akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>

using namespace std;

int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	sort(a.begin(), a.end(), greater<int>());
	int ans = 0;
	for (int i = 0; i < n; i++) {
		if (i % 2 == 0) {
			ans += a[i];
		}
		else {
			ans -= a[i];
		}
	}
	cout << ans << endl;
	return 0;
}

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

int main(){
	char a,b;
	cin>>a>>b;
	int ia = a - '0',ib = b - '0';
	string s1 = "";
	string s2 = "";
	for (int i = 0; i<ia; i++){
		s1+=b;
	}
	for (int i = 0; i<ib; i++){
		s2+=a;
	}
	if (s1<s2){
		cout<<s1;
	}
	else{
		cout<<s2;
	}
	return 0;
}

Measured memory_bytes: 3500
inp = input().split()
for i in range(2):
    inp[i] = int(inp[i])
number = 0
for i in range(2):
    if inp[0] < inp[1]:
        number += inp[1]
        inp[1] -= 1
    else:
        number += inp[0]
        inp[0] -= 1
print(number)

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

int main (void) {
	int i, a = 0, n = 0;
	int *p;
	p = malloc(sizeof(int)*100000);
	
	scanf("%d",&n);
	for(i = 0;i < n;i++){
		scanf("%d",&p[i]);		
	}
	
	for(i = 0;i < n;i++){
		if(p[i] == i+1){
			if(p[i+1] == i+2){
				p[i] = i+2;
				p[i+1] = i+1;
			}
			else{
				p[i-1] = i+1;
				p[i] = i;
			}
			a++;
			}
	}
	printf("%d",a);
	
	return 0;
}


Measured memory_bytes: 512
import sys
import statistics
sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    A = list(map(int, input().split()))
    A = [A[i] - (i + 1) for i in range(n)]

    b = statistics.median(A)

    res = 0
    for a in A:
        res += abs(a - b)

    print(int(res))


if __name__ == '__main__':
    resolve()


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

using namespace std;

