akhauriyash/Code-Regression huggingface dataset:
#include<vector>
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include <iostream>
#include <algorithm>
#include <map>
#include <cmath>
#define INF 100000000000000
using namespace std;
typedef long long llong;

//int isalpha(char ch): ch がアルファベットなら true を返す
//int isdigit(char ch): ch が数字なら true を返す
//int islower(char ch): ch が小文字なら true を返す
//int isupper(char ch): ch が大文字なら true を返す
//int tolower(char ch): ch の小文字を返す
//int toupper(char ch): ch の大文字を返す

//string型
//size()	文字数を返す
//insert()	（指定した場所に）文字・文字列を挿入する
//erase()	（指定した場所の）文字・文字列を削除する
//clear()	すべての文字を削除する
//substr()	文字列の（指定した）部分文字列を返す
//replace()	（指定した）部分文字列を新しい文字列に置換する
//文字列の比較は、<=や==などを使え
//replace関数を使い、簡単に文字列を置換
//リバース関数：reverse(str.begin(), str.end());
//map<type, type> dict;で宣言
//グラフ理論用変数
//vector<vector<llong> > graph(N);

//ソート
//降順sort(v.begin(), v.end(), std::greater<Type>());

//大文字から小文字へんかん
//w[i] = w[i]-'A'+'a';

int main(){
    llong H,W;
    string s;
    vector<string> S;
    llong cnt;
    cin >> H >> W;
    for(int i=0; i<H; i++){
        cin >> s;
        S.push_back(s);
    }
    for(int i=0; i<H; i++){
        for(int j=0; j<W; j++){
            if(S[i][j]=='#'){
                continue;
            }
            cnt = 0;
            for(int dy=-1; dy<2; dy++){
                for(int dx=-1; dx<2; dx++){
                    if(dy+i>=H || dx+j>=W || dy+i<0 || dx+j<0){
                        continue;
                    }
                    if(S[dy+i][dx+j]=='#'){
                        cnt++;
                    }
                }
            }            
            S[i][j]=cnt+'0';
        }
    }
    for(int i=0; i<S.size(); i++){
        cout << S[i] << endl;
    }
}

Measured memory_bytes: 3112
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < int(n); i++)
#define vi vector<int>
#define all(x) (x).begin(),(x).end()
#define INF (1<<30)-1
using ll = long long;
using namespace std;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
template<class T> inline bool chmax(T &a, const T &b){ if(a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b){ if(b<a) { a=b; return 1; } return 0; }

int main(){
  cin.tie(0), ios::sync_with_stdio(false);
  int n; cin >> n;
  string s; cin >> s;

  const int MOD = 1e9+7;
  map<char,int> mp;
  rep(i,n) mp[s[i]]++;
  ll ans = 1;
  for(auto x : mp){
    ans *= x.second+1;
    ans %= MOD;
  }
  cout << ans-1;
  cout << "\n";
  return 0;
}


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


int main(){
    int i,j,k,room[4][3][10];
    for(i=0;i<4;i++){
        for(j=0;j<3;j++){
            for(k=0;k<10;k++){
                room[i][j][k]=0;
            }
        }
    }
    int number,b,f,r,v;
    cin>>number;
    for(i=0;i<number;i++){
        cin>>b>>f>>r>>v;
        room[b-1][f-1][r-1]+=v;     
    }
    for(j=0;j<3;j++){
        for(k=0;k<10;k++){
            cout<<" "<<room[0][j][k];
        }
        cout<<endl;
    }
    cout<<"####################"<<endl;
    for(j=0;j<3;j++){
        for(k=0;k<10;k++){
            cout<<" "<<room[1][j][k];
        }
        cout<<endl;
    }
    cout<<"####################"<<endl;
    for(j=0;j<3;j++){
        for(k=0;k<10;k++){
            cout<<" "<<room[2][j][k];
        }
        cout<<endl;
    }
    cout<<"####################"<<endl;
    for(j=0;j<3;j++){
        for(k=0;k<10;k++){
            cout<<" "<<room[3][j][k];
        }
        cout<<endl;
    }    
    return 0;
}


Measured memory_bytes: 3092
# coding: utf-8
N = int(input())

max_4 = int(N / 4)
max_7 = int(N / 7)

yes = 0

for i in range(max_4+1):
    for j in range(max_7+1):
        if i*4 + j*7 == N:
            yes = 1
            break

if yes == 1:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}

fn main() {
    let n: usize = read();
    let grid: Vec<Vec<usize>> = (0..n).map(|_| read_vec::<usize>().iter().cloned().collect()).collect();

    let mut lengths = Vec::new();
    for i in 0..n - 1 {
        for j in i..n {
            lengths.push((grid[i][j], i, j));
        }
    }
    lengths.sort();

    let mut constructed_roads = std::collections::HashSet::new();
    let mut ans = 0;

    for (length, i, j) in lengths {
        let mut min_constructed_length = std::usize::MAX;
        for k in 0..n {
            if constructed_roads.contains(&(i, k)) && constructed_roads.contains(&(j, k)) {
                min_constructed_length = std::cmp::min(grid[i][k] + grid[j][k], min_constructed_length);
            }
        }
        if length > min_constructed_length {
            println!("-1");
            return;
        }
        if length < min_constructed_length {
            ans += length;
        }
        constructed_roads.insert((i, j));
        constructed_roads.insert((j, i));
    }
    println!("{:?}", ans);
}


Measured memory_bytes: 14588
import numpy as np

N=int(input())
L=np.array(list(map(int,input().split())))
L.sort(axis=0)
c=0
for i,L1 in enumerate(L):
  for j,L2 in enumerate(L[i+1:]):
    if L1==L2:
      continue
    c+=np.count_nonzero(L[i+j+2:]<L1+L2)-np.count_nonzero(L[i+j+2:]==L2)
print(c)

Measured memory_bytes: 27164
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define IO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
using namespace std;
const int N = 5e3 + 5, M = 3e5 + 5;


ull base = 29;
inline void pushBack(ull& h, ull base, char c){
	h = ((h*base) + c);
}

int n;
string s;

ull mp[N][N];

bool valid(int len){
    for(int i = 0 ; i < n ; ++i)
        for(int j = i + len ; j < n ; ++j)
            if(mp[i][len] == mp[j][len])
                return true;
    return false;
}

