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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
def how_many_fits(w,h,index,set):
    if w == 0 or h == 0 or index < 0:
        return 0
    else:
        my_items = int(w/set[index])*int(h/set[index])
        right = how_many_fits(w % set[index], h, index - 1, set)
        bottom = how_many_fits(int(w/set[index]) * set[index], h % set[index], index - 1, set)
        return my_items + right + bottom
        
room = input().split()
h = int(room[0])
w = int(room[1])
types = int(input())
sizes = [int(b) for b in input().split()]


possible_sizes = []
possible_types = 0
for size in sizes:
    if size <= h and size <= w:
        possible_sizes.append(size)
        possible_types += 1
    
#pow_set_size = (int) (pow(2, possible_types))


#power_set = []
#for counter in range(0, pow_set_size): 
#        combo = []
#        for j in range(0, possible_types): 
#            if((counter & (1 << j)) > 0): 
#                combo.append(possible_sizes[j])
#        if len(combo) > 0:
#            if(h % combo[0]) == 0 and (w % combo[0]) == 0:
#                power_set.append(combo)


if len(possible_sizes) == 0 or h % possible_sizes[0] != 0 or w % possible_sizes[0] != 0:
    print(-1)
    

    
else:
#    min_combo = w*h
#    for set in power_set:
#        current = how_many_fits(w,h,len(set) - 1, set)
#        if current < min_combo:
#            min_combo = current
            
#    print(min_combo)
    current = how_many_fits(w,h,len(possible_sizes) - 1, possible_sizes)
    print(current)