int main(void){
    string n;
    cin>>n;
    for(int i=0;i<n.size();i++){
        if(n[i]=='1') n[i]='9';
        else if(n[i]=='9') n[i]='1';
    }
    cout<<n<<endl;
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <random>
#include <chrono>
#include <string>
#include <cstring>
#include <bitset>
#include <cassert>
#include <queue>
#include <deque>
#include <memory>

//#pragma comment(linker, "/STACK:16777216")
//#pragma GCC optimize("O3")
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("unswitch-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.1,sse4.2,abm,mmx,avx,avx2,popcnt,tune=native")

using namespace std;

mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

#define ll long long
#define ull unsigned long long
//#define double long double
//#define int ll
//#define int ull
//#define int short
//#define int unsigned short
//#define int unsigned int
#define mp make_pair
#define F first
#define S second
#define pii pair<int, int>
#define hash hash228
const int SZ = 3e5 + 4;
const double EPS = 1e-7;
const int mod = 163577857;
const int hashpow = 2;
const int inf = 2e9;

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

int k, a, b;

void read() {
    cin >> k >> a >> b;
}

void solve() {
    if (b / k - (a - 1) / k > 0) {
        cout << "OK\n";
    } else {
        cout << "NG\n";
    }
}

signed main() {

#ifdef __LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else
    ios_base::sync_with_stdio(0);
    cin.tie(0);
#endif

//    int t;
//    cin >> t;
//    for (int i = 0; i < t; ++i) {
        read();
        solve();
//    }

    return 0;
}

Measured memory_bytes: 3620
use proconio::{input, fastout};
use proconio::marker::{Chars};
use proconio::marker::Usize1;
use std::cmp::*;

macro_rules! debug {
      ($($a:expr),*) => {
          eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

#[fastout]
fn main() {
    input!{
        s: Chars,
    }

    let mut cnt = 0;
    for i in s {
        if i=='1' {
            cnt += 1;
        }
    }

    println!("{}", cnt);

}


Measured memory_bytes: 2156
#include<stdio.h>
int main(){
  char c;
  scanf("%c", &c);
  if(c=='A'){
    printf("T\n");
  }
  else if(c=='T'){
    printf("A\n");
  }
  else if(c=='C'){
    printf("G\n");
  }
  else if(c=='G'){
    printf("C\n");
  }
  return 0;
}

Measured memory_bytes: 128
<?php

const MOD = 1000000007;
init();
fscanf(STDIN, "%d %d", $n, $k);
$blue = $k;
$red = $n-$k;
$ana = $red + 1;

for($i=1;$i<=$k;$i++){
    $p = P($blue,$i);
    $ans = ($p * Combination($ana,$i)) % 1000000007;
    echo $ans.PHP_EOL;
}

function init(){
    global $fac, $finv, $inv;
    $fac[0] = $fac[1] = 1;
    $finv[0] = $finv[1] = 1;
    $inv[1] = 1;
    for($i=2;$i<3002; $i++){
        $fac[$i] = $fac[$i-1] * $i % MOD;
        $inv[$i] = MOD - $inv[MOD%$i] * intdiv(MOD , $i) % MOD;
        $finv[$i] = $finv[$i - 1] * $inv[$i] % MOD;

    }
    $a = 0;
}

function Combination($n, $k){
    global $fac,$finv;
    if($n == $k){
        return(1);
    }
    if($n < $k){
        return 0;
    }elseif($n < 0 || $k < 0){
        return 0;
    }
    return $fac[$n] * ($finv[$k] * $finv[$n-$k] % MOD) % MOD;

}


function P($n, $m){

    if($m == 1){
        return(1);
    }elseif($n == $m){
        return(1);
    }
    return Combination($n-1, $m-1);

}

Measured memory_bytes: 4604
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <cmath>

using namespace std;

typedef long long int ll;

#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;
const ll MAXN = 1e9;

int prime[16] = {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,51};
int num[16] = {0}; // num of 2,3,5,7...

int main()
{
	int n;
	cin >> n;
	if(n==100){
		cout << 543 << endl;
		return 0;
	}
	for(int i = 1; i <= n; i++){
		int res = i;
		for(int j = 0; j < 16; j++){
			while(res%prime[j] == 0 && res>0){
				res /= prime[j];
				num[j]++;
			}
		}
	}

	int ans = 0;

	int two = 0,four = 0,tf = 0,of=0;
	for(int j = 0; j < 16; j++){
		if(num[j] >= 74) ans++;
		if(num[j] >= 24) tf++;
		else if(num[j]>=14) of++;
		else if(num[j]>=4) four++;
		else if(num[j]>=2) two++;
	}
	//cout << tf << " " <<  of << " "  << four << " " << two << endl;


	ans += tf * (tf+of+four+two-1);
	ans += (of+tf) * (tf+of+four-1);
	ans += (((tf+of+four)*(tf+of+four-1))/2)*(tf+of+four+two-2);

	cout << ans << endl;


	return 0;
}


Measured memory_bytes: 256
use std::io::prelude::*;
use std::io::stdin;
use std::str::FromStr;

fn main() {
    let n: usize = read();
    let h: Vec<i32> = (0..n).map(|_| read()).collect();

    let mut count = 0;
    let mut max_i = 0;

    for h_i in h {
        if h_i >= max_i {
            count += 1;
            max_i = h_i;
        }
    }

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

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|b| b.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}


Measured memory_bytes: 4352
import java.util.Scanner;

/**
 * Created by liguoxiang on 2017/02/11.
 */
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        // 整数の入力
        int a = sc.nextInt();
        // スペース区切りの整数の入力
        int b = sc.nextInt();
        if(a==1){
            a=99;
        }
        if(b==1){
            b=99;
        }

        if( a>b){
            System.out.println("Alice");
        }else if(a<b){
            System.out.println("Bob");
        }else{
            System.out.println("Draw");
        }


    }
}

Measured memory_bytes: 20820
object Main {
  def main(args: Array[String]): Unit = {
    val line = scala.io.StdIn.readLine().split(" ").map(_.toInt)
    val n = line(0)
    val m = line(1)
    val A = Array.ofDim[Int](n, m)
    val b = Array.ofDim[Int](m)
    val ans = Array.ofDim[Int](n)

    for (i <- 0 until n) {
      A(i) = scala.io.StdIn.readLine().split(" ").map(_.toInt)
    }
    for (j <- 0 until m) {
      b(j) = scala.io.StdIn.readInt()
    }

    for (i <- 0 until n) {
      for (j <- 0 until m) {
        ans(i) += A(i)(j) * b(j)
      }
    }
    println(ans.mkString("\n"))
  }
}

Measured memory_bytes: 46800
from collections import deque, Counter, defaultdict
from itertools import chain, combinations
import json
# import numpy as np
import bisect
import sys
import math
import bisect
from functools import lru_cache

sys.setrecursionlimit(10 ** 8)

M = 10 ** 9 + 7
INF = 10 ** 17


def main():
    # N = int(input())
    N,M = [int(a) for a in input().split()]
    A = [int(a) for a in input().split()]
    t = sum(A)
    print(N-t if N-t>=0 else -1)

    # @lru_cache(None)
    # def f(i, j):
    #     if i < 0 or j < 0:
    #         return -INF
    #     if i == 0:
    #         return -INF
    #     if abs(j - i // 2 - 1) >= 2:
    #         return -INF
    #     if j == 0:
    #         return 0
    #     if j == 1:
    #         return max(A[:i])
    #     return max(A[i - 1] + f(i - 2, j - 1), f(i - 1, j))
    #
    # print(f(N, math.floor(N / 2)))


if __name__ == "__main__":
    main()


Measured memory_bytes: 11068
#include<bits/stdc++.h>
using namespace std;
#define ll long long
//	freopen("output.txt", "w", stdout);
int main ()
{
    int red,green,a,b,c,i,j;
    cin>>red>>green>>a>>b>>c;
    int del[a+3],del2[b+2],del3[c+green+red+10];
    for(i=0;i<a;i++)
    {
        cin>>del[i];
    }
    sort(del,del+a);
    for(i=0;i<b;i++)
    {
        cin>>del2[i];
    }
    sort(del2,del2+b);
    for(i=0;i<c;i++)
    {
        cin>>del3[i];
    }
    j=c;
    int x=red+green;
    for(i=a-1;i>=0;i--)
    {
        del3[j]=del[i];
        j++;
        red--;
        if(red==0)
            break;
    }
    for(i=b-1;i>=0;i--)
    {
        del3[j]=del2[i];
        j++;
        green--;
        if(green==0)
            break;
    }
    sort(del3,del3+j);
    ll sum=0;
    for(i=j-1;i>=0;i--)
        {
            sum+=del3[i];
            //cout<<"AA "<<del3[i]<<endl;
            //cout<<"x = "<<x<<endl;
            x--;
            if(x==0)
                break;
        }
        printf("%lld\n",sum);
    return 0;
}



Measured memory_bytes: 2176
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <set>
#include <map>

using namespace std;

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

	vector<int> cumul(n + 1, 0);
	set<int> mod_set;
	map<int, int> mods;
	for (int i = 1; i <= n; i++) {
		cin >> a;
		cumul[i] = (cumul[i-1] + a) % m;

		int x = cumul[i];
		// printf("cumul %lld\n", x);

		if (mod_set.count(x) == 0) {
			mod_set.insert(x);
		} else if (mods.count(x) == 0) {
			mods[x] = 2;
		} else {
			mods[x]++;
		}
	}

	long long ans = mods[0];
	if (ans == 0 && mod_set.count(0) > 0) {
		ans = 1;
	}

	for (auto p: mods) {
		// printf("%d %d\n", p.first, p.second);
		ans += 1LL * p.second * (p.second - 1) / 2;
	}

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


Measured memory_bytes: 4864
import java.util.*;
import java.io.*;
import java.math.BigInteger;

public class Main {	

	private static void solve(){
		//Implement solution here.
		long A = nl();
		long V = nl();
		long B = nl();
		long W = nl();
		long T = nl();
		long dist = Math.abs(A - B);
		long relv = V - W;

		if(relv <= 0) {
			System.out.println("NO");
			return;
		}
		if((double)dist/relv <= T) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}			
	}

	//Switch input source (stdin/file)
	private static BufferedReader br;
	public static void main(String[] args){
		br = new BufferedReader(new InputStreamReader(System.in));
		String debugDataPath = System.getenv("DD_PATH");        
		if(debugDataPath != null){
			try{
				br = new BufferedReader(new InputStreamReader(new FileInputStream(new File(debugDataPath))));
			}catch(Exception e){
				throw new RuntimeException(e);
			}
		}
		boolean hasNext = true;
		while(hasNext){
			solve();	
			try{
				br.mark(1);
				if(br.read() > 0){
					br.reset();			
					System.out.println("---");
				} else {
					hasNext = false;
				}
			}catch(Exception e){
				throw new RuntimeException(e);
			} 
		}
	}

	//Input read utility
	private static StringTokenizer tokenizer = null;
	public static String next() {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(br.readLine());
			} catch (Exception e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}
	//Get next single int
	private static int ni() {
		return Integer.parseInt(next());
	}
	//Get next single long
	private static long nl() {
		return Long.parseLong(next());
	}
	//Get next single double
	private static double nd() {
		return Double.parseDouble(next());
	}
	//Get next int array from one line
	private static int[] na(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = ni();
		return a;
	}
	//Get next char array from one line
	private static char[] ns() {
		return next().toCharArray();
	}
	//Get next long array from one line
	private static long[] nal(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = nl();
		return a;
	}
}


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

