akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;
int main(void) {
  int A; int B; int C; int D;
  cin >> A >> B >> C >> D;
  if (A <= C && C <= B) {
    if (D <= B) {
    	cout << D - C;
    }
    else  {
    	cout << B - C;
    }
  }
  else if (C < A) {
    if (D < A) {
      cout << 0;
    }
    else if (A <= D && D <= B) {
	  cout << D - A;
    }
    else {
      cout << B - A;
    }
  }
  else {
    cout << 0;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define EPS (1e-10)
#define equals(a, b) (fabs((a)-(b)) < EPS)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<double> vd;
typedef pair<double,double> PD;
typedef pair<int,P> ed;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
  
int main() {
  int N;
  cin >> N;
  vi l(2*N);
  rep(i,2*N) {
    cin >> l[i];
  }
  sort(rng(l));
  int acc = 0;
  rep(i,N) {
    acc += l[i*2];
  }
  cout << acc << endl;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#define MAX 500000
#define SENTINEL 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 i;
  int n1 = mid-left;
  int n2 = right - mid;
  for(i = 0; i < n1; i++) L[i] = A[left + i];
  for(i = 0; i < n2; i++) R[i] = A[mid + i];
  L[n1] = R[n2] = SENTINEL;
  int j = 0,k;
  i = 0;
  for(k = left;k<right;k++){
    cnt++;
    if(L[i] <= R[j]){
      A[k] = L[i++];
    }else{
      A[k] = R[j++];
    }
  }
}

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

int main(){
  int A[MAX],n,i;
  cnt = 0;

  scanf("%d",&n);
  for(i = 0; i < n; i++) scanf("%d",&A[i]);

  mergeSort(A,n,0,n);

  for(i = 0; i < n; i++){
    if(i) printf(" ");
    printf("%d",A[i]);
  }
  printf("\n");
  printf("%d\n",cnt);
  return 0;
}



Measured memory_bytes: 5636
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <stack>
#include <set>

using namespace std;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef pair<int, int> P;
typedef long long LL;
#define ALL(a) (a).begin(),(a).end()
#define PB push_back
#define MP make_pair
#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define IFOR(v,it) for(auto it=(v).begin();it!=(v).end();++it)
#define RIFOR(v,it) for(auto it=(v).rbegin();it!=(v).rend();++it)
#define IN_LL(v) LL v;cin>>v;
#define IN(v) int v;cin>>v;
#define OUT(v) cout<<v<<endl
#define MOD 1000000007

int gcd(int a, int b) {
  if (a < b)
    return gcd(b, a);
  if (b == 0)
    return a;
  return gcd(b, a % b);
}

int main() {
  IN(N);

  vector<int> A(N);
  REP(i, N)
    cin >> A[i];
  SORT(A);
  int ans = A[0];
  REP(i, N)
    ans = gcd(ans,A[i]);
  OUT(ans);

  return 0;
}


Measured memory_bytes: 640
#ifndef BZ
#pragma GCC optimize "-O3"
#endif
#include <bits/stdc++.h>
#define FASTIO ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define rep(i, l, r) for (ll i = (l); i < (r); ++i)
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
#define pii pair<ll, ll>
#define pll pair<ll, ll>
#define pli pair<ll, ll> 
#define pdd pair<ld, ld> 
#define pb push_back
#define reset(x,v) memset(x,v,sizeof(x))
#define mod 1000000007
using namespace std;

int main(){
	FASTIO
	int l, r, d;
	cin >> l >> r >> d;
	int c = 0;
	rep(i, l, r + 1){
		if(i % d == 0)
			c++;
	}
	cout << c;
    return 0;
}

Measured memory_bytes: 3604
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     @hamayanhamayan0
　　　　／　　　＼　 　  |　|
　　　 /　　 /￣￣￣￣/　　|
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
　 　　　＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/














int N; ll K; ll A[201010];
//---------------------------------------------------------------------------------------------------
ll getMinus(ll lim) { // [-inf, lim]
	vector<ll> mi, pl;
	rep(i, 0, N) {
		if (A[i] < 0) mi.push_back(A[i]);
		if (0 < A[i]) pl.push_back(A[i]);
	}

	int j = 0;
	ll res = 0;
	fore(m, mi) {
		// m * p <= lim
		while (j < pl.size() && lim < m * pl[j]) j++;
		res += pl.size() - j;
	}
	return res;
}
//---------------------------------------------------------------------------------------------------
ll getZeros() {
	int zero = 0;
	rep(i, 0, N) if (A[i] == 0) zero++;
	return 1LL * zero * (N - zero) + 1LL * zero * (zero - 1) / 2;
}
//---------------------------------------------------------------------------------------------------
ll getPlus(ll lim) {
	vector<ll> mi, pl;
	rep(i, 0, N) if (0 < A[i]) pl.push_back(A[i]);
	rrep(i, N - 1, 0) if (A[i] < 0) mi.push_back(-A[i]);

	ll res = 0;

	int n = mi.size();
	int j = n - 1;
	rep(i, 0, n) {
		while (i < j && lim < mi[i] * mi[j]) j--;
		res += max(0, j - i);
	}

	n = pl.size();
	j = n - 1;
	rep(i, 0, n) {
		while (i < j && lim < pl[i] * pl[j]) j--;
		res += max(0, j - i);
	}

	return res;
}
//---------------------------------------------------------------------------------------------------
ll getCount(ll lim) { // the number of pairs (i,j), A[i]*A[j] <= lim
	ll res = getMinus(min(lim, -1LL));
	if (0 <= lim) res += getZeros();
	if (0 < lim) res += getPlus(lim);
	return res;
}
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> N >> K;
	rep(i, 0, N) cin >> A[i];
	sort(A, A + N);

	ll ng = -infl, ok = infl;
	while (ng + 1 != ok) {
		ll md = (ok + ng) / 2;
		if (K <= getCount(md)) ok = md;
		else ng = md;
	}
	cout << ok << endl;
}







Measured memory_bytes: 5260
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
int N,s[86400],t[86400],u[86400];
double L;
bool one(double& v,double a){
	int x=0;
	rep(i,N){
		v=min(L,v+(s[i]-x)*a);
		x=s[i];
		v=min(L,v+(t[i]-x)*(a-u[i]));
		if(v<0) return 0;
		x=t[i];
	}
	v=min(L,v+(86400-x)*a);
	return 1;
}
double can(double a){
	double v=L;
	if(!one(v,a)) return 0;
	double v1=v;
	if(!one(v,a)) return 0;
	return abs(v-v1)<1e-9;
}
int main(){
	while(true){
		cin>>N>>L;
		if(N==0) break;
		rep(i,N) cin>>s[i]>>t[i]>>u[i];
		double ub=1e6,lb=0;
		rep(tt,100){
			double m=(ub+lb)/2;
			if(can(m)) ub=m;
			else lb=m;
		}
		printf("%.12f\n",ub);
	}
}

Measured memory_bytes: 2260
N = input()
k = ["2","4","5","7","9"]
l = ["0","1","6","8"]
m = ["3"]
if len(N) == 3:
    S = N[2]
elif len(N) == 2:
    S = N[1]
else:
    S = N[0]
if S in k:
    print("hon")
elif S in l:
    print("pon")
else:
    print("bon")

Measured memory_bytes: 9064
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <cmath>
#include <queue>
#include <stack>
#include <list>
#include <functional>
#include <numeric>
#include <iostream>
#include <string>
#include <time.h>
#include <bitset>

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }

int K;

int main() {

	cin >> K;

	vector<ll> run;
	vector<ll> cur;

	rep(i, 9) run.push_back(i + 1);
	rep(i, 9) cur.push_back(i + 1);
	while (run.size() < K) {
		vector<ll> next;
		for (auto cc : cur) {
			if (cc % 10 == 0) {
				next.push_back(cc * 10);
				next.push_back(cc * 10 + 1);
			}
			else if (cc % 10 == 9) {
				next.push_back(cc * 10 + 8);
				next.push_back(cc * 10 + 9);
			}
			else {
				next.push_back(cc * 10 + cc % 10 - 1);
				next.push_back(cc * 10 + cc % 10);
				next.push_back(cc * 10 + cc % 10 + 1);
			}
		}
		cur = next;
		for (auto nn : next) run.push_back(nn);
	}

	cout << run[K - 1] << endl;

	return 0;
}


Measured memory_bytes: 4436
#include "bits/stdc++.h"
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)
#define ALL(v) v.begin(), v.end()
#define FS first
#define SC second
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())
#define MEMSET(v, h) memset((v), h, sizeof(v))
#define SQR(x) ((x) * (x))
#define BIT(n) (1LL<<(n))
#define PCNT(x) __builtin_popcountll(x)
#define PB push_back
#define MP make_pair
#define endl "\n"
using namespace std;
typedef long long LL;
typedef long double LD;
typedef vector<int> VI;
typedef vector<LL> VLL;
typedef vector<bool> VB;
typedef vector<vector<int> > VVI;
typedef vector<vector<bool> > VVB;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
const LL MOD=1000000007ll;
const LL INF=2000000000ll;
template <class T> bool chmax( T& a, T b );
template <class T> bool chmin( T& a, T b );
int dx[4] = {1,0,-1,0};
int dy[4] = {0,1,0,-1};

long power(long a,long b){return b?power(a*a%MOD,b/2)*(b%2?a:1)%MOD:1;}

long perm(int N, int K){
	long x=1;
	for(int i=1;i<=K;i++)
	{
		x=x*(N-i+1)%MOD;
	}
	return x%MOD;
}

long factorial(int N){
	return perm(N,N);
}

long comb(int N,int K){
	long x=1,y=1;
	for(int i=1;i<=K;i++)
	{
		x=x*(N-i+1)%MOD;
		y=y*i%MOD;
	}
	return x*power(y,MOD-2)%MOD;
}

long hcomb(int N, int K){
    return comb(N+K-1, N-1);
}

bool isprime(int n) {
    if (n < 2) return false;
    for (int i = 2; i*i <= n; ++i) {
        if (n % i ==  0) return false;
    }
    return true;
}

void eratosthenes(int n){
	// エラトステネスのふるい
    bitset<1000000> is_prime(0); // 十分大きなサイズを確保します
    for (int i = 2; i <= n; ++i) is_prime.set(i); // とりあえず全部ふるいに入れます
    for (int i = 2; i <= n; ++i) {
        if (is_prime[i]) { // 素数 i を発見したら
            for (int j = i * 2; j <= n; j += i) {
                is_prime.reset(j); // i の倍数をふるい落とす
            }
        }
    }
	for (int i = 2; i <= n; ++i) {
        if (is_prime[i]) cout << i << endl;
    }
}

void dfs(const vector<vector<int> > &G, int v, vector<int> &seen) {
    seen[v] = true; // v を訪問済にする

    // v から行ける各頂点 next_v について
    for (int next_v : G[v]) { 
        if (seen[next_v]) continue; // next_v が探索済だったらスルー
        dfs(G, next_v, seen); // 再帰的に探索
    }
}

void bfs(const vector<vector<int> > &G, int v, vector<int> &dist){
    REP(i,SZ(dist)) dist[i] = -1; // 全頂点を「未訪問」に初期化
    queue<int> que;

    // 初期条件 (頂点 0 を初期ノードとする)
    dist[v] = 0;
    que.push(v); // 0 を橙色頂点にする

    // BFS 開始 (キューが空になるまで探索を行う)
    while (!que.empty()) {
        v = que.front(); // キューから先頭頂点を取り出す
        que.pop();

        // v から辿れる頂点をすべて調べる
        for (int next_v : G[v]) {
            if (dist[next_v] != -1) continue; // すでに発見済みの頂点は探索しない

            // 新たな白色頂点 nv について距離情報を更新してキューに追加する
            dist[next_v] = dist[v] + 1;
            que.push(next_v);
        }
    }
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(10);

    LL N, A, B, T;
    cin >> N >> A >> B;
    T = A+B;

    LL ans = 0;
    ans += N/T*A;
    ans += min(A,N%T);

    cout << ans << endl;

}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG  // 添字の配列で範囲外エラー表示させる
#define rep(i, n) for (int i = 0; i < (n); i++)
#include <bits/stdc++.h>
using namespace std;
using ll = long;
using P = pair<int, int>;

