Language: C++

6
8 6 9 1 2 1#include<bits/stdc++.h>

using namespace std;

const int mod = 1e9 + 7;

long long rec(int left, int right, vector<vector<long long>>& dp, vector<pair<int, int>>& infant){
  if(left > right) return 0;
  if(dp[left][right] != -1) return dp[left][right];
  
  long long l = rec(left + 1, right, dp, infant);
  long long r = rec(left, right - 1, dp, infant);
  
  l += (long long)infant[right - left].first * abs(infant[right - left].second - left);
  r += (long long)infant[right - left].first * abs(infant[right - left].second - right);
  
  if(l < r){
    dp[left][right] = r;
  }else{
    dp[left][right] = l;
  }
  
  return dp[left][right];
}

int main(){
  int N;
  cin >> N;
  
  vector<vector<long long>> dp(N, vector<long long>(N, -1));
  vector<pair<int, int>> infant(N);
  long long joy = 0;
  for(int i = 0; i < N; i++){
    int A;
    cin >> A;
    infant[i] = make_pair(A, i);
  }
  
  sort(infant.begin(), infant.end());
  
  cout << rec(0, N - 1, dp, infant) << endl;
  
  return 0;
}

Compiler output:
a.cc:2:12: error: stray '#' in program
    2 | 8 6 9 1 2 1#include<bits/stdc++.h>
      |            ^
a.cc:1:1: error: expected unqualified-id before numeric constant
    1 | 6
      | ^
a.cc:8:36: error: 'vector' has not been declared
    8 | long long rec(int left, int right, vector<vector<long long>>& dp, vector<pair<int, int>>& infant){
      |                                    ^~~~~~
a.cc:8:42: error: expected ',' or '...' before '<' token
    8 | long long rec(int left, int right, vector<vector<long long>>& dp, vector<pair<int, int>>& infant){
      |                                          ^
a.cc: In function 'long long int rec(int, int, int)':
a.cc:10:6: error: 'dp' was not declared in this scope
   10 |   if(dp[left][right] != -1) return dp[left][right];
      |      ^~
a.cc:12:38: error: 'dp' was not declared in this scope
   12 |   long long l = rec(left + 1, right, dp, infant);
      |                                      ^~
a.cc:12:42: error: 'infant' was not declared in this scope
   12 |   long long l = rec(left + 1, right, dp, infant);
      |                                          ^~~~~~
a.cc:15:48: error: 'abs' was not declared in this scope
   15 |   l += (long long)infant[right - left].first * abs(infant[right - left].second - left);
      |                                                ^~~
a.cc: In function 'int main()':
a.cc:29:3: error: 'cin' was not declared in this scope
   29 |   cin >> N;
      |   ^~~
a.cc:31:3: error: 'vector' was not declared in this scope
   31 |   vector<vector<long long>> dp(N, vector<long long>(N, -1));
      |   ^~~~~~
a.cc:31:17: error: expected primary-expression before 'long'
   31 |   vector<vector<long long>> dp(N, vector<long long>(N, -1));
      |                 ^~~~
a.cc:32:10: error: 'pair' was not declared in this scope
   32 |   vector<pair<int, int>> infant(N);
      |          ^~~~
a.cc:32:15: error: expected primary-expression before 'int'
   32 |   vector<pair<int, int>> infant(N);
      |               ^~~
a.cc:37:5: error: 'infant' was not declared in this scope
   37 |     infant[i] = make_pair(A, i);
      |     ^~~~~~
a.cc:37:17: error: 'make_pair' was not declared in this scope
   37 |     infant[i] = make_pair(A, i);
      |                 ^~~~~~~~~
a.cc:40:8: error: 'infant' was not declared in this scope
   40 |   sort(infant.begin(), infant.end());
      |        ^~~~~~
a.cc:40:3: error: 'sort' was not declared in this scope; did you mean 'short'?
   40 |   sort(infant.begin(), infant.end());
      |   ^~~~
      |   short
a.cc:42:3: error: 'cout' was not declared in this scope
   42 |   cout << rec(0, N - 1, dp, infant) << endl;
      |   ^~~~
a.cc:42:25: error: 'dp' was not declared in this scope
   42 |   cout << rec(0, N - 1, dp, infant) << endl;
      |                         ^~
a.cc:42:40: error: 'endl' was not declared in this scope
   42 |   cout << rec(0, N - 1, dp, infant) << endl;
      |                                        ^~~~