akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
/*
二台の机 A, B があります。机 A には N 冊の本が、机 B には M 冊の本が、それぞれ縦に積まれています。

机 A に現在上から i 番目に積まれている本 (1≤i≤N) は読むのに Ai 分を要し、
机 B に現在上から i 番目に積まれている本 (1≤i≤M) は読むのに Bi 分を要します。

次の行為を考えます。

本が残っている机を選び、その机の最も上に積まれた本を読んで机から取り除く。
合計所要時間が K 分を超えないようにこの行為を繰り返すとき、最大で何冊の本を読むことができるでしょうか。本を読むこと以外に要する時間は無視します。
*/
void N_Greedy(int n=-1){
    unsigned int N,M,K;
    std::vector<long long>A,B;
    std::cin>>N>>M>>K;
    unsigned int A_Cursor=0,B_Cursor=0;
    unsigned long long time=0;
    unsigned int numReadBook=0;
    unsigned long long sumMinTime,sumBufTime;
    int pivot;
    unsigned int i;
    if(n==-1)
        n=(int)N;
    A=std::vector<long long>(N);
    B=std::vector<long long>(M);
    for(i=0;i<N;++i)
        std::cin>>A[i];
    for(i=0;i<M;++i)
        std::cin>>B[i];
    while (n>0){
        // sumMinTime=-1;
        pivot=-1;
        for(i=0;i<(unsigned int)n+1;++i){
            sumBufTime=0;
            // int cnt=0;
            if(A_Cursor+i>N || B_Cursor+(n-i)>M){
                continue;
            }
            for(unsigned int j=A_Cursor;j<A_Cursor+i;++j){
                sumBufTime+=A[j];
                // std::cout<<A[i]<<" ";
                // cnt++;
            }
            // std::cout<<std::endl;
            for(unsigned int j=B_Cursor;j<B_Cursor+(n-i);++j){
                sumBufTime+=B[j];
                // std::cout<<B[i]<<" ";
                // cnt++;
            }
            // std::cout<<std::endl;
            // std::cout<<n<<":"<<cnt<<std::endl;
            if(pivot==-1 || sumMinTime>sumBufTime){
                sumMinTime=sumBufTime;
                pivot=i;
                // std::cout<<"check"<<std::endl;
            }
        }
        if(pivot!=-1 && (K-time)>=sumMinTime){
            time+=sumMinTime;
            numReadBook+=n;
            // std::cout<<sumMinTime<<std::endl;
            A_Cursor+=pivot;
            B_Cursor+=n-pivot;
        }else{
            --n;
        }
    }
    std::cout<<numReadBook;
}

void correct(){
    int N,M;
    unsigned long long K;
    std::vector<unsigned long long>A,B;
    std::vector<unsigned long long>sumA,sumB;
    std::cin>>N>>M>>K;

    A=std::vector<unsigned long long>(N);
    B=std::vector<unsigned long long>(M);
    sumA=std::vector<unsigned long long>(N+1,0);
    sumB=std::vector<unsigned long long>(M+1,0);
    int numReadBook=-1,bufReadBook;
    int startJ=M;

    for(int i=0;i<N;++i){
        std::cin>>A[i];
        sumA[i+1]=sumA[i]+A[i];
    }
    for(int i=0;i<M;++i){
        std::cin>>B[i];
        sumB[i+1]=sumB[i]+B[i];
    }

    for(int i=0;i<N+1;++i){
        for(int j=startJ;j>=0;--j){//降順
            if(sumA[i]+sumB[j]<=K){
                bufReadBook=i+j;
                startJ=j;
                break;
            }
        }
        if(numReadBook==-1 || numReadBook<bufReadBook){
            numReadBook=bufReadBook;
        }
    }
    if(numReadBook>-1)
        std::cout<<numReadBook;
    else
        std::cout<<0;
}
int main(){
    // N_Greedy();
    correct();
    return 0;
}

Measured memory_bytes: 9588
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  while(1){
    c-=b;
    if(c<=0){
      cout<<"Yes"<<'\n';
      break;
    }
    a-=d;
    if(a<=0){
      cout<<"No"<<'\n';
      break;
    }
  }
  return 0;
}


Measured memory_bytes: 3584
def f(n,x):
    C = []
    y = x
    for i in range(n):
        C.append(y%2)
        y//=2
    return C
S = input()
N = len(S)-1
ans = 0
for i in range(2**N):
    C = f(N,i)
    s = S[0]
    for i in range(N):
        s+=("+" if C[i] else "")+S[i+1]
    ans+=eval(s)
print(ans)

Measured memory_bytes: 3064
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby
    #from itertools import product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    n = int(input())

    a = 0
    for i in range(1, 40, 2):
        a -= 2**i
    b = n - a

    res = 0
    for i in range(40):
        if i%2 == 0:
            if (b>>i) & 1:
                res += 1<<i
        else:
            if ((b>>i) & 1) == 0:
                res += 1<<i

    print('{:b}'.format(res))

if __name__ == '__main__':
    main()

Measured memory_bytes: 3316
#include<stdio.h>
#include<cstdio>
#include<iostream>
#include<math.h>
#include<algorithm>
#include<string.h>
#include<string>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<functional>
#define pi 3.14159
#define Inf (int)pow(2., 12.)

using namespace std;
typedef std::pair<int, int> mypair;
queue<mypair> qu;
#define M 1000000
const int dy[4] = {0, 1, 0, -1}, dx[4] = {1, 0, -1, 0};
#define N 123456 
int num = 0;

int ToInt(string str) {
	int a = 0, n = (int)str.size();
	for(int i = 0; i < n; i++) {
		a += (str[i]-'0') * (int)pow(10., (double)(n-i-1));
	}
	return a;
}

string ToString(int a, int l) {
	string str;
	if(l == 6) str = "000000";
	if(l == 5) str = "00000";
	if(l == 4) str = "0000";
	if(l == 3) str = "000";
	if(l == 2) str = "00";
	if(l == 1) str = "0";
	for(int i = 0; i < l; i++) {
		int n = a / (int)pow(10., (double)(l-i-1));
			str[i] = n + '0';
			a -= n * (int)pow(10., (double)(l-i-1));
			}

	return str;
}
int dia(int h, int w) {
	return h*h + w*w;
}

