malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int arr[11];   string str[11];   int m, n;   int f(int k) {     if (k == n) {       for (int i = 0; i < m; i++)         if (arr[i] != 0) return 0;       return 1;     }     int ans = 0;     bool c = 0;     for (int i = 0; i < m; i++)       if (str[i][k] ==  0 ) {         arr[i]--;         if (arr[i] < 0) c++;       }     if (c == 0) ans += f(k + 1);     for (int i = 0; i < m; i++)       if (str[i][k] ==  0 ) arr[i]++;     c = 0;     for (int i = 0; i < m; i++)       if (str[i][k] ==  1 ) {         arr[i]--;         if (arr[i] < 0) c++;       }     if (!c) ans += f(k + 1);     for (int i = 0; i < m; i++)       if (str[i][k] ==  1 ) arr[i]++;     return ans;   }   int main() {     cin >> n >> m;     for (int i = 0; i < m; i++) cin >> str[i] >> arr[i];     cout << f(0) << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n, m, k;       cin >> n >> m >> k;       vector<int> val(n);       for (int i = 0; i < n; i++) {         cin >> val[i];       }       if (m == 1) {         cout << max(val[0], val[n - 1]) << endl;         continue;       }       if (k >= m - 1) {         vector<int> vec;         for (int i = 0; i < m; i++) {           vec.push_back(val[i]);           vec.push_back(val[n - i - 1]);         }         cout << *max_element(vec.begin(), vec.end()) << endl;         continue;       }       int res_glob = 0;       for (int i = 0; i <= k; i++) {         int ind_l = i;         int ind_r = n - 1 - (k - i);         int need = m - k - 1;         int cur_res = 2000000000;         for (int j = 0; j <= need; j++) {           int cur_elem = ind_l + j;           int cur_elem_left = ind_r - (need - j);           cur_res = min(cur_res, max(val[cur_elem], val[cur_elem_left]));         }         res_glob = max(res_glob, cur_res);       }       cout << res_glob << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int a[500005];   int main() {     int n, b, i, ma = 0, ju, cnt, le, st, j;     scanf( %d , &n);     int hahaha = 1;     for (i = 0; i < n; i++) {       scanf( %d , &a[i]);     }     le = 1;     ju = a[0];     for (i = 1; i < n; i++) {       if (a[i] != ju)         le++;       else {         ma = max(ma, le);         st = i - le + 1;         cnt = 0;         if (le >= 3) {           if (le % 2 == 0) {             le = (le - 2) / 2;             for (j = st; j < i - 1; j++) {               if (cnt < le) {                 a[j] = a[st - 1];               } else {                 a[j] = a[i];               }               cnt++;             }           } else {             for (j = st; j < i - 1; j++) {               a[j] = a[st - 1];             }           }         }         le = 1;       }       ju = a[i];     }     ma = max(ma, le);     st = i - le + 1;     cnt = 0;     if (le >= 3) {       if (le % 2 == 0) {         le = (le - 2) / 2;         for (j = st; j < i - 1; j++) {           if (cnt < le) {             a[j] = a[st - 1];           } else {             a[j] = a[i - 1];           }           cnt++;         }       } else {         for (j = st; j < i - 1; j++) {           a[j] = a[st - 1];         }       }     }     le = (ma - 1) / 2;     printf( %d n , le);     for (i = 0; i < n; i++) {       printf( %d  , a[i]);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const int mod = 1e9 + 7;   const int maxn = 1e6 + 10;   int n, k, cnt[maxn], a[maxn], L[maxn], R[maxn];   stack<pair<int, int> > stk;   int main() {     scanf( %d , &n);     ;     scanf( %d , &k);     ;     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     ;     stk.push({INF, 0});     for (int i = 1; i <= n; i++) {       while (stk.top().first < a[i]) stk.pop();       L[i] = stk.top().second + 1;       stk.push({a[i], i});     }     while (stk.size()) stk.pop();     stk.push({INF, n + 1});     for (int i = n; i >= 1; i--) {       while (stk.top().first <= a[i]) stk.pop();       R[i] = stk.top().second - 1;       stk.push({a[i], i});     }     for (int i = 1; i <= n; i++) {       cnt[i] = (cnt[i - 1] + (i - 1) / (k - 1)) % mod;     }     long long ans = 0;     for (int i = 1; i <= n; i++) {       int t = (cnt[R[i] - L[i] + 1] - cnt[i - L[i]] - cnt[R[i] - i]) % mod;       ans += 1LL * t * a[i] % mod;     }     printf( %I64d n , (ans % mod + mod) % mod);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int p[50001], n, l, r;   queue<int> ver[50001];   void go(int pre, int v) {     int t;     p[v] = pre;     if (v != l) {       while (!ver[v].empty()) {         t = ver[v].front();         ver[v].pop();         if (t != pre) go(v, t);       }     }   }   int main() {     scanf( %d%d%d , &n, &l, &r);     l--;     r--;     for (int i = 0; i < n; i++)       if (i == l)         continue;       else {         scanf( %d , &p[i]);         p[i]--;         ver[p[i]].push(i);         ver[i].push(p[i]);       }     go(-1, r);     for (int i = 0; i < n; i++)       if (i == r)         continue;       else         printf( %d  , p[i] + 1);     return 0;   }
#include <bits/stdc++.h>   long long gcd(long long x, long long y) {     if (x > y) std::swap(x, y);     return y % x == 0 ? x : gcd(y % x, x);   }   using namespace std;   int main() {     int n;     scanf( %d , &n);     int a[20];     bool flag = true;     for (int i = (1); i <= (n); i++) scanf( %d , a + i);     for (int i = (1); i <= (n - 1); i++)       if (abs(a[i] - a[i + 1]) >= 2) flag = false;     if (flag)       puts( YES );     else       puts( NO );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 3e5 + 50;   int n, cnt, f[N][18], d[N], fa[N], id[N], s[N];   vector<int> v1[N], v2[N];   void dfs1(int x, int ff) {     for (int i = 0; i < 17; i++) f[x][i + 1] = f[f[x][i]][i];     for (int i = 0, y; i < v1[x].size(); i++)       if ((y = v1[x][i]) != ff)         f[y = v1[x][i]][0] = x, d[y] = d[x] + 1, dfs1(y, x);   }   int find(int x) { return fa[x] == x ? x : fa[x] = find(fa[x]); }   void merge(int x, int y) {     x = find(x);     y = find(y);     if (s[x] > s[y]) swap(x, y);     fa[x] = y;     s[y] += s[x];     id[y] = d[id[y]] < d[id[x]] ? id[y] : id[x];   }   void dfs2(int x, int ff) {     for (int i = 0, y; i < v2[x].size(); i++)       if ((y = v2[x][i]) != ff) dfs2(y, x);     if (!ff) return;     int fx = id[find(x)], p = ff;     for (int i = 17; ~i; i--)       if (d[id[find(f[p][i])]] > d[fx]) p = f[p][i];     if (id[find(f[p][0])] != fx) p = fx;     merge(p, f[p][0]);     printf( %d %d %d %d n , p, f[p][0], x, ff);   }   int main() {     scanf( %d , &n);     for (int i = 1, x, y; i < n; i++)       scanf( %d%d , &x, &y), v1[x].push_back(y), v1[y].push_back(x);     for (int i = 1, x, y; i < n; i++)       scanf( %d%d , &x, &y), v2[x].push_back(y), v2[y].push_back(x);     printf( %d n , n - 1);     for (int i = 1; i <= n; i++) id[i] = fa[i] = i, s[i] = 1;     dfs1(d[1] = 1, 0);     dfs2(1, 0);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string a, b;     int n, m;     cin >> n >> m;     cin >> a >> b;     int pw = 1;     int ans = 0, res = 0;     for (int i = 0; i < m; i++) {       if (i < n && a[n - i - 1] ==  1 ) res = (res + pw) % 998244353;       if (b[m - i - 1] ==  1 ) ans = (ans + res) % 998244353;       pw = (pw + pw) % 998244353;     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long a, b, ans, w1, w2;   int main() {     cin >> a >> b;     ans = 2 * a + 2 * b + 2;     w1 = 2 * a + 2 * b + 2;     w2 = 2 * a + 2 * b + 2;     for (long long i = 1; i <= sqrt(a + b); i++) {       if (a % i == 0 && a / i < w1) w1 = a / i;       if (b % i == 0 && b / i < w2) w2 = b / i;       if ((a + b) % i == 0) {         if (w1 <= (a + b) / i) {           if (2 * (i + (a + b) / i) < ans) ans = 2 * (i + (a + b) / i);         }         if (w2 <= (a + b) / i) {           if (2 * (i + (a + b) / i) < ans) ans = 2 * (i + (a + b) / i);         }       }     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 5e5 + 100;   int num[N];   bool vis[N];   vector<int> v;   int n, k;   int main() {     scanf( %d %d , &n, &k);     int mn = 1e9 + 1000;     for (int i = 1; i <= n; i++) {       scanf( %d , &num[i]);       if (num[i] < mn) {         mn = num[i];         vis[i] = true;         v.push_back(i);       }     }     v.push_back(n + 1);     num[n + 1] = 0;     int cnt = 0;     int mx = 0;     for (int i = 1; i < v.size(); i++) {       mx = max(mx, v[i] - v[i - 1]);       if (v[i] - v[i - 1] > k) cnt++;     }     if (cnt >= 2) {       puts( NO );     } else if (cnt == 0) {       puts( YES );     } else {       int tmp = -1;       for (int i = 1; i < v.size(); i++) {         if (v[i] - v[i - 1] > k) tmp = i;       }       bool ans = false;       if (tmp != v.size() - 1 && v[tmp + 1] - v[tmp - 1] <= 2 * k) ans = true;       if (tmp == 0 && v[1] <= 2 * k) tmp = true;       for (int i = v[tmp] + 1; i <= n; i++) {         if (vis[i]) continue;         if (num[i] < num[v[tmp - 1]] && num[i] > num[v[tmp]]) ans = true;       }       if (ans)         puts( YES );       else         puts( NO );     }     return 0;   }
#include <iostream>      int main(void) {    int count;    std::cin >> count;    for (int i = 0; i < count; ++i) {     int number;     std::cin >> number;     int64_t sum = 0;     for (int j = 0; j < number; ++j) {      int part;      std::cin >> part;      sum += part;     }     std::cout << (sum % number) * (number - sum % number) <<   n ;    }    return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ii = pair<int, int>;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int n;     cin >> n;     vector<int> v(n);     for (auto &i : v) cin >> i;     int q;     cin >> q;     vector<int> idx(n, 0);     vector<int> ops(q, 0);     for (int i = 0; i < q; ++i) {       int op;       cin >> op;       if (op == 1) {         int p, x;         cin >> p >> x;         v[p - 1] = x;         idx[p - 1] = i;       } else {         int x;         cin >> x;         ops[i] = x;       }     }     for (int i = q - 2; i >= 0; --i) ops[i] = max(ops[i], ops[i + 1]);     for (int i = 0; i < n; ++i) {       v[i] = max(ops[idx[i]], v[i]);     }     for (int i = 0; i < n; ++i) cout << v[i] <<    ;     cout <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 200005;   int a[maxn];   int main() {     int n;     scanf( %d , &n);     for (int i = 0; i < n * 2; i++) scanf( %d , &a[i]);     sort(a, a + n * 2);     long long area = 1ll * (a[n - 1] - a[0]) * (a[n * 2 - 1] - a[n]);     for (int i = 1; i < n; i++) {       area = min(area, 1ll * (a[i + n - 1] - a[i]) * (a[n * 2 - 1] - a[0]));     }     printf( %I64d , area);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, d;     scanf( %d %d , &n, &d);     int data[n + 10];     for (int i = 0; i < n; i++) scanf( %d , &data[i]);     long long ans = 0;     for (int i = 0; i < n - 1; i++) {       int h = upper_bound(data, data + n, data[i] + d) - data;       h--;       int l = i;       int n = (h - l) + 1;       if (n < 3) continue;       n -= 2;       ans += ((long long)(n) * (long long)(n + 1)) / 2;     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 123;   int n, t, label[N], times = 0;   vector<int> e[N];   vector<pair<int, int> > res;   void newLabel(int u) {     res.push_back(make_pair(u, times));     label[u] = times;   }   void dfs(int u, int backLabel = -1, int p = 0) {     newLabel(u);     int numchild = (int)e[u].size() - (u > 1);     for (int v : e[u]) {       if (v == p) continue;       if (label[u] >= t) {         times = backLabel - numchild;         newLabel(u);       }       times = label[u] + 1;       dfs(v, label[u], u);       if (label[v] > label[u]) {         times = label[u];         newLabel(v);       }       ++times;       newLabel(u);       --numchild;     }     if (u > 1 && label[u] > backLabel) {       times = backLabel;       newLabel(u);     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie();     cout.tie();     cin >> n;     for (int i = 1; i < n; ++i) {       int u, v;       cin >> u >> v;       e[u].push_back(v);       e[v].push_back(u);     }     t = -1;     for (int i = 1; i <= n; ++i) t = max(t, (int)e[i].size());     dfs(1);     cout << res.size() <<   n ;     for (pair<int, int> x : res) {       cout << x.first <<     << x.second <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct point {     double df, de;     void init(double _df, double _de) {       df = _df;       de = _de;     }   } V[100];   int nf, ne, ns, rf, re, rs, df, de;   int n, top, place[13];   double ans = 0, dp[21][21], lf, le, ls;   bool cmp(const point &a, const point &b) { return a.df > b.df; }   double cross(double l1, double r1, double l2, double r2) {     if (l2 >= r1 || l1 >= r2) return 0;     return min(r1, r2) - max(l1, l2);   }   void init_V() {     top = 0;     for (int i = 0; i < n; i++)       if (place[i] < 2) {         double t1 = lf * df, t2 = le * de;         for (int j = 0; j < n; j++)           if (place[j]) {             t1 += df * place[j] *                   cross(j - ls / 2, j + ls / 2, i - lf / 2, i + lf / 2);             t2 += de * place[j] *                   cross(j - ls / 2, j + ls / 2, i - le / 2, i + le / 2);           }         for (int j = 1; j + place[i] <= 2; j++) V[top++].init(t1, t2);       }     sort(V, V + top, cmp);   }   void init_dp() {     memset(dp, 0, sizeof(dp));     for (int i = 0; i <= nf; i++)       for (int j = 0; j <= ne; j++) {         if (i) dp[i][j] = max(dp[i][j], dp[i - 1][j] + V[i + j - 1].df);         if (j) dp[i][j] = max(dp[i][j], dp[i][j - 1] + V[i + j - 1].de);       }     ans = max(ans, dp[nf][ne]);   }   void dfs(int p, int left) {     if ((n - p) * 2 < left) return;     if (p == n) {       init_V();       init_dp();       return;     }     for (int i = 0; i <= 2 && left >= i; i++) {       place[p] = i;       dfs(p + 1, left - i);     }   }   int main() {     cin >> nf >> ne >> ns >> rf >> re >> rs >> df >> de;     n = (nf + ne + ns + 1) / 2;     lf = 2 * sqrt(rf * rf - 1.0);     le = 2 * sqrt(re * re - 1.0);     ls = 2 * sqrt(rs * rs - 1.0);     dfs(0, ns);     printf( %.10lf n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   struct rge {     T b, e;   };   template <class T>   rge<T> range(T i, T j) {     return rge<T>{i, j};   }   struct debug {     template <class T>     debug& operator<<(const T&) {       return *this;     }   };   using ll = long long;   template <typename T>   void min_self(T& a, T b) {     a = min(a, b);   }   template <typename T>   void max_self(T& a, T b) {     a = max(a, b);   }   const int mxN = 2500 * 1000 + 5;   int xs[mxN], N = 0;   const ll inf = 1e18;   class SegTree {    public:     struct Node {       ll mn = inf;       void merge(Node x, Node y) { mn = min(x.mn, y.mn); }     };     SegTree(int _n) : n(_n) {       tree.resize(4 * n);       lazy.resize(4 * n);     }     void build(int i, int L, int R) {       if (L == R) {         tree[i].mn = 0;       } else {         int m = L + (R - L) / 2;         build(2 * i, L, m);         build(2 * i + 1, m + 1, R);         tree[i].merge(tree[2 * i], tree[2 * i + 1]);       }     }     void push(int i) {       ll& v = lazy[i];       tree[2 * i].mn += v;       lazy[2 * i] += v;       tree[2 * i + 1].mn += v;       lazy[2 * i + 1] += v;       v = 0;     }     Node get(int i, int L, int R, int tl, int tr) {       if (tl > tr) return Node();       if (L == tl && tr == R) {         return tree[i];       } else {         push(i);         int m = L + (R - L) / 2;         Node ans;         ans.merge(get(2 * i, L, m, tl, min(tr, m)),                   get(2 * i + 1, m + 1, R, max(m + 1, tl), tr));         return ans;       }     }     ll get(int tl, int tr) {       Node ans = get(1, 1, n, tl, tr);       return ans.mn;     }     void upd(int i, int L, int R, int tl, int tr, int val) {       if (tl > tr) return;       if (L == tl && tr == R) {         tree[i].mn += val;         lazy[i] += val;       } else {         push(i);         int m = L + (R - L) / 2;         upd(2 * i, L, m, tl, min(tr, m), val);         upd(2 * i + 1, m + 1, R, max(m + 1, tl), tr, val);         tree[i].merge(tree[2 * i], tree[2 * i + 1]);       }     }     void upd(int tl, int tr, int val) { upd(1, 1, n, tl, tr, val); }       private:     int n;     vector<Node> tree;     vector<ll> lazy;   };   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int n;     cin >> n;     vector<pair<int, int>> tv;     for (int i = 0; i < n; i++) {       int a, b;       cin >> a >> b;       for (int x : {a - 1, a, a + 1, b - 1, b, b + 1}) {         xs[N++] = x;       }       tv.emplace_back(a, b);     }     sort(xs, xs + N);     N = unique(xs, xs + N) - xs;     SegTree st(N);     st.build(1, 1, N);     for (auto pp : tv) {       int L = pp.first, R = pp.second;       L = lower_bound(xs, xs + N, L) - xs;       R = lower_bound(xs, xs + N, R) - xs;       st.upd(L + 1, R + 1, 1);     }     int who = 1;     for (auto pp : tv) {       int L = pp.first, R = pp.second;       L = lower_bound(xs, xs + N, L) - xs;       R = lower_bound(xs, xs + N, R) - xs;       if (st.get(L + 1, R + 1) > 1) {         cout << who <<   n ;         exit(0);       }       who++;     }     cout <<  -1 n ;   }
#include <bits/stdc++.h>   using namespace std;   void solve() {     long long a, b;     cin >> a >> b;     if (b - a > 5) {       cout << 0 <<   n ;     } else {       long long val = 1;       for (long long j = a + 1; j <= b; j++) {         val *= (j % 10);         val %= 10;       }       cout << val <<   n ;     }   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     solve();   }
#include <bits/stdc++.h>   using namespace std;   struct Point {     int x;     int y;   };   struct Rect {     int left;     int top;     int right;     int bottom;   };   bool FindBoundary(const vector<Point> &pts, Rect *getRect) {     if (pts.empty()) {       return false;     }     auto it = pts.begin();     getRect->left = it->x;     getRect->right = it->x;     getRect->top = it->y;     getRect->bottom = it->y;     for (auto it = pts.begin(); it != pts.end(); ++it) {       if (getRect->left > it->x) {         getRect->left = it->x;       }       if (getRect->right < it->x) {         getRect->right = it->x;       }       if (getRect->top < it->y) {         getRect->top = it->y;       }       if (getRect->bottom > it->y) {         getRect->bottom = it->y;       }     }     return true;   }   bool IsSquare(const Rect *rect) {     return rect->right - rect->left == rect->top - rect->bottom;   }   bool CheckPoints(const vector<Point> &pts, const Rect *rect, int n) {     int left = 0, top = 0, right = 0, bottom = 0;     bool notAny = true;     for (auto it = pts.begin(); it != pts.end(); ++it) {       notAny = true;       if (it->x == rect->left) {         notAny = false;         ++left;       }       if (it->x == rect->right) {         notAny = false;         ++right;       }       if (it->y == rect->top) {         notAny = false;         ++top;       }       if (it->y == rect->bottom) {         notAny = false;         ++bottom;       }       if (notAny) {         return false;       }     }     if (left < n || right < n || top < n || bottom < n) {       return false;     }     return true;   }   int main(int argc, char *argv[]) {     int n = 0;     cin >> n;     int amount = 4 * n + 1;     vector<Point> points;     for (int i = 0; i < amount; ++i) {       Point pt;       cin >> pt.x >> pt.y;       points.push_back(pt);     }     bool found = false;     for (int i = 0; i < amount; ++i) {       vector<Point> sqPoints;       for (int j = 0; j < amount; ++j) {         if (j != i) {           sqPoints.push_back(points[j]);         }       }       Rect rect;       if (!FindBoundary(sqPoints, &rect)) {         continue;       }       if (!IsSquare(&rect)) {         continue;       }       if (!CheckPoints(sqPoints, &rect, n)) {         continue;       }       printf( %d %d , points[i].x, points[i].y);       break;     }     return 0;   }
#include<bits/stdc++.h>   using namespace std;   typedef long long ll;   //#define rep(i,a,b) for(int i=a;i<b;i++);   void solve(){    ll n;    cin>>n;    string s;    cin>>s;    vector<ll>v;    for(int i=0;i<n;i++){     if (s[i]== * ){      v.push_back(i);     }    }    if (v.size()<=1 or v.size()==n){     cout<<0<<endl;    }    else{    ll mid=v.size()/2;    ll ans=0;    for(int i=0;i<v.size();i++){     ans+=abs(v[i]-v[mid]);    }           if (v.size()%2==0){     ll t1=v.size()/2;     ll t2=v.size()/2-1;        ll d1=t1*(t1+1)/2;     ll d2=t2*(t2+1)/2;     ans-=(d1+d2);    }       else{     ll t1=v.size()/2;     ll d1=t1*(t1+1)/2;     ans-=(2*d1);    }       cout<<ans<<endl;   }   }   int main(){    int t=1;    cin>>t;    while(t--)    solve();   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int W, H, n;     scanf( %d%d%d , &W, &H, &n);     multiset<int> w, h;     w.insert(-W);     h.insert(-H);     set<int> wa, ha;     wa.insert(0);     wa.insert(W);     ha.insert(0);     ha.insert(H);     for (int i = 0; i < n; i++) {       char t;       int x;       scanf(  n%c%d , &t, &x);       if (t ==  H ) {         auto r = ha.lower_bound(x);         auto l = r;         l--;         h.erase(h.find((*l) - (*r)));         ha.insert(x);         h.insert((*l) - x);         h.insert(x - (*r));       } else if (t ==  V ) {         auto r = wa.lower_bound(x);         auto l = r;         l--;         w.erase(w.find((*l) - (*r)));         wa.insert(x);         w.insert((*l) - x);         w.insert(x - (*r));       }       printf( %lld n , 1ll * (*h.begin()) * (*w.begin()));     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long MAX = 1000009;   long long mod = 998244353;   long long n, kek[MAX];   vector<long long> child[MAX];   long long bin(long long num, long long power) {     if (power == 0)       return 1;     else {       long long an = (num) % mod;       if (power % 2 == 0) {         an = bin(num, power / 2);         long long an1 = an;         an *= an1;         an %= mod;         return an;       } else {         an *= bin(num, power - 1);         an %= mod;         return an;       }     }   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long q;     cin >> q;     while (q--) {       long long n, k;       cin >> n >> k;       if (n % k <= k / 2) {         cout << n <<   n ;       } else         cout << n - ((n % k) - k / 2) <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool chk(int n, int first) { return n & (1 << first); }   void set(int& n, int first) { n = n | (1 << first); }   void reset(int& n, int first) { n = n & ~(1 << first); }   const int mx = 600010;   bool f[mx];   int a[mx][3], _size;   char s[mx];   int new_node() {     ++_size;     for (int i = 0; i < 3; i++) a[_size][i] = 0;     f[_size] = false;     return _size;   }   void Insert(char str[]) {     int cur = 0, i = -1;     while (str[++i] !=   0 ) {       int& next = a[cur][str[i] -  a ];       if (next == 0) next = new_node();       cur = next;     }     f[cur] = true;   }   bool Search(int i, int cur, bool flag) {     if (s[i] ==   0 ) return f[cur] && flag;     if (flag) {       int next = a[cur][s[i] -  a ];       if (next == 0) return false;       return Search(i + 1, next, 1);     } else {       int next = a[cur][s[i] -  a ];       if (next > 0 && Search(i + 1, next, 0)) return true;       for (int j = 0; j < 3; j++) {         next = a[cur][j];         if (next == 0) continue;         if (s[i] == j +  a ) continue;         if (Search(i + 1, next, 1)) return true;       }       return false;     }   }   int main() {     int i, j, k, n, m;     while (scanf( %d%d , &n, &m) == 2) {       _size = -1;       new_node();       for (i = 0; i < n; i++) {         scanf( %s , s);         Insert(s);       }       for (i = 0; i < m; i++) {         scanf( %s , s);         if (Search(0, 0, 0))           printf( YES n );         else           printf( NO n );       }     }   }