#define int long long #define x first #define y second
usingnamespace std;
typedef pair<int, int> PII;
constint N = 200010;
int T; int n; string s;
voidsolve() { cin >> n >> s;
int l = 0, r = n; while (l < r) { int mid = l + r >> 1; if (mid * mid < n) l = mid + 1; else r = mid; }
if (l * l != n) { cout << "No" << endl; return; }
for (int i = 0; i < l; i++) if (s[i] == '0') { cout << "No" << endl; return; } for (int i = n - 1 - l; i < n; i++) if (s[i] == '0') { cout << "No" << endl; return; }
int id = l; while (id + l != n) { for (int i = 0; i < l; i++) { if (i == 0 || i == l - 1) { if (s[id] == '0') { cout << "No" << endl; return; } } else { if (s[id] == '1') { cout << "No" << endl; return; } } id++; } }
#define int long long #define x first #define y second
usingnamespace std;
typedef pair<int, int> PII;
constint N = 200010, mod = 1e9 + 7;
int T; int n; int a[N];
intqmi(int a, int b) { int res = 1; while (b) { if (b & 1) res = res * a % mod; a = a * a % mod; b >>= 1; } return res; }
signedmain() { cin >> T; while (T--) { cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; int sum = 0; for (int i = 0; i < n; i++) sum = (sum + a[i]) % mod; int res = 0; for (int i = 0; i < n; i++) { sum = (sum - a[i] + mod) % mod; res = (res + a[i] * sum % mod) % mod; } int q = (n - 1) * n / 2 % mod; res = res * qmi(q, mod - 2) % mod; cout << res << endl; }
intgcd(int a, int b) { return b? gcd(b, a % b) : a; }
signedmain() { cin >> T; while (T--) { cin >> n >> k; for (int i = 0; i < n; i++) cin >> a[i]; if (n == 1) { if (a[0] < k) cout << k << endl; else cout << k - 1 << endl; continue; } int g = 0; for (int i = 0; i < n; i++) g = gcd(g, a[i]); int res = 0; for (int i = 0; i < n; i++) { if (k <= g - 1 || i == n - 1) { res = g * i + k; break; } else k -= g - 1; } cout << res << endl; }
boolcheck(int k) { int cnt = 0; for (int i = 1; i <= n; i += x) { int l = i, r = min(i + k - 1, n); cnt += s[r] - s[l - 1]; if (i + x - 1 <= n) cnt += s[i + x - 1] - s[i + x - 2]; } return cnt >= n / 2 + 1; }
signedmain() { cin >> T; while (T--) { cin >> n >> q; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 1; i <= n; i++) s[i] = 0; for (int i = 0; i < n; i++) s[a[i]]++; for (int i = 1; i <= n; i++) s[i] += s[i - 1]; while (q--) { cin >> x; int l = 0, r = x - 1; while (l < r) { int mid = l + r >> 1; if (!check(mid)) l = mid + 1; else r = mid; } cout << l << ' '; } cout << endl; }