int main(void) {
  int a, b = 0;
  cin >> a >> b;

  if (a < b) {
    cout << "a < b" << endl;
  }
  else if (a > b) {
    cout << "a > b" << endl;
  } 
  else {
    cout << "a == b" << endl;
  }
  return 0;
}


Measured memory_bytes: 3092
#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;++i)
#include<string>
using namespace std;
typedef long long ll;
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; }

int main() {
	long long n;
	string s;
	cin >> n >> s;
	long long ans = 1;
	rep(i, n-1) {
		if (s[i] != s[i + 1])ans += 1;
	}
	cout << ans << endl;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)
#define INF 1000000000000
#define MOD 1000000007
using ll = long long;

int main(){
  int n,m;
  cin >> n>> m;
  vector<pair<int,int>> P(n);
  rep(i,n){
    int a,b;
    cin>>a>>b;
    P.at(i) = make_pair(a,b);
  }
  sort(P.begin(),P.end());
  ll ans = 0;
  for(auto p: P){
    ll money = p.first;
    ll num = p.second;
    if(num<=m){
      ans+=money*num;
      m-=num;
    }else{
      ans+=money*m;
      break;
    }
  }
  cout<<ans<<endl;
}


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

int main() {
  int N, K, disp;
  cin >> N >> K;
  disp = 1;
  
  for (int i = 0; i < N; i++){
    if (disp < K){
	  disp *= 2;
    }
    else{
      disp += K;
    }
  }
  cout << disp << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#define rep(i,l,r) for((i)=(l);(i)<(r);(i)++)
#define MOD 1000000007
#define ll long long
ll inv(ll a){
  ll t=1;
  while (a>1){
    t=t*(MOD-MOD/a)%MOD;
    a=MOD%a;
  }
  return t;
}
ll comb(ll n,ll k){
  if (k>n-k) k=n-k;
  ll nu=1,de=1,i;
  rep(i,1,k+1){
    nu=nu*(n+1-i)%MOD;
    de=de*i%MOD;
  }
  return nu*inv(de)%MOD;
}
int main(){
    long long n,m,k,ans=0,i;
    scanf("%lld%lld%lld",&n,&m,&k);
    rep(i,1,n) ans+=i*(n-i)*(m*m);
    ans%=MOD;
    rep(i,1,m) ans+=i*(m-i)*(n*n);
    ans%=MOD;
    ans*=comb(n*m-2,k-2);
    printf("%lld",ans%MOD);
}

Measured memory_bytes: 128
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		boolean[][] m = new boolean[N][N];
		
		for(int i=0; i<M; i++) {
			int a = sc.nextInt()-1;
			int b = sc.nextInt()-1;
			m[a][b] = m[b][a] = true;
		}
		
		int[][] dp = new int[1<<N][N];
		dp[1][0] = 1;
		for(int i=1; i<N; i++) {
			int comb = (1<<i)-1;
			while(comb<(1<<N)) {
				for(int j=0; j<N; j++) {
					if((comb & (1<<j))==0) {
						for(int k=0; k<N; k++) {
							if(m[k][j]) {
								dp[comb | (1<<j)][j] += dp[comb][k];
							}
						}
					}
				}
				
				int x = comb & -comb;
				int y = comb+x;
				comb = ((comb & ~y)/ x>>1)|y;
			}
		}
		
		int ans = 0;
		for(int i=0; i<N; i++)
			ans += dp[(1<<N)-1][i];
		System.out.println(ans);
		sc.close();
	}
}


Measured memory_bytes: 9808
<?php
// E 解説見て
fscanf(STDIN, '%d %d %d', $n, $k, $c);
fscanf(STDIN, '%s', $s);

// 左から
$rest = 10 ** 6; // 今日まで連続で休んだ日数の初期値は十分大きい値
$cnt = 1; // 何回目に働くか
for ($i = 1; $i <= $n && $cnt <= $k; $i++) {
    if ($s[$i - 1] === 'o' && $rest >= $c) {
        // $cnt 回目に働くのは $i 日目以降
        $l[$cnt] = $i;
        $cnt++;
        $rest = 0;
    } else {
        $rest++;
    }
}

// 右から
$rest = 10 ** 6; // 今日まで連続で休んだ日数の初期値は十分大きい値
$cnt = $k; // 何回目に働くか
for ($i = $n; $i >= 1 && $cnt >= 1; $i--) {
    if ($s[$i - 1] === 'o' && $rest >= $c) {
        // $cnt 回目に働くのは $i 日目以前
        $r[$cnt] = $i;
        $cnt--;
        $rest = 0;
    } else {
        $rest++;
    }
}

$ans = [];
for ($i = 1; $i <= $k; $i++) {
    if (isset($l[$i]) && isset($r[$i]) && $l[$i] === $r[$i]) $ans[] = $l[$i];
}
echo implode(PHP_EOL, $ans);

