akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
 
#define IOS 		ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define sd(n)       scanf("%d", &n)
#define sdd(a,b)    scanf("%d %d", &a, &b)
#define sddd(a,b,c) scanf("%d %d %d", &a, &b, &c)
#define sld(n)      scanf("%lld", &n)
#define slld(a,b)   scanf("%lld %lld", &a, &b)
#define sllld(a,b,c) scanf("%lld %lld %lld", &a, &b, &c)
#define slu(n)      scanf("%llu", &n)
#define sllu(a,b)   scanf("%llu %llu", &a, &b)
#define slllu(a,b,c) scanf("%llu %llu %llu", &a, &b, &c)
#define ss(a)		scanf("%s", a)
#define inStrAftInSome cin.ignore(numeric_limits<streamsize>::max(),'\n')		//input string(with whitespace) after input something(char, int, bool, str)
#define all(a) 		a.begin(),a.end()
#define unq(x)      x.erase(unique(all(x)), x.end()
#define mp 			make_pair
#define sz(av) 		int((av).size())					//return size of vec
#define CLR(arr)    memset(arr, 0, sizeof(arr))			//assign 0 to whole arr
#define SET(vec)    memset(arr, -1, sizeof(arr))		//assign -1 to whole arr
#define CLRV(vec)	fill(vec.begin(), vec.end(), 0)		//assign 0 to whole vec
#define SETV(vec,n,a) vec.assign(n, a)	
#define vtd(rowsize,colsize,type,name) 		vector < vector <type> > name(rowsize,vector <type> (colsize)); 	//assign to first n elements value a in vec
#define SETB(a)		memset(a, true, sizeof(a))			//boolean array initialize by true value
#define CLRB(a)		memset(a, false, sizeof(a))			//boolean array initialize by false value
#define vintitr 	vector<int>::iterator
#define vlnlnitr 	vector<long long>::iterator
#define sintitr 	set<int>::iterator
#define slnlnitr 	set<long long>::iterator
#define aa			first
#define bb			second
#define mod 		1000000007
#define PI 			acos(-1.00)
#define psb 		push_back
#define ppb			pop_back
#define ppb			pop_back
#define psf			push_front
#define ppf			pop_front
#define in 			inset
#define rep(i, n) 	for(int i=0; i<n; i++)
#define repi(i,j,n) for(int i=j; i<n; i++)
#define rof(i, n)   for(int i=n-1; i>=0; i--)
#define min3(a,b,c) (min((c),min((a),(b))))
#define max3(a,b,c) (max((a),max((b),(c))))
#define __lcm(a, b)	a*b / __gcd(a, b)
#define __builtin_zerocount(a)	8*sizeof(a)-__builtin_popcount(a)-__builtin_clz(a)-__builtin_ctz(a)
#define D(t)        cerr << #t " = " <<t  << '\n'
#define DBG         cerr << "Hi!" << '\n'
 
 
typedef long long	 		ll;
typedef unsigned long long	llu;
typedef long double			ld;
typedef pair<int, int> 		pii;

int main()
{
//	freopen("t.in","r",stdin);
//	freopen("t.out","w",stdout);
	IOS;
	int n;
	cin >> n;
	cout << n*n*n << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

/**
 * Created by chinalife on 2019/7/24.
 */
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int t = Integer.valueOf(sc.nextLine());
        for(int i = 0;i < t;i++){
            String input = sc.nextLine();
            String[] intArr = input.split(" ");
            int[] inputInt = new int[intArr.length];
            for(int j = 0;j < intArr.length;j++){
                inputInt[j] = Integer.valueOf(intArr[j]);
            }
            boolean result = dfs(inputInt,0,0,0);
            if(result){
                System.out.println("YES");
            }else{
                System.out.println("NO");
            }
        }
    }
    public static boolean dfs(int[] input,int i,int left,int right){
        if(i == 10){
            return true;
        }
        if(input[i] > left){
            boolean result = dfs(input,i+1,input[i],right);
            if(result){
                return result;
            }
        }
        if(input[i] > right){
            boolean result = dfs(input,i+1,left,input[i]);
            if(result){
                return result;
            }
        }
        return false;
    }

}


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

#define int long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x) cout << #x << " = " << (x) << endl;
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define SP << " " <<

typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;
typedef vector<ll> vec;
typedef vector<P> pvec;
typedef vector<vector<ll>> vvec;
typedef vector<vector<P>> pvvec;
typedef priority_queue<ll> PQI;
typedef priority_queue<P> PQP;
typedef priority_queue<ll,vector<ll>,greater<ll>> PQIG;
typedef priority_queue<P,vector<P>,greater<P>> PQPG;

const vector<int> dx = {0, -1, 0, 1, 1, 1, -1, -1};
const vector<int> dy = {1, 0, -1, 0, 1, -1, 1, -1};
constexpr int MOD = (1000000007);
// const int MOD = (998244353);
// const int INF = (1 << 30); // 1073741824
const int INF = (1LL << 60); // 1152921504606846976
const double EPS = (1 >> 30);

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return 1;} return 0;}
template<class T> inline T ceil(T a, T b) {return T((a + b - 1)/b);}
template< typename T1, typename T2 > istream &operator>>(istream &is, pair< T1, T2 > &p) { is >> p.first >> p.second; return is; }

int nmax=200000; // 2*(10^5)
vvec g(nmax);



signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);
    //---------------------------------------------
    
    int n,m;
    cin>>n>>m;
    pvec a(n);
    rep(i,n){
        cin>>a[i];
    }
    pvec b(m);
    rep(i,m){
        cin>>b[i];
    }
    int memo=INF;
    int ans=0;
    rep(i,n){
        memo=INF;
        ans=0;
        rep(j,m){
            if(chmin(memo,abs(a[i].fs-b[j].fs)+abs(a[i].sc-b[j].sc))){
                ans=j;
            }
        }
        cout<<ans+1<<endl;
    }
}

