akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
struct edge
{
	int u, v, w;
}e[maxn];
bool cmp(const edge & a, const edge & b) { return a.w > b.w;} 
typedef long long ll;
ll ans;
int n, h, w, tot;
int fa[maxn];
bool vis[maxn];
int getfa(int x) { return x == fa[x] ? x : fa[x] = getfa(fa[x]);}
int main()
{
	scanf("%d%d%d", &n, &h, &w);
	tot = h + w;
	for(int i = 1; i <= n; ++i)
	{
		scanf("%d%d%d", &e[i].u, &e[i].v, &e[i].w);
		e[i].v += h;
	}
	sort(e + 1, e + n + 1, cmp);
	for(int i = 1; i <= tot; ++i) fa[i] = i;
	for(int i = 1; i <= n; ++i)
	{
		int fu = getfa(e[i].u);
		int fv = getfa(e[i].v);
		if(vis[fu] && vis[fv]) continue;
		if(vis[fv]) swap(fu, fv);
		if(fu == fv)
		{
			if(!vis[fu])
			{
				vis[fu] = 1;
				ans += e[i].w;
			}
		}
		else
		{
			fa[fv] = fu;
			ans += e[i].w;
		}
	}
	printf("%lld\n", ans);
	return 0;
}
	

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

ll get(ll n)
{
    ll s[30];
    s[0]=0;
    for(ll i=1;i<30;i++) s[i]=s[i-1]+i;
    vector<ll> v;
    for(ll i=2;i*i<=n;i++)
    {
        if(n%i==0)
        {
            ll cnt=0;
            while(n%i==0) cnt++ , n=n/i;
            v.push_back(cnt);
        }
    }
    if(n!=1) v.push_back(1);
    ll ans=0;
    for(ll i=0;i<v.size();i++)
    {
        int id = lower_bound(s,s+30,v[i]) - s;
      //  cout << v[i] << " ";
        if(s[id]==v[i]) ans+=id;
        else 
        {
            id--;
            if(id>0) ans+=id;
        }
    }
    return ans;
}

int main() {

    ll n;
    cin >> n;
    cout << get(n);
    return 0;
}


Measured memory_bytes: 3624
#ifndef __cplusplus
    cat << EOF
#endif
#include <bits/stdc++.h>
using namespace std;

#define rep(...) overload_rep(__VA_ARGS__, rep_1, rep_0)(__VA_ARGS__)
#define rep_0(i, end) for(int i = 0; i < (end); ++i)
#define rep_1(i, fr, ba) for(int i = (fr); i <= (ba); ++i)
#define overload_rep(arg0, arg1, arg2, name, ...) name
#define all(box) box.begin(), box.end()

template <class T, class U> inline bool chmax(T& lhs, const U& rhs) { if(lhs < rhs) { lhs = rhs; return 1; } return 0; }
template <class T, class U> inline bool chmin(T& lhs, const U& rhs) { if(lhs > rhs) { lhs = rhs; return 1; } return 0; }

int main() {

    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];

    int ans = 0;
    rep(i, n - 1) {
        if(a[i] < a[i + 1]) ans++;
    }
    cout << ans << '\n';

}



Measured memory_bytes: 3108
x,y,a,b,c = map(int,input().split())

p = list(map(int,input().split()))
q = list(map(int,input().split()))
r = list(map(int,input().split()))

p.sort()
q.sort()
r.sort(reverse=True)

p = p[a-x:]
q = q[b-y:]

p.extend(q)
p.sort()

ans = sum(p)
count = 0
for i in range(c):
	if p[i] < r[i]:
		ans += r[i] - p[i]
	else:
		break
print(ans)


Measured memory_bytes: 23328
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <deque>
 
using namespace std;
 
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define pb push_back
#define mp make_pair
#define all(r) r.begin(),r.end()
#define fi first
#define se second
#define println(X) cout<<X<<endl;
#define DBG(X) cout<<#X<<" : "<<X<<endl;
 
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pii> pp;

const int INF = 1e9;

double EPS = 1e-10;


int c, n, m, s, g;



const int MAX_V = 510;

int d[MAX_V][MAX_V][15];
int connect[MAX_V][MAX_V];
int V;
 
void warshall_floyd_init(){
	for(int i = 0; i < V; i++){
		for(int j = 0; j < V; j++){
			for(int k = 0; k <= c; k++){
				if(i == j) d[i][i][k] = 0;
				else d[i][j][k] = INF;
			}
			connect[i][j] = 0;
		}
	}
}

void warshall_floyd() {
				for(int l = c; l>=0; l--){
				//for(int l = 0; l <= c; l++){
	for (int k = 0; k < V; k++) {
		for (int i = 0; i < V; i++) {
			for (int j = 0; j < V; j++) {
					d[i][j][l] = min({d[i][j][l], d[i][k][l] + d[k][j][c], d[i][k][c] + d[k][j][l]});
					if(l>0 && connect[k][j] > 0){
						d[i][j][l-1]=min(d[i][j][l-1], d[i][k][l]+connect[k][j]/2);
					}
					if(l>0 && connect[i][k] > 0){
						d[i][j][l-1]=min(d[i][j][l-1],connect[i][k]/2 + d[k][j][l]);						
					}
				}
			}
		}
	}
}
int main(){
	int a, b, f;
	int ans;
	while(cin>>c>>n>>m>>s>>g){
		if(c == 0 && n == 0 && m == 0 && s == 0 && g == 0) break;
		s--; g--;
		V = n;
		warshall_floyd_init();
		//cout<<d[0][2][0]<<endl;
		for(int i = 0; i < m; i++){
			cin>>a>>b>>f;
			//f/=10;
			a--; b--;
			//d[a][b][c] = d[b][a][c] = f;
			d[a][b][c] = min(d[a][b][c], f);
			d[b][a][c] = min(d[b][a][c], f);
			connect[a][b] = connect[b][a] = f;	
		}
		warshall_floyd();
		int ans = INF;
		for(int i = 0; i <= c; i++) ans = min(ans, d[s][g][i]);
		cout<<ans<<endl;
		//cout<<" "<<d[4][5][2]<<endl;
	}
	
}

Measured memory_bytes: 4240
#pragma GCC optimize "03"
#include "bits/stdc++.h"
using namespace std;
 
#define ll long long int
#define ld long double
#define pi pair<int, int>
#define pb push_back
#define fi first
#define se second
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif
 
