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

const int64_t MOD = 1e9+7;
void add(int64_t& a, int64_t b){
    a = (a+b) % MOD;
}
void mul(int64_t& a, int64_t b){
    a = a*b % MOD;
}

vector<int64_t> fact, seq_inv, fact_inv;

void create_fact_mod(int num){
    fact[0] = fact[1] = 1;
    for(int i=2; i<=num; i++) fact[i] = fact[i-1] * i % MOD;
}

void create_seq_inv_mod(int num){
    seq_inv[0] = seq_inv[1] = 1;
    for(int i=2; i<=num; i++) seq_inv[i] = (MOD - MOD/i) * seq_inv[MOD%i] % MOD;
}

void create_fact_inv_mod(int num){
    fact_inv[0] = fact_inv[1] = 1;
    for(int i=2; i<=num; i++) fact_inv[i] = fact_inv[i-1] * seq_inv[i] % MOD;
}

void create_mod_tables(int num){
    fact.resize(num+1);
    seq_inv.resize(num+1);
    fact_inv.resize(num+1);
    create_fact_mod(num);
    create_seq_inv_mod(num);
    create_fact_inv_mod(num);
}

int64_t comb_mod(int n, int k){
    return fact[n] * fact_inv[n-k] % MOD * fact_inv[k] % MOD;
}

int64_t perm_mod(int n, int k){
    return fact[n] * fact_inv[n-k] % MOD;
}

int64_t power_mod(int64_t num, int64_t power){
    int64_t prod = 1;
    num %= MOD;
    while(power > 0){
        if(power&1) prod = prod * num % MOD;
        num = num * num % MOD;
        power >>= 1;
    }
    return prod;
}

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

int64_t inv_mod(int64_t a){
    int64_t x, y;
    extgcd(a, MOD, x, y);
    return (MOD + x%MOD) % MOD;
}

int main(){
    int N, X;
    cin >> N >> X;
    vector<int> L(N);
    for(int i=0; i<N; i++) cin >> L[i];
    sort(L.begin(), L.end());
    create_mod_tables(2*X);
    
    const int M = 510;
    static int64_t pre[M][M][M];
    for(int n=0; n<=X; n++) for(int s=0; s<=X; s++) pre[0][n][s] = 1;
    for(int i=0; i<N; i++) for(int n=0; n<=X; n++) for(int s=0; s<=X; s++){
        pre[i+1][n][s] = max(1, s-(L[i]-1)*n) * pre[i][n][s] % MOD;
    }

    static int64_t dp[2][M][M][2];
    dp[X%2][0][0][0] = 1;
    int pt = N-1;
    for(int x=X; x>0; x--){
        while(pt >= 0 && L[pt] > x) pt--;
        for(int n=0; n<=X; n++) for(int s=0; s<=X; s++) for(int f=0; f<2; f++){
            int64_t bef = dp[x%2][n][s][f];
            if(bef == 0) continue;
            if(f == 0 && pt < N-1) continue;
            mul(bef, inv_mod(pre[pt+1][n][s]));
            for(int k=0; s+x*k<=X; k++){
                int n2 = n+k, s2 = s+x*k, f2 = f|(k>0);
                int64_t res = bef * pre[pt+1][n2][s2] % MOD * comb_mod(n2, k) % MOD;
                add(dp[(x-1)%2][n2][s2][f2], res);
            }
        }
        for(int n=0; n<=X; n++) for(int s=0; s<=X; s++) for(int f=0; f<2; f++) dp[x%2][n][s][f] = 0;
    }

    int64_t ans = 0;
    for(int n=1; n<=X; n++) for(int s=0; s<=X; s++){
        int rest = X-s-(n-1);
        if(rest < 0) continue;
        int64_t res = comb_mod(rest+n, n) * dp[0][n][s][1] % MOD;
        int blank = X-s;
        if(blank%2) res = MOD-res;
        add(ans, res);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 215296
#include<iostream>
using namespace std;
int main()
{
	int w, h, n, x, y, a;
	cin >> w >> h >> n;
	int xmin = 0, xmax = w, ymin = 0, ymax = h;
	for(int i = 0; i < n; i++){
		cin >> x >> y >> a;
		if(a == 1) xmin = max(xmin, x);
		if(a == 2) xmax = min(xmax, x);
		if(a == 3) ymin = max(ymin, y);
		if(a == 4) ymax = min(ymax, y);
	}
	int xx = xmax - xmin;
	int yy = ymax - ymin;
	cout << (xx > 0 && yy > 0 ? xx * yy : 0) << endl;
	return 0;
}

Measured memory_bytes: 256
n, a, b = map(int, input().split())
s = input()

all = list(s)
count = 0
count_b = 0
for i in all:
    if i == 'a':
        if count < a + b:
            print('Yes')
            count += 1
        else:
            print('No')
    elif i == 'b':
        if (count < a + b) and (count_b < b):
            print('Yes')
            count += 1
            count_b += 1
        else:
            print('No')
    else:
        print('No')


Measured memory_bytes: 4784
import sys

sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return list(map(int, sys.stdin.readline().split()))
def II(): return int(sys.stdin.readline())
def LS(): return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]

def main():
    n = II()
    a_s = LI()
    b_s = LI()
    b_s.append(0)
    ans = 0
    ans += min(a_s[0], b_s[0])
    for i in range(n):
        r = max(b_s[i] - a_s[i], 0)
        # print(a_s, b_s, b_s[i] - a_s[i], a_s[i+1], r)
        if r > a_s[i+1]:
            ans += a_s[i+1]
        else:
            ans += r
        a_s[i+1] = max(a_s[i+1] - r, 0)
        ans += min(a_s[i+1], b_s[i+1])
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 19376
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
 
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef unsigned long long ull;
typedef long double ld; 
typedef tree<ii, null_type, less<ii>, rb_tree_tag, tree_order_statistics_node_update> pbds;

vi J[222222];
ll ans[222222];
int cnt[222222];
set<ii> S;

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n,k; cin>>n>>k;
	for(int i=0;i<n;i++)
	{
		int c,v; cin>>c>>v; c--;
		J[c].pb(v);
	}
	set<ii> unused;
	vector<ii> jewels;
	for(int i=0;i<k;i++)
	{
		sort(J[i].rbegin(),J[i].rend());
		for(int j=0;j<J[i].size();j++)
		{
			if(j<=1)
			{
				jewels.pb(mp(J[i][0]+J[i][1],i));
			}
			else
			{
				jewels.pb(mp(J[i][j]*2,i));
			}
		}
		ll s=J[i][0]+J[i][1];
		J[i][0]=J[i][1]=s;
		for(int j=2;j<J[i].size();j++) J[i][j]<<=1;
		if(J[i].size()>=3)
		{
			S.insert({J[i][0]+J[i][1]+J[i][2], i});
		}
	}
	sort(jewels.rbegin(),jewels.rend());
	memset(ans,-1,sizeof(ans));
	ll sum=jewels[0].fi;
	set<ii> exact2;
	set<ii> weakest;
	set<ii> weakest2;
	for(int i=2;i<=n;i++)
	{
		sum+=jewels[i-1].fi;
		//add jewels[i-2] to the front
		{
			int id=jewels[i-2].se;
			cnt[id]++;
			if(cnt[id]==2)
			{
				exact2.insert({J[id][0]+J[id][1],id});
				for(int j=2;j<J[id].size();j++) unused.insert({J[id][j],id});
			}
			else if(cnt[id]==3)
			{
				weakest.insert(mp(J[id][cnt[id]-1],id));
				exact2.erase({J[id][0]+J[id][1],id});
			}
			else if(cnt[id]>=4)
			{
				weakest.erase(mp(J[id][cnt[id]-2],id));
				weakest.insert(mp(J[id][cnt[id]-1],id));
				if(cnt[id]>4) weakest2.erase({J[id][cnt[id]-3]+J[id][cnt[id]-2],id});
				weakest2.insert({J[id][cnt[id]-1]+J[id][cnt[id]-2],id});
			}
		}
		//remove jewels[i-2] from "back"
		{
			int id = jewels[i-2].se;
			if(J[id].size()>=3)
			{
				S.erase({J[id][0]+J[id][1]+J[id][2],id});
			}
			if(cnt[id]>2)
			{
				unused.erase({J[id][cnt[id]-1],id});
			}
		}
		if(!(cnt[jewels[i-1].se]==0&&jewels[i-1].se==jewels[i].se))
		{
			ans[i]=sum;
		}
		else
		{
			if(!unused.empty())
			{
				ans[i]=max(ans[i],sum-jewels[i].fi+(*prev(unused.end())).fi);
			}
			if(!weakest.empty())
			{
				ans[i]=max(ans[i],sum+jewels[i].fi-(*weakest.begin()).fi);
			}
			if(!exact2.empty()&&!S.empty())
			{
				//cerr<<i<<' '<<sum<<' '<<jewels[i-1].fi<<' '<<(*exact2.begin()).fi<<' '<<(*prev(S.end())).fi<<'\n';
				ans[i]=max(ans[i],sum-jewels[i-1].fi-(*exact2.begin()).fi+(*prev(S.end())).fi);
			}
			if(!weakest2.empty()&&!S.empty())
			{
				ans[i]=max(ans[i],sum-jewels[i-1].fi-(*weakest2.begin()).fi+(*prev(S.end())).fi);
			}
		}
		
	}
	for(int i=1;i<=n;i++)
	{
		if(ans[i]!=-1) ans[i]>>=1;
		cout<<ans[i]<<'\n';
	}
}


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

