akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair<ll, int> li;
typedef pair<int, ll> il;
typedef vector<ii> vii;
typedef vector<il> vil;
typedef vector<li> vli;

#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define MOD 100000007
#define sz size()
const double pi=acos(-1.0);
int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1,-1, 1, -1, 0, 0, -1, 1};

int main()
{
    int i, j, c=0;
    string s;
    cin>>s;
    for(i=0,j=s.sz-1;i<=j;i++,j--){
        if(s[i]!=s[j])c++;
    }
    cout<<c<<endl;
    return 0;
}


Measured memory_bytes: 256
def solve():
    N, M, *AB = map(int, open(0).read().split())
    FROM_1 = set()
    TO_N = set()
    for i in range(M):
        a, b = AB[2*i], AB[2*i + 1]
        if a == 1:
            FROM_1.add(b)
        elif a == N:
            TO_N.add(b)
        if b == 1:
            FROM_1.add(a)
        elif b == N:
            TO_N.add(a)
    ans = FROM_1 & TO_N
    print('POSSIBLE') if ans else print('IMPOSSIBLE')

if __name__ == '__main__':
   solve()


Measured memory_bytes: 46660
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) 
	{
		Scanner sc = new Scanner(System.in);
		long min = 0;
		
		int n = sc.nextInt();
		long k = sc.nextLong();
		long[] a = new long[n];
		Long[] f = new Long[n];
		
		for(int i = 0; i < n; i++)
			a[i] = sc.nextLong();
		
		for(int i = 0; i < n; i++)
			f[i] = sc.nextLong();
		
		Arrays.sort(a);
		Arrays.sort(f, Collections.reverseOrder());
//		System.out.println(Arrays.toString(a));
//		System.out.println(Arrays.toString(f));
		
		for(int i = 0; i < n; i++)
			min = Math.max(min,a[i]*f[i]);
		long l = 0;
		long r = 100000000000000l;
		
		while(l<=r)
		{
			long tar = (l + r) / 2;
			{
				//assume tar is decided here
				long price = 0;
				
				for(int i = 0; i < n; i++)
				{
					long m = a[i] * f[i];
					long up = m - tar;
					long lef = (m - tar) / f[i];
					if((m-tar)%f[i]!=0)lef++;
					if(m <= tar)lef = 0;
					price += Math.max(lef,0);
					
//					System.out.println("price " + i + ": " + lef);
				}
//				System.out.println(price);
				if(price <= k)
				{
					min = Math.min(min, tar);
					
					//good enough
					r = tar-1;
				}
				else
				{
					//cant afford this, bigger target now
					l = tar+1;
				}
			}
		}

		System.out.println(min);
	}

}


Measured memory_bytes: 109076
#include<bits/stdc++.h>
using namespace std;
#define Maxn 100010

int n, a[Maxn], f[Maxn], Lngst, nxt[Maxn];


int main()
{
    scanf("%d", &n);
    for (int i=1; i<=n; i++)
    {
        scanf("%d", &a[n - i + 1]);
        f[i] = -1;
    }
    for (int i=1; i<=n; i++)
    {
        nxt[i] = lower_bound(f, f + n, a[i], greater<int>()) - f;
        f[nxt[i]] = a[i];
        Lngst = max(Lngst, nxt[i]);
    }
    
    long long Res = 0;
    for (int i=n; i>=1; i--)
        if (nxt[i] == Lngst) { Res+=a[i]; Lngst--; }
    
    printf("%lld\n", Res);
}



Measured memory_bytes: 4388
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/adaptor/indexed.hpp>
#define FOR(i,k,n)  for(int i = (k);i < (n);++i)
#define REP(i,n)    FOR(i,0,n)
#define ALL(x) begin(x),end(x)

using namespace std;
using namespace boost::adaptors;
using namespace std::string_literals;
using ll = int64_t;
using vecint = vector<int>;
using vecll = vector<ll>;
using boost::irange;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n,k;
  cin>>k>>n;
  vecint a(n);
  for(auto&& e:a)cin>>e;
  int mx = 0;
  REP(i,n) {
    if(i==n-1) {
      mx = max(mx, a[0]+k-a[n-1]);
    } else {
      mx = max(mx, a[i+1]-a[i]);
    }
  }
  cout<<k-mx<<endl;
  return 0;
}


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

int main(){
    char N[200002];
    scanf("%s",N);
    int s = 0;
    int i = 0;
    while(N[i] != '\0'){
        int n = N[i] - '0';
        s = s*10 + n;
        s = s%9;
        //printf("n %d s %d\n",n,s);
        i++;
    }
    if(s == 0){printf("Yes\n");}
    else{printf("No\n");}
    return 0;
}

Measured memory_bytes: 1820
# -*- coding: utf-8 -*-
from collections import deque
H, W = list(map(int, input().split()))
Sn = [input() for _ in range(H)]

def func(h,w): # 黒のみ
    move = [(0,-1),(-1,0),(0,1),(1,0)]
    w_cnt = 0
    b_cnt = 0
    que = deque()
    que.append((h,w))
    while len(que) > 0:
        xh,xw = que.popleft()
        if visited[xh][xw] == 0:
            visited[xh][xw] = 1
            if Sn[xh][xw] == "#":
                b_cnt += 1
            else:
                w_cnt += 1
        else:
            continue
            
        for mh, mw in move:
            if 0 <= xh + mh < H and 0 <= xw + mw < W:
                if Sn[xh][xw] != Sn[xh + mh][xw + mw] and visited[xh + mh][xw + mw] == 0:
                    que.append((xh + mh, xw + mw))

    return b_cnt, w_cnt

cnt = 0
visited = [[0 for _ in range(W)] for _ in range(H)]

for i in range(H):
    for j in range(W):
        if Sn[i][j] == "#" and visited[i][j]==0:
            b_cnt, w_cnt = func(i, j)
            cnt += b_cnt*w_cnt
            
print(cnt)


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

int n,f[3][105];
int main()
{
    scanf("%d",&n);
    for (int i=1; i<=2; i++)
        for (int j=1; j<=n; j++)
            scanf("%d",&f[i][j]),
                  f[i][j]+=max(f[i-1][j],f[i][j-1]);
    printf("%d",f[2][n]);
    return 0;
}


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

