local ffi = require 'ffi' local C = ffi.C ffi.cdef [[ long atol(const char *); int printf(const char *, ...); ]] C.printf("%ld\n", (function (f, s) return f(s) end)(function (s) local a,b,c = s:match("(%d+)%s(%d+)%s(%d+)") a,b,c = C.atol(a),C.atol(b),C.atol(c) if a > c then return c end local d = a-1LL+b return c/d*a + (c%d < a and c%d or a) end, io.stdin:read("*l")))