akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

main()
{
	long long a,b,n;
	scanf("%lld %lld %lld",&n,&a,&b);
	a-=b;
	vector<long long> v(n);
	for(int i=0;i<n;i++)
	{
		scanf("%lld",&v[i]);
	}
	long long l=1,r=1e10;
	while(l<=r)
	{
		//printf("%lld %lld\n",l,r);
		if(l==r)
		{
			printf("%lld\n",l);
			return 0;
		}
		long long mid=(l+r)/2;
		long long com=mid*b,use=mid;
		//printf("%lld\n",com);
		for(int i=0;i<n;i++)
		{
			if(v[i]-com>0)
			{
				use-=(v[i]-com)/a;
				//printf("%lld:%lld\n",i+1,use);
				if((v[i]-com)%a!=0)use--;
			}
		}
		if(use<0)
		{
			l=mid+1;
		}
		else
		{
			r=mid;
		}
	}
}

Measured memory_bytes: 1024
N,Q = gets.split.map &:to_i
r = [0]

if N == 1
  Q.times{
  	p gets.split.map(&:to_i).min
  }
  exit
end

30.times{ |q|
  x = N ** q
  break if x > 10**10
  r << r[-1] + x
}
Q.times{
  u,v = gets.split.map(&:to_i)
  #u,v = v,u if v > u
  j = r.rindex{|x| u > x }
  anc = {}
  anc[u] = 1
  while j > 0 do
    u = (u - r[j] - 1)/N + r[j-=1] + 1
    anc[u] = 1
  end
  if anc[v]
    p v; next
  end
  j = r.rindex{|x| v > x }
  while j > 0 do
    v = (v - r[j] - 1)/N + r[j-=1] + 1
    break if anc[v]
  end
  p v
}

Measured memory_bytes: 3068
#include <bits/stdc++.h>
using namespace std ;
#define ll long long
void FastInputOutput(){
    ios_base :: sync_with_stdio( 0 ) ;
    cin.tie( 0 ) ;
    cout.tie( 0 ) ;
}

inline int D(){
    int t ;
    scanf( "%d" , &t ) ;
    return t ;
}
inline ll LLD(){
    ll t ;
    scanf( "%lld" , &t ) ;
    return t ;
}

ll power(ll x, ll p, ll m){
    ll res = 1;
    while(p){
        if(p&1)    res = (res * x)%m;
        x = (x * x)%m;
        p >>= 1;
    }
    return res;
}
long double ModLog(long double base, long double x) {
    return (logl(x) / logl(base));
}

const int N = 1e6 + 5, MX = 1e9;
int cnt(int n){
    int ret = 0;
    while (n) {
        ret += n % 10;
        n /= 10;
    }
    return ret;
}

