akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define rep(i, n) repd(i, 0, n)

using namespace std;

using ll = long long;
using ul = unsigned long long;
using ld = long double;
ll mod = 1000000007;

int main() {
    ll x, k, d;
    cin >> x >> k >> d;
    x = abs(x);
    if (abs(x) - abs(k * d) >= 0) {
        cout << abs(x) - abs(k * d) << endl;
    } else {
        ll temp = x % d;
        if (temp == 0) {
            if ((k - x / d) % 2) {
                cout << d << endl;
            } else {
                cout << 0 << endl;
            }
        } else {
            if ((k - x / d) % 2) {
                cout << d - temp << endl;
            } else {
                cout << temp << endl;
            }
        }
    }
    return 0;
}



Measured memory_bytes: 3632
#!/usr/bin/env python3
import sys

YES = "Yes"  # type: str
NO = "No"  # type: str

def solve(N: int):
    if N % 10 == N // 100:
        ret = YES
    else:
        ret = NO
    print(ret)
    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: 2940
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
  int mp[100][100];
  int x,y,size;
  int siro=100;
  int kosa=0;
  for(int i=20;i<30;i++){
    for(int j=20;j<30;j++){
      mp[i][j]=0;
    }
  }

  while(scanf("%d,%d,%d",&x,&y,&size)!=EOF){
    x=x+20;
    y=y+20;
    if(size==1){
      if(20<=x && x<=29 && 20<=y && y<=29){
	mp[x][y]++;
	mp[x+1][y]++;
	mp[x][y+1]++;
	mp[x-1][y]++;
	mp[x][y-1]++;
      }
    }
    else if(size==2){
      if(20<=x && x<=29 && 20<=y && y<=29){
	mp[x][y]++;
	mp[x][y-1]++;
	mp[x+1][y-1]++;
	mp[x+1][y]++;
	mp[x+1][y+1]++;
	mp[x][y+1]++;
	mp[x-1][y+1]++;
	mp[x-1][y]++;
	mp[x-1][y-1]++;
      }
    }
    else if(size==3){
      if(20<=x && x<=29 && 20<=y && y<=29){
	mp[x][y]++;
	mp[x][y-1]++;
	mp[x+1][y-1]++;
	mp[x+1][y]++;
	mp[x+1][y+1]++;
	mp[x][y+1]++;
	mp[x-1][y+1]++;
	mp[x-1][y]++;
	mp[x-1][y-1]++;
	mp[x][y-2]++;
	mp[x+2][y]++;
	mp[x][y+2]++;
	mp[x-2][y]++;
      }
    }
  }
  for(int i=20;i<30;i++){
    for(int j=20;j<30;j++){
      if(mp[i][j]!=0) siro--;
      if(kosa<mp[i][j]) kosa=mp[i][j];
    }
  }
  printf("%d\n",siro);
  printf("%d\n",kosa);
}

Measured memory_bytes: 1204
<?php
list($N, $W) = explode(" ", trim(fgets(STDIN)));

While ($str = trim(fgets(STDIN))) {
    $wv[] = explode(" ", $str);
}

$memo = [];
$max = 0;

function dp($i, $maxW)
{
    global $N, $wv, $memo;

    if (isset($memo[$i][$maxW])) {
        return $memo[$i][$maxW];
    }

    if ($i == $N) {
        $max = 0;
    } else if ($maxW < $wv[$i][0]) {
        $max = dp($i + 1, $maxW);
    } else {
        $max = max(
            dp($i + 1, $maxW),
            dp($i + 1, $maxW - $wv[$i][0]) + $wv[$i][1]
        );
    }

    $memo[$i][$maxW] = $max;
    return $max;
}

echo dp(0, $W);

Measured memory_bytes: 10744
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
const ll INF = 1LL << 60;
const ll MOD = (ll) 1e9 + 7;

int main(){
    string s;
    cin >> s;
    ll ans = INF;
    for (int i = 0; i < s.size() - 2; i++) {
        string sub = s.substr(i, 3);
        ll x = stoi(sub, nullptr, 10);
        ans = min(ans, abs(x - 753));
    }
    cout << ans << "\n";
}

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

int mod = 1000000007;
int64_t large = 9223372036854775807;
double PI = 3.141592653589793;

int main()
{
    int sx, sy, tx, ty;
    cin >> sx >> sy >> tx >> ty;
    int dx = tx - sx;
    int dy = ty - sy;

    cout << string(dx, 'R') << string(dy, 'U');

    cout << string(dx, 'L') << string(dy, 'D');

    cout << 'D' << string(dx + 1, 'R') << string(dy + 1, 'U') << 'L';

    cout << 'U' << string(dx + 1, 'L') << string(dy + 1, 'D') << 'R';
}

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

using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define all(x) x.begin(), x.end()

template <typename T1, typename T2> inline void chkmin(T1 &x, const T2 & y) {if (x > y) x = y;}
template <typename T1, typename T2> inline void chkmax(T1 &x, const T2 & y) {if (x < y) x = y;}
#define int ll

int n, m;
void read() {
	cin >> n >> m;
	if (n == 1 || m == 1) {
		cout << 1;
		return;
	}
	int ans = (n * m + 1) / 2;
	cout << ans << endl;
}

void run() {

}

void write() {

}

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	read();
	run();
	write();
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
template <class T> void chmin(T &a, const T &b) noexcept { if (b < a) a = b; }
template <class T> void chmax(T &a, const T &b) noexcept { if (a < b) a = b; }
void debug_out() { cout << "\n"; }
template <class T, class... Args>
void debug_out(const T &x, const Args &... args) { cout << x << " "; debug_out(args...);}
#ifdef _DEBUG
  #define debug(...) debug_out(__VA_ARGS__)
#else
  #define debug(...) 
