akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char* argv[])
{
    int n,x;
    vector<pair<int,int>> input;
    vector<int> numberofways;
    set<int> dummy;
    set<set<int>> answer;
    while(1)
    {
        cin >> n >> x;
        if(n==0 && n==x) break;
        input.push_back(make_pair(n,x));
    }
    for (auto var : input)
    {
        for (int i = 1; i <= var.first; i++)
        {
            dummy.insert(i);
            for (int j = 1; j <= var.first; j++)
            {
                dummy.insert(j);
                if(var.second-i-j>0 && var.second-i-j<=var.first) dummy.insert(var.second-j-i);                                                                                             
                if(dummy.size()==3)
                {
                    answer.insert(dummy);
                }
                if(var.second-i-j>0 && var.second-i-j<=var.first) dummy.erase(var.second-j-i);                                                                                              
                dummy.erase(j);
            }
            dummy.erase(i);
        }
        numberofways.push_back(answer.size());
        answer.clear();
    }
    for (auto var : numberofways)
    {
        cout << var << endl;
    }
    return 0;
}


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

main(){
  string s;
  int f= 0;
  cin >> s;
  if (s[0] != 'A'){
    f = 1;
  }
  else if (count(s.begin()+2, s.end()-1,'C')!=1){f = 1;}
  else{
    for(int i=0;i<s.size();i++){
      if (s[i] == 'A' || s[i]=='C')continue;
      else{
        if('a'<=s[i]&&s[i]<='z')continue;
        else{
          f = 1;
          break;
        }
      } 
    }
  }
  
  if (f == 1)cout<<"WA"<<endl;
  else{cout<<"AC"<<endl;}
  
  return 0;

}

Measured memory_bytes: 256
import sys
input=sys.stdin.readline
n=int(input())
lr=[list(map(int,input().split())) for _ in range(n)]
lr.sort(key=lambda x:x[0])
lr.sort(key=lambda x:x[1])
mae=[]
l=0
r=10**9
for i in range(n-1):
    ll,rr=lr[i]
    l=max(ll,l)
    r=min(rr,r)
    mae.append(r-l+1)

usi=[]
l=0
r=10**9+1
for i in range(n-1,0,-1):
    ll,rr=lr[i]
    l=max(ll,l)
    r=min(rr,r)
    usi.append(r-l+1)
usi.reverse()

ans=0

for i in range(n-1):
    ans=max(mae[i]+usi[i],ans)

lr2=[(0,-1)]
ll=0
rr=10**9
for i in range(n-1):
    l,r=lr[i]
    ll=max(ll,l)
    rr=min(rr,r)
    lr2.append((ll,rr))
lr3=[(0,-1)]
ll=0
rr=10**9
for i in range(n-1,0,-1):
    l,r=lr[i]
    ll=max(ll,l)
    rr=min(rr,r)
    lr3.append((ll,rr))
lr3.reverse()

ans2=0
for i in range(n):
    l,r=lr[i]
    rr=min(lr2[i][1],lr3[i][1])
    ll=max(lr2[i][0],lr3[i][0])
    d=max(0,rr-ll+1)
    ans2=max(ans2,r-l+1+d)


ans=max(ans,ans2)



print(ans)


Measured memory_bytes: 50952
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ll long long
using namespace std;

const ll P = 1000000007;
const long long INF = 1LL << 60;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

int main()
{
  cout << fixed << setprecision(10);
  int N;
  cin >> N;
  int AC = 0;
  int WA = 0;
  int TLE = 0;
  int RE = 0;
  vector<string> S(N);
  rep(i,N) cin >> S[i];
  rep(i,N)
  {
    if(S[i]=="AC") AC ++;
    else if(S[i]=="WA") WA++;
    else if(S[i]=="TLE") TLE ++;
    else RE ++;
  }
  cout << "AC x " << AC << endl;
  cout << "WA x " << WA << endl;
  cout << "TLE x " << TLE << endl;
  cout << "RE x " << RE << endl;
  return 0;
}


Measured memory_bytes: 6420
#include<bits/stdc++.h>
#define enld '\n'
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[6] = {1, 0, -1, 0,1,1};
const int dy[6] = {0, 1, 0, -1,1,-1};
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(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N,M;
    cin >> N >> M;
    while(N != 0){
        vector<vector<int>> G(N);
        for(int i=0; i<M; i++){
            int a,b;
            cin >> a >> b;
            a--;b--;
            G[a].push_back(b);
            G[b].push_back(a);
        }
        vector<int> dist(N,-1);
        dist[0] = 0;
        queue<int> que;
        que.push(0);
        while(que.size()){
            int v = que.front();
            que.pop();
            for(int nv: G[v]){
                if(dist[nv] != -1) continue;
                dist[nv] = dist[v] + 1;
                que.push(nv);
            }
        }
        int cnt = 0;
        for(int i=1; i<N; i++){
            if(dist[i] <= 2 and dist[i] != -1){
                cnt++;
            }
        }
        cout << cnt << enld;
        cin >> N >> M;
    }
    return 0;
}



Measured memory_bytes: 3356
#include "bits/stdc++.h"
using namespace std;
const int MOD = 1e9 + 7;
typedef long long lint;
const int INF =1e7;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define trep(i, k, n) for (int i = (k); i < (int)(n); ++i)
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
lint cc[100005]={0};
int main()
{
    int n;
    cin>>n;
    lint k;
    cin >> k;
    rep(i, n)
    {
        int a,b;
        cin >> a>>b;
        cc[a] += b;
    }
    int i = 0;
    while (k > cc[i])
    {
        k -= cc[i];
        i++;
    }
    cout << i << endl;
    return 0;
}

Measured memory_bytes: 1024
package main

import "fmt"

func main() {
	var N int
	fmt.Scan(&N)
	Hz := make([]int, N)
	for i := 0; i < N; i++ {
		fmt.Scan(&Hz[i])
	}

	maxJump := 0
	tmpJump := 0

	for i := 0; i < N-1; i++ {
		if Hz[i] >= Hz[i+1] {
			tmpJump++
		} else {
			tmpJump = 0
		}

		if tmpJump > maxJump {
			maxJump = tmpJump
		}
	}
	fmt.Println(maxJump)
}