int main(){
  int n,mx=-1,nm=0;
  cin>>n;
  vector<int>d(n);
  for(int i=0;i<n;i++){
    cin>>d[i];
  }
  for(int i=0;i<n;i++){
    mx=max(mx,d[i]);
    nm+=d[i];
  }
  cout<<nm-mx/2<<endl;
}
  


Measured memory_bytes: 256
n = int(input())
ab = [list(map(int, input().split())) for _ in range(n)]

a, b = map(list, zip(*ab))
a.sort()
b.sort()

if n % 2:
    i = (n + 1) // 2 - 1
    mn = a[i]
    mx = b[i]

else:
    i1, i2 = n // 2 - 1, n // 2
    mn = a[i1] + a[i2]
    mx = b[i1] + b[i2]

ans = mx - mn + 1
print(ans)


Measured memory_bytes: 61072
#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define repreverse(i, start, end) for (long long i = start; i >= end; --i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define len(x) ((long long)(x).size())
#define lcm(a, b) ((a) / __gcd((a), (b)) * (b))
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vllvll = vector<vll>;
using vc = vector<char>;
using pll = pair<ll, ll>;
template<class T> void print1d(T x,ll n=-1){if(n==-1)n=x.size();rep(i,0,n){cout<<x[i]<<' ';}cout<<'\n';}
template<class T> void print2d(T x,ll r=-1,ll c=-1){if(r==-1)r=x.size();if(c==-1)c=x[0].size();rep(i,0,r)print1d(x[i],c);}
template<class T, class U> bool haskey(T mp, U key) { return mp.find(key) != mp.end(); }
template<class T, class U> bool isin(T el, U container) { return find(all(container), el) != container.end(); }
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; }
template<class T> bool even(T n) { return ! (n & 1); }
template<class T> bool odd(T n) { return n & 1; }
template<class T> ll rup(T a, T b) { return a % b ? a / b + 1 : a / b; }
template<class T> ld deg2rad(T deg) { return M_PI * deg / 180.0; }
template<class T> ld rad2deg(T rad) { return 180.0 * rad / M_PI; }
const long double pi = M_PI;
const long long big = 1LL << 50;
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;
ll intpow(ll a, ll n, ll _mod=numeric_limits<ll>::max()) { ll p=1; while (n) { if (n&1) p=p*a%_mod; a=a*a%_mod; n>>=1; } return p; } 
ll modc(ll a, char op, ll b, ll _mod=mod)
{
        a %= _mod; b %= _mod; ll res = 1;
        switch (op) {
        case '+': res = (a + b) % _mod; break;
        case '-': res = (a - b) % _mod; break;
        case '*': res = a * b % _mod; break;
        case '/': res = modc(a, '*', modc(b, '^', _mod-2, _mod), _mod); break;
        case '^': res = intpow(a, b, _mod); break;
        case 'P': rep(i, a-b+1, a+1) res = modc(res, '*', i, _mod); break;
        case 'C': res = modc(modc(a, 'P', b, _mod), '/', modc(b, 'P', b, _mod)); break;
        } 
        if (res < 0) { res += _mod; } return res;
}

