akhauriyash/Code-Regression huggingface dataset:
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.readline
read = sys.stdin.read
#from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
#import math
#from itertools import combinations
import bisect# lower_bound etc
#import numpy as np
def run():
    N,M = map(int, sysread().split())
    AB = []

    for _ in range(N):
        AB.append(list(map(int, sysread().split())))
    AB = sorted(AB, key = lambda x:x[0])
    A = [a for a, _ in AB]
    B = [0] + [b for _, b in AB] + [0]
    intB = [abs(B[idx] - B[idx - 1]) for idx in range(1, N+2)]
    to = [[] for _ in range(N+1)]
    for i in range(M):
        # to: (code_id, next)
        l, r = map(int, sysread().split())
        l = bisect.bisect_left(A, l)
        r = bisect.bisect_right(A, r)
        if l == r:continue
        to[l].append((i, r))
        to[r].append((i, l))

    seen = [False] * (N+1)

    def dfs(node, to, stack):
        seen[node] = True
        stack.append(node)
        for _, n_node in to[node]:
            if not seen[n_node]:
                dfs(n_node, to, stack)


    trees = []
    for k in range(N+1):
        tmp_stack = []
        if not seen[k]:
            dfs(k, to, tmp_stack)
            trees.append(tmp_stack)
            # tree check
            ret = 0
            for v in tmp_stack:
                ret += intB[v]
            if ret % 2 != 0:
                print(-1)
                return None

    seen2 = [False] * (N+1)
    code_ids = []
    for tree in trees:
        while tree:
            cur = tree.pop()
            seen2[cur] = True
            for id, next in to[cur]:
                if not seen2[next]:
                    if intB[cur] == 1:
                        code_ids.append(id)
                        intB[cur] = 0
                        intB[next] = abs(intB[next] - 1)
                    break
    print(len(code_ids))
    print(' '.join(list(map(str, sorted([h+1 for h in code_ids])))))



if __name__ == "__main__":
    run()

Measured memory_bytes: 156896
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main()
{
    int N,even=0;
    float ans;

    cin >> N;

    for(int i=1;i<=N;i++)
    {
        if(i%2 == 1) even++;
    }

    ans = (float)even/(float)N;

    cout << ans << endl;

}

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

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
typedef long double ld;

const int INF = 1e9;
const ld EPS = 1e-8;

struct state{
  int AC, penalty, team;
};

bool comp(state s1, state s2) {
  if(s1.AC != s2.AC) return s1.AC > s2.AC;
  else if(s1.penalty != s2.penalty) return s1.penalty < s2.penalty;
  else return s1.team < s2.team;
}

