akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define A 100000000
#define B 10000
using  namespace std;
typedef long long ll;
struct Info
{
    ll sum;
    int p, q, r;
    bool operator<(const Info& rhs) const
    {
        return sum < rhs.sum;
    }
};

int main()
{
    int x, y, z, k;
    cin >> x >> y >> z >> k;
    vector<ll> a(x), b(y), c(z);
    rep(i, x) cin >> a[i];
    rep(i, y) cin >> b[i];
    rep(i, z) cin >> c[i];
    sort(a.begin(), a.end(), greater<ll>() );
    sort(b.begin(), b.end(), greater<ll>() );
    sort(c.begin(), c.end(), greater<ll>() );

    priority_queue<Info> que;
    Info info = {a[0]+b[0]+c[0], 0, 0, 0};
    que.push(info);
  	map<tuple<int, int, int>, bool> mp;
	int l = 0;
    while (l < k) {
        Info info1 = que.top();
		que.pop();
        int p, q, r;
        p = info1.p;
        q = info1.q;
        r = info1.r;
      	if (!mp[make_tuple(p, q, r)]) {
          	mp[make_tuple(p, q, r)] = true;
          	++l;
          	ll sum = info1.sum;
            cout << sum << endl;
            if (p+1 < x) {
                Info info2 = {a[p+1]+b[q]+c[r], p+1, q, r};
                que.push(info2);
            }
            if (q+1 < y) {
                Info info2 = {a[p]+b[q+1]+c[r], p, q+1, r};
                que.push(info2);
            }
            if (r+1 < x) {
                Info info2 = {a[p]+b[q]+c[r+1], p, q, r+1};
                que.push(info2);
            }
        }
    }
    return 0;
}

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

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

    vector<string> s(h+2);
    REP(i,h+2){
        if(i==0|| i==h+1){
            REP(j,w+2){
                s[i]+="N";
            }
        }else{
            cin>>s[i];
            s[i].insert(0,"N");
            s[i].insert(w+1,"N");
        }
    }

    for(int i=1; i<h+1; i++){
        for(int j=1; j<w+1; j++){
            if(s[i][j]=='#'){
                continue;
            }
            int count=0;
            // 上の列
            REP(k,3){
                if(s[i-1][j+k-1]=='#'){
                    count++;
                }
            }
            // 下の列
            REP(k,3){
                if(s[i+1][j+k-1]=='#'){
                    count++;
                }
            }
            // 左右
            if(s[i][j-1]=='#'){
                count++;
            }
            if(s[i][j+1]=='#'){
                count++;
            }

            s[i][j]=count+'0';
        }
    }

    for(int i=1; i<h+1; i++){
        for(int j=1; j<w+1; j++){
            cout<<s[i][j];
            if(j==w){
                cout<<endl;
            }
        }
    }  
}

Measured memory_bytes: 256
N, x = map(int, input().split())
A = list(map(int, input().split()))
ans = 0
for i in range(1, N):
    total = A[i-1]+A[i]
    if total > x:
        ans += (total-x)
        A[i] -= (total-x)
        if A[i] < 0:
            A[i] = 0
print(ans)


Measured memory_bytes: 14540
n,X = map(int,input().split())
x = list(map(int,input().split()))
x.append(X)
x.sort()
a=[]
for i in range(len(x)-1):
        a.append(x[i+1]-x[i])        

def gcd(m,n):
        while n:
                m,n = n,m%n
        return m

ans=a[0]
for j in a:
        if j%ans != 0:
                ans = gcd(j,ans)
print(ans)

Measured memory_bytes: 14228
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstring>
#include<deque>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;

using lint = long long;
using P = pair<int, int>;
using LLP = pair<long long, long long>;

#define REP(i, x, n) for(int i = (x), i##_len = int(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = int(n) ; i < i##_len ; ++i)
#define reps(i, n) for(int i = 1, i##_len = int(n) ; i <= i##_len ; ++i)
#define rrep(i, n) for(int i = int(n) - 1 ; i >= 0 ; --i)
#define rreps(i, n) for(int i = int(n) ; i > 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())
#define TWINS(x) cout << ((x) ? "Yay!" : ":(") << endl

const int IINF = (1 << 30) - 1;
const long long LLINF = 1LL << 61;
const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};
const double EPS = 1e-8;

int dfs(int y, int x, vector< vector<char> > &v){
    v[y][x] = '#';

    int res = 1;
    rep(i, 4){
        if(v[y + dy4[i]][x + dx4[i]] == '.'){
            res += dfs(y + dy4[i], x + dx4[i], v);
        }
    }

    return res;
}

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

    int w, h;
    while(cin >> w >> h, w){
        vector< vector<char> > v(h + 2, vector<char>(w + 2, '#'));
        int sy, sx;
        reps(i, h){
            reps(j, w){
                cin >> v[i][j];
                if(v[i][j] == '@'){
                    sy = i;
                    sx = j;
                }
            }
        }

        int ans = dfs(sy, sx, v);
        cout << ans << endl;
    }

    return 0;
}


Measured memory_bytes: 3176
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <numeric>
#include <chrono>
#include <bitset>
#include <tuple>
#include <queue>
#include <map>
#include <cstring>
#include <cassert>
#include <math.h>
using namespace std;

const int N = 2e5 + 10, mod = 1e9 + 7;

int fp(int a, int b) {
    int ret = 1;
    while(b) {
        if(b & 1) ret = 1ll * ret * a % mod;
        b >>= 1;
        a = 1ll * a * a % mod;
    }
    return ret;
}

using ll = long long;
pair<ll, ll> get(pair<ll, ll> t) {
    if(!t.first || !t.second) return {t.second, t.first};
    int sign = (t.first < 0 ? 1 : 0);
    return {(sign ? 1 : -1) * t.second, abs(t.first)};
}

