1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
h, w = [int(x) for x in input().split()]
n = int(input())
dd = [int(x) for x in input().split()]
dd.reverse()

def count(height, width, dims):
  
  if height == 0 or width == 0:
    return 0
  
  if len(dims) == 0:
    return -1
  
  if height >= dims[0] and width >= dims[0]:
    hh = height // dims[0]
    ww = width // dims[0]
    
    c1 = count(dims[0], width-ww*dims[0], dims[1:])
    if c1 < 0:
      return -1
      
    c2 = count(height-hh*dims[0], width, dims[1:])
    if c2 < 0:
      return -1
    
    return hh*(ww+c1) + c2
  
  else:
    return count(height, width, dims[1:])

paintings = count(h,w,dd)
print(paintings)