#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define sz size() #define pb push_back #define mp make_pair #define fi first #define se second #define all(c) (c).begin(), (c).end() #define rep(i,a,b) for(int i=(a);i<(b);++i) #define clr(a, b) memset((a), (b) ,sizeof(a)) #define MOD 1000000009 int d1[100001]; int d2[100001]; int main(){ int n; cin>>n; map ma; rep(i,0,n){ int a; cin>>a; ma[a]++; } vector v; map::iterator itr = ma.begin(); while(itr!=ma.end()){ v.pb((*itr).se); itr++; } clr(d1,0); clr(d2,0); rep(i,0,v.sz){ d1[i] = v[i]; } rep(i,1,v.sz){ d1[i]+=d1[i-1]; } rep(i,0,v.sz){ if(v[i]>1){ d2[i] = v[i]*(v[i]-1)/2; } } rep(i,1,v.sz){ d2[i] += d2[i-1]; } int ans = 0; rep(i,0,v.sz){ int a = v[i]; int b = d1[v.sz-1]-d1[a]; int c = d1[a-1]; int d = d2[v.sz-1]-d2[a]; int e = d2[a-1]; if(b>1){ ans += b*(b-1)/2; ans -= d; } if(c>1){ ans += c*(c-1)/2; ans -= e; } } cout << ans << endl; return 0; }