#pragma GCC target("avx2")
#pragma GCC optimize("O3")

#include <x86intrin.h>
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

template<typename T> using ordered_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define pf push_front
#define ppb pop_back
#define mp make_pair
#define bpp __builtin_popcountll
#define sqr(x) ((x) * (x))
#define al 0x3F3F3F3F
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define in insert
#define ppf pop_front
#define endl '\n'
//#define int long long

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;

const int mod = (int)1e9 + 7;
const int N = (int)3e5 + 123;
const ll inf = (ll)1e18 + 1;

const double pi = acos (-1.0);
const double eps = 1e-7;
const int dx[] = {0, 0, 1, 0, -1};
const int dy[] = {0, 1, 0, -1, 0};

int n, k, a[N], lvl[N], dp[401][401], suff[201][201];
vector <int> g[N];

void dfs (int v = 1, int pr = 0) {
   lvl[v] = lvl[pr] + 1;
   if (sz (g[v]) <= 1 && v > 1) {
      dp[v][lvl[v]] = a[v];
      dp[v][2 * n] = 0;
      for (int i = 2 * n; i >= 1; i --) suff[v][i] = max (suff[v][i + 1], dp[v][i]);
      return;
   }
   for (auto to : g[v])
      if (to != pr)
         dfs (to, v);
   for (int mx = 2 * n; mx > lvl[v]; mx --) {
      if (mx - lvl[v] <= k) continue;
      int sum = 0;
      for (auto to : g[v]) sum += suff[to][mx];
      dp[v][lvl[v]] = max (dp[v][lvl[v]], sum + a[v]);
   }
   for (int mn = 2 * n; mn > lvl[v]; mn --) {
      int need = k + 2 * lvl[v] - mn + 1;
      if (need < 1) need = 1;
      for (int i = 0; i < sz (g[v]); i ++) {
         if (g[v][i] == pr) continue;
         int sum = dp[g[v][i]][mn];
         if (sum == -mod) continue;
         need = max (need, mn);
         for (int j = 0; j < sz (g[v]); j ++) {
            if (g[v][j] == pr || i == j) continue;
            if (suff[g[v][j]][need] == -mod) continue;
            sum += suff[g[v][j]][need];
         }
         dp[v][mn] = max (dp[v][mn], sum);
      }
   }
   for (int i = 2 * n; i >= 1; i --) suff[v][i] = max (suff[v][i + 1], dp[v][i]);
}

inline void boost () {
   ios_base :: sync_with_stdio (NULL);
   cin.tie (NULL), cout.tie (NULL);
}

inline void Solve () {
   cin >> n >> k;
   for (int i = 1; i <= n; i ++) cin >> a[i];
   for (int i = 1; i < n; i ++) {
      int x, y;
      cin >> x >> y;
      g[x].pb (y);
      g[y].pb (x);
   }
   for (int i = 1; i <= n; i ++)
      for (int j = 1; j <= 2 * n; j ++)
         dp[i][j] = -mod;
   dfs ();
   int ans = 0;
   for (int i = 1; i <= 2 * n; i ++) ans = max (ans, dp[1][i]);
   cout << ans;
}

main () {
// freopen (".in", "r", stdin);
// freopen (".out", "w", stdout);
   boost ();
   int tt = 1;
   //cin >> tt;
   while (tt --) {
      Solve ();
   }
   return 0;
}


#pragma GCC target("avx2")
#pragma GCC optimize("O3")

#include <x86intrin.h>
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

template<typename T> using ordered_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define pf push_front
#define ppb pop_back
#define mp make_pair
#define bpp __builtin_popcountll
#define sqr(x) ((x) * (x))
#define al 0x3F3F3F3F
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define in insert
#define ppf pop_front
#define endl '\n'
//#define int long long

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;

const int mod = (int)1e9 + 7;
const int N = (int)3e5 + 123;
const ll inf = (ll)1e18 + 1;

const double pi = acos (-1.0);
const double eps = 1e-7;
const int dx[] = {0, 0, 1, 0, -1};
const int dy[] = {0, 1, 0, -1, 0};

int n, k, a[N], lvl[N], dp[401][401], suff[201][201];
vector <int> g[N];

void dfs (int v = 1, int pr = 0) {
   lvl[v] = lvl[pr] + 1;
   if (sz (g[v]) <= 1 && v > 1) {
      dp[v][lvl[v]] = a[v];
      dp[v][2 * n] = 0;
      for (int i = 2 * n; i >= 1; i --) suff[v][i] = max (suff[v][i + 1], dp[v][i]);
      return;
   }
   for (auto to : g[v])
      if (to != pr)
         dfs (to, v);
   for (int mx = 2 * n; mx > lvl[v]; mx --) {
      if (mx - lvl[v] <= k) continue;
      int sum = 0;
      for (auto to : g[v]) sum += suff[to][mx];
      dp[v][lvl[v]] = max (dp[v][lvl[v]], sum + a[v]);
   }
   for (int mn = 2 * n; mn > lvl[v]; mn --) {
      int need = k + 2 * lvl[v] - mn + 1;
      if (need < 1) need = 1;
      for (int i = 0; i < sz (g[v]); i ++) {
         if (g[v][i] == pr) continue;
         int sum = dp[g[v][i]][mn];
         if (sum == -mod) continue;
         need = max (need, mn);
         for (int j = 0; j < sz (g[v]); j ++) {
            if (g[v][j] == pr || i == j) continue;
            if (suff[g[v][j]][need] == -mod) {
               sum = -mod;
               break;
            }
            sum += suff[g[v][j]][need];
         }
         dp[v][mn] = max (dp[v][mn], sum);
      }
   }
   for (int i = 2 * n; i >= 1; i --) suff[v][i] = max (suff[v][i + 1], dp[v][i]);
}

inline void boost () {
   ios_base :: sync_with_stdio (NULL);
   cin.tie (NULL), cout.tie (NULL);
}

inline void Solve () {
   cin >> n >> k;
   for (int i = 1; i <= n; i ++) cin >> a[i];
   for (int i = 1; i < n; i ++) {
      int x, y;
      cin >> x >> y;
      g[x].pb (y);
      g[y].pb (x);
   }
   for (int i = 1; i <= n; i ++)
      for (int j = 1; j <= 2 * n; j ++)
         dp[i][j] = -mod;
   dfs ();
   int ans = 0;
   for (int i = 1; i <= 2 * n; i ++) ans = max (ans, dp[1][i]);
   cout << ans;
}

main () {
// freopen (".in", "r", stdin);
// freopen (".out", "w", stdout);
   boost ();
   int tt = 1;
   //cin >> tt;
   while (tt --) {
      Solve ();
   }
   return 0;
}


#pragma GCC target("avx2")
#pragma GCC optimize("O3")

#include <x86intrin.h>
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

template<typename T> using ordered_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define pf push_front
#define ppb pop_back
#define mp make_pair
#define bpp __builtin_popcountll
#define sqr(x) ((x) * (x))
#define al 0x3F3F3F3F
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define in insert
#define ppf pop_front
#define endl '\n'
//#define int long long

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;

const int mod = (int)1e9 + 7;
const int N = (int)3e5 + 123;
const ll inf = (ll)1e18 + 1;

const double pi = acos (-1.0);
const double eps = 1e-7;
const int dx[] = {0, 0, 1, 0, -1};
const int dy[] = {0, 1, 0, -1, 0};

int n, k, a[N], lvl[N], dp[401][401], suff[201][201];
vector <int> g[N];

void dfs (int v = 1, int pr = 0) {
   lvl[v] = lvl[pr] + 1;
   if (sz (g[v]) == 1 && v > 1) {
      dp[v][lvl[v]] = a[v];
      dp[v][2 * n] = 0;
      for (int i = 2 * n; i >= 1; i --) suff[v][i] = max (suff[v][i + 1], dp[v][i]);
      return;
   }
   for (auto to : g[v])
      if (to != pr)
         dfs (to, v);
   for (int mx = 2 * n; mx > lvl[v]; mx --) {
      if (mx - lvl[v] <= k) continue;
      int sum = 0;
      for (auto to : g[v]) sum += suff[to][mx];
      dp[v][lvl[v]] = max (dp[v][lvl[v]], sum + a[v]);
   }
   for (int mn = 2 * n; mn > lvl[v]; mn --) {
      int need = k + 2 * lvl[v] - mn + 1;
      if (need < 1) need = 1;
      for (int i = 0; i < sz (g[v]); i ++) {
         if (g[v][i] == pr) continue;
         int sum = suff[g[v][i]][mn];
         if (sum == -mod) continue;
         if (need >= mn) {
            for (int j = 0; j < sz (g[v]); j ++) {
               if (g[v][j] == pr || i == j) continue;
               if (suff[g[v][j]][need] == -mod) {
                  sum = -mod;
                  break;
               }
               sum += suff[g[v][j]][need];
            }
         }
         dp[v][mn] = max (dp[v][mn], sum);
      }
   }
   for (int i = 2 * n; i >= 1; i --) suff[v][i] = max (suff[v][i + 1], dp[v][i]);
}

inline void boost () {
   ios_base :: sync_with_stdio (NULL);
   cin.tie (NULL), cout.tie (NULL);
}

inline void Solve () {
   cin >> n >> k;
   for (int i = 1; i <= n; i ++) cin >> a[i];
   for (int i = 1; i < n; i ++) {
      int x, y;
      cin >> x >> y;
      g[x].pb (y);
      g[y].pb (x);
   }
   for (int i = 1; i <= n; i ++)
      for (int j = 1; j <= 2 * n; j ++)
         dp[i][j] = -mod;
   dfs ();
   int ans = 0;
   for (int i = 1; i <= 2 * n; i ++) ans = max (ans, dp[1][i]);
   cout << ans;
}

main () {
// freopen (".in", "r", stdin);
// freopen (".out", "w", stdout);
   boost ();
   int tt = 1;
   //cin >> tt;
   while (tt --) {
      Solve ();
   }
   return 0;
}


#pragma GCC target("avx2")
#pragma GCC optimize("O3")

#include <x86intrin.h>
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

template<typename T> using ordered_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define pf push_front
#define ppb pop_back
#define mp make_pair
#define bpp __builtin_popcountll
#define sqr(x) ((x) * (x))
#define al 0x3F3F3F3F
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define in insert
#define ppf pop_front
#define endl '\n'
//#define int long long

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;

const int mod = (int)1e9 + 7;
const int N = (int)3e5 + 123;
const ll inf = (ll)1e18 + 1;

const double pi = acos (-1.0);
const double eps = 1e-7;
const int dx[] = {0, 0, 1, 0, -1};
const int dy[] = {0, 1, 0, -1, 0};

int n, k, a[N], lvl[N], dp[401][401], suff[201][201];
vector <int> g[N];

void dfs (int v = 1, int pr = 0) {
   lvl[v] = lvl[pr] + 1;
   if (sz (g[v]) == 1 && v > 1) {
      dp[v][lvl[v]] = a[v];
      dp[v][2 * n] = 0;
      for (int i = 2 * n; i >= 1; i --) suff[v][i] = max (suff[v][i + 1], dp[v][i]);
      return;
   }
   for (auto to : g[v])
      if (to != pr)
         dfs (to, v);
   for (int mx = 2 * n; mx > lvl[v]; mx --) {
      if (mx - lvl[v] <= k) continue;
      int sum = 0;
      for (auto to : g[v]) sum += suff[to][mx];
      dp[v][lvl[v]] = max (dp[v][lvl[v]], sum + a[v]);
   }
   for (int mn = 2 * n; mn > lvl[v]; mn --) {
      int need = k + 2 * lvl[v] - mn + 1;
      if (need < 1) need = 1;
      for (int i = 0; i < sz (g[v]); i ++) {
         if (g[v][i] == pr) continue;
         int sum = dp[g[v][i]][mn];
         if (sum == -mod) continue;
         for (int j = 0; j < sz (g[v]); j ++) {
            if (g[v][j] == pr || i == j) continue;
            sum += suff[g[v][j]][need];
         }
         dp[v][mn] = max (dp[v][mn], sum);
      }
   }
   for (int i = 2 * n; i >= 1; i --) suff[v][i] = max (suff[v][i + 1], dp[v][i]);
}

inline void boost () {
   ios_base :: sync_with_stdio (NULL);
   cin.tie (NULL), cout.tie (NULL);
}

inline void Solve () {
   cin >> n >> k;
   for (int i = 1; i <= n; i ++) cin >> a[i];
   for (int i = 1; i < n; i ++) {
      int x, y;
      cin >> x >> y;
      g[x].pb (y);
      g[y].pb (x);
   }
   for (int i = 1; i <= n; i ++)
      for (int j = 1; j <= 2 * n; j ++)
         dp[i][j] = -mod;
   dfs ();
   int ans = 0;
   for (int i = 1; i <= n; i ++) ans = max (ans, dp[1][i]);
   cout << ans;
}

main () {
// freopen (".in", "r", stdin);
// freopen (".out", "w", stdout);
   boost ();
   int tt = 1;
   //cin >> tt;
   while (tt --) {
      Solve ();
   }
   return 0;
}


#pragma GCC target("avx2")
#pragma GCC optimize("O3")

#include <x86intrin.h>
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

template<typename T> using ordered_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define pf push_front
#define ppb pop_back
#define mp make_pair
#define bpp __builtin_popcountll
#define sqr(x) ((x) * (x))
#define al 0x3F3F3F3F
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define in insert
#define ppf pop_front
#define endl '\n'
//#define int long long

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;

const int mod = (int)1e9 + 7;
const int N = (int)3e5 + 123;
const ll inf = (ll)1e18 + 1;

const double pi = acos (-1.0);
const double eps = 1e-7;
const int dx[] = {0, 0, 1, 0, -1};
const int dy[] = {0, 1, 0, -1, 0};

int n, k, a[N], lvl[N], dp[401][401], suff[201][201];
vector <int> g[N];

void dfs (int v = 1, int pr = 0) {
   lvl[v] = lvl[pr] + 1;
   if (sz (g[v]) == 1 && v > 1) {
      dp[v][lvl[v]] = a[v];
      dp[v][2 * n] = 0;
      for (int i = 2 * n; i >= 1; i --) suff[v][i] = max (suff[v][i + 1], dp[v][i]);
      return;
   }
   for (auto to : g[v])
      if (to != pr)
         dfs (to, v);
   for (int mx = 2 * n; mx > lvl[v]; mx --) {
      if (mx - lvl[v] <= k) continue;
      int sum = 0;
      for (auto to : g[v]) sum += suff[to][mx];
      dp[v][lvl[v]] = max (dp[v][lvl[v]], sum + a[v]);
   }
   for (int mn = 2 * n; mn > lvl[v]; mn --) {
      int need = k + 2 * lvl[v] - mn + 1;
      if (need < 1) need = 1;
      if (need < mn) continue;
      for (int i = 0; i < sz (g[v]); i ++) {
         if (g[v][i] == pr) continue;
         int sum = dp[g[v][i]][mn];
         if (sum == -mod) continue;
         for (int j = 0; j < sz (g[v]); j ++) {
            if (g[v][j] == pr || i == j) continue;
            sum += suff[g[v][j]][need];
         }
         dp[v][mn] = max (dp[v][mn], sum);
      }
   }
   for (int i = 2 * n; i >= 1; i --) suff[v][i] = max (suff[v][i + 1], dp[v][i]);
}

