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

inline int read(){
    int s=0,w=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){
        if(ch=='-')w=-1;ch=getchar();
    }
    while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
    return s*w;
}

inline bool read(int& a){
    int s=0,w=1;
    char ch=getchar();
    if(ch==EOF){
		return false;
	}
    while(ch<'0'||ch>'9'){
        if(ch=='-')w=-1;ch=getchar();
    }
    while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
    a=s*w;
    return true;
}

inline void write(int x){
    if(x<0) putchar('-'),x=-x;
    if(x>9) write(x/10);
    putchar(x%10+'0');
}

inline void writeln(int x){
    if(x<0) putchar('-'),x=-x;
    if(x>9) write(x/10);
    putchar(x%10+'0');
    puts("");
}

int a[10];

signed main(){
	int ans=-1e18;
	
	for(int i=1;i<=4;i++)
		a[i]=read();
		
	for(int i=1;i<=2;i++)
		for(int j=3;j<=4;j++)
			ans=max(ans,a[i]*a[j]);
		
	writeln(ans);
	return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for(int i = 0; i < n; i++){
    a[i] = i+1;
  }
  vector<int> p(n),q(n);
  for(int i = 0; i < n; i++) cin >> p[i];
  for(int i = 0; i < n; i++) cin >> q[i];

  map<vector<int>, int> mp;
  do{
      mp[a] = mp.size();
  }while(next_permutation(a.begin(), a.end()));
  int ans = abs(mp[p]-mp[q]);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 5248
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <tuple>
#include <random>
using namespace std;

#define endl '\n'
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef complex<double> comp;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};
const int inf = 1e9 + 9;
const ll mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);

string s;

void solve() {
    const int n = (int)s.size();
    if (s[n-1] == '1' || s[0] == '0' || s[n-2] == '0') {
        cout << -1 << endl;
        return;
    }

    for (int i = 0; i < n-1; i++) {
        if (s[i] != s[n-i-2]) {
            cout << -1 << endl;
            return;
        }
    }

    vector<P> res;
    int r = 0, p = 0;
    for (int i = 1; i < n/2; i++) {
        if (s[i] == '1') {
            int d = i+1-r;
            int np = p+d-1;
            res.push_back(make_pair(np, p));
            for (int j = p+1; j < np; j++) {
                res.push_back(make_pair(np, j));
            }
            p = np;
            r = i;
        }
    }

    if (p < n-1) {
        res.push_back(make_pair(p, p+1));
        p++;
        for (int i = p+1; i < n; i++) {
            res.push_back(make_pair(p, i));
        }
    }
    for (P p : res) {
        cout << p.first+1 << " " << p.second+1 << endl;
    }
}

void input() {
    cin >> s;
}

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

    input();
    solve();
}


Measured memory_bytes: 4424
w = int(input())
s = [i for i in range(w+1)]
n = int(input())
for i in range(n):
    a = list(map(int,input().split(",")))
    s[a[0]], s[a[1]] = s[a[1]], s[a[0]]
for i in range(1, w+1):
    print(s[i])


Measured memory_bytes: 5596
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define MAX_N 50

int main() {
	int n, r;
	int card[MAX_N];
	int buffer[MAX_N];
	int i, j;

	while(scanf("%d %d", &n, &r) == 2 && n) {
		for(i = 0; i < n; ++i) {
			card[i] = n - i;
		}

		for(i = 0; i < r; ++i) {
			int p, c;
			scanf("%d %d", &p, &c);
			--p;

			for(j = 0; j < c; ++j) {
				buffer[j] = card[p + j];
			}

			for(j = 0; j < p; ++j) {
				buffer[j + c] = card[j];
			}

			for(j = p + c; j < n; ++j) {
				buffer[j] = card[j];
			}

			memcpy(card, buffer, sizeof(card));
		}

		printf("%d\n", card[0]);
	}

	return EXIT_SUCCESS;
}

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

using namespace std;

int main() {
	int n, d, x;
	cin >> n >> d >> x;
	int e, sum = x;
	for (int i = 0; i < n; i++) {
		cin >> e;
		sum += (((d - 1) / e) + 1);
	}
	cout << sum << "\n";
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<cstring>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<fstream>

#define MOD (1000000007)

using namespace std;

typedef long long int Int;

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

    string str;
    cin>>str;
    str = "#"+str+"#";
    bool flg = true;
    bool cross = false;
    int cont = 0;
    //b->d
    for(int i = b;i <= d;i++) {
        if(str[i] == '.') {
            if(str[i-1] == '.' && str[i] == '.' && str[i+1] == '.')
                cross = true;
        } else if(str[i] == '#' && str[i-1] == '#') {
            flg = false;
            break;
        } else {
            cont = 0;
        }
    }

    //a->c
    bool c_o = true;
    for(int i = a;i <= c;i++) {
        if(str[i] == '#' && str[i-1] == '#') {
            c_o = false;
            break;
        }
    }

    if(c < d) {
        if(c_o && flg) {
            cout<<"Yes"<<endl;
        } else {
            cout<<"No"<<endl;
        }
    } else {
        if(c_o && flg && cross) {
            cout<<"Yes"<<endl;
        } else {
            cout<<"No"<<endl;
        }
    }


    return 0;
}




Measured memory_bytes: 772
//----------------------------templates
    #pragma GCC optimize ("Ofast")
    #pragma GCC target ("tune=native")
    #pragma GCC target ("avx")
    //----------------------------
    #include <bits/stdc++.h>
    using namespace std;

    typedef long long ll;
    typedef unsigned long long ull;
    #define int ll

    #define FOR(i,j,n) for (int i=(int)(j);i<(n);i++)
    #define REP(i,n) for (int i=0;i<(int)(n);i++)
    #define REPS(i,n) for (int i=1;i<=(int)(n);i++)
    #define REPN(i,n) for (int i=(int)(n)-1;i>=0;i--)
    #define REPNS(i,n) for (int i=(int)(n);i>0;i--)

    #define I(n) scanf("%lld", &(n))
    #define LL(n) scanf("%lld", &(n))
    #define pb(n) push_back((n))
    #define mp(i,j) make_pair((i),(j))
    #define eb(i,j) emplace_back((i),(j))
    #define y0 y3487465
    #define y1 y8687969
    #define j0 j1347829
    #define j1 j234892
    #define uniq(v) v.erase( unique(v.begin(), v.end()), v.end() )

    #define all(x) (x).begin(),(x).end()
    #define sz(x) ((int)(x).size())

    typedef vector<int> vi;
    typedef pair<int,int> pi;
    typedef vector<pi> vpi;
    typedef vector<vi> vvi;
    typedef vector<vpi> vvpi;
    typedef vector<vvi> vvvi;

    const int mod = 1000000007;