int main(){
  int T, P, R;
  while(cin >> T >> P >> R && T) {
    vector<state> a(T);
    REP(i, T) a[i] = (state){0, 0, i + 1};
    vector<vector<int>> flag(T, vector<int> (P, 0));
    REP(r,R) {
      int tID, pID, time;
      string msg;
      cin >> tID >> pID >> time >> msg;
      tID--;
      pID--;
      if(msg == "CORRECT") {
        if(flag[tID][pID] == -1) continue;
        a[tID].AC++;
        a[tID].penalty += flag[tID][pID] * 1200 + time;
        flag[tID][pID] = -1;
      }else if(msg == "WRONG"){
        if(flag[tID][pID] == -1) continue;
        flag[tID][pID]++;
      }
    }
    sort(ALL(a), comp);
    REP(i,T) {
      cout << a[i].team << " " << a[i].AC << " " << a[i].penalty << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 3160
#include<stdio.h>

int linearSearch(int A[],int n,int key){
  int i;
  for(i=0; i<n; i++){
    if(A[i]==key) return i;
  }
  return -1;
     }



   int main(){

     int i,j,n,count=0,N,A[10000],key;


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



     scanf("%d",&N);
     for(j=0; j<N; j++){
       scanf("%d",&key);
       if(linearSearch(A,n,key)!=-1){
         count++;
       }
     }


     /*  for(i=0; i<n; i++){                                                    
       for(j=0; j<N; j++){                                                      
                                                                                
         if(A[i]==B[j]){                                                        
           count++;                                                             
           break;                                                               
       }                                                                        
       }                                                                        
     }                                                                          
     */




     printf("%d\n",count);

     return 0;
   }



Measured memory_bytes: 2108
#include <bits/stdc++.h>
#include <math.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rrep(i, n) for(int i = 0; i <= (n); i++)
using namespace std;
typedef long long ll;
 
const ll INF = 1LL<<62;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// 多次元 vector 生成
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

const int MOD = 1000000007;




int main(){
    ll N, K; cin >> N >> K;
    vector<ll> A(N);
    rep(i,N) cin >> A[i];
    
    for(int i = K; i < N; i++){
        if (A[i] > A[i-K]){
            cout << "Yes" << endl;
        }
        else{
            cout << "No" << endl;
        }
    }
}



Measured memory_bytes: 4844
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {
    public static void main(final String[] args) {
        final Scanner scanner = new Scanner(System.in);
        final long n = scanner.nextLong();

        if (n == 2) {
            System.out.println(1);
            return;
        }

        final long sqrt = (long) Math.sqrt(n);
        final Map<Long, Long> primes = primeFactorization(n - 1);
        long counter = 1; // none
        for (final long value : primes.values()) {
            counter *= value + 1;
        } // 約数の全ての組み合わせ(1含む)
        if (!primes.containsKey(2L)) {
            counter++; // 2 は必ず答えに含まれるので，約数になければ追加
        }
        if (isPrimeNumber(n - 1) && !primes.containsKey(n - 1)) {
            counter++;
        }

        for (long i = 3; i <= sqrt; i++) {
            if (n % i != 0) {
                continue;
            }

            long tmp = n / i;
            while (tmp % i == 0) {
                tmp /= i;
            }
            if (tmp % i == 1) {
                counter++;
            }
        }

        System.out.println(counter);
    }

    private static Map<Long, Long> primeFactorization(long n) {
        final double sqrt = Math.sqrt(n);
        final Map<Long, Long> countMap = new HashMap<>();
        for (long i = 2; i <= sqrt; i++) {
            if (n % i == 0) {
                countMap.compute(i, (k, v) -> v = v == null ? 1 : v + 1);
                n /= i;
                i--;
            }
        }

        if (n != 1) {
            countMap.compute(n, (k, v) -> v = v == null ? 1 : v + 1);
        }

        return countMap;
    }

    private static boolean isPrimeNumber(final long n) {
        for (int i = 2; i <= Math.sqrt(n); i++) {
            if (n % i == 0) {
                return false;
            }
        }
        return true;
    }
}


Measured memory_bytes: 29140
import random

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

a, b = map(int, input().split())

a_divs = make_divisors(a)
b_divs = make_divisors(b)

a_b_divs = list(set(a_divs) & set(b_divs))
a_b_divs.sort()

# 素数判定
# https://pashango-p.hatenadiary.org/entry/20090704/1246692091
# ミラー・ラビン(Miller-Rabin)テスト
def is_prime3(q,k=50):
    q = abs(q)
    #計算するまでもなく判定できるものははじく
    if q == 2: return True
    if q < 2 or q&1 == 0: return False

    #n-1=2^s*dとし（但しaは整数、dは奇数)、dを求める
    d = (q-1)>>1
    while d&1 == 0:
        d >>= 1
    
    #判定をk回繰り返す
    for i in range(k):
        a = random.randint(1,q-1)
        t = d
        y = pow(a,t,q)
        #[0,s-1]の範囲すべてをチェック
        while t != q-1 and y != 1 and y != q-1: 
            y = pow(y,2,q)
            t <<= 1
        if y != q-1 and t&1 == 0:
            return False
    return True
# 1を含むため
ans = 1
for j in a_b_divs:
    if is_prime3(j) == True:
        #print(j)
        ans += 1

print(ans)


Measured memory_bytes: 5548
#include <bits/stdc++.h>
using namespace std;
#define M_PI 3.14159265358979323846
#define MOD 1000000007
typedef long long ll;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<int, int> ipair;
typedef pair<ll, ll> llpair;

int n, h[100001];

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL), cout.tie(NULL);
    cin>>n;
    for(int i=0; i<n; i++) cin>>h[i];
    int dp[n];
    dp[0] = 0;
    dp[1] = abs(h[1] - h[0]);
    for(int i=2; i<n; i++){
        dp[i] = min(dp[i-2]+abs(h[i]-h[i-2]), dp[i-1]+abs(h[i]-h[i-1]));
    }
    cout<<dp[n-1]<<"\n";
	return 0;
}

Measured memory_bytes: 4408
n=gets.to_i
a=gets.split.map{|i|(i=i.to_i)%2>0?0:i%4>0?1:2}
a,b,c=(0..2).map{|i|a.count i}
puts (a>c&&(a+c<n||a-1>c))?:No:"Yes"

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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))
#define sz(v) ((int) v.size())

using namespace std;

using i64 = long long;
using f80 = long double;
using vi32 = vector<int>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

void yes() { cout << "Yes" << endl; exit(0); }
void no() { cout << "No" << endl; exit(0); }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> void amax(T &x, T y) { x = max(x, y); }
template <typename T> void amin(T &x, T y) { x = min(x, y); }
template <typename T> T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { for (auto &x : v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }

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

void solve() {
  int n;
  i64 x, d;
  cin >> n >> x >> d;
  if (d == 0) {
    if (x == 0) {
      cout << 1 << endl;
    } else {
      cout << n + 1 << endl;
    }
    return;
  }
  if (d < 0) {
    x *= -1;
    d *= -1;
  }
  using P = pair<i64, i64>;
  map<int, vector<P>> mp;
  repc(i, n) {
    i64 I = i;
    i64 head = I * x + I * (I - 1) / 2 * d;
    i64 tail = I * x + (I * n - I * (I + 1) / 2) * d;
    i64 mod = head % d;
    if (mod < 0) mod += d;
    if (head > tail) swap(head, tail);
    mp[mod].emplace_back(head, tail);
  }
  for (auto& m : mp) {
    sort(m.second.begin(), m.second.end(), [](P a, P b) {
      if (a.first != b.first) return a.first < b.first;
      return a.second < b.second;
    });
  }
  i64 ans = 0;
  for (auto& m : mp) {
    i64 head, tail;
    tie(head, tail) = m.second[0];
    reps(i, sz(m.second) - 1) {
      if (tail >= m.second[i].first) {
        tail = max(tail, m.second[i].second);
      } else {
        ans += (tail - head) / d + 1;
        head = m.second[i].first;
        tail = m.second[i].second;
      }
    }
    ans += (tail - head) / d + 1;
  }
  cout << ans << endl;
}


Measured memory_bytes: 22144
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>
/*#pragma GCC optimize("Ofast","unroll-loops","omit-frame-pointer","inline") //Optimization flags
#pragma GCC option("arch=native","tune=native","no-zero-upper") //Enable AVX
#pragma GCC target("avx2")  //Enable AVX*/

using namespace std;

using ll = long long;

#define mp make_pair

const int p = 1e9 + 7;


int mul(int a, int b) {
    return (1LL * a * b) % p;
}

int add(int a, int b) {
    int s = (a+b);
    if (s>=p) s-=p;
    return s;
}

int sub(int a, int b) {
    int s = (a+p-b);
    if (s>=p) s-=p;
    return s;
}

int po(int a, int deg)
{
    if (deg==0) return 1;
    if (deg%2==1) return mul(a, po(a, deg-1));
    int t = po(a, deg/2);
    return mul(t, t);
}

int inv(int n)
{
    return po(n, p-2);
}

/*struct DSU {
    vector<int> sz;
    vector<int> parent;

    void make_set(int v) {
        parent[v] = v;
        sz[v] = 1;
    }

    int find_set(int v) {
        if (v == parent[v])
            return v;
        return parent[v] = find_set(parent[v]);
    }

    void union_sets(int a, int b) {
        a = find_set(a);
        b = find_set(b);
        if (a != b) {
            if (sz[a] < sz[b])
                swap(a, b);
            parent[b] = a;
            sz[a] += sz[b];
        }
    }

    DSU(int n) {
        sz.resize(n);
        parent.resize(n);
        for (int i = 0; i < n; i++) make_set(i);
    }
};*/

/*const int N = 1000000;

vector<int> facs(N), invfacs(N);

void init()
{
    facs[0] = 1;
    for (int i = 1; i<N; i++) facs[i] = mul(facs[i-1], i);
    invfacs[N-1] = inv(facs[N-1]);
    for (int i = N-2; i>=0; i--) invfacs[i] = mul(invfacs[i+1], i+1);
}

int C(int n, int k)
{
    return mul(facs[n], mul(invfacs[k], invfacs[n-k]));
}*/



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

    int n;
    cin>>n;
    int ans = 0;
    if (n%10 == 0) ans = 9;
    while (n)
    {
        ans+=(n%10);
        n/=10;
    }
    cout<<ans;


}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (ll(i) = 0; (i) < (n); (i)++)
#define all(x) (x).begin(), (x).end()
#define print(x) cout << (x) << endl;

