akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

struct graph_scc{
	int V;
	static const int MAX=200000;
	vector<int> G[MAX];
	vector<int> rG[MAX];
	vector<int> vs;
	bool used[MAX];
	int cmp[MAX];
	void init(int n){
		V=n;
		for(int i=0;i<V;i++){
			G[i].clear();
			rG[i].clear();
		}
		vs.clear();
		memset(cmp,0,sizeof(cmp));
	}
	void add_edge(int from,int to){
		G[from].push_back(to);
		rG[to].push_back(from);
	}

	void dfs(int v){
		used[v]=true;
		for(int i=0;i<G[v].size();i++){
			if(!used[G[v][i]])dfs(G[v][i]);
		}
		vs.push_back(v);
	}
	void rdfs(int v,int k){
		used[v]=true;
		cmp[v]=k;
		for(int i=0;i<rG[v].size();i++){
			if(!used[rG[v][i]])rdfs(rG[v][i],k);
		}
	}

	int scc(int n){
		V=n;
		memset(used,0,sizeof(used));
		vs.clear();
		for(int v=0;v<V;v++){
			if(!used[v])dfs(v);
		}
		memset(used,0,sizeof(used));
		int k=0;
		for(int i=vs.size()-1;i>=0;i--){
			if(!used[vs[i]]){
				rdfs(vs[i],k++);
			}
		}
		return k;
	}
};

int n,m,w;
vector<P> G[100005];
graph_scc gr;
int ord[100005];
bool dp[100000][105];

int main(void){
	scanf("%d%d%d",&n,&m,&w);
	bool zero=false;
	for(int i=0;i<m;i++){
		int a,b,c;
		scanf("%d%d%d",&a,&b,&c);
		gr.add_edge(a,b);
		if(c==0)zero=true;
		G[a].push_back(P(b,c));
	}
	gr.scc(n);
	for(int i=0;i<n;i++){
		ord[gr.cmp[i]]=i;
		dp[i][0]=true;
	}
	for(int i=0;i<n;i++){
		int v=ord[i];
		for(int j=0;j<G[v].size();j++){
			int to=G[v][j].first;
			int cost=G[v][j].second;
			for(int k=0;k+cost<=100;k++){
				if(dp[v][k]){
					dp[to][k+cost]=true;
				}
			}
		}
	}
	int ma=-1;
	if(zero)ma=0;
	for(int i=0;i<n;i++){
		for(int j=1;j<-w;j++){
			if(dp[i][j]){
				ma=max(ma,j);
			}
		}
	}
	if(ma==-1){
		printf("NA\n");
	}else{
		printf("%d\n",ma+w);
	}
	return 0;
}



Measured memory_bytes: 46064
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = (a); i <= (b); i++)
#define rng(a) a.begin(), a.end()
#define ina(n,a) cin >> n; for(int i = 1; i <= n; i++) cin >> a[i]
#define sz(x) (int)(x).size()
#define se second
#define fi first
#define prev            coyhhhhhhyoc    
#define next          sdNNNmNNNNNNNmds  
#define y0           hNNNNy_yNNNNNN_sNh
#define y1          mNNNNNdtdNNNNNNtsNNm
#define yn          mNNNNNNNNy___smNNNms
#define tm            oooooosyysooooot 
#define read               tyhyt        
#define rank              ytmNmo         
#define index              yyy
#define pb push_back
#define pcnt __builtin_popcountll
#define rrep(i,a,b) for(int i = (b); i >= (a); i--)
#define rall(x,a) for(auto x : a)
#define MOD 1000000007
#define endl "\n"
typedef long long ll;
using namespace std;

