local ffi = require 'ffi' local C, ct = ffi.C, ffi.typeof 'int64_t[1]' ffi.cdef [[ int printf(const char *, ...); int scanf(const char *, ...); ]] C.printf("%ld\n", (function (n) C.scanf("%ld",n) local a,b,c=n[0],n[0],n[0]*2 while a~=0 do local t=a/2 a,b,c=t,b+t,(2*t+a>c and 2*t+a or c) end return c-b>=0 and c-b or b-c end)(ct()))