void tan(int d) {
		for(int i = 1; i < 150; i++) {
			for(int j = i+1; j < 150; j++) {
				if(dia(i, j) == d) {
					cout << i << " " << j <<endl;
					return;
				} else if(dia(i, j) > d) break;
			}
		}
		tan(d + 1);
}

int main(){
	int h, w;
	while(cin >> h >> w) {
		if(h + w == 0) break;
		bool bo2 = false;
		for(int i = h+1; i < 150; i++) {
			for(int j = i+1; j < 150; j++) {
				if(dia(i, j) == dia(h, w)) {
					h = i;
					w = j;
					bo2 = true;
					break;
				} else if(dia(i, j) > dia(h,w)) break;
			}
			if(bo2) break;
		}
		if(bo2) cout << h << " " << w <<endl;
		else tan(dia(h, w) + 1);
	}
	return 0;
}

Measured memory_bytes: 1200
#include<bits/stdc++.h>
const long long INF = LLONG_MAX / 2;
const long long MOD = 1000000007;
const long double PI = 3.1415926;
#define FOR(i,r,n) for(int i = (ll)(r); i < (ll)(n); i++)
#define REP(i,n) FOR(i,0,n)
#define ll long long int
using namespace std;
ll ans = 0, sum = 0, n, k, counter = 0, w, h;
string s;
vector<ll> v;
vector < pair<ll, ll > > vp;
vector<vector<ll> > vv(50, vector<ll>(50, INF));
vector<string> sv;

int main() {
	ll n1, n2;
	ll a[100];
	ll b[100];
	ll c[100];
	cin >> n1;
	REP(i, n1) {
		cin >> a[i];
		sum += a[i];
	}
	cin >> n2;
	REP(i, 2 * n2) {
		cin >> b[i];
		cin >> c[i];
	}
	REP(i, n2) {
		ans = sum - a[(b[i] - 1)] + c[i];
		cout << ans << endl;
	}
}

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

typedef long long ll;
const ll LL_MAX (1LL<<60);

#define rep(i,s,e) for(ll i=(s); i<(e); i++) 

using namespace std;

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

    bool is_odd(true), is_even(true);
    rep(i, 0, s.size())
    {
        if(i % 2 == 0)
        {
            if(s[i] == 'R' || s[i] == 'U' || s[i] == 'D')
            ;
            else
            {
                //cout << s[i] << endl; 
                is_even = false;
            }
        }    
        else
        {

            if(s[i] == 'L' || s[i] == 'U' || s[i] == 'D')
                    ;
            else
            {
                //cout << s[i] << endl; 
                is_odd = false;
            }
        }

    }

    if(is_even && is_odd)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES

#include <iostream>
#include <cstdio>
#include <cmath>

#define RAD_TO_DEG(x)	(x * 180.0 / M_PI)

using namespace std;

