akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define ll      long long
#define f(i,a,b)    for(ll i=a;i<b;i++)
#define jatin   ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define pb      push_back
#define v       vector<ll>
#define mi       map<ll,ll>
#define mp      make_pair<ll,ll>
#define F       first
#define S       second
#define set     set<ll>
ll gcd (ll a,ll b){
    return b?gcd(b,a%b):a;
}
ll lcm(ll a,ll b){
    return a*b/gcd(a,b);
}
ll factorial(ll n) 
{ 
    ll res = 1, i; 
    for (i = 2; i <= n; i++) 
        res = (res*i)%1000000009; 
    return res; 
}
/*ll pascal(ll i,ll j){
    if(j==1 || i==j)
        return 1;
    return pascal(i-1,j-1) + pascal(i-1,j);
}*/\

int main(){
    jatin
    ll n;
    cin>>n;
    ll a[100000];
    f(i,0,n){
        cin>>a[i];
    }  
    ll b[100000];
    b[0]=0;
    b[1]=abs(a[1]-a[0]);
    f(i,2,n){
        b[i] = min(b[i-1]+abs(a[i]-a[i-1]),b[i-2]+abs(a[i]-a[i-2]));
    }
    cout<<b[n-1];
}

Measured memory_bytes: 1792
N = int(input())
A = list(map(int, input().split()))
S=sum(A)
i=0
X=0
while X<S/2:
    X=X+A[i]
    i=i+1
k=i
ka=0
ja=0
wa=0
ya=0
za=0
for l in range(k+1):
    ka=ka+A[l]
for l in range(k):
    wa=wa+A[l]
for l in range(k-1):
    za=za+A[l]
Z=[]

Z.append(abs(S-ka-ka))
Z.append(abs(S-wa-wa))

Z.append(abs(S-za-za))
print(min(Z))



    



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

int main() {
  int H,W;
  cin >> H >> W;
  char s [H][W];
  for (int i=0;i<H;i++) {
    for (int j=0;j<W;j++) cin >> s[i][j];
  }
  int dx[4]={1,0,-1,0};
  int dy[4]={0,-1,0,1};
  bool can =true;
  for (int i=0;i<H;i++) {
    for (int j=0;j<W;j++) {
      bool found=false;
      if (s[i][j]=='#') {
        for (int k=0; k<4;k++) {
          int x=i+dx[k];
          int y=j+dy[k];
          if(0<=x&&x<H&&0<=y&&y<W&&s[x][y]=='#') found=true;
        }
        if (!found) {
          can=false;
          break;
        }
      }
    }
    if(!can) break;
  }
  if (can) cout<<"Yes"<<endl;
  else cout <<"No"<< endl;
}


Measured memory_bytes: 3644
#include <iostream>
#include <iomanip>

using namespace std;

int main(){
	int a, b;
	
	cin >> a;
	cin >> b;
	
	cout << a / b << " ";
	cout << a % b << " ";
	cout << fixed << setprecision(5) << (double)a / b << endl;
	
}

Measured memory_bytes: 1244
n=int(input())
a,b=map(int,input().split())
p=list(map(int,input().split()))
ta=0
tb=0
tc=0
for i in range(n):
  if p[i]<=a:
    ta=ta+1
  elif p[i]>=b+1:
    tc=tc+1
  else:
    tb=tb+1
print(min(ta,tb,tc))

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

