Untitled
unknown
python
3 years ago
781 B
9
Indexable
n = int(input())
arr = []
for i in range(n):
arr.append(int(input()))
def powerset(s):
subsets = []
x = len(s)
for i in range(1 << x):
subsets.append([s[j] for j in range(x) if (i & (1 << j))])
return subsets
def most_frequent_bit(arr):
# count the frequency of each bit in the array
bit_counts = [0] * 32
for num in arr:
for i in range(32):
bit_counts[i] += (num >> i) & 1
# find the bit with the highest frequency
max_bit_count = max(bit_counts)
max_bit_index = bit_counts.index(max_bit_count)
# return the frequency of the most frequent bit
return max_bit_count
alls = powerset(arr)
ans = 0
for i in alls:
# print(i, most_frequent_bit(i))
ans += most_frequent_bit(i)
print(ans)Editor is loading...