akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
using namespace std;
typedef long long ll;

int main(){

    int n; cin >> n;

    ll a[n];

    int cntNegative = 0;
    for(int i=0; i<n; i++){
        cin >> a[i];
        if(a[i] < 0) cntNegative++;
    }

    ll ans = 0;
    if(cntNegative % 2 == 0){
        for(int i=0; i<n; i++){
            ans += abs(a[i]);
        }
    }
    else{
        ll vmin = 1e9;
        for(int i=0; i<n; i++){
            ans += abs(a[i]);
            vmin = min(vmin, abs(a[i]));
        }

        ans -= 2*vmin;
    }

    cout << ans;

    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define md 1000000007
#define ld long double
#define pi 3.14159265359
using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    long long n, i = 0, j= 0, k = 0, l = 0, m = 0, a = 0, b = 0, sum = 0, x = 0, y = 0, z = 0, c, p;
    cin >> n;
    ll arr[n];
    for(i = 0; i < n; i++){
        cin >> arr[i];
    }
    for(i = 0; i < n; i++){
        for(j = i+1; j < n; j++){
            for(k = j+1; k < n; k++){
                if(arr[i] != arr[j] && arr[i] != arr[k] && arr[j] != arr[k]){
                    a = arr[i]; b = arr[j]; c = arr[k];
                    if(a+b > c && a+c > b && b + c > a){
                        x++;
                    }
                }
            }
        }
    }
    cout << x;


    return 0;
}


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

int main(){
    int k;cin >> k;
    vector<ll> a;
    rep(i,9) a.push_back(i+1);
    while(1){
        if(k <= a.size()){
            cout << a[k-1] << endl;
            return 0;
        }
        k -= a.size();
        vector<ll> old;
        swap(old,a);
        for(ll x : old) {
            for(int i = -1; i <= 1;++i){
                int d = x%10 + i;
                if(d < 0|| d > 9) continue;
                ll nx = x*10 + d;
                a.push_back(nx);
            }
        }
    }
}

Measured memory_bytes: 1712
#include <bits/stdc++.h>
using namespace std;
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define in(x,y,h,w) x >= 0 && x < h && y >= 0 && y < w

#define int long long
#define double long double
//typedef    long long          ll;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      P;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
 
const int INF=1e+18;
const double EPS=1e-9;
const int MOD=1000000007;

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

signed main(){
	int a,b,c,x,y,mi = INF;
	cin >> a >> b >> c >> x >> y;
	for(int i = 0;i <= max(x,y);i++){
		chmin(mi,c * i * 2 + a * max(0ll,x - i) + b * max(0ll,y - i));
	}
	cout << mi << endl;
	return 0;
}

Measured memory_bytes: 256
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

int hc (int a, int b, int c) {
  return (a * 1024 + b) * 1024 + c;
}

import std.container;
alias Q = DList!int;

void main() {
  int a, b, c;
  readf (" %d %d %d", &a, &b, &c);
  if (a == b && b == c) {
    writeln (0);
    return;
  }
  auto q = new Q ();
  int[int] d;
  int s = hc (a, b, c);
  d[s] = 0;
  q.insertBack (s);
  while (!q.empty) {
    auto i = q.front;
    q.removeFront ();
    int nd = d[i] + 1;
    c = i & 1023;
    i >>= 10;
    b = i & 1023;
    a = i >> 10;
    foreach (t; [ tuple (a + 1, b + 1, c),
                  tuple (a, b + 1, c + 1),
                  tuple (a + 1, b, c + 1),
                  tuple (a + 2, b, c),
                  tuple (a, b + 2, c),
                  tuple (a, b, c + 2)]) {
      auto j = hc (t[0], t[1], t[2]);
      if (t[0] == t[1] && t[1] == t[2]) {
        writeln (nd);
        return;
      }
      if (! (j in d)) {
        q.insertBack (j);
        d[j] = nd;
      }
    }
  }
  
}


Measured memory_bytes: 8572
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
n,k = readInts()
def calc(a):
    sml = (0 + a-1) * a //2
    lar = sml + a * (n-a+1)
    return lar - sml + 1
ans = 0
for i in range(k,n+2):
    ans += calc(i) % mod
print(ans % mod)


Measured memory_bytes: 10384
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); ++i)
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<long long,long long>;
using veci = vector<int>;
using vecl = vector<long long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long long>>;


template <typename T>
struct PrimeFact {
    vector<T> spf;
    PrimeFact(T N) { init(N); }
    void init(T N) { // 前処理。spf を求める
        spf.assign(N + 1, 0);
        for (T i = 0; i <= N; i++) spf[i] = i;
        for (T i = 2; i * i <= N; i++) {
            if (spf[i] == i) {
                for (T j = i * i; j <= N; j += i) {
                    if (spf[j] == j) {
                        spf[j] = i;
                    }
                }
            }
        }
    }
    map<T, T> get(T n) { // nの素因数分解を求める
        map<T, T> m;
        while (n != 1) {
            m[spf[n]]++;
            n /= spf[n];
        }
        return m;
    }
};

int main() {
    ll N; cin >> N;
    ll ans = 0;
    PrimeFact<ll> PF(N);
    for(ll i = 1; i <= N; i++) {
        map<ll,ll> res = PF.get(i);
        ll cost = 1;
        for(auto p : res) {
            cost *= p.second + 1;
        }
        ans += i*cost;
    }
    cout << ans << endl;
}

Measured memory_bytes: 81400
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <vector>

typedef long long ll;
using namespace std;

ll Mod = 1e9 + 7;
int main()
{
    int a, b, c, d, e, k;
    cin >> a >> b >> c >> d >> e >> k;

    if (e - a <= k) cout << "Yay!" << endl;
    else cout << ":(" << endl;
    return 0;
}

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

using namespace std;