int main(){
  int n,h;
  cin >> h >> n;
  int a[n],b[n];
  rep(i,n)cin >> a[i] >> b[i];
  int m = 2*10010;
  int dp[n+1][m+1];
  rep(i,n+1)rep(j,m+1)dp[i][j] = INF;
  dp[0][0] = 0;
  rep(i,n){
    rep(j,m){
      if(j<a[i])dp[i+1][j] = dp[i][j];
      else dp[i+1][j] = min(dp[i+1][j-a[i]]+b[i],min(dp[i+1][j],dp[i][j]));
    }
  }
  int ans = INF;
  rep(i,m+1)if(dp[n][i] < ans && i>=h)ans = dp[n][i];
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 81896
a = [ list(map(int,input().split())) for i in range(3)]
n = int(input())
b_n = [int(input()) for i in range(n)]
result = [ [0]*3 for i in range(3)]

def check():
    for b in b_n:
        for i in range(3):
            for j in range(3):
                if a[i][j] == b:
                    result[i][j] = 1
    yoko = [0]*3
    tate = [0]*3

    for i in range(3):
        for j in range(3):
            yoko[i] += result[i][j]
            tate[j] += result[i][j]
    for i in range(3):
        if yoko[i] == 3 or tate[i] == 3:
            print('Yes')
            return 0
    if result[0][0] + result[1][1] + result[2][2] ==3:
        print('Yes')
        return 0
    elif result[0][2] + result[1][1] + result[2][0] ==3:
        print('Yes')
        return 0
    print('No')
    return 0
check()

Measured memory_bytes: 3064
N, K = map(int, input().split())
A = list(map(int, input().split()))
l = A[0]
r = A[K]
for i in range(1,N-K):
  if l < r:
    print('Yes')
  else:
    print('No')
  l = A[i]
  r = A[K+i]
if l < r:
  print('Yes')
else:
  print('No')

Measured memory_bytes: 31564
import time

s = input()[::-1] # 入力文字列を逆順でsに格納

counts = [0] * 2019
counts[0] = 1

num, d = 0, 1

for char in s:
    num += int(char) * d
    num %= 2019
    d *= 10
    d%= 2019
    counts[num] += 1

#start = time.time()#計測始
ans = 0
for cnt in counts:
    ans += cnt * (cnt - 1) // 2

print(ans) # 答えの出力
#end = time.time()#計測終
#print(f"{end-start}sec.")#計測出力

Measured memory_bytes: 9312
#include <stdio.h>
#include <stdlib.h>

int cmp(const void *a, const void *b) {
    return *(int*)a - *(int*)b;
}

int main() {
    int i, N, A, B, *P;
    int size[3] = {0};
    if (scanf("%d%*c%d%*c%d%*c", &N, &A, &B) == -1) return -1;
    P = (int *)malloc(sizeof(int) * N);
    if (!P) return -1;
    for (i = 0; i < N; i++) {
        if (scanf("%d%*c", &P[i]) == -1) return -1;
        if (P[i] <= A) size[0]++;
        else if (P[i] >= A + 1 && P[i] <= B) size[1]++;
        else if (P[i] >= B + 1) size[2]++;
    }
    qsort(size, 3, sizeof(int), cmp);
    if (size[0] == 0) {
        printf("0\n");
        return 0;
    }
    else printf("%d\n", size[0]);
    free(P);
    return 0;
}

Measured memory_bytes: 128
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ARC091B {
    class Program {
        static void Main(string[] args) {
            long[] input = Console.ReadLine().Split(' ').Select(s => long.Parse(s)).ToArray();
            long N = input[0];
            long K = input[1];
            long ans = 0;
            if(K == 0) {
                ans = N * N;
            } else {
                for (int b = 1; b <= N; b++) {
                    if (b <= K) {
                        continue;
                    }
                    long num = N / b;
                    ans += num * (b - K);
                    long remain = N % b;
                    if (remain >= K) {
                        ans += remain - K + 1;
                    }
                }
            }
            Console.WriteLine(ans);
        }
    }
}


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

int main() {
    string S; cin >> S;
    int cnt, M = 0;
    for (int i = 0; i < S.size(); i++) {
        cnt = 0;
        if (S.at(i) == 'A' || S.at(i) == 'C' || S.at(i) == 'G' || S.at(i) == 'T') {
            cnt++;
            for (int j = i + 1; j < S.size(); j++) {
                if (S.at(j) == 'A' || S.at(j) == 'C' || S.at(j) == 'G' || S.at(j) == 'T') {
                    cnt++;
                }
                else {
                    break;
                }
            }
        }
        M = max(M, cnt);
    }
    cout << M << endl;
}

Measured memory_bytes: 256
N=int(input())
if N==1:
  print(0)
  exit(0)
def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0:
        cnt+=1
        temp //= i
      arr.append([i, cnt])
  if temp!=1:
    arr.append([temp, 1])
  if arr==[]:
    arr.append([n, 1])
  return arr

X=factorization(N)
ans=0
for p,n in X:
  _n=0
  while n>0:
    _n+=1
    if n-_n<=_n:
      n=0
    else:
      n-=_n
    ans+=1
print(ans)

Measured memory_bytes: 9496
#include <bits/stdc++.h>
using namespace std;
 
int main(){ 
    char c[3][3];
    for(int i=0;i<3;i++){
        for(int j=0;j<3;j++){
            cin>>c[i][j];
        }
    }

    for(int i=0;i<3;i++)cout<<c[i][i];
 
    return 0;
}

Measured memory_bytes: 256
a = gets.to_i
nedan = []
a.times.each do
  nedan << gets.to_i
end
c = 0
nedanmax = nedan.max
nedan.each_with_index {|en, i|
  c = i if en == nedanmax
}
nedan[c.to_i] = (nedan.max / 2)
summ = nedan.inject(0){|sum, i| sum + i}
puts summ.to_i

Measured memory_bytes: 1788
#include<bits/stdc++.h>
#define title "title"
#define ll long long
#define ull unsigned ll
#define fix(x) fixed<<setprecision(x)
#define pii pair<ll,ll>
#define vint vector<ll>
#define pb push_back
using namespace std;
void Freopen(){
	freopen(title".in","r",stdin);
	freopen(title".out","w",stdout);
}
ll read(){
	ll g=0,f=1;
	char ch=getchar();
	while(ch<'0'||'9'<ch){if(ch=='-')f=-1;ch=getchar();}
	while('0'<=ch&&ch<='9'){g=g*10+ch-'0';ch=getchar();}
	return g*f;
}
const ll N=5e5+5;
const ll mod=998244353;
ll fac[N],inv[N],n,m,maxn,po_m[N],po_n[N],ans;
ll C(ll n,ll m){
	if(n<m)return 0;
	return fac[n]*inv[m]%mod*inv[n-m]%mod;
}
signed main(){
	n=read(),m=read(),maxn=max(n,m);
	fac[0]=1;for(ll i=1;i<=maxn;i++)fac[i]=fac[i-1]*i%mod;
	inv[1]=1;for(ll i=2;i<=maxn;i++)inv[i]=(mod-mod/i)*inv[mod%i]%mod;
	inv[0]=1;for(ll i=1;i<=maxn;i++)inv[i]=inv[i-1]*inv[i]%mod;
	po_m[0]=1;for(ll i=1;i<=n;i++)po_m[i]=po_m[i-1]*(m+1)%mod;
	po_n[0]=1;for(ll i=1;i<=m;i++)po_n[i]=po_n[i-1]*(n+1)%mod;
	for(ll i=0;i<=min(n,m);i++)ans=(ans+(i&1?mod-1:1)*C(n,i)%mod*C(m,i)%mod*fac[i]%mod*po_m[n-i]%mod*po_n[m-i]%mod)%mod;
	return cout<<ans,signed();
}
/*
1 2
2 3
10 7
314159 265358
*/

Measured memory_bytes: 19164
use proconio::input;
use proconio::marker::Chars;

fn main() {
	input! {
		k: u32,
		s: Chars,//Vec<cahr>
	}

	if s.len() <= k as usize {
		for c in s {
			print!("{}", c);
		}
	} else {
		for i in 0..k {
			print!("{}", s[i as usize]);
		}
		print!("{}", "...");
	}
}



Measured memory_bytes: 2144
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
	int n;
	bool ok = 1;
	string s[100];
	map<string, int> used;
	cin >> n;
	for (int i = 0; i < n; ++i)
	{
		cin >> s[i];
		if (used[s[i]])
		{
			ok = 0;
		}
		++used[s[i]];
	}
	for (int i = 1; i < n; ++i)
	{
		if (s[i-1][s[i-1].size()-1] != s[i][0])
		{
			ok = 0;
		}
	}
	cout << (ok?"Yes":"No") << endl;
	return 0;
}

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

