#include #include #include #include using namespace std; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); uint32_t N, i; cin >> N; vector A(N); for (i = 0; i != N; ++i) cin >> A[i]; uint64_t ans = static_cast(N) * (N - 1) * (N - 2) / 6; uint32_t count = 1; sort(A.begin(), A.end()); for (i = 1; i != N; ++i) { if (A[i] != A[i - 1]) ans -= static_cast(count) * (count - 1) / 2 * (N - count) + static_cast(count) * (count - 1) * (count - 2) / 6, count = 1; else ++count; } if (A[i] != A[i - 1]) ans -= static_cast(count) * (count - 1) / 2 * (N - count) + static_cast(count) * (count - 1) * (count - 2) / 6; cout << ans % 1'000'000'007 << '\n'; return 0; }