#endif

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  string str;
  int k;
  cin >> str >> k;
  int n = str.length();
  vector<vector<vector<ll> > > dp(n+5, vector<vector<ll> >(2, vector<ll>(100,0)));
  dp[0][0][0] = 1;
  rep(i,n) {
    rep(j,100) { //0の個数
      dp[i+1][1][j] += dp[i][1][j]*9; //0以外
      dp[i+1][1][j+1] += dp[i][1][j]; //0

      int x = str[i]-'0';
      if (x > 0) {
       dp[i+1][1][j] += dp[i][0][j]*(x-1); //0以外
       dp[i+1][1][j+1] += dp[i][0][j]; //0
      }

      if (x == 0) dp[i+1][0][j+1] += dp[i][0][j]; //0をつける
      else dp[i+1][0][j] += dp[i][0][j]; //0以外がつく
    }
  }
  //0の個数はn-k個
  if (n-k < 0) cout << 0 << endl;
  else cout << dp[n][1][n-k] + dp[n][0][n-k] << endl;
  return 0;
}

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



int main()
{
    int t,i,j,k,n=101;
    cin>>i>>j>>k;
    while(k>0)
    {
        n--;
        if(i%n==0 and j%n==0)
        {
      //      cout<<n<<endl;
            k--;
        }
    }
    cout<<n;
    return 0;
}

Measured memory_bytes: 256
#pragma region _head

#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<map>
#include<iomanip>
#include<queue>
#include<stack>
#include<numeric>
#include<utility>

#pragma region _define

#define f(i,a,b) for(LL i=a;i<b;i++)
#define f_vI(v,n) f(i,0,n)cin>>v[i]
#define f_v2I(v1,v2,n) f(i,0,n)cin>>v1[i]>>v2[i]
#define f_v3I(v1,v2,v3,n) f(i,0,n)cin>>v1[i]>>v2[i]>>v3[i]
#define f_vO(v,n) f(i,0,n)cout<<v[i]<<endl;
#define all(a) a.begin(),a.end()
#define size(s) s.size()
#define check() cout<<"! ! !"
#define endl "\n"
#define _y() cout<<"Yes"<<endl
#define _Y() cout<<"YES"<<endl
#define _n() cout<<"No"<<endl
#define _N() cout<<"NO"<<endl

#pragma endregion

#pragma region _using

using namespace std;

using LL = long long;
using st = string;
using vi = vector<LL>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vc = vector<char>;
using vs = vector<st>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvvb = vector<vvb>;
using si = stack<LL>;
using ss = stack<st>;
using pi = pair<LL, LL>;
using v_pi = vector<pi>;

#pragma endregion

#pragma region _graph

#define node 50  //グラフの最大位数　適宜変更
//bool graph[node][node]; bool visited[node] = { false };
#define link(a,b,m) f(i,0,m){cin>>a[i]>>b[i]; a[i]--; b[i]--; graph[a[i]][b[i]]=graph[b[i]][a[i]]=true;}

#pragma endregion

LL gcd(LL a, LL b) {
	LL r;
	while ((r = a % b) != 0) {
		a = b;
		b = r;
	}
	return b;
}
LL lcm(LL a, LL b) {
	return (a / gcd(a, b)*b);
}

#pragma endregion

/************************************************************************/

int main(void) {
	cin.tie(0); ios::sync_with_stdio(false);
 
	int n, T;
	cin >> n >> T;
	vi t(n);
	LL ans = 0, tmp = 0;
	f(i, 0, n) {
		cin >> t[i];
		if (i != 0) {
			if (t[i] - t[i - 1] <= T) {
				ans += t[i] - t[i - 1];
			}
			else {
				ans += T;
			}
		}
	}
	cout << ans + T;
	return 0;
}

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

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

    ll choose[n + 1];
    ll sum = 0;
    for (int i = 1; i <= n; i++) {
        choose[i] = (ll)cnt[i] * (cnt[i] - 1) / 2;
        sum += choose[i];
    }

    ll ans[n];
    for (int i = 0; i < n; i++) {
        ans[i] = sum - choose[a[i]] + (ll)(cnt[a[i]] - 1) * (cnt[a[i]] - 2) / 2;
    } 

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

Measured memory_bytes: 7296
h,w,k = map(int,input().split())
grid = [list(input())for i in range(h)]
from copy import deepcopy
maze = deepcopy(grid)
ans = 0
for i in range(2**h):
    for j in range(2**w):
        point = 0
        for bh in range(h):
            if ((i>>bh)&1):
                for a in range(w):
                    grid[bh][a] = '0'
        for bw in range(w):
            if ((j >> bw)&1):
                for b in range(h):
                    grid[b][bw] = '0'
        for ii in range(h):
            for jj in range(w):
                if grid[ii][jj] == '#':
                    point += 1
        
        if point == k:
            ans += 1
        
        grid = deepcopy(maze)
print(ans)


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

namespace AtCoder.Contests.ABC166
{
    /// <summary>
    /// 
    /// </summary>
    static class D
    {
        static void Main(string[] args)
        {
            var x = NextInt();

            var sqrt = Math.Sqrt(x);
            for (int i = 1; i <= sqrt; i++)
            {
                if(x % i != 0) continue;

                for (long a = 0; 5* a * a * a * a - 10 * a * a * a + 10 *a * a -5*a +1 <= x; a++)
                {
                    var b = a - i;
                    if((a - b) * (a * a * a * a + a * a * a * b + a * a * b * b + a * b * b * b + b * b * b * b) == x)
                    {
                        Console.WriteLine(a + " " + b);
                        return;
                    }
                }
            }
        }

        #region Console
        static int _index = 0;
        static string[] _buffer;

        static string Next()
        {
            if (_buffer == null || _index >= _buffer.Length)
            {
                _buffer = Console.ReadLine().Split();
                _index = 0;
            }

            return _buffer[_index++];
        }
        static int NextInt()
        {
            return int.Parse(Next());
        }
        static long NextLong()
        {
            return long.Parse(Next());
        }
        static int ReadInt()
        {
            return int.Parse(Console.ReadLine());
        }
        static long ReadLong()
        {
            return long.Parse(Console.ReadLine());
        }
        static int[] ReadIntArray()
        {
            return Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        }
        static int[] ReadIntArray(int n)
        {
            var a = new int[n];
            for (int i = 0; i < n; i++)
            {
                a[i] = ReadInt();
            }
            return a;
        }
        static long[] ReadLongArray()
        {
            return Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
        }
        static long[] ReadLongArray(int n)
        {
            var a = new long[n];
            for (int i = 0; i < n; i++)
            {
                a[i] = ReadLong();
            }
            return a;
        }
        static List<T> ReadObjects<T>(int n, Func<int[], T> creator)
        {
            var l = new List<T>(n);

            for (int i = 0; i < n; i++)
            {
                var a = ReadIntArray();
                l.Add(creator(a));
            }

            return l;
        }