vllvll ans;
ll N, M, Q;

void rec(vll v, ll a, ll cur)
{
    if (a > M) return;
    if (cur == N) {
        ans.push_back(v);
        return;
    }

    v.push_back(a);

    rep(i, 0, M+1) {
        rec(v, a+i, cur+1);
    }
}

int main()
{
    cin >> N >> M >> Q;
    vll tmp;
    rep(i, 1, M+1) rec(tmp, i, 0);    

    vll a(Q), b(Q), c(Q), d(Q);
    rep(i, 0, Q) {
        cin >> a[i] >> b[i] >> c[i] >> d[i];
    }

    ll mx = -inf;
    rep(i, 0, len(ans)) {
        ll sc = 0;
        rep(j, 0, Q)
            if (ans[i][b[j]-1] - ans[i][a[j]-1] == c[j]) {
                sc += d[j];
            }

        chmax(mx, sc);
    }

    cout << mx << endl;
}


Measured memory_bytes: 22920
open Batteries
open BatPervasives
open Printf

let scan fmt f =
  Scanf.sscanf (read_line ()) fmt f

let scan_list cnv =
  read_line ()
  |> BatString.split_on_char ' '
  |> List.map cnv

let (n, k) = scan "%d %d" BatTuple.Tuple2.make
let ps = scan_list float_of_string

let exp n = n *. (n +. 1.0) /. 2.0 /. n

let rec zip xs = function
  | [] -> []
  | y::ys ->
    match xs with
    | [] -> []
    | z::zs -> (z, y)::zip zs ys

let rec hold_max m p = function
  | [] -> m
  | (x, y)::sumss ->
    let n = p -. x +. y in
    hold_max (if m > n then m else n) n sumss

let () =
  let sums = List.map exp ps in
  let init = BatList.fsum @@ BatList.take k sums in
  hold_max init init (zip sums @@ BatList.drop k sums)
  |> printf "%f\n"


Measured memory_bytes: 36992
#include <cmath>
#include <climits>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>

using namespace std;

int main(){
  int i,j;
  priority_queue<int,vector<int>,greater<int> > ql;
  priority_queue<int> qr;
  int n;
  cin >> n;
  vector<int> v(3*n);
  for(int i = 0;i < v.size();i++) cin >> v[i];
  vector<long long> dr(n+1,0),dl(n+1,0);
  for(int i = 0;i < n;i++){
    dl[0] += v[i];
    ql.push(v[i]);
    dr[n] += v[i+2*n];
    qr.push(v[i+2*n]);
  }
  for(int i = 0;i < n;i++){
    ql.push(v[i+n]);
    dl[i+1] = dl[i]+v[i+n]-ql.top();
    ql.pop();
  }
  for(int i = n-1;i >= 0;i--){
    qr.push(v[i+n]);
    dr[i] = dr[i+1]+v[i+n]-qr.top();
    qr.pop();
  }
  long long ans = LLONG_MIN;
  for(int i = 0;i <= n;i++){
    if(ans < dl[i]-dr[i]) ans = dl[i]-dr[i];
  }
  cout << ans << endl;
}


Measured memory_bytes: 3964
#include <bits/stdc++.h>
using namespace std;
 
int main(){
 
int N, A;
  cin >> N;
int cnt = 0;  
  
  map<int,bool> mp;
  
  for(int i = 0;i < N;i++){
  cin >> A;
    if(mp[A]){
    mp[A] = false;
    cnt--;  
    }
    else{
    mp[A] = true;
    cnt++;  
    } 
  }

  cout << cnt << endl;
return 0;
 
}

