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
import sys

def main():
    data = sys.stdin.readlines()
    h,w = list(map(int,data[0].split()))
    sz = list(map(int,data[2].split()))
    if (h % sz[0] != 0) or (w % sz[0] != 0):
        print(-1)
        return 0

    cnt = 0
    while len(sz) > 1:
        h = h // sz[0]
        w = w // sz[0]
        sz = [x // sz[0] for x in sz[1:]]
        hr = h % sz[0]
        wr = w % sz[0]
        cnt += h*wr + w*hr - hr*wr
    cnt += (h//sz[0]) * (w//sz[0])
    print(cnt)
    return 0
    

if __name__ == "__main__":
    main()