malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   signed main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     long long t;     cin >> t;     while (t--) {       long long n, l, r;       cin >> n >> l >> r;       vector<long long> lol = {0};       for (long long i = n - 1; i >= 1; i--) {         lol.push_back(lol.back() + 2 * i);       }       for (long long x = l; x <= r; x++) {         if (x == n * (n - 1) + 1) {           cout << 1 <<    ;         } else {           long long block =               (long long)(lower_bound(lol.begin(), lol.end(), x) - lol.begin());           if (x % 2 == 1) {             cout << block <<    ;           } else {             long long h = x - lol[block - 1];             cout << h / 2 + block <<    ;           }         }       }       cout <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t != 0) {       int n;       cin >> n;       long long m = (n - 1) / 2;       long long sum = m * (m + 1) * (2 * m + 1) / 6;       long long raspuns = 8 * sum;       cout << raspuns <<   n ;       t--;     }   }
#include <bits/stdc++.h>   using namespace std;   void ensure(bool b) {     if (!b) {       cout << 0 << endl;       exit(0);     }   }   void solve() {     int n;     cin >> n;     vector<vector<int>> g(n);     vector<int> e(2 * n - 2);     for (int i = 0; i < n - 1; i++) {       int x, y;       cin >> x >> y;       x--;       y--;       g[x].emplace_back(i << 1);       e[i << 1] = y;       g[y].emplace_back(i << 1 | 1);       e[i << 1 | 1] = x;     }     vector<int> dep(n), pa(n, -1);     function<void(int, int)> dfs = [&](int u, int p) {       for (int i : g[u])         if ((i ^ p) != 1) {           int v = e[i];           dep[v] = dep[u] + 1;           pa[v] = i;           dfs(v, i);         }     };     dfs(0, -1);     auto get_path = [&](int u, int v) {       vector<int> left, right;       while (u != v) {         if (dep[u] > dep[v]) {           left.push_back(pa[u] ^ 1);           u = e[pa[u] ^ 1];         } else {           right.push_back(pa[v]);           v = e[pa[v] ^ 1];         }       }       reverse(right.begin(), right.end());       for (auto& x : right) {         left.push_back(x);       }       return left;     };     int total_diff = 0;     const int HEAD = -2, TAIL = -3;     vector<int> S(n, -1), T(n, -1), pre(2 * n - 2, -1), nxt(2 * n - 2, -1);     auto limit_path = [&](int u, int v) {       auto p = get_path(u, v);       int len = p.size();       total_diff += len;       ensure(total_diff <= 2 * n - 2);       int i;       i = p[0];       ensure(S[u] == -1 && pre[i] == -1);       pre[i] = HEAD;       S[u] = i;       i = p.back() ^ 1;       ensure(T[v] == -1 && nxt[i] == -1);       nxt[i] = TAIL;       T[v] = i;       for (int _ = 0, j; _ + 1 < len; _++) {         i = p[_], j = p[_ + 1];         u = e[i];         i ^= 1;         ensure(nxt[i] == -1 && pre[j] == -1);         nxt[i] = j;         pre[j] = i;       }     };     for (int v = 0; v < n; v++) {       int u;       cin >> u;       u--;       if (u == -1) continue;       ensure(u != v);       limit_path(u, v);     }     long long res = 1;     const long long MOD = 1e9 + 7;     vector<bool> trk(2 * n - 2, false);     for (int u = 0; u < n; u++) {       int cnt = 0;       int vis = 0;       if (S[u] != -1) {         int i = S[u];         trk[i] = true;         vis++;         while (nxt[i] >= 0) {           i = nxt[i];           ensure(!trk[i]);           trk[i] = true;           vis++;         }         if (T[u] == i) {           ensure(vis == g[u].size());         }         cnt++;       }       for (int i : g[u])         if (pre[i] == -1) {           trk[i] = true;           vis++;           while (nxt[i] >= 0) {             i = nxt[i];             ensure(!trk[i]);             trk[i] = true;             vis++;           }           cnt++;         }       ensure(vis == g[u].size());       if (S[u] != -1) cnt--;       if (T[u] != -1) cnt--;       for (int i = 1; i <= cnt; i++) {         (res *= i) %= MOD;       }     }     cout << res;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     solve();     cout << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long n, k;     cin >> n >> k;     long long a[n];     for (int i = 0; i < n; ++i) {       cin >> a[i];     }     std::map<long long, long long> m;     for (int i = 0; i < n; ++i) {       m[a[i]]++;     }     long long l = 1, r = n / k, mid;     multiset<long long> ans, s;     multiset<long long>::iterator it;     map<long long, long long> m1;     while (l <= r) {       mid = l + (r - l) / 2;       long long c = 0;       m1 = m;       s.clear();       for (int i = 0; i < n; ++i) {         if (m1[a[i]] >= mid) {           s.insert(a[i]);           c++;           m1[a[i]] -= mid;         }         if (c == k) {           break;         }       }       if (c >= k) {         ans = s;         l = mid + 1;       } else {         r = mid - 1;       }     }     for (it = ans.begin(); it != ans.end(); it++) {       cout << *it <<    ;     }     cout << endl;     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( Ofast ,  unroll-loops ,  omit-frame-pointer ,  inline )   #pragma GCC option( arch=native ,  tune=native ,  no-zero-upper )   #pragma GCC target(         sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native )   using namespace std;   int n, q, fa[66666], aa[66666], kh[66666], a[66666], p[66666], fp[66666],       siz[66666], ck, pa[66666];   vector<int> edge[66666];   int dd[66666];   void dfs(int u) {     siz[u] = 1;     p[++ck] = u;     fp[u] = ck;     pa[ck] = fp[fa[u]];     dd[ck] = dd[pa[ck]] + 1;     for (auto v : edge[u]) {       dfs(v);       siz[u] += siz[v];     }   }   int main() {     scanf( %d%d , &n, &q);     for (int i = 1; i <= n; ++i) {       scanf( %d , aa + i);     }     for (int i = 2; i <= n; ++i) {       scanf( %d , fa + i);       edge[fa[i]].push_back(i);     }     dfs(1);     for (int i = 1; i <= n; ++i) {       a[fp[i]] = aa[i];       kh[i] = -50001;     }     for (int i = 1; i <= q; ++i) {       int x;       scanf( %d , &x);       int y = siz[x];       x = fp[x];       int pp = i + 1, *jj = kh + x, *diao = dd + x, *aa = a + x;       int ans = 0, cnt = 0;       for (int j = 0; j < y; ++j) {         if (jj[j] + aa[j] < pp) {           jj[j] = i;           ans += diao[j];           cnt++;         }       }       ans = ans - cnt * dd[x];       printf( %d %d n , ans, cnt);     }   }
#include <bits/stdc++.h>   #pragma comment(linker,  /stack:256000000 )   using namespace std;   int main() {     int n;     scanf( %d , &(n));     vector<int> v1(n), v2(n), v3(n);     if (!(n % 2)) {       printf( -1 n );       return 0;     }     for (int i = (0), endi = (n); i < endi; ++i) v1[i] = i;     for (int i = (0), endi = (n); i < endi; ++i) v2[i] = (i + 1) % n;     for (int i = (0), endi = (n); i < endi; ++i) v3[i] = (v1[i] + v2[i]) % n;     for (int i = (0), endi = ((v1).size()); i < endi; ++i) {       printf( %d  , (v1[i]));     };     printf(  n );     for (int i = (0), endi = ((v2).size()); i < endi; ++i) {       printf( %d  , (v2[i]));     };     printf(  n );     for (int i = (0), endi = ((v3).size()); i < endi; ++i) {       printf( %d  , (v3[i]));     };     printf(  n );   }
#include <bits/stdc++.h>   using namespace std;   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     long long int n, t, x, y, a = 0, b = 0, suma = 0, sumb = 0;     cin >> n;     while (n--) {       cin >> t >> x >> y;       if (t == 1) {         a++;         suma += x;       } else {         b++;         sumb += x;       }     }     if (suma >= 5 * a)       cout <<  LIVE ;     else       cout <<  DEAD ;     cout << endl;     if (sumb >= 5 * b)       cout <<  LIVE ;     else       cout <<  DEAD ;   }
#include <bits/stdc++.h>   using namespace std;   const long long INF = 1e15;   struct Edge {     int t, w;   } e[100010 << 1];   queue<int> g[100010];   long long d[100010], f[100010];   int i, j, k, n, m, q, x, h[100010];   struct _ {     int x;     _(int x) : x(x) {}     bool operator<(const _& a) const { return d[x] > d[a.x]; }   };   priority_queue<_> Q;   vector<int> V[100010];   int done[100010 << 2];   inline void Dij() {     for (i = 2; i <= n; i++) d[i] = INF;     Q.push(1);     while (!Q.empty()) {       x = Q.top().x;       Q.pop();       for (int j : V[x])         if (d[e[j].t] > d[x] + e[j].w) {           d[e[j].t] = d[x] + e[j].w;           Q.push(e[j].t);         }     }   }   int main() {     scanf( %d%d%d , &n, &m, &q);     for (int i = 1; i <= m; ++i) {       scanf( %d%d%d , &x, &e[i].t, &e[i].w);       V[x].push_back(i);     }     Dij();     for (int i = 1; i <= q; ++i) {       scanf( %d%d , &x, &k);       if (x == 1)         printf( %lld n , d[k] >= INF ? -1 : d[k]);       else {         for (int i = 1; i <= k; ++i) scanf( %d , &x), e[x].w++;         for (int i = 2; i <= n; ++i) f[i] = INF;         g[m = 0].push(1);         k = min(k, n - 1);         for (int i = 0; i <= m; ++i)           while (!g[i].empty()) {             x = g[i].front();             g[i].pop();             if (i > f[x]) continue;             for (int j : V[x]) {               long long y = f[x] + d[x] + e[j].w - d[e[j].t];               if (f[e[j].t] > y) {                 f[e[j].t] = y;                 if (y <= k) {                   g[y].push(e[j].t);                   if (y > m) m = y;                 }               }             }           }         for (int i = 2; i <= n; ++i) d[i] = min(INF, d[i] + f[i]);       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const long long LL_INF = 0x3f3f3f3f3f3f3f3f;   const int xx[4] = {1, -1, 0, 0};   const int yy[4] = {0, 0, 1, -1};   int inline in() {     int x = 0, c;     for (; (unsigned)((c = getchar()) -  0 ) >= 10;) {       if (c ==  - ) return -in();       if (!~c) throw ~0;     }     do {       x = (x << 3) + (x << 1) + (c -  0 );     } while ((unsigned)((c = getchar()) -  0 ) < 10);     return x;   }   int main() {     cin.sync_with_stdio(false);     cin.tie(0);     int n, t;     string buf;     cin >> n >> t >> buf;     int i = buf.find( . ) + 1;     while (i < n && buf[i] <  5 ) i++;     if (i == n) {       cout << buf << endl;       return 0;     }     while (t-- && buf[i] >=  5 ) {       i--;       bool flag = (buf[i] ==  . );       if (flag) i--;       buf[i]++;       if (flag) break;     }     int len = i + 1;     for (; i >= 1 && buf[i] ==  9  + 1; i--) {       buf[i] =  0 ;       buf[i - 1]++;     }     if (buf[0] ==  9  + 1) {       buf[0] =  0 ;       buf =  1  + buf;       len++;     }     buf.resize(len);     cout << buf << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, i, e = 0, o = 0, k, p, j;     long long int arr[100005];     vector<long long int> v[100005], od, ev;     cin >> n >> k >> p;     for (i = 0; i < n; i++) {       cin >> arr[i];       if (arr[i] % 2 == 0) {         ev.push_back(arr[i]);         e++;       } else {         od.push_back(arr[i]);         o++;       }     }     if (o < (k - p)) {       cout <<  NO n ;       return 0;     }     o = o - k + p;     if (o % 2 == 1) {       cout <<  NO n ;       return 0;     }     if ((e + (o) / 2) < p) {       cout <<  NO n ;       return 0;     }     cout <<  YES n ;     int j1 = 0, j2 = k - p;     for (i = 0; i < od.size(); i++) {       j1++;       if (j1 <= k - p) {         v[j1].push_back(od[i]);       } else {         j2++;         if (j2 > k) {           j2 = k;         }         v[j2].push_back(od[i]);         i++;         v[j2].push_back(od[i]);       }     }     for (i = 0; i < ev.size(); i++) {       j2++;       if (j2 <= k) {         v[j2].push_back(ev[i]);       } else {         v[k].push_back(ev[i]);       }     }     for (i = 1; i <= k; i++) {       cout << v[i].size() <<    ;       for (j = 0; j < v[i].size(); j++) {         cout << v[i][j] <<    ;       }       cout <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   template <class T_T>   T_T gcd(T_T a, T_T b) {     return b ? gcd(b, a % b) : a;   }   template <class T_T>   T_T f_max(T_T a, T_T b) {     return a > b ? a : b;   }   using namespace std;   const int N = 100000;   int a[105][105], r[105], c[105], cnt_r[105], cnt_c[105], ans;   int main() {     int n, m, i, j;     scanf( %d%d , &n, &m);     for (i = 1; i <= n; i++)       for (j = 1; j <= m; j++) {         scanf( %d , &a[i][j]);         r[i] += a[i][j];         c[j] += a[i][j];       }     queue<int> q;     for (i = 1; i <= n; i++)       if (r[i] < 0) q.push(i);     for (i = 1; i <= m; i++)       if (c[i] < 0) q.push(i + n);     while (!q.empty()) {       int v = q.front();       q.pop();       if (v <= n) {         if (r[v] >= 0) continue;         cnt_r[v]++;         r[v] = -r[v];         for (i = 1; i <= m; i++) {           c[i] -= 2 * a[v][i];           a[v][i] = -a[v][i];           if (c[i] < 0) q.push(i + n);         }       } else {         v -= n;         if (c[v] >= 0) continue;         cnt_c[v]++;         c[v] = -c[v];         for (i = 1; i <= n; i++) {           r[i] -= 2 * a[i][v];           a[i][v] = -a[i][v];           if (r[i] < 0) q.push(i);         }       }     }     for (i = 1, ans = 0; i <= n; i++)       if (cnt_r[i] & 1) ans++;     printf( %d  , ans);     for (i = 1; i <= n; i++)       if (cnt_r[i] & 1) printf( %d  , i);     puts(  );     for (i = 1, ans = 0; i <= m; i++)       if (cnt_c[i] & 1) ans++;     printf( %d  , ans);     for (i = 1; i <= m; i++)       if (cnt_c[i] & 1) printf( %d  , i);     puts(  );   }
#include <bits/stdc++.h>   using namespace std;   int n, k;   char s[1000005];   int main() {     scanf( %d%d%s , &n, &k, s);     for (int i = 0; i < n && k; ++i) {       if (s[i] ==  4  && s[i + 1] ==  7  && s[i + 2] ==  7  && !(i & 1)) k %= 2;       if (k && s[i] ==  4  && s[i + 1] ==  7 ) {         if (i & 1)           s[i] = s[i + 1];         else           s[i + 1] = s[i];         --i, --i, --k;       }     }     printf( %s , s);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void solve() {     long long int n, m, a = 0, b = 0, c = 0, d, h, p, x, y, z, i = 0, j = 0,                         k = 0, l, r, rem, time = 0, ans = 0, mini = 1e18 + 1,                         maxi = 0, count = 0, sum = 0, sign = 0, xx, yy, zz;     cin >> n;     if (n >= 22 || n <= 10)       cout <<  0             <<   n ;     else if (n > 10 && n < 20 || n == 21)       cout <<  4             <<   n ;     else if (n == 20)       cout <<  15             <<   n ;   }   void fast() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);   }   int main() {     fast();     int t = 1;     while (t--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     vector<int> r;     for (int i = 0; i < n; i++) {       int tmp;       cin >> tmp;       r.push_back(tmp);     }     int m_lng = 0;     for (int i = 0; i < n; i++) {       int cnt = 1;       int lng = 0;       int sum = 0;       for (int j = i; j < n; j++) {         sum += r[j];         if (sum > 100 * cnt) lng = cnt;         cnt++;       }       if (m_lng < lng) m_lng = lng;     }     cout << m_lng;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int fact[500005];   void criba() {     for (int i = 2; i * i < 500005; i++)       if (fact[i] == 0)         for (int j = i * i; j < 500005; j += i) fact[j] = i;     for (int i = 2; i < 500005; i++)       if (fact[i] == 0) fact[i] = i;   }   bool vis[500005];   int F[500005], a[500005];   int mask[1 << 9], primes[9];   vector<pair<int, int> > G[500005];   int main() {     int n, q;     criba();     while (cin >> n >> q) {       for (int i = 0; i < n; i++) {         scanf( %d , &a[i]);         int num = a[i], top = 0;         while (num > 1) {           int f = fact[num];           while (num % f == 0) num /= f;           primes[top++] = f;         }         mask[0] = 1;         for (int j = 1, l; j < (1 << top); j++) {           l = 31 - __builtin_clz(j & -j);           mask[j] = mask[j ^ (1 << l)] * primes[l];           if (__builtin_popcount(j) % 2 == 0)             G[i].push_back(make_pair(mask[j], 0));           else             G[i].push_back(make_pair(mask[j], 1));         }       }       long long pos, cur = 0, last = 0;       long long ans, val, id;       for (int i = 0; i < q; i++) {         scanf( %d , &pos);         pos--;         ans = cur;         if (vis[pos]) {           for (int j = 0; j < G[pos].size(); j++) {             val = G[pos][j].first;             id = G[pos][j].second;             if (id)               ans -= F[val];             else               ans += F[val];             F[val]--;           }           cur--;         } else {           for (int j = 0; j < G[pos].size(); j++) {             val = G[pos][j].first;             id = G[pos][j].second;             if (id)               ans -= F[val];             else               ans += F[val];             F[val]++;           }           cur++;         }         if (vis[pos] && a[pos] == 1) ans--;         if (vis[pos])           ans = last - ans;         else           ans = last + ans;         vis[pos] = 1 - vis[pos];         printf( %I64d n , ans);         last = ans;       }     }   }
#include <bits/stdc++.h>   int main() {     int n, m, a[1003], b[1003], i, j, count = 0, k = 0, flag = 0;     scanf( %d %d , &n, &m);     for (i = 0; i < n; i++) {       scanf( %d , &a[i]);     }     for (i = 0; i < m; i++) {       scanf( %d , &b[i]);     }     for (i = 0; i < m; i++) {       for (j = k; j < n; j++) {         if (b[i] >= a[j]) {           count++;           flag = 1;           break;         }       }       if (flag == 1) {         k = j + 1;       } else if (flag == 0) {         break;       }       flag = 0;     }     printf( %d n , count);   }
#include <bits/stdc++.h>   using namespace std;   int n, c[3010];   struct info {     int x, y;   };   struct as {     int a, b, c;   } ans;   struct node {     int x, id;   } a[3010];   inline bool cmp(node a, node b) { return a.x > b.x; }   inline info max(info a, info b) {     if (a.x < b.x) return b;     return a;   }   struct seg {     int lt[12010], rt[12010];     info mx[12010];     inline void build(int i, int l, int r) {       lt[i] = l;       rt[i] = r;       if (l == r) {         mx[i] = (info){a[l].x - a[l + 1].x, l};         return;       }       int mid = l + r >> 1;       build(i * 2, l, mid);       build(i * 2 + 1, mid + 1, r);       mx[i] = max(mx[i * 2], mx[i * 2 + 1]);     }     inline info query(int i, int l, int r) {       if (l <= lt[i] && r >= rt[i]) return mx[i];       int mid = lt[i] + rt[i] >> 1;       info ans = {-1, 0};       if (l <= mid) ans = query(i * 2, l, r);       if (r > mid) ans = max(ans, query(i * 2 + 1, l, r));       return ans;     }   } A;   inline as max(as t1, as t2) {     if (t1.a == 0) return t2;     if (a[t1.a].x - a[t1.a + 1].x != a[t2.a].x - a[t2.a + 1].x)       return a[t1.a].x - a[t1.a + 1].x > a[t2.a].x - a[t2.a + 1].x ? t1 : t2;     if (a[t1.b].x - a[t1.b + 1].x != a[t2.b].x - a[t2.b + 1].x)       return a[t1.b].x - a[t1.b + 1].x > a[t2.b].x - a[t2.b + 1].x ? t1 : t2;     if (a[t1.c].x - a[t1.c + 1].x != a[t2.c].x - a[t2.c + 1].x)       return a[t1.c].x - a[t1.c + 1].x > a[t2.c].x - a[t2.c + 1].x ? t1 : t2;   }   int main() {     cin >> n;     for (int i = 1; i <= n; i++) scanf( %d , &a[i].x), a[i].id = i;     sort(a + 1, a + n + 1, cmp);     A.build(1, 1, n);     for (int i = 1; i <= n; i++)       for (int j = i + 1; j < n; j++)         if (2 * (j - i) >= i && i * 2 >= j - i) {           int lk = max(j + (max(i, j - i) + 1) / 2, j + 1),               rk = min(j + 2 * min(i, j - i), n);           if (lk <= rk) ans = max(ans, (as){i, j, A.query(1, lk, rk).y});         }     for (int i = 1; i <= ans.a; i++) c[a[i].id] = 1;     for (int i = ans.a + 1; i <= ans.b; i++) c[a[i].id] = 2;     for (int i = ans.b + 1; i <= ans.c; i++) c[a[i].id] = 3;     for (int i = ans.c + 1; i <= n; i++) c[a[i].id] = -1;     for (int i = 1; i <= n; i++) printf( %d  , c[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int A, B;   char a[5555];   char b[5555];   int dp[5555][5555];   int main() {     scanf( %d%d , &A, &B);     scanf( %s%s , a + 1, b + 1);     int ans = 0;     int i, j;     for (i = 1; i <= A; i++) {       for (j = 1; j <= B; j++) {         if (a[i] == b[j]) dp[i][j] = max(dp[i][j], dp[i - 1][j - 1] + 2);         dp[i][j] = max(dp[i][j], dp[i - 1][j] - 1);         dp[i][j] = max(dp[i][j], dp[i][j - 1] - 1);         ans = max(ans, dp[i][j]);       }     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int x, l;     int cnt = 0;     for (int i = 0; i < n; i++) {       cnt = 0;       cin >> x;       if (x % 7 != 0) {         cnt++;       }       x /= 7;       cout << x + cnt << endl;     }     return 0;   }
#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:36777216 )   using namespace std;   long long pow_mod(long long x, long long y, long long z) {     long long res = 1;     while (y) {       if (y & 1) res *= x, res %= z;       x *= x, x %= z, y >>= 1;     }     return res % z;   }   void ext_gcd(long long a, long long b, long long &d, long long &x,                long long &y) {     if (!b) {       d = a, x = 1, y = 0;     } else {       ext_gcd(b, a % b, d, y, x), y -= x * (a / b);     }   }   long long inv(long long a, long long c) {     long long d, x, y;     ext_gcd(a, c, d, x, y);     return (x + c) % c;   }   long long fac[111111];   long long C(int x, int y) {     if (x < y) return 0;     return fac[x] * inv(fac[y], 1000000007) % 1000000007 *            inv(fac[x - y], 1000000007) % 1000000007;   }   int n, v;   vector<pair<int, int> > vec;   long long gao(int l, int r, int pre) {     if (l < 1) return 0;     if (r > n) return 0;     long long res;     if (pre == 1)       res = 1;     else       res = pow_mod(2, pre - 2, 1000000007);     for (int i = 1; i < vec.size(); i++) {       if (vec[i].second > r) {         res *= C(vec[i].first - pre - 1, vec[i].second - r - 1);         res %= 1000000007;         if (res == 0) return 0;         l = l - (vec[i].first - pre - 1 - (vec[i].second - r - 1));         r = vec[i].second;       } else if (vec[i].second < l) {         res *= C(vec[i].first - pre - 1, l - vec[i].second - 1);         res %= 1000000007;         if (res == 0) return 0;         r = r + (vec[i].first - pre - 1 - (l - vec[i].second - 1));         l = vec[i].second;       } else         return 0;       if (i == vec.size() - 1) return res;       if (r > n || l < 1) return 0;       pre = vec[i].first;     }     return res;   }   int main() {     fac[0] = 1;     for (int i = 1; i <= 100000; i++) fac[i] = fac[i - 1] * i % 1000000007;     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , &v);       if (v) vec.push_back(make_pair(v, i));     }     if (vec.size() == 0) {       printf( %I64d n , pow_mod(2, n - 1, 1000000007));       return 0;     }     vec.push_back(make_pair(n + 1, n + 1));     sort(vec.begin(), vec.end());     long long ans;     if (vec[0].first == 1)       ans = gao(vec[0].second, vec[0].second, 1);     else       ans = gao(vec[0].second - vec[0].first + 1, vec[0].second, vec[0].first) +             gao(vec[0].second, vec[0].second + vec[0].first - 1, vec[0].first) %                 1000000007;     printf( %I64d n , ans);   }