akhauriyash/Code-Regression huggingface dataset:
h,n = map(int, input().split())
magic = []
INF = 10**8
dp = [[INF for j in range(h+1)] for i in range(n+1)] #体力がjのモンスターをi番目の魔法までを使って倒せる消費魔力の最小値
 
for i in range(n):
    a,b = map(int, input().split())
    magic.append([a, b])
 
for i in range(n):
    for j in range(h):
        if j+1 > magic[i][0]:
            dp[i+1][j+1] = min(dp[i][j+1], dp[i][j+1-magic[i][0]] + magic[i][1], dp[i+1][j+1-magic[i][0]] + magic[i][1])
        else:
            dp[i+1][j+1] = min(dp[i][j+1], magic[i][1])
            
print(dp[n][h])

Measured memory_bytes: 125532
#include <stdio.h>
 
int main(void){
    char blood[3];
    int a=0,b=0,o=0,ab=0;
    while(scanf("%*d,%s",blood)!=EOF){
        if(blood[1]=='B')ab++;
        else if(blood[0]=='A')a++;
        else if(blood[0]=='B')b++;
        else if(blood[0]=='O')o++;
    }
    printf("%d\n%d\n%d\n%d\n",a,b,ab,o);
    return 0;
}

Measured memory_bytes: 596
#!/usr/bin/env python3
# coding=utf-8

import sys

n, y = map(int, sys.stdin.readline().strip().split(" "))
currents = [10000, 5000, 1000]
flag = True
for i in range(0, n + 1):
    for j in range(0, n + 1 - i):
        if flag and currents[0] * i + currents[1] * j + currents[2] * (n - i - j) == y:
            print("{} {} {}".format(i, j, n - i - j))
            flag = False
if flag:
    print("-1 -1 -1")


Measured memory_bytes: 3060
#define X (x-P>0?x-P:P-x)
#define Y (y-Q>0?y-Q:Q-y)
#define N (P<x?1:-1)
#define M (Q<y?1:-1)
#define p(x,y) (A[++S]=x,B[S]=y) 
t,k,x,y,P,Q,S,i=1,A[1<<20],B[1<<20];main(){scanf("%d%d%d",&k,&x,&y);!(k&1)&&(x+y&1)&&(exit(puts("-1")&0),0);while(X+Y>k*2)X>k?(P+=k*N):(Q+=k*M),p(P,Q);if(X+Y!=k){(k%2&&(X+Y)%2)&&(Y<=k?(P+=(k-Y)*N,Q=y):(Q+=(k-X)*M,P=x),p(P,Q));t=k*2-X-Y>>1,X<Y?p(x+t*N,Q+(k-X-t)*M):p(P+(k-Y-t)*N,y+t*M);}p(x,y),printf("%d\n",S);for(;i<=S;)printf("%d %d\n",A[i++],B[i]);}

Measured memory_bytes: 4864
#include <bits/stdc++.h>
using namespace std;
#define LL long long
const LL mod = 1e9+7;
const LL k = 1e9;
int ans = 0;
LL a, b, c;
set<LL> s;
LL id (LL a, LL b, LL c) {
    LL ret = 0;
    ret = (ret + (((a*k)%mod)*k%mod))%mod;
    ret = (ret + (b*k)%mod)%mod;
    ret = (ret + c)%mod;
    return ret;
}
int main () {
    scanf ("%lld%lld%lld", &a, &b, &c);
    s.insert (id(a, b, c));
    while (a%2==0&&b%2==0&&c%2==0) {
        LL na, nb, nc;
        na = (b+c)/2;
        nb = (a+c)/2;
        nc = (a+b)/2;
        a = na; b = nb; c = nc;
        if (s.count (id(a, b, c))) {
            ans = -1;
            break;
        }
        ans++;
    }
    printf ("%d\n", ans);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  rep(i, N) {
    REP(j, i+1, N) {
      int x = i^j;
      rep(k, 10) {
        if((x>>k)&1) {
          cout << k+1 << ' ';
          break;
        }
      }
    }
    cout << "\n";
  }
  return 0;
}


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

int main() {
  
  char c;
  cin >> c;
  if((c=='a'||c=='i')||((c=='u'||c=='e')||c=='o'))
    cout<< "vowel"<< endl;
  else
    cout << "consonant" <<endl;
}



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