const int N = 3333;
pair<int, int> ab[N];
int dp[N][N][2];
int n, t;

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> t;
    rep(i, 1, n) {
        cin >> ab[i].fi >> ab[i].se;
    }
    sort(ab + 1, ab + n + 1);
    rep(i, 1, n) {
        rep(ct, 0, t) {
            int pt = ct - ab[i].fi;
            dp[i][ct][0] = max(dp[i - 1][ct][0], dp[i - 1][ct][1]);
            if(pt >= 0) {
                dp[i][ct][1] = max(dp[i - 1][pt][0], dp[i - 1][pt][1]) + ab[i].se;
            }
        }
    }
    int ans = 0;
    rep(i, 1, n) {
        rep(ct, 0, t - 1) {
            ans = max(ans, dp[i][ct][1]);
            ans = max(ans, dp[i][ct][0] + ab[i].se);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 80128
#include <bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;

#define ll long long
#define ld long double
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define gcd __gcd
#define lcm(a, b) ((a) * (b) / gcd((a), b))
#define all(x) x.begin(), x.end()
#define rep(i, x, n) for (ll i = x; i < n; i++)
#define fastio() ios_base::sync_with_stdio(NULL); cin.tie(0); cout.tie(0)
#define endl '\n'

typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef pair<int, int> ii;
typedef vector<pair<int, int> > vii;

template <class T> inline T RD(T &a) {T x; cin >> x; return a = x;}

signed main()
{
//	freopen("TEXT.inp", "r", stdin); freopen("TEXT.out", "w", stdout);
	fastio();

	int x, a; cin >> x >> a;
	if (x >= a) cout << 10;
	else cout << 0;


}


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

int main(){
	string T;
	cin >> T;
	int L = T.size();
	
	for(int i = 0; i < L; i++){
		char &c = T.at(i);
		
		if(c == '?')
			c = 'D';
	}

	cout << T << endl;

}

Measured memory_bytes: 3752
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM
import Control.Monad

type Cand = (Int, Int) -- (start, skip)                                         
-- a candidate set is either empty (skip == 0)                                  
-- or singleton (skip == n)                                                     
-- or { start + i * skip | i = 0, 1, ..., i0 } where skip|n                     

type VChar = VU.Vector Char
type Ring = [Int]

icmp :: Int -> Int -> Int -> Int
icmp n x y = ((y + n) `mod` n) * n + ((x + n) `mod` n)

idiv :: Int -> Int -> (Int, Int)
idiv n i = (i `mod` n, i `div` n)

solve :: Int -> [String] -> Int
solve n css =
  if skip == 0 then 0 else n * (n `div` skip)
  where
    vc = buildV n css
    (_, skip) = foldr (nextCand n vc) (0,1) allRings
    allRings = map (mkRing n) [0..n-1]

mkRing :: Int -> Int -> Ring
mkRing n i = map (\k -> icmp n (0+k) (i-k)) [0..n-1]

nextCand :: Int -> VChar -> Ring -> Cand -> Cand
nextCand n vc ring cand@(start,skip)
  | skip == 0 = (0,0)
  | otherwise = nextCand1 n vc ring cand

nextCand1 :: Int -> VChar -> Ring -> Cand -> Cand
nextCand1 n vc ring (start,skip) =
  case allGoods of []         -> (0,0)
                   [k]        -> (k,n)
                   (k0:k1:_)  -> (k0,k1-k0)
  where allGoods = [fk p | p <- [0 .. n`div`skip - 1], good n vc ring (fk p)]
          where fk p = start + skip * p

good :: Int -> VChar -> Ring -> Int -> Bool
good n vc ring k = flip all ring $ \i ->
  let (x, y) = idiv n i
      j      = icmp n (y+k) (x-k)
  in vc VU.! i == vc VU.! j

buildV :: Int -> [String] -> VChar
buildV n css =
  VU.create $ do
  v <- VUM.new (n*n)
  forM (zip [0..] (concat css)) $ \(i, c) -> do
    VUM.write v i c
  return v

main = do
  conts <- getContents
  let sn : css = lines conts
      n = read sn
  putStrLn $ show $ solve n css


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

using ll=long long;
const ll z=0;

int main() {
  int N;
  cin >> N;
  vector<ll> L(N+1,0);
  L[0]=2;
  L[1]=1;
  for(int i=2;i<N+1;i++){
    L[i]=L[i-1]+L[i-2];
  }
  cout << L[N] << endl;

}

Measured memory_bytes: 256
def lcs(x, y):

    l1, l2 = len(x), len(y)

    dp = [0] * (l2+1)
    #dp = [[0]*(l2+1) for i in range(l1+1)]

    for i in range(l1):
        prev = dp[:]
        for j in range(l2):
            if x[i] == y[j]:
                dp[j+1] = prev[j] + 1
                #dp[i+1][j+1] = dp[i][j] + 1   
            elif dp[j+1] < dp[j]:
                dp[j+1] = dp[j]
    
    return dp[l2]

N = int(input())
ans = []
for i in range(N):
    x = input()
    y = input()
    ans.append(lcs(x,y))
for i in range(N):
    print(ans[i])



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

const int MAX = 1e5+5;
vector<int> graph[MAX];
int visited[MAX];
vector<int> res;
int N, M;

void dfs(int cur) {
    res.push_back(cur);
    visited[cur] = true;
    for (int& child : graph[cur]) {
        if (!visited[child]) {
            dfs(child);
            return;
        }
    }
}

int main() {
   // freopen("input", "r", stdin);
    cin >> N >> M;
    for (int i = 0; i < M; ++i) {
        int a, b; cin >> a >> b;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }
    dfs(1);
    reverse(res.begin(), res.end());
    res.pop_back();
    dfs(1);
    cout << res.size() << endl;
    for (int& i : res) cout << i << " ";
    return 0;
}


Measured memory_bytes: 10104
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a[3],d=0,e=0;
  cin>>a[0]>>a[1]>>a[2];
  for(int i=0;i<3;i++){
    if(a[i]==5) d++;
    if(a[i]==7) e++;
  }
  if(d==2 && e==1) cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <numeric>
#include <queue>
#include <numeric>
#include <iomanip>
#include <sstream>

#define rep(i,a,b) for((i)=a;i<(int)(b);i++)
#define max(a,b) (a < b ? b : a)
#define min(a,b) (a > b ? b : a)

using namespace std;


int main() {
	int a, b;
	int N;
	cin >> N;
	int i, j;
	rep(i, 1, 10) {
		if ((N % i == 0) && N / i < 10) {
			cout << "Yes";
			return 0;

		}
	}
	cout << "No";
	return 0;


}


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

int main(){
	int N; cin >> N;
  	int arr[N], dp[N];
  	
  	for(int i=0; i<N; i++){
      cin >> arr[i];
    }
  	
  	dp[N-1] = 0;
  	dp[N-2] = abs(arr[N-2] - arr[N-1]);
  
  	for (int i=N-3; i>=0; i--){
      dp[i] = min(abs(arr[i] - arr[i+1]) + dp[i+1], abs(arr[i] - arr[i+2]) + dp[i+2]);
       
    }
  	
  	cout << dp[0] << endl;
	return 0;
}


Measured memory_bytes: 4356
from collections import Counter
n = int(input())
D = list(map(int,input().split()))
Dc = Counter(D)
mod = 998244353
ans = 1

if Dc[0]!=1 or D[0]!=0:
    print(0)
else:
    for i in range(max(D)):
        ans = ans*pow(Dc[i],Dc[i+1])%mod
    print(ans%mod)

Measured memory_bytes: 98444
import sys

input_list = list(int(i) for i in sys.stdin)
max_n = min(1000000, max(input_list) + 1)

prime_list = list(i % 2 for i in range(max_n))
prime_list[1], prime_list[2] = 0, 1
i = 3
while i * i < max_n:
    if prime_list[i]:
        for j in range(i * 2, max_n, i):
            prime_list[j] = 0
    i += 2

for i in range(1, max_n):
    prime_list[i] += prime_list[i - 1]

inset = sorted((n, i) for i, n in enumerate(input_list))
outset = sorted((t[1], prime_list[t[0]]) for t in inset)
for t in outset:
    print(t[1])

Measured memory_bytes: 47264
N = int(input())
xy = [map(int, input().split()) for _ in range(N)]
D1, D2 = [list(i) for i in zip(*xy)]

for i in range(N - 2):
    if D1[i] == D2[i] and D1[i+1] == D2[i+1] and D1[i+2] == D2[i+2]:
        print("Yes")
        exit()

print("No")

Measured memory_bytes: 62552
#include <iostream>
#include <utility>
#include <vector>

using namespace std;

long long solve(vector<pair<long long, long long>>& dp, long long n, long long& x) {
    if (x <= 0) {
        return 0;
    } else if (dp[n].first > 0 && x - dp[n].first >= 0) {
        x -= dp[n].first;
        return dp[n].second;
    } else if (n == 0) {
        dp[0].first = 1;
        dp[0].second = 1;

        x -= dp[0].first;
        return dp[0].second;
    }

    long long cnt = 0, rem = x;

    x--;

    cnt += solve(dp, n - 1, x);

    if (x > 0) {
        cnt++; x--;
    }

    cnt += solve(dp, n - 1, x);

    if (x > 0) {
        x--;

        dp[n].first = rem - x;
        dp[n].second = cnt;
    }

    return cnt;
}

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

    vector<pair<long long, long long>> dp(n + 1, make_pair(0, 0));
    cout << solve(dp, n, x) << endl;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC067C
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());

            long[] a = new long[N];
            string[] vals = Console.ReadLine().Split(' ');

            a[0] = long.Parse(vals[0]);

            for (int i = 1; i < N; i++)
            {
                a[i] = a[i-1] + long.Parse(vals[i]);
            }


            long min = long.MaxValue;

            for(int i = 0; i < N-1; i++)
            {
                long arai = a[N - 1] - a[i];

                long d = Math.Abs(a[i] - arai);

                if (min > d)
                    min = d;

            }

            Console.WriteLine(min);

        }
    }
}


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

