fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. typedef long long int ll;
  5. #define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  6.  
  7.  
  8. #include <ext/pb_ds/assoc_container.hpp>
  9. #include <ext/pb_ds/tree_policy.hpp>
  10. using namespace __gnu_pbds;
  11.  
  12. typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>order_set;
  13. typedef pair<int, int>pr;
  14. #define all(i) i.begin() , i.end()
  15. #define ft first
  16. #define sn second
  17. #define pb push_back
  18.  
  19. #define en "\n"
  20.  
  21. #define MAXN 1000010
  22. #define inf 1e6+5
  23. const ll mod = 1e9 + 7;
  24.  
  25. ll n;
  26. ll a[MAXN];
  27.  
  28. void solve()
  29. {
  30.  
  31. cin >> n;
  32. for (ll i = 0; i < n; i++) {
  33. cin >> a[i];
  34. }
  35.  
  36. sort(a, a + n);
  37.  
  38. ll ans = 0;
  39.  
  40. ll x = 0;
  41. for (ll i = 0; i < n; i++)
  42. {
  43. ll y = 1;
  44. if (a[i] == a[i + 1] && i + 1 < n)
  45. {
  46. while (a[i] == a[i + 1] && i + 1 < n) {
  47. y++;
  48. i++;
  49. }
  50. }
  51. ll z = n - (x + y);
  52. ans += (((x * y) % mod) * z) % mod;
  53. x += y;
  54. ans %= mod;
  55. }
  56.  
  57. cout << ans << en;
  58.  
  59. }
  60. int main()
  61. {
  62. IOS;
  63. ll t;
  64. t = 1;
  65.  
  66. // cin >> t;
  67.  
  68.  
  69. int c = 0;
  70. while ( t-- )
  71. {
  72. // cout<<"Case "<<++c<<": ";
  73. solve();
  74. }
  75. return 0;
  76. }
Success #stdin #stdout 0.01s 5348KB
stdin
Standard input is empty
stdout
0