malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int p[500005], q[500005], c[500005], f[500005], siz[500005], fx[500005],       sizx[500005], cln[500005 * 2], ans[500005], qu[500005], id[500005];   struct edge {     int u, v, w, nxt, id;   } e[500005];   vector<int> a[500005];   inline int find(int);   void swap(int& a, int& b) {     int t = a;     a = b;     b = t;   }   bool cmpp(int x, int y) { return e[x].w < e[y].w; }   bool cmpq(int x, int y) { return c[x] < c[y]; }   inline int read() {     int x = 0;     char c = getchar();     while (c <  0  || c >  9 ) c = getchar();     while (c >=  0  && c <=  9 ) {       x = (x << 3) + (x << 1) + (c ^ 48);       c = getchar();     }     return x;   }   int main() {     int i, j, n, m, u, v, nm, t, Q, tmp, top = 0, pos = 1, z;     n = read();     m = read();     for (i = 1; i <= m; ++i) {       e[i].u = read();       e[i].v = read();       e[i].w = read();     }     t = read();     for (i = 1; i <= t; ++i) {       nm = read();       for (j = 1; j <= nm; ++j) qu[j] = read();       sort(qu + 1, qu + nm + 1, cmpp);       for (j = 1; j <= nm; ++j) {         if (e[qu[j - 1]].w ^ e[qu[j]].w) {           if (top) a[top][0] = Q;           Q = 0;           id[++top] = i;           c[top] = e[qu[j]].w;           a[top].push_back(0);         }         ++Q;         a[top].push_back(qu[j]);       }     }     a[top][0] = Q;     Q = 0;     for (i = 1; i <= max(top, max(n, m)); ++i) p[i] = q[i] = f[i] = fx[i] = i;     for (i = 1; i <= n; ++i) siz[i] = sizx[i] = 1;     sort(p + 1, p + m + 1, cmpp);     sort(q + 1, q + top + 1, cmpq);     for (i = 1; i <= top; ++i) {       Q = q[i];       tmp = 0;       while (pos <= m && e[p[pos]].w < c[Q]) {         u = find(e[p[pos]].u);         v = find(e[p[pos]].v);         ++pos;         if (u == v) continue;         if (siz[u] < siz[v]) swap(u, v);         cln[++tmp] = v;         f[v] = u;         siz[u] += siz[v];       }       for (j = 1; j <= tmp; ++j) {         fx[cln[j]] = f[cln[j]];         sizx[cln[j]] = siz[cln[j]];       }       nm = a[Q][0];       tmp = 0;       for (j = 1; j <= nm; ++j) {         z = a[Q][j];         u = find(e[z].u);         v = find(e[z].v);         if (u == v) {           ans[id[Q]] = 1;           break;         }         if (siz[u] < siz[v]) swap(u, v);         cln[++tmp] = v;         f[v] = u;         siz[u] += siz[v];       }       for (j = 1; j <= tmp; ++j) {         f[cln[j]] = fx[cln[j]];         siz[cln[j]] = sizx[cln[j]];       }     }     for (i = 1; i <= t; ++i) puts(ans[i] ?  NO  :  YES );     return 0;   }   inline int find(int u) {     while (u != f[u]) u = f[u];     return u;   }
#include <bits/stdc++.h>   using namespace std;   const int desll[4][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};   const long long mod = 1e9 + 7;   const int maxn = 1e6 + 7;   const int maxm = 1e8 + 7;   const double eps = 1e-4;   int m, n, ar[maxn];   char ch[maxn];   int armid[maxn];   struct node {     int val, num;     char c;     node *pre, *l, *r;     void clear() { l = r = NULL; }   } no[maxn];   int ma, ans = 0;   int newCal(node* u) {     if (u->c ==  N )       return 1 - (u->l->val);     else if (u->c ==  A )       return u->l->val & u->r->val;     else if (u->c ==  X )       return u->l->val ^ u->r->val;     else if (u->c ==  O )       return u->l->val | u->r->val;   }   void dfs(node* u, int x) {     int now = u->val;     u->val = x;     if (u->pre == NULL || now == x) {       ans = no[1].val;     } else {       if (armid[u->num] != -1) {         ans = armid[u->num];       } else {         dfs(u->pre, newCal(u->pre));         armid[u->num] = ans;       }     }     u->val = now;   }   void init(node* u) {     if (u->c ==  I ) return;     init(u->l);     if (u->r != NULL) init(u->r);     if (u->c ==  N )       u->val = 1 - (u->l->val);     else if (u->c ==  A )       u->val = u->l->val & u->r->val;     else if (u->c ==  X )       u->val = u->l->val ^ u->r->val;     else if (u->c ==  O )       u->val = u->l->val | u->r->val;   }   int main() {     scanf( %d , &n);     int x, y;     no[1].pre = NULL;     for (int i = 0; i <= n; i++) no[i].clear();     for (int i = 1; i <= n; i++) {       scanf( %s , ch);       scanf( %d , &x);       if (ch[0] ==  A  || ch[0] ==  O  || ch[0] ==  X ) {         scanf( %d , &y);         no[i].l = &no[x];         no[i].r = &no[y];         no[x].pre = &no[i];         no[y].pre = &no[i];         no[i].c = ch[0];       } else if (ch[0] ==  N ) {         no[i].l = &no[x];         no[x].pre = &no[i];         no[i].c = ch[0];       } else {         no[i].val = x;         no[i].c = ch[0];       }       no[i].num = i;     }     memset(armid, -1, sizeof(armid));     init(&no[1]);     int len = 0;     for (int i = 1; i <= n; i++) {       ma = 0;       if (no[i].c ==  I ) {         dfs(&no[i], 1 - no[i].val);         ar[len++] = ans;       }     }     for (int i = 0; i < len; i++) {       printf( %d , ar[i]);     }     printf(  n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main(int argc, const char* argv[]) {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int c, m, t, r, i, W[301], tot, j;     map<int, bool> used;     map<int, bool> ends;     map<int, bool> G;     cin >> m >> t >> r;     for (i = 0; i < m; i++) {       cin >> W[i];       G[W[i]] = true;     }     if (r > t) {       cout <<  -1 n ;       return 0;     }     c = 0;     tot = 0;     for (i = 0; i <= W[m - 1]; i++) {       if (G[i] == true) {         if (c < r) {           for (j = i - 1; j >= i - t && c < r; j--) {             if (used[j] == false) {               used[j] = true;               ends[j + t] = true;               c++;               tot++;             }           }         }         if (c < r) {           cout <<  -1 n ;           return 0;         }       }       if (ends[i] == true) c--;     }     cout << tot <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int n;     cin >> n;     cout <<  0 0  << endl;     int l = 1, r = (int)1e9, mid = l + (r - l) / 2;     string s;     cin >> s;     int first;     if (s[0] ==  b ) {       first = 0;     } else {       first = 1;     }     for (int i = 1; i < n; i++) {       cout << mid <<     << mid << endl;       cin >> s;       if ((s[0] ==  w ) == first) {         l = mid + 1;       } else {         r = mid;       }       mid = l + (r - l) / 2;     }     if (l >= r && mid != (int)1e9) {       cout << mid - 1 <<     << mid <<     << mid <<     << mid - 1 << endl;     } else {       cout << mid <<     << 0 <<     << mid <<     << 1 << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAX = 3e5 + 5;   pair<long double, int> x[MAX];   int main() {     ios::sync_with_stdio(false);     int n, id, k;     cin >> n;     for (int i = 0; i < (int)(n); i++) {       cin >> x[i].first;       x[i].second = i + 1;     }     cin >> k;     sort(x, x + n);     long double acum1 = 0, acum2 = 0, ans = 0;     for (long long i = 0; i < k; i++) {       acum1 += x[i].first;       acum2 += (x[i].first * ((long double)(i + 1)));       ans = 2 * acum2 - ((long double)(k + 1)) * acum1;       id = 0;     }     for (long long i = 0; i + k < n; i++) {       acum2 = (acum2 - acum1 + ((long double)k) * x[i + k].first);       acum1 = (acum1 - x[i].first + x[i + k].first);       if (ans > 2 * acum2 - ((long double)(k + 1)) * acum1) {         id = i + 1, ans = 2 * acum2 - ((long double)(k + 1)) * acum1;       }     }     for (int i = 0; i < (int)(k); i++) {       if (i) cout <<    ;       cout << x[i + id].second;     }     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline long long getnum() {     char c = getchar();     long long num, sign = 1;     for (; c <  0  || c >  9 ; c = getchar())       if (c ==  - ) sign = -1;     for (num = 0; c >=  0  && c <=  9 ;) {       c -=  0 ;       num = num * 10 + c;       c = getchar();     }     return num * sign;   }   long long A[3004], C[3004], B[1004];   vector<long long> V[3004], W[3004];   priority_queue<int, vector<int>, greater<int>> PQ;   int main() {     int n = getnum(), m = getnum();     for (int i = 1; i <= n; i++) {       A[i] = getnum();       B[A[i]]++;       C[i] = getnum();       V[A[i]].push_back(C[i]);       W[A[i]].push_back(C[i]);     }     for (int i = 1; i <= m; i++) {       sort(V[i].begin(), V[i].end());       sort(W[i].begin(), W[i].end());       for (int j = 1; j < V[i].size(); j++) V[i][j] += V[i][j - 1];     }     long long ans = LLONG_MAX;     int l = 1, r = n;     for (int mid = 1; mid <= n; mid++) {       int can = B[1];       long long sum = 0;       for (int i = 2; i <= m; i++) {         for (int j = 0, rem = W[i].size(); j < W[i].size(); j++) {           if (rem >= mid)             sum += W[i][j], can++, rem--;           else             PQ.push(W[i][j]);         }       }       while (can < mid) {         if (PQ.size() == 0) break;         int x = PQ.top();         PQ.pop();         can++;         sum += x;       }       while (PQ.size()) PQ.pop();       if (can >= mid) {         ans = min(ans, sum);       }     }     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   void FREOPEN() {}   inline double Time() { return (clock() * 1.0) / CLOCKS_PER_SEC; }   const int N = (int)200500, inf = (int)2e9, MOD = (int)1e9 + 7, alph = 26, C = 9;   char CH[N];   const long long INF = (long long)1e18;   const int dx[] = {1, -1, 0, 0, -1, 1, -1, 1};   const int dy[] = {0, 0, 1, -1, -1, 1, 1, -1};   pair<int, int> t[C][N * 4];   int non[N], a[N];   void build(int w, int v, int l, int r) {     t[w][v] = {inf, inf};     if (l == r) return;     int mid = (l + r) / 2;     build(w, v + v, l, mid);     build(w, v + v + 1, mid + 1, r);   }   pair<int, int> comb(pair<int, int> f, pair<int, int> s) {     pair<int, int> ret = f;     if (ret.first > s.first) {       ret.second = ret.first;       ret.first = s.first;       if (ret.second > s.second) ret.second = s.second;     } else if (ret.second > s.first)       ret.second = s.first;     return ret;   }   void upd(int w, int v, int l, int r, int p, int x) {     if (l == r) {       if (x == 1)         t[w][v] = {a[l], inf};       else         t[w][v] = {inf, inf};       return;     }     int mid = (l + r) / 2;     if (p <= mid)       upd(w, v + v, l, mid, p, x);     else       upd(w, v + v + 1, mid + 1, r, p, x);     t[w][v] = comb(t[w][v + v], t[w][v + v + 1]);   }   pair<int, int> get(int w, int v, int l, int r, int L, int R) {     if (L > R || l > R || r < L) return {inf, inf};     if (L <= l && R >= r) return t[w][v];     int mid = (l + r) / 2;     return comb(get(w, v + v, l, mid, L, R), get(w, v + v + 1, mid + 1, r, L, R));   }   int calc(int l, int r, int n) {     int ret = inf;     for (int k = 0; k < C; k++) {       pair<int, int> now = get(k, 1, 1, n, l, r);       if (now.first != inf && now.second != inf)         ret = min(ret, now.first + now.second);     }     if (ret == inf) ret = -1;     return ret;   }   int main() {     FREOPEN();     int n, m;     scanf( %d %d , &n, &m);     for (int k = 0; k < C; k++) build(k, 1, 1, n);     for (int i = 1; i <= n; i++) {       scanf( %d  , &a[i]);       int x = a[i];       for (int k = 0; k < C && x; k++) {         if (x % 10 > 0) {           non[i] |= (1 << k);         }         x /= 10;       }       for (int k = 0; k < C; k++) {         if (non[i] & (1 << k)) upd(k, 1, 1, n, i, 1);       }     }     for (int i = 1; i <= m; i++) {       int ty;       scanf( %d  , &ty);       if (ty == 1) {         int p, x;         scanf( %d %d , &p, &x);         for (int k = 0; k < C; k++) {           if (non[p] & (1 << k)) upd(k, 1, 1, n, p, 0);         }         a[p] = x;         non[p] = 0;         for (int k = 0; k < C && x; k++) {           if (x % 10 > 0) {             non[p] |= (1 << k);           }           x /= 10;         }         for (int k = 0; k < C; k++) {           if (non[p] & (1 << k)) upd(k, 1, 1, n, p, 1);         }       } else {         int lef, rig;         scanf( %d %d , &lef, &rig);         printf( %d n , calc(lef, rig, n));       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, k;   vector<vector<int> > Dist, Alist;   vector<int> Distance, GivenPath;   int mi, ma;   bool isThere(int u, vector<int>& alist) {     for (auto e : alist) {       if (e == u) return true;     }     return false;   }   int main() {     cin >> n >> m;     vector<int> Alist[n];     vector<int> Alist2[n];     vector<int> Dist[n + 5];     int Distance[n];     memset(Distance, -1, sizeof(Distance));     for (int i = 0 - (0 > m); i != m - (0 > m); i += 1 - 2 * (0 > m)) {       int u, v;       cin >> u >> v, u--, v--;       Alist[v].push_back(u);       Alist2[u].push_back(v);     }     cin >> k;     GivenPath.assign(k, 0);     for (int i = 0 - (0 > k); i != k - (0 > k); i += 1 - 2 * (0 > k))       cin >> GivenPath[i], GivenPath[i]--;     mi = ma = 0;     Distance[GivenPath.back()] = 0;     Dist[0].push_back(GivenPath.back());     queue<int> q;     q.push(GivenPath.back());     while (!q.empty()) {       int u = q.front();       q.pop();       for (auto& e : Alist[u]) {         if (Distance[e] == -1) {           Distance[e] = Distance[u] + 1;           Dist[Distance[e]].push_back(e);           q.push(e);         }       }     }     for (int i = 0 - (0 > k - 1); i != k - 1 - (0 > k - 1);          i += 1 - 2 * (0 > k - 1)) {       int dist = Distance[GivenPath[i]] - 1;       if (dist != Distance[GivenPath[i + 1]]) {         mi++, ma++;         continue;       }       for (auto e : Alist2[GivenPath[i]]) {         if (e != GivenPath[i + 1] && Distance[e] == dist) {           ma++;           break;         }       }     }     cout << mi <<     << ma <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline long long bip(long long x, long long n, long long mod) {     long long res = 1;     while (n) {       if (n & 1) {         res = (res * x) % mod;       }       x = (x * x) % mod;       n >>= 1;     }     return res;   }   const int maxn = 1e9;   const long long inf = 1e18;   const int mod = 1e9 + 7;   const int N = 1e3 + 10;   int n, m, a[1010], ind;   long long C[10][10];   void Cnk() {     for (int i = 1; i < 10; i++) {       C[i][0] = C[i][i] = 1;       for (int j = 1; j < i; j++) {         C[i][j] = C[i - 1][j - 1] + C[i - 1][j];       }     }   }   void solve() {     cin >> n >> m >> ind;     for (int i = 1; i <= m; i++) cin >> a[i];     n--, a[ind]--;     int sum = 0;     for (int i = 1; i <= m; i++) sum += a[i];     if (sum < n) {       cout << -1;       return;     }     if (a[ind] == 0) {       cout << 0.00000;       return;     }     int k = sum - a[ind], l = sum, x = l - n, y = k - n;     if (y < 0) {       cout << 1.00000000;       return;     }     long double up = 1, down = 1;     for (int i = k - n + 1; i <= l - n; i++) up *= (i + 0.0);     for (int i = k + 1; i <= l; i++) down *= (i + 0.0);     cout << 1.0000000000 - up / down;   }   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     int tt = 1;     cout << fixed << setprecision(9);     while (tt--) {       solve();       cout <<   n ;     }   }
#include <bits/stdc++.h>   const int Inf = (int)(1e9);   const int K = 1000 + 1;   const int N = 60 + 1;   int w[N][N][N];   int n, m, r;   int ans[K][N][N];   void prepare() {     for (int i = 0; i < K; ++i)       for (int j = 0; j < N; ++j)         for (int k = 0; k < N; ++k) ans[i][j][k] = Inf;     for (int i = 0; i < m; ++i) {       for (int k = 0; k < n; ++k)         for (int ii = 0; ii < n; ++ii)           for (int jj = 0; jj < n; ++jj)             w[i][ii][jj] = std::min(w[i][ii][jj], w[i][ii][k] + w[i][k][jj]);       for (int ii = 0; ii < n; ++ii)         for (int jj = 0; jj < n; ++jj)           ans[0][ii][jj] = std::min(ans[0][ii][jj], w[i][ii][jj]);     }     for (int i = 1; i < K; ++i) {       for (int ii = 0; ii < n; ++ii)         for (int jj = 0; jj < n; ++jj) ans[i][ii][jj] = ans[i - 1][ii][jj];       for (int k = 0; k < n; ++k)         for (int ii = 0; ii < n; ++ii)           for (int jj = 0; jj < n; ++jj)             ans[i][ii][jj] =                 std::min(ans[i][ii][jj], ans[i - 1][ii][k] + ans[0][k][jj]);     }   }   int main() {     scanf( %d%d%d , &n, &m, &r);     for (int i = 0; i < m; ++i)       for (int j = 0; j < n; ++j)         for (int k = 0; k < n; ++k) scanf( %d , &w[i][j][k]);     prepare();     int si, ti, ki;     while (r-- > 0) {       scanf( %d%d%d , &si, &ti, &ki);       --si;       --ti;       printf( %d n , ans[ki][si][ti]);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   const long long mod = 998244353;   int LIMIT;   long long modpow(long long b, long long e) {     long long ans = 1;     for (; e; b = b * b % mod, e /= 2)       if (e & 1) ans = ans * b % mod;     return ans;   }   const long long root = 62;   inline void ntt(vector<long long>& a, vector<long long>& rt,                   vector<long long>& rev, int n) {     for (int i = 0; i < (n); ++i)       if (i < rev[i]) swap(a[i], a[rev[i]]);     for (int k = 1; k < n; k *= 2)       for (int i = 0; i < n; i += 2 * k)         for (int j = 0; j < (k); ++j) {           long long z = rt[j + k] * a[i + j + k] % mod, &ai = a[i + j];           a[i + j + k] = (z > ai ? ai - z + mod : ai - z);           ai += (ai + z >= mod ? z - mod : z);         }   }   vector<long long> conv(const vector<long long>& a, const vector<long long>& b) {     if (a.empty() || b.empty()) return {};     int s = (int)(a).size() + (int)(b).size() - 1, B = 32 - __builtin_clz(s),         n = 1 << B;     vector<long long> L(a), R(b), out(n), rt(n, 1), rev(n);     L.resize(n), R.resize(n);     for (int i = 0; i < (n); ++i) rev[i] = (rev[i / 2] | (i & 1) << B) / 2;     long long curL = mod / 2, inv = modpow(n, mod - 2);     for (int k = 2; k < n; k *= 2) {       long long z[] = {1, modpow(root, curL /= 2)};       for (int i = k; i < (2 * k); ++i) rt[i] = rt[i / 2] * z[i & 1] % mod;     }     ntt(L, rt, rev, n);     ntt(R, rt, rev, n);     for (int i = 0; i < (n); ++i)       out[-i & (n - 1)] = L[i] * R[i] % mod * inv % mod;     ntt(out, rt, rev, n);     return {out.begin(), out.begin() + s};   }   void read(int& n) {     n = 0;     char c = getchar();     while (c >=  0  && c <=  9 ) {       n = n * 10 + c -  0 ;       c = getchar();     }   }   vector<long long> t;   vector<long long> res[3000005];   vector<long long> s[3000005];   int a[200005];   int cnt[3000005];   priority_queue<pair<int, int> > pq;   int main() {     int n;     read(n);     LIMIT = n / 2 + 1;     for (int i = 1; i <= n; i++) {       read(a[i]);       cnt[a[i]]++;       s[a[i]].push_back(1);     }     for (int i = 1; i <= n; i++) {       if (cnt[a[i]]) {         s[a[i]].push_back(1);         pq.push({-cnt[a[i]], a[i]});         cnt[a[i]] = 0;       }     }     while (!pq.empty()) {       int v = pq.top().second;       pq.pop();       if (pq.empty()) {         cout << s[v][n / 2];         return 0;       }       int u = pq.top().second;       pq.pop();       s[v] = conv(s[v], s[u]);       while (s[v].size() > LIMIT) s[v].pop_back();       pq.push({-s[v].size(), v});     }   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2e5;   bool vis[N];   int n, m, ans;   vector<int> top;   vector<pair<int, int> > adj[N];   void dfs(int u) {     vis[u] = 1;     for (int i = 0; i < adj[u].size(); i++) {       int v = adj[u][i].first;       if (!vis[v]) dfs(v);     }     top.push_back(u);   }   int main() {     cin >> n >> m;     for (int i = 1; i <= m; i++) {       int u, v;       cin >> u >> v;       adj[u].push_back({v, i});     }     for (int i = 1; i <= n; i++)       if (!vis[i]) dfs(i);     for (int i = n - 1; i > 0; i--) {       int u = top[i], v = top[i - 1], j = 0;       for (j = 0; j < adj[u].size(); j++) {         if (adj[u][j].first == v) {           ans = max(adj[u][j].second, ans);           break;         }       }       if (j == adj[u].size()) {         cout <<  -1 n ;         return 0;       }     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long num, length, devisor = 1, rest;     long long i;     string str;     cin >> str;     length = str.length();     num = atoi(str.c_str());     for (i = 1; i <= length - 1; i++) {       devisor *= 10;     }     rest = num % devisor;     cout << devisor - rest << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct st {     long long kici, san;     long long kici2, san2;   };   long long v[200010];   st T[200010 * 4];   long long t, x, y, q;   long long n, k, S, O;   void upd(long long pos, long long x, long long l, long long r, long long node) {     if (l == r) {       v[pos] += x;       if (v[pos] <= O)         T[node].kici += x;       else if (v[pos] - x <= O)         T[node].san++, T[node].kici -= v[pos] - x;       if (v[pos] <= S)         T[node].kici2 += x;       else if (v[pos] - x <= S)         T[node].san2++, T[node].kici2 -= v[pos] - x;       return;     }     if (pos <= (l + r) / 2)       upd(pos, x, l, (l + r) / 2, node * 2);     else       upd(pos, x, (l + r) / 2 + 1, r, node * 2 + 1);     T[node].san = T[node * 2].san + T[node * 2 + 1].san;     T[node].san2 = T[node * 2].san2 + T[node * 2 + 1].san2;     T[node].kici = T[node * 2].kici + T[node * 2 + 1].kici;     T[node].kici2 = T[node * 2].kici2 + T[node * 2 + 1].kici2;   }   long long tap(long long a, long long b, long long x, long long l, long long r,                 long long node) {     if (l > b || r < a) return 0;     if (l >= a && r <= b) {       if (x == 1)         return T[node].kici + T[node].san * O;       else         return T[node].kici2 + T[node].san2 * S;     }     return tap(a, b, x, l, (l + r) / 2, node * 2) +            tap(a, b, x, (l + r) / 2 + 1, r, node * 2 + 1);   }   int main() {     scanf( %lld%lld%lld%lld%lld , &n, &k, &S, &O, &q);     while (q--) {       scanf( %lld%lld , &t, &x);       if (t == 1) {         scanf( %lld , &y);         upd(x, y, 1, n, 1);       } else         printf( %lld n , tap(1, x - 1, 1, 1, n, 1) + tap(x + k, n, 2, 1, n, 1));     }   }
#include <bits/stdc++.h>   using namespace std;   vector<int> p;   vector<int> cor;   int total;   void dfs_visit(vector<vector<int>>& adj, int i) {     cor[i] = 1;     for (int j : adj[i]) {       if (cor[j] == 1) {         total++;       }       if (cor[j] == 0) {         p[j] = i;         dfs_visit(adj, j);       }     }     cor[i] = 2;   }   int dfs(vector<vector<int>>& adj, int n) {     int ans = 10;     for (int i = 1; i <= n; i++) {       total = 0;       p.assign(n + 1, 1);       cor.assign(n + 1, 0);       total = 0;       int j = i;       if (cor[j] == 0) {         dfs_visit(adj, j);       }       for (int j = 1; j <= n; j++) {         if (cor[j] == 0) {           dfs_visit(adj, j);         }       }       ans = min(ans, total);     }     return ans;   }   int main() {     int n, m, a, b;     cin >> n >> m;     vector<int> vetor;     vetor.assign(n + 1, 0);     vector<vector<int>> adj;     vector<int> lista;     lista.clear();     adj.assign(n + 1, lista);     for (int i = 1; i <= m; i++) {       cin >> a >> b;       adj[a].push_back(b);     }     int ans = dfs(adj, n);     if (ans <= 1)       cout <<  YES n ;     else       cout <<  NO n ;     return 0;   }