        static int[,] ReadMatrix(int n, int m)
        {
            var r = new int[n, m];
            for (int i = 0; i < n; i++)
            {
                var a = ReadIntArray();
                for (int j = 0; j < m; j++)
                {
                    r[i, j] = a[j];
                }
            }
            return r;
        }
        #endregion
    }
}


Measured memory_bytes: 27500
#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()

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

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

string s[55];
int n, m;

int dirx[] = {1, -1, 0, 0};
int diry[] = {0, 0, 1, -1};

bool chk(int x, int y)
{
    for (int i = 0; i < 4; i++) {
        int curx = x + dirx[i];
        int cury = y + diry[i];

        if (curx < 0 || curx >= n || cury < 0 || cury >= m) continue;

        if (s[curx][cury] == '#') return true;
    }

    return false;
}

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

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

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            if (s[i][j] == '#') {
                bool x = chk(i, j);
                if (!x) {printf("No\n"); return 0;}
            }
        }
    }

    printf("Yes\n");
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <limits.h>

#define ROOP(i,n) for(i=0;i<n;i++)

//prototype declaration
int getint();
long long getllint();
double getdint();
char getch();
void setstring(char *s);
void showint(int i);
void showllint(long long i);
void showdouble(double i);
void showchar(char c);
void showstring(char *s);

int myPower(int a, int n) { // aのn乗の計算
	int x = 1;
	while (n > 0) { // 全てのbitが捨てられるまで
		if ( n & 1) { // 一番右のbitが１のとき
			x *= a;
		}
		a *= a;
		n >>= 1; // bit全体を右に1つシフトして一番右を捨てる
	}
	return x;
}

int min(int a, int b) {
	return a < b ? a : b;
}

int main(void) {
	int n, k, i, j;
	n = getint();
	k = getint();
	double ans = 0;
	for (i = 1; i <= n; i++) {
		double probability = 1.0/n;
		j = i;
		while(j < k) {
			j *= 2;
			probability /= 2;
		}
		ans += probability;
	}

	printf("%.12f\n", ans);
	return 0;
}

int getint() {
	int i;
	scanf("%d", &i);
	return i;
}

long long getllint() {
	long long i;
	scanf("%lld", &i);
	return i;
}

double getdint() {
	double i;
	scanf("%lf", &i);
	return i;
}

char getch() {
	char c;
	scanf("%c", &c);
	return c;
}

void setstring(char *s) {
	scanf("%s", s);
}

void showint(int i) {
	printf("%d\n", i);
}

void showllint(long long i) {
	printf("%lld\n", i);
}

void showdouble(double i) {
	printf("%lf\n", i);
}

void showchar(char c) {
	printf("%c\n", c);
}

void showstring(char *s) {
	printf("%s\n", s);
}


Measured memory_bytes: 128
#include <iostream>
#include <cstdlib>
#include <cmath>

using namespace std;

int main(){
	int a;
	int b;
	int k;
	cin >> a >> b;
	k = a + b;
	if(k%2==0){
		cout << k/2 ;
	}
	else{
		cout << "IMPOSSIBLE";
	}
	return 0;
}

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

using namespace std;

int calc_diff(vector<int>& strength, int team) {

  int team_a = 0, team_b = 0;

  for (int i = 0; i < (int) strength.size(); i++) {
    if (team & 1) {
      team_a += strength[i];
    } else {
      team_b += strength[i];
    }
    team >>= 1;
  }

  return abs(team_a - team_b);
}

int main() {

  int size;
  while (cin >> size && size != 0) {

    vector<int> strength(size);
    for (int i = 0; i < size; i++) {
      cin >> strength[i];
    }

    int minDiff = INT_MAX;
    for (int i = 0; i < (1<<size); i++) {
      minDiff = min(minDiff, calc_diff(strength, i));
    }

    cout << minDiff << endl;
  }
  
  return 0;
}

Measured memory_bytes: 3096
import java.util.Scanner;

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

		char a = input.charAt(0);
		char b = input.charAt(1);
		char c = input.charAt(2);
		int flagA = 0;
		int flagB = 0;
		int flagC = 0;
		for (int i = 0; i <= 3; i++) {
			if (a == input.charAt(i)) {
				flagA++;
			}
		}
		for (int i = 0; i <= 3; i++) {
			if (b == input.charAt(i)) {
				flagB++;
			}
		}
		for (int i = 0; i <= 3; i++) {
			if (c == input.charAt(i)) {
				flagC++;
			}
		}

		if (flagA == 2 && flagB == 2 && flagC == 2) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}


Measured memory_bytes: 23892
/* BISMILLAHIR RAHMANIR RAHIM */
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
	ios_base :: sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int n, m;
	cin >> n >> m;
	vector< pair< ll, pair<int, int> > > edge;
	for(int i = 0, u, v, w; i < m; i++) {
		cin >> u >> v >> w;
		u--, v--;
		edge.push_back({-w, {u, v}});
	}
	
	const ll inf = 1e15;
	vector<ll> d(n, inf);
	d[0] = 0;
	bool negativeCycle = false;

	for(int i = 1; i <= n + n; i++) {
		for(auto& e : edge) {
			int u = e.second.first;
			int v = e.second.second;
			ll w = e.first;
			if( d[v] > d[u] + w ) {
				d[v] = d[u] + w;
				if( i >= n and v == n - 1 ) {
					negativeCycle = true;
				} 
			}
		}
	}
	if( negativeCycle ) cout << "inf\n";
	else                cout << -d[n - 1] << "\n";
}


