#include #include #include #include #include #include #include #include #include #include static const int MOD = 1000000007; using ll = long long; using u32 = uint32_t; using namespace std; template constexpr T INF = ::numeric_limits::max() / 32 * 15 + 208; int main() { const int M = 30000; ll a, b, t; cin >> a >> b >> t; if(b >= M){ ll ans = (t+b-1)/b*b; for (int i = 0; i <= t; i += b) { ans = min(ans, i+(t-i+a-1)/a*a); } cout << ans << "\n"; }else { ll ans1 = t/(2*a*b)*2*a*b, ans2 = INF; t %= (2*a*b); vector v(b+1), u(a+1); for (int i = 0; i <= b; ++i) { v[i] = i*a; } for (int i = 0; i <= a; ++i) { u[i] = i*b; } int cur = b; for (int i = 0; i <= a; ++i) { while(cur > 0 && u[i]+v[cur-1] >= t) cur--; if(u[i]+v[cur] >= t) ans2 = min(ans2, u[i]+v[cur]); } cout << ans1+ans2 << "\n"; } return 0; }