Language: C++

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define repf(i, f, l) for(int i = f; i < (int)l; ++i)
#define repit(it, t) for(__typeof((t).begin()) it = (t).begin(); it != (t).end(); it++)
#define endl "\n"
#define pb emplace_back
#define int long long
#define lb lower_bound
#define fs first
#define sd second
#define DBG0(x) { cout << #x << ": " << x << "\t"; }
#define DBG(x) {DBG0(x); cout << endl;}
#define DBG2(x, y) {DBG0(x); DBG(y);}
#define DBG3(x, y, z) {DBG0(x); DBG2(y, z);}
#define DBG4(w, x, y, z) {DBG0(w); DBG3(x, y, z);}
#define abs(x) ((x) < 0 ? (-1 * (x)) : (x))
#define max(x, y) (((x) < (y)) ? (y) : (x))

typedef vector<int> vint;
typedef pair<int, int> pii;

#define N 2001
int dp[N][N];


void printDp(int n) {
    cout << endl;
    rep(i, n + 1) {
        rep(j, n + 1) {
            cout << dp[i][j] << " ";
        }
        cout << endl;
    }
}

signed main(void){
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<pii> as = vector<pii>();
    rep(i, n) {
        int a;
        cin >> a;
        as.push_back(pii(a, i));
    }
    sort(as.begin(), as.end(), [](pii& a, pii& b) { return a.first > b.first; });
    rep(i, N) rep(j, N) dp[i][j] = 0;

    for (int i = 0; i < n; ++i) {
        for (int j = 0; i + j < n; ++j) {
            pii cur = as[i + j];
            int dis = (n - j - 1) - cur.second;
            dp[i][j + 1] = max(dp[i][j] + cur.first * abs(dis), dp[i][j + 1]);

            dis = i - cur.second;
            dp[i + 1][j] = max(dp[i][j] + cur.first * abs(dis), dp[i + 1][j]);
        }
    }
//  printDp(n);
    int ans = 0;
    for (int i = 0; i <= n; ++i) {
        ans = max(ans, dp[i][n - i]);
    }
    cout << ans << endl;

    return 0;
}


Compiler output:
a.cc:20:9: error: 'vector' does not name a type
   20 | typedef vector<int> vint;
      |         ^~~~~~
a.cc:21:9: error: 'pair' does not name a type
   21 | typedef pair<int, int> pii;
      |         ^~~~
a.cc: In function 'void printDp(long long int)':
a.cc:28:5: error: 'cout' was not declared in this scope
   28 |     cout << endl;
      |     ^~~~
a.cc:1:1: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
  +++ |+#include <iostream>
    1 | using namespace std;
a.cc: In function 'int main()':
a.cc:38:5: error: 'ios' has not been declared
   38 |     ios::sync_with_stdio(false);
      |     ^~~
a.cc:40:5: error: 'cin' was not declared in this scope
   40 |     cin >> n;
      |     ^~~
a.cc:40:5: note: 'std::cin' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:41:5: error: 'vector' was not declared in this scope
   41 |     vector<pii> as = vector<pii>();
      |     ^~~~~~
a.cc:1:1: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
  +++ |+#include <vector>
    1 | using namespace std;
a.cc:41:12: error: 'pii' was not declared in this scope
   41 |     vector<pii> as = vector<pii>();
      |            ^~~
a.cc:41:17: error: 'as' was not declared in this scope; did you mean 'abs'?
   41 |     vector<pii> as = vector<pii>();
      |                 ^~
      |                 abs
a.cc:41:34: error: expected primary-expression before ')' token
   41 |     vector<pii> as = vector<pii>();
      |                                  ^
a.cc:47:35: error: 'pii' is not a type
   47 |     sort(as.begin(), as.end(), [](pii& a, pii& b) { return a.first > b.first; });
      |                                   ^~~
a.cc:47:43: error: 'pii' is not a type
   47 |     sort(as.begin(), as.end(), [](pii& a, pii& b) { return a.first > b.first; });
      |                                           ^~~
a.cc: In lambda function:
a.cc:47:62: error: request for member 'first' in 'a', which is of non-class type 'int'
   47 |     sort(as.begin(), as.end(), [](pii& a, pii& b) { return a.first > b.first; });
      |                                                              ^~~~~
a.cc:47:72: error: request for member 'first' in 'b', which is of non-class type 'int'
   47 |     sort(as.begin(), as.end(), [](pii& a, pii& b) { return a.first > b.first; });
      |                                                                        ^~~~~
a.cc: In function 'int main()':
a.cc:47:5: error: 'sort' was not declared in this scope; did you mean 'short'?
   47 |     sort(as.begin(), as.end(), [](pii& a, pii& b) { return a.first > b.first; });
      |     ^~~~
      |     short
a.cc:52:16: error: expected ';' before 'cur'
   52 |             pii cur = as[i + j];
      |                ^~~~
      |                ;
a.cc:53:37: error: 'cur' was not declared in this scope
   53 |             int dis = (n - j - 1) - cur.second;
      |                                     ^~~
a.cc:65:5: error: 'cout' was not declared in this scope
   65 |     cout << ans << endl;
      |     ^~~~
a.cc:65:5: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'