Measured memory_bytes: 384
"use strict";
function Main(input) {
  input = input.split("\n");
  var [m1,d1] = input[0].trim().split(' ').map(Number);
  var [m2,d2] = input[1].trim().split(' ').map(Number);
  if (m1 === 12 && m2 === 1) {
    console.log(1);
  } else if (m2 - m1 === 1) {
    console.log(1);
  } else {
    console.log(0);
  }
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7500
import math

MOD = 10 ** 9 + 7


def cmb(n, r):
    total = 1
    for i in range(r):
        total *= (n - i) % MOD
    return total * pow(math.factorial(r), MOD - 2, MOD) % MOD


def calc(n, r):
    ret = 1
    for i in range(r):
        ret = ret * (n - i) % MOD
    return ret * pow(math.factorial(r), MOD - 2, MOD) % MOD


if __name__ == '__main__':
    n, a, b = list(map(int, input().split(" ")))

    total = pow(2, n, MOD)
    a_total = calc(n, a)
    b_total = calc(n, b)
    print((total - a_total - b_total - 1) % MOD)

Measured memory_bytes: 5444
import java.io.IOException;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		boolean isOK = true;
		for (int i = 0; i < n; i++) {
			int a = sc.nextInt();
			if (a % 2 == 0 && (a % 3 != 0 && a % 5 != 0)) {
				isOK = false;
			}
		}
		System.out.println(isOK ? "APPROVED" : "DENIED");
	}

}


Measured memory_bytes: 24916
#define _GLIBCXX_DEBUG
#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 pair<int, int> P;
typedef vector<vector<int>> Matrix;
static const int INF = 2000000000;



int main(){
  string s;
  cin >> s;
  string ans = "ABC"+s;
  cout << ans << endl;
}

Measured memory_bytes: 256
s=input()
sm=0
for i in range(1<<len(s)-1):
  j=0
  st=0
  while j<len(s):
    if (i>>j)&1 ==1:
      sm+=int(s[st:j+1])
      st=j+1  
    j+=1
  sm+=int(s[st:])
  
print(sm)

Measured memory_bytes: 9200
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
const int inf = 1e9;

struct segmentTree{
    vector<int> node;
    int n;
    
    segmentTree(vector<int> v){
        int s = v.size();
        n = 2;
        while(n < s) n *= 2;
        node = vector<int>(2*n -1, inf);
        for(int i=0; i<s; i++){
            node[i +n-1] = v[i];
        }
        for(int i=n-2; i>=0; i--){
            node[i] = min(node[2*i +1], node[2*i +2]);
        }
    }
    segmentTree(){}
    
    void Set(int val, int pos){
        int idx = n-1 + pos;
        node[idx] = val;
        do{
            idx = (idx -1)/2;
            node[idx] = min(node[2*idx +1], node[2*idx +2]);
        }while(idx != 0);
    }
    int pGet(int pos){
        return node[pos +n-1];
    }
    int Get(int l, int r){
        if(l == r) return inf;
        return _get(l, r, 0, 0, n);
    }
    int _get(int l, int r, int k, int cl, int cr){
        if(l <= cl && cr <= r){
            return node[k];
        }
        if(r <= cl || cr <= l){
            return inf;
        }
        int m = (cl +cr)/2;
        return min(_get(l, r, 2*k+1, cl, m), _get(l, r, 2*k+2, m, cr));
    }
};


int main(){
    int n;
    cin >> n;
    segmentTree segtree(vector<int>(n+1, 0));
    int coins = 0;
    for(int i=0; i<n; i++){
        int x;
        cin >> x;
        if(segtree.pGet(0) == 1){
            cout << "No" << endl;
            continue;
        }
        if(x >= n){
            cout << "Yes" << endl;
            segtree.Set(1, n);
            coins++;
            continue;
        }
        if(segtree.pGet(x) == 0){
            segtree.Set(1, x);
            cout << "Yes" << endl;
            coins++;
        }else{
            if(segtree.Get(1, x) == 0 || coins==x){
                coins++;
                for(int j=x; j>=0; j--){
                    if(segtree.pGet(j) == 0){
                        segtree.Set(1, j);
                        break;
                    }else{
                        segtree.Set(0, j);
                        coins--;
                    }
                }
                cout << "Yes" << endl;
            }else{
                cout << "No" << endl;
            }
        }
    }
    return 0;
}



Measured memory_bytes: 12748
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    long long a[90];
    a[0]=2;
    a[1]=1;
    a[2]=3;
    for(int i=3;i<=n;i++)
    {
        a[i]=a[i-1]+a[i-2];
    }
    cout<<a[n]<<endl;
}

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

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define INF 1000000007LL
#define all(x) x.begin(),x.end()
#define rep(i,a,b) for(i=a;i<=b;i++)

#define cil(a,b) ( ((a)%(b) == 0)?((a)/(b)):((a)/(b)+1) )

typedef long long ll;
typedef double db;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
typedef vector<pii> vii;

ll mypow(ll a, ll b) { if(b == 0) return 1; ll temp=mypow(a,b/2); temp=(temp*temp)%INF; if(b%2 == 1) temp=(a*temp)%INF; return temp; }
int mygcd(int a, int b) { if(b==0) return a; return mygcd(b,a%b); }
int cntBits(ll a) { int ret=0; while(a>0) { ret++; a/=2; } return ret; }

int main()
{
	ios::sync_with_stdio(0);
	int tt=1,tcase; 
	//cin >> tt;
	rep(tcase,1,tt)
	{
		int a,b,t,ans=0; cin >> a >> b >> t;
		for(int i=a;i<=t;i+=a) ans+=b;
		cout << ans << "\n";
	}
	return 0;
}


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

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

using ll = long long;
using ld = long double;
ll INF = LLONG_MAX;

using vi = vector<int>;
using vll = vector<ll>;
using pii = pair<int, int>;

namespace output {
	void pr(int x) { cout << x; }
	void pr(long x) { cout << x; }
	void pr(ll x) { cout << x; }
	void pr(unsigned x) { cout << x; }
	void pr(unsigned long x) { cout << x; }
	void pr(unsigned long long x) { cout << x; }
	void pr(float x) { cout << x; }
	void pr(double x) { cout << x; }
	void pr(ld x) { cout << x; }
	void pr(char x) { cout << x; }
	void pr(const char* x) { cout << x; }
	void pr(const string& x) { cout << x; }
	void pr(bool x) { pr(x ? "true" : "false"); }
	template<class T> void pr(const complex<T>& x) { cout << x; }
	
	template<class T1, class T2> void pr(const pair<T1,T2>& x);
	template<class T> void pr(const T& x);
	
