akhauriyash/Code-Regression huggingface dataset:
n = int(input())
t, a = map(int, input().split())
h_l = list(map(int, input().split()))

# print(n)
# print(t)
# print(a)
# print(h_l)

min_a_tono_sa = 999999
index = 0
for i in range(len(h_l)):
    h = h_l[i]
    heikin_kion = t - h * 0.006
    # print(heikin_kion)
    a_tono_sa = abs(a - heikin_kion)
    # print(a_tono_sa)
    
    if min_a_tono_sa > a_tono_sa:
        min_a_tono_sa = a_tono_sa
        index = i + 1
        
print(index)

Measured memory_bytes: 9276
#include<iostream>
using namespace std;
int main() {
    int input;
    int number;
    int min = 0,max = 1001;
    int judge = 0;

    cin >> input;
    while(max-min != 1) {
        number = (max+min)/2;
        if(input < number*100) {
            max = number;
        }else if(input > number*105) {
            min = number;
        }else {
            judge =1;
            break;
        }
    }
    cout << judge << endl;

    return 0;


}

Measured memory_bytes: 256
/*
    ALWAYS REMMEMBER:
        NEVER GIVE UP !
        DON'T MESS WITH ME !!!
        "" THE EXPERT IN ANYTHING WAS ONCE A BEGINNER ""
*/

#include<bits/stdc++.h>
using namespace std;
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define f(i,a,b) for(ll i=a; i<=b; i++)
#define fi(i,a,b) for(ll i=a; i>=b; i--)
#define fa(x,b) for(auto x:b)
#define TC ll test_case; cin>>test_case; for(ll number=1 ; number <= test_case ; number ++ )
#define vll vector<ll>
#define pb push_back
#define pll pair<ll,ll>
#define mp make_pair
#define ff first
#define ss second
#define sz(a) (ll)(a).size()
#define sp(x) cout << fixed << setprecision(x);
#define ReadFile freopen("input.txt","r",stdin)
#define WriteFile freopen("output.txt","w",stdout)
#define endl "\n"

const ld pi = acos(-1);
const ll M=1e9+7,N=1e7+5,INF=1e18;

void solve()
{
    ll n,k;
    cin >> n >> k;
    cout << max (ceil(log(n)/log(k)),(double)1);
}

int32_t main()
{
    FIO
    solve();
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
      String str = sc.next();
      String x1 = str.substring(0,1);
      String x2 = str.substring(1,2);
      String x3 = str.substring(2,3);
      String x4 = str.substring(3,4);
      if(x1.equals(x2)||x2.equals(x3)||x3.equals(x4))
        System.out.println("Bad");
      else System.out.println("Good");
    }
}


Measured memory_bytes: 21844
#include <iostream>
using namespace std;
typedef long long ll;
const int N=2e5+5;
int ans[N];
int pow(ll x,int y,int mod){
    ll ans=1;
    while(y){
        if(y&1) ans=ans*x%mod;
        x=x*x%mod;
    }
    return ans;
}
ll x1[N],x2[N];
void init(){
    for(int i=1; i<N; i++) {
        int y=i,z=0;
        while(y) {
            if(y&1) z++;
            y>>=1;
        }
        ans[i]=ans[i%z]+1;
    }
}

int main() {
    init();
    int n;
    string s;
    cin>>n;
    cin>>s;
    int cnt=0;
    ll sum1=0,sum2=0;
    for(int i=0;i<n;i++){
        if(s[i]=='1')cnt++;
    }
    x1[0]=x2[0]=1;
    for(int i=1;i<n;i++){
        if(cnt-1>0)x1[i]=x1[i-1]*2%(cnt-1);
        x2[i]=x2[i-1]*2%(cnt+1);
    }
    for(int i=0;i<n;i++){
        if(s[i]=='1'){
            if(cnt-1>0)sum1=(sum1+x1[n-i-1])%(cnt-1);
            sum2=(sum2+x2[n-i-1])%(cnt+1);
        }
    }
    for(int i=0;i<n;i++){
        int sum;
        if(s[i]=='1'){
            if(cnt-1>0)sum=(sum1-x1[n-i-1]+cnt-1)%(cnt-1);
            else {
                cout<<"0\n";
                continue;
            }
        }
        else {
            sum=(sum2+x2[n-i-1])%(cnt+1);
        }
        cout<<ans[sum]+1<<"\n";
    }
    return 0;
}


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

int main() {
  int h,w,n;
  cin>>h>>w;
  int a[505][505];
  vector<tuple<int,int,int,int>> ans;
  rep(i,h) {
    rep(j,w) {
      cin>>a[i][j];
    }
  }
  
  rep(i,h) {
    rep(j,w-1) {
      if (a[i][j]%2) {
	ans.emplace_back(i+1,j+1,i+1,j+2);
	a[i][j+1]++;
	n++;
      }
    }
  }
  rep(i,h-1) {
    if (a[i][w-1]%2) {
      ans.emplace_back(i+1,w,i+2,w);
      a[i+1][w-1]++;
      n++;
    }
  }
  cout<<n<<endl;
  rep(i,ans.size()) {
    printf("%d %d %d %d\n",get<0>(ans[i]),get<1>(ans[i]),get<2>(ans[i]),get<3>(ans[i]));
  }
  return 0;
}



Measured memory_bytes: 5232
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <map>
#define rep(i,n) Rep(i,0,n)
#define Rep(i,k,n) for(int i=k ; i<n ; i++)
#define rep1(i,n) for(int i=1 ; i<=n ; i++)
#define vi vector<int>
#define vii vector<int,int>
#define Sort(v) sort(v.begin(),v.end())
#define Reverse(v) reverse(v.begin(),v.end())

//const int MOD = 1000000007;
//const int INF = 1<<30;
using namespace std;

string disp(bool x){
    return x ? "Yes" : "No";
}

