M={}\x0d def f(x,y,z):\x0d y,z=y-x,z-x\x0d R=M[(0,y,z)]=M.get((0,y,z))or f(f(-5,y,z),f(y-5,z,0),f(z-5,0,y))if 0>y else z\x0d return x+R\x0d while 1:print f(*[int(n) for n in raw_input().split()])
Note that non-ascii characters in the above source code will be escaped (such as \x9f).