std::vector<pair<unsigned long long, unsigned long long>> prime_factors(unsigned long long number)
{
    std::vector<pair<unsigned long long,unsigned long long>> result;
    unsigned long long root = static_cast<unsigned long long>(std::sqrt(number));
    int count = 0;
    int leng = 0;
    int flag = 0;
    while (number % 2 == 0) {
        if(count == 0) {
            result.push_back(pair<unsigned long long, unsigned long long>(2,0));
            count += 1;
            flag = 1;
        }
        result[leng].second += 1;
        number = number / 2;
    }
    if (flag == 1) {
        leng++;
        flag = 0;
    }

    for (unsigned int i = 3; i <= root; i+=2) {
        count = 0;
        while (number % i == 0) {
            if(count == 0) {
                result.push_back(pair<unsigned long long, unsigned long long>(i,0));
                count += 1;
                flag = 1;
            }
            result[leng].second += 1;
            number = number /i;
        }
        if (flag == 1) {
            leng++;
            flag = 0;
        }
    }

    if(number > 2) {
        result.push_back(pair<unsigned long long, unsigned long long>(number,1));
    }

    return result;
}

long long func(long long a, long long b){
    return (a - b)*(pow(a,4) + pow(a,3) * pow(b,1) + pow(a,2) * pow(b,2) + pow(a,1) * pow(b,3) + pow(b,4));
}
int main(void)
{
    long long X;
    cin >> X;
    for(long long i = 0;i < 1000; i++) {
        for(long long j = -1000;j < 1000; j++) { 
            if(func(i,j) == X) {
                cout << i << " " << j << endl;
                return 0;
            }
        } 
    }
    return 0;

}

Measured memory_bytes: 4048
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <cmath>
#include <iomanip>
#include <functional>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) (int)(x).size()
using namespace std;
using ll = long long;
constexpr int inf = 1000000000;
constexpr ll INF = 1000000000000000000;

int main() {
    char c;
    cin >> c;
    if ('a' <= c && c <= 'z') cout << "a\n";
    else cout << "A\n";
    return 0;
}


Measured memory_bytes: 3620
n = 0
a = []

def format_input(filename = None):
	global n
	global a
	if filename == None:
		n = list(map(int, input().split())).pop()
		a = list(map(int, input().split()))

	elif filename == '__random__':
		from random import randint as rng
		n = rng(2, 2 * 10**5)
		a = [rng(1, 10**9) for i in range(n)]

def get_answer():
	answer = "YES"
	sorted_a = sorted(a)

	memo = [0, sorted_a.pop()]
	while answer == "YES" and len(sorted_a) > 0:
		memo[0] = memo[1]
		memo[1] = sorted_a.pop()
		if memo[0] == memo[1]:
			answer = "NO"

	return answer

if __name__ == '__main__':
	format_input()

	ans = get_answer()
	print(ans)


Measured memory_bytes: 25676
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#define inf 0x3f3f3f3f
#define met(a,b) memset(a,b,sizeof a)
#define pb push_back
#define mp make_pair
typedef long long ll;
using namespace std;
const int N = 1e5+10;
const int M = 1e6+10;
int n,m,k,tot=0,q;
ll ans=0;
int head[N],vis[N],l[N],r[N];
int v[N],d[N],c[N],color[N];
vector<int>edg[N];
void bfs(int v,int d,int c){

    queue<pair<int,int> >q;
    if(vis[v]>=d)return;
    q.push(make_pair(v,d));
    while(!q.empty()){
        int t=q.front().first;
        int dd=q.front().second;
        q.pop();
        if(dd==-1)continue;
        if(!color[t])color[t]=c;
        vis[t]=max(vis[t],dd);

        for(int i=0;i<edg[t].size();i++){
            int u=edg[t][i];
            if(vis[u]>=dd-1&&vis[u]!=-1)continue;
            q.push(make_pair(u,dd-1));
        }
    }
}
int main() {
    int T;
    met(vis,-1);
    scanf("%d%d",&n,&m);
    int u,vv;
    while(m--){
        scanf("%d%d",&u,&vv);
        edg[u].push_back(vv);
        edg[vv].push_back(u);
    }
    scanf("%d",&q);
    for(int i=1;i<=q;i++){
        scanf("%d%d%d",&v[i],&d[i],&c[i]);
    }
    for(int i=q;i>=1;i--){
        bfs(v[i],d[i],c[i]);
    }
    for(int i=1;i<=n;i++)printf("%d\n",color[i]);
    return 0;
}



Measured memory_bytes: 9096
#include <iostream>
#include <string>
#include <cstring>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>
#include <fstream>

