malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   #pragma comment(linker,  /stack:67108864 )   using namespace std;   template <class T>   T abs(T a) {     return (a) > 0 ? (a) : -(a);   }   template <class T>   T sqr(T a) {     return (a) * (a);   }   const long double PI = 3.1415926535897932, EPS = 1E-9;   const int INF = 1000 * 1000 * 1000, NMAX = 16;   int n, m;   int sldknfhskjdf = 0;   int a[NMAX][NMAX];   int result = 0;   int answer[NMAX][NMAX];   int dx[4][5] = {       {0, 1, 1, 1, 2}, {0, 0, 0, 1, 2}, {0, 1, 1, 1, 2}, {0, 1, 2, 2, 2}};   int dy[4][5] = {       {0, 0, 1, 2, 0}, {0, 1, 2, 1, 1}, {2, 0, 1, 2, 2}, {1, 1, 0, 1, 2}};   void brute(int x, int y) {     if (x == n) {       if (sldknfhskjdf > result) {         result = sldknfhskjdf;         memcpy(answer, a, sizeof(a));       }       return;     }     if (y >= m) {       brute(x + 1, 0);       return;     }     if (sldknfhskjdf + (m - y + m * (n - x - 1)) / 5 <= result) return;     for (int idx = 0; idx < int(4); ++idx) {       bool can = true;       for (int i = 0; i < int(5); ++i) {         int nx = x + dx[idx][i];         int ny = y + dy[idx][i];         if (nx < 0 || nx >= n || ny < 0 || ny >= m || a[nx][ny] != 0) {           can = false;           break;         }       }       if (can) {         ++sldknfhskjdf;         for (int i = 0; i < int(5); ++i) {           int nx = x + dx[idx][i];           int ny = y + dy[idx][i];           a[nx][ny] = sldknfhskjdf;         }         brute(x, y + 1);         for (int i = 0; i < int(5); ++i) {           int nx = x + dx[idx][i];           int ny = y + dy[idx][i];           a[nx][ny] = 0;         }         --sldknfhskjdf;       }     }     brute(x, y + 1);   }   int main() {     for (int i = 0; i < int(NMAX); ++i)       for (int j = 0; j < int(NMAX); ++j) {         a[i][j] = 0;       }     for (int i = 0; i < int(NMAX); ++i)       for (int j = 0; j < int(NMAX); ++j) {         answer[i][j] = 0;       }     cin >> n >> m;     const string h =          13 nA.BBB.C.. nAAABCCCD. nA.EB.FCD. nEEEFFFDDD nG.E.HFIII nGGGJHHHI.            nGK.JHL.IM n.KJJJLMMM nKKK.LLL.M n ;     if (n == 9 && m == 9) {       cout << h;       return 0;     }     brute(0, 0);     cout << result << endl;     for (int i = 0; i < int(n); ++i) {       for (int j = 0; j < int(m); ++j) {         if (answer[i][j] == 0) {           cout <<  . ;         } else {           cout << char( A  + answer[i][j] - 1);         }       }       cout << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int inf = 1e9 + 9;   int n, vl, ans, tmp[110000], ret[110000];   void redo(vector<int>& a) {     int i, j, s, p, q, nn = 0;     for (i = 0; i < a.size(); i++) {       if (nn == 0 || a[nn - 1] < a[i]) a[nn++] = a[i];     }     a.resize(nn);   }   void dfs(int id, vector<int>& a, int now) {     int i, j, s, p, q;     if (ans <= now) return;     for (i = 0; i < a.size(); i++) {       if (a[i] != 0) break;     }     if (i >= a.size()) {       ans = now;       for (i = 0; i < now; i++) ret[i] = tmp[i];       return;     }     if (id >= 18) return;     bool you = false;     for (i = 0; i < a.size(); i++) {       if (abs(a[i]) & (1 << id)) {         you = true;         break;       }     }     if (!you)       dfs(id + 1, a, now);     else {       vector<int> na;       na.resize(a.size());       tmp[now] = (1 << id);       for (i = 0; i < a.size(); i++) {         if (abs(a[i]) & (1 << id))           na[i] = a[i] - (1 << id);         else           na[i] = a[i];       }       sort(na.begin(), na.end());       redo(na);       dfs(id + 1, na, now + 1);       tmp[now] = -(1 << id);       na.resize(a.size());       for (i = 0; i < a.size(); i++) {         if (abs(a[i]) & (1 << id))           na[i] = a[i] + (1 << id);         else           na[i] = a[i];       }       sort(na.begin(), na.end());       redo(na);       dfs(id + 1, na, now + 1);     }   }   int main() {     vector<int> a;     a.clear();     scanf( %d , &n);     int i, j, s, p, q;     for (i = 0; i < n; i++) {       scanf( %d , &vl);       a.push_back(vl);     }     sort(a.begin(), a.end());     redo(a);     ans = inf;     dfs(0, a, 0);     printf( %d n , ans);     for (i = 0; i < ans; i++) printf( %d  , ret[i]);     printf(  n );     return 0;   }
#include <bits/stdc++.h>   int main() {     int T;     scanf( %d , &T);     while (T--) {       int n;       scanf( %d , &n);       int sum = 0;       for (int i = 0; i < n; i++) {         int t;         scanf( %d , &t);         if (t <= 2048) {           sum += t;         }       }       printf( %s n , sum >= 2048 ?  YES  :  NO );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     string colours;     cin >> n >> colours;     string collec[] = { RGB ,  RBG ,  BRG ,  BGR ,  GRB ,  GBR };     int index;     int max = INT_MAX;     for (int i = 0; i < 6; i++) {       int count = 0;       for (int j = 0; j < n; j++) {         if (colours[j] != collec[i][j % 3]) count++;       }       if (count < max) {         max = count;         index = i;       }     }     cout << max << endl;     for (int i = 0; i < n; i++) cout << collec[index][i % 3];   }
#include <bits/stdc++.h>   using namespace std;   string s[51];   int main() {     int tot = 1;     cin >> s[1];     int len = s[1].size();     for (int i = 2; i <= s[1].size(); i += 1) {       s[i] = s[i - 1];       string ss;       ss.resize(1);       ss[0] = s[i][len - 1];       s[i].insert(0, ss);       s[i].erase(len, 1);       int add = 1;       for (int j = 1; j < i; j += 1)         if (s[i] == s[j]) add = 0;       tot += add;     }     printf( %d , tot);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[100000];   int b[100000];   int main() {     int n, m, y0, y1;     cin >> n >> m >> y0 >> y1;     for (int x = 0; x < n; ++x) {       cin >> a[x];     }     for (int x = 0; x < m; ++x) {       cin >> b[x];     }     int i = 0, j = 0, pp = -1;     int kk = 0;     for (int x = 0; x < n; ++x) {       while (j < m && abs(a[x] - b[j + 1]) < abs(a[x] - b[j])) j++;       if (j != pp || abs(a[x] - b[j]) == abs(a[x - 1] - b[j])) {         kk++;         pp = j;       } else if (j + 1 < m && abs(a[x] - b[j]) == abs(a[x] - b[j + 1])) {         kk++;         pp = ++j;       } else         pp = j;     }     cout << n - kk << endl;   }
#include <bits/stdc++.h>   using namespace std;   int n;   char a[1005], b[1005];   int minn, maxx;   int main() {     scanf( %d , &n);     scanf( %s%s , a, b);     sort(a, a + n);     sort(b, b + n);     for (int i = 0, j = 0; i < n; i++) {       while (j < n && b[j] < a[i]) j++;       if (j < n)         j++;       else         minn++;     }     for (int i = 0, j = 0; i < n; i++) {       while (j < n && b[j] <= a[i]) j++;       if (j < n) {         maxx++;         j++;       }     }     printf( %d n%d n , minn, maxx);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       vector<int> arr(n);       map<int, int> mp;       for (int i = 0; i < n; i++) {         cin >> arr[i];         mp[arr[i]]++;       }       int ans = 0;       int ct = 0;       for (int i = 0; i <= 100; i++) {         if (ct < 2) {           if (mp[i] == 0) {             ans += (2 - ct) * i;             if (ct == 1)               ct++;             else               ct += 2;           } else if (mp[i] % 2 == 0)             continue;           else if (mp[i] == 1) {             if (ct == 1)               continue;             else {               ct++;               ans += i;             }           }         } else           break;       }       cout << ans << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int n, p;   int sum[200000];   int main() {     scanf( %d %d , &n, &p);     for (int i = 1; i <= n; ++i) {       scanf( %d , &sum[i]);       sum[i] = (sum[i - 1] + sum[i]) % p;     }     int ans = 0;     int l, r;     for (int i = 1; i < n; ++i) {       l = sum[i];       r = sum[n] - sum[i];       if (r < 0) r += p;       if (l + r > ans) ans = l + r;     }     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int order[3][4] = {{0, 1, 2, 3}, {0, 2, 3, 1}, {0, 3, 1, 2}};   long long solve(long long n) {     long long four = 1;     while (four * 4 <= n) {       four *= 4;     }     int part = (n - 1) % 3;     n -= four;     n /= 3;     long long res = four * (part + 1);     while (n > 0) {       res += order[part][n / four] * four;       n %= four;       four /= 4;     }     return res;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int tc;     long long n;     cin >> tc;     while (tc--) {       cin >> n;       long long ans = solve(n);       cout << ans <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using namespace std::chrono;   long long google_itr = 1;   const long long mod = 1e9 + 7;   const long long inf = 1e18;   void virus() {     long long len, k;     cin >> len >> k;     string seq;     cin >> seq;     long long zero = 0, one = 0;     for (auto i = 0; i < k; i++) {       long long enc = -1;       for (auto j = i; j < len; j += k) {         if (seq[j] !=  ? ) {           if (enc != -1 and seq[j] -  0  != enc) {             cout <<  NO n ;             return;           }           enc = seq[j] -  0 ;         }       }       if (enc != -1) (enc == 0) ? zero++ : one++;     }     if (one > (k / 2) or zero > (k / 2)) {       cout <<  NO n ;       return;     }     cout <<  YES n ;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long t;     cin >> t;     while (t--) {       auto start = high_resolution_clock::now();       virus();       auto stop = high_resolution_clock::now();       auto duration = duration_cast<seconds>(stop - start);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 5e3 + 3, M = 1e5 + 3;   const double eps = 1e-7;   int n, m, k, u[M], v[M], id[M];   double w[M];   bool vis[M];   struct dsu {     int fa[N];     inline void init(int range) {       for (register int i = (1); i <= (range); ++i) fa[i] = i;     }     int Fnd(int u) { return fa[u] == u ? u : fa[u] = Fnd(fa[u]); }   } D;   inline bool cmp(int A, int B) { return w[A] < w[B]; }   int res, tmp;   inline int chk(double mid) {     for (register int i = (1); i <= (m); ++i) id[i] = i, vis[i] = 0;     for (register int i = (1); i <= (m); ++i)       if (u[i] == 1 || v[i] == 1) w[i] += mid;     sort(id + 1, id + m + 1, cmp);     D.init(n);     res = 0, tmp = 0;     double val = 0;     for (register int i = (1); i <= (m); ++i) {       int Fu = D.Fnd(u[id[i]]), Fv = D.Fnd(v[id[i]]);       if (Fu == Fv) continue;       D.fa[Fu] = Fv;       vis[id[i]] = 1;       tmp++;       if (u[id[i]] == 1 || v[id[i]] == 1) {         res++;       }       if (tmp == n - 1) break;     }     for (register int i = (1); i <= (m); ++i)       if (u[i] == 1 || v[i] == 1) w[i] -= mid;     return res;   }   int main() {     scanf( %d%d%d , &n, &m, &k);     if (k == 0) {       if (n > 1)         puts( -1 );       else         puts( 0 );       return 0;     }     for (register int i = (1); i <= (m); ++i) {       static int ___;       scanf( %d%d%d , u + i, v + i, &___);       w[i] = (double)___ + eps * 1.0 * i;     }     double L = -1e7, R = 1e7, mid;     while (L + eps < R) {       mid = (L + R) / 2;       if (chk(mid) > k)         L = mid;       else         R = mid;     }     if (chk(L) != k) chk(R);     printf( %d n , n - 1);     for (register int i = (1); i <= (m); ++i)       if (vis[i]) printf( %d  , i);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int Max_N = 55;   const int dx[] = {233, 0, 0, 1, -1};   const int dy[] = {233, 1, -1, 0, 0};   namespace Disjoint_set {   int fa[Max_N * Max_N], siz[Max_N * Max_N];   int getf(int u) { return fa[u] == u ? u : fa[u] = getf(fa[u]); }   void init(int n) {     for (int i = 1; i <= n; i++) fa[i] = i, siz[i] = 1;   }   void merge(int u, int v) {     u = getf(u), v = getf(v);     if (u == v) return;     if (siz[u] > siz[v]) swap(u, v);     siz[v] += siz[u], fa[u] = v;   }   }  // namespace Disjoint_set   using namespace Disjoint_set;   int N, r1, c1, r2, c2;   char Map[Max_N][Max_N];   inline int encode(int x, int y) { return (x - 1) * N + y; }   inline bool inside(int n, int m) {     return 1 <= n && n <= N && 1 <= m && m <= N;   }   int main() {     scanf( %d , &N);     scanf( %d%d%d%d , &r1, &c1, &r2, &c2);     for (int i = 1; i <= N; i++) scanf( %s , Map[i] + 1);     init(N * N);     for (int i = 1; i <= N; i++)       for (int j = 1; j <= N; j++)         if (Map[i][j] ==  0 )           for (int k = 1; k <= 4; k++)             if (inside(i + dx[k], j + dy[k]) && Map[i + dx[k]][j + dy[k]] ==  0 )               merge(encode(i, j), encode(i + dx[k], j + dy[k]));     if (getf(encode(r1, c1)) == getf(encode(r2, c2))) return printf( %d n , 0), 0;     int Ans = 2 * N * N, f1 = getf(encode(r1, c1)), f2 = getf(encode(r2, c2));     for (int i = 1; i <= N; i++)       for (int j = 1; j <= N; j++)         if (getf(encode(i, j)) == f1)           for (int k = 1; k <= N; k++)             for (int w = 1; w <= N; w++)               if (getf(encode(k, w)) == f2)                 Ans = min(Ans, abs(i - k) * abs(i - k) + abs(j - w) * abs(j - w));     printf( %d n , Ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int conv[1000000];   int a[1000000];   int b[1000000];   int n;   int best = 0;   int d[1000000];   int main() {     ios_base::sync_with_stdio(0);     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a[i];       a[i]--;     }     for (int i = 0; i < n; i++) {       cin >> b[i];       b[i]--;     }     for (int i = 0; i < n; i++) {       conv[a[i]] = i;     }     for (int i = 0; i < n; i++) {       b[i] = conv[b[i]];     }     reverse(b, b + n);     for (int i = 0; i < n; i++) {       int l = -1;       int r = best;       while (r - l > 1) {         int mid = (r + l) >> 1;         if (d[mid] > b[i]) {           r = mid;         } else {           l = mid;         }       }       if (r == best) {         d[best++] = b[i];       } else {         d[r] = b[i];       }     }     cout << best;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[1000];   int main() {     long long p;     int k;     cin >> p >> k;     int kol = 0;     while (p > 0) {       a[kol] = kol % 2 ? (k - p % k) % k : p % k;       p = (kol % 2 ? (p + k - 1) : p) / k;       kol++;     }     if (kol % 2 == 0) {       a[kol++] = 1;     }     cout << kol << endl;     for (int i = 0; i < kol; i++) cout << a[i] <<    ;     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   map<int, int> mp;   const int N = 1e5 + 3, M = 2e5 + 3;   int b[N], st[N], tp, he[N], to[M], ne[M], d[N], a[N];   bool f[N];   void dfs(int x) {     for (int i, j; i = he[x];)       if (he[x] = ne[i], !f[j = i >> 1]) f[j] = 1, dfs(to[i]), st[++tp] = i;   }   int main() {     int m, i, j, k, n = 0, t = 1;     scanf( %d , &m), --m;     for (i = 1; i <= m; ++i)       if (scanf( %d , b + i), !mp[b[i]]) a[mp[b[i]] = ++n] = b[i];     for (i = 1; i <= m; ++i) {       scanf( %d , &j);       if (j < b[i]) puts( -1 ), exit(0);       if (!mp[j]) a[mp[j] = ++n] = j;       j = mp[j], k = mp[b[i]], ++d[j], ++d[k];       ne[++t] = he[j], to[t] = k, he[j] = t;       ne[++t] = he[k], to[t] = j, he[k] = t;     }     for (i = 1, j = 0; i <= n; ++i)       if (d[i] & 1) ++j;     if (j > 2) puts( -1 ), exit(0);     if (j == 2) {       for (i = 1; i <= n; ++i)         if (d[i] & 1) {           dfs(i);           break;         }     } else       dfs(i = 1);     if (tp < m) puts( -1 ), exit(0);     for (printf( %d  , a[i]), i = tp; i; --i) printf( %d  , a[to[st[i]]]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int r[100005], t, n, m, ans = 0;   vector<int> id[100005];   set<int> v;   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= m; i++) {       scanf( %d , &t);       v.insert(t);       id[t].push_back(i);       r[t] = max(r[t], i);     }     for (auto it : v) {       int sum = 0;       for (int i = 0; i < id[it].size() && sum < 2; i++) {         t = 0;         if (id[it][i] < r[it - 1]) t++;         if (id[it][i] < r[it + 1]) t++;         sum = max(sum, t);       }       ans += sum;     }     printf( %d n , n * 3 - 2 - ans - v.size());     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m;   int cnt;   int dfn[300005], low[300005], bel[300005], tot, scc;   bool vis[300005], ins[300005];   string ori[100005];   stack<int> s;   map<string, int> hashh;   vector<int> g[300005], dag[300005];   pair<long long, long long> a[300005];   pair<long long, long long> dp[300005];   pair<long long, long long> operator+(const pair<long long, long long> &a,                                        const pair<long long, long long> &b) {     return make_pair(a.first + b.first, a.second + b.second);   }   void down(string &a) {     for (int i = 0; i < a.length(); i++)       if ( A  <= a[i] && a[i] <=  Z ) a[i] = a[i] -  A  +  a ;   }   pair<long long, long long> calc(string a) {     pair<long long, long long> t = make_pair(0, 0);     for (int i = 0; i < a.length(); i++)       if (a[i] ==  r ) t.first++;     t.second = a.length();     return t;   }   void add(string &s) {     down(s);     if (hashh.count(s) == 0) hashh[s] = ++cnt;     pair<long long, long long> t = calc(s);     a[hashh[s]] = t;   }   void tarjan(int u) {     s.push(u);     ins[u] = 1;     dfn[u] = low[u] = ++tot;     for (int i = 0; i < g[u].size(); i++) {       int v = g[u][i];       if (dfn[v] == 0) {         tarjan(v);         low[u] = min(low[u], low[v]);       } else if (ins[v])         low[u] = min(low[u], dfn[v]);     }     if (dfn[u] == low[u]) {       int v;       scc++;       dp[scc] = make_pair(1 << 30, 1 << 30);       do {         v = s.top();         s.pop();         ins[v] = 0;         bel[v] = scc;         dp[scc] = min(dp[scc], a[v]);       } while (v != u);     }   }   void dfs(int u) {     if (vis[u]) return;     vis[u] = 1;     for (int i = 0; i < dag[u].size(); i++) {       int v = dag[u][i];       dfs(v);       dp[u] = min(dp[u], dp[v]);     }   }   int main() {     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> ori[i];       add(ori[i]);     }     cin >> m;     for (int i = 1; i <= m; i++) {       string u, v;       cin >> u >> v;       add(u);       add(v);       g[hashh[u]].push_back(hashh[v]);     }     for (int i = 1; i <= cnt; i++)       if (dfn[i] == 0) tarjan(i);     for (int i = 1; i <= cnt; i++)       for (int j = 0; j < g[i].size(); j++)         if (bel[i] != bel[g[i][j]]) dag[bel[i]].push_back(bel[g[i][j]]);     for (int i = 1; i <= scc; i++)       if (vis[i] == 0) dfs(i);     pair<long long, long long> ans;     for (int i = 1; i <= n; i++) ans = ans + dp[bel[hashh[ori[i]]]];     cout << ans.first <<     << ans.second;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 1000000000;   const long long LINF = 1e17;   const double PI = 3.141592653589793238;   const int mod = 1000000007;   const double eps = 0.000001;   template <typename T, typename TT>   ostream &operator<<(ostream &s, pair<T, TT> t) {     return s <<  (  << t.first <<  ,  << t.second <<  ) ;   }   template <typename T>   ostream &operator<<(ostream &s, vector<T> t) {     for (int i = 0; i < (t).size(); i++)       s << t[i] << ((i < (t).size() - 1) ?     :   );     return s;   }   template <typename T>   ostream &operator<<(ostream &s, set<T> t) {     for (T x : t) s << x <<    ;     return s;   }   template <typename T>   istream &operator>>(istream &s, vector<T> &t) {     for (int _i = 0; _i < t.size(); _i++) s >> t[_i];     return s;   }   int main(int argc, const char *argv[]) {     int n;     cin >> n;     int q[10][1023], p[10][1023];     for (int i = (0); i < (int)(10); i++)       for (int j = (0); j < (int)(n); j++) q[i][j] = p[i][j] = INF;     for (int i = (0); i < (int)(10); i++) {       vector<int> cq, cp;       for (int j = (0); j < (int)(n); j++) {         if (j & (1 << i))           cp.push_back(j + 1);         else           cq.push_back(j + 1);       }       if (cp.size() > 0) {         cout << cp.size() <<   n  << cp <<   n ;         fflush(stdout);         for (int j = (0); j < (int)(n); j++) cin >> p[i][j];       }       if (cq.size() < n) {         cout << cq.size() <<   n  << cq <<   n ;         fflush(stdout);         for (int j = (0); j < (int)(n); j++) cin >> q[i][j];       }     }     cout <<  -1 n ;     for (int j = (0); j < (int)(n); j++) {       int minv = INF;       for (int i = (0); i < (int)(10); i++) {         if (j & (1 << i))           minv = min(minv, q[i][j]);         else           minv = min(minv, p[i][j]);       }       cout << minv <<    ;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, sum = 0, k;     cin >> n;     char a[n];     cin >> a;     for (int i = 0; i < n; i++) {       k = int(a[i]);       if (k % 2 == 0) {         sum = sum + (i + 1);       }     }     cout << sum;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int arr[200005];   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int n;     cin >> n;     for (int i = 0; i < n; i++) cin >> arr[i];     sort(arr, arr + n);     int now = arr[0], cnt = 1;     set<int> sup;     stack<int> sdown;     sup.insert(now);     for (int i = 1; i < n; i++) {       if (arr[i] == now) {         cnt++;         sdown.push(arr[i]);       } else {         now = arr[i];         sup.insert(now);         cnt = 1;       }       if (cnt >= 3) {         cout <<  NO  << endl;         return 0;       }     }     cout <<  YES  << endl;     cout << sup.size() << endl;     bool flag = true;     for (auto i = sup.begin(); i != sup.end(); i++) {       if (flag) {         cout << *i;         flag = false;       } else         cout <<     << *i;     }     cout << endl;     cout << sdown.size() << endl;     flag = true;     while (!sdown.empty()) {       if (flag) {         cout << sdown.top();         flag = false;       } else         cout <<     << sdown.top() << endl;       sdown.pop();     }     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct __timestamper {};   int main() {     int n;     scanf( %d , &n);     vector<int> l(n), r(n);     for (int i = 0; i < n; i++) scanf( %d%d , &l[i], &r[i]);     double ans = 0;     for (int i = 1; i <= 10000; i++) {       double prob[3];       prob[0] = 1;       prob[1] = prob[2] = 0;       for (int j = 0; j < n; j++) {         double p = max(r[j] - max(l[j], i) + 1, 0) * 1.0 / (r[j] - l[j] + 1);         prob[2] += prob[1] * p;         prob[1] = prob[1] * (1.0 - p) + prob[0] * p;         prob[0] *= 1.0 - p;       }       ans += prob[2];     }     printf( %.10f n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long mod = 1000000007LL;   const int lmt = 1005;   const long long inf = 1LL << 62;   long long dp[lmt][lmt], a[lmt], req[lmt];   int n;   long long solve(int idx, int left) {     if (idx > n) return 0;     if (dp[idx][left] != -1) return dp[idx][left];     long long ans = min(a[idx], solve(idx + 1, left) + a[idx]);     if (left > 0) ans = max(solve(idx + 1, left - 1), ans);     return dp[idx][left] = ans;   }   void process() {     memset(dp, -1, sizeof(dp));     for (int i = 0; i <= n; i++) {       req[i] = solve(1, i);     }   }   int main() {     int q;     scanf( %d%d , &n, &q);     for (int i = 1; i <= n; i++) scanf( %lld , &a[i]);     process();     while (q--) {       long long val;       scanf( %lld , &val);       for (int i = 0; i <= n; i++) {         if ((req[i] + val) >= 0) {           printf( %d n , i);           break;         }       }     }     return 0;   }