Measured memory_bytes: 4864
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn = 2e5 + 5;
vector<pair<ll,ll>> a , b;
priority_queue<ll , vector<ll> , greater<ll>>Q;
int main()
{
    ios::sync_with_stdio(false);
    int t; cin >> t;
    while (t--){
        a.clear();
        b.clear();
        int n ; cin >> n;
        ll ans = 0;
        for (int i = 1 ; i <= n ; i++){
            ll k , l , r; cin >> k >> l >> r;
            // 这里注意一个边界条件，当 k == n 时，r就不可能取到了，你只能放在前面.
            if (l > r) ans += r , a.push_back(make_pair(k , l - r));
            else ans += l , b.push_back(make_pair(n - k , r - l));
        }
        sort(a.begin() , a.end());
        sort(b.begin() , b.end());
        for (auto & g : a){
            // 排序之后不可能出现 Q.size() > g.k的情况吧
            if (g.first == 0) continue;
            if (Q.size() < g.first) Q.push(g.second);
            else if (Q.size() == g.first)
                if (Q.top() < g.second) Q.pop() , Q.push(g.second);
        }
        while (Q.size()) ans += Q.top() , Q.pop();
        for (auto & g : b){
            if (g.first == 0) continue;
            if (Q.size() < g.first) Q.push(g.second);
            else if (Q.size() == g.first)
                if (Q.top() < g.second) Q.pop() , Q.push(g.second);
        }
        while (Q.size()) ans += Q.top() , Q.pop();
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 8276
N = int(input())
S1 = input()
S2 = input()
mod = 1000000007

if N == 1:
	print(3)
	exit(0)

if S1[0] == S1[1]:
	i = 2
	ans = 6
	prev_flag = 2
else:
	i = 1
	ans = 3
	prev_flag = 1

while i < (N-1):
	if S1[i] == S1[i+1]:
		i += 1
		if prev_flag == 2:
			ans *= 3
		else:
			ans *= 2

		prev_flag = 2

	else:
		if prev_flag == 1:
			ans *= 2

		prev_flag = 1

	i += 1

if i == (N-1) and prev_flag == 1:
	ans *= 2

print(ans%mod)


Measured memory_bytes: 3064
(* O(m^3 log m) *)
let n, k = Scanf.scanf " %d %d" @@ fun a b -> a, b
let vs = Array.init n @@ fun _ -> Scanf.scanf " %d" (+) 0
let ans = ref 0
let m = min n k
let f a b =
  let xs = Array.init (a + b) (fun i -> if i < a then vs.(i) else vs.(n - 1 - i + a)) in
  let sum = ref @@ Array.fold_left (+) 0 xs in
  Array.sort (-) xs;
  let i = ref 0 in
  let c = min (a + b) (k - a - b) in
  while !i < c && xs.(!i) < 0 do sum := !sum - xs.(!i); incr i done;
  !sum
let _ =
  for a = 0 to m do
    for b = 0 to m - a do ans := max !ans @@ f a b done done;
  Printf.printf "%d\n" !ans

Measured memory_bytes: 2560
//#pragma GCC optimize ("-O3","unroll-loops")
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>


#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define m0(x) memset(x,0,sizeof(x))
#define print(x) cout<<x<<'\n';
#define pe(x) cout<<x<<" ";
#define lb(v,n) lower_bound(v.begin(), v.end(), n);
#define ub(v,n) upper_bound(v.begin(), v.end(), n);
#define int long long
//#define int unsigned long long
#define all(x) (x).begin(), (x).end()
//#define double long double

using namespace std;

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

const int MOD = 1e9 + 7;
const ll INF = 1e17;
const double pi = acos(-1);
const double EPS = 1e-10;
typedef pair<int, int>P;
const int MAX = 200020;

int H[100010];
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	int N; cin >> N;
	REP(i, N) {
		cin >> H[i];
	}
	for (int i = N - 2; i >= 0; i--) {
		if (H[i + 1] < H[i])H[i]--;
	}
	bool ok = true;
	REP(i, N - 1) {
		if (H[i + 1] < H[i])ok = false;
	}
	if (ok) {
		print("Yes");
	}
	else print("No");
}



Measured memory_bytes: 1152
#include<stdio.h>
#include<iostream>

using namespace std;

int main(){
	int H, W;
	while (true)
	{
		scanf("%d %d", &H, &W);
		if (H == 0 && W == 0)
		{
			return 0;
		}
		for (int i = 0; i < H; i++)
		{
			for (int j = 0; j < W; j++)
			{
				cout << "#";
			}
			cout << endl;
		}
		cout << endl;
	}
}


Measured memory_bytes: 3160
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try (Scanner in = new Scanner(System.in)) {
            int N = in.nextInt();
            double[] x = new double[N];
            String[] u = new String[N];
            for (int i = 0; i < N; i++) {
                x[i] = in.nextDouble();
                u[i] = in.next();
            }

            double sum = 0;
            for (int i = 0; i < N; i++) {
                if (u[i].equals("JPY")) {
                    sum += x[i];
                } else {
                    sum += x[i] * 380000;
                }
            }

            System.out.println(sum);
        }
    }
}


Measured memory_bytes: 29020
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

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; }

//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//ここから編集する

