jiahuimbzuai/CoQuIR huggingface dataset:
//  [java]
import java.util.Scanner;
import java.util.Arrays;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        long a[]=new long[N];
        for(int i=0; i<N; i++){
            a[i]=sc.nextLong();
        }

        
        
        Arrays.sort(a);

        long res=0;

        while(M>0){
            a[N-1] = a[N-1]/2;
            M--;
            Arrays.sort(a);
        }

        for(int i=0; i<N; i++){
            res = res+a[i];
        }  



        System.out.println(res);
        
        
        
        
        }
    }
//  [java]
import java.math.BigInteger;
import java.util.*;
import java.util.stream.Collectors;

public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int m = sc.nextInt();
    List<Long> a = new ArrayList<>();
    for (int i = 0; i < n; i++) {
      a.add(sc.nextLong());
    }
    if (n == 1) {
      long p = a.get(0);
      for (int i = 0; i < m; i++) {
        p = p / 2;
      }
      System.out.println(p);
      return;
    }
    a.sort(Comparator.reverseOrder());
    for (int i = 0; i < m; i++) {
      Long aLong = a.get(0);
      long newLong = aLong / 2;
      a.set(0, newLong);
      if (newLong < a.get(1)) {
        a.sort(Comparator.reverseOrder());
      }
    }
    System.out.println(a.stream().reduce(0L, Long::sum));
  }
}
//  [java]
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();
        double[] a = new double[n];
        for (int i=0;i<n;i++)a[i]=sc.nextInt();
        Arrays.sort(a);
        for (int i=0;i<m;i++){
            a[n-1]/=2.0;
            Arrays.sort(a);
        }
        long ans = 0;
        for (int i=0;i<n;i++)ans+=(long)Math.floor(a[i]);
        System.out.println(ans);
    }
}
//  [cpp]
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

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


	int N = getint(), M = getint();

	int A[100000];
	int B[30] = {};
	rep(i, N) {
		A[i] = getint();
		B[31 - __builtin_clz(A[i])]++;
	}
	int k = 29;
	while (k >= 1 && M - B[k] >= 0) {
		M -= B[k];
		B[k - 1] += B[k];
		k--;
	}
	rep(i, N) {
		int kari = 31 - __builtin_clz(A[i]);
		if (kari > k) A[i] >>= kari - k;
	}

	//なるほど？

	nth_element(A, A + max(0, N - M), A + N);

	ll kotae = 0;
	rep(i, N - M) kotae += A[i];
	for (int i = max(0, N - M); i < N; i++) kotae += A[i] >> 1;
	printf("%lld", kotae);

	Would you please return 0;
}
//  [cpp]
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

void pakuri_sort(int N, int A[]) {
	const int b = 8;
	int tmp[100001];
	rep(k, 4) {
		int kazu[1 << b] = {}, kazu2[1 << b] = {};
		rep(i, N) kazu[A[i] >> k * b & ((1 << b) - 1)]++;
		rep(i, (1 << b) - 1) kazu[i + 1] += kazu[i];
		for (int i = N - 1; i >= 0; i--) tmp[--kazu[A[i] >> k * b & ((1 << b) - 1)]] = A[i];
		k++;
		rep(i, N) kazu2[tmp[i] >> k * b & ((1 << b) - 1)]++;
		rep(i, (1 << b) - 1) kazu2[i + 1] += kazu2[i];
		for (int i = N - 1; i >= 0; i--) A[--kazu2[tmp[i] >> k * b & ((1 << b) - 1)]] = tmp[i];
	}
}

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


	int N = getint(), M = getint();

	int A[100000];
	int B[30] = {};
	rep(i, N) {
		A[i] = getint();
		B[31 - __builtin_clz(A[i])]++;
	}
	int k = 29;
	while (k >= 0 && M - B[k] >= 0) {
		M -= B[k];
		B[k - 1] += B[k];
		k--;
	}
	if (k == -1) {
		printf("0");
		return 0;
	}
	rep(i, N) {
		int kari = 31 - __builtin_clz(A[i]);
		if (kari > k) A[i] >>= kari - k;
	}

	pakuri_sort(N, A);

	ll kotae = 0;
	rep(i, N - M) kotae += A[i];
	for (int i = max(0, N - M); i < N; i++) kotae += A[i] >> 1;
	printf("%lld", kotae);

	Would you please return 0;
}
//  [cpp]
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
#define LINF 1e18
typedef long long ll;


int main() {
    int N,M; cin >> N >> M;
    priority_queue<int> A;
    REP(i,N){
        int a; cin >> a;
        A.push(a);
    }

    REP(i,M){
        int a = A.top(); A.pop();
        A.push(a/2);
    }
    
    ll ans = 0;
    while(A.size()>0){
        int a = A.top(); A.pop();
        ans += a;
    }
    cout << ans << endl;
    return 0;
}
//  [cpp]
#include <bits/stdc++.h>
using namespace std;
//#define int long long
//#define ll long long
const int maxm=3e5+5;
int a[maxm];
int n,m;
signed main(){
    cin>>n>>m;
    for(int i=1;i<=n;i++)cin>>a[i];
    priority_queue<int,vector<int>,less<int> >q;
    for(int i=1;i<=n;i++){
        q.push(a[i]);
    }
    while(m&&!q.empty()){
        int x=q.top();q.pop();
        x/=2;
        m--;
        if(x)q.push(x);
    }
    int ans=0;
    while(!q.empty()){
        ans+=q.top();q.pop();
    }
    cout<<ans<<endl;
    return 0;
}
/*


*/
//  [cpp]
#include<bits/stdc++.h> 
#define rep(i,n) for(int i = 0; i < n; i++)
#define pb push_back
using namespace std;
typedef long long ll;

int main(){
    int n, m;
    cin >> n >> m;
    vector<int> a(n);
    ll ans = 0;
    multiset<int> s;
    rep(i, n){
        cin >> a[i];
        ans += a[i];
        s.insert(a[i]);
    }
    rep(i, m){
        int x = *s.rbegin();
        s.erase(x);
        ans -= x - x / 2;
        s.insert(x / 2);
    }
    cout << max(ans, 0ll) << endl;
}
//  [c]
#include<stdio.h>
long long a[100001];
void quickSort(int i,int j){
	int p=i,q=j,t;long long mid;
	if(i>=j) return;
	i--;j++;
	mid=a[(i+j)/2];
	while(1){
		while(a[++i]>mid);
		while(a[--j]<mid);
		if(i<j){
			t=a[i];
			a[i]=a[j];
			a[j]=t;
		}
		else
			break;
	}
	quickSort(j+1,q);
	quickSort(p,i-1);
}
int main(){
	int n,m,i,j=1;
	long long sum=0,index=2;
	scanf("%d%d",&n,&m);
	for(i=0;i<n;i++)
		scanf("%lld",&a[i]);
	if(n==1){
		for(;m>0;m--){
			a[0]/=2;
			if(a[0]==0)
				break;
			}	
		printf("%lld",a[0]);
		return 0;			
	}	
	quickSort(0,n-1);
	while(index<=a[0]){
		index*=2; 
	}
	while(m>0){
		index/=2;
		for(i=0;i<n;i++)
			if(a[i]<index)
				break;
		m-=i;
		if(m<0){
			quickSort(0,n-1);
			for(j=0;j<m+i;j++)
				a[j]/=2;
		}
		else{
			for(j=0;j<i;j++)
				a[j]/=2;
		}
	}
	for(i=0;i<n;i++){
		sum+=a[i];
	}
	printf("%lld",sum);
	return 0;
}
//  [c]
#include <stdio.h>
#include <stdlib.h>

