w, h = map(int, input().split())
n = int(input())
s = list(map(int, input().split()))
if w % s[0] > 0 or h % s[0] > 0:
    print('-1')
    exit(0)
res = 0
while w > 0 and h > 0:
    w, h = min(w, h), max(w, h)
    res_c, r, f = 0, w, -1
    for v in s[::-1]:
        if v <= r:
            if f == -1: f = v
            res_c += (r // v) * (f // v)
            r %= v
            if r == 0: break
    
    res += res_c * (h // f)
    h %= f
print(res)
        1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23  | w, h = map(int, input().split()) n = int(input()) s = list(map(int, input().split())) if w % s[0] > 0 or h % s[0] > 0: print('-1') exit(0) res = 0 while w > 0 and h > 0: w, h = min(w, h), max(w, h) res_c, r, f = 0, w, -1 for v in s[::-1]: if v <= r: if f == -1: f = v res_c += (r // v) * (f // v) r %= v if r == 0: break res += res_c * (h // f) h %= f print(res)  | 
            
        
                    English