A. Placing Marbles … Count “1” in the input string

1 |
print(input().count("1")) |

B. Shift Only … Add the result into the temporary list if the number modulo 2 is 0. In each iteration of the list, compare the length of the original list and temporary list.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
n = int(input()) a = list(map(int, input().split())) result = 0 while True: temp_a = [] for num in a: if num%2 == 0: temp_a.append(num//2) if len(temp_a) != n: break a = temp_a result += 1 print(result) |

C. Not So Diverse … In python, there is a Counter function which can create a dictionary from a list. In this case, take a list of numbers, and make a dictionary which has “number” as a key, and “times of the number appears in the list” as a value.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
n = int(input()) a = list(map(int, input().split())) result = 0 while True: temp_a = [] for num in a: if num%2 == 0: temp_a.append(num//2) if len(temp_a) != n: break a = temp_a result += 1 print(result) |