akhauriyash/Code-Regression huggingface dataset:
def solve array, target
  count = 0
  left = 0
  right = array.size - 1

  loop do
    center = (left + right) / 2
    break if left > right
    count += 1
    if array[center] == target
      break
    else
      if array[center] < target
        left = center + 1
      elsif array[center] > target
        right = center - 1
      end
    end
  end

  count
end

while (n = $stdin.gets.to_i) != 0
  array = Array.new
  n.times do
    array << $stdin.gets.to_i
  end
  p solve(array, $stdin.gets.to_i)
end

Measured memory_bytes: 6088
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	static boolean p[];
	public static void main(String[] args) {
		// TODO ツ篠ゥツ督ョツ青カツ青ャツつウツづェツつスツδソツッツドツ・ツスツタツブ
		Scanner sc=new Scanner(System.in);
		int n,i,count;
		while(true){
			n=sc.nextInt();
			if(n==0) break;
			count=0;
			p=new boolean[n];
			Arrays.fill(p, true);
			p[0]=p[1]=false;
			prime(p,n);

			for(i=n-1;1<=i/2;i--){
				if(p[i]){
					if(i!=n-i){
						p[i]=false;
					}
					if(p[n-i]){
						p[n-i]=false;
						//System.out.printf("%d %d\n",i,n-i);
						count++;
					}
				}
			}

			System.out.println(count);
		}
	}
	static void prime(boolean p[],int n){
		int i,j;
		for(i=2;i<n;i++){
			if(p[i]){
				for(j=2*i;j<n;j+=i){
					p[j]=false;
				}
			}
		}
	}
}

Measured memory_bytes: 17000
#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(),x.end()
#define db(...) " [" << #__VA_ARGS__ << ": " << __VA_ARGS__ << "] "
using ii=long long;
const int N = 21;
int d[N];
ii mask[N + 1][1 << N];
const ii mod = 1e9 + 7;
int main()
{
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        int x = 0;
        for (int j = 0; j < n; ++j) {
            int y;
            cin >> y;
            if (y) x |= 1 << j;
        }
        d[i] = x;
    }
    mask[0][0] = 1;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < (1 << n); ++j) {
            if (__builtin_popcount(j) != i) continue;
            for (int h = 0; h < n; ++h) {
                if (j & (1 << h)) continue;
                if (!(d[i] & (1 << h))) continue;
                mask[i + 1][j | (1 << h)] += mask[i][j];
                mask[i + 1][j | (1 << h)] %= mod;
            }
        }
    }
    cout << mask[n][(1 << n) - 1] << "\n";
}


Measured memory_bytes: 309504
#include <bits/stdc++.h>
#include <algorithm>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(x) (x).begin(), (x).end()
#define PB(x) push_back(x)
#define MP(x,y) make_pair(x,y)
using namespace std;
using P = pair<int,int>;
typedef long long ll;
 
int main() {

    int n,q;
    string s;
    cin>>n>>q>>s;
    vector<int> l(q);
    vector<int> r(q);
    rep(i,q) {
        cin>>l[i]>>r[i];
    }

    vector<int> t(n);
    rep(i,n-1) {
        if(s[i]=='A'&&s[i+1]=='C')  t[i]=1;
        else    t[i]=0;
    }

    vector<int> u(n);
    u[0]=0;
    rep(i,n-1) {
        u[i+1]=u[i]+t[i];
    }

    rep(i,q) {
        cout<<u[r[i]-1]-u[l[i]-1]<<'\n';
    }

 return 0;
}

Measured memory_bytes: 2560
import sys
s=input()
l="abcdefghijklmnopqrstuvwxyz"
for i in range(len(l)): #aから順に調べていく
    if l[i] in s: #もし文字列sの中にa..があればそれを表示
        continue
    else:
        print(l[i])
        sys.exit()
print("None")
    

Measured memory_bytes: 3188
n,k = list(map(int,input().split()))
h = list(map(int,input().split()))
 
dp = [float('inf')]*n
 
for i in range(n):
  if i == 0:
    dp[0] = 0
    continue
    
  for j in range(0 if i-k < 0 else i-k,i):
    dp[i] = min(dp[i], dp[j] + abs(h[i] - h[j]))
  
  
print(dp[n-1])

Measured memory_bytes: 55008
#include <iostream>
#include <string>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <bitset>
#include <functional>
#include <queue>
#include <utility>
#include <map>
using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define dump(x)  cerr << #x << " = " << (x) << endl;
typedef long long LL;
typedef pair<int, int> P;
typedef pair<LL, LL> PLL;
const int INF = 1 << 29;	// 十分大きい値にする, INT_MAX にしないのはオーバーフロー対策


void solve()
{
	const int MAX_N = 100000, MAX_M = 100000;	// 最後に数字直す
	int N, M;
	priority_queue<LL, vector<LL>, greater<int>> A;
	PLL BC[MAX_M + 1];
	cin >> N >> M;
	FOR(i, 0, N) {
		LL tmp;
		cin >> tmp;
		A.push(tmp);
	}
	FOR(i, 0, M) {
		cin >> BC[i].first >> BC[i].second;
	}

	sort(BC, BC + M, [](PLL& x, PLL& y) { return x.second > y.second; });

	FOR(i, 0, M) {
		int j = 0;
		for (j = 0; j < BC[i].first; j++) {
			if (A.top() < BC[i].second) {
				A.pop();
				A.push(BC[i].second);
			}
			else {
				break;
			}
		}
		if (j == 0) break;
	}

	LL ans = 0;
	while (!A.empty()) {
		ans += A.top();
		A.pop();
	}

	cout << ans << endl;
}

int main(void)
{
	solve();
	return 0;
}


Measured memory_bytes: 2936
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while(true) {
            int x = sc.nextInt();
            int y = sc.nextInt();
            if( x == 0 && y == 0) {
                break;
            }
            if( x > y) {
                System.out.println(y + " " + x);
            } else {
                System.out.println(x + " " + y);
            }
        }
    }
}


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

int main(){
  int n;
  cin >> n;
  int sum = 0, minV = 100, s;
  for ( int i = 0; i < n; i++){
    cin >> s;
    sum += s;
    if ( s % 10 != 0){
      minV = min(s, minV);
    }
  }

  if (minV == 100 ){
    cout << 0 << endl;
  } else if ( sum % 10 == 0) {
    cout << sum - minV << endl;
  } else {
    cout << sum << endl;
  }

  return 0;
}

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