//--------------------------------------------

int n,ret;
vi a,b,c;

priority_queue<int,vi,greater<int>> insuf;
priority_queue<int> suf;
signed main(){
    I(n);
    a.resize(n);
    REP(i,n) I(a[i]);
    b.resize(n);
    REP(i,n) I(b[i]);
    c.resize(n);
    REP(i,n) {
        c[i] = a[i] - b[i];
        // cerr << c[i] << " ";
        if (c[i] < 0){
            insuf.push(c[i]);
        } else {
            suf.push(c[i]);
        }
    }
    int sc = accumulate(all(c), 0LL);
    //cerr << sc << endl;
    if (sc < 0LL){
        cout << -1 << endl;
        return 0;
    }
    int buff = 0;

    while(!insuf.empty()){
        int isf = insuf.top();
        insuf.pop();
        ret++;

        while(isf < 0){
            isf += buff;
            if (isf < 0){
                buff = suf.top();
                suf.pop();
                ret++;
            }
        }
        buff = isf;

    }

    cout << ret << endl;

}

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

const int maxn = 300010, P = 998244353;
int n, r, g, b, rg, gb, rb, ans = 1;
char s[maxn];

int main() {
    scanf("%d %s", &n, s + 1);
    for (int i = 1; i <= 3 * n; i++) {
        if (s[i] == 'R') {
            if (gb) {
                ans = 1LL * ans * gb % P, gb--;
            } else {
                if (g || b) {
                    ans = 1LL * ans * (g + b) % P;
                    if (g) rg++, g--;
                    if (b) rb++, b--;
                }
                else r++;
            }
        } else if (s[i] == 'G') {
            if (rb) {
                ans = 1LL * ans * rb % P, rb--;
            } else {
                if (r || b) {
                    ans = 1LL * ans * (r + b) % P;
                    if (r) rg++, r--;
                    if (b) gb++, b--;
                }
                else g++;
            }
        } else {
            if (rg) {
                ans = 1LL * ans * rg % P, rg--;
            } else {
                if (r || g) {
                    ans = 1LL * ans * (r + g) % P;
                    if (r) rb++, r--;
                    if (g) gb++, g--;
                }
                else b++;
            }
        }
    }
    for (int i = 1; i <= n; i++) {
        ans = 1LL * ans * i % P;
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 512
#include <stdio.h>

void InputString(char* string);
void Converting(char* string);
void Printing(char* string);

int main(void) {
	char string[1200];

	InputString(string);
	Converting(string);
	Printing(string);
}

void InputString(char* string) {
	scanf("%[^\n]s", string);
}

void Converting(char* string) {
	int sub = 'a' - 'A';

	char* tmp = string;
	while (*tmp) {
		if (*tmp >= 'a' && *tmp <= 'z') {
			*tmp -= sub;
		} else
		if (*tmp >= 'A' && *tmp <= 'Z') {
			*tmp += sub;
		}
		tmp++;
	}
}

void Printing(char* string) {
	printf("%s\n", string);
}


Measured memory_bytes: 2108
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

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

    int a = 0;
    rep(i,n){
        int x,w;
        cin >>x >>w;
        a += x*w;
    }

    if(a == 0) printf("0\n");
    else{
        printf("1\n");
        printf("%d %d\n", -a/abs(a), abs(a));
    }
    return 0;
}



Measured memory_bytes: 3232
#include <bits/stdc++.h>
#define SZ(v) ((int)((v).size()))
using namespace std;
using ll = long long;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int x=0, y=0;
	string s; cin >> s;
	for (char c : s) {
		if (c == 'N') x |= 1;
		if (c == 'S') x |= 2;
		if (c == 'W') y |= 1;
		if (c == 'E') y |= 2;
	}
	if ((x==0 || x == 3) && (y==0 || y==3)) {
		cout << "Yes\n";
	} else {
		cout << "No\n";
	}
}


Measured memory_bytes: 3652
from collections import defaultdict
def II(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
N=II()
A=LI()
SA=sum(A)
Q=II()
queries=[]
for i in range(Q):
  b,c=MI()
  queries.append((b,c))
cnt=defaultdict(int)
for a in A:
  cnt[a]+=1
for b,c in queries:
  if b in cnt:
    SA-=cnt[b]*b
    SA+=cnt[b]*c
    cnt[c]+=cnt[b]
    cnt[b]=0
  print(SA)
  

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

typedef long long ll;

void dfs(vector<vector<int>> &adj, int s, vector<bool> &visited){
    visited[s] = 1;
    
    for(int i : adj[s]){
        if(!visited[i])
            dfs(adj, i, visited);
    }
}


int main()
{
    int n, m;
    cin >> n >> m;
    vector<vector<int>> adj(n+1);
    
    for(int i = 0; i < m; i++){
        int p, q;
        cin >> p >> q;
        adj[p].push_back(q);
        adj[q].push_back(p);
    }
    
    vector<bool> visited(n+1);
    int ans = 0;
    
    for(int i = 1; i <= n; i++){
        if(visited[i] == 0){
            dfs(adj, i, visited);
            ans++;
        }
    }
    
    cout << ans-1 << "\n";
    
}


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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0;i < n;i++){
    cin >> a[i];
  }
  int ans = 0;
  
  for (int i = 0;i < n;i++){
    if (i % 2 == 0 && a[i] % 2 == 1){
      ans++;
    }
  }
  cout << ans << endl;
}



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

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    string s;
    cin >> s;
    
    int y = (s[0]-'0') * 1000 + (s[1]-'0') * 100 + (s[2]-'0') * 10 + (s[3]-'0');
    int m = (s[5]-'0') * 10 + s[6]-'0';
    // int d = (s[8]-'0') * 10 + s[9]-'0';
    
    string ans;
    if(y < 2019){
        ans = "Heisei";
    }else if(y > 2019){
        ans = "TBD";
    }else{
        if(m <= 4){
            ans = "Heisei";
        }else{
            ans = "TBD";
        }
    }
    
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var n, l int
	fmt.Scan(&n, &l)
	var s int
	for i := 1; i <= n; i++ {
		s += i
	}
	s += l*n - n
	if l >= 0 {
		fmt.Println(s - l)
	} else if l+n-1 <= 0 {
		fmt.Println(s - (l + n - 1))
	} else {
		fmt.Println(s)
	}
}


Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
	int n;
  	vector<int> nums;
  
  	cin >> n;
  	int temp;
  	for(int i=0; i<n; i++){
      cin >> temp;
      nums.push_back(temp);
    }
  
  	sort(nums.begin(),nums.end(),greater<int>());
  
  	int ali = 0;
  	int bob = 0;
  
  	for(int i=0; i<n; i++){
      if(i%2 == 0){
        ali += nums[i];
      }else{
        bob += nums[i];
      }
    }
  
  	cout << ali - bob;
  
}