bool check(vector<int>& dist, vector<string>& S, int& d) {
    int N = S.size();
    vector<vector<int>> V(d + 1, vector<int>());
    for (int i = 0; i < N; i++) {
        V[dist[i]].push_back(i);
    }

    for (auto v : V) {
        int n = v.size();
        for (int i = 0; i < n; i++) {
            for (int j = i + 1; j < n; j++) {
                if (S[v[i]][v[j]] == '1') {
                    return false;
                }
            }
        }
    }

    return true;
}

int main() {
    int N;
    cin >> N;
    vector<string> S(N);
    for (int i = 0; i < N; i++) {
        cin >> S[i];
    }

    int D = -1;
    vector<int> dist;
    for (int root = 0; root < N; root++) {
        queue<int> que;
        que.push(root);
        vector<int> dist_temp(N, 1e9);
        dist_temp[root] = 0;
        while (!que.empty()) {
            int u = que.front();
            que.pop();

            for (int i = 0; i < N; i++) {
                if (S[u][i] == '1' && dist_temp[i] > dist_temp[u] + 1) {
                    dist_temp[i] = dist_temp[u] + 1;
                    que.push(i);
                }
            }
        }
        int d = *max_element(dist_temp.begin(), dist_temp.end());

        if (D < d && check(dist_temp, S, d)) {
            D = d;
            dist = dist_temp;
        }
    }

    if (D == -1) {
        cout << -1 << endl;
    } else {
        cout << D + 1 << endl;
    }
}


Measured memory_bytes: 384
cards = gets.to_i
array = gets.split(" ").map{|k|k.to_i}
cards_sum1 = 0
cards_sum2 = 0
array.each do |num|
    cards_sum2 += num
end

if array.length == 2
    ans = (array[0] - array[1]).abs
else
    ans = Float::INFINITY
    for i in 0..array.length-2 do
        cards_sum1 += array[i]
        cards_sum2 -= array[i]
        a = (cards_sum1 - cards_sum2).abs
        if ans > a
            ans = a
        end
    end
end


puts ans

Measured memory_bytes: 15364
S = list(input())
T = list(input())
temp_ans = 0

for i in range(len(S)-len(T)+1):
    temp_S = S[i:i+len(T)]
    count = 0
    for j in range(len(T)):
        if temp_S[j] == T[j]:
            count += 1
    if temp_ans < count:
        temp_ans = count

ans = len(T) - temp_ans
print(ans)

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