void BubbleSort(int n,int x[],string y[]){
    int flag = 1;
    int ok = 0;
    
    while(flag) {
        flag = 0;
        for(int i=n-1 ; i>=ok+1 ; i--){
            if(x[i] < x[i-1]) {
                swap(x[i],x[i-1]);
                swap(y[i],y[i-1]);
                flag = 1;
            }
        }
        ok++;
    }
    
    rep(i,n) cout << y[i] << (i != n-1 ? ' ': '\n');
    return;
 }

void SelectSort(int n,int x[],string y[]){
    rep(i,n){
        int minj = i;
        for(int j=i ; j<n ; j++){
            if(x[minj]>x[j]) minj = j;
        }
        if(x[i]>x[minj]) {
            swap(x[i],x[minj]);
            swap(y[i],y[minj]);
        }
    }
    rep(i,n) cout << y[i] << (i != n-1 ? ' ': '\n');
    return;
}

string check(int n,string x[] , string y[]){
    bool flag = 1;
    rep(i,n){
        if(x[i] != y[i]) flag = 0;
    }
    return(flag ? "Stable" : "Not stable");
}

int main(){
    int n; cin >> n;
    string c[n] ,d[n]; int a[n],b[n];
    rep(i,n) {
        cin >> c[i];
        d[i] = c[i];
        
        a[i] = c[i][1]-'0';
        b[i] = a[i];
    }
    BubbleSort(n, a, c);
    cout << "Stable" << endl;
    SelectSort(n, b, d);
    cout << check(n,c,d) << endl;

}







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

int main() {
    int d, g;
    cin >> d >> g;
    vector<int> p(d), c(d);
    for (int i = 0; i < d; i++) cin >> p[i] >> c[i];

    int ans = 10 * 100;
    for (int combination = 0b0; combination < (1 << d); combination++) {
        int const_score = 0, const_num = 0, not_used_max = -1;
        for (int i = 0; i < d; i++) {
            if ((combination >> i) & 1) {
                const_score += (i + 1) * 100 * p[i] + c[i];
                const_num += p[i];
            } else {
                not_used_max = i;
            }
        }

        int adjust = 0, adjust_num = 0;
        if (const_score < g) {
            adjust = (not_used_max + 1) * 100;
            adjust_num = ((g - const_score) / adjust) + ((g - const_score) % adjust ? 1 : 0);
            if (adjust_num >= p[not_used_max]) continue;
        }

        ans = min(ans, const_num + adjust_num);
    }

    cout << ans << endl;
}

Measured memory_bytes: 1144
//includes
#include<iostream>
#include<vector>
#include<set>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<string>
#include<stack>
#include<map>
#include<queue>
#include<iomanip>
#include<numeric>
#include<assert.h>
#include<cstring>
#include<unordered_map>
#include<bitset>

//macros and consts
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define all(a) (a).begin(),(a).end()
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define FORE(i,a) for(auto &i : a)
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define accm accumulate
#define Fi first
#define Se second
#define INF 1e9
#define llINF (1LL<<60)
#define mINF -1e9
#define mllINF -(1LL<<60)
#define endl "\n"
#define CONT continue
#define BRK break
#define modulo(n, m) (((n)%(m)+(m))%m)

//shorter types
using namespace std;
using ll = long long;
using vi = std::vector<int>;
using vc = std::vector<char>;
using vll = std::vector<long long>;
using vs = std::vector<string>;
using Mi = map<int,int>;
using Mll = map<ll,ll>;
using UMi = unordered_map<int,int>;
using UMll = unordered_map<ll,ll>;
using Pi = pair<int,int>;
using Pll = pair<ll,ll>;
using vPi = vector<Pi>;
using vPll = vector<Pll>;
using vvi = vector<vector<int>>;
using vvll = vector<vector<ll>>;
using vvc = vector<vector<char>>;
using vvs = vector<vector<string>>;
using pqgi = priority_queue<int,vector<int>,greater<int>>;
using pqsi = priority_queue<int,vector<int>,less<int>>;
using pqgll = priority_queue<int,vector<int>,greater<int>>;
using pssll = priority_queue<int,vector<int>,less<int>>;
template<class T>
using vec = vector<T>;

//here begins your code
signed main(){
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  int N,M;
  cin >> N >> M;
  if(N == M){
  	cout << "Yes" << endl;
  }
  else{
  	cout << "No" << endl;
  }


  //check types
  //do not eb if you resize
  //resize before you access by idx
  return 0;
} 

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

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

#define MOD 1000000007

using namespace std;

bool compare( pair<int,int> a,pair<int,int> b ){
	return a.first < b.first;
}