int bs(){
    int l = 0, r = n - 1, mid, ans = 0;
    while(l <= r){
        mid = (l + r) / 2;
        if(valid(mid)){
            ans = mid;
            l = mid + 1;
        }
        else r = mid - 1;
    }
    return ans;
}

int main(){
    IO;
    cin >> n;
    cin >> s;
    for(int i = 0 ; i < n ; ++i){
        ull h = 0;
        for(int j = i ; j < n ; ++j){
            pushBack(h, base, s[j]);
            mp[i][j - i + 1] = h;
        }
    }
    printf("%d\n", bs());
}


Measured memory_bytes: 194944
#include <iostream>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
using namespace std;
typedef pair<int, int> P;
typedef long long ll;
const int MOD = 1000000007;

int main(){
  int n, max = 0, max_index = 0, sub_max = 0, num;
  cin >> n;
  for(int i=0;i<n;i++){
    cin >> num;
    if(num >= max && num > sub_max){
      sub_max = max;
      max = num;
      max_index = i;
    }else if(num <= max && num > sub_max){
      sub_max = num;
    }
  }
  for(int i=0;i<n;i++){
    if(i == max_index) cout << sub_max << "\n";
    else cout << max << "\n";
  }
}



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

int N;
const int MAX_N = 1.0e5 + 100;
ll A[MAX_N];

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

    vector<ll> x;
    ll S = 0;
    for (int i = 0; i < N; i++) {
        S += A[i];
    }

    ll x0 = S;
    for (int i = 1; i < (N+1)/2; i++) {
        x0 -= 2*A[2*i - 1];
    }

    x.push_back(x0);

    for (int i = 1; i < N; i++) {
        ll x_i = 2*A[i-1] - x[i-1];
        x.push_back(x_i);
    }

    for (int i = 0; i < N; i++) {
        cout << x[i] << " ";
    }
    cout << endl;
    
    return 0;
}


Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <array>
#include <cmath>
#include <iterator>
#include <utility>
#include <set>
#include <random>
#include <map>
#include <stack>
#include <queue>
#include <list>

using namespace std;

int main() {
    string s, result;
    //vector<char> vec;
    cin >> s;
    for (unsigned int i = 0; i < s.length(); i++)
    {
        if (s[i] == 'B' && !result.empty())
        {
            result.pop_back();
        }
        else if (s[i] != 'B')
        {
            result.push_back(s[i]);
        }
    }
    cout << result << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

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

        int sumsum = 0;

        while (true) {


            int n = sc.nextInt();
            sumsum += n;
            if( n == 0 || sumsum > 50000) {
                break;
            }
            int sum = 0;
            int[] array = new int[n];

            for (int i = 0; i < n; i++) {
                array[i] = sc.nextInt();
                sum += array[i];
            }

            int ave = sum / n;

            int num = 0;
            for ( int i = 0; i < n; i++ ) {
                if( array[i] <= ave ) {
                    num++;
                }
            }

            System.out.println(num);


        }
        sc.close();

    }

}



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

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

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

#define int long long
#define otp(n) cout << n;
#define ct(n) cout << n << endl;
#define cts(n) cout << n << " ";
#define cte cout << endl;
#define ctv(v) rep(i,(v).size()) otp(v[i]) cte
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define repo(i,o,n) for(int i=o;i<n;i++)
#define repm(i,n) for(int i=n-1;i>=0;i--)
#define repv(i,v) for(int i=0;i<(v).size();i++)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end());
#define vdelete(v) (v).erase(unique(all(v)), (v).end());
#define vcopy(v1,v2) copy((v1).begin(), (v1).end(), back_inserter((v2)));
#define pb(n) push_back(n);

int h,w;
char c[100][100];

