#include #include #include using namespace std; #define MOD 1000000007 typedef long long ll; int main(){ int n, tmp; cin >> n; map a; set b; for(int i = 0; i < n; i++){ cin >> tmp; a[tmp]++; b.insert(tmp); } ll size = a.size(); if(size < 3){ cout << 0 << endl; return 0; } ll ans = (size*(size-1)/2*(size-2)/3)%MOD; for(set::iterator it = b.begin(); it != b.end(); it++){ ll times = a[(*it)]; if(times > 1){ ans = (times * ans)%MOD; } } cout << ans << endl; return 0; }