int main() {
	int d, n;
	cin >> d >> n;
	int ans = pow(100, d);
	if (n != 100) {
		ans *= n;
	}
	else {
		ans *= n + 1;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
if __name__ == "__main__":
    # 入力パターン．
    # 先に要素数Nが与えられて，その数読み込むパターン
    ### N
    ### d_1 
    ### ...
    ### d_N
    N = int(input())
    d = [str(input()) for _ in range(N)]
    print(len(set(d)))


Measured memory_bytes: 35632
package main

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

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.ParseInt(sc.Text(), 10, 64)
	if e != nil {
		panic(e)
	}
	return int(i)
}

func nextInt64() int64 {
	sc.Scan()
	i, e := strconv.ParseInt(sc.Text(), 10, 64)
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	n := nextInt()
	yes := "Yes"
	no := "No"

	if n == 1 {
		fmt.Println(yes)
		return
	}

	nn := make([]int64, 0, n)
	for i := 0; i < n; i++ {
		nn = append(nn, nextInt64())
	}

	nn = append(nn, 1000000000)

	for i := 0; i < n; i++ {
		// if i+1 == n {
		// 	break
		// }
		if nn[i+1] == nn[i] {
			continue
		}
		if nn[i+1]-1 < nn[i] {
			// fmt.Printf("%#v %#v %#v\n", i, nn[i+1], nn[i])
			fmt.Println(no)
			return
		}

		if nn[i+1] > nn[i] {
			nn[i+1]--
		}
	}

	fmt.Println(yes)
}


Measured memory_bytes: 4096
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vd = vector<double>;
using vvd = vector<vd>;
using vl = vector<ll>;
using vvl = vector<vl>;
using pii = pair<int, int>;
using vs = vector<string>;
#define rep(i,n) range(i,0,n)
#define range(i,a,n) for(int i=a;i<n;i++)
#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI 3.141592653589793

template<class S, class T>ostream&operator<<(ostream&os, pair<S, T>p)
{
	os << "[" << p.first << "," << p.second << "]"; return os;
}
template<class S>auto&operator<<(ostream&os, vector<S>t)
{
	bool a = 1; for (auto s : t) { os << (a ? "" : " ") << s; a = 0; }
	return os;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int h,w;
	while (cin >> h>>w, h) {
		vvi f(h, vi(w));
		vvi fsum(h+1, vi(w+1,0));
		rep(i, h)rep(j, w)cin >> f[i][j];
		int MIN[10][10][10][10];
		int MAX[10][10][10][10];
		rep(i, 10)rep(j, 10)rep(k, 10)rep(l, 10)MIN[i][j][k][l] = 0;
		rep(i, 10)rep(j, 10)rep(k, 10)rep(l, 10)MAX[i][j][k][l] = 0;
		rep(i, h)rep(j, w) {
			MIN[i][j][i][j] = f[i][j];
			MAX[i][j][i][j] = f[i][j];
			fsum[i + 1][j + 1] = f[i][j];
		}
		range(i,0, h + 1)range(j, 1, w + 1)fsum[i][j] += fsum[i][j - 1];
		range(i,1, h + 1)range(j, 0, w + 1)fsum[i][j] += fsum[i-1][j];
		//for (auto l : fsum)cout << l << endl;

		range(ylen,0,  h) rep(y, h - ylen ) {
			range(xlen,0, w ) rep(x, w - xlen) {
				if (ylen + xlen == 0)continue;
				//cout << pii(y, x) << "," << pii(y + ylen, x + xlen) << ":";
				if (ylen != 0) {
					MIN[y][x][y + ylen][x + xlen] = min(MIN[y][x][y + ylen - 1][x + xlen], MIN[y + ylen][x][y + ylen][x + xlen]);
					MAX[y][x][y + ylen][x + xlen] = max(MAX[y][x][y + ylen - 1][x + xlen], MAX[y + ylen][x][y + ylen][x + xlen]);
				}
				else {
					MIN[y][x][y + ylen][x + xlen] = min(MIN[y][x][y + ylen][x + xlen - 1], MIN[y + ylen][x + xlen][y + ylen][x + xlen]);
					MAX[y][x][y + ylen][x + xlen] = max(MAX[y][x][y + ylen][x + xlen - 1], MAX[y + ylen][x + xlen][y + ylen][x + xlen]);
				}
			}
		}
		int ans = 0;
		rep(ay, h)rep(ax, w)range(by,ay+2, h)range(bx,ax+2, w) {
			int inner = MAX[ay+1][ax+1][by-1][bx-1];
			int outer = INF;
			outer = min(outer, MIN[ay][ax][ay][bx]);
			outer = min(outer, MIN[ay][ax][by][ax]);
			outer = min(outer, MIN[ay][bx][by][bx]);
			outer = min(outer, MIN[by][ax][by][bx]);
			//cout << pii(ay, ax) << pii(by, bx) << outer << "," << inner << endl;
			if (outer > inner) {
				int high = fsum[by][bx] + fsum[ay + 1][ax + 1] - fsum[by][ax + 1] - fsum[ay + 1][bx];
				ans = max(ans, (by-ay-1)*(bx - ax - 1)*outer-high);
				//cout << pii(by, bx) << pii(ay, ax) << "=" << fsum[by][bx] + fsum[ay + 1][ax + 1] - fsum[by][ax + 1] - fsum[ay + 1][bx] << endl;
			}
		}
		cout << ans << endl;
		//cout << "=====" << endl;
	}
	return 0;
}


Measured memory_bytes: 3220
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
    int n,l;
    cin>>n>>l;
    int mi = inf;
    int ans = 0;
    rep(i,n){
        ans+=l+i;
        if(abs(mi)>abs(l+i)){
            mi=l+i;
        }
    }
    cout<<ans-mi<<endl;

    return 0;
}

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

int main() {
    string s,t;
    cin>>s>>t;
    int count = 0;
    for(int i = 0; i < s.length(); i++) {
        count += (s.at(i) != t.at(i));
    }
    cout<<count<<endl;
    return 0;
}

Measured memory_bytes: 3916
n=int(input())
al=0
bob=0
a=list(map(int,input().split()))
a.sort()
for i in range(1,n+1):
    if i%2==1:
        al+=a[i-1]
    else:
        bob+=a[i-1]
if al>bob:
    print(abs(al-bob))
else:
    print(abs(bob-al))

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

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

#define rep(i,cc,n) for(int i=cc;i<n;++i)
#define lrep(i,cc,n) for(long long i=cc;i<n;++i)
#define sqrep(i,cc,n) for(long long i=cc;i*i<=n;++i)
#define rrep(i,cc,n) for(long i=cc;i>n;--i)
#define pii pair<int, int>
#define pll pair<long long, long long>
 
using ll = long long;

const vector<int> dx = {1, 0, -1, 0};
const vector<int> dy = {0, 1, 0, -1};
const ll inf = 1001001001;
const ll e9  = 1000000000;
const ll mod = 1000000007;


int main(){
   int n, k;
   ll s;
   cin >> n >> k >> s;
   if(s == 1000000000){
       rep(i, 0, k)cout << 1000000000 << " ";
       rep(i, k, n)cout << 1 << " ";
       cout << endl;
   }else{
       rep(i, 0, k)cout << s << " ";
       rep(i, k, n)cout << s+1 << " ";
       cout << endl;
   }
}

Measured memory_bytes: 3636
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    int k;
    cin >> n >> k;
    vint d(k);
    REP(i,k) cin >> d[i];
    int ans = n;
    while(1){
        int t = ans;
        int f = true;
        while(t>0){
            int x = t%10;
            for(int i:d){
                if(x==i){
                    f = false;
                    break;
                }
            }
            t/=10;
            if(!f)break;
        }
        if(f){
            cout << ans << endl;
            return 0;
        }
        ans++;
    }
    
    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3

import bisect

n = int(input())
a = list(map(int, input().split()))

a.sort()

if n == 2:
    print(a[1], a[0])
    exit()
# value = comb(a[1], a[0], exact=True)
# ans = [a[1], a[0]]
# index = 0
# for i in range(2, n):
#     value_tmp = comb(a[i], a[index], exact=True)
#     x = a[i]
#     y = a[index]
#     diff = abs((x-2*y)//2)
#     while 1:
#         y_new = a[index+1]
#         diff_new = abs((x-2*y_new)//2)
#         if diff_new > diff:
#             break
#         else:
#             index += 1
#     if value_tmp > value:
#         ans = [a[i], a[index]]
#         # value = value_tmp
# print(*ans)

