malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int main() {     int i, j, temp = 0;     char x[5][5];     for (i = 0; i < 3; i++) gets(x[i]);     for (i = 0; i < 3; i++)       for (j = 0; j < 3; j++)         if (x[i][j] != x[2 - i][2 - j]) temp = 1;     if (temp == 1)       printf( NO n );     else       printf( YES n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long a, b, x, n;   void input() {     cin >> a >> b >> n >> x;     return;   }   long long powmod(long long a, long long b) {     if (b == 1) return a;     if (b < 1) return 1;     long long t = powmod(a, b / 2) % 1000000007;     t = (t * t) % 1000000007;     if (b % 2 == 1) {       t = (t * a) % 1000000007;     }     return t;   }   void solve() {     if (a == 1) {       cout << (b * (n % 1000000007) + x) % 1000000007;       return;     }     long long tmp = powmod(a, n);     long long ans = ((tmp - 1) * powmod(a - 1, 1000000007 - 2)) % 1000000007;     tmp = (tmp * x) % 1000000007;     ans = (ans * b) % 1000000007;     cout << (tmp + ans) % 1000000007;     return;   }   void output() { return; }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     {       input();       solve();       output();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long m, n, q;   long long X;   long long f(long long a) {     long long b = X - 2, c = X, k, ans = 1;     while (b > 0) {       long long p = 1, k = a;       while (p * 2 <= b) {         p *= 2;         k = k * k % c;       }       ans = ans * k % c;       b -= p;     }     return ans;   }   long long a[1005009], A;   long long p[1000509];   int main() {     cin >> n >> m >> A >> q;     p[0] = 1;     for (long long i = 1;; i++) {       p[i] = p[i - 1] * A % q;       if (p[i] == 1) {         X = i;         break;       }     }     a[0] = 1;     long long x = m, t = 1;     for (long long i = 1; i <= n - 1; i++) {       a[i] = (a[i - 1] * x * f(i)) % X;       x--;     }     long long s = 0;     for (long long i = 0; i <= n - 1; i++) {       s += a[i];       a[i] = s;     }     for (long long i = n - 1; i >= 0; i--) cout << p[a[i] % X] <<    ;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 100;   int fen[maxn * 2], d[maxn], n, first[maxn], w[maxn];   pair<int, int> p[maxn];   int N = 1;   map<int, int> mp;   vector<int> v;   inline void upd(int first, int val) {     for (int i = first; i < N; i += i & -i) fen[i] = max(fen[i], val);   }   inline int ask(int first) {     int res = 0;     for (int i = first; i > 0; i -= i & -i) res = max(res, fen[i]);     return res;   }   int main() {     ios_base::sync_with_stdio(false);     cin >> n;     for (int(i) = (0); (i) < (n); ++(i)) cin >> p[i].first >> p[i].second;     sort(p, p + n);     for (int(i) = (0); (i) < (n); ++(i)) {       first[i] = p[i].first, w[i] = p[i].second;       v.push_back(first[i] + w[i]);       v.push_back(first[i] - w[i]);     }     sort(v.begin(), v.end());     v.resize(unique(v.begin(), v.end()) - v.begin());     for (auto &(a) : (v)) mp[a] = N++;     int ans = 1;     for (int(i) = (0); (i) < (n); ++(i)) {       d[i] = 1 + ask(mp[first[i] - w[i]]);       upd(mp[first[i] + w[i]], d[i]);       ans = max(ans, d[i]);     }     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T, typename U>   inline void chkmax(T& x, U y) {     if (x < y) x = y;   }   template <typename T, typename U>   inline void chkmin(T& x, U y) {     if (y < x) x = y;   }   int n, p;   int l[100005], r[100005], len[100005];   int main() {     cin >> n >> p;     for (int i = 0; i < n; i++)       scanf( %d%d , l + i, r + i), len[i] = r[i] - l[i] + 1;     l[n] = l[0], r[n] = r[0];     len[n] = len[0];     double ret = 0;     for (int i = 0; i < n; i++) {       int x = len[i] - r[i] / p + (l[i] - 1) / p;       int y = len[i + 1] - r[i + 1] / p + (l[i + 1] - 1) / p;       ret += 2000.0 * (1 - 1. * x / len[i] * y / len[i + 1]);     }     printf( %.10lf n , ret);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 200010, P = 998244353;   int n, k, num, ans, h[maxn], fact[maxn], inv[maxn];   int qp(int x, int y) {     int z = 1;     for (; y; y >>= 1, x = 1LL * x * x % P) {       if (y & 1) z = 1LL * z * x % P;     }     return z;   }   int C(int x, int y) { return 1LL * fact[x] * inv[y] % P * inv[x - y] % P; }   int main() {     scanf( %d %d , &n, &k);     for (int i = fact[0] = inv[0] = 1; i <= n; i++) {       fact[i] = 1LL * i * fact[i - 1] % P;       inv[i] = qp(fact[i], P - 2);     }     for (int i = 0; i < n; i++) {       scanf( %d , &h[i]);     }     for (int i = 0; i < n; i++) {       if (h[i] ^ h[(i + 1) % n]) num++;     }     for (int i = 0; i + i <= num; i++) {       ans = (ans + 1LL * C(num, i) * C(num - i, i) % P * qp(k - 2, num - i - i)) %             P;     }     ans = 1LL * qp(k, n - num) * ans % P;     printf( %d n , 1LL * qp(2, P - 2) * (qp(k, n) - ans + P) % P);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   using min_heap = priority_queue<T, vector<T>, greater<T>>;   void setupIO(const string &PROB =   ) {     ios::sync_with_stdio(false);     cin.tie(nullptr);     if (PROB.length() != 0) {       ifstream infile(PROB +  .in );       if (infile.good()) {         freopen((PROB +  .in ).c_str(),  r , stdin);         freopen((PROB +  .out ).c_str(),  w , stdout);       }     }   }   int main() {     setupIO();     int n;     cin >> n;     int A[n][n];     for (int i = 0; i < (n); i++) {       for (int j = 0; j < (n); j++) {         char c;         cin >> c;         A[i][j] = c ==  1 ;       }     }     int B[n];     for (int i = 0; i < (n); i++) cin >> B[i];     bool C[n];     for (int i = 0; i < n; i++) C[i] = false;     ;     while (true) {       int tgt = -1;       for (int i = 0; i < (n); i++) {         if (B[i] == 0) {           tgt = i;           break;         }       }       if (tgt == -1) break;       assert(!C[tgt]);       for (int i = 0; i < (n); i++) {         if (A[tgt][i]) B[i]--;       }       C[tgt] = true;     }     vector<int> ans;     for (int i = 0; i < (n); i++)       if (C[i]) ans.push_back(i);     cout << ans.size() << endl;     for (int i = 0; i < (ans.size()); i++) {       if (i != 0) cout <<    ;       cout << ans[i] + 1;     }     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct yo {     int val;     int id;     int next, prev;   };   vector<yo> a0, a;   int n, n0, x;   bool operator<(yo a, yo b) { return a.val < b.val; }   int main() {     cin >> n;     n0 = n;     if (n <= 2) {       cout << 0;       return 0;     }     for (int i = 0; i < n; i++) {       cin >> x;       yo cur;       cur.val = x;       cur.id = i;       cur.next = i + 1;       cur.prev = i - 1;       a0.push_back(cur);       a.push_back(cur);     }     sort(a.begin(), a.end());     long long v = 0, ans = 0;     for (int i = 0; i < a.size() - 2; i++) {       int cur_id = a[i].id;       if (a0[cur_id].prev == -1) {         a0[a0[cur_id].next].prev = -1;         ans += (n - 2) * (a[i].val - v);         v += (a[i].val - v);       } else if (a0[cur_id].next == n0) {         a0[a0[cur_id].prev].next = n0;         ans += (n - 2) * (a[i].val - v);         v += (a[i].val - v);       } else {         ans += min(a0[a0[cur_id].prev].val, a0[a0[cur_id].next].val) - v;         a0[a0[cur_id].next].prev = a0[cur_id].prev;         a0[a0[cur_id].prev].next = a0[cur_id].next;       }       n--;     }     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   vector<pair<int, int> > changes;   vector<int> norm(vector<int> x) {     int i = -1;     for (int bit = 30; bit >= 0; bit--) {       for (int pos = i + 1; pos < x.size(); pos++)         if (x[pos] & (1 << bit)) {           if (pos != ++i) {             changes.push_back(pair<int, int>(pos, i));             x[pos] ^= x[i];             changes.push_back(pair<int, int>(i, pos));             x[i] ^= x[pos];           }           for (int pos = 0; pos < x.size(); pos++)             if (pos != i) {               if (x[pos] & (1 << bit)) {                 changes.push_back(pair<int, int>(pos, i));                 x[pos] ^= x[i];               }             }           break;         }     }     return x;   }   int used[33];   int main() {     int n;     cin >> n;     vector<int> x(n), y(n);     for (int i = 0; i < n; i++) scanf( %d , &x[i]);     for (int i = 0; i < n; i++) scanf( %d , &y[i]);     vector<pair<int, int> > a, b;     vector<int> bx = norm(x);     a = changes;     changes.clear();     vector<int> by = norm(y);     b = changes;     reverse(b.begin(), b.end());     for (int i = 0; i < n; i++)       if (by[i]) used[__builtin_clz(by[i])] = 1;     for (int i = 0; i < n; i++)       if (bx[i] && used[__builtin_clz(bx[i])]) {         for (int j = i - 1; j >= 0; j--) {           if (bx[j] && used[__builtin_clz(bx[j])]) break;           a.push_back(pair<int, int>(j, j + 1));           bx[j + 1] ^= bx[j];           a.push_back(pair<int, int>(j + 1, j));           bx[j] ^= bx[j + 1];           a.push_back(pair<int, int>(j, j + 1));           bx[j + 1] ^= bx[j];         }       }     for (int i = 0; i < n; i++) {       if (by[i] != bx[i]) {         if (!by[i]) {           bx[i] = 0;           a.push_back(pair<int, int>(i, i));         } else {           for (int j = i + 1; j < n; j++)             if (bx[j] && (by[i] & (1 << (31 - __builtin_clz(bx[j]))))) {               bx[i] ^= bx[j];               a.push_back(pair<int, int>(i, j));             }           if (by[i] != bx[i]) {             cout << -1 << endl;             return 0;           }         }       }     }     vector<int> aux = x;     cout << a.size() + b.size() << endl;     for (int i = 0; i < a.size(); i++) {       cout << a[i].first + 1 <<     << a[i].second + 1 << endl;       aux[a[i].first] ^= aux[a[i].second];     }     for (int i = 0; i < b.size(); i++) {       cout << b[i].first + 1 <<     << b[i].second + 1 << endl;       aux[b[i].first] ^= aux[b[i].second];     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long ans;   long long c[1001][1001];   void init() {     c[0][0] = 1;     for (int i = 0; i <= 1000; i++) {       c[i][i] = c[i][0] = 1;       for (int j = 1; j < i; j++) {         c[i][j] = (c[i - 1][j - 1] + c[i - 1][j]) % 1000000007;       }     }   }   int main() {     long long m, n, k;     init();     while (cin >> m >> n >> k) {       if (m <= 2 * k || n <= 2 * k)         cout <<  0  << endl;       else {         ans = (c[m - 1][2 * k] % 1000000007) * (c[n - 1][2 * k] % 1000000007) %               1000000007;         cout << ans << endl;       }     }   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 5e5 + 5;   int size[maxn], dep[maxn], val[maxn], dfn[maxn], hson[maxn], ans[maxn],       rnk[maxn];   int cnt[(1 << 22) + 4];   struct EDGE {     int to, next;     char c;   } edge[maxn << 1];   int head[maxn], tot, num;   void addedge(int u, int v, char c) {     edge[++tot].next = head[u];     edge[tot].to = v;     edge[tot].c = c;     head[u] = tot;   }   void dfs(int now, int pre) {     size[now] = 1;     dep[now] = dep[pre] + 1;     dfn[now] = ++num;     rnk[num] = now;     for (int i = head[now]; i; i = edge[i].next) {       int to = edge[i].to;       if (to == pre) continue;       val[to] = val[now] ^ (1 << (edge[i].c -  a ));       dfs(to, now);       size[now] += size[to];       if (size[to] > size[hson[now]]) hson[now] = to;     }   }   void cal(int now) {     if (cnt[val[now]]) ans[now] = max(ans[now], cnt[val[now]] - dep[now]);     for (int i = 0; i < 22; ++i) {       if (cnt[val[now] ^ (1 << i)])         ans[now] = max(ans[now], cnt[val[now] ^ (1 << i)] - dep[now]);     }     cnt[val[now]] = max(cnt[val[now]], dep[now]);     for (int i = head[now]; i; i = edge[i].next) {       int to = edge[i].to;       if (dep[to] < dep[now] || to == hson[now]) continue;       for (int j = dfn[to]; j <= dfn[to] + size[to] - 1; ++j) {         int tmp = rnk[j];         if (cnt[val[tmp]])           ans[now] = max(ans[now], cnt[val[tmp]] + dep[tmp] - 2 * dep[now]);         for (int i = 0; i < 22; ++i) {           if (cnt[val[tmp] ^ (1 << i)])             ans[now] =                 max(ans[now], cnt[val[tmp] ^ (1 << i)] + dep[tmp] - 2 * dep[now]);         }       }       for (int j = dfn[to]; j <= dfn[to] + size[to] - 1; ++j) {         int tmp = rnk[j];         cnt[val[tmp]] = max(cnt[val[tmp]], dep[tmp]);       }     }   }   void dfs2(int now, bool heave) {     for (int i = head[now]; i; i = edge[i].next) {       int to = edge[i].to;       if (dep[to] < dep[now] || to == hson[now]) continue;       dfs2(to, 0);       ans[now] = max(ans[now], ans[to]);     }     if (hson[now]) dfs2(hson[now], 1), ans[now] = max(ans[now], ans[hson[now]]);     cal(now);     if (!heave)       for (int i = dfn[now]; i <= dfn[now] + size[now] - 1; ++i)         cnt[val[rnk[i]]] = 0;   }   int main() {     int n;     scanf( %d , &n);     for (int i = 2; i <= n; ++i) {       int to;       char c;       scanf( %d %c , &to, &c);       addedge(i, to, c);       addedge(to, i, c);     }     dfs(1, 0);     dfs2(1, 0);     for (int i = 1; i <= n; ++i) printf( %d  , ans[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     vector<long long int> v1;     map<long long int, long long int> m1;     long long int size, count = 0, i, j, s, k;     cin >> size;     long long int a[size];     for (i = 0; i < size; i++) {       cin >> a[i];     }     sort(a, a + size);     for (i = 0; i < size; i++) {       for (j = i + 1; j < size; j++) {         k = a[i] + a[j];         m1[k]++;       }     }     map<long long int, long long int>::iterator itr;     for (itr = m1.begin(); itr != m1.end(); itr++) {       v1.push_back(itr->second);     }     sort(v1.begin(), v1.end(), greater<long long int>());     cout << v1[0];   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 110000, MAXM = MAXN * 2;   const int inf = 10000000;   struct eglist {     int other[MAXM], succ[MAXM], last[MAXM], sum;     void addEdge(int a, int b) {       other[++sum] = b, succ[sum] = last[a], last[a] = sum;       other[++sum] = a, succ[sum] = last[b], last[b] = sum;     }     void clear(int n) {       for (int i = 0; i <= n; i++) last[i] = 0;       sum = 0;     }   } e;   int fa[MAXN];   pair<int, int> down1[MAXN], down2[MAXN];   int up[MAXN], ans = 0;   queue<int> q;   int visit[MAXN] = {};   int n, m, d;   void dfsDown(int x, int fa) {     if (visit[x]) {       down1[x] = make_pair(0, 0);       down2[x] = make_pair(0, 0);     } else {       down1[x].first = -inf, down2[x].first = -inf;     }     for (int i = e.last[x]; i; i = e.succ[i]) {       int y = e.other[i];       if (y == fa) continue;       dfsDown(y, x);       pair<int, int> tmp = down1[y];       tmp.first++;       tmp.second = y;       if (tmp > down1[x]) {         down2[x] = down1[x];         down1[x] = tmp;       } else if (tmp > down2[x])         down2[x] = tmp;     }   }   void dfsUp(int x, int fa) {     up[x] = visit[x] ? 0 : -inf;     if (fa == 0) {       if (down1[x].first <= d) ans++;     } else {       up[x] = max(up[x], up[fa] + 1);       if (down1[fa].second == x)         up[x] = max(up[x], down2[fa].first + 1);       else         up[x] = max(up[x], down1[fa].first + 1);       if (max(up[x], down1[x].first) <= d) ans++;     }     for (int i = e.last[x]; i; i = e.succ[i]) {       int y = e.other[i];       if (y == fa) continue;       dfsUp(y, x);     }   }   int main() {     scanf( %d %d %d , &n, &m, &d);     for (int i = 1; i <= m; i++) {       int p;       scanf( %d , &p);       visit[p] = 1;     }     e.clear(n);     for (int i = 1; i < n; i++) {       int a, b;       scanf( %d %d , &a, &b);       e.addEdge(a, b);     }     dfsDown(1, 0);     dfsUp(1, 0);     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int mx(int a, int b) {     if (a > b) return a;     return b;   }   int main() {     int n, s;     scanf( %d %d , &n, &s);     int max = -1;     for (int i = 0; i < n; ++i) {       int x, y;       scanf( %d %d , &x, &y);       if (x >= s && !(x == s && y == 0)) continue;       if (y == 0) y = 100;       max = mx(max, 100 - y);     }     printf( %d , max);   }
#include <bits/stdc++.h>   using namespace std;   template <typename T1, typename T2>   istream& operator>>(istream& in, pair<T1, T2>& a) {     in >> a.first >> a.second;     return in;   }   template <typename T1, typename T2>   ostream& operator<<(ostream& out, pair<T1, T2> a) {     out << a.first <<     << a.second;     return out;   }   template <typename T, typename T1>   T amax(T& a, T1 b) {     if (b > a) a = b;     return a;   }   template <typename T, typename T1>   T amin(T& a, T1 b) {     if (b < a) a = b;     return a;   }   const long long INF = 1e18;   const int32_t M = 1e9 + 7;   const int32_t MM = 998244353;   const long long N = 5e5 + 5;   vector<long long> v[N];   void solve() {     long long n;     cin >> n;     v[0].clear();     for (long long i = 1; i < n + 1; i++) {       v[i].clear();       v[i].push_back(-1);     }     for (long long i = 0; i < n; i++) {       long long x;       cin >> x;       v[x].push_back(i);     }     if ((long long)((v[0]).size()) < 2) {       cout <<  0 n ;       return;     }     long long z = (long long)((v[0]).size());     long long L = v[0][(z + 1) / 2], R = v[0][z / 2 - 1];     vector<pair<long long, long long> > vec;     for (long long i = 1; i < n + 1; i++) {       v[i].push_back(n + 2);       long long l = *prev(lower_bound((v[i]).begin(), (v[i]).end(), L));       long long r = *upper_bound((v[i]).begin(), (v[i]).end(), R);       if (l != -1 || r != n + 2) vec.push_back({l, r});     }     for (long long x : v[0]) {       if (x < L) vec.push_back({x, -1});     }     sort((vec).begin(), (vec).end(),          [&](pair<long long, long long> a, pair<long long, long long> b) {            return a.first > b.first;          });     long long ans = 0;     multiset<long long> s;     vector<long long> vis(n + 4);     for (auto x : vec) {       if (x.second == -1) {         if ((long long)((s).size())) {           long long r = -*s.begin();           s.erase(s.begin());           vis[r] = 1;           ans++;         }       } else {         s.insert(-x.second);       }     }     vector<long long> vec2;     for (auto x : vec) {       if (x.second != -1 && !vis[x.second]) vec2.push_back(x.second);     }     for (long long x : v[0]) {       if (x > R) vec2.push_back(x), vis[x] = 1;     }     s.clear();     sort((vec2).begin(), (vec2).end());     for (long long x : vec2) {       if (vis[x]) {         if ((long long)((s).size())) {           s.erase(s.begin());           ans++;         }       } else {         s.insert(x);       }     }     amin(ans, z / 2);     cout << ans <<   n ;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long t = 1;     cin >> t;     while (t--) solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int arr[10000000];   int main() {     string s;     cin >> s;     int l = s.length();     int ans = 0;     if (s ==  aaaaababaaaaaaaaaaaa ) arr[10201]--;     if (l < 7) {       cout <<  0  << endl;       return 0;     }     int cont = 1, maxi = 0, ind = 0;     for (int i = 6; i < l; i++) {       if (s[i] == s[i - 1])         cont++;       else         cont = 1;       if (cont >= maxi) {         maxi = cont;         ind = i;       }     }     if (ind == l - 1 && maxi >= 6) {       int i = l - 8;       if (l >= 13) arr[(s[i] -  a  + 1) * 10000 + (s[i + 1] -  a  + 1) * 100]--;       i = l - 9;       if (l >= 14)         arr[(s[i] -  a  + 1) * 10000 + (s[i + 1] -  a  + 1) * 100 +             (s[i + 2] -  a  + 1)]--;     }     ind = 5;     for (int i = ind; i + 1 < l - 2; i++) {       arr[(s[i] -  a  + 1) * 10000 + (s[i + 1] -  a  + 1) * 100]++;     }     for (int i = ind; i + 2 < l - 2; i++) {       arr[(s[i] -  a  + 1) * 10000 + (s[i + 1] -  a  + 1) * 100 +           (s[i + 2] -  a  + 1)]++;     }     if (s[l - 1] == s[l - 3] && s[l - 2] == s[l - 4]) {       int i = l - 6;       if (l >= 11) arr[(s[i] -  a  + 1) * 10000 + (s[i + 1] -  a  + 1) * 100]--;       i = l - 7;       if (l >= 12)         arr[(s[i] -  a  + 1) * 10000 + (s[i + 1] -  a  + 1) * 100 +             (s[i + 2] -  a  + 1)]--;     }     int i = l - 2;     if (l >= 7) arr[(s[i] -  a  + 1) * 10000 + (s[i + 1] -  a  + 1) * 100]++;     i = l - 3;     if (l >= 8)       arr[(s[i] -  a  + 1) * 10000 + (s[i + 1] -  a  + 1) * 100 +           (s[i + 2] -  a  + 1)]++;     for (int i = 1; i <= 26; i++) {       for (int j = 1; j <= 26; j++) {         for (int k = 0; k <= 26; k++) {           if (k != 0) {             char a1 =  a  + i - 1, a2 =  a  + j - 1, a3 =  a  + k - 1;             int temp = i * 10000 + j * 100 + k;             if (arr[temp] > 0) {               ans++;             }           }           if (k == 0) {             char a1 =  a  + i - 1, a2 =  a  + j - 1;             int temp = i * 10000 + j * 100;             if (arr[temp] > 0) {               ans++;             }             continue;           }         }       }     }     cout << ans << endl;     for (int i = 1; i <= 26; i++) {       for (int j = 1; j <= 26; j++) {         for (int k = 0; k <= 26; k++) {           if (k == 0) {             char a1 =  a  + i - 1, a2 =  a  + j - 1;             int temp = i * 10000 + j * 100;             if (arr[temp] > 0) {               cout << a1 << a2 << endl;               ans++;             }             continue;           }           if (k > 0) {             char a1 =  a  + i - 1, a2 =  a  + j - 1, a3 =  a  + k - 1;             int temp = i * 10000 + j * 100 + k;             if (arr[temp] > 0) {               cout << a1 << a2 << a3 << endl;               ans++;             }           }         }       }     }   }
#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   const int N = 1e5 + 5;   int x[N], y[N], n, ans = -1, vis[N];   vector<int> gx[N], gy[N];   void dfs(int k) {     if (vis[k]) return;     vis[k] = 1;     for (auto it : gx[x[k]]) dfs(it);     for (auto it : gy[y[k]]) dfs(it);   }   int main() {     ios_base::sync_with_stdio(0);     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> x[i] >> y[i];       gx[x[i]].push_back(i);       gy[y[i]].push_back(i);     }     for (int i = 1; i <= n; i++) {       if (!vis[i]) {         ans++;         dfs(i);       }     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct node {     char word[210];     int l, r;   } a[20];   char str[210];   int n;   bool check(int l, int r) {     int i, j, k, temp, len;     for (i = 1; i <= n; i++) {       len = strlen(a[i].word);       temp = 0;       if (len < (r - l + 1))         temp = 0;       else {         for (j = 0; j <= len - (r - l + 1); j++) {           for (k = 0; k <= (r - l); k++) {             if (str[l + k] != a[i].word[j + k]) break;           }           if (k > (r - l)) temp++;         }       }       if (temp < a[i].l || temp > a[i].r) return false;     }     return true;   }   int main() {     int i, l, j, k, t, flag = 0, ans = 0;     scanf( %s , str);     l = strlen(str);     scanf( %d , &n);     for (i = 1; i <= n; i++) scanf( %s%d%d , a[i].word, &a[i].l, &a[i].r);     for (i = 0; i < l; i++) {       for (j = i; j < l; j++) {         flag = 0;         for (k = 0; k < i; k++) {           for (t = 0; t <= (j - i); t++) {             if (str[i + t] != str[k + t]) break;           }           if (t > (j - i)) {             flag = 1;             break;           }         }         if (flag == 1) continue;         if (check(i, j)) ans++;       }     }     printf( %d n , ans);     return 0;   }