#include<stdio.h>

int main(){
	int N;
	scanf("%d",&N);
	double A=N;
	if(N%2==0){
	printf("0.5");
    }else{
    	printf("%f\n",(A+1)/2/A);
    }

	return 0;
}


#include <stdio.h>

int main(void) {
  int n;
  scanf("%d", &n);

  int i, cnt_odd = 0;
  for (i = 1; i <= n; ++i) {
    if (i % 2) ++cnt_odd;
  }

  printf("%lf\n", (double)cnt_odd / n);

  return 0;
}


main(n){scanf("%d",&n);printf("%f",-~n/2*1./n);}


#include<stdio.h>

int main(void){
  int a;
  scanf("%d",&a);
  int b=(a+1)/2;
  double c=(double)b/a
  printf("%f\n",c);
  return 0;
}


#include<stdio.h>

int main(void){
  int a;
  scanf("%d",&a);
  printf("%f\n",(a+1)/2/a);
  return 0;
}


#include <stdio.h>
int main(void)
{
  int N;
  scanf ("%d",&N);
  double M;
  M=(double) N;
  if (N%2==0) printf ("%f",1/2);
  else printf ("%f",(((M-1)/2)+1)/M);


function main(arg) {
	arg = arg.trim();
  	arg = parseInt(arg, 10);
	console.log(((Math.round(arg/2))/arg).toFixed(9))
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


function Main(input) {
    var nums = Number(input);
    var cnt = 0;
    for(var i = 1;i <= nums;i++){
      if(i % 2 !== 0) {
        cnt++;
      }
    }
    console.log(cnt / nums);
 }

/* var input = `4`;
Main(input);
 */
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


'use strict'
const main = input => {
  const z = parseInt(input[0], 10);
  console.log(Math.ceil(z/2)/z);
}
main(require("fs").readFileSync("/dev/stdin", "utf8").split('\n'));


function Main(input) {

    var data = input.split("\n");
    var n = parseInt(data[0]);
    var ans;
    if(n%2==0){
        ans = 0.5;
    }else{
        ans = (n+1)/2/n;
    }

    console.log('%f\n',ans);
}
//（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


function Main(input) {

    var data = input.split("\n")
    var n = parseInt(data[0]);
    var ans;
    if(n%2==0){
        ans = 0.5;
    }else{
        ans = (n+1)/2/n;
    }

    console.log('%f\n',ans);
}
//（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


function Main(input) {

    var data = input.split("\n")
    var n = parseInt(data[0]);
    var ans;
    if(n%2==0){
        ans = 0.5;
    }else{
        ans = (n+1)/2/n
    }

    console.log('%f\n',ans);
}
//（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


package main

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

var mod = 1000000007

func main() {
	r := bufio.NewReader(os.Stdin)
	var n int
	fmt.Fscan(r, &n)

	odds := 0
	evens := 0
	for i := 1; i <= n; i++ {
		if i%2 == 0 {
			evens++
		} else {
			odds++
		}
	}
	fmt.Println(float64(odds) / float64(odds+evens))
}

// Union-Find
type unionFind struct {
	d []int
}

func newUnionFind(n int) *unionFind {
	uf := new(unionFind)
	uf.d = make([]int, n)
	for i := 0; i < n; i++ {
		uf.d[i] = -1
	}
	return uf
}

func (uf *unionFind) find(x int) int {
	if uf.d[x] < 0 {
		return x
	}
	uf.d[x] = uf.find(uf.d[x])
	return uf.d[x]
}

func (uf *unionFind) unite(x, y int) bool {
	rootX := uf.find(x)
	rootY := uf.find(y)
	if rootX == rootY {
		return false
	}

	if uf.d[rootX] < uf.d[rootY] {
		uf.d[rootX] += uf.d[rootY]
		uf.d[rootY] = rootX
	} else {
		uf.d[rootY] += uf.d[rootX]
		uf.d[rootX] = rootY
	}

	return true
}

func (uf *unionFind) same(x, y int) bool {
	return uf.find(x) == uf.find(y)
}

func (uf *unionFind) size(x int) int {
	return -uf.d[uf.find(x)]
}

// mod
func modpow(a, n, mod int) int {
	res := 1
	for n > 0 {
		if n%2 != 0 {
			res = res * a % mod
		}
		a = a * a % mod
		n = n / 2
	}
	return res
}

func modinv(n, mod int) int {
	return modpow(n, mod-2, mod)
}

func modcomb(n, a, mod int) int {
	x := 1
	y := 1
	for i := 0; i < a; i++ {
		x = x * (n - i)
		x %= mod
		y = y * (i + 1)
		y %= mod
	}
	return x * modpow(y, mod-2, mod) % mod
}

func modfactorial(n, mod int) int {
	result := 1
	for i := 1; i <= n; i++ {
		result = (result * i) % mod
	}
	return result
}

// Combination ...
type Combination struct {
	facts, invs []int
	mod         int
}

// NewCombination ...
func NewCombination(n, mod int) Combination {
	return Combination{
		facts: make([]int, n+1),
		invs:  make([]int, n+1),
		mod:   mod,
	}
}

func (cmb *Combination) calc(n, k int) int {
	ret := cmb.facts[n] * cmb.invs[k]
	ret %= cmb.mod
	ret = ret * cmb.invs[n-k]
	ret %= cmb.mod
	return ret
}

func (cmb *Combination) init(n int) {
	cmb.facts[0] = 1
	// 階乗を算出
	for i := 1; i <= n; i++ {
		cmb.facts[i] = cmb.facts[i-1] * i % cmb.mod
	}
	// 逆元を算出
	cmb.invs[n] = modinv(cmb.facts[n], cmb.mod)
	for i := n - 1; i >= 0; i-- {
		cmb.invs[i] = cmb.invs[i+1] * (i + 1) % cmb.mod
	}
}

// Utility
func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

func primeFactor(x int) map[int]int {
	res := make(map[int]int)
	for i := 2; i*i <= x; i++ {
		for x%i == 0 {
			res[i]++
			x = x / i
		}
	}
	if x != 1 {
		res[x] = 1
	}
	return res
}

func divisor(x int) []int {
	res := make([]int, 0)
	for i := 1; i*i <= x; i++ {
		if x%i == 0 {
			res = append(res, i)
			if i != x/i {
				res = append(res, x/i)
			}
		}
	}
	return res
}

func gcd(x, y int) int {
	if y == 0 {
		return x
	}
	return gcd(y, x%y)
}

func lcm(x, y int) int {
	return x / gcd(x, y) * y
}

func reverseString(s string) string {
	r := []rune(s)
	for i, j := 0, len(r)-1; i < len(r)/2; i, j = i+1, j-1 {
		r[i], r[j] = r[j], r[i]
	}
	return string(r)
}

// Queue ...
type Queue []int

// pop ...
func (q *Queue) empty() bool {
	return len(*q) == 0
}

// push ...
func (q *Queue) push(i int) {
	*q = append(*q, i)
}

// pop ...
func (q *Queue) pop() (int, bool) {
	if q.empty() {
		return 0, false
	} else {
		res := (*q)[0]
		*q = (*q)[1:]
		return res, true
	}
}

// Stack ...
type Stack []int

// pop ...
func (s *Stack) empty() bool {
	return len(*s) == 0
}

// push ...
func (s *Stack) push(i int) {
	*s = append(*s, i)
}

// pop ...
func (s *Stack) pop() (int, bool) {
	if s.empty() {
		return 0, false
	} else {
		index := len(*s) - 1
		res := (*s)[index]
		*s = (*s)[:index]
		return res, true
	}
}

// priority_queue
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)
	x := old[n-1]
	*h = old[0 : n-1]
	return x
}