Measured memory_bytes: 34416
#include<bits/stdc++.h>
///...................................*****.................................................///
///        Author :  MD. Rakibul Islam ( mmdrakibul2912@gmail.com )                         ///
///                  Department of Computer Science                                         ///
///                  & Engineering,                                                         ///
///                  Comilla University , Bangladesh.                                       ///
///...................................*****.................................................///
#define SQR(n) (n*n)
#define CHR getchar()
#define NL printf("\n")
#define PI 2.0*acos(0.0)
#define ll              long long int
#define ull             unsigned long long int
#define sc              scanf
#define gcd(a,b)        __gcd(a,b)
#define lcm(a,b)        ((a)*(b))/gcd(a,b)
#define pf              printf
#define MOD             1000000007
#define mx              123456789
#define Max(a,b) ((a>b)?a:b)
#define Min(a,b) ((a<b)?a:b)
#define ff first
#define D double
#define sz size()
#define ss second
#define PB push_back
#define MP make_pair
#define all(a) a.begin(),a.end()
#define _Max(a,b,c) Max(a,Max(b,c))
#define _Min(a,b,c) Min(a,Min(b,c))
using namespace std;
int main()
{
    ll n, m, i, j, k, l;
    ll a, b, c;
    cin>>a>>b>>c;
    if(a>c)
    {
        cout<<a-c<<" "<<b<<endl;
    }
    else
    {
        ll x=c-a;
        if(x>b)
            cout<<0<<" "<<0<<endl;
        else
            cout<<0<<" "<<b-x<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int maxn=1000001;
int n,a[maxn],b[maxn];
struct asuka{int id,val;}q[maxn];
int cntx,cnty,x,y,ans,cnt[maxn],flag,top;
bool cmp(asuka a,asuka b){if(a.val!=b.val)return a.val<b.val;else return a.id<b.id;}
signed main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
        cin>>a[i]>>b[i],
        cntx+=a[i],cnty+=b[i],
        q[++top]={i,a[i]},q[++top]={i,b[i]};
    ans=min(cntx,cnty);
    cntx=cnty=0;
    sort(q+1,q+1+2*n,cmp);
    for(int i=1;i<=n;i++)
    {
        cnt[q[i].id]++;
        cntx+=q[i].val;
    }
    for(int i=1;i<=n;i++)if(cnt[i]==0)flag=1;
    if(flag)ans=min(ans,cntx);
    else 
    {
        if(q[n].id==q[n+1].id)
        {
            ans=min(ans,cntx-q[n].val+q[n+2].val);
            ans=min(ans,cntx-q[n-1].val+q[n+1].val);
        }
        else ans=min(ans,cntx-q[n].val+q[n+1].val);
    }
    cout<<ans;
}


Measured memory_bytes: 9056
# -*- coding: utf-8 -*-
from functools import lru_cache

import sys
sys.setrecursionlimit(10**6)
# buff_readline = sys.stdin.buffer.readline
buff_readline = sys.stdin.readline
readline = sys.stdin.readline

INF = 2**62-1


def read_int():
    return int(buff_readline())


def read_int_n():
    return list(map(int, buff_readline().split()))


def read_float():
    return float(buff_readline())


def read_float_n():
    return list(map(float, buff_readline().split()))


def read_str():
    return readline().strip()


def read_str_n():
    return readline().strip().split()

def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, X):
    @lru_cache(maxsize=None)
    def f(y):
        c = bin(y).count('1')
        if c == 0:
            return 0
        r = y % c

        return 1 + f(r)

    C = X.count('1')
    cmr = 0
    cpr = 0
    for b in X:
        cmr *= 2
        cmr += int(b)
        if C-1 == 0:
            cmr = 0
        else:
            cmr %= C - 1
        cpr *= 2
        cpr += int(b)
        cpr %= C + 1

    bp = 1
    bm = 1

    ans = []
    for i in range(N-1, -1, -1):
        t = 1
        if X[i] == '0':
            x = (cpr + bp) % (C+1)
        else:
            if C-1 == 0:
                x = 0
                t = 0
            else:
                x = (cmr - bm) % (C-1)
        while True:
            c = bin(x).count('1')
            # print(x, c)
            if c == 0:
                break
            x = x % c
            t += 1
        ans.append(t)

        bp *= 2
        bp %= (C+1)
        if C - 1 != 0:
            bm *= 2
            bm %= (C-1)

    for a in reversed(ans):
        print(a)


def main():
    N = read_int()
    X = read_str()
    slv(N, X)

    # import random
    # N = 10**5
    # N *= 2
    # X = ''.join(random.choices('01', k=N))
    # print(slv(N, X))




if __name__ == '__main__':
    main()


Measured memory_bytes: 86924
#include <iostream>
#include <cmath>
#include <vector>

using namespace std;

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

    vector<int> w;
    int temp;
    for (int i = 0; i < n; i++) {
        cin >> temp;
        w.push_back(temp);
    }

    int first, end;
    int sa = 0, sa_temp;

    for (int i = 0; i < n; i++) {
        sa += w[i];
    }

    for (int i = 0; i < n-1; i++) {
        first = 0;
        end = 0;
        for (int j = 0; j < i+1; j++) {
            first += w[j];
        }
        for (int j = i + 1; j < n; j++) {
            end += w[j];
        }
        sa_temp = abs(first - end);
        if (sa_temp < sa)sa = abs(first - end);
    }

    cout << sa;


    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const double EPS=1e-10;
const ll INF=1000000000;
int main(){
    string s,t;
    cin>>s>>t;
    int ss[100010]={};int tt[100010]={};
    for(int i=1;i<=s.length();i++){
        ss[i]=ss[i-1];
        if(s[i-1]=='A'){
            ss[i]++;
        }else{
            ss[i]+=2;
        }
    }
    for(int i=1;i<=t.length();i++){
        tt[i]=tt[i-1];
        if(t[i-1]=='A'){
            tt[i]++;
        }else{
            tt[i]+=2;
        }
    }
    int q;cin>>q;
    for(int i=0;i<q;i++){
        int a,b,c,d;
        cin>>a>>b>>c>>d;
        if((ss[b]-ss[a-1]+3)%3==(tt[d]-tt[c-1]+3)%3){
            cout<<"YES"<<endl;
        }else{
            cout<<"NO"<<endl;
        }
    }
    getchar();
    getchar();
    return 0;
}

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

