#include #include #include #include #include using namespace std; const int mod = 1e9 + 7; int main() { int n, a; cin >> n; vector num(101, 0); for (int i = 0; i < n; i++) { cin >> a; num[a]++; } int lower = 0; int mid = 0; int higher = n; long long ans = 0; for (int i = 0; i < num.size(); i++) { if (num[i] > 0) { lower += mid; mid = num[i]; higher -= num[i]; ans += 1LL * lower * mid * higher; } } ans %= mod; cout << ans << endl; return 0; }