-
Notifications
You must be signed in to change notification settings - Fork 179
/
binary.py
36 lines (29 loc) · 900 Bytes
/
binary.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
from itertools import combinations
def binary():
Bin_Dict = {}
for i in numbers:
Bin_Dict[i] = bin(i)[2:].count('1')
return Bin_Dict
def c():
count = 0
for i in range(1,len(numbers)+1):
for j in combinations(numbers,i):
number_of_ones = 0
number_of_zeros = 0
for elm in j:
number_of_ones += Bin_Dict[elm]
number_of_zeros += lar_bit-Bin_Dict[elm]
if number_of_ones == number_of_zeros:
count += 1
return count
if __name__ == '__main__':
N = int(input())
numbers = list(map(int,input().split()))
lar = max(numbers)
lar_bit = len(bin(lar)[2:]) #print upto places
Bin_Dict = binary()
ans = c()
bin_ans = bin(ans)[2:]
if len(bin_ans) != lar_bit:
bin_ans = '0'*(lar_bit-len(bin_ans))+bin_ans
print(bin_ans)