Problem:


Score: 300 points

Problem Statement

As AtCoder Beginner Contest 100 is taking place, the office of AtCoder, Inc. is decorated with a sequence of length N, a = {a_1, a_2, a_3, ..., a_N}.

Snuke, an employee, would like to play with this sequence.

Specifically, he would like to repeat the following operation as many times as possible:

For every i satisfying 1 \leq i \leq N, perform one of the following: "divide a_i by 2" and "multiply a_i by 3".  
Here, choosing "multiply a_i by 3" for every i is not allowed, and the value of a_i after the operation must be an integer.

At most how many operations can be performed?

Constraints

N is an integer between 1 and 10 \ 000 (inclusive).

a_i is an integer between 1 and 1 \ 000 \ 000 \ 000 (inclusive).

Input

Input is given from Standard Input in the following format:

N
a_1 a_2 a_3 ... a_N

Output

Print the maximum number of operations that Snuke can perform.

Sample Input 1

3
5 2 4

Sample Output 1

3

The sequence is initially {5, 2, 4}. Three operations can be performed as follows:

First, multiply a_1 by 3, multiply a_2 by 3 and divide a_3 by 2. The sequence is now {15, 6, 2}.

Next, multiply a_1 by 3, divide a_2 by 2 and multiply a_3 by 3. The sequence is now {45, 3, 6}.

Finally, multiply a_1 by 3, multiply a_2 by 3 and divide a_3 by 2. The sequence is now {135, 9, 3}.

Sample Input 2

4
631 577 243 199

Sample Output 2

0

No operation can be performed since all the elements are odd. Thus, the answer is 0.

Sample Input 3

10
2184 2126 1721 1800 1024 2528 3360 1945 1280 1776

Sample Output 3

39



Sample input:
3
5 2 4


Sample output:
3

Submission status: Time Limit Exceeded

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N = INT()
a = LIST()
count = 0
flag = 0
while flag == 0:	
	for i in range(N):
		if a[i] % (1024**2) == 0:
			a[i] /= (1024**2)
			count += 20
			break
	else:
		flag = 1
flag = 0
while flag == 0:	
	for i in range(N):
		if a[i] % 2 == 0:
			a[i] /= 2
			count += 1
			break
	else:
		flag = 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N = INT()
a = LIST()
count = 0
flag = 0
while flag == 0:	
	for i in range(N):
		if a[i] % 1024 == 0:
			a[i] /= 1024
			count += 10
			break
	else:
		flag = 1
flag = 0
while flag == 0:	
	for i in range(N):
		if a[i] % 2 == 0:
			a[i] /= 2
			count += 1
			break
	else:
		flag = 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N = INT()
a = LIST()
count = 0
flag = 0
while flag == 0:	
	for i in range(N):
		if a[i] % 32 == 0:
			a[i] /= 32
			count += 5
			break
	else:
		flag = 1
flag = 0
while flag == 0:	
	for i in range(N):
		if a[i] % 2 == 0:
			a[i] /= 2
			count += 1
			break
	else:
		flag = 1	
print(count)

Submission status: Time Limit Exceeded

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N = INT()
a = LIST()
count = 0
flag = 0
while flag == 0:	
	for i in range(len(a)):
		if a[i] % 2 == 0:
			a[i] /= 2
			count += 1
			break
	else:
		flag = 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-

n = int(input())
a = list(map(int,input().split()))
af = [[]]

def factorize(n):
    b = 2
    fct = []
    while b * b <= n:
        while n % b == 0:
            n //= b
            fct.append(b)
        b = b + 1
    if n > 1:
        fct.append(n)
    return fct

for i in range(n):
    af.append(factorize(a[i]))
del af[0]

cnt = 0

for i in range(len(af)):
    for j in range(len(af[i])):
        if af[i][j] == 2:
            cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())

def prime_factors(n):
  i = 2
  factors = []
  while i * i <= n:
    if n % i==0:
      n //= i
      factors.append(i)
    else:
      i += 1
  if n > 1:
    factors.append(n)
  return factors