int main(){
  int a, b, c; //"a"+"b"=c
  bool square=false;
  cin >> a >> b;

  c = pow(10, to_string(b).length())*a+b;

  for(int i=0; i<c; i++){
    if(pow(i, 2)==c){
      square=true;
      break;
    }
  }
  if(square) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 256
#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 f(int n)
{
    return ((n & 1) ? 3 * n + 1 : n / 2);
}

int main()
{
    vector<int> v(3);
    rep(i, 3) cin >> v[i];

    sort(all(v));
    reverse(all(v));

    cout << v[0] * 10 + v[1] + v[2] << '\n';
    return 0;
}


Measured memory_bytes: 3600
using System;
class latte
{
    static int gcd(int a, int b)
    {
        if (b == 0) return a;
        return gcd(b, a % b);
    }
    static int lcm(int a, int b)
    {
        return a / gcd(a, b) * b;
    }
    static void Main()
    {
        while (true)
        {
            string s = Console.ReadLine();
            if (s == null) break;
            string[] t = s.Split();
            int a = int.Parse(t[0]);
            int b = int.Parse(t[1]);
            Console.WriteLine(gcd(a, b) + " " + lcm(a, b));
        }
    }
}

Measured memory_bytes: 5604
#include<iostream>
#include<vector>
#include<limits>
#include<math.h>
#include<bits/stdc++.h>

using namespace std;

#define make_graph(m,G) for (int i = 0; i<m; i++) { int a,b; cin>>a>>b;G[a-1].push_back(b-1); G[b-1].push_back(a-1);}
#define make_dir_graph(m,G) for (int i = 0; i<m; i++) { int a,b; cin>>a>>b;G[a-1].push_back(b-1);}
#define make_weighted_graph(m,G,w) for (int i = 0; i<m; i++) { int a,b; cin>>a>>b; cin>>w[a-1][b-1];w[b-1][a-1]=w[a-1][b-1];G[a-1].push_back(b-1); G[b-1].push_back(a-1);}
#define make_weighted_dir_graph(m,G,w) for (int i = 0; i<m; i++) { int a,b; cin>>a>>b; cin>>w[a-1][b-1]; G[a-1].push_back(b-1);}

int main()
{
	int t=1;
	// cin>>t;
	while (t--)
	{
		// code
		int n,W;
		cin>>n>>W;
		int w[n+1], v[n+1];

		for (int i = 1; i<=n; i++)
		{
			cin>>w[i]>>v[i];
		}
		long long dp[n+1][W+1] = {};
		dp[1][w[1]] = v[1];
		for (int i = 1; i<=n; i++)
		{
			for (int weight = 0; weight<=W; weight++)
			{
				if (weight >= w[i])
				{
					dp[i][weight] = max(dp[i-1][weight-w[i]] + v[i], dp[i-1][weight]);
				}
				else
				{
					dp[i][weight] = dp[i-1][weight];
				}
				//cout<<dp[i][weight]<<" ";
			}
			//cout<<endl;
		}
		cout<<dp[n][W]<<endl;;
	}
}

Measured memory_bytes: 79104
def tak_and_cards(N: int, A: int, X: list) -> int:
    #  部分点解法
    # :---------:
    # count = 0
    # for b in range(1, 1 << N):
    #     n, s = 0, 0
    #     for i in range(N):
    #         if (b >> i) & 1 == 0:
    #             continue
    #         n += 1
    #         s += X[i]

    #     if s == n * A:
    #         count += 1
    # return count
    max_X = max(X)
    dp = [[0] * (2 * max_X * N + 1) for _ in range(N + 1)]
    dp[0][max_X * N] = 1

    for k, x in enumerate(X):
        for t in range(2 * max_X * N + 1):
            y = x - A

            dp[k + 1][t] = dp[k][t]
            if 0 <= t - y and t - y <= 2 * max_X * N:
                dp[k + 1][t] += dp[k][t - y]

    return dp[N][max_X*N] - 1


if __name__ == "__main__":
    N, A = map(int, input().split())
    x = [int(s) for s in input().split()]
    ans = tak_and_cards(N, A, x)
    print(ans)


Measured memory_bytes: 5616
#include <stdio.h>

void bubbleSort(int A[], int n) {
	int i, j;
	int temp;
	for (i = 0; i < n - 1; i++) {
		for (j = n - 1; j > i; j--) {
			if (A[j - 1] > A[j]) {
				temp = A[j];
				A[j] = A[j - 1];
				A[j - 1] = temp;
			}
		}
	}
}


int main() {
	int i;
	int N, v[50];
	double ans = 0;

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

	bubbleSort(v, N);

	ans = ((double)v[0] + (double)v[1]) / 2;
	for (i = 2; i < N; i++) {
		ans = (ans + (double)v[i]) / 2;
	}

	printf("%lf\n", ans);

	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define N 1111116
#define next nxt
 
int n,x[N],y[N],next[N],p[N],f[N];
 
int travel(int x){
	int ans=0;
	for (int t=p[x];t;t=next[t])
		if (y[t]!=f[x])
		f[y[t]]=x,ans^=travel(y[t])+1;
	return ans;
}
 
int read(){
	int x=0,f=1;char ch=getchar();
	for (;!isdigit(ch);ch=getchar()) if (ch=='-') f=-f;
	for (;isdigit(ch);ch=getchar()) x=x*10+ch-'0';
	return x*f;
}
 
int main(){
	n=read();
	for (int i=1;i<=n-1;i++){
		x[2*i-1]=y[2*i]=read();
		y[2*i-1]=x[2*i]=read();
		next[2*i-1]=p[x[2*i-1]];p[x[2*i-1]]=2*i-1;
		next[2*i]=p[x[2*i]];p[x[2*i]]=2*i;
	}
	printf(travel(1)?"Alice\n":"Bob\n");
	return 0;
}

Measured memory_bytes: 13568
#include <bits/stdc++.h>
#define clr(x) memset(x,0,sizeof x)
#define For(i,a,b) for (int i=(a);i<=(b);i++)
#define Fod(i,b,a) for (int i=(b);i>=(a);i--)
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define fi first
#define se second
#define outval(x) cerr<<#x" = "<<x<<endl
#define outtag(x) cerr<<"-----------------"#x"-----------------\n"
#define outarr(a,L,R) cerr<<#a"["<<L<<".."<<R<<"] = ";\
                    For(_x,L,R) cerr<<a[_x]<<" ";cerr<<endl;
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair <int,int> pii;
LL read(){
    LL x=0,f=0;
    char ch=getchar();
    while (!isdigit(ch))
        f=ch=='-',ch=getchar();
    while (isdigit(ch))
        x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
    return f?-x:x;
}
const int N=100005,INF=1e9;
namespace flows{
	const int N=100005*2,M=N*2;
	struct Edge{
		int x,y,nxt,cap;
		Edge(){}
		Edge(int _x,int _y,int _nxt,int _cap){
			x=_x,y=_y,nxt=_nxt,cap=_cap;
		}
	}e[M];
	int n,S,T,cnt;
	int fst[N],cur[N],dis[N];
	void clear(int _n,int _S,int _T){
		n=_n,S=_S,T=_T,cnt=1;
		clr(fst);
	}
	void Add(int x,int y,int cap){
		e[++cnt]=Edge(x,y,fst[x],cap),fst[x]=cnt;
		e[++cnt]=Edge(y,x,fst[y],0),fst[y]=cnt;
	}
	int bfs(){
		static int q[N];
		int head=0,tail=0;
		For(i,1,n)
			dis[i]=0;
		dis[S]=1;
		q[++tail]=S;
		while (head!=tail){
			int x=q[++head];
			for (int i=fst[x];i;i=e[i].nxt){
				int y=e[i].y;
				if (e[i].cap&&!dis[y]){
					dis[y]=dis[x]+1;
					q[++tail]=y;
				}
			}
		}
		return dis[T]!=0;
	}
	int dfs(int x,int Lim){
		if (x==T||!Lim)
			return Lim;
		int rem=Lim;
		for (int &i=cur[x];i;i=e[i].nxt){
			int y=e[i].y;
			if (dis[x]+1==dis[y]&&e[i].cap){
				int d=dfs(y,min(rem,e[i].cap));
				rem-=d,e[i].cap-=d,e[i^1].cap+=d;
				if (!rem)
					break;
			}
		}
		return Lim-rem;
	}
	int Dinic(){
		int res=0;
		while (bfs()){
			For(i,1,n)
				cur[i]=fst[i];
			res+=dfs(S,INF);
		}
		return res;
	}
}
int n,c=0;
int p[N],q[N];
int x[N],y[N];
int main(){
	n=read();
	For(i,1,n)
		p[i]=read()+1;
	For(i,1,n)
		q[i]=read()+1;
	For(i,1,n){
		if (x[i])
			continue;
		c++;
		for (int j=i;!x[j];j=p[j])
			x[j]=c;
	}
	For(i,1,n){
		if (y[i])
			continue;
		c++;
		for (int j=i;!y[j];j=q[j])
			y[j]=c;
	}
	int S=c+1,T=S+1;
	flows::clear(T,S,T);
	int ans=0;
	For(i,1,n){
		if (i==p[i]&&i==q[i])
			ans++;
		else if (i==p[i]&&i!=q[i])
			flows::Add(S,y[i],1);
		else if (i==q[i]&&i!=p[i])
			flows::Add(x[i],T,1);
		else if (p[i]!=q[i])
			flows::Add(x[i],y[i],1);
		else {
			flows::Add(x[i],y[i],1);
			flows::Add(y[i],x[i],1);
		}
	}
	ans+=flows::Dinic();
	cout<<n-ans<<endl;
	return 0;
}

Measured memory_bytes: 12544
input_a = int(input())
input_b = int(input())
input_c = int(input())
input_total = int(input())
count = 0
for i in range(input_a + 1):
    for j in range(input_b + 1):
        for k in range(input_c + 1):
            if i * 500 + j * 100 + k * 50 == input_total:
                count += 1
print(count)


Measured memory_bytes: 3060
import sys
read = sys.stdin.buffer.read

from fractions import gcd

N,*A = map(int,read().split())

lcm = 1
answer = 0
for x in A:
  n = x//gcd(lcm,x)
  lcm *= n
  answer *= n
  answer += lcm//x
  
answer %= (10**9 + 7)
print(answer)


Measured memory_bytes: 5984
n = int(input())
p = list(map(int, input().split()))
q = list(map(int, input().split()))

from itertools import permutations
ss = []
for s in permutations(range(1, n + 1)):
    ss.append(s)
ss = sorted(ss)
for k, s in enumerate(ss):
    if list(s) == p:
        a = k
    if list(s) == q:
        b = k

print(abs(a - b))

Measured memory_bytes: 8308
def sum(list, index):
    if (len(list) > 1):
        d = len(list[:-1]) - 1
        return (sum(list[:-1], 0) + list[-1] * 10**index * 2**d ) + (sum(list[:-1], index + 1 ) + list[-1] * 10**index * 2**d)
    else:
        return (list[-1] * 10**index)

def resolve():
    s = list(map(int,input()))
    print(sum(s,0))


if __name__ == "__main__":
    resolve()

Measured memory_bytes: 9152
fun main(args: Array<String>) {
    val n = readLine()!!.split(" ")[0]
    val a = n.get(0).toInt()
    val b = n.get(1).toInt()
    val c = n.get(2).toInt()
    if (a == 55){
        println("Yes")
    } else if (b == 55){
        println("Yes")
    } else if (c == 55){
        println("Yes")
    } else {
        println("No")
    }
}



Measured memory_bytes: 36536
#include <stdio.h>

int main()
{
    long long n, w, N, a, b;
    scanf("%lld", &N);

    for(n = 1; n <= 3500; n++)
    {
        for(w = 1; w <= 3500; w++)
        {
            a = N * n * w;
            b = 4 * n * w - N * w - N * n;
            if(b != 0 && a % b == 0 && a / b > 0)
            {
                printf("%lld %lld %lld", a / b, n, w);
                return 0;
            }
        }
    }
    
}

Measured memory_bytes: 256
import numpy as np
W, H, N = map(int, input().split())
S = np.zeros((H, W))

for i in range(N):
    x, y, a = map(int, input().split())
    if a == 1:
        S[:, :x] += 1
    elif a == 2:
        S[:, x:] += 1
    elif a == 3:
        S[:y, :] += 1
    elif a == 4:
        S[y:, :] += 1

print(len(S[S == 0]))

Measured memory_bytes: 18604
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vll = vector<ll>;
#define forn(i,n) for(int i=0; i < int(n); ++i)
#define all(x) (x).begin(), (x).end()
#define eb emplace_back
#define pb push_back
#define fst first
#define snd second

int main() {
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    ll ans = 0;
    for (int x; cin >> x; ans += x-1);
    cout << ans << '\n';
}


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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

#define ASSERT(expr...) assert((expr))

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;
using ll = long long;

constexpr i64 INF = 1010000000000000017LL;

constexpr i64 MOD = 1000000007LL;

constexpr f64 EPS = 1e-12;

constexpr f64 PI = 3.14159265358979323846;

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)

#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }

template<typename T, typename U, typename Comp=less<>>
bool chmax(T& xmax, const U& x, Comp comp={}) {
    if(comp(xmax, x)) {
        xmax = x;
        return true;
    }
    return false;
}

template<typename T, typename U, typename Comp=less<>>
bool chmin(T& xmin, const U& x, Comp comp={}) {
    if(comp(x, xmin)) {
        xmin = x;
        return true;
    }
    return false;
}

struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;

ll mod_pow(ll x, ll n) {
    if (n == 0) return 1;
    if (n % 2 == 0) {
        return mod_pow(x * x % MOD, n / 2) % MOD;
    } else {
        return x * mod_pow(x, (n - 1)) % MOD;
    }
}

ll mod_pow_r(ll x, ll n) {
    if (x == 0) return 0;
    if (n == 0) return 1;

    ll ret = 1;
    while (n) {
        if (n & 1) ret = ret * x % MOD;
        x = x * x % MOD;
        n /= 2;
    }
    return ret;
}

ll factorial(ll n) {
    ll ret = 1;
    REP(i, n) {
        ret *= (i + 1);
        ret %= MOD;
    }
    return ret;
}

ll combination(ll n, ll r) {
    if (n < 0 || n < r || r < 0) return 0;
    ll fn = factorial(n);
    ll fr = factorial(r);
    ll fn_r = factorial(n-r);

    ll d = (mod_pow(fr, MOD - 2) * mod_pow(fn_r, MOD - 2)) % MOD;
    ll u = fn % MOD;
    return u * d % MOD;
}

void solve() {
    ll N;
    cin >> N;

    for (ll i = sqrt(N); i > 0; i--) {
        if (N % i == 0) {
            cout << i + N / i - 2;
            return;
        }
    }
}

signed main() {
    solve();
    return 0;
}

Measured memory_bytes: 256
N,K=map(int,input().split())
A=[int(a)-1 for a in input().split()]
city=0
if K<=N:
    for k in range(K):
        city=A[city]
    print(city+1)
else:
    visited=[-1]*N
    for k in range(K):
        if visited[city]!=-1:
            roop_start=visited[city]
            cycle_num=k-roop_start
            break
        visited[city]=k
        city=A[city]
    K=(K-roop_start)%cycle_num+roop_start
    city=0
    for k in range(K):
        city=A[city]
    print(city+1)

Measured memory_bytes: 32296
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <string>
#include <typeinfo>
#include <random>
#include <vector>
//#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef vector<vector<bool>> vvb;
typedef vector<vector<int>> vvi;
 
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define all(a) (a).begin(), (a).end()
 
int main()
{
	int a,b,t;
	cin>>a>>b>>t;
	cout<<b*(t/a)<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
typedef long long ll;
#define pb push_back
#define fi first
#define se second
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
template <class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &p){os<<"("<<p.first<<","<< p.second<<")";return os;}
template <class T> ostream &operator<<(ostream &os, const vector<T> &v){os<<"{";REP(i,(int)v.size()){if(i)os<<",";os<<v[i];}os<<"}";return os;}
template <typename T, size_t S> void printArray(const T (&array)[S]){for(auto val : array)std::cout << val << ", ";std::cout << "\n";}
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}
const double PI=acos(-1);
const ll MOD = 1000000007;
using Graph = vector<vector<int>>;
template<class T>inline bool chmax(T& a, T b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T& a, T b){if(a > b){a = b; return 1;}return 0;}
const ll INF = 1LL<<60;
//const int dx[4] = {1, 0, -1, 0};
//const int dy[4] = {0, 1, 0, -1};
//const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
//const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