using namespace std;

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(ll i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(),n.end()
#define MOD 1000000007
#define P pair<ll, ll>

ll n, m, ans, t[60], num[60][60], cnt, dp[5100000];
vector<ll> g[60];
vector<P> s(100), v(100);
bool used[60];
bool dfs(ll a, ll b, ll c) {
	used[a] = true;
	if (a == b)return true;
	REP(i, g[a].size()) {
		if (!used[g[a][i]]) {
			if (dfs(g[a][i], b, c)) {
				num[a][g[a][i]] += (1ll << c);
				num[g[a][i]][a] += (1ll << c);
				return true;
			}
		}
	}
	return false;
}
void dfs2(ll a, ll b, ll c) {
	if (a == b) {
		dp[c]++;
		return;
	}
	dfs2(a + 1, b, (c | num[v[a].first][v[a].second]));
	dfs2(a + 1, b, c);
}

void dfs3(ll a, ll b, ll c) {
	if (a == b) {
		///cout << c << " !" << endl;
		ans += dp[(1ll << m) - 1 - c];
		return;
	}
	dfs3(a + 1, b, (c | num[v[a].first][v[a].second]));
	dfs3(a + 1, b, c);
}


int main() {
	cin >> n;
	REP(i, n - 1) {
		ll a, b;
		cin >> a >> b;
		a--;
		b--;
		g[a].push_back(b);
		g[b].push_back(a);
		v[i] = P(a, b);

	}
	cin >> m;
	REP(i, m) {
		ll a, b;
		cin >> a >> b;
		a--;
		b--;
		s[i] = P(a, b);
	}
	REP(i, m) {
		REP(j, 60)used[j] = false;
		dfs(s[i].first, s[i].second, i);
	}
	dfs2(0, n / 2, 0);
	//REP(i, 1 << m)cout << dp[i] << " !  " << i << endl;

	REP(k, m) {
		REP(s, 1ll << m) {
			if (!((s >> k) & 1)) {
				dp[s] += dp[s ^ (1ll << k)];
			}
		}
	}
	//REP(i, 1 << m)cout << dp[i] << " !! " << i << endl;
	dfs3(n / 2, n - 1, 0);
	cout << ans << endl;
}


Measured memory_bytes: 10496
def resolve():    
    import heapq
    n,m=map(int,input().split())
    ab=[list(map(int,input().split())) for _ in range(n)]
    b=[[] for _ in range(10**5+1)]
    for i,j in ab:
        b[i].append(-j)
    q=[]
    ans=0
    for i in range(1,m+1):
        for j in b[i]:
            heapq.heappush(q,j)
        if q:
            ans+=heapq.heappop(q)
    print(-ans)
        
if __name__ == '__main__':
    resolve()

Measured memory_bytes: 40240
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<string>
#include<cstring>
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
#include <fstream>
using namespace std;
typedef long long ll;
const ll INF = 0x3f3f3f3f;
const double PI = acos(-1.0);
const double eps = 1e-6;
const int mod = 1e9+7;
const int maxn = 200005;
int a[maxn];
ll n;
int main() {
	cin>>n;
	string s;
	cin>>s;
	char c[30];
	for(int i=0;i<=26;i++)
		c[i] = 'A'+i;
	n%=26;
	for(int i=0;i<s.length();i++)
		cout<<c[(s[i]-'A'+n)%26];
    return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

int main()
{
    int a,b,c;
    while(scanf("%d%d%d",&a,&b,&c)!=EOF)
    {
      if((c-b)<=a&&(c-b)>0)
       printf("safe");
      if((c-b)<=0)
       printf("delicious");
      if((c-b)>a)
       printf("dangerous");
    }

    return 0;
}

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

int main() {
    int N, M;
    cin >> N;
    map<string, int> s;
    string tmp="";
    for (int i=0; i<N; i++) {
        cin >> tmp;
        s[tmp] += 1;
    }
    cin >> M;
    for (int i=0; i<M; i++) {
        cin >> tmp;
        s[tmp] -= 1;
    }
    int res=0;
    for( auto i = s.begin(); i != s.end() ; ++i ) {
      if(i->second > res) res = i->second;
    }
    cout << res;

}

Measured memory_bytes: 384
#include<iostream>
#include<list>
#define MAX(a,b) ((a) > (b) ? (a) : (b))
#define MIN(a,b) ((a) > (b) ? (b) : (a))
using namespace std;


int main(){
	long a,b,r,x,y;
	list<long> aby;
	
	while(!(cin>>a>>b).eof()){
		x=a,y=b;
		while(1){
			r=MAX(x,y)%MIN(x,y);
			if(r==0) break;
			x=MIN(x,y);
			y=r; 
		}
		aby.push_back(a);
		aby.push_back(b);
		aby.push_back(MIN(x,y));
		
	}
	list<long>::iterator it = aby.begin();
	while(it != aby.end()){
		a = *it, it++;
		b = *it, it++;
		y = *it;
		cout << y << " "<<(a*b)/y <<endl;
		it++;
	}
	
	return 0;
}

Measured memory_bytes: 1192
#include <iostream>
using namespace std;
int main(void){
    int N = 1;
    int K = 1;
    int j = 0;
     cin >> N >> K;
    for(int i = 0; i < N;i++){
      int h;
        cin >> h;
        if(h >= K)
        j++;
    }
     cout << j << endl;
}


Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;

namespace atcorder2
{
    class Program
    {
        public static long Read()
        {
            return long.Parse(Console.ReadLine());
        }

        public static long[] Reads()
        {

            return Console.ReadLine().Split().Select(long.Parse).ToArray();
        }






        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);


            var s = Console.ReadLine();
            long ans = 0;
            for (int i = 0; i <s.Length-1; i++)
            {
                if (s[i] != s[i + 1]) ans++;
            }
            Console.WriteLine(ans);
         
            Console.Out.Flush();
        }
    }
}




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

using namespace std;
typedef long long ll;
typedef double dd;
#define all(v) v.begin(),v.end()
#define endl "\n"
#define clr(n, r) memset(n,r,sizeof(n));

void fast() {

    cin.tie(0);
    cin.sync_with_stdio(0);
}

ll n, m;


int main() {
    fast();
    string s;
    cin>>s;
    string ans;
    for(char i :s){
        if(i=='B'&&!ans.empty())ans.pop_back();
        if(i!='B')ans.push_back(i);
    }
cout<<ans;
}

Measured memory_bytes: 256
use std::io::{BufRead, Write};
use std::io;
use std::ops::{Add, Div, Mul, Sub};
use std::iter::Sum;

const MOD: u64 = 1000000007;

#[derive(Clone, Copy)]
struct ModInt {
    pub inner: u64,
}

impl From<u64> for ModInt {
    fn from(i: u64) -> ModInt {
        ModInt { inner: i }
    }
}

impl Add<ModInt> for ModInt {
    type Output = ModInt;
    fn add(self, rhs: ModInt) -> ModInt {
        ModInt {
            inner: (self.inner + rhs.inner) % MOD,
        }
    }
}

impl Sub<ModInt> for ModInt {
    type Output = ModInt;
    fn sub(self, rhs: ModInt) -> ModInt {
        ModInt {
            inner: (self.inner + MOD - rhs.inner) % MOD,
        }
    }
}

impl Mul<ModInt> for ModInt {
    type Output = ModInt;
    fn mul(self, rhs: ModInt) -> ModInt {
        ModInt {
            inner: (self.inner * rhs.inner) % MOD,
        }
    }
}

impl Sum for ModInt {
    fn sum<I: Iterator<Item = ModInt>>(iter: I) -> ModInt {
        iter.fold(ModInt::from(0), Add::add)
    }
}