main() {
    cin >> h >> w;
    rep(i,h) rep(j,w) cin >> c[i][j];
    rep(i,h*2) {
        rep(j,w) otp(c[i/2][j])
        cte
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define Mashu cout << "UUZ ate it." << endl
#define RE register int
#define ll long long
using namespace std;

int mn[800010][2];
int vis[200010][2];
long long n;
int ans;

int lc(int x){
	return x << 1;
}

int rc(int x){
	return x << 1 | 1;
}

void pushup(int k, int ovo){
	mn[k][ovo] = min(mn[lc(k)][ovo], mn[rc(k)][ovo]);
}

void build(int k, int l, int r){
	if (l == r){
		mn[k][1] = n - 1;
		mn[k][0] = n - 1;
		return;
	}
	int mid = (l + r) >> 1;
	build(lc(k), l, mid);
	build(rc(k), mid + 1, r);
	pushup(k, 1);
	pushup(k, 0);
}

void change(int k, int l, int r, int L, int x, int ovo){
	if (l == r && l == L){
		mn[k][ovo] = min(mn[k][ovo], x);
		return;
	}
	int mid = (l + r) >> 1;
	if (L <= mid){
		change(lc(k), l, mid, L, x, ovo);
	}
	else{
		change(rc(k), mid + 1, r, L, x, ovo);
	}
	pushup(k, ovo);
}

void query(int k, int l, int r, int L, int R, int ovo){
	if (L <= l && r <= R){
		ans = min(ans, mn[k][ovo]);
		return;
	}
	int mid = (l + r) >> 1;
	if (L <= mid){
		query(lc(k), l, mid, L, R, ovo);
	}
	if (R >= mid + 1){
		query(rc(k), mid + 1, r, L, R, ovo);
	}
}

int main(){
	int q;
	cin >> n >> q;
	build(1, 1, n - 1);
	long long now = (n - 2) * (n - 2);
	for (int i = 1; i <= q; i++){
		int opt, k;
		cin >> opt >> k;
		ans = INT_MAX;
		if (opt == 1){
			if (vis[k][0]) continue;
			query(1, 1, n - 1, k, n, 0);
			change(1, 1, n - 1, ans, k - 1, 1);
			vis[k][0] = 1;
			now -= ans - 1;
		}
		else{
			if (vis[k][1]) continue;
			query(1, 1, n - 1, k, n, 1);
			change(1, 1, n - 1, ans, k - 1, 0);
			vis[k][1] = 1;
			now -= ans - 1;
		}
	}
	cout << now << endl;
	return 0;
	Mashu;
}

Measured memory_bytes: 9240
N = int(input())
As = list(map(int,input().strip().split()))


flag = True

while(flag):
    As = sorted(As)
    for i in range(1,len(As)):
        As[i] %= As[0]

    As = list(filter(lambda  x: x > 0, As))
    if len(As) == 1:
        flag = False

print(As[0])


Measured memory_bytes: 15020
A = []
for i in range(3):
    a = input().split()
    a = [int(x) for x in a]
    A.append(a)
N = int(input())

for _ in range(N):
    b = int(input())
    for i in range(3):
        for j in range(3):
            if A[i][j] == b:
                A[i][j] = 0
T = 'No'
for i in range(3):
    if sum(A[i]) == 0:
        T = 'Yes'
        break
    s = 0
    for j in range(3):
        s += A[j][i]
    if s == 0:
        T = "Yes"
if A[0][0]+A[1][1]+A[2][2] == 0 or A[0][2]+A[1][1]+A[2][0] == 0:
    T = 'Yes'
print(T)

Measured memory_bytes: 3188
import java.util.*;

public class Main {

	public static void main(String[] args) {
	
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] emp = new int[N];
		int A;
		for(int i = 2 ; i < N + 1; i++) {
			A = sc.nextInt() -1;
			emp[A]++; 
		} 
		for(int res : emp) {
			System.out.println(res);
		}
	}
	
}

Measured memory_bytes: 60232
#include<cstdio>
#define clz 1000000007
using namespace std;
int n,c,a[405],b[405],q[405][405],s[405][405],f[405][405],ans;
int main(){
	//freopen("candies.in","r",stdin);
	//freopen("candies.out","w",stdout);
	scanf("%d%d",&n,&c);
	for(int i=1;i<=400;i++){
		q[i][0]=1;
		for(int j=1;j<=400;j++) q[i][j]=(1ll*q[i][j-1]*i)%clz;
	}
	for(int i=0;i<=400;i++){
		s[i][0]=1;
		for(int j=1;j<=400;j++)
			s[i][j]=(s[i][j-1]+q[j][i])%clz;
	}
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	for(int i=1;i<=n;i++) scanf("%d",&b[i]);
	f[0][0]=1;
	for(int i=1;i<=n;i++)
		for(int j=0;j<=c;j++)
			for(int k=0;k<=j;++k)
				f[i][j]=(1ll*f[i][j]+1ll*f[i-1][k]*((s[j-k][b[i]]-s[j-k][a[i]-1]+clz)%clz))%clz;
	printf("%d",f[n][c]);
}

Measured memory_bytes: 2048
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef set<int> si;
typedef map<string, int> msi;
typedef long long ll;
const ll INF = 1e18L + 1;

int main() {
  int H,W;
  cin >> H >> W;
  ll ans = 0;
  if (H!=1&&W!=1){
    ans += ceil((double)H / 2) * ceil((double)W / 2);
  ans += floor((double)H / 2) * floor((double)W / 2);
  }else
    ans = 1;

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

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

using namespace std;

#define M 1000000007
#define pb push_back
#define f first
#define s second
#define rep(i, st, ed) for(int i=st; i<ed; i++)
#define repn(i, st, ed) for(int i=st; i<=ed; i++)
#define repb(i, ed, st) for(int i=ed; i>=st; i--)

typedef long long ll;
typedef unsigned long long int llt;

const int N = 5e5 + 10;

vector<int> g[N];
bool viss[N];
int vis[N];

// Normal DFS
void dfs(int curr, int par)
{
  for(auto x: g[curr])
    if(x != par)
      dfs(x, curr);
}

// DFS with visiting status
void dfs1(int curr, int par)
{
  viss[curr] = 1;
  for(auto x: g[curr])
    if(!viss[x])
      dfs1(x, curr);
}

// DFS with strongly connected component
void dfs2(int curr, int par, int num)
{
  vis[curr] = num;
  for(auto x: g[curr])
    if(vis[x] == 0)
      dfs2(x, curr, num);
}

// XOR from 0 to n
ll fxor(ll n)
{
  if(n < 0) return 0;
  if(n % 4 == 3) return 0;
  else if(n % 4 == 0) return n;
  else if(n % 4 == 1) return n^(n-1);
  else if(n%4 == 2) return n^(n-1)^(n-2);
}

// Power in logn with mod 1000000007
llt ppow(llt x, llt y)
{
  llt res = 1;
  while(y > 0){
    if(y&1)
      res = (res * x)%M;
    y = y >> 1;
    x = (x * x)%M;
  }
  return res;
}

// Factorial with dp
llt factdp[N];
llt fact(llt x)
{
  if(x == 0) return 1;
  if(x == 1) return 1;
  if(factdp[x] != -1) return factdp[x];
  return factdp[x] = (x*fact(x-1))%M;
}

// String return to base b
string ansConv ="";
void convert10tob(llt N, int b)
{
     if (N == 0)
        return;
     int x = N % b;
     N /= b;
     if (x < 0)
        N += 1;
     convert10tob(N, b);
     ansConv += to_string(x);
     return;
}

// Convert string to num wiht base b
llt convertstrtob(string a, int b)
{
  llt aa = 0;
  llt mul = 1;
  for(int i=a.length()-1; i>=0; i--)
  {
    int curr = a[i] - '0';
    aa += (curr * mul);
    mul *= b;
  }
  return aa;
}

// Union Find algo with array
// Find()
int findpar(int curr, int arr[])
{
  while(arr[curr] != curr) curr = arr[curr];
  return curr;
}
// Union()
void Union(int b, int spa, int arr[])
{
  while(arr[b] != b)
  {
    int c = arr[b];
    arr[b] = spa;
    b = c;
  }
  arr[b] = spa;
}

// Main Code

int main()
{
  int a, b;
  cin>>a>>b;
  if(a >= 10 || b>= 10) puts("-1");
  else cout<<(a*b)<<endl;
  return 0;
}


Measured memory_bytes: 12160
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <queue>
#include <cmath>
#include <memory.h>

using namespace std;

typedef long long ll;

int used[26];

int main(){
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  string str; cin >> str;
  for(int i=0;i<26;i++) used[i] = 100;
  for(int i=0;i<str.size();i++){
    used[str[i] - 'a'] = i;
  }
  if(str.size() < 26){
    int unused = -1;
    for(int i=0;i<26;i++){
      if(used[i] == 100){
        unused = i;
        break;
      }
    }
    char t = unused + 'a';
    cout << str << t << endl;
  }else if(str == "zyxwvutsrqponmlkjihgfedcba"){
    cout << -1 << endl;
  }else{
    int i, j;
    for(i=25;i>=0;i--){
      for(j=str[i] - 'a';j<26;j++){
        if(used[j] > i) goto LABEL;
      }
    }
    LABEL:
    // cout << i << " " << j << endl;
    char last = j + 'a';
    cout << str.substr(0, i) << last << endl;
  }
}

Measured memory_bytes: 256
//code by lynmisakura.wish to be accepted!
/****************************/
#include<iostream>
#include<iomanip>
#include<math.h>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>
#include<algorithm>
#include<bitset>
#include <climits>
#include<set>
#include<bitset>
using namespace std;
/***************************/
typedef long long ll;
typedef long long ijt;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef pair<int, int> pi;
typedef vector<pair<int, int>> vpi;

const long long INF = 1LL << 55;

#define itn int
#define endl '\n'
#define pb push_back
#define mp make_pair
#define ss second
#define ff first
#define dup(x,y) ((x) + (y) - 1)/(y)
#define mins(x,y) x = min(x,y)
#define maxs(x,y) x = max(x,y)
#define all(x) (x).begin(),(x).end()
#define Rep(n) for(int i = 0;i < n;i++)
#define rep(i,n) for(int i = 0;i < n;i++)
#define rrep(i,n) for(int i = n - 1;i >= 0;i--)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll qp(ll a, ll b) { ll ans = 1; do { if (b & 1)ans = 1ll * ans*a; a = 1ll * a*a; } while (b >>= 1); return ans; }
ll qp(ll a, ll b, int mo) { ll ans = 1; do { if (b & 1)ans = 1ll * ans*a%mo; a = 1ll * a*a%mo; } while (b >>= 1); return ans; }

#define _GLIBCXX_DEBUG
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int main(void) {
	ijt n;cin >> n;
	vector<ijt> a(n+1);
	ijt sum = 0;
	rep(i, n) {
		cin >> a[i+1];
		sum += a[i+1];
	}
	if (n == 1) {
		cout << "YES" << endl;
		return 0;
	}
	ijt m;
	if (sum % (n*(n + 1) / 2) != 0) {
		cout << "NO" << endl;
		return 0;
	}
	else {
		m = sum / (n*(n+1)/2);
	}

	for (int i = 1; i <= n; i++) {
		if (a[i] < m or a[i] > n*m) {
			cout << "NO" << endl;
			return 0;
		}
	}

	ijt xsum = 0;
	for (int i = 1; i <= n; i++) {
		if (i != n) {
			ijt d = a[i+1] - a[i];
			if (((n-1)* m + d) % n != 0) {
				cout << "NO" << endl;return 0;
			}
			else {
				xsum += ((n-1)*m + d)/n;
			}
		}
		else {
			ijt d = a[1] - a[n];
			if (((n - 1)* m + d) % n != 0) {
				cout << "NO" << endl; return 0;
			}
			else {
				xsum += ((n - 1)*m + d) / n;
			}
		}
	}
	if (xsum != m*(n-1)) {
		cout << "NO" << endl;
	}
	else {
		cout << "YES" << endl;
	}
	return 0;
}

Measured memory_bytes: 1024
n = int(input())
A = list(map(int,input().split()))

def partition(A,p,r):
    x = A[r]
    i = p-1
    for j in range(p,r):
        if A[j] <= x:
            i += 1
            A[i],A[j] = A[j],A[i]
    A[i+1],A[r] = A[r],A[i+1]
    return i+1

q = partition(A,0,n-1)
print(*A[:q],end=' ')
print('[{0}]'.format(A[q]),end=' ')
print(*A[q+1:])

Measured memory_bytes: 18428
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;
import std.container;

ulong MOD = 1_000_000_007;
ulong INF = 1_000_000_000_000;
alias sread = () => readln.chomp();
alias TOWN = Tuple!(long, "x", long, "y");

void main()
{
    auto n = lread();
    auto s = sread();
    foreach(e; s)
    {
        auto next = (e - 'A' + n) % 26;
        write(('A' + next).to!(char));
    }
    writeln();
}

T lread(T = long)()
{
    return readln.chomp.to!T();
}

T[] aryread(T = long)()
{
    return readln.split.to!(T[])();
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}

long product_MOD(long n)
{
    long p_MOD = 1;
    while (n > 0)
    {
        p_MOD *= n--;
        p_MOD %= MOD;
    }
    return p_MOD;
}


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

using namespace std;

#define INPUT_OUTPUT { \
	freopen("input.txt", "r", stdin); \
	freopen("output.txt", "w", stdout); \
}

int main()
{
	//INPUT_OUTPUT;
	string s;
	cin >> s;
	if(s == "SAT") cout << "1" << endl;
	else if(s == "FRI") cout << "2" << endl;
	else if(s == "THU") cout << "3" << endl;
	else if(s == "WED") cout << "4" << endl;
	else if(s == "TUE") cout << "5" << endl;
	else if(s == "MON") cout << "6" << endl;
	else if(s == "SUN") cout << "7" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
 
int main() {
	int n,a[110];
	cin>>n;
	for (int i=0;i<n;i++){
		cin>>a[i];
	}
	for (int j=n-1;j>=0;j--){
		cout<<a[j];
		if (j>0){
			cout<<" ";
		}
	}
	cout<<endl;
}


Measured memory_bytes: 3084
import heapq

MAX = 10000
WHITE = 0
GRAY = 1
BLACK = 2
INF = float('inf')
color = [WHITE for _ in range(MAX)]
d = [INF for _ in range(MAX)]
adj = [None for _ in range(MAX)]
n = 0


def main():
    global n
    n = int(input())

    for _ in range(n):
        u, k, *n_s = map(int, input().split(' '))
        adj[u] = ([(n_s[2*j], n_s[2*j+1]) for j in range(k)])

    dijkstra(0)

    for i in range(n):
        print(f'{i} {d[i] if d[i] != INF else -1}')


def dijkstra(s):
    d[s] = 0

    pq = []

    heapq.heappush(pq, (0, s))

    while len(pq) > 0:
        f = heapq.heappop(pq)
        u = f[1]

        color[u] = BLACK
        if d[u] < f[0]:
            continue

        for j in range(len(adj[u])):
            v = adj[u][j][0]
            if color[v] == BLACK:
                continue
            if d[v] > d[u] + adj[u][j][1]:
                d[v] = d[u] + adj[u][j][1]
                heapq.heappush(pq, (d[v], v))
                color[v] = GRAY


if __name__ == '__main__':
    main()



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

#define iter(i, a, b) for(int i=(a); i<(b); i++)
#define rep(i, a) iter(i, 0, a)
#define rep1(i, a) iter(i, 1, (a)+1)
#define log(a) cerr<<"\033[32m[DEBUG] "<<#a<<'='<<(a)<<" @ line "<<__LINE__<<"\033[0m"<<endl
#define all(a) a.begin(), a.end()
#define fi first
#define se second
#define pb push_back
#define mp make_pair

using ll=long long;
using pii=pair<int, int>;
#define int ll
const int MOD = 1000000007;

int bit[200005]; int N;

void upd(int x, int v) { x++; while(x <= N) { bit[x] += v; x += (-x&(x)); } }
int get(int x) { x++; int ans = 0; while(x) { ans += bit[x]; x -= (-x&(x)); } return ans; }

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    int dia, A; cin >> N >> dia >> A;
    vector<pii> v;
    rep(i, N) {
        int loc, ne; cin >> loc >> ne;
        ne = (ne + A - 1) / A;
        v.pb({loc, ne});
    }
    sort(all(v));
    int ans = 0;
    rep(i, N) {
        if(get(i) >= v[i].se) continue;
        // bin search for last index <= than v[i].fi+2*dia
        int targ = v[i].fi+2*dia;
        int lef = i, rig = N-1, ban = i;
        while(lef <= rig) {
            int mid = (lef+rig)/2;
            if(v[mid].fi > targ) rig = mid-1;
            else { lef = mid+1; ban = mid; }
        }
        int dt = v[i].se-get(i);
        ans += dt;
        upd(i, dt); upd(ban+1, -dt);
    }
    cout << ans << endl;    
}


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

using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
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; }
typedef unsigned short us;
int main(){
    clock_t start=clock();
    int n;
    cin>>n;
    int a[n][n];rep(i,n)rep(j,n) a[i][j]=-1;
    rep(i,n){
        rep(j,n-1){
            cin>>a[i][j];a[i][j]--;
        }
    }
    
    //0~n-1人の試合の進行度
    int index[n]={};
    //1日たって何も進捗が埋めなければ-1出す用の旗
    bool update;
    for(int day=1;day<=n*(n-1)/2;day++){
        update=false;
        set<pair<int,int>> s;
        //今日まだ試合できるか
        bool can[n];
        rep(i,n) can[i]=true;
        for(int i=0;i<n;i++){
            if(index[i]>n-2) continue;
            if(!s.count(make_pair(a[i][index[i]],i))) s.insert(make_pair(i,a[i][index[i]]));
            else{
                update=true;
            }
        }
        vector<pair<int,int>> match;
        for(int i=0;i<n;i++){
            if(s.count(make_pair(a[i][index[i]],i))&&can[i]&&can[a[i][index[i]]]){
                //cout<<"DAY:"<<day<<" match:"<<i<<"-"<<a[i][index[i]]<<endl;
                match.push_back(make_pair(i,a[i][index[i]]));
                can[i]=false;can[a[i][index[i]]]=false;
            }
        }
        for(auto x:match){
            index[x.first]++;index[x.second]++;
        }
        if(!update){
            puts("-1");return 0;
        }
        //rep(i,n){cout<<index[i]<<' ';}cout<<endl;
        bool f=true;
        rep(i,n){
            if(index[i]!=n-1){f=false;break;}
        }
        if(f){
            cout<<day<<endl;return 0;
        }
        double ttt=(double)(clock()-start)/CLOCKS_PER_SEC;
        if(ttt>1.2){
            cout<<n*(n-1)/2<<endl;return 0;
        }
    }
    cout<<(n*(n-1)/2)<<endl;
    return 0;
}

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

