Your task is to form an integer array nums from an initial array of zeros arr that is the same size as nums.
Return the minimum number of function calls to make nums from arr.
The answer is guaranteed to fit in a 32-bit signed integer.
 
Example 1:
Input: nums = [1,5]
Output: 5
Explanation: Increment by 1 (second element): [0, 0] to get [0, 1] (1 operation).
Double all the elements: [0, 1] -> [0, 2] -> [0, 4] (2 operations).
Increment by 1 (both elements)  [0, 4] -> [1, 4] -> [1, 5] (2 operations).
Total of operations: 1 + 2 + 2 = 5.

Example 2:
Input: nums = [2,2]
Output: 3
Explanation: Increment by 1 (both elements) [0, 0] -> [0, 1] -> [1, 1] (2 operations).
Double all the elements: [1, 1] -> [2, 2] (1 operation).
Total of operations: 2 + 1 = 3.

Example 3:
Input: nums = [4,2,5]
Output: 6
Explanation: (initial)[0,0,0] -> [1,0,0] -> [1,0,1] -> [2,0,2] -> [2,1,2] -> [4,2,4] -> [4,2,5](nums).

Example 4:
Input: nums = [3,2,2,4]
Output: 7

Example 5:
Input: nums = [2,4,8,16]
Output: 8

 
Constraints:

1 <= nums.length <= 10^5
0 <= nums[i] <= 10^9

Difficulty: MEDIUM
Tags: Bit manipulation

Data structures

Greedy algorithms
Skill types: Bit manipulation

Data structures

Greedy algorithms

Starter code:
class Solution:
    def minOperations(self, nums: List[int]) -> int:
        

Solutions:
class Solution:

	def minOperations(self, nums: List[int]) -> int:
		return sum((bin(x).count('1') for x in nums)) + len(bin(max(nums))) - 3


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		add_count = sum((bin(v).count('1') for v in nums))
		mul_count = len(bin(max(nums))) - 3
		return add_count + mul_count

	def minOperations_my(self, nums: List[int]) -> int:
		add_sum = mul_maxi = 0
		for value in nums:
			c1 = c2 = 0
			while value > 1:
				if value & 1:
					c1 += 1
				c2 += 1
				value >>= 1
			add_sum += c1 + value
			mul_maxi = max(mul_maxi, c2)
		return add_sum + mul_maxi


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		m = [bin(x)[2:].zfill(32) for x in nums]
		ret = 0
		for i in range(32):
			cnts = sum([1 if x[i] == '1' else 0 for x in m])
			ret += cnts
			if ret > 0:
				ret += 1
				pass
			pass
		return ret - 1


class Solution:

	def minOperations(self, a: List[int]) -> int:
		ans = 0
		mx = 0
		for x in a:
			cnt = 0
			while x:
				if x % 2:
					ans += 1
				cnt += 1
				x //= 2
			mx = max(mx, cnt)
		return max(ans + mx - 1, 0)


class Solution:

	def minOperations(self, nums: List[int]) -> int:

		def highestBit(x):
			i = 0
			while x:
				i += 1
				x = x >> 1
			return i

		def numberOfBits(x):
			i = 0
			while x:
				i += 1
				x = x & x - 1
			return i
		doublings = max(map(highestBit, nums))
		print(doublings)
		adds = sum(map(numberOfBits, nums))
		print(adds)
		return doublings - 1 + adds


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		ops = 0
		max_num = 0
		for n in nums:
			max_num = max(max_num, n)
			while n > 0:
				n = n & n - 1
				ops += 1
		while max_num > 1:
			max_num >>= 1
			ops += 1
		return ops


