akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdint>
#include <complex>
using namespace std;

int main() {

    uint64_t N;

    uint64_t a, b, ans, best = INT64_MAX;

    cin >> N;

    for (uint64_t i = 1; i <= sqrt(N); i++) {
        
        if (N % i == 0) {
            a = i; 
            b = N / i;
            ans = std::to_string(std::max(a,b)).length();
            if (best > ans) {
                best = ans;
            }
            if (a > b) break;
        }
    }

    cout << best << endl;

    return 0;
}

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

#define endl '\n'

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

    int x, t;
    cin >> x >> t;
    if(x - t <= 0)
        cout << 0;
    else
        cout << (x - t);

    return 0;
}

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

const int MAX = 1120;
int primes[200];
int primesSize;
int c[1121][15][188];

int solve(int n, int k, int index) {
    if (n == 0 && k == 0) {
        return 1;
    } else if (n == 0 || k == 0) {
        return 0;
    }
    if (c[n][k][index] >= 0) {
        return c[n][k][index];
    }
    int res = 0;
    for (int i = index; i < primesSize; i++) {
        if (primes[i] > n) {
            break;
        } else {
            res += solve(n - primes[i], k - 1, i + 1);
        }
    }
    c[n][k][index] = res;
    return res;
}

int main() {
    primes[0] = 2;
    primesSize = 1;
    for (int i = 3; i <= MAX; i += 2) {
        bool add = true;
        for (int j = 0; j < primesSize; j++) {
            if (primes[j] * primes[j] > i) {
                break;
            }
            if (i % primes[j] == 0) {
                add = false;
                break;
            }
        }
        if (add) {
            primes[primesSize++] = i;
        }
    }
    memset(c, -1, sizeof(c));
    while (true) {
        int n, k;
        cin >> n >> k;
        if ((n | k) == 0) {
            break;
        }
        cout << solve(n, k, 0) << endl;
    }
}

Measured memory_bytes: 0
using System;

namespace ABC053_B
{
    class Program
    {
        static void Main(string[] args)
        {
            var s = Console.ReadLine();
            var a = 0;
            var z = 0;
            for(var i=0;i<s.Length;i++)
            {
                if (s[i] == 'A')
                {
                    a = i;
                    break;
                }
            }
            for(var j=s.Length-1;j>=0;j--)
            {
                if (s[j] == 'Z')
                {
                    z = j;
                    break;
                }
            }
            Console.WriteLine(z - a + 1);
        }
    }
}


Measured memory_bytes: 13140
while True:
    n, p = map(int, raw_input().split())
    wan = p
    if n == p == 0:
        break
    A = [0 for _ in xrange(n)]
    i = 0
    while True:
        if p > 0:
            A[i] += 1
            p -= 1
            if A[i] == wan:
                print i
                break
        else:
            p += A[i]
            A[i] = 0
        i = (i + 1) % n

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

using ll=long long;

int main(){
    int K; cin >> K;
    string S; cin >> S;
    if(S.size() <= K) cout << S << endl;
    else{
        string T=S.substr(0,K);
        T+="...";
        cout << T << endl;
    }
    return 0;
}

Measured memory_bytes: 3632
// vvvvvvvvvvvv TEMPLATE vvvvvvvvvvvv
#include <bits/stdc++.h>
using namespace std; using ll = long long; using P = pair<ll, ll>;
const ll linf = 1e18; const double eps = 1e-12, pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define each(i,a) for (auto&& i : a)
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
#define pb push_back
#define eb emplace_back
#define all(a) begin(a),end(a)
#define chmin(x,v) x = min(x, v)
#define chmax(x,v) x = max(x, v)
template<typename T> ll min(ll a, const T&& b) { return a < b ? a : b; }
template<typename T> ll min(const T&& a, ll b) { return a < b ? a : b; }
template<typename T> ll max(ll a, const T&& b) { return a > b ? a : b; }
template<typename T> ll max(const T&& a, ll b) { return a > b ? a : b; }
template<typename Head> void out(Head h) { cout << h << endl; } template<typename Head, typename... Tail>void out(Head h, Tail... t) { cout << h << " "; out(t...); }
template<typename T> istream& operator>>(istream& is, vector<T>& v) { each(x,v) is >> x; return is; }
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) { rep(i,v.size()) { if (i) os << " "; os << v[i]; } return os; }
ostream& operator<<(ostream& os, const vector<string>& v) { rep(i,v.size()) { if (i) os << endl; os << v[i]; } return os; }
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) { rep(i,v.size()) { if (i) os << endl; os << v[i]; } return os; }
template<typename T1, typename T2> ostream& operator<<(ostream& os, const pair<T1, T2>& p) { return os << "(" << p.first << ", " << p.second << ")"; }
struct yes_no : std::numpunct<char> { string_type do_truename() const { return "Yes"; } string_type do_falsename() const { return "No"; } };
void solve(); int main() {
  ios::sync_with_stdio(false); cin.tie(0); locale loc(locale(), new yes_no); cout.imbue(loc); cout << fixed << setprecision(10) << boolalpha;
  solve();
}
// ^^^^^^^^^^^^ TEMPLATE ^^^^^^^^^^^^

void solve() {
  ll n; cin >> n;
  vector<P> edges;
  if (n % 2 == 0) {
    ll S = n+1;
    rep(i, 1, n+1) rep(j, 1, i) {
      if (i + j == S) continue;
      edges.eb(i, j);
    }
  }
  else {
    ll S = n;
    rep(i, 1, n+1) rep(j, 1, i) {
      if (i + j == S) continue;
      edges.eb(i, j);
    }
  }
  cout << edges.size() << endl;
  each(p, edges) {
    cout << p.first << " " << p.second << endl;
  }
}


Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main(){


    long long int a,b,result;
    cin>>a>>b;
    result = a*b;
    if(a == 1 || b ==1)
        cout<<1;
    else if(result % 2==0)
        cout<<result/2;
    else    
        cout<<(result/2)+1;

}


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

int main()
{
    ll a, b, c, k;
    std::cin >> a >> b >> c >> k;

    ll sum = 0;
    sum += min(k, a);
    k -= a;

    if (k > 0)
    {
        k -= b;
        if (k > 0)
        {
            sum -= min(k, c);
        }
    }

    std::cout << sum << std::endl;

    return 0;
}

Measured memory_bytes: 3636
import java.util.Scanner;

