inlineintread(){ int s = 0, x = 1; char ch = getchar(); while (!isdigit(ch)) { if (ch == '-') x = -x; ch = getchar(); } while (isdigit(ch)) { s = s * 10 + ch - '0'; ch = getchar(); } return s * x; }
int l, r;
intmain(){ int T = read(); while (T --> 0) { l = read(); r = read(); if (l * 2 > r) puts("-1 -1"); elseprintf("%d %d\n", l, l * 2); } return0; }
inlineintread(){ int s = 0, x = 1; char ch = getchar(); while (!isdigit(ch)) { if (ch == '-') x = -x; ch = getchar(); } while (isdigit(ch)) { s = s * 10 + ch - '0'; ch = getchar(); } return s * x; }
int n, k, z; int aa[MAXN]; int dp[MAXN][MAXZ]; int ans;
voidcleanup(){ memset(dp, 0, sizeof dp); ans = 0; }
intmain(){ int T = read(); while (T --> 0) { n = read(); k = read(); z = read(); for (int i = 1; i <= n; ++i) aa[i] = read(); for (int j = 0; j <= z; ++j) { for (int i = 1; i <= n; ++i) { dp[i][j] = dp[i - 1][j]; if (i != n && j) dp[i][j] = std::max(dp[i][j], dp[i + 1][j - 1]); dp[i][j] += aa[i]; if (i - 1 + j * 2 == k) ans = std::max(ans, dp[i][j]); } } printf("%d\n", ans); cleanup(); } return0; }
inlineintread(){ int x; scanf("%d", &x); return x; }
constint MAXN = 2e5 + 10;
int n; char ss[MAXN];
intmain(){ int T = read(); while (T --> 0) { scanf("%s", ss + 1); n = (int) strlen(ss + 1); int mx = 0; for (int a = 0; a <= 9; ++a) { for (int b = 0; b <= 9; ++b) { int len = 0; for (int i = 1; i <= n; ++i) { if (len % 2 == 0) { len += (ss[i] - '0' == a); } else { len += (ss[i] - '0' == b); } } if (len % 2 == 1 && a != b) --len; mx = std::max(mx, len); } } printf("%d\n", n - mx); } return0; }
inlineintread(){ int s = 0, x = 1; char ch = getchar(); while (!isdigit(ch)) { if (ch == '-') x = -x; ch = getchar(); } while (isdigit(ch)) { s = s * 10 + ch - '0'; ch = getchar(); } return s * x; }
voidread(int arg){ arg = 0; n = read(); k = read(); int l = read(); int r = read(); aa = Interval(l, r); l = read(); r = read(); bb = Interval(l,r); if (bb < aa) std::swap(bb, aa); k -= (aa & bb) * n; }
intmain(){ int T = read(); while (T --> 0) { read(0); if (k <= 0) { puts("0"); continue; } // aa.l <= bb.l if (aa.r <= bb.l) { // 最麻烦的,两个区间不交 longlongint ans = 0x7f7f7f7f7f7f7f7f; int ptr = 1; int full = bb.r - aa.l, expand = bb.l - aa.r; if (1ll * n * full <= k) { printf("%lld\n", 1ll * n * (full + expand) + (k - 1ll * n * full) * 2); } else { while (ptr <= n) { if (ptr * full <= k) ans = std::min(ans, ptr * (expand + full) + (k - 1ll * ptr * full) * 2); elsebreak; ++ptr; } ans = std::min(ans, 1ll * k + 1ll * ((k - 1) / full + 1) * expand); printf("%lld\n", ans); } } else { // aa.l <= bb.l <= bb.r int exl = std::abs(bb.l - aa.l); int exr = std::abs(aa.r - bb.r); if (1ll * (exl + exr) * n >= k) { printf("%d\n", k); } elseprintf("%lld\n", 2ll * k - 1ll * (exl + exr) * n); } } return0; }