akhauriyash/Code-Regression huggingface dataset:
#ifdef LOCAL
#include <cstdio>
#include <vector>
#include <algorithm>
#include <iostream>
#include <cstring>
#else
#include <bits/stdc++.h>
#endif
using namespace std ;

typedef long long ll ;
typedef unsigned long long ull ;
#define rep(i , n ) for ( int i =0; i < n ; i++)
#define rrep(i , n) for ( int i = n-1; i >=0 ; i--)

#define _sort(arg) sort(begin(arg), end(arg))
#define MOD 1000000007
#define pb push_back
#define DEBUG(x) cout << #x << ": " << x << endl;

class UnionFind {
private:
	ull size_; 
	std::vector<ull> par, rank, count;

public:
	UnionFind() : size_(0), par(std::vector<ull>()), rank(std::vector<ull>()), count(std::vector<ull>()) {};
	UnionFind(ull size__) : size_(size__) {
		par.resize(size_); rank.resize(size_); count.resize(size__);
		for (ull i = 0; i < size_; i++) par[i] = i, rank[i] = 0, count[i] = 1;
	}
	ull size() { return size_; }
	// ull root(ull x) { return par[x] == x ? x : par[x] = root(par[x]); }
	
	ull root(ull x)
	{
		while(par[x] != x)
		{
			par[x] = par[par[x]];
			x = par[x];
		}
		return x;
	}
	
	bool same(ull x, ull y) { return root(x) == root(y); }

	void unite(ull x, ull y) {
		x = root(x), y = root(y);
		if (x == y) return;
		if (rank[x] < rank[y]) par[x] = y, count[y]+=count[x], count[x]=0;
		else if (rank[x] == rank[y]) par[y] = x, rank[x]++, count[x]+=count[y], count[y]=0;
		else par[y] = x, count[x] += count[y], count[y] = 0;
	}

	ull size__(ull x)
	{
		return count[root(x)];
	}

	bool operator==(const UnionFind &u) { return par == u.par; }
	bool operator!=(const UnionFind &u) { return par != u.par; }
};
/*
maybe sth wrong 
got wa in one problem
*/
ll modpow(ll a, ll b)
{
	if (b == 0)
	{
		return 1;
	}

	if (b % 2)
	{
		return a * modpow(a, b-1) % MOD;
	}
	else
	{
		ll halfB = b / 2;
		ll half = modpow(a, halfB);
		return half * half % MOD;
	}
}

ll calcComb(ll n, ll m)
{
	if (m > n-m)
	{
		return calcComb(n, n-m);
	}

	ll ansMul = 1;
	ll ansDiv = 1;

	rep(i, m)
	{
		ansMul *= (n-i);
		ansDiv *= (i+1);
		ansMul %= MOD;
		ansDiv %= MOD;
	}

	return ansMul * modpow(ansDiv, MOD - 2) % MOD;
}

__attribute__((constructor))
void initial()
{
	cin.tie(NULL);
	ios::sync_with_stdio(false);
}

//ll arr[1000000000];

int main()
{
	ll x,y,z,k;
	vector<ll> a, b, c;

	cin >> x >> y >> z >> k;
	
	rep(i, x)
	{
		ll tmp;
		cin >> tmp;
		a.pb(tmp);
	}
	
	rep(i, y)
	{
		
		ll tmp;
		cin >> tmp;
		b.pb(tmp);
	}

	rep(i, z)
	{
		
		ll tmp;
		cin >> tmp;
		c.pb(tmp);
	}
	
	sort(a.begin(), a.end(), greater<ll>());
	sort(b.begin(), b.end(), greater<ll>());
	sort(c.begin(), c.end(), greater<ll>());

	vector<ll> v; 
	for (int i = 1; i <= min(k, x); i++)
	{
		for (int j = 1; j <= min(k/i+1, y); j++)
		{
			for (int m = 1; m <= min(k/i/j+1, z); m++)
			{
				v.pb(a[i-1]+b[j-1]+c[m-1]);
			}
		}
	}

	sort(v.begin(), v.end(), greater<ll>());
	rep(i, k)
	{
		cout << v[i] << endl;
	}

	return 0;
}


Measured memory_bytes: 1412
#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;++i)
#include<string>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<int, int>P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//max=({});
//条件式が真ならwhileの中身を回し続ける
//printf("%d\n", ans);

//pairの入力
//vector<pair<ll, ll>>work(n);
//rep(i, n) {
//	ll a, b;
//	cin >> a >> b;
//	work[i] = make_pair(a, b);
//for(auto p:mp)(mapの探索)
//printf("%.10f\n",なんちゃら)

int g[15][15];
const int INF = 1001001001;
const int dx[4] = { -1,0,1,0 };
const int dy[4] = { 0,-1,0,1 };

//最大公約数
ll gcd(ll x, ll y) {
	return y ? gcd(y, x % y) : x;
}

ll lcm(ll x, ll y) {
	if (x == 0 || y == 0)return 0;
	return (x / gcd(x, y) * y);
}

//素因数分解
vector<pair<ll, int>>factorize(ll n) {
	vector<pair<ll, int>>res;
	for (ll i = 2;i * i <= n;++i) {
		if (n % i)continue;
		res.emplace_back(i, 0);
		while (n % i == 0) {
			n /= i;
			res.back().second++;
		}
	}
	if (n != 1)res.emplace_back(n, 1);
	return res;
}

int bingo[3][3];
bool flag[3][3];
int cnt[2][105];
int h, w;
int choco[1010][1010];
int s[11][11];

int main() {
	ll n, k;
	cin >> n >> k;
	vector<ll>a(n), b(n);
	map<ll, ll>mp;
	rep(i, n) {
		cin >> a[i] >> b[i];
		mp[a[i]] += b[i];
	}
	for (auto p : mp) {
		ll x = p.first;
		ll y = p.second;
		k -= y;
		if (k <= 0) {
			cout << x << endl;
			break;
		}
	}
	return 0;
}


Measured memory_bytes: 5760
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <numeric>
#include <cmath>

using namespace std;

typedef long long int ll;
typedef pair<int,int> P;

#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;
const ll MAXN = 1e9;