Measured memory_bytes: 4992
#include<bits/stdc++.h>
using namespace std;
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int w,h,sx,sy,gx,gy,ans;
bool flag ;
int mas[22][22];
bool used[22][22];
typedef pair<int,int> P;
P s,g;
P go(P p,int i){
	while(1){
	 if(!(p.first>=0&&p.first<h&&p.second>=0&&p.second<w)){
		flag = true;
		return p;
	}
	if(mas[p.first][p.second]!=0)return p;
	p.first+=dx[i];
	p.second+=dy[i];
	}
}
void dfs(P p ,int cnt){
	if(cnt >= ans)return;
	    for(int i=0;i<4;i++){
	     int nx=p.first+dx[i],ny=p.second+dy[i];
		if((!(nx>=0&&nx<h&&ny>=0&&ny<w))||mas[nx][ny]==1)continue;
			flag = false;
			P p1 = go(P(nx,ny),i);
			if(flag)continue;
			nx=p1.first; 
			ny=p1.second;

			if(p1==g){
				ans = cnt;
				return;
			}
			if(mas[nx][ny]==1){
				mas[nx][ny]--;
				dfs(P(nx-dx[i],ny-dy[i]),cnt+1);
				mas[nx][ny]++;
			}
		}
	      return;
}

int main(){
	while(1){
		cin >> w >> h;
		if(w==0&&h==0)break;
		for(int i=0;i<h;i++){
			for(int j=0;j<w;j++){
				cin >> mas[i][j];
				if(mas[i][j]==2){
					sx=i,sy=j;
					s = P(sx,sy);
				}
				if(mas[i][j]==3){
					gx=i,gy=j;
					g = P(gx,gy);
				}
		          }
	        }
		 ans=11;
		 mas[sx][sy]=0;
		 dfs(P(sx,sy),1);
	  	 if(ans>=11)cout << -1 << endl;
		 else cout << ans << endl;
	    }
	return 0;
}



Measured memory_bytes: 3076
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define bg begin()
#define ed end()
#define all(x) x.bg,x.ed
#define pb push_back
#define pf push_front
#define eb emplace_back
using namespace std;
typedef long long ll;
template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}
template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;
using pi=pair<int,int>;
using vi=vc<int>;
void yes(){ cout << "Yes" << endl; }
void no(){ cout << "No" << endl; }
int SIZE(string s){return (int)s.size();}
const long long INF = 1LL << 60;

int main(){
    cout << fixed << setprecision(20);
    int n; cin >> n;
    vc<ll> ans(26,INF);
    rep(i,n){
        string s; cin >> s;
        map<int,int> m;
        int si = SIZE(s);
        rep(j,si)
            m[s[j]-'a']++;
        rep(j,26) chmin(ans[j], m[j]);
    }
    string ss = "";
    rep(i,26){
        if(ans[i] == INF) continue;
        while(ans[i] > 0){
            ss += 'a'+i;
            ans[i]--;
        }
    }
    cout << ss << endl;
    return 0;
}


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

int get_two(int b) {
  auto out = 0;
  while(b % 2 == 0 && b > 0) {
    out++;
    b /= 2;
  }
  return out;
}

int main(void){
  int num;
  std::cin >> num;
  std::vector<int> a(num);
  for(int i = 0; i < num; i++){
    int tmp;
    std::cin >> tmp;
    a[i] = tmp;
  }
  int min = 114514;
  for(auto x : a) min = std::min(min, get_two(x));
  std::cout << min << std::endl;
  return 0;
}


Measured memory_bytes: 888
import bisect
n=int(input())
A=sorted(list(map(int,input().split())))
B=sorted(list(map(int,input().split())))
C=sorted(list(map(int,input().split())))
ans=0
for b in B:
    ans+=(bisect.bisect_left(A,b)*(n-bisect.bisect_right(C,b)))

print(ans)

Measured memory_bytes: 23200
import itertools

n, m = map(int, input().split())

ls = [[] for _ in range(n)]

for _ in range(m):
    s, t = map(int, input().split())
    ls[s-1].append(t-1)
    ls[t-1].append(s-1)

count = 0
for per in itertools.permutations(range(n)):

    if per[0] != 0:
        continue
    for i in range(1, n):
        if per[i] not in ls[per[i-1]]:
            break
        if i == n-1:
            count += 1

print(count)


Measured memory_bytes: 9120
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		for(int i = 0; i < N; i++) {
			int a = sc.nextInt();
			int b = sc.nextInt();
			int c = sc.nextInt();
			boolean A = (a * a == b * b + c * c);
			boolean B = (b * b == a * a + c * c);
			boolean C = (c * c == a * a + b * b);
			if(A|B|C) {
				System.out.println("YES");
			} else {
				System.out.println("NO");
			}
		}
	}
}

Measured memory_bytes: 23372
#include <cstdio>
#include <iostream>

int N, M;

int main()
{
	scanf("%d %d", &N, &M);
	int l, i = 0;
	int sum = 0;
	while(std::cin >> l) {
		i++;

		sum += l;
	}

	if(N < sum) {
		printf("-1");
	} else {
		printf("%d", N - sum);
	}

	return 0;
}

Measured memory_bytes: 3828
#include <bits/stdc++.h>
#define int long long
using namespace std;

signed main() {
  int N, X;
  cin >> N >> X;
  
  vector<int> moto(N);
  int total = 0;
  int chisai = 10000;
  for( int i = 0; i < N; i++ ){
    cin >> moto.at(i);
    if( moto.at(i) < chisai ) chisai = moto.at(i);
    total += moto.at(i);
  }
  
  X = ( X - total ) / chisai;
  cout << N + X << endl;
  
    
}


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

using namespace std;

string s;
int cnt1=0;
int cnt[50]={0};
bool flag;

