#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define all(x) (x).begin(),(x).end() #define rep(i,m,n) for(int i = m;i < n;++i) #define pb push_back #define fore(i,a) for(auto &i:a) #define rrep(i,m,n) for(int i = m;i >= n;--i) #define INF INT_MAX/2 using namespace std; using ll = long long; using R = double; using Data = pair>; const ll MOD = 1e9 + 7; const ll inf = 1LL << 50; struct edge { ll from; ll to; ll cost; }; ll dp[5]; ll dat[110]; int main() { ll n; cin >> n; rep(i, 0, n) { int p; cin >> p; dat[p]++; } rep(i, 0, 105) { ll d1 = dp[1]; ll d2 = dp[2]; dp[1] += dat[i]; dp[2] += d1 * dat[i]; dp[3] += d2 * dat[i]; } cout << dp[3] % MOD << endl; return 0; }