A=list(map(lambda x:prime_factors(x).count(2) if x%2==0 else 0,list(map(int,input().split()))))
print(sum(A))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
b = 1
for i in range(n):
    b = b * a[i]
count = 0
while (b % 2 == 0):
    count += 1
    b = b // 2
print(count)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N=int(input())
a=list(map(int,input().split()))
b=np.prod(a,dtype='int64')
count=0
while b%2==0:
    b/=2
    count+=1
print(count)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N=int(input())
a=list(map(int,input().split()))
b=np.prod(a,dtype='int64')
count=0
while b%2==0:
    if b%2==1:
        break
    b/=2
    count+=1
print(count)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

def prime_decomposition(n):
	i=2
	table=[]
	while i*i <= n:
		while n%i == 0:
			n /= i
			table.append(i)
		i += 1
	if n > 1:
		table.append(n)
	return table

n=int(input())
a=list(map(int,input().split()))
ans_table = []
for i in a:
	ans_table.extend(prime_decomposition(i))
print(Counter(ans_table)[2])

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
import math
import random


class Prime:
    seed_primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97]

    def is_prime(self, n):
        """
        prime test (hybrid)

        see also: https://qiita.com/gushwell/items/ff9ed83ba55350aaa369

        :param n:
        :return: boolean
        """
        is_prime_common = self.is_prime_common(n)
        if is_prime_common is not None:
            return is_prime_common

        if n < 2000000:
            return self.is_prime_brute_force(n)
        else:
            return self.is_prime_miller_rabin(n)

    def is_prime_common(self, n):
        if n == 1: return False
        if n in Prime.seed_primes: return True
        if any(map(lambda x: n % x == 0, self.seed_primes)): return False

    def is_prime_brute_force(self, n):
        """
        brute force prime test
        use with is_prime_common if you want to skip seed_primes

        :param n:
        :return: boolean
        """
        for k in range(2, int(math.sqrt(n)) + 1):
            if n % k == 0:
                return False
        return True

    def is_prime_miller_rabin(self, n):
        """
        miller rabin prime test
        use with is_prime_common if you want to skip seed_primes

        see also
            algorithm: https://en.wikipedia.org/wiki/Miller%E2%80%93Rabin_primality_test
            implementation: https://qiita.com/srtk86/items/609737d50c9ef5f5dc59
            improvement: https://qiita.com/gushwell/items/ff9ed83ba55350aaa369

        :param n:
        :return: boolean
        """

        d = n - 1
        while d & 1 == 0:
            d >>= 1

        # use one of these lines / upper is more efficient.
        witnesses = self.get_witnesses(n)
        # witnesses = [random.randint(1, n - 1) for _ in range(100)]

        for w in witnesses:
            y = pow(w, d, n)

            while d != n - 1 and y != 1 and y != n - 1:
                y = (y * y) % n
                d <<= 1

            if y != n - 1 and d & 1 == 0:
                return False

        return True

    def get_witnesses(self, num):
        def _get_range(num):
            if num < 2047:
                return 1
            if num < 1373653:
                return 2
            if num < 25326001:
                return 3
            if num < 3215031751:
                return 4
            if num < 2152302898747:
                return 5
            if num < 3474749660383:
                return 6
            if num < 341550071728321:
                return 7
            if num < 3825123056546413051:
                return 9
            return 12

        return self.seed_primes[:_get_range(num)]

    def gcd(self, a, b):
        if a < b:
            return self.gcd(b, a)
        if b == 0:
            return a
        while b:
            a, b = b, a % b
        return a

    @staticmethod
    def f(x, n, seed):
        """
        pseudo prime generator
        :param x:
        :param n:
        :param seed:
        :return: pseudo prime
        """
        p = Prime.seed_primes[seed % len(Prime.seed_primes)]
        return (p * x + seed) % n

    def find_factor(self, n, seed=1):
        """
        find one of factor of n
        this function is based to Pollard's rho algorithm

        see also
            algorithm: https://en.wikipedia.org/wiki/Pollard%27s_rho_algorithm
            implementation: https://qiita.com/gushwell/items/561afde2e00bf3380c98

        :param n:
        :param seed:
        :return: factor
        """
        if self.is_prime(n):
            return n

        x, y, d = 2, 2, 1
        count = 0
        while d == 1:
            count += 1
            x = self.f(x, n, seed)
            y = self.f(self.f(y, n, seed), n, seed)
            d = self.gcd(abs(x - y), n)

        if d == n:
            return self.find_factor(n, seed+1)
        return self.find_factor(d)

    def find_factors(self, n):
        primes = {}
        if self.is_prime(n):
            primes[n] = 1
            return primes

        while n > 1:
            factor = self.find_factor(n)

            primes.setdefault(factor, 0)
            primes[factor] += 1

            n //= factor

        return primes