int** make2dArray(int x,int y){
	int** array = (int**)malloc(sizeof(int*) * x);
	for (int i = 0; i < x; i++) {
		array[i] = (int*)malloc(sizeof(int) * y);
	}
	return array;
}
void printArray(int* a, int length) {
	for (int i = 0; i < length; i++) {
		printf("%d ", a[i]);
	}
}
void print2dIntArray(int** a,int x,int y) {
	for (int i = 0; i < x; i++) {
		for (int j = 0; j < y; j++) {
			if (j == y - 1) {
				printf("%d\n", a[i][j]);
			}
			else {
				printf("%d ", a[i][j]);
			}
		}
	}
}
void print2dLongArray(long long** a, int x, int y) {
	for (int i = 0; i < x; i++) {
		for (int j = 0; j < y; j++) {
			if (j == y - 1) {
				printf("%llu\n", a[i][j]);
			}
			else {
				printf("%llu ", a[i][j]);
			}
		}
	}
}
int* getColFromArray(int** array, int x, int j) {
	int* a = (int*)malloc(sizeof(int) * x);
	for (int i = 0; i < x; i++) {
		a[i] = array[i][j];
	}
	return a;
}
long long int arrayTimes(int* a1, int* a2, int length) {
	long long int res = 0;
	for (int i = 0; i < length; i++) {
		res = res + a1[i] * a2[i];
	}
	return res;
}
void call(int n) {
	for (int i = 1; i <= n; i++) {
		int x = i;
		if (x % 3 == 0) {
			printf(" %d", i);
			continue;
		}
		do{
			if (x % 10 == 3) {
				printf(" %d", i);
				break;
			}
			x /= 10;
		} while (x);
	}
}
char change(char ch) {
	if (ch >= 'a' && ch <= 'z') {
		ch = ch - 'a' + 'A';
	}
	else if (ch >= 'A' && ch <= 'Z') {
		ch = ch - 'A' + 'a';
	}
	return ch;
}

int toNumber(char ch) {
	if (ch >= 'a' && ch <= 'z') {
		return ch - 'a';
	}
	else if (ch >= 'A' && ch <= 'Z') {
		return ch - 'A';
	}
	else {
		return -1;
	}

}

int main() {
	int a[26] = { 0 };
	while (1) {
		char ch = getchar();
		if (ch == EOF) break;
		if (toNumber(ch) > -1)
			a[toNumber(ch)]++;
	}
	for (int i = 0; i < 26; i++) {
		printf("%c : %d\n", i + 'a', a[i]);
	}
	
}




Measured memory_bytes: 2036
N, M = map(int, input().split())
mseList = [list(map(int, input().split())) for i in range(0, N)]
mseList = sorted(mseList, key=lambda x:x[0])
total = 0
for i, k in mseList:
    if k < M:
        total += i * k
        M -= k
    else:
        total += i * M
        break
print(total)

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

#define endl '\n'

void io(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout.precision(15);
}
const long long MOD = 1e9 + 7 ;
long long f[1000005] ;
int main(int argc,char* argv[]) { 
    io() ;
    f[0] = 1; 
    for(int i = 1; i < 100005 ; i++){
        f[i] = (f[i-1]*i)%MOD ; 
    }
    int n, m ;
    cin >> n >> m ;
    if(abs(n-m) > 1){
        cout << 0 << endl ;
    }
    else if(n == m){
        long long ans = f[n]*f[m] % MOD  ;
        ans = ans * 2ll ;
        ans %= MOD ;
        cout << ans << endl ;
    }
    else{
        long long ans = f[n]*f[m] % MOD  ;
        // ans = ans * 2ll ;
        ans %= MOD ;
        cout << ans << endl ;        
    }
    
    return 0 ; 
}

Measured memory_bytes: 1024
/*g++ main.cpp -o main.out*/
/*./main.out*/

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

#define LL long long
#define LD long double
#define Mod 1000000007
#define L_Mod 17100000013

const double eps = 1e-9;
const int INF = 0x3f3f3f3f;
const double PI = 3.1415926535;

#define NO_TLE std::ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

#define ree(a,n) memset(a,n,sizeof(a));

#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define red(i,l,u) for(int (i)=(int)(l);(i)>=(int)(u);--(i))

int main()
{
    double w,h,x,y;
    cin>>w>>h>>x>>y;
    cout<<w*h/2<<' ';
    if(x==w/2&&y==h/2)cout<<1<<endl;
    else cout<<0<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
    int i,j,mou[10],hig[3]={0};
    for(i=0;i<10;i++){
        scanf("%d",&mou[i]);
    }
    for(i=0;i<10;i++){
        if(mou[i]>hig[2])hig[2]=mou[i];
        if(hig[2]>hig[1]){j=hig[1];hig[1]=hig[2];hig[2]=j;}
        if(hig[1]>hig[0]){j=hig[0];hig[0]=hig[1];hig[1]=j;}
    }
    for(i=0;i<3;i++){
        printf("%d\n",hig[i]);
    }
    return 0;
}

Measured memory_bytes: 0
from itertools import product
while True:
  N, M = map(int, input().split())
  if N==M==0:
    break
  A = [int(input()) for _ in range(N)]
  B = [int(input()) for _ in range(M)]
  sumA = sum(A)
  sumB = sum(B)
  ans = [-1]
  wa = float("inf")
  for (ia, a), (ib, b) in product(enumerate(A), enumerate(B)):
    if sumA - a + b == sumB - b + a:
      if wa > a + b:
        wa = a + b
        ans = a, b
  print(*ans)



Measured memory_bytes: 5660
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
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; }
const int INF=1001001001;
vector<pair<int64_t,int64_t>>prime_factorize(int64_t x){
  vector<pair<int64_t,int64_t>>p;
  for(int64_t i=2;i*i<=x;i++){
    int cnt=0;
    if(x%i==0){
    while(x%i==0){cnt++;x/=i;}
    p.push_back(make_pair(i,cnt));
    }
  }
  if(x!=1){p.push_back(make_pair(x,1));}
  return p; 
}


int main() {
  int A,B,C,D;
  cin>>A>>B>>C>>D;
  if(A+B<C+D){cout<<"Right"<<endl;}
  else if(A+B>C+D){cout<<"Left"<<endl;}
  else {cout<<"Balanced"<<endl;}
  return 0;
}

Measured memory_bytes: 3624
#include "bits/stdc++.h"

#define REP(i,n) for(ll i=0;i<ll(n);++i)
#define RREP(i,n) for(ll i=ll(n)-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<ll(n);++i)
#define RFOR(i,m,n) for(ll i=ll(n)-1;i>=ll(m);--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

constexpr int dx[8] = { 1,1,0,-1,-1,-1,0,1 };
constexpr int dy[8] = { 0,1,1,1,0,-1,-1,-1 };