void swap(long *x,long *y){
    long z;
    z=*x;
    *x=*y;
    *y=z;
}

int max(long a,long b){
    if(a>b)return a;
    else return b;
}

void pushdown(long* a,int n){
    int i=1;
    while(1){
        if(a[i]>=max(a[2*i],a[2*i+1]))break;
        if(a[2*i]>a[2*i+1]){
            swap(&a[i],&a[2*i]);
            i*=2;
        }else{
            swap(&a[i],&a[2*i+1]);
            i=2*i+1;
        }
        if(i*2>n)break;
    }
}

void add_num(long*a,int i){
    while(i>1){
        if(a[i]<=a[i/2])break;
        swap(&a[i],&a[i/2]);
        i/=2;
    }
}

int main(void){
    int N,M,tmp;
    scanf("%d%d",&N,&M);
    long a[100001];
    for(int i=0;i<100001;i++)a[i]=0;
    for(int i=1;i<N+1;i++){
        scanf("%ld",&a[i]);
        add_num(a,i);
    }
    for(int i=0;i<M;i++){
        a[1]=a[1]/2;
        pushdown(a,N);
    }
    long count=0;
    for(int i=1;i<N+1;i++){
        count+=a[i];
    }
    printf("%ld\n",count);
    return 0;
}
//  [c]
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define max(p,q) ((p)>(q)?(p):(q))
#define min(p,q) ((p)<(q)?(p):(q))
#define chmax(a,b) ((a)=(a)>(b)?(a):(b))
#define chmin(a,b) ((a)=(a)<(b)?(a):(b))
#define abs(p) ((p)>=(0)?(p):(-(p)))
#define swap(a,b) do{ll w=(a);(a)=(b);(b)=w;}while(0)
#define swapd(a,b) do{double w=(a);(a)=(b);(b)=w}while(0)
#define in(a) scanf("%lld", &(a))
#define ind(a) scanf("%lf", &(a))
#define put(a) printf("%lld\n", (a))
#define putd(a) printf("%.15f\n", (a));
//def   puts(a) printf("%s\n", a) 文字はこっち
//your code here!
#define MAX_HEAP 100005
ll a[MAX_HEAP];
ll g_idx = -1; //ヒープの末尾の添字 最初は空っぽだから-1

void downheap(void){//根に置かれている要素を適切なとこまで下におろす。
    ll i, j;
    i = 0;              //根から始める
    while(i*2+1<=g_idx){//子が存在するという条件
        j = i*2+1;
        if(j+1<=g_idx && a[j]<a[j+1]){
            j++;        //2つ(or1つ)の子供の内、小さい方の添字をjとしている
        }
        if(a[i] >= a[j]){
            break;      //子供の方が大きければ、終了
        }
        //終了していないと言うことは、親子関係が逆なのでswap
        swap(a[i],a[j]);
        i = j;          //子供が親になって次のループへ
    }
}

ll PQ_pop(void){//最小値を取り出す
    ll ret = a[0];         //返り値
    if(g_idx<0) exit(1);  //ヒープが空っぽかどうか確認
    a[0] = a[g_idx--];     //末尾の要素を先頭にもってく
    //a[0]=a[g_idx];  g_idx=g_idx - 1; 後からマイナス
    downheap();
    return ret;
}

void upheap(void){ //末尾に置かれている要素を適切なとこまで上にあげる
    ll x = g_idx;  //グローバル変数をいじる訳にはいかないので代入
    while(x>0 && a[(x-1)/2]<a[x]){//親がいる&&親が子供より大きい なら継続
        swap(a[(x-1)/2], a[x]);   //親と子供をswap
        x = (x-1)/2;              //親を子供にしてループへ
    }
}

void PQ_push(ll elem){//ヒープに要素elemを追加する
    if(g_idx >= MAX_HEAP-1){//ヒープに空きがあるか確認
        exit(1);
    }
    a[++g_idx] = elem;      //末尾にelemを入れる
    //g_idx+=1;  a[g_idx]=elem  先にプラス
    upheap();
}


int main(void){
    ll N, M, A, ans=0;
    in(N); in(M);
    rep(i,N){
        in(A);
        PQ_push(A);
    }
    rep(_,M){
        A = PQ_pop();
        PQ_push(A/2);
    }
    rep(i,N) ans += a[i];
    put(ans);
    return 0;
}
//  [c]
H[1<<17],h;
p(a){
	for(*H=a,a=++h;a>1&*H>H[a/2];a/=2)H[a]=H[a/2];
	H[a]=*H;
}
q(a,b){
	for(a=b=1;a<h&H[a]>H[h];H[a]=H[b=(H[b=a*2]<H[b+1]&b<h)+b])a=b;
	H[a]=H[h];H[h--]=0;
}
long s;N;M;
main(a){
	for(scanf("%d%d",&N,&M);~scanf("%d",&a);)p(a);
	for(;M--;p(a/2))q(a=H[1]);
	for(;N--;s+=a)q(a=H[1]);
	printf("%ld",s);
}
//  [c]
H[1<<17],h=1;
e(k,l){return h<l||k<=h&l>0&H[k]>H[l];}
p(k,l){
	l=h++;
	for(*H=k;e(0,l/2);l/=2)H[l]=H[l/2];
	H[l]=k;
}
q(k,l,m){
	k=H[--h];H[h]=0;
	for(l=1;e(l,h);l=m)H[l]=H[m=l*2+1-e(l*2,l*2+1)];
	H[l/2]=k;
}
long s;N;M;
main(a){
	for(scanf("%d%d",&N,&M);~scanf("%d",&a);)p(a);
	for(;M--;p(a/2))q(a=H[1]);
	for(;N--;s+=a)q(a=H[1]);
	printf("%ld",s);
}
//  [c]
H[1<<17],h=1;
e(k,l){return h<l||k<=h&l>0&H[k]>H[l];}
p(k,l){
	l=h++;
	for(*H=k;e(0,l/2);l/=2)H[l]=H[l/2];
	H[l]=k;
}
q(k,l,m){
	k=H[--h];H[h]=0;
	for(l=1;e(l,h);l=m)H[l]=H[m=l*2+1-e(l*2,l*2+1)];
	H[l/2]=k;
}
long s;a;b;c;
main(){
	for(;~scanf("%d",&b+!a+!c);)p(b);
	for(;c--+a+2;c<0?s+=b:p(b/2))q(b=H[1]);
	printf("%ld",s);
}
//  [javascript]
input = require('fs').readFileSync('/dev/stdin', 'utf8')
lines = input.split('\n')
line = lines.shift().split(' ')
N = line[0] * 1
K = line[1] * 1 
A = lines.shift().split(' ')

