malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   using namespace std;   const int maxn = 1e6 + 10;   const int md = 1e9 + 7;   long long FAC[maxn], iFAC[maxn];   long long dp[maxn];   vector<tuple<int, int>> a;   long long mpow(long long a, long long b) {     if (b == 0) return 1;     long long res = mpow(a, b / 2);     res *= res;     res %= md;     if (b & 1ll) {       res *= a;       res %= md;     }     return res;   }   long long inv(long long a) { return mpow(a, md - 2); }   void pre_calc() {     FAC[0] = FAC[1] = 1;     for (int i = 2; i <= 200000; i++) FAC[i] = (FAC[i - 1] * i) % md;     iFAC[0] = iFAC[1] = 1;     for (int i = 2; i <= 200000; i++) iFAC[i] = (iFAC[i - 1] * inv(i)) % md;   }   int T;   string str;   int x, y, n, m;   int nk;   void task() {     cin >> n >> m >> nk;     for (int i = 0; i < nk; ++i) {       cin >> x >> y;       --x;       --y;       a.emplace_back(x, y);     }     --n;     --m;     a.emplace_back(n, m);     sort(a.begin(), a.end());     for (int i = 0; i < a.size(); ++i) {       int xi = get<0>(a[i]), yi = get<1>(a[i]);       dp[i] = FAC[xi + yi] * iFAC[xi] % md * iFAC[yi] % md;       for (int j = 0; j < i; ++j) {         int xj = get<0>(a[j]), yj = get<1>(a[j]);         long long mul =             FAC[xi + yi - xj - yj] * iFAC[xi - xj] % md * iFAC[yi - yj] % md;         dp[i] = (dp[i] - dp[j] * mul % md) % md;       }     }     cout << (dp[a.size() - 1] + md) % md << endl;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     pre_calc();     T = 1;     while (T--) {       task();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int d1, d2, d3;     cin >> d1 >> d2 >> d3;     int s1 = d1 + d3 + d2;     int s2 = 2 * d1 + 2 * d3;     int s3 = 2 * d2 + 2 * d1;     int s4 = 2 * d2 + 2 * d3;     cout << min(s1, min(s2, min(s3, s4)));   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int i = 0, a = 0, b = 0, c = 0;     string s;     cin >> s;     for (; i < s.length(); i++) {       if (s[i] ==  a )         a++;       else         break;     }     for (; i < s.length(); i++) {       if (s[i] ==  b )         b++;       else         break;     }     for (; i < s.length(); i++) {       if (s[i] ==  c )         c++;       else         break;     }     if (i != s.length() || (c != a && c != b) || a == 0 || b == 0)       cout <<  NO  << endl;     else       cout <<  YES  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   long long f[5020][5020], a[5020], powk[5020], ans, ans2, invn;   int n, k;   inline long long power(long long x, long long y) {     long long res = 1;     while (y) {       if (y & 1) res = res * x % mod;       x = x * x % mod;       y >>= 1;     }     return res;   }   void init() {     powk[0] = 1;     for (register int i = 1; i <= n; i++)       powk[i] = powk[i - 1] * (k - i + 1) % mod;     invn = mod - power(n, mod - 2);   }   int main() {     scanf( %d %d , &n, &k);     init();     ans = 1;     for (register int i = 1; i <= n; i++)       scanf( %lld , &a[i]), ans = ans * a[i] % mod;     f[0][0] = 1;     for (register int i = 1; i <= n; i++) {       f[i][0] = 1;       for (register int j = 1; j <= i; j++) {         f[i][j] = (f[i - 1][j] + f[i - 1][j - 1] * a[i]) % mod;       }     }     for (register int i = 0; i <= n; i++) {       ans2 = (ans2 + f[n][i] * power(invn, n - i) % mod * powk[n - i]) % mod;     }     cout << (ans - ans2 + mod) % mod << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int dr[] = {+1, -1, +0, +0, +1, -1, +1, -1};   const int dc[] = {+0, +0, +1, -1, +1, -1, -1, +1};   const int ms[] = {+31, +29, +31, 30, +31, +30, +31, +31, +30, +31, +30, +31};   const int N = 200 + 5;   const int MOD = 1e9 + 7;   void add(int &a, int b) {     a += b;     while (a >= MOD) a -= MOD;   }   int dp[N][N][N];   int n, first[N];   string w;   int failure(char letra, int idx) {     if (idx >= (int)w.size()) return (int)w.size();     while (idx > 0 && letra != w[idx]) {       idx = first[idx - 1];     }     return idx + (w[idx] == letra);   }   void KMP() {     first[0] = 0;     for (int i = 1; i < (int)(int)w.size(); i++) {       first[i] = failure(w[i], first[i - 1]);     }   }   int solve(int p = 0, int streak = 0, int score = 0) {     if (score < 0) return 0;     if (p >= 2 * n) return (streak == (int)w.size() && score == 0);     int &rec = dp[p][streak][score];     if (~rec) return rec;     rec = 0;     add(rec, solve(p + 1, failure( ( , streak), score + 1));     add(rec, solve(p + 1, failure( ) , streak), score - 1));     return rec;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n >> w;     KMP();     memset(dp, -1, sizeof(dp));     cout << solve() <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, k;     int m;     cin >> n >> m >> k;     set<long long> removal;     for (int i = 0; i < m; i++) {       long long x;       cin >> x;       removal.insert(x);     }     long long total = 0;     long long offset = 0;     set<long long>::iterator itr = removal.begin();     while (itr != removal.end()) {       auto num = *itr;       auto cur_offset = offset;       auto a = num - offset;       auto r = a % k, d = a / k;       long long K = 0;       if (r == 0) {         K = a;       } else {         K = k * (d + 1);       }       total++;       do {         offset++;         itr++;       } while (itr != removal.end() && *itr - cur_offset <= K);     }     cout << total << endl;     ;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 3e5 + 4;   const int maxlog = 22;   const int mod = 1e9 + 7;   const int sq = 350;   int deg[maxn], cnt[maxn];   map<pair<int, int>, int> m;   long long ans = 0;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cout.precision(20);     int n, p;     cin >> n >> p;     for (int i = 0; i < n; i++) {       int u, v;       cin >> u >> v;       deg[u]++, deg[v]++;       if (u > v) swap(u, v);       m[make_pair(u, v)]++;     }     for (int i = 1; i <= n; i++) cnt[deg[i]]++;     for (int i = n; i >= 0; i--) cnt[i] += cnt[i + 1];     for (int i = 1; i <= n; i++) {       int x = max(0, p - deg[i]);       ans += (long long)cnt[x];       if (2 * deg[i] >= p) ans--;     }     ans /= 2;     for (map<pair<int, int>, int>::iterator it = m.begin(); it != m.end(); it++) {       int u = (*it).first.first, v = (*it).first.second;       int cnt = (*it).second;       if (deg[u] + deg[v] >= p && deg[u] + deg[v] - cnt < p) ans--;     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long m, n, q = 998244853, sum = 1, a = 1, b = 1, r = 0, x = 208513042, y,                     z;     cin >> n >> m;     if (n == 0) {       cout << 0;       return 0;     }     if (m == 0) {       cout << n;       return 0;     }     for (long long i = 1; i < min(m, n); i++) {       a = (a * (m + n + 1 - i)) % q;       b = (b * i) % q;       r = ((a % b) + r * i) % q;       sum = (sum + a / b) % q;     }     a = (a * (m + n + 1 - min(m, n))) % q;     b = (b * min(m, n)) % q;     r = (r * min(m, n)) % q;     for (long long j = 1 + min(m, n); j <= 2000; j++) {       a = (a * j) % q;       b = (b * j) % q;       r = (r * j) % q;     }     y = (r * x) % q;     sum = (sum + y) % q;     if (n > m) {       y = (a * x) % q;       z = (y * (n - m)) % q;       sum = (sum + z) % q;     }     cout << sum;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int len[55];   int n;   struct node {     int x, y, s;   } arr[55 * 55];   int ans[55 * 55][2];   int main() {     int i, j, tmp, k;     while (scanf( %d , &n) != EOF) {       for (i = 1; i <= n; i++) scanf( %d , &len[i]);       k = 0;       for (i = 1; i <= n; i++)         for (j = 1; j <= len[i]; j++) {           scanf( %d , &tmp);           arr[k].x = i;           arr[k].y = j;           arr[k++].s = tmp;         }       int mi, t, m = 0;       for (i = 0; i < k - 1; i++) {         mi = arr[i].s;         t = i;         for (j = i + 1; j < k; j++)           if (arr[j].s < mi) {             mi = arr[j].s;             t = j;           }         if (t != i) {           ans[m][0] = i;           ans[m++][1] = t;           swap(arr[i].s, arr[t].s);         }       }       printf( %d n , m);       for (i = 0; i < m; i++)         printf( %d %d %d %d n , arr[ans[i][0]].x, arr[ans[i][0]].y,                arr[ans[i][1]].x, arr[ans[i][1]].y);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     scanf( %d , &t);     while (t--) {       int n, ans = 0, num[101], temp, minn = 1e9 + 7, maxx = 0, ann;       for (int i = 1; i <= 100; i++) num[i] = 0;       scanf( %d , &n);       for (int i = 1; i <= n; i++) {         scanf( %d , &temp);         num[temp]++;         minn = min(minn, temp);         maxx = max(maxx, temp);       }       for (int i = 2; i <= maxx * 2; i++) {         int sum = 0;         for (int j = 1; j <= i / 2; j++)           if (j != i - j)             sum += min(num[j], num[i - j]);           else             sum += num[j] / 2;         if (sum > ans) {           ans = sum;         }       }       printf( %d n , ans);     }   }
#include <bits/stdc++.h>   const int N = 2005;   using namespace std;   bitset<N> f[N];   int n;   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         int t;         scanf( %d , &t);         if (t > 0) f[i][j] = 1;       }     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++)         if (f[i][j]) {           f[i] |= f[j];         }     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++)         if (f[i][j]) {           f[i] |= f[j];         }     }     for (int i = 1; i <= n; i++) {       if (f[i].count() != n) {         printf( NO );         return 0;       }     }     printf( YES );     return 0;   }
#include <bits/stdc++.h>   int main() {     int a, b, c;     scanf( %d%d%d , &a, &b, &c);     if ((a + b) == c || (c + b) == a || (a + c) == b) {       printf( 1 );     } else {       if ((a + b) < c) {         printf( %d , (c - b - a + 1));       } else if (b + c < a) {         printf( %d , (a - b - c + 1));       } else if (c + a < b) {         printf( %d , (b - c - a + 1));       } else {         printf( 0 );       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   int cnt[3], seen[3];   string s;   int main() {     ios::sync_with_stdio(0);     cin >> n >> s;     int m = n / 3;     for (int i = 0; i < n; i++) {       cnt[s[i] -  0 ]++;     }     for (int i = 0; i < n; i++) {       if (cnt[s[i] -  0 ] > m) {         for (long long j = 0; j < 3; j++) {           if (cnt[j] < m) {             if (j > s[i] -  0  && seen[s[i] -  0 ] < m) break;             cnt[j]++;             cnt[s[i] -  0 ]--;             s[i] = j +  0 ;           }         }       }       seen[s[i] -  0 ]++;     }     cout << s << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void solve() {     int n, k, z;     cin >> n >> k >> z;     int a[n];     for (int i = 0; i < n; i++) {       cin >> a[i];     }     int ans = 0;     for (int i = 0; i <= z; i++) {       int kol = k - 2 * i;       if (kol < 0) {         continue;       }       int tren = 0;       int maxa = 0;       for (int j = 0; j < kol + 1; j++) {         tren += a[j];         if (j < n - 1) {           maxa = max(a[j] + a[j + 1], maxa);         }       }       tren += i * maxa;       ans = max(ans, tren);     }     cout << ans << endl;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int t = 1;     cin >> t;     while (t--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   inline void remax(T& A, T B) {     if (A < B) A = B;   }   template <class T>   inline void remin(T& A, T B) {     if (A > B) A = B;   }   string ToString(long long num) {     string ret;     do {       ret += ((num % 10) +  0 );       num /= 10;     } while (num);     reverse(ret.begin(), ret.end());     return ret;   }   long long ToNumber(string s) {     long long r = 0, p = 1;     for (int i = s.size() - 1; i >= 0; --i) r += (s[i] -  0 ) * p, p *= 10;     return r;   }   long long Gcd(long long a, long long b) {     while (a %= b ^= a ^= b ^= a)       ;     return b;   }   long long Power(long long base, long long power) {     long long ret = 1;     while (power) {       if (power & 1) ret *= base;       power >>= 1;       base *= base;     }     return ret;   }   long long PowerMod(long long base, long long power, long long mod) {     if (!power) return 1;     if (power & 1) return (base * PowerMod(base, power - 1, mod)) % mod;     return PowerMod((base * base) % mod, power >> 1, mod);   }   int Log(long long num, long long base) {     int ret = 0;     while (num) {       ++ret;       num /= base;     }     return ret;   }   int Count(long long mask) {     int ret = 0;     while (mask) {       if (mask & 1) ++ret;       mask >>= 1;     }     return ret;   }   inline void run() {     unsigned long long ans;     long long n;     scanf( %I64d , &n);     ans = n * 3;     ans *= (n + 1);     cout << ++ans <<   n ;   }   int main() {     FILE* input = stdin;     FILE* output = stdout;     while (!feof(input)) {       run();       break;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int i, j, n;   void write(int X) {     if (X < 0) putchar( - ), X = -X;     if (X > 9) write(X / 10);     putchar(X % 10 | 48);   }   void print(int k) {     int h;     for (h = 1; h <= (4); h++) {       write(((i - 1) << 2) + h);       putchar(   );       write(((j - 1) << 2) + (!((h + k) % 4) ? 4 : (h + k) % 4));       putchar(  n );     }   }   int main() {     cin >> n;     if (n % 4 == 2 || n % 4 == 3) puts( NO ), exit(0);     puts( YES );     for (i = 1; i <= (n >> 2); i++) {       if (n % 4 == 1) {         write(((i - 1) << 2) + 1);         putchar(   );         write(n);         putchar(  n );       }       write(((i - 1) << 2) + 1);       putchar(   );       write(((i - 1) << 2) + 3);       putchar(  n );       if (n % 4 == 1) {         write(((i - 1) << 2) + 3);         putchar(   );         write(n);         putchar(  n );       }       if (n % 4 == 1) {         write(((i - 1) << 2) + 2);         putchar(   );         write(n);         putchar(  n );       }       write(((i - 1) << 2) + 2);       putchar(   );       write(((i - 1) << 2) + 4);       putchar(  n );       if (n % 4 == 1) {         write(((i - 1) << 2) + 4);         putchar(   );         write(n);         putchar(  n );       }       write(((i - 1) << 2) + 1);       putchar(   );       write(((i - 1) << 2) + 2);       putchar(  n );       write(((i - 1) << 2) + 3);       putchar(   );       write(((i - 1) << 2) + 4);       putchar(  n );       write(((i - 1) << 2) + 2);       putchar(   );       write(((i - 1) << 2) + 3);       putchar(  n );       write(((i - 1) << 2) + 1);       putchar(   );       write(((i - 1) << 2) + 4);       putchar(  n );     }     for (i = 1; i <= ((n >> 2) - 1); i++)       for (j = i + 1; j <= (n >> 2); j++) {         print(2), print(1);         print(3), print(0);       }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long t;     cin >> t;     while (t--) {       long long n;       cin >> n;       long long arr[n];       for (long long i = 0; i < n; i++) {         cin >> arr[i];       }       long long b[n];       if (n % 2 == 0) {         for (long long i = 0; i < n - 1; i = i + 2) {           b[i] = arr[i + 1];           b[i + 1] = -1 * arr[i];         }         for (long long i = 0; i < n; i++) {           cout << b[i] <<    ;         }         cout <<   n ;       } else {         for (long long i = 3; i < n - 1; i = i + 2) {           b[i] = arr[i + 1];           b[i + 1] = -1 * arr[i];         }         if (arr[0] + arr[1] != 0) {           cout << -arr[2] <<     << -arr[2] <<     << arr[0] + arr[1] <<    ;         } else if (arr[1] + arr[2] != 0) {           cout << arr[1] + arr[2] <<     << -arr[0] <<     << -arr[0] <<    ;         } else {           cout << -arr[1] <<     << arr[0] + arr[2] <<     << -arr[1] <<    ;         }         for (long long i = 3; i < n; i++) {           cout << b[i] <<    ;         }         cout <<   n ;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int dr[]{-1, -1, 0, 1, 1, 1, 0, -1};   const int dc[]{0, 1, 1, 1, 0, -1, -1, -1};   void run() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);   }   void solve() {     int n, m;     cin >> n >> m;     vector<pair<int, int>> v(m);     vector<int> id;     for (auto &it : v) {       cin >> it.first >> it.second;       id.push_back(it.first);     }     sort(id.rbegin(), id.rend());     vector<long long> sum(1, 0);     for (auto &it : id) sum.push_back(it + sum.back());     long long mx = sum[min(n, m)];     for (auto &it : v) {       int tmp_n = n;       int j = upper_bound(id.begin(), id.end(), it.second, greater<int>()) -               id.begin();       long long cur = 0;       if (it.first < it.second) {         cur += it.first;         tmp_n--;       }       j = min(j, tmp_n);       cur += sum[j];       tmp_n -= j;       cur += 1LL * tmp_n * it.second;       mx = max(mx, cur);     }     cout << mx <<   n ;   }   int main() {     run();     int T;     cin >> T;     while (T--) {       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   signed main() {     ios_base::sync_with_stdio;     cin.tie(NULL);     long long i, j, n, t, k, m;     cin >> t;     while (t--) {       cin >> n >> k;       vector<long long> s(n);       for (long long i = 0; i < n; i++) {         cin >> s[i];       }       map<long long, queue<long long>> m;       for (long long i = 0; i < n; i++) {         m[s[i]].push(i);       }       vector<long long> res(n + 1, 0);       long long ans = 0;       long long count = 0;       long long col = 1;       vector<long long> v;       for (auto i : m) {         if (i.second.size() >= k) {           long long kk = k;           col = 1;           while (!i.second.empty() && kk > 0) {             res[i.second.front()] = col;             col++;             kk--;             i.second.pop();           }         } else {           while (!i.second.empty()) {             v.push_back(i.second.front());             i.second.pop();           }         }       }       if (v.size() >= k) {         long long sz = v.size();         long long st = sz / k;         st = st * k;         long long col = 1;         for (long long i = 0; i < st; i++) {           res[v[i]] = col;           col++;           if (col == k + 1) {             col = 1;           }         }       }       for (long long i = 0; i < n; i++) {         cout << res[i] <<    ;       }       cout <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     scanf( %d , &t);     while (t--) {       int n;       scanf( %d , &n);       char s[n + 1];       scanf( %s , s + 1);       int a[100] = {0}, b[100] = {0};       int aa = 0, bb = 0;       for (int i = 1; i <= n; i++) {         if (s[i] ==  a ) {           aa++;           b[i] = b[i - 1];           a[i] = a[i - 1] + 1;         } else {           bb++;           a[i] = a[i - 1];           b[i] = b[i - 1] + 1;         }       }       int flag = 1;       if (aa == 0 || bb == 0) {         printf( -1 -1 n );         continue;       } else {         for (int i = 1; i <= n; i++) {           if (flag == 1)             for (int j = n; j >= i; j--) {               if (a[j] - a[i - 1] == b[j] - b[i - 1]) {                 printf( %d %d n , i, j);                 flag = 0;                 break;               }             }           else             break;         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, u, r, i;   bool flag = false;   long long max_score = 0;   vector<long long> a, b, k, p;   inline long long score(vector<long long> a) {     long long s = 0;     for (i = (0); i < (n); ++i) {       s += a[i] * k[i];     }     return s;   }   vector<long long> permute(const vector<long long> &a) {     vector<long long> temp(a.size());     for (i = (0); i < (n); ++i) {       temp[i] = a[p[i] - 1] + r;     }     return temp;   }   void recurse(vector<long long> a, long long remain) {     if (remain % 2 == 0) {       long long sc = score(a);       if (!flag || max_score < sc) {         max_score = sc;         flag = true;       }     }     if (remain == 0) return;     recurse(permute(a), remain - 1);     remain--;     for (i = (0); i < (n); ++i) {       a[i] = a[i] ^ b[i];     }     if (remain % 2 == 0) {       long long sc = score(a);       if (!flag || max_score < sc) {         max_score = sc;         flag = true;       }     }     if (remain == 0) return;     recurse(permute(a), remain - 1);   }   int main(int argc, char *argv[]) {     cin >> n >> u >> r;     a = vector<long long>(n);     b = vector<long long>(n);     p = vector<long long>(n);     k = vector<long long>(n);     for (i = (0); i < (n); ++i) {       cin >> a[i];     }     for (i = (0); i < (n); ++i) {       cin >> b[i];     }     for (i = (0); i < (n); ++i) {       cin >> k[i];     }     for (i = (0); i < (n); ++i) {       cin >> p[i];     }     recurse(a, u);     cout << max_score << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n, s, d;   bool f(char x) {     if (x ==  a  || x ==  e  || x ==  i  || x ==  o  || x ==  u ) return true;     if (x >=  0  && x <=  9 ) {       int p = x -  0 ;       if (p % 2 == 1) return true;     }     return false;   }   int main() {     string s;     cin >> s;     int d = 0;     for (int i = 0; i < s.length(); i++) {       if (f(s[i])) d++;     }     cout << d;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long in() {     int32_t x;     scanf( %d , &x);     return x;   }   const long long maxn = 1e5 + 10;   const long long mod = 1e9 + 7;   const long long inf = 1e9 + 10;   vector<long long> g[maxn];   long long deg[maxn];   long long a[maxn];   bool mark[maxn];   long long rem;   vector<long long> path, V;   inline void dfs(long long node) {     mark[node] = true;     rem--;     path.push_back(node);     for (auto u : g[node]) {       if (mark[u]) {         cout << 0 << endl;         exit(0);       }       dfs(u);     }   }   long long dp[maxn];   int32_t main() {     long long n = in(), q = in(), t = in();     rem = n;     for (long long i = 0; i < n; i++) a[i] = in();     for (long long i = 0; i < q; i++) {       long long from = in() - 1, to = in() - 1;       g[from].push_back(to);       deg[to]++;     }     V.push_back(0);     dp[0] = 1;     for (long long i = 0; i < n; i++) {       if (!mark[i] && !deg[i]) {         path.clear();         dfs(i);         long long prefsum = 0;         for (auto v : path) {           prefsum += a[v];           V.push_back(prefsum);           if (v - path.back()) t -= prefsum;         }       }     }     if (rem) return cout << 0 << endl, 0;     if (t < 0) return cout << 0 << endl, 0;     for (long long i = 1; i < V.size(); i++) {       for (long long pre = 0; pre + V[i] < maxn; pre++)         (dp[pre + V[i]] += dp[pre]) %= mod;     }     cout << dp[t] << endl;   }
#include <bits/stdc++.h>   using namespace std;   void er() {     cout <<  NO  << endl;     exit(0);   }   int main() {     int n;     cin >> n;     int a[n + 1];     int o = 0;     int um = 0;     for (int i = 1; i <= n; i++) {       cin >> a[i];       if (a[i] != 0) o++;       um = um + a[i];     }     if (o < 1) er();     if (um != 0) {       cout <<  YES  << endl;       cout << 1 << endl;       cout << 1 <<     << n << endl;       return 0;     }     cout <<  YES  << endl;     cout << 2 << endl;     for (int i = 1; i <= n; i++) {       if (a[i] != 0) {         cout << 1 <<     << i << endl;         cout << i + 1 <<     << n << endl;         break;       }     }   }