int main() {
    // ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int tc = 1;
    // scanf("%d", &tc);
    for(int cn = 1; cn <= tc; cn++) {
        int n; scanf("%d", &n);
        vector<long long> a(n), b(n);
        for(int i = 0; i < n; i++) scanf("%lld%lld", &a[i], &b[i]);
        map<pair<ll, ll>, int> cnt, vis;
        int bad = 0;
        for(int i = 0; i < n; i++) {
            if(!a[i] && !b[i]) {
                bad++;
                continue;
            }
            if(!a[i]) b[i] = 1;
            if(!b[i]) a[i] = 1;
            int sign = (a[i] < 0 ^ b[i] < 0 ? 1 : 0);
            a[i] = abs(a[i]), b[i] = abs(b[i]);
            ll g = __gcd(a[i], b[i]);
            pair<ll, ll> t = {(sign ? -1 : 1) * a[i] / g, b[i] / g};
            cnt[t]++;
        }
        int ans = 1;
        for(auto x : cnt) {
            pair<ll, ll> t = x.first;
            if(vis[t]) continue;
            // cout << t.first << ' ' << t.second << 
            // ' '  << x.second << ' ' << cnt[get(t)] << '\n';
            int cur = fp(2, x.second);
            cur = (1ll * cur + fp(2, cnt[get(t)])) % mod;
            cur = (1ll * cur - 1) % mod;
            // cout << cur << '\n';
            ans = 1ll * ans * cur % mod;
            vis[get(t)] = 1;
        }
        ans = (ans - 1ll) % mod;
        ans = (1ll * ans + bad) % mod;
        if(ans < 0) ans += mod;
        printf("%d\n", ans);
    }  
    return 0;
}

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

#define M_PI       3.14159265358979323846   // pi

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> VI;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> t3;
typedef tuple<ll, ll, char, ll> t4;

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

const ll mod = 1000000007;

static const ll INF = 1e15;

int main(void)
{
	ll n,w;
	cin >> n >> w;
	vector<P> vs(n);
	rep(i, n) {
		cin >> vs[i].first >> vs[i].second;
	}
	vector<vector<ll>> dp(n + 1, vector<ll>(10001, INF));
	dp[0][0] = 0;
	rep(i, n) {
		ll v = vs[i].first;
		ll we = vs[i].second;

		rep(j, 10001) {
			dp[i + 1][j] = dp[i][j];
			auto pv = j - v;
			if (pv >= 0) {
				dp[i + 1][j] = min(dp[i + 1][j], dp[i][pv] + we);
			}
		}
	}
	ll mv = 0;
	for (ll i = 0; i < 10001;i++) {
		if (dp[n][i] <= w) {
			mv = max(mv, i);
		}
	}
	cout << mv << endl;
	return 0;
}




Measured memory_bytes: 10792
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
inline int read(){
	int x=0,f=1;
	char c=getchar();
	while(c<'0'||c>'9'){
		if(c=='-')f=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9'){
		x=(x<<1)+(x<<3)+c-'0';
		c=getchar();
	}
	return x*f;
}
int main(){
	printf("%d\n",(read()-1)>>1);
	return 0;
}


Measured memory_bytes: 3744
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <iomanip>

using namespace std;

int main(){
   int N;
   int M;
   cin >> N >>M;
   vector<pair<int,int>> v;
   vector<pair<int,int>> u;
   map<pair<int,int>, int> order;
   for(int i = 0 ; i < M; i++){
      int p,y;
      cin >> p >> y;
      v.push_back(make_pair(p,y));
      u.push_back(make_pair(p,y));
   }
   sort(v.begin(),v.end());
   int prevP =-1;
   int cnt = 1;
   for(int i=0; i < M; i++){
      pair<int,int> p =v[i];
      if(p.first!=prevP){
         order[p]=1;
         cnt=2;
      }
      else{
         order[p]=cnt;
         cnt++;
      }
      prevP=p.first;
   }
   for(int i = 0 ; i < M; i++){
      pair<int,int> p = u[i];
      printf("%06d%06d\n", p.first, order[p]); 
   }

   return 0;
}


Measured memory_bytes: 9324
import Control.Monad
import qualified Data.Map as M

main :: IO ()
main = do
  (n:k:q:as) <- map read . words <$> getContents
  mapM_ putStrLn $ solve n k q as

solve :: Int -> Int -> Int -> [Int] -> [String]
solve n k q as = go mp0 as
  where
    mp0 = M.fromList $ zip [1..n] $ repeat 0

    go mp []
      = map (\x -> if x + k > q then "Yes" else "No")
      $ map snd $ M.toList mp

    go mp (a:as)
      = go (M.insertWith (+) a 1 mp) as

Measured memory_bytes: 28412
#include <utility>
#include <iostream>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <algorithm>
#define INTINF 2147483647
#define LLINF 9223372036854775807
#define MAX 30
#define NIL -1
typedef long long ll;
using namespace std;


struct BTNode { int parent, left, right; };
BTNode T[MAX];
int root;


void input(){
  int n, id, l, r;
  std::cin >> n;
  for (size_t i = 0; i < n; i++) {
    T[i].parent = NIL;
    T[i].left = NIL;
    T[i].right = NIL;
  }
  for (size_t i = 0; i < n; i++) {
    std::cin >> id >> l >> r;
    T[id].left = l;  T[id].right = r;
    if (l != NIL) T[l].parent = id;
    if (r != NIL) T[r].parent = id;
  }
  for (size_t i = 0; i < n; i++) {
    if(T[i].parent==NIL) root=i;
  }
}


void PreorderWalk(int id){
  if (id == NIL) return;
  std::cout << " " << id;
  PreorderWalk(T[id].left);
  PreorderWalk(T[id].right);
}

void InorderWalk(int id){
  if (id == NIL) return;
  InorderWalk(T[id].left);
  std::cout << " " << id;
  InorderWalk(T[id].right);
}

void PostorderWalk(int id){
  if (id == NIL) return;
  PostorderWalk(T[id].left);
  PostorderWalk(T[id].right);
  std::cout << " " << id;
}



int main(int argc, char const *argv[]) {
  cin.tie(0);
  ios::sync_with_stdio(false);

  input();

  std::cout << "Preorder" << '\n';
  PreorderWalk(root);
  std::cout << '\n';

  std::cout << "Inorder" << '\n';
  InorderWalk(root);
  std::cout << '\n';

  std::cout << "Postorder" << '\n';
  PostorderWalk(root);
  std::cout << '\n';

  return 0;
}



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

using namespace std;

typedef long long ll;

const int N = 5e3 + 10;
const ll mod = 998244353;

int n, k;
ll C[N][N];

ll comb(int x, int y) {
    if (x < 0 || y < 0 || y > x) return 0;
    return C[x][y];
}

int main() {
    cin >> k >> n;
    memset(C, 0, sizeof(C));
	for (int i = 0; i < N; i++) {
		C[i][0] = 1;
		for (int j = 1; j <= i; j++)
            C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]) % mod;
	}
	for (int i = 2; i <= 2 * k; i++) {
		int t1 = i / 2, t2 = max(1, i - k);
		ll ret = 0;
		for (int j = 0; j <= t1 - t2 + 1; j++)
			(ret += (j % 2 ? -1 : 1) * (comb(t1 - t2 + 1 , j) * comb(n + k - 2 * j - 1, n - 2 * j) % mod)) %= mod;
		(ret += mod * mod) %= mod;
		cout << ret << endl;
	}
}


