#include using namespace std; #define REP(i,n) for(int i=0; i<(int)(n); i++) const long long MOD = 1e9 + 7; int main() { ios_base::sync_with_stdio(0); cin.tie(0); long long n; cin >> n; long long ret = n * (n-1) * (n-2) / 6; vector hist(101); REP (i, n) { int a; cin >> a; hist[a]++; } REP (i, 101) { long long h = hist[i]; if (h >= 2) ret -= h * (h-1) / 2 * (n - h); if (h >= 3) ret -= h * (h-1) * (h-2) / 6; } cout << ret % MOD << endl; return 0; }