#include using namespace std; int ok( int x, int y, int z ){ return 1; return min( { x, y, z } ) == y or max( { x, y, z } ) == y; } const int MOD7 = ( int ) 1e9 + 7; signed main(){ int N; cin >> N; vector< int > A( N ); for( int i = 0; i < N; ++i ) cin >> A[ i ]; int maxa = *max_element( A.begin(), A.end() ); vector< int > cnt( maxa + 1 ); for( int i = 0; i < N; ++i ) ++cnt[ A[ i ] ]; long long ans = 0; for( int i = 1; i <= maxa; ++i ) for( int j = i + 1; j <= maxa; ++j ) for( int k = j + 1; k <= maxa; ++k ) if( ok( i, j, k ) ) ans += 1LL * cnt[ i ] * cnt[ j ] % MOD7 * cnt[ k ] % MOD7; cout << ans << endl; return 0; } /* #include using namespace std; signed main(){ int N, K; cin >> N >> K; vector< vector< double > > dpn( N + 1, vector< double >( N * 6 ) ); dpn[ 0 ][ 0 ] = 1.0; for( int i = 0; i < N; ++i ) for( int j = 0; j < dpn[ i ].size(); ++j ) for( int k = 1; k <= 6; ++k ) if( j + k <= dpn[ i ].size() ) dpn[ i + 1 ][ j + k ] += dpn[ i ][ j ] / 6.0; vector< vector< double > > dpk( K + 1, vector< double >( K * 6 ) ); dpk[ 0 ][ 0 ] = 1.0; for( int i = 0; i < K; ++i ) for( int j = 0; j < dpk[ i ].size(); ++j ) for( int k = 2; k <= 6; k += 2 ) if( j + k <= dpk[ i ].size() ) dpk[ i + 1 ][ j + k ] += dpk[ i ][ j ] / 6.0; return 0; } */