Measured memory_bytes: 196352
#include <stdio.h>


// I/O
int get_uint() {
    int n = 0;
    int c = getchar_unlocked();
    if(c < 48 || 57 < c) return c;
    while(47 < c && c < 58) n = 10 * n + (c & 0xf), c = getchar_unlocked();
    return n;
}
void put_uint(int n) {
    if(!n) {
        putchar_unlocked('0');
        return;
    }
    char buf[11];
    int i = 0;
    while(n) buf[i++] = (char)(n % 10 + '0'), n /= 10;
    while(i--)putchar_unlocked(buf[i]);
}
//


int main(int argc, char **argv) {
    int n = get_uint();
    int fib[45] = {1, 1};
    for(int i = 2; i < 45; ++i) fib[i] = fib[i - 1] + fib[i - 2];
    put_uint(fib[n]);
    putchar_unlocked('\n');
    return 0;
}



Measured memory_bytes: 2100
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,tasu=0,hiku=0,kakeru=0,saidai;
  cin>>a>>b;
  tasu=a+b;
  hiku=a-b;
  kakeru=a*b;
  saidai=max(max(tasu,hiku),kakeru);
  cout<<saidai<<endl;
  return 0;
}

Measured memory_bytes: 256
L,R=map(int,input().split())
mod=2019
if R-L>=2020:
    print(0)
    exit()
else:
    l=[]
    for i in range(L,R+1):
        l.append(i%mod)
ans=2018
for i in l:
    for j in l:
        if i!=j:
            ans=min(ans,i*j%mod)
print(ans)

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

using namespace std;

int main()
{
	int n, k;
	cin >> n >> k;

	int h[100000];
	for (int i = 0; i < n; i++) {
		cin >> h[i];
	}

	sort(h, h + n, greater < int >());

	int min_diff = INT_MAX;

	for (int i = 0; i < n - k + 1; i++) {
		int diff = h[i] - h[i + k - 1];
		if (diff < min_diff) {
			min_diff = diff;
		}
	}

	cout << min_diff << endl;
	return 0;
}


Measured memory_bytes: 640
n=int(input())
A=[list(map(int,input().split())) for i in range(n)]
B,H=[],[0]*n

def binary(A,B,node,parent,sibling,depth,type):
    if node!=-1:
        id,left,right=A[node]
        degree=len([i for i in (left,right) if i!=-1])
        if parent==-1:
            type="root"
        elif degree!=0:
            type="internal node"
        else:
            type="leaf"
        B.append([node,parent,sibling,degree,depth,type])
        binary(A,B,left,node,right,depth+1,type)
        binary(A,B,right,node,left,depth+1,type)

def get_height(H,u):
    h1,h2=0,0
    if A[u][2]!=-1:
        h1=get_height(H,A[u][2])+1
    if A[u][1]!=-1:
        h2=get_height(H,A[u][1])+1
    H[u]=max(h1,h2)
    return H[u]

top=[i for i in range(n)]
for i in range(n):
    for j in (A[i][1],A[i][2]):
        if j!=-1:
            top.remove(j)
top=top[0]
A=sorted(A)
binary(A,B,top,-1,-1,0,"root")
get_height(H,top)
B=sorted(B)

for j,i in enumerate(B):
    print("node {}: parent = {}, sibling = {}, degree = {}, depth = {}, height = {}, {}".format(i[0],i[1],i[2],i[3],i[4],H[j],i[5]))


Measured memory_bytes: 5624
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <numeric>
using namespace std;
typedef long long ll;

int main(){
    int n,m;cin>>n>>m;
    vector<int> v(n);
    for(int i=0;i<n;i++)cin>>v[i];
    int sum=accumulate(v.begin(),v.end(),0);
    sort(v.rbegin(),v.rend());
    for(int i=0;i<m;i++){
        if(v[i]*4*m<sum){cout<<"No";return 0;}
    }
    cout<<"Yes";
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        B solver = new B();
        solver.solve(1, in, out);
        out.close();
    }

    static class B {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            StringBuilder S = new StringBuilder();
            StringBuilder tmp = new StringBuilder();
            S.append(in.next());
            boolean ok = false;

            if (S.length() == 7) {
                if ("keyence".equals(S.toString())) {
                    ok = true;
                }
            } else {
                int sublen = S.length() - 7;
                for (int i = 0; i < S.length() - sublen; i++) {
                    tmp.append(S.toString());
                    if ("keyence".equals(tmp.replace(i, i + sublen, "").toString())) {
                        ok = true;
                        break;
                    }
                    tmp.setLength(0);
                }
            }

            out.println(ok ? "YES" : "NO");

        }

    }
}



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

int a, b, c, d;

int main() {
	cin >> a >> b >> c >> d;
	cout << min(a, b) + min(c, d) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  //input
  int A,B,K; cin>>A>>B>>K; 
  int sum=0; 
  //compute
  if(A+K-1>=B-K+1){
    for(int i=0;i<B-A+1;i++){
  		cout<<A+i<<endl;
    }
  }
  else{  
  	for(int i=0;i<K;i++){
  		cout<<A+i<<endl;
    }

    for(int i=K-1;i>=0;i--){
      cout<<B-i<<endl;
    }
  }
  
}
  



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <stack> // s.top()
#include <bitset>
#include <queue> // s.front()
using namespace std;

typedef long long ll;
#define print(x) cout<<(x)<<endl


#define INF10 10000000000
#define INF5 100000
#define EPS 1e-10
#define MOD 1000000007


// DONT USE "int", USE "ll" !!!!!!!!!!!!
int main() {
	int base[26] = { 0 };
	string S; cin >> S;
	for (int i = 0; i < S.size(); i++) {
		base[S[i] - 97]++;
		
	}
	for (int i = 0; i < 26; i++) {
		if (base[i] == 0) {
			char out = 97 + i;
			print(out);
			return 0;
		}
	}
	print("None");

	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define ll long long
#define rep(X,N) for(int X = 0; X < N; X++)
#define repvin(V,N) for(int i = 0; i < N; i++) {int tmp; cin >> tmp; V.push_back(tmp);} int dummmmmmmmy

using namespace std;

int main(){

    string s;
    cin >> s;
    int K;
    cin >> K;

    vector<string> ranking;
    int cnt = 0;

    int n = s.size();

    map<string,int> m;

    rep(i,n){
        rep(j,5){
            if(n - i < j + 1) break;
            string tmpstr = s.substr(i,j + 1);

            if(m[tmpstr] != 0){
                continue;
            }

            m[tmpstr] = m[tmpstr] + 1;
            
            ranking.push_back(tmpstr);

        }
    }

    sort(ranking.begin(),ranking.end());

    cout << ranking[K - 1] << endl;
    return 0;
}

Measured memory_bytes: 2048
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		String S = in.next();
		StringBuilder sb = new StringBuilder(S);
		int ans = 0;
		for (int i = sb.length() - 2; i >= 0; i--) {
			if (i + 1 < sb.length() && sb.charAt(i) != sb.charAt(i + 1)) {
				sb.delete(i, i + 2);
				ans += 2;
			}
		}
		System.out.println(ans);
		in.close();
	}
}

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