int main(){
	int n;
	cin >> n;
	vector<pair<int,int>> arm(n);
	vector<pair<int,int>> range(n);
	for( int i=0; i<n; i++ ){
		cin >> arm[i].first >> arm[i].second;
		range[i].first = arm[i].first + arm[i].second;
		range[i].second = arm[i].first - arm[i].second;
	}
	int ans=1;
	int g;

	sort( all( range ) );

	if( n == 1 ){
		cout << 1 << endl;
		return 0;
	}

	g = range[0].first;
	for( int i=1; i<n; i++ ){
		if( g <= range[i].second ){
			ans++;
			g = range[i].first;
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 1792
// tested by Hightail - https://github.com/dj3500/hightail
import std.stdio, std.string, std.conv, std.algorithm;
import std.range, std.array, std.math, std.typecons, std.container, core.bitop;

int n, x;
int[] a;

void main() {
    scan(n, x);
    a = readln.split.to!(int[]);

    auto b = a.dup();

    long ans = 10L^^15;

    foreach (k ; 0 .. n) {
        long anst = 1L * k * x;

        foreach (i ; 0 .. n) {
            b[i] = min(b[i], a[(i - k + n) % n]);
        }

        anst += sum(b, 0L);
        ans = min(ans, anst);
    }

    writeln(ans);
}


void scan(T...)(ref T args) {
    string[] line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}


void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

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

#define SORT(c) sort((c).begin(), (c).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
#define ANS(ans) cout << (ans) << endl;
#define UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
typedef vector<int> VI;
typedef pair<int, int> P;

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

int main() {
  string s;
  cin>>s;
  char ch = s.back();

  string ans;
  if (ch == '3') {
    ans = "bon";
  }else if(ch == '0' || ch == '1' || ch == '6' || ch == '8'){
    ans = "pon";
  }else{
    ans = "hon";
  }

  ANS(ans);
  return 0;
}


Measured memory_bytes: 3620
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
int res = 0;
bool isok(int N, int K) {
	
	while (true) {
		K /= 3;
		if (K > 1) {
			N -= K;
		}
		else {
			break;
		}
	}
	
	return N >= 0;
}
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	if (N == 0) {
		cout << 0 << endl;
		return 0;
	}
	N--;
	res++;
	int k = 1;
	while (N > 0) {
		if (isok(N - 3 * k, 3 * k)) {
			k *= 3;
		}
		else if (isok(N - k, k)) {

		}
		else {
			k /= 3;
		}
		N -= k;
		res++;
	}
	cout << res << endl;
}


Measured memory_bytes: 3208
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define pll pair<ll,ll>
#define pii pair<int,int>
#define rep(i,n) for(int i=0;i<n;i++)
#define For(i,a,b) for(int i=a;i<b;i++)
#define sz(x) ((ll)(x).size())
#define pb push_back
#define mp make_pair
#define bit(n) (1LL<<(n))
#define F first
#define S second
#define debug(x) cerr << x << endl
#define Complex complex<double>
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
const ll INF = 1LL<<60;
const ll mod = (int)1e9 + 7;

/*
テストケース全てに目を通す
テストケースが2個以下だったらなんかある
N最小のコーナーケースがないか調べる
制約をしっかりと確認する（1からNまでの順列、全て異なる値などの制約も含め）
制約のn*mとn,mを読み違えない
操作の逆順を考える
オーバーフローしないか確かめる
Codeforcesではscanfを使う
modの引き算には+modをする
エラー出力は消す
エラー出力を消せ！！！！！
数値の区切り位置を誤読しない
cout << fixed;
cout << setprecision(n) << ans;
 */

int main() {
    ll h,w;
    cin >> h >> w;
    if(h==1 || w==1){
        cout << 1;
        return 0;
    }
    cout << (h*w+1)/2 << endl;



    
}

/*
*/


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader input =new BufferedReader (new InputStreamReader (System.in));
		String str = input.readLine( );
		String[] nl = str.split(" ");
		int n = Integer.parseInt(nl[0]);
		String[] list = new String[n];

		for(int i=0; i<n; i++){
			list[i] = input.readLine( );
		}
		Arrays.sort(list);
		String answer = "";
		for(int i=0; i<n; i++){
			answer = answer + list[i];
		}
		System.out.println(answer);
	}

}


Measured memory_bytes: 12236
#include <cstdio>
bool A[200001];
inline char tc(){
  static char fl[100],*A=fl,*B=fl;
  return A==B&&(B=(A=fl)+fread(fl,1,100,stdin),A==B)?EOF:*A++;  
}
inline int read(){
  int a=0;static char c;
  c = tc();
  while (c & 16)a=a*10+c-48,c=tc();
  return a;
}
int main(){
  register int n,m,a,b;n=read();m=read();
  while(m--){a=read();b=read();
    if(a==1){
      if(A[b])return puts("POSSIBLE"),0;
      A[b]=1;
    }
    if(b==n){
      if(A[a])return puts("POSSIBLE"),0;
      A[a]=1;
    }
  }
  puts("IMPOSSIBLE");
}

Measured memory_bytes: 384
#include <stdio.h>
int main(){    
int i, j, k;    
int n, x;    
int count;    
while(1){        
scanf("%d %d ", &n, &x);        
if(n==0&&x==0)break;        
count=0;       
for(i=1;3*i+3<=x;i++){            
for(j=i+1;i+2*j+1<=x;j++){                
for(k=n;k>j;k--){                    
if(x==i+j+k){                        
count++;                        
break;                    }
else if(x>=i+j+k){                        break;                    }                }            }        }        
printf("%d\n", count);    }    
return 0;
}


Measured memory_bytes: 2052
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    String aa,bb;
    aa = bb = "";
    for(int i = 0;i < b; i++){
      aa += a;
  }
    for(int i = 0;i < a; i++){
      bb += b;
    }
    System.out.println(aa.compareTo(bb) > 0 ? bb : aa);
  }
    
}

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

typedef long long int ll;
string s;
ll ans = 0;

