#include #define VARNAME(x) #x #define show(x) cerr << #x << " = " << x << endl using namespace std; using ll = long long; template ostream& operator<<(ostream& os, const vector& v) { os << "sz:" << v.size() << "\n["; for (const auto& p : v) { os << p << ","; } os << "]\n"; return os; } template ostream& operator<<(ostream& os, const pair& p) { os << "(" << p.first << "," << p.second << ")"; return os; } constexpr ll MOD = (ll)1e9 + 7LL; template constexpr T INF = numeric_limits::max() / 64; using P = pair; P convert(const P& pos) { const ll x = pos.first - pos.second; const ll y = pos.first + pos.second; return make_pair(x, y); } int main() { int N; cin >> N; vector d(N); for (int i = 0; i < N; i++) { cin >> d[i]; } ll x, y; cin >> x >> y; if (x == 0 and y == 0) { cout << 0 << endl; } for (int i = 0; i < N; i++) { if (abs(x) + abs(y) == d[i]) { cout << 1 << endl; return 0; } } sort(d.begin(), d.end()); tie(x, y) = convert(make_pair(x, y)); for (int i = 0; i < N; i++) { const ll xinf = x - d[i]; const ll yinf = y - d[i]; const ll xsup = x + d[i]; const ll ysup = y + d[i]; for (int j = 0; j < 4; j++) { const ll mini = (j == 0) ? min({abs(yinf), abs(xinf), abs(xsup)}) : (j == 1) ? min({abs(xinf), abs(yinf), abs(ysup)}) : (j == 2) ? min({abs(ysup), abs(xinf), abs(xsup)}) : min({abs(xsup), abs(yinf), abs(ysup)}); const ll maxi = (j == 0) ? max({abs(yinf), abs(xinf), abs(xsup)}) : (j == 1) ? max({abs(xinf), abs(yinf), abs(ysup)}) : (j == 2) ? max({abs(ysup), abs(xinf), abs(xsup)}) : max({abs(xsup), abs(yinf), abs(ysup)}); if (upper_bound(d.begin(), d.end(), maxi) - lower_bound(d.begin(), d.end(), mini) > 0) { cout << 2 << endl; return 0; } } } cout << -1 << endl; return 0; }