typedef long long ll;
const ll INF = 99999999999999;
const ll MOD = 1000000007;

ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
ll lcm(ll number1, ll number2)
{
    return number1 * number2 / gcd(number1, number2);
}
template <class T>
bool contain(const std::string &s, const T &v)
{
    // contain(to_string(N), '3')
    return s.find(v) != std::string::npos;
}

int ctoi(char c)
{
    if (c >= '0' && c <= '9')
        return c - '0';
    return 0;
}

using namespace std;

ll d(ll a)
{
    ll ret = 0;
    while (a > 0)
    {
        a /= 10;
        ret++;
    }
    return ret;
}

// C++ゆるさねえリスト
// accumulate(all(a), 0LL);
// 二分探索

int main()
{
    int x, n, amari, ans = 0;
    cin >> x;
    n = floor(x / 100);
    amari = x % 100;
    if (n * 5 >= amari)
    {
        ans = 1;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<map>
#include<utility>
#include<functional>
#include<stack>
#include<queue>
#include<cmath>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
using namespace std;
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }

int main() {
	int n = 0;
	int c[500] = {}, s[500] = {}, f[500] = {};
	int ans = 0; 
	double tmp = 0;

	cin >> n;
	rep(i, n - 1) {
		cin >> c[i] >> s[i] >> f[i];
	}

	rep(i,n) {

		ans = 0;

		for (int j = i; j < n - 1; j++) {

				if (ans < s[j]) {
					ans = s[j];
				}
				else if ((ans - s[j]) % f[j] != 0) {
					tmp = (ans - s[j]) / f[j];
					ans = (tmp + 1) * f[j] + s[j];
					
				}
			
			ans += c[j];

		}

		cout << ans << endl;
	}

	return 0;

}

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

long long modexp(int x, long long e, int m) {
    long long ans = 1, p = x % m;
    while (e > 0) {
        if (e % 2 != 0) ans = (ans * p) % m;
        p = (p * p) % m;
        e >>= 1;
    }
    return ans;
}

class ModComb {
    long long *fact, *facti;
    const int mod;
public:
    explicit ModComb(int n, int m) : mod(m) {
        fact = new long long[n+1];
        facti = new long long[n+1];
        fact[0] = 1; facti[0] = 1;
        for (int i = 1; i <= n; i++) fact[i] = (fact[i-1] * i) % m;
        // calc 1/n!
        long long &inv = facti[n], pw = fact[n];
        inv = 1;
        for (int e = mod-2; e > 0; e /= 2) {
            if (e&1) inv = inv * pw % mod;
            pw = pw * pw % mod;
        }
        for (int i = n-1; i > 0; i--) facti[i] = (facti[i+1] * (i+1)) % m;
    }

    ~ModComb() {
        if (fact) delete[] fact;
        if (facti) delete[] facti;
    }

    long long getFact(int n) const {
        return n < 0 ? 0 : fact[n];
    }

    long long getFactInv(int n) const {
        return n < 0 ? 0 : facti[n];
    }

    long long getComb(int n, int k) const {
        if (n < 0 || k < 0 || k > n) return 0;
        return fact[n] * facti[k] % mod * facti[n-k] % mod;
    }

    long long getPerm(int n, int k) const {
        if (n < 0 || k < 0 || k > n) return 0;
        return fact[n] * facti[n-k] % mod;
    }
};


int main() {
    int n, m; cin >> n >> m;
    bitset<300> a[n];
    for (int i = 0; i < n; i++)
        for (int j = 0; j < m; j++) {
            int x; cin >> x;
            if (x == 1) a[i][j] = true;
        }

    // int expect = 0;
    // for (int s = 0; s < 1<<n; s++)
    //     for (int t = 0; t < 1<<m; t++) {
    //         int sum = 0;
    //         for (int i = 0; i < n; i++)
    //             for (int j = 0; j < m; j++)
    //                 if (((s >> i) & 1) && ((t >> j) & 1) && a[i][j])
    //                     sum++;
    //         if (sum % 2) expect++;
    //     }

    int r = 0;
    for (int j = 0; j < m; j++) {
        for (int i = r; i < n; i++)
            if (a[i][j]) {
                for (int ii = i+1; ii < n; ii++)
                    if (a[ii][j]) a[ii] ^= a[i];
                swap(a[i], a[r]);
                r++;
                break;
            }
    }

    long long ans = 0;
    const int M = 998244353;
    ModComb mc(300, M);
    for (int k = 1; k <= r; k += 2)
        ans += mc.getComb(r, k) * modexp(3, r-k, M) % M;
    ans = ans % M * modexp(2, (n - r) + (m - r), M) % M;
    cout << ans << endl;

    // if (ans == expect) cerr << "OK\n";
    // else cerr << "WA; expect " << expect << ", got " << ans << endl;
}


Measured memory_bytes: 3156
s = input()

if s == "SUN":
    print("7")
elif s == "MON":
    print("6")
elif s == "TUE":
    print("5")
elif s == "WED":
    print("4")
elif s == "THU":
    print("3")
elif s == "FRI":
    print("2")
elif s == "SAT":
    print("1")

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
 
int main () {
  long long k,n;
  cin >>k>>n;
  vector<long long>a(n);

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

  long long staymax;
  staymax =k-a[n-1]+a[0];

  for(int i=1;i<n;i++){
    if(staymax <a[i]-a[i-1]){
      staymax =a[i]-a[i-1];
    }
  }
  cout <<k-staymax<<endl;
return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#define int         int64_t
#define ii          pair<int,int>
#define dd          pair<double,double>
#define vi          vector<int>
#define pb          push_back
#define all(x)      (x).begin(), (x).end()
#define checkBit(v, p)      (v&(1LL << p))
#define loop(i,a,b) for(int i = a;i < int(b);i++)
#define x           first
#define y           second
using namespace std;

int inf = 2e9, mod = 1e9 + 7;

int32_t main()
{
    ios_base::sync_with_stdio(false); cout << fixed <<setprecision(0);
    string s; cin >> s;
    char prev = ' ';
    int sum = 0;
    int i=0;
    for(;i<s.size();i++){
        sum++;
        if(s[i] != prev){
            prev = s[i];
            continue;
        }
        prev = ' ';
        i++;
    }
    if(i == s.size()+1) --sum;
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 720
# encoding: utf-8
N, M = map(int, input().split())
S = input()
T = input()

def gcd(a, b):
    if b == 0: return a
    elif a < b: return gcd(b, a)
    else: return gcd(b, a % b)

tmpans = N * M // gcd(N, M)
S_intv = tmpans // N
T_intv = tmpans // M

for sidx, si in enumerate(S):
    # skip
    idx = sidx * S_intv
    if idx % T_intv > 0: continue
    # else
    tidx = idx // T_intv
    if si != T[tidx]:
        ans = -1
        break
else:
    ans = tmpans

print(ans)

Measured memory_bytes: 3316
#pragma target("avx")
#pragma optimize("O3")
#include<bits/stdc++.h>
using ll = int_fast64_t;
using P = std::pair<ll,ll>;
using PP = std::pair<ll,P>;
using V = std::vector<ll>;
template<typename T> using pq = std::priority_queue<T>;
template<typename T> using rpq = std::priority_queue<T, std::vector<T>, std::greater<T>>;

#define REP(i,b,e) for(ll i=b; i<e; i++)
#define ALL(vec) vec.begin(),vec.end()
#define PRINT(vec) printf("[ ");for(auto &i:vec)printf("%ld ",i);puts("]");
#define SCAN(vec) for(auto &i:vec)scanf("%ld",&i)
#define fi first
#define se second

const int MOD = 1e9+7;
const ll INF = 1e18;
int dx[] = {0, 1, 0, -1, 1, 1, -1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

int main(){
	ll x, y;
	scanf("%ld %ld", &x, &y);

	ll ans = 1e18;
	if(x<=y) ans = std::min(ans, y-x);
	else ans = std::min(ans,(ll)(2l+x-y));
	ans = std::min(ans, (ll)(1ll+llabs(x+y)));
	printf("%ld\n", ans);
	return 0;
}



Measured memory_bytes: 256
import java.util.*;
import java.io.*;

class Main{
    public static void main(String[] args){
        FastScanner fsc=new FastScanner();
        int n=fsc.nextInt();
        int a=fsc.nextInt();
        fsc.close();
        System.out.println((n*n-a));
    }
    static class FastScanner {
        private final InputStream in = System.in;
        private final byte[] buffer = new byte[1024];
        private int ptr = 0;
        private int buflen = 0;
        private boolean hasNextByte(){
            if(ptr<buflen) return true;
            else{
                ptr = 0;
                try{
                    buflen = in.read(buffer);
                }
                catch(IOException e){
                    e.printStackTrace();
                }
                if(buflen<=0) return false;
            }
        return true;
        }
        private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
        private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
        public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
        public String next() {
            if (!hasNext()) throw new NoSuchElementException();
            StringBuilder sb = new StringBuilder();
            int b = readByte();
            while(isPrintableChar(b)) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }
        public long nextLong() {
            if (!hasNext()) throw new NoSuchElementException();
            long n = 0;
            boolean minus = false;
            int b = readByte();
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            if (b < '0' || '9' < b) throw new NumberFormatException();
            while(true){
                if ('0' <= b && b <= '9') {
                    n *= 10;
                    n += b - '0';
                }
                else if(b == -1 || !isPrintableChar(b)) return minus ? -n : n;
                else throw new NumberFormatException();
                b = readByte();
            }
        }
        public int nextInt() {
            long nl = nextLong();
            if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
            return (int) nl;
        }
        public double nextDouble() { return Double.parseDouble(next());}
        public void close(){
            try{in.close();}
            catch(IOException e){e.printStackTrace();}
        }
    }
}


Measured memory_bytes: 22484
#include <algorithm>
#include <bits/stdc++.h>
#include <bitset>
#include <cassert>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <vector>
using namespace std;
#define REP(i, n) for (int64_t i = 0; i < (int64_t)n; i++)
#define REP_FOR(i, a, b) for (int64_t i = (int64_t)a; i < (int64_t)b; i++)
#define REP_REV(i, a, b) for (int64_t i = (int64_t)a; i > (int64_t)b; i--)
#define FORALL(v) (v).begin(), (v).end()
#define mp(a, b) make_pair(a, b)
#define eb(x) emplace_back(x)
#define F first
#define S second
typedef long long ll;
typedef long double ld;
typedef pair<int64_t, int64_t> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<int64_t> vii;
typedef vector<vii> vvii;
const ll mod = 1e9 + 7;
const int64_t infi = 1147483600;
const ll infl = 4e18 + 5;
const char EOL = '\n';
//cout << fixed << setprecision(17) << res << endl;
const ll MOD = 998244353;
 
int main() {
    string c;
    cin >> c;
    c[0] = c[0]+1;
    cout << c << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<string>
#include<stack>
#include<cstdio>
#include<cmath>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<ll,P> P1;

#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define rep(i,x) for(int i=0;i<x;i++)
#define rep1(i,x) for(int i=1;i<=x;i++)
#define rrep(i,x) for(int i=x-1;i>=0;i--)
#define rrep1(i,x) for(int i=x;i>0;i--)
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
#define mp1(a,b,c) P1(a,P(b,c))

const ll M = 1000000007;

struct mat{
	ll a[2][2];
};

mat times(mat x,mat y){
	mat ret;
	rep(i,2)rep(j,2)ret.a[i][j] = x.a[i][0]*y.a[0][j] + x.a[i][1]*y.a[1][j];
	rep(i,2)rep(j,2)ret.a[i][j] %= M;
	return ret;
}

mat I;
void init(){
	rep(i,2)rep(j,2)I.a[i][j] = (i==j)?1:0;
}
mat power(mat x,ll k){
	if(k == 0)return I;
	mat ret = power(x,k/2);
	ret = times(ret,ret);
	if(k%2 == 1)ret = times(ret,x);
	return ret;
}

ll f(ll k){
	mat A;
	rep(i,2)rep(j,2)A.a[i][j] = 1;
	A.a[0][0] = 0;
	return power(A,k+1).a[1][0];
}

ll g(ll n){
	if(n%2 == 0)return n*n/4;
	else return (n*n-1)/4;
}

int main(){
	init();
	ll k;
	cin >> k;
	ll l = 1 , r = 2*M;
	while(l < r){
		ll m = (l+r+1)/2;
		if(g(m) < k)l = m;
		else r = m-1;
	}
	
	ll s = k-g(l);
	s = 2*s-1;
	ll x = (l+1)/2;
	if(s > x)s = 2*x+1-s;
	cout << (f(s)*f(l+1-s))%M << endl;
}
	

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
int main(){
    int a[3][3];
    for(int i=0;i<3;i++){
        for(int j=0;j<3;j++){
            cin>>a[i][j];
        }
    }
    int n; cin>>n;
    for(int i=0;i<n;i++){
        int tmp; cin>>tmp;
        for(int j=0;j<3;j++){
            for(int k=0;k<3;k++){
                if(a[j][k]==tmp){
                    a[j][k]=0;
                }
            }
        }
    }
    bool b[4]={false,false,false,false};
    for(int i=0;i<3;i++){
        int c=0;
        for(int j=0;j<3;j++){
            if(a[i][j]!=0){
                c++;
            }
        }
        if(c==0){
                b[0]=true;
        }
    }
        for(int i=0;i<3;i++){
        int c=0;
        for(int j=0;j<3;j++){
            if(a[j][i]!=0){
                c++;
            }
            
        }
        if(c==0){
                b[1]=true;
        }
    }
    if(a[0][0]==0&&a[1][1]==0&&a[2][2]==0){
        b[2]=true;
    }
    if(a[0][2]==0&&a[1][1]==0&&a[2][0]==0){
        b[3]=true;
    }
    for(int i=0;i<4;i++){
        if(b[i]==true){
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
}

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

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

template<typename T>
T mod(T a, T b){
    return (a + b) % b;
}

template<typename T>
T gcd(T a, T b){
    if (b == 0) return a;
    return gcd(b, a % b);
}

ll lcm(ll a, ll b){
    return a * b / gcd(a,b);
}

// n を素因数分解
map<ll, ll> factor(ll n){
    map<ll, ll> mp;
    for (ll i = 2; i*i <= n; i++) {
        while (n % i == 0) {
            mp[i]++;
            n /= i;
        }
    }

    if (n > 1) {
        mp[n]++;
    }

    return mp;
}

// 文字列に "hoge" が含まれているか
// string str = "hogepiyo";
// if (str.find("hoge") != string::npos) {
//     cout << "文字列が含まれています" << endl;
// }

// char to string
// char c = 'a';
// string str = {c};

char cn(char c, int n) {
    if (c+n <= 'Z') {
        return c+n;
    } else {
        return c+n - 'Z' + 'A' - 1;
    }
}

void solve(){
    int N;
    cin >> N;
    string s;
    cin >> s;

    for (int i = 0; i < s.size(); i++) {
        cout << cn(s[i], N);
    }
    cout << endl;

    return;
}

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


Measured memory_bytes: 256
#include<stdio.h>
void reverseprint(int N, int a[]){
    printf("%d", a[N - 1]);
    int i;
    for (i = N - 2; i >= 0; i--){
        printf(" %d", a[i]);
    }
    printf("\n");
}
void scansequence(int N, int a[]){
    int i;
    for (i = 0; i < N; i++)
    {
        scanf("%d", &a[i]);
    }
}
int main(void){
    int N;
    int a[100];
    scanf("%d", &N);
    scansequence(N, a);
    reverseprint(N, a);
    return 0;
}


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

ll K;
vector<ll> a;
int main() {
  cin >> K;

  ll N = 50;
  a.resize(N, 0);
  for (ll i = 0; i < N; ++i) {
    a[i] = i + K / N + (i < K % N ? N - (K % N - 1) : -(K % N));
  }

  cout << N << endl;
  rep(i, N) {
    if (i != 0) cout << " ";
    cout << a[i];
  }
  cout << endl;
  return 0;
}


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

// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] lreads(T = long)(long n){return generate(()=>readln.chomp.to!T()).take(n).array();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);
// dfmt on

void main()
{
    auto S = sread();
    foreach_reverse (i; 1 .. S.length - 1)
    {
        if (i % 2 == 0 && S[0 .. i / 2] == S[i / 2 .. i])
        {
            writeln(i);
            return;
        }
    }
}


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

typedef long long ll;
typedef unsigned long long ull;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for(int i=(b-1);i>=(a);--i)
#define REP(i,n)   FOR(i,0,n)
#define RREP(i,n)   RFOR(i,0,n)
#define SORT(s) sort(s.begin(), s.end())
#define P pair<int, int>
#define mp make_pair

const double INF = 1e+09;
const int MOD = 1e9+7;

using namespace std;

template <typename _Ty>
ostream& operator << (ostream& ostr, const vector<_Ty>& v) {if (v.empty()) {ostr << "{ }"; return ostr;}
    ostr << "{" << v.front(); for (auto itr = ++v.begin(); itr != v.end(); itr++) {ostr << ", " << *itr;}
    ostr << "}";
    return ostr;}

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

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

int lcm(int a, int b)
{return a * b / gcd(a, b);}

vector<int> uniq(vector<int> vec){
  sort(vec.begin(), vec.end());
  vec.erase(unique(vec.begin(), vec.end()), vec.end());
  return vec;}

vector<ll> divisor(ll n) {
vector<ll> ret;
for(int64_t i = 1; i * i <= n; i++) {
  if(n % i == 0) {
    ret.push_back(i);
    if(i * i != n) ret.push_back(n / i);
  }
}
  sort(begin(ret), end(ret));
  return (ret);
}
void permu(int n){
  vector<int> perm(n);
  REP(i, n) perm[i] = i;
do{
  cout << perm  << endl;
}
while (next_permutation(perm.begin(), perm.end()));
return;}

vector<pair<ll, int>> prime_div(ll n){
  vector<pair<ll, int>> res;
  for (ll i=2; i*i <= n;i++){
    if (n%i == 0){
      int a = 0;
      while(n%i == 0){
        n /= i;
        a++;
      }
      pair<ll, int> tmp;
      tmp.first = i;
      tmp.second = a;
      res.push_back(tmp);
    }
  }
  if (n != 1){
    pair<ll, int> now;
    now.first = n;
    now.second = 1;
    res.push_back(now);}
  return res;
}


// printf("%.10f\n" , ans);
int main(void){
  ios::sync_with_stdio(false);
  int n ;
  cin >> n;
  vector<int> a(n);
  REP(i, n) cin >> a[i];
  sort(a.begin(), a.end());
  vector<int> vals(a[n-1] + 10, 0);
  REP(i, n){
    int now = a[i];
    if (vals[now] != 0) vals[now]++;
    for (int j=now; j<=a[n-1]; j+=now){
      vals[j] += 1;
    }
  }
  ll ans = 0;
  REP(i, n){
    if (vals[a[i]] == 1) ans++;
  }

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



Measured memory_bytes: 8020
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(ll i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  ll n, m;
  cin >> n;
  map<ll, ll> mp;
  rep(i, n) {
    ll d;
    cin >> d;
    mp[d]++;
  }
  cin >> m;
  bool ok = true;
  rep(i, m) {
    ll t;
    cin >> t;
    if(mp[t] <= 0) ok = false;
    mp[t]--;
  }
  cout << (ok ? "YES" : "NO") << endl;
}

Measured memory_bytes: 16108
#include <bits/stdc++.h>
#define MAX(a,b) (((a)>(b))?(a):(b))
using namespace std;

int main(){
    int n, i, j;
    cin >> n;
    int x[n], y[n];
    for(i = 0; i < n; i++){
        cin >> x[i] >> y[i];
    }
    if(n == 1){
        cout << 1 << endl;
        return 0;
    }
    map<pair<int, int>, int> m;
    int c_max = 1;
    for(i = 0; i < n; i++){
        for(j = 0; j < n; j++){
            if(i == j) continue;
            int p = x[i] - x[j];
            int q = y[i] - y[j];
            pair<int, int> pq(p, q);
            if(m.count(pq) == 0){
                m[pq] = 1;
            }
            else{
                m[pq]++;
                c_max = MAX(c_max, m[pq]);
            }
        }
    }
    cout << n - c_max << endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
int n,x,ans=0;
int a[1001];
int main() {
    scanf("%d%d",&n,&x);
    for (int i=1;i<=n;i++) scanf("%d",&a[i]);
    sort(a+1,a+n+1);
    for (int i=1;i<n;i++)
        if (x>=a[i]) {
            ans++;
            x-=a[i];
        }
    if (x==a[n]) ans++;
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<map>
#include<vector>
#include<string>
#include <cmath>

using namespace std;

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



Measured memory_bytes: 504
# -*- coding: utf-8 -*-

[A, B, C] = [int(i) for i in input().split()]

if A == B and B == C:
    print('No')
elif A == B:
    print('Yes')
elif A == C:
    print('Yes')
elif B == C:
    print('Yes')
else:
    print('No')

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

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

  if (s.find("BW") == s.npos) {
    cout << 0 << endl;
    return 0;
  }

  int start = s.find("B");
  int64_t ans = 0;
  int left = start;
  for (uint i = start; i < s.length(); i++) {
    if (s[i] == 'W') {
      ans += (i - left);
      left++;
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3708
#include <iostream>
using namespace std;
int main(void){
int K, A, B;
cin >> K >> A >> B;
if(!(A % K) || !(B % K) || (A / K < B / K)){
  cout << "OK" << endl;
} else {
  cout << "NG" << endl;
}
return 0;
}

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

#define pb push_back
#define mp make_pair
#define fi first
#define se second

using namespace std;

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

bool chkmax(int &x,int y){return x<y?x=y,true:false;}
bool chkmin(int &x,int y){return x>y?x=y,true:false;}

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

int n;
int a[200005],mina[600000];

void build(int id,int l,int r){
	if(l==r) return (void)(mina[id]=a[l]);
	int mid=(l+r)/2;
	build(id<<1,l,mid);
	build(id<<1|1,mid+1,r);
	mina[id]=min(mina[id<<1],mina[id<<1|1]);
}

int getr(int id,int l,int r,int x,int c){
	if(l==r) return c<=mina[id]?r+1:r;
	int mid=(l+r)/2;
	if(x>mid-1) return getr(id<<1|1,mid+1,r,x,c);
	else{
		if(mina[id<<1]<c){
			int tmp=getr(id<<1,l,mid,x,c);
			if(tmp==mid+1) return getr(id<<1|1,mid+1,r,mid,c);
			else return tmp;
		}
		else return getr(id<<1|1,mid+1,r,mid,c);
	}
}

int getl(int id,int l,int r,int x,int c){
	if(l==r) return c<=mina[id]?l-1:l;
	int mid=(l+r)/2;
	if(x<=mid+1) return getl(id<<1,l,mid,x,c);
	else{
		if(mina[id<<1|1]<c){
			int tmp=getl(id<<1|1,mid+1,r,x,c);
			if(tmp==mid) return getl(id<<1,l,mid,mid+1,c);
			else return tmp;
		}
		else return getl(id<<1,l,mid,mid+1,c);
	}
}

int main(){
	n=readint();
	for(int i=1;i<=n;i++) a[i]=readint();
	build(1,1,n);
	ll ans=0;
	for(int i=1;i<=n;i++){
		ll lf=getl(1,1,n,i,a[i]),rg=getr(1,1,n,i,a[i]);
//		cout<<"test "<<i<<' '<<lf<<' '<<rg<<endl;
		ans+=a[i]*(rg-i)*(i-lf);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3072
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Scanner;

public class Main 
{
	static class Node
	{
		int i;
		boolean vis = false;
		HashSet<Node> e = new HashSet<>();
		int depth = 0;
		
		public Node(int id)
		{
			i=id;
		}
	}

	static Node[] nd;
	public static void main(String[] args) 
	{
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		
		nd = new Node[n];
		
		for(int i = 0; i < n; i++)
			nd[i] = new Node(i);

		for(int i = 0; i < n-1; i++)
		{
			int a = sc.nextInt()-1;
			int b = sc.nextInt()-1;
			
			nd[a].e.add(nd[b]);
			nd[b].e.add(nd[a]);
		}
		long an = 1;
		long MOD = 1000000007;
		//0 serves as the root
		//cover the impossible case too
		
		LinkedList<Node> q = new LinkedList<Node>();
		q.add(nd[0]);
		nd[0].vis=true;
		
		an = k;
		
//		System.out.println("Starting an " + an);
		while(!q.isEmpty())
		{
			Node pos = q.poll();
			
			int children = 0;
			for(Node e : pos.e)
				if(!e.vis)
				{
					children++;
				}
			
			for(Node e : pos.e)
				if(!e.vis)
				{
					e.vis = true;
					e.depth = pos.depth+1;
					q.add(e);
				}
			
			if(children > 0)
			{
				int biggestsubt = children;
				if(pos.depth > 0)biggestsubt++;
				
				for(int i = 0; i < children; i++)
				{
					an = (an * (k-(biggestsubt-i)))%MOD;
				}
			}
		}
		an = an%MOD;
		System.out.println(an);
		
	}

}


Measured memory_bytes: 117984
s = list(input())
a = int(''.join(s[0:2]))
b = int(''.join(s[2:4]))

a_month = False
b_month = False

if(a > 0) and (a <= 12):
    a_month = True

if(b > 0) and (b <= 12):
    b_month = True
    
if (a_month == False) and (b_month == False):
    print('NA')
    
elif (a_month == True) and (b_month == True):
    print('AMBIGUOUS')
    
elif (a_month == True):
    print('MMYY')
    
else:
    print('YYMM')
    
    

Measured memory_bytes: 3064
#include "bits/stdc++.h"
using namespace std;

typedef long long ll;

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

    ll n,s;cin>>n>>s;
    if(n==s){
        cout<<n+1<<endl;
        return 0;
    }
    for(ll b=2;b*b<=n;b++){
        ll stmp=n,sum=0;
        while(stmp){
            sum += stmp % b;
            stmp /= b;
        }
        if(sum==s){
            cout<<b<<endl;
            return 0;
        }
    }
    ll res=1e12;
    for(ll p=1;p*p<n;p++){
        ll tmp=n-s+p;
        if(tmp%p==0 && tmp>0){
            ll btmp=tmp/p;
            ll stmp=n,sum=0;
            while(stmp){
                sum += stmp % btmp;
                stmp /= btmp;
            }
            if(sum==s){
                res=min(res,btmp);
            }
        }
    }
    if(res<1e12) cout<<res<<endl;
    else cout<<-1<<endl;
}


Measured memory_bytes: 256
package main

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

func main() {
	n := readI()
	a := readIs(n)

	least := a[0]
	ans := 0
	for i := 0; i < n; i++ {
		if least > a[i] {
			ans += least - a[i]
		} else {
			least = a[i]
		}
	}
	fmt.Println(ans)
}

/*-----------Utils-----------*/

var sc = bufio.NewScanner(os.Stdin)

func init() {
	if len(os.Args) >= 2 {
		if os.Args[1] == "debug" {
			debug()
		}
	}
	const maxBuf = 200100
	var buf []byte = make([]byte, maxBuf)
	sc.Split(bufio.ScanWords)
	sc.Buffer(buf, maxBuf)
}

func debug() {
	testFile, err := os.Open("./test/sample-1.in")
	if err != nil {
		fmt.Fprintln(os.Stderr, "Error : There is no testfile.")
		os.Exit(1)
	}
	sc = bufio.NewScanner(testFile)
}

func readS() string {
	sc.Scan()
	return sc.Text()
}

func readSs(a int) []string {
	b := make([]string, a)
	for i := 0; i < a; i++ {
		b[i] = readS()
	}
	return b
}

func readI() int {
	sc.Scan()
	r, _ := strconv.Atoi(sc.Text())
	return r
}

func readIs(a int) []int {
	b := make([]int, a)
	for i := 0; i < a; i++ {
		b[i] = readI()
	}
	return b
}

func readF() float64 {
	sc.Scan()
	r, _ := strconv.ParseFloat(sc.Text(), 64)
	return r
}

func readFs(a int) []float64 {
	b := make([]float64, a)
	for i := 0; i < a; i++ {
		b[i] = readF()
	}
	return b
}


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

int main() {

  int a, b;

  cin >> a >> b;
  
  int x = a+b;

  if(x%2==1){
  	cout << x/2+1 << endl;
  }else{
    cout << x/2 << endl;
  }
}


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

int main() {

    int a,b;
    cin>>a>>b;

    if(a+b==15){
        cout<<"+"<<endl;

    }else if(a*b==15){
        cout<<"*"<<endl;

    }else{
        cout<<"x"<<endl;



    }

    return 0;
}


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

int main() {
	long long a, b, k;
	cin >> a >> b >> k;
	vector<long long> ans;
	for(int i = a; i < a + k; i++){
		ans.push_back(i);
	}
	for(int i = b - k + 1; i <= b; i++){
		ans.push_back(i);
	}
	sort(ans.begin(), ans.end());
	map<long long , int> m;
	for(int i = 0; i < ans.size(); i++){
		if(m[ans[i]] == 0 && ans[i] >= a && ans[i] <= b){
		cout << ans[i] << endl;
		m[ans[i]]++;
		}
	}
	return 0;
}

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

int memo[1010][1010];

int dp(int c, int a){
    int ans = 0;

    if(memo[c][a] != -1){
        return memo[c][a];
    }

    if(c >= 3){
        ans = max(ans, dp(c-3, a)+1);
    }

    if(c >= 2 && a >= 1){
        ans = max(ans, dp(c-2, a-1)+1);
    }

    return memo[c][a] = ans;
}

int main(){
    int q;
    cin >> q;
    memset(memo, -1, sizeof(memo));

    int c, a, r;
    for(int p = 0;p < q;p++){
        cin >> c >> a >> r;

        int tmp = min(c, min(a, r));

        cout << tmp + dp(c-tmp, a-tmp) << endl;
    }

    return 0;
}



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

#define uint unsigned int
#define ll long long
#define ull unsigned long long
#define ld long double
#define rep(i, l, r) for (int i = l; i < r; i++)
#define repb(i, r, l) for (int i = r; i > l; i--)
#define sz(a) (int)a.size()
#define fi first
#define se second

using namespace std;

const int N = 100000;
const int inf = (int)1e9 + 1;
const ll big = (ll)1e18 + 1;
const int P = 31;
const int MOD = (int)1e9 + 7;
const int MOD1 = (int)1e9 + 9;
const double eps = 1e-6;
const double pi = atan2(0, -1);

ll solve(ll n, ll x)
{
    if (x % (n - x) == 0)
        return x / (n - x) * (2 * (n - x));
    else
        return x / (n - x) * (2 * (n - x)) + (n - x) + n % (n - x) + solve(n - x, (n - x) - n % (n - x));
}

int main()
{
    //freopen("a.in", "r", stdin);
    //freopen("a.out", "w", stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.precision(20);
    //int TL = 1.95 * CLOCKS_PER_SEC;
    //clock_t time = clock();
    ll n, x;
    cin >> n >> x;
    cout << x + solve(n, x) << endl;
    return 0;
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
#まず、combの左に来るのは、max(a)
#combの右に来るのは、max(a)//2 or max(a)-max(a)//2　に一番近い数字

m = max(a)
a.sort()
a.pop()
#print(a)
#前から順番に審査していき、現状最高のやつを選んでおく。

dif = 10**9
ans = 0
for num in a:
  d = min(abs(m//2 - num),abs(m//2 + num - m))
  if dif > d:
    dif = d
    ans = num
print(m,ans)  

Measured memory_bytes: 62704
#include<stdio.h>
  int main(void){
  int num1,num2,num3;
  scanf("%d",&num1);
  scanf("%d",&num2);
  scanf("%d",&num3);
  if(num1==num2&&num2==num3){
    printf("1");
  }else if(num1==num2||num2==num3||num3==num1){
    printf("2");
  }else{
    printf("3");
  }
  return 0;
}


Measured memory_bytes: 128