int myLowerBound(vector<int> &A, int key) {
    int left = 0;
    int right = A.size();
    while (left < right) {
        int mid = (left + right) / 2;
        if (A[mid] == key)
            return true;
        else if (key < A[mid])
            right = mid;
        else
            left = mid + 1;
    }
    return false;
}

int main() {
    int n, q;
    vector<int> S, T;

    cin >> n;
    S.assign(n, 0);
    rep(i, n) cin >> S.at(i);
    cin >> q;
    T.assign(q, 0);
    rep(i, q) cin >> T.at(i);

    int count = 0;
    sort(S.begin(), S.end());
    rep(i, q) {
        bool ok = myLowerBound(S, T.at(i));
        if (ok) {
            count++;
        }
    }

    cout << count << endl;

    return 0;
}


Measured memory_bytes: 3400
#include<iostream>
#include<algorithm>
#define rep(i,f,t) for(int i=f;i<t;i++)
#define ll long long
using namespace std;
int main(){
	ll n,m,k;
  	cin>>n>>m>>k;
  	ll a[n],b[m],dp[m+1],sum[n+1];
  	sum[0]=0;dp[0]=0;
  	rep(i,0,n){cin>>a[i];sum[i+1]=sum[i]+a[i];}
  	rep(i,0,m){cin>>b[i];dp[i+1]=dp[i]+b[i];}
  	ll maxi=0;
  	rep(i,0,n+1){
  		ll chk=k-sum[i];
//  		cout<<chk<<endl;
  		if(chk<0)break;
  		ll p=upper_bound(dp,dp+m+1,chk)-dp;  
  		p--;
  		p+=i;
    	maxi=max(maxi,p);
  	}
	cout<<maxi<<endl;
  	return 0;
}

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

// どんな順番でやっても繰り上がりの回数もmod10の値も同じなので変わらない

int main() {
    int M;
    cin >> M;
    ll sum = 0;
    ll ans = 0;
    for (int i = 0; i < M; ++i) {
        ll c, d;
        cin >> d >> c;
        sum += c * d;
        ans += c;
    }
    ans--; // とりあえず全部足す
    while (sum / 10){
        ans += sum / 10;
        sum = sum % 10 + sum / 10;
    }
    cout << ans << "\n";
    return 0;
}

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

#ifdef LOCAL

template<class T, class U>
ostream& operator<<(ostream& os, pair<T, U> p) {
	os << "(" << p.first << ", " << p.second << ")";
	return os;
}

template<template<class, class...> class C, class... A>
typename enable_if<!is_same<C<A...>, string>::value, ostream&>::type
operator<<(ostream& os, class C<A...> c) {
	auto i = c.begin();
	while (i != c.end()) {
		os << " {"[i == c.begin()] << *i;
		os << ",}"[++i == c.end()];
	}
	return os;
}

#define debug(x) cerr << #x << " = " << x << endl;
#else
#define debug(...) {}
#endif

const int N = 1e6;
long long infLL = 1e18;
int inf = 1e9;

int tab[2][N];
int dp[2][N];

int main() {
	ios_base::sync_with_stdio(false);
	int n;
	cin >> n;
	for (int i= 0; i < 2; i ++)
		for (int j = 0; j < n; j ++){
			cin >> tab[i][j];
		}
	for (int i = 0; i < 2; i ++) {
		for (int j = 0; j < n; j ++) {
			if (i > 0 && j > 0) dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
			else if (i > 0) dp[i][j] = dp[i-1][j];
			else if (j > 0) dp[i][j] = dp[i][j-1];
			else dp[i][j] = 0;
			dp[i][j] += tab[i][j];
		}
	}
	cout << dp[1][n-1];
}


Measured memory_bytes: 6400
#include<bits/stdc++.h>
#include<stdio.h>
#include <algorithm>
#include <iostream>
#include <iterator>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cstdio>
#include <vector>
#include <cmath>
#include <queue>
#include <deque>
#include <stack>
#include <list>
#include <map>
#include <set>
using namespace std;
int main()
{

    int t,n,i,arra[1000],c1=0,c2=0,c3=0,c4=0;
    string s;
        cin>>n;
        for(i=0;i<n;i++)
        {
            cin>>s;
            if(s=="AC")
               c1++;
            else if(s=="WA")
               c2++;
            else if(s=="TLE")
               c3++;
            else if(s=="RE")
               c4++;

        }

        cout<<"AC x "<<c1<<endl;
         cout<<"WA x "<<c2<<endl;
          cout<<"TLE x "<<c3<<endl;
           cout<<"RE x "<<c4<<endl;
    return 0;
}



Measured memory_bytes: 3628
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int a[105];
int main(void){
    int n; cin>>n;
    int ans=0;
    cin>>a[0];
    for(int i=1;i<n;i++){
        cin>>a[i];
        if(a[i]==a[i-1]){
            a[i]=-1;
            ans++;
        }
    }
    cout<<ans<<endl;
    
    
}


Measured memory_bytes: 256
// D - 11
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
#define rp(i,s,e) for(int i=(s);i<(e);++i)

#define MAX 100000
ll fac[MAX+1]; // 累乗 n!
ll inv[MAX+1]; // 逆元 1/n
ll finv[MAX+1]; // 逆元の累乗 (n^-1)! = (1/n)!

void init(int n, int p){
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	rp(i, 2, n+1){
		fac[i] = fac[i-1] * i % p;
		inv[i] = p - inv[p%i] * (p/i) % p;
		finv[i] = finv[i-1] * inv[i] % p;
	}
}

ll nCk_mod(int n, int k, int m){
	if(n<k || n<0 || k<0) return 0;
	return fac[n] * (finv[n-k] * finv[k] % m) % m;
}

void solve(int N, int d){
	int MOD = 1000000007;
	init(N+1+1, MOD);
	rp(k, 1, N+2){
		ll ans = (nCk_mod(N+1, k, MOD) - nCk_mod(N-d, k-1, MOD) + MOD) % MOD;
		cout<< ans <<endl;
	}
}

