Language: C++

v#include <bits/stdc++.h>
using namespace std;

typedef long long int ll;
typedef pair <ll, ll> pll;

const int Max = 2e6 + 10;
const int Mod = 1e9 + 7;
const ll Inf = 1LL << 62;

ll ar[Max];


int main() {
#ifdef Mr_Emrul
        freopen("inputf.in", "r", stdin);
#endif /// Mr_Emrul


        ios_base::sync_with_stdio(false);
        cin.tie(0);

        ll ans = 0;
        ll n;
        cin >> n;
        set <int> st;
        for(int i = 1; i <= n; i++) {
                cin >> ar[i];
                st.insert(i);
        }
        vector <pll> vec;
        set <int> ache = st;
        while(ache.size()) {
                bool f = 0;
                vec.clear();
                for(int i : ache) {
                        ll x = *st.begin();
                        ll y = *st.rbegin();
                        if(abs(x - i) >= abs(y - i)) {
                                vec.push_back({abs(x - i) * ar[i], i});
                        }
                        else  {
                                vec.push_back({abs(y - i) * ar[i], i});
                        }
                }
                sort(vec.begin(), vec.end());
                reverse(vec.begin(), vec.end());
                for(pll x : vec) {
                        int l = *st.begin();
                        int r = *st.rbegin();
                        if(1LL * abs(l - x.second) * ar[x.second] == x.first) {
                                ans += abs(l - x.second) * ar[x.second];
                                st.erase(l);
                                ache.erase(x.second);
                                f = 1;
                        }
                        else if(1LL * abs(r - x.second) * ar[x.second] == x.first) {
                                ans += abs(r - x.second) * ar[x.second];
                                st.erase(r);
                                ache.erase(x.second);
                                f = 1;
                        }
                        break;
                }
        }
        assert(ache.size() == 0);
        cout << ans << endl;
        return 0;
}


Compiler output:
a.cc:1:2: error: stray '#' in program
    1 | v#include <bits/stdc++.h>
      |  ^
a.cc:1:1: error: 'v' does not name a type
    1 | v#include <bits/stdc++.h>
      | ^
a.cc:5:9: error: 'pair' does not name a type
    5 | typedef pair <ll, ll> pll;
      |         ^~~~
a.cc: In function 'int main()':
a.cc:20:9: error: 'ios_base' has not been declared
   20 |         ios_base::sync_with_stdio(false);
      |         ^~~~~~~~
a.cc:21:9: error: 'cin' was not declared in this scope
   21 |         cin.tie(0);
      |         ^~~
a.cc:26:9: error: 'set' was not declared in this scope
   26 |         set <int> st;
      |         ^~~
a.cc:26:14: error: expected primary-expression before 'int'
   26 |         set <int> st;
      |              ^~~
a.cc:29:17: error: 'st' was not declared in this scope; did you mean 'std'?
   29 |                 st.insert(i);
      |                 ^~
      |                 std
a.cc:31:9: error: 'vector' was not declared in this scope
   31 |         vector <pll> vec;
      |         ^~~~~~
a.cc:31:17: error: 'pll' was not declared in this scope; did you mean 'll'?
   31 |         vector <pll> vec;
      |                 ^~~
      |                 ll
a.cc:31:22: error: 'vec' was not declared in this scope
   31 |         vector <pll> vec;
      |                      ^~~
a.cc:32:14: error: expected primary-expression before 'int'
   32 |         set <int> ache = st;
      |              ^~~
a.cc:33:15: error: 'ache' was not declared in this scope
   33 |         while(ache.size()) {
      |               ^~~~
a.cc:37:33: error: 'st' was not declared in this scope; did you mean 'std'?
   37 |                         ll x = *st.begin();
      |                                 ^~
      |                                 std
a.cc:39:28: error: 'abs' was not declared in this scope; did you mean 'ans'?
   39 |                         if(abs(x - i) >= abs(y - i)) {
      |                            ^~~
      |                            ans
a.cc:46:17: error: 'sort' was not declared in this scope; did you mean 'short'?
   46 |                 sort(vec.begin(), vec.end());
      |                 ^~~~
      |                 short
a.cc:47:17: error: 'reverse' was not declared in this scope
   47 |                 reverse(vec.begin(), vec.end());
      |                 ^~~~~~~
a.cc:48:24: error: expected ';' before 'x'
   48 |                 for(pll x : vec) {
      |                        ^~
      |                        ;
a.cc:65:9: error: expected primary-expression before '}' token
   65 |         }
      |         ^
a.cc:64:18: error: expected ';' before '}' token
   64 |                 }
      |                  ^
      |                  ;
   65 |         }
      |         ~         
a.cc:65:9: error: expected primary-expression before '}' token
   65 |         }
      |         ^
a.cc:64:18: error: expected ')' before '}' token
   64 |                 }
      |                  ^
      |                  )
   65 |         }
      |         ~         
a.cc:48:20: note: to match this '('
   48 |                 for(pll x : vec) {
      |                    ^
a.cc:65:9: error: expected primary-expression before '}' token
   65 |         }
      |         ^
a.cc:66:16: error: 'ache' was not declared in this scope
   66 |         assert(ache.size() == 0);
      |                ^~~~
a.cc:66:9: error: 'assert' was not declared in this scope
   66 |         assert(ache.size() == 0);
      |         ^~~~~~
a.cc:1:1: note: 'assert' is defined in header '<cassert>'; this is probably fixable by adding '#include <cassert>'
  +++ |+#include <cassert>
    1 | v#include <bits/stdc++.h>
a.cc:67:9: error: 'cout' was not declared in this scope
   67 |         cout << ans << endl;
      |         ^~~~
a.cc:67:24: error: 'endl' was not declared in this scope
   67 |         cout << ans << endl;
      |                        ^~~~