Jzzhu has a big rectangular chocolate bar that consists of n × m unit squares. He wants to cut this bar exactly k times. Each cut must meet the following requirements:

  each cut should be straight (horizontal or vertical);  each cut should go along edges of unit squares (it is prohibited to divide any unit chocolate square with cut);  each cut should go inside the whole chocolate bar, and all cuts must be distinct. 

The picture below shows a possible way to cut a 5 × 6 chocolate for 5 times.

 [Image] 

Imagine Jzzhu have made k cuts and the big chocolate is splitted into several pieces. Consider the smallest (by area) piece of the chocolate, Jzzhu wants this piece to be as large as possible. What is the maximum possible area of smallest piece he can get with exactly k cuts? The area of a chocolate piece is the number of unit squares in it.


-----Input-----

A single line contains three integers n, m, k (1 ≤ n, m ≤ 10^9; 1 ≤ k ≤ 2·10^9).


-----Output-----

Output a single integer representing the answer. If it is impossible to cut the big chocolate k times, print -1.


-----Examples-----
Input
3 4 1

Output
6

Input
6 4 2

Output
8

Input
2 3 4

Output
-1



-----Note-----

In the first sample, Jzzhu can cut the chocolate following the picture below:

 [Image] 

In the second sample the optimal division looks like this:

 [Image] 

In the third sample, it's impossible to cut a 2 × 3 chocolate 4 times.

Source: codeforces | Difficulty: MEDIUM_HARD
Tags: Mathematics

Greedy algorithms