int main()
{
	double a, b, x;

	cin >> a >> b >> x;
	
	double ans;

	if (a * a * b < 2 * x) {
		double water_h = x / a / a;

		ans = RAD_TO_DEG(atan2(2 * (b - water_h), a));
	}
	else {
		ans = RAD_TO_DEG(atan2(b, 2 * x / b / a));
	}

	printf("%.10f\n", ans);

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int a,b,c;
  scanf("%d%d%d",&a,&b,&c);
  if(a <= c && c <= b){
    printf("Yes");
  }else if(b <= c && c<=a){
    printf("Yes");
  }else{
    printf("No");
  }
  return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main() {
    int k,s,z,res=0;
    cin>>k>>s;
    for(int i=0;i<=k;i++){
        for(int j=0;j<=k;j++){
            z=s-i-j;
            if(z<0||z>k)continue;
            res++;
        }
    }
    cout<<res<<endl;
}

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


int main() {
	map<char, int>mp;
	string st; cin >> st;
	for (auto c : st) {
		mp[c]++;
	}
	
	int ans=count_if(mp.begin(), mp.end(), [](const auto&p) {return p.second % 2; });

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

Measured memory_bytes: 3188
def main():
    S = input()
    N = len(S)
    from collections import deque

    def solve(S):
        cur = deque([S[0]])
        ans1 = 1
        i = 1
        plus = 1
        while i < N:
            if i+plus > N:
                break
            if S[i:i+plus] in cur:
                plus += 1
            else:
                cur.pop()
                cur.append(S[i:i+plus])
                i = i+plus
                plus = 1
                ans1 += 1

        cur = deque([S[:2]])
        ans2 = 1
        i = 2
        plus = 1
        while i < N:
            if i+plus > N:
                ans2 = -1
                break
            if S[i:i+plus] in cur:
                plus += 1
            else:
                cur.pop()
                cur.append(S[i:i+plus])
                i = i+plus
                plus = 1
                ans2 += 1
        return ans1, ans2
    ans1, ans2 = solve(S)
    ans3, ans4 = solve(S[::-1])
    print(max(ans1, ans2, ans3, ans4))


if __name__ == '__main__':
    main()


Measured memory_bytes: 43340
#include <bits/stdc++.h> 
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define _GLIBCXX_DEBUG
typedef long long ll;
using namespace std;
int main(){
  int a,b;
  cin>>a>>b;
  cout<<max(max(a+b,a-b),a*b)<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#define llint long long int

using namespace std;

llint comb(llint n)
{
	return n * (n-1) / 2;
}

string A;
llint cnt[26];

int main(void)
{
	cin >> A;
	
	for(int i = 0; i < (int)A.size(); i++){
		cnt[A[i] - 'a']++;
	}
	
	llint ans = comb( (int)A.size() ) + 1;
	for(int i = 0; i < 26; i++){
		ans -= comb( cnt[i] );
	}
	
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
//#pragma GCC optimize("Ofast")
#define rep(i,n) for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
#define pi M_PI
#define PQ(T) priority_queue<T>
#define SPQ(T) priority_queue<T,vector<T>,greater<T>>
using ll=long long;
using P=pair<ll,ll>;
using PP=tuple<ll,ll,ll>;
using S=multiset<ll>;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
const ll inf=1001001001001001;
const int INF=1001001001;
const int mod=1000000007;
const double eps=1e-10;
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';}
template<class T> void outvp(T v){rep(i,v.size())cout<<'('<<v[i].fi<<','<<v[i].se<<')';cout<<'\n';}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';}
template<class T> void outvv(T v){rep(i,v.size())outv(v[i]);}
template<class T> bool isin(T x,T l,T r){return (l)<=(x)&&(x)<=(r);}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
void decimal(int x){cout<<fixed<<setprecision(x);}
//ll GCD(ll a,ll b){if(b==0) return a; return GCD(b,a%b);}
//ll LCM(ll a,ll b){return(a/GCD(a,b))*(b/GCD(a,b))*GCD(a,b);}
ll POW(ll a,ll b){a%=mod;if(b==0)return 1;if(b&1)return a*POW(a,b-1)%mod;ll k=POW(a,b/2);return k*k%mod;}
vi calc(ll x){vi res;while(x>0){res.eb(x%10);x/=10;}reverse(all(res));return res;}

void solve(){
  ll n; cin>>n;
  vi a(n);
  rep(i,n) cin>>a[i];
  const ll MAX=pow(10,18);
  ll ans=1;
  rep(i,n){
    if(a[i]==0){
      out(0); return;
    }
  }
  rep(i,n){
    if(MAX/ans<a[i]){
      ans=-1; break;
    }
    ans*=a[i];
  }
  out(ans);
}

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


Measured memory_bytes: 3976
ans_list = []

def solve():
    S = input()
    if S == ".":
        return "end"
    T = input()

    if S == T:
        return "IDENTICAL"

    cs = []
    ct = []

    ns = []
    nt = []

    tmp = ""
    flag = False
    for s in S:
        if s == '"':
            if flag:
                flag = False
                cs.append(tmp)
            else:
                flag = True
                ns.append(tmp)
            tmp = ""
            continue
        tmp += s
    ns.append(tmp)

    tmp = ""
    flag = False
    for t in T:
        if t == '"':
            if flag:
                flag = False
                ct.append(tmp)
            else:
                flag = True
                nt.append(tmp)
            tmp = ""
            continue
        tmp += t
    nt.append(tmp)

    if ns != nt or len(cs) != len(ct):
        return "DIFFERENT"
    
    cnt = 0
    for csi, cti in zip(cs, ct):
        if csi != cti:
            cnt += 1
    
    if cnt == 1:
        return "CLOSE"
    else:
        return "DIFFERENT"
    

while True:
    ans = solve()
    if ans == "end":
        break
    ans_list.append(ans)

for ans in ans_list:
    print(ans)


Measured memory_bytes: 5596
<?php
for ($i = 0; $i < 3; $i++) {
    $num = [];
    $num = explode(' ', trim(fgets(STDIN)));
    $list[] = $num[0];
    $list[] = $num[1];
}

$value = array_count_values($list);
if (max($value) == 2 && min($value) == 1) {
    echo 'YES';
} else {
    echo 'NO';
}

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

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

using namespace std;

int main()
{
  vector<int> v;
  int n = 3;
  while (n--)
  {
    int x;
    cin >> x;
    v.push_back(x);
  }
  sort(v.begin(), v.end());
  cout << v[0] << " " << v[1] << " " << v[2] << endl;
  return 0;
}

Measured memory_bytes: 3112
#[allow(unused_imports)]
use std::cmp;

// Input macro from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
  (source = $s:expr, $($r:tt)*) => {
    let mut iter = $s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
  ($($r:tt)*) => {
    #[allow(unused_mut)]
    let mut s = {
      use std::io::Read;
      let mut s = String::new();
      std::io::stdin().read_to_string(&mut s).unwrap();
      s
    };
    let mut iter = s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
}

macro_rules! input_inner {
  ($iter:expr) => {};
  ($iter:expr, ) => {};

  ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
    let $var = read_value!($iter, $t);
    input_inner!{$iter $($r)*}
  };
}

macro_rules! read_value {
  ($iter:expr, ( $($t:tt),* )) => {
    ( $(read_value!($iter, $t)),* )
  };

  ($iter:expr, [ $t:tt ; $len:expr ]) => {
    (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
  };

  ($iter:expr, chars) => {
    read_value!($iter, String).chars().collect::<Vec<char>>()
  };

  ($iter:expr, usize1) => {
    read_value!($iter, usize) - 1
  };

  ($iter:expr, $t:ty) => {
    $iter.next().unwrap().parse::<$t>().expect("Parse error")
  };
}

fn prob(n: usize, k: usize, mut x: usize) -> f64 {
  let mut ret = 1.0 / n as f64;
  while x < k {
    x *= 2;
    ret /= 2.;
  }
  ret
}

fn main() {
  input! {
    n: usize,
    k: usize,
  }
  let ans: f64 = (1 .. n+1).map(|x| prob(n, k, x)).sum();
  println!("{}", ans);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define fi first
#define se second
#define pb push_back
#define vi vector<int >
#define vii vector < pair<int ,int > >
#define IO ios::sync_with_stdio(0) ; cin.tie(0) ; cout.tie(0)
#define IOfiles freopen("input.txt","r+",stdin) ; freopen("output.txt","w+",stdout)
#define PI 3.14159265
const long long mod = 1e9 + 7LL;
typedef long long ll;
typedef pair<int, int> ii;
typedef double db;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a;}
ll pwr(ll x , ll n) { ll ans = 1; while (n) {ans *= x; n--;} return ans;}

void solve() {

}

int main()
{
    IO;
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    while (true) {
        c -= b;
        if (c <= 0) {
            cout << "Yes" << endl;
            return 0;
        }
        a -= d;
        if (a <= 0) {
            cout << "No" << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 3648
n = int(input())
lst = list(map(int, input().split()))
dic = {}
for i in range(n):
  a = lst[i]
  dic.setdefault(a - 1, 0)
  dic[a - 1] += 1
  dic.setdefault(a, 0)
  dic[a] += 1
  dic.setdefault(a + 1, 0)
  dic[a + 1] += 1
print(max(list(dic.values())))

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

int main(){
	int first, year, n;
	for( cin >> n; cin >> first >> year >> n; ){
		int ans = 0;
		for( int i = 0; i < n; ++i ){
			int compound, fee;
			double interest;
			int sum = 0;
			
			cin >> compound >> interest >> fee;
			if( compound ){
				sum = first;
				for( int j = 0; j < year; ++j ){
					sum += int( sum * interest ) - fee;
				}
			}
			else{
				int p = first;
				for( int j = 0; j < year; ++j ){
					sum += int( p * interest );
					p -= fee;
				}
				sum += p;
			}
			
			ans = max( ans, sum );
		}
		
		cout << ans << endl;
	}
}

Measured memory_bytes: 0
n, k = map(int, input().split())
a = n // k

if k % 2 == 0:
    b = 0
    for i in range(1, n+1):
        if i % k == k // 2:
            b += 1
    print(a ** 3 + b ** 3)
else:
    print(a ** 3)


Measured memory_bytes: 39024
#include<iostream>
#include<algorithm>
using namespace std;
#define MAX_N 100
int card[2 * MAX_N], n;
void RE(){
  int tmp[2 * MAX_N];
  for(int i = 0 ; i < n ; i++ ){
    tmp[2 * i] = card[i];
    tmp[2 * i + 1] = card[n+i];
  }
  for(int i = 0 ; i < 2 * n ; i++ ) card[i] = tmp[i];
  return;
}
void SE(int& buff){
  int tmp[2 * MAX_N];
  for(int i = buff ; i < 2 * n ; i++ ) tmp[i] = card[i];
  for(int i = buff - 1,j = 2 * n - 1 ; i >= 0 ; i--,j-- ) card[j] = card[i];
  for(int i = buff ; i < 2 * n ; i++ ) card[i-buff] = tmp[i];
  return;
}
int main(){
  int m;
  cin >> n >> m;
  for(int i = 0 ; i < 2 * n ; i++ ) card[i] = i + 1;
  for(int i = 0 ; i < m ; i++ ){
    int buff;
    cin >> buff;
    if(buff == 0) RE();
    else SE(buff);
  }
  for(int i = 0 ; i < 2 * n ; i++ ){
    cout << card[i] << endl;
  }
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
bool a[500]={0};
int main()
{
	int n,i,x=1;
	cin>>n;
	while(x<=n){
		a[x]=1;
		x*=2;
	}
	for(i=n;i>=1;i--)
		if(a[i]){
			cout<<i;
			break;
		}
	cout<<endl;
	return 0;
}

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

int main(){
  int num;
  int i;
  int min = 1000001;
  int max = -1000001;
  long int sum = 0;
  cin>>num;
  int tmp;
  for(i=0;i<num;i++){
    cin >> tmp;
    if(tmp>max){
      max = tmp;
    }
    if(tmp<min){
      min =tmp;
    }
    sum += tmp;
  }

  cout<<min<<" "<<max <<" "<<sum<<endl;
  return 0;
}

Measured memory_bytes: 1164
#include <iostream>
using namespace std;
int main(){
    int a,b;
    cin >> a >> b;
    int ans = 0;
    for(int i = 0; i < 2; i++)
    {
        if (a>=b) {
            ans += a;
            a--;
        }
        else
        {
            ans+= b;
            b--;
        }
    }
    cout << ans << endl;
}

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

int main(){
  string O,R;
  cin >> O >> R;
  int NO = O.size();
  int NR = R.size();
  vector<char> P(NO + NR);
  for(int i = 0;i<NR;i++){
    P.at(2*i) = O.at(i);
    P.at(2*i+1) = R.at(i);
  }
  if(NO>NR){
    P.at(NO + NR -1) = O.at(NO-1);
  }
  for(int i = 0;i<NO+NR;i++){
    cout << P.at(i);
  }
  cout << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
    char s[100001], *p;
    int mod = 1000000007;
    int dp[13] = {1}, nextdp[13];
    int i, j, k, l, r;

    scanf("%s", s);

    for (p = s; *p != '\0'; p++) {
        for (j = 0; j < 13; j++) nextdp[j] = 0;

        if (*p == '?') {
            l = 0, r = 9;
        } else {
            l = r = *p - '0';
        }

        for (i = 0; i < 13; i++) {
            for (j = l; j <= r; j++) {
                k = (i * 10 + j) % 13;
                nextdp[k] = ((long long)nextdp[k] + dp[i]) % mod;
            }
        }

        for (j = 0; j < 13; j++) dp[j] = nextdp[j];
    }

    printf("%d\n", dp[5]);
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>

using namespace std;

typedef long long int ll;

ll N,A,B;

int main(){

    scanf("%lld%lld%lld",&N,&A,&B);

    ll complet_turns=N/(A+B);
    ll remain=N%(A+B);

    ll remain_A=min(remain,A);

    printf("%lld\n",complet_turns*A+remain_A);

    return 0;
}

Measured memory_bytes: 128
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
//#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>

using namespace std;

#define PI          3.1415926535897932384626433832795l

#define pb push_back
#define mp make_pair
#define lb lower_bound // First element which is not less than val
#define ub upper_bound // First element greater than val
#define f first
#define s second

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vd = vector<double>;
using vs = vector<string>;
using vpii = vector<pair<int,int>>;
using vpll = vector<pair<ll,ll>>;

using pii = pair<int,int>;
using pll = pair<ll,ll>;

#define endl '\n'
#define re return
#define repz(i, a) for (ll i = 0; i < (a); i++)
#define vecin(n,v) for(ll i = 0; i < n; i++) cin>>v[i];
#define full(v) v.begin(),v.end()

// Implementation by AI.Cash
// All the leaves are at n,n+1,...
// Every segment is of the form [l,r)

void solve()
{
  int l;
  cin >> l;

  vpii edges;
  int curr =0;
  for (int i = 18; i >= 0; i--)
  {
    while (l >= curr + (1<<i))
    {
      edges.pb({19-i,curr});
      curr += (1<<i);
    }
  }

  cout << 20 << " " << edges.size() + 36 << "\n";

  for (int i = 1; i < 19; i++)
  {
    cout << i+1 << " " << i+2 << " " << 0 << endl;
    cout << i+1 << " " << i+2 << " " << (1<<(18-i)) << endl;
  }

  for (int i = 0; i < (int)edges.size(); i++)
  {
    cout << 1 << " " << edges[i].f+1 << " " << edges[i].s << endl;
  }

}

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

  ll t = 1;
  //cin >> t;
  while (t--)
  {
    solve();
  }
}



Measured memory_bytes: 3652
//#include "bits/stdc++.h"
#include <iostream>
#include <vector>
#include <map>
#include <utility>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#include <complex>
#include <bitset>
#include <functional>
#include <stack>
#include <regex>
#include <tuple>
#include <iomanip>


#define int long long
#define REP(i,l,r) REPEAT(i,l,r,true) // [l, r)
#define rep(i,n) REP(i,0,n)           // [0, n)
#define REPEAT(i,l,r,condition) for(int i=(condition)?l:r-1;(condition)?i<r:i>=l;(condition)?++i:--i) // false<-[l, r)->true
#define all(e) e.begin(),e.end()
#define rall(e) e.rbegin(),e.rend()
#define pb push_back
#define fs first
#define sc second
#ifdef LOCAL
#define show(...) cerr<<#__VA_ARGS__<<" = ";_DEBUG(__VA_ARGS__)
#define showlr(n,l,r) cerr<<#n<<" = ";for(int i=l;i<r;i++){cerr<<n[i]<<", ";}cerr<<endl // [l, r)
#else
#define show(...)
#define showlr(n,l,r)
#endif

#define YN(condition) puts((condition)?"YES":"NO")
#define Yn(condition) puts((condition)?"Yes":"No")
#define yn(condition) puts((condition)?"yes":"no")
#define YES puts("YES")
#define Yes puts("Yes")
#define yes puts("yes")
#define NO  puts("NO")
#define No  puts("No")
#define no  puts("no")

#define case(i) printf("Case #%lld: ",i)

using namespace std;

using vi=vector<int>;
using pint=pair<int,int>;

struct io{io(){cin.tie(0);ios::sync_with_stdio(false);cout.tie(0);cout<<fixed<<setprecision(20);}}io;

template<class T> istream& operator >>(istream &is, vector<T> &v){for(T &e:v)is>>e;return is;}
template<class T> ostream& operator <<(ostream &os, vector<T> v){os<<"{";for(T &e:v)os<<e<<(v.size()-(int)(&e-&v[0])>1?", ":"");os<<"}";return os;}

void _DEBUG(){}
template<typename H,typename... T> void _DEBUG(H a,T...b){cerr<<a<<(sizeof...(b)?",":"\n");_DEBUG(b...);}

inline void in(){}
template<typename H,typename... T>void in(H &a, T&... b){cin>>a;in(b...);}
inline void out(){}
template<typename H,typename... T> void out(H a, T... b){cout<<a<<(sizeof...(b)?" ":"\n");out(b...);}

template<class T> void resz(int n,T& v){v.resize(n);}
template<class H,class... T> void resz(int n,H& a,T&... b){a.resize(n);resz(n,b...);}

template<typename V,typename H> void resize(vector<V>& v,const H a){v.resize(a);}
template<typename V,typename H,typename... T> void resize(vector<V>& v,const H& a,const T... b){v.resize(a);for(auto &v:v) resize(v,b...);}

const int INF=1LL<<55;
const int MOD=1000000007;
const double EPS=1e-8;
/*------------end of definitions------------*/

int N;

signed main(){

    in(N);
    Yn(N/100==N%10);

    return 0;
}


Measured memory_bytes: 504
#include<stdio.h>
int main(){
    char a[101];
    scanf("%s",a);
    int i,j,k,u;
    for(u=0;a[u]!=NULL;u++){
      i++;  
     }

     for(j=0;j<i/2;j++){
         if(a[j]!=a[i-1-j])k++;
     }
     printf("%d",k);
    return 0;
}

Measured memory_bytes: 128
#include <cstdio>
#include <iostream>
#include <algorithm>
#define N 2010
#define M 4000000
#define P 1000000007

using namespace std;

typedef long long ll;

int n,k;
ll f[N][N],fac[N*N],inv[N*N];

inline int C(int x,int y){
  if(x<y) return 0;
  return fac[x]*inv[y]%P*inv[x-y]%P;
}

int main(){
  //freopen("1.in","r",stdin);
  //freopen("1.out","w",stdout);
  scanf("%d%d",&n,&k);
  if(k==1) return puts("1"),0;
  fac[0]=inv[0]=inv[1]=1;
  for(int i=1;i<=M;i++) fac[i]=fac[i-1]*i%P;
  for(int i=2;i<=M;i++) inv[i]=(P-P/i)*inv[P%i]%P;
  for(int i=1;i<=M;i++) inv[i]=inv[i]*inv[i-1]%P;
  f[0][0]=1;
  for(int i=1;i<=n;i++)
    for(int j=i;~j;j--){
      f[i][j]=f[i][j+1]%P;
      if(j) (f[i][j]+=f[i-1][j-1]*C(i*k-j-1,k-2))%=P;
    }
  printf("%lld\n",f[n][0]*fac[n]%P);
  return 0;
}

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

#define N 100
#define infinity 100000

void chain_multiplication(void);
int mini(int, int);

int n, m[N + 1] = {}, M[N + 1][N + 1] = {};

int main(){
  int i;

  scanf("%d", &n);

  for(i = 1; i <= n; i++)
    scanf("%d %d", &m[i - 1], &m[i]);
  
 
  chain_multiplication();
  
  printf("%d\n", M[1][n]);
  

  return 0;
}

void chain_multiplication(){
  int i, j, k, l;

  for(i = 1; i <= n; i++)
    M[i][i] = 0;
  
  for(l = 2; l <= n; l++){
    for(i = 1; i <= n - l + 1; i++){
      j = i + l - 1;
      M[i][j] = infinity;

      for(k = i; k <= j - 1; k++)
	M[i][j] = mini(M[i][j], M[i][k] + M[k + 1][j] + m[i - 1] * m[k] * m[j]);
    }
  }
}

int mini(int x, int y){
  if(x < y)
    return x;

  else
    return y;
}



Measured memory_bytes: 2148
import sys

def solve():
    input = sys.stdin.readline
    H, W = map(int, input().split())
    A = [input().strip("\n") for _ in range(H)]
    count = 0
    for h in range(H):
        for w in range(W):
            if A[h][w] == "#": count += 1
    if count + 1 == H + W: print("Possible")
    else: print("Impossible")


    return 0

if __name__ == "__main__":
    solve()

Measured memory_bytes: 3064
import java.util.*;
public class Main{
	public static void main(String[] args){
      Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      ArrayList<Integer> list = new ArrayList<>();
      if(n==0){
        System.out.println(0);
      	return;
      }
      while(n!=0){
      	int b = Math.abs(n%2);
        list.add(b);
        n = (n-b)/(-2);
      }
      Collections.reverse(list);
      for(int x : list)System.out.print(x);
      System.out.println("");
    }
}

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

#define debug(x) (cerr << #x << " = " << x << endl;)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define FOR(it, b, e) for (typeof(b) it = (b); it != (e); ++it)
#define MSET(c, v) memset(c, v, sizeof(c)

const int INF = 0x3F3F3F3F; 
const int NEGINF = 0xC0C0C0C0;
const int NULO = -1;
const double EPS = 1e-10;

inline int cmp(double x, double y = 0) 
{  
  if(fabs(x - y) < EPS)
    return 0;
  return x > y ? 1 : -1;
}

int c[15];
int a[16][15];

int main()
{
  ios::sync_with_stdio(0);
  int n,m,x;
  cin >> n >> m >> x;
  for(int i = 0; i < n ; i++)
  {
    cin >> c[i];
    for(int j = 0 ; j < m; j++)
    {
      cin >> a[i][j];
    }
  }

  int ans = INT_MAX;
  for(int mask = 0; mask < (1 << n); mask++)
  {
    int cost = 0;
    vector<int>lvl(m, 0);
    for(int i = 0 ; i < n; i++)
    {
      if(mask & (1 << i))
      {
        cost += c[i];
        for(int j = 0; j < m; j++)
        {
          lvl[j] += a[i][j];
        }
      }
    }
    bool ok = true;
    for(int j = 0 ; j < m ; j++)
    {
      ok &= lvl[j] >= x;
    }
    if(ok)
      ans = min(ans, cost);
    // cout << mask << " " << ok << " " << cost << endl; 
  }
  ans = ans == INT_MAX ? -1 : ans;
  cout << ans << endl;
  return 0;
}

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

int main()
{
	int n;
	std::cin >> n;
	double x[20];
	double result = 0;
	std::string u[20];
	for (int i = 0; i < n; i++) {
		std::cin >> x[i] >> u[i];
	}
	for (int i = 0; i < n; i++) {
		result += (u[i] == "JPY") ? x[i] : x[i] * 380000.0;
	}
	
	std::cout<<result;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
s = input()
a = [0] * 26
c = 1

for i in range(0, n):
    a[ord(s[i]) - ord("a")] += 1
    p = a[ord(s[i]) - ord("a")]
    c = c // p * (p + 1)
    
print((c - 1) % (10**9 + 7))

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define rep0(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define ll long long
#define coYes cout << "Yes" << endl
#define coYES cout << "YES" << endl
#define coyes cout << "yes" << endl
#define coNo cout << "No" << endl
#define coNO cout << "NO" << endl
#define cono cout << "no" << endl
#define BIT_FLAG_0 (1<<0) // 0000 0000 0000 0001
int gcd(int a, int b){ //最大公約数
    if(a%b == 0){
        return b;
    }else{
    return gcd(b, a%b);
    }
}

int main(){
    int n,c=0;
    cin >> n;
    vector<vector<int>> d(n,vector<int> (2));
    rep0(i,n){
            cin >> d[i][0] >> d[i][1];
    }
    rep0(i,n){
        if(d[i][0]==d[i][1]) c++;
        else c=0;
        if(c==3) break;
    }
    if(c>=3){
        coYes;
        return 0;
    }else{
        coNo;
        return 0;
    }
}


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

using namespace std;

map< int64_t, int > prime_factor(int64_t n) {
  map< int64_t, int > ret;
  for(int64_t i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return (ret);
}


int main() {
  int N;
  cin >> N;
  cout << N << ":";
  for(auto &p : prime_factor(N)) {
    for(int k = 0; k < p.second; k++) cout << " " << p.first;
  }
  cout << endl;
}



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

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

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

int main() {
    int N; cin >> N;
    vector<int> A(N);
    REP(i, N) cin >> A[i];

    vector<int> L(N), R(N);
    L[0] = A[0];
    for (int i = 1; i < N; i++) {
        L[i] = gcd(L[i-1], A[i]);
    }
    R[N-1] = A[N-1];
    for (int i = N-2; i >= 0; i--) {
        R[i] = gcd(R[i+1], A[i]);
    }

    int res = 1;
    for (int i = 0; i < N; i++) {
        int x = 1;
        if (i == 0)
            x = R[i+1];
        else if (i == N-1)
            x = L[i-1];
        else
            x = gcd(L[i-1], R[i+1]);
        res = max(res, x);
    }
    cout << res << endl;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using namespace std;

int main() {
    ll N, D, A;
    cin >> N >> D >> A;
    D = D * 2;
    vector<pair<int, int>> m(N);
    rep(i, N) cin >> m[i].first >> m[i].second;
    sort(all(m));

    ll ans = 0;
    ll dmg = 0;
    queue<pair<ll, ll>> q;
    rep(i, N) {
        while (!q.empty() && m[i].first > q.front().first) {
            dmg -= q.front().second;
            q.pop();
        }
        ll cnt = max((m[i].second - dmg + A - 1) / A ,0LL);
				ans += cnt;
        dmg += cnt * A;
        q.push({m[i].first + D, cnt * A});
    }

    cout << ans << endl;
}

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

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

#define p_ary(ary,a,b,i) do { cout << "["; for (int (i) = (a);(i) < (b);++(i)) cout << ary[(i)] << ((b)-1 == (i) ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

typedef unsigned long long ull;
 
mt19937_64 r(std::chrono::high_resolution_clock::now().time_since_epoch().count());

ull const MASK30 = (1<<30)-1;
ull const MASK31 = INT_MAX;
ull const MOD = (1LL<<61)-1;
ull const MOD5 = MOD*5;
ull const base = r()%MOD;
 
struct RollingHash {
private:
    vector<ull> power,hash;
public:
    ull mul(ull a,ull b) {
        ull au = a>>31;
        ull ad = (a&MASK31);
        ull bu = b>>31;
        ull bd = (b&MASK31);
        ull mid = au*bd+ad*bu;
        return ((au*bu)<<1)+ad*bd+(mid>>30)+((mid&MASK30)<<31);
    }

    ull calcmod(ull a) {
        a = (a&MOD)+(a>>61);
        if (a > MOD) a -= MOD;
        return a;
    }

    RollingHash(string& s) {
        int n = s.size();
        power.resize(n+1);
        hash.resize(n+1);
        power[0] = 1;
        hash[0] = 0;
        for (int i = 0;i < n;++i) power[i+1] = calcmod(mul(power[i],base));
        for (int i = 0;i < n;++i) hash[i+1] = calcmod(mul(hash[i],base)+s[i]);
    }

    ull get(int l, int r)  {
        if (l) {
            return calcmod(hash[r]+MOD5-mul(hash[l],power[r-l]));
        }
        return hash[r];
    }
 
 
    ull connect(ull h1,int l,int r) {
        ull h2 = get(l,r);
        return calcmod(mul(h1,power[r-l])+h2);
    }
 
    int LCP(int l1,int r1,RollingHash& rh,int l2,int r2) {
        int ok = 0,ng = min(r1-l1,r2-l2)+1;
        while (ng-ok > 1) {
            int mid = (ok+ng)/2;
            if (get(l1,l1+mid) == rh.get(l2,l2+mid)) ok = mid;
            else ng = mid;
        }
        return ok;
    }
};

int main() {
    string s,t,u;
    cin >> s >> t;
    int n = s.size(),m = t.size(),x,ans = 0;
    u = "";
    for (int i = 0;i < m/n+2;++i) u += s;
    x = u.size();
    RollingHash rht(t),rhu(u);
    vector<int> a(x);
    for (int i = 0;i < n;++i) a[i] = rht.LCP(0,m,rhu,i,x);
    vector<bool> b(n,false),used(n,false);

    for (int i = 0;i < n;++i) {
        if (a[i] < m) continue;
        b[i] = true;
    }
    for (int i = 0;i < n;++i) {
        if (!b[i]) used[i] = true;
        if (b[((i-m)%n+n)%n]) continue;
        int ret = 0,f = i;
        while (b[f]) {
            used[f] = true;
            (f += m) %= n;
            ret++;
        }
        ans = max(ans,ret);
    }
    for (int i = 0;i < n;++i) if (!used[i]) {
        cout << "-1" << endl;
        return 0;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 39880
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String[] ab = scanner.nextLine().split(" ", 2);
        int a = Integer.parseInt(ab[0]);
        int b = Integer.parseInt(ab[1]);
        for (int i = 1; i <= 3; i++) {
            if ((a * b * i) % 2 == 1) {
                System.out.println("Yes");
                return;
            }
        }
        System.out.println("No");
    }
}


Measured memory_bytes: 22868
/**
 *      purpose : 
 *      author  : kyomukyomupurin
 *      created : 
**/

// input/output
#include <iostream>
#include <fstream>
#include <sstream>
// container class
#include <array>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
// math, algorithm
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
// etc
#include <bitset>
#include <cctype>
#include <cstring>
#include <chrono>
#include <iomanip>
#include <random>
#include <utility>
// using-directive
using namespace std;
// alias template
using int64 = int64_t;
using pii = pair<int, int>;
using pll = pair<int64_t, int64_t>;
// text macro replacement
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define print(x) cout << (x) << '\n'
#define debug(x) cout << #x << ": " << (x) << '\n'

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  int n; cin >> n;
  string s; cin >> s;
  int k; cin >> k;

  --k;
  char c = s[k];

  for (int i = 0; i < (int) s.size(); ++i){
    if (s[i] != c) cout << '*';
    else cout << s[i];
  }
  cout << endl;


  return 0;
}

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

using namespace std;

using ll = long long;
using vll = vector<ll>;
using vii = vector<int>;
using pii = pair<int, int>;

const ll INF = numeric_limits<ll>::max(),
         MOD = 1e9 + 7;

const int INF_i = numeric_limits<int>::max(),
          MAX = 1e6;

ll f(string &s, int D) {
    vll dp(D); // dp[j] = number of ways to get digit sum of a valid prefix % D = 0
    int prev = s[0] - '0';
    for (int d = 1; d < prev; d++) {
        dp[d % D] += 1;
    }

    prev %= D; // digit sum of prefix [0, i)
    for (int i = 1; i < s.size(); i++) {
        int di = s[i] - '0'; 
        vll new_dp(D);
        for (int d = 0; d < 10; d++) {
            if (d) (++new_dp[d % D]) %= MOD; // case '00000..0d'
            
            for (int j = 0; j < D; j++)
                (new_dp[(j + d) % D] += dp[j]) %= MOD;
            
            if (d < di) (++new_dp[(prev + d) % D]) %= MOD; // case 'd0d1d2..d(i-1)d'
        }
        swap(dp, new_dp);
        (prev += di) %= D;
    }
    if (!prev) (++dp[0]) %= MOD;
    return dp[0] % MOD;
}

int main() {
    cin.tie(NULL);
    ios_base::sync_with_stdio(false);

    string s;
    cin >> s;
    int D;
    cin >> D;
    cout << f(s, D) << '\n';

}

Measured memory_bytes: 256
using static System.Math;
using System;

public class hello
{
    public static void Main()
    {
        while (true)
        {
            string[] line = Console.ReadLine().Trim().Split(' ');
            if (line[0] == "0" && line[1] == "0" && line[2] == "0") break;
            var n = int.Parse(line[0]);
            var p = getTime(line[1]);
            var q = getTime(line[2]);
            var time = new int[24 * 60 + 1];
            for (int i = 0; i < n; i++)
            {
                var wn = int.Parse(Console.ReadLine().Trim());
                line = Console.ReadLine().Trim().Split(' ');
                for (int j = 0; j < wn; j++)
                {
                    time[getTime(line[2 * j])]++;
                    time[getTime(line[2 * j + 1])]--;
                }
            }
            var ans = getAns(time, n, p, q);
            Console.WriteLine(ans);
        }
    }
    static int getAns(int[] time, int n, int p, int q)
    {
        var timec = time.Length;
        for (int i = 1; i < timec; i++)
            time[i] += time[i - 1];
        var count = 0; var maxc = 0;
        for (int i = p; i < q; i++)
            if (time[i] < n) count++;
            else { maxc = Max(maxc, count); count = 0; }
        return Max(maxc, count);
    }
    static int getTime(string s) => s.Length == 4 ? int.Parse(s.Substring(0, 2)) * 60 + int.Parse(s.Substring(2)) : int.Parse(s.Substring(0, 1)) * 60 + int.Parse(s.Substring(1));
}



Measured memory_bytes: 15916
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define MT make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define RT return
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;

template<class Val>
struct BinaryIndexedTree {
    int n;
    vector<Val> t;
    BinaryIndexedTree() {}
    BinaryIndexedTree(int _n) :n(_n + 1), t(_n + 1) {}
    void add(int k, Val val) {
        k++;
        while (k < n) {
            t[k] += val;
            k += (k&-k);
        }
    }
    void set(int k, Val val) {
        add(k, -sum(k, k + 1));
        add(k, val);
    }
    Val sum(int k) {
        Val r = 0;
        while (k > 0) {
            r += t[k];
            k -= (k&-k);
        }
        return r;
    }
    Val sum(int l, int r) {
        return sum(r) - sum(l);
    }
};

const int MAX_N = 100005;
int N, A[MAX_N], B[MAX_N], C[MAX_N];

// sm(C[i]), sorted
int S[MAX_N], T[MAX_N];

// index of sum of y
int g(int y) {
    return lower_bound(T, T + N + 1, y) - T;
};

ll f(int x) {
    // cnt of sum left
    BinaryIndexedTree<int> bit(N + 1);
    int b = B[x];

    rep(i, N) {
        int c = A[i] >= b ? 1 : -1;
        T[i + 1] = S[i + 1] = S[i] + c;
    }

    sort(T, T + N + 1);
    
    ll cnt = 0;
    bit.add(g(0), 1);
    rep(i, N) {
        int j = g(S[i + 1]);
        cnt += bit.sum(0, j+1);
        bit.add(j, 1);
    }

    return cnt;
}

ll H(ll n) {
    n = n + 2 - 1;
    return n*(n - 1) / 2;
}

void solve() {
    cin >> N;
    rep(i, N) {
        cin >> A[i];
        B[i] = A[i];
    }

    sort(B, B + N);
    int M = unique(B, B + N) - B;

    ll need = (H(N) + 1) / 2;

    int ok = 0, ng = M;
    while (ng-ok > 1) {
        int mid = (ok + ng) / 2;
        if (f(mid) >= need) {
            ok = mid;
        } else {
            ng = mid;
        }
    }

    cout << B[ok] << endl;
}

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


Measured memory_bytes: 2180
// Math = ♥️

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

/*-------------------------------------------------------------------------------------------------------------------------*/
#define ll long long                  // Short form for long long
#define ld long double                // Short form for long double
typedef pair<ll, ll> ii;              // Pair of long long
typedef vector<ll> vi;                // Vector of long long
typedef vector<vi> vvi;               // Vector of vector of long long
typedef vector<ii> vii;               // Vector of pairs
typedef vector<vii> vvii;             // Vector of vector of pairs
#define pq priority_queue             // Max heap (To convert to min heap, use negative sign before every value)
#define ff first                      // For pairs
#define ss second                     // For pairs
#define pb push_back                  // Pushback to vector
#define mp make_pair                  // Makes pairs to be stored as pair
#define all(c) (c).begin(), (c).end() // Mainly used by me in sorting
// ordered_set adds two new functions to set - (set).find_by_order([kth element based on zero indexing]) and order_of_key()
// order_of_key returns number of elements less that parameter. If element exists, that order is its index
#define ordered_set tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>
/*-------------------------------------------------------------------------------------------------------------------------*/

int main(void)
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll n, W;
    cin >> n >> W;

    ll w[n], val[n];
    for (int i = 0; i < n; i++)
        cin >> w[i] >> val[i];

    ll dp[n + 1][W + 1];

    for (int i = 0; i <= W; i++)
        dp[0][i] = 0;

    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j <= W; j++)
        {
            if (j + w[i] > W)
                dp[i + 1][j] = dp[i][j];
            else
                dp[i + 1][j] = max(dp[i][j], dp[i][j + w[i]] + val[i]);
        }
    }

    ll maxi = dp[n][0];
    for (int i = 1; i <= W; i++)
        maxi = max(maxi, dp[n][i]);

    cout << maxi << "\n";
}


Measured memory_bytes: 79232
import java.util.*;

class Main{
	public static void main(String[] $){
		Scanner s=new Scanner(System.in);
		int n=s.nextInt(),d=s.nextInt(),r=s.nextInt();
		for(int q=0;q<n;++q)
			for(int i=0,a=s.nextInt();i*a+1<=d;++i)
				++r;
		System.out.println(r);
	}
}


Measured memory_bytes: 21844
import java.util.Scanner;

public class Main{
	public static void main(String args[]){

		Scanner sc = new Scanner(System.in);

		int n=sc.nextInt();
		int r[]=new int[n];
		int a,b;
		int counter=0;
		int mini;

		for (int i=0;i<n;++i){
			r[i]=sc.nextInt();
		}

		for (int i=0;i<n;++i){
			mini=i;
			for (int j=i+1;j<n;++j){
				if(r[mini]>r[j]){
					mini=j;
				}
			}
			if(i!=mini){
				a=r[mini];
				b=r[i];
				r[mini]=b;
				r[i]=a;
				++counter;
			}

		}

		for (int i=0;i<n;++i){
			System.out.print(r[i]);
			if(i != n-1)System.out.print(" ");
		}
		System.out.println();
		System.out.println(counter);

	}
}


Measured memory_bytes: 26304
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <random>
#include <cstdio>
#include <cmath>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int) n; i++)

int main() {
    int x,a,b; cin >> x >> a >> b ;
    if (b <= a)
    {
        cout << "delicious\n";
    } else if (b-a <= x) {
        cout << "safe\n";
    } else {
        cout << "dangerous\n";
    }
    return 0;
}

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

void dump(vector<int> d)
{
  rep(i, d.size())
  {
    printf("%d ", d[i]);
  }
  cout << endl;
}

int main()
{
  int N;
  cin >> N;
  vector<int> d(N);
  rep(i, N)
  {
    cin >> d[i];
  }

  // cout << N
  //      << endl;
  // dump(d);

  int total = 0;
  rep(i, N)
  {
    rep(j, N)
    {
      if (j >= i)
        continue;
      total += d[i] * d[j];
    }
  }
  cout << total << endl;
}


Measured memory_bytes: 256
def resolve():
    A, B, C = [int(i) for i in input().split()]
    K = int(input())
    if A < B and B < C:
        print("Yes")
        return
    for _ in range(K):
        if B >= C:
            C *= 2
        elif A >= B:
            B *= 2
        if A < B and B < C:
            print("Yes")
            return
    else:
        print("No")


resolve()


Measured memory_bytes: 9112