// sortable points
type point struct {
	x int
	y int
}

type points []point

func (p points) Len() int {
	return len(p)
}

func (p points) Less(i, j int) bool {
	return p[i].x < p[j].x
}

func (p points) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}


package main

import "fmt"

func main(){
	var N int ;
	var gu, ki float64
	fmt.Scan(&N);

	for i := 1 ; i <= N ; i++ {
		if i % 2== 0{
			gu++;
		}else {
			ki++;
		}
	}
	fmt.Println(float64(ki / (ki+gu)));
}


package main

import(
  "fmt"
)

func main() {
  var N int
  fmt.Scan(&N)
  if N % 2 == 0 {
    fmt.Println(0.5)
  } else {
    fmt.Println(((float64(N)-float64(1))/float64(2)+float64(1))/float64(N))
  }
}


package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)

	scanner.Scan()

	N, err := strconv.Atoi(scanner.Text())
	if err != nil {
		log.Fatal(err)
	}

	if N%2 == 0 {
		fmt.Println(float32((N / 2)) / float32(N))
	} else {
		fmt.Println(float32(((N - 1) / 2)) / float32(N))
	}
}


package main

import "fmt"

func main() {
	var n int
	var r float64

	fmt.Scan(&n)

	if n%2 == 0 {
		r = float64(n / 2)
	} else {
		r = float64((n+1)/2) / float64(n)
	}

	fmt.Println(r)
}


package main

import "fmt"

func main() {
	var n int
	var r float32

	fmt.Scan(&n)

	if n%2 == 0 {
		r = n / 2
	} else {
		r = float32((n+1)/2) / n
	}

	fmt.Println(r)
}


N= gets.strip.to_f

if N%2==0
	puts 0.5
else
	puts ((N+1)/2)/(N)

end


N=gets.to_i
puts N.even? ? 0.500000 : (1+N/2)/N.to_f


N = gets.to_i
odds = (N.even? ? N/2 : N/2+1)
p odds / N.to_f


n=gets.to_i
p (n+1)/2.0/n


n=gets.to_f
if n==1
  puts 1.000
elsif n%2==0
  puts 0.5
else
  puts 0.6
end


n=gets.to_i
cnt=0
(0...n).each do |i|
  if i%2==1
    cnt=cnt.succ
  end
end
p cnt/n.to_f


use proconio::input;
use proconio::marker::Chars;
fn main() {
    input!{
        n:usize
    };
    println!("{}", ((n+1)/2) as f32 / n as f32);
}


use std::io;

fn main() {
	let mut buf = String::new();
	io::stdin().read_line(&mut buf).expect("");
	let n = match buf.trim().parse::<i32>() {
		Ok(n) => n,
		_ => panic!(""),
	};
	let all = n / 2 + n%2;
	println!("{}", all as f32 / n as f32);
}


#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

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

fn f(s: &[char]) -> bool {
    let m = s.len();
    for i in 0..m {
        if s[i] != s[m - 1 - i] {
            return false;
        }
    }
    true
}

use std::iter::Iterator;

fn main() {
    input! {
        n : i64
    }

    let mut  num = n / 2;
    if n % 2 == 1 {
        num = num + 1;
    }

    println!("{}", num as f64 / n as f64)

}


use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

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

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let n: usize = iterator.next().unwrap().parse().unwrap();
    let odd: usize = n / 2 + n % 2;
    let ans: u64 = odd as f64 / n as f64;
    return ans.to_string();
}


macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
    	n:isize
    }

    println!("{}", a(n));
}

fn a(n:isize) -> f32 {
match n {
1 => 1.0,
2 => 0.5,
3 => 0.66666666666666666,
_ => if n%2==1 { ((n as f32)+1.0)/2.0/n } else { 0.5 }
}}


macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
    	n:isize
    }

    println!("{}", a(n));
}

fn a(n:isize) -> f32 {
match n {
1 => 1.0,
2 => 0.5,
3 => 0.66666666666666666,
_ => if n%2==1 { (n+1.0)/2.0/n } else { 0.5 }
}}


import Foundation

let num = Float(readLine()!)!

if num % 2 == 0 {
  print(0.5)
} else {
  let halfNum = Float((num + 1) / 2)
  print(halfNum/num)
}


let N = Int(readLine()!)!
print(Double(N/2+N%2)/Double(N))


func readInts() -> [Int] {
    return readLine()!.split(separator: " ").map { Int($0)! }
}
let a = readInts()
let b = a[0]
var c = b/2
if b%2 != 0 {
  c += 1
}
print(Double(c)/Double(b))


import Foundation

let input_line: String = readLine()!
let split: [String] = input_line.components(separatedBy: " ")

var N = Double(split[0])!

if (Int(N)%2==0){
    print(1/2)
}else{
    print((N+1)/(2*N))
}


import Foundation

let input_line: String = readLine()!
let split: [String] = input_line.components(separatedBy: " ")

var N = Double(split[0])!

if (Int(N)%2==0){
    print(Double(1/2))
}else{
    print(Double((N+1)/(2*N)))
}