int main(){
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    
    while(1){
        c-=b;
        if(c<=0){
            cout<<"Yes\n";
            break;
        }
        a-=d;
        if(a<=0){
            cout<<"No\n";
            break;
        }
    }
    
    return 0;
}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0,i##_len=(int)(n);i<i##_len;i++)
#define rep1(i,n)for(int i=1,i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=(int)(n)-1;0<=i;i--)
#define rrep1(i,n) for(int i=(int)(n);1<=i;i--)

#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define all(obj) (obj).begin(),(obj).end() 

#define pcount __builtin_popcount
#define SZ(x) ((int)(x).size())
#define LEN(x) ((int)(x).length())

#define dump(x)  cerr << #x << " = " << (x) << endl;

#define endl "\n"

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

typedef long long lint;

using namespace std;
int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	map<lint,lint>m;
	lint n,sum=0;
	cin>>n;
	vector<lint>a(n);
	rep(i,n)cin>>a.at(i);
	rep(i,n){
		if(m.count(a.at(i))){
			m.at(a.at(i))++;
		}else{
			m.emplace(a.at(i),1);
		}
	}
	each(it,m){
		lint num=(*it).second;
		sum+=num*(num-1)/2;
	}
	rep(i,n){
		lint num=m.at(a.at(i));
		cout<<sum-(num-1)<<endl;
	}
}

