#include<iostream> #include<algorithm> #define int long long
usingnamespacestd;
int n, k; constint maxn = 1000005; int v[maxn]; int A[maxn], a[maxn];
structnode { int id, val; } B[maxn];
int T[maxn];
intlb(int i){ return i & (-i); }
boolcmp(node a, node b){ if (a.val == b.val) return a.id < b.id; return a.val < b.val; }
voidadd(int i, int d){ while (i <= n + 100) { T[i] += d; i += lb(i); } }
intsum(int i){ int ans = 0; while (i > 0) { ans += T[i]; i -= lb(i); } return ans; }
signedmain(){ cin >> n >> k; for (int i = 1; i <= n; i ++) cin >> v[i]; sort(v + 1, v + 1 + n); int ans = 0; for (int i = 1; i <= n; i ++) { A[i] = v[i] * k / v[n]; a[i] = v[i] * k % v[n]; ans += (2 * i - 1 - n) * A[i]; B[i] = (node) {i, a[i]}; } sort(B + 1, B + 1 + n, cmp); // for (int i = 1; i <= n; i ++) cout << B[i].id << " " << B[i].val << endl; for (int i = 1; i <= n; i ++) { int p = sum(B[i].id - 1); ans -= (i - 1 - p); add(B[i].id, 1); } cout << ans << endl; return0; }