import Foundation

let input_line: String = readLine()!
let split: [String] = input_line.components(separatedBy: " ")

var N = Double(split[0])!

if (N%2==0){
    print(Double(1/2))
}else{
    print(Double((N+1)/(2*N)))
}


import * as fs from 'fs'
const reader = (s: string) => parseInt(s, 10)

function Main(input: string) {
  const N = reader(input)

  console.log(N % 2 === 0 ? 0.5 : 1 - (N - 1) / 2 / N)
}

Main(fs.readFileSync('/dev/stdin', 'utf8'))


import * as fs from 'fs';

//in
// 4
//out
// 0.5
const main = (inp: string) => {

    const n = parseInt(inp);

    if (n % 2 === 0) {
        console.log(n / 2 / n);
    } else {
        console.log((n + 1) / 2 / n);
    }
};

main(fs.readFileSync('/dev/stdin', 'utf8').trim());


function Main(input) {
  let n = parseInput(input)[0][0];
  console.log(Math.ceil(n/2) / n);
}

function parseInput(input) {
  const lines = input.trim().split('\n');
  return lines.map(line => line.split(' '));
}

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


import * as fs from 'fs';

//in
// 4
//out
// 0.5
const main = (inp: string) => {

    const n = parseInt(inp);

    if (n % 2 === 0) {
        console.log(n / 2);
    } else {
        console.log((n + 1) / 2);
    }
};

main(fs.readFileSync('/dev/stdin', 'utf8').trim());