	template<class T, class... Ts> void pr(const T& t, const Ts&... ts) { 
		pr(t); pr(ts...); 
	}
	template<class T1, class T2> void pr(const pair<T1,T2>& x) { 
		pr("{",x.f,", ",x.s,"}"); 
	}
	template<class T> void pr(const T& x) { 
		pr("{"); // const iterator needed for vector<bool>
		bool fst = 1; for (const auto& a: x) pr(!fst?", ":"",a), fst = 0; 
		pr("}");
	}
	
	void print() { pr("\n"); } // print w/ spaces
	template<class T, class... Ts> void print(const T& t, const Ts&... ts) { 
		pr(t); if (sizeof...(ts)) pr(" "); print(ts...); 
	}
}

using namespace output;

int main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	ll N, A, B, C, D; cin >> N >> A >> B >> C >> D;
	F0R(i, N) {
		ll hi = A + i * -C + (N - i - 1) * D;
		ll lo = A + i * -D + (N - i - 1) * C;
		if (hi >= B && B >= lo) {
			print("YES");
			return 0;
		}
	}
	print("NO");
}

Measured memory_bytes: 384
N,M = map(int,input().split())
X = list(map(int,input().split()))
if N >= M:
    print(0)
    exit()
X.sort()
A = []
for i in range(M-1):
    A.append(X[i+1]-X[i])
A.sort()
print(sum(A[:M-N]))

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

typedef struct dice_tag{
	int num[7];
} dice_t;


void north(dice_t *dice)
{
	int tmp = dice->num[1];
	dice->num[1] = dice->num[2];
	dice->num[2] = dice->num[6];
	dice->num[6] = dice->num[5];
	dice->num[5] = tmp;
}

void south(dice_t *dice)
{
	int tmp = dice->num[1];
	dice->num[1] = dice->num[5];
	dice->num[5] = dice->num[6];
	dice->num[6] = dice->num[2];
	dice->num[2] = tmp;
}

void west(dice_t *dice)
{
	int tmp = dice->num[1];
	dice->num[1] = dice->num[3];
	dice->num[3] = dice->num[6];
	dice->num[6] = dice->num[4];
	dice->num[4] = tmp;
	
}

void east(dice_t *dice)
{
	int tmp = dice->num[1];
	dice->num[1] = dice->num[4];
	dice->num[4] = dice->num[6];
	dice->num[6] = dice->num[3];
	dice->num[3] = tmp;

}



int main(void)
{
	dice_t dice;

	for(int i = 1; i <= 6; i++) scanf("%d", &dice.num[i]);

	char order[128];
	scanf("%s", order);

	int i = 0;
	while(order[i] != '\0')
	{
		if(order[i] == 'N') north(&dice);
		else if(order[i] == 'S') south(&dice);
		else if(order[i] == 'W') west(&dice);
		else east(&dice);
		i++;
	}

	printf("%d\n", dice.num[1]);
	
	return 0;
}


Measured memory_bytes: 3224
#pragma GCC optimize("O3")

#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <string>
#include <assert.h>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <random>
#include <cmath>
#include <chrono>
#include <bitset>

#define ld long double
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()

#define int long long
using namespace std;

const int INF = 2e18;
const int MOD = 1e9 + 7;
const int MB = 20;

void solve() {
	int n;
	cin >> n;
	int ans = 0;
	int k;
	cin >> k;
	for (int i = 0; i < n; i++) {
		int x;
		cin >> x;
		if (x >= k) ans++;
	}
	cout << ans;
}
signed main() {
	/*
	freopen("search.in", "r", stdin);
	freopen("search.out", "w", stdout);
	*/
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	cout.precision(12);
	solve();
}

Measured memory_bytes: 256
// Last Change: 03/28/2019 18:39:19.
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

namespace NS {
void LoopUntilZeroInpput() {
  int hogegegege = 0;
  while (cin >> hogegegege && hogegegege != 0) {
  }
}
} // namespace NS

int main() {
  ll N;
  cin >> N;

  ll ipt, cnt;
  for (ll i = cnt = 0; i < N; ++i) {
    cin >> ipt;
    while (ipt % 2 == 0) {
      ipt /= 2;
      ++cnt;
    }
  }

  cout << cnt << endl;

  NS::LoopUntilZeroInpput();
}


Measured memory_bytes: 256
main(){double a,b,c,d,e,f,g,h;for(scanf("%lf",&a);~scanf("%lf%lf%lf%lf%lf%lf%lf%lf",&a,&b,&c,&d,&e,&f,&g,&h);)puts(fabs((c-a)*(h-f)-(d-b)*(g-e))>1e-12?"NO":"YES");exit(0);}

Measured memory_bytes: 612
s = input()

import numpy as np

s = np.array(list(s))
ans1 = []
ans2 = []
for i in range(len(s)):
    if i%2:
        ans1.append("0")
        ans2.append("1")
    else:
        ans1.append("1")
        ans2.append("0")

print(min(sum(s==ans1), sum(s==ans2)))


Measured memory_bytes: 21404
#include "bits/stdc++.h"
using namespace std;
#define repi(i,a,b) for(int i=(a), i##_len=(b); i<i##_len; ++i)
#define rep(i,n) repi(i,0,n)
#define repi_(i,a,b) for(int i=(a), i##_len=(b); i<=i##_len; ++i)
#define rep_(i,n) repi_(i,0,n)
#define all(x) (x).begin(),(x).end()
#define vsort(v) sort((v).begin(), (v).end())
#define gsort(v) tsort(v); reverse((v).begin(), (v).end())
#define vrev(v) reverse((v).begin(), (v).end())
#define siz(v) ((int)(v).size())
#define ers(v, n) (v).erase((v).begin() + n)
#define cnt(v, n) count(all(v), n)
#define vmin(v) *min_element(v.begin(), v.end())
#define vmax(v) *max_element(v.begin(), v.end())
#define el "\n"
#define co(x) cout<<(x)<<el
#define coc(c, a, b) if(c)co((a));else co((b))
#define cosp(x) cout<<(x)<<' '
#define YES(c) coc(c,"YES", "NO")
#define Yes(c) coc(c,"Yes", "No")
#define yes(c) coc(c,"yes", "no")
#define POSSIBLE(c) coc(c, "POSSIBLE", "IMPOSSIBLE")
#define Possible(c) coc(c, "Possible", "Impossible")
#define possible(c) coc(c, "possible", "impossible")
#define inf INT_MAX
#ifdef tqktmp_2
#define gc() getchar(); getchar()
#else
#define gc() 1
#endif