int main()
{
	cin>>s;
	int l=s.size();
	for(int i=0;i<l;i++)
	{
		int ASue=s[i]-'0';
		cnt[ASue]++;
		if(cnt[ASue]==2)
		{
			cnt1++;
			flag=true;
		}
		else
			flag=false;
	}
	if(flag&&cnt1==2)
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;
int main() {
    int N; cin >> N;
    vector<int> a(N, 0);
    int ma = 0; cin >> ma; int mi = ma; a[0] = ma;
    for (int i = 1; i < N; i++) {
        int n; cin >> n;
        ma = max(ma, n), mi = min(mi, n);
        a[i] = n;
    }
    long long int ans = 0;
    for (int i = mi; i <= ma; i++) {
        long long int tmp = 0;
        for (int j = 0; j < N; j++) tmp += pow(a[j] - i, 2);
        if (ans == 0) ans = tmp;
        ans = min(ans, tmp);
    }
    cout << ans << endl;
}


Measured memory_bytes: 3632
primes :: [Integer]
primes = 2 : filter isPrime [3,5..]
  where isPrime n = n > 1 && foldr (\x acc -> x * x > n || (n `mod` x /= 0 && acc)) True primes

solve :: Int -> Integer
solve n = sum $ take n primes

main :: IO ()
main = getContents >>= mapM_ (print . solve . read) . takeWhile (/="0") . lines

Measured memory_bytes: 6576
#include <iostream>
#include <vector>
using namespace std;
template <class T> inline bool chmin(T& a, T b) {
  if(a > b) {
    a = b;
    return true;
  }
  return false;
}
const int INF = 300000;

int main() {
  int N;
  cin >> N;
  vector<int> ps(N);
  for(int i = 0; i < N; ++i) {
    cin >> ps[i];
  }
  vector<int> mns(N, 0);
  int mn = INF;
  for(int i = 0; i < N; ++i) {
    chmin(mn, ps[i]);
    mns[i] = mn;
  }
  int ans = 0;
  for(int i = 0; i < N; ++i) {
    if(mns[i] >= ps[i]) {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <fstream>
#include <algorithm>
#include <iomanip>
#include <random>
#include <ctime>
#include <bitset>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <cstring>
#include <queue>
#include <deque>
#include <stack>
#include <climits>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#define ld long double
#define ull unsigned long long
#define ll long long
#define pb push_back
#define pii pair<int, int>
#define pll pair<ll, ll>
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fast_io cout.tie(0), cin.tie(0), ios_base::sync_with_stdio(0)
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("Ofast")
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
using namespace std;
//using namespace __gnu_pbds;
//typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
ld eps = (ld)1 / 1e6;
ll inf = LLONG_MAX, mod1 = 1e9 + 7, mod2 = 998244353;
ll sqr(ll a) { return a * a; }
ll qb(ll a) { return a * a * a; }
ll gcd(ll a, ll b) { return !a ? b : gcd(b % a, a); }
ll binpow(ll a, ll b, ll mod) { return b ? (b % 2 ? (a * (sqr(binpow(a, b / 2, mod)) % mod)) % mod : sqr(binpow(a, b / 2, mod)) % mod) : 1; }
ll binmult(ll a, ll b, ll mod) { return b ? (b % 2 ? (2 * binmult(a, b / 2, mod) + a) % mod : (2 * binmult(a, b / 2, mod)) % mod) : 0; }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
ll a[200001];

int main()
{
    fast_io;
    ll n, i, t, sum = 0, s = 0;
    cin >> n;
    for (i = 1; i <= n; i++) cin >> a[i], sum += a[i], sum %= mod1;
    for (i = 1; i < n; i++)
    {
        sum -= a[i];
        if (sum < 0) sum += mod1;
        t = sum * a[i];
        t %= mod1;
        s += t;
        s %= mod1;
    }
    cout << s;
    return 0;
}

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

template <class... Args>
void gin(Args&&... args) { (cin >> ... >> args); }
#define dbg(var) cout<<#var<<"="<<var<<" "
#define nl cout<<"\n"
#define fr(i,n) for(int i=0;i<n;i++)
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define fa(v) for(auto &i:v)
#define all(v) v.begin(),v.end()
#define sz(v) (int)(v.size())
//#define int long long

void solve(){
 int n; gin(n);
 cout << (n >= 30 ? "Yes":"No");

}
int32_t main()
{
   ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
   // int tst; cin >> tst; while(tst--)
   {
   	solve();
   }
}

Measured memory_bytes: 3644
import java.io.InputStream
import java.io.PrintStream
import java.util.*

class Abc081A(
    val input: InputStream,
    val output: PrintStream
) {
    fun proc() {
        val sc = Scanner(input)
        val a = sc.nextLine()
        val res = a.toCharArray().count { it == '1' }
        output.print(res)
    }
}

fun main(args: Array<String>) {
    Abc081A(System.`in`, System.out).proc()
}


Measured memory_bytes: 29352
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int A, B, C;
    int K;
    cin >> A >> B >> C;
    cin >> K;
    int count = 0;
    while (B <= A)
    {
        B *= 2;
        count++;
    }
    while (C <= B)
    {
        C *= 2;
        count++;
    }

    if (count <= K)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 3652
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <set>
#include <iomanip>
#include <stdio.h>
#include <sstream>
#include <bits/stdc++.h>
using namespace std;
int main(void){
  long long int r,D,x;
  cin>>r>>D>>x;
  for(long long int i=0; i<10; i++){
    x=r*x-D;
    cout<<x<<endl;
  }
}

Measured memory_bytes: 3612
#include <iostream>
#include <algorithm>
#include <string>
#include <sstream>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstring>
#include <cmath>
#include <cstdio>

using namespace std;

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

typedef long long ll;

int main(){
    int N;
    int score[200][3];
    int ans[200];
    cin >> N;
    REP(i,N)cin >> score[i][0] >> score[i][1] >> score[i][2];
    memset(ans,0,sizeof ans);
    REP(i,3){
        REP(j,N){
            int flag = 1;
            REP(k,N){
                if(j==k)continue;
                if(score[k][i] == score[j][i]){
                    flag=0;
                    break;
                }
            }
            if(flag)ans[j]+=score[j][i];
        }
    }
    REP(i,N)cout << ans[i] << endl;
    return 0;
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef map<int, int> mi;
typedef set<int> si;
#define VV(T) vector<vector< T > >
#define dump(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl

#define rep(i, n) REP(i, 0, n)                              // 0, 1, ..., n-1
#define REP(i, x, n) for(int i = x; i < n; i++)             // x, x + 1, ..., n-1
#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(v) (v).begin() , (v).end()
#define RALL(v) (v).rbegin(), (v).rend()

#define pb push_back
#define pu push
#define mp make_pair
#define fi first
#define sc second

#define COUT(x) cout << (x) << endl
#define VECCIN(x) for(auto&youso_: (x) )cin>>youso_
#define VECCOUT(x) for(auto&youso_: (x) )cout<<youso_<<" ";cout<<endl

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


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

    int r, D, x; cin >> r >> D >> x;
    rep(i, 10) {
        x = r * x  - D;
        COUT(x);
    }
}

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

void solve() {
  int n;
  int64_t k;
  cin >> n >> k;

  vector<int> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  sort(a.begin(), a.end());

  auto pos = lower_bound(a.begin(), a.end(), 0);
  auto rpos_left = make_reverse_iterator(pos);
  auto non_zero_pos = upper_bound(a.begin(), a.end(), 0);
  auto rpos_right = make_reverse_iterator(non_zero_pos);

  auto pos_cnt = a.end() - pos;
  auto neg_cnt = n - pos_cnt;
  auto non_zero_pos_cnt = a.end() - non_zero_pos;
  auto zero_cnt = pos_cnt - non_zero_pos_cnt;

  constexpr int64_t limit = 1'000'000'000LL;
  int64_t left = -limit * limit;
  int64_t right = limit * limit + 1;
  while (left <= right) {
    int64_t lcnt = 0;
    int64_t ucnt = 0;
    auto mid = left + (right - left) / 2;

    if (mid == 0) {
      lcnt = neg_cnt * non_zero_pos_cnt;
      ucnt = lcnt;
      for (int i = 0; i < zero_cnt; ++i) {
        ucnt += n - 1 - i;
      }
      assert(lcnt <= ucnt);
    } else if (mid < 0) {
      for (auto it = a.begin(); it != pos; ++it) {
        auto lit =
            lower_bound(a.rbegin(), rpos_right, mid / *it, greater<int64_t>{});
        auto uit =
            lower_bound(lit, rpos_right, (mid + 1) / *it, greater<int64_t>{});
        auto dl = lit - a.rbegin();
        auto du = uit - a.rbegin();
        assert(dl <= du);
        lcnt += dl;
        ucnt += du;
      }
    } else {
      for (auto it = rpos_left; it != a.rend(); ++it) {
        auto lit =
            upper_bound(rpos_left, it, (mid - 1) / *it, greater<int64_t>{});
        auto uit = upper_bound(lit, it, mid / *it, greater<int64_t>{});
        auto dl = non_zero_pos_cnt + lit - rpos_left;
        auto du = non_zero_pos_cnt + uit - rpos_left;
        assert(dl <= du);
        lcnt += dl;
        ucnt += du;
      }
      for (int i = 0; i < zero_cnt; ++i) {
        lcnt += n - 1 - i;
        ucnt += n - 1 - i;
      }
      for (auto it = non_zero_pos; it != a.end(); ++it) {
        auto lit = upper_bound(it + 1, a.end(), (mid - 1) / *it);
        auto uit = upper_bound(lit, a.end(), mid / *it);
        auto dl = lit - it - 1;
        auto du = uit - it - 1;
        assert(dl <= du);
        lcnt += dl;
        ucnt += du;
      }
    }
    assert(lcnt <= ucnt);
    if (k <= lcnt) {
      right = mid;
    } else if (ucnt < k) {
      left = mid + 1;
    } else {
      cout << mid << endl;
      return;
    }
  }
  assert(false);
}

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

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

int N;
LL P[15][2];
LL Z[15];

LL XD[1<<15][15];
LL YD[1<<15][15];

vector<UL> MX;
vector<UL> M;

UL popcount(UL x){
 x = (x&0x55555555) + ((x>>1)&0x55555555);
 x = (x&0x33333333) + ((x>>2)&0x33333333);
 x = (x&0x0f0f0f0f) + ((x>>4)&0x0f0f0f0f);
 x = (x&0x00ff00ff) + ((x>>8)&0x00ff00ff);
 x = (x&0x0000ffff) + ((x>>16)&0x0000ffff);
 return x;
}

LL ans[16];

int main() {
 cin>>N;
 rep(i,N) cin>>P[i][0]>>P[i][1]>>Z[i];

 rep(i,N) XD[0][i]=abs(P[i][0]);
 rep(i,N) YD[0][i]=abs(P[i][1]);
 rep(i,15)rep(j,15) rep(m,1<<j){
  int p=m|(1<<j);
  XD[p][i]=min(XD[m][i],abs(P[j][0]-P[i][0]));
  YD[p][i]=min(YD[m][i],abs(P[j][1]-P[i][1]));
 }
 rep(i,15) rep(p,1<<15){ XD[p][i] *= Z[i]; YD[p][i] *= Z[i]; }

 rep(i,1<<10) if(!(i&(i<<5)))
  MX.push_back((i>>5<<15)|(i&0x1f));
 for(UL x:MX) for(UL y:MX) for(UL z:MX)
  M.push_back((x<<10)|(y<<5)|z);

 rep(i,16) ans[i]=1000000000000000ll;

 for(UL m:M){
  int pops = popcount(m);
  UL xm = m>>15;
  UL ym = m&0x7fff;
  LL tmp=0;
  rep(j,15) tmp += min(XD[xm][j],YD[ym][j]);
  ans[pops] = min(ans[pops],tmp);
 }

 rep(i,N+1) cout<<ans[i]<<endl;

 return 0;
}



Measured memory_bytes: 76676
#include <bits/stdc++.h>
#define rep(i,n) for(long long i = 0; i < (long long)(n); ++i)

using namespace std;
using ll = long long;

int main() {
	string ans = "pairwise";
	ll n;
	cin >> n;
	bool set = false;
	vector<ll> a(n);
	rep(i, n) {
		cin >> a[i];
		if (a[i] == 1) {
			a[n-1] = 1e9;
			i--;
			n--;
			set = true;
		}
	}
	sort(a.begin(), a.end());
	if (n < 100000) {
		vector<bool> ok(1000005, true);
		rep(i,n) {
			if (ok[a[i]] == false) ans = "setwise";
			else {
				ll now = a[i];
				for (ll j = 2; j * j <= a[i]; j++) {
					while (now % j == 0) now /= j;
					if (a[i] % j == 0) {
						if (ok[j] == true) {
							ll k = 1;
							while (j * k < 1000005) {
								ok[j * k] = false;
								k++;
							}
						}
					}
				}
				if (now != 1) {
					ll k = 1;
					while (now * k < 1000005) {
						ok[now * k] = false;
						k++;
					}
				}
			}
			if (ans == "setwise") i = n - 1;
		}
	}
	else ans = "setwise";
	ll x = a[0];
	rep(i, n) {
		x = __gcd(a[i], x);
	}
	if (x != 1 && !set) ans = "not";
	cout << ans << " " << "coprime" << endl;
	return 0;
}


Measured memory_bytes: 11192
#include <bits/stdc++.h>
#define int long long
#define all(c) (c).begin(),(c).end()
#define pii pair<long long,long long>
#define endl '\n'

using namespace std;

signed main(){
    std::ios::sync_with_stdio(false);
    int k;
    int ans=0;
    cin >> k;
    for(int i=1;i<=k;i++){
        for(int j=1;j<=k;j++){
            for(int l=1;l<=k;l++){
                ans+=__gcd(__gcd(i,j),l);
            }
        }
    }
    cout << ans;
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,i,j,l,m,k=0,ans=0;
  cin>>n;
  vector<int> a(n);
  vector<vector<int>> xy(280,vector<int>(2));
  for(i=0;i<n;i++){
    cin>>a.at(i);
    for(j=0;j<a.at(i);j++){
      cin>>xy.at(k).at(0)>>xy.at(k).at(1);
      k++;
    }
  }
  for(i=0;i<(1<<n);i++){
    bitset<15> b(i);
    vector<int> c(n,-1);
    bool f=true;
    k=0;
    m=0;
    for(j=0;j<n;j++){
      if(b.test(j)){
        m++;
        if(c.at(j)==-1) c.at(j)=1;
        else if(c.at(j)==0) f=false;
        for(l=0;l<a.at(j);l++){
          if(c.at(xy.at(k).at(0)-1)==-1) c.at(xy.at(k).at(0)-1)=xy.at(k).at(1);
          else if(c.at(xy.at(k).at(0)-1)!=xy.at(k).at(1)) f=false;
          k++;
        }
      }
      else{
        if(c.at(j)==-1) c.at(j)=0;
        else if(c.at(j)==1) f=false;
        for(l=0;l<a.at(j);l++) k++;
      }
    }
    if(f==true && ans<m) ans=m;
  }
  cout<<ans<<endl;
}

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

int main() {
	string S;
	cin >> S;
	int ans = 0, l=S.size();
	for (int i = 0;i < l;++ i) ans += S[i] + i & 1;
	cout << min(ans, l-ans);
	return 0;
}
/*
31536000のコメント解説欄
ここテンプレで用意してるから、A問題とかだとこの先空欄の危険あり
また、コンテスト後に https://31536000.hatenablog.com/ で解説していると思うので、良かったら読んでねー

最終系は010101…か101010…なので、どっちがより変える数が少ないか数えておけばいい

*/

Measured memory_bytes: 512
# include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pii pair<int,int>
typedef long long ll;
string s;
ll ans;
int kiri[500005],kanan[500005];
int arr[500005];
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin>>s;
    memset(kiri,-1,sizeof(kiri));
    memset(kanan,-1,sizeof(kanan));
    for(int i=0;i<s.size();i++){
        if(s[i]=='<') {
            if(i!=0 && kiri[i-1]!=-1){
                kiri[i]=kiri[i-1]+1;
            }
            else kiri[i]=0;
        }
        
    }
    for(int i=s.size()-1;i>=0;i--){
        if(s[i]=='>') {
            if(kanan[i+1]!=-1){
                kanan[i]=kanan[i+1]+1;
            }
            else kanan[i]=1;
        }
        
    }
    for(int i=0;i<s.size();i++){
        if(i!=0 && kiri[i-1]!=-1 && kanan[i]!=-1){
            arr[i]=max(kiri[i-1]+1,kanan[i]);
        } 
        else if(kiri[i]!=-1) arr[i]+=kiri[i];
        else if(kanan[i]!=-1)arr[i] += kanan[i];
    }
    for(int i=0;i<=s.size()-1;i++){
        ans+=arr[i];
    }
    if(s.back()=='>') ans+=0;
    else ans+=kiri[s.size()-1]+1;
    cout<<ans<<endl;
}






Measured memory_bytes: 9704
lines = readlines(chomp: true).map{|line| line.split(' ').map(&:to_i)}
 
n = lines[0][0]
k = lines[0][1]
 
result = n
 
for i in 1..n
  for j in 1..k
    if lines[2 * j].include?(i) then
      result = result - 1
      break
    end
  end
end
 
print result

Measured memory_bytes: 14268
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <cassert>
#include <memory>
#include <stack>
#include <set>
#include <map>

#define INF 1000000000
#define MOD 1000000007
typedef long long ll;
typedef unsigned long long ull;
using namespace std;

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

  int N; cin>>N;
  vector<int> dp(N+10);
  dp[0] = 0;
  for(int i=1; i<=N; i++) {
    dp[i] = INF;
    int power = 1;
    while(power <= i) {
      dp[i] = min(dp[i], dp[i-power] + 1);
      power *= 6;
    }

    power = 1;
    while(power <= i) {
      dp[i] = min(dp[i], dp[i-power] + 1);
      power *= 9;
    }
  }

  cout << dp[N] << endl;
}


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

#define TYPE(c)   remove_reference_t<decltype(c)>
#define REP(i, n) for(TYPE(n) i = 0; i < n; i++)
#define FOR(v, c) for(TYPE(c.begin()) v = c.begin(); v != c.end(); v++)
#define ALL(c)    c.begin(), c.end()
#define SORT(c)   sort(ALL(c))
#define RSORT(c)  sort(ALL(c), greater<TYPE(c)::value_type>())
#define UNIQUE(c) c.erase(unique(ALL(c)), c.end())

using namespace std;
using ll = long long;

constexpr int MOD  = (int)1e9 + 7;
constexpr int INF  = (int)1e9 + 1;
constexpr ll  LINF = (ll)1e18 + 1;
template<typename T> constexpr bool chmax(T& a, const T& b)
{ if(a < b) { a = b; return true; } else { return false; } }
template<typename T> constexpr bool chmin(T& a, const T& b)
{ if(b < a) { a = b; return true; } else { return false; } }
template<typename S, typename T> ostream& operator<<(ostream &os, const pair<S, T>& p)
{ return os << "(" << p.first << "," << p.second << ")"; }
ostream& operator<<(ostream &os, const string& s)
{ FOR(v, s) os << *v; return os; }
template<typename T> auto operator<<(ostream& os, const T& t)
    -> typename conditional<true, ostream&, decltype(*t.begin())>::type
{ os << "["; FOR(v, t) { if(v != t.begin()) os << ","; os << *v; } os << "]"; return os; }

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

    ll N;
    std::cin >> N;
    std::vector<ll> A(N);
    REP(i, N) {
        std::cin >> A[i];
    }

    ll ans = 0;
    REP(i, N) {
        ans += A[i] / 2;
        if(i != N - 1 && A[i] % 2 == 1 && 1 <= A[i + 1]) {
            ans++;
            A[i + 1]--;
        }
    }
    std::cout << ans << std::endl;

    return 0;
}


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

using namespace std;
typedef long long ll;
//typedef unsigned long long ll;

#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define sz(x) ll(x.size())
//typedef pair<ll, int> P;
typedef pair<ll, ll> P;
//const double INF = 1e10;
const ll INF = LONG_LONG_MAX / 10;
//const ll INF = 1e15;
const ll MINF = LONG_LONG_MIN;
//const int INF = INT_MAX / 10;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
//typedef pair<int, int> P;
//typedef pair<double, double> P;

bool contain(set<P> &s, P a) { return s.find(a) != s.end(); }

//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);


void print_line(vector<ll> &line) {
    if (line.size() == 0ll) {
        cout << endl;
        return;
    }
    for (ll i = 0; i < line.size(); i++) {
        cout << line[i];
        if (i == line.size() - 1) cout << endl;
        else cout << ' ';
    }
}


typedef priority_queue<long long, vector<long long>, greater<long long>> PQ_ASK;
const int mod = 1000000007;

int main() {
    set<ll> a;
    int q;
    cin >> q;
    rep(i, q) {
        int command;
        ll x;
        cin >> command >> x;

        if (command == 0) {
            a.insert(x);
            cout << a.size() << endl;
        } else {
            cout << (a.find(x) != a.end()) << endl;
        }

    }

}



Measured memory_bytes: 12448
N,X = list(map(int,input().split()))
L = list(map(int,input().split()))

zahyou = [0]*(N+1)

for i in range(1,N+1):
    zahyou[i] = zahyou[i-1] + L[i-1]
    
count = 0

for i in range(N+1):
    if zahyou[i] <= X:
        count+=1
        
print(count)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define pi acos(-1)
#define ll long long
#define pii pair<ll,ll>
#define debug(a) cout<<a<<'\n'
#define maxn 100009 /// Still trying to be normal
#define MOD 1000000007
#define F first
#define S second
#define rep(i, a, b) for(ll i = a; i < (b); ++i)
#define per(i, b, a) for(ll i = b-1; i>=a ; i--)
#define trav(a, x) for(auto& a : x)
#define allin(a , x) for(auto a : x)
#define all(x) begin(x), end(x)
#define sz(x) (ll)(x).size()
using namespace std;
const ll INF = 1e9 + 15;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll x;
    cin>>x;
    ll acum=100;
    ll ans=0;
    while(acum<x){
        acum+=(ll)(acum*(0.01));
        ans++;
    }
    cout<<ans<<'\n';
    return 0;  
}

