print((function (f) local a,b,c = f() while a~=0 do a,b,c = a/2,b+a/2,a+a>c and a+a or c end return tonumber(b-c<0 and c-b or b-c) end)((function (ffi) ffi.cdef 'int scanf(const char *, ...);' local C,c = ffi.C,ffi.new("long[1]") return function () C.scanf("%ld",c) return c[0],c[0],c[0] end end)(require'ffi')))