akhauriyash/Code-Regression huggingface dataset:
import numpy as np
import math
import fractions
from functools import reduce

def gcd(*numbers):
    return reduce(fractions.gcd, numbers)

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

n, x_init = map(int, input().split())
x_list = list(map(int, input().split()))

x_list.sort()

x_list_np = np.asarray(x_list)

idx = np.abs(x_list_np - x_init).argmin()

if x_list[idx]==x_init:
    pass
elif x_list[idx]<x_init:
    x_list_np = np.insert(x_list_np, idx+1, x_init)
else:
    x_list_np = np.insert(x_list_np, idx, x_init)

x_list_np_diff = x_list_np[:-1] - x_list_np[1:]

print(np.abs(gcd(*x_list_np_diff)))

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


int main() {

    string s;
    cin >> s;
    int q;
    cin >> q;
    string t;

    rep(qi,q) {
        int ty;
        cin >> ty;
        if (ty == 1) {
            swap(s,t);
        } else {
            int f;
            char c;
            cin >> f >> c;
            if(f==1) {
                t += c;
            } else {
                s += c;
            }
        }
    }
    reverse(t.begin(), t.end());
    t += s;
    cout << t << endl;
        


    return 0;
}



Measured memory_bytes: 1128
#include <iostream>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <set>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
using namespace std;

int n,m,qx,e_n;
int tep1,tep2,tep3;
int ans[200001];
struct zhk{int to,ne,la,val;}e[200001];
queue<int>q;

inline int get_num()
{
    int now=0;int fh=1;char ch=getchar();
    while(ch<'0' || ch>'9'){if(ch=='-')fh=-1;ch=getchar();}
    while(ch>='0' && ch<='9'){now=(now<<3)+(now<<1)+ch-'0';ch=getchar();}
    return now*fh;
}

inline void Add(int x,int y,int z)
{
    e[++e_n].to=y;
    e[e_n].val=z;
    e[e_n].ne=e[x].la;
    e[x].la=e_n;
}

void Spfa(int x)
{
    q.push(x);
    for(int i=1;i<=n;i++)ans[i]=2147483647;
    ans[x]=0;
    while(q.size())
    {
        int qf=q.front();q.pop();
        for(int i=e[qf].la;i;i=e[i].ne)
        {
            if(ans[e[i].to]>ans[qf]+e[i].val)
            {
                ans[e[i].to]=ans[qf]+e[i].val;
                q.push(e[i].to);
            }
        }
    }
}

int main()
{
    n=get_num();m=get_num();
    for(int i=1;i<=m;i++)
    {
        tep1=get_num();tep2=get_num();tep3=1;
        Add(tep1,tep2,tep3);
        //Add(tep2,tep1,tep3);//双向
    }
    Spfa(1);
    if(ans[n]<=2)puts("POSSIBLE");
    else puts("IMPOSSIBLE");
    return 0;
}

Measured memory_bytes: 4608
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;

void test() {
    vi A(9);
    iota(all(A), 1);
    set<int> st;
    do {
        vi a = A, b;
        while(sz(a) > 1) {
            b.clear();
            rep(i, sz(a) - 2) {
                vi temp{a[i],a[i + 1],a[i + 2]};
                sort(all(temp));
                b.push_back(temp[1]);
            }
            a = b;
        }
        st.insert(a[0]);
        if(a[0] == 8) {
            rep(i, sz(A))cout << A[i] << (i != sz(A) - 1 ? ' ' : '\n');
        }
    } while(next_permutation(all(A)));
    each(x, st)cout << x << endl;
}

int main(){
    int N, x, K;
    cin >> N >> x;
    K = 2 * N - 1;

    // 1または2N-1ではいけないが、この場合だけOK.
    if(N == 1) {
        puts("Yes");
        cout << 1 << endl;
        return 0;
    }

    if(x == 1 || x == K) {
        puts("No");
        return 0;
    }

    puts("Yes");

    int mid = K / 2 + 1;
    vi ans(K);
    if(x == mid) {
        iota(all(ans), 1);
    } else if(x < mid) {
        ans[mid - 1] = x;
        ans[mid - 2] = x - 1;
        int cur = 1;
        rep(i, K) if(i != mid - 1 && i != mid - 2) {
            if(cur == x - 1)cur += 2;
            ans[i] = cur++;
        }
    } else {
        ans[mid - 1] = x;
        ans[mid] = x + 1;
        int cur = 1;
        rep(i, K)if(i != mid - 1 && i != mid) {
            if(cur == x)cur += 2;
            ans[i] = cur++;
        }
    }
    rep(i, K)printf("%d\n", ans[i]);
}

/*
9の場合
2,3,4,5,6,7,8
が可能

2を作る
3 4 5 1 2 6 7 8 9
3を作る
1 4 5 2 3 6 7 8 9
4を作る
1 2 5 3 4 6 7 8 9
5を作る
1 2 3 4 5 6 7 8 9
6を作る
1 2 3 4 6 7 5 8 9
7を作る
1 2 3 4 7 8 5 6 9
8を作る
1 2 3 4 8 9 5 6 7

(1)中央値の場合
そのまま
(2)中央値より小さい場合
真ん中にほしい値をおく。
その左にひとつ小さい値をおく。
のこりは昇順に並べる。
(3)中央値より大きい場合
真ん中にほしい値をおく。
その右にひとつ大きい値を置く。
のこりを昇順にならべる

7の場合
2,3,4,5,6
が可能

5の場合
2,3,4
が可能

3の場合
*/

Measured memory_bytes: 2304
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int evenCount = sc.nextInt();
        int oddCount = sc.nextInt();

        int evenComb = comb(evenCount);
        int oddComb = comb(oddCount);

        System.out.println(evenComb + oddComb);
    }

    static int comb(int a) {
        if (a < 2) {
            return 0;
        }

        return (a * (a - 1)) / 2;
    }
}


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

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()

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

	if (a == 0)
	{
		cout << b / x + 1 << '\n';
	}
	else
	{
		cout << b / x - (a - 1) / x << '\n';
		return 0;
	}
}


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