Measured memory_bytes: 3640
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <queue>
#include <fstream>
#include <string>
#include <math.h>
#include <set>
#include <string>
#include <bitset>
#include <fstream>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
//typedef pair<ll, P> T;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define revrep(i, n) for (ll i = (n) - 1; i >= 0; i--)
#define f first
#define s second
#define pb push_back

ll mod = 1000000007;
const ll INF = 100000000000010000;
//const ull B = 998244353;
//ll kai[3010];

//void pres(double A, ll x = 20) { printf("%.20f\n", x); }

vector<ll> dx = { 0, 1, 0, -1, 1, -1, 1, -1, 0};
vector<ll> dy = { 1, 0, -1, 0, 1, 1, -1, -1, 0};

void chmin(double& x, double y) {
	x = min(x, y);
}

void chmax(double& x, double y) {
	x = max(x, y);
}

ll pow_long(ll x, ll y) {
	ll res = 1;
	while (y > 0) {
		if (y % 2 == 1) res *= x;
		x *= x;
		y /= 2;
	}
	return res;
}

void test() {
	cout << "888888888888888888888888" << endl;
}

ll gcd(ll x, ll y) {
	if (y == 0) return x;
	return gcd(y, x % y);
}

ll pow_mod(ll x, ll k) {
	x %= mod;
	ll res = 1;
	while (k > 0) {
		if (k % 2) {
			res *= x; res %= mod;
		}
		x *= x; x %= mod;
		k /= 2;
	}
	return res;
}

