1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
def main():
    h,w=list(map(int,input().split()))
    n=int(input())
    d=list(map(int,input().split()))
    if h%d[0] or w%d[0]:
        print(-1)
        return
    c=0
    while d[-1]>h or d[-1]>w:
        d.pop()
    c+=(h//d[-1])*(w//d[-1])
    rh=h%d[-1]
    rw=w%d[-1]
    d.pop()
    while len(d):
        c+=(rh//d[-1])*(w//d[-1])
        c+=(rw//d[-1])*((h-rh)//d[-1])
        rh%=d[-1]
        rw%=d[-1]
        d.pop()
    print(c)
main()