using namespace std;

const int mod = 1e9 + 7;

int main()
{
  int N, A[100000] = {};

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

  long long ret = 1;
  if(N % 2 == 0) {
    int pe = 0;
    for(int i = 1; pe < N; pe += 2, i += 2) {
      if(A[i] != 2) {
        cout << 0 << endl;
        return (0);
      }
      (ret *= 2) %= mod;
    }
  } else {
    int pe = 1;
    if(A[0] != 1) {
      cout << 0 << endl;
      return (0);
    }
    for(int i = 2; pe < N; pe += 2, i += 2) {
      if(A[i] != 2) {
        cout << 0 << endl;
        return (0);
      }
      (ret *= 2) %= mod;
    }
  }

  cout << ret << endl;
}

Measured memory_bytes: 640
import Control.Applicative ((<$>), (<*>))
import Control.Monad
import Data.List
import Data.Function (on)

main :: IO ()
main = do
  n <- getl toInt
  unless (n == 0) $ do
    ((unwords . map show) . solve) <$> replicateM n (getl $ wrds toInt) >>= putStrLn
    main

solve :: [[Int]] -> [Int]
solve = g . maximumBy (compare `on` snd) . map f
  where
    f [x,y,z] = (x, (y + z))
    g (x,y) = [x, y]
    
toInt :: String -> Int
toInt = read

wrds :: (String -> a) -> String -> [a]
wrds f = map f . words

getl :: (String -> a) -> IO a
getl f = f <$> getLine

Measured memory_bytes: 15520
s = input()
sr = s[::-1]
mannnaka = (len(s) - 1) // 2

for i in range(mannnaka):
    if s[i] != sr[i]:
        print('No')
        exit()