Measured memory_bytes: 256
/*input
3
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
int main()
{
	ios_base::sync_with_stdio(false);
	ll S;
	cin >> S;
	ll x1 = (S - 1) / 1000000000 + 1;
	ll y1 = (x1 * 1000000000 - S);
	cout << "0 0 " << x1 << " " << y1 << " 1 1000000000" << "\n";
}

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


int main()
{
	//?????°????????????sum_table???0??§?????????
	int n, m, l;
	int A_table[MAX][MAX];
	int B_table[MAX][MAX];
	long sum_table[MAX][MAX];

	for (int i1 = 0; i1 < MAX; i1++)
	{
		for (int i2 = 0; i2 < MAX; i2++)
		{
			sum_table[i1][i2] = 0;
		}
	}

	//????´???°?????\???
	cin >> n >> m >> l;

	//A_table??¨B_table???????´??????\???
	for (int i1 = 0; i1 < n; i1++)
	{
		for (int i2 = 0; i2 < m; i2++)
		{
			cin >> A_table[i1][i2];
		}
	}

	for (int i1 = 0; i1 < m; i1++)
	{
		for (int i2 = 0; i2 < l; i2++)
		{
			cin >> B_table[i1][i2];
		}
	}

	//A_table??¨B_table??????????¨???????sum_table?????£??\
	for (int s1 = 0; s1 < n; s1++)
	{
		for (int s2 = 0; s2 < l; s2++)
		{
			for (int i = 0; i < m; i++)
			{
				sum_table[s1][s2] = sum_table[s1][s2] + (A_table[s1][i]*B_table[i][s2]);
			}
		}
	}

	//sum_table?????????
	for (int i1 = 0; i1 < n; i1++)
	{
		for (int i2 = 0; i2 < l; i2++)
		{
			if (i2 + 1 == l)
			{
				cout << sum_table[i1][i2] << '\n';
			}
			else
			{
				cout << sum_table[i1][i2] << ' ';
			}
		}
	}

	return 0;
}

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

struct PersistentUnionFind{
  using T = pair<int, int>;
  int n;
  vector<int> r,p;
  stack<T> st;
  PersistentUnionFind(){}
  PersistentUnionFind(int sz):n(sz),r(sz,1),p(sz,0){iota(p.begin(),p.end(),0);}
  int find(int x){
    return x==p[x]?p[x]:find(p[x]);
  }
  bool same(int x,int y){
    return find(x)==find(y);
  }
  void unite(int x,int y){
    x=find(x);y=find(y);
    st.emplace(-1,-1);
    if(x==y) return;
    if(r[x]<r[y]) swap(x,y);
    r[x]+=r[y];
    p[y]=x;
    st.top()=T(x,y);
  }
  void undo(int t=1){
    for(int i=0;i<t;i++){
      int x,y;
      tie(x,y)=st.top();st.pop();
      if(x<0) continue;
      r[x]-=r[y];
      p[y]=y;
    }
  }
};

struct DynamicConnectivity{
  using edge = pair<int, int>;
  using range = edge;
  
  int n,q;
  PersistentUnionFind puf;
  vector<vector<edge> > edges;
  vector<pair<range, edge> > prc;
  map<edge, int> cnt,app;
  
  DynamicConnectivity(){}
  DynamicConnectivity(int n,int q_):n(n),q(1),puf(n){
    while(q<q_) q<<=1;
    edges.resize(q*2-1);
  }
  
  void insert(int t,int u,int v){
    edge e=minmax(u,v);
    if(cnt[e]++==0) app[e]=t;
  }
  
  void erase(int t,int u,int v){
    edge e=minmax(u,v);
    if(--cnt[e]==0) prc.emplace_back(range(app[e],t),e);
  }
  
  void add(int a,int b,const edge &e,int k,int l,int r){
    if(r<=a||b<=l) return;
    if(a<=l&&r<=b){
      edges[k].emplace_back(e);
      return;
    }
    int m=(l+r)>>1;
    add(a,b,e,k*2+1,l,m);
    add(a,b,e,k*2+2,m,r);
  }
  
  void add(range &r,const edge &e){
    add(r.first,r.second,e,0,0,q);
  }
  
  void build(){
    for(auto &e:cnt){
      if(!e.second) continue;
      prc.emplace_back(range(app[e.first],q),e.first);
    }
    for(auto &s:prc)
      add(s.first,s.second);
  }

  void exec(function<void(int)> &f,int k=0){
    for(auto &e:edges[k])
      puf.unite(e.first,e.second);

    if(k<q-1){
      exec(f,k*2+1);
      exec(f,k*2+2);
    }else{
      int x=k-(q-1);
      f(x);
    }
    
    puf.undo(edges[k].size()); 
  }
};


signed main(){
  int n,q;
  cin>>n>>q;
  DynamicConnectivity dc(n,q);
  vector<int> t(q),u(q),v(q);
  for(int i=0;i<q;i++){
    cin>>t[i]>>u[i]>>v[i];
    if(t[i]==1) dc.insert(i,u[i],v[i]);
    if(t[i]==2) dc.erase(i,u[i],v[i]);
  }
  dc.build();
  function<void(int)> f=[&](int x){
    if(x<0||x>=q) return;
    if(t[x]!=3) return;
    cout<<(dc.puf.same(u[x],v[x])?"YES":"NO")<<endl;
  };
  dc.exec(f);
  return 0;
}



Measured memory_bytes: 14856
#[allow(unused_imports)]
use std::char::*;
#[allow(unused_imports)]
use std::cmp::*;
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

//const MAX:usize = 100006;
//const INF:u64 = u64::max_value();

fn main() {
    let n:u32 = read();
    let a:Vec<f64> = (0..n).map(|_| read::<f64>()).collect();

    let ans:f64 = a.iter().map(|x| 1.0/x).sum();
    
    println!("{}", format!("{:.10}", 1.0/ans));
    
}

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

int main(){
    while (true){
        int h, w;
        cin >> h >> w;
        if (h == 0 && w == 0) break;
        for (int i = 0; i < h; i++){
            for (int j = 0; j < w; j++){
                if ((i+j) %2 ==0) cout << "#";
                else cout << ".";
            }
            cout << endl;
        }
    cout << endl;
    }
    return 0;
}


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

const int INF = 1e+9;

using P = pair<int,int>;
int n,k,t,ans;
set<int> st[200010];
vector<P> on[200010],off[200010];

int calc(int x){
	return (st[x].size() == 2 && *(st[x - 1].begin()) < *(st[x].begin()))
	+ (st[x + 1].size() == 2 && *(st[x].begin()) < *(st[x + 1].begin()));
}

signed main(){
	cin >> n >> k >> t;
	for(int i = 0;i < t;i++){
		int l,r,x;
		cin >> l >> r >> x; l--;r--;
		on[l].emplace_back(i,x);
		off[r].emplace_back(i,x);
	}
	st[0].insert(-1);
	for(int i = 0;i <= k + 1;i++) st[i].insert(INF);
	int cnt = 0;
	for(int i = 0;i < n;i++){
		for(P p : on[i]){
			cnt -= calc(p.second);
			st[p.second].insert(p.first);
			cnt += calc(p.second);
		}
		if(cnt == k) ans++;
		for(P p : off[i]){
			cnt -= calc(p.second);
			st[p.second].erase(p.first);
			cnt += calc(p.second);
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 43556
x, k, d = map(int, input().split())

x = abs(x)

n = x//d
if n > k:
    ans = x - (k*d)

else:
    if (k - n) % 2 == 0:
        ans = x - (n*d)
    else:
        ans = x - ((n+1)*d)

print(abs(ans))

Measured memory_bytes: 9176
#include<stdio.h>

void maxHeapify(int *,int);
void Swap(int *,int,int);

int N;
int T[500010] ={0};

int main()
{
    int i, j;
    scanf("%d", &N);
    for (i = 0; i < N; i++) {
        scanf("%d", &T[i]);
    }
    for (i = N/2+1; i >= 0; i--) {
        maxHeapify(T, i);
    }
    for (i = 0; i < N; i++) {
        printf(" %d", T[i]);
    }
    puts("");
  
    return 0;
}

void Swap(int T[], int x, int y)
{
    int tmp = T[x];
    T[x] = T[y];
    T[y] = tmp;
}

void maxHeapify(int T[], int i)
{
    int parent = i;
    int left = (i+1)*2 - 1;
    int right = (i+1)*2;
     
    int largest;
    if (right <= N && T[parent] < T[right]) {
        largest = right;
    }
    else {
        largest = parent;
    }
     
    if (left <= N && T[largest] < T[left]) {
        largest = left;
    }
  
    if (largest != parent) {
        Swap(T, largest, parent);
        maxHeapify(T, largest);
    }    
     
    return;
}
 



Measured memory_bytes: 3712
#include<bits/stdc++.h>
using namespace std;
int n,m,K,ans;
long long a[200004],b[200004];
int main(){
	cin>>n>>m>>K;
	for(int i=1;i<=n;i++)cin>>a[i],a[i]=a[i-1]+a[i];
	for(int i=1;i<=m;i++)cin>>b[i],b[i]=b[i-1]+b[i];
	for(int i=0;i<=n;i++)if(K>=a[i]){
		int res=upper_bound(b+1,b+1+m,K-a[i])-b-1;
		ans=max(ans,res+i);
	}
	cout<<ans;
}

Measured memory_bytes: 6756
#include<stdio.h>

int main(){

	int n, m, i, j;
	scanf("%d %d\n", &n, &m);
	int A[n][m], b[m], c;

	for ( i = 0 ; i < n ; i++ ) {
		for ( j = 0 ; j < m ; j++ ){
			A[i][j] = 0;
			if ( i == 0 ) b[m] = 0;
		}
	}

	for ( i = 0 ; i < n ; i++ ) {
		for ( j = 0 ; j < m ; j++ ) {
			scanf("%d", &A[i][j]);
			if ( j != m - 1 ) {
				scanf(" ");
			} else {
				scanf("\n");
			}
		}
	}
	for ( j = 0 ; j < m ; j++ ){
		scanf("%d", &b[j]);
		if ( j != m - 1 ) scanf("\n");
	}

	for ( i = 0 ; i < n ; i++ ) {
		c = 0;
		for ( j = 0 ; j < m ; j++ ) {
			c = c + A[i][j] * b[j];
		}
		printf("%d\n", c);
	}

    return 0;
}

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

int main() {
	// your code goes here
	int n;long w;
	
	cin>>n>>w;
	long long dp[w+1]={0};
	
	long wt,v;
	
    for(int i=0;i<n;i++)
    {
        cin>>wt>>v;
        
        for(long j=w-wt;j>=0;j--)
        {
            dp[j+wt]=max(dp[j+wt],dp[j]+v);
        }
        
        
    }
    
    long long a=0;
    for(long i=1;i<=w;i++)
    {
        a=max(a,dp[i]);
    }	
    cout<<a;
	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int digits_product(int num) {
        int d1 = num/10;
        int d2 = num%10;
        if(d1 >= 2 && d2 >= 2)
                return d1*d2;
        return 1001;
}
void solve() {
        int m, d, count = 0;
        cin >> m >> d;
        for(int i=d;i>=1;i--) {
                if(digits_product(i) <= m && digits_product(i) > 0)
                        count++;
        }
        cout << count << '\n';
        return ;
}
int main() {
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        cout.tie(NULL);
        solve();
        return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm>
#include<sstream>
#include<complex>
#include<functional>
#include<vector>
#include<map>
#include<queue>
#include<deque>
#include<stack>
#include<set>

using namespace std;
#define endl '\n'
#define eb emplace_back
#define fst first
#define scd second
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define YES(n) cout << ((n) ? "YES" : "NO" ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No" ) << endl

constexpr int MOD = 1000000007;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef vector<ll> vl;

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }

// value
ll L, R;

void solve() {

	cin >> L >> R;

	if (R - L >= 2019) {
		cout << 0 << endl;
		return;
	}

	ll ans = L * (L + 1) % 2019;
	for (ll i = L; i <= R; i++) {
		for (ll j = i + 1; j <= R; j++) {
			ans = min(ans, i * j % 2019);
		}
	}

	cout << ans << endl;

	return;

}

int main() {

	cin.tie(0);
	ios::sync_with_stdio(false);

	solve();

	return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;
#define REP(i, n) for (ll i = 0; i < (int)(n); i++)
#define RREP(i, n) for (ll i = (int)(n)-1; i > -1 ; i--)
#define IN(T, x) T x;cin >> x;
#define AIN(T, a, n) vector<T> a(n);REP(i, n){cin >> a[i];}
#define A2IN(T1, a, T2, b, n) vector<T1> a(n);vector<T2> b(n);REP(i, n){cin >> a[i] >> b[i];}
#define ALL(a) (a).begin(),(a).end()
#define SORT(a) sort(ALL(a))
#define RSORT(a) SORT(a);reverse(ALL(a))
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;}
#define OUT(x) cout << x << endl
#define BOUT(b) if(b){OUT("Yes");}else{OUT("No");}
const ll MOD = 100000007;


int main() {
  IN(ll, N);
  IN(ll, A);
  IN(ll, B);
  IN(ll, C);
  AIN(string, S, N);
  string ans = "";
  if(A+B+C==0){
    OUT("No");
    return 0;
  }
  REP(i,N-1){
    bool isA = false;
    bool isB = false;
    bool isC = false;
    bool nextA = false;
    bool nextB = false;
    if(S.at(i).at(0) == 'A')
      isA = true;
    else
      isB = true;
    if(S.at(i).at(1) == 'C')
      isC = true;
    else
      isB = true;
    if(S.at(i+1).at(0) == 'A')
      nextA = true;
    else
      nextB = true;
    if(S.at(i+1).at(1) != 'C')
      nextB = true;
    if(!((A >= 1 && isA)||(B >= 1 && isB)||(C >= 1 && isC))){
      OUT("No");
      return 0;
    }
    if(!(isA)){
      if(B>C){
        B--;
        C++;
        ans += 'C';
      }else if(B<C){
        C--;
        B++;
        ans += 'B';
      }else{
        if(nextB){
          C--;
          B++;
          ans += 'B';
        }else{
          B--;
          C++;
          ans += 'C';
        }
      }
    }else if(!(isB)){
      if(A>C){
        A--;
        C++;
        ans += 'C';
      }else if(A<C){
        C--;
        A++;
        ans += 'A';
      }else{
        if(nextA){
          C--;
          A++;
          ans += 'A';
        }else{
          A--;
          C++;
          ans += 'C';
        }
      }
    }else{
      if(B>A){
        B--;
        A++;
        ans += 'A';;
      }else if(B<A){
        A--;
        B++;
        ans += 'B';;
      }else{
        if(nextB){
          A--;
          B++;
          ans += 'B';;
        }else{
          B--;
          A++;
          ans += 'A';;
        }
      }
    }
  }
  bool lastA = false;
  bool lastB = false;
  bool lastC = false;
  if(S.at(N-1).at(0) == 'A')
    lastA = true;
  else
    lastB = true;
  if(S.at(N-1).at(1) == 'C')
    lastC = true;
  else
    lastB = true;
  if(!((A >= 1 && lastA)||(B >= 1 && lastB)||(C >= 1 && lastC))){
    OUT("No");
    return 0;
  }
  if(!(lastA)){
    if(B>=C){
      B--;
      C++;
      ans += 'C';;
    }else{
      C--;
      B++;
      ans += 'B';;
    }
  }else if(!(lastB)){
    if(A>=C){
      A--;
      C++;
      ans += 'C';
    }else{
      C--;
      A++;
      ans += 'A';
    }
  }else{
    if(B>=A){
      B--;
      A++;
      ans += 'A';
    }else{
      A--;
      B++;
      ans += 'B';
    }
  }
  OUT("Yes");
  REP(i,N){
    OUT(ans.at(i));
  }
}





Measured memory_bytes: 6672
package main

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


func main() {
   sc.Split(bufio.ScanWords)
   defer out.Flush()


   n,k := nextInt(), nextInt()
   h := nextInts(n)
   sort.Sort(sort.Reverse(sort.IntSlice(h)))
   sum := 0
   for i := k; i < n; i += 1{
      sum += h[i]
   }
   fmt.Println(sum)
}

// -*-*-*-*-*-*-*-*-
// * I/O utilities *
// -*-*-*-*-*-*-*-*-

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

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

func nextInt() int {
   a, _ := strconv.Atoi(next())
   return a
}

func nextFloat64() float64 {
   a, _ := strconv.ParseFloat(next(), 64)
   return a
}

func nextInts(n int) []int {
   ret := make([]int, n)
   for i := 0; i < n; i++ {
      ret[i] = nextInt()
   }
   return ret
}
func nextFloats(n int) []float64 {
   ret := make([]float64, n)
   for i := 0; i < n; i++ {
      ret[i] = nextFloat64()
   }
   return ret
}
func nextStrings(n int) []string {
   ret := make([]string, n)
   for i := 0; i < n; i++ {
      ret[i] = next()
   }
   return ret
}

func split(s string) []string {
   ret := make([]string, len([]rune(s)))
   for i, v := range []rune(s) {
      ret[i] = string(v)
   }
   return ret
}

func PrintOut(src interface{}, joinner string) {
   switch reflect.TypeOf(src).Kind() {
   case reflect.Slice:
      s := reflect.ValueOf(src)
      for idx := 0; idx < s.Len(); idx++ {
         fmt.Fprintf(out, "%v", s.Index(idx))
         if idx < s.Len()-1 {
            fmt.Fprintf(out, "%s", joinner)
         } else {
            fmt.Fprintln(out)
         }
      }
   default:
      fmt.Fprintln(out, "fuck")
   }
}

Measured memory_bytes: 5120
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define pb push_back
#define mp make_pair
#define M 1000000007
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
const int N = 2e5 + 5;
int n , a[N] , l[N] , r[N] , cumxor;
int main(){
	scanf("%d",&n);
	for (int i = 0; i < n; ++i){
		if(i)l[i] = cumxor;
		scanf("%d",a+i);
		cumxor ^= a[i];
	}
	cumxor = 0;
	for (int i = n-1; i >= 0; --i){
		r[i] = cumxor;
		cumxor ^= a[i];
	}
	for (int i = 0; i < n; ++i){
		printf("%d ",(r[i]^l[i]));
	}
	puts("");
	

}	

Measured memory_bytes: 6012
from collections import defaultdict
N=int(input())
a=list(map(int,input().split()))
acc_s=[]
acc_s.append(0)
dic=defaultdict(int)
dic[0]=1
for i in range(N):
  if i==0:
    acc_s.append(a[i])
    dic[a[i]]+=1
  else:
    v=a[i]+acc_s[-1]
    dic[v]+=1
    acc_s.append(v)
cnt=0
for key in dic.keys():
  v=dic[key]
  cnt+=(v*(v-1)//2)
print(cnt)

Measured memory_bytes: 39280
#include <cmath>
#include <cstdio>
#include <vector>
#include <list>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <stack>
#include <fstream>
#include <queue>
#include <iomanip>
#include <iterator>
#include <map>
#include <unordered_map>
#include <set>
#define fast ios_base::sync_with_stdio(false)
#define ll long long int
#define ld long double
#define vi vector<ll>
#define vvi vector<vi >
#define pi pair<ll,ll>
#define vvpi vector<vector<pi > >
#define vpi vector<pi >
#define vppi vector<pair<ll,pi > >
#define vs vector<string>
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define pb push_back
#define eb emplace_back
#define mkp make_pair
#define fs first
#define se second
#define crz(v,n) v.clear(),v.resize(n+1,0)
#define print(v) for(ll it=0;it<v.size();it++) cout<<v[it]<<" ";cout<<endl
#define printp(v) for(ll it=0;it<v.size();it++) cout<<v[it].first<<" "<<v[it].second<<endl
using namespace std;
int main(){
	ll a,b;cin>>a>>b;cout<<6-a-b<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define inf 0x3f3f3f3f
#define pb push_back
#define fi first
#define se second

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector <int> vi;
typedef vector <vector <int>> vvi;
typedef pair <int, int> pi;
typedef vector <pair <int, int>> vpi;

int n, maxi, maxi2, pos;

vi v;

void read() {
  cin >> n;
  for(int i = 0; i < n; ++i) {
    int x;
    cin >> x;
    v.pb(x);
    if (x > maxi) {
      maxi2 = maxi;
      maxi = x;
      pos = i;
    } else if (x > maxi2)
        maxi2 = x;
  }
}

void solve() {
  for(int i = 0; i < n; ++i) {
    if (i != pos) {
      cout << maxi << "\n";
    } else cout << maxi2 << "\n";
  }
}


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


Measured memory_bytes: 2548
#include <bits/stdc++.h>
#define ft first
#define sc second
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define pt(sth) cout << sth << "\n"
#define chmax(a, b) {if(a<b) a=b;}
#define chmin(a, b) {if(a>b) a=b;}
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
static const ll INF=1e18;
static const ll MAX=1e5+7;
static const ll MOD=1e9+7;
ll max(ll a, ll b) {return a>b?a:b;}
ll min(ll a, ll b) {return a<b?a:b;}

int main(void) {
  ll N;
  cin >> N;
  ll i;
  ll sum=0;
  ll pc=0, nc=0;
  ll a[MAX];
  
  for(i=0; i<N; i++) {
    cin >> a[i];
    sum+=abs(a[i]);
    
    if(a[i]>=0) pc++;
    else nc++;
  }
  sort(a, a+N);
  
  if(pc==0) {
    pt(sum-abs(a[N-1])*2);
    
    ll p=a[N-1];
    for(i=0; i<N-1; i++) {
      pt(p<<" "<<a[i]);
      p-=a[i];
    }
    
  }else if(nc==0) {
    pt(sum-a[0]*2);
    
    ll p=a[0];
    for(i=1; i<N-1; i++) {
      pt(p<<" "<<a[i]);
      p-=a[i];
    }
    
    pt(a[N-1]<<" "<<p);
    
  }else {
    pt(sum);
    
    ll id=0;
    for(i=0; i<N; i++) {
      if(a[i]>=0) {
        id=i;
        break;
      }
    }
    
    ll p=a[0];
    for(i=id; i<N-1; i++) {
      pt(p<<" "<<a[i]);
      p-=a[i];
    }
    
    a[0]=p;
    p=a[N-1];
    for(i=0; i<id; i++) {
      pt(p<<" "<<a[i]);
      p-=a[i];
    }
    
  }
  
}












Measured memory_bytes: 2688
import java.util.Scanner;

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

    int A = sc.nextInt(), B = sc.nextInt();
    int C = sc.nextInt(), X = sc.nextInt(), Y = sc.nextInt();
    
    System.out.println(solve(A,B,C,X,Y));
  }

  private static long solve(int A, int B, int C, int X, int Y) {
    long ret = 1L<<60;
    for(int ab = 0; ab<=Math.max(X, Y)*2; ab++) {
      long temp = ab * C;
      // 買うべきA, Bの枚数
      int a = X-ab/2, b = Y-ab/2;
      if(a<0)a=0;
      if(b<0)b=0;
      temp += a*A + b*B;
      ret = Math.min(ret, temp);
    }
    return ret;
  }
}


Measured memory_bytes: 35980
#include <cstdio>
using namespace std;

#define REP(i, stop) for (int i = 0, i##_len = stop; i < i##_len; ++i)

const int is = 1 << 14;
char ib[is], *ip = ib + is, it;
inline char getc() {
	if (ip == ib + is) { fread_unlocked(ib, 1, is, stdin); ip = ib; }
	return *ip++;
}
inline int read() {
	int r = 0;
	if (ip + 16 > ib + is) while ((it = getc()) & 16) r = r * 10 + it - '0';
	else while ((it = *ip++) & 16) r = r * 10 + it - '0';
	return r;
}

const int os = 1 << 14;
char ob[os], *op = ob, ot;
inline void putc(const char c) {
	*op++ = c;
	if (op == ob + os) { fwrite_unlocked(ob, 1, os, stdout); op = ob; }
}
// x shoud be greater than or equal to zero
inline void write(int x) {
	char d[6];
	int i = 0;
	while (true) {
		d[i] = x % 10 + 48;
		x /= 10;
		++i;
		if (x <= 0) break;
	}
	while (i--) {
		putc(d[i]);
	}
}

int A[200000];
signed main() {
	int n = read();
	int m0 = 0;
	int m1 = 0;
	REP(i, n) {
		int a = read();
		if (a > m0) {
			m1 = m0;
			m0 = a;
		} else if (a > m1) {
			m1 = a;
		}
		A[i] = a;
	}
	REP(i, n) {
		int a = A[i];
		if (a == m0) {
			write(m1);
		} else {
			write(m0);
		}
		putc('\n');
	}
	fwrite_unlocked(ob, 1, op - ob, stdout);
}


Measured memory_bytes: 2304
#include <iostream>

using namespace std;

typedef long long ll;

int main(){
  ll X;
  cin >> X;
  ll ans = 0;
  ans += (X / 500) * 1000;
  X = X % 500;
  ans += (X / 5) * 5;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
ll const INF = 1LL << 60;

int main() {
  ll N;
  cin >> N;
  string a, b, c;
  cin >> a >> b >> c;
  ll ans = 0;
  for (int i = 0; i < N; i++) {
    if (a[i] == b[i] && c[i] == b[i]) continue;
    if (a[i] == b[i] || c[i] == b[i] || a[i] == c[i]) {
      ans++;
    } else {
      ans += 2;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    //int t;cin>>t;while(t--)
    {
        ll i,j,k,l,m,n,a,b,c,d,cnt=0,sum=0,o=1,x;
        cin>>x>>n;
        vector <int> vec;
        map <int,int> mp;
        for(i=0;i<n;i++)
        {
            cin>>k;
            mp[k]=1;
        }
        vec.push_back(x);
        for(i=0;i<1000;i++)
        {
            vec.push_back(x-o);
            vec.push_back(x+o);
            o++;
        }
        for(int i: vec)
        {
            if(mp[i]==0)
            {
                cout<<i<<endl;
                return 0;
            }
        }
    }


}


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

#define ln '\n'
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define FOR(i, a, b) for (int i = (a); i <= (int)(b); ++i)
#define FORR(i, a, b) for (int i = (a); i >= (int)(b); --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
typedef vector<P> VP;
typedef vector<PL> VPL;
typedef vector<string> VS;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m, x;
    cin >> n >> m >> x;

    VI c(n);
    VVI a(n, VI(m));

    REP(i, n) {
        cin >> c[i];
        REP(j, m) cin >> a[i][j];
    }

    int ans = 1e9;
    REP(c_bit, pow(2, n)) {
        VI a_sum(m, 0);
        int cost = 0;
        REP(i, n) {
            if (((c_bit >> i) & 1) == 1) {
                REP(j, m) a_sum[j] += a[i][j];
                cost += c[i];
            }
        }

        REP(j, m) {
            if (a_sum[j] < x) break;
            if (j == m - 1) ans = min(ans, cost);
        }
    }

    if (ans == (int)1e9)
        cout << -1 << ln;
    else
        cout << ans << ln;
    return 0;
}


Measured memory_bytes: 4096
use std::io::prelude::*;

fn input<T: std::str::FromStr>() -> T {
    let stdin = std::io::stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}

#[allow(dead_code)]
fn with_stdout_lock<F: FnOnce(std::io::BufWriter<std::io::StdoutLock>)>(f: F) {
    let out = std::io::stdout();
    let w = std::io::BufWriter::new(out.lock());
    f(w);
}

fn main() {
    let n: usize = input();
    let m: i32 = input();
    let mut ab: Vec<(i32, i32)> = (0..n).map(|_| (input(), input())).collect();
    ab.sort();

    let mut ans = 0i64;
    let mut p = 0;
    for &(a, b) in &ab {
        if p + b >= m {
            ans += a as i64 * (m - p) as i64;
            break;
        } else {
            p += b;
            ans += a as i64 * b as i64;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
using System;
using System.Linq;
public class Hello
{
    public static void Main()
    {
        int[] n = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
        int a = n[0]+n[1];
      int b = n[2]+n[3];
      if(a == b)Console.WriteLine("Balanced");
      else if(a > b)Console.WriteLine("Left");
      else if(a < b)Console.WriteLine("Right");
    }
}

Measured memory_bytes: 13396
from heapq import heapify, heappop
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

def main():
    X,Y,A,B,C = map(int, readline().split())
    p = [-int(i) for i in readline().split()]
    q = [-int(i) for i in readline().split()]
    r = [-int(i) for i in readline().split()]

    p = sorted(p)[:X]
    q = sorted(q)[:Y]
    r.sort()
    
    Q = p + q + r
    heapify(Q)

    ans = 0
    for i in range(X+Y):
        ans -= heappop(Q)
        
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 23272
#include <stdio.h>

int main(){
  int n;
  scanf("%d",&n);
  int a[n],i,b=1,c,count=0;
  for(i=0;i<n;i++) scanf("%d",&a[i]);

  while(b){
    b=0;
    for(i=n-1;i>0;i--){
      if(a[i]<a[i-1]){
	c=a[i];
	a[i]=a[i-1];
	a[i-1]=c;
	b=1;
	count++;
      }
    }
  }

  printf("%d" ,a[0]);
  for(i=1;i<n;i++){
    printf(" %d"  ,a[i]);
  }
  
  printf("\n%d\n",count);

  return 0;
}



Measured memory_bytes: 2144
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count __gcd reverse etc.
#include <cstdlib>	// require abs exit atof atoi 
#include <cstdio>		// require scanf printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>		// require fabs
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>		// require tolower, toupper
#include <fstream>	// require freopen
#include <ctime>		// require srand
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
/*
	Earth Invasion Diary of Miyabi-sensei

	http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2330

	解説は
	http://d.hatena.ne.jp/nanikaka/20120111/1326289463
	が詳しい。

	n が 3 の倍数でないときは
	例えば
	n = 3*k + 1 のとき
	n は (k, k, k+1) となって k+1 が一番大きい
	また
	n = 3*k + 2 のとき
	n は (k+1, k+1, k ) となって k+1 が一番大きい
	よって
	f(n/3 + 1) としている。
 	
*/
int f (int n ){
	return (n <= 1 ? 0 : (n % 3 == 0 ? f(n/3) : f(n/3 + 1) ) + 1 ); 
}