inline void boost () {
   ios_base :: sync_with_stdio (NULL);
   cin.tie (NULL), cout.tie (NULL);
}

inline void Solve () {
   cin >> n >> k;
   for (int i = 1; i <= n; i ++) cin >> a[i];
   for (int i = 1; i < n; i ++) {
      int x, y;
      cin >> x >> y;
      g[x].pb (y);
      g[y].pb (x);
   }
   for (int i = 1; i <= n; i ++)
      for (int j = 1; j <= 2 * n; j ++)
         dp[i][j] = -mod;
   dfs ();
   int ans = 0;
   for (int i = 1; i <= 2 * n; i ++) ans = max (ans, dp[1][i]);
   cout << ans;
}

main () {
// freopen (".in", "r", stdin);
// freopen (".out", "w", stdout);
   boost ();
   int tt = 1;
   //cin >> tt;
   while (tt --) {
      Solve ();
   }
   return 0;
}


#pragma GCC target("avx2")
#pragma GCC optimize("O3")

#include <x86intrin.h>
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

template<typename T> using ordered_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define pf push_front
#define ppb pop_back
#define mp make_pair
#define bpp __builtin_popcountll
#define sqr(x) ((x) * (x))
#define al 0x3F3F3F3F
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define in insert
#define ppf pop_front
#define endl '\n'
//#define int long long

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;

const int mod = (int)1e9 + 7;
const int N = (int)3e5 + 123;
const ll inf = (ll)1e18 + 1;

const double pi = acos (-1.0);
const double eps = 1e-7;
const int dx[] = {0, 0, 1, 0, -1};
const int dy[] = {0, 1, 0, -1, 0};

int n, k, a[N], lvl[N], dp[401][401], suff[201][201];
vector <int> g[N];

void dfs (int v = 1, int pr = 0) {
   lvl[v] = lvl[pr] + 1;
   if (sz (g[v]) == 1 && v > 1) {
      dp[v][lvl[v]] = a[v];
      dp[v][2 * n] = 0;
      for (int i = 2 * n; i >= 1; i --) suff[v][i] = max (suff[v][i + 1], dp[v][i]);
      return;
   }
   for (auto to : g[v])
      if (to != pr)
         dfs (to, v);
   for (int mx = 2 * n; mx > lvl[v]; mx --) {
      if (mx - lvl[v] <= k) continue;
      int sum = 0;
      for (auto to : g[v]) sum += suff[to][mx];
      dp[v][lvl[v]] = max (dp[v][lvl[v]], sum + a[v]);
   }
   for (int mn = 2 * n; mn > lvl[v]; mn --) {
      int need = k + 2 * lvl[v] - mn + 1;
      if (need < 1) need = 1;
      for (int i = 0; i < sz (g[v]); i ++) {
         if (g[v][i] == pr) continue;
         int sum = dp[g[v][i]][mn];
         if (sum == -mod) continue;
         for (int j = 0; j < sz (g[v]); j ++) {
            if (g[v][j] == pr || i == j) continue;
            sum += suff[g[v][j]][need];
         }
         dp[v][mn] = max (dp[v][mn], sum);
      }
   }
   for (int i = 2 * n; i >= 1; i --) suff[v][i] = max (suff[v][i + 1], dp[v][i]);
}

inline void boost () {
   ios_base :: sync_with_stdio (NULL);
   cin.tie (NULL), cout.tie (NULL);
}

inline void Solve () {
   cin >> n >> k;
   for (int i = 1; i <= n; i ++) cin >> a[i];
   for (int i = 1; i < n; i ++) {
      int x, y;
      cin >> x >> y;
      g[x].pb (y);
      g[y].pb (x);
   }
   for (int i = 1; i <= n; i ++)
      for (int j = 1; j <= 2 * n; j ++)
         dp[i][j] = -mod;
   dfs ();
   int ans = 0;
   for (int i = 1; i <= 2 * n; i ++) ans = max (ans, dp[1][i]);
   cout << ans;
}

main () {
// freopen (".in", "r", stdin);
// freopen (".out", "w", stdout);
   boost ();
   int tt = 1;
   //cin >> tt;
   while (tt --) {
      Solve ();
   }
   return 0;
}


#pragma GCC target("avx2")
#pragma GCC optimize("O3")

#include <x86intrin.h>
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

template<typename T> using ordered_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define pf push_front
#define ppb pop_back
#define mp make_pair
#define bpp __builtin_popcountll
#define sqr(x) ((x) * (x))
#define al 0x3F3F3F3F
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define in insert
#define ppf pop_front
#define endl '\n'
//#define int long long

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;

const int mod = (int)1e9 + 7;
const int N = (int)3e5 + 123;
const ll inf = (ll)1e18 + 1;

const double pi = acos (-1.0);
const double eps = 1e-7;
const int dx[] = {0, 0, 1, 0, -1};
const int dy[] = {0, 1, 0, -1, 0};

int n, k, a[N], lvl[N], dp[401][401], suff[201][201];
vector <int> g[N];

void dfs (int v = 1, int pr = 0) {
   lvl[v] = lvl[pr] + 1;z
   if (sz (g[v]) == 1 && v > 1) {
      dp[v][lvl[v]] = a[v];
      dp[v][2 * n] = 0;
      for (int i = 2 * n; i >= 1; i --) suff[v][i] = max (suff[v][i + 1], dp[v][i]);
      return;
   }
   for (auto to : g[v])
      if (to != pr)
         dfs (to, v);
   for (int mx = 2 * n; mx > lvl[v]; mx --) {
      if (mx - lvl[v] <= k) continue;
      int sum = 0;
      for (auto to : g[v]) sum += suff[to][mx];
      dp[v][lvl[v]] = max (dp[v][lvl[v]], sum + a[v]);
   }
   for (int mn = 2 * n; mn > lvl[v]; mn --) {
      int need = k + 2 * lvl[v] - mn + 1;
      if (need < 1) need = 1;
      for (int i = 0; i < sz (g[v]); i ++) {
         if (g[v][i] == pr) continue;
         int sum = dp[g[v][i]][mn];
         if (sum == -mod) continue;
         for (int j = 0; j < sz (g[v]); j ++) {
            if (g[v][j] == pr || i == j) continue;
            sum += suff[g[v][j]][need];
         }
         dp[v][mn] = max (dp[v][mn], sum);
      }
   }
   for (int i = 2 * n; i >= 1; i --) suff[v][i] = max (suff[v][i + 1], dp[v][i]);
}

inline void boost () {
   ios_base :: sync_with_stdio (NULL);
   cin.tie (NULL), cout.tie (NULL);
}

inline void Solve () {
   cin >> n >> k;
   for (int i = 1; i <= n; i ++) cin >> a[i];
   for (int i = 1; i < n; i ++) {
      int x, y;
      cin >> x >> y;
      g[x].pb (y);
      g[y].pb (x);
   }
   for (int i = 1; i <= n; i ++)
      for (int j = 1; j <= 2 * n; j ++)
         dp[i][j] = -mod;
   dfs ();
   int ans = 0;
   for (int i = 1; i <= 2 * n; i ++) ans = max (ans, dp[1][i]);
   cout << ans;
}

main () {
// freopen (".in", "r", stdin);
// freopen (".out", "w", stdout);
   boost ();
   int tt = 1;
   //cin >> tt;
   while (tt --) {
      Solve ();
   }
   return 0;
}


#pragma GCC target("avx2")
#pragma GCC optimize("O3")

#include <x86intrin.h>
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

template<typename T> using ordered_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define pf push_front
#define ppb pop_back
#define mp make_pair
#define bpp __builtin_popcountll
#define sqr(x) ((x) * (x))
#define al 0x3F3F3F3F
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define in insert
#define ppf pop_front
#define endl '\n'
//#define int long long

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;

const int mod = (int)1e9 + 7;
const int N = (int)3e5 + 123;
const ll inf = (ll)1e18 + 1;

const double pi = acos (-1.0);
const double eps = 1e-7;
const int dx[] = {0, 0, 1, 0, -1};
const int dy[] = {0, 1, 0, -1, 0};

int n, k, a[N], lvl[N], dp[401][601], suff[401][601];
vector <int> g[N];

void dfs (int v = 1, int pr = 0) {
   lvl[v] = lvl[pr] + 1;
   if (sz (g[v]) <= 1 && v > 1) {
      dp[v][lvl[v]] = a[v];
      dp[v][3 * n] = 0;
      for (int i = 3 * n; i >= 1; i --) suff[v][i] = max (suff[v][i + 1], dp[v][i]);
      return;
   }
   for (auto to : g[v])
      if (to != pr)
         dfs (to, v);
   for (int mx = 3 * n; mx > lvl[v]; mx --) {
      if (mx - lvl[v] <= k) continue;
      int sum = 0;
      for (auto to : g[v]) sum += suff[to][mx];
      dp[v][lvl[v]] = max (dp[v][lvl[v]], sum + a[v]);
   }
   for (int mn = 3 * n; mn > lvl[v]; mn --) {
      int need = k + 2 * lvl[v] - mn + 1;
      if (need < 1) need = 1;
      for (int i = 0; i < sz (g[v]); i ++) {
         if (g[v][i] == pr) continue;
         int sum = dp[g[v][i]][mn];
         if (sum == -mod) continue;
         need = max (need, mn);
         for (int j = 0; j < sz (g[v]); j ++) {
            if (g[v][j] == pr || i == j) continue;
            if (suff[g[v][j]][need] == -mod) continue;
            sum += suff[g[v][j]][need];
         }
         dp[v][mn] = max (dp[v][mn], sum);
      }
   }
   for (int i = 3 * n; i >= 1; i --) suff[v][i] = max (suff[v][i + 1], dp[v][i]);
}

inline void boost () {
   ios_base :: sync_with_stdio (NULL);
   cin.tie (NULL), cout.tie (NULL);
}

inline void Solve () {
   cin >> n >> k;
   for (int i = 1; i <= n; i ++) cin >> a[i];
   for (int i = 1; i < n; i ++) {
      int x, y;
      cin >> x >> y;
      g[x].pb (y);
      g[y].pb (x);
   }
   for (int i = 1; i <= n; i ++)
      for (int j = 1; j <= 3 * n; j ++)
         dp[i][j] = -mod;
   dfs ();
   int ans = 0;
   for (int i = 1; i <= 2 * n; i ++) ans = max (ans, dp[1][i]);
   cout << ans;
}

main () {
// freopen (".in", "r", stdin);
// freopen (".out", "w", stdout);
   boost ();
   int tt = 1;
   //cin >> tt;
   while (tt --) {
      Solve ();
   }
   return 0;
}


#pragma GCC target("avx2")
#pragma GCC optimize("O3")

#include <x86intrin.h>
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

template<typename T> using ordered_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define pf push_front
#define ppb pop_back
#define mp make_pair
#define bpp __builtin_popcountll
#define sqr(x) ((x) * (x))
#define al 0x3F3F3F3F
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define in insert
#define ppf pop_front
#define endl '\n'
//#define int long long

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;

const int mod = (int)1e9 + 7;
const int N = (int)3e5 + 123;
const ll inf = (ll)1e18 + 1;

const double pi = acos (-1.0);
const double eps = 1e-7;
const int dx[] = {0, 0, 1, 0, -1};
const int dy[] = {0, 1, 0, -1, 0};

int n, k, a[N], lvl[N], dp[401][401], suff[201][201];
vector <int> g[N];

void dfs (int v = 1, int pr = 0) {
   lvl[v] = lvl[pr] + 1;
   if (sz (g[v]) == 1 && v > 1) {
      dp[v][lvl[v]] = a[v];
      dp[v][2 * n] = 0;
      for (int i = 2 * n; i >= 1; i --) suff[v][i] = max (suff[v][i + 1], dp[v][i]);
      return;
   }
   for (auto to : g[v])
      if (to != pr)
         dfs (to, v);
   for (int mx = 2 * n; mx > lvl[v]; mx --) {
      if (mx - lvl[v] <= k) continue;
      int sum = 0;
      for (auto to : g[v]) sum += suff[to][mx];
      dp[v][lvl[v]] = max (dp[v][lvl[v]], sum + a[v]);
   }
   for (int mn = 2 * n; mn > lvl[v]; mn --) {
      int need = k + 2 * lvl[v] - mn + 1;
      if (need < 1) need = 1;
      for (int i = 0; i < sz (g[v]); i ++) {
         if (g[v][i] == pr) continue;
         int sum = dp[g[v][i]][mn];
         if (sum == -mod) continue;
         need = max (need, mn);
         for (int j = 0; j < sz (g[v]); j ++) {
            if (g[v][j] == pr || i == j) continue;
            if (suff[g[v][j]][need] == -mod) {
               sum = -mod;
               break;
            }
            sum += suff[g[v][j]][need];
         }
         dp[v][mn] = max (dp[v][mn], sum);
      }
   }
   for (int i = 2 * n; i >= 1; i --) suff[v][i] = max (suff[v][i + 1], dp[v][i]);
}

inline void boost () {
   ios_base :: sync_with_stdio (NULL);
   cin.tie (NULL), cout.tie (NULL);
}

inline void Solve () {
   cin >> n >> k;
   for (int i = 1; i <= n; i ++) cin >> a[i];
   for (int i = 1; i < n; i ++) {
      int x, y;
      cin >> x >> y;
      g[x].pb (y);
      g[y].pb (x);
   }
   for (int i = 1; i <= n; i ++)
      for (int j = 1; j <= 2 * n; j ++)
         dp[i][j] = -mod;
   dfs ();
   int ans = 0;
   for (int i = 1; i <= 2 * n; i ++) ans = max (ans, dp[1][i]);
   cout << ans;
}

