# Task
 CodeBots decided to make a gift for CodeMaster's birthday. They got a pack of candies of various sizes from the store, but instead of giving the whole pack they are trying to make the biggest possible candy from them. On each turn it is possible:
 
 ```
 to pick any two candies of the same size and merge
 them into a candy which will be two times bigger;

 to pick a single candy of an even size and split it 
 into two equal candies half of this size each.```
What is the size of the biggest candy they can make as a gift?

# Example

 For `arr = [2, 4, 8, 1, 1, 15]`, the output should be 16.
```
[2, 4, 8, 1, 1, 15] --> [2, 4, 8, 2, 15]
-->[4, 4, 8, 15] --> [8, 8, 15] --> [16, 15] -->choose 16
``` 

# Input/Output


 - [input] integer array `arr`

    Array of positive integers.

    Constraints:
    
    `5 ≤ inputArray.length ≤ 50,`
    
    `1 ≤ inputArray[i] ≤ 100.`


 - `[output]` an integer

Source: codewars | Difficulty: EASY
Tags: Ad-hoc

Starter code: def obtain_max_number(arr):
	

Solutions:
from collections import Counter

def obtain_max_number(arr):
	c = Counter(arr)
	while 1:
		find = next((k for k in c if c[k] > 1), None)
		if not find:
			return max(c)
		c[find] -= 2
		c[find * 2] = c.get(find * 2, 0) + 1


from bisect import insort

def obtain_max_number(arr):
	arr = sorted(arr)
	while True:
		prev = -1
		for (i, x) in enumerate(arr):
			if x == prev:
				break
			prev = x
		else:
			return max(arr)
		insort(arr, arr.pop(i) + arr.pop(i - 1))


from collections import Counter

def obtain_max_number(arr):
	count = Counter(arr)
	while any((value > 1 for value in list(count.values()))):
		n = next((key for key in count if count[key] > 1))
		count[n] -= 2
		count[n * 2] += 1
	return max(count)


from collections import Counter

def obtain_max_number(arr):
	(tmp, prevLen) = (arr[:], 0)
	while len(tmp) != prevLen:
		(c, tmp, prevLen) = (Counter(tmp), [], len(tmp))
		for (k, v) in c.items():
			tmp.extend([2 * k] * (v // 2) + [k] * (v % 2))
	return max(c)


def obtain_max_number(arr):
	last_len = 0
	while len(arr) != last_len:
		last_len = len(arr)
		for n in arr:
			if arr.count(n) > 1:
				arr.remove(n)
				arr.remove(n)
				arr.append(n * 2)
	return max(arr)


from collections import Counter
from functools import lru_cache
from itertools import chain

@lru_cache(maxsize=None)
def func(n):
	return [n] if n & 1 else 2 * func(n >> 1)

def obtain_max_number(arr):
	return max((k * (1 << v.bit_length() - 1) for (k, v) in Counter(chain.from_iterable(map(func, arr))).items()))


from collections import Counter
obtain_max_number = lambda arr: (lambda n: max(n) if len(arr) == len(n) else obtain_max_number(n))(sum([[2 * k] * (v // 2) + [k] * (v % 2) for (k, v) in Counter(arr).items()], []))


def obtain_max_number(arr):
	used = [False] * len(arr)
	i = 0
	while i < len(arr):
		if not used[i]:
			j = i + 1
			while j < len(arr):
				if arr[j] == arr[i]:
					arr[j] += arr[i]
					arr[i] = 0
					used[i] = True
					i = -1
					break
				j += 1
		i += 1
	return max(arr)


from collections import Counter

def obtain_max_number(arr):
	c = dict(Counter(arr))
	s = set(c)
	r = 0
	while s:
		m = min(s)
		v = c[m]
		s -= {m}
		M = m * 2
		if v // 2:
			c[M] = c.get(M, 0) + v // 2
			s |= {M}
		r = max(r, m)
	return r


def obtain_max_number(arr):
	while sorted(arr) != sorted(list(set(arr))):
		new_arr = []
		checked = []
		for i in arr:
			if arr.count(i) >= 2 and i not in checked:
				checked.append(i)
				n = [i * 2] * (arr.count(i) // 2) if arr.count(i) % 2 == 0 else [i * 2] * ((arr.count(i) - 1) // 2) + [i]
				new_arr.extend(n)
			elif arr.count(i) < 2 and i not in checked:
				checked.append(i)
				new_arr.append(i)
		arr = new_arr[:]
	return max(arr)