#define cel(n, k) ((n-1)/k+1)
#define sets(a) memset(a, -1, sizeof(a))
#define clr(a) memset(a, 0, sizeof(a))
#define dbg(x) cout << "Line " << __LINE__ <<": " << x << nl
#define nl "\n"
#define sp " "

#define fastio() ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define file() freopen("in.txt", "r", stdin), freopen("out.txt", "w", stdout)

typedef long long ll;
typedef pair<int,int> pii;

const int N = 1e5+5;

int tc = 1;


int main(){

   	//file();

    fastio();

    //cin >> tc;

    while(tc--){

    	int to = 1+2+3+4+5;

    	int a, b, c, d, e, f;

    	cin >> a >> b >> c >> d >> e;

    	cout << to - a - b - c - d - e << nl;
    	
    	
    }

    return 0;
}


Measured memory_bytes: 3640
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <iomanip>
#include <math.h>
#include <map>
using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a.at(i);
    }
    int ans = 0;
    while(true) {
        for (int i = 0; i < n; i++) {
            if (a.at(i) % 2 == 1) {
                goto last;
            }
        }
        for (int i = 0; i < n; i++) {
            a.at(i) /= 2;
        }
        ans++;
    }
    last:
    cout << ans << endl;
}

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

const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;
const int MOD=1000000007;

ll ppow(ll a,ll b){
	a%=MOD;
	ll res=1;
	while(b){
		if(b&1)res=(res*a)%MOD;
		a=(a*a)%MOD;
		b>>=1;
	}
	return res;
}
class Fact{
	vector<ll>fact;
	vector<ll>inv;
public:
	Fact(){}
	Fact(int n){
		n=n*2+10;
		fact=inv=vector<ll>(n);
		fact[0]=inv[0]=1;
		for(int i=1;i<n;i++){
			fact[i]=(fact[i-1]*i)%MOD;
		}
		inv[n-1]=ppow(fact[n-1],MOD-2);
		for(int i=n-2;i>=0;i--){
			inv[i]=(inv[i+1]*(i+1))%MOD;
		}
	}
	ll get(int n){
		return fact[n];
	}
	ll get_inv(int n){
		return inv[n];
	}
	ll nPr(int n,int r){
		return fact[n]*inv[n-r]%MOD;
	}
	ll nCr(int n,int r){
		return nPr(n,r)*inv[r]%MOD;
	}
	ll nrP(int n,int r){
		return nPr(n+r,n);
	}
	ll nrC(int n,int r){
		return nCr(n+r,n);
	}
};

int main(){
	int n,K;cin>>n>>K;
	ll ans=0;
	Fact fac(n);
	for(int k=0;k<=n-1;k++){
		if(k>K)break;
		(ans+=fac.nCr(n,k)*fac.nCr(k+(n-k-1),k)%MOD)%=MOD;
	}
	cout<<ans<<endl;
}

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

using namespace std;

const int maxn = 100010;

struct edge {
	int to, next;
}e[maxn << 1];

bool vis[maxn][11]; int head[maxn], u[maxn], d[maxn], c[maxn], color[maxn], cnt = 1;

void insert(int u, int v) {
	e[++cnt].to = v; e[cnt].next = head[u]; head[u] = cnt;
	e[++cnt].to = u; e[cnt].next = head[v]; head[v] = cnt;
}

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

void dfs(int u, int d, int color) {
	if(vis[u][d]) return;
	vis[u][d] = 1;
	if(d == 0) {
		if(!c[u]) c[u] = color;
		return;
	}
	dfs(u, d - 1, color);
	for(int i = head[u], v = e[i].to; i; i = e[i].next, v = e[i].to) dfs(v, d - 1, color);
}

int main() {
	int n = read(), m = read();
	for(int i = 0; i < m; i++) {
		int u = read(), v = read(); insert(u, v);
	}
	int q = read();
	for(int i = 0; i < q; i++) {
		u[i] = read(), d[i] = read(), color[i] = read();
	}
	reverse(u, u + q); reverse(d, d + q); reverse(color, color + q);
	for(int i = 0; i < q; i++) dfs(u[i], d[i], color[i]);
	for(int i = 1; i <= n; i++) printf("%d\n", c[i]);
	return 0;
}

Measured memory_bytes: 5248
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<string> vec(N);
  bool b = true;
  char c;
  for(int i = 0; i < N; i++) {
    string S;
    cin >> S;
    vec[i] = S;
    if(i != 0) {
      if(S[0] != c) {
        b = false;
      }
    }
    int M = S.size();
    c = S[M - 1];
  }
  for(int i = 0; i < N; i++) {
    for(int j = i + 1; j < N; j++) {
      if(vec[i] == vec[j]) {
        b = false;
        break;
      }
    }
  }
  if(b) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

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

