malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int MOD = 999999929, MAXN = 300005, P2 = (1 << 19), MTS = (1 << 20) + 5;   int pot2[MAXN];   int TREE[MTS][2];   int n;   long long suma(int p, int k, int num) {     p += P2;     k += P2;     long long res = 0LL;     while (p < k) {       if ((p & 1)) {         res += TREE[p++][num];         if (res >= MOD) res -= MOD;       }       if (!(k & 1)) {         res += TREE[k--][num];         if (res >= MOD) res -= MOD;       }       p >>= 1;       k >>= 1;     }     if (p == k) {       res += TREE[p][num];       if (res >= MOD) res -= MOD;     }     return res;   }   void aT(int pos, int val, int num) {     pos += P2;     TREE[pos][num] = val;     while (pos > 1) {       pos >>= 1;       TREE[pos][num] = TREE[(pos << 1)][num] + TREE[((pos << 1) + 1)][num];       if (TREE[pos][num] >= MOD) TREE[pos][num] -= MOD;     }   }   void add(int pos) {     aT(pos, pot2[pos], 0);     aT(n - pos + 1, pot2[n - pos + 1], 1);   }   bool palindrom(int l) {     int k = min(l - 1, n - l);     long long a = suma(l - k, l + k, 0);     long long b = suma(n - l - k + 1, n - l + k + 1, 1);     if (l - k > n - l - k + 1) {       int g = l - k - (n - l - k + 1);       b *= pot2[g];       b %= MOD;     } else {       int g = n - l + 1 - l;       a *= pot2[g];       a %= MOD;     }     return (a == b);   }   int main() {     scanf( %d , &n);     pot2[0] = 1;     for (int i = 1; i <= n; ++i) {       pot2[i] = (pot2[i - 1] << 1);       if (pot2[i] >= MOD) pot2[i] %= MOD;     }     for (int i = 0; i < n; ++i) {       int a;       scanf( %d , &a);       if (!palindrom(a)) {         printf( YES );         return 0;       }       add(a);     }     printf( NO );   }
#include <bits/stdc++.h>   using namespace std;   const int inf = ~0u >> 1, mod = (int)(1e9) + 7;   int n, m;   long long pow2[555 * 555], f[555][555];   int main() {     scanf( %d%d , &n, &m);     pow2[0] = 1ll;     for (int i = 0; i < (int)500 * 500; ++i) pow2[i + 1] = (pow2[i] * 2ll) % mod;     f[0][0] = 1ll;     for (int k = 0; k < (int)m; ++k) {       for (int i = 1; i <= n; ++i)         for (int j = 0; j < i; ++j) {           long long tmp = f[j][k];           tmp = tmp * (pow2[i - j] - 1) % mod;           tmp = tmp * (pow2[j * (i - j)]) % mod;           f[i][k + 1] = (f[i][k + 1] + tmp) % mod;         }     }     long long ans = 0;     for (int i = 1; i <= n; ++i)       ans = (ans + f[i][m] * pow2[i * (n - i)] % mod) % mod;     if (m)       cout << ans << endl;     else       cout << 1;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int MOD = 998244353;   long long int exp(long long int n, long long int e) {     if (e == 0) return 1;     long long int temp = exp((n * n) % MOD, e / 2);     return e % 2 == 0 ? temp : (temp * n) % MOD;   }   long long int inverse(long long int n) { return exp(n, MOD - 2); }   int LIM = 3e5 + 10;   vector<long long int> factorial(LIM, 1);   vector<long long int> inv(LIM, 1);   long long int choose(long long int n, long long int r) {     long long int ans = ((factorial[n] * inv[r]) % MOD * inv[n - r]) % MOD;     return ans;   }   void solve() {     int n, k;     cin >> n >> k;     vector<long long int> arr(n + 1);     int a = 0;     for (int i = 1; i <= n; i++) {       cin >> arr[i];       if (i > 1) a += arr[i] == arr[i - 1];     }     a += (arr[1] == arr[n]);     long long int ans = 0;     long long int m = n - a;     for (int i = 0; i < m; i++) {       long long int temp = (exp(k - 2, i) * choose(m, i)) % MOD;       long long int prod = -1;       long long int c = m - i;       if (c % 2 == 1)         prod = exp(2, c - 1);       else         prod = (((exp(2, c) - choose(c, c / 2) + MOD) % MOD) * inv[2]) % MOD;       ;       temp = (temp * prod) % MOD;       ans = (ans + temp) % MOD;     }     ans = (ans * exp(k, a)) % MOD;     cout << ans << endl;   }   int main() {     int t;     t = 1;     for (int i = 1; i < LIM; i++) {       factorial[i] = (factorial[i - 1] * i) % MOD;       inv[i] = inverse(factorial[i]);     }     while (t--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, k, x, y, p;   int v[109][109];   int main() {     cin >> n >> k;     p = n;     while (p) {       v[x++][y++] = k;       p--;     }     for (int i = 0; i < n; i++) {       for (int h = 0; h < n; h++) cout << v[i][h] <<    ;       cout <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = (1 << 30) - 1;   const long double EPS = 1e-9;   const long double PI = fabs(atan2(0.0, -1.0));   const int MAXV = 80010;   int n;   vector<int> g[MAXV];   void load() {     scanf( %d , &n);     for (int i = 0, u, v; i < n - 1; i++) {       scanf( %d%d , &u, &v);       --u, --v;       g[u].push_back(v);       g[v].push_back(u);     }   }   int sz[MAXV];   unsigned long long pths[MAXV];   unsigned long long dp[MAXV];   unsigned long long bad = 0;   void dfs(int v, int p) {     sz[v] = 1;     for (int i = 0; i < (int)g[v].size(); i++) {       int to = g[v][i];       if (to == p) continue;       dfs(to, v);       sz[v] += sz[to];     }     pths[v] = 0;     for (int i = 0; i < (int)g[v].size(); i++) {       int to = g[v][i];       if (to == p) continue;       pths[v] += sz[to] * 1ULL * (sz[v] - sz[to] - 1);     }     assert(pths[v] % 2 == 0);     pths[v] /= 2;     pths[v] += sz[v] - 1;     dp[v] = 0;     for (int i = 0; i < (int)g[v].size(); i++) {       int to = g[v][i];       if (to == p) continue;       dp[v] += dp[to];     }     bad += dp[v];     dp[v] += pths[v] * 1ULL * sz[v];     for (int i = 0; i < (int)g[v].size(); i++) {       int to = g[v][i];       if (to == p) continue;       bad += dp[to] * 1ULL * (sz[v] - sz[to] - 1);     }   }   void solve() {     dfs(0, -1);     unsigned long long res = 0;     unsigned long long all = 0;     for (int i = 0; i < n; i++) all += pths[i];     for (int i = 0; i < n; i++) res += pths[i] * (all - pths[i]);     cout << res - 2 * bad <<   n ;   }   int main() {     load();     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   const long long inf = 1e18;   const long double eps = 1e-10;   struct Pnt {     long long x, y;     Pnt(long long x, long long y) : x(x), y(y) {}   };   Pnt operator+(Pnt a, Pnt b) { return {a.x + b.x, a.y + b.y}; }   bool operator==(Pnt a, Pnt b) { return (a.x == b.x) && (a.y == b.y); }   struct Solver {     vector<Pnt> a;     long long n;     Solver(vector<Pnt> a) : a(a) { n = a.size(); }     long long solve() {       if (n % 2) return 0;       long long d = n / 2;       Pnt mid = a[0] + a[d];       for (long long i = 0; i < n; ++i) {         long long j = (i + d) % n;         if (!(a[i] + a[j] == mid)) return 0;       }       return 1;     }   };   const long long debug = 0;   int32_t main() {     if (debug) freopen( input.txt ,  r , stdin);     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long tests = 1;     if (debug) cin >> tests;     while (tests--) {       long long stress = 0;       if (!stress) {         long long n;         cin >> n;         vector<Pnt> a;         a.reserve(n);         for (long long i = 0; i < n; ++i) {           long long x, y;           cin >> x >> y;           a.push_back({x, y});         }         Solver solver(a);         long long res = solver.solve();         if (res)           cout <<  YES n ;         else           cout <<  NO n ;       } else {       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   void debug(T v, string delimiter =   n ) {     for (__typeof(v.begin()) it = v.begin(), it_end = v.end(); it != it_end; it++)       cout << *it << delimiter;     cout << flush;   }   int dx[] = {0, 1, 0, -1};   int dy[] = {1, 0, -1, 0};   string ds =  SENW ;   const double PI = 4.0 * atan(1.0);   string solve(string s) {     if (s[0] ==  0 ) return 0;     long long ans = 1;     if (s[0] ==  ?  || isalpha(s[0])) ans = 9;     string zero =   ;     vector<int> used(30);     int rem = 10;     if (isalpha(s[0])) {       used[s[0] -  A ] = 1;       rem--;     }     for (int i = 1; i < (int)(s.size()); i++) {       if (s[i] ==  ? ) {         zero +=  0 ;       } else if (isalpha(s[i])) {         if (used[s[i] -  A ] == 0) {           used[s[i] -  A ] = 1;           ans *= rem;           rem--;         }       }     }     ostringstream out;     out << ans;     string ret = out.str();     return ret + zero;   }   int main() {     string s;     while (cin >> s) {       cout << solve(s) << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 300000;   int sub[2 * MAXN + 5][2];   int par[2 * MAXN + 5];   int getRoot(int a) {     while (par[a] > 0) {       a = par[a];     }     return a;   }   long long int ans = 0;   void dsu(int a, int b) {     int x0 = sub[a][0] + sub[b][0];     int x1 = sub[a][1] + sub[b][1];     ans -= sub[a][0] * 1ll * sub[a][1] + sub[b][0] * 1ll * sub[b][1];     ans += x0 * 1ll * x1;     if (sub[a][0] + sub[a][1] < sub[b][0] + sub[b][1]) {       sub[b][0] = x0;       sub[b][1] = x1;       par[a] = b;     } else {       sub[a][0] = x0;       sub[a][1] = x1;       par[b] = a;     }   }   void removeDSU(int a, int b) {     if (sub[a][0] + sub[a][1] < sub[b][0] + sub[b][1]) {       sub[b][0] -= sub[a][0];       sub[b][1] -= sub[a][1];       par[a] = -1;     } else {       sub[a][0] -= sub[b][0];       sub[a][1] -= sub[b][1];       par[b] = -1;     }     ans -= (sub[a][0] + sub[b][0]) * 1ll * (sub[a][1] + sub[b][1]);     ans += sub[a][0] * 1ll * sub[a][1] + sub[b][0] * 1ll * sub[b][1];   }   vector<pair<int, int> > st[8 * MAXN];   void addEdge(int id, int l, int r, int u, int v, int x, int y) {     if (v < l || r < u) return;     if (u <= l && r <= v) {       st[id].push_back(pair<int, int>(x, y));       return;     }     int mid = (l + r) / 2;     addEdge(id * 2, l, mid, u, v, x, y);     addEdge(id * 2 + 1, mid + 1, r, u, v, x, y);   }   unordered_map<int, int> prevApp[MAXN + 4];   long long int res[MAXN + 5];   void dfs(int id, int l, int r) {     vector<pair<int, int> > operations;     for (auto i : st[id]) {       int m = getRoot(i.first);       int n = getRoot(i.second);       if (m == n) {         continue;       }       operations.push_back(pair<int, int>(m, n));       dsu(m, n);     }     int mid = (l + r) / 2;     if (l == r) {       res[l] = ans;     } else {       dfs(id * 2, l, mid);       dfs(id * 2 + 1, mid + 1, r);     }     reverse(operations.begin(), operations.end());     for (auto i : operations) {       removeDSU(i.first, i.second);     }   }   int main() {     ios::sync_with_stdio(0);     cin.tie(NULL);     int q;     cin >> q;     for (int i = 1; i <= q; i++) {       int x, y;       cin >> x >> y;       if (prevApp[x][y] == 0) {         prevApp[x][y] = i;       } else {         addEdge(1, 1, q, prevApp[x][y], i - 1, x, y + MAXN);         prevApp[x][y] = 0;       }     }     for (int i = 1; i <= MAXN; i++) {       for (auto j : prevApp[i]) {         if (j.second > 0) {           addEdge(1, 1, q, j.second, q, i, j.first + MAXN);         }       }     }     memset(par, -1, sizeof(par));     for (int i = 1; i <= MAXN; i++) {       sub[i][0] = 1;       sub[i + MAXN][1] = 1;     }     dfs(1, 1, q);     for (int i = 1; i <= q; i++) cout << res[i] <<    ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool flag = 0;   void sss(int &n, int &k) {     if (flag == 0)       n = n + k;     else if (flag == 1)       n = n - k;   }   void print(int &now, int k) {     k += 48;     if (k > now) {       while (k != now) {         printf( + );         now++;       }     } else if (k < now) {       while (k != now) {         printf( - );         now--;       }     }     printf( . );   }   int main() {     int i, k = 0, n = 0;     char c;     while ((c = getchar()) != EOF) {       if (c >=  0  && c <=  9 )         n = n * 10 + c -  0 ;       else if (c ==  + ) {         sss(k, n);         n = 0;         flag = 0;       } else if (c ==  - ) {         sss(k, n);         n = 0;         flag = 1;       }     }     sss(k, n);     n = 0;     int p = k, j;     while (p) {       p /= 10;       n++;     }     if (k == 0) n = 1;     int now = 0;     for (i = n; i >= 1; i--) {       p = k;       for (j = 1; j <= i - 1; j++) p /= 10;       p %= 10;       print(now, p);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 100 + 10;   double dp[2][maxn][maxn];   double s[maxn][maxn], s2[maxn][maxn];   inline double S(int x1, int y1, int x2, int y2) {     return s[x2][y2] - s[x2][y1 - 1] - s[x1 - 1][y2] + s[x1 - 1][y1 - 1];   }   inline double S2(int x1, int y1, int x2, int y2) {     return s2[x2][y2] - s2[x1 - 1][y1 - 1];   }   int a[maxn];   int main() {     int n, k;     scanf( %d%d , &n, &k);     k = min(k, 1000);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     for (int m = 1; m <= k; m++) {       for (int i = 1; i <= n + 1; i++)         for (int j = 1; j <= n + 1; j++)           s[i][j] =               s[i - 1][j] + s[i][j - 1] - s[i - 1][j - 1] + dp[(m + 1) % 2][i][j],           s2[i][j] = s2[i - 1][j - 1] + dp[(m + 1) % 2][i][j];       for (int i = 1; i <= n; i++)         for (int j = i + 1; j <= n; j++) {           double &d = dp[m % 2][i][j];           d = 0;           for (int x = 1; x <= i; x++)             d += S(x, j, x + j - i - 1, j) +                  (n - j + 1 - S2(x, x + j - i, x + n - j, x + n - i));           for (int x = i + 1; x <= j; x++) d += S(i, x, i, x + n - j);           int mul = (n - j + 1) * (n - j) / 2 + i * (i - 1) / 2 +                     (j - i) * (j - i - 1) / 2;           d += mul * dp[(m + 1) % 2][i][j];           d /= (n * (n + 1) / 2);         }     }     double ans = 0;     for (int i = 1; i <= n; i++)       for (int j = i + 1; j <= n; j++)         ans += (a[i] > a[j] ? (1 - dp[k % 2][i][j]) : dp[k % 2][i][j]);     printf( %.10f n , ans);   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     long long mod = 1000000007;     long long sols = 0, ti = 0;     for (int i = s.size() - 1; i >= 0; i--) {       if (s[i] ==  b )         ti++;       else {         sols += ti;         ti *= 2;         sols %= mod;         ti %= mod;       }     }     cout << sols << endl;   }
#include <bits/stdc++.h>   using namespace std;   int n, t;   string str1, str2;   int main() {     scanf( %d %d , &n, &t);     cin >> str1 >> str2;     int l1 = n - t, l2 = n - t;     string ans;     ans.resize(n);     for (int i = 0; i < n; i++) {       if (l1 == 0 && l2 == 0) break;       if (str1[i] == str2[i]) {         ans[i] = str1[i];         l1--;         l2--;       }     }     if (l1 == 0 && l2 == 0) {       for (int i = 0; i < n; i++) {         if (ans[i] >=  a  && ans[i] <=  z ) continue;         for (int j =  a ; j <=  z ; j++) {           if (j != str1[i] && j != str2[i]) {             ans[i] = j;             break;           }         }       }     } else {       int state = 0;       for (int i = 0; i < n; i++) {         if (l1 == 0 && l2 == 0) {           if (ans[i] >=  a  && ans[i] <=  z ) continue;           for (int j =  a ; j <=  z ; j++) {             if (j != str1[i] && j != str2[i]) {               ans[i] = j;               break;             }           }         } else {           if (ans[i] >=  a  && ans[i] <=  z ) continue;           if (state == 0) {             l1--;             ans[i] = str1[i];             state = 1;           } else {             l2--;             ans[i] = str2[i];             state = 0;           }         }       }     }     if (l1 > 0 || l2 > 0)       printf( -1 n );     else       cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int mod = 1000000007;   struct M {     int v[2][2];   } A, V, c[1 << 20];   struct Vec {     int v[2];   } a[1 << 20], Vec0;   bool E(const M& a) {     return a.v[0][0] == 1 && a.v[1][1] == 1 && a.v[0][1] == 0 && a.v[1][0] == 0;   }   M operator*(const M& a, const M& b) {     M ret;     for (int i = 0; i < 2; ++i)       for (int j = 0; j < 2; ++j)         ret.v[i][j] =             (1ll * a.v[i][0] * b.v[0][j] + 1ll * a.v[i][1] * b.v[1][j]) % mod;     return ret;   };   Vec operator+(const Vec& a, const Vec& b) {     Vec ret;     ret.v[0] = (a.v[0] + b.v[0]) % mod;     ret.v[1] = (a.v[1] + b.v[1]) % mod;     return ret;   }   Vec operator*(const M& m, const Vec& vec) {     Vec ret;     ret.v[0] = (1ll * vec.v[0] * m.v[0][0] + 1ll * vec.v[1] * m.v[0][1]) % mod;     ret.v[1] = (1ll * vec.v[0] * m.v[1][0] + 1ll * vec.v[1] * m.v[1][1]) % mod;     return ret;   }   M pow(M a, int b) {     M t;     t.v[0][0] = t.v[1][1] = 1;     t.v[0][1] = t.v[1][0] = 0;     while (b) {       if (b & 1) t = t * a;       b = b >> 1;       a = a * a;     }     return t;   }   void init(int u, int l, int r) {     if (l == r) {       int b;       scanf( %d , &b);       M t = pow(A, b - 1);       a[u].v[0] = t.v[0][0];       a[u].v[1] = t.v[0][1];       return;     }     c[u].v[0][0] = c[u].v[1][1] = 1;     c[u].v[0][1] = c[u].v[1][0] = 0;     int mid = (l + r) >> 1;     init(u << 1, l, mid);     init(u << 1 | 1, mid + 1, r);     a[u] = a[u << 1] + a[u << 1 | 1];   }   int L, R;   void change(int u, int l, int r) {     if (R < l || r < L) return;     if (L <= l && r <= R) {       c[u] = V * c[u];       a[u] = V * a[u];       return;     }     if (!E(c[u])) {       c[u << 1] = c[u] * c[u << 1];       a[u << 1] = c[u] * a[u << 1];       c[u << 1 | 1] = c[u] * c[u << 1 | 1];       a[u << 1 | 1] = c[u] * a[u << 1 | 1];       c[u].v[0][0] = c[u].v[1][1] = 1;       c[u].v[0][1] = c[u].v[1][0] = 0;     }     int mid = (l + r) >> 1;     change(u << 1, l, mid);     change(u << 1 | 1, mid + 1, r);     a[u] = a[u << 1] + a[u << 1 | 1];   }   Vec query(int u, int l, int r) {     if (R < l || r < L) return Vec0;     if (L <= l && r <= R) return a[u];     int mid = (l + r) >> 1;     return c[u] * (query(u << 1, l, mid) + query(u << 1 | 1, mid + 1, r));   }   int main() {     A.v[0][0] = A.v[0][1] = A.v[1][0] = 1;     int n, m;     scanf( %d%d , &n, &m);     init(1, 1, n);     for (int i = 0; i < m; ++i) {       int op, x;       scanf( %d , &op);       if (op == 1) {         scanf( %d%d%d , &L, &R, &x);         V = pow(A, x);         change(1, 1, n);       } else {         scanf( %d%d , &L, &R);         Vec vec = query(1, 1, n);         printf( %d n , vec.v[0]);       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool sortbysec(const pair<long long int, long long int> &a,                  const pair<long long int, long long int> &b) {     if (a.first > b.first)       return (a.first < b.first);     else if (a.first == b.first)       return (a.second > b.second);     else       return true;   }   void solve() {     long long int n, c;     cin >> n >> c;     long long int a[n];     for (long long int i = 0; i < n; i++) cin >> a[i];     long long int cnt = 1;     for (long long int i = 1; i < n; i++) {       if (a[i] - a[i - 1] <= c)         cnt++;       else         cnt = 1;     }     if (n == 1)       cout << 1;     else       cout << cnt;   }   int main() {     solve();     return 0;   }
#include <bits/stdc++.h>   const unsigned long long M1 = 1e8 + 7;   const unsigned long long M2 = 1e9 + 7;   const unsigned long long M3 = 998244353;   const int N = 2e5 + 5;   int n, m, k, U[N], V[N], h[10], ans;   unsigned long long k1[N], k2[N], k3[N], f1[10][10], f2[10][10], f3[10][10],       g[10][10];   unsigned long long s1, s2, s3;   std::vector<int> E[N];   void dfs(int dep) {     if (dep == k + 1) {       unsigned long long b1, b2, b3, d = 0;       b1 = 0;       b2 = 0;       b3 = 0;       for (int i = 1; i <= k; i++) {         b1 += f1[i][h[i]];         b2 += f2[i][h[i]];         b3 += f3[i][h[i]];         d += g[i][h[i]];       }       if (b1 == s1 && b2 == s2 && b3 == s3 && d == n) ++ans;       return;     }     for (int i = 1; i <= dep; i++) {       h[dep] = i;       dfs(dep + 1);     }   }   int main() {     scanf( %d%d%d , &n, &m, &k);     for (int i = 1, x, y, w; i <= m; i++) {       scanf( %d%d%d , &x, &y, &w);       U[w] = x;       V[w] = y;       E[x].push_back(w);     }     k1[0] = k2[0] = k3[0] = 1;     for (int i = 1; i <= n; i++) {       std::sort(E[i].begin(), E[i].end());       k1[i] = k1[i - 1] * M1;       k2[i] = k2[i - 1] * M2;       k3[i] = k3[i - 1] * M3;       s1 += k1[i];       s2 += k2[i];       s3 += k3[i];     }     for (int i = 1; i <= n; i++)       for (int v = 0, s = E[i].size(); v < s; v++) {         f1[s][v + 1] += k1[V[E[i][v]]];         f2[s][v + 1] += k2[V[E[i][v]]];         f3[s][v + 1] += k3[V[E[i][v]]];         g[s][v + 1]++;       }     dfs(1);     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2005;   int arr[N][N], n;   vector<int> adj[N], revAdj[N];   bool visited[N];   vector<int> vec;   void dfs(int v) {     visited[v] = 1;     for (auto i : revAdj[v])       if (!visited[i]) dfs(i);     vec.push_back(v);   }   void dfs2(int v) {     visited[v] = 1;     for (auto i : adj[v])       if (!visited[i]) dfs2(i);   }   void func() {     cin >> n;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         cin >> arr[i][j];         if (arr[i][j]) arr[i][j] = 1;       }     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         if (j != i && arr[i][j]) {           revAdj[j].push_back(i);           adj[i].push_back(j);         }       }     }     for (int i = 1; i <= n; i++)       if (!visited[i]) dfs(i);     reverse(vec.begin(), vec.end());     for (int i = 1; i <= n; i++) visited[i] = 0;     int cnt = 0;     for (int i = 0; i < n; i++) {       if (!visited[vec[i]]) {         cnt++;         if (cnt > 1) {           cout <<  NO n ;           return;         }         dfs2(vec[i]);       }     }     cout <<  YES n ;   }   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     int ntc = 1;     for (int i = 1; i <= ntc; i++) {       func();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[2 * 100000 + 10];   int n, m, k;   bool find(int pos) {     int m1 = 0;     while (m1 < m && pos <= n) {       int k1 = k;       while (pos <= n && a[pos] <= k1) {         k1 -= a[pos++];       }       m1++;     }     return pos == n + 1 ? 1 : 0;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     cerr.tie(nullptr);     cin >> n >> m >> k;     for (int i = 1; i <= n; i++) {       cin >> a[i];     }     int ans = 0;     int l = 1, r = n;     while (l <= r) {       int mid = (l + r) / 2;       if (find(mid)) {         ans = max(ans, n - mid + 1);         r = mid - 1;       } else {         l = mid + 1;       }     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   constexpr int Mod = 1e9 + 7;   inline int fpm(int a, int b) {     int res = 1;     while (b) {       if (b & 1) res = 1LL * res * a % Mod;       a = 1LL * a * a % Mod;       b >>= 1;     }     return res;   }   int n, m, k, r, c, sx, sy, tx, ty;   int tot;   int main() {     scanf( %d%d%d , &n, &m, &k);     scanf( %d%d , &r, &c);     scanf( %d%d%d%d , &sx, &sy, &tx, &ty);     if (sx == tx && sy == ty)       tot = 1LL * n * m % (Mod - 1);     else       tot = ((1LL * n * m - 1LL * r * c) % (Mod - 1) + Mod - 1) % (Mod - 1);     printf( %d n , fpm(k, tot));   }