in_file = open("DATA3.txt")
out_file = open("OUT3.txt", "w")

for line in in_file:
    line = int(line.rstrip())
    binary = bin(line)[2:]
    weight = binary.count("1")
    found = False
    num = line+1
    while not found:
        it_binary = bin(num)[2:]
        it_count = it_binary.count("1")
        if it_count == weight:
            out = num
            found = True
        else:
            num += 1
   
    out_file.write(str(out) + "\n")
           
in_file.close()
out_file.close()