N = int(input())
A = tuple(map(int,input().split()))
prime = Prime()

n2= 0
n2= 0
for num in A:
    d = prime.find_factors(num)
    if 2 in d.keys():
        n2+= d[2]
else:
    print(n2)

Submission status: Time Limit Exceeded

Solution code:
import math
import random


class Prime:
    seed_primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97]

    def is_prime(self, n):
        """
        prime test (hybrid)

        see also: https://qiita.com/gushwell/items/ff9ed83ba55350aaa369

        :param n:
        :return: boolean
        """
        is_prime_common = self.is_prime_common(n)
        if is_prime_common is not None:
            return is_prime_common

        if n < 2000000:
            return self.is_prime_brute_force(n)
        else:
            return self.is_prime_miller_rabin(n)

    def is_prime_common(self, n):
        if n == 1: return False
        if n in Prime.seed_primes: return True
        if any(map(lambda x: n % x == 0, self.seed_primes)): return False

    def is_prime_brute_force(self, n):
        """
        brute force prime test
        use with is_prime_common if you want to skip seed_primes

        :param n:
        :return: boolean
        """
        for k in range(2, int(math.sqrt(n)) + 1):
            if n % k == 0:
                return False
        return True

    def is_prime_miller_rabin(self, n):
        """
        miller rabin prime test
        use with is_prime_common if you want to skip seed_primes

        see also
            algorithm: https://en.wikipedia.org/wiki/Miller%E2%80%93Rabin_primality_test
            implementation: https://qiita.com/srtk86/items/609737d50c9ef5f5dc59
            improvement: https://qiita.com/gushwell/items/ff9ed83ba55350aaa369

        :param n:
        :return: boolean
        """

        d = n - 1
        while d & 1 == 0:
            d >>= 1

        # use one of these lines / upper is more efficient.
        witnesses = self.get_witnesses(n)
        # witnesses = [random.randint(1, n - 1) for _ in range(100)]

        for w in witnesses:
            y = pow(w, d, n)

            while d != n - 1 and y != 1 and y != n - 1:
                y = (y * y) % n
                d <<= 1

            if y != n - 1 and d & 1 == 0:
                return False

        return True

    def get_witnesses(self, num):
        def _get_range(num):
            if num < 2047:
                return 1
            if num < 1373653:
                return 2
            if num < 25326001:
                return 3
            if num < 3215031751:
                return 4
            if num < 2152302898747:
                return 5
            if num < 3474749660383:
                return 6
            if num < 341550071728321:
                return 7
            if num < 3825123056546413051:
                return 9
            return 12

        return self.seed_primes[:_get_range(num)]

    def gcd(self, a, b):
        if a < b:
            return self.gcd(b, a)
        if b == 0:
            return a
        while b:
            a, b = b, a % b
        return a

    @staticmethod
    def f(x, n, seed):
        """
        pseudo prime generator
        :param x:
        :param n:
        :param seed:
        :return: pseudo prime
        """
        p = Prime.seed_primes[seed % len(Prime.seed_primes)]
        return (p * x + seed) % n

    def find_factor(self, n, seed=1):
        """
        find one of factor of n
        this function is based to Pollard's rho algorithm

        see also
            algorithm: https://en.wikipedia.org/wiki/Pollard%27s_rho_algorithm
            implementation: https://qiita.com/gushwell/items/561afde2e00bf3380c98

        :param n:
        :param seed:
        :return: factor
        """
        if self.is_prime(n):
            return n

        x, y, d = 2, 2, 1
        count = 0
        while d == 1:
            count += 1
            x = self.f(x, n, seed)
            y = self.f(self.f(y, n, seed), n, seed)
            d = self.gcd(abs(x - y), n)

        if d == n:
            return self.find_factor(n, seed+1)
        return self.find_factor(d)

    def find_factors(self, n):
        primes = {}
        if self.is_prime(n):
            primes[n] = 1
            return primes

        while n > 1:
            factor = self.find_factor(n)

            primes.setdefault(factor, 0)
            primes[factor] += 1

            n //= factor

        return primes
