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
//Jakub Nowak XIV LO Wroclaw
#include<bits/stdc++.h>
using namespace std;

#define boost ios_base::sync_with_stdio(false); cin.tie(0);
#define int long long
#define vi vector<int>
#define pii pair<int,int>
#define pb push_back
#define st first
#define nd second

void wypisz(auto &X) {
    for(auto &x : X) cout << x << " ";
    cout << "\n";
}

void solve() {
    int h, w, n;
    vi D(1, 0);

    cin >> h >> w >> n;
    for(int i=1; i<=n; i++) {
        int x;
        cin >> x;
        D.pb(x);
    }

    if(h%D[1] != 0 || w%D[1] != 0) {
        cout << -1 << "\n";
        return;
    }

    int ans = 0;
    for(int i=1; i<=D.size()-2; i++) {
        int rh = h%D[i+1];
        int rw = w%D[i+1];
        ans += (rw*h + rh*w - rw*rh)/(D[i]*D[i]);
        h -= rh;
        w -= rw;
    }
    ans += (h*w)/(D.back()*D.back());

    cout << ans << "\n";
}

int32_t main() {
    boost
    solve();
}