def reader(inFile):
return tuple(inFile.getInts())
def solver((N, p)):
wins = [(((p - 1) >> i) & 1) == 0 for i in xrange(N)][::-1]
a1 = 0
for win in wins:
if not win:
a1 += 1
else:
break
a1 = ((1 << (a1 + 1)) - 2) if (a1 < N) else ((1 << N) - 1)
a2 = 0
for win in wins:
if win:
a2 += 1
else:
break
if (a2 == len([win for win in wins if win])):
a2 -= 1
a2 = (1 << N) - (1 << (a2 + 1))
return "%d %d" % (a1, a2)
if __name__ == "__main__":
from GCJ import GCJ
GCJ(reader, solver, "/Users/lpebody/gcj/2013_2/b/", "b").run()
ZGVmIHJlYWRlcihpbkZpbGUpOgogICAgcmV0dXJuIHR1cGxlKGluRmlsZS5nZXRJbnRzKCkpCgpkZWYgc29sdmVyKChOLCBwKSk6CiAgICB3aW5zID0gWygoKHAgLSAxKSA+PiBpKSAmIDEpID09IDAgZm9yIGkgaW4geHJhbmdlKE4pXVs6Oi0xXQogICAgYTEgPSAwCiAgICBmb3Igd2luIGluIHdpbnM6CiAgICAgICAgaWYgbm90IHdpbjoKICAgICAgICAgICAgYTEgKz0gMQogICAgICAgIGVsc2U6CiAgICAgICAgICAgIGJyZWFrCiAgICBhMSA9ICgoMSA8PCAoYTEgKyAxKSkgLSAyKSBpZiAoYTEgPCBOKSBlbHNlICgoMSA8PCBOKSAtIDEpCiAgICBhMiA9IDAKICAgIGZvciB3aW4gaW4gd2luczoKICAgICAgICBpZiB3aW46CiAgICAgICAgICAgIGEyICs9IDEKICAgICAgICBlbHNlOgogICAgICAgICAgICBicmVhawogICAgaWYgKGEyID09IGxlbihbd2luIGZvciB3aW4gaW4gd2lucyBpZiB3aW5dKSk6CiAgICAgICAgYTIgLT0gMQogICAgYTIgPSAoMSA8PCBOKSAtICgxIDw8IChhMiArIDEpKQogICAgcmV0dXJuICIlZCAlZCIgJSAoYTEsIGEyKQoKaWYgX19uYW1lX18gPT0gIl9fbWFpbl9fIjoKICAgIGZyb20gR0NKIGltcG9ydCBHQ0oKICAgIEdDSihyZWFkZXIsIHNvbHZlciwgIi9Vc2Vycy9scGVib2R5L2djai8yMDEzXzIvYi8iLCAiYiIpLnJ1bigpCg==