#include #define be(v) (v).begin(),(v).end() #define pb(q) push_back(q) #define rep(i, n) for(int i=0;i> n; map mp; vector a(n); rep(i, n) { cin >> a[i]; mp[a[i]]++; } ll ans = 0; vector v; for(auto [x, y] : mp) { v.pb(y); } ll num1 = 0, num2 = 0; all(e, v) { ans += num2 * e; num2 += num1 * e; num1 += e; ans %= mod; num2 %= mod; num1 %= mod; } cout << ans << endl; return 0; }