ids = [] with open('input.txt') as fh: for line in fh: ids.append(int( line.strip()\ .replace('F', '0')\ .replace('B', '1')\ .replace('L', '0')\ .replace('R', '1'), 2 )) print(max(ids)) state = 0b000 for i in range(2 << 10): state = (state >> 1) | ((i in ids) << 2) if state == 0b101: print(i - 1)