akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>

#define MAX_DISTANCE 20000000

using namespace std;

int N,R;
int adj[202][202];
int town[10];
int visit[10];
int min_cost;

void solve(int from, int depth, int cost){
  if(depth==R-1){
    if(min_cost>cost)
      min_cost=cost;
    return ;
  }
  //  cerr << "from:"<<from<<" depth:"<<depth<<" cost:"<<cost<<endl;
  for(int to=0;to<R;to++){
    if(visit[to]==0){
      visit[to]=1;
      solve(town[to],depth+1,cost+adj[from][town[to]]);
      visit[to]=0;
    }
  }
}


int main(){

  int M;
  cin>>N>>M>>R;

  for(int i=0;i<R;i++)
    cin>>town[i];

  for(int i=1;i<=N;i++)
    for(int j=1;j<=N;j++)
      adj[i][j]=MAX_DISTANCE;
  
  for(int i=0;i<M;i++){
    int A,B,C;
    cin>>A>>B>>C;
    adj[A][B]=adj[B][A]=C;
  }

  for(int k=1;k<=N;k++){
    for(int i=1;i<=N;i++){
      for(int j=1;j<=N;j++){
	adj[i][j]=min(adj[i][k] + adj[k][j] , adj[i][j]);
      }
    }
  }

  /*
  for(int i=1;i<=N;i++){
    for(int j=1;j<=N;j++){
      cerr << adj[i][j] << " ";
    }
    cerr << endl;
  }
  */
  
  min_cost = MAX_DISTANCE * R;

  for(int i=0;i<R;i++){
    visit[i]=1;
    solve(town[i],0,0);
    visit[i]=0;
  }

  cout<<min_cost<<endl;
  
  return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<sstream>
#include<iomanip>
#include<bitset>
#include<map>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#define lli long long int
#define uli unsigned long long int
#define inf 999999999999999999
#define rep(i,n,m) for(lli i=(lli)(n);i<(lli)(m);++i)
#define reep(i,n,m) for(int i=(int)(n);i<=(int)(m);++i)
#define per(i,m,n) for(lli i=(int)(m)-1;i>=(int)(n);--i)
#define st(n) sort(n.begin(), n.end())
#define rev(n) reverse(n.begin(),n.end())
#define ou(S) cout << S << endl
#define pb(n) push_back(n)
#define ue(N) N.erase(unique(N.begin(),N.end()),N.end());
#define nou(S) cout << S
#define hou(S) cout << setprecision(30) << S << endl
#define vec(K,L,N,S) vector<L> K(N,S)
#define dv(K,L,N,M,S) vector<vector<L>> K(N,vector<L>(M,S))
#define tv(K,L,N,M,R,S) vector<vector<vector<L>>> K(N,vector<vector<L>>(M,vector<L>(R,S)))
#define pint pair<lli,lli>
#define paf(L,R) pair<L,R>
#define mod 1000000007
#define maxx 5100000
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
using namespace std;
int main(){
  int a,b,k,x=0,ans;
  vector<lli> c(101);
  cin>>a>>b>>k;
  reep(i,1,100){
    if(a%i==0&&b%i==0){
      c.at(i)=i;
    }
  }
  st(c);
  ou(c.at(100-k+1));
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string.h>
#include <iomanip>
#include <math.h>
#include <string>
#include <queue>
#include <map>
#include <set>
#include <functional>

using namespace std;

typedef long long int ll;
typedef std::pair<int, int> pii;
typedef std::pair<ll, int> pli;
typedef std::pair<ll, ll> pll;

#define FOR(i,n,m) for(ll i=(ll)(m);i<(ll)(n);++i)
#define REP(i,n) FOR(i,n,0)
#define IREP(i,n) for(ll i=(ll)(n);i>=0;--i)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

int main()
{
	int A, B, K;
	cin >> A >> B >> K;

	FOR(i, B + 1, A)
	{
		if (i < A + K || i > B - K)
		{
			cout << i << endl;
		}
	}

	return 0;
}

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

void fnInput(vector<int>& rvnSeqP, vector<int>& rvnSeqQ)
{
  int nSeqSiz;
  cin >> nSeqSiz;
  rvnSeqP.resize(nSeqSiz);
  rvnSeqQ.resize(nSeqSiz);

  for (int& rnSeqP : rvnSeqP)
    cin >> rnSeqP;
  for (int& rnSeqQ : rvnSeqQ)
    cin >> rnSeqQ;
}
  
int fnCountOrderGet(const vector<int>& cnrvnSeqP, const vector<int>& cnrvnSeqQ)
{
  vector<int> vnSeqX(cnrvnSeqP.size());
  int nCntP, nCntQ, nCntX = 0;

  iota(begin(vnSeqX), end(vnSeqX), 1);
  do {
    nCntX++;
    if (cnrvnSeqP == vnSeqX) nCntP = nCntX;
    if (cnrvnSeqQ == vnSeqX) nCntQ = nCntX;
  }
  while ( next_permutation(begin(vnSeqX), end(vnSeqX)) );

  return abs(nCntP - nCntQ);
}
  
int main()
{
  vector<int> vnSeqP, vnSeqQ;

  fnInput(vnSeqP, vnSeqQ);
  cout << fnCountOrderGet(vnSeqP, vnSeqQ) << endl;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>

using namespace std;

int main() {
	int a, b; cin >> a >> b;

	if (a == 1 && b == 1) cout << "Draw" << endl;
	else if (a == 1) cout << "Alice" << endl;
	else if (b == 1) cout << "Bob" << endl;
	else {
		if (a < b) cout << "Bob" << endl;
		else if (a > b) cout << "Alice" << endl;
		else cout << "Draw" << endl;
	}
}

Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

use std::collections::HashMap;

fn main() {
    let n: usize = read();
    let mut a: HashMap<usize, usize> = HashMap::new();
    let mut ans = 0;

    for _ in 0..n {
        let ai = read();
        let current = a.entry(ai).or_insert(0);
        *current += 1;
    }

    for (k, v) in a {
        if v > k {
            ans += v - k;
        }
        if v < k {
            ans += v;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 12540
l = list(map(int,input().split()))

l.sort()

ans = 0
ans += l[2] - l[1]

if  (l[2] - (ans + l[0])) % 2 == 0:
    ans += (l[2] - (ans + l[0])) / 2
else:
    ans += int((l[2] - (ans + l[0])) / 2) + 2

print(int(ans))


Measured memory_bytes: 9056
import sys
input = sys.stdin.readline
from fractions import gcd


def read():
    N = int(input().strip())
    S = []
    for i in range(N):
        s = int(input().strip())
        S.append(s)
    return N, S

def solve(N, S, SMAX=10000):
    dp = [[False for j in range(SMAX+1)] for i in range(N+1)]
    for i in range(N):
        dp[i][0] = True
    for i in range(N):
        for j in range(SMAX):
            if j-S[i] >= 0:
                dp[i+1][j] = dp[i][j] | dp[i][j-S[i]]
            else:
                dp[i+1][j] = dp[i][j]
    for j in range(SMAX, -1, -1):
        if j % 10 == 0:
            continue
        if dp[N][j]:
            return j
    return 0

if __name__ == '__main__':
    inputs = read()
    print(solve(*inputs))


Measured memory_bytes: 13392
#include <bits/stdc++.h>
using namespace std;
int main () {
  int N;
  cin >> N;
  vector<double> data(N);
  for(int i = 0; i < N; i++)cin >> data.at(i);
  sort(data.begin(), data.end());
  double ans = (data.at(0) + data.at(1)) / 2;
  for(int i = 2; i < N; i++){
    ans = (ans + data.at(i)) / 2;
  }
  cout << setprecision(10) << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,s,e) for(int i=(s); i<(e);i++)
#define rep(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n)
#define repe(i,n) for(auto &&i:n)
#define all(v) (v).begin(),(v).end()
#define decimal fixed<<setprecision(20)
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
using namespace std;
using LL = long long;
const int INF = 1e9;
const LL LLINF = 1e16;

int main(){
    int n;
    cin >> n;
    int a[101010][3];
    rep(i, n)rep(j, 3) cin >> a[i][j];
    int dp[101010][3];
    memset(dp, -1, sizeof(dp));
    rep(i, 3) dp[0][i] = 0;
    rep(i, n){
        rep(j, 3){
            dp[i+1][j] = max({dp[i+1][j], dp[i][(j+1)%3]+a[i][(j+1)%3], dp[i][(j+2)%3]+a[i][(j+2)%3]});
        }
    }

    cout << max({dp[n][0], dp[n][1], dp[n][2]}) << endl;

}


Measured memory_bytes: 2560
<?php
$input = STDIN;

$chars = str_split(trim(fgets($input)));

foreach ($chars as $c) {
    if (ctype_lower($c)) {
        $ans[] = strtoupper($c);
    } else {
        $ans[] = strtolower($c);
    }
}

print implode('', $ans) . "\n";


Measured memory_bytes: 9640
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
  ll n,ans=0,val;
  cin>>n;
  map<string,ll> map;
  vector<string> vec(n);
  for(ll i=0;i<n;i++){
    string s;
    cin>>s;
    map[s]++;
  }
  for(auto it = map.begin(); it != map.end(); it++){
    val = (*it).second;
    val=max(ans,val);
    ans=val;
  }
  for(auto it = map.begin(); it != map.end(); it++){
    if((*it).second==ans){
      cout<<(*it).first<<endl;
    }
  }
}

Measured memory_bytes: 26752
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T,class U> using P = pair<T,U>;
template<class T> using vec = vector<T>;
template<class T> using vvec = vector<vec<T>>;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)

const ll MOD = 1e9 + 7;

int main(){
    string s;
    cin >> s;
    vec<int> ans(s.size());

    int num_r = 0, num_l = 0;
    bool now_r = true;
    int idx_rl = -1;
    rep(i, s.size()) {
        if (s[i]=='R' && now_r==false) {
            ans[idx_rl] += num_l/2;
            ans[idx_rl+1] += (num_l+1)/2;
            num_l = 0;         
            now_r = true;   
            num_r++;
        }
        else if (s[i]=='L' && now_r==true){
            idx_rl = i-1;
            ans[idx_rl] += (num_r+1)/2;
            ans[idx_rl+1] += num_r/2;
            num_r = 0;
            now_r = false;
            num_l++;
        }
        else if (s[i]=='R' && now_r==true) num_r++;
        else if (s[i]=='L' && now_r==false) num_l++;

        if (i==s.size()-1){
            ans[idx_rl] += num_l/2;
            ans[idx_rl+1] += (num_l+1)/2;
        }
    }
    rep(i, s.size()) cout << ans[i] << " ";
    cout << endl;
}

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

using namespace std;

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

int H, W, M;
int idx(int x, int y){
  return y*W+x;
}
int dx[] = {-1,0,1,0};
int dy[] = {0,-1,0,1};

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

  cin >> H >> W >> M;
  VS vs(H);
  REP(i,H) cin >> vs[i];
  VVI cost(H, VI(W)), on(H, VI(W)), off(H, VI(W));
  REP(y,H) REP(x,W) cin >> cost[y][x];
  REP(y,H) REP(x,W) cin >> on[y][x];
  REP(y,H) REP(x,W) cin >> off[y][x];
  vector<PII> task(M);
  REP(i,M) cin >> task[i].second >> task[i].first;

  vector<PII> path;
  path.PB(task[0]);
  for(int i=0;i+1<M;++i){
	bool vis[50][50];
	fill((bool*)vis, (bool*)vis+50*50, false);
	PII par[50][50];

	queue<PII> q;
	q.push(task[i]);
	vis[task[i].second][task[i].first] = true;
	while(!vis[task[i+1].second][task[i+1].first]){
	  PII p = q.front(); q.pop();
	  REP(i,4){
		int tx = p.first + dx[i], ty = p.second + dy[i];
		if(tx < 0 || W <= tx || ty < 0 || H <= ty || vis[ty][tx] || vs[ty][tx] == '#') continue;
		vis[ty][tx] = true;
		par[ty][tx] = p;
		q.push(MP(tx,ty));
	  }
	}

	vector<PII> tmp;
	PII p = task[i+1];
	while(p != task[i]){
	  tmp.PB(p);
	  p = par[p.second][p.first];
	}
	reverse(ALL(tmp));
	path.insert(path.end(), ALL(tmp));
  }

  bool flag[50][50];
  fill((bool*)flag, (bool*)flag+50*50, false);
  LL ans = 0;
  for(int i=0;i<SZ(path);++i){
	int x = path[i].first, y = path[i].second;
	if(!flag[y][x]){
	  flag[y][x] = true;
	  ans += on[y][x];
	}
	int j;
	for(j=i+1;j<SZ(path);++j){
	  if(path[i] == path[j]){
		if((j-i)*cost[y][x] < on[y][x] + off[y][x])
		  ans += (j-i)*cost[y][x];
		else
		  ans += on[y][x] + off[y][x];
		break;
	  }
	}
	if(j == SZ(path)){
	  ans += off[y][x];
	}
  }

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

Measured memory_bytes: 13356
#include <bits/stdc++.h>
using namespace std;
bool victims[11000];
int main(){
  int a, b;
  cin >> a >> b;
  for(int i = 0;i < a;i++)
  {
   victims[i] = false;
  }
  for(int i = 0;i < b;i++)
  {
    int re;
    cin >> re;
    for(int j = 0;j < re;j++)
    {
      int res;
      cin >> res;
      victims[res - 1] = true;
    }
  }
  int ans = 0;
  for(int i = 0;i < a;i++)
  {
    if(!victims[i])
    {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

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

const int INF = 100100;

int main()
{
    int n, m;
    cin >> n >> m;
    int mi = INF;
    int ma = 0;
    rep(i, m) {
        int l;
        int r;
        cin >> l >> r;
        mi = min(mi, r);
        ma = max(ma, l);
    }
    if(mi < ma) cout << 0 << endl;
    else cout << mi - ma + 1 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <assert.h>
#include <fstream>
#include <iostream>
#include <algorithm>
#include <array>
#include <vector>
#include <queue>
#include <set>
#include <cmath>
//#include <unordered_map>
//#include <unordered_set>
//#include <boost/container/static_vector.hpp>
//#include <boost/unordered_set.hpp>
//#include <boost/unordered_map.hpp>
//#include <unistd.h>

//#include <cv.h>
//#include <highgui.h>
#include <stdlib.h>
#include <string>

const int MAX_N = 100050;

int P1[MAX_N], P2[MAX_N];


int main(int argc, char **argv) {
    std::string S;

    std::cin >> S;

    for (int i = 0; i < S.size(); i++) {
        if (i % 2 == 0) {
            P1[i] = 0;
            P2[i] = 1;
        } else {
            P1[i] = 1;
            P2[i] = 0;
        }
    }

    int ret1 = 0;
    int ret2 = 0;

    for (int i = 0; i < S.size(); i++) {
        if (S[i] == '0') {
            if (P1[i] == 1) { ret1++; }
            if (P2[i] == 1) { ret2++; }
        } else {
            if (P1[i] == 0) { ret1++; }
            if (P2[i] == 0) { ret2++; }
        }
    }

    std::cout << std::min(ret1, ret2) << std::endl;

    return 0;
}

Measured memory_bytes: 1280
# include <iostream>
# include <algorithm>
#include <array>
# include <cassert>
#include <cctype>
#include <climits>
#include <numeric>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <tuple>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
# include <chrono>
# include <random>
# include <limits.h>
# include <unordered_map>
# include <unordered_set>
# include <deque>
# include <cstdio>
# include <cstring>
#include <stdio.h>
#include<time.h>
#include <stdlib.h>
#include <cstdint>
#include <cfenv>
#include<fstream>
//#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
long long MOD = 1000000000 + 7; //924844033 1000000000 + 7;
constexpr long long INF = numeric_limits<LL>::max();
const double PI = acos(-1);
#define fir first
#define sec second
#define thi third
#define debug(x) cerr<<#x<<": "<<x<<'\n'
typedef pair<LL, LL> Pll;
typedef pair<double, double> Dll;
typedef pair<LL, pair<LL, LL>> Ppll;
typedef pair<LL, pair<LL, bitset<100001>>> Pbll;
typedef pair<LL, pair<LL, vector<LL>>> Pvll;
typedef pair<LL, LL> Vec2;
struct Tll { LL first, second, third; };
struct Fll { LL first, second, third, fourth; };
typedef pair<LL, Tll> Ptll;
#define rep(i,rept) for(LL i=0;i<rept;i++)
#define Rrep(i,mf) for(LL i=mf-1;i>=0;i--)
LL h, w, n, m, k, t, s, p, q, last, first, cnt, sum, ans, dp[310][310][310],a[200000],b[200000];
string str, ss;
bool f;
char c;
int di[4][2] = { { 0,1 },{ 1,0 },{ 0,-1 },{ -1,0 } };
struct Edge { LL to, cost; };
struct edge { LL from, to, cost; };
vector<LL>vec;
vector<edge>ed;
vector<LL>v;
map<LL,LL>ma;
set<LL>st;
void YN(bool f) {
	if (f)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
}
void yn(bool f) {
	if (f)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}

int main() {
	cin >> n >> m;
	dp[0][1][1] = 1;
	rep(i, m) {
		rep(j, n+1) {
			rep(k, n+1) {
				(dp[i + 1][j + 1][k] += dp[i][j][k] * (n - j) % MOD) %= MOD;
				(dp[i + 1][j][j] += dp[i][j][k] * k% MOD) %= MOD;
				(dp[i + 1][j][k] += dp[i][j][k] * (j - k) % MOD) %= MOD;
			}
		}
	}
	cout << dp[m][n][n] << endl;
	return 0;
}

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

int main(){
	char c, o;
  	cin >> c;
  	switch(c){
      case 'A': o = 'T';
        		break;
      case 'T': o = 'A'; break; 
      case 'C': o = 'G'; break; 
      case 'G': o = 'C'; break; 
    
    }
	cout << o << endl;

return 0;
}

Measured memory_bytes: 384
import java.util.Scanner;


public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
Scanner sc =new Scanner(System.in);
String s =sc.next();
boolean b =true;
if(s.charAt(0)==s.charAt(1)&&s.charAt(1)==s.charAt(2)){
	System.out.println("No");
}
else{
	System.out.println("Yes");
}
	}

}


Measured memory_bytes: 22612
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) throws IOException {
        solve(new BufferedReader(new InputStreamReader(System.in)));
    }

    private static void solve(BufferedReader in) throws IOException {
        StringTokenizer st = new StringTokenizer(in.readLine());
        int N = Integer.parseInt(st.nextToken()), M = Integer.parseInt(st.nextToken());

        @SuppressWarnings("unchecked")
        List<LR>[] nByLen = new List[M + 1];

        for (int n = 1; n < N + 1; n++) {
            st = new StringTokenizer(in.readLine());
            int l = Integer.parseInt(st.nextToken());// 1 <= l <= r <= M
            int r = Integer.parseInt(st.nextToken());
            LR lr = new LR(l, r);
            if (nByLen[lr.len] == null) {
                nByLen[lr.len] = new ArrayList<>();
            }
            nByLen[lr.len].add(lr);
        }

        int accum = N;

        fenwick = new int[M + 1];
        for (int d = 1; d < M + 1; d++) {
            int sum = accum;
            for (int e = d; e < M + 1; e += d) {
                sum += faccum(e);
            }
            System.out.println(sum);
            if (nByLen[d] != null) {
                accum -= nByLen[d].size();
                for (LR lr : nByLen[d]) {
                    fadd(lr.l, 1);
                    fadd(lr.r + 1, -1);
                }
            }
        }
    }

    private static class LR {
        final int l, r, len;

        LR(int l, int r) {
            this.l = l;
            this.r = r;
            this.len = r - l + 1;
        }
    }

    private static int[] fenwick;

    private static int faccum(int i) {
        int sum = 0;
        for (; i > 0; i -= i & -i) {
            sum += fenwick[i];
        }
        return sum;
    }

    private static void fadd(int i, int a) {
        for (; i < fenwick.length; i += i & -i) {
            fenwick[i] += a;
        }
    }
}

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

int main() {
    string s;
    cin >> s;
    int len = (int)s.size();
    int a = 0, z = 0;
    for (int i = 0; i < len; i++) {
        if (s.at(i) == 'A') {
            a = i;
            break;
        }
    }
    for (int i = len - 1; i >= 0; i--) {
        if (s.at(i) == 'Z') {
            z = i;
            break;
        }
    }
    cout << z - a + 1 << endl;
}   

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

#define f(i,a,b) for( ll i = a; i < b ; i++ )
#define af(i,a,b) for( ll i = a; i >= b ; i--)
#define rep(i,a,b,k) for(ll i = a; i < b ; i+= k )
#define arep(i,a,b,k) for( ll i = a; i >= b ; i-= k)
#define ones(x) (ll) __builtin_popcount(x)
#define fs first
#define sc second
#define pb push_back
#define po pop_back
#define mp make_pair  
#define sz(a) (ll) a.size()
#define all(a) a.begin(), a.end()
#define sor(a) sort( a.begin(), a.end() )
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ller ios::sync_with_stdio(false);cin.tsie(nullptr);cout.tie(nullptr)
#define watch(x) cout << (#x) << " is #" << (x) <<"#" <<endl
#define PI 3.1415926535
using namespace std;
typedef long long ll;
typedef long double ld; 
typedef pair<ll,ll> ii ;
typedef vector<ll>  vi ;
typedef vector<ii> vii ;
const ll mod = 1e9+7;
const ll MAX = 3000+4;
const ll inf = 1e18+7;
ll dp[MAX][MAX];
int main(){
  fastio;
  string s,t;
  cin>>s>>t;
  memset(dp,0,sizeof(dp));
  f(i,1,sz(s)+1){
    f(j,1,sz(t)+1){
      if(s[i-1]==t[j-1]) dp[i][j]=dp[i-1][j-1]+1;
      else dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
    }
  }
  ll i=sz(s),j=sz(t);
  string lcs="";
  while(i>0 && j>0) {
    if(dp[i][j]==dp[i-1][j])  i--;
    else if(dp[i][j]==dp[i][j-1]) j--;
    else {
    lcs+=s[i-1];
    i--,j--;
      }
  }
  reverse(all(lcs));
  cout<<lcs<<"\n";
  return 0; 
}

Measured memory_bytes: 74140
def solve(a, b, c):
    for i in range(1000):
        if (a % 2 == 1) or (b % 2 == 1) or (c % 2 == 1):
            return i
        a, b, c = b//2 + c//2, c//2 + a//2, a//2 + b//2
    return -1

a, b, c = map(int, input().split())
print(solve(a, b, c))

Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		String S = sc.next();
		if (N % 2 != 0) {
			System.out.println("No");
		} else {
			if (S.substring(0, N / 2).equals(S.substring(N / 2, N))) {
				System.out.println("Yes");
			} else {
				System.out.println("No");
			}
		}
	}

}


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

int main(){
  long long N, M, K;
  cin >> N >> M >> K;
  const long long INF = 2e9;
  vector<long long> A(N+1,INF), B(M+1,INF);
  for(int i = 0; i < N; ++i){
    cin >> A[i];
  }
  for(int j = 0; j < M; ++j){
    cin >> B[j];
  }
  for(int i = 0; i < N; ++i)
    A[i+1] += A[i];
  for(int j = 0; j < M; ++j)
    B[j+1] += B[j];
  long long ans = upper_bound(B.begin(), B.end(), K) - B.begin();
  for(int i = 0; i < N; ++i){
    if(A[i] > K) break;
    long long r = K - A[i];
    int t = upper_bound(B.begin(), B.end(), r) - B.begin();
    ans = max<long long>(ans,i+1+t);
  }
  cout << ans << endl;
}


Measured memory_bytes: 6428
#include <bits/stdc++.h>
typedef long long ll;
#define pb push_back
using namespace std;
typedef pair<ll,ll> pll;

string yes = "Possible\n";
string no = "Impossible\n";
ll n;
ll a[2002];
ll used[2002];
int main()
{
	cin >> n;
	for(ll i=1;i<=n;i++) cin >> a[i];

	sort(a+1,a+n+1);

	if(n == 2) {
		cout << yes; return 0;
	}
	if(a[n]==2){
		if(a[1]==1 && a[2]==2) {
			cout << yes;
		}else cout << no;
		return 0;
	}
	multiset<ll> S;
	ll d = a[n];
	for(ll i = d ; i > (d/2) ; i--) S.insert(i);
	for(ll i = ((d+1)/2) ; i <= d ; i++) S.insert(i);

	for(auto it : S) {
		bool ok = false;
		for(ll i=1;i<=n;i++){
			if(used[i] == 0 && a[i] == it){
				used[i]=1;
				ok=true;
				break;
			}
		}
		if(ok==false) {
			cout<<no; return 0;
		}
	}
	ll maxm = (d + 1) / 2;
	for(ll i=1;i<=n;i++){
		if(used[i]==0 && a[i] < maxm + 1) {
			cout << no; return 0;
		}
	}
	cout << yes;
	return 0;
}

Measured memory_bytes: 3656
#include<bits/stdc++.h>
const int N=100005;
using namespace std;
int n,m,k,tp,ls;
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i<<=1)
	if(i==n)return puts("No"),0;
	puts("Yes");
	if(n==6)m=n-1,printf("6 5\n12 2\n");
	else if(n&1)m=n;
	else m=n-5,tp=n-1^n,
	printf("%d %d\n%d %d\n",n,n-1,2*n,tp);
	k=m;
	if((m&3)==1)k-=2;
	for(int i=1;i<=k;i++){
		if(ls)printf("%d %d\n",ls,i);
		if(i==tp){
			for(int j=n-1;j>n-4;j--)
			printf("%d %d\n%d %d\n",j,j-1,j+n,j+n-1);
			printf("%d %d\n%d %d\n",2*n-1,n-4,i,n-1);
			ls=2*n-4;
		}
		else ls=i;
	}
	for(int i=1;i<=k;i++)
	printf("%d %d\n",ls,i+n),ls=i+n;
	if(k<m)printf("%d %d\n%d 1\n1 %d\n%d %d\n",
	k+1,k+2,k+2,n+k+1,n+k+1,n+k+2);
}