int in(int N){//d=R-L; L & R of the same value
	int d = 0;
	vi exist(N+1, -1);
	rp(i, 0, N+1){
		int a; cin>>a;
		if(exist[a] >= 0){
			d = i - exist[a];
			break;
		}
		exist[a] = i;
	}
	return d;
}

int main(){
	int N; cin>>N;
	solve(N, in(N));
}

Measured memory_bytes: 3576
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double pi=3.141592653589793;
typedef unsigned long long ull;
typedef long double ldouble;
const ll INF=1e18;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


int main(){
    int N;
    cin >> N;
    vector<ll> a(3*N), b(N+2), e(N+2);
    rep(i, 3*N) cin >> a.at(i);
    priority_queue<ll, vector<ll>, greater<ll> > begin;
    priority_queue<ll> end;
    ll begin_sum = 0, end_sum = 0;
    rep(i, N){
        begin.push(a.at(i));
        begin_sum += a.at(i);
    }
    rep2(i, 2*N, 3*N) {
        end.push(a.at(i));
        end_sum += a.at(i);
    }
    b.at(0) = begin_sum;
    rep2(i, N, 2*N + 1){
        ll tmp = begin.top();
        if(a.at(i) > tmp){
            begin.pop();
            begin.push(a.at(i));
            begin_sum += (a.at(i) - tmp);
            b.at(i - N + 1) = begin_sum;
        }
        else {
            b.at(i - N + 1) = e.at(i - N);
        }
    }
    e.at(N+1) = end_sum;
    for(int i = 2*N-1; i >= N-1; i--){
        ll tmp = end.top();
        if(a.at(i) < tmp){
            end.pop();
            end.push(a.at(i));
            end_sum += (a.at(i) - tmp);
            e.at(i - N + 1) = end_sum;
        }
        else {
            e.at(i - N + 1) = e.at(i - N + 2);
        }
    }
    ll ans = -1*INF;
    rep(i, N+1){
        ll tmp = b.at(i) - e.at(i+1);
        chmax(ans, tmp);
    }
    cout << ans << endl;

}

Measured memory_bytes: 9552
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <cstdio>
#include <map>
#include <set>
#include <utility>
#include <vector>
#include <queue>
#include <cmath>
#define read(X) scanf("%d",&X);
#define readLL(X) cin>>X;
#define readN(N,a) for(int i=0;i<N;i++)scanf("%lld",&a[i]);
#define LL long long
#define FOR(x,a,b) for(int x=a;x<b;x++)
#define pii pair<int,int>
#define INF 3000000
using namespace std;

long long A,B;

long long getnaik(long long upto){
	long long kagi=1;
	while (kagi <= upto) kagi*=2;
	return kagi-1;

}

int main(){
	cin>>A>>B;
	long long res=0;
	long long sum=0;
	if (A==B) {cout<<1<<endl; return 0;}
	while(true){
		long long kagi=1;
		
		if (A> B) swap(A,B);
		while ((kagi <= B)) kagi*=2;
		kagi/=2;
		//cout<<A<<" "<<B<<endl;
		if (kagi > A){
			long long ekstra = kagi - A;
			long long atas = getnaik(B - kagi);
			long long tot = min(ekstra + atas,  kagi - 1);
			res = kagi + tot - A + 1;
			cout<<res<<endl;
			sum+=res;
			break;
		} 
		if (A >= kagi) A-=kagi;
		B-=kagi;
		if (B==0) break;
	}


}

Measured memory_bytes: 256
k,n = gets.chomp.split.map(&:to_i)
line = gets.chomp.split.map(&:to_i)
ar = []
line.each_with_index do |x, i|
  if i != line.size - 1
    ar<< line[i+1]-x
  end    
end  
ar << k-line[-1]+line[0]

puts ar.inject(:+)-ar.max

Measured memory_bytes: 18364
#include <cstdio>
#include <cstring>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>

using namespace std;

int main()
{
	int n;
	long long int a[100000], asum[100000];
	scanf("%d", &n);
	for(int i=0; i<n; i++){
		scanf("%lld", &a[i]);
	}
	sort(a, a+n);
	for(int i=0; i<n; i++){
		if(i==0){
			asum[0]=a[0];
		}else{
			asum[i]=asum[i-1]+a[i];
		}
	}
	int imax=0;
	for(int i=1; i<n; i++){
		if(a[i]>2*asum[i-1]){
			imax=i;
		}
	}
	printf("%d\n", n-imax);
	return 0;
}

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

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

  if (s.size() < 2 || s.size() % 2 != 0) {
    cout << "No" << endl;
    return 0;
  }

  bool yes = true;
  for (int i = 0; i < s.size(); i += 2) {
    if (s[i] == 'h' && s[i + 1] == 'i')
      continue;
    yes = false;
  }

  if (yes)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<string>
#include<cmath>
#include<math.h>
#include<vector>
#include<algorithm>
#include<map>
#pragma warning(disable: 4996)
#define rep(i,n) for(int i = 1; i <= (n); i++)
using namespace std;
using ll = long long;


int main() {

	ll N;
	cin >> N;
	ll a, b;
	ll num = 1 * pow(10, 12);
	rep(i, sqrt(N)) {
		if (N % i == 0) {
			a = i;
			b = N / i;
			if ((a + b - 2) < num) {
				num = a + b - 2;
			}
		}
	}
	cout << num << endl;
	return 0;
}

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

int main() {
	string S;
	cin >> S;
	int nums[3] = { 0,0,0 };
	for (char c : S) nums[c - 'a']++;
	cout << (max({ abs(nums[0] - nums[1]) ,abs(nums[1] - nums[2]) ,abs(nums[2] - nums[0]) }) >= 2 ? "NO" : "YES") << endl;
}

Measured memory_bytes: 512
const MOD: i64 = 1_000_000_007;

struct Combination {
    fact: Vec<i64>,
    inv_fact: Vec<i64>,
}

impl Combination {
    fn new(n: usize) -> Combination {
        let mut fact = vec![0; n + 1];
        let mut inv_fact = vec![0; n + 1];
        fact[0] = 1;
        for i in 1..=n {
            fact[i] = fact[i - 1] * i as i64 % MOD;
        }
        inv_fact[n] = Self::pow(fact[n], MOD as usize - 2);
        for i in (1..=n).rev() {
            inv_fact[i - 1] = inv_fact[i] * i as i64 % MOD;
        }

        Combination { fact, inv_fact }
    }

    fn pow(mut a: i64, mut n: usize) -> i64 {
        let mut res = 1;
        while n > 0 {
            if n & 1 > 0 {
                res = res * a % MOD;
            }
            a = a * a % MOD;
            n >>= 1;
        }
        res
    }
    
    fn c(&self, n: usize, r: usize) -> i64 {
        if n < r { return 0; }
        let tmp = self.inv_fact[n - r] * self.inv_fact[r] % MOD;
        self.fact[n] * tmp % MOD
    }

    fn h(&self, n: usize, r: usize) -> i64 {
        self.c(n + r - 1, r)
    }
}

fn main() {
    let s: usize = {
        let mut buf = String::new();
        std::io::stdin().read_line(&mut buf).unwrap();
        buf.trim_end().parse().unwrap()
    };

    let comb = Combination::new(s);

    let mut ans = 0;
    for n in 1..=(s / 3) {
        let r = s - 3 * n;
        ans = (ans + comb.h(n, r)) % MOD;
    }
    println!("{}", ans);
}

Measured memory_bytes: 2180
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<functional>
#include<map>
#include<cmath>
#include<iomanip>

using namespace std;

typedef long long ll;

int gcd(int a, int b){
 if(a < b) return gcd(b, a);

 if(b == 0) return a;
 else return gcd(b, a % b);
}

int main()
{
  int n; cin >> n;
  vector<int> a(n);
  for(int i = 0; i < n; i++) cin >> a[i];

  //累積GCD
  vector<int> left(n + 1, 0), right(n + 1, 0);
  for(int i = 0; i < n; i++) left[i + 1] = gcd(left[i], a[i]);
  for(int i = n - 1; i >= 0; i--) right[i] = gcd(right[i + 1], a[i]);

  int res = 0;
  for (int i = 0; i < n; i++)
  {
    int l = left[i];
    int r = right[i + 1];

    res = max(res, gcd(l, r));
  }

  cout << res << endl;
  return 0;
}


Measured memory_bytes: 1408
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var s []string

func print(A []int) {
	for i, o := range A {
		s[i] = strconv.Itoa(o)
	}
	fmt.Println(strings.Join(s, " "))
}

func main() {
	var sc = bufio.NewScanner(os.Stdin)

	sc.Scan()
	N, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	s = make([]string, N)

	sc.Scan()
	A := make([]int, N)
	for i, v := range strings.Split(sc.Text(), " ") {
		n, e := strconv.Atoi(v)
		if e != nil {
			panic(e)
		}
		A[i] = n
	}

	print(A)
	for i := 1; i < N; i++ {
		v := A[i]
		j := i - 1
		for j >= 0 && A[j] > v {
			A[j+1] = A[j]
			j--
		}
		A[j+1] = v
		print(A)
	}
}


Measured memory_bytes: 1208
import heapq

n = int(input())

a = list(map(int,input().split()))

func = lambda p: p * (-1)

b = list(map(func,a[:]))

#print(a)
#print(b)

l = [0] * (3*n)

first = a[0:n]
second = b[2*n:3*n]

x = [0] * (3*n)
y = [0] * (3*n)

x[n-1] = sum(first)
y[2*n-1] = sum(second)

heapq.heapify(first)
heapq.heapify(second)

for i in range(n,2*n):
    heapq.heappush(first, a[i])
    s = first[0]
    heapq.heappop(first)
    x[i] = x[i-1] + a[i] - s

for i in range(n,2*n):
    heapq.heappush(second, b[-i-1])
    t = second[0]
    heapq.heappop(second)
    y[-i-2] = y[-i-1] + b[-i-1] - t
    
for i in range(n-1,2*n):
    l[i] = x[i] + y[i]
    
#print(x)
#print(y)
#print(l)

print(max(l[n-1:2*n]))

Measured memory_bytes: 47052
#ifdef debug
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>

using namespace std;

#define vec vector
#define ALL(x) (x).begin(), (x).end()

typedef unsigned int ui;
typedef long long ll;
typedef long double ld;
typedef pair< int, int > pii;
typedef pair< long long, long long > pll;

const int inf = 1e9;
const ll inf64 = 1e18;

const int N = 1005;

int n;
int a[N];
ll dp[N];
int fr[N];

int main() {

#ifdef debug
    freopen("input.txt", "r", stdin);
#endif

    cin >> n;

    for(int i = 1;i <= n;i++) {
        cin >> a[i];
    }

    fill(dp + 1, dp + n + 1, -inf64);
    fill(fr + 1, fr + n + 1, -1);

    for(int i = 1;i <= n;i++) {
        dp[i] = a[i];
        for(int j = 1;j + 1 < i;j++) {
            if((i - j - 1) % 2 && dp[i] < dp[j] + a[i]) {
                dp[i] = dp[j] + a[i];
                fr[i] = j;
            }
        }
    }

    vec< int > way;
    int best = -1;

    for(int i = 1;i <= n;i++) {
        if(best == -1 || dp[i] > dp[best]) {
            best = i;
        }
    }

    cout << dp[best] << "\n";

    while(best != -1) {
        way.push_back(best);
        best = fr[best];
    }

    reverse(ALL(way));

    vec< int > res;

    for(int i = n;i > way.back();i--) {
        res.push_back(i);
    }

    for(int i = 1;i < way.front();i++) {
        res.push_back(1);
    }

    for(int i = 0;i + 1 < (int)way.size();i++) {
        int len = way[i + 1] - way[i] - 1;
        for(int j = len - 2;j > 0;j -= 2) {
            res.push_back(j + 2);
        }
        res.push_back(2);
    }

    cout << (int)res.size() << "\n";

    for(int x : res) {
        cout << x << "\n";
    }

    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <complex>
#include <cstdio>
#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>
#if __cplusplus >= 201103L
#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>
#endif

using namespace std;

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

typedef long long ll;

const int Inf = 100100100;
const double EPS = 1e-9;

int gcd(int a, int b) {
    if (b == 0) {
        return a;
    } else {
        return gcd(b, a % b);
    }
}

int lcm(int a, int b) {
    return a * b / gcd(a, b);
}

int bitCount(long bits) {
    bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
    bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
    bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
    bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
    return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;  cin >> n;
    int ans = 0;
    int active = 0;
    vector<int> h(n);
    rep(i, n) {
      cin >> h[i];
    }
    rep(i, n) {
      if (active >= h[i]) {
        active = h[i];
      } else {
        ans += h[i] - active;
        active = h[i];
      }
    }
    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
tot=sum(a)

v=[1]
for q in a:
    tot-=q
    v.append(min(2*(v[-1]-q),tot))
    
if all([u>=0 for u in v]):
    print(sum(v))
else:
    print(-1)

Measured memory_bytes: 646076
import itertools
import sys
import math
import numpy as np
from collections import deque
from itertools import combinations
from functools import reduce
from functools import lru_cache
sys.setrecursionlimit(10**9)

def main():
    S = list(input())
    N = len(S)

    def is_kaibun(s,e):
        for i in range(s,e-s+1):
            if S[e-i] != S[i]:
                return False
        return True

    if is_kaibun(0,(N-1)//2-1) and is_kaibun(0,N-1)  and is_kaibun((N+3)//2-1,N-1):
        print("Yes")
    else:
        print("No")


if __name__ == "__main__":
  main()


Measured memory_bytes: 21412
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define chmax(a, b) a = max(a, b)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;

using ll = long long;

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

	string s;
	string t;
	int q;
	cin >> s >> q;
	while (q--) {
		int qi;
		cin >> qi;
		if (qi == 1) {
			swap(s, t);
		} else {
			int f; char c;
			cin >> f >> c;
			if (f == 1) t += c;
			else s += c;
		}
	}
	reverse(all(t));
	cout << t << s << "\n";
}


Measured memory_bytes: 980
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int x = sc.nextInt();
        int y = sc.nextInt();

        int ans = Integer.MAX_VALUE;
        for (int i = 0; i <= Math.max(x, y); ++i) {
            int X = x - i > 0 ? x - i : 0;
            int Y = y - i > 0 ? y - i : 0;
            int tmp = (c * 2) * i + a * X + b * Y;
            ans = Math.min(tmp, ans);
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 22996
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>

int inorinn(const void* x, const void* y) {
	int64_t a = *(const int64_t*)x, b = *(const int64_t*)y;
	return a < b ? -1 : a > b;
}

int32_t N;
int64_t M;
int64_t A[114514];

int64_t mizuhasu[114514];

int main(void) {
	int32_t i;
	int64_t mikakosi = 0;
	int32_t parunyasu = 0;
	if (scanf("%" SCNd32 "%" SCNd64, &N, &M) != 2) return 1;
	for (i = 0; i < N; i++) {
		if (scanf("%" SCNd64, &A[i]) != 1) return 1;
	}
	for (i = 1; i <= N; i++) {
		mizuhasu[i] = (mizuhasu[i - 1] + A[i - 1]) % M;
	}
	qsort(mizuhasu, N + 1, sizeof(*mizuhasu), inorinn);
	for (i = 1; i <= N + 1; i++) {
		if (i > N || mizuhasu[i] != mizuhasu[parunyasu]) {
			int64_t sumipe = i - parunyasu;
			mikakosi += sumipe * (sumipe - 1) / 2;
			parunyasu = i;
		}
	}
	printf("%" PRId64 "\n", mikakosi);
	return 0;
}


Measured memory_bytes: 2556
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;

const ll INF = LONG_LONG_MAX;

int main() {
  ll a, b, c;
  cin >> a >> b >> c;
  if (a + b + c >= 22) puts("bust");
  else
    puts("win");

  return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#pragma warning(disable : 4996)
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<time.h>
#include<random>
#include<array>


using namespace std;

#define REP(i, n) for(int i = 0;i < n;++i)
#define REPR(i, n) for(int i = n-1;i >= 0;--i)
#define FOR(i, m, n) for(int i = m;i < n;++i)
#define FORR(i, m, n) for(int i = m-1;i >= n;--i)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end())
#define ll long long
#define print(x) cout<<(x)<<'\n'
#define pe(x) cout<<(x)<<" "
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define lb(v,n) lower_bound(v.begin(), v.end(), (n))
#define ub(v,n) upper_bound(v.begin(), v.end(), (n))
#define int long long
//#define double long double
#define all(x) (x).begin(), (x).end()
#define print_space(v) REP(i,v.size())cout << v[i] << ((i == v.size() - 1) ? "\n" : " ")
template<typename T1, typename T2> inline void chmin(T1 & a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
typedef pair<int, int>P;
typedef array<int, 3> arr3;
std::random_device rd;
std::mt19937 mt(rd());
constexpr ll MOD = 1e9+7; constexpr int MAX = 2000020;
const double pi = acos(-1); constexpr double EPS = 1e-8;
constexpr ll INF = 1e18;
void y(bool cond) {
	if (cond)print("Yes");
	else print("No");
}

double T[101], V[101];
double v1[2000020];//v[i]=[i/2-0.5,i/2)
double v2[2000020];
double max_v[1000010];
void solve() {
	int N; cin >> N;
	REP(i, N)cin >> T[i];
	REP(i, N)cin >> V[i];
	int now = 0;
	int idx = 0;
	REP(i, N) {
		REP(_, T[i]) {
			max_v[idx] = V[i];
			idx++;
		}
	}
	double now_v=0;
	REP(i, idx) {
		if (now_v <= max_v[i] - 1) {
			now_v += 0.5;
			v1[i*2 + 1] = now_v;
			now_v += 0.5;
			v1[i*2 + 2] += now_v;
		}
		else if (now_v <= max_v[i] - 0.5) {
			now_v += 0.5;
			v1[i * 2 + 1] = now_v;
			v1[i * 2 + 2] = now_v;
		}
		else {
			now_v = max_v[i];
			v1[i * 2 + 1] = now_v;
			v1[i * 2 + 2] = now_v;
		}
	}
	now_v = 0;
	REPR(i, idx) {
		if (now_v <= max_v[i] - 1) {
			now_v += 0.5;
			v2[i * 2 + 1] = now_v;
			now_v += 0.5;
			v2[i * 2] = now_v;
		}
		else if (now_v <= max_v[i] - 0.5) {
			now_v += 0.5;
			v2[i * 2 + 1] = now_v;
			v2[i * 2] = now_v;
		}
		else{
			now_v = max_v[i];
			v2[i * 2 + 1] = now_v;
			v2[i * 2] = now_v;
		}
	}
	double ans = 0;
	now_v = 0;
	REP(i, idx * 2) {
		double nxt = min(v1[i + 1], v2[i + 1]);
		ans += (now_v + nxt)*0.25;
		now_v = nxt;
	}
	cout << setprecision(20) << ans << endl;
}


signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	//int q; cin >> q;
	//while (q--)
	solve();
}



Measured memory_bytes: 4480
#include <cstdio>
#include <cmath>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>

#ifdef _DEBUG
#define DMP(x) cerr << #x << ": " << x << "\n"
#else
#define DMP(x) ((void)0)
#endif

const int MOD = 1000000007, INF = 1111111111; 
using namespace std;
using lint = long long;

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int a, b;
	cin >> a >> b;

	cout << (b - a)*(b - a - 1) / 2 - a << "\n";

	return 0;
}

Measured memory_bytes: 256
import bisect

A, B, Q = map(int, input().split())

shrines = []
for i in range(A):
    shrines.append(int(input()))

temples = []
for i in range(B):
    temples.append(int(input()))

shortest_s_to_t = {}
for shrine in shrines:
    index = bisect.bisect_left(temples, shrine)
    if index == 0:
        distance = abs(shrine - temples[index])
        shortest_s_to_t[shrine] = distance
    elif index == B:
        distance = abs(shrine - temples[index - 1])
        shortest_s_to_t[shrine] = distance
    else:
        distance_left = abs(shrine - temples[index - 1])
        distance_right = abs(shrine - temples[index])
        shortest_s_to_t[shrine] = min(distance_left, distance_right)

shortest_t_to_s = {}
for temple in temples:
    index = bisect.bisect_left(shrines, temple)
    if index == 0:
        distance = abs(temple - shrines[index])
        shortest_t_to_s[temple] = distance
    elif index == A:
        distance = abs(temple - shrines[index - 1])
        shortest_t_to_s[temple] = distance
    else:
        distance_left = abs(temple - shrines[index - 1])
        distance_right = abs(temple - shrines[index])
        shortest_t_to_s[temple] = min(distance_left, distance_right)

for i in range(Q):
    x = int(input())

    # shrine to temple
    index = bisect.bisect_left(shrines, x)
    ans = 10**11
    if index > 0:
        left_shrine = shrines[index - 1]
        candidate = abs(x - left_shrine) + shortest_s_to_t[left_shrine]
        ans = min(ans, candidate)
    if index < A:
        right_shrine = shrines[index]
        candidate = abs(x - right_shrine) + shortest_s_to_t[right_shrine]
        ans = min(ans, candidate)

    # temple to shrine
    index = bisect.bisect_left(temples, x)
    if index > 0:
        left_temple = temples[index - 1]
        candidate = abs(x - left_temple) + shortest_t_to_s[left_temple]
        ans = min(ans, candidate)
    if index < B:
        right_temple = temples[index]
        candidate = abs(x - right_temple) + shortest_t_to_s[right_temple]
        ans = min(ans, candidate)

    print(ans)

Measured memory_bytes: 35360
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;

class Program
{
    public static void Main()
    {
        int N = int.Parse(Console.ReadLine());
        List<Tuple<int, int>> K = new List<Tuple<int, int>>() { Capacity = N};
        for(int i = 0; i < N; i++)
        {
            var s = Console.ReadLine().Split(' ');
            int A = int.Parse(s[0]);
            int B = int.Parse(s[1]);
            K.Add(new Tuple<int, int>(B, A));
        }

        K.Sort((x, y) =>
        {
            if (x.Item1 < y.Item1)
                return 1;
            else if (x.Item1 > y.Item1)
                return -1;
            else
            {
                if (x.Item2 < y.Item2)
                    return 1;
                else if (x.Item2 > y.Item2)
                    return -1;
                else
                    return 0;
            }
        });
        
        int j, CT = K[0].Item1;
        for(j = 0; j < N; j++)
        {
            CT = Math.Min(CT, K[j].Item1) - K[j].Item2;
        }
        if (j == N && CT >= 0)
            Console.WriteLine("Yes");
        else
            Console.WriteLine("No");
    }
}

Measured memory_bytes: 25384
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <tuple>
using namespace std;


int main() {
    int x,y,z;
    cin>>x>>y>>z;
    if (x+y+z>=22) {
        cout << "bust" << endl;
    } else {
        cout << "win" << endl;

    }
}


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

#define dv(i) for (int c=0; c<(int)(i).size(); c++) cout<<(i)[c]<<(c==(int)(i).size()-1?"\n":" ")
#define dm(i) for (auto f: i) cout<<f.first<<" "<<f.second<<"\n"
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define alp(i) (i),(i)+sizeof((i))/sizeof((i)[0])

const int MOD = 1000000007;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    int N; string S; cin>>N>>S; int ret=INT_MIN;
    FOR(c,1,N) {
        string a=S.substr(0,c),b=S.substr(c,sz(S)-c);// cout<<a<<" "<<b<<" ";
        set<char> sa(all(a)),sb(all(b));
        vector<char> temp;
        set_intersection(all(sa),all(sb),back_inserter(temp));
        ret=max(ret,sz(temp));
    }
    cout<<ret<<'\n';
    return 0;
}

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

int main() {
  int n,m,x=0;
  cin>>n;
  vector<string> s(n);
  for(int i=0;i<n;i++){
    string c;
    cin>>c;
    s[i]=c;
  }
  cin>>m;
  vector<string> t(m);
  for(int i=0;i<m;i++){
    string c;
    cin>>c;
    t[i]=c;
  }
  for(int i=0;i<n;i++){
    string name=s[i];
    int yen=0;
    for(int j=0;j<n;j++){
      if(s[j]==name){
        yen+=1;
      }
    }
    for(int k=0;k<m;k++){
      if(t[k]==name){
        yen-=1;
      }
    }
    if(yen>0 && yen>x){
      x=yen;
    }
  }
  cout<<x<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <limits.h>
#include <stdbool.h>

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

//qsort(str, n, sizeof(int), up_comp);
int up_comp(const void *a, const void *b){return *(int*)a - *(int*)b;}
int down_comp(const void *a, const void *b){return *(int*)b - *(int*)a;}
int int_sort( const void * a , const void * b ) {return strcmp(( char * )a , ( char * )b );}
int count_digit(int a){int i=0;while(a!=0){a=a/10;i++;}return i;}
int euclid( int a, int b ){int temp;if(a<b){temp=a;a=b;b=temp;}if(b<1)return -1;if(a%b==0) return b;return euclid(b,a%b);}

int main(void){
 
    int a, b;
    
    scanf("%d%d", &a, &b);
    
    if (a!=2&&b!=2) {
        printf("Yes");
    } else {
        printf("No");
    }
    
    return 0;
}



Measured memory_bytes: 1712
import sys
sys.setrecursionlimit(1000000000)
import math
from math import gcd
def lcm(a, b): return a * b // gcd(a, b)
from itertools import count, permutations, chain, product
from functools import lru_cache
from collections import deque, defaultdict
from pprint import pprint
ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
INF = float('inf')
N1097 = 10**9 + 7

def meg(f, ok, ng):
    while abs(ok-ng)>1:
        mid = (ok+ng)//2
        if f(mid):
            ok=mid
        else:
            ng=mid
    return ok

def get_inv(n, modp):
    return pow(n, modp-2, modp)

def factorials_list(n, modp):    # 10**6
    fs = [1]
    for i in range(1, n+1):
        fs.append(fs[-1] * i % modp)
    return fs

def invs_list(n, fs, modp):     # 10**6
    invs = [get_inv(fs[-1], modp)]
    for i in range(n, 1-1, -1):
        invs.append(invs[-1] * i % modp)
    invs.reverse()
    return invs

def comb(n, k, modp):
    num = 1
    for i in range(n, n-k, -1):
        num = num * i % modp
    den = 1
    for i in range(2, k+1):
        den = den * i % modp
    return num * get_inv(den, modp) % modp

def comb_from_list(n, k, modp, fs, invs):
    return fs[n] * invs[n-k] * invs[k] % modp

#

class UnionFindEx:
    def __init__(self, size):
        #正なら根の番号、負ならグループサイズ
        self.roots = [-1] * size
    def getRootID(self, i):
        r = self.roots[i]
        if r < 0:   #負なら根
            return i
        else:
            r = self.getRootID(r)
            self.roots[i] = r
            return r
    def getGroupSize(self, i):
        return -self.roots[self.getRootID(i)]
    def connect(self, i, j):
        r1, r2 = self.getRootID(i), self.getRootID(j)
        if r1 == r2:
            return False
        if self.getGroupSize(r1) < self.getGroupSize(r2):
            r1, r2 = r2, r1
        self.roots[r1] += self.roots[r2]    #サイズ更新
        self.roots[r2] = r1
        return True

Yes = 'Yes'
No = 'No'



def main():
    K = ii()
    n = 7%K
    s = set()
    for i in range(1, K+10):
        if n == 0:
            print(i)
            return
        n = (10*n + 7) % K
        if n in s:
            print(-1)
            return
        s.add(n)






main()



Measured memory_bytes: 78664
#include <iostream>
#include<cstdlib>
#include<queue>
#include<set>
#include<vector>
#include<string>
#include<algorithm>
#include<stack>
#include<map>
#include<deque>
#include<cstdio>
using namespace std;
#define rep(i,a) for(int i=0;i<a;i++)
#define mp make_pair
#define pb push_back
//#define ll __int64
#define ll long long
#define P pair<ll,ll>

vector<P>G[1100];
int n,m;
ll a,b,c;
ll dist[1100];
bool heiro[11000];
bool k[110000];
bool used[11000];
const ll INF=-20000000000000000;
const int M=1000;

bool tan(int now){
	queue<int>bfs;
	bfs.push(now);

	while(!bfs.empty()){
		int next=bfs.front();
		bfs.pop();
		if(used[next])continue;
		used[next]=1;
		if(next==n-1)return 1;
		rep(i,G[next].size()){
			bfs.push(G[next][i].first);
		}
	}
	return 0;
}

bool che(int now){
	queue<int>bfs;

	bfs.push(now);
	
	while(!bfs.empty()){
		int next=bfs.front();
		bfs.pop();
		if(used[next])continue;
		used[next]=1;
		if(heiro[next])k[next]=1;
		rep(i,G[next].size()){
			bfs.push(G[next][i].first);
		}
	}
	
	bool ok=0;
	rep(i,M)used[i]=0;
	rep(i,M){
		if(k[i]&&used[i]==0){
			if(tan(i))ok=1;//iからnに行ける
		}
	}
	if(ok)return 0;
	return 1;
}
int main(){
	//O(VE)辺に着目して距離を更新
	cin>>n>>m;
	rep(i,n)dist[i]=INF;

	rep(i,m){
		cin>>a>>b>>c;
		a--;
		b--;
		G[a].push_back(mp(b,c));
		//G[b].push_back(mp(a,c));
	}	
	dist[0]=0;

	rep(i,3*n){
			rep(j,n){
			rep(k,G[j].size()){
				int from=j,to=G[j][k].first,cost=G[j][k].second;
				if(dist[to]<dist[from]+cost){
					dist[to]=dist[from]+cost;
					if(i>n)heiro[to]=heiro[from]=1;
				}
			}
			}
		if(i>=3*n-1){
			break;
		}
	}

	if(che(0))
	cout<<dist[n-1]<<endl;
	else cout<<"inf"<<endl;
	return 0;
}


Measured memory_bytes: 384