inlineintrd(){ int x = 0; bool f = 0; char c = getchar(); for (; !isdigit(c); c = getchar()) f |= (c == '-'); for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48); return f ? -x : x; }
#define N 200007
int n, k, m, dlt[N];
ll c, d, a[N];
inlineboolvalid(ll x){ for (int i = 1; i <= n; ++i) dlt[i] = 0; auto add = [&](ll l, ll r) { l = max(l, 1ll); r = min(r, n - m + 1ll); if (r < l) return; ++dlt[l]; --dlt[r + 1]; }; for (int i = 1; i <= n; ++i) { if (a[i] >= x) ++dlt[1]; else { if (x - a[i] <= c) add(i - m + 1, i); elseif (d != 0) add(i - m + 1, i - ((x - a[i] - c + d - 1) / d)); } } int mx = 0; for (int i = 1; i <= n; ++i) { dlt[i] += dlt[i - 1]; mx = max(mx, dlt[i]); } return mx >= k; }
intmain(){ n = rd(), k = rd(), m = rd(); c = rd(), d = rd(); for (int i = 1; i <= n; ++i) a[i] = rd(); ll l = 0, r = 1e18; while (l < r) { ll mid = (l + r + 1) / 2; valid(mid) ? l = mid : r = mid - 1; } printf("%lld\n", l); return0; }
inlineintrd(){ int x = 0; bool f = 0; char c = getchar(); for (; !isdigit(c); c = getchar()) f |= (c == '-'); for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48); return f ? -x : x; }
intgcd(int a, int b){return b ? gcd(b, a % b) : a;}
inlinevoidwork(){ bool fl = false; int n = rd(), cnt = 1, sum = 1, reg = 0; for (int i = 1; i <= n; ++i) { int x = rd(); if (x == 1) {++cnt; ++sum;} elseif (x == -1) { --cnt; if (!cnt) { if (reg) {--reg; cnt += 2; sum += 1;} else fl = true; } } else { if (cnt > 1) {--cnt; ++reg;} else {++cnt; ++sum;} } } if (fl) {puts("-1"); return;} int g = gcd(sum, cnt); printf("%d %d\n", sum / g, cnt / g); }
intmain(){ for (int t = rd(); t; --t) work(); return0; }
inlineintrd(){ int x = 0; bool f = 0; char c = getchar(); for (; !isdigit(c); c = getchar()) f |= (c == '-'); for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48); return f ? -x : x; }
#define N 1000007
int f[N], a[N];
intgcd(int a, int b){return b ? gcd(b, a % b) : a;}
inlinevoidwork(){ int n = rd(); for (int i = 1; i <= n; ++i) a[i] = rd(); f[n + 1] = 0; for (int i = n; i; --i) if (a[i] == 0) f[i] = f[i + 1]; elseif (a[i] == -1) f[i] = f[i + 1] + 1; else f[i] = max(0, f[i + 1] - 1); int nw = 1, sum = 1; for (int i = 1; i <= n; ++i) if (a[i] == -1) {--nw; if (!nw) {puts("-1"); return;}} elseif (a[i] == 1) {++nw; ++sum;} else { if (nw <= f[i] + 1) {++nw; ++sum;} else --nw; } int g = gcd(nw, sum); printf("%d %d\n", sum / g, nw / g); }
intmain(){ for (int t = rd(); t; --t) work(); return0; }
inlineintrd(){ int x = 0; bool f = 0; char c = getchar(); for (; !isdigit(c); c = getchar()) f |= (c == '-'); for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48); return f ? -x : x; }
int cnt[27];
char s[100007];
inlinevoidwork(){ scanf("%s", s + 1); for (int i = strlen(s + 1); i; --i) ++cnt[s[i] - 'a']; int ans = 0; for (int i = 0; i < 26; ++i) { ans = max(ans, cnt[i]); cnt[i] = 0; } printf("%d\n", (int)strlen(s + 1) - ans); }
intmain(){ for (int t = rd(); t; --t) work(); return0; }
#define T int typedefpair<T, T> pii; typedef tuple<T, T, T> tii;
#define fr first #define sc second #define mp make_pair #define mt make_tuple #define pb push_back #define eb emplace_back
#define lowbit(x) ((x) & -(x)) #define all(x) (x).begin(), (x).end() #define rep(i, x, y) for (int i = (x); i <= (y); ++i) #define per(i, x, y) for (int i = (x); i >= (y); --i)
inline T rd(){ T x = 0; bool f = 0; char c = getchar(); for (; !isdigit(c); c = getchar()) f |= (c == '-'); for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48); return f ? -x : x; }
#define N 200007
int tot, hd[N], a[N];
structedge {int to, nxt;} e[N];
inlinevoidadd(int u, int v){ e[++tot] = {v, hd[u]}; hd[u] = tot; e[++tot] = {u, hd[v]}; hd[v] = tot; }
bool vis[N], used[N];
vector<pii> ans;
voiddfs(int u, int fa){ vis[u] = true; int faid = 0; for (int i = hd[u], v; i; i = e[i].nxt) if (!vis[v = e[i].to]) dfs(v, u); elseif (v == fa) faid = (i >> 1); int lst = 0; for (int i = hd[u], v, id; i; i = e[i].nxt) if ((v = e[i].to) != fa && !used[id = (i >> 1)]) { if (lst) { used[lst] = used[id] = true; ans.eb(lst, id); lst = 0; } else lst = id; } if (lst && faid) { used[lst] = used[faid] = true; ans.eb(lst, faid); } }
vector<int> L, R;
inlinevoidwork(){
int m = rd(); L.clear(); R.clear(); ans.clear(); rep (i, 1, m) {a[i] = rd(); L.pb(a[i] + i); R.pb(a[i] - i);} sort(all(L)); L.erase(unique(all(L)), L.end()); sort(all(R)); R.erase(unique(all(R)), R.end()); auto lid = [&](int x) {return lower_bound(all(L), x) - L.begin() + 1;}; auto rid = [&](int x) {return lower_bound(all(R), x) - R.begin() + 1 + L.size();};
tot = 1; int n = L.size() + R.size(); rep(i, 1, n) {hd[i] = 0; vis[i] = false;} rep(i, 1, m) {used[i] = false; add(lid(a[i] + i), rid(a[i] - i));} rep(i, 1, n) if (!vis[i]) dfs(i, i); if (ans.size() * 2 != m) {puts("No"); return;} puts("Yes"); for (auto [x, y] : ans) printf("%d %d\n", x, y); }
intmain(){ for (int t = rd(); t; --t) work(); return0; }
inline T rd(){ T x = 0; bool f = 0; char c = getchar(); for (; !isdigit(c); c = getchar()) f |= (c == '-'); for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48); return f ? -x : x; }
#define letp const P // P for Point
structP { T x, y; P (T x = 0, T y = 0) : x(x), y(y) {} P operator - (letp &p) const {return {x - p.x, y - p.y};} T operator | (letp &p) const {return x * p.x + y * p.y;} // dot T operator ^ (letp &p) const {return x * p.y - y * p.x;} // cross // left(counterclockwise) = 1 | on = 0 | right(clockwise) = -1 intori(letp &p)const{T t = (*this) ^ p; return (t > 0) - (t < 0);} };
intmain(){ int n = rd(); vector<P> p(n); for (int i = 0; i < n; ++i) {p[i].x = rd(); p[i].y = rd();} auto nxt = [&](constint i) {return i == p.size() - 1 ? 0 : i + 1;}; auto pre = [&](constint i) {return i == 0 ? p.size() - 1 : i - 1;};
int l, r, L = 0, ans = 0; for (; p[L].y == p[pre(L)].y; L = pre(L)); l = r = L; do { while (p[r].y == p[nxt(r)].y) r = nxt(r); if (p[pre(l)].y > p[l].y && p[nxt(r)].y > p[r].y) { if (l == r) ans += ((p[l] - p[pre(l)]).ori(p[nxt(l)] - p[l]) > 0); else ans += (p[nxt(l)].x > p[l].x); } l = r = nxt(r); } while (l != L); printf("%d\n", ans); return0; }