malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   struct debugger {     template <typename T>     debugger& operator,(const T& v) {       cerr << v <<    ;       return *this;     }   } dbg;   int inf = (1 << 20);   int dp[(1 << 21) + 10];   void F(int x, int y) {     x += inf;     y += inf;     dp[x]++;     if (x == y) return;     dp[y]++;     while (x / 2 != y / 2) {       if (x % 2 == 0) dp[x + 1]++;       if (y % 2 == 1) dp[y - 1]++;       x /= 2;       y /= 2;     }     return;   }   int ar[400010];   int n, k;   int func(int x) {     int sm = 0;     x += inf;     while (x > 1) {       sm += dp[x];       x /= 2;     }     return sm;   }   int chk(int x) {     int sm = 0;     for (int i = x; i <= ar[n - 1]; i += x) sm += func(i);     if (sm == n) return 1;     return 0;   }   int main() {     cin >> n >> k;     for (int i = (0), _n = (n); i < _n; i++) cin >> ar[i];     sort(ar, ar + n);     if (ar[0] <= k) {       cout << ar[0] << endl;       return 0;     }     for (int i = (0), _n = (n); i < _n; i++) F(ar[i] - k, ar[i]);     int rs = k;     for (int i = (2), _n = (ar[0]); i <= _n; i++)       if (chk(i)) rs = i;     cout << rs << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t, n, i, j, k, tmp;     int a, b, c;     cin >> a >> b >> c;     int p;     if ((c - b + a) % 2 != 0) {       printf( Impossible n );       return 0;     }     p = (c - b + a) / 2;     int count1 = 0;     if (p == 0) {       count1++;     }     if (a - p == 0) {       count1++;     }     if (b - (a - p) == 0) {       count1++;     }     if (p >= 0 && a - p >= 0 && b - (a - p) >= 0 && count1 <= 1) {       cout << a - p <<     << b - (a - p) <<     << p << endl;     } else {       printf( Impossible n );     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n, k;     cin >> n >> k;     map<int, int> m;     int c[7000][2];     int a[n + 1];     int b[n + 1];     int mx;     for (int i = 0; i < n; i++) {       cin >> a[i];       m[a[i]]++;       mx = max(mx, m[a[i]]);     }     if (mx > k) {       cout <<  NO  << endl;       return 0;     }     int x = 0;     for (auto i : m) {       c[i.first][0] = x;       x = x + i.second;     }     cout <<  YES  << endl;     for (int i = 0; i < n; i++) {       cout << (c[a[i]][0] % k) + 1 <<    ;       c[a[i]][0]++;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     double n, m, a, b, x = 1000000, y;     cin >> n >> m;     while (n--) {       cin >> a >> b;       y = a / b;       x = min(x, y);     }     printf( %.8lf n , m * x);   }
#include <bits/stdc++.h>   using namespace std;   long long bigmod(long long p, long long e, long long M) {     long long ret = 1;     for (; e > 0; e >>= 1) {       if (e & 1) ret = (ret * p) % M;       p = (p * p) % M;     }     return ret;   }   long long extended(long long a, long long b, long long &x, long long &y) {     a = abs(a);     b = abs(b);     long long g, x1, y1;     if (!b) {       x = 1;       y = 0;       g = a;       return g;     }     g = extended(b, a % b, x1, y1);     x = y1;     y = x1 - (a / b) * y1;     return g;   }   long long modinverse(long long a, long long M) { return bigmod(a, M - 2, M); }   long long bpow(long long p, long long e) {     long long ret = 1;     for (; e > 0; e >>= 1) {       if (e & 1) ret = (ret * p);       p = (p * p);     }     return ret;   }   int toInt(string s) {     int sm;     stringstream ss(s);     ss >> sm;     return sm;   }   int toLlint(string s) {     long long int sm;     stringstream ss(s);     ss >> sm;     return sm;   }   string convertInt(long long number) {     if (number == 0) return  0 ;     string temp =   ;     string returnvalue =   ;     while (number > 0) {       temp += number % 10 + 48;       number /= 10;     }     for (int i = 0; i < temp.length(); i++)       returnvalue += temp[temp.length() - i - 1];     return returnvalue;   }   long long ncr[1001][1001];   void NCR() {     for (int i = 1; i <= 1000; i++) {       ncr[i][i] = 1;       ncr[i][0] = 1;       for (int r = 1; r < i; r++) {         ncr[i][r] = (ncr[i - 1][r] + ncr[i - 1][r - 1]) % 1000000007;       }     }   }   vector<int> vec[100009];   long long n;   long long dp[100005][2], ar[100009];   void dfs(int V, int pv) {     dp[V][0] = 1 - ar[V];     dp[V][1] = ar[V];     for (int i = 0; i < vec[V].size(); i++) {       long long old[2];       memset(old, 0, sizeof(old));       int v = vec[V][i];       if (v == pv) continue;       old[0] = dp[V][0];       old[1] = dp[V][1];       dp[V][0] = dp[V][1] = 0;       dfs(v, V);       dp[V][0] += (old[0] * dp[v][1]) % 1000000007;       dp[V][1] += (old[1] * dp[v][1]) % 1000000007;       dp[V][1] += (old[1] * dp[v][0]) % 1000000007;       dp[V][1] += (old[0] * dp[v][1]) % 1000000007;       dp[V][0] += (old[0] * dp[v][0]) % 1000000007;     }   }   int main() {     cin >> n;     for (int i = 1; i < n; i++) {       int v;       cin >> v;       vec[i].push_back(v);       vec[v].push_back(i);     }     for (int i = 0; i < n; i++) {       int val;       cin >> val;       ar[i] = val;     }     dfs(0, -1);     cout << dp[0][1] % 1000000007 << endl;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> prim;   const int N = 1e5 + 9;   int n, dp[10000], a[N];   bool v[100000];   int pos[100000];   void pre() {     for (int i = 2; i < 100000; i++)       if (!v[i]) {         prim.push_back(i);         pos[i] = prim.size() - 1;         int k = i << 1;         while (k < 100000) v[k] = 1, k += i;       }   }   int main() {     pre();     int ans = 1;     cin >> n;     for (int i = 1, now; i <= n; i++) {       cin >> now;       int org = now;       int tmp = 0;       for (int j = 0; j < 100; j++)         if (now % prim[j] == 0) {           while (now % prim[j] == 0) now /= prim[j];           tmp = max(tmp, dp[j] + 1);         }       if (now > 1) tmp = max(tmp, dp[pos[now]] + 1);       for (int j = 0; j < 100; j++)         if (org % prim[j] == 0) {           while (org % prim[j] == 0) org /= prim[j];           dp[j] = tmp;         }       if (org > 1) dp[pos[now]] = tmp;       ans = max(ans, tmp);     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int power(long long int a, long long int b) {     long long int res = 1;     a %= 1000000007;     assert(b >= 0);     for (; b; b >>= 1) {       if (b & 1) res = res * a % 1000000007;       a = a * a % 1000000007;     }     return res;   }   long long int modInverse(long long int a) { return power(a, 1000000007 - 2); }   const int N = 500023;   bool vis[N];   vector<int> adj[N];   void solve() {     long long int n, m;     cin >> n >> m;     string s;     cin >> s;     s =  &  + s;     map<long long int, long long int> repeat;     for (long long int i = 0; i < m; i++) {       long long int c;       cin >> c;       repeat[c]++;     }     long long int cnt[28] = {0};     long long int final[28] = {0};     for (int i = 1; i <= n; i++) {       cnt[s[i] -  a ]++;       final[s[i] -  a ]++;       for (int j = 0; j < 26; j++) {         final[j] += (cnt[j] * repeat[i]);       }     }     for (int i = 0; i < 26; i++) {       cout << final[i] <<    ;     }     cout <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int T = 1;     cin >> T;     int t = 0;     while (t++ < T) {       solve();     }     cerr <<  Time :   << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC          <<  ms n ;   }
#include <bits/stdc++.h>   using namespace std;   const long double EPS = 1e-9;   long double Dis(long long a, long long Y, long long b, long long YY) {     return sqrt((long double)(b - a) * (b - a) + (Y - YY) * (Y - YY));   }   struct PT {     long long ID;     long double len, Y;     PT(long long _ID, long double _Y) {       ID = _ID;       Y = _Y;     }     bool operator<(const PT &a) const { return (Y < a.Y); }   };   vector<PT> A, B;   void BinSearch(vector<PT> &C, long double val, long long &low, long long &up) {     long long i, med;     up = C.size() - 1;     low = 0;     if (val >= C[up].Y) {       low = max(up - 1, low);       return;     }     if (val <= C[low].Y) {       up = min(low + 1, up);       return;     }     while ((up - low) > 1) {       med = (up + low) / 2;       if (C[med].Y < val)         low = med;       else         up = med;     }   }   int main() {     long long i, n, m, a, b, temp;     cin >> n >> m >> a >> b;     for (i = 0; i < n; i++) {       cin >> temp;       A.push_back(PT(i + 1, temp));       A[i].len = Dis(0, 0, a, temp);     }     for (i = 0; i < m; i++) {       cin >> temp;       B.push_back(PT(i + 1, temp));     }     for (i = 0; i < m; i++) {       cin >> temp;       B[i].len = temp;     }     sort(A.begin(), A.end());     sort(B.begin(), B.end());     long long ind1, ind2;     long double ans, tmp1, tmp2, mini, tt;     long long l, u;     ans = 1e18;     for (i = 0; i < m; i++) {       tt = ((long double)a * B[i].Y) / ((long double)(b));       BinSearch(A, tt, l, u);       tmp1 = Dis(a, A[u].Y, b, B[i].Y) + A[u].len;       tmp2 = Dis(a, A[l].Y, b, B[i].Y) + A[l].len;       mini = min(tmp1, tmp2);       if (ans > (B[i].len + mini)) {         if ((tmp1 < tmp2))           ind1 = A[u].ID, ans = B[i].len + tmp1;         else           ind1 = A[l].ID, ans = B[i].len + tmp2;         ind2 = B[i].ID;       }     }     cout << ind1 <<     << ind2 << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 4000 + 10, MOD = (int)1e9 + 9;   int n, m, b, w, f[MAXN][MAXN];   int main() {     cin >> n >> w >> b;     m = max(b, w);     f[0][0] = 1;     for (int i = 1; i <= m; ++i) {       for (int j = 1; j <= i; ++j)         f[i][j] = ((long long)f[i - 1][j] * (j + i - 1) +                    (long long)f[i - 1][j - 1] * j) %                   MOD;     }     int Tohka = 0;     for (int i = 1; i <= min(b, n - 2); ++i)       Tohka = ((long long)Tohka +                (long long)f[w][n - i] * f[b][i] % MOD * (n - i - 1)) %               MOD;     cout << Tohka << endl;     fclose(stdin);     fclose(stdout);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline void read(long long &x) {     long long f = 1;     x = 0;     char c = getchar();     while (c <  0  || c >  9 ) {       if (c ==  - ) f = -1;       c = getchar();     }     while (c >=  0  && c <=  9 ) {       x = x * 10 + c -  0 ;       c = getchar();     }     x *= f;   }   long long fa[200005][21], lg[2 * 200005], deep[200005], dis[200005], w[200005],       t[200005], h[200005], head, n, ans[200005];   struct yyy {     long long to, z, w;     inline void add(long long x, long long y, long long W) {       to = y;       z = h[x];       h[x] = head;       w = W;     }   } a[200005 * 2];   inline void dfs2(long long x, long long pre) {     register long long i;     deep[x] = deep[pre] + 1;     fa[x][0] = pre;     for (i = 1; i <= lg[deep[x]]; i++) fa[x][i] = fa[fa[x][i - 1]][i - 1];     for (i = h[x]; i; i = a[i].z)       if (a[i].to != pre) dis[a[i].to] = dis[x] + a[i].w, dfs2(a[i].to, x);   }   inline void dfs(long long x, long long pre) {     register long long i;     for (i = h[x]; i; i = a[i].z)       if (a[i].to ^ pre) {         dfs(a[i].to, x);         t[x] += t[a[i].to];       }   }   inline void init() {     register long long i, j, k;     for (j = 1, k = 1; j <= n; j <<= 1, k++)       for (i = j; i < j * 2; i++) lg[i] = k;     dfs2(1, 0);   }   signed main() {     register long long i, j, x, y;     read(n);     for (i = 1; i <= n; i++) read(w[i]);     for (i = 2; i <= n; i++) {       read(x);       read(y);       a[++head].add(i, x, y);       a[++head].add(x, i, y);     }     init();     for (i = 2; i <= n; i++) {       x = i;       for (j = lg[deep[i]]; j >= 0; j--)         if (fa[x][j] && dis[i] - dis[fa[x][j]] <= w[i]) x = fa[x][j];       t[fa[x][0]]--;       t[fa[i][0]]++;     }     dfs(1, 0);     for (i = 1; i <= n; i++) printf( %lld  , t[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n, x, a[200000];   long long bs(long long xx, long long yy, long long k) {     long long m = (xx + yy) / 2;     if (yy - xx <= 1) return xx;     if (a[m] <= k)       return bs(m, yy, k);     else       return bs(xx, m, k);   }   int main() {     cin >> n;     for (int i = 0; i < n; i++) cin >> a[i];     sort(a, a + n);     x = 1;     for (int j = 0; j < 31; j++) {       for (int i = 0; i < n; i++) {         if (a[bs(0, n, a[i] - x)] == a[i] - x &&             a[bs(0, n, a[i] + x)] == a[i] + x) {           return cout << 3 << endl                       << a[i] - x <<     << a[i] <<     << a[i] + x,                  0;         }       }       x *= 2;     }     x = 1;     for (int j = 0; j < 31; j++) {       for (int i = 0; i < n; i++) {         if (a[bs(0, n, a[i] - x)] == a[i] - x) {           return cout << 2 << endl << a[i] - x <<     << a[i], 0;         }       }       x *= 2;     }     cout << 1 << endl << a[0];     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void fastIo() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);   }   int main() {     fastIo();     int q;     cin >> q;     while (q--) {       int n;       cin >> n;       string s;       cin >> s;       if (n == 1) {         cout <<  NO  << endl;       } else if (n == 2) {         if (s[0] >= s[1])           cout <<  NO  << endl;         else {           cout <<  YES  << endl;           cout <<  2  << endl;           cout << s[0] <<     << s[1] << endl;         }       } else {         cout <<  YES  << endl;         cout <<  2  << endl;         cout << s[0] <<    ;         for (int i = 1; i < n; i++) cout << s[i];         cout << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       string s1, s2;       cin >> s1 >> s2;       bool poss = true;       int change[20][20];       memset(change, 0, sizeof(change));       for (int i = 0; i < n; i++) {         if (s1[i] > s2[i])           poss = false;         else {           if (s1[i] != s2[i]) {             change[s1[i] - 97][s2[i] - 97]++;           }         }       }       if (!poss) {         cout << -1 << endl;         continue;       }       int steps = 0;       for (int i = 0; i < 19; i++) {         int x = -1;         for (int j = 1; j < 20; j++) {           if (change[i][j] > 0) {             steps++;             x = j;             break;           }         }         if (x != -1) {           for (int j = x + 1; j <= 20; j++) {             change[x][j] += change[i][j];           }         }       }       cout << steps << endl;     }   }
#include <bits/stdc++.h>   const int inf = 1e9;   const double eps = 1e-9;   const int mod = 1e9 + 7;   using namespace std;   int mypow(int x, int y) {     int res = 1;     for (; y >= 1; y >>= 1) {       if (y & 1) res = (1ll * res * x) % mod;       x = (1ll * x * x) % mod;     }     return res;   }   int32_t main() {     long long n;     int k;     cin >> n >> k;     vector<long long> p;     vector<int> al;     long long x = n;     for (long long i = 2; i * i <= x; ++i) {       if (!(x % i)) {         p.push_back(i);         al.push_back(0);       }       int c = 0;       while (!(x % i)) {         al[al.size() - 1]++;         x /= i;       }     }     if (x != 1) {       p.push_back(x);       al.push_back(1);     }     int ans = 1;     for (int o = 0; o < p.size(); ++o) {       vector<vector<int>> dp(k + 1, vector<int>(al[o] + 1, 0));       dp[0][al[o]] = 1;       for (int i = 1; i <= k; ++i) {         for (int j = 0; j <= al[o]; ++j) {           int s = (1ll * dp[i - 1][j] * mypow(j + 1, mod - 2)) % mod;           for (int h = 0; h <= j; ++h) {             dp[i][h] = (dp[i][h] + s) % mod;           }         }       }       int l = 0;       int r = 1;       for (int j = 0; j <= al[o]; ++j) {         l = (l + (1ll * dp[k][j] * r) % mod) % mod;         r = (1ll * r * (p[o] % mod)) % mod;       }       ans = (1ll * ans * l) % mod;     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   map<long long, map<long long, long long, greater<long long>>> comp;   map<long long, long long, greater<long long>> Add(long long x) {     if (x == 0) return {};     if (comp.count(x)) return comp[x];     long long choose = (x - 1) / 2;     long long diff = min(choose + 1, x - choose);     map<long long, long long, greater<long long>> ret = {{diff, 1}};     for (long long xp : {choose, x - choose - 1})       for (auto p : Add(xp)) ret[p.first] += p.second;     return comp[x] = ret;   }   long long Solve(long long x, long long seek, long long& cnt) {     long long choose = (x - 1) / 2;     long long diff = min(choose + 1, x - choose);     if (diff == seek) {       return choose + cnt;     }     long long ret = 0;     for (long long xp : {choose, x - choose - 1}) {       long long now = Add(xp)[seek];       if (now > cnt) {         return ret + Solve(xp, seek, cnt);       }       cnt -= now;       ret += choose + 1;     }     assert(false);   }   int32_t main() {     long long n, k;     cin >> n >> k;     if (k == 1) {       cout << 1 << endl;       return 0;     }     if (k == 2) {       cout << n << endl;       return 0;     }     n -= 2;     k -= 3;     for (auto p : Add(n)) {       if (p.second > k) {         cout << 2 + Solve(n, p.first, k) << endl;         return 0;       }       k -= p.second;     }     assert(false);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   void smax(T &a, T b) {     if (a < b) a = b;   }   const double EPS = 1e-9;   vector<pair<pair<int, int>, int> > adj[100000 + 10];   long long totSum;   pair<pair<int, int>, int> edges[100000 + 10];   int belows[100000 + 10];   int n;   pair<long long, int> f(int u, int jad) {     long long sum = 0;     int cnts = 0;     for (int i = 0; i < ((int)(adj[u]).size()); ++i) {       int v = adj[u][i].first.first;       int cost = adj[u][i].first.second;       int edge = adj[u][i].second;       if (v == jad) {         continue;       }       pair<long long, int> temp = f(v, u);       int cnt = temp.second;       long long belowSum = temp.first + (long long)cost * cnt;       belows[edge] = cnt;       totSum += cnt * sum;       totSum += cnts * belowSum;       sum += belowSum;       cnts += cnt;     }     cnts++;     totSum += sum;     return make_pair(sum, cnts);   }   inline long long getDollarBabe(long long temp) { return temp * (n - temp); }   int main(int argc, char const *argv[]) {     ios_base::sync_with_stdio(false);     cin.tie(0);     cin >> n;     for (int i = 0; i < n - 1; ++i) {       int u, v, len;       cin >> u >> v >> len;       if (u > v) {         swap(u, v);       }       u--;       v--;       adj[u].push_back(make_pair(make_pair(v, len), i));       adj[v].push_back(make_pair(make_pair(u, len), i));       edges[i] = make_pair(make_pair(u, v), len);     }     totSum = 0;     f(0, -1);     int q;     cin >> q;     while (q--) {       int r, w;       cin >> r >> w;       r--;       int temp = belows[r];       totSum -= (edges[r].second - w) * getDollarBabe(temp);       edges[r].second = w;       cout << fixed << setprecision(8)            << (double)totSum * 6 / ((long long)(n) * (n - 1)) << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long mod = 1000000007;   int main() {     int n, m;     scanf( %d %d , &n, &m);     string S;     set<int> H[n];     set<int> V[m];     for (int i = 0; i < (n); i++) {       cin >> S;       for (int j = 0; j < (m); j++)         if (S[j] !=  . ) {           int t = S[j] -  0 ;           int h = (t <= 2);           int v = (t == 1 || t == 4);           H[i].insert((h + j) % 2);           V[j].insert((v + i) % 2);         }     }     bool good = true;     int cnt = m + n;     for (int i = 0; i < (n); i++) {       if (H[i].size() > 1)         good = 0;       else if (H[i].size())         --cnt;     }     for (int j = 0; j < (m); j++) {       if (V[j].size() > 1)         good = 0;       else if (V[j].size())         --cnt;     }     if (good) {       int ans = 1;       for (int i = 0; i < (cnt); i++) {         ans += ans;         ans %= 1000003;       }       cout << ans << endl;     } else       cout << 0 << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long n;     cin >> n;     cin.ignore();     while (n--) {       string str1, str2;       getline(cin, str1);       getline(cin, str2);       bool test = true;       long long j = 0, i = 0;       char last_ch = str1[0];       while (j < str2.size() && i < str1.size()) {         if (str2[j] == str1[i])           last_ch = str1[i], i++, j++;         else if (str2[j] == last_ch) {           while (str2[j] == last_ch) j++;         } else {           test = false;           break;         }       }       while (j < str2.size()) {         if (str2[j] != last_ch) {           test = false;           break;         }         j++;       }       if (!test) {         cout <<  NO  << endl;         continue;       }       if (i < str1.size()) {         cout <<  NO  << endl;         continue;       }       cout <<  YES  << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int II() {     int q;     scanf( %d , &q);     return q;   }   void solve() {     long long N, M;     cin >> N >> M;     long long ar[N + 10], br[N + 10], cr[N + 10];     for (long long i = 1; i <= N; i++) {       cin >> ar[i] >> br[i] >> cr[i];     }     long long mi = M, mx = M;     ar[0] = 0;     for (long long i = 1; i <= N; i++) {       long long q = ar[i] - ar[i - 1];       mi = max(mi - q, br[i]);       mx = min(mx + q, cr[i]);       if (mi > cr[i] or mx < br[i]) {         cout <<  NO  << endl;         return;       }     }     cout <<  YES  << endl;   }   int32_t main() {     long long tt;     cin >> tt;     long long cas = 1;     while (tt--) {       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   void winter_is_coming() {     std::ios_base::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);   }   int main() {     void winter_is_coming();     long long a, b, dis, dis2, ans = 0;     cin >> a >> b;     dis = abs(a - b);     dis2 = dis / 2;     dis = dis - dis2;     ans = (dis * (dis + 1) / 2) + (dis2 * (dis2 + 1) / 2);     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, fa[100010], siz[100010];   double ans;   int getfa(int w) { return (w == fa[w]) ? w : fa[w] = getfa(fa[w]); }   struct edg {     int nx, ny, val;     bool operator<(const edg& e) const { return val > e.val; }   } a[100010];   int main() {     cin >> n >> m;     int b[100010];     long long tot = 0;     for (int i = 1; i <= n; i++) cin >> b[i];     for (int i = 0; i < m; i++) {       int x, y;       cin >> x >> y;       a[i] = (edg){x, y, min(b[x], b[y])};     }     sort(a, a + m);     for (int i = 1; i <= n; i++) fa[i] = i;     for (int i = 1; i <= n; i++) siz[i] = 1;     for (int i = 0; i < m; i++)       if (getfa(a[i].nx) ^ getfa(a[i].ny)) {         int x = a[i].nx, y = a[i].ny;         tot += (long long)a[i].val * siz[fa[x]] * siz[fa[y]];         siz[fa[x]] += siz[fa[y]];         fa[fa[y]] = fa[x];       }     ans = tot;     tot = (long long)n * (n - 1) / 2;     ans /= tot;     printf( %.06lf , ans);     return 0;   }