function main(input) {
  const fline: string = input.split('\n')[0];
  const sline: string[] = input.split('\n')[1].split(' ');
  const n: number = parseInt(fline.split(' ')[0], 10);
  const k: number = parseInt(fline.split(' ')[1], 10);
  const h: number[] = sline.map(x => parseInt(x, 10));

  let ans: number = 0;
  h.forEach(function(el) {
    if (el >= k) ans += 1;
  });
  console.log(ans);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


import * as fs from 'fs'
const reader = (s: string) => parseInt(s, 10)

function Main(input: string) {
  const N = reader(input)

  console.log(N !== 1 ? 1 - 2 / N : 1)
}

Main(fs.readFileSync('/dev/stdin', 'utf8'))


n,m=map(int,input().split())
a=list(map(int,input().split()))
a.sort(reverse=True)
c=0
while c<m:
  d=a[0]/2
  for i in range(n):
    if a[0]==0:
      c=m
    if a[i]>d:
      a[i]//=2
      c+=1
      if c==m:
        break
    else:
      a.sort(reverse=True)
      break
print(sum(a))


N,M=map(int,input().split())
*A,=map(int,input().split())
A=sorted(A)

while M:
    A[-1]//=2
    M-=1
    i=-2
    while M and (-N<=i and A[i]>=A[-1]):
        A[i]//=2
        M-=1
        i-=1
    A.sort()

print(sum(A))


n,m = map(int,input().split())
a = sorted(map(int,input().split()))

import bisect

for i in range(m):
    a[-1] //= 2

    if 1 < len(a):
        if a[-2] > a[-1]:
            bisect.insort(a,a[-1])
            a = a[:-1]

print(sum(a))


n,m = map(int,input().split())
a = sorted(map(int,input().split()))

for i in range(m):
    a[-1] //= 2

    if 1 < len(a) and a[-2] > a[-1]:
        a = sorted(a)

print(sum(a))


n,m = map(int,input().split())
a = sorted(map(int,input().split()))

for i in range(m):
    a[-1] //= 2

    if a[-2] > a[-1]:
        a = sorted(a)

print(sum(a))


import java.util.*;
import java.io.*;
import static java.lang.System.*;

class FastScanner {
  private final InputStream in = System.in;
  private final byte[] buffer = new byte[1024];
  private int ptr = 0;
  private int buflen = 0;
  private boolean hasNextByte() {
      if (ptr < buflen) {
          return true;
      }else{
          ptr = 0;
          try {
              buflen = in.read(buffer);
          } catch (IOException e) {
              e.printStackTrace();
          }
          if (buflen <= 0) {
              return false;
          }
      }
      return true;
  }
  private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
  private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
  public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
  public String next() {
      if (!hasNext()) throw new NoSuchElementException();
      StringBuilder sb = new StringBuilder();
      int b = readByte();
      while(isPrintableChar(b)) {
          sb.appendCodePoint(b);
          b = readByte();
      }
      return sb.toString();
  }
  public long nextLong() {
      if (!hasNext()) throw new NoSuchElementException();
      long n = 0;
      boolean minus = false;
      int b = readByte();
      if (b == '-') {
          minus = true;
          b = readByte();
      }
      if (b < '0' || '9' < b) {
          throw new NumberFormatException();
      }
      while(true){
          if ('0' <= b && b <= '9') {
              n *= 10;
              n += b - '0';
          }else if(b == -1 || !isPrintableChar(b)){
              return minus ? -n : n;
          }else{
              throw new NumberFormatException();
          }
          b = readByte();
      }
  }
  public int nextInt() {
      long nl = nextLong();
      if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
      return (int) nl;
  }
  public double nextDouble() { return Double.parseDouble(next());}
}

class Main {
  public static final int MOD = 1000000007;
  public static final int INF = 1000000000;
  public static int[] heap;		// データの配列
  public static int num;		// 現在の要素数
  public static void main(String[] args) {
    FastScanner sc = new FastScanner();
    int N = sc.nextInt();
    int M = sc.nextInt();
    int A[] = new int[N];
    heap = new int[N+10];
    num = 0;
    for(int i=0; i<N; i++){
      A[i] = sc.nextInt();
      insert(A[i]);
    }
    for(int i=0; i<M; i++){
      int a = deletemax();
      a /= 2;
      insert(a);
    }
    long ans = 0;
    for(int i=0; i<N; i++){
      ans += heap[i];
    }
    out.println(ans);
  }

  public static void insert(int a){
    heap[num++]=a;
    int i=num,j=i/2;
    while(i>1 && heap[i-1]>heap[j-1]){
      int t=heap[i-1];
      heap[i-1]=heap[j-1];
      heap[j-1]=t;
      i=j;
      j=i/2;
    }
  }

  /*
   * 先頭の要素を取り除き、返す
   */
  public static int deletemax(){
    int r=heap[0];
    heap[0]=heap[--num];
    int i=1,j=i*2;
    while(j<=num){
      if(j+1<=num && heap[j-1]<heap[j]) j++;
      if(heap[i-1]<heap[j-1]){
	int t=heap[i-1];
	heap[i-1]=heap[j-1];
	heap[j-1]=t;
      }
      i=j;
      j=i*2;
    }
    return r;
  }

}


import java.io.IOException;
import java.io.InputStream;
import java.util.InputMismatchException;
import java.util.PriorityQueue;

public class Main {

	public static void main(String[] args) {
		Task task = new Task();
		task.solve();
	}

	static class Task {
		static final long MOD = (long) 1e9 + 7;

		public void solve() {
			Scan sc = new Scan();
			int n = (int) sc.scanLong();
			int m = (int) sc.scanLong();
			PriorityQueue<Integer> pq = new PriorityQueue<>();
			for (int i = 0; i < n; ++i) {
				pq.add(-1 * (int) sc.scanLong());
			}
			for (int i = 0; i < m; ++i) {
				int min = pq.poll();
				min /= 2;
				pq.add(min);
			}
			long res = 0;
			for (int el : pq) {
				res += -1 * el;
			}
			System.out.println(res);
		}
	}

	static class Scan {
		private byte[] buf = new byte[1024];
		private int index;
		private InputStream in;
		private int total;

		public Scan() {
			in = System.in;
		}

		public int scan() {
			if (total < 0)
				throw new InputMismatchException();
			if (index >= total) {
				index = 0;
				try {
					total = in.read(buf);
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
				if (total <= 0)
					return -1;
			}
			return buf[index++];
		}

		public long scanLong() {
			long integer = 0;
			int n = scan();
			while (isWhiteSpace(n))
				n = scan();
			int neg = 1;
			if (n == '-') {
				neg = -1;
				n = scan();
			}
			while (!isWhiteSpace(n)) {
				if (n >= '0' && n <= '9') {
					integer *= 10;
					integer += n - '0';
					n = scan();
				} else
					throw new InputMismatchException();
			}
			return neg * integer;
		}

		public double scanDouble() throws IOException {
			double doub = 0;
			int n = scan();
			while (isWhiteSpace(n))
				n = scan();
			int neg = 1;
			if (n == '-') {
				neg = -1;
				n = scan();
			}
			while (!isWhiteSpace(n) && n != '.') {
				if (n >= '0' && n <= '9') {
					doub *= 10;
					doub += n - '0';
					n = scan();
				} else
					throw new InputMismatchException();
			}
			if (n == '.') {
				n = scan();
				double temp = 1;
				while (!isWhiteSpace(n)) {
					if (n >= '0' && n <= '9') {
						temp /= 10;
						doub += (n - '0') * temp;
						n = scan();
					} else
						throw new InputMismatchException();
				}
			}
			return doub * neg;
		}

		public String scanString() {
			StringBuilder sb = new StringBuilder();
			int n = scan();
			while (isWhiteSpace(n))
				n = scan();
			while (!isWhiteSpace(n)) {
				sb.append((char) n);
				n = scan();
			}
			return sb.toString();
		}

		public char scanChar() {
			int n = scan();
			while (isWhiteSpace(n))
				n = scan();
			return (char) n;
		}

		private boolean isWhiteSpace(int n) {
			if (n == ' ' || n == '\n' || n == '\r' || n == '\t' || n == -1)
				return true;
			return false;
		}
	}
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.PriorityQueue;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.util.Collections;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        DPowerfulDiscountTickets solver = new DPowerfulDiscountTickets();
        solver.solve(1, in, out);
        out.close();
    }

    static class DPowerfulDiscountTickets {
        public void solve(int testNumber, InputReader in, OutputWriter out) {
            int n = in.nextInt();
            int m = in.nextInt();

            long[] a = in.nextLongArray(n);
            PriorityQueue<Long> res = new PriorityQueue<>(Collections.reverseOrder());

            long sum = 0;
            long total = 0;
            for (long j : a) {
                res.add(j);
                total += j;
            }
            while (m != 0) {
                m--;
                long x = res.peek();
                res.poll();
                sum += x - x / 2;
                res.add(x / 2);
            }

            out.println(total - sum);
        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void close() {
            writer.close();
        }

        public void println(long i) {
            writer.println(i);
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public long nextLong() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public long[] nextLongArray(int n) {
            long[] array = new long[n];
            for (int i = 0; i < n; ++i) array[i] = nextLong();
            return array;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}


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

        }
    }


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


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


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


#include <bits/stdc++.h>

namespace fast {
    // fast I/O by rsk0315 (update: 2019-08-08 07:02:47).
    // This version supports only integer inputs/outputs, single character
    // outputs, and string literal outputs.
    static size_t constexpr buf_size = 1 << 17;
    static size_t constexpr margin = 1;
    static char inbuf[buf_size + margin] = {};
    static char outbuf[buf_size + margin] = {};
    static __attribute__((aligned(8))) char minibuf[32];
    static size_t constexpr int_digits = 20;  // 18446744073709551615
    static uintmax_t constexpr digit_mask = 0x3030303030303030;
    static uintmax_t constexpr first_mask = 0x00FF00FF00FF00FF;
    static uintmax_t constexpr second_mask = 0x0000FFFF0000FFFF;
    static uintmax_t constexpr third_mask = 0x00000000FFFFFFFF;
    static uintmax_t constexpr tenpow[] = {
            1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000
    };
    template <typename Tp>
    using enable_if_integral = std::enable_if<std::is_integral<Tp>::value, Tp>;

    class scanner {
        char* pos = inbuf;
        char* endpos = inbuf + buf_size;

        void M_read_from_stdin() {
            endpos = inbuf + fread(pos, 1, buf_size, stdin);
        }
        void M_reread_from_stdin() {
            ptrdiff_t len = endpos - pos;
            if (!(inbuf + len <= pos)) return;
            memcpy(inbuf, pos, len);
            char* tmp = inbuf + len;
            endpos = tmp + fread(tmp, 1, buf_size-len, stdin);
            *endpos = 0;
            pos = inbuf;
        }

    public:
        scanner() { M_read_from_stdin(); }

        template <typename Integral,
                typename enable_if_integral<Integral>::type* = nullptr>
        void scan_parallel(Integral& x) {
            // See https://qiita.com/rsk0315_h4x/items/17a9cb12e0de5fd918f4
            if (__builtin_expect(endpos <= pos + int_digits, 0))
                M_reread_from_stdin();
            bool ends = false;
            typename std::make_unsigned<Integral>::type y = 0;
            bool neg = false;
            if (std::is_signed<Integral>::value && *pos == '-') {
                neg = true;
                ++pos;
            }
            do {
                memcpy(minibuf, pos, 8);
                long c = *(long*)minibuf;
                long d = (c & digit_mask) ^ digit_mask;
                int skip = 8;
                int shift = 8;
                if (d) {
                    int ctz = __builtin_ctzl(d);
                    if (ctz == 4) break;
                    c &= (1L << (ctz-5)) - 1;
                    int discarded = (68-ctz) / 8;
                    shift -= discarded;
                    c <<= discarded * 8;
                    skip -= discarded;
                    ends = true;
                }
                c |= digit_mask;
                c ^= digit_mask;
                c = ((c >> 8) + c*10) & first_mask;
                c = ((c >> 16) + c*100) & second_mask;
                c = ((c >> 32) + c*10000) & third_mask;
                y = y*tenpow[shift] + c;
                pos += skip;
            } while (!ends);
            x = (neg? -y: y);
            ++pos;
        }

        template <typename Integral,
                typename enable_if_integral<Integral>::type* = nullptr>
        void scan_serial(Integral& x) {
            if (__builtin_expect(endpos <= pos + int_digits, 0))
                M_reread_from_stdin();
            bool neg = false;
            if (std::is_signed<Integral>::value && *pos == '-') {
                neg = true;
                ++pos;
            }
            typename std::make_unsigned<Integral>::type y = *pos-'0';
            while (*++pos >= '0') y = 10*y + *pos-'0';
            x = (neg? -y: y);
            ++pos;
        }

        template <typename Integral,
                typename enable_if_integral<Integral>::type* = nullptr>
        // Use scan_parallel(x) only when x may be too large (about 10^12).
        // Otherwise, even when x <= 10^9, scan_serial(x) may be faster.
        void scan(Integral& x) { scan_serial(x); }
    };

    class printer {
        char* pos = outbuf;

        void M_flush_stdout() {
            fwrite(outbuf, 1, pos-outbuf, stdout);
            pos = outbuf;
        }

    public:
        printer() = default;
        ~printer() { M_flush_stdout(); }

        void print(char c) {
            if (__builtin_expect(pos + 1 >= outbuf + buf_size, 0)) M_flush_stdout();
            *pos++ = c;
        }

        template <size_t N>
        void print(char const(&s)[N]) {
            if (__builtin_expect(pos + N >= outbuf + buf_size, 0)) M_flush_stdout();
            memcpy(pos, s, N-1);
            pos += N-1;
        }

        template <typename Integral,
                typename enable_if_integral<Integral>::type* = nullptr>
        void print(Integral x) {
            if (__builtin_expect(pos + int_digits >= outbuf + buf_size, 0))
                M_flush_stdout();
            if (x == 0) {
                *pos++ = '0';
                return;
            }
            if (x < 0) {
                *pos++ = '-';
                if (__builtin_expect(x == std::numeric_limits<Integral>::min(), 0)) {
                    switch (sizeof x) {
                        case 2: print("32768"); return;
                        case 4: print("2147483648"); return;
                        case 8: print("9223372036854775808"); return;
                    }
                }
                x = -x;
            }
            char* mp = minibuf + sizeof minibuf;
            *--mp = x % 10 + '0';
            size_t len = 1;
            typename std::make_unsigned<Integral>::type y = x / 10;
            while (y > 0) {
                *--mp = y % 10 + '0';
                y /= 10;
                ++len;
            }
            memcpy(pos, mp, len);
            pos += len;
        }

        template <typename Tp>
        void println(Tp x) { print(x), print('\n'); }
    };
} // fast::

fast::scanner in;
fast::printer out;

int main(){ // O(N+logA+logM)
    using namespace std;
    unsigned long N, M;
    in.scan(N);
    in.scan(M);
    vector<unsigned long> A(N);
    for(auto& i : A)in.scan(i);
    {
        vector<unsigned long> s(31);
        for(const auto& i : A)++s[__builtin_clzl(i) - 33UL]; // O(N)
        partial_sum(s.cbegin(), s.cend(), s.begin()); // O(logA)
        partial_sum(s.cbegin(), s.cend(), s.begin()); // O(logA)
        s[30] = M + 2;
        auto t = s.end() - upper_bound(s.cbegin(), s.cend(), M); // O(loglogA)
        for(auto& i : A)if(64UL > t + __builtin_clzl(i)){ // O(N)
            auto k = 64UL - t - __builtin_clzl(i);
            M -= k;
            i >>= k;
        }
    }
    nth_element(A.begin(), A.begin() + M - 1, A.end(), greater<>()); // expected O(N)
    unsigned long ans{0};
    for(unsigned long i = 0; i < N; ++i)ans += A[i] >> (i < M); // O(N)
    out.print(ans);
    return 0;
}


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


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


#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;
}
/*

*/


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


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


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


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


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


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


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


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)


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")}]);


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


"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()


"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()


"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()


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)

}


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
}


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
}