void solve(){
    ll n, k; cin >> n >> k;
    vector<ll> a(200001, 0);
    REP(i, n){
        ll ain; cin >> ain;
        a[ain]++;
    }
    vector<pair<ll, ll>> vp;
    REP(i, 200001){
        if(a[i] != 0) vp.pb({a[i], i});
    }
    sort(RALL(vp));
    if(k >= vp.size()) cout << 0 << endl;
    else{
        ll res = 0;
        for(int i=k; i<vp.size(); i++){
            res += vp[i].fi;
        }
        cout << res << endl;
    }
}

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

Measured memory_bytes: 6768
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <stdio.h>
using namespace std;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPL(i,f,n) for(int i=f, i##_len=(n); i<i##_len; ++i)
typedef long long ll;

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

	int H,W;
	string s[60];
	cin >> H >> W;
	REP(i, H) cin >> s[i];

	bool ans = true;
	int dx[4] = { 1,-1,0,0 };
	int dy[4] = { 0,0,1,-1 };
	REP(i, H) {
		REP(j, W) {
			if (s[i][j] == '#') {
				bool found = false;
				REP (k, 4) {
					int i2 = i + dx[k];
					int j2 = j + dy[k];
					if (i2 >= 0 && i2 < H 
						&& j2 >= 0 && j2 < W && s[i2][j2] == '#') {
						found = true;
					}
				}
				if (!found) {
					ans = false;
					break;
				}
			}
		}
	}
	cout << (ans?"Yes":"No") << endl;
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
 
int main(void){
   int x,y,i,j;
   for(;;){
      scanf("%d %d",&y,&x);
      if(x+y==0) break;
      for(i=0;i<y;i++){
         for(j=0;j<x;j++)
            printf("#");
         printf("\n");
      }
   printf("\n");
   }
   return 0;
}


Measured memory_bytes: 2044
#include <iostream>
#include <vector>
#include <cstdlib>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <string>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
using vi = vector<int>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける
using vl = vector<ll>;  // long longの1次元の型に vl という別名をつける
using vvl = vector<vl>; // long longの2次元の型に vvl という別名をつける
int MOD = 1000000007; //10^9 + 7

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

// 無限大の値
const ll  lINF = 1LL << 60;
const int iINF = 1 << 29;

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

  cout << (a+b+1)/2 << endl;
  return 0;
} 