Measured memory_bytes: 6312
import itertools

n, c = map(int, input().split())
d = []
for i in range(c):
    di = list(map(int, input().split()))
    d.append(di)
dic0 = {}
dic1 = {}
dic2 = {}
for i in range(1, n+1):
    ci = list(map(int, input().split()))
    for j in range(n):
        cj = ci[j]
        if (i+j+1)%3 == 0:
            if cj in dic0:
                dic0[cj] += 1
            else:
                dic0[cj] = 1
        elif (i+j+1)%3 == 1:
            if cj in dic1:
                dic1[cj] += 1
            else:
                dic1[cj] = 1
        else:
            if cj in dic2:
                dic2[cj] += 1
            else:
                dic2[cj] = 1

ans = 10**9
for c0, c1, c2 in itertools.permutations(list(range(1, c+1)), 3):
    temp = 0
    for key in dic0.keys():
        if key != c0:
            temp += d[key-1][c0-1] * dic0[key]
    for key in dic1.keys():
        if key != c1:
            temp += d[key-1][c1-1] * dic1[key]
    for key in dic2.keys():
        if key != c2:
            temp += d[key-1][c2-1] * dic2[key]
    ans = min(ans, temp)
print(ans)

Measured memory_bytes: 75768
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {

    private static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

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

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

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }

    public static void main(final String[] args) throws IOException {
        FastReader in = new FastReader();
        PrintWriter out = new PrintWriter(System.out, true);
        int n = in.nextInt();
        int answer = (n / 2) + (n % 2);
        out.println(answer);
    }
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)
typedef long long ll;

int main() {
    int n; cin >> n;
    int a[n];
    vector<int> b(n);
    int top = 0;
    rep(i,n){
        cin >> a[i];
        b[i] = a[i];
        top = max(top,a[i]);
    }
    sort(b.begin(),b.end());
    reverse(b.begin(),b.end());
    int second = b[1];

    rep(i,n){
        if(a[i] == top) cout << second << endl;
        else cout << top << endl;
    }
}

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

struct TaskStruct
{
	char name[12];
	int time;
};
typedef struct TaskStruct Task;

#define QUEUE_SIZE 100000
struct QueueStruct
{
	int head, tail;
	Task data[QUEUE_SIZE];
};
typedef struct QueueStruct Queue;

void queue_clear(Queue *queue)
{
	queue->head = 0;
	queue->tail = 0;
}

int queue_empty(Queue *queue)
{
	return (queue->head == queue->tail);
}

Task queue_dequeue(Queue *queue)
{
	Task task = queue->data[queue->head++];
	queue->head %= QUEUE_SIZE;
	return task;
}

void queue_enqueue(Queue *queue, Task task)
{
	queue->data[queue->tail++] = task;
	queue->tail %= QUEUE_SIZE;
}

void queue_dump(Queue *queue)
{
	printf("[");
	for(int i = queue->head; i != queue->tail; i = (i+1)%QUEUE_SIZE)
	{
		Task task = queue->data[i];
		printf(" %s(%d)", task.name, task.time);
	}
	printf(" ]\n");
}

int main()
{
	int n, t, quantum;
	Queue queue;
	queue_clear(&queue);

	scanf("%d %d", &n, &quantum);
	for(int i = 0; i < n; ++i)
	{
		Task task;
		scanf("%s %d", task.name, &task.time);
		queue_enqueue(&queue, task);
	}

	t = 0;
	while(!queue_empty(&queue))
	{
		//queue_dump(&queue);
		Task task = queue_dequeue(&queue);
		if(task.time <= quantum)
		{
			t += task.time;
			printf("%s %d\n", task.name, t);
		}
		else
		{
			task.time -= quantum;
			t += quantum;
			queue_enqueue(&queue, task);
		}
	}
}



Measured memory_bytes: 3324
#!/usr/bin/env python3

from pprint import pprint
import sys

sys.setrecursionlimit(10 ** 6)


X, Y, A, B, C = map(int, input().split())
apples_A = sorted(list(map(int, input().split())))
apples_B = sorted(list(map(int, input().split())))
apples_C = sorted(list(map(int, input().split())))

# 赤のリンゴからおいしさが大きい順に X 個選ぶ (1)
# 緑のリンゴからおいしさが大きい順に Y 個選ぶ (2)
# (1), (2) そして 無色のリンゴのから、おいしさが大きいものから順に X + Y 個選べば良い

apples_rest = sorted(apples_A[-X:] + apples_B[-Y:] + apples_C)
ans = sum(apples_rest[ -(X + Y):])

print(ans)


Measured memory_bytes: 109460
import sys
sys.setrecursionlimit(10**6)
e=enumerate
def dfs(v):
  d=sorted(map(dfs,t[v]))
  l=len(d)
  return max([0]+[l-i+d for i,d in e(d)])
n,*a=map(int,open(0))
t=[[]for _ in[0]+a]
for i,v in e(a,1):t[v-1]+=i,
print(dfs(0))

Measured memory_bytes: 204500
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using static MyIO;
using System.IO;

namespace paiza
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = GetInt();
            var B = GetInt();

            Console.WriteLine(N * B);

            return;
        }
        

    }
}

public static class MyIO
{
    private static string[] args = null;
    private static int num = -1;
    private static int used = -1;

    private static string getArg()
    {
        if (used == num)
        {
            args = Console.ReadLine().Split(' ');
            num = args.Length;
            used = 0;
        }
        return args[used++];
    }

    public static int GetInt() => int.Parse(getArg());
    public static long GetLong() => long.Parse(getArg());
    public static double GetDouble() => double.Parse(getArg());
    public static string GetString() => getArg();
    public static char GetChar() => getArg()[0];
    public static int[] GetInts(int N) => Enumerable.Range(0, N).Select(_ => GetInt()).ToArray();
    public static long[] GetLongs(int N) => Enumerable.Range(0, N).Select(_ => GetLong()).ToArray();
    public static double[] GetDoubles(int N) => Enumerable.Range(0, N).Select(_ => GetDouble()).ToArray();
    public static string[] GetStrings(int N) => Enumerable.Range(0, N).Select(_ => GetString()).ToArray();
}

Measured memory_bytes: 27492
/*Template by hemnath_d(Enlightened by chamow)*/
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define vec vector<ll>
#define pll pair<ll,ll>
#define fastread ios_base::sync_with_stdio(false); cin.tie(NULL);
#define pb push_back
#define mp make_pair
#define fx first
#define sx second
#define inf 100000000000000
#define minf -100000000000000
#define maxi 100005
vec adj[maxi];
/*Function to add an edge*/
//Undirected graph
void add_edge(ll a,ll b)
{
    adj[a].pb(b);
}
ll dp[maxi];
ll dfs(ll x)
{
	if(dp[x]!=-1)
		return dp[x];
	ll ans=0;
	for(ll i=0;i<adj[x].size();i++)
		ans=max(ans,dfs(adj[x][i])+1);
	dp[x]=ans;
	return ans;
}
int main()
{
    fastread;
    ll n,m;
    cin>>n>>m;
    for(ll i=0;i<=n;i++)
    	dp[i]=-1;
    for(ll i=0;i<m;i++)
    {
    	ll x,y;
    	cin>>x>>y;
    	add_edge(x,y);
    }
    ll ans=0;
    for(ll i=1;i<=n;i++)
    	ans=max(ans,dfs(i));
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 8576
N=int(input())
a=list(map(int,input().split()))
def change(a,x):
    sum=0
    for i in a:
        sum+=(x-i)**2
    return sum

def binarysearch(left,right,a):
    if right-left<=1:
        return min(change(a,left),change(a,right))
    else:
        center=left+(right-left)//2
        if change(a,center)<=change(a,center+1):
            return binarysearch(left,center,a)
        else:
            return binarysearch(center,right,a)

if change(a,100)<=change(a,99):
    print(change(a,100))
elif change(a,-100)<=change(a,-99):
    print(change(a,-100))
else:
    print(binarysearch(-100,100,a))

Measured memory_bytes: 3064
#include "bits/stdc++.h"
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for(lint i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(lint i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
template<typename T1, typename T2> pair<T1, T2> operator+(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first + r.first, l.second + r.second); }
template<typename T1, typename T2> pair<T1, T2> operator-(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first - r.first, l.second - r.second); }

lint N;
lint cost[300][300];
bool need[300][300];

int main() {
	cin.tie(0); ios_base::sync_with_stdio(false);
	cin >> N;
	REP(i, N) {
		REP(j, N) {
			cin >> cost[i][j];
			need[i][j] = true;
		}
	}

	lint sum = 0;
	REP(k, N) {
		REP(i, N) {
			REP(j, N) {	
				if (cost[i][j] > cost[i][k] + cost[k][j]) {
					cout << -1 << endl;
					return 0;
				}
				else {
					if (cost[i][j] == cost[i][k]+cost[k][j] && i != k && k != j) {
						need[i][j] = false;
					}
				}
			}
		}
	}
	REP(i, N - 1) {
		FOR(j, i + 1, N) {
			if(need[i][j]) sum += cost[i][j];
		}
	}
	cout << sum << endl;
}


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

using namespace std;

#define rep(i,n) for(int i = 0; i != n; ++i)

const double EPS = 1e-10;
const int INF = 1e7;

int main(){
  // int n;
  // scanf("%d", &n);
  string s;
  cin >> s;
  int sum = 700;
  for (int i=0; i<3; ++i) {
    if (s[i] == 'o') sum += 100;
  }
  std::cout << sum << '\n';
  return 0;
}


Measured memory_bytes: 256
n = gets.to_i
a = gets.to_i
b = gets.to_i
c = gets.to_i
d = gets.to_i
e = gets.to_i
all = [a,b,c,d,e]

min = all.min
index = all.index(min)
ans = index + (n % min == 0 ? n / min : n / min + 1) + 4 - index

puts ans


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

int n, Lmin, Last[28], Next[200005][28], Urm[200005], L[200005];
char s[200005], u[200005];
char s1[200005], sol[200005];
bool f[27];
inline void dfs(int nod, int L){
    if(L >= Lmin) return ;

}
int main()
{
//    freopen("ciorna.in", "r", stdin);
    scanf("%s", s + 1);
    n = strlen(s + 1);
    for(int i = 1; i <= n ; ++i)
        f[s[i] - 'a'] = 1;
    for(int i = 0; i < 26 ; ++i)
        if(f[i] == 0){printf("%c", i + 'a'); return 0;}
    for(int i = n; i >= 1 ; --i){
        for(int j = 0; j < 26 ; ++j)
            Next[i][j] = Last[j];
        Last[s[i] - 'a'] = i;
    }
    Lmin = n;
    L[n] = 2;
    u[n] = 'a';
    Urm[n] = n + 1;
    for(int i = n - 1; i >= 1 ; --i){
        L[i] = n;
        for(int j = 0; j < 26 ; ++j){
            if(Next[i][j] == 0){
                u[i] = j + 'a';
                L[i] = 2;
                Urm[i] = n + 1;
                break ;
            }
            else{
                if(L[i] > L[Next[i][j]] + 1){
                    L[i] = L[Next[i][j]] + 1;
                    Urm[i] = Next[i][j];
                    u[i] = s[Next[i][j]];
                }
            }
        }
    }
    for(int i = 0; i < 26 ; ++i){
        if(L[Last[i]] < Lmin){
            memset(s1, NULL, sizeof(s1));
            memset(sol, NULL, sizeof(sol));
            Lmin = L[Last[i]];
            int l = 0, p = Last[i];
            s1[++l] = s[p];
            while(p <= n){
                s1[++l] = u[p];
                p = Urm[p];
            }
            strcpy(sol + 1, s1 + 1);
        }
    }
    printf("%s", sol + 1);
    return 0;
}


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

string str;

ll dfs(ll sum,ll b,ll d){
  if(d>str.size()-1){
return sum+b;
  }
  
  else{
    
    ll m=dfs(sum,b*10+str[d]-'0',d+1);
    ll n=dfs(sum+b,str[d]-'0',d+1);
    
    return m+n;
  }
}
 int main(){
  
   cin>>str;
   
   ll ans=dfs(0,str[0]-'0',1);
   
   cout<<ans<<endl;
 }
  
  


Measured memory_bytes: 256
from itertools import combinations as comb


def main():
    a, b, c = map(int, input().split())
    if a == (b+c) or b == (a+c) or c == (a+b):
        ans = 'Yes'
    else:
        ans = "No"
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9120
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <functional>
#include <array>
#include <map>
#include <queue>
#include <limits.h>
#include <set>
#include <stack>
#include <random>
#include <complex>
#include <unordered_map>
#define rep(i,s,n) for(int i = (s); (n) > i; i++)
#define REP(i,n) rep(i,0,n)
#define RANGE(x,a,b) ((a) <= (x) && (x) < (b))
#define DUPLE(a,b,c,d) (RANGE(a,c,d) || RANGE(b,c,d) || RANGE(c,a,b) || RANGE(d,a,b))
#define INCLU(a,b,c,d) (RANGE(a,c,d) && (b,c,d))
#define PW(x) ((x)*(x))
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MODU 1000000007
#define bitcheck(a,b)   ((a >> b) & 1)
#define bitset(a,b)      ( a |= (1 << b))
#define bitunset(a,b)    (a &= ~(1 << b))
#define MP(a,b) make_pair((a),(b))
#define Manh(a,b) (abs((a).first-(b).first) + abs((a).second - ((b).second))
#define pritnf printf
#define scnaf scanf
#define itn int
#define PI 3.141592653589


#define izryt bool
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T &val) {
	std::fill((T*)array, (T*)(array + N), val);
}
pii Dir[8] = { //移動
	{ 0 ,1 },{ -1 ,0 },{ 1 ,0 },{ 0 ,-1 },
	{ 1 ,1 },{ 1 ,-1 },{ -1 ,1 },{ -1 ,-1 }
};

unsigned long xor128() {
	static unsigned long x = 123456789, y = 362436069, z = 521288629, w = 88675123;
	unsigned long t = (x^(x << 11));
	x = y; y = z; z = w;
	return (w = (w^(w >> 19))^(t^(t >> 8)));
}

void calc(vector<double>& lg, vector<ll>& so, int n) {
	vector<pll> po;

	ll cou = 0;
	double cur = lg[n - 1];

	for (int i = n - 1; 0 <= i; i--) {
		double nex = lg[i];

		if (nex > cur) {
			int sa = ceil((nex - cur) / 2) * 2;

			int cpos = i;
			for (auto itr = po.rbegin(); itr != po.rend(); ++itr) {
				if (itr->second == 0) continue;
				if (itr->second >= sa) {
					itr->second -= sa;
					cou += (itr->first - cpos)*sa;
					sa = 0;
					break;
				}
				else {
					cou += (itr->first - cpos)*itr->second;
					sa -= itr->second;
					itr->second = 0;
				}
			}

			cou += sa * (n - 1 - cpos);
		}
		else if (cur - nex >= 2) po.push_back({ i, ((ll)((cur - nex) / 2)) * 2 });

		cur = nex;

		so[i] = cou;
	}
}

int main(void) {
	int n;

	cin >> n;
	vector<ll> a(n);
	vector<double> lg(n);

	REP(i, n) {
		cin >> a[i];
		lg[i] = log2(a[i]);
	}

	vector <ll> sou(n + 1), sod(n + 1);

	calc(lg, sou, n);
	reverse(ALL(lg));
	calc(lg, sod, n);

	ll ans = LLONG_MAX;

	rep(c, 0, n + 1) {
		ll up = sou[c], dn = sod[n - c];
		ans = min(ans, up + dn + c);

	}


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


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

using namespace std;

#define int long long 

int32_t main()
{
	int n;
	cin >> n;
	vector<int> v(n);
	for(int i=0;i<n;i++)
	{
		cin >> v[i];
	}
	int curr = v[0], ans = 0;
	for(int i=1;i<n;i++)
	{
		ans += max(0LL, curr-v[i]);
		curr = max(curr, v[i]);
	}
	cout << ans << "\n";
}

Measured memory_bytes: 4756
#include<stdio.h>
#include<string.h>
int main()
{
    char s1[105],s2[105];
    int i,j,k,n;
    scanf("%d",&n);
    scanf("%s %s",s1,s2);
    for(i=0;i<n;i++)
    {
        printf("%c",s1[i]);
        printf("%c",s2[i]);
    }
    return 0;
}


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

typedef long long ll;
typedef pair<int, int> ii;

const int N = 1e5 + 5;
int n, m;
ii a[N];
priority_queue<int, vector<int>, greater<int>> que;
ll res;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n >> m;
    for (int i = 0; i < n; ++i) {
        cin >> a[i].first >> a[i].second;
    }
    sort(a, a + n, greater<ii>());
    for (int i = 0; i < n; ++i) {
        int p = a[i].second;
        if (que.size() + a[i].first <= m) {
            res += p;
            que.push(p);
        } else if (!que.empty() && p > que.top()) {
            res -= que.top();
            res += p;
            que.pop();
            que.push(p);
        }
    }
    cout << res << endl;
    return 0;
}



Measured memory_bytes: 4604
s = input()
n = int(s)
l = len(s)
isall9 = True
for i in range(1, l):
    if s[i] != "9":
        isall9 = False
if isall9:
    print( int(s[0])  + 9 * (l - 1) )
else:
    res = int(int(s[0]) - 1) + 9 * (l - 1)
    print( res)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef int64_t i64;

int main()
{
  int H,W,h,w;
  cin >> H >> W >> h >> w;

  int ans = (h*W) + (w*H);
  ans = ans - (h*w);
  ans = (H*W) - ans;

  cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.*;

class Main{
public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
	long x = sc.nextLong();
	long y = sc.nextLong();
	long ans = 1;
	while(2*x<=y) {
		x *= 2;
		ans++;
	}
	System.out.println(ans);
}
}

Measured memory_bytes: 23124
#include<bits/stdc++.h>
#define ll long long
#define viit(a) vector<int>::iterator a
#define IT iterater
#define REP(i,a,n) for(ll i=a;i<(n);i++)
#define FOR(i,a,n) for(ll i=a;i<=(n);i++)
#define V vector
#define RE return
#define B(s) s.back()
#define all(a) a.begin(),a.end()
#define ER1(a) a.erase(a.begin())
#define ER0(a) a.erase(a.end())
#define Fill(a,b) memset(a,b,sizeof(a))
#define SO(a) sort(all(a))
#define pb push_back
#define pii pair<int,int>
#define F first
#define S second
using namespace std;
int main()
{
    ios::sync_with_stdio(0);
    long long n,k,a[1000001];
    cin>>k>>n;
    REP(i,0,n)
    cin>>a[i];
    long long minimum=1000050;
    REP(i,0,n-1){
    	int s=abs(a[i]-a[(i+1)%n]);
    	minimum=min(k-s,minimum);
	}
	minimum=min(a[n-1]-a[0],minimum);
	cout<<minimum;	 
    RE 0;
}


Measured memory_bytes: 3712
#include <stdio.h>
#include <math.h>
#include <string.h>
int main(){
    char a[20000];
    scanf("%s",a);       printf("%c",a[0]);
    scanf("%s",a);       printf("%c",a[0]);
    scanf("%s",a);       printf("%c",a[0]);
    return 0;
}

Measured memory_bytes: 128
#include <stdio.h>

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

Measured memory_bytes: 128
#![allow(dead_code)]
use std::io::{self, Read};
use std::str::FromStr;
use std::u64;
use std::collections::VecDeque;
use std::collections::BinaryHeap;

pub struct Scanner<R: Read> {
    reader: R,
}
impl<R: Read> Scanner<R> {
    pub fn new(reader: R) -> Scanner<R> {
        Scanner { reader: reader }
    }
    pub fn read<T: FromStr>(&mut self) -> T {
        let s = self
            .reader
            .by_ref()
            .bytes()
            .map(|c| c.expect("failed to read char") as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        s.parse::<T>().ok().expect("failed to parse token")
    }
}

// 通常のキューを使った探索。これでも時間内で動作した
fn solve(mat: &Vec<Vec<(usize, u64)>>) -> Vec<u64> {
    let n = mat.len();
    let mut dist = vec![u64::MAX; n];
    dist[0] = 0;

    let mut que = VecDeque::new();
    que.push_back(0);

    while let Some(idx) = que.pop_front() {
        for &(i, d) in mat[idx].iter() {
            let s = dist[idx] + d;
            if s < dist[i] {
                dist[i] = s;
                que.push_back(i);
            }
        }
    }

    dist
}

// BinaryHeapで用いるためのStruct
#[derive(Eq, PartialEq)]
struct Node {
    idx: usize,
    cost: u64,
}

impl Ord for Node {
    fn cmp(&self, other :&Node) -> std::cmp::Ordering {
        // Minヒープにするため、比較を左右逆にする(cost小さい、idx小さい)
        // まず、左右逆のcostの比較を行う
        other.cost.cmp(&self.cost)
            // コストが同じだった場合(thenはEqual時のみ呼び出しで、それ以外はそのまま値を返す)、
            // 左右逆のidxの比較を行う
            .then_with(|| self.idx.cmp(&other.idx))
    }
}

// PartialOrdも順序比較に実装が必要。ここではNanは存在しないのでOrdの実装をSomeでラップするだけ
impl PartialOrd for Node {
    fn partial_cmp(&self, other: &Node) -> Option<std::cmp::Ordering> {
        Some(self.cmp(other))
    }
}


// 二分ヒープを用いたダイクストラ法
fn solve_binary_heap(mat: &Vec<Vec<(usize, u64)>>) -> Vec<u64> {
    let n = mat.len();
    let mut dist = vec![u64::MAX; n];
    let mut par = vec![None; n];    // 親

    dist[0] = 0;
    let mut heap = BinaryHeap::new();
    heap.push(Node {idx: 0, cost: 0,});

    while let Some(Node{idx, cost: _cost}) = heap.pop() {
        for &(i, d) in mat[idx].iter() {
            let s = dist[idx] + d;
            if s < dist[i] {
                dist[i] = s;
                par[i] = Some(idx);
                heap.push(Node {idx: i, cost: dist[i], });
            }
        }
    }

    dist
}


fn main() {
    let sin = io::stdin();
    let sin = sin.lock();
    let mut sc = Scanner::new(sin);

    let n: usize = sc.read();

    let mut mat: Vec<Vec<(usize, u64)>> = vec![vec![]; n];
    for _ in 0..n {
        let u: usize = sc.read();
        let k: usize = sc.read();
        for _ in 0..k {
            let v: usize = sc.read();
            let c: u64 = sc.read();
            mat[u].push((v, c));
        }
    }

    // let dist = solve(&mat);
    let dist = solve_binary_heap(&mat);

    for i in 0..n {
        println!("{} {}", i, dist[i]);
    }
}



Measured memory_bytes: 15264
#include <bits/stdc++.h>
#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define FORR(i, a, b) for(ll i = (a); i > (b); --i)
#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOREACH(x, a) for(auto &(x) : (a))
#define dump(x) cout << #x << " = " << (x) << endl;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  vector<double> p(N);
  REP(i, N) cin >> p[i];
  vector<vector<double>> dp(N, vector<double>(N + 1, 0));
  dp[0][0] = 1 - p[0];
  FOR(i, 1, N) { dp[i][0] = dp[i - 1][0] * (1 - p[i]); }
  dp[0][1] = p[0];
  REP(i, N - 1) FOR(j, 1, N + 1) {
    dp[i + 1][j] = dp[i][j - 1] * p[i + 1] + dp[i][j] * (1 - p[i + 1]);
  }
  double ans = 0;
  for(int j = N; j > double(N) / 2; j--) {
    ans += dp[N - 1][j];
  }
  // REP(i, N) {
  //   REP(j, N + 1) { cout << dp[i][j] << ' '; }
  //   cout << endl;
  // }
  cout << setprecision(10) << ans << endl;
  return 0;
}

Measured memory_bytes: 70784
function main(input) {
  input = input.split(" ");
  var max = input[1] < input[2] ? input[1] : input[2];
  var min = input[0]-input[1] > input[2] ? 0 : input[2]-(input[0]-input[1]);
  console.log(max + " " + min);
}
main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define int ll
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a) (a).begin(),(a).end()
#define pb emplace_back

int fa(int n){
    if(n==0)return 1;
    else return fa(n-1)*2+3;
}

int fp(int n){
    if(n==0)return 1;
    else return fp(n-1)*2+1;
}

signed main(){
    int n,x;
    cin>>n>>x;

    int ans = 0;
    while(x>0){
      //今見てるパウンドがLevel N
        for(int i=n;i>=0;i--){  
            if(x>=fa(i)){ //Level　i のバーガーを食べきれるか
                x-=fa(i);
                ans+=fp(i);

                if(x>0){  //Level i を食べた後に間のパウンドを食べる
                    x--;
                    ans++;
                }

                n = i;  //今見てるパウンドを更新(?)
                break;
            }else{  //無理ならLevel i のパンズを食べてLevel i-1に移行
                x--;
            }
        }
    }

    cout<<ans<<endl;
}


Measured memory_bytes: 256
sx,sy,tx,ty=map(int,input().split())

s=""

s += "R"*(tx-sx)+"U"*(ty-sy)
s += "R"
s += "D"*(ty-sy+1)+"L"*(tx-sx+1)
s += "U"
s += "U"*(ty-sy)+"R"*(tx-sx)
s += "U"
s += "L"*(tx-sx+1)+"D"*(ty-sy+1)
s += "R"

print(s)


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

using namespace std;

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


int main() {
    int H, W = 0;
    cin >> H >> W;
    vector<string> data(102);
    rep(i, H + 2) {
        if (i == 0 || i == H + 1) {
            data.at(i) = string(W + 2, '#');
        } else {
            string line;
            cin >> line;
            line = '#' + line + '#';
            data.at(i) = line;
        }
    }

    rep(i, H + 2) {
        cout << data.at(i) << endl;
    }
}


Measured memory_bytes: 256
use std::cmp;

fn main() {
    // input
    let input = read_vec::<i32>();

    // A
    let a = input[0];
    // B
    let b = input[1];

    let plus = a+b;
    
    let minus = a-b;
    let multi = a*b;

    let ans = cmp::max(plus, cmp::max(minus, multi));

    println!("{}", ans);
}

#[allow(dead_code)]
fn read_line<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}
#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read_line::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

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

#define rep(i,start,n) for(int i=start;i<(int)(n);i++)
#define rrep(i,n,end) for(int i=n-1;i>=end;i--)
#define each(it,v) for(auto it : v)
#define all(v) (v).begin(),(v).end()

using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using Pii = pair<int,int>;
using Pll = pair<ll,ll>;
using vpii = vector<Pii>;
using vpll = vector<Pll>;

const ll mod=1e9+7;
const int intINF=INT_MAX;
const ll  longINF=LONG_LONG_MAX;

ll power(ll a, ll n, ll m)
{
        ll ret = 1;
        for (; n > 0; n >>= 1, a = a * a % m)
        {
                if (n % 2 == 1)
                {
                        ret = ret * a % m;
                }
        }
        return ret;
}

ll C(int N,int K)
{
        ll 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)%mod;
}

main()
{
        int n,a,b; cin>>n>>a>>b;

        ll ans=power(2,n,mod)-1;
        ans-=C(n,a)%mod;
        ans-=C(n,b)%mod;
        cout<<(ans%mod+mod)%mod<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <random>
#include <unordered_map>
#include <unordered_set>
#define all(a) a.begin(),a.end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define pb push_back
#define debug(x) cerr << __LINE__ << ' ' << #x << ':' << x << '\n'
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;
typedef complex<ld> com;
constexpr int inf = 1000000010;
constexpr ll INF = 1000000000000000010;
constexpr ld eps = 1e-12;
constexpr ld pi = 3.141592653589793238;
template<class T, class U> inline bool chmax(T &a, const U &b) { if (a < b) { a = b; return true; } return false; }
template<class T, class U> inline bool chmin(T &a, const U &b) { if (a > b) { a = b; return true; } return false; }


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

	int n, x, t;
	cin >> n >> x >> t;
	n = (n + x - 1) / x;
	cout << n * t << '\n';
}

Measured memory_bytes: 3604
#include <iostream>
#include <cstdio>
#include <cassert>
#include <cstring>
#include <vector>
#include <valarray>
#include <array>
#include <queue>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <complex>
#include <random>
#include <bitset>

using namespace std;
typedef long long ll;

const int MN = 100100;
typedef pair<int, int> P;

vector<int> g[MN];
bool used[MN];
bool color[MN];
int c0, c1;
bool err;
void dfs(int p, bool c) {
    used[p] = true;
    color[p] = c;
    if (!c) c0++;
    else c1++;
    for (int d: g[p]) {
        if (used[d]) {
            if (color[p] == color[d]) err = true;
            continue;
        }
        dfs(d, !c);
    }
}

bitset<MN> b;
ll solve() {
    int v, e;
    cin >> v >> e;
    for (int i = 0; i < e; i++) {
        int a, b;
        cin >> a >> b; a--; b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    b[0] = true;
    for (int i = 0; i < v; i++) {
        if (used[i]) continue;
        c0 = c1 = 0;
        dfs(i, 0);
        if (err) return -1;
        b = (b<<c0) | (b<<c1);
    }
    ll sm = -1;
    for (int i = 0; i < v; i++) {
        if (!b[i]) continue;
        sm = max(sm, (ll)(v-i)*i-e);
    }
    return sm;
}


int main() {
    cout << solve() << endl;
    return 0;
}

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

typedef long long ll;

string s;
int Cnt1, Cnt2;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> s;
    int n = s.length();
    // 1: 010101
    // 2: 101010
    for (int i = 0; i < n; ++i) {
        if (i & 1) {
            if (s[i] == '1') {
                ++Cnt2;
            } else {
                ++Cnt1;
            }
        } else {
            if (s[i] == '1') {
                ++Cnt1;
            } else {
                ++Cnt2;
            }
        }
    }
    cout << min(Cnt1, Cnt2) << endl;

    return 0;
}



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

#define st first
#define nd second
#define ll long long
#define ld long double
#define pb push_back
#define emp emplace_back
#define pii pair<int, int>
#define usg unsigned
#define sg signed
#define mp make_pair

using namespace std;

void setIO(){
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
}

const ld PI = 4*atan((ld)1);
const int INF = 1e9+7;

int main(){
	setIO();
	int a, b, c, d, ct=0;
	cin>>a>>b>>c>>d;
	while(a>0 && c>0){
		if(ct&1^1) c-=b;
		else a-=d;
		ct++;
	}
	if(a<=0) cout<<"No\n";
	else cout<<"Yes\n";
}

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

using namespace std;
typedef long long ll;
const int MAXN = 300100;
const int P = (1 << 17);
const int MAXP = 2 * P + 100;

int N, M;
vector <pair <int, int> > event[MAXN];
int seg[MAXP];

void upd (int x, int v)
{
    x += P;
    while (x)
    {
        seg[x] += v;
        x /= 2;
    }
}

int csum (int x)
{
    if (x >= P) return seg[1];
    x += P;
    int ctot = 0;
    while (x > 1)
    {
        if (x & 1) ctot += seg[x-1];
        x /= 2;
    }
    return ctot;
}

ll gogo (int K)
{
    ll ans = 0;
    ll cv = 0;
    for (int i = 0; i * K <= M; i++)
    {
        ll nc = csum ((i + 1) * K);
        ans += (nc - cv) * i;
        cv = nc;
    }
    return ans;
}

int main()
{
    ios_base::sync_with_stdio(0);

    cin >> N >> M;
    for (int i = 0; i < N; i++)
    {
        int l, r;
        cin >> l >> r;
        l--;

        event[r-l].push_back(make_pair (l, r));
    }

    int nleft = N;
    for (int i = 1; i <= M; i++)
    {
        for (auto pp : event[i])
        {
            nleft--;
            upd (pp.first, -1);
            upd (pp.second, 1);
        }

        cout << nleft + gogo (i) << "\n";
    }
}

Measured memory_bytes: 13056
#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
using vi = vector<i64>;
using vvi = vector<vi>;

int main() {
    int n;
    cin >> n;
    int a, b;
    int maxa = 0, maxb = 0;
    for (int i = 0; i < n; i++) {
        cin >> a >> b;
        if (a > maxa) {
            maxa = a;
            maxb = b;
        }
    }
    cout << maxa + maxb << endl;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

N = int(input())
A = [int(input()) for _ in range(N)]

if A[0] != 0:
    ans = -1
else:
    for a, b in zip(A, A[1:]):
        if a == b:
            continue
        elif a > b:
            continue
        elif a+1 == b:
            continue
        else:
            ans = -1
            print(ans)
            exit()

    subA = []
    prev = -1
    l = 0
    tmp_array = []
    while l < N:
        if A[l] > prev:
            tmp_array.append(A[l])
            prev = A[l]
        else:
            prev = A[l]
            subA.append(tmp_array)
            tmp_array = [prev]

        l += 1
    subA.append(tmp_array)
    ans = sum([max(l) for l in subA])
print(ans)


Measured memory_bytes: 31372
N, M = map(int, input().split())
A = list(map(int, input().split()))
BC = [list(map(int, input().split())) for _ in range(M)]
BC.sort(key=lambda x: x[1], reverse=True)
D = []
sum_B=0
for B, C in BC:
    D += [C] * B
    sum_B += B
    if sum_B>N:
        break

A+=D
A.sort(reverse = True)
print(sum(A[:N]))

Measured memory_bytes: 36168
# abcde    s=input()    s='abcde'
# abcde    s=list(input())    s=['a', 'b', 'c', 'd', 'e']
# 5(1つだけ)    a=int(input())    a=5
# 1 2    | x,y = s_inpl()   |    x=1,y=2
# 1 2 3 4 5 ... n 　    li = input().split()    li=['1','2','3',...,'n']
# 1 2 3 4 5 ... n 　    li = inpl()    li=[1,2,3,4,5,...,n]
# FFFTFTTFF 　    li = input().split('T')    li=['FFF', 'F', '', 'FF']

# INPUT
# 3
# hoge
# foo
# bar
# ANSWER
# n=int(input())
# string_list=[input() for i in range(n)]

import math
import copy
from collections import defaultdict
from collections import Counter
from collections import deque
# 直積 A={a, b, c}, B={d, e}:のとき，A×B={(a,d),(a,e),(b,d),(b,e),(c,d),(c,e)}: product(A, B)
from itertools import product
# 階乗 P!: permutations(seq), 順列 {}_len(seq) P_n: permutations(seq, n)
from itertools import permutations
# 組み合わせ {}_len(seq) C_n: combinations(seq, n)
from itertools import combinations
from bisect import bisect_left, bisect_right
# import numpy as np

def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W

# 四方向: 右, 下, 左, 上
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]

def i_inpl(): return int(input())
def s_inpl(): return map(int,input().split())
def l_inpl(): return list(map(int, input().split()))
INF = float("inf")
MAX_DIGIT = 50

############
############
############

N, K = l_inpl()
A = l_inpl()

# dp[上からi桁まで][smaller]
# smaller=0: X=K
# smaller=1: X<K
dp = [[-1] * 2 for _ in range(MAX_DIGIT+1)]
dp[0][0] = 0

for d in range(1, MAX_DIGIT+1):
    mask = 1<<(MAX_DIGIT - d)

    # A[i]においてd桁目にビットが立っているものの個数
    cnt = 0
    for i in range(N):
        if A[i] & mask:
            cnt += 1

    # Xのd桁目を0, 1にしたときのコスト
    cost0 = mask * cnt
    cost1 = mask * (N - cnt)

    # Kのd桁目が1だったとき
    if mask & K:
        # X=K -> X=K
        dp[d][0] = dp[d-1][0] + cost1
        if dp[d-1][1] == -1:
            dp[d][1] = cost0
        else:
            # X=K, X<K -> X<K
            dp[d][1] = max(dp[d-1][0] + cost0, dp[d-1][1] + max(cost0, cost1))
    # Kのd桁目が0だったとき
    else:
        # X=K -> X=K
        dp[d][0] = dp[d-1][0] + cost0
        # X<K -> X<K
        if dp[d-1][1] != -1:
            dp[d][1] = max(dp[d-1][1] + cost0, dp[d-1][1] + cost1)
    

print(max(dp[MAX_DIGIT][0], dp[MAX_DIGIT][1]))



Measured memory_bytes: 15464
#include<iostream>
using namespace std;
int main()
{
  int i,j;
  
  cin>>i>>j;
  	
  if(i>=0 && i<10 &&j>=0 && j<10) {
    
  	cout<<i*j<<endl;
    
  }
  else {
    cout<<"-1"<<endl;
  }
  
}

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

int change[6]={1,5,10,50,100,500};
int cnt;
int n;

int main(){
	while(cin >> n){
		if(!n)break;
		cnt = 0;
		n = 1000-n;
		for( int i = 5; i >= 0; i-- ){
			while(n>=change[i]){
				n-=change[i];
				cnt++;
			}
		}
		cout << cnt << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
import bisect,collections,copy,itertools,math,string
def I(): return int(input())
def S(): return input()
def LI(): return list(map(int,input().split()))
def LS(): return list(input().split())
##################################################
N = I()
T = LI()
M = I()
P = [LI() for _ in range(M)]
temp = sum(T)
for x in P:
    print(temp+x[1]-T[x[0]-1])

Measured memory_bytes: 4532
#include<bits/stdc++.h>
using namespace std;
#define ll long long                                    // long long省略
#define pb push_back                                    // push_back省略
#define mp make_pair                                    // make_pair省略
#define fi first                                        // first省略
#define se second                                       // second省略
#define itn int                                         // int誤字保険
#define count cout                                      // cout誤字保険
#define vecotr vector                                   // vector誤字保険
#define ednl endl                                       // endl誤字保険
#define opt() cin.tie(0); ios::sync_with_stdio(false)   // 入出力速度改善

#define rep(i,l,r) for(ll i=(l);i<(r);i++)               // 範囲[l, r)で刻み1のfor文(順方向)
#define repp(i,l,r,k) for(ll i=(l);i<(r);i+=(k))         // 範囲[l, r)で刻みkのfor文(順方向)
#define rrep(i,l,r) for(ll i=(r-1);i>=(l);i--)           // 範囲[l, r)で刻み1のfor文(逆方向)
#define rrepp(i,l,r,k) for(ll i=(r-1);i>=(l);i-=(k))     // 範囲[l, r)で刻みkのfor文(逆方向)
#define all(x) (x).begin(), (x).end()                   // vectorのポインタ位置指定用
#define max(p,q)((p)>(q)?(p):(q))                       // max拡張
#define min(p,q)((p)<(q)?(p):(q))                       // min拡張
#define bit(n,m)(((n)>>(m))&1)                          // 変数nのm番目のbitを取り出す

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; }

int dy[]={0, 1, 0, -1};                                 // 4方向近傍
int dx[]={1, 0, -1, 0};                                 // 4方向近傍

int main(){
    ll a,b,c; cin>>a>>b>>c;
    if(a<1200) cout << "ABC" << ednl;
    else if(a<2800) cout << "ARC" << ednl;
    else cout << "AGC" << ednl;
}

Measured memory_bytes: 256
def main():
    n = int(input())
    *xs, = map(int, input().split())

    ret = float('inf')
    for p in range(100 + 1):
        t = 0
        for x in xs:
            t += (p - x) ** 2
        ret = min(ret, t)
    print(ret)


if __name__ == '__main__':
    main()

# import sys
#
# sys.setrecursionlimit(10 ** 7)
#
# input = sys.stdin.readline
# rstrip()
# int(input())
# map(int, input().split())


Measured memory_bytes: 2940
#include <iostream>

using namespace std;

int main()
{
    int n,sum=0;
    string s;
    cin>>n>>s;
    for(int i=0;i<s.length();i++){
        if(s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='C'){
            sum++;
        }
    }
    cout<<sum;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define Rep(i, a, b) for(int i = a; i <= b; i++)
#define repr(i, a, b) for(int i = b-1; i >= a; i--)
#define _GLIBCXX_DEBUG
#define Vl vector<ll>
#define Vs vector<string>
#define Vp vector<pair<ll, ll>>
using ll = long long;
#define ALL(v) (v).begin(),(v).end()
#define endl "\n"
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define co(x) cout << x << endl
#define coel cout << endl
#define pb push_back
#define sz(v) ((ll)(v).size())
using namespace std;  
const double pi = acos(-1.0);
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
#define pp pair<ll, pair<ll, ll>> 
#define fi first
#define se second

////////////////////////////////////////////////////////


int main() {
    ll n; cin >> n;
    Vl a(n), b(n);
    rep(i, 0, n) cin >> a[i];
    rep(i, 0, n) cin >> b[i];

    ll s = 0, t = 0;
    rep(i, 0, n){
        if(a[i] < b[i]) s += (b[i] - a[i])/2; // bigger b
        if(a[i] > b[i]) t += a[i] - b[i]; // bigger a
    }
    if(s >= t) co("Yes");
    else co("No");

    return 0;
}




Measured memory_bytes: 3792
#
# abc105 b
#
import unittest
from io import StringIO
import sys


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """11"""
        output = """Yes"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """40"""
        output = """Yes"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """3"""
        output = """No"""
        self.assertIO(input, output)


def resolve():
    N = int(input())
    ans = "No"
    for i in range(N//4+1):
        for j in range(N//7+1):
            if 4*i + 7*j == N:
                ans = "Yes"
                break
    print(ans)


if __name__ == "__main__":
    # unittest.main()
    resolve()


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

int main() {
    int n;
    cin >> n;
    int count = 0;

    for(int i=1;i<n+1;i++){
      for(int j=1;j<n+1;j++){
        for(int k=1;k<n+1;k++){
          count +=__gcd(__gcd(i,j),__gcd(j,k));
        }
      }
    }
  cout << count << endl;
}

Measured memory_bytes: 3468