Measured memory_bytes: 2816
MOD = 1000000007


def mod_pow(x, n):
    if n == 0:
        return 1

    res = mod_pow(x * x % MOD, n // 2)
    if n % 2:
        res = res * x % MOD

    return res


m, n = map(int, input().split())

print(mod_pow(m, n))




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

int main() {
  int a, b, c, k;
  cin >> a >> b >> c >> k;
  if (k < a) {
    cout << k << endl;
  }
  else if (k <= a + b) {
    cout << a << endl;
  }
  else {
    cout << a - (k - a - b) << endl;
  }
}

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

def func(A):
    for a in A:
        #print(a)
        if a % 2 != 0: continue
        if a % 3 == 0 or a % 5 == 0: continue
        return 'DENIED'
    return 'APPROVED'

print(func(A))

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std; 
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ll long long
long long min(long long x,long long y){return (x<y ? x:y);}
long long max(long long x,long long y){return (x>y ? x:y);}
#define ld long double
int stoi(string s) {return atoi(s.c_str());}
int keta(ll x){ if(x<10){return 1;} else{return keta(x/10) + 1;}}


int main(){
  int N; cin >> N;
  int fc[8] = {0};
  int scn = 0;
  int a;
  REP(i,N){
    cin >> a;
    if(a<3200){
      fc[a/400] = 1;
    }else{
      scn++;
    }
  }
  int fcn = 0; REP(i,8){fcn += fc[i];}
  if(fcn>0) printf("%d %d\n",fcn,fcn+scn);
  else printf("%d %d\n",1,scn);
  
}

Measured memory_bytes: 256
data=[]
while(True):
  a,b=map(int,input().split(' '))
  if a==0 and b==0:
    break
  data.append((a,b))

  

for h,w in data:
  l0=''
  l1=''
  for i in range(w):
    if i%2!=0:
      l0+='.'
      l1+='#'
    else:
      l0+='#'
      l1+='.'
  for i in range(h):
    if i%2==0:
      print(l0)
    else:
      print(l1)
  print('')



Measured memory_bytes: 5632
#define dbg(fmt,...) fprintf(stderr,fmt,__VA_ARGS__)
#define dpri(x) dbg(#x ": %d\n", x)
#define dprs(x) dbg(#x ": %s\n", x)
#include <stdio.h>
#include <string.h>
typedef long long ll;
const int MYINF = 1e9+7;

#define slen 210
static char s[slen];
static char p[slen];

int main(int argc, char **argv)
{
	int i, len;

	fgets(s, slen, stdin);
	len = strlen(s) - 1;
	s[len] = '\0';
	for (i = 0; i < len; i++) {
		s[len+i] = s[i];
	}
	s[len+len] = '\0';

	fgets(p, slen, stdin);
	len = strlen(p) - 1;
	p[len] = '\0';

	if (strstr(s, p)) puts("Yes");
	else puts("No");

	return 0;
}

Measured memory_bytes: 524
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <tuple>
#include <cmath>
#include <cassert>
#include <string>

using namespace std;

typedef long long ll;

int N, A;
int x[100010];

ll memo[60][60][2510];

ll f(int n, int m, int a) {
  if (memo[n][m][a] != -1) return memo[n][m][a];
  ll ans = -1;
  if (m == 0 && a == 0) {
    ans = 1;
  } else if (m == 0) {
    ans = 0;
  } else if (n < m) {
    ans = 0;
  } else if (a-x[n-1] < 0) {
    ans = f(n-1, m, a);
  } else {
    ans = f(n-1, m-1, a-x[n-1]) + f(n-1, m, a);
  }
  // cerr << "memo[" << n << "][" << m << "][" << a << "] = " << ans << endl;
  return memo[n][m][a] = ans;
}

int main() {
  cin >> N >> A;
  for (auto i = 0; i < N; i++) {
    cin >> x[i];
  }
  fill(&memo[0][0][0], &memo[0][0][0]+60*60*2510, -1);
  ll ans = 0;
  for (auto i = 1; i <= N; i++) {
    ans += f(N, i, A*i);
  }
  cout << ans << endl;
}


Measured memory_bytes: 70784
import java.io.*;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.*;

public class Main {
    static Input in = new Input(System.in);
    static PrintWriter out = new PrintWriter(System.out);

    public static void main(String[] args) {
        long N = in.nextLong();
        int ans = 0;
        long div = 2;
        for (; N != 1; div++) {
            if (div * div > N) break;
            int i = 0;
            while (N % div == 0) {
                N /= div;
                i++;
            }
            int j = 1;
            while (i - j >= 0) {
                ans++;
                i -= j;
                j++;
            }
        }
        if (N != 1)
            ans++;
        out.println(ans);

        out.flush();
    }

    static class Input {
        private BufferedReader br;
        private String[] buff;
        private int index = 0;

        Input(InputStream is) {
            br = new BufferedReader(new InputStreamReader(is));
        }
        String nextLine() {
            try {
                return br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return null;
        }
        String next() {
            while (buff == null || index >= buff.length) {
                buff = nextLine().split(" ");
                index = 0;
            }
            return buff[index++];
        }
        byte nextByte() {
            return Byte.parseByte(next());
        }
        short nextShort() {
            return Short.parseShort(next());
        }
        int nextInt() {
            return Integer.parseInt(next());
        }
        long nextLong() {
            return Long.parseLong(next());
        }
        float nextFloat() {
            return Float.parseFloat(next());
        }
        double nextDouble() {
            return Double.parseDouble(next());
        }
        BigInteger nextBigInteger() {
            return new BigInteger(next());
        }
        BigDecimal nextBigDecimal() {
            return new BigDecimal(next());
        }
    }
}



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

using namespace std;

#define EPS 1e-10
#define equal(a,b) (fabs(a-b) < EPS)
#define lt(a,b) (a-b < -EPS)

struct Point{
    double x,y;

    Point(){}
    Point(double x,double y) : x(x),y(y) {}

    Point operator + (const Point &p)const{ return Point(x+p.x,y+p.y); }
    Point operator - (const Point &p)const{ return Point(x-p.x,y-p.y); }
    Point operator * (const double &k)const{ return Point(x*k,y*k); }
};

double dot(const Point &a,const Point &b){ return a.x*b.x + a.y*b.y; }
double cross(const Point &a,const Point &b){ return a.x*b.y - b.x*a.y; }
double norm(const Point &p){ return dot(p,p); }
double abs(const Point &p){ return sqrt(norm(p)); }

#define COUNTER_CLOCKWISE 1
#define CLOCKWISE -1
#define ONLINE_BACK 2
#define ONLINE_FRONT -2
#define ON_SEGMENT 0
typedef Point Vector;

int ccw(Point p0,Point p1,Point p2){
    Vector a = p1 - p0;
    Vector b = p2 - p0;
    if(cross(a,b) > EPS) return COUNTER_CLOCKWISE;
    if(cross(a,b) < -EPS) return CLOCKWISE;
    if(dot(a,b) < -EPS) return ONLINE_BACK;
    if(norm(a) < norm(b)) return ONLINE_FRONT;
    return ON_SEGMENT;
}

struct Segment{
    Point s,t;
    Segment(){}
    Segment(Point s,Point t) : s(s),t(t) {}
};

typedef Segment Line;

Line getPerpendicularBisector(const Point &a,const Point &b){
    double cx = (a.x + b.x) / 2.0;
    double cy = (a.y + b.y) / 2.0;
    Point p = Point(cx + (a.y - b.y), cy + (b.x - a.x));
    return Line(Point(cx,cy),p);
}

Point crosspointLL(const Line &a,const Line &b){
    Vector va = a.t-a.s, vb = b.t-b.s;
    double d = cross(vb,va);
    if(abs(d) < EPS) return b.s;
    return a.s+va*cross(vb,b.t-a.s)*(1.0/d);
}

#define prev(G,i) (G[(i-1+G.size())%G.size()])
#define curr(G,i) (G[i%G.size()])
#define next(G,i) (G[(i+1)%G.size()])
typedef vector<Point> Polygon;

Polygon convex_cut(const Polygon &pg,const Line &l){
    Polygon res;
    for(int i = 0 ; i < (int)pg.size() ; i++){
        Point cp = curr(pg,i), np = next(pg,i);
        if(ccw(l.s,l.t,cp) != -1) res.push_back(cp);
        if(ccw(l.s,l.t,cp)*ccw(l.s,l.t,np) < 0){
            res.push_back(crosspointLL(Line(cp,np),l));
        }
    }
    return res;
}
        
double area(const Polygon &pg){
    double res = 0;
    for(int i = 0 ; i < (int)pg.size() ; i++){
        res += cross(pg[i],next(pg,i));
    }
    return abs(res)/2.0;
}

int main(){
    int N,M;
    while(cin >> N >> M, N){
        Polygon pg(N);
        for(int i = 0 ; i < N ; i++){
            cin >> pg[i].x >> pg[i].y;
        }
        vector<Point> ps(M);
        for(int i = 0 ; i < M ; i++){
            cin >> ps[i].x >> ps[i].y;
        }
        for(int i = 0 ; i < M ; i++){
            Polygon p = pg;
            for(int j = 0 ; j < M ; j++){
                if(i == j) continue;
                p = convex_cut(p,
                               getPerpendicularBisector(ps[i],ps[j]));
            }
            printf("%.15f\n",area(p));
        }
    }
    return 0;
}

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

int main() {
    
    int n, a[100];
    cin >> n;
    for (int i = 0; i < n; i++) cin >> a[i];
    
    sort(a, a + n, greater<int>());
    
    int ans = 0;
    for (int i = 0; i < n; i++)
        ans += a[i] * (i % 2 ? -1 : 1);
    
    cout << ans << endl;
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
    int N,M;
    cin>>N>>M;
    vector<int>A(N);
    vector<int>B(N);
    for(int i=0; i<N; i++){
        cin>>A.at(i);
        cin>>B.at(i);
    }
    vector<int>C(M);
    vector<int>D(M);
    for(int i=0; i<M; i++){
        cin>>C.at(i);
        cin>>D.at(i);
    }
    for(int i=0; i<N; i++){
        int answer=0;
             int h=1000000000;
        for(int j=0; j<M; j++){
             if(abs(A.at(i)-C.at(j))+abs(B.at(i)-D.at(j))<h){
                 answer=j+1;
               h=abs(A.at(i)-C.at(j))+abs(B.at(i)-D.at(j));
             }
        }
        cout<<answer<<endl;
    }
}


Measured memory_bytes: 3584
cookie = [int(i) for i in input().split() ]
cnt = 0
a = cookie[0]
b = cookie[1]
c = cookie[2]
x = 0
y = 0
z = 0
while a % 2 == 0 and b % 2 == 0 and c % 2 == 0:
    if a == 1 and b == 1 and c == 1:
        break
    if a == b and a == c:
        break
    x = (b + c)//2
    y = (a + c)//2 
    z = (a + b)//2
    cnt += 1
    a = x
    b = y 
    c = z
    x = 0
    y = 0
    z = 0
if a  == 1 and b == 1 and c == 1: 
        print("0")
elif a == b and a == c:
    print("-1")
else:
    print(cnt)

Measured memory_bytes: 38620
#include <iostream>
#include <vector>
// #include <algorithm>
using namespace std;

typedef long long ll;
#define all(x) (x).begin(),(x).end()

void solve(){
    ll N;
    cin >> N;

    vector<ll> a(N+1);
    for (int i = 1; i <= N; i++) {
        cin >> a[i];
    }

    vector<ll> b(N+1);
    for (int i = N; i > 0; i--) {
        ll sum = 0;
        for (int j = 2; j <= N / i; j++) {
            sum += b[j*i];
        }
        b[i] = a[i] ^ (sum % 2);
    }

    int cnt = 0;
    for (int i = 1; i <= N; i++) {
        if (b[i] == 1) {
            cnt++;
        }
    }

    if (cnt == 0) {
        cout << 0 << endl;
        return;
    }

    vector<ll> candidate;
    for (int i = 1; i <= N; i++) {
        if (b[i] == 1) {
            candidate.push_back(i);
        }
    }

    cout << cnt << endl;
    for (int i = 0; i < cnt; i++) {
        if (i == 0) {
            cout << candidate[0];
        } else {
            cout << " " << candidate[i];
        }
    }
    cout << endl;

    return;
}

int main(int argc, char const* argv[])
{
    solve();
    return 0;
}


Measured memory_bytes: 4980
a=gets.chomp.to_i
b=gets.chomp.to_i
c=gets.chomp.to_i
x=gets.chomp.to_i
z=0
for n in 0..a do
  for m in 0..b do
    for l in 0..c do
      if n*500+m*100+l*50==x then
        z+=1
      end
    end
  end
end
puts z

Measured memory_bytes: 1788
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using P=pair<int,int>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
const ll mod=1000000007;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
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 (a>b) { a=b; return 1; } return 0; }
vector<ll> divisor(ll n){
	vector<ll> ret;
	for(int i=1;i<=(int)sqrt(n);i++){
		if(n%i==0){
			ret.push_back(i);
            if(i*i!=n)ret.push_back(n/i);
		}
	}
	sort(ret.begin(),ret.end(),greater<ll>());
	return(ret);
}
int main(){
ll n,m;
cin>>n>>m;
V<ll> tmp=divisor(m);
for(int i=0;i<tmp.size();i++){
    if(tmp[i]*n<=m){
        cout<<tmp[i]<<endl;
        return 0;
    }
}
}


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

int isort(int A[],int N){
  int minj,sw=0;
  for(int i=0;i<N;i++){
    minj=i;
    for(int j=i;j<N;j++){
      if(A[minj]>A[j]) minj=j;
    }
    swap(A[i],A[minj]);
    if(i!=minj)sw++;
  }
  return sw;
}

int main(){
  int A[100],N,sw;
  cin>>N;

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

  sw=isort(A,N);

  for(int i=0;i<N;i++){
    if(i!=0) cout<<" ";
    cout<<A[i];
  }
  cout<<endl;
  cout<<sw<<endl;
  return 0;
}

Measured memory_bytes: 3100
#include<stdio.h>
int main(){
	int a=0,c=0;
	int b[10000];
	scanf("%d",&a);
	
	for(int i=0;i<a;i++)
	{
		scanf("%d",&b[i]);
	}
	
	for(int j=0;j<a;j++)
	{
		for(int i=j;i<a-1;i++)
		{
			c+=b[j]*b[i+1];
		}
		
	}
	printf("%d",c);
	
	return 0;
} 

Measured memory_bytes: 128
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <bitset>
#include <climits>
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define RFOR(i,a,b) for (int i=(a)-1;i>=(b);i--)
#define ll long long
#define ull unsigned long long
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const int INF = 1e9;
const ll LL_INF = 1e18;
const int MOD = 1e9 + 7;

using namespace std;
const int MAXN = (1e5) + 4;
int r[30][100005];
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, C;
  cin >> N >> C;
  REP(i,N){
    int s, t, c;
    cin >> s >> t >> c;
    c--;
    s--;
    r[c][s]++;
    r[c][t]--;
  }
  REP(i,C)
  REP(j,MAXN){
      r[i][j + 1] += r[i][j];
  }
  int ans = 0;
  REP(i,MAXN){
    int res = 0;
    REP(j,C) if(r[j][i] > 0) res++;
    ans = max(ans, res);
  }
  cout << ans << endl;
  return 0;
}


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