ll gcd(ll a, ll b) {
    if (a < b) swap(a, b);
    if (a % b == 0) return b;
    return gcd(b, a % b);

}

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

    ll N, X;
    cin >> N >> X;

    ll ans = -1;
    rep(i, 0, N) {
        ll hya;
        cin >> hya;
        ll tmp = abs(X - hya);
        if (i == 0) {
            ans = tmp;
        }else{
            ans = gcd(ans,tmp);
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 888
#include<bits/stdc++.h>
using namespace std;
////////////////////////////////////////////////*kedar1514*////////////////////////////////////////////////(Template Start)*****
#define endl "\n"
#define ll long long
#define fo(i,n) for(i=0;i<n;i++)
#define Fo(i,n) for(i=1;i<=n;i++)
#define si(x)   scanf("%d",&x)
#define sl(x)   scanf("%lld",&x)
#define ss(s)   scanf("%s",s)
#define pi(x)   printf("%d\n",x)
#define pl(x)   printf("%lld\n",x)
#define ps(s)   printf("%s\n",s)
#define all(x)  (x.begin(),x.end())
#define sortAll(x) sort(all(x))   
#define clearAll(arr) memset(arr,0,sizeof(arr))
#define deb(sum) cout<<"deb = "<<sum<<endl;
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define PI 3.1415926535897932384626
typedef pair<int, int>              pii;
typedef pair<long long, long long>  pll;
typedef vector<int>                 vi;
typedef vector<long long>           vl;
typedef vector<pii>                 vpii;
typedef vector<pll>                  vpll;
#define kedar ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

ll powerMod(ll x, ll n, ll mod) {
  ll res = 1;
  x %= mod;
  while (n) {
	if (n & 1)
	  res = (res * x) % mod;
	x = (x * x) % mod;
	n >>= 1;
  }
  return res;
}

ll power(ll x, ll n) {
  ll res = 1;
  while (n) {
	if (n & 1)
	  res = (res * x);
	x = (x * x);
	n >>= 1;
  }
  return res;
}

int gcd(int A, int B) {
    if(B==0)
        return A;
    else
        return gcd(B, A % B);
}
////////////////////////////////////////////////*kedar1514*////////////////////////////////////////////////(Template ends)*****
// <<
//  <<,
//  , cout<<<<endl;
ll arr[100005][3];
ll dp[100005][4];
ll n;
int totalCost(int ind,int aa,int bb,int cc)
{
  int flag=0; 
  if(aa==1) flag=1;
  if(bb==1) flag=2;
  if(cc==1) flag=3;

  if(ind>=n)
  {
    return 0;
  }

  if(dp[ind][flag]!=-1)
  {
    return dp[ind][flag];
  }

  int a=-1;
  int b=-1;
  int c=-1;
  if(aa==0)
    a = arr[ind][0] + totalCost(ind+1,1,0,0);
  if(bb==0)
    b = arr[ind][1] + totalCost(ind+1,0,1,0);
  if(cc==0)
    c = arr[ind][2] + totalCost(ind+1,0,0,1);
  
  return    dp[ind][flag] = max(a,max(b,c));
}

void solve()
{
  cin>>n;
  for (ll i = 0; i < n; i++)
  {
    cin>>arr[i][0]>>arr[i][1]>>arr[i][2];
  }
  memset(dp,-1,sizeof(dp));
  cout<<totalCost(0,0,0,0);
}

int main(){
    kedar;
// <<
//  <<,
//  ,

    ll t=1;
    //cin>>t;
    while(t--)
    {       
        solve();
    }
    return 0;
}// <<
//  <<,
//  ,


Measured memory_bytes: 13568
a = input()

W, H, x, y, r = map(int, a.split())

if W < x + r:
    print('No')
elif 0 > x - r:
    print('No')
elif H < y + r:
    print('No')
elif 0 > y - r:
    print('No')
else:
    print('Yes')


Measured memory_bytes: 5596
#include<iostream>
#include<cstring>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-2;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
int main() {
	int a, b, k; cin >> a >> b >> k;
	int cnt = 0;
	per1(i, max(a, b)) {
		if ((a%i) == 0 && (b%i) == 0) {
			cnt++;
			if (cnt == k) {
				cout << i << endl; break;
			}
		}
	}
	//stop
	return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        PriorityQueue<Integer> q = new PriorityQueue<>(Collections.reverseOrder());
        for (int i = 0; i < n; i++) {
            int a = sc.nextInt();
            q.offer(a);
        }

        for (int i = 0; i < m; i++) {
            int a = q.poll();
            q.offer(a/2);
        }

        long res = 0;
        while (!q.isEmpty()) {
            res += (long)q.poll();
        }
        System.out.println(res);
    }
}

Measured memory_bytes: 60728
import java.util.*;

public class Main {
  public static void main(String[] args) {
    
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int A = sc.nextInt();
    int B = sc.nextInt();
    
    if (N*A < B) {
      System.out.println(N*A);
    }
    else {
      System.out.println(B);
    }
  }
}

Measured memory_bytes: 23124
#include <iostream>
#include<algorithm>
//#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb emplace_back
#define mp make_pair
#define MOD (int) 1e9+7
#define for0(i, n) for (int i = 0; i < n; i++)
#define ff first
#define ss second
#define endl "\n"
#define bits(n) __builtin_popcount(n)
#define ini(a, i) memset(a, i, sizeof(a))

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll t;
	// cin >> t;
	t  = 1;
	while (t--)
	{
		ll n;
		cin >> n;
		ll arr[n];
		for (ll i = 0; i < n; i++) cin >> arr[i];
		ll ans = 1000, p = 1000;
		ll i = 0;
		while (i < n - 1)
		{
			while (i < n - 1 && arr[i] >= arr[i + 1])
				i++;
			if (i == n - 1)
				break;
			ll buy = p / arr[i];
			p = p % arr[i];

			while (i < n - 1 && arr[i] <= arr[i + 1])
				i++;
			p += (buy * arr[i]);
			// cout << i << " ";
		}
		if (p < 1000)
			cout << "1000" << endl;
		else
			cout << p << endl;
		// cout << max(1000, p) << endl;
	}
	return 0;
}


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

const ll INF = ll(1e18)+1;

int main() {
    int n; ll k;
    cin >> n >> k;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    sort(a.begin(), a.end());
    ll l = -INF, r = INF;
    while (l+1 < r) {
        ll x = (l+r)/2;
        bool ok = [&] {
            ll tot = 0;
            rep(i, n) {
                if (a[i] < 0) {
                    int l = -1, r = n;
                    while (l+1 < r) {
                        int c = (l+r) / 2;
                        if (a[c]*a[i] < x) r = c; else l = c;
                    }
                    tot += n-r;
                } else {
                    int l = -1, r= n;
                    while (l+1 < r) {
                        int c = (l+r) / 2;
                        if (a[c]*a[i] < x) l = c; else r = c;
                    }
                    tot += r;
                }
                if (a[i]*a[i] < x) tot--;
            }
            tot /= 2;
            return tot < k;
        } ();
        if (ok) l = x; else r = x;
    }
    cout << l << endl;
    return 0;
}

Measured memory_bytes: 4840
N, K = [int(_) for _ in input().split()]

M = 10**9+7

cs = []

row = [1]
for i in range(2001):
    cs.append(row)
    row = [(x + y) % M for x, y in zip([0]+row, row+[0])]

#print(cs)

def C(x, y):
    if y < 0 or y > x:
        return 0
    return cs[x][y]

for i in range(1, K + 1):
    a = i
    b = i - 1
    c = K - a
    d = N - K - b
    # print(i, a, b, c, d)
    r1 = C(a + d, d)
    r2 = C(a - 1 + c, c)
    r = r1 * r2 % M
    print(r)


Measured memory_bytes: 61660
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cassert>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <complex>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <iterator>

using namespace std;

#define dump(n) cout<<"# "<<#n<<'='<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define iter(c) __typeof__((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();++i)
#define all(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;
typedef pair<int,int> pii;

const int INFTY=1<<29;
const double EPS=1e-9;

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}
template<typename T>
ostream& operator<<(ostream& os,const vector<T>& a){
	os<<'[';
	rep(i,a.size()) os<<(i?" ":"")<<a[i];
	return os<<']';
}

struct Edge{
	int src,dst,weight;
	Edge(){};
	Edge(int s,int d,int w):src(s),dst(d),weight(w){}
};
typedef vector<vector<Edge>> Graph;

