f = open ('input3.txt', 'r') inp = f.readlines() ones = [0] * 12 zeroes = [0] * 12 gamma = 0 epsilon = 0 for i in range(len(inp)): inp[i] = inp[i].strip() for line in inp: for i in range(len(line)): if line[i] == '1': ones[i] += 1 if line[i] == '0': zeroes[i] += 1 for i in range(len(ones)): if ones[i] < zeroes[i]: gamma <<= 1 epsilon = (epsilon << 1) + 1 else: gamma = (gamma << 1) + 1 epsilon <<= 1 print(epsilon * gamma) print(gamma) print(epsilon)