package main

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

const (
	initialBufSize = 1e4
	maxBufSize     = 1e6 + 7
)

var buf []byte = make([]byte, initialBufSize)
var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(buf, maxBufSize)
}

var d = []Position{{1, 0}, {-1, 0}, {0, 1}, {0, -1}}
var d8 = []Position{{1, 0}, {-1, 0}, {0, 1}, {0, -1}, {1, 1}, {1, -1}, {-1, 1}, {-1, -1}}

// 問題によって値は調整する
const (
	mod     = int(1e9) + 7
	maxsize = 510000
)

func main() {
	N, M := nextInt(), nextInt()
	A := make([]int, N)
	for i := 0; i < N; i++ {
		A[i] = nextInt()
	}
	sort.Ints(A)
	for i := 0; i < M; i++ {
		A[len(A)-1] /= 2
		if len(A) > 1 && A[len(A)-1] < A[len(A)-2] {
			sort.Ints(A)
		}
	}
	var ans int
	for i := 0; i < N; i++ {
		ans += A[i]
	}
	fmt.Println(ans)
}

// Position として迷路問題での現在地を表す構造体を定義
type Position struct {
	H int
	W int
}

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

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

// Math Utilities
// https://play.golang.org/p/bm7uZi0zCN

// Abs Absolute Value
func Abs(a int) int {
	if a > 0 {
		return a
	}
	return -a
}