int main() {
    long n, k;
    cin >> n >> k;
    long arr[n];
    long numb;
    long sum = 0;
    for(int i = 0; i < n; i++) {
        cin >> numb;
        arr[i] = numb;
        sum+= numb;
    }

    sort(arr, arr+n);

    if(n <= k) {
        cout << 0 << endl;
    }
    else {
        for(int i = 0; i < k; i++) {
            sum-=arr[n-i-1];

        }
        cout << sum << endl;
    }  
}

Measured memory_bytes: 1792
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <vector>
#include <complex>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <iterator>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <regex>
#include <limits>
#include <time.h>
#include <cstdint>
using namespace std;
using pii  = pair<int,int>;
using ll=long long;
using ld=long double;
#define pb push_back
#define mp make_pair
#define sc second
#define fr first
#define stpr setprecision
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,n) for(ll i=0;i<(n);++i)
#define Rep(i,a,b) for(ll i=(a);i<(b);++i)
#define rrep(i,n) for(ll i=n-1;i>=0;i--)
#define rRep(i,a,b) for(ll i=a;i>=b;i--)
#define crep(i) for(char i='a';i<='z';++i)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define ALL(x) (x).begin(),(x).end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define endl '\n'
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
ll gcd(ll a,ll b){return (b == 0 ? a : gcd(b, a%b));}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll MOD=1000000007;
constexpr ll INF=1000000011;
constexpr ll MOD2=998244353;
constexpr ll LINF = 1001002003004005006ll;
constexpr ld EPS=10e-8;
template <class T, class U> inline bool chmax(T& lhs, const U& rhs) { if (lhs < rhs) { lhs = rhs; return 1; } return 0; }
template <class T, class U> inline bool chmin(T& lhs, const U& rhs) { if (lhs > rhs) { lhs = rhs; return 1; } return 0; }
template<typename T> istream& operator>>(istream& is,vector<T>& v){for(auto&& x:v)is >> x;return is;}
template<typename T,typename U> istream& operator>>(istream& is, pair<T,U>& p){ is >> p.first; is >> p.second; return is;}
template<typename T,typename U> ostream& operator>>(ostream& os, const pair<T,U>& p){ os << p.first << ' ' << p.second; return os;}
template<class T> ostream& operator<<(ostream& os, vector<T>& v){
  for(auto i=begin(v); i != end(v); ++i){
    if(i !=begin(v)) os << ' ';
    os << *i;
  }
  return os;
}

ll N,K;
ll dp[3][100007];
ll A[100007],B[100007];

int main(){
  cin >> N >> K;
  rep(i,N){
    cin >> A[i];
    B[i+1]=B[i+1]+A[i];
    B[i+2]=B[i+1];
  }
  rep(i,N){
    dp[0][i+1]=max(dp[0][i],dp[0][i]+A[i]);
    dp[1][i+K]=max(dp[0][i],dp[0][i]+(B[i+K]-B[i]));
  }
  ll ANS=0;
  Rep(i,K,N+1){
    ANS=max(ANS,dp[1][i]+dp[0][N]-dp[0][i]);
  }
  cout << ANS << endl;
}


Measured memory_bytes: 6728
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <math.h>
using namespace std;

void check(int x, int y) {
	for (int i = 0; i <= x; i++)
	{
		if (i * 4 + 2 * (x - i) == y)
		{
			cout << "Yes";
			return;
		}
	}
	cout << "No";
}

int main()
{
	int x, y;
	cin >> x >> y;
	check(x, y);
	return 0;
}



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


int main(){

	int n;  cin>>n;
	string s; int mx=0; int count=0; 
	cin>>s; 
	for(int i=0;i<n;i++){
		
		if(s[i]=='I') count++; 
		else count--; 
		mx=max(count,mx);
	}

	cout<<mx<<endl;
}

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