x = a[-1]
index = bisect.bisect_left(a[:n-1], x/2)

ans = []
ans.append([abs(x/2-a[index-1]), a[index-1]])
ans.append([abs(x/2-a[index]), a[index]])
ans.append([abs(x/2-a[index+1]), a[index+1]])

ans.sort()

print(x, ans[0][1])


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

using ll=long long;
const ll MOD=1e9+7;

vector<ll> fact;

ll powm(ll x,ll k){
    ll res=1;
    while(k){
        if(k&1) res=res*x%MOD;
        k>>=1;
        x=x*x%MOD;
    }
    return res;
}
ll inv(ll x){
    return powm(x,MOD-2);
}
void init(int n){
    fact.resize(n+1);
    fact[0]=1;
    for(int i=0;i<n;i++){
        fact[i+1]=fact[i]*(i+1)%MOD;
    }
}
int main(){
    int n;
    cin>>n;
    init(n);
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    vector<vector<ll>> dp(n+1,vector<ll>(n+1));
    dp[0][n]=1;
    auto comb=[](int n,int k){
        return fact[n]*inv(fact[k])%MOD*inv(fact[n-k])%MOD;
    };
    auto calc=[comb](int i,int j,int f){
        return comb(j,f*i)*fact[f*i]%MOD*inv(fact[f])%MOD*inv(powm(fact[i],f))%MOD;
    };

    for(int i=0;i<n;i++){
        for(int j=0;j<=n;j++){
            if(a<=i+1 && i+1<=b){
                for(int f=c;f<=d;f++){
                    if(j-f*(i+1)<0) break;
                    (dp[i+1][j-f*(i+1)]+=calc(i+1,j,f)*dp[i][j])%=MOD;
                }
            }
            (dp[i+1][j]+=dp[i][j])%=MOD;
        }
    }
    
    cout<<dp[n][0]<<endl;
    return 0;
}


Measured memory_bytes: 10112
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long llong;
const int INF = 1 << 28;