// Pow Integer power: compute a**b using binary powering algorithm
// See Donald Knuth, The Art of Computer Programming, Volume 2, Section 4.6.3
func Pow(a, b int) int {
	p := 1
	for b > 0 {
		if b&1 != 0 {
			p *= a
		}
		b >>= 1
		a *= a
	}
	return p
}

// PowMod Modular integer power: compute a**b mod m using binary powering algorithm
func PowMod(a, b, m int) int {
	a = a % m
	p := 1 % m
	for b > 0 {
		if b&1 != 0 {
			p = (p * a) % m
		}
		b >>= 1
		a = (a * a) % m
	}
	return p
}

func ceil(a, b int) int {
	return (a + (b - 1)) / b
}

// MinOf 与えられたintのうち最小のものを返す
func MinOf(vars ...int) int {
	min := vars[0]
	for _, i := range vars {
		if min > i {
			min = i
		}
	}
	return min
}

// MaxOf 与えられたintのうち最大のものを返す
func MaxOf(vars ...int) int {
	max := vars[0]
	for _, i := range vars {
		if max < i {
			max = i
		}
	}
	return max
}

func gcdof2numbers(a int, b int) int {
	if b == 0 {
		return a
	}
	return gcdof2numbers(b, a%b)
}

func lcmof2numbers(a int, b int) int {
	return a / gcdof2numbers(a, b) * b
}

// マイナスの場合は考慮していない
func factorial(a int) int {
	if a == 1 || a == 0 {
		return 1
	} else {
		return factorial(a-1) * a
	}
}

// NextPermutation はsortインターフェース（要はソート済みスライス）から次の順列にスライスを並べ替える
// https://play.golang.org/p/ljft9xhOEn
func NextPermutation(x sort.Interface) bool {
	n := x.Len() - 1
	if n < 1 {
		return false
	}
	j := n - 1
	for ; !x.Less(j, j+1); j-- {
		if j == 0 {
			return false
		}
	}
	l := n
	for !x.Less(j, l) {
		l--
	}
	x.Swap(j, l)
	for k, l := j+1, n; k < l; {
		x.Swap(k, l)
		k++
		l--
	}
	return true
}

// PrimeFactorize 素因数分解したmapを返す
func PrimeFactorize(n int) map[int]int {
	pf := map[int]int{}
	for i := 2; i*i <= n; i++ {
		for n%i == 0 {
			pf[i]++
			n /= i
		}
	}
	if n != 1 {
		pf[n]++
	}
	return pf
}

// FastPrimeFactorize osa_k法を使った高速素因数分解
// sieveを作るところのjはi*2スタートでもよい？
// https://qiita.com/rsk0315_h4x/items/ff3b542a4468679fb409
func FastPrimeFactorize(n int, sieve []int) map[int]int {
	pf := make(map[int]int)
	for n > 1 {
		pf[sieve[n]]++
		n /= sieve[n]
	}
	return pf
}

// MakeSieve は高速素数判定に使う篩を作る。
// Sieve[i] < i なら合成数なので、Sieveは素数判定にも使える
func MakeSieve(max int) []int {
	sieve := make([]int, max)
	for i := range sieve {
		sieve[i] = i
	}
	for i := 2; i*i <= max; i++ {
		if sieve[i] == i {
			for j := i; j < max; j += i {
				if sieve[j] == j {
					sieve[j] = i
				}
			}
		}
	}
	return sieve
}

// IH golangの公式サンプルより
// https://xn--go-hh0g6u.com/pkg/container/heap/#example__intHeap
// IntHeap は，整数の最小ヒープです。
type IH []int

func (h IH) Len() int           { return len(h) }
func (h IH) Less(i, j int) bool { return h[i] < h[j] }
func (h IH) Swap(i, j int)      { h[i], h[j] = h[j], h[i] }

func (h *IH) Push(x interface{}) {
	// Push と Pop はポインタレシーバを使っています。
	// なぜなら，スライスの中身だけでなく，スライスの長さも変更するからです。
	*h = append(*h, x.(int))
}

func (h *IH) Pop() interface{} {
	old := *h
	n := len(old)
	x := old[n-1]
	*h = old[0 : n-1]
	return x
}

// golangの公式サンプルより
// https://xn--go-hh0g6u.com/pkg/container/heap/#example__priorityQueue

// Item は，優先キューで管理する項目です。
type Item struct {
	value    string // 値。任意です。
	priority int    // キューにおける優先度
	// index は heap.Interface メソッドで更新されます。
	index int // ヒープにおけるインデックス
}

// PriorityQueue は heap.Interface を実装し，Item のリストを保持します。
type PriorityQueue []*Item

func (pq PriorityQueue) Len() int { return len(pq) }

func (pq PriorityQueue) Less(i, j int) bool {
	// Pop が最小ではなく最大の優先度を持つ項目を返して欲しいので，ここでは > を使っています。
	return pq[i].priority > pq[j].priority
}

func (pq PriorityQueue) Swap(i, j int) {
	pq[i], pq[j] = pq[j], pq[i]
	pq[i].index = i
	pq[j].index = j
}

func (pq *PriorityQueue) Push(x interface{}) {
	n := len(*pq)
	item := x.(*Item)
	item.index = n
	*pq = append(*pq, item)
}

func (pq *PriorityQueue) Pop() interface{} {
	old := *pq
	n := len(old)
	item := old[n-1]
	old[n-1] = nil  // メモリリークを避ける
	item.index = -1 // 安全のため
	*pq = old[0 : n-1]
	return item
}

// update はキューの Item の優先度と値を更新します。
func (pq *PriorityQueue) update(item *Item, value string, priority int) {
	item.value = value
	item.priority = priority
	heap.Fix(pq, item.index)
}

// UnionFind の定義
// 下記を参考
// https://youtu.be/TdR816rqc3s?t=6822
// https://github.com/atcoder/live_library/blob/master/uf.cpp
// https://qiita.com/haru1843/items/2295d0ec1f5002bd5c33#%E5%AE%9F%E8%A3%85
type UnionFind struct {
	parent []int
	maxlen int
}