main () {
// freopen (".in", "r", stdin);
// freopen (".out", "w", stdout);
   boost ();
   int tt = 1;
   //cin >> tt;
   while (tt --) {
      Solve ();
   }
   return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int maxn = 205;
int d[maxn][maxn], a[maxn], n, k;
vector<int> G[maxn];
int dfs(int u, int fa) {
    d[u][0] = a[u];
    int w[maxn];
    memset(w, 0, sizeof(w));
    for (auto v : G[u])
    if (v != fa) {
        dfs(v, u);
        for (int j = 0; j <= n; j++)
            w[j] += d[v][j];
        d[u][0] += d[v][k];
    }
    for (auto v : G[u])
    if (v != fa)
        for (int j = 1; j <= n; j++)
            d[u][j] = max(d[u][j], d[v][j - 1] + w[max(0, k - j)] - d[v][max(0, k - j)]);
    for (int i = n - 1; ~i; i--)
        d[u][i] = max(d[u][i], d[u][i + 1]);
    return d[u][0];
}
int main() {
    int u, v;
    cin >> n >> k;
    for (int i = 1; i <= n; i++)
        cin >> a[i];
    for (int i = 1; i < n; i++) {
        cin >> u >> v;
        G[u].push_back(v);
        G[v].push_back(u);
    }
    cout << dfs(1, 0);
}


#include<bits/stdc++.h>
using namespace std;
const int maxn = 205;
int d[maxn][maxn], a[maxn], n, k;
vector<int> G[maxn];
int dfs(int u, int fa) {
    d[u][0] = a[u];
    int w[maxn], son = 0;
    memset(w, 0, sizeof(w));
    for (auto v : G[u])
    if (v != fa) {
        ++son;
        dfs(v, u);
        for (int j = 0; j <= n; j++)
            w[j] += d[v][j];
        d[u][0] += d[v][k];
    }
    for (auto v : G[u])
    if (v != fa)
        for (int j = 1; j <= n; j++) {
            int p = max(j - 1, k - j);
            d[u][j] = max(d[u][j], d[v][j - 1] + w[p] - d[v][p]);
        }
    for (int i = n - 1; ~i; i--)
        d[u][i] = max(d[u][i], d[u][i + 1]);
    return d[u][0];
}
int main() {
    int u, v;
    cin >> n >> k;
    for (int i = 1; i <= n; i++)
        cin >> a[i];
    for (int i = 1; i < n; i++) {
        cin >> u >> v;
        G[u].push_back(v);
        G[v].push_back(u);
    }
    cout << dfs(1, 0);
}


#include<bits/stdc++.h>
using namespace std;
const int maxn = 205;
int d[maxn][maxn], a[maxn], n, k;
vector<int> G[maxn];
int dfs(int u, int fa) {
    d[u][0] = a[u];
    int w[maxn], son = 0;
    memset(w, 0, sizeof(w));
    for (auto v : G[u])
    if (v != fa) {
        ++son;
        dfs(v, u);
        for (int j = 0; j <= n; j++)
            w[j] += d[v][j];
        //if (u == 5)
            //printf("d[%d][%d] = %d\n", v, k, d[v][k]);
        d[u][0] += d[v][k];
    }
    for (auto v : G[u])
    if (v != fa)
        for (int j = 1; j <= n; j++) {
            int p = max(0, k - j);
            if (p >= j - 1 || son == 1) {
                d[u][j] = max(d[u][j], d[v][j - 1] + w[p] - d[v][p]);
                if (u == 7) {
                    //printf("d[%d][%d] = %d w[%d] = %d d[%d][%d] = %d\n", v, j - 1, d[v][j - 1], p, w[p], v, p, d[v][p]);
                    //printf("d[%d][%d] = %d\n", u, j, d[u][j]);
                }
            }
        }
    for (int i = n - 1; ~i; i--)
        d[u][i] = max(d[u][i], d[u][i + 1]);
    return d[u][0];
}
int main() {
    int u, v;
    cin >> n >> k;
    for (int i = 1; i <= n; i++)
        cin >> a[i];
    for (int i = 1; i < n; i++) {
        cin >> u >> v;
        G[u].push_back(v);
        G[v].push_back(u);
    }
    cout << dfs(1, 0);
}


#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
#include<bits/stdc++.h>
#define rc(x) return cout<<x<<endl,0
#define pb push_back
#define mkp make_pair
#define in insert
#define er erase
#define fd find
#define fr first
#define sc second
typedef long long ll;
typedef long double ld;
const ll INF=0x3f3f3f3f3f3f3f3f;
const ll llinf=(1LL<<62);
const int inf=(1<<30);
const int nmax=2e2+5;
const int mod=1e9+7;
using namespace std;
int n,k,vl[nmax],x,y,i,j,sm,rs;
bitset<nmax>viz,g[nmax];
vector<int>a[nmax],rnd;
void dfs(int x,int p,int l)
{
	if(l>k)g[p][x]=1;
	viz[x]=1;
	for(int i=0;i<a[x].size();i++)if(!viz[a[x][i]])dfs(a[x][i],p,l+1);
}
int main()
{
	//freopen("sol.in","r",stdin);
	//freopen("sol.out","w",stdout);
	mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
	//srand(time(0));
	cin>>n>>k;
	for(i=1;i<=n;i++)cin>>vl[i];
	for(i=1;i<n;i++)
	{
		cin>>x>>y;
		a[x].pb(y);
		a[y].pb(x);
	}
	for(i=1;i<=n;i++)
	{
		viz.reset();
		dfs(i,i,0);
	}
	for(i=1;i<=n;i++)rnd.pb(i);
	for(j=1;j<=200000;j++)
	{
		shuffle(rnd.begin(),rnd.end(),rng);
		viz.reset();
		sm=0;
		for(i=0;i<n;i++)
		{
			x=rnd[i];
			if((viz&g[x]).count()==viz.count())
			{
				sm+=vl[x];
				viz[x]=1;
			}
			else break;
		}
		rs=max(rs,sm);
	}
	cout<<rs<<endl;
	return 0;
}


#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
#include<bits/stdc++.h>
#define rc(x) return cout<<x<<endl,0
#define pb push_back
#define mkp make_pair
#define in insert
#define er erase
#define fd find
#define fr first
#define sc second
typedef long long ll;
typedef long double ld;
const ll INF=0x3f3f3f3f3f3f3f3f;
const ll llinf=(1LL<<62);
const int inf=(1<<30);
const int nmax=2e2+5;
const int mod=1e9+7;
using namespace std;
int n,k,vl[nmax],x,y,i,j,sm,rs;
bitset<nmax>viz,g[nmax];
vector<int>a[nmax],rnd;
void dfs(int x,int p,int l)
{
	if(l>k)g[p][x]=1;
	viz[x]=1;
	for(int i=0;i<a[x].size();i++)if(!viz[a[x][i]])dfs(a[x][i],p,l+1);
}
int main()
{
	//freopen("sol.in","r",stdin);
	//freopen("sol.out","w",stdout);
	mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
	//srand(time(0));
	cin>>n>>k;
	for(i=1;i<=n;i++)cin>>vl[i];
	for(i=1;i<n;i++)
	{
		cin>>x>>y;
		a[x].pb(y);
		a[y].pb(x);
	}
	for(i=1;i<=n;i++)
	{
		viz.reset();
		dfs(i,i,0);
	}
	for(i=1;i<=n;i++)rnd.pb(i);
	while (clock() / (double) CLOCKS_PER_SEC <= 1.98)
	{
		shuffle(rnd.begin(),rnd.end(),rng);
		viz.reset();
		sm=0;
		for(i=0;i<n;i++)
		{
			x=rnd[i];
			if((viz&g[x]).count()==viz.count())
			{
				sm+=vl[x];
				viz[x]=1;
			}
		}
		rs=max(rs,sm);
	}
	cout<<rs<<endl;
	return 0;
}


#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
#include<bits/stdc++.h>
#define rc(x) return cout<<x<<endl,0
#define pb push_back
#define mkp make_pair
#define in insert
#define er erase
#define fd find
#define fr first
#define sc second
typedef long long ll;
typedef long double ld;
const ll INF=0x3f3f3f3f3f3f3f3f;
const ll llinf=(1LL<<62);
const int inf=(1<<30);
const int nmax=2e2+5;
const int mod=1e9+7;
using namespace std;
int n,k,vl[nmax],x,y,i,j,sm,rs;
bitset<nmax>viz,g[nmax];
vector<int>a[nmax],rnd;
void dfs(int x,int p,int l)
{
	if(l>k)g[p][x]=1;
	viz[x]=1;
	for(int i=0;i<a[x].size();i++)if(!viz[a[x][i]])dfs(a[x][i],p,l+1);
}
int main()
{
	//freopen("sol.in","r",stdin);
	//freopen("sol.out","w",stdout);
	//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
	srand(time(0));
	cin>>n>>k;
	for(i=1;i<=n;i++)cin>>vl[i];
	for(i=1;i<n;i++)
	{
		cin>>x>>y;
		a[x].pb(y);
		a[y].pb(x);
	}
	for(i=1;i<=n;i++)
	{
		viz.reset();
		dfs(i,i,0);
	}
	for(i=1;i<=n;i++)rnd.pb(i);
	for(j=1;j<=200000;j++)
	{
		random_shuffle(rnd.begin(),rnd.end());
		viz.reset();
		sm=0;
		for(i=0;i<n;i++)
		{
			x=rnd[i];
			if((viz&g[x]).count()==viz.count())
			{
				sm+=vl[x];
				viz[x]=1;
			}
		}
		rs=max(rs,sm);
	}
	cout<<rs<<endl;
	return 0;
}


#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
#include<bits/stdc++.h>
#define rc(x) return cout<<x<<endl,0
#define pb push_back
#define mkp make_pair
#define in insert
#define er erase
#define fd find
#define fr first
#define sc second
typedef long long ll;
typedef long double ld;
const ll INF=0x3f3f3f3f3f3f3f3f;
const ll llinf=(1LL<<62);
const int inf=(1<<30);
const int nmax=2e2+5;
const int mod=1e9+7;
using namespace std;
int n,k,vl[nmax],x,y,i,j,sm,rs;
bitset<nmax>viz,g[nmax];
vector<int>a[nmax],rnd;
void dfs(int x,int p,int l)
{
	if(l>k)g[p][x]=1;
	viz[x]=1;
	for(int i=0;i<a[x].size();i++)if(!viz[a[x][i]])dfs(a[x][i],p,l+1);
}
int main()
{
	//freopen("sol.in","r",stdin);
	//freopen("sol.out","w",stdout);
	//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
	cin>>n>>k;
	for(i=1;i<=n;i++)cin>>vl[i];
	for(i=1;i<n;i++)
	{
		cin>>x>>y;
		a[x].pb(y);
		a[y].pb(x);
	}
	for(i=1;i<=n;i++)
	{
		viz.reset();
		dfs(i,i,0);
	}
	for(i=1;i<=n;i++)rnd.pb(i);
	for(j=1;j<=100000;j++)
	{
		random_shuffle(rnd.begin(),rnd.end());
		viz.reset();
		sm=0;
		for(i=0;i<n;i++)
		{
			x=rnd[i];
			if((viz&g[x]).count()==viz.count())
			{
				sm+=vl[x];
				viz[x]=1;
			}
		}
		rs=max(rs,sm);
	}
	cout<<rs<<endl;
	return 0;
}


#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
#include <bits/stdc++.h>
#define rc(x) return cout<<x<<endl,0
#define pb push_back
#define mkp make_pair
#define in insert
#define er erase
#define fd find
#define fr first
#define sc second
typedef long long ll;
typedef long double ld;
const ll INF=0x3f3f3f3f3f3f3f3f;
const ll llinf=(1LL<<62);
const int inf=(1<<30);
const int nmax=2e3+50;
const int mod=1e9+7;
using namespace std;
int n,k,v[nmax],f[nmax][nmax],x,y,i,sf[nmax],pr[nmax];
vector<int>a[nmax];
void dfs(int x,int p)
{
	int sm=0;
	for(int i=0;i<(int)a[x].size();i++)
	{
		int y=a[x][i];
		if(y==p)continue;
		dfs(y,x);
		sm+=f[y][k-1];
	}
	f[x][0]=v[x]+sm;
	for(int i=1;i<=n;i++)
	{
		for(int j=0;j<(int)a[x].size();j++)
		{
			int y=a[x][j];
			if(y==p)continue;
			pr[j]=f[y][max(i-1,k-i-1)];
			if(j)pr[j]+=pr[j-1];
		}
		for(int j=(int)a[x].size()-1;j>=0;j--)
		{
			int y=a[x][j];
			if(y==p)continue;
			sf[j]=f[y][max(i-1,k-i-1)];
			if(j<(int)a[x].size()-1)sf[j]+=sf[j+1];
		}
		for(int j=0;j<(int)a[x].size();j++)
		{
			int y=a[x][j];
			if(y==p)continue;
			sm=f[y][i-1];
			if(j)sm+=pr[j-1];
			if(j<(int)a[x].size()-1)sm+=sf[j+1];
			f[x][i]=max(f[x][i],sm);
		}
	}
	for(int i=n;i>=0;i--)f[x][i]=max(f[x][i],f[x][i+1]);
}
int main()
{
	//freopen("sol.in","r",stdin);
	//freopen("sol.out","w",stdout);
	//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
	cin>>n>>k;
	k++;
	for(i=1;i<=n;i++)cin>>v[i];
	for(i=1;i<n;i++)
	{
		cin>>x>>y;
		a[x].pb(y);
		a[y].pb(x);
	}
	dfs(1,1);
	cout<<f[1][0]<<endl;
	return 0;
}


#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
#include<bits/stdc++.h>
#define rc(x) return cout<<x<<endl,0
#define pb push_back
#define mkp make_pair
#define in insert
#define er erase
#define fd find
#define fr first
#define sc second
typedef long long ll;
typedef long double ld;
const ll INF=0x3f3f3f3f3f3f3f3f;
const ll llinf=(1LL<<62);
const int inf=(1<<30);
const int nmax=2e2+5;
const int mod=1e9+7;
using namespace std;
int n,k,vl[nmax],x,y,i,j,sm,rs;
bitset<nmax>viz,g[nmax];
vector<int>a[nmax],rnd;
void dfs(int x,int p,int l)
{
	if(l>k)g[p][x]=1;
	viz[x]=1;
	for(int i=0;i<a[x].size();i++)if(!viz[a[x][i]])dfs(a[x][i],p,l+1);
}
int main()
{
	//freopen("sol.in","r",stdin);
	//freopen("sol.out","w",stdout);
	//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
	cin>>n>>k;
	for(i=1;i<=n;i++)cin>>vl[i];
	for(i=1;i<n;i++)
	{
		cin>>x>>y;
		a[x].pb(y);
		a[y].pb(x);
	}
	for(i=1;i<=n;i++)
	{
		viz.reset();
		dfs(i,i,0);
	}
	for(i=1;i<=n;i++)rnd.pb(i);
	for(j=1;j<=500000;j++)
	{
		random_shuffle(rnd.begin(),rnd.end());
		viz.reset();
		sm=0;
		for(i=0;i<n;i++)
		{
			x=rnd[i];
			if((viz&g[x]).count()==viz.count())
			{
				sm+=vl[x];
				viz[x]=1;
			}
		}
		rs=max(rs,sm);
	}
	cout<<rs<<endl;
	return 0;
}


#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
#include<bits/stdc++.h>
#define rc(x) return cout<<x<<endl,0
#define pb push_back
#define mkp make_pair
#define in insert
#define er erase
#define fd find
#define fr first
#define sc second
typedef long long ll;
typedef long double ld;
const ll INF=0x3f3f3f3f3f3f3f3f;
const ll llinf=(1LL<<62);
const int inf=(1<<30);
const int nmax=2e2+5;
const int mod=1e9+7;
using namespace std;
int n,k,vl[nmax],x,y,i,j,sm,rs;
bitset<nmax>viz,g[nmax];
vector<int>a[nmax],rnd;
void dfs(int x,int p,int l)
{
	if(l>k)g[p][x]=1;
	viz[x]=1;
	for(int i=0;i<a[x].size();i++)if(!viz[a[x][i]])dfs(a[x][i],p,l+1);
}
int main()
{
	//freopen("sol.in","r",stdin);
	//freopen("sol.out","w",stdout);
	mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
	//srand(time(0));
	cin>>n>>k;
	for(i=1;i<=n;i++)cin>>vl[i];
	for(i=1;i<n;i++)
	{
		cin>>x>>y;
		a[x].pb(y);
		a[y].pb(x);
	}
	for(i=1;i<=n;i++)
	{
		viz.reset();
		dfs(i,i,0);
	}
	for(i=1;i<=n;i++)rnd.pb(i);
	while (clock() / (double) CLOCKS_PER_SEC <= 1.9)
	{
		shuffle(rnd.begin(),rnd.end(),rng);
		viz.reset();
		sm=0;
		for(i=0;i<n;i++)
		{
			x=rnd[i];
			if((viz&g[x]).count()==viz.count())
			{
				sm+=vl[x];
				viz[x]=1;
			}
		}
		rs=max(rs,sm);
	}
	cout<<rs<<endl;
	return 0;
}


#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
#include<bits/stdc++.h>
#define rc(x) return cout<<x<<endl,0
#define pb push_back
#define mkp make_pair
#define in insert
#define er erase
#define fd find
#define fr first
#define sc second
typedef long long ll;
typedef long double ld;
const ll INF=0x3f3f3f3f3f3f3f3f;
const ll llinf=(1LL<<62);
const int inf=(1<<30);
const int nmax=2e2+5;
const int mod=1e9+7;
using namespace std;
int n,k,vl[nmax],x,y,i,j,sm,rs;
bitset<nmax>viz,g[nmax];
vector<int>a[nmax],rnd;
void dfs(int x,int p,int l)
{
	if(l>k)g[p][x]=1;
	viz[x]=1;
	for(int i=0;i<a[x].size();i++)if(!viz[a[x][i]])dfs(a[x][i],p,l+1);
}
int main()
{
	//freopen("sol.in","r",stdin);
	//freopen("sol.out","w",stdout);
	mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
	//srand(time(0));
	cin>>n>>k;
	for(i=1;i<=n;i++)cin>>vl[i];
	for(i=1;i<n;i++)
	{
		cin>>x>>y;
		a[x].pb(y);
		a[y].pb(x);
	}
	for(i=1;i<=n;i++)
	{
		viz.reset();
		dfs(i,i,0);
	}
	for(i=1;i<=n;i++)rnd.pb(i);
	while (clock() / (double) CLOCKS_PER_SEC <= 1.95)
	{
		shuffle(rnd.begin(),rnd.end(),rng);
		viz.reset();
		sm=0;
		for(i=0;i<n;i++)
		{
			x=rnd[i];
			if((viz&g[x]).count()==viz.count())
			{
				sm+=vl[x];
				viz[x]=1;
			}
		}
		rs=max(rs,sm);
	}
	cout<<rs<<endl;
	return 0;
}


#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
#include<bits/stdc++.h>
#define rc(x) return cout<<x<<endl,0
#define pb push_back
#define mkp make_pair
#define in insert
#define er erase
#define fd find
#define fr first
#define sc second
typedef long long ll;
typedef long double ld;
const ll INF=0x3f3f3f3f3f3f3f3f;
const ll llinf=(1LL<<62);
const int inf=(1<<30);
const int nmax=2e2+5;
const int mod=1e9+7;
using namespace std;
int n,k,vl[nmax],x,y,i,j,sm,rs;
bitset<nmax>viz,g[nmax];
vector<int>a[nmax],rnd;
void dfs(int x,int p,int l)
{
	if(l>k)g[p][x]=1;
	viz[x]=1;
	for(int i=0;i<a[x].size();i++)if(!viz[a[x][i]])dfs(a[x][i],p,l+1);
}
int main()
{
	//freopen("sol.in","r",stdin);
	//freopen("sol.out","w",stdout);
	mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
	//srand(time(0));
	cin>>n>>k;
	for(i=1;i<=n;i++)cin>>vl[i];
	for(i=1;i<n;i++)
	{
		cin>>x>>y;
		a[x].pb(y);
		a[y].pb(x);
	}
	for(i=1;i<=n;i++)
	{
		viz.reset();
		dfs(i,i,0);
	}
	for(i=1;i<=n;i++)rnd.pb(i);
	while (clock() / (double) CLOCKS_PER_SEC <= 1.8)
	{
		shuffle(rnd.begin(),rnd.end(),rng);
		viz.reset();
		sm=0;
		for(i=0;i<n;i++)
		{
			x=rnd[i];
			if((viz&g[x]).count()==viz.count())
			{
				sm+=vl[x];
				viz[x]=1;
			}
		}
		rs=max(rs,sm);
	}
	cout<<rs<<endl;
	return 0;
}


#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
#include <bits/stdc++.h>
#define rc(x) return cout<<x<<endl,0
#define pb push_back
#define mkp make_pair
#define in insert
#define er erase
#define fd find
#define fr first
#define sc second
typedef long long ll;
typedef long double ld;
const ll INF=0x3f3f3f3f3f3f3f3f;
const ll llinf=(1LL<<62);
const int inf=(1<<30);
const int nmax=2e3+50;
const int mod=1e9+7;
using namespace std;
int n,k,v[nmax],f[nmax][nmax],x,y,i,sf[nmax],pr[nmax];
vector<int>a[nmax];
void dfs(int x,int p)
{
	int sm=0;
	for(int i=0;i<(int)a[x].size();i++)
	{
		int y=a[x][i];
		if(y==p)continue;
		dfs(y,x);
		sm+=f[y][k-1];
	}
	f[x][0]=v[x]+sm;
	for(int i=1;i<=n;i++)
	{
		for(int j=0;j<(int)a[x].size();j++)
		{
			int y=a[x][j];
			if(j)pr[j]=pr[j-1];
			if(y==p)continue;
			pr[j]=f[y][max(i-1,k-i-1)];
			if(j)pr[j]+=pr[j-1];
		}
		for(int j=(int)a[x].size()-1;j>=0;j--)
		{
			int y=a[x][j];
			if(j<(int)a[x].size()-1)sf[j]=sf[j+1];
			if(y==p)continue;
			sf[j]=f[y][max(i-1,k-i-1)];
			if(j<(int)a[x].size()-1)sf[j]+=sf[j+1];
		}
		for(int j=0;j<(int)a[x].size();j++)
		{
			int y=a[x][j];
			if(y==p)continue;
			sm=f[y][i-1];
			if(j)sm+=pr[j-1];
			if(j<(int)a[x].size()-1)sm+=sf[j+1];
			f[x][i]=max(f[x][i],sm);
		}
	}
	for(int i=n;i>=0;i--)f[x][i]=max(f[x][i],f[x][i+1]);
}
int main()
{
	//freopen("sol.in","r",stdin);
	//freopen("sol.out","w",stdout);
	//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
	cin>>n>>k;
	k++;
	for(i=1;i<=n;i++)cin>>v[i];
	for(i=1;i<n;i++)
	{
		cin>>x>>y;
		a[x].pb(y);
		a[y].pb(x);
	}
	dfs(1,1);
	cout<<f[1][0]<<endl;
	return 0;
}


#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
#include <bits/stdc++.h>
#define rc(x) return cout<<x<<endl,0
#define pb push_back
#define mkp make_pair
#define in insert
#define er erase
#define fd find
#define fr first
#define sc second
typedef long long ll;
typedef long double ld;
const ll INF=0x3f3f3f3f3f3f3f3f;
const ll llinf=(1LL<<62);
const int inf=(1<<30);
const int nmax=1e3+50;
const int mod=1e9+7;
using namespace std;
int n,k,v[nmax],f[nmax][nmax],x,y,i;
vector<int>a[nmax];
void dfs(int x,int p)
{
	int sm=0;
	for(int i=0;i<(int)a[x].size();i++)
	{
		int y=a[x][i];
		if(y==p)continue;
		dfs(y,x);
		sm+=f[y][k-1];
	}
	f[x][0]=v[x]+sm;
	for(int i=1;i<=n;i++)
	{
		for(int j=0;j<(int)a[x].size();j++)
		{
			int y=a[x][j];
			if(y==p)continue;
			sm=f[y][i-1];
			for(int t=0;t<(int)a[x].size();t++)
			{
				int z=a[x][t];
				if(z==p || z==y)continue;
				sm+=f[z][max(i-1,k-i-1)];
			}
			f[x][i]=max(f[x][i],sm);
		}
	}
	for(int i=n;i>=0;i--)
	{
		//if(i<=k)cout<<x<<" "<<i<<" "<<f[x][i]<<endl;
		f[x][i]=max(f[x][i],f[x][i+1]);
	}
}
int main()
{
	//freopen("sol.in","r",stdin);
	//freopen("sol.out","w",stdout);
	//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
	cin>>n>>k;
	k++;
	for(i=1;i<=n;i++)cin>>v[i];
	for(i=1;i<n;i++)
	{
		cin>>x>>y;
		a[x].pb(y);
		a[y].pb(x);
	}
	dfs(1,1);
	cout<<f[1][0]<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int N = 205;
long long val[N],sum[N],dp[N];
int n,k;
bool viz[N];
vector<int> v[N];
void dfs(int x, int lvl)
{
    viz[x] = 1;
    sum[lvl]+=val[x];
    for (auto it: v[x])
        if (!viz[it])
            dfs(it,lvl+1);
    dp[lvl] = sum[lvl];
    if (lvl>k)
        for (int i = 1; i<lvl-k; i++)
            dp[lvl] = max(dp[lvl],sum[lvl]+dp[i]);
}
int main()
{
    cin >> n >> k;
    for (int i = 1; i<=n; i++)
        cin >> val[i];
    for (int i = 1; i<n; i++)
    {
        int x,y;
        cin >> x >> y;
        v[x].push_back(y);
        v[y].push_back(x);
    }
    long long ans = 0;
    for (int root = 1; root<=n; root++)
    {
        memset(viz,0,sizeof(viz));
        memset(sum,0,sizeof(sum));
        memset(dp,0,sizeof(dp));
        dfs(root,1);
        for (int i = 1; i<=n; i++)
            ans = max(ans,dp[i]);
    }
    cout << ans;
}


#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <list>
#include <vector>
#include <map>
#include <queue>

using namespace std;

int main()
{
    int n;
    cin>>n;
    vector <int> qq;
    long long q, a=0, x=0;
    for (int i=0; i<n; i++)
        {
            cin>>q;
            a+=q;
            qq.push_back(q);
        }
    sort(qq.begin(), qq.end());
    a+=(qq[n-1]-qq[0])*(n-1)*2;
   // cout<<a;
    long long nn=n;
    long long aa=a;
    long long r;
    while ((nn!=0)&&(aa!=0))
        {
            if (nn>aa)
            {
                r=aa;
                nn%=aa;
            }
            else
            {
                r=nn;
                aa%=nn;
            }
        }
    cout << a/r<<" "<<n/r;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#define Eo(x) do { cerr << #x << " = " << (x) << endl; } while (0)
#define E(x) do { cerr << #x << " = " << (x) << " "; } while (0)
#undef assert
#define assert(x) if(x);else{fprintf(stderr, "%s:%d: assertion %s failed\n", __FILE__, __LINE__, #x); abort();}
#else
#define Eo(x)
#define E(x)
#endif
#define Sz(x) (int((x).size()))
#define All(x) (x).begin(),(x).end()

template<class A, class B> ostream &operator<<(ostream &os, const pair<A, B>& p) { return os << '(' << p.first << ", " << p.second << ')'; }
template<class T> void operator<<(vector<T> &v, const T &x){v.push_back(x);}
template<class T> void operator>>(vector<T> &v, T &x){assert(!v.empty()); x=v.back(); v.pop_back();}
template<class T> void operator<<(set<T> &v, const T &x){v.insert(x);}
template<class T> void operator>>(set<T> &v, T &x){assert(!v.empty()); x=*v.begin(); v.erase(v.begin());}

typedef long long int64;
typedef pair<int, int> pii;

const int INF = 0x3F3F3F3F;
const double EPS = 1e-8;
const double PI = acos(-1.0);

const int N = 100100;
int a[N];

int64 s[N];

template <typename T>
struct Ratio {

    T n, d;
    Ratio(T n0 = T(), T d0 = T(1)) {
        T g = abs(__gcd(n0, d0));
        if (d0 < 0) g *= -1;
        n = n0 / g;
        d = d0 / g;
    }
    Ratio operator + (const Ratio &that) const { return Ratio(n * that.d + that.n * d, d * that.d); }
    Ratio operator - (const Ratio &that) const { return Ratio(n * that.d - that.n * d, d * that.d); }
    Ratio operator * (const Ratio &that) const { return Ratio(n * that.n, d * that.d); }
    Ratio operator / (const Ratio &that) const { return Ratio(n * that.d, d * that.n); }
    bool operator < (const Ratio &that) const { Ratio diff = *this - that; return (diff.n < 0); }
    bool operator <= (const Ratio &that) const { Ratio diff = *this - that; return (diff.n <= 0); }
    bool operator == (const Ratio &that) const { return (n == that.n && d == that.d); }
    bool operator != (const Ratio &that) const { return (n != that.n || d != that.d); }
    double realVal() const { return double(n) / d; }
};

int main() {
	int n;
	scanf("%d", &n);

	for (int i = 0; i < n; ++i) scanf("%d", a + i);
	sort(a, a + n);
	for (int i = 0; i < n; ++i) s[i + 1] = s[i] + a[i];
	int64 sum = 0;
	for (int i = 1; i < n; ++i) {
		sum += int64(i) * a[i] - s[i];
	}
Eo(sum);
	sum *= 2;
Eo(sum);
	sum += s[n];
Eo(sum);
	Ratio<int64> x(sum);
	//for (int i = 2; i <= n; ++i) {
		x = x / n;
	//}
	cout << x.n << " " << x.d << endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#define Eo(x) do { cerr << #x << " = " << (x) << endl; } while (0)
#define E(x) do { cerr << #x << " = " << (x) << " "; } while (0)
#undef assert
#define assert(x) if(x);else{fprintf(stderr, "%s:%d: assertion %s failed\n", __FILE__, __LINE__, #x); abort();}
#else
#define Eo(x)
#define E(x)
#endif
#define Sz(x) (int((x).size()))
#define All(x) (x).begin(),(x).end()

template<class A, class B> ostream &operator<<(ostream &os, const pair<A, B>& p) { return os << '(' << p.first << ", " << p.second << ')'; }
template<class T> void operator<<(vector<T> &v, const T &x){v.push_back(x);}
template<class T> void operator>>(vector<T> &v, T &x){assert(!v.empty()); x=v.back(); v.pop_back();}
template<class T> void operator<<(set<T> &v, const T &x){v.insert(x);}
template<class T> void operator>>(set<T> &v, T &x){assert(!v.empty()); x=*v.begin(); v.erase(v.begin());}

typedef long long int64;
typedef pair<int, int> pii;

const int INF = 0x3F3F3F3F;
const double EPS = 1e-8;
const double PI = acos(-1.0);

const int N = 100100;
int a[N];

int64 s[N];

template <typename T>
struct Ratio {

    T n, d;
    Ratio(T n0 = T(), T d0 = T(1)) {
        T g = abs(__gcd(n0, d0));
        if (d0 < 0) g *= -1;
        n = n0 / g;
        d = d0 / g;
    }
    Ratio operator + (const Ratio &that) const { return Ratio(n * that.d + that.n * d, d * that.d); }
    Ratio operator - (const Ratio &that) const { return Ratio(n * that.d - that.n * d, d * that.d); }
    Ratio operator * (const Ratio &that) const { return Ratio(n * that.n, d * that.d); }
    Ratio operator / (const Ratio &that) const { return Ratio(n * that.d, d * that.n); }
    bool operator < (const Ratio &that) const { Ratio diff = *this - that; return (diff.n < 0); }
    bool operator <= (const Ratio &that) const { Ratio diff = *this - that; return (diff.n <= 0); }
    bool operator == (const Ratio &that) const { return (n == that.n && d == that.d); }
    bool operator != (const Ratio &that) const { return (n != that.n || d != that.d); }
    double realVal() const { return double(n) / d; }
};

int main() {
	int n;
	scanf("%d", &n);
	//for (int i = 1; i <= n; ++i) s << i;
	//pgen();
	//for (int i = 1; i <= n; ++i) printf("%d ", x[i]);
	//printf("\n");

	for (int i = 0; i < n; ++i) scanf("%d", a + i);
	sort(a, a + n);
	for (int i = 0; i < n; ++i) s[i + 1] = s[i] + a[i];
	int64 sum = 0;
	for (int i = 1; i < n; ++i) {
		sum += i * a[i] - s[i];
	}
Eo(sum);
	sum *= 2;
Eo(sum);
	sum += s[n];
Eo(sum);
	Ratio<int64> x(sum);
	//for (int i = 2; i <= n; ++i) {
		x = x / n;
	//}
	cout << x.n << " " << x.d << endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#define Eo(x) do { cerr << #x << " = " << (x) << endl; } while (0)
#define E(x) do { cerr << #x << " = " << (x) << " "; } while (0)
#undef assert
#define assert(x) if(x);else{fprintf(stderr, "%s:%d: assertion %s failed\n", __FILE__, __LINE__, #x); abort();}
#else
#define Eo(x)
#define E(x)
#endif
#define Sz(x) (int((x).size()))
#define All(x) (x).begin(),(x).end()

template<class A, class B> ostream &operator<<(ostream &os, const pair<A, B>& p) { return os << '(' << p.first << ", " << p.second << ')'; }
template<class T> void operator<<(vector<T> &v, const T &x){v.push_back(x);}
template<class T> void operator>>(vector<T> &v, T &x){assert(!v.empty()); x=v.back(); v.pop_back();}
template<class T> void operator<<(set<T> &v, const T &x){v.insert(x);}
template<class T> void operator>>(set<T> &v, T &x){assert(!v.empty()); x=*v.begin(); v.erase(v.begin());}

typedef long long int64;
typedef pair<int, int> pii;

const int INF = 0x3F3F3F3F;
const double EPS = 1e-8;
const double PI = acos(-1.0);

const int N = 100100;
int a[N];

int64 s[N];

template <typename T>
struct Ratio {

    T n, d;
    Ratio(T n0 = T(), T d0 = T(1)) {
        T g = abs(__gcd(n0, d0));
        if (d0 < 0) g *= -1;
        n = n0 / g;
        d = d0 / g;
    }
    Ratio operator + (const Ratio &that) const { return Ratio(n * that.d + that.n * d, d * that.d); }
    Ratio operator - (const Ratio &that) const { return Ratio(n * that.d - that.n * d, d * that.d); }
    Ratio operator * (const Ratio &that) const { return Ratio(n * that.n, d * that.d); }
    Ratio operator / (const Ratio &that) const { return Ratio(n * that.d, d * that.n); }
    bool operator < (const Ratio &that) const { Ratio diff = *this - that; return (diff.n < 0); }
    bool operator <= (const Ratio &that) const { Ratio diff = *this - that; return (diff.n <= 0); }
    bool operator == (const Ratio &that) const { return (n == that.n && d == that.d); }
    bool operator != (const Ratio &that) const { return (n != that.n || d != that.d); }
    double realVal() const { return double(n) / d; }
};

int main() {
	int n;
	scanf("%d", &n);
	//for (int i = 1; i <= n; ++i) s << i;
	//pgen();
	//for (int i = 1; i <= n; ++i) printf("%d ", x[i]);
	//printf("\n");

	for (int i = 0; i < n; ++i) {
		scanf("%d", a + i);
		s[i + 1] = s[i] + a[i];
	}
	int64 sum = 0;
	for (int i = 0; i < n; ++i) {
		sum += (i + 1) * a[i] - s[i];
	}
	sum *= 2;
	sum -= s[n];
	sum *= 2;
	Ratio<int64> x(sum);
	for (int i = 2; i <= n; ++i) {
		x = x / i;
	}
	cout << x.n << " " << x.d << endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#define Eo(x) do { cerr << #x << " = " << (x) << endl; } while (0)
#define E(x) do { cerr << #x << " = " << (x) << " "; } while (0)
#undef assert
#define assert(x) if(x);else{fprintf(stderr, "%s:%d: assertion %s failed\n", __FILE__, __LINE__, #x); abort();}
#else
#define Eo(x)
#define E(x)
#endif
#define Sz(x) (int((x).size()))
#define All(x) (x).begin(),(x).end()

template<class A, class B> ostream &operator<<(ostream &os, const pair<A, B>& p) { return os << '(' << p.first << ", " << p.second << ')'; }
template<class T> void operator<<(vector<T> &v, const T &x){v.push_back(x);}
template<class T> void operator>>(vector<T> &v, T &x){assert(!v.empty()); x=v.back(); v.pop_back();}
template<class T> void operator<<(set<T> &v, const T &x){v.insert(x);}
template<class T> void operator>>(set<T> &v, T &x){assert(!v.empty()); x=*v.begin(); v.erase(v.begin());}

typedef long long int64;
typedef pair<int, int> pii;

const int INF = 0x3F3F3F3F;
const double EPS = 1e-8;
const double PI = acos(-1.0);

const int N = 100100;
int a[N];

int64 s[N];

template <typename T>
struct Ratio {

    T n, d;
    Ratio(T n0 = T(), T d0 = T(1)) {
        T g = abs(__gcd(n0, d0));
        if (d0 < 0) g *= -1;
        n = n0 / g;
        d = d0 / g;
    }
    Ratio operator + (const Ratio &that) const { return Ratio(n * that.d + that.n * d, d * that.d); }
    Ratio operator - (const Ratio &that) const { return Ratio(n * that.d - that.n * d, d * that.d); }
    Ratio operator * (const Ratio &that) const { return Ratio(n * that.n, d * that.d); }
    Ratio operator / (const Ratio &that) const { return Ratio(n * that.d, d * that.n); }
    bool operator < (const Ratio &that) const { Ratio diff = *this - that; return (diff.n < 0); }
    bool operator <= (const Ratio &that) const { Ratio diff = *this - that; return (diff.n <= 0); }
    bool operator == (const Ratio &that) const { return (n == that.n && d == that.d); }
    bool operator != (const Ratio &that) const { return (n != that.n || d != that.d); }
    double realVal() const { return double(n) / d; }
};

int main() {
	int n;
	scanf("%d", &n);
	//for (int i = 1; i <= n; ++i) s << i;
	//pgen();
	//for (int i = 1; i <= n; ++i) printf("%d ", x[i]);
	//printf("\n");

	for (int i = 0; i < n; ++i) {
		scanf("%d", a + i);
		s[i + 1] = s[i] + a[i];
	}
	int64 sum = 0;
	for (int i = 1; i < n; ++i) {
		sum += i * a[i] - s[i];
	}
Eo(sum);
	sum *= 2;
Eo(sum);
	sum += s[n];
Eo(sum);
	Ratio<int64> x(sum);
	//for (int i = 2; i <= n; ++i) {
		x = x / n;
	//}
	cout << x.n << " " << x.d << endl;
    return 0;
}


//nathanajah's template
//28-11-2012
#include <stdio.h>
#include <iostream>
#include <stdlib.h>
#include <math.h>
#include <string>
#include <string.h>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <deque>
#include <map>
#include <ctime>
#define ii pair<int,int>
#define vi vector<int>
#define vii vector<ii>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define LL long long
#define ULL unsigned LL
#define INF 0x3FFFFFFF
#define INFLL 0x3FFFFFFFFFFFFFFF
#define SZ(a) (int)(a).size()
#define ALL(a) (a).begin(),(a).end()
#ifdef DEBUG
	#define debug(...) \
	fprintf(stderr,__VA_ARGS__)
#else
	#define debug(...)
#endif
using namespace std;

inline string GetString()
{
	char GS[1000005];
	scanf("%s",GS);string ret=GS;
	return ret;
}

inline char getc()
{
	char c=' ';
	while (c==' ' || c=='\t' || c=='\r' || c=='\n')
		c=getchar();
	return c;
}
//ENDOFTEMPLATE

int n,i;
LL arr[1000005];
LL num=0;
int main()
{
	scanf("%d",&n);
	for (i=0;i<n;++i)
		scanf("%I64d",&arr[i]);
	sort(arr,arr+n);
	for (i=0;i<(n-1);++i) {
		LL baru=arr[i+1]-arr[i];
		LL banyak=(i+1)*(n-(i+1));
		num+=banyak*baru*2LL;
	}
	for (i=0;i<n;++i)
		num+=arr[i];
	LL den=n;
	LL gcd=__gcd(den,num);
	num/=gcd;
	den/=gcd;
	printf("%I64d %I64d\n",num,den);
}


//nathanajah's template
//28-11-2012
#include <stdio.h>
#include <iostream>
#include <stdlib.h>
#include <math.h>
#include <string>
#include <string.h>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <deque>
#include <map>
#include <ctime>
#define ii pair<int,int>
#define vi vector<int>
#define vii vector<ii>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define LL long long
#define ULL unsigned LL
#define INF 0x3FFFFFFF
#define INFLL 0x3FFFFFFFFFFFFFFF
#define SZ(a) (int)(a).size()
#define ALL(a) (a).begin(),(a).end()
#ifdef DEBUG
	#define debug(...) \
	fprintf(stderr,__VA_ARGS__)
#else
	#define debug(...)
#endif
using namespace std;

inline string GetString()
{
	char GS[1000005];
	scanf("%s",GS);string ret=GS;
	return ret;
}

inline char getc()
{
	char c=' ';
	while (c==' ' || c=='\t' || c=='\r' || c=='\n')
		c=getchar();
	return c;
}
//ENDOFTEMPLATE

int n,i;
LL arr[100005];
LL num=0;
int main()
{
	scanf("%d",&n);
	for (i=0;i<n;++i)
		scanf("%I64d",&arr[i]);
	sort(arr,arr+n);
	for (i=0;i<(n-1);++i) {
		LL baru=arr[i+1]-arr[i];
		LL banyak=(i+1)*(n-(i+1));
		num+=banyak*baru*2LL;
	}
	for (i=0;i<n;++i)
		num+=arr[i];
	LL den=n;
	LL gcd=__gcd(den,num);
	num/=gcd;
	den/=gcd;
	printf("%I64d %I64d\n",num,den);
}


//nathanajah's template
//28-11-2012
#include <stdio.h>
#include <iostream>
#include <stdlib.h>
#include <math.h>
#include <string>
#include <string.h>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <deque>
#include <map>
#include <ctime>
#define ii pair<int,int>
#define vi vector<int>
#define vii vector<ii>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define LL long long
#define ULL unsigned LL
#define INF 0x3FFFFFFF
#define INFLL 0x3FFFFFFFFFFFFFFF
#define SZ(a) (int)(a).size()
#define ALL(a) (a).begin(),(a).end()
#ifdef DEBUG
	#define debug(...) \
	fprintf(stderr,__VA_ARGS__)
#else
	#define debug(...)
#endif
using namespace std;

inline string GetString()
{
	char GS[1000005];
	scanf("%s",GS);string ret=GS;
	return ret;
}

inline char getc()
{
	char c=' ';
	while (c==' ' || c=='\t' || c=='\r' || c=='\n')
		c=getchar();
	return c;
}
//ENDOFTEMPLATE

LL n,i;
LL arr[100005];
LL num=0;
int main()
{
	scanf("%I64d",&n);
	for (i=0;i<n;++i)
		scanf("%I64d",&arr[i]);
	sort(arr,arr+n);
	for (i=0;i<(n-1);++i) {
		LL baru=arr[i+1]-arr[i];
		LL banyak=(i+1)*(n-(i+1));
		num+=banyak*baru*2LL;
	}
	for (i=0;i<n;++i)
		num+=arr[i];
	LL den=n;
	LL gcd=__gcd(den,num);
	num/=gcd;
	den/=gcd;
	printf("%I64d %I64d\n",num,den);
}


//nathanajah's template
//28-11-2012
#include <stdio.h>
#include <iostream>
#include <stdlib.h>
#include <math.h>
#include <string>
#include <string.h>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <deque>
#include <map>
#include <ctime>
#define ii pair<int,int>
#define vi vector<int>
#define vii vector<ii>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define LL long long
#define ULL unsigned LL
#define INF 0x3FFFFFFF
#define INFLL 0x3FFFFFFFFFFFFFFF
#define SZ(a) (int)(a).size()
#define ALL(a) (a).begin(),(a).end()
#ifdef DEBUG
	#define debug(...) \
	fprintf(stderr,__VA_ARGS__)
#else
	#define debug(...)
#endif
using namespace std;

inline string GetString()
{
	char GS[1000005];
	scanf("%s",GS);string ret=GS;
	return ret;
}

inline char getc()
{
	char c=' ';
	while (c==' ' || c=='\t' || c=='\r' || c=='\n')
		c=getchar();
	return c;
}
//ENDOFTEMPLATE

int n,i;
LL arr[1000005];
LL num=0;
int main()
{
	scanf("%d",&n);
	for (i=0;i<n;++i)
		scanf("%I64d",&arr[i]);
	sort(arr,arr+n);
	for (i=0;i<(n-1);++i) {
		LL baru=arr[i+1]-arr[i];
		LL banyak=(i+1)*(n-(i+1));
		num+=banyak*baru*2;
	}
	for (i=0;i<n;++i)
		num+=arr[i];
	LL den=n;
	LL gcd=__gcd(den,num);
	num/=gcd;
	den/=gcd;
	printf("%I64d %I64d\n",num,den);
}


#include<cstdio>
#include<iostream>
#include<cassert>
#include<algorithm>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<queue>
#include<set>
using namespace std;
typedef vector<int> VI;
typedef long long LL;
#define FOR(x, b, e) for(int x=b; x<=(e); ++x)
#define FORD(x, b, e) for(int x=b; x>=(e); --x)
#define REP(x, n) for(int x=0; x<(n); ++x)
#define VAR(v,n) __typeof(n) v=(n)
#define ALL(c) c.begin(),c.end()
#define SIZE(x) (int)x.size()
#define FOREACH(i,c) for(VAR(i,(c).begin());i!=(c).end();++i)
#define MP make_pair
#define PB push_back
#define ST first
#define ND second

const int MAXN=100010;

int n;
int a[MAXN];

void readData(){
    scanf("%d", &n);
    REP(i,n){
        scanf("%d", a + i);
    }
}

int nwd(LL a, LL b){
    if (a == 0) return (int)b;
    if (b == 0) return (int)a;
    return (nwd(max(a,b)%min(a,b), min(a,b)));
}

void solve(){
    LL s = 0;
    LL res = 0;
    REP(i,n){
        res += ( (LL)i * a[i] );
        res -= s;
        s += (LL)a[i];
    }
    res *= 2;
    res += s;
    int nw = nwd(res, n);
    res = res/nw;
    n = n/nw;
    printf("%d %d\n",(int)res, (int)n);
}

int main(){
    readData(); solve();
}


#include<cstdio>
#include<iostream>
#include<cassert>
#include<algorithm>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<queue>
#include<set>
using namespace std;
typedef vector<int> VI;
typedef long long LL;
#define FOR(x, b, e) for(int x=b; x<=(e); ++x)
#define FORD(x, b, e) for(int x=b; x>=(e); --x)
#define REP(x, n) for(int x=0; x<(n); ++x)
#define VAR(v,n) __typeof(n) v=(n)
#define ALL(c) c.begin(),c.end()
#define SIZE(x) (int)x.size()
#define FOREACH(i,c) for(VAR(i,(c).begin());i!=(c).end();++i)
#define MP make_pair
#define PB push_back
#define ST first
#define ND second

const int MAXN=100010;

int n;
int a[MAXN];

void readData(){
    scanf("%d", &n);
    REP(i,n){
        scanf("%d", a + i);
    }
    sort(a, a + n);
}

int nwd(LL a, LL b){
    if (a == 0) return (int)b;
    if (b == 0) return (int)a;
    return (nwd(max(a,b)%min(a,b), min(a,b)));
}

void solve(){
    LL s = 0;
    LL res = 0;
    REP(i,n){
        res += ( i * a[i] );
        res -= s;
        s += a[i];
    }
    res *= 2;
    res += s;
    int nw = nwd(res, n);
    res = res/nw;
    n = n/nw;
    printf("%d %d\n",(int)res, (int)n);
}

int main(){
    readData(); solve();
}


#include<cstdio>
#include<iostream>
#include<cassert>
#include<algorithm>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<queue>
#include<set>
using namespace std;
typedef vector<int> VI;
typedef long long LL;
#define FOR(x, b, e) for(int x=b; x<=(e); ++x)
#define FORD(x, b, e) for(int x=b; x>=(e); --x)
#define REP(x, n) for(int x=0; x<(n); ++x)
#define VAR(v,n) __typeof(n) v=(n)
#define ALL(c) c.begin(),c.end()
#define SIZE(x) (int)x.size()
#define FOREACH(i,c) for(VAR(i,(c).begin());i!=(c).end();++i)
#define MP make_pair
#define PB push_back
#define ST first
#define ND second

const int MAXN=100010;

int n;
int a[MAXN];

void readData(){
    scanf("%d", &n);
    REP(i,n){
        scanf("%d", a + i);
    }
    sort(a, a + n);
}

LL nwd(LL a, LL b){
    if (a == 0) return (int)b;
    if (b == 0) return (int)a;
    return (nwd(max(a,b)%min(a,b), min(a,b)));
}

void solve(){
    LL s = 0;
    LL res = 0;
    REP(i,n){
        res += ( (LL)(i + 1) * a[i] );
        res -= s;
        s += (LL)a[i];
    }
    res *= 2;
    res -= s;
    LL nw = nwd(res, n);
    res = res/nw;
    n = n/nw;
    cout<<res << ' ' << n << endl;
}

int main(){
    readData(); solve();
}


#include<cstdio>
#include<iostream>
#include<cassert>
#include<algorithm>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<queue>
#include<set>
using namespace std;
typedef vector<int> VI;
typedef long long LL;
#define FOR(x, b, e) for(int x=b; x<=(e); ++x)
#define FORD(x, b, e) for(int x=b; x>=(e); --x)
#define REP(x, n) for(int x=0; x<(n); ++x)
#define VAR(v,n) __typeof(n) v=(n)
#define ALL(c) c.begin(),c.end()
#define SIZE(x) (int)x.size()
#define FOREACH(i,c) for(VAR(i,(c).begin());i!=(c).end();++i)
#define MP make_pair
#define PB push_back
#define ST first
#define ND second

const int MAXN=100010;

int n;
int a[MAXN];

void readData(){
    scanf("%d", &n);
    REP(i,n){
        scanf("%d", a + i);
    }
    sort(a, a + n);
}

int nwd(LL a, LL b){
    if (a == 0) return (int)b;
    if (b == 0) return (int)a;
    return (nwd(max(a,b)%min(a,b), min(a,b)));
}

void solve(){
    LL s = 0;
    LL res = 0;
    REP(i,n){
        res += ( (LL)(i + 1) * a[i] );
        res -= s;
        s += (LL)a[i];
    }
    res *= 2;
    res -= s;
    LL nw = nwd(res, n);
    res = res/nw;
    n = n/nw;
    printf("%I64d %I64d\n",(int)res, (int)n);
}

int main(){
    readData(); solve();
}


#include<cstdio>
#include<iostream>
#include<cassert>
#include<algorithm>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<queue>
#include<set>
using namespace std;
typedef vector<int> VI;
typedef long long LL;
#define FOR(x, b, e) for(int x=b; x<=(e); ++x)
#define FORD(x, b, e) for(int x=b; x>=(e); --x)
#define REP(x, n) for(int x=0; x<(n); ++x)
#define VAR(v,n) __typeof(n) v=(n)
#define ALL(c) c.begin(),c.end()
#define SIZE(x) (int)x.size()
#define FOREACH(i,c) for(VAR(i,(c).begin());i!=(c).end();++i)
#define MP make_pair
#define PB push_back
#define ST first
#define ND second

const int MAXN=100010;

int n;
int a[MAXN];

void readData(){
    scanf("%d", &n);
    REP(i,n){
        scanf("%d", a + i);
    }
}

int nwd(LL a, LL b){
    if (a == 0) return (int)b;
    if (b == 0) return (int)a;
    return (nwd(max(a,b)%min(a,b), min(a,b)));
}

void solve(){
    LL s = 0;
    LL res = 0;
    REP(i,n){
        res += ( (LL)i * a[i] );
        res -= (LL)s;
        s += (LL)a[i];
    }
    res *= 2;
    res += s;
    int nw = nwd(res, n);
    res = res/nw;
    n = n/nw;
    printf("%d %d\n",(int)res, (int)n);
}

int main(){
    readData(); solve();
}


#include<cstdio>
#include<iostream>
#include<cassert>
#include<algorithm>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<queue>
#include<set>
using namespace std;
typedef vector<int> VI;
typedef long long LL;
#define FOR(x, b, e) for(int x=b; x<=(e); ++x)
#define FORD(x, b, e) for(int x=b; x>=(e); --x)
#define REP(x, n) for(int x=0; x<(n); ++x)
#define VAR(v,n) __typeof(n) v=(n)
#define ALL(c) c.begin(),c.end()
#define SIZE(x) (int)x.size()
#define FOREACH(i,c) for(VAR(i,(c).begin());i!=(c).end();++i)
#define MP make_pair
#define PB push_back
#define ST first
#define ND second

const int MAXN=100010;

int n;
int a[MAXN];

void readData(){
    scanf("%d", &n);
    REP(i,n){
        scanf("%d", a + i);
    }
    sort(a, a + n);
}

int nwd(LL a, LL b){
    if (a == 0) return (int)b;
    if (b == 0) return (int)a;
    return (nwd(max(a,b)%min(a,b), min(a,b)));
}

void solve(){
    LL s = 0;
    LL res = 0;
    REP(i,n){
        res += ( (LL)(i + 1) * a[i] );
        res -= s;
        s += (LL)a[i];
    }
    res *= 2;
    res -= s;
    int nw = nwd(res, n);
    res = res/nw;
    n = n/nw;
    printf("%d %d\n",(int)res, (int)n);
}

int main(){
    readData(); solve();
}


#include <iostream>
#include <vector>
#include <cmath>
#include <cstdio>
#include <set>
#include <map>
#include <fstream>
#include <cstdlib>
#include <string>
#include <cstring>
#include <algorithm>

#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()

using namespace std;

long long a[200000];
long long psum[200000];

long long gcd(long long a, long long b) {
    return b == 0 ? a : gcd(b, a % b);
}

int main() {
#ifdef LOCAL_DEFINE
    freopen("input.txt", "rt", stdin);
    freopen("output.txt", "wt", stdout);
#endif

    int N;
    cin >> N;
    long long snum = 0, sden = N;
    long long mnum = 0, mden = N;
    psum[0] = 0;
    for (int i = 0; i < N; ++i) {
        cin >> a[i];
        snum += a[i];
    }
    sort(a, a + N);
    for (int i = 0; i < N; ++i) {
        psum[i + 1] = psum[i] + a[i];
    }
    for (int i = 0; i < N; ++i) {
        mnum += 2 * (i * a[i] - psum[i]);
    }
    long long rnum = snum + mnum, rden = N;
    long long g = gcd(rnum, rden);
    rnum /= g;
    rden /= g;
    cout << rnum << ' ' << rden << '\n';

    return 0;
}


#include <iostream>
#include <vector>
#include <cmath>
#include <cstdio>
#include <set>
#include <map>
#include <fstream>
#include <cstdlib>
#include <string>
#include <cstring>
#include <algorithm>

#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()

using namespace std;

long long a[200000];
long long psum[200000];

long long gcd(long long a, long long b) {
    return b == 0 ? a : gcd(b, a % b);
}

int main() {
#ifdef LOCAL_DEFINE
    freopen("input.txt", "rt", stdin);
    freopen("output.txt", "wt", stdout);
#endif

    int N;
    cin >> N;
    long long snum = 0, sden = N;
    long long mnum = 0, mden = N;
    psum[0] = 0;
    for (int i = 0; i < N; ++i) {
        cin >> a[i];
        snum += a[i];
    }
    sort(a, a + N);
    for (int i = 0; i < N; ++i) {
        psum[i + 1] = psum[i] + a[i];
    }
    for (int i = 0; i < N; ++i) {
        mnum += 2 * (i * a[i] - psum[i]);
    }
    long long rnum = snum * mden + mnum * sden, rden = mden * sden;
    long long g = gcd(rnum, rden);
    rnum /= g;
    rden /= g;
    cout << rnum << ' ' << rden << '\n';

	return 0;
}


#include <iostream>
#include <vector>
#include <cmath>
#include <cstdio>
#include <set>
#include <map>
#include <fstream>
#include <cstdlib>
#include <string>
#include <cstring>
#include <algorithm>

#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()

using namespace std;

int a[200000];
long long psum[200000];

long long gcd(long long a, long long b) {
    return b == 0 ? a : gcd(b, a % b);
}

int main() {
#ifdef LOCAL_DEFINE
    freopen("input.txt", "rt", stdin);
    freopen("output.txt", "wt", stdout);
#endif

    int N;
    cin >> N;
    long long snum = 0, sden = N;
    long long mnum = 0, mden = N;
    psum[0] = 0;
    for (int i = 0; i < N; ++i) {
        cin >> a[i];
        snum += a[i];
    }
    sort(a, a + N);
    for (int i = 0; i < N; ++i) {
        psum[i + 1] = psum[i] + a[i];
    }
    for (int i = 0; i < N; ++i) {
        mnum += 2 * (i * a[i] - psum[i]);
    }
    long long rnum = snum * mden + mnum * sden, rden = mden * sden;
    long long g = gcd(rnum, rden);
    rnum /= g;
    rden /= g;
    cout << rnum << ' ' << rden << '\n';

	return 0;
}


#include <cstdio>
#include <algorithm>

long long gcd(long long a, long long b) { return a % b? gcd(b, a % b): b; }

int N;
int arr[100001];
long long sum = 0;

int main() {
    scanf("%d", &N);
    for (int i = 0; i < N; ++i)
        scanf("%d", &arr[i]);
    std::sort(arr, arr + N);
    long long now = arr[0];
    for (int i = 1; i < N; ++i)
        now += (arr[i] - arr[0]);
    for (int i = 0; i < N; ++i) {
        now += (i + 1) * (arr[i] - arr[i - 1]);
        now -= (N - i) * (arr[i] - arr[i - 1]);
        sum += now;
    }
    long long de = N;
    long long GCD = gcd(sum, de);
    printf("%I64d %I64d\n", sum / GCD, de / GCD);
}


#include <cstdio>
#include <algorithm>

long long gcd(long long a, long long b) { return a % b? gcd(b, a % b): b; }

int N;
long long arr[100001];
long long sum = 0;

int main() {
	scanf("%d", &N);
	for (int i = 0; i < N; ++i)
		scanf("%d", &arr[i]);
	std::sort(arr, arr + N);
	long long now = arr[0];
	for (int i = 1; i < N; ++i)
		now += (arr[i] - arr[0]);
	sum += now;
	for (int i = 1; i < N; ++i) {
		now += (i + 1) * (arr[i] - arr[i - 1]);
		now -= (N - i) * (arr[i] - arr[i - 1]);
		sum += now;
	}
	long long de = N;
	long long GCD = gcd(sum, de);
	printf("%I64d %I64d\n", sum / GCD, de / GCD);
}


#include <cstdio>
#include <algorithm>

long long gcd(long long a, long long b) { return a % b? gcd(b, a % b): b; }

int N;
int arr[100001];
long long sum = 0;

int main() {
	scanf("%d", &N);
	for (int i = 0; i < N; ++i)
		scanf("%d", &arr[i]);
	std::sort(arr, arr + N);
	long long now = arr[0];
	for (int i = 1; i < N; ++i)
		now += (arr[i] - arr[0]);
	sum += now;
	for (int i = 1; i < N; ++i) {
		now += (i + 1) * (arr[i] - arr[i - 1]);
		now -= (N - i) * (arr[i] - arr[i - 1]);
		sum += now;
	}
	long long de = N;
	long long GCD = gcd(sum, de);
	printf("%I64d %I64d\n", sum / GCD, de / GCD);
}


#include <cstdio>

long long gcd(long long a, long long b) { return a % b? gcd(b, a % b): b; }

int N;
int arr[100001];
long long sum = 0;

int main() {
    scanf("%d", &N);
    long long now = 0;
    for (int i = 0; i < N; ++i) {
        scanf("%d", &arr[i]);
        if (i == 0) now = arr[0];
        else now += (arr[i] - arr[0]);
    }
    sum += now;
    for (int i = 1; i < N; ++i) {
        now += (i + 1) * (arr[i] - arr[i - 1]);
        now -= (N - i) * (arr[i] - arr[i - 1]);
        sum += now;
    }
    long long de = N;
    long long GCD = gcd(sum, de);
    printf("%I64d %I64d\n", sum / GCD, de / GCD);
}


#include <cstdio>
#include <algorithm>

long long gcd(long long a, long long b) { return a % b? gcd(b, a % b): b; }

int N;
int arr[100001];
long long sum = 0;

int main() {
    scanf("%d", &N);
    for (int i = 0; i < N; ++i)
        scanf("%d", &arr[i]);
    std::sort(arr, arr + N);
    long long now = arr[0];
    for (int i = 1; i < N; ++i)
        now += (arr[i] - arr[0]);
    sum += now;
    for (int i = 0; i < N; ++i) {
        now += (i + 1) * (arr[i] - arr[i - 1]);
        now -= (N - i) * (arr[i] - arr[i - 1]);
        sum += now;
    }
    long long de = N;
    long long GCD = gcd(sum, de);
    printf("%I64d %I64d\n", sum / GCD, de / GCD);
}


#include <cstdlib>
#include <iostream>
#include <cmath>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <map>
using namespace std;
int n;
long long sum[100010];
int a[100010];
long long tot=0;
long long gcd(long long a,long long b){
long long r;
while(b>0){
r=a%b;
a=b;
b=r;
}
return a;
}
int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
   // cout<<6*8/gcd(6,8)<<endl;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        int t;
        cin>>t;
        tot+=t;
        a[i]=t;
    }
    sort(a+1,a+1+n);
    long long  cnt=0;
    long long hei=tot;
    for(int i=1;i<=n;i++)
    {
        long long temp=hei-a[i]*(n-i+1);
        hei-=a[i];
        cnt+=temp;
    }
    //fz+=cnt*A(n-2,n-2)*2;
    long long fz1=cnt*(n-1)*2,fz2=tot;
    long long fm1=(n-1)*n,fm2=n;//A(n,n);
    long long g=gcd(fz1,fm1);
    fz1/=g,fm1/=g;
   // cout<<fz2<<" "<<fm2<<endl;
    g=gcd(fz2,fm2);

    fz2/=g,fm2/=g;

    /*for(long long i=1;i<=n;i++)
    {
        fm2*=i;
        g=gcd(fz2,fm2);
        fz2/=g,fm2/=g;
    }*/

    g=fm1*fm2/gcd(fm1,fm2);
    fz1*=g/fm1;
    fz2*=g/fm2;
    fz1+=fz2;
    fm1=g;
    g=gcd(fz1,g);
    fz1/=g;
    fm1/=g;
    cout<<fz1<<" "<<fm1<<endl;
    return 0;
}


#include <cstdlib>
#include <iostream>
#include <cmath>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <map>
using namespace std;
int n;
long long a[100010];
long long tot=0;
long long gcd(long long a,long long b)
{
    long long r;
    while(b>0)
    {
        r=a%b;
        a=b;
        b=r;
    }
    return a;
}
int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
   // cout<<6*8/gcd(6,8)<<endl;
    cin>>n;
    int t;
    for(int i=1;i<=n;i++)
    {
        cin>>t;
        tot+=t;
        a[i]=t;
    }
    sort(a+1,a+1+n);
    long long  cnt=0;
    long long hei=tot;
    for(int i=1;i<=n;i++)
    {
        long long temp=hei-a[i]*(n-i+1);
        hei-=a[i];
        cnt+=temp;
    }
    //fz+=cnt*A(n-2,n-2)*2;
    long long fz1=cnt*2,fz2=tot;
    long long fm1=n;//A(n,n);
    fz1+=fz2;
    long long g=gcd(fz1,fm1);
    fz1/=g,fm1/=g;

   // cout<<fz2<<" "<<fm2<<endl;
   /* g=gcd(fz2,fm2);
    fz2/=g,fm2/=g;
    /*for(long long i=1;i<=n;i++)
    {
        fm2*=i;
        g=gcd(fz2,fm2);
        fz2/=g,fm2/=g;
    }

    g=fm1*fm2/gcd(fm1,fm2);
    fz1*=g/fm1;
    fz2*=g/fm2;
    fz1+=fz2;
    fm1=g;
    g=gcd(fz1,g);
    fz1/=g;
    fm1/=g;*/
    cout<<fz1<<" "<<fm1<<endl;
    return 0;
}


#include <cstdlib>
#include <iostream>
#include <cmath>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <map>
using namespace std;
int n;
long long sum[100010];
int a[100010];
long long tot=0;
long long gcd(long long a,long long b){
long long r;
while(b>0){
r=a%b;
a=b;
b=r;
}
return a;
}
int main()
{
   // freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
   // cout<<6*8/gcd(6,8)<<endl;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        int t;
        cin>>t;
        tot+=t;
        a[i]=t;
    }
    sort(a+1,a+1+n);
    long long  cnt=0;
    long long hei=tot;
    for(int i=1;i<=n;i++)
    {
        long long temp=hei-a[i]*(n-i+1);
        hei-=a[i];
        cnt+=temp;
    }
    //fz+=cnt*A(n-2,n-2)*2;
    long long fz1=cnt*2,fz2=tot;
    long long fm1=n,fm2=n*(n-1);//A(n,n);
    fz1+=fz2;
    long long g=gcd(fz1,fm1);
    fz1/=g,fm1/=g;

   // cout<<fz2<<" "<<fm2<<endl;
   /* g=gcd(fz2,fm2);
    fz2/=g,fm2/=g;
    /*for(long long i=1;i<=n;i++)
    {
        fm2*=i;
        g=gcd(fz2,fm2);
        fz2/=g,fm2/=g;
    }

    g=fm1*fm2/gcd(fm1,fm2);
    fz1*=g/fm1;
    fz2*=g/fm2;
    fz1+=fz2;
    fm1=g;
    g=gcd(fz1,g);
    fz1/=g;
    fm1/=g;*/
    cout<<fz1<<" "<<fm1<<endl;
    return 0;
}


#include <cstdlib>
#include <iostream>
#include <cmath>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <map>
using namespace std;
int n;
long long sum[100010];
int a[100010];
long long tot=0;
long long gcd(long long a,long long b){
long long r;
while(b>0){
r=a%b;
a=b;
b=r;
}
return a;
}
int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
   // cout<<6*8/gcd(6,8)<<endl;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        int t;
        cin>>t;
        tot+=t;
        a[i]=t;
    }
    sort(a+1,a+1+n);
    long long  cnt=0;
    long long hei=tot;
    for(int i=1;i<=n;i++)
    {
        long long temp=hei-a[i]*(n-i+1);
        hei-=a[i];
        cnt+=temp;
    }
    //fz+=cnt*A(n-2,n-2)*2;
    long long fz1=cnt*(n-1)*2,fz2=tot*2;
    long long fm1=(n-1)*n,fm2=2;//A(n,n);
    long long g=gcd(fz1,fm1);
    fz1/=g,fm1/=g;
    fm2=1;
    for(long long i=1;i<=n;i++)
    {
        fm2*=i;
        g=gcd(fz2,fm2);
        fz2/=g,fm2/=g;
    }
    g=fm1*fm2/gcd(fm1,fm2);
    fz1*=g/fm1;
    fz2*=g/fm2;
    fz1+=fz2;
    fm1=g;
    g=gcd(fz1,g);
    fz1/=g;
    fm1/=g;
    cout<<fz1<<" "<<fm1<<endl;
    return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <math.h>
#include <assert.h>
#include <vector>
#include <queue>
#include <string>
#include <map>
#include <set>

using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define FORIT(it, c) for (__typeof((c).begin())it = (c).begin(); it != (c).end(); it++)
#define MEMSET(v, h) memset((v), h, sizeof(v))
#define PB push_back
#define GU(a, b) if ((a)>(b)) (b)=(a);
#define SU(a, b) if ((a)<(b)) (b)=(a);
#define MID(l, r) (((l)+(r))>>1)

inline int lowbit(int x) { return x&(-x); }
inline ll mgcd(ll x, ll y) { return y?mgcd(y, x%y):x; }

typedef pair<int, int> Range;
#define lt first
#define rt second
inline bool in(int p, Range r) { return p>=r.lt&&p<=r.rt; }
inline bool in(Range r1, Range r2) { return r1.lt>=r2.lt&&r1.rt<=r2.rt; }
inline int mid(Range rg) { return MID(rg.lt, rg.rt); }
Range shift(bool d, Range rg) {
	return d?Range(mid(rg)+1, rg.rt):Range(rg.lt, mid(rg));
}

ll n, a[100005], sum, suma, x, y, m;
int ta[100005];

int main() {
	cin>>n;
	sum=suma=0;
	REP(i,n) {
		scanf("%d",&ta[i]);
		a[i]=ta[i];
		suma+=a[i];
		if (i) sum+=sum+(a[i]-a[i-1])*((bool(sum))+1);
	}
	x=sum*4+suma*(n-1);
	if (n==2) x-=sum*2;
	y=n*(n-1);
	m=mgcd(x,y); x/=m; y/=m;
	cout<<x<<" "<<y<<endl;

	return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <math.h>
#include <assert.h>
#include <vector>
#include <queue>
#include <string>
#include <map>
#include <set>

using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define FORIT(it, c) for (__typeof((c).begin())it = (c).begin(); it != (c).end(); it++)
#define MEMSET(v, h) memset((v), h, sizeof(v))
#define PB push_back
#define GU(a, b) if ((a)>(b)) (b)=(a);
#define SU(a, b) if ((a)<(b)) (b)=(a);
#define MID(l, r) (((l)+(r))>>1)

inline int lowbit(int x) { return x&(-x); }
inline ll mgcd(ll x, ll y) { return y?mgcd(y, x%y):x; }

typedef pair<int, int> Range;
#define lt first
#define rt second
inline bool in(int p, Range r) { return p>=r.lt&&p<=r.rt; }
inline bool in(Range r1, Range r2) { return r1.lt>=r2.lt&&r1.rt<=r2.rt; }
inline int mid(Range rg) { return MID(rg.lt, rg.rt); }
Range shift(bool d, Range rg) {
	return d?Range(mid(rg)+1, rg.rt):Range(rg.lt, mid(rg));
}

ll n, a[100005], sumt[100005], sum, suma, x, y, m;
int ta[100005];

int main() {
	cin>>n;
	sum=suma=0;
	REP(i,n) scanf("%d",&ta[i]);
	sort(ta,ta+n);
	REP(i,n) {
		a[i]=ta[i];
		suma+=a[i];
		if (i) {
		  sumt[i]=sumt[i-1]+(a[i]-a[i-1])*i;
		  sum+=sumt[i];
    }
	}
	x=sum*2+suma;
	if (n==2) x-=sum;
	y=n;
	m=mgcd(x,y); x/=m; y/=m;
	cout<<x<<" "<<y<<endl;

	return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <math.h>
#include <assert.h>
#include <vector>
#include <queue>
#include <string>
#include <map>
#include <set>

using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define FORIT(it, c) for (__typeof((c).begin())it = (c).begin(); it != (c).end(); it++)
#define MEMSET(v, h) memset((v), h, sizeof(v))
#define PB push_back
#define GU(a, b) if ((a)>(b)) (b)=(a);
#define SU(a, b) if ((a)<(b)) (b)=(a);
#define MID(l, r) (((l)+(r))>>1)

inline int lowbit(int x) { return x&(-x); }
inline ll mgcd(ll x, ll y) { return y?mgcd(y, x%y):x; }

typedef pair<int, int> Range;
#define lt first
#define rt second
inline bool in(int p, Range r) { return p>=r.lt&&p<=r.rt; }
inline bool in(Range r1, Range r2) { return r1.lt>=r2.lt&&r1.rt<=r2.rt; }
inline int mid(Range rg) { return MID(rg.lt, rg.rt); }
Range shift(bool d, Range rg) {
	return d?Range(mid(rg)+1, rg.rt):Range(rg.lt, mid(rg));
}

ll n, a[100005], sumt[100005], sum, suma, x, y, m;
int ta[100005];

int main() {
	cin>>n;
	sum=suma=0;
	REP(i,n) scanf("%d",&ta[i]);
	sort(ta,ta+n);
	REP(i,n) {
		a[i]=ta[i];
		suma+=a[i];
		if (i) {
		  sumt[i]=sumt[i-1]+(a[i]-a[i-1])*i;
		  sum+=sumt[i];
    }
	}
	x=sum*2+suma;
	//if (n==2) x-=sum;
	y=n;
	m=mgcd(x,y); x/=m; y/=m;
	cout<<x<<" "<<y<<endl;

	return 0;
}


#include<bits/stdc++.h>

using namespace std;

typedef long long LL;
typedef unsigned long long uLL;
typedef long double ldb;
typedef pair<int,int> pii;

int A[100000];

LL gcd(LL x, LL y)
{
    return y ? gcd(y, x%y) : x;
}

int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);
    int n;
    LL num=0, denum;
    cin>>n;
    denum = n;
    for(int i = 0; i < n; ++i)
    {
        cin>>A[i];
        num += A[i];
    }
    sort(A, A+n);
    for(int i = 1; i < n; ++i)
        num += LL(i)*LL(n-i)*2LL*LL(A[i]-A[i-1]);
    LL g = gcd(num, denum);
    num /= g;
    denum /= g;
    cout<<num<<' '<<denum<<endl;
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

typedef long long LL;
typedef unsigned long long uLL;
typedef long double ldb;
typedef pair<int,int> pii;

int A[100000];

int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);
    int n;
    LL num=0, denum;
    cin>>n;
    denum = n;
    for(int i = 0; i < n; ++i)
    {
        cin>>A[i];
        num += A[i];
    }
    for(int i = 1; i < n; ++i)
        num += LL(i)*LL(n-i)*2LL*LL(A[i]-A[i-1]);
    LL gcd = __gcd(num, denum);
    num /= gcd;
    denum /= gcd;
    cout<<num<<' '<<denum<<endl;
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

typedef long long LL;
typedef unsigned long long uLL;
typedef long double ldb;
typedef pair<int,int> pii;

int A[100000];

int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);
    int n;
    LL num=0, denum;
    cin>>n;
    denum = n;
    for(int i = 0; i < n; ++i)
    {
        cin>>A[i];
        num += A[i];
    }
    for(int i = 1; i < n; ++i)
        num += LL(i)*(n-i)*2*(A[i]-A[i-1]);
    LL gcd = __gcd(num, denum);
    num /= gcd;
    denum /= gcd;
    cout<<num<<' '<<denum<<endl;
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

