#include<bits/stdc++.h> usingnamespace std; using ll = longlong;
intmain(){ int t; cin >> t;
while (t--) { int n; cin >> n;
vector<int> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; }
int p = 0; for (int i = 0; i < n; i++) { if (a[i] != 1 && a[i] != -1) { p = i; } }
set<int> res; res.insert(0); int sum = 0; int maxr = 0, minr = 0; for (int i = p + 1; i < n; i++) { sum += a[i]; maxr = max(maxr, sum); minr = min(minr, sum); } sum = 0; int maxl = 0, minl = 0; for (int i = p - 1; i >= 0; i--) { sum += a[i]; maxl = max(maxl, sum); minl = min(minl, sum); } for (int i = minl + minr; i <= maxl + maxr; i++) { res.insert(a[p] + i); }
auto solve = [&](int l, int r) { int maxsum = 0, maxx = -2e9; for (int i = l; i < r; i++) { maxsum += a[i]; maxx = max(maxx, maxsum); if (maxsum < 0) { maxsum = 0; } } int minsum = 0, minn = 2e9; for (int i = l; i < r; i++) { minsum += a[i]; minn = min(minn, minsum); if (minsum > 0) { minsum = 0; } } for (int i = minn; i <= maxx; i++) { res.insert(i); } };
solve(0, p); solve(p + 1, n);
cout << res.size() << endl; for (auto x : res) { cout << x << " "; } cout << endl; }
#include<bits/stdc++.h> usingnamespace std; using ll = longlong;
intmain(){ int t; cin >> t;
while (t--) { ll l, r, d; cin >> l >> r >> d;
r = r / d; l = (l + d - 1) / d;
bool ok = false; for (ll len = r - l; len >= 0; len--) { for (ll j = l; j + len <= r; j++) { if (gcd(j, j + len) == 1) { l = j, r = j + len; ok = true; break; } } if (ok) break; }