akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

using ll = long long;
using ull = uint64_t;
using P = pair<int, int>;
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
// constexpr int mod = 1000000007;
constexpr int mod = 998244353;

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

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

    int n;
    cin >> n;
    vector<int> a(n), b(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 k = 0; k <= 28; ++k){
        int T = 1 << (k + 1);
        vector<int> m(n);
        for(int i = 0; i < n; ++i){
            m[i] = b[i] % T;
        }
        sort(m.begin(), m.end());
        T >>= 1;
        ll c = 0;
        for(int i = 0; i < n; ++i){
            int val = a[i] % (T << 1);
            c += lower_bound(m.begin(), m.end(), T * 2 - val) - lower_bound(m.begin(), m.end(), T - val);
            c += lower_bound(m.begin(), m.end(), T * 4 - val) - lower_bound(m.begin(), m.end(), T * 3 - val);
        }
        if(c % 2)   ans += T;
    }
    cout << ans << endl;
}

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

using namespace std;

struct Dice
{
  int x, y;
  int l, r, f, b, d, u;

  void RollF()
  {
    --y;
    int buff = d;
    d = f;
    f = u;
    u = b;
    b = buff;
  }

  void RollB()
  {
    ++y;
    int buff = d;
    d = b;
    b = u;
    u = f;
    f = buff;
  }

  void RollL()
  {
    --x;
    int buff = d;
    d = l;
    l = u;
    u = r;
    r = buff;
  }

  void RollR()
  {
    ++x;
    int buff = d;
    d = r;
    r = u;
    u = l;
    l = buff;
  }
};

int N;
Dice dice[15];
string rot[15];
int dp[1 << 15];
int v[2100][2100], buff[2100][2100];

void Roll(Dice& obj, char c)
{
  switch(c) {
    case 'L':
      obj.RollL();
      return;
    case 'R':
      obj.RollR();
      return;
    case 'B':
      obj.RollB();
      return;
    case 'F':
      obj.RollF();
      return;
    default:
      return;
  }
}

int AddDice(int idx)
{
  int ret = 0;
  Dice obj = dice[idx];
  for(char c : rot[idx]) {
    Roll(obj, c);
    if(v[obj.y][obj.x] == -1) {
      v[obj.y][obj.x] = idx;
      buff[obj.y][obj.x] = obj.d;
      ret += obj.d;
    } else if(v[obj.y][obj.x] == idx) {
      ret -= buff[obj.y][obj.x];
      ret += obj.d;
      buff[obj.y][obj.x] = obj.d;
    }
  }
  return (ret);
}

void DeleteDice(int idx)
{
  Dice obj = dice[idx];
  for(char c : rot[idx]) {
    Roll(obj, c);
    if(v[obj.y][obj.x] == idx) {
      v[obj.y][obj.x] = -1;
    }
  }
}

int rec(int bit)
{
  if(bit == (1 << N) - 1) return (0);
  if(~dp[bit]) return (dp[bit]);
  int ret = 0;
  for(int i = 0; i < N; i++) {
    if((bit >> i) & 1) continue;
    int get = AddDice(i);
    ret = max(ret, rec(bit | (1 << i)) + get);
    DeleteDice(i);
  }
  return (dp[bit] = ret);
}

int main()
{
  memset(v, -1, sizeof(v));
  while(cin >> N, N) {
    for(int i = 0; i < N; ++i) {
      cin >> dice[i].x >> dice[i].y;
      cin >> dice[i].l >> dice[i].r >> dice[i].f >> dice[i].b >> dice[i].d >> dice[i].u;
      cin >> rot[i];
      rot[i] = "~" + rot[i];
      dice[i].x += 1050, dice[i].y += 1050;
    }
    memset(dp, -1, sizeof(dp));
    cout << rec(0) << endl;
  }
}

Measured memory_bytes: 23952
#include<stdio.h>

int main(){
	
	int N=0;
	int i=0;
	int max=0;
	int ans=0;
	int H[100];
	
	scanf("%d", &N);
	
	for(i=0;i<100;i++)
	{
		H[i]=0;
	}
	
	for(i=0;i<N;i++)
	{
		scanf("%d",&H[i]);
	}
	
	max = H[0];
	
	for(i=0;i<N;i++)
	{
		if(max<=H[i])
		{
			ans++;
			max=H[i];
		}
	}
	
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;	 
    public class Main{
	public static void main(String[] agrs) {
	    Scanner sc = new Scanner(System.in);
	        for(;;){
	            int n = sc.nextInt();
	            int r = sc.nextInt();	             
	            if( n==0 && r==0) {
	                break;
	            }	             
	            int[] input = new int[n];
	            for(int i = 0; i < n ; i++){
	                input[i] = n - i;
	            }	             
	            for(int i = 0; i < r ; i++){
	                int p = sc.nextInt()-1;
	                int c = sc.nextInt();                 
	                int[] deck = input.clone();	                 
	                for(int j = 0 ; j < c ; j++){
	                    deck[j] = input[j+p];
	                }
	                for(int j = 0; j < p ; j ++){
	                    deck[j+c] = input[j];
	                }
	                input = deck;
	            }
	            System.out.println(input[0]);
	        }
	}
    }


Measured memory_bytes: 37220
n,c=map(int, input().split())
lst = [list(map(int, input().split())) for i in range(n)] 
ans=0
lback=[0]
rback=[0]
l=0
r=0
for i, j in enumerate(lst,1):
  l+=j[1]
  if(lback[i-1]<l-2*j[0]):
    lback+=[l-2*j[0]]
  else:
    lback+=[lback[i-1]]
  ans=max(ans,l-j[0])
for i, j in enumerate(lst[::-1],1):
  r+=j[1]
  if(rback[i-1]<r-2*(c-j[0])):
    rback+=[r-2*(c-j[0])]
  else:
    rback+=[rback[i-1]]
  ans=max(ans,r-(c-j[0]), lback[n-i]+r-(c-j[0]) )
l=0
for i, j in enumerate(lst,1):
  l+=j[1]
  ans=max(ans,rback[n-i]+l-j[0])
print(ans)

Measured memory_bytes: 33408
#include<bits/stdc++.h>
using namespace std;
#define Mod(n) n % 1000000007
const int dx[8] = {1, 0, -1, 0, -1, 1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, -1, -1, 1};
int main()
{    
    int N;
    cin >> N;
    string ans;
    for(int i = N;i < 1000;++i)
    {
        string s = to_string(i);
        if(s[0] == s[1] && s[1] == s[2])
        {
            ans = s;
            break;
        }
    }
    cout << ans + '\n';
}

Measured memory_bytes: 256
# floor(Ax/B) - A floor(x/B) の最大値Mを求める
# xはN以下の非負整数
# floor(Ax / B) = M + A floor(x / B)
# x / B = k + r
# Ax / B = Ak + Ar

# floor(Ak + Ar) = M + A floor(k + r)
# Ak + floor(Ar) = M + Ak + A floor(r)
# floor(Ar) = M

# r = x / B - k
# M = floor(A * (x / B - k))
#   = floor(A * x /B) - Ak
#   = floor(A/B * x) - Ak
#   = floor(A/B * x) - A * (x // B) 

# A B N
# 5 7 4

# M = floor(5/7 * x) - 5 * (x // 7)


# A B N 
# 11 10 9
# M = floor(11 / 10 * x) - 11 * (x // 10)

import math

def calcM(A, B, x):
        return math.floor(A / B * x) - A * math.floor(x / B)    

def resolve_v1(A, B, N):
    maxM = 0
    for x in range(N+1): # O(N)
        M = calcM(A, B, x)
        maxM = max(maxM, M)

    return maxM

def resolve_v2(A, B, N):
    # x == kB - 1
    maxM = calcM(A, B, N)

    for x in filter(lambda x: (x + 1) % B == 0, range(N+1)): # O(N/B)
        maxM = max(maxM, calcM(A, B, x))
    return maxM


def resolve_v3(A, B, N):
    maxM = calcM(A, B, N)

    k, r = divmod(N, B)
    if k and B * k -1 <= N:
        # k * B - 1で調査
        maxM = max(maxM, calcM(A, B, k * B - 1))
    # if r == 0:
    #     maxM = max(maxM, calcM(A, B, N - 1))

    maxM = calcM(A, B, min(N, B - 1))


    return maxM

if __name__ == '__main__':
    A, B, N = map(int, input().split())
    M = resolve_v3(A, B, N)
    print(M)




Measured memory_bytes: 9104
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#define T = 1000000007

using namespace std;

long long* a;
const long long mod = 1e9+7;

int main(){
	int n, m; 
    cin >> n >> m;

    a = new long long[n+1];
    a[0] = 1;
    a[1] = 1;

    for(int i = 2; i < n+1; i++){
        a[i] = -1;
    }

    for(int i = 0; i < m; i++){
        long long t;
        cin >> t;
        a[t] = false;
    }

    for(int i = 1; i < n; i++){
        if(a[i+1]) a[i+1] = (a[i] + a[i-1]) % mod;
    }

    cout << a[n] << endl;
}

Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<vector>
#include<queue>
using namespace std;
typedef long long llong;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)