typedef long long LL;
typedef unsigned long long uLL;
typedef long double ldb;
typedef pair<int,int> pii;

int A[100000];

LL gcd(LL x, LL y)
{
    return y ? gcd(y, x%y) : x;
}

int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);
    int n;
    LL num=0, denum;
    cin>>n;
    denum = n;
    for(int i = 0; i < n; ++i)
    {
        cin>>A[i];
        num += A[i];
    }
    for(int i = 1; i < n; ++i)
        num += LL(i)*LL(n-i)*2LL*LL(A[i]-A[i-1]);
    LL g = gcd(num, denum);
    num /= g;
    denum /= g;
    cout<<num<<' '<<denum<<endl;
    return 0;
}


//============================================================================
// Name : firstTrial.cpp
// Author :
// Version :
// Copyright : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <bits/stdc++.h>
#define io  ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define file freopen("INPUT.txt", "r", stdin), freopen("OUTPUT.txt", "w", stdout);
using namespace std;
const int N = 1e5 + 20;
int arr[N];
int main(){
    io;
	long long int n;
	cin >> n;
	for(int i = 0; i < n; i++)
		cin >> arr[i];
	sort(arr, arr + n);
	reverse(arr, arr + n);
	long long int tot = arr[0], ans = 0;
	for(int i = 1; i < n; i++){
		//((tot - (i * arr[i])) * 2 * (n - 2 + 1) * (n - 2)!) / (n)!
		//((tot - (i * arr[i])) * 2 * (n - 1)) / (n * (n - 1))
		//((tot - (i * arr[i])) * 2) / (n)
		ans += (tot - (1ll * i * arr[i])) * 2;
		tot += arr[i];
	}
	ans += tot;
	if(__gcd(ans, n) == 1)
		cout << ans << ' ' << n << endl;
	else
		cout << ans / __gcd(ans, n) << ' ' << n / __gcd(ans, n) << endl;
	return 0;
}