int main(void)
{
    int N, K;
    cin >> N >> K;
    int h;
    int c = 0;
    for (int i = 0; i < N; i++) {
        cin >> h;
        if (h >= K) c++;
    }
    cout << c << endl;

    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
typedef vector<int> vi;
#define pii pair<int,int>
#define MAXN 200009
const int INF = 1e9+7;
#define int int64_t
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define db(x) cerr << #x << " = " << x << endl
#define db2(x, y) cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")\n";
#define db3(x, y, z) cerr << "(" << #x << ", " << #y << ", " << #z << ") = (" << x << ", " << y << ", " << z << ")\n"
#define dbv(a) cerr << #a << " = "; for (auto xxxx: a) cerr << xxxx << " "; cerr << endl


int32_t main(){
		
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    int x = 0;
    int a[n];
    rep(i,0,n){cin>>a[i];x^=a[i];}
    rep(i,0,n){cout<<(x^a[i])<<" ";}
}

Measured memory_bytes: 5192
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;

int n;
char k[2][9];

void init() {
  scanf("%d", &n);
}

bool input() {
  int i;

  if (!n) return false;
  n--;

  scanf("%s", k[0]);
  scanf("%s", k[1]);

  return true;
}

int main() {
  int i, j, a, num[2];

  init();
  while (input()) {
    a = 1;
    for (i = 0; i < 2; i++) {
      num[i] = 0;
      for (j = 0; j < strlen(k[i]); j++) {
        switch (k[i][j]) {
        case 'm':
          num[i] += a * 1000;
          a = 1;
          break;
        case 'c':
          num[i] += a * 100;
          a = 1;
          break;
        case 'x':
          num[i] += a * 10;
          a = 1;
          break;
        case 'i':
          num[i] += a;
          a = 1;
          break;
        default:
          a = k[i][j] - '0';
          break;
        }
        //printf("%d\n", num[i]);
      }

    }
    num[0] += num[1];

    a = num[0] / 1000;
    num[0] %= 1000;
    if (a > 0) {
      if (a > 1) {
        printf("%d", a);
      }
      printf("m");
    }
    a = num[0] / 100;
    num[0] %= 100;
    if (a > 0) {
      if (a > 1) {
        printf("%d", a);
      }
      printf("c");
    }
    a = num[0] / 10;
    num[0] %= 10;
    if (a > 0) {
      if (a > 1) {
        printf("%d", a);
      }
      printf("x");
    }
    a = num[0];
    if (a > 0) {
      if (a > 1) {
        printf("%d", a);
      }
      printf("i");
    }
    printf("\n");

  }

  return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include<queue>
#include<set>
#include<climits>
#include <cmath>
using namespace std;

int main()
{
  long long n, n2;
  cin >> n;
  n2 = n;

  long long d = 0;

  while(n != 0)
  {
    n /= 10;
    d++;
  }

  if (d == 1)
  {
    cout << n2 << endl;
    exit(0);
  }

  long long result = 9 * (d - 1);
  long long keta = pow(10, (d - 1));
  long long keta1 = pow(10, d);

  if (keta1 -1 == n2)
  {
    cout << d * 9 << endl;
    exit(0);
  }

  if((n2 / keta) != 0)
   result += (n2 / keta) - 1;

  if((n2 / keta) + 1 == (n2 +1) / keta)
  {
    cout << result + 1 << endl;
    exit(0);
  }

  cout << result << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5+10;
string s[10]={"SUN","MON","TUE","WED","THU","FRI","SAT"};
int main()
{
	string s1;
	cin>>s1;
	for(int i=0;i<=6;i++)
	{
		if(s[i]==s1)
		{
			cout<<7-i<<endl;
			return 0;
		}
	}
}

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

typedef long long ll;

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

int main(){
    ll a,b;
    cin >> a >> b;
    cout << a*b/gcd(a,b) << endl;
    return 0;
}

Measured memory_bytes: 3636
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <stdio.h>
#include <list>
#define black 0
#define red 1
#define white -1
#define maxn 110
using namespace std;

int tot = 0;
int book[maxn] = {}, t[maxn][2] = {};
list<int> map[maxn];

void dfs(int u)
{
	book[u] = red;
			t[u][0] = ++tot;
			for (list<int>::iterator it = map[u].begin(); it != map[u].end(); it++)
			{
				if (book[*it - 1] == black)
				{
					dfs(*it - 1);
				}
			}
			book[u] = white;
			t[u][1] = ++tot;
	return;
}
int main()
{
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
	{
		int u, k, v;
		scanf("%d%d", &u, &k);
		u--;
		for (int i = 0; i < k; i++)
		{
			scanf("%d", &v);
			map[u].push_back(v);
		}
	}
	for (int i = 0; i < n; i++)
		if (book[i] == black)
			dfs(i);
	for (int i = 0; i < n; i++)
	{
		printf("%d %d %d\n", i + 1, t[i][0], t[i][1]);;
	}
	return 0;
}


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

using namespace std;

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

    if(s == 'a' || s == 'e' || s == 'i' || s == 'o' || s == 'u')
        cout << "vowel";
    else
        cout << "consonant";
}

Measured memory_bytes: 256
N=int(input())
A=[int(input()) for _ in range(N)]
A.insert(0,0)
i=1
count=0
while True:
  if count>N:
    print(-1)
    break
  lamp=A[i]
  count+=1
  if lamp==2:
    print(count)
    break
  i=lamp

Measured memory_bytes: 12888
//
// Created by Hideaki Imamura on 2020-03-10.
//
# include <bits/stdc++.h>

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

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

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

# define EPS (1e-7)
# define INF (1e9)
# define PI (acos(-1))
//const ll mod = 1000000007;

ll N, K;
vector<ll> A, pos, neg;
ll n_zero, n_pos, n_neg;

// 積がx以下の(i,j)の数 for (pos, neg)
//ll f(ll x) {
//    ll ret = 0;
//    int j = n_pos - 1;
//    for (int i = n_neg - 1; i >= 0; --i) {
//        while (j >= 0 && neg[i] * pos[j] <= x) j--;
//        ret += n_pos - 1 - j;
//    }
//    return ret;
//}

// 積がx以下の(i,j)の数 for (pos, pos) or (neg, neg)
ll g(ll x) {
    ll sum = n_pos * n_neg + n_zero * (n_pos + n_neg) + (n_zero * (n_zero - 1)) / 2;
    int j = n_neg - 1;
    for (int i = 0; i < n_neg - 1; i++) {
        while (j >= 0 && neg[i] * neg[j] <= x) j--;
        sum += min((int)n_neg - j - 1, (int)n_neg - i - 1);
    }
    j = 0;
    for (int i = n_pos - 1; i >= 1; i--) {
        while (j < n_pos && pos[i] * pos[j] <= x) j++;
        sum += min(i, j);
    }
    return sum;
}

int main() {
    cin >> N >> K;
    n_zero = 0;
    for (int i = 0; i < N; ++i) {
        ll a;
        cin >> a;
        A.push_back(a);
        if (a == 0) {
            n_zero++;
        } else if (a > 0) {
            pos.push_back(a);
        } else {
            neg.push_back(a);
        }
    }
    sort(A.begin(), A.end());
    sort(pos.begin(), pos.end());
    sort(neg.begin(), neg.end());
    n_pos = pos.size();
    n_neg = neg.size();

    if (K <= n_pos * n_neg) {
        ll l = - 1e18 - 1ll;
        ll r = 0;
        while (r - l > 1) {
            ll m = (l + r) / 2;
            ll sum = 0;
            int j = n_pos - 1;
            for (int i = n_neg - 1; i >= 0; i--) {
                while (j >= 0 && neg[i] * pos[j] <= m) j--;
                sum += n_pos - 1 - j;
            }
            if (sum >= K) {
                r = m;
            } else {
                l = m;
            }
        }
        cout << r << endl;
    } else if (K <= n_pos * n_neg + n_zero * (n_pos + n_neg) + (n_zero * (n_zero - 1)) / 2) {
        cout << 0 << endl;
    } else {
        ll l = 0;
        ll r = 1e18 + 1ll;
        while (r - l > 1) {
            ll m = (l + r) / 2;
            ll sum = g(m);
            if (sum >= K) {
                r = m;
            } else {
                l = m;
            }
        }
        cout << r << endl;
    }
    return 0;
}

Measured memory_bytes: 4468
n = int(input())
t = list(map(int,input().split()))
v = list(map(int,input().split()))
t.append(0)
v.append(0)
nowv = 0
ans = 0
for i in range(n):
    m = v[i]
    t0 = 0
    for j in range(i+1,n+1):
        mnow = v[j]
        #print(v[j],i)
        for k in range(j,i,-1):
            if mnow + t[k] <= v[k]:
                mnow += t[k]
            else:
                mnow = v[k]
            #print(mnow)
        m = min(m,mnow)
        t0 += t[j]
    m = min(m,nowv+t[i])
    #print(m)
    if m == v[i]:
        if nowv+t[i] <= v[i]:
            ans += (2*nowv+t[i])*t[i]/2
        else:
            #print(nowv,v[i])
            ans += (nowv+v[i])*(abs(v[i]-nowv))/2 + v[i]*(t[i]-v[i]+nowv)
    else:
        if m <= nowv:
            a = nowv - m
            b = (t[i]-a)/2
            if nowv + b <= v[i]:
                ans += a*(m+nowv)/2
                ans += (2*nowv+b)*b
            else:
                ans += (nowv+v[i])*(v[i]-nowv)/2
                ans += v[i]*(t[i]-(v[i]-nowv)-(v[i]-m))
                ans += (m+v[i])*(v[i]-m)/2
        else:
            a = m - nowv
            b = (t[i]-a)/2
            if nowv + a+ b <= v[i]:
                ans += a*(m+nowv)/2
                ans += (2*m+b)*b
                #print(a,b)
            else:
                ans += (nowv+v[i])*(v[i]-nowv)/2
                ans += v[i]*(t[i]-(v[i]-nowv)-(v[i]-m))
                ans += (m+v[i])*(v[i]-m)/2
    #print(ans)
    nowv = m
    #print(nowv)
print(ans)

Measured memory_bytes: 40816
#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 <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

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

int main(){
    int n,p;
    int m = 0;

    cin >> n;
    p = n;

    while(p > 0){
        m += p % 10;
        p /= 10;
    }

    if(n % m == 0)cout << "Yes";
    else cout << "No";

    return 0;
}


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

int main()
{
    int n;
    ll d;
    cin >> n >> d;
    int ans = 0;
    rep(i, n){
        ll x, y;
        cin >> x >> y;
        if(x*x + y*y <= d*d) ans++;
    }
    cout << ans << endl;
    return 0;
}

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

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> ii;
typedef tuple<ll, ll, ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define REP(i,n) for (ll i = 0; i < n; ++i)
#define REPR(i,n) for (ll i = n-1; i >= 0; --i)
#define FOR(i,m,n) for (int i = m; i < n; ++i)
#define FORR(i,m,n) for (ll i = n-1; i >= m; --i)
#define FORE(x,xs) for (const auto& x : xs)
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define ALL(v) v.begin(), v.end()
#define rALL(v) v.rbegin(), v.rend()

const int MAX = 200010;

int M;
ll D[MAX], C[MAX];
ll cnt[10];

int main() {
    cin >> M;
    ll digit = 0;
    ll sum = 0;
    REP (i, M) {
        ll c, d; cin >> d >> c;
        sum += c*d;
        digit += c;
    }
    cout << (sum-1)/9 + digit -1 << endl;
}

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

class Program
{
    static void Main()
    {
        FastScanner sc = new FastScanner(Console.OpenStandardInput());
        int H, N;
        H = sc.nextInt();
        N = sc.nextInt();
        int A, accum;
        accum = 0;
        for (int i = 0; i < N; i++)
        {
            A = sc.nextInt();
            accum += A;
        }
        Console.WriteLine(H <= accum ? "Yes" : "No");
    }
}

// FastScanner start
public class FastScanner
{
    public readonly Stream str;
    private readonly byte[] buf = new byte[1024];
    private int len, ptr;
    public bool isEof = false;
    public FastScanner(Stream stream)
    {
        str = stream;
    }
    private T[] enumerate<T>(int n, Func<T> f)
    {
        var a = new T[n];
        for (int i = 0; i < n; ++i) a[i] = f();
        return a;
    }
    public char nextChar()
    {
        byte b = 0;
        do
        {
            b = read();
        }
        while ((b < 33 || 126 < b) && !isEof);
        return (char)b;
    }
    public int nextInt()
    {
        return (isEof) ? int.MinValue : (int)nextLong();
    }
    public long nextLong()
    {
        if (isEof)
        {
            return long.MinValue;
        }
        long ret = 0;
        byte b = 0;
        var ng = false;
        do
        {
            b = read();
        }
        while (b != '-' && (b < '0' || '9' < b));
        if (b == '-')
        {
            ng = true;
            b = read();
        }
        for (; true; b = read())
        {
            if (b < '0' || '9' < b)
            {
                return ng ? -ret : ret;
            }
            else ret = ret * 10 + b - '0';
        }
    }
    public int[] intArray(int n)
    {
        return enumerate(n, nextInt);
    }
    public long[] longArray(int n)
    {
        return enumerate(n, nextLong);
    }
    public char[] charArray(int n)
    {
        return enumerate(n, nextChar);
    }
    public string Scan()
    {
        var sb = new StringBuilder();
        for (var b = nextChar(); b >= 33 && b <= 126; b = (char)read())
        {
            sb.Append(b);
        }
        return sb.ToString();
    }
    private byte read()
    {
        if (isEof)
        {
            return 0;
        }
        if (ptr >= len)
        {
            ptr = 0;
            if ((len = str.Read(buf, 0, 1024)) <= 0)
            {
                isEof = true;
                return 0;
            }
        }
        return buf[ptr++];
    }
}
// FastScanner end

Measured memory_bytes: 11092
from collections import defaultdict
n,p = map(int,input().split())
s = list(map(int,list(input())))[::-1]
ans = 0
if p == 2 or p == 5:
    for i in range(n):
        if s[i]%p==0:
            ans += n-i
    print(ans)
else:
    d = defaultdict(int)
    check = 0
    ten = 1
    for i in range(n):
        check += s[i]*ten
        check %= p
        ans += d[check]
        if check == 0:
            ans+=1
        d[check] += 1
        ten *= 10
        ten %= p
    print(ans)

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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define contains(v, t) (find(v.begin(), v.end(), t) != v.end())
#define MOD 1000000007
typedef long long ll;
typedef unsigned long long ull;

int main() {
  int x;
  cin >> x;
  if (x == 7 || x == 5 || x == 3) {
    cout << "YES";
  } else {
    cout << "NO";
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = INT32_MAX;
const ll INFL = INT64_MAX;
const int mod = 1e9 + 7;

template <typename T>
void print_vec(vector<T> v) {
  for (T i : v) cout << i << " ";
  cout << endl;
}

int main() {
  int ans = 0;
  rep(i, 5) {
    int x;
    cin >> x;
    if (x == 0) ans = i + 1;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3584
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <cstring>
#include <climits>
using namespace std;
#define ll long long
#define FOR(i,n) for(int i=0;i<n;i++)
#define sz(x) (int)(x.size())
#define all(x) (x).begin(),(x).end()
template<typename tp> void read(tp &x) {cin >> x;}
template<typename tp, typename... Args> void read(tp& x, Args&... args) {read(x);read(args...);}
const int mxN = (int)1e5,INF = (int)1e9,MOD = (int)1e9+7;

void solve()
{
	int n,w;
	read(n,w);
	ll items[n][2];
	FOR(i,n) read(items[i][0],items[i][1]);
	ll dp[w+1][n+1];
  //dp[i][j] max value we can get if we have a knapsack with weight i
  //and we have j items we can select from.
	for(int i=0;i<=w;i++)
	{
		dp[i][0] = 0;
		for(int j=1;j<=n;j++)
		{
			dp[i][j] = dp[i][j-1];
			if(i-items[j-1][0]>=0)
				dp[i][j] = max(items[j-1][1] + dp[i-items[j-1][0]][j-1],dp[i][j]);
           //We take max between taking this item and leaving it
		}
	}
	cout << dp[w][n] << '\n';
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int test = 1;
	//read(test);
	while(test--)
		solve();
	return 0;
}



Measured memory_bytes: 82520
#include <iostream>
using namespace std;
#define FOR(i, m, n) for(int i = m;i < n;i++)

int sumDig(int num) {
	int dig,res=0;
	while(num){
		dig = num % 10;
		res = res + dig;
		num = num / 10;
	}
	return res;
}

int main()
{
	int N,A,B,a,b,min;
	cin >> N;
	min = N;

	FOR(i,1,N) {
		a = i;
		b = N - i;
		A = sumDig(a);
		B = sumDig(b);
		if (min > A + B) {
			min = A + B;
		}
	}
	cout << min << endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {

  public static void main(String[] args) {
    new Main().run();
  }

  public void run() {

    try(BufferedReader in = new BufferedReader(new InputStreamReader(System.in))) {

      final int n = Integer.parseInt(in.readLine());

      String line = in.readLine();
      int[] seq = new int[n];
      int[] ref = new int[n];
      char regex = ' ';
      boolean isContinue = true;
      for(int i=0, offset=0,next=0; isContinue; i++, offset = ++next) {
        if((next = line.indexOf(regex,offset)) == -1) {
          next = line.length();
          isContinue = false;
        }
        ref[i] = seq[i] = Integer.parseInt(line.substring(offset,next));
      }

      Arrays.parallelSort(ref);

      final int d = n>>1;
      final int p = ref[d];
      final int r = ref[d];
      final int l = ref[d-1];
      StringBuilder buf = new StringBuilder();
      for(int i: seq) {
        if(i < p) buf.append(r).append('\n');
        else buf.append(l).append('\n');
      }

      System.out.print(buf);
    }
    catch(IOException e) {
      System.err.println(e);
    }
  }
}

Measured memory_bytes: 52448
#include <bits/stdc++.h>
#define fi first
#define se second 
#define ll long long 
#define mod 1000000007

using namespace std;

string s;
int n, k;
int dp[10100][110][2], dp2[10100][110], a[10100];

int main()   {
    // ifstream cin("tst.in");
    // ofstream cout("tst.out");
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);

    cin >> s;
    n = s.size();
    s = '+' + s;
    cin >> k;

    for (int i = 1; i <= n; i++)
        a[i] = s[i] - '0';

    for (int i = 1; i < a[1]; i++)
        dp[1][i % k][0]++;
    dp[1][a[1] % k][1] = 1;

    for (int i = 1; i <= 9; i++)
        dp2[1][i % k]++; 

    int sum = (n > 1 ? dp2[1][0] : 0);
    for (int pos = 2; pos <= n; pos++) {
        for (int cif = 0; cif < 10; cif++) {
            for (int rest = 0; rest < k; rest++) {
                int nrest = (rest + cif) % k; 
                if (cif < a[pos]) {
                    dp[pos][nrest][0] = (dp[pos][nrest][0] + dp[pos - 1][rest][0] + dp[pos - 1][rest][1]) % mod;
                } else if (cif == a[pos]) {
                    dp[pos][nrest][0] = (dp[pos][nrest][0] + dp[pos - 1][rest][0]) % mod;
                    dp[pos][nrest][1] = (dp[pos][nrest][1] + dp[pos - 1][rest][1]) % mod;
                } else {
                    dp[pos][nrest][0] = (dp[pos][nrest][0] + dp[pos - 1][rest][0]) % mod;
                }

                dp2[pos][nrest] = (dp2[pos][nrest] + dp2[pos - 1][rest]) % mod;
            }
        }
        if (pos < n) 
            sum = (sum + dp2[pos][0]) % mod;
    }

    cout << ((dp[n][0][0] + dp[n][0][1]) % mod + sum) % mod;
    return 0;
}   

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

int main(){
    int A,B,C,X;
    0<=A,B,C<=50;
    50<=X<=20000;
    cin>>A>>B>>C>>X;
    int res=0;
    for(int a=0;a<=A;++a){
        for(int b=0;b<=B;++b){
            for(int c=0;c<=C;++c){
                int total=500*a+100*b+50*c;
                if(total==X){
                    ++res;
                }
            }
        }
    }
    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 764
#define deb 123321
#define fi first
#define se second
#define mp make_pair
#define pb push_back

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

typedef long long ll;
typedef unsigned long long ull;
constexpr int R=5e7+69, INF=2e9+6969;

ll n,ans;
map <ll,ll> m;
ll roz(ll x)
{
	int xdddd=0;
	ll ans=1;
	for(ans;ans*(ans+1)<=x*2;++ans)
	{
		xdddd=123;
	}
	return ans-1;
} 

int main()
{
	m.clear();
	scanf("%lld", &n);
	ll a=n;
	for(ll i=2;i*i<=n;++i)
	{
		//  printf("%lld\n", i);
		if(a%i==0)
		{
			while(a%i==0)
			{
				m[i]++;
				a/=i;
			}
		}
	}
	if(a!=1) m[a]++;
	for(auto e: m)
	{
		ans+=roz(e.se);
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 3832
#include<stdio.h>
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include<stack>
#include <queue>
#include<map>
#include <set>
#include<math.h>
using namespace std;
#define int long long
#define ll long long
#define rep(i,n) for(ll i=0;i<n;++i)
#define loop(i,m,n) for(ll i=m;i<n;++i)
#define ggr getchar(); getchar();return 0;
#define pie 3.141592653589793238462643383279
#define elif else if
#define P pair<ll,ll>
const int inf = 1000000007;
int bin(int bina) {
	int ans = 0;
	for (int i = 0; bina > 0; i++)
	{
		ans = ans + (bina % 2) * pow(10, i);
		bina = bina / 2;
	}
	return ans;
}
bool prime(int n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n % i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x * y / gcd(x, y);
}
int kai(int x) {
	if (x == 0)return 1;
	return kai(x - 1) * x % inf;
}
int mod_pow(int x, int y, int mod) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % mod;
		}
		x = x * x % mod;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	return kai(x)* mod_pow(kai(x - y), inf - 2, inf) % inf * mod_pow(kai(y), inf - 2, inf) % inf;
}
int a[114];
signed main() {
	int n, s, d,f=0,g=0,h=0;
	cin >> n >> s >> d;
	rep(i, n) {
		cin >> a[i];
	}
	rep(i, n) {
		if (a[i] <= s) {
			f++;
		}
		elif(a[i] <= d) {
			g++;
		}
		else {
			h++;
		}
	}
	cout << min({ f,g,h }) << endl;
}


Measured memory_bytes: 256
/******

AUTHOR : RUDRANSH TRIPATHI, IIIT NAGPUR, CCID(rt24) & CFID(rsgt24)

MOTTO : Use criticism as fuel and you will never run out of energy.
        AIM : TO BECOME A BETTER CODER
        INTROSPECT + COURSE CORRECTIONS = CATALYST FOR SUCCESS
        Every moment is an opportunity to better yourself
        
*******/

#include<bits/stdc++.h>
using namespace std;
const int M = 1e9 + 7;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define int long long int
#define pb push_back
#define d(x) cout<<x<<"\n"

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

/*
int powermod(int A, int p, int MOD = mod){
    A%=MOD;
    int res  = 1;
    while(p){
        if(p&1)
            res = ((__int128)res*A)%MOD;
        
        A = ((__int128)A*A)%MOD;
        p>>=1;
    }

    return res;
}
*/

/*
const int MAX = 100000; 
int prefix[MAX + 1]; 

void buildPrefix() 
{ 
	bool prime[MAX + 1]; 
	memset(prime, true, sizeof(prime)); 

	for (int p = 2; p * p <= MAX; p++) { 
		if (prime[p] == true) { 
			for (int i = p * 2; i <= MAX; i += p) 
				prime[i] = false; 
		} 
	} 
	prefix[0] = prefix[1] = 0; 
	for (int p = 2; p <= MAX; p++) { 
		prefix[p] = prefix[p - 1]; 
		if (prime[p]) 
			prefix[p]++; 
	} 
} 

int query(int L, int R) 
{ 
	return prefix[R] - prefix[L - 1]; 
}
*/

/*

//Find all paths from a to b in an undirected graph
vector<int> g[100000];
int visited[100000];
 //count of all the paths from 1 to n;
vector<string> ans;

void dfs(int visited[10000],int u,int v,vector<int> path)
{
    visited[u]=1;
    if(u==v)
    {
        string temp="";
        for(int i=0;i<path.size();i++)
        {
            temp+=to_string(path[i]);
        }
        ans.pb(temp);
    }
    else
    {
        for(int i=0;i<g[u].size();i++)
        {
            int y=g[u][i];

            if(visited[y]==0)
            {
                visited[y]=1;
                path.pb(y);
                dfs(visited,y,v,path);
                path.pop_back();
            }

        }
    }

    visited[u]=0;

}
*/

vector<pair<int,string>> vp;

void solve()
{
    int n;
    cin>>n;
    int ar[n];
    
    for(int i=0;i<n;i++)
    cin>>ar[i];
    int sum=0;
    
    for(int i=1;i<n;i++)
    {
        if(ar[i-1]>ar[i])
        {
            sum+=ar[i-1]-ar[i];
            ar[i]=ar[i-1];
        }
    }
    
    //for(int i=0;i<n;i++)
    //cout<<ar[i];
    //cout<<"\n";
    
    
    cout<<sum<<"\n";
    
    
}

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

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

int main() {
  int W,H,N,x[100],y[100],a[100];
  cin>>W>>H>>N;
  for (int i(0);i<N;i++) cin>>x[i]>>y[i]>>a[i];
  int minx(0),miny(0),maxx(W),maxy(H);
  for (int i(0);i<N;i++){
    if (a[i]==1) minx=max(minx,x[i]);
    else if (a[i]==2) maxx=min(maxx,x[i]);
    else if (a[i]==3) miny=max(miny,y[i]);
    else if (a[i]==4) maxy=min(maxy,y[i]);
  }
  cout << (maxx-minx>0 && maxy-miny>0? (maxx-minx)*(maxy-miny):0);
}

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

int main() {
    int N;
    cin >> N;
    int AC = 0, WA = 0, TLE = 0, RE = 0;
    rep(i, N) {
        string S;
        cin >> S;
        // AC, WA, TLE, RE
        if (S == "AC") AC++;
        if (S == "WA") WA++;
        if (S == "TLE") TLE++;
        if (S == "RE") RE++;
    }
    cout << "AC x " << AC << endl;
    cout << "WA x " << WA << endl;
    cout << "TLE x " << TLE << endl;
    cout << "RE x " << RE << endl;

}

Measured memory_bytes: 3624
#include "bits/stdc++.h"
using namespace std;
#define mod 1e9+7
#define FOR(a,c)   for ( int (a)=0; (a)<(c); (a)++)
#define FORL(a,b,c)  for ( int (a)=(b); (a)<=(c); (a)++)
#define FORR(a,b,c)  for (  int (a)=(b); (a)>=(c); (a)--)
typedef long long int ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
#define F first
#define S second
#define PB push_back
#define POB pop_back
#define MP make_pair

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

double A,B,C,D,x,y;
cin>>A>>B>>C>>D;
x=ceil(C/B);
y=D*(x-1);
if(y>=A)
    cout<<"No";
else
    cout<<"Yes";
    
return 0;
}

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


//TEMPLATE
#define pb                push_back
#define mp                make_pair
#define ll                long long
#define ld                long double
#define pii               pair <ll, ll>
#define piii              pair <ll, pii>
#define F                 first
#define S                 second

#define newline           printf("\n")
#define minusone          printf("-1\n")
#define zeroo             printf("0\n")
#define scl1(a)           scanf("%lld", &a)
#define scl2(a, b)        scanf("%lld %lld", &a, &b)
#define scl3(a, b, c)     scanf("%lld %lld %lld", &a, &b, &c)
#define prl1(a)           printf("%lld\n", a)
#define prl2(a, b)        printf("%lld %lld\n", a, b)
#define ssl1(s)           scanf(" %[^\n]", s)
#define scd1(a)           scanf("%lf", &a)
#define scd2(a, b)        scanf("%lf %lf", &a, &b)
#define prd(a)            printf("%lf\n", a)
#define prld(a)           printf("%Lf\n", a)
#define prcase(cs)        printf("Case %lld: ", cs)
#define cin1(a)           cin >> a
#define cin2(a, b)        cin >> a >> b
#define cin3(a, b, c)     cin >> a >> b >> c
#define cin4(a, b, c, d)  cin >> a >> b >> c >> d
#define cot1(a)           cout << a << "\n"
#define cot2(a, b)        cout << a << " " << b << "\n"
#define cot3(a, b, c)     cout << a << " " << b << " " << c << "\n"
#define cot4(a, b, c, d)  cout << a << " " << b << " " << c << " " << d << "\n"
#define cotline           cout << "\n"
#define cotminus          cout << "-1\n"
#define cot0              cout << "0\n"
#define cotyes            cout << "YES\n"
#define cotno             cout << "NO\n"
#define cotcase(cs)       cout << "Case " << cs << ": "

#define reversed(s)       reverse(s.begin(), s.end())
#define asort(s)          sort(s.begin(), s.end())
#define dsort(s)          sort(s.rbegin(), s.rend())
#define all(s)            s.begin(), s.end()
#define uniq(s)           s.resize(distance(s.begin(),unique(s.begin(), s.end())))
#define found(s, x)       (s.find(x) != s.end())

#define for0(i, n)        for (i = 0; i < n; i++)
#define for1(i, n)        for (i = 1; i <= n; i++)
#define fora(i, a, b)     for (i = a; i <= b; i++)
#define forb(i, b, a)     for (i = b; i >= a; i--)
#define fori(it, s)       for(auto it = s.begin(); it != s.end(); it++)

#define FR                ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ms(a, x)          memset(a, x, sizeof a)
#define bitcount(n)       __builtin_popcountll(n)

//#define pi              3.1415926536
#define pi                acos(-1)

const ll INF = LLONG_MAX;
const ll SZ = 4e5+5;
const ll mod = 1e9+7;


ll n;
ll a[SZ];
//ll b[SZ];



int main() {
    ll cs = 0, tc = 1, x, y, z, i, j, k, g, p, q, ans = 0, sum = 0, c = 0, t = 0;
    //    ll a, b, d;
    string s, s1, s2;

    cin1(n);

    p = 1000;
    c = (n/p) + (n%p != 0);
    t = c * p;
    ans = t - n;
    cot1(ans);

    return 0;
}



Measured memory_bytes: 3644
n = int(input())
a = list(map(int, input().split()))
a.sort()
#furui = [False] * (10**6+1)
#ans = 0
#for i in range(n):
#    if i-1 >= 0 and a[i] == a[i-1]:
#        continue
#    if furui[a[i]] == False:
#        if (i + 1 < n and a[i] != a[i + 1]) or i==n-1:
#            ans += 1
#        now = a[i]
#        while now <= 10**6:
#            furui[now] = True
#            now += a[i]
#print(ans)
furui = [0] *(10**6+1)
for i in range(n):
    now = a[i]
    if furui[now] == 1:
        furui[now] = 2
    if furui[now] == 0:
        now_2 = now
        while now_2 <= 10**6:
            furui[now_2]  += 1
            now_2 += now
ans = 0
for i in a:
    if furui[i] == 1:
        ans += 1
print(ans)

Measured memory_bytes: 105816