int n;
vector<int> l(10);
int A, B, C;
int dfs(int depth, int a, int b, int c) {
   if (depth == n) {
      if (min({a, b, c}) <= 0)
         return INF;
      return abs(a - A) + abs(b - B) + abs(c - C) - 30;
   }
   int ans0 = dfs(depth + 1, a, b, c);
   int ans1 = dfs(depth + 1, a + l[depth], b, c) + 10;
   int ans2 = dfs(depth + 1, a, b + l[depth], c) + 10;
   int ans3 = dfs(depth + 1, a, b, c + l[depth]) + 10;
   return min({ans0, ans1, ans2, ans3});
}
int main() {
   cin >> n;
   cin >> A >> B >> C;
   rep(i, n) cin >> l[i];
   int ans = dfs(0, 0, 0, 0);
   cout << ans << endl;
   return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,k;cin >> n >> k;
  vector<vector<int>> a(2*k,vector<int>(2*k)),b(2*k,vector<int>(2*k));
  for(int i=0;i<n;i++){
    int x,y;cin >> x >> y;
    char c;cin >> c;
    if(c=='W'){
      a[x%(2*k)][y%(2*k)]++;
    }
    else{
      a[x%(2*k)][(y+k)%(2*k)]++;
    }
  }
  for(int i=0;i<2*k;i++){
    for(int j=0;j<2*k;j++){
      if(i<k){
        a[i][j]+=a[i+k][(j+k)%(2*k)];
      }
      else{
        a[i][j]=a[(i+k)%(2*k)][(j+k)%(2*k)];
      }
      b[i][(j+k)%(2*k)]=a[i][j];
    }
  }
  int ans=0;
  for(int i=0;i<2*k;i++){
    for(int j=1;j<2*k;j++){
      a[i][j]+=a[i][j-1];
      b[i][j]+=b[i][j-1];
    }
  }
  for(int j=0;j<2*k;j++){
    for(int i=1;i<2*k;i++){
      a[i][j]+=a[i-1][j];
      b[i][j]+=b[i-1][j];
    }
  }
  for(int i=k;i<2*k;i++){
    for(int j=k;j<2*k;j++){
      ans=max(ans,a[i][j]-a[i-k][j]-a[i][j-k]+a[i-k][j-k]);
      ans=max(ans,b[i][j]-b[i-k][j]-b[i][j-k]+b[i-k][j-k]);
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 31616
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7 
#mod = 998244353
from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10

N = INT()
ans = [0]*N

for x in range(1, 110):
	for y in range(1, 110):
		for z in range(1, 110):
			n = (x+y+z)**2 - x*y-y*z-z*x
			if n <= N:
				ans[n-1] += 1

print(*ans, sep = "\n")


Measured memory_bytes: 74280
N=int(input())
S=input()

L0=[]
L1=[]
ans=[]

for i in range(N-2):
    if S[i] in L0:
        continue
    else:
        L0.append(S[i])
    for j in range(i+1,N-1):
        temp=S[i]+S[j]
        if temp in L1:
            continue
        else:
            L1.append(temp)
        for k in range(j+1,N):
            ans.append(temp+S[k])


print(len(set(ans)))

Measured memory_bytes: 193140
class Dice
  def initialize(n, s, e, w, t, b)
    $north = n
    $south = s
    $east = e
    $west = w
    $top = t
    $bottom = b
  end

  def move_north
    north = $north
    south = $south
    top = $top
    bottom = $bottom
    $north = top
    $top = south
    $bottom = north
    $south = bottom
  end

  def move_south
    north = $north
    south = $south
    top = $top
    bottom = $bottom
    $south = top
    $bottom = south
    $north = bottom
    $top = north
  end

  def move_east
    top = $top
    bottom = $bottom
    east = $east
    west = $west
    $east = top
    $bottom = east
    $west = bottom
    $top = west
  end

  def move_west
    top = $top
    bottom = $bottom
    east = $east
    west = $west
    $west = top
    $bottom = west
    $east = bottom
    $top = east
  end

  def execute_orders(orders)
    orders.each do |order|
      if order == "N"
        move_north
      elsif order == "S"
        move_south
      elsif order == "E"
        move_east
      elsif order == "W"
        move_west
      else
        puts "error!"
      end
    end
  end
end

dice_number = gets.chomp.split.map(&:to_i)
t = dice_number[0]
s = dice_number[1]
e = dice_number[2]
w = dice_number[3]
n = dice_number[4]
b = dice_number[5]
input_orders = gets.chomp.to_s
orders = []
size = input_orders.size
for i in 0...size
  orders << input_orders[i]
end

dice = Dice.new(n, s, e, w, t, b)
dice.execute_orders(orders)
puts $top

Measured memory_bytes: 8704
#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;

typedef long long int ll;
typedef long double ld;

#define llset tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
#define en '\n'
#define S second
#define F first
#define pll pair<ll,ll>
#define PB push_back

const ll N = 1e6+7;
ll mod = 1e9+7;
#define calncr for(int i=1  ;i<=1e6;i++) fac[i] = (fac[i-1]*i)%mod;
ll fac[N] = {0};

ll gen_base(const ll before, const ll after) {
    auto seed = std::chrono::high_resolution_clock::now().time_since_epoch().count();
    std::mt19937 mt_rand(seed);
    int base = std::uniform_int_distribution<ll>(before+1, after)(mt_rand);
    return base % 2 == 0 ? base-1 : base;
}

ll pow(ll a,ll b)
{
    if(!b)
        return 1;
    ll p = pow(a,b/2);
    if(b%2)
        return (a*((p*p)%mod))%mod;
    else
        return (p*p)%mod;
}

ll modInv(ll a)
{
    //cout<<a<<" "<<mod<<en;
    return pow(a%mod,mod-2);
}

ll nCr(ll n,ll r)
{
    return (fac[n]*modInv((fac[r]*fac[n-r])%mod))%mod;
}

ll hashf(ll r,ll x,ll mod)
{
    return (x+r)%mod;
}


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    fac[0] = 1;
    calncr;
    ll n;
    cin>>n;
    ll arr[n];
    for(ll i=0;i<n;i++)
        cin>>arr[i];
    ll mx = 0,ans=0;
    for(ll i=0;i<n;i++){
        if(arr[i]<mx){
            ans+=(mx-arr[i]);
        }
        else{
            mx = max(mx,arr[i]);
        }
    }
    cout<<ans<<en;
}


Measured memory_bytes: 13032
N = gets.to_i
a_list = gets.split.map(&:to_i)

b_list = Array.new(N)
if N.even?
  (N - 1).step(by: -2, to: 1).with_index do |n, i|
    b_list[i] = a_list[n]
  end
  0.step(by: 2, to: N - 2).with_index do |n, i|
    b_list[N / 2 + i] = a_list[n]
  end
else
  (N - 1).step(by: -2, to: 0).with_index do |n, i|
    b_list[i] = a_list[n]
  end
  1.step(by: 2, to: N - 2).with_index do |n, i|
    b_list[N / 2 + 1 + i] = a_list[n]
  end
end
puts b_list.join(' ')


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

int main() {
    int N;
    std::cin >> N;

    const int d = N % 10; 
    switch (d) {
    case 2: case 4: case 5: case 7: case 9: {
        std::cout << "hon" << std::endl;
        break;
    }
    case 0: case 1: case 6: case 8: {
        std::cout << "pon" << std::endl;
        break;
    }
    case 3: {
        std::cout << "bon" << std::endl;
        break;
    }
    default: {
        break;
    }
    }

    return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int a[N];
int main() {
	int n, L, ans = 0;
	scanf("%d%d", &n, &L);
	for (int i = 1; i <= n; ++ i) {
		scanf("%d", &a[i]);
		if (i > 1 && a[i - 1] + a[i] >= L) {
			ans = i - 1;
		}
	}
	if (ans) {
		puts("Possible");
		for (int i = 1; i < ans; ++ i) printf("%d\n", i);
		for (int j = n - 1; j >= ans; -- j) printf("%d\n", j);
	}
	else {
		puts("Impossible");
	}
}



Measured memory_bytes: 1280
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;
int main(void){
    int a[3],b[3],c[3];
    for(int i=0;i<3;i++){
        cin>>a[i];
    }
    for(int i=0;i<3;i++){
        cin>>b[i];
    }
    for(int i=0;i<3;i++){
        cin>>c[i];
    }
    int def[2];
    bool ans=true;
    def[0]=b[0]-a[0];
    def[1]=c[0]-b[0];
    if(def[0]!=b[1]-a[1]||def[1]!=c[1]-b[1]||def[0]!=b[2]-a[2]||def[1]!=c[2]-b[2])ans=false;
    def[0]=a[1]-a[0];
    def[1]=a[2]-a[1];
    if(def[0]!=b[1]-b[0]||def[0]!=c[1]-c[0]||def[1]!=b[2]-b[1]||def[1]!=c[2]-c[1])ans=false;
    if(ans)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}


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

// {U}{INT,LONG,LLONG}_{MAX,MIN}
#define ALPHABET    (26)
#define INF         INT_MAX
#define MOD         (1000000007LL)

using LL  = long long;
// }}}

int main() {
    std::ios::sync_with_stdio(false);
    int w, a, b;cin >> w >> a >> b;
    if(a > b) swap(a, b);
    cout << max(0, b-(a+w)) << endl;
    return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

"""
正則二部グラフの辺彩色
"""

import numpy as np

N,M = map(int,input().split())
grid = [[int(x) for x in input().split()] for _ in range(N)]

edge = []
for i,row in enumerate(grid):
    for j,x in enumerate(row):
        edge.append(((x-1)//M,N+i))

graph = [dict() for _ in range(N+N)] # 頂点ごろに、色->相手
rest_color = [set(range(M)) for _ in range(N+N)]

for u,v in edge:
    common = rest_color[u] & rest_color[v]
    if common:
        c = common.pop()
        graph[u][c] = v
        graph[v][c] = u
        rest_color[u].remove(c)
        rest_color[v].remove(c)
        continue
    # 交互道を作って色c,dと当てていく
    c = rest_color[u].pop()
    d = rest_color[v].pop()
    cd = c + d
    V = [u,v]
    next_c = c
    while next_c not in rest_color[v]:
        v = graph[v][next_c]
        V.append(v)
        next_c = cd - next_c
    rest_color[v].remove(next_c)
    rest_color[v].add(cd - next_c)
    for i,(u,v) in enumerate(zip(V,V[1:])):
        if i%2 == 0:
            graph[u][c] = v
            graph[v][c] = u
        else:
            graph[u][d] = v
            graph[v][d] = u

after = [[None] * M for _ in range(N)]

for i,row in enumerate(grid):
    mod_to_x = [[] for _ in range(N)]
    for x in row:
        mod_to_x[(x-1)//M].append(x)
    for color in range(M):
        after[i][color] = mod_to_x[graph[i+N][color]].pop()

B = np.array(after)
C = B.copy()
C.sort(axis = 0)
print('\n'.join(' '.join(row) for row in B.astype(str)))
print('\n'.join(' '.join(row) for row in C.astype(str)))

Measured memory_bytes: 23592
import java.util.Scanner;

 
public class Main {
 
	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		long x  = Math.abs(sc.nextLong());
		long k  = sc.nextLong();
		long d  = sc.nextLong();
		long ans = 0;

		//最初にできるだけ0に近づける
		long devide = x / d;
		long rest = x % d;
		
		//0に近づけるだけでk回動く場合
		if(devide >= k) {
			ans = x - (k * d);
		}else {
			
			//k - divideが偶数なら何もしない
			if((k - devide) % 2 == 0) {
				ans = rest;
			}else {
				//k - divideが奇数なら1度だけ動かす
				ans = d - rest;
			}
		}
		
		System.out.println(ans);
		sc.close();
	}
}




Measured memory_bytes: 35692
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return 1;
    }
    return 0;
}
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MOD (1000000007)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

bool isPrime(int num)
{
    if (num < 2)
        return false;
    for (int i = 2; i * i <= num; i++)
    {
        if (num % i == 0)
            return false;
    }
    return true;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> pnum;
    const int num = 55555;
    for (int prime = 2; prime <= num; prime++)
    {
        bool flg = true;
        for (int i = 2; i * i <= prime; i++)
        {
            if (prime % i == 0)
                flg = false;
        }
        if (flg)
            pnum.push_back(prime);
    }
    sort(pnum.begin(), pnum.end()); // pnum : 55555以下の素数(5637個)
    vector<int> ans;
    for(int i=0;i<pnum.size();i++){
        if(pnum[i] % 10 == 1) ans.push_back(pnum[i]);
    }
    for(int i=0;i<n;i++) cout << ans[i] << ' ';
    cout << endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <map>

using namespace std;

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

    map <int, int> C;
    for (int i = 0; i < S.length(); i++){
        C[S[i]] ++;
    }
    
    bool flag = false;
    for (int i = 'a'; i <= 'z'; i++){
        if (C[i] == 0){
            flag = true;
            char a = i;
            cout << a << endl;
            break;
        }
    }
    if (flag == false){
        cout << "None" << endl;
    }
    

    return 0;
}

Measured memory_bytes: 512
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}
template <class C>
void print(const C &c, std::ostream &os = std::cout) {
    std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, " "));
    os << std::endl;
}

int main() {
    ll n;
    cin >> n;
    vl c(n);
    for (int i = 0; i < n; ++i) {
        cin >> c[i];
    }
    vl d(1);
    d[0] = c[0];
    for (int i = 1; i < n; ++i) {
        if (c[i] != d.back())
            d.push_back(c[i]);
    }
    map<int, vector<ll>> cnt;
    vector<ll> dp(d.size(), 0);
    dp[0] = 1;
    cnt[d[0]].push_back(1);
    for (int i = 1; i < d.size(); ++i) {
        dp[i] = dp[i - 1];
        if (cnt[d[i]].size() != 0)
            dp[i] = (dp[i] + cnt[d[i]].back()) % MOD;

        if (cnt[d[i]].size() == 0)
            cnt[d[i]].push_back(dp[i - 1]);
        else
            cnt[d[i]].push_back((cnt[d[i]].back() + dp[i - 1]) % MOD);
    }
    cout << dp[d.size() - 1] << "\n";
    return 0;
}

Measured memory_bytes: 26864
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;
typedef long long LL;
const int Max = 4e5;
const int MOD = 1e9 + 7;

int n, m, all;
int pre[Max + 5], last[Max + 5], other[Max + 5], cost[Max + 5], Inque[Max + 5], seq[Max + 5], dis[Max + 5];;

void build(int x, int y, int w)
{
	pre[++all] = last[x];
	last[x] = all;
	other[all] = y;
	cost[all] = w;
}

void Bfs(int s)
{
	int head = 1, tail = 1, now, ed, dr;
	seq[tail] = s;
	for(int i = 1; i <= n; i++)
	{
		if(i == s) dis[i] = 0;
		else dis[i] = 1 << 30;
	}
	Inque[s] = 1;
	while(head <= tail)
	{
		now = seq[head];
		ed = last[now];
		while(ed != -1)
		{
			dr = other[ed];
			if(dis[now] + cost[ed] < dis[dr])
			{
				dis[dr] = dis[now] + cost[ed];
				if(!Inque[dr])
				{
					Inque[dr] = 1;
					seq[++tail] = dr;
				}
			}
			ed = pre[ed];
		}
		Inque[now] = 0;
		head++;
	}
}

int main()
{
	all = -1;
	memset(last, -1, sizeof(last));
	scanf("%d%d", &n, &m);
	for(int i = 1; i <= m; i++)
	{
		int x, y;
		scanf("%d%d", &x, &y);
		build(x, y, 1);
		build(y, x, 1);
	}
	Bfs(1);
	if(dis[n] <= 2) 
	printf("POSSIBLE\n");
	else 
		printf("IMPOSSIBLE\n");
	return 0;
}

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

int main() {
	int n,m;
	cin>>n>>m;
	vector<vector<char>> v(n, vector<char> (m));
	vector<vector<int>> dp(n, vector<int> (m));
	for(int i=0;i<n;i++) {
		for(int j=0;j<m;j++) {
			cin>>v[i][j];
		}
	}
	dp[0][0] = v[0][0]=='.'?1:0;
	for(int i=1;i<m;i++) {
		dp[0][i] = (v[0][i]=='#')? 0 : dp[0][i-1];
	}
	for(int i=1;i<n;i++) {
		dp[i][0] = (v[i][0]=='#')? 0 : dp[i-1][0];
	}
	for(int i=1;i<n;i++) {
		for(int j=1;j<m;j++) {
			if(v[i][j]=='.') {
				dp[i][j] = ((dp[i-1][j]%1000000007) + (dp[i][j-1]%1000000007)) % 1000000007;
			} else {
				dp[i][j] = 0;
			}
		}
	}
	cout<<dp[n-1][m-1];
	
	return 0;
}


Measured memory_bytes: 7168
#include <algorithm>
#include <boost/optional.hpp>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define REP(i, n) for(int i = 0, i##_MACRO = (n); i < i##_MACRO; i++)
#define RANGE(i, a, b) for(int i = (a), i##_MACRO = (b); i < i##_MACRO; i++)
#define EACH(e, a) for(auto&& e : a)
#define ALL(a) std::begin(a), std::end(a)
#define RALL(a) std::rbegin(a), std::rend(a)
#define FILL(a, n) memset((a), n, sizeof(a))
#define FILLZ(a) FILL(a, 0)
#define INT(x) (static_cast<int>(x))

using namespace std;

using ll = long long;
using VI = vector<int>;
using VI2D = vector<vector<int>>;

constexpr int INF = 2e9;
constexpr double EPS = 1e-10;
constexpr double PI = acos(-1.0);

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

template <typename T>
constexpr int sign(T x) {
	return x < 0 ? -1 : x > 0 ? 1 : 0;
}

template <>
constexpr int sign(double x) {
	return x < -EPS ? -1 : x > EPS ? 1 : 0;
}

template <typename T, typename U>
constexpr void chmax(T& m, U x) {
	m = max(m, x);
}

template <typename T, typename U>
constexpr void chmin(T& m, U x) {
	m = min(m, x);
}

template <typename T>
constexpr T square(T x) {
	return x * x;
}

int main() {
	int x, y, z;
	cin >> x >> y >> z;
	cout << z << ' ' << x << ' ' << y << endl;
	return 0;
}


Measured memory_bytes: 256
#include <cstring>
#include <iostream>
#include <set>
#include <string>
#include <unordered_map>
#include <vector>

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

int N;
int64_t a[10000 + 1];

std::vector<int> primes;
std::set<int> ans;

void MakePrime() {
  primes.push_back(2);
  for (int i = 3; i <= 10000; i += 2) {
    bool is_prime = true;
    for (int p : primes) {
      if (i % p == 0) {
        is_prime = false;
        break;
      }
    }
    if (is_prime) primes.push_back(i);
  }
}

int64_t GetMod(int v, int m) {
  if (v < 0) return m + v % m;
  return v % m;
}

bool IsMultipleExprInMod(int p) {
  static int64_t w[10000 + 1];

  std::memcpy(w, a, sizeof(int64_t) * (N + 1));
  // std::cout << p << std::endl;
  for (int i = N - p; i >= 0; i--) {
    // for(int k = 0; k <= N; k++) std::cerr << w[k] << ", ";
    // std::cerr << std::endl;
    int64_t v = GetMod(w[N - (i + p)], p);
    w[N - (i + p)] = GetMod(w[N - (i + p)] - v, p);
    w[N - (i + 1)] = GetMod(w[N - (i + 1)] + v, p);
  }
  // for(int k = 0; k <= N; k++) std::cerr << w[k] << ", ";
  // std::cerr << std::endl;
  for (int i = 0; i <= N; i++) {
    if (w[i] % p) return false;
  }
  return true;
}

int main() {
  std::string s;
  std::cin >> N;
  for (int i = 0; i <= N; i++) {
    std::cin >> a[i];
  }
  //
  int div = std::abs(a[0]);
  for (int i = 0; i <= N; i++) {
    int v = a[i];
    if (!v) continue;
    div = gcd(div, std::abs(v));
  }
  if (div % 2 == 0) {
    ans.insert(2);
    while (div % 2 == 0) div /= 2;
  }
  for (int i = 3; i <= div; i += 2) {
    if (div % i == 0) {
      ans.insert(i);
      while (div % i == 0) div /= i;
    }
  }
  //
  MakePrime();
  for (int p : primes) {
    if (p > N) break;
    if (IsMultipleExprInMod(p)) ans.insert(p);
  }

  for (int p : ans) std::cout << p << std::endl;
  return 0;
}


Measured memory_bytes: 512
/******************************************
* AUTHOR : GURUTEJA *
******************************************/
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define N 100005
#define MOD 1000000007
#define dd double
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep1(i,b) for(int i=1;i<=b;i++)
#define pb push_back
#define mp make_pair
#define clr(x) x.clear()
#define sz(x) ((int)(x).size())
#define F first
#define S second

void debug(){
	#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif 

}

  int main() {
    debug();
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,x;
 
    cin>>n>>x;
    int a[n];
    for (int i = 0; i <n; ++i)
    {
    	cin>>a[i];
    }
    sort(a,a+n);
    int i=0;
    while(x>0 && i<n){
        x-=a[i];
        if(x<0){
        	break;
        }
        i++;
    }
    if(x>0)
      cout<<i-1<<endl;
    else
      cout<<i<<endl;
    return 0;
  }

Measured memory_bytes: 3536
//コンパイラ最適化用
#pragma GCC optimize("Ofast")
#define _GLIBCXX_DEBUG
//インクルード(アルファベット順)
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<chrono>//実行時間計測
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm,accumulate
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//順序保持しないmap
#include<unordered_set>//順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列
#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, int> pii;
typedef pair<ll, ld> pld;
typedef pair<pii, int> ppiii;
typedef pair<pii, ll> ppiill;
typedef pair<pll, ll> ppllll;
typedef pair<pli, int> pplii;
typedef map<int, int> mii;
typedef deque<ll> dll;
typedef queue<ll> qll;
typedef priority_queue<ll> pqll;
typedef priority_queue<ll, vector<ll>, greater<ll>> pqrll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<int>> vvint;
typedef vector<vector<pll>> vvpll;

//マクロ
//forループ
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=ll(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=ll(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) x.begin(),x.end() 
#define SIZE(x) ll(x.size()) 
//定数
#define INF 1000000000000 //10^12:∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange
//略記
#define PB push_back //挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
#define cin(x) cin >> x

signed main(){
    //入力の高速化用のコード
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    //入力
    ll N = 0;
    cin(N);

    vll X(N);
    REP(i,N) cin(X.at(i));

    ll ans  = 1000000;

    REP(i,100){
      ll d =0;
      REP(j,N){
        d += ((X[j]-i)*(X[j]-i));
      }

      ans = min(ans,d);

    }

    //出力
    cout << ans << endl;
    //REP(i,N) cout << ans.at(i) <<endl;
  return 0;
}

Measured memory_bytes: 3644
#include <utility>
#include <iostream>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <algorithm>
using namespace std;

int main(int argc, char const *argv[]) {
  int n, val, tmp;
  int len=0;
  std::cin >> n;
  std::vector<int> S; S.reserve(100000);


  for (size_t i = 0; i < n; i++) {
    std::cin >> val;
    if (i==0 || val != tmp) {
      len++;
      S[len]=val;
      tmp=val;
    }
  }



  int num=0;

  int q; std::cin >> q;
  for (size_t i = 0; i < q; i++) {
    std::cin >> val;
    int lower=0;
    int upper=len;
    int mid = upper/2;
    while (1) {
      if (val==S[mid] || val==S[mid+1] || val==S[mid-1]) {
        num++;
        break;
      }
      if(S[0] <= val && val <= S[mid-1]){
        upper = mid;
        mid = (mid + lower)/2;
      }else if (S[mid+1] <= val && val <= S[upper]) {
        lower = mid;
        mid = (mid + upper)/2;
      }else{
        break;
      }
    }

  }
  std::cout << num << '\n';

  return 0;
}



Measured memory_bytes: 3096
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include<numeric>
using namespace std;
using P = pair<int, int>;
#define rep(i,n) for(int i=0; i<(n);i++)
typedef long long ll;


int main(){
    int n,m,x; cin >> n >> m >> x;
    vector<vector<int>> a(n, vector<int>(m));
    vector<int> c(n);
    rep(i, n){
        cin >> c[i];
        rep(j, m){
            cin >> a[i][j];
        }
    }

    int ans = 1001001001;
    rep(s, 1<<n){
        int cost = 0;
        vector<int> d(m);
        rep(i, n){
            if(s >> i & 1){
                cost += c[i];
                rep(j, m) d[j] += a[i][j];
            }
        }
        bool ok = true;
        rep(j, m) if(d[j] < x) ok = false;
        if(ok) ans = min(ans, cost);
    }
    if(ans == 1001001001) cout << -1 << endl;
    else cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3172
/* Filename: C.java
 * Author: Mushiyo
 */

import java.util.Scanner;

public class Main{

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

		while (input.hasNext()) {
			char[] s = input.next().toCharArray();
			int K = input.nextInt();

			int cur = 0;
			boolean hasA = false;
			while (K > 0) {
				if (cur < s.length - 1) {
					int distToA = ('z' - s[cur] + 1) % 26;

					if (distToA <= K) {
						s[cur] = 'a';
						K -= distToA;
					}

				} else {
					char tmp = (char) ((s[cur] - 'a' + K % 26) % 26 + 'a');
					
					if(tmp > s[cur] && hasA && K % 26 == 0){
						
					} else {
						s[cur] = tmp;
					}
					
					K = 0;
				}
				
				if (s[cur] == 'a') {
					hasA = true;
				}				
				++cur;
			}

			System.out.println(s);
		}
	}

}


Measured memory_bytes: 13712
#include <iostream>
#include <string>
#include <cmath>

#include <list>
#include <queue>
#include <algorithm>
#include <map>

#define INF 1000000000

using namespace std;

map<long long, int> prime_factor(long long n) {
  map<long long, int> ret;
  for(long long i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}

int main(void)
{
    long long n;
    cin >> n;
    map<long long, int> ret = prime_factor(n);
    // for (long long i = 0; i < n; i++) {
    //     cout << i << " " << ret[i] << endl;
    // }

    int ans = 0;

    for(auto itr = ret.begin(); itr != ret.end(); ++itr) {
        // cout << "key = " << itr->first << ", val = " << itr->second << "\n";
        int count = itr->second;
        int sum = 0;
        for (int i = 1; i <= 100; i++) {
            sum += i;
            if (sum > count) {
                ans += i - 1;
                break;
            }
        }
    }

    cout << ans;
    return 0;
}


Measured memory_bytes: 3632
n, m, k = [int(x) for x in input().split()]

flag = False

for i in range(n+1):
    for j in range(m+1):
        if (n - i) * (m - j) + i * j == k:
            flag = True
            break       
        else:
            continue
        break

if flag:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
using namespace std;
int main() {
	int a, b, c;
	cin >> a >> b >> c;
	int cnt = 0;
	for (int i = max(a, b); i > 0; i--) {
		if (a % i == 0 && b % i == 0) {
			cnt++;
			if (cnt == c) {
				cout << i << endl;
				return 0;
			}
		}
	}	
}

Measured memory_bytes: 256
#include<iostream>
#include<numeric>
#include<math.h>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<climits>
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define ll long long
#define mkp make_pair
#define ar array
#define pll pair<ll,ll>
#define rep(i,from,to) for(int i=from;i<to;i++)
#define repd(i,from,till) for(int i=from;i>=till;i--)
#define waste ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define inf 1e9+1
#define mod 1e9+7
#define inf1 1e18+1
#define pie 3.14159265358979323846
#define N 100005
using namespace std;
/*
ll bin(ll i,ll j){
	ll mid=(i+j)/2;
	if(a[mid]==x)reutrn mid;
	else if(ans>x)return bin(i,mid-1);
	else return bin(mid+1,j);
}/*
ll power(ll base,ll power){
    ll res=1;
    base=base%mod;
    while(power>0){
    	if(power&1){
    		res=(res*base)%mod;
		}
		power=power>>1;
		base=(base*base)%mod;
	}
	return res;
}
*/
/*
int nCr(int x, int y){
	if(y>x)return 0;
	int num=fact[x];
	num*=invfact[y];
	num%=mod;
	num*=invfact[x-y];
	num%=mod;
	return num;
}
*/
/*bool prime[n+1];
void SieveOfEratosthenes(int n){
	rep(i,0,n+1)prime[i]=true
    for (int p=2;p*p<=n;p++)
        if (prime[p])
            for (int i=p*p;i<=n;i+=p)prime[i]=false;
}*/
/*
int gcd(int a,int b){
	if(b==0)return a;
	else return gcd(b,a%b);
}
*/

int solve(){
    int n;
    cin>>n;
    int a[n][3];
    rep(i,0,n){
    	cin>>a[i][0]>>a[i][1]>>a[i][2];
	}
	rep(i,0,101){
		rep(j,0,101){
			int flag=0,val=-1;			
			rep(k,0,n){
				if(a[k][2]==0)continue;
				if(val==-1)val=a[k][2]+abs(a[k][0]-i)+abs(a[k][1]-j);
				else if(val!=a[k][2]+abs(a[k][0]-i)+abs(a[k][1]-j)){
					flag=1;break;
				}
			}
			if(flag==0){
				int chk=0;
				rep(k,0,n){
					if(a[k][2]==0){
						if(val-abs(a[k][0]-i)-abs(a[k][1]-j)>0)chk=1;
					}
				}
				if(chk==0)return cout<<i<<" "<<j<<" "<<val<<endl,0;
			}
		}
	}
	return 0;
}
int main(){
    waste;
    int t;
    //cin>>t;
    t=1;
    while(t--){
       	solve();
    }
}


Measured memory_bytes: 256
n, d = map(int, input().split())
xy = []
for i in range(n):
    x, y = map(int, input().split())
    xy.append([x, y])
count = 0
for pq in xy:
    if (pq[0]**2 + pq[1]**2) <= d**2:
        count+=1
print(count)

Measured memory_bytes: 39048
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define PI                acos(-1)
#define pb                emplace_back
#define mp                make_pair
#define all(a)            (a).begin(), (a).end()
#define clr(a,h)          memset(a, (h), sizeof(a))
#define forr(i, b, e)     for(ll i = b; i < e; i++)
#define forg(i, b, e, m)  for(ll i = b; i < e; i+=m)
#define F first
#define S second

using namespace std;
using namespace __gnu_pbds;

typedef long long       ll;
typedef pair<ll, ll>  ii;
typedef vector<ll>     vi;
typedef vector<ii>      vii;
typedef vector<ll>      vll;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
const ll INF = ll(1e9 + 7);
#define tam 123456
int main()
{
    std::ios::sync_with_stdio(false); cin.tie(0);
    int n;
    cin>>n;
    int val;
    map<int,int> mp;
    forr(i,0,n)
    {
        cin>>val;
        mp[val]++;
    }
    val=n-1;
    bool nop=false;
    int tot=1;
    const int MOD=1e9+7;
    forr(i,0,n)
    {
        tot*=mp[abs(val)];
        tot%=MOD;
        //cout<<abs(val)<<" "<<mp[abs(val)]<<" "<<tot<<endl;
        if (mp[abs(val)]<=0)
            nop=1;
        else
        {
            mp[abs(val)]--;
        }
        val-=2;
    }
    if (nop==1)
        cout<<0<<endl;
    else
    {
        cout<<tot<<endl;
    }
}
// PLUS ULTRA!
    

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

int main()
{
    ll L, R, d;
    cin >> L >> R >> d;
    ll ans = 0;
    for (int i = L; i <= R; ++i) {
        if (i % d == 0) ans++;
    }
    cout << ans << endl;


}


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

int main(){
    string s;
    cin>>s;
    int n=s.size();
    int ans1=0,ans2=0;
    char c1='0',c2='1';
    for(int i=0; i<n; i++){
        swap(c1,c2);
        if(s[i]==c1)ans1++;
        else ans2++;
    }
    cout<<min(ans1,ans2);
    return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;string s,t;cin>>n>>s>>t;
  int maxi=0;
  for(int i=0;i<n;i++){//going through all substrings starting from 0 in t
   for(int start=0;start<n;start++)//starting pos in s
   {
     int ans=0;
  		for(int j=0;j<=i;j++){
          if(start+j >=n)break;
        	if(s[start+j]==t[j])ans++;
        }
    maxi = max(maxi,ans);
  	} 
  }
cout<<n-maxi+n;
    //for(int i=0;i<n-maxi;i++)cout<<s[i];
    //cout<<t;
}

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

int main() {
  int mod=1000000007;
  int n;
  cin >> n;
  long to=0;
  vector<int>a(n);
  vector<int>b(n);
  vector<int>c(n);
  rep(i,n){
    cin>>a.at(i)>>b.at(i);
    to-=b.at(i);
    c.at(i)=a.at(i)+b.at(i);
  }
  sort(c.begin(),c.end());
  reverse(c.begin(),c.end());
  rep(i,(n-1)/2+1){
    to+=c.at(i*2);
  } 
  cout<<to<<endl;  
}

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

using ll = long long;

const int INF = 1001001001;
const ll INF_LL = 1001001001001001001LL;

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

  if(b>a+x) cout << "dangerous" << endl;
  else if(b<=a+x && b>a) cout << "safe" << endl;
  else cout << "delicious" << endl;
  
  return 0;
}


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

using namespace std;

typedef long long ll;
typedef vector<ll> vl;
typedef long double ld;
typedef vector<ld> vd;
typedef bool bl;
typedef vector<bl> vb;
typedef unordered_map<ll,unordered_map<ll,ll>> graph;

const ll e5 = 1 << 20;
const ll mod = 1000000007;
const ll e3 = 1 << 13;
const ll INF = 1ll << 60;

ll n,k;
ll v[100];
ll ans;

int main(){
  cin >> n >> k;
  for(ll i = 0;i < n;i++) cin >> v[i];
  for(ll i = 0;i <= n;i++){
    for(ll j = 0;j+i <= n;j++){
      ll x = 0;
      ll cnt = k;
      vl y = vl(0);
      for(ll s = 0;s < j;s++){
        x += v[s];
        cnt--;
        if(v[s] < 0) y.push_back(v[s]);

      }
      for(ll s = j+i;s < n;s++){
        x += v[s];
        cnt--;
        if(v[s] < 0) y.push_back(v[s]);
      }
      if(cnt >= 0){
        sort(y.begin(),y.end());
        for(ll i = 0;i < cnt && i < y.size();i++){
          x -= y[i];
        }
        // cerr << j << " " << j+i << " " << x << endl;
        ans = max(ans,x);
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256