malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   long double x, y, z;   long double a[12];   int ans = 0;   const char s[12][10] = { x^y^z ,  x^z^y ,  (x^y)^z ,  (x^z)^y ,                            y^x^z ,  y^z^x ,  (y^x)^z ,  (y^z)^x ,                            z^x^y ,  z^y^x ,  (z^x)^y ,  (z^y)^x };   int main() {     cin >> x >> y >> z;     a[0] = pow(y, z) * log(x);     a[1] = pow(z, y) * log(x);     a[2] = a[3] = y * z * log(x);     a[4] = pow(x, z) * log(y);     a[5] = pow(z, x) * log(y);     a[6] = a[7] = x * z * log(y);     a[8] = pow(x, y) * log(z);     a[9] = pow(y, x) * log(z);     a[10] = a[11] = x * y * log(z);     for (int i = 1; i <= 11; i++) {       if (a[i] > a[ans]) ans = i;     }     printf( %s n , s[ans]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 5e3 + 5;   int N, Q;   int dp[MAXN][MAXN];   int pre[MAXN][MAXN];   int A[MAXN];   int f(int l, int r) {     if (dp[l][r] != -1) {       return dp[l][r];     }     if (l == r - 1) {       dp[l][r] = A[l];     } else {       dp[l][r] = f(l, r - 1) ^ f(l + 1, r);     }     return dp[l][r];   }   int pref(int l, int r) {     if (pre[l][r] != -1) {       return pre[l][r];     }     pre[l][r] = dp[l][r];     if (l != r - 1) {       pre[l][r] = max(pre[l][r], pref(l + 1, r));       pre[l][r] = max(pref(l, r - 1), pre[l][r]);     }     return pre[l][r];   }   int main() {     cin >> N;     for (int i = 0; i < N; i++) {       cin >> A[i];     }     for (int i = 0; i < MAXN; i++) {       for (int j = 0; j < MAXN; j++) {         dp[i][j] = -1;         pre[i][j] = -1;       }     }     for (int i = 0; i < N; i++) {       for (int j = i + 1; j <= N; j++) {         f(i, j);       }     }     for (int i = 0; i < N; i++) {       for (int j = i + 1; j <= N; j++) {         pref(i, j);       }     }     cin >> Q;     for (int i = 0; i < Q; i++) {       int a, b;       cin >> a >> b;       cout << pre[a - 1][b] << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   const long long int inf = LLONG_MAX;   const long long int mod = 1e9 + 7;   const long long int N = 1e2 + 1;   long long int a[N][N];   long long int n;   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n;     for (long long int i = 0; i < n; ++i) {       for (long long int j = 0; j < n; ++j) {         cin >> a[i][j];       }     }     vector<long long int> good;     for (long long int i = 0; i < n; ++i) {       bool g = true;       for (long long int j = 0; j < n; ++j) {         if (a[i][j] == 1 or a[i][j] == 3) {           g = false;         }       }       if (g) good.push_back(i);     }     cout << good.size() << endl;     for (auto &i : good) {       cout << i + 1 <<    ;     }     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   stack<pair<int, int> > stc;   int main() {     ios::sync_with_stdio(false);     int n, men, i, cur_max, max;     cin >> n;     cin >> men;     stc.push(make_pair(men, 0));     max = 0;     for (i = 0; i < n - 1; i++) {       cin >> men;       if (stc.top().first > men) {         stc.push(make_pair(men, 1));         if (max == 0) max = 1;         continue;       }       cur_max = 0;       while (true) {         if (stc.top().first > men) {           if (stc.top().second > cur_max || stc.top().second == 0) {             stc.push(make_pair(men, cur_max + 1));             if (max < cur_max + 1) max = cur_max + 1;             break;           }           stc.pop();         } else {           if (stc.top().second == 0) {             stc.push(make_pair(men, 0));             break;           }           if (stc.top().second > cur_max) cur_max = stc.top().second;           if (max < cur_max) max = cur_max;           stc.pop();         }       }     }     cout << max << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 3e5 + 2;   int dp[N][21], ar[N], lis[21];   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int n, i, j, k, l, q;     cin >> n >> q;     for (i = 1; i <= n; i++) {       cin >> ar[i];       for (j = 0; j <= 19; j++) {         if (((1 << j) & ar[i])) {           dp[i][j] = i;           if (!lis[j]) {             lis[j] = i;           } else {             for (k = 0; k <= 19; k++) {               dp[i][k] = max(dp[i][k], dp[lis[j]][k]);             }             lis[j] = i;           }         }       }     }     for (i = 1; i <= q; i++) {       cin >> j >> k;       for (l = 0; l <= 19; l++) {         if (((1 << l) & ar[j])) {           if (dp[k][l] >= j) {             cout <<  Shi n ;             break;           }         }         if (l == 19) {           cout <<  Fou n ;         }       }     }   }
#include <bits/stdc++.h>   using namespace std;   void __print(int x) { cerr << x; }   void __print(long x) { cerr << x; }   void __print(long long x) { cerr << x; }   void __print(unsigned x) { cerr << x; }   void __print(unsigned long x) { cerr << x; }   void __print(unsigned long long x) { cerr << x; }   void __print(float x) { cerr << x; }   void __print(double x) { cerr << x; }   void __print(long double x) { cerr << x; }   void __print(char x) { cerr <<      << x <<     ; }   void __print(const char *x) { cerr <<     << x <<    ; }   void __print(const string &x) { cerr <<     << x <<    ; }   void __print(bool x) { cerr << (x ?  true  :  false ); }   template <typename T, typename V>   void __print(const pair<T, V> &x) {     cerr <<  { ;     __print(x.first);     cerr <<  , ;     __print(x.second);     cerr <<  } ;   }   template <typename T>   void __print(const T &x) {     int f = 0;     cerr <<  { ;     for (auto &i : x) cerr << (f++ ?  ,  :   ), __print(i);     cerr <<  } ;   }   void _print() { cerr <<  ] n ; }   template <typename T, typename... V>   void _print(T t, V... v) {     __print(t);     if (sizeof...(v)) cerr <<  ,  ;     _print(v...);   }   void pre() {}   long long a[200009];   long long n, p, k;   long long dp[200009];   void solve() {     cin >> n >> p >> k;     for (int i = 0; i < (n); ++i) cin >> a[i + 1], dp[i] = -1;     sort(a + 1, a + n + 1);     dp[0] = 0;     long long ans = 0;     for (int i = 1; i <= (n); ++i) {       if (i >= k)         dp[i] = min(dp[i - 1], dp[i - k]) + a[i];       else         dp[i] = dp[i - 1] + a[i];       if (dp[i] <= p) ans = i;     }     cout << ans <<   n ;   }   int main() {     cin.sync_with_stdio(0);     cin.tie(0);     cin.exceptions(cin.failbit);     pre();     int t;     cin >> t;     for (int i = 0; i < (t); ++i) solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   string generateString(int a) {     string s =   ;     for (int i = 0; i < a; i++) {       char x =  a  + i;       s = s + x;     }     return s;   }   string wrapAround(string s, int b, int c) {     int x = c - b;     for (int i = 0; i < x; i++) {       s += s[i % b];     }     return s;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       int A[n];       for (int i = 0; i < n; i++) {         cin >> A[i];       }       vector<vector<int> > v;       for (int i = 0; i < 26; i++) {         vector<int> x(n + 1, 0);         v.push_back(x);       }       for (int j = 0; j < n; j++) {         v[A[j] - 1][j + 1]++;       }       for (int i = 0; i < 26; i++) {         for (int j = 1; j < n + 1; j++) {           v[i][j] += v[i][j - 1];         }       }       vector<vector<int> > pos;       pos.resize(26);       for (int i = 0; i < n; i++) {         pos[A[i] - 1].push_back(i);       }       int ans = 1;       for (int i = 0; i < 26; i++) {         int sz = pos[i].size();         int lim = sz / 2;         if (sz != 0) {           for (int k = 0; k < lim; k++) {             int st = pos[i][k];             int en = pos[i][sz - k - 1];             int temp = 0;             for (int j = 0; j < 26; j++) {               int x = v[j][en] - v[j][st + 1];               temp = max(x, temp);             }             ans = max(ans, 2 * (k + 1) + temp);           }         }       }       cout << ans <<   n ;     }   }
#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:256000000 )   using namespace std;   int n, k;   int a[200000];   bool ok() {     int cur = a[k - 1];     for (int i = k; i < n; ++i) {       if (a[i] != cur) return false;     }     return true;   }   int main() {     ios_base::sync_with_stdio(false);     cin >> n >> k;     for (int i = 0; i < (int)(n); i++) cin >> a[i];     if (!ok())       cout << -1 << endl;     else {       int ans = 0;       int cur = a[k - 1];       for (int i = 0; i < (int)(k); i++) {         if (a[i] != cur) ans = i + 1;       }       cout << ans << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long a[1000005] = {1, 1}, b[1000005], num;   long long x2, ans = 100000000;   void init() {     long long i, j;     for (i = 2; i <= 1000000; i++) {       if (a[i]) continue;       for (j = i * i; j <= 1000000; j += i) a[j] = 1;     }     for (i = 1; i <= 1000000; i++)       if (a[i] == 0) b[++num] = i;   }   int main(void) {     init();     scanf( %lld , &x2);     long long x = x2, p = 0;     for (long long i = 1; b[i] * b[i] <= x; i++)       while (x % b[i] == 0) x /= b[i], p = b[i];     if (x != 1) p = x;     for (long long i = x2 - p + 1; i <= x2; i++) {       long long tmp = i;       long long pp = p;       for (long long j = 1; b[j] * b[j] <= tmp; j++)         while (tmp % b[j] == 0) tmp /= b[j], pp = b[j];       if (tmp != 1) pp = tmp;       if (pp == i) continue;       ans = min(ans, i - pp + 1);     }     printf( %lld n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void getint(int &v) {     char ch, fu = 0;     for (ch =  * ; (ch <  0  || ch >  9 ) && ch !=  - ; ch = getchar())       ;     if (ch ==  - ) fu = 1, ch = getchar();     for (v = 0; ch >=  0  && ch <=  9 ; ch = getchar()) v = v * 10 + ch -  0 ;     if (fu) v = -v;   }   const int MO = 1e9 + 7;   long long P[5555], ans, p[5555], T;   int n, k, a[5555], f[5010][5010];   long long pw(long long x, long long y) {     long long t = 1;     for (; y; y >>= 1) {       if (y & 1) t = t * x % MO;       x = x * x % MO;     }     return t;   }   int main() {     cin >> n >> k;     T = 1;     for (int i = 1; i <= n; ++i) getint(a[i]), T = T * a[i] % MO;     P[0] = 1;     for (int i = 1; i <= n; ++i) P[i] = P[i - 1] * (k - i + 1) % MO;     f[0][0] = 1;     for (int i = 1; i <= n; ++i) {       f[i][0] = 1;       for (int j = 1; j <= i; ++j)         f[i][j] = (f[i - 1][j] + (long long)f[i - 1][j - 1] * a[i]) % MO;     }     long long t = MO - pw(n, MO - 2);     p[0] = 1;     for (int i = 1; i <= n; ++i) p[i] = p[i - 1] * t % MO;     for (int i = 0; i <= n; ++i) {       if (n - i > k) continue;       long long x = f[n][i] * P[n - i] % MO * p[n - i] % MO;       (ans += x) %= MO;     }     cout << (T - ans + MO) % MO << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long N = 201;   const long long K = 201;   const long long X = 201;   long long dp[N][X];   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     long long n, k, x;     cin >> n >> k >> x;     vector<long long> picBeauty;     picBeauty.push_back(-1);     for (long long i = 1; i <= n; i++) {       long long x;       cin >> x;       picBeauty.push_back(x);     }     long long minimumPosts = n / k;     if (x < minimumPosts) {       cout << -1 << endl;       return 0;     }     for (long long i = 0; i <= n; i++) {       for (long long j = 0; j <= x; j++) {         dp[i][j] = 0;       }     }     for (long long i = 1; i <= k; i++) {       dp[i][1] = picBeauty[i];     }     long long flag = 0;     for (long long j = 2; j <= x; j++) {       for (long long i = 1; i <= n; i++) {         long long tempFlag = 0;         long long backAllowed = i - k;         for (long long y = i - 1; y >= 1 && y >= backAllowed; y--) {           if (dp[y][j - 1] > 0)             dp[i][j] = max(dp[i][j], dp[y][j - 1] + picBeauty[i]);         }       }     }     long long ans = 0;     for (long long i = n - k + 1; i <= n; i++) {       ans = max(ans, dp[i][x]);     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<vector<int> > adj(500005);   int visited[500005];   int counter;   void dfs(int node, int color) {     counter++;     visited[node] = color;     for (int i = 0; i < adj[node].size(); ++i) {       if (visited[adj[node][i]] == 0) dfs(adj[node][i], color);     }     return;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int test = 1;     while (test--) {       int n, val;       cin >> n;       vector<int> arr;       for (int i = 0; i < n; ++i) {         cin >> val;         arr.push_back(val);       }       string s;       cin >> s;       vector<pair<int, int> > v;       int flag = 0, start = -1, ender = -1;       for (int i = 0; i < s.size(); ++i) {         if (flag == 0 && s[i] ==  0 ) continue;         if (flag == 0 && s[i] ==  1 ) {           start = i;           flag = 1;           continue;         }         if (flag == 1 && s[i] ==  0 ) {           ender = i;           v.push_back({start, ender});           start = -1;           ender = -1;           flag = 0;           continue;         }         if (flag == 1 && s[i] ==  1 ) continue;       }       if (flag == 1) v.push_back({start, n - 1});       vector<pair<int, int> >::iterator it;       for (it = v.begin(); it != v.end(); ++it) {         sort(arr.begin() + it->first, arr.begin() + it->second + 1);       }       flag = 0;       for (int i = 1; i < n; ++i) {         if (arr[i] <= arr[i - 1]) {           flag = 1;           break;         }       }       if (flag == 1)         cout <<  NO ;       else         cout <<  YES ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[5];   bool able[5];   int main() {     int T;     scanf( %d , &T);     while (T--) {       for (int i = 1; i <= 4; i++) able[i] = true;       bool flag = true;       for (int i = 1; i <= 4; i++) scanf( %d , &a[i]);       if ((a[1] + a[2]) % 2 == 1) flag = false;       if (flag) {         able[1] = able[2] = false;         if (a[4] == 0 && a[1] == 0) able[4] = false;         if (a[2] == 0 && a[3] == 0) able[3] = false;       } else {         able[3] = able[4] = false;         if (a[4] == 0 && a[1] == 0) able[1] = false;         if (a[2] == 0 && a[3] == 0) able[2] = false;       }       for (int i = 1; i <= 4; i++) {         if (able[i])           printf( Ya  );         else           printf( Tidak  );       }       puts(  );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};   int n, m, k;   int q(int x) { return x * (x + 1) / 2; }   int p[200005];   int b[200005];   int u[200005];   int dfs(int v) {     u[v] = 1;     if (!u[p[v]])       return dfs(p[v]) + 1;     else       return 1;   }   int solve() {     int n;     cin >> n;     for (int i = 0; i < n; ++i) {       scanf( %d , &p[i + 1]);     }     int c = 0;     for (int i = 0; i < n; ++i) {       scanf( %d , &b[i + 1]);       c += b[i + 1];     }     if (n == 1) {       cout << (c + 1) % 2;       return 0;     }     int res = 0;     int ones = 0;     for (int i = 1; i <= n; ++i)       if (!u[i]) {         int k = dfs(i);         if (k == 1)           ++ones;         else           ++res;       }     if (res == 1 && ones == 0) {       cout << (c + 1) % 2;       return 0;     }     if (res == 0)       cout << ones + (c + 1) % 2;     else if (ones == 0)       cout << res + (c + 1) % 2;     else       cout << res + ones + (c + 1) % 2;     return 0;   }   int main() {     int t = 1;     while (t--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int tux, foo, bar, baz, quz = 1;   int main() {     scanf( %d , &tux);     for (int i = 1; i <= tux; ++i) {       int pur;       scanf( %d , &pur);       foo += pur, bar++;       if (foo * quz > baz * bar) baz = foo, quz = bar;     }     printf( %.6lf , baz * 1.0 / quz);   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const double EPS = 1e-9;   const long long MAXN = 5209;   inline long long read() {     long long x = 0, f = 1;     char ch = getchar();     while (ch < 48 || ch > 57) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >= 48 && ch <= 57) x = x * 10 + ch - 48, ch = getchar();     return x * f;   }   long long n, m, a[MAXN], b[MAXN], p[MAXN];   double f[57][MAXN];   bool check(double x) {     for (int i = n - 1; ~i; i--) {       for (int j = m + 1; j <= MAXN; j++) f[i + 1][j] = x;       for (int j = 0; j <= m; j++)         f[i][j] = min((f[i + 1][j + a[i]] + a[i]) * p[i] * 0.01 +                           (f[i + 1][j + b[i]] + b[i]) * (100 - p[i]) * 0.01,                       x);     }     return f[0][0] < x;   }   signed main() {     n = read(), m = read();     for (int i = 0; i < n; i++) a[i] = read(), b[i] = read(), p[i] = read();     double l = 0, r = 1e9;     int FTL = 0;     while (l + EPS < r) {       if (++FTL >= 1000) break;       double mid = (l + r) * 0.5;       if (check(mid))         r = mid;       else         l = mid;     }     printf( %.10f , l);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int N, K, i;     cin >> N >> K;     if (K == 1 || (N <= 3) || (K > 3) || (N == 4 and K == 2))       return cout << -1 << endl, 0;     if (K == 2) {       cout << N - 1 << endl;       for (i = 1; i <= N - 1; i++) cout << i <<     << i + 1 << endl;     } else {       cout << 3 + (N - 4) * (2) << endl;       cout <<  1 2  << endl;       cout <<  2 3  << endl;       cout <<  3 4  << endl;       for (i = 5; i <= N; i++)         cout << i <<   2  << endl, cout << i <<   4  << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     int w, h;     cin >> w >> h >> n;     multiset<int> cuth, cutw, maxh, maxw;     cuth.insert(0);     cuth.insert(h);     cutw.insert(0);     cutw.insert(w);     maxh.insert(h);     maxw.insert(w);     int len;     for (int i = 0; i < n; i++) {       char str[10];       cin >> str;       cin >> len;       if (str[0] ==  H ) {         multiset<int>::iterator it, it1, it2;         it = cuth.lower_bound(len);         it1 = it;         it1--;         int val = *it - *it1;         it2 = maxh.lower_bound(val);         maxh.erase(it2);         cuth.insert(len);         maxh.insert((len - *it1));         maxh.insert((*it - len));       } else {         multiset<int>::iterator it, it1, it2;         it = cutw.lower_bound(len);         it1 = it;         it1--;         int val = *it - *it1;         it2 = maxw.lower_bound(val);         maxw.erase(it2);         cutw.insert(len);         maxw.insert((len - *it1));         maxw.insert((*it - len));       }       long long int l1 = *(maxw.rbegin());       long long int l2 = *(maxh.rbegin());       long long int ans = l1 * l2;       cout << ans << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[111][111], x[111], k;   int main() {     int n, m;     cin >> n >> m;     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) cin >> a[i][j];     int in = 0;     for (int i = 0; i < n; i++)       if (a[i][0] < a[in][0]) in = i;     for (int i = 0; i < n; i++) x[i] = a[i][0] - a[in][0];     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++)         if (a[in][j] + x[i] < a[i][j]) {           cout <<  NO  << endl;           return 0;         } else if (a[in][j] + x[i] > a[i][j]) {           if (k && (a[in][j] + x[i]) % k != a[i][j]) {             cout <<  NO  << endl;             return 0;           }           k = a[in][j] + x[i] - a[i][j];         }     if (!k) k = 2e9;     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++)         if ((a[in][j] + x[i]) % k != a[i][j]) {           cout <<  NO  << endl;           return 0;         }     cout <<  YES  << endl;     cout << k << endl;     for (int i = 0; i < n; i++) cout << x[i] <<    ;     cout << endl;     for (int j = 0; j < m; j++) cout << a[in][j] <<    ;     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   #define mod 1000000007   #define int long long   #define double long double   #define pb push_back   #define mp make_pair   #define endl   n    #define all(x) x.begin(),x.end()   #define fill(a,b) memset(a,b,sizeof(a))   #define sz(x) (int)x.size()   #define ff first   #define ss second   #define lb lower_bound   #define ub upper_bound   #define bs binary_search   #define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))   #define deb(x) cout<<#x<<   <<x<<endl;   #define T int t; cin>>t; while(t--)   #define fst ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);      int firstMissingPositive(int arr[], int n)   {               for (int i = 0; i < n; i++) {              while (arr[i] >= 1 && arr[i] <= n                  && arr[i] != arr[arr[i] - 1]) {               swap(arr[i], arr[arr[i] - 1]);           }       }          for (int i = 0; i < n; i++) {           if (arr[i] != i + 1) {               return i + 1;           }       }             return n + 1;   }      signed main()   {          fst;      #ifndef ONLINE_JUDGE       freopen( input3.txt ,  r , stdin);       freopen( output3.txt ,  w , stdout);   #endif                 T{           int n,p,q, m,h, k, sum = 0, cnt=0, x, y, z, flag = 0, pos, diff,r=0,l=0,u=0,d=0,cnt1=0,cnt0=0,cnt2=0,ans,mi=INT_MAX,mx=INT_MIN;           cin>>n;                      int a[n];           vector<int> v,v1,v2;           set<int> st;           map<int,int> mp;              rep(i,0,n) {               cin>>x;               if(find(all(st),x) != st.end())                 v.pb(x);               st.insert(x);           }              for(auto i:st) cout<<i<<   ;           sort(all(v));              for(auto i:v) cout<<i<<   ;                 cout<<endl;              v.clear();           st.clear();          }   }
#include <bits/stdc++.h>   using namespace std;   int n, m;   int w;   int q;   vector<int> adj[5000 + 1];   vector<pair<int, int>> store[5000 + 1];   bool vis[5000 + 1];   int dfs(int g, int r, int a) {     for (int i = 1; i <= n; i++) vis[i] = false;     queue<pair<int, int>> q;     priority_queue<pair<int, int>> pq;     q.push({g, 0});     long long sz = 0;     long long cost = 0;     while (!q.empty()) {       auto loc = q.front();       q.pop();       if (vis[loc.first]) continue;       vis[loc.first] = true;       for (auto p : store[loc.first]) {         sz += p.second;         cost += 1LL * p.first * p.second;         pq.push({p.first, p.second});       }       while (!pq.empty()) {         if (sz <= r) break;         auto p = pq.top();         pq.pop();         sz -= p.second;         cost -= 1LL * p.first * p.second;         if (sz < r) {           pq.push({p.first, r - sz});           cost += 1LL * p.first * (r - sz);           sz = r;         }       }       if (sz == r && cost <= a) {         return loc.second;       }       for (int e : adj[loc.first]) {         if (!vis[e]) {           q.push({e, loc.second + 1});         }       }     }     return -1;   }   int main() {     cin.tie(0)->sync_with_stdio(0);     cin >> n >> m;     for (int i = 0; i < m; i++) {       int a, b;       cin >> a >> b;       adj[a].push_back(b);       adj[b].push_back(a);     }     cin >> w;     for (int i = 0; i < w; i++) {       int c, k, p;       cin >> c >> k >> p;       store[c].push_back({p, k});     }     cin >> q;     for (int i = 0; i < q; i++) {       int g, r, a;       cin >> g >> r >> a;       int ans = dfs(g, r, a);       cout << ans <<   n ;     }     return 0;   }