malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int N = 20, Mod = 1e9 + 7;   int pl, pr, vl, vr, k;   long double p, q;   vector<int> v;   void count(int t) {     int L, R;     L = min(v[t], pr) - max(v[t - 1] + 1, pl);     R = min(v[t + k] - 1, vr) - max(v[t + k - 1], vl);     p += max(L + 1, 0) * 1ll * max(R + 1, 0);     L = min(v[t], vr) - max(v[t - 1] + 1, vl);     R = min(v[t + k] - 1, pr) - max(v[t + k - 1], pl);     p += max(L + 1, 0) * 1ll * max(R + 1, 0);     if (k == 1) {       if (vl <= v[t] && v[t] <= vr && pl <= v[t] && v[t] <= pr) p--;     }   }   void add(int length) {     for (int i = 0; i < (1 << length); i++) {       int num = 0;       for (int j = 0; j < length; j++) {         num *= 10;         if (i & (1 << j))           num += 4;         else           num += 7;       }       v.push_back(num);     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cin >> pl >> pr >> vl >> vr >> k;     q = (pr - pl + 1) * 1ll * (vr - vl + 1);     for (int i = 1; i <= 9; i++) add(i);     v.push_back(0);     v.push_back(Mod);     v.push_back(Mod);     sort(v.begin(), v.end());     int n = v.size();     for (int i = 1; i < n - k - 1; i++) {       count(i);     }     cout << fixed << setprecision(10) << p / q;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 5;   const int M = 5.1e6 + 5;   const int B = 10;   int n, q;   int h[M];   int go[B + 1][N];   vector<int> dv[N];   int best[8][M];   int main() {     for (int i = 2; i * i < M; i++) {       if (!h[i]) {         for (int j = i; j < M; j += i) h[j] = i;       }     }     scanf( %d %d , &n, &q);     for (int i = 1; i <= n; i++) {       int x;       scanf( %d , &x);       while (h[x]) {         int y = h[x], c = 0;         while (x % y == 0) {           x /= y;           c ^= 1;         }         if (c) dv[i].push_back(y);       }       if (x > 1) dv[i].push_back(x);       assert(dv[i].size() <= 7);     }     for (int need = 0; need <= B; need++) {       go[need][n + 1] = n + 1;       memset(best, 0, sizeof(best));       for (int i = n; i >= 1; i--) {         go[need][i] = go[need][i + 1];         for (int mask = 0; mask < (1 << dv[i].size()); mask++) {           int prod = 1, cnt = dv[i].size() - __builtin_popcount(mask);           for (int j = 0; j < dv[i].size(); j++)             if (mask & (1 << j)) prod *= dv[i][j];           if (cnt <= need and need - cnt <= 7 and best[need - cnt][prod]) {             go[need][i] = min(go[need][i], best[need - cnt][prod]);           }           best[cnt][prod] = i;         }       }     }     for (int i = 1; i <= q; i++) {       int l, r;       scanf( %d %d , &l, &r);       for (int i = 0; i <= B + 1; i++) {         if (i > B or go[i][l] <= r) {           printf( %d n , i);           break;         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long inf = 0x3f3f3f3f3f3f3f3fll;   inline long long read() {     long long x = 0, f = 1;     char c = getchar();     while (c <  0  || c >  9 ) {       if (c ==  - ) f = -1;       c = getchar();     }     while (c >=  0  && c <=  9 ) {       x = (x << 1) + (x << 3) + c -  0 ;       c = getchar();     }     return x * f;   }   int n, x[5005], m, p[5005], c[5005], q[5005], l, r, t[5005];   long long s[5005], dp[5005][5005];   int main() {     n = read(), m = read();     for (int i = 1; i <= n; ++i) {       x[i] = read();     }     sort(x + 1, x + n + 1);     for (int i = 1; i <= m; ++i) {       p[i] = read(), c[i] = read();       t[i] = i;     }     sort(t + 1, t + m + 1, [&](int i, int j) { return p[i] < p[j]; });     memset(dp, 0x3f, sizeof(dp));     dp[0][0] = 0;     for (int j = 1; j <= m; ++j) {       r = 0, l = 1;       for (int i = 1; i <= n; ++i) {         s[i] = s[i - 1] + abs(x[i] - p[t[j]]);       }       for (int i = 0; i <= n; ++i) {         while (l <= r && q[l] < i - c[t[j]]) ++l;         while (l <= r && dp[i][j - 1] - s[i] <= dp[q[r]][j - 1] - s[q[r]]) --r;         q[++r] = i;         dp[i][j] = dp[q[l]][j - 1] + s[i] - s[q[l]];       }     }     if (dp[n][m] == inf) {       printf( -1 n );       return 0;     }     printf( %lld n , dp[n][m]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int pr[2 * 100 * 1000 + 10];   int a[2 * 100 * 1000 + 10];   int main() {     int max_n = 0;     int n;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a[i];       if (a[i] > max_n) max_n = a[i];     }     for (int i = 0; i <= max_n; i++) pr[i] = 1;     for (int i = 2; i <= max_n; i++)       if (pr[i]) {         int k = 2;         while (i * k <= max_n) {           pr[i * k] = 0;           k++;         }       }     long long ans = 1;     for (long long i = 2; i <= max_n; i++) {       if (!pr[i]) continue;       int bad_index = -1;       long long cur = i;       while (cur <= max_n) {         int cnt = 0;         int new_bad = -1;         for (int j = 0; j < n; j++)           if (j != bad_index && a[j] % cur) {             cnt++;             new_bad = j;             if (cnt > 1) break;           }         if (cnt > 1) break;         if (bad_index != -1 && new_bad != -1) break;         if (bad_index == -1) bad_index = new_bad;         ans *= i;         cur *= i;       }     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   map<double, int> Freq;   int main() {     double N;     double W;     scanf( %lf%lf , &N, &W);     vector<double> vec;     for (int i = 0; i < N * 2; i++) {       double a;       scanf( %lf , &a);       vec.push_back(a);     }     sort((vec).begin(), (vec).end());     double ans = min(vec[0] * 1.0, vec[(int)(N + 1e-9)] / 2.0);     ans = min(ans, W * 1.0 / (N * 3.0));     printf( %.9lf n , 3 * N * ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> edge[200002], col;   int vis[200002];   queue<int> q;   void bfs(int s) {     vis[s] = 1;     q.push(s);     while (!q.empty()) {       int x = q.front();       q.pop();       set<int> st;       for (auto y : edge[x]) {         if (vis[y]) {           st.insert(col[y - 1]);         }       }       if (col[x - 1] == -1) {         int flag = 1;         while (1) {           if (st.find(flag) != st.end()) {             flag++;           } else {             col[x - 1] = flag;             break;           }         }       }       int start = col[x - 1] - 1, end = col[x - 1] + 1;       for (auto y : edge[x]) {         if (!vis[y]) {           vis[y] = 1;           q.push(y);           int flag = 0;           while (!flag) {             if (start > 0) {               if (st.find(start) != st.end()) {                 start--;               } else {                 col[y - 1] = start;                 st.insert(start);                 start--;                 flag = 1;               }             } else {               if (st.find(end) != st.end()) {                 end++;               } else {                 col[y - 1] = end;                 st.insert(end);                 end++;                 flag = 1;               }             }           }         }       }     }   }   void solve() {     int n;     cin >> n;     for (int i = 0; i < n - 1; i++) {       int x, y;       cin >> x >> y;       edge[x].push_back(y);       edge[y].push_back(x);     }     col.assign(n, -1);     for (int i = 1; i <= n; i++) {       if (edge[i].size() > 1) {         bfs(i);         break;       }     }     int mx = 1;     for (auto x : col) {       mx = max(x, mx);     }     cout << mx <<   n ;     for (auto x : col) {       cout << x <<    ;     }     cout <<   n ;   }   int main() {     ios_base ::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     solve();   }
#include <bits/stdc++.h>   using namespace std;   struct node {     int val, id;     friend bool operator<(node a, node b) { return a.id > b.id; }   };   int main() {     int t, m, n;     struct node p;     while (~scanf( %d %d , &m, &n)) {       priority_queue<node> a;       priority_queue<node> b;       int id = 0;       for (int i = 0; i < m; i++) {         scanf( %d , &t);         p.id = id++;         p.val = t;         a.push(p);       }       id = 0;       ;       for (int i = 0; i < n; i++) {         scanf( %d , &t);         p.id = id++;         p.val = t;         b.push(p);       }       while (!b.empty() && !a.empty()) {         if (a.top().val <= b.top().val) {           a.pop();           b.pop();         } else if (a.top().val > b.top().val) {           a.pop();         }       }       printf( %d n , n - b.size());     }   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 2e5;   const int MAXM = 2e5;   int NV, NH;   int V[MAXN];   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     cin >> NV >> NH;     for (int i = 0; i < NV; i++) {       cin >> V[i];     }     priority_queue<int, vector<int>, greater<int>> H;     for (int i = 0; i < NH; i++) {       int x1, x2, y;       cin >> x1 >> x2 >> y;       if (x1 == 1) {         H.push(x2);       } else {         continue;       }     }     int res = NV + NH;     sort(V, V + NV);     V[NV] = int(1e9);     for (int i = 0; i <= NV; i++) {       while (!H.empty() && H.top() < V[i]) {         H.pop();       }       res = min(res, i + int(H.size()));     }     cout << res <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long double EPS = 1e-3;   const int INF = (long double)(1e9);   const long long mod = (int)(1e+9 + 7);   const int N = (int)(2e3);   int days_month[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};   long long ekn;   long long inverse;   long long expo(long long b, long long e) {     long long prod = 1;     while (e != 0) {       if (e & 1) prod = (1LL * prod * b) % mod;       b = (1LL * b * b) % mod;       e >>= 1;     }     return prod % mod;   }   int f(int i) {     long long prod = (1LL * expo(2, i) * (ekn - 1)) % mod;     prod = (prod * inverse) % mod;     return prod;   }   int main() {     string s;     cin >> s;     int k;     cin >> k;     int n = int(s.size());     ekn = expo(2, 1LL * k * n);     inverse = expo(expo(2, n) - 1, mod - 2);     int ans = 0;     for (int i = 0; i < n; i++) {       if (s[i] !=  0  && s[i] !=  5 ) continue;       ans += f(i);       if (ans >= mod) ans -= mod;     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2 * (int)1e5 + 100;   int n, k;   char a[N];   int main() {     scanf( %d %d , &n, &k);     scanf( %s , a);     int tmp = 0, result = 0, ans = 0;     for (int i = 0; i < 26; i++) {       char ch =  a  + i;       tmp = 0;       result = 0;       for (int j = 0; j <= n; j++) {         if (a[j] == ch) {           tmp++;         } else {           result += tmp / k;           tmp = 0;         }       }       ans = max(ans, result);     }     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAX_N = 110;   const int INF = 1 << 28;   const double EPS = 1e-9;   const double PI = 3.14159265358979;   int n, d;   int a[MAX_N];   int x[MAX_N], y[MAX_N];   int g[MAX_N][MAX_N];   int main() {     cin >> n >> d;     for (int i = (1); i < (n - 1); i++) cin >> a[i];     for (int i = (0); i < (n); i++) cin >> x[i] >> y[i];     for (int i = (0); i < (n); i++)       for (int j = (0); j < (n); j++) {         g[i][j] = d * (abs(x[i] - x[j]) + abs(y[i] - y[j]));         if (i != j) g[i][j] -= a[j];       }     for (int k = (0); k < (n); k++)       for (int i = (0); i < (n); i++)         for (int j = (0); j < (n); j++) g[i][j] = min(g[i][j], g[i][k] + g[k][j]);     cout << g[0][n - 1] << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   map<long long, long long> Map;   void modify(long long x, long long y) {     map<long long, long long>::iterator it;     long long c;     scanf( %I64d , &c);     while (x != y) {       if (x < y) swap(x, y);       it = Map.find(x);       if (it != Map.end())         it->second += c;       else         Map[x] = c;       x >>= 1;     }   }   long long query(long long x, long long y) {     map<long long, long long>::iterator it;     long long ans = 0;     while (x != y) {       if (x < y) swap(x, y);       it = Map.find(x);       if (it != Map.end()) ans += it->second;       x >>= 1;     }     return ans;   }   int main(int argc, char* argv[]) {     int q = 0;     for (; scanf( %d , &q) != EOF;) {       Map.clear();       while (q--) {         int od;         long long x, y, c;         scanf( %d%I64d%I64d , &od, &x, &y);         if (od == 1)           modify(x, y);         else           printf( %I64d n , query(x, y));       }     }     return 0;   }
#include <bits/stdc++.h>   int a[1000005];   double tt;   int main() {     int n, i, t;     double vb, vs, x, y, d;     while (scanf( %d %lf %lf , &n, &vb, &vs) != EOF) {       t = 2;       for (i = 1; i <= n; i++) {         scanf( %d , &a[i]);       }       scanf( %lf %lf , &x, &y);       d = a[2] / vb + sqrt((x - a[2]) * (x - a[2]) + y * y) / vs;       for (i = 2; i <= n; i++) {         tt = a[i] / vb + sqrt((x - a[i]) * (x - a[i]) + y * y) / vs;         if (tt <= d) {           d = tt;           t = i;         }       }       printf( %d n , t);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   int sumOfDigits(int n) {     int ans = 0;     if (n <= 9) return n;     while (n) {       ans += n % 10;       n /= 10;     }     return ans;   }   int main() {     cin.tie(NULL);     ios_base::sync_with_stdio(false);     int a;     cin >> a;     while (sumOfDigits(a) % 4 != 0) {       a++;     }     cout << a << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long maxn = 4e5 + 10;   const long long mod = 998244353;   const long long inf = 1e18 + 10;   const long long Log = 21;   long long n, m, k;   long long pw(long long a, long long b) {     if (b == 0) return 1;     long long x = pw(a, b / 2);     x = (x * x) % mod;     if (b & 1) x = (x * a) % mod;     return x;   }   long long cnt(long long x, long long p) {     long long X = 0;     while (x % p == 0) {       x /= p;       X++;     }     return X;   }   long long D;   vector<long long> pr;   long long fac[maxn], repo[maxn];   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     fac[0] = 1;     repo[0] = 1;     for (long long i = 1; i < 200; i++) {       fac[i] = (fac[i - 1] * i) % mod;       repo[i] = pw(fac[i], mod - 2);     }     cin >> D;     for (long long i = 2; i <= sqrt(D); i++)       if (D % i == 0) {         while (D % i == 0) D /= i;         pr.push_back(i);       }     if (D > 1) pr.push_back(D);     long long q;     cin >> q;     while (q--) {       long long u, v;       cin >> u >> v;       if (u > v) swap(u, v);       long long ans = 1, sm2 = 0, sm1 = 0;       for (auto p : pr) {         long long x = cnt(u, p);         long long y = cnt(v, p);         (ans *= repo[abs(x - y)]) %= mod;         if (x < y) sm1 += y - x;         if (x > y) sm2 += x - y;       }       (ans *= (fac[sm1] * fac[sm2]) % mod) %= mod;       cout << ans <<   n ;     }   }
#pragma GCC optimize( -Ofast , -funroll-all-loops )   #pragma GCC optimize(2)   #pragma GCC optimize(3, Ofast , inline )   #include<bits/stdc++.h>   using namespace std;      typedef long long ll;   int _;   int n;   int a[30010];      void solve(){       cin >> _;       while(_--){           cin >> n;           int cnt0 = 0, cnt1 = 0, cnt2 = 0;           for(int i = 1; i <= n; i++){               cin >> a[i];               if(a[i] % 3 == 0){                   cnt0++;               }               else if(a[i] % 3 == 1){                   cnt1++;               }               else{                   cnt2++;               }           }           int need = n/3;           if(cnt0 == need && cnt1 == need && cnt2 == need){               cout <<  0  <<   n ;           }           else if(cnt0 > need && cnt1 > need && cnt2 < need){               cout << (cnt0-need)*2 + (cnt1-need) <<   n ;           }           else if(cnt0 < need && cnt1 > need && cnt2 > need){               cout << (cnt1-need)*2+(cnt2-need) <<   n ;           }           else if(cnt0 > need && cnt1 < need && cnt2 > need){               cout << (cnt0-need) + (cnt2-need)*2 <<   n ;           }           else if(cnt0 > need && cnt1 < need && cnt2 < need){               cout << (need-cnt1) + (need-cnt2)*2 <<   n ;           }           else if(cnt0 < need && cnt1 > need && cnt2 < need){               cout << (need-cnt2) + 2*(need-cnt0) <<   n ;           }           else if(cnt0 < need && cnt1 < need && cnt2 > need){               cout << (need-cnt0) + 2*(need-cnt1) <<   n ;           }           else if(cnt0 == need){               if(cnt1 > need && cnt2 < need){                   cout << (cnt1-need) <<   n ;               }               else{                   cout << 2*(cnt2-need) <<  n ;               }           }           else if(cnt1 == need){               if(cnt0 > need && cnt2 < need){                   cout << 2*(cnt0-need) <<   n ;               }               else{                   cout << (cnt2-need) <<   n ;               }           }           else if(cnt2 == need){               if(cnt0 > need && cnt1 < need){                   cout << (cnt0 - need) <<   n ;               }               else{                   cout << 2*(cnt1 - need) <<   n ;               }           }       }       return ;   }      int main(){       ios::sync_with_stdio(false);       cin.tie(0);       cout.tie(0);              solve();       return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 200005;   int n, a[maxn], total;   void solve() {     vector<int> ans;     for (int i = 1; i <= n; i++) {       if (a[i] * n == total) ans.push_back(i);     }     cout << (int)ans.size() << endl;     for (int i = 0; i < ans.size(); i++) {       if (i) printf(   );       cout << ans[i];     }     cout << endl;   }   int main() {     cin >> n;     total = 0;     for (int i = 1; i <= n; i++) {       cin >> a[i];       total += a[i];     }     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long arr[1000000], arr1[1000000], cnt2[1000000];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long n, k, i, j, x, y, z, ans, a, b, c;     cin >> n >> k;     for (i = 1; i <= n; i++) {       cin >> arr[i];     }     for (i = 1; i <= n; i++) {       cin >> arr1[i];     }     x = arr[k] + arr1[1];     y = 1;     z = n;     for (i = 1; i <= k; i++) {       if (arr[i] + arr1[z] <= x) {         z--;       } else if (arr[i] + arr1[z] > x) {         y++;       }     }     cout << y << endl;   }
#include <bits/stdc++.h>   using namespace std;   const long long mod = 998244353;   int n, q, a[300500], dp[300500][30], best[300500][30], last[30];   int f(int x, int bt) {     if (a[x] & (1 << bt)) return x;     if (dp[x][bt] != -1) return dp[x][bt];     int mn = 1e9;     for (int i = 0; i <= 27; i++) {       if (a[x] & (1 << i) && best[x][i] != 1e9) mn = min(mn, f(best[x][i], bt));     }     return dp[x][bt] = mn;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     memset(dp, -1, sizeof dp);     for (int i = 0; i <= 27; i++) last[i] = 1e9;     cin >> n >> q;     for (int i = 0; i < n; i++) cin >> a[i];     for (int i = n - 1; i >= 0; i--) {       for (int j = 0; j <= 27; j++) best[i][j] = 1e9;       for (int j = 0; j <= 27; j++) {         best[i][j] = last[j];         if ((a[i] & (1 << j))) last[j] = i;       }     }     while (q--) {       int x, y, ans = 0;       cin >> x >> y;       x--, y--;       for (int i = 0; i <= 27; i++) {         if ((a[y] & (1 << i)) && f(x, i) <= y) ans = 1;       }       if (ans)         cout <<  Shi  << endl;       else         cout <<  Fou  << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   const int OO = (int)2e9;   const double PI = 2 * acos(0.0);   const double EPS = 1e-9;   int dcmp(double a, double b) { return fabs(a - b) <= EPS ? 0 : a > b ? 1 : 2; }   int DI[] = {-1, 0, 1, 0, 1, -1, -1, 1};   int DJ[] = {0, 1, 0, -1, 1, -1, 1, -1};   map<int, long long> m;   int main() {     int n;     cin >> n;     for (int i = 0; i < (int)n; i++) {       int x;       cin >> x;       m[x]++;     }     long long ans = 0;     for (int i = -10; i < 0; i++)       if (m.count(i) && m.count(abs(i))) ans += (m[i] * m[abs(i)]);     if (m.count(0)) {       for (long long t = m[0] - 1; t > 0; t--) ans += t;     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   priority_queue<pair<int, int>, vector<pair<int, int> >,                  greater<pair<int, int> > >       que;   stringstream ssin;   const long long LINF = 0x7fffffffffffffffll;   const int N = 4e5 + 5, M = 4e5 + 5, mod = 1e9 + 7, INF = 0x3f3f3f3f;   int n, idx, sum;   int e[M], ne[M], h[N], ans[N];   inline long long read() {     char c = getchar();     long long x = 0, f = 1;     while (c <  0  || c >  9 ) {       if (c ==  - ) f = -1;       c = getchar();     }     while (c >=  0  && c <=  9 ) {       x = x * 10 + c -  0 ;       c = getchar();     }     return x * f;   }   void add(int a, int b) {     e[idx] = b;     ne[idx] = h[a];     h[a] = idx++;   }   void dfs(int u, int fa) {     for (int i = h[u]; ~i; i = ne[i]) {       int v = e[i];       if (v == fa) continue;       dfs(v, u);     }     if (fa != -1) {       if (ans[u] == u) {         swap(ans[u], ans[fa]);         sum += 2;       }     }   }   int main() {     n = read();     memset(h, -1, sizeof h);     ;     for (int i = 1; i < n; ++i) {       ans[i] = i;       int a, b;       a = read();       b = read();       add(a, b);       add(b, a);     }     ans[n] = n;     dfs(1, -1);     if (ans[1] == 1) {       sum += 2;       for (int i = h[1]; ~i; i = ne[i]) {         int v = e[i];         swap(ans[1], ans[v]);         break;       }     }     cout << sum <<   n ;     for (int i = 1; i <= n; ++i) cout << ans[i] <<    ;     puts(  );   }
#include <bits/stdc++.h>   using namespace std;   long long inv(long long a, long long mod) {     long long b = mod, p = 1, q = 0;     while (b) {       long long c = a / b, d = a;       a = b;       b = d % b;       d = p;       p = q;       q = d - c * q;     }     return (p + mod) % mod;   }   int fs = 505050;   vector<long long> fact(fs), ifact(fs);   long long binom(int a, int b, long long mod) {     if (a < b) return 0;     return fact[a] * ifact[b] % mod * ifact[a - b] % mod;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n;     cin >> n;     long long k;     cin >> k;     vector<long long> a(n);     for (int i = 0; i < n; i++) cin >> a[i];     long long mod = 998244353;     fact[0] = 1;     for (int i = 1; i < fs; i++) fact[i] = fact[i - 1] * i % mod;     ifact[fs - 1] = inv(fact[fs - 1], mod);     for (int i = fs - 1; i > 0; i--) ifact[i - 1] = ifact[i] * i % mod;     long long res = 0;     int same = 0;     for (int i = 0; i < n; i++) {       if (a[i] == a[(i + n - 1) % n]) same++;     }     int x = n - same;     if (x & 1) {       long long coef = k - 2;       for (int i = 1; i <= x; i += 2) {         res +=             binom(x, i, mod) * coef % mod * binom(x - i, (x - i) / 2, mod) % mod;         res %= mod;         coef = coef * (k - 2) % mod * (k - 2) % mod;       }     } else {       long long coef = 1;       for (int i = 0; i <= x; i += 2) {         res +=             binom(x, i, mod) * coef % mod * binom(x - i, (x - i) / 2, mod) % mod;         res %= mod;         coef = coef * (k - 2) % mod * (k - 2) % mod;       }     }     for (int i = 0; i < same; i++) {       res = res * k % mod;     }     long long ent = 1;     for (int i = 0; i < n; i++) {       ent = ent * k % mod;     }     res = (ent - res + mod) % mod;     res = res * ((mod + 1) / 2) % mod;     cout << res <<   n ;     return 0;   }