class Solution:

	def minOperations_1(self, nums: List[int]) -> int:
		ops = 0
		while not all((n == 0 for n in nums)):
			for (i, n) in enumerate(nums):
				if n % 2 != 0:
					nums[i] = n - 1
					ops += 1
			if all((n == 0 for n in nums)):
				break
			nums = [n // 2 for n in nums]
			ops += 1
		return ops

	def minOperations_2(self, nums: List[int]) -> int:
		op_1 = 0
		op_2 = 0
		for n in nums:
			op_2_cur = 0
			while n > 0:
				if n % 2 != 0:
					op_1 += 1
					n -= 1
				else:
					op_2_cur += 1
					n = n // 2
			op_2 = max(op_2, op_2_cur)
		return op_1 + op_2

	def minOperations(self, nums: List[int]) -> int:
		op1 = 0
		op2 = 0
		for i in range(31):
			for n in nums:
				if n & 1 << i != 0:
					op1 += 1
					op2 = i
		return op1 + op2


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		addOneOperations = 0
		highestSetBit = 0
		for bit in range(31):
			for num in nums:
				if num & 1 << bit != 0:
					addOneOperations += 1
					highestSetBit = bit
		return addOneOperations + highestSetBit


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		if nums == [0]:
			return 0
		count = 0
		max_bits = 0
		for n in nums:
			bits = 0
			while n:
				count += n & 1
				bits += 1
				n >>= 1
			max_bits = max(max_bits, bits)
		return count + max_bits - 1


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		add_sum = mul_maxi = 0
		for value in nums:
			c1 = c2 = 0
			while value > 1:
				if value & 1:
					c1 += 1
				c2 += 1
				value >>= 1
			add_sum += c1 + value
			mul_maxi = max(mul_maxi, c2)
		return add_sum + mul_maxi


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		hb = 0
		ans = 0
		for n in nums:
			for i in range(32):
				if n & 1 << i:
					ans += 1
					if i > hb:
						hb = i
		return ans + hb


import collections

class Solution:

	def minOperations(self, nums: List[int]) -> int:
		sum = 0
		for num in nums:
			sum += collections.Counter(bin(num))['1']
		sum += len(bin(max(nums))) - 3
		return sum


class Solution:

	def minOperations(self, nums: List[int]) -> int:

		def n1b(x):
			ans = 0
			while x:
				x &= x - 1
				ans += 1
			return ans

		def hi(x):
			ans = 0
			while x:
				x >>= 1
				ans += 1
			return ans
		maxshift = 0
		tog = 0
		for n in nums:
			maxshift = max(maxshift, hi(n))
			tog += n1b(n)
		maxshift = max(0, maxshift - 1)
		return maxshift + tog


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		x = [0] * len(nums)
		counts = 0
		while 1:
			counts += sum((n % 2 for n in nums))
			nums = [n // 2 for n in nums]
			if nums == x:
				return counts
			counts += 1

		def div(l):
			for i in range(len(l)):
				if sum(l) == 0:
					return None
				l[i] *= 2
			return l

		def mi(l):
			for i in range(len(l)):
				l[i] += 1
			return l
		q = deque()
		q.append([0] * len(nums))
		d = 0
		while q:
			d += 1
			for i in range(len(q)):
				x = q.popleft()
				j = x.copy()
				print(x)
				if x == nums:
					return d
				y = div(j)
				if y != None:
					q.append(y)
				q.append(mi(x))


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		a = m = 0
		for i in nums:
			a += bin(i).count('1')
			m = max(m, len(bin(i)) - 3)
		return a + m


import math

class Solution:

	def minOperations(self, nums: List[int]) -> int:
		max_half_ops = 0

		def find_odd_ops_req(num):
			nonlocal max_half_ops
			result = 0
			half_ops = 0
			while num:
				result += num & 1
				half_ops += 1
				num = num >> 1
			max_half_ops = max(max_half_ops, half_ops - 1)
			return result
		result = 0
		for num in nums:
			result += find_odd_ops_req(num)
		return result + max_half_ops


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		(n_add, n_mul) = (0, 0)
		for num in nums:
			c_mul = 0
			while num > 1:
				n_add += num % 2
				num //= 2
				c_mul += 1
			if num == 1:
				n_add += 1
			n_mul = max(n_mul, c_mul)
		return n_add + n_mul


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		(op_0, op_1) = (0, 1)
		for num in nums:
			b_len = 0
			while num:
				op_0 += num & 1
				num >>= 1
				b_len += 1
			op_1 = max(op_1, b_len)
		return op_0 + op_1 - 1


import math

class Solution:

	def minOperations(self, nums: List[int]) -> int:
		count = max([int(math.log(x) / math.log(2)) for x in nums if x > 0])
		for n in nums:
			while n:
				if n % 2:
					count += 1
					n -= 1
				else:
					n //= 2
		return count


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		maxTwos = 0
		ones = 0
		for num in nums:
			(count, left) = self.getCount(num)
			maxTwos = max(maxTwos, count)
			ones += left
		return ones + maxTwos

	def getCount(self, num):
		count = 0
		odd = num % 2
		if num % 2 == 1:
			num -= 1
		while num > 1:
			odd += num % 2
			num //= 2
			count += 1
		return (count, num + odd)


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		(ans, largest) = (0, 0)
		for num in nums:
			largest = max(largest, num)
			while num > 0:
				if num % 2 == 1:
					num -= 1
					ans += 1
				if num > 0:
					num = num // 2
		while largest > 1:
			ans += 1
			largest = largest // 2
		return ans


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		twos = 0
		ones = 0
		for n in nums:
			mul = 0
			while n:
				if n % 2:
					n -= 1
					ones += 1
				else:
					n //= 2
					mul += 1
			twos = max(twos, mul)
		return ones + twos


class Solution:

	def minOperations(self, nums: List[int]) -> int:

		def numOperations(x):
			(n1, n2) = (0, 0)
			while x:
				if x & 1:
					n1 += 1
					x -= 1
				else:
					n2 += 1
					x //= 2
			return (n1, n2)
		(n1, n2) = (0, 0)
		for x in nums:
			(x1, x2) = numOperations(x)
			n1 += x1
			n2 = max(n2, x2)
		return n1 + n2


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		ones = 0
		twoes = 0
		for i in nums:
			c = 0
			while i:
				if i % 2:
					i -= 1
					ones += 1
				else:
					i //= 2
					c += 1
			twoes = max(twoes, c)
		return ones + twoes


class Solution:

	def minOperations(self, nums: List[int]) -> int:

		def operate(n):
			max_ = 0
			ans = 0
			k = 0
			while n > 0:
				k += 1
				ans += n % 2
				n = n // 2
			max_ = max(max_, k - 1)
			return (max_, ans)
		ans = 0
		max_ = 0
		for n in nums:
			(m, o) = operate(n)
			max_ = max(max_, m)
			ans += o
		return ans + max_


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		maxTwos = 0
		totalOnes = 0
		for num in nums:
			(twos, ones) = self.getCount(num)
			maxTwos = max(maxTwos, twos)
			totalOnes += ones
		return totalOnes + maxTwos

	def getCount(self, num):
		twos = 0
		ones = 0
		while num > 1:
			ones += num % 2
			num //= 2
			twos += 1
		return (twos, ones + num)


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		totOddRem = 0
		max2Power = 0
		for x in nums:
			pow2 = 0
			while True:
				totOddRem += x & 1
				if x > 1:
					pow2 += 1
					x >>= 1
				else:
					break
			if pow2 > max2Power:
				max2Power = pow2
		return totOddRem + max2Power


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		ans = 0
		while any(nums):
			ans += sum((n % 2 for n in nums))
			if any((n > 1 for n in nums)):
				ans += 1
			for i in range(len(nums)):
				nums[i] //= 2
		return ans


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		(maxLmove, bitCount) = (0, 0)
		for num in nums:
			if num == 0:
				continue
			Lmove = 0
			while num != 0:
				if num & 1:
					bitCount += 1
				num = num >> 1
				if num != 0:
					Lmove += 1
			maxLmove = max(maxLmove, Lmove)
		return maxLmove + bitCount


class Solution:

	def minOperations0(self, nums: List[int]) -> int:
		l = len(nums)
		ans = 0

		def turnEven():
			nonlocal ans
			for i in range(l):
				if nums[i] % 2 == 1:
					nums[i] -= 1
					ans += 1

		def countZero():
			count = 0
			for n in nums:
				if n == 0:
					count += 1
			return count
		while True:
			turnEven()
			if countZero() == l:
				return ans
			for i in range(l):
				nums[i] //= 2
			ans += 1

	def minOperations(self, nums: List[int]) -> int:
		res = 0
		maxLen = 1
		for n in nums:
			bits = 0
			while n > 0:
				res += n & 1
				bits += 1
				n >>= 1
			maxLen = max(maxLen, bits)
		return res + maxLen - 1


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		res = 0
		maxi = 0
		for num in nums:
			res += 1 if num > 0 else 0
			div = 0
			while num > 1:
				res += 1 if num % 2 else 0
				num //= 2
				div += 1
			maxi = max(div, maxi)
		return res + maxi


def val(n):
	c = 0
	while n > 1:
		if n % 2 == 1:
			c += 1
			n -= 1
		else:
			n = n // 2
	return c

def ma(n):
	c = 0
	while n > 1:
		if n % 2 == 1:
			n -= 1
		else:
			n = n // 2
			c += 1
	return c

class Solution:

	def minOperations(self, n: List[int]) -> int:
		c = ma(max(n))
		for i in range(len(n)):
			if n[i] > 0:
				c += val(n[i]) + 1
		return c


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		highest_bit = 0
		addone = 0
		for num in nums:
			tmp = -1
			while num > 0:
				addone += num & 1
				num >>= 1
				tmp += 1
			highest_bit = max(highest_bit, tmp)
		return highest_bit + addone


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		if max(nums) == 0:
			return 0
		return sum(map(lambda x: bin(x).count('1'), nums)) + int(log2(max(nums)))


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		op0 = 0
		op1 = 0
		for n in nums:
			l = 0
			while n > 0:
				l += 1
				if n % 2 == 1:
					op0 += 1
				n //= 2
			op1 = max(op1, l - 1)
		return op0 + op1


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		(two, one) = (0, 0)
		for n in nums:
			mul = 0
			while n:
				if n % 2:
					one += 1
					n -= 1
				else:
					mul += 1
					n //= 2
			two = max(two, mul)
		return one + two


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		mx = 1
		ops = 0
		for nm in nums:
			bt = 0
			while nm > 0:
				ops += nm & 1
				bt += 1
				nm = nm >> 1
			mx = max(mx, bt)
		return ops + mx - 1


class Solution:

	def minOperations(self, nums: List[int]) -> int:

		def ops(num):
			plus = 0
			mult = 0
			while num:
				if num % 2:
					plus += 1
					num -= 1
				else:
					num //= 2
					mult += 1
			return (plus, mult)
		plus = 0
		mult = 0
		for num in nums:
			(plus_, mult_) = ops(num)
			plus += plus_
			mult = max(mult, mult_)
		return plus + mult


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		total = 0
		currentMax = 0
		for n in nums:
			if n == 0:
				continue
			total += 1
			count = 0
			while n > 1:
				if n % 2 == 1:
					n -= 1
					total += 1
				n = n // 2
				count += 1
			currentMax = max(count, currentMax)
		return total + currentMax


class Solution:

	def minOperations(self, nums: List[int]) -> int:

		def calculate(num):
			temp1 = 0
			temp2 = 0
			while num:
				if num % 2:
					temp1 += 1
					num -= 1
				else:
					temp2 += 1
					num >>= 1
			return (temp1, temp2)
		(ones, twos) = (0, 0)
		for val in nums:
			if val:
				(a, b) = calculate(val)
				ones += a
				twos = max(twos, b)
		print(ones)
		return ones + twos


class Solution:

	def calc(self, num):
		m = 0
		a = 0
		while num > 0:
			if num & 1:
				a += 1
				num -= 1
			else:
				num = num >> 1
				m += 1
		return (a, m)

	def minOperations(self, nums: List[int]) -> int:
		adds = 0
		mults = 0
		for i in range(len(nums)):
			(a, m) = self.calc(nums[i])
			if mults < m:
				mults = m
			adds += a
		return mults + adds


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		cache = defaultdict(int)
		for i in nums:
			for (ind, j) in enumerate(bin(i)[2:][::-1]):
				if j == '1':
					cache[ind] += 1
		return sum(cache.values()) + max(cache.keys())


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		op = 0
		s = sum(nums)
		while s:
			odd_ct = len([0 for n in nums if n & 1])
			op += odd_ct
			s -= odd_ct
			if s != 0:
				nums = [n // 2 for n in nums]
				op += 1
				s /= 2
		return op


from collections import Counter

class Solution:

	def minOperations(self, nums: List[int]) -> int:
		max_doubles = 0
		increments = 0
		counts = Counter(nums)
		for (n, c) in counts.items():
			if n == 0:
				continue
			doubles = 0
			while n:
				if n % 2 == 1:
					increments += c
					n -= 1
				else:
					doubles += 1
					n //= 2
			max_doubles = max(max_doubles, doubles)
		return increments + max_doubles


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		(div_arr, sub_arr) = ([], [])
		for n in nums:
			div = 0
			sub = 0
			while n:
				if n % 2 == 1:
					n -= 1
					sub += 1
				else:
					n = n // 2
					div += 1
			sub_arr.append(sub)
			div_arr.append(div)
		return max(div_arr) + sum(sub_arr)


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		count = 0
		while any((n > 0 for n in nums)):
			for i in range(len(nums)):
				if nums[i] % 2 == 1:
					nums[i] -= 1
					count += 1
			if all((n == 0 for n in nums)):
				break
			nums = [n // 2 for n in nums]
			count += 1
		return count


class Solution:

	def minOperations(self, nums: List[int]) -> int:

		def countBit(num):
			(count, highbit) = (0, 0)
			while num > 0:
				highbit += 1
				if num % 2 == 1:
					count += 1
				num //= 2
			return (count, highbit)
		nums = sorted(nums)
		last = {}
		sum = 0
		maxDouble = 0
		for num in nums:
			if num == 0:
				continue
			elif num in last:
				sum += last[num]
			else:
				(count, highbit) = countBit(num)
				maxDouble = max(maxDouble, highbit)
				sum += count
				last = {num: count}
		print(sum, maxDouble)
		if maxDouble == 0:
			return 0
		return sum + maxDouble - 1


import math

class Solution:

	def minOperations(self, nums: List[int]) -> int:
		(ones, co, twos) = (0, 0, 0)
		for xx in nums:
			(x, c) = (0, 0)
			while xx > 1:
				co += xx & 1
				xx //= 2
				c += 1
			x = int(floor(math.log(max(xx, 1), 2)))
			twos = max(twos, x + c)
			ones += max(xx - 2 ** x, 0)
			if xx >= 1:
				ones += 1
		return ones + twos + co


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		n = len(nums)
		res = 0
		while any((v > 0 for v in nums)):
			for (i, v) in enumerate(nums):
				if v & 1:
					res += 1
				nums[i] >>= 1
			res += 1
		return res - 1


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		multi_max = 0
		answer = 0
		for num in nums:
			cur_multi = 0
			while num:
				if num % 2 == 1:
					answer += 1
					num -= 1
				else:
					cur_multi += 1
					num //= 2
			multi_max = max(multi_max, cur_multi)
		return answer + multi_max


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		if not nums:
			return 0
		(ans, nxt) = (0, [])
		for num in nums:
			if num & 1:
				num -= 1
				ans += 1
			if num:
				nxt.append(num // 2)
		if nxt:
			ans += 1
		return ans + self.minOperations(nxt)


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		n_add = 0
		n_mul = 0
		for n in nums:
			mul = 0
			while n > 0:
				if n % 2:
					n -= 1
					n_add += 1
				else:
					mul += 1
					n //= 2
			n_mul = max(n_mul, mul)
		return n_add + n_mul


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		count = 0
		res = 0
		double = 0
		for i in nums:
			count = 0
			while i:
				if i % 2 == 1:
					i -= 1
					res += 1
				else:
					i //= 2
					count += 1
			double = max(double, count)
		return res + double


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		ones = 0
		maxlen = 0
		binlen = 0
		for num in nums:
			binlen = 0
			while num != 0:
				if num % 2 != 0:
					ones += 1
					num -= 1
				if num != 0:
					num //= 2
					binlen += 1
			maxlen = max(maxlen, binlen)
		return maxlen + ones


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		n = len(nums)
		num = max(nums)
		res = 0
		for i in range(n):
			if nums[i] == 0:
				continue
			res += 1
			num = nums[i]
			while num > 1:
				res += num % 2
				num //= 2
		c = 0
		num = max(nums)
		while num > 1:
			num //= 2
			res += 1
		return res


class Solution:

	def minOperations(self, nums: List[int]) -> int:

		def calc(num):
			tmp = 1
			ans = [0, 0]
			count = 0
			while tmp <= num:
				if tmp & num != 0:
					ans[0] += 1
				count += 1
				tmp <<= 1
			ans[1] = count - 1
			return ans
		result = 0
		tt = 0
		for num in nums:
			r = calc(num)
			result += r[0]
			tt = max(tt, r[1])
		result += tt
		return result


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		ans = 0
		maxt = 0
		for i in nums:
			if i == 0:
				continue
			t = 0
			while i > 0:
				if i & 1:
					i -= 1
					ans += 1
				else:
					i >>= 1
					t += 1
			maxt = max(maxt, t)
		ans += maxt
		return ans


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		result = 0
		max_len = 0
		for num in nums:
			b = bin(num)
			result += b.count('1')
			max_len = max(max_len, len(b))
		return result + max_len - 3


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		doubles = 0
		incs = 0
		for num in nums:
			numDoubles = 0
			while num > 0:
				if num % 2 == 0:
					num //= 2
					numDoubles += 1
				else:
					num -= 1
					incs += 1
			doubles = max(doubles, numDoubles)
		return doubles + incs


class Solution:

	def minOpsSingle(self, x):
		n_inc = 0
		n_db = 0
		assert x >= 0
		while x > 0:
			if x % 2 == 0:
				x = x // 2
				n_db += 1
			else:
				x -= 1
				n_inc += 1
		return (n_inc, n_db)

	def minOperations(self, nums: List[int]) -> int:
		tot_inc = 0
		tot_db = 0
		for n in nums:
			(x, y) = self.minOpsSingle(n)
			tot_inc += x
			tot_db = max(tot_db, y)
		return tot_inc + tot_db


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		count = 0
		while not all((ele < 2 for ele in nums)):
			for i in range(len(nums)):
				if nums[i] % 2 == 1:
					nums[i] -= 1
					count += 1
				nums[i] //= 2
			count += 1
		count += sum((ele == 1 for ele in nums))
		return count


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		multiply = 0
		add = 0
		for num in nums:
			mask = 1
			for i in range(32):
				if mask << i & num:
					multiply = max(i, multiply)
					add += 1
		return multiply + add


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		n = len(nums)
		ans = 0
		while True:
			zeros = 0
			ans += 1
			for (i, num) in enumerate(nums):
				nums[i] = num // 2
				ans += num % 2
				if not nums[i]:
					zeros += 1
			if zeros == n:
				break
		return ans - 1


class Solution:

	def minOperations(self, nums: List[int]) -> int:

		def calcOps(num):
			one = 0
			two = 0
			while num > 0:
				if num % 2 == 0:
					num //= 2
					two += 1
				else:
					num -= 1
					one += 1
			return [one, two]
		one = 0
		two = 0
		for x in nums:
			ops = calcOps(x)
			one += ops[0]
			two = max(two, ops[1])
		return one + two


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		move = 0
		while max(nums) > 0:
			for (i, num) in enumerate(nums):
				if num % 2 == 1:
					move += 1
				nums[i] = num // 2
			if max(nums) > 0:
				move += 1
		return move


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		res = 0
		while any((x != 0 for x in nums)):
			for (i, x) in enumerate(nums):
				if x % 2 != 0:
					nums[i] -= 1
					res += 1
			if sum(nums) == 0:
				break
			nums = [x // 2 for x in nums]
			res += 1
		return res


class Solution:

	def minOperations(self, nums: List[int]) -> int:

		def all_zeros(nums):
			for num in nums:
				if num != 0:
					return False
			return True

		def to_all_evens(nums):
			cnt = 0
			for i in range(len(nums)):
				if nums[i] % 2 != 0:
					cnt += 1
					nums[i] -= 1
			return cnt
		op_cnt = 0
		while not all_zeros(nums):
			op_cnt += to_all_evens(nums)
			if not all_zeros(nums):
				nums = [x // 2 for x in nums]
				op_cnt += 1
		return op_cnt


class Solution:

	def minOperations(self, a: List[int]) -> int:
		(ans, max_len) = (0, 0)
		for (i, x) in enumerate(a):
			b = bin(x)
			ans += b.count('1')
			max_len = max(max_len, len(b) - 2)
		return ans + max_len - 1


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		res = 0
		max_len = 0
		for x in nums:
			bit = 0
			while x > 0:
				if x % 2 == 1:
					res += 1
				x >>= 1
				bit += 1
			max_len = max(max_len, bit)
		return res + max_len - 1


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		cnt = 0
		(max_val, max_index) = (-1, len(nums))
		for i in range(len(nums)):
			if nums[i] > max_val:
				max_val = nums[i]
				max_index = i
		while max_val != 0:
			for i in range(len(nums)):
				if nums[i] % 2 == 1:
					nums[i] -= 1
					cnt += 1
			max_val = nums[max_index]
			if max_val == 0:
				break
			for i in range(len(nums)):
				nums[i] = nums[i] // 2
			cnt += 1
			max_val = nums[max_index]
		return cnt


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		cnt1 = 0
		maxcnt0 = 0
		for n in nums:
			cnt0 = 0
			while n > 0:
				if n % 2 == 1:
					n -= 1
					cnt1 += 1
				else:
					n //= 2
					cnt0 += 1
			maxcnt0 = max(cnt0, maxcnt0)
		return maxcnt0 + cnt1


import math

class Solution:

	def minOperations(self, nums: List[int]) -> int:
		arr = nums.copy()
		count = result = 0
		while any(arr):
			for (i, n) in enumerate(arr):
				if n & 1:
					count += 1
					arr[i] -= 1
			result += count
			arr = [x >> 1 for x in arr]
			count = 0
		return result + int(math.log2(max(nums)))


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		c = 0
		while True:
			c0 = 0
			for i in range(len(nums)):
				if nums[i] % 2 == 1:
					c += 1
					nums[i] = (nums[i] - 1) // 2
				else:
					nums[i] = nums[i] // 2
				if nums[i] == 0:
					c0 += 1
			if c0 == len(nums):
				return c
			else:
				c += 1


class Solution:

	def minOperations(self, nums: List[int]) -> int:

		def iter_count(x):
			shift_count = sub_count = 0
			while x > 0:
				if x & 1:
					x -= 1
					sub_count += 1
				else:
					x >>= 1
					shift_count += 1
			return (shift_count, sub_count)
		max_shift_count = 0
		total_subs = 0
		for x in nums:
			(i, j) = iter_count(x)
			max_shift_count = max(max_shift_count, i)
			total_subs += j
		return max_shift_count + total_subs


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		count_of_one_steps = 0
		count_of_half_steps = 0
		for i in nums:
			one_steps = 0
			half_steps = 0
			while i != 0:
				if i % 2 == 0:
					half_steps += 1
					i //= 2
				else:
					one_steps += 1
					i -= 1
			count_of_one_steps += one_steps
			count_of_half_steps = max(count_of_half_steps, half_steps)
		return count_of_one_steps + count_of_half_steps


class Solution:

	def minOperations(self, nums: List[int]) -> int:

		def countcall(x, c):
			c0 = 0
			for i in range(len(x)):
				if x[i] % 2 == 1:
					c += 1
					x[i] = (x[i] - 1) // 2
				else:
					x[i] = x[i] // 2
				if x[i] == 0:
					c0 += 1
			if c0 == len(x):
				return c
			else:
				c += 1
				return countcall(x, c)
		return countcall(nums, 0)


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		(x, y) = (0, 0)
		for num in nums:
			num = format(num, 'b')
			x += num.count('1')
			y = max(y, len(num) - 1)
		return x + y


class Solution:

	def minOperations(self, nums: List[int]) -> int:

		def check(n):
			N_minus_one = 0
			N_div2 = 0
			while n > 0:
				if n % 2 == 0:
					n = n // 2
					N_div2 += 1
				else:
					n -= 1
					N_minus_one += 1
			return (N_minus_one, N_div2)
		N = len(nums)
		minus_one = []
		div2 = []
		for n in nums:
			(N_minus_one, N_div2) = check(n)
			minus_one.append(N_minus_one)
			div2.append(N_div2)
		res = sum(minus_one)
		res += max(div2)
		print(minus_one)
		print(div2)
		return res


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		cost = 0
		max_nb_op_1 = 0
		for i in range(len(nums)):
			nb_op_0 = nb_op_1 = 0
			x = nums[i]
			while x > 0:
				if x % 2 != 0:
					nb_op_0 += x % 2
					x -= x % 2
				if x > 0:
					nb_op_1 += 1
					x = x // 2
			cost += nb_op_0
			max_nb_op_1 = max(max_nb_op_1, nb_op_1)
		cost += max_nb_op_1
		return cost

	def minOperations_dumb_solution(self, nums: List[int]) -> int:
		cost = 0
		while True:
			all_zeros = True
			all_evens = True
			for i in range(len(nums)):
				if nums[i] == 0:
					continue
				all_zeros = False
				if nums[i] % 2 != 0:
					cost += nums[i] % 2
					nums[i] = nums[i] - nums[i] % 2
					all_evens = False
			if all_zeros:
				break
			while all_evens:
				for i in range(len(nums)):
					nums[i] = nums[i] // 2
					if nums[i] % 2 != 0:
						all_evens = False
				cost += 1
		return cost


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		step = 0
		while True:
			for i in range(len(nums)):
				if nums[i] % 2 != 0:
					nums[i] = nums[i] - 1
					step += 1
				nums[i] = nums[i] // 2
			if sum(nums) == 0:
				return step
			step += 1


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		ones = 0
		doubles = 0
		while sum(nums) != 0:
			for i in range(len(nums)):
				if nums[i] % 2 != 0:
					nums[i] -= 1
					ones += 1
			if sum(nums) != 0:
				for i in range(len(nums)):
					nums[i] = nums[i] // 2
				doubles += 1
		return ones + doubles


class Solution:

	def getPow(self, n: int) -> Tuple[int, int]:
		if n == 0:
			return (0, -1)
		if n == 1:
			return (1, 0)
		inc = 0
		mul = 0
		i = n
		while i != 0:
			if i % 2 == 1:
				inc += 1
				i = i - 1
			else:
				i = i // 2
				mul += 1
		return (inc, mul)

	def minOperations(self, nums: List[int]) -> int:
		pows = [self.getPow(n) for n in nums]
		num_incs = 0
		num_mults = 0
		max_pow = 0
		for i in range(0, len(nums)):
			if nums[i] == 0:
				continue
			if nums[i] == 1:
				num_incs += 1
			else:
				inc = pows[i][0]
				power = pows[i][1]
				num_incs += inc
				if power > max_pow:
					max_pow = power
		num_incs += max_pow
		return num_incs


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		cnt = 0
		if self.check(nums):
			return cnt
		while not self.check(nums):
			for i in range(len(nums)):
				cnt += nums[i] % 2
			cnt += 1
			self.divide2(nums)
		return cnt - 1

	def check(self, nums):
		for i in range(len(nums)):
			if nums[i] != 0:
				return False
		return True

	def divide2(self, nums):
		for i in range(len(nums)):
			nums[i] //= 2


class Solution:

	def minOperations(self, nums: List[int]) -> int:

		def fun_call(num, mem):
			if not mem.get(num) is None:
				return mem[num]
			add = 0
			mul = 0
			old_num = num
			while num > 0:
				if num % 2 == 0:
					num //= 2
					mul += 1
				else:
					num -= 1
					add += 1
			mem[old_num] = (add, mul)
			return mem[old_num]
		res = 0
		mul_max = 0
		mem = {0: (0, 0)}
		for i in range(len(nums)):
			(add, mul) = fun_call(nums[i], mem)
			res += add
			mul_max = max(mul_max, mul)
		res += mul_max
		return res


class Solution:

	def toZero(self, n):
		extra = 0
		pwr2 = 0
		while n > 0:
			if n % 2:
				n -= 1
				extra += 1
			else:
				n = n / 2
				pwr2 += 1
		return [extra, pwr2]

	def minOperations(self, nums: List[int]) -> int:
		maxPwr2 = 0
		extras = 0
		for n in nums:
			a = self.toZero(n)
			maxPwr2 = max(maxPwr2, a[1])
			extras += a[0]
		return extras + maxPwr2


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		res = 0
		mask = 2 ** 32 - 2
		for _ in range(32):
			end = True
			for (i, x) in enumerate(nums):
				res += x & 1
				nums[i] >>= 1
				if nums[i]:
					end = False
			if end:
				break
			res += 1
		return res


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		count = 0
		for i in range(len(nums)):
			if nums[i] % 2 != 0 and nums[i] > 0:
				count += 1
				nums[i] -= 1
		if nums == [0] * len(nums):
			return count
		nums = [i // 2 for i in nums]
		return count + self.minOperations(nums) + 1


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		count = 0
		while True:
			for (i, num) in enumerate(nums):
				if num % 2:
					nums[i] -= 1
					count += 1
			if sum(nums) == 0:
				return count
			for i in range(len(nums)):
				nums[i] //= 2
			count += 1


import math

class Solution:

	def minOperations(self, nums: List[int]) -> int:
		plus_one = times_two = 0
		for (idx, num) in enumerate(nums):
			two = 0
			while num:
				if num == 1:
					plus_one += 1
					break
				if num % 2:
					plus_one += 1
					num -= 1
				num = num // 2
				two += 1
			times_two = max(times_two, two)
		return plus_one + times_two


class Solution:

	def minOperations(self, nums) -> int:
		res = 0
		N = len(nums)
		while True:
			for (i, v) in enumerate(nums):
				if v & 1:
					res += 1
					nums[i] -= 1
			if nums == [0] * N:
				return res
			for i in range(N):
				nums[i] //= 2
			res += 1
		return res


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		(moves, ndone) = (0, len(nums) - nums.count(0))
		while ndone:
			for (i, num) in enumerate(nums):
				if num % 2 == 1:
					moves += 1
					nums[i] -= 1
					if nums[i] == 0:
						ndone -= 1
			if ndone:
				nums = [num // 2 for num in nums]
				moves += 1
		return moves


def get_num_ops(num):
	assert num >= 0
	(d_ops, s_ops) = (0, 0)
	while num != 0:
		if num % 2 == 1:
			num = num - 1
			s_ops += 1
		else:
			num = num // 2
			d_ops += 1
	return (d_ops, s_ops)

class Solution:

	def minOperations(self, nums: List[int]) -> int:
		num_ops = 0
		doubling_ops = []
		for num in nums:
			(d, s) = get_num_ops(num)
			doubling_ops.append(d)
			num_ops += d + s
			print(num_ops)
		doubling_ops = sorted(doubling_ops)
		change = [doubling_ops[0]]
		for i in range(1, len(doubling_ops)):
			change.append(doubling_ops[i] - doubling_ops[i - 1])
		for (i, c) in enumerate(change):
			num_ops = num_ops - c * (len(change) - i - 1)
		return num_ops


import math

class Solution:

	def minOperations(self, nums: List[int]) -> int:
		count = 0
		maxi = 0
		for j in nums:
			e = 0
			if j == 0:
				continue
			if j == 1:
				count = count + 1
			if j > 1:
				while j:
					if j % 2 == 0:
						e = e + 1
						j = j // 2
					else:
						j = j - 1
						count = count + 1
			if e > maxi:
				maxi = e
		count = count + maxi
		return count


class Solution:

	def minOperations(self, nums: List[int]) -> int:

		def count(n):
			a = b = 0
			while n:
				if n & 1:
					n -= 1
					b += 1
				else:
					n >>= 1
					a += 1
			return (a, b)
		maxA = sumB = 0
		for n in nums:
			(a, b) = count(n)
			maxA = max(maxA, a)
			sumB += b
		return maxA + sumB


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		number_of_moves = 0
		while True:
			for (pos, num) in enumerate(nums):
				if num % 2 == 1:
					nums[pos] -= 1
					number_of_moves += 1
			if not any(nums):
				break
			nums = list([x // 2 for x in nums])
			number_of_moves += 1
		return number_of_moves


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		op = 0
		sum1 = sum(nums)
		while sum1 != 0:
			for i in range(len(nums)):
				if nums[i] % 2 != 0:
					nums[i] -= 1
					sum1 -= 1
					op += 1
			if sum1 == 0:
				return op
			for i in range(len(nums)):
				nums[i] //= 2
			op += 1
			sum1 /= 2
		return op


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		d = {}
		odd = 0
		mx_even = 0
		for (i, val) in enumerate(nums):
			even = 0
			while val:
				if val % 2 == 0:
					while val > 0 and val % 2 == 0:
						val = val // 2
						even += 1
				else:
					val -= 1
					odd += 1
			mx_even = max(even, mx_even)
		return odd + mx_even


from math import log

class Solution:

	def minOperations(self, nums: List[int]) -> int:
		res = 0
		vposes = set(range(len(nums)))
		while vposes:
			rm = set()
			for i in vposes:
				if nums[i] % 2:
					nums[i] -= 1
					res += 1
				if not nums[i]:
					rm.add(i)
			vposes.symmetric_difference_update(rm)
			chg = False
			for i in vposes:
				chg = True
				nums[i] //= 2
			res += chg
		return res


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		ops = 0
		max_div = 0
		for n in nums:
			divs = 0
			while n > 0:
				if n % 2:
					n -= 1
					ops += 1
				else:
					n /= 2
					divs += 1
			max_div = max(max_div, divs)
		return ops + max_div


class Solution:

	def minOperations(self, a: List[int]) -> int:
		ans = 0
		zero_cnt = 0
		while zero_cnt < len(a):
			zero_cnt = 0
			for (i, x) in enumerate(a):
				if x % 2 == 1:
					ans += 1
					a[i] = (x - 1) // 2
				else:
					a[i] = x // 2
				zero_cnt += a[i] == 0
			ans += zero_cnt < len(a)
		return ans


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		steps = 0
		while True:
			for idx in range(0, len(nums)):
				if nums[idx] % 2 == 1:
					nums[idx] -= 1
					steps += 1
			if sum(nums) == 0:
				break
			nums = [int(x / 2) for x in nums]
			steps += 1
		return steps


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		ans = 0
		n = len(nums)
		not_zero = set(list(range(n)))
		while True:
			if len(not_zero) == 0:
				return ans
			zeros = []
			for i in not_zero:
				if nums[i] % 2 == 1:
					nums[i] -= 1
					ans += 1
				if nums[i] == 0:
					zeros.append(i)
				nums[i] = nums[i] // 2
			for j in zeros:
				not_zero.remove(j)
			if len(not_zero) > 0:
				ans += 1


class Solution:

	def minOperations(self, nums: List[int]) -> int:

		def get_add_mul_times(num: int):
			(a, b) = (0, 0)
			while num > 0:
				if num >> 1 << 1 != num:
					a += 1
					num -= 1
				else:
					b += 1
					num //= 2
			return (a, b)
		N = len(nums)
		(add, mul) = ([0] * N, [0] * N)
		for ii in range(N):
			(a, b) = get_add_mul_times(nums[ii])
			add[ii] = a
			mul[ii] = b
		return max(mul) + sum(add)


import numpy as np

class Solution:

	def minOperations(self, nums: List[int]) -> int:
		count = 0
		if not any(nums):
			return count
		for i in range(len(nums)):
			if nums[i] % 2 != 0:
				nums[i] -= 1
				count += 1
		if any(nums):
			count += 1
			for i in range(len(nums)):
				nums[i] = nums[i] // 2
		return count + self.minOperations(nums)


bin = '{:0b}'.format

class Solution:

	def minOperations(self, nums: List[int]) -> int:
		maxBitLen = 0
		bitCount = 0
		for num in nums:
			b = bin(num)
			maxBitLen = max(maxBitLen, len(b))
			bitCount += b.count('1')
		return maxBitLen + bitCount - 1


class Solution:

	def minOperations(self, nums: List[int]) -> int:

		@lru_cache(None)
		def helper(num):
			if num < 2:
				return (num, 0)
			(a, b) = helper(num // 2)
			return (a + num % 2, b + 1)
		a = b = 0
		for num in nums:
			(tmpa, tmpb) = helper(num)
			a += tmpa
			b = max(b, tmpb)
		return a + b


class Solution:

	def minOperations(self, nums: List[int]) -> int:

		def helper(num):
			if num in self.dic:
				return self.dic[num]
			n = num
			(count, even) = (0, 0)
			while n != 0:
				if n % 2 == 1:
					n -= 1
				else:
					n //= 2
					even += 1
				count += 1
			self.dic[num] = (count, even)
			return (count, even)
		(ans, maxb, self.dic) = (0, 0, {})
		for num in nums:
			(a, b) = helper(num)
			ans += a - b
			maxb = max(maxb, b)
		return ans + maxb


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		steps = 0
		(maxIdx, maxNum) = (None, -math.inf)
		for (idx, num) in enumerate(nums):
			if num > maxNum:
				maxNum = num
				maxIdx = idx
		(nums[maxIdx], nums[-1]) = (nums[-1], nums[maxIdx])

		def divideBy2(nums):
			nums = [num // 2 for num in nums]
			return nums
		while nums[-1] > 0:
			for i in range(len(nums)):
				if nums[i] % 2 == 1:
					nums[i] -= 1
					steps += 1
			if nums[-1] == 0:
				return steps
			nums = divideBy2(nums)
			steps += 1
		return steps


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		add = 0
		double = 0
		ans = 0
		for i in range(len(nums)):
			x = nums[i]
			if x == 0:
				continue
			add += 1
			curr = 0
			while x != 1:
				if x % 2 != 0:
					x -= 1
					add += 1
				while x % 2 != 1:
					x /= 2
					curr += 1
			double = max(double, curr)
		ans = double + add
		return ans


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		op_count = 0
		while not all([v == 0 for v in nums]):
			for i in range(len(nums)):
				odd = nums[i] % 2
				if odd:
					nums[i] -= 1
					op_count += 1
				nums[i] //= 2
			op_count += 1
		return max(0, op_count - 1)


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		ans = 0
		all_zero = False
		while not all_zero:
			all_zero = True
			for i in range(len(nums)):
				if nums[i] % 2 == 1:
					ans += 1
					nums[i] -= 1
				nums[i] //= 2
				if nums[i] != 0:
					all_zero = False
			if not all_zero:
				ans += 1
		return ans


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		res = 0
		_max = 0
		for i in nums:
			bit = 0
			while i > 0:
				res += i & 1
				i >>= 1
				bit += 1
			_max = max(bit, _max)
		return res + _max - 1


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		res = 0
		max_len = 0
		for num in nums:
			bits = 0
			while num > 0:
				res += num % 2
				num >>= 1
				bits += 1
			max_len = max(bits - 1, max_len)
		return res + max_len


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		res = 0
		n = len(nums)
		while 1:
			all0 = True
			has_div = False
			for i in range(n):
				if nums[i] == 0:
					continue
				all0 = False
				if nums[i] & 1:
					res += 1
					if nums[i] > 1:
						has_div = True
					nums[i] = (nums[i] - 1) // 2
				else:
					has_div = True
					nums[i] //= 2
			if all0:
				break
			if has_div:
				res += 1
		return res


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		count = 0
		while True:
			Zero = True
			for i in range(len(nums)):
				if nums[i] & 1:
					nums[i] -= 1
					count += 1
				if nums[i]:
					Zero = False
			if Zero:
				return count
			count += 1
			for i in range(len(nums)):
				nums[i] >>= 1


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		count = 0
		check = 0
		if not nums:
			return 0
		while check != len(nums):
			(x, check, nums) = self.odd(nums)
			count += x
			if check == len(nums):
				return count
			nums = self.div(nums)
			count += 1

	def div(self, nums):
		for i in range(len(nums)):
			nums[i] = nums[i] // 2
		return nums

	def odd(self, nums):
		a = 0
		b = 0
		for i in range(len(nums)):
			if nums[i] & 1 == 1:
				a += 1
				nums[i] -= 1
			if nums[i] == 0:
				b += 1
		return (a, b, nums)


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		maxDivideCount = 0
		minusCount = 0
		for num in nums:
			divideCount = 0
			while num != 0:
				if num % 2 == 0:
					num //= 2
					divideCount += 1
				else:
					num -= 1
					minusCount += 1
			maxDivideCount = max(divideCount, maxDivideCount)
		return maxDivideCount + minusCount


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		oneCnt = 0
		pwrCnt = 0
		for num in nums:
			if num == 0:
				continue
			exp = 0
			while num > 0:
				if num % 2 == 0:
					num /= 2
					exp += 1
				else:
					num -= 1
					oneCnt += 1
			pwrCnt = max(pwrCnt, exp)
		return oneCnt + pwrCnt


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		if sum(nums) == 0:
			return 0
		steps = 0
		n_zeros = 0
		for (i, num) in enumerate(nums):
			if num % 2 != 0:
				nums[i] -= 1
				steps += 1
			if nums[i] == 0:
				n_zeros += 1
			nums[i] = nums[i] // 2
		if n_zeros != len(nums):
			steps += 1
		return steps + self.minOperations(nums)


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		ans = 0
		while any(nums):
			for (i, x) in enumerate(nums):
				if x % 2 == 1:
					nums[i] -= 1
					ans += 1
			if any(nums):
				for (i, x) in enumerate(nums):
					nums[i] //= 2
				ans += 1
		return ans


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		max_dev = 0
		steps = 0
		for i in nums:
			dev = 0
			while i != 0:
				if i % 2 == 0:
					i = i / 2
					dev = dev + 1
				else:
					i = i - 1
					steps = steps + 1
			if dev > max_dev:
				max_dev = dev
		return steps + max_dev


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		res = 0
		t = 0
		for ele in nums:
			ele = str(bin(ele))[2:]
			res += ele.count('1')
			t = max(t, len(ele) - 1)
		return res + t


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		n = len(nums)
		one = 0
		two_req = 0
		for i in nums:
			two = 0
			i_copy = i
			while i_copy > 0:
				if i_copy % 2 == 0:
					i_copy = i_copy // 2
					two += 1
				else:
					i_copy -= 1
					one += 1
			two_req = max(two_req, two)
		res = two_req + one
		return res


from math import log

class Solution:

	def minOperations(self, nums: List[int]) -> int:
		cnt = int(log(max(nums)) / log(2))
		for n in nums:
			while n > 0:
				if n % 2 == 1:
					n -= 1
					cnt += 1
				else:
					n = n // 2
		return cnt


from functools import lru_cache

class Solution:

	def minOperations(self, nums: List[int]) -> int:
		divideByTwos = 0
		decrements = 0
		for num in nums:
			if num == 0:
				continue
			(divides, dec) = self.reductions(num)
			divideByTwos = max(divideByTwos, divides)
			decrements += dec
		return divideByTwos + decrements

	@lru_cache(maxsize=None)
	def reductions(self, num: int) -> (int, int):
		decrements = 0
		divides = 0
		while num > 1:
			if num % 2 == 0:
				num /= 2
				divides += 1
			else:
				num -= 1
				decrements += 1
		return (divides, decrements + 1)


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		ops = 0
		while not self.is_end(nums):
			ops += self.perform_decrement(nums)
			if self.is_end(nums):
				return ops
			ops += self.perform_division(nums)
		return ops

	def is_end(self, nums):
		return all((i == 0 for i in nums))

	def perform_decrement(self, nums):
		ops = 0
		for i in range(len(nums)):
			if nums[i] % 2 == 1:
				nums[i] -= 1
				ops += 1
		return ops

	def perform_division(self, nums):
		for i in range(len(nums)):
			if nums[i] != 0:
				nums[i] //= 2
		return 1


class Solution:

	def minOperations(self, nums: List[int]) -> int:

		@lru_cache(None)
		def get(n):
			add = 0
			mul = 0
			while n:
				if n & 1:
					add += 1
					n -= 1
				else:
					mul += 1
					n = n >> 1
			return (add, mul)
		cadd = 0
		mmul = 0
		for n in nums:
			(add, mul) = get(n)
			cadd += add
			mmul = max(mul, mmul)
		return cadd + mmul


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		N = len(nums)
		ansr = 0
		while any(nums):
			divideByTwo = False
			for i in range(N):
				if nums[i] == 1:
					ansr += 1
					nums[i] = 0
				elif nums[i] == 0:
					continue
				else:
					divideByTwo = True
					if nums[i] % 2 == 1:
						ansr += 1
					nums[i] = nums[i] // 2
			if divideByTwo:
				ansr += 1
		return ansr


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		ans = 0
		n = len(nums)
		while True:
			for i in range(n):
				if nums[i] % 2 == 1:
					ans += 1
					nums[i] -= 1
			stop = True
			for i in range(n):
				if nums[i] != 0:
					nums[i] //= 2
					stop = False
			if stop:
				break
			else:
				ans += 1
		return ans


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		max_divide = 0
		res = 0
		for num in nums:
			cnt_divide = 0
			while num:
				if num % 2 == 1:
					res += 1
					num -= 1
				else:
					num //= 2
					cnt_divide += 1
			max_divide = max(max_divide, cnt_divide)
		return res + max_divide


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		ans = 0
		nums.sort()
		while nums[-1] != 0:
			if nums[-1] >= 2:
				ans += 1
			for (i, num) in enumerate(nums):
				ans += num % 2
				nums[i] = num // 2
		return ans


import math

class Solution:

	def rec(self, nums):
		if not nums:
			return 0
		if len(nums) == 1:
			if nums[0] <= 2:
				return nums[0]
			if nums[0] % 2 == 0:
				nums[0] = nums[0] // 2
				return 1 + self.rec(nums)
			else:
				nums[0] = (nums[0] - 1) // 2
				return 2 + self.rec(nums)
		op = 0
		new = []
		for i in range(len(nums)):
			if nums[i] != 0:
				if nums[i] % 2 != 0:
					nums[i] -= 1
					op += 1
					if nums[i] != 0:
						new.append(nums[i] // 2)
				else:
					new.append(nums[i] // 2)
		if len(new) > 0:
			op += 1
		return op + self.rec(new)

	def minOperations(self, nums: List[int]) -> int:
		return self.rec(nums)


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		N = len(nums)
		res = 0
		while sum(nums) != 0:
			all_even = True
			for i in range(N):
				if nums[i] & 1:
					all_even = False
					res += 1
					nums[i] -= 1
			if all_even:
				res += 1
				nums = [n // 2 for n in nums]
		return res


def ones(x):
	return 0 if x == 0 else 1 + ones(x & x - 1)

def twos(x):
	cc = 0
	while x > 1:
		x //= 2
		cc += 1
	return cc

class Solution:

	def minOperations(self, nums: List[int]) -> int:
		o = 0
		t = 0
		for x in nums:
			o += ones(x)
			t = max(t, twos(x))
		return o + t


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		add_count = 0
		mut_count = 0

		def get_add_mut_count(n):
			add = mut = 0
			while n:
				if n % 2:
					n -= 1
					add += 1
				else:
					n /= 2
					mut += 1
			return (add, mut)
		for n in nums:
			(a, m) = get_add_mut_count(n)
			add_count += a
			mut_count = max(mut_count, m)
		return add_count + mut_count


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		count = 0
		while True:
			zeros = 0
			for i in range(len(nums)):
				if nums[i] % 2 == 0:
					continue
				else:
					nums[i] -= 1
					count += 1
			for j in range(len(nums)):
				if nums[j] == 0:
					zeros += 1
				nums[j] = nums[j] // 2
			if zeros == len(nums):
				return count
			count += 1


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		nums.sort()
		nums = nums[::-1]
		ops = 0
		n = len(nums)
		while nums:
			while nums[-1] == 0:
				nums.pop()
				if not nums:
					break
				n -= 1
			if not nums:
				break
			oc = 0
			for i in range(n):
				if nums[i] % 2 != 0:
					oc = 1
					break
			if oc == 1:
				for i in range(n):
					if nums[i] % 2 != 0:
						ops += 1
						nums[i] -= 1
			else:
				ops += 1
				for i in range(n):
					nums[i] = nums[i] // 2
		return ops


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		valid = {0: 0}
		for i in range(31):
			valid[2 ** i] = i
		ans = 0
		for i in range(len(nums)):
			if nums[i] > 0:
				ans += 1
		max_val = float('-inf')
		need_step = [0] * len(nums)
		max_multiply_step = 0
		for i in range(len(nums)):
			(one_step, multiply_step) = (0, 0)
			while nums[i] not in valid:
				if nums[i] & 1:
					one_step += 1
					nums[i] -= 1
				else:
					multiply_step += 1
					nums[i] //= 2
			max_multiply_step = max(max_multiply_step, multiply_step + valid[nums[i]])
			ans += one_step
		ans += max_multiply_step
		return ans


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		ans = 0
		if len(nums) == 1:
			v = nums[0]
			while v:
				if v % 2:
					ans += 1
					v -= 1
				if v:
					v //= 2
					ans += 1
			return ans
		c = collections.Counter()
		for (i, v) in enumerate(nums):
			if v % 2:
				nums[i] -= 1
				ans += 1
			c[nums[i]] += 1
		two = 0
		for v in sorted(c.keys()):
			temp = 0
			t = 0
			u = v
			while v:
				if v % 2:
					t += 1
					v -= 1
				if v:
					v //= 2
					temp += 1
			ans += t * c[u] + (temp - two)
			two += temp - two
		return ans


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		zeroIndexes = set()
		result = 0
		isEven = False
		while len(zeroIndexes) != len(nums):
			if isEven:
				for i in range(len(nums)):
					nums[i] >>= 1
				result += 1
				isEven = False
			else:
				for i in range(len(nums)):
					if i not in zeroIndexes:
						if nums[i] & 1:
							nums[i] -= 1
							result += 1
						if nums[i] == 0:
							zeroIndexes.add(i)
				isEven = True
		return result


import math

class Solution:

	def minOperations(self, nums: List[int]) -> int:
		res = 0
		while True:
			for i in range(len(nums)):
				if nums[i] % 2 == 1:
					res += 1
					nums[i] -= 1
			numZeros = 0
			for i in range(len(nums)):
				if nums[i] == 0:
					numZeros += 1
			if numZeros == len(nums):
				break
			for i in range(len(nums)):
				nums[i] //= 2
			res += 1
		return res


from collections import deque

class Solution:

	def minOperations(self, nums: List[int]) -> int:
		step = 0
		while sum(nums):
			for (i, val) in enumerate(nums):
				if val % 2:
					nums[i] -= 1
					step += 1
			if sum(nums):
				step += 1
				for (i, val) in enumerate(nums):
					if val:
						nums[i] /= 2
		return step


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		ans = 0
		while True:
			count = 0
			flag = 0
			for i in range(len(nums)):
				if nums[i] & 1:
					count += 1
					nums[i] -= 1
			for i in range(len(nums)):
				if nums[i] != 0:
					nums[i] = nums[i] // 2
					flag = 1
			ans += count
			if flag:
				ans += 1
			count = 0
			if nums.count(0) == len(nums):
				return ans


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		counter = 0
		while 1:
			temp_counter = 0
			bigger_than_zero = 0
			for i in range(len(nums)):
				if nums[i] % 2 == 1:
					temp_counter += 1
					nums[i] -= 1
				if nums[i] > 0:
					bigger_than_zero += 1
			counter += temp_counter
			if bigger_than_zero == 0:
				return counter
			for i in range(len(nums)):
				nums[i] //= 2
			counter += 1
		return counter


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		nums.sort(reverse=True)
		step = 0
		while any((n > 0 for n in nums)):
			if all((n % 2 == 0 for n in nums)):
				nums = [n // 2 for n in nums]
				step += 1
			else:
				remain_idx = []
				for (i, v) in enumerate(nums):
					if v % 2 == 1:
						nums[i] = nums[i] - 1
						step += 1
		return step


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		m = 0
		f = 0
		for x in nums:
			if x == 0:
				continue
			c = 0
			mm = 0
			baz = x
			while x > 1:
				if x % 2 == 0:
					x = x // 2
					mm += 1
				else:
					x -= 1
					c += 1
			print((baz, c))
			f += 1 + c
			m = max(m, mm)
			print(m)
		f += m
		return f


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		ret = 0
		while nums.count(0) != len(nums):
			for i in range(0, len(nums)):
				if nums[i] % 2 != 0:
					nums[i] = nums[i] - 1
					ret = ret + 1
			nums[:] = [i / 2 for i in nums]
			ret = ret + 1
		return 0 if ret == 0 else ret - 1


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		ans = 0
		while not all((n == 0 for n in nums)):
			div = 0
			for (i, n) in enumerate(nums):
				if n & 1:
					ans += 1
					n -= 1
				if n > 0:
					div = 1
					n //= 2
				nums[i] = n
			ans += div
		return ans


class Solution:

	def minOperations(self, nums: List[int]) -> int:

		def dfs(n):
			if sum(nums) == 0:
				return n
			subs = 0
			zeros = 0
			for i in range(len(nums)):
				if nums[i] % 2:
					nums[i] -= 1
					subs += 1
				if nums[i] == 0:
					zeros += 1
				nums[i] /= 2
			if zeros == len(nums):
				return subs + n
			return dfs(1 + subs + n)
		return dfs(0)


class Solution:

	def minOperations(self, nums: List[int]) -> int:

		def count(num):
			div = 0
			minus = 0
			while num:
				if num % 2 == 0:
					num = num // 2
					div += 1
				else:
					num = num - 1
					minus += 1
			return (div, minus)
		m = []
		d = []
		for i in nums:
			(div, minus) = count(i)
			d.append(div)
			m.append(minus)
		return max(d) + sum(m)


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		n = len(nums)
		ans = 0
		m = 0

		def get(val):
			ret = 0
			give = 0
			while val != 0:
				if val & 1:
					val -= 1
					ret += 1
				else:
					val = val // 2
					give += 1
			return (ret, give)
		for i in range(n):
			if nums[i] == 0:
				continue
			(val, mult) = get(nums[i])
			m = max(m, mult)
			ans += val
		ans += m
		return ans


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		if nums == [0]:
			return 0
		copy = list(nums)
		ans = 0
		while any([el != 0 for el in copy]):
			numOdd = 0
			for i in range(len(copy)):
				if copy[i] % 2 != 0:
					numOdd += 1
					copy[i] -= 1
			for i in range(len(copy)):
				copy[i] /= 2
			ans += numOdd + 1
		return ans - 1


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		n = m = 0
		for x in nums:
			s = bin(x)[2:]
			m = max(len(s) - 1, m)
			n += len(s.replace('0', ''))
		return m + n


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		res = max_mult = 0
		for num in nums:
			count = 0
			while num != 0:
				if num % 2:
					res += 1
					num -= 1
				else:
					count += 1
					num //= 2
			max_mult = max(max_mult, count)
		return res + max_mult


from collections import Counter, defaultdict, OrderedDict, deque
from bisect import bisect_left, bisect_right
from functools import reduce, lru_cache
from typing import List
import itertools
import math
import heapq
import string
true = True
false = False
(MIN, MAX, MOD) = (-1061109567, 1061109567, 1000000007)

class Solution:

	def minOperations(self, nums: List[int]) -> int:
		cnt = 0
		cc = Counter(nums)
		while True:
			dup = defaultdict(int)
			do_even = False
			for n in cc:
				if n == 0:
					continue
				if n % 2:
					cnt += cc[n]
					if n - 1 > 0:
						do_even = True
						dup[n // 2] += cc[n]
				else:
					do_even = True
					dup[n // 2] += cc[n]
			if do_even:
				cnt += 1
			if not dup:
				return cnt
			cc = dup
		return cnt
sol = Solution()
nums = [1, 5]
nums = [2, 2]
nums = [4, 2, 5]


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		res = 0
		nz = 0
		for num in nums:
			if num > 0:
				nz += 1
		while nz > 0:
			div2 = False
			for i in range(len(nums)):
				if nums[i] % 2 == 1:
					nums[i] -= 1
					res += 1
					if nums[i] == 0:
						nz -= 1
				if nums[i] > 0:
					div2 = True
					nums[i] //= 2
					if nums[i] == 0:
						nz -= 1
			if div2:
				res += 1
		return res


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		goal = [0] * len(nums)
		if nums == goal:
			return 0
		calls = 0
		div_needed = False
		for i in range(len(nums)):
			if nums[i] % 2 == 1:
				nums[i] -= 1
				calls += 1
			if nums[i] > 0:
				div_needed = True
		if div_needed:
			nums = [n / 2 for n in nums]
			calls += 1
		return calls + self.minOperations(nums)


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		ans = 0
		while sum(nums) != 0:
			count_odd = 0
			for (i, num) in enumerate(nums):
				if num % 2 != 0:
					count_odd += 1
					ans += 1
					nums[i] = nums[i] - 1
			if count_odd == 0:
				nums = [n // 2 for n in nums]
				ans += 1
		return ans


class Solution:

	def minOperations(self, a: List[int]) -> int:
		ans = 0
		while True:
			a.sort(reverse=True)
			for i in range(len(a)):
				if a[i] % 2:
					ans += 1
					a[i] -= 1
			for i in a:
				if i != 0:
					break
			else:
				break
			for i in range(len(a)):
				if a[i] % 2 == 0:
					a[i] //= 2
			ans += 1
		return ans


class Solution:

	def minOperations(self, A: List[int]) -> int:
		return sum((bin(a).count('1') for a in A)) + len(bin(max(A))) - 3


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		ops = 0
		done = False
		while not done:
			for i in range(len(nums)):
				if nums[i] % 2:
					nums[i] -= 1
					ops += 1
			done = True
			for i in range(len(nums)):
				if nums[i] != 0:
					done = False
					nums[i] /= 2
			if not done:
				ops += 1
		return ops


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		maxDoubles = 0
		incrs = 0
		for num in nums:
			doubles = 0
			while num > 0:
				if num % 2 == 1:
					incrs += 1
					num -= 1
				else:
					doubles += 1
					num >>= 1
			maxDoubles = max(maxDoubles, doubles)
		return incrs + maxDoubles


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		res = 0
		sum1 = 1
		while sum1 != 0:
			sum1 = 0
			for (ii, i) in enumerate(nums):
				if i % 2 != 0:
					nums[ii] -= 1
					res += 1
				nums[ii] = nums[ii] // 2
				sum1 += nums[ii]
			res += 1
		return res - 1


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		actions = 0
		n = len(nums)
		while True:
			odd_flag = False
			for i in range(n):
				if nums[i] % 2 == 1:
					actions += 1
					nums[i] -= 1
					odd_flag = True
			if all((num == 0 for num in nums)):
				break
			if odd_flag:
				continue
			for i in range(n):
				nums[i] //= 2
			actions += 1
			if all((num == 0 for num in nums)):
				break
		return actions


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		count = 0
		while True:
			next_nums = [0] * len(nums)
			all_zeros = True
			for (i, x) in enumerate(nums):
				if x == 0:
					continue
				if x % 2 != 0:
					count += 1
				next_num = x // 2
				next_nums[i] = next_num
				all_zeros &= next_num == 0
			if all_zeros:
				break
			count += 1
			nums = next_nums
		return count


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		L = lambda x: len(x)
		op = 0
		while sum(nums):
			isodd = False
			for i in range(L(nums)):
				if nums[i] & 1:
					nums[i] -= 1
					isodd = True
					op += 1
			if not isodd:
				for i in range(L(nums)):
					nums[i] >>= 1
				op += 1
		return op


class Solution:

	def minOperations(self, nums):
		ans = 0
		maxtimes = 0
		for num in nums:
			(plus, times) = (0, 0)
			while num != 0:
				plus = plus + num % 2
				if num // 2 != 0:
					times += 1
				num = num // 2
			maxtimes = max(maxtimes, times)
			ans = ans + plus
		ans += maxtimes
		return ans
x = Solution()
print(x.minOperations([1, 5]))


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		if max(nums) == 0:
			return 0
		operations = 0
		for i in range(len(nums)):
			if nums[i] % 2 == 1:
				nums[i] = nums[i] - 1
				operations += 1
		if operations > 0:
			return operations + self.minOperations(nums)
		for i in range(len(nums)):
			nums[i] = nums[i] // 2
		operations += 1
		return operations + self.minOperations(nums)


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		max_ = max(nums)
		multiplication = len(bin(max_)[2:]) - 1
		additions = 0
		for n in nums:
			additions += bin(n)[2:].count('1')
		return additions + multiplication


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		c = 0
		while True:
			sol = True
			for i in range(len(nums)):
				if nums[i] % 2 != 0:
					nums[i] -= 1
					c += 1
				if nums[i] != 0:
					sol = False
			if sol:
				break
			c += 1
			nums = [x // 2 for x in nums]
		return c


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		ans = 0
		while any([True if num > 0 else False for num in nums]):
			for (idx, num) in enumerate(nums):
				if num % 2 == 1:
					ans += 1
					nums[idx] -= 1
			flag = 0
			for (idx, num) in enumerate(nums):
				if num != 0:
					flag = True
					nums[idx] = num // 2
			if flag:
				ans += 1
		return ans


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		N = len(nums)
		c = 0
		while any(nums):
			for i in range(N):
				if nums[i] & 1:
					nums[i] -= 1
					c += 1
			m = max(nums)
			for i in range(N):
				nums[i] >>= 1
			c += 1
		return c - 1


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		mul = [0 for i in range(len(nums))]
		inc = [0 for i in range(len(nums))]
		for i in range(len(nums)):
			while nums[i] != 0:
				if nums[i] % 2 == 1:
					inc[i] += 1
					nums[i] = nums[i] - 1
				else:
					mul[i] += 1
					nums[i] //= 2
		return max(mul) + sum(inc)


class Solution:

	def minOperations(self, nums: List[int]) -> int:

		def get_op(n):
			op_0 = 0
			op_1 = 0
			while n != 0:
				if n % 2 == 0:
					op_1 += 1
					n = n // 2
				else:
					op_0 += 1
					n -= 1
			return (op_0, op_1)
		ans = 0
		op_1 = 0
		for n in nums:
			(tmp_0, tmp_1) = get_op(n)
			ans += tmp_0
			op_1 = max(op_1, tmp_1)
		return ans + op_1


from functools import lru_cache

class Solution:

	def minOperations(self, nums) -> int:

		@lru_cache(None)
		def minOpt(num):
			if num == 0:
				return (0, 0)
			if num % 2 == 1:
				(m, a) = minOpt(num - 1)
				return (m, a + 1)
			else:
				(m, a) = minOpt(num // 2)
				return (m + 1, a)
		(multiply, add) = (0, 0)
		for num in nums:
			(m, a) = minOpt(num)
			multiply = max(m, multiply)
			add += a
		return multiply + add


import math

class Solution:

	def minOperations(self, nums: List[int]) -> int:
		t = 0
		h = nums[0]
		for n in nums:
			if n > h:
				h = n
			while n:
				n &= n - 1
				t += 1
		if h > 0:
			return t + math.floor(math.log(h, 2))
		return t


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		ones = 0
		two = 0
		for i in nums:
			mul = 0
			while i:
				if i % 2 == 1:
					i = i - 1
					ones += 1
				else:
					i = i // 2
					mul += 1
			two = max(two, mul)
		return ones + two


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		(inc, mult) = (0, 0)
		for i in nums:
			if i:
				(a, b) = self.getRes(i)
				inc += a
				mult = max(mult, b)
		return inc + mult

	def getRes(self, n):
		(inc, mult) = (0, 0)
		while n:
			if n % 2 == 1:
				n -= 1
				inc += 1
			else:
				n //= 2
				mult += 1
		return (inc, mult)


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		op = 0
		while len(nums) > 0:
			for i in range(len(nums)):
				if nums[i] % 2 == 1:
					nums[i] -= 1
					op += 1
			nums = list(filter(lambda x: x != 0, nums))
			if len(nums) > 0:
				nums[:] = [int(x / 2) for x in nums]
				op += 1
		return op


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		o = 0
		m = 0
		a = 0
		for i in nums:
			m = 0
			while i:
				if i % 2 == 0:
					m += 1
					i //= 2
				else:
					o += 1
					i -= 1
			a = max(m, a)
		return o + a


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		lst = list(map(find_op, nums))
		mul = max(lst, key=lambda x: x[0])
		mul = mul[0]
		add = sum([item[1] for item in lst])
		return add + mul

def find_op(n):
	(mul, add) = (0, 0)
	while n > 0:
		if n % 2 == 1:
			add += 1
		n //= 2
		mul += 1
	if mul > 0:
		mul -= 1
	return (mul, add)


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		count_zeros = 0
		for i in nums:
			if i == 0:
				count_zeros += 1
		operations = 0
		while count_zeros != len(nums):
			odd_max = -1
			for i in range(0, len(nums)):
				if nums[i] % 2 == 1:
					operations += 1
					nums[i] -= 1
					odd_max = i
					if nums[i] == 0:
						count_zeros += 1
			if odd_max == -1:
				operations += 1
				for i in range(0, len(nums)):
					nums[i] = nums[i] // 2
		return operations


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		return sum((bin(a).count('1') for a in nums)) + len(bin(max(nums))[2:]) - 1


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		res = 0
		for i in range(len(nums)):
			if nums[i] % 2:
				nums[i] -= 1
				res += 1
		if any(nums):
			nums = [i // 2 for i in nums]
			return res + 1 + self.minOperations(nums)
		else:
			return res


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		arr = nums[:]
		res = 0
		while any(arr):
			odd = sum([x % 2 == 1 for x in arr])
			if odd:
				arr = [x - x % 2 for x in arr]
				res += odd
			else:
				arr = [x // 2 for x in arr]
				res += 1
		return res


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		res = 0
		while any(nums):
			ones = sum((num & 1 for num in nums))
			res += ones
			nums = [num >> 1 for num in nums]
			res += 1
		return res - 1


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		op = 0
		a = [0] * len(nums)
		while nums != a:
			for i in range(len(nums)):
				if nums[i] % 2 == 0:
					nums[i] = nums[i] // 2
				else:
					op += 1
					nums[i] -= 1
					nums[i] = nums[i] // 2
			op += 1
		return op - 1


class Solution:

	def minOperations(self, nums):
		ret = []
		overall = 0
		for i in nums:
			temp = 0
			if i == 0:
				overall -= 1
			if i % 2 == 1 and i != 1:
				overall += 1
				i -= 1
			while i > 1:
				if i % 2 == 1:
					overall += 1
					i -= 1
				else:
					temp += 1
					i /= 2
			ret.append(temp)
		return overall + max(ret) + len(ret)


class Solution:

	def getOdd(self, nums):
		for (i, n) in enumerate(nums):
			if n % 2 == 1:
				return i
		return None

	def minOperations(self, nums: List[int]) -> int:
		res = 0
		while nums.count(0) != len(nums):
			odd = self.getOdd(nums)
			if odd is None:
				for i in range(len(nums)):
					nums[i] = nums[i] // 2
				res += 1
			else:
				for i in range(len(nums)):
					if nums[i] % 2 == 1:
						nums[i] = nums[i] - 1
						res += 1
		return res


class Solution:

	def minOperations(self, nums) -> int:
		a = list(sorted(nums))
		moves = 0
		while True:
			for i in range(len(a)):
				if a[i] % 2 == 1:
					moves += 1
					a[i] -= 1
			remaining = 0
			for i in range(len(a)):
				if a[i] > 0:
					remaining += 1
			if remaining == 0:
				break
			moves += 1
			for i in range(len(a)):
				a[i] = a[i] // 2
		return moves


class Solution:

	def minOperations(self, A):
		(steps, n) = (0, len(A))
		while True:
			zeros = 0
			for i in range(n):
				if A[i] % 2 > 0:
					A[i] -= 1
					steps += 1
				if A[i] == 0:
					zeros += 1
			if zeros == n:
				break
			for i in range(n):
				A[i] >>= 1
			steps += 1
		return steps


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		(zeros, ops) = (0, 0)
		while zeros != len(nums):
			(odds, evens, zeros) = (0, 0, 0)
			for i in range(0, len(nums)):
				if nums[i] % 2 == 1:
					nums[i] -= 1
					odds += 1
				if nums[i] == 0:
					zeros += 1
				else:
					evens += 1
					nums[i] //= 2
			ops += odds
			ops += 1 if evens else 0
		return ops


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		op1 = op2 = 0
		for num in nums:
			count1 = count2 = 0
			while num:
				if num & 1:
					count1 += num & 1
					num -= 1
				if num:
					count2 += 1
				num >>= 1
			op1 += count1
			op2 = max(op2, count2)
		return op1 + op2


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		(res, val) = (0, sum(nums))
		while val:
			val0 = val
			for (i, x) in enumerate(nums):
				if x % 2:
					nums[i] -= 1
					val -= 1
			res += val0 - val
			if val == val0:
				for i in range(len(nums)):
					nums[i] //= 2
				val //= 2
				res += 1
		return res


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		minops = 0
		while sum(nums) > 0:
			for (i, num) in enumerate(nums):
				if num & 1:
					nums[i] -= 1
					minops += 1
			nums = [num >> 1 for num in nums]
			minops += 1
		return minops - 1


import math

class Solution:

	def minOperations(self, nums: List[int]) -> int:
		maxn = 0
		res = 0
		for i in range(len(nums)):
			if nums[i] > 0:
				if nums[i] > 0:
					count = 0
					n = nums[i]
					while n > 0:
						if n % 2 > 0:
							res += 1
							n = n - 1
						else:
							count += 1
							n = n // 2
					if count > maxn:
						maxn = count
		return res + maxn


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		odds: List[int] = [n for n in nums if n % 2 == 1]
		evens: Set[int] = [n for n in nums if n != 0 and n % 2 == 0]
		new: List[int] = []
		n: int = 0
		n_ops: int = 0
		while len(odds) > 0 or len(evens) > 0:
			if len(odds) > 0:
				n = odds.pop() - 1
				if n > 0:
					evens.append(n)
			else:
				new = [n // 2 for n in evens]
				odds = [n for n in new if n % 2 == 1]
				evens = [n for n in new if n % 2 == 0]
			n_ops += 1
		return n_ops


class Solution:

	def minOperations(self, nums: List[int]) -> int:

		def minSteps(num):
			if num == 1:
				return 1
			if num in memo:
				return memo[num]
			memo[num] = minSteps(num // 2) if num % 2 == 0 else 1 + minSteps(num - 1)
			return memo[num]

		def countPowerOfTwo(num):
			if num < 2:
				return 0
			(cnt, cur) = (1, 2)
			while cur * 2 <= num:
				cnt += 1
				cur <<= 1
			return cnt
		memo = {}
		res = countPowerOfTwo(max(nums))
		for num in nums:
			if num == 0:
				continue
			res += minSteps(num)
		return res


import math

class Solution:

	def minOperations(self, nums: List[int]) -> int:
		p = []
		ans = 0
		for i in nums:
			r = 0
			while i > 0:
				if i % 2 == 0:
					r += 1
					i /= 2
				else:
					ans += 1
					i -= 1
			p.append(r)
		ans += max(p)
		return ans


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		ans = 0
		max_count = 0
		for num in nums:
			cnt = 0
			while num > 0:
				if num % 2 != 0:
					num -= 1
					ans += 1
				else:
					num /= 2
					cnt += 1
			max_count = max(max_count, cnt)
		return ans + max_count


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		ans = 0
		big = 0
		for i in range(len(nums)):
			k = nums[i]
			k = bin(k)
			ans += k.count('1')
			big = max(big, 0, len(k) - 3)
		ans += big
		return ans


class Solution:

	def minOperations(self, nums: List[int]) -> int:

		def get_counts(x):
			if x == 0:
				return (0, 0)
			elif x % 2 == 0:
				(add_count, mul_count) = get_counts(x // 2)
				return (add_count, mul_count + 1)
			else:
				(add_count, mul_count) = get_counts(x - 1)
				return (add_count + 1, mul_count)
		(add_count, mul_count) = (0, 0)
		for num in nums:
			(ac, mc) = get_counts(num)
			add_count += ac
			mul_count = max(mc, mul_count)
		return add_count + mul_count


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		op = 0
		while True:
			doDivision = 0
			NoZero = 1
			for i in range(len(nums)):
				if nums[i] != 0:
					NoZero = 0
				if nums[i] % 2 == 1:
					nums[i] -= 1
					op += 1
				if nums[i] != 1 and nums[i] != 0:
					doDivision = 1
					nums[i] //= 2
			if doDivision == 1:
				op += 1
			if NoZero == 1:
				return op


from typing import Tuple

class Solution:

	def ones_twos(self, n: int, ones: int, twos: int) -> Tuple[int, int]:
		if n == 0:
			return (ones, twos)
		if n == 1:
			return (ones + 1, twos)
		if n % 2 == 0:
			return self.ones_twos(n // 2, ones, twos + 1)
		else:
			return self.ones_twos(n - 1, ones + 1, twos)

	def minOperations(self, nums: List[int]) -> int:
		(ones, twos) = (0, 0)
		for num in nums:
			(o, t) = self.ones_twos(num, 0, 0)
			ones += o
			twos = max(twos, t)
		return ones + twos


class Solution1:

	def minOperations(self, nums: List[int]) -> int:
		twos = 0
		ones = 0
		for n in nums:
			mul = 0
			while n:
				if n % 2:
					n -= 1
					ones += 1
				else:
					n //= 2
					mul += 1
			twos = max(twos, mul)
		return ones + twos

class Solution:

	def minOperations(self, nums: List[int]) -> int:
		maxval = max(nums)
		idx = nums.index(maxval)
		ans = 0
		while nums[idx] != 0:
			for (i, n) in enumerate(nums):
				ans += n % 2
				nums[i] = n - n % 2
			if nums[idx] != 0:
				for (i, n) in enumerate(nums):
					nums[i] = nums[i] // 2
				ans += 1
		return ans


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		res = 0
		a = [x for x in nums if x]
		while a:
			for (i, x) in enumerate(a):
				if x & 1:
					a[i] -= 1
					res += 1
			a = [x // 2 for x in a if x]
			if a:
				res += 1
		return res


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		lru_cache(maxsize=None)

		def check(n):
			if n == 0:
				return (0, 0)
			elif n == 1:
				return (1, 0)
			else:
				r1 = 0
				r2 = 0
				(k, l) = divmod(n, 2)
				(r1, r2) = check(k)
				r1 += l
				r2 += 1
			return (r1, r2)
		r1 = 0
		r2 = 0
		for n in nums:
			(c1, c2) = check(n)
			r1 += c1
			r2 = max(r2, c2)
		return r1 + r2


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		zeros = []
		operations = 0
		for item in nums:
			zeros.append(0)
		while nums != zeros:
			for (index, item) in enumerate(nums):
				if item % 2 == 1:
					nums[index] = item - 1
					operations += 1
			if nums == zeros:
				break
			for (index, item) in enumerate(nums):
				if item % 2 == 0:
					nums[index] = item / 2
			operations += 1
		return operations


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		ans = 0
		count = collections.Counter()
		for n in nums:
			if n != 0:
				count[n] += 1
		while len(count) > 0:
			newcount = collections.Counter()
			for (k, v) in count.items():
				if k % 2 == 0:
					newcount[k // 2] += v
				elif k > 1:
					newcount[(k - 1) // 2] += v
					ans += v
				else:
					ans += v
			ans += 1
			count = newcount
		return ans - 1


class Solution:

	def minOperations(self, nums: List[int]) -> int:

		def _op(arr):
			(odds, zeros) = (0, 0)
			for i in range(len(arr)):
				if arr[i] == 0:
					zeros += 1
				elif arr[i] % 2 == 1:
					arr[i] -= 1
					odds += 1
			if zeros == len(arr):
				return 0
			if odds != 0:
				return odds
			for i in range(len(arr)):
				arr[i] //= 2
			return 1
		ans = 0
		ops = _op(nums)
		while ops != 0:
			ans += ops
			ops = _op(nums)
		return ans


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		ops = 0
		if not any((n != 0 for n in nums)):
			return 0
		while nums:
			if any((n % 2 != 0 for n in nums)):
				for (idx, n) in enumerate(nums):
					if nums[idx] % 2 != 0:
						nums[idx] -= 1
						ops += 1
				nums = [n for n in nums if n != 0]
			else:
				ops += 1
				nums = [int(n / 2) for n in nums]
		return ops


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		steps = 0
		nums = sorted(nums)
		j = -1
		while j < len(nums) - 1:
			s = j + 1
			while s < len(nums):
				if nums[s] == 0:
					j += 1
				elif nums[s] == 1:
					steps += 1
					j += 1
					nums[s] = 0
				elif nums[s] % 2 == 1:
					steps += 1
					nums[s] -= 1
					nums[s] //= 2
				else:
					nums[s] //= 2
				s += 1
			steps += 1
		return steps - 1


class Solution:

	def minOperations(self, nums: List[int]) -> int:

		def do(n):
			(a, b) = (0, 0)
			while n != 0:
				if n % 2 == 1:
					a += 1
					n -= 1
				else:
					b += 1
					n //= 2
			return [a, b]
		(aa, bb) = (0, 0)
		for n in nums:
			(a, b) = do(n)
			aa += a
			bb = max(b, bb)
		return aa + bb


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		d = max(nums)
		if d == 0:
			return 0
		res = 0
		while d >= 2:
			res += 1
			d >>= 1
		for num in nums:
			while num:
				res += 1
				num &= num - 1
		return res


import math

class Solution:

	def minOperations(self, nums: List[int]) -> int:
		n = len(nums)
		power = [0] * n
		rem = [0] * n
		for i in range(n):
			j = nums[i]
			count1 = 0
			count2 = 0
			while j > 0:
				if j % 2 == 0:
					count1 += 1
					j = j // 2
				else:
					count2 += 1
					j = j - 1
			(power[i], rem[i]) = (count1, count2)
		ans = max(power) + sum(rem)
		return ans


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		arr = [0] * len(nums)
		if arr == nums:
			return 0
		ops = 0
		while arr != nums:
			for i in range(len(nums)):
				if nums[i] % 2 == 1:
					nums[i] -= 1
					ops += 1
			ops += 1
			nums = [x / 2 for x in nums]
		return ops - 1


class Solution:

	def minOperations(self, nums: List[int]) -> int:

		def odd_2_even(nums):
			step = 0
			new_nums = []
			for i in range(len(nums)):
				if nums[i] % 2 == 1:
					step += 1
					nums[i] -= 1
					if nums[i] > 0:
						new_nums.append(nums[i])
				elif nums[i] > 0:
					new_nums.append(nums[i])
			return (step, new_nums)

		def even_2(nums):
			return [a // 2 for a in nums]
		step = 0
		while len(nums) > 0:
			(add, nums) = odd_2_even(nums)
			if len(nums) > 0:
				nums = even_2(nums)
				step += 1
			step = step + add
		return step


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		cost = 0
		d = 0
		for a in nums:
			(division, increments) = self.trick(a)
			d = max(division, d)
			cost += increments
		return d + cost

	def trick(self, mx):
		if mx in {0, 1}:
			return (0, 0) if mx == 0 else (0, 1)
		if mx % 2 == 0:
			(d, i) = self.trick(mx // 2)
			return (d + 1, i)
		else:
			(d, i) = self.trick(mx - 1)
			return (d, i + 1)


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		result = 0
		result_num_div = 0
		for i in range(len(nums)):
			num_div = 0
			while nums[i] > 0:
				if nums[i] % 2 == 1:
					result += 1
					nums[i] -= 1
				if nums[i] > 1:
					num_div += 1
				nums[i] /= 2
			result_num_div = max(result_num_div, num_div)
		return result + result_num_div


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		res = 0
		n = len(nums)
		while True:
			i = 0
			zc = 0
			while i < n:
				if nums[i] & 1 > 0:
					break
				elif nums[i] == 0:
					zc += 1
				i += 1
			if zc == n:
				return res
			if i == n:
				for j in range(n):
					nums[j] = nums[j] // 2
				res += 1
			for j in range(i, n):
				if nums[j] & 1:
					nums[j] -= 1
					res += 1


class Solution:

	def minOperations(self, nums: List[int]) -> int:

		def count_ops(x: int) -> int:
			if x == 0:
				return (0, 0)
			elif x == 1:
				return (1, 0)
			elif x % 2 == 0:
				(add, mul) = count_ops(x // 2)
				return (add, mul + 1)
			else:
				(add, mul) = count_ops(x - 1)
				return (add + 1, mul)
		count = maxmul = 0
		for i in nums:
			(add, mul) = count_ops(i)
			maxmul = max(maxmul, mul)
			count += add
		return count + maxmul


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		ans = 0
		cnt = len(nums)
		for n in nums:
			if n == 0:
				cnt -= 1
		while cnt > 0:
			for (i, n) in enumerate(nums):
				if n != 0 and n % 2 == 1:
					nums[i] -= 1
					ans += 1
					if nums[i] == 0:
						cnt -= 1
			two = 0
			for (i, n) in enumerate(nums):
				if n != 0 and n % 2 == 0:
					two = 1
					nums[i] //= 2
			ans += two
		return ans


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		arr = [0] * len(nums)
		count = 0
		while nums != arr:
			check = True
			for x in nums:
				if x % 2 != 0:
					check = False
			if check == True:
				count += 1
				for x in range(len(nums)):
					nums[x] = nums[x] // 2
			for x in range(len(nums)):
				if nums[x] % 2 != 0:
					nums[x] = nums[x] - 1
					count += 1
		return count


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		out = 0
		while sum(nums) != 0:
			for i in range(len(nums)):
				if nums[i] % 2 == 1:
					nums[i] -= 1
					out += 1
			if sum(nums) == 0:
				break
			for i in range(len(nums)):
				nums[i] /= 2
			out += 1
		return out


from copy import deepcopy

class Solution:

	def minOperations(self, nums: List[int]) -> int:

		def modify(arr, op, idx):
			if op == 0:
				arr[idx] = arr[idx] - 1
			elif op == 1:
				for (i, num) in enumerate(arr):
					arr[i] = num // 2
		zeros = [0] * len(nums)
		ans = 0
		while True:
			for (i, num) in enumerate(nums):
				if num % 2 == 1:
					nums[i] = num - 1
					ans += 1
			if nums == zeros:
				return ans
			else:
				modify(nums, 1, 0)
				ans += 1
		return ans


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		ops = 0
		N = len(nums)
		while True:
			n = 0
			alleven = True
			for (i, num) in enumerate(nums):
				if num == 0:
					n += 1
				elif num % 2:
					nums[i] -= 1
					if num == 0:
						n += 1
					alleven = False
					ops += 1
			if n == N:
				break
			if alleven:
				for i in range(N):
					if nums[i]:
						nums[i] = nums[i] // 2
				ops += 1
		return ops


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		result = 0
		while True:
			to_continue = False
			ops = 0
			for i in range(len(nums)):
				if nums[i] == 0:
					continue
				elif nums[i] % 2 == 1:
					nums[i] -= 1
					ops += 1
					to_continue = True
				else:
					to_continue = True
			if ops > 0:
				result += ops
			elif to_continue:
				result += 1
				for i in range(len(nums)):
					nums[i] //= 2
			else:
				break
		return result


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		val = max(nums)
		double = 0
		add = 0
		value = 0
		count = 0
		value = val
		while value != 0:
			if value % 2 == 0:
				value = value // 2
				double += 1
			else:
				value -= 1
				add += 1
		count += double
		print(add, double)
		for x in nums:
			value = x
			half = 0
			add = 0
			while value != 0:
				if value % 2 == 0:
					value = value // 2
					half += 1
				else:
					value -= 1
					add += 1
			count += add
		return count


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		count = 0
		nums = [num for num in nums if num]
		if not nums:
			return 0
		while nums:
			flag = False
			new_nums = []
			for num in nums:
				if num % 2:
					flag = True
					break
			if flag:
				for num in nums:
					if num % 2:
						num = num - 1
						count += 1
					if num:
						new_nums.append(num)
			else:
				for num in nums:
					new_nums.append(num / 2)
				count += 1
			nums = new_nums
		return count


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		operations = 0
		while not all((n == 0 for n in nums)):
			if all((n % 2 == 0 for n in nums)):
				nums = [n / 2 for n in nums]
				operations += 1
			else:
				for (i, num) in enumerate(nums):
					if num % 2 != 0:
						nums[i] = num - 1
						operations += 1
		return operations


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		ans_count = 0
		while True:
			zero_count = 0
			have_odd = False
			for idx in range(len(nums)):
				if nums[idx] % 2 != 0:
					have_odd = True
					ans_count += 1
					nums[idx] -= 1
				if nums[idx] == 0:
					zero_count += 1
			if zero_count == len(nums):
				break
			if not have_odd:
				ans_count += 1
				for idx in range(len(nums)):
					nums[idx] //= 2
		return ans_count


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		sol = nums
		cost = 0
		while sum(sol) > 0:
			for i in range(len(sol)):
				if sol[i] & 1 != 0:
					sol[i] -= 1
					cost += 1
			if len(sol) > 0:
				sol = [x // 2 for x in sol if x > 0]
				if len(sol) > 0:
					cost += 1
		return cost


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		delete_count = 0
		divide_count = 0
		for e in nums:
			divide = 0
			while e != 0:
				if e % 2:
					e -= 1
					delete_count += 1
				else:
					e /= 2
					divide += 1
			divide_count = max(divide_count, divide)
		return delete_count + divide_count


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		n_op = 0
		l = len(nums)
		target = l * [0]
		while nums != target:
			if all((i % 2 == 0 for i in nums)):
				nums = [i / 2 for i in nums]
				n_op += 1
			else:
				for i in range(l):
					if nums[i] % 2 == 1:
						nums[i] -= 1
						n_op += 1
		return n_op


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		ans = 0
		ma = 0
		for n in nums:
			k = 0
			while n != 0:
				if n % 2 == 0:
					k += 1
					n = n // 2
				else:
					n -= 1
					ans += 1
				ma = max(ma, k)
		return ans + ma


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		ops = 0
		while not all((n == 0 for n in nums)):
			for (i, n) in enumerate(nums):
				if n % 2 != 0:
					nums[i] = n - 1
					ops += 1
			if all((n == 0 for n in nums)):
				break
			nums = [n // 2 for n in nums]
			ops += 1
		return ops


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		divied2 = 0
		res = 0
		for i in nums:
			temp = 0
			while i > 0:
				if i % 2 == 0:
					i //= 2
					temp += 1
				else:
					i -= 1
					res += 1
				divied2 = max(divied2, temp)
		return res + divied2


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		count = 0
		double = 0
		for i in range(len(nums)):
			cd = 0
			while nums[i] > 0:
				if nums[i] % 2 == 1:
					count += 1
				cd += 1
				nums[i] //= 2
			double = max(double, cd)
		return count + double - 1


masks = [1431655765, 858993459, 252645135, 16711935, 65535]

class Solution:

	def minOperations(self, nums: List[int]) -> int:
		totOddRem = 0
		maxX = nums[0]
		for x in nums:
			if x == 1:
				totOddRem += 1
			else:
				xCopy = x
				for (p, m) in enumerate(masks):
					xCopy = (xCopy & m) + ((xCopy & ~m) >> (1 << p))
				totOddRem += xCopy
			if x > maxX:
				maxX = x
		leftMost = 0
		step = 16
		for m in reversed(masks):
			m = ~m
			if m & maxX != 0:
				leftMost += step
				maxX &= m
			step >>= 1
		return totOddRem + leftMost


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		count = 0
		onesCount = 0
		aboveOneIdxs = []
		for (idx, n) in enumerate(nums):
			if n == 1:
				onesCount += 1
			elif n > 1:
				aboveOneIdxs.append(idx)
		while onesCount + len(aboveOneIdxs) != 0:
			count += onesCount
			onesCount = 0
			newAboveOneIdxs = []
			for idx in aboveOneIdxs:
				if nums[idx] % 2 != 0:
					nums[idx] -= 1
					count += 1
				nums[idx] //= 2
				if nums[idx] == 1:
					onesCount += 1
				else:
					newAboveOneIdxs.append(idx)
			if len(aboveOneIdxs) > 0:
				count += 1
			aboveOneIdxs = newAboveOneIdxs
		return count


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		n = len(nums)
		noz = 0
		nosteps = 0
		while noz != n:
			noz = 0
			noe = 0
			noo = 0
			for i in range(len(nums)):
				if nums[i] == 0:
					noz += 1
					noe += 1
				elif nums[i] % 2 == 0:
					noe += 1
					nums[i] = nums[i] // 2
				else:
					noo += 1
					nums[i] -= 1
					nums[i] = nums[i] // 2
			nosteps += noo
			if noz == n:
				break
			nosteps += 1
		return nosteps - 1


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		num_operations = 0
		odd = True
		even = False
		while odd or even:
			if odd:
				for i in range(len(nums)):
					if nums[i] != 0:
						if nums[i] % 2:
							nums[i] -= 1
							num_operations += 1
						if nums[i]:
							even = True
				odd = False
			if even:
				num_operations += 1
				for i in range(len(nums)):
					nums[i] /= 2
					if nums[i] % 2:
						even = False
						odd = True
		return num_operations


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		n = len(nums)

		def modify(arr, op, ind):
			if op == 0:
				arr[ind] = arr[ind] + 1
			if op == 1:
				for i in range(len(arr)):
					arr[i] = arr[i] * 2
			return arr
		arr = [0] * n
		ops_needed = 0
		check_ind = 0
		nums.sort(key=lambda x: -x)
		while any((n != 0 for n in nums)):
			for (ind, numb) in enumerate(nums):
				if numb >= 1 and numb % 2 == 1:
					ops_needed += 1
					nums[ind] = nums[ind] - 1
			for numb in nums:
				if numb >= 1 and numb % 2 == 0:
					ops_needed += 1
					for (ind, elt) in enumerate(nums):
						nums[ind] = nums[ind] / 2
					break
			check_ind += 1
			if check_ind > 100:
				break
		return ops_needed


class Solution:

	def makeHalf(self, a):
		for i in range(len(a)):
			a[i] //= 2

	def makeEven(self, a):
		c = 0
		for i in range(len(a)):
			if a[i] % 2 == 0:
				continue
			else:
				a[i] -= 1
				c += 1
		return c

	def minOperations(self, nums: List[int]) -> int:
		op = 0
		while sum(nums) != 0:
			op += self.makeEven(nums)
			if sum(nums) == 0:
				return op
			self.makeHalf(nums)
			op += 1
		return op


import math

class Solution:

	def minOperations(self, nums: List[int]) -> int:
		res = 0
		while sum(nums) != 0:
			counts = sum([x % 2 == 0 for x in nums])
			if counts == len(nums):
				for i in range(len(nums)):
					nums[i] = nums[i] // 2
				res += 1
			else:
				for i in range(len(nums)):
					if nums[i] % 2 != 0:
						nums[i] -= 1
						res += 1
		return res


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		print(0 % 2)
		step = 0
		while any((n > 0 for n in nums)):
			if all((n % 2 == 0 for n in nums)):
				nums = [n // 2 for n in nums]
				step += 1
			else:
				remain_idx = []
				for (i, v) in enumerate(nums):
					if v % 2 == 1:
						nums[i] = nums[i] - 1
						if nums[i] == 0:
							del nums[i]
						step += 1
		return step


class Solution:

	def minOperations(self, A: List[int]) -> int:

		def even(A):
			for i in range(len(A)):
				A[i] //= 2
			return A

		def odd(A):
			c = 0
			z = 0
			for i in range(len(A)):
				if A[i] % 2 == 1:
					A[i] -= 1
					c += 1
					if A[i] == 0:
						z += 1
			return (A, c, z)
		res = 0
		zero = 0
		for i in A:
			if i == 0:
				zero += 1
		while zero < len(A):
			(A, c, z) = odd(A)
			zero += z
			res += c
			if zero < len(A):
				A = even(A)
				res += 1
		return res


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		count = 0
		res = {}
		for i in range(len(nums)):
			if nums[i] != 0:
				res[i] = nums[i]
		zeros = []
		while res:
			zeros.clear()
			for key in res:
				if res[key] % 2 != 0:
					res[key] -= 1
					count += 1
					minus = True
				if res[key] == 0:
					zeros.append(key)
			for zero in zeros:
				res.pop(zero)
			if res:
				for key in res:
					res[key] //= 2
				count += 1
		return count


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		ans = 0
		while any(nums):
			temp = [0] * len(nums)
			flag = False
			for i in range(len(nums)):
				if nums[i] % 2:
					nums[i] -= 1
					flag = True
					ans += 1
				elif not flag and (not nums[i] % 2):
					temp[i] = nums[i] // 2
			if not flag:
				ans += 1
				nums = temp
		return ans


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		nums.sort(reverse=True)
		s = sum(nums)
		res = 0
		while s:
			for i in range(len(nums)):
				if nums[i] % 2:
					nums[i] -= 1
					res += 1
			s = 0
			nums = list([x for x in nums if x > 0])
			if not nums:
				break
			for i in range(len(nums)):
				nums[i] //= 2
				s += nums[i]
			res += 1
		return res


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		nops = 0
		all_z = False
		while not all_z:
			all_z = True
			op2_mark = False
			for (idx, val) in enumerate(nums):
				if val != 0:
					all_z = False
				else:
					continue
				if val % 2 == 0:
					if not op2_mark:
						nops += 1
						op2_mark = True
					nums[idx] /= 2
				else:
					nops += 1
					if nums[idx] - 1 > 0:
						if not op2_mark:
							nops += 1
							op2_mark = True
					nums[idx] = (nums[idx] - 1) / 2
		return nops


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		ans = 0
		seen_nonzero = True
		while True:
			all_zeros = True
			for i in range(len(nums)):
				if nums[i] % 2 == 1:
					nums[i] -= 1
					ans += 1
				if nums[i] > 0:
					all_zeros = False
			if all_zeros:
				break
			for i in range(len(nums)):
				nums[i] = nums[i] // 2
			ans += 1
		return ans


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		result = 0
		while True:
			for (i, x) in enumerate(nums):
				if x & 1:
					result += 1
					nums[i] -= 1
			if all((x == 0 for x in nums)):
				return result
			for (i, x) in enumerate(nums):
				nums[i] //= 2
			result += 1


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		ans = 0
		while sum(nums) != 0:
			tmp = nums.copy()
			ones_tmp = nums.copy()
			cnt = 0
			ones_cnt = 0
			flag = False
			for (i, a) in enumerate(nums):
				if a == 1:
					ones_cnt += 1
					ones_tmp[i] = 0
					flag = True
				tmp[i] = nums[i] // 2
				cnt += nums[i] % 2
			if flag:
				ans += ones_cnt
				nums = ones_tmp[:]
			else:
				ans += cnt + 1
				nums = tmp[:]
		return ans


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		res = 0
		while nums != [0] * len(nums):
			for i in range(len(nums)):
				if nums[i] == 1:
					nums[i] -= 1
					res += 1
				elif nums[i] % 2 == 1:
					nums[i] -= 1
					res += 1
			if nums == [0] * len(nums):
				break
			for i in range(len(nums)):
				nums[i] //= 2
			res += 1
		return res


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		ret = 0
		for (i, x) in enumerate(nums):
			if x % 2:
				ret += 1
				nums[i] -= 1
		if all((x == 0 for x in nums)):
			return ret
		for (i, x) in enumerate(nums):
			nums[i] //= 2
		ret += 1
		return ret + self.minOperations(nums)


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		count = 0
		while 1:
			for (i, vi) in enumerate(nums):
				if vi & 1:
					count += 1
					nums[i] = vi - 1
			chk = True
			for (i, vi) in enumerate(nums):
				if vi > 0:
					chk = False
				nums[i] = vi // 2
			if chk:
				break
			count += 1
		return count


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		zeros = sum([num == 0 for num in nums])
		odds = set([i for i in range(len(nums)) if nums[i] % 2])
		n = len(nums)
		count = 0
		while zeros < n:
			if odds:
				for oddidx in odds:
					nums[oddidx] = nums[oddidx] - 1
					if nums[oddidx] == 0:
						zeros += 1
				count += len(odds)
				odds = set()
			else:
				for i in range(n):
					if nums[i] > 0:
						nums[i] = nums[i] // 2
						if nums[i] % 2:
							odds.add(i)
				count += 1
		return count


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		(n, res) = (len(nums), 0)
		mul = [0] * n
		for i in range(n):
			while nums[i] != 0:
				if nums[i] % 2:
					res += 1
					nums[i] -= 1
				else:
					mul[i] += 1
					nums[i] //= 2
		return res + max(mul)


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		ans = 0
		n = len(nums)
		s = sum(nums)
		while s != 0:
			nums_2 = [num % 2 for num in nums]
			diff = sum(nums_2)
			if diff == 0:
				nums = [num // 2 for num in nums]
				ans += 1
				s //= 2
			else:
				ans += diff
				s -= diff
				nums = [nums[i] - nums_2[i] for i in range(n)]
		return ans


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		cost = 0
		while True:
			all_zeros = True
			all_evens = True
			for i in range(len(nums)):
				if nums[i] == 0:
					continue
				all_zeros = False
				if nums[i] % 2 != 0:
					cost += nums[i] % 2
					nums[i] = nums[i] - nums[i] % 2
					all_evens = False
			if all_zeros:
				break
			if all_evens:
				for i in range(len(nums)):
					nums[i] = nums[i] // 2
				cost += 1
		return cost


class Solution:

	def minOperations(self, nums):
		add_operations = {}
		result = 0
		max_m = 0
		for i in nums:
			current = i
			if current in add_operations:
				result += add_operations[current]
			else:
				add_amount = 0
				multiplying_amount = 0
				while current:
					if current % 2:
						add_amount += 1
						current -= 1
					else:
						multiplying_amount += 1
						current = current / 2
				max_m = max(max_m, multiplying_amount)
				result += add_amount
				add_operations[i] = add_amount
		return result + max_m


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		res = 0
		mmax = float('inf')
		while mmax > 0:
			mmax = 0
			for i in range(len(nums)):
				if nums[i] & 1 == 1:
					nums[i] -= 1
					res += 1
				mmax = max(mmax, nums[i])
			if mmax > 0:
				nums = [x // 2 for x in nums]
				res += 1
		return res


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		self.ans = 0
		self.nums = nums

		def manipulate():
			for i in range(len(self.nums)):
				if self.nums[i] % 2 == 1:
					self.ans += 1
					self.nums[i] -= 1

			def allEven():
				for num in self.nums:
					if num % 2 == 1:
						return False
				return True
			if AllZero():
				return
			while allEven():
				self.nums = [num / 2 for num in self.nums]
				self.ans += 1

		def AllZero():
			for num in self.nums:
				if num != 0:
					return False
			return True
		while not AllZero():
			manipulate()
		return int(self.ans)


import math

class Solution:

	def minOperations(self, nums: List[int]) -> int:
		m = max(nums)
		n = math.floor(math.log(m, 2))
		res = 0
		while n >= 1:
			for (i, num) in enumerate(nums):
				if num >= 2 ** n:
					if num % 2 == 1:
						res += 1
						nums[i] = (nums[i] - 1) / 2
					else:
						nums[i] = nums[i] / 2
			res += 1
			n = n - 1
		for num in nums:
			if num == 1:
				res += 1
		return res


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		res = 0
		total = sum(nums)
		while total != 0:
			evens = 0
			for i in range(len(nums)):
				if nums[i] % 2 != 0:
					nums[i] -= 1
					res += 1
					total -= 1
				else:
					evens += 1
			if evens == len(nums):
				for i in range(len(nums)):
					nums[i] /= 2
					total -= nums[i]
				res += 1
		return res


class Solution:

	def pow2(self, num):
		addition = 0
		mult = 0
		while num > 0:
			if num % 2 == 0:
				num = num // 2
				mult += 1
			else:
				num -= 1
				addition += 1
		return (mult, addition)

	def minOperations(self, nums: List[int]) -> int:
		(result, _) = self.pow2(max(nums))
		for num in nums:
			if num > 0:
				result += self.pow2(num)[1]
		return result


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		lim = len(nums)
		test = [0] * lim
		t = 0
		while nums != test:
			vals = []
			v = 0
			for i in range(0, lim):
				if nums[i] % 2 == 0:
					vals.append(nums[i] // 2)
				else:
					nums[i] -= 1
					v += 1
			if v == 0:
				nums = vals
				t += 1
			else:
				t += v
		return t


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		big = 0
		ans = 0
		for i in range(len(nums)):
			twos = 0
			while nums[i] > 0:
				if nums[i] % 2 == 0:
					twos += 1
					nums[i] = nums[i] // 2
				else:
					ans += 1
					nums[i] -= 1
			if twos > big:
				big = twos
		return ans + big


import math

class Solution:

	def minOperations(self, nums: List[int]) -> int:
		max_log = 0
		count_zero = 0
		steps = 0
		for num in nums:
			if num != 0:
				log_num = 0
				while num > 0:
					if num % 2 == 0:
						num /= 2
						log_num += 1
					else:
						steps += 1
						num -= 1
				max_log = max(max_log, log_num)
		return steps + max_log


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		ans = 0
		peak = 0
		for n in nums:
			ans += bin(n)[2:].count('1')
			peak = max(peak, len(bin(n)[2:]) - 1)
		return ans + peak


class Solution:

	def minOperations(self, target: List[int]) -> int:
		result = 0
		while True:
			zero_count = 0
			i = 0
			n = len(target)
			while i < n:
				if target[i] & 1 > 0:
					break
				elif target[i] == 0:
					zero_count += 1
				i += 1
			if zero_count == n:
				return result
			if i == n:
				for j in range(n):
					target[j] = target[j] // 2
				result += 1
			for j in range(i, n):
				if target[j] & 1:
					target[j] -= 1
					result += 1


class Solution:

	def minOperations(self, A: List[int]) -> int:
		if all((v == 0 for v in A)):
			return 0
		curr = 0
		A_next = A.copy()
		changed = False
		for (i, v) in enumerate(A):
			if v % 2 == 1:
				changed = True
				curr += 1
				A_next[i] = v - 1
		if not changed:
			return 1 + self.minOperations([v // 2 for v in A])
		else:
			return curr + self.minOperations(A_next)


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		n = len(nums)
		moves = 0
		while True:
			zeros = 0
			for i in range(n):
				if nums[i] % 2:
					nums[i] -= 1
					moves += 1
			for i in range(n):
				if nums[i] == 0:
					zeros += 1
			if zeros == n:
				return moves
			for j in range(n):
				nums[j] //= 2
			moves += 1


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		cnt = 0
		while any(nums):
			even = 0
			for (k, v) in enumerate(nums):
				if v % 2 == 1:
					cnt += 1
					nums[k] -= 1
				elif v > 0:
					even += 1
			if even > 0:
				nums = list([x // 2 for x in nums])
				cnt += 1
		return cnt


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		self.count = 0

		def sub(nums):
			for i in range(len(nums)):
				if nums[i] % 2 != 0:
					nums[i] -= 1
					self.count += 1
			return nums

		def divide_all(nums):
			for k in range(len(nums)):
				if nums[k] == 0 or nums[k] % 2 == 0:
					nums[k] //= 2
				else:
					return []
			return nums

		def zeros(nums):
			c = 0
			for n in nums:
				if n == 0:
					c += 1
			return c
		sub(nums)
		while zeros(nums) < len(nums):
			divide_all(nums)
			self.count += 1
			sub(nums)
		return self.count


class Solution:

	def minOperations(self, nums: List[int]) -> int:

		def check(nums):
			flag = False
			for n in nums:
				if n > 1:
					flag = True
			return flag
		cnt = 0
		n = len(nums)
		flag = check(nums)
		while flag:
			cnt += 1
			for i in range(n):
				if nums[i] % 2:
					nums[i] -= 1
					nums[i] = nums[i] // 2
					cnt += 1
				else:
					nums[i] = nums[i] // 2
			flag = check(nums)
		for n in nums:
			if n != 0:
				cnt += 1
		return cnt


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		nums.sort()
		n = len(nums)
		q = collections.deque()
		q += [(0, nums)]
		tot = [0] * n
		while q:
			(cnt, t) = q.popleft()
			if t == tot:
				return cnt
			flag = False
			for i in range(n):
				if t[i] % 2:
					cnt += 1
					t[i] -= 1
				if t[i] != 0:
					flag = True
				t[i] //= 2
			if flag:
				cnt += 1
			q += [(cnt, t)]
		return 0


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		plus = 0
		double = 0
		for x in nums:
			if x != 0:
				plus += 1
			counter = 0
			while x / 2 >= 1:
				if x % 2 != 0 and x != 1:
					plus += 1
					x -= 1
				x /= 2
				counter += 1
			double = max(double, counter)
		return plus + double


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		m = 0
		numb = len(nums)
		while True:
			zc = 0
			var = 0
			for i in range(numb):
				if nums[i] % 2 != 0:
					nums[i] = nums[i] - 1
					m += 1
				if nums[i] == 0:
					zc += 1
			if zc == numb:
				break
			nums = list([i // 2 for i in nums])
			m += 1
		return m


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		counter = 0
		while 1:
			temp_counter = 0
			bigger_than_zero = 0
			for i in range(len(nums)):
				if nums[i] % 2 == 1:
					temp_counter += 1
					nums[i] -= 1
				if nums[i] > 0:
					bigger_than_zero += 1
					temp = bin(nums[i])
			counter += temp_counter
			if bigger_than_zero == 0:
				return counter
			run_again = True
			while run_again:
				counter += 1
				for i in range(len(nums)):
					nums[i] //= 2
					if nums[i] % 2 == 1:
						run_again = False
		return counter


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		self.count = 0
		all_even = False

		def reduce():
			nonlocal all_even
			zero = 0
			if all_even:
				for (i, num) in enumerate(nums):
					nums[i] >>= 1
					if nums[i] & 1:
						all_even = False
					zero += num == 0
				self.count += 1
			else:
				for (i, num) in enumerate(nums):
					if num & 1:
						self.count += 1
						nums[i] -= 1
				all_even = True
			return zero
		while True:
			n = reduce()
			if n == len(nums):
				break
		return self.count - 1


from collections import deque

class Solution:

	def minOperations(self, nums: List[int]) -> int:
		stack = deque([[nums, 0]])
		while stack:
			(cur_nums, count) = stack.popleft()
			if all([n == 0 or n == 1 for n in cur_nums]):
				return sum(cur_nums) + count
			if all([n % 2 == 0 for n in cur_nums]):
				stack.append([[n // 2 for n in cur_nums], count + 1])
				continue
			tmp = []
			for n in cur_nums:
				if n % 2 == 1:
					count += 1
					tmp.append(n - 1)
				else:
					tmp.append(n)
			stack.append([tmp, count])


class Solution:

	def minOperations(self, nums, op=0):
		isum = 0
		e = 0
		for i in range(len(nums)):
			if nums[i] % 2 != 0:
				op = op + 1
				nums[i] = nums[i] - 1
				if nums[i] != 0:
					e = 1
					nums[i] = nums[i] / 2
			elif nums[i] != 0:
				e = 1
				nums[i] = nums[i] / 2
			isum = isum + nums[i]
		op = op + e
		if isum == 0:
			return op
		return self.minOperations(nums, op)


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		ans = 0
		while True:
			maxv = 0
			for k in range(len(nums)):
				if nums[k] % 2:
					nums[k] -= 1
					ans += 1
				maxv = max(maxv, nums[k])
			if maxv == 0:
				break
			if maxv > 0:
				for k in range(len(nums)):
					nums[k] //= 2
				ans += 1
		return ans


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		(res, n) = (0, len(nums))
		for i in range(32):
			(zero, one) = (0, 0)
			for j in range(n):
				if nums[j] & 1 == 1:
					one += 1
				nums[j] >>= 1
				if nums[j] == 0:
					zero += 1
			res += one
			if zero == n:
				break
			else:
				res += 1
		return res


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		n = len(nums)
		res = 0
		max_zero = 0
		for i in range(len(nums)):
			(zero, one) = Solution.parse(nums[i])
			res += one
			max_zero = max(max_zero, zero)
		res += max_zero
		return res

	def parse(v):
		(zero, one) = (0, 0)
		while v > 0:
			if v % 2 == 1:
				one += 1
				v -= 1
			else:
				zero += 1
				v /= 2
		return (zero, one)


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		res = 0
		while True:
			divide = False
			all_zero = True
			for (i, n) in enumerate(nums):
				if n == 0:
					continue
				all_zero = False
				if n > 1:
					divide = True
				res += n % 2
				nums[i] //= 2
			res += int(divide)
			if all_zero:
				break
		return res


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		if not nums or sum(nums) == 0:
			return 0
		cnt = 0
		while sum(nums) != 0:
			if all((num % 2 == 0 for num in nums)):
				cnt += 1
				for i in range(len(nums)):
					nums[i] //= 2
			else:
				for i in range(len(nums)):
					if nums[i] % 2:
						cnt += 1
						nums[i] -= 1
		return cnt


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		count = 0
		while True:
			s = 0
			for i in range(len(nums)):
				num = nums[i]
				if num & 1:
					count += 1
					nums[i] = num - 1
					s += num - 1
				else:
					s += num
			if s == 0:
				return count
			nums = [num // 2 for num in nums]
			count += 1


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		ans = 0
		num_zero = sum((n == 0 for n in nums))
		while num_zero != len(nums):
			for (i, n) in enumerate(nums):
				if n % 2 == 1:
					ans += 1
					nums[i] -= 1
					if nums[i] == 0:
						num_zero += 1
				nums[i] >>= 1
			ans += 1
		return ans - 1

	def num_steps(self, n):
		if n == 0:
			return 0
		(steps, mask) = (0, 1)
		while mask <= n:
			if n & mask:
				steps += 2
			else:
				steps += 1
			mask <<= 1
		return steps - 1


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		numreps = []
		for num in nums:
			numreps.append(self.numToOps(num))
		numops = 0
		max2s = 0
		for rep in numreps:
			numops += rep[1]
			if rep[2] > max2s:
				max2s = rep[2]
		return numops + max2s

	def numToOps(self, val):
		rep = {1: 0, 2: 0}
		while val:
			if val % 2:
				rep[1] += 1
				val = val - 1
			else:
				rep[2] += 1
				val = int(val / 2)
		return rep


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		adds = []
		muls = []
		for (idx, num) in enumerate(nums):
			adds.append(0)
			muls.append(0)
			while num > 0:
				if num % 2 == 1:
					adds[idx] += 1
					num -= 1
				else:
					muls[idx] += 1
					num /= 2
		return sum(adds) + max(muls)


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		maxval = max(nums)
		idx = nums.index(maxval)
		ans = 0
		while nums[idx] != 0:
			for (i, n) in enumerate(nums):
				ans += n % 2
				nums[i] = n - n % 2
			if nums[idx] != 0:
				for (i, n) in enumerate(nums):
					nums[i] = nums[i] // 2
				ans += 1
		return ans


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		if not nums:
			return 0
		n = len(nums)
		ans = 0
		while True:
			zero_count = 0
			i = 0
			while i < n:
				if nums[i] % 2 == 1:
					break
				elif nums[i] == 0:
					zero_count += 1
				i += 1
			if zero_count == n:
				return ans
			if i == n:
				for j in range(n):
					nums[j] //= 2
				ans += 1
			for j in range(i, n):
				if nums[j] % 2 == 1:
					nums[j] -= 1
					ans += 1
		return ans


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		N = len(nums)
		ref = [0] * N
		res = 0
		while nums != ref:
			isAllEven = 1
			for i in range(N):
				if nums[i] % 2:
					nums[i] -= 1
					res += 1
					isAllEven = 0
			if isAllEven:
				for i in range(N):
					nums[i] //= 2
				res += 1
		return res


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		res = 0
		odd = 0
		flag = True
		while len(nums) > 0:
			temp = []
			if flag:
				for x in nums:
					if x & 1 == 1:
						res += 1
						if x - 1 != 0:
							temp.append(x - 1)
					elif x != 0:
						temp.append(x)
				flag = False
			else:
				for x in nums:
					temp.append(x // 2)
				res += 1
				flag = True
			nums = temp
		return res


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		n = len(nums)
		calls = 0
		while True:
			num_zeros = 0
			odd_index = 0
			for i in range(n):
				if nums[i] % 2 != 0:
					break
				elif nums[i] == 0:
					num_zeros += 1
				odd_index += 1
			if num_zeros == n:
				return calls
			if odd_index == n:
				for j in range(n):
					nums[j] /= 2
				calls += 1
			for j in range(i, n):
				if nums[j] % 2 != 0:
					nums[j] -= 1
					calls += 1


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		ans = 0
		s2 = []
		for i in nums:
			n1 = 0
			m = 0
			for j in range(32):
				if i & 2 ** j != 0:
					m = j
					n1 += 1
			ans += n1
			s2.append(m)
		s2.sort()
		ans += s2[0]
		for i in range(1, len(s2)):
			ans += s2[i] - s2[i - 1]
		return ans


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		total = 0
		max_divide = 0
		for (i, x) in enumerate(nums):
			divide = 0
			while x > 0:
				if x % 2 == 1:
					x -= 1
					total += 1
				else:
					x /= 2
					divide += 1
			if divide > max_divide:
				max_divide = divide
		return total + max_divide


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		ans = 0
		while sum(nums) > 0:
			can_divide = False
			for i in range(len(nums)):
				if nums[i] % 2 == 1:
					ans += 1
					nums[i] -= 1
				if nums[i] > 0:
					can_divide = True
			if can_divide:
				ans += 1
				for i in range(len(nums)):
					nums[i] //= 2
		return ans


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		count = {}

		def iseven(n):
			return n % 2 == 0
		ans = 0
		for n in nums:
			count[n] = count.get(n, 0) + 1
		keys = list(count.keys())
		for n in keys:
			if n == 0:
				count.pop(n)
			if not iseven(n):
				ans += count[n]
				n -= 1
				if n != 0:
					count[n] = count.get(n, 0) + count[n + 1]
				count.pop(n + 1)
		while len(count) > 0:
			keys = list(count.keys())
			ans += 1
			new_count = {}
			for n in keys:
				if not iseven(int(n / 2)):
					if int(n / 2) != 1:
						new_count[int(n / 2) - 1] = new_count.get(int(n / 2) - 1, 0) + count[n]
					ans += count[n]
				else:
					new_count[int(n / 2)] = new_count.get(int(n / 2), 0) + count[n]
			count = new_count
		return ans


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		ops = 0

		def op0() -> int:
			nonlocal nums
			ops = sum([n % 2 for n in nums])
			nums = [n >> 1 << 1 for n in nums]
			return ops

		def op1() -> int:
			nonlocal nums
			ops = 0
			while sum([n % 2 for n in nums]) == 0:
				ops += 1
				nums = [n // 2 for n in nums]
			return ops
		while sum(nums):
			ops += op0()
			if sum(nums):
				ops += op1()
		return ops


def adjust2power(n):
	if n == 0:
		return 0
	for i in range(1, n + 1):
		if 1 << i >= n:
			if n % (1 << i) != 0:
				i -= 1
			break
	return 1 << i

def howManyPower(n):
	for i in range(1, n + 1):
		if 1 << i == n:
			return i

class Solution:

	def minOperations(self, nums: List[int]) -> int:
		nums2p = []
		ans = 0
		while max(nums) > 1:
			ans += 1
			for i in range(len(nums)):
				if nums[i] == 0:
					continue
				if nums[i] > 1:
					ans += nums[i] % 2
				nums[i] = max(nums[i] // 2, 1)
		return ans + len(nums) - nums.count(0)


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		ans = 0
		n = len(nums)
		while True:
			ok = False
			flag = True
			for i in range(n):
				if nums[i] & 1:
					ans += 1
					nums[i] -= 1
				if nums[i] != 0 and (not nums[i] & 1):
					nums[i] //= 2
					if flag:
						ans += 1
						flag = False
				if nums[i] != 0:
					ok = True
			if not ok:
				break
		return ans


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		ret = 0
		change = 0
		while sum(nums):
			change = 0
			for i in range(len(nums)):
				if nums[i] % 2:
					ret += 1
					nums[i] -= 1
					change = 1
			if change == 0:
				ret += 1
				for i in range(len(nums)):
					nums[i] = nums[i] // 2
		return ret


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		f = {}

		def calc(x):
			if x == 0:
				return (0, 0)
			if x not in f:
				if x % 2 == 1:
					(a, b) = calc(x - 1)
					f[x] = (a + 1, b)
				else:
					(a, b) = calc(x // 2)
					f[x] = (a, b + 1)
			return f[x]
		x = []
		y = []
		for e in nums:
			(a, b) = calc(e)
			x.append(a)
			y.append(b)
		return sum(x) + max(y)


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		n = len(nums)
		done = [0] * n
		ans = 0
		while nums != done:
			for (i, x) in enumerate(nums):
				if x % 2:
					nums[i] -= 1
					ans += 1
			if nums != done:
				for (i, x) in enumerate(nums):
					nums[i] /= 2
				ans += 1
		return ans


class Solution:

	def minOperations(self, a: List[int]) -> int:
		res = [0]
		while True:
			self.checkOdd(a, res)
			end = self.checkDivide(a)
			if end:
				break
			else:
				res[0] += 1
		return res[0]

	def checkOdd(self, a, res):
		for i in range(len(a)):
			if a[i] % 2 != 0:
				a[i] -= 1
				res[0] += 1

	def checkDivide(self, a):
		flg = True
		for i in range(len(a)):
			if a[i] > 0:
				a[i] /= 2
				flg = False
		return flg


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		count = 0
		while True:
			op = False
			zeroes = 0
			for i in range(len(nums)):
				if nums[i] % 2 != 0:
					count += 1
					nums[i] -= 1
			for i in range(len(nums)):
				if nums[i] == 0:
					zeroes += 1
				else:
					nums[i] = nums[i] // 2
					op = True
			if op:
				count += 1
			if zeroes == len(nums):
				return count


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		result = 0
		while True:
			allzero = True
			for (index, num) in enumerate(nums):
				if num != 0:
					allzero = False
				if num % 2 == 1:
					nums[index] = num - 1
					result += 1
			if allzero:
				break
			allzero = True
			for (index, num) in enumerate(nums):
				if num != 0:
					allzero = False
				nums[index] = num // 2
			if allzero:
				break
			else:
				result += 1
		return result


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		num_operations = 0
		stacks = [[], []]
		cur_idx = 0
		nxt_idx = 1
		odd = False
		for num in nums:
			if num % 2:
				odd = True
			if num:
				stacks[0].append(num)
		num_operations = 0
		while stacks[0] or stacks[1]:
			if odd:
				while stacks[cur_idx]:
					nxt = stacks[cur_idx].pop()
					if nxt % 2:
						nxt -= 1
						num_operations += 1
					if nxt:
						stacks[nxt_idx].append(nxt)
				odd = False
			else:
				num_operations += 1
				while stacks[cur_idx]:
					nxt = stacks[cur_idx].pop()
					nxt /= 2
					if nxt % 2:
						odd = True
					if nxt:
						stacks[nxt_idx].append(nxt)
			(cur_idx, nxt_idx) = (nxt_idx, cur_idx)
		return num_operations


class Solution:

	def minOperations(self, nums: List[int]) -> int:

		def proc(nums):
			cnt = 0
			for i in range(len(nums)):
				if nums[i] % 2 > 0:
					nums[i] -= 1
					cnt += 1
			if cnt == 0:
				for i in range(len(nums)):
					nums[i] //= 2
			return max(cnt, 1)
		ops = 0
		while sum(nums) > 0:
			ops += proc(nums)
		return ops


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		m = max(nums)
		n = nums.count(m)
		return sum((bin(a).count('1') for a in nums)) + len(bin(max(nums))) - 3


class Solution:

	def minOperations(self, nums) -> int:
		steps = 0
		while True:
			for i in range(len(nums)):
				if nums[i] % 2 == 1:
					nums[i] -= 1
					steps += 1
			remaining = 0
			for i in range(len(nums)):
				if nums[i] > 0:
					remaining += 1
			if remaining == 0:
				return steps
			for i in range(len(nums)):
				nums[i] /= 2
			steps += 1


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		count = 0
		l = len(nums)
		while True:
			allZeros = True
			for i in range(l):
				if nums[i] != 0:
					allZeros = False
				if nums[i] % 2:
					count += 1
					nums[i] -= 1
			if allZeros:
				return count
			flag = False
			for i in range(l):
				if nums[i] != 0:
					flag = True
					nums[i] = nums[i] // 2
			if flag:
				count += 1


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		result = 0
		while nums:
			new = []
			for x in nums:
				if x > 0:
					if x != 1:
						new.append(x - (x & 1))
					result += x & 1
			nums = new
			if not nums:
				break
			for i in range(len(nums)):
				nums[i] //= 2
			result += 1
		return result


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		ret = 0

		def check(nums):
			isAllZero = 1
			multiplied = 0
			res = 0
			for i in range(len(nums)):
				if nums[i] != 0:
					isAllZero = 0
				if nums[i] & 1:
					res += 1
					nums[i] -= 1
				if nums[i] != 0:
					nums[i] = nums[i] // 2
					multiplied = 1
			if multiplied == 1:
				res += 1
			return (isAllZero, res)
		while True:
			(done, cnt) = check(nums)
			ret += cnt
			if done == 1:
				break
		return ret


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		s = set(nums)
		if len(s) == 1 and 0 in s:
			return 0
		else:
			l = nums
			cnt = 0
			for i in range(len(l)):
				if l[i] % 2 == 1:
					cnt += 1
					l[i] -= 1
			if cnt == 0:
				return 1 + self.minOperations([a // 2 for a in l])
			else:
				return cnt + self.minOperations(l)


import math

class Solution:

	def minOperations(self, n: List[int]) -> int:
		nums = []
		for i in range(len(n)):
			if n[i] == 0:
				continue
			nums.append(n[i])

		def countOdd(nums):
			c = 0
			for i in range(len(nums)):
				if nums[i] != 1 and nums[i] % 2 == 1:
					nums[i] -= 1
					c += 1
			return c
		count = 0
		while set(nums) != {1}:
			count += countOdd(nums)
			for i in range(len(nums)):
				if nums[i] == 1:
					continue
				nums[i] = nums[i] // 2
			count += 1
		count += len(nums)
		return count


class Solution:

	def is_divisible(self, nums):
		res = []
		for ix in range(len(nums)):
			if nums[ix] % 2 != 0:
				res.append(ix)
		return res

	def divide_by_2(self, nums):
		for ix in range(len(nums)):
			nums[ix] = nums[ix] / 2

	def minOperations(self, nums: List[int]) -> int:
		ops = 0
		while nums != [0] * len(nums):
			minus_ix = self.is_divisible(nums)
			for ix in minus_ix:
				nums[ix] -= 1
				ops += 1
			if nums == [0] * len(nums):
				return ops
			self.divide_by_2(nums)
			ops += 1
		return ops


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		high = len(bin(max(nums))) - 3
		one = sum([bin(n).count('1') for n in nums])
		return high + one


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		n = len(nums)
		temp = c = 0
		while True:
			for i in range(n):
				if nums[i] == 1:
					c += 1
					nums[i] = 0
				elif nums[i] % 2 == 1:
					nums[i] -= 1
					c += 1
				if nums[i] == 0:
					temp += 1
			if temp == n:
				return c
			temp = 0
			for i in range(n):
				nums[i] = int(nums[i] / 2)
			c += 1


class Solution:

	def minOperations(self, nums: List[int]) -> int:

		def nrOfOpsToZero(n):
			if n == 0:
				return (0, 0)
			if n % 2 == 1:
				(recDups, recIncs) = nrOfOpsToZero(n - 1)
				return (recDups, recIncs + 1)
			(recDups, recIncs) = nrOfOpsToZero(n // 2)
			return (recDups + 1, recIncs)
		maxDups = 0
		totalIncs = 0
		for i in range(0, len(nums)):
			(dups, incs) = nrOfOpsToZero(nums[i])
			totalIncs += incs
			maxDups = max(maxDups, dups)
		return int(maxDups + totalIncs)


class Solution:

	def minOperations(self, nums: List[int]) -> int:

		def makeeven():
			did = 0
			for i in range(len(nums)):
				if nums[i] & 1:
					nums[i] -= 1
					did += 1
			return did

		def halv():
			did = False
			for i in range(len(nums)):
				if nums[i]:
					nums[i] >>= 1
					did = True
			return did
		count = 0
		while any(nums):
			count += makeeven()
			count += int(halv())
		return count


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		(odds, even) = ([], [])
		for i in nums:
			if i & 1:
				odds.append(i)
			elif i != 0:
				even.append(i)
		count = 0
		while odds or even:
			if odds:
				i = odds.pop()
				if i - 1 != 0:
					even.append(i - 1)
			else:
				new_even = []
				for i in even:
					i //= 2
					if i & 1:
						odds.append(i)
					else:
						new_even.append(i)
				even = new_even
			count += 1
		return count


class Solution:

	def minOperations(self, nums: List[int]) -> int:

		@lru_cache(None)
		def steps(n):
			if n == 0:
				return (0, 0, 0)
			if n == 1:
				return (1, 1, 0)
			if n & 1:
				(a, b, c) = steps(n - 1)
				return (a + 1, b + 1, c)
			(a, b, c) = steps(n // 2)
			return (a + 1, b, c + 1)
		evens = 0
		odds = 0
		for num in nums:
			(a, b, c) = steps(num)
			odds += b
			evens = max(evens, c)
		return odds + evens


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		length = len(nums)

		def check_all_zeros(arr):
			for ele in arr:
				if ele != 0:
					return False
			return True

		def divide_by_2(arr):
			return list([x / 2 for x in arr])
		ops = 0
		while True:
			if check_all_zeros(nums):
				return ops
			all_even = True
			for i in range(length):
				num = nums[i]
				if num % 2 == 0:
					if i == length - 1 and all_even:
						nums = divide_by_2(nums)
						ops += 1
				else:
					all_even = False
					nums[i] -= 1
					ops += 1


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		res = 0
		n = len(nums)
		while True:
			p = 0
			for i in range(n):
				if nums[i] % 2:
					nums[i] -= 1
					res += 1
				p += nums[i]
			if p == 0:
				return res
			for i in range(n):
				nums[i] //= 2
			res += 1


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		ans = 0
		n = len(nums)
		co = 0
		while True:
			co = 0
			for i in range(n):
				if nums[i] % 2 == 1:
					nums[i] -= 1
					ans += 1
			for i in range(n):
				if nums[i] == 0:
					co += 1
			if co == n:
				return ans
			for i in range(n):
				nums[i] = nums[i] // 2
			ans += 1
		return ans


class Solution:

	def minOperations(self, A: List[int]) -> int:
		if all((v == 0 for v in A)):
			return 0
		odds = 0
		A_next = A.copy()
		for (i, v) in enumerate(A):
			if v % 2 == 1:
				odds += 1
				A_next[i] = v - 1
		if odds > 0:
			return odds + self.minOperations(A_next)
		return 1 + self.minOperations([v // 2 for v in A])


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		op = 0
		while max(nums) != 0:
			allEven = True
			for (i, n) in enumerate(nums):
				if n % 2 == 1:
					nums[i] -= 1
					op += 1
					allEven = False
			if allEven:
				nums = [n // 2 for n in nums]
				op += 1
		return op


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		c = 0
		while len(nums) != 0:
			L = []
			for i in range(len(nums)):
				if nums[i] == 1:
					c += 1
				elif nums[i] % 2 == 1:
					L.append(nums[i] // 2)
					c += 1
				elif nums[i] != 0 and nums[i] % 2 == 0:
					L.append(nums[i] // 2)
			if len(L) != 0:
				c += 1
			nums = L
		return c


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		ans = 0
		while set(nums) != {0}:
			even = True
			for i in range(len(nums)):
				if nums[i] & 1:
					ans += 1
					even = False
					nums[i] -= 1
			if even:
				nums = [i // 2 for i in nums]
				ans += 1
		return ans


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		c = 0
		n = len(nums)
		while True:
			if len(set(nums)) == 1 and nums[0] == 0:
				break
			for i in range(n):
				if nums[i] % 2 != 0 and nums[i] > 0 and (nums[i] != 0):
					nums[i] = nums[i] - 1
					c += 1
			f = 0
			for i in range(n):
				if nums[i] % 2 == 0:
					f += 1
			if len(set(nums)) == 1 and nums[0] == 0:
				break
			if f == len(nums):
				for i in range(n):
					if nums[i] % 2 == 0 and nums[i] != 0:
						nums[i] = nums[i] // 2
				c += 1
		return c


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		op = 0
		while sum(nums) != 0:
			odds = 0
			for i in range(len(nums)):
				if nums[i] & 1 != 0:
					odds += 1
					nums[i] -= 1
			if odds == 0:
				nums = list(map(lambda x: x // 2, nums))
				op += 1
			else:
				op += odds
		return op


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		if sum(nums) == 0:
			return 0
		total = 0
		zeros = False
		while sum(nums) > 0:
			for (i, num) in enumerate(nums):
				if num < 1:
					continue
				zeros = False
				total += num % 2
				nums[i] -= num % 2
			if sum(nums) > 0:
				total += 1
				for (i, num) in enumerate(nums):
					nums[i] >>= 1
		return total


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		if sum(nums) == 0:
			return 0
		s = 0
		for i in range(len(nums)):
			if nums[i] % 2 == 1:
				nums[i] -= 1
				s += 1
		if s == 0:
			for i in range(len(nums)):
				nums[i] //= 2
			s += 1
		return self.minOperations(nums) + s


class Solution:

	def minOperations(self, nums: List[int]) -> int:

		def deductOdd(nums):
			n = len(nums)
			cnt = 0
			for i in range(n):
				if nums[i] % 2 == 1:
					nums[i] -= 1
					cnt += 1
			return cnt

		def halfEven(nums):
			n = len(nums)
			allZero = True
			for i in range(n):
				if nums[i] > 0:
					nums[i] //= 2
					allZero = False
			return allZero
		result = deductOdd(nums)
		while not halfEven(nums):
			result += 1
			result += deductOdd(nums)
		return result


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		count = 0
		numzeros = 0
		n = len(nums)
		for i in range(n):
			if nums[i] == 0:
				numzeros += 1
		while numzeros < n:
			k = 0
			for i in range(n):
				if nums[i] % 2:
					nums[i] -= 1
					count += 1
					if nums[i] == 0:
						numzeros += 1
					else:
						k = 1
						nums[i] = nums[i] / 2
				elif nums[i] == 0:
					continue
				else:
					k = 1
					nums[i] = nums[i] / 2
			if k == 1:
				count += 1
		return count


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		c = 1
		count = 0
		maxn = max(nums)
		while c * 2 <= maxn:
			c = c * 2
			count += 1

		@lru_cache
		def dfs(n):
			if n <= 1:
				return n
			elif n % 2 == 0:
				return dfs(n // 2)
			else:
				return 1 + dfs(n // 2)
		for i in nums:
			count += dfs(i)
		return count


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		count = 0
		while True:
			for i in range(len(nums)):
				if nums[i] == 1:
					nums[i] = 0
					count += 1
			if max(nums) < 1:
				break
			for i in range(len(nums)):
				if nums[i] < 2:
					continue
				if nums[i] % 2 != 0:
					count += 1
				nums[i] //= 2
			count += 1
		return count


class Solution:

	def minOperations(self, nums: List[int]) -> int:

		def cod(k, i):
			if k == 0:
				self.memo[k] = [self.g[i], self.h[i]]
				return 0
			if k not in self.memo:
				if k % 2 == 0:
					self.g[i] += 1
					cod(int(k / 2), i)
				else:
					self.h[i] += 1
					cod(k - 1, i)
		self.memo = {}
		l = len(nums)
		f = [0] * l
		self.g = [0] * l
		self.h = [0] * l
		for i in range(l):
			f[i] = cod(nums[i], i)
		return sum(self.h) + max(self.g)


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		result = 0
		new_nums = sorted(nums, reverse=True)
		while len(new_nums) > 0:
			if new_nums[-1] == 0:
				new_nums.pop(len(new_nums) - 1)
			elif new_nums[-1] == 1:
				new_nums.pop(len(new_nums) - 1)
				result += 1
			else:
				flag = True
				for i in range(len(new_nums)):
					if new_nums[i] & 1 == 1:
						new_nums[i] -= 1
						result += 1
						flag = False
				if flag:
					for i in range(len(new_nums)):
						new_nums[i] >>= 1
					result += 1
		return result


def ops(x):
	if x == 1:
		return (0, 1)
	if x % 2 == 0:
		(d, i) = ops(x // 2)
		return (d + 1, i)
	else:
		(d, i) = ops(x - 1)
		return (d, i + 1)

class Solution:

	def minOperations(self, nums: List[int]) -> int:
		increments = 0
		max_doubles = 0
		for x in nums:
			if x == 0:
				continue
			(doubs, incrs) = ops(x)
			increments += incrs
			if doubs > max_doubles:
				max_doubles = doubs
		return increments + max_doubles


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		ans = -1
		l = nums
		while 1:
			tf = 0
			for i in range(len(nums)):
				if l[i] > 0:
					tf = 1
					if l[i] % 2:
						l[i] -= 1
						ans += 1
					if l[i]:
						l[i] //= 2
			if not tf:
				break
			ans += 1
		return ans


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		total = 0
		zeros = 0
		for i in nums:
			if i == 0:
				zeros += 1
		while zeros < len(nums):
			for i in range(len(nums)):
				if nums[i] % 2 == 1:
					nums[i] -= 1
					if nums[i] == 0:
						zeros += 1
					total += 1
			allEven = True
			while allEven and zeros < len(nums):
				for i in range(len(nums)):
					nums[i] = nums[i] >> 1
					if nums[i] % 2 == 1:
						allEven = False
				total += 1
		return total


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		res = sum((num > 0 for num in nums))
		max_time = 0
		for num in nums:
			add_op = 0
			time_op = 0
			Y = num
			X = 1
			while Y > X:
				if Y % 2 == 1:
					Y -= 1
					add_op += 1
				else:
					Y /= 2
					time_op += 1
			max_time = max(max_time, time_op)
			if num > 1:
				res += add_op
		res += max_time
		return res


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		even_num = []
		odd_num = []
		zero_num = []

		def category(n, zero_num, even_num, odd_num):
			if n == 0:
				zero_num.append(n)
			elif n % 2 == 0:
				even_num.append(n)
			else:
				odd_num.append(n)
		for n in nums:
			category(n, zero_num, even_num, odd_num)
		ans = 0
		while len(even_num) or len(odd_num):
			new_odd_num = []
			if len(odd_num):
				ans += len(odd_num)
			for n in odd_num:
				n = n - 1
				category(n, zero_num, even_num, new_odd_num)
			odd_num = new_odd_num
			new_even_num = []
			if len(even_num):
				ans += 1
			for n in even_num:
				n = n // 2
				category(n, zero_num, new_even_num, odd_num)
			even_num = new_even_num
		return ans


class Solution:

	def minOperations(self, t: List[int]) -> int:
		n = len(t)
		ans = 0
		while 1:
			z = 0
			i = 0
			while i < n:
				if t[i] % 2:
					break
				elif t[i] == 0:
					z += 1
				i += 1
			if z == n:
				return ans
			if i == n:
				for j in range(n):
					t[j] = t[j] // 2
				ans += 1
			for j in range(i, n):
				if t[j] & 1:
					t[j] -= 1
					ans += 1
		return ans


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		ans = 0
		while any((num != 0 for num in nums)):
			odd = 0
			for (idx, num) in enumerate(nums):
				if num & 1:
					nums[idx] -= 1
					odd += 1
					ans += 1
			if not odd:
				for (idx, num) in enumerate(nums):
					nums[idx] = num // 2
				ans += 1
		return ans


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		valid = {0: 0}
		for i in range(31):
			valid[2 ** i] = i
		ans = 0
		max_multi_step = float('-inf')
		for i in range(len(nums)):
			if nums[i] > 0:
				ans += 1
			else:
				continue
			(one_step, multi_step) = (0, 0)
			while nums[i] not in valid:
				if nums[i] & 1:
					one_step += 1
					nums[i] -= 1
				else:
					multi_step += 1
					nums[i] //= 2
			ans += one_step
			max_multi_step = max(max_multi_step, multi_step + valid[nums[i]])
		ans += max_multi_step
		return ans


from math import floor, log

class Solution:

	def minOperations(self, nums: List[int]) -> int:
		ans = 0
		for x in nums:
			for i in bin(x)[2:]:
				if i != '0':
					ans += 1
		m = max(nums)
		ans += floor(log(m, 2))
		return ans


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		ops = 0

		def it():
			nonlocal ops
			postAllZero = True
			for i in range(len(nums)):
				n = nums[i]
				if n % 2 == 1:
					nums[i] -= 1
					ops += 1
				if nums[i] > 0:
					postAllZero = False
			if postAllZero:
				return
			for i in range(len(nums)):
				nums[i] /= 2
			ops += 1
			it()
		it()
		return ops


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		nums.sort()
		result = 0
		multiple = 0
		last = 0

		def find(mx):
			nonlocal last
			if mx <= 1:
				return mx
			if mx % 2 == 1:
				return find(mx - 1) + 1
			last += 1
			return find(mx // 2) + 1
		result = 0
		for (i, n) in enumerate(nums):
			result += find(n) - last
			multiple = max(multiple, last)
			last = 0
		return result + multiple


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		max_mul = 0
		total_add = 0
		ope_dict = {0: (0, 0)}

		def func(num: int):
			if num in ope_dict:
				return ope_dict[num]
			elif num % 2:
				r = func(num - 1)
				ope_dict[num] = (r[0] + 1, r[1])
			else:
				r = func(num // 2)
				ope_dict[num] = (r[0], r[1] + 1)
			return ope_dict[num]
		for n in nums:
			(add, mul) = func(n)
			total_add += add
			max_mul = max(max_mul, mul)
		return total_add + max_mul


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		numOperations = 0
		compare = [0] * len(nums)
		while nums != compare:
			for i in range(len(nums)):
				if nums[i] % 2 != 0:
					nums[i] -= 1
					numOperations += 1
			if nums == compare:
				return numOperations
			for i in range(len(nums)):
				nums[i] /= 2
			numOperations += 1
		return numOperations


class Solution:

	def minOperations(self, A: List[int]) -> int:
		r = 0
		while A != [0 for i in A]:
			odd = 0
			for i in range(len(A)):
				if A[i] % 2 == 1:
					A[i] = A[i] - 1
					odd += 1
			if odd == 0:
				A = [x // 2 for x in A]
				r += 1
			else:
				r += odd
		return r


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		import sys
		import math

		def h2(n):
			ans1 = 0
			ans2 = 0
			while n != 1:
				if n % 2 == 0:
					ans1 += 1
					n /= 2
				else:
					n -= 1
					ans2 += 1
			return (ans1, ans2)
		ans = 0
		mixx = -1
		for i in nums:
			if i != 0:
				ans += 1
				(ans1, ans2) = h2(i)
				ans += ans2
				mixx = max(ans1, mixx)
		ans += mixx
		return int(ans)


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		count = 0
		while any((num != 0 for num in nums)):
			for pos in range(len(nums)):
				if nums[pos] % 2 != 0:
					nums[pos] -= 1
					count += 1
			if all((num == 0 for num in nums)):
				return count
			else:
				nums = [num / 2 for num in nums]
				count += 1
		return count


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		cou = [0] * len(nums)
		count = 0
		for i in range(len(nums)):
			while nums[i] > 0:
				if nums[i] % 2 != 0:
					nums[i] -= 1
					count += 1
				else:
					nums[i] = nums[i] // 2
					cou[i] += 1
		res = max(cou) + count
		return res


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		count = 0
		max_max_power = 0
		for n in nums:
			if n == 0:
				continue
			max_power = 0
			temp = n
			while temp > 1:
				max_power += 1
				temp >>= 1
			max_max_power = max(max_max_power, max_power)
			while max_power >= 0:
				if 2 ** max_power <= n:
					n -= 2 ** max_power
					count += 1
				max_power -= 1
		return count + max_max_power


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		i = 0
		k = 0
		for x in range(10 ** 9):
			if nums == [0.0] * len(nums):
				break
			if i >= 1:
				k += 1
				i = 0
			for y in range(len(nums)):
				if nums[y] % 2 != 0:
					nums[y] -= 1
					k += 1
				if nums[y] % 2 == 0:
					nums[y] = nums[y] / 2
					i += 1
		return k


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		arr = [0] * len(nums)
		count = 0
		while nums != arr:
			f = 0
			for i in range(len(nums)):
				if nums[i] % 2 == 1:
					nums[i] -= 1
					count += 1
					f = 1
			if f == 0:
				for i in range(len(nums)):
					nums[i] = nums[i] // 2
				count += 1
		return count


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		ans = 0

		def cal1(arr):
			z = 0
			op = 0
			for i in range(len(arr)):
				if arr[i] % 2 == 1:
					arr[i] -= 1
					op += 1
					if arr[i] == 0:
						z += 1
			return (op, z)

		def cal2(arr):
			flg = 0
			for i in range(len(arr)):
				if arr[i] % 2 == 0 and arr[i] > 0:
					arr[i] //= 2
					flg = 1
			return flg
		nz = sum([1 for i in nums if i != 0])
		while nz > 0:
			(op, z) = cal1(nums)
			ans += op
			nz -= z
			ans += cal2(nums)
		return ans


class Solution:
	import math

	def minOperations(self, nums: List[int]) -> int:

		def f(s):
			n = 0
			p = 0
			while s:
				if s % 2 == 0:
					s = s // 2
					p += 1
				else:
					s -= 1
				n += 1
			return (n, p)
		nums.sort(key=lambda x: f(x)[1])
		res = 0
		inc = 0
		for i in range(len(nums)):
			if nums[i] != 0:
				(n, p) = f(nums[i])
				res += n - p
				res += p - inc
				inc = p
		return res


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		add = 0
		mul = 0
		for n in nums:
			m = 0
			while n > 0:
				if n & 1 == 1:
					add += 1
					n -= 1
				else:
					m += 1
					mul = max(m, mul)
					n //= 2
		return add + mul


class Solution:

	def odds(self, nums):
		ops = 0
		for i in range(len(nums)):
			if nums[i] % 2 == 1:
				nums[i] -= 1
				ops += 1
		return (nums, ops)

	def opsc(self, nums, final):
		if nums == final:
			return 0
		(nums, ops) = self.odds(nums)
		if nums == final:
			return ops
		for i in range(len(nums)):
			nums[i] /= 2
		ops += 1
		ops += self.opsc(nums, final)
		return ops

	def minOperations(self, nums: List[int]) -> int:
		final = []
		for i in range(len(nums)):
			final.append(0)
		return self.opsc(nums, final)


class Solution:

	def soln(self, nums, ans, e, o):
		if len(nums) == 0:
			return ans
		for i in nums:
			if i % 2 == 0 and i != 0:
				e.append(i)
			elif i != 0:
				o.append(i)
		ans += len(o)
		for i in range(len(o)):
			o[i] -= 1
		oo = []
		for i in range(len(o)):
			if o[i] != 0:
				oo.append(o[i])
		o = oo.copy()
		for i in range(len(o)):
			o[i] = int(o[i] / 2)
		if len(e) != 0 or len(o) != 0:
			ans += 1
		for i in range(len(e)):
			e[i] = int(e[i] / 2)
		nnu = []
		for i in e:
			if i != 0:
				nnu.append(i)
		for i in o:
			if i != 0:
				nnu.append(i)
		return self.soln(nnu, ans, [], [])

	def minOperations(self, nums: List[int]) -> int:
		e = []
		o = []
		ans = 0
		return self.soln(nums, ans, e, o)


from functools import lru_cache

class Solution:

	def minOperations(self, nums: List[int]) -> int:
		res = 0

		@lru_cache(None)
		def dp(n):
			if n == 0:
				return (0, 0)
			else:
				(add, mul) = (0, 0)
				if n & 1 == 1:
					(a, b) = dp(n - 1)
					return (a + 1, b)
				else:
					(a, b) = dp(n // 2)
					return (a, b + 1)
		res = 0
		m = 0
		for i in nums:
			(a, b) = dp(i)
			res += a
			m = max(m, b)
		return res + m


class Solution:

	def modify(self, arr, op, idx):
		if op == 0:
			arr[idx] = arr[idx] - 1
		if op == 1:
			for i in range(len(arr)):
				arr[i] = arr[i] / 2

	def minOperations(self, nums: List[int]) -> int:
		result = [0 for _ in range(len(nums))]
		operations = 0
		while nums != result:
			for i in range(len(nums)):
				if nums[i] % 2 == 1:
					self.modify(nums, 0, i)
					operations += 1
			if nums == result:
				return operations
			self.modify(nums, 1, i)
			operations += 1
		return operations


import functools
import sys

class Solution:

	def minOperations(self, nums: List[int]) -> int:
		sys.setrecursionlimit(10 ** 6)

		@functools.lru_cache(None)
		def cal(n):
			if n == 0:
				return (0, 0)
			if n % 2 == 0:
				(a, b) = cal(n // 2)
				return (a, b + 1)
			else:
				(a, b) = cal(n - 1)
				return (a + 1, b)
			return (a, b)
		ans = 0
		mul = 0
		for e in nums:
			(a, b) = cal(e)
			ans += a
			mul = max(mul, b)
		return ans + mul


from typing import List

class Counter:

	def __init__(self):
		self.c = 0

class Solution:

	def minOperations(self, nums: List[int]) -> int:

		def makeAllEven(nums, counter):

			def decrease(num, counter):
				if num % 2 != 0:
					num -= 1
					counter.c += 1
				return num
			ret = list(map(lambda n: decrease(n, counter), nums))
			return ret

		def allZero(nums):
			return sum(nums) == 0

		def makeAllHalf(nums, counter):
			ret = list(map(lambda x: x // 2, nums))
			counter.c += 1
			return ret
		counter = Counter()
		while not allZero(nums):
			nums = makeAllEven(nums, counter)
			if not allZero(nums):
				nums = makeAllHalf(nums, counter)
		return counter.c


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		mem = {}
		ans = [[0 for i in range(len(nums))] for j in range(2)]
		for (i, num) in enumerate(nums):
			times = [0, 0]
			_num = num
			while _num != 0:
				if _num in mem:
					times[0] += mem[_num][0]
					times[1] += mem[_num][1]
					break
				if _num % 2 == 1:
					_num -= 1
					times[0] += 1
				else:
					_num /= 2
					times[1] += 1
			mem[num] = times
			ans[0][i] = times[0]
			ans[1][i] = times[1]
		print(ans)
		return sum(ans[0]) + max(ans[1])


from math import log2, log
from typing import List

class Solution:

	def minOperations(self, nums: List[int]) -> int:
		ops = 0

		def op0() -> int:
			nonlocal nums
			ops = sum([n % 2 for n in nums])
			nums = [n >> 1 << 1 for n in nums]
			return ops

		def op1() -> int:
			nonlocal nums
			ops = 0
			while sum([n % 2 for n in nums]) == 0:
				ops += 1
				nums = [n // 2 for n in nums]
			return ops
		while sum(nums):
			ops += op0()
			if sum(nums):
				ops += op1()
		return ops


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		ops = 0
		changed = True
		while changed:
			changed = False
			for (i, x) in enumerate(nums):
				if not x % 2 == 0:
					nums[i] -= 1
					ops += 1
					changed = True
			divided = False
			for (i, x) in enumerate(nums):
				if x > 0:
					nums[i] = nums[i] // 2
					divided = True
			if divided:
				changed = True
				ops += 1
		return ops


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		memo = {0: (0, 0)}

		def helper(num):
			if num not in memo:
				if num % 2 == 1:
					(a, b) = helper(num - 1)
					memo[num] = (a + 1, b)
				else:
					(a, b) = helper(num // 2)
					memo[num] = (a, b + 1)
			return memo[num]
		a = b = 0
		for num in nums:
			(tmpa, tmpb) = helper(num)
			a += tmpa
			b = max(b, tmpb)
		return a + b


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		tot_step = 0
		while True:
			not_zero = False
			for i in range(len(nums)):
				if nums[i] == 0:
					continue
				not_zero = True
				if nums[i] % 2 != 0:
					nums[i] -= 1
					tot_step += 1
			not_zero = False
			for i in range(len(nums)):
				if nums[i] == 0:
					continue
				not_zero = True
				nums[i] = nums[i] / 2
			if not_zero == False:
				break
			tot_step += 1
		return tot_step


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		max_div = 0
		max_sub = 0
		for num in nums:
			(div_times, sub_times) = self.calc_steps(num)
			max_div = max(max_div, div_times)
			max_sub += sub_times
		return max_div + max_sub

	@lru_cache
	def calc_steps(self, num):
		if num == 0:
			return (0, 0)
		if num == 1:
			return (0, 1)
		if num == 2:
			return (1, 1)
		if num == 3:
			return (1, 2)
		(div_times, sub_times) = self.calc_steps(num // 2)
		return (div_times + 1, num % 2 + sub_times)


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		_max = -1
		ans = 0
		for x in nums:
			ans += bin(x).count('1')
			_max = max(_max, x)
		ans += len(bin(_max)) - 3
		return ans


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		ans = 0
		for x in nums:
			ans += bin(x).count('1')
		width = len(bin(max(nums))) - 2
		return ans + width - 1


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		ans = max_op = 0
		for b in map(bin, nums):
			ans += b.count('1')
			max_op = max(max_op, len(b) - 3)
		return ans + max_op


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		op0 = sum((bin(num).count('1') for num in nums))
		op1 = len(bin(max(nums))) - 3
		return op0 + op1


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		(sumOp0, maxOp1) = (0, 0)
		for num in nums:
			(op0, op1) = (list(bin(num)).count('1'), len(bin(num)[2:]) - 1)
			sumOp0 += op0
			maxOp1 = max(maxOp1, op1)
		return sumOp0 + maxOp1


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		ans = 0
		mx = 0
		for n in nums:
			b = bin(n)
			ans += b.count('1')
			mx = max(mx, len(b) - 3)
		return ans + mx


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		ans = 0
		bns = 0
		for x in nums:
			b = bin(x)
			ans += b.count('1')
			if x:
				bns = max(bns, len(b) - 2)
		return ans + max(bns - 1, 0)


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		res = length = 0
		for num in nums:
			bits = bin(num)
			res += bits.count('1')
			length = max(length, len(bits) - 2)
		return res + length - 1


class Solution:

	def minOperations(self, arr: List[int]) -> int:
		(ret, maxx) = (0, 0)
		import math
		for i in arr:
			maxx = max(maxx, len(bin(i)) - 3)
			ret += bin(i).count('1')
		return ret + maxx


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		n = len(nums)
		result = 0
		m = 0

		def bitcount(a):
			cnt = 0
			while a:
				cnt += 1
				a &= a - 1
			return cnt
		for num in nums:
			result += bitcount(num)
			m = max(m, num)
		for i in range(32):
			if m > 1:
				result += 1
			else:
				break
			m >>= 1
		return result


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		shifts = 0
		adds = 0
		for n in nums:
			if n == 0:
				continue
			b = bin(n)[2:]
			shifts = max(shifts, len(b) - 1)
			adds += sum((c == '1' for c in b))
		return shifts + adds


import numpy as np

class Solution:

	def minOperations(self, nums: List[int]) -> int:
		ops = 0
		arr = np.array(nums)
		while np.sum(arr) != 0:
			inds = np.where(arr % 2 == 1)[0]
			ops += len(inds)
			arr[inds] -= 1
			if np.sum(arr) != 0:
				arr = arr / 2
				ops += 1
		return ops


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		ans = 0
		shift = 0
		for k in nums:
			strk = bin(k)[2:]
			ans += strk.count('1')
			shift = max(shift, len(strk) - 1)
		return ans + shift


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		res = 0
		mul_max = 0
		for x in nums:
			if x == 0:
				continue
			x_bin = bin(x)
			mul = -1
			for i in x_bin[2:]:
				if i == '1':
					res += 1
				mul += 1
			if mul > mul_max:
				mul_max = mul
		return res + mul_max


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		num_set_bits = 0
		max_bit_len = 0
		for n in nums:
			num_set_bits += bin(n).count('1')
			max_bit_len = max(max_bit_len, len(bin(n)) - 2)
		return num_set_bits + max_bit_len - 1


from math import log2 as l

class Solution:

	def minOperations(self, nums: List[int]) -> int:
		cnt = 0
		mx = max(nums)
		if mx & 1 and mx != 1:
			mx -= 1
		for x in nums:
			while x:
				if x & 1:
					cnt += 1
				x //= 2
		return int(l(mx)) + cnt


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		s = 0
		b = 0
		for n in nums:
			b += (f := f'{n:b}').count('1')
			s = max(s, len(f))
		return s - 1 + b


class Solution:

	def minOperations(self, nums):
		result = 0
		max_value = 0
		for n in nums:
			max_value = max(max_value, n)
			while n:
				if n & 1:
					result += 1
				n = n >> 1
		if not max_value:
			return 0
		while max_value:
			result += 1
			max_value = max_value >> 1
		return result - 1


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		ones = 0
		maxLength = 0
		for x in nums:
			x = bin(x)[2:]
			maxLength = max(maxLength, len(x))
			ones += x.count('1')
		print((ones, maxLength - 1))
		return ones + maxLength - 1


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		highest_bit = one_bit = 0
		for i in range(32):
			for num in nums:
				if num & 1 << i:
					highest_bit = i
					one_bit += 1
		return highest_bit + one_bit


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		cnt = 0
		maxLen = 0
		for num in nums:
			num_bin = bin(num)[2:]
			cnt += sum(map(int, num_bin))
			maxLen = max(maxLen, len(num_bin))
		return cnt + maxLen - 1


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		to_ret = 0
		max_len = 0
		for t in nums:
			st = bin(t)[2:]
			max_len = max(max_len, len(st))
			to_ret += sum(map(int, st))
		return to_ret + max_len - 1


class Solution:

	def minOperations(self, nums: List[int]) -> int:
		twos = len(bin(max(nums))[2:]) - 1
		ones = collections.Counter(''.join((bin(i)[2:] for i in nums)))['1']
		return ones + twos


class Solution:

	def minOperations(self, nums: List[int]) -> int:

		def check(num):
			divisions = inc = 0
			while num:
				if num % 2:
					inc += 1
				divisions += 1
				num //= 2
			return (divisions, inc)
		res = 0
		m = 1
		for n in nums:
			(d, r) = check(n)
			m = max(m, d)
			res += r
		return res + m - 1