int main() {
    cin >> s;
    ll cnt = 0;
    for(ll i = 0; i < s.length(); ++i) {
        if(s[i] == 'R') {
            cnt++;
            ans = max(ans, cnt);
        }
        else {
            cnt = 0;
        }
    }

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

Measured memory_bytes: 3544
#include<iostream>
#include<bitset>
#include<vector>
#include<algorithm>
#include<string>
#include <cstdlib> 
using namespace std;
int main()
{
  int64_t X,K,D;
  int64_t count=0;
  cin >> X>>K>>D;
  X=abs(X);
  count=X/D;
  if(count<K)
  {
  	X=X%D;
    while(X>0)
  	{
    	X-=D;
    	count++;
    	if(count==K)
    	{
      		break;
    	}
  	}
  }
  else if(count>=K)
  {
    X-=K*D;
    count=K;
  }
 
  if((K-count)%2==0)
  {
    cout << abs(X) << endl;
  }
  else
  {
    cout << abs(X+D) << endl;
  }
          
}


Measured memory_bytes: 3644
n=int(input())
count=0
ren=0
for i in range(n):
  a,b=map(int,input().split())
  if a==b:
    if count<3:
      count+=1
      ren=1
  elif count<3:
    count=0
if count>=3:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 9172
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define ULL unsigned long long
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define pll pair<LL,LL>
#define x first
#define y second
#define pi acos(-1)
#define sqr(x) ((x)*(x))
#define pdd pair<double,double>
#define MEMS(x) memset(x,-1,sizeof(x))
#define MEM(x) memset(x,0,sizeof(x))
#define less Less
#define EPS 1e-4
#define arg ARG
#define cpdd const pdd
#define rank Rank
vector<pii> v[100005];
int val[200005];
int color[200005];
int d[100005];
void dfs(int x,int op=0){
    
    if(color[x]!=-1)return;
   // printf("%d %d\n",x,op);
    for(auto it:v[x]){
        if(d[it.x]<d[x]){
            dfs(it.x);
            color[x]=color[it.x];
            val[it.y]=d[x]-d[it.x];
            return ;
        }
        if(d[it.x]==d[x]&&op==0){
         //   printf("%d %d\n",x,it.x);
            dfs(it.x,1);
            if(color[it.x]==-1)color[it.x]=0,color[x]=1;
            else color[x]=color[it.x]^1;
            val[it.y]=d[it.x];
            return ;
        }
    }
}
int main(){
    int n,m;
    scanf("%d %d",&n,&m);
    for(int i = 1;i<=n;i++)
        scanf("%d",&d[i]);
    for(int i =  0;i<m;i++){
        int x,y;
        scanf("%d %d",&x,&y);
        v[x].pb(mp(y,i));
        v[y].pb(mp(x,i));
    }
    for(int i = 1;i<=n;i++){
        int Min=1e9;
        for(auto it:v[i]){
            //if(d[it.x])
            Min=min(Min,d[it.x]);
        }
       // printf("%d\n",i);
        if(Min>d[i]){
            printf("-1\n");
            return 0;
        }
    }
    fill(val,val+m,1e9);
    MEMS(color);
    for(int i =1;i<=n;i++){
        dfs(i);
    }
    for(int i = 1;i<=n;i++){
       // printf("%d\n",color[i]);
        printf("%c","BW"[color[i]]);
    }
    printf("\n");
    for(int i = 0;i<m;i++)
        printf("%d\n",val[i]);
}
/*
2 6
5 7
7 5
4 3
6 4
7 3
6 5
5 7
3 6
4 7
*/
//a+a+1=10a+1
//3a+2=10a+2

Measured memory_bytes: 12288
n=int(input())
S=list(map(int,input().split()))
q=int(input())
T=list(map(int,input().split()))

c=0
for j in range(q):
	l=-1
	r=n
	while l+1<r:
		m=(l+r)//2
		if S[m]==T[j]:
			c+=1
			break
		elif S[m]<T[j]:
			l=m
		else:
			r=m
print(c)


Measured memory_bytes: 16704
#include <iostream>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <cassert>

#define REP(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define eb emplace_back

typedef long long ll;
using namespace std;

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s,t;cin >> s >> t;
    int a,b;cin >> a >> b;
    string u;cin >> u;
    if(u == s){
        cout << a-1 << " " << b << endl;
    }
    else{
        cout << a << " " << b-1 << endl;
    }
    
    return 0;
}


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

vector<int> fa;

void add(int x, int v) {
  while (x < (int)fa.size()) fa[x] += v, x += (x & -x);
}

int query(int x) {
  int ans = 0;
  while (x > 0) ans += fa[x], x -= (x & -x);
  return ans;
}

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

  int n, k;
  cin >> n >> k;
  vector<int> lf;
  vector<int> rg;
  rg.emplace_back(0);
  for (int i = 0; i < n; ++i) {
    int x;
    cin >> x;
    if (x < 0)
      lf.emplace_back(x);
    else
      rg.emplace_back(x);
  }
  lf.emplace_back(0);
  reverse(lf.begin(), lf.end());
  ll ans = 8e18;
  for (int i = 0; i < rg.size(); ++i) {
    if (k - i < lf.size()) {
      ll l = -lf[k - i];
      ll r = rg[i];
      ans = min(ans, r + l + min(l, r));
    }
  }
  cout << ans;
}

Measured memory_bytes: 1020
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<cstdlib>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<string>
#include<utility>
#include<vector>

using namespace std;

#define ll long long
#define pal pair<ll,ll>
#define pad pair<double,double>
#define PB push_back
#define MP make_pair
#define F first
#define S second

const ll MOD = 1e18+7;
const ll INF = 1e18;
const double EPS = 1e-8;

long long lpow(long long x, long long n) {
    long long ret = 1;
    while (n > 0) {
        if (n & 1) ret = ret * x % MOD;
        x = x * x % MOD;
        n >>= 1;
    }
    return ret;
}

template<typename T,typename U>
bool chmax(T& max, const U& x){
	if(max<x){
		max = x;
		return true;
	}
	return false;
}

template<typename T,typename U>
bool chmin(T& min, const U& x){
	if(min>x){
		min = x;
		return true;
	}
	return false;
}


int main(){
	ll tmp,n,keta;
	string ans="";
	cin >> n;

	for(ll i=1;;i++){
		n-=lpow(26,i);
		ans.PB('a');
		if(n<=0){
			keta = i;
			n+=lpow(26,i);
			break;
		}
	}
	ll dig = keta;
	while(keta>0){
		tmp = ceil((double)n/lpow(26,keta-1))+EPS;
		if(tmp!=0){
			ans[dig-keta]='a'+tmp-1;
		}else{
			ans[dig-keta]='z';
		}
		n=n%lpow(26,keta-1);
		keta-=1;
	}
	cout << ans << endl;
}