int main(){
        double A, B;
        cin >> A >> B;
        int ans = 10000;
        for(int i = 1; i <= 1000; i++) {
                if(floor(i * 0.08) == A && floor(i * 0.1) == B) {
                        ans = min(ans,i);
                }
        }
        if(ans != 10000) cout << ans << endl;
        else cout << -1  << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#pragma warning(disable:4996)


int main() {

	long long a;
	scanf("%lld", &a);
	long long n = 100;
	int cnt = 0;
	while (n < a) {
		cnt++;
		n += (n / 100);
	}
	printf("%d", cnt);


	return 0;
}

Measured memory_bytes: 1736
#include <iostream>
#include <vector>
#include <string.h>
#include <set>
#include <map>
#include <assert.h>
#include <algorithm>
#include <queue>
#include <bitset>
#include <stack>
#include <chrono>
#include <random>
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
#define ll long long
#define MOD 1000000007 
#define INF 1000000000000000000
#define rnd mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define FIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define uid uniform_int_distribution <int>
using namespace std;
// Read the question carefully and see all the given sample tests
// Think about the correctness before implementing

ll power(ll a, ll b, ll c)
{
	ll res = 1;
	while(b != 0)
	{
		if(b & 1)
			res = (res * a) % c;
		a = (a * a) % c;
		b /= 2;
	}
	return res;
}
ll ncr(ll n, ll r)
{
	if(r > n - r)
		r = n - r;
	ll res = 1;
	for (int i = 1; i <= r; i++)
	{
		res *= (n - i + 1);
		res %= MOD;
		res *= power(i, MOD - 2, MOD);
		res %= MOD;
	}
	return res;
}
int main()
{
	int x, y;
	cin >> x >> y;
	if((x + y) % 3 != 0)
	{
		cout << 0;
	}
	else
	{
		int val = (x + y) / 3;
		if(y < val || y > val + val + 1)
		{
			cout << 0;
		}
		else
		{ 
			cout << ncr(val, y - val);
		}
	}
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    int H,W,i,j,ans1,ans2;
    for(;;){
        cin>>H>>W;
        if(H==0&&W==0){
            break;
        }
        for(i=1;i<=H;i++){
            ans1=i/2*2;
            for(j=1;j<=W;j++){
                ans2=j/2*2;
                if((ans1!=i)!=(ans2!=j)){
                    cout<<".";
                }else{
                    cout<<"#";
                }
            }
            cout<<endl;
        }
        cout<<endl;
    }
        return 0;
    }


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

A = A + [0]
K = min(K, 50)
for k in range(K):
    t = [0]*(N+1)
    for i in range(N):
        l = max(i-A[i], 0)
        r = min(i+A[i], N-1)
        t[l] += 1
        t[r+1] -= 1

    S = [0]*N
    S[0] = t[0]
    for i in range(1, N):
        S[i] = S[i-1] + t[i]

    A = S.copy()
print(*S)

Measured memory_bytes: 170780
a,b,c = map(int,input().split())
if a <= b and b <= c:
    print(f"{a} {b} {c}")
elif a <= c and  c <= b:
    print(f"{a} {c} {b}")
elif b <= a and a <= c:
    print(f"{b} {a} {c}")
elif b <= c and c <= a:
    print(f"{b} {c} {a}")
elif c <= a and a <= b:
    print(f"{c} {a} {b}")
else:
    print(f"{c} {b} {a}")


Measured memory_bytes: 5608
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
#define all(x) (x).begin(), (x).end()
#define fsp(x) cout << fixed << setprecision(x)
const ll inf = LLONG_MAX;
const long double pi = acos(-1);
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

int main() {
	//ios::sync_with_stdio(false);
	//cin.tie(nullptr);

	ll n, k;
	cin >> n >> k;
	vll v(n);
	for (ll i = 0; i < n; i++) cin >> v[i];

	ll ans = 0;
	for (ll i = 0; i <= min(n, k); i++) {
		for (ll j = 0; j <= min(n - i, k - i); j++) {
			ll sum = 0;
			priority_queue<ll, vll, greater<ll>> pq;
			for (ll l = 0; l < i; l++) {
				sum += v[l];
				if (v[l] < 0) pq.push(v[l]);
			}
			for (ll l = 0; l < j; l++) {
				sum += v[n - 1 - l];
				if (v[n - 1 - l] < 0) pq.push(v[n - 1 - l]);
			}
			ll x = min(k - i - j, (ll)pq.size());
			while (x--) {
				sum -= pq.top();
				pq.pop();
			}
			ans = max(ans, sum);
		}
	}
	cout << ans << endl;
}


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

namespace CSharpSample01
{
    
    class Program
    {

        

        static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split(' ');

            int N = int.Parse(str[0]);
            int K = int.Parse(str[1]);

            double ans = 0;
            int last = N;

            if (N >= K)
            {
                ans += (double)(N - K + 1) / N;
                last = K - 1;            
            }
          
            for (int point = 1; point <= last; point++)
            {
                int cnt = 0;
                int p = point;
                while (true)
                {
                    p *= 2;
                    cnt++;

                    if (p >= K)
                    {
                        break;
                    }
                }

                
                ans += Math.Pow(0.5, cnt) * (double)1 / N;

            }

            Console.WriteLine(ans);
            

        }
    }
}

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

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int a, b, suma = 0;
    cin >> a >> b;
    if(b>a) {
        cout << 1;
        return 0;
    } else {
        while(a>0) {
            a -= b;
            suma++;
        }
    }
    cout << suma;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define RFOR(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define REP(i,n) FOR(i,0,(n))
#define REPS(i,n) FOR(i,1,(n)+1)
#define RREP(i,n) RFOR(i,0,(n))
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define DEBUG(x)  cout << #x << " = " << (x) << endl;
#define SORT(x) sort(ALL(x));
#define RSORT(x) sort(RALL(x));
#define SUM(x) accumulate(ALL(x),0);
#define FI first
#define SE second
#define PB push_back
#define EB emplace_back
#define SZ(x) (int)(x).size()
#define BN(x) ((1<<x)-1)
#define DUP(x,y) (((x)+(y)-1)/(y))
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const ll mod = 1e9+7;
const int INF = (1<<30)-1;
const ll INFLL = (1LL<<62)-1;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//cout << fixed << setprecision(10);

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

ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

vi to[200005];
vi ans;

void dfs(int v, int p = -1) {
  for (int u : to[v]) {
    if (u == p) continue;
    ans[u] += ans[v];
    dfs(u,v);
  }
  return;
}

int main () {
  int N, Q; cin >> N >> Q;
  REP(i,N-1) {
    int a, b; cin >> a >> b;
    --a; --b;
    to[a].push_back(b);
    to[b].push_back(a);
  }

  ans.resize(N);
  REP(i,Q) {
    int p, x; cin >> p >> x;
    --p;
    ans[p] += x;
  }

  dfs(0);
  REP(i,N) {
    cout << ans[i] << endl;
  }
  
  return 0;
}

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

typedef long long   ll;
const ll mod = 1e9 + 7;

#define speedup_IO      ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define forn(i,a,n)     for(ll i = a; i < n; i++)
#define ford(i,n,a)     for(ll i = n; i >= a; i--)
#define pb              push_back
#define lb              lower_bound		// first element >= val(itr) 
#define ub              upper_bound		// first element >  val(itr)
#define pll             pair<ll,ll>
#define all(a)          (a).begin(),(a).end()
#define reset(a,x)      memset(a,x,sizeof(a))	//x can be 0 or -1

ll mypow(ll base, ll exp) {ll res = 1; while (exp) {if (exp & 1) res = (res * base) % mod; exp >>= 1, base = (base * base) % mod;} return res;}
ll gcd(ll a, ll b)  { return b ? gcd(b, a % b) : a;            }
ll mult(ll a, ll b) { if (a < 0) {a += mod;} if (b < 0) {b += mod;} return ((a % mod) * (b % mod)) % mod; }
ll add(ll a, ll b)  { if (a < 0) {a += mod;} if (b < 0) {b += mod;} return (a % mod + b % mod) % mod;        }
ll sub(ll a, ll b)  { if (a < 0) {a += mod;} if (b < 0) {b += mod;} return (a % mod + mod - b % mod) % mod;  }


const ll inf = 1e18;
const int nax = 1e5 + 5;

void SolveTestCase()
{
	ll x,y,z;
	cin>>x>>y>>z;
	
	swap(x,y);
	swap(x,z);
	cout<<x<<" "<<y<<" "<<z;
}

int main()
{
	speedup_IO;

	int t = 1;
	//cin >> t;
	forn(i,0,t)
	{
		SolveTestCase();
	}

	return 0;
}


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

typedef pair<int, int> P;

#define F first
#define S second

int main(void)
{
  int m, n, x, y;
  P target[256], star[1024];
  P shift[1024];

  while(cin >> m, m){
    for(int i = 0;i < m; i++)
      cin >> target[i].F >> target[i].S;
    cin >> n;
    for(int i = 0;i < n; i++)
      cin >> star[i].F >> star[i].S;
    
    sort(target, target + m);
    sort(star, star + n);
    
    bool flag;
    for(int i = 0;i < n; i++){
      flag = true;
      x = star[i].F - target[0].F;
      y = star[i].S - target[0].S;

      for(int j = 0;j < m; j++){
	if(!binary_search(star, star + n, P(target[j].F + x, target[j].S + y))){
	  flag = false;
	  break;
	}	
      }
      if(flag) break;
    }
    cout << x << " " << y << endl;
  }
}


Measured memory_bytes: 1180
#include <stdio.h>
#include <iostream>
#include <math.h>
#include <string.h>
#include <algorithm>
#include <vector>
#include <limits.h>

#define rep(x,y) for(int x = 0;x < y;++x)

int main() {

    int N;
    std::cin >> N;
    std::vector<int> W(N);

    int min_value = INT_MAX;
    int left = 0, right;

    rep(i, N) std::cin >> W[i];

    rep(i, N) {
        right += W[i];
    }

    rep(i, N - 1) {
        left += W[i];
        right -= W[i];
        min_value = std::min(min_value, abs(left - right));
    }

   std:: cout << min_value << '\n';
}

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

int main(){
  int N;
  string S;
  int cntLW, cntRE;
  int cnt[1000000];
  int min;

  cin >> N >> S;
  min=N;

  //cntLW
  cntLW=0;
  for(int i=0;i<N;i++){
    cnt[i]+=cntLW;
    if(S[i]=='W') cntLW++;
  }

  //cntRE
  cntRE=0;
  for(int i=N-1;i>=0;i--){
    cnt[i]+=cntRE;
    if(S[i]=='E') cntRE++;
  }

  //find min
  min=N;
  for(int i=0;i<N;i++)
    if(min > cnt[i]) min = cnt[i];

  cout << min << endl;

  return 0;

}


Measured memory_bytes: 3716
import sys
import heapq

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def IS(): return sys.stdin.readline()[:-1]
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LII(rows_number): return [II() for _ in range(rows_number)]
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]