Measured memory_bytes: 3580
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
int main(){
  ll N;
  cin>>N;
  vector<ll>vec(N);
  for(ll i=0;i<N;i++){
    cin>>vec.at(i);
  }
  sort(vec.begin(),vec.end());
  ll g=vec.at(N-1)*vec.at(N-1)*N;
  for(ll i=vec.at(0);i<vec.at(N-1)+1;i++){
    ll a=0;
    for(ll k=0;k<N;k++){
      a+=(vec.at(k)-i)*(vec.at(k)-i);
    }
    g=min(a,g);
  }
  cout<<g<<endl;
  
}
    


Measured memory_bytes: 3624
#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<ll,ll>;

const ll mod = 1000000007;
const double eps = 1e-8;

#ifdef DEBUG
#include "inc/debug.hpp"
#else
#define debug(...) 42
#endif

ll A[3], D;
ll m[3] = {2, 3, 5};

map<ll,ll> mm;

ll dfs(ll x) {
    if (x == 0) return 0;
    if (mm.count(x)) return mm[x];

    ll ret = (x < LLONG_MAX / D) ? D * x : LLONG_MAX;
    for (int i=0; i<3; ++i) {
        if (x % m[i] == 0) ret = min(ret, A[i] + dfs(x / m[i]));
        else {
            ll x2 = (x - x % m[i]) / m[i];
            ret = min(ret, D * (x % m[i]) + A[i] + dfs(x2));
            ll x3 = (x + m[i] - x % m[i]) / m[i];
            if (x3 != 1) ret = min(ret, D * (m[i] - x % m[i]) + A[i] + dfs(x3));
        }
    }

    // debug(x, ret);
    return mm[x] = ret;
}

int main() {
    int T;
    cin >> T;
    while (T--) {
        ll N;
        cin >> N;
        for (int i=0; i<3; ++i) cin >> A[i];
        cin >> D;
        mm.clear();
        cout << dfs(N) << endl;
    }
    return 0;
}

Measured memory_bytes: 4304
import java.util.Scanner;

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

		String s = sc.next();

		if (s.equals("Sunny")) {
			System.out.println("Cloudy");
		} else if (s.equals("Cloudy")) {
			System.out.println("Rainy");
		} else {
			System.out.println("Sunny");
		}
		sc.close();
	}
}

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

using namespace std;

int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	
	long int n, minDist = LONG_MAX, dist;
	cin >> n;
	
	for (int i = 1; i <= sqrt(n); ++i) {
		if (n % i == 0) {
			dist = i - 1 + n / i - 1;
			if (dist < minDist) {
				minDist = dist;
			}
		}
	}
	
	cout << minDist; 
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define STI(s) atoi(s.c_str())
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;
const double EPS = 1e-9;


int main(void) {
    
    
    int n;
    cin>>n;
    if(n==1){
        fin("Hello World");
    } else {
        int a,b;
        cin>>a>>b;
        cout<<a+b<<endl;
    }


    
}


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

int main(){
  string s; cin >> s;
  sort(s.begin(), s.end());
  bool backet[26] = {false};

  for(int i = 0; i < s.size(); i++){
    //--- char - char = int ---//
    backet[s[i] - 'a'] = true;
  }
  for(int i = 0; i < 26; i++) {
    if(backet[i] == false) {
      //--- int + char = char ---//
      cout << char(i + 'a') << endl;
      return 0;
    }
  }
  cout << "None" << endl;
}