#include<bits/stdc++.h>
#define long long long
using namespace std;
const int N=1e6;
int aa[N+2];
int main()
{
  ios_base::sync_with_stdio(0);cin.tie(0);
  int n;cin>>n;long sm=0,tt=0;
  for(int i=1;i<=n;i++)cin>>aa[i],sm+=aa[i]*1LL;
  sort(aa+1,aa+n+1);

  tt=sm;
  for(int i=1;i<=n;i++)
  {
    sm-=((aa[i]-aa[i-1])*1LL)*(n-i+1);
    tt+=sm*2;
  }
  long gc=__gcd(tt,n*1LL);
  cout<<tt/gc<<" "<<n/gc<<endl;
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long double ld;
typedef long long ll;
#define int ll

typedef pair<int,int> pii;
#define x first
#define y second

typedef pair<int,int> frac;
#define num first
#define den second

frac norm(frac a)
{
    int g=__gcd(a.num,a.den);
    a.num/=g;
    a.den/=g;
    if(a.den<0)
        a.num*=-1,
        a.den*=-1;
    return a;
}

frac add(frac a,frac b)
{
    a=norm(a);
    b=norm(b);
    int den=a.den/__gcd(a.den,b.den)*b.den;
    a.num*=den/a.den;
    b.num*=den/b.den;
    return norm(frac(a.num+b.num,den));
}

const int N=1e5+100;

int a[N];

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
        cin>>a[i];
    sort(a+1,a+n+1);
    frac ans(0,1);
    for(int i=1;i<=n;i++)
    {
        ans=add(ans,frac(a[i],n));
        ans=add(ans,frac(a[i]*(n-1)*(i-1),n*(n-1)));
        ans=add(ans,frac(a[i]*(n-1)*(i-1),n*(n-1)));
        ans=add(ans,frac(-a[i]*(n-1)*(n-i),n*(n-1)));
        ans=add(ans,frac(-a[i]*(n-1)*(n-i),n*(n-1)));
    }
    cout<<ans.num<<" "<<ans.den;
}


