akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const int mod=1000000007;
const int INF=1001001001;

int main() {
  int N,x;
  cin>>N>>x;
  vector<int>a(N);
  for(int i=0;i<N;i++){
    cin>>a[i];
  }
  sort(a.begin(),a.end());
  int sum=x;
  int cnt=0;
  for(int i=0;i<N;i++){
    if(sum==0){break;}
    else if(i==0&&a[i]>sum){break;}
    else if(i==N-1&&sum!=a[i]){break;}//余りが少ない個数でも押し付けられる
    else if(sum-a[i]<0){break;}
    else{cnt++;sum-=a[i];}
  }
  cout<<cnt<<endl;
  return 0;  
}

Measured memory_bytes: 3612
package main

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

////////////////////////////////////////
///        templates                 ///
////////////////////////////////////////

var sc = bufio.NewScanner(os.Stdin)

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

var rdr = bufio.NewReaderSize(os.Stdin, 1000000)

func readBigLine() string {
	buf := make([]byte, 0, 1000000)
	for {
		l, p, e := rdr.ReadLine()
		if e != nil {
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}

func strSprit(str string) []string {
	cols := strings.Split(str, " ")
	return cols
}

func parseInt(str string) int {
	n, _ := strconv.Atoi(str)
	return n
}

func intSprit(str string) []int {
	strs := strSprit(str)
	cols := make([]int, len(strs))
	for i, v := range strs {
		cols[i] = parseInt(v)
	}
	return cols
}

func bitCount(n uint) int {

	x := uint64(n)

	const m = 1<<64 - 1
	const m0 = 0x5555555555555555
	const m1 = 0x3333333333333333
	const m2 = 0x0f0f0f0f0f0f0f0f

	x = x>>1&(m0&m) + x&(m0&m)
	x = x>>2&(m1&m) + x&(m1&m)
	x = (x>>4 + x) & (m2 & m)
	x += x >> 8
	x += x >> 16
	x += x >> 32

	return int(x) & (1<<7 - 1)
}

func bitExist(n, i int) bool {
	return ((n >> uint(i)) & 1) == 1
}

func setBit(d, n int) int {
	t := 1 << uint(n)
	return d | t
}

func intAbs(n int) int {
	return int(math.Abs(float64(n)))
}

////////////////////////////////////////
///        end templates             ///
////////////////////////////////////////
type pair struct {
	l, idx int
	s      string
}

func isFlat(s string) bool {
	if len(s) <= 0 {
		return false
	}
	t := s[0]
	for i := 1; i < len(s); i++ {
		if t != s[i] {
			return false
		}
	}
	return true
}

func main() {
	S := readBigLine()

	z := 0
	o := 0

	for _, v := range S {
		sv := string(v)
		if sv == "0" {
			z++
		} else {
			o++
		}
	}

	low := 0

	if z >= o {
		low = o
	} else {
		low = z
	}

	fmt.Println(low * 2)
}


Measured memory_bytes: 1024
#include<cstdio>
#include<cmath>
#include<string>
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
#include<map>
#include<set>
#include<limits>
#include<bitset>
#include<array>
#include<numeric>
#include<iomanip>
#include<functional>

using namespace std;
typedef long long int ll;

#define C cout<<
#define E <<endl

ll n,m,aa[100010],b[100010];
map<int,int> mpa;
vector<int> vc;
ll gcd(ll tara,ll tarb){ //最大公約数
    ll am=1;
    while(am){
        am=tara%tarb;
        tara=tarb;
        tarb=am;
    }
    return tara;
}

ll lcm(ll tara,ll tarb){ //最小公倍数
    return tarb/gcd(tara,tarb)*tara;
}
int main(){
    cin>>n;
    ll qq;
    for(int i=0;i<n;i++){
        cin>>aa[i];
        if(!i)qq=aa[i];
        else qq=lcm(aa[i],qq);
    }
    C qq E;
    
}

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

signed main(){
	int n,p,dp[51][51] = {};
	cin >> n >> p;
	dp[0][0] = 1;
	for(int i = 0;i < n;i++) {
		int a;
		cin >> a;
		a %= 2;
		for(int j = 0;j <= 50;j++){
			if(j + a <= 50) dp[i + 1][j + a] += dp[i][j];
			dp[i + 1][j] += dp[i][j];
		}
	}
	int ans = 0;
	for(int i = 0;i <= 50;i++){
		if(i % 2 == p) ans += dp[n][i];
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 1000000000000000001
#define ll long long
using namespace std;
using pll = pair<ll, ll>;


int main()
{
  ll N, M;
  cin >> N >> M;
  ll all = 0;
  vector<ll> A(N);
  for (ll i = 0; i < N; ++i)
  {
    ll a;
    cin >> a;
    all += a;
    A.at(i) = a;
  }
  ll cnt = 0;
  for (ll i = 0; i < N; ++i)
  {
    if (A.at(i) * 4 * M >= all)
    {
      cnt += 1;
    }
  }
  if (cnt >= M)
  {
    cout << "Yes" << endl;
  }
  else
  {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <string>

using namespace std;

int main()
{
    string s;
    int i = 0;

    cin >> s;
    if(s[0] == '1') ++i;
    if(s[1] == '1') ++i;
    if(s[2] == '1') ++i;
    cout << i << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
// memo  fixed  setprecision(20);
using vvll = vector<vector<ll>>;
ll mod =1e9+7;
/*"itob" int to "N"base */           template<typename TypeInt> string itob(const TypeInt v, int base){static const char table[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";string ret;static numeric_limits<TypeInt> t;TypeInt n = v;if (t.is_signed) {if (v < 0) n *= -1;}while (n >= base) {ret += table[n%base];n /= base;}ret += table[n];if (t.is_signed) {if (v < 0 && base == 10) ret += '-';}reverse(ret.begin(), ret.end());return ret;}
/*"chmin" a = MAX*/                  template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
/*"chmax" a = MIN*/                  template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
/*"ctoi"  char to int*/              int ctoi(char c) {return c-'0';}
/*"gcd"   MAX Euclidean */           ll gcd(ll a,ll b){if(b==0)return a; return gcd(b,a%b);}
/*"lcm"   MIN*/                      ll lcm(ll a,ll b){ll g = gcd(a,b);return a/g*b;}
/*"primecheck"If prime,return true.*/bool primecheck(ll n){if(n < 2) return false;else{for(int i = 2; i * i <= n; i++){if(n % i == 0) return false;}return true;}}
string  reverserange(string s,ll a,ll b){reverse(s.begin()+a-1,s.begin()+b); return s;}
ll modpow(ll a,ll n, ll mod){ll res = 1;while(n>0){if (n%2==1){res = res * a % mod;}a = a * a % mod;n/=2;}return res;}
int main() {
    string s;
    cin >> s;
    for(int i=0;i<2;i++){
        for(int j=0;j<2;j++){
            for(int k=0;k<2;k++){
                for(int l=0;l<2;l++){
                    string che = "";
                    if(i==1)che+="AKIH";
                    else che+="KIH";
                    if(j==1)che+="AB";
                    else che+="B";
                    if(k==1)che+="AR";
                    else che+="R";
                    if(l==1)che+='A';
                    if(che==s){
                        cout <<"YES"<<endl;
                        return 0;
                    }
                }
            }
        }
    }
    cout <<"NO"<<endl;
}
    



Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("O3")

#define fi first
#define se second
#define em emplace
#define eb emplace_back
#define mp make_pair
#define pi pair<int,int>
#define vi vector<int>
#define vpi vector<pair<int,int>>
#define vll vector<ll>
#define vpll vector<pair<ll,ll>>
#define endl '\n'

#define si(v) int(v.size())
#define all(v) v.begin(), v.end()
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rep2(i, n, m) for (ll i = n; i <= (m); ++i)
#define rep3(i, n, m) for (ll i = n; i >= (m); --i)

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

using ll = long long;
using ld = long double;
using namespace std;

constexpr ll MOD = 1000000007;

signed main()
{
  cout << fixed << setprecision(20);
  ios::sync_with_stdio(false);
  cin.tie(0);
  
  int a, b; cin >> a >> b;
  int now = 1, ans = 0;

  while (b > now) {
    now += (a - 1);
    ++ans;
  }

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

Measured memory_bytes: 3612
#include<stdio.h>
#define len 100003
typedef struct{
    char na[10];
    int t;
}P;

P Q[len];
int head,tail;
void enqueue(P x){
    Q[tail]=x;
    tail=(tail+1)%len;
    
}

P dequeue(){
    P x=Q[head];
    head=(head+1)%len;
    return x;
}
int laps;

int main(){
    int n,q;
    scanf("%d %d",&n,&q);
    head=0,tail=n;
    int i;
    for(i=0;i<=n-1;i++){
        scanf("%s",Q[i].na);
        scanf("%d",&Q[i].t);
    }
    P u;
    while(head!=tail){
        u=dequeue();
        if(u.t>q){
            u.t-=q;
            laps+=q;
            enqueue(u);
        }else{
            laps+=u.t;
            printf("%s %d\n",u.na,laps);
        }
    }
    return 0;
}

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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

using ll = long long;
using vll = vector<ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using P = pair<int, int>;

vvi to;
vll ans;
map<int, int> cnt;

void dfs(int v, int p, ll c){
    ans[v] += c;
    for(auto u : to[v]){
        if(u == p) continue;
        dfs(u, v, c + cnt[u]);
    }
    return;
}

void Main() {
    int n, q; cin >> n >> q;
    to.resize(n);
    ans.resize(n, 0);
    
    rep(i, n-1){
        int a, b; cin >> a >> b; a--; b--;
        to[a].pb(b); to[b].pb(a);
    }
    
    rep(i, q){
        int p, x; cin >> p >> x; p--;
        cnt[p] += x;
    }
    
    dfs(0, -1, cnt[0]);
    
    rep(i, n) cout << ans[i] << " ";
    cout << endl;
    return;
}

int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}

Measured memory_bytes: 43008
#include <bits/stdc++.h>
using namespace std;
#define int int64_t
signed main(){
  int a,v,b,w,t,m;
  cin>>a>>v>>b>>w>>t;
  if(v-w<=0) cout<<"NO\n";
  else{
    if(a<0||b<0){
      m=min(a,b);
      m=0-m;
      a+=m;
      b+=m;
    }
    if(v*t-w*t>=abs(a-b)) cout<<"YES\n";
    else cout<<"NO\n";
  }
}

Measured memory_bytes: 3636
import numpy as np
N, S = [int(_) for _ in input().split()]
A = [int(_) for _ in input().split()]
dp = np.array([0] * (3001), dtype=int)
dp[0] = 2
dp[A[0]] = 1
mod = 998244353
for a in A[1:]:
    dpn = np.zeros(3001, dtype=int)
    dpn[a:] = dp[:-a]
    dpn += dp * 2
    dpn %= mod
    dp = dpn
print(dp[S])


Measured memory_bytes: 27528
numCards = gets.to_i;

aryCardField = Array.new(4).map{Array.new(13,false)};
 
for num in 0..numCards-1 do
 
	aryCardMarkNumber = gets.split(" ");
 
	cardMark = aryCardMarkNumber[0];
	cardNum = aryCardMarkNumber[1].to_i;
 
	case cardMark
	when "S" then
		aryCardField[0][cardNum-1] = true;
	when "H" then
		aryCardField[1][cardNum-1] = true;
	when "C" then
		aryCardField[2][cardNum-1] = true;
	when "D" then
		aryCardField[3][cardNum-1] = true;
	end
end

for countMark in 0..3 do
	for countNum in 0..12 do
		
		if aryCardField[countMark][countNum] == false then
			
			case countMark
			when 0 then
				puts "S " + (countNum+1).to_s;
			when 1 then
				puts "H " + (countNum+1).to_s;
			when 2 then
				puts "C " + (countNum+1).to_s;
			when 3 then
				puts "D " + (countNum+1).to_s;
			end
		end
		
	end
end

Measured memory_bytes: 8708
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e3+7, MOD = 1e9+7;
ll g[N][N], h, w, memo[N][N];
ll go(int i, int j) {
    if (i==h-1 && j==w-1) return 1;
    if (memo[i][j] != -1) return memo[i][j];
    ll tot = 0;
    if (i+1 < h && !g[i+1][j]) { tot += go(i+1, j); tot%=MOD; }
    if (j + 1 < w && !g[i][j+1]) { tot += go(i, j+1);tot%=MOD; }
    return memo[i][j] = tot;
}
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    cin >> h >> w;
    for (int i = 0; i < h; i++) {
        string s; cin >> s;
        for (int j = 0; j < w; j++) {
            char x=s[j];
            if (x == '#') g[i][j]=x;
            else g[i][j]= 0;
        }
    }
    memset(memo, -1, sizeof memo);
    int ans = go(0,0)%MOD;
    cout << ans << endl;

    return 0;
}

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

long long g(long long a, long long n, const long long p) {
    long long r = 1;
    while (n > 0) {
        if (n & 1) r = (r * a) % p;
        a = (a * a) % p;
        n >>= 1;
    }
    return r;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int x, y;
    cin >> x >> y;
    if ((x + y) % 3 != 0) cout << 0 << '\n';
    else if ((x + y) / 3 > min(x, y)) cout << 0 << '\n';
    else {
        // (0, 0)
        const long long magic = int(1e9) + 7;
        const int MAX_N = (2 * int(1e6)) / 3;
        long long f[MAX_N + 1];
        int n = (x + y) / 3;
        f[0] = 1;
        f[1] = 1;
        f[2] = 2;
        for (int x = 3; x <= n; ++x) f[x] = (f[x - 1] * x) % magic;
        int k = x - (x + y) / 3;
        long long dividend = f[n];
        long long divisor = (f[k] * f[n - k]) % magic;
        long long ans = (dividend * g(divisor, magic - 2, magic)) % magic;
        cout << ans << '\n';
    }
    return 0;
}


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

int main() {
  ll n,a,b,c,d,e; cin >>n >>a >>b >>c >>d >>e;
  ll ans = 4;
  ll tas = min(min(min(min(a,b),c),d),e);
  ans += (n+tas-1)/tas;
  
  
  cout <<ans;
  cout <<endl;
}

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

using namespace std;
using ll = long long;

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

    const int INF = 1000000000;

    int d;
    cin >> d;
    vector<int> c(26);
    vector<vector<int>> s(d, vector<int>(26));
    for(int i = 0; i < 26; ++i) cin >> c[i];
    for(int j = 0; j < d; ++j)
        for(int i = 0; i < 26; ++i) cin >> s[j][i];

    int m;
    vector<int> t(d);
    vector<int> blank(26);
    for(int j = 0; j < d; ++j) {
        for(int i = 0; i < 26; ++i) blank[i]++;
        m = - INF;
        for(int i = 0; i < 26; ++i) {
            if(s[j][i] + c[i] * blank[i] > m) {
                t[j] = i;
                m = s[j][i] + c[i] * blank[i];
            }
        }
        blank[t[j]] = 0;
    }

    for(int j = 0; j < d; ++j) {
        printf("%d\n", t[j] + 1);
    }

    return 0;
}

Measured memory_bytes: 3800
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cfloat>
#include<climits>
#include<cmath>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<string>
#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 REVERSE(x) reverse((x).begin(), (x).end())
#define TWINS(x) cout << ((x) ? "Yay!" : ":(") << '\n'
#define endl '\n'

constexpr int IINF = (1 << 30) - 1;
constexpr long long LLINF = 1LL << 61;
constexpr double EPS = 1e-10;

constexpr int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
constexpr int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};

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

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

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

    int sum = 0;
    rep(i, 3){
        int a;
        cin >> a;
        sum += a;
    }

    if(sum > 21){
        cout << "bust" << endl;
    }else{
        cout << "win" << endl;
    }

    cout << flush;

    return 0;
}

Measured memory_bytes: 256
# coding: utf-8
# Your code here!

N = int(input().rstrip())
A = list(map(int, input().rstrip().split()))

def gcd(x, y):
    if x == 0:
        return y
    if y == 0:
        return x
        
    if y > x:
        temp = y
        y = x
        x = temp
    amari = x % y
    if amari == 0:
        return y
    else:
        return gcd(y, amari)
        
L = list(range(N))
L[0] = 0
for i in range(N-1):
    L[i+1] = gcd(L[i], A[i])
    
R = list(range(N))
R.append(0)
for i in reversed(range(N)):
    R[i] = gcd(R[i+1], A[i])

M = [gcd(L[i], R[i+1]) for i in range(N)] # i=1,...,N

print(max(M))


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

using ll = int64_t;
#define int ll

#define FOR(i, a, b) for (int i = int(a); i < int(b); i++)
#define REP(i, b) FOR(i, 0, b)
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(x) x.begin(), x.end()

using pi = pair<int, int>;
using vi = vector<int>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  REP(i, (int)v.size()) {
    if (i) os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

ll read() {
  ll i;
  scanf("%" SCNd64, &i);
  return i;
}

void printSpace() { printf(" "); }

void printEoln() { printf("\n"); }

void print(ll x, int suc = 1) {
  printf("%" PRId64, x);
  if (suc == 1) printEoln();
  if (suc == 2) printSpace();
}

string readString() {
  static char buf[3341000];
  scanf("%s", buf);
  return string(buf);
}

char *readCharArray() {
  static char buf[3341000];
  static int bufUsed = 0;
  char *ret = buf + bufUsed;
  scanf("%s", ret);
  bufUsed += strlen(ret) + 1;
  return ret;
}

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

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

template <class T>
T Sq(const T &t) {
  return t * t;
}

signed main() {
  string s;
  int k;
  cin >> s >> k;
  set<string> ss;
  for (int i = 0; i < s.length(); i++) {
    for (int j = 1; j <= 5; j++) {
      if (i + j > s.length()) continue;
      ss.insert(s.substr(i, j));
    }
  }
  set<string>::iterator it = ss.begin();
  advance(it, k - 1);
  cout << *it << endl;
}


Measured memory_bytes: 1664
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <stdio.h>
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <string>
#include <cstring>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <ctime>
#include <vector>
#include <fstream>
#include <list>
#include <iomanip>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define ms(s) memset(s, 0, sizeof(s))
const int inf = 0x3f3f3f3f;
const int MAXN = 1e5 + 10;
#define LOCAL



int main() 
{
	ios::sync_with_stdio(false);
	cout.tie(0), cin.tie(0);
	int t;
	cin >> t;
	if (t % 1000 == 0) cout << 0 << endl;
	else
	cout << (t / 1000 + 1) * 1000 - t << endl;
    return 0;
}

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

void in(int *, int);
void ext(int *);
void maximum(int *, int);

int n = 0;

main(){
  int i;
  int t[2000002];
  char a[10];
  
  while(1){
    scanf("%s", a);
    if(a[2] == 'd') break;
    else if(a[0] == 'i'){
      scanf("%d", &t[0]);
      in(t, t[0]);
    }
    else ext(t);
  }
  
  return 0; 
}
void maximum(int *t, int i){
  int l, r, large, c;
  
  if( i*2+1 < n + 1) r = i*2+1;
  else r = i;
  if( i*2 < n + 1) l = i*2;
  else l = i;
  
  if(l <= n && t[l] > t[i]) large = l;
  else large = i;
  
  if(r <= n && t[r] > t[large])large = r;
  
  if(large != i){
    c = t[i];
    t[i] = t[large];
    t[large] = c;
    maximum(t, large);
  }
}
void in(int *t, int a){
  int i,c;
  
  n++;
  i = n;
  t[n] = a;
  
  while(i > 1 && t[i/2] < t[i]){
    c = t[i];
    t[i] = t[i/2];
    t[i/2] = c;
    i /= 2;
  }
}
void ext(int *t){
  
  printf("%d\n", t[1]);
  
  if(n > 1)t[1] = t[n];
  
  n--;
  
  if(n > 1) maximum(t, 1);
}




Measured memory_bytes: 5660
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
int my_max(int a,int b)
{
    return a>b? a:b;
}
int main()
{
    int gyz=1;
    int n,m;
    scanf("%d %d",&n,&m);
    for(int i=1;i*i<=m;i++)
    {
        if(m%i==0)
        {
            if(m/i>=n)
                gyz=my_max(gyz,i);
            if(i>=n)
                gyz=my_max(gyz,m/i);
            
        }
    }
    printf("%d\n",gyz);
    return 0;
}


Measured memory_bytes: 128
def gcd(a, b):
    if b > a:
        _ = b
        b = a
        a = _
    while b:
        a, b = b, a % b
    return a

A,B,C,D = map(int, input().split())

GcdCD = gcd(C,D)
LcmCD = (C*D)//GcdCD

s1 = B- ((B//C)+(B//D)-(B//LcmCD))
s2 = (A-1)-(((A-1)//C)+((A-1)//D)-((A-1)//LcmCD))
if s2 < 0:
    s2 = 0
print(s1-s2)

Measured memory_bytes: 3064
#include <stdio.h>

int main(void) {
    int a, b, total = 0;
    scanf("%d%d", &a, &b);
    for(int i = 0; i < 2; i++) {
        if(a >= b) {
            total += a;
            a--;
        } else {
            total += b;
            b--;
        }
    }
    printf("%d\n", total);
    return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdlib>
using namespace std;

int main(){
    int x, n;
    cin >> x >> n;
    if(n==0){
        cout << x << endl;
        return 0;
    }

    vector<int> v(n);
    for (int i=0; i<n; i++){
        cin >> v.at(i);
    }
    sort(v.begin(), v.end());
    int diff = 0, ans = x, temp = 200;
    bool flg = 0;
    for (int i=v.at(0)-5; i<v.at(n-1)+5; i++){
        for (int j=0; j<n; j++){
            if(v.at(j)==i){
                flg = 1;
                //cout << "skip" << endl;
                continue;
            }
        }
        if(flg==1){
            flg = 0;
            continue;
        }
        diff = abs(x-i);
        //cout <<  "i:" << i << endl;
        if(diff < temp){
            temp = diff;
            ans = i;
        }
    }
   

    cout << ans << endl;
    return 0;

}

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

using namespace std;



int main(){
    long double n,k;
    cin>>n>>k;
    if(n>=k){
        //1
        long double a = (n-k+1)/n;
        //2
        long double sum = 0;
        for(long long i=1;i<k;i++){
            long double d = 1;
            while(i*d<k){
                d = d*2;
            }
            sum += 1/d;
        }
        sum = sum/n;
        sum += a;

        cout<<fixed<<setprecision(10)<<sum<<endl;
    }else{
        long double sum = 0;
        for(long long i=1;i<=n;i++){
            long double d = 1;
            while(i*d<k){
                d = d*2;
            }
            sum += 1/d;
        }
        sum = sum/n;

        cout<<fixed<<setprecision(10)<<sum<<endl;
    }



}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define For(i,a,b) for(int i=a;i<=b;i++)
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define sz(x) ((int)x.size())
#define int ll
using namespace std;
using ll=long long;
using pii=pair<int,int>;

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

bool check(int n)
{
	string s;
	for(;n;n/=10) s=char(n%10+'0')+s;
	For(i,0,sz(s)/2) if(s[i]!=s[sz(s)-i-1]) return false;
	return true;
}

int32_t main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int a,b; cin>>a>>b;
	int cnt=0;
	For(i,a,b) if(check(i)) cnt++;
	cout<<cnt<<"\n";
	return 0;
}















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

int main(){
    int W, H, x, y, r;
    cin >> W >> H >> x >> y >> r;
    if (x >= r and x <= W - r and y >= r and y <= H - r){
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 3100
#include<bits/stdc++.h>
#define int long long
using namespace std;
constexpr int mod=1e9+7;
signed main(){
    int n,k,a[200000];
    cin>>n>>k;
    for(int i=0;i<n;i++)
        cin>>a[i];
    sort(a,a+n);
    int ub=mod*mod,lb=-(mod*mod);
    while(ub-lb>1){
        int mid=(ub+lb)/2,cnt=0;
        for(int i=0;i<n;i++){
            if(a[i]>0)
                cnt+=upper_bound(a,a+n,(long double)mid/a[i])-a;
            else if(a[i]<0)
                cnt+=n-(lower_bound(a,a+n,(long double)mid/a[i])-a);
            else if(mid>=0)
                    cnt+=n;
            if(a[i]*a[i]<=mid)
                cnt--;
        }
        (cnt>=2*k?ub:lb)=mid;
    }
    cout<<ub<<endl;
}

Measured memory_bytes: 1792
<?php
list($x, $y, $z) = ints();
echo "$z $x $y";


function str(){return trim(fgets(STDIN));}
function ints(){return array_map('intval',explode(' ',trim(fgets(STDIN))));}
function int(){return intval(trim(fgets(STDIN)));}
function chmax(&$a,$b){if($a<$b){$a=$b;return 1;}return 0;}
function chmin(&$a,$b){if($a>$b){$a=$b;return 1;}return 0;}
function popcount($x){$c=0;while($x){$x&=$x-1;++$c;}return$c;}
function o(...$val){
    if(count($val)==1)$val=array_shift($val);
    echo debug_backtrace()[0]['line'].")";
    if(is_array($val)){
        if(count($val) == 0)echo "empty array";
        elseif(!is_array(current($val)))echo "array: ",implode(" ", addIndex($val)),"\n";
        else{
            echo "array:array\n";
            if(isCleanArray($val))foreach($val as $row)echo implode(" ", addIndex($row)),"\n";
            else foreach($val as $i => $row)echo "[".$i."] ".implode(" ", addIndex($row)),"\n";
        }
    }else echo $val."\n";
}
function addIndex($val){if(!isCleanArray($val)){$val = array_map(function($k, $v){return $k.":".$v;}, array_keys($val), $val);}return $val;}
function isCleanArray($array){$clean=true;$i = 0;foreach($array as $k=>$v){if($k != $i++)$clean = false;}return $clean;}
// 座圧対象の配列 -> [圧縮された配列,復元用のMap,圧縮用のMap]
function atsu($array){$a = array_flip($array);$fuku=array_flip($a);sort($fuku);$atsu = array_flip($fuku);foreach($array as $i=>$val)$array[$i]=$atsu[$val];return [$array, $fuku, $atsu];}
function gcdAll($array){$gcd=$array[0];for($i=1,$I=count($array);$i<$I;++$i){$gcd=gcd($gcd,$array[$i]);}return $gcd;}
function gcd($m, $n){if(!$n)return $m;return gcd($n, $m % $n);}
function lcmAll($array){$lcm=$array[0];for($i=1,$I=count($array);$i<$I;++$i){$lcm=lcm($lcm,$array[$i]);}return $lcm;}
function lcm($a, $b) {return $a / gcd($a, $b) * $b;}

function dfs($current, $from = -1, $d = 0){
  global $G, $distance;
  $distance[$current] = $d;
  foreach($G[$current] as $to){
    if($from != $to){
      dfs($to, $current, $d + 1);
    }
  }
}

function loadTree($N = false){
  if($N === false)$N = $GLOBALS['N'];
  return loadGraph($N, $N-1);
}
function loadGraph($N = false, $M = false, $both = true){
  if($N === false)$N = $GLOBALS['N'];
  if($M === false)$N = $GLOBALS['M'];
  $G = array_fill(1, $N, []);
  for($i = 0; $i < $M; $i++){
    $values = ints();
    if(count($values) == 2){
      list($a, $b) = $values;
      $G[$a][] = $b;
      if($both)$G[$b][] = $a;
    }else{
      list($a, $b, $d) = $values;
      $G[$a][] = [$b, $d];
      if($both)$G[$b][] = [$a, $d];
    }
  }
  return $G;
}


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

using namespace std;

const int MaxN = 2e5 + 25;
const int MOD = 1e9 + 7;


int main()
{
//    freopen("input.txt", "r", stdin);

    ios_base :: sync_with_stdio(false);
    cin.tie(NULL);

    long long n, m;

    cin >> n >> m;
    if(n > m)
        swap(n, m);

    if(n == 1)
    {
        if(m == 1)
            cout << 1 << '\n';
        else
            cout << max(0ll, m - 2) << '\n';
        return 0;
    }

    cout << n * m - (n + n + m + m - 4) << '\n';

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long long LL;
const int maxn=1e6+10;
char s[maxn];
int main()
{
	int n,q;
	scanf("%d %s %d",&n,s+1,&q);
	while(q--){
		int k;
		scanf("%d",&k);
		ll ans=0,now=0;
		int cntd=0,cntm=0;
		for(int i=1;i<=n;i++){
			if(i>k){
				if(s[i-k]=='D'){
					cntd--;
					now-=cntm;
				}
				if(s[i-k]=='M'){
					cntm--;
				}
			}
			if(s[i]=='D'){
				cntd++;
			}
			if(s[i]=='M'){
				cntm++;
				now+=cntd;
			}
			if(s[i]=='C'){
				ans+=now;
			}
		}
		printf("%lld\n",ans);
	}
}

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

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    long long n;
    cin >> n;
    map<long long, int> f;
    for (long long i = 2; i * i <= n; i++) {
        while (n % i == 0) {
            f[i]++;
            n /= i;
        }
    }
    if (n != 1) {
        f[n]++;
    }
    vector<long long> sum(101);
    for (int i = 1; i <= 100; i++) {
        sum[i] += sum[i - 1] + i;
    }
    long long ans = 0;
    for (auto &ff : f) {
        ans += upper_bound(sum.begin(), sum.end(), ff.second) - sum.begin() - 1;
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
int K,N,a[200000],dist=0,tmp=0,tmp_maxi,maxi=0;
int main(){
    cin >> K >> N;
    for (int i=0;i<N;i++)cin >> a[i];

    for(int i=0;i<N+1;i++) {
    if(i==0) tmp = a[0];
    if(i==N){ tmp_maxi = K - tmp + a[0];}
    else{
        tmp_maxi = a[i] - tmp;
    }  
    if(tmp_maxi >= maxi) {
        maxi = tmp_maxi;
        }
    if(i<N) tmp = a[i];
    };
    cout << K - maxi << endl;
}

Measured memory_bytes: 1024
#include<iostream>
#include<vector>
using namespace std;
int main()
{
	long long int a,b,c,d;
	cin>>a>>b>>c>>d;
	if(b>0 && d>0)
	{
		if(b*d>=a*c)
		cout<<b*d;
		else
		cout<<a*c;
	}
	else if(b<0 && d<0)
	cout<<a*c;
	else if(b==0 && d==0)
	cout<<a*c;
	else if(b>0 && d<0)
	{
		if(a>0)
		cout<<a*d;
		else
		cout<<a*c;
	}
	else if(b<0 && d>0)
	{
		if(c>0)
		cout<<c*b;
		else
		cout<<a*c;
	}
	else if(b==0)
	{
		if(c<0)
		cout<<a*c;
		else
		cout<<0;
	}
	else 
	{
		if(a<0)
		cout<<a*c;
		else
		cout<<0;
	}
}

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

int main() {
    int n, m; cin >> n >> m;
    int a[1010];
    int total = 0;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        total += a[i];
    }
    int count = n;
    for (int i = 0; i < n; i++) {
        if (total % (4*m) == 0 && a[i] < total / (4*m)) {
            count--;
        } else if (total % (4*m) != 0 && a[i] <= total / (4*m)) {
            count--;
        }
    }
    if (count >= m) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
M,D=map(int,input().split())
ans=0
for m in range(1,M+1):
    for d in range(1,D+1):
        d10,d1=[int(c) for c in str(d).zfill(2)]
        if d1>=2 and d10>=2 and d1*d10==m:
            ans += 1
print(ans)


Measured memory_bytes: 41072
/*
Md. Shahnewaz Siddique Labib
Dept. of CSE
IUT'19
*/
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define vi vector<int>
#define vpii vector<pair<int, int>>
#define pb push_back
#define mp make_pair
#define fastio ios_base::sync_with_stdio(NULL); cin.tie(NULL); cout.tie(NULL);

using namespace std;



int main(){
    //vector<pair<int, pair<int, int>>> num;
    fastio;
    int arr[3][3], check[3][3], n, x, i;
    for(int i = 0; i < 3; i++){
        cin >> arr[i][0] >> arr[i][1] >> arr[i][2];
        check[i][0] = 0;
        check[i][1] = 0;
        check[i][2] = 0;
    }
    cin >> n;

    for(int i = 0; i < n; i++){
        cin >> x;
        for(int j = 0; j < 3; j++){
            for(int k = 0; k < 3; k++){
                if(arr[j][k] == x) check[j][k] = 1;
                //goto hell;
            }
        }
    }
    int flag1 = 0, flag2 = 0, flag3 = 0, flag4 = 0, flag5 = 0, flag6 = 0;

    for(int i = 0; i < 3; i++){
        if(check[0][i]) flag1++;
        if(check[1][i]) flag2++;
        if(check[2][i]) flag3++;
        if(check[i][0]) flag4++;
        if(check[i][1]) flag5++;
        if(check[i][2]) flag6++;

    }
    if(flag1 == 3 || flag2 == 3 || flag3 == 3 || flag4 == 3 || flag5 == 3 || flag6 == 3){
        cout << "Yes";
        return 0;
    }

    if((check[0][0] && check[1][1] && check[2][2]) || (check[2][0] && check[1][1] && check[0][2])){
        cout << "Yes";
        return 0;
    }

    cout << "No";




    
    

}

Measured memory_bytes: 256
n,k = map(int,input().split())
arr = list(map(int,input().split()))

dp = [False]*(k+1)

for stones in range(k+1):
    for x in arr:
        if stones >= x and dp[stones-x] == False:
            dp[stones] = True

if dp[k]:
    print("First")
else:
    print("Second")


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

using namespace std;

long long n, a, ans;
long long sum;
map<long long, int>mp;

int main()
{
  cin >> n;
  mp[0]++;
  for (int i = 1; i <= n; i++) {
    cin >> a;
    sum += a;
    ans += mp[sum];
    mp[sum]++;
  }
  cout << ans;
  return 0;
}


Measured memory_bytes: 12800
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        ArrayList<ArrayList<Integer>> graph = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            graph.add(new ArrayList<>());
        }
        for (int i = 0; i < m; i++) {
            graph.get(sc.nextInt() - 1).add(sc.nextInt() - 1);
        }
        int start = sc.nextInt() - 1;
        int end = sc.nextInt() - 1;
        PriorityQueue<Path> queue = new PriorityQueue<>();
        queue.add(new Path(start, 0, 0));
        int[][] points = new int[3][n];
        for (int i = 0; i < 3; i++) {
            Arrays.fill(points[i], Integer.MAX_VALUE);
        }
        while (queue.size() > 0) {
            Path p = queue.poll();
            if (points[p.count][p.idx] <= p.value) {
                continue;
            }
            points[p.count][p.idx] = p.value;
            for (int x : graph.get(p.idx)) {
                queue.add(new Path(x, p.value + 1, (p.count + 1) % 3));
            }
        }
        if (points[0][end] == Integer.MAX_VALUE) {
            System.out.println(-1);
        } else {
            System.out.println(points[0][end] / 3);
        }
    }
    
    static class Path implements Comparable<Path> {
        int idx;
        int value;
        int count;
        
        public Path(int idx, int value, int count) {
            this.idx = idx;
            this.value = value;
            this.count = count;
        }
        
        public int compareTo(Path another) {
            return value - another.value;
        }
    }
   
   
}

Measured memory_bytes: 101516
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define SIZE 100005

int N;
map<int,int> MAP;


int main(){

	scanf("%d",&N);

	int ans = 0;

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

		scanf("%d",&tmp);


		auto at = MAP.lower_bound(tmp); //自分以上の数

		if(at == MAP.begin()){ //自分より小さい数なし

			ans++;
			MAP[tmp]++;;

		}else{ //自分より小さい数あり

			at--;
			int work = at->first;
			MAP[work]--;
			if(MAP[work] == 0){

				MAP.erase(work);
			}
			MAP[tmp]++;
		}
	}

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

	return 0;
}


Measured memory_bytes: 4864
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cerr << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cerr<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 500010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = 1 << 30;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
mt19937 rng; //use it by rng() % mod, shuffle(all(vec), rng)
///////////////////////////////////////////////////////////////////////////////////////////////////

int N;
ll A[MAX_N];
int at = 0;

vector<int> G[MAX_N];
ll ans[MAX_N];

void loop(int v, int p) {
	rep(i, 0, sz(G[v])) {
		int n = G[v][i];
		if(n == p) continue;
		loop(n, v);
	}
	ans[v] = A[at++];
}

void solve() {
	cin >> N;
	rep(i, 0, N - 1) {
		int a, b; cin >> a >> b; a--; b--;
		G[a].pb(b);
		G[b].pb(a);
	}
	rep(i, 0, N) cin >> A[i];
	sort(A, A + N);
	loop(0, -1);
	cout << accumulate(A, A + N - 1, 0ll) << "\n";
	rep(i, 0, N) cout << ans[i] << " ";
	cout << "\n";
}

uint32_t rd() {
	uint32_t res;
#ifdef __MINGW32__
	asm volatile("rdrand %0" :"=a"(res) ::"cc");
#else
	res = std::random_device()();
#endif
	return res;
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
    cerr << fixed;
	cerr.precision(6);
	rng.seed(rd());
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
    freopen("in.txt", "rt", stdin);
#endif	
	solve();
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	return 0;
}



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

// エイリアス
using  ll = long signed long;
using ull = long unsigned long;
using  ld = long double;
using   P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;

// 汎用マクロ
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define FOREACH(i,q) for (auto &i : q)
#define UNIQUE(v) do { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); } while (false)
#define SZ(x) ((int)(x).size())
template <class T>inline bool chmin(T &a, const T b) {if (a > b) { a = b; return true;} return false;}
template <class T>inline bool chmax(T &a, const T b) {if (a < b) { a = b; return true;} return false;}
template <class T>inline void line_out(const vector<T> vec) {int n = SZ(vec); rep(i, n) { cout << vec[i]; if(i < n-1) cout << " ";}cout << endl;}
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 28;
const ll INF64 = 1ll << 60;
const int mod = 1000000007;
//const int mod = 998244353;
struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};


int main()
{
  int n; cin >> n;
  vector<llP> meal(n);
  rep(i, n) cin >> meal[i].first >> meal[i].second;
  auto comp = [&](llP x, llP y) {
    return x.first+x.second > y.first+y.second;
  };

  sort(ALL(meal), comp);

  ll ans = 0;
  rep(i, n) ans -= meal[i].second;
  rep(i, n) if(i%2==0) ans += meal[i].first+meal[i].second;
  cout << ans << endl;
}


Measured memory_bytes: 4840
import itertools

n, k = map(int, input().split(' '))

if k > (n - 1) * (n - 2) // 2:
    print('-1')
else:
    v = list(range(2, n+1))

    pairs = list(itertools.combinations(v, 2))

    print(((n-1) * (n-2) // 2) - k + (n - 1))

    for i in range(2, n + 1):
        print('1 ' + str(i))
    
    for i in range(((n-1) * (n-2) // 2) - k):
        print(str(pairs[i][0]) + ' ' + str(pairs[i][1]))

Measured memory_bytes: 3716
#include<iostream>

using namespace std;


main(){
  
  int a[4],b[4];
  int blow, hit;

  while(cin >> a[0]>> a[1]>> a[2]>>a[3]){
    blow = 0;hit=0;
    cin >> b[0]>>b[1]>>b[2]>>b[3];

    for(int i=0;i<4;i++){
      for(int j=0;j<4;j++){
	if(a[i]==b[j]&&i==j)hit++;
	if(a[i]== b[j]&& i!=j)blow++;
      }
    }

    cout << hit <<" "<< blow<< endl;//
  }


  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
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;
}

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;
ll total;

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, t, s;
    cin >> N >> s >> t;
    cout << "? " << t << " " << s << endl;
    cin >> total;
    vector<l_l> v;
    v.push_back({total, t});
    v.push_back({0, s});
    for(int i = 1; i <= N; i++) {
        if(i == t || i == s) continue;
        cout << "? " << t << " " << i << endl;
        ll tdist, sdist;
        cin >> tdist;
        cout << "? " << s << " " << i << endl;
        cin >> sdist;
        if(sdist + tdist != total) continue;
        v.emplace_back(sdist, i);
    }
    sort(v.begin(), v.end());
    ll now = s;
    ll nowdist = 0;
    vector<int> ans;
    ans.push_back(s);
    for(int i = 1; i < v.size(); i++) {
        cout << "? " << now << " " << v[i].second << endl;
        ll sub;
        cin >> sub;
        if(sub + nowdist == v[i].first) {
            ans.push_back(v[i].second);
            now = v[i].second;
            nowdist = v[i].first;
        }
    }
    cout << "!";
    for(int i = 0; i < ans.size(); i++) cout << " " << ans[i];
    cout << endl;
    return 0;
}



Measured memory_bytes: 4652
package main

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

var sc, wr = bufio.NewScanner(os.Stdin), bufio.NewWriter(os.Stdout)

func scanString() string   { sc.Scan(); return sc.Text() }
func scanRunes() []rune    { return []rune(scanString()) }
func scanInt() int         { a, _ := strconv.Atoi(scanString()); return a }
func scanInt64() int64     { a, _ := strconv.ParseInt(scanString(), 10, 64); return a }
func scanFloat64() float64 { a, _ := strconv.ParseFloat(scanString(), 64); return a }

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = scanInt()
	}
	return res
}

func debug(a ...interface{}) { fmt.Fprintln(os.Stderr, a...) }

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

//•*¨*•.¸¸♪main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)
func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1001001)

	s := scanRunes()
	k := scanInt()
	a, b := 0, 0
	s = append(s, s...)
	for i := 0; i < len(s)-1; i++ {
		if s[i] == s[i+1] {
			s[i+1] = '@'
			if i+1 < len(s)/2 {
				a++
			} else {
				b++
			}
		}
	}
	if s[0] == s[len(s)-1] {
		fmt.Fprintln(wr, a+b*(k-1))
	} else {
		fmt.Fprintln(wr, (k+1)/2*a+k/2*b)
	}
}


Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)for(int i=0;i<(n);i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
using ll = long long;

const int INF = 1001001001;

int main(){
    int n, x, y; 
    cin >> n >> x >> y;
    --x, --y;
    vector<int> ans(n);
    rep(sv, n){
        vector<int> dist(n, INF);
        queue<int> q;
        auto push = [&](int v, int d){
            if(dist[v] != INF) return;
            dist[v] = d;
            q.push(v);
        };
        push(sv, 0);
        while(!q.empty()){
            int v= q.front(); q.pop();
            int d = dist[v];
            if(v-1 >= 0) push(v-1, d+1);
            if(v+1 < n) push(v+1, d+1);
            if(v == x) push(y, d+1);
            if(v == y) push(x, d+1);
        }
        rep(i,n) ans[dist[i]]++;
    }
    rep(i,n) ans[i] /= 2;
    for(int i = 1; i <= n-1; ++i){
        cout << ans[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

//struct edge {int from, to, cost;};

constexpr double EPS = 1e-10;
//constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;
constexpr int MOD = 1'000'000'007;
//inline void modAdd(LL &l, LL &r) {l = (l + r) % MOD;}

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

void solve() {
    int n,x;
    cin >> n >> x;
    VI l(n);
    REP(i,0,n) cin >> l[i];
    int pos = 0;
    int cnt = 0;
    while (pos <= x && cnt < n) {
        pos += l[cnt];
        ++cnt;
    }
    if (pos > x) --cnt;
    cout << cnt + 1 << endl;
}

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

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

int main(){
  int N,M,X; cin>>N>>M>>X;
  int lcnt=0,mcnt=0;
  for(int i=0;i<M;i++){
    int A; cin>>A;
    if(A<X){
      lcnt++;
    }else{
      mcnt++;
    }
  }
  cout<<min(lcnt,mcnt)<<endl;
}

Measured memory_bytes: 256
import sys
import numpy as np

N = int(sys.stdin.readline().strip())
a = list(map(lambda x: int(x), sys.stdin.readline().strip().split(" ")))

index = np.argmax(a)
n = a.pop(index)

m = -1
tmp = n

for e in a:
    if abs((n/2) - e) < tmp:
        tmp = abs((n/2) - e)
        m = e
        
print(str(n) + " " + str(int(m)))


Measured memory_bytes: 23132