Measured memory_bytes: 512
import java.util.Scanner;
 
class Main{
    	public static void main(String[] args){
        	Scanner sc = new Scanner(System.in);
        	String card1,card2;
        	int cnt1 = 0,cnt2 = 0, x;
        	int y = sc.nextInt();
        	for(int i = 0; i < y; i++){
            		card1 = sc.next();
            		card2 = sc.next();
            		x = card1.compareTo(card2);
            		if(x == 0){
				cnt1++;
				cnt2++;
			}else if(x > 0){
				cnt1 += 3;
            		}else{
				cnt2 += 3;
        		}
		}
        	System.out.println(cnt1 + " " + cnt2);
    	}
}

Measured memory_bytes: 20812
#include <bits/stdc++.h>
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define debug  freopen("in.txt","r",stdin),freopen("out.txt","w",stdout);
#define pb push_back
#define all(x) x.begin(),x.end()
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int maxn = 1e6+10;
const int maxM = 1e6+10;
const int inf = 0x3f3f3f3f;

ll A,B,N;
int main(){
	// debug;
	ios;

	cin>>A>>B>>N;
	if(N>=B) cout<<A*(B-1)/B;
	else cout<<A*N/B;


	return 0;
}


Measured memory_bytes: 3588
adj = [[0 for _ in range(4)] for _ in range(4)]
for i in range(3):
    a, b = [int(i) - 1 for i in input().split()]
    adj[a][b] = 1
    adj[b][a] = 1
for i in range(4):
    for j in range(4):
        if i == j:
            continue
        for k in range(4):
            if i == k or j == k:
                continue
            for l in range(4):
                if i == l or j == l or k == l:
                    continue
                elif adj[i][j] == 1 and adj[j][k] == 1 and adj[k][l] == 1:
                    print("YES")
                    exit()
print("NO")

Measured memory_bytes: 3064
from collections import *
n=int(input())
l=list(map(int,input().split()))
x,y=[],[]
c=0
for i in range(0,n,2):
    x.append(l[i])
for i in range(1,n,2):
    y.append(l[i])
xx=-1
if(len(set(x))==1):
    xx=x[0]
else:
    d=defaultdict(int)
    for i in x:
        d[i]+=1
    m=0
    xx=-1
    for i in d:
        if(d[i]>m):
            xx=i
            m=d[i]
    c+=sum(d.values())-m
if(len(set(y))>1 or (len(set(y))==1 and y[0]==xx)):
    d=defaultdict(int)
    for i in y:
        d[i]+=1
    m=0
    yy=-1
    for i in d:
        if(d[i]>m and i!=xx):
            yy=i
            m=d[i]
    c+=sum(d.values())-m
cc=0
yy=-1
if(len(set(y))==1):
    yy=y[0]
else:
    d=defaultdict(int)
    for i in y:
        d[i]+=1
    m=0
    yy=-1
    for i in d:
        if(d[i]>m):
            yy=i
            m=d[i]
    cc+=sum(d.values())-m
if(len(set(x))>1 or (len(set(x))==1 and x[0]==yy)):
    d=defaultdict(int)
    for i in x:
        d[i]+=1
    m=0
    xx=-1
    for i in d:
        if(d[i]>m and i!=yy):
            xx=i
            m=d[i]
    cc+=sum(d.values())-m
print(min(cc,c))


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

using namespace std;

const int maxn = 1e5+10;

int n, m, deg[maxn], dp[maxn];