typedef long long lint;

lint dx[8] = { 0,1,1,1,0,-1,-1,-1 },
dy[8] = { 1,1,0,-1,-1,-1,0,1 };

template<class T>inline bool maxi(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>inline bool mini(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }



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

	lint w, a, b; cin >> w >> a >> b;
	if ((a + w > b&&a < b + w) || (b < a + w && a < b + w))co(0);
	else co(min(abs(a - b - w), abs(b - a - w)));
	gc();
}


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

int main(){
    ll n;
    cin >> n;
    vector <ll> a(n);
    ll ans3=0,ans2;
    rep(i,n){
        cin >> a[i];
        ans3+=a[i];
    }
    vector <vector <ll>> ans(n-1, vector <ll> (2));
    sort(a.begin(),a.end());
    
        rep(i,n-2){
            if(a[i+1]>=0){
                ans[i][0]=a[0];
                ans[i][1]=a[i+1];
                a[0]-=a[i+1];
            }
            else{
                ans[i][0]=a[n-1];
                ans[i][1]=a[i+1];
                a[n-1]-=a[i+1];
            }
        }
        ans[n-2][0]=a[n-1];
        ans[n-2][1]=a[0];
        ans2=a[n-1]-a[0];
    

    cout << ans2 << endl;
    rep(i,n-1){
        cout << ans[i][0] << " " << ans[i][1] << endl;
    }

    
    

    return 0;
}

Measured memory_bytes: 8192
#include <bits/stdc++.h>
#define GET_MACRO(_1,_2,_3,_4,_5,NAME,...) NAME
#define pr(...) GET_MACRO(__VA_ARGS__,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__)
#define pr1(a) (#a)<<"="<<(a)
#define pr2(a,b) pr1(a)<<", "<<pr1(b)
#define pr3(a,b,c) pr2(a,b)<<", "<<pr1(c)
#define pr4(a,b,c,d) pr3(a,b,c)<<", "<<pr1(d)
#define pr5(a,b,c,d,e) pr4(a,b,c,d)<<", "<<pr1(e)
#define int long long
#define double long double
using namespace std;
const int N = 1000 * 50 + 1;
const int INF = 1LL<<55;
const int mod = (1e9)+7;
const double EPS = 1e-8;
const double PI = 6.0 * asin(0.5);
typedef pair<int,int> P;
typedef long long ll;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
ostream& operator<<(ostream& o,P p){return o<<"("<<p.first<<","<<p.second<<")";}
istream& operator>>(istream& i,P &p){return i>>p.first>>p.second;}
ostream& operator<<(ostream& o,vector<auto> &a){int i=0;for(auto t:a)o<<(i++?" ":"")<<t;return o;}
istream& operator>>(istream& i,vector<auto> &a){for(auto &t:a)i>>t;return i;}
void prArr(auto a,string s=" "){int i=0;for(auto t:a)cout<<(i++?s:"")<<t;cout<<endl;}

class CumulativeSum{
public:
  vector<int> sum;
  CumulativeSum(){}
  CumulativeSum(vector<int> A){
    int n = A.size();
    sum.resize(n+1,0);
    for(int i=1;i<=n;i++) sum[i] += sum[i-1] + A[i-1];
  }
  int get(int l,int r){assert(l>=0 && r<=(int)sum.size());return sum[r] - sum[l];} //[l,r)
};


int n;
vector<int> A;
CumulativeSum Sum;

signed main(){
  cin>>n;
  A.resize(n);
  cin>>A;
  Sum = CumulativeSum(A);
  
  vector<vector<int> >dp(n+1,vector<int>(N,-INF));
  dp[0][0] = INF;
  
  for(int i=0;i<n;i++){
    for(int mx = 0;mx < N; mx++){
      if(dp[i][mx] == -INF) continue;
      for(int k=i;k<n;k++){
        if(i == 0 && k == n-1) continue;
        int sum = Sum.get(i,k+1);
        int nmx = max(mx,sum);
        int na = min(dp[i][mx],sum);
        Max(dp[k+1][nmx] ,na);
      }
    }
  }

  int ans = INF;
  for(int i=0;i<N;i++) if(dp[n][i] != -INF)  Min(ans, i - dp[n][i]);
  cout<<ans<<endl;
  
  return 0;
}



Measured memory_bytes: 23204
n = int(input())
xy = [tuple(map(int, input().split())) for _ in range(n)]
s_xy = set(xy)

count = 0
for i in range(n-1):
    for j in range(i+1, n):
        p, q = xy[j][0] - xy[i][0], xy[j][1] - xy[i][1]
        tc = sum((x-p,y-q) in xy for x, y in s_xy)
        if count <= tc:
            count = tc
            
print(n-count)

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