#include <bits/stdc++.h>

#pragma GCC optimize("O2","unroll-loops")
using namespace std;
#define ll long long
#define ull unsigned long long
#define rep(i,n,N) for(int i=n;i<=N;++i)
#define rap(i,n,N) for(int i=n;i>=N;--i)
#define mp make_pair
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define fi first
#define se second
#define ff fi.fi
#define fs fi.se
#define sf se.fi
#define ss se.se
#define lc (id<<1)
#define rc ((id<<1)|1)
#define db(x) cout << ">>>>>> " << #x << " -> " << x << endl
#define all(x) x.begin(),x.end()
#define pii pair<int,int>
#define pll pair<ll,ll>
#define plll pair<ll,pll>
#define pllll pair<pll,pll>
#define piii pair<int,pii>
#define piiii pair<pii,pii>
#define psi pair<string,int>
#define endl '\n'
const int MAX = 2e5+5;
const ll MAX2 = 11;
const ll MOD = 1000000007;
const ll MOD2 = 1000000006;
const ll INF = 2e18;
const int dr[]={1,0,-1,0,1,1,-1,-1,0};
const int dc[]={0,-1,0,1,1,-1,1,-1,0};
const double pi = acos(-1);
const double EPS = 1e-9;
const int block = 316;

ll n,x[MAX],a,z,tbh,nw;