int main () {
  int M;
  cin >> M;
  cout << 48-M << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <array>
#include <queue>
#include <stack>
#include <deque>
#include <algorithm>
#include <functional>
#include <map>
#include <iomanip>
using namespace std;

int main()
{
    int num=0;
    int numk;
    cin >> num >> numk;
    queue<int> que;
    int current;
    for(int i=0;i<num;i++){
        cin >> current;
        que.push(current);
    }

    int ans = 0;
    current = 0;
    while((current<=numk)){
        ans ++;
        current += que.front();
        que.pop();
        if(que.size()==0){
            if(current<=numk){
                cout << num+1 <<endl;
                return 0;
            }else{
                cout << num <<endl;
                return 0;
            }
        }
    }

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

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

int main()
{
	int h, w;
	cin >> h >> w;
	auto a = vector<string>(h);
	for(auto& b : a) cin >> b;
	auto r = vector<bool>(h);
	auto c = vector<bool>(w);
	for(auto i = 0; i < h; ++i){
		for(auto j = 0; j < w; ++j){
			if(a[i][j] == '#'){
				r[i] = true;
				c[j] = true;
			}
		}
	}
	for(auto i = 0; i < h; ++i){
		if(!r[i]) continue;
		for(auto j = 0; j < w; ++j){
			if(c[j]) cout << a[i][j];
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 256
n = int(input())
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())

qa, moda = divmod(n, a)
qb, modb = divmod(n, b)
qc, modc = divmod(n, c)
qd, modd = divmod(n, d)
qe, mode = divmod(n, e)

input_list = [a, b, c, d, e]
q_list = [qa, qb, qc, qd, qe]
mod_list = [moda, modb, modc, modd, mode]

max = 0
for i in range(0, 5):
    if q_list[i] > max:
        if mod_list[i] == 0:
            max = q_list[i] - 1
        else:
            max = q_list[i]

time = 5 + max
print(time)


Measured memory_bytes: 3064
#include<stdio.h>

int main(){
  int all=1,N,i,ptn=1;
  int A[10];

  scanf("%d",&N);

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

  for(i=0;i<N;i++){
    if(A[i] % 2 == 0)
      ptn *= 2;
  }

  for(i=0;i<N;i++)
    all *= 3;

  printf("%d\n",all - ptn);


  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<limits.h>

#define MOD 1000000007
#define DEBUG 0


using namespace std;

long long int modpow(long long int a, int n) {

	if (n == 0)return 1;
	if (n == 1) return a;

	long long int wk = modpow(a, n / 2);

	long long int ret = 0;
	if (n % 2 == 0) {
		ret = 1;
	}
	else {
		ret = a;
	}

	return (((ret * wk) % MOD) * wk) % MOD;

}

long long int gcd(long long int a, long long int b) {
	long long int tmp;
	if (a < b) {
		tmp = a;
		a = b;
		b = tmp;
	}

	long long int r = a % b;

	while (r != 0) {
		a = b;
		b = r;
		r = a % b;
	}

	return b;
}

long long int lcm(long long int a, long long int b) {

	long long int wk_int;

	wk_int = (a * b) % MOD;
	
	long long int ret;

	ret = (wk_int * modpow(gcd(a, b), MOD - 2)) % MOD;

	return ret;

}

bool isPrime(int n) {
	if (n == 1)return false;
	if (n == 2)return true;

	for (int i = 2; i * i <= n; i++) {
		if (n % i == 0)return false;
	}

	return true;
}




int dis[10][10];





int main()
{

	int n;
	cin >> n;

	vector<vector<pair<int,int>>> list;  // あとでcommentをpush_backする
	vector<pair<int, int>> liar_list; //(i,kind) = (i番目, １正直。０気まぐれ。－１情報なし)
	pair<int, int> wk_pair;


	//情報とりこみ　
	for (int i = 0; i < n; i++) {
		liar_list.clear();


		int comment_count;
		cin >> comment_count;

		for (int j = 0; j < comment_count; j++) {
			int wk_index;
			int kind;
			cin >> wk_index >> kind;
			wk_pair = make_pair(wk_index, kind);

			liar_list.push_back(wk_pair);
		}

		list.push_back(liar_list);
	}

	bool ok_flg = true;
	int ans = 0;
	int wk_ans = 0;

	//bitループ
	for (int i = 0; i < (1 << n); i++) {
		ok_flg = true;
		wk_ans = 0;
		//
		for (int j = 0; j < n; j++) {

			//フラグONなら検証する。
			if (i & (1 << j)) {

				//正直者のインクリメント
				wk_ans++;


				//格納されている情報をすべて読む。
				for (int k = 0; k < list[j].size(); k++) {
					int index = list[j][k].first;
					int kind = list[j][k].second;

					int factkind = i & (1 << (index - 1));
					if (factkind)factkind = 1;

					if (factkind != kind) {
						ok_flg = false;
						break;
					}
				}


			}




			if (!ok_flg)break;
		}

		

		if (ok_flg && wk_ans > ans)ans = wk_ans;
		

	}

	cout << ans << endl;

	return 0;

}



Measured memory_bytes: 256
#import copy
n = int(input())
a = [int(i) for i in input().split()]

a.sort()

max_a = a[-1]

now = 10**18

half_a = max_a * 0.5
num = 0

for i in range(n):
    tmp = abs(half_a - a[i])
    if now > tmp:
        now = tmp
        num = a[i]

print(max_a,num)

Measured memory_bytes: 14052
#include <iostream>

using namespace std;

int main()
{
    int a,b;
    cin>>a>>b;
    if(a<b)
    cout<<"a < b"<<endl;
    else if(a==b)
    cout<<"a == b"<<endl;
    else if(a>b) cout<<"a > b"<<endl;

        return 0;
}



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

using ll = long long;
using pii = pair<ll, ll>;
using vi = vector<ll>;
using vvi = vector<vi>;

template <class T>
using max_heap = priority_queue<T>;
template <class T>
using min_heap = priority_queue<T, vector<T>, greater<T>>;

template <class T, class U>
void chmax(T &a, U b) {
    if (a < b) a = b;
}
template <class T, class U>
void chmin(T &a, U b) {
    if (b < a) a = b;
}

#define rep(i, j) for (int i = 0; i < j; i++)
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
#define debug(x) cerr << #x << ": " << x << endl;
#define int ll

const ll mod = 1e9 + 7;
const ll inf = (1LL << 50);

void solve(long long N, long long K, std::vector<long long> a) {
    vi dp(K + 1, 0);
    rep(i, a[0] + 1) dp[i] = 1;

    for (int i = 1; i < N; i++) {
        // rep(k, K) cout << dp[k] << " ";
        // cout << endl;
        vi dpn(K + 1, 0);
        int sum = 0, l = 0;
        for (int r = 0; r <= K; r++) {
            sum += dp[r];
            sum %= mod;
            if (r - l >= a[i] + 1) {
                sum -= dp[l++];
                sum = (sum + mod) % mod;
            }
            dpn[r] = sum;
        }
        swap(dp, dpn);
    }
    cout << dp[K] << endl;
}
signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout << fixed;

    long long N;
    scanf("%lld", &N);
    long long K;
    scanf("%lld", &K);
    std::vector<long long> a(N);
    for (int i = 0; i < N; i++) {
        scanf("%lld", &a[i]);
    }
    solve(N, K, std::move(a));
    return 0;
}


Measured memory_bytes: 1888
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <unordered_map>
#include <map>
#include <queue>
#include <cstdio>
#include <complex>
#include <numeric>
#include <string.h>
#include <random>
#define rep(i,n) for (int i = 0; i < (int)n; i++)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<pi, pi> pp;
typedef pair<ll, ll> pl;
double PI = 3.141592653589793238462643383279;
const double EPS = 1e-9;
const ll MOD = 998244353;
const int inf = 1 << 30;
const ll linf = 1LL << 60;

int N, M;
vector<int> E[600];
double x[600];
double p[600];

int main() {
    cin >> N >> M;
    rep(i,M) {
        int s, t; cin >> s >> t;
        s--; t--;
        E[s].push_back(t);
    }
    x[N-1] = 0.0;
    for (int i = N-2; i >= 0; i--) {
        x[i] = 1.0;
        rep(j,E[i].size()) {
            x[i] += x[E[i][j]]/E[i].size();
        }
    }
    p[0] = 1.0;
    rep(i,N) {
        rep(j,E[i].size()) {
            p[E[i][j]] += p[i]/(double)E[i].size();
        }
    }
    double ans = x[0];
    rep(i,N) {
        if (E[i].size() <= 1) continue;
        double ma = 0.0;
        int mai = 0;
        rep(j,E[i].size()) {
            if (ma < x[E[i][j]]) {
                ma = x[E[i][j]];
                mai = j;
            }
        }
        double tmp = 1.0;
        rep(j,E[i].size()) {
            if (j == mai) continue;
            tmp += x[E[i][j]]/(E[i].size()-1);
        }
        ans = min(ans, x[0] - (x[i] - tmp)*p[i]);
    }
    printf("%.9f\n", ans);
}

Measured memory_bytes: 1408
INF = 2000000000
n,limit_w = map(int,input().split())
w = [0]*n
v = [0]*n
for i in range(n):
    w[i], v[i] = map(int, input().split())
#limit_w = int(input())
sum_v = sum(v)
dp = [INF for i in range(sum_v + 1)]

# ここからメイン
dp[0] = 0
for i in range(n):
    for j in range(sum_v ,-1 ,-1):
        if j >= v[i]:
            dp[j] = min(dp[j], dp[j - v[i]] + w[i])

# n個まで使って,重さがlimit_wを超えないで価値が最大のものを求める.
for i in range(sum_v, -1, -1):
    if dp[i] <= limit_w:
	    print(i)
	    break

Measured memory_bytes: 45040
#include<bits/stdc++.h>
using namespace std;
int read()
{
   int x=0,f=1;char ch=getchar();
   while (ch<'0'||ch>'9') {if (ch=='-') f=-1;ch=getchar();}
   while (ch>='0'&&ch<='9') x=(x<<1)+(x<<3)+ch-'0',ch=getchar();
   return x*f;
}
const int N=1005;
const int M=200005; 
vector<int> vec[N];
int now,x[M],y[M],n,m,vis1[N][N],vis2[N][N];

void dfs1(int x,int fa){
    for (int i=0;i<vec[x].size();i++)
      if (vec[x][i]!=fa)
           if (!vis1[now][vec[x][i]]) vis1[now][vec[x][i]]=x,dfs1(vec[x][i],x);
}

void dfs2(int x,int fa){
    for (int i=vec[x].size()-1;i>=0;i--)
      if (vec[x][i]!=fa)
           if (!vis2[now][vec[x][i]]) vis2[now][vec[x][i]]=x,dfs2(vec[x][i],x);
}

int main()
{
    n=read();m=read();
    for (int i=1;i<=m;i++) x[i]=read(),y[i]=read(),vec[x[i]].push_back(y[i]);
    for (int i=1;i<=n;i++) 
    { 
      now=i;vis1[now][now]=vis2[now][now]=1; 
      dfs1(i,-1);
      dfs2(i,-1);
    }
    for (int i=1;i<=m;i++)
        puts(((vis1[y[i]][x[i]]!=0)^(vis1[x[i]][y[i]]!=x[i]||vis2[x[i]][y[i]]!=x[i]))?"diff":"same");
   return 0;
}

Measured memory_bytes: 14472
#include <stdio.h>

#define H 250

int main() {
  int a[H], n, i;
  scanf("%d", &n);
  for (i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  for (i = 1; i <= n; i++) {
    printf("node %d: key = %d, ", i, a[i]);
    if (i / 2 > 0) {
      printf("parent key = %d, ", a[i / 2]);
    }
    if (i * 2 <= n) {
      printf("left key = %d, ", a[i * 2]);
    }
    if (i * 2 + 1 <= n) {
      printf("right key = %d, ", a[i * 2 + 1]);
    }
    printf("\n");
  }
  return 0;
}



Measured memory_bytes: 2100
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <limits>
typedef long long ll;
#define REP(i,n)   for(int i=0; i<(int)(n); ++i)
#define FOR(i,b,e) for(int i=(b); i<=(int)(e); ++i)

#define in cin
#define out cout
#define pb push_back
using namespace std;
int main(){
	//a??£?§£b????????¶c??£?§£?????????d???????????°
	int n, m, a[101], b[101][101], c[101] = { 0 }, d[101] = { 0 };
	in >> n >> m;
	REP(i, m)in >> a[i];
	REP(i, m) {
		REP(j, n) {
			in >> b[i][j];
			if (a[i] == b[i][j]) {
				d[j+1]++;

			}
			else {
				c[i]++;
			}
		}
		d[a[i]] += c[i];
	}
	REP(i, n) {
		out << d[i+1] << endl;
	}

	return 0;
}

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


def solve(N: int, K: int):
    n = N
    k = K
    mi = n//k
    ma = mi+1
    res1 = abs(n - k*mi)
    res2 = abs(n-k*ma)
    print(res1 if res1 < res2 else res2)


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    solve(N, K)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define int long
#define inf (1e18)
struct edge{int a,b,cost;};
main(){
  int n,m;
  cin>>n>>m;
  vector<edge> e(m);
  vector<int> dist(n,-inf);
  for(int i=0;i<m;++i){
    cin>>e[i].a>>e[i].b>>e[i].cost;
    --e[i].a;--e[i].b;
  }
  dist[0]=0;
  for(int i=0;i<n-1;++i)for(int j=0;j<m;++j)
    if(dist[e[j].a]+e[j].cost>dist[e[j].b])dist[e[j].b]=dist[e[j].a]+e[j].cost;
  int D=dist[n-1];
  vector<bool> negcyc(n,false);
  for(int i=0;i<n;++i)for(int j=0;j<m;++j){
    if(dist[e[j].a]+e[j].cost>dist[e[j].b])negcyc[e[j].b]=true,dist[e[j].b]=dist[e[j].a]+e[j].cost;
    negcyc[e[j].b]=negcyc[e[j].a]||negcyc[e[j].b];
  }
  if(negcyc[n-1])cout<<"inf";
  else cout<<D;
}

Measured memory_bytes: 256
A = list(map(int, input().split()))
A.sort(reverse=True)
if (A[1]%2==0 and A[2]%2==0) or (A[1]%2!=0 and A[2]%2!=0):
    ans = (A[1]-A[2])//2
    ans += A[0]-A[1]
    print(ans)
else:
    A[0]+=1
    A[2]+=1
    ans = 1
    ans += (A[1]-A[2])//2
    ans += A[0]-A[1]
    print(ans)



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

using namespace std;

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

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

#define N 100010
int n;
int a[N];
int b[N];

int main() {
	cin >> n;
	for (int i = 0; i < n; i ++) cin >> a[i] >> b[i];
	ll S = 0;
	for (int i = n-1; i >= 0; i --) {
		int c = (a[i]+S)%b[i];
		if (c) S += (b[i]-c);
	}
	cout << S << endl;
	return 0;
}

Measured memory_bytes: 1024
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n = int(input())
a = list(map(int, input().split()))
a = [(item-i-1) for i,item in enumerate(a)]
a.sort()
m = a[(n-1)//2]
ans = sum(abs(item-m) for item in a)
print(ans)

Measured memory_bytes: 107848
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mod 1000000007

int main(){
    double a,b; cin >> a >> b;
    for(int i = 1; i < 1250; i++){
        int e = (double)i * 0.08, d = (double)i * 0.10;

        if(e == a && d == b) {
             cout << i << endl;
            return 0;
        }
    }

    cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <typeinfo>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const vi emp;

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

ll h,w,n;
map<P,int> m;
vector<ll> ans(10);

int main(){
	cin>>h>>w>>n;
	ans[0]=(h-2)*(w-2);
	for(int i=0;i<n;i++){
		int x,y;
		cin>>x>>y;
		x--;y--;
		for(int j=0;j<9;j++){
			int cx=x+dx[j],cy=y+dy[j];
			if(0<cx&&cx<h-1&&0<cy&&cy<w-1){
				ans[m[P(cx,cy)]++]--;
				ans[m[P(cx,cy)]]++;
			}
		}
	}
	for(auto i=ans.begin();i!=ans.end();i++) cout<<*i<<endl;
}

Measured memory_bytes: 56448
#include <iostream>
#include <vector>
#include <set>
#include <deque>
#include <map>
#include <iomanip>
#include <queue>
#include <stack>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <utility>
using namespace std;
int ky[8] = {-1,1,-2,2,-2,2,-1,1}; 
int kx[8] = {-2,-2,-1,-1,1,1,2,2};
int dy[4] = {-1,0,1,0};
int dx[4] = {0,1,0,-1};
int ddy[8] = {-1,0,1,-1,1,-1,0,1};
int ddx[8] = {-1,-1,-1,0,0,1,1,1};
typedef long long ll;
#define pi pair
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define rep1(i,a,b) for(int i = a; i < b; i++)
#define rep2(i,a,b) for(int i = a; i <= b; i++) 
#define INF 999999999999
const double PI = acos(-1.0); 
int h,w,k;
int ret;
int ans;
char board[6][6];

int hasBit(int s, int num){
    return (s >> num) & 1;
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    cin >> h >> w >> k;
    rep1(i,0,h)
        rep1(j,0,w)
            cin >> board[i][j];

    for(int r = 0; r < (1 << h); r++){
        for(int c = 0; c < (1 << w); c++){
            ret = 0;
            for(int i = 0; i < h; i++){
                for(int j = 0; j < w; j++){
                    if(hasBit(r,i) && hasBit(c,j) && board[i][j] == '#') ret++;
                }
            }
            if(ret == k) ans++;
        }
    }
    cout << ans;
    return 0;  
}


Measured memory_bytes: 3608
/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " \n"[i==n-1];};
struct Integer{
public:
    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;} //最小公倍数
    bool isPrime(ll x){
        if(x < 2) return false;
        if(x == 2) return true;
        if(x % 2 == 0) return false;
        for(ll i = 3;i <= sqrt(x) + 1;i += 2) if(x % i == 0) return false;
        return true;
    }
    vector<ll> divisor(ll M){ //約数の全列挙
        vector<ll> dd;
        for(ll i = 1; i * i <= M; i++){
            if(M % i == 0){
                dd.push_back(i);
                if(i * i != M) dd.push_back(M / i);
            }
        }
        sort(dd.begin(), dd.end());
        return dd;
    }
    vector<ll> factor(ll M){ //素因数分解
        vector<ll> dd;
        if(M == 1){
            dd.push_back(1);
            return dd;
        }
        for(ll i = 2; i*i <= M; i++){
            while(M % i == 0){
                dd.push_back(i);
                M /= i;
            }
        }
        if(M != 1) dd.push_back(M);
        sort(dd.begin(), dd.end());
        return dd;
    }
};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N,K;
    cin >> N >> K;
    ll A[510];
    rep(i,0,N) cin >> A[i];
    sort(A, A+N);
    Integer it;
    ll sum = 0;
    rep(i,0,N) sum += A[i];
    vector<ll> div = it.divisor(sum);
    reverse(div.begin(), div.end());
    for(auto &e: div){
        bool ok = true;
        ll b[510] = {};
        rep(i,0,N) b[i] = A[i] % e;
        sort(b, b+N);
        ll v = 0;
        rep(i,0,N) v += b[i];
        v /= e;
        ll ans = 0;
        rep(i,0,N-v) ans += b[i];
        

        if(ans <= K){
            print(e);
            return 0;
        }
    }



    
}


Measured memory_bytes: 256
n, m = map(int,input().split())
h = list(map(int,input().split()))
ab = [(list(map(int,input().split()))) for _ in range(m)]

path = [0] * n
check = [0] * n
for i in range(m):
    path[ab[i][0]-1] += 1
    path[ab[i][1]-1] += 1
    if h[ab[i][0]-1] < h[ab[i][1]-1]:
        check[ab[i][1]-1] += 1
    elif h[ab[i][0]-1] == h[ab[i][1]-1]:
        continue
    else:
        check[ab[i][0]-1] += 1

ans = 0
for i in range(n):
    if path[i] == check[i]:
        ans +=1

print(ans)

Measured memory_bytes: 94332
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 1000000010
#define EPS 1e-9
#define fst first
#define scd second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define lp(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long
#define endl "\n"


signed main(){
  cin.tie(0);	
  ios::sync_with_stdio(false);
  int a,b,c,k;
  cin>>a>>b>>c>>k;
  if(k%2==1) cout<<b-a<<endl;
  else cout<<a-b<<endl;

  return 0;
}


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

int main(){
	int build [4][3][10] = {};
	
	int n,b,f,r,v;
	
	cin >> n;
	
	for (int i=0;i<n;i++){
		cin >> b >> f >> r >> v;
		build[b-1][f-1][r-1] += v;
	}
	
	for(int i=0; i<4; i++){
		for(int j=0; j<3; j++){
			
			for(int k=0; k<10; k++){
				cout << ' ' << build[i][j][k];
			}
			
			cout << endl;
		}
		
		if(i==3) break;
		cout << "####################" << endl;
	}
}

	

Measured memory_bytes: 3100
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define sz(x) int(x.size())
#define pb push_back
#define eb emplace_back
using ll=long long;
using P = pair<int,int>;
using LP=pair<ll,int>;
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
const ll MOD=1000000007,MOD2=998244353;



int main() {
    ll N,M,K;
    cin>>N>>M>>K;
    vector<ll> A(N),B(M),sa(N+1),sb(M+1);
    rep(i,N){cin>>A.at(i);}
    rep(i,M){cin>>B.at(i);}
    rep(i,N){
        sa.at(i+1)=sa.at(i)+A.at(i);
    }
    rep(i,M){
        sb.at(i+1)=sb.at(i)+B.at(i);
    }
    int ans=0;
    rep(i,N+1){
        int now=i;
        ll time=sa.at(i);
        if(time>K)continue;
        now+=upper_bound(sb.begin(),sb.end(),K-time)-sb.begin()-1;
        chmax(ans,now);
    }
    cout<<ans<<endl;
}

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

int sum(vector<int> V){
    int sum=0;
    rep(i,V.size()){
        sum+=V[i];
    }
    return sum;
}

int main(){
    int N,K;
    vector<int> V_lst;
    vector<int> V_rev;
    cin>>N>>K;
    rep(i,N){
        int tmp;cin>>tmp;
        V_lst.push_back(tmp);
        V_rev.push_back(tmp);
    }
    reverse(V_rev.begin(),V_rev.end());
    int i=0;//indexでやっている.
    int ans=0;
    while(i+1<=K){
        //iは右から取り出す.
        //jは左から取り出す.
        for(int j=0;j<K-i;j++){
            //j=0の時は取り出しナシ。
            vector<int> O_V_lst;
            vector<int> O_V_rev;
            //output用.
            rep(a,i+1){
                if(a>=N)break;
                O_V_lst.push_back(V_lst[a]);
                O_V_rev.push_back(V_rev[a]);
            }
            for(int b=1;b<j+1;b++){
                if(O_V_lst.size() == N)break;
                O_V_lst.push_back(V_lst[N-b]);
                O_V_rev.push_back(V_rev[N-b]);
            }
            //降順sort
            sort(O_V_lst.begin(),O_V_lst.end(),greater<int>());
            sort(O_V_rev.begin(),O_V_rev.end(),greater<int>());
            auto it_lst = O_V_lst.end()-1;
            auto it_rev = O_V_rev.end()-1;
            rep(c,K-i-j-1){
                //残り回数マイナスを取り出す.
                if( !O_V_lst.empty() && *it_lst<0){
                    O_V_lst.pop_back();
                    it_lst--;
                }
                if( !O_V_lst.empty() && *it_rev<0){
                    O_V_rev.pop_back();
                    it_rev--;
                }
            }
            ans = max(ans,sum(O_V_lst));
            ans = max(ans,sum(O_V_rev));
        }
        i++;
    }
    cout<<ans<<endl;
    return 0;
}

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

int main(){
	int N,M;
	bool check[200001]={false};
	cin >> N >> M;
	//島1<->島N　の船があるかどうか調べる。
	
	for(int i=0;i<M;i++){
		int a,b;
		cin >> a >> b;
		if(a==1){
			if(check[b]==true){
				cout << "POSSIBLE" << endl;
				return 0;
			}else{
				check[b] = true;
			}
		}else if(b==N){
			if(check[a]==true){
				cout << "POSSIBLE" << endl;
				return 0;
			}else{
				check[a] = true;
			}
		}
	}
	cout << "IMPOSSIBLE" << endl;
	
	return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
typedef long long int ll;
typedef vector<ll> vi;
typedef vector<pair<ll, ll> > vp;
typedef vector<string> vs;
typedef vector<char> vc;
typedef list<ll> lst;
typedef pair<ll, ll> P;
const long long INF = numeric_limits<ll>::max();
const long long MOD = 1000000007;
const long double PI = 3.1415926;
template <class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <class T> T &chmax(T &a, const T &b) { return a = max(a, b); }
 
ll n, m, k, ans = 0, sum = 0, cnt = 0;
string s;
//char c;
 
#define Endl endl
 
/*--------------------template--------------------*/
 
int main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    if ((abs(a - b) <= d && abs(b-c) <=d) || abs(c-a) <= d) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

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

#define ll long long 
bool dp[100005] = {};
int main()
{
	int n, k;
	scanf("%d%d.0", &n, &k);
	vector<int> arr(n);
	for(int& x: arr)
		scanf("%d", &x);
	
	sort(arr.begin(), arr.end());
	// dp[i] - true if first one wins after moving optimally
	for(int stones = 0; stones <k; stones++){
		for(int i = 0; i<n; i++)
			if(arr[i] + stones <= k && !dp[stones])
				dp[stones+ arr[i]] = true;
		}
	if(dp[k])
		printf("First\n");
	else
		printf("Second\n");
	return 0;
	}


Measured memory_bytes: 384
import bisect

A,B,Q = map(int, input().split())

S = []
for i in range(A):
    S.append(int(input()))

T = []
for i in range(B):
    T.append(int(input()))

ans = []
for i in range(Q):
    x = int(input())
    s = bisect.bisect_left(S, x)
    s = min([s,len(S)-1])
    kyori_s = S[s]
    st1 = min([bisect.bisect_left(T, kyori_s), len(T)-1])
    st2 = max([st1-1,0])
    kyori1 = abs(kyori_s-x) + min([abs(T[st1]-kyori_s),abs(T[st2]-kyori_s)])

    s = max([s-1,0])
    kyori_s = S[s]
    st1 = min([bisect.bisect_left(T, kyori_s), len(T)-1])
    st2 = max([st1-1,0])
    kyori2 = abs(kyori_s-x) + min([abs(T[st1]-kyori_s),abs(T[st2]-kyori_s)])

    t = bisect.bisect_left(T, x)
    t = min([t,len(T)-1])
    kyori_t = T[t]
    ts1 = min([bisect.bisect_left(S, kyori_t), len(S)-1])
    ts2 = max([ts1-1,0])
    kyori3 = abs(kyori_t-x) + min([abs(S[ts1]-kyori_t),abs(S[ts2]-kyori_t)])

    t = max([t-1,0])
    kyori_t = T[t]
    ts1 = min([bisect.bisect_left(S, kyori_t), len(S)-1])
    ts2 = max([ts1-1,0])
    kyori4 = abs(kyori_t-x) + min([abs(S[ts1]-kyori_t),abs(S[ts2]-kyori_t)])

    ans.append(min([kyori1,kyori2,kyori3,kyori4]))

for i in ans:
    print(i)

Measured memory_bytes: 16932
#include<cstdio>
#include<cstdio>
#include<algorithm>
using namespace std;
int main(){
    int n,k;
    scanf("%d %d",&n,&k);
    for(int i=0;i<k;i++){
        int x,y;
        scanf("%d %d",&x,&y);
        x=min(x,n-x+1);
        y=min(y,n-y+1);
        int ans=min(x,y)%3;
        if(ans==0) printf("3\n");
        else printf("%d\n",ans);
    }
    return 0;
}

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

int main(){
	int n;
	cin >> n;
	int a[n];
	for(int i = 0;i < n; i++){
		cin >> a[i];
	}
	for(int j = 1;j < n;j++){
		cout << a[n-j] << " ";
	}
	cout << a[0] << endl;
	return 0;
}

Measured memory_bytes: 1164
def merge(hight):
    if len(hight) == 0:
        return 0
    if len(hight) == 1:
        return hight[0]
    m = min(hight)
    m_idx = hight.index(m)
    hight = [h - m for h in hight]
    left_hight = hight[:m_idx]
    right_hight = hight[m_idx + 1:]
    return  merge(left_hight) + merge(right_hight) + m

if __name__ == '__main__':
    N = int(input())
    h = list(map(int, input().split()))
    print(merge(h))

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

//const long double PIL = 3.141592653589793238462643383279502884L;
//const double PI = 3.14159265358979323846;

#define sz(a) int((a).size())
#define all(c) (c).begin(), (c).end()
#define what_is(x) cerr << #x << " is " << x << endl;

using ll = long long;
using ii = pair<int,int>;
using vi = vector<int>;
using vll = vector<long long>;
using vii = vector<pair<int,int>>;

int main() {
	//~ ios::sync_with_stdio(0);
	//~ cin.tie(0);
	int r;
	cin >> r;
	printf("%d\n", r*r);
}


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

using namespace std;
typedef long long ll;

int main()
{

  ll N;

  cin >> N;

  int A = 0;

  vector<int> B(0);

  for (int i = 0; i < N; i++)
  {

    int a;

    cin >> a;

    A ^= a;

    B.push_back(a);
  }

  for (int i = 0; i < N; i++)
  {

    int kasu = B[i]^A;

    cout << kasu << " ";
  }

  return 0;
}


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

using namespace std;


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

  if(n % 2 == 0)
    {
      cout << (double)(n/2)/n << endl;
    }
  else
    {
      cout << (double)(n/2 + 1)/n << endl;
    }
  return 0;
}


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

int main(){
  int64_t X;
  cin >> X;
  for(int i=-1000;i<=1000;i++){
    for(int j=-1000;j<=1000;j++){
      if(pow(i,5)-pow(j,5)==X){
        cout << i << " " << j << endl;
        return 0;
      }
    }
  }
  return 0;
}


Measured memory_bytes: 3992
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <cmath>
#include <string>
#include <sstream>
#include <iomanip>
#include <complex>
using namespace std;

#define ll long long
#define vvi vector< vector<int> >
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back 
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(){
  int cnt[26] = {0};
  while(1){
    char c = getchar();
    if(c==EOF) break;
    if('A'<=c&&c<='Z'){
      cnt[c-'A']++; 
    }else if('a'<=c&&c<='z'){
      cnt[c-'a']++;
    }
  }
  REP(i,26){
    cout << (char)('a'+i )<< " : " << cnt[i] << endl;
  }
  return 0;
}

Measured memory_bytes: 1120
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def calc_max(A):
    Amax = [0] * len(A)
    cal = 0
    for i, (x, v) in enumerate(A):
        cal += v
        if i == 0:
            Amax[i] = max(cal - x, 0)
        else:
            Amax[i] = max(cal - x, Amax[i - 1])

    return Amax


def solve(A, Amax, B, Bmax, ans):
    N = len(A)
    for i in range(N - 1):
        if ans < Amax[i] - A[i][0] + Bmax[N - i - 2]:
            ans = Amax[i] - A[i][0] + Bmax[N - i - 2]

    return ans


def main():
    N, C, *XV = map(int, read().split())

    A = [0] * N
    for i, (x, v) in enumerate(zip(*[iter(XV)] * 2)):
        A[i] = (x, v)
    Amax = calc_max(A)

    B = [(C - x, v) for x, v in reversed(A)]
    Bmax = calc_max(B)

    ans = max(Amax[-1], Bmax[-1])
    ans = max(ans, solve(A, Amax, B, Bmax, ans))
    ans = max(ans, solve(B, Bmax, A, Amax, ans))

    print(ans)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 41948
#![allow(non_snake_case, unused_assignments, unused_mut, dead_code)]
use proconio::fastout;
use proconio::input;
//use proconio::marker::Usize1;
use proconio::marker::Chars;
//use std::collections::HashSet;
// use std::cmp::*;
//use std::collections::VecDeque;
//use std::collections::BTreeSet;

#[fastout]
fn main() {
    input! {
       N: usize,
       S:Chars
    }
    let mut r = 0i64;
    let mut g = 0i64;
    let mut b = 0i64;
    for i in 0..N {
        if S[i] == 'R' {
            r += 1;
        }
        if S[i] == 'G' {
            g += 1;
        }
        if S[i] == 'B' {
            b += 1;
        }
    }
    let mut ans = r * g * b;

    for i in 0..(N - 1) {
        for j in (i + 1)..N {
            let k = 2 * j - i;
            if k >= N {
                continue;
            }
            //        println!("{},{},{}", i, j, k);
            if S[i] != S[j] && S[j] != S[k] && S[k] != S[i] {
                ans -= 1;
            }
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 2152
//1_2_A?????????????????? 3_3
#include<stdio.h>

//spap??¢??°
void swap(int *a,int *b){
	int temp=*a;
	*a=*b;
	*b=temp;
	return ;
}

int printArray(int data[],int num){
	int i;
	for(i=0;i<num;i++){
		if(i!=0)printf(" ");
		printf("%d",data[i]);
	}
	printf("\n");
	return 0;
}

int main(){
	int i,j,k,A[100]={0},count=0;
	int n;
	int flag=1;
	
	scanf("%d",&n);
	//??\???
	for(i=0;i<n;i++){
		scanf("%d",&A[i]);
	}
	
	//?????????
	for(j=0;flag;j++){
		flag=0;
		for(i=n-1;i>=j+1;i--){
			if(A[i]<A[i-1]){			//?????§????´?????¬????????´????????°?????????¨???	
				swap(&A[i],&A[i-1]);	//??????
				count++;
				flag=1;
			}
			//printArray(A,n);
		}
	}
	
	printArray(A,n);
	printf("%d\n",count);
	
	return 0;
}

Measured memory_bytes: 604
#include <iostream>
#include <atcoder/convolution>

using namespace std;
using namespace atcoder;

using ll = long long;

int main() {
    int N, M; cin >> N >> M;
    vector<ll> A(N), B(M);
    for (int i = 0; i < N; i++) cin >> A[i];
    for (int i = 0; i < M; i++) cin >> B[i];
    vector<ll> C = convolution(A, B);
    for (int i = 0; i < N + M - 1; i++) {
        cout << C[i] << (i < N + M - 2 ? " " : "\n");
    }
    return 0;
}

Measured memory_bytes: 27276
#include<bits/stdc++.h>
#ifdef LOCAL
#include "lib/debug.hpp"
#else
#define debug(...) 1
#endif
#define ALL(a) (a).begin(), (a).end()
#define rep(i, n) REP(i, 0, (n))
#define repc(i, n) REPC(i, 0, (n))
#define REP(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define REPC(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
using namespace std;
using ll = int_fast64_t;
using pr = pair<ll, ll>;
using vll = vector<ll>;
using vpr = vector<pr>;
template<class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } else return false; }
template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }

void answer() {
  int n, k; cin >> n >> k;
  vll h(n);
  rep(i,n) cin>>h[i];
  sort(ALL(h), greater<ll>());
  ll ans = 0;
  REP(i,k,n) ans += h[i];
  cout << ans << "\n";
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  answer();
  return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); 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 equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
//const ll mod = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

ll dp[400400];

int main() {
  ll n, k, c;
  cin >> n >> k >> c;
  string s;
  cin >> s;

  repr(i, n - 1) {
    if (s[i] == 'x') dp[i] = dp[i + 1];
    else {
      dp[i] = max(dp[i + 1], dp[i + c + 1] + 1);
    }
  }
  if (dp[0] > k) return 0;
  vector<ll> ans;
  ll res = k, idx = -1, fi = -1;
  rep(i, n) {
    if (s[i] == 'x') continue;
    if (dp[i] == res) {
      if (idx == -1) {
        idx = i + 1;
        fi = i;
      }
      else idx = -2;
    }
    else {
      if (idx > 0) ans.push_back(idx);
      i = fi + c;
      idx = -1;
      fi = -1;
      res--;
    }
  }
  if (idx > 0) ans.push_back(idx);
  if (!ans.empty()) {
    rep(i, ans.size()) cout << ans[i] << endl;
  }
  
  


  
  return 0;
}


Measured memory_bytes: 4980
a,b,k=map(int,input().split())
l=[]
if a+k<=b-k:
  for i in range(a,a+k):l.append(i)
  for i in range(b-k+1,b+1):l.append(i)
else:
  for i in range(a,b+1):
    l.append(i)

for ll in l:
  print(ll)

Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <numeric>
#define rep(i, m, n) for(int i = m;i < n;i++)
#define repr(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define INF 999999999
using namespace std;

int main(){
    int n, k; cin >> n >> k;
    int a[n] = {0};
    rep(i, 0, n) cin >> a[i];
    sort(a, a + n);
    reverse(a, a + n);
    int ans = 0;
    rep(i, 0, k){
        ans += a[i];
    }
    cout << ans << endl;
    return 0;
}


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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define lcm( a, b ) (a)/__gcd((a),(b))*(b)
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 200005;

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

LL fac[SIZE], finv[SIZE], inv[SIZE];
void combInit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for( int i = 2; i < SIZE; ++i ) {
        fac[i] = (fac[i - 1] * i) % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = (finv[i - 1] * inv[i]) % MOD;

    }
}

LL comb(int n, int k) {
    if( n < k ) return 0;
    if( n < 0 || k < 0 ) return 0;
    return (fac[n] * (finv[k] * finv[n - k] % MOD)) % MOD;

}

vector< int > Div( int n ) {
    vector< int > ret;
    for( int i = 1; i * i <= n; ++i ) {
        if( n % i == 0 ) {
            ret.pb( i );

            if( i * i != n ) ret.pb( n / i );
        }
    }
    sort( all( ret ) );
    return ret;
}

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

    int n, q;
    cin >> n >> q;
    string s;
    cin >> s;
    int sum[SIZE] = {};

    for( int i = 1; i < n; ++i ) {
        if( s[i - 1] == 'A' && s[i] == 'C' ) {
            sum[i + 1] = 1;

        }
        sum[i + 1] += sum[i];

    }

    while( q-- ) {
        int l, r;
        cin >> l >> r;
        cout << sum[r] - sum[l] << endl;

    }
    return 0;
}



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

# define C continue;
# define R return

# define D double
# define I insert
# define ll long long
# define ld long double

# define ull unsigned long long
# define ui unsigned int

# define pb push_back
# define pf push_front

# define vi vector < int >
# define vc vector < char >
# define vs vector < string >
# define vb vector < bool >
# define vd vector < D >
# define vll vector < ll >
# define vull vector < ull >
# define vld vector < ld >
# define PQ priority_queue

# define vvi vector < vector < int > >
# define vvb vector < vector < bool > >
# define vvc vector < vector < char > >
# define vvs vector < vs >
# define vvll vector < vector < ll > >
# define vvd vector < vector < D > >
# define vvld vector < vector < ld > >

# define all(v) (v).begin() , (v).end()
# define allrev(v) (v).rbegin() , (v).rend()
# define allcomp(v) v.begin() , v.end() , comp
# define allrevcomp(v) v.rbegin() , v.rend() , comp

# define pii pair < int , int >
# define pll pair < ll , ll >
# define pld pair < ld , ld >
# define pDD pair < D , D >

# define vpld vector < pld >
# define vpii vector < pii >
# define vpll vector < pll >
# define vpDD vector < pDD >

# define vvpii vector < vector < pii > >
# define F first
# define S second
# define mp make_pair

# define dist(a,b,p,q) sqrt((p-a)*(p-a) + (q-b)*(q-b))

# define pp(n) printf("%.10Lf",n);
# define line cout<<"\n";
# define fast ios_base::sync_with_stdio(false) ; cin.tie(0) ; cout.tie(0);

string vow = "aeiou";
int month[] = {-1, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

const int dxhorse[] = {-2, -2, -1, -1, 1, 1, 2, 2};
const int dyhorse[] = {1, -1, 2, -2, 2, -2, 1, -1};

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

const ld pie = 3.1415926535897932384626 ;
const ll mod = 1e9 + 7 ;

/// Tip : If a and b are positive integers ; we may say - ceil (a/b) = 1 + floor ( (a-1)/b ) .

ll nc2 ( ll n )
{
    n *= (n-1) ;
    n >>= 1 ;

    return n ;
}

void solve ( int test_case )
{
    int n , p ;
    cin >> n >> p ;

    string s ;
    cin >> s ;

    if ( p == 2 || p == 5 )
    {
        ll ans = 0 ;

        for ( int i=0 ; i < n ; i ++ )
        {
            int dig = s[i] - '0' ;
            dig %= p ;

            if ( dig == 0 ) ans += (i+1) ;
        }

        cout << ans ; line ; R ;
    }

    s = "." + s ;

    vi suff ( n + 2 ) ;

    int f = 1 ;
    for ( int i = n ; i > 0 ; i -- )
    {
        int dig = s[i] - '0' ;

        int c = dig * f ;
        c %= p ;

        suff[i] = suff[i + 1] + c ;
        suff[i] %= p ;

        f *= 10 ;
        f %= p ;
    }

    vi h ( p ) ;

    for ( int i=0 ; i <= n ; i ++ )
        h[suff[i]] ++ ;

    ll ans = 0 ;
    for ( int i=0 ; i < p ; i ++ )
    {
        ans += nc2 ( h[i] ) ;
    }

    cout << ans ;
    line ;
}

int main()
{fast
    int t = 1;
    // cin >> t;

    for ( int i=1 ; i <= t ; i ++ ) solve ( i ) ;
    return 0;
}


Measured memory_bytes: 1360
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
string s;
int con1,con2;
int main(){
	cin>>s;
	int len=s.length();
	if(len==1){
		cout<<"0";
		return 0;
	}
	for(int i=0;i<len;i++){
		if(s[i]=='0')	con1++;
		else	con2++;
	}
	cout<<min(con1,con2)*2;
	return 0;
}

Measured memory_bytes: 512
#include<stdio.h>
#include<math.h>

int main(void){
	int n,i,s;
	scanf("%d",&n);
	int a[n],b[n];
	for(i=0;i<n;i++)
		scanf("%d",&a[i]);
	
	s=0;
	for(i=0;i<n;i++)
	{	
		b[i]=a[i];
		while(b[i]%2==0){
		b[i]=b[i]/2;
		s=s+1;
		}
	}
		printf("%d",s);
	}
		
		
		

Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        
        if(a == b){
            System.out.println("a == b");
        }else if(a < b){
            System.out.println("a < b");
        }else{
            System.out.println("a > b");
        }
        
        
    }
}


Measured memory_bytes: 26312