ll div_mod(ll x) {
	return pow_mod(x, mod - 2);
}

//コンビネーション
const int MAXcomb = 1000010;
ll fac[MAXcomb], finv[MAXcomb], inv[MAXcomb];
//facはn!,finvは1/n!
//invは逆元
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAXcomb; i++) {
		fac[i] = fac[i - 1] * i % mod;
		inv[i] = mod - inv[mod%i] * (mod / i) % mod;
		finv[i] = finv[i - 1] * inv[i] % mod;
	}
}
ll comb(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * finv[k] % mod * finv[n - k] % mod;
}

ll N, R;

void solve() {
	cin >> N >> R;
	if (N >= 10) cout << R << endl;
	else cout << R + 100 * (10 - N) << endl;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll T = 1;
	//cin >> T;
	rep(i, T) solve();
}


Measured memory_bytes: 256
/*
 *  AUTHOR : MANAV PATEl
*/
#include<bits/stdc++.h>
#include<functional>
//#include<boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;
using namespace std;

namespace fastio {

	template <class T> istream &operator>>(istream &os, vector<T> & vec) {
		for (auto &u : vec)os >> u;
		return os;
	}
	template <class T> ostream &operator<<(ostream &os, const vector<T> & vec) {
		for (auto &u : vec)os << u << " ";
		return os;
	}
	template<class T1, class T2> inline istream& operator>>(istream& os, pair<T1, T2>& p) {
		return os >> p.first >> p.second;
	}
	template<class T1, class T2> ostream& operator<<(ostream& os, const pair<T1, T2>& p) {
		return os << p.first << " " << p.second;
	}
	template <class T> ostream &operator<<(ostream &os, set<T> & con) {
		for (auto &u : con) os << u << " ";
		return os;
	}
	void re() {}
	template <typename T, typename... args> void re(T& x, args&... tail) {
		cin >> x;
		re(tail...);
	}
	void pr() {}
	template <typename T> void pr(const T& x) {
		cout << x;
	}
	template <typename T, typename... args> void pr(const T& x, const args&... tail) {
		cout << x << " ";
		pr(tail...);
	}
	template <typename... args> void prln(const args&... tail) {
		pr(tail...);
		cout << "\n";
	}
}
using namespace fastio;