int main(){
//	cout<<fixed<<setprecision(2);
//    freopen("input.txt", "r", stdin);
//	freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin>>n;
	rep(i,1,n)cin>>x[i];
	sort(x+1,x+1+n);

	a = n*x[1];
	nw = n, tbh = n*2-3;

	rep(i,2,n){
		nw+= tbh;
		a+= (x[i]-x[i-1])*nw;
		tbh-= 4;
	}

	z = __gcd(a,n);
	cout<<a/z<<' '<<n/z<<endl;
    return 0;
}


#include <cstring>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <map>
#include <queue>
#include <vector>
#include <cmath>
#define maxn 100005
using namespace std;

typedef long long ll;
ll n,m,ans,u,v,sum;
ll a[maxn],s[maxn];

ll gcd(ll xx,ll yy)
{
    ll r=xx%yy;
    if(r==0) return yy;
    else return gcd(yy,r);
}
void solve()
{
    ll i,j,g;
    u=0;
    s[1]=0;
    for(i=2;i<=n;i++)
    {
        s[i]=s[i-1]+(i-1)*fabs(a[i]*1.0-a[i-1]);
        u+=s[i];
    }
    u=2*u+sum;
    v=n;
    g=gcd(u,v);
    u/=g;
    v/=g;
}
int main()
{
    ll i,j;
    while(~scanf("%I64d",&n))
    {
        sum=0;
        for(i=1;i<=n;i++)
        {
            scanf("%I64d",&a[i]);
            sum+=a[i];
        }
        sort(a+1,a+n+1);
        solve();
        printf("%I64d %I64d\n",u,v);
    }
    return 0;
}