int main(int argc, char const *argv[])
{
	int n;
	while(cin>>n,n)
	{
		int a[n],s=0;
		for (int i = 0; i < n; ++i) cin>>a[i],s+=a[i];
		double v=(double)s/n;
		int ans=0;
		for (int i = 0; i < n; ++i) if((double)a[i]<v+0.000001) ++ans;
		cout<<ans<<endl;
	}
	return 0;
}


Measured memory_bytes: 3120
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
from bisect import bisect_left, bisect_right
import random
from itertools import permutations, accumulate, combinations
import sys
import string
from copy import deepcopy

INF = float('inf')


def LI(): return list(map(int, sys.stdin.readline().split()))


def I(): return int(sys.stdin.readline())


def LS(): return sys.stdin.readline().split()


def S(): return sys.stdin.readline().strip()


def IR(n): return [I() for i in range(n)]


def LIR(n): return [LI() for i in range(n)]


def SR(n): return [S() for i in range(n)]


def LSR(n): return [LS() for i in range(n)]


def SRL(n): return [list(S()) for i in range(n)]


def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]


mod = 10 ** 9 + 7

n = I()
A = LI()
ret = 0
ans = 0
for i in range(n):
    if A[i] > ret:
        ret = A[i]
    elif A[i] < ret:
        ans += ret - A[i]