heap = [0]
_insertHeap = (v) => {
    var idx = heap.length
    while(idx > 1) {
        var parent = ~~(idx / 2)
        if (heap[parent] < v) {
            heap[idx] = heap[parent]
            idx = parent
        } else {
            break;
        }
    }
    heap[idx] = v
}

_popHeap = () => {
    var val = heap[1]
    var last = heap.pop()
    
    if (heap.length == 1) {
        return val
    }
    
    var idx = 1
    while(true) {
        var left = idx * 2
        var right = idx * 2 + 1
        var next = idx
        if (left < heap.length && heap[left] > last) {
          next = left
        }
        if (right < heap.length && heap[right] > last && heap[right] > heap[left]) {
          next = right
        }
        if (next != idx) {
          heap[idx] = heap[next]
          idx = next
        } else {
            break;
        }
    }
    heap[idx] = last
    return val
}

for(i=0; i<N; i++) {
    _insertHeap(A[i] * 1)
}

for(i=0; i<K; i++) {
    a = _popHeap()
    _insertHeap(~~(a / 2))
}

sum = 0
for(i=1; i<heap.length; i++) {
    sum += heap[i]
}

console.log(sum)
//  [javascript]
module.exports=function(t){var e={};function r(n){if(e[n])return e[n].exports;var i=e[n]={i:n,l:!1,exports:{}};return t[n].call(i.exports,i,i.exports,r),i.l=!0,i.exports}return r.m=t,r.c=e,r.d=function(t,e,n){r.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},r.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},r.t=function(t,e){if(1&e&&(t=r(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var i in t)r.d(n,i,function(e){return t[e]}.bind(null,i));return n},r.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(e,"a",e),e},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.p="",r(r.s=0)}([function(t,e,r){r(1)(r(3).readFileSync("/dev/stdin","UTF-8").split("\n"))},function(t,e,r){function n(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){var r=[],n=!0,i=!1,o=void 0;try{for(var a,h=t[Symbol.iterator]();!(n=(a=h.next()).done)&&(r.push(a.value),!e||r.length!==e);n=!0);}catch(t){i=!0,o=t}finally{try{n||null==h.return||h.return()}finally{if(i)throw o}}return r}(t,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}var i=r(2);t.exports=function(t){var e=n(t[0].split(" ").map(function(t){return Number(t)}),2),r=e[0],o=e[1],a=new i;t[1].split(" ").map(function(t){a.pushItem(Number(t))});for(var h=0;h<o;h++){var s=Math.floor(a.getTop()/2);a.removeTop(),a.pushItem(s)}for(var u=0,p=0;p<r;p++)u+=a.heap[p];console.log(u)}},function(t,e,r){"use strict";function n(t,e){return t<=e}function i(t,e){return t>=e}t.exports=class{constructor(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],e=!(arguments.length>1&&void 0!==arguments[1])||arguments[1],r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:void 0;this.heap=t,this.cf=e?n:i,r&&(this.cf=r),this.size=this.heap.length}pushItem(t){this.size+=1,this.heap.push(t);for(var e=this.heap.length-1;0!=e;){var r=Math.floor((e-1)/2);if(this.cf(this.heap[e],this.heap[r]))break;var n=this.heap[r];this.heap[r]=this.heap[e],this.heap[e]=n,e=r}}getTop(){return this.heap[0]}removeTop(){if(0!=this.size){this.size-=1;var t=this.heap.length-1;this.heap[0]=this.heap[t],this.heap.pop(),t--;for(var e=0;2*e+1<=t;){var r=this.heap[2*e+1],n=2*e+2<=t?this.heap[2*e+2]:r;if(this.cf(n,r)){if(this.cf(r,this.heap[e]))break;var i=r;this.heap[2*e+1]=this.heap[e],this.heap[e]=i,e=2*e+1}else{if(this.cf(n,this.heap[e]))break;var o=n;this.heap[2*e+2]=this.heap[e],this.heap[e]=o,e=2*e+2}}}}}},function(t,e){t.exports=require("fs")}]);
//  [javascript]
module.exports=function(t){var e={};function i(r){if(e[r])return e[r].exports;var s=e[r]={i:r,l:!1,exports:{}};return t[r].call(s.exports,s,s.exports,i),s.l=!0,s.exports}return i.m=t,i.c=e,i.d=function(t,e,r){i.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:r})},i.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},i.t=function(t,e){if(1&e&&(t=i(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var r=Object.create(null);if(i.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var s in t)i.d(r,s,function(e){return t[e]}.bind(null,s));return r},i.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return i.d(e,"a",e),e},i.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},i.p="",i(i.s=0)}([function(t,e,i){"use strict";var r=i(1);i(2)(r.readFileSync("/dev/stdin","utf8"))},function(t,e){t.exports=require("fs")},function(t,e,i){"use strict";var r=i(3),s=i(5);t.exports=function(t){var e=new r(t);s(e)}},function(t,e,i){"use strict";var r=i(4);t.exports=class{constructor(t){var e=t.trim().split(/\s+/g);this.inp=new r(e)}inr(){return this.inp.deq()}in(){return parseInt(this.inp.deq(),10)}fin(){this.inp.clear()}}},function(t,e,i){"use strict";t.exports=class{constructor(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];this.size=t.length,this.items=t,this.ind=0}enq(t){this.size+=1,this.items.push(t)}deq(){var t=this.items[this.ind];return this.size-=1,this.ind+=1,t}clear(){this.items=[],this.size=0,this.ind=0}}},function(t,e,i){"use strict";var r=i(6);t.exports=function(t){for(var e=t.in(),i=t.in(),s=new r,n=0;n<e;n++){var o=t.in();s.pushItem(o)}for(var h=0;h<i;h++){var a=s.getTop();s.removeTop(),s.pushItem(Math.floor(a/2))}for(var u=0,p=s.getValuesList(),f=0;f<e;f++)u+=p[f];console.log(u)}},function(t,e,i){"use strict";function r(t,e){return t<=e}function s(t,e){return t>=e}t.exports=class{constructor(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],e=!(arguments.length>1&&void 0!==arguments[1])||arguments[1],i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:void 0;this.cf=e?r:s,i&&(this.cf=i),this.heap=t,this.size=this.heap.length,this.heapify()}heapify(){for(var t=0,e=this.size;2*t+1<=e;)t=2*t+1;for(var i=t-1;i>=0;)2*i+1>e-1?i--:(this.downHeap(i),i--)}downHeap(t){for(var e=this.size,i=t;2*i+1<e;){var r=this.heap[2*i+1],s=2*i+2<e?this.heap[2*i+2]:r,n=this.cf(s,r)?r:s,o=this.cf(s,r)?2*i+1:2*i+2;if(this.cf(n,this.heap[i]))break;var h=n;this.heap[o]=this.heap[i],this.heap[i]=h,i=o}}upHeap(t){for(var e=t;0!=e;){var i=Math.floor((e-1)/2);if(this.cf(this.heap[e],this.heap[i]))break;var r=this.heap[i];this.heap[i]=this.heap[e],this.heap[e]=r,e=i}}pushItem(t){this.size+=1,this.heap.push(t),this.upHeap(this.size-1)}getTop(){return this.heap[0]}removeTop(){return 0!=this.size&&(1==this.size?(this.size=0,this.heap=[],!0):(this.size-=1,this.heap[0]=this.heap.pop(),this.downHeap(0),!0))}getValuesList(){return this.heap}}}]);
//  [javascript]
"use strict"
const create = () => {
    const input = require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n");
    const res = {
        "list": input, "index": 0, "max": input.length,
        "hasNext": function() {return this.index < this.max},
        "next": function() { if (!this.hasNext()) {throw "ArrayIndexOutOfBoundsException";}else{return this.list[this.index++];}}
    };
    return res;
}
const o = create();
const next = () => o.next()
const nextInt = () => parseInt(o.next())
const nextStrArray = () => o.next().split(" ")
const nextIntArray = () => o.next().split(" ").map(el => parseInt(el))
const nextCharArray = () => o.next().split("")
const hasNext = () => o.hasNext()
const myout = (...x) => console.log(...x)