Measured memory_bytes: 11136
#include<bits/stdc++.h> 
typedef long long ll;
using namespace std; 
int main()
{
    set<string> s;
    string ss;
    int n;
    cin>>n;
    for (int i = 0; i < n; ++i)
    {
        cin>>ss;
        s.insert(ss);
    }
    cout<<s.size()<<endl;
    
    return 0;
}


Measured memory_bytes: 19180
import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;


public class Main {
	
	public static void main(String[] args) throws IOException {
		new Main().exec();
	}
	
	public void exec() throws IOException {
		InputUtil in = new InputUtil();
		PrintWriter out = new PrintWriter(System.out);
		int N = in.nextInt();
		boolean ans = ((N/10==9) || (N%10==9));
		out.println(ans?"Yes":"No");
		out.flush();
	}
}


class InputUtil {
	//Static Fields
	private static final int BUFSIZ = 100000;
	
	//Fields
	protected InputStream in;
	private byte[] buf = null;
	private int ptr = 0;
	private int max = -1;
	private DataInputStream dis = null;
	//Constructors
	public InputUtil() {this(System.in,BUFSIZ);}
	public InputUtil(InputStream in, int bufsiz) {
		initBuf(bufsiz);
		initIn(in);
	}
	
	//Methods
	//Initializer
	protected void initIn(InputStream in) {dis = new DataInputStream(this.in = in);}
	protected void initBuf(int bufsiz) {buf = new byte[bufsiz];}
	