for i in range(mannnaka // 2):
    if s[i] != s[mannnaka - i - 1] or sr[i] != sr[mannnaka - i - 1]:
        print('No')
        exit()

print('Yes')


Measured memory_bytes: 3060
a,b = map(int,input().split())
k = 0
if a > b:
  k = a - b
  if k % 2 != 0:
    print('IMPOSSIBLE')
  else:
    print(int((k/2)+b))
else:
  k = b - a
  if k % 2 != 0:
    print('IMPOSSIBLE')
  else:
    print(int((k/2)+a))

Measured memory_bytes: 3060
#include <iostream>
using namespace std;
 
int main() {
  int n;
  cin >> n;
 
  for ( int i = 1; i <= n; i++ ) {
    if ( i % 3 == 0 ) {
      cout << " " << i;
      continue;
    }
    int j = i;
    while ( j > 0 ) {
      if ( j % 10 == 3 ) {
         cout << " " << i;
         break;
      } else j /= 10;
    }
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 1160
N = int(input())
nums=[int(input()) for _ in range(N)]
MAX = 10**4
dp = [0] * (MAX+1)
dp[0] = 1
for num in nums:
  for i in range(MAX+1)[::-1]:
    if dp[i] == 1 and (i + num) <= MAX:
      dp[i+num] = 1
ans = 0
for i in range(MAX+1):
  if dp[i] == 1 and i%10 != 0:
    ans = i
print(ans)


Measured memory_bytes: 3064
#include <iostream>

using namespace std;

#define mod 1000000007

long long fact[1000005];


void precompute()	{
	for (int i = 1; i < 1000000; i++)	{
      	fact[i] = (i * (fact[i - 1] % mod)) % mod;
    }
}

long long power(int x, int y, int m)	{
	if (y == 0)
      	return 1;
  	long long p = (power(x, y / 2, m) % m);
  	p = ((p % m) * (p % m)) % m;
  	if (y % 2 == 0)
      	return p;
 	else
      	return ((x % m) * (p % m)) % m;
}

long long modinv(long long int x)	{
	return power(x, mod - 2, mod);
}

int main()	{
  	fact[0] = 1;
  	long long h, w, a, b;
  	precompute();
  	cin >> h >> w >> a >> b;
  	long long result = 0;
  	for (int i = 0; i <= w - b - 1; i++)	{
    	long long temp1 = ((fact[h - a + b + i - 1]) * modinv(fact[b + i]) % mod * modinv(fact[h - a - 1]) % mod) % mod;
      	long long temp2 = ((fact[w - b - i + a - 2]) * modinv(fact[w - b - 1 - i]) % mod * modinv(fact[a - 1]) % mod) % mod;
		long long temp = ((temp1 % mod) * (temp2 % mod)) % mod; 
     	result = ((result % mod) + (temp % mod)) % mod;
    }
  	cout << result % mod << endl;
  	return 0;
}


Measured memory_bytes: 8064
#include <stdio.h>
#include <iostream>
#include <vector>
#include <queue>

using namespace std;

typedef pair<string,int> Pairsi;

int main(){
	priority_queue<Pairsi,vector<Pairsi>,greater<Pairsi> > q;
	Pairsi psi;
	vector<int> tn;
//	int tn[1000],tni=0;
	int c=0,n;
	string s,ts;


//input
	while(1){
		cin >> s >> n;
		if(cin.eof())break;
		q.push(make_pair(s,n));
		c++;
	}

//output
/*
	for(int i=0;i<c;i++){
		psi = q.top();
		q.pop();

		if(i==0){
	
		}else if(ts==psi.first){
			cout << "equal";
		}else{
			cout << ts << endl;

			for(int j=0;j<tn.size();j++){
				cout << tn[j] << ' ';
			}
			tn.clear();
			cout << endl;
		}

		ts = psi.first;
		tn.push_back(psi.second);
//		tn[tni++] = psi.second;

	}*/
	for(int i=0;i<c;i++){
		psi = q.top();
		q.pop();

		if(ts==psi.first){
			cout << " " << psi.second;
		}else{
			if(i!=0){
				cout << endl;
			}
			cout << psi.first << endl;
			cout << psi.second;
		}

		ts = psi.first;
	}

	puts("");

	return 0;
}

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

#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
#define MOD 1000000007

using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

int iy[]={0, 0, 1, -1};
int ix[]={1, -1, 0, 0};

long long int n, m, ans;

int main(){
	cin >> n >> m;
	for(long long int i=1;i<=sqrt(m);i++){
		if(m%i==0&&m/i>=n) ans = max(ans, i);
		if(m%i==0&&i>=n) ans = max(ans, m/i);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
N = int(input())
A = []
B = []
count = 0
for i in range(N):
  a, b = map(int, input().split())
  A.append(a)
  B.append(b)

A.reverse()
B.reverse()

for a,b in zip(A,B):
  if b != 1 and a + count != 0 and (a + count) % b != 0:
    count += b - (a + count) % b
    
print(count)

Measured memory_bytes: 56796
#include <bits/stdc++.h>
using namespace std; 
long long dp[500000]; 
inline long long stoii(string s)
{
	long long res=0;
	for(int i=0; i<s.size(); i++)
		res*=10, res+=(s[i]-'0');
	return res;	
}
int main() 
{  
    string s;
    cin>>s;
    memset(dp, 0, sizeof(dp));
    dp[0]=1, dp[1]=1, dp[2]=2, dp[3]=4, dp[4]=8, dp[5]=16, dp[6]=32, dp[7]=64, dp[8]=128, dp[9]=256, dp[10]=512;
    long long ans=0;
    int len=s.size();
    for(int i=1; i<=len; i++)
    	for(int j=0; (j+i)<=len; j++)
    		ans+=(long long)(stoii(s.substr(j, i))*dp[j]*dp[len-i-j]);
	cout<<ans;
    return 0;  
}  


Measured memory_bytes: 4096
#include<cstdio>
#include<algorithm>
using namespace std;
int gi(){
	int x=0,w=1;char ch=getchar();
	while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
	if(ch=='-')w=0,ch=getchar();
	while(ch>='0'&&ch<='9')x=(x<<3)+(x<<1)+ch-'0',ch=getchar();
	return w?x:-x;
}
const int N=2005;
const int mod=1000000007;
int n,m,k,f[N<<1][N][2],sum[N],ans;
int main(){
	n=gi();m=gi()-1;k=gi()-1;
	f[0][0][0]=1;
	for(int i=1;i<=max(n,m)<<1;++i){
		sum[0]=(f[i-1][0][0]+f[i-1][0][1])%mod;
		for(int j=1;j<=n;++j)sum[j]=(1ll*sum[j-1]+f[i-1][j][0]+f[i-1][j][1])%mod;
		for(int j=0;j<=n;++j){
			f[i][j][0]=(sum[j]-sum[j-1]+mod)%mod;
			int x=max(0,j-k);
			f[i][j][1]=(sum[j-1]-(x?sum[x-1]:0)+mod)%mod;
		}
		for(int j=0;j<=n;++j)
			if(j%k==n%k&&(i*k-j)%k==m%k&&i*k-j<=m)
				ans=(ans+f[i][j][1])%mod;
	}
	printf("%d\n",ans);return 0;
}


Measured memory_bytes: 62848
def d_katana_thrower():
    # 最大振り火力をもつ刀以上の投げ火力をもつ刀は、大火力のものから順に投げる。
    # 投げダメージの総和が敵の体力より大きければ投げて倒せばいいし、
    # 足りなければ最大振り火力をもつ刀を降り続けて倒せばいい。
    # ただし、最大振り火力をもつ刀については、投げ火力が振り火力より高くても、
    # 投げる前に振らなければならないが、「投げてから振る」とみなして問題ない。
    N, H = [int(i) for i in input().split()]
    Swords = [[int(i) for i in input().split()] for j in range(N)]
    max_swing = max([s[0] for s in Swords])
    sword_to_throw = sorted([s[1] for s in Swords if s[1] >= max_swing], reverse=True)

    threw_times = 0
    for damage in sword_to_throw:
        H -= damage
        threw_times += 1
        if H <= 0:
            return threw_times  # 刀を投げている途中で敵を倒したら終わり
    return threw_times + -(-H // max_swing)

print(d_katana_thrower())

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

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

  string ret="No";
  // temp = sqrt(a)*sqrt(b);
  //cout <<temp << endl;
  //cout << a+b+2*sqrt(static_cast<long double>(a*b))<< endl;
  //cout << c<< endl;
  if(a+b+2*sqrt(static_cast<long double>(a*b))<c) ret="Yes";
  cout << ret;
  

}

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

using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define MIN(a, b) ((a) > (b) ? (b) : (a))
#define MAX(a, b) ((a) < (b) ? (b) : (a))

const long long INF = 1LL << 60;
typedef unsigned long long ll;
const long long MOD = 1000000000 + 7;

int main() {
  int a, b;
  cin >> a >> b;
  if (a + b >= 10)
    cout << "error" << endl;
  else
    cout << a + b << endl;
  return 0;
}

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

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vi l(n);
  for (int i = 0; i < n; i++) {
    cin >> l[i];
  }
  int longest = 0;
  int sum = 0;
  for (int i = 0; i < n; i++) {
    sum += l[i];
    longest = max(longest, l[i]);
  }
  if (longest < (sum - longest)) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define fi first
#define se second
#define ll long long
#define dbg(v) cerr<<#v<<" = "<<v<<'\n'
#define vi vector<int>
#define vl vector <ll>
#define pii pair<int,int>
#define mp make_pair
#define db long double
#define pb push_back
#define all(s) s.begin(),s.end()
template < class T > T smin(T &a,T b) {if (a > b) a = b;return a;}
template < class T > T smax(T &a,T b) {if (a < b) a = b;return a;}
bitset < (1 << 22) > D;
int main(void)
{
    int n;
    cin>>n;
    D[0] = 1;
    int sum = 0;
    while (n --)
    {
        int v;
        cin>>v;
        sum += v;
        D |= D << v;
    }
    int ans = (sum + 1) / 2;
    while (!D[ans])
        ++ans;
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 1920
import java.util.Scanner;

public class Main {

	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		int p = Math.min(sc.nextInt(), Math.min(sc.nextInt(), sc.nextInt()));
		int d = Math.min(sc.nextInt(), sc.nextInt());
		System.out.println(p + d - 50);
	}
}

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

#define inf 1e+9
#define endl "\n"
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()

#define m0(x) memset(x, 0, sizeof(x))
#define fill(x, y) memset(x, y, sizeof(x))

#define lb(c, x) distance((c).begin(), lower_bound(all(c), (x)))
#define ub(c, x) distance((c).begin(), upper_bound(all(c), (x)))

template <class T> using pq = priority_queue<T>;
template <class T> using pqg = priority_queue<T, vector<T>, greater<T>>;

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

int main(){
    int n; cin >> n;
    vlint a(n), b(n), c(n);
    rep(i, n) cin >> a[i];
    rep(i, n) cin >> b[i];
    rep(i, n) cin >> c[i];
    sort(all(a));
    sort(all(c));

    lint ans = 0;
    rep(i, n){
        ans += lb(a, b[i]) * (n - ub(c, b[i]));
    }
    cout << ans << endl;

}


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


int main () {

    long long  a,b,c;
    cin >> a >> b >> c;
    long long A = 4 * a * b;
    long long B = (c - a - b) *(c -a - b) ;
    if ((c - a - b) < 0){
        cout << "No" <<endl;
        return 0;
    }
    if(A < B){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}




Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
#define g 9.8

int main(void) {
	int h;
	float s,t,y;
	while(scanf("%f",&s) != EOF){
		t = s/g;
		y = g*t*t/2;
		h = y;
		printf("%d\n",(h+10)/5);
	}
	return 0;
}

Measured memory_bytes: 624
#include <stdio.h>
int main(void){
    int a,b,c,d;
    scanf("%d%d%d%d",&a,&b,&c,&d);
    if(a+b==c+d) printf("Balanced");
    else if(a+b>c+d) printf("Left");
    else printf("Right");
    return 0;
}


Measured memory_bytes: 128
#include <stdio.h>
#include <string.h>

int main( void )
{
	char str[1001];
	char inst[8];
	char p[1001];
	char tmp;
	int i, j, q, a, b;
	
	scanf("%s", str);
	scanf("%d", &q);
	
	for(i = 0; i < q; i++){
		scanf("%s %d %d", inst, &a, &b);
		
		if(strcmp(inst, "replace") == 0){
			scanf("%s", p);
			for(j = a; j <= b; j++){
				str[j] = p[j - a];
			}
		} else if(strcmp(inst, "reverse") == 0){
			for(j = a; j < b-(j-a); j++){
				tmp = str[j];
				str[j] = str[b-(j-a)];
				str[b-(j-a)] = tmp;
			}
		} else if(strcmp(inst, "print") == 0){
			for(j = a; j <= b; j++){
				printf("%c", str[j]);
			}
			printf("\n");
		} else {
			// DO NOTHING
		}
	}
	
	return 0;
}

Measured memory_bytes: 1816
//
// Created by yamunaku on 2020/01/10.
//

#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repl(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perl(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD9 998244353
#define MOD1 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP <<" "<<
#define CYES cout<<"Yes"<<endl
#define CNO cout<<"No"<<endl
#define CFS cin.tie(0);ios::sync_with_stdio(false)
#define CST(x) cout<<fixed<<setprecision(x)

using ll = long long;
using ld = long double;
using vi = vector<int>;
using mti = vector<vector<int>>;
using vl = vector<ll>;
using mtl = vector<vector<ll>>;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
template<typename T>
using heap = priority_queue<T, vector<T>, function<bool(const T, const T)>>;

ll gcd(ll x, ll y){
    ll tmp;
    while(x % y){
        tmp = x % y;
        x = y;
        y = tmp;
    }
    return y;
}

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


int main(){
    // CFS;
    int n, m;
    cin >> n >> m;
    vi a(n);
    rep(i, n) cin >> a[i], a[i] /= 2;

    ll x = 1;
    int tmp = a[0];
    int count = 0;
    while(tmp % 2 == 0){
        tmp /= 2;
        count++;
    }
    rep(i, n){
        x = lcm(x, a[i]);
        tmp = a[i];
        int c = 0;
        while(tmp % 2 == 0){
            tmp /= 2;
            c++;
        }
        if(c != count){
            cout << 0 << endl;
            return 0;
        }
        if(x > m){
            cout << 0 << endl;
            return 0;
        }
    }

    cout << (m - x) / 2 / x + 1 << endl;
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <sstream>
#include <queue>
#include <deque>
#include <set>
#define ll long long
#define MP make_pair
#define PII pair<int, int>
#define F first
#define S second
#define SHN 1e9
#define lSHN 1e18
using namespace std;
int n,m;
int res;
int main()
{
	cin >>n>>m;
	res=n*3+m;
	cout <<res/2;
	return 0;
} 

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <limits>
#include <climits>
#include <utility>
#include <algorithm>
#include <numeric>

using namespace std;

using ll = long long;
using ull = unsigned long long;

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

    ull i = b - a;
    ull x = i*(i+1)/2 - b;
    cout << x << endl;

    return 0;
}


Measured memory_bytes: 512
from collections import deque, defaultdict, Counter
N, M, K = (int(i) for i in input().split())  
A = list(map(int, input().split()))
B = list(map(int, input().split()))
CA = [0]
CB = [0]
for i in range(N):
  CA.append(CA[i] + A[i])
  
for i in range(M):
  CB.append(CB[i] + B[i])

r = M
ans = 0
for i in range(N+1):
  if CA[i] > K:
    break
    
  while CA[i] + CB[r] > K:
    r -= 1  
  ans = max(ans, i + r)
  
print(ans)

Measured memory_bytes: 49308
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <limits.h>	
#define inf INT_MAX
#define INF 9223372036854775807
#define rep(i,n) for(i=0;i<n;i++)

int in(void){
	int i;scanf("%d",&i);
	return i;
}
long long llin(void){
	long long i;scanf("%lld",&i);
	return i;
}
void chin(char s[]){
	scanf("%s",s);
}
void print(int a){
	printf("%d\n",a);
}
void llprint(long long a){
	printf("%lld\n",a);
}
void print2(int a,int b){
	printf("%d %d\n",a,b);
}
long long max(long long a,long long b){
	return a>b?a:b;
}
long long min(long long a,long long b){
	return a<b?a:b;
}

int main(void){
	int n=in(),i,s[100],sum=0,m=0;
	rep(i,n){
		s[i]=in();
		sum+=s[i];
	}
	if(sum%10!=0){
		print(sum);
		return 0;
	}
	rep(i,n){
		if((sum-s[i])%10!=0){
			m=max(m,sum-s[i]);
		}
	}
	print(m);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll; // [9,223,372,036,854,775,807 to -9.....808] 19 digits
typedef long double ld;
#define inc(i, a, b) for (long long int i = a; i <= b; i++)
#define dec(i, a, b) for (long long int i = a; i >= b; i--)
#define fast                      \
    ios_base::sync_with_stdio(0); \
    cin.tie(NULL);                \
    cout.tie(NULL);
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define lv vector<ll>
#define cv vector<char>
#define dv vector<ld>
#define rall(c) (c).rbegin(), (c).rend()
#define lpr pair<ll, ll>
#define mp make_pair
#define cin(c) \
    ll c;      \
    cin >> c;
#define lmap unordered_map<ll, ll>
#define vinp(a, n) \
    inc(i, 1, n)   \
    {              \
        cin(k);    \
        a.pb(k);   \
    }
#define LIM 1000000007
#define F first
#define S second
#define fr(i, n) inc(i, 0, n - 1)
#define fri(n, a) \
    inc(i, 0, n - 1) { cin >> a[i]; }
#define debug(p) cout << p;
#define umap unordered_map
#define uset unordered_set
#define fill(a, val, n) \
    inc(i, 0, n - 1) { a[i] = val; }
void i_love_Accepted()
{
    ll n;
    cin>>n;
    ll p=n/1000;
    if(n%1000==0)
    {
        cout<<0;
        return;
    }
    cout<<(p+1)*1000-n;
}   
int main()
{
    fast;
    ll t=1;
    //cin>>t;
    while(t--)
    {
        i_love_Accepted();
        cout<<"\n";
    } 
}


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

#define int long long

int n;
string s;
int t;
vector<int> all;
int pow_10;

void dfs(int m, int bit, int sum) {
  if ( m == n ) {
    if ( abs(sum-t) < pow_10/3 ) return;
    all.emplace_back(sum);
    return;
  }

  for ( int i = 0; i < 10; i++ ) {
    if ( bit & (1<<i) ) continue;
    int nxt = sum;
    nxt *= 10;
    nxt += i;
    dfs(m+1, bit|(1<<i), nxt);    
  }
}

struct St {
  int m, bit, sum;  
};

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  cin >> s;
  t = (int)stoll(s);  

  n = s.size();
  pow_10 = pow(10, n);  
  // dfs(0, 0, 0);
  
  stack<St> S;
  S.push({0, 0, 0});

  while ( !S.empty() ) {
    St p = S.top(); S.pop();
    int m = p.m, bit = p.bit, sum = p.sum;    
    if ( m == n ) {
      if ( abs(sum-t) < pow_10/3LL ) {
	continue;
      }
      all.emplace_back(sum);
      continue;      
    }

    for ( int i = 0; i < 10; i++ ) {
      if ( bit & (1LL<<i) ) continue;
      if ( m == 0 ) {
	if ( abs(i-(s[0]-'0')) > 5 ) {
	  continue;
	}
      }
      int nxt = sum;
      nxt *= 10LL;
      nxt += i;
      // dfs(m+1, bit|(1<<i), nxt);      
      S.push({m+1, bit|(1LL<<i), nxt});      
    }
  }

  sort(all.begin(), all.end());  

  int ans = t;
  int ma = 0;
  for ( int i = 0; i < (int)all.size(); i++ ) {
    if ( ma < min(abs(all[i]-t), pow_10-abs(all[i]-t)) ) {      
      ma = min(abs(all[i]-t), pow_10-abs(all[i]-t));      
      ans = all[i];      
    }
  }

  cout << setfill('0') << setw(n) << right;  
  cout << ans << endl;
  
  return 0;
}



Measured memory_bytes: 19640
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define REPL(i,m,n) for(ll i=(ll)(m); i<(ll)(n); i++)
#define repl(i,n) REPL(i,0,n)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
int main() {
  int N, K;
  cin >> N >> K;
  vector<ll> H(N);
  rep(i, N) cin >> H[i];
  sort(all(H));
  if(N <= K) cout << 0 << endl;
  else cout << accumulate(H.begin(), H.begin()+(N-K), 0LL) << endl;
  return 0;
}


Measured memory_bytes: 1792
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
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; }

class union_find {
    private:
        vector<int> par;
        vector<int> ran;
        vector<ll> size;
    public:
        union_find(int n);
        int find(int x);
        void unite(int x, int y);
        bool same(int x, int y);
        ll show_size(int x);
};

union_find::union_find(int n){
    par.resize(n);
    ran.resize(n);
    size.resize(n);
    rep(i,n) par[i] = i;
    rep(i,n) ran[i] = 0;
    rep(i,n) size[i] = 1;
};

int union_find::find(int x) {
    if(par[x] == x) return x;
    else return par[x] = find(par[x]);
};

void union_find::unite(int x, int y) {
    x = find(x);
    y = find(y);
    if(x == y) return;
    ll t = show_size(x)+show_size(y);
    size[x] = size[y] = t;
    if(ran[x] < ran[y]){
        par[x] = y;
        //size[y] += size[x];
    }
    else{
        par[y] = x;
        //size[x] += size[y];
        if(ran[x] == ran[y]) ran[x]++;
    }
};

ll union_find::show_size(int x) {
    if(par[x] == x) return size[x];
    return show_size(par[x] = find(par[x]));
}

bool union_find::same(int x, int y) {
    return (find(x) == find(y));
};

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, m, k;
	cin >> n >> m >> k;
	union_find uf(n);
	vector<vector<int>> v(n);
	rep(i,m){
		int a, b;
		cin >> a >> b;
		--a; --b;
		uf.unite(a, b);
		v[a].push_back(b);
		v[b].push_back(a);
	}
	rep(i,k){
		int c, d;
		cin >> c >> d;
		--c; --d;
		v[c].push_back(d);
		v[d].push_back(c);
	}
	rep(i,n){
		int ans = uf.show_size(i) - 1;
		for(auto p : v[i]){
			if(uf.same(i, p)) --ans;
		}
		cout << ans << " ";
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 11264
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
const int INF = 1<<29;
int main() {
    int N; cin >> N;
    string S; cin >> S;
    vector<int> r(N+1,0),g(N+1,0),b(N+1,0);
    for (int i=0;i<N;++i){
        r[i+1] = r[i];
        g[i+1] = g[i];
        b[i+1] = b[i];
        if (S[i]=='R') r[i+1]++;
        if (S[i]=='G') g[i+1]++;
        if (S[i]=='B') b[i+1]++;
    }
    ll res = 0;
    
    for (int i=0;i<N-2;++i) for (int k=i+2;k<N;++k){
        if (S[i]==S[k]) continue;
        char C;
        if (S[i]=='R' && S[k]=='G') C = 'B';
        if (S[i]=='G' && S[k]=='R') C = 'B';
        if (S[i]=='R' && S[k]=='B') C = 'G';
        if (S[i]=='B' && S[k]=='R') C = 'G';
        if (S[i]=='B' && S[k]=='G') C = 'R';
        if (S[i]=='G' && S[k]=='B') C = 'R';
        
        if (C=='R') res += r[k] - r[i+1];
        if (C=='G') res += g[k] - g[i+1];
        if (C=='B') res += b[k] - b[i+1];
        if ((k-i)%2==0){
            int j = i + (k-i)/2;
            if (S[j]==C) res--;  
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 3640
// AOJ 2940 Numbers game
// 2018.3.13 bal4u

#include <stdio.h>
#include <stdlib.h>

#if 1
#define gc() getchar_unlocked()
#define pc(c) putchar_unlocked(c)
#else
#define gc() getchar()
#define pc(c) putchar(c)
#endif
int in()
{
	int n = 0, c = gc();
	do n = 10 * n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}

void ins(char *s)
{
	do *s = gc();
	while (*s++ > ' ');
	*(s - 1) = 0;
}

void out(int n)
{
	int i;
	char ob[20];

	if (!n) pc('0');
	else {
		i = 0; while (n) ob[i++] = n % 10 + '0', n /= 10;
		while (i--) pc(ob[i]);
	}
}

int N;
int a[20000][2], M;

void bsch()
{
	int m, l = 0, r = N;
	char s[10];

	while (l < r) {
		m = (l + r) >> 1;
		out(m + 1), pc('\n'), fflush(stdout);
		ins(s);
		if (s[0] == 'Y') return;   // Yes
		if (s[1] == 'e') r = m;    // Near
		else l = m + 1;
	}
}

void mkgraph(int l, int r)
{
	int i, m;

	if (l >= r) return;
	m = (l + r) >> 1;
	for (i = l; i < m; i++) {
		a[M][0] = m + 1;
		a[M++][1] = i + 1;
	}
	mkgraph(l, m), mkgraph(m + 1, r);
}

int main()
{
	int i, K;

	N = in(), K = in();
	mkgraph(0, N);
	out(M), pc('\n');
	for (i = 0; i < M; i++) {
		out(a[i][0]), pc(' ');
		out(a[i][1]), pc('\n');
	}
	fflush(stdout);

	while (K--) bsch();
	return 0;
}


Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i, j, n) for(int i=j;i<n;++i)
#define all(i) i.begin(),i.end()
#define rall(i) i.rbegin(),i.rend()
#define INF 1e9
#define LINF 1e18
const int mod = 1e9 + 7;
 
typedef long long i64;
typedef pair<int, int> pi;
 
template <class T> using vt = vector<T>;
template <class T> using vvt = vector<vector<T>>;
 
i64 gcd(i64 n, i64 m) {return (m == 0? n : gcd(m, n % m));}
i64 lcm(i64 n, i64 m) {return (n / gcd(n, m) * m);}
int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};

struct Edge {
  int to;
  i64 cost;

  Edge(int _to, i64 _cost) : to(_to), cost(_cost) {}
};

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

  int n, k;
  cin >> n >> k;
  vt<int> h(n);
  rep(i, 0, n) cin >> h[i];

  vt<int> dp(n, INF);
  dp[0] = 0;
  rep(i, 0, n) {
    for(int j = i + 1; j <= i + k && j < n; ++j) {
      dp[j] = min(dp[j], dp[i] + abs(h[j] - h[i]));
    }
  }
  cout << dp[n - 1] << endl;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define maxn 200005
int n;
int R[maxn];
int main()
{
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        scanf("%d",&R[i]);
    }
    int minv=R[0];
    int maxv=R[1]-R[0];
    for(int i=1;i<n;i++)
    {
        maxv=max(maxv,R[i]-minv);
        minv=min(minv,R[i]);
    }
    printf("%d\n",maxv);
    return 0;
}

Measured memory_bytes: 3976
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long LL;
 
const int N = 1e5 + 1;
 
struct edge
{
	int to, w;
};
 
vector<edge> G[N];
LL d[N];
 
void dfs(int v, int p)
{
	for (edge id : G[v])
    	if (id.to != p)
        {
        	d[id.to] = d[v] + id.w;
          	dfs(id.to, v);
        }
}
 
int main()
{
	int n, a, b, c, q, k;
  	cin >> n;
  	for (int i = 1; i < n; ++i)
    {
    	cin >> a >> b >> c;
      	G[a].push_back({b, c});
      	G[b].push_back({a, c});
    }
  	cin >> q >> k;
  	dfs(k, 0);
  	for (int i = 0; i < q; ++i)
    {
    	cin >> a >> b;
     	cout << d[a] + d[b] << '\n';
    }
}

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

#define int long long

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

/*
#define cin ifs
#define cout ofs
ifstream ifs("in.txt");
ofstream ofs("out.txt");
//*/

int N, X, Y, Z;
int mem[40][1 << 17];
int mod = 1e9 + 7;

int dp(int idx, int prev) {
    if (idx == N) {
        return 1;
    }
    if (mem[idx][prev] != -1) {
        return mem[idx][prev];
    }
    int res = 0;
    for (int i = 0; i < 10; i++) {
        int cur = (prev << 1) + 1 << i;
        cur &= ~(~0 << X + Y + Z);
        bitset<17> bs(cur);
        if (!bs[Z - 1] || !bs[Y + Z - 1] || !bs[X + Y + Z - 1]) {
            res += dp(idx + 1, cur);
            res %= mod;
        }
    }
    return mem[idx][prev] = res;
}

signed main() {
    for (int i = 0; i < 40; i++) {
        for (int j = 0; j < 1 << 17; j++) {
            mem[i][j] = -1;
        }
    }
    cin >> N >> X >> Y >> Z;
    int ans = 1;
    for (int i = 0; i < N; i++) {
        ans *= 10;
        ans %= mod;
    }
    cout << (ans + mod - dp(0, 0)) % mod << endl;
    return 0;
}

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


main(){
   ll n,i;
   string s,ans;
   cin >> n >> s;

   if(n%2==1){
       ans="No";
   }else{
       ans="Yes";
       for(i=0;i<n/2;i++){
           if(s[i]!=s[n/2+i]){
               ans="No";
               break;
           }
       }
   }
   cout << ans << endl;
}

Measured memory_bytes: 256