public class Main {
	public static int gcd(int x, int y) {

		int d = 1;
		if (x > y) {
			for (int i = 1; i <= x % y; i++) {
				if (y % i == 0 && x % y % i == 0) {
					d = i;
				}
			}
		} else if (y > x) {
			for (int i = 1; i <= y % x; i++) {
				if (x % i == 0 && y % x % i == 0) {
					d = i;
				}
			}
		} else {
			d = y;
		}

		return d;

	}

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int x = scanner.nextInt();
		int y = scanner.nextInt();
		int d = gcd(x, y);
		System.out.println(d);
		scanner.close();
	}

}


Measured memory_bytes: 26232
// I make this just for fun because i'm done
// Aimi Haraguni >> Konomi Suzuki >> Yui >>  Ikimono Gakari >> Garnidelia >> Kalafina >> Eir Aoi.   .. dude? 
// problems that involves any kind of persistent data structures are the best of the best, are not them?
 
// #pragma GCC optimize ("Ofast,unroll-loops")
// #pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
 
#define pb emplace_back
#define ff  first
#define ss second
#define tm1 first
#define tm2 second.first
#define tm3 second.second
#define sz(x) ll(x.size())
#define all(v) (v).begin(), (v).end()
#define FER(i,a,b) for(ll i=ll(a); i< ll(b); ++i)
#define IFR(i,a,b) for(ll i=ll(a); i>=ll(b); --i )
#define fastio ios_base::sync_with_stdio(0); cin.tie(0)
 
#define N 31000000
// #define M 19
 
// #define mod  11092019
#define mod1 1000000007
#define mod2 1000000009
#define bas 987625403
#define sqr(x) (x)*(x)  
#define INF 2000000000
 
using namespace std;
using namespace __gnu_pbds;
 
typedef int ll;
typedef pair<ll, ll> ii;
typedef pair<ll, ii > tri;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef tree<pair<ll, ll>, null_type, less<pair<ll, ll>>, rb_tree_tag, tree_order_statistics_node_update> S_t;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
 
#define trace(...) fff(#__VA_ARGS__, __VA_ARGS__)
template<typename t> void fff(const char* x, t&& val1) { cout<<x<< " : "<<val1<<"\n";}
template<typename t1, typename... t2> void fff(const char* x, t1&& val1, t2&&... val2){
    const char* xd=strchr(x+1, ',');
    cout.write(x, xd-x)<<" : "<<val1<<" | ";
    fff(xd+1, val2...);
}

inline ll mul(ll a, ll b, ll mod) { return (long long) a*b%mod;}
inline ll add(ll a, ll b, ll mod) { return a+b < mod? a+b: a+b-mod;}
inline void Mul(ll &a, ll b, ll mod) { a = (long long) a*b%mod;}
inline ll bp(ll a, ll p, ll mod){
	ll ret;
	for(ret = 1; p; p>>=1, Mul(a, a, mod)) (p & 1) && (Mul(ret, a, mod), 1);
	return ret;
}
static inline void read(ll &x) { cin>>x;}

ll ar[1<<10];
int main(){
	fastio;
	ll x, n; cin>>x>>n;
	vi tnt(150, 0);
	FER(i, 0, n) {
		ll g; cin>>g;
		tnt[g]++;
	}
	ll ans = INF, resp = -1;
	FER(i, 0, 102) if(!tnt[i]){
		if(abs(i - x) < ans) {
			ans = abs(i-x);
			resp = i;
		}
	} 
	cout<<resp<<"\n";
	return 0;
}

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