Measured memory_bytes: 3632
n=int(input())
s=input()
l,r=[],[]
ans=min(s.count("W"),s.count("E"))
k=s.count("E")
for i in range(n):
    if s[i]=="W":
        k+=1
    else:
        k-=1
    ans=min(ans,k)
print(ans)

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

using namespace std;

#define int long long
#define ar array
#define vt vector
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define sz(x) (int)(x).size()

#define F_OR(i, a, b, s) for (int i=(a); (s)>0?i<(b):i>(b); i+=(s))
#define F_OR1(e) F_OR(i, 0, e, 1)
#define F_OR2(i, e) F_OR(i, 0, e, 1)
#define F_OR3(i, b, e) F_OR(i, b, e, 1)
#define F_OR4(i, b, e, s) F_OR(i, b, e, s)
#define GET5(a, b, c, d, e, ...) e
#define F_ORC(...) GET5(__VA_ARGS__, F_OR4, F_OR3, F_OR2, F_OR1)
#define FOR(...) F_ORC(__VA_ARGS__)(__VA_ARGS__)
#define EACH(x, a) for (auto& x: a)
const int M = 1e9 + 7;

template<class T>
bool umin(T &a, const T &b) {
    return b < a ? a = b, 1 : 0;
}

template<class T>
bool umax(T &a, const T &b) {
    return a < b ? a = b, 1 : 0;
}

template<class A>
void read(vt<A> &v);

template<class A, size_t S>
void read(ar<A, S> &a);

template<class T>
void read(T &x) {
    cin >> x;
}

void read(double &d) {
    string t;
    read(t);
    d = stod(t);
}

void read(long double &d) {
    string t;
    read(t);
    d = stold(t);
}

template<class H, class... T>
void read(H &h, T &... t) {
    read(h);
    read(t...);
}

template<class A>
void read(vt<A> &x) {
    EACH(a, x)read(a);
}

template<class A, size_t S>
void read(array<A, S> &x) {
    EACH(a, x)read(a);
}

string to_string(char c) {
    return string(1, c);
}

string to_string(bool b) {
    return b ? "true" : "false";
}

string to_string(const char *s) {
    return string(s);
}

string to_string(string s) {
    return s;
}

string to_string(vt<bool> v) {
    string res;
    FOR(sz(v))res += char('0' + v[i]);
    return res;
}

template<size_t S>
string to_string(bitset<S> b) {
    string res;
    FOR(S)res += char('0' + b[i]);
    return res;
}

template<class T>
string to_string(T v) {
    bool f = 1;
    string res;
    EACH(x, v) {
        if (!f)
            res += ' ';
        f = 0;
        res += to_string(x);
    }
    return res;
}

template<class A>
void write(A x) {
    cout << to_string(x);
}

template<class H, class... T>
void write(const H &h, const T &... t) {
    write(h);
    write(t...);
}

void print() {
    write("\n");
}

template<class H, class... T>
void print(const H &h, const T &... t) {
    write(h);
    if (sizeof...(t))
        write(' ');
    print(t...);
}

template<class T, class U>
void vti(vt<T> &v, U x, size_t n) {
    v = vt<T>(n, x);
}

template<class T, class U>
void vti(vt<T> &v, U x, size_t n, size_t m...) {
    v = vt<T>(n);
    EACH(a, v)vti(a, x, m);
}


int modpow(int x, int p) {
    if (!p) return 1;
    int val = modpow(x, p / 2);
    val = (val * val) % M;
    if (p & 1) val = (val * x) % M;
    return val;
}

int inverse(int x) {
    return modpow(x, M - 2);
}

void solve() {
    int a, b, c, d;
    read(a, b, c, d);
    
    vt<int> v(101, 0);
    int ans = 0;
    FOR(i, a, b) v[i] = 1;
    FOR(i, c, d) {
        v[i]++;
        if (v[i] > 1) ans++;
    }
    print(ans);
}

int32_t main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    
    int tt = 1;
    //read(tt);
    FOR(tt) {
        //write("Case #", i + 1, ": ");
        solve();
        
    }
    
}


Measured memory_bytes: 3696
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e5+45;

int n,k,c;
string s;
int dpp[N],dps[N];

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> k >> c;
    cin >> s;
    int prvi = 1;
    while(s[prvi-1] == 'x'){
        prvi++;
    }
    dpp[prvi] = 1;
    for(int i = prvi+1; i <= n; i++){
        dpp[i] = dpp[i-1];
        if(s[i-1] == 'o' && i >= c+2){
            dpp[i] = max(dpp[i],dpp[i-c-1]+1);
        }
    }
    prvi = n;
    while(s[prvi-1] == 'x'){
        prvi--;
    }
    dps[prvi] = 1;
    for(int i = prvi-1; i >= 1; i--){
        dps[i] = dps[i+1];
        if(s[i-1] == 'o' && n-i+1 >= c+2){
            dps[i] = max(dps[i],dps[i+c+1]+1);
        }
    }
    for(int i = 1; i <= n; i++){
        if(s[i-1] == 'x'){
            continue;
        }
        if(dpp[i-1]+dps[i+1] < k){
            cout << i << endl;
        }
    }
}


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

using namespace std;


int main(){
    int num_query;
    int command,val;
    char key[20];

    scanf("%d",&num_query);
    map<string,int> map_array;

    for(int i = 0;i < num_query;i++){
        scanf("%d %s",&command,key);
        if(command == 0){
            scanf("%d",&val);
            map_array[key] = val;
        }else if(command == 1){
            if(map_array.find(key) != map_array.end()) printf("%d\n",map_array[key]);
            else printf("0\n");
        }else if(command == 2){
            if(map_array.find(key) != map_array.end()) map_array.erase(key);
        }
    }

    return 0;   
}


