import std.stdio, std.string, std.conv, std.algorithm, std.numeric; import std.range, std.array, std.math, std.typecons, std.container, core.bitop; void main() { int n; scan(n); auto d = readln.split.to!(int[]); int x, y; scan(x, y); long L = abs(x) + abs(y); if (L == 0) { writeln(0); return; } d.sort(); foreach (i ; 0 .. n) { if (d[i] == L) { writeln(1); return; } } auto ds = (d.map!(a => -a).retro().array ~ d).assumeSorted(); debug { writeln(ds); } foreach (i ; 0 .. 2*n) { long r = L - ds[i]; auto lb = ds.lowerBound(r + 1); debug { writeln(lb); } if (!lb.empty && lb.back == r) { writeln(2); return; } } writeln(-1); } void scan(T...)(ref T args) { string[] line = readln.split; foreach (ref arg; args) { arg = line.front.to!(typeof(arg)); line.popFront(); } assert(line.empty); } void fillAll(R, T)(ref R arr, T value) { static if (is(typeof(arr[] = value))) { arr[] = value; } else { foreach (ref e; arr) { fillAll(e, value); } } }