function PriorityQueue(){
    this.heap = [];
}
 
PriorityQueue.prototype = {
    push : function(x){
        var h = this.heap, i = h.length++, j;
        while(i){
            j = i-1 >> 1;
            if(h[j] <= x)break;
            h[i] = h[j];
            i = j;
        }
        h[i] = x;
    },
    pop : function(){
        var h = this.heap, r = h[0], x = h.pop();
        var i = 0, k = h.length >> 1, j;
        while (i < k) {
            j = (i << 1) + 1;
            if(h[j+1] < h[j])++j;
            if(x <= h[j])break;
            h[i] = h[j];
            i = j;
        }
        if(h.length)h[i] = x;
        return r;
    },
    size : function(){return this.heap.length;},
    top : function(){return this.heap[0];},
};

const Main = () => {
    let [N, M] = nextIntArray()
    const a = nextIntArray()
    a.sort((a,b) => b-a)
    let pq = new PriorityQueue()
    for(let i = 0;i<a.length;i++){
        pq.push(-a[i])
    }
    while(M>0){
        let tmp = pq.pop()
        tmp = Math.floor(tmp/2)
        pq.push(tmp)
        M--
    }
    let sum = 0
    for(let i = 0; i<pq.arr.length;i++){
        sum += -pq.arr[i]
    }
    console.log(sum)
}
Main()
//  [javascript]
"use strict"
const create = () => {
    const input = require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n");
    const res = {
        "list": input, "index": 0, "max": input.length,
        "hasNext": function() {return this.index < this.max},
        "next": function() { if (!this.hasNext()) {throw "ArrayIndexOutOfBoundsException";}else{return this.list[this.index++];}}
    };
    return res;
}
const o = create();
const next = () => o.next()
const nextInt = () => parseInt(o.next())
const nextStrArray = () => o.next().split(" ")
const nextIntArray = () => o.next().split(" ").map(el => parseInt(el))
const nextCharArray = () => o.next().split("")
const hasNext = () => o.hasNext()
const myout = (...x) => console.log(...x)

class MaxHeap {
    arr
    constructor() {
        this.arr = []
    }
    build() {
        for (let i = this.arr.length - 1; i >= 0; i--) {
            this.heapify(i, this.arr.length)
        }
    }
    heapify(i, len) {
        let l = 2 * i + 1
        let r = 2 * i + 2
        let largest = i

        // Condition 'l <= len' & 'r <= len' is for the case of leaf nodes.
        // On leaf nodes, swap() should NOT happen so this condition skips these cases.
        if (l <= len && this.arr[l] > this.arr[i]) {
            largest = l
        }
        if (r <= len && this.arr[r] > this.arr[i]) {
            largest = r
        }
        if (largest !== i) {
            this.swap(i, largest)
            this.heapify(largest, len)
        }
    }
    swap(i, j) {
        [this.arr[i], this.arr[j]] = [this.arr[j], this.arr[i]]
    }
    push(data) {
        this.arr.push(data)
        this.build()
    }
    pop() {
        let elm = this.arr.shift()
        this.build()
        return elm
    }
}

const Main = () => {
    let [N, M] = nextIntArray()
    const a = nextIntArray()
    a.sort((a,b) => b-a)
    let mh = new MaxHeap()
    for(let i = 0;i<a.length;i++){
        mh.push(a[i])
    }
    while(M>0){
        let tmp = mh.pop()
        tmp = Math.floor(tmp/2)
        mh.push(tmp)
        M--
    }
    let sum = 0
    for(let i = 0; i<mh.arr.length;i++){
        sum += mh.arr[i]
    }
    console.log(sum)
}
Main()
//  [javascript]
"use strict"
const create = () => {
    const input = require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n");
    const res = {
        "list": input, "index": 0, "max": input.length,
        "hasNext": function() {return this.index < this.max},
        "next": function() { if (!this.hasNext()) {throw "ArrayIndexOutOfBoundsException";}else{return this.list[this.index++];}}
    };
    return res;
}
const o = create();
const next = () => o.next()
const nextInt = () => parseInt(o.next())
const nextStrArray = () => o.next().split(" ")
const nextIntArray = () => o.next().split(" ").map(el => parseInt(el))
const nextCharArray = () => o.next().split("")
const hasNext = () => o.hasNext()
const myout = (...x) => console.log(...x)