Measured memory_bytes: 25908
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<set>
#include<map>
#include<queue>
#define SF scanf
#define PF printf
#define MAXN 100010
using namespace std;
typedef long long ll;
set<int> st[MAXN];
map<ll,int> mp;
int n,fa[MAXN];
ll get_num(int x,int y){
	if(x>y)
		swap(x,y);
	return 1ll*(x-1)*n+y-1;
}
queue<ll> q;
void add_edge(int x,int y){
	ll id=get_num(x,y);
	mp[id]++;
	if(mp[id]==2)
		q.push(id);
	if(mp[id]>2){
		PF("NO");
		exit(0);	
	}
	st[x].insert(y);
	st[y].insert(x);
}
void Del(int x,int y){
	set<int>::iterator it=st[x].begin();
	for(;it!=st[x].end();it++){
		int u=*it;
		st[u].erase(x);
		if(u!=y){
			st[u].insert(y);
			st[y].insert(u);
			mp[get_num(u,y)]++;
			if(mp[get_num(u,y)]==2)
				q.push(get_num(u,y));
			if(mp[get_num(u,y)]>2){
				PF("NO!");
				exit(0);	
			}
		}
		mp.erase(get_num(u,x));	
	}
	st[x].clear();
}
int get_fa(int x){
	if(fa[x]==0)
		return x;
	fa[x]=get_fa(fa[x]);
	return fa[x];	
}
int main(){
	//freopen("bluered.in","r",stdin);
	//freopen("bluered.out","w",stdout);
	SF("%d",&n);
	int u,v;
	for(int i=1;i<2*n-1;i++){
		SF("%d%d",&u,&v);
		add_edge(u,v);	
	}
	for(int i=1;i<n;i++){
		if(q.empty()){
			PF("NO");
			return 0;	
		}
		ll id=q.front();
		q.pop();
		int u=id%n+1;
		int v=id/n+1;
		if(u==v){
			i--;
			continue;
		}
		u=get_fa(u);
		v=get_fa(v);
		if(st[u].size()>st[v].size())
			swap(u,v);
		Del(u,v);
		fa[u]=v;
	}
	PF("YES");
}

Measured memory_bytes: 36608
#include<stdio.h>
int three(int);
int main(){
    int x,k,i;
    scanf("%d",&x);
    for(i=1;i<=x;i++){
        k=three(i);
        if(i%3==0||k==3){
            printf(" %d",i);
        }
    }
    printf("\n");
    return 0;
}

int three(int a){
    while(10<a){
    if(a%10==3){
        break;
        }
        a/=10;
    }
    return a%10;
}


Measured memory_bytes: 2148
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <algorithm>
#include <queue>
using namespace std;
const int maxn = 1e5+10;
char in[maxn];
int cnt[5];
int main(){
    int i,j,len;
    while(~scanf("%s",in)){
        len = strlen(in);
        memset(cnt, 0, sizeof(cnt));
        for(i=0;i<len;i++){
            ++cnt[in[i] - 'a'];
        }
        int a3 = cnt[0];
        int b3 = cnt[1];
        int c3 = cnt[2];
        int cut = min(a3, min(b3,c3));
        bool flag = true;
        for(i=0;i<3;i++){
            cnt[i] -= cut;
            if(cnt[i] > 1){
                //cout<<i<<" "<<cnt[i]<<endl;
                flag = false;
                break;
            }
        }
        if(flag){
            printf("YES\n");
        }else{
            printf("NO\n");
        }
    }
    return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#include<iostream>
#include<cmath>
#include<vector>
#include<string>
#include<queue>
#include<set>
#include<map>
#include<algorithm>
#include<functional>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll, int> plli;
typedef pair<int, pii> pipii;
typedef vector<vector<int> > mati;
typedef vector<vector<double> > matd;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vector<vector<bool>>> vvvb;

#define FOR(i,x,y) for(ll i=(ll)x; i<(ll)y; ++i)
#define REP(i,y) FOR(i, 0, y)
#define RFOR(i,x,y) for(ll i=(ll)x; i>=(ll)y; --i)
#define RREP(i,x) RFOR(i, x, 0)

template <typename T>
void vec_print(vector<T> VEC){
  REP(i, VEC.size()){
    cout << VEC[i] << " ";
  }
  cout << "\n";
};

template <typename T>
void mat_print(vector<vector<T> > MAT){
  REP(i, MAT.size()){
    REP(j, MAT[i].size()){
      cout << MAT[i][j] << " ";
    }
    cout << "\n";
  }
};

template <typename CLASS1, typename CLASS2>
class HOGE{
  public:
    CLASS1 key;
    CLASS2 value;
    HOGE(void){
      return;
    };
    HOGE(CLASS1 key, CLASS2 value){
      this->key = key;
      this->value = value;
    };
    ~HOGE(void){
      return;
    };

    void print(void){
      cout << "key : " << key << ", value : " << value << "\n";
      return;
    };
    
    bool operator==(const HOGE &obj){
      return (this->value == obj.value);
    };
    bool operator<(const HOGE &obj){
      return (this->value < obj.value);
    };
    bool operator>(const HOGE &obj){
      return (this->value > obj.value);
    };
};

constexpr int INF = (1<<30);
constexpr ll INFLL = 1LL<<62;
constexpr long double EPS = 1e-12;
constexpr ll MOD = (ll)((1E+9)+7);

int main(){
  cin.tie(0); // cut the cin and cout (default, std::flush is performed after std::cin)
  ios::sync_with_stdio(false); // cut the iostream and stdio (DON'T endl; BUT "\n";)

  ll N;
  cin >> N;

  unordered_set<ll> st;

  ll N_sqrt = (ll)sqrt(N);

  if(N==1){
    cout << "0" << "\n";
    return 0;
  }

  for(ll N_m=1; N_m<=N_sqrt; ++N_m){
    ll m = (N-N_m)/N_m;
    if(N/m == N%m) st.emplace(m);
  }

  for(ll m=1; m<=(N/N_sqrt)+1; ++m){
    if(N/m == N%m && st.find(m)==st.end()) st.emplace(m);
  }

  ll ans = 0;
  for(auto itr : st){
    ans += itr;
  }

  cout << ans << "\n";

  return 0;
}

Measured memory_bytes: 384
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        #[allow(unused_mut)]
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

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

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

use std::collections::HashMap;

fn main() {
    input! {
       n: usize,
       s: [String; n],
    }
    let mut counter = HashMap::new();
    for si in s {
        *counter.entry(si).or_insert(0) += 1;
    }
    let max = counter.iter().map(|(_, v)| v).max().unwrap();
    let mut ans = vec![];
    for (k, v) in counter.iter() {
        if v == max {
            ans.push(k);
        }
    }
    ans.sort();
    for i in ans {
        println!("{}", i);
    }
}


Measured memory_bytes: 28428
#include <stdio.h>
int n, ans;
int a[100];
int b[100];
int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; i++)a[i] = 1000000;
	for (int i = 0; i < n - 1; i++) {
		scanf("%d", b + i);
		if (a[i] > b[i])a[i] = b[i];
		if (a[i + 1] > b[i])a[i + 1] = b[i];
	}
	for (int i = 0; i < n; i++) {
		ans += a[i];
	}
	printf("%d\n", ans);
}

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