typedef long long int ll;
typedef long double ld;

const ll mod = 1e9+7;
const ll mod1 = 998244353;

#define fill(a)  memset(a, 0, sizeof(a))
#define fst first
#define snd second
#define mp make_pair
#define pb push_back

int main()
{
	cin.sync_with_stdio(false);
	cin.exceptions(cin.failbit);
	cin.tie(0);
	int n;
	re(n);
	vector <pair<int,int > > v;
	for(int i = 0; i <n; i++)
	{
		int x, y;
		re(x,y);
		v.pb({y,x});
	}
	sort(v.begin(),v.end());
	ll sum = 0, cnt = 0;
	for(int i = 0; i <n; i++)
	{
		sum += v[i].snd;
		if(sum <= v[i].fst)
		{
			cnt++;
		}
	}
	if(cnt == n) prln("Yes");
	else prln("No");
}


Measured memory_bytes: 2420
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl '\n'

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n, m;cin>>n>>m;
	vector<int> bulbs[m];
	for(int i = 0;i < m; ++i){
		int x;cin>>x;
		while(x--){
			int t;cin>>t;
			bulbs[i].push_back(t-1);
		}
	}
	int p[m];
	for(int i = 0; i < m;++i) cin>>p[i];
	int val = 1<<n;
	int cnt = 0;
	for(int i = 0; i < val; ++i){
		int temp = 0;
		for(int j = 0; j < m;++j){
			int ncnt = 0;
			for(auto x : bulbs[j]){
				if(i & 1<<x){
					ncnt++;
				}
			}
			if(ncnt%2==p[j]) temp++;
		}
		if(temp==m) cnt++;
	}
	cout<<cnt<<endl;
	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
	int N,M;
	cin>>N>>M;
	unordered_map<int,long> X;
	int A;
	int sum=0;
	long long total = 0;
	for(int i=0;i<N;i++){
		cin>>A;
		sum=(sum+A)%M;
		if(X.find(sum)!=X.end()){
			X[sum]++;
		}else{
			X[sum]=1;
		}
		if(sum%M==0)total++;
	}
	for(auto pair:X){
		total+=pair.second*(pair.second - 1)/2;
	}
	cout<<total<<endl;
}