int main()
{
	ios_base::sync_with_stdio(0);
	int n; cin >> n;
	int res = f(n);
	cout << res << endl;

	return 0;
}

Measured memory_bytes: 1196
N = int(input())
A = list(map(int, input().split()))
cnt1 = A.count(1)
cnt2 = A.count(2)
cnt3 = A.count(3)

dp = [[[-1] * (N + 1) for _ in range(N + 1)] for _ in range(N + 1)]
dp[0][0][0] = 0

def func(c1, c2, c3):
    if dp[c1][c2][c3] != -1:
        return dp[c1][c2][c3]

    prob0 = (N - c1 - c2 - c3) / N
    temp = 1 / (1 - prob0)
    if c1 > 0:
        temp += func(c1 - 1, c2, c3) * (c1 / N) / (1 - prob0)
    if c2 > 0:
        temp += func(c1 + 1, c2 - 1, c3) * (c2 / N) / (1 - prob0)
    if c3 > 0:
        temp += func(c1, c2 + 1, c3 - 1) * (c3 / N) / (1 - prob0)

    dp[c1][c2][c3] = temp
    return temp

print(func(cnt1, cnt2, cnt3))


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

using namespace std;

int main  ()
{

 int N;
 int A;

 cin >> N;
 cin >> A;

 if(A-N%500 >= 0)
 {
  cout<< "Yes" <<endl;
 }

 else
 {
  cout<< "No" <<endl;
 }
return 0;

}

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

