#include <bits/stdc++.h>

using namespace std;

ifstream fi ("bai2_16.inp");
ofstream fo ("bai2_16.out");

int main(){
  int a,b,c;
  fi>>a>>b>>c;
  int du=c%min(a,b),hieu=max(a,b)-min(a,b);
  if (du>=hieu){
    c=c-(du-hieu);
  }
  else c=c-du;
  fo<<c;
}
