#include using namespace std; typedef long long ll; int main(void) { #ifdef DEBUG freopen("input.txt", "r", stdin); #endif ios_base::sync_with_stdio(false); cin.tie(NULL); long N; cin >> N; int A[N]; for (int i = 0; i < N; i++) { cin >> A[i]; } map mp; for (int i = 0; i < N; i++) { mp[A[i]]++; } long cnt, mod; mod = 1000000007; cnt = (N * (N - 1) * (N - 2)) / 6; for (auto itr = mp.begin(); itr != mp.end(); ++itr) { long n = itr->second; if (n > 2) cnt -= (n * (n - 1) * (n - 2)) / 6; if (n > 1) cnt -= (n * (n - 1)) / 2 * (N - n); } cout << cnt % mod << endl; return 0; }