const int N = 3e2 + 5;
const int mod = 1e9 + 7;
const int inf = 1e9 + 9;

int n;
ld dp[N][N][N];

ld rec(int c1, int c2, int c3){
	if(dp[c1][c2][c3] != -1)
		return dp[c1][c2][c3];
	int t = c1+c2+c3;
	if(t == 0)	
		return 0;
	dp[c1][c2][c3] = n;
	if(c1 != 0)
		dp[c1][c2][c3] += (rec(c1-1, c2, c3))*c1;
	if(c2 != 0)
		dp[c1][c2][c3] += (rec(c1+1, c2-1, c3))*c2;
	if(c3 != 0)
		dp[c1][c2][c3] += (rec(c1, c2+1, c3-1))*c3;
	dp[c1][c2][c3] /= t;
	return dp[c1][c2][c3];
} 
 
signed main() {
	IOS;
	#ifdef LOCAL
		freopen("input.txt","r", stdin);
		freopen("output.txt","w",stdout);
	#endif
	int a[3] = {0};
	cin >> n;
	for(int i = 1; i <= n; i++){
		int p;	cin >> p;
		a[p-1]++;
	}	
	for(int i = 0; i < N; i++)
		for(int j = 0; j < N; j++)
			for(int k = 0; k < N; k++)
				dp[i][j][k] = -1;
	cout << setprecision(10) << fixed << rec(a[0], a[1], a[2]);
	return 0;
}

Measured memory_bytes: 443648
#include <stdio.h>
#include <string.h>
#define MIN(x, y) (((x) > (y)) ? (y) : (x))
#define ABS(x) ((x) >= 0 ? (x) : (-(x)))

char s[200001];
int t[2020] = {1};
int main()
{
  scanf("%s", s);
  long long sum = 0;
  int n = strlen(s);
  int rem = 0;
  int y = 1;
  for (int i = n - 1; i >= 0; i--) {
    rem = (rem + (s[i] - '0') * y) % 2019;
    t[rem]++;
    y = y * 10 % 2019;
  }
  for (int i = 0; i < 2019; i++) {
    sum += (long long) t[i] * (t[i] - 1);
  }
  printf("%lld", sum / 2);
  return 0;
}

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

#define MOD ((int)1e9+7)
typedef long long ll;

vector<int> adj[(int)1e5];
ll black[(int)1e5];
ll white[(int)1e5];

void bfs(int idx, int from) {
    // base case:
    white[idx] = black[idx] = 1;
    
    // recursive step:
    vector<int>& adjs = adj[idx];
    for (int i=0; i<adjs.size(); i++) {
        if (adjs[i] != from)
            bfs(adjs[i], idx);
    }

    for (int i=0; i<adjs.size(); i++) {
        if (adjs[i] != from) {
            white[idx] *= white[adjs[i]] + black[adjs[i]];
            white[idx] %= MOD;
            black[idx] *= white[adjs[i]];
            black[idx] %= MOD;
        }
    }

    // printf("white[%d] black[%d] = %lld %lld\n", idx, idx, white[idx], black[idx]);
}

int main() {
    int N; cin >> N;
    for (int i=0; i<N-1; i++) {
        int x,y;
        scanf("%d %d", &x, &y);

        adj[x-1].push_back(y-1);
        adj[y-1].push_back(x-1);
    }

    // calculate
    bfs(0, -1);

    // print answer
    cout << (black[0] + white[0]) %MOD << endl;

    return 0;
}

Measured memory_bytes: 14208
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))

sum = 0
for i in range(n-1):
    sum += b[i]
    if a[i+1]==a[i]+1:
        sum += c[a[i]-1]
sum += b[n-1]
print(sum)

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

using namespace std;
typedef long long ll;

int main() {
    string alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    string S;
    int N;
    cin >> N >> S;
    int len  = (int)(S.length());
    for(int i = 0; i < len; i++) {
        for(int j = 0; j < 26; j++) {
            if(S[i] == alpha[j]) {
                S[i] = alpha[(j+N)%26];
                break;
            }
        }
    }
    cout << S << endl;
}

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

int main(){
	int x,y,w,h,r;
	cin >> w >> h >> x >> y >> r;
	
	if((x<=w-r)&&(x>=r)&&(y<=h-r)&&(y>=r )) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}



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

int main() {
  int a, b;
  cin >> a >> b;
  int ans = 0;
  if (a-1 > b) cout << a+a-1 << endl;
  else if (b-1 > a) cout << b+b-1 << endl;
  else cout << a+b << endl;
return 0;
}

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