int main()
{
    ll l,r;
    cin >> l >> r;
    ll ans=2018;

    for(ll i=l; i<r; i++){
        if(ans==0) break;
        for(ll j=l+1; j<r+1; j++){
            ans = min(ans,(((i%2019)*(j%2019))%2019));
            if(ans==0) break;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	auto len = [](long long x){
		int r = 0;
		while(x) x /= 10, r++;
		return r;
	};
	long long n; cin >> n;
	int ans = len(n);
	for(int i = 1; i <= 1'000'000; i++) if(!(n%i)) ans = min(ans, max(len(i), len(n/i)));
	cout << ans << endl;
	return 0;
}


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

int main() {
  long n, cnt = 0;

  cin >> n;

  for (int i = 0; i < n; i++) {
    long temp;
    cin >> temp;
    while (temp % 2 == 0 && temp > 1) {
      cnt++;
      temp /= 2;
    }
  }

  cout << cnt << endl;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cassert>
#include <cstring>
#include <climits>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define mp make_pair
#define fi first
#define se second
#define pb push_back

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

constexpr ll INF = 1e18;
constexpr ll MOD = 1e9 + 7;
constexpr double PI = 3.14159265358979323846;
constexpr int di[] = {0, 0, 1, -1};
constexpr int dj[] = {1, -1, 0, 0};

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

    int n, a[112345], b[112345];

    ll as = 0, bs = 0;

    cin >> n;
    REP(i, n)
    cin >> a[i], as += a[i];
    REP(i, n)
    cin >> b[i], bs += b[i];

    if (as < bs)
    {
        cout << -1 << endl;
        return 0;
    }

    V v;

    ll need = 0;
    int needNum = 0;
    REP(i, n)
    {
        if (a[i] < b[i])
        {
            need += (b[i] - a[i]);
            needNum++;
        }
        else
        {
            v.push_back(a[i] - b[i]);
        }
    }

    SORT(v);

    int res = needNum;

    int i = v.size() - 1;
    while (need > 0)
    {
        res++;
        need -= v[i];
        i--;
    }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 1660
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define pi pair<ll, ll>
#define mp make_pair
#define pb push_back
#define vi vector<ll>
#define pd pair<double, double>
#define vp vector<pi>
#define f(i, n) for(int i = 0; i < n; i++)
#define fo(i, a, n) for(int i = a; i < n; i++)
#define mod (1000*1000*1000+7)
#define sz(x) int((x).size())
#define all(x) x.begin(),x.end()
#define DBG(v) cerr << #v << " = " << (v) << endl;
ll INF = (1ll<<61);

using namespace std;

int main(int argc, char* argv[])
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int n; cin >> n;
    int x = 1;
    int ans = 0;
    f(i, n){
      int a; cin >> a;
      if(a == x) x++;
      else ans++;
    }
    cout <<  (ans == n?-1:ans) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <vector>

using namespace std;

// BEGIN NO SAD
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
typedef vector<int> vi;
// END NO SAD

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

void solve() {
  int n;
  cin >> n;
  for(int x = 1; x <= 100000; x++) {
    if((int)(1.08*x) == n) {
      cout << x << "\n";
      return;
    }
  }
  cout << ":(\n";
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  solve();
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
string S;
string words[4] = {"dream","dreamer","erase","eraser"};
bool dp[110000] = {false}; // dp[i] : i番目までの文字列が作れるか？


int main(){
    cin >> S;
    dp[0] = true;
    for(int i=0;i<S.size();++i){
        if(!dp[i]) continue;
        for(string s : words){
            if(S.substr(i,s.size())==s) dp[i+s.size()] = true;
        }
    }
    cout << (dp[S.size()] ? "YES" : "NO") << endl;
    return 0;
}


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

using namespace std;

int main() {
    int ans = 0;
    string s, r;
    while (cin >> s) {
        r = s;
        reverse(r.begin(), r.end());
        if (s == r) {
            ans++;
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1192
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define INF 0x6fffffff
#define INFL 0x6fffffffffffffffLL

int main() {
	ll		a,b,c,d,i,j,k,n,m,x,y,ans = 0;
	string	s;

	cin >> a >> b >> c >> d;
	
	while(1) {
		c = c - b;
		if (c<=0) {
			cout << "Yes" << endl;
			return 0;
		}
		a = a - d;
		if (a<=0) {
			cout << "No" << endl;
			return 0;
		}
	}


}


Measured memory_bytes: 3612
/*...................bismillahir rahmanir rahim.....................*/
/*
  author :
    Muhammad Najmul hasan Nayeem
    Sust Math 17
*/
// #pragma comment(linker, "/stack:200000000")
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
// #pragma GCC optimize("unroll-loops")

#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/trie_policy.hpp>
// using namespace __gnu_pbds;
 
using namespace std;

#define m_p make_pair
#define PB push_back
#define eb emplace_back
#define FF first
#define SS second
#define MX5 100005
#define MX6 1000006
#define MOD 1000000007
#define in()({int a;scanf("%d",&a);a;})
#define SI(a) scanf("%d",&a)
#define SII(a,b) scanf("%d%d",&a,&b)
#define SIII(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define SC()({char a;scanf("%c",&a);a;})
#define SL()({long long a;scanf("%lld",&a);a;})
#define SD()({double a;scanf("%f",&a);a;})
#define nl '\n'
#define For(_,n) for(int i=_;i<=n;i++)
#define once "once upon a time\n"
#define FI freopen("input.txt","r+",stdin);
#define FO freopen("output.txt","w+",stdout);
 
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> PII;
typedef pair<string,string> PSS;
// typedef tree<PII,null_type,less<PII>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

template <class A, class B> ostream& operator << (ostream& out, const pair<A, B> &a) {
    return out << "(" << a.FF << ", " << a.SS << ")";
}
 
template <class A> ostream& operator << (ostream& out, const vector<A> &v) {
    out << "[";
    for(int i=0;i<v.size();i++) {
        if(i) out << ", ";
        out << v[i];
    }
    return out << "]";
}
 
#define chk(a) cout<<(#a)<<" = "<<a<<endl;
#define chka(a,_) cout<<(#a)<<"["<<_<<"] = "<<a[_]<<"\n";

// int Set(int n,int pos){ return n | (1<<pos); }
// int Reset(int n,int pos){ return n=n & ~(1<<pos); }
// bool Check(int n,int pos){ return (bool)(n & (1<<pos)); }
 
/*............start.............*/

void solve()
{
    int n;
    cin>>n;
    int mx=0;
    LL res=0;
    for(int i=0;i<n;i++)
    {
        int x;
        cin>>x;
        if(x>=mx) mx=x;
        else res+=(mx-x);
    }
    cout<<res<<nl;
}
int main()
{
    // clock_t time_start=clock();
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    int q=1;
    // cin>>q;
    // SI(q);
    for(int kase=1;kase<=q;kase++)
    {
        // cout<<"Case "<<kase<<": ";
        // printf("Case %d: ",kase );
        solve();
    }
    // clock_t time_end=clock();
    // cerr<<float((time_end-time_start)/CLOCKS_PER_SEC);
    return 0;
}


Measured memory_bytes: 3608
package main

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

func main() {
	n := readInt()
	c := readBytes()

	ans := 0
	l, r := 0, n-1
	for {
		for l < r && c[l] != 'W' {
			l++
		}
		for l < r && c[r] != 'R' {
			r--
		}
		if l >= r {
			break
		}
		c[l], c[r] = c[r], c[l]
		ans++
	}

	fmt.Println(ans)
}

var (
	readString func() string
	readBytes  func() []byte
)

func init() {
	log.SetFlags(log.Lshortfile)
	readString, readBytes = newReadString(os.Stdin)
}

func newReadString(ior io.Reader) (func() string, func() []byte) {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	f1 := func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
	f2 := func() []byte {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Bytes()
	}
	return f1, f2
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readInt() int {
	return int(readInt64())
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(readString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func sum(a []int) int {
	var ret int
	for i := range a {
		ret += a[i]
	}
	return ret
}

func sumFloat64(a []float64) float64 {
	var ret float64
	for i := range a {
		ret += a[i]
	}
	return ret
}

func gcd(m, n int) int {
	for m%n != 0 {
		m, n = n, m%n
	}
	return n
}

func lcm(m, n int) int {
	return m / gcd(m, n) * n
}


Measured memory_bytes: 2244
#include<bits/stdc++.h>
using namespace std;
int n,m,a[111111],memo[111111];
int dp(int x){
  int ret=0;
  if(memo[x]!=-1) return memo[x];
  if(x==n-1) return 0;
  for(int i=1;i<=min(m,n-1-x);i++){
    if(i==1) ret=dp(x+i)+abs(a[x]-a[x+i]);
    else ret=min(ret,dp(x+i)+abs(a[x]-a[x+i]));
  }
  return memo[x]=ret;
}
int main(){
  memset(memo,-1,sizeof(memo));
  cin>>n>>m;
  for(int i=0;i<n;i++) cin>>a[i];
  cout<<dp(0)<<endl;
  return(0);
}


Measured memory_bytes: 8832
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for (int i = (int)(s); i < (int)(n); i++)
const ll mod = ll(1e9) + 7;
const int INF = int(1e9);
int main()
{
    int A, B, C;
    cin >> A >> B >> C;
    if (A == B && B == C)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
from operator import itemgetter


N, M = list(map(int, input().split()))

a = []
for i in range(N):
    a.append(list(map(int, input().split())))

def main():
    b = sorted(a, key=itemgetter(0))
    # print(b)
    m = 0
    cost = 0
    for i in range(N):
        # print(b[i])
        if (m + b[i][1]) <= M:
            m += b[i][1]
            cost += (b[i][0] * b[i][1])
        else:
            cost += (b[i][0] * (M-m))
            return cost
    return cost

print(main())


Measured memory_bytes: 29864
#include <stdio.h>

struct Card{char suit;int value;};

void bubble(struct Card  A[],int N){
	int i,j;
	for(i=0;i<N;i++){
		for(j=N-1;j>=i+1;j--){
			if(A[j].value < A[j-1].value){
				int t=A[j].value;
				A[j].value=A[j-1].value;
				A[j-1].value=t;
				
				char s=A[j].suit;
				A[j].suit=A[j-1].suit;
				A[j-1].suit=s;
			}
		}
	}
}

void selection(struct Card  A[],int N){
	int i,j,minj;
	for(i=0;i<N;i++){
		minj=i;
		for(j=i;j<N;j++){
			if(A[j].value < A[minj].value){
				minj=j;
			}
		}
		int t = A[i].value;
		A[i].value=A[minj].value;
		A[minj].value=t;
		
		char s=A[i].suit;
		A[i].suit=A[minj].suit;
		A[minj].suit=s;
	}
}

int main(void){
	int N,i;
	struct Card C1[36],C2[36]; 
	
	scanf("%d ",&N);
	for(i=0;i<N;i++){
		scanf(" %c%d",&C1[i].suit,&C1[i].value);
	}
	
	for(i=0;i<N;i++){
		C2[i]=C1[i];
	}
	
	bubble(C1,N);
	selection(C2,N);
	
	for(i=0;i<N;i++){
		if(i>0){
			printf(" ");
		}
		printf("%c%d",C1[i].suit,C1[i].value);
		
	}
	
	printf("\n");
	
	printf("Stable\n");
	
	for(i=0;i<N;i++){
		if(i>0){
			printf(" ");
		}
		printf("%c%d",C2[i].suit,C2[i].value);
	}
	
	printf("\n");
	
	for(i=0;i<N;i++){
		if(C1[i].suit!=C2[i].suit){
			printf("Not stable\n");
			break;
		}
		if(i==N-1){
			printf("Stable\n");
		}
	}
	
	return 0;
}


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

constexpr int MOD = 998244353;

int main() {
    int N, S; cin >> N >> S;
    vector<ll> A(N); for (int i = 0; i < N; i++) cin >> A[i];

    vector<vector<ll>> memo(N, vector<ll>(3001, 0));

    ll ans = 0;
    memo[0][A[0]] = 1;
    if (A[0] == 0) ans += N;
    for (int i = 1; i < N; i++) {
        if (S == A[i]) {
            ans += ((N-i) * (i+1)) % MOD;
            ans %= MOD;
        } else if (S > A[i]) {
            ans += (memo[i-1][S-A[i]] * (N-i)) % MOD;
            ans %= MOD;
        }
        for (int j = 1; j < S+1; j++) {
            if (j > A[i]) {
                if (memo[i-1][j-A[i]] != 0) memo[i][j] = memo[i-1][j] + memo[i-1][j-A[i]];
                else memo[i][j] = memo[i-1][j];
            } else if (j == A[i]) {
                memo[i][j] = memo[i-1][j] + i + 1;
            } else {
                memo[i][j] = memo[i-1][j];
            }
            memo[i][j] %= MOD;
        }
    }
    cout << ans << endl;
}


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

def check(l,r,k,s,acc):
    cnt = acc[r] - acc[l]
    if l>0 and s[l]=="0":
        cnt += 1
    return cnt<=k

def f(n,k,s):
    acc = [0]*(n+1)
    for i in range(n):
        if i==0:
            if s[i]=="0":
                acc[i+1] = 1
        else:
            if s[i]=="0" and s[i-1]=="1":
                acc[i+1] = acc[i]+1
            else:
                acc[i+1] = acc[i]

    left = 0
    right = 0
    res = -1
    while left<n:
        while right<n and check(left,right+1,k,s,acc):
            right += 1

        res = max(res, right-left)

        if left==right:
            right += 1

        left += 1

    return res

if __name__ == '__main__':
    n,k = map(int, input().split())
    s = input()
    print(f(n,k,s))


Measured memory_bytes: 5560