// UnionFind のスライス初期化
func newUnionFind(N int) *UnionFind {
	u := new(UnionFind)
	u.parent = make([]int, N)
	u.maxlen = 1
	for i := range u.parent {
		u.parent[i] = -1
	}
	return u
}

// xの根を見つける
func (u *UnionFind) find(x int) int {
	if u.parent[x] < 0 {
		return x
	}
	u.parent[x] = u.find(u.parent[x])
	return u.parent[x]
}

// xとyのグループを結合する
func (u *UnionFind) unite(x, y int) {
	xf := u.find(x)
	yf := u.find(y)
	if xf == yf {
		return
	}
	// 常に大きい方に小さい木をくっつける
	if xf > yf {
		xf, yf = yf, xf
	}
	u.parent[xf] += u.parent[yf]
	u.parent[yf] = xf
	if u.parent[xf] < 0 {
		u.maxlen = MaxOf(u.maxlen, Abs(u.parent[xf]))
	}
}

// xとyが同じグループに所属するかどうかを返す
func (u *UnionFind) same(x, y int) bool {
	if u.find(x) == u.find(y) {
		return true
	}
	return false
}

// xの所属するグループの木の大きさを返す
func (u *UnionFind) size(x int) int {
	return -u.parent[u.find(x)]
}

// 根の数を返す
func (u UnionFind) rootcnt() int {
	var cnt int
	for _, v := range u.parent {
		if v < 0 {
			cnt++
		}
	}
	return cnt
}

// COMで使うスライス
var fac = make([]int, maxsize)
var finv = make([]int, maxsize)
var inv = make([]int, maxsize)

// COMinit で COMで使うためのテーブルを作る前処理
// O(N)
// https://qiita.com/drken/items/3b4fdf0a78e7a138cd9a#5-%E4%BA%8C%E9%A0%85%E4%BF%82%E6%95%B0-ncr
func COMinit() {
	fac[0], fac[1] = 1, 1
	finv[0], finv[1] = 1, 1
	inv[1] = 1
	for i := 2; i < maxsize; i++ {
		fac[i] = fac[i-1] * i % mod
		inv[i] = mod - inv[mod%i]*(mod/i)%mod
		finv[i] = finv[i-1] * inv[i] % mod
	}
}

// COM nCkを求める。COMinitを先に実行する
// COMinitの結果を使ってO(1)で行える
func COM(n, k int) int {
	if n < k {
		return 0
	}
	if n < 0 || k < 0 {
		return 0
	}
	return fac[n] * (finv[k] * finv[n-k] % mod) % mod
}


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
}


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
}


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(&:+)


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(:+)


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(:+)


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


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


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


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])
}


#![allow(unused_imports)]
use std::cmp::{max, min};
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};

use nyan::*;

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

    let n: usize = sc.read();
    let m: usize = sc.read();
    let mut a: BinaryHeap<u64> = sc.read_vec(n);

    for _ in 0..m {
        *a.peek_mut().unwrap() /= 2;
    }

    println!("{}", a.into_iter().sum::<u64>());
}

#[allow(dead_code)]
mod nyan {
    use std::cmp::*;
    use std::fmt::{Debug, Display};
    use std::io::{self, BufRead};
    use std::iter::FromIterator;
    use std::str::FromStr;

    // https://doc.rust-lang.org/1.39.0/src/core/num/mod.rs.html#4473-4523
    #[inline]
    pub fn is_ascii_whitespace(c: char) -> bool {
        match c {
            '\t' | '\n' | '\x0C' | '\r' | ' ' => true,
            _ => false,
        }
    }

    #[inline]
    pub fn is_ascii_linebreak(c: char) -> bool {
        match c {
            '\n' | '\r' => true,
            _ => false,
        }
    }

    struct Reader<R> {
        reader: R,
        buffer: String,
        cursor: usize,
    }

    impl<R: BufRead> Reader<R> {
        fn new(reader: R) -> Reader<R> {
            Reader {
                reader: reader,
                buffer: String::with_capacity(32),
                cursor: 0,
            }
        }

        #[inline]
        fn trim_start(&mut self) {
            match self.buffer[self.cursor..].find(|c| !is_ascii_whitespace(c)) {
                Some(l) => self.cursor += l,
                None => self.cursor = self.buffer.len(),
            }
        }

        fn prepare_buffer(&mut self) -> io::Result<()> {
            self.trim_start();

            while self.buffer.len() - self.cursor == 0 {
                self.buffer.clear();
                match self.reader.read_line(&mut self.buffer) {
                    Err(e) => return Err(e),
                    Ok(0) => return Err(io::Error::from(io::ErrorKind::UnexpectedEof)),
                    Ok(_) => {
                        self.cursor = 0;
                        self.trim_start();
                    }
                }
            }

            Ok(())
        }

        fn next_word(&mut self) -> io::Result<&str> {
            self.prepare_buffer()?;

            match self.buffer[self.cursor..].find(is_ascii_whitespace) {
                Some(l) => {
                    let start = self.cursor;
                    self.cursor += l;
                    Ok(&self.buffer[start..self.cursor])
                }
                None => Err(io::Error::from(io::ErrorKind::Other)),
            }
        }

        fn next_line(&mut self) -> io::Result<&str> {
            self.prepare_buffer()?;

            match self.buffer[self.cursor..].find(is_ascii_linebreak) {
                Some(l) => {
                    let start = self.cursor;
                    self.cursor += l;
                    Ok(&self.buffer[start..self.cursor])
                }
                None => Err(io::Error::from(io::ErrorKind::Other)),
            }
        }
    }

    pub struct Scanner<R> {
        reader: Reader<R>,
    }

    impl<R: BufRead> Scanner<R> {
        pub fn new(reader: R) -> Scanner<R> {
            Scanner {
                reader: Reader::new(reader),
            }
        }

        pub fn read<T>(&mut self) -> T
        where
            T: FromStr,
            <T as FromStr>::Err: Debug,
        {
            self.reader.next_word().unwrap().parse().unwrap()
        }

        pub fn read_vec<T, U>(&mut self, n: usize) -> T
        where
            T: FromIterator<U>,
            U: FromStr,
            <U as FromStr>::Err: Debug,
        {
            (0..n).map(|_| self.read()).collect()
        }