fn solve<R: BufRead, W: Write>(mut input: R, mut output: W) {
    let mut s = String::new();
    input.read_line(&mut s).unwrap();
    let _: usize = s.trim().parse().unwrap();
    s.clear();
    input.read_line(&mut s).unwrap();
    let s1 = s.trim().as_bytes().to_owned();
    s.clear();
    input.read_line(&mut s).unwrap();
    let _ = s.trim().as_bytes().to_owned();
    #[derive(Clone, Copy)]
    enum BlockType {
        Horizontal,
        Vertical,
    }
    let mut bt: Vec<BlockType> = Vec::new();
    let mut i = 0;
    while i != s1.len() {
        if i == s1.len() - 1 || s1[i] != s1[i + 1] {
            bt.push(BlockType::Vertical);
            i += 1;
        } else {
            bt.push(BlockType::Horizontal);
            i += 2;
        }
    }
    let mut total = ModInt {
        inner: match bt[0] {
            BlockType::Horizontal => 6,
            BlockType::Vertical => 3,
        },
    };
    for x in bt.windows(2) {
        total = total * ModInt {
            inner: match (x[0], x[1]) {
                (BlockType::Horizontal, BlockType::Horizontal) => 3,
                (BlockType::Horizontal, BlockType::Vertical) => 1,
                (BlockType::Vertical, BlockType::Horizontal) => 2,
                (BlockType::Vertical, BlockType::Vertical) => 2,
            },
        }
    }
    writeln!(output, "{}", total.inner).unwrap();
}

fn main() {
    let stdin = io::stdin();
    let stdout = io::stdout();
    solve(stdin.lock(), stdout.lock());
}

#[cfg(test)]
mod tests {
    fn test(input: &str, output: &str) {
        let mut v = Vec::<u8>::new();
        ::solve(input.as_bytes(), &mut v);
        assert_eq!(String::from_utf8(v).unwrap(), output);
    }
    #[test]
    fn case1() {
        test(
            "3
aab
ccb\n",
            "6\n",
        );
    }
    #[test]
    fn case2() {
        test(
            "1
Z
Z\n",
            "3\n",
        );
    }
    #[test]
    fn case3() {
        test(
            "52
RvvttdWIyyPPQFFZZssffEEkkaSSDKqcibbeYrhAljCCGGJppHHn
RLLwwdWIxxNNQUUXXVVMMooBBaggDKqcimmeYrhAljOOTTJuuzzn\n",
            "958681902\n",
        );
    }
}


Measured memory_bytes: 4352
open Batteries
open Printf
let () =
  let a,b,c,d = Scanf.scanf "%d %d %d %d " (fun a b c d -> a,b,c,d) in
  let ans = (min b d) - (max a c) in
  Printf.printf "%d\n" @@
  if ans > 0 then ans else 0


Measured memory_bytes: 1024
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<ll, int> P;
typedef pair<int, P> E;
#define MOD (1000000007ll)
#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	b += MOD;
	a += b;
	a %= MOD;
}

priority_queue< P, vector<P>, greater<P> > pq;

int main(void){
	int n,m,b,i;
	ll a,ret=0ll;
	P p;
	cin >> n >> m;
	for(i=0; i<n; ++i){
		cin >> a >> b;
		pq.push(P(a,b));
	}
	while(!pq.empty()){
		p = pq.top();
		pq.pop();
		a = p.first;
		b = p.second;
		if(m>b){
			ret += a*b;
			m -= b;
		}else{
			ret += a*m;
			break;
		}
	}
	cout << ret << endl;
	return 0;
}


Measured memory_bytes: 2420
/*
  #問題：
  


  #分析：
  #オブジェクト：
  
  #条件：
  

  #要求：
  

  #解法：
  
*/

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
#include <initializer_list>
#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define uLL unsigned LL
#define LD long double

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
const int mod=1000000007;


const unsigned int BIT_FLAG_0 = (1<<0);
const unsigned int BIT_FLAG_1 = (1<<1);
const unsigned int BIT_FLAG_2 = (1<<2);
const unsigned int BIT_FLAG_3 = (1<<3);
const unsigned int BIT_FLAG_4 = (1<<4);
const unsigned int BIT_FLAG_5 = (1<<5);
const unsigned int BIT_FLAG_6 = (1<<6);
const unsigned int BIT_FLAG_7 = (1<<7);


#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
namespace mp = boost::multiprecision;

using Bint = mp::cpp_int;



