a_in, b_in, t = map(int,input().split()) cnt = [0] * 2 a = min(a_in, b_in) b = max(a_in, b_in) dif = a - b ans = [] if a >= t: ans.append(a) elif b >= t: s_sum = 0 while s_sum < t: s_sum += a if b-t <= s_sum-t: ans.append(b) else: ans.append(s_sum) else: s_sum = 0 while s_sum < t: s_sum += b cnt[1] += 1 ans.append(s_sum) while cnt[0] >= 0 and cnt[1] >= 0: s_sum += dif cnt[0] += 1 cnt[1] -= 1 if s_sum >= t: ans.append(s_sum) else: s_sum += a cnt[1] += 1 ans.sort() print(ans[0])