int main() {

	ll x; cin >> x;
	ll quo = x / 11;
	ll mod = x % 11;
	ll ans = 2 * quo;
	if (1 <= mod && mod <= 6) ans++;
	else if (6 < mod) ans += 2;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3640
#include<stdio.h>
#include<math.h>

int main(void){
	int n,m,x;
	scanf("%d %d %d",&n,&m,&x);
	
	int c[n];
	int a[n][m];
	for(int i=0;i<n;i++){
		scanf("%d",&c[i]);
		for(int j=0;j<m;j++){
			scanf("%d",&a[i][j]);
		}
	}
	
	
	int keisan[m+1];
	int min_hairetu;
	int min_daikin=2147483647;
	
	for(int i=1;i<pow(2,n);i++){
		min_hairetu=2147483647;
		for(int j=0;j<m;j++){
			keisan[j]=0;
			for(int k=0;k<n;k++){
				if(i&(1<<k)){
					keisan[j]+=a[k][j];
				}
			}
			min_hairetu<keisan[j]?1:(min_hairetu=keisan[j]);
		}
		
		if(min_hairetu>=x){
			keisan[m]=0;
			for(int k=0;k<n;k++){
				if(i&(1<<k)){
					keisan[m]+=c[k];
				}
			}
			min_daikin<keisan[m]?1:(min_daikin=keisan[m]);
		}
	}
	
	if(min_daikin!=2147483647){
		printf("%d",min_daikin);
	}else{
		printf("-1");
	}
	
}

Measured memory_bytes: 2484
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
int main() {
  int r;
  cin >> r;
  const double p = 3.14159265358979323846;
  cout <<2*r*p<<endl;
}


Measured memory_bytes: 3764
import bisect
N = int(input())
S = list(input())
R = []
G = []
B = []
for i in range(N):
    if S[i] == "R":
        R.append(i)
    elif S[i] == "G":
        G.append(i)
    else:
        B.append(i)

r = len(R)
g = len(G)
b = len(B)
ans = r*g*b

for i in R:
    for j in G:
        M = max(i,j)
        m = min(i,j)
        d = M - m
        x = (M+m)/2
        y = M + d
        z = m - d
        if bisect.bisect_left(B,x) != bisect.bisect_right(B,x):
            ans -= 1
        if bisect.bisect_left(B,y) != bisect.bisect_right(B,y):
            ans -= 1
        if bisect.bisect_left(B,z) != bisect.bisect_right(B,z):
            ans -= 1
print(ans)

Measured memory_bytes: 76368
import bisect

N = int(input())
L = [int(_) for _ in input().split()]
L.sort()

ans = 0
for i in range(N - 2):
    for j in range(i + 1, N - 1):
        r = L[i] + L[j]
        # 同じ長さでも違う棒はOK
        ri = bisect.bisect_left(L, r)
        ans += ri - j - 1

print(ans)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#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++)
ll PowMod(ll N, ll P, ll M) {   // Calc N^P mod M ()
    if(P == 0) return 1;
    if(P%2 == 0) {
        ll t = PowMod(N, P/2, M);
        return (t%M)*(t%M);
    }
    return N*PowMod(N, P-1, M)%M;
} 


int main() {
    ll A[3][3];
    REP(i, 3) {
        REP(j, 3) {
            cin >> A[i][j]; 
        }
    }
    ll N;
    cin >> N;
    ll b;
    REP(k, N) {
        cin >> b;
        REP(i, 3) {
            REP(j, 3) {
                if(b == A[i][j]) {
                    A[i][j] = 0;
                } 
            }
        }
    }

    string ret = "No";
    if(  (A[0][0] == 0)&&(A[0][1] == 0)&&(A[0][2] == 0)
       ||(A[1][0] == 0)&&(A[1][1] == 0)&&(A[1][2] == 0)
       ||(A[2][0] == 0)&&(A[2][1] == 0)&&(A[2][2] == 0)
       ||(A[0][0] == 0)&&(A[1][0] == 0)&&(A[2][0] == 0)
       ||(A[0][1] == 0)&&(A[1][1] == 0)&&(A[2][1] == 0)
       ||(A[0][2] == 0)&&(A[1][2] == 0)&&(A[2][2] == 0)
       ||(A[0][0] == 0)&&(A[1][1] == 0)&&(A[2][2] == 0)
       ||(A[0][2] == 0)&&(A[1][1] == 0)&&(A[2][0] == 0)
    ) {
        ret = "Yes";
    }

    cout << ret << endl;
}

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

/*                    ॐ Shree ॐ                     */
/* ॐ ॐ ॐ
ॐ भूर् भुवः स्वः
तत् सवितुर्वरेण्यं
भर्गो देवस्य धीमहि
धियो यो नः प्रचोदयात्
*/
using namespace std;
typedef long long int ll;
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#else
// online submission
#endif
	int a,b,c,k;
	cin>>a>>b>>c>>k;
	int sum=0;
	sum+=min(k,a);
	k-=sum;
	k-=min(b,k);
	sum-=min(k,c);
	cout<<sum;
}

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

int main() {
  int N , K , X , Y;
  cin >> N;
  cin >> K;
  cin >> X;
  cin >> Y;
  
  if (N>K){
  cout << (K * X)+((N-K) * Y) << endl;
  }
  else{
    cout << N*X << endl;
  }
}


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

ll f(ll n){
    if(n == 0) return 1;
    ll ret = f(n / 2) * f(n / 2);
    if(n % 2 == 1) ret *= 2;
    return ret;
}

int main(){
    ll h;
    cin >> h;
    ll c = 0;
    while(h != 0){
        h /= 2;
        c++;
    }
    cout << f(c) - 1 << endl;

}

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

int main()
{
	string str;
	while(cin >> str && str != "0")
	{
		int sum = 0;
		for(int i = 0; i < str.length(); ++i)
		{
			sum += str[i] - '0';
		}
		cout << sum << endl;
	}

    return 0;
}



Measured memory_bytes: 3220
////////////////////////////////////////////////////////////////////
// This source code is for Visual Studio
////////////////////////////////////////////////////////////////////
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <sstream>
#include <iterator>
#include <stack>
#include <functional>
#include <iomanip>
#include <string>
#include <cstring>
#include <deque>
#include <math.h>

#define	numberof(a)	(sizeof(a) / sizeof(a[0]))
#define	INF		UINT64_MAX
#define Rep(i,n) for(int i = 0; i < (n); ++i )

using namespace std;

typedef vector< vector<int> > MAT;
typedef pair<int, int> PINT;
typedef long long ll;
typedef uint32_t u32;
typedef uint64_t u64;
typedef int32_t s32;
typedef int64_t s64;

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

int main()
{
	ll N = 0;
	ll ret = 0;
	ll L_0 = 2;
	ll L_1 = 1;

	cin >> N;

	for (int i = 2; i <= N; ++i) {
		ll tmp = L_1;
		L_1 = L_0 + L_1;
		L_0 = tmp;
	}
	ret = L_1;

	cout << ret << endl;

	return 0;
}





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

int N, K;
vector<int> adj[2000];
int dist[2000];
int edge[2000][2];

void set_dist(int x){
    for(int i = 0; i < N; i++){
        dist[i] = 10000;
    }
    dist[x] = 0;
    stack<int> next;
    next.push(x);
    while(!next.empty()){
        int now = next.top(); next.pop();
        for(int i = 0; i < adj[now].size(); i++){
            if(dist[adj[now][i]] > dist[now]){
                next.push(adj[now][i]);
                dist[adj[now][i]] = dist[now] + 1;
            }
        }
    }
}


int calc_farthest(int x){
    set_dist(x);
    int ret = 0;
    for(int i = 0; i < N; i++){
        if(dist[i] > dist[ret]){
            ret = i;
        }
    }
    return ret;
}

int calc_dist(int x, int y){
    set_dist(x);
    return dist[y];
}



int calc_diam(){
    int far_0 = calc_farthest(0);
    int far_x = calc_farthest(far_0);
    return calc_dist(far_0, far_x);
}