def main():
	N,M = MI()
	A = LI()
	A = list(map(lambda x : x*(-1), A))
	heapq.heapify(A)
	for i in range(M):
		discnt_price = (heapq.heappop(A) * -1)//2
		heapq.heappush(A,discnt_price*-1)
	print(sum(A)*-1)


main()

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

using namespace std;

int main() {
    int n;
    cin>>n;
    
    int mat[n][3];
    for(int i=0;i<n;i++) for(int j=0;j<3;j++) cin>>mat[i][j];
    
    int dp[n][3] = {0};
    dp[0][0] = mat[0][0], dp[0][1] = mat[0][1], dp[0][2] = mat[0][2];
    
    for(int i=1;i<n;i++){
        dp[i][0] = mat[i][0] + max(dp[i-1][1],dp[i-1][2]);
        dp[i][1] = mat[i][1] + max(dp[i-1][0],dp[i-1][2]);
        dp[i][2] = mat[i][2] + max(dp[i-1][0],dp[i-1][1]);
    }
    
    cout<<max({dp[n-1][0], dp[n-1][1], dp[n-1][2]});
}

Measured memory_bytes: 2560
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e13;
const ll MAX_N = 100010;

int main() {
    ll n, k;
    cin >> n >> k;

    vl a(n);
    rep(i, n) {
        cin >> a[i];
    }
    sort(all(a));

    vl f(n);
    rep(i, n) {
        cin >> f[i];
    }
    sort(rall(f));

    // 判定問題「チーム全体の成績をxにできるか？」を二分探索で解く
    ll left = -1;
    ll right = INF;
    while(right - left > 1) {
        ll x = (left + right)/2;
        ll cnt = 0;  // 修行回数
        rep(i, n) {
            cnt += max(0LL, a[i] - x/f[i]);
        }
        if(cnt <= k) {
            right = x;
        }
        else {
            left = x;
        }
    }

    out(right);
    re0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int count = 0;
  string s;
  cin >> s;
  for (int i = 0; i < 4; i++) {
    if (s.at(i) == '+') {
      count++;
    }
  }
  cout << 2 * count - 4;
}

Measured memory_bytes: 256
#pragma GCC optimize(2)
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using PII = pair<int, int>;
using PLL = pair<LL, LL>;
const int INF = 1e9;
const int MXN = 0;
const int MXV = 0;
const LL MOD = 1e9 + 7;
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define FOR(i, L, R) for (int i = L; i != (int)R; ++i)
#define FORD(i, L, R) for (int i = L; i != (int)R; --i)
#define IOS                                                                    \
    cin.tie(nullptr);                                                          \
    cout.tie(nullptr);                                                         \
    ios_base::sync_with_stdio(false);

LL pow2(LL n)
{
    LL tmp = 2, res = 1;
    for (; n > 0; n >>= 1)
    {
        if ((n & 1) != 0)
        {
            res = (res * tmp) % MOD;
        }
        tmp = (tmp * tmp) % MOD;
    }
    return res;
}

LL extgcd(LL a, LL b, LL &x, LL &y)
{
    LL d = a;
    if (b)
    {
        d = extgcd(b, a % b, y, x), y -= (a / b) * x;
    }
    else
        x = 1, y = 0;
    return d;
} // ax+by=1 ax同餘 1 mod b

LL sol(LL m, LL n)
{
    LL x = 1, y = 1, tmp1, tmp2;
    for (LL i = m; i > m - n; --i){ x = (x * i) % MOD; }
    for (LL i = 1; i <= n; ++i){ y = (y * i) % MOD; }
    extgcd(y, MOD, tmp1, tmp2);
    x = (x * tmp1);
    return (x + MOD) % MOD;
}