int main(void){
  int n; cin>>n;
  vector<int> a(n);
  int cnt=0,max=0;
  FOR(i,0,n) {
    cin>>a[i];
    if(a[i]>=max){
      max=a[i];
      cnt++;
    }
  }
  cout<<cnt<<endl;
  return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=1e6+10;
const int mod=998244353;
const int inv2=(mod+1)>>1;

int gi() {
	int x=0,o=1;char ch=getchar();
	while((ch<'0'||ch>'9')&&ch!='-') ch=getchar();
	if(ch=='-') o=-1,ch=getchar();
	while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
	return x*o;
}

int n,mu[N],cnt[N],f[N],cnt2[N],inv[N];

int main() {
	mu[1]=inv[1]=1;
	for(int i=1;i<N;i++) {
		if(i>1) inv[i]=1ll*(mod-mod/i)*inv[mod%i]%mod;
		for(int j=i+i;j<N;j+=i)
			mu[j]=(mu[j]-mu[i]+mod)%mod;
	}
	cin>>n;
	for(int i=1,v;i<=n;i++) v=gi(),cnt[v]=(cnt[v]+v)%mod,cnt2[v]=(cnt2[v]+1ll*v*v)%mod;
	for(int i=1;i<N;i++) {
		for(int j=i;j<N;j+=i) f[i]=(f[i]+cnt[j])%mod;
		f[i]=1ll*f[i]*f[i]%mod;
		for(int j=i;j<N;j+=i) f[i]=(f[i]-cnt2[j]+mod)%mod;
		f[i]=1ll*f[i]*inv2%mod;
	}
	int ans=0;
	for(int i=1;i<N;i++) {
		int s=0;
		for(int j=i;j<N;j+=i) s=(s+1ll*f[j]*mu[j/i])%mod;
		ans=(ans+1ll*s*inv[i])%mod;
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 19840
package main

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

var sc = bufio.NewScanner(os.Stdin)

func ri() (n int) {
	sc.Scan()
	for _, v := range sc.Bytes() {
		n = n*10 + int(v-48)
	}
	return
}

func deleteElement(a []int, i int) []int {
	return append(a[:i], a[i+1:]...)
}

func main() {
	sc.Split(bufio.ScanWords)
	n := ri()

	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = ri() - 1
	}

	ans := make([]int, n)
	ansIndex := 0
	for len(b) != 0 {
		prevLen := len(b)
		for i := len(b) - 1; i >= 0; i-- {
			if i == b[i] {
				ans[ansIndex] = i
				ansIndex++
				b = deleteElement(b, i)
				break
			}
		}
		if nowLen := len(b); prevLen == nowLen {
			break
		}
	}

	if len(b) == 0 {
		for i := len(ans) - 1; i >= 0; i-- {
			fmt.Println(ans[i] + 1)
		}
	} else {
		fmt.Println(-1)
	}
}


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

int main() {
     ios_base::sync_with_stdio(false);
     cin.tie(NULL);
     cout.tie(NULL);
     long long i,j,l,q,t,m,n,h,p;
     long long k,z,p1,h1,x,y;
     string st="",st1="";
     q=1;
     int isprime[1000001]={0};
     isprime[1]=1;
     int noof[1000001];
     for(i=0;i<1000001;i++)
          noof[i]=1;
     for(i=2;i<1000001;i++)
     {
          if(isprime[i]==0)
          {
               noof[i]=2;
               for(j=i*i;j<=1000001;j+=i)
                    isprime[j]=1;
          }
     }
     for(i=4;i<1000001;i++)
     {
          if(isprime[i]==1)
          {
               k=i;p=1;
               for(j=2;j*j<=i;j++)
               {
                    if(k==1 || isprime[k]==0)
                         break;
                    x=0;
                    while(k%j==0)
                         k=k/j,x++;
                    p=p*(x+1);
               }
               if(isprime[k]==0)
                    p=p*2;
               noof[i]=p;
          }
     }
     for(l=0;l<q;l++)
     {
          std::cin >> n;p=0;
          for(i=1;i<n;i++)
          {
               x=n-i;
               p=p+noof[x];
          }
          std::cout << p << std::endl;
     }
    return 0;
}

Measured memory_bytes: 11456
#include <bits/stdc++.h>
using namespace std;
#define rep(i,ini,n) for(int i=ini;i<n;i++)
#define _rep(i,ini,n) for(int i=ini;i>=n;i--)
#define ToEnd(a) a.begin(),a.end()
uint64_t MOD=1000000007;

int main(){
    int N; cin>>N;
    vector<int64_t> A(N);
    rep(n,0,N) cin>>A.at(n);

    int cnt=0;
    for(auto a:A){
        if(a<0) cnt++;
    }

    int64_t ans=0,minA=INT64_MAX;
    for(auto a:A){
        ans+=abs(a);
        minA=min(minA,abs(a));
    }

    if(cnt%2) ans-=2*minA;
    cout<<ans<<endl;
}

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

using namespace std;
using boost::adaptors::reversed;
using boost::irange;
using uint = unsigned int;
using ll = long long int;
using ull = unsigned long long int;

int main() {
    ll A, B;
    cin >> A >> B;
    cout << (A * B) - A - B + 1 << endl;
    return 0;
}

Measured memory_bytes: 256
def main():
    m = 1000000007

    h, w = map(lambda x: int(x), input().split())

    grid = []
    for row in range(h):
        grid.append(input())

    count = []
    for row in range(h):
        count.append([0] * w)

    for row in range(h):
        if grid[row][0] == "#":
            break
        count[row][0] = 1

    for column in range(w):
        if grid[0][column] == "#":
            break
        count[0][column] = 1

    for row in range(1, h):
        for column in range(1, w):
            if grid[row][column] == ".":
                count[row][column] = (
                    (count[row - 1][column] % m) +
                    (count[row][column - 1] % m)
                ) % m

    print(count[-1][-1])

main()


Measured memory_bytes: 74620
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

using boost::multiprecision::cpp_int;
using namespace std;

#if __has_include("print.hpp")
  #include "print.hpp"
#endif

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MOD 1000000007

typedef long long ll;
typedef pair<ll, ll> p;


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<ll> v(n);
  rep(i, n) cin >> v[i];
  ll res = 0;

  vector<ll> count(100);

  for (int i = 0; i < n; i++) {
    // while(tmp < v[i]){
    //   tmp *= 2;
    //   ci++;
    // }
    int index = 0;
    while(v[i] > 0){
      if(v[i] % 2 == 1) count[index]++;
      v[i] /= 2;
      index++;
    }
  }

  for (int i = 0; i < 100; i++) {
    res += (count[i] * (n-count[i]) % MOD) * (ll(pow(2, i)) % MOD);
    res %= MOD;
  }
  cout << res << endl;

}


Measured memory_bytes: 2560
N,M=map(int,input().split())
A=list((map(int,input().split())))
 
m=[[1,2],[2,5],[3,5],[4,4],[5,5],[6,6],[7,3],[8,7],[9,6]]
B=[]
    
for a in A:
    B.append(m[a-1])

if [5,5] in B:
    if [2,5] in B:
        B.remove([2,5])
    if [3,5] in B:    
        B.remove([3,5])

if [3,5] in B and [2,5] in B:
    B.remove([2,5])

if [7,3] in B:
    if [6,6] in B:
        B.remove([6,6])
    if [9,6] in B:
        B.remove([9,6])
    
if [9,6] in B and [6,6] in B:
    B.remove([6,6])

if [1,2] in B and [7,3] in B:
    if [2,5] in B:
        B.remove([2,5])
    if [3,5] in B:
        B.remove([3,5])
    if [5,5] in B:
        B.remove([5,5])
    if [8,7] in B:
        B.remove([8,7])

if [1,2] in B and ([2,5] in B or [3,5] in B or [5,5] in B) and [8,7] in B:
    B.remove([8,7])
    
if [4,4] in B and [7,3] in B and [8,7] in B:
    B.remove([8,7])
    
if [1,2] in B and [4,4] in B:
    B.remove([4,4])

maxlist=[""]*(N+1)
 
for i in range(N+1):
    if i!=0 and maxlist[i]=="":
        continue
    else:
        for b in B:
            if i+b[1]>N:
                continue
            ans=maxlist[i]+str(b[0])
            _max=maxlist[i+b[1]]
            if len(ans)<len(_max):
                continue
            elif len(ans)>len(_max):
                maxlist[i+b[1]] = ans
            else:
                for j in range(len(ans)):
                    if ans[j]<_max[j]:
                        break
                    if ans[j]>_max[j]:
                        maxlist[i+b[1]] = ans
                        break
 
print(maxlist[N])

Measured memory_bytes: 137180
n = int(input())
x = list(map(int,input().split()))

chk = []
hp = 0
#i->集会の座標, j->体力
for i in range(min(x),max(x)+1):
    for j in range(len(x)):
        hp +=(x[j]-i)**2
    chk.append(hp)
    hp = 0
print(min(chk))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define Red ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define rep(i, n) for(int i =0 ; i < n; ++i)
#define Rep(i,a,b) for(int i=a;i<=b;i++)
#define pii pair < int, int >
typedef vector<int> vi;
typedef  long long ll;
const int mod =1e9+7;
const int N = (int)2e5 + 5;



void solve(){
	int a,b;
  	cin>>a>>b;
	cout<<max(a+b,max(a*b,a-b));


}

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

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	
	public static void countABC(char[] arr) {
		int counter = 0;
		for (int count = 0; count < arr.length - 2; count++) {
			if(arr[count] == 'A' && arr[count + 1] == 'B' &&
				arr[count + 2] == 'C') counter++;
		}
		System.out.println(counter);
	}

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		scan.nextInt();
		countABC(scan.next().toCharArray());
		scan.close();
	}

}