        pub fn read_vec2d<T, U, V>(&mut self, m: usize, n: usize) -> T
        where
            T: FromIterator<U>,
            U: FromIterator<V>,
            V: FromStr,
            <V as FromStr>::Err: Debug,
        {
            (0..m).map(|_| self.read_vec(n)).collect()
        }

        pub fn read_line<T: FromIterator<char>>(&mut self) -> T {
            self.reader.next_line().unwrap().chars().collect()
        }

        pub fn read_lines<T, U>(&mut self, n: usize) -> T
        where
            T: FromIterator<U>,
            U: FromIterator<char>,
        {
            (0..n).map(|_| self.read_line()).collect()
        }
    }

    pub fn print_vec<T: Display>(v: &[T]) {
        if v.is_empty() {
            return;
        }

        print!("{}", v[0]);
        for i in v.iter().skip(1) {
            print!(" {}", i);
        }
        println!();
    }

    // C++ like binary search functions (upper_bound, lower_bound, equal_range)
    pub trait BinarySearch<T> {
        fn lower_bound(&self, value: &T) -> usize;
        fn upper_bound(&self, value: &T) -> usize;
        fn equal_range(&self, value: &T) -> (usize, usize) {
            (self.lower_bound(value), self.upper_bound(value))
        }
    }

    impl<T: Ord> BinarySearch<T> for [T] {
        // https://en.cppreference.com/w/cpp/algorithm/lower_bound#Possible_implementation
        fn lower_bound(&self, value: &T) -> usize {
            let mut first = 0;
            let mut last = self.len();
            while last != first {
                let mid = (first + last) / 2;
                match self[mid].cmp(value) {
                    Ordering::Less => first = mid + 1,
                    _ => last = mid,
                }
            }
            first
        }

        // https://en.cppreference.com/w/cpp/algorithm/upper_bound#Possible_implementation
        fn upper_bound(&self, value: &T) -> usize {
            let mut first = 0;
            let mut last = self.len();
            while last != first {
                let mid = (first + last) / 2;
                match self[mid].cmp(value) {
                    Ordering::Greater => last = mid,
                    _ => first = mid + 1,
                }
            }
            first
        }
    }

    #[test]
    pub fn test_binary_search() {
        let data = vec![1, 1, 2, 3, 3, 3, 3, 4, 4, 4, 5, 5, 6];
        assert_eq!(data.lower_bound(&4), 7);
        assert_eq!(data.upper_bound(&4), 10);
    }

    // https://doc.rust-lang.org/std/cmp/struct.Reverse.html
    #[derive(PartialEq, Eq, Debug)]
    pub struct Rev<T>(pub T);

    impl<T: PartialOrd> PartialOrd for Rev<T> {
        fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
            other.0.partial_cmp(&self.0)
        }
    }

    impl<T: Ord> Ord for Rev<T> {
        fn cmp(&self, other: &Self) -> Ordering {
            other.0.cmp(&self.0)
        }
    }

    // Extended Euclidean algorithm
    // ax + by = gcd(x, y)
    pub fn extended_gcd(a: u64, b: u64) -> (u64, i64, i64) {
        if b == 0 {
            (a, 1, 0)
        } else {
            let (m, y, x) = extended_gcd(b, a % b);
            (m, x, y - (a / b) as i64 * x)
        }
    }

    pub fn gcd(a: u64, b: u64) -> u64 {
        if b == 0 {
            a
        } else {
            gcd(b, a % b)
        }
    }

    pub fn lcm(a: u64, b: u64) -> u64 {
        (a * b) / gcd(a, b)
    }

    // x^n (mod p)
    pub fn pow_mod(mut x: u64, mut n: u64, p: u64) -> u64 {
        let mut r = 1;
        while n > 0 {
            if n & 1 > 0 {
                r *= x;
                r %= p;
            }
            x *= x;
            x %= p;
            n >>= 1;
        }
        r
    }

    #[test]
    fn test_pow_mod() {
        assert_eq!(pow_mod(4, 13, 497), 445);
        assert_eq!(pow_mod(2, 90, 13), 12);
        assert_eq!(pow_mod(2, 99999999, 147), 134);
    }

    // a^{p-1} = 1 (mod p) (Fermat's little theorem)
    // a^{p - 2} * a = 1 → a^{-1} = a^{p-2}
    pub fn inv_mod(n: u64, p: u64) -> u64 {
        pow_mod(n, p - 2, p)
    }

    // s * (s + 1) * .. * t (mod p)
    pub fn prod_mod(s: u64, t: u64, p: u64) -> u64 {
        (s..t + 1).fold(1, |acc, x| acc * x % p)
    }

    // nCk (mod p)
    pub fn comb_mod(n: u64, k: u64, p: u64) -> u64 {
        // nCk = n! / (k! * (n - k)!)
        //     = ((n-k+1) * (n-k+2) * ... * n) * inv(k!)
        prod_mod(n - k + 1, n, p) * inv_mod(prod_mod(1, k, p), p) % p
    }

    #[inline]
    pub fn minmax<T: Ord>(a: T, b: T) -> (T, T) {
        if a < b {
            (a, b)
        } else {
            (b, a)
        }
    }

    #[test]
    fn test_minmax() {
        assert_eq!(minmax(1, 3), (1, 3));
        assert_eq!(minmax(3, 1), (1, 3));
    }

    pub struct UnionFind {
        n: usize,
        root: Vec<usize>,
        rank: Vec<usize>,
        size: Vec<usize>,
    }

    impl UnionFind {
        pub fn new(n: usize) -> UnionFind {
            UnionFind {
                n: n,
                root: (0..n).collect(),
                rank: vec![0; n],
                size: vec![1; n],
            }
        }

        pub fn root(&mut self, x: usize) -> usize {
            let r = self.root[x];
            if r == x {
                r
            } else {
                self.root[x] = self.root(r);
                self.root[x]
            }
        }

        pub fn merge(&mut self, x: usize, y: usize) {
            let rx = self.root(x);
            let ry = self.root(y);
            if rx == ry {
                return;
            }

            if self.rank[rx] < self.rank[ry] {
                self.root[rx] = ry;
                self.size[ry] += self.size[rx];
            } else {
                self.root[ry] = rx;
                self.size[rx] += self.size[ry];
                if self.rank[rx] == self.rank[ry] {
                    self.rank[rx] += 1;
                }
            }
        }

        pub fn size(&mut self, x: usize) -> usize {
            let rx = self.root(x);
            self.size[rx]
        }
    }
}