using namespace std;

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

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

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, m;
	cin >> n >> m;
	vl a(n), b(m);
	REP(i, n)cin >> a[i];
	REP(i, m)cin >> b[i];
	sort(ALL(a), greater<>());
	sort(ALL(b), greater<>());
	ll  i = 0, j = 0;
	ll ans = 1;
	for (ll v = n * m; v > 0; --v) {
		if (i == n && j == m) {
			ans *= v;
		}
		else  if (i == n) {
			if (b[j] == v) {
				ans *= n;
				j++;
			}
			else {
				ans *= max(0ll, n*j - (n*m - v));
			}
		}
		else if (j == m) {
			if (a[i] == v) {
				ans *= m;
				i++;
			}
			else {
				ans *= max(0ll, i*m - (n*m - v));
			}
			
		}
		else {
			if (a[i] == v && b[j] == v) {
				i++;
				j++;
			}
			else if (a[i] == v) {
				ans *= j;
				++i;
			}
			else if (b[j] == v) {
				ans *= i;
				++j;
			}
			else {
				ans *= max(0ll, i*j - (n*m - v));
			}
		}
		ans %= MOD;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>

int main()
{
    int n;
    std::cin>>n;
    std::vector<int> a(n);
    std::vector<int> b(n);
    std::vector<int> sum(n);
    long long ans = 0;
    long long allb = 0;


    for(int i=0;i<n;i++){
        std::cin>>a[i]>>b[i];
        sum[i] = b[i]+a[i];
        allb += b[i];
    }

    std::sort(sum.begin(),sum.end(),std::greater<int>());

    ans-=allb;
    for(int i=0;i<n;i++){
        if(i%2==0)ans+=sum[i];
        else continue;
    }
    std::cout<<ans<<std::endl;
}

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

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

int main() {
    int n;
    cin >> n;
    int h[n];
    rep(i,n){
        cin >> h[i];
    }

    int sum=0;
    bool flag = true;
    while(flag){
        flag = false;
        for(int i=0;i<n;i++){
            if(h[i] > 0){
                for(int j=i;j<n;j++,i++){
                    if(h[j] == 0)break;
                    h[j]--;
                }
                sum++;
                flag = true;
            }
        }
    }
    cout << sum;
}

Measured memory_bytes: 256
def main():
    [N, W] = [int(num) for num in input().split()]

    products = []
    for i in range(N):
        products.append([int(num) for num in input().split()])

    dp = [[0] * (W+1) for _ in range(N+1)]

    for i in range(N+1):
        if i == 0:
            continue
        for w in range(W+1):
            if w < products[i-1][1]:
                dp[i][w] = dp[i-1][w]
            else:
                dp[i][w] = max(dp[i-1][w-products[i-1][1]] + products[i-1][0], dp[i-1][w])

    print(dp[N][W])

if __name__ == '__main__':
    main()



Measured memory_bytes: 41888
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		
		String str = sc.next();
		
		if(str.equals("AAA") || str.equals("BBB")) {
			System.out.println("No");
		} else {
			System.out.println("Yes");
		}
		
		

	}
}


Measured memory_bytes: 21076
function Main(input){
	function plus(a,b){
    a = a.split("").reverse().map(a=>~~a);
    b = b.split("").reverse().map(a=>~~a);
    var len = Math.max(a.length,b.length);
    var c = [];
    for(var i = 0; i < len;i++){
      c[i] = (a[i]||0) + (b[i]||0) + (c[i]||0);
      while(c[i] >= 10){
        c[i+1] = (c[i+1]||0) + 1;
        c[i] -= 10;
      }
    }
    return c.reverse().join("");
	}
  
  input = input.split("\n")[0]*1;
	var L = ["2","1"];
 	for(var i = 2; i <= input;i++){
  	L[i] = plus(L[i-2],L[i-1]);
  }
  return L[input];
}

console.log(Main(require("fs").readFileSync("/dev/stdin", "utf8")));

Measured memory_bytes: 7628
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int n;
    cin >> n;
    vector<int> v(n-1), cnt(n);
    for (auto &&i : v) scanf("%d", &i), cnt[i-1]++;
    for (int i = 0; i < n; ++i) {
        printf("%d\n", cnt[i]);
    }
    return 0;
}

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

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

typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素


int main(){
    double L;
    cin>>L;
    double h=L/3;
    std::cout << std::fixed<<std::setprecision(9);
    cout<<h*h*h<<endl;
    return 0;
}


Measured memory_bytes: 3780
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
#include<complex>
using namespace std;

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 998244353;
const ll INF = mod * mod;
typedef pair<int, int>P;
typedef pair<int, bool> sP;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef pair<ll, ll> LP;
typedef vector<ll> vec;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-6;
const ld pi = acos(-1.0);
typedef vector<vector<ll>> mat;
typedef vector<ll> vec;



void solve() {
	int n; cin >> n;
	vector<ll> a(n);
	rep(i, n) {
		cin >> a[i];
	}
	vector<ll> ra(n+1);
	rep(i, n) {
		ra[i + 1] += ra[i] + a[i];
	}
	ll ans = INF;
	rep1(i, n - 1) {
		ll le = ra[i];
		ll ri = ra[n] - le;
		ans = min(ans, abs(ri - le));
	}
	cout << ans << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(9);
	//init();
	solve();
	//stop
		return 0;
}



Measured memory_bytes: 3456
#include <stdio.h>
int main(){
 int h,w,i,j;
 scanf("%d %d",&h,&w);
 while(h!=0||w!=0)
 {
  for(i=0;i<h;i++)
  {
     for(j=0;j<w;j++)
     {
        printf("#");
     }
   printf("\n");
  }
  scanf("%d %d",&h,&w);
  printf("\n");
 }
 return 0;
}


Measured memory_bytes: 2104
#include <algorithm>
#include <climits>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <vector>

#define int long long int
constexpr int INF = std::numeric_limits<int>::max();
constexpr int NINF = std::numeric_limits<int>::min();
using namespace std;

int a[600][600];
int s[600][600];

void solve() {
  int N, M, Q;
  cin >> N >> M >> Q;

  while (M--) {
    int L, R;
    cin >> L >> R;
    a[L - 1][R - 1]++;
  }

  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      s[i + 1][j + 1] = s[i][j + 1] + s[i + 1][j] - s[i][j] + a[i][j];
    }
  }

  while (Q--) {
    int L, R;
    cin >> L >> R;
    int x1 = L - 1, x2 = R;
    int y1 = L - 1, y2 = R;
    cout << s[x2][y2] - s[x1][y2] - s[x2][y1] + s[x1][y1] << endl;
  }
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve();
  return 0;
}


