Language: C++

int main(){
  #define TASK "ABC"
  //freopen(TASK".inp", "r", stdin); freopen(TASK".out", "w", stdout);
  ios_base::sync_with_stdio(0);

  int n;
  cin >> n;

  vector < pair < int, int > > a(n);

  for (int i = 0; i < n; ++i) {
    int x;
    cin >> x;
    a[i] = {x, i};
  }

  sort(a.begin(), a.end());

  vector < vector < ll > > d(n, vector < ll >(n, 0));

  d[0][n - 1] = 0;
  for (int len = n - 1; len > 0; --len)
    for (int i = 0; i + len < n; ++i) {
      int j = i + len;

      d[i][j - 1] = max(d[i][j - 1], d[i][j] + ll(abs(a[len].second - j)) * a[len].first);
      d[i + 1][j] = max(d[i + 1][j], d[i][j] + ll(abs(a[len].second - i)) * a[len].first);
    }

  ll ans = 0;

  for (int i = 0; i < n; ++i)
    ans = max(ans, d[i][i] + ll(abs(a[0].second - i)) * a[0].first);

  cout << ans;
  return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:4:3: error: 'ios_base' has not been declared
    4 |   ios_base::sync_with_stdio(0);
      |   ^~~~~~~~
a.cc:7:3: error: 'cin' was not declared in this scope
    7 |   cin >> n;
      |   ^~~
a.cc:9:3: error: 'vector' was not declared in this scope
    9 |   vector < pair < int, int > > a(n);
      |   ^~~~~~
a.cc:9:12: error: 'pair' was not declared in this scope
    9 |   vector < pair < int, int > > a(n);
      |            ^~~~
a.cc:9:19: error: expected primary-expression before 'int'
    9 |   vector < pair < int, int > > a(n);
      |                   ^~~
a.cc:14:5: error: 'a' was not declared in this scope
   14 |     a[i] = {x, i};
      |     ^
a.cc:17:8: error: 'a' was not declared in this scope
   17 |   sort(a.begin(), a.end());
      |        ^
a.cc:17:3: error: 'sort' was not declared in this scope; did you mean 'short'?
   17 |   sort(a.begin(), a.end());
      |   ^~~~
      |   short
a.cc:19:21: error: 'll' was not declared in this scope
   19 |   vector < vector < ll > > d(n, vector < ll >(n, 0));
      |                     ^~
a.cc:19:26: error: expected primary-expression before '>' token
   19 |   vector < vector < ll > > d(n, vector < ll >(n, 0));
      |                          ^
a.cc:19:28: error: 'd' was not declared in this scope
   19 |   vector < vector < ll > > d(n, vector < ll >(n, 0));
      |                            ^
a.cc:26:51: error: 'abs' was not declared in this scope
   26 |       d[i][j - 1] = max(d[i][j - 1], d[i][j] + ll(abs(a[len].second - j)) * a[len].first);
      |                                                   ^~~
a.cc:26:21: error: 'max' was not declared in this scope
   26 |       d[i][j - 1] = max(d[i][j - 1], d[i][j] + ll(abs(a[len].second - j)) * a[len].first);
      |                     ^~~
a.cc:30:5: error: expected ';' before 'ans'
   30 |   ll ans = 0;
      |     ^~~~
      |     ;
a.cc:33:5: error: 'ans' was not declared in this scope
   33 |     ans = max(ans, d[i][i] + ll(abs(a[0].second - i)) * a[0].first);
      |     ^~~
a.cc:33:33: error: 'abs' was not declared in this scope
   33 |     ans = max(ans, d[i][i] + ll(abs(a[0].second - i)) * a[0].first);
      |                                 ^~~
a.cc:33:11: error: 'max' was not declared in this scope
   33 |     ans = max(ans, d[i][i] + ll(abs(a[0].second - i)) * a[0].first);
      |           ^~~
a.cc:35:3: error: 'cout' was not declared in this scope
   35 |   cout << ans;
      |   ^~~~
a.cc:35:11: error: 'ans' was not declared in this scope
   35 |   cout << ans;
      |           ^~~