static const int MAX = 20;
static const int NIL = -1;
int n, m;
char s[MAX][MAX + 1];
int d[MAX][MAX + 1];
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int ans;

void dfs(int x, int y, int k){
    REP(l, n){
        REP(g, m){
            d[l][g] = NIL;
        }
    }
    queue <pair<int, int> > S;
    S.push(make_pair(x, y));
    d[x][y] = 0;
    int maxL = 0;
    int maxX = x;
    int maxY = y;
    while (!S.empty()){
        int X = S.front().first;
        int Y = S.front().second;
        S.pop();
        REP(l, 4){
            int nx = X + dx[l];
            int ny = Y + dy[l];
            if (0 <= nx && nx < n && 0 <= ny && ny < m && s[nx][ny] != '#' && d[nx][ny] == NIL){
                S.push(make_pair(nx, ny));
                d[nx][ny] = d[X][Y] + 1;
                if (maxL < d[nx][ny]){
                    maxL = d[nx][ny];
                    maxX = nx;
                    maxY = ny;
                }
            }
        }
    }
    ans = max(ans, maxL);
    if (k == 1) dfs(maxX, maxY, k + 1);
}

int main(){
    cin >> n >> m;
    REP(i, n){
        REP(j, m){
            cin >> s[i][j];
        }
    }

    int cnt = 0;
    ans = 0;
    REP(i, n){
        REP(j, m){
            if (s[i][j] == '.'){
                dfs(i, j, 0);
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
from heapq import heappush, heappop
import re
from collections import deque
import sys
import math
input = sys.stdin.readline


def int_raw():
    return int(input())


def ss_raw():
    return input().split()


def ints_raw():
    return tuple(map(int, ss_raw()))


DIV = 10**9+7


def mod_inv_prime(a, mod=DIV):
    return pow(a, mod-2, mod)


def mod_inv(a, b):
    r = a
    w = b
    u = 1
    v = 0
    while w != 0:
        t = r//w
        r -= t*w
        r, w = w, r
        u -= t*v
        u, v = v, u
    return (u % b+b) % b


def ncr(n, r, mod=DIV):
	r = min(r, n-r)
	ret = 1
	for i in range(1, r+1):
		ret = ret * (n-i+1) % mod
		ret = ret * mod_inv(i, mod) % mod
	return ret


def main():
    r =int_raw()
    return r*r*3
print(main())


Measured memory_bytes: 38256
#include<bits/stdc++.h>
using namespace std;
const double pi=acos(-1.0);
const int dx[]={0,1,0,-1};
const int dy[]={1,0,-1,0};
#define ll long long
#define inf int(1e9+7)
#define pb push_back
#define mp make_pair
#define st first
#define nd second
#define l(s) s.size()
int a,p;
int main()
{
	cin>>a>>p;
	cout<<(a*3+p)/2;
	return 0;
}

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

int main(){
    int h, a;
    cin >> h >> a;
    int ans = 0;
    while(h > 0){
        h -= a;
        ans++;
    }
    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(v) v.begin(),v.end()
#define _GLIBCXX_DEBUG

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vd = vector<double>;
using vvi = vector<vi>;
using vvll = vector<vll>;
using vvd = vector<vd>;
using vvvi = vector<vvi>;
using vvvll = vector<vvll>;
using vvvd = vector<vvd>;

const double pi=acos(-1);
const ll MOD=1e9+7;
const ll INF=(1LL<<60);

bool is_prime(int64_t x) {
    for(int64_t i = 2; i * i <= x; i++) {
        if(x % i == 0) return false;
    }
    return true;
}

int main() {
    int dic[100010];
    dic[0]=0;
    dic[1]=0;
    dic[3]=1;
    int dic1[100010];
    dic1[1]=0;
    dic1[2]=1;
    dic1[3]=1;
    for (int i=5;i<100010;i+=2){
        if (is_prime(i)){
            dic1[i]=1;
            if (((i+1)/2)%2==1 && dic1[(i+1)/2]){
                dic[i]=dic[i-2]+1;
            }
            else{
                dic[i]=dic[i-2];
            }
        }
        else{
            dic[i]=dic[i-2];
        }
    }
    int q;
    cin>>q;
    rep(i,q){
        int l,r;
        cin>>l>>r;
        cout<<dic[r]-dic[max(0,l-2)]<<endl;
    }
    

    return 0;
}

Measured memory_bytes: 1408
r =10000001
p = [1]*r
p[0]= p[1] = 0
for i in range(int(r**0.5)):
	if p[i]:
		p[2*i::i] = [0 for j in range(2*i,r,i)]
		
while 1:
	try:
		n = input()
		if n == 0: break
		n -= 1-n%2
		while any(not p[n-i] for i in [0,2,6,8]):
			n -= 2 + (2 + 4*(1-p[n-6]))*(1-p[n-2])
		print n
	except:
		pass

Measured memory_bytes: 280936
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>
#include <string>

using namespace std;

int main() {
    int N;
    string S;
    cin >> N;
    cin >> S;
    long long r = 0, g = 0, b = 0;
    long long sum;
    for(int i = 0; i < N; i++) {
        if(S[i] == 'R') {
            r++;
        } else if(S[i] == 'G') {
            g++;
        } else {
            b++;
        }
    }
    sum = r * g * b;
    for(int i = 2; i <= N - 1; i++) {
        for(int j = 1; i + j <= N && i - j >= 1; j++) {
            if(S[i - j - 1] != S[i - 1] && S[i - 1] != S[i + j - 1] && S[i - j - 1] != S[i + j - 1]) {
                sum--;
            }
        }
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 3632
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <iostream>
#include <random>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include <fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;

using ll = long long;
using vll = vector<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using vb = vector<bool>;
using mll = map<ll, ll>;
using sll = stack<ll>;
#define REP(i,n) for(ll i(0);(i)<(n);(i)++)
#define rep(i,n) for(ll i(0);(i)<(n);(i)++)
#define ALL(a) a.begin(), a.end()
#define enld endl //* missspell check
const ll INF = 1LL << 60;
ll gcd (ll a, ll b){ return b == 0? a : gcd(b, a % b); }
ll lcm (ll a, ll b){ return a * (b / gcd(a, b));}

void solve(long long A, long long B){
    cout << lcm(A, B)<<endl;
}

int main(){
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    solve(A, B);
    return 0;
}


Measured memory_bytes: 256
//解説の別解
// 左がxとすると右はsum-xなので
// 最小のabs(sum-2x)をみつける
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
using ll = long long;
// const int INF = 2147483647;
const ll INF = 1000000000000000000LL;

int main(){
	int n;
	cin >> n;
	vector<int> a(n);
	ll sum=0;
	rep(i,n){
		cin >> a[i];
		sum+=a[i];
	}
	ll x=0;
	ll ans = INF;
	for(int i=0;i<n;i++){
		x+=a[i];
		// 2人とも1枚ずつとらなきゃだめ
		if(i+1<n) ans=min(ans,abs(sum-2*x));
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <string>
#include <cmath>
#include <limits>
#include <algorithm>
#include <memory>

constexpr long long MOD = 1000000007;

int main()
{
  int N;
  std::cin >> N;
  std::string S;
  std::cin >> S;
  int K;
  std::cin >> K;
  char c = S[K-1];
  for (auto& val: S)
  {
    if (val != c)
      val = '*';
  }
  std::cout << S << std::endl;
  return 0;
}



Measured memory_bytes: 256
#include <iostream>
using namespace std;
#define x 1000000
int main(){
	bool q[x];
	for(int i=2;i<x;i++) q[i] = true;
	for(int i=2;i<x;i++) if(q[i]) for(int j=2;j<=x/i;j++) q[i*j] = false;
	int n;
	while(cin >> n){
		int a = 0;
		for(int i=2;i<=n;i++) if(q[i]) a++;
		cout << a << endl;
	}
}

Measured memory_bytes: 2132
// "bits/stdc++.h" {{{
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <sstream>
#include <numeric>
#include <array>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <cassert>
#include <cctype>
#include <cfloat>
#include <climits>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <limits>
#include <typeinfo>
#include <initializer_list>
#include <bitset>
#include <chrono>
#include <functional>
#include <tuple>
#include <typeindex>
#include <utility>
#include <string>
#include <regex>
// }}}

// Begin {{{
using namespace std;

#define all(x) x.begin(), x.end()
#define rep(i, n) for (i64 i = 0; i < (n); ++i)
#define reps(i, s, n) for (i64 i = (s); i <= (n); ++i)
#define VAR(Type, ...) Type __VA_ARGS__; IN(__VA_ARGS__)
#define Float(x) OUTN(fixed, setprecision(x));

using i64 = int_fast64_t;
using pii = pair<i64, i64>;

template <class A, class B>
inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }

template <class A, class B>
inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int MOD = int(1e9) + 7;

// IN
void IN() {}
template <class Head, class... Tail>
void IN(Head&& head, Tail&&... tail) {
  cin >> head;
  IN(forward<Tail>(tail)...);
}

// OUTS
void OUTS() {}
template <class Head, class... Tail>
void OUTS(Head&& head, Tail&&... tail) {
  cout << head << " \n"[sizeof...(tail)==0];
  OUTS(forward<Tail>(tail)...);
}

template <class T>
void OUTS(vector<T> &vec) { for (auto &e : vec) cout << e << " \n"[&e==&vec.back()]; }

template <class T>
void OUTS(vector<vector<T>> &df) { for (auto &vec : df) OUTS(vec); }

// OUTL
void OUTL() {}
template <class Head, class... Tail>
void OUTL(Head&& head, Tail&&... tail) {
  cout << head << "\n";
  OUTL(forward<Tail>(tail)...);
}

template <class T>
void OUTL(vector<T> &vec) { for (auto &e : vec) cout << e << "\n"; }

// OUTN
void OUTN() {}
template <class Head, class... Tail>
void OUTN(Head&& head, Tail&&... tail) {
  cout << head;
  OUTN(forward<Tail>(tail)...);
}

template <class T>
void OUTN(vector<T> &vec) { for (auto &e : vec) cout << e; }
// }}} End

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

  VAR(string, s);

  string t = "CODEFESTIVAL2016";
  i64 res = 0;
  for (int i = 0; i < s.length(); ++i) {
    if (s[i] != t[i]) ++res;
  }

  OUTL(res);
  return 0;
}


Measured memory_bytes: 256
/// IN THE NAME OF GUITAR
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long int ll;
typedef pair<ll, ll> pll;

#define sz(x)                       (ll) x.size()
#define all(x)                      (x).begin(),(x).end()
#define F                           first
#define S                           second
#define lc                          id << 1
#define rc                          lc | 1

ll Pow(ll a, ll b, ll md, ll ans = 1) {
    for (; b; b >>= 1, a = a * a % md)
        if (b & 1)
            ans = ans * a % md;
    return ans % md;
}
 
const ll MAXN = 1e6 + 20;
const ll INF  = 1e18;
const ll MOD  = 1e9 + 7;
ll dp[MAXN], ps[MAXN], n;

int main() {
	scanf("%lld", &n);
	dp[n - 1] = n * n % MOD; dp[n] = ps[n] = n;
	ps[n - 1] = (dp[n] + dp[n - 1]) % MOD;
	for (ll i = n - 2; i >= 1; i--) {
		dp[i] = (dp[i + 1] + (n - 1) * (n - 1) % MOD) % MOD;
		dp[i] = ((dp[i] + ps[i + 3]) % MOD + 1 + i) % MOD;
		ps[i] = (ps[i + 1] + dp[i]) % MOD;
	}
	printf("%lld\n", dp[1]);
    return 0;
}
 

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

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

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	string s="keyence";
	string t; cin>>t;
	for (int i=0; i<=s.size(); i++) {
		string a=s.substr(0,i), b=s.substr(i);
		if(t.substr(0,a.size())==a&&t.substr(t.size()-b.size())==b) {
			cout<<"YES\n";
			return 0;
		}
	}
	cout<<"NO\n";
	return 0;
}

Measured memory_bytes: 256
d,g=map(int,input().split())
p,c=[],[]
for _ in range(d):
    pi,ci=map(int,input().split())
    p.append(pi)
    c.append(ci)
ans=float("inf")
for i in range(1<<d):
    tmp=0
    solvedproblemNum=0
    problemlist=[]
    for j in range(d):
        if (i>>j) & 1 :
            tmp+=p[j]*100*(j+1)+c[j]
            solvedproblemNum+=p[j]
        else:
            problemlist+=[100*(j+1)]*(p[j]-1)
    problemlist=sorted(problemlist,reverse=True)
    for item in problemlist:
        if tmp>=g:
            ans=min(ans,solvedproblemNum)
            break
        solvedproblemNum+=1
        tmp+=item
    if tmp>=g:
        ans=min(ans,solvedproblemNum)
    # print(problemlist,i,tmp)
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
//---------------------------
using namespace std;
//---------------------------
#define REP(i,n) for(int i = 0; i < (n); i++)
#define P(x) cout << (x) << "\n"

#define MOD 1e9+7
#define PI acos(-1.0)
#define ll long long

int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};
//---------------------------

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

  // ifstream in("input.txt");
  // cin.rdbuf(in.rdbuf());

  int N;cin>>N;
  int wait=0;
  int C[501],S[501],F[501],e[501];
  e[N]=0;
  for(int i=1;i<=N-1;i++){
    cin>>C[i]>>S[i]>>F[i];
  }
  for(int i=1;i<=N-1;i++){
    // e[i]を求める
    wait=0;
    for(int j=i;j<=N-1;j++){
      if(wait<=S[j])wait=S[j];
      if(wait>S[j]){
        int m=wait/F[j];
        int n=(wait%F[j]>0)?1:0;
        // cout<<'m'<<m<<'n'<<n<<endl;
        wait=(m+n)*F[j];
      }
      wait+=C[j];
    }
    P(wait);
  }
  P(e[N]);
  return 0;
}


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

int main(){
//    cout << fixed << setprecision(10);
    int K, N;
    cin >> K >> N;
    int A0;
    cin >> A0;
    int last = A0;
    int maxDistance = 0;
    
    for (int i = 1; i < N; i++) {
        int A;
        cin >> A;
        int distance = A - last;
        if (maxDistance < distance) {
            maxDistance = distance;
        }
        last = A;
    }
    
    int distance = A0 + K - last;
    if (maxDistance < distance) {
        maxDistance = distance;
    }
    
    cout << K - maxDistance;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
const ll mod=1000000007;
const ll INF=1e15;
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define U_ERASE(V) V.erase(unique(ALL(V)), V.end());
#define pb push_back
#define mp make_pair
typedef pair<ll,ll> P;
vec dx={1,0,-1,0};
vec dy={0,1,0,-1};

int main(){
    ll N; cin>>N;
    string S; cin>>S;
    vector<int> d(N,0);
    rep(i,N) if(S.at(i)=='o') d.at(i)=1;

    bool able=false;

    vector<int> ans(N);
    rep(k,4){
        bool okay=true;
        ans.at(0)=k/2;
        ans.at(1)=k%2;
        REP(i,1,N-1){
            ll x=(ans.at(i)+ans.at(i-1))%2;
            if(d.at(i)==1) ans.at(i+1)=1-x;
            else ans.at(i+1)=x;
        }
        if((ans.at(N-2)+ans.at(N-1)+ans.at(0))%2!=d.at(N-1)) okay=false;
        if((ans.at(N-1)+ans.at(0)+ans.at(1))%2!=d.at(0)) okay=false;
        if(okay) {able=true; break;}
    }
    if(able) rep(i,N){
        if(ans.at(i)) cout<<'S';
        else cout<<'W';
    }
    else cout<<-1;
    cout<<endl;

}

Measured memory_bytes: 1408
#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
int main(){
    string S,T;
    cin>>S>>T;
    vector<int> lis[30];
    for(int i=0;i<S.size();i++){
        lis[S[i]-'a'].push_back(i+1);
    }
    long long int ans=0,now=0;

/*
    for(int i=0;i<30;i++){
        printf("%c:",'a'+i);
        for(int j=0;j<lis[i].size();j++){
            printf("[%d]",lis[i][j]);
        }
        puts("");
    }
*/

    for(int i=0;i<T.size();i++){
        if(lis[T[i]-'a'].size()==0){
            puts("-1");
            return 0;
        }
        int mo=T[i]-'a';
        if(lis[mo][lis[mo].size()-1]<=now){
            //printf("[%d]",i);
            ans+=S.size()-now;
            ans+=lis[T[i]-'a'][0];
            now=lis[T[i]-'a'][0];
        }
        else{
            int l=0,r=lis[mo].size(),mid;
            for(int j=0;j<20;j++){
                mid=(l+r)/2;
                if(now<lis[mo][mid])r=mid;
                else l=mid;
            }
            if(now>=lis[mo][mid])mid++;
            ans+=lis[mo][mid]-now;
            now=lis[mo][mid];
        }
        //cout<<ans<<endl;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1216
//1.read question_2.read I/O_3.read test cases_4.read constraints(to decide TC of solution)_5.decide method_6.dry run_
//7.code_8.test_9.submit
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
#define mod 1000000007
#define F first
#define S second
#define _READ freopen("input.txt","r", stdin);
#define pb push_back
#define MP make_pair
#define _FAST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int main()
{
 
    lli n,k;
    cin>>n>>k;vector<lli> ar(n);
    for(auto &i:ar)
        cin>>i;
    sort(ar.rbegin(),ar.rend());
    for(lli i=0;i<min(k,n);i++)
    {
        ar[i]=0;
    }
    lli sum=0;
    for(lli i=0;i<n;i++)
        sum+=ar[i];
    cout<<sum;
    return 0;
}


Measured memory_bytes: 1792
import math
#import numpy as np
import queue
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)

def main():
    n = int(ipt())
    x = [int(i) for i in ipt().split()]
    nl = [n]*n
    lst = 0
    mod = 10**9+7
    ans = 1
    for i,xi in enumerate(x):
        if xi < 2*(i-lst)+1:
            nl[lst] = i+1
            lst += 1
    for i,nli in enumerate(nl):
        ans = ans*(nli-i)%mod
    print(ans)

    return

if __name__ == '__main__':
    main()


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

#define DB(x) cerr << __LINE__ << ": " << #x << " = " << (x) << endl
#define all(x) (x).begin(),(x).end()
#define mem(x, n) memset(x, n, sizeof(x))

using namespace std;

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

const int SIZE = 2e5+10;

const ll MOD = 1e9 + 7;
ll n;
ll A[SIZE];

ll check(ll b) {
	ll s = 0;
	for(int i=0;i<n;i++) {
		s += abs(A[i] - (b + i + 1));
	}
	return s;
}

int main() {
	scanf("%lld", &n);
	for(int i=0;i<n;i++) {
		scanf("%lld", &A[i]);
	}
	ll l = -2e9, r = 2e9, m1, m2, c1, c2, ans;
	for(int i=0;i<200;i++) {
		m1 = l + (r-l)/3;
		m2 = l + (r-l)*2/3;
		c1 = check(m1);
		c2 = check(m2);
		if(c1 < c2) {
			ans = c1;
			r = m2;
		} else {
			ans = c2;
			l = m1;
		}
	}
	printf("%lld\n", ans);
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
//#pragma GCC target ("avx")
#pragma GCC optimization ("Ofast")
#pragma GCC optimization ("unroll-loops")
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define all(v) v.begin(),v.end()
#define P pair<int,int>
#define siz(s) (int)s.size()

template<class T> inline bool chmin(T &a, T b) {
	if(a>b){a=b;return true;}
	return false;
}
template<class T> inline bool chmax(T &a, T b) {
	if(a<b){a=b;return true;}
	return false;
}
template<class T> inline int getidx(vector<T> &v, T a) {
	return lower_bound(all(v), a) - v.begin();
}

constexpr int mod=1e9+7;
constexpr int inf=3e18;

int mod_pow(int x,int y,int m=mod){
	int res=1;
	while(y>0){
		if(y&1)res=res*x%m;
		y>>=1;x=x*x%m;
	}
	return res;
}
int gcd(int x, int y) {
	if (y == 0)
		return x;
	return gcd(y, x % y);
}

int N,A[2000005];
map<int,int>dp[200005][2];
signed main(){
	cin.tie(0);ios::sync_with_stdio(false);
	cin>>N;
	rep(i,N)cin>>A[i];
	rep(i,N+1){
		rep(j,2)rep(k,2)dp[i][k][(i+1)/2-j]=-inf;
	}
	dp[0][0][0]=0;
	rep(i,N){
		for(int j=(i+1)/2-1;j<=(i+1)/2;j++){
			if(j<0)continue;
			chmax(dp[i+1][0][j],max(dp[i][0][j],dp[i][1][j]));
			chmax(dp[i+1][1][j+1],dp[i][0][j]+A[i]);
		}
	}
	cout<<max(dp[N][0][N/2],dp[N][1][N/2])<<"\n";
}


Measured memory_bytes: 86472
#include <bits/stdc++.h>
#include <iostream>
#include <utility> // pair
#include <string>
#include <vector>
#define MAX_H 21
#define MAX_W 21
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define FOR(i, a, b) for(ll i=a; i<b; i++)
#define REP(i, n) for(ll i=0; i<n; i++)
#define REV(i, n) for(ll i=n-1; i>=0; i--)
#define ALL(v) v.begin(), v.end()
#define pb push_back
const ll INF = 1000;
ll h, w, d[400][400];
char s[MAX_H][MAX_W];
ll dx[] = {1, -1, 0, 0};
ll dy[] = {0, 0, 1, -1};

signed main(){
    cin >> h >> w;
    REP(i, h) REP(j, w) cin >> s[i][j];
    REP(i, h*w) REP(j, h*w){
        if(i == j) d[i][j] = 0;
        else d[i][j] = INF;
    }
    REP(i, h*w){
        ll x = i % h;
        ll y = i / h;
        REP(j, 4){
            ll nx = x + dx[j];
            ll ny = y + dy[j];
            if(0 <= nx && nx < h && 0 <= ny && ny < w){
                if(s[x][y] == '.' && s[nx][ny] == '.'){
                    d[i][ny*h+nx] = 1;
                }
            }
        }
    }



    //warshall_floyd
    REP(k, h*w) REP(i, h*w) REP(j, h*w) d[i][j] = min(d[i][j], d[i][k] + d[k][j]);

    ll ret = 0;
    REP(i, h*w) REP(j, h*w){
        if(d[i][j] != INF) ret = max(ret, d[i][j]);
    }
    cout << ret << endl;
    return 0;
}

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

#define rep2(x,fr,to) for(int x=(fr);x<(to);x++)
#define rep(x,to) for(int x=0;x<(to);x++)
#define repr(x,fr,to) for(int x=(fr);x>=(to);x--)
#define all(c) c.begin(),c.end()
#define sz(v) (int)v.size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
typedef vector<ll> VL; const int MD = 1e9 + 7;
void dbg(){cerr<<"\n";} template <typename T,typename ...T2> void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }


int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);
	int k, n;
	cin >>n >>k;
	vector<double> ts(n+1);
	rep(i, n){
		int a; cin >>a;
		ts[i+1] = ts[i] + (a+1)/ 2.0;
	}
	double ans = 0;
	rep(i, n+1-k) ans = max(ans, ts[i+k] - ts[i]);
	printf("%.14f\n", ans);
	return 0;
}


Measured memory_bytes: 1792
n = int(input())
p = list(map(int,input().split()))
p.sort()
a1 = max(p)
a2 = min(p)
half = (a1+1) // 2
s = n // 2
graph = [0] * n

while True:
    if graph[s] != 0:
        break
    else:
        graph[s] += 1
    if p[s] <= half:
        if abs(p[s] - half) < abs(a2 - half):
            a2 = p[s]
        s += 1
    elif p[s] > half:
        if abs(p[s] - half) < abs(a2 - half):
            a2 = p[s]
        s -= 1
    if s == 0 or s == n:
        break
print(a1, a2)

Measured memory_bytes: 14440
#include<bits/stdc++.h>
using namespace std;
template <typename T> using vec = vector<T>;

int main()
{
    int n,q;
    string s;
    cin >> n >> q >> s;
    vec<int> sum(n);
    for (int i = 1; i < n; i++)
    {
        if(s.at(i)=='C' and s.at(i-1) == 'A')
        sum.at(i)++;
    }
    for (int i = 1; i < n; i++)
    {
        sum.at(i) += sum.at(i-1);
    }
    for (int i = 0; i < q; i++)
    {
        int l,r;
        cin >> l >> r;
        l--;
        r--;
        cout << sum.at(r) - sum.at(l) << endl;
    }
}

Measured memory_bytes: 1408
A, B, C = map(int, input().split())

if A == B == C:
    ans = -1 if A % 2 == 0 else 0
else:
    ans = 0
    while A % 2 + B % 2 + C % 2 == 0:
        A, B, C = (B + C) // 2, (C + A) // 2, (A + B) // 2
        ans += 1
print(ans)

Measured memory_bytes: 3060
#include<stdio.h>
int main()
{
    long n,m,a=0,b=0,c=0;
    scanf("%ld %ld",&n,&m);
    for(a=0;a<=n;a++)
    {
    	for(b=0;a+b<=n;b++)
    	{
    		for(c=0;a+b+c<=n;c++)
			{
				if(a+b+c==n&&a*10000+b*5000+c*1000==m)
				{
					printf("%ld %ld %ld",a,b,c);
					return 0;
				}
			}
		}
	}
	printf("-1 -1 -1");
	return 0;
} 

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int digsum(int n){
  int sum=0;
  int dig;
  while(n){
    dig=n%10;
    sum=sum+dig;
    n=n/10;
  }
  return sum;
}
int main(){
  int N;
  cin>>N;
  int A,B;
  cin>>A>>B;
  int count=0;
  for(int i=1;i<=N;i++){
    if(digsum(i)>=A && digsum(i)<=B){
      count=count+i;
    }
  }
  cout<<count<<endl;
  return 0;
}


Measured memory_bytes: 256
n = int(input())
d_ls = list(map(int, input().split()))
m_0 = 0
for i in range(n):
    if i % 2 == 0:
        m_0 += d_ls[i]
    else:
        m_0 -= d_ls[i]
m_ls = [0] * n
m_ls[0] = m_0
for i in range(n-1):
    m_ls[i+1] = 2*d_ls[i] - m_ls[i]
m_ls = list(map(str,m_ls))
print(' '.join(m_ls))



Measured memory_bytes: 18504
#!/usr/bin/env python3
import sys
import functools
import itertools
INF = float("inf")


@functools.lru_cache(maxsize=None)
def pow(b, n):
    return b**n


def f(n):
    # n桁の753数
    if n < 3:
        return 0

    return pow(3, n) - 3*pow(2, n) + 3


def solve(N: int):
    ketamax = len(str(N))

    ans = 0
    # 桁
    for i in range(3, ketamax):
        ans += f(i)
    # print(ans)
    # 最大桁数の場合だけごにょる(O(N))
    for item in itertools.product(["3", "5", "7"], repeat=ketamax):
        if "3" not in item or "5" not in item or "7" not in item:
            continue
        elif int("".join(item)) > N:
            continue
        else:
            ans += 1
    print(ans)
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    solve(N)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3572
#include <stdio.h>
#include <string.h>
#include <algorithm>
#define rep(i,st,ed) for (int i=st;i<=ed;++i)

const int INF=0x3f3f3f3f;
const int N=200005;

struct edge {int x,y,next;} e[N*2];

int f[N],g[N],ls[N],edCnt;

int read() {
	int x=0,v=1; char ch=getchar();
	for (;ch<'0'||ch>'9';v=(ch=='-')?(-1):(v),ch=getchar());
	for (;ch<='9'&&ch>='0';x=x*10+ch-'0',ch=getchar());
	return x*v;
}

void add_edge(int x,int y) {
	e[++edCnt]=(edge) {x,y,ls[x]}; ls[x]=edCnt;
	e[++edCnt]=(edge) {y,x,ls[y]}; ls[y]=edCnt;
}

void dfs(int x,int fa) {
	int rec=-INF,flag=0,wjp=0;
	for (int i=ls[x];i;i=e[i].next) {
		if (e[i].y==fa) continue;
		dfs(e[i].y,x); wjp=1;
		int mx=std:: max(g[e[i].y],f[e[i].y]);
		g[x]+=mx; f[x]+=mx;
		if (mx==g[e[i].y]) flag=1;
		rec=std:: max(rec,g[e[i].y]-f[e[i].y]);
	}
	if (wjp&&!flag||rec+1>0) f[x]+=rec+1;
}

int main(void) {
	int n=read();
	rep(i,2,n) add_edge(read(),read());
	dfs(1,0);
	if (std:: max(f[1],g[1])*2==n) puts("Second");
	else puts("First");
	return 0;
}


Measured memory_bytes: 5504
#! env/bin/local python3
# -*- coding:utf-8 -*-

# -- submit ----

# --- write code below ---
n = int(input())

converter = {
    0: 'pon',
    1: 'pon',
    2: 'hon',
    3: 'bon',
    4: 'hon',
    5: 'hon',
    6: 'pon',
    7: 'hon',
    8: 'pon',
    9: 'hon'
}

print(converter[n % 10])


Measured memory_bytes: 9160
#include<iostream>
#include<stdio.h>
#pragma warning(disable : 4996)
#include<algorithm>
#include<math.h>
using namespace std;
struct edge
{
	int from, to;
	double cost;
	edge() {};
	edge(int a, int b,double c) {
		from = a, to = b, cost = c;
	}
};
bool cmp(edge e1, edge e2) {
	return e1.cost > e2.cost;
}
const int MAX_N = 10005;
const int MAX_C = 100000;
int N, M;
int A[MAX_C], B[MAX_C], C[MAX_C], D[MAX_C];
edge es[MAX_C];
int par[MAX_N];
int ranks[MAX_N];

#define loop(i,N) for(int i=1;i<=N;i++)
void init(int X) {
	for (int i = 0; i <=N; i++)
	{
		par[i] = i;
		ranks[i] = 0;
	}
}
int find(int x) {
	if (par[x] == x)
		return x;
	else {
		return par[x] = find(par[x]);
	}
}
bool same(int x, int y) {
	return find(x) == find(y);
}
void unite(int x, int y) {
	x = find(x);
	y = find(y);
	if (x == y)
		return;
	if (ranks[x] < ranks[y]) {
		par[x] = y;
	}
	else {
		par[y] = x;
		if (ranks[x] == ranks[y])
			ranks[x]++;
	}
}
double kruskal() {
	init(N);
	sort(es+1, es + M+1, cmp);
	double res = 0;
	loop(u, M) {
		edge  e = es[u];
		if (!same(e.from, e.to)) {
			unite(e.from, e.to);
				res += e.cost;
		}
	}
	return res;
}
int main() {
	while (scanf("%d%d",&N,&M)!=EOF)
	{
		double ans=0;
		loop(i, N) {
			scanf("%d%d", &A[i], &B[i]);
		}
		loop(j, M) {
			scanf("%d%d", &C[j], &D[j]);
			double dis = sqrt((A[C[j]] - A[D[j]])*(A[C[j]] - A[D[j]]) + (B[C[j]] - B[D[j]])*(B[C[j]] - B[D[j]]));
			es[j] = edge(C[j], D[j], dis);
			ans += dis;
		}
		ans -= kruskal();
		printf("%.3lf\n", ans);
	}
}


Measured memory_bytes: 4036
import sys
import math
import collections
import bisect
import itertools
import decimal
import copy
import heapq

# import numpy as np

# sys.setrecursionlimit(10 ** 6)
INF = 10 ** 20
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline().rstrip())
ns = lambda: map(int, sys.stdin.readline().rstrip().split())
na = lambda: list(map(int, sys.stdin.readline().rstrip().split()))
na1 = lambda: list(map(lambda x: int(x) - 1, sys.stdin.readline().rstrip().split()))
flush = lambda: sys.stdout.flush()


# ===CODE===
def main():
    x=ni()
    print(1 if x==0 else 0)





if __name__ == '__main__':
    main()


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

typedef long long LL;
const int N = 200006;

int a[N];

int main ()
{
    int n;
    scanf("%d",&n);
    for (int i=1;n>=i;i++)
    {
        scanf("%d",&a[i]);
    }
    LL ans=0;
    int now_mn = 12345690;
    a[n+1] = 880301;
    for (int i=n;i>=1;i--)
    {
        if (a[i+1] == a[i] + 1) continue;
        else if (i - a[i] < 1)
        {
            puts("-1");
            return 0;
        }
        else
        {
            if (i-a[i] > now_mn)
            {
                puts("-1");
                return 0;
            }
            ans += (a[i]);
            now_mn = min(now_mn,i-a[i]);
        }
    }
    printf("%lld\n",ans);
}


Measured memory_bytes: 1024
$G=$'-<>=~$";map{$i+=100;for$k(reverse@a=//..$<){$p[$k]+=$-=$_>$k?0:$p[$k-$_]+$i*$_+($_==$`&&$')-$p[$k]for 1..$`}}<>;printf grep$p[$_]>$G,@a

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define      fastt       ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define      debug       printf("\n<<CameHere>>\n")
#define      mem(x,y)    memset(x, y, sizeof(x))
#define      all(qz)     qz.begin(),qz.end()
#define      rall(qz)    qz.rbegin(),qz.rend()
#define      inf         1000000000000000000
#define      mod         1000000007
#define      Sqr(x)      ((x)*(x))
#define      ll          long long
#define      mk          make_pair
#define      pb          push_back
#define      pi          acos(-1.0)
#define      cos(a)      cos(a*pi/180)
#define      sin(a)      sin(a*pi/180)
#define      tan(a)      tan(a*pi/180)

#define toll(a) atoll(a.c_str())
string tostr(ll a) {stringstream rr;rr<<a;return rr.str();}
ll pow(ll c,ll d){return d==0?:c*pow(c,d-1);}
ll gcd(ll a,ll b) {return b==0? a:gcd(b,a%b);}
ll lcm(ll a,ll b) {return ((a*b)/gcd(a,b));}
/*---------AL ASAD NUR RIYAD------------*/


int main()
{
    fastt

    ll n;
    cin>>n;
    vector<ll> v(n);
    for(ll i=0;i<n;i++) cin>>v[i];
    ll x=v[0];
    ll cnt=0;
    for(ll i=1;i<n;i++){
        if(v[i]<x){
            cnt+=x-v[i];
        }
        else x=v[i];
    }
    cout<<cnt<<endl;
    return 0;
}
























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

int n, A[50];

int solve(int i, int m){
    if(m==0) return 1;
    if(i>=n) return 0;
    int res = solve(i+1,m) || solve(i+1, m-A[i]);

    return res;
}

int main(){
    int q, M, i;
    
    scanf("%d", &n);
    for(i=0; i<n; i++) scanf("%d", &A[i]);
    scanf("%d", &q);
    for(i=0; i<q; i++){
        scanf("%d", &M);
        if(solve(0,M)) printf("yes\n");
        else printf("no\n");
    }

    return 0;
}


Measured memory_bytes: 3160
//Author: master19
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long int
#define ff first 
#define ss second 
#define pb push_back
#define endl "\n"
#define mod 1000000007LL // fixed...
#define modd 1000000007LL // Can be changed for global use
#define all(arr) arr.begin(),arr.end()
#define x(arr) arr.begin(),arr.end()
#define ulli unsigned long long int
#define assign(x,val) memset(x,val,sizeof(x))
#define prec(val, dig) fixed << setprecision(dig) << val
#define Sort(arr) sort(arr.begin(), arr.end())
#define time() std::chrono::high_resolution_clock::now();
#define lower(str) transform(str.begin(), str.end(), str.begin(), ::tolower);
#define upper(str) transform(str.begin(), str.end(), str.begin(), ::toupper);
#define crap ios_base :: sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define get(arr, num) vector < ll > arr(num); for(int i=0; i<num; i++)cin >> arr[i];
#define get_set(arr, num, st, type) set < type > st; for(int i=0; i<num; i++) st.insert(arr[i]);
#define put(arr, num) for(int i=0; i<num; i++)cout << arr[i] << " "; cout << endl;
#define Time(start, finish) std::chrono::duration<double> elapsed = finish - start; cout << elapsed.count() << endl;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update > new_ds; 
void debug_out() { cerr << endl; }
template <typename HeadStart, typename... TailEnd>
void debug_out(HeadStart H, TailEnd... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
ll lets_do_it();
pair < ll, ll > xy[] = {{-1, 0}, {1, 0} , {0, -1}, {0, 1}};
pair < ll, ll > dig[] = {{-1, -1}, {-1, 1}, {1, 1}, {1, -1}};
bool isValid(ll x, ll y, ll row, ll col){
    return ((x>=0) && (y >=0)  && (x < row) && (y < col));
}
int main(int argc, const char** argv) {
    crap;
    ll test = 1;
    // cin >> test;
    for(int loop=0; loop<test; loop++){
        // cout << "Case #" << (loop+1) << ": "; 
        lets_do_it();
    }
    return 0;
}
ll lets_do_it(){
    // Your code goes by here !!
    string str;
    cin >> str;
    if(str[str.length() - 1] == 's')
        str = str + "es";
    else
        str = str + "s";
    cout << str << endl;




    return 0;
}


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

N,T=map(int,input().split())
D=[tuple(map(int,input().split())) for i in range(N)]
D.sort()

DP=[0]*(T+1)
ANS=0

for i in range(N):
    a,b=D[i]

    for j in range(T,a-1,-1):
        DP[j]=max(DP[j-a]+b,DP[j])

    for j in range(i+1,N):
        ANS=max(ANS,DP[T-1]+D[j][1])

print(ANS)

Measured memory_bytes: 44396
#include<iostream>
using namespace std;
int main()
{
	int a, b, c, t;
	cin >> a >> b >> c;
	if (a > b) { t = a; a = b; b = t; }
	if (a > c) { t = a; a = c; c = t; }
	if (b > c) { t = b; b = c; c = t; }
	cout << a <<" "<< b <<" "<< c << endl;
	return 0;
}


Measured memory_bytes: 3096
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) {
        try {
            // 標準入力
            InputStreamReader isr = new InputStreamReader(System.in);
            BufferedReader br = new BufferedReader(isr);
            String a = br.readLine();
            int aCount = 0;
            String b = br.readLine();
            int bCount = 0;
            String c = br.readLine();
            int cCount = 0;;
            String now = "a";
            while (true) {
                if ("a".equals(now)) {
                    if (aCount >= a.length()) {
                        System.out.println("A");
                        break;
                    }
                    now = a.substring(aCount, aCount + 1);
                    aCount++;
                } else if ("b".equals(now)) {
                    if (bCount >= b.length()) {
                        System.out.println("B");
                        break;
                    }
                    now = b.substring(bCount, bCount + 1);
                    bCount++;
                } else if ("c".equals(now)) {
                    if (cCount >= c.length()) {
                        System.out.println("C");
                        break;
                    }
                    now = c.substring(cCount, cCount + 1);
                    cCount++;
                }
            }
       } catch (IOException e) {
            e.printStackTrace();
       }
    }
}


Measured memory_bytes: 21332
def func(latter, remains, former = []):
    #print(remains, former, latter)
    if remains == 0:
        return sum(x for _,x in former)
    if len(latter) == 0:      # 諦めて戻る
        while True:
            b, p = former.pop()    # formerの先頭から順に取り出し
            if p==0:               # ゼロの間は
                latter.append(b)   # latterに入れて
            else:             # ゼロでないものが見つかった時
                break         # ストップ
        return func(latter, remains+b, former+[(b, p-1)])
    a = latter.pop()
    q, r = divmod(remains, a)
    if r!=0: # 端数が出た時
        q = q-1 if q > 0 else 0  # ひとつ以上入るなら、ひとつ減らして入れ、入らないなら入れない
    return func(latter, remains-q*a, former+[(a, q)])

def func2(l, remains, remain_num, ans=[]):
    #print(l, remains, remain_num, ans)
    if len(l)>0:
        a, *l = l
        for i in range(min(remains//a, remain_num)+1):
            yield from func2(l, remains-a*i, remain_num-i, [(a, i)]+ans)
    elif remain_num==0 and remains==0:
        yield ans

n, m = map(int, input().split())
s = sorted((int(x) for x in input().split()), reverse=True)
num = [6,2,5,5,4,5,6,3,7,6]
t = sorted({num[i] for i in s}, reverse=True)
t_rev = {x:max(j for j in s if num[j]==x) for x in t}
t_min = t[-1]
m_num = func(t.copy(), n)   # 桁数
max_replacement = n - m_num*t_min        # 最小マッチでない数以外の数を最大何個使えるか
min_match_num = max(0, m_num - max_replacement)  # 最小マッチ数の数を少なくともどれだけ使うか
other_num = m_num - min_match_num   # 残された桁数
def func3(ans):
    l = {t_rev[x]:(i+min_match_num if x==t_min else i) for x,i in ans}
    return [l[x] for x in sorted(l, reverse=True)]
answer = max(func3(ans) for ans in func2(t.copy(), n-min_match_num*t_min, other_num))
print(*(str(x)*i for x, i in zip(sorted(t_rev.values(), reverse=True), answer)), sep='')

Measured memory_bytes: 3192
#include<bits/stdc++.h>
using namespace std;
typedef int sign;
typedef long long ll;
#define For(i,a,b) for(register sign i=(sign)(a);i<=(sign)(b);++i)
#define Fordown(i,a,b) for(register sign i=(sign)(a);i>=(sign)(b);--i)
const int N=600+5;
template<typename T>bool cmax(T &a,T b){return (a<b)?a=b,1:0;}
template<typename T>bool cmin(T &a,T b){return (a>b)?a=b,1:0;}
template<typename T>T read()
{
	T ans=0,f=1;
	char ch=getchar();
	while(!isdigit(ch)&&ch!='-')ch=getchar();
	if(ch=='-')f=-1,ch=getchar();
	while(isdigit(ch))ans=(ans<<3)+(ans<<1)+(ch-'0'),ch=getchar();
	return ans*f;
}
template<typename T>void write(T x,char y)
{
	if(x==0)
	{
		putchar('0'),putchar(y);
		return;
	}
	if(x<0)
	{
		putchar('-');
		x=-x;
	}
	static char wr[20];
	int top=0;
	for(;x;x/=10)wr[++top]=x%10+'0';
	while(top)putchar(wr[top--]);
	putchar(y);
}
void file()
{
#ifndef ONLINE_JUDGE
	freopen("F.in","r",stdin);
	freopen("F.out","w",stdout);
#endif
}
int n,a[N];
void input()
{
	n=read<int>();
	For(i,1,n*2)a[i]=read<int>();
}
int ban[N];
int f[N][N],g[N][N];
const int mo=1e9+7;
void add(int &x,int y){x+=y;x-=(x>=mo?mo:0);}
void work()
{	
	//memset(ban,-1,sizeof ban);				
	For(i,1,n*2)if(a[i]!=-1)ban[a[i]]=1;
	For(i,1,n)
	{
		if(a[i*2-1]!=-1&&a[i*2]!=-1)ban[a[i*2]]=ban[a[i*2-1]]=2;
	}
	f[0][0]=1;
	For(i,1,2*n)if(ban[i]<2)
	{
		memset(g,0,sizeof g);
		For(j,0,n*2)For(k,0,2*n)if(f[j][k])
		{
			//cout<<i<<' '<<j<<' '<<k<<endl;
			if(!ban[i])
			{
				add(g[j+1][k],f[j][k]);
				add(g[j][k+1],f[j][k]);
				if(k)add(g[j][k-1],f[j][k]);
			}
			else
			{
				add(g[j][k+1],f[j][k]);
				if(j)add(g[j-1][k],1ll*f[j][k]*j%mo);
			}
		}
		memcpy(f,g,sizeof f);
		/*cout<<i<<endl;
		For(j,0,n*2)For(k,0,n*2)if(f[j][k])
		{
			cout<<j<<' '<<k<<' '<<f[j][k]<<endl;
		}*/
	}
	int ans=f[0][0],cnt=0;
	For(i,1,n)if(a[i*2]==-1&&a[i*2-1]==-1)
	{
		ans=1ll*ans*(++cnt)%mo;
	}
	write(ans,'\n');
}
int main()
{

	input();
	work();
	return 0;
}



Measured memory_bytes: 3200