malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int MAX_N = 1000000;   struct UnionFind {     int par[MAX_N], ra[MAX_N];     void init(int n) {       for (int(i) = 0; (i) < (n); (i)++) par[i] = i, ra[i] = 0;     }     int find(int x) { return par[x] == x ? x : par[x] = find(par[x]); }     bool same(int x, int y) { return find(x) == find(y); }     void unite(int x, int y) {       if ((x = find(x)) != (y = find(y))) {         if (ra[x] < ra[y]) swap(x, y);         par[y] = x, ra[x] += (ra[x] == ra[y]);       }     }   };   long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   long long A, B;   string a, b;   int pp[1000000][26];   int sz[1000000];   UnionFind uf;   int main() {     scanf( %I64d%I64d , &A, &B);     cin >> a >> b;     long long al = a.size(), bl = b.size();     long long st = al * bl;     st /= gcd(al, bl);     uf.init(al);     for (int(i) = 0; (i) < (al); (i)++) uf.unite(i, (i + bl) % al);     for (int(i) = 0; (i) < (al); (i)++) {       int ns = uf.find(i);       pp[ns][a[i] -  a ]++;       sz[ns]++;     }     long long ans = 0;     for (int(i) = 0; (i) < (bl); (i)++) {       int ns = uf.find(i % al);       for (int(j) = 0; (j) < (26); (j)++)         if (j != b[i] -  a ) ans += pp[ns][j];     }     long long kkd = A * al / st;     cout << ans * kkd << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 10010;   vector<int> v[MAXN];   int childcnt[MAXN] = {0};   int main() {     int n;     cin >> n;     for (int i = 1; i < n; i++) {       int a, b;       scanf( %d%d , &a, &b);       v[a].push_back(b);       v[b].push_back(a);     }     int root = 0;     for (int i = 1; i <= n; i++) {       if (v[i].size() == 1) {         root = i;         break;       }     }     bool vis[MAXN];     memset(vis, false, sizeof(vis));     queue<int> q;     q.push(root);     vis[root] = true;     int deep = 0;     long long ans = 0;     while (!q.empty()) {       childcnt[deep++] = q.size();       queue<int> p;       while (!q.empty()) {         int cur = q.front();         q.pop();         int len = v[cur].size();         int cnt = 0;         for (int i = 0; i < len; i++) {           if (!vis[v[cur][i]]) {             vis[v[cur][i]] = true;             p.push(v[cur][i]);             cnt++;           }         }         ans += (cnt - 1) * cnt / 2;       }       q = p;     }     for (int i = 2; i < deep; i++) {       ans += childcnt[i];     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   const long long LINF = (long long)1e18;   const long double PI = acos((long double)-1);   const long double EPS = 1e-9;   inline long long gcd(long long a, long long b) {     long long r;     while (b) {       r = a % b;       a = b;       b = r;     }     return a;   }   inline long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }   inline long long fpow(long long n, long long k, int p = MOD) {     long long r = 1;     for (; k; k >>= 1) {       if (k & 1) r = r * n % p;       n = n * n % p;     }     return r;   }   inline long long isqrt(long long k) {     long long r = sqrt(k) + 1;     while (r * r > k) r--;     return r;   }   inline long long icbrt(long long k) {     long long r = cbrt(k) + 1;     while (r * r * r > k) r--;     return r;   }   inline int inv(int a, int p = MOD) { return fpow(a, p - 2, p); }   inline int sign(long double x) { return x < -EPS ? -1 : x > +EPS; }   inline int sign(long double x, long double y) { return sign(x - y); }   template <class T>   void dbv(T a) {     for (auto x : a) {       cout << x <<   **  ;     }     cout << endl;   }   long long calc(long long in, vector<long long> &a) {     priority_queue<long long> pq;     long long cum = in;     long long cnt = 0;     long long n = a.size();     for (int i = (0); i < (n); ++i) {       pq.push(-a[i]);       cum += a[i];       if (cum < 0) {         cum += pq.top();         pq.pop();         cnt++;       }     }     return cnt;   }   void output() {     long long n, q;     cin >> n >> q;     vector<long long> a(n);     for (int i = (0); i < (n); ++i) {       cin >> a[i];     }     long long st = calc(0, a);     vector<long long> lims;     lims.push_back(0);     for (int val = (st - 1); val >= (0); --val) {       long long low = lims[st - val - 1] + 1;       long long high = LINF;       while (low < high) {         long long mid = (low + high) / 2;         if (calc(mid, a) <= val)           high = mid;         else           low = mid + 1;       }       lims.push_back(low);     }     lims.push_back(1e18);     for (int i = (0); i < (q); ++i) {       long long qu;       cin >> qu;       long long low = 0;       long long high = st + 1;       while (low < high) {         long long mid = (low + high) / 2;         if (qu < lims[mid])           high = mid;         else           low = mid + 1;       }       cout << (st - (low - 1)) << endl;     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long t = 1;     for (int i = (0); i < (t); ++i) {       output();     }     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( Ofast,no-stack-protector,unroll-loops,fast-math,O3 )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native )   using namespace std;   long long n, k, ans, pw[11], a[200005];   map<int, int> w[11];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     cout.precision(30);     cerr.precision(7);     ;     cin >> n >> k;     pw[0] = 1LL;     for (int i = 1; i <= 10; i++) pw[i] = (pw[i - 1] * 10LL) % k;     for (int i = 1; i <= n; i++) {       cin >> a[i];       for (int j = 1; j <= 10; j++) w[j][(a[i] * pw[j]) % k]++;     }     for (int i = 1; i <= n; i++) {       int l = (int)to_string(a[i]).size();       ans += w[l][(k - (a[i] % k)) % k];       ans -= !(((pw[l] * a[i]) % k + a[i]) % k);     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   long long m, n, f[22], inv[22];   inline long long read() {     long long s = 0, f = 1;     char c = getchar();     while (c <  0  || c >  9 ) {       if (c ==  - ) {         f = -1;       }       c = getchar();     }     while (c >=  0  && c <=  9 ) {       s = (s << 1) + (s << 3) + c -  0 ;       c = getchar();     }     return s * f;   }   inline void write(long long x) {     if (x < 0) {       x = ~(x - 1);       putchar( - );     }     if (x > 9) {       write(x / 10);     }     putchar(x % 10 +  0 );   }   long long power(long long a, long long p) {     long long res = 1;     while (p) {       if (p & 1) res *= a, res %= mod;       p >>= 1;       a *= a;       a %= mod;     }     return res;   }   long long c(long long n, long long m) {     if (n < m || n < 0 || m < 0) {       return 0;     }     n %= mod;     if (n == 0 || m == 0) {       return 1;     }     long long res = 1;     for (long long i = 0; i < m; i++) {       res *= n - i, res %= mod;     }     for (long long i = 1; i <= m; i++) {       res *= inv[i], res %= mod;     }     return res;   }   signed main() {     n = read(), m = read();     for (long long i = 1; i <= n; i++) {       f[i] = read();     }     for (long long i = 1; i <= 20; i++) {       inv[i] = power(i, mod - 2);     }     long long ans = 0;     for (long long i = 1; i < (1 << n); i++) {       long long t = n + m - 1, bit = 0;       for (long long j = 0; j < n; j++) {         if (i & (1 << j)) {           t -= f[j + 1] + 1;           bit++;         }       }       if (bit % 2 == 1) {         ans = (ans + c(t, n - 1)) % mod;       } else {         ans = (ans - c(t, n - 1)) % mod;       }     }     cout << (c(n + m - 1, n - 1) - ans + mod) % mod << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   inline void chkmin(T &a, T b) {     if (a > b) a = b;   }   template <class T>   inline void chkmax(T &a, T b) {     if (a < b) a = b;   }   double fail[310][3100], p[310][3100], val[310], nf[3100];   int main() {     int N, M, i, j, u;     double res;     scanf( %d%d , &N, &M);     for (i = 1; i <= N; i++)       for (j = 1; j <= M; j++) {         scanf( %lf , &p[j][i]);         p[j][i] /= 1000;       }     for (i = 1; i <= M; i++) {       fail[i][0] = 1;       for (j = 1; j <= N; j++) {         fail[i][j] = fail[i][j - 1] * (1 - p[i][j]);       }       val[i] = 1 - fail[i][N];     }     res = 0;     for (i = 1; i <= N; i++) {       u = max_element(val, val + M + 1) - val;       res += val[u];       for (j = 1; j <= N; j++)         nf[j] = nf[j - 1] * (1 - p[u][j]) + fail[u][j - 1] * p[u][j];       memcpy(fail[u], nf, sizeof(nf));       val[u] -= nf[N];     }     printf( %.15lf n , res);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int s[1001000];   int g[1001000];   int ans[1001000];   int main() {     int n;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> s[i] >> g[i];       ans[i] = 1001000;     }     ans[0] = s[0] + g[0];     for (int i = 0; i < n - 1; i++) {       ans[i + 1] = min(g[i + 1] + s[i + 1], ans[i] + 1);     }     for (int i = n - 1; i > 0; i--) {       ans[i - 1] = min(ans[i] + 1, ans[i - 1]);     }     long long sum = 0;     for (int i = 0; i < n; i++) {       sum += ans[i] - s[i];       if (ans[i] < s[i]) {         cout << -1;         return 0;       }     }     cout << sum << endl;     for (int i = 0; i < n; i++) {       cout << ans[i] <<    ;     }     return 0;   }
#include <bits/stdc++.h>   const long long int N = 2e5 + 5;   using namespace std;   int main() {     ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);     long long int x, y, a, b;     cin >> x >> y >> a >> b;     vector<pair<long long int, long long int>> mp;     for (int i = a; i <= x; i++) {       for (int j = b; j <= y; j++) {         if (i <= j)           continue;         else {           mp.push_back({i, j});         }       }     }     cout << mp.size() << endl;     for (int i = 0; i < mp.size(); i++) {       cout << mp[i].first <<     << mp[i].second << endl;     }   }
#include <bits/stdc++.h>   char s[100001];   int main() {     int n;     int i, j;     scanf( %s , s);     n = strlen(s);     for (i = 0; i < n; i++)       if (s[i] ==  0 ) break;     if (i == n) {       for (j = 0; j < n - 1; j++) printf( %c , s[j]);       printf(  n );     } else {       for (j = 0; j < i; j++) printf( %c , s[j]);       for (j = i + 1; j < n; j++) printf( %c , s[j]);       printf(  n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 105555;   int a[N];   int main() {     int n;     scanf( %d , &n);     int mn = 1e7, mi, mx = -1e7, xi;     for (int i = 0; i < n; ++i) {       scanf( %d , a + i);       if (i > 1 && xi < i - 1 && mx > a[i - 1] && a[i - 1] < a[i]) {         printf( 3 n%d %d %d n , xi + 1, i, i + 1);         return 0;       }       if (i > 1 && mi < i - 1 && mn < a[i - 1] && a[i - 1] > a[i]) {         printf( 3 n%d %d %d n , mi + 1, i, i + 1);         return 0;       }       if (a[i] > mx) {         mx = a[i];         xi = i;       }       if (a[i] < mn) {         mn = a[i];         mi = i;       }     }     puts( 0 );   }
#include <bits/stdc++.h>   using namespace std;   set<long long int> blacklist;   long long int par(long long int* parent, long long int f, long long int n) {     if (parent[f] < 0) return parent[f];     if (parent[f] == f)       return f;     else {       parent[f] = par(parent, parent[f], n);       return parent[f];     }   }   void unio(long long int* parent, long long int f, long long int s,             long long int pf, long long int ps) {     if (pf < ps)       parent[ps] = pf;     else       parent[pf] = ps;   }   void utilfun(long long int* parent, vector<long long int>* adj,                pair<long long int, long long int>* edge, long long int n,                long long int m, long long int a, long long int b) {     for (long long int i = 0; i < m; i++) {       long long int f = edge[i].first;       long long int s = edge[i].second;       if (f == a || f == b || s == a || s == b) {         continue;       } else {         long long int pf = par(parent, f, n);         long long int ps = par(parent, s, n);         unio(parent, f, s, pf, ps);       }     }     long long int ind = -2;     for (long long int i = 0; i < m; i++) {       long long int f = edge[i].first;       long long int s = edge[i].second;       if ((f == a || s == a) && (s != b && f != b)) {         long long int ot = f + s - a;         long long int pot = par(parent, ot, n);         if (pot >= 0) {           parent[pot] = ind;           ind--;         }       }     }     for (long long int i = 0; i < m; i++) {       long long int f = edge[i].first;       long long int s = edge[i].second;       if ((f == b || s == b) && (s != a && f != a)) {         long long int ot = f + s - b;         long long int pot = par(parent, ot, n);         if (pot == -1) {           continue;         } else if (pot < -1) {           blacklist.insert(pot);         } else           parent[pot] = b;       }     }   }   int main() {     long long int t;     cin >> t;     while (t--) {       blacklist.clear();       long long int n, m, a, b;       cin >> n >> m >> a >> b;       a--;       b--;       vector<long long int> adj[n];       pair<long long int, long long int> edge[m];       long long int parent[n];       for (long long int i = 0; i < n; i++) parent[i] = i;       for (long long int i = 0; i < m; i++) {         long long int x, y;         cin >> x >> y;         x--;         y--;         adj[x].push_back(y);         adj[y].push_back(x);         edge[i] = {x, y};       }       utilfun(parent, adj, edge, n, m, a, b);       long long int ac = 0;       long long int bc = -1;       set<long long int>::iterator itr;       for (long long int i = 0; i < n; i++) {         long long int pot = par(parent, i, n);         if (blacklist.find(pot) != blacklist.end()) continue;         if (pot < -1)           ac++;         else if (pot == b)           bc++;       }       cout << ac * bc <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   class TaskC {    public:     void solve(std::istream& in, std::ostream& out);   };   void TaskC::solve(std::istream& in, std::ostream& out) {     int n;     in >> n;     int a[310][310];     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; ++j) {         in >> a[i][j];       }     }     int k;     in >> k;     while (k--) {       int x, y, c;       in >> x >> y >> c;       --x, --y;       a[x][y] = min(a[x][y], c);       a[y][x] = min(a[y][x], c);       for (int i = 0; i < n; ++i) {         for (int j = 0; j < n; ++j) {           a[i][j] = min(a[i][j], min(a[i][x] + a[x][y] + a[y][j],                                      a[i][y] + a[y][x] + a[x][j]));         }       }       long long ans = 0;       for (int i = 0; i < n; ++i) {         for (int j = 0; j < i; ++j) ans += (long long)a[i][j];       }       out << ans <<    ;     }   };   int main() {     TaskC solver;     std::istream& in(std::cin);     std::ostream& out(std::cout);     solver.solve(in, out);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void solve() {     long long int n, k;     cin >> n >> k;     vector<long long int> a(n);     for (long long int i = 0; i < n; i++) cin >> a[i];     long long int ans = -1e18;     for (long long int i = 0; i < n; i++) {       for (long long int j = i; j < n; j++) {         vector<long long int> in, out;         long long int sum = 0;         for (long long int k = 0; k < n; k++) {           if (k < i || k > j)             out.push_back(a[k]);           else             in.push_back(a[k]), sum += a[k];         }         sort((in).begin(), (in).end());         sort((out).rbegin(), (out).rend());         long long int l = 0, r = 0, s = k;         while (l < (long long int)in.size() && r < (long long int)out.size() &&                s-- > 0) {           if (in[l] < out[r]) sum += out[r] - in[l];           l++, r++;         }         ans = max(ans, sum);       }     }     cout << ans <<   n ;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int test_cases = 1;     while (test_cases--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int A[1111111];   int B[1111111];   int main(void) {     int alen = 0;     int blen = 0;     scanf( %d %d , &alen, &blen);     for (int i = 0; i < alen; i++) scanf( %d , &A[i]);     memset(B, -1, sizeof(B));     for (int i = 0; i < blen; i++) {       int x = 0;       scanf( %d , &x);       B[x] = i;     }     deque<int> Queue;     int ans = 0;     for (int i = 0; i < 2 * alen; i++) {       int where = B[A[i % alen]];       if (where != -1) {         while (Queue.size() >= 2 &&                !((Queue.front() < Queue.back() &&                   (Queue.back() < where || where < Queue.front())) ||                  (Queue.front() > Queue.back() && Queue.back() < where &&                   where < Queue.front())))           Queue.pop_front();         Queue.push_back(where);       } else         Queue.clear();       ans = max<int>(ans, Queue.size());     }     ans = min(ans, alen);     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   const int N = 3e4 + 10;   long long ri() {     char c = getchar();     long long x = 0, f = 1;     for (; c <  0  || c >  9 ; c = getchar())       if (c ==  - ) f = -1;     for (; c >=  0  && c <=  9 ; c = getchar()) x = (x << 1) + (x << 3) -  0  + c;     return x * f;   }   long long len[66];   int n, d, m, tot, gen[25], b[N];   std::bitset<N> all;   struct info {     long long ans, len;     std::bitset<N> pre, suf;     info operator+(const info &b) {       info c;       c.ans = ans + b.ans;       c.len = len + b.len;       c.pre = pre;       c.suf = b.suf;       if (len < n - 1) c.pre &= (b.pre << len) | (all >> n - 1 - len);       if (b.len < n - 1) c.suf &= (suf >> b.len) | (all << n - 1 - b.len);       if (len + b.len >= n) {         std::bitset<N> res = suf & b.pre;         if (len < n - 1) res &= (all << n - 1 - len);         if (b.len < n - 1) res &= (all >> n - 1 - b.len);         c.ans += res.count();       }       return c;     }     void operator+=(const info &b) { *this = !len ? b : *this + b; }   } f[66][66];   long long Query(long long x) {     info res;     res.ans = res.len = 0;     int add = 0;     for (int i = tot; ~i; --i)       for (int j = 1; j <= d; ++j) {         if (x >= len[i]) {           x -= len[i];           res += f[i][(add + gen[j]) % m];         } else {           (add += gen[j]) %= m;           break;         }       }     return res.ans;   }   int main() {     d = ri();     m = ri();     for (int i = 1; i <= d; ++i) gen[i] = ri();     n = ri();     for (int i = 1; i <= n; ++i) b[i] = ri();     for (int i = 1; i < n; ++i) all.set(i);     len[tot = 0] = 1;     for (int i = 0; i < m; ++i) {       f[0][i].len = 1;       if (n == 1)         f[0][i].ans = i <= b[1];       else {         for (int j = 1; j <= n - 1; ++j) {           f[0][i].pre[j] = i <= b[n - j + 1];           f[0][i].suf[j] = i <= b[n - j];         }       }     }     long long L = ri(), R = ri();     for (; len[tot] <= R / d;) {       ++tot;       len[tot] = len[tot - 1] * d;       for (int i = 0; i < m; ++i)         for (int j = 1; j <= d; ++j) f[tot][i] += f[tot - 1][(i + gen[j]) % m];     }     printf( %lld n , Query(R) - Query(L + n - 2));     return 0;   }
#include <bits/stdc++.h>   using namespace std;   class Solution {    public:     int n, m;     std::vector<int> r;     std::vector<std::vector<int>> d;     std::vector<std::vector<std::array<int, 2>>> v;     std::vector<bool> visited;     std::vector<int> val;     void dfs(int cur, int col) {       visited[cur] = true;       val[cur] = col;       for (auto next : v[cur]) {         if (visited[next[0]]) continue;         dfs(next[0], col ^ next[1]);       }     }     void solve(std::istream& in, std::ostream& out) {       in >> n >> m;       r.resize(n);       d.resize(n);       for (auto& el : r) in >> el;       for (int i = 0; i < m; ++i) {         int x;         in >> x;         for (int j = 0; j < x; ++j) {           int a;           in >> a;           --a;           d[a].push_back(i);         }       }       v.resize(m);       val.resize(m);       for (int i = 0; i < n; ++i) {         v[d[i][0]].push_back({d[i][1], !r[i]});         v[d[i][1]].push_back({d[i][0], !r[i]});       }       visited.resize(m);       for (int i = 0; i < m; ++i) {         if (!visited[i]) {           dfs(i, 0);         }       }       for (int i = 0; i < n; ++i)         if ((val[d[i][0]] ^ val[d[i][1]]) != (!r[i])) return void(out <<  NO n );       out <<  YES n ;     }   };   void solve(std::istream& in, std::ostream& out) {     out << std::setprecision(12);     Solution solution;     solution.solve(in, out);   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     istream& in = cin;     ostream& out = cout;     solve(in, out);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long N = 1e5;   long long pref1[N + 5];   long long pref2[N + 5];   long long ans;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int n, m, type, l, r;     cin >> n;     n++;     int arr[n];     for (int i = 1; i < n; i++) {       cin >> arr[i];       pref1[i] = pref1[i - 1] + arr[i];     }     sort(arr + 1, arr + n);     for (int i = 1; i < n; i++) pref2[i] = pref2[i - 1] + arr[i];     cin >> m;     while (m--) {       cin >> type >> l >> r;       if (type == 1)         ans = pref1[r] - pref1[l - 1];       else         ans = pref2[r] - pref2[l - 1];       cout << ans << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     scanf( %d , &n);     vector<int> a(n);     int i;     for (i = 0; i < n; i++) {       scanf( %d , &a[i]);     }     vector<int> b(n);     for (i = 0; i < n - 1; i++) {       b[i] = a[i] + a[i + 1];     }     b[n - 1] = a[n - 1];     for (i = 0; i < n; i++) {       printf( %d  , b[i]);     }     return 0;   }
#include <bits/stdc++.h>   int main() {     int t, x, i, z, n, max = 0, s = 0, a[1000], m;     scanf( %d %d , &n, &m);     for (i = 0; i < n; i++) {       scanf( %d , &a[i]);       s += a[i];       if (max < a[i]) {         max = a[i];       }     }     max = max + m;     s = s + m;     if (s % n == 0) {       x = s / n;     } else {       x = (s / n) + 1;     }     for (i = 0; i < n; i++) {       if (x < a[i]) {         x = a[i];       }     }     printf( %d %d , x, max);   }
#include <bits/stdc++.h>   using namespace std;   bool comp(string a, string b) { return (a.length() > b.length()); }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     cout.setf(ios::fixed);     cout.setf(ios::showpoint);     {       long long int n, x, y;       cin >> n >> x >> y;       long long int a[n];       for (long long int i = 0; i < n; i++) cin >> a[i];       for (long long int i = 0; i < n; i++) {         long long int c = 0;         for (long long int j = max(0LL, i - x); j < i; j++)           if (a[j] < a[i]) c++;         for (long long int j = i + 1; j < min(n, i + y + 1); j++)           if (a[j] < a[i]) c++;         if (!c) {           cout << i + 1;           break;         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   vector<int> re;   int main() {     cin >> n;     int least[n];     for (int i = 0; i < n; i++) cin >> least[i];     sort(least, least + n);     int cont = 0;     for (int i = 1; i < n; i++) {       if (least[i] == least[i - 1]) {         re.push_back(least[i]);         least[i - 1] = -1;         cont++;       } else {         cont = 0;       }       if (cont >= 2) {         cout <<  NO  << endl;         return 0;       }     }     sort(re.begin(), re.end());     cout <<  YES  << endl;     cout << n - re.size() << endl;     for (int i = 0; i < n; i++) {       if (least[i] == -1) continue;       cout << least[i] <<    ;     }     cout << endl;     cout << re.size() << endl;     for (int i = re.size() - 1; i >= 0; i--) cout << re[i] <<    ;     cout << endl;     return 0;   }