int main(){
    int n;
    cin >> n;
    switch(n % 10){
        case 2:
        case 4:
        case 5:
        case 7:
        case 9:
        cout << "hon" << endl;
        break;
        case 0:
        case 1:
        case 6:
        case 8:
        cout << "pon" << endl;
        break;
        case 3:
        cout << "bon" << endl;
    }
    return 0;
}

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

#include <bits/stdc++.h>
using namespace std;
using lint = long long;

struct UnionFind{
	vector<lint> rnk,par,num;
	UnionFind(lint N) : rnk(N),par(N),num(N){
		init();
	}
	void init(){
		for(lint i = 0;i < rnk.size();i++){
			rnk[i] = 0;
			par[i] = i;
			num[i] = 1;
		}
	}
	lint find(lint x){
		if(par[x] == x) return x;
		return par[x] = find(par[x]);
	}
	void unite(lint x,lint y){
		x = find(x);
		y = find(y);
		if(x == y) return;
		if(rnk[x] < rnk[y]){
			par[x] = y;
			num[y] += num[x];
		}
		else{
			par[y] = x;
			num[x] += num[y];
			if(rnk[x] == rnk[y]) rnk[x]++;
		}
	}
	bool same(lint x,lint y){
		return (find(x) == find(y));
	}
	lint size(lint x){
		return num[find(x)];
	}
};

signed main(){
  lint N, M, K; cin >> N >> M >> K;
  vector<lint> f(N, 0);
  UnionFind tree(N);
  vector<lint> a(M + K), b(M + K);
  for(lint i = 0; i < M; i++){
    cin >> a[i] >> b[i]; --a[i]; --b[i];
    tree.unite(a[i], b[i]);
  }
  for(lint i = 0; i < K; i++){
    cin >> a[M + i] >> b[M + i];
    a[M + i]--; b[M + i]--;
  }
  for(lint i = 0; i < M + K; i++){
    if(tree.same(a[i], b[i])){
      f[a[i]]++; f[b[i]]++;
    }
  }
  for(lint i = 0; i < N; i++){
    cout << tree.size(i) - f[i] - 1 << " ";
  }
  cout << endl;
}

Measured memory_bytes: 7040
/*starting with the name of almighty ALLAH*/
/*solved by RAKIB JOY*/
// Practice is the only shortcut to improve
#include<bits/stdc++.h>
#define ll long long int
#define pb push_back
#define vc vector
#define vi vc<int>
#define vl vc<ll>
#define dbg(x) cout<<x<<endl;
#define mp(x,y) make_pair(x,y)
#define yes dbg("YES")
#define no dbg("NO")
#define tst int t;cin>>t;while(t--)
#define srt(v) sort(v.begin(),v.end());
#define rsrt(v) sort(v.begin(),v.end(),greater<int>());
#define rj ios::sync_with_stdio(false);cin.tie(0);
#define rvs(v) reverse(v.begin(),v.end());
#define F first
#define S second
#define mod 1000000007
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*b)/gcd(a,b)
#define PI 2*acos(0.0)
#define pii pair<int,int>
#define fr(i,a,b) for(ll i=a;i<=b;i++)
#define coutv(v) for(auto it:v)cout<<it<<' ';cout<<endl;
#define cinv(v) for(auto &it:v)cin>>it;
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<typename T> using ordered_set =tree<T, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>;
*/
//sieve bool b[1000005];void primenire(){int i, j;b[0]=true;b[1]=true;for(i=4; i<=1000000; i+=2){b[i]=true;}for(i=3; i<=1001; i+=2){if(!b[i]){for(j=i*i; j<=1000001; j+=2*i){b[j]=true;}}}}
//power ll power(ll a,ll b){if(b==0) return 1LL;if(b&1) return a*power(a,b-1);else return power(a,b/2)*power(a,b/2);}
//bigmod long long int m(long long int a,long long int b,long long int c){if(b==0)return 1;if(b%2==0){long long int  tmp=m(a,b/2,c);return ((tmp%c)*(tmp%c))%c;}elsereturn ((a%c)*(m(a,b-1,c)%c))%c;}
//MaxSubarraySum ll mss(vector<ll>v){ll mx=v[0];ll sz=v.size();for(int i=1;i<=sz;i++){ll t=v[i]+v[i-1];if(t>=v[i]) v[i]=t;mx=max(mx,v[i]*1LL);}return mx;}
//combination ll com[1001][1001];void combination(){com[1][1]=1;com[1][0]=1;for(ll i=2; i<=1000; i++){com[i][0]=1;for(ll j=1; j<=i; j++){com[i][j]=com[i-1][j]+com[i-1][j-1];}}}
///--------------Graph Moves--------------------------------------
///const int fx[] = {+1,-1,+0,+0};
///const int fy[] = {+0,+0,+1,-1};
///const int fx[] = {+0,+0,+1,-1,-1,+1,-1,+1}; ///King's move
///const int fy[] = {-1,+1,+0,+0,+1,+1,-1,-1}; ///king's Move
///const int fx[] = {-2,-2,-1,-1,+1,+1,+2,+2}; ///knight's move
///const int fy[] = {-1,+1,-2,+2,-2,+2,-1,+1}; ///knight's move
///---------------------------------------------------------------

void solve()
{
   ll a,b,c;
   cin>>a>>b>>c;
   ll p=ceil((double)a/b);
   cout<<p*c<<endl;
}
int main()
{
    rj
    solve();



    return 0;
}



Measured memory_bytes: 3756
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
struct mint {
  ll x;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
int main() {
  int H,W;
  cin >> H >> W;
  mint dp[H][W];
  dp[0][0] = 1;
  string a[H];
  for (int i = 0; i < H; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (a[i][j] == '.') {
        if (i) {
          dp[i][j] = dp[i-1][j];
        }
        if (j) {
          dp[i][j] += dp[i][j-1];
        }
      } else {
        dp[i][j] = mint();
      }
    }
  }
  cout << dp[H-1][W-1].x;
}

Measured memory_bytes: 13244
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  scanf("%d", &n);
  int s = 0;
  for (int i = 0; i < n; i++) {
    int x;
    scanf("%d", &x);
    s ^= x;
  }
  printf((s & 1) ? "NO\n" : "YES\n");
  return 0;
}


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

int main() {
    ll A,B,V,W,T;

    cin >> A >> V >> B >> W >>T;

    ll idou;
    idou = (V - W)*T;

    ll kyori;
    kyori = abs(A - B);

    if(kyori <= idou){
        cout << "YES" << endl;
    }
    else
    {
        cout << "NO" << endl;
    }
}


Measured memory_bytes: 3612
#include<stdio.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<string.h>
#include<functional>
#include<limits.h>
#include<stdlib.h>
#include<string>
#include<unordered_map>
#include <iomanip>
using namespace std;
 
#define intmax INT_MAX
#define lmax LONG_MAX
#define uintmax UINT_MAX
#define ulmax ULONG_MAX
#define llmax LLONG_MAX
#define ll long long
#define rep(i,a,N) for((i)=(a);(i)<(N);(i)++)
#define rrp(i,N,a) for((i)=(N)-1;(i)>=(a);(i)--)
#define llfor ll i,j,k
#define sc(a) cin>>a
#define pr(a) cout<<a<<endl
#define pY puts("YES")
#define pN puts("NO")
#define py puts("Yes")
#define pn puts("No")
#define pnn printf("\n")
#define sort(a) sort(a.begin(),a.end())
#define push(a,b) (a).push_back(b)
#define llvec vector<vector<ll>>
#define charvec vector<vector<char>>
#define sizeoof(a,b) (a,vector<ll>(b))
#define llpvec vector<pair<ll,ll>>
/*繰り上げ除算*/ll cei(ll x,ll y){ll ans=x/y;if(x%y!=0)ans++;return ans;}
/*最大公約数*/ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
/*最小公倍数*/ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
/*n乗*/ll llpow(ll x,ll n){ll i,ans=1;rep(i,0,n)ans*=x;return ans;}
/*階乗*/ll fact(ll x){ll i,ans=1;rep(i,0,x)ans*=(x-i);return ans;}
/*nCr*/ll ncr(ll n,ll r){return fact(n)/fact(r)/fact(n-r);}
/*nPr*/ll npr(ll n,ll r){return fact(n)/fact(n-r);}
/*primejudge*/bool prime(ll a){if(a<=1)return false;ll i;for(i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
ll ans=0;llfor;///////////////////////////////////////////////////////////
int main(){
  int N,K;
  cin>>N>>K;
  int count=0;
  for(int i=0;i<N;i++){
    int h;
    cin>>h;
    if(h>=K) count++;
  }
  cout<<count;
return 0;}

Measured memory_bytes: 3596
#include <stdio.h>

//ダイスの構造体
typedef struct{
	int top;
	int bottom;
	int right_side;
	int left_side;
	int front;
	int back;
}Dice;

//関数プロトタイプ宣言
void moving_north(int *top, int *bottom, int *front, int *back);
void moving_east(int *top, int *bottom, int *right_side, int *left_side);
void rotate_right(int *front, int *back, int *right_side, int *left_side);
int dice_comparison(Dice dice[], int index1, int index2);

int main(void)
{
	Dice dice[100];

	//iとjはループ変数、flagは2つ以上のダイスが等しいか表す
	int i, j, count, flag;

	flag = 0;
	scanf("%d", &count);
	for(i = 0; i < count; i++){
		scanf("%d %d %d %d %d %d", 
			  &dice[i].top, &dice[i].front, &dice[i].right_side, &dice[i].left_side, &dice[i].back, &dice[i].bottom);
	}

	for(i = 0; i < count; i++){
		for(j = (i + 1); j < count; j++){
			if(dice_comparison(dice, i, j)){
				flag = 1;
				break;
			}
		}
		//無駄な繰り返しを省略
		if(flag){
			break;
		}
	}

	//1組でも等しければ "No" と出力する
	if(flag){
		printf("No\n");
	}
	else{
		printf("Yes\n");
	}

	return 0;
}

//北側に転がす関数
void moving_north(int *top, int *bottom, int *front, int *back)
{
	int temp;

	//各面の値をずらす
	temp = *top;
	*top = *front;
	*front = *bottom;
	*bottom = *back;
	*back = temp;
}

//東側に転がす関数
void moving_east(int *top, int *bottom, int *right_side, int *left_side)
{
	int temp;

	//各面の値をずらす
	temp = *top;
	*top = *left_side;
	*left_side = *bottom;
	*bottom = *right_side;
	*right_side = temp;
}

//上面と下面を軸とし右側へ回転する関数
void rotate_right(int *front, int *back, int *right_side, int *left_side)
{
	int temp;

	//各面の値をずらす
	temp = *front;
	*front = *left_side;
	*left_side = *back;
	*back = *right_side;
	*right_side = temp;
}

//2つのダイスが等しいか比較する関数(Dice3で作成したものと同じ)
int dice_comparison(Dice dice[], int index1, int index2)
{
	int i, j;

	for(i = 0; i < (4 * 4); i++){
		for(j = 0; j < 4; j++){
			//2つのダイスの目が全て等しければ1を返す
			if((dice[index1].top == dice[index2].top) && (dice[index1].bottom == dice[index2].bottom) && (dice[index1].front == dice[index2].front) &&
				(dice[index1].back == dice[index2].back) && (dice[index1].right_side == dice[index2].right_side) && (dice[index1].left_side == dice[index2].left_side)){
					return 1;
			}
			//ダイスの向きを変える
			rotate_right(&dice[index2].front, &dice[index2].back, &dice[index2].right_side, &dice[index2].left_side);
		}

		//ダイスを北側に転がし、ダイスが1周する度に東側に転がす
		moving_north(&dice[index2].top, &dice[index2].bottom, &dice[index2].front, &dice[index2].back);
		if((i > 0) && (i % 4 == 0)){
			moving_east(&dice[index2].top, &dice[index2].bottom, &dice[index2].right_side, &dice[index2].left_side);
		}
	}

	return 0;
}


Measured memory_bytes: 2108
#include<iostream>
using namespace std;
int main(){
    int k,s;
    cin>>k>>s;
    int ans=0;
    for(int i=0;i<=k;i++){
        for(int j=0;j<=k;j++){
            int l=s-i-j;
            if(0<=l&&l<=k)ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3604
#include <iostream>
#include <vector>
#include <string>
#define rep(i,n) for(int (i) = 0;(i) <  (n);(i)++)
using namespace std;

typedef long long ll;

class union_find{
    int n;
    vector<int> par;
    vector<int> rank;
    vector<int> sizev;
public:
    union_find(int n){  //初期化
        this->n=n;
        par = vector<int>(n,0);
        sizev = vector<int>(n,1);
        rep(i,n){
            par[i]=i;
        }
        rank = vector<int>(n,0);
    }
    int find(int x){    //親
        if(par[x]==x){
            return x;
        }else{
            par[x]=find(par[x]);
            return par[x];
        }
    }
    
    int size(int x){
        return sizev[find(x)];
    }
    void unite(int x,int y){    //結合
        x=find(x);
        y=find(y);
        if(x==y){return;}
        if(rank[x]<rank[y]){
            par[x]=y;
            sizev[y]+=sizev[x];
        }else{
            par[y]=x;
            sizev[x]+=sizev[y];
            if(rank[x]==rank[y])rank[x]++;
        }
    }
    bool same(int x,int y){     //同じグループか判定
        return find(x)==find(y);
    }
};

int main(){
    int N,M;
    cin>>N>>M;
    vector<int> v[2];
    vector<ll> ans;
    ans.resize(M+1,0);
    for(int m = 0;m < M;m++){
        int a,b;
        cin>>a>>b;
        v[0].push_back(--a);
        v[1].push_back(--b);
    }
    union_find uf(N);
    ans[M-1] = (ll)N*(ll)(N-1)/2;
    for(int m = M-1;m >= 1;m--){
        int a = v[0][m],b = v[1][m];
        ans[m-1]=ans[m];
        if(!uf.same(a,b)){
            ans[m-1]-=(ll)uf.size(a)*(ll)uf.size(b);
            uf.unite(a,b);
        }
    }
    for(int m = 0; m < M;m++){
        cout<<ans[m]<<endl;
    }
}



Measured memory_bytes: 4340
#include <bits/stdc++.h>
#define pb push_back
#define int long long
#define mp make_pair
#define inf 1000000007LL
#define LINF 1000000000000000007LL
#define ll long long
using namespace std;
int good[514514],used[514514];
int modpow(int x,int k){
	// x ^ k mod inf
	int p2[55],res=1;
	p2[0]=1;p2[1]=x%inf;
	for(int i=2;i<=50;i++){
		p2[i]=p2[i-1]*p2[i-1];
		p2[i] %= inf;
	}
	for(int i=1;i<=50;i++){
		if(k%2==1){
			res *= p2[i];
			res %= inf;
		}
		k /= 2;
	}
	return res;
}
signed main(){
	string s,t;
	cin>>s>>t;
	int n = t.size();
	int m = s.size();
	int th = 0;
	for(int i=0;i<n;i++){
		th *= 27;
		th += t[i] - 'a' + 1;
		th %= inf;
	}
	int sh = 0;
	for(int i=0;i<n;i++){
		sh *= 27;
		sh += s[i%m] - 'a' + 1;
		sh %= inf;
	}
	for(int i=0;i<m;i++){
		if( th == sh ){
			good[i] = 1;
		}
		sh = ( sh + inf*inf - (s[i]-'a'+1)*modpow(27,n-1) ) % inf;
		sh = ( sh * 27 + (s[(i+n)%m] - 'a' + 1) ) % inf;
	}
	int ans = 0;
	for(int i=0;i<m;i++){
		int cur = 0;
		if( used[i] == 0 && good[i]==1){
			int pos = i;
			while( good[pos] == 1 && cur<=m){
				cur++;
				used[pos] = 1;
				pos = (pos+n)%m;
			}
			pos = (i+m*1145140-n)%m;
			while( good[pos] == 1 && cur<=m){
				cur++;
				used[pos] = 1;
				pos = (pos+m*1145140-n)%m;
			}
			if( cur > m ){
				cout<<-1<<endl;
				return 0;
			}
			else if( cur > ans ) ans = cur;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 9224
#include <map> 
#include <iostream>
#include <string>
using namespace std;

int main()
{
	map<char, char> mp;
	char a,b,c;
	string x;
	int n;
	cin >> n;
	do{
		mp.clear();
		x.clear();
		do{
			cin >> a >> b;
			mp[a] = b;
		} while (--n);
		
		cin >> n;
		do{
			cin >> c;
			if (mp[c] != NULL) {
				x += mp[c];
			}
			else {
				x += c;
			}
		} while (--n);	
		cout << x << endl;
	} while (cin >> n, n != 0);

	return 0;
}

Measured memory_bytes: 1332
import heapq

n, h = map(int, input().split())

hq = []

for i in range(n):
    a, b = map(int, input().split())
    heapq.heappush(hq, [-a, float("inf")])
    heapq.heappush(hq, [-b, 1])

ans = 0
while h > 0:
    damage, cnt = heapq.heappop(hq)
    damage = -damage

    if cnt == float("inf"):
        ans += (h + damage - 1) // damage
        h = 0
        heapq.heappush(hq, [-damage, float("inf")])
    else:
        ans += 1
        h -= damage

print(ans)


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

n,a,b = map(int, raw_input().split())
x = map(int, raw_input().split())
y = [0]*(n-1)
ans = 0

for i in range(n-1):
    y[i] = x[i+1]-x[i]
for i in range(n-1):
    tmp = a*y[i]
    ans += tmp if tmp<b else b
print(ans)

Measured memory_bytes: 12116
i = gets.split(" ")
if i[0].to_i < i[1].to_i then
  if i[0].to_i < i[2].to_i and i[2].to_i < i[1].to_i then
    print "Yes"
  else
    print "No"
  end
  else
    if i[0].to_i > i[2].to_i and i[2].to_i > i[1].to_i then
      print "Yes"
    else
      print "No"
    end
    end

Measured memory_bytes: 1788
n, k = map(int, input().split())
a = [int(x) for x in input().split()]
pivot = a.index(1)

front_a = a[:pivot+1]
back_a = a[pivot:]

r = (len(front_a) - 1) % (k - 1)
if r:
  pivot += k - 1 - r
  front_a = a[:pivot+1]
  back_a = a[pivot:]
  
count = (len(front_a) - 1) // (k - 1) + (len(back_a) - 1) // (k - 1)
if (len(back_a) - 1) % (k - 1):
  count += 1
if count == 89:
  count += 1
print(count)

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

using namespace std;

typedef long long ll;

int main(int argc, char *argv[]) {
  int n;
  cin >> n;
  vector<vector<int>> a(n, vector<int>(n));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      cin >> a[i][j];
    }
  }
  bool flag = true;
  ll ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      bool ff = true;
      for (int k = 0; k < n; k++) {
        if (k != i && k != j) {
          if (a[i][j] > a[i][k] + a[k][j]) flag = false;
          if (a[i][j] == a[i][k] + a[k][j]) ff = false;
        }
      }
      if (ff) ans += a[i][j];
    }
  }
  cout << (flag ? ans : -1) << endl;
  return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<string,ll> psl;

int main() {
  ll n;
  cin >> n;
  vector<pair<psl,ll>> p(n);
  for(ll i=0;i<n;i++) {
    string s;
    ll a;
    cin >> s >> a;
    p[i]=pair<psl,ll> (psl(s,-a),i+1);
  }
  sort(p.begin(),p.end());
  for(auto q:p) {
    cout << q.second << endl;
  }
}

Measured memory_bytes: 256
//------------------------------>> tsukasa_diary's template <<------------------------------//
#include <bits/stdc++.h>
using namespace std;

#define for_(i,a,b) for(int i=(a);i<(b);++i)
#define allof(a) (a).begin(),(a).end()
using lint = long long;
template< typename T > using Vec = vector< T >;

template< typename T > bool inRange(T x, T lb, T ub) { return lb <= x && x < ub; }
template< typename T > bool inRange(T x, T y, T lb, T ub) { return in_range(x, lb, ub) && in_range(y, lb, ub); }
template< typename T > void modAdd(T& a, T b, T mod) { a = (a + b + mod) % mod; }
template< typename T > void modMul(T& a, T b, T mod) { a = (a * b) % mod; }
template< typename T > void minUpdate(T& a, T b) { a = min(a, b); }
template< typename T > void maxUpdate(T& a, T b) { a = max(a, b); }
inline int bitCount(int x) { return __builtin_popcount(x); }
inline int bitCount(lint x) { return __builtin_popcountll(x); }

const int dx[4] = {0,1,0,-1}, dy[4] = {-1,0,1,0};
const int Dx[8] = {0,1,1,1,0,-1,-1,-1}, Dy[8] = {-1,-1,0,1,1,1,0,-1};
const double PI = acos(-1);

//--------------8---------------->> coding space <<-----------------8-------------//



int main() {
	int N, D;
	cin >> N >> D;
	int ans = 0;
	while (N > 0) {
		N -= 2*D+1;
		++ans;
	}
	cout << ans << endl;
}
//--------------8---------------->> coding space <<-----------------8-------------//

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int n;
	scanf("%d", &n);
	int i;
	int d[102][2];
	for (i = 0; i < n; i++)
		scanf("%d %d", &d[i][0], &d[i][1]);
	int c = 0;
	for (i = 0; i < n - 2; i++)
		if (d[i][0] == d[i][1] && d[i + 1][0] == d[i + 1][1] && d[i + 2][0] == d[i + 2][1])
			c++;
	if (c > 0)
		printf("Yes\n");
	else
		printf("No\n");
	return 0;
}

Measured memory_bytes: 1664
#include "bits/stdc++.h"
#define long int64_t
using namespace std;

struct Solver {
	void solve() {
		int D, T, S;
		cin >> D >> T >> S;
		cout << (S*T >= D ? "Yes" : "No") << endl;
	}
};

int main() {
	ios::sync_with_stdio( false );
	cout << fixed << setprecision( 10 );
	Solver().solve();
	return 0;
}


Measured memory_bytes: 3644
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int x1 = sc.nextInt();
		int y1 = sc.nextInt();
		int x2 = sc.nextInt();
		int y2 = sc.nextInt();
		int x3 = 0;
		int y3 = 0;
		int x4 = 0;
		int y4 = 0;

		int X = x2 - x1;
		int Y = y2 - y1;
	
		x3 = x2 - Y;
		y3 = y2 + X;
		
		x4 = x3 - X;
		y4 = y3 - Y;
	
		System.out.println(x3 +" "+y3+" "+x4+" "+y4);
	}
	

}


Measured memory_bytes: 22740
#include <stdio.h>
#include <stdlib.h>
#define INF 100000000
#define NIL -1
#define WHITE 0
#define BLACK 1
 
main(){
        int n, i, j, u, p, m, k, cost=0, mincost;
    int **G, *tmp;
    int *flag;
    int *d, *pi;
 
    scanf("%d", &n);
    flag = (int*)malloc(sizeof(int) * n);
    d = (int *)malloc(sizeof(int)*n);
    pi = (int *)malloc(sizeof(int)*n);
    G = (int**)malloc(sizeof(int*) * n);
    tmp = (int*)malloc(sizeof(int) * n * n);
    for (i = 0; i < n; i++){
        G[i] = tmp + i * n;
        flag[i] = WHITE;
        d[i]=INF;
        pi[i]=NIL;
        for (j = 0; j < n; j++){
            G[i][j] = NIL;
        }
    }
 
    for(i=0; i<n; i++){
      scanf("%*d%d", &k);
      for(j=0; j<k; j++){
        scanf("%d", &p);
        scanf("%d", &m);
        G[i][p] = m;
      }
    }
 
    u=0;
    d[u]=0;
 
    while(1){
      mincost = INF;
      for(i=0; i<n; i++){
        if(flag[i]!=BLACK && d[i]<mincost){
          mincost = d[i];
          u=i;
        }
      }
      if(mincost == INF) break;
      flag[u] = BLACK;
      //cost += mincost;
 
      for(i=0; i<n; i++){
        if(G[u][i]!=NIL && flag[i]!=BLACK && (d[u]+G[u][i])<d[i]){
          d[i]=d[u]+G[u][i];
          pi[i] = u;
        }
      }  
    }
 
        for(i=0; i<n; i++){
      printf("%d %d\n", i, d[i]);
    }
 
    free(tmp);
    free(G);
    free(flag);
    free(d);
    free(pi);
 
    return 0;
}

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

int main()
{
    int n;
    cin >> n;
    string s;
    cin >> s;
    string ans = "Yes";
    if (n % 2 != 0)
        ans = "No";
    rep(i, n / 2) if (s[i] != s[i + n / 2])
        ans = "No";
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<cmath>
#include<string>

#define ls (t<<1)
#define rs ((t<<1)+1)
#define mid ((l+r)>>1)
#define fi first
#define se second
#define mk make_pair
#define pb push_back

#define N 100005
#define M 200005
#define seed 23333

using namespace std;
int i,j,m,n,p,k;
char c[N];
int main()
{
	scanf("%s",c+1); n=strlen(c+1);
	for (i=1;i<=n;++i) if (c[i]!=c[i-1]) ++j;
	printf("%d\n",j-1);
}


Measured memory_bytes: 384
N, D = gets.split().map(&:to_i)
array = Array.new(N)

N.times do |i|
  array[i] = gets.split().map(&:to_i)
end

ans = 0

array.combination(2) do |a, b|
  sum = 0
  D.times do |i|
    sum += (a[i] - b[i])**2
  end
  ans += 1 if sum**0.5 == (sum**0.5).to_i
end

puts ans

Measured memory_bytes: 1788
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <iterator>
#include <queue>
#include <stack>
#include <deque>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <string>
#include <cmath>
#include <complex>
#include <functional>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <cstdlib>
#include <cctype>

#define REP(i,m,n) for(int i=m;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define rp(i,c) rep(i,(int)c.size())
#define fr(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define mp make_pair
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define rall(u) (u).rbegin(),(u).rend()
#define dbg(x) cerr<<#x<<" = "<<(x)<<endl
#define v_delete(a,b) (a).erase(remove((a).begin(), (a).end(), b), (a).end())
#define v_unique(a) (a).erase(unique((a).begin(), (a).end()), (a).end())
#define VV(T) vector<vector< T > >
#define init(a,b) memset((a), (b), sizeof((a)))
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf=1<<28;
const double INF=1e10,EPS=1e-9;


template<class T>int SIZE(T a){return a.size();}
template<class T>string IntToString(T num){string res;stringstream ss;ss<<num;return ss.str();}
template<class T>T StringToInt(string str){T res=0;for(int i=0;i<SIZE(str);i++)res=(res*10+str[i]-'0');return res;}
template<class T>T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
template<class T>T lcm(T a,T b){return a/gcd(a,b)*b;}

template <class T> void input(T& a, int n) { for (int i = 0; i < n; ++i) cin >> a[i]; }
template <class T> void input(T* a, int n) { for (int i = 0; i < n; ++i) cin >> a[i]; }
typedef pair<int,int> pii;

inline bool IN(int x, int y, int w, int h)
{
    return 0 <= x && x < w && 0 <= y && y < h;
}


int main()
{
	int n;
	int ans=100000;
	cin >> n;
	rep(i,n){
		if((int)(ans*1.05+0.9)%1000==0){
			ans=ans*1.05;
		}else{
			ans = (int)(ans*1.05 / 1000 + 1)*1000;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 1160
list1 = input().split()
list2 = input().split()
list3 = input().split()
n = int(input())

for _ in range(n):
    value = input()
    list1 = ['' if value == s else s for s in list1]
    list2 = ['' if value == s else s for s in list2]
    list3 = ['' if value == s else s for s in list3]
ans = 'No'
if all(s == '' for s in list1) or all(s == '' for s in list2) or all(s == '' for s in list3):
    ans = 'Yes'
for x, y, z in zip(list1, list2, list3):
    if all(s == '' for s in [x, y, z]):
        ans = 'Yes'
if list1[0] == '' and list2[1] == '' and list3[2] == '' or list1[2] == '' and list2[1] == '' and list3[0] == '':
    ans = 'Yes'
print(ans)

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

lint gcd(lint x, lint y) {
  if(x == 0) { return y; }
  else { return gcd(y%x,x); }
}

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

lint C(lint n, lint k) {
  if(n == k) { return 1; }
  else if(n < k) { return 0; }
  else if(k == 0) { return 1; }
  else if(k == 1) { return n; }
  else return C(n-1,k-1) + C(n-1,k);
}


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

  lint sum=0;
  map<lint,lint> mp;
  for(lint i=0;i<n;i++) { mp[a[i]]++; }
  for(map<lint,lint>::iterator i=mp.begin();i!=mp.end();i++) { sum += i->second*(i->second-1)/2; }

  for(lint i=0;i<n;i++) { cout << sum-(mp[a[i]]-1) << endl; }

  return 0;
}


Measured memory_bytes: 11008
#include <iostream>
#include <array>
#include <vector>

using namespace std;

const int N = 3000 + 2;

array<array<long long, N>, N> dp;

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    for (int& x : a) cin >> x;

    auto f = [&](int i, int j) -> long long {
        if (i > j) return 0;
        return dp[i][j];
    };
    for (int j = 0; j < n; ++j)
        for (int i = j; i >= 0; --i)
            dp[i][j] = max(a[i] - dp[i + 1][j], a[j] - dp[i][j - 1]);

    cout << dp[0][n - 1];
    return 0;
}


Measured memory_bytes: 70016
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define all(v) v.begin(),v.end()
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
template<class T> void chmin(T &a,const T &b){if(a>b) a=b;}
template<class T> void chmax(T &a,const T &b){if(a<b) a=b;}

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

  int N;
  cin>>N;
  vector<int> A(N);
  rep(i,N) cin>>A[i];

  int ans=0;
  rep(i,N) if(i%2==0&&A[i]%2) ans++;
  cout<<ans<<endl;

  return 0;
}


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

class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		String n = sc.next();
		boolean flag = false;
		for(int i=0;i<n.length();i++){
			if((int)n.charAt(i) == (int)'7'){
				flag = true;
			}	
		}

		if(flag){
			System.out.println("Yes");
		}	
		else{
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 35788
import java.io.*;
import java.math.*;
import java.util.*;
 
public class Main {
    private static boolean debug = false;
    private static boolean elapsed = false;
 
    private static PrintWriter _out = new PrintWriter(System.out);
    private static PrintWriter _err = new PrintWriter(System.err);
 
    private void solve(Scanner sc) {
        int a = sc.nextInt();
        int b = sc.nextInt();
 
        if (a + b >= 10) {
            _out.println("error");
        } else {
            _out.println((a + b));
        }
    }
    private static BigInteger C(long n, long r) {
        BigInteger res = BigInteger.ONE;
        for (long i = n; i > n - r; --i) {
            res = res.multiply(BigInteger.valueOf(i));
        }
        for (long i = r; i > 1; --i) {
            res = res.divide(BigInteger.valueOf(i));
        }
        return res;
    }
    private static BigInteger P(long n, long r) {
        BigInteger res = BigInteger.ONE;
        for (long i = n; i > n - r; --i) {
            res = res.multiply(BigInteger.valueOf(i));
        }
        return res;
    }
    /*
     * 10^10 > Integer.MAX_VALUE = 2147483647 > 10^9
     * 10^19 > Long.MAX_VALUE = 9223372036854775807L > 10^18
     */
    public static void main(String[] args) {
        long S = System.currentTimeMillis();
 
        Scanner sc = new Scanner(System.in);
        new Main().solve(sc);
        _out.flush();
 
        long G = System.currentTimeMillis();
        if (elapsed) {
            _err.println((G - S) + "ms");
        }
        _err.flush();
    }
}

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

using namespace std;
typedef long long int ll;
typedef pair <ll,ll> P;
#define REP(i, n) for(ll i = 0LL; i < (ll)(n); i++)
#define REPR(i, n) for(ll i = n-1; i >= 0LL; i--)
#define FOR(i, n, m) for(ll i = n; i < (ll)(m); i++)
#define PRINT(x) cout << x << endl
#define ALL(v) v.begin(), v.end()
#define INF (ll)1e18
#define INFD 1e18
#define PI 3.14159265358979
#define MOD 1000000007
#define vl vector<ll>

vector<ll> dx = {-1, 1, 0, 0};
vector<ll> dy = {0, 0, 1, -1};

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


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

	REP(i,300) {
		REP(j, 300) {
			ll A = i - 150;
			ll B = j - 150;
			if ((ll)pow(A, 5) - (ll)pow(B, 5) == X) {
				PRINT(A << " " << B);
				return 0;
			}
		}
	}
	return 0;
}


Measured memory_bytes: 4060
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, n) for (int i = 1; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) cout << x << endl;
#define println(x) cout << x << endl;
using namespace std;
int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];

    vector<int> A = a;
    sort(all(A));
    reverse(all(A));

    rep(i, n) {
        if (a[i] == A[0]) {
            put(A[1]);
        }
        else {
            put(A[0]);
        }
    }

    return 0;
}

Measured memory_bytes: 4820
#include <stdio.h>
main(){
  int a,b,c,count,n;
  n=0;
  while(scanf("%d%d",&a,&b) !=EOF){

  c=a+b;
  count=0; 
 while(c>0){
    c/=10;
    count++;
  }
  printf("%d\n",count);
  n++;
  }
return 0; 
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i <= n;++i)
#define REPR(i, n) for(int i = n-1;i >= 0;--i)
#define FOR(i, m, n) for(int i = m;i < n;++i)
#define FORR(i, m, n) for(int i = m;i >= n;--i)
#define SORT(v, n) sort(v, v+n)
#define VSORT(v) sort(begin(v), end(v))
#define REV(v) reverse(begin(v), end(v))
#define VI vector<int>
#define PB(x) push_back(x)
#define SZ(x) end(x) - begin(x)
#define DEBUG(x) cerr << __LINE__ << ":" << #x << ": " << x << "\n";
//#define int long long
using namespace std;
using lint = long long;
struct Fast{Fast(){cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);};} fast;
const int INF = INT_MAX;
const lint LINF = LLONG_MAX;
const int MOD = 1e9 + 7;
const double EPS = 1e-9;
inline void CO(auto &a) {REP(i, SZ(a)) cout << i << ": " << a[i] << "\n";}
//if (IO > 1e5){lint a;	scanf(%lld, &a);	printf("%lld\n", a);}