int main()
{
    IOS;
    LL n, a, b;
    cin >> n >> a >> b;
    LL ans = (pow2(n) - 1 + MOD) % MOD;
    ans -= sol(n, a);
    ans -= sol(n, b);
    while(ans < MOD)
    {
        ans += MOD;
    }
    cout << (ans + MOD) % MOD << '\n';
}


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

int main() {
 int s;
  cin>>s;
  if(s==25){
    cout<<"Christmas"<<endl;}
  else if(s==24){
    cout<<"Christmas Eve"<<endl;}
  else if(s==23){
    cout<<"Christmas Eve Eve"<<endl;}
  else{
    cout<<"Christmas Eve Eve Eve"<<endl;}

}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define EPS (1e-7)
#define INF (1e9)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
const double PI = acos(-1);
const ll MOD = 1000000007;
// const ll MOD = 998244353;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
 
template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
///////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int N; cin >> N;
    vector<int> h(N);
    rep(i,N) cin >> h[i];
    vector<ll> A(N);
    rep(i,N) cin >> A[i];

    map<int,ll> dic;
    ll ans = 0;
    rep(i,N) {
        auto it = dic.lower_bound(h[i]);
        if (it == dic.begin()) dic.emplace(h[i],A[i]);
        else {
            it--;
            dic.emplace(h[i],it->second+A[i]);
        }
        while (true) {
            auto ite = dic.upper_bound(h[i]);
            if (ite == dic.end() || ite->second >= dic[h[i]]) break;
            dic.erase(ite);
        }
    }
    for (auto i : dic) chmax(ans,i.second);
    cout << ans << endl;

}