N = int(input())
A = tuple(map(int,input().split()))
prime = Prime()
from collections import Counter
a = {}

def merge_dict_add_values(d1, d2):
    return dict(Counter(d1) + Counter(d2))

for num in A:
    a = merge_dict_add_values(a,prime.find_factors(num))
if 2 in a.keys():
    print(a[2])
else:
    print(0)

Submission status: Time Limit Exceeded

Solution code:
import operator as o
import functools as f
n,*a=map(int,open(0).read().split())
#print(f.reduce(o.mul,a))
x=f.reduce(o.mul,a)
count=0
while True:
    if x%2==0:
        x=x//2
        count+=1
    else:
        break
print(count)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=sorted([int(i) for i in input().split()])
cnt=0
while True:
    odd=[i for i in a if i%2==1]
    even=[i for i in a if i%2==0]
    if len(even)==0:
        break
    maxi=even[-1]
    even=[i*3 for i in even[0:-1]]
    even.append(maxi//2)
    a=odd+even
    cnt+=1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = sorted(list(map(int,input().split())),reverse=True)
count = 0
while True:
    cnt = 0
    ccnt = 0
    done = 0
    for i in range(n):
        if a[i] % 2 == 0:
            if done == 0:
                a[i] = a[i] // 2
                cnt += 1
                done += 1
            else:
                a[i] = a[i] * 3
                ccnt += 1
        else:
            a[i] = a[i] * 3
            ccnt += 1
    if cnt  == 0:
        break
    else:
        count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A=list(map(int,input().split()))
a_multiply=1
for i in range(N):
      a_multiply=a_multiply*A[i]
i=0
while a_multiply%2==0:
      i=i+1
      a_multiply=a_multiply//2
print(i)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
aList = [int(x) for x in input().split()]

# 2で割るor3倍にする
# 全部3倍はダメで、操作後は整数でないとダメ。

en = aList
count = 0
while True:
    cache = []
    for x in en:
        if x % 2 == 0:
            if len(cache) > 0:
                cache.append(int(3*x))
            else:
                cache.append(x // 2)

    if len(cache) > 0:
        count += 1
    else:
        break
    en = cache

print(count)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=[int(i) for i in input().split()]
count=0
for ai in a:
    if ai%2==0:
        while ai!=1:
            ai/=2
            count+=1
print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)
ans = 0

while any(A[i] % 2 == 0 for i in range(n)):
    count = 0
    for i in range(n):
        if A[i] % 2 == 0:
            if count == 0:
                A[i] = A[i] // 2
                count += 1
            else:
                A[i] = A[i] * 3
        else:
            A[i] = A[i] * 3
    A.sort(reverse=True)
    ans += 1
        
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
array =[]
for line in sys.stdin.readlines():
    array.append(line.rstrip())
box =list()
for i in range(int(array[0])):
    box.append(int(array[1].split(" ")[i]))
count =0
for j in range(int(array[0])):
    while(True):
        if box[j]%2==0:
            count+=1
            box[j]=box[j]//2
        else:
            break;
print(count)

Submission status: Time Limit Exceeded

Solution code:
import sys
array =[]
for line in sys.stdin.readlines():
    array.append(line.rstrip())
num1 = array[0]
num2 = array[1]
box =list()
for i in range(int(num1)):
    box.append(int(num2.split(" ")[i]))
count =0
for j in range(len(box)):
    while(True):
        if box[j]%2==0:
            count+=1
            box[j]=box[j]//2
        else:
            break;
print(count)

Submission status: Time Limit Exceeded

Solution code:
import sys
array =[]
for line in sys.stdin.readlines():
    array.append(line.rstrip())
num1 = array[0]
box =list()
num2 = array[1]
for i in range(0,len(num2.split(" "))) :
    box.append(int(num2.split(" ")[i]))
count =0
for j in range(len(box)):
    while(True):
        if box[j]%2==0:
            count+=1
            box[j]=box[j]//2
        else:
            break;
print(count)

Submission status: Time Limit Exceeded

Solution code:
from functools import reduce
_ = input()
even = reduce(lambda x, y: x * y, list(map(int, input().split())))
i = 0
while even % 2 == 0:
    i = i + 1
    even = even // 2
print(i)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int, input().split()))
b = []
for i in range(n):
  if a[i] % 2 == 0:
    b.append(a[i])