int main(){
    int N;
    cin >> N;
    int a[N+1],b[N];
    for(int i=0;i<=N;i++) cin >> a[i];
    for(int i=0;i<N;i++) cin >> b[i];

    long long ans = 0;
    for(int i=0;i<N;i++){
        ans += min(a[i],b[i]);
        b[i] -= min(a[i],b[i]);
        ans += min(a[i+1],b[i]);
        a[i+1] -= min(a[i+1],b[i]);
    }
    cout << ans << endl;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define endl "\n"
#define F first
#define S second
#define mod 1000000007
#define pb push_back
#define FOR(i,a,n) for(int i=a;i<n;i++)
#define REV(i,a,n) for(int i=a;i>=n;i--)
#define all(a) a.begin(),a.end()
const int NUM = 2e5 + 5;

int32_t main(){
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int num_tests=1; 
    //cin >> num_tests;
    while(num_tests-->0){
        string s,t; cin >> s >> t;
        int ans = 1e18;
        FOR(i,0,s.size() - t.size() + 1){
            int cnt = 0;
            FOR(j,i,i+t.size()){
                if(s[j] != t[j-i])
                    cnt++;
            }
            ans = min(ans,cnt);
        }
        cout << ans;
    }    
}

Measured memory_bytes: 3656
k,s = map(int,input().split())
cnt = 0
for x in range(0,k+1):
    for y in range(0,k+1):
        z = s - x - y  
        #print(x,y,z)
        if z >=0 and s<=3*k and z<=k:
            cnt +=1
print(cnt)
        

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

int main(){
	int a,b;
    cin >> a >> b;
  	if(a<=5)
      cout << 0 << endl;
    else if(6<=a&&a<=12)
      cout << b/2 << endl;
    else if(13<=a)
      cout << b << endl;
}

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

void solve()
{
	int n;
	cin >> n;
	int l = 0, r = 10000000;
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
     string s;
      cin >> s;
      int n = s.size();
      int c = 0;
      for(auto e : s)
        if(e == 'o')
          c++;
      if(15 - n >= 8 - c)
        cout << "YES";
      else
        cout << "NO";
     
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
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; }
const int INF=1001001001;
const long long mod=998244353;

struct Unionfind{
  vector<int>d;
  Unionfind(int n):d(n,-1){}
  int root(int x){
    if(d[x]<0){return x;}
    return d[x]=root(d[x]);
  }
  bool unite(int x,int y){
    x=root(x);y=root(y);
    if(x==y){return false;}
    if(d[x]>d[y]){swap(x,y);}
    d[x]+=d[y];
    d[y]=x;
    return true;
  }
  bool same(int x,int y){return root(x)==root(y);}
  int size(int x){return -d[root(x)];}
};
 
int main(){
  int N;
  cin>>N;
  Unionfind uf(N);
  vector<int>y(N);
  vector<int>id(N);
  for(int i=0;i<N;i++){
    int X,Y;
    cin>>X>>Y;
    X--;Y--;
    y[X]=Y;
    id[i]=Y;//yの値でグループを作るので、i番目のグループのサイズを出力するときはi番目のyの値のグループを見る
  }
  set<int>s;
  for(int x=0;x<N;x++){
    int MIN=y[x];
    while(!s.empty()&&*begin(s)<y[x]){//cout<<"a"<<x<<" "<<*begin(s)<<endl;
      uf.unite(y[x],*begin(s));
      chmin(MIN,*begin(s));
      s.erase(s.begin());
    }
    s.insert(MIN);
  }
  for(int i=0;i<N;i++){
    cout<<uf.size(id[i])<<endl;
  }
  return 0;                       
}

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

int main(){
  int r,g,b,n;
  cin >> r>>g>>b;
  n=100*r+10*g+b;
  
  if(n%4==0) cout <<"YES"<<endl;
  else cout<< "NO"<<endl;
return 0;
}


Measured memory_bytes: 3644
#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>;
long long solve(long long a, long long b) {
    if (a == b) return (a-1)*2;
    long long lim = a*b - 1;
    long long low = 1, high = 1LL<<31;
    while (high - low > 1) {
        long long mid = (low + high) / 2;
        long long mul = (mid+1)/2 * (mid+1 - (mid+1)/2);
        if (mul > lim) high = mid;
        else low = mid;
    }
    return low - 1;
}

int main() {
    int Q; cin >> Q;
    for (int q = 0; q < Q; ++q) {
        long long a, b; cin >> a >> b;
        cout << solve(a, b) << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define faster ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
 
typedef vector<int> vi;;
typedef vector<ll> vll;

#define l() length()
#define sz() size()
 
#define b() begin()
#define e() end()
#define all(x) x.begin(), x.end()
 
#define pb(i) push_back(i)
#define PB() pop_back()
 
 
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;
#define mp make_pair
#define Fi first
#define Se second
 
const int maxx=100009;
 
// Happy Coding!


void solve(){
    int n,a,b;
    cin>>n>>a>>b;
    
    string str;
    cin>>str;
    
    int jp=0,ov=0;
    for(int i=0;i<n;i++){
        if(str[i]=='c'){
            cout<<"No\n";
        }
        else{
            if(str[i]=='a'){
                if(jp+ov<a+b){
                    cout<<"Yes\n";
                    jp++;
                }
                else{
                    cout<<"No\n";
                }
            }
            else{
                if(jp+ov<a+b && ov<b){
                    cout<<"Yes\n";
                    ov++;
                }
                else{
                    cout<<"No\n";
                }
            }
        }
    }
}
 
int main() {
    faster;
    int t=1;
    // cin>>t;
    
    while(t-->0){
        solve();
    }
	return 0;
}

Measured memory_bytes: 3732
using System;

class Hello{


static void Main(){
string [] str=Console.ReadLine().Split(' ');

for(int i=0;str[1]!="?";i++)
{
if(str[1]=="+")Console.WriteLine(int.Parse(str[0])+int.Parse(str[2]));
else if(str[1]=="-")Console.WriteLine(int.Parse(str[0])-int.Parse(str[2]));
else if(str[1]=="*")Console.WriteLine(int.Parse(str[0])*int.Parse(str[2]));
else Console.WriteLine(int.Parse(str[0])/int.Parse(str[2]));

str=Console.ReadLine().Split(' ');
}

}
}


Measured memory_bytes: 15964
D=int(input())
C=list(map(int, input().split()))
S=[list(map(int,input().split())) for i in range(D)]

#T=[]
#for i in range(D):
#  T.append(int(input()))

#M=int(input())
#dq=[list(map(int,input().split())) for i in range(M)]

def dissat(day):
  dissat = 0
  for i in range(26):
    if T[day-1]-1 == i:
      continue
    dissat += C[i]*(day-lastdays[i])

  return dissat    
    
def last(day):
  lastdays[T[day-1]-1] = day

# 
def calcscore(D):
  sat = 0
  for i in range(D):
    # dayi
    last(i)
    sat += S[i][T[i]-1] - dissat(i+1)
  #print(sat)
  return sat

# main
#lastdays = [0]*26
#calcscore(D)


# change contenst
#for i in range(M):
#  T[dq[i][0]-1] = dq[i][1]
#  lastdays = [0]*26
#  calcscore(D)

#
import random

count = 0
while count < 100:
  T = [0]*D
  for i in range(D):
    T[i] = random.randrange(1,26)

  lastdays = [0]*26
  oldscore = calcscore(D)
  if oldscore > 0:
    break
  count += 1


count = 0
while count < 1000:
  count += 1
  d=random.randrange(1,D)
  q=random.randrange(1,26)
  old = T[d-1] # 後で戻せるように元の値を記憶しておく
  T[d-1] = q
  lastdays = [0]*26
  newscore = calcscore(D)
  if newscore < oldscore:
    T[d-1] = old
  else:
    oldscore = newscore

for i in range(D):
  print(T[i])

Measured memory_bytes: 85112
#include<iostream>
using namespace std;
#define max 500000
#define sen 2000000000

int l[max/2+2],r[max/2+2];
int cnt;

void merge(int a[],int n,int left,int mid,int right){
	int n1=mid-left;
	int n2=right-mid;
	for(int i=0;i<n1;i++)l[i]=a[left+i];
	for(int i=0;i<n2;i++)r[i]=a[mid+i];
	l[n1]=r[n2]=sen;
	int i=0,j=0;
	for(int k=left;k<right;k++){
		cnt++;
		if(l[i]<=r[j])a[k]=l[i++];
		else a[k]=r[j++];
	}
}

void merso(int a[],int n,int left,int right){
	if(left+1<right){
		int mid=(left+right)/2;
		merso(a,n,left,mid);
		merso(a,n,mid,right);
		merge(a,n,left,mid,right);
	}
}

int main(void){
	int a[max],n,i;
	cnt=0;
	
	cin>>n;
	for(i=0;i<n;i++)cin>>a[i];
	
	merso(a,n,0,n);
	
	for(i=0;i<n;i++){
		if(i)cout<<" ";
		cout << a[i];
	}
	cout <<endl;
	
	cout << cnt << endl;
	
	return 0;
}


Measured memory_bytes: 6924
#include <bits/stdc++.h>
#define MOD 1000000007
#define ll long long int
#define db double
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define pb push_back
#define endl "\n"
#define mp make_pair
#define f first
#define s second
ll power(ll x, ll y, long long int mod = 1000000007){ ll ans = 1;x %= mod;while(y){if(y&1)ans = (x * ans) % mod;x = (x * x) % mod;y >>= 1;}return ans;}
ll modInverse(ll a, ll m){ll m0 = m;ll y = 0, x = 1;if (m == 1) return 0;while (a > 1){ ll q = a / m;ll t = m;m = a % m,a = t;t = y;y = x - q * y;x = t;}if(x < 0) x += m0;return x;}
using namespace std;

int main() {
    fastio;
    int h, w;
    cin >> h >> w;
    // char grid[h][w];
    // for(int i = 0; i < h; i++)
    ll dp[w];
    for(int i = 0; i < w; i++) {
        dp[i] = 1;
    }
    for(int i = 0; i < h; i++) {
        for(int j = 0; j < w; j++) {
            char c;
            cin >> c;
            if(c == '#')
                dp[j] = 0;
            else {
                ll left = j ? dp[j - 1] : 0;
                ll top = i ? dp[j] : 0;
                dp[j] = (left + top) % MOD;
                if(!i && !j)
                    dp[j] = 1;
            }
            //cout << dp[j] << " ";
        }
        //cout << endl;
    }
    cout << dp[w - 1] << endl;
}

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

using namespace __gnu_pbds;
using namespace std;

typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

#define mp make_pair
#define pb push_back
#define pf push_front
#define ss second
#define ff first
#define sz(x) (int)x.size()
#define newl "\n"
#define vi vector<int>
#define pii pair<int, int>
#define vii vector<pii>
#define vl vector<ll>
#define pll pair<ll, ll>
#define vll vector<pll>
#define coutp cout << fixed << setprecision(12)
#define mem(x, val) memset(x, val, sizeof(x))
#define fastio                        \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define all(v) (v).begin(), (v).end()

const ld pi = 3.14159265359;
ll INF = 1e18 + 10;
ll MOD = 998244353;
ll mod = 1e9 + 9;

inline ll add(ll a, ll b, ll m)
{
    if ((a + b) >= m)
        return (a + b) % m;
    return a + b;
}

inline ll mul(ll a, ll b, ll m)
{
    if ((a * b) < m)
        return a * b;
    return (a * b) % m;
}

ll power(ll x, ll y, ll m)
{
    ll res = 1;
    x = x % m;
    if (x == 0)
        return 0;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % m;
        y = y >> 1;
        x = (x * x) % m;
    }
    return res;
}
vl a(51), p(51);
ll fun(ll n,ll x) {
    if(n==0) {
        return x<=0?0:1; 
    }
    else if(x<=((ll)1+a[n-1])) {
        return fun(n-1,x-1);
    }
    else {
        return 1+p[n-1]+fun(n-1,x-2-a[n-1]);
    }
}

void solve()
{
    ll n,x;
    cin>>n>>x;
    a[0]=1;
    p[0]=1;
    for(int i=1;i<=n;i++) {
        a[i]=2*a[i-1]+3;
        p[i]=2*p[i-1]+1;
    }

    ll ans = fun(n,x);
    cout<<ans;
}

int main()
{
    fastio;
    int t;

    t = 1;
    //cin >> t;
    //int test=t;
    while (t-- > 0)
    {
        //cout<<"Case #"<<(test-t)<<": ";
        solve();
        cout << newl;
    }

    return 0;
}

Measured memory_bytes: 3608
#include <stdio.h>

int D,G;
int p[10];
int c[10];
#define pow2(n) (1 << n)
//int pow2(int n)  { return 1 << n;}

int main(){
	scanf("%d %d",&D,&G);
	for(int i = 0; i < 10; i++){
		p[i] = c[i] = 0;
	}
	for(int i = 0; i < D; i++){
		scanf("%d %d",p+i,c+i);
	}

	int mincnt = 100000;
	for(int n = 0; n < pow2(D); n++){
		int cnt = 0;
		int score = 0;
		// complete block
		for(int i = 0; i < D; i++){
			if(n & pow2(i)){
				score += c[i] + (i+1)*100*p[i];
				cnt   += p[i];
			}
		}	
		// non-complete block

		for(int i = D-1; i >= 0; i--){
			if(n & pow2(i) || p[i]==0) continue;

			if(G-score > (i+1)*100*(p[i]-1)){
				score += (i+1)*100*(p[i]-1);
				cnt   += p[i]-1;
			}else{
				if(G >= score){
					if( (G-score) % ((i+1)*100) == 0)
						cnt += (G-score)/ ((i+1)*100);
					else
						cnt += 1 + (G-score)/ ((i+1)*100);
					score += cnt*((i+1)*100);
				}else {}
				break;
			}
		}
		if(G > score) cnt = 10000;
		//printf("(n=%d, cnt=%d)\n",n,cnt);
		if (mincnt > cnt) mincnt = cnt;
	}
	printf("%d\n",mincnt);
}	

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

int main() {
    string s;
    cin>>s;
    if(s[2]==s[3]&&s[4]==s[5]){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int euclid(int a, int b) {
    int c = a % b;

    if (c == 0) {
        return b;
    }
    else {
        return euclid(b, c);
    }
}

int main() {
    int a, b;

    cin >> a >> b;

    cout << euclid(a, b) << endl;
}



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

using namespace std;

int main() {
    ios_base::sync_with_stdio(0);
	cin.tie(0);
    
    int n;
    cin >> n;
    
    unordered_set<string> ss;
    for (int i = 0; i != n; ++i) {
        string s;
        cin >> s;
        ss.insert(s);
    }
    
    cout << ss.size() << endl;
    
    return 0;
}


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

using namespace std;

typedef long long ll;
typedef vector<int> pi;
typedef pair<int,int> vi;

#define F first
#define S second
#define PB push_back
#define MK make_pair
#define REP(i, a, b) for (int i=a; i < b; i++)


bool sort_by(vi c, vi d){
	return c.S < d.S;
}
	
	

int main() {
	string s, tmp, prev;
	cin >> s;
	int ans = 0;
	
	REP(i,0, (int)s.size()){
		if(i == 0){
			//++ans;
			prev = "";
			tmp = s[i];
			//cout << prev << endl;
		}
		else if(prev == tmp){
			tmp += s[i];
		}
		else{
			//cout << prev << endl;
			prev = tmp;
			tmp = s[i];
			++ans;
		}
	}
	
	cout << ans + (prev != tmp?1:0);
			
			
			

}


Measured memory_bytes: 640
/**
 * @author yuzining
 * @date 2020/08/02 20:06
 */

#ifdef local
#include "D:\vscode\acm\local.hpp"
#else
#include<bits/stdc++.h>
using namespace std;
#define debug(...) do { } while(false)
void Main();
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  Main();
  return 0;
}
#endif

void Main() {
  int n; cin >> n;
  int ans = 7;
  for(int i = 1; i <= n; i++) {
    ans %= n;
    if(ans == 0) {
      cout << i << '\n';
      return;
    }
    ans = (ans * 10 + 7) % n;
  }
  cout << "-1\n";
}

Measured memory_bytes: 3644
#include <iostream>
using namespace std;
int cnt=0;

void merge(int *A, int left, int mid, int right){
    int n1 = mid-left;
    int n2 = right-mid;
    int *L,*R;
    L = new int[n1+1];
    R = new int[n2+1];

    for(int i=0;i<n1;i++)
        L[i] = A[left+i];
    for(int i=0;i<n2;i++)
        R[i] = A[mid+i];
    
    L[n1] = 1000000001;
    R[n2] = 1000000002;
    int i = 0;
    int j = 0;

    for(int k=left;k<right;k++){
        cnt++;
        if(L[i]<=R[j]){
            A[k] = L[i];
            i++;
        }
        else{
            A[k] = R[j];
            j++;
        }
    }

    delete[] L;
    delete[] R;
}

void mergeSort(int *A, int left, int right){
    if(left+1 < right){
        int mid = (left+right)/2;
        mergeSort(A,left,mid);
        mergeSort(A,mid,right);
        merge(A,left,mid,right);
    }
} 

int main(){
    int n, *S;
    cin >> n;
    S = new int[n];
    for(int i=0;i<n;i++)
        cin >> S[i];
    mergeSort(S,0,n);

    cout << S[0];
    for(int i=1;i<n;i++)
        cout << " " << S[i];
    cout << endl << cnt << endl;

    delete[] S;
    return 0;
}


Measured memory_bytes: 6772
#include<bits/stdc++.h>
using namespace std;
typedef long long l;
int main(){
    string a,b,c;
    cin>>a>>b;
    c=a;
    for(int i=0;i<a.size();i++){
        a=c;
        for(int j=0;j<a.size();j++){
            if(j) c[j]=a[j-1];
            else c[j]=a[a.size()-1];
        }
        if(b==c){
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
    return 0;
}


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

typedef long long int ll;
ll powk(ll a, ll n = 2){
    ll r = 1;
    for(ll i = 0;i < n;i++){
        r *= a;
    }

    return r;
}

int main()
{
    double L;
    cin >> L;
    
    cout <<setprecision(10)<< (L / 3) * (L / 3) * (L / 3);

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5+10;
int a[N], n;
map<int,int> M;

bool test() {
    if (M.size() > 3) return false;
    if (M.size() == 1) return M.begin()->first == 0;
    if (M.size() == 2) {
        auto it = M.begin();
        ++it;
        return it->second == 2 * M.begin()->second;
    }
    else {
        vector<int> vec,cnt;
        for (auto i: M) {
            vec.push_back(i.first);
            cnt.push_back(i.second);
        }
        return (vec[0] ^ vec[1]) == vec[2] && cnt[0] == cnt[1] &&cnt[1] == cnt[2];
    }
}

int main() {
    scanf("%d", &n);
    for (int i = 0; i < n; i++) scanf("%d", a+i), M[a[i]]++;
    puts(test() ? "Yes" : "No");
}

Measured memory_bytes: 4224
#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>
#include<cstring>
#include<string>
#include<iomanip>
#include<map>
#include<fstream>
#include<queue>
#include<set>
#include<deque>

using namespace std;

int main()
{
	int n, x = 1;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		if (i * i > n)
			break;
		x = i * i;
	}
	cout << x << endl;
}

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

int main(void)
{
    int n; cin>>n;
    int a[82];
    for(int i=0;i<n;++i) cin>>a[i];
    long long ans = 1000;
    for(int i=1;i<n;++i)
        if(a[i]>a[i-1]) ans += (a[i]-a[i-1])*(ans/a[i-1]);
    cout<<ans;
    return 0;
}

Measured memory_bytes: 3612
# range(stop)は0<=i<stopの連番リストを返す．stopは含まれない．
# 0始まりで1ずつ増加する連番なので，負の値を指定すると空になる．
# range(start, stop)はstrat<=i<stopの連番リストを返す．stopは含まれないので注意．
# stepを負にすることで逆順の連番リストを作成できる．

def MaximumProfit(val_list, N):
   maxv = -10e10
   minv = val_list[0]
   for i in range(1, N):
      maxv = max(maxv, val_list[i]-minv)
      minv = min(minv, val_list[i])
   return maxv

N = int(input())
val_list = [int(input()) for _ in range(N)] # 1つの数字をN行入力
ans = MaximumProfit(val_list, N)
print(ans)


Measured memory_bytes: 13632
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
const int INF = 100000000;
using namespace std;


class Edge {
    public:
        int to;
        double cost;
        Edge(int to, double cost) : to(to), cost(cost) { }
};

typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

double prim(const Graph &g, vector<bool> &visited, int s) {
    int n = g.size();
    double total = 0;

    //priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> q;
    priority_queue<pair<double, int> > q;

    q.push(make_pair(0,s));
    while (not q.empty()) {
        pair<double, int> u = q.top(); q.pop();
        if (visited[u.second]) continue;
        total += u.first;
        visited[u.second] = true;
        for(auto it : g[u.second]) {
            if (not visited[it.to]) q.push(make_pair(it.cost, it.to));
        }
    }
    return total;
}

int main(){
    complex<double> p[10005];
    int n, m;
    cin >> n >> m;
    rep(i,n){
        double a, b;
        cin >> a >> b;
        p[i] = complex<double>(a,b);
    }

    Graph g(n);
    vector<bool> visited(n, 0);
    double sum = 0;
    rep(i,m){
        int a, b;
        cin >> a >> b;
        a--; b--;

        double cost = abs(p[a] - p[b]);
        g[a].emplace_back(b, abs(cost));
        g[b].emplace_back(a, abs(cost));
        sum += cost;
    }

    double usedsum = 0;
    rep(i,n){
        if(visited[i] == 0){
        //cout << endl; rep(i,n) show(visited[i])
            usedsum += prim(g, visited, i);
        }
    }
    cout << fixed << setprecision(5) <<  sum - usedsum << endl;
}

Measured memory_bytes: 5256
import itertools
def main():
    grid = [list(map(int, input().split())) for i in range(3)]
    all = sum(sum(grid, []))
    a = [0] * 3
    b = [0] * 3
    for i, j, k in itertools.product(range(grid[0][0] + 1), range(grid[1][1] + 1), range(grid[2][2] + 1)):
        a = [i, j, k]
        b = [grid[idx][idx] - v for idx, v in enumerate(a)]
        if (sum(a) * 3) + (sum(b) * 3) == all:
            print("Yes")
            exit()
    print('No')


if __name__ == '__main__':
    main()


Measured memory_bytes: 9192
#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <queue>
#include <vector>
#include <stack>
#include <set>
#include <map>
#include <iterator>

using namespace std;

typedef long long ll;
#define mems(p) memset(p,-1,sizeof(p))
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define nl "\n"

void fast()
{ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);}

int main() {
	int h1, m1, h2, m2, k;
  cin >>h1>>m1>>h2>>m2>>k;
  int ans = 0;
  ans += (h2-h1)*60;
  ans += (m2-m1);
  ans -= k;
  ans = max(0, ans);
  cout << ans << nl;
}

Measured memory_bytes: 3584
import sys
readline = sys.stdin.readline


H, W = map(int, readline().split())

if H == 1 or W == 1:
    print(1)
    exit(0)

if H % 2 == 0:
    print(H // 2 * W)
else:
    print(H // 2 * W + (W + 1) // 2)

Measured memory_bytes: 38256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
const ll N = 1e5 + 5, MOD = 1e9+7;

ll n;
ll x,y,w;
ll vis[N],color[N];
vector < pair<ll,ll> > adj[N];

void dfs( ll u ){
    vis[u]=1;
    for( auto v: adj[u] ){
        if(!vis[v.first]){
            if(v.second&1)   color[v.first]=1-color[u];
            else             color[v.first]=color[u];
            dfs(v.first);
        }
    }
}

int main(){

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

    cin>>n;

    for( ll i=1; i<n; i++ ){
        cin>>x>>y>>w;
        adj[x].pb({y,w});
        adj[y].pb({x,w});
    }

    color[1]=0;
    dfs(1);

    for( ll i=1; i<=n; i++ )          cout<<color[i]<<endl;
    return 0;
}




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

#define ull unsigned long long
#define endl '\n'
#define ll long long
const int N = 2e3 + 5;
vector<ll> node[N];
ll dp[N][N];
ll vis[N][N];
ll cnt[N];
void bfs(ll u){
        queue<ll> q;
        q.push(u);
        dp[u][u] = 0;
        while (q.size() > 0) {
                ll now = q.front();
                q.pop();
                for (auto j : node[now]){
                        if (vis[u][j] == 0){
                                vis[u][j] = 1;
                                dp[u][j] = dp[u][now] + 1;
                                q.push(j);
                        }
                }
        }
}
int main(){
        ios_base::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
        if (fopen(".INP", "r")){
                freopen(".INP", "r", stdin);
                freopen(".OUT", "w", stdout);
        }
        ll n;
        cin >> n;
        for (int i = 1; i < n; i++){
                node[i].push_back(i + 1);
                node[i + 1].push_back(i);
        }
        ll x, y;
        cin >> x >> y;
        node[x].push_back(y);
        node[y].push_back(x);
        for (int i = 1; i <= n; i++){
                bfs(i);
        }
        for (int i = 1; i <= n; i++){
                for (int j = i + 1; j <= n; j++){
                        cnt[dp[i][j]]++;
                }
        }
        for (int i = 1; i < n; i++) {
                cout << cnt[i] << endl;
        }
}


Measured memory_bytes: 63104
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;

vector<int> con[10001];
int c[10001];
int ans[10001];
int cnt;
long long a;

void dfs(int v, int p)
{
	ans[v] = c[cnt--];

	for (int i : con[v])
		if (i != p)
			dfs(i, v);
}

int main()
{
	int n;

	scanf("%d", &n);

	for (int i = 0; i < n - 1; i++)
	{
		int a, b;
		scanf("%d %d", &a, &b);
		con[a].push_back(b);
		con[b].push_back(a);
	}

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

	sort(c + 1, c + n + 1);

	int m = 1;
	for (int i = 2; i <= n; i++)
		if (con[i].size() > con[m].size())
			m = i;

	cnt = n;

	dfs(m, -1);

	a -= c[n];
	printf("%I64d\n", a);

	for (int i = 1; i <= n; i++)
		printf("%d ", ans[i]);

	a -= c[n];

	return 0;
}

Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
const int mod = 1000000007;

int main(){
  int n, h, w;
  cin >> n >> h >> w;
  int ans = 0;
  rep(i, n) {
    int a, b;
    cin >> a >> b;
    if (a >= h && b >= w) ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main {

	int INF = 1 << 28;
	
	void run() {
		Scanner sc = new Scanner(System.in);
		for(;;) {
			int q1 = sc.nextInt();
			if(q1 == 0) break;
			int b = sc.nextInt();
			int c1 = sc.nextInt();
			int c2 = sc.nextInt();
			int q2 = sc.nextInt();
			
			int i,j=0;
			for(i=q2;i>0;i--) {
//				System.out.println(c1*i + " " + b);
				if( b<c1*i ) continue;
				int zan = b-c1*i;
				j = zan/c2;
				if(i+j >= q1) break;
			}
			
			if( i!=0 ) System.out.println(i + " " + j);
			else System.out.println("NA");
			
		}
	}

	public static void main(String[] args) {
		new Main().run();
	}
}

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

typedef long long ll;
const ll MOD = 1e9 + 7;
const ll inf = 1LL<<60;
const double eps = 1e-9;

typedef pair<ll, ll> P;

int main()
{
    int h, a;
    cin >> h >> a;
    cout << (h-1)/a + 1<< endl;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define r(i,n) for(i=0;i<n;i++)
using namespace std;
int main(){
  int n,i,j,q;
  while(cin>>n,n){
    int m=0,tt;
    string p[n],s[n];
    r(i,n){cin>>p[i];}
    r(i,n){tt=p[i].size();r(j,tt){
      if(!j)s[i]+=p[i][j];
      else{if(p[i][j-1]=='a'||p[i][j-1]=='i'||p[i][j-1]=='u'||p[i][j-1]=='e'||p[i][j-1]=='o')s[i]+=p[i][j];}
    }}
    r(i,n){tt=s[i].size();m=max(m,tt);}
    string t[n];
    r(i,m){
      int p=0;
      r(j,n)if(i<s[j].size())t[j]+=s[j][i];
    r(j,n)for(int k=j+1;k<n;k++)if(t[k]==t[j])p++;
      if(!p)goto L;
    }
    cout<<-1<<endl;
    if(0){L:;cout<<i+1<<endl;}
  }
}

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

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

 typedef long long ll;
 const long long INF = 1LL << 60;



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

   vector<long long> dp(100010, INF);

   dp.at(0) = 0;
   for(int i = 1; i <= n; i++)
   {
       int num = 1;
       while(num <= i)
       {
           chmin(dp.at(i), dp.at(i-num) + 1);
           num *= 6;
       }

       num = 9;
       while(num <= i)
       {
           chmin(dp.at(i), dp.at(i-num) + 1);
           num *= 9;
       }
   }

   cout << dp.at(n) << endl;

    return 0;
 }

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
signed a , b , C = ~(1<<31), M = (1<<16)-1;
void init(signed A,signed B){a=A;b=B;}
signed r() {
  a = 36969 * (a & M) + (a >> 16);
  b = 18000 * (b & M) + (b >> 16);
  return (C & ((a << 16) + b)) % 1000000;
}

struct Point{
  Int x,y,z;
  Point(){}
  bool operator==(const Point &a)const{
    return x==a.x&&y==a.y&&z==a.z;
  }
  bool operator<(const Point &a)const{
    if(x!=a.x) return x<a.x;
    if(y!=a.y) return y>a.y;
    return z>a.z;
  }
};

signed main(){  
  cin.tie(0);
  ios::sync_with_stdio(0);
  Int m,n,A,B;
  while(cin>>m>>n>>A>>B,m||n){
    init(A,B);
    
    vector<Point> ps(m+n);
    for(Int i=0;i<m;i++) cin>>ps[i].x>>ps[i].y>>ps[i].z;
    for(Int i=m;i<m+n;i++){
      ps[i].x=r();
      ps[i].y=r();
      ps[i].z=r();
    }
    n+=m;
    sort(ps.begin(),ps.end());
    using P = pair<Int, Int>;
    vector<set<P> > dp(n+1);
    
    auto print=[&](const set<P> &sp){
      for(auto p:sp) cout<<p.first<<" "<<p.second<<endl;
      cout<<endl;
    };
    
    auto veri=[&](const set<P> &sp){
      return;
      P a(-1,1e7);
      for(auto p:sp){
	assert(a.first<p.first);
	assert(a.second>p.second);
	a=p;
      }
    };
    
    auto check=[&](Int k,P p)->Int{
      if(dp[k].empty()) return 0;
      veri(dp[k]);
      auto it=dp[k].lower_bound(P(p.first,-1));
      if(it!=dp[k].begin()) --it;
      //if(it!=dp[k].begin()&&it->first>=p.first) --it;
      return it->first<p.first && it->second<p.second;
    };
    
    auto push=[&](Int k,P p){
      veri(dp[k]);
      if(dp[k].count(p)) return;
      dp[k].emplace(p);
      
      auto it=dp[k].lower_bound(p);
      while(it!=dp[k].end()){
	auto uk=it;uk++;
	if(uk==dp[k].end()) break;
	if(it->second<=uk->second){
	  dp[k].erase(uk);
	  it=dp[k].lower_bound(p);
	  continue;
	}
	break;
      }
      while(it!=dp[k].begin()){
	auto uk=it;uk--;
	if(uk->second<=it->second){
	  it=dp[k].erase(it);
	  if(it==dp[k].end()) break;
	  continue;
	}
	break;
      }
      
      veri(dp[k]);
    };
    
    for(Int i=0;i<n;i++){
      //cout<<ps[i].x<<" "<<ps[i].y<<" "<<ps[i].z<<endl;
      
      P p(ps[i].y,ps[i].z);
      Int l=0,r=i+1;
      while(l+1<r){
	Int m=(l+r)>>1;
	if(check(m,p)) l=m;
	else r=m;
      }
      push(l+1,p);
      //veri(dp[l+1]);
      
      if(0){
	cout<<l+1<<endl;
	for(int j=0;j<=n;j++){
	  cout<<j<<":"<<endl;
	  print(dp[j]);
	}
      }
    }
    
    Int ans=1;
    while(ans<n&&!dp[ans+1].empty()) ans++;
    cout<<ans<<endl;
  }
  
  return 0;
}



Measured memory_bytes: 29768
import java.util.Scanner;
import java.util.Arrays;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] x = new int [n];
        for(int i = 0;i < n;i++){
            x[i] = sc.nextInt();
        }
        int[] a = x.clone();
        Arrays.sort(x);
        for(int i = 0;i < n;i++){
            if(a[i] < x[n/2]){
                System.out.println(x[n/2]);
            }
            else{
                System.out.println(x[n/2-1]);
            }
        }
    }
}

Measured memory_bytes: 91764
def main():

    N = int(input())
    A = list(map(int, input().split()))
    d = dict()
    for v in A: d[v] = d.get(v, 0) + 1
    ans = sum(A)

    Q = int(input())
    for _ in range(Q):
        B, C = map(int, input().split())
        if B in d:
            ans -= d[B] * B
            ans += d[B] * C
            if C in d: d[C] += d[B]
            else: d[C] = d[B]
            del d[B]
        print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 20884
#include<iostream>
#include<string>
#include<vector>
#include<unordered_map>
#include<algorithm>
#include<cmath>
#include<limits>
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, k;
	string s;
	cin >> n >> k >> s;
	if (s[k - 1] == 'A') s[k - 1] = 'a';
	if (s[k - 1] == 'B') s[k - 1] = 'b';
	if (s[k - 1] == 'C') s[k - 1] = 'c';
	cout << s << endl;
	return 0;
}

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

int main(void) {
	int sinpan;
	int input;
	int score_sum;
	int smax, smin;
	
	while(1){
		scanf("%d", &sinpan);
		if ( sinpan == 0 ) { break; }
		
		score_sum = 0;
		smax = 0;
		smin = 1000;
		
		for ( int i=0; i<sinpan; i++ ) {
			scanf("%d", &input);
			score_sum += input;
			if ( smax < input ) { smax = input; }
			if ( smin > input ) { smin = input; }
		}
		printf("%d\n", (int)( (score_sum-smax-smin)/(sinpan-2)));

	}
	
	return 0;
}

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

int main()
{
	int i, H, W;
	char a[101][101];
	scanf("%d %d", &H, &W);
	for (i = 1; i <= H; i++) scanf("%s", &(a[i][1]));

	int j, count[26] = {};
	for (i = 1; i <= H; i++) {
		for (j = 1; j <= W; j++) count[a[i][j] - 'a']++;
	}
	
	int flag = 1;
	if (H % 2 == 0 && W % 2 == 0) {
		for (i = 0; i < 26; i++) if (count[i] % 4 != 0) break;
		if (i < 26) flag = 0;
	} else if (H % 2 == 0) {
		for (i = 0, j = 0; i < 26; i++) {
			if (count[i] % 2 != 0) break;
			else if (count[i] % 4 != 0) j++;
		}
		if (i < 26 || j > H / 2) flag = 0;
	} else if (W % 2 == 0) {
		for (i = 0, j = 0; i < 26; i++) {
			if (count[i] % 2 != 0) break;
			else if (count[i] % 4 != 0) j++;
		}
		if (i < 26 || j > W / 2) flag = 0;
	} else {
		for (i = 0, j = 0, flag = 0; i < 26; i++) {
			if (count[i] % 2 == 1) {
				if (flag == 1) break;
				flag = 1;
				if (count[i] % 4 == 3) j++;
			} else if (count[i] % 4 != 0) j++;
		}
		if (i < 26 || j > (H + W) / 2 - 1) flag = 0;
	}

	if (flag != 0) printf("Yes\n");
	else printf("No\n");
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 128
# coding: utf-8
# Your code here!

from operator import itemgetter
n = int(input())
ab = [list(map(int,input().split())) for _ in range(n)]
abps = [x+[x[0]+x[1]] for x in ab]
sabps = sorted(abps,key=itemgetter(2))[::-1]
takahashi_aoki=[0,0]
for i in range(n):
    takahashi_aoki[i%2]+=sabps[i][i%2]
print(takahashi_aoki[0]-takahashi_aoki[1])

Measured memory_bytes: 40232
#include <stdio.h>


int main()
{
    int n,l;scanf("%d%d",&n,&l);

    if (l<=0 && l+n-1>=0){
        printf("%d\n", n*l+(n-1)*n/2 );
    }
    else
    if (l>0){
        printf("%d\n", (n-1)*l+(1+n-1)*(n-1)/2  );
    }
    else
        printf("%d\n", (n-1)*l+(0+n-2)*(n-1)/2  );




}


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

using namespace std;

int main() {
    int l;
    cin >> l;
    long dp[l+1][5];
    fill(dp[0], dp[l+1], 0);
    for (int i=0; i<l; i++) {
        long a; cin >> a;
        dp[i+1][0] = dp[i][0] + a;
        dp[i+1][1] = min(dp[i][0], dp[i][1]) + a % 2 + (a == 0 ? 2 : 0);
        dp[i+1][2] = min({dp[i][0], dp[i][1], dp[i][2]}) + (a+1) % 2;
        dp[i+1][3] = min({dp[i][0], dp[i][1], dp[i][2], dp[i][3]}) + a % 2 + (a == 0 ? 2 : 0);
        dp[i+1][4] = min({dp[i][0], dp[i][1], dp[i][2], dp[i][3], dp[i][4]}) + a;
    }
    cout << min({dp[l][0], dp[l][1], dp[l][2], dp[l][3], dp[l][4]}) << '\n';
    return 0;
}

Measured memory_bytes: 8064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ss second
#define ff first
#define pb push_back
#define mp make_pair

int h[100100];
int main() {
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
        cin>>h[i];
        reverse(h,h+n);
    for(int i=1;i<n;i++)
    {
        if(h[i]>h[i-1])
            h[i]--;
        if(h[i]>h[i-1])
        {
            cout<<"No";
            return 0;
        }
    }
    cout<<"Yes";
    return 0;
}
//5 1 5 -10 -10 -10 5 7


Measured memory_bytes: 640
#include <iostream>
#include <functional>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <queue>
#include <map>
#include <iomanip>
#include <complex>
#include <random>
#include <bitset>
// #include <prettyprint.hpp>
using namespace std;
#define repi(i,n) for(int i=0;i<n;++i)
#define rep(i,n) for(ll i=0;i<n;++i)
#define repinvi(i,n) for(int i=n-1;i>=0;--i)
#define sll(n) scanf("%lld", &n);
#define sii(n) scanf("%d", &n);
#define slf(n) scanf("%lf", &n);
#define pll pair<ll,ll>
#define pii pair<int,int>
#define psi pair<si,si>
typedef long long ll;
typedef double lf;
typedef short int si;


void Main(){
    ll A, B, N;
    sll(N);
    sll(A);
    sll(B);
    ll left = N % (A + B);
    ll times = N / (A + B);
    
    cout << times * A + min(A, left) <<endl;


}

int main(){
    Main();
}

Measured memory_bytes: 256
#include  <bits/stdc++.h>
using namespace std;
static int fast_io = []() { std::ios::sync_with_stdio(false); cin.tie(nullptr); return 0; }();
unordered_map<long long int,long long int> dp;
long long int solve (long long int num){  
  if(dp[num]==0){
    dp[num]=2*solve(num/2)+1;  
  }
  return dp[num];
}
int main(){
  long long int h;
  cin>>h;
  dp[1]=1;
  cout<<solve(h)<<"\n";  
  return 0;
}

Measured memory_bytes: 256
def main():
    N, M = (int(i) for i in input().split())
    dic = {}
    for i in range(M):
        s, c = (int(i) for i in input().split())
        if s in dic.keys() and dic[s] != c:
            return print(-1)
        dic[s] = c
    # print(dic)
    for i in range(1000):
        s = str(i)
        if len(s) != N:
            continue
        for j in range(1, N+1):
            p = int(s[j-1])
            if (j in dic.keys()) and (dic[j] != p):
                break
        else:
            return print(i)
    print(-1)


if __name__ == '__main__':
    main()


Measured memory_bytes: 38640