1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
h, w = map(int, input().split())
n = int(input())
images = [int(x) for x in input().split()]
sum_imgs = []

if h % images[0] != 0 or w % images[0] != 0:
    print('-1')
else:
    count_h = h // images[0]
    count_w = w // images[0]

    sum_imgs.append(count_h * count_w)

    for i in range(1, n):
        scalar = (images[i] // images[i-1])
        count_h = count_h // scalar
        count_w = count_w // scalar

        sum_imgs.append(count_h * count_w)
        sum_imgs[i-1] = sum_imgs[i-1] - \
            (scalar * scalar * count_h * count_w)

    print(sum(sum_imgs))