int main(){
    int n = D(), k = D();
    int ans = 1;
    int tot = k;
    while (tot < n)
        tot += (k - 1), ++ans;
    printf("%d", ans);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

#define MOD 1000000007

using namespace std;

#define int long long

int extgcd(int a, int b, int& x, int& y) {
  int d = a;
  if (b != 0) {
    d = extgcd(b, a % b, y, x);
    y -= (a / b) * x;
  } else {
    x = 1;
    y = 0;
  }
  return d;
}

int mod_inverse(int a, int m) {
  int x, y;
  extgcd(a, m, x, y);
  return (m + x % m) % m;
}

int comb(int a, int b, int m) {
  if (b > a - b) {
    return comb(a, a - b, m);
  }
  if (b < 0) {
    return 0;
  }
  int ans = 1;
  for (int i = 1; i <= b; i++) {
    ans = ans * (a + 1 - i) % m;
    ans = ans * mod_inverse(i, m) % m;
  }
  return ans;
}

signed main() {
  int n, k;
  cin >> n >> k;
  for (int i = 1; i <= k; i++) {
    int c1 = comb(n - k + 1, i, MOD);
    c1 = c1 * comb(k - 1, i - 1, MOD) % MOD;
    c1 = (c1 + MOD) % MOD;
    cout << c1 << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
#define eps 1e-7
#define eq(x,y) (fabs((x)-(y)) < eps)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int>pii;
const int mod = 998244353;
long double PI = acosl(-1);
const ll infl = 1e18+100;
const int inf = 2e9+100;
const int nmax = 2e5+2;
const int MAXLG = log2(nmax)+1;
//mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
//typedef tree< int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ost;

vector<pair<pii,pii> >Q;
int n,m;
int ans;

void recc(int baki, int curmax, vector<int>& v){
    if(baki==0){
        int cur = 0;
        for(auto z : Q){
            if(v[z.first.second] - v[z.first.first] == z.second.first)
                cur += z.second.second;
        }
        ans = max(ans , cur);
        return;
    }
    for(int i=curmax; i<m; i++){
        v.push_back(i);
        recc(baki-1, i, v);
        v.pop_back();
    }
}

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

//    freopen("bajeces.txt", "r", stdin);
//    freopen("mara.txt", "w", stdout);
    int q;
    cin>>n>>m>>q;
    Q.resize(q);
    for(auto & z : Q){
        cin>>z.first.first>>z.first.second>>z.second.first>>z.second.second;
        z.first.first--, z.first.second--;
    }
    vector<int>faka;
    recc(n, 0, faka);

    cout<<ans;
}
/*

*/


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

int main() {
	int ans=0;
	char S[4];
	cin>>S;
	for(int i=0;i<3;i++){
		if(S[i]=='o')ans+=100;
		}
		cout<<ans+700;
	}

Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sstream>
#include <functional>
#include <map>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <list>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;
#define rep(i,n) for(int (i)=0;(i)<(ll)(n);++(i))
#define repd(i,n,d) for(ll (i)=0;(i)<(ll)(n);(i)+=(d))
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset((m),(v),sizeof(m))
#define chmin(X,Y) ((X)>(Y)?X=(Y),true:false)
#define chmax(X,Y) ((X)<(Y)?X=(Y),true:false)
#define fst first
#define snd second
#define UNIQUE(x) (x).erase(unique(all(x)),(x).end())
template<class T> ostream &operator<<(ostream &os, const vector<T> &v){int n=v.size();rep(i,n)os<<v[i]<<(i==n-1?"":" ");return os;}

#define N 320
int h, w;
ll dp[N][N], dp2[N][N];
vector<string> s;

ll calc2(ll i, ll j, ll k){
	ll c = 0;
	rep(l, h){
		int i2 = l-i, j2 = l-j;
		if(i2>=0 && j2>=0 && s[i2][k]==s[j2][k+1]) c++;
	}
	return c;
}

ll calc(ll a, ll b, ll k){
	if(a<0||b<0) return INF;
	if(dp[a][b]<INF) return dp[a][b];
	ll &res = dp[a][b];
	res = calc2(a, b, k)+min(calc(a-1, b, k), calc(a, b-1, k));
	return res;
}

int main(){
	cin>>h>>w;
	s = vector<string>(h);
	rep(i, h) cin>>s[i];
	ll res = 0;
	rep(k, w-1){
		rep(_, N) fill(dp[_], dp[_]+N, INF);
		mset(dp2, 0);
		//dp[0][0] = calc2(0, 0, k);
		dp[0][0] = 0;
		rep(i, h+1){
			rep(j, h+1){
				ll c = dp[i][j];
				ll r = 0;
				if(i>0 && j>0){
					r = dp2[i-1][j-1];
					if(s[h-i][k]==s[h-j][k+1]) r--;
				} else {
					rep(l, h){
						if(l-i>=0 && l-j>=0 && s[l-i][k]==s[l-j][k+1]) r++;
					}
				}
				dp2[i][j] = r;
				chmin(dp[i+1][j], c+r);
				chmin(dp[i][j+1], c+r);
			}
		}
		res += dp[h][h];
		//res += calc(h, h, k);
	}
	cout<<res<<endl;
	return 0;
}


Measured memory_bytes: 2048
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
#define rep(i,n) for (int i=0; i<n;++i)
using namespace std;

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

    string S, T, ans;
    cin >> S >> T;
    int l = T.size();
    if (S.size() < l){
        cout << "UNRESTORABLE" << endl;
        return 0;
    }
    rep(i,S.size()-l+1){
        string S2 = S.substr(i,l);
        rep(j, l){
            if (S2[j] == '?' || S2[j] == T[j]){
                if (j == l-1){
                    string tmp = S;
                    S.replace(i,l,T);
                    rep(k, S.size()) if(S[k] == '?') S[k]='a';
                    if(ans.empty()) ans=S;
                    else ans=min(ans,S);
                    S=tmp;
                    break;
                }else continue;
            }else break;
        }
    }

    if (ans.empty()) cout << "UNRESTORABLE" << endl;
    else cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <cstring>
#include <utility>
#include <algorithm>
#include <functional>
#include <deque>
#include <cctype>
#include <ctime>
#include <cstdlib>
#include <iomanip>
using namespace std;

int main(){
    string s;;
    cin >> s;;
    ;
    bool f = true;
    if(s[1-1]!='A') f = false;
    int cnt = 0;
    for (int i = 3; i <= s.size()-1; ++i) if(s[i-1]=='C') {++cnt; s[i-1] = 'c';};
    if(cnt!=1) f = false;
    for (int i = 2; i <= s.size(); ++i) if(!(('a'<=s[i-1]&&s[i-1]<='z'))) f = false;
    if(f) cout << "AC" << endl;
    else cout << "WA" << endl;;
}


Measured memory_bytes: 504
#include <iostream>
#include <algorithm>
using namespace std;
typedef pair<int,int> P;
bool f_sort(P a,P b){return a.first>b.first;};
bool s_sort(P a,P b){return a.second<b.second;};
int main(){
  int n,ans=0;
  cin >>n;
  P r[n];P b[n];
  for(int i=0;i<n;i++){
    cin >> r[i].first >> r[i].second;
  }
  for(int i=0;i<n;i++){
    cin >> b[i].first >> b[i].second;
  }
  sort(r,r+n,f_sort);//rのx座標を大きい順に並べる
  sort(b,b+n,s_sort);//bのy座標を小さい順に並べる
  for(int i=0;i<n;i++){//bの下にある点から調べる
    for(int j=0;j<n;j++){//rの上にある点から調べる
      if((r[j].first<b[i].first)&&(r[j].second<b[i].second)&&r[j].first!=-1){
        ans++;
        r[j].first=-1;
        break;
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <queue>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1<<30;

int main() {
  int q1,b,c1,c2,q2;
  while(cin >> q1, q1) {
    cin >> b >> c1 >> c2 >> q2;
    int a1 = min(q2,b/c1);
    int a2 = (b-a1*c1) / c2;
    
//    printf("[%d,%d]\n",a1,a2);
    while(a1 + a2 < q1) {
      a1--;
      if (a1 == 0) {
        break;
      }
      while(a1 * c1 + a2 * c2 <= b)
        a2++;
      a2--;
    }
    if (a1 == 0)
      cout << "NA";
    else
      cout << a1 << " " << a2;
    cout << endl;
    
  }
}

Measured memory_bytes: 0
#include <cstdlib>
#include <iterator>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cctype>
#include <functional>
using namespace std;

int main() {
    int a, b, x;
    cin >> a >> b >> x;
    if(a > x | a + b < x) cout << "NO" << endl;
    else cout << "YES" << endl; 
}


Measured memory_bytes: 256
#include <cstdio>

using namespace std;

int N;
int memory[100];

int count(int target, int counter) {
  if (target % 2 != 0)
    return counter;
  else
    return count(target / 2, ++counter);
}

int main() {
  scanf("%d", &N);
  int max_value = 0;
  int ans = 0;
  for(int i=1;i<=N;++i){
    memory[i-1] = count(i, 0);
    if(max_value <= memory[i-1]){
      max_value = memory[i-1];
      ans = i;
    }
  }
  printf("%d", ans);
}


Measured memory_bytes: 128
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define rep(i,l,n) for(int i=l;i<n;i++)
#define ull unsigned long long
#define min(a,b) (a)<(b)?(a):(b)
#define max(a,b) (a)>(b)?(a):(b)

int main(){
	int A,B;
	scanf("%d %d",&A,&B);
	rep(i,0,1100){
		if( floor(i*0.08)==A && floor(i*0.1)==B ){
			printf("%d",i);
			return 0;
		}
	}
	printf("-1");
	return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll mod = 1e9+7;
ll power(ll a,ll b){
    ll res=1;
    while(b){
        if(b&1)res=res*a%mod;
        b>>=1;
        a=a*a%mod;
    }
    return res;
}

int main(){
    ll n,i,j,t,x,y,ma=0,mi=1e17;
    cin>>x>>y;
    if(x>=10)cout<<y;
    else cout<<100*(10-x)+y;
}
/*
7
140 1
120 2
100 3
120
100
-1
100
*/


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

int main() {
    using BS = bitset<64>;
    int n; cin >> n;
    vector<BS> mask(n);
    for (auto &ms: mask) {
        int k; cin >> k;
        while (k--) {
            int i; cin >> i; ms.set(i);
        }
    }
    BS b;
    int q; cin >> q;
    while (q--) {
        int t; cin >> t;
        if (t == 0) {
            int i; cin >> i; cout << b.test(i) << endl;
        } else {
            int m; cin >> m;
            if (t == 1) b |=  mask[m];
            if (t == 2) b &= ~mask[m];
            if (t == 3) b ^=  mask[m];
            if (t == 4) cout << ((b & mask[m]) == mask[m]) << endl;
            if (t == 5) cout << (b & mask[m]).any() << endl;
            if (t == 6) cout << (b & mask[m]).none() << endl;
            if (t == 7) cout << (b & mask[m]).count() << endl;
            if (t == 8) cout << (b & mask[m]).to_ullong() << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3100
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp setprecision
#define pb(x) push_back(x)
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ld, ld> pdd;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = 1e8;
const ll INF = 1e16;
const string alpha = "abcdefghijklmnopqrstuvwxyz";

int main(){
    string s;
    cin >> s;
    int n = s.size();
    if(s[0] == s[n-1]){
        if(n%2 == 0) cout << "First" << endl;
        else cout << "Second" << endl;
    }
    else{
        if(n%2 == 0) cout << "Second" << endl;
        else cout << "First" << endl;
    }
}

Measured memory_bytes: 512
import java.util.*;
import java.util.function.*;
public class Main {
  public static void main(String[] args) {
    long mod = (long)Math.pow(10,9) + 7;
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    long[] A = new long[N];
    for (int i = 0; i < N; i++) {
      A[i] = sc.nextLong();
    }
    long ans = 0;
    for (int i = 0; i < 60; i++) {
        long cnt = 0;
        for (int j = 0; j < N; j++){
            if (((A[j] >>> i) & 1) == 1){
                cnt++; // 1の物をカウント
            }
        }
        long a = (cnt * (N - cnt)) % mod; //0の数*1の数=合計カウント数
        for (int j = 0; j < i; j++){
            a = (a << 1) % mod; //桁を繰り上げて元に戻す
        }
        ans += a;
        ans %= mod;
    }
    System.out.println(ans);
  }
}

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

const string YES = "Yes";
const string NO = "No";

void solve(long long x, long long y){
    map<int, char> g;
    g.insert(make_pair(1, 'A'));
    g.insert(make_pair(3, 'A'));
    g.insert(make_pair(5, 'A'));
    g.insert(make_pair(7, 'A'));
    g.insert(make_pair(8, 'A'));
    g.insert(make_pair(10, 'A'));
    g.insert(make_pair(12, 'A'));
    g.insert(make_pair(4, 'B'));
    g.insert(make_pair(6, 'B'));
    g.insert(make_pair(9, 'B'));
    g.insert(make_pair(11, 'B'));
    g.insert(make_pair(2, 'C'));
    if (g[x] == g[y]) cout << YES << '\n';
    else cout << NO << '\n';
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    long long x;
    scanf("%lld",&x);
    long long y;
    scanf("%lld",&y);
    solve(x, y);
    return 0;
}


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

int main() {
    
    int n,m;
    cin>>n>>m;
    
    int S[n][n];
    const int INF = 10e6;
    int a[m],b[m],c[m];
    
    for (int i=0; i<n; i++) {
        for (int j=0; j<n; j++) {
            S[i][j] = INF;
            if (i==j) S[i][j]=0;
        }
    }
    
    for (int i=0; i<m; i++) {
        int s,t,w;
        cin>>s>>t>>w;
        S[s-1][t-1] = w;
        S[t-1][s-1] = w;
        a[i] = s-1;
        b[i] = t-1;
        c[i] = w;
    }
    
    for(int k=0; k<n; k++) {
        for (int i=0; i<n; i++) {
            for (int j=0; j<n; j++) {
                S[i][j] = min(S[i][j], S[i][k] + S[k][j]);
            }
        }
    }
    
    int out = m;
    for (int x=0; x<m; x++) {
        for (int i=0; i<n; i++) {
            if (S[i][a[x]] + c[x] == S[i][b[x]]) {
                out--;
                break;
            }
        }
    }
    
    cout << out << endl;
    
    
    return 0;
}

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

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

using LL  = long long;
// }}}

int main() {
    std::ios::sync_with_stdio(false);
    int n, k;cin >> n >> k;
    int ans = 0;
    for(int i=1;i<=n;i++){
        int x;cin >> x;
        ans += min(abs(x-k), abs(x))*2;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<map>
#include<tuple>
#include<cmath>


#define MOD 1000000007
#define rep(i,k,N) for(int i=k;i<N;i++)
#define MP make_pair
#define MT make_tuple //tie,make_tuple は別物
#define PB push_back

typedef long long ll;

using namespace std;

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

int main(){
    string S;
    cin>>S;
    bool Aans =true, Bans=true;
    rep(i,0,3){
        if(S[i]=='A'){
            Bans =false;
        }
        else{
            Aans =false;
        }
    }
    if(Aans || Bans){
        cout <<"No";
    }
    else cout <<"Yes";
    return 0;
}

Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}

func nextIntSlice(size int) []int {
	re := make([]int, size)
	for i := 0; i < size; i++ {
		re[i] = nextInt()
	}
	return re
}

func max(a ...int) int {
	max := a[0]
	for _, v := range a {
		if v > max {
			max = v
		}
	}
	return max
}

func min(a ...int) int {
	min := a[0]
	for _, v := range a {
		if v < min {
			min = v
		}
	}
	return min
}

func abs(n int) int {
	if n < 0 {
		return -n
	}
	return n
}

func main() {
	sc.Split(bufio.ScanWords)
	w, a, b := nextInt(), nextInt(), nextInt()
	if a > b {
		a, b = b, a
	}
	ans := b - (a + w)
	if ans < 0 {
		fmt.Println(0)
	} else {
		fmt.Println(ans)
	}
}


Measured memory_bytes: 640
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#define ll long long
#define pb push_back
#define mp make_pair
#define rep(i, a, b) for(int i = a; i <= b; i++)
void read(int &x) {
    x = 0; int flag = 1; char ch = ' ';
    while(ch < '0' || ch > '9') { if(ch == '-') flag = -1; ch = getchar(); }
    while(ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
    x *= flag;
}
void read(ll &x) {
    x = 0; int flag = 1; char ch = ' ';
    while(ch < '0' || ch > '9') { if(ch == '-') flag = -1; ch = getchar(); }
    while(ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
    x *= flag;
}
using namespace std;
int n, k;
vector < pair <int, int> > a;
void write() {
    printf("%d\n", (int)a.size());
    rep(i, 0, a.size() - 1) printf("%d %d\n", a[i].first, a[i].second);
}
int main()
{
    read(n), read(k);
    if((n - 1) * (n - 2) / 2 < k) {
        puts("-1");
        return 0;
    }
    rep(i, 1, n - 1) a.pb(mp(i, n));
    int cur = (n - 1) * (n - 2) / 2;
    if(cur == k) { write(); return 0; }
    rep(i, 1, n - 2)
        rep(j, i + 1, n - 1) {
            a.pb(mp(i, j));
            cur--;
            if(cur == k) { write(); return 0; }
        }
    return 0;
}

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

typedef pair<int,int> P;
#define ll long long
#define ld long double
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
#define sz(x) ((int)(x).size())
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(x) (x).begin(),(x).end()

const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
int main()
{
    int n;cin >> n;
    vector<ll> a(n);
    rep(i,n)cin >> a[i];
    ll mx = -1;
    ll add = 0;
    rep(i,n)
    {
        if(a[i]<mx)
        {
            add += (mx-a[i]);
        }
        mx = max(mx, a[i]);
    }
    cout << add << endl;
}

Measured memory_bytes: 4836
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<functional>
#include<math.h>
 
#define rep(i,n) for(ll i=0;i<(n);i++)
typedef long long ll;
using namespace std;

int main(void){
    ll N,money = 1000,stock = 0;
    cin >> N;
    vector<ll> A(N);
    rep(i,N){
        cin >> A.at(i);
    }
    rep(i,N-1){
        if(A.at(i)<A.at(i+1)){
            money += (A.at(i+1)-A.at(i))*(money/A.at(i));
        }
    }
    cout << money << endl;
}

Measured memory_bytes: 3600
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <cmath>
#include <list>
#include <chrono>
#include <thread>

using namespace std;

const bool debug = false;

#ifndef M_PI
    const double M_PI = acos(-1.0);
#endif // M_PI

#define y1 roman_kaban
#define rank oryshych_konb
#define ull unsigned long long
//#define ll long long
const int mod = int(1e9) + 9;
//const int inf = 1e7;
//const long long infLL = 1e16;
//const int MX2 = 10100500; //  e7
//const long long INF = 1e18 + 0.5;
const int MX = 1200500; //       e5
const int SZ = 11;

int a[MX];

int main()
{
    //vector<int> a;lower_bound(a.begin(), a.end());
    //brute(); return 0;
    ios_base::sync_with_stdio(false);
    //freopen("/Users/ozzy/Documents/in.txt","r", stdin);
    int n, x, y;
    cin >> n >> x >> y;
    x -= y;
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    int low = 0;
    int hi = 1e9;
    while(low + 1 < hi){
        long long mid = (low + hi) >> 1;
        int cnt = mid;
        for(int i = 0; i < n; i++){
            long long z = a[i] - mid * y;
            if(z < 0) z = 0;
            cnt -= (z + x - 1) / x;
            if(cnt < 0) break;
        }
        if(cnt < 0) low = mid; else hi = mid;
    }
    cout << hi << endl;
    return 0;
}


Measured memory_bytes: 640
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <climits>
#include <cmath>
#include <complex>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <cstdint>
using namespace std;
typedef long long ll;
#define MP make_pair
#define PB push_back
#define inf 1000000007
#define mod 1000000007
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)

int main(){
    int n;
    cin >> n;
    vector<pair<int,int> > a;
    rep(i,n){
        int b;
        cin >> b;
        a.push_back(MP(b,i+1));
    }
    sort(a.begin(),a.end());
    rep(i,n){
        cout << a[i].second << " ";
    }
    cout << endl;
    return 0;
}

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

int main(int argc, const char * argv[]) {
    // insert code here...
    int W,H,N;
    int x[100],y[100],a[100];
    scanf("%d%d%d",&W,&H,&N);
    for(int i=0;i<N;i++){
        scanf("%d%d%d",&x[i],&y[i],&a[i]);
    }
    int s[W][H];
    memset(s,0,sizeof(s));
    
    for(int i=0;i<N;i++){
        if(a[i]==1)
        {
            for(int X=0;X<x[i];X++)
            {
                for(int Y=0;Y<H;Y++)
                {
                    s[X][Y] = 1;
                }
            }
        }
        if(a[i]==2){
            for(int X = x[i];X<W;X++){
                for(int Y=0;Y<H;Y++){
                    s[X][Y] = 1;
                }
            }
        }
        
        if(a[i] == 3){
            for(int Y=0;Y<y[i];Y++){
                for(int X=0;X<W;X++){
                    s[X][Y] = 1;
                }
            }
        }
        
        if(a[i]==4){
            for(int Y=y[i];Y<H;Y++){
                for(int X=0;X<W;X++){
                    s[X][Y] = 1;
                }
            }
        }
        
        
       
    }
    int count = 0;
    for(int i=0;i<W;i++){
        for(int k=0;k<H;k++){
            if(s[i][k] == 0){
                count++;
            }
        }
    }
    printf("%d\n",count);
    
    return 0;
}


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

signed main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    string S, T;
    cin >> S >> T;
    int A, B;
    cin >> A >> B;
    string U;
    cin >> U;
    (S == U ? A : B) --;
    cout << A << " " << B << endl;
    return 0;
}





Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int M = sc.nextInt();

		if(N > M) {
			System.out.println("No");
		}else {
			System.out.println("Yes");
		}

	}

}


Measured memory_bytes: 23892
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;

/* short */
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) begin(v), end(v)
#define RALL(v) rbegin(v), rend(v)

/* REPmacro */
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define REP(i, n) for(int i = 0; i < (n); i++)

/* exchange */
#define chmin(a, b) (a) = min((ll)(a), (ll)(b))
#define chmax(a, b) (a) = max((ll)(a), (ll)(b))

/* output */
#define I(x) cin >> x;
#define D(x) cerr << (x) << " ";
#define BR cerr << "\n";
#define P(x) cout << (x) << endl;
#define FIX cout << fixed << setprecision(10);

/* const */
const int ARRAY = 100005;
const int INF = 1001001001; // 10^9
const ll LINF = 1001001001001001001; // 10^18
const int MOD = 1e9 + 7;

ll N = 0;
ll K;
ll ret = 0;
vvl table(61, vl(200005));

int main(void){
  
  I(N);
  I(K);
  FOR(i, 1, N+1) {
    I(table[1][i]);
  }
  FOR(i, 2, 61) {
    FOR(j, 1, N+1) {
      table[i][j] = table[i-1][table[i-1][j]];
    }
  }

  ll now = 1;
  FOR(i, 1, 61) {
    if ((K >> (i-1)) & 1) {
      now = table[i][now];
    }
  }

  P(now);

}


Measured memory_bytes: 99956
#include <bits/stdc++.h>
#define rep(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<x<<endl
using namespace std;
using ll = long long;
const ll MOD = 1e9+7;
const ll LINF = LLONG_MAX;
const int INF = INT_MAX;
const double PI=acos(-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; }

int main(){
	int h,w,k; cin>>h>>w>>k;
	vector<string> c(h);
	rep(i,0,h) cin>>c[i];
	int res=0;
	// bit全探索
	for(int hbit = 0; hbit < (1 << h); hbit++){
		for(int wbit = 0; wbit < (1 << w); wbit++){
			int cnt = 0;
			for(int i = 0; i < h; i++){
				for(int j = 0; j < w; j++){
					// もしi,jが選ばれていて, 黒だったらおk
					if((hbit & (1<<i)) and (wbit & (1<<j)) and (c[i][j] == '#')){
						cnt++;
					}
				}
			}
			if(cnt == k) res++;
		}
	}
	cout<<res<<endl;
}

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


int main() {

  ios_base::sync_with_stdio(false);
  cin.tie(0); cout.tie(0);

  int A,B,C; cin >> A >> B >> C;

  int maxL = max(A,max(B,C));
  int minL = min(A,min(B,C));
  int midL = A ^ B ^ C ^ maxL ^ minL;

  int diff1 = maxL - minL;
  int diff2 = maxL - midL;

  if ((diff1 % 2 == 0) && (diff2 % 2 == 0)) {
    //cout << "evens" << endl;
    cout << (diff1 + (diff2-diff1)/2) << endl;
  } else if ((diff1 % 2 != 0) && (diff2 % 2 != 0)) {
    //cout << "odds" << endl;
    cout << (1 + (diff1-1)/2 + (diff2-1)/2) << endl;
  } else {
    diff1++;
    diff2++;
    int ans = 1;
    if (diff1 % 2 == 0) {
      ans += diff1/2 + (diff2-1)/2;
    } else { 
      ans += diff2/2 + (diff1-1)/2;
    }
    cout << ans << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<map>
#include<bitset>
using namespace std;

typedef long long ll;
#define rep(i, n) for(int i = 0;i < (n);i++)
#define repr(i, n) for(int i = (n);i >= 0;i--)
#define repf(i, m, n) for(int i = (m);i < (n);i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1;} return 0;}
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1;} return 0;}
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
//////////////////////////////////////////////////


int main() {
    ll k; cin >> k;
    auto bfs = [&](ll s) -> ll {
        ll cnt = 0;
        if (s <= 9) return s;
        priority_queue<ll, vector<ll>, greater<ll>> que;
        repf(i,1,10) que.push(i);
        cnt += 9;
        while(!que.empty()) {
            ll cur = que.top();
            ll t = cur%10;
            que.pop();
            int st = max(0,(int)t-1), en = min(9,(int)t+1);
            repf(i,st,en+1) {
                cnt++;
                if (cnt == s) {
                    return cur*10+i;
                }
                que.push(cur*10+i);
            }
        }
    };
    cout << bfs(k) << endl;
    return 0;
}

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

int main(void){

    string s;
    cin >> s;

    char c[s.size()];
    s.copy(c, s.size());

    ll sum = 0;
    ll num = 0;

    rep(i, s.size()){
        sum += c[i] - '0';
        num += pow(10, s.size() - i - 1) * (c[i] - '0');
    }

    if(num % sum == 0){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}


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

int main(void){
    int n;
    long long y;
    cin >> n >> y;
    for(int i = 0;i<=n;i++){
        for(int j = 0;i+j<=n;j++){
            int k = n - (i + j);
            int total = 10000*i+5000*j+1000*k;
            if(total == y){
                cout << i << " " << j << " " << k << endl;
                return 0;
            }
        }
    }
    cout << -1 << " " << -1 << " " << -1 << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define L long long
#define pb push_back
#define pi pair<int,int>
#define pii pair<pair<int,int>,int>
#define aa first
#define bb second
#define mp make_pair
#define mpp(a,b,c) mp(mp(a,b),c)
using namespace std;
int n,f[1010],g[5010],x[1010],p;
vector<int> a[1010];
inline void dp(int i,int j)
{
	int k,l,u;
	for(auto k:a[i])
	  if(k!=j)
	    dp(k,i);
	for(auto k:a[i])
	  if(k!=j)
	    for(l=x[i];l>=0;l--)
	      {
		   u=1e9;
		   if(l>=x[k])
		     u=min(u,g[l-x[k]]+f[k]);
		   if(l>=f[k])
		     u=min(u,g[l-f[k]]+x[k]);
	       g[l]=u;
		  }
	for(k=0,l=1e9;k<=x[i];k++)
	  l=min(l,g[k]),g[k]=0;;
	if(l>5e8)
	  p=1;
	else
	  f[i]=l;
}
int main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	int i,j;
	scanf("%d",&n);
	for(i=2;i<=n;i++)
	  {
	   scanf("%d",&j);
	   a[j].pb(i);
	  }
	for(i=1;i<=n;i++)
	  scanf("%d",&x[i]);
	dp(1,0);
	if(p)
	  printf("IMPOSSIBLE\n");
	else
	  printf("POSSIBLE\n");
	return 0;
}


Measured memory_bytes: 384
/// In the name of God
#include <bits/stdc++.h>
//#define int long long
using namespace std;
typedef pair<int,int> pii;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;

#define y1 def1
#define X first
#define Y second
#define endl '\n'
#define all(o) o.begin(), o.end()
#define IOS ios::sync_with_stdio(0), cin.tie(0)
const int maxn = 1e5 + 10;
vi adj[maxn];
int dfs(int v,int p){
    int res = 0;
    for(auto u : adj[v])
        if(u != p) res ^= (dfs(u, v) + 1);
    return res;
}
int main(){
    int n;
    cin >> n;
    for(int i=0; i<n-1; i++){
        int u, v;
        cin >> u >> v;
        u--, v--;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    if(dfs(0, 0))
        cout << "Alice" << endl;
    else
        cout << "Bob" << endl;
}


Measured memory_bytes: 10368
import java.util.Scanner;


public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
	
		while(sc.hasNext()){
			int n = sc.nextInt();
			if(n == 0)break;
			
			int cnt = 0;
			for(int i=1;i<n;i++) {
				int sum = i;
				for(int j=i+1;j<n;j++) {
					if(sum+j == n) {
						cnt++;
						break;
					}
					if(sum+j < n) {
						sum += j;
						continue;
					}
					else break;
				}
			}
			
			System.out.println(cnt);
		}
		
	}
}


Measured memory_bytes: 26472
#include<bits/stdc++.h>
#define mod 1000000007
#define ll long long int
#define ar array
#define mp make_pair
using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	int x,a,b;
	cin>>x>>a>>b;
	cout<<(abs(x-a)<abs(x-b)?"A":"B")<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
int main() {
 	int N;cin >>N; 
 	int A[N]; 
 	for(int i=0;i<N;i++){
 	cin >>A[i];
 	}
  
  for(int i=0;i<N;i++){
  	int v=A[i];
    int j=i-1;
  	while(j>=0&&A[j]>v){
  	A[j+1]=A[j];
    j--;
    A[j+1]=v;
  	}
   for(int k=0;k<N;k++){
 	if(k==N-1&&i==N-1){cout <<A[k]<<endl;}
    else if(i<N-1&&k==N-1){cout <<A[k]<<endl;}
    else{cout<<A[k]<<' ';}
   }
  }
}
 


Measured memory_bytes: 3132
n=int(input())
h=list(map(int, input().split()))+[0]*10
dp=[10**10]*(n+10)
dp[0]=0
dp[1]=abs(h[0]-h[1])
for i in range(0, n):
    dp[i+1] = min(dp[i+1], dp[i]+abs(h[i]-h[i+1]))
    dp[i+2] = min(dp[i+2], dp[i]+abs(h[i]-h[i+2]))
print(dp[n-1])


Measured memory_bytes: 52208
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();
//a, b <= n
// a % b >= k
// a = b*x+k', k' >= k => b > k
// 2^10
int main() {
    ll n, k, ans = 0;
    cin >> n >> k;
    for(ll div= k+1; div <= n; div++) {
        ll rem = n % div;
        ll cnt = n/div;
        //[(0... k-1), k ... div] , 0 <= rem <= k-1
        //[0... k-1, (k ... )div] , k <= rem < div
        // remain pattern:
        //  1, 2, 3, ..div-1, div,div+1,
        // (1, 2, 3, ..div-1, 0) ,    1, 2,
        ll acc = k*cnt; // count remain = [0, k-1]
        if (k != 0) {
            acc += min(k-1, rem);
        }
        // cout << "div = " << div << ", cnt " << cnt << ", acc = " << (n-acc) << endl;
        ans += n - acc;
    }
    cout << ans << endl;
    return 0;
}




Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int K, S;
  int count = 0;

  scanf("%d %d", &K, &S);

  for(int X = 0; X <= K; X++){
    for(int Y = 0; Y <= K; Y++){

      int Z = S - (X + Y);
      if(Z >= 0 && Z <= K){
        count++;
      }

    }
  }

  printf("%d\n", count);
  
  return 0;
}


Measured memory_bytes: 128
from sys import stdin
import sys
if __name__ == "__main__":
    # stdin = open("input.txt")
    

    N, Y = (int(item) for item in stdin.readline().rstrip().split())

    for a in range(0, N+1):
        max_b = N-a
        for b in range(0, max_b+1):
            c = N - a - b
            if Y == a*10000 + b*5000 + c*1000:
                print(a, b, c)
                sys.exit(0)
    print("-1 -1 -1")

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

using ll = long long;

using namespace std;

int main(){
  int K;
  string S;
  cin >> K >> S;
  bool add = false;
  while((int) S.size() > K){
    S.pop_back();
    add = true;
  }
  if(add){
    S.push_back('.');
    S.push_back('.');
    S.push_back('.');
  }
  cout << S;
  return 0;
}


Measured memory_bytes: 3624
#include <iostream>
#include<stdlib.h>
#include <stdio.h>
using namespace std;

#define INF 1000000000

int cnt=0;

void merge(int s[],int left,int mid,int right){
    int n1,n2;
    int *l,*r;
    n1=mid-left;
    n2=right-mid;
    l=(int *)malloc(sizeof(int)*(n1+1));
    r=(int *)malloc(sizeof(int)*(n2+1));
    for (int i=0; i<=n1-1; i++) {
        l[i]=s[left+i];
    }
    for (int j=0; j<=n2-1; j++) {
        r[j]=s[mid+j];
    }
    l[n1]=INF;
    r[n2]=INF;
    int i=0;
    int j=0;
    for (int k=left; k<=right-1; k++) {
        if(l[i]<=r[j]){
            s[k]=l[i];
            i++;
            cnt++;
        }
        else{
            s[k]=r[j];
            j++;
            cnt++;
        }
    }
    free(l);
    free(r);
}


void mergesort(int s[],int left,int right){
    int mid;
    if (left+1<right) {
        mid=(left+right)/2;
        mergesort(s, left, mid);
        mergesort(s, mid, right);
        merge(s,left,mid,right);
    }
}

int main(){
    int n;
    int s[500000];
    cin>>n;
    for (int i=0; i<n; i++)cin>>s[i];
    mergesort(s, 0, n);
    for (int i=0; i<n-1; i++)cout<<s[i]<<" ";
    cout<<s[n-1]<<endl<<cnt<<endl;
    return 0;
}

Measured memory_bytes: 6744
import numpy as np


def main():
    N = int(input())
    S = input()
    count = 1
    now = S[0]
    for n in range(1, N):
        if(now != S[n]):
            count += 1
            now = S[n]
    print(count)


if(__name__ == "__main__"):
    main()


Measured memory_bytes: 12660
def main():
    D = int(input())
    c = list(map(int, input().split()))
    s = [list(map(int, input().split())) for _ in range(D)]

    for i in range(D):
        tmp = s[i]
        print(tmp.index(max(tmp))+1)


if __name__ == "__main__":
    main()


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

using namespace std;
const int N = 1e6 + 1;
long long a[N] , avail[N] , b[N] , c[N];
int n , q;
vector <int> V;
void compress(){
    V.push_back(-1);
    for (int i = 1; i <= n; i++) V.push_back(a[i]);
    for (int i = 1; i <= q; i++){
        V.push_back(b[i]);
        V.push_back(c[i]);
    }
    sort(V.begin(),V.end());
    V.resize(unique(V.begin(),V.end()) - V.begin());
    for (int i = 1; i <= n; i++) a[i] = lower_bound(V.begin(),V.end(),a[i]) - V.begin();
    for (int i = 1; i <= q; i++){
        b[i] = lower_bound(V.begin(),V.end(),b[i]) - V.begin();
        c[i] = lower_bound(V.begin(),V.end(),c[i]) - V.begin();
    }
}   
int main(){
    //freopen("thaythe.inp","r",stdin);
    //freopen("thaythe.out","w",stdout);
    ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    cin >> n; 
    for (int i = 1; i <= n; i++) cin >> a[i];
  	cin >> q;
    for (int i = 1; i <= q; i++) cin >> b[i] >> c[i];
    compress();
    long long sum = 0;
    for (int i = 1; i <= n; i++){
        sum = sum + V[a[i]];
        avail[a[i]]++;
    }
    for (int i = 1; i <= q; i++)
           {
            sum = sum - 1LL * V[b[i]] * avail[b[i]];
            sum = sum + 1LL * V[c[i]] * avail[b[i]];
            avail[c[i]] += avail[b[i]];
            avail[b[i]] = 0;
            cout << sum << "\n";
        }
    return 0;
}

Measured memory_bytes: 7652
#include <bits/stdc++.h>
#define va first
#define vb second
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

map<string, string> mp;
string s;
int main() {
	mp["Sunny"] = "Cloudy";
	mp["Cloudy"] = "Rainy";
	mp["Rainy"] = "Sunny";

	cin >> s;
	cout << mp[s];
}

Measured memory_bytes: 764
#!venv/bin/python
 
import math
import numpy as np
import random
import copy
import statistics 
import bisect
import heapq
from collections import defaultdict 
import time
import sys
from pprint import pprint

N = int(input())
A = [ int(x) for x in input().split() ]

min_heap = []
max_heap = []

for a in A:
    heapq.heappush(min_heap, a)
    heapq.heappush(max_heap, -a)

ans = []
for i in range(N-2):
    max = -heapq.heappop(max_heap)
    min = heapq.heappop(min_heap)
    diff = max - min
    new_val = 0
    if -max_heap[0] - (-diff) > diff - min_heap[0]:
        ans.append("{} {}".format(min,max))
        new_val = -diff
    else:
        ans.append("{} {}".format(max,min))
        new_val = diff
    heapq.heappush(max_heap, -new_val)
    heapq.heappush(min_heap, new_val)

print( -max_heap[0] - min_heap[0]  )
for a in ans:
    print(a)
print("{} {}".format(-max_heap[0], min_heap[0]))



Measured memory_bytes: 35456
(* O(n log n) *)
let kNMax = 200000 in
let kInf = 300000 in
Scanf.scanf " %d %d" @@ fun n k ->
  let a_s = Array.init n @@ fun _ -> Scanf.scanf " %d" @@ (+) 0 in
  let balls = Array.make (kNMax + 1) 0 in
  Array.iter (fun a -> balls.(a) <- balls.(a) + 1) a_s;
  let c = ref 0 in
  Array.iteri (fun i b -> if b = 0 then balls.(i) <- kInf else incr c) balls;
  Printf.printf "%d\n" @@
    if !c <= k then 0
    else
      (Array.sort (-) balls;
      Array.sub balls 0 (!c - k) |> Array.fold_left (+) 0)

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

int main() {
  string S;
  int X=0;
  cin >> S;
  int Y=S.size();
  
  for(int i=0; i < Y/2; i++){
   if(S[i] != S[Y-i-1]){
     X++;
   }
  }
  cout << X << endl;
}


Measured memory_bytes: 3612
#include <queue>
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <string>
#include <vector>
#include <map>
#include <functional>
#include <set>

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

using namespace std;
typedef long long int ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pint;
const ll inf = (1LL << 60);
//const ll mod = 1000000007;
ll max(ll a, ll b) {
	if (a < b)
		return b;
	else
		return a;

}
ll min(ll a, ll b) {
	if (a < b)
		return a;
	else
		return b;

}

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





ll sum[3000];

int main() {

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


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

	
	
	ll ans = 0;
	for (int i = 0; i < N; i++) {
		for (int j = i+1; j < N; j++) {

			auto it = lower_bound(L.begin(), L.end(), abs(L[i] - L[j]));
			auto it2 = lower_bound(L.begin(), L.end(), L[i] + L[j]);
			int l1 = max(distance(L.begin(), it), j+1);
			int l2 = distance(L.begin(), it2);

			ans += max(l2 - l1, 0);

		}

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

Measured memory_bytes: 256
#include<algorithm>
#include<iostream>
#include<vector>
#include<string>
#include<queue>
#include<stack>
#include<cmath>
#include<list>
#include<set>
#include<map>

using namespace std;
long long MOD = 1000000007LL;
const double PI = 3.14159265358979323846;
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483648
#define INT_MAX 2147483647
#define endl "\n"

int main() {
	string s, t;
	cin >> s;
	cin >> t;

	int count = 0;
	for (int i = 0; i < s.length(); ++i) {
		if (s[i] != t[i]) {
			++count;
		}
	}

	cout << count << endl;
	return 0;
}

Measured memory_bytes: 3896
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        List<Integer> suuzi = new ArrayList<>();
        for(int i = 0; i < 3; i++){
            suuzi.add(sc.nextInt());
        }
        Collections.sort(suuzi, Collections.reverseOrder());
        int m = ((suuzi.get(0) * 10) + suuzi.get(1)) + suuzi.get(2);
        System.out.println(m);
    }
}


Measured memory_bytes: 22356
#include "bits/stdc++.h"
using namespace std;

#define sz(x) (int)(x.size())
#define FOR(i,L,R) for(int i = L; i <= R; i++)
#define int long long

const int N = 2e5 + 2, inf = 1e18;

vector<array<int,2>> a;

int get(int i, int j) {
    int dist = abs(a[i][0] - a[j][0]) + abs(a[i][1] - a[j][1]);
    return dist;
}

int32_t main(){
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    int n;
    cin >> n;
    a.resize(n);
    vector<int> pos, neg;

    FOR(i,0,n-1) {
        cin >> a[i][0] >> a[i][1];
        pos.push_back(a[i][0] + a[i][1]);
        neg.push_back(a[i][0] - a[i][1]);
    }

    int ans = 0;
    sort(pos.begin(), pos.end());
    sort(neg.begin(), neg.end());

    ans = max({ans, pos.back() - pos[0], neg.back() - neg[0]});
    cout << ans;
}


Measured memory_bytes: 9824
#include<iostream>
#define N 1000006
using namespace std;


void init(bool array[]){
	for(int i=0;i<N;i++){
		array[i]=true;
	}
}

void eratos(bool array[]){
	for(int i=2;i*i<N;i++){
		if(array[i]==true){
			for(int j=0;i*(j+2)<N;j++){
				array[i*(j+2)] = false;
			}
		}
	}
	array[1]=false;
}

int main(){
	bool array[N];
	init(array);
	eratos(array);

	while(1){
		int  a,d, n,cnt=0;
		cin >> a >> d >>n;
		if(a+d+n==0) break;
		for(int i=a;;i+=d){
			if(array[i]){
				cnt++;
			}
			if(cnt==n){
				cout << i << endl;
				break;
			}
		}

	}
	return 0;
}

Measured memory_bytes: 2132
#include <bits/stdc++.h>
#include <iostream>
#include <math.h>    //pow(x,y)=x^y 99999とかの場合+1するif文
#include <algorithm> //sort(a.begin(), a.end());reverse(a.begin(), a.end());
#include <ctime>     //実行時間を測る
#define ll long long
#define vecvec(h, w, name) vector<vector<ll>> name(h, vector<ll>(w));
#define rep(init, i, n) for (ll i = init; i < (n); i++)
#define rev(s) reverse(s.begin(), s.end())
#define sor(v) sort(v.begin(), v.end()) //昇順
#define PI 3.14159265358979323846264338327950L
//コード自動整形 Shift + Option + F @vscode
//変数名一括置換　command+fn+f2 @vscode
using namespace std;
using vec = vector<ll>;
//function
ll facctorialMethod(ll k);     //階乗を出力する
ll modpow(ll a, ll n, ll mod); // a^n mod を計算する
ll gcd(ll a, ll b);            //最大公約数
ll lcm(ll a, ll b);            //最小公倍数
//

//struct
// UnionFind
// coding: https://youtu.be/TdR816rqc3s?t=726
// comment: https://youtu.be/TdR816rqc3s?t=6822
struct UnionFind
{
  vector<ll> d;
  UnionFind(ll n = 0) : d(n, -1) {}
  ll find(ll x)
  { //根っこを返す
    if (d[x] < 0)
      return x;
    return d[x] = find(d[x]); //根っこの場所を貼り付ける
  }
  bool unite(ll x, ll y)
  { //くっつける操作、連結成分の情報整理 ABC177,157D参照
    x = find(x);
    y = find(y);
    if (x == y)
      return false;
    if (d[x] > d[y])
      swap(x, y); //dはマイナスをかけたサイズだからxの方がサイズ小さいようにする
    d[x] += d[y];
    d[y] = x;
    return true;
  }
  //find(i)でi番目の属しているグループ番号を出力
  bool same(ll x, ll y) { return find(x) == find(y); } //同じ集合に属しているかを判定
  ll size(ll x) { return -d[find(x)]; }                //あるID、xが所属するグループに所属するIDの数を得る ABC177,157D参照
};
//

/////main/////
int main()
{
  int clock_on = 0; //提出時は0!!!!!!!!!!!!!!!!!
  int time_clock = clock();
  //
ll K;string S;
cin>>K>>S;
if(S.size()<=K){cout<<S<<endl;return 0;}
else{
    cout<<S.substr(0,K)<<"..."<<endl;
    
}

  //
  if (clock_on == 1)
    printf("Execution Time: %.4lf sec\n", 1.0 * (clock() - time_clock) / CLOCKS_PER_SEC);
  return 0;
}
/////main/////

/////function/////
//階乗を出力する
ll facctorialMethod(ll k)
{
  ll sum = 1;
  for (ll i = 1; i <= k; ++i)
  {
    sum *= i;
  }
  return sum;
}

// a^n mod を計算する
ll modpow(ll a, ll n, ll mod)
{
  ll res = 1;
  while (n > 0)
  {
    if (n & 1)
      res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

//最大公約数
ll gcd(ll a, ll b)
{
  if (a % b == 0)
  {
    return b;
  }
  else
  {
    return gcd(b, a % b);
  }
}

//最小公倍数
ll lcm(ll a, ll b)
{
  return a * b / gcd(a, b);
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
#define fol(i,n) for(int i=0;i<n;i++)
#define pb push_back
typedef long long ll;
typedef pair<int,int> P;
typedef vector<P> vip;

void solve(){
    int a,b;cin>>a>>b;
    if (a<=0&&b>=0) {cout << "Zero"<<endl;return;}
    if (a>0) cout << "Positive"<<endl;
    else{
        if (b<0) cout << ((b-a)%2?"Positive":"Negative")<<endl;
        else cout << ((1-a)%2?"Positive":"Negative")<<endl;
    }
}

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


Measured memory_bytes: 256