int main()
{   int w,a,b;
    scanf("%d%d%d",&w,&a,&b);
    if(b>a+w){
        printf("%d",b-(a+w));
    }else if(a<=b&&b<=a+w){
        printf("0");
    }else if(a>b+w){
        printf("%d",a-(b+w));
    }else printf("0");
    return 0;
}


Measured memory_bytes: 128
N, M = map(int, input().split())
shops = [[int(i) for i in input().split()] for i in range(N)]
from operator import itemgetter
shops = sorted(shops, key=itemgetter(0))

ans = 0
k = 0
while M > 0:
    if M >= shops[k][1]:
        ans += shops[k][0] * shops[k][1]
        M -= shops[k][1]
    elif M < shops[k][1]:
        ans += shops[k][0] * M
        M = 0
    k += 1
print(ans)

Measured memory_bytes: 23652
N = gets.to_i
a = [nil]
N.times{ a.push( gets.to_i ) }

pos = 1
cnt = 1
loop do
  
  break if a[pos] == 2
  
  if a[pos].nil?
    cnt = -1
    break
  end

  tmp = a[pos]
  a[pos] = nil
  pos = tmp
  
  cnt += 1
  
  break if a[pos] == 2
  
end

puts cnt

Measured memory_bytes: 3124
import Control.Applicative
import Control.Monad
import Data.List
import Data.Char
strToInt s = (read :: String -> Int) s

main :: IO ()
main = do
    -- 整数の入力
    n <- readLn
    -- kaigyousuuretu
    ts <- map strToInt <$> replicateM n getLine
    -- 出力
    putStrLn . show $ foldl1' lcm ts


Measured memory_bytes: 1020
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
#define VL vector<ll>
#define VS vector<string>
#define VB vector<bool>
#define VP vector<pair<ll,ll>>
#define VVL vector<vector<ll>>
#define VVP vector<vector<pair<ll,ll>>>
#define PL pair<ll,ll>
#define ALL(v) (v).begin(), (v).end()
ll d1[4] = {1, -1, 0, 0};
ll d2[4] = {0, 0, 1, -1};

int main(){
    ll H, W;
    cin >> H >> W;
    VS s(H);
    rep(h, 0, H) cin >> s[h];
    VVL L(H, VL(W, 0)), R(H, VL(W, 0)), U(H, VL(W, 0)), D(H, VL(W, 0));
    
    // R方向に操作していくことで，Lの値が分かる．
    rep(h, 0, H){
        ll c = 0;
        rep(w, 0, W){
            if(s[h][w] == '.'){
                c++;
                L[h][w] = c;
            }else{
                c = 0;
            }
        }
        c = 0;
        for(ll w = W-1; w >= 0; w--){
            if(s[h][w] == '.'){
                c++;
                R[h][w] = c;
            }else{
                c = 0;
            }
        }
    }

    rep(w, 0, W){
        ll c = 0;
        rep(h, 0, H){
            if(s[h][w] == '.'){
                c++;
                U[h][w] = c;
            }else{
                c = 0;
            }
        }
        c = 0;
        for(ll h = H-1; h >= 0; h--){
            if(s[h][w] == '.'){
                c++;
                D[h][w] = c;
            }else{
                c = 0;
            }
        }
    }

    ll ans = 0;
    rep(h, 0, H){
        rep(w, 0, W){
            if(s[h][w] == '#') continue;
            ans = max(ans, L[h][w] + R[h][w] + U[h][w] + D[h][w] - 3);
        }
    }

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

Measured memory_bytes: 129664
//In The Name of Allah
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N = 110, M = 1e5 + 10;
const ll Inf = 1e18;

int w[N], v[N];
ll dp[N][M];

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int n, W;
    cin >> n >> W;
    for (int i = 1; i <= n; i ++)
        cin >> w[i] >> v[i];
    for (int i = 0; i < N; i ++)
        for (int j = 1; j < M; j ++)
            dp[i][j] = Inf;
    for (int i = 1; i <= n; i ++)
    {
        for (int j = 0; j < M; j ++)
        {
            dp[i][j] = dp[i - 1][j];
            if (v[i] <= j)
                dp[i][j] = min(dp[i][j], dp[i - 1][j - v[i]] + w[i]);
        }
    }
    ll ans = 0;
    for (ll i = 0; i <= n; i ++)
        for (ll j = 0; j < M; j ++)
            if (dp[i][j] <= W)
                ans = max(ans, j);
    cout << ans;
    return 0;
}


Measured memory_bytes: 86272
#include<stdio.h>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
 
 
using namespace std;
 
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
 
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
 
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
 
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
 
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
 
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
 
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;


