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
#include<bits/stdc++.h>

using namespace std;

#define fwd(i,a,b) for(int i=(a); i<(b);i++)
#define rep(i,n) for(int i=0; i<(n);i++)
#define ford(i,a,b) for(int i=(a); i>(b);i--)
#define all(X) (X).begin(), (X).end()
#define sz(X)((int)(X).size())

#define st first
#define nd second

#define DEBUG
#ifdef DEBUG
template<typename T1, typename T2> auto& operator<<(ostream& out, const pair<T1, T2>& a) { return out << "(" << a.first << ", " << a.second << ")"; }
template<typename T, typename N> auto& operator<<(N& out, const T& a) { out << "{"; for (const auto& b : a) out << b << ", "; return out << "}"; }
template<typename... Args> void print(Args&&... args) { (cerr << ... << args) << "\n"; }
#define debug(x...) cerr << "[" #x "]: ", print(x)
#else
#define debug(...) ;
#endif

typedef long long ll;
typedef long double ld;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    ll h,w,n;
    cin >> h >> w >> n;
    vector<ll> tab(n);
    rep(i,n) cin >> tab[n-i-1];
    ll ch = 0, cw = 0;
    ll ans = 0;
    for(auto d : tab) {
        if((h-ch)/d > 0 || (w-cw)/d > 0) {
            ans += (w/d)*(h/d);
            ans -= (cw/d)*(ch/d);
            cw = (w/d)*d;
            ch = (h/d)*d;
        }
    }

    if(cw==w && ch==h) cout << ans;
    else cout << "-1";

    return 0;
}