criyle/codenet-compile-errors huggingface dataset:
Language: C++

#include <iostream>
#include <deque>

#include <algorithm>

using namespace std;

int main(){
  int N;
  long A[2001];
  
  cin >> N;
  for(int i=1;i<=N;i++){
  	cin >> A[i];  
  }
  
  int person[2001] = {0};
  int pos[2001] = {0};
  
  deque<pair<long,pair<int,int>>> score;
  
  for(int i=1; i<=N; i++){
  	for(int pos=1; pos<=N; pos++){
		score.push_back(make_pair(A[i]*abs(i-pos),make_pair(i,pos)));
    }
  }
  sort(score.begin(),score.end(),greater<pair<long,pair<int,int>>);
  
  long sum = 0;
  
  for(auto itr = score.begin(),count = 0; count<20; itr++ ){
    if(person[*itr.second.first]==0&&pos[*itr.second.second]==0){
      person[*itr.second.first]=1;
      pos[*itr.second.second]=1;
      sum+=*itr.first;
      count++;
    }
  }
  cout << sum << endl;
  return 0; 
}


Compiler output:
a.cc: In function 'int main()':
a.cc:27:42: error: template argument 1 is invalid
   27 |   sort(score.begin(),score.end(),greater<pair<long,pair<int,int>>);
      |                                          ^~~~~~~~~~~~~~~~~~~~~~~~
