malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int u[1005];   int v[1005];   int main() {     int n, k, i;     cin >> n >> k;     int a, b, c, d;     int t;     cin >> a >> b >> c >> d;     if (n == 4) {       cout <<  -1  << endl;     } else if (k < n + 1) {       cout <<  -1  << endl;     } else {       cout << a <<    ;       cout << c <<    ;       for (i = 1; i <= n; i++) {         if (i == a || i == b || i == c || i == d) {           continue;         }         cout << i <<    ;       }       cout << d <<    ;       cout << b << endl;       cout << c <<    ;       cout << a <<    ;       for (i = 1; i <= n; i++) {         if (i == a || i == b || i == c || i == d) {           continue;         }         cout << i <<    ;       }       cout << b <<    ;       cout << d << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int NR = 4e6 + 5;   int n;   long long P = 51123987;   char s[NR];   int d[NR];   long long f[NR], g[NR];   int main() {     scanf( %d , &n);     scanf( %s , s + 1);     for (int i = n; i >= 1; i--) {       s[i * 2] = s[i];       s[i * 2 - 1] =  # ;     }     s[n * 2 + 1] =  # ;     n = n * 2 + 1;     int p = 0, maxr = 0;     for (int i = 1; i <= n; i++) {       if (i <= maxr) d[i] = min(d[p + maxr - i], maxr - i + 1);       while (i - d[i] >= 1 && i + d[i] <= n && s[i - d[i]] == s[i + d[i]]) d[i]++;       if (i + d[i] - 1 > maxr) {         p = i - d[i] + 1;         maxr = i + d[i] - 1;       }       if (s[i] ==  #  && d[i] == 1) continue;       f[(i - d[i] + 2) / 2]++;       f[i / 2 + 1]--;       if (s[i] ==  # )         g[i / 2 + 1]++;       else         g[i / 2]++;       g[(i + d[i] - 1) / 2 + 1]--;     }     n = (n - 1) / 2;     for (int i = 1; i <= n; i++) {       f[i] += f[i - 1];       f[i] %= P;       g[i] += g[i - 1];       g[i] %= P;     }     long long sum1 = 0, sum2 = 0, ans = 0;     for (int i = 1; i <= n; i++) {       sum1 += f[i];       sum1 %= P;       ans += f[i] * sum2;       ans %= P;       sum2 += g[i];       sum2 %= P;     }     sum1 = sum1 * (sum1 - 1) / 2 % P;     printf( %lld n , (sum1 - ans + P) % P);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long N = 1e6 + 1;   const long long M = 1e9 + 7;   const long long H = 1e5 + 7;   const long long B = 1e4 + 7;   const long long A = 1e6 + 7;   set<long long> o;   map<long long, long long> mp, pm;   map<char, long long> hs;   vector<long long> v, vc, oreder1, inoreder, posoreder, ve, vv, vd;   deque<char> p, pe;   deque<string> ts, ss, stoi, rs;   deque<double> sd, ds;   string g, s, w, h, s1;   double l;   char z, u =  a ;   bool re, rt;   deque<int> e;   map<pair<long long, long long>, long long> aw, wa;   long long cnt, ans, TT, n, a, b, c, q, m, t, d, temp, mx = 0, mn = 0, rem, sum,                                                         tt = 1e32;   long long used[N];   int main() {     ios_base::sync_with_stdio(0);     srand(time(NULL));     cin >> n;     for (long long i = 0; i < n; i++) {       cin >> a >> b;       cnt = 0;       for (long long i = 0; i < a; i++) {         cin >> l;         cnt += l;       }       if (cnt == b) cout <<  YES  << endl;       if (cnt != b) cout <<  NO  << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int dp[225][1 << 16];   int dx[4] = {0, -1, 0, 1};   int dy[4] = {1, 0, -1, 0};   int tran[4] = {2, 3, 0, 1};   string s[15];   bool visit[15][15][1 << 16];   int n, m, length, backx, backy, startbody, status;   struct snake {     int x, y, body;   } start;   bool in(int x, int y) { return (x >= 0 && x < n && y >= 0 && y < m); }   bool collision(int x, int y, snake sn) {     int body = sn.body;     int xx = sn.x;     int yy = sn.y;     for (int i = 1; i < length - 1; i++) {       xx += dx[tran[body & 3]];       yy += dy[tran[body & 3]];       body >>= 2;       if (x == xx && y == yy) return true;     }     return false;   }   int BFS() {     queue<pair<snake, int>> Q;     Q.push({start, 0});     visit[start.x][start.y][start.body] = 1;     while (!Q.empty()) {       snake nowsnake = Q.front().first;       int nowstep = Q.front().second;       if (s[nowsnake.x][nowsnake.y] ==  @ ) return nowstep;       Q.pop();       for (int i = 0; i < 4; i++) {         int nextx = nowsnake.x + dx[i];         int nexty = nowsnake.y + dy[i];         if (in(nextx, nexty) && s[nextx][nexty] !=  #  &&             !collision(nextx, nexty, nowsnake)) {           snake nextsnake;           nextsnake.x = nextx;           nextsnake.y = nexty;           nextsnake.body = ((nowsnake.body << 2) & startbody) | i;           if (!visit[nextsnake.x][nextsnake.y][nextsnake.body]) {             visit[nextsnake.x][nextsnake.y][nextsnake.body] = true;             Q.push({nextsnake, nowstep + 1});           }         }       }     }     return -1;   }   int main() {     cin >> n >> m;     for (int i = 0; i < n; i++) cin >> s[i];     length = 0;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (s[i][j] !=  #  && s[i][j] !=  @  && s[i][j] !=  . ) {           if (s[i][j] ==  1 ) {             start.x = i;             start.y = j;           }           if (s[i][j] -  0  > length) {             backx = i;             backy = j;             length = s[i][j] -  0 ;           }         }       }     }     startbody = (1 << ((length - 1) * 2)) - 1;     status = 0;     while (s[backx][backy] !=  1 ) {       for (int i = 0; i < 4; i++) {         int newbackx = backx + dx[i];         int newbacky = backy + dy[i];         if (in(newbackx, newbacky) &&             s[newbackx][newbacky] + 1 == s[backx][backy]) {           status <<= 2;           status |= i;           backx = newbackx;           backy = newbacky;           break;         }       }     }     start.body = status;     cout << BFS() << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 100005;   int a[N], n, i, k, j, c, p, b[N], m, r, t, check, mr;   struct tree {     int data = 0;     int rank = 1;   } * ROOT[N], *f[N];   vector<int> leafs;   void push(tree*& node, int number) {     tree* child = new tree();     child->data = number;     child->rank = node->rank + 1;     f[number] = child;     if (leafs.size()) {       for (int it = leafs.size() - 1; it >= 0; it--) {         if (leafs[it] == node->data) {           leafs.erase(leafs.begin() + it);           break;         }       }     }     leafs.push_back(number);     c = max(c, child->rank);   };   int main() {     cin >> n;     for (i = 0; i < n; i++) cin >> a[i];     for (i = 0; i < n; i++) {       if (a[i] > m) {         j++;         ROOT[j] = new tree();         ROOT[j]->data = a[i];         m = a[i];         if (leafs.size()) leafs.clear();         continue;       }       if (a[i] > a[i - 1]) {         if (!leafs.size()) {           push(ROOT[j], a[i]);           continue;         } else {           r = 0;           mr = 0;           check = 0;           for (int it = leafs.size() - 1; it >= 0; it--) {             if (f[leafs[it]]->rank < r) leafs.erase(leafs.begin() + it);             if (mr <= f[leafs[it]]->rank) {               if (leafs[it] < a[i]) {                 if (f[leafs[it]]->rank > r) {                   r = f[leafs[it]]->rank;                   t = leafs[it];                   check = 1;                 }               }             }             mr = max(mr, f[leafs[it]]->rank);           }           if (check)             push(f[t], a[i]);           else             push(ROOT[j], a[i]);         }       } else {         c = max(c, 1);       }     }     if (c)       cout << c;     else       cout << 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long OO = (long long)1e15;   const double EPS = 1e-11;   vector<vector<pair<long long, int> > > adj;   vector<vector<long long> > ar;   vector<vector<long long> > dep;   long long nxt(int node, long long time) {     int idx =         lower_bound(ar[node].begin(), ar[node].end(), time) - ar[node].begin();     if (idx >= (int)ar[node].size() || ar[node][idx] != time) return 0;     return dep[node][idx] - time;   }   long long dij(int src, int d, int len) {     priority_queue<pair<long long, int>, vector<pair<long long, int> >,                    greater<pair<long long, int> > >         q;     long long cst = nxt(src, 0);     q.push(make_pair((cst), (src)));     vector<long long> dest(len, OO);     dest[src] = q.top().first;     while (!q.empty()) {       int n = q.top().second;       long long c = q.top().first;       q.pop();       if (c != dest[n]) continue;       if (n == d) return c;       for (int i = 0; i < (int)adj[n].size(); ++i) {         int tn = adj[n][i].second;         long long tc = adj[n][i].first;         long long nc = c + tc + ((tn == d) ? 0 : nxt(tn, c + tc));         if (nc < dest[tn]) {           dest[tn] = nc;           q.push(make_pair((dest[tn]), (tn)));         }       }     }     return -1;   }   int main() {     int n, m, a, b, k;     cin >> n >> m;     adj.clear();     adj.resize(n);     long long c;     for (int i = 0; i < m; ++i) {       cin >> a >> b >> c;       a--, b--;       adj[a].push_back(make_pair((c), (b)));       swap(a, b);       adj[a].push_back(make_pair((c), (b)));     }     ar.clear();     dep.clear();     ar.resize(n);     dep.resize(n);     for (int i = 0; i < n; ++i) {       cin >> k;       if (k == 0) continue;       ar[i].resize(k);       dep[i].resize(k);       for (int j = 0; j < k; ++j) {         cin >> ar[i][j];       }       dep[i][k - 1] = ar[i][k - 1] + 1;       for (int j = k - 2; j >= 0; --j) {         if (ar[i][j] + 1 != ar[i][j + 1])           dep[i][j] = ar[i][j] + 1;         else           dep[i][j] = dep[i][j + 1];       }     }     cout << dij(0, n - 1, n) << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long M = 1e9 + 7;   const long long N = 1e6 + 7;   long long a[N];   long long n;   long long res = 0;   long long par[N];   long long sz[N];   long long findpar(long long v) {     if (par[v] == v) return v;     return par[v] = findpar(par[v]);   }   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n;     for (long long i = 1; i <= n; i++) {       cin >> a[i];       par[i] = i;       sz[i] = 1;     }     vector<pair<long long, pair<long long, long long> > > vec;     for (long long i = 1; i < n; i++) {       long long v, u;       cin >> v >> u;       vec.push_back({max(a[v], a[u]), {v, u}});     }     sort(vec.begin(), vec.end());     for (auto pr : vec) {       long long x = pr.first;       long long v = findpar(pr.second.first);       long long u = findpar(pr.second.second);       res += sz[v] * sz[u] * x;       par[v] = u;       sz[u] += sz[v];     }     for (long long i = 0; i < vec.size(); i++)       vec[i].first = -1 * (min(a[vec[i].second.first], a[vec[i].second.second]));     sort(vec.begin(), vec.end());     for (long long i = 1; i <= n; i++) {       par[i] = i;       sz[i] = 1;     }     for (auto pr : vec) {       long long x = pr.first;       long long v = findpar(pr.second.first);       long long u = findpar(pr.second.second);       res += sz[v] * sz[u] * x;       par[v] = u;       sz[u] += sz[v];     }     cout << res;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int i, j, k, l, n;     cout.precision(10);     {       cin >> n >> k;       if (n <= k / 2)         cout <<  YES               <<   n ;       else {         cout <<  NO               <<   n ;         return 0;       }       for (i = 0; i < n - 1; i++) {         cout <<  1  ;       }       cout << k - (n - 1) <<   n ;       cout << k / 2 <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int C[200005], A[200005], n, k, i, j, mx;   int main() {     scanf( %d%d%d , &n, &i, &k);     for (i = 1; i <= n; i++) scanf( %d , &A[i]);     for (i = j = 1; i <= n; i++) {       while (j - i + 1 - C[A[i]] - (A[j] == A[i]) <= k && j <= n) {         C[A[j]]++;         j++;       }       if (j - i - C[A[i]]-- <= n) mx = max(mx, C[A[i]] + 1);     }     printf( %d , mx);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   unsigned long long n, a = 1, b = 1, mod = 1000000007, pp = 1000000005;   unsigned long long fp(unsigned long long n, unsigned long long p) {     if (p == 0) return 1;     if (p == 1) return n;     unsigned long long res;     res = fp(n, p / 2) % mod;     res = (res * res) % mod;     if (p % 2) res = (res * n) % mod;     return res % mod;   }   long long solve(long long n, long long m) {     unsigned long long a = 1, b = 1, res;     for (int i = 1; i <= m; i++) {       a *= n;       a %= mod;       n--;       b *= i;       b %= mod;     }     res = (a * fp(b, pp) % mod) % mod;     return res;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0), cout.tie(0);     ios_base::sync_with_stdio(0);     ;     cin >> n;     unsigned long long ans = solve(2 * n, n);     cout << (ans % mod - n) % mod <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool isrange(int second, int first, int n, int m) {     if (0 <= second && second < n && 0 <= first && first < m) return true;     return false;   }   int dy[4] = {1, 0, -1, 0}, dx[4] = {0, 1, 0, -1},       ddy[8] = {1, 0, -1, 0, 1, 1, -1, -1}, ddx[8] = {0, 1, 0, -1, 1, -1, 1, -1};   const int MAX = 101010;   long long int a[6], arr[MAX];   vector<pair<long long int, int> > v;   vector<int> tmp;   int num[MAX], start = 1;   long long int seg[MAX * 4];   multiset<long long int> s[MAX];   long long int getn(int l, int r) {     l += start;     r += start;     long long int ans = 0;     while (l <= r) {       if (l % 2) {         ans = max(ans, seg[l]);         l++;       }       if ((r % 2) == 0) {         ans = max(ans, seg[r]);         r--;       }       l /= 2;       r /= 2;     }     return ans;   }   void upd(int first, long long int second) {     first += start;     seg[first] = second;     for (int e = (first / 2); e >= 1; e /= 2)       seg[e] = max(seg[e * 2], seg[e * 2 + 1]);   }   void del(int first) {     long long int second = *s[first].begin();     s[first].erase(s[first].lower_bound(second));     second = *s[first].begin();     upd(first, second);   }   int main(void) {     while (start < MAX) start *= 2;     for (int e = 0; e < 6; e++) scanf( %lld , &a[e]);     int n;     scanf( %d , &n);     for (int e = 0; e < n; e++) {       long long int r;       scanf( %lld , &r);       for (int p = 0; p < 6; p++) {         v.push_back(make_pair(r - a[p], e));         s[e].insert(r - a[p]);       }     }     if (n == 1) return !printf( 0 );     for (int e = 0; e < n; e++) {       long long int first = *s[e].begin();       upd(e, first);     }     sort(v.begin(), v.end());     memset(num, 0, sizeof(num));     long long int ans = 1e18, lx = 0;     for (int e = 0; e < (int)v.size(); e++) {       if (lx != v[e].first) {         bool suc = false;         for (int p = 0; p < (int)tmp.size(); p++) {           num[tmp[p]]++;           if (num[tmp[p]] == 6) {             suc = true;             break;           }           del(tmp[p]);         }         if (suc) break;         tmp.clear();       }       long long int vv = 0;       if (0 <= v[e].second - 1) vv = max(vv, getn(0, v[e].second - 1));       if (v[e].second + 1 < n) vv = max(vv, getn(v[e].second + 1, n - 1));       ans = min(ans, vv - v[e].first);       tmp.push_back(v[e].second);       lx = v[e].first;     }     printf( %lld , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     scanf( %d , &n);     int len = 0, x, pre;     long long ans = 0LL;     for (int i = 0; i < n; i++) {       scanf( %d , &x);       if (i != 0) {         if (pre == x) {           len++;         } else {           ans += 1LL * (len + 1) * len / 2;           len = 1;         }       } else         len = 1;       pre = x;     }     ans += 1LL * (len + 1) * len / 2;     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void dfs(int u, int p[], bool mark[]) {     mark[u] = true;     if (mark[p[u]]) return;     dfs(p[u], p, mark);   }   int main() {     int result = 0, cycle = 0;     int n;     cin >> n;     int p[n + 1], b[n + 1], f = 0;     bool mark[n + 1];     for (int i = 1; i <= n; i++) {       cin >> p[i];       mark[i] = false;     }     for (int i = 1; i <= n; i++) {       cin >> b[i];       f += b[i];     }     if (f % 2 == 0) result++;     for (int i = 1; i <= n; i++) {       if (!mark[i]) {         dfs(i, p, mark);         cycle++;       }     }     if (cycle > 1) result += cycle;     cout << result << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline bool upmin(T &x, T y) {     return y < x ? x = y, 1 : 0;   }   template <typename T>   inline bool upmax(T &x, T y) {     return x < y ? x = y, 1 : 0;   }   const long double eps = 1e-15;   const long double pi = acos(-1);   const long long oo = 1 << 30;   const long long loo = 1ll << 62;   const long long mods = 1e9 + 7;   const long long MAXN = 100005;   const long long INF = 0x7fffffff;   inline long long read() {     long long f = 1, x = 0;     char c = getchar();     while (c <  0  || c >  9 ) {       if (c ==  - ) f = -1;       c = getchar();     }     while (c >=  0  && c <=  9 ) {       x = (x << 3) + (x << 1) + (c ^ 48);       c = getchar();     }     return x * f;   }   double mx[MAXN], mn[MAXN], smx[MAXN], smn[MAXN], sp[MAXN], sq[MAXN];   signed main() {     long long n = read();     for (long long i = 1; i <= n; i++) scanf( %lf , &mx[i]);     for (long long i = 1; i <= n; i++) scanf( %lf , &mn[i]);     for (long long i = 1; i <= n; i++) smx[i] = smx[i - 1] + mx[i];     for (long long i = n; i >= 1; i--) smn[i] = smn[i + 1] + mn[i];     for (long long i = 1; i <= n; i++) {       double pl = 1 + smx[i] - smn[i + 1], mul = smx[i],              mi = sqrt(pl * pl - mul * 4 + eps);       sp[i] = (pl + mi) * 0.5, sq[i] = (pl - mi) * 0.5;     }     for (long long i = 1; i <= n; i++) printf( %.10lf  , sp[i] - sp[i - 1]);     puts(  );     for (long long i = 1; i <= n; i++) printf( %.10lf  , sq[i] - sq[i - 1]);     puts(  );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<pair<int, int> > v;   bool cmp(pair<int, int> a, pair<int, int> b) {     if (a.first == b.first) {       return a.second < b.second;     }     return a.first > b.first;   }   int main() {     string s;     int n, m;     cin >> n >> m;     cin >> s;     char ara[m + 1], ara1[m + 1];     for (int i = 0; i < m; i++) {       char x, y;       cin >> x >> y;       ara[i] = x;       ara1[i] = y;     }     char str[27], str1[27];     int j = 0;     for (char ch =  a ; ch <=  z ; ch++) {       char ch1;       ch1 = ch;       int f = 0;       for (int i = 0; i < m; i++) {         if (ara[i] == ch1) {           str[j] = ara1[i];           ch1 = ara1[i];           f = 1;         } else if (ara1[i] == ch1) {           str[j] = ara[i];           ch1 = ara[i];           f = 1;         }       }       if (f == 1) {         str1[j] = ch;         j++;       }       f = 0;     }     str[j] =   0 ;     str1[j] =   0 ;     string st = (string)str;     string st1 = (string)str1;     int l1 = st1.size();     for (int j = 0; j < n; j++) {       for (int i = 0; i < l1; i++) {         if (s[j] == st1[i]) {           s[j] = st[i];           break;         }       }     }     cout << s;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, k;   int x[100000], y[100000], xx[100000], yy[100000];   int ord[100000];   vector<int> inds;   inline bool cmpx(const int &lhs, const int &rhs) { return x[lhs] < x[rhs]; }   inline bool cmpy(const int &lhs, const int &rhs) { return y[lhs] < y[rhs]; }   vector<int> xs, ys;   void sortUnique(vector<int> &inds) {     sort(inds.begin(), inds.end());     inds.erase(unique(inds.begin(), inds.end()), inds.end());   }   int main() {     scanf( %d%d , &n, &k);     for (int i = 0; i < (int)(n); ++i)       scanf( %d%d%d%d , x + i, y + i, xx + i, yy + i), x[i] += xx[i],           y[i] += yy[i];     for (int i = 0; i < (int)(n); ++i) ord[i] = i;     sort(ord, ord + n, cmpx);     for (int i = 0; i < (int)(k + 1); ++i) inds.push_back(ord[i]);     for (int i = 0; i < (int)(k + 1); ++i) inds.push_back(ord[n - 1 - i]);     for (int i = 0; i < (int)(n); ++i) ord[i] = i;     sort(ord, ord + n, cmpy);     for (int i = 0; i < (int)(k + 1); ++i) inds.push_back(ord[i]);     for (int i = 0; i < (int)(k + 1); ++i) inds.push_back(ord[n - 1 - i]);     sortUnique(inds);     for (int ind : inds) xs.push_back(x[ind]), ys.push_back(y[ind]);     sortUnique(xs);     sortUnique(ys);     int xsz = (int)xs.size();     int ysz = (int)ys.size();     long long ans = 2e18;     for (int i = 0; i < (int)(xsz); ++i)       for (int j = i; j < xsz; ++j) {         int cnt = j - i + 1;         if (xsz - cnt > k) continue;         int xbeg = xs[i], xed = xs[j];         for (int ii = 0; ii < (int)(ysz); ++ii)           for (int jj = ii; jj < ysz; ++jj) {             cnt = jj - ii + 1;             if (ysz - cnt > k) continue;             int ybeg = ys[ii], yed = ys[jj];             int bad = 0;             for (int ind : inds)               if (x[ind] < xbeg || x[ind] > xed || y[ind] < ybeg ||                   y[ind] > yed) {                 ++bad;               }             if (bad <= k) {               long long dx = ((long long)xed - xbeg + 1) / 2;               long long dy = ((long long)yed - ybeg + 1) / 2;               if (dx <= 0) dx = 1;               if (dy <= 0) dy = 1;               ans = min(ans, (long long)dx * dy);             }           }       }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   int main() {     int n, k;     cin >> n >> k;     cout << k * (6 * (n - 1) + 5) << endl;     for (int i = 1; i <= n; i++) {       printf( %d %d %d %d n , k * (6 * (i - 1) + 1), k * (6 * (i - 1) + 2),              k * (6 * (i - 1) + 3), k * (6 * (i - 1) + 5));     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   class fenwickTree {    public:     int* tree;     int size;     int prefixSum(int index) {       index++;       int ret = 0;       while (index > 0) {         ret += tree[index];         index -= (index & -index);       }       return ret;     }     void update(int index, int delta) {       index++;       while (index <= size) {         tree[index] += delta;         index += (index & -index);       }     }     int rangeSum(int left, int right) {       return prefixSum(right) - prefixSum(left - 1);     }     fenwickTree(int n) {       size = n;       tree = new int[size + 1];       memset(tree, 0, sizeof(int) * (size + 1));     }   };   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       fenwickTree tree(n + 1);       int cts[n + 1];       memset(cts, 0, sizeof cts);       long long invert = 0;       bool ok = false;       for (int i = 0; i < n; i++) {         int w;         cin >> w;         cts[w]++;         if (cts[w] == 2) ok = true;         tree.update(w, 1);         invert += tree.rangeSum(w + 1, n);       }       if (invert & 1 && !ok)         cout <<  NO n ;       else         cout <<  YES n ;     }   }