import std.algorithm, std.array, std.container, std.range, std.bitmanip; import std.numeric, std.math, std.bigint, std.random, core.bitop; import std.string, std.regex, std.conv, std.stdio, std.typecons; void main() { auto rd = readln.split.map!(to!int); auto a = rd[0], b = rd[1], t = rd[2]; writeln(calc(a, b, t)); } int calc(int a, int b, int t) { if (t % a == 0) return t; auto ca = t / a + 1; auto cb = 0; auto ct = a * ca; bool[int] memo; memo[ct - t] = true; while (ca > 0) { ca -= (ct + b - t) / a; if (ca < 0) break; cb += 1; ct = a * ca + b * cb; if ((ct - t) in memo) break; memo[ct - t] = true; } return t + memo.keys.reduce!(min); }