a = b
count = 0
while True:
  if len(a) == 0:
    break
  i = a.index(max(a))
  a[i] /= 2
  count += 1
  if a[i] % 2 == 1:
    a.remove(a[i])
print(count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))

s = 1
for i in range(N):
	s = s * A[i]

ans = 0
while s % 2 == 0:
	s = s // 2
	ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
an = list(map(int, input().split()))

cnt = 0
while(1):
    an.sort(reverse=True)
    isAnyEven = False
    for x in an:
        if x%2==0:
            isAnyEven = True
            break
    if isAnyEven == False:
        break
    maxEven = False
    for i in range(n):
        if maxEven == False and an[i] % 2 == 0:
            an[i] = an[i]//2
            maxEven = True
        else:
            an[i] = an[i]*3
    cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
def findEvenIndex(data):
    maxeven = 0
    if len(data) == 0:
        return -1
    for i in range(len(data)):
        if data[i]%2==0:
            if maxeven < data[i]:
                maxeven = data[i]
    if maxeven == 0:#no even data
        return -1
    else:
        return data.index(maxeven)

n = int(input())
an = list(map(int, input().split()))
cnt = 0
while(1):
    maxEvenIdx = findEvenIndex(an)
    if maxEvenIdx == -1:
        break
    for i in range(len(an)):
        if i == maxEvenIdx:
            an[i] = an[i]//2
        else:
            an[i] = an[i]*3
    cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
lis = list(map(int,input().split()))
num = 0
for i in range(n):
  while lis[i] % 2 == 0:
    num += 1
    lis[i] // 2
print(num)

Submission status: Time Limit Exceeded

Solution code:
def prime(n): # nまでの素数を列挙
    import math
    if n == 1:
        return []
    else:
        num_list = [i + 1 for i in range(2,n,2)]
        list_prime = [2]
        limit = math.sqrt(n)
        if n == 2:
            return list_prime
        else:
            while True:
                p = num_list[0]
                if p >= limit:
                    return list_prime + num_list
                list_prime.append(p)
                num_list = [num for num in num_list if num % p != 0]


def primeFactorization(n):
    import math
    if n == 1:
        return {}
    else:
        list_prime = prime(int(math.sqrt(n)))
        i = 0
        dict_pF = {}
        dict_primeFactorization = {}
        for pri in list_prime:
            dict_pF[pri] = 0
        while True:
            if n == 1:
                for key, value in dict_pF.items():
                    if value != 0:
                        dict_primeFactorization[key] = value
                return dict_primeFactorization
            elif i >= len(list_prime):
                dict_pF[n] = 1
                for key, value in dict_pF.items():
                    if value != 0:
                        dict_primeFactorization[key] = value
                return dict_primeFactorization
            p = list_prime[i]
            if n % p == 0:
                n //= p
                dict_pF[p] += 1
                continue
            else:
                i += 1

