malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   template <class _, class __>   bool checkmax(_ &a, __ b) {     return a < b ? a = b, true : false;   }   template <class _, class __>   bool checkmin(_ &a, __ b) {     return a > b ? a = b, true : false;   }   using namespace std;   const int INF = 1e9;   struct node {     int x, p;     bool operator<(const node &a) const { return x < a.x; }   } A[200086];   int n, c, m;   stack<int> stk;   int nxt[200086];   int main() {     cin >> n >> c >> m;     for (register int i = (1), i_end_ = (m); i <= i_end_; ++i) {       scanf( %d%d , &A[i].x, &A[i].p);     }     A[0] = (node){0, 0};     A[++m] = (node){n, INF};     sort(A, A + m + 1);     for (register int i = (m), i_end_ = (0); i >= i_end_; --i) {       while (!stk.empty() && A[stk.top()].p >= A[i].p) stk.pop();       nxt[i] = stk.empty() ? -1 : stk.top();       stk.push(i);     }     int rest = c;     long long ans = 0;     for (register int i = (1), i_end_ = (m); i <= i_end_; ++i) {       if (rest < A[i].x - A[i - 1].x) {         puts( -1 );         return EXIT_SUCCESS;       }       if (i == m) break;       rest -= A[i].x - A[i - 1].x;       if (nxt[i] != -1) {         int dis = A[nxt[i]].x - A[i].x;         if (rest >= dis) continue;         ans += 1ll * (min(dis, c) - rest) * A[i].p;         rest = min(dis, c);       } else {         if (rest >= A[m].x - A[i].x) continue;         ans += 1ll * (min(A[m].x - A[i].x, c) - rest) * A[i].p;         rest = min(A[m].x - A[i].x, c);       }     }     printf( %I64d n , ans);     return EXIT_SUCCESS;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     int len, star = 0, question = 0, k = 0, n = 0;     cin >> s;     cin >> k;     len = s.length();     for (int i = 0; i < len; i++) {       if (s[i] ==  ? ) {         question++;       }       if (s[i] ==  * ) {         star++;       }     }     n = len - (star + question);     if (n == k) {       for (int i = 0; i < len; i++) {         if (s[i] !=  ?  && s[i] !=  * ) {           cout << s[i];         }       }     } else if (n < k && star < 1) {       cout <<  Impossible ;     } else if (n > k && n - star - question > k) {       cout <<  Impossible ;     } else {       if (n > k) {         for (int i = 0; i < len; i++) {           if (s[i] !=  ?  && s[i] !=  * ) {             if (i + 1 < len && (s[i + 1] ==  ?  || s[i + 1] ==  * ) && n > k) {               n--;             } else {               cout << s[i];             }           }         }       } else {         for (int i = 0; i < len; i++) {           if (s[i] !=  ?  && s[i] !=  * ) {             if (i + 1 < len && s[i + 1] ==  * ) {               cout << s[i];               while (n < k) {                 cout << s[i];                 n++;               }             } else {               cout << s[i];             }           }         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   const long double PI2 = atan2(1.L, 0.L);   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n;     long double r;     cin >> n >> r;     long double res =         r * r * n * sin(PI2 / n) * sin(2 * PI2 / n) / sin(3 * PI2 / n);     cout << fixed << setprecision(10) << res <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k, A[100], B[100];     cin >> n >> k;     for (int i = 0; i < n; i++) cin >> A[i];     for (int i = 0; i < k; i++) cin >> B[i];     if (k > 1) {       cout <<  Yes n ;       return 0;     }     for (int i = 0; i < n; i++)       if (!A[i]) A[i] = B[0];     for (int i = 1; i < n; i++)       if (A[i] < A[i - 1]) {         cout <<  Yes n ;         return 0;       }     cout <<  No n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, x, y;     cin >> n >> x >> y;     string num;     cin >> num;     num = num.substr(num.length() - x, x);     cout << count(num.begin(), num.end() - y - 1,  1 ) +                 count(num.end() - y, num.end(),  1 ) +                 (*(num.end() - y - 1) ==  1  ? 0 : 1);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e6 + 7;   int n;   long long dp[2][maxn];   int main() {     cin >> n;     int now = 1;     dp[0][1] = 1;     dp[0][2] = 1;     long long ans = 0;     ans += dp[0][n];     for (int i = 1; i <= 19; i++) {       memset(dp[now], 0, sizeof(dp[now]));       for (int j = (1 << (i)) - 1; j < (1 << (i + 1)) - 1; j++) {         if (dp[now ^ 1][j] == 0) continue;         for (int l = (1 << (i)) - 1; l < (1 << (i + 1)) - 1; l++) {           if (j + l + 1 < maxn && l % 2 == 0)             dp[now][j + l + 1] += dp[now ^ 1][j] * dp[now ^ 1][l];         }       }       ans += dp[now][n];       now ^= 1;     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC optimize( unroll-loops )   #pragma GCC target( sse2 )   using namespace std;   const int N = 2020;   namespace Gause {   static const int N = ::N;   int equ, var;   bitset<N> a[N];   int x[N];   int free_x[N];   int free_num;   int l[N];   void ini(int n) {     for (int i = (0); i < (n); ++i) x[i] = 0;     for (int i = (0); i < (n); ++i) a[i].reset();   }   int Gauss() {     int max_r, col, k;     free_num = 0;     for (k = 0, col = 0; k < equ && col < var; k++, col++) {       max_r = k;       for (int i = k + 1; i < equ; i++) {         if (abs(a[i][col]) > abs(a[max_r][col])) max_r = i;       }       if (a[max_r][col] == 0) {         k--;         free_x[free_num++] = col;         continue;       }       l[k] = col;       if (max_r != k) {         swap(a[k], a[max_r]);       }       for (int i = k + 1; i < equ; i++) {         if (a[i][col] != 0) a[i] ^= a[k];       }     }     for (int i = k; i < equ; i++) {       if (a[i][col] != 0) return -1;     }     for (int i = k - 1; i >= 0; i--) {       int t = l[i];       x[t] = a[i][var];       for (int j = t + 1; j < var; j++) x[t] ^= (a[i][j] & x[j]);     }     return 0;   }   }  // namespace Gause   int T, n, m, u, v;   bool du[N], vis[N][N];   int main() {     std::ios::sync_with_stdio(0);     std::cin.tie(0);     cin >> T;     for (int cas = (0); cas < (T); ++cas) {       cin >> n >> m;       Gause ::ini(n);       for (int i = (1); i < (n + 1); ++i)         for (int j = (1); j < (n + 1); ++j) vis[i][j] = 0;       for (int i = (1); i < (n + 1); ++i) du[i] = 0;       for (int i = (1); i < (m + 1); ++i) {         cin >> u >> v;         du[u] ^= 1;         du[v] ^= 1;         vis[u][v] = vis[v][u] = 1;       }       Gause ::equ = Gause ::var = n;       for (int i = (1); i < (n + 1); ++i) {         vis[i][i] = du[i];         for (int j = (1); j < (n + 1); ++j) Gause ::a[i - 1][j - 1] = vis[i][j];         Gause ::a[i - 1][n] = du[i];       }       Gause::Gauss();       bool Vis[2] = {0};       for (int i = (1); i < (n + 1); ++i) Vis[Gause::x[i - 1]] = 1;       if (Vis[0] && Vis[1]) {         cout << 2 <<   n ;       } else {         cout << 1 <<   n ;         if (Vis[1])           for (int i = (1); i < (n + 1); ++i) Gause::x[i - 1] = 0;       }       for (int i = (1); i < (n + 1); ++i) cout << Gause::x[i - 1] + 1 <<    ;       cout <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   const int maxn = 2e5 + 5;   using namespace std;   int rd() {     int x = 0, f = 1;     char c = getchar();     while (!isdigit(c)) {       if (c ==  - ) f = -1;       c = getchar();     }     while (isdigit(c)) x = (x << 3) + (x << 1) + c -  0 , c = getchar();     return x * f;   }   int n, q, cnt, id, now;   map<long long, int> mp;   map<pair<int, int>, int> ans;   vector<pair<int, int> > a[maxn];   vector<pair<int, int> >::iterator it;   int gcd(int a, int b) { return (b == 0) ? a : gcd(b, a % b); }   int get(long long x) {     if (!mp.count(x)) mp[x] = ++id;     return mp[x];   }   pair<int, int> fac(int x, int y) {     int z = gcd(x, y);     return make_pair(x / z, y / z);   }   int main() {     n = rd();     for (int i = 1, op, x, y; i <= n; i++) {       op = rd();       x = rd();       y = rd();       long long r = 1ll * x * x + 1ll * y * y;       if (op == 1) {         ++cnt;         now = get(r);         for (int i = 0; i < ((int)a[now].size()); i++)           ans[fac(a[now][i].first + x, a[now][i].second + y)] += 2;         ans[fac(x, y)]++;         a[now].push_back(make_pair(x, y));       } else if (op == 2) {         --cnt;         now = get(r);         for (int i = 0; i < ((int)a[now].size()); i++)           if (a[now][i] != make_pair(x, y))             ans[fac(a[now][i].first + x, a[now][i].second + y)] -= 2;         ans[fac(x, y)]--;         it = a[now].begin();         while (*it != make_pair(x, y)) ++it;         a[now].erase(it);       } else         printf( %d n , cnt - ans[fac(x, y)]);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     cout.precision(10);     cout << fixed;     long long q;     cin >> q;     for (int i = 0; i < (int)(q); ++i) {       long long n, ans = 0;       cin >> n;       vector<int> a(n);       for (int j = 0; j < (int)(n); ++j) {         cin >> a[j];       }       sort((a).rbegin(), (a).rend());       for (int j = 0; j < (int)(n); ++j) {         if (a[j] > j) {           ans++;         } else {           break;         }       }       cout << ans <<   n ;     }   }
#include <bits/stdc++.h>   double A[200000], B[200000], C[200000], p[200000], F[200000];   int i, j, n, m;   int main() {     scanf( %d , &n);     double now, last = 0;     C[0] = 1;     for (i = 1; i <= n; i++) {       if (i <= n) scanf( %lf , &now);       C[i] = now * (C[i - 1]) + 1 - now;       B[i] = now * (B[i - 1] + C[i - 1]);       A[i] = (A[i - 1] + 2 * B[i - 1] + C[i - 1]) * now + (1 - now) * A[i - 1];       last = now;     }     printf( %.9lf n , A[n]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<pair<long long int, long long int> > arr;   bool fun(pair<long long int, long long int> fi,            pair<long long int, long long int> se) {     if (fi.first < se.first) {       return true;     } else       return false;   }   void solve() {     long long int i, j, k, l, m, n, x;     cin >> n;     for (i = 0; i < n; i++) {       cin >> x;       arr.push_back(make_pair(x, i + 1));     }     sort(arr.begin(), arr.end(), fun);     if (n <= 3) {       cout << 1 << endl;       return;     }     long long int d = arr[1].first - arr[0].first;     long long int count = 0;     long long int index = arr[0].second;     for (i = 0; i < n; i++) {       if (arr[i].first != arr[0].first + (i - count) * d) {         count++;         index = arr[i].second;         if (count > 1) {           break;         }       }     }     if (count <= 1) {       cout << index << endl;       return;     }     d = arr[2].first - arr[0].first;     count = 1;     index = arr[1].second;     for (i = 3; i < n; i++) {       if (arr[i].first != arr[0].first + (i - count) * d) {         count++;         index = arr[i].second;         if (count > 1) {           break;         }       }     }     if (count <= 1) {       cout << index << endl;       return;     }     d = arr[2].first - arr[1].first;     count = 1;     index = arr[0].second;     for (i = 3; i < n; i++) {       if (arr[i].first != arr[1].first + (i - count) * d) {         count++;         index = arr[i].second;         if (count > 1) {           break;         }       }     }     if (count <= 1) {       cout << index << endl;       return;     }     cout << -1 << endl;     return;   }   int main() {     long long int t = 1;     while (t--) {       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   int n, i, b, a[105];   int main() {     cin >> n;     for (i = 1; i <= n; i++) {       cin >> a[i];       b += a[i];     }     if (b != 0) {       cout <<  YES n1 n1   << n;       return 0;     }     for (i = 1; i <= n; i++) {       if (a[i] != 0) {         break;       }     }     if (i <= n) {       cout <<  YES n2 n1   << i << endl;       cout << i + 1 <<     << n;     } else {       cout <<  NO  << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, CountDog[400];   char x[100005];   int main() {     scanf( %d , &n);     if (n == 1) {       printf( Yes );       return 0;     }     for (int i = 1; i <= n; i++) {       cin >> x[i];       CountDog[x[i]]++;     }     for (int i = 1; i <= n; i++)       if (CountDog[x[i]] >= 2) {         printf( Yes );         return 0;       }     printf( No );   }
#include <bits/stdc++.h>   using namespace std;   long long int a[200001];   long long int q[200001];   long long int pre[200001];   long long int binarysearch(long long int n, long long int p) {     long long int low = 1, high = n;     while (low <= high) {       long long int mid = (low + high) / 2;       if (pre[mid] <= p)         low = mid + 1;       else         high = mid - 1;     }     return high;   }   int main() {     long long int n, q1;     cin >> n >> q1;     for (long long int i = 1; i <= n; i++) cin >> a[i];     for (long long int i = 1; i <= q1; i++) cin >> q[i];     pre[1] = a[1];     for (long long int i = 2; i <= n; i++) pre[i] = a[i] + pre[i - 1];     long long int cal = 0;     for (long long int i = 1; i <= q1; i++) {       long long int ser = q[i] + cal;       long long int ans = binarysearch(n, ser);       if (ans < n)         cout << n - ans <<   n ;       else         cout << n <<   n ;       cal += q[i];       if (ans == n) cal = 0;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, t, cost = 0, r, min = 100000000;     cin >> n;     int a[n];     for (int i = 0; i < n; i++) {       cin >> a[i];     }     sort(a, a + n);     for (int i = 1; i <= a[n - 1]; i++) {       t = i;       for (int j = 0; j < n; j++) {         if (a[j] - t > 1) {           cost = cost + a[j] - (t + 1);         } else if (t - a[j] > 1) {           cost = cost + t - 1 - a[j];         }       }       if (cost < min) {         min = cost;         r = t;       }       cost = 0;     }     cout << r <<     << min;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, m;     cin >> n >> m;     if (m == 0) {       cout <<  YES  << endl;       return 0;     }     vector<long long int> v(m);     for (long long int i = 0; i < m; cin >> v[i++])       ;     sort(v.begin(), v.end());     if (v[0] == 1 || v[m - 1] == n) {       cout <<  NO  << endl;       return 0;     }     int ind = 1, ans = 0;     for (int i = 0; i < (m - 2); i++) {       if ((v[i] == (v[i + 1] - 1)) && (v[i + 1] == (v[i + 2] - 1))) {         cout <<  NO  << endl;         return 0;       }     }     cout <<  YES  << endl;   }
#include <bits/stdc++.h>   using namespace std;   int dp[1010][1010];   vector<int> arr;   int m;   int solve(int idx, int mod) {     if (idx == (int)arr.size())       return (mod == 0);     else if (dp[idx][mod] != -1)       return dp[idx][mod];     int ret = solve(idx + 1, mod);     if (ret) return (dp[idx][mod] = ret);     ret = solve(idx + 1, (mod + arr[idx]) % m);     return (dp[idx][mod] = ret);   }   int main() {     ios_base::sync_with_stdio(false);     for (int i = (int)(0); i < (int)(1010); i++)       for (int j = (int)(0); j < (int)(1010); j++) dp[i][j] = -1;     int n;     cin >> n >> m;     arr.resize(n);     for (int i = (int)(0); i < (int)(n); i++) cin >> arr[i];     if (n > m)       cout <<  YES  << endl;     else {       int yes = 0;       for (int i = (int)(0); i < (int)(n); i++) yes |= solve(i + 1, arr[i] % m);       if (yes)         cout <<  YES  << endl;       else         cout <<  NO  << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, q;   int b[100000][2];   int a[100000];   int c[5];   int main() {     cin >> n >> q;     for (int i = 0; i < n; i++) {       b[i][0] = 0;       b[i][1] = 0;       a[i] = 0;     }     c[0] = n - 1;     int s = 0;     for (int i = 0; i < q; i++) {       int y, x;       cin >> x >> y;       x--;       y--;       if (b[y][x] == 1) {         if (y == 0) {           if (b[y + 1][x] == 1) s--;           c[a[y]]--;           a[y]--;           c[a[y]]++;         } else if (y == n - 1) {           if (b[y - 1][x] == 1) s--;           c[a[y - 1]]--;           a[y - 1]--;           c[a[y - 1]]++;         } else {           if (b[y - 1][x] == 1) s--;           if (b[y + 1][x] == 1) s--;           c[a[y - 1]]--;           a[y - 1]--;           c[a[y - 1]]++;           c[a[y]]--;           a[y]--;           c[a[y]]++;         }         b[y][x] = 0;       } else {         if (y == 0) {           if (b[y + 1][x] == 1) s++;           c[a[y]]--;           a[y]++;           c[a[y]]++;         } else if (y == n - 1) {           if (b[y - 1][x] == 1) s++;           c[a[y - 1]]--;           a[y - 1]++;           c[a[y - 1]]++;         } else {           if (b[y + 1][x] == 1) s++;           if (b[y - 1][x] == 1) s++;           c[a[y - 1]]--;           a[y - 1]++;           c[a[y - 1]]++;           c[a[y]]--;           a[y]++;           c[a[y]]++;         }         b[y][x] = 1;       }       if (c[4] == 0 && c[3] == 0 && c[2] - s <= 0)         cout <<  Yes  << endl;       else         cout <<  No  << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   const double PI = acos(-1);   inline bool EQ(double a, double b) { return fabs(a - b) < 1e-9; }   long long bigmod(long long a, long long b) {     long long ret = 1;     while (b) {       if (b & 1) ret = (ret * a) % 1000000007;       b >>= 1;       a = (a * a) % 1000000007;     }     return ret;   }   long long inverse(long long n) { return bigmod(n, 1000000007 - 2); }   long long add(long long a, long long b) {     long long ret = a + b;     if (ret >= 1000000007) ret %= 1000000007;     return ret;   }   long long subtract(long long a, long long b) {     long long ret = a - b;     if (ret < 0) ret += 1000000007;     return ret;   }   long long mult(long long a, long long b) {     long long ret = a * b;     if (ret >= 1000000007) ret %= 1000000007;     return ret;   }   bool checkBit(int n, int i) { return (n & (1 << i)); }   int setBit(int n, int i) { return (n | (1 << i)); }   int resetBit(int n, int i) { return (n & (~(1 << i))); }   long long a[500010], p[500010];   int main() {     int n, k;     scanf( %d%d , &n, &k);     long long sum = 0;     for (int i = 0; i < n; ++i) {       scanf( %lld , &a[i]);       sum += a[i];     }     sort(a, a + n);     long long avg = sum / n, rem = sum % n;     for (int i = 0; i < n; ++i) p[i] = avg;     for (int i = n - 1; rem; --i) {       --rem;       ++p[i];     }     long long up = 0, down = n - 1, days = 0;     for (int i = 0; i < n; ++i) {       if (a[i] <= p[i]) {         up = i;         days += p[i] - a[i];       } else         break;     }     for (int i = n - 1; i >= 0; --i) {       if (a[i] >= p[i])         down = i;       else         break;     };     ;     ;     if (k >= days) {       printf( %lld n , p[n - 1] - p[0]);       return 0;     }     long long mn = -1, mx = -1;     sum = 0, days = 0;     for (int i = 0; i < up + 1; ++i) {       ++sum;       long long x = a[i], y = min(a[i + 1], p[i + 1]);       days += sum * (y - x);       ;       if (days == k) {         mn = y;         break;       } else if (days > k) {         days -= sum * (y - x);         rem = k - days;         ;         mn = a[i] + rem / sum;         break;       }     };     sum = 0, days = 0;     for (int i = n - 1; i >= down; --i) {       ++sum;       long long x = a[i], y = max(a[i - 1], p[i - 1]);       days += sum * (x - y);       ;       if (days == k) {         mx = y;         break;       } else if (days > k) {         days -= sum * (x - y);         rem = k - days;         ;         mx = a[i] - rem / sum;         break;       }     };     cout << mx - mn << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using Long = long long;   vector<vector<int>> G(100010);   int D[100010];   int dist[100010];   int P[100010];   int ep1 = -1, ep1lvl = -1, ep2 = -1, ep2lvl = -1;   void dfs(int u, int p, int lvl) {     if (lvl > ep1lvl) {       ep1lvl = lvl;       ep1 = u;     }     for (auto v : G[u]) {       if (v != p) dfs(v, u, lvl + 1);     }   }   void dfs1(int u, int p, int lvl) {     P[u] = p;     if (lvl > ep2lvl) {       ep2lvl = lvl;       ep2 = u;     }     for (auto v : G[u]) {       if (v != p) dfs1(v, u, lvl + 1);     }   }   int md;   vector<int> path;   void getMid(int u) {     while (P[u] != -1) {       path.push_back(u);       u = P[u];     }     path.push_back(u);     reverse(path.begin(), path.end());   }   bool ok = true;   int n, k;   int main() {     cin >> n >> k;     memset(D, 0, sizeof(D));     for (int i = 0; i < 100000; i++) P[i] = -1, dist[i] = 1 << 30;     int first = 0;     for (int i = 0; i < n - 1; i++) {       int u, v;       cin >> u >> v;       u--, v--;       if (!i) first = u;       G[u].push_back(v);       G[v].push_back(u);       D[u]++, D[v]++;     }     dfs(first, -1, 1);     dfs1(ep1, -1, 1);     if (ep2lvl <= k) {       puts( No );       return 0;     }     getMid(ep2);     md = path[k];     queue<int> Q;     Q.push(md);     dist[md] = 0;     while (!Q.empty()) {       int u = Q.front();       Q.pop();       if (u == md) {         if (D[u] < 3) ok = false;       } else {         if (dist[u] != k && (D[u] - 1) < 3) ok = false;         if (dist[u] == k && D[u] > 1) ok = false;       }       for (int v : G[u]) {         if (dist[v] == 1 << 30) {           dist[v] = dist[u] + 1;           Q.push(v);         }       }     }     (ok) ? puts( Yes ) : puts( No );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int ans[] = {0, 1,         0, 18,        0, 1800,                  0, 670320,    0, 734832000, 0, 890786230,                  0, 695720788, 0, 150347555, 0};     int n;     cin >> n;     cout << ans[n] <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   inline T bigmod(T p, T e, T M) {     if (e == 0) return 1;     if (e % 2 == 0) {       long long t = bigmod(p, e / 2, M);       return (T)((t * t) % M);     }     return (T)(((long long)bigmod(p, e - 1, M) * (long long)(p)) % M);   }   template <class T>   inline T gcd(T a, T b) {     if (b == 0) return a;     return gcd(b, a % b);   }   template <class T>   inline T modinverse(T a, T M) {     return bigmod(a, M - 2, M);   }   long long seg[4000001], ar[1000001], val[1000001];   void insert(int idx, int s, int e, int p, int v) {     if (s == e) {       seg[idx] = v;       return;     }     int mid = (s + e) / 2;     if (p <= mid)       insert(idx * 2 + 1, s, mid, p, v);     else       insert(idx * 2 + 2, mid + 1, e, p, v);     seg[idx] = seg[idx * 2 + 1] + seg[idx * 2 + 2];   }   long long query(int idx, int s, int e, int p) {     if (seg[idx] < p) return -1;     if (s == e) return s;     int mid = (s + e) / 2;     if (p <= seg[idx * 2 + 1])       return query(idx * 2 + 1, s, mid, p);     else       return query(idx * 2 + 2, mid + 1, e, p - seg[idx * 2 + 1]);   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     long long a, b, c, d, e, f, g, h = 1, x, y, z;     cin >> a >> b;     for (int i = (0); i < (b); ++i) cin >> ar[i];     c = 0;     for (int i = (0); i < (a); ++i) {       cin >> d;       if (d == -1) {         for (int j = (0); j < (b); ++j) {           e = query(0, 1, 1000000, ar[j] - j);           if (e == -1) break;           insert(0, 1, 1000000, e, 0);         }       } else {         c++;         val[c] = d;         insert(0, 1, 1000000, c, 1);       }     }     if (seg[0] == 0)       cout <<  Poor stack!  << endl;     else {       for (int i = (1); i < (seg[0] + 1); ++i) {         e = query(0, 1, 1000000, i);         cout << val[e];       }     }   }
#include <bits/stdc++.h>   using namespace std;   int row[1008], col[1008], n, m, a, b, cnt;   int main() {     cin >> n >> m;     for (int i = 0; i < n + 1; i++) row[i] = col[i] = true;     while (m--) {       cin >> a >> b;       row[a] = col[b] = false;     }     for (int i = 2; i < n; i++) cnt += (row[i] + col[i]);     if (n % 2) cnt -= (row[n / 2 + 1] && col[n / 2 + 1]);     cout << cnt << endl;     return 0;   }