a.py (501B) [raw]
1 #!/usr/bin/env python3 2 import sys 3 4 # First get the counts of bit by position 5 counts = [] 6 first = True 7 for l in sys.stdin: 8 i = 0 9 for c in l.strip(): 10 if first: 11 counts.append([0, 0]) 12 counts[i][int(c)] += 1 13 i += 1 14 15 first = False 16 17 # Then build up the binary string summaries 18 gamma = "" 19 eps = "" 20 for c in counts: 21 if c[0] > c[1]: 22 gamma += "0" 23 eps += "1" 24 else: 25 gamma += "1" 26 eps += "0" 27 28 print(int(gamma, 2) * int(eps, 2))