int main(){
    int w,h,x,y,r;
    cin >> w >> h >> x >> y >> r;
    bool ok = (x-r >= 0) && (y-r >= 0) && (w >= x+r) && (h >= y+r);
    cout << (ok?"Yes":"No") << endl;
    return 0;
}



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

int main(void) {
  string s;
  cin >> s;
  string d;
  int cnt=0;
  
  for(int i=0; i<s.size(); i++){
    d += s[s.size()-1-i];
  }
  
  for(int i=0; i<s.size(); i++){
    if(d[i] != s[i])
      cnt++;
  }
  
  cout << cnt/2 << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <map>

using namespace std;

typedef long long ll;

ll tshape(ll W, ll H, ll x){
    ll A1 = W*x;
    ll A2 = (W/2)*(H-x);
    ll A3 = (W - W/2)*(H-x);
    ll Amin = min(A1, min(A2, A3));
    ll Amax = max(A1, max(A2, A3));
    return Amax-Amin;
}

int main(){
    ll H, W;
    cin >> H >> W;
    ll best = min(H, W);
    if(H%3==0 || W%3==0) best = 0;

    // T shapes
    best = min(best, tshape(W, H, H/3));
    best = min(best, tshape(W, H, H/3 + 1));
    best = min(best, tshape(H, W, W/3));
    best = min(best, tshape(H, W, W/3 + 1));

    cout << best << endl;

    return 0;
}


Measured memory_bytes: 256
from bisect import bisect_right
N,D,A = map(int,input().split(" "))
line = []
line_append = line.append
for i in range(N):
    x,h = map(int,input().split(" "))
    line_append((x,-(-h//A)))
line.sort()
X = list(map(lambda x: x[0],line))
dmg = [0 for _ in range(N+1)]
ans = 0
for i in range(N):
    x,h = line[i]
    h = max(0,h - dmg[i])
    dmg[i] += h
    dmg[bisect_right(X,x+2*D)] -= h
    dmg[i+1] += dmg[i]
    ans += h

print(ans)

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

int main(){
    int n, x;
    cin >> n >> x;
    vector<int> m(n);
    int sum = 0;
    for (int i = 0; i < n; i++)
    {
        cin >> m.at(i);
        sum += m.at(i);
    }
    sort(m.begin(), m.end());
    int y = (x - sum) / m.at(0); 
    cout << n + y;
}

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

int main() {
    int N;
    cin >> N;
    vector<pair<ll, ll>> work;
    rep(i, N) {
        ll A, B;
        cin >> A >> B;
        work.push_back(make_pair(B, A));
    }
    sort(work.begin(), work.end());
    ll time = 0;
    for (auto p : work) {
        time += p.second;
        if (time > p.first) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 6512
#include <iostream>
using namespace std;
int main(){
    int A,B,X,m = 0,i;
    cin>>A>>B>>X;
    if(A < 2 * B && A > B){
        for(i = 0 ; X > 500 ; i++){
            X = X -1000;
        }
        m = A * i;
        for(i = 0 ; X > 0 ; i++){
            X = X -500;
        }
        m += (B * i);
    }else if(A > B){
        for(i = 0 ; X > 0 ; i++){
            X = X -500;
        }
        m += (B * i);
    }else{
        for(i = 0 ; X > 0 ; i++){
            X = X -1000;
        }
        m += (A * i);
    }
    cout<<m<<endl;
}



Measured memory_bytes: 3092
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m;
    cin>>n>>m;
  int a[n],b[m];

     vector<long long int>c(n+1,0);
  vector<long long int>d(m+1,0);
    int k;
    cin>>k;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    for(int i=0;i<m;i++)
    {
        cin>>b[i];
    }
  for(int i=0;i<n;i++)
  {
    c[i+1]=c[i]+a[i];
  }
  for(int i=0;i<m;i++)
    d[i+1]=d[i]+b[i];
    long int ans=0;
    long int l;
    for(long int i=0;i<=n;i++)
    {
          long long int e=k-c[i];
          if(e<0)
            continue;
          else
          {
            l=lower_bound(d.begin(),d.end(),e)-d.begin();
              if(l>m || d[l]>e)
                l--;
          }
          ans=max(ans,i+l);
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 7928
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <algorithm>

#define int long long
#define MOD7 1000000007
#define MOD9 1000000009

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

using namespace std;

int nextInt() {int a; cin >> a; return a;}
char nextChar() {char a; cin >> a; return a;}
double nextDouble() {double a; cin >> a; return a;}
string nextString() {string a; cin >> a; return a;}

void inputVector(vector<int> &v, int &n) {rep(i,n){v.push_back(nextInt());}}
void inputVector(vector<double> &v, int &n) {rep(i,n){v.push_back(nextDouble());}}
void inputVector(vector<string> &v, int &n) {rep(i,n){v.push_back(nextString());}}

int cnt[2];

signed main() {
    string S;
    cin >> S;

    rep(i, S.size()) {
	if (S[i] == 'p') {
	    cnt[0]++;
	} else {
	    cnt[1]++;
	}
    }

    cout << (cnt[1] - cnt[0]) / 2 << endl;

    return 0;
}


Measured memory_bytes: 512