a.cc:31:7: error: inconsistent deduction for 'auto': 'std::_Deque_iterator<std::pair<long int, std::pair<int, int> >, std::pair<long int, std::pair<int, int> >&, std::pair<long int, std::pair<int, int> >*>' and then 'int'
   31 |   for(auto itr = score.begin(),count = 0; count<20; itr++ ){
      |       ^~~~
a.cc:32:20: error: 'struct std::_Deque_iterator<std::pair<long int, std::pair<int, int> >, std::pair<long int, std::pair<int, int> >&, std::pair<long int, std::pair<int, int> >*>' has no member named 'second'
   32 |     if(person[*itr.second.first]==0&&pos[*itr.second.second]==0){
      |                    ^~~~~~
a.cc:32:47: error: 'struct std::_Deque_iterator<std::pair<long int, std::pair<int, int> >, std::pair<long int, std::pair<int, int> >&, std::pair<long int, std::pair<int, int> >*>' has no member named 'second'
   32 |     if(person[*itr.second.first]==0&&pos[*itr.second.second]==0){
      |                                               ^~~~~~
a.cc:33:19: error: 'struct std::_Deque_iterator<std::pair<long int, std::pair<int, int> >, std::pair<long int, std::pair<int, int> >&, std::pair<long int, std::pair<int, int> >*>' has no member named 'second'
   33 |       person[*itr.second.first]=1;
      |                   ^~~~~~
a.cc:34:16: error: 'struct std::_Deque_iterator<std::pair<long int, std::pair<int, int> >, std::pair<long int, std::pair<int, int> >&, std::pair<long int, std::pair<int, int> >*>' has no member named 'second'
   34 |       pos[*itr.second.second]=1;
      |                ^~~~~~
a.cc:35:17: error: 'struct std::_Deque_iterator<std::pair<long int, std::pair<int, int> >, std::pair<long int, std::pair<int, int> >&, std::pair<long int, std::pair<int, int> >*>' has no member named 'first'; did you mean '_M_first'?
   35 |       sum+=*itr.first;
      |                 ^~~~~
      |                 _M_first
Language: C++

#include <iostream>
#include <deque>

#include <algorithm>

using namespace std;

int main(){
  int N;
  long A[2001];
  
  cin >> N;
  for(int i=1;i<=N;i++){
  	cin >> A[i];  
  }
  
  int person[2001] = {0};
  int pos[2001] = {0};
  
  deque<pair<long,pair<int,int>>> score();
  
  for(int i=1; i<=N; i++){
  	for(int pos=1; pos<=N; pos++){
		score.push_back(make_pair(A[i]*abs(i-pos),make_pair(i,pos)));
    }
  }
  sort(score.begin(),score.end(),greater<pair<long,pair<int,int>>);
  
  long sum = 0;
  
  for(auto itr = score.begin(),count = 0; count<20; itr++ ){
    if(person[*itr.second.first]==0&&pos[*itr.second.second]==0){
      person[*itr.second.first]=1;
      pos[*itr.second.second]=1;
      sum+=*itr.first;
      count++;
    }
  }
  cout << sum << endl;
  return 0; 
}


Compiler output:
a.cc: In function 'int main()':
a.cc:20:40: warning: empty parentheses were disambiguated as a function declaration [-Wvexing-parse]
   20 |   deque<pair<long,pair<int,int>>> score();
      |                                        ^~
a.cc:24:23: error: request for member 'push_back' in 'score', which is of non-class type 'std::deque<std::pair<long int, std::pair<int, int> > >()'
   24 |                 score.push_back(make_pair(A[i]*abs(i-pos),make_pair(i,pos)));
      |                       ^~~~~~~~~
a.cc:27:14: error: request for member 'begin' in 'score', which is of non-class type 'std::deque<std::pair<long int, std::pair<int, int> > >()'
   27 |   sort(score.begin(),score.end(),greater<pair<long,pair<int,int>>);
      |              ^~~~~
a.cc:27:28: error: request for member 'end' in 'score', which is of non-class type 'std::deque<std::pair<long int, std::pair<int, int> > >()'
   27 |   sort(score.begin(),score.end(),greater<pair<long,pair<int,int>>);
      |                            ^~~
a.cc:27:42: error: template argument 1 is invalid
   27 |   sort(score.begin(),score.end(),greater<pair<long,pair<int,int>>);
      |                                          ^~~~~~~~~~~~~~~~~~~~~~~~
a.cc:31:24: error: request for member 'begin' in 'score', which is of non-class type 'std::deque<std::pair<long int, std::pair<int, int> > >()'
   31 |   for(auto itr = score.begin(),count = 0; count<20; itr++ ){
      |                        ^~~~~
a.cc:31:43: error: parse error in template argument list
   31 |   for(auto itr = score.begin(),count = 0; count<20; itr++ ){
      |                                           ^~~~~~~~
a.cc:31:43: error: cannot resolve overloaded function 'count' based on conversion to type 'bool'
a.cc:36:12: error: no post-increment operator for type
   36 |       count++;
      |            ^~
Language: C++

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

int main() {
    int N;
    struct map{
        int index;
        int64_t elem;
    };
    vector<map> A;
    
    cin >> N;
    for(int i=0;i<N;i++){
        int64_t elem;
        cin >> elem;
        A.push_back({i,elem});
    };

    sort(A.begin(), A.end(), [](const map& x, const map& y){ return x.elem > y.elem;});

    struct x_y{
        int x;
        int y;
    };
    vector<x_y> dpnxy;
    vector<x_y> dpnxy1;
    dpnxy.push_back({0,0});

    vector<int64_t> dpn;
    vector<int64_t> dpn1;
    dpn.push_back(0);

    for(int n=1;n<=N;n++){
        for(int i=0;i<dpnxy.size();i++){
            int x = dpnxy.at(i).x;
            int y = dpnxy.at(i).y;
            int n_left = x;
            int n_right = N-1-y;

            if(A.at(n-1).index >= n_left){
                int64_t l = dpn.at(i) + A.at(n-1).elem * (A.at(n-1).index - n_left);
                
                if(i != 0 && dpnxy1.at(dpnxy1.size()-1).x == x+1 && dpnxy1.at(dpnxy1.size()-1).y ==y){
                    if(dpn1.at(dpn1.size()-1) < l){
                        dpn1.at(dpn1.size()-1) = l;
                    }
                }else{
                    dpnxy1.push_back({x+1,y});
                    dpn1.push_back(l);
                }
            }

            if(A.at(n-1).index <= n_right){
                int64_t r = dpn.at(i) + A.at(n-1).elem * (n_right - A.at(n-1).index);
                dpnxy1.push_back({x,y+1});
                dpn1.push_back(r);
            }
        }
        dpnxy = dpnxy1;
        dpn = dpn1;
        // for(int i=0;i<dpn.size();i++){
        //     cout << dpnxy.at(i).x << " " << dpnxy.at(i).y << " " << dpn.at(i) << "|";
        // }
        // cout << endl;
        dpnxy1.clear();
        dpn1.clear();
    }
    int64_t result = 0;
    for(int i=0;i<dpn.size();i++){
        if(result < dpn.at(i)){
            result = dpn.at(i);
        }
    }
    cout << result << endl;

Compiler output:
a.cc: In function 'int main()':
a.cc:74:28: error: expected '}' at end of input
   74 |     cout << result << endl;
      |                            ^
a.cc:4:12: note: to match this '{'
    4 | int main() {
      |            ^
Language: C++

//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <stdio.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second
#define mp make_pair
 
const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll INF = 1ll << 60;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int N;
ll A[int(2e4+5)], DP[int(2e4+5)][int(2e4+5)];
Pll P[int(2e4+5)];

int main(){
  cin >> N;
  for (int i = 1; i <= N; i++){
    cin >> A[i];
    P[i] = mp(A[i], i);
  }
  sort(P + 1, P + N + 1, greater<Pll>());

  ll ans = 0;
  for (ll i = 1; i <= N; i++){
    for (ll j = 0; j <= i; j++){
      ll now = 0;

      if (j >= 1){
        now = max(now, DP[j-1][i-j] + P[i].fi * abs(P[i].se - j));
      }
      if (i - j - 1 >= 0){
        now = max(now, DP[j][i-j-1] + P[i].fi * abs(P[i].se - (N - (i - j) + 1)));
      }
      DP[j][i-j] = now;
      ans = max(ans, DP[j][i - j]);
    }
  }
  printf("%lld\n", ans);

  return 0;
}


Compiler output:
/tmp/ccQg5rtj.o: in function `main':
a.cc:(.text+0x11a): relocation truncated to fit: R_X86_64_PC32 against symbol `P' defined in .bss section in /tmp/ccQg5rtj.o
a.cc:(.text+0x160): relocation truncated to fit: R_X86_64_PC32 against symbol `P' defined in .bss section in /tmp/ccQg5rtj.o
a.cc:(.text+0x16a): relocation truncated to fit: R_X86_64_PC32 against symbol `P' defined in .bss section in /tmp/ccQg5rtj.o
a.cc:(.text+0x1e9): relocation truncated to fit: R_X86_64_PC32 against symbol `P' defined in .bss section in /tmp/ccQg5rtj.o
a.cc:(.text+0x1ff): relocation truncated to fit: R_X86_64_PC32 against symbol `P' defined in .bss section in /tmp/ccQg5rtj.o
a.cc:(.text+0x284): relocation truncated to fit: R_X86_64_PC32 against symbol `P' defined in .bss section in /tmp/ccQg5rtj.o
a.cc:(.text+0x29a): relocation truncated to fit: R_X86_64_PC32 against symbol `P' defined in .bss section in /tmp/ccQg5rtj.o
collect2: error: ld returned 1 exit status
Language: C++

//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <stdio.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second
#define mp make_pair
 
const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll INF = 1ll << 60;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int N;
ll A[int(2e4+5)], DP[int(2e4+5)][int(2e4+5)];
Pll P[int(2e4+5)];

int main(){
  cin >> N;
  for (int i = 1; i <= N; i++){
    scanf("%lld", A + i);
    P[i] = mp(A[i], i);
  }
  sort(P + 1, P + N + 1, greater<Pll>());

  ll ans = 0;
  for (ll i = 1; i <= N; i++){
    for (ll j = 0; j <= i; j++){
      ll now = 0;

      if (j >= 1){
        now = max(now, DP[j-1][i-j] + P[i].fi * abs(P[i].se - j));
      }
      if (i - j - 1 >= 0){
        now = max(now, DP[j][i-j-1] + P[i].fi * abs(P[i].se - (N - (i - j) + 1)));
      }
      DP[j][i-j] = now;
      ans = max(ans, DP[j][i - j]);
    }
  }
  printf("%lld\n", ans);

  return 0;
}


Compiler output:
/tmp/ccR5LQp2.o: in function `main':
a.cc:(.text+0x11f): relocation truncated to fit: R_X86_64_PC32 against symbol `P' defined in .bss section in /tmp/ccR5LQp2.o
a.cc:(.text+0x165): relocation truncated to fit: R_X86_64_PC32 against symbol `P' defined in .bss section in /tmp/ccR5LQp2.o
a.cc:(.text+0x16f): relocation truncated to fit: R_X86_64_PC32 against symbol `P' defined in .bss section in /tmp/ccR5LQp2.o
a.cc:(.text+0x1ee): relocation truncated to fit: R_X86_64_PC32 against symbol `P' defined in .bss section in /tmp/ccR5LQp2.o
a.cc:(.text+0x204): relocation truncated to fit: R_X86_64_PC32 against symbol `P' defined in .bss section in /tmp/ccR5LQp2.o
a.cc:(.text+0x289): relocation truncated to fit: R_X86_64_PC32 against symbol `P' defined in .bss section in /tmp/ccR5LQp2.o
a.cc:(.text+0x29f): relocation truncated to fit: R_X86_64_PC32 against symbol `P' defined in .bss section in /tmp/ccR5LQp2.o
collect2: error: ld returned 1 exit status
Language: C++

//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <stdio.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second
#define mp make_pair
 
const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll INF = 1ll << 60;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

ll N;
ll A[int(2e4+5)], DP[int(2e4+5)][int(2e4+5)];
Pll P[int(2e4+5)];

int main(){
  scanf("%lld", &N);
  for (ll i = 1; i <= N; i++){
    scanf("%lld", A + i);
    P[i] = mp(A[i], i);
  }
  sort(P + 1, P + N + 1, greater<Pll>());

  ll ans = 0;
  for (ll i = 1; i <= N; i++){
    for (ll j = 0; j <= i; j++){
      ll now = 0;

      if (j >= 1){
        now = max(now, DP[j-1][i-j] + P[i].fi * abs(P[i].se - j));
      }
      if (i - j - 1 >= 0){
        now = max(now, DP[j][i-j-1] + P[i].fi * abs(P[i].se - (N - (i - j) + 1)));
      }
      DP[j][i-j] = now;
      ans = max(ans, DP[j][i - j]);
    }
  }
  printf("%lld\n", ans);

  return 0;
}


Compiler output:
/tmp/ccCLmYQg.o: in function `main':
a.cc:(.text+0x122): relocation truncated to fit: R_X86_64_PC32 against symbol `P' defined in .bss section in /tmp/ccCLmYQg.o
a.cc:(.text+0x16d): relocation truncated to fit: R_X86_64_PC32 against symbol `P' defined in .bss section in /tmp/ccCLmYQg.o
a.cc:(.text+0x177): relocation truncated to fit: R_X86_64_PC32 against symbol `P' defined in .bss section in /tmp/ccCLmYQg.o
a.cc:(.text+0x1f6): relocation truncated to fit: R_X86_64_PC32 against symbol `P' defined in .bss section in /tmp/ccCLmYQg.o
a.cc:(.text+0x20c): relocation truncated to fit: R_X86_64_PC32 against symbol `P' defined in .bss section in /tmp/ccCLmYQg.o
a.cc:(.text+0x291): relocation truncated to fit: R_X86_64_PC32 against symbol `P' defined in .bss section in /tmp/ccCLmYQg.o
a.cc:(.text+0x2a7): relocation truncated to fit: R_X86_64_PC32 against symbol `P' defined in .bss section in /tmp/ccCLmYQg.o
collect2: error: ld returned 1 exit status
Language: C++

//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <stdio.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second
#define mp make_pair
 
const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll INF = 1ll << 60;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int N;
ll A[int(2e4+5)], DP[int(2e4+5)][int(2e4+5)];
Pll P[int(2e4+5)];

int main(){
  scanf("%d", &N);
  for (int i = 1; i <= N; i++){
    scanf("%lld", A + i);
    P[i] = mp(A[i], i);
  }
  sort(P + 1, P + N + 1, greater<Pll>());

  ll ans = 0;
  for (ll i = 1; i <= N; i++){
    for (ll j = 0; j <= i; j++){
      ll now = 0;

      if (j >= 1){
        now = max(now, DP[j-1][i-j] + P[i].fi * abs(P[i].se - j));
      }
      if (i - j - 1 >= 0){
        now = max(now, DP[j][i-j-1] + P[i].fi * abs(P[i].se - (N - (i - j) + 1)));
      }
      DP[j][i-j] = now;
      ans = max(ans, DP[j][i - j]);
    }
  }
  printf("%lld\n", ans);

  return 0;
}


Compiler output:
/tmp/ccZp0B5j.o: in function `main':
a.cc:(.text+0x124): relocation truncated to fit: R_X86_64_PC32 against symbol `P' defined in .bss section in /tmp/ccZp0B5j.o
a.cc:(.text+0x16a): relocation truncated to fit: R_X86_64_PC32 against symbol `P' defined in .bss section in /tmp/ccZp0B5j.o
a.cc:(.text+0x174): relocation truncated to fit: R_X86_64_PC32 against symbol `P' defined in .bss section in /tmp/ccZp0B5j.o
a.cc:(.text+0x1f3): relocation truncated to fit: R_X86_64_PC32 against symbol `P' defined in .bss section in /tmp/ccZp0B5j.o
a.cc:(.text+0x209): relocation truncated to fit: R_X86_64_PC32 against symbol `P' defined in .bss section in /tmp/ccZp0B5j.o
a.cc:(.text+0x28e): relocation truncated to fit: R_X86_64_PC32 against symbol `P' defined in .bss section in /tmp/ccZp0B5j.o
a.cc:(.text+0x2a4): relocation truncated to fit: R_X86_64_PC32 against symbol `P' defined in .bss section in /tmp/ccZp0B5j.o
collect2: error: ld returned 1 exit status
Language: C

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

int main() {
	int n;
	cin >> n;

	vector<pair<int, int>> a(n + 1);
	for (int i = 1; i <= n; ++i) {
		cin >> a[i].first;
		a[i].second = i;
	}

	sort(a.begin() + 1, a.end(), greater<pair<int, int>>());

	vector<vector<long long>> dp(n + 1, vector<long long>(n + 1, 0));
	for (int i = 1; i <= n; ++i) {
		for (int j = 0; j < i; ++j) {
			int l = j;
			int r = i - 1 - j;
			dp[l + 1][r] = max(dp[l + 1][r], dp[l][r] + abs(l + 1 - a[i].second) * a[i].first);

			r = j;
			l = i - 1 - j;
			dp[l][r + 1] = max(dp[l][r + 1], dp[l][r] + abs(n - r - a[i].second) * a[i].first);
		}
	}

	long long ans = 0;
	for (int i = 0; i <= n; ++i) {
		ans = max(ans, dp[i][n - i]);
	}

	cout << ans;

	return 0;
}
	

Compiler output:
main.c:1:10: fatal error: bits/stdc++.h: No such file or directory
    1 | #include <bits/stdc++.h>
      |          ^~~~~~~~~~~~~~~
compilation terminated.
Language: C++

#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <tuple>
#include <queue>
#include <bitset>
#include <set>
#include <map>
#include <list>

using ll = long long;
using ld = long double;
using namespace std;
const int INF = 1e9+100;
const ll INF64 = 7e18l;
const int mod = 1000000007;
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(a) (a).begin(), (a).end()
#define FIN ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);


int main(){
    FIN;
    ll n; cin >> n;
    vector<pair<ll,ll>> a(n);
    for(int i=0;i<n;i++){
        cin >> a[i].first;
        a[i].second = i;
    }
    sort(ALL(a),greater<pair<ll,ll>>);

    vector<vector<ll>> dp(n+1,vector<ll>(n+1,0));
    for(int i=0;i<n;i++){
        for(int j=0;i+j<n;i++){
            dp[i+1][j] = max(dp[i+1][j],dp[i][j]+a[i+j].first * (a[i+j].second - i));
            dp[i][j+1] = max(dp[i][j+1],dp[i][j]+a[i+j].first * (n-1-j - a[i+j].second));
        }
    }

    ll 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: In function 'int main()':
a.cc:35:37: error: expected primary-expression before ')' token
   35 |     sort(ALL(a),greater<pair<ll,ll>>);
      |                                     ^
Language: C++

#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <tuple>
#include <queue>
#include <bitset>
#include <set>
#include <map>
#include <list>

using ll = long long;
using ld = long double;
using namespace std;
const int INF = 1e9+100;
const ll INF64 = 7e18l;
const int mod = 1000000007;
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(a) (a).begin(), (a).end()
#define FIN ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);


int main(){
    FIN;
    ll n; cin >> n;
    vector<pair<ll,ll>> a(n);
    for(int i=0;i<n;i++){
        cin >> a[i].first;
        a[i].second = i;
    }
    sort(ALL(a),greater<pair<ll,ll>>);

    vector<vector<ll>> dp(n+1,vector<ll>(n+1,0));
    for(int i=0;i<n;i++){
        for(int j=0;i+j<n;i++){
            dp[i+1][j] = max(dp[i+1][j],dp[i][j]+A[i+j].first * (A[i+j].second - i));
            dp[i][j+1] = max(dp[i][j+1],dp[i][j]+A[i+j].first * (N-1-j - A[i+j].second));
        }
    }

    ll 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: In function 'int main()':
a.cc:35:37: error: expected primary-expression before ')' token
   35 |     sort(ALL(a),greater<pair<ll,ll>>);
      |                                     ^
a.cc:40:50: error: 'A' was not declared in this scope
   40 |             dp[i+1][j] = max(dp[i+1][j],dp[i][j]+A[i+j].first * (A[i+j].second - i));
      |                                                  ^
a.cc:41:66: error: 'N' was not declared in this scope
   41 |             dp[i][j+1] = max(dp[i][j+1],dp[i][j]+A[i+j].first * (N-1-j - A[i+j].second));
      |                                                                  ^
a.cc:46:47: error: 'N' was not declared in this scope
   46 |     for(int i=0;i<=n;i++) ans = max(ans,dp[i][N-i]);
      |                                               ^
Language: C

#include <stdio.h>
#define mod 1000000007
typedef long long ll;

ll abs(ll a) {
  return a > 0 ? a : -a;
}

int main(void) {
  ll i, j, k, n, ans = 0, sum, max, mn, sum2, cnt;
  scanf("%lld", &n);
  bool flg[n];
  ll a[n], now[n];
  for(i = 0; i < n; ++i) scanf("%lld", &a[i]), flg[i] = true, now[i] = 0;
  for(k = 0; k < n; ++k) {
    max = -1, sum = sum2 = cnt = 0;
    for(i = 0; i < n; ++i) if(flg[i] && max < a[i]) max = a[i], mn = i;
    flg[mn] = false;
    for(i = 0; i < mn; ++i) if(flg[i]) {
      if(now[i] < 0) sum -= a[i];
      else sum += a[i];
      cnt++;
    }
    if(now[i] > 0) {
      sum -= now[i] * a[i];
      sum += abs(cnt - now[i]) * a[i];
    }
    else sum += cnt * a[i];
    cnt = 0;
    for(; i < n; ++i) if(flg[i]) {
      if(now[i] > 0) sum2 -= a[i];
      else sum2 += a[i];
      cnt++;
    }
    if(now[mn] < 0) {
      sum2 += now[mn] * a[mn];
      sum2 += abs(now[mn] + cnt) * a[mn];
    }
    else sum2 += cnt * a[mn];
    if(sum > sum2) {
      ans += sum;
      for(i = 0; i < mn; ++i) now[i]++;
    } else {
      ans += sum2;
      for(i = mn; i < n; ++i) now[i]--;
    }
  }
  printf("%lld", ans);
  return 0;
}

Compiler output:
main.c:5:4: warning: conflicting types for built-in function 'abs'; expected 'int(int)' [-Wbuiltin-declaration-mismatch]
    5 | ll abs(ll a) {
      |    ^~~
main.c:2:1: note: 'abs' is declared in header '<stdlib.h>'
    1 | #include <stdio.h>
  +++ |+#include <stdlib.h>
    2 | #define mod 1000000007
main.c: In function 'main':
main.c:12:3: error: unknown type name 'bool'
   12 |   bool flg[n];
      |   ^~~~
main.c:2:1: note: 'bool' is defined in header '<stdbool.h>'; this is probably fixable by adding '#include <stdbool.h>'
    1 | #include <stdio.h>
  +++ |+#include <stdbool.h>
    2 | #define mod 1000000007
main.c:14:57: error: 'true' undeclared (first use in this function)
   14 |   for(i = 0; i < n; ++i) scanf("%lld", &a[i]), flg[i] = true, now[i] = 0;
      |                                                         ^~~~
main.c:14:57: note: 'true' is defined in header '<stdbool.h>'; this is probably fixable by adding '#include <stdbool.h>'
main.c:14:57: note: each undeclared identifier is reported only once for each function it appears in
main.c:18:15: error: 'false' undeclared (first use in this function)
   18 |     flg[mn] = false;
      |               ^~~~~
main.c:18:15: note: 'false' is defined in header '<stdbool.h>'; this is probably fixable by adding '#include <stdbool.h>'
Language: C

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

using namespace std;

typedef long long ll;
typedef vector<long long> vi;
typedef pair<long long, long long> ii;
typedef vector<pair<long long, long long>> vii;
typedef stringstream ss;
ll mil() { return numeric_limits<long long>::min(); }
ll mal() { return numeric_limits<long long>::max(); }

#define R3(i, a, b) for (long long i = (a); i < (b); ++i)
#define R2(i, b) for (long long i = 0; i < (b); ++i)
#define R1(b) for (long long i = 0; i < (b); ++i)
#define RR(i, a, b) for (long long i = a; i > b; --i)
#define PB(x) push_back(x)
#define MP(x, y) make_pair(x, y)

// build: ctrl + f9

// run: shift + f10
// debug: shift + f9
// sanitize: shift + f11



ll recur(ll l, ll r, ll i, vii &ai, map<tuple<ll, ll, ll>, ll> & cache) {
    if(i == ai.size()) {
        return 0;
    }  

    if(cache.count(make_tuple(l, r, i)) > 0) {
        return cache[make_tuple(l, r, i)];
    }

    auto & e = ai[i];

    cache[make_tuple(l, r, i)] = max(abs(e.second - l)*e.first + recur(l+1, r, i+1, ai, cache), abs(e.second - r)*e.first + recur(l, r-1, i+1, ai, cache));    
    
    return cache[make_tuple(l, r, i)];
}

void solve() {
    
    int N;

    cin >> N;
    vii ai(N);

    ll val = 0;
    R1(N) cin >> val, ai[i] = MP(val, i);
    sort(ai.begin(), ai.end(), greater<ii>());
    map<tuple<ll, ll, ll>, ll> cache;

    ll sum = recur(0, ai.size() - 1, 0, ai, cache);
    
    cout << sum << endl;
}

int main(int argc, char **argv)
{
    freopen("../../input.txt", "r", stdin);
    freopen("../../output.txt", "w", stdout);

    ll ti;

    cin >> ti;

    R1(ti)
        solve();    
}

Compiler output:
main.c:1:10: fatal error: iostream: No such file or directory
    1 | #include <iostream>
      |          ^~~~~~~~~~
compilation terminated.
Language: C++

#include<bits/stdc++.h>
using namespace std;
typedef long long int64;
typedef pair<int64, int64> pii;
//int64 dp[2002][2002];
vector<pii> A(2002);
int n;
map<vector<int>, int64> dp;
int64 solve(int l, int r, int pos){
   if(l > r) return 0;
   if(pos >= n) return 0;
   //int64 &ret = dp[{l, r, pos}];
   //if(ret > 0) return ret;
   in64 ret = A[pos].first * abs(A[pos].second - l) + solve(l + 1, r, pos + 1);
   ret = max(ret, A[pos].first * abs(A[pos].second - r) + solve(l, r - 1, pos + 1));
   return ret;
}
int main(){
	cin >> n;
    for(int i = 0; i < n; i++){
    	cin >> A[i].first;
        A[i].second = i;
    }
    sort(A.rbegin(), A.rend());
    //memset(dp, -1, sizeof(dp));
    int64 ans = solve(0, n - 1, 0);
    cout << ans << endl;
    return 0;
}


Compiler output:
a.cc: In function 'int64 solve(int, int, int)':
a.cc:14:4: error: 'in64' was not declared in this scope; did you mean 'int64'?
   14 |    in64 ret = A[pos].first * abs(A[pos].second - l) + solve(l + 1, r, pos + 1);
      |    ^~~~
      |    int64
a.cc:15:4: error: 'ret' was not declared in this scope
   15 |    ret = max(ret, A[pos].first * abs(A[pos].second - r) + solve(l, r - 1, pos + 1));
      |    ^~~
Language: C++

#include<bits/stdc++.h>
using namespace std;
typedef long long int64;
typedef pair<int64, int64> pii;
int main(){
	int64 n; cin >> n;
    vector<pii> A(n);
    for(int64 i = 0; i < n; i++){
    	cin >> A[i].first;
        A[i].second = i;
    }
    sort(A.begin(), A.end());
    int64 dp[2002][2002], ans = 0;
  	for(int64 l = n; l >= 1; l--){
    	for(int64 i = 0; i < n - l + 1; i++){
          int64 j = i + l - 1;
          if(l == 1){
          	  ans = max(ans, dp[i][j] + A[l].first * abs(A[l].second - i));
          }
          else{
          	  dp[i + 1][j] = max(dp[i + 1][j], dp[i][j] + A[l].first * abs(A[l].second - i));
              dp[i][j - 1] = max(dp[i][j - 1], dp[i][j] + A[l].first * abs(A[l].second - j));
          }
    }
    cout << ans << endl;
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:27:2: error: expected '}' at end of input
   27 | }
      |  ^
a.cc:5:11: note: to match this '{'
    5 | int main(){
      |           ^
Language: C

n=int(input())
x=list(map(int,input().split()))
a=sorted([(int(v),i)for i,v in enumerate(x)],reverse=True)
dp=[[0]*(n+1)for i in range(n+1)]
dp[0][0]=a[0][0]*(n-1-a[0][1])
dp[0][1]=a[0][0]*a[0][1]
for i,v in enumerate(a[1:]):
  dp[i+1][0]=dp[i][0]+v[0]*abs(n-1-(i+1)-v[1])
  dp[i+1][i+2]=dp[i][i+1]+v[0]*abs(v[1]-(i+1))
  for j in range(1,i+2):
    a=dp[i][j]+v[0]*abs(n-1-(i+1)+j-v[1])
    b=dp[i][j-1]+v[0]*abs(v[1]-(j-1))
    dp[i+1][j]=max(a,b)
print(max(dp[n-1]))

Compiler output:
main.c:1:1: warning: data definition has no type or storage class
    1 | n=int(input())
      | ^
main.c:1:1: error: type defaults to 'int' in declaration of 'n' [-Wimplicit-int]
main.c:1:3: error: expected expression before 'int'
    1 | n=int(input())
      |   ^~~
Language: C

#include <bits/stdc++.h>
 
#define f(i,a,b) for( ll i = a; i < (ll) b ; i++ ) 
#define af(i,a,b) for( ll i = a; i >= (ll) b ; i--)
#define rep(i,a,b,k) for(ll i = a; i < b ; i+= k )
#define arep(i,a,b,k) for( ll i = a; i >= b ; i-= k)
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define sz(a) (ll) a.size()
#define all(a) a.begin(), a.end()
#define sor(a) sort( a.begin(), a.end() )
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define inter ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr)
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> ii ;
typedef vector<ll>  vi ;
typedef vector<ii> vii ;
 
const ll MAX= 2e3+100;

struct pp{
	ll v,ind;
	bool operator<(const pp &o){
		return v>o.v;
	} 	
};

pp c[MAX];
ll dp[MAX][MAX];
 	
int main(){
	fastio;
	ll n,k;
	cin>>n;
	f(i,1,n+1) cin>>k,c[i]={k,i};
	sort(c+1,c+n+1);
	f(i,1,n+1){
		f(j,1,i+1){
			dp[j][i-j]= max(dp[j][i-j],dp[j-1][i-j]+abs(c[i].ind - j)*c[i].v  );
			dp[i-j][j] =max(dp[i-j][j],dp[i-j][j-1]+abs(n-(j-1) - c[i].ind )*c[i].v  );
		}
	}
	ll ans=0;
	f(i,1,n+1) ans=max(ans,dp[i][n-i]);
	cout<<ans<<endl;
	return 0;	
}

Compiler output:
main.c:1:10: fatal error: bits/stdc++.h: No such file or directory
    1 | #include <bits/stdc++.h>
      |          ^~~~~~~~~~~~~~~
compilation terminated.
Language: C++

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int long long
int dp[2010][2010];
int a[2010];
struct node
{
    int first;
    int second;
}c[5001];


bool cmp(node p1,node p2)
{
    return p1.second>p2.second;
}

int work(int now,int l,int r)
{
	if (l>r)  return c[now].second;
	if (dp[l][r]!= -1)  return dp[l][r];

	int f=work(now+1,l+1,r)+c[now].second*abs(c[now].first-l);
	int s=work(now+1,l,r-1)+c[now].second*abs(c[now].first-r);
	dp[l][r]=max(dp[l][r], max(f,s) );

	return dp[l][r];
}
int main()
{
    int n;
    cin>>n;
    memset(dp,-1,sizeof(dp));
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        c[i].second = a[i];
        c[i].first = i;
    }
    sort(c+1,c+1+n,cmp);
    cout<<work(1,1,n);
    /*
    for(int l=1;l<=n;l++)
    {
        for(int r=1;r<=n;r++)
        {
            if(l+r==n+1)
            {
                ans=max(ans,dp[l][r]);
            }
            cnt=l+r-1;
            dp[l+1][r]= max(dp[l+1][r],dp[l][r]+abs(c[cnt].first-l)*c[cnt].second);
            dp[l][r-1]= max(dp[l][r-1],dp[l][r]+abs(r - c[cnt].first)*c[cnt].second);
        }
    }*/
    //cout<<ans<<endl;
}

Compiler output:
cc1plus: error: '::main' must return 'int'
Language: C++

#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

long long dp[2005][2005] = {};

long long main() {
    
    long long n;
    cin >> n;
    vector<pair<long long, long long>> a(n + 1);
    dp[2005][2005] = {};
    for (long long i = 1; i < n + 1; ++i) cin >> a[i].first, a[i].second = i;
    sort(a.begin() + 1, a.end(), greater<pair<long long, long long>>());
    for (long long i = 1; i < n + 1; ++i) {
        for (long long j = 0; j < i; ++j) {
            long long L = j;
            long long R = i - 1 - j;
            dp[L + 1][R] = max(
                dp[L + 1][R],
                dp[L][R] + abs(L + 1 - a[i].second) * a[i].first
            );
            R = j;
            L = i - 1 - j;
            dp[L][R + 1] = max(
                dp[L][R + 1],
                dp[L][R] + abs(n - R - a[i].second) * a[i].first
            );
        }
    }
    long long ans = 0;
    for (long long i = 1; i < n + 1; ++i) {
        ans = max(ans, dp[i][n - i]);
    }
    cout << ans << endl;

    return 0;
}

Compiler output:
cc1plus: error: '::main' must return 'int'
Language: C++

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll dp[2005][2005];   // dp[i][j] 前 i 个人放了 j 个左边的
ll n,ma;
struct stu
{
    ll pos,w;
}a[2004];
bool cmp(stu u,stu v)
{
    return u.w>v.w;
}
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        scanf("%lld",&a[i].w);
        a[i].pos=i;
    }
    sort(a+1,a+n+1,cmp);
    memset(dp,-1,sizeof(dp));
    dp[0][0]=0;
    for(int i=1;i<=n;i++)
    {
        memset(dp[i],-1,sizeof(dp[i]));
        for(int j=0;j<=i;j++)
        {
            if(dp[i-1][j]!=-1){
             dp[i][j]=max(dp[i-1][j-1]+a[i].w*abs(a[i].pos-n+i-j-1),
                         dp[i-1][j]+a[i].w*abs(a[i].pos-j-1));
            }
            //if(dp[i-1][j]!=-1){
            //dp[i][j]=max(dp[i][j],dp[i-1][j]+a[i].w*abs(a[i].pos-n+i-j-1));    // 放在右边
            //dp[i][j+1]=max(dp[i][j+1],dp[i-1][j]+a[i].w*abs(a[i].pos-j-1));    // 放在左边
            }
        }
    }
    for(int i=0;i<=n;i++)
    {
        ma=max(ma,dp[n][i]);
    }
    cout<<ma;
    return 0;
}


Compiler output:
a.cc:40:5: error: expected unqualified-id before 'for'
   40 |     for(int i=0;i<=n;i++)
      |     ^~~
a.cc:40:17: error: 'i' does not name a type
   40 |     for(int i=0;i<=n;i++)
      |                 ^
a.cc:40:22: error: 'i' does not name a type
   40 |     for(int i=0;i<=n;i++)
      |                      ^
a.cc:44:5: error: 'cout' does not name a type
   44 |     cout<<ma;
      |     ^~~~
a.cc:45:5: error: expected unqualified-id before 'return'
   45 |     return 0;
      |     ^~~~~~
a.cc:46:1: error: expected declaration before '}' token
   46 | }
      | ^
Language: C

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e3+5;
vector<pair<ll,ll> >v(N);
ll dp[N][N];
int n;
ll fun(int l,int r){
	if(l>r) return 0;
	if(dp[l][r]) return dp[l][r];
	int i=n-(r-l+1);
	return dp[l][r]=max(fun(l,r-1)+v[i].first*(r-v[i].second),fun(l+1,r)+v[i].first*(v[i].second-l));
}
int main(){
	scanf("%d",&n);
	for(int i=0,x;i<n;i++)
		scanf("%d",&x),v.push_back({x,i});
	sort(v.rbegin(),v.rend());
	fun(0,n-1);
	printf("%lld\n",dp[0][n-1]);
	return 0;
}

Compiler output:
main.c:1:9: fatal error: bits/stdc++.h: No such file or directory
    1 | #include<bits/stdc++.h>
      |         ^~~~~~~~~~~~~~~
compilation terminated.
Language: C++

#include <iostream>
#include <vector>
using namespace std;

int n, a, dp[2005][2005];
vector <pair<int, int> > v;

int solve(int l, int r){
    if (~dp[l][r]) return dp[l][r];
    if (l > r) return dp[l][r] = 0;
    int idx = (r-l);
    return max(solve(l+1, r) + abs(v[idx].second-l)*v[idx].first , solve(l, r-1) + abs(r-v[idx].second)*v[idx].first);
}

int main() {
    cin >> n;
    memset(dp, -1, sizeof(dp));
    for (int i = 0; i < n; i++){
        cin >> a;
        v.push_back({a, i});
    }
    sort(v.begin(), v.end());
    cout << solve(0, n-1) << "\n";
}


Compiler output:
a.cc: In function 'int main()':
a.cc:17:5: error: 'memset' was not declared in this scope
   17 |     memset(dp, -1, sizeof(dp));
      |     ^~~~~~
a.cc:3:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
    2 | #include <vector>
  +++ |+#include <cstring>
    3 | using namespace std;
a.cc:22:5: error: 'sort' was not declared in this scope; did you mean 'short'?
   22 |     sort(v.begin(), v.end());
      |     ^~~~
      |     short
Language: C

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

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,int> plli;

long long MOD = 10000000000 + 7;

bool compare(plli x, plli y){
  return x.first > y.first;
}

int main(){
  cout << setprecision(10);
  int N;
  cin >> N;
  vector<plli> v(N);

  for(int i = 0; i < N; i++){
    ll tmp;
    cin >> tmp;
    v.at(i) = make_pair(tmp, i);
  }

  sort(v.begin(), v.end(), compare);

  // cerr << v[0].first << " " << v[0].second << endl;

  vector<vector<ll>> dp(N+1, vector<ll>(N+1, 0)); 
  // dp[i][j] : 左にi個、右にj個入れたときの最大
  for(int k = 1; k <= N; k++){
    // dp[i][j]: i+j = k を走査する
    for(int i = 0; i <= k; i++){
      int j = k - i;
      if(i-1>=0) dp[i][j] = max(dp[i][j], dp[i-1][j] + v[k-1].first * abs(v[k-1].second - i + 1) );
      if(j-1>=0) dp[i][j] = max(dp[i][j], dp[i][j-1] + v[k-1].first * abs(N-j - v[k-1].second));
    }
  }
  ll ans = 0;
  for(int i = 0; i <= N; i++){
    ans = max(ans, dp.at(i).at(N-i));
  }
  cout << ans << endl;
}


Compiler output:
main.c:1:9: fatal error: bits/stdc++.h: No such file or directory
    1 | #include<bits/stdc++.h>
      |         ^~~~~~~~~~~~~~~
compilation terminated.
Language: C

//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
typedef long double lb;
#define int long long
#define double long double
#define endn "\n"
typedef pair<int,int> P;
template<class T> inline bool chmin(T& a, T b){if(a>b){a = b;return 1;}return 0;}
template<class T> inline bool chmax(T& a, T b){if(a<b){a = b;return 1;}return 0;}
const int MOD = 1000000007;
//const int MOD = 998244353;
template<class T> inline int add(T& a, T b, T M = MOD){a=(a+M)%M;b=(b+M)%M;a=(a+b)%M;return a;};
template<class T> inline int mul(T& a, T b, T M = MOD){if(a>=M)a%=M;if(b>=M)b%=M;a*=b;if(a>=M)a%=M;return a;};
const ll INF = 1e16;
const double EPS = 1e-10;
const double PI = 3.141592653589793;
const string abc="abcdefghijklmnopqrstuvwxyz";
const string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 

////////////////////////////////////////////////////////////////////
///////////////////////___modpow___////////////////////
ll modpow(ll a,  ll n, const ll &MOD = MOD){
  ll ret = n == 0 ? 1 : modpow(a, n/2, MOD);
  (ret *= ret) %= MOD;
  if(n%2)((ret *= a) %= MOD);
  return ret;
}
///////////////////////___modinv___////////////////////
ll modinv(ll d, const ll &MOD = MOD){
  return modpow(d, MOD-2, MOD);
}
////////////////////////////////////////////////////////////////////

int n, dp[2100][2100];P a[2100];
signed main() {
  cin>>n;rep(i,n)cin>>a[i].first, a[i].second = i;
  sort(a,a+n,greater<int>());
  dp[0][1] = a[0].first*a[0].second;
  dp[0][0] = a[0]*(n-a[0].second-1);
  repd(i,1,n){
    rep(j,n){
      dp[i][j] = max(dp[i-1][j]+a[i]*(n-a[i].second-1), dp[i-1][j-1]+a[i]*(a[i].second-j));
    }
  }
  int ans = 0;
  rep(i,n)chmax(ans, dp[n-1][i]);
  cout << ans << endl;
}



Compiler output:
main.c:2:10: fatal error: bits/stdc++.h: No such file or directory
    2 | #include <bits/stdc++.h>
      |          ^~~~~~~~~~~~~~~
compilation terminated.
Language: C

#include <cstdio>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <cassert>
#include <numeric>
#include <functional>
#include <cassert>
#pragma warning(disable:4996) 
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF  9223300000000000000
#define LINF2 1223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;

using namespace std;

ll dp[2005][2005];

void solve()
{
    int n;
    scanf("%d", &n);
    vector<pair<int,int> > z(n);  // val,id
    int i,j;
    for (i = 0; i < n; i++) {
        int tmp;
        scanf("%d", &tmp);
        z[i] = make_pair(tmp, i);
    }
    sort(z.rbegin(), z.rend());

    for (i = 0; i <= n; i++) {
        for (j = 0; j <= n; j++) {
            dp[i][j] = -1;
        }
    }
    dp[0][0] = 0;
    for (i = 0; i < n; i++) {
        for (j = 0; j <= i; j++) {
            if (dp[i][j] < 0) continue;

            int val = z[i].first;
            int id  = z[i].second;
            dp[i + 1][j+1] = MAX(dp[i + 1][j+1], dp[i][j]+(ll)val*(id-j));
            dp[i + 1][j] = MAX(dp[i + 1][j], dp[i][j]+(ll)val*(n-1-(i-j)-id));
        }
    }

    ll ans = 0;
    for (j = 0; j <= n; j++) {
        ans=MAX(ans, dp[n][j]);
    }
    printf("%lld\n", ans);

    return;
}

int main(int argc, char* argv[])
{
#if 1
    solve();
#else
    int T;
    scanf("%d", &T);
    int t;
    for(t=0; t<T; t++) {
        //printf("Case #%d: ", t+1);
        solve();
    }
#endif
    return 0;
}



Compiler output:
main.c:1:10: fatal error: cstdio: No such file or directory
    1 | #include <cstdio>
      |          ^~~~~~~~
compilation terminated.
Language: C

#include <bits/stdc++.h>

using namespace std;

#define FOR(i, n) for(int i = 0; i < (int) n; i++)
#define rall(x) x.rbegin(), x.rend()
#define all(x) x.begin(), x.end()
#define PB push_back
#define F first
#define S second

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;

#define MAX 10000007

int n;
vector<pii> v;

ll dp[2007][2007];

ll solve(int l, int r){
    if(dp[l][r] != -1) return dp[l][r];


    ll atual = v[l+n-r-1].F;
    int idx = v[l+n-r-1].S;

    if(l==r){
        return atual*abs(idx-l);
    }

    ll a1 = solve(l+1, r) + atual*abs(idx-l);
    ll a2 = solve(l, r-1) + atual*abs(idx-r);

    return dp[l][r] = max(a1, a2);

}

int main(){
	ios::sync_with_stdio(false); cin.tie(0);

    memset(dp, -1, sizeof(dp));

	cin >> n;
    v.resize(n);
    FOR(i, n) cin >> v[i].F, v[i].S = i;

    sort(rall(v));


    cout << solve(0, n-1) << '\n';

	return 0;
}


Compiler output:
main.c:1:10: fatal error: bits/stdc++.h: No such file or directory
    1 | #include <bits/stdc++.h>
      |          ^~~~~~~~~~~~~~~
compilation terminated.
Language: C

/*input
6
8 6 9 1 2 1
*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 

#define rep(i,j,n) for(i=j;i<n;i++)
#define repi(i,j,n) for(i=j;i>n;i--)
#define inf 100001
#define M 1000000007
#define ll long long
#define ld long double
#define vll vector<long long>
#define vi vector<int>
#define pll pair<long long,long long>
#define pii pair<int,int>
#define vpii vector<pair<int,int> >
#define vpll vector<pair<long long,long long> >
#define pb push_back
#define pf pop_front
#define F first
#define S second
#define endl '\n'

using namespace std;
using namespace __gnu_pbds; 

template<typename T>
using ordered_set=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;


ll power(ll a,ll m,ll mod){
	ll ans=1;
	while(m){
		if(m%2){
			ans*=a;
			ans%=(mod);
		}
		a=(a*a)%(mod);
		m>>=1;
	}
	return ans;
}


void init(ll* a,ll n,ll val){
	for(ll i=0;i<n;i++)
		a[i]=val;
}



int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);	
	ll t=1,i,j;
	ll n;
	cin>>n;
	ll dp[n+2][n+2];
	memset(dp,0,sizeof(dp));
	ll a;
	vpll v;
	rep(i,0,n)cin>>a,v.pb({a,i});
	sort(v.begin(),v.end());
	reverse(v.begin(),v.end());

	rep(i,0,n){
		rep(j,1,i+2){
			dp[j][n-(i+1-j)+1]=max(dp[j][n-(i+1-j)+1],dp[j-1][n-(i+1-j)+1]+(abs(v[i].S-(j-1)))*v[i].F);
		}
		repi(j,n,n-i-1){
			dp[i+j-n][j]=max(dp[i+j-n][j],dp[i+j-n][j+1]+abs(v[i].S-j+1)*v[i].F);
		}
	}
	ll ans=0;
	rep(i,0,n+1)ans=max(ans,dp[i][i+1]);
	cout<<ans<<endl;
	return 0;
}




Compiler output:
main.c:6:10: fatal error: bits/stdc++.h: No such file or directory
    6 | #include <bits/stdc++.h>
      |          ^~~~~~~~~~~~~~~
compilation terminated.
Language: C

#include <bits/stdc++.h>
#define WHOLE(v) (v).begin(), (v).end()
#define REV_WHOLE(v) (v).rbegin(), (v).rend()
using i64 = int64_t;
using namespace std;
template<class F>auto recursive(F f){return[f](auto...a){return f(f,a...);};}
template<class I,class V=typename I::value_type>V sum_up(const I&l,const I&r){V v;for(I i=l;i!=r;i++)v=i==l?*i:v+*i;return v;}
template<class I,class T=iterator_traits<I>>I operator+(I it,int n){for(int i=0;i<n;i++)it++;return it;}
template<class I,class T=iterator_traits<I>>I operator-(I it,int n){for(int i=0;i<n;i++)it--;return it;}
template<class T>using rev_priority_queue=priority_queue<T,vector<T>,greater<T>>;
template<class T>using vector2d=vector<vector<T>>;
struct fixprec{int p;fixprec(int p):p(p){}};
ostream&operator<<(ostream&o,fixprec f){return o<<fixed<<setprecision(f.p);}
void R_YESNO(bool p){cout<<(p?"YES":"NO")<<endl;}
void R_YesNo(bool p){cout<<(p?"Yes":"No")<<endl;}

int main() {
    int N;
    cin >> N;
    vector<i64> A(N);
    for(i64 &a : A) cin >> a;
    vector<int> x(N);
    for(int i = 0; i < N; i++) x[i] = i;
    for(int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            for (int k = 0; k < N; k++) {
                int i0 = x[i], j0 = x[j], k0 = x[k];
                i64 cur = A[i0] * abs(i0 - i) + A[j0] * abs(j0 - j) + A[k0] * abs(k0 - k);
                i64 nxt = A[i0] * abs(i0 - j) + A[j0] * abs(j0 - k) + A[k0] * abs(k0 - i);
                if (cur < nxt) {
                    swap(x[i], x[j]);
                    swap(x[i], x[k]);
                }
            }
        }
    }
    i64 ans = 0;
    for(int i = 0; i < N; i++) {
        ans += A[x[i]] * abs(x[i] - i);
    }
    cout << ans << endl;
    return 0;
}



Compiler output:
main.c:1:10: fatal error: bits/stdc++.h: No such file or directory
    1 | #include <bits/stdc++.h>
      |          ^~~~~~~~~~~~~~~
compilation terminated.
Language: C

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

using lnt = long long;
using Real = long double;

#define ALL(obj) (obj).begin(),(obj).end()
#define RALL(obj) (obj).rbegin(),(obj).rend()
#define REP(i, n) for(lnt i=0;i<(n);++i)
#define RANGE(i, a, b) for(lnt i=(a);i<(b);++i)
#define RREP(i, n) for(lnt i=(n)-1;i>= 0;--i)

#define ln '\n'
#define pb push_back
#define eb emplace_back
#define pque priority_queue
#define umap unordered_map
#define uset unordered_set
#define dcout cout<<fixed<<setprecision(20)
#define summon_tourist cin.tie(0);ios::sync_with_stdio(false)

constexpr int dx[]={1,0,-1,0,1,1,-1,-1}, dy[]={0,-1,0,1,1,-1,1,-1};
constexpr Real eps = 1e-9; const Real pi = acosl(-1);
constexpr lnt BIG = INT_MAX/10, BBIG = LLONG_MAX/10;

template<class T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template<class T> inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template<class T> inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template<class T> inline T nHr(T a,T b){return nCr(a+b-1,b);}
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}

using pint = pair<int, int>; using plnt = pair<lnt, lnt>;
using vint = vector<int>; using vlnt = vector<lnt>;
constexpr lnt MOD = 1e9+7;

lnt dp[2010][2010];

int main(){
    summon_tourist;

	lnt N, A[2000]; cin >> N;
    map<lnt, lnt, greater<lnt> > mp;
    REP(i, N) {
        cin >> A[i];
        mp.emplace(A[i], i);
    }
    REP(i, N+5) REP(j, N+5) dp[i][j] = -BBIG;
    dp[0][0] = 0;
    sort(A, A+N); reverse(A, A+N);
    auto itr = mp.begin();
    REP(i, N){
        lnt num = itr->first, idx = itr->second;
        // cerr << num << ' ' << idx << endl;
        REP(left, i+1){
            lnt right = i-left;
            chmax(dp[left+1][right], dp[left][right] + num*abs(idx-left));
            chmax(dp[left][right+1], dp[left][right] + num*abs(idx-(N-right-1)));
        }
        itr++;
    }
    lnt ans = 0;
    REP(i, N+1){
        chmax(ans, dp[i][N-i]);
    }
    cout << ans << ln;
}


Compiler output:
main.c:1:9: fatal error: bits/stdc++.h: No such file or directory
    1 | #include<bits/stdc++.h>
      |         ^~~~~~~~~~~~~~~
compilation terminated.