malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   long long isPrime(long long x) {     long long i, flag = 1;     if (x == 0 || x == 1) {       flag = 0;     }     for (i = 2; i <= sqrt(x); i++) {       if (x % i == 0) {         flag = 0;         break;       }     }     return flag;   }   long long fact(long long n) {     long long ans = 1;     for (long long i = 2; i <= n; i++) {       ans *= i;     }     return ans;   }   const long long INF = 1e18;   const long long N = 2 * 1e5;   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     {       long long n;       cin >> n;       if (n == 0) {         cout << 1 <<   n ;         return 0;       }       if (n % 4 == 1) {         cout << 8 <<   n ;       } else if (n % 4 == 2) {         cout << 4 <<   n ;       } else if (n % 4 == 3) {         cout << 2 <<   n ;       } else if (n % 4 == 0) {         cout << 6 <<   n ;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3fffffff;   const int inf = -INF;   const int N = 100005;   const int M = 2005;   const int mod = 1000000007;   const double pi = acos(-1.0);   int mp1[N], mp2[N];   int main() {     int n, m;     int d, p;     char s[2];     scanf( %d %d , &n, &m);     memset(mp1, 0, sizeof(mp1));     memset(mp2, 0, sizeof(mp2));     for (int i = 1; i <= n; i++) {       scanf( %s %d %d , &s, &p, &d);       if (s[0] ==  S )         mp1[p] += d;       else         mp2[p] += d;     }     int k = 0, t = 0;     for (int it = 0; it < N, t < m; it++) {       if (it > 100000) break;       if (mp1[it] > 0) t++, k = it;     }     for (int j = k; j >= 0; j--)       if (mp1[j] > 0) printf( S %d %d n , j, mp1[j]);     t = 0;     for (int it = N; it >= 0 && t < m; it--) {       if (mp2[it] > 0) printf( B %d %d n , it, mp2[it]), t++;     }   }
#include <bits/stdc++.h>   using namespace std;   char arr[300001];   int main(void) {     int N;     scanf( %d , &N);     scanf( %s , arr);     int i;     char _max = 0;     int idx = -1;     for (i = 0; i < N; i++) {       if (_max < arr[i]) {         _max = arr[i];         idx = i;       }       if (idx != -1 && _max > arr[i]) {         printf( YES n );         printf( %d %d n , idx + 1, i + 1);         return 0;       }     }     printf( NO n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int mo = 1000000007;   const int Maxn = 1010;   int f[110000], g[110000];   int a[Maxn * 2], b[Maxn * 2];   int sum[110000];   char st[Maxn];   int n, m, cnt;   bool Check(int s) {     for (int i = 0; i < n; ++i)       if (a[s + i] != b[i]) return false;     return true;   }   void Update(int &x, int y) {     if (y < 0) y += mo;     x += y;     if (x >= mo) x -= mo;   }   int main() {     scanf( %s , st);     n = strlen(st);     for (int i = 0; i < n; ++i) a[i] = st[i] -  a ;     for (int i = 0; i < n; ++i) a[i + n] = a[i];     scanf( %s , st);     for (int i = 0; i < n; ++i) b[i] = st[i] -  a ;     scanf( %d , &m);     sum[0] = 1;     for (int i = 1; i <= m; ++i) sum[i] = (long long)sum[i - 1] * (n - 1) % mo;     f[0] = 0;     f[1] = 1;     for (int i = 2; i <= m; ++i) {       f[i] = sum[i - 1] - f[i - 1];       if (f[i] < 0) f[i] += mo;     }     g[0] = 1;     g[1] = 0;     for (int i = 2; i <= m; ++i) {       g[i] = sum[i - 1] - g[i - 1];       if (g[i] < 0) g[i] += mo;     }     if (!m) {       if (Check(0))         printf( 1 n );       else         printf( 0 n );       return 0;     }     int ans = 0;     if (Check(0)) Update(ans, g[m]);     for (int i = 1; i < n; ++i)       if (Check(i)) Update(ans, f[m]);     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline int read() {     int w = 1, s = 0;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) w = 0;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       s = (s << 1) + (s << 3) + ch -  0 ;       ch = getchar();     }     return w ? s : -s;   }   const int N = 1001;   struct point {     int x, y, num;   } p[N];   struct square {     int x, y, r;   } s[N];   int opp[N], bel[N];   bool num[N];   int n, m, k, ans;   vector<int> f[N];   bool cmp1(point a, point b) { return a.x < b.x; }   bool cmp2(square a, square b) { return a.x - a.r < b.x - b.r; }   bool solve(int x) {     if (x == 0) return 1;     return 0;   }   void content() {     n = read(), m = read(), k = read();     for (int i = 1; i <= n; i++) p[i].x = read(), p[i].y = read(), p[i].num = i;     sort(p + 1, p + n + 1, cmp1);     for (int i = 1; i <= n; i++) opp[p[i].num] = i;     for (int i = 1; i <= m; i++) {       s[i].r = read();       s[i].x = read(), s[i].y = read();     }     sort(s + 1, s + m + 1, cmp2);     for (int i = 1; i <= m; i++) {       for (int j = 1; j <= n; j++) {         if (p[j].x < s[i].x - s[i].r) continue;         if (p[j].x > s[i].x + s[i].r) break;         int a = p[j].x, b = p[j].y, c = s[i].x, d = s[i].y;         double lc = sqrt(pow((a - c), 2) + pow((b - d), 2));         if (lc < s[i].r) f[p[j].num].push_back(i);       }     }     for (int i = 1; i <= k; i++) {       int x = read(), y = read();       for (int j = 0; j < f[x].size(); j++) num[f[x][j]] = solve(num[f[x][j]]);       for (int j = 0; j < f[y].size(); j++) num[f[y][j]] = solve(num[f[y][j]]);       for (int j = 1; j <= m; j++)         if (num[j]) ans++;       printf( %d n , ans);       ans = 0;       memset(num, 0, sizeof(num));     }   }   int main() {     content();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int k[3];   long long t[200000];   long long c[200000];   int n;   long long T[3];   long long nt[200000];   multiset<long long> s;   int main(void) {     for (int i = 0; i < 3; i++) scanf(  %d , &k[i]);     for (int i = 0; i < 3; i++) scanf(  %I64d , &T[i]);     scanf( %d , &n);     for (int i = 0; i < n; i++) scanf( %I64d , &c[i]), nt[i] = c[i];     for (int i = 0; i < 3; i++) k[i] = min(k[i], n + 1);     for (int step = 0; step < 3; step++) {       s.clear();       for (int i = 0; i < k[step]; i++) {         s.insert(0ll);       }       for (int i = 0; i < n; i++) t[i] = nt[i];       for (int i = 0; i < n; i++) {         long long TM = max(*s.begin(), t[i]);         nt[i] = TM + T[step];         s.erase(s.begin());         s.insert(nt[i]);       }     }     long long ans = 0;     for (int i = 0; i < n; i++) {       ans = max(ans, nt[i] - c[i]);     }     printf( %I64d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   void print(T a) {     for (auto x : a) cout << x <<    ;     cout <<   n ;   }   void solve() {     int n, m;     cin >> n >> m;     char a[n][m];     short down[n][m], up[n][m];     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         cin >> a[i][j];         down[i][j] = 0;         up[i][j] = 0;       }     }     short l[m], r[m];     for (int j = 0; j < m; j++) up[0][j] = 1;     int ans = 0;     for (int i = 1; i < n; i++) {       for (int j = 0; j < m; j++) {         if (j == 0 || (a[i][j - 1] != a[i][j]))           l[j] = j;         else           l[j] = l[j - 1];       }       for (int j = m - 1; j >= 0; j--) {         if (j == m - 1 || (a[i][j + 1] != a[i][j]))           r[j] = j;         else           r[j] = r[j + 1];       }       for (int j = 0; j < m; j++) {         int x = 1;         if (a[i - 1][j] == a[i][j]) x = up[i - 1][j] + 1;         x = min(x, j - l[j] + 1);         x = min(x, r[j] - j + 1);         up[i][j] = x;       }     }     for (int j = 0; j < m; j++) down[n - 1][j] = 1;     for (int i = n - 2; i >= 0; i--) {       for (int j = 0; j < m; j++) {         if (j == 0 || (a[i][j - 1] != a[i][j]))           l[j] = j;         else           l[j] = l[j - 1];       }       for (int j = m - 1; j >= 0; j--) {         if (j == m - 1 || (a[i][j + 1] != a[i][j]))           r[j] = j;         else           r[j] = r[j + 1];       }       for (int j = 0; j < m; j++) {         int x = 1;         if (a[i + 1][j] == a[i][j]) x = down[i + 1][j] + 1;         x = min(x, j - l[j] + 1);         x = min(x, r[j] - j + 1);         down[i][j] = x;       }     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         short res = min(up[i][j], down[i][j]);         ans += res;       }     }     cout << ans <<   n ;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int t = 1;     for (int i = 0; i < t; i++) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 1 << 30;   const int p = 10000007;   pair<long long, int> c[500005];   pair<long long, long long> sum[500005];   int id[500005];   long long a[500005], b[500005], ans[500005];   int main() {     int n, m;     scanf( %d%d , &n, &m);     for (int i = (int)1; i <= (int)n; i++) {       scanf( %I64d%I64d , &a[i], &b[i]);       c[i] = make_pair(a[i] - b[i], i);     }     sort(c + 1, c + n + 1);     for (int i = (int)1; i <= (int)n; i++) id[c[i].second] = i;     sum[0] = make_pair(0, 0);     sum[n + 1] = make_pair(0, 0);     for (int i = (int)1; i <= (int)n; i++)       sum[i].first = sum[i - 1].first + a[c[i].second];     for (int i = (int)n; i >= (int)1; i--)       sum[i].second = sum[i + 1].second + b[c[i].second];     for (int i = (int)1; i <= (int)n; i++)       ans[i] = a[i] * (n - id[i]) + b[i] * (id[i] - 1) + sum[id[i] - 1].first +                sum[id[i] + 1].second;     for (int times = (int)1; times <= (int)m; times++) {       int x, y;       scanf( %d%d , &x, &y);       if (id[x] < id[y])         ans[x] -= a[x] + b[y], ans[y] -= a[x] + b[y];       else         ans[x] -= a[y] + b[x], ans[y] -= a[y] + b[x];     }     for (int i = (int)1; i <= (int)n; i++) printf( %I64d  , ans[i]);     puts(  );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b;     cin >> a >> b;     string s;     cin >> s;     while (b--) {       for (int i = 0; i < a - 1; i++) {         if (s[i] ==  B  && s[i + 1] ==  G ) {           int t;           t = s[i];           s[i] = s[i + 1];           s[i + 1] = t;           i++;         }       }     }     cout << s;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int abss(int n) {     if (n < 0)       return -n;     else       return n;   }   const int maxn = 3e5 + 10;   int _min(int a, int b) {     if (a < b)       return a;     else       return b;   }   int _max(int a, int b) {     if (a > b)       return a;     else       return b;   }   char s[maxn];   int main() {     int a, b, x;     cin >> a >> b >> x;     int w = _min(a, b);     if (a > b) {       int c0 = 0, c1 = 0;       int tail = 0;       printf( 0 );       c0++;       for (int i = 1; i <= x - 1; i++) {         if (i % 2 == 1)           printf( 1 ), c1++, tail = 1;         else           printf( 0 ), c0++, tail = 0;       }       if (tail == 0 || x - 1 == 0) {         int temp = a - c0;         while (temp--) printf( 0 );         temp = b - c1;         while (temp--) printf( 1 );       } else {         int temp = b - c1;         while (temp--) printf( 1 );         temp = a - c0;         while (temp--) printf( 0 );       }       printf(  n );     } else {       int c0 = 0, c1 = 0;       printf( 1 );       c1++;       int tail = 1;       for (int i = 1; i <= x - 1; i++) {         if (i % 2 == 1)           printf( 0 ), c0++, tail = 0;         else           printf( 1 ), c1++, tail = 1;       }       if (tail == 0 && x - 1 != 0) {         int temp = a - c0;         while (temp > 0) printf( 0 ), temp--;         temp = b - c1;         while (temp > 0) printf( 1 ), temp--;       } else {         int temp = b - c1;         while (temp > 0) printf( 1 ), temp--;         temp = a - c0;         while (temp > 0) printf( 0 ), temp--;       }       printf(  n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     int a, b, c, d, m, v;     cin >> a >> b >> c >> d;     m = max((3 * a) / 10, a - (a / 250) * c);     v = max((3 * b) / 10, b - (b / 250) * d);     if (m > v)       cout <<  Misha ;     else if (v > m)       cout <<  Vasya ;     else       cout <<  Tie ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int nn[2000000];   int ans[2000000];   string ss;   int main() {     int n;     cin >> n;     for (int i = 0; i < n; i++) cin >> nn[i];     int se = 0, en = n - 1;     int noa = 0;     ans[noa] = 0;     while ((nn[se] > ans[noa] || nn[en] > ans[noa]) && en != se) {       if (nn[se] > ans[noa] && nn[se] < nn[en]) {         ans[++noa] = nn[se];         se++;         ss.append( L );       } else if (nn[en] > ans[noa]) {         ans[++noa] = nn[en];         en--;         ss.append( R );       } else {         ans[++noa] = nn[se];         se++;         ss.append( L );       }     }     if (en == se)       if (nn[se] > ans[noa]) {         noa++;         ss.append( L );       }     cout << noa << endl;     cout << ss << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 355001;   const int SQRTN = 320;   const int LOGN = 20;   const long double PI = acos(-1);   const long double TAU = 2 * PI;   int n, a[N], idx[N], last, m, an[N];   long long ans;   signed main() {     cin >> n >> m;     for (int i = 1; i <= n; i++) {       scanf( %d , a + i);       idx[a[i]] = i;       an[i] = n + 1;     }     for (int j = 0, x, y; j < m; j++) {       scanf( %d%d , &x, &y);       if (idx[x] > idx[y]) swap(x, y);       an[idx[x]] = min(an[idx[x]], idx[y]);     }     int x = n + 1;     ans = -(n * 1ll * (n + 1)) >> 1;     for (int i = n; i > 0; i--) x = min(x, an[i]), ans += x;     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   void propagate(int node, const map<int, set<int> >& idToChildren,                  set<int>& leaves) {     map<int, set<int> >::const_iterator it = idToChildren.find(node);     if (it == idToChildren.end()) {       leaves.insert(node);       return;     }     const set<int>& s = (*it).second;     for (set<int>::const_iterator cit = s.begin(); cit != s.end(); ++cit) {       propagate(*cit, idToChildren, leaves);     }   }   int main() {     int n;     cin >> n;     int f[n + 1];     char visited[n + 1];     char inLoop[n + 1];     int tag[n + 1];     char hasParent[n + 1];     char hasChild[n + 1];     for (int i = 1; i <= n; i++) {       cin >> f[i];       visited[i] = inLoop[i] = 0;       tag[i] = i;       hasParent[i] = hasChild[i] = 0;     }     for (int i = 1; i <= n; i++) {       if (visited[i]) continue;       bool found = false;       set<int> traversed;       visited[i] = 1;       traversed.insert(i);       int x = i;       int confluence = -1;       while (1) {         int xTemp = f[x];         if (inLoop[xTemp]) {           f[x] = tag[xTemp];           break;         } else if (traversed.find(xTemp) != traversed.end()) {           found = true;           confluence = xTemp;           break;         } else if (visited[xTemp]) {           break;         } else {           x = xTemp;           visited[x] = 1;           traversed.insert(x);         }       }       if (found) {         int y = confluence;         do {           tag[y] = confluence;           inLoop[y] = 1;           y = f[y];         } while (y != confluence);       }     }     map<int, set<int> > idToChildren;     map<int, set<int> > rootToLeaves;     for (int i = 1; i <= n; i++) {       if (inLoop[i]) continue;       hasParent[i] = hasChild[f[i]] = 1;       idToChildren[f[i]].insert(i);     }     set<int> roots;     set<int> leaves;     for (int i = 1; i <= n; i++) {       if (tag[i] != i) continue;       if (!hasParent[i]) {         roots.insert(i);       }       if (!hasChild[i]) {         leaves.insert(i);       }     }     for (set<int>::const_iterator it = roots.begin(); it != roots.end(); ++it) {       propagate(*it, idToChildren, rootToLeaves[*it]);     }     if (leaves.size() == 1 && *leaves.begin() == *roots.begin()) {       cout << 0 << endl;       return 0;     }     cout << leaves.size() << endl;     int firstRoot = *roots.begin();     int prevRoot = firstRoot;     {       set<int>::const_iterator it = roots.begin();       advance(it, 1);       for (; it != roots.end(); ++it) {         for (set<int>::const_iterator lit = rootToLeaves[*it].begin();              lit != rootToLeaves[*it].end(); ++lit) {           cout << prevRoot <<     << *lit << endl;         }         prevRoot = *it;       }     }     for (set<int>::const_iterator it = rootToLeaves[firstRoot].begin();          it != rootToLeaves[firstRoot].end(); ++it) {       cout << prevRoot <<     << *it << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 600010, inf = N;   int n, m;   int head[N], cnt = 1;   struct edge {     int to, next;   } e[N << 1];   void adde(int a, int b) {     e[++cnt].to = b;     e[cnt].next = head[a];     head[a] = cnt;   }   int nxt[N], st[N], vis[N], top, mn, mx, in[N];   void dfs(int k, int fa) {     vis[k] = 1;     st[++top] = k;     for (int i = head[k]; i; i = e[i].next) {       int v = e[i].to;       if (v == fa) continue;       if (!vis[v])         dfs(v, k);       else if (!in[v]) {         mx = 0;         mn = inf;         while (top) {           mx = max(st[top], mx);           mn = min(mn, st[top]);           in[st[top]] = 1;           top--;           if (st[top + 1] == v) break;         }         nxt[mn] = min(nxt[mn], mx);       }     }     if (!in[k]) top--;   }   long long sum[N];   int main() {     scanf( %d%d , &n, &m);     int u, v, q;     for (int i = 1; i <= m; i++) {       scanf( %d%d , &u, &v);       adde(u, v);       adde(v, u);     }     for (int i = 1; i <= n + 1; i++) nxt[i] = n + 1;     for (int i = 1; i <= n; i++)       if (!vis[i]) dfs(i, 0);     for (int i = n; i; i--) nxt[i] = min(nxt[i + 1], nxt[i]);     for (int i = 1; i <= n; i++) sum[i] = sum[i - 1] + nxt[i];     scanf( %d , &q);     int L, R;     while (q--) {       scanf( %d%d , &L, &R);       int l = L, r = R, res = L - 1;       while (l <= r) {         int mid = l + r >> 1;         if (nxt[mid] > R)           r = mid - 1;         else           l = mid + 1, res = mid;       }       printf( %lld n , 1ll * (R - res) * (R - res + 1) / 2 + sum[res] -                            sum[L - 1] - 1ll * (res + L) * (res - L + 1) / 2);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     string s1, s2;     cin >> s1 >> s2;     int a, b, c, d;     a = s1[0] -  0 ;     b = s1[1] -  0 ;     c = s2[1] -  0 ;     d = s2[0] -  0 ;     vector<int> v1({a, b, c, d});     map<vector<int>, int> mp;     mp[{a, b, c, d}] = 1;     n--;     while (n--) {       string s;       cin >> s;       cin >> s1 >> s2;       a = s1[0] -  0 ;       b = s1[1] -  0 ;       c = s2[1] -  0 ;       d = s2[0] -  0 ;       vector<int> v1({a, b, c, d});       vector<int> v2({b, c, d, a});       vector<int> v3({c, d, a, b});       vector<int> v4({d, a, b, c});       if (mp.find({a, b, c, d}) != mp.end()) {         continue;       } else if (mp.find({b, c, d, a}) != mp.end()) {         continue;       } else if (mp.find({c, d, a, b}) != mp.end()) {         continue;       } else if (mp.find({d, a, b, c}) != mp.end()) {         continue;       } else         mp[{a, b, c, d}] = 1;     }     cout << mp.size() << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     long long t, j = 0;     cin >> t;     cin >> s;     for (long long i = 0; i < s.size(); i++) {       if (s[i] ==  F )         if (s[i + 1] ==  S ) j--;       if (s[i] ==  S )         if (s[i + 1] ==  F ) j++;     }     if (j <= 0)       cout <<  NO ;     else if (j > 0)       cout <<  YES ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char g[3010][3010];   long long dp[2][3010][3010];   int main() {     int n, m;     scanf( %d %d , &n, &m);     for (int i = 1; i < n + 1; i++) scanf( %s , g[i] + 1);     if (g[1][2] ==  . ) dp[0][1][2] = 1;     if (g[2][1] ==  . ) dp[1][2][1] = 1;     for (int i = 1; i < n + 1; i++)       for (int j = 1; j < m + 1; j++) {         if (g[i][j] ==  . ) {           for (int z = 0; z < 2; z++)             dp[z][i][j] =                 (dp[z][i][j] + dp[z][i - 1][j] + dp[z][i][j - 1]) % 1000000007LL;         }       }     printf( %lld n , (((dp[0][n - 1][m] * dp[1][n][m - 1] -                         dp[0][n][m - 1] * dp[1][n - 1][m]) %                        1000000007LL) +                       1000000007LL) %                          1000000007LL);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int mas[1010][1010];   int mas1[1001][1001];   bool check(int i, int j) {     return mas[i][j] && mas[i + 1][j] && mas[i + 2][j] && mas[i + 2][j + 1] &&            mas[i + 2][j + 2] && mas[i + 1][j + 2] && mas[i][j + 2] &&            mas[i][j + 1];   }   void draw(int i, int j) {     mas1[i][j] = mas1[i + 1][j] = mas1[i + 2][j] = mas1[i + 2][j + 1] =         mas1[i + 2][j + 2] = mas1[i + 1][j + 2] = mas1[i][j + 2] =             mas1[i][j + 1] = 1;   }   int main() {     int n, m;     cin >> n >> m;     for (int i = 1; i <= n; ++i)       for (int j = 1; j <= m; ++j) {         char temp;         cin >> temp;         if (temp ==  # )           mas[i][j] = 1;         else           mas[i][j] = 0;       }     for (int i = 1; i <= n - 2; ++i)       for (int j = 1; j <= m - 2; ++j) {         if (check(i, j)) draw(i, j);       }     bool f = 1;     for (int i = 1; i <= n; ++i)       for (int j = 1; j <= m; ++j) {         if (mas[i][j] && !mas1[i][j]) f = 0;       }     if (f)       cout <<  YES ;     else       cout <<  NO ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2004;   int pa[N];   int n, m, x, y, op, pos = 1, ans = 0;   pair<int, int> p[N];   bool b[N];   int main() {     scanf( %d %d , &n, &m);     for (int i = 1; i <= n * 2; i++) {       scanf( %d , &p[i].first);       p[i].second = i;     }     for (int i = 0; i < m; i++) {       scanf( %d %d , &x, &y);       pa[x] = y;       pa[y] = x;     }     sort(p + 1, p + 2 * n + 1, greater<pair<int, int> >());     scanf( %d , &op);     for (int i = 1; i <= n; i++) {       if (op == 1) {         bool g = 0;         for (int i = pos; i <= 2 * n; i++)           if (!b[p[i].second] && pa[p[i].second] != 0) {             ans = p[i].second;             g = 1;             break;           }         if (!g) {           for (; pos <= 2 * n && b[p[pos].second]; ++pos)             ;           ans = p[pos].second;         }         b[ans] = 1;         cout << ans << endl;         scanf( %d , &x);         b[x] = 1;       } else {         scanf( %d , &x);         b[x] = 1;         if (pa[x] == 0 || b[pa[x]]) {           bool g = 0;           for (int i = pos; i <= 2 * n; i++)             if (!b[p[i].second] && pa[p[i].second] != 0) {               ans = p[i].second;               g = 1;               break;             }           if (!g) {             for (; pos <= 2 * n && b[p[pos].second]; ++pos)               ;             ans = p[pos].second;           }         } else {           ans = pa[x];           b[pa[x]] = 1;         }         b[ans] = 1;         cout << ans << endl;       }     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     scanf( %d , &n);     vector<int> segs;     int numNeg = 0;     int curLen = 0;     for (int i = 0; i < n; i++) {       int a;       scanf( %d , &a);       if (a < 0) {         if (numNeg == 2) {           segs.push_back(curLen);           curLen = 1;           numNeg = 1;         } else {           numNeg += 1;           curLen += 1;         }       } else {         curLen += 1;       }     }     if (curLen != 0) {       segs.push_back(curLen);     }     printf( %d n , segs.size());     for (int s : segs) {       printf( %d  , s);     }     return 0;   }