#include using namespace std; typedef signed long long ll; #undef _P #define _P(...) (void)printf(__VA_ARGS__) #define FOR(x,to) for(x=0;x M; void solve() { int i,j,k,l,r,x,y; string s; cin>>N; FOR(i,N) cin>>x, M[x]++; ret=1LL*N*(N-1)*(N-2)/6%mo; ITR(it,M) { x=it->second; if(x>=2) ret+=mo-(1LL*x*(x-1)/2*(N-x))%mo; if(x>=3) ret+=mo-(1LL*x*(x-1)*(x-2)/6)%mo; } cout<