	//buffer operation
	private void next() throws IOException {ptr++; readBuf();}
	private void readBuf() throws IOException {
		if(ptr >= max && dis.available()>0) {
			if(max>0) Arrays.fill(buf,0,max,(byte)0);
			max = dis.read(buf);
			ptr = 0;
		}
	}
	
	//Number Input Reader/Parser
	private boolean isNum(byte b) {return '0' <= b && b <= '9'; }
	private boolean isMinus(byte b) {return b=='-'; }

	private int _nextInt() throws IOException {
		int sign = 1;
		int res = 0;
		byte c;
		while (!isNum(c=buf[ptr]) && !isMinus(c)) 
			next();
		if (isMinus(buf[ptr])) {
			sign = -1;
			next();
		}
		while (isNum(c=buf[ptr])) {
			res *= 10;
			res += c - '0' ;
			next();
		}
		next();
		return sign * res;
	}
	
	public int nextInt() throws IOException {
		readBuf();
		return _nextInt();
	}

	public int[] nextInt(int[] result) throws IOException {
		readBuf();
		for(int i=0; i<result.length; i++) {
			result[i] = _nextInt();
		}
		return result;
	}
	
	//Close 
	public void close() throws IOException {
		if(!this.in.equals(System.in)) 
			this.in.close();
	}

}

Measured memory_bytes: 21076
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;

struct Dice{
    int north;
    int south;
    int east;
    int west;
    int top;
    int bottom;
};

int main(){

    int n;
    while(cin>>n&&n!=0){
        Dice d;
        d.top=1;
        d.north=2;
        d.west=3;
        d.bottom=6;
        d.south=5;
        d.east=4;
        for(int i = 0; i < n; i++){
            string str;
            cin>>str;
            if(str=="north"){
                int tmp=d.top;
                d.top=d.south;
                d.south=d.bottom;
                d.bottom=d.north;
                d.north=tmp;
            }
            else if(str=="west"){
                int tmp=d.top;
                d.top=d.east;
                d.east=d.bottom;
                d.bottom=d.west;
                d.west=tmp;
            }
            else if(str=="east"){
                int tmp=d.top;
                d.top=d.west;
                d.west=d.bottom;
                d.bottom=d.east;
                d.east=tmp;
            }
            else if(str=="south"){
                int tmp=d.top;
                d.top=d.north;
                d.north=d.bottom;
                d.bottom=d.south;
                d.south=tmp;
            }
        }
        cout<<d.top<<endl;
    }

    return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<algorithm>
using namespace std;
struct P{
	int p,y,d;
	int b[15];
};
int cmp(P x1,P x2){
	if(x1.p==x2.p){
		return x1.y<x2.y;
	}
	return x1.p<x2.p;
}
int cmp1(P x1,P x2){
	return x1.d<x2.d;
}
P a[100010];
int main(){
	int n,m,i,j,k;
	cin >> n >> m;
	for(i=0;i<m;i++){
		cin >> a[i].p >> a[i].y;
		a[i].d=i;
		for(j=0;j<13;j++){
			a[i].b[j]=0;
		}
	}
	sort(a,a+m,cmp);
	int x=1,w;
	for(i=0;i<m;i++){
		if(i==0 || a[i].p!=a[i-1].p){
			x=1;
		}
		else{
			x++;
		}
		j=5;
		w=a[i].p;
		while(w){
			a[i].b[j]=w%10;
			w/=10;
			if(j==0)
				break;
			j--;
		}
		w=x;
		j=11;
		while(w){
			a[i].b[j]=w%10;
			w/=10;
			if(j==6)
				break;
			j--;
		}
	}
	sort(a,a+m,cmp1);
	for(i=0;i<m;i++){
		for(j=0;j<12;j++){
			cout << a[i].b[j];
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 8576
n = int(input())
li_a = list(map(int,input().split()))
li_a.sort(reverse=True)

ans = li_a[0]
if n % 2 == 0:
    for i in range(1,n//2):
        ans += 2*li_a[i]
else:
    for i in range(1,n//2):
        ans += 2*li_a[i]
    ans += li_a[n//2]

print(ans)

Measured memory_bytes: 31380
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  int A,B;cin >> A >> B;
  int K;cin >> K;
  rep(i,K){
    if(i%2==0){
      A>>=1;
      B+=A;
    }else{
      B>>=1;
      A+=B;
    }
  }
  cout << A SP B << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <math.h>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

#define mod ((ull)1e9+7)
#define MAX ((ull)1e6)

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

	ll total=0;
	for(int i=0; i<=n; i++){
		total+=abs(a[i]-a[i+1]);
	}

	for(int i=1; i<=n; i++){
		if((a[i-1]<=a[i] && a[i]<=a[i+1]) || (a[i-1]>=a[i] && a[i]>=a[i+1])){
			cout << total << endl;
		}else{
			cout << total-2*min(abs(a[i-1]-a[i]), abs(a[i]-a[i+1])) << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1664
#include "iostream"
#include "vector"
#include "string"
#include "algorithm"
#include "math.h"
#include "cstring"
#include "queue"

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

int n;
int a[310];
double dp[310][310][310];	//1,2,3

double rec(int x, int y, int z)
{
  if (dp[x][y][z] != -1)
  {
    return dp[x][y][z];
  }
  else
  {
    double check = n;
    if (x != 0)
    {
      check += x * rec(x - 1, y, z);
    }
    if (y != 0)
    {
      check += y * rec(x + 1, y - 1, z);
    }
    if (z != 0)
    {
      check += z * rec(x, y + 1, z - 1);
    }
    check /= x + y + z;
    return dp[x][y][z] = check;
  }
}

int main()
{
  cin >> n;
  int count[3] = {0, 0, 0};
  for (int i = 0; i < n; i++)
  {
    cin >> a[i];
    count[a[i] - 1]++;
  }
  fill(dp[0][0], dp[309][309], -1);
  dp[0][0][0] = 0;
  printf("%.10f\n", rec(count[0], count[1], count[2]));
}

Measured memory_bytes: 233088
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
int main(){
    int n,A[200000],ans=0;
    cin>>n;
    rep(i,n) cin>>A[i];
    rep(i,n) if(A[i]%2==1) ans++;
    if(ans%2==0) cout<<"YES";
    else cout<<"NO";
}

Measured memory_bytes: 640
#include <iostream>

using namespace std;

int main(void)
{
  int h1, h2, m1, m2, k, total;
  
  cin >> h1 >> m1 >> h2 >> m2 >> k;
  
  if(h1 < 0 || h1 > 23 || h2 < 0 || h2 > 23)
  {
    return 0;
  }

  if( k < 1) return 0;
  
  if(h1 > h2)
  {
    return 0;
  }
  else if(m1 >= m2 && h1 == h2)
  {
    return 0;
  }
  
  total += (h2 - h1) * 60;
  
  total += m2 - m1 - k;
  
  cout << total << endl;
  
  return 0;
}

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

int main()
{
  int N;
  cin >> N;
  stack<string> s;
  bool flag = true;
  string a[N];
  for(int i = 0; i < N; i++) cin >> a[i];
  for(int i = 0; i < N; i++){
    if(a[i] == "A"){
      s.push(a[i]);
    }else{
      if(s.empty()){
        flag = false;
        break;
      }else{
        s.pop();
      }
    }
  }
  if(flag && s.empty()) cout << "YES";
  else cout << "NO";
  cout << endl;
}

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

int main(){
    long n;
    cin >> n;
    long A[10001] = {};
    for (long i = 0; i < n; i++){
        long x;
        cin >> x;
        A[x]++;
    }
    long k = 0;
    for (long i = 0; i <= 10000; i++){
        for (long j = 0; j < A[i]; j++){
            if (k++) cout << " ";
            cout << i;
        }
    }
    cout << endl;
    return 0;
}

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

int main() {
  string board[60];
  int X, Y;
  cin >> X>>Y;
  int dx[] = {1,1,1,0,0,-1,-1,-1};
  int dy[] = {0,1,-1,-1,1,1,0,-1};
  
  for (int i =0;i<X;i++){
    cin >> board[i];
  }
    for (int i = 0; i<X;i++){
      for(int j =0;j<Y;j++){
        if (board[i][j] == '.'){
          int count = 0;
          for (int k = 0;k < 8;k++){
            int x = i + dx[k];
            int y = j + dy[k];
            if (x>=0 && x<X && y>=0 && y<Y && board[x][y] == '#'){
              count++;
            }
          board[i][j] = '0' + count;
          }
        }
      }
    }

  for (int i = 0; i < X;i++){
    cout << board[i] << endl;
  }

}



Measured memory_bytes: 3620
#![allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}
fn read_vec2<T: std::str::FromStr>(n: usize) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
fn main() {
    let t: Vec<i32> = read_vec();
    println!("{}", if t[1] * t[2] >= t[0] {"Yes"} else {"No"});
}

Measured memory_bytes: 2084
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
    using namespace std;

    int main(){
      ll x[2];
      cin >> x[0] >> x[1];
      sort(x,x+2);
      if(x[1]-x[0]<=1)cout << "Brown" << endl;
        else cout << "Alice" << endl;
      return 0;}

Measured memory_bytes: 256
module app;

import core.bitop;

import std.algorithm;
import std.array;
import std.bigint;
import std.container.rbtree;
import std.conv;
import std.stdio;
import std.string;
import std.traits;

struct Input
{
	int n;
	int[] a;
}

void parseInput(T)(out Input input, T adapter)
{
	with (input)
	{
		adapter.readf!"%d\n"(n);
		a.length = n;
		foreach (i; 0..n)
		{
			adapter.readf!"%d "(a[i]);
		}
	}
}

struct Output
{
}

auto main2(Input* input)
{
	ulong sum = 0;
	ulong prev = input.a[0];
	foreach (ai; input.a[1..$])
	{
		if (prev > ai)
			sum += prev - ai;
		else
			prev = ai;
	}

	return sum;
}

alias retType = ReturnType!main2;
static if (!is(retType == void))
{
	unittest { writeln("begin unittest"); }
	auto _placeholder_ = ReturnType!main2.init;

	unittest // example1
	{
		string example =
`5
2 1 5 4 3`;
		if (example.empty) return;
		Input input = void;
		parseExample(input, example);
		auto result = main2(&input);
		printResult(result);
		assert(result == 4);
	}

	unittest // example2
	{
		string example =
`5
3 3 3 3 3`;
		if (example.empty) return;
		Input input = void;
		parseExample(input, example);
		auto result = main2(&input);
		printResult(result);
		assert(result == 0);
	}

	unittest // example3
	{
		string example =
``;
		if (example.empty) return;
		Input input = void;
		parseExample(input, example);
		auto result = main2(&input);
		printResult(result);
		assert(result == _placeholder_);
	}

	unittest { writeln("end unittest"); }

	void parseExample(out Input input, string example)
	{
		parseInput(input, new StringAdapter(example));
	}
}

class StdinAdapter
{
	// readf!"%s"は使えない
	// https://issues.dlang.org/show_bug.cgi?id=19820
	uint readf(alias format, A...)(auto ref A args) { return std.stdio.readf!format(args); }
	string readln() { return std.stdio.readln().strip(); }
}

class StringAdapter
{
	import std.format;
	string _s;
	this(string input) { _s = input; }
	uint readf(alias format, A...)(auto ref A args) { return _s.formattedRead!format(args); }
	string readln()
	{
		auto i = _s.countUntil("\n");
		if (i == -1) i = _s.length;
		string ret = _s[0..i];
		_s = _s[i..$];
		return ret;
	}
}

void printResult(T)(T result)
{
	static if (isFloatingPoint!T) writefln("%f", result);
	else writeln(result);
}

void main()
{
	Input input = void;
	parseInput(input, new StdinAdapter());
	static if (is(retType == void))
		main2(&input);
	else
	{
		auto result = main2(&input);
		printResult(result);
	}
}


Measured memory_bytes: 3472
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound, __gcd, count, find, next_permutation
#include <bitset>    // bitset
#include <deque>     // deque
#include <iomanip>   // setprecsion
#include <iostream>  // cout, endl, cin
#include <map>       // map
#include <queue>     // queue, priority_queue
#include <set>       // set
#include <stack>     // stack
#include <string>    // string, to_string, stoi
#include <tuple>     // tuple, make_tuple
#include <utility>   // pair, make_pair
#include <vector>    // vector

#include <cassert> // assert
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>  // abs, sin, cos, tan
#include <ctime> // clock

// __builtin_popcountll

using namespace std;
using Graph = vector<vector<int>>;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rrep(i, n) for (ll i = (n - 1); i >= 0; --i)
#define blank(ans) cout << (ans) << " ";
#define mp(p, q) make_pair(p, q)
#define mt(p, q, r) make_tuple(p, q, r)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef string str;

typedef vector<ll> vll;
typedef vector<ld> vd;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<str> vs;
typedef vector<vector<ll>> vvll;
typedef vector<vector<ld>> vvd;
typedef vector<vector<bool>> vvb;
typedef vector<vector<char>> vvc;
typedef vector<vector<str>> vvs;
typedef vector<pair<ll, ll>> vpll;
typedef vector<tuple<ll, ll, ll>> vtlll;

const ld PI = acos(-1.0);
const ll MAX = 9000000000000000000;
const ll MIN = -9000000000000000000;
const ld DMAX = 4500;
const ld DMIN = -4500;
const ll MOD = 1000000007;

template <typename T>
void fin(T a)
{
  cout << a << endl;
  exit(0);
}

void Main()
{
  ll a, b, c, x, y;cin >> a >> b >> c >> x >> y;
  ll ans = 0;
  if(a + b >= 2 * c)
  {
    ll tmp = min(x, y);
    ans += tmp * 2 * c;
    x -= tmp;
    y -= tmp;
  }
  ans += min(a, 2 * c) * x;
  ans += min(b, 2 * c) * y;
  fin(ans);
  return;
}

//前処理
int main()
{
  int ti = clock();
  srand((unsigned)time(NULL));
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(20); //高精度少数表示
  //cout << setfill('0') << internal << setw(4); //0埋め４桁
  Main();
  //cout << 1.0 * (clock() - ti) / CLOCKS_PER_SEC << endl; // 実行時間計測
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1LL << 60;
ll MOD = 1000000000 + 7;

int main() {
    int k, t;
    cin >> k >> t;
    vector<int> a(t);
    for (int i = 0; i < t; i++) cin >> a[i];
    sort(a.begin(), a.end(), greater<int>());
    int kmax = a[0], kother = 0;
    for (int i = 1; i < t; i++) kother += a[i];
    int ans = 0;
    if (kmax > kother) ans = kmax - kother - 1;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3552
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <complex>
#include <cmath>

using namespace std;

const double EPS = 1e-10;
const double INF = 100000000.0;

typedef complex<double> B;
typedef pair<double, int> P;

map<int, int> idToIdx;
map<int, int> idxToId;
B buildings[1000];
int n, m;
int s, t;
vector<int> G[1000];
int prev[1000];
double dist[1000];
bool used[1000];

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

double getDistance(B a, B b){
  //cout << a << ' ' << b << ' ' << abs(a-b) << endl;
  return abs(a-b);
}

void addEdge(int a, int b){
  G[a].push_back(b);
  G[b].push_back(a);
}

void makeGraph(){
  for(int i=0;i<n;i++){
    for(int j=i+1;j<n;j++){
      if(getDistance(buildings[i], buildings[j]) < 50.0 + EPS) addEdge(i, j);
    }
  }
}

void dijkstra(){
  fill(dist, dist+n, INF);
  fill(prev, prev+n, -1);
  dist[s] = 0.0;
  que.push(make_pair(0.0, s));

  while(!que.empty()){
    P p = que.top();que.pop();
    int v = p.second;
    if(dist[v] < p.first) continue;
    for(int i=0;i<G[v].size();i++){
      if(dist[G[v][i]] > dist[v] + getDistance(buildings[v], buildings[G[v][i]])){
	dist[G[v][i]] = dist[v] + getDistance(buildings[v], buildings[G[v][i]]);
	prev[G[v][i]] = v;
	//cout << "!" << getDistance(v, G[v][i]) << endl;
	que.push(make_pair(dist[G[v][i]], G[v][i]));
      }
    }
  }
}

void traverse(){
  vector<int> path;
  if(prev[t] == -1){
    cout << "NA" << endl;
    return;
  }
  for(;t!=-1;t=prev[t]) path.push_back(t);
  reverse(path.begin(), path.end());
  cout << idxToId[path[0]];
  for(int i=1;i<path.size();i++){
    cout << ' ' << idxToId[path[i]];
  }
  cout << endl;
}

main(){
  while(cin >> n && n){
    for(int i=0;i<n;i++){
      G[i].clear();
    }
    idToIdx.clear();
    idxToId.clear();
    for(int i=0;i<n;i++){
      int id;
      cin >> id >> buildings[i].real() >> buildings[i].imag();
      idToIdx[id] = i;
      idxToId[i] = id;
    }
    makeGraph();
    cin >> m;
    for(int i=0;i<m;i++){
      cin >> s >> t;
      s = idToIdx[s];
      t = idToIdx[t];
      dijkstra();
      for(int i=0;i<n;i++){
	//cout << dist[i] << endl;
      }
      traverse();
    }
  }
  return 0;
}

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


int main(int argc, char *argv[]) {
  // C-style stdio functions should not be used.
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  string tt = "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ";
  int N;
  string S;
  cin >> N >> S;
  char buf[S.size() + 10];
  for (int i = 0; i < (int)S.size(); i++) {
    buf[i] = (S.at(i) - 'A' + N) % 26 + 'A';
  }
  buf[S.size()] = 0;
  string ans(buf);
  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 256