#include <iostream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <iterator>
#include <functional>
#include <complex>
#include <queue>
#include <stack>
#include <cmath>
#include <cassert>
#include <cstring>
using namespace std;
typedef long long LL;
typedef complex<double> CMP;

class CorrectMultiplicationTwo { public:
	int getMinimum(int a, int b, int c)
	{
		LL score = 1LL<<62;
		if(a>b) swap(a,b);
		int Amax = int(sqrt((double)c))+999;
		for (int A = 1; A <= Amax; A++)
		{
			for (int B = c/A-10; B <= c/A+10; B++)
			{
				if( B > 0 )
					score = min(score, abs(A-a)+abs(B-b)+abs(LL(A)*B-c));
			}
		}
		return score;
	}
};

// BEGIN CUT HERE
#include <ctime>
double start_time; string timer()
 { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); }
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v)
 { os << "{ ";
   for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it)
   os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; }
void verify_case(const int& Expected, const int& Received) {
 bool ok = (Expected == Received);
 if(ok) cerr << "PASSED" << timer() << endl;  else { cerr << "FAILED" << timer() << endl;
 cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' << endl; } }
#define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock();
#define END	 verify_case(_, CorrectMultiplicationTwo().getMinimum(a, b, c));}
int main(){

CASE(0)
	int a = 19; 
	int b = 28; 
	int c = 522; 
	int _ = 2; 
END
CASE(1)
	int a = 10; 
	int b = 30; 
	int c = 500; 
	int _ = 11; 
END
CASE(2)
	int a = 111; 
	int b = 111; 
	int c = 12321; 
	int _ = 0; 
END
CASE(3)
	int a = 1000; 
	int b = 100; 
	int c = 10; 
	int _ = 1089; 
END
CASE(4)
	int a = 399; 
	int b = 522; 
	int c = 199999; 
	int _ = 24; 
END
/*
CASE(5)
	int a = ; 
	int b = ; 
	int c = ; 
	int _ = ; 
END
CASE(6)
	int a = ; 
	int b = ; 
	int c = ; 
	int _ = ; 
END
*/
}
// END CUT HERE
