#include<bits/stdc++.h> // #define int long long #define pb push_back using std::cin, std::cout, std::string; intread(int x = 0, int f = 0, char ch = getchar()) { while (ch < 48or57 < ch) f = ch == 45, ch = getchar(); while(48 <= ch and ch <= 57) x = x * 10 + ch - 48, ch = getchar(); return f ? -x : x; } constint N = 1e6 + 5; constint INF = 1 << 30; // const long long INF = 1LL << 60; int n, a[N]; voidsolve() { int x = read(); string ans = ""; if (x > 52) ans += char('a' + x - 52 - 1), x -= (ans[0] - 'a' + 1); else ans += 'a', x--; if (x > 26) ans += char('a' + x - 26 - 1), x -= (ans[1] - 'a' + 1); else ans += 'a', x--; ans += char('a' + x - 1); cout << ans << '\n'; }
signedmain() { #ifndef ONLINE_JUDGE freopen("A.in", "r", stdin); #endif for (int T = read(); T--; solve()); return0; }
#include<bits/stdc++.h> #define int long long #define pb push_back using std::cin, std::cout, std::string; intread(int x = 0, int f = 0, char ch = getchar()) { while (ch < 48or57 < ch) f = ch == 45, ch = getchar(); while(48 <= ch and ch <= 57) x = x * 10 + ch - 48, ch = getchar(); return f ? -x : x; } constint N = 1e6 + 5; constint INF = 1 << 30; // const long long INF = 1LL << 60; int n, a[N]; voidsolve() { int n = read(), sum = 0, f = 1, tot = 0; for (int i = 1; i <= n; i++) a[i] = read(), sum += a[i]; sum /= n; for (int i = 1; i <= n; i++) { if (a[i] > sum) tot += a[i] - sum; else tot -= sum - a[i]; if (tot < 0) f = 0; } puts(f ? "YES" : "NO"); }
signedmain() { #ifndef ONLINE_JUDGE freopen("B.in", "r", stdin); #endif for (int T = read(); T--; solve()); return0; }
#include<bits/stdc++.h> // #define int long long #define pb push_back using std::cin, std::cout, std::string; intread(int x = 0, int f = 0, char ch = getchar()) { while (ch < 48or57 < ch) f = ch == 45, ch = getchar(); while(48 <= ch and ch <= 57) x = x * 10 + ch - 48, ch = getchar(); return f ? -x : x; } constint N = 2e5 + 5; constint INF = 1 << 30; // const long long INF = 1LL << 60; int n, a[N], b[N], c[N]; voidsolve() { n = read(); for (int i = 1; i <= n; i++) a[i] = read(); if (n == 1) returnputs("0"), void(); int l, r, ans = n; l = 0, r = n + 1; for (int i = 1; i <= n; i++) if (a[i] == a[1]) l = i; elsebreak; for (int i = n; i >= 1; i--) if (a[i] == a[1]) r = i; elsebreak; if (l == n and r == 1) returnputs("0"), void(); ans = r - l - 1; l = 0, r = n + 1; for (int i = 1; i <= n; i++) if (a[i] == a[n]) l = i; elsebreak; for (int i = n; i >= 1; i--) if (a[i] == a[n]) r = i; elsebreak; ans = std::min(ans, r - l - 1); cout << ans << '\n'; }
signedmain() { #ifndef ONLINE_JUDGE freopen("C.in", "r", stdin); #endif for (int T = read(); T--; solve()); return0; }
#include<bits/stdc++.h> // #define int long long #define pb push_back using std::cin, std::cout, std::string; intread(int x = 0, int f = 0, char ch = getchar()) { while (ch < 48or57 < ch) f = ch == 45, ch = getchar(); while(48 <= ch and ch <= 57) x = x * 10 + ch - 48, ch = getchar(); return f ? -x : x; } constint N = 1e6 + 5; constint INF = 1 << 30; // const long long INF = 1LL << 60; int a[N]; structNode { int bit, cnt0; boolfriendoperator < (Node a, Node b) { return a.cnt0 < b.cnt0; } }; intcountbit(int x) { int res = 0; while (x > 0) x /= 10, res++; return res; } intcount0(int x) { int res = 0; while (x > 0and x % 10 == 0) x /= 10, res++; return res; } voidsolve() { int n = read(), m = read(); for (int i = 1; i <= n; i++) a[i] = read(); std::priority_queue<Node> Q; int T = 0, ans = 0; for (int i = 1; i <= n; i++) Q.push(Node{countbit(a[i]), count0(a[i])}); for (int i = 1; i <= n - 1; i++) { int x = Q.top().bit, y = Q.top().cnt0; Q.pop(); int k = Q.top().bit; Q.pop(); Q.push(Node{k + x - y, 0}); } ans = Q.top().bit; if (n == 1) ans -= Q.top().cnt0; puts(ans > m ? "Sasha" : "Anna"); }
signedmain() { #ifndef ONLINE_JUDGE freopen("E.in", "r", stdin); #endif for (int T = read(); T--; solve()); return0; }
#include<bits/stdc++.h> // #define int long long #define pb push_back using std::cin, std::cout, std::string; intread(int x = 0, int f = 0, char ch = getchar()) { while (ch < 48or57 < ch) f = ch == 45, ch = getchar(); while(48 <= ch and ch <= 57) x = x * 10 + ch - 48, ch = getchar(); return f ? -x : x; } constint N = 2e5 + 5; constint INF = 1 << 30; int n, m, a[N], ind[N]; std::vector<int> g[N]; booltoposort() { int cnt = 0; std::queue<int> Q; for (int i = 1; i <= n; i++) if (!ind[i]) Q.push(i); for (int u; !Q.empty(); ) { u = Q.front(), Q.pop(), cnt++; for (auto v : g[u]) if (!--ind[v]) Q.push(v); } return cnt == n; } voidsolve() { n = read(), m = read(); for (int i = 1; i <= n; i++) g[i].clear(), ind[i] = 0; while(m--) { for (int i = 1; i <= n; i++) a[i] = read(); for (int i = 2; i < n; i++) g[a[i]].pb(a[i + 1]), ind[a[i + 1]]++; } puts(toposort() ? "YES" : "NO"); }
signedmain() { #ifndef ONLINE_JUDGE freopen("F.in", "r", stdin); #endif for (int T = read(); T--; solve()); return0; }