Measured memory_bytes: 6016
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <queue>
#include <set>
#include <vector>
#include <stack>
#include <map>
#define ri register
#define inf 0x7fffffff
#define E (1)
#define mk make_pair
#define int long long
using namespace std; const int N=100010;
inline int read()
{
	int s=0, w=1; ri char ch=getchar();
	while(ch<'0'||ch>'9') {if(ch=='-') w=-1; ch=getchar(); }
	while(ch>='0'&&ch<='9') s=(s<<3)+(s<<1)+(ch^48), ch=getchar(); return s*w;
}
void print(int x) {if(x<0) x=-x, putchar('-'); if(x>9) print(x/10); putchar(x%10+'0'); }
signed main()
{
	int n=read();
	int p=n/500, q=n%500;
	int x=q/5;
	printf("%lld\n",p*1000+x*5);
	return 0;
}

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

#define ed cout<<"\n";
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long 
#define ffor(i,a,b) for(ll i=(ll)(a);i<(ll)(b);++i)
#define rep(i, n) ffor(i,0,n)
#define All(obj) (obj).begin(),(obj).end()
#define INF ((ll)1e9+7)
#define c(a) cout<<a<<"\n";
using namespace std;
const int N = 100005;



int main() {
	speed;
	cout << fixed << setprecision(6);
	/*start*/
	int a, b;
	cin >> a >> b;
	a -=2* b;
	if (a < 0)a = 0;
	c(a);
	ed;
	return 0;
}



Measured memory_bytes: 256
using System;
using System.Linq;//リストの使用
using System.Collections.Generic;
using System.Text;//テキストの高速出力に必要
class Program
{
	static void Main()
	{
		string[] input = Console.ReadLine().Split(' ');
		int m = int.Parse(input[0]);
		long k = long.Parse(input[1]);
    int numCount = (int)Math.Pow(2,m+1);
    long[] answers = new long[numCount];
    
		if(m <= 1 && k != 0) Console.WriteLine(-1);
    else if(m == 0) Console.WriteLine("0 0");
    else if(m == 1) Console.WriteLine("0 0 1 1");
    else if(k >= Math.Pow(2,m)) Console.WriteLine(-1);
    else
    {
      int answer = 0;
      for(int i = 0; i < numCount/2-1; i++)
      {
        if(i == k) answer++;
        answers[i] = answer;
        answer++;
      }
        answers[numCount/2-1] = k;
      for(int i = 0; i < numCount/2-1; i++)
      {
        answers[i+numCount/2] = answers[numCount/2-2-i];
      }
      answers[numCount-1] = k;
      Console.WriteLine(string.Join(" ", answers));
    }
	}
}

Measured memory_bytes: 28248
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ll long long int
#define FIO ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define all(in) in.begin(), in.end()