print(ans)


Measured memory_bytes: 110296
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long int;
 
const int MAX = (int)(1e5 + 5);
const ll INF = (ll)(1e10 + 5);
 
string s;
 
int main(void) {
  // Here your code !
 
  cin >> s;
 
  if ("2019/04/30" < s) {
    printf("TBD\n");
  }
  else {
    printf("Heisei\n");
  }
 
  return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import static java.lang.Math.*;

public class Main {
    public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int d = sc.nextInt();
		int t = sc.nextInt();
		int s = sc.nextInt();
		
		// 計算
		String result = "No";
		if(t*s >= d) result = "Yes";
		
		
		// 出力
		System.out.println(result);
	}
	
	public static class Scanner {
		private BufferedReader br; private StringTokenizer tok;
		public Scanner(InputStream is) throws IOException { br = new BufferedReader(new InputStreamReader(is));}
		private void getLine() throws IOException { while(!hasNext()) tok = new StringTokenizer(br.readLine());}
		private boolean hasNext() { return tok != null && tok.hasMoreTokens();}
		public String next() throws IOException { getLine(); return tok.nextToken();}
		public int nextInt() throws IOException { return Integer.parseInt(next());}
		public long nextLong() throws IOException { return Long.parseLong(next());}
		public double nextDouble() throws IOException { return Double.parseDouble(next());}
	}
}


Measured memory_bytes: 25388
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>

using namespace std;

int main(int argc, char *argv[]) {
  // read inputs
  int N, L;
  scanf("%d %d", &N, &L);

  // solve
  int closest_to_zero = L, total = 0;
  for (int i = 0; i < N; i++) {
    const int k = L + i;
    total += k;
    if (abs(k) < abs(closest_to_zero)) {
      closest_to_zero = k;
    }
  }
  printf("%d\n", total - closest_to_zero);
  
  return 0;
}


Measured memory_bytes: 128
use std::io::*;
use std::str::*;
use std::collections::*;

pub fn read_from<T: FromStr, R: Read>(s: &mut R) -> T {
    let s = s.bytes().map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    if !s.is_empty() {
        if let Ok(s) = s.parse::<T>() {
            s
        } else {
            panic!("faild to parse {}", s);
        }
    } else {
        if cfg!(local) {
            // eprintln!("reached to EOF");
        }
        std::process::exit(0)
    }
}

pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let mut stdin = stdin.lock();
    read_from(&mut stdin)
}

pub fn chars() -> Vec<char> {
    let stdin = stdin();
    let mut stdin = stdin.lock();
    let s: String = read_from(&mut stdin);
    s.chars().collect()
}

pub fn readn<T: FromStr>(n: usize) -> Vec<T> {
    let stdin = stdin();
    let mut stdin = stdin.lock();
    (0..n).map(|_| read_from(&mut stdin)).collect()
}

fn main() {
    loop {
        let n: usize = read();
        let m: usize = read();
        let q: usize = read();

        let tokens = readn(q*2+m*2);

        let mut to_l: Vec<_> = vec![BTreeSet::new(); n + 1];
        let mut to_r: Vec<_> = vec![BTreeSet::new(); n + 1];
        let mut rails: Vec<(usize, usize, usize)> = (0..m).map(|i| (tokens[i*2], tokens[i*2+1], i)).collect();
        rails.sort();
        let mut rails: VecDeque<_> = rails.iter().cloned().collect();
        for &(l, r, i) in rails.iter() {
            to_l[r].insert((l, i));
            to_r[l].insert((r, i));
        }
        let mut qs: Vec<_> = (0..q).map(|i| {
            let l: usize = tokens[m*2+i*2];
            let r: usize = tokens[m*2+i*2+1];
            (l, r, i)
        }).collect();
        qs.sort();

        let mut ans = vec![0; q];
        for &(ql, qr, i) in qs.iter() {
            while rails.len() > 0 && rails.front().unwrap().0 < ql {
                let (l, r, i) = rails.pop_front().unwrap();
                to_l[r].remove(&(l, i));
                to_r[l].remove(&(r, i));
            }
            let mut cnt = 0;
            for r in ql..qr + 1 {
                cnt += to_l[r].len();
            }
            ans[i] = cnt;
        }

        for e in ans.iter() {
            println!("{}", e);
        }
    }
}


Measured memory_bytes: 41844
#include<iostream>
using namespace std;
int main(){
	int str[10000],i;
	str[1]=1;
	for(int i=1;i<i+1;i++){
		cin>>str[i];
		if(str[i]==0){
			for(int a=1;a<i;a++){
				cout<<"Case "<<a<<": "<<str[a]<<endl;
			}
			break;
		}
	}
	
	
	return 0;
}

Measured memory_bytes: 1196
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")



M = 10**9+7
N = 4*10**5+3 # 必要なテーブルサイズ

def cmb(n, r, M):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return (g1[n] * g2[r] * g2[n-r]) % M

g1 = [None] * (N+1) # 元テーブル
g2 = [None] * (N+1) #逆元テーブル
inverse = [None] * (N+1) #逆元テーブル計算用テーブル
g1[0] = g1[1] = g2[0] = g2[1] = 1
inverse[0], inverse[1] = [0, 1] 

for i in range( 2, N + 1 ):
    g1[i] = ( g1[i-1] * i ) % M 
    inverse[i] = ( -inverse[M % i] * (M//i) ) % M # ai+b==0 mod M <=> i==-b*a^(-1) <=> i^(-1)==-b^(-1)*aより
    g2[i] = (g2[i-1] * inverse[i]) % M 

n,k = map(int, input().split())
M = 10**9+7
if k<n:
    ans = 0
    for p in range(k+1):
        ans += cmb(n,p,M) * cmb(n-1, p, M)
        ans %= M
else:
    ans = cmb(2*n-1,n,M)
print(ans)

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

int main() {
    int N, K; cin >> N >> K;
    vector<char> D(K);
    REP(i, 0, K) {
        cin >> D[i];
    }

    while (1) {
        string s = to_string(N);
        bool ok = true;
        REP(i, 0, s.size()) {
            REP(j, 0, D.size()) {
                if (s[i] == D[j]) {
                    ok = false;
                    break;
                }
            }
            if (!ok) break;
        }
        if (ok) break;
        N++;
    }
    cout << N << endl;
    return 0;
}

Measured memory_bytes: 256