
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <queue>

using namespace std;

long long x[100001], y[100001];
int t[100001];

int gcd(int m, int n) {
	while (n > 0) {
		int r = m % n;
		m = n;
		n = r;
	}
	return m;
}

int getPhi(int n) {
	int res = 1;
	for (int i = 2; i * i <= n; i ++)
		if (n % i == 0) {
			res *= i - 1;
			n /= i;
			while (n % i == 0) {
				res *= i;
				n /= i;
			}
		}
	if (n > 1) res *= n - 1;
	return res;
}

int getPower(int a, int p, int modulo) {
	if (p == 0) return 1;
	int res = getPower(a, p / 2, modulo);
	res = (long long)res * res % modulo;
	if (p % 2 == 1) res = (long long)res * a % modulo;
	return res;
}

int main() {
	int n, a, b;
	scanf("%d%d%d", &n, &a, &b);
	for (int i = 0; i < n; i ++) scanf("%d", &t[i]);
	t[n] = -t[n-1];
	for (int i = n - 1; i >= 1; i --) t[i] = t[i] - t[i-1];
	n ++;
	
	int d = gcd(a, b);
	for (int i = 0; i < n; i ++) {
		if (t[i] % d != 0) {
			printf("-1\n");
			return 0;
		}
		t[i] /= d;
	}
	a /= d;
	b /= d;
	
	if (a > b) swap(a, b);
	if (a == 1 && b == 1) {
		long long ans = 0;
		for (int i = 0; i < n; i ++) ans += abs(t[i]);
		printf("%lld\n", ans / 2);
		return 0;
	}
	
	int x0 = getPower(a, getPhi(b) - 1, b);
	int y0 = (1 - (long long)x0 * a) / b;
	
	for (int i = 0; i < n; i ++) {
		x[i] = (long long)x0 * t[i];
		y[i] = (long long)y0 * t[i];
		long long head = -t[i], tail = t[i];
		if (head > tail) swap(head, tail);
		tail --;
		while (head <= tail) {
			long long mid = (head + tail) / 2;
			long long t1 = abs(x[i] - mid * b) + abs(y[i] + mid * a);
			long long t2 = abs(x[i] - (mid + 1) * b) + abs(y[i] + (mid + 1) * a);
			if (t1 < t2) tail = mid - 1; else head = mid + 1;
		}
		x[i] -= (tail + 1) * b;
		y[i] += (tail + 1) * a;
	}
	
	long long s = 0;
	for (int i = 0; i < n; i ++) s += x[i];
	s /= b;
	if (s < 0) {
		swap(a, b);
		for (int i = 0; i < n; i ++) swap(x[i], y[i]);
		s *= -1;
	}
	
	priority_queue< pair<long long, int> > Q;
	for (int i = 0; i < n; i ++) {
		long long tmp = abs(x[i] - b) + abs(y[i] + a) - abs(x[i]) - abs(y[i]);
		Q.push(make_pair(-tmp, i));
	}
	
	for (int i = 0; i < s; i ++) {
		int loc = Q.top().second;
		Q.pop();
		x[loc] -= b;
		y[loc] += a;
		long long tmp = abs(x[loc] - b) + abs(y[loc] + a) - abs(x[loc]) - abs(y[loc]);
		Q.push(make_pair(-tmp, loc));
	}
	
	long long ans = 0;
	for (int i = 0; i < n; i ++) ans += abs(x[i]) + abs(y[i]);
	printf("%lld\n", ans / 2);
	
	return 0;
}