// Thank you, vjudge4, for http://codeforces.com/contest/341/submission/25822002
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 5;
int a[maxn];
ll p[maxn];

int main()
{
    ll n;
    ios::sync_with_stdio(0);
    p[1] = 1;
    for(ll i = 2; i <= maxn; ++i)
    {
        p[i] = p[i - 1] * i;
    }
    while(cin >> n)
    {
        ll ans = 0, route = 0;
        for(ll i = 1; i <= n; ++i)
        {
            cin >> a[i];
            ans += a[i];
        }
        sort(a + 1, a + 1 + n);
        for(ll i = 1; i <= n; ++i)
        {
            ans += 2 * (a[i] * (i - 1) - a[i] * (n - i));
        }
        ll tmp = __gcd(ans, n);
        cout << ans / tmp << " " << n / tmp << "\n";
    }
    return 0;
}


// Thank you, vjudge5, for http://codeforces.com/contest/341/submission/25818852
#include<bits/stdc++.h>
using namespace std;
int a[100010];
long long int gcd(long long int n,long long int m)
{
    if(n%m==0)
        return(m);
    else
        return gcd(m,n%m);
}
int main()
{
    long long int n;
    cin>>n;
    long long int ma=0;
    long long int son=n;
    for(int i=1;i<=n;i++){
        scanf("%d",&a[i]);
    }
    sort(a+1,a+1+n);
    for(int i=1;i<=n;i++){
        ma+=(4*i-2*n-1)*a[i];
    }
    long long int g=gcd(ma,son);
    cout<<ma/g<<" "<<son/g<<endl;
    return 0;
}


#include <bits/stdc++.h>

#define F first
#define S second
#define mp make_pair
#define pb push_back
#define sz(x) (int)x.size()

using namespace std;

typedef long long ll;
typedef long double ld;

const int N = (int)2e5 + 123;
const int mod = (int)1e9 + 7;
const ll inf = 1e18 + 9;

inline void boost () {
	ios_base::sync_with_stdio (0);
	cin.tie (0), cout.tie (0);
}
ll n, a[N];
ll x, y, pref;

int main () {
 	boost ();
	cin >> n;
	for (int i = 1;i <= n;i ++) {
		cin >> a[i];
		x += a[i];
	}
	sort (a + 1, a + n + 1);
	for (int i = 1;i <= n;i ++) {
		y += a[i] * 1ll * (i - 1) - pref;
		pref += a[i];
	}
	ll gcd = __gcd (y + y + x, n);
	cout << (y + y + x) / gcd << ' ' << n / gcd;
	return 0;
}


#include <bits/stdc++.h>

#define F first
#define S second
#define mp make_pair
#define pb push_back
#define sz(x) (int)x.size()

using namespace std;

typedef long long ll;
typedef long double ld;

const int N = (int)2e4 + 123;
const int mod = (int)1e9 + 7;
const ll inf = 1e18 + 9;

inline void boost () {
	ios_base::sync_with_stdio (0);
	cin.tie (0), cout.tie (0);
}
ll n, a[N];
ll x, y, pref;

int main () {
 	boost ();
	cin >> n;
	for (int i = 1;i <= n;i ++) {
		cin >> a[i];
		x += a[i];
	}
	sort (a + 1, a + n + 1);
	for (int i = 1;i <= n;i ++) {
		y += a[i] * 1ll * (i - 1) - pref;
		pref += a[i];
	}
	ll gcd = __gcd (y + y + x, n);
	cout << (y + y + x) / gcd << ' ' << n / gcd;
	return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define pll pair<long long,long long>
using namespace std;

ll n,a[100010],A,s,sum;

int main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(0);

    cin >> n;
    for(int i=0; i<n; i++) cin >> a[i];
    sort( a , a+n );

    for(int i=0; i<n; i++){
        s+=i*a[i]-sum;
        sum+=a[i];
    }

    A = s+s+sum;
    cout << A/__gcd( A , n ) << " " << n/__gcd( A , n );

    return 0;
}


/**
  first of all
  we have # permutations equal to n!
  then we need to calculate the sum of distance between them
  there are some observations
  1.each element will repeat n!/n time
  2.the sum of distances between all elements will repeat (n!/n)*2
  the final answer will equal
  (1/n!)*[ n!/n * (sum of all elements) + (n!/n) * 2 * (sum of distances between all elements) ]
  simplify the equation to be equal to
  (1/n) * [ (sum of all elements) + 2 * (sum of distances between all elements) ]
  to calculate the sum of distances
  we will express each element as char after sorting in increasing order them
  a b c
  c - a +
  c - b +
  b - a
  _____
  2c - 2a
  which is equal to this form
  (sum of distances between all elements)=
 (number of elements after this number - number of elements before this number) * arr[i]
  for all i from 1 to n
*/
#include<bits/stdc++.h>
#define pb push_back
#define F first
#define S second
#define MOD 1000000007
#define rw freopen("input.txt","r",stdin),freopen("output.txt","w",stdout);
#define ll long long
#define acm ios::sync_with_stdio(0),ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
using namespace std;
ll arr[(int)1e5+5]= {};
ll GCD(ll a,ll b)
{
    if (!b)
        return a;
    return GCD(b,a%b);
}
int main()
{
    acm;
    ll n,sum1=0,sum2=0;
    cin>>n;
    for (int i=0; i<n; ++i)
        cin>>arr[i];
    sort(arr,arr+n);
    for (int i=1; i<=n; ++i)
    {
        ll x;
        x=arr[i-1];
        sum1+=x;
        sum2+=(((i-1)-(n-i))*x);
    }
    ll ans=(2*sum2)+sum1;
    ll z=GCD(ans,n);
    ans/=z;
    n/=z;
    cout<<ans<<" "<<n<<"\n";
    return 0;
}