void solve(std::string C){
    cout<<(char)(C[0]+1)<<endl;
}

int main(){
    std::string C;
    std::cin >> C;
    solve(C);
    return 0;
}


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

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

using namespace std;

const int INF = 1<<29;

int x[100010];
int main(){
	int n;
	cin >> n;
	rep(i, n){
		int a, b;
		cin >> a >> b;
		x[a]++, x[b+1]--;
	}

	int num = 1;
	int best = 0;
	rep(i, 100010){
		num += x[i];
		if(num >= i){
			best = max(best, i-1);
		}
	}
	cout << best << endl;

	return 0;
}

Measured memory_bytes: 1548
#include <cassert>

#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
//#include <boost/foreach.hpp>
//#include <boost/range/algorithm.hpp>
#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define ll long long
#define Sort(v) sort(all(v))
#define INF 1000000000
#define END return 0
#define pb push_back
#define se second
#define fi first
#define pb push_back
#define all(v) (v).begin() , (v).end()
#define MP make_pair
#define MOD 1000000007LL
using namespace std;
int day[12]={31,28,31,30,31,30,31,31,30,31,30,31};

int main (){
    int n;
    cin>>n;
    deque<int> v;
    rep(i,0,n){
        int cmd;cin>>cmd;
        if(cmd==0){
            int d,x;cin>>d>>x;
            if(d==0)v.push_front(x);
            else v.push_back(x);
        }else if(cmd==1){
            int p;cin>>p;
            cout<<v[p]<<endl;
        }else {
            int d;
            cin>>d;if(d==0){v.pop_front();}else {v.pop_back();}
        }
    }
}



/*

*/


Measured memory_bytes: 4620
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()


def main():
    h,w = LI()
    if h < w:
        h,w = w,h

    if h % 3 == 0 or w % 3 == 0:
        return 0

    r = inf
    if h >= 3:
        r = w
    w1 = w//2
    w2 = (w+1)//2
    for t in range(1,h):
        a = [t*w, (h-t) * w1, (h-t) * w2]
        tr = max(a) - min(a)
        if tr < r:
            r = tr
    h1 = h//2
    h2 = (h+1)//2
    for t in range(1,w):
        a = [t*h, (w-t) * h1, (w-t) * h2]
        tr = max(a) - min(a)
        if tr < r:
            r = tr
    return r



print(main())


Measured memory_bytes: 7248
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
#include <iostream>
#define maxn 200009
using namespace std;
long long a[maxn],b[maxn];
int p[maxn];
long long getsum(int x,long long *b){
	long long sum=0;
	while(x>0){
		sum+=b[x];
		x-=x&-x;
	}
	return sum;
}
void update(int x,int val,long long *b){
	while(x<maxn){
		b[x]+=val;
		x+=x&-x;
	}
}
void add(int L,int R,int val,long long *b){
	update(L,val,b);
	update(R+1,-val,b);
}
int main(){
	int n;
	scanf("%d",&n); 
	for(int i=1;i<=n;i++)
	scanf("%d",&p[i]);
	for(int i=1;i<=n;i++)
		add(i,i,i,a);
	for(int i=1;i<=n;i++)
		add(i,i,n+1-i,b);
	long long last=getsum(p[1],a)+getsum(p[1],b);
	for(int i=2;i<=n;i++){
		int pos=p[i];
		int A=getsum(pos,a);
		int B=getsum(pos,b);
		long long cur=A+B;
		if(cur<=last){
			add(pos,n,last-cur+1,a);
			add(1,pos,last-cur+1,b);
		}
		last=getsum(pos,a)+getsum(pos,b);
	}
	for(int i=1;i<=n;i++){
		printf("%I64d ",getsum(i,a));
	}
	puts("");
	for(int i=1;i<=n;i++)
		printf("%I64d ",getsum(i,b));
	puts("");
	//system("pause");
	return 0;
}

Measured memory_bytes: 3200
N=int(input())
x=[0]
inp=input().split()
for k in range(N):
  x.append(int(inp[k]))
y=[]
OK=True
for k in range(N):
  ok=False
  for i in range(len(x)-1,0,-1):
    if x[i]==i:
      y.insert(0,i)
      del x[i]
      ok=True
      break
  if ok==False:
    print(-1)
    OK=False
    break
if OK==True:
  for k in range(len(y)):
    print(y[k])
    

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

int main(){
  size_t x,y,a,b,c; cin>>x>>y>>a>>b>>c;
  vector<int> p(a),q(b),r(c);
  multiset<int> ps,qs;
  multiset<int,greater<int>> rs;
  for(size_t i=0; i<a; i++) {
    cin>>p[i];
    if(ps.size()<x) ps.insert(p[i]);
    else if(*ps.begin()<p[i]) {
      ps.erase(ps.begin());
      ps.insert(p[i]); 
    }    
  }
  for(size_t i=0; i<b; i++) {
    cin>>q[i];
    if(qs.size()<y) qs.insert(q[i]);
    else if(*qs.begin()<q[i]) {
      qs.erase(qs.begin());
      qs.insert(q[i]); 
    }    
  }
  for(size_t i=0; i<c; i++) {
    cin>>r[i];
    rs.insert(r[i]);
  }
  for(auto ite=rs.begin(); ite!=rs.end(); ite++) {
    if(min({*ps.begin(),*qs.begin(),*ite})==*ps.begin()) {
      ps.erase(ps.begin());
      ps.insert(*ite);
    } else if(min({*ps.begin(),*qs.begin(),*ite})==*qs.begin()) {
      qs.erase(qs.begin());
      qs.insert(*ite);    
    }
  }
  cout << accumulate(ps.begin(),ps.end(),0LL)+ accumulate(qs.begin(),qs.end(),0LL) << endl;
  return 0;  
}

Measured memory_bytes: 17504