int main(){
    cin >> N >> K;
    for(int i = 0; i < N - 1; i++){
        int A, B;
        cin >> A >> B;
        A--;
        B--;
        adj[A].push_back(B);
        adj[B].push_back(A);
        edge[i][0] = A;
        edge[i][1] = B;
    }


    long long ret = 1000000;
    if(K % 2 == 0){
        for(int c = 0; c < N; c++){
            long long tmp = 0;
            set_dist(c);
            for(int i = 0; i < N; i++){
                if(dist[i] > K/2){
                    tmp++;
                }
            }
            ret = min(ret, tmp);
        }
    }else{
        for(int e = 0; e < N - 1; e++){
            long long tmp = 0;
            bool not_removed[2000] = {};
            set_dist(edge[e][0]);
            for(int i = 0; i < N; i++){
                if(dist[i] <= K / 2){
                    not_removed[i] = true;
                }
            }
            set_dist(edge[e][1]);
            for(int i = 0; i < N; i++){
                if(dist[i] <= K / 2){
                    not_removed[i] = true;
                }
            }
            for(int i = 0; i < N; i++){
                if(!not_removed[i]){
                    tmp++;
                }
            }
            ret = min(tmp, ret);
        }
    }

    cout << ret << endl;

    
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <deque>
#include <set>
#include <iomanip>
#include <utility>
typedef long long ll;
typedef long double ld;
using namespace std;

int main() {
	int N;
	cin >> N;
	ll A, B, xsum=0;
	cin >> A >> B;
	for(int i=2; i<N; ++i){
		ll E;
		cin >> E;
		xsum ^= E;
	}
	if((((A+B)&1) != (xsum&1)) || A+B<xsum){
		cout << -1 << endl;
		return 0;
	}
	ll f=(A+B-xsum)>>1;
	if((f&xsum)!=0 || f>A){
		cout << -1 << endl;
		return 0;
	}
	bool flag=false;
	ll now=0;
	for(int d=40; d>=0; --d){
		if(1&(xsum>>d)){
			if(flag || (1&((A-f)>>d))) now += ((ll) 1<<d);
		}
		if((1&((A-f)>>d)) && !(1&(now>>d))) flag=true;
	}
	now += f;
	if(now==0) cout << -1 << endl;
	else cout << A-now << endl;
	return 0;
}

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

int main()
{
  int n, sum ;
  cin >>n ;
  sum = 0 ;
  
  rep(i, n+1){
    sum += i ;
  }
  
  cout <<sum <<endl ;
  
  
    return 0 ;
}

Measured memory_bytes: 256
N = int(input())
L = list(map(int,input().split()))
L.sort()
count = 0

for i in range(N):
  for j in range(i+1,N):
    for k in range(j+1,N):
      if (L[i] == L[j]) or (L[j] == L[k]) or (L[k] == L[i]):
        continue
      else:
        if (L[i]+L[j]>L[k]) and (L[j]+L[k]>L[i]) and (L[k]+L[i]>L[j]):
          count += 1
         
print(count)

Measured memory_bytes: 9212
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define FOR(i,l,r) for(i=l;i<r;i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define P pair<ll,ll>
#define F first
#define S second
signed main(){
  ll N;cin>>N;string S;
  if(N==0)S="0";
  while(abs(N)>0){
    if(N%2==0)S="0"+S;
    else{S="1"+S;N--;}
    N/=-2;
  }
  cout<<S<<endl;
  return 0;
}

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

using namespace std;

int main (void) {
      string s;
      int cnt = 0;
      int sel = 0;
      int count = 0;
      int flag = 0;

      cin >> s;

      sel = s.size();

      if (s[0] == 'A'){
            for (cnt = 2; cnt < sel - 1; cnt++){
                  if (s[cnt] == 'C'){
                        count = count + 1;
                  }
            }
            if (count == 1){
                  count = 0;
                  for (cnt = 0; cnt < sel; cnt++){
                        if (islower(s[cnt])){
                              count = count + 1;
                        }
                  }
                  if (count == sel - 2){
                        cout << "AC" << "\n";
                        flag = 1;
                  }
            }
      }

      if (flag == 0){
            cout << "WA" << "\n";
      }
      return 0;
}


Measured memory_bytes: 256
n, k, q = list(map(int, input().split()))
points = [k - q for i in range(n)]
for i in range(q):
    index = int(input()) - 1
    points[index] += 1
for i in range(n):
    if points[i] <= 0:
        ans = "No"
    else:
        ans = "Yes"
    print(ans)


Measured memory_bytes: 7948
import java.util.*;

public class Main{

    int n,m,l;
    int[][] dist,assa;

    void solve(){
        Scanner sc = new Scanner(System.in);

        while(true){
            n = sc.nextInt();
            m = sc.nextInt();
            l = sc.nextInt();
            if(n==0 && m==0 && l==0) break;

            dist = new int[n][n];
            assa = new int[n][n];
            for(int i=0; i<n; i++) Arrays.fill(dist[i],-1);
            for(int i=0; i<m; i++){
                int a = sc.nextInt()-1, b = sc.nextInt()-1;
                int d = sc.nextInt(), e = sc.nextInt();
                dist[a][b] = d; dist[b][a] = d;
                assa[a][b] = e; assa[b][a] = e;
            } 

            System.out.println(dijkstra());
        }
    }

    int dijkstra(){
        PriorityQueue<int[]> q = new PriorityQueue<int[]>(n,new Comparator<int[]>(){
                public int compare(int[] a, int[] b){
                    return a[2]-b[2];
                }
            });
        q.add(new int[]{0,l,0});
        boolean[][] v = new boolean[n][l+1];

        while(q.size()>0){
            int[] qp = q.poll();
            int pos = qp[0], money = qp[1], assas = qp[2];

            if(pos==n-1) return assas;
            if(v[pos][money]) continue;
            v[pos][money] = true;

            for(int i=0; i<n; i++){
                if(dist[pos][i]==-1) continue;
                if(dist[pos][i]<=money){
                    q.add(new int[]{i,money-dist[pos][i],assas});
                }
                q.add(new int[]{i,money,assas+assa[pos][i]});
            }
        }

        return -1;
    }


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

Measured memory_bytes: 14000
#include <bits/stdc++.h>
using namespace std;
#define FS ios_base::sync_with_stdio(0);
#define FOR(i,s,e) for(int i=s; i<e; ++i)
#define FFOR(i,s,e) for(int i=s; i<=e; ++i)
#define mem(o,s) memset(s,o,sizeof(s));
typedef long long ll;
#define MOD 1000000007
#define pi pair<int,int>
#define fi first
#define se second
#define pb push_back


int main(){
  FS
  int N,M;
  cin>>N>>M;
  if(N==M) cout<<"Yes\n";
  else cout<<"No\n";
}
    


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
constexpr ll LLINF = LLONG_MAX;


vector<vector<P> > g;

void add_edge(ll u, ll v, ll d){
    g[u].push_back({v,d});
    g[v].push_back({u,d});
}

ll dijkstra(int s, int t){
    vector<ll> dist(g.size(), LLINF/3);
    dist[s] = 0;
    priority_queue<P, vector<P>, greater<P> > que;
    que.push({dist[s], s});
    while(!que.empty()){
        P p = que.top();
        que.pop();
        int v = p.second;
        if(dist[v] < p.first) continue;
        for(auto e : g[v]){
            int u = e.first;
            ll d = e.second;
            if(dist[u] > dist[v] + d){
                dist[u] = dist[v] + d;
                que.push({dist[u], u});
            }
        }
    }
    return dist[t];
}

int main() {
    int n, m, s, t;
    cin >> n >> m >> s >> t;
    s--; t--;
    g.resize(n);
    for(int i=0;i<m;i++){
        ll a, b, c, d;
        cin >> a >> b >> c >> d;
        a--; b--; c--;
        add_edge(a, b, d);
        add_edge(b, c, d);
        add_edge(c, a, d);
    }
    cout << dijkstra(s,t) << endl;
    return 0;
}



Measured memory_bytes: 23668
N = int(input())
A = list(map(int,input().rstrip().split(" ")))
uru = [0,0]
uruold = [0,1000]
kau = [0,0]
kauold = [1000 // A[0],1000 % A[0]]
for i in range(N):
    if uruold[0] * A[i] + uruold[1] < kauold[0] * A[i] + kauold[1]:
        uru[0] = 0
        uru[1] = kau[0] * A[i] + kau[1]
    else:
        uru = uruold
    if uruold[1] // A[i] + uruold[0] > kauold[1] // A[i] + kauold[0] or (uruold[1] // A[i] + uruold[0] == kauold[1] // A[i] + kauold[0] and uruold[1] % A[i] > kauold[1] % A[i]):
        kau[0] = uruold[1] // A[i] + uruold[0]
        kau[1] = uruold[1] % A[i]
    else:
        kau = kauold
    uruold = uru
    kauold = kau
print(max(uru[1]+ uru[0] * A[N-1],kau[1] + kau[0] * A[N-1]))

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

typedef long long lglg;

vector<int> getZ(int n, char s[]) {
	vector<int> z(n);
	int x = 0, y = 0;
	for (int i = 1; i < n; i++) {
		z[i] = max(0,min(z[i-x],y-i+1));
		while (i+z[i] < n && s[z[i]] == s[i+z[i]]) {
			x = i; y = i+z[i]; z[i]++;
		}
	}
	return z;
}


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

	int n;
	string s;
	cin >> n >> s;
	int k = 0;
	int bad = n/2 + 1;
	for (int b=n/2; b>=1; b/=2) {
		while (k+b < bad) {
			bool success = false;
			for (int l=0; l<n; ++l) {
				int r = l+k+b;
				if (r+k+b > n) break;
				char x[n-l+1];
				for (int i=l; i<r; ++i) x[i-l] = s[i];
				x[k+b] = '#';
				for (int i=r; i<n; ++i) x[i-l+1] = s[i];
				for (int i : getZ(n-l+1, x)) {
					if (i == k+b) {
						success = true;
						break;
					}
				}
				if (success) break;
			}
			if (!success) {
				bad = k+b;
				break;
			}
			k += b;
		}
	}
	cout << k;
}

Measured memory_bytes: 384
import java.io.*;
import java.util.*;

public class Main {

    static MyScanner sc;
    private static PrintWriter out;
    static long M = 1000000007;

    public static void main(String[] s) throws Exception {
        StringBuilder stringBuilder = new StringBuilder();


        if (stringBuilder.length() == 0) {
            sc = new MyScanner(System.in);
        } else {
            sc = new MyScanner(new BufferedReader(new StringReader(stringBuilder.toString())));
        }


        out = new PrintWriter(new OutputStreamWriter(System.out));
        long t = System.currentTimeMillis();


        solve();
        out.flush();
    }

    private static void solve() {
        String k = sc.next();
        out.println(k.substring(0, k.length() - 8));
    }




    private static void solveT() {
        int t = sc.nextInt();
        while (t-- > 0) {
            solve();
        }
    }

    private static long gcd(long l, long l1) {
        if (l > l1) return gcd(l1, l);
        if (l == 0) return l1;
        return gcd(l1 % l, l);
    }

    private static long pow(long a, long b, long m) {
        if (b == 0) return 1;
        if (b == 1) return a;
        long pp = pow(a, b / 2, m);
        pp *= pp;
        pp %= m;
        return (pp * (b % 2 == 0 ? 1 : a)) % m;
    }


    static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        MyScanner(BufferedReader br) {
            this.br = br;
        }

        public MyScanner(InputStream in) {
            this(new BufferedReader(new InputStreamReader(in)));
        }

        void findToken() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
        }

        String next() {
            findToken();
            return st.nextToken();
        }

        int[] na(int n) {
            int[] k = new int[n];
            for (int i = 0; i < n; i++) {
                k[i] = sc.nextInt();
            }
            return k;
        }

        long[] nl(int n) {
            long[] k = new long[n];
            for (int i = 0; i < n; i++) {
                k[i] = sc.nextLong();
            }
            return k;
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }
    }


}


Measured memory_bytes: 21204
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 numOfPalindromic = 0;

      for(; A<=B; A++) if ((A/10000 == A%10) && ((A/1000)%10 == (A/10)%10)) numOfPalindromic++;
      System.out.println(numOfPalindromic);
    }
}

Measured memory_bytes: 23380
#define _CRT_SECURE_NO_WARNINGS 
#include <stdio.h>
#include <math.h>
#define Abs(x) ((x>=0)?x:-x)

int main()
{

	//FILE* fin = freopen("input.txt", "r", stdin);
	while (1){

		int sumt = 0, sumh = 0, n, m;
		int cardt[100], cardh[100];
		scanf("%d", &n);
		scanf("%d", &m);
		if (n == 0 && m == 0){
			break;
		}
		int i = 0;
		while (i < n){
			scanf("%d", &cardt[i]);
			sumt += cardt[i];
			i++;
		}
		i = 0;
		while (i < m){
			scanf("%d", &cardh[i]);
			sumh += cardh[i];
			i++;
		}

		if ((sumt + sumh) % 2 == 1){
			printf("%d\n", -1);
			continue;
		}

		int j, temp, diff, flag = 0, csum = 300, I = 0, J = 0;
		diff = sumt - sumh;
		//printf("sumt=%d sumh=%d diff=%d\n", sumt, sumh, diff);
		for (i = 0; i < n; i++){
			for (j = 0; j < m; j++){
				if (cardt[i] - cardh[j] == (diff / 2)){
					flag = 1;
					if ((cardt[i] + cardh[j]) < csum){
						I = i;
						J = j;
						csum = cardt[i] + cardh[j];
					}
				}
			}
		}
		if (flag == 0){
			printf("%d\n", -1);
			continue;
		}
		
		sumt = sumt - cardt[I] + cardh[J];
		sumh = sumt + cardt[I] - cardh[J];
		if (sumt == sumt){
			printf("%d %d\n", cardt[I], cardh[J]);
		}
	}
	return 0;
}

Measured memory_bytes: 600
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <vector>

static const int IINF = 1 << 30;
static const long long LINF = 1LL << 60;
static const long long MOD = 1.0e+9 + 7;

template <typename T> std::vector<T> vectors(std::size_t n, T val) {
  return std::vector<T>(n, val);
}

template <typename T, typename... Args>
auto vectors(std::size_t n, Args... args) {
  return std::vector<decltype(vectors<T>(args...))>(n, vectors<T>(args...));
}

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

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

template <class T> inline void chadd(T &a, const T &b) {
  a += b, a %= MOD;
  // TODO minus case
}

template <class T>
std::ostream &operator<<(std::ostream &s, const std::vector<T> &v) {
  if (v.empty())
    return s;
  s << *v.begin();
  for (auto iter = v.begin() + 1; iter != v.end(); ++iter)
    if (std::is_fundamental<T>::value)
      s << " " << *iter;
    else
      s << std::endl << *iter;
  return s;
}

int main() {
  // Input
  int N;
  std::cin >> N;

  std::vector<std::vector<int>> A(2, std::vector<int>(N, -1));
  for (int i = 0; i < 2; ++i)
    for (int j = 0; j < N; ++j)
      std::cin >> A[i][j];

  // Main
  int res = 0;
  for (int j = 0; j < N; ++j) {
    int tmp = 0;
    for (int k = 0; k <= j; ++k)
      tmp += A[0][k];
    for (int k = j; k < N; ++k)
      tmp += A[1][k];
    chmax(res, tmp);
  }

  // Output
  std::cout << res << std::endl;

  return 0;
}


Measured memory_bytes: 256
N = int(input())
A = []
B = []
for i in range(N):
    Ai, Bi = map(int, input().split())
    A.append(Ai)
    B.append(Bi)

A.sort()
B.sort()
if N % 2 == 0:
    ans = sum(B[N // 2 - 1:N // 2 + 1]) - sum(A[N // 2 - 1:N // 2 + 1]) + 1
else:
    ans = B[N // 2] - A[N // 2] + 1
print(ans)


Measured memory_bytes: 25396
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <limits.h>
#include <float.h>
#include <numeric>
#include <queue>
#include <typeinfo>
#include <memory>


using namespace std;

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

#define fs first
#define sc second

const ll mod = 1000000007;
ll fact[200200];
ll invfact[200200];

inline ll take_mod(ll a){
    return (a % mod + mod) % mod;
}

inline ll add(ll a, ll b){
    return take_mod(a+b);
}

inline ll sub(ll a, ll b){
    return take_mod(a-b);
}


inline ll mul(ll a, ll b){
    return take_mod(a * b);
}

inline ll pow(ll x, ll n){
    ll res = 1LL;
    while(n > 0){
        if(n & 1) res = mul(res, x);
        x = mul(x, x);
        n >>= 1;
    }
    return res;
}

ll mod_inv(ll x){
    return pow(x, mod-2);
}

// nは上限
void make_fact(ll n){
    fact[0] = 1;
    ll res = 1;
    for(int i = 1; i <= n; i++){
        fact[i] = res;
        res = mul(res, i+1);
    }
}

// nは上限
void make_invfact(ll n){
    invfact[0] = 1;
    invfact[n] = mod_inv(fact[n]);
    for(int i = n-1; i >= 1; i--){
        invfact[i] = mul(invfact[i + 1], i + 1);
    }
}

ll perm(ll n, ll k){
    return mul(fact[n], invfact[n-k]);
}

ll comb(ll n, ll k){
    if(n == 0){
        return 1;
    }
    return mul(mul(fact[n], invfact[n-k]), invfact[k]);
}


ll dp[2010][2010][2];
int main(){
    ll N, K;
    cin >> N >> K;

    make_fact(2010);
    make_invfact(2010);
    for(ll i = 1; i <= K; i++){
        ll M = N - K - (i-1);
        ll x = i;
        if(M < 0){
            cout << 0 << endl;
            continue;
        }
        ll red = comb(M+x, x);
        ll blue = comb(K-1, i-1);
        // cout << red << " " << blue << " " << mul(red, blue) << endl;
        cout << mul(red, blue) << endl;
    }


    return 0;
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define ALL(A) (A).begin(), (A).end()
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;
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 dx[] = { 0, 1, -1, 0, 1, -1, 1, -1 };  // i<4:4way i<8:8way
int dy[] = { 1, 0, 0, -1, 1, -1, -1, 1 };

const ll mod = 1e9 + 7;
const ll INF = -1 * ((1LL << 63) + 1);
const int inf = -1 * ((1 << 31) + 1);

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    ll n,k,ans = -1e18;
    cin >> n >> k;

    vector<ll> p(n+1),c(n+1);
    for(int i=1;i<=n;i++)cin >> p[i];
    rep(i,n)cin >> c[i+1];
    for(int i=1;i<=n;i++){
        // i は開始地点
        vector<bool> v(n+1,false); // 訪れたかどうか
        ll tmp = 0;
        int len = 0;
        int left = 0;
        int now = i;
        v[now] = true;
        for(int j=0;j<k;j++){
            now = p[now];
            tmp += c[now];
            len++;
            chmax(ans,tmp);
            if(v[now]){
                left = k - j - 1; // 残りの操作回数は k - j - 1 回になる
                break;
            }
        }
        if(left){
            // ループの長さはlen
            // 1ループあたりのスコアはtmp
            // よってtmp *= (k/len)
            int x = k/len;
            if(x)x--;
            tmp = tmp * x;
            left %= len;
            for(int j=0;j<left + len;j++){
                now = p[now];
                tmp += c[now];
                chmax(ans,tmp);
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3708
use proconio::{input, fastout};

#[fastout]
fn main() {
    input! {
        n: isize,
        k: isize,
        mut p: [isize; n]
    }

    p.sort();

    let mut ans = 0;
    for i in 0..k {
        ans += p[(i as usize)];
    }
    println!("{}", ans);
}


Measured memory_bytes: 2128
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<climits>
#define MOD 1000000007
typedef long long ll;
using namespace std;

int main(){
  map<string,ll> mp;
  int n; cin >> n;
  for(int i=0;i<n;i++){
    string s;
    cin >> s;
    mp[s]++;
  }
  ll mx = 0;
  for(auto c:mp){
    mx = max(mx, c.second); 
  }
  vector<string> v;
  for(auto c:mp){
    if(c.second == mx) v.push_back(c.first);
  }
  sort(v.begin(),v.end());
  for(auto c:v){
    cout << c << endl;
  }
  return 0;
}

Measured memory_bytes: 27632
import java.io.*;
import java.util.StringTokenizer;


public class Main {

    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        long h = sc.nextLong();
        long cur = 1;
        long ans = 0;
        while (h >= 1) {
            ans += cur;
            h /= 2;
            cur*=2;
        }
        out.println(ans);
        out.flush();
        out.close();
    }


    static class Scanner {

        StringTokenizer st;
        BufferedReader br;

        public Scanner(InputStream system) {
            br = new BufferedReader(new InputStreamReader(system));
        }

        boolean ready() throws IOException {
            return br.ready();
        }


        public String next() throws IOException {
            while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }

        public String nextLine() throws IOException {
            return br.readLine();
        }

        public int nextInt() throws IOException {
            return Integer.parseInt(next());
        }

        public double nextDouble() throws IOException {
            return Double.parseDouble(next());
        }

        public char nextChar() throws IOException {
            return next().charAt(0);
        }

        public Long nextLong() throws IOException {
            return Long.parseLong(next());
        }

        public int[] nextIntArray(int n) throws IOException {
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }

        public long[] nextLongArray(int n) throws IOException {
            long[] a = new long[n];
            for (int i = 0; i < n; i++)
                a[i] = nextLong();
            return a;
        }


        public Integer[] nextIntegerArray(int n) throws IOException {
            Integer[] a = new Integer[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }

        public double[] nextDoubleArray(int n) throws IOException {
            double[] ans = new double[n];
            for (int i = 0; i < n; i++)
                ans[i] = nextDouble();
            return ans;
        }

        public short nextShort() throws IOException {
            return Short.parseShort(next());
        }

    }

}

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

int f(int n){
    if(n % 2 == 0) return n/2;
    else return 3*n + 1;
}

int main(){
    int s, a, ans = 1;
    set<int> S;
    cin >> s;
    a = s;
    S.insert(a);
    while(true){
        ++ans;
        a = f(a);
        if(S.find(a) != S.end()) break;
        else  S.insert(a);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3636
//(bool) ? (if true) : (if false)
//63LL - __builtin_clzll(n)
//(x&-x)
#include<bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(0);cin.tie(0)
#define fst first
#define snd second
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define pf push_front
#define sz size()
#define FORN(i,j,n) for(long long i=j; i<(long long)n;i++) 
#define FOR(i,n) FORN(i,0,n)
#define FORIT(i,x) for( auto i = x.begin() ; i != x.end() ; i++ )
#define LIM 262150
#define ones(x) __builtin_popcount(x)
#define trace(x)    cerr << #x << ": " << x << endl;
#define trace2(x, y) cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
using namespace std;
 
typedef long long ll ;
typedef unsigned long long ull ;
typedef vector <int> vi;
typedef vector <long long> vll;
typedef pair <int,int> ii;
typedef vector <string> vs;
typedef vector <ii> vii;
const ll MAX = 2e5+5;
const ll MOD = 1e9+7;
int n,m;
set<int> s[MAX];
vi G[MAX];
bool vis[MAX];
int ans = -1;
int r = 0;
void dfs(int x){
	vis[x] = true;
	r++;
	FOR(i,G[x].sz){
		int y = G[x][i];
		if(!vis[y]) dfs(y);
	}
}
int main() {
	fastio;
	cin >> n >> m;
	FOR(i,m){
		int a,b; cin >> a >> b;
		if(s[a].count(b)) continue;
		G[a].pb(b);
		G[b].pb(a);
		s[a].insert(b);
		s[b].insert(a);
	}
	FORN(i,1,n+1){
		if(!vis[i]){
			dfs(i);
			ans = max(ans,r);
			r = 0;
		}
	}
	cout<< ans << '\n';
	return 0;
}

Measured memory_bytes: 49080
q, h, s, d = map(int, input().split(" "))
n = int(input())

cost = 0
div2 = n // 2

a = min(q * 8, h * 4, s * 2, d)

n -= div2 * 2
cost += div2 * a

if n == 1:
    a = min(q * 4, h * 2, s)

    cost += a

print(int(cost))


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

using namespace std;

using int64 = long long;
const int64 INF = 1LL << 60;


vector< int64 > solve(vector< int64 > A) {
  int N = (int) A.size();
  stack< int > st;
  vector< int64 > result(N);
  int64 ret = 0;

  st.emplace(N - 1);
  for(int i = (int) A.size() - 2; i >= 0; i--) {

    while(A[i] > A[i + 1]) {
      A[i + 1] *= 4;
      int r = st.top();
      st.pop();
      if(i + 1 != r) A[r] *= 4;
      ret += (r - i) * 2;
      if(r + 1 == N || A[r] * 4 <= A[r + 1]) st.emplace(r);
    }
    if(A[i] * 4 <= A[i + 1]) st.emplace(i);
    result[i] = ret;
  }
  return result;
}


int main() {
  int N;
  cin >> N;
  vector< int64 > A(N);
  for(int i = 0; i < N; i++) {
    cin >> A[i];
  }
  auto suf = solve(A);
  for(int i = 0; i < N; i++) {
    A[i] *= 2;
  }
  reverse(begin(A), end(A));
  auto pre = solve(A);
  reverse(begin(pre), end(pre));
  int64 ret = min(pre[N - 1] + N, suf[0]);
  for(int i = 1; i < N; i++) {
    ret = min(ret, pre[i - 1] + suf[i] + i);
  }
  cout << ret << endl;
}

Measured memory_bytes: 6500
// clang-format off
	#include <bits/stdc++.h>
	using namespace std; using ll = long long; using uint = unsigned int;
	#define SFINAE(x, ...)	template <class, class = void> struct x : false_type {}; template <class T> struct x<T, void_t<__VA_ARGS__>> : true_type {};
	SFINAE(DefaultIO, decltype(cout << declval<T &>()))
	SFINAE(IsTuple, typename tuple_size<T>::type)
	SFINAE(Iterable, decltype(begin(declval<T>())))
	template <class T> constexpr char Space(const T &) { return (Iterable<T>::value or IsTuple<T>::value) ? '\n' : ' '; }
	template <auto &os> struct Writer {
		template <class T> void Impl(T const &t) const {
			if constexpr (DefaultIO<T>::value) os << t;
			else if constexpr (Iterable<T>::value) { int i = 0; for (auto &&x : t) ((i++) ? (os << Space(x), Impl(x)) : Impl(x)); }
			else if constexpr (IsTuple<T>::value) apply([this](auto const &... args) { int i = 0; (((i++) ? (os << ' ', Impl(args)) : Impl(args)), ...);}, t);
			else static_assert(IsTuple<T>::value, "No matching type for print");
		}
		template <class F, class... Ts> auto &operator()(F const &f, Ts const &... ts) const { return Impl(f), ((os << ' ', Impl(ts)), ...), os << '\n', *this; }
	};
	template <auto &is> struct Reader {
		template <class T> auto& operator()(T &t) const {
			if constexpr (DefaultIO<T>::value) is >> t;
			else if constexpr (Iterable<T>::value) for (auto &x : t) (*this)(x);
			else if constexpr (IsTuple<T>::value) apply([this](auto &... args) { ((*this)(args), ...); }, t);
			else static_assert(IsTuple<T>::value, "No matching type for read");
			return *this;
		}
	};
	#ifdef NARUT_LOCAL
	#define Debug(...) cerr << "\033[0;31m", Writer<cerr>{}(__VA_ARGS__), cerr << "\033[0m\n"
	#else
	#define Debug(...) 0
	#endif
	[[maybe_unused]] constexpr Reader<cin> Cin; [[maybe_unused]] constexpr Writer<cout> Cout;
	#define FOR(i, j, n) for (int i = int(j); i < int(n); ++i)
	#define ROF(i, j, n) for (int i = int(n) - 1; i >= int(j); --i)
// clang-format on





auto Main() {
	int n,k;
	cin>>n>>k;
	vector<int> A(n);
	Cin(A);
	sort(begin(A), end(A));
	cout <<
		accumulate(A.begin(), A.begin()+k, 0ll);		
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout << fixed << setprecision(10);
#ifdef NARUT_LOCAL
	assert(freopen("io/test.in", "r", stdin));
	cin.exceptions(cin.badbit | cin.failbit);
	cerr << fixed << setprecision(10);
#endif

	Main();
}


Measured memory_bytes: 3648
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def S(): return input().rstrip()
def LS(): return S().split()
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float("INF")

#solve
def solve():
    s = S()
    d = defaultdict(int)
    tmp = 0
    ans = 0
    d[0] = 1
    for i, si in enumerate(s[::-1]):
        tmp += int(si) * pow(10, i, 2019)
        tmp %= 2019
        ans += d[tmp]
        d[tmp] += 1
    print(ans)
    return


#main
if __name__ == '__main__':
    solve()


Measured memory_bytes: 84220
def comb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

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



for i in range(1,k+1):
    if (n-k+1) >= i:
        print((comb(n-k+1, i) * comb(k-1, i-1))%(1000000007))
    else:
        print(0)


Measured memory_bytes: 3316
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
 
int main()
{
  int a, b, x;
  cin >> a >> b >> x;
  
  double theta;
  int V = a*a*b;
  
  if(V/2 < x){
    theta = atan((double)(2*(V-x))/(double)(a*a*a));
  }
  else{
    theta = atan((double)(a*b*b)/(double)(2*x));
  }
  printf("%lf\n", theta*180/M_PI);

  return 0;
}

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

using namespace std;

typedef long long int ll; 

int main(void)
{
	long double a,b,h,m;
	cin >> a >> b >> h >> m;

	long double min_deg = m*6;
	long double hr_deg = h*30 + m*0.5;

	long double theta = fabs(min_deg - hr_deg);

	long double theta2 = 360 - theta;
	long double angle = min(theta,theta2);
	long double pi = 2 * acos(0.0); 

	angle*=pi;
	angle/=180;

	long double ans = a*a + b*b - 2*a*b*cos(angle);
	// cout << angle << endl;
	ans =  pow(ans,0.5);
	// cout << ans << endl; 
	printf("%0.18Lf\n",ans);
	return 0;
}

Measured memory_bytes: 4148
#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e6;
bool prime[MAX];
signed
main(){
	vector<int> pnum;
	for(int i=0;i<MAX;i++)
		prime[i] = true;
	prime[1] = false;
	for(int i=2;i<MAX;i++)
	{
		if(prime[i])
		{
			pnum.push_back(i);
			for(int j=2*i;j<MAX;j+=i)
				prime[j] = false;
		}
	}

	int n,p;
	while(cin >> n >> p)
	{
		if(n==-1 and p==-1) break;
		int cnt = 0;
		while(1)
		{
			if(pnum[cnt]>n) break;
			else cnt++;
		}
		vector<int> ans;
		for(int i=cnt;i<cnt+p;i++)
		{
			for(int j=i;j<cnt+p;j++)
			{
				ans.push_back(pnum[i]+pnum[j]);
			}
		}
		sort(ans.begin(),ans.end());
		cout << ans[p-1] << endl;
	}
}


Measured memory_bytes: 4228
N,M=map(int,input().split())
A=[int(input()) for _ in range(M)]
ai=0
n1,n2=0,1
for i in range(1,N+1):
    if ai<M and i==A[ai]:
        ai+=1
        n1=n2
        n2=0
    else:
        tmp=n2
        n2=(n1+n2)%1000000007
        n1=tmp
print(n2)

Measured memory_bytes: 7080