struct UnionFind{
	vi data;
	UnionFind(int size):data(size,-1){}
	int Find(int n){
		return data[n]<0?n:(data[n]=Find(data[n]));
	}
	void Unite(int a,int b){
		int ra=Find(a),rb=Find(b);
		if(ra!=rb){
			if(-data[ra]<-data[rb])
				swap(ra,rb);
			data[ra]+=data[rb];
			data[rb]=ra;
		}
	}
	int Size(int n){
		return -data[Find(n)];
	}
};

int main()
{
	for(int n,m;cin>>n>>m;){
		vi as(m),bs(m),ws(m,-1);
		rep(i,m){
			char t; cin>>t>>as[i]>>bs[i];
			as[i]--,bs[i]--;
			if(t=='!') cin>>ws[i];
		}
		
		Graph g(n);
		rep(i,m) if(ws[i]!=-1){
			g[as[i]].emplace_back(as[i],bs[i],ws[i]);
			g[bs[i]].emplace_back(bs[i],as[i],-ws[i]);
		}
		
		vi vis(n),ps(n);
		rep(s,n) if(!vis[s]){
			queue<pii> q; q.emplace(s,0);
			while(q.size()){
				int u,w; tie(u,w)=q.front(); q.pop();
				if(vis[u]) continue;
				vis[u]=1,ps[u]=w;
				for(Edge e:g[u])
					q.emplace(e.dst,w+e.weight);
			}
		}
		
		UnionFind uf(n);
		rep(i,m){
			if(ws[i]!=-1) // ! a b w
				uf.Unite(as[i],bs[i]);
			else{         // ? a b
				if(uf.Find(as[i])==uf.Find(bs[i]))
					cout<<ps[bs[i]]-ps[as[i]]<<endl;
				else
					cout<<"UNKNOWN"<<endl;
			}
		}
	}
}

Measured memory_bytes: 8080
#include <bits/stdc++.h>
#define FOR(i, m, n) for (int i = m; i < (n); i++)
#define RFOR(i, m, n) for (int i = (m - 1); i >= 0; i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, n, 0)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define print(ele) cout << (ele) << endl
#define print10(ele) cout << fixed << setprecision(10) << (ele) << endl

using namespace std;
typedef long long ll;
typedef vector<int> ivec;
typedef vector<string> svec;
typedef vector<ll> lvec;

const int mod = 1e9 + 7;
const ll INF = 1000000000000000000LL;

int main() {
  ll x;
  cin >> x;
  ll ans = 0;
  ll position = 0;
  while (position < x) {
    ans++;
    position += ans;
  }

  print(ans);
  return 0;
}

Measured memory_bytes: 256
import sys
from operator import itemgetter


def _s(): return sys.stdin.readline().strip()


def _i(): return int(sys.stdin.readline().strip())


def parse(s):
    l, r = 0, 0
    for c in s:
        if c == '(':
            r += 1
        else:
            if r > 0:
                r -= 1
            else:
                l += 1
    return (l, r)


def main():
    n = _i()
    p = list(filter(lambda x: x != (0, 0), [parse(_s()) for _ in range(n)]))
    u, d = [], []
    for l, r in p:
        u.append((l, r)) if l <= r else d.append((l, r))
    u.sort(key=itemgetter(0))
    d.sort(key=itemgetter(1), reverse=True)
    r = 0
    for ll, rr in u+d:
        if ll > r:
            return 'No'
        r += (rr - ll)

    return 'Yes' if r == 0 else 'No'


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


Measured memory_bytes: 209320
package main

import (
	"fmt"
	"strconv"
)

func main() {
	var a, b int
	fmt.Scan(&a, &b)

	var str string
	if a > b {
		for i := 0; i < a; i++ {
			str += strconv.Itoa(b)
		}
	} else {
		for i := 0; i < b; i++ {
			str += strconv.Itoa(a)
		}
	}
	fmt.Println(str)
}


Measured memory_bytes: 512
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
	// write your code here
        Scanner scanner =new Scanner(System.in);
        int S=scanner.nextInt();
        int h=S/3600;
        int m=(S-h*3600)/60;
        int s=(S-h*3600-m*60);
        System.out.println(h+":"+m+":"+s);
    }
}



Measured memory_bytes: 26360
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

priority_queue<P, vector<P>, greater<P> > pq;

int main(void){
	int n,i;
	ll a,b,t=0ll;
	P p;
	cin >> n;
	for(i=0; i<n; ++i){
		cin >> a >> b;
		pq.push(P(b,a));
	}
	for(i=0; i<n; ++i){
		p = pq.top();
		pq.pop();
		t += p.second;
		if(t>p.first){
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}


Measured memory_bytes: 6512
let nil = -1

type tree = { mutable parent : int; mutable child : int; mutable bro : int; mutable depth : int }

let make () = { parent = nil; child = nil; bro = nil; depth = nil }

let set_depth t n =
  let rec root i =
    if i = n then nil
    else if t.(i).parent = nil then i
    else root (i + 1) in
  let rec doit i d =
    t.(i).depth <- d;
    if t.(i).bro <> nil then doit t.(i).bro d;
    if t.(i).child <> nil then doit t.(i).child (d + 1) in
  doit (root 0) 0

let print_tree t =
  let rec print_children i c =
    if c <> nil then begin
      if c <> t.(i).child then print_string ", ";
      print_int c;
      print_children i t.(c).bro
    end in
  t |> Array.iteri (fun i _ ->
    "node " ^ string_of_int i ^ ": parent = " ^ string_of_int t.(i).parent
       ^ ", depth = " ^ string_of_int t.(i).depth
       ^ (if t.(i).parent = nil then ", root, ["
          else if t.(i).child = nil then ", leaf, ["
          else ", internal node, [")
    |> print_string;
    print_children i t.(i).child;
    print_endline "]")

let () =
  let n = Scanf.scanf "%d " (fun i -> i) in
  let t = Array.init n (fun _ -> make ()) in
  for _ = 0 to n - 1 do
    let (id, k) = Scanf.scanf "%d %d " (fun id k -> (id, k)) in
    let left_child = ref 0 in
    for i = 0 to k - 1 do
      let c = Scanf.scanf "%d " (fun i -> i) in
      t.(c).parent <- id;
      if i = 0 then t.(id).child <- c
      else t.(!left_child).bro <- c;
      left_child := c;
    done;
  done;
  set_depth t n;
  print_tree t

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

#define NDEBUG
#include <cassert>


typedef long long ll;
typedef long double Double;
typedef unsigned long long ull;
typedef pair<int,int> ii;
typedef pair<ll,ll> llll;
typedef pair<double,double> dd;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<long double> vD;

#define sz(a)  int((a).size())
#define pb  push_back
#define eb  emplace_back
#define FOR(var,from,to) for(int var=(from);var<=(to);++var)
#define rep(var,n)  for(int var=0;var<(n);++var)
#define rep1(var,n)  for(int var=1;var<=(n);++var)
#define repC2(vari,varj,n)  for(int vari=0;vari<(n)-1;++vari)for(int varj=vari+1;varj<(n);++varj)
#define ALL(c)  (c).begin(),(c).end()
#define RALL(c)  (c).rbegin(),(c).rend()
#define tr(i,c)  for(auto i=(c).begin(); i!=(c).end(); ++i)
#define found(s,e)  ((s).find(e)!=(s).end())
#define mset(arr,val)  memset(arr,val,sizeof(arr))
#define mid(x,y) ((x)+((y)-(x))/2)
#define IN(x,a,b) ((a)<=(x)&&(x)<=(b))
#define cons make_pair

#define PQ(T) priority_queue<T>
#define RPQ(T) priority_queue<T,vector<T>,greater<T>>

template<class T> inline void amin(T & a, T const & b) { a = min(a, b); }
template<class T> inline void amax(T & a, T const & b) { a = max(a, b); }

inline ll square(ll x) { return x * x; }
inline ll gcd(ll a, ll b) { while(a) swap(a, b%=a); return b; }
template <typename T>
inline T mod(T a, T b) { return ((a % b) + b) % b; }




int solve(string& s){
    int L = s.size();
    int best = L;

    int cnt = 0;
    rep(i,L){
        if (s[i] != '0'+i%2) ++cnt;
    }
    amin(best, cnt);

    cnt = 0;
    rep(i,L){
        if (s[i] != '1'-i%2) ++cnt;
    }
    amin(best, cnt);

    return best;
}

int main() {
    string s; cin >> s;
    cout << solve(s) << endl;
    return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <algorithm>
#include <string.h>
#include <cmath>


const int MAXN = 100;
int n;

struct DLNode {
	int x;
	struct DLNode* next;
	struct DLNode* pre;

	DLNode() {
	}

	DLNode(int x) : x(x) {
	}
};

DLNode head;

void init() {
	head.next = head.pre = &head;
}

bool is_empty() {
	return head.pre == head.next && head.pre == (&head);
}

void delete_first() {
	if (is_empty()) {
		return;
	}
	DLNode* tmp = head.next;
	tmp->next->pre = &head;
	tmp->pre->next = tmp->next;
	delete tmp;
}

void delete_last() {
	if (is_empty()) return;
	DLNode* tmp = head.pre;
	tmp->pre->next = &head;
	head.pre = tmp->pre;
	delete tmp;
}

void insert(int x) {
	DLNode* t = new DLNode(x);
	t->pre = &head;
	t->next = head.next;
	t->next->pre = t;
	t->pre->next = t;
}

void deletex(int x) {
	if (is_empty()) return;
	DLNode* first = &head;
	DLNode* cur = head.next;
	while (cur != &head) {
		if (cur->x == x) {
			break;
		}
		first = cur;
		cur = cur->next;
	}
	if (cur != &head) {
		first->next = cur->next;
		cur->next->pre = first;
		delete cur;
	}
}

int getx() {
	int x;
	scanf("%d", &x);
	return x;
}

void input() {
	scanf("%d", &n);
	char s[20];
	for (int i = 0; i < n; i++) {
		scanf("%s", s);
		if (strcmp(s, "insert") == 0) {
			insert(getx());
		}
		else if (strcmp(s, "delete") == 0) {
			deletex(getx());
		}
		else if (strcmp(s, "deleteFirst") == 0) {
			delete_first();
		}
		else {
			delete_last();
		}
	}
}

void output() {
	DLNode* cur = head.next;
	while (cur != &head) {
		if (cur != head.next) {
			printf(" ");
		}
		printf("%d", cur->x);
		cur = cur->next;
	}
	puts("");
}

int main() {
	init();
	input();
	output();
	return 0;
}


Measured memory_bytes: 34448
#include <stdio.h>

int N, A;
int arr[51];
long long int sum[2][127511];
int main()
{
        long long int ans = 0;
        int i, j, k;
        int now = 0;
        scanf("%d%d", &N, &A);
        for(i = 0; i < N; i++){
                scanf("%d", &arr[i]);
                arr[i] += 2500;
        }

        sum[now][0] = 1;
        for(i = 0; i < N; i++){
                now = 1 - now;
                for(j = 0; j < arr[i]; j++)
                        sum[now][j] = sum[1 - now][j];
                for(j = arr[i]; j <= 127511; j++)
                        sum[now][j] = sum[1 - now][j] + sum[1 - now][j - arr[i]];
        }

        for(i = 1; i <= N; i++){
                ans += sum[now][i*(A+2500)];
        }
        printf("%lld\n", ans);
        return 0;

}


Measured memory_bytes: 2176
N=int(input())
b,ba,a=0,0,0
ans=0
for i in range(N):
    s=input()
    for i in range(len(s)-1):
        if s[i:i+2]=='AB':
            ans+=1
    if s[0]=='B' and s[-1]=='A':
        ba+=1
    elif s[-1]=='A':
        a+=1
    elif s[0]=='B':
        b+=1
if b==0 and a==0:
    print(ans+max(ba-1,0))
else:
    print(ans+ba+min(a,b))

Measured memory_bytes: 3064
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

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

using namespace std;
typedef long long ll;

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

    if (a < 0 && b == 0) {
        b = -1;
    } else if (a == 0 && b > 0) {
        a = 1;
    }
    if (c < 0 && d == 0) {
        d = -1;
    } else if (c == 0 && d > 0) {
        c = 1;
    }

    ll ans = a * c;
    if (ans < a * d) {
        ans = a * d;
    }
    if (ans < b * c) {
        ans = b * c;
    }
    if (ans < b * d) {
        ans = b * d;
    }
    cout << ans;

    return 0;
}


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

int alpha[26];
main()
{
    char w[101];
    scanf("%s", w);
    int i,x,l,flag=0;
    for(i=0;i<26;i++) alpha[i]=0;

    l=strlen(w);
    for(i=0;i<l;i++) {
        x=w[i];
        alpha[x-97]++;
    }

    for(i=0;i<26;i++) {
        if(alpha[i]%2==1) flag++;
    }

    if(flag>0) printf("No\n");
    else printf("Yes\n");
}


Measured memory_bytes: 128
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>
#include <assert.h>
#include <unordered_set>
#include <random>


using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e18;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)




























int main(){
    ll a, v, b, w, t;
    cin >> a >> v >> b >> w >> t;
    if(a > b){
        a = -a;
        b = -b;
    }
    a += v * t;
    b += w * t;
    cout << ((a >= b)? "YES" : "NO") << endl;
}


Measured memory_bytes: 3580
#include "bits/stdc++.h"

using namespace std;

#define all(v)          v.begin(), v.end()
#define pb              push_back
#define sz(x)          (int) (x.size())
#define endl            "\n"
#define isOdd(n)       (n&1)
#define pow(n, m)      (ll)powl(n, m)
#define clr(x, val)     memset(x, val, sizeof(x))
#define EPS 1e-7

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;


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

    ll k, c = 1, x = 7; cin >> k;
    if(!isOdd(k)) return cout << -1, 0;
    while(x%k != 0 && c < (int)1e7){
        x = ((x*10%k) + 7)%k;
        c++;
    }
    if(x%k != 0) c = -1;
    cout << c;
    return 0;
}


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