n = int(input())
list_a = list((map(int, input().split())))

ans = 0
for number in list_a:
    try:
        ans += primeFactorization(number)[2]
    except:
        pass

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a = list(map(int,input().split()))

a.sort()
a.reverse()

i=0
count=0

while True:
    if a[i]%2 == 0:
        a[i] = a[i]/2
        i=0
        count += 1
    else:
        if i == len(a) - 1:
            break
        i += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a = list(map(int,input().split()))

cnt = 0
while True:
    flg = False
    for i in range(N):
        if a[i] % 2 == 0:
            a[i] /= 2
            break
        elif i == N - 1:
            print(cnt)
            flg = True
    if flg == True:
        break

    cnt += 1

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a = list(map(int,input().split()))

cnt = 0
while True:
    g =-1
    for i in range(N):
        if a[i] % 2 == 0:
            g = i
            break
        elif i == N - 1:
            print(cnt)

    if g == -1:
        break

    for i in range(N):
        if g == i:
            a[i] /= 2
    cnt += 1

Submission status: Time Limit Exceeded

Solution code:
def getinputdata():

    array_result = []    
    array_result.append(input().split(" "))

    flg = True

    try:
        while flg:

            data = input()

            if(data != ""):
                
                array_result.append(data.split(" "))

                flg = True

            else:

                flg = False
    finally:

        return array_result

arr_data = getinputdata()

n= int(arr_data[0][0])

arr=[int(arr_data[1][x]) for x in range(n)]

arr = [i for i in arr if i % 2==0]

cnt=0

while len(arr)>0:
    
    if any(x % 4 == 0 for x in arr):

        val=max(list(filter(lambda x : x%4 ==0, arr)))        
        idx=arr.index(val)

        arr=[x*3 for x in arr]
        arr[idx]//=6
        cnt+=1

#    elif any(x % 2 == 0 for x in arr):
    else:
        cnt+=len(arr)
        break

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
def getinputdata():

    array_result = []    
    array_result.append(input().split(" "))

    flg = True

    try:
        while flg:

            data = input()

            if(data != ""):
                
                array_result.append(data.split(" "))

                flg = True

            else:

                flg = False
    finally:

        return array_result

arr_data = getinputdata()

n= int(arr_data[0][0])

arr=[int(arr_data[1][x]) for x in range(n)]

arr = [i for i in arr if i % 2==0]

cnt=0

#1つでも偶数が存在する場合　trueでループ処理対象
#奇数は処理対象外にしてもよい

while len(arr)>0:
    
    if any(x % 4 == 0 for x in arr):

        val=max(list(filter(lambda x : x%4 ==0, arr)))        
        idx=arr.index(val)

        #奇数は計算しなくて良い計算するだけ無駄
        arr=[x*3 for x in arr]
        arr[idx]//=6
    
    elif any(x % 2 == 0 for x in arr):
    
        val=max(list(filter(lambda x : x%2 ==0, arr)))        
        idx=arr.index(val)
        
        #奇数は計算しなくて良い計算するだけ無駄
        arr=[x*3 for x in arr]
        arr.pop(idx)
    cnt+=1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
def getinputdata():

    array_result = []    
    array_result.append(input().split(" "))

    flg = True

    try:
        while flg:

            data = input()

            if(data != ""):
                
                array_result.append(data.split(" "))

                flg = True

            else:

                flg = False
    finally:

        return array_result

arr_data = getinputdata()

n= int(arr_data[0][0])

arr=[int(arr_data[1][x]) for x in range(n)]

arr = [i for i in arr if i % 2==0]

cnt=0

#1つでも偶数が存在する場合　trueでループ処理対象
#奇数は処理対象外にしてもよい