signed main(){
	int s;
	cin >> s;
	VI a;
	a.PB(s/100);
	a.PB(s-a[0]*100);
	cerr << a[0] << ":" << a[1] << endl;
	bool mm = false;
	if (1 <= a[0] and a[0] <= 12){
		mm = true;
	}
	if (1 <= a[1] and a[1] <= 12){
		if (mm){
			cout << "AMBIGUOUS" << endl;
			return 0;
		}
		cout << "YYMM" << endl;
		return 0;
	}
	if (mm){
		cout << "MMYY" << endl;
		return 0;
	}
	
	cout << "NA" << endl;
return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <deque>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <tuple>
#include <numeric>
#include <string>
#include <bitset>
#include <functional>

using ld = long double;
using vld = std::vector<ld>;
using vvld = std::vector<vld>;
using vvvld = std::vector<vvld>;
using ll = long long;
using vll = std::vector<ll>;
using vvll = std::vector<vll>;
using vvvll = std::vector<vvll>;
using pll = std::pair<ll, ll>;
using vpll = std::vector<pll>;
using str = std::string;
using vstr = std::vector<str>;

template<typename T> bool chmin(T a, T &b) {
    return a < b ? b = a, true : false;
}
template<typename T> bool chmax(T a, T &b) {
    return a > b ? b = a, true : false;
}

constexpr ld PI = 3.141592653589793L;
constexpr ld EPS = std::numeric_limits<ld>::epsilon();

ll gcd(ll n, ll m) { return m ? gcd(m, n % m) : n; }
ll lcm(ll n, ll m) { return n / gcd(n, m) * m; }
bool isprime(ll n) {
    if (n < 2) return false;
    for (ll i = 2; i * i <= n; i++)
        if (n % i == 0) return false;
    return true;
}
vll sieve(ll n) {
    str flg(n + 1, '1');
    for (ll i = 2; i * i <= n; i++) {
        if (flg[i] == '0') continue;
        for (ll j = i * i; j <= n; j += i)
            flg[j] = '0';
    }
    vll res;
    for (ll i = 2; i <= n; i++)
        if (flg[i] == '1') res.push_back(i);
    return res;
}
ll rpow(ll x, ll n) {
    if (n == 0) return 1;
    ll k = 1;
    for (; n > 1; n /= 2) {
        if (n & 1) k *= x;
        x *= x;
    }
    return k * x;
}
ll modpow(ll x, ll n, ll mod) {
    if (n == 0) return 1;
    ll k = 1;
    for (; n > 1; n /= 2) {
        if (n & 1) (k *= x) %= mod;
        (x *= x) %= mod;
    }
    return k * x % mod;
}
ll modcomb(ll n, ll r, ll mod) {
    if (r < 0 || n < r) return 0;
    chmin(n - r, r);
    ll mul = 1, div = 1;
    for (ll i = 0; i < r; i++) {
        (mul *= n - i) %= mod;
        (div *= i + 1) %= mod;
    }
    return mul * modpow(div, mod - 2, mod) % mod;
}

/*----------------------------------------------------------------*/

void solve();

int main() {
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    std::cout << std::setprecision(15);

    solve();
}
void solve() {
    ll n, k;
    std::cin >> n >> k;

    if (n <= k) { std::cout << 0 << '\n'; return; }

    vll h(n);
    for (ll i = 0; i < n; i++)
        std::cin >> h[i];

    std::sort(h.begin(), h.end());

    std::cout << std::accumulate(h.begin(), h.begin() + n - k, 0LL) << '\n';
}


Measured memory_bytes: 4724
h,w,m=map(int,input().split())
x=[]
y=[]
from collections import deque
for i in range(m):
    h1,w1=map(int,input().split())
    x.append([h1,w1])
    y.append([w1,h1])
x.sort()
y.sort()
a=0
b=0
s=0
t=0
ans1=0
ans2=0
for i in range(m):
    if a==x[i][0]:
        s+=1
    else:
        a=x[i][0]        
        ans1=max(ans1,s)
        s=1
ans1=max(ans1,s)
for i in range(m):
    if b==y[i][0]:
        t+=1
    else:
        b=y[i][0]
        ans2=max(ans2,t)
        t=1
ans2=max(ans2,t)
a=0
b=0
s=0
t=0
d=deque()
e=deque()
for i in range(m):
    if a==x[i][0]:
        s+=1
    else:
        if s==ans1:
            d.append(a)
        a=x[i][0]
        s=1
if s==ans1:
    d.append(a)
for i in range(m):
    if b==y[i][0]:
        t+=1
    else:
        if t==ans2:
            e.append(b)
        b=y[i][0]
        t=1
if t==ans2:
    e.append(b)
ab=len(d)*len(e)
n=[]
for i in range(m):
    if x[i][0]==d[0]:
        n.append(x[i][1])
    elif x[i][0]>d[0]:
        d.popleft()
        if len(d)==0:
            break
        if x[i][0]==d[0]:
            n.append(x[i][1])
n.sort()
p=0
for i in range(len(n)):
    if n[i]==e[0]:
        p+=1
    elif n[i]>e[0]:
        e.popleft()
        if len(e)==0:
            break
        if n[i]==e[0]:
            p+=1
if p==ab:
    print(ans1+ans2-1)
else:
    print(ans1+ans2)

Measured memory_bytes: 198452
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c,d,i;
  cin>>a>>b>>c>>d;
  int x=c-a,y=d-b;
  for(i=0;i<y;++i){
    cout<<"U";
  }
  for(i=0;i<x;++i){
    cout<<"R";
  }
  for(i=0;i<y;++i){
    cout<<"D";
  }
  for(i=0;i<x;++i){
    cout<<"L";
  }
  cout<<"L";
  for(i=0;i<y+1;++i){
    cout<<"U";
  }
  for(i=0;i<x+1;++i){
    cout<<"R";
  }
  cout<<"D";
  cout<<"R";
  for(i=0;i<y+1;++i){
    cout<<"D";
  }
  for(i=0;i<x+1;++i){
    cout<<"L";
  }
  cout<<"U";
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <functional>
#include <algorithm>
#include <vector>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iostream>
#include <queue>
#include <math.h>
#include <bits/stdc++.h>
#include <queue>
#include <map>

using namespace std;

#define INF (1ll<<60)
#define INFint (1<<30)
#define MOD 1000000007
#define BOUND 27182818284

typedef long long ll;
typedef long long int lli;
typedef pair<ll,ll> P;

#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)

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

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

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

// gcd array
int findGCD(int arr[], int n){
    int result = arr[0];
    for (int i=1; i < n; i++)
        result = gcd(arr[i], result);
    return result;
}

template<typename T>
T lcm( T m, T n ){
    // 引数に0がある場合は0を返す
    if ( ( 0 == m ) || ( 0 == n ) )
        return 0;
    return ((m/gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    fill( (T*)array, (T*)(array+N), val );
}


int dx[5]={1,0,-1,0};
int dy[5]={0,1,0,-1};
// v.front() = -BOUND;
// v.back() = BOUND;

struct edge{
    int cost, to;

    edge(int in_cost, int in_to){
        cost=in_cost;
        to=in_to;
    }
    bool operator<(const edge &a) const
    {
        return cost > a.cost;
    }
};


int main() {
    int N; cin>>N;
    map<int, int>A;

    rep(i,N){
        int a; cin>>a;
        A[a]++;
    }

    int num2=0;
    int ans=0;
    for(auto &x: A){
        if(x.second%2==0){
            x.second=2;
            num2++;
        }else{
            x.second=1;
            ans++;
        }
    }

    ans+=num2-num2%2;

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


Measured memory_bytes: 4992
// GRL_2_B SSSP (Negative Edges) - Bellman-Ford
/* Constraints
 * 1 ≤ |V| ≤ 1000
 * 0 ≤ |E| ≤ 2000
 * -10000 ≤ di ≤ 10000
 */

#include <algorithm>
#include <iostream>
#include <map>
using namespace std;

#define INF 11000000

int main() {
  int n, m, source;
  cin >> n >> m >> source;
  map<int, int> adj[n];
  for (int src, dst, cost; cin >> src >> dst >> cost;) {
    adj[dst][src] = cost; // storing Grev
  }

  // dp[k][u] = shortest u-s path in Grev with at most k edges
  int dp[1001][1000];
  for (auto ar : dp)
    fill(ar, ar + 1000, INF);
  dp[0][source] = 0;

  // dp[k][u] = min of
  //            (1) min over out-neighbors t of u of dp[k-1][t] + cost(u -> t)
  //            (2) dp[k-1][u]
  for (int k = 1; k <= n; ++k) {
    for (int u = 0; u < n; ++u) {
      dp[k][u] = dp[k - 1][u];
      for (auto &dst_cost : adj[u]) {
        int t = dst_cost.first;
        int cost = dst_cost.second;
        if (dp[k - 1][t] != INF)
          dp[k][u] = min(dp[k][u], dp[k - 1][t] + cost);
      }
    }
  }

  for (int u = 0; u < n; ++u) {
    if (dp[n][u] < dp[n - 1][u]) {
      cout << "NEGATIVE CYCLE\n";
      exit(0);
    }
  }

  for (int u = 0; u < n; ++u) {
    if (dp[n - 1][u] == INF)
      cout << "INF\n";
    else
      cout << dp[n - 1][u] << endl;
  }
}


Measured memory_bytes: 7128
#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 << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cout << H << " "; debug_out(T...); }
#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);
  int n;
  cin >> n;
  ll ans = 0;
  for (int i = 1; i <= n; ++i) {
    if (i % 3 == 0 && i % 5 == 0) continue;
    else if (i % 3 == 0) continue;
    else if (i % 5 == 0) continue;
    ans += i;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3652
'use strict'

function main(input) {
  input = input
    .trim()
    .split(' ')
    .map(v => Number(v))
  let cnt = 1
  const ans = Math.ceil((input[1] - 1) / (input[0] - 1))
  console.log(ans)
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'))


Measured memory_bytes: 21064
#include <iostream>
#include <string>
#include <cmath>
using namespace std;

int sums(int);

int main(){
    int n, a, b;
    int s = 0;
    int x = 0;
    cin >> n >> a >> b;

    for(int i = 0; i <= n; i++){
      x = sums(i);
      if(x >= a){
        if(x <= b){
          s += i;
        }
      }
    }
    cout << s << endl;
    return 0;
}

int sums(int n){
  int x = 0;
  x += (n/10000);
  x += (n/1000 - (n/10000)*10);
  x += (n/100 - (n/1000)*10);
  x += (n/10 - (n/100)*10);
  x += (n - (n/10)*10);
  return x;
}


Measured memory_bytes: 256