1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
h,w = map(int,input().split())
n = int(input())
d = list(map(int,input().split()))


def calc(w,h,i):
	if w==0 or h==0:
		return 0
	s = (w//d[i])*(h//d[i])
	#print(d[i],w,h,s)
	s += calc(h%d[i],w,i-1)+calc(h//d[i]*d[i],w%d[i],i-1)
	return s

if h%d[0]>0 or w%d[0]>0:
	print(-1)
else:
	print(calc(w,h,n-1))