class MaxHeap {
    arr
    constructor() {
        this.arr = []
    }
    build() {
        for (let i = this.arr.length - 1; i >= 0; i--) {
            this.heapify(i, this.arr.length)
        }
    }
    heapify(i, len) {
        let l = 2 * i + 1
        let r = 2 * i + 2
        let largest = i

        // Condition 'l <= len' & 'r <= len' is for the case of leaf nodes.
        // On leaf nodes, swap() should NOT happen so this condition skips these cases.
        if (l <= len && this.arr[l] > this.arr[i]) {
            largest = l
        }
        if (r <= len && this.arr[r] > this.arr[i]) {
            largest = r
        }
        if (largest !== i) {
            this.swap(i, largest)
            this.heapify(largest, len)
        }
    }
    swap(i, j) {
        [this.arr[i], this.arr[j]] = [this.arr[j], this.arr[i]]
    }
    push(data) {
        this.arr.push(data)
        this.build()
    }
    pop() {
        let elm = this.arr.shift()
        this.build()
        return elm
    }
}

const Main = () => {
    let [N, M] = nextIntArray()
    const a = nextIntArray()
    a.sort((a,b) => b-a)
    let mh = new MaxHeap()
    for(let el of a){
        mh.push(el)
    }
    while(M>0){
        let tmp = mh.pop()
        tmp = Math.floor(tmp/2)
        mh.push(tmp)
        M--
    }
    let sum = 0
    for(let el of mh.arr){
        sum += el
    }
    console.log(sum)
}
Main()
//  [go]
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
    sc.Scan()
    i, e := strconv.Atoi(sc.Text())
    if e != nil {
        panic(e)
    }
    return i
}

func nextInt64() int64 {
    sc.Scan()
    i, e := strconv.ParseInt(sc.Text(), 10, 64)
    if e != nil {
        panic(e)
    }
    return i
}

func nextString() string {
    sc.Scan()
    return sc.Text()
}

var a []int64

func heapone(num int) {
    var i,vs int
    for j := 2; j <= num; j++ {
        i = j
        for ;; {
            vs = i/2
            if vs == 0 {
                break
            }
            if a[i] > a[vs] {
                tmp2 := a[i]
                a[i] = a[vs]
                a[vs] = tmp2
                i = vs
            } else {
                break
            }
        }
    }
}

func heapupdate(num int) {
    tmp := a[1] / 2
    var i,vs int

    //update
    a[1] = a[1] / 2

    i = 1
    for ;; {
        vs = i * 2
        if vs > num {
            break
        }
        if vs <= num - 1 && a[vs] < a[vs + 1] {
            vs++
        }
        if a[i] < a[vs] {
            tmp2 := a[i]
            a[i] = a[vs]
            a[vs] = tmp2
            i = vs
        } else {
            break
        }
    }
    return

    //delete
    a[1] = a[num]
    i = 1
    for ;; {
        vs = i * 2
        if vs > num - 1 {
            break
        }
        if vs <= num - 2 && a[vs] < a[vs + 1] {
            vs++
        }
        if a[i] < a[vs] {
            tmp2 := a[i]
            a[i] = a[vs]
            a[vs] = tmp2
            i = vs
        } else {
            break
        }
    }

    //insert
    a[num] = tmp
    i = num
    for ;; {
        vs = i/2
        if vs == 0 {
            break
        }
        if a[i] > a[vs] {
            tmp2 := a[i]
            a[i] = a[vs]
            a[vs] = tmp2
            i = vs
        } else {
            break
        }
    }
}

func main() {
    buf := make([]byte, 0)
    sc.Buffer(buf, 4000000)
    sc.Split(bufio.ScanWords)
	n := nextInt()
	m := nextInt()

    a = make([]int64, n + 1)
    for i := 1; i <= n; i++ {
        a[i] = nextInt64()
    }
    heapone(n)
    for i := 0; i < m; i++ {
        //fmt.Println(a)
        //fmt.Println(a[1], "->", a[1]/2)
        heapupdate(n)
    }
    
    //fmt.Println(a)
    score := 0
    for i := 1; i <= n; i++ {
        score += int(a[i])
    }

    fmt.Println(score)

}
//  [go]
package main

import (
	"bufio"
	"container/heap"
	"fmt"
	"os"
	"strconv"
)

func solve(sc *scanner, wr *bufio.Writer) {
	n, m := sc.getInt2()
	pq := newIntPriorityQueue(n)
	for i := 0; i < n; i++ {
		a := sc.getInt()
		pq.push(a)
	}

	for i := 0; i < m; i++ {
		pq.fix(0, pq.head()/2)
	}

	ans := sum(*pq.h...)
	fmt.Fprintln(wr, ans)
}

type intPriorityQueue struct {
	h *intHeap
}

func newIntPriorityQueue(cap int) *intPriorityQueue {
	pq := new(intPriorityQueue)
	ih := make(intHeap, 0, cap)
	pq.h = &ih
	heap.Init(pq.h)
	return pq
}
func (pq *intPriorityQueue) push(x int) { heap.Push(pq.h, x) }
func (pq *intPriorityQueue) pop() int   { return heap.Pop(pq.h).(int) }
func (pq *intPriorityQueue) fix(i, x int) {
	(*pq.h)[i] = x
	heap.Fix(pq.h, i)
}
func (pq *intPriorityQueue) head() int {
	return (*pq.h)[0]
}

type intHeap []int

func (h *intHeap) Len() int           { return len(*h) }
func (h *intHeap) Less(i, j int) bool { return (*h)[i] > (*h)[j] }
func (h *intHeap) Swap(i, j int)      { (*h)[i], (*h)[j] = (*h)[j], (*h)[i] }
func (h *intHeap) Push(x interface{}) {
	*h = append(*h, x.(int))
}
func (h *intHeap) Pop() interface{} {
	old := *h
	n := len(old)
	ret := old[n-1]
	*h = old[0 : n-1]
	return ret
}

func main() {
	sc := newScanner()
	wr := bufio.NewWriter(os.Stdout)
	maxBufSize := int(1e8)
	sc.Buffer(make([]byte, 4096), maxBufSize)
	sc.Split(bufio.ScanWords)

	solve(sc, wr)
	wr.Flush()
}

// input ------------------------
type scanner struct {
	*bufio.Scanner
}

func newScanner() *scanner {
	sc := bufio.NewScanner(os.Stdin)
	return &scanner{sc}
}
func (sc *scanner) getInt() int {
	sc.Scan()
	ret, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return ret
}
func (sc *scanner) getInt2() (int, int) {
	return sc.getInt(), sc.getInt()
}
func (sc *scanner) getInt3() (int, int, int) {
	return sc.getInt(), sc.getInt(), sc.getInt()
}
func (sc *scanner) getInt4() (int, int, int, int) {
	return sc.getInt(), sc.getInt(), sc.getInt(), sc.getInt()
}
func (sc *scanner) getInts(n int) []int {
	ret := make([]int, n)
	for i := range ret {
		ret[i] = sc.getInt()
	}
	return ret
}
func (sc *scanner) getString() string {
	sc.Scan()
	return sc.Text()
}
func (sc *scanner) getRunes() []rune {
	return []rune(sc.getString())
}
func (sc *scanner) getFloat() float64 {
	sc.Scan()
	ret, err := strconv.ParseFloat(sc.Text(), 64)
	if err != nil {
		panic(err)
	}
	return ret
}
func (sc *scanner) getFloats(n int) []float64 {
	ret := make([]float64, n)
	for i := range ret {
		ret[i] = sc.getFloat()
	}
	return ret
}