Measured memory_bytes: 15104
//#pragma GCC optimize(2)
#include<set>
#include<map>
#include<stack>
#include<cmath>
#include<queue>
#include<cstdio>
#include<vector>
#include<climits>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define LL long long
using namespace std;
int read(){
	bool f=0;int x=0;char c=getchar();
	while(c<'0'||'9'<c){if(c=='-')f=1;c=getchar();}
	while('0'<=c&&c<='9') x=(x<<3)+(x<<1)+(c^48),c=getchar();
	return !f?x:-x;
}
#define MAXN 100000
#define INF 0x3f3f3f3f
int main(){
	int n=read(),k=read(),ans=0;
	for(int i=1;i<=n;i++){
		int x=read();
		if(x>=k)
			ans++;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
#define int ll

int32_t main()
{
	#ifndef ONLINE_JUDGE
	freopen("in","r",stdin);
	freopen("out","w",stdout);
	#endif
	int n;
	cin>>n;
	std::vector<int> a(n);
	for(auto &i:a)cin>>i;

	sort(a.begin(),a.end());
	vector<int> ct(1004);
	for(int i=0;i<n;i++)ct[a[i]]++;
	for(int i=1;i<=1000;i++)ct[i]+=ct[i-1];
	
	int ans=0;
	for(int i=0;i<n;i++)
		for(int j=i+1;j<n;j++)
		{
			
			int r=a[i]+a[j];
			auto it=lower_bound(a.begin(),a.end(),r)-a.begin();
			//cout<<"#"<<it<<"\n";
			if(it>j)ans+=(it-j-1);
			
		}

	cout<<ans;

	

}

Measured memory_bytes: 3648
from collections import defaultdict

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

def Fib(n):
    a, b = 0, 1
    if n == 1:
        return a
    elif n == 2:
        return b
    else:
        for i in range(n-2):
            a, b = b, a + b
        return b

N = int(input())
if(N == 1):
    print(0)
else:
    fact = factorization(N)
    l = [i for i in range(1,1000)]
    count = 0
    d = {}
    for n in fact:
        num = n[1]
        for f in l:
            num -= f
            if(num < 0):
                break
            count += 1
    print(count)

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

main(){
	int n,c=0;
	char *p,*q;
	char str[20];
	cin>>str;
	p = str;
	q = p;
	while(*q)q++;
	q--;
	for(;p<q;p++,q--){
		if((*p=='i' && *q=='i') ||
		   (*p=='w' && *q=='w') ||
		   (*p=='(' && *q==')') ||
		   (*p==')' && *q=='(')
		   ) continue;
		c++;
	}
	if(p==q && (*p=='('||*p==')')) c++;
	cout << c << endl;
	return 0;
}

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

int main() {
  int N, K; cin >> N >> K;
  int P[N]; for (int i = 0; i < N; i++) { cin >> P[i]; P[i]--; }
  int C[N]; for (int i = 0; i < N; i++) cin >> C[i];
  long max_score = -1e+9;
  for (int k = 0; k < N; k++) {
    int i = P[k], c = 1;
    vector<long> V; V.push_back(C[i]);
    while (i != k && c < K) {
      i = P[i];
      V.push_back(V.back() + C[i]);
      c++;
    }
    long max_s = -1e+9;
    for (auto it = V.begin(); it != V.end(); it++) max_s = max(max_s, *it);
    if (c < K && V.back() > 0) {
      for (auto j = 0; j < c; j++) {
        if (j <= (K-1) % c) max_s = max(max_s, V[j] + (K-1) / c * V.back());
        else max_s = max(max_s, V[j] + ((K-1) / c - 1) * V.back());
      }
    }
    max_score = max(max_score, max_s);
  }
  cout << max_score << endl;
}

Measured memory_bytes: 3756
#include <iostream>
#include <iomanip>
#include <fstream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>

#define _GLIBCXX_DEBUG
using namespace std;
using vi = vector<int64_t>;
using vvi = vector<vi>;

int main(int argc, const char * argv[]) {
    // fasten cin
    cin.tie(0);
    ios::sync_with_stdio(false);
    // implement
    int64_t x,a;
    cin >> x >> a;
    if(x<a){
        cout << 0 << endl;
    }else{
        cout << 10 << endl;
    }
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
using namespace std;

int main()
{
    int n,num[1000],i=0,rem,sum=1;
    cin>>n;
    for(i=0; i<n; i++)
        cin>>num[i];

    while(num[i] != 0)
    {
        rem=num[i]%10;
        sum=sum*10+num[i];
        num[i]=num[i]/10;
        i++;
    }

    for(i=n-1; i>0; i--)
    {
        cout<< num[i]<< " ";
    }
    cout<< num[0];
    cout<< endl;

    return 0;
}



Measured memory_bytes: 3096
import numpy as np
import bisect
from operator import itemgetter
import math
import functools
import itertools
import numpy as np
import sys
MAX_INT = int(10e10)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N,K = IL()
v = IL()

VList = [[] for _ in range(N+1)]

ans = 0
for left in range(N+1):
  for right in range(N+1):
    if left+right == 0:
      continue
    if left+right > min(N, K):
      break
    else:
      l = v[:left] + v[N-right:]
      cnt = K - (left+right)
      l.sort()
      tmp = sum(l)
      for j in range(min(cnt, len(l))):
        if l[j] < 0:
          tmp -= l[j]
        else:
          break
      ans = max(ans, tmp)

print(ans)

Measured memory_bytes: 14452
#include<bits/stdc++.h>
using namespace std;
int n,m,x;
int a[100][100],cen[100];
int main()
{
	scanf("%d%d%d", &n, &m, &x);
	for(int i=0;i<n;++i)
	{
		scanf("%d", &cen[i]);
		for(int j=0;j<m;++j)
		{
			scanf("%d", &a[i][j]);
		}
	}
	int ans=1000000000;
	for(int i=1;i<(1<<n);++i)
	{
		int act=0;
		int t[100];
		for(int j=0;j<n;++j)
		{
			if(i&(1<<j))
			{
				act+=cen[j];
				for(int g=0;g<m;++g)
				{
					t[g]+=a[j][g];
				}
			}
		}
		bool ok=1;
		for(int g=0;g<m;++g)
		{
			if(t[g]<x) ok=0;
			t[g]=0;
		}
		if(ok) ans=min(ans,act);
	}
	if(ans!=1000000000) printf("%d\n", ans);
	else printf("-1\n");
	return 0;
}


Measured memory_bytes: 3836
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
// Welcome to my source code!

int main() {
    int n;
    cin >> n;
    int a[n];
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        a[i] -= i + 1;
    }
    sort(a, a+n);
    ll ans = 0;
    for (int i = 0; i < n; i++) {
        ans += abs(a[i] - a[n / 2]);
    }
    if (n & 1) {
        ll t = 0;
        for (int i = 0; i < n; i++) {
            t += abs(a[i] - a[(n + 1) / 2]);
        }
        ans = min(ans, t);
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
# AtCoder DP Task D - Knapsack 1
def knapsack(target, W, V): # target=knapsack weight
    P = [[0] * (target + 1) for _ in range(len(V))]
    for vi in range(len(V)):
        row, prev = P[vi], P[vi - 1]
        for w in range(target + 1):
            if vi > 0:
                row[w] = prev[w] # same value without vi-th item
                if w >= W[vi]:
                    new = P[vi - 1][w - W[vi]] + V[vi]
                    if new > P[vi][w]: # most value
                        row[w] = new
            else:
                if w >= W[vi]:
                    row[w] = V[vi]
    return P[len(V) - 1][target]

def knapsack_rec(target, W, V): # target=knapsack weight
    P = [-1] * (target + 1)
    P[target] = 0 # default + max

    for vi in range(len(V)):
        we = W[vi]
        va = V[vi]
        for i in range(we, target + 1):
            if P[i] != -1 and P[i - we] < P[i] + va:
                P[i - we] = P[i] + va

    return max(P)

assert knapsack_rec(15, [6, 5, 6, 6, 3, 7], [5, 6, 4, 6, 5, 2]) == 17

if __name__ == "__main__":
    import sys
    n, w, *r = map(int, sys.stdin.read().split())
    W, V = r[::2], r[1::2]
    ans = knapsack_rec(w, W, V)
    print(ans)


Measured memory_bytes: 41584
# -*- coding: utf-8 -*-
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys

def s():
    return raw_input().strip()
def n():
    return int(raw_input())
def d():
    return float(raw_input())

def ls():
    return raw_input().strip().split()
def ln():
    return map(int, raw_input().strip().split())
def ld():
    return map(float, raw_input().strip().split())

def fs():
    return [raw_input().strip() for i in xrange(input())]
def fn():
    return [int(raw_input().strip()) for i in xrange(input())]
def fd():
    return [float(raw_input().strip()) for i in xrange(input())]

X = s()

con = 0
dec = 0
for c in X:
    if c == 'S':
        con += 1
    elif con > 0:
        con -= 1
        dec += 2
    else:
        con = 0

print len(X) - dec



Measured memory_bytes: 4768
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <bitset>
using namespace std;

typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define index(xs, x) (int)(lower_bound(all(xs), x) - xs.begin())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
#define double long double
P operator +(const P &a, const P &b) { return P(a._1+b._1, a._2+b._2); };
P operator -(const P &a, const P &b) { return P(a._1-b._1, a._2-b._2); };
long long det(P a, P b) { return 1LL*a._1*b._2 - 1LL*a._2*b._1; }
long long dot(P a, P b) { return 1LL*a._1*b._1 + 1LL*a._2*b._2; }
double abs(P a) { return sqrt(1LL*a._1*a._1 + 1LL*a._2*a._2); }

vector<P> convex_hull(vector<P> ps) {
  int n = ps.size(), k = 0;
  sort(all(ps));
  vector<P> qs(n*2);
  for (int i=0; i<n; i++) {
    while (k > 1 && det(qs[k-1]-qs[k-2], ps[i]-qs[k-1]) <= 0) k--;
    qs[k++] = ps[i];
  }
  for (int i=n-2, t=k; i>=0; i--) {
    while (k > t && det(qs[k-1]-qs[k-2], ps[i]-qs[k-1]) <= 0) k--;
    qs[k++] = ps[i];
  }
  qs.resize(k-1);
  return qs;
}

int N;
map<P, int> id;
int X[100], Y[100];
double O[100];
signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  cin >> N;
  vector<P> ps;
  rep(i, N) {
    int x, y;
    cin >> x >> y;
    ps.pb(P(x, y));
    id[P(x, y)] = i;
  }
  vector<P> hull = convex_hull(ps);
  int n = hull.size();
  if (n == 2) {
    O[id[hull[0]]] = 0.5;
    O[id[hull[1]]] = 0.5;
  }
  else {
    double sum = 0;
    rep(i, n) {
      P a = hull[i], b = hull[(i+1)%n], c = hull[(i+n-1)%n];
      double deg = acos((1.0*dot(a-c, b-a)) / (1.0*abs(a-c)*abs(b-a)));
      sum += deg;
    }
    rep(i, n) {
      P a = hull[i], b = hull[(i+1)%n], c = hull[(i+n-1)%n];
      double deg = acos((1.0*dot(a-c, b-a)) / (1.0*abs(a-c)*abs(b-a)));
      O[id[a]] = deg/sum;
    }
  }
  rep(i, N) cout << fixed << setprecision(20) << O[i] << "\n";
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

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

const long long INF = 1e18;
//const ll mod = 1000000007;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    ll ans = 0;
    for(ll i = 1; i <= N; i++) {
        ans += i * (N + 1 - i);
    }
    for(int i = 0; i < N - 1; i++) {
        ll a, b;
        cin >> a >> b;
        if(a > b) swap(a, b);
        ll L = a;
        ll R = (N + 1 - b);
        ans -= L * R;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
int main(){
  string S,T;
  cin >> S >> T;
  int ans= 0;
  for(int i = 0; i < 3;i++){
    if(S.at(i) == T.at(i)){ans++;}
  }
  cout << ans;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string.h>
#include<string>
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<vector>
#include<queue>
#include<map>
using namespace std;
const int maxd=1000000007,N=100000;
const double pi=acos(-1.0);
typedef long long ll;

int read()
{
	int x=0,f=1;char ch=getchar();
	while ((ch<'0') || (ch>'9')) {if (ch=='-') f=-1;ch=getchar();}
	while ((ch>='0') && (ch<='9')) {x=x*10+(ch-'0');ch=getchar();}
	return x*f;
}

int main()
{
	int n=read(),k=read(),tmp=(n+1)/2;
	if (tmp>=k) cout << "YES";else cout <<"NO";
	return 0;
}


Measured memory_bytes: 256
package main

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

func nextInt(sc *bufio.Scanner) int {
	sc.Scan()
	t := sc.Text()
	i, err := strconv.Atoi(t)
	if err != nil {
		panic(err)
	}
	return i
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	N := nextInt(sc)
	X := nextInt(sc)
	T := nextInt(sc)

	q := N / X
	r := N % X

	if r != 0 {
		fmt.Println((q + 1) * T)
		return
	}
	fmt.Println(q * T)
}


Measured memory_bytes: 1772
a,b,q=map(int,input().split())
S=[int(input()) for i in range(a)]
T=[int(input()) for i in range(b)]
Q=[int(input()) for i in range(q)]

QLIST=[[10**15,10**15,10**15,10**15] for i in range(q)]

QI=[[Q[i],i] for i in range(q)]
QI.sort()

i=0
j=0

while j<q and i<a:
    if S[i]>QI[j][0]:
        if i>0:
            QLIST[QI[j][1]][0]=QI[j][0]-S[i-1]
        QLIST[QI[j][1]][1]=S[i]-QI[j][0]

        j+=1
    else:
        i+=1

    if i==a:
        for h in range(j,q):
            QLIST[QI[h][1]][0]=QI[h][0]-S[i-1]

i=0
j=0

while j<q and i<b:
    if T[i]>QI[j][0]:
        if i>0:
            QLIST[QI[j][1]][2]=QI[j][0]-T[i-1]
        QLIST[QI[j][1]][3]=T[i]-QI[j][0]

        j+=1
    else:
        i+=1

    if i==b:
        for h in range(j,q):
            QLIST[QI[h][1]][2]=QI[h][0]-T[i-1]
        
        
for L1,R1,L2,R2 in QLIST:
    A=max(L1,L2)
    B=max(R1,R2)
    C=min(L1,R1)*2+min(L2,R2)
    D=min(L1,R1)+min(L2,R2)*2

    print(min(A,B,C,D)) 


Measured memory_bytes: 53728
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <fstream>
#include <numeric>
using namespace std;
typedef long long int ll;

#define EPS (1e-7)
#define INF 1e18
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define PI (acos(-1))

#define REP(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep(i, init, n) for(ll i = init; i <(ll)(n); i++)

int main() {

    int N;
    cin >> N;
    vector<vector<ll>> F(N, vector<ll>(10));
    vector<vector<ll>> P(N, vector<ll>(11));
    REP(i, N) REP(j, 10) cin >> F[i][j];
    REP(i, N) REP(j, 11) cin >> P[i][j];

    ll ans = -1e9;
    for(ll i = 1; i < (1<<10); i++){
        vector<ll> tmp(10);
        REP(j, 10) tmp[j] = (i >> j) & 1;
        //REP(j, 10) cout << tmp[j] << " ";
        //cout << endl;
        ll score = 0;
        REP(j, N){
            ll hoge = 0;
            REP(k, 10) hoge += F[j][k] * tmp[k];
            score += P[j][hoge];
        }
        ans = max(ans, score);
    }
    cout << ans << endl;
    return 0;
}



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

int main() {
  int a,b,c,d,x;
  cin>>x;
  a=x/1000;
  x%=1000;
  b=x/100;
  x%=100;
  c=x/10;
  d=x%10;

  if(7==a+b+c+d) printf("%d+%d+%d+%d=7\n",a,b,c,d);
  else if(7==a-b+c+d) printf("%d-%d+%d+%d=7\n",a,b,c,d);
  else if(7==a+b-c+d) printf("%d+%d-%d+%d=7\n",a,b,c,d);
  else if(7==a+b+c-d) printf("%d+%d+%d-%d=7\n",a,b,c,d);
  else if(7==a-b-c+d) printf("%d-%d-%d+%d=7\n",a,b,c,d);
  else if(7==a+b-c-d) printf("%d+%d-%d-%d=7\n",a,b,c,d);
  else if(7==a-b+c-d) printf("%d-%d+%d-%d=7\n",a,b,c,d);
  else if(7==a-b-c-d) printf("%d-%d-%d-%d=7\n",a,b,c,d);
}	


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
 
const int N = 100;
int L[2 * N] = { 0 };
 
int main(){
	int n, ans = 0;
	cin >> n;
	for(int i = 0; i < 2 * n; ++i)
	{
		cin >> L[i];
	}
	sort(L, L + 2 * n, greater<int>() );
	for(int i = 0; i < 2 * n; i += 2){
		ans += min(L[i], L[i + 1]);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
// Shortcut
 
#define int long long
#define endl '\n'
#define eb emplace_back
#define pb push_back
#define pob pop_back
#define mp make_pair
#define upb upper_bound
#define lwb lower_bound
#define fi first
#define se second
#define For(i, l, r) for (int i = l; i < r; i++)
#define ForE(i, l, r) for (int i = l; i <= r; i++)
#define Ford(i, r, l) for (int i = r; i > l; i--)
#define FordE(i, r, l) for (int i = r; i >= l; i--)
#define Fora(i, a) for (auto i : a)
 
// I/O & Debug
 
#define PrintV(a) for (int iiii = 0; iiii < a.size(); iiii++) cout << a[iiii] << ' ';
#define PrintVl(a) for (int iiii = 0; iiii < a.size(); iiii++) cout << a[iiii] << endl;
#define PrintA(a, n) for (int iiii = 0; iiii < n; iiii++) cout << a[iiii] << ' ';
#define PrintAl(a, n) for (int iiii = 0; iiii < n; iiii++) cout << a[iiii] << endl;
#define Ptest(x) return cout << x, 0;
#define gl(s) getline(cin, s);
#define setpre(x) fixed << setprecision(x)
/*
#define debug(args...){ string _sDEB = #args; replace(_sDEB.begin(), _sDEB.end(), ',', ' '); stringstream _ssDEB(_sDEB); istream_iterator<string> _itDEB(_ssDEB); DEB(_itDEB, args); }
void DEB(istream_iterator<string> it) {}
template<typename T, typename... Args>
void DEB(istream_iterator<string> it, T a, Args... args){
    cout << *it << " = " << a << endl;
    DEB(++it, args...);
}
*/
 
// Functions
 
#define isvowel(a) (a == 'a' || a == 'e' || a == 'i' || a == 'o' || a == 'u')
#define bend(a) a.begin(), a.end()
#define rbend(a) a.rbegin(), a.rend()
#define mset(a) memset(a, 0, sizeof(a));
#define mmset(a) memset(a, 0x3f, sizeof(a));
//mt19937 rando(chrono::steady_clock::now().time_since_epoch().count());
 
// Data Structure
 
#define pque priority_queue
#define mts multiset
typedef long long ll;
typedef long double ld;
typedef vector <int> vi;
typedef vector <ll> vll;
typedef vector <ld> vld;
typedef vector <string> vs;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef vector <vi > vvi;
typedef vector <vll > vvll;
typedef vector <pii > vpii;
typedef vector <pll > vpll;
 
const int N = 1e5 + 5, mod = 1e9 + 7, inf = 1e9 + 7;
 
signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    string s;
    cin >> s;
    ll ans = 0, t = (s[0] == 'A'), lt = 0;
    For(i, 1, s.length()){
        if (i >= 2 && s[i - 1] == 'B' && s[i] == 'C'){
            ans += lt;
            t = lt;
        }
        else if (s[i] == 'A'){
            t++;
            if (t != 1) lt++;
        }
        else{
            lt = t;
            t = 0;
        }
        //cout << lt << ' ' << t << ' ' << ans << endl;
    }
    cout << ans;
}
 
/*
==================================+
INPUT:                            |
------------------------------    |
 
------------------------------    |
==================================+
OUTPUT:                           |
------------------------------    |
 
------------------------------    |
==================================+
*/

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

const int N = 1e5+10;

vector<int> G[N];
bool visited[N];
vector<int> out; //トポロジカル順序

void dfs(int u){
  visited[u] = true;
  for(int v : G[u]){
    if(!visited[v]) dfs(v);
  }
  out.push_back(u);
}

//https://atcoder.jp/contests/nikkei2019-qual/tasks/nikkei2019_qual_d
signed main(){

  int n,m; cin >> n >> m;
  for(int i = 0; i < n-1+m; i++){
    int a,b; cin >> a >> b;
    G[a].push_back(b);
  }

  for(int i = 1; i <= n; i++){
    if(!visited[i]) dfs(i);
  }
  reverse(out.begin(),out.end());

  vector<int> dp(n+1,0);
  vector<int> ans(n+1,0);
  for(int i = 0; i < n; i++){
    for(int v : G[out[i]]){
      //vに近いのが出力すべき先祖
      if(dp[v] < dp[out[i]]+1){
        dp[v] = dp[out[i]]+1;
        ans[v] = out[i];
      }
    }
  }

  for(int i = 1; i <= n; i++){
    cout << ans[i] << endl;
  }

  return 0;
}


Measured memory_bytes: 12016
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
ll strtoint(string str);
int main(){
	fast;
	ll a,b,c,d; cin>>a>>b>>c>>d;
	ll mt=ceil((double)c/b),ma=ceil((double)a/d);
	if(mt<=ma)cout<<"Yes\n";
	else
		cout<<"No\n";
	return 0;
}
ll strtoint(string str){
	ll x=0;
	stringstream ss;
	ss<<str;
	ss>>x;
	return x;
}

Measured memory_bytes: 3748
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <utility>
#include <set>
#include <stack>
#include <climits>
#include <cmath>
#include <iomanip>

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define rep1(i,n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
#define reps(i,s,n) for(int i=s, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define MEMSET(v, h) memset((v), h, sizeof(v))
typedef long long ll;
const char sp = ' ';


using namespace std;

int main(void){
    ll N, K;
    cin>>N>>K;
    ll divi=1, dm=0, nec[30], la=N;
    MEMSET(nec, 0);
    while(true){
        if(la-K/divi<0){ divi*=2, dm++; continue;}
        nec[dm]=la-K/divi;
        la=K/divi;
        //cout<<dm<<sp<<nec[dm]<<endl;
        if(K%divi==0) la--, nec[dm]++;
        if(la==0) break;
        
        divi*=2;
        dm++;
    }
    ll dmcons=dm;
    //cout<<dmcons<<endl;
    double possi=0;
    divi=1;
    dm=0;
    while(true){
        possi+=(double)nec[dm]/((double)divi*(double)N);
        divi*=2;
        dm++;
        if(dmcons<dm) break;
    }
    cout<<setprecision(20)<<possi<<endl;
    return 0;
}


Measured memory_bytes: 256