while len(arr)>0:
    
    if any(x % 4 == 0 for x in arr):

        val=max(list(filter(lambda x : x%4 ==0, arr)))        
        idx=arr.index(val)

        #奇数は計算しなくて良い計算するだけ無駄
        arr=[x*3 for x in arr]
        arr[idx]//=6
    
    elif any(x % 2 == 0 for x in arr):
    
        val=max(list(filter(lambda x : x%2 ==0, arr)))        
        idx=arr.index(val)
        
        #奇数は計算しなくて良い計算するだけ無駄
        arr=[x*3 for x in arr]
        arr[idx]//=6

    arr = [i for i in arr if i % 2==0]
    cnt+=1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
def getinputdata():

    array_result = []    
    array_result.append(input().split(" "))

    flg = True

    try:
        while flg:

            data = input()

            if(data != ""):
                
                array_result.append(data.split(" "))

                flg = True

            else:

                flg = False
    finally:

        return array_result

arr_data = getinputdata()

n= int(arr_data[0][0])

arr=[int(arr_data[1][x]) for x in range(n)]

cnt=0

while any(x % 2 == 0 for x in arr):

    if any(x % 4 == 0 for x in arr):

        val=max(list(filter(lambda x : x%4 ==0, arr)))        
        idx=arr.index(val)
        
        arr=[x*3 for x in arr]
        arr[idx]//=6
               
        cnt+=1
    
    elif any(x % 2 == 0 for x in arr):
    
        val=max(list(filter(lambda x : x%2 ==0, arr)))        
        idx=arr.index(val)
        
        arr=[x*3 for x in arr]
        arr[idx]//=6
        
        cnt+=1
    
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
def getinputdata():

    array_result = []    
    array_result.append(input().split(" "))

    flg = True

    try:
        while flg:

            data = input()

            if(data != ""):
                
                array_result.append(data.split(" "))

                flg = True

            else:

                flg = False
    finally:

        return array_result

arr_data = getinputdata()

n= int(arr_data[0][0])

arr=[int(arr_data[1][x]) for x in range(n)]

cnt=0
chkflg=True

while chkflg:

    if any(x % 4 == 0 for x in arr):

        val=max(list(filter(lambda x : x%4 ==0, arr)))        
        idx=arr.index(val)
        
        arr=[x*3 for x in arr]
        arr[idx]//=6
               
        cnt+=1
    
    elif any(x % 2 == 0 for x in arr):
    
        val=max(list(filter(lambda x : x%2 ==0, arr)))        
        idx=arr.index(val)
        
        arr=[x*3 for x in arr]
        arr[idx]//=6
        
        cnt+=1
    
    else:
        chkflg=False
        
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
def getinputdata():

    array_result = []    
    array_result.append(input().split(" "))

    flg = True

    try:
        while flg:

            data = input()

            if(data != ""):
                
                array_result.append(data.split(" "))

                flg = True

            else:

                flg = False
    finally:

        return array_result

arr_data = getinputdata()

n= int(arr_data[0][0])

arr=[int(arr_data[1][x]) for x in range(n)]

cnt=0
chkflg=True

while chkflg:

    if any(x % 4 == 0 for x in arr):

        val=max(list(filter(lambda x : x%4 ==0, arr)))        
        idx=arr.index(val)
        
        for i in range(n):
            
            if i==idx:
                arr[i]//=2                
            else:
                arr[i]*=3
        
        cnt+=1
    
    elif any(x % 2 == 0 for x in arr):
    
        val=max(list(filter(lambda x : x%2 ==0, arr)))        
        idx=arr.index(val)
        
        for i in range(n):
            
            if i==idx:
                arr[i]//=2                
            else:
                arr[i]*=3
        
        cnt+=1
    
    
    else:
        chkflg=False
        
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
from functools import reduce

def count_two(n):
	two_count = 0
	while n != 0 and n % 2 == 0:
		two_count += 1
		n //= 2
	return two_count

n = int(input())
a = map(int, input().split())
a_product = reduce(lambda x, y: x*y, a)
print(count_two(a_product))