using namespace std;

#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)

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

int N, M;
vi G[101010];
int used[101010] = {};
map<int,int> mp;
map<pii,int> d;

bool dfs(int n) {
    bool ret = 1;
    used[n] = 1;
    for (int v : G[n]) {
        if (used[v]) {
            //cout << n << " " << v << " " << d[pii(n, v)] << endl;
            if (mp[v] != mp[n] + d[pii(n, v)]) return 0;
            continue;
        }
        mp[v] = mp[n] + d[pii(n, v)];
        if (!dfs(v)) return 0;
    }
    return ret;
}

void solve() {
    cin >> N >> M;
    vector<vi> info(M);
    rep(i,M) {
        int l, r, dd;
        cin >> l >> r >> dd;
        info[i] = vi({l, r, dd});
        l--; r--;
        G[l].push_back(r);
        G[r].push_back(l);
        d[pii(l, r)] = dd;
        d[pii(r, l)] = -dd;
    }
    sort(info.begin(), info.end());
    rep(i,N) {
        if (used[i]) continue;
        mp[i] = 0;
        int res = dfs(i);
        if (!res) {
            cout << "No" << endl;
            return;
        }
    }
    // REP(i,0,M) {
    //     if (!mp.count(info[i][0]) && !mp.count(info[i][1])) {
    //         mp[info[i][0]] = 0;
    //         mp[info[i][1]] = info[i][2];
    //     } else if (mp.count(info[i][0]) && mp.count(info[i][1])) {
    //         if (mp[info[i][0]] + info[i][2] != mp[info[i][1]]) {
    //             cout << "No" << endl;
    //             return;
    //         }
    //     } else if (mp.count(info[i][0])) {
    //         mp[info[i][1]] = mp[info[i][0]] + info[i][2];
    //     } else if (mp.count(info[i][1])) {
    //         mp[info[i][0]] = mp[info[i][1]] - info[i][2];
    //     }
    // }
    cout << "Yes" << endl;
}

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


Measured memory_bytes: 54912
#define _CRT_SECURE_NO_WARNINGS

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <array>
#include <cassert>
#include <bitset>
#include <cstdint>
using namespace std;
using LL = long long;

int N;
vector<int>A, B, C;

int main() {
	cin >> N;
	cout << N * N * N << endl;
	return 0;
}

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

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

    deque<int> deq;
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;

        if (i % 2 == 0) deq.push_back(a);
        else deq.push_front(a);
    }

    if (n % 2 == 0) {
        cout << deq[0]; deq.pop_front();
        while (!deq.empty()) {
            cout << " " << deq[0]; deq.pop_front();
        }
    } else {
        cout << deq[deq.size() - 1]; deq.pop_back();
        while (!deq.empty()) {
            cout << " " << deq[deq.size() - 1]; deq.pop_back();
        }
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 3072
n = gets.to_i
a = gets.split.map(&:to_i)

class Array
  def partition
    x = self[-1]
    i = -1
    (size - 1).times do |j|
      if self[j] <= x
        i += 1
        self[i], self[j] = self[j], self[i]
      end
    end
    self[i + 1], self[-1] = self[-1], self[i + 1]
    i + 1
  end
end

r = a.partition
puts a[0, r].join(" ") + " [#{a[r]}] " + a[r + 1..-1].join(" ")


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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int N, count = 0; 
    cin >> N;
    vector<long long> a;
    a.resize(N);
    for (int i = 0; i < N; ++i) {
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    
    if (N == 1) {
      ++count;
    } else {
      
    for (int i = 0; i < N - 1; ++i) {
        if (a[i] == a[i + 1]) {
        	++i;	
            if (i + 1 == N - 1) {
                ++count;
            }
        } else {
            ++count;
            if (i + 1 == N - 1) {
                ++count;
            }
        }
    }
    }
    cout << count << endl;
  

    return 0;
}

Measured memory_bytes: 1024