Measured memory_bytes: 35648
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <algorithm>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1010101010;
constexpr lint LINF = 1LL << 60;

template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
	for (const auto &e : vec) os << e << (&e == &vec.back() ? "\n" : " ");
	return os;
}

#ifdef _DEBUG
template <class T>
void dump(const char* str, T &&h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head &&h, Tail &&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + (*(str + 1) == ' ' ? 2 : 1), t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

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

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	lint N, M;
	cin >> N >> M;

	vector<lint> a(N);
	for (int i = 0; i < N; i++) cin >> a[i];

	lint lcm_a = 1;
	for (lint i = 0; i < N; i++) {
		lint tmp = gcd(lcm_a, a[i]);
		lcm_a = lcm_a * a[i] / tmp;
		if (lcm_a / 2 > M) {
			cout << 0 << "\n";
			return 0;
		}
	}

	for (int i = 0; i < N; i++) {
		if (lcm_a / a[i] % 2 == 0) {
			cout << 0 << "\n";
			return 0;
		}
	}

	DMP(lcm_a);
	cout << (M - lcm_a / 2) / lcm_a + 1 << "\n";

	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1e18

int main() {
    int X, Y, Z;
    cin >> X >> Y >> Z;
    swap(X, Y);
    swap(X, Z);
    cout << X << " " << Y << " " << Z << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define reg register
#define ll long long
#define mo 1000000007
#define P make_pair
inline ll read()
{
	ll x=0,w=0;char ch=getchar();
	while(!isdigit(ch))w|=ch=='-',ch=getchar();
	while(isdigit(ch))x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
	return w?-x:x;
}
inline void Max(int &x,int y){x=x>y?x:y;}
int q,ans,res;
ll f[100],x,y;
vector< pair<ll,ll> >G[100];
inline void Add(int &x,int y){x+=y;if(x>=mo)x-=mo;}
int main()
{
    q=read();reg int i,o,sz,b;
    f[0]=1;f[1]=2;reg ll xx,yy;
    for(i=2;i<=89;++i)f[i]=f[i-1]+f[i-2];
    G[1].push_back(P(1,2));G[1].push_back(P(1,3));G[1].push_back(P(1,4));
    for(i=1;i<87;++i)
    {
        sz=G[i].size();
        for(o=0;o<sz;++o)
        {
            x=G[i][o].second,y=G[i][o].first+x;
            while(y<=2ll*f[i+1])
                G[i+1].push_back(P(x,y)),y+=x;
        }
    }
    while(q--)
    {
        x=read(),y=read();if(x<y)swap(x,y);
        if(y==1){printf("1 %lld\n",x%mo);continue;}
        b=upper_bound(f+1,f+1+89,y)-f;
        if(x>=f[b])ans=b,printf("%d ",b);
        else ans=b-1,printf("%d ",b-1);
        if(ans==1){printf("%lld\n",1ll*x%mo*y%mo);continue;}
        sz=G[ans-1].size();res=0;
        for(o=0;o<sz;++o)
        {
            xx=G[ans-1][o].first;
            yy=G[ans-1][o].second;
            if(yy<=x)Add(res,1ll*(y-xx)/yy%mo);
            if(yy<=y)Add(res,1ll*(x-xx)/yy%mo);
        }
        printf("%d\n",res);
    }
	return 0;
}


Measured memory_bytes: 4096
#include <iostream>
#include <iomanip>
#include <math.h>
using namespace std;

int main()
{
  char s;

  cin >> s;

  if(isupper(s))
  {
    cout << "A" << endl;
  }
  else
  {
    cout << "a" << endl;
  }

  //cout << fixed << setprecision(8) << s << " " << l << " " << endl;

  return 0;
}



Measured memory_bytes: 3632
import java.util.Scanner;

class Main
{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		
		int[] a = new int[1000];
		int q = 0;
		String str = "1";
		
		while(!(str.equals("0"))){
			a[q] = 0;
			str = scan.nextLine();
			char[] CH = str.toCharArray();
			for(int i=0; i<CH.length; i++){
				a[q] += (int)CH[i] - 48;}
				q++;}
				
			for(int i=0; i<q-1; i++){
				System.out.println(a[i]);}
	}
}


Measured memory_bytes: 26464
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<int> b(N-1);
  int i = 0;
  while(i<N-1){
    cin >> b.at(i);
    i++;
  }
  int sum = 0;
  if(i == 0) {
    sum = b.at(0)*2 ;
  }
  else{
  vector<int> a(N,0);
  a.at(0) += b.at(0);
  for(int i= 1; i< N-1; i++){
    a.at(i) += min(b.at(i),b.at(i-1));
  }
  a.at(N-1) += b.at(N-2);
for(int i= 0; i< N; i++){
  sum+= a.at(i);
}
cout << sum << endl;
}
  

}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

int main(void){
   int d = 0;
   int x = 0;
   int max = 0;
   int i = 0;
   int N = 0;
   char S[101];
   
   scanf("%d",&N);
   scanf("%s",S);
   
   while(1){
     if(S[i] == 'I'){
         x++;
         if(x > max) max = x;
       }
     else if(S[i] == 'D'){
         x--;
       }
     else if(S[i] == '\0'){
         break;
       }
     else exit(0);
     i++;
   }
   printf("%d\n",max);
}

Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#define lol(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
typedef long long ll;

