Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define ll long long
- #define SZ(v) ((int)(v.size()))
- #include <ext/pb_ds/assoc_container.hpp>
- #include <ext/pb_ds/tree_policy.hpp>
- using namespace __gnu_pbds;
- template<class T> using indexed_set = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
- constexpr int N = 52;
- constexpr int mod = 1e9+7;
- void run () {
- int n;
- cin >> n;
- vector<int> a(n);
- map<int, int> freq;
- for (int &i : a) {
- cin >> i;
- freq[i]++;
- }
- ll sum = 0;
- for (auto i : freq) {
- int num1 = i.first;
- int num1Freq = i.second;
- for (auto j : freq) {
- int num2 = j.first;
- int num2Freq = j.second;
- int diff = abs(num1 - num2);
- sum += 1ll * num2Freq * num1Freq * diff * diff;
- }
- }
- cout << sum / 2;
- }
- int main() {
- ios_base::sync_with_stdio(false);
- cin.tie(nullptr);
- cout.tie(nullptr);
- // freopen("/home/hamoudi/Coding/run.in", "r", stdin);
- int tt = 1;
- // cin >> tt;
- while (tt--)
- run();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement