akhauriyash/Code-Regression huggingface dataset:
import java.io.*;
import java.util.*;
import java.util.function.IntPredicate;

class Main {
    static Scanner scanner = new Scanner();

    static long ans = Long.MAX_VALUE;
    static int n;
    static long[] a, b;
    public static void main(String[]$) {
        n = scanner.nextInt();
        a = new long[n];
        b = new long[n + 1];
        for (int i = 0; i < n; i++) {
            a[i] = scanner.nextInt();
            b[i + 1] = a[i] + b[i];
        }
        for (int m = 2; m < n; m++) {
            long maxL = b[m];
            long maxR = b[n];
            int l = binarySearch(0, m, i -> b[i] * 2 <= maxL);
            int r = binarySearch(m, n, i -> b[i] * 2 <= maxL + maxR);
            f(l, m, r);
            f(l, m, r - 1);
            f(l - 1, m, r);
            f(l - 1, m, r - 1);
        }
        System.out.println(ans);
    }

    static void f(int l, int m, int r) {
        long a1 = b[l];
        long b1 = b[m] - b[l];
        long c1 = b[r] - b[m];
        long d1 = b[n] - b[r];
        ans = Math.min(ans, max(a1, b1, c1, d1) - min(a1, b1, c1, d1));
    }

    static long min(long... a) {
        long n = a[0];
        for (int i = 1; i < a.length; i++) {
            n = Math.min(n, a[i]);
        }
        return n;
    }

    static long max(long... a) {
        long n = a[0];
        for (int i = 1; i < a.length; i++) {
            n = Math.max(n, a[i]);
        }
        return n;
    }

    static int binarySearch(int min, int max, IntPredicate predicate) {
        int ok = min, ng = max;
        while (ng - ok > 1) {
            int mid = (ok + ng) / 2;
            if (predicate.test(mid)) {
                ok = mid;
            } else {
                ng = mid;
            }
        }
        return ng;
    }

    static class Scanner {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in), 1 << 15);
        StringTokenizer tokenizer;

        String next() {
            try {
                while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                    tokenizer = new StringTokenizer(reader.readLine());
                }
            } catch (IOException ignored) {
            }
            return tokenizer.nextToken();
        }

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

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

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

int main() {
    string s;
    while (cin >> s) {
        if (s == "#") break;
        int a, b, c, d;
        cin >> a >> b >> c >> d;
        string mp[30];
        int h = 0;
        for (int i = 0; i < s.size(); i++) {
            if (s[i] == '/') {
                h++;
            } else {
                if (s[i] == 'b') {
                    mp[h] += 'b';
                } else {
                    int num = s[i] - '0';
                    while (num--) mp[h] += '.';
                }
            }
        }
        swap(mp[c - 1][d - 1], mp[a - 1][b - 1]);
        string ans = "";
        for (int i = 0; i <= h; i++) {
            for (int j = 0; j < mp[i].size(); j++) {
                if (mp[i][j] == 'b') {
                    ans += 'b';
                } else {
                    int cnt = 0;
                    while (mp[i][j++] == '.') cnt++;
                    ans += (cnt + '0');
                    j -= 2;
                }
            }
            if(i != h) ans += '/';
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 3232
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>

using namespace std;

#define int long long
#define endl "\n"

constexpr long long INF = (long long)1e18;
constexpr long long MOD = 1'000'000'007; 

string yn(bool f){return f?"Yes":"No";}
string YN(bool f){return f?"YES":"NO";}



signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	const int MAX = 20;
	
	while(true){
		vector<tuple<int,int,int>> nb1, nb2;
		vector<tuple<int,int,int>> val;
		vector<int> np1, np2;
		int R = -1, C = -1, S = -1;
		int p, q;
		
		cin>>p>>q;
		
		if(!p && !q) break;
		
		np1.resize(p+1);
		np2.resize(q+1);
		
		nb1.resize(p+1);
		nb2.resize(q+1);
		
		for(int i = 1; i <= p; i++){
			int a = 0, b = 0, c = 0, j = 0;
			string s;
			
			cin>>s;
			
			for(; j < s.size() && s[j] == '.'; j++) np1[i-1]++;
			for(; j < s.size(); j++){
				if(s[j] == '(') a++;
				if(s[j] == ')') a--;
				if(s[j] == '{')	b++;
				if(s[j] == '}') b--;
				if(s[j] == '[') c++;
				if(s[j] == ']') c--;
			};
			
			nb1[i] = make_tuple(get<0>(nb1[i-1]) + a, get<1>(nb1[i-1]) + b, get<2>(nb1[i-1]) + c);
		}
		
		for(int i = 1; i <= q; i++){
			int a = 0, b = 0, c = 0, j = 0;
			string s;
			
			cin>>s;
			
			for(; j < s.size(); j++){
				if(s[j] == '(') a++;
				if(s[j] == ')') a--;
				if(s[j] == '{')	b++;
				if(s[j] == '}') b--;
				if(s[j] == '[') c++;
				if(s[j] == ']') c--;
			};
			
			nb2[i] = make_tuple(get<0>(nb2[i-1]) + a, get<1>(nb2[i-1]) + b, get<2>(nb2[i-1]) + c);
		}
		
		for(int i = 1; i <= MAX; i++){
			for(int j = 1; j <= MAX; j++){
				for(int k = 1; k <= MAX; k++){
					bool flag = true;
					for(int l = 1; l <= p; l++){
						int np = i * get<0>(nb1[l]) + j * get<1>(nb1[l]) + k * get<2>(nb1[l]);
						
						if(np1[l] != np){
							flag = false;
							break;
						}
					}
					
					if(flag) {
						val.push_back(make_tuple(i,j,k));
					}
				}
			}
		}
		
		for(int i = 0; i < q; i++){
			if(i) cout<<" ";
			
			int num = -1;
			
			for(int j = 0; j < val.size(); j++){
				int temp = 
				get<0>(val[j]) * get<0>(nb2[i]) +
				get<1>(val[j]) * get<1>(nb2[i]) +
				get<2>(val[j]) * get<2>(nb2[i]);
				
				if(num == -1){
					num = temp;
				} else if(temp != num){
					num = -1;
					break;
				}
			}
			
			cout<<num;
		}
		
		cout<<endl;
	}
	
	
	return 0;
}


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

#define FOR(i, m, n) for(int i = m;i < n;i++)
#define ll long long

unsigned GetDigit(unsigned num){
    unsigned digit = 0;
    while(num != 0){
        num /= 10;
        digit++;
    }
    return digit;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n;
	cin >> n;
	ll upper = sqrt(n);
	ll ans = 0;
	FOR(i, 1, upper+1){
		if (n%i==0){
			ans = n/i;
		}
	}
	cout << GetDigit(ans) << endl;
}


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

using namespace std;

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

    int a, b;

    cin >> a >> b;

    int ans = -1;

    for(int i=1; i<=3000000; i++){
        if(i*8/100 == a and i*10/100 == b){
            ans = i;
            break;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
	int size;
	int val[100];
	scanf("%d",&size);
	
	for(int i = 0; i < size; i++){
		scanf("%d",&val[i]);
	}
	
	//sort
	for(int i = 0; i < size; i++){
		int v = val[i];
		for(int u = i - 1; u >= 0 && val[u] > v; u--){
			val[u + 1] = val[u];
			val[u] = v;
		}
		
		//output
		for(int o = 0; o < size - 1; o++){
			printf("%d ",val[o]);
		}
		printf("%d\n",val[size - 1]);
	}
	return 0;
}


Measured memory_bytes: 2056
def BubbleSort(A,N):
    count = 0
    flag = 1
    while flag == 1:
        flag = 0
        for j in range(n-1,0,-1):
            if A[j] < A[j-1]:
                key = A[j]
                A[j] = A[j-1]
                A[j-1] = key
                count += 1
                flag = 1
    L=[str(ai) for ai in A]
    L=" ".join(L)
    print(L)
    return count
    
n = int(input())
a = list(map(int,input().split()))
count = BubbleSort(a,n)
print(count)


Measured memory_bytes: 5604
#include <iostream>
using namespace std;
int main() {
  int A,B,C;
  cin >> A >> B >> C;
  int add_A = A;
  bool broken = false;
  while(A * B  > add_A){
    if (add_A % B == C){
      broken = true;
      break;
    }
    add_A += A;
  }
  if(broken){
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

#n = int(input())
#l = list(map(int, input().split()))

'''
A=[]
B=[]
for i in range():
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)'''
cnt=0
s=list(input())
t = list(input())
if s[0]==t[0]: cnt+=1
if s[1]==t[1]: cnt+=1
if s[2]==t[2]: cnt+=1
print(cnt)

Measured memory_bytes: 3064
al=[list(map(int, input().split())) for _ in range(3)]
bl=[[False]*3 for _ in range(3)]
n=int(input())
for _ in range(n):
    b = int(input())
    for i in range(3):
        for j in range(3):
            if al[i][j] == b: bl[i][j] = True

for i in range(3):
    if all(bl[i]):
        print('Yes')
        exit()

for j in range(3):
    if all([bl[0][j],bl[1][j],bl[2][j]]):
        print('Yes')
        exit()

if all([bl[0][0],bl[1][1],bl[2][2]]) or all([bl[2][0],bl[1][1],bl[0][2]]):
    print('Yes')
    exit()

print('No')

Measured memory_bytes: 62204
#include<iostream>
#include<string>

using namespace std;

int main() {
	string s;

	cin >> s;

	if (s == "ooo") {
		cout << 1000 << endl;
	}

	else if (s == "oox") {
		cout << 900 << endl;
	}

	else if (s == "oxo") {
		cout << 900 << endl;
	}

	else if (s == "xoo") {
		cout << 900 << endl;
	}

	else if (s == "oxx") {
		cout << 800 << endl;
	}

	else if (s == "xox") {
		cout << 800 << endl;
	}

	else if (s == "xxo") {
		cout << 800 << endl;
	}

	else if (s == "xxx") {
		cout << 700 << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a,b;
  cin >> a >> b;
  int m = b;
  if (a < 13) {
    m /= 2;
    if (a < 6) {
      m = 0;
    }
  }
  cout << m << endl;
}

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

int main(void){
  int x,y;
  cin >> x >> y;
  x = x==1 ? x+13 : x;
  y = y==1 ? y+13 : y;
  if(x>y){
    cout <<"Alice" << endl;
  }else if(x==y){
    cout <<"Draw" << endl;
  }else{
    cout << "Bob" << endl;
  }
}

Measured memory_bytes: 256
#include <stdio.h>

#define N 10000
#define Q 501

int LinerSearch(int *, int *, int, int);


int main() {
  int i, n, q, ans;
  int data1[N], data2[Q];


  scanf("%d", &n);

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

  scanf("%d", &q);

  for (i = 0; i < q; i++) {
    scanf("%d", &data2[i]);
  }

  ans = LinerSearch(data1, data2, n, q);
  
  printf("%d\n", ans);
  
  return 0;
  
}


int LinerSearch(int *s, int *t, int n, int q) {
  int i, j, key, count = 0;
  
  for (i = 0; i < q; i++) {
    s[n] = t[i];
    for (j = 0; j <= n; j++) {
      if (j != n && s[j] == t[i]) {
	count++;
	break;
      }
    }
  }

  return count;
}




Measured memory_bytes: 2108
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>
#include <time.h>
#include <tuple>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e12;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1

ll sq(ll num) { return num*num; }
ll mod_pow(ll x, ll n) {
	if (n == 0)return 1;
	if (n == 1)return x%MOD;
	ll res = sq(mod_pow(x, n / 2));
	res %= MOD;
	if (n % 2 == 1) {
		res *= x;
		res %= MOD;
	}
	return res;
}
ll mod_add(ll a, ll b) { return (a + b) % MOD; }
ll mod_sub(ll a, ll b) { return (a - b + MOD) % MOD; }
ll mod_mul(ll a, ll b) { return a*b % MOD; }

int h, w;
int f[1010][1010];
int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };

bool of(int y,int x) {
	return y < 0 || y >= h || x < 0 || x >= w;
}

ll solve(int y, int x, ll cnt) {
	if (f[y][x] == 3)return 0;
	if (cnt >= 10)return INF;
	//cout << y << " " << x << endl;
	ll res = INF;
	rep(i, 4) {
		int nx = x + dx[i];
		int ny = y + dy[i];
		if (of(ny, nx))continue;
		if (f[ny][nx] == 1)continue;
		while (!f[ny][nx]) {
			nx += dx[i];
			ny += dy[i];
			if (of(ny, nx))break;
		}
		if (of(ny, nx))continue;
		bool g = 0;
		if (f[ny][nx] == 1)g = 1;
		if (g) {
			f[ny][nx] = 0;
			nx -= dx[i];
			ny -= dy[i];
		}
		res = min(solve(ny, nx, cnt + 1) + 1, res);
		if (g) {
			nx += dx[i];
			ny += dy[i];
			f[ny][nx] = 1;
		}
		//cout << res << endl;
	}
	return res;
}

int main() {
	while (cin >> w >> h&&h + w) {
		int sy, sx;
		rep(i, h) {
			rep(j, w) {
				cin >> f[i][j];
				if (f[i][j] == 2) {
					sy = i;
					sx = j;
					f[i][j] = 0;
				}
			}
		}
		ll res = solve(sy, sx, 0);
		if (res == INF)cout << -1 << endl;
		else cout << res << endl;
	}
}


Measured memory_bytes: 3152
#include <bits/stdc++.h>
typedef long long ll;

using namespace std;

const ll inf=998244353;
int num[200005];
int main()
{
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
        scanf("%d",&num[i]);
    ll ans=0;
    for(int i=1;i<n;i++)
    {
        if(num[i]-num[i-1]<0)
        {
            ans+=num[i-1]-num[i];
            num[i]=num[i-1];
        }
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 4540
int main()
{
  int i,n,l;
  scanf("%d%d", &n, &l);
  int sum=0;
  for (i = 0; i < n; i++) {
    sum+=l+i;
  }
  if(l<=0 && l+n-1>=0){
    printf("%d\n", sum);
  }else if(l>0){
    printf("%d\n", sum-l);
  }else{
    printf("%d\n", sum-(l+n-1));
  }
  return 0;
}

Measured memory_bytes: 128
n, m = map(int, input().split())
if n*2 < m:
    while n*2 <= m:
        if m - 2*n > 100000:
            m -= 60000
            n += 30000
        elif m - 2*n > 10000:
            m -= 6000
            n += 3000
        else:
            m -= 2
            n += 1
    print(n - 1)
else:
    print(m//2)

Measured memory_bytes: 64172
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<numeric>
#include<algorithm>
#include<complex>
#include<queue>
#include<stdlib.h>
#include<map>
#include<cmath>
#include<stdio.h>
#include<stdlib.h>
#include<set>

#define ll long long int
#define MOD 1000000007
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define mp make_pair

using namespace std;

int main(){
    int N;
    cin >> N;
    vector<vector<int>> vec(N,vector<int>(3));
    for(int i=0;i<N;i++){
        cin >> vec[i][0] >> vec[i][1] >> vec[i][2];
    }
    int dp[N+1][3];
    dp[0][0]=vec[0][0];
    dp[0][1]=vec[0][1];
    dp[0][2]=vec[0][2];
    for(int i=1;i<N;i++){
        for(int j=0;j<3;j++){
            dp[i][j]=max(dp[i-1][(j+1)%3]+vec[i][j],dp[i-1][(j+2)%3]+vec[i][j]);
        }
    }
    cout << max({dp[N-1][0],dp[N-1][1],dp[N-1][2]}) << endl;
    return 0;
}


Measured memory_bytes: 6912
#include <iostream>

using namespace std;

int main()
{
    int a,b,ans;
    char op;

    cin >> a >> op >> b;

    while(op!='?'){
        switch(op){
            case '+':
                ans = a + b;
                break;
            case '-':
                ans = a - b;
                break;
            case '*':
                ans = a*b;
                break;
            case '/':
                ans = a/b;
                break;
        }

        cout << ans <<endl;
        cin >> a >> op >> b;
    }

    return 0;
}



Measured memory_bytes: 3092
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<queue>
#include<map>
#include<string>
#include<cassert>
#include<numeric>
#define all(x) (x).begin(),(x).end()
#define print(x) cout << (x) << endl
typedef long long ll;
typedef long double ld;
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
 
using namespace std;

int main(){
    string s;   cin >> s;
    int Q;  cin >> Q;
    int p = 0;
    for(int i=0; i<Q; i++){
        int t;  cin >> t;
        if(t == 1) p++;
        else{
            int f;  string c;   cin >> f >> c;
            if(f == 1){
                if(p%2 == 0)    s = c + s;
                else    s += c;
            }else{
                if(p%2 == 0)    s += c;
                else    s = c + s;
            }
        }
    }
    if(p%2 == 1)    reverse(all(s));
    print(s);
}

Measured memory_bytes: 4616
#include <iostream>
#include <vector>

using namespace std; 

int main(void) {
	int size;
	cin >> size;
	vector<int> key(size);
	for (int i = 0; i < size; ++i) {
		cin >> key[i];
	}
	for (int i = 0; i < size; ++i) {
		cout << "node " << i+1 << ": ";
		cout << "key = " << key[i] << ", ";
		if (i > 0) {
			cout << "parent key = " << key[(i-1)/2] << ", ";
		}
		if (((2*i)+1) < size) {
			cout << "left key = " << key[(2*i)+1] << ", ";
		}
		if (((2*i)+2) < size) {
			cout << "right key = " << key[(2*i)+2] << ", ";
		}
		cout << endl;
	}
	return 0;
}



Measured memory_bytes: 3096
#include <bits/stdc++.h>
using namespace std;
int l=200000,n,m,s[200000],a;
int main(void){
    cin>>n>>m;
    for(int i=0;i<n;i++){
        cin>>a;
        s[a]++;
    }
    sort(s,s+l);
    reverse(s,s+l);
    for(int i=0;i<m;i++){
        n-=s[i];
    }
    cout<<n<<endl;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define INF 100000000
using namespace std;
int cnt = 0;
int divide(string num){
  int result = 0;
  for(int i=1; i<num.size(); i++){
    int left = atoi(num.substr(0,i).c_str());
    int right = atoi(num.substr(i,num.size()-i).c_str());
    //cout << left << " " << right << endl;
    result = max(result,left*right);
    //cout << result << endl;
  }
  cnt++;
  if(result>=10) return divide(to_string(result));
  else if(cnt==INF) return -1;
  else return 1;
}
int main(){
  int n;
  cin >> n;
  string num;
  rep(i,n){
    cin >> num;
    cnt = 0;
    if(atoi(num.c_str()) <= 9) cout << 0 << endl;
    else if(divide(num) == 1) cout << cnt << endl;
    else cout << -1 << endl;
  }
  return 0;
}


Measured memory_bytes: 3280
#!/usr/bin/env python
# coding: utf-8

from collections import Counter
def ri():
    return int(input())

def rl():
    return list(input().split())

def rli():
    return list(map(int, input().split()))

def main():
    n = ri()
    ls = Counter()
    for i in range(n):
        s = input()
        ls[s] += 1
    m = -1
    ans = []
    for k, c in ls.most_common():
        if m == -1:
            m = c
        if c < m:
            break
        ans.append(k)
    ans.sort()
    for s in ans:
        print(s)


if __name__ == '__main__':
    main()


Measured memory_bytes: 43564
s = list(input())
k = int(input())
count = 0
s1 = list(set(s))
if len(s1) == 1:
    count = int((k * len(s)) / 2)
elif k >= 3:
    t1 = s * 5
    for i in range(len(t1) - 1):
        if t1[i] == t1[i + 1]:
            t1.pop(i + 1)
            t1.insert(i + 1, "")
            count += 1
    if count % 5 == 0:
        count = (count / 5) * k
    elif (count + 1) % 5 == 0:
        count = ((count + 1) / 5) * k - 1
    else:
        count = ((count + 2) / 5) * k - 2
else:
    t1 = s * k
    for i in range(len(t1) - 1):
        if t1[i] == t1[i + 1]:
            t1.pop(i + 1)
            t1.insert(i + 1, "")
            count += 1
print(int(count))


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

typedef long long ll;
typedef string st;
typedef vector<int> vi;
typedef vector<st> vs;
#define rep(i, n) for(int i = 0; i < n; i++)
#define fogg(i,a,b) for(int i = (a); i <= (b); i++)
#define ford(i,a,b) for(int i = (a); i >= (b); i--)
#define test int t; cin >> t; while(t--)
#define debug(x) cout << '>' << #x << ':' << x << "\n";
#define endl '\n'
#define pb push_back
#define gp " "
#define ff first
#define ss second
#define mp make_pair



int main() {
	
	int n;
	cin >> n;
	ll sum=0;
	for(int i=1;i<=n;i++) {
		if(i%3==0 || i%5==0) {
			continue;
		}
		sum+=i;
	}

	cout << sum;
	return 0;
}

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

void counting_sort(int A[], int B[], int k, int n){
    int C[k+1] = {};
    for (int i = 0; i < n; i++) {
        C[A[i]]++;
    }
    for (int i = 1; i <= k; i++) {
        C[i] += C[i-1];
    }
    for (int i = n - 1; i >= 0; i--) {
        B[C[A[i]] - 1] = A[i];
        C[A[i]]--;
    }
}

int main(){
    int n;
    cin >> n;
    int A[n];
    int B[n];
    int k = 0;
    for (int i = 0; i < n; i++) {
        cin >> A[i];
        if (k < A[i]) k = A[i];
    }
    counting_sort(A, B, k, n);
    cout << B[0];
    for (int i = 1; i < n; i++) {
        cout << " " << B[i];
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 18696
n,l = map(int, input().split(' '))
apples = []
for i in range(1, n+1):
  apples.append(l + i - 1)
pie = sum(apples)
for i in range(n):
  partial = pie - apples[i]
  if i == 0:
    diff = abs(pie - partial)
    ans = pie - partial
  else:
    d = abs(pie - partial)
    if d < diff:
      diff = d
      ans = pie - partial
print(pie - ans)

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

int main(){
  int n;
  cin >> n;
  vector<int> d(n);
  for(int i=0;i<n;i++){
    cin >> d[i];
  }
  int sum=0;
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      if(j>i){
        sum+=d[i]*d[j];
      }
    }
  }
  cout << sum << endl;
}


Measured memory_bytes: 256
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <queue>
#include <iterator>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned long long ULL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

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

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

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int gcd(int a, int b){
   int tmp;
   while(a%b!=0){
      tmp=a%b;
      a=b;
      b=tmp;
   }
}

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

bool prime_number(int n){
   if(n==0||n==1) return false;
   vector<bool> a(n+1);
   fill(ALL(a),true);
   FOR(i,2,n/2+1){
      if(!a[i]) continue;
      for(int j=2;i*j<=n;j++){
         a[i*j]=false;
      }
   }
   return a[n];
}

int main(){
   VI a,b;
   int x;
   
   REP(i,10){
      cin >> x;
      a.PB(x);
   }
   REP(i,10){
      cin >> x;
      b.PB(x);
   }
   sort(ALL(a)); sort(ALL(b));
   cout << a[7]+a[8]+a[9] << " " << b[7]+b[8]+b[9] << endl;
}

Measured memory_bytes: 1216
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,string>;
using Map = map<string,ll>;




int main(){
ll N;
cin >> N;
Map a;
string S;
for(int i=0;i<N;i++){
    cin>>S;
    if(a.count(S)){a[S]++;}
    else a[S]=1
;}
ll Max=0;
for(auto p:a){
    Max=max(p.second,Max);
}
vector<string> ans(0);
for(auto p:a){
    if(p.second==Max){ans.emplace_back(p.first);}
;}
sort(ans.begin(), ans.end());
for(auto p:ans){
    cout<<p<<endl
;}

return 0;
}  



Measured memory_bytes: 26868
/* *
 *
 * Author: Hamkor
 *
 * */
 
#include <bits/stdc++.h>

using namespace std;

/* * * *   * * *   	* * * */
#define ll long long
#define ld long double
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define VI vector<int>
#define VII vector<pair<int, int>>
#define VLL vector<pair<ll, ll>>
#define PB push_back()
#define B begin()
#define E end()
#define F first
#define S second
#define SZ size()
#define P complex <ll> 
#define X real()
#define Y imag()
const int oo = 1e9;
const ll mod = 1e7;
/* * * *   * * *   	* * * */

int main(){
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int n, m; cin>>n>>m;
	vector<vector<int>> a (n+1, vector<int>());
	VI p(1e5 + 10), y (1e5 + 10);
	for (int i=0; i<m; ++i){
		cin>>p[i]>>y[i];
		a[p[i]].push_back(y[i]);
	}
	for (int i=1; i<=n; ++i) sort(a[i].B, a[i].E);
	for (int i=0; i<m; ++i){
		cout<<right<<setw(6)<<setfill('0')<<p[i];
		int j = lower_bound(a[p[i]].B, a[p[i]].E, y[i]) - a[p[i]].B + 1;
		cout<<right<<setw(6)<<setfill('0')<<j<<"\n";
	}
	return 0;
}


Measured memory_bytes: 7808
#include <stdio.h>

int main()
{
    int N;
    scanf("%d",&N);
    int P[N];

    for (int i=0;i<N;i++) {
        scanf("%d",&P[i]);
    }
    int count=1;
    int c=P[0];
    for (int i=1;i<N;i++) {
        if (P[i]<=c) {
        c=P[i];
        count++;
        }
    }
    printf("%d",count);

    return 0;
}

Measured memory_bytes: 896
// Date: 2020-05-30

#include <bits/stdc++.h>
using namespace std;

typedef long long LL;
typedef long double LD;
typedef vector<int> VI;
typedef pair<LL, LL> pll;
typedef pair<int, int> pii;
#define IO freopen("in.txt", "r", stdin);freopen("out.txt", "w", stdout)
#define FIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define rep(i, a, b) for(int i = int(a); i <= int(b); ++i)
#define per(i, b, a) for(int i = int(b); i >= int(a); --i)
#define D(x) cout << #x << " = " << x << endl;
#define mem(x, y) memset(x, y, sizeof(x))
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)x.size())
#define mk make_pair
#define pb push_back
#define fi first
#define se second
const LL INF = 1e18;
const LL mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const int N = 2e5 + 10;
template <typename T> void chkmax(T &x, T y) { x = max(x, y); }
template <typename T> void chkmin(T &x, T y) { x = min(x, y); }
LL qpow(LL x, LL y, LL MOD) {LL a=1; while(y){ if(y&1) a=a*x%MOD; x=x*x%MOD; y>>=1; } return a;}

int main() {
    int h1, m1, h2, m2, k;
    cin >> h1 >> m1 >> h2 >> m2 >> k;
    int val = m2 + 60 - m1, gap = h2-h1-1;
    int ans = gap * 60 + val;
    cout << ans-k;


    return 0;
}

Measured memory_bytes: 3636
import Data.List

f3 :: String -> String
f3 str
   |((head str)=='#') && ((length str)>1) =replicate (length str) 'b'
   |otherwise=str

f2 ::String->String
f2 str=concat $ map f3 $ group str


f :: [String]->[String]
f []=[]
f (x:xs)=f2 x : f xs

main = do
      x<-getLine
      y<-getContents
      let z=lines y
          z2=transpose z
          z3=f z
          z4=transpose (f z2)
          (h:w:[])=map read (words x)::[Int]
      putStrLn $ if (length [1 | y<-[0..(h-1)],x<-[0..(w-1)],z !! y !! x=='#',z3 !! y !! x=='#',z4 !! y !! x=='#'])>0 then "No" else "Yes"

Measured memory_bytes: 1276
#include "bits/stdc++.h"
using namespace std;
int main() {
	int H, W;
	cin >> H >> W;
	vector<vector<char>>A(H, vector<char>(W));
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			cin >> A.at(i).at(j);
		}
	}
	vector<vector<bool>>Paint(H, vector<bool>(W, false));
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			if (A.at(i).at(j) == '.') {
				Paint.at(i).at(j) = true;
				continue;
			}
			if (j != W - 1) {
				if (A.at(i).at(j) == '#' && A.at(i).at(j + 1) == '#') {
					Paint.at(i).at(j) = true;
					Paint.at(i).at(j + 1) = true;
				}
			}
			if (j != 0) {
				if (A.at(i).at(j) == '#' && A.at(i).at(j - 1) == '#') {
					Paint.at(i).at(j) = true;
					Paint.at(i).at(j - 1) = true;
				}
			}
			if (i != 0) {
				if (A.at(i).at(j) == '#' && A.at(i - 1).at(j) == '#') {
					Paint.at(i).at(j) = true;
					Paint.at(i - 1).at(j) = true;
				}
			}
			if (i != H - 1) {
				if (A.at(i).at(j) == '#' && A.at(i + 1).at(j) == '#') {
					Paint.at(i).at(j) = true;
					Paint.at(i + 1).at(j) = true;
				}
			}
		}
	}
	bool finish = true;
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			if (!Paint.at(i).at(j)) {
				finish = false;
			}
		}
	}
	if (finish) cout << "Yes" << endl;
	else cout << "No" << endl;
}

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

int main()
{
	long long int a,b,c,n,d;
	cin>>a>>b>>c>>d;
	
	if((a+b)-d>=0)
	{
		cout<<min(a,d);
	}
	else
	{
		cout<<((2*a)+b-d);
	}
	
	return 0;
}

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

using namespace std;

#define int long long

typedef long long li;
typedef long double ld;

void solve();

int32_t main () {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout << fixed << setprecision(20);
	#ifdef LOCAL
		freopen("input.txt", "r", stdin);
	#endif
	solve();
	return 0;
}

void solve() {
	int r, d, x;
	cin >> r >> d >> x;
	for (int i = 1; i <= 10; ++i) {
		x = r * x - d;
		cout << x << endl;
	}
}

Measured memory_bytes: 256
{-# LANGUAGE BangPatterns #-}
import           Control.Exception           (assert)
import           Control.Monad
import           Control.Monad.Primitive
import qualified Control.Monad.ST            as ST
import qualified Data.Array.IO               as IO
import qualified Data.Array.ST               as ST
import qualified Data.Array.Unboxed          as A
import           Data.Bits
import qualified Data.ByteString.Char8       as BS
import           Data.Char
import           Data.Foldable
import           Data.List
import qualified Data.Map.Strict             as Map
import           Data.Maybe
import qualified Data.Sequence               as Seq
import qualified Data.Set                    as Set
import qualified Data.Vector                 as VB
import qualified Data.Vector.Mutable         as VBM
import qualified Data.Vector.Unboxed         as V
import qualified Data.Vector.Unboxed.Mutable as VM
import           Debug.Trace

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine
getIntVec n = V.unfoldrN n (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine

readInteger = fst . fromJust . BS.readInteger
readIntegerList = map readInteger . BS.words
getInteger = readInteger <$> BS.getLine
getIntegerList = readIntegerList <$> BS.getLine

inf :: Int
inf = 10^18

main = do
  n <- getInt
  as <- getIntVec n

  let solve i x y z res
        | i == n = res
        | otherwise =
          let a = as V.! i
              t = length $ filter (== a) [x, y, z]
              (x', y', z') | x == a = (x+1, y, z)
                           | y == a = (x, y+1, z)
                           | z == a = (x, y, z+1)
                           | otherwise = (x, y, z)
              res' = res * t `mod` 1000000007
          in solve (i+1) x' y' z' res'

  print $ solve 0 0 0 0 1

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

struct UnionFind {
private:
	std::vector<int> value;
public:
	UnionFind(int size): value(size, -1){}
	int find(int x){
		return value[x] < 0 ? x : value[x] = find(value[x]);
	}
	int size(int x){
		return -value[find(x)];
	}
	bool same(int x, int y){
		return find(x) == find(y);
	}
	bool unite(int x, int y){
		if ((x = find(x)) == (y = find(y))) return false;
		if (value[x] > value[y]) std::swap(x, y);
		value[x] += value[y];
		value[y] = x;
		return true;
	}
};

using namespace std;

struct Edge {
	int src, dst;
	double cost;
	Edge(){}
	Edge(int src, int dst, double cost): src(src), dst(dst), cost(cost){}
};

int n, m;
int x[10000], y[10000];
vector<Edge> es;

int main()
{
	scanf("%d %d", &n, &m);
	for (int i = 0; i < n; i++){
		scanf("%d %d", x + i, y + i);
	}
	for (int i = 0; i < m; i++){
		int s, t;
		scanf("%d %d", &s, &t); --s; --t;
		double d = sqrt((x[s] - x[t]) * (x[s] - x[t]) + (y[s] - y[t]) * (y[s] - y[t]));
		es.push_back(Edge(s, t, d));
	}
	
	sort(begin(es), end(es), [](const Edge &a, const Edge &b){return a.cost > b.cost;});
	UnionFind uf(n);
	double res = 0;
	for (auto &e : es){
		if (!uf.unite(e.src, e.dst)) res += e.cost;
	}
	printf("%.20f\n", res);
	return 0;
}

Measured memory_bytes: 1852
#include<bits/stdc++.h>
using namespace std;
typedef int ll;
const ll MAXN=5e5+51;
ll cnt,x;
double res,sum;
double prob[MAXN];
inline ll read()
{
    register ll num=0,neg=1;
    register char ch=getchar();
    while(!isdigit(ch)&&ch!='-')
    {
        ch=getchar();
    }
    if(ch=='-')
    {
        neg=-1;
        ch=getchar();
    }
    while(isdigit(ch))
    {
        num=(num<<3)+(num<<1)+(ch-'0');
        ch=getchar();
    }
    return num*neg;
} 
int main()
{
	cnt=read(),x=read();
	for(register int i=0;i<cnt;i++)
	{
		prob[i]=1.0*(1+read())/2;
	}
	for(register int i=0;i<x;i++)
	{
		sum+=prob[i];
	}
	res=sum;
	for(register int l=1,r=x;r<cnt;l++,r++)
	{
		sum=sum+prob[r]-prob[l-1];
		res=max(res,sum);
	}
	printf("%.12lf\n",res);
}

Measured memory_bytes: 1792
#include <stdio.h>

int main() {
  int n,T;
  scanf("%d %d",&n,&T);
  int min=1001;
  for (int i = 0; i < n; i++) {
    int c,t;
    scanf("%d %d",&c,&t);
    if (t <= T && min > c) min = c;
  }
  if (min > 1000) {
    printf("TLE\n");
    return 0;
  }
  printf("%d\n",min);
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
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; }

#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { INIT(){
  cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;

int N, K;
vector<int> A(N);
vector<int> dp(100100, -1);
bool dfs(int n){
  if(n < 0) return false;
  if(dp[n] != -1) return dp[n];

  bool ret = true;
  REP(i, N){
    if(dfs(n-A[i])) ret = false;
  }

  return dp[n] = ret;
}

signed main() {
  cin >> N >> K;

  A.resize(N);
  REP(i, N) cin >> A[i];

  if(!dfs(K)) cout << "First" << "\n";
  else cout << "Second" << "\n";

  return 0;
}

Measured memory_bytes: 5760
n = int(input())
D = [list(map(int, input().split())) for _ in range(n)]

cnt = 0
for d1, d2 in D:
  if d1 == d2:
    cnt += 1
  else:
    cnt = 0
  if cnt >= 3:
    print("Yes")
    exit()
print("No")

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

namespace program
{
    class Program
    {
        static void Main()
        {
          int res=0;
          res += Math.Min(Input.ScanInt(),Input.ScanInt());
          res += Math.Min(Input.ScanInt(),Input.ScanInt());
          Console.WriteLine(res);
        }
    }

    static class Input
    {
        static public int ScanInt() { return int.Parse(Console.ReadLine()); }
        static public uint ScanUint() { return uint.Parse(Console.ReadLine()); }
        static public double ScanDouble() { return double.Parse(Console.ReadLine()); }
        static public long ScanLong() { return long.Parse(Console.ReadLine()); }
        static public ulong ScanUlong() { return ulong.Parse(Console.ReadLine()); }
        static public int[] ScanIntArray() { return Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); }
        static public uint[] ScanUintArray() { return Console.ReadLine().Split(' ').Select(x => uint.Parse(x)).ToArray(); }
        static public double[] ScanDoubleArray() { return Console.ReadLine().Split(' ').Select(x => double.Parse(x)).ToArray(); }
        static public long[] ScanLongArray() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray(); }
        static public ulong[] ScanUlongArray() { return Console.ReadLine().Split(' ').Select(x => ulong.Parse(x)).ToArray(); }

        static public string ScanStr() { return Console.ReadLine(); }
        static public string[] ScanStrArray() { return ScanStr().Split(' '); }
    }

    static class MyMath
    {
        public static int GCD(int a, int b)
        {
            Func<int, int, int> gcd = null;
            gcd = (x, y) => y == 0 ? x : gcd(y, x % y);
            return a > b ? gcd(a, b) : gcd(b, a);
        }
        public static ulong GCD(ulong a, ulong b)
        {
            Func<ulong, ulong, ulong> gcd = null;
            gcd = (x, y) => y == 0 ? x : gcd(y, x % y);
            return a > b ? gcd(a, b) : gcd(b, a);
        }
        public static int LCM(int a, int b)
        {
            return a * b / GCD(a, b);
        }
        public static ulong LCM(ulong a, ulong b)
        {
            return a * b / GCD(a, b);
        }
    }
}


Measured memory_bytes: 13140
#include <cstring>
#include <iostream>
using namespace std;
int field[21][21];

bool check() {
	for (int i = 0; i <= 20; i++) {
		for (int j = 0; j <= 20; j++) {
			if (field[i][j]) return 0;
		}
	}
	return 1;
}

int main () {
	int n;
	while (cin >> n, n) {
		memset(field, 0, sizeof(field));
		for (int i = 0; i < n; i++) {
			int x, y;
			cin >> x >> y;
			field[x][y] = 1;
		}
		int rx = 10, ry = 10, m;
		cin >> m;
		for (int i = 0; i < m; i++) {
			char d;
			int l, dx, dy;
			cin >> d >> l;
			switch (d) {
			case 'N': dx = 0, dy = +1; break;
			case 'E': dx = +1, dy = 0; break;
			case 'S': dx = 0, dy = -1; break;
			case 'W': dx = -1, dy = 0; break;
			}
			for (int j = 0; j < l; j++) {
				rx += dx; ry += dy;
				field[rx][ry] = 0;
			}
		}
		cout << (check() ? "Yes" : "No") << endl;
	}
	return 0;
}

Measured memory_bytes: 1148
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Queue;
import java.util.Set;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] sa = br.readLine().split(" ");
		int n = Integer.parseInt(sa[0]);
		List<List<Hen>> list = new ArrayList<>(n);
		for (int i = 0; i < n; i++) {
			list.add(new ArrayList<>());
		}
		Hen[] arr = new Hen[n - 1];
		for (int i = 0; i < n - 1; i++) {
			sa = br.readLine().split(" ");
			int a = Integer.parseInt(sa[0]) - 1;
			int b = Integer.parseInt(sa[1]) - 1;
			Hen h = new Hen(a, b);
			arr[i] = h;
			list.get(a).add(h);
			list.get(b).add(h);
		}
		br.close();

		int k = 0;
		boolean[] visit = new boolean[n];
		Queue<Integer> que = new ArrayDeque<>();
		que.add(0);
		visit[0] = true;
		while (!que.isEmpty()) {
			int cur = que.poll();
			Set<Integer> set = new HashSet<>();
			for (Hen h : list.get(cur)) {
				set.add(h.c);
			}
			int i = 1;
			for (Hen h : list.get(cur)) {
				if (h.c == 0) {
					for ( ; i < n; i++) {
						if (!set.contains(i)) {
							h.c = i;
							set.add(i);
							k = Math.max(k, i);
							break;
						}
					}
					if (cur == h.a && !visit[h.b]) {
						que.add(h.b);
						visit[h.b] = true;
					} else if (cur == h.b && !visit[h.a]) {
						que.add(h.a);
						visit[h.a] = true;
					}
				}
			}
		}

		System.out.println(k);
		for (int i = 0; i < arr.length; i++) {
			System.out.println(arr[i].c);
		}
	}

	static class Hen {
		int a, b, c;

		public Hen(int a, int b) {
			this.a = a;
			this.b = b;
		}
	}
}


Measured memory_bytes: 71256
K, N = map(int, input().split())
 
A_list = list(map(int, input().split()))

distance = []
diff = 0

for i in range(0, N):
    
    if i == N-1:
        diff = K + A_list[0] - A_list[i]
        distance.append(diff)
        
    else:
        diff = A_list[i+1] - A_list[i]
        distance.append(diff)
        

print(sum(distance) - max(distance))

Measured memory_bytes: 26444
#include <iostream>

using namespace std;

int main ( void )
{
  int sum[2] = { 0 };

  for ( int i = 0, x; i < 8; ++i )
  {
     cin >> x;
     sum[i/4] += x;
  }

  if ( sum[0] > sum[1] )
    cout << sum[0] << endl;
  else
    cout << sum[1] << endl;

  return 0;
}

Measured memory_bytes: 1160
N, K = map(int, input().split())
A = list(map(int, input().split()))

L = len(bin(max(max(A), K))[2:])
B = list(map(lambda x: "0"*(L-len(bin(x)[2:]))+bin(x)[2:], A))
#print(B)

answer = 0
for i in range(L):
  cnt = 0
  for j in range(N):
    if B[j][i] == "0":
      cnt += 1
  if cnt > N - cnt and 2**(L-i-1) <= K:
    K -= 2**(L-i-1)
    answer += 2**(L-i-1) * cnt
  else:
    K -= 0
    answer += 2**(L-i-1) * (N - cnt)
print(answer)  

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

#define ED return 0;
#define UP(a,b) ((a+(b-1))/b)
#define SORT(vec) sort(vec.begin(),vec.end());
#define DOUBLECHANGE(count) cout << setprecision(count);
#define REV(vec) reverse(vec.begin(),vec.end());
#define ipow(x,y) long(pow(x,y))
const long long mod = 1000000007;

void check(int island, vector<vector<bool>> vec,vector<bool> &checked,int N){
    for(int i = 0;i < N;i++){
        if(vec[island][i] == true && checked.at(i) == false){
            checked.at(i) = true;
            check(i,vec,checked,N);
        }
    }
    return;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, M;
    cin >> N >> M;
    vector<vector<bool>> vec (N,vector<bool>(N,false));
    vector<pair<int,int>> bridge (M,pair<int,int> (0,0));
    for(int i = 0;i < M;i++){
        int a, b;
        cin >> a >> b;
        bridge.at(i).first = a-1;
        bridge.at(i).second = b-1;
        vec[a-1][b-1] = true;
        vec[b-1][a-1] = true;
    }
    int ans = 0;
    for(int i = 0;i < M;i++){
        vector<bool> checked (N,false);
        vec[bridge.at(i).first][bridge.at(i).second] = false;
        vec[bridge.at(i).second][bridge.at(i).first] = false;
        check(0,vec,checked,N);
        bool ok = true;
        for(int i = 0;i < N;i++){
            if(checked.at(i) == false){
                ok = false;
                break;
            }
        }
        if(!ok){
            ans++;
        }
        vec[bridge.at(i).first][bridge.at(i).second] = true;
        vec[bridge.at(i).second][bridge.at(i).first] = true;
    }
    cout << ans << endl;
}


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

using namespace std;
typedef long long ll;

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

    std::priority_queue<double, std::vector<double>, std::greater<double> > nums;

    for(int i=0; i < n; i++) {
        double val;
        cin >> val;
        nums.push(val);
    }

    while(nums.size() >= 2) {
        double a = nums.top();
        nums.pop();
        double b = nums.top();
        nums.pop();

        nums.push((a+b)/2);
    }

    cout << nums.top();
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
#define M 1001
struct edge{int to;double cost;};
typedef double D;
typedef complex<D> P;
const D EPS = 1e-9; 
#define X real()
#define Y imag()
D dot(P a, P b) {return (conj(a)*b).X; }
D cross(P a, P b) {  return (conj(a)*b).Y;}
int ccw(P a, P b, P c) {
  b-=a;c-=a;
  if (cross(b,c) >  EPS) return +1;
  if (cross(b,c) < -EPS) return -1;
  if (dot(b,c)   < -EPS) return +2;  
  if (norm(b) < norm(c)) return -2; 
  return 0;
}
bool isecSS(P a1, P a2, P b1, P b2) {
  return ccw(a1,a2,b1)*ccw(a1,a2,b2)<=0&&ccw(b1,b2,a1)*ccw(b1,b2,a2)<=0;
}
double dist(P a,P b){
  return sqrt((a.X-b.X)*(a.X-b.X)+(a.Y-b.Y)*(a.Y-b.Y));
}
int na,nb;
typedef pair<int,double> PE;
double ax[M],ay[M],bx[M],by[M];
vector<edge>v[2][M];
edge tmp;
double dij(int x){
  double d[M];
  r(i,M)d[i]=1e8;
  priority_queue<PE,vector<PE>,greater<PE> >q;
  q.push(PE(0,0));
  d[0]=0;
  while(!q.empty()){
    PE p=q.top();q.pop();
    int t=p.first;
    double co=p.second;
    if(d[t]<co)continue;
    r(i,v[x][t].size()){
      tmp=v[x][t][i];
      int tot=v[x][t][i].to;
      double co2=v[x][t][i].cost;
      if(d[tot]>co2+co){
        d[tot]=co2+co;
        q.push(PE(tot,co2+co));
      }
    }
  }
  return d[1];
}
int main(){
  cin>>na>>nb;
  r(i,na)cin>>ax[i]>>ay[i];
  r(i,nb)cin>>bx[i]>>by[i];
  r(i,na)r(j,na)if(!isecSS(P(ax[i],ay[i]),P(ax[j],ay[j]),P(bx[0],by[0]),P(bx[1],by[1]))){
    tmp.to=j,tmp.cost=dist(P(ax[i],ay[i]),P(ax[j],ay[j]));
    v[0][i].push_back(tmp);
  }
  r(i,nb)r(j,nb)if(!isecSS(P(bx[i],by[i]),P(bx[j],by[j]),P(ax[0],ay[0]),P(ax[1],ay[1]))){
    tmp.to=j,tmp.cost=dist(P(bx[i],by[i]),P(bx[j],by[j]));
    v[1][i].push_back(tmp);
  }
  double a2=dist(P(ax[0],ay[0]),P(ax[1],ay[1]));
  double b2=dist(P(bx[0],by[0]),P(bx[1],by[1]));
  double a1=dij(0),b1=dij(1);
  if(a1==1e8&&b1==1e8)cout<<(-1)<<endl;
  else if(a1+b2<b1+a2)printf("%.9f\n",a1+b2);
  else printf("%.9f\n",a2+b1);
}

Measured memory_bytes: 34892
#include<bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
int A[60][60];
int B[60][60];
int x,y;
int dx[4]={0,0,1,-1};
int dy[4]={1,-1,0,0};
int dfs(int x,int y){
    A[x][y]=3;
    int ans=0;
    REP(i,4){
        int xx=dx[i]+x;
        int yy=dy[i]+y;
        if(A[xx][yy]==0){
           ans+=dfs(xx,yy);
        }
    }
    return ans+1;
}

int dfs2(int x,int y){
    B[x][y]=3;
    int ans=0;
    REP(i,4){
        int xx=dx[i]+x;
        int yy=dy[i]+y;
        if(B[xx][yy]==0){
           ans+=dfs2(xx,yy);
        }
    }
    return ans+1;
}

int main(){
    int W,H;
    while(cin>>W>>H,W+H){
        REP(i,60){
            REP(j,60){
                A[i][j]=1;
                B[i][j]=1;
            }
        }
        REP(i,H){
            string s;
            cin>>s;
            REP(j,W){
                if(s[j]=='.'){
                   A[i+1][j+1]=0;
                   B[i+1][j+1]=0;
                }
                if(s[j]=='B'){
                   A[i+1][j+1]=2;
                }
                if(s[j]=='W'){
                   B[i+1][j+1]=2;
                }
            }
        }
        REP(i,H+1){
            REP(j,W+1){
                if(A[i][j]==2){
                   REP(k,4){
                       int x=i+dx[k];
                       int y=j+dy[k];
                       if(A[x][y]==0){
                          dfs(x,y);
                       }
                   }
                }
            }
        }
        REP(i,H+1){
            REP(j,W+1){
                if(B[i][j]==2){
                   REP(k,4){
                       int x=i+dx[k];
                       int y=j+dy[k];
                       if(B[x][y]==0){
                          dfs2(x,y);
                       }
                   }
                }
            }
        }
        int w=0;
        int b=0;
        REP(i,H+1){
            REP(j,W+1){
                if(A[i][j]==3&&B[i][j]!=3)b++;
                if(A[i][j]!=3&&B[i][j]==3)w++;
            }
        }
        cout<<b<<" "<<w<<endl;
    }
    return 0;
}

Measured memory_bytes: 3176
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0; i<(n); i++)
vector<int> num(1000);
void divisor(int n){
  for(int i=2; i<=n; i++){
    int cnt = 0;
    while(n%i==0){
      cnt++;
      n /= i;
    }
    num[i] += cnt;
  }
  return;
}
int main() {
  int n;
  cin >> n;
  for(int i=1; i<=n; i++){
    divisor(i);
  }
  //cout << num[5] << endl;
  ll ans = 1;
  rep(i,1000) {
    if(num[i]>0) {
      ans *= num[i]+1;
      ans %= 1000000007;
      //cout << ans << endl;
    } 
  }
  cout << ans << endl;
}

Measured memory_bytes: 384