class BearPlays():
def pileSize(self, a, b, k):
lol = a*pow(2, k, a+b)
lol %= (a+b)
return min(lol, a+b-lol)
Y2xhc3MgQmVhclBsYXlzKCk6CiAgICBkZWYgcGlsZVNpemUoc2VsZiwgYSwgYiwgayk6CiAgICAgICAgbG9sID0gYSpwb3coMiwgaywgYStiKQogICAgICAgIGxvbCAlPSAoYStiKQogICAgICAgIHJldHVybiBtaW4obG9sLCBhK2ItbG9sKQ==