using namespace std;
typedef pair<ll,ll> P;
#define N 30
#define M 15

class Half_Zen{
public:
    vector<P> v,s;
    //s.first=∑a
    //s.second=∑b
    void dfs(ll asum,ll bsum,int i){
	if(i==v.size()){
	    s.push_back(make_pair(asum,bsum));
	    return;
	}
	for(int k=-1;k<=1;k++){
	    dfs(asum+k*v[i].first,bsum+k*v[i].second,i+1);
	}
    }
    void Init(vector<P> tmp){
	v=tmp;
	dfs(0,0,0);
	sort(s.begin(),s.end());
    }
    ll sa(int i){return s[i].first;}
    ll sb(int i){return s[i].second;}
    ll size(){return s.size();}
};

int main(){
    int n;cin>>n;
    ll d;cin>>d;
    vector<P> v1,v2;
    for(int i=0;i<N;i++){
	ll a,b;
	if(i<n)cin>>a>>b;
	else a=b=0;
	if(i<M)v1.push_back(make_pair(a,b));
	else v2.push_back(make_pair(a,b));
    }
    Half_Zen z1,z2;
    z1.Init(v1);z2.Init(v2);
    //for(int i=0;i<z1.size();i++)cout<<z1.sa(i)<<" "<<z1.sb(i)<<endl;
    //for(int i=0;i<z2.size();i++)cout<<z2.sa(i)<<" "<<z2.sb(i)<<endl;
    ll ans=0;
    deque<P> Q;
    int l,r;l=r=z2.size()-1;
    for(int i=0;i<z1.size();i++){
	while(r>=0&&z2.sa(r)>=-z1.sa(i)-d){
	    ll news=z2.sb(r);
	    while(!Q.empty()){
		if(Q.back().first<news)Q.pop_back();
		else break;
	    }
	    Q.push_back(make_pair(news,r));
	    r--;
	}
	while(l>=0&&z2.sa(l)>-z1.sa(i)+d){
	    if(Q.front().second==l)Q.pop_front();
	    l--;
	}
	if(Q.size()==0)continue;
	ans=max(ans,z1.sb(i)+Q.front().first);
    }
    cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 685972
import java.util.Scanner;

class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String str = sc.nextLine();
        String[] array = str.split(" ");
        int num=Integer.parseInt(array[0]);
        int max=Integer.parseInt(array[1]);
        int[] suu = new int[num];
        int count=num;
        int min=0;
        for(int i=0;i<num;i++){
            suu[i]=sc.nextInt();
        }
      for(int j=0;j<suu.length;j++){
          max=max-suu[j];
      }
      if(max==0){
        System.out.println(num);
      }else{
          min=suu[0];
        for(int k=0;k<suu.length;k++){
            min=Math.min(min, suu[k]);
        }
        while(max>=0){
            max=max-min;
            count++;
        }
        System.out.println(count-1);
      }
    }
}

Measured memory_bytes: 23892
#include <iostream>
#include <bits/stdc++.h>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <map>
#define for1(x,y) for(long long x = 1; x<ll(y); x++)
#define forn(x,y,z) for(long long x = y; x< ll(z); x++)
#define for0(x,y,z) for(long long x = y; x< ll(z); x++)
# define PII pair<int,int>
# define FF first
# define SS second
# define PB push_back

#define forn(x,y,z) for(long long x = y; x< ll(z); x++)
#define for0(x,y,z) for(long long x = y; x< ll(z); x++)
using namespace std;
typedef long long ll;
typedef long double ld;	

#define maxn 1000015
const double EPS = (1e-7), EPSm= (1e7);
const ll linf = (ll)1e17 + 5;
long double PI = 3.14159265359;
int dir[8][2]={{1,0},{-1,0},{0,1},{0,-1},{-1,-1},{1,1},{-1,1},{1,-1}};
	
const int MAXN = 1e5+10;
const int NINF = -1e5;
const int INF = 20000000;

void solve()
{
	int n;
	cin>>n;
	vector<ll> v(n);
	forn(i,0,n) cin>>v[i];
	ll s=v[0],sum=0;
	forn(i,1,n){
		if(s>v[i]) sum+=(s-v[i]);
		else if(v[i]>s) s=v[i];
	}
	cout<<sum<<endl;
	return;
}


int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int test;
	//cin >> test;
	//while(test--)
		solve();
	return 0;
}


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

using ll = long long;

constexpr ll INF = 1e18;

int main() {
    string S;
    cin >> S;
    if(S.size() < 4 || S.substr(0, 4) != "YAKI") {
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;
    }
}