Solutions:
def split1(m, n, k):
	if m % (k + 1) == 0:
		return n * (m // (k + 1))
	if k < m:
		return m // (k + 1) * n
	else:
		k2 = k - m + 1
		return n // (k2 + 1)

def split(m, n, k):
	r = max(split1(m, n, k), split1(n, m, k))
	return r if r else -1
args = input().split()
print(split(*map(int, args)))


(a, b, k) = list(map(int, input().split()))
if a + b - 2 < k:
	print(-1)
	return
k += 2
if a > b:
	(a, b) = (b, a)
i = 1
maxi = -1
while i * i <= a:
	y = min(i, k - 1)
	val1 = a // y * (b // (k - y))
	if maxi < val1:
		maxi = val1
	j = min(a // i, k - 1)
	val2 = a // j * (b // (k - j))
	if maxi < val2:
		maxi = val2
	i += 1
print(maxi)


(n, m, k) = map(int, input().split())
if m > n:
	(n, m) = (m, n)
ans = -1
if k < n:
	ans = m * (n // (k + 1))
	if k < m:
		ans = max(ans, n * (m // (k + 1)))
elif k <= n - 1 + m - 1:
	ans = m // (k + 1 - n + 1)
print(ans)


def main():
	(a, b, c) = map(int, input().split())
	(res, c) = ([-1], c + 1)
	if c < a + b:
		for (n, m, k) in ((a, b, c), (b, a, c)):
			if n < k:
				k -= n - 1
				(n, m) = (m, 1)
			res.append(n // k * m)
	print(max(res))
main()


(n, m, k) = map(int, input().split())
if k > n + m - 2:
	print(-1)
else:
	(a, b) = (m * (n // (k + 1)), n * (m // (k + 1)))
	if a == 0:
		a = m // (k - n + 2)
	if b == 0:
		b = n // (k - m + 2)
	print(max(a, b))


def f(x):
	global n, m, k
	(c1, c2) = (x, k - x)
	(w1, w2) = (n // (c1 + 1), m // (c2 + 1))
	return w1 * w2

def solve():
	global n, m, k
	max_k = n + m - 2
	if k > max_k:
		print(-1)
		exit()
	L = max(0, k - (m - 1))
	R = min(k, n - 1)
	ans2 = max(f(L), f(R))
	return ans2
(n, m, k) = map(int, input().split())
print(solve())
exit()
import random
L = 10000
while 1:
	(n, m, k) = (random.randint(1, L), random.randint(1, L), random.randint(1, L))
	solve()


from itertools import *

def read_ints():
	return map(int, input().strip().split())
(n, m, k) = read_ints()

def val(x, k, n, m):
	Y = x + 1
	Z = k - x + 1
	if Y > 0 and Z > 0:
		return n // (x + 1) * (m // (k - x + 1))

def sym(n, m, k):
	x = min(n - 1, k)
	return val(x, k, n, m)

def test(n, m, k):
	if n + m + 2 < k:
		return -1
	answers = [sym(n, m, k), sym(m, n, k)]
	return max(answers) or -1
print(test(n, m, k))


(n, m, k) = list(map(int, input().split()))
(ans, ans1) = (0, 0)
if n + m - 2 < k:
	print(-1)
	return
else:
	k1 = k
	if k < n:
		ans = n // (k + 1) * m
	else:
		k -= n - 1
		ans = m // (k + 1)
	if k1 < m:
		ans1 = m // (k1 + 1) * n
	else:
		k1 -= m - 1
		ans1 = n // (k1 + 1)
print(max(ans1, ans))


inputx = input().split(' ')
n = int(inputx[0])
m = int(inputx[1])
k = int(inputx[2])
if n + m - 2 < k:
	print(-1)
else:
	if n > m:
		(n, m) = (m, n)
	if k < n:
		print(max(n * int(m / (k + 1)), m * int(n / (k + 1))))
	elif n <= k and k < m:
		print(n * int(m / (k + 1)))
	else:
		print(int(n / (k - m + 2)))


def split1(m, n, k):
	if k < m:
		return m // (k + 1) * n
	else:
		return n // (k - m + 2)

def split(m, n, k):
	r = max(split1(m, n, k), split1(n, m, k))
	return r if r else -1
args = input().split()
print(split(*list(map(int, args))))


l = input().split()
n = int(l[0])
m = int(l[1])
k = int(l[2])
if k <= n + m - 2:
	if k < n:
		outn = int(n / (k + 1)) * m
	else:
		outn = int(m / (k - n + 2))
	if k < m:
		outm = int(m / (k + 1)) * n
	else:
		outm = int(n / (k - m + 2))
	print('', max(outn, outm), sep='')
else:
	print('-1')


import os
import sys
from math import *
from collections import *
from fractions import *
from bisect import *
from heapq import *
from io import BytesIO, IOBase

def vsInput():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
ALPHA = 'abcdefghijklmnopqrstuvwxyz'
M = 998244353
EPS = 1e-06

def value():
	return tuple(map(int, input().split()))

def array():
	return [int(i) for i in input().split()]

def Int():
	return int(input())

def Str():
	return input()

def arrayS():
	return [i for i in input().split()]
(r, c, cuts) = value()
max_cuts = r + c - 2
if cuts > max_cuts:
	print(-1)
else:
	x = min(cuts + 2 - 1, r)
	ans1 = r // x * (c // (cuts + 2 - x))
	(r, c) = (c, r)
	x = min(cuts + 2 - 1, r)
	ans2 = r // x * (c // (cuts + 2 - x))
	print(max(ans1, ans2))


(n, m, k) = map(int, input().split())
(n, m) = (min(n, m), max(n, m))

def p(i, j):
	return n // (i + 1) * (m // (j + 1))
if k < n:
	print(max(p(k, 0), p(0, k)))
elif k < m:
	print(p(0, k))
elif k <= n + m - 2:
	print(p(k - (m - 1), m - 1))
else:
	print(-1)


import math
(n, m, k) = list(map(int, input().split()))
if k > n + m - 2:
	print(-1)
	return
if n % (k + 1) == 0:
	print(int(n / (k + 1)) * m)
	return
if m % (k + 1) == 0:
	print(int(m / (k + 1)) * n)
	return
r = max(n // (k + 1), 1)
r1 = max(0, k - n + 1)
r2 = m // (1 + r1)
ans = r * r2
r = max(m // (k + 1), 1)
r1 = max(0, k - m + 1)
r2 = n // (1 + r1)
ans = max(ans, r * r2)
print(int(ans))


(n, m, k) = list(map(int, input().split()))
if n + m - 2 < k:
	print('-1\n')
else:
	x = min(n - 1, k)
	y = max(0, k - x)
	ans = n // (x + 1) * (m // (y + 1))
	y = min(m - 1, k)
	x = max(0, k - y)
	ans = max(ans, n // (x + 1) * (m // (y + 1)))
	print(ans, '\n')


(n, m, k) = map(int, input().split())
if k <= n + m - 2:
	x = min(k + 1, n)
	y = k + 2 - x
	a = n // x * (m // y)
	y = min(k + 1, m)
	x = k + 2 - y
	b = n // x * (m // y)
	print(max(a, b))
else:
	print(-1)


from sys import stdin as cin
from fractions import gcd
mod = 1000000007
(n, m, k) = map(int, cin.readline().split())
if k > n + m - 2:
	print(-1)
else:
	if n < m:
		(n, m) = (m, n)
	max_min_area = max(n * (m // (k + 1)), m * (n // (k + 1)))
	if k + 1 > m:
		max_min_area = max(max_min_area, n // (k - m + 2))
	if k + 1 > n:
		max_min_area = max(max_min_area, m // (k - n + 2))
	print(max_min_area)


def main():
	(n, m, k) = [int(i) for i in input().split()]
	if k > n + m - 2:
		print(-1)
		return
	if k > n - 1:
		result1 = m // (k + 2 - n)
	else:
		result1 = n // (k + 1) * m
	if k > m - 1:
		result2 = n // (k + 2 - m)
	else:
		result2 = m // (k + 1) * n
	print(max(result1, result2))
main()


(n, m, k) = map(int, input().split())
if n + m - 2 < k:
	print(-1)
	return

def divisors(n):
	div = set()
	for i in range(1, int(n ** (1 / 2)) + 1):
		if n % i == 0:
			div.add(i)
			div.add(n // i)
	return [*div]

def solve(n, m, k):
	div = divisors(n)
	ans = 0
	for i in div:
		if i - 1 > k:
			continue
		ans = max(ans, n // i * (m // (k - i + 2)))
	return ans
print(max(solve(n, m, k), solve(m, n, k)))


(n, m, k) = [int(x) for x in input().split()]
if k + 2 > n + m:
	print(-1)
else:
	if k >= n:
		alpha = m // (k - n + 2)
	else:
		alpha = m * (n // (k + 1))
	if k >= m:
		beta = n // (k - m + 2)
	else:
		beta = n * (m // (k + 1))
	print(max(alpha, beta))


(n, m, k) = map(int, input().split())
if k > n + m - 2:
	print(-1)
else:
	if n < m:
		(n, m) = (m, n)
	if m % (k + 1) == 0:
		print(m * n // (k + 1))
	elif k <= n - 1:
		if k > m - 1:
			print(n // (k + 1) * m)
		else:
			print(max(n // (k + 1) * m, m // (k + 1) * n))
	else:
		print(m // (k - (n - 1) + 1))


a = input().split(' ')
n = int(a[0])
m = int(a[1])
k = int(a[2])
if k > m + n - 2:
	print(-1)
else:
	ans = 1
	if k < n:
		ans = max(ans, n // (k + 1) * m)
	if k < m:
		ans = max(ans, m // (k + 1) * n)
	if k >= n:
		ans = max(ans, m // (k - (n - 1) + 1))
	if k >= m:
		ans = max(ans, n // (k - (m - 1) + 1))
	print(ans)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
INF = 10 ** 18
MOD = 10 ** 9 + 7
Ri = lambda : [int(x) for x in sys.stdin.readline().split()]
ri = lambda : sys.stdin.readline().strip()
(n, m, k) = Ri()
if n - 1 + m - 1 < k:
	print(-1)
else:
	if n < m:
		(n, m) = (m, n)
	if k >= n:
		print(m // (k - (n - 1) + 1))
		exit()
	ans = -10 ** 18
	if k < m:
		ans = max(ans, n * (m // (k + 1)))
	if k < n:
		ans = max(ans, m * (n // (k + 1)))
	print(ans)


import sys
import time
import math
from functools import lru_cache
INF = 10 ** 18 + 3
EPS = 1e-10
MAX_CACHE = 10 ** 9
MOD = 1 << 30

def time_it(function, output=sys.stderr):

	def wrapped(*args, **kwargs):
		start = time.time()
		res = function(*args, **kwargs)
		elapsed_time = time.time() - start
		print('"%s" took %f ms' % (function.__name__, elapsed_time * 1000), file=output)
		return res
	return wrapped

@time_it
def main():
	(n, m, k) = map(int, input().split())
	(n, m) = sorted((n, m))
	if k + 1 >= m:
		res = n // (k + 2 - m)
	else:
		res = max(n * (m // (k + 1)), m * (n // (k + 1)))
	if res == 0:
		res = -1
	print(res)

def set_input(file):
	global input
	input = lambda : file.readline().strip()

def set_output(file):
	global print
	local_print = print

	def print(*args, **kwargs):
		kwargs['file'] = kwargs.get('file', file)
		return local_print(*args, **kwargs)
set_input(open('input.txt', 'r') if 'MINE' in sys.argv else sys.stdin)
set_output(sys.stdout)
main()


(n, m, k) = map(int, input().split())
if k <= n + m - 2:
	x1 = min(k + 1, n)
	y1 = k + 2 - x1
	a = n // x1 * (m // y1)
	y2 = min(k + 1, m)
	x2 = k + 2 - y2
	b = n // x2 * (m // y2)
	print(max(a, b))
else:
	print(-1)


def read(mode=2):
	inputs = input().strip()
	if mode == 0:
		return inputs
	if mode == 1:
		return inputs.split()
	if mode == 2:
		return [int(x) for x in inputs.split()]

def write(s='\n'):
	if isinstance(s, list):
		s = ' '.join(map(str, s))
	s = str(s)
	print(s, end='')
(n, m, k) = read()
if n + m - 2 < k:
	print(-1)
else:
	mx = 0
	if n > k:
		mx = max(mx, n // (k + 1) * m)
	else:
		mx = max(mx, 1 * (m // (k - n + 2)))
	if m > k:
		mx = max(mx, m // (k + 1) * n)
	else:
		mx = max(mx, 1 * (n // (k - m + 2)))
	print(mx)


def Calc(n, m, k):
	if n + m - 2 < k:
		return -1
	if k <= n - 1:
		return n // (k + 1) * m
	return m // (k - n + 2)
(n, m, k) = [int(x) for x in input().split()]
print(max(Calc(n, m, k), Calc(m, n, k)))


def cut(n, m, k):
	if k > m + n - 2:
		return -1
	if k < max(m, n):
		return max(n * (m // (k + 1)), m * (n // (k + 1)))
	return max(n // (k - m + 2), m // (k - n + 2))
(n, m, k) = map(int, input().split())
print(cut(n, m, k))


import math, sys, bisect, heapq
from collections import defaultdict, Counter, deque
from itertools import groupby, accumulate
input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__
ilele = lambda : map(int, input().split())
alele = lambda : list(map(int, input().split()))

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]
MOD = 1000000000 + 7

def Y(c):
	print(['NO', 'YES'][c])

def y(c):
	print(['no', 'yes'][c])

def Yy(c):
	print(['No', 'Yes'][c])

def printDivisors(n):
	A = []
	i = 1
	while i <= math.sqrt(n):
		if n % i == 0:
			if n / i == i:
				A.append(i)
			else:
				A.append(i)
				A.append(n // i)
		i = i + 1
	return A
(n, m, k) = ilele()
z = n - 1 + m - 1
if k > z:
	print(-1)
elif k == z:
	print(1)
else:
	mini = -1
	A = printDivisors(n)
	B = printDivisors(m)
	for i in A:
		l = i
		b = k - (n // l - 1)
		if b <= 0:
			mini = max(mini, l * m)
		elif b <= m - 1:
			r = max(1, m // (b + 1))
			mini = max(mini, l * r)
	for i in B:
		r = i
		b = k - (m // r - 1)
		if b <= 0:
			mini = max(mini, r * n)
		elif b <= n - 1:
			l = max(1, n // (b + 1))
			mini = max(mini, l * r)
	print(mini)


(n, m, k) = map(int, input().split())
if k > n + m - 2:
	print(-1)
	exit()
res = 0
if k < n:
	res = max(res, n // (k + 1) * m)
else:
	res = max(res, m // (k - (n - 1) + 1))
if k < m:
	res = max(res, m // (k + 1) * n)
else:
	res = max(res, n // (k - (m - 1) + 1))
print(res)


(n, m, k) = [int(s) for s in input().split()]
(n, m) = (max(n, m), min(n, m))
if n + m - 2 < k:
	print(-1)
elif n - 1 < k:
	print(m // (k - n + 2))
elif m - 1 < k:
	print(n // (k + 1) * m)
else:
	print(max(n // (k + 1) * m, m // (k + 1) * n))