Advertisement
Hamoudi30

Untitled

Mar 9th, 2022
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.11 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define SZ(v) ((int)(v.size()))
  5. #include <ext/pb_ds/assoc_container.hpp>
  6. #include <ext/pb_ds/tree_policy.hpp>
  7. using namespace __gnu_pbds;
  8. template<class T> using indexed_set = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
  9. constexpr int N = 52;
  10. constexpr int mod = 1e9+7;
  11. void run () {
  12.     int n;
  13.     cin >> n;
  14.     vector<ll> a(n);
  15.     map<ll, ll> freq;
  16.     for (ll &i : a) {
  17.         cin >> i;
  18.         freq[i]++;
  19.     }
  20.     ll sum = 0;
  21.     for (auto i : freq) {
  22.         ll num1 = i.first;
  23.         ll num1Freq = i.second;
  24.         for (auto j : freq) {
  25.             ll num2 = j.first;
  26.             ll num2Freq = j.second;
  27.             ll diff = abs(num1 - num2);
  28.             sum += num2Freq * num1Freq * diff * diff * 1ll;
  29.         }
  30.     }
  31.     cout << sum / 2;
  32. }
  33. int main() {
  34.     ios_base::sync_with_stdio(false);
  35.     cin.tie(nullptr);
  36.     cout.tie(nullptr);
  37. //    freopen("/home/hamoudi/Coding/run.in", "r", stdin);
  38.     int tt = 1;
  39. //    cin >> tt;
  40.     while (tt--)
  41.         run();
  42.     return 0;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement