akhauriyash/Code-Regression huggingface dataset:
import random as rng
import itertools as it
import collections as col
import heapq as hq
import sys
import copy as cp
sys.setrecursionlimit(10**9)
input = sys.stdin.readline


def dump_impl(*objects):
    print(*objects, file=sys.stderr)


def dump_dummy(*objects):
    pass


dump = dump_impl if "DEBUG" in sys.argv else dump_dummy


def odd(n): return n & 1


def even(n): return not odd(n)


A, B, C = map(int, input().split())
ans = 0
a, b, c = A, B, C
while True:
    dump(a, b, c)
    if odd(a) or odd(b) or odd(c):
        print(ans)
        exit()
    if ans > 0 and a == A and b == B and c == C:
        print(-1)
        exit()
    a, b, c = (b+c)//2, (a+c)//2, (a+b)//2
    ans += 1


Measured memory_bytes: 9740
#include <iostream>

struct Node{
  Node (int z) : //constructor
    key (z),
    parent (-1),
    id (0),
    left (nullptr),
    right (nullptr)
  {}
  Node () :  //defoult constructor
    key (0),
    parent (-1),
    id (0),
    left (nullptr),
    right (nullptr)
  {}
  int key;
  int parent;
  int id;
  Node *left, *right;
};
  Node *root;

//Preorder tree walk.
void preorder(Node *node){
  std::cout << " " << node->id;
  if(node->left != nullptr) preorder(node->left);
  if(node->right != nullptr) preorder(node->right);
}
//Inorder tree walk.
void inorder(Node *node){
  if(node->left != nullptr) inorder(node->left);
  std::cout << " " << node->id;
  if(node->right != nullptr) inorder(node->right);
}
//Postorder tree walk.
void postorder(Node *node){
  if(node->left != nullptr) postorder(node->left);
  if(node->right != nullptr) postorder(node->right);
  std::cout << " " << node->id;
}
int FindRoot(Node* nodes, int n){
  for(int i=0; i<n; i++){
    if(nodes[i].parent == -1){
      return i;
    }
  }
  return n-1;
}
int  main(){
  int n;
  std::cin >> n;

  //input
  Node nodes[n];
  for(int i=0; i<n; i++){
    int id, left, right;
    std::cin >> id >> left >> right;
    nodes[id].id = id;
    if( left != -1 ){
      nodes[id].left = &nodes[left];
      nodes[left].parent = id;
    }
    if( right != -1 ){
      nodes[id].right = &nodes[right];
      nodes[right].parent = id;
    }
  }
  //Get root index.
  int idx = FindRoot(nodes, n);
  root = &nodes[idx];

  std::cout << "Preorder" << std::endl;
  preorder(root);
  std::cout << std::endl;
  std::cout << "Inorder" << std::endl;
  inorder(root);
  std::cout << std::endl;
  std::cout << "Postorder" << std::endl;
  postorder(root);
  std::cout << std::endl;

    return 0;
}




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

int main(){
	char x;
	int b,c;
	while(1){
		c=0;
		while(1){
			scanf("%c",&x);
			if(x=='\n')break;
			b=x-'0';
			c=c+b;
		}
		if(c==0)break;
		cout << c << endl;
	}
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, long long> P;

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

    int n, m;
    cin >> n >> m;
    vector<int> A(n);
    for(int i = 0; i < n; i++){
        cin >> A[i];
    }

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

    map<int, long long> mp;
    for(int i = 0; i < m; i++){
        long long b;
        int c;
        cin >> b >> c;
        mp[-c] += b;
    }

    vector<P> B((int)mp.size());
    int idx = 0;
    for(auto x : mp){
        B[idx] = {-x.first, x.second};
        idx++;
    }

    int b_i = 0;
    for(int i = 0; i < n; i++){
        if(A[i] > B[b_i].first) break;
        A[i] = B[b_i].first;
        B[b_i].second--;
        if(B[b_i].second == 0){
            b_i++;
            if(b_i == (int)B.size()){
                break;
            }
        }
    }

    long long ans = 0;
    for(int i = 0; i < n; i++){
        ans += A[i];
    }
    
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 8448
import math
import numpy as np
A, B, H, M = [int(i) for i in input().split()]

ji = np.array([A*math.cos(-math.pi/6*(H+M/60) + math.pi/2), A*math.sin(-math.pi/6*(H+M/60) + math.pi/2)])

hun = np.array([B*math.cos(-math.pi/30*M + math.pi/2), B*math.sin(-math.pi/30*M + math.pi/2)])

print(math.sqrt(((ji-hun)**2).sum()))

Measured memory_bytes: 27172
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <array>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdio>
#include <iomanip>
#include <utility>
#include <unordered_map>

using namespace std;
typedef long long int ll;

#define SP(x) setprecision((int)x)
#define SW(x) setw(x) // 桁数指定
#define SF(c) setfill(c) // 埋め文字指定('0')
#define ALL(v) v.begin(), v.end()

int main(int argc, char const *argv[])
{
    ll n;
    string s;
    cin >> n;
    cin >> s;
    ll ans = 0;
    for (ll i = 0; i < 1000; i++)
    {
        ostringstream ss;
        ss << SF('0') << SW(3) << i;
        ll t = 0;
        while (t < n)
        {
            if (s[t] == ss.str()[0])
                break;
            t++;
        }
        if (t >= n)
            continue;
        t++;
        while (t < n)
        {
            if (s[t] == ss.str()[1])
                break;
            t++;
        }
        if (t >= n)
            continue;
        t++;
        while (t < n)
        {
            if (s[t] == ss.str()[2])
                break;
            t++;
        }
        if (t >= n)
            continue;
        ans++;
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
"""
N = int(input())
A, B = map(int,input().split())
lst = [list(map(int,input().split())) for i in range(M)]
A = list(map(int,input().split()))
"""

M, D = map(int,input().split())

if D < 10 or M < 4:
  print(0)
  exit()
  
ans = 0
for day in range(10,D+1):
  d1 = day % 10
  d10 = day // 10
  if d1 > 1 and d10 > 1:
    if d1 * d10 <= M:
      ans += 1
      
print(ans)

Measured memory_bytes: 3060
using System;
using System.Linq;
using System.Collections.Generic;

namespace AtCoder
{
    class Program
    {
        public static int CountChar(string s, char c)
        {
            return s.Length - s.Replace(c.ToString(), "").Length;
        }
        public static void Main(string[] args)
        {
            string S = Console.ReadLine();
            int N = S.Length;
            int num0 = CountChar(S, '0');
            int num1 = N - num0;
            Console.WriteLine((num0 > num1)? num1 * 2: num0 * 2);
        }
    }
}

Measured memory_bytes: 13536
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
using Pt = complex<double>;
using Pr = pair<Pt,int>;
const double EPS = 1e-9, PI = -acos(-1);
int n;
namespace std{
	bool operator<(const Pt& a, const Pt& b) {
		return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
	}
}
bool R(Pt a, Pt b, Pt c){return imag(conj(b-a)*(c-a)) < -EPS;}
double calc(Pt a, Pt b, Pt c){
	return abs(arg((b-a)/(c-b)) / (2*PI));
}
void convex_hull(vector<Pr> ps){
	vector<Pr> ch(ps.size()*2);
	auto r = ch.begin();
	sort(ps.begin(), ps.end());
	rep(i,2){
		auto t = r+1;
		for(auto p:ps){
			while(r > t && !R((r-2)->first, (r-1)->first, p.first)) r--;
			*(r++) = p;
		}
		r--;
		if(!i) reverse(ps.begin(), ps.end());
	}
	int sz = r-ch.begin();
	vector<double> ans(n);
	rep(i,r-ch.begin()) ans[ch[i].second] = calc(ch[i?i-1:sz-1].first, ch[i].first, ch[i+1].first);
	rep(i,n) printf("%.8f\n", ans[i]);
}
double x, y;
int main(){
	scanf("%d", &n);
	vector<Pr> ps(n);
	rep(i,n){
		scanf("%lf%lf", &x, &y);
		ps[i] = Pr(Pt(x,y),i);
	}
	convex_hull(ps);
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std ;
#define N 120000
#define int long long 
map<int,int > mp;
int a[N];
signed main()
{
	int n;
	cin>>n;
	int fu=0;
	int sum=0;
	int minn=9999999999999;
	for(int i=1;i<=n;i++){
		scanf("%lld",&a[i]);
		sum+=abs(a[i]);
		minn=min(minn,abs(a[i]));
		if(a[i]<0) fu++;
	}
	if(fu%2==1){
		printf("%lld\n",sum-2*minn);
	}
	else{
		printf("%lld\n",sum);
	}
} 

Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        var input = Console.ReadLine();

        var flag = false;

        foreach(var n in input)
        {
            if(n == '7')
            {
                flag = true;
            }
        }


        if (flag)
        {
            Console.WriteLine("Yes");
        }
        else
        {
            Console.WriteLine("No");
        }
        Console.ReadLine();

    }
}

Measured memory_bytes: 17332
#include<iostream>
#include<climits>
#include<cstring>
using namespace std;

long long int profit = 0;

long long int maxProfit(long long int weight[], long long int value[], long long int n, long long int w, long long int idx,long long int mem[105][100005]) {
    
     //cout<<idx<<" "<<value[idx]<<" "<<w<<endl;
    
    if(idx>=n || w==0)
      return 0;
      
    if(mem[idx][w]!=-1)
       return mem[idx][w];
      
   
    
    long long int profit1 = INT_MIN;
    if(weight[idx]<=w){
	profit1 = value[idx] + maxProfit(weight, value, n, w - weight[idx], idx + 1,mem);
    }
	
	long long int profit2 = maxProfit(weight, value, n, w, idx + 1,mem);
	
	//cout<<profit1<<" "<<profit2;
	
	profit = max(profit1, profit2);
	mem[idx][w] = profit;

	return profit;
}



int main() {
	long long int weight[105];
	long long int n, w;
	cin >> n >> w;
	long long int value[105];

	for (int i = 0; i < n; i++) {
		long long int w1, v1;
		cin >> w1 >> v1;
		weight[i] = w1;
		value[i] = v1;
	}
	
	long long int mem[105][100005];
	memset(mem,-1,sizeof mem);

	/*for (int i = 0; i < n; i++) {
		cout << weight[i] << " " << value[i] << endl;
	}*/

	cout << maxProfit(weight, value, n, w, 0,mem) << endl;







	return 0;
}

Measured memory_bytes: 85644
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

int N;
int a[200010], b[200010];

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < N; i++) {
    cin >> b[i];
  }
  int ans = 0;
  for (int i = 0; i+1 < 30; i++) {
    vector<int> va, vb;
    for (int j = 0; j < N; j++) {
      va.emplace_back(a[j]%(1<<(i+1)));
      vb.emplace_back(b[j]%(1<<(i+1)));
    }
    sort(vb.begin(), vb.end());
    int cnt = 0;
    for (int j = 0; j < N; j++) {
      cnt += lower_bound(vb.begin(), vb.end(), (2*(1<<i)-va[j])) - lower_bound(vb.begin(), vb.end(), ((1<<i)-va[j]));
      cnt += lower_bound(vb.begin(), vb.end(), (4*(1<<i)-va[j])) - lower_bound(vb.begin(), vb.end(), (3*(1<<i)-va[j]));
    }
    if (cnt&1) ans += 1 << i;
  }
  cout << ans << endl;

  return 0;
}

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

const long long mod = 1e9+7;

// a^bを返す
long long Pow(long long a, long long b) {
	long long ret = 1;
	while (b > 0) {
		if (b & 1) {
			ret = (ret % mod) * (a % mod) % mod;
		}
		a = (a % mod) * (a % mod) % mod;
		b /= 2;
	}

	return ret % mod;
}

// nCkを返す
long long nCk(long long n, long long k) {
	long long bunbo = 1, bunshi = 1;
	for (int ki = 1; ki <= k; ki++) {
		bunbo *= ki;
		bunshi *= n - ki + 1;
		bunbo %= mod;
		bunshi %= mod;
	}

	return bunshi * Pow(bunbo, mod - 2) % mod;
}

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

	// 全体の本数
	long long ans = Pow(2, n) - 1;

	// nCaの分を引く
	ans -= nCk(n, a);
	ans %= mod;

	// nCbの分を引く
	ans -= nCk(n, b);
	ans %= mod;

	// ans を絶対値modの範囲に収める → modを足して正の値にする → あまりを求める
	ans = ((ans % mod) + mod) % mod;

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cerr<<*i<<" "; cerr<<endl; }
inline bool valid(int x, int y, int W, int H){ return (x >= 0 && y >= 0 && x < W && y < H); }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 100000007;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
ll extgcd(ll a, ll b, ll &x, ll &y){
  int d = a;
  if(b != 0){
    d = extgcd(b, a % b, y, x);
    y -= (a / b) * x;
  }else{
    x = 1; y = 0;
  }
  return d;
}
ll mod_inv(ll a, ll M){
  ll x, y;
  extgcd(a, M, x, y);
  return (M + x % M) % M;
}
ll FACT[2001], IFACT[2001];
ll binomial(ll n, ll r){
  if(n < 0 || r < 0 || r > n)return 0;
  if(r > n / 2)r = n - r;
  return FACT[n]*IFACT[n-r]%MOD*IFACT[r]%MOD;
}

int main(){
  FACT[0] = 1; IFACT[0] = 1;
  for(int i = 1; i <= 2000; i++){
    FACT[i] = (FACT[i - 1] * i) % MOD;
    IFACT[i] = mod_inv(FACT[i], MOD);
  }
  int r, c, a1, a2, b1, b2;
  ll k = 1;
  cin>>r>>c>>a1>>a2>>b1>>b2;
  int y = abs(b1 - a1);
  if(y == r - y) k *= 2;
  else if(y > r - y) y = r - y;
  int x = abs(b2 - a2);
  if(x == c - x) k *= 2;
  else if(x > c - x) x = c - x;
  cout<<(k * binomial(x + y, x)) % MOD<<endl;
  return 0;
}

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

int main()
{
  
  vector<string> s;
  int n,l;
  cin>>n>>l;
  int i;
  for(i=0;i<n;i++)
  {
     string ch;
      cin>>ch;
      s.push_back(ch);
  
  }
  
  sort(s.begin(),s.end());
  
    string f;
    
    for(auto it=s.begin();it!=s.end();it++)
    {
    	
    	
       f=f+*it;
    	
    
	}
  
      cout<<f<<endl;
  
 return 0;
  

}

Measured memory_bytes: 3652
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <cassert>
using namespace std;
using ll = long long;
const int INF = 1<<30;
const int MOD = 1e9 + 7;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int m;
    while(cin >> m, m)
    {
        vector<int> a(m), b(m);
        for(int i = 0; i < m; i++) cin >> a[i] >> b[i];
        vector<int> dp(1010, 0);
        dp[0] = 1;
        for(int i = 0; i < m; i++)
        {
            for(int j = 1010; j >= 1; j--)
            {
                for(int k = 1; k <= b[i]; k++)
                {
                    if(j - a[i] * k >= 0) dp[j] += dp[j - a[i] * k];
                }
            }
        }
        int g; cin >> g;
        for(int i = 0; i < g; i++)
        {
            int n; cin >> n;
            cout << dp[n] << endl;
        }
    }
    return 0;
}




Measured memory_bytes: 3064
// lcmとか__builtin_popcountとかはg++ -std=c++17 default.cppみたいなかんじで

#include <bits/stdc++.h>
#define mod 1000000007
#define INF LLONG_MAX
#define ll long long
#define ln cout<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define YES cout<<"YES"<<endl
#define No cout<<"No"<<endl
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
using namespace std;
ll dx[4]={1,0,-1,0};
ll dy[4]={0,1,0,-1};

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

    ll a=0,b=0,c,d,m,n,maxi=0,f=0,mini=INF,sum=0;
    string str;
  cin>>n;
    cin>>str;
    rep(i,str.length())
      if(str[i]=='R') a++;
  else b++;
  if(a>b) Yes;
  else No;

    return 0;
}


Measured memory_bytes: 3572
#include<iostream>
using namespace std;
int main(){
	int A,B;
	string S;
	cin>>A>>B;
	cin>>S;
	for (int i=0;i<A+B+1;i++){
		if(i<A){
			if(!('0'<=S[i]&&S[i]<='9')){
				cout<<"No";
				return 0;
			}
		}
		if(i==A){
			if(S[i]!='-'){
				cout<<"No";
				return 0;
			}
		}
		if(i>A)
			if(!('0'<=S[i]&&S[i]<='9')){
				cout<<"No";
				return 0;
			}
	}
	cout<<"Yes";
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<utility>
#include<algorithm>
#include<string>
#include<cstdio>
#include<queue>
#include<functional>
#include<tuple>
#include<iomanip>
#include<stack>
#include<cmath>
#define ll long long
using namespace std;
int main() {
	int n, w, h; cin >> n >> w >> h;
	int dataw[100001] = {}, datah[100001] = {};
	for (int i = 0; i < n; ++i) {
		int x, y, z; cin >> x >> y >> z;
		int minx=x-z, maxx=x+z, miny=y-z, maxy=y+z;
		if (minx < 0) minx = 0;
		if (maxx > w) maxx = w;
		if (miny < 0) miny = 0;
		if (maxy > h) maxy = h;
		++dataw[minx]; --dataw[maxx];
		++datah[miny]; --datah[maxy];
	}
	int sum = 0,cnt=0;
	for (cnt = 0; cnt < w; ++cnt) {
		sum += dataw[cnt];
		if (sum == 0) break;
	}
	if (cnt == w) {
		cout << "Yes" << endl;
		return 0;
	}
	sum = 0; cnt = 0;
	for (cnt = 0; cnt < h; ++cnt) {
		sum += datah[cnt];
		if (sum == 0) break;
	}
	if (cnt == h) {
		cout << "Yes" << endl;
		return 0;
	}
	cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 3896
function main(_stdin) {
    const stdin = _stdin.trim().split('\n');
    const n = Number(stdin.shift());
    const cards = stdin.map(e => {
        const c = e.split(' ');
        return {mark: c[0], num: Number(c[1])};
    });
    const copy = cards.slice();
    let isStable = true;
    quickSort(cards, 0, n - 1);

    let temp = 0;
    const unum = cards.filter(e => {
        if(temp !== e.num) {
            temp = e.num;
            return temp;
        }
    }).map(e => e.num);

    temp = 0;
    while(isStable && unum.length > temp) {
        const n = unum[temp];
        const initial = cards.filter(e => e.num === n).map(e => e.mark).join();
        const ini2  = copy.filter(e => e.num === n).map(e => e.mark).join();
        if(ini2 !== initial) {
            isStable  = false;
        }
        temp++;
    }

    console.log(isStable ? 'Stable' : 'Not stable');

    for(const card of cards) {
        console.log(card.mark, card.num);
    }
}

function quickSort(A, p, r) {
    if (p < r) {
        const q = partition(A, p, r);
        quickSort(A, p, q - 1);
        quickSort(A, q + 1, r);
    }
}


function partition(A, p, r) {
    let lower = p - 1;
    const x = A[r];

    for (let i = p; i < r; i++) {
        if (A[i].num <= x.num) {
            lower++;
            let t = A[lower];
            A[lower] = A[i];
            A[i] = t;
        }
    }

    t = A[lower + 1];
    A[lower + 1] = A[r];
    A[r] = t;
    return lower + 1;
}


main(require('fs').readFileSync('/dev/stdin', 'utf8'));



Measured memory_bytes: 70712
#include <iostream>
#include <string>

using namespace std;

string decipher (const string& s_, int n) {
    string s = s_;
    for (int i = 0; i < s.size(); i++) {
        if ('a' <= s[i] && s[i] <= 'z') {
            int c = (int)s[i] + n;
            if (c > (int)'z') {
                c = c - (int)'z' + (int)'a' - 1;
            }
            s[i] = (char)c;
        }
    }
    return s;
}

bool test (const string& s) {
    if ((int)s.find("the")  != -1) return true;
    if ((int)s.find("this") != -1) return true;
    if ((int)s.find("that") != -1) return true;
    return false;
}

int main (void) {
    while (1) {
        string s, s_;
        getline(cin, s);
        if (cin.eof()) break;
        for (int i = 0; i < 26; i++) {
            s_ = decipher(s, i);
            if (test(s_)) {
                cout << s_ << endl;
                break;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 1180
import sys
input = sys.stdin.readline

def main():
    n=int(input())
    a=list(map(int,input().split()))
    b=list(map(int,input().split()))
    c=list(map(int,input().split()))
    m=0
    m+=b[a[0]-1]
    for i in range(1,n):
        m+=b[(a[i]-1)]
        if a[i]==a[i-1]+1:
            m+=c[a[i]-2]

    print(m)

if __name__ == "__main__":
    main()



Measured memory_bytes: 3064
import sys

def main():

	N = int(input())
	
	A = list(map(int, input().split()))
	
	Lists = [0]*N
	
	for i in A:
		Lists[i-1] = Lists[i-1] + 1
		
	for List in Lists:
		print(List)

if __name__ == "__main__":
    main()

Measured memory_bytes: 32192
#include <iostream>
#include <cmath>

bool prime_number(int n);
int proceed;
bool pn[1000000];

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

	while(std::cin >> n) {
		if(n < 2) {
			result = 0;
		}else {
			result = 1;
			for(i = 3; i <= n; i += 2) {
				if(prime_number(i)) {
					result++;
				}
			}
		}
		std::cout << result << std::endl;
	}
}

bool prime_number(int n) {
	if(n <= proceed){
		return pn[n];
	}
	proceed = n;
	int i;
	double rt = sqrt(n);
	if(n < 2) {
		return false;
	}else if(n == 2) {
		pn[2] = true;
		return true;
	}else if(n % 2 == 0) {
		return false;
	}
	for(i = 3; i <= rt; i += 2) {
		if(n % i == 0) {
			return false;
		}
	}
	pn[n] = true;
	return true;
}


Measured memory_bytes: 4080
#include<iostream>
#include<algorithm>
#include<queue>
#include<deque>
#include<map>
#include<vector>
#include<math.h>
long long int mod = 1000000007;
long long modpow(long long a, long long n, long long mod);
long long modinv(long long a, long long mod);


using namespace std;
int main() {
	
	//C
	long long int x, k, d;
	cin >> x >> k >> d;
	if (x < 0)x = -x;
	if (x >= 0) {
		if (sqrt(x) > sqrt(k) * sqrt(d)) {
			cout << x - k * d << endl;
			return 0;
		}
		if ((k - (x / d)) % 2 == 0) {
			cout << x % d << endl;
			return 0;
		}
		else {
			cout << d - (x % d) << endl;
			return 0;
		}
	}
	

	//D
	/*
	int n, k;
	cin >> n >> k;
	int p[5000],c[5000];
	int i;
	for (i = 0; i < n; i++) {
		cin >> p[i];
		p[i]--;
	}
	for (i = 0; i < n; i++) {
		cin >> c[i];
	}
	int loopnum = 0, j;
	int l[5000];
	int lpl[5000];
	for (i = 0; i < n; i++) {
		l[i] = -1;
		lpl[i] = 0;
	}
	int loopl;
	for (i = 0; i < n; i++) {
		if (l[i] == -1) {
			j = i;
			loopl = 0;
			while (l[j] == -1) {
				l[j] = loopnum;
				j = p[j];
				loopl++;
			}
			lpl[loopnum] = loopl;
			loopnum++;
		}
	}

	for (i = 0; i < loopnum; i++) {

	}
	*/
}
// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
	long long res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}

// a^{-1} mod を計算する
long long modinv(long long a, long long mod) {
	return modpow(a, mod - 2, mod);
}


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

int cmpnum(const void * n1, const void * n2)
{
	if(*(double *)n1 >*(double *)n2)
	{
		return -1;
	}
	else if(*(double *)n1 < *(double *)n2)
	{
		return 1;
	}
	else
	{
		return 0;
}
}

int main(void)
{
  int i,n;
  double v[51]={0};
  double sum=0;

  scanf("%d",&n);
  for(i=0;i<n;i++)
    scanf("%lf",&v[i]);

  qsort(v, sizeof(v)/ sizeof(v[0]),sizeof(double),cmpnum);

  sum+=v[n-1];
  for(i=0;i<n-1;i++){
    sum+=v[n-2-i];
    sum/=2;
  }
  printf("%lf",sum);

  return 0;

}


Measured memory_bytes: 128
// Author: πα

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

int main()
{
    ios::sync_with_stdio(false), cin.tie(nullptr);
    int n, d, i, x = 0;
    cin >> n;
    for(i = 0; i < n; ++i)
        cin >> d, x ^= d;
    cout << (x ? "No" : "Yes");
    return 0;
}


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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}

using namespace std;
using ll=long long;
ll a[100010];

int main(void){
	int n;
	cin >> n;
	rep(i,n) cin >> a[i];

	ll ans=0LL;

	if(n==1){
		cout << a[0]/2LL << endl;
		return 0;
	}

	rep(i,1,n){
		ll sum=(a[i]+a[i-1]);
		ll cnt=sum/2LL;
		ans+=cnt;

		if(sum%2==1){
			if(a[i]==0)
				a[i-1]=1LL;
			else
				a[i]=1LL;
		}else
			a[i-1]=a[i]=0LL;
	}	

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

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, N) for(int i = 0; i < N; i++)
#define rep2(i, N, a, b) for(int i = a; i < N; i += b)

int main(){
	int Q, H, S, D;
	long long N;
	cin >> Q >> H >> S >> D >> N;

	long long ans = 0;
	int one = min(Q * 4, min(H * 2, S));
	if (one * 2 > D){
		ans += (N / 2) * D;
		N = N % 2;
	}
	ans += N * one;
	cout << ans << endl;
}

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

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

  ll mx = max({a, b, c});
  ll mn = min({a, b, c});
  ll md = a + b + c - mx - mn;

  ll ans = 0;
  ans += mx - md;
  if((md - mn) % 2 == 0) ans += (md - mn)/2;
  else ans += (md - mn + 1)/2/*mn +2*/ + 1;//mxとmd ++

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


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

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define test() int t;cin>>t;for(int test=1;test<=t;test++)
#define pb push_back
#define nl cout<<"\n"
#define F first
#define S second
#define all(x) x.begin(),x.end()

template<class C> void min_self( C &a, C b ){ a = min(a,b); }
template<class C> void max_self( C &a, C b ){ a = max(a,b); }

const ll MOD = 1000000007;
ll mod( ll n, ll m=MOD ){ n%=m,n+=m,n%=m;return n; }

const int MAXN = 2e5+5;
const int LOGN = 21;
const ll INF = 1e14;
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};

template<class T1, class T2, class T3> void add( T1 &x, T2 y, T3 m = MOD )
{
	x += y;
	if( x >= m )
		x -= m;
}

template<class T1, class T2, class T3> void sub( T1 &x, T2 y, T3 m = MOD )
{
	x -= y;
	if( x < 0 )
		x += m;
}

vector<int>roads[MAXN], rails[MAXN];
vector<bool>vis(MAXN), vis2(MAXN);
int road_comp[MAXN], road_size[MAXN];
int rail_comp[MAXN], rail_size[MAXN], cc;

void roads_dfs( int node )
{
	vis[node] = 1;
	road_comp[node] = cc;
	road_size[cc]++;
	for( int next : roads[node] )
	{
		if( !vis[next] )
		{
			roads_dfs(next);
		}
	}
}

void rails_dfs( int node )
{
	vis2[node] = 1;
	rail_comp[node] = cc;
	rail_size[cc]++;
	for( int next : rails[node] )
	{
		if( !vis2[next] )
		{
			rails_dfs(next);
		}
	}
}

int main() 
{
	fastio();

	int n,k,l;
	cin>>n>>k>>l;
	for(int i=0;i<k;i++)
	{
		int u,v;
		cin>>u>>v;
		u--,v--;
		roads[u].pb(v);
		roads[v].pb(u);
	}
	for(int i=0;i<l;i++)
	{
		int u,v;
		cin>>u>>v;
		u--,v--;
		rails[u].pb(v);
		rails[v].pb(u);
	}

	cc = 0;
	for(int i=0;i<n;i++)
	{
		if( !vis[i] )
		{
			roads_dfs(i);
			cc++;
		}
	}

	cc = 0;
	for(int i=0;i<n;i++)
	{
		if( !vis2[i] )
		{
			rails_dfs(i);
			cc++;
		}
	}

	vector<int>order;
	for(int i=0;i<n;i++)
		order.pb(i);

	auto cmp = [&]( int i, int j ) -> bool
	{
		if( road_comp[i] != road_comp[j] )
			return road_comp[i] < road_comp[j];
		return rail_comp[i] < rail_comp[j];
	};

	sort(all(order), cmp);

	vector<int>ans(n);
	for(int i=0;i<n;)
	{
		int a = road_comp[order[i]], b = rail_comp[order[i]];
		int j = i;
		while( j < n && road_comp[order[j]] == a && rail_comp[order[j]] == b ) j++;
		for(int k=i;k<j;k++)
			ans[order[k]] = j-i;
		i = j;
	}

	for(int i=0;i<n;i++)
		cout<<ans[i]<<" ";

	cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
	return 0;
}


Measured memory_bytes: 20856
#include <stdio.h>
  
int main(void){
  
  int a[4][13] = {0};
  int n,rank;
  char c;
  register int i,s;
  
  scanf("%d",&n);
  for(i = 0;i < n;i++){
    scanf("%s %d",&c,&rank);
    switch(c){
      case 'S':
        a[0][rank - 1] = 1;
        break;
      case 'H':
        a[1][rank - 1] = 1;
        break;
      case 'C':
        a[2][rank - 1] = 1;
        break;
      case 'D':
        a[3][rank - 1] = 1;
    }

  }
  for(i = 0;i < 4;i++){
    for(s = 0;s < 13;s++){
      if(a[i][s] == 0){
        switch(i){
          case 0:
            printf("S %d\n",s + 1);
            break;
          case 1:
            printf("H %d\n",s + 1);
            break;
          case 2:
            printf("C %d\n",s + 1);
            break;
          case 3:
            printf("D %d\n",s + 1);
        }
      }
    }
  }
  return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define mod 1000000007
#define pb push_back
#define F first
#define S second
using namespace std;

int main(void) {
	boost;
	ll l, r,d;
	cin >>l>>r>>d;
	ll ans=0;
	if(l%d==0){
		ans=r/d - l/d +1;
	}else{
		ans=r/d - l/d;
	}
	cout<<ans;
	return 0;
}

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

int main() {
  char c;
  cin >> c;
  
  if (c == 'A')
    cout << 'T' << endl;
  if (c == 'G')
    cout << 'C' << endl;
  if (c == 'C')
    cout << 'G' << endl;
  if (c == 'T')
    cout << 'A' << endl;
}

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

using namespace std;

int main(){
    int N, A, B;
    string S;
    cin>>N>>A>>B;
    cin>>S;
    int count = 0, ov = 0;
    for(auto it:S){
        if(it == 'a' && count < A+B){
            cout<<"Yes"<<endl;
            count++;
        }
        else if(it == 'b' && count < A+B && ov < B){
            cout<<"Yes"<<endl;
            count++;
            ov++;
        }
        else cout<<"No"<<endl;
    }
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef long double ld;
#define umap unordered_map
#define size(a) int((a).size())
#define present(c, x) (c.find(x) != c.end()) 
#define printVerdict(verdict) cout << (verdict ? "YES": "NO") << '\n'
#define printDecimal(d) printf("%.9f\n", d)
#define inrange(val, start, end) (val >= start && val <= end)
#define var(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
 
const ll mod = 1e9 + 7; 
const int inf = 0x3f3f3f3f;
 
template <class T1, class T2, class T3> 
void printTuple(tuple<T1, T2, T3> t) { cout << get<0>(t) << " " << get<1>(t) << " " << get<2>(t) << '\n'; }
template <class T1, class T2>
void printPair(pair<T1, T2> p) { cout << p.first << " " << p.second  << '\n'; }
template <class T>
void printArray(vector<T> arr) { for (int i = 0; i<size(arr); i++) {cout << arr[i] << " ";} cout << '\n'; } 
 
int find_rep(int u, vector<int> &parent) {
	if (parent[u] != u) parent[u] = find_rep(parent[u], parent);
	return parent[u];
}

void merge(int u, int v, vector<int> &parent, vector<int> &sz) {
	u = find_rep(u, parent), v = find_rep(v, parent);
	if (u != v) {
		if (sz[u] < sz[v]) swap(u, v);
		sz[u] += sz[v];
		parent[v] = u;
	}
}

int main() {
	std::ios_base::sync_with_stdio(false);
	cin.tie(0);
	int n,q; cin >> n >> q;
	vector<int> parent(n), sz(n, 1);
	for (int i = 0; i<n; i++) parent[i] = i, sz[i] = 1;
	while (q--) {
		int t,u,v; cin >> t >> u >> v;
		if (t == 0) merge(u, v, parent, sz);
		else cout << (find_rep(u, parent) == find_rep(v, parent)) << '\n';
	}
} 


Measured memory_bytes: 4652
#include<stdio.h>
#include<stdlib.h>
int main(){
  int i,j,n,x,k=0,flag;
  int *A;

  scanf("%d",&n);
  if(n<1 || n>100)return 0;

  A = (int *)malloc(sizeof(int) * n);

for(i = 0;i < n;i++){
  scanf("%d",&A[i]);
    if(A[i]<0|| A[i]>100)return 0;
}

flag = 1;
 i = 0; // 未ソート部分列の先頭インデックス
 while (flag){
   flag = 0;

   for( j = n-1 ;j > 0; j--){

     if (A[j] < A[j-1]){
       x = A[j];
       A[j] = A[j-1];
       A[j-1] = x;
        flag = 1;
       k++;
    }
     }
  i++;
 }

  printf("%d",A[0]);
for(i=1;i<n;i++){
  printf(" %d",A[i]);
}
printf("\n");
printf("%d\n",k);

return 0;
}



Measured memory_bytes: 2128
#include <bits/stdc++.h>
using namespace std;
#define int long long

int32_t main(){
    ios::sync_with_stdio(0),cin.tie(0);
    string s,t;
    cin >> s >> t;
    int ans=0;
    for(int i=0;i<(int)s.size();i++)
        if(s[i]!=t[i])ans++;
    cout << ans;
}

Measured memory_bytes: 3816
N = int(input())
A = list(map(int,input().split()))
A.sort()
from collections import Counter
AA = Counter(A)
dp = [True]*(A[-1]+1)
ans = 0
for k,v in AA.items():
    if dp[k]==True and v == 1:
        ans += 1
    for i in range(A[-1]//k+1):
        dp[k*i] = False
print(ans)

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

#define FOR(i, a, n) for(int i = a; i < n; ++i)
#define logarr(arr) for(auto i : arr) { cout << i << " "; } cout << "\n";
#define ll long long
#define sc(a) scanf("%d", &a);
#define scl(a) scanf("%lld", &a);


void solve() {

    int a;
    sc(a);
    int ans = a + (a * a) + (a * a * a);
    cout << ans << endl;

}


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


	int t = 1;
	// sc(t); 
	while(t--) {
		solve();
	}

	return 0;

}
// g++ -std=c++17 -o solve solve.cpp


Measured memory_bytes: 3780
#include<bits/stdc++.h>
#define ll long long int
#define Y printf("YES\n")
#define N printf("NO\n")
#define mp make_pair
#define pb push_back
#define tp make_tuple
#define sc(a) scanf("%lld",&a)
#define sc2(a,b) scanf("%lld%lld",&a,&b)
#define sc3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define pr(a) printf("%lld\n",a)
using namespace std;
#define mod 1000000007

bool chk_bit(ll n,ll k) // check whether 0 or 1
{
    return n & (1LL << k);
}

int main()
{
    ll n,i,j,x=0,y=0,d;

    cin>>n;

    ll a[n+5];

    for(i=0; i<n; i++)cin>>a[i];

    ll sum=0;

    for(i=0; i<64; i++)
    {

        x=0,y=0;

        for(j=0; j<n; j++)
        {

            if(chk_bit(a[j],i))x++;
            else y++;
        }

        d=(x*y)%mod;

        ll dd=(1LL << i)%mod;

        ll kk=(d*dd)%mod;

        sum+=kk;

        sum=sum%mod;
    }

    cout<<sum%mod<<endl;


}



Measured memory_bytes: 5884
import java.util.Scanner;
import java.util.*;
public class Main {
    public static void main(String[] args) {
	Scanner stdin = new Scanner(System.in);
	int n = stdin.nextInt();
	int[] num = new int[100];
	int cnt = 0;

	for ( int i = 0; i < n; i++ ){
	    num[i] = stdin.nextInt();
	}

	int flag = 1;
	while ( flag == 1 ){
	    flag = 0;
	    for ( int j = n-1; j > 0; j-- ){
		if ( num[j] < num[j-1] ){
		    int tmp = num[j];
		    num[j] = num[j-1];
		    num[j-1] = tmp;
		    flag = 1;
		    cnt++;
		}
	    }
	}

	System.out.print(num[0]);
	for ( int i = 1; i < n; i++ ){
	    System.out.print(" " + num[i]);
	}
	System.out.println();
	System.out.println(cnt);

    }
}

Measured memory_bytes: 26120
#include<bits/stdc++.h>
#include<chrono>
#define ll long long
#define mod 1000000007
#define endl '\n'
#define tab ' '
#define pb push_back
#define eb emplace_back
#define ff first
#define ss second
#define watch(x) cout<<(#x)<<" = "<<x<<endl
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define pi 3.141592653589793238460
#define F(i,a,b) for(int i=(int)a;i<=(int)b;i++)
#define RF(i,a,b) for(int i=(int)a;i>=(int)b;i--)
// a.exe < "C:/Users/Piyush Naithani/Desktop/Codechef/Testfiles/icpc2.txt"
using namespace std;

void solve()
{
    int n; 
    cin >> n;

    int A[n];
    for(auto &i: A) cin>>i;

    int broken = 0;
    int cnt = 1;

    bool possible = true;
    
    F(i,0,n-1)
    {
        if(A[i]==cnt)
        {
            cnt++;
        }
        else
        {

            broken++;
            if(broken==n)
                possible = false;
        }
    }

    if(possible) cout << broken;
    else cout << "-1";
    
    
}


int main(){
    fast;
    #ifndef ONLINE_JUDGE
      // freopen("C:\Users\Piyush Naithani\Desktop\Codechef\Testfiles\icpc2.txt","r",stdin);
    
    // freopen("file name","w",stdout);
    #endif

    solve();

    return 0;
}


Measured memory_bytes: 1024
N = int(input())
A = list(map(int,input().split()))
X = []
X.append(sum(A)-2*sum(A[1::2]))
print(X[0],end=" ")
for i in range(1,N):
    X.append(A[i-1]*2-X[i-1])
    print(X[i],end=" ")

Measured memory_bytes: 14092
n,m = map(int,input().split())
r = []
for _ in range(m):
    r.append(tuple(map(int,input().split())))
r.sort(key = lambda x:x[1],reverse = True)
ans = 0
while len(r) > 0:
    _,y = r[-1]
    ans += 1
    while len(r) > 0 and r[-1][0] < y:
        r.pop()
print(ans)

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

a=[0]*(n+1)
a[0]=1
p=[0]*(n+1)
p[0]=1

for i in range(n):
  a[i+1]=2*a[i]+3
  p[i+1]=2*p[i]+1


def f(n,x):
  if x==a[n]:
    return p[n]
  elif x==0:
    return 0
  elif x<=1+a[n-1]:
    return f(n-1,x-1)
  elif x==2+a[n-1]:
    return p[n-1]+1
  elif x>2+a[n-1]:
    return p[n-1]+1+f(n-1,x-2-a[n-1])
  
print(f(n,x))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a;
  int b;
  int c;
  int d;
  cin >> a >> b >> c >> d;
  int left = a+b;
  int right = c+d;
  if (left > right ){
   cout << "Left" ;
  }
  else if (left == right){
    cout << "Balanced" ;
  }
  else{
    cout << "Right";
  }
}


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

using namespace std; 

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef pair<LL, LL> PLL;
typedef vector<PLL> VPLL;
typedef priority_queue<int> PQ_DESC;
typedef priority_queue<int, vector<int>, greater<int>> PQ_ASC;
typedef priority_queue<PII> PQ_DESC_PII;
typedef priority_queue<PII, vector<PII>, greater<PII>> PQ_ASC_PII;

#define ALL(c) (c).begin(),(c).end()
#define PB push_back
#define MP make_pair
#define SORT_ASC(c) sort(ALL(c))
//#define SORT_DESC(c) sort(ALL(c), greater<typeof(*((c).begin()))>())
#define SORT_DESC(c) sort((c).rbegin(),(c).rend())
#define REV(c) reverse((c).begin(), (c).end())
#define SIZE(a) int((a).size())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ROF(i,a,b) for(int i=(b-1);i>=(a);--i)
#define REP(i,n) FOR(i,0,n)
#define PER(i,n) ROF(i,0,n)

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int LARGE_INT = 1e9+100;
const int INF = 2e9+100;
const LL INF_LL = (LL)INF * 300 * 300;
const int MOD = 1e9+7;

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

LL modpow(LL a, LL n) {
    LL res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

void Main()
{
    LL x;cin>>x;


    for(LL a= -6000;a<6000;a++){
        LL a5 = a*a*a*a*a;
        int fugo = 1;
        if(a5<x){
            fugo = -1;
        }
        LL diff = max(x-a5,a5-x);
        for(LL b=0;b*b*b*b*b<=diff;b++){
            LL b5 = b*b*b*b*b;
            if(b5 == diff){
                cout<<a<<" "<<fugo*b<<endl;
                return;
            }
        }
    }


    
    return;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
    return 0;
}

Measured memory_bytes: 3656
#include<bits/stdc++.h>
#define ll long long int
#define ul unsigned long long int
#define all(arr) arr.begin(), arr.end()
#define va vector<long long int> a 
#define vb vector<long long int> b
#define debug() for(ll l=0;l<50;l++){}
const ll M = 1e9+7;
const ll inf = 1e18+5;
const ll val = 10000020;
const ll INF=INT_MAX;
using namespace std;
#define fast cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);
ll bs(ll arr[], ll l, ll r, ll x){
	ll mid=0;
    if (r >= l){
		if (arr[mid] == x) return mid; 
        if (arr[mid] > x) return bs(arr, l, mid - 1, x); 
        return bs(arr, mid + 1, r, x); 
    }
    return -1;
}
ll cs(vector<ll> &a,ll x){
	return upper_bound(all(a),x)-a.begin();
}
ll power(ll x,ul y,ll p){
	ll res = 1;
	x = x % p;
	if(x == 0) return 0;
	while (y > 0){
		if (y & 1) res = (res*x) % p;
		y = y>>1;
		x = (x*x) % p;
		}
	return res;
}
ll arr[500000],st[500000];
void buildtree(int si,int ss,int se){
	if(ss==se){
		st[si]=arr[ss];
		return;
	}
	int mid=ss+(se-ss)/2;
	buildtree(2*si,ss,mid);
	buildtree(2*si+1,mid+1,se);
	st[si]=min(st[2*si],st[2*si+1]);
}
int query(int si,int ss,int se,int qs,int qe){
	if(qs>se || qe<ss) //completely outside
		return INF;
	if(ss>=qs && se<=qe)
		return st[si];
	int mid=ss+(se-ss)/2;
	int l=query(2*si,ss,mid,qs,qe);
	int r=query(2*si+1,mid+1,se,qs,qe);
	return min(l,r);
}
void update(int si,int ss,int se,int qi){
	if(ss==se){
		st[si]=arr[ss];
		return;
	}
	int mid=ss+(se-ss)/2;
	if(qi<=mid) update(2*si,ss,mid,qi);
	else update(2*si+1,mid+1,se,qi);
	st[si]=min(st[2*si],st[2*si+1]);
}
ll mm(ll a,ll b,ll mod){ 
    ll res = 0;
    a %= mod; 
    while(b){
        if (b & 1) res = (res + a) % mod; 
        a = (2 * a) % mod; 
        b >>= 1; // b = b / 2 
    } 
    return res; 
} 

void DFS_ITR(vector<vector<ll>>& adj,ll src,vector<ll>& a,vector<ll>& f,vector<ll>& d,ll day,vector<bool>& visited){
	vector<ll>s;
    s.push_back(src);
    vector<ll>s2;
    visited[src]=true;
    while(s.size()>0){
		ll u=s[s.size()-1];
        s.pop_back();
        for(auto c:adj[u]){
            if(!visited[c]){
                ll eat=min(a[src-1],f[c-1]);
                f[c-1]-=eat;
                if(f[c-1]==0 && d[c]==-1) d[c]=day;
                s.push_back(c);
                s2.push_back(c);
                visited[c]=true;
			}
		}
	}
    for(auto i:s2) visited[i]=false;
}
ll nCr(ll n, ll r){
    return (n*(n-1)*(n-2))/6;
}

void solve(){
	ll n;
	cin>>n;
	ll a[n],sum=0;
	for(ll i=0;i<n;i++) cin>>a[i];
	ll max1=a[0];
	for(ll i=1;i<n;i++){
		if(a[i]<max1) sum+=max1-a[i];
		max1=max(max1,a[i]);
	}
	cout<<sum<<"\n";
}
int main(){
	fast;
	ll t=1;
	//cin>>t;
	while(t--)
		solve();
	return 0;
}



Measured memory_bytes: 5180
k=list(map(int, input().split(' ')))
a=list(map(int, input().split(' ')))
m=a[0]
for i in range(k[1]):
    if i==k[1]-1:
        if k[0]-a[i]+a[0]>m:
            m=k[0]-a[i]+a[0]
    else:
        if a[i+1]-a[i]>m:
            m=a[i+1]-a[i]
print(k[0]-m)

Measured memory_bytes: 25840
using System;
using System.Linq;
using System.Collections.Generic;
public class Hello{
    public static void Main(){
        var input = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        var a = input[0];
        var b = input[1];
        var ans = "";
        if(1 <= b){
            if(1 <= a){
                ans = "Positive";
            }else{
                ans = "Zero";
            }
        }else if(b == 0){
            ans = "Zero";
        }else{
            if((Math.Abs(a - b) + 1)% 2 == 0){
                ans = "Positive";
            }else{
                ans = "Negative";
            }
        }
        Console.WriteLine(ans);
    }
}


Measured memory_bytes: 13268
from itertools import accumulate
import sys
input = sys.stdin.readline
N,C = map(int,input().split())
p = [list(map(int,input().split())) for i in range(N)]
p.sort()
ch = [[0,0] for i in range(C+1)]
p_true = []
for i in range(N):
  [s,t,c] = p[i]
  if ch[c][1] == s:
    ch[c][1] = t
  elif ch[c] == [0,0]:
    ch[c] = [s,t]
  else:
    p_true.append([ch[c][0],ch[c][1],c])
    ch[c] = [s,t]
for i in range(1,C+1):
  if ch[i] != [0,0]:
    p_true.append([ch[i][0],ch[i][1],i])
p_true.sort()
time = [0 for i in range(100002)]
for i in range(len(p_true)):
  [s,t,c] = p_true[i]
  time[s] += 1
  time[t+1] -= 1
print(max(accumulate(time)))

Measured memory_bytes: 36512
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <cstring>
#define rep(i, N) for (int i = 0; i < (int)N; i++)
using namespace std;
typedef long long ll;
const ll LLINF = 9223372036854775807;
const int MOD = 1000000007;

ll gcd(ll x,ll y) {
  if (x < y) swap(x, y);
  if (y == 0) return x;
  else return gcd(x%y, y);
}

ll lcm(ll x, ll y) { return x/gcd(x,y)*y; }

int main() {
  int N; cin >> N;
  ll T[N]; rep(i, N) cin >> T[i];
  ll result = 1;
  rep(i, N) result = lcm(result, T[i]);
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
int A[1];
int size=1;
int m=2;
#define N 101
#define mod 1000000007
#define f(i,n) for(int i=0;i<n;i++)
/*
bool prime(ll n){if(n==1)return false;for(ll i=2;i*i<=n;i++)if(n%i==0){return false;}return true;}
void prime_fact(int n){for(int i=2;i*i<=n;i++){int count=0;if(n%i==0){while(n%i==0)n/=i,count++;cout<<i<<"^"<<count<<" ";}}if(n>1)cout<<n<<"^1";}
ll power(ll base ,ll pow){ll res=1;while(pow>0){if(pow&1)res*=base,pow-=1;else base*=base,pow/=2;}return res;}
void prime_fact_seieve(int n){for(int i=2;i<=size;i++){if(A[i]==0)for(ll j=i;j<=size;j+=i)if(A[i]==0)A[j]=i;}while(n>2){cout<<A[n]<<"*";n/=A[n];}}
template <class X> X gcd(X a , X b) { return b==0?a: gcd( b, a%b); }
template <class X> X lcm(X a , X b) { return a/gcd(a,b) * b ; }
ll Ab[N][N],I[N][N];  // identity matrix and a matrix to store result
void multiply(ll I[][N],ll A[][N],int dim)
{   int res[dim+1][dim+1];
    for(int i=0;i<dim;i++)
    {  for(int j=0;j<dim;j++)
        {
           res[i][j]=0;
           for(int k=0;k<dim;k++)
           {  res[i][j]+=((I[i][k]%mod)*(A[k][j])%mod)%mod;}}}

        for(int i=0;i<dim;i++)
            for(int j=0;j<dim;j++)
                I[i][j]=res[i][j];}
void powerMat(ll A[][N],int dim,int n)
{   for(int i=0;i<dim;i++)
    for(int j=0;j<dim;j++)
    {if(i==j) I[i][j]=1;
     else     I[i][j]=0;}
     while(n>0)
     {
         if(n%2)
         multiply(I,A,dim),n--;
         else
         multiply(A,A,dim),n/=2;
     }
     for(int i=0;i<dim;i++)
         for(int j=0;j<dim;j++)
             A[i][j]=I[i][j];
}
void printMat(ll A[][N],int dim)
{
    for(int i=0;i<dim;i++)
    {for(int j=0;j<dim;j++)
        {
            cout<<A[i][j]<<" ";
        }cout<<"\n";}
}
// REMEMBER PREFIX SUM SUFFIX SUM OR GCD VERY INTERESTING QUESTIONS
ll power(ll base ,ll pow,ll mo){ll res=1;while(pow>0){if(pow&1)res=(res%mo*base%mo)%mo,pow-=1;else base=(base%mo*base%mo)%mo,pow/=2;}return res;}*/

int cnt[100001];
int main()
{  int n;
   cin>>n;
   int temp;
   ll sum=0;
   f(i,n){cin>>temp;sum+=temp;cnt[temp]++;}
   //f(i,100001)if(cnt[i]!=0)arr.push_back(i);
   int a,b,c,q;
   cin>>q;
   while(q--)
   {
       cin>>a>>b;
       c=b-a;
       sum+=cnt[a]*c;
       cnt[b]+=cnt[a];
       cnt[a]=0;
       cout<<sum<<"\n";
   }

}


Measured memory_bytes: 3976
import java.util.Scanner;

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

        int x = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();
        if(Math.abs(x-a) >  Math.abs(x-b)){
            System.out.print("B");
        }else{
            System.out.print("A");
        }
    }
}

Measured memory_bytes: 21844
#include <stdio.h>
int main(void){
    
    int n;
    int a;
    int x=0,y=0,z=0;
    scanf("%d",&n);
    for(;~scanf("%d",&a);){
        if(a%4==0){
            z++;
        }else if(a%2==0){
            y++;
            }else{
            z--;
        }
    }
    puts((y&&z>=0||!y&&z>=-1)?"Yes":"No");
}

Measured memory_bytes: 1620
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
using namespace std;
#define lint long long int
/*
vector<char>al(26);
al = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
vector<char>AL(26);
AL = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
*/

int main() {
	lint N;
	cin >> N;
	lint ans = 1;
	for (int ia = 1; ia <= N; ia++) {
		ans =ans*ia % 1000000007;
	}
	cout << ans << endl;
}



Measured memory_bytes: 256