solution
stringlengths 11
983k
| difficulty
int64 0
21
| language
stringclasses 2
values |
---|---|---|
#include <bits/stdc++.h>
using namespace std;
bool cando(const set<int>& S, int x) {
for (set<int>::const_iterator it = S.begin(); it != S.end(); ++it) {
int v = *it;
if (S.count(v - x) || S.count(v + x)) return true;
}
return false;
}
int main() {
set<int> S;
int N, L, X, Y, v;
scanf("%d%d%d%d", &N, &L, &X, &Y);
for (int i = 0; i < (N); ++i) scanf("%d", &v), S.insert(v);
if (cando(S, X) && cando(S, Y)) {
cout << 0 << endl;
return 0;
} else if (cando(S, X)) {
cout << 1 << endl;
cout << L - Y << endl;
return 0;
} else if (cando(S, Y)) {
cout << 1 << endl;
cout << L - X << endl;
return 0;
}
for (set<int>::iterator it = S.begin(); it != S.end(); ++it) {
int xx = *it;
long long nw = xx - X;
long long yy = nw - Y;
assert(!S.count(nw));
assert(abs(nw - xx) == X);
assert(abs(nw - yy) == Y);
if ((0 <= (nw) && (nw) <= L) && (0 <= (xx) && (xx) <= L) &&
(0 <= (yy) && (yy) <= L) && S.count(xx) && S.count(yy)) {
cout << 1 << endl << nw << endl;
return 0;
}
};
for (set<int>::iterator it = S.begin(); it != S.end(); ++it) {
int xx = *it;
long long nw = xx + X;
long long yy = nw - Y;
assert(!S.count(nw));
assert(abs(nw - xx) == X);
assert(abs(nw - yy) == Y);
if ((0 <= (nw) && (nw) <= L) && (0 <= (xx) && (xx) <= L) &&
(0 <= (yy) && (yy) <= L) && S.count(xx) && S.count(yy)) {
cout << 1 << endl << nw << endl;
return 0;
}
};
for (set<int>::iterator it = S.begin(); it != S.end(); ++it) {
int xx = *it;
long long nw = xx + X;
long long yy = nw + Y;
assert(!S.count(nw));
assert(abs(nw - xx) == X);
assert(abs(nw - yy) == Y);
if ((0 <= (nw) && (nw) <= L) && (0 <= (xx) && (xx) <= L) &&
(0 <= (yy) && (yy) <= L) && S.count(xx) && S.count(yy)) {
cout << 1 << endl << nw << endl;
return 0;
}
};
for (set<int>::iterator it = S.begin(); it != S.end(); ++it) {
int xx = *it;
long long nw = xx - X;
long long yy = nw + Y;
assert(!S.count(nw));
assert(abs(nw - xx) == X);
assert(abs(nw - yy) == Y);
if ((0 <= (nw) && (nw) <= L) && (0 <= (xx) && (xx) <= L) &&
(0 <= (yy) && (yy) <= L) && S.count(xx) && S.count(yy)) {
cout << 1 << endl << nw << endl;
return 0;
}
};
cout << 2 << endl;
cout << L - X << " " << L - Y << endl;
}
| 8 | CPP |
#Adapted from code of hatsuyuki15 in this contest
n, l, x, y = map(int, input().split())
a = set(map(int, input().split()))
boy = False
girl = False
one = False
where = -1
for i in a:
if i + x in a:
boy = True
if i + y in a:
girl = True
if i - x > 0 and i - x + y in a:
one = True
where = i - x
if i + x < l and i + x - y in a:
one = True
where = i + x
if i + x + y in a:
one = True
where = i + x
if boy and girl:
print(0)
if boy and not girl:
print(1)
print(y)
if girl and not boy:
print(1)
print(x)
if not boy and not girl:
if one:
print(1)
print(where)
if not one:
print(2)
print(x, y) | 8 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
bool Can(const vector<int64_t>& A, int64_t X, int* idx = NULL) {
for (int i = 0; i < A.size(); ++i) {
int64_t reper = A[i] + X;
if (binary_search(A.begin(), A.end(), reper)) {
if (idx) {
*idx = i;
}
return true;
}
}
return false;
}
bool Can2(const vector<int64_t>& A, int64_t X, int* idx = NULL) {
for (int i = static_cast<int>(A.size()) - 1; i >= 0; --i) {
int64_t reper = A[i] + X;
if (binary_search(A.begin(), A.end(), reper)) {
if (idx) {
*idx = i;
}
return true;
}
}
return false;
}
int main() {
ios_base::sync_with_stdio(false);
int N;
int64_t L, X, Y;
cin >> N >> L >> X >> Y;
vector<int64_t> A(N);
for (int64_t& a : A) {
cin >> a;
}
bool can_x = Can(A, X);
bool can_y = Can(A, Y);
if (can_x && can_y) {
cout << 0 << '\n';
return 0;
}
if (can_x && !can_y) {
cout << 1 << '\n' << Y << '\n';
return 0;
}
if (!can_x && can_y) {
cout << 1 << '\n' << X << '\n';
return 0;
}
int idx = 0;
if (Can(A, Y - X, &idx)) {
if (A[idx] + Y <= L) {
cout << 1 << '\n';
cout << A[idx] + Y << '\n';
return 0;
}
if (A[idx] - X >= 0) {
cout << 1 << '\n';
cout << A[idx] - X << '\n';
return 0;
}
}
if (Can2(A, Y - X, &idx)) {
if (A[idx] - X >= 0) {
cout << 1 << '\n';
cout << A[idx] - X << '\n';
return 0;
}
}
if (Can(A, X + Y, &idx)) {
cout << 1 << '\n';
cout << A[idx] + X << '\n';
return 0;
}
cout << 2 << '\n';
cout << X << ' ' << Y << '\n';
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int n, l, x, y;
int a[N];
map<int, bool> exist;
vector<int> coolx;
vector<int> cooly;
bool check(int d) {
int low, high, mid;
low = 1;
high = n;
while (low <= high) {
mid = (low + high) / 2;
if (d - a[mid] == x) return true;
if (d - a[mid] < x)
high = mid - 1;
else
low = mid + 1;
}
low = 1;
high = n;
while (low <= high) {
mid = (low + high) / 2;
if (a[mid] - d == x) return true;
if (a[mid] - d < x)
low = mid + 1;
else
high = mid - 1;
}
return false;
}
int main() {
int i;
cin >> n >> l >> x >> y;
for (i = 1; i <= n; i++) scanf("%d", &a[i]);
for (i = 1; i <= n; i++) {
if (a[i] >= x)
if (exist[a[i] - x]) coolx.push_back(i);
exist[a[i]] = true;
}
exist.clear();
for (i = 1; i <= n; i++) {
if (a[i] >= y)
if (exist[a[i] - y]) cooly.push_back(i);
exist[a[i]] = true;
}
if (coolx.size() > 0 && cooly.size() > 0) {
cout << 0 << endl;
return 0;
}
if (coolx.size() > 0 && cooly.size() == 0) {
cout << 1 << endl;
for (i = 1; i <= n; i++) {
if (a[i] >= y) {
cout << a[i] - y << endl;
break;
}
}
return 0;
}
if (coolx.size() == 0 && cooly.size() > 0) {
cout << 1 << endl;
for (i = 1; i <= n; i++) {
if (a[i] >= x) {
cout << a[i] - x << endl;
break;
}
}
return 0;
}
int d;
for (i = 1; i <= n; i++) {
d = a[i] + y;
if (d <= l)
if (check(d)) {
cout << 1 << endl;
cout << d << endl;
return 0;
}
if (a[i] >= y) {
d = a[i] - y;
if (check(d)) {
cout << 1 << endl;
cout << d << endl;
return 0;
}
}
}
cout << 2 << endl;
cout << x << " " << y << endl;
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
map<int, int> M;
int A[100005];
int main() {
int n, x, y, l;
cin >> n >> l >> x >> y;
bool can_x = false, can_y = false;
for (int i = 0; i < n; i++) {
scanf("%d", &A[i]);
M[A[i]] = i + 1;
}
for (int i = 0; i < n; i++) {
if (A[i] < x) continue;
if (M[A[i] - x] > 0) {
can_x = true;
break;
}
}
for (int i = 0; i < n; i++) {
if (A[i] < y) continue;
if (M[A[i] - y] > 0) {
can_y = true;
break;
}
}
if (can_x && can_y) {
cout << 0 << endl;
return 0;
}
if (can_x == true && can_y == false) {
cout << 1 << endl;
cout << y << endl;
return 0;
}
if (can_x == false && can_y == true) {
cout << 1 << endl;
cout << x << endl;
return 0;
}
for (int i = 0; i < n; i++) {
if (A[i] + x <= l) {
if (A[i] + x - y >= 0 && M[A[i] + x - y] > 0) {
cout << 1 << endl;
cout << A[i] + x << endl;
return 0;
}
if (A[i] + x + y <= l && M[A[i] + x + y] > 0) {
cout << 1 << endl;
cout << A[i] + x << endl;
return 0;
}
}
if (A[i] - x >= 0) {
if (A[i] - x - y >= 0 && M[A[i] - x - y] > 0) {
cout << 1 << endl;
cout << A[i] - x << endl;
return 0;
}
if (A[i] - x + y <= l && M[A[i] - x + y] > 0) {
cout << 1 << endl;
cout << A[i] - x << endl;
return 0;
}
}
}
cout << 2 << endl;
cout << x << ' ' << y << endl;
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
template <class P, class Q>
inline void smin(P &a, Q b) {
if (b < a) a = b;
}
template <class P, class Q>
inline void smax(P &a, Q b) {
if (a < b) a = b;
}
const int maxn = 100000 + 100;
int n, l, x, y;
int a[maxn];
set<int> s;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n >> l >> x >> y;
for (int i = 0, _n = (int)(n); i < _n; i++) cin >> a[i], s.insert(a[i]);
bool hx = false, hy = false;
for (int i = 0, _n = (int)(n); i < _n; i++) {
if (s.find(a[i] - x) != s.end()) hx = true;
if (s.find(a[i] - y) != s.end()) hy = true;
}
if (hx && hy) {
cout << 0 << endl;
return 0;
}
if (hx || hy) {
int v = x;
if (hx) v = y;
cout << 1 << endl;
cout << v << endl;
return 0;
}
for (int i = 0, _n = (int)(n); i < _n; i++) {
if (s.find(a[i] - x - y) != s.end()) {
cout << 1 << endl;
cout << a[i] - x << endl;
return 0;
}
if (s.find(a[i] - y + x) != s.end() && a[i] + x < l) {
cout << 1 << endl;
cout << a[i] + x << endl;
return 0;
}
if (s.find(a[i] + y - x) != s.end() && a[i] - x > 0) {
cout << 1 << endl;
cout << a[i] - x << endl;
return 0;
}
}
cout << 2 << endl;
cout << x << ' ' << y << endl;
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
const int size = 300 * 1000 + 100;
int a[size];
set<int> marks;
int n, len, x, y;
set<int> couldget(int val) {
set<int> psb;
for (int i = 0; i < n; i++)
if (marks.find(a[i] + val) != marks.end()) psb.insert(a[i]);
return psb;
}
int main() {
scanf("%d%d%d%d", &n, &len, &x, &y);
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
marks.insert(a[i]);
}
set<int> cx = couldget(x);
set<int> cy = couldget(y);
set<int> csum = couldget(x + y);
set<int> cdif = couldget(y - x);
if (!cx.empty() && !cy.empty()) {
cout << 0 << endl;
return 0;
}
if (!cx.empty() || !cy.empty()) {
cout << 1 << endl;
if (!cx.empty())
cout << y << endl;
else
cout << x << endl;
return 0;
}
if (!csum.empty()) {
cout << 1 << endl;
cout << *csum.begin() + x << endl;
return 0;
}
if (!cdif.empty() && (*cdif.begin() + y <= len || *cdif.rbegin() >= x)) {
cout << 1 << endl;
if (*cdif.begin() + y <= len) {
cout << *cdif.begin() + y << endl;
} else {
cout << *cdif.rbegin() - x << endl;
}
return 0;
}
cout << 2 << endl;
cout << x << ' ' << y << endl;
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-9;
const int IINF = 1000000000;
const double PI = acos(-1.0);
const long long LINF = 6000000000000000000LL;
int main() {
int n, l, x, y;
while (scanf("%d%d%d%d", &n, &l, &x, &y) == 4) {
vector<int> v(n);
set<int> marks;
for (int i = 0; i < n; ++i) {
scanf("%d", &v[i]);
marks.insert(v[i]);
}
bool first = false, second = false;
for (int i = 0; i < n; ++i) {
if (marks.find(v[i] - x) != marks.end() ||
marks.find(v[i] + x) != marks.end()) {
first = true;
}
if (marks.find(v[i] - y) != marks.end() ||
marks.find(v[i] + y) != marks.end()) {
second = true;
}
}
if (first && second) {
printf("0\n");
} else if (first || second) {
printf("1\n");
for (int i = 0; i < n; ++i) {
int val;
if (!first)
val = x;
else
val = y;
if (v[i] - val >= 0) {
printf("%d\n", v[i] - val);
break;
}
if (v[i] + val <= l) {
printf("%d\n", v[i] + val);
break;
}
}
} else {
for (int i = 0; i < n; ++i) {
vector<int> check = {v[i] + x, v[i] - x, v[i] + y, v[i] - y};
for (int to : check) {
if (to < 0 || to > l) continue;
if (marks.find(to - x) != marks.end() &&
marks.find(to + y) != marks.end()) {
printf("1\n%d\n", to);
return 0;
}
if (marks.find(to + x) != marks.end() &&
marks.find(to - y) != marks.end()) {
printf("1\n%d\n", to);
return 0;
}
if (marks.find(to - x) != marks.end() &&
marks.find(to - y) != marks.end()) {
printf("1\n%d\n", to);
return 0;
}
if (marks.find(to + x) != marks.end() &&
marks.find(to + y) != marks.end()) {
printf("1\n%d\n", to);
return 0;
}
}
}
printf("2\n%d %d\n", x, y);
}
}
return 0;
}
| 8 | CPP |
__author__ = "zabidon"
n, l, x, y = map(int, input().split())
data = set(map(int, input().split()))
old_x = any(i + x in data for i in data)
old_y = any(i + y in data for i in data)
if old_x and old_y:
#all
print(0)
elif old_x:
#one
print(1)
print(y)
elif old_y:
#one
print(1)
print(x)
else:
found = False
for i in data:
if i + x + y in data:
found = True
print(1)
print(i + x)
elif i + x - y in data:
# because x<y
# i + x - y mean exist one mark
if 0 <= i + x <= l:
found = True
print(1)
print(i + x)
if not found and 0 <= i - y <= l:
found = True
print(1)
print(i - y)
if found:
break
if not found:
print(2)
print(x, y) | 8 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
void afill(T *arr, int size, T val) {
fill(arr, arr + size, val);
}
long long mod = 1e9 + 7;
double eps = 1e-9;
const int MAX_SIZE = 1e5;
int n, t, m, q, k;
int l, x, y;
int arr[1 << 17];
bool check(int pp, int xx) {
if (pp - xx >= 0 && *lower_bound(arr, arr + n, pp - xx) == pp - xx)
return true;
if (pp + xx <= l && *lower_bound(arr, arr + n, pp + xx) == pp + xx)
return true;
return false;
}
bool check2(int p, int off) {
if (p < 0 || p > l) return false;
if (p + off < 0 || p + off > l) return false;
return *lower_bound(arr, arr + n, p + off) == p + off;
}
int main() {
ios_base::sync_with_stdio(0);
cin >> n >> l >> x >> y;
for (int i = 0; i < n; ++i) cin >> arr[i];
bool fst = false, scd = false;
for (int i = 0; i < n; ++i) {
fst |= check(arr[i], x);
scd |= check(arr[i], y);
}
if (fst & scd) {
cout << 0 << '\n';
} else if (scd) {
cout << 1 << '\n' << x << '\n';
} else if (fst) {
cout << 1 << '\n' << y << '\n';
} else {
bool f = false;
for (int i = 0; i < n && !f; ++i) {
int pos = arr[i];
if (check2(pos - x, y) || check2(pos - x, -y)) {
cout << 1 << '\n' << pos - x << '\n';
f = true;
} else if (check2(pos + x, y) || check2(pos + x, -y)) {
cout << 1 << '\n' << pos + x << '\n';
f = true;
}
}
if (!f) cout << 2 << '\n' << x << ' ' << y << '\n';
}
cin >> n;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
template <class T>
bool umin(T& a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
template <class T>
bool umax(T& a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
int arr[100009];
map<int, int> pm, hs;
int main() {
int n, l, x, y;
scanf("%d%d%d%d", &n, &l, &x, &y);
for (int i = 1; i <= n; i++) scanf("%d", arr + i), pm[arr[i]] = 1;
int dx = 0, dy = 0;
for (int i = 1; i <= n; i++) {
if (pm[arr[i] + x] or pm[arr[i] - x]) dx = 1;
if (pm[arr[i] + y] or pm[arr[i] - y]) dy = 1;
if (arr[i] + x <= l) hs[arr[i] + x] = 1;
if (arr[i] - x >= 0) hs[arr[i] - x] = 1;
}
if (dx or dy) {
if (dx and dy)
printf("0\n");
else if (dx)
printf("1\n%d\n", y);
else
printf("1\n%d\n", x);
return 0;
}
for (int i = 1; i <= n; i++) {
if (hs[arr[i] + y] or hs[arr[i] - y]) {
if (hs[arr[i] + y] and arr[i] + y <= l) {
printf("1\n%d\n", arr[i] + y);
return 0;
} else if (hs[arr[i] - y] and arr[i] - y >= 0) {
printf("1\n%d\n", arr[i] - y);
return 0;
}
}
}
printf("2\n%d %d\n", x, y);
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target( \
"avx,avx2,fma,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
long long MOD = 1e9 + 7;
int main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0),
cout << fixed << setprecision(20);
long long n, l, x, y;
cin >> n >> l >> x >> y;
set<long long> q;
for (int i = 0; i < n; i++) {
long long a;
cin >> a;
q.insert(a);
}
long long fl1 = 0, fl2 = 0;
for (auto i : q) {
if (q.count(i + x) || q.count(i - x)) {
fl1 = 1;
}
if (q.count(i + y) || q.count(i - y)) {
fl2 = 1;
}
}
if (fl1 && fl2) {
cout << 0;
return 0;
}
if (fl1 || fl2) {
cout << 1 << endl;
if (!fl1)
cout << x;
else
cout << y;
return 0;
}
set<long long> q2;
for (auto i : q) {
if (0 <= i - x) q2.insert(i - x);
if (i + x <= l) q2.insert(i + x);
}
for (auto i : q) {
if (q2.count(i - y) || q2.count(i + y)) {
cout << 1 << endl;
if (q2.count(i - y))
cout << i - y;
else
cout << i + y;
return 0;
}
}
cout << 2 << endl;
cout << x << " " << y;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int n, l, x, y, sxy;
int a[105000];
bool fx, fy, fxy;
set<long long> s;
int main() {
s.clear();
scanf("%d %d %d %d", &n, &l, &x, &y);
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
s.insert((long long)a[i]);
}
fx = fy = fxy = false;
for (int i = 0; i < n; i++) {
long long tmp;
if (!fx) {
tmp = a[i];
tmp = tmp + x;
if (s.find(tmp) != s.end()) fx = true;
}
if (!fy) {
tmp = a[i];
tmp = tmp + y;
if (s.find(tmp) != s.end()) fy = true;
}
if (!fxy) {
tmp = a[i];
tmp = tmp + x + y;
if (s.find(tmp) != s.end()) {
sxy = a[i] + x;
fxy = true;
continue;
}
tmp = a[i];
tmp = tmp + x - y;
if (s.find(tmp) != s.end()) {
long long tt = a[i];
tt = tt + x;
if (tt <= l) {
sxy = a[i] + x;
fxy = true;
continue;
} else {
tt = a[i];
tt = tt - y;
if (tt >= 0) {
sxy = a[i] - y;
fxy = true;
continue;
}
}
}
tmp = a[i];
tmp = tmp + y - x;
if (s.find(tmp) != s.end()) {
long long tt = a[i];
tt = tt + y;
if (tt <= l) {
sxy = a[i] + y;
fxy = true;
continue;
} else {
tt = a[i];
tt = tt - x;
if (tt >= 0) {
sxy = a[i] - x;
fxy = true;
continue;
}
}
}
}
}
int cnt = 0;
cnt = fx + fy;
if (cnt == 2)
puts("0");
else if (cnt == 1) {
printf("1\n");
if (fx) printf("%d\n", y);
if (fy) printf("%d\n", x);
} else {
if (fxy) {
printf("1\n");
printf("%d\n", sxy);
} else {
printf("2\n");
printf("%d %d\n", x, y);
}
}
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 4;
int n, l, x, y, a[MAXN], xf = 0, yf = 0, f = -1;
bool bs(int lo, int hi, int c) {
int mid;
while (lo < hi) {
mid = (lo + hi) / 2;
if (a[mid] >= c)
hi = mid;
else
lo = mid + 1;
}
return (lo != n && a[lo] == c);
}
int main() {
cin >> n >> l >> x >> y;
for (int i = 0; i < n; i++) cin >> a[i];
for (int i = 0; i < n; i++) {
if (bs(0, n, x + a[i])) xf = 1;
if (bs(0, n, y + a[i])) yf = 1;
}
if (!xf && !yf) {
for (int i = 0; i < n; i++) {
if (a[i] + x <= l) {
if (bs(0, n, a[i] + x - y) || bs(0, n, a[i] + x + y)) {
f = a[i] + x;
break;
}
}
if (a[i] - x >= 0) {
if (bs(0, n, a[i] - x - y) || bs(0, n, a[i] - x + y)) {
f = a[i] - x;
break;
}
}
}
for (int i = 0; i < n; i++) {
if (a[i] + y <= l) {
if (bs(0, n, a[i] + y - x) || bs(0, n, a[i] + y + x)) {
f = a[i] + y;
break;
}
}
if (a[i] - y >= 0) {
if (bs(0, n, a[i] - y - x) || bs(0, n, a[i] - y + x)) {
f = a[i] - y;
break;
}
}
}
if (f != -1)
cout << 1 << endl << f;
else
cout << 2 << endl << x << ' ' << y;
} else if (!xf)
cout << 1 << endl << x;
else if (!yf)
cout << 1 << endl << y;
else
cout << 0;
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int n, L, fx, fy, ans;
int a[100010];
set<int> aa, x;
int main() {
int i, canx = 0, cany = 0, tmp;
scanf("%d%d%d%d", &n, &L, &fx, &fy);
for (i = 1; i <= n; i++) {
scanf("%d", &a[i]);
aa.insert(a[i]);
}
for (i = 1; i <= n; i++) {
if (!canx) {
tmp = a[i] + fx;
if (aa.find(tmp) != aa.end()) canx = 1;
}
if (!cany) {
tmp = a[i] + fy;
if (aa.find(tmp) != aa.end()) cany = 1;
}
}
if (canx && cany) {
printf("0\n");
return 0;
}
if (canx + cany == 1) {
printf("1\n");
if (!canx)
printf("%d\n", fx);
else
printf("%d\n", fy);
return 0;
}
ans = -1;
for (i = 1; i <= n; i++) {
tmp = a[i] + fx;
if (tmp >= 0 && tmp <= L) x.insert(tmp);
tmp = a[i] - fx;
if (tmp >= 0 && tmp <= L) x.insert(tmp);
}
for (i = 1; i <= n; i++) {
tmp = a[i] + fy;
if (tmp >= 0 && tmp <= L && x.find(tmp) != x.end()) {
ans = tmp;
break;
}
tmp = a[i] - fy;
if (tmp >= 0 && tmp <= L && x.find(tmp) != x.end()) {
ans = tmp;
break;
}
}
if (ans != -1) {
printf("1\n");
printf("%d\n", ans);
} else {
printf("2\n");
printf("%d %d\n", fx, fy);
}
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
inline int toInt(string s) {
int i;
stringstream(s) >> i;
return i;
}
inline string toString(long long i) {
string s;
stringstream ss;
ss << i;
ss >> s;
return s;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, l, x, y, fx = 1, fy = 1, f = 0, tmp = -1;
cin >> n >> l >> x >> y;
vector<int> v(n);
for (int i = 0; i < n; i++) cin >> v[i];
map<int, bool> m;
for (int i = 0; i < n; i++) m[v[i]] = 1;
for (int i = 0; i < n; i++) {
if (m[v[i] + x]) fx = 0;
if (m[v[i] + y]) fy = 0;
}
if (fx && fy) {
for (int i = 0; i < n; i++) {
if ((v[i] + x) < l) {
if (m[v[i] + x + y] || m[v[i] + x - y]) {
f = 1;
tmp = v[i] + x;
}
}
if ((v[i] + y) < l) {
if (m[v[i] + y + x] || m[v[i] + y - x]) {
f = 1;
tmp = v[i] + y;
}
}
if ((v[i] - x) > 0) {
if (m[v[i] - x + y] || m[v[i] - x - y]) {
f = 1;
tmp = v[i] - x;
}
}
if ((v[i] - y) > 0) {
if (m[v[i] - y + x] || m[v[i] - y - x]) {
f = 1;
tmp = v[i] - y;
}
}
}
if (f) {
cout << 1 << endl;
cout << tmp << endl;
} else {
cout << 2 << endl;
cout << x << ' ' << y << endl;
}
} else if (fx || fy) {
cout << 1 << endl;
if (fx) cout << x << endl;
if (fy) cout << y << endl;
} else
cout << 0 << endl;
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline int size(const T& c) {
return c.size();
}
using namespace std;
int fastMax(int x, int y) { return (((y - x) >> (32 - 1)) & (x ^ y)) ^ y; }
int fastMin(int x, int y) { return (((y - x) >> (32 - 1)) & (x ^ y)) ^ x; }
const int maxn = 100000 + 10;
int a[maxn];
map<int, bool> ma;
map<int, bool> ma1;
map<int, bool> ma2;
int l, x, y, n;
bool ok1, ok2;
int main() {
scanf("%d%d%d%d", &n, &l, &x, &y);
ma.clear();
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
if (a[i] >= x && ma[a[i] - x]) ok1 = true;
if (a[i] >= y && ma[a[i] - y]) ok2 = true;
ma[a[i]] = true;
if (a[i] >= x) ma1[a[i] - x] = true;
if (a[i] + x <= l) ma1[a[i] + x] = true;
if (a[i] >= y) ma2[a[i] - y] = true;
if (a[i] + y <= l) ma2[a[i] + y] = true;
}
if (ok1 && ok2) {
cout << 0;
} else if (ok1 || ok2) {
if (ok1) {
cout << 1 << endl;
cout << y;
}
if (ok2) {
cout << 1 << endl;
cout << x << endl;
}
} else {
for (__typeof((ma2).begin()) it = (ma2).begin(); it != (ma2).end(); it++) {
int u = (*it).first;
if (ma1[u] && ma2[u]) {
cout << 1 << endl;
cout << u << endl;
return 0;
}
}
cout << 2 << endl;
cout << x << ' ' << y << endl;
}
fclose(stdin);
fclose(stdout);
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
long long MOD = int(1e9) + 7;
long long powmod(long long num, long long power) {
if (power == 0) return 1 % MOD;
if (power == 1) return num % MOD;
long long t = powmod(num, power / 2) % MOD;
return power % 2 ? t * t % MOD * num % MOD : t * t % MOD;
}
long long pow1(long long num, long long power) {
if (power == 0) return 1;
if (power == 1) return num;
long long t = pow1(num, power / 2);
return power % 2 ? t * t * num : t * t;
}
int check(int);
int binarysearch(int len) {
int lo = 1, hi = len, mid, flag;
while (lo <= hi) {
mid = hi + lo >> 1;
(flag = check(mid)) ? lo = mid + 1 : hi = mid - 1;
}
return mid - 1 + flag;
}
const int N = 1000 * 100 + 5;
int debug = 1;
int check(int a) { return a; }
inline int inp() {
int n = 0, s = 1, c = getchar();
if (c == '-') s = -1;
while (c < 48) c = getchar();
while (c > 47) n = (n << 3) + (n << 1) + c - '0', c = getchar();
return n * s;
}
long long a[N];
set<long long> s;
int main() {
ios::sync_with_stdio(false);
long long i, j, n, t, l, x, y;
long long X = 0, Y = 0;
cin >> n >> l >> x >> y;
for (i = 0; i < n; i++) {
cin >> a[i];
s.insert(a[i]);
}
for (i = 0; i < n; i++) {
if (s.find(a[i] + x) != s.end()) X = 1;
if (s.find(a[i] + y) != s.end()) Y = 1;
}
if (X == 1 && Y == 1) {
cout << 0;
} else if (X == 1) {
cout << 1 << endl << y;
} else if (Y == 1) {
cout << 1 << endl << x;
} else {
int flag = 0, cur = -1;
for (i = 0; i < n; i++) {
if (s.find(a[i] + x + y) != s.end()) {
flag = 1;
cur = a[i] + x;
}
if (s.find(a[i] + y - x) != s.end() && a[i] + y <= l) {
flag = 1;
cur = a[i] + y;
}
if (s.find(a[i] + y - x) != s.end() && a[i] - x >= 0) {
flag = 1;
cur = a[i] - x;
}
if (s.find(a[i] + x - y) != s.end() && a[i] - y >= 0) {
flag = 1;
cur = a[i] - y;
}
if (s.find(a[i] + x - y) != s.end() && a[i] + x <= l) {
flag = 1;
cur = a[i] + x;
}
}
if (flag == 0) {
cout << 2 << endl << x << " " << y;
} else {
cout << 1 << endl << cur;
}
}
cin >> i;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int MAX = 110000;
set<int> mark, add;
vector<int> A;
vector<int> B;
int main() {
int val, n, l, x, y;
scanf("%d", &n);
scanf("%d", &l);
scanf("%d", &x);
scanf("%d", &y);
for (int i = 0; i < n; i++) {
scanf("%d", &val);
mark.insert(val);
}
int a = -1, b = -1;
int fa = false, fb = false;
for (set<int>::iterator it = mark.begin(); it != mark.end(); it++) {
int val = (*it);
int d = (val - x);
if (d >= 0) {
if (mark.find(d) != mark.end()) {
fa = true;
break;
} else {
A.push_back((d));
}
}
d = val + x;
if (d > l) continue;
if (mark.find(d) != mark.end()) {
fa = true;
break;
} else {
A.push_back((d));
}
}
for (set<int>::iterator it = mark.begin(); it != mark.end(); it++) {
int val = (*it);
int d = (val - y);
if (d >= 0) {
if (mark.find(d) != mark.end()) {
fb = true;
break;
} else {
B.push_back((d));
}
}
d = val + y;
if (d > l) continue;
if (mark.find(d) != mark.end()) {
fb = true;
break;
} else {
B.push_back((d));
}
}
if (fa && fb) {
cout << 0 << endl;
} else if (fa && !fb) {
cout << 1 << endl;
cout << B[0] << endl;
} else if (!fa && fb) {
cout << 1 << endl;
cout << A[0] << endl;
} else {
sort(A.begin(), A.end());
cout << endl;
for (int i = 0; i < ((int)B.size()); i++) {
if (binary_search(A.begin(), A.end(), B[i])) {
cout << 1 << endl;
cout << B[i] << endl;
return 0;
}
}
cout << 2 << endl;
if (A[0] > B[0]) swap(A[0], B[0]);
cout << A[0] << " " << B[0] << endl;
}
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
template <class T>
inline T tmin(T a, T b) {
return (a < b) ? a : b;
}
template <class T>
inline T tmax(T a, T b) {
return (a > b) ? a : b;
}
template <class T>
inline void add_max(T &a, T b) {
if (b > a) a = b;
}
template <class T>
inline void add_min(T &a, T b) {
if (b < a) a = b;
}
template <class T>
inline T tabs(T a) {
return (a > 0) ? a : -a;
}
template <class T>
T gcd(T a, T b) {
if (b == 0) return a;
return gcd(b, a % b);
}
int main(int argc, char *argv[]) {
ios_base::sync_with_stdio(false);
int n, l, x, y;
cin >> n >> l >> x >> y;
vector<int> a(n);
int ans = 2;
bool tx = false, ty = false;
for (int i = (0); i < (n); ++i) {
cin >> a[i];
}
for (int i = (0); i < (n); ++i) {
if (binary_search(a.begin(), a.end(), a[i] + x)) tx = true;
if (binary_search(a.begin(), a.end(), a[i] + y)) ty = true;
}
if (tx && ty) {
printf("%d\n", 0);
return 0;
}
if (tx || ty) {
if (!tx)
printf("%d\n%d\n", 1, x);
else
printf("%d\n%d\n", 1, y);
return 0;
}
for (int i = (0); i < (n); ++i) {
if (a[i] >= x) {
if (binary_search(a.begin(), a.end(), a[i] - x - y)) {
printf("%d\n%d\n", 1, a[i] - x);
return 0;
}
if (binary_search(a.begin(), a.end(), a[i] - x + y)) {
printf("%d\n%d\n", 1, a[i] - x);
return 0;
}
}
if (a[i] + x <= l) {
if (binary_search(a.begin(), a.end(), a[i] + x - y)) {
printf("%d\n%d\n", 1, a[i] + x);
return 0;
}
if (binary_search(a.begin(), a.end(), a[i] + x + y)) {
printf("%d\n%d\n", 1, a[i] + x);
return 0;
}
}
}
printf("%d\n%d %d\n", 2, x, y);
return 0;
}
| 8 | CPP |
# -*- coding: utf-8 -*-
import math
import collections
import bisect
import heapq
import time
import random
import itertools
import sys
from typing import List
"""
created by shhuan at 2020/1/13 20:48
"""
def solve(N, L, X, Y, A):
vs = set(A)
mx = any([a+X in vs for a in A])
my = any([a+Y in vs for a in A])
if mx and my:
print(0)
elif mx:
print(1)
print(Y)
elif my:
print(1)
print(X)
else:
# try to add 1 mark
for a in vs:
for b, c in [(a + X, Y), (a + Y, X), (a - X, Y), (a - Y, X)]:
if 0 <= b <= L:
if (b + c <= L and b + c in vs) or (b - c >= 0 and b - c in vs):
print(1)
print(b)
return
# add 2 marks
print(2)
print('{} {}'.format(X, Y))
N, L, X, Y = map(int, input().split())
A = [int(x) for x in input().split()]
solve(N, L, X, Y, A) | 8 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
long long n, l, x, y;
map<long long, bool> mp;
int a[100005];
void chk(int d, int t) {
if (d < 0 || d > l) return;
if ((mp[d + t] || mp[d - t])) {
cout << 1 << endl << d;
exit(0);
}
}
int main() {
bool fst = false, sec = false;
cin >> n >> l >> x >> y;
for (int i = 0; i < n; i++) {
cin >> a[i];
mp[a[i]] = true;
}
for (int i = 0; i < n; i++) {
if (mp[a[i] - x]) fst = true;
if (mp[a[i] + x]) fst = true;
if (mp[a[i] - y]) sec = true;
if (mp[a[i] + y]) sec = true;
}
if (fst && sec) {
cout << 0;
return 0;
} else if (fst && !sec) {
cout << 1 << endl << y;
return 0;
} else if (!fst && sec) {
cout << 1 << endl << x;
return 0;
} else {
for (int i = 0; i < n; i++) {
chk(a[i] + x, y);
chk(a[i] - x, y);
chk(a[i] + y, x);
chk(a[i] - y, x);
}
cout << 2 << endl << x << ' ' << y;
return 0;
}
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100007;
int l, x, y, z, n;
int a[maxn];
bool foundX, foundY, foundZ;
set<int> mys;
int main() {
scanf("%d%d%d%d", &n, &l, &x, &y);
z = x + y;
foundX = foundY = foundZ = 0;
int pz;
for (int i = 1; i <= n; ++i) {
scanf("%d", &a[i]);
mys.insert(a[i]);
}
for (int i = 1; i <= n; ++i) {
if (mys.find(a[i] - x) != mys.end()) foundX = 1;
if (mys.find(a[i] - y) != mys.end()) foundY = 1;
if (mys.find(a[i] - x - y) != mys.end()) {
foundZ = 1;
pz = a[i] - y;
}
if (mys.find(a[i] + (y - x)) != mys.end() && a[i] - x >= 0) {
foundZ = 1;
pz = a[i] - x;
}
if (mys.find(a[i] - (y - x)) != mys.end() && a[i] + x <= l) {
foundZ = 1;
pz = a[i] + x;
}
}
if (foundX && foundY) {
puts("0");
} else if (foundX || foundY) {
puts("1");
if (foundX)
printf("%d", y);
else
printf("%d", x);
} else if (foundZ) {
puts("1");
printf("%d", pz);
} else {
puts("2");
printf("%d %d", x, y);
}
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
int a[100002], frist, mid, es, n;
using namespace std;
int main() {
int t1 = 0, t2 = 0, t3 = 0, t4 = 0;
int ants = 2, p = -1, q = 0;
int i, l, x, y;
cin >> n;
cin >> l >> x >> y;
for (i = 1; i <= n; i++) cin >> a[i];
for (i = 1; i < n + 1; i++) {
if (binary_search(a, a + n + 1, a[i] + x)) t1 = 1;
if (binary_search(a, a + n + 1, a[i] + y)) t2 = 1;
if (binary_search(a, a + n + 1, a[i] + x + y)) {
t3 = 1;
p = a[i];
}
if (binary_search(a, a + n + 1, a[i] + y - x) &&
((a[i] + y <= l) || (a[i] - x >= 0))) {
t4 = 1;
p = a[i];
}
}
if (t1) {
ants--;
q = 1;
}
if (t2) {
ants--;
q = 2;
}
if (ants == 2 && (t3 || t4)) {
ants--;
}
cout << ants << endl;
if (ants == 2) cout << a[1] + x << " " << a[1] + y << endl;
if (ants == 1) {
if (p == -1) {
if (q == 1) {
cout << a[1] + y << endl;
} else
cout << a[1] + x << endl;
} else {
if (p + y <= l)
cout << p + y << endl;
else
cout << p - x << endl;
}
}
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
int nextInt(void) {
char ch;
int sign, x;
do {
ch = getchar();
} while (ch < '-');
if (ch == '-') {
sign = -1;
ch = getchar();
} else
sign = 1;
x = 0;
while (ch >= '0' && ch <= '9') {
x = x * 10 + ch - '0';
ch = getchar();
}
return sign * x;
}
int binarySearch(int *data, int n, int key) {
int l = 0, r = n - 1, m;
while (l <= r) {
m = (l + r) / 2;
if (key == data[m])
return 1;
else if (key < data[m])
r = m - 1;
else
l = m + 1;
}
return 0;
}
int a[100000];
int main(void) {
int i;
int n, l, x, y;
int flag;
scanf("%d %d %d %d", &n, &l, &x, &y);
for (i = 0; i < n; i++) a[i] = nextInt();
flag = 0;
for (i = 0; i < n && a[i] + x <= a[n - 1]; i++)
if (binarySearch(a, n, a[i] + x)) {
flag |= 1;
break;
}
for (i = 0; i < n && a[i] + y <= a[n - 1]; i++)
if (binarySearch(a, n, a[i] + y)) {
flag |= 2;
break;
}
switch (flag) {
case 0:
for (i = 0; i < n; i++)
if (a[i] + x <= a[n - 1] && (binarySearch(a, n, a[i] + x - y) ||
binarySearch(a, n, a[i] + x + y))) {
printf("%d\n%d\n", 1, a[i] + x);
return 0;
} else if (a[i] - x >= 0 && binarySearch(a, n, a[i] - x + y)) {
printf("%d\n%d\n", 1, a[i] - x);
return 0;
}
printf("%d\n%d %d\n", 2, x, y);
break;
case 1:
printf("%d\n%d\n", 1, y);
break;
case 2:
printf("%d\n%d\n", 1, x);
break;
case 3:
puts("0");
break;
}
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 122222;
int arr[maxn], n;
int l[maxn], r[maxn], len, ll, maxl, maxr, minl, minr;
bool get_val(int x) {
if (x > ll) return 0;
len = 0;
for (int i = 1; i < n; i++) {
int head = i + 1, tail = n;
if (arr[tail] - arr[i] < x)
continue;
else if (arr[tail] - arr[i] == x) {
l[len] = i, r[len] = head;
len++;
} else if (arr[head] - arr[i] > x)
continue;
{
while (tail - head > 1) {
int mid = (tail + head) / 2;
if (arr[mid] - arr[i] <= x)
head = mid;
else
tail = mid;
}
if (arr[head] - arr[i] == x) {
l[len] = i, r[len] = head;
len++;
}
}
}
maxl = -1, minl = 0x3f3f3f3f;
for (int i = 0; i < len; i++) {
if (arr[l[i]] > maxl) maxl = arr[l[i]], maxr = arr[r[i]];
if (arr[l[i]] < minl) minl = arr[l[i]], minr = arr[r[i]];
}
return len != 0;
}
int main() {
int x, y;
while (~scanf("%d%d%d%d", &n, &ll, &x, &y)) {
for (int i = 1; i <= n; i++) scanf("%d", arr + i);
int flag = 0;
if (get_val(x)) flag |= 1;
if (get_val(y)) flag |= 2;
if (flag == 3) {
puts("0");
} else if (flag == 2) {
printf("1\n%d\n", x);
} else if (flag == 1) {
printf("1\n%d\n", y);
} else {
flag = 0;
if (get_val(x + y)) {
printf("1\n%d\n", minl + x);
continue;
} else if (get_val(y - x)) {
if (ll - minr >= x) {
printf("1\n%d\n", minr + x);
continue;
} else if (maxl >= x) {
printf("1\n%d\n", maxl - x);
continue;
}
}
printf("2\n%d %d\n", x, y);
}
}
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, l, x, y;
set<long long> Set;
while (cin >> n >> l >> x >> y) {
for (int i = 1; i <= n; ++i) {
long long t;
scanf("%I64d", &t);
Set.insert(t);
}
bool checkx = 0;
bool checky = 0;
for (set<long long>::iterator it = Set.begin(); it != Set.end(); it++) {
if (Set.find(*it + x) != Set.end()) {
checkx = 1;
}
if (Set.find(*it + y) != Set.end()) {
checky = 1;
}
if (checkx && checky) {
break;
}
}
if (checkx && checky) {
cout << 0 << endl;
break;
}
if (checkx) {
cout << 1 << endl;
cout << y << endl;
break;
}
if (checky) {
cout << 1 << endl;
cout << x << endl;
break;
}
bool find = 0;
long long ans = 0;
for (set<long long>::iterator it = Set.begin(); it != Set.end(); it++) {
if ((*it + x <= l) && Set.find(*it + x + y) != Set.end()) {
find = 1;
ans = *it + x;
break;
}
if ((*it + x <= l) && Set.find(*it + x - y) != Set.end()) {
find = 1;
ans = *it + x;
break;
}
if ((*it - x >= 0) && Set.find(*it - x + y) != Set.end()) {
find = 1;
ans = *it - x;
break;
}
if ((*it - x >= 0) && Set.find(*it - x - y) != Set.end()) {
find = 1;
ans = *it - x;
break;
}
}
if (find) {
cout << 1 << endl;
cout << ans << endl;
break;
}
cout << 2 << endl;
cout << x << " " << y << endl;
}
return 0;
}
| 8 | CPP |
def fastio():
import sys
from io import StringIO
from atexit import register
global input
sys.stdin = StringIO(sys.stdin.read())
input = lambda : sys.stdin.readline().rstrip('\r\n')
sys.stdout = StringIO()
register(lambda : sys.__stdout__.write(sys.stdout.getvalue()))
fastio()
MOD = 10**9 + 7
I = lambda:list(map(int,input().split()))
n, l, x, y = I()
a = I()
s = set(a)
f = 0
for i in range(n):
if a[i] + x in s:
break
else:
f = 1
for i in range(n):
if a[i] + y in s:
break
else:
f += 2
if f == 1:
print(1)
print(x)
elif f == 2:
print(1)
print(y)
elif f == 0:
print(0)
else:
for i in range(n):
k = a[i] + x
if 0 <= k <= l and ((k - y >= 0 and (k-y) in s) or ((k+y) <= l and (k+y) in s)):
print(1)
print(k)
exit()
k = a[i] - x
if 0 <= k <= l and ((k - y >= 0 and (k-y) in s) or ((k+y) <= l and (k+y) in s)):
print(1)
print(k)
exit()
for i in range(n):
k = a[i] + y
if 0 <= k <= l and (k - x >= 0 and (k-x) in s or (k+x) <= l and (k+x) in s):
print(1)
print(k)
break
k = a[i] - y
if 0 <= k <= l and (k - x >= 0 and (k-x) in s or (k+x) <= l and (k+x) in s):
print(1)
print(k)
break
else:
print(2)
print(x, y)
| 8 | PYTHON3 |
#include <bits/stdc++.h>
const long long INF = 1000000007;
const double cp = 2 * asin(1.0);
const double eps = 1e-9;
const long long mod = 1000000007;
using namespace std;
int main() {
cin.tie(NULL);
ios_base::sync_with_stdio(false);
map<int, int> a;
map<int, int> dif;
map<int, int>::iterator it;
int n, l, x, y, b[1000005];
bool fx = false, fy = false;
cin >> n >> l >> x >> y;
int mini = 1e9, maxi = 0;
for (int i = 1; i <= n; ++i) {
cin >> b[i];
a[b[i]]++;
mini = min(mini, b[i]);
maxi = max(maxi, b[i]);
dif[b[i] - x]++;
dif[b[i] + x]++;
}
for (int i = 1; i <= n; ++i) {
if (a.find(b[i] + x)->second != 0) fx = true;
if (a.find(b[i] - x)->second != 0) fx = true;
if (a.find(b[i] + y)->second != 0) fy = true;
if (a.find(b[i] - y)->second != 0) fy = true;
}
if (fx && fy) {
cout << 0;
return 0;
}
for (int i = 1; i <= n; ++i) {
if (dif.find(b[i] - y)->second != 0 && b[i] - y > 0 && b[i] - y <= l) {
cout << 1 << endl;
cout << abs(b[i] - y) << endl;
return 0;
}
if (dif.find(b[i] + y)->second != 0 && b[i] + y > 0 && b[i] + y <= l) {
cout << 1 << endl;
cout << abs(b[i] + y) << endl;
return 0;
}
}
vector<int> ans;
if (!fx) {
if (mini + x > l)
ans.push_back(maxi - x);
else
ans.push_back(mini + x);
}
if (!fy) {
if (mini + y > l)
ans.push_back(maxi - y);
else
ans.push_back(mini + y);
}
cout << ans.size() << endl;
for (int i = 0; i < ans.size(); ++i) cout << ans[i] << ' ';
cout << endl;
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
map<int, int> beg, X;
set<int> Y;
int n, l, x, y;
int main() {
int p, ansx, ansy;
bool a = false, b = false;
int c = 0;
scanf("%d%d%d%d", &n, &l, &x, &y);
for (int i = 0; i < n; i++) {
scanf("%d", &p);
beg[p] = 1;
if (p >= x) {
X[p - x] = 1;
if (beg[p - x]) a = true;
}
if (p >= y) {
Y.insert(p - y);
if (beg[p - y]) b = true;
}
if (p + y <= l) {
Y.insert(p + y);
}
if (p + x <= l) {
X[p + x] = 1;
}
}
int ans;
if (a && b)
printf("0\n");
else if (a) {
printf("1\n%d\n", y);
} else if (b) {
printf("1\n%d\n", x);
} else {
set<int>::iterator it = Y.begin();
bool flag = false;
for (it; it != Y.end(); it++) {
if (X[*it]) {
printf("1\n%d\n", *it);
flag = true;
break;
}
}
if (!flag) printf("2\n%d %d\n", x, y);
}
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int n, mark_len, girl, boy;
int mark[100005];
void input() {
scanf("%d%d%d%d", &n, &mark_len, &girl, &boy);
for (int i = 0; i < n; i++) {
scanf("%d", &mark[i]);
}
}
bool find(int a) {
int* p = lower_bound(mark, mark + n, a);
if (p == mark + n) return false;
return a == *p;
}
void work() {
bool found_boy = false;
bool found_girl = false;
for (int i = 0; i < n; i++) {
found_boy = found_boy || find(mark[i] + boy);
found_girl = found_girl || find(mark[i] + girl);
}
if (found_boy && found_girl) {
puts("0");
return;
}
if (found_boy) {
puts("1");
printf("%d\n", girl);
return;
}
if (found_girl) {
puts("1");
printf("%d\n", boy);
return;
}
for (int i = 0; i < n; i++) {
if ((find(mark[i] + girl - boy) && mark[i] + girl <= mark_len) ||
find(mark[i] + girl + boy)) {
printf("1\n%d\n", mark[i] + girl);
return;
}
if (find(mark[i] - girl + boy) && mark[i] - girl >= 0) {
printf("1\n%d\n", mark[i] - girl);
return;
}
}
printf("2\n%d %d\n", girl, boy);
}
int main() {
input();
work();
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
static const auto INF = std::numeric_limits<int>::max();
bool check_default(int x, int l, const std::set<int>& marks) {
for (auto p : marks) {
if (marks.count(p + x)) {
return true;
}
if (marks.count(p - x)) {
return true;
}
}
return false;
}
bool check(int p, int y, int l, const std::set<int>& marks) {
if (p < 1 || p > l) {
return false;
}
return marks.count(p - y) || marks.count(p + y);
}
int main() {
int n, l, x, y;
std::cin >> n >> l >> x >> y;
std::set<int> marks;
for (int i = 0; i < n; ++i) {
int a;
std::cin >> a;
marks.insert(a);
}
auto xok = check_default(x, l, marks);
auto yok = check_default(y, l, marks);
std::vector<int> ans;
if (!xok && !yok) {
for (auto p : marks) {
if (check(p + x, y, l, marks)) {
ans.push_back(p + x);
break;
}
if (check(p - x, y, l, marks)) {
ans.push_back(p - x);
break;
}
}
if (ans.empty()) {
ans.push_back(x);
ans.push_back(y);
}
} else if (xok && !yok) {
ans.push_back(y);
} else if (!xok && yok) {
ans.push_back(x);
}
std::cout << ans.size() << std::endl;
if (!ans.empty()) {
std::copy(std::begin(ans), std::end(ans),
std::ostream_iterator<int>(std::cout, " "));
std::cout << std::endl;
}
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, l, x, y;
cin >> n >> l >> x >> y;
set<int> s;
bool b = false, g = false;
vector<int> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
s.insert(a[i]);
}
for (int i = 0; i < n; i++) {
if (s.count(a[i] - x) > 0) b = true;
if (s.count(a[i] - y) > 0) g = true;
}
if (b && g) {
cout << 0;
return 0;
}
if ((g && !b) || (!g && b)) {
if (!b) cout << 1 << endl << a.back() - x;
if (!g) cout << 1 << endl << a.back() - y;
return 0;
}
for (int i = 0; i < n; i++) {
if (a[i] - x >= 0) {
int pos = a[i] - x;
if (s.count(pos - y) > 0 || s.count(pos + y) > 0) {
cout << 1 << endl << pos;
return 0;
}
}
int pos = a[i] + x;
if ((pos <= l) && (s.count(pos - y) > 0 || s.count(pos + y) > 0)) {
cout << 1 << endl << pos;
return 0;
}
}
cout << 2 << endl << a.back() - x << " " << a.back() - y;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
const long long N = 100011;
vector<long long> v;
long long dist[2];
bool ok[2];
bool puede(long long l, long long n) {
for (long long i = 0; i < n; i++) {
long long pos = lower_bound(v.begin(), v.end(), v[i] + l) - v.begin();
if (pos == n) break;
if (v[pos] == v[i] + l) {
return true;
}
}
return false;
}
bool puede2(long long l, long long n) {
long long pos = lower_bound(v.begin(), v.end(), l) - v.begin();
if (pos == n) return false;
if (v[pos] == l) {
return true;
}
return false;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.precision(10);
cout << fixed;
long long n, l, q;
cin >> n >> l >> dist[0] >> dist[1];
for (long long i = 0; i < n; i++) {
cin >> q;
v.push_back(q);
}
for (long long i = 0; i < 2; i++) {
ok[i] = puede(dist[i], n);
}
if (ok[0] && ok[1]) {
cout << 0 << endl;
return 0;
}
if (ok[0] || ok[1]) {
cout << 1 << endl;
if (ok[0]) {
cout << dist[1] << endl;
} else {
cout << dist[0] << endl;
}
return 0;
}
for (long long i = 0; i < n; i++) {
long long pos =
lower_bound(v.begin(), v.end(), v[i] + dist[1] + dist[0]) - v.begin();
if (pos == n) break;
if (v[pos] == v[i] + dist[1] + dist[0]) {
cout << 1 << endl;
cout << v[i] + dist[0] << endl;
return 0;
}
}
for (long long i = 0; i < n; i++) {
if (0 <= v[i] - dist[0] && puede2(v[i] - dist[0] + dist[1], n)) {
cout << 1 << endl;
cout << v[i] - dist[0] << endl;
return 0;
}
if (0 <= v[i] - dist[1] && puede2(v[i] - dist[1] + dist[0], n)) {
cout << 1 << endl;
cout << v[i] - dist[1] << endl;
return 0;
}
if (v[i] + dist[1] <= v[n - 1] && puede2(v[i] - dist[0] + dist[1], n)) {
cout << 1 << endl;
cout << v[i] + dist[1] << endl;
return 0;
}
if (v[i] + dist[0] <= v[n - 1] && puede2(v[i] - dist[1] + dist[0], n)) {
cout << 1 << endl;
cout << v[i] + dist[0] << endl;
return 0;
}
}
cout << 2 << endl;
cout << dist[0] << " ";
cout << dist[1] << endl;
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int n, m, x, y, a[100001];
set<int> events;
int main() {
scanf("%d%d%d%d", &n, &m, &x, &y);
events.clear();
for (int i = 1; i <= n; i++) scanf("%d", &a[i]), events.insert(a[i]);
int status = 0;
for (int i = 1; i <= n; i++) {
int z = a[i] - x;
if (z > 0 && events.find(z) != events.end()) status |= 1;
z = a[i] + x;
if (z <= m && events.find(z) != events.end()) status |= 1;
z = a[i] - y;
if (z > 0 && events.find(z) != events.end()) status |= 2;
z = a[i] + y;
if (z <= m && events.find(z) != events.end()) status |= 2;
}
if (status == 3) {
printf("0\n");
return 0;
} else if (status == 1) {
printf("1\n%d\n", y);
return 0;
} else if (status == 2) {
printf("1\n%d\n", x);
return 0;
} else {
events.clear();
for (int i = 1; i <= n; i++) {
int z = a[i] - x;
if (z > 0) events.insert(z);
z = a[i] + x;
if (z <= m) events.insert(z);
}
bool ok = true;
for (int i = 1; i <= n && ok; i++) {
int z = a[i] - y;
if (z > 0 && events.find(z) != events.end()) {
printf("1\n%d\n", z);
ok = false;
break;
}
z = a[i] + y;
if (z <= m && events.find(z) != events.end()) {
printf("1\n%d\n", z);
ok = false;
break;
}
}
if (ok) printf("2\n%d %d\n", x, y);
}
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
set<int> M;
int n, l, x, y, a[100005];
bool okx, oky;
inline bool has(int x) { return M.find(x) != M.end(); }
bool ok(int d, int t) {
if (d < 0 || d > l) return 0;
return (has(d + t) || has(d - t));
}
int main() {
cin >> n >> l >> x >> y;
for (int i = 0; i < n; i++) {
cin >> a[i];
M.insert(a[i]);
}
for (int i = 0; i < n; i++) {
if (has(a[i] - x)) okx = 1;
if (has(a[i] - y)) oky = 1;
}
if (okx && oky)
cout << 0;
else if (okx && !oky)
cout << 1 << endl << y;
else if (!okx && oky)
cout << 1 << endl << x;
else {
int i;
for (i = 0; i < n; i++) {
if (ok(a[i] + x, y)) {
cout << 1 << endl << a[i] + x;
break;
}
if (ok(a[i] - x, y)) {
cout << 1 << endl << a[i] - x;
break;
}
}
if (i == n) cout << 2 << endl << x << " " << y;
}
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e8;
const int MAXM = 100000007;
const int MAX = 1e7;
const int des = 10000;
const int maxn = 100005;
int main() {
map<int, bool> mp;
vector<int> g;
int n, l, x, y;
cin >> n >> l >> x >> y;
for (int i = 0; i < n; i++) {
int tmp;
cin >> tmp;
g.push_back(tmp);
mp[tmp] = true;
}
bool nadX = true;
for (int i = 0; i < n - 1; i++) {
if (g[i] + x <= l && mp.find(g[i] + x) != mp.end()) {
nadX = false;
break;
}
}
bool nadY = true;
for (int i = 0; i < n - 1; i++) {
if (g[i] + y <= l && mp.find(g[i] + y) != mp.end()) {
nadY = false;
break;
}
}
if (nadX && nadY) {
for (int i = 0; i < n; i++) {
int plusa = g[i] + x - y, minusa = g[i] - x + y;
if (mp.find(plusa) != mp.end() && g[i] + x <= l) {
cout << "1\n" << g[i] + x << endl;
return 0;
}
if (mp.find(minusa) != mp.end() && g[i] - x > 0) {
cout << "1\n" << g[i] - x << endl;
return 0;
}
int plusa1 = g[i] + x + y, minusa1 = g[i] - x - y;
if (mp.find(plusa1) != mp.end() && g[i] + x + y <= l) {
cout << "1\n" << g[i] + x << endl;
return 0;
}
if (mp.find(minusa1) != mp.end() && g[i] - x - y > 0) {
cout << "1\n" << g[i] - x << endl;
return 0;
}
}
cout << 2 << endl << x << " " << y << endl;
return 0;
}
if (nadX) {
cout << 1 << endl << x;
return 0;
}
if (nadY) {
cout << 1 << endl << y;
return 0;
}
cout << 0;
}
| 8 | CPP |
class CodeforcesTask480BSolution:
def __init__(self):
self.result = ''
self.n_l_x_y = []
self.ruler = []
def read_input(self):
self.n_l_x_y = [int(x) for x in input().split(" ")]
self.ruler = [int(x) for x in input().split(" ")]
def process_task(self):
dists = {}
for a in self.ruler:
dists[a] = True
hasx = False
hasy = False
for a in self.ruler:
try:
if dists[a - self.n_l_x_y[2]]:
hasx = True
except KeyError:
pass
try:
if dists[a + self.n_l_x_y[2]]:
hasx = True
except KeyError:
pass
try:
if dists[a - self.n_l_x_y[3]]:
hasy = True
except KeyError:
pass
try:
if dists[a - self.n_l_x_y[3]]:
hasy = True
except KeyError:
pass
if hasx and hasy:
break
if hasx and hasy:
self.result = "0"
elif hasx:
self.result = "1\n{0}".format(self.n_l_x_y[3])
elif hasy:
self.result = "1\n{0}".format(self.n_l_x_y[2])
else:
res = [0, 0]
sgn = False
dst = self.n_l_x_y[2] + self.n_l_x_y[3]
diff = self.n_l_x_y[3] - self.n_l_x_y[2]
for a in self.ruler:
try:
if dists[a - dst]:
if a - self.n_l_x_y[2] > 0:
sgn = True
res = a - self.n_l_x_y[2]
except KeyError:
pass
try:
if dists[a + dst]:
if a + self.n_l_x_y[2] < self.n_l_x_y[1]:
sgn = True
res = a + self.n_l_x_y[2]
except KeyError:
pass
try:
if dists[a - diff]:
if a + self.n_l_x_y[2] < self.n_l_x_y[1]:
sgn = True
res = a + self.n_l_x_y[2]
except KeyError:
pass
try:
if dists[a + diff]:
if a - self.n_l_x_y[2] > 0:
sgn = True
res = a - self.n_l_x_y[2]
except KeyError:
pass
if sgn:
break
if sgn:
self.result = "1\n{0}".format(res)
else:
self.result = "2\n{0} {1}".format(self.n_l_x_y[2], self.n_l_x_y[3])
def get_result(self):
return self.result
if __name__ == "__main__":
Solution = CodeforcesTask480BSolution()
Solution.read_input()
Solution.process_task()
print(Solution.get_result())
| 8 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
typedef unsigned int UI;
typedef long int LI;
typedef unsigned long int ULI;
typedef long long int LL;
typedef unsigned long long int ULL;
LL mod = 1e9 + 7;
inline int scanInt() {
int n = 0;
char ch = getchar();
int sign = 1;
while (ch < '0' || ch > '9') {
if (ch == '-') sign = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
n = (n << 1) + (n << 3) + (int)(ch - '0');
ch = getchar();
}
return n * sign;
}
inline LL scanLong() {
LL n = 0;
char ch = getchar();
LL sign = 1;
while (ch < '0' || ch > '9') {
if (ch == '-') sign = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
n = (n << 1) + (n << 3) + (LL)(ch - '0');
ch = getchar();
}
return n * sign;
}
int main() {
LL n = scanLong();
;
LL l = scanLong();
;
LL x = scanLong();
;
LL y = scanLong();
;
vector<LL> arr(n);
for (__typeof(n) i = (0) - ((0) > (n)); i != (n) - ((0) > (n));
i += 1 - 2 * ((0) > (n)))
arr[i] = scanLong();
set<LL> s;
s.insert(x);
s.insert(y);
for (__typeof(arr.end()) it = (arr.begin()) - ((arr.begin()) > (arr.end()));
it != (arr.end()) - ((arr.begin()) > (arr.end()));
it += 1 - 2 * ((arr.begin()) > (arr.end()))) {
if (binary_search(arr.begin(), arr.end(), *it + x)) s.erase(x);
if (binary_search(arr.begin(), arr.end(), *it + y)) s.erase(y);
}
if (s.size() == 0)
puts("0");
else if (s.size() == 1) {
puts("1");
printf("%lld ", *s.begin());
printf("\n");
} else {
for (__typeof(arr.end()) it = (arr.begin()) - ((arr.begin()) > (arr.end()));
it != (arr.end()) - ((arr.begin()) > (arr.end()));
it += 1 - 2 * ((arr.begin()) > (arr.end()))) {
if (binary_search(arr.begin(), arr.end(), *it + x + y) ||
binary_search(arr.begin(), arr.end(), *it + x - y)) {
if (*it + x <= l) {
puts("1");
printf("%lld ", (*it + x));
printf("\n");
return 0;
}
}
if (binary_search(arr.begin(), arr.end(), *it - x + y) ||
binary_search(arr.begin(), arr.end(), *it - x - y)) {
if (*it - x >= 0) {
puts("1");
printf("%lld ", (*it - x));
printf("\n");
return 0;
}
}
if (binary_search(arr.begin(), arr.end(), *it + y + x) ||
binary_search(arr.begin(), arr.end(), *it + y - x)) {
if (*it + y <= l) {
puts("1");
printf("%lld ", (*it + y));
printf("\n");
return 0;
}
}
if (binary_search(arr.begin(), arr.end(), *it - y + x) ||
binary_search(arr.begin(), arr.end(), *it - y - x)) {
if (*it - y >= 0) {
puts("1");
printf("%lld ", (*it - y));
printf("\n");
return 0;
}
}
}
puts("2");
printf("%lld ", x);
printf("%lld ", y);
printf("\n");
}
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
int n, l, x, y, a[100005];
bool J(int w) {
if (w < 0 || w > l) return 0;
int L = 1, R = n;
while (L <= R) {
int mid = (L + R) >> 1;
if (a[mid] < w)
L = mid + 1;
else if (a[mid] > w)
R = mid - 1;
else
return 1;
}
return 0;
}
int main() {
scanf("%d%d%d%d", &n, &l, &x, &y);
for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
sort(a + 1, a + n + 1);
int k = 0;
for (int i = 1; i < n; i++) {
int w = a[i] + x;
if (!(k & 1) && J(w)) k += 1;
w = a[i] + y;
if (k < 2 && J(w)) k += 2;
}
if (k != 0) {
if (k == 1) {
printf("1\n%d\n", y);
} else if (k == 2) {
printf("1\n%d\n", x);
} else
puts("0");
} else {
bool ok = 0;
for (int i = 1; i <= n; i++) {
int w = a[i] + x;
if (w <= l) {
if (J(w + y) || J(w - y)) {
ok = 1;
printf("1\n%d\n", w);
break;
}
}
w = a[i] - x;
if (w >= 0) {
if (J(w + y) || J(w - y)) {
ok = 1;
printf("1\n%d\n", w);
break;
}
}
}
if (!ok) {
swap(x, y);
for (int i = 1; i <= n; i++) {
int w = a[i] + x;
if (w <= l) {
if (J(w + y) || J(w - y)) {
ok = 1;
printf("1\n%d\n", w);
break;
}
}
w = a[i] - x;
if (w >= 0) {
if (J(w + y) || J(w - y)) {
ok = 1;
printf("1\n%d\n", w);
break;
}
}
}
}
if (!ok) printf("2\n%d %d\n", x, y);
}
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int n, l, x, y;
int a[100000];
int fnd1(int f) {
int l = 0;
for (int r = 0; r < n; r++) {
while (a[l] + f < a[r] && l < n) l++;
if (a[l] + f == a[r]) return l;
}
return -1;
}
int fnd2(int f) {
int r = n - 1;
for (int l = n - 1; l >= 0; l--) {
while (a[l] + f < a[r] && r >= 0) r--;
if (a[l] + f == a[r]) return l;
}
return -1;
}
int main() {
ios::sync_with_stdio(false);
cin >> n >> l >> x >> y;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
bool p, q;
p = q = 0;
p = (fnd1(x) != -1);
q = (fnd1(y) != -1);
if (p && q)
cout << 0 << endl;
else {
if (p)
cout << 1 << endl << y << endl;
else if (q)
cout << 1 << endl << x << endl;
else {
int c;
c = fnd1(x + y);
if (c != -1) {
cout << 1 << endl << a[c] + x << endl;
return 0;
}
c = fnd1(y - x);
if (c != -1 && a[c] + y <= l) {
cout << 1 << endl << a[c] + y << endl;
return 0;
}
c = fnd2(y - x);
if (c != -1 && a[c] - x >= 0) {
cout << 1 << endl << a[c] - x << endl;
} else
cout << 2 << endl << x << " " << y << endl;
}
}
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int NMAX = 100000;
set<int> MP;
int N, L, X, Y, A = 1, B = 1;
vector<int> sol;
bool FIND(int val) { return MP.find(val) != MP.end(); }
int main() {
cin >> N >> L >> X >> Y;
for (int i = 1; i <= N; ++i) {
int nr;
cin >> nr;
MP.insert(nr);
}
for (auto i : MP) {
int p = i;
if (FIND(p + X)) A = 0;
if (FIND(p + Y)) B = 0;
}
if (A && B) {
for (auto i : MP) {
int p = i;
if (!FIND(p + X) && p + X <= L) {
if (FIND(p + X - Y) || FIND(p + X + Y)) {
cout << "1\n";
cout << p + X << '\n';
return 0;
}
}
if (!FIND(p + Y) && p + Y <= L) {
if (FIND(p + Y - X) || FIND(p + Y + X)) {
cout << "1\n";
cout << p + Y << '\n';
return 0;
}
}
if (!FIND(p + X) && p - X >= 0) {
if (FIND(p - X - Y) || FIND(p - X + Y)) {
cout << "1\n";
cout << p - X << '\n';
return 0;
}
}
if (!FIND(p - Y) && p - Y >= 0) {
if (FIND(p - Y - X) || FIND(p - Y + X)) {
cout << "1\n";
cout << p - Y << '\n';
return 0;
}
}
}
cout << "2\n";
cout << X << ' ' << Y << '\n';
return 0;
} else if (A) {
cout << "1\n";
cout << X << '\n';
} else if (B) {
cout << "1\n";
cout << Y << '\n';
} else
cout << "0\n";
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
long n, l, x, y, a[1 << 20];
set<long> has;
long hx, hy;
long ans;
long thx, thy;
void check(long ps) {
if (ps < 0 || ps > l) return;
hx = thx;
hy = thy;
if (has.find(ps + x) != has.end()) hx = 1;
if (has.find(ps + y) != has.end()) hy = 1;
if (has.find(ps - x) != has.end()) hx = 1;
if (has.find(ps - y) != has.end()) hy = 1;
if (hx && hy) ans = ps;
}
int main() {
ios_base::sync_with_stdio(0);
cin >> n >> l >> x >> y;
for (int i = 0; i < n; i++) {
cin >> a[i];
has.insert(a[i]);
}
hx = hy = 0;
for (int i = 0; i < n; i++) {
if (has.find(a[i] + x) != has.end()) hx = 1;
if (has.find(a[i] + y) != has.end()) hy = 1;
if (has.find(a[i] - x) != has.end()) hx = 1;
if (has.find(a[i] - y) != has.end()) hy = 1;
}
thx = hx;
thy = hy;
if (hx && hy) {
cout << 0 << endl;
} else {
ans = -1;
for (int i = 0; i < n; i++) {
check(a[i] - x);
check(a[i] + x);
check(a[i] - y);
check(a[i] + y);
}
if (ans >= 0)
cout << 1 << endl << ans << endl;
else {
cout << 2 << endl;
cout << x << " " << y << endl;
}
}
cin.get();
cin.get();
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
long long Max(long long a, long long b) { return (a > b ? a : b); }
long long Min(long long a, long long b) { return (a > b ? b : a); }
long long n, length, x, y, tmp, answer;
vector<long long> V;
vector<long long> ans;
bool X, Y;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n >> length >> x >> y;
for (long long i = 0; i < n; i++) {
cin >> tmp;
V.push_back(tmp);
}
answer = 2;
X = false;
Y = false;
for (long long i = 0; i < n; i++) {
if (binary_search(V.begin(), V.end(), x + V[i])) {
answer--;
X = true;
break;
}
}
for (long long i = 0; i < n; i++) {
if (binary_search(V.begin(), V.end(), y + V[i])) {
Y = true;
answer--;
break;
}
}
if (answer == 0) {
cout << "0\n";
return 0;
}
if (answer == 1) {
if (X) {
cout << "1\n" << y << "\n";
return 0;
} else {
cout << "1\n" << x << "\n";
return 0;
}
}
for (long long i = 0; i < n; i++) {
if (V[i] + x < length) {
if (binary_search(V.begin(), V.end(), V[i] + x + y)) {
cout << "1\n" << V[i] + x << "\n";
return 0;
}
if (binary_search(V.begin(), V.end(), V[i] + x - y)) {
cout << "1\n" << V[i] + x << "\n";
return 0;
}
}
if (V[i] - x > 0) {
if (binary_search(V.begin(), V.end(), V[i] - x + y)) {
cout << "1\n" << V[i] - x << "\n";
return 0;
}
if (binary_search(V.begin(), V.end(), V[i] - x - y)) {
cout << "1\n" << V[i] - x << "\n";
return 0;
}
}
if (V[i] + y < length) {
if (binary_search(V.begin(), V.end(), V[i] + x + y)) {
cout << "1\n" << V[i] + y << "\n";
return 0;
}
if (binary_search(V.begin(), V.end(), V[i] + y - x)) {
cout << "1\n" << V[i] + y << "\n";
return 0;
}
}
if (V[i] - y > 0) {
if (binary_search(V.begin(), V.end(), V[i] + x - y)) {
cout << "1\n" << V[i] - y << "\n";
return 0;
}
if (binary_search(V.begin(), V.end(), V[i] - y - x)) {
cout << "1\n" << V[i] - y << "\n";
return 0;
}
}
}
cout << "2\n" << x << " " << y << "\n";
return 0;
}
| 8 | CPP |
R = lambda: map(int, input().split())
n, l, x, y = R()
arr = set(R())
x_good, y_good = False, False
for m in arr:
if m + x in arr or m - x in arr:
x_good = True
break
for m in arr:
if m + y in arr or m - y in arr:
y_good = True
break
if x_good and y_good:
print(0)
exit()
elif x_good:
print(1)
print(y)
exit()
elif y_good:
print(1)
print(x)
exit()
else:
for m in arr:
if m + x <= l and (m + x + y in arr or m + x - y in arr):
print(1)
print(m + x)
exit()
if m - x >= 0 and (m - x + y in arr or m - x - y in arr):
print(1)
print(m - x)
exit()
if m + y <= l and (m + y + x in arr or m + y - x in arr):
print(1)
print(m + y)
exit()
if m - y >= 0 and (m - y + x in arr or m - y - x in arr):
print(1)
print(m - y)
exit()
print(2)
print(x, y) | 8 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
map<long long, int> mp;
long long n, m, i, j, x, y, num[100005];
bool in(long long x) { return (x > -1 && x <= m); }
int main() {
ios::sync_with_stdio(0);
cin >> n >> m >> x >> y;
for (i = 1; i <= n; i++) {
cin >> num[i];
mp[num[i]] = 1;
}
bool okx = 0, oky = 0;
for (i = 1; i <= n; i++) {
if (mp[num[i] + x] || mp[num[i] - x]) okx = 1;
if (mp[num[i] + y] || mp[num[i] - y]) oky = 1;
}
if (okx) {
if (oky) {
cout << 0;
return 0;
}
cout << 1 << endl << y;
return 0;
}
if (oky) {
cout << 1 << endl << x;
return 0;
}
for (i = 1; i <= n; i++) {
if (in(num[i] - x) && (mp[num[i] - x - y] || mp[num[i] - x + y])) {
cout << 1 << endl << num[i] - x;
return 0;
}
if (in(num[i] + x) && (mp[num[i] + x - y] || mp[num[i] + x + y])) {
cout << 1 << endl << num[i] + x;
return 0;
}
if (in(num[i] - y) && (mp[num[i] - x - y] || mp[num[i] + x - y])) {
cout << 1 << endl << num[i] - y;
return 0;
}
if (in(num[i] + y) && (mp[num[i] - x + y] || mp[num[i] + x + y])) {
cout << 1 << endl << num[i] + y;
return 0;
}
}
cout << 2 << endl << x << ' ' << y << endl;
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
long long mod = 1000000007;
int n, ll, x, y;
vector<int> a;
int t;
using namespace std;
int main() {
cin >> n >> ll >> y >> x;
for (int i = 0; i < n; i++) {
cin >> t;
a.push_back(t);
}
bool hx = false;
bool hy = false;
int l = 0;
int r = 0;
while (r < n) {
if (a[r] - a[l] == x) {
hx = 1;
break;
}
if (a[r] - a[l] < x) {
r++;
} else {
l++;
}
}
l = 0;
r = 0;
while (r < n) {
if (a[r] - a[l] == y) {
hy = 1;
break;
}
if (a[r] - a[l] < y) {
r++;
} else {
l++;
}
}
if (hx && hy) {
cout << 0 << endl;
} else if (hx) {
cout << 1 << endl;
cout << y << endl;
} else if (hy) {
cout << 1 << endl;
cout << x << endl;
} else {
l = 0;
r = 0;
while (r < n) {
if (a[r] - a[l] == x + y) {
cout << 1 << endl;
cout << a[l] + x << endl;
return 0;
}
if (a[r] - a[l] < x + y) {
r++;
} else {
l++;
}
}
l = 0;
r = 0;
while (r < n) {
if (a[r] - a[l] == x - y && a[l] - y >= 0) {
cout << 1 << endl;
cout << a[l] - y << endl;
return 0;
}
if (a[r] - a[l] < x - y) {
r++;
} else {
l++;
}
}
l = 0;
r = 0;
while (r < n) {
if (a[r] - a[l] == x - y && a[r] + y <= ll) {
cout << 1 << endl;
cout << a[r] + y << endl;
return 0;
}
if (a[r] - a[l] < x - y) {
r++;
} else {
l++;
}
}
cout << 2 << endl;
cout << x << endl;
cout << y << endl;
}
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int a[100000];
int main() {
int n, l, x, y, f = 0, i;
set<int> s;
scanf("%d %d %d %d", &n, &l, &x, &y);
for (i = 0; i < n; i++) {
scanf("%d", &a[i]);
s.insert(a[i]);
}
for (i = 0; i < n; i++) {
if (s.count(a[i] + x)) f |= 1;
if (s.count(a[i] + y)) f |= 2;
}
if (f == 3) {
puts("0");
return 0;
} else if (f == 1) {
puts("1");
printf("%d\n", y);
return 0;
} else if (f == 2) {
puts("1");
printf("%d\n", x);
return 0;
}
for (i = 0; i < n; i++) {
if (s.count(a[i] + y - x)) {
if (a[i] >= x) {
puts("1");
printf("%d\n", a[i] - x);
return 0;
} else if (a[i] + y <= l) {
puts("1");
printf("%d\n", a[i] + y);
return 0;
}
}
if (s.count(a[i] + x + y)) {
puts("1");
printf("%d\n", a[i] + x);
return 0;
}
}
puts("2");
printf("%d %d\n", x, y);
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100100;
int n, l, x, y, v[MAXN];
int c1, c2, c3, c4, ret, ret2;
int main() {
cin.sync_with_stdio(false);
cin >> n >> l >> x >> y;
c1 = c2 = c3 = c4 = 0;
for (int i = 1; i <= n; ++i) {
cin >> v[i];
}
for (int i = 1; i < n; ++i) {
if (v[lower_bound(v + i + 1, v + n + 1, v[i] + x) - v] == v[i] + x) c1 = 1;
if (v[lower_bound(v + i + 1, v + n + 1, v[i] + y) - v] == v[i] + y) c2 = 1;
if (v[lower_bound(v + i + 1, v + n + 1, v[i] + x + y) - v] ==
v[i] + x + y) {
c3 = 1;
ret = v[i] + x;
}
if (v[lower_bound(v + i + 1, v + n + 1, v[i] + abs(x - y)) - v] ==
v[i] + abs(x - y)) {
if (v[i] + max(x, y) <= l) {
c4 = 1;
ret2 = v[i] + max(x, y);
} else if (v[i] - min(x, y) >= 0) {
c4 = 1;
ret2 = v[i] - min(x, y);
}
}
}
if (c1 && c2)
cout << 0;
else if (c3)
cout << 1 << "\n" << ret;
else if (c4)
cout << 1 << "\n" << ret2;
else {
cout << 2 - c1 - c2 << "\n";
if (!c1) cout << x << " ";
if (!c2) cout << y << " ";
}
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5;
const int inf = 1e9 + 7;
const long long ll_inf = 1e18 + 420;
const double eps = 1e-4;
const int N = 1e6 + 7;
const int MAX = 2e5 + 9;
const int mod = 1e9 + 7;
const long double pi = 3.14159265359;
bool t[2];
int n, l, x, y;
int main() {
cin >> n >> l >> x >> y;
set<int> s;
int a[n + 100];
for (int i = 0; i < n; ++i) {
scanf("%d", &a[i]);
s.insert(a[i]);
}
for (auto i : s) {
auto it = s.find(i + x);
if (it != s.end()) t[0] = 1;
it = s.find(i + y);
if (it != s.end()) t[1] = 1;
}
if (t[0] && t[1]) {
printf("0\n");
return 0;
}
if (t[0]) {
printf("1\n");
printf("%d\n", y);
return 0;
}
if (t[1]) {
printf("1\n");
printf("%d\n", x);
return 0;
}
for (auto i : s) {
auto it = s.find(i + x + y);
if (it != s.end()) {
printf("1\n");
printf("%d\n", i + x);
return 0;
}
it = s.find(i + y - x);
if (it != s.end()) {
if (i - x >= 0) {
printf("1\n");
printf("%d\n", i - x);
return 0;
} else if (i + y <= l) {
printf("1\n");
printf("%d\n", i + y);
return 0;
}
}
}
printf("2\n");
printf("%d %d\n", x, y);
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int N = (int)1e6 + 7;
long long b, c, res, a[N], l, x, y, n;
map<long long, long long> m;
int main() {
cin >> n >> l >> x >> y;
if (x > y) swap(x, y);
for (int i = 1; i <= n; i++) {
scanf("%I64d", a + i);
m[a[i]] = 1;
}
res = 2;
for (int i = 1; i <= n; i++) {
if (a[i] == x || m[a[i] + x]) b = 1;
if (a[i] == y || m[a[i] + y]) c = 1;
}
if (b && c) {
cout << 0;
return 0;
}
if (b || c) {
cout << 1 << endl;
cout << (!b ? x : y) << endl;
return 0;
}
for (int i = 1; i <= n; i++) {
if (m[a[i] + x - y] && a[i] + x <= l) {
cout << 1 << endl << a[i] + x;
return 0;
} else if (m[a[i] + y - x] && a[i] + y <= l) {
cout << 1 << endl << a[i] + y;
return 0;
} else if (m[a[i] - x + y] && a[i] - x >= 0) {
cout << 1 << endl << a[i] - x;
return 0;
} else if (m[a[i] + y + x] && a[i] + y + x <= l) {
cout << 1 << endl << a[i] + y;
return 0;
}
}
cout << 2 << endl;
cout << x << ' ' << y << endl;
return 0;
}
| 8 | CPP |
from collections import defaultdict as dc
def serch(a,b,x,y):
for i in range(1,n):
if (b[a[i]-x-y]):
return a[i]-y
if b[a[i]-(y-x)] and a[i]+x<=l:
return a[i]+x
if b[a[i]+(y-x)] and a[i]-x>=0:
return a[i]-x
return 0
n,l,x,y=[int(i) for i in input().split()]
a=[int(i) for i in input().split()]
b=dc(int)
b=dc(lambda :0,b)
k1=0
k2=0
for i in range(n):
b[a[i]]=1
if b[a[i]-x]==1:
k1=1
if b[a[i]-y]==1:
k2=1
if k1==1 and k2==1:
print(0)
elif k1==0 and k2==0:
z=serch(a,b,x,y)
if z!=0:
print(1)
print(z)
else:
print(2)
print(x,y)
elif k1==0:
print(1)
print(x)
else:
print(1)
print(y)
| 8 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 5;
map<int, int> mp1, mp2;
int n, l, x, y, a[MAXN], xok, yok;
bool check(int d) {
for (int i = 0, r = 0; i < n && r < n; ++i) {
for (; r < n && a[r] - a[i] < d; ++r)
;
if (r < n && a[r] - a[i] == d) return true;
}
return false;
}
bool ok(int p) {
if (p < 0 || p > l) return false;
return mp1[p] || mp2[p];
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> l >> x >> y;
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
xok = check(x);
yok = check(y);
if (xok && yok)
cout << 0 << endl;
else if (xok || yok)
cout << 1 << endl << x * (xok ^ 1) + y * (yok ^ 1) << endl;
else {
int pos = -1;
for (int i = 0; i < n; ++i) {
mp1[a[i] - x] = 1;
mp2[a[i] + x] = 1;
}
for (int i = 0; i < n && pos < 0; ++i) {
if (ok(a[i] - y))
pos = a[i] - y;
else if (ok(a[i] + y))
pos = a[i] + y;
}
if (pos == -1)
cout << 2 << endl << x << " " << y << endl;
else
cout << 1 << endl << pos << endl;
}
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int n, l, x, y, a[100005];
set<int> st;
bool xok, yok;
void ck(int d, int t) {
if (d < 0 || d > l) return;
if (st.count(d + t) || st.count(d - t)) {
cout << 1 << ' ' << d;
exit(0);
}
}
int main() {
ios::sync_with_stdio(false);
cin >> n >> l >> x >> y;
for (int i = 0; i < n; i++) {
cin >> a[i];
st.insert(a[i]);
}
for (int i = 0; i < n; i++) {
if (st.count(a[i] + x) || st.count(a[i] - x)) xok = true;
if (st.count(a[i] + y) || st.count(a[i] - y)) yok = true;
}
if (xok && yok) {
cout << 0;
return 0;
} else if (xok) {
cout << 1 << endl << y;
return 0;
} else if (yok) {
cout << 1 << endl << x;
return 0;
} else {
for (int i = 0; i < n; i++) {
ck(a[i] - x, y);
ck(a[i] + x, y);
ck(a[i] - y, x);
ck(a[i] + y, x);
}
cout << 2 << endl << x << ' ' << y;
return 0;
}
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
long long n, l, x, y;
bool okx = false, oky = false;
bool f(const vector<long> &a, long long x) {
return x <= a.back() && *lower_bound(a.begin(), a.end(), x) == x;
}
int main() {
cin >> n >> l >> x >> y;
vector<long> a(n);
for (int i = 0; i < n; i++) cin >> a[i];
for (int i = 0; i < n; i++) {
if (f(a, a[i] + x)) okx = true;
if (f(a, a[i] + y)) oky = true;
}
if (okx && oky) {
cout << 0 << endl;
return 0;
}
if (okx) {
cout << 1 << endl << y << endl;
return 0;
}
if (oky) {
cout << 1 << endl << x << endl;
return 0;
}
for (int i = 0; i < n; i++) {
if (f(a, a[i] + x + y)) {
cout << 1 << endl << a[i] + x << endl;
return 0;
}
if (f(a, a[i] + y - x)) {
if (a[i] + y < l) {
cout << 1 << endl << a[i] + y << endl;
return 0;
}
if (a[i] - x > 0) {
cout << 1 << endl << a[i] - x << endl;
return 0;
}
}
}
cout << 2 << endl << x << " " << y << endl;
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int n, l, x, y;
vector<int> v(100005);
bool chk(int i, int j, int k) {
int lo = i + 1;
int hi = j, mi;
while (lo < hi) {
mi = (lo + hi) / 2;
if (v[mi] - v[i] < k) {
lo = mi + 1;
} else if (v[mi] - v[i] > k) {
hi = mi - 1;
} else
return true;
}
return ((v[lo] - v[i]) == k);
}
int mark;
bool bsearch(int k, bool b = false, bool c = false) {
for (int i = 0; i < n - 1; i++) {
if (chk(i, n, k)) {
if (!c) {
if (b) mark = v[i];
return true;
} else {
if (v[i] - x >= 0) {
mark = v[i] - x;
return true;
}
if (v[i] + y <= l) {
mark = v[i] + y;
return true;
}
}
}
}
return false;
}
int main() {
cin >> n >> l >> x >> y;
for (int i = 0; i < n; i++) cin >> v[i];
bool g = bsearch(x);
bool b = bsearch(y);
if (!(g || b)) {
bool k = bsearch(x + y, true);
if (k) {
cout << 1 << endl;
cout << mark + x;
return 0;
}
k = bsearch(y - x, false, true);
if (k) {
cout << 1 << endl;
cout << mark;
} else {
cout << 2 << endl;
cout << x << " " << y;
}
} else if (!(g && b)) {
cout << 1 << endl;
if (!g)
cout << x;
else
cout << y;
} else
cout << 0;
return 0;
}
| 8 | CPP |
n, l, x, y = map(int, input().split())
s = set(map(int, input().split()))
def f(d): return any(i + d in s for i in s)
def g():
for i in s:
if i + x + y in s: return i + x
return 0
def h():
for i in s:
if i + y - x in s:
if i - x >= 0: return i - x
if i + y <= l: return i + y
return 0
def e(d):
print(1)
print(d)
if f(x):
if f(y):
print(0)
else:
e(y)
elif f(y):
e(x)
else:
z = g()
if z:
e(z)
else:
z = h()
if z:
e(z)
else:
print(2)
print(x, y) | 8 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
long long n, l, x, y;
long long a[100005];
map<long long, bool> mp;
void check(int d, int t) {
if (d < 0 || d > l) return;
if (mp[d - t] || mp[d + t]) {
cout << 1 << endl << d << endl;
exit(0);
}
}
int main() {
cin >> n >> l >> x >> y;
for (int i = 1; i <= n; i++) {
cin >> a[i];
mp[a[i]] = true;
}
bool X = false, Y = false;
for (int i = 1; i <= n; i++) {
if (mp[a[i] - x] || mp[a[i] + x]) X = true;
if (mp[a[i] + y] || mp[a[i] - y]) Y = true;
}
if (X && Y)
cout << 0 << endl;
else if (X)
cout << 1 << endl << y << endl;
else if (Y)
cout << 1 << endl << x << endl;
else {
for (int i = 1; i <= n; i++) {
check(a[i] - x, y);
check(a[i] + x, y);
check(a[i] - y, x);
check(a[i] + y, x);
}
cout << 2 << endl << x << " " << y << endl;
}
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
set<int> s;
int main() {
int n, l, x, y, t;
bool fx = 0, fy = 0;
cin >> n >> l >> x >> y;
for (int i = 1; i <= n; i++) {
cin >> t;
s.insert(t);
}
set<int>::iterator it;
for (it = s.begin(); it != s.end(); it++) {
t = *it;
if (s.count(t + x)) fx = 1;
if (s.count(t + y)) fy = 1;
}
if (fx & fy) {
puts("0");
return 0;
} else if (fx) {
printf("1\n%d\n", y);
return 0;
} else if (fy) {
printf("1\n%d\n", x);
return 0;
} else {
for (it = s.begin(); it != s.end(); it++) {
t = *it;
if (s.count(t + x + y)) {
printf("1\n%d\n", t + x);
return 0;
} else if (s.count(t + x - y) && t + x <= l) {
printf("1\n%d\n", t + x);
return 0;
} else if (s.count(t - x + y) && t - x >= 0) {
printf("1\n%d\n", t - x);
return 0;
}
}
}
printf("2\n%d %d\n", x, y);
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int const N = 1e5 + 10;
unordered_set<int> st;
int a[N];
int n, l, x, y;
bool fx, fy;
bool has(int x) { return st.find(x) != end(st); }
bool ok0() {
for (int i = 0; (!fx || !fy) && i < n; ++i) {
if (has(a[i] + x)) fx = true;
if (has(a[i] + y)) fy = true;
}
if (fx && fy) puts("0");
return fx && fy;
}
bool ok1() {
if (fx || fy) {
printf("1\n%d\n", !fx * x + !fy * y);
return true;
}
for (int i = 0; i < n; ++i) {
for (int j = 0; j < 2; ++j) {
if (a[i] - x >= 0 && (has(a[i] - x + y) || has(a[i] - x - y))) {
printf("1\n%d\n", a[i] - x);
return true;
}
if (a[i] + x <= l && (has(a[i] + x - y) || has(a[i] + x - y))) {
printf("1\n%d\n", a[i] + x);
return true;
}
swap(x, y);
}
}
return false;
}
bool ok2() {
printf("2\n%d %d\n", x, y);
return true;
}
int main() {
scanf("%d%d%d%d", &n, &l, &x, &y);
for (int i = 0; i < n; ++i) scanf("%d", a + i), st.insert(a[i]);
ok0() || ok1() || ok2();
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int a[100005];
map<int, int> mp;
int main() {
int n, l, x, y;
scanf("%d%d%d%d", &n, &l, &x, &y);
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
mp[a[i]] = 1;
}
int ok1 = 0, ok2 = 0;
for (int i = 0; i < n; i++) {
if (mp[a[i] + x] == 1) {
ok1 = 1;
break;
}
}
for (int i = 0; i < n; i++) {
if (mp[a[i] + y] == 1) {
ok2 = 1;
break;
}
}
if (!ok1 && !ok2) {
int z, ok = 0;
for (int i = 0; i < n; i++) {
z = a[i] + x;
if (z <= l && (mp[z - y] == 1 || mp[z + y] == 1)) {
ok = 1;
break;
}
z = a[i] - x;
if (z >= 0 && (mp[z - y] == 1 || mp[z + y] == 1)) {
ok = 1;
break;
}
}
if (ok) {
puts("1");
printf("%d\n", z);
} else {
for (int i = 0; i < n; i++) {
z = a[i] + y;
if (z <= l && (mp[z - x] == 1 || mp[z + x] == 1)) {
ok = 1;
break;
}
z = a[i] - y;
if (z >= 0 && (mp[z - x] == 1 || mp[z + x] == 1)) {
ok = 1;
break;
}
}
if (ok) {
puts("1");
printf("%d\n", z);
} else {
puts("2");
printf("%d %d\n", x, y);
}
}
} else if (!ok1) {
puts("1");
printf("%d\n", x);
} else if (!ok2) {
puts("1");
printf("%d\n", y);
} else
puts("0");
return 0;
}
| 8 | CPP |
def main():
n,l,x,y = map(int,input().split())
arr = set(map(int,input().split()))
first = False
second = False
for i in arr:
if i+x in arr:
first = True
if i+y in arr:
second = True
if first and not second:
print(1)
print(y)
return
if second and not first:
print(1)
print(x)
return
if first and second:
print(0)
return
found = False
for i in arr:
if i+x-y in arr and i+x <= l:
found = True
coord = i+x
break
if i+y-x in arr and i+y <= l:
found = True
coord = i+y
break
if i+x+y in arr and i+min(x,y) <= l:
found = True
coord = i+min(x,y)
if i-x-y in arr and i-max(x,y) >= 0:
found = True
coord = i-max(x,y)
if i-x+y in arr and i-x >= 0:
found = True
coord = i-x
break
if i-y+x in arr and i-y >= 0:
found = True
coord = i-y
break
if found:
break
if found:
print(1)
print(coord)
return
print(2)
print(x,y)
main()
| 8 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int n, l, x, y, a[100005];
set<long long> st;
int main(int argc, char *argv[]) {
ios_base::sync_with_stdio(false);
cout.precision(10);
cout << fixed;
if (argc > 1 && fopen(argv[1], "r")) freopen(argv[1], "rt", stdin);
cin >> n >> l >> x >> y;
for (int i = 0; i < (int)(n); ++i) cin >> a[i], st.insert(a[i]);
bool fx = 0, fy = 0;
for (long long a1 : st) {
if (st.count(a1 - x) || st.count(a1 + x)) {
fx = 1;
break;
}
}
for (long long a1 : st) {
if (st.count(a1 - y) || st.count(a1 + y)) {
fy = 1;
break;
}
}
if (fx && fy)
cout << 0 << endl;
else if (fx)
cout << 1 << endl << y << endl;
else if (fy)
cout << 1 << endl << x << endl;
else {
for (long long a1 : st) {
long long a2 = a1 + x + y;
if (st.count(a2)) {
cout << 1 << endl << a1 + x << endl;
return 0;
}
a2 = a1 - x + y;
if (st.count(a2)) {
if (a1 + y <= l) {
cout << 1 << endl << a1 + y << endl;
return 0;
} else if (a1 - x >= 0) {
cout << 1 << endl << a1 - x << endl;
return 0;
}
}
a2 = a1 + x - y;
if (st.count(a2)) {
if (a1 + x <= l) {
cout << 1 << endl << a1 + x << endl;
return 0;
} else if (a1 - y >= 0) {
cout << 1 << endl << a1 - y << endl;
return 0;
}
}
a2 = y - x;
if (st.count(a2)) {
cout << 1 << endl << y << endl;
return 0;
}
}
cout << 2 << endl << x << " " << y << endl;
}
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int getint() {
int x = 0, tmp = 1;
char c = getchar();
while ((c < '0' || c > '9') && c != '-') c = getchar();
if (c == '-') c = getchar(), tmp = -1;
while (c >= '0' && c <= '9') x *= 10, x += (c - '0'), c = getchar();
return x * tmp;
}
int n, l, x, y, a[100010];
set<int> S;
void init() {
n = getint();
l = getint();
x = getint();
y = getint();
for (int i = 0; i < n; i++) {
a[i] = getint();
S.insert(a[i]);
}
}
set<int> S2, S3;
void find_ans() {
for (int i = 0; i < n; i++) {
int ndx = a[i] - x;
if (ndx >= 0) S2.insert(ndx);
}
for (int i = n - 1; i >= 0; i--) {
int ndx = a[i] + x;
if (ndx <= l) S3.insert(ndx);
}
for (int i = 0; i < n; i++) {
int ndy = a[i] - y;
if (S2.count(ndy) > 0 || S3.count(ndy) > 0) {
printf("1\n%d\n", ndy);
return;
}
}
for (int i = n - 1; i >= 0; i--) {
int ndy = a[i] + y;
if (S3.count(ndy) > 0 || S2.count(ndy) > 0) {
printf("1\n%d\n", ndy);
return;
}
}
printf("2\n");
printf("%d %d\n", x, y);
}
void solve() {
bool canx = false, cany = false;
for (int i = 0; i < n; i++) {
int ndx = a[i] - x;
int ndy = a[i] - y;
if (S.count(ndx)) canx = true;
if (S.count(ndy)) cany = true;
}
if (canx && cany)
puts("0");
else if (canx)
printf("1\n%d\n", y);
else if (cany)
printf("1\n%d\n", x);
else
find_ans();
}
int main() {
init();
solve();
}
| 8 | CPP |
#include <bits/stdc++.h>
const int MAX = 1e5 + 11;
using namespace std;
int N, L, X, Y, A[MAX];
set<int> all;
static bool can(int v) {
for (int i = 0; i < (N); ++i) {
if (all.count(v + A[i])) {
return true;
}
}
return all.count(v) > 0;
}
int main() {
scanf("%d%d%d%d", &(N), &(L), &(X), &(Y));
for (int i = 0; i < (N); ++i) {
scanf("%d", &(A[i]));
all.insert(A[i]);
}
if (can(X) && can(Y)) {
printf("0");
return 0;
}
if (can(X)) {
printf("1\n%d", Y);
return 0;
}
if (can(Y)) {
printf("1\n%d", X);
return 0;
}
set<int> xx, yy;
for (int i = 0; i < (N); ++i) {
if (X + A[i] < L) xx.insert(X + A[i]);
if (Y + A[i] < L) yy.insert(Y + A[i]);
}
for (auto u : xx) {
if (yy.count(u)) {
printf("1\n%d", u);
return 0;
}
}
xx = set<int>(), yy = set<int>();
for (int i = 0; i < (N); ++i) {
if (A[i] - X >= 0) xx.insert(A[i] - X);
if (A[i] - Y >= 0) yy.insert(A[i] - Y);
}
for (auto u : xx) {
if (yy.count(u)) {
printf("1\n%d", u);
return 0;
}
}
xx = set<int>(), yy = set<int>();
for (int i = 0; i < (N); ++i) {
if (A[i] - X >= 0) xx.insert(A[i] - X);
if (A[i] + Y < L) yy.insert(A[i] + Y);
}
for (auto u : xx) {
if (yy.count(u)) {
printf("1\n%d", u);
return 0;
}
}
xx = set<int>(), yy = set<int>();
for (int i = 0; i < (N); ++i) {
if (A[i] + X < L) xx.insert(A[i] + X);
if (A[i] - Y >= 0) yy.insert(A[i] - Y);
}
for (auto u : xx) {
if (yy.count(u)) {
printf("1\n%d", u);
return 0;
}
}
A[N++] = X;
if (can(Y)) {
printf("1\n%d", X);
return 0;
}
A[N - 1] = Y;
if (can(X)) {
printf("1%d\n", Y);
return 0;
}
printf("2\n%d %d", X, Y);
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
const double eps = 1e-8;
int main() {
ios_base::sync_with_stdio(0);
map<long long, bool> mapa;
long long in[200009];
long long n, len, x, y;
cin >> n >> len >> x >> y;
for (int i = 0; i < n; i++) {
cin >> in[i];
mapa[in[i]] = true;
}
bool x_mila = false, y_mila = false;
for (int i = 0; i < n; i++) {
if (mapa[in[i] - x] == true) x_mila = true;
if (mapa[in[i] + x] == true) x_mila = true;
if (mapa[in[i] - y] == true) y_mila = true;
if (mapa[in[i] + y] == true) y_mila = true;
}
if (x_mila && y_mila) {
cout << "0" << endl;
return 0;
}
vector<int> opt;
for (int i = 0; i < n; i++) {
if (in[i] - x >= 0) opt.push_back(in[i] - x);
if (in[i] + x <= len) opt.push_back(in[i] + x);
if (in[i] - y >= 0) opt.push_back(in[i] - y);
if (in[i] + y <= len) opt.push_back(in[i] + y);
}
for (int i = 0; i < ((int)(opt.size())); i++) {
bool xm = false, ym = false;
int curr = opt[i];
if (mapa[curr - x] || mapa[curr + x]) xm = true;
if (mapa[curr - y] || mapa[curr + y]) ym = true;
if ((xm && ym) || (x_mila && ym) || (xm && y_mila)) {
cout << "1" << endl;
cout << curr << endl;
return 0;
}
}
cout << "2" << endl;
cout << x << " " << y << endl;
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
long long n, l, x, y;
set<long long> st;
int main() {
cin >> n >> l >> x >> y;
for (int i = 0; i < n; i++) {
long long t;
cin >> t;
st.insert(t);
}
bool fst = false, sec = false;
for (set<long long>::iterator it = st.begin(); it != st.end(); it++) {
if (st.count(*it - x)) {
fst = true;
}
if (st.count(*it - y)) {
sec = true;
}
}
if (fst && sec) {
cout << 0;
return 0;
} else if (fst && !sec) {
cout << 1 << endl << y;
return 0;
} else if (!fst && sec) {
cout << 1 << endl << x;
return 0;
} else {
for (set<long long>::iterator it = st.begin(); it != st.end(); it++) {
if (st.count(*it - x - y)) {
cout << 1 << endl << *it - y;
return 0;
}
}
int c = max(x, y) - min(x, y);
for (set<long long>::iterator it = st.begin(); it != st.end(); it++) {
if (st.count(*it - c)) {
if (*it + min(x, y) <= l) {
cout << 1 << endl << *it + min(x, y);
return 0;
} else if (*it - max(x, y) >= 0) {
cout << 1 << endl << *it - max(x, y);
return 0;
}
}
}
cout << 2 << endl << x << ' ' << y;
return 0;
}
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
inline bool is_palindrome(const string& s) {
return std::equal(s.begin(), s.end(), s.rbegin());
}
const long long MOD = 1000000007;
const long long INF = 1e9 + 5;
const double eps = 1e-7;
const double PI = acos(-1.0);
inline void debug_vi(vector<int> a) {
for (long long i = (long long)(0); i < (long long)(a.size()); i++)
cout << a[i] << " ";
}
inline void debug_vll(vector<long long> a) {
for (long long i = (long long)(0); i < (long long)(a.size()); i++)
cout << a[i] << " ";
}
const int N = 1e5 + 5;
int arr[N];
pair<int, int> xpos, ypos;
int main() {
std::ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n, l, x, y, j;
cin >> n >> l >> x >> y;
xpos = {-1, -1};
ypos = xpos;
for (long long i = (long long)(0); i < (long long)(n); i++) {
cin >> arr[i];
}
j = 0;
for (long long i = (long long)(0); i < (long long)(n); i++) {
while (j < n && arr[j] - arr[i] < x) j++;
if (j < n && arr[j] - arr[i] == x) {
xpos = {i, j};
break;
}
}
j = 0;
for (long long i = (long long)(0); i < (long long)(n); i++) {
while (j < n && arr[j] - arr[i] < y) j++;
if (j < n && arr[j] - arr[i] == y) {
ypos = {i, j};
break;
}
}
if (xpos.first != -1 && ypos.first != -1) {
cout << 0;
} else if (xpos.first != -1 || ypos.first != -1) {
cout << 1 << "\n";
if (xpos.first != -1) {
cout << y;
} else {
cout << x;
}
} else {
j = 0;
for (long long i = (long long)(0); i < (long long)(n); i++) {
while (j < n && arr[j] - arr[i] < x + y) j++;
if (j < n && arr[j] - arr[i] == x + y) {
cout << 1 << "\n";
cout << arr[i] + x << "\n";
return 0;
}
}
j = 0;
for (long long i = (long long)(0); i < (long long)(n); i++) {
while (j < n && arr[j] - arr[i] < y - x) j++;
if (j < n && arr[j] - arr[i] == y - x) {
if (arr[i] - x >= 0) {
cout << 1 << "\n";
cout << arr[i] - x;
return 0;
} else if (arr[j] + x <= l) {
cout << 1 << "\n";
cout << arr[j] + x;
return 0;
}
}
}
cout << 2 << "\n";
cout << x << " " << y;
}
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int n, l, x[2];
set<int> ss;
map<int, int> mp, bp;
int main() {
cin >> n >> l >> x[0] >> x[1];
for (int i = 0; i < n; i++) {
int a;
scanf("%d", &a);
ss.insert(a);
}
bool flag[2] = {0};
for (auto v = ss.begin(); v != ss.end(); v++) {
if (ss.count(*v + x[0])) flag[0] = 1;
if (ss.count(*v + x[1])) flag[1] = 1;
}
if (flag[0] && flag[1]) {
puts("0");
return 0;
}
if (flag[0] || flag[1]) {
puts("1");
for (int i = 0; i < 2; i++)
if (!flag[i]) printf("%d\n", x[i]);
return 0;
}
int blog = -1;
for (auto v = ss.begin(); v != ss.end(); v++) {
if (ss.count(*v + x[0] + x[1])) blog = *v + x[0];
if (*v + x[0] <= l) mp[*v + x[0]]++;
if (*v + x[1] <= l) mp[*v + x[1]]++;
if (mp[*v + x[0]] == 2) blog = *v + x[0];
if (mp[*v + x[1]] == 2) blog = *v + x[1];
}
if (blog != -1) {
printf("1\n%d\n", blog);
return 0;
}
blog = -1;
for (auto v = ss.begin(); v != ss.end(); v++) {
if (*v - x[0] >= 0) bp[*v - x[0]]++;
if (*v - x[1] >= 0) bp[*v - x[1]]++;
if (bp[*v - x[0]] == 2) blog = *v - x[0];
if (bp[*v - x[1]] == 2) blog = *v - x[1];
}
if (blog != -1) {
printf("1\n%d\n", blog);
return 0;
}
printf("2\n%d %d\n", x[0], x[1]);
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, l, x, y;
cin >> n >> l >> x >> y;
int arr[n];
for (int i = 0; i < n; i++) cin >> arr[i];
bool isX = false, isY = false;
for (int i = 0; i < n; i++) {
int low = i, high = n - 1, mid = (low + high) / 2;
while (low <= high) {
if (arr[mid] - arr[i] < x) {
low = mid + 1;
mid = (low + high) / 2;
} else if (arr[mid] - arr[i] > x) {
high = mid - 1;
mid = (low + high) / 2;
} else if (arr[mid] - arr[i] == x) {
isX = true;
break;
}
}
if (isX == true) break;
}
for (int i = 0; i < n; i++) {
int low = i, high = n - 1, mid = (low + high) / 2;
while (low <= high) {
if (arr[mid] - arr[i] < y) {
low = mid + 1;
mid = (low + high) / 2;
} else if (arr[mid] - arr[i] > y) {
high = mid - 1;
mid = (low + high) / 2;
} else if (arr[mid] - arr[i] == y) {
isY = true;
break;
}
}
if (isY == true) break;
}
if (isX == true && isY == true) {
cout << 0;
return 0;
} else if (isX == true)
cout << 1 << endl << y;
else if (isY == true)
cout << 1 << endl << x;
else {
for (int i = 1; i < n; i++) {
if (arr[i] - (arr[i - 1] + x) == y) {
if (arr[i - 1] + x > arr[i] && arr[i - 1] + x <= l) {
cout << 1 << endl << arr[i - 1] + y;
return 0;
}
cout << 1 << endl << arr[i - 1] + x;
return 0;
}
}
map<int, int> m;
for (int i = 0; i < n; i++) {
if (arr[i] - x > 0) {
m[arr[i] - x] = x;
}
if (m[arr[i] + x] == y && arr[i] + x < l) {
cout << 1 << endl << arr[i] + x;
return 0;
}
m[arr[i] + x] = x;
m[arr[i] + y] = y;
if (arr[i] - y > 0) {
if (m[arr[i] - y] == x) {
cout << 1 << endl << arr[i] - y;
return 0;
}
}
}
cout << 2 << endl << x << " " << y;
}
return 0;
}
| 8 | CPP |
import itertools
import math
def can_measure(a, d):
return any(i + d in a for i in a)
def main():
n, l, x, y = map(int, input().split())
a = set(map(int, input().split()))
can_x = can_measure(a, x)
can_y = can_measure(a, y)
if can_x and can_y:
print(0)
elif can_x:
print(1)
print(y)
elif can_y:
print(1)
print(x)
else:
for i in a:
if i + x + y in a:
print(1)
print(i + x)
break
else:
t = i + x - y in a
if 0 <= i + x <= l and t:
print(1)
print(i + x)
break;
if 0 <= i - y <= l and t:
print(1)
print(i - y)
break;
else:
print(2)
print(x, y)
if __name__ == "__main__":
main()
| 8 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int i, N, M, K, k;
int G, B;
unordered_map<int, int> u;
int s[100010];
int main() {
int a, b, c, d;
int T;
cin >> N >> K >> G >> B;
for (a = 0; a < (int)N; a++) {
scanf("%d", &c);
s[a] = c;
u[c] = 1;
if (G and u[c - G] == 1) {
G = 0;
}
if (B and u[c - B] == 1) {
B = 0;
}
}
if (!G and !B) {
puts("0");
return 0;
}
if (G and !B) {
printf("1\n%d", G);
return 0;
}
if (B and !G) {
cout << 1 << endl << B;
return 0;
}
for (a = 0; a < (int)N; a++) {
c = s[a];
if (c + B < K)
if (u[c + B + G] == 1 or u[c + B - G] == 1) {
cout << 1 << endl << c + B;
return 0;
}
if (c + G < K)
if (u[c + B + G] == 1 or u[c + G - B] == 1) {
cout << 1 << endl << c + G;
return 0;
}
if (c - B > 0)
if (u[c - B + G] == 1 or u[c - B - G] == 1) {
cout << 1 << endl << c - B;
return 0;
}
if (c - G > 0)
if (u[c - G + B] == 1 or u[c - G - B] == 1) {
cout << 1 << endl << c - G;
return 0;
}
}
cout << 2 << endl << B << ' ' << G;
return 0;
}
| 8 | CPP |
"""
Codeforces Contest 274 Div 1 Problem B
Author : chaotic_iak
Language: Python 3.3.4
"""
def check_dist(d, a):
left = 0
right = 1
while right < len(a):
if a[right] - a[left] == d:
return left+1
if a[right] - a[left] > d:
left += 1
else:
right += 1
return 0
def check_dist_rev(d, a):
left = len(a)-2
right = len(a)-1
while left > -1:
if a[right] - a[left] == d:
return left+1
if a[right] - a[left] > d:
right -= 1
else:
left -= 1
return 0
def main():
n,l,x,y = read()
a = read()
x_sat = check_dist(x, a)
y_sat = check_dist(y, a)
if x_sat and y_sat:
print(0)
return
elif x_sat and not y_sat:
print(1)
print(y)
return
elif not x_sat and y_sat:
print(1)
print(x)
return
add_sat = check_dist(x+y, a)
sub_sat = check_dist(y-x, a)
if add_sat:
print(1)
print(a[add_sat-1] + x)
elif sub_sat:
p = sub_sat-1
if a[p]+y < l:
print(1)
print(a[p]+y)
elif a[p]-x > 0:
print(1)
print(a[p]-x)
else:
p = check_dist_rev(y-x, a) - 1
if a[p]+y < l:
print(1)
print(a[p]+y)
elif a[p]-x > 0:
print(1)
print(a[p]-x)
else:
print(2)
print(x,y)
else:
print(2)
print(x, y)
################################### NON-SOLUTION STUFF BELOW
def read(mode=2):
# 0: String
# 1: List of strings
# 2: List of integers
inputs = input().strip()
if mode == 0: return inputs
if mode == 1: return inputs.split()
if mode == 2: return list(map(int, inputs.split()))
def write(s="\n"):
if s is None: s = ""
if isinstance(s, list): s = " ".join(map(str, s))
s = str(s)
print(s, end="")
write(main()) | 8 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int a[100101];
int x, y;
int n, m;
int rn = 0;
int r[11];
int main() {
int i, j, k, l, s, t, sum = 0;
bool color4 = false, color1 = false, color2 = false, color3 = false;
scanf("%d%d%d%d", &n, &m, &x, &y);
for (i = 1; i <= n; i++) scanf("%d", &a[i]);
for (i = 1; i <= n; i++) {
k = a[i] + x;
s = lower_bound(a + 1, a + n + 1, k) - a;
if (a[s] == k) {
color1 = true;
break;
}
}
for (i = 1; i <= n; i++) {
k = a[i] + y;
s = lower_bound(a + 1, a + n + 1, k) - a;
if (a[s] == k) {
color2 = true;
break;
}
}
if (!color1 && !color2) {
for (i = 1; i <= n; i++) {
k = a[i] + y + x;
if (k < 0) break;
s = lower_bound(a + 1, a + n + 1, k) - a;
if (a[s] == k) {
color3 = true;
break;
}
}
if (color3) {
printf("1\n%d\n", a[i] + x);
return 0;
}
}
if (!color1 && !color2) {
for (i = 1; i <= n; i++) {
k = a[i] + y - x;
if (k < 0 || k > m || a[i] + y > m) break;
s = lower_bound(a + 1, a + n + 1, k) - a;
if (a[s] == k) {
color4 = true;
break;
}
}
if (color4) {
printf("1\n%d\n", a[i] + y);
return 0;
} else {
for (i = 1; i <= n; i++) {
k = a[i] - (y - x);
if (k < 0 || k > m || a[i] - y < 0) continue;
s = lower_bound(a + 1, a + n + 1, k) - a;
if (a[s] == k) {
color4 = true;
break;
}
}
if (color4) {
printf("1\n%d\n", a[i] - y);
return 0;
}
}
}
if (!color1) r[++rn] = x;
if (!color2) {
r[++rn] = y;
}
if (rn == 2 && r[1] == r[2]) rn--;
printf("%d\n", rn);
for (i = 1; i <= rn - 1; i++) printf("%d ", r[i]);
if (rn) printf("%d\n", r[rn]);
}
| 8 | CPP |
import sys
first = sys.stdin.readline().split(" ")
n = int(first[0])
l = int(first[1])
x = int(first[2])
y = int(first[3])
second = sys.stdin.readline().split(" ")
have_dict = {}
need_dict_x = {}
need_dict_y = {}
for val in second:
have_dict[val] = 1
val = int(val)
need_dict_x[str(val - x)] = 1
need_dict_x[str(val+x)] = 1
need_dict_y[str(val - y)] = 1
need_dict_y[str(val + y)] = 1
need_x = 1
need_y = 1
something = 1
for val in have_dict.keys():
try:
need_dict_x[val]
need_x = 0
except:
something += 1
try:
need_dict_y[val]
need_y = 0
except:
something -= 1
need_vals = []
if need_x == 1 and need_y == 1:
to_return = 2
return_val = str(x) + " "+str(y)
for val in need_dict_x.keys():
if int(val) < 0 or int(val) > l:
continue
else:
try:
need_dict_y[val]
to_return = 1
return_val = val
except:
continue
print(to_return)
print(return_val)
else:
print(need_x+need_y)
if need_x == 1:
print(x)
elif need_y == 1:
print(y) | 8 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-8;
const double pi = acos(-1.0);
const int mod = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const int M = 1000100;
int a[100050];
map<int, int> vis;
int main() {
int n, len, x, y;
cin >> n >> len >> x >> y;
for (int i = 0; i < n; ++i) {
scanf("%d", &a[i]);
vis[a[i]] = 1;
}
int ans = 0;
int l = 0, r = 0;
int tmp = a[0];
while (r < n) {
if (tmp < x) {
r++;
if (r == n) break;
tmp = a[r] - a[l];
} else if (tmp > x) {
l++;
tmp = a[r] - a[l];
} else {
ans++;
break;
}
}
l = 0, r = 0;
tmp = a[0];
while (r < n) {
if (tmp < y) {
r++;
if (r == n) break;
tmp = a[r] - a[l];
} else if (tmp > y) {
l++;
tmp = a[r] - a[l];
} else {
ans += 2;
break;
}
}
if (ans == 3) {
cout << "0" << endl;
return 0;
}
for (int i = 0; i < n; ++i) {
if (a[i] - x == a[i + 1] - y) {
if (a[i] - x >= 0) {
cout << "1" << endl;
cout << a[i] - x << endl;
return 0;
}
}
if ((a[i] + y == a[i + 1] + x) || (a[i] + y == a[i + 1] - x)) {
if (a[i] + y > len) continue;
cout << "1" << endl;
cout << a[i] + y << endl;
return 0;
}
}
if (ans == 1) {
cout << "1" << endl;
cout << y << endl;
return 0;
}
if (ans == 2) {
cout << "1" << endl;
cout << x << endl;
return 0;
}
int ca = y - x;
for (int i = 0; i < n; ++i) {
if (a[i] - y == x) {
if (a[i] - y >= 0) {
cout << "1" << endl;
cout << y << endl;
return 0;
}
}
if (a[i] - x == y) {
if (a[i] - x < 0) {
cout << "1" << endl;
cout << x << endl;
return 0;
}
}
if (a[i] + x == y) {
if (a[i] + x <= len) {
cout << "1" << endl;
cout << y << endl;
return 0;
}
}
if (vis[a[i] - x + y]) {
if (a[i] - x >= 0) {
cout << "1" << endl;
cout << a[i] - x << endl;
return 0;
}
}
if (vis[a[i] - y + x]) {
if (a[i] - y >= 0) {
cout << "1" << endl;
cout << a[i] - y << endl;
return 0;
}
}
if (vis[a[i] + x - y]) {
if (a[i] + x <= len) {
cout << "1" << endl;
cout << a[i] + x << endl;
return 0;
}
}
if (vis[a[i] + y - x]) {
if (a[i] + y <= len) {
cout << "1" << endl;
cout << a[i] + y << endl;
return 0;
}
}
}
cout << "2" << endl;
cout << x << " " << y << endl;
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
bool check(long long int *a, long long int n, long long int l,
long long int x) {
for (int i = 0; i < n; i++)
if (binary_search(a, a + n, a[i] - x) | binary_search(a, a + n, a[i] + x))
return true;
return false;
}
void func(long long int *a, long long int n, long long int l, long long int x,
long long int y) {
bool flag1 = false, flag2 = false;
flag1 = check(a, n, l, x);
flag2 = check(a, n, l, y);
if (!flag1 && !flag2) {
bool flag = false;
int pos;
for (int i = 0; i < n; i++) {
long long int z = a[i] + y;
if (z <= l)
if (binary_search(a, a + n, z + x) | binary_search(a, a + n, z - x)) {
flag = true;
pos = z;
break;
}
z = a[i] - y;
if (z >= 0)
if (binary_search(a, a + n, z + x) | binary_search(a, a + n, z - x)) {
flag = true;
pos = z;
break;
}
}
if (!flag)
for (int i = 0; i < n; i++) {
long long int z = a[i] + x;
if (z <= l)
if (binary_search(a, a + n, z + y) | binary_search(a, a + n, z - y)) {
flag = true;
pos = z;
break;
}
z = a[i] - x;
if (z >= 0)
if (binary_search(a, a + n, z + y) | binary_search(a, a + n, z - y)) {
flag = true;
pos = z;
break;
}
}
if (!flag)
cout << 2 << endl << x << endl << y << endl;
else
cout << 1 << endl << pos << endl;
} else if (!flag1)
cout << 1 << endl << x << endl;
else if (!flag2)
cout << 1 << endl << y << endl;
else
cout << 0 << endl;
}
int main() {
ios_base::sync_with_stdio(false);
long long int n, l, x, y;
cin >> n >> l >> x >> y;
long long int a[n + 1];
for (long long int i = 0; i < n; i++) cin >> a[i];
func(a, n, l, x, y);
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int n, l, x, y;
vector<int> marks;
bool check(int a) { return (a >= 0 && a <= l); }
int main() {
cin >> n >> l >> x >> y;
marks.resize(n);
for (int i = 0; i < n; i++) cin >> marks[i];
sort(marks.begin(), marks.end());
bool X = false, Y = false;
for (int i = 0; i < n; i++) {
X = binary_search(marks.begin(), marks.end(), marks[i] + x);
if (X) break;
}
for (int i = 0; i < n; i++) {
Y = binary_search(marks.begin(), marks.end(), marks[i] + y);
if (Y) break;
}
if (X && Y)
cout << 0;
else if (X) {
cout << 1 << endl;
cout << marks[0] + y;
} else if (Y) {
cout << 1 << endl;
cout << marks[0] + x;
} else {
for (int i = 0; i < n; i++) {
bool flag = binary_search(marks.begin(), marks.end(), marks[i] + x + y);
bool flag2 = binary_search(marks.begin(), marks.end(), marks[i] + x - y);
if (flag) {
cout << 1 << endl;
cout << marks[i] + x;
return 0;
}
if (flag2) {
if (check(marks[i] + x)) {
cout << 1 << endl;
cout << marks[i] + x;
return 0;
}
if (check(marks[i] - y)) {
cout << 1 << endl;
cout << marks[i] - y;
return 0;
}
}
flag = binary_search(marks.begin(), marks.end(), marks[i] - x + y);
if (flag) {
if (check(marks[i] - x)) {
cout << 1 << endl;
cout << marks[i] - x;
return 0;
}
if (check(marks[i] + y)) {
cout << 1 << endl;
cout << marks[i] + y;
return 0;
}
}
flag = binary_search(marks.begin(), marks.end(), marks[0] - x - y);
if (flag) {
if (check(marks[i] - x)) {
cout << 1 << endl;
cout << marks[i] - x;
return 0;
}
if (check(marks[i] - y)) {
cout << 1 << endl;
cout << marks[i] - y;
return 0;
}
}
}
cout << 2 << endl;
cout << marks[0] + x << " " << marks[0] + y << endl;
}
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
template <class T>
void read(T& num) {
char CH;
bool F = false;
for (CH = getchar(); CH < '0' || CH > '9'; F = CH == '-', CH = getchar())
;
for (num = 0; CH >= '0' && CH <= '9';
num = num * 10 + CH - '0', CH = getchar())
;
F && (num = -num);
}
int stk[70], tp;
template <class T>
inline void print(T p) {
if (!p) {
puts("0");
return;
}
while (p) stk[++tp] = p % 10, p /= 10;
while (tp) putchar(stk[tp--] + '0');
putchar('\n');
}
const long long mod = 1e9 + 7;
const double PI = acos(-1.0);
const int inf = 1e9;
const int N = 1e6 + 20;
const int maxn = 5e3 + 10;
const double eps = 1e-12;
int n;
long long l, x, y, a[N];
map<long long, int> mp;
int check1(long long d) {
for (int i = 1; i <= n; i++) {
long long temp = a[i] + d;
if (mp[temp]) return 1;
}
return 0;
}
int check2() {
for (int i = 1; i <= n; i++) {
long long temp = a[i] + x + y;
if (mp[temp]) {
cout << "1\n";
cout << a[i] + x << endl;
return 0;
}
}
long long leng = y - x;
for (int i = 1; i <= n; i++) {
long long temp = a[i] + leng;
if (mp[temp]) {
if (temp + x <= l) {
cout << "1\n";
cout << temp + x << endl;
return 0;
}
if (a[i] - x >= 0) {
cout << "1\n";
cout << a[i] - x << endl;
return 0;
}
}
}
cout << "2" << endl;
cout << x << " " << y << endl;
return 0;
}
int main() {
read(n);
read(l);
read(x);
read(y);
for (int i = 1; i <= n; i++) read(a[i]), mp[a[i]] = 1;
int fx = check1(x), fy = check1(y);
if (fx && fy)
cout << "0\n";
else if (fx || fy) {
if (fx)
cout << "1\n" << y << endl;
else
cout << "1\n" << x << endl;
} else
check2();
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
set<int> st;
int a[200001], i, j, m, n, p, k, l, x, y;
bool check0() {
int i, flag = 0, flag1 = 0;
for (i = 1; i <= n; i++) {
if (*st.lower_bound(a[i] + x) == a[i] + x) flag = 1;
if (*st.lower_bound(a[i] + y) == a[i] + y) flag1 = 1;
}
if (flag & flag1) {
printf("0\n");
return true;
}
return false;
}
bool check1() {
int i, flag = 0, flag1 = 0;
for (i = 1; i <= n; i++) {
if (*st.lower_bound(a[i] + x) == a[i] + x) flag = 1;
if (*st.lower_bound(a[i] + y) == a[i] + y) flag1 = 1;
}
for (i = 1; i <= n; i++) {
int Flag = flag, Flag1 = flag1;
if (*st.lower_bound(a[i] + x) != a[i] + x && a[i] + x <= l) {
Flag = 1;
if (*st.lower_bound(a[i] + y + x) == a[i] + y + x ||
*st.lower_bound(a[i] - y + x) == a[i] - y + x)
Flag1 = 1;
if (Flag & Flag1) {
printf("1\n%d\n", a[i] + x);
return true;
}
}
if (*st.lower_bound(a[i] - x) != a[i] - x && a[i] - x > 0) {
Flag = 1;
if (*st.lower_bound(a[i] + y - x) == a[i] + y - x ||
*st.lower_bound(a[i] - y - x) == a[i] - y - x)
Flag1 = 1;
if (Flag & Flag1) {
printf("1\n%d\n", a[i] - x);
return true;
}
}
}
for (i = 1; i <= n; i++) {
int Flag = flag, Flag1 = flag1;
if (*st.lower_bound(a[i] + y) != a[i] + y && a[i] + y <= l) {
Flag1 = 1;
if (*st.lower_bound(a[i] + x + y) == a[i] + x + y ||
*st.lower_bound(a[i] + y - x) == a[i] + y - x)
flag1 = 1;
if (Flag & Flag1) {
printf("1\n%d\n", a[i] + y);
return true;
}
}
if (*st.lower_bound(a[i] - y) != a[i] - y && a[i] - y > 0) {
Flag = 1;
if (*st.lower_bound(a[i] - y + x) == a[i] - y + x ||
*st.lower_bound(a[i] - y - x) == a[i] - y - x)
flag1 = 1;
if (Flag & Flag1) {
printf("1\n%d\n", a[i] - y);
return true;
}
}
}
return false;
}
int main() {
scanf("%d%d%d%d", &n, &l, &x, &y);
for (i = 1; i <= n; i++) scanf("%d", &a[i]), st.insert(a[i]);
if (check0()) return 0;
if (check1()) return 0;
printf("2\n%d %d\n", x, y);
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int a[100005];
vector<int> vx;
vector<int> vy;
int main() {
int n, l, x, y, p = 0;
cin >> n;
cin >> l;
cin >> x;
cin >> y;
for (int i = 0; i < n; i++) {
cin >> a[i];
if (a[i] + x <= l) {
vx.push_back(a[i] + x);
}
if (a[i] - x >= 0) {
vx.push_back(a[i] - x);
}
if (a[i] + y <= l) {
vy.push_back(a[i] + y);
}
if (a[i] - y >= 0) {
vy.push_back(a[i] - y);
}
}
a[n] = 1000 * 1000 * 1000 + 5;
sort(vx.begin(), vx.end());
sort(vy.begin(), vy.end());
int i = 0, j = 0, k = 0;
bool c = false, bx = false, by = false;
vx.push_back(1000 * 1000 * 1000 + 6);
vy.push_back(1000 * 1000 * 1000 + 7);
for (int i = 0; i < vy.size(); i++) {
}
while (i <= n && j < vx.size() && k < vy.size()) {
bool b = true;
if (a[i] < vx[j] && a[i] < vy[k]) {
i++;
b = false;
}
if (vx[j] < a[i] && vx[j] < vy[k] && b) {
j++;
b = false;
}
if (vy[k] < a[i] && vy[k] < vx[j] && b) {
k++;
b = false;
}
if (vx[j] == a[i] && vy[k] == a[i] && b == true) {
i++;
j++;
k++;
b = false;
c = true;
bx = true;
by = true;
break;
}
if (vx[j] == vy[k] && b) {
c = true;
b = false;
p = vx[j];
j++;
k++;
}
if (a[i] == vx[j] && b) {
bx = true;
b = false;
i++;
j++;
}
if (a[i] == vy[k] && b) {
by = true;
i++;
k++;
}
}
bool b = true;
if (bx && by) {
cout << 0;
}
if (bx && !by) {
cout << 1 << endl;
cout << vy[0];
}
if (!bx && by) {
cout << 1 << endl;
cout << vx[0];
}
if (!bx && !by) {
if (c) {
cout << 1 << endl;
cout << p;
} else {
cout << 2 << endl;
cout << vx[0] << " " << vy[0];
}
}
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int const MAX_N = 300100;
unsigned int const MAX_HASH = 2000003;
unsigned long long const HASH_CONST = 1000000000000000009ULL;
long long const LL_INF = 1000000000000000000LL;
int n, L, X, Y;
int s[MAX_N];
struct my_list {
int value;
my_list *next;
};
struct my_ht {
my_list *s[MAX_HASH];
my_ht() {
for (int i = 0; i < MAX_HASH; i++) s[i] = 0;
}
void clear() {
for (int i = 0; i < MAX_HASH; i++)
if (s[i] != 0) {
my_list *t = s[i], *tt;
while (t) {
tt = t;
t = t->next;
delete tt;
}
s[i] = 0;
}
}
~my_ht() { clear(); }
unsigned int get_hash(unsigned int v) {
return (((v + 1) * HASH_CONST)) % MAX_HASH;
}
void add(int val) {
unsigned int d = get_hash(val);
my_list *t = new my_list;
t->value = val;
t->next = s[d];
s[d] = t;
}
my_list *find(int val) {
if (val < 0 || val > L) return 0;
unsigned int d = get_hash(val);
my_list *t = s[d];
while (t) {
if (t->value == val) return t;
t = t->next;
}
return 0;
}
} ht;
int main() {
scanf("%d%d%d%d", &n, &L, &X, &Y);
for (int i = 0; i < n; i++) {
scanf("%d", &s[i]);
ht.add(s[i]);
}
int is_X = 0, is_Y = 0;
for (int i = 0; i < n; i++) {
if ((ht.find(s[i] - X) != 0) || (ht.find(s[i] + X) != 0)) is_X = 1;
if ((ht.find(s[i] - Y) != 0) || (ht.find(s[i] + Y) != 0)) is_Y = 1;
}
if (is_X && is_Y) {
cout << "0\n";
return 0;
}
if (is_X && !is_Y) {
cout << "1\n" << Y;
return 0;
}
if (!is_X && is_Y) {
cout << "1\n" << X;
return 0;
}
for (int i = 0; i < n; i++) {
int val = s[i] - X - Y;
if (val >= 0 && val <= L && s[i] - Y >= 0 && s[i] - Y <= L &&
ht.find(val) != 0) {
cout << "1\n" << (s[i] - Y);
return 0;
}
val = s[i] + X - Y;
if (val >= 0 && val <= L && s[i] + X >= 0 && s[i] + X <= L &&
ht.find(val) != 0) {
cout << "1\n" << (s[i] + X);
return 0;
}
val = s[i] - X + Y;
if (val >= 0 && val <= L && s[i] - X >= 0 && s[i] - X <= L &&
ht.find(val) != 0) {
cout << "1\n" << (s[i] - X);
return 0;
}
}
cout << "2\n" << X << " " << Y;
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int inf = (int)1e9;
const int mod = (int)1e9 + 7;
const double pi = acos(-1.0);
const double eps = 1e-9;
int n, a[100005], l, x, y;
map<int, int> cnt;
bool ok[2];
int main() {
scanf("%d%d%d%d", &n, &l, &x, &y);
for (int i = 0; i < n; i++) scanf("%d", a + i);
cnt[0] = 1;
for (int i = 1; i < n; i++) {
int val = a[i] - x;
if (cnt[val] != 0) ok[0] = 1;
val = a[i] - y;
if (cnt[val] != 0) ok[1] = 1;
cnt[a[i]]++;
}
if (ok[1] && ok[0]) return printf("0\n"), 0;
if (ok[1] + ok[0] == 1) {
printf("1\n");
if (ok[0])
printf("%d\n", y);
else
printf("%d\n", x);
return 0;
}
for (int i = 0; i < n; i++) {
int val;
val = x + a[i];
if (cnt[val - y] && val > 0 && val <= l) {
printf("1\n%d\n", val);
return 0;
}
val = x + a[i];
if (cnt[val + y] && val > 0 && val <= l) {
printf("1\n%d\n", val);
return 0;
}
val = a[i] - x;
if (cnt[val + y] && val > 0 && val <= l) {
printf("1\n%d\n", val);
return 0;
}
val = a[i] - x;
if (cnt[val - y] && val > 0 && val <= l) {
printf("1\n%d\n", val);
return 0;
}
}
printf("2\n%d %d\n", x, y);
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
template <class T>
bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
template <class T>
ostream &operator<<(ostream &os, const vector<T> &t) {
os << "[";
for (__typeof((t).begin()) it = (t).begin(); it != (t).end(); it++) {
if (it != t.begin()) os << ",";
os << *it;
}
os << "]";
return os;
}
template <class T>
ostream &operator<<(ostream &os, const set<T> &t) {
os << "{";
for (__typeof((t).begin()) it = (t).begin(); it != (t).end(); it++) {
if (it != t.begin()) os << ",";
os << *it;
}
os << "}";
return os;
}
template <class S, class T>
ostream &operator<<(ostream &os, const pair<S, T> &t) {
return os << "(" << t.first << "," << t.second << ")";
}
const int INF = 1 << 28;
const double EPS = 1e-8;
const int MOD = 1000000007;
int n, l, x, y;
int main() {
scanf("%d%d%d%d", &n, &l, &x, &y);
set<int> me;
int f = 0, tar = 0, tar2 = 0;
for (int i = 0; i < (int)(n); i++) {
int t;
scanf("%d", &t);
me.insert(t);
if (me.count(t - x)) f |= 1;
if (me.count(t - y)) f |= 2;
if (me.count(t - x - y)) {
f |= 4;
tar = t - x;
}
if (me.count(t + x - y)) {
if (t + x <= l) {
f |= 8;
tar2 = t + x;
} else if (0 <= t - y) {
f |= 8;
tar2 = t - y;
}
}
}
if ((f & 3) == 3)
puts("0");
else if (f & 1)
printf("%d\n%d\n", 1, y);
else if (f & 2)
printf("%d\n%d\n", 1, x);
else if (f & 4)
printf("%d\n%d\n", 1, tar);
else if (f & 8)
printf("%d\n%d\n", 1, tar2);
else
printf("%d\n%d %d\n", 2, x, y);
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
map<long long, int> flag;
int main() {
long long n, x, y, l;
int cx = 0, cy = 0, cxy = 0, cyx = 0;
cin >> n >> l >> x >> y;
for (long long i = 0; i < n; i++) {
long long t;
cin >> t;
flag[t] = 1;
if (x == t || flag.count(t - x)) {
cx = 1;
}
if (y == t || flag.count(t - y)) {
cy = 1;
}
if (flag.count(t - (x + y))) {
cxy = t - y;
}
if (flag.count(t - (y - x))) {
if (t + x < l) {
cyx = t + x;
} else if (t - y > 0) {
cyx = t - y;
}
}
}
if (cx && cy) {
cout << "0" << endl;
} else if (cx == 0 && cy == 1) {
cout << "1" << endl;
cout << x << endl;
} else if (cx == 1 && cy == 0) {
cout << "1" << endl;
cout << y << endl;
} else if (cxy) {
cout << "1" << endl;
cout << cxy << endl;
} else if (cyx) {
cout << "1" << endl;
cout << cyx << endl;
} else if (cx == 0 && cy == 0) {
cout << "2" << endl;
cout << x << " " << y << endl;
}
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int n;
long long a[100123], l, x, y;
vector<pair<int, int> > all;
pair<int, int> f(long long v) {
long long sum = 0;
int r = 1;
pair<int, int> ret;
all.clear();
for (int l = 1; l <= n; ++l) {
while (a[r] - a[l] < v) r++;
if (a[r] - a[l] == v) {
all.push_back(pair<int, int>(l, r));
ret = pair<int, int>(l, r);
}
}
if (((int)((all).size()))) return ret;
return pair<int, int>(0, 0);
}
int main() {
ios_base::sync_with_stdio(0);
scanf(" %d %lld %lld %lld", &n, &l, &x, &y);
long long val;
for (int i = 1; i <= n; ++i) {
scanf(" %lld", &a[i]);
}
a[n + 1] = (1LL << 62);
pair<int, int> temx = f(x);
pair<int, int> temy = f(y);
if (!temx.first && !temy.first) {
pair<int, int> temxy = f(x + y);
if (temxy.first) {
printf("1\n%lld\n", a[temxy.first] + x);
} else {
temxy = f(y - x);
if (temxy.first) {
for (int i = 0; i < ((int)((all).size())); ++i) {
temxy = all[i];
if (a[temxy.second] + x < l) {
printf("1\n%lld\n", a[temxy.second] + x);
return 0;
} else if (a[temxy.first] - x > 0) {
printf("1\n%lld\n", a[temxy.first] - x);
return 0;
}
}
printf("2\n%lld %lld\n", x, y);
} else {
printf("2\n%lld %lld\n", x, y);
}
}
} else if (!temx.first && temy.first) {
printf("1\n%lld\n", x);
} else if (temx.first && !temy.first) {
printf("1\n%lld\n", y);
} else {
printf("0\n");
}
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
set<int> s;
int n, a[100001], x, y, l;
int find() {
for (int i = 1; i <= n; i++) {
if (a[i] + x <= l && (s.count(a[i] + x + y) || s.count(a[i] + x - y)))
return a[i] + x;
if (a[i] - x >= 0 && (s.count(a[i] - x + y) || s.count(a[i] - x - y)))
return a[i] - x;
}
return -1;
}
int check(int m) {
for (int i = 1; i <= n; i++)
if (s.count(a[i] - m)) return 1;
return 0;
}
int main() {
scanf("%d%d%d%d", &n, &l, &x, &y);
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
s.insert(a[i]);
}
int tx = check(x);
int ty = check(y);
if (tx && ty)
printf("0\n");
else if (tx && !ty)
printf("1\n%d\n", y);
else if (!tx && ty)
printf("1\n%d\n", x);
else {
int flag = find();
if (flag == -1)
printf("2\n%d %d\n", x, y);
else
printf("1\n%d\n", flag);
}
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
set<int> s;
int main() {
int n, la, x, y, dl, a;
cin >> n >> la >> x >> y;
bool f1 = 0, f2 = 0, f3 = 0;
for (int i = 1; i <= n; i++) {
cin >> a;
if (a - x >= 0 && s.count(a - x)) {
f1 = 1;
}
if (a - y >= 0 && s.count(a - y)) {
f2 = 1;
}
if (a - x - y >= 0 && s.count(a - x - y)) {
f3 = 1;
dl = a - y;
}
if (a - y >= 0 && s.count(a - y + x)) {
f3 = 1;
dl = a - y;
}
if (a + x <= la && s.count(a + x - y)) {
f3 = 1;
dl = a + x;
}
s.insert(a);
}
if (f1 && f2) {
cout << 0 << endl;
return 0;
}
if (f1) {
cout << 1 << endl << y;
return 0;
}
if (f2) {
cout << 1 << endl << x;
return 0;
}
if (f3) {
cout << 1 << endl << dl;
return 0;
}
cout << 2 << endl << x << " " << y;
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int a[100100];
int main() {
int n, l, x, y;
int i;
set<int> s;
set<int>::iterator st;
set<int>::iterator st1;
set<int>::iterator st2;
while (scanf("%d%d%d%d", &n, &l, &x, &y) == 4) {
s.clear();
for (i = 0; i < n; i++) {
scanf("%d", &a[i]);
s.insert(a[i]);
}
st = s.end();
int flagx = 0, flagy = 0;
for (i = 0; i < n; i++) {
if (s.find(a[i] + x) != st) {
flagx = 1;
}
if (s.find(a[i] + y) != st) {
flagy = 1;
}
}
if (flagx == 1 && flagy == 1) {
printf("0\n");
continue;
}
if ((flagx != 0 && flagy == 0) || (flagx == 0 && flagy != 0)) {
int make;
if (flagx == 1) make = y;
if (flagy == 1) make = x;
printf("1\n%d\n", make);
continue;
} else {
int flag = 0;
for (i = 0; i < n; i++) {
if (s.find(a[i] + x + y) != st && (a[i] + x) <= l) {
printf("1\n%d\n", a[i] + x);
flag = 1;
break;
}
if (s.find(a[i] + x - y) != st && (a[i] + x) <= l) {
printf("1\n%d\n", a[i] + x);
flag = 1;
break;
}
if (s.find(a[i] + y - x) != st && (a[i] + y) <= l) {
printf("1\n%d\n", a[i] + y);
flag = 1;
break;
}
if (s.find(a[i] - x + y) != st && (a[i] - x) >= 0) {
printf("1\n%d\n", a[i] - x);
flag = 1;
break;
}
if (s.find(a[i] - y + x) != st && (a[i] - y) >= 0) {
printf("1\n%d\n", a[i] - y);
flag = 1;
break;
}
}
if (flag == 0) {
printf("2\n%d %d\n", x, y);
}
}
}
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
void open() {
freopen("jumps.in", "r", stdin);
freopen("jumps.out", "w", stdout);
}
int n, l, x, y;
int ke[100010];
map<int, bool> mat;
bool vx, vy;
bool in(int x) { return x >= 0 && x <= l; }
int main() {
scanf("%d%d%d%d", &n, &l, &x, &y);
for (int i = 1; i <= n; ++i) scanf("%d", ke + i), mat[ke[i]] = 1;
for (int i = 1; i <= n; ++i) {
if (!vx && mat.count(ke[i] + x)) {
vx = 1;
}
if (!vy && mat.count(ke[i] + y)) {
vy = 1;
}
if (vx && vy) {
printf("0\n");
return 0;
}
}
if (vx || vy) {
printf("1\n%d\n", vx ? y : x);
return 0;
}
for (int i = 1; i <= n; ++i) {
if (mat.count(ke[i] + x + y)) {
printf("1\n%d\n", ke[i] + x);
return 0;
}
if (mat.count(ke[i] + y - x) && in(ke[i] + y)) {
printf("1\n%d\n", ke[i] + y);
return 0;
}
if (mat.count(ke[i] - y + x) && in(ke[i] - y)) {
printf("1\n%d\n", ke[i] - y);
return 0;
}
}
printf("2\n%d %d\n", x, y);
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int a[100200];
int main(int argc, char const *argv[]) {
int n, l, x, y;
cin >> n >> l >> x >> y;
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
}
sort(a, a + n);
int flagx = 0, flagy = 0;
int posx, posy;
for (int i = 0; i < n; i++) {
int tmp = a[i] + x;
posx = lower_bound(a, a + n, tmp) - a;
if (a[posx] == tmp) {
flagx = 1;
break;
}
}
for (int i = 0; i < n; i++) {
int tmp = a[i] + y;
posy = lower_bound(a, a + n, tmp) - a;
if (a[posy] == tmp) {
flagy = 1;
break;
}
}
if (flagx && flagy) {
printf("%d\n", 0);
return 0;
} else if (flagx && !flagy) {
printf("%d\n", 1);
printf("%d\n", y);
return 0;
} else if (!flagx && flagy) {
printf("%d\n", 1);
printf("%d\n", x);
return 0;
} else {
for (int i = 0; i < n; i++) {
int tmp = a[i] - x;
if (tmp > l) break;
tmp += y;
int pos1 = lower_bound(a, a + n, tmp) - a;
tmp -= y;
tmp -= y;
int pos2 = lower_bound(a, a + n, tmp) - a;
if (a[i] - x >= 0 && (tmp + 2 * y == a[pos1] || tmp == a[pos2])) {
printf("%d\n", 1);
printf("%d\n", a[i] - x);
return 0;
}
tmp = a[i] + x;
tmp += y;
pos1 = lower_bound(a, a + n, tmp) - a;
tmp -= y;
tmp -= y;
pos2 = lower_bound(a, a + n, tmp) - a;
if (a[i] + x <= l && (tmp + 2 * y == a[pos1] || tmp == a[pos2])) {
printf("%d\n", 1);
printf("%d\n", a[i] + x);
return 0;
}
}
printf("%d\n", 2);
printf("%d %d\n", x, y);
}
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100001;
int n, l, x, y, a[maxn];
bool calc(int x) {
if (x < 0 || x > l) return 0;
int k = lower_bound(a + 1, a + n + 1, x) - a;
return (x == a[k]);
}
void get() {
int ans = 0, i;
for (i = 1; i <= n; i++) {
if (calc(a[i] - x) || calc(a[i] + x)) ans |= 1;
if (calc(a[i] - y) || calc(a[i] + y)) ans |= 2;
}
if (ans == 3)
printf("0\n");
else if (ans == 2)
printf("1\n%d\n", x);
else if (ans == 1)
printf("1\n%d\n", y);
else {
for (i = 1; i <= n; i++) {
int tx = a[i] + x, ty = a[i] + y;
if (tx <= l && (calc(tx - y) || calc(tx + y))) {
printf("1\n%d\n", tx);
return;
}
if (ty <= l && (calc(ty - x) || calc(ty + x))) {
printf("1\n%d\n", ty);
return;
}
}
for (i = 1; i <= n; i++) {
int tx = a[i] - x, ty = a[i] - y;
if (tx >= 0 && (calc(tx - y) || calc(tx + y))) {
printf("1\n%d\n", tx);
return;
}
if (ty >= 0 && (calc(ty - x) || calc(ty + x))) {
printf("1\n%d\n", ty);
return;
}
}
printf("2\n%d %d\n", x, y);
}
}
int main() {
int i;
scanf("%d%d%d%d", &n, &l, &x, &y);
for (i = 1; i <= n; i++) scanf("%d", &a[i]);
get();
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
set<int> H;
vector<int> r;
int n, l, x, y;
bool valid(int tmp) { return tmp >= 0 && tmp <= l; }
int main() {
scanf("%d%d%d%d", &n, &l, &x, &y);
for (int i = 0; i < n; i++) {
int ha;
scanf("%d", &ha);
H.insert(ha);
}
r.push_back(x);
r.push_back(y);
bool suc1 = false;
for (set<int>::iterator it = H.begin(); it != H.end(); it++) {
int me = *it;
int nt = me - x;
if (H.count(nt)) {
suc1 = true;
if (r.size() == 2) {
r.clear();
r.push_back(y);
}
} else if (valid(nt)) {
if (H.count(nt + y) || H.count(nt - y)) {
if (r.size() == 2) {
r.clear();
r.push_back(nt);
}
}
}
nt = me + x;
if (H.count(nt)) {
suc1 = true;
if (r.size() == 2) {
r.clear();
r.push_back(y);
}
} else if (valid(nt)) {
if (H.count(nt + y) || H.count(nt - y)) {
if (r.size() == 2) {
r.clear();
r.push_back(nt);
}
}
}
}
bool suc2 = false;
for (set<int>::iterator it = H.begin(); it != H.end(); it++) {
int me = *it;
int nt = me - y;
if (H.count(nt)) {
suc2 = true;
if (r.size() == 2) {
r.clear();
r.push_back(x);
}
} else if (valid(nt)) {
if (H.count(nt + x) || H.count(nt - x)) {
if (r.size() == 2) {
r.clear();
r.push_back(nt);
}
}
}
nt = me + y;
if (H.count(nt)) {
suc2 = true;
if (r.size() == 2) {
r.clear();
r.push_back(x);
}
} else if (valid(nt)) {
if (H.count(nt + x) || H.count(nt - x)) {
if (r.size() == 2) {
r.clear();
r.push_back(nt);
}
}
}
}
if (suc1 && suc2) r.clear();
printf("%d\n", (int)r.size());
for (int i = 0; i < r.size(); i++) {
printf("%d\n", r[i]);
}
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int toInt(string s) {
int r = 0;
istringstream sin(s);
sin >> r;
return r;
}
long long toInt64(string s) {
long long r = 0;
istringstream sin(s);
sin >> r;
return r;
}
double toDouble(string s) {
double r = 0;
istringstream sin(s);
sin >> r;
return r;
}
string toString(long long n) {
string s, s1;
while (n / 10 > 0) {
s += (char)((n % 10) + 48);
n /= 10;
}
s += (char)((n % 10) + 48);
n /= 10;
s1 = s;
for (long long i = 0; i < s.length(); i++) s1[(s.length() - 1) - i] = s[i];
return s1;
}
bool isUpperCase(char c) { return c >= 'A' && c <= 'Z'; }
bool isLowerCase(char c) { return c >= 'a' && c <= 'z'; }
bool isLetter(char c) { return c >= 'A' && c <= 'Z' || c >= 'a' && c <= 'z'; }
bool isDigit(char c) { return c >= '0' && c <= '9'; }
char toLowerCase(char c) { return (isUpperCase(c)) ? (c + 32) : c; }
char toUpperCase(char c) { return (isLowerCase(c)) ? (c - 32) : c; }
long long gcd(long long a, long long b) {
if (!a) return b;
return gcd(b % a, a);
}
vector<long long> q;
long long a[100001];
long long n, l;
bool two(long long x) {
long long sum = 0;
long long f = 0, s = -1;
long long len = q.size();
while (f < len && s < len) {
if (sum == x)
return true;
else if (sum < x) {
if (s + 1 >= len) return false;
sum += q[++s];
} else if (sum > x)
sum -= q[f++];
}
if (sum == x) return true;
return false;
}
vector<long long> find(long long x) {
vector<long long> ans;
ans.push_back(x);
ans.push_back(l - x);
for (long long i = 1; i < n - 1; i++) {
if (a[i] + x <= l) ans.push_back(a[i] + x);
if (a[i] - x >= 0) ans.push_back(a[i] - x);
}
return ans;
}
long long common(vector<long long> x, vector<long long> y) {
map<long long, bool> mark;
for (long long i = 0; i < x.size(); i++) mark[x[i]] = true;
for (long long j = 0; j < y.size(); j++)
if (mark[y[j]] == true) return y[j];
return -1;
}
int main() {
ios::sync_with_stdio(0);
long long x, y;
cin >> n >> l >> x >> y;
for (long long i = 0; i < n; i++) {
cin >> a[i];
if (i != 0) q.push_back(a[i] - a[i - 1]);
}
bool X = two(x), Y = two(y);
long long bads = 0;
if (!X) bads++;
if (!Y) bads++;
if (bads == 0)
cout << 0 << endl;
else if (bads == 1) {
cout << 1 << endl;
if (!X)
cout << x << endl;
else
cout << y << endl;
} else if (bads == 2) {
vector<long long> comA = find(x);
vector<long long> comB = find(y);
long long point = common(comA, comB);
if (point == -1)
cout << 2 << endl << x << ' ' << y << endl;
else
cout << 1 << endl << point << endl;
}
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int n, x, y, l;
vector<int> ruler;
vector<int> X;
vector<int> Y;
int xFound;
int yFound;
int isThere(int x, vector<int> &v) {
if (binary_search(v.begin(), v.end(), x)) return 1;
return 0;
}
int checkZero() {
for (int i = 0; i < n; i++) {
int toAdd = ruler[i] - x;
if (isThere(toAdd, ruler)) {
xFound = 1;
}
if (toAdd >= 0) X.push_back(toAdd);
toAdd = ruler[i] + x;
if (isThere(toAdd, ruler)) {
xFound = 1;
}
if (toAdd <= l) X.push_back(toAdd);
toAdd = ruler[i] - y;
if (isThere(toAdd, ruler)) {
yFound = 1;
}
if (toAdd >= 0) Y.push_back(toAdd);
toAdd = ruler[i] + y;
if (isThere(toAdd, ruler)) {
yFound = 1;
}
if (toAdd <= l) Y.push_back(toAdd);
}
return (xFound + yFound == 2);
}
int checkOne() {
sort(X.begin(), X.end());
sort(Y.begin(), Y.end());
if (xFound == 1 && yFound == 0) {
cout << 1 << endl;
cout << y << endl;
return 1;
}
if (yFound == 1 && xFound == 0) {
cout << 1 << endl;
cout << x << endl;
return 1;
}
int size = X.size();
for (int i = 0; i < size; i++) {
if (isThere(X[i], Y)) {
cout << 1 << endl;
cout << X[i] << endl;
return 1;
}
}
return 0;
}
int main() {
cin >> n >> l >> x >> y;
for (int i = 0; i < n; i++) {
int a;
cin >> a;
ruler.push_back(a);
}
if (checkZero()) {
cout << 0 << endl;
return 0;
}
if (checkOne()) {
return 0;
}
int len = X.size();
cout << 2 << endl;
cout << x << " " << y << endl;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
vector<int> a;
int main() {
int n, l, x, y;
scanf("%d %d %d %d", &n, &l, &x, &y);
for (int i = 0; i < n; i++) {
int z;
scanf("%d", &z);
a.push_back(z);
}
sort(a.begin(), a.end());
bool f1 = binary_search(a.begin(), a.end(), x);
bool f2 = binary_search(a.begin(), a.end(), y);
for (int i = 0; i < n; i++) {
if (binary_search(a.begin(), a.end(), a[i] + y)) {
f2 = true;
}
if (binary_search(a.begin(), a.end(), a[i] - y)) {
f2 = true;
}
if (binary_search(a.begin(), a.end(), a[i] + x)) {
f1 = true;
}
if (binary_search(a.begin(), a.end(), a[i] - x)) {
f1 = true;
}
}
if (f1 && f2) {
cout << 0;
return 0;
}
if (f1) {
cout << 1 << endl;
cout << y;
return 0;
}
if (f2) {
cout << 1 << endl;
cout << x;
return 0;
}
int result = -1;
for (int i = 0; i < n; i++) {
if (a[i] + x <= a[n - 1]) {
if (binary_search(a.begin(), a.end(), a[i] + x - y) ||
binary_search(a.begin(), a.end(), a[i] + x + y)) {
result = a[i] + x;
break;
}
}
if (a[i] - x >= a[0]) {
if (binary_search(a.begin(), a.end(), a[i] - x - y) ||
binary_search(a.begin(), a.end(), a[i] - x + y)) {
result = a[i] - x;
break;
}
}
if (a[i] + y <= a[n - 1]) {
if (binary_search(a.begin(), a.end(), a[i] + y - x) ||
binary_search(a.begin(), a.end(), a[i] + y + x)) {
result = a[i] + y;
break;
}
}
if (a[i] - y >= a[0]) {
if (binary_search(a.begin(), a.end(), a[i] - y - x) ||
binary_search(a.begin(), a.end(), a[i] - x + y)) {
result = a[i] - y;
break;
}
}
}
if (result != -1) {
cout << 1 << endl;
cout << result;
} else {
cout << 2 << endl;
cout << x << " " << y;
}
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int n;
long long l, x, y, arr[100005];
map<long long, bool> b;
int main() {
scanf("%d", &n);
scanf("%I64d%I64d%I64d", &l, &x, &y);
arr[0] = 0;
for (int i = 0; i < n; i++) {
scanf("%I64d", &arr[i]);
b[arr[i]] = 1;
}
int c = 100000;
long long sol;
bool first = 0, second = 0;
for (int i = 0; i < n + 1; i++) {
if (b[arr[i] + x]) {
first = 1;
}
if (b[arr[i] + y]) {
second = 1;
}
}
if (first && second) {
printf("0\n");
return 0;
}
if (first) {
printf("1\n%I64d\n", y);
return 0;
}
if (second) {
printf("1\n%I64d\n", x);
return 0;
}
for (int i = 0; i < n; i++) {
if (b[arr[i] + x + y]) {
printf("1\n%I64d\n", arr[i] + x);
return 0;
}
if (b[arr[i] - x + y] && arr[i] - x >= 0) {
printf("1\n%I64d\n", arr[i] - x);
return 0;
}
if (b[arr[i] - x + y] && arr[i] + y <= l) {
printf("1\n%I64d\n", arr[i] + y);
return 0;
}
if (b[arr[i] + x - y] && arr[i] - y >= 0) {
printf("1\n%I64d\n", arr[i] - y);
return 0;
}
if (b[arr[i] + x - y] && arr[i] + x <= l) {
printf("1\n%I64d\n", arr[i] + x);
return 0;
}
}
printf("2\n%I64d %I64d\n", x, y);
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int n;
long long l, x, y;
vector<long long> a;
map<long long, long long> m;
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n >> l >> x >> y;
long long s = 0;
bool ok1, ok2;
ok1 = ok2 = false;
a = vector<long long>(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
if (m.count(a[i] - x)) {
ok1 = true;
}
if (m.count(a[i] - y)) {
ok2 = true;
}
m[a[i]] = 1;
}
if (x + y == 0) {
cout << "0\n";
return 0;
}
if (ok1 & ok2) {
cout << "0\n";
return 0;
}
if (ok1) {
cout << "1\n";
cout << y << "\n";
return 0;
}
if (ok2) {
cout << "1\n";
cout << x << "\n";
return 0;
}
for (int i = 0; i < n; i++) {
int l1 = upper_bound(a.begin(), a.end(), a[i] + x - y) - a.begin();
if (l1 && a[l1 - 1] == a[i] + x - y && a[i] + x <= a[n - 1]) {
cout << "1\n" << a[i] + x << '\n';
return 0;
}
l1 = upper_bound(a.begin(), a.end(), a[i] + x + y) - a.begin();
if (l1 && a[l1 - 1] == a[i] + x + y && a[i] + x <= a[n - 1]) {
cout << "1\n" << a[i] + x << '\n';
return 0;
}
l1 = upper_bound(a.begin(), a.end(), a[i] - x + y) - a.begin();
if (l1 && a[l1 - 1] == a[i] - x + y && a[i] - x >= 0) {
cout << "1\n" << a[i] - x << '\n';
return 0;
}
l1 = upper_bound(a.begin(), a.end(), a[i] - x - y) - a.begin();
if (l1 && a[l1 - 1] == a[i] - x - y && a[i] - x >= 0) {
cout << "1\n" << a[i] - x << '\n';
return 0;
}
}
cout << "2\n";
cout << x << " " << y << "\n";
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
const long long int N = 1e5 + 5;
const long long int mod = 1e17 + 7;
set<long long int> s;
bool gi, bo;
long long int res = 0;
long long int c[5];
int main() {
ios::sync_with_stdio(false);
long long int n, l, x, y;
cin >> n >> l >> x >> y;
for (long long int i = 1; i < n + 1; i++) {
long long int z;
cin >> z;
s.insert(z);
if (s.count(z - x) or s.count(z + x)) {
gi = 1;
}
if (s.count(z - y) or s.count(z + y)) {
bo = 1;
}
if (gi == 1 and bo == 1) {
cout << "0\n";
return 0;
}
if (res != 1) {
if (s.count(z - x - y)) {
res = 1;
c[1] = z - x;
}
if (s.count(z + x + y)) {
res = 1;
c[1] = z + x;
}
if (s.count(z + x - y) and z + x <= l) {
res = 1;
c[1] = z + x;
}
if (s.count(z - x + y) and z + y <= l) {
res = 1;
c[1] = z + y;
}
if (s.count(z + x - y) and z - y >= 0) {
res = 1;
c[1] = z - y;
}
if (s.count(z - x + y) and z - x >= 0) {
res = 1;
c[1] = z - x;
}
}
}
if (res != 1) {
res = 0;
if (!gi) {
res++;
c[res] = x;
s.insert(x);
}
if (!bo) {
res++;
c[res] = y;
}
}
cout << res << endl;
for (long long int i = 1; i < res + 1; i++) {
cout << c[i] << " ";
}
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
long long n, l, x, y, a[100001];
map<long long, long long> m;
void read() {
cin >> n >> l >> x >> y;
for (long long i = 1; i < n + 1; i++) {
cin >> a[i];
m[a[i]] = i;
}
}
long long f(long long d) {
for (long long i = 1; i < n + 1; i++) {
if (m.count(a[i] + d)) return i;
}
return 0;
}
signed main() {
cin.tie(0);
cout.tie(0);
ios_base::sync_with_stdio(false);
read();
long long temp1 = f(x), temp2 = f(y);
if (temp1 > 0) {
if (temp2 > 0)
return cout << 0, 0;
else
return cout << "1\n" << y, 0;
}
if (temp2 > 0) {
return cout << "1\n" << x, 0;
}
long long temp = f(x + y);
if (temp > 0) {
return cout << 1 << "\n" << a[temp] + x, 0;
}
for (long long i = 1; i < n + 1; i++) {
if (m.count(a[i] + y - x) && a[i] - x >= 0)
return cout << "1\n" << a[i] - x, 0;
if (m.count(a[i] + y - x) && a[i] + y <= l)
return cout << "1\n" << a[i] + y, 0;
}
cout << 2 << "\n" << x << " " << y;
return 0;
}
| 8 | CPP |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.