#include using namespace std; const int MOD = 1000000007; int main(){ int n,in,ans=1; map mp; cin >> n; while(cin>>in) mp[in]++; for(int i=0;i<3;i++) (ans*=(mp.size()-i))%=MOD; (ans/=6)%=MOD; for(auto iter=mp.begin();iter!=mp.end();iter++) (ans*=(iter->second))%=MOD; cout << ans << endl; return 0; }