// math ----------------------------
func sum(ns ...int) int {
	var sum int
	for _, n := range ns {
		sum += n
	}
	return sum
}

func max(ns ...int) int {
	max := ns[0]
	for i := 1; i < len(ns); i++ {
		if max < ns[i] {
			max = ns[i]
		}
	}
	return max
}

func min(ns ...int) int {
	min := ns[0]
	for i := 1; i < len(ns); i++ {
		if min > ns[i] {
			min = ns[i]
		}
	}
	return min
}

func pow(a, b int) int {
	ret := 1
	for b > 0 {
		if b&1 > 0 {
			ret = ret * a
		}
		a = a * a
		b >>= 1
	}
	return ret
}
//  [go]
package main

import (
	"bufio"
	"container/heap"
	"fmt"
	"os"
	"strconv"
)

func solve(sc *scanner, wr *bufio.Writer) {
	n, m := sc.getInt2()
	pq := newIntPriorityQueue()
	for i := 0; i < n; i++ {
		a := sc.getInt()
		heap.Push(pq, a)
	}

	for i := 0; i < m; i++ {
		(*pq)[0] /= 2
		heap.Fix(pq, 0)
	}

	ans := sum(*pq...)
	fmt.Fprintln(wr, ans)
}

type intPriorityQueue []int

func newIntPriorityQueue() *intPriorityQueue {
	pq := new(intPriorityQueue)
	heap.Init(pq)
	return pq
}

func (pq intPriorityQueue) Len() int           { return len(pq) }
func (pq intPriorityQueue) Less(i, j int) bool { return pq[i] > pq[j] }
func (pq intPriorityQueue) Swap(i, j int)      { pq[i], pq[j] = pq[j], pq[i] }
func (pq *intPriorityQueue) Push(x interface{}) {
	*pq = append(*pq, x.(int))
}
func (pq *intPriorityQueue) Pop() interface{} {
	old := *pq
	n := len(old)
	ret := old[n-1]
	*pq = old[0 : n-1]
	return ret
}

func main() {
	sc := newScanner()
	wr := bufio.NewWriter(os.Stdout)
	maxBufSize := int(1e8)
	sc.Buffer(make([]byte, 4096), maxBufSize)
	sc.Split(bufio.ScanWords)

	solve(sc, wr)
	wr.Flush()
}

// input ------------------------
type scanner struct {
	*bufio.Scanner
}

func newScanner() *scanner {
	sc := bufio.NewScanner(os.Stdin)
	return &scanner{sc}
}
func (sc *scanner) getInt() int {
	sc.Scan()
	ret, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return ret
}
func (sc *scanner) getInt2() (int, int) {
	return sc.getInt(), sc.getInt()
}
func (sc *scanner) getInt3() (int, int, int) {
	return sc.getInt(), sc.getInt(), sc.getInt()
}
func (sc *scanner) getInt4() (int, int, int, int) {
	return sc.getInt(), sc.getInt(), sc.getInt(), sc.getInt()
}
func (sc *scanner) getInts(n int) []int {
	ret := make([]int, n)
	for i := range ret {
		ret[i] = sc.getInt()
	}
	return ret
}
func (sc *scanner) getString() string {
	sc.Scan()
	return sc.Text()
}
func (sc *scanner) getRunes() []rune {
	return []rune(sc.getString())
}
func (sc *scanner) getFloat() float64 {
	sc.Scan()
	ret, err := strconv.ParseFloat(sc.Text(), 64)
	if err != nil {
		panic(err)
	}
	return ret
}
func (sc *scanner) getFloats(n int) []float64 {
	ret := make([]float64, n)
	for i := range ret {
		ret[i] = sc.getFloat()
	}
	return ret
}

// math ----------------------------
func sum(ns ...int) int {
	var sum int
	for _, n := range ns {
		sum += n
	}
	return sum
}

func max(ns ...int) int {
	max := ns[0]
	for i := 1; i < len(ns); i++ {
		if max < ns[i] {
			max = ns[i]
		}
	}
	return max
}

func min(ns ...int) int {
	min := ns[0]
	for i := 1; i < len(ns); i++ {
		if min > ns[i] {
			min = ns[i]
		}
	}
	return min
}

func pow(a, b int) int {
	ret := 1
	for b > 0 {
		if b&1 > 0 {
			ret = ret * a
		}
		a = a * a
		b >>= 1
	}
	return ret
}
//  [go]
package main

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

var sc = bufio.NewScanner((os.Stdin))

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	l := nextLine()
	i, e := strconv.Atoi(l)
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)
	N, M, A := nextInt(), nextInt(), []int{}
	for i := 0; i < N; i++ {
		A = append(A, nextInt())
	}

	fmt.Printf("%d\n", ABC141D(M, A))
}

// ABC141D ...
func ABC141D(M int, A []int) (res int) {
	A = sort.IntSlice(A)

	for i := 0; i < M; i++ {
      	A[len(A)-1] = A[len(A)-1] / 2
		//A = sort.IntSlice(A)
		A = sort.IntSlice(A)
	}

	for i := 0; i < len(A); i++ {
		res += A[i]
	}

	return
}
//  [go]
package main

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

var sc = bufio.NewScanner((os.Stdin))

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	l := nextLine()
	i, e := strconv.Atoi(l)
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)
	N, M, A := nextInt(), nextInt(), []int{}
	for i := 0; i < N; i++ {
		A = append(A, nextInt())
	}

	fmt.Printf("%d\n", ABC141D(M, A))
}

// ABC141D ...
func ABC141D(M int, A []int) (res int) {
	sort.Sort(sort.Reverse(sort.IntSlice(A)))

	for i := 0; i < M; i++ {
		A[0] = A[0] / 2
		//A = sort.IntSlice(A)
		sort.Sort(sort.Reverse(sort.IntSlice(A)))
	}

	for i := 0; i < len(A); i++ {
		res += A[i]
	}

	return
}
//  [ruby]
n, m = gets.split.map(&:to_i)
a = gets.split.map(&:to_i).sort.reverse
t = Array.new
t << (a.shift >> 1)
m -= 1
while m > 0
  t << (a.empty? || a[0] < t[0] ? t.shift >> 1 : a.shift >> 1)
  m -= 1