Measured memory_bytes: 764
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;cin>>n;
  string s,t;cin>>s>>t;
  string a="";
  for(int i=0;i<n;i++)
  {
    a+=s[i];
    a+=t[i];
  }
  cout<<a<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define INF 1e9
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(void){
    int N;
    cin>>N;
    int ans=0;
    int m=0;
    for(int i=0;i<N;i++){
        int a,b;
        cin>>a>>b;
        if(a>m){
            m=a;
            ans=a+b;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
bool isPalindrome(string s,int p,int r){
    string rev=s;
    for(int i=p;i<r;i++){
        rev[i]=s[r-i-1];
    }
    if(rev==s){
        return true;
    }else{
        return false;
    }
}
int main(){
    string s;
    cin>>s;
    int n=s.length();  
    //cout<<(n-1)/2;
    if(isPalindrome(s,0,n)){
        if(isPalindrome(s,0,(n-1)/2) && isPalindrome(s,(n+1)/2,n)){
            cout<<"Yes";
        }else{
            cout<<"No";
        }
    }else{
        cout<<"No";
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stdio.h>
#include <map>
#include <set>
#include <utility>
#include <queue>
#include <bitset>
#include <math.h>
#include <numeric>
#include <stack>

using namespace std;
 
#define rep(i,m,n) for(int i=m;i<(int)(n);i++)
#define endl '\n'
typedef long long ll;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    int Max=max(a,c);
    int Min=min(b,d);
    cout<<max(0,Min-Max)<<endl;
}


Measured memory_bytes: 256
local n,k=io.read("n","n")
local a={}
for i=1,n do
    a[i]=io.read("n")
end

local dp={}
for i=0,k do
    if not dp[i] then
        for j=1,n do
            dp[i+a[j]]=true
        end
    end
end
print(dp[k] and "First" or "Second")

Measured memory_bytes: 6172
/* long long or int & the MAX_INT or MIN_INT */
/* the size of a[] & inline */
/* xx 396 */

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

const int MAX_N=1e3+10;

int dist[MAX_N*MAX_N],N,deg[MAX_N*MAX_N];
vector <int> G[MAX_N*MAX_N];
queue <int> Q;

int get_ID(int x,int y){
	if(x>y) swap(x,y);
	return x*MAX_N+y;
}

signed main(){
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	for(int i=0;i<MAX_N*MAX_N;i++) deg[i]=-1;
	cin>>N; int last;
	for(int i=0;i<N;i++) for(int j=0;j<N-1;j++){
		int x; cin>>x; x--;
		if(!j){last=x; continue;}
		G[get_ID(i,last)].push_back(get_ID(i,x));
		if(deg[get_ID(i,last)]==-1) deg[get_ID(i,last)]=0;
		if(deg[get_ID(i,x)]==-1) deg[get_ID(i,x)]=0; 
		deg[get_ID(i,x)]++; last=x;
	}
	for(int i=0;i<MAX_N*MAX_N;i++) if(deg[i]==0) Q.push(i),dist[i]=1;
	while(!Q.empty()){
		int fr=Q.front(); Q.pop(); 
		for(int i=0;i<G[fr].size();i++){
			int to=G[fr][i];
			dist[to]=max(dist[to],dist[fr]+1);
			deg[to]--;
			if(deg[to]==0) Q.push(to);
		}
	}
	int ans=0;
	for(int i=0;i<MAX_N*MAX_N;i++) if(deg[i]>0) ans=-1;
	if(ans<0){cout<<ans<<endl; return 0;}
	for(int i=0;i<MAX_N*MAX_N;i++) ans=max(ans,dist[i]);
//	for(int i=0;i<MAX_N*MAX_N;i++) if(dist[i]>0) cout<<i/MAX_N+1<<" "<<i%MAX_N+1<<" "<<dist[i]<<endl;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 47744
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


ll N,M;
long double dp[21][121];

long double POW(long double x,ll count){

	if(count == 0){
		return 1.0;
	}else if(count % 2 == 0){
		return POW(x*x,count/2);
	}else{
		return x*POW(x,count-1);
	}
}

void func(){

	long double E = 0.0,next_E,A,P,POW_P;
	ll index = 0,next_index;
	ll left,right,mid;

	while(index < M){

		A = 0; //基準値(現在期待値)より大きい出目の、期待値的加重平均
		P = 0; //出目が現在期待値以下となる確率

		for(ll i = N; i <= 6*N; i++){

			if(i <= E){ //基準値以下→確率集計

				P += dp[N][i];

			}else{ //基準値より大きい

				A += i*dp[N][i];
			}
		}

		if(P == 1.0){ //未来確定
			printf("%.10Lf\n",E);
			return;
		}

		//期待値の整数部が増加する、最小のインデックスを求める
		left = index+1,right = M,mid = (left+right)/2;
		next_index = M;

		while(left <= right){

			POW_P = POW(P,mid-index);
			next_E = (A*(1.0-POW_P))/(1.0-P)+POW_P*E;

			if(floor(next_E) > floor(E)){

				next_index = mid;
				right = mid-1;

			}else{
				left = mid+1;
			}
			mid = (left+right)/2;
		}

		POW_P = POW(P,next_index-index);
		next_E = (A*(1.0-POW_P))/(1.0-P)+POW_P*E;

		E = next_E;
		index = next_index;
	}
	printf("%.10Lf\n",E);
}

void calcDP(){

	for(int num = 0; num <= 20; num++){
		for(int value = 0; value <= 120; value++){
			dp[num][value] = 0;
		}
	}

	dp[0][0] = 1.0; //dp[サイコロの数][出目の合計] = 確率
	for(int num = 0; num <= 19; num++){
		for(int value = 0; value <= 114; value++){
			for(int dice = 1; dice <= 6; dice++){
				dp[num+1][value+dice] += dp[num][value]/6.0;
			}
		}
	}
}

int main(){

	calcDP();

	while(true){
		scanf("%lld %lld",&N,&M);
		if(N == 0 && M == 0)break;

		func();
	}

	return 0;
}



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

using namespace std;

int main() {
    int n;
    cin>>n;
    
    int d[n][2];
    
    for(int i=0;i<n;i++)
        for(int j=0;j<2;j++)
            cin>>d[i][j];
    
    bool flag=0;
    int c=0;
    for(int i=0;i<n;i++){
        if(d[i][0]==d[i][1])
            c++;
        else
            c=0;
        if(c==3){flag=1; break;}
    }
    
    if(flag)
        cout<<"Yes";
    else
        cout<<"No";
}

Measured memory_bytes: 3620
#include <iostream>
#include <vector>
#include <algorithm>
#define REP(i,n) for(int i=0;i<n;i++)
#define unsigned long ul
using namespace std;

int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
   	int a,b;
    cin >> a >> b;
    int m = max(a, b);
    if(abs(a-b)>=2){
        cout << m*2-1 << endl;
    }else{
        cout << a+b << endl;
    }
	return 0;
}


Measured memory_bytes: 256
from functools import lru_cache
import sys
sys.setrecursionlimit(20000000)
N = int(input())
heights = [int(h) for h in input().split()]


# heights = [10, 30, 40, 20]

# heights = [10, 10]
# heights = [30, 10, 60, 10, 60, 50]
# 记忆化
@lru_cache(None)
def dfs(i):
    if i == len(heights) - 1:
        return 0
    return min(abs(heights[i] - heights[i + 1]) + dfs(i + 1) if i + 1 < len(heights) else float("inf"),

               abs(heights[i] - heights[i + 2]) + dfs(i + 2) if i + 2 < len(heights) else float("inf"))


print(dfs(0))


Measured memory_bytes: 268484