int main()
{
    int n,x;
    cin>>n>>x;
    vector<int>l(n);
    for(int i = 0; i < n; i++){
        cin>>l[i];
    }
    vector<int>d(n+1,0);
    for(int i = 1; i <= n; i++){
        d[i] = d[i-1] + l[i-1];
    }
    int ans=0;
    for(int i = 0; i <= n; i++){
        if(d[i]<=x)ans++;
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 256
S = input()
T = input()
U = "abcdefghijklmnopqrstuvwxyz"
s =[0 for i in range(26)]
t =[0 for i in range(26)]
for k in range(26):
    s[k] += S.count(U[k])
    t[k] += T.count(U[k])
print("Yes" if sorted(s)==sorted(t) else "No")

Measured memory_bytes: 3632
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using System.Runtime.CompilerServices;
using static MyUtil;

class MyUtil
{
    public static int[] ReadIntArray()
    {
	return ReadLine().Split().Select(x => int.Parse(x)).ToArray();
    }
}

class Program
{
    public static void Main()
    {
	var tmp = ReadIntArray();
	int a = tmp[0], b = tmp[1];
	int ans = b;

	if (a <= 5)
	{
	    ans = 0;
	}
	else if (a < 13)
	{
	    ans /= 2;
	}

	WriteLine(ans);
    }
}


Measured memory_bytes: 13268
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define Rep(i, r, n) for (ll i = r; i < n; i++)
#define pb push_back
#define MOD 1000000007
#define INF 1000000000
#define EPS 0.0000000001
typedef long long ll;

ll n,q;
vector<vector<ll>> edge;
vector<ll> cost(n,0);
vector<bool> check(n);

void dfs(ll current){
    check[current]=true;
    for(ll next:edge[current]){
        if(check[next]){
            continue;
        }
        cost[next]+=cost[current];
        dfs(next);
    }
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    //---------------------------------------------
    
    cin>>n>>q;
    ll a,b,p,x;
    cost.resize(n);
    edge.resize(n);
    rep(i,n-1){
        cin>>a>>b;
        edge[a-1].pb(b-1);
        edge[b-1].pb(a-1);
    }
    rep(i,q){
        cin>>p>>x;
        cost[p-1]+=x;
    }
    check.resize(n);
    dfs(0);
    rep(i,n){
        cout<<cost[i]<<" ";
    }
    cout<<endl;

    
}   

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

int main(){
	int a,b;
	while(true){
		char op;
		cin>>a>>op>>b;
		if(op=='+'){
			cout<<a+b<<endl;
		}
		else if(op=='-'){
			cout<<a-b<<endl;
		}
		else if(op=='*'){
			cout<<a*b<<endl;
		}
		else if(op=='/'){
			cout<<a/b<<endl;
		}
		else if(op=='?'){ 
			break;
		}  
	}
	return 0;
}



Measured memory_bytes: 3092
#pragma GCC optimize("Ofast", "unroll-loops")

#include <bits/stdc++.h>

using namespace std;

string N; int K;
vector<int> can_use(10, true);
int mn_use;

void input(void) {
	cin >> N >> K;
	for (int i = 0; i < K; ++i) {
		int di; cin >> di;
		can_use[di] = false;
	}
	for (int i = 0; i < 10; ++i) {
		if (can_use[i]) {
			mn_use = i;
			break;
		}
	}
}

int main(void) {
	constexpr int INF = (1 << 25);
	input();
	vector<vector<int>> dp(N.size() + 1, vector<int>(2, 0));
	for (int i = 1; i < 10; ++i) {
		if (can_use[i]) {
			dp[0][1] = i;
			break;
		}
	}
	for (int i = 1; i <= N.size(); ++i) {
		// dp[i][0]の確定
		if (dp[i - 1][0] == INF || !can_use[N[i - 1] - '0'])
			dp[i][0] = INF;
		else dp[i][0] = dp[i - 1][0] * 10 + (N[i - 1] - '0');
		// dp[i][1]の確定
		dp[i][1] = min(dp[i - 1][1] * 10 + mn_use, INF);
		int d = -1;
		for (int j = (N[i - 1] - '0') + 1; j < 10; ++j) {
			if (can_use[j]) {
				d = j;
				break;
			}
		}
		if (d != -1) 
			dp[i][1] = min(dp[i][1], dp[i - 1][0] * 10 + d);
	}
	cout << min(dp[N.size()][0], dp[N.size()][1]) << endl;
	return 0;
}

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

typedef long long int ll;

int main(){
    string s; cin >> s;
    for(int i = 1; i < 4; i++){
        if(s[i]==s[i-1]){
            cout << "Bad\n"; return 0;
        }
    }
    cout << "Good\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iomanip>
#include <algorithm>
#define ll long long
#include <unordered_map>
using namespace std;
 
int main() {
  ll N, D, x, y, cnt = 0;
  cin >> N >> D;
  for(ll i = 0; i < N; i++) {
    cin >> x >> y;
    if(x * x + y * y <= D * D) cnt++;
  }
  cout << cnt << endl;
}

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

int main() {
    int n, m, k;
    cin >> n >> m >> k;
    for (int i = 0; i <= m; i++) {
        if (m - i * 2 != 0 && (k - i * n) % (m - i * 2) == 0 && 0 <= (k - i * n) / (m - i * 2) && (k - i * n) / (m - i * 2) <= n) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}   

Measured memory_bytes: 256
fun main() {
    val n = readLine()!!.toInt()
    val list = (1..n).map { readLine()!! }
    var a = 0
    var w = 0
    var t  = 0
    var r = 0
    for (l in list) {
        when(l) {
            "AC" -> {
                a++
            }
            "WA" -> {
                w++
            }
            "TLE" -> {
                t++
            }
            "RE" -> {
                r++
            }
        }
    }
    println("AC x $a\n" +
            "WA x $w\n" +
            "TLE x $t\n" +
            "RE x $r")
}

Measured memory_bytes: 60580
n = gets.to_i
N = 100000
memo = [0] * (N+1)
(1..N+1).each do |i|
  a = []
  7.times do |j|
    k = i - 6 ** j
    a << memo[k] if k >= 0
    k = i - 9 ** j
    a << memo[k] if k >= 0
  end
  memo[i] = a.min + 1
end
puts memo[n]


Measured memory_bytes: 2812
#include <bits/stdc++.h>
#include <boost/range/irange.hpp>
using namespace std;
using namespace boost;
main() {
  int d;
  cin >> d;
  cout << "Christmas";
  for (auto i : irange(0, 25 - d)) {
    cout << " Eve";
  }
  cout << endl;
}
  

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <set>
using namespace std;


int Total(multiset<int > a){
	int total=0;
	multiset<int >::iterator it = a.begin();
	for (; it != a.end(); it++)	total += *it;
	return total;
}

int main(){
	int n=0,m=0;
	multiset <int > sn,sm;

	while (cin >> n >> m,n,m){
		int nTotal = 0, mTotal=0,flag=0;
		sn.clear();
		sm.clear();
		while (n--){
			int temp;
			cin >> temp;
			nTotal += temp;
			sn.insert(temp);
		}
		while (m--){
			int temp;
			cin >> temp;
			mTotal += temp;
			sm.insert(temp);
		}
		for (multiset<int>::iterator itn = sn.begin(); itn != sn.end(); itn++){
			for (multiset<int>::iterator itm = sm.begin(); itm != sm.end(); itm++){
				if (Total(sn) - *itn + *itm == Total(sm) - *itm + *itn){
					// exe
					cout << *itn << " " << *itm << endl;
					flag = 9;
					break;
				}
			}
			if (flag == 9)	break;
		}
		if (flag != 9)	cout << -1 << endl;
	}
	return 0;
}

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

using Int = long long;
const char newl = '\n';

template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
template<typename T> void drop(const T &x){cout<<x<<endl;exit(0);}
template<typename T=Int>
vector<T> read(size_t n){
  vector<T> ts(n);
  for(size_t i=0;i<n;i++) cin>>ts[i];
  return ts;
}

//INSERT ABOVE HERE
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(0);

  Int a,b,c,d;
  cin>>a>>b>>c>>d;
  Int ans=a*c;

  vector<Int> vx({a,b});
  vector<Int> vy({c,d});
  if(a<=0 and 0<=b) vx.emplace_back(0);
  if(c<=0 and 0<=d) vy.emplace_back(0);

  for(Int x:vx)
    for(Int y:vy)
      chmax(ans,x*y);

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


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

int main() {
	string s,c;
    cin>>s;
    cin>>c;
    if(c.length() > s.length()) {
        c.erase(c.begin()+s.length(),c.end());
        if(c==s) cout<<"Yes\n";
        else cout<<"No\n";
    }
    else cout<<"No\n";
	return 0;
}

Measured memory_bytes: 3600
let rec f x=function|(0,0)->1|(n,_)when n<=0->0|(n,m)->(let rec(^)i a=if i>m||i>9then a else(i+1)^(a+f(i+1)(n-1,m-i))in x^0)and q()=Scanf.scanf"%d %d
"(fun n s->if n<>0||s<>0then q(Printf.printf"%d
"(f 0(n,s))));;q()

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

int dp[300000];

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

    vector<pair<int, int>> lr;
    rep(i, k) {
        int l, r;
        cin >> l >> r;
        lr.push_back({l, r + 1});
    }

    dp[0] = 1;
    dp[1] = -1;
    rep(i, n) {
        if (i > 0) dp[i] = (dp[i] + dp[i - 1]) % MOD;
        rep(j, k) {
            int l, r;
            tie(l, r) = lr[j];
            if (i + l < n) dp[i + l] = (dp[i + l] + dp[i]) % MOD;
            if (i + r < n) dp[i + r] = (dp[i + r] - dp[i] + MOD) % MOD;
        }
    }

    cout << dp[n - 1] << endl;
    return 0;
}


Measured memory_bytes: 4372
/// Code By t_bone_289 (Tushar Singh)
/// An Immature Programmer.... I'm still developing !!
#include<bits/stdc++.h>
using namespace std;
#define pll pair<ll,ll>
#define fi first
#define se second
#define mp make_pair
#define pb emplace_back
typedef long long ll;
typedef double d;
typedef long double ld;
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    string s;
    cin>>s;
    ll n;
    cin>>n;
    for(ll i=0;i<s.size();i+=n)
    {
        cout<<s[i];
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long ll;
typedef pair<ll, ll> P;
#define ALL(v) v.begin(),v.end()

const int MOD = 1000000007;
const int MAX = 5100000;
ll gcd(ll a, ll b) {
    return (b==0) ? a : gcd(b, a%b);
}

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
ll COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

// 以下から
const int MAX_N = 100000;
struct Edge {
    int to;
    int id;
};

int main(){
    ll n; cin >> n;
    vector<ll> v(n);
    rep(i,n) {
        cin >> v[i];
    }
    ll ans = 0;
    rep(i,60) {
        ll x = 0;
        rep(j,n) if (v[j] >> i & 1) x++;
        ll now = x * (n-x) % MOD;
        rep (j,i) {
            now = now * 2 % MOD;
        }
        ans += now;
        ans %= MOD;
    }

    cout << ans << endl;
}


Measured memory_bytes: 2560
#include<iostream>
#include<algorithm>
#include<math.h>
#include<vector>

using namespace std;

int main() {
    
    int N;
    cin >> N;
   
    string S;
    cin >> S;
    for (int i = 0; i < S.length(); i++){
        int  A = S[i] + N;
        
        if (A > 90) A -= 26;
        char B = A;
        cout << B;
    }





    return 0; 
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <random>
#include <chrono>
#include <tuple>
#include <random>

using namespace std;

typedef long long ll;
typedef long double ld;
#define fastInp cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);

const ll SIZE = 1e6 * 2 + 10, INF = 1e9 * 1e9 + 10;

int main()
{
    fastInp;

    ll x;
    cin >> x;

    cout << 10 - (x / 200);

    return 0;
}

Measured memory_bytes: 3644
abcd_origin = list(input())

for i in range(8):
    abcd = abcd_origin.copy()
    temp = []
    temp.append(abcd.pop(0))
    for j in range(3):
        if (i >> j) & 1:
            temp.append('+')
            temp.append(abcd.pop(0))
        else:
            temp.append('-')
            temp.append(abcd.pop(0))

    result = int(temp[0])

    for k in range(3):
        if temp[2 * k + 1] == '+':
            result += int(temp[2 * k + 2])
        else:
            result -= int(temp[2 * k + 2])

    if result == 7:
        equ = ''.join(temp) + '=7'
        print(equ)
        exit()


Measured memory_bytes: 9112
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

n,m,q = map(int,input().split())
E = [tuple(map(int,input().split())) for i in range(q)]
A = list(itertools.combinations_with_replacement(range(1,m+1),n))
for comb in A:
  tmp = 0
  for a,b,c,d in E:
    a-=1;b-=1
    if comb[b]-comb[a] == c:
      tmp += d
  ans = max(ans,tmp)
print(ans)

Measured memory_bytes: 21780
use std::io::*;
use std::str::FromStr;

#[allow(dead_code)]
fn get_line() -> String {
    let stdin = stdin();
    let mut line = String::new();
    stdin.lock().read_line(&mut line).expect("io error.");
    line.trim().to_string()
}

#[allow(dead_code)]
fn cast<T: FromStr>(s: &str) -> T {
    s.parse().ok().expect("parse error.")
}

#[allow(dead_code)]
fn get_word<T: FromStr>() -> T {
    cast(&get_line())
}

#[allow(dead_code)]
fn get_vec<T: FromStr>() -> Vec<T> {
    (&get_line()).split(' ').map(cast::<T>).collect()
}



/* ---------- ここまでテンプレ ---------- */


fn main() {
    let n: usize = get_word();

    let mut sv: Vec<String> = Vec::new();
    for i in 0..n {
        sv.push(get_line());
    }

    for i in 0..n {
        for j in i+1..n {
            if sv[i] == sv[j] {
                println!("No");
                return;
            }
        }
    }

    for i in 0..n-1 {
        if sv[i].chars().last().unwrap() != sv[i + 1].chars().next().unwrap() {
            println!("No");
            return;
        }
    }

    println!("Yes");
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const int MOD2 = 998244353;

int x[100010], zero = 0, half = 0;
map<int,int> mp, tmp, same;
int c[100010]; // 各k (mod m) に対して、同じ数のペアがいくつあるかをカウント

int main(){
    int n, m;
    cin >> n >> m;
    rep(i, n) cin >> x[i];

    rep(i, n){
        mp[x[i]%m]++;
        tmp[x[i]]++;
    }
    for(auto e : tmp){
        same[e.first%m] += e.second / 2;
        if (e.first%m == 0) zero += e.second;
        if (m%2 == 0 && e.first%m == m/2) half += e.second;
    }

    int ans = 0;
    ans += zero / 2;

    for(int k = 1; k <= m/2;  k++){
        if (m%2 == 0 && k == m/2) {
            ans += half / 2;
            continue;
        }
        int p, q;
        if (mp[k] <= mp[m-k]) p = k, q = m-k;
        else p = m-k, q = k;
        ans += mp[p];
        ans += min((mp[q] - mp[p]) / 2, same[q]);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 18036
#include <iostream>

using namespace std;

int main()
{
  int h, w;
  cin >> h >> w;
  for(int i = 1; i <= h; i++)
  {
	string token;
	for(int j = 1; j <= w; j++)
	{
	  cin >> token;
	  if("snuke" == token)
	  {
		cout << static_cast<char>('A' + j - 1) << i << endl;
	  }
	}
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/range/adaptors.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;
using namespace boost::adaptors;

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

    vector<int64_t> a(n);
    for (auto&& aa : a) {
        cin >> aa;
    }

    vector<int64_t> f(n);
    for (auto&& ff : f) {
        cin >> ff;
    }

    sort(a.begin(), a.end());
    sort(f.rbegin(), f.rend());

    int64_t score = 0;
    for (auto i : irange(0L, n)) {
        score = max(a[i] * f[i], score);
    }

    auto r = irange(0L, score + 1);
    auto aa = *partition_point(r.begin(), r.end(), [&](int64_t s) {
        vector<int64_t> c(n);
        for (auto i : irange(0L, n)) {
            c[i] = s / f[i];
        }

        int64_t kk = 0;
        for (auto i : irange(0L, n)) {
            kk += max(a[i] - c[i], 0L);
        }

        return !(kk <= k);
    });

    cout << aa << endl;
}

Measured memory_bytes: 4992
n = int(input())
A = list(map(int,input().split()))

L = [0]*(n+2)
R = [0]*(n+2)
L[n] = A[n]
R[n] = A[n]

for i in range(n,-1,-1):
  L[i] = A[i] + (L[i+1]+1)//2
  R[i] = A[i] + R[i+1]
  
if L[0]>1:
  print(-1)
else:
  tmp = 1
  ans = 0
  for i in range(n+1):
    ans += tmp
    tmp -= A[i]
    tmp = min(tmp*2,R[i+1])    
  print(ans)    

Measured memory_bytes: 22340
#include <iostream>
#include <algorithm>

using namespace std;

int main() {
    long long int N, A, B;
    cin >> N >> A >> B;
    
    if((B-A)%2) {
        cout << min((N-B+N-A+1)/2, (A-1+B)/2) << endl;
    } else {
        cout << (B-A)/2 << endl;
    }


    return 0;
    
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <set>
#include <vector>
#include <map>
#include <cstdio>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <cassert>
#include <climits>
using namespace std;
typedef long long ll;
#define DEBUG
#ifdef DEBUG
	#define debug printf
#else
	#define debug(...)
#endif
const int maxn = 55;
map< pair<ll,ll>,ll > mp;
ll x[maxn],y[maxn];
int main(int argc, char const *argv[])
{
	ll n;
	cin>>n;
	mp.clear();
	for(int i = 0;i < n; ++i)
	{
		scanf("%lld%lld",&x[i],&y[i]);
		mp[{x[i],y[i]}] = 1;
	}
	int ans = 0;
	for(int i = 0;i < n; ++i)
	{
		for(int j = 0;j < n; ++j)
		{
			if(i == j)
			{
				continue;
			}
			pair<ll,ll> add = {x[i] - x[j],y[i] - y[j]};
			int cnt = 0;
			for(int i = 0;i < n; ++i)
			{
				pair<ll,ll> now = {x[i] + add.first,y[i] + add.second};
				if(mp[now] == 1)
				{
					cnt++;
				}
			}
			ans = max(ans,cnt);
		}
	}
	printf("%lld\n",n - ans);
	return 0;
}

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

using namespace std;
typedef long long unsigned int ll;

#define PI (acos(-1))
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

int main(void){
    int n; cin >> n;
    int x; cin >> x;
    vector <int> ls;
    int l;
    int p = 0;
    int ans = 1;
    REP(i, n){
        cin >> l;
        p += l;
        if (p > x){
            break;
        }
        ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<string.h>
#include<complex>
#include<math.h>
using namespace std;
typedef long long int llint;
#define rep(i,n) for(int i=0;i<n;i++)

bool check(int a, int b) {
	return a > b;
}

int main() {
	int n, m;
	cin >> n >> m;
	if (n > m) {
		n = m;
	}
	vector<int>a(m);
	rep(i, m) {
		cin >> a[i];
	}
	sort(a.begin(), a.end());
	vector<int>b(m - 1);
	int ans = 0;
	rep(i, m - 1) {
		b[i] = a[i + 1] - a[i];
		ans += b[i];
	}
	sort(b.begin(), b.end(), check);
	rep(i, n - 1) {
		ans -= b[i];
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1024
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int A, B, ans = 0;
    cin >> A >> B;
    while (ans++ < 1000)
    {
        if ((int)(ans * 0.08)  == A && (int)(ans * 0.1) == B)
        {
            cout << ans << endl;
            return(0);
        }
    }
    cout << -1 << endl;
    return (0);
}

Measured memory_bytes: 888
#include <iostream>
#include <cstdio>
#include <string>
#include <cmath>
#include <algorithm>
using namespace std;

int main() {
    int n,x;
    while (1) {
        cin >> n >> x;
        if (n == 0 && x == 0) break;
        int m = 0;
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j < i; j++) {
                if (x - i - j < j && x-i-j>0) m++;
            }
        }
        cout << m << endl;
    }
        
    return 0;
}



        



Measured memory_bytes: 3092
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  int a=0,b;
  cin>>s;
  size_t size=s.length();
  for(int i=0;i<size;i++){
    if(s[i]=='A' && a==0) a=i+1;
    if(s[i]=='Z' && a!=0) b=i+1;
  }
  cout<<b-a+1<<"\n";
  return(0);
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#define INF 1e9+5
using namespace std;
int main(){
	int n,k;
	cin>>n>>k;
	int a[n],dp[n];
	for(int i=0;i<n;i++)cin>>a[i],dp[i]=INF;
	dp[0]=0;
	for(int i=0;i<n;i++){
		for(int j=i+1;j<=i+k&&j<n;j++)
		dp[j]=min(dp[j],abs(a[i]-a[j])+dp[i]);
	}
	cout<<dp[n-1];
}

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

#include <iostream>
//#include <algorithm>
// #include <iomanip>
#define ll long long
#define map unordered_map
#define set unordered_set
#define pll pair<ll, ll>
#define vll vector<ll>
#define mll map<ll, ll>

using namespace std;

const ll MOD = 1000000007LL;
const ll INF = (1LL << 60LL);

int main() {
  // std::cout << std::fixed << std::setprecision(10);
  ll N;
  scanf("%lld", &N);

  map<string, ll> m;
  for (ll i = 0; i < N; i++) {
    string s;
    cin >> s;

    m[s]++;
  }

  // AC x 10
  // WA x 0
  // TLE x 0
  // RE x 0

  cout << "AC x " << m["AC"] << endl;
  cout << "WA x " << m["WA"] << endl;
  cout << "TLE x " << m["TLE"] << endl;
  cout << "RE x " << m["RE"] << endl;
}


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

struct Point {
	double x,y;
}; 

void koch(int n,Point p1,Point p2)
{
	if(n==0) return ;
	Point s,t,u;
	double th = M_PI*60.0/180.0;
	
	s.x = (2.0*p1.x+1.0*p2.x)/3.0;
	t.x = (1.0*p1.x+2.0*p2.x)/3.0;
	s.y = (2.0*p1.y+1.0*p2.y)/3.0;
	t.y = (1.0*p1.y+2.0*p2.y)/3.0;
	
	u.x = (t.x - s.x)*cos(th)-(t.y - s.y)*sin(th)+s.x;
	u.y = (t.x - s.x)*sin(th)+(t.y - s.y)*cos(th)+s.y;
	
	koch(n-1,p1,s);
	printf("%.8lf %.8lf\n",s.x,s.y);
	koch(n-1,s,u);
	printf("%.8lf %.8lf\n",u.x,u.y);
	koch(n-1,u,t);
	printf("%.8lf %.8lf\n",t.x,t.y);
	koch(n-1,t,p2);
}
int main()
{
	Point a,b;
	int n;
	
	scanf("%d",&n);
	
	a.x = 0;
	a.y = 0;
	b.x = 100;
	b.y = 0;
	
	printf("%.8lf %.8lf\n",a.x,a.y);
	koch(n,a,b);
	printf("%.8lf %.8lf\n",b.x,b.y);
	
	return 0;
	
	
	
	
}


Measured memory_bytes: 3184
import java.util.*;
public class Main{
	static int a[],n,i,j,ans[],cnt;
	private static Scanner sc=new Scanner(System.in);
	public static void main(String[] args) {
		while (sc.hasNextInt()){
			int n=sc.nextInt();
			int a[]=new int[n];
			if(n==0)break;
			int ans[]=new int [n];
				for( i=0;i<n;i++){
					a[i]=sc.nextInt();
				}
				for(i=0;i<ans.length;i++){
					ans[i]=-100000;
				}
	//	for( i=0;i<n;i++){
		//	if(a[i]>0){
				for(i=0;i<n;i++){
					cnt=0;
				for(j=i;j<n;j++){
					cnt+=a[j];
				//	System.out.print(cnt);
					if(ans[i]<=cnt)ans[i]=cnt;
					}}
	//}
		
				Arrays.sort(ans);
				//for(int i=0;i<n;i++){
					System.out.println(ans[n-1]);
			//}	
		}
		
	}
}

Measured memory_bytes: 26468
#include <stdio.h>
#include <set>
#include <string>
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int main(){
    int n,k;
    scanf("%d %d", &n, &k);
    if(k * 2 -1  <= n){
        printf("YES");
        return 0;
    }
    printf("NO");

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define ff              first
#define ss              second
#define int             long long
#define in              insert
#define pb              push_back
#define mp              make_pair
#define lb              lower_bound
#define ub              upper_bound
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n]
#define w(x)            int x; cin>>x; while(x--)
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

int32_t main()
{
	FIO;
	int h, w; cin >> h >> w;
	char grid[h][w];
	for (int i = 0; i < h; i++)
		for (int j = 0; j < w; j++)
			cin >> grid[i][j];

	vector<vi> dp(h, vi(w, 1));

	for (int i = 0; i < h; i++)
		for (int j = 0; j < w; j++) {
			if (grid[i][j] == '#')
				dp[i][j] = 0;
			else if (i == 0 && j)
				dp[i][j] = dp[i][j - 1];
			else if (j == 0 && i)
				dp[i][j] = dp[i - 1][j];
			else if (i && j)
				dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % mod;
		}

	cout << dp[h - 1][w - 1] << endl;

	return 0;
}

Measured memory_bytes: 12156
#include<stdio.h>
int main(void)
{
	double a, b;
	scanf("%lf %lf", &a, &b);
	if(a>b){printf("a > b\n");}
	else{if(a ==b){printf("a == b\n");}
	else{printf("a < b\n");}}
	return 0;
}

Measured memory_bytes: 1036
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;

int main(void)
{
	int n, num;
	string str;
	long long a;
	
	while (cin >> n, n){
		map <string, long long> m;
		vector <string> data;
		for (int i = 0; i < n; i++){
			cin >> str >> num >> a;
			if (!m[str]) data.push_back(str);
			m[str] += (num * a);
		}
		bool flag = true;
		for (int i = 0; i < data.size(); i++){
			if (1000000 <= m[data[i]]){
				cout << data[i] << endl;
				flag = false;
			}
		}
		if (flag) cout << "NA" << endl;
	}
	
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
using ll = long long;
using vin=vector<int>;
using vll=vector<ll>;
using P = pair<int, int>;
const int inf=1e9+7;
const ll INF=1e18;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

int main() {
 int n;
  cin>>n;
 string s;
  cin>>s;
  int dp[220000];
  rep(i,0,n) dp[i]=0;//i番目（ふくむ）より右が黒にする必要数
  int ans=inf;
  rep(i,0,n){
   if(s[i]=='.') dp[0]++; 
  }
  rep(i,1,n+1){
    if(s[i-1]=='#'){
      dp[i]=dp[i-1]+1;
      
    }
    else{
     dp[i]=dp[i-1]-1; 
    }
  }
  
  rep(i,0,n+1){
    ans=min(ans,dp[i]);
  }
  
    cout<<ans<<endl;                 
}

Measured memory_bytes: 4548
#include <bits/stdc++.h>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
#define pi 3.14159265358979323846264338327950L
using namespace std;

int main() {
  string N;
  cin >> N;
  int S=N.size(), A, K=0, ans;
  if (N[0]=='1') {
    A=1;
  }
  else if (N[0]=='2') {
    A=2;
  }
  else if (N[0]=='3') {
    A=3;
  }
  else if (N[0]=='4') {
    A=4;
  }
  else if (N[0]=='5') {
    A=5;
  }
  else if (N[0]=='6') {
    A=6;
  }
  else if (N[0]=='7') {
    A=7;
  }
  else if (N[0]=='8') {
    A=8;
  }
  else {
    A=9;
  }
  ans=A+9*(S-1)-1;
  if (S==1) {
    ans=A;
  }
  else {
    for (int i=1; i<S; i++) {
      if (N[i]=='9') {
        K++;
      }
    }
    if (K==S-1) {
      ans=A+9*K;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3576
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s,t,tem;
    cin>>s>>t;
    tem=t.substr(0,s.size());
    if(tem==s)
        cout<<"Yes";
    else
        cout<<"No";
    cout<<"\n";
    return 0;
}


Measured memory_bytes: 3584
### https://note.nkmk.me/python-union-find/

class UnionFind():
  def __init__(self, n):
    self.n = n
    self.parents = [-1] * n 
    # 各要素の親要素の番号を格納するリスト 
    # 要素が根（ルート）の場合は-(そのグループの要素数)を格納する

  def find(self, x): # 要素xが属するグループの根を返す
    if self.parents[x] < 0:
      return x
    else:
      self.parents[x] = self.find(self.parents[x])
      return self.parents[x]

  def union(self, x, y): # 要素xが属するグループと要素yが属するグループとを併合する
    x = self.find(x)
    y = self.find(y)

    if x == y:
      return

    if self.parents[x] > self.parents[y]:
      x, y = y, x

    self.parents[x] += self.parents[y]
    self.parents[y] = x

  def size(self, x): # 要素xが属するグループのサイズ（要素数）を返す
    return -self.parents[self.find(x)]

  def same(self, x, y): # 要素x, yが同じグループに属するかどうかを返す
    return self.find(x) == self.find(y)

  def members(self, x): # 要素xが属するグループに属する要素をリストで返す
    root = self.find(x)
    return [i for i in range(self.n) if self.find(i) == root]

  def roots(self): # すべての根の要素をリストで返す
    return [i for i, x in enumerate(self.parents) if x < 0]

  def group_count(self): #グループの数を返す
    return len(self.roots())

  def all_group_members(self): #{ルート要素: [そのグループに含まれる要素のリスト], ...}の辞書を返す
    return {r: self.members(r) for r in self.roots()}

  def __str__(self):
    return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
    #print()での表示用
    #ルート要素: [そのグループに含まれる要素のリスト]を文字列で返す

N, M = map(int, input().split())
friends = UnionFind(N)
for _ in range(M):
  A, B = map(int, input().split())
  A -= 1
  B -= 1
  friends.union(A, B)
x = friends.roots()
ans = 0
for k in x:
  y = friends.size(k)
  ans = max(ans,y)
print(ans)

Measured memory_bytes: 82480
import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n = int(readline())
    a = list(map(int, readline().split()))
    cnt = 0
    for v in a:
        if v % 2 != 0:
            cnt += 1
    print("YES" if cnt % 2 == 0 else "NO")


if __name__ == '__main__':
    solve()


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

int main()
{
    int n;
    cin >> n;
    int a=0;
    int b=0;
    int ab=0;
    string s;
    bool x;	
  	int y;    //y b~a
    x=false;
    y=0;
    for(int i=0;i<n;i++){
        x=false;
    	cin >> s;
        for(int j=0;j<s.length()-1;j++){
        	if(s[j]=='A' && s[j+1]=='B'){ab++;}
        }
        if(s.front()=='B'){
        	b++;
            x=true;
        }
        if(s.back()=='A'){
        	a++;
            if(x){y++;}
        }
    }  
    long long k;
    if(y==a&&y==b){
    	k=y-1;
        if(y==0){
        	k=0;
        }
    }else{
        k=min(a,b);
    }
    cout << ab+k << endl;
}

Measured memory_bytes: 256
import sys
def main():
    input = sys.stdin.readline
    N=int(input())
    A=[int(input()) for _ in range(N)]
    from collections import Counter
    C=Counter(A)
    ans=0
    for v in C.values():
        if v&1: ans+=1
    print(ans)


if __name__ == '__main__':
    main()

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

int main() {
  int N,m,sum;
  cin >> N;
  m = N;
  for(int i=0;i<8;i++){
    int l;
    l = m % 10;
    m = (m-l)/10;
    sum += l;
  }
  if(N%sum == 0){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<climits>
#include<vector>
#include<list>
#include<functional>
#include<algorithm>
#include<string>
#include<cmath>
#include<complex>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<tuple>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;



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

	int a;
	string s;
	cin >> a >> s;
	if (a >= 3200) cout << s << endl;
	else cout << "red\n";

	return 0;
}


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

// 1-indexed, 100000頂点以下で統一
#define MAX_SIZE 100000
vector<pair<int, int>> v[MAX_SIZE+1];

int main() {
    int N;
    cin >> N;
    for (int i = 0; i < N - 1; ++i) {
        int a,b,c;
        cin >> a >> b >> c;
        v[a].push_back(make_pair(b,c));
        v[b].push_back(make_pair(a,c));
    }

    vector<int> ans(N+1, -1);
    stack<int> s;
    s.push(1);
    ans[1] = 0;

    while(! s.empty()){
        int t = s.top();
        s.pop();
        for(auto x: v[t]){
            if(ans[x.first] == -1){
                ans[x.first] = (ans[t] + x.second) % 2;
                s.push(x.first);
            }
        }
    }

    for (int i = 1; i < N+1; ++i) {
        cout << ans[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 7672
#include <stdio.h>

int main() {
  long long int a, b, x, c1, c2;
  scanf("%lld %lld %lld", &a, &b, &x);
  if (a == 0) {
    c1 = -1;
  } else {
    c1 = (a - 1) / x;
  }
  if (b == 0) {
    c2 = 0;
  } else {
    c2 = b / x;
  }

  printf("%lld\n", c2 - c1);
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
string b[1000000];
bool cmp(string a, string b){
    return a < b;
}
int main(){
    int n,l;
    cin >> n >> l;
    for(int i = 1;i <= n;++i)
        cin >> b[i];
    sort(b + 1,b + 1 + n,cmp);
    for(int i = 1;i <= n;++i)
        cout << b[i];
    return 0;
}

Measured memory_bytes: 8064
#include <stdio.h>
#include <algorithm>


int a[100000 + 5];
int n;

int main()
{
    scanf("%d", &n);
    for (int i = 0; i < n; ++ i) {
        int x;
        scanf("%d", &x); ++ x;
        a[x] ++;
        a[x - 1] ++;
        a[x + 1] ++;
    }
    printf("%d\n", *std::max_element(a, a + 100000 + 2));
}


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

using namespace std;

const int Nmax = 3e5+5;
int x, y, z, i;
long long money = 0;

struct om
{
    int g, s, b;
} a[Nmax];

bool cmp1(om a, om b)
{
    return a.g + b.s > b.g + a.s;
}

long long ans[Nmax], sum = 0;
priority_queue < int, vector<int>, greater<int> > heap;


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

    cin >> x >> y >> z;
    for(i=1; i<=x+y+z; ++i) cin >> a[i].g >> a[i].s >> a[i].b;

    sort(a+1, a+x+y+z+1, cmp1);

    for(i=1; i<=x+z; ++i)
    {
        heap.push(a[i].g - a[i].b);
        ans[i] = ans[i-1] + a[i].g;

        if(heap.size() > x)
        {
            ans[i] -= heap.top();
            heap.pop();
        }
    }

    while(!heap.empty()) heap.pop();

    for(i=x+y+z; i>x; --i)
    {
        heap.push(a[i].s - a[i].b);
        sum += a[i].s;

        if(heap.size() > y)
        {
            sum -= heap.top();
            heap.pop();
        }

        if(i<=x+z+1) money = max(money, sum + ans[i-1]);
    }

    cout << money << '\n';

    return 0;
}


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

int main(){
    int A,B,C;
    cin >> A >> B >> C;
    int current_coin = 0;
    int is_sunday = 0;
    while(current_coin < C){
        is_sunday++;
        current_coin += A;
        if(is_sunday%7 == 0) current_coin += B;
    }
    cout << is_sunday << endl;
    return 0;
}


Measured memory_bytes: 3104
#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define st first
#define nd second
#define pii pair<int,int>

using namespace std;


const int nax = 3e5 + 5;
int r[nax];
int c[nax];

int n,m;

set<pii> s;

int rmax = 0;
int cmax = 0;

vector<int> rows,cols;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin>>n>>m;
    int q; cin>>q;
    while(q--)
    {
        int x,y; cin>>x>>y;
        s.insert({x,y});
        r[x]++; c[y]++;
    }
    for(int i=1;i<nax;i++)
    {
        int akt = r[i];
        if(akt > rmax)
        {
            rmax = akt;
            rows.clear();
            rows.pb(i);
        }
        else if(akt == rmax) rows.pb(i);
    }
    for(int i=1;i<nax;i++)
    {
        int akt = c[i];
        if(akt > cmax)
        {
            cmax = akt;
            cols.clear();
            cols.pb(i);
        }
        else if(akt == cmax) cols.pb(i);
    }
    int ans = rmax + cmax - 1;
    bool ok = true;
    for(auto x : rows)
    {
        if(!ok) break;
        for(auto y : cols)
        {
            if(s.count({x,y}) == 0)
            {
                ans++;
                ok = false;
                break;
            }
        }
    }
    cout<<ans;


    return 0;
}


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

using namespace std;

bool cmp (pair<long long, int> i,pair<long long, int> j) {
    return (i.first<j.first);
}
int main(int argc, const char * argv[]) {
    int N;
    int M;
    cin >> N >> M;
    
    vector<pair<long long,int>> AB;
    AB.assign(N, pair<long long, int>(0, 0));
    
    for (int i = 0; i < N; i++) {
        cin >> AB[i].first >> AB[i].second;
    }
    
    sort(AB.begin(),AB.end(),cmp);
    
    long long ans = 0;
    for (int i = 0; i < N; i++) {
        if (M >= AB[i].second) {
            ans = ans + AB[i].first*AB[i].second;
            M = M - AB[i].second;
        } else {
            ans = ans + AB[i].first*M;
            break;
        }
    }
    
    cout << ans;
    
    return 0;
}

Measured memory_bytes: 1792
import java.util.*;
import java.math.*;
public class Main {
	public static void main(String[] args){
		
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
      
        if((B-1)%(A-1)!=0){System.out.println((B-1)/(A-1)+1);}
      else{System.out.println((B-1)/(A-1));}
   
	}
}

Measured memory_bytes: 35524
#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];

	vector<int> L(n+1);
	vector<int> R(n+1);

	L[0] = 0;
	R[n] = 0;

	for(int i=0; i<n; i++) L[i+1] = __gcd(L[i],a[i]);
	for(int i=n-1; i>=0; i--) R[i] = __gcd(R[i+1],a[i]);
	
	vector<int> M(n);
	for(int i=0; i<n; i++) M[i] = __gcd(L[i],R[i+1]);

	cout << *max_element(M.begin(), M.end()) << endl;

}

Measured memory_bytes: 4848
#include <bits/stdc++.h>
#define rep(a,b) for(int a=0; a<b; ++a)
#define ran(a,b) for(auto &a:b)
#define all(v) v.begin(),v.end()
using namespace std;

template<typename T>
using pq = priority_queue<T>;
template<typename T>
using rpq = priority_queue<T,vector<T>,greater<T>>;
template<typename T>
using vec = vector<T>;

using ll = long long;
using pi = pair<int,int>;
using ti = tuple<int,int,int>;
using tup = tuple<string,int,int>;

ll MOD=1000000007;

int main(){
	int X; cin>>X;
	int t=-1; int sum=0;
	while(sum<X){
		++t;
		sum=t*(t+1)/2;
	}
	cout<<t<<endl;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**6)

n = int(input())

neighbor = [[] for _ in range(n + 1)]

for i in range(n - 1):
    x, y = map(int, input().split())
    neighbor[y].append(x)
    neighbor[x].append(y)

mod = 10**9 + 7
dp = [[0] * 2 for _ in range(n + 1)]


def dfs(i, bw, p):
    if dp[i][bw] != 0:
        return dp[i][bw]

    dp[i][bw] = 1
    for j in neighbor[i]:
        if j == p:
            continue

        if bw == 0:  # black
            dp[i][0] = (dp[i][0] * dfs(j, 1, i)) % mod
        else:  # white
            dp[i][1] = (dp[i][1] * (dfs(j, 0, i) + dfs(j, 1, i))) % mod

    return dp[i][bw]


print((dfs(1, 0, 0) + dfs(1, 1, 0)) % mod)


Measured memory_bytes: 110132
n = int(raw_input())
a = map(int, raw_input().split())
sm = 0
h = len(a) / 2

while h > 0:
	for x in xrange(0,len(a)):
		y = x
		tmp = a[y]
		while y - h >= 0 and a[y-h] > tmp:
			a[y] = a[y-h]
			y = y - h
		a[y] = tmp
		
	if h == 1:
		h = 0
	elif h / 2 != 0:
		h = h / 2
	else:
		h = 1

for x in xrange(0,len(a)):
	sm = sm + a[x]

print a[0], a[len(a)-1], sm

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

using namespace std;

#define G_MAX   50
int graph[G_MAX + 1][G_MAX + 1];
int visit[G_MAX + 1];
int N, M;

void dfs(int n);        // 連結かどうかを調べる深さ優先探索

int main(void){
    vector <int> a, b;
    int sub;
    int cnt = 0;
    
    cin >> N >> M;
    for(int i = 0; i < M; i++){
        cin >> sub;
        a.push_back(sub);
        cin >> sub;
        b.push_back(sub);
    }
    
    // 隣接行列の作成
    for(int i = 0; i < M; i++){
        graph[a[i]][b[i]] = 1;
        graph[b[i]][a[i]] = 1;
    }
    
    for(int i = 0; i < M; i++){
        graph[a[i]][b[i]] = 0;
        graph[b[i]][a[i]] = 0;      // 辺を取り除いてそれが橋であったかを調べる
        
        for(int j = 1; j <= N; j++){
            visit[j] = 0;
        }
        
        dfs(1);
        
        bool bridge = false;
        for(int j = 1; j <= N; j++){
            if(visit[j] == 0)       bridge = true;
        }
        if(bridge)      cnt++;
        
        graph[a[i]][b[i]] = 1;
        graph[b[i]][a[i]] = 1;      // 処理が終われば元に戻す
    }
    
    cout << cnt << endl;
}

void dfs(int n){        // ある点から始めて、連結ならば訪問済みフラグを立てる　それができなければ非連結と判定
    visit[n] = 1;
    
    for(int x = 1; x <= N; x++){
        if(graph[n][x] == 0)        continue;
        if(visit[x] == 1)           continue;
        dfs(x);
    }
}

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

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

#ifdef DEBUG
    #define IFD if(true)
#else
    #define IFD if(false)
#endif

#define MOD 1000000007

#include <iostream>
#include <sstream>
#include <vector>

template<typename T_bit_data>
class BIT
{
private:
    int cnt; // 実際の要素数
    std::vector<T_bit_data>* data; // データ本体
public:
    BIT(int n)
    {
        cnt = n;
        data = new std::vector<T_bit_data>(cnt + 1);
    }

    virtual ~BIT() { delete data; }

    T_bit_data Sum(int k)
    {
        if(k <= 0 || cnt < k) {
            std::ostringstream s;
            s << "k = " << k;
            throw std::out_of_range(s.str());
        }
        T_bit_data s = 0;
        while(k > 0) {
            s += (*data)[k];
            // 1 であるビットのうち一番下のビットを 0 に
            k -= k & -k; // 目的の 1 であるビットは k & -k で取り出せる
        }
        return s;
    }

    void Add(int k, T_bit_data a)
    {
        if(k <= 0 || cnt < k) {
            std::ostringstream s;
            s << k << " -> " << a;
            throw std::out_of_range(s.str());
        }
        while(k <= cnt) {
            (*data)[k] += a;
            k += k & -k;
        }
    }

    void Show()
    {
        for(int i = 1; i <= cnt; i++) {
            std::cout << (*data)[i] << " ";
        }
        std::cout << std::endl;
    }
};

int main()
{
    int N, K;
    cin >> N >> K;

    vector<int> A(N);
    rep(n, N) {
        cin >> A[n];
    }

    BIT<int> bit(2000);
    ll ans = 0;
    rep(i, N) {
        ans += i - bit.Sum(A[i]);
        bit.Add(A[i], 1);
    }
    ans = (ans * (ll)K) % MOD;

    ll m = ((ll)K * (ll)(K - 1) / 2) % MOD;
    rep(i, N) {
        ans = (ans + (ll)(N - bit.Sum(A[i])) * m % MOD) % MOD;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <set>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define INF int(1e9)
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define REPONE(i, n) for(int i = 1; i <= (int)(n); i++)
#define EACH(i, mp) for(auto i:mp)
#define FOR(i, m, n) for(int i = m;i < n;i++)
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

ll A, B, C;
ll K;

int main() {
    cin >> A >> B >> C >> K;
    if (K % 2 == 0) cout << A - B << endl;
    else cout << B - A << endl;
    return 0;
}

Measured memory_bytes: 256