end
puts (a + t).inject(&:+)
//  [ruby]
N,M = gets.split.map(&:to_i)
A = gets.split.map(&:to_i)

ans = A.sort.reverse!
tmp = [ans.shift / 2]
(M-1).times do
  if ans.empty?
    ans = tmp
    tmp = [ans.shift / 2]
  elsif ans[0] < tmp[0]
    tmp << tmp.shift / 2
  else
    tmp << ans.shift / 2
  end
end
ans += tmp
puts ans.inject(:+)
//  [ruby]
n, m = gets.split.map(&:to_i)
a = gets.split.map(&:to_i).sort.reverse

s = []

m.times do
  if a.empty?
    s << s.shift / 2
    next
  end

  if s.empty?
    s << a.shift / 2
    next
  end

  if s[0] > a[0]
    s << s.shift / 2
  else
    s << a.shift / 2
  end
end

s += a
puts s.inject(:+)
//  [ruby]
class SkewHeap
  def initialize(rev = nil)
    @rev = rev
  end
  def push(k)
    @root = meld(@root, Node.new(k))
  end
  def top
    @root.key
  end
  def empty?
    @root.nil?
  end
  def pop
    key = @root.key
    @root = meld(@root.lchild, @root.rchild)
    key
  end
  def meld(lhs, rhs)
    return lhs unless rhs
    return rhs unless lhs
    lhs, rhs = rhs, lhs unless lhs < rhs
    lhs, rhs = rhs, lhs if @rev
    lhs.rchild = meld(lhs.rchild, rhs)
    lhs.lchild, lhs.rchild = lhs.lchild, lhs.rchild
    lhs
  end
  class Node
    include Comparable
    attr_accessor :key, :lchild, :rchild
    def initialize(k)
      @key = k
    end
    def <=>(other)
      @key <=> other.key
    end
  end
end

N,M=gets.split.map(&:to_i)
A=gets.split.map(&:to_i)
q=SkewHeap.new(true)
A.each do |a| q.push(a) end
M.times do
  q.push(q.pop/2)
end
s=0
s+=q.pop until q.empty?
p s
//  [ruby]
eval'_,M,*A='+`dd`.split*?,
(..1).bsearch{|i|d=M
k=A.sum{|a|a>>=d-d-=1while-i<a
a}
d<0||!X=k+i/2*d}
p X
//  [ruby]
eval'_,M,*A='+`dd`.split*?,
(-2**30..).bsearch{|i|d=M
k=A.sum{|a|a>>=d-d-=1while-i<a
a}
d<0||!X=k+i/2*d}
p X
//  [rust]
fn main() {
    let (n,m): (usize,usize) = read_pair();
    let a: Vec<i64> = read_vec();

    let mut a = a;
    let mut m = m;
    let mut k = 1<<30;
    while k > 0 && m > 0{
        a.sort_by(|a,b| b.cmp(a));
        for a in a.iter_mut() {
            if *a & k > 0 {
                *a >>= 1;
                m -= 1;
                if m == 0 { break }
            }
        }
        k >>= 1;
    }
    println!("{}", a.iter().fold(0, |s,&x| s+x))
}

fn get_line() -> String {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).ok();
    buf.trim().to_owned()
}
fn read<T: std::str::FromStr>() -> T{
    get_line().parse().ok().unwrap()
}
fn read_vec<T: std::str::FromStr>() -> Vec<T>{
    get_line().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}
fn read_pair<T: std::str::FromStr + Copy>() -> (T,T){
    let v:Vec<T> = read_vec(); (v[0], v[1])
}
//  [rust]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|s| s.parse().ok().unwrap())
        .collect()
}

fn main() {
    let input = read_vec::<usize>();
    let (n, m) = (input[0], input[1]);
    let mut v = Vec::with_capacity(n);

    let ax = read_vec::<usize>();
    for a in ax {
        v.push(a);
    }

    for _ in 0..m {
        v.sort();
        v[n-1] = v[n-1] / 2;
    }

    let ans: usize = v.into_iter().sum();

    println!("{}", ans);
}
//  [swift]
struct Heap<Element: Comparable>: SequenceType, GeneratorType {
    var items = [Element]()
    var i = 0
    mutating func next() -> Element? {
        defer { i += 1 }
        return i < items.count ? items[i] : nil
    }
    mutating func push(item: Element) {
        var i = items.count
        while i > 0 {
            let p = (i - 1) / 2
            if items[p] <= item {
                break
            }
            if i == items.count {
                items.append(items[p])
            } else {
                items[i] = items[p]
            }
            i = p
        }
        if i == items.count {
            items.append(item)
        } else {
            items[i] = item
        }
    }
    mutating func pop() -> Element {
        let ret = items[0]
        let x = items[items.count - 1]
        var i: Int = 0
        while i * 2 + 1 < items.count - 1 {
            var a = i * 2 + 1
            let b = i * 2 + 2
            if b < items.count - 1 && items[b] < items[a] {
                a = b
            }
            if items[a] >= x {
                break
            }
            items[i] = items[a]
            i = a
        }
        items[i] = x
        _ = items.removeLast()
        return ret
    }
}
let M = Int(String(readLine()!.characters.split(" ")[1]))!
var a = Heap<Int>()
readLine()!.characters.split(" ").forEach{a.push(-Int(String($0))!)}
(0..<M).forEach{_ in a.push(a.pop()/2)}
print(a.reduce(0){$0-$1})
//  [swift]
struct Heap<Element: Comparable>: CollectionType {
  var items = [Element]()
  var startIndex: Int {
    return items.startIndex
  }
  var endIndex: Int {
    return items.endIndex
  }
  subscript(i: Int) -> Element {
    return items[i]
  }
  mutating func push(item: Element) {
    var i = items.count
    while i > 0 {
      let p = (i - 1) / 2
      if items[p] <= item {
        break
      }
      if i == items.count {
        items.append(items[p])
      } else {
        items[i] = items[p]
      }
      i = p
    }
    if i == items.count {
      items.append(item)
    } else {
      items[i] = item
    }
  }
  mutating func pop() -> Element {
    let ret = items[0]
    let x = items[items.count - 1]
    var i: Int = 0
    while i * 2 + 1 < items.count - 1 {
      let b = i * 2 + 2
      if b < items.count - 1 && items[b] < items[a] {
        a = b
      }
      if items[a] >= x {
        break
      }
      items[i] = items[a]
      i = a
    }
    items[i] = x
    items.removeLast()
    return ret
  }
}
let M=Int(String(readLine()!.characters.split(" ")[1]))!
var q=Heap<Int>()
readLine()!.characters.split(" ").map{q.push(-Int(String($0))!)}
(0..<M).map{_ in q.push(q.pop()/2)}
print(q.reduce(0){$0-$1})
//  [swift]
struct Heap<Element: Comparable>: CollectionType {
  var items = [Element]()
  var startIndex: Int {
    return items.startIndex
  }
  var endIndex: Int {
    return items.endIndex
  }
  subscript(i: Int) -> Element {
    return items[i]
  }
  mutating func push(item: Element) {
    var i = items.count
    while i > 0 {
      let p = (i - 1) / 2
      if items[p] <= item {
        break
      }
      if i == items.count {
        items.append(items[p])
      } else {
        items[i] = items[p]
      }
      i = p
    }
    if i == items.count {
      items.append(item)
    } else {
      items[i] = item
    }
  }
  mutating func pop() -> Element {
    let ret = items[0]
    let x = items[items.count - 1]
    var i: Int = 0
    while i * 2 + 1 < items.count - 1 {
      let b = i * 2 + 2
      if b < items.count - 1 && items[b] < items[a] {
        a = b
      }
      if items[a] >= x {
        break
      }
      items[i] = items[a]
      i = a
    }
    items[i] = x
    _ = items.removeLast()
    return ret
  }
}
let M=Int(String(readLine()!.characters.split(" ")[1]))!
var q=Heap<Int>()
readLine()!.characters.split(" ").map{q.push(-Int(String($0))!)}
(0..<M).map{_ in q.push(q.pop()/2)}
print(q.reduce(0){$0-$1})
//  [typescript]
import * as fs from "fs";

