malteklaes/cpp-code-code_search_net-style huggingface dataset:
/* بسم الله الرحمن الرحيم    * Author: kabir10    * Time: 2021-01-08 21:11:10   **/   #include<bits/stdc++.h>   using namespace std;   #define mod 1000000007      void __print(int x) {cerr << x;}   void __print(long x) {cerr << x;}   void __print(long long x) {cerr << x;}   void __print(unsigned x) {cerr << x;}   void __print(unsigned long x) {cerr << x;}   void __print(unsigned long long x) {cerr << x;}   void __print(float x) {cerr << x;}   void __print(double x) {cerr << x;}   void __print(long double x) {cerr << x;}   void __print(char x) {cerr <<      << x <<     ;}   void __print(const char *x) {cerr <<     << x <<    ;}   void __print(const string &x) {cerr <<     << x <<    ;}   void __print(bool x) {cerr << (x ?  true  :  false );}      template<typename T, typename V>   void __print(const pair<T, V> &x) {cerr <<  { ; __print(x.first); cerr <<  , ; __print(x.second); cerr <<  } ;}   template<typename T>   void __print(const T &x) {int f = 0; cerr <<  { ; for (auto &i: x) cerr << (f++ ?  ,  :   ), __print(i); cerr <<  } ;}   void _print() {cerr <<  ] n ;}   template <typename T, typename... V>   void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr <<  ,  ; _print(v...);}   #ifndef ONLINE_JUDGE   #define debug(x...) cerr <<  [  << #x <<  ] = [ ; _print(x)   #else   #define debug(x...)   #endif   int arr[300007];   int check(int i) {       int contribution = 0;       if(arr[i] > arr[i - 1] && arr[i] > arr[i + 1]) {           contribution = 1;       }       if(arr[i] < arr[i - 1] && arr[i] < arr[i + 1]) {           contribution = 1;       }       return contribution;   }      int main() {       ios_base::sync_with_stdio(false);       int t;       cin >> t;       while(t--) {           int n;           cin >> n;                      vector<int> sum(n, 0);           for(int i = 0; i < n; i++) {               cin >> arr[i];           }           if(n < 3) {               cout << 0 << endl;               continue;           }           int total = 0;           for(int i = 1; i < n - 1; i++) {               sum[i] = check(i);               total += sum[i];           }              int ans = total;              for(int i  = 1; i < n - 1; i++) {               int temp = arr[i];               arr[i] = arr[i - 1];               int add1 = 0, add2 = 0;               for(int j = max(1, i - 1); j <= min(n - 2, i + 1); j++) {                   add1 += check(j);                   add1 -= sum[j];               }               arr[i] = arr[i + 1];               for(int j = max(1, i - 1); j <= min(n - 2, i + 1); j++) {                   add2 += check(j);                   add2 -= sum[j];               }               arr[i] = temp;                              ans = min(ans, min(total + add1, total + add2));           }           cout << ans << endl;       }       return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, a[210], m;   priority_queue<int> q;   priority_queue<int, deque<int>, greater<int> > q2;   int main() {     while (scanf( %d%d , &n, &m) != EOF) {       for (int i = 0; i < n; ++i) scanf( %d , &a[i]);       int ans = a[0];       for (int i = 0; i < n; ++i) {         for (int j = i; j < n; ++j) {           for (int k = 0; k < n; ++k) {             if (k >= i && k <= j)               q2.push(a[k]);             else               q.push(a[k]);           }           for (int k = 0; k < m; ++k) {             if (q.empty() || q2.empty()) break;             int s = q2.top();             int l = q.top();             if (s >= l) break;             q2.pop();             q.pop();             q2.push(l);             q.push(s);           }           int sum = 0;           while (!q2.empty()) {             sum += q2.top();             q2.pop();           }           ans = max(ans, sum);           while (!q.empty()) {             q.pop();           }         }       }       printf( %d n , ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class c>   struct rge {     c b, e;   };   template <class c>   rge<c> range(c i, c j) {     return rge<c>{i, j};   }   template <class c>   auto dud(c* x) -> decltype(cerr << *x, 0);   template <class c>   char dud(...);   struct debug {     ~debug() { cerr << endl; }     template <class c>     typename enable_if<sizeof dud<c>(0) != 1, debug&>::type operator<<(c i) {       cerr << boolalpha << i;       return *this;     }     template <class c>     typename enable_if<sizeof dud<c>(0) == 1, debug&>::type operator<<(c i) {       return *this << range(begin(i), end(i));     }     template <class c, class b>     debug& operator<<(pair<b, c> d) {       return *this <<  (  << d.first <<  ,   << d.second <<  ) ;     }     template <class c>     debug& operator<<(rge<c> d) {       *this <<  [ ;       for (auto it = d.b; it != d.e; ++it) *this <<  ,   + 2 * (it == d.b) << *it;       return *this <<  ] ;     }   };   long long mod = 1e9 + 7;   int INF = 1e9;   long long INF64 = 1e18;   long long binpow(long long a, long long b, long long m) {     a %= m;     long long res = 1;     while (b > 0) {       if (b & 1) {         res = res * a % m;       }       a = a * a % m;       b >>= 1;     }     return res;   }   vector<vector<int>> adj(2e5 + 5);   vector<int> ord;   vector<int> pos(2e5 + 5);   vector<int> ending(2e5 + 5);   void dfs(int node, int par) {     pos[node] = ord.size();     ord.push_back(node);     for (int i : adj[node]) {       if (i == par) continue;       dfs(i, node);     }     ending[node] = ord.size();   }   void test_case(int tnum) {     int n, q;     cin >> n >> q;     for (int i = 2; i <= n; i++) {       int u;       cin >> u;       adj[u].push_back(i);       adj[i].push_back(u);     }     dfs(1, -1);     for (int i = 0; i < q; i++) {       int u, k;       cin >> u >> k;       if (pos[u] + k - 1 >= ending[u]) {         cout << -1 <<   n ;       } else {         cout << ord[pos[u] + k - 1] <<   n ;       }     }   }   int main() {     cin.tie(0);     cout.tie(0);     ios_base::sync_with_stdio(false);     int t = 1;     for (int i = 1; i <= t; i++) {       test_case(t);     }   }
#include <bits/stdc++.h>   using namespace std;   struct data {     int x, p;     bool operator<(const data &b) const { return x < b.x; }   } a[200010];   int seg[200010 * 4];   int query(int l, int r, int from, int to, int x, int p) {     if (l == from && r == to)       if (seg[p] > x) return 0;     if (l + 1 == r) return l;     int m = l + r >> 1, t;     if (to <= m) return query(l, m, from, to, x, p << 1);     if (from >= m) return query(m, r, from, to, x, p << 1 | 1);     t = query(l, m, from, m, x, p << 1);     if (t) return t;     return query(m, r, m, to, x, p << 1 | 1);   }   void build(int l, int r, int p) {     if (l + 1 == r) {       seg[p] = a[l].p;       return;     }     build(l, l + r >> 1, p << 1);     build(l + r >> 1, r, p << 1 | 1);     seg[p] = min(seg[p << 1], seg[p << 1 | 1]);   }   int main() {     int d, n, m, i;     long long ans = 0;     cin >> d >> n >> m;     for (i = 1; i <= m; i++) {       scanf( %d%d , &a[i].x, &a[i].p);     }     sort(a + 1, a + 1 + m);     a[0].x = 0;     a[m + 1].x = d, a[m + 1].p = -1;     for (i = 1; i <= m + 1; i++)       if (a[i].x - a[i - 1].x > n) ans = -1;     build(1, m + 2, 1);     if (ans != -1) {       int now, j, nex;       for (now = n - a[1].x, i = j = 1; i <= m;) {         while (j <= m && a[j + 1].x - a[i].x <= n) j++;         nex = query(1, m + 2, i + 1, j + 1, a[i].p, 1);         if (nex) {           if (a[nex].x - a[i].x <= now) {             now -= a[nex].x - a[i].x;           } else {             ans += ((long long)a[nex].x - a[i].x - now) * a[i].p;             now = 0;           }           i = nex;         } else {           ans += ((long long)n - now) * a[i].p;           now = n - (a[i + 1].x - a[i].x);           i++;         }       }     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int ar[50];   int n, l, r, x, ans = 0, p = 0;   vector<int> vec;   void besaz(string s) {     if (s.length() == n) {       p++;       vec.clear();       for (int i = 0; i < n; i++)         if (s[i] ==  1 ) vec.push_back(ar[i]);       sort(vec.begin(), vec.end());       unsigned long long sum = 0;       for (int i = 0; i < (int)vec.size(); i++) {         sum += vec[i];       }       if (vec.size() >= 2 && sum <= r && sum >= l &&           vec[vec.size() - 1] - vec[0] >= x)         ans++;       return;     } else {       besaz(s +  0 );       besaz(s +  1 );     }   }   int main() {     cin >> n >> l >> r >> x;     for (int i = 0; i < n; i++) cin >> ar[i];     besaz(  );     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   const int N = 4010;   int v[N], idx, f[N];   int last;   void init() {     for (int i = 0; i <= 2 * n; i++) f[i] = v[i] = 0;     last = idx = 0;   }   int main() {     ios::sync_with_stdio(false);     cin.tie();     cout.tie(0);     int T;     cin >> T;     while (T--) {       init();       cin >> n;       for (int i = 0; i < 2 * n; i++) {         int x;         cin >> x;         if (x > last) {           idx++;           last = x;         }         v[idx]++;       }       for (int i = 1; i <= idx; i++)         for (int j = n; j >= v[i]; j--) f[j] = max(f[j], f[j - v[i]] + v[i]);       if (f[n] == n)         cout <<  YES  << endl;       else         cout <<  NO  << endl;     }     return 0;   }
#include <bits/stdc++.h>   const double E = exp(1);   const int maxn = 1e6 + 10;   const int mod = 1e9 + 7;   using namespace std;   char ch[maxn];   int a[maxn];   bool cmp(int a, int b) { return a > b; }   int main(int argc, char const *argv[]) {     ios::sync_with_stdio(false);     int n, k;     cin >> n >> k;     cin >> ch;     int res = 1;     for (int i = 0; i < n; i++) {       if (k == 1)         a[ch[i] -  a ]++;       else {         if (ch[i] == ch[i + 1])           res++;         else           res = 1;         if (res == k) {           a[ch[i] -  a ]++;           res = 1;           i += 1;         }       }     }     sort(a, a + 26, cmp);     cout << a[0] << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 110;   bool ls(string s1, string s2) {     for (int i = 0; i < s1.size(); i++)       if (s1[i] < s2[i])         return 1;       else if (s1[i] > s2[i])         return 0;     return 0;   }   int main() {     string s, t, tmp;     cin >> s;     int pos = s.find( . );     for (int i = pos + 1; i < s.size(); i++) tmp += s[i];     t =  5 ;     for (int i = 0; i < tmp.size() - 1; i++) t +=  0 ;     if (ls(tmp, t) && s[pos - 1] !=  9 )       for (int i = 0; i < pos; i++) cout << s[i];     else if (!ls(tmp, t) && s[pos - 1] !=  9 ) {       for (int i = 0; i < pos - 1; i++) cout << s[i];       cout << char(s[pos - 1] + 1);     } else       cout <<  GOTO Vasilisa. ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int n, m;     cin >> n >> m;     int arr[n];     for (int i = 0; i < n; i++) cin >> arr[i];     int start = 0, end = m;     int ans;     while (start <= end) {       int mid = (start + end) / 2;       int min;       if (m - arr[0] <= mid)         min = 0;       else         min = arr[0];       int flag = 0;       for (int i = 1; i < n; i++) {         if (arr[i] < min && min - arr[i] <= mid) continue;         if (arr[i] < min && min - arr[i] > mid) {           flag = 1;           break;         }         if (arr[i] == min) continue;         if (arr[i] > min && min + m - arr[i] <= mid) continue;         if (arr[i] > min) min = arr[i];       }       if (flag == 1) {         start = mid + 1;       } else {         ans = mid;         end = mid - 1;       }     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     char a[101][101];     for (int i = 1; i <= 4; i++) {       for (int j = 1; j <= 4; j++) {         cin >> a[i][j];       }     }     for (int i = 1; i <= 4; i++) {       for (int j = 1; j <= 4; j++) {         if ((a[i - 1][j - 1] ==  .  && a[i - 1][j] ==  .  &&              a[i][j - 1] ==  . ) ||             (a[i + 1][j + 1] ==  .  && a[i + 1][j] ==  .  &&              a[i][j + 1] ==  . ) ||             (a[i + 1][j - 1] ==  .  && a[i + 1][j] ==  .  &&              a[i][j - 1] ==  . ) ||             (a[i - 1][j + 1] ==  .  && a[i - 1][j] ==  .  &&              a[i][j + 1] ==  . )) {           cout <<  YES ;           return 0;         }         if ((a[i - 1][j - 1] ==  #  && a[i - 1][j] ==  #  &&              a[i][j - 1] ==  # ) ||             (a[i + 1][j + 1] ==  #  && a[i + 1][j] ==  #  &&              a[i][j + 1] ==  # ) ||             (a[i + 1][j - 1] ==  #  && a[i + 1][j] ==  #  &&              a[i][j - 1] ==  # ) ||             (a[i - 1][j + 1] ==  #  && a[i - 1][j] ==  #  &&              a[i][j + 1] ==  # )) {           cout <<  YES ;           return 0;         }       }     }     cout <<  NO ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const double pi = acos(-1);   const int maxn = 20005;   const long long Mod = 998244353;   using namespace std;   int n, m, k;   int a[60][maxn], sum[60][maxn], dp[60][maxn];   int mx[maxn << 2], lazy[maxn << 2];   void pushup(int rt) { mx[rt] = max(mx[rt << 1], mx[rt << 1 | 1]); }   void pushdown(int rt) {     if (lazy[rt]) {       mx[rt << 1] += lazy[rt];       mx[rt << 1 | 1] += lazy[rt];       lazy[rt << 1] += lazy[rt];       lazy[rt << 1 | 1] += lazy[rt];       lazy[rt] = 0;     }   }   void build(int rt, int l, int r) {     lazy[rt] = 0;     mx[rt] = 0;     if (l == r) return;     int mid = (l + r) / 2;     build(rt << 1, l, mid);     build(rt << 1 | 1, mid + 1, r);   }   void update(int rt, int l, int r, int L, int R, int val) {     if (l > R || r < L) {       return;     }     if (l >= L && r <= R) {       lazy[rt] += val;       mx[rt] += val;       return;     }     pushdown(rt);     int mid = (l + r) / 2;     update(rt << 1, l, mid, L, R, val);     update(rt << 1 | 1, mid + 1, r, L, R, val);     pushup(rt);     return;   }   int query(int rt, int l, int r, int L, int R) {     if (l > R || r < L) return 0;     if (l >= L && r <= R) {       return mx[rt];     }     pushdown(rt);     int mid = (l + r) / 2;     return max(query(rt << 1, l, mid, L, R),                query(rt << 1 | 1, mid + 1, r, L, R));   }   int getsum(int i, int j) {     int ret = sum[i][j + k - 1] - sum[i][j - 1];     if (i != n) {       ret += sum[i + 1][j + k - 1] - sum[i + 1][j - 1];     }     return ret;   }   int main() {     std::ios::sync_with_stdio(false);     std::cin.tie(0);     ;     cin >> n >> m >> k;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) cin >> a[i][j];       for (int j = 1; j <= m; j++) sum[i][j] = sum[i][j - 1] + a[i][j];     }     for (int i = 1; i <= m - k + 1; i++) dp[1][i] = getsum(1, i);     for (int i = 2; i <= n; i++) {       build(1, 1, m - k + 1);       for (int j = 1; j <= m - k + 1; j++)         update(1, 1, m - k + 1, j, j, dp[i - 1][j]);       for (int j = 1; j <= m - k + 1; j++) {         int l = max(j, 1), r = min(j + k - 1, k);         if (l <= r) update(1, 1, m - k + 1, j, j, -(sum[i][r] - sum[i][l - 1]));       }       for (int j = 1; j <= m - k + 1; j++) {         dp[i][j] = mx[1] + getsum(i, j);         int L = max(1, j - k + 1);         int R = min(m - k + 1, j);         update(1, 1, m - k + 1, L, R, a[i][j]);         if (j != m - k + 1) {           int L = max(1, j + 1);           int R = min(m - k + 1, j + k);           update(1, 1, m - k + 1, L, R, -a[i][j + k]);         }       }     }     int ans = 0;     for (int i = 1; i <= m - k + 1; i++) ans = max(ans, dp[n][i]);     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int result = n;     while ((n % 2 == 0 && n / 2 != 1) || (n % 3 == 0 && n / 3 != 1) ||            (n % 5 == 0 && n / 5 != 1) || (n % 7 == 0 && n / 7 != 1)) {       if (n % 2 == 0) {         n /= 2;       } else if (n % 3 == 0) {         n /= 3;       } else if (n % 5 == 0) {         n /= 5;       } else if (n % 7 == 0) {         n /= 7;       }       result += n;     }     result += 1;     cout << result << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, d;     cin >> n >> d;     long long arr[n];     for (long long i = 0; i < n; i++) cin >> arr[i];     set<long long> s1;     for (long long i = 0; i < n; i++) {       long long pd = arr[i] - d;       if (i == 0)         s1.insert(pd);       else if (i != 0) {         long long a1 = abs(arr[i - 1] - pd);         if (a1 >= d) s1.insert(pd);       }       long long nd = arr[i] + d;       if (i == n - 1)         s1.insert(nd);       else if (i != n - 1) {         long long a1 = abs(arr[i + 1] - nd);         if (a1 >= d) s1.insert(nd);       }     }     cout << s1.size() <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MX = 10005;   int n, m, x[11], acu[MX], cn[22];   long long sum[MX];   string s[11];   vector<int> res;   void main_() {     cin >> n >> m;     for (int i = 0; i < int(n); i++) cin >> x[i];     for (int i = 0; i < int(n); i++) cin >> s[i];     long long mx = -1e18;     int rm;     for (int mk = 0; mk < int(1 << n); mk++) {       memset(acu, 0, sizeof(acu));       long long p = 0;       for (int i = 0; i < int(n); i++) {         int d = 0;         if (mk & (1 << i)) {           p -= x[i];           d = 1;         } else {           p += x[i];           d = -1;         }         for (int j = 0; j < int(m); j++)           if (s[i][j] ==  1 ) acu[j] += d;       }       memset(cn, 0, sizeof(cn));       for (int j = 0; j < int(m); j++) cn[acu[j] + 10]++;       for (int i = 20, x = 10, t = m; i >= 0; i--, x--) {         p += x * sum[t];         t -= cn[i];         p -= x * sum[t];       }       if (mx < p) {         mx = p;         rm = mk;       }     }     vector<pair<int, int> > v(m);     for (int i = 0; i < int(m); i++) v[i].second = i;     for (int i = 0; i < int(n); i++) {       int d = (rm & (1 << i)) ? 1 : -1;       for (int j = 0; j < int(m); j++)         if (s[i][j] ==  1 ) v[j].first += d;     }     sort(v.begin(), v.end());     vector<int> res(m);     for (int i = 0; i < int(m); i++) res[v[i].second] = i + 1;     for (int i = 0; i < int(m); i++) cout << res[i] <<    ;     cout <<   n ;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     for (int i = 0; i < int(MX); i++) {       sum[i] = i;       if (i) sum[i] += sum[i - 1];     }     int t = 1;     cin >> t;     while (t--) main_();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct node {     int nxt, t;   } A[1166900];   int head[100010], node_cnt;   void add_edge(int x, int y) {     A[node_cnt] = (node){head[x], y};     head[x] = node_cnt++;   }   int pri[100010], pri_cnt, mu[100010];   bool mark[100010];   void sieve() {     int i, j;     mu[1] = 1;     for (i = 2; i < 100010; i++) {       if (!mark[i]) {         pri[++pri_cnt] = i;         mu[i] = -1;       }       for (j = 1; j <= pri_cnt; j++) {         int t = i * pri[j];         if (t >= 100010) {           break;         }         mark[t] = 1;         if ((i % pri[j]) == 0) {           mu[t] = 0;           break;         }         mu[t] = -mu[i];       }     }     memset(head, -1, sizeof(head));     for (i = 100010 - 1; i >= 1; i--) {       for (j = i; j < 100010; j += i) {         add_edge(j, i);       }     }   }   int Fac[100010], Inv[100010], InvFac[100010];   void init() {     sieve();     int i;     Fac[0] = 1;     for (i = 1; i < 100010; i++) {       Fac[i] = 1LL * Fac[i - 1] * i % 1000000007;     }     Inv[1] = 1;     for (i = 2; i < 100010; i++) {       Inv[i] =           1LL * (1000000007 - 1000000007 / i) * Inv[1000000007 % i] % 1000000007;     }     InvFac[0] = 1;     for (i = 1; i < 100010; i++) {       InvFac[i] = 1LL * InvFac[i - 1] * Inv[i] % 1000000007;     }   }   int C(int n, int m) {     if (n < m) {       return 0;     }     return 1LL * Fac[n] * InvFac[n - m] % 1000000007 * InvFac[m] % 1000000007;   }   int main() {     init();     int Case;     scanf( %d , &Case);     while (Case--) {       int i, n, m, Ans = 0;       scanf( %d%d , &n, &m);       for (i = head[n]; ~i; i = A[i].nxt) {         int x = A[i].t, y = n / x;         if (y < m) {           break;         }         Ans = (Ans + mu[x] * C(y - 1, m - 1)) % 1000000007;       }       if (Ans < 0) {         Ans += 1000000007;       }       printf( %d n , Ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, a, last;     cin >> n;     bool r = false;     stack<int> s;     int m = 0;     for (int i = 0; i < n; i++) {       cin >> a;       m = max(m, a);       if (!s.empty() && a == s.top() && a >= last) {         s.pop();       } else {         s.push(a);       }       last = a;     }     if (s.size() > 1) {       cout <<  NO ;     } else {       if (s.size() == 1 && s.top() < m)         cout <<  NO ;       else         cout <<  YES ;     }   }
#include<bits/stdc++.h>   using namespace std;   const int N=17;   int n,p[1<<N];bool used[1<<N];   struct Edge{int nxt,to;}e[N*(1<<N)];int fir[1<<N];   void add(int u,int v,int i){e[i]=(Edge){fir[u],v},fir[u]=i;}   int col[1<<N];   void solve(){    cin>>n;    for(int i=0;i<(1<<n);++i){     used[i]=0,p[i]=fir[i]=col[i]=0;    }    for(int i=1;i<=n*(1<<(n-1));++i){     int u,v;scanf( %d%d ,&u,&v);     add(u,v,i<<1),add(v,u,i<<1|1);    }    p[0]=0,used[0]=true;    for(int i=fir[0],j=0;i;i=e[i].nxt,j++){     p[1<<j]=e[i].to,used[e[i].to]=true;    }    for(int i=1;i<(1<<n);++i){     if(p[i]) continue;     vector<int> bag;     set<int> fuck1,fuck2;     for(int j=0;j<n;++j){      if(i&(1<<j)) bag.push_back(p[i^(1<<j)]);     }     for(int j=0;j<(int)bag.size();++j){      if(!j){       for(int c=fir[bag[j]];c;c=e[c].nxt)       if(!used[e[c].to]) fuck2.insert(e[c].to);      }      else{       fuck1=fuck2,fuck2.clear();       for(int c=fir[bag[j]];c;c=e[c].nxt){        if(fuck1.find(e[c].to)==fuck1.end()) continue;        fuck2.insert(e[c].to);       }      }     }     p[i]=*fuck2.begin(),used[*fuck2.begin()]=true;    }    for(int i=0;i<(1<<n);++i) printf( %d  ,p[i]);    printf(  n );    if(n-(n&(-n))) return printf( -1 n ),void();    for(int i=0;i<(1<<n);++i){     int tmp=i;     for(int j=0;j<n;++j)     col[p[i]]^=j*(tmp&1),tmp>>=1;    }    for(int i=0;i<(1<<n);++i) printf( %d  ,col[i]);    return printf(  n ),void();   }   int main(){    int T;cin>>T;    while(T--) solve();   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 3, P = 998244353;   int fc[N], ifc[N];   int qp(int a, int b) {     int r = 1;     for (; b; b >>= 1, a = a * 1ll * a % P)       if (b & 1) r = r * 1ll * a % P;     return r;   }   int main() {     int n, m = 0, i, j, k, l, o, s = 0;     scanf( %d%d%d , &n, &k, &o), l = o, fc[0] = 1;     if (n == 1) return puts( 0 ), 0;     for (i = 1; i < n; ++i) scanf( %d , &j), m += j != l, l = j;     for (i = 1, m += j != o; i <= m; ++i) fc[i] = fc[i - 1] * 1ll * i % P;     for (i = m, ifc[m] = qp(fc[m], P - 2); i; --i)       ifc[i - 1] = ifc[i] * 1ll * i % P;     for (i = m / 2, o = (k - 2) * 1ll * (k - 2) % P, l = qp(k - 2, m - i * 2); ~i;          --i)       s = (s + (fc[m] * 1ll * ifc[i] % P * ifc[(m) - (i)] % P) *                    (fc[m - i] * 1ll * ifc[i] % P * ifc[(m - i) - (i)] % P) % P *                    l) %           P,       l = l * 1ll * o % P;     printf( %lld ,            ((qp(k, m) - s) * 1ll * qp(2, P - 2) % P * qp(k, n - m) % P + P) % P);     return 0;   }