malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 500;   int n, s, deg[N], cnt;   int main() {     scanf( %d%d , &n, &s);     for (int i = 1; i < n; i++) {       int x, y;       scanf( %d%d , &x, &y);       deg[x]++;       deg[y]++;     }     for (int i = 1; i <= n; i++)       if (deg[i] == 1) cnt++;     if (n == 2)       printf( %.10lf n , (double)s);     else       printf( %.10lf n , (double)(2 * s) / (double)cnt);   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 50;   const int magic = 2500;   struct Node {     int from, to, delta, add;     Node(int from, int to, int delta, int add)         : from(from), to(to), delta(delta), add(add) {}   };   int n, a[maxn], c[maxn], q[maxn], id[maxn], b[maxn], ans[maxn], Q;   vector<Node> All;   void BuildInterval() {     for (auto&& x : All)       for (int i = x.from; i <= x.to; ++i)         b[id[i]] -= x.delta, ans[id[i]] += x.add;     for (int i = 1; i <= Q; ++i) id[i] = i;     sort(id + 1, id + Q + 1,          [&](const int& x, const int& y) { return b[x] < b[y]; });     All.clear();     All.push_back(Node(1, Q, 0, 0));   }   int main(int argc, char* argv[]) {     scanf( %d , &n);     for (int i = 1; i <= n; ++i) scanf( %d%d , c + i, q + i), id[i] = i;     sort(id + 1, id + n + 1, [&](const int& x, const int& y) {       return q[x] > q[y] || (q[x] == q[y] && c[x] < c[y]);     });     for (int i = 1; i <= n; ++i) a[i] = c[id[i]];     scanf( %d , &Q);     for (int i = 1; i <= Q; ++i) scanf( %d , b + i);     BuildInterval();     for (int i = 1; i <= n; ++i) {       for (int j = 0, limit = All.size(); j < limit; ++j) {         if (All[j].from > All[j].to) continue;         if (b[id[All[j].from]] - All[j].delta >= a[i])           All[j].delta += a[i], ++All[j].add;         else if (b[id[All[j].to]] - All[j].delta >= a[i]) {           int l = All[j].from + 1, r = All[j].to;           while (l < r) {             int mid = l + r >> 1;             if (b[id[mid]] - All[j].delta >= a[i])               r = mid;             else               l = mid + 1;           }           All.push_back(Node(l, All[j].to, All[j].delta + a[i], All[j].add + 1));           All[j].to = l - 1;         }       }       if (All.size() > magic || i == n) BuildInterval();     }     for (int i = 1; i <= Q; ++i) printf( %d  , ans[i]);     puts(  );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f, N = 3.1e5;   int n, m, dis[N], fm[N];   vector<int> vec[N];   void bfs() {     memset(dis, 0x3f, sizeof(dis));     queue<int> q;     q.push(1);     dis[1] = 0;     while (!q.empty()) {       int u = q.front();       q.pop();       for (int v : vec[u])         if (dis[v] == INF) dis[v] = dis[u] + 1, fm[v] = u, q.push(v);     }   }   int x[N], y[N], fa[N], sz[N], d[N];   bool vis[N];   int find(int u) { return u == fa[u] ? u : fa[u] = find(fa[u]); }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> n >> m;     for (int i = 1; i <= m; i++)       cin >> x[i] >> y[i], vec[x[i]].push_back(y[i]), vec[y[i]].push_back(x[i]);     bfs();     stack<int> s;     if (dis[n] <= 4)       for (int i = n; i; i = fm[i]) s.push(i);     else {       bool ok = 0;       for (int i = 1; i <= n; i++)         if (dis[i] == 2) {           s.push(n);           s.push(1);           s.push(i);           s.push(fm[i]);           s.push(1);           ok = 1;           break;         }       if (!ok) {         for (int i = 1; i <= n; i++) fa[i] = i, sz[i] = 1;         for (int i = 1; i <= m; i++)           if (x[i] != 1 && y[i] != 1 && dis[x[i]] == 1 && dis[y[i]] == 1) {             int u = x[i], v = y[i];             d[u]++, d[v]++;             int fv = find(v), fu = find(u);             if (fu == fv) continue;             fa[fv] = fu, sz[fu] += sz[fv];           }         for (int i = 1; i <= n; i++)           if (dis[i] == 1 && d[i] != sz[find(i)] - 1) {             for (int v : vec[i])               if (v != 1) vis[v] = 1;             for (int v : vec[i])               if (v != 1) {                 bool Get = 0;                 for (int vv : vec[v])                   if (vv != 1 && vv != i && !vis[vv]) {                     s.push(n);                     s.push(i);                     s.push(vv);                     s.push(v);                     s.push(i);                     s.push(1);                     Get = 1;                     break;                   }                 if (Get) break;               }             break;           }       }     }     cout << int(s.size() - 1) << endl;     while (!s.empty()) cout << s.top() <<    , s.pop();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t-- > 0) {       int n, m;       cin >> n;       int a[n];       for (int i = 0; i < n; i++) {         cin >> a[i];       }       int i = 0, t = 0, f = 0;       while (i < n - 1) {         if (a[0] != 1) {           f = 1;           cout <<  First n ;           break;         } else if (a[0] == 1) {           while (i < n - 1 && a[i] == 1) {             t++;             i++;           }           break;         }         i++;       }       if (t % 2 == 0 && f == 0) {         cout <<  First n ;       } else if (t % 2 == 1 && f == 0) {         cout <<  Second n ;       }     }     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   #pragma GCC target( popcnt )   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n;     cin >> n;     vector<pair<char, int>> arr;     for (int i = 0; i < 2 * n; i++) {       char sym;       cin >> sym;       int tmp;       if (sym ==  + ) {         tmp = 1;       } else {         cin >> tmp;       }       arr.emplace_back(sym, tmp);     }     reverse(arr.begin(), arr.end());     stack<int> mys;     string s =  YES ;     vector<int> ans;     for (int i = 0; i < int(arr.size()); i++) {       char sym;       int x;       tie(sym, x) = arr[i];       if (sym ==  + ) {         if (mys.empty()) {           s =  NO ;           break;         }         ans.push_back(mys.top());         mys.pop();       } else {         if (!mys.empty() && mys.top() < x) {           s =  NO ;           break;         }         mys.push(x);       }     }     cout << s <<   n ;     if (s ==  YES ) {       reverse(ans.begin(), ans.end());       for (auto ele : ans) {         cout << ele <<    ;       }     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int q;     cin >> q;     int l[500], r[500], d[500], ans[500];     for (int i = 0; i < q; i++) {       cin >> l[i] >> r[i] >> d[i];       int quo;       if (d[i] < l[i]) {         ans[i] = d[i];       } else {         quo = int(r[i] / d[i]);         ans[i] = d[i] * (quo + 1);       }     }     for (int i = 0; i < q; i++) {       cout << ans[i] << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n, v[100010], c[100010], l[100010], r, mx = 0;   map<long long, long long> dp, path, acp;   vector<long long> ans, vt[3 * 100010];   void getdp(long long x) {     long long i, ss;     dp.clear();     path.clear();     acp.clear();     for (i = 0; i < vt[x].size(); i++) {       dp[l[vt[x][i]]] = dp[l[vt[x][i]] + c[vt[x][i]]] = -1000000000000000000;       path[l[vt[x][i]]] = path[l[vt[x][i]] + c[vt[x][i]]] = -1;       acp[vt[x][i]] = -1;     }     dp[0] = 0;     for (ss = 0; ss < vt[x].size(); ss++) {       i = vt[x][ss];       if (l[i] == 0) {         if (v[i] > dp[l[i] + c[i]] || path[l[i] + c[i]] == -1) {           dp[l[i] + c[i]] = v[i];           path[l[i] + c[i]] = i;           acp[i] = -1;         }       } else {         if (path[l[i]] == -1) {           continue;         }         if (dp[l[i]] + v[i] > dp[l[i] + c[i]] || path[l[i] + c[i]] == -1) {           dp[l[i] + c[i]] = dp[l[i]] + v[i];           path[l[i] + c[i]] = i;           acp[i] = path[l[i]];         }       }     }     i = path[x];     if (dp[x] > mx) {       mx = dp[x];       ans.clear();       while (i != -1) {         ans.push_back(i);         i = acp[i];       }     }     return;   }   int main() {     long long i, j, mx = 0;     scanf( %lld , &n);     for (i = 0; i < n; i++) {       scanf( %lld%lld%lld%lld , &v[i], &c[i], &l[i], &r);       vt[c[i] + l[i] + r].push_back(i);     }     for (i = 0; i <= 300000; i++) {       if (vt[i].empty()) {         continue;       }       getdp(i);     }     sort(ans.begin(), ans.end());     printf( %lld n , (long long)ans.size());     for (i = 0; i < ans.size(); i++) {       printf( %lld  , ans[i] + 1);     }     puts(  );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 300005, M = 25;   const long long p = 998244353ll;   inline long long expo(long long a, int b = 998244351) {     long long c = 1ll;     while (b) {       if (b & 1) c = c * a % p;       b >>= 1;       a = a * a % p;     }     return c;   }   long long FAC[N], IFA[N];   inline long long comb(int a, int b) {     return (b < 0 || b > a) ? 0ll : (FAC[a] * (IFA[b] * IFA[a - b] % p) % p);   }   vector<int> L[N], R[N];   int I[N], C[M << 1];   long long E[M], ss;   inline void dfs(int m, long long a, int w = 1) {     if (m) {       dfs(m - 1, a, w);       if ((ss & E[m]) == E[m]) dfs(m - 1, a & (~E[m]), -w);     } else {       C[__builtin_popcountll(a)] += w;     }   }   int main() {     int n, m, i, a, b, c = 0, f = 0, c0 = 0, c1 = 0;     long long ans = 0ll, s1 = 0ll;     vector<int>::iterator d;     scanf( %d%d , &n, &m);     FAC[0] = 1ll;     for (i = (1); i <= (n); ++i) FAC[i] = FAC[i - 1] * i % p;     IFA[n] = expo(FAC[n]);     for (i = (n); i >= (1); --i) IFA[i - 1] = IFA[i] * i % p;     for (i = (1); i <= (n); ++i) {       scanf( %d%d , &a, &b);       L[a].push_back(i);       R[b].push_back(i);     }     for (i = (1); i <= (m); ++i) {       scanf( %d%d , &a, &b);       if (!I[a]) I[a] = ++c;       if (!I[b]) I[b] = ++c;       E[i] = (1ll << I[a]) | (1ll << I[b]);     }     C[0] = 1;     for (i = (1); i <= (n); ++i) {       for (d = L[i].begin(); d != L[i].end(); ++d) {         a = *d;         if (I[a]) {           ++c1;           f = 1;           s1 |= 1ll << I[a];         }         ++c0;       }       if (f) {         for (a = (0); a <= (c1); ++a) C[a] = 0;         ss = s1;         dfs(m, s1);         f = 0;       }       for (a = (0); a <= (c1); ++a)         ans = (ans + (C[c1 - a] + p) * comb(c0 - a, i - a)) % p;       for (d = R[i].begin(); d != R[i].end(); ++d) {         a = *d;         if (I[a]) {           --c1;           f = 1;           s1 ^= 1ll << I[a];         }         --c0;       }     }     printf( %lld , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void ga(int N, int *A) {     for (int i(0); i < N; i++) cin >> A[i];   }   int main(void) {     ios_base::sync_with_stdio(false);     string num;     getline(cin, num);     int ln = num.length();     int b = 0;     int st = 0;     int en = ln;     bool dot = 0;     for (char e : num) {       dot = dot or (e ==  . );     }     for (int i(0); i < ln; i++) {       if (num[i] !=  0 ) {         st = i;         break;       }     }     for (int i = ln - 1; i > 0; i--) {       if (num[i] !=  0 ) {         en = i + 1;         break;       }     };     ;     if (num[st] ==  . ) {       b--;       for (int i(st + 1); i < ln; i++) {         if (num[i] !=  0 ) {           st = i;           break;         }         b--;       }       cout << num[st] << (en - st - 1 == 0 ?    :  . )            << num.substr(st + 1, en - st - 1) <<  E  << b << endl;       return 0;     } else {       b--;       for (int i(st); i < ln; i++) {         if (num[i] ==  . ) {           en--;           num.erase(i, 1);           break;         }         b++;       };       for (int i = en - 1; i >= 0; i--) {         if (num[i] !=  0 ) {           ;           en = i + 1;           break;         }       }       cout << num[st] << (en - st - 1 == 0 ?    :  . )            << num.substr(st + 1, en - st - 1)            << (b == 0 ?    :  E  + to_string(b)) << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m;   int a[1000005];   inline int Pow_Log(int x, int p) {     int sol = 1;     while (p) {       if (p & 1) {         sol = (1LL * sol * x) % 1000000009;         --p;       }       p >>= 1;       x = (1LL * x * x) % 1000000009;     }     return sol;   }   int main() {     int i, j, sol = 1, x;     cin.sync_with_stdio(0);     cin >> n >> m;     x = Pow_Log(2, m);     for (i = 1; i <= n; ++i) {       --x;       if (x < 0) x += 1000000009;       sol = (1LL * sol * x) % 1000000009;     }     cout << sol;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int n, m, a, b, c, d, k, x, y, z, ans = 0, total = 0;   long long int arr[201000] = {0};   int main(void) {     cin >> n >> m;     for (int i = 0; i < n; i++) cin >> arr[i];     sort(arr, arr + n);     a = (n / 2);     ans += abs(arr[a] - m);     for (int i = a + 1; i < n; i++) {       if (arr[i] < m) {         ans += abs(arr[i] - m);       } else {         break;       }     }     for (int i = a - 1; i >= 0; i--) {       if (arr[i] > m) {         ans += abs(arr[i] - m);       } else {         break;       }     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   string file[10005];   unordered_map<string, pair<int, int> > ss;   unordered_map<string, bool> sk;   void deal(const string &in, int loc) {     sk.clear();     int len = in.size();     string temp;     for (int i = 1; i <= len; ++i) {       for (int j = 0; j <= len - i; ++j) {         temp.clear();         for (int k = j; k < i + j; ++k) {           temp.push_back(in[k]);         }         auto &flag = sk[temp];         if (flag)           continue;         else {           flag = true;           auto it = ss.find(temp);           if (it == ss.end()) {             ss.emplace(make_pair(temp, make_pair(loc, 1)));           } else             ++it->second.second;         }       }     }   }   string quest;   int main() {     int n, m;     ios::sync_with_stdio(false);     cin >> n;     for (int i = 0; i < n; ++i) {       cin >> file[i];       deal(file[i], i);     }     cin >> m;     while (m--) {       cin >> quest;       auto it = ss.find(quest);       if (it != ss.end()) {         cout << it->second.second <<     << file[it->second.first] <<   n ;       } else {         cout <<  0 - n ;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n, a[100069];   int main() {     long long t, rr, i;     bool bad;     scanf( %lld , &t);     for (rr = 0; rr < t; rr++) {       scanf( %lld , &n);       for (i = 1; i <= n * 4; i++) {         scanf( %lld , a + i);       }       sort(a + 1, a + n * 4 + 1);       bad = 0;       for (i = 1; i <= n * 4; i += 2) {         if (a[i] != a[i + 1]) {           bad = 1;           break;         }       }       for (i = 3; i <= n * 2; i += 2) {         if (a[i] * a[n * 4 + 1 - i] != a[1] * a[n * 4]) {           bad = 1;           break;         }       }       if (bad) {         printf( NO n );       } else {         printf( YES n );       }     }   }
#include <bits/stdc++.h>   using namespace std;   int n, m, len, kmpA[100010], ans, kmpB[100010], mxA[100010], mxB[100010];   char S[100010], A[100010], B[100010];   int main() {     scanf( %s , S + 1);     n = strlen(S + 1);     scanf( %d , &m);     while (m--) {       scanf( %s , A);       kmpA[0] = -1;       len = strlen(A);       if (len == 1) continue;       for (int i = 1, k = -1; i <= len; i++) {         while (k != -1 && A[i - 1] != A[k]) k = kmpA[k];         k++;         kmpA[i] = k;       }       for (int i = 0; i <= len - 1; i++) B[len - 1 - i] = A[i];       kmpB[0] = -1;       for (int i = 1, k = -1; i <= len; i++) {         while (k != -1 && B[i - 1] != B[k]) k = kmpB[k];         k++;         kmpB[i] = k;       }       for (int i = 1, k = 0; i <= n; i++) {         while (k != -1 && S[i] != A[k]) k = kmpA[k];         k++;         mxA[i] = k;       }       for (int i = n, k = 0; i >= 1; i--) {         while (k != -1 && S[i] != B[k]) k = kmpB[k];         k++;         mxB[i] = k;       }       for (int i = 1; i <= n; i++) mxA[i] = max(mxA[i - 1], mxA[i]);       for (int i = n; i >= 1; i--) mxB[i] = max(mxB[i + 1], mxB[i]);       bool flag = false;       for (int i = 1; i <= n + 1; i++) {         if (mxA[i - 1] + mxB[i] >= len) {           flag = true;           break;         }       }       ans += flag;     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bitset<1005> tt[30];   unordered_map<bitset<1005>, int> ff;   pair<bitset<1005>, int> ar[1000005];   int bc[1000005];   void print(bitset<1005> t) {     for (int i = 0; i < 12; ++i) {       if (t[i]) {         putchar( 1 );       } else {         putchar( 0 );       }     }     putchar(  n );   }   int construct(int l, int r, bool isG) {     bitset<1005> tmp;     ar[0] = {tmp, 0};     int cc = 1;     for (int i = l; i <= r; ++i) {       int ind = i;       if (isG) {         ind -= l;       }       int tcc = cc;       for (int j = 0; j < cc; ++j) {         ar[tcc++] = {ar[j].first ^ tt[i], (1 << ind) + ar[j].second};       }       cc = tcc;     }     if (!isG) {       for (int i = 0; i < cc; ++i) {         if (!ff.count(ar[i].first)) {           ff[ar[i].first] = bc[ar[i].second];         } else {           ff[ar[i].first] = min(ff[ar[i].first], bc[ar[i].second]);         }       }     }     return cc;   }   void solve() {     int n, s, d;     scanf( %d %d %d  , &n, &s, &d);     for (int i = 0; i < s; ++i) {       int x;       scanf( %d  , &x);       while (x--) {         int t;         scanf( %d  , &t);         tt[i][t - 1] = 1;       }     }     bc[0] = 0;     for (int i = 1; i < 1000005; ++i) {       bc[i] = bc[i / 2] + (i & 1);     }     int g = min(s - 1, 18);     construct(0, g, 0);     int sz = construct(g + 1, s - 1, 1);     while (d--) {       bitset<1005> tmp;       int x;       scanf( %d  , &x);       while (x--) {         int t;         scanf( %d  , &t);         tmp[t - 1] = 1;       }       const int inf = 1e9;       int ret = inf;       for (int i = 0; i < sz; ++i) {         if (ff.count(tmp ^ ar[i].first)) {           ret = min(ret, bc[ar[i].second] + ff[tmp ^ ar[i].first]);         }       }       if (ret == inf) {         ret = -1;       }       printf( %d n , ret);     }   }   int main() {     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());   const int INF = 2e9;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n, p;     cin >> n >> p;     vector<int> a(n);     for (int i = 0; i < (int)(n); i++) cin >> a[i];     sort((a).begin(), (a).end());     int l = -INF, r = INF;     for (int i = 0; i < (int)(n); i++) {       l = max(l, a[i] - i);       if (p - 1 <= i) r = min(r, a[i] - i + (p - 1));     }     vector<int> ans;     for (int i = l; i < r; i++) ans.push_back(i);     cout << ((int)(ans).size()) << endl;     for (auto x : ans) cout << x <<    ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int getReverted(int num) {     bool bin[8] = {0};     for (int j = 0; num != 0; j++) {       bin[j] = num % 2;       num /= 2;     }     for (int j = 0; j < 8; j++) {       num += (int)bin[j] * pow(2, 7 - j);     }     return num;   }   int strSize(char *str) {     int i;     for (i = 0; str[i] !=   0 ; i++)       ;     return i;   }   int main() {     char str[101];     int last = 0, result, size, reverted;     scanf(  %[^ n]s , str);     size = strSize(str);     for (int i = 0; str[i] !=   0 ; i++) {       reverted = getReverted(str[i]);       result = (last - reverted) % 256;       if (result < 0)         while (result < 0) result += 256;       cout << result;       if (i != size - 1) cout << endl;       last = getReverted(str[i]);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   string getmin(string prev, string cur) {     if (prev.length() < cur.length()) {       for (int i = 0; i < cur.length(); i++) {         if (cur[i] ==  ? ) cur[i] = (i == 0) ?  1  :  0 ;       }       return cur;     }     if (prev.length() > cur.length()) return   ;     int fmsm = 100;     for (int i = 0; i < cur.length(); i++) {       if (cur[i] ==  ? ) continue;       if (cur[i] != prev[i]) {         fmsm = i;         break;       }     }     int nm = 0;     for (int i = 0; i < cur.length(); i++) {       if (i == fmsm) {         if (cur[i] < prev[i]) nm++;       }       if (cur[i] ==  ? ) {         if (i < fmsm)           nm = nm * 10 + prev[i] -  0 ;         else {           nm *= 10;         }       }     }     if (fmsm == 100) nm++;     for (int i = cur.length() - 1; i >= 0; i--) {       if (cur[i] ==  ? ) {         cur[i] =  0  + nm % 10;         nm /= 10;       }     }     if (nm) return   ;     return cur;   }   int main() {     int n;     scanf( %d , &n);     string cur =   ;     vector<string> nums;     for (int i = 0; i < n; i++) {       char ch[32];       scanf(  %s , ch);       string chs(ch);       string x = getmin(cur, chs);       if (x.empty()) {         printf( NO n );         return 0;       }       nums.push_back(x);       cur = x;     }     printf( YES n );     for (int i = 0; i < n; i++) printf( %s n , nums[i].c_str());     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     int t, ang;     cin >> t;     while (t--) {       cin >> ang;       int ans = -1;       for (int i = 3; i <= 360; ++i) {         int k = ang * i / 180;         if ((ang * i) % 180 == 0 && 360 % i == 0 && 1 <= k && k <= i - 2) {           ans = i;           break;         }       }       cout << ans << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e3 + 1;   char a[N], b[N];   vector<int> g[26];   bool vis[26][26];   vector<pair<char, char> > sol;   char go[26];   int main() {     scanf( %s%s , a, b);     int n = strlen(a);     for (int i = 0; i < n; ++i) {       if (a[i] == b[i]) continue;       int x = a[i] -  a ;       int y = b[i] -  a ;       g[x].push_back(y);       g[y].push_back(x);     }     bool can = true;     for (int i = 0; i < 26 && can; ++i) {       sort(g[i].begin(), g[i].end());       g[i].resize(unique(g[i].begin(), g[i].end()) - g[i].begin());       can &= g[i].size() <= 1;     }     if (!can) {       puts( -1 );       return 0;     }     for (int i = 0; i < 26; ++i)       if (!g[i].empty()) {         int x = min(i, g[i][0]), y = max(i, g[i][0]);         if (vis[x][y]) continue;         go[x] = y +  a ;         go[y] = x +  a ;         vis[x][y] = true;         sol.push_back(make_pair(x +  a , y +  a ));       } else         go[i] = i +  a ;     for (int i = 0; i < 26 && can; ++i) {       can &= go[a[i] -  a ] == b[i];       can &= go[b[i] -  a ] == a[i];     }     if (!can) {       puts( -1 );       return 0;     }     printf( %d n , (int)sol.size());     for (int i = 0; i < (int)sol.size(); ++i)       printf( %c %c n , sol[i].first, sol[i].second);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void solve() {     int n, k;     cin >> n >> k;     long long a[n * k];     for (int i = 0; i < n * k; i++) {       cin >> a[i];     }     long long sum = 0;     int jump = ((n + 1) / 2);     if (n % 2 == 0) jump++;     int count = 0;     for (int i = n * k - jump; count < k; i -= jump) {       sum += a[i];       count++;     }     cout << sum << endl;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t;     cin >> t;     while (t--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     string input, temp;     bool f1, f2;     cin >> n;     getline(cin, input);     for (int i = 0; i < n; i++) {       f1 = false;       f2 = false;       getline(cin, input);       if (input.length() > 4) {         temp = input.substr(0, 5);         if (temp ==  miao. ) f2 = true;         temp = input.substr(input.length() - 5, 5);         if (temp ==  lala. ) f1 = true;       }       if (f1 && !f2)         cout <<  Freda s  << endl;       else if (f2 && !f1)         cout <<  Rainbow s  << endl;       else         cout <<  OMG>.< I don t know!  << endl;     }     return 0;   }