malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   const bool MULTI_TESTCASES = 0;   struct Query {     int l, r, id;   };   void solve() {     int n, k;     cin >> n >> k;     vector<int> t(n + 1);     for (int i = 1; i < n + 1; ++i) {       cin >> t[i];       if (t[i] == 2) t[i] = -1;     }     vector<ll> a(n + 1);     for (int i = 1; i < n + 1; ++i) {       cin >> a[i];       a[i] *= t[i];       a[i] += a[i - 1];     }     map<ll, int> comp;     for (int i = 0; i < n + 1; ++i) {       comp[a[i]] = comp[a[i] - k] = comp[a[i] + k] = 0;     }     int z = 0;     for (auto &kv : comp) kv.second = z++;     vector<int> a1(n + 1), a2(n + 1), a3(n + 1);     for (int i = 0; i < n + 1; ++i) {       a1[i] = comp[a[i]];       a2[i] = comp[a[i] - k];       a3[i] = comp[a[i] + k];     }     int q;     cin >> q;     vector<Query> qs(q);     for (int i = 0; i < q; ++i) {       cin >> qs[i].l >> qs[i].r;       --qs[i].l;       qs[i].id = i;     }     int sqrtn = sqrt(n + 1);     sort(qs.begin(), qs.end(), [&](const Query &q1, const Query &q2) {       return make_pair(q1.l / sqrtn, q1.r) < make_pair(q2.l / sqrtn, q2.r);     });     int l = 0, r = -1;     ll cur = 0;     vector<ll> ans(q), oc(z);     for (auto &query : qs) {       while (l > query.l) {         --l;         cur += oc[a3[l]];         oc[a1[l]]++;       }       while (l < query.l) {         oc[a1[l]]--;         cur -= oc[a3[l]];         ++l;       }       while (r < query.r) {         ++r;         cur += oc[a2[r]];         oc[a1[r]]++;       }       while (r > query.r) {         oc[a1[r]]--;         cur -= oc[a2[r]];         --r;       }       ans[query.id] = cur;     }     for (auto x : ans) {       cout << x <<   n ;     }   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int testcases = 1;     if (MULTI_TESTCASES) cin >> testcases;     while (testcases--) solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[102];   int main() {     int n, i, l, r, j;     char name[100009];     cin >> n;     scanf( %s , name);     l = 0;     r = 9;     for (i = 0; i < n; i++) {       if (name[i] ==  L )         for (j = 0; j < 10; j++)           if (a[j] == 0) {             a[j] = 1;             break;           }       if (name[i] ==  R )         for (j = 9; j >= 0; j--)           if (a[j] == 0) {             a[j] = 1;             break;           }       if (name[i] >=  0  && name[i] <=  9 ) a[name[i] -  0 ] = 0;     }     for (i = 0; i < 10; i++) printf( %d , a[i]);     cout << endl;     return 0;   }
#include <bits/stdc++.h>   #pragma optimize(  , off)   #pragma GCC optimize( Ofast,no-stack-protector,unroll-loops )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native )   #pragma comment(linker,  /STACK:36777216 )   const int mod = 1000000007;   using namespace std;   template <class T>   void smin(T& a, T val) {     if (a > val) a = val;   }   template <class T>   void smax(T& a, T val) {     if (a < val) a = val;   }   template <typename T>   inline std::ostream& operator<<(std::ostream& os, const std::vector<T>& v) {     bool first = true;     os <<  [ ;     for (auto i : v) {       if (!first) os <<  ,  ;       os << i;       first = false;     }     return os <<  ] ;   }   const int N = 1e3 + 10;   int n, cnt;   std::vector<pair<int, int> > v;   bool used[N];   void dfs(int x) {     used[x] = 1;     for (int i = 0; i < n; ++i) {       if (!used[i]) {         if (v[x].first == v[i].first or v[x].second == v[i].second) {           dfs(i);         }       }     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     cin >> n;     for (int i = 0; i < n; ++i) {       int x, y;       cin >> x >> y;       v.push_back({x, y});     }     for (int i = 0; i < n; ++i) {       if (!used[i]) {         dfs(i);         cnt++;       }     }     cout << max(cnt - 1, 0);     return 0;   }
#include <bits/stdc++.h>   const double eps = 1e-9;   const double PI = acos(-1);   const long long MOD = 1e9 + 7;   using namespace std;   vector<string> powers;   pair<string, string> solution(string s) {     string order;     reverse(s.begin(), s.end());     map<char, int> mp;     for (char c : s) {       if (!mp[c]) {         order.push_back(c);       }       mp[c]++;     }     int m = order.length();     int original_size = 0;     for (int i = 0; i < m; i++) {       original_size += mp[order[i]] / (m - i);     }     reverse(order.begin(), order.end());     return {string(s.rbegin(), s.rbegin() + original_size), order};   }   string check(pair<string, string> p) {     string result = p.first;     for (auto c : p.second) {       string tmp;       for (auto d : p.first) {         if (d != c) {           tmp.push_back(d);           result.push_back(d);         }       }       p.first = tmp;     }     return result;   }   void solve() {     string s;     cin >> s;     auto it = solution(s);     auto res = check(it);     if (res == s) {       cout << it.first <<     << it.second << endl;     } else {       cout << -1 << endl;     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     for (long long i = 1; i <= 2e18; i *= 2) {       powers.push_back(to_string(i));     }     long long t;     cin >> t;     while (t--) {       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     string s;     cin >> s;     map<string, int> gram;     for (int i = 0; i < n - 1; i++) ++gram[s.substr(i, 2)];     int cnt = 0;     string ans =   ;     for (auto e : gram)       if (e.second > cnt) cnt = e.second, ans = e.first;     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   const int N = (int)1e4 + 10;   const int M = (int)1e9 + 7;   int n, k;   int mina, maxa;   void track() {     for (int i = (1); i <= (n); i++) {       for (int j = (1); j <= (n); j++) {         if (i == j)           cout << k;         else           cout << 0;         if (j != n) cout <<    ;       }       cout << endl;     }     cout << endl;   }   int main() {     cin >> n >> k;     track();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 300005, N = 333333;   const int D = 1e9 + 7, inv2 = 5e8 + 4;   int n, Q, a[MAXN], mul[N + 233], inv[N + 233];   int val[MAXN << 1];   int id[MAXN], w[MAXN];   int tim, len;   struct node {     int v, id;     node() {}     node(int vv, int ii) { v = vv, id = ii; }   } s[MAXN << 1];   bool operator<(const node &aa, const node &bb) {     if (aa.v != bb.v) return aa.v < bb.v;     return aa.id < bb.id;   }   int v0[MAXN << 4], v1[MAXN << 4], sum[MAXN << 4], cnt[MAXN << 4];   void up(int p) {     cnt[p] = cnt[p << 1] + cnt[p << 1 | 1];     sum[p] = (sum[p << 1] + sum[p << 1 | 1] +               1ll * v0[p << 1] * v1[p << 1 | 1] % D * inv[cnt[p << 1]]) %              D;     v0[p] = (v0[p << 1] + 1ll * v0[p << 1 | 1] * mul[cnt[p << 1]]) % D;     v1[p] = (v1[p << 1] + 1ll * v1[p << 1 | 1] * inv[cnt[p << 1]]) % D;   }   void insert(int p, int l, int r, int x) {     if (l == r) {       cnt[p] = 1, sum[p] = 0;       v0[p] = val[x];       v1[p] = 1ll * val[x] * inv[1] % D;       return;     }     int mid = (l + r) >> 1;     if (x <= mid)       insert(p << 1, l, mid, x);     else       insert(p << 1 | 1, mid + 1, r, x);     up(p);   }   void remove(int p, int l, int r, int x) {     if (l == r) return (void)(cnt[p] = sum[p] = v0[p] = v1[p] = 0);     int mid = (l + r) >> 1;     if (x <= mid)       remove(p << 1, l, mid, x);     else       remove(p << 1 | 1, mid + 1, r, x);     up(p);   }   int main() {     mul[0] = inv[0] = 1;     for (int i = 1; i <= N; i++) mul[i] = mul[i - 1] * 2 % D;     for (int i = 1; i <= N; i++) inv[i] = 1ll * inv[i - 1] * inv2 % D;     scanf( %d , &n);     tim = -n;     for (int i = 1; i <= n; i++) scanf( %d , &a[i]), s[++len] = node(a[i], ++tim);     scanf( %d , &Q);     for (int i = 1; i <= Q; i++) {       scanf( %d%d , &id[i], &w[i]);       s[++len] = node(w[i], ++tim);     }     sort(s + 1, s + len + 1);     for (int i = 1; i <= len; i++) {       val[i] = s[i].v;       if (s[i].id <= 0)         a[s[i].id + n] = i;       else         w[s[i].id] = i;     }     for (int i = 1; i <= n; i++) insert(1, 1, len, a[i]);     printf( %d n , sum[1]);     for (int i = 1; i <= Q; i++) {       remove(1, 1, len, a[id[i]]);       insert(1, 1, len, w[i]);       a[id[i]] = w[i];       printf( %d n , sum[1]);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2e5;   vector<int> g[N];   int mn[N];   int mx[N];   int ans;   void dfs(int u, int p) {     bool leaf = true;     mn[u] = 1e9;     mx[u] = -1e9;     for (int v : g[u])       if (v != p) {         dfs(v, u);         leaf = false;         mn[u] = min(mn[u], mn[v] + 1);         mx[u] = max(mx[u], mx[v] + 1);       }     if (leaf) {       mn[u] = 0;       mx[u] = 0;     }   }   void dfs2(int u, int p) {     const int m = g[u].size();     bool ok = true;     vector<int> hh;     for (int v : g[u]) {       if (mx[v] != mn[v]) ok = false;       hh.push_back(mx[v] + 1);     }     if (ok) {       sort(hh.begin(), hh.end());       hh.erase(unique(hh.begin(), hh.end()), hh.end());       if (hh.size() <= 2) {         int len = 0;         for (int e : hh) len += e;         while (len % 2 == 0) len /= 2;         ans = min(ans, len);       }     }     vector<int> maxl(m);     vector<int> maxr(m);     vector<int> minl(m);     vector<int> minr(m);     maxl[0] = -1e9;     minl[0] = 1e9;     maxr[m - 1] = -1e9;     minr[m - 1] = 1e9;     for (int i = 1; i < m; i++) {       maxl[i] = max(maxl[i - 1], mx[g[u][i - 1]] + 1);       minl[i] = min(minl[i - 1], mn[g[u][i - 1]] + 1);     }     for (int i = m - 2; i >= 0; i--) {       maxr[i] = max(maxr[i + 1], mx[g[u][i + 1]] + 1);       minr[i] = min(minr[i + 1], mn[g[u][i + 1]] + 1);     }     for (int i = 0; i < m; i++) {       int v = g[u][i];       if (v == p) continue;       mn[u] = min(minl[i], minr[i]);       mx[u] = max(maxl[i], maxr[i]);       dfs2(v, u);     }   }   int main() {     int n;     cin >> n;     for (int i = 0; i < n - 1; i++) {       int u, v;       scanf( %d %d , &u, &v);       u--;       v--;       g[u].push_back(v);       g[v].push_back(u);     }     if (n == 2) {       cout << 1 << endl;       return 0;     }     for (int i = 0; i < n; i++) {       if (g[i].size() >= 2) {         ans = 1e9;         dfs(i, -1);         dfs2(i, -1);         if (ans >= 1e8) ans = -1;         cout << ans << endl;         return 0;       }     }   }
#include <bits/stdc++.h>   using namespace std;   bool found = false;   int b, A[10000], orig_a;   int main() {     int a, b[3], i, j, n, x, y, z, array[100000];     cin >> n;     for (i = 0; i < 3; i++) {       if (i <= 1) {         cout <<  ?   << 1 <<     << i + 2 << endl;       } else {         cout <<  ?   << 2 <<     << 3 << endl;       }       fflush(stdout);       cin >> b[i];     }     z = -(b[0] - b[1] - b[2]) / 2;     y = b[2] - z;     x = b[0] - y;     array[0] = x;     array[1] = y;     array[2] = z;     for (i = 4; i <= n; i++) {       cout <<  ?   << 1 <<     << i << endl;       fflush(stdout);       cin >> a;       array[i - 1] = a - x;     }     cout <<  ! ;     for (i = 0; i < n; i++) {       cout <<     << array[i];     }     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int max_n = 1111111, inf = 1000000007;   int n, k, a[max_n], pw[max_n], used[max_n];   int main() {     cin >> n >> k;     if (k == 0) {       long long ans = 1;       for (int i = 1; i < n; ++i) {         ans = (ans * n) % inf;       }       cout << ans << endl;       return 0;     }     if (k == 1) {       long long ans = 1;       for (int i = 0; i < n; ++i) {         ans = (ans * n) % inf;       }       cout << ans << endl;       return 0;     }     pw[0] = 1;     for (int i = 1; i < n; ++i) {       pw[i] = (1LL * pw[i - 1] * k) % n;     }     for (int i = 0; i < n; ++i) {       a[i] = (1LL * i * k) % n;     }     long long ans = 1;     for (int i = 0; i < n; ++i) {       if (used[i] == 0) {         int cnt = 1, v = i, last;         while (used[v] == 0) {           used[v] = cnt;           ++cnt;           last = v;           v = a[v];         }         cnt = used[last] - used[v] + 1;         if (pw[cnt] == 1) {           ans = (ans * n) % inf;         }       }     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     map<char, int> mp;     for (int i = 0; i < s.length(); i++) {       mp[s[i]]++;     }     int mn;     set<int> st;     set<int>::iterator it;     st.insert(mp[ B ]);     st.insert(mp[ u ] / 2);     st.insert(mp[ l ]);     st.insert(mp[ b ]);     st.insert(mp[ a ] / 2);     st.insert(mp[ s ]);     st.insert(mp[ r ]);     it = st.begin();     cout << *it;   }
#include <bits/stdc++.h>   using namespace std;   char buf[11];   const int MAXC = 20;   double C[MAXC][MAXC + 1];   void count(int &sum, int &q) {     char buf[11];     cin >> buf;     sum = 0;     q = 0;     for (char *p = buf; *p; ++p) {       switch (*p) {         case  + :           ++sum;           break;         case  - :           --sum;           break;         case  ? :           ++q;       }     }   }   void init_C() {     C[0][0] = 1.0;     for (int i = 1; i < MAXC; ++i) {       C[i][0] = C[i][i] = 1.0;       for (int j = 1; j < i; ++j) C[i][j] = C[i - 1][j - 1] + C[i - 1][j];     }   }   int main() {     init_C();     int sum1, sum2, quest;     count(sum1, quest);     count(sum2, quest);     int diff = sum1 - sum2;     int t = (quest + diff) / 2;     if (abs(diff) > quest || (quest + diff) % 2) {       cout <<  0.0 n ;     } else {       cout << setprecision(12) << C[quest][t] / (1 << quest) <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct Point {     long double x, y;     Point(){};     long double dist(Point b) {       return sqrt((b.x - x) * (b.x - x) + (b.y - y) * (b.y - y));     }   };   int main() {     Point a, b, c;     cin >> a.x >> a.y >> b.x >> b.y >> c.x >> c.y;     long double k = a.dist(b);     long double l = c.dist(b);     if (k == l && k + l != a.dist(c))       cout <<  YES ;     else       cout <<  NO ;   }
#include <bits/stdc++.h>   int main() {     int days, time, count, free;     int x = 0;     scanf( %d , &days);     scanf( %d , &time);     int busyTime[days];     for (x = 0; x < days; x++) {       scanf( %d , &busyTime[x]);     }     count = 0;     while (time > 0) {       free = 86400 - busyTime[count];       time -= free;       count++;     }     printf( %d , count);   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 2000000000;   const int N = 1e5 + 5;   const int TN = 1 << 18;   const double PI = acos(-1);   int n, m, k;   long long tree[TN], lazy[TN] = {0};   void probagate(int l, int r, int p) {     tree[p] |= lazy[p];     if (l != r) {       lazy[p << 1] |= lazy[p];       lazy[(p << 1) | 1] |= lazy[p];     }     lazy[p] = 0;   }   void update(int val, int ql, int qr, int l = 0, int r = n - 1, int p = 1) {     probagate(l, r, p);     if (ql > r || qr < l) return;     if (ql <= l && r <= qr) {       lazy[p] |= val;       probagate(l, r, p);       return;     }     int m = (l + r) >> 1;     update(val, ql, qr, l, m, (p << 1));     update(val, ql, qr, m + 1, r, (p << 1) | 1);     tree[p] = tree[(p << 1)] & tree[(p << 1) | 1];   }   int get(int ql, int qr, int l = 0, int r = n - 1, int p = 1) {     probagate(l, r, p);     if (ql > r || qr < l) return (1LL << 31) - 1;     if (ql <= l && r <= qr) {       return tree[p];     }     int m = (l + r) >> 1;     return get(ql, qr, l, m, (p << 1)) & get(ql, qr, m + 1, r, (p << 1) | 1);   }   void print(int l = 0, int r = n - 1, int p = 1) {     probagate(l, r, p);     if (l == r) {       printf( %d  , tree[p]);       return;     }     int m = (l + r) >> 1;     print(l, m, (p << 1));     print(m + 1, r, (p << 1) | 1);   }   int main() {     scanf( %d%d , &n, &m);     vector<pair<pair<int, int>, int>> v;     for (int i = 0; i < m; i++) {       int a, b, c;       scanf( %d%d%d , &a, &b, &c);       a--;       b--;       v.push_back({{a, b}, c});       update(c, a, b);     }     for (int i = 0; i < m; i++) {       int a = v[i].first.first;       int b = v[i].first.second;       int c = v[i].second;       if (get(a, b) != c) {         return puts( NO );       }     }     puts( YES );     print();   }
#include <bits/stdc++.h>   using namespace std;   struct point {     int i;     int j;   };   int main() {     vector<char> s;     int n, m;     char c;     char a[102][102];     point first;     first.i = -1;     point last;     memset(a, 0, sizeof(a));     scanf( %d %d %c , &n, &m, &c);     getchar();     for (int i = 0; i < n + 1; i++) {       a[i][0] = c;       a[i][m + 1] = c;     }     for (int i = 0; i < m + 1; i++) {       a[0][i] = c;       a[n + 1][i] = c;     }     for (int i = 1; i < n + 1; i++) {       for (int j = 1; j < m + 1; j++) {         scanf( %c , &c);         a[i][j] = c;         if (c == a[0][0]) {           if (first.i < 0) {             first.i = i;             first.j = j;           }           last.i = i;           last.j = j;         }       }       getchar();     }     int can;     for (int i = first.i; i < last.i + 1; i++) {       for (int j = first.j; j < last.j + 1; j++) {         can = count(s.begin(), s.end(), a[i][j]);         if (a[i - 1][j] !=  .  && count(s.begin(), s.end(), a[i - 1][j]) == 0)           s.push_back(a[i - 1][j]);         if (a[i][j - 1] !=  .  && count(s.begin(), s.end(), a[i][j - 1]) == 0)           s.push_back(a[i][j - 1]);         if (a[i][j + 1] !=  .  && count(s.begin(), s.end(), a[i][j + 1]) == 0)           s.push_back(a[i][j + 1]);         if (a[i + 1][j] !=  .  && count(s.begin(), s.end(), a[i + 1][j]) == 0)           s.push_back(a[i + 1][j]);       }     }     if (s.size())       printf( %d n , s.size() - 1);     else       printf( %d n , s.size());     return 0;   }
#include <bits/stdc++.h>   #pragma optimize( O3 )   using namespace std;   const long long MOD = 1e9 + 7;   const long long INF = 1e9 + 7;   const int base = 2e5 + 1;   const int MAX = 1e5 + 2;   const double EPS = 1e-9;   const double PI = acos(-1.);   const int MAXN = 1e6 + 47;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   int main() {     int n;     cin >> n;     int cnt = 0;     vector<int> res;     set<int> was, is;     for (long long i = (0); i < (n); ++i) {       int a;       cin >> a;       if (a < 0) {         if (is.count(abs(a))) {           is.erase(abs(a));           cnt--;         } else {           cout << -1;           return 0;         }       } else {         if (was.count(a) || is.count(a)) {           cout << -1;           return 0;         } else {           was.insert(a);           is.insert(a);           cnt++;         }       }       if (cnt == 0) {         res.push_back(i + 1);         was.clear();       }     }     if (cnt != 0) {       cout << -1;       return 0;     }     cout << (int)res.size() <<   n ;     int last = 0;     for (long long i = (0); i < ((int)res.size()); ++i) {       cout << res[i] - last <<    ;       last = res[i];     }     cerr <<   nTime elapsed:   << clock() / (double)CLOCKS_PER_SEC <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     int s = 0;     int a[5000];     cin >> n;     int i;     for (i = 1; i <= n; i++) {       cin >> a[i];     }     for (i = 1; i <= n; i++) {       if (a[i] == a[a[a[a[i]]]]) s = s + 1;     }     if (s != 0) {       cout <<  YES ;     } else       cout <<  NO ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     int n, k;     cin >> n >> k;     vector<pair<int, int>> a(n * 2);     vector<pair<int, int>> ans;     for (int i = 0; i < n; i++) {       cin >> a[i].first >> a[n + i].first;       a[n + i].second = 1;     }     sort(a.begin(), a.end());     int z = 0;     for (int i = 0; i < n * 2; i++)       if (a[i].second == 0) {         z++;         if (z == k) ans.push_back({a[i].first, 0});       } else {         if (z == k) ans.back().second = a[i].first;         z--;       }     cout << ans.size() <<   n ;     for (int i = 0; i < ans.size(); i++)       cout << ans[i].first <<     << ans[i].second <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   map<string, int> mp;   int main() {     int n, m;     string s;     cin >> n >> m;     for (int i = 0; i < n; i++) {       cin >> s;       mp[s] = 1;     }     int con = 0;     for (int i = 0; i < m; i++) {       cin >> s;       if (mp[s] == 1) {         con++;       }     }     m -= con;     n -= con;     if (con & 1) {       n++;     }     if (n > m) {       cout <<  YES ;     } else       cout <<  NO ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long t, a, b, c;     cin >> t;     while (t--) {       cin >> a >> b >> c;       if (a == c) {         cout <<  -1   << b <<   n ;       } else if (a > c) {         cout <<  -1 1 n ;       } else {         double x = (double)c / b;         double y = (double)a;         if (x < y)           cout <<  1   << b <<   n ;         else           cout <<  1 -1 n ;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<vector<int>> adj, CC;   const int MX = 1e5 + 69;   int n, m, q, vis[MX], dis[MX], pa[MX], compsz[MX], D[MX];   int parent(int x) {     if (x == pa[x]) return x;     return pa[x] = parent(pa[x]);   }   bool cmp(int a, int b) {     if (dis[a] != dis[b]) return dis[a] < dis[b];     return a < b;   }   long long* cum[MX];   int* compel[MX];   int bfs(int x, bool ok) {     int p = parent(x);     queue<int> q;     q.push(x);     vis[x] = 0;     vector<int> v;     while (!q.empty()) {       int nxt = q.front();       v.push_back(nxt);       q.pop();       for (auto u : adj[nxt]) {         if (vis[u] == -1) {           vis[u] = vis[nxt] + 1;           dis[u] = max(dis[u], vis[u]);           q.push(u);           D[p] = max(D[p], dis[u]);         }       }     }     int mx = -69, opt = x;     while (!v.empty() && ok == 1) {       int nxt = v.back();       v.pop_back();       if (mx < vis[nxt]) {         mx = vis[nxt];         opt = nxt;       }       vis[nxt] = -1;     }     if (ok) return opt;     sort(v.begin(), v.end(), cmp);     int sz = v.size(), j = 0;     long long sum = 0;     p = parent(x);     compel[p] = new int[D[p] + 2];     cum[p] = new long long[D[p] + 2];     for (int i = 0; i <= D[p] + 1; i++) cum[p][i] = compel[p][i] = 0;     for (auto u : v) {       j++;       sum += dis[u];       cum[p][dis[u] + 1] = sum;       compel[p][dis[u] + 1] = j;     }     compsz[p] = v.size();     CC[p] = v;     v.clear();     return opt;   }   long double nig[MX];   void join(int u, int v) {     u = parent(u);     v = parent(v);     if (u == v) return;     pa[u] = v;   }   map<int, long double> quer[MX];   int DD;   long double solve(int u, int v) {     if (compsz[u] > compsz[v]) swap(u, v);     if (quer[u].count(v)) return quer[u][v];     DD = max(D[u], D[v]);     long double ret = 0;     for (int i = 0; i < compsz[u]; i++) {       int nxt = CC[u][i];       int l = min(D[v], max(-1, DD - dis[nxt] - 2));       long double r = compsz[v] - compel[v][l + 1];       ret += r * (dis[nxt] + 1) + cum[v][D[v] + 1] - cum[v][l + 1] +              (long double)compel[v][l + 1] * DD;     }     return quer[u][v] = ret / ((long double)compsz[u] * compsz[v]);   }   int main() {     cin >> n >> m >> q;     for (int i = 1; i <= n; i++) pa[i] = i;     memset(vis, -1, sizeof vis);     adj.resize(n + 69);     CC.resize(n + 69);     for (int i = 1; i <= m; i++) {       int u, v;       scanf( %d%d , &u, &v);       adj[u].push_back(v);       adj[v].push_back(u);       join(u, v);     }     for (int i = 1; i <= n; i++) {       if (i != parent(i)) continue;       int p = parent(i);       int u = bfs(i, 1);       u = bfs(u, 1);       bfs(u, 0);     }     cout << fixed;     cout.precision(10);     for (int i = 1; i <= q; i++) {       int u, v;       scanf( %d%d , &u, &v);       u = parent(u);       v = parent(v);       if (u == v)         cout << -1 << endl;       else         cout << solve(u, v) << endl;     }     return 0;   }