Measured memory_bytes: 3596
using System;
using System.Text;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Threading.Tasks;
class Program
{
	static void Main(string[] args)
	{
		var input = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
		int H = input[0];
		int W = input[1];
		var input2 = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
		int h = input2[0];
		int w = input2[1];
		int ans = H * W - h * W - w * H + h * w;
		Console.WriteLine(ans);
	}
}


Measured memory_bytes: 13268
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <bitset>
using namespace std;

typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define index(xs, x) (int)(lower_bound(all(xs), x) - xs.begin())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007

int count_ab(string s) {
  //cout<<"count_ab("<<s<<")\n";
  vector<int> pos_a, pos_b;
  rep(i, s.length()) if (s[i] == 'a') pos_a.pb(i);
  rep(i, s.length()) if (s[i] == 'b') pos_b.pb(i);

  int ctr = 0, lp = -1;
  rep(i, pos_a.size()) if (lp < pos_a[i]) {
    ctr++;
    lp = pos_b[i];
  }
  return ctr;
}

string solve_ba(string s) {
  vector<int> pos_a, pos_b;
  rep(i, s.length()) if (s[i] == 'a') pos_a.pb(i);
  rep(i, s.length()) if (s[i] == 'b') pos_b.pb(i);
  int num = pos_a.size();
  string m = "";
  rep(offset, num) {
    int a = offset, b = offset;
    string o = "";
    while (a < num || b < num) {
      if (a < num && (b == num || pos_a[a] < pos_b[b])) a++, o += 'a';
      else b++, o += 'b';
    }
    //cout<<"offset="<<offset<<": "<<o<<"\n";
    m = max(m, o);
  }
  //cout<<"solve_ba("<<s<<") = "<<m<<"\n";
  return m;
}

int N;
string S;
signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  cin >> N >> S;
  vector<string> block_list;

  int a = 0, b = 0;
  string buf = "";
  rep(i, 2*N) {
    buf += S[i];
    if (S[i] == 'a') a++;
    else b++;
    if (a == b) {
      a = b = 0;
      block_list.pb(buf);
      buf = "";
    }
  }
  assert(buf.empty());

  vector<pair<string, int> > list2;
  rep(i, block_list.size()) {
    string s = block_list[i];
    if (s[0] == 'b') {
      list2.pb(make_pair(solve_ba(s), -i));
    }
  }
  sort(all(list2), greater<pair<string, int> >());
  string out = "";
  int lp = -1;
  for (auto p : list2) {
    int ord = -p._2;
    if (lp < ord) {
      out += p._1;
      lp = ord;
    }
  }

  int add = 0;
  while (!block_list.empty() && block_list.back()[0] == 'a') {
    add += count_ab(block_list.back());
    block_list.pop_back();
  }
  //cout<<"add="<<add<<"\n";
  rep(_, add) out += "ab";
  cout << out << "\n";
  return 0;
}


Measured memory_bytes: 512
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
	int a,b,c;
	cin>>a>>b>>c;
	int sum = 0;
	if(c>a){
		sum+=a+1;
		c-=a+1;
	}
	else{
		sum+=c;
		c=0;
	}
	if(b>c){
		sum+=b+c;
	}
	else{
		sum+=b*2;
	}
	cout<<sum<<endl;
	return 0;
} 

Measured memory_bytes: 256
import java.util.*; 

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

  		int[] w=new int[n];
  		int s2=0;
		for(int c=0;c<n;c++){
    		w[c]=sc.nextInt();
          	s2+=w[c];
    	}
  		int s1=0;
  		int min=s2-s1;
  		
  
  		for(int a=0;a<n-1;a++){
        	s1+=w[a];
            s2-=w[a];
           if(Math.abs(s2-s1)<=min){
           	min=Math.abs(s2-s1);
           }else{
           	break;
           }
        
        }

    	System.out.println(min);
    }
}

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