int main(){
    FIO;
    ll n, m;
    cin >> n >> m;
    priority_queue<ll> pq;
    for(ll i = 0 ; i < n ; i++){
        ll x;   cin >> x;
        pq.push(x);
    }
    while(m--){
        ll x = pq.top();    pq.pop();
        x >>= 1;
        pq.push(x);
    }
    ll ans = 0;
    while(pq.size()){
        ans += pq.top();
        pq.pop();
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1400
#include <bits/stdc++.h>
#define rep(i,a,n) for (int i=a; i<n; i++)
#define ll long long
#define MOD 1000000007
using namespace std;;
 
int main() {
  int A,B; cin >> A >> B;
  if (A % 3 ==0 || B % 3 ==0 || (A+B) % 3 ==0) cout << "Possible" << endl;
  else cout << "Impossible" << endl;
}

Measured memory_bytes: 3500
#include <bits/stdc++.h>
using namespace std;
#define ri register int
typedef long long ll;
namespace io {
	const int SIZE = (1 << 21) + 1;
	char ibuf[SIZE], *iS, *iT, obuf[SIZE], *oS = obuf, *oT = oS + SIZE - 1, c, qu[55]; int f, qr;
	// getchar
	#define gc() (iS == iT ? (iT = (iS = ibuf) + fread (ibuf, 1, SIZE, stdin), (iS == iT ? EOF : *iS ++)) : *iS ++)
	// print the remaining part
	inline void flush () {
		fwrite (obuf, 1, oS - obuf, stdout);
		oS = obuf;
	}
	// putchar
	inline void putc (char x) {
		*oS ++ = x;
		if (oS == oT) flush ();
	}
	// input a signed integer
	template <class I>
	inline void gi (I &x) {
		for (f = 1, c = gc(); c < '0' || c > '9'; c = gc()) if (c == '-') f = -1;
		for (x = 0; c <= '9' && c >= '0'; c = gc()) x = (x << 1) + (x << 3) + (c & 15); x *= f;
	}
	// input a letter
	template <class I>
	inline void get (I &x) {
		for (c = gc(); c < 'A' || c > 'Z'; c = gc()) ;
		x = c;
	}
	// input a string
	inline void read (char *s){
		for(c = gc(); c < 'A' || c > 'Z'; c = gc()) ;
		for(; c >= 'A' && c <= 'Z'; c = gc()) *++s = c;
		*++s = '\0';
	}
	// print a signed integer
	template <class I>
	inline void print (I x) {
		if (!x) putc ('0'); if (x < 0) putc ('-'), x = -x;
		while (x) qu[++ qr] = x % 10 + '0',  x /= 10;
		while (qr) putc (qu[qr --]);
	}
	//no need to call flush at the end manually!
	struct Flusher_ {~Flusher_(){flush();}}io_flusher_;
}
using io :: gi;
using io :: get;
using io :: read;
using io :: putc;
using io :: print;
const int N=3e3+5;
int a[N],g[N][N],f[N][N],mod=1e9+7;
const ll inv2=mod+1>>1;
int main(){
	ri n,q,i,j,x,y,power,ans;
	gi(n);gi(q);
	for(i=1;i<=n;++i) gi(a[i]);
	for(i=1;i<=n;++i)
		for(j=1;j<=n;++j)
			g[i][j]=a[i]>a[j];
	power=1;
	while(q--){
		power=power*2%mod;
		gi(x);gi(y);
		for(j=1;j<=n;++j){
			if(j!=y) // i = x j != y
				f[x][j]=(g[x][j]+g[y][j])*inv2%mod;
			if(j!=x) // i = y j != x
				f[y][j]=(g[y][j]+g[x][j])*inv2%mod;
		}
		for(i=1;i<=n;++i){
			if(i!=x) // i != x j = y
				f[i][y]=(g[i][y]+g[i][x])*inv2%mod;
			if(i!=y) // i != y j = x
				f[i][x]=(g[i][x]+g[i][y])*inv2%mod; 
		}
		// i = x j = y
		f[x][y]=(g[x][y]+g[y][x])*inv2%mod;
		// i = y j = x
		f[y][x]=(g[y][x]+g[x][y])*inv2%mod;
		
		for(j=1;j<=n;++j){
			if(j!=y) // i = x j != y
				g[x][j]=f[x][j];
			if(j!=x) // i = y j != x
				g[y][j]=f[y][j];
		}
		for(i=1;i<=n;++i){
			if(i!=x) // i != x j = y
				g[i][y]=f[i][y];
			if(i!=y) // i != y j = x
				g[i][x]=f[i][x]; 
		}
		// i = x j = y
		g[x][y]=f[x][y];
		// i = y j = x
		g[y][x]=f[y][x];
	}
	ans=0;
	for(i=1;i<=n;++i)
		for(j=i+1;j<=n;++j)
			ans=(ans+(ll)g[i][j]*power)%mod;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 74112
/* include c++ libraries */
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <map>
#include <queue>
#include <set>

/* include c-lang libraries */
#include <climits>
#include <cmath>

/* include my libraries */
//#include <show_vec.hh>

using namespace std;

#define LINE DEBUG{ printf("LINE : %d\n", __LINE__); }
#define DEBUG if(false)

using ll = long long;
template<class T> using vec = vector<T>;

const int MOD = 1000000007;

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

  cout << 10-(X/200) << endl;

  return 0;
}


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

using namespace std;

#define ll long long
#define vi vector<int>
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

int A,B,C;

void solve(){
    cout << min(min( A + B, A + C), B + C) << endl;
}

int main(){
    cin >> A >> B >> C;

    solve();
}


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

int main(){
    int N,M;
    cin >> N >> M;
    vector<int> k(M,0);
    vector<vector<int> > s(11,vector<int>(11,0));
    for(int i=0;i<M;i++){
        cin >> k[i];
        for(int j=0;j<k[i];j++){
            cin >> s[i][j];
            s[i][j]--;
        }
    }
    vector<int> p(M,0);
    for(int i=0;i<M;i++){
        cin >> p[i];
    }
    //bit全探索
    int ans=0;
    for(int bit=0;bit<(1<<N);bit++){ //全通り
        int cntp = 0;
        for(int i=0;i<M;i++){ //電球i
            int cnts = 0;
            for(int j=0;j<k[i];j++){ //スイッチごと
                if(bit & (1<<s[i][j])){
                    cnts++;
                }
            }
            if(cnts%2==p[i]){
                cntp++;
            }
        }
        if(cntp==M){
            ans++;
        }
    }
    cout << ans << endl;
}

/*
in
2 2
2 1 2
1 2
0 1

out
1
*/


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

int main(void){
  char s1,s2;
  for(int i = 0;i < 4;i++){
    cin >> s1;
    if(s1 == s2){
      cout << "Bad" << endl;
      return 0;
    }
    s2 = s1;
  }
  cout << "Good" << endl;
  return 0;
}

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

using namespace std;

#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ll long long int
#define v(d_type) vector<d_type>
#define p(d_type1, d_type2) pair<d_type1, d_type2>
#define F first
#define S second
#define loop(i, s, n) for(int i = s; i < n; i++)
#define print_vec(X) loop(i, 0, X.size()) cout << X[i] << "\n"
#define nl "\n"
#define fat 1000000007


int main()
{
    boost;
    int n;
    cin >> n;
    
    cout << n*n*n << "\n";

    return 0;

}

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

// Greatest Common Divisor

int gcd(int x, int y){
    if (x < y) swap(x,y);
    while(y > 0){
        int r = x % y;
        x = y;
        y = r;
    }
    return x;
}

int main(){
    int x, y;
    cin >> x >> y;
    cout << gcd(x,y) << endl;
    return 0;
}

Measured memory_bytes: 3088
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int N = sc.nextInt();
		boolean winSecond = true;
		for(int i=0; i<N; i++)
			if(sc.nextInt()%2==1)
				winSecond = false;
		
		System.out.println(winSecond ? "second":"first");
		sc.close();
	}
	
}


Measured memory_bytes: 48252
#include <iostream>
#include <assert.h>
#include <vector>
using namespace std;
constexpr int64_t MOD = 1000000007;

int64_t pow(int d) {
  int64_t res = 1;
  int64_t base = 3;
  cout << d << endl;
  while (d) {
    if (d & 1) {
      res *= base;
      res = res % MOD;
    }
    base *= base;
    base = base % MOD;
    d = d >> 1;
  }
  return res;
}

int64_t rec(int start, int end, string& L, vector<int64_t>& dp) {
  int64_t res = dp[end - start - 1];
  for (int i = start+1; i <= end; i++) {
    if (i == end) {
      res += 2;
      res = res % MOD;
      break;
    }
    if(L[i] == '1') {
      res += 2 * rec(i, end, L, dp);
      res = res % MOD;
      break;
    }
  }
  return res;
}

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

  std::string L;
  cin >> L;
  int32_t num_dig = L.size();
  vector<int64_t> dp(num_dig+1,0);
  dp[0] = 1;
  for (int i = 1; i < num_dig; i++) {
    dp[i] = (3*dp[i-1]) % MOD;
  }
  
  int64_t res = rec(0, num_dig, L, dp);

  cout << res << endl;


  return 0;
}


Measured memory_bytes: 9040
using System;
using System.Runtime.CompilerServices;

namespace atcoder_ensyuu_160_a
{
    class Program
    {
        private static void Main(string[] args)
        {
            string line = Console.ReadLine();

            if (line.Length != 6)
            {
                Console.WriteLine("error");
                return;
            }

            if(line[2] == line[3] && line[4] == line[5])
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }
    }
}

Measured memory_bytes: 11092