vector<int> grafo[maxn];

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

    cin >> n >> m;

    for(int i=1; i<=m; i++){
        int u, v;

        cin >> u >> v;

        grafo[v].push_back(u);

        deg[u]++;
    }

    memset(dp, -1, sizeof dp);

    int ans = -1;

    queue<int> fila;

    for(int i=1; i<=n; i++){
        if(!deg[i]){
            fila.push(i);
            dp[i] = 0;
        }
    }

    while(!fila.empty()){
        int u = fila.front(); fila.pop();

        ans = max(ans, dp[u]);

        for(auto v : grafo[u]){
            deg[v]--;
            if(!deg[v]){
                dp[v] = dp[u] + 1;
                fila.push(v);
            }
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 6528
import sys, bisect, math, itertools, string, queue, copy
# import numpy as np
# import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
# input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input()) # n=1
def inpm(): return map(int,input().split()) # x=1,y=2
def inpl(): return list(map(int, input().split())) # a=[1,2,3,4,5,...,n]
def inpls(): return list(input().split())  # a=['1','2','3',...,'n']
def inplm(n): return list(int(input()) for _ in range(n)) # x=[] 複数行
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return sorted([list(map(int, input().split())) for _ in range(n)]) # [[1,1,1,1],[2,2,2,2],[3,3,3,3]] 
def graph():
    n=inp()
    g=[[] for _ in range(n)]
    for i in range(n):
        a = inp()
        a -= 1
        g[i].append(a)
        g[a].append(i)
    return n,g

def main():
    n,k = inpm()
    a = inpl()
    a.sort()
    if n <= k:
        print(0)
        return
    ans = 0
    for i in range(n-k):
        ans += a[i]
    print(ans)    
    
if __name__ == "__main__":
    main()




Measured memory_bytes: 91756
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>

#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a)-1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a)-1; (i) >= (b); (i)--)
#define PI acos(-1.0)
#define DEBUG(C) cerr << C << endl;
#define VI vector <int>
#define VII vector <VI>
#define VL vector <LL>
#define VLL vector <VL>
#define VD vector <double>
#define VDD vector <VD>
#define PII pair <int, int>
#define PDD pair <double, double>
#define PLL pair <LL, LL>
#define VPII vector <PII>
#define ALL(a) (a).begin(), (a).end()
#define SORT(a) sort(ALL(a))
#define REVERSE(a) reverse(ALL(a))
#define MP make_pair
#define FORE(a, b) for (auto &&a:b)
#define FIND(s, e) (s.find(e) != s.end())
#define EB emplace_back

using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;

int V, E;
VII graph;
VI ans;
vector <bool> is;
void dfs(int now) {
    if (is[now]) return;
    is[now] = true;
    FORE(el, graph[now]) {
        dfs(el);
    }
    ans.EB(now);
}

int main(void) {
    cin >> V >> E;
    graph.resize(V);
    is.resize(V, false);
    set <int> s;
    REP(i, E) {
        int a, b;
        scanf("%d%d", &a, &b);
        graph[a].EB(b);
        s.insert(a);
    }
    REP(i, V) dfs(i);
    REVERSE(ans);
    FORE(el, ans) cout << el << endl;
}

Measured memory_bytes: 4248
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_map>
#include <functional>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cstdlib>

using namespace std;
typedef long long llong;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<llong, llong> pll;

const int mod = 1e9 + 7;
const int half = 5e8 + 4;
int n;
int a[200000];
int b[200000];
int arr[4001][4001];
int fact[8001], ifact[4001];

llong sq(int x) {
    return (llong)x * x % mod;
}

int main() {
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) {
        scanf("%d%d", a + i, b + i);
        ++arr[a[i] + b[i]][a[i] + 2000];
    }
    ifact[1] = 1;
    for (int i = 2; i <= 4000; ++i) {
        int q = mod / i, r = mod - i * q;
        ifact[i] = mod - ((llong)ifact[r] * q) % mod;
    }
    fact[0] = 1;
    for (int i = 1; i <= 8000; ++i) {
        fact[i] = (llong)i * fact[i - 1] % mod;
    }
    ifact[0] = 1;
    for (int i = 1; i <= 4000; ++i) {
        ifact[i] = (llong)ifact[i - 1] * ifact[i] % mod;
    }
    for (int i = 4000; i; --i) {
        for (int j = i; j <= 4000; ++j) {
            arr[i - 1][j - 1] += arr[i][j];
            arr[i - 1][j - 1] %= mod;
            arr[i - 1][j] += arr[i][j];
            arr[i - 1][j] %= mod;
        }
    }
    int ans = 0;
    for (int i = 1; i <= 2000; ++i) {
        ans = (ans + (llong)arr[0][2000 - i] * arr[0][2000 + i] % mod) % mod;
    }
    ans <<= 1;
    ans %= mod;
    ans += sq(arr[0][2000]);
    ans %= mod;
    for (int i = 0; i < n; ++i) {
        ans += mod - (llong)fact[(a[i] + b[i]) << 1] * ifact[a[i] << 1] % mod * ifact[b[i] << 1] % mod;
        ans %= mod;
    }
    ans = (llong)ans * half % mod;
    printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 64384
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  
  int N;
  string A;
  cin >> N;
  
  for (int i = 0; i < N; i++) {
    string x;
    cin >> x;
    
    if (x == "Y") {
      A = "Four";
      cout << A << endl;
      break;
    }
  }
  
  if (A != "Four") {
    cout << "Three" << endl;
  }
}

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

using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
typedef long long ll;

int main(){
  int n,a;
  cin >> n;
  int mx = 0;
  int mn = 1e9;
  rep(i,n){
    cin >> a;
    mx = max(mx,a);
    mn = min(mn,a);
  }
  cout << mx-mn << endl;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n, k;
    cin >> n >> k;
    int a[n+1];
    for(int i=0; i<n; ++i){
        cin >> a[i];
    }
    bool ans[k+1];
    ans[0] = 0;
    for(int i=1; i<=k; i++){
        bool res = false;
        for(int j=0;j<n;j++){
            if(i-a[j]>=0 && !ans[i-a[j]]){
                res = true;
                break;
            }
        }
        ans[i] = res;

    } 
    cout << ((ans[k]==1)?"First":"Second");
}

Measured memory_bytes: 3732
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>


using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x * x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define loop(n) FOR(i,0,n)
#define rrep(i,a,b) for(int i=(a);i>=(b);--i)
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

bool isSmall(int h1, int w1, int h2, int w2) {
	int d1 = h1 * h1 + w1 * w1;
	int d2 = h2 * h2 + w2 * w2;

	if (d1 < d2)return true;
	if (d1 > d2)return false;

	if (h1 < h2)return true;
	else return false;
}

int main() {
	
	while (true) {
		int h, w; cin >> h >> w;

		if (h == 0 && w == 0)return 0;

		int answ = 1000;
		int ansh = 1000;

		for (int ch = 1; ch < 151; ch++) {
			for (int cw = ch+1; cw < 151; cw++) {

				if (ch == h && cw == w)continue;
				if (isSmall(ch, cw,h,w))continue;

				if (isSmall(ch, cw, ansh, answ)) {
					ansh = ch;
					answ = cw;
				}
			}
		}

		cout << ansh << " " << answ << endl;

	}

	return 0;
}


Measured memory_bytes: 3088
#include <stdio.h>

void insertionSort(int*, int);

int main(){

  int i,j,k,N,A[100],v;

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

  insertionSort(A, N);
  
   

  return 0;
}

void insertionSort(int *A, int N){
  int i,j,k,v;
  
  for(i=0;i<N-1;i++) printf("%d ",A[i]);
    printf("%d\n",A[N-1]);
    
    for(i=1;i<N;i++){
    v = A[i];
    j = i - 1;
    while(j>=0 && A[j] > v){
      A[j+1] = A[j];
      j--;
      A[j+1] = v;
    }
    for(k=0;k<N-1;k++) printf("%d ",A[k]);
    printf("%d\n",A[N-1]);
  }
}



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

using namespace std;

using ll = long long;

constexpr int MAX_N = 22, MOD = 1e9 + 7;
int n;
bool a[MAX_N][MAX_N];
int dp[1 << MAX_N];

int Solve(int v, int s) {
    if (v == n) return 1;
    if (dp[s] != -1) return dp[s];

    int &res = dp[s] = 0;
    for (int u = 0; u < n; ++u) {
        if (a[v][u] && !(s >> u & 1))
            res = (res + Solve(v + 1, s | (1 << u))) % MOD;
    }
    return res;
}

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

    cin >> n;

    for (int i = 0; i < n; ++i)
        for (int j = 0; j < n; ++j)
            cin >> a[i][j];
    for (int s = 0; s < 1 << n; ++s) dp[s] = -1;

    cout << Solve(0, 0) << endl;

    return 0;
}


Measured memory_bytes: 10624