using namespace std;

int main(){
    int n;
    cin >> n;
    int x[n];
    for(int i=0;i<n;i++)cin >> x[i];
    int tmp[n];
    for(int i=0;i<n;i++)tmp[i] = x[i];
    sort(tmp, tmp+n);

    int med = n/2;
    for(int i=0;i<n;i++){
        if(x[i]>=tmp[med])cout << tmp[med-1] << endl;
        else cout << tmp[med] << endl;
    }
}


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

int main() {
	string S;
	cin >> S;
	rep(i,3){
		if (S[i] == '1') {
			S[i] = '9';
		}
		else if (S[i] == '9') S[i] = '1';
	}
	cout << S << endl;
	return 0;
}


Measured memory_bytes: 3568
# 全パターンを書き並べるのは面倒
# bit全探索: https://qiita.com/gogotealove/items/11f9e83218926211083a をコピペ，加筆

n = input()
op_cnt = len(n) - 1  # すき間の個数
for i in range(2 ** op_cnt):
    op = ["-"] * op_cnt  # あらかじめ ["-", "-", "-"] というリストを作っておく
    for j in range(op_cnt):
        if ((i >> j) & 1): # ビットを右にシフトし，1だったら以下の処理を行う
            op[op_cnt - 1 - j] = "+"  # フラグが立っていた箇所を "+" で上書き

    formula = ""
    for p_n, p_o in zip(n, op + [""]):  # 少々モヤッとする
        formula += (p_n + p_o)
    if eval(formula) == 7: # eval: 文字列を式として評価してくれる
        print(formula + "=7")
        break

Measured memory_bytes: 3060
/// Containers Start
#include <algorithm>
#include <bitset>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
/// C Header Files
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <math.h>
#include <stdio.h>
/// Containers End

using namespace std;

/// Math Start
#define PI acos(-1.0)
#define Pi 3.141592653589793
#define EPS (1e-7)
#define INF (0x3f3f3f3f)
/// Math End

/// Extra Start
#define nn '\n'
#define pb push_back
#define ull unsigned long long
#define ll long long
#define MOD 1000000007
#define sz(a) int((a).size())
#define space " "
#define All(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
/// Extra End

#define rep(i, n) for (int i = 0; i < n; i++)
#define Cini(a)                                                                \
    int a;                                                                     \
    cin >> a;
#define Cinii(a, b)                                                            \
    int a, b;                                                                  \
    cin >> a >> b;
#define Ciniii(a, b, c)                                                        \
    int a, b, c;                                                               \
    cin >> a >> b >> c;
#define Cins(s)                                                                \
    string s;                                                                  \
    cin >> s;
#define Cinss(s1, s2)                                                          \
    string s1, s2;                                                             \
    cin >> s1 >> s2;
#define Cinc(c)                                                                \
    char c;                                                                    \
    cin >> c;
/// Functions End


/// Debug Start
#define deb(x) cout << #x << ": " << x << endl
#define deb2(x, y) cout << #x << ": " << x << '\t' << #y << ": " << y << endl;
#define deb3(x, y, z)                                                          \
    cout << #x << ": " << x << '\t' << #y << ": " << y << '\t' << #z << ": "   \
         << z << endl;
/// Debug End

int dx[] = {-1, 0, 1, 0};
int dy[] = {0, -1, 0, 1};

/**>>>>>>>>>>>>>>>>>>> END <<<<<<<<<<<<<<<<<<**/

/// template


signed main(void) {
    cin.sync_with_stdio(false);
    cin.tie(0);
    Cinii(N,D);
    cout << ceil((double)N/(2*D+1)) << nn;
    return 0;
}

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

int main(void)
{
    int N;
    cin >> N;

    string S;
    cin >> S;

    if (N % 2 == 1) {
        cout << "No" << endl;

        return 0;
    }

    string str = S.substr(0, N / 2);
    string str2 = str + str;
    if (S == str2)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 256
"""
DDD PDDDDDP 5+1
DDP PDDDDPP 4+0
DPD PDDDPDP 4+2
DPP PDDDPPP 3+1

PDD PDPDDDP 4+2
PDP PDPDDPP 3+2
PPD PDPDPDP 3+3
PPP PDPDPPP 2+2
"""

t = input()
tt = t.replace('?', 'D')
print(tt)


Measured memory_bytes: 9428
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <tuple>
#include <numeric>
#define rep(i, s, g) for ((i) = (s); (i) < (g); ++(i))
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll MOD = 1e9 + 7;
const ll INF = (1ll << 60);

int main(void)
{
    ll a, b, n;

    cin >> a >> b >> n;

    if (b <= n)
    {
        n = b - 1;
    }

    cout << floor(a * n / b) - a * floor(n / b) << endl;
}


Measured memory_bytes: 3780
#include <iostream>
#include <string>
#include <set>
#include <regex>
#include <locale>
using namespace std;

int main () {
  string a, b, c;
  cin >> a >> b >> c;
  
  locale loc;
  cout << toupper(a[0], loc) << toupper(b[0], loc) << toupper(c[0], loc) << endl;
}

Measured memory_bytes: 3116
#include <stdio.h>
#include <string.h>
int max(int a,int b){
  if(a<b)return b;
  else return a;
}
int lcs(char *x,char *y){
  
  int i,j;
  int xlen,ylen;
  int dp[1001][1001];
    
  xlen=strlen(x);
  ylen=strlen(y);
  for(i=0;i<=xlen;i++)dp[i][0]=0;
  for(j=0;j<=ylen;j++)dp[0][j]=0;
  for(i=0;i<xlen;i++){
    for(j=0;j<ylen;j++){
      if(x[i]==y[j]) dp[i+1][j+1]=dp[i][j]+1;
      else dp[i+1][j+1]=max(dp[i+1][j],dp[i][j+1]);
    }
  }
  return dp[xlen][ylen];
}
int main(){
  int q;
  char x[1001];
  char y[1001];
  int leng;
  scanf("%d",&q);
  while(q>0){
    scanf("%s",x);
    scanf("%s",y);
  
    printf("%d\n",lcs(x,y));
    q--;
  }
  return 0;
}



Measured memory_bytes: 5600