class MaxHeap<T> {
	private items: Array<T>;
	constructor(items: Array<T>) {
		this.items = items;
		for(let ix: number = this.items.length; ix >= 0; ix--) {
			this.bubbleDown(ix);
		}
	}
	push(item: T): void {
		let i: number = this.items.length;
		this.items.push(item);
		this.bubbleUp(i);
	}
	pop(): T {
		let toReturn: T = this.items[0];
		let poppedElement: T = this.items.pop();
		if (this.items.length > 0) {
			this.items[0] = poppedElement;
			this.bubbleDown(0);
		}
		return toReturn;
	}
	peek(): T {
		return this.items[0];
	}
	size(): number {
		return this.items.length;
	}
	private bubbleUp(ix: number): void {
		if (ix != 0) {
			let p: number = Math.floor((ix-1)/2);
			if (this.items[ix] > this.items[p]) {
				[this.items[ix], this.items[p]] = [this.items[p], this.items[ix]];
				this.bubbleUp(p);
			}
		}
	}
	private bubbleDown(ix: number): void {
		let min_index = ix;
		for(let i = 1; i < 3; i++) {
			if (2*ix+i < this.items.length && this.items[min_index] < this.items[2*ix+i]) {
				min_index = 2*ix+i;
			}
		}
		if (min_index != ix) {
			[this.items[min_index], this.items[ix]] = [this.items[ix], this.items[min_index]]
			this.bubbleDown(min_index);
		}
	}
}

let [line1, line2] = fs.readFileSync("/dev/stdin", "utf8").split("\n");
let [N, M] = line1.split(" ").map(Number);
let A = line2.split(" ").map(Number);

let maxHeap: MaxHeap<number> = new MaxHeap(A);

while (M > 0) {
	maxHeap.push(Math.floor(maxHeap.pop()/2));
	M -= 1;
}

let total = 0;
while (maxHeap.size() > 0) {
	total += maxHeap.pop();
}

console.log(total);
//  [typescript]
import { readFileSync } from 'fs'
function main() {
  const input = readFileSync('/dev/stdin', 'utf8')
  const inputs = input.trim().split('\n')
  const [n, m] = inputs[0].split(' ').map(v => parseInt(v))
  let list = inputs[1].split(' ').map(v => parseInt(v)).sort((a, b) => b - a)
  for (let i = 0; i < m; i++) {
    list[0] = Math.floor(list[0] / 2)
    for (let k = 1; k < list.length; k++) {
      if (list[0] < list[k]) {
        const sortItem = list[k]
        list.splice(k, 1)
        list.unshift(sortItem)
        break
      }
    }
  }
  let result = 0
  list.forEach(v => {
    result += v
  })
  console.log(result)
}
main()
//  [typescript]
import { readFileSync } from 'fs'
function main() {
  const input = readFileSync('/dev/stdin', 'utf8')
  const inputs = input.trim().split('\n')
  const [n, m] = inputs[0].split(' ').map(v => parseInt(v))
  let list = inputs[1].split(' ').map(v => parseInt(v)).sort((a, b) => b - a)
  for (let i = 0; i < m; i++) {
    list[0] = Math.floor(list[0] / 2)
    list = list.sort((a, b) => b - a)
  }
  let result = 0
  list.forEach(v => {
    result += v
  })
  console.log(result)
}
main()
//  [python]
import sys, os, math, bisect, itertools, collections, heapq, queue
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from decimal import Decimal
from collections import defaultdict

# import fractions

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)
# lcm = lambda x, y: (x * y) // fractions.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    X = il()
    S = sorted(X)
    l = S[N // 2 - 1]
    r = S[N // 2]
    for x in X:
        if x <= l:
            print(r)
        else:
            print(l)


if __name__ == '__main__':
    main()
//  [python]
N = int(input())
X = list(map(int,input().split()))
Y = sorted(X)

m1=Y[N//2-1]
m2=Y[N//2]

medians = [m2 if x < m2 else m1 for x in X]
print('\n'.join(map(str,medians)))
//  [python]
def getval():
    n = int(input())
    x = list(map(int,input().split()))
    return n,x 

def main(n,x):
    y = sorted(x)
    a,b = y[(n-1)//2],y[(n-1)//2+1]
    for i in x:
        if i>a:
            print(a)
        else:
            print(b)

if __name__=="__main__":
    n,x = getval()
    main(n,x)
//  [python]
import statistics
n = int(input())
X = list(map(int, input().split()))
med = sorted(X)[n//2-1]
X_ = sorted(X)
X_.remove(med)
for i in range(n-1):
    if X_[i]>=med:
        med_2 = X_[i]
        break
for i in range(n):
    if X[i]>med:
        print(med)
    elif X[i]==med:
        print(med_2)
    else:
        print(med_2)
//  [python]
import numpy as np

N = int(input())
xl = [int(x) for x in input().split()]

xlsorted = np.sort(xl)
m1 = xlsorted[int(N/2)-1]
m2 = xlsorted[int(N/2)]

for i in range(N):
    if xl[i] <= m1:
        print(m2)
    else:
        print(m1)
//  [python]
#!/usr/bin/env python3

def main():
    n = int(input())
    x = list(map(int, input().split()))
    ans = [0] * n
    for i in range(n):
        fix = x[0:i] + x[i + 1:n]
        fix.sort()
        ans[i] = fix[n // 2 - 1]
    print(*ans, sep='\n')


if __name__ == "__main__":
    main()