malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, i;     cin >> a >> b;     int arr[a + 1];     for (i = 1; i <= a; i++) cin >> arr[i];     for (i = 1; i <= a; i++) {       b -= (86400 - arr[i]);       if (b <= 0) break;     }     cout << i << endl;   }
#include <bits/stdc++.h>   using namespace std;   inline long long gcd(long long a, long long b) {     if (b == 0)       return a;     else       return gcd(b, a % b);   }   inline long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }   signed main() {     std::ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     string s;     int n, a, b;     cin >> n >> a >> b >> s;     for (int i = 0; i <= n / a; i++) {       if ((n - i * a) % b == 0) {         cout << i + (n - i * a) / b << endl;         for (int j = 0; j < i * a; j++) {           cout << s[j];           if ((j + 1) % a == 0) cout << endl;         }         for (int j = i * a, k = 0; j < n; j++, k++) {           cout << s[j];           if ((k + 1) % b == 0) cout << endl;         }         return 0;       }     }     cout <<  -1 n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> primes;   int dp[101][1 << 18], n, a[111], man, ansd[111], loc[100];   vector<int> fact[100];   int rec(int i, int mask) {     if (i == n) return 0;     if (dp[i][mask] != 1000000000) return dp[i][mask];     int dif = abs(a[i] - 1);     int ans = rec(i + 1, mask) + dif;     for (int j = 2; j <= 60; j++) {       int k;       for (k = 0; k < fact[j].size(); k++)         if (mask & (1 << fact[j][k])) break;       if (k != (int)fact[j].size()) continue;       int d = abs(a[i] - j);       if (d <= dif) {         int msk = mask;         for (k = 0; k < fact[j].size(); k++) msk = msk | (1 << fact[j][k]);         ans = min(ans, rec(i + 1, msk) + d);       }     }     return dp[i][mask] = ans;   }   void reccons(int i, int mask, int m) {     if (i == n) return;     int dif = abs(a[i] - 1);     if (rec(i + 1, mask) == m - dif) {       ansd[i] = 1;       reccons(i + 1, mask, m - dif);       return;     }     for (int j = 2; j <= 60; j++) {       int k;       for (k = 0; k < fact[j].size(); k++)         if (mask & (1 << fact[j][k])) break;       if (k != (int)fact[j].size()) continue;       int d = abs(a[i] - j);       if (d > dif) continue;       int msk = mask;       for (k = 0; k < fact[j].size(); k++) msk = msk | (1 << fact[j][k]);       if (rec(i + 1, msk) == m - d) {         ansd[i] = j;         reccons(i + 1, msk, m - d);         return;       }     }   }   int main() {     int i, j, t;     for (i = 2; i <= 60; i++) {       for (j = 2; j < i; j++)         if (i % j == 0) break;       if (j == i) primes.push_back(i);     }     for (i = 0; i < 17; i++) loc[primes[i]] = i;     for (i = 2; i <= 60; i++) {       for (j = 0; j < 17; j++)         if (i % primes[j] == 0) fact[i].push_back(j);     }     scanf( %d , &n);     for (i = 0; i < n; i++) scanf( %d , &a[i]);     for (i = 0; i <= n; i++)       for (j = 0; j < (1 << 17); j++) dp[i][j] = 1000000000;     man = rec(0, 0);     reccons(0, 0, man);     for (i = 0; i < n; i++) printf( %d  , ansd[i]);     printf(  n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 100 + 10;   string a[maxn], ans[maxn];   int main() {     int n;     while (cin >> n) {       int cnt[2][26];       memset(cnt, 0, sizeof cnt);       for (int i = 0; i < n; ++i) cin >> a[i], ++cnt[0][a[i][0] -  A ];       multiset<string> Q;       for (int i = 0; i < n; ++i) {         string x;         cin >> x;         ++cnt[1][x[0] -  A ];         Q.insert(x);       }       sort(a, a + n);       int cur = 0;       for (int i = 0; i < n; ++i) {         string& t = a[i];         int id = t[0] -  A ;         for (multiset<string>::iterator it = Q.begin(); it != Q.end(); ++it) {           const string& now = *it;           int idx = now[0] -  A ;           if (now[0] == t[0]) {             ans[cur++] = t +     + now;             --cnt[0][id];             --cnt[1][idx];             Q.erase(it);             break;           } else if (cnt[0][idx] < cnt[1][idx] && cnt[0][id] > cnt[1][id]) {             ans[cur++] = t +     + now;             --cnt[0][id];             --cnt[1][idx];             Q.erase(it);             break;           }         }       }       sort(ans, ans + cur);       cout << ans[0];       for (int i = 1; i < cur; ++i) {         cout <<  ,   << ans[i];       }       cout << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool check(int left, int right, int m) {     left ^= right;     if (left > m)       return false;     else       return true;   }   void solve() {     int n, m;     cin >> n >> m;     if (n > m) {       cout << 0 <<   n ;       return;     }     int ans = 0;     for (int i = 0; i < 31; ++i) {       if ((1 << i) & n)         continue;       else {         ans ^= (1 << i);         if ((ans ^ n) > m) break;       }     }     for (int i = 30; i >= 0; --i) {       if ((1 << i) & ans) {         int num = ans ^ (1 << i);         if ((num ^ n) > m) {           ans ^= (1 << i);         }       }     }     cout << ans <<   n ;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int test;     cin >> test;     while (test--) {       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   const int MAX_N = 100 * 1000 + 10;   const int inf = (int)1e9;   const double eps = 1e-6;   int main() {     int r, g, b;     cin >> r >> g >> b;     int rr = (((r + 1) / 2) - 1) * 3 + 30;     int gg = (((g + 1) / 2) - 1) * 3 + 31;     int bb = (((b + 1) / 2) - 1) * 3 + 32;     cout << max(rr, max(bb, gg)) << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   class TwoSAT {    private:     const static int maxm = 100010 * 2;     int S[maxm], c;     vector<int> G[maxm];     bool DFS(int u) {       if (vis[u ^ 1]) return false;       if (vis[u]) return true;       vis[u] = 1;       S[c++] = u;       for (auto &v : G[u])         if (!DFS(v)) return false;       return true;     }       public:     int N;     bool vis[maxm];     void Clear() {       for (int i = 2; i < (N + 1) * 2; ++i) G[i].clear();       memset(vis, 0, sizeof(bool) * (N + 1) * 2);     }     void AddClause(int x, int xv, int y, int yv) {       x = x * 2 + xv;       y = y * 2 + yv;       G[x].push_back(y);       G[y].push_back(x);     }     bool Solve() {       for (int i = 2; i < (N + 1) * 2; i += 2)         if (!vis[i] && !vis[i + 1]) {           c = 0;           if (!DFS(i)) {             while (c > 0) vis[S[--c]] = 0;             if (!DFS(i + 1)) return false;           }         }       return true;     }   };   int n, m;   bool r[100010];   int f[100010];   TwoSAT ts;   int main() {     ios::sync_with_stdio(false);     int i, j, x, y;     cin >> n >> m;     ts.N = m + 1;     for (i = 1; i <= n; ++i) cin >> r[i];     for (i = 1; i <= m; ++i) {       cin >> x;       for (j = 0; j < x; ++j) {         cin >> y;         if (f[y]) {           if (r[y]) {             ts.AddClause(f[y], 1, i, 1);             ts.AddClause(f[y], 0, i, 0);           } else {             ts.AddClause(f[y], 1, i, 0);             ts.AddClause(f[y], 0, i, 1);           }         } else           f[y] = i;       }     }     if (ts.Solve())       puts( YES );     else       puts( NO );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   double d, h, v, e;   int main() {     ios_base::sync_with_stdio(false);     cin >> d >> h >> v >> e;     v = v / (acos(-1) * d * d / 4);     double t = h / (v - e);     if (t < 0 || fabs(v - e) < 1e-8) {       printf( NO n );       return 0;     }     printf( YES n%.12lf n , t);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using namespace std;   inline int read() {     char ch;     bool sign = 0;     int res = 0;     while (!isdigit(ch = getchar()))       if (ch ==  - ) sign = 1;     while (isdigit(ch)) res = res * 10 + (ch ^ 48), ch = getchar();     if (sign)       return -res;     else       return res;   }   mt19937 Rnd(chrono::system_clock::now().time_since_epoch().count());   const int maxn = 200000 + 10;   const int inf = 1e9;   const int MAXM = 3;   const long long MOD[] = {469762049, 998244353, 1004535809, 1000000007};   const int mod = 1811939329;   const int apsz = 26;   int a[maxn], n, cnt[maxn], Sqrt;   int mx;   inline int brute(int x) {     vector<int> pos(2 * n + 2, -1);     int now = maxn;     int ans = 0;     pos[n] = 0;     for (auto i = (1); i <= (n); ++i) {       if (now == maxn && a[i] != x && a[i] != mx) continue;       if (now == maxn) now = 0;       if (a[i] == x) {         now++;       } else if (a[i] == mx)         now--;       if (pos[now + n] >= 0) ans = max(ans, i - pos[now + n]);       if (pos[now + n] == -1) pos[now + n] = i;     }     return ans;   }   inline int gao(int c) {     memset(cnt, 0, sizeof(cnt));     int has = 0;     int l, r, ans;     for (ans = 0, r = l = 1; r <= n; ++r) {       ++cnt[a[r]];       if (cnt[a[r]] == c)         has++;       else if (cnt[a[r]] == c + 1)         has--;       while (cnt[a[r]] > c) {         --cnt[a[l]];         if (cnt[a[l]] == c) has++;         if (cnt[a[l]] == c - 1) has--;         l++;       }       assert(has >= 0 && r >= l);       if (has > 1) ans = max(ans, r - l + 1);     }     return ans;   }   inline int solve() {     int mxcnt = 0;     for (auto i = (1); i <= (n); ++i) {       if (++cnt[a[i]] > mxcnt) mxcnt = cnt[a[i]], mx = a[i];     }     for (auto i = (1); i <= (n); ++i) {       if (mx != a[i] && cnt[a[i]] == mxcnt) return n;     }     int ans(0);     Sqrt = sqrt(n + 3);     for (auto i = (1); i <= (n); ++i) {       if (cnt[a[i]] >= Sqrt && a[i] != mx) {         ans = max(brute(a[i]), ans);         cnt[a[i]] = 0;       }     }     for (auto c = (1); c <= (Sqrt); ++c) {       ans = max(ans, gao(c));     }     return ans;   }   int main(void) {     scanf( %d , &(n));     for (auto i = (1); i <= (n); ++i) scanf( %d , &(a[i]));     printf( %d n , solve());     return 0;   }
#include <bits/stdc++.h>   using namespace std;   unordered_map<int, int> mapa;   vector<int> tab;   int main() {     ios_base::sync_with_stdio(false);     int n, k, a;     cin >> n >> k;     int aktIlosc = n;     for (int i = 0; i < n; i++) {       cin >> a;       if (mapa[a] == 0) tab.push_back(a);       mapa[a]++;     }     sort(tab.begin(), tab.end());     for (int i = 0; i + 1 < tab.size(); i++) {       if (tab[i] < tab[i + 1] && tab[i] + k >= tab[i + 1])         aktIlosc -= mapa[tab[i]];     }     cout << aktIlosc;   }
#include <bits/stdc++.h>   using namespace std;   char dif(char c1) {     if (c1 ==  a ) return  b ;     return  a ;   }   char dif2(char c1, char c2) {     if (c1 !=  a  && c2 !=  a ) return  a ;     if (c1 !=  b  && c2 !=  b ) return  b ;     return  c ;   }   int main() {     int n, t;     cin >> n >> t;     string s1, s2;     cin >> s1 >> s2;     vector<int> com;     vector<int> nocom;     for (long long i = 0; i < (n); i++)       if (s1[i] == s2[i])         com.push_back(i);       else         nocom.push_back(i);     int comsz = com.size();     int nocomsz = nocom.size();     if (!(2 * t >= nocomsz)) {       cout << -1 << endl;       return 0;     }     string s3 = s1;     if (nocomsz & 1) {       int ind = nocom[nocomsz - 1];       s3[ind] = dif2(s1[ind], s2[ind]);       t--;     }     for (int i = 0; (i + 1 < nocomsz) && t > 0; i += 2) {       int ind1 = nocom[i];       s3[ind1] = s2[ind1];       int ind2 = nocom[i + 1];       s3[ind2] = s1[ind2];       t--;     }     for (int i = 0; i < comsz && t > 0; i++) {       int ind = com[i];       s3[ind] = dif(s1[ind]);       t--;     }     for (int i = 0; (i + 1 < nocomsz) && t > 0; i += 2) {       int ind1 = nocom[i];       int ind2 = nocom[i + 1];       s3[ind1] = dif2(s1[ind1], s2[ind1]);       s3[ind2] = dif2(s1[ind2], s2[ind2]);       t--;     }     cout << s3 << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e4 + 10;   const long long mod = 998244353;   int n, m, k, x;   bool a[55][maxn];   int main() {     scanf( %d%d , &m, &n);     for (int i = 1; i <= (m); i++) {       scanf( %d , &k);       for (int j = 1; j <= (k); j++) {         scanf( %d , &x);         a[i][x] = 1;       }     }     for (int i = 1; i <= (m); i++)       for (int j = 1; j <= (m); j++) {         bool flag = 0;         for (int l = 1; l <= n && !flag; l++)           if (a[i][l] && a[j][l]) flag = 1;         if (!flag) {           printf( impossible n );           return 0;         }       }     printf( possible n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int sum(long int c) {     int somme = 0;     while (c) {       somme = somme + c % 10;       c = c / 10;     }     return (somme);   }   int main() {     long int k, c = 19;     cin >> k;     while (k) {       if (sum(c) == 10) k--;       c += 9;     }     cout << c - 9;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const int M = 100005;   const int MOD = 1e9 + 7;   long long c[100005], x, k, tot = 0;   vector<long long> son[100005];   void dfs(int n, int m) {     if (tot >= 100000) return;     if (n == 0 || m == 0) {       printf( %I64d  , c[n]);       ++tot;       return;     }     for (int v : son[n]) dfs(v, m - 1);   }   int main() {     cin >> x >> k;     if (k == 0) {       printf( %I64d n , x);       return 0;     }     int top = 0;     for (int i = 1; i * 1ll * i < x; ++i) {       if (x % i == 0) {         c[top++] = i;         c[top++] = x / i;       }     }     if (sqrt(x) * sqrt(x) == x) c[top++] = sqrt(x);     sort(c, c + top);     for (int i = 0; i < top; ++i)       for (int j = 0; j <= i; ++j)         if (c[i] % c[j] == 0) son[i].push_back(j);     dfs(top - 1, k);     return 0;   }
#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:16777216 )   using namespace std;   const double PI = acos(-1.0);   long long gcd(long long a, long long b) {     if (b == 0) return a;     return gcd(b, a % b);   }   pair<long long, int> all[2000111];   long long cntA, cntB;   int cnt;   int main() {     long long a, b;     cin >> a >> b;     long long x = a * b / gcd(a, b);     for (int i = (1), _b = (x / a - 1); i <= _b; i++)       all[cnt++] = make_pair(a * i, 0);     for (int i = (1), _b = (x / b - 1); i <= _b; i++)       all[cnt++] = make_pair(b * i, 1);     sort(all, all + cnt);     long long last = 0;     for (int i = 0, _a = (cnt); i < _a; i++) {       if (all[i].second == 0)         cntA += all[i].first - last;       else         cntB += all[i].first - last;       last = all[i].first;     }     if (a > b)       cntA += x - last;     else       cntB += x - last;     if (cntA > cntB)       puts( Dasha );     else if (cntA < cntB)       puts( Masha );     else       puts( Equal );     return 0;   }
#include <bits/stdc++.h>   long long R = 7 + 1e9, NUMTESTCASE;   const int NN = 10 + 1e5;   const double pi = acos(-1.0);   int di[4] = {1, 0, -1, 0}, dj[4] = {0, 1, 0, -1},       DI[8] = {1, 1, 0, -1, -1, -1, 0, 1}, DJ[8] = {0, 1, 1, 1, 0, -1, -1, -1};   using namespace std;   int main() {     int x, t, n, mx, k;     cin >> n >> mx >> k;     vector<int> a[n];     t = 0;     for (int i = (0); i <= (n - 1); ++i) {       scanf( %d , &x);       if (x <= mx)         a[t].push_back(1);       else         t++;     }     int ans = 0;     for (int i = (0); i <= (n - 1); ++i) ans += max(0, (int)a[i].size() - k + 1);     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int stop, n, k, x, i, ind, j, y[1000001], mini[2001][2001];   string s[2001];   struct name {     int a[26];     int cnt;   } trie[1000001];   vector<int> d[1000001];   int m;   void add(int v, int pos) {     if (pos > s[i].length()) return;     if (trie[v].a[s[i][pos] -  a ])       add(trie[v].a[s[i][pos] -  a ], pos + 1);     else {       m++;       trie[v].a[s[i][pos] -  a ] = m;       add(m, pos + 1);     };     trie[v].cnt++;   }   void dp(int v) {     for (int j = 0; j < 26; j++)       if (trie[v].a[j]) dp(trie[v].a[j]);     d[v].resize(trie[v].cnt + 1);     for (int j = 0; j < 26; j++) {       int p = trie[v].a[j];       if (p == 0) continue;       int s = d[p].size() - 1;       for (int k1 = d[v].size() - s - 1; k1 >= 0; k1--)         for (int i = 1; i <= s; i++) {           d[v][k1 + i] = max(d[v][k1 + i], d[v][k1] + d[p][i] + i * (i - 1) / 2);         }     }   }   int main() {     cin >> n >> k;     for (i = 1; i <= n; i++) {       cin >> s[i];       add(0, 0);     };     dp(0);     cout << d[0][k];     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     vector<int> vet, mat;     int n, x;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> x;       if (x != 0) vet.push_back(x);     }     for (int i = 0; i < n; i++) {       cin >> x;       if (x != 0) mat.push_back(x);     }     int aux = 0;     if (n <= 3) {       cout <<  YES ;     } else {       int r;       for (int i = 0; i < n - 1; i++) {         if (mat[i] == vet[0]) {           r = i;           break;         }       }       for (int i = 0; i < n - 1; i++) {         int l = r + i;         if (l >= n - 1) l -= (n - 1);         if (vet[i] != mat[l]) {           aux = 1;           break;         }       }       if (aux) {         cout <<  NO ;       } else         cout <<  YES ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool comp(int a, int b) { return a < b; }   int main() {     stack<int> s;     int N, t;     cin >> N;     while (N--) {       cin >> t;       if (s.empty()) {         s.push(t);       } else {         if (((s.top()) & 1) == (t & 1))           s.pop();         else           s.push(t);       }     }     if (s.size() < 2)       cout <<  YES  << endl;     else       cout <<  NO  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using vi = vector<int>;   using vvi = vector<vi>;   using vll = vector<ll>;   using vvll = vector<vll>;   using vb = vector<bool>;   using vd = vector<double>;   using vs = vector<string>;   using vpii = vector<pair<int, int>>;   using vpll = vector<pair<ll, ll>>;   using pii = pair<int, int>;   using pll = pair<ll, ll>;   int dx[8] = {0, 1, 1, 1, 0, -1, -1, -1};   int dy[8] = {1, 1, 0, -1, -1, -1, 0, 1};   void solve() {     vi a(6);     for (ll i = 0; i < 6; i++) cin >> a[i];     ;     ll ans = ((a[0] + a[1] + a[2]) * (a[0] + a[1] + a[2]) - a[0] * a[0] -               a[2] * a[2] - a[4] * a[4]);     cout << ans <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ll t = 1;     while (t--) {       solve();     }   }
#include <bits/stdc++.h>   int n, h;   char name[10];   long double p[70], cont[70];   int main() {     scanf( %s%d%d , name, &n, &h);     if (name[0] ==  B ) {       printf( %d n , n);       return 0;     }     long double ans = n;     p[0] = cont[0] = 1.0;     for (int i = 1; i <= h; i++) {       p[i] = p[i - 1] / 2.0;       cont[i] = cont[i - 1] * 2.0;     }     for (int i = 1; i <= h; i++)       for (int j = 2; j <= n; j++)         ans += p[i] * p[i] * pow(1.0 - p[i], j - 2) *                (cont[i] - cont[i - 1] * ((j - 2) / (cont[i] - 1.0) + 1.0)) *                (n - j + 1);     printf( %.10f n , (double)ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n, m, c1, c2, v, q;   long long xs, xe, ye, ys;   long long pos1[100005];   long long pos2[100005];   long long solve(int pos, int v) {     long long ans = abs(pos - xe) + abs(pos - xs);     long long y = abs(ye - ys);     ans += (y - 1) / v + 1;     return ans;   }   int main() {     cin >> n >> m >> c1 >> c2 >> v;     for (int i = 0; i < c1; i++) cin >> pos1[i];     for (int i = 0; i < c2; i++) cin >> pos2[i];     cin >> q;     while (q--) {       int id;       cin >> ys >> xs >> ye >> xe;       long long ans = 999999999999;       if (ys == ye)         ans = abs(xe - xs);       else {         if (c1) {           id = upper_bound(pos1, pos1 + c1, xs) - pos1;           if (id != c1) ans = min(ans, solve(pos1[id], 1));           if (id - 1 >= 0) ans = min(ans, solve(pos1[id - 1], 1));           id = upper_bound(pos1, pos1 + c1, xe) - pos1;           if (id != c1) ans = min(ans, solve(pos1[id], 1));           if (id - 1 >= 0) ans = min(ans, solve(pos1[id - 1], 1));         }         if (c2) {           id = upper_bound(pos2, pos2 + c2, xs) - pos2;           if (id != c2) ans = min(ans, solve(pos2[id], v));           if (id - 1 >= 0) ans = min(ans, solve(pos2[id - 1], v));           id = upper_bound(pos2, pos2 + c2, xe) - pos2;           if (id != c2) ans = min(ans, solve(pos2[id], v));           if (id - 1 >= 0) ans = min(ans, solve(pos2[id - 1], v));         }       }       cout << ans << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 1;   int n, m, q, p[N], dis[N], far, cur, sz[N];   vector<int> g[N];   unordered_map<int, double> dp[N];   vector<pair<int, long long>> v[N];   int get(int u) { return p[u] == u ? u : p[u] = get(p[u]); }   void dfs(int u, int p, int depth) {     dis[u] = max(dis[u], depth);     if (dis[u] > cur) {       cur = dis[u];       far = u;     }     for (auto i : g[u])       if (i != p) dfs(i, u, depth + 1);   }   double calc(int a, int b) {     if (dp[a].find(b) != dp[a].end()) return dp[a][b];     double ans = 0;     int mx = max(v[a].back().first, v[b].back().first);     for (int i = v[a].size() - 1, j = 0; i + 1; i--) {       while (j < v[b].size() && v[a][i].first + v[b][j].first + 1 <= mx) j++;       ans += mx * 1LL * j;       if (j < v[b].size()) {         ans += v[b].back().second + v[b].size() - j +                v[a][i].first * 1LL * (v[b].size() - j);         if (j) ans -= v[b][j - 1].second;       }     }     ans /= v[a].size() * 1LL * v[b].size();     return dp[a][b] = dp[b][a] = ans;   }   int main() {     scanf( %d%d%d , &n, &m, &q);     int z = sqrt(n);     for (int i = 0; i < n; i++) p[i] = i, sz[i] = 1;     for (int i = 0, a, b; i < m; i++) {       scanf( %d%d , &a, &b);       --a;       --b;       sz[get(b)] += sz[get(a)];       p[get(a)] = get(b);       g[a].push_back(b);       g[b].push_back(a);     }     for (int i = 0; i < n; i++)       if (p[i] == i) {         cur = -1e9;         dfs(i, -1, 0);         cur = -1e9;         dfs(far, -1, 0);         cur = -1e9;         dfs(far, -1, 0);       }     for (int i = 0; i < n; i++) v[get(i)].push_back({dis[i], dis[i]});     for (int i = 0; i < n; i++) sort(v[i].begin(), v[i].end());     for (int i = 0; i < n; i++)       if (i == p[i])         for (int j = 1; j < v[i].size(); j++)           v[i][j].second += v[i][j - 1].second;     for (int i = 0, a, b; i < q; i++) {       scanf( %d%d , &a, &b);       --a;       --b;       a = get(a);       b = get(b);       if (a == b) {         puts( -1 );         continue;       }       if (sz[a] > sz[b]) swap(a, b);       printf( %.10lf n , calc(a, b));     }   }