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

#include <bits/stdc++.h>

using namespace std;

const int N = 2005;
long long n;
pair<long long, long long> arr[N];
deque<long long> dq;

bool cmp(pair<long long, long long> a, pair<long long, long long> b){
    if(a.first == b.first){
        return a.second > b.second;
    } else {
        return a.first > b.first;
    }
}

int main(){

    cin >> n;
    for(int i = 1; i <= n; i++){
        int a;
        cin >> a;
        arr[i] = {a, i};
        dq.push_back(a);
    }
    sort(arr + 1, arr + 1 + n, cmp)
    long long ans = 0;
    int ptr = 1;
    while(ptr <= n){
        long long tp = arr[ptr].second;
        if(abs(tp - dq.front()) > abs(tp - dq.back())){
            ans += abs(tp - dq.front()) * pq.top().first;
            dq.pop_front();
        } else {
            ans += abs(tp - dq.back()) * pq.top().first;
            dq.pop_back();
        }
        ptr++;
    }

    cout << ans << '\n';

    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:27:36: error: expected ';' before 'long'
   27 |     sort(arr + 1, arr + 1 + n, cmp)
      |                                    ^
      |                                    ;
   28 |     long long ans = 0;
      |     ~~~~                            
a.cc:33:13: error: 'ans' was not declared in this scope; did you mean 'abs'?
   33 |             ans += abs(tp - dq.front()) * pq.top().first;
      |             ^~~
      |             abs
a.cc:33:43: error: 'pq' was not declared in this scope; did you mean 'dq'?
   33 |             ans += abs(tp - dq.front()) * pq.top().first;
      |                                           ^~
      |                                           dq
a.cc:36:13: error: 'ans' was not declared in this scope; did you mean 'abs'?
   36 |             ans += abs(tp - dq.back()) * pq.top().first;
      |             ^~~
      |             abs
a.cc:36:42: error: 'pq' was not declared in this scope; did you mean 'dq'?
   36 |             ans += abs(tp - dq.back()) * pq.top().first;
      |                                          ^~
      |                                          dq
a.cc:42:13: error: 'ans' was not declared in this scope; did you mean 'abs'?
   42 |     cout << ans << '\n';
      |             ^~~
      |             abs
Language: C

#include <iostream>
#include <cstdio>
#include <cstring>
#include <climits>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <sstream>
#include <numeric>
// # #include <boost/multiprecision/cpp_dec_float.hpp>
// #include <boost/multiprecision/cpp_int.hpp>

// namespace
using namespace std;
// namespace mp = boost::multiprecision;

// types
using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
// using mpi = mp::cpp_int;
// using mpf = mp::number<mp::cpp_dec_float<1024>>;

// consts
int MOD = 1000000007;  // https://qiita.com/drken/items/3b4fdf0a78e7a138cd9a

struct Swap { ll v; int x; int y; };

int main() {
    ll n, a;
    cin >> n;
    vector<pll> v;
    for (ll i = 0; i < n; ++i) {
        cin >> a;
        v.emplace_back(make_pair(a, i));
    }
    sort(v.begin(), v.end());
    reverse(v.begin(), v.end());
    vector<vector<ll>> dp(n + 1, vector<ll>(n + 1, INT_MIN));
    dp[0][0] = 0;
    for (int k = 0; k < n; ++k) {
        for (int i = 0; i <= k + 1; ++i) {
            int j = k - i + 1;
            // k = 0 i = 0 j = 1
            // k = 0 i = 1 j = 0
            // k = n-1 i = 0 j = n
            // k = n-1 i = n j = 0
            ll A = v[k].first;
            ll i0 = v[k].second;
            if (i-1 >= 0) dp[i][j] = max(dp[i][j], dp[i-1][j] + A * abs(i - 1 - i0));
            if (j-1 >= 0) dp[i][j] = max(dp[i][j], dp[i][j-1] + A * abs(n - j - i0));
            // cout << "i " << i << "\tj " << j << "\ti0 " << i0 << "\tA " << A << "\tdp[i][j] " << dp[i][j] << endl;
        }
    }
    ll ans = 0;
    for (ll i = 0; i <= n; ++i) {
        ll j = n - i;
        ans = max(ans, dp[i][j]);
    }
    cout << ans << endl;
    return 0;
}


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;
int main()
{
    int a,b,c,d,e,i,j,k,t,n,s=0;
    scanf("%d",&n);
    b=0, c=n-1;
    int a1[n],a2[n],a3[n];
    for(i=0; i<n; i++)
    {
        scanf("%d",&a1[i]);
        a2[i]=a1[i];
    }
    sort(a2,a2+n,greater<int>());
    for(i=0; i<n; i++)
    {
        for(j=0; j<n; j++)
        {
            if(a2[i]==a1[j])
            {
                if((j-b)>=(c-j))
                {
                    s=s+(j-b)*a2[i];
                    b++;
                }
                else
                {
                    s=s+(c-j)*a2[i];
                    c--;
                }
            }
        }
    }
    printf("%d",s);
}


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.h>
using namespace std;
typedef long long ll;

int fun(vector<int> vec,int id,vector<int> vis,int n){
	if(id==n){
		return 0;
	}
	int ma=INT_MIN;
	for(int i=0;i<n;i++){
		if(!vis[i]){
			vis[i]=1;
			ma=max(ma,vec[id]*abs(i-id)+fun(vec,id+1,vis,n));
			vis[i]=0;
		}
	}
	return ma;
}

int main() {
   int n;
   cin>>n;
   vector<int> ar;
   for(int i=0;i<n;i++){
   	int a;cin>>a;
   	ar.push_back(a);
   }
   vector<int> visi(n+1,0);
   cout<<fun(ar,0,visi,n);
    return 0;
}


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

#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
const int inf=1e9+7;
const ll mod=1e9+7;

long DP[2005][2005];

int main() {
    int N;
    cin>>N;
    vector<pair<long, int> > A(N);
    long tmp;
    for(int i=0;i<N;++i){
        cin>>tmp;
        A[i] = make_pair(tmp, i);
    }
    sort(A.begin(), A.end(), greater<pair<long, int> >() );
    int r;
    for(int i=1;i<=N;++i){
        for(int l=0;l<=i;++l){
            r = i - l;
            if(l==0){
                DP[l][r] = DP[l][r-1]+A[i-1].fi*abs(A[i-1].se-(N-r));
            }
            else if(r==0){
                DP[l][r] = DP[l-1][r]+A[i-1].fi*abs(A[i-1].se-(l-1));
            }
            else{
                DP[l][r] = max(DP[l-1][r]+A[i-1].fi*abs(A[i-1].se-(l-1)), DP[l][r-1]+A[i-1].fi*abs(A[i-1].se-(N-r)));
            }
        }
    }
    long ans = 0;
    for(int i=0;i<=N;++i){
        if(DP[N-i][i]>ans)ans = DP[N-i][i];
    }
    cout<<ans<<endl;
}


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

#include<bits/stdc++.h>
const int mod=1e9+7;
typedef long long ll;
const int N=2e3+5;

int n;
std::vector<std::pair<ll,int> > v;
ll dp[N][N];
ll solve(int l,int r)
{
	if(dp[l][r]>=0) return dp[l][r];
	if(r<l) return dp[l][r]=0;
	int i=n-r+l;//当前正在放第i个
	return std::max(
		v[i].first*std::abs(v[i].second-l)+solve(l+1,r),
		v[i].first*std::abs(v[i].second-r)+solve(l,r-1)
	);
}
int main()
{
	// freopen("a.in","r",stdin);
	scanf("%d",&n);
	v.push_back(std::make_pair(0,0));
	for(int i=1;i<=n;i++)
	{
		ll j;
		scanf("%lld",&j);
		v.push_back(std::make_pair(j,i));
	}
	std::sort(v.rbegin(),v.rend()-1);
	memset(dp,-1,sizeof(dp));
	printf("%lld\n",solve(1,n));
	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 <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)

int main() {
    int n;
    cin >> n;
    vector<pair<ll, int>> a(n);
    rep(i,n){
        ll x;
        cin >> x;
        a[i] = make_pair(x, i);
    }
    sort(a.rbegin(), a.rend());

    vector<vector<ll>> dp(n+1, vector<ll>(n+1, 0));

    ll ans = 0;
    for (int l = 0; l < n; l++) {
        for(int r = 0; r < n; r++){
            if(l+r == n){
                ans = max(ans, dp[l][r]);
                break;
            }
            ll activeness = a[l+r].first;
            int index = a[l+r].second;
            dp[l + 1][r] = max(dp[l + 1][r], dp[l][r] +abs(index - l) * activeness);
            dp[l][r+1] = max(dp[l][r+1], dp[l][r] +abs(index - (n-1-r)) * activeness);
        }
    }
    cout << ans << endl;
}

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 <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <list>
#include <numeric>
#include <stack>
#include <iomanip>
#include <random>
#include <complex>
#include <functional>
#include <tuple>

using namespace std;

#define Rep(i,a,b) for(ll i = a; i < b; ++i)
#define rep(i,b) Rep(i,0,b)
#define allof(a) (a).begin(), (a).end()

#define Yes(q) ((q) ? "Yes" : "No")
#define YES(q) ((q) ? "YES" : "NO")
#define Possible(q) ((q) ? "Possible" : "Impossible")
#define POSSIBLE(q) ((q) ? "POSSIBLE" : "IMPOSSIBLE")

using ll = long long;

constexpr int inf = 1e9 + 7;
constexpr ll infll = 1ll << 60ll;
constexpr ll mod = 1e9 + 7;
// 0~3までは右左下上 4~7までは斜め
constexpr int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
constexpr int dy[] = { 0, -1, 0, 1, 1, -1, -1, 1 };

namespace {
    template<typename T> void chmax(T& a, T b) { a = std::max(a, b); }
    template<typename T> void chmin(T& a, T b) { a = std::min(a, b); }
    template<typename T> void chadd(T& a, T b) { a = a + b; }

    void Cout(long long x, const char* end = "\n") { std::cout << x << end; }
    template <typename T> void Cout(const T& x, const char* end = "\n") { std::cout << x << end; }
    template <typename T> void Cout(const std::vector<T>& x, const char* sep = " ", const char* end = "\n") { for (std::size_t i = 0, sz = x.size(); i < sz; i++) { std::cout << x[i] << (i == sz - 1 ? end : sep); } }

    // 標準入出力
    struct inp {
        std::size_t sz;
        inp(std::size_t _sz = 1) : sz(_sz) {}
        template <typename T> operator T () const { T a; std::cin >> a; return a; }
        template <typename T> operator std::vector<T>() const { vector<T> a(sz); for (std::size_t i = 0; i < sz; i++) std::cin >> a[i]; return a; }
        template <typename T, typename U> operator std::pair<T, U>() const { T f; U s; std::cin >> f >> s; return std::pair<T, U>(f, s); }
    };

    inp inp1; // input one

    struct Child {
        ll value;
        int prev;
    };
}

int main() {

    int n = inp1;
    vector<ll> a = inp(n);
    vector<Child> childs(n);
    rep(i, n) {
        childs[i].value = a[i];
        childs[i].prev = i;
    }

    // 大きいやつから左端に行くか右端に行くか選択する
    sort(allof(childs), [](Child& lhs, Child& rhs) {
        return lhs.value > rhs.value;
        });

    // dp[i][j] := i人見たときに，左にj人送った時のうれしさの最大値
    vector<vector<ll>> dp(n + 1, vector<ll>(n + 1, 0LL));

    rep(i, n) { // i+1人目を移動
        rep(j, i + 1) { // すでにj人左に送った
            // 右に送った数
            int right = i - j;
            // 左に送る
            chmax(dp[i + 1][j + 1], dp[i][j] + childs[i].value * abs(childs[i].prev - j));
            // 右に送る
            chmax(dp[i + 1][j], dp[i][j] + childs[i].value * abs(childs[i].prev - (n - right - 1)));
        }
    }

    ll ans = 0LL;
    rep(i, n + 1) { // 左に送った人の数
        chmax(ans, dp[n][i]);
    }

    Cout(ans);

    return 0;
}


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>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ok() puts(ok?"Yes":"No");
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef set<int> si;
typedef map<string, int> msi;
typedef greater<int> gt;
typedef priority_queue<int, vector<int>, gt> minq;
typedef long long ll;
const ll LINF = 1e18L + 1;
const int INF = 1e9 + 1;
//clang++ -std=c++11 -stdlib=libc++ 

int main() {
  int N; cin>>N;
  vi A(N);
  rep(i,N) cin >> A[i];
  vii ord(N);
  rep(i,N) ord[i] = ii(i, A[i]);
  sort(ord.begin(), ord.end(), [](ii a, ii b) {return a.second>b.second;});
  vector<vector<ll>> dp(N+1, vector<ll>(N+1,0)); // total when there's l babies on the left and r on the right

  ll ans = 0;
  rep(l, N) {
    rep(r,N) {
      if (l+r==N) {
        ans = max(ans, dp[l][r]);
        break;
      }
      int idx = l+r;
      dp[l+1][r] = max(dp[l+1][r], dp[l][r]+ord[idx].second*abs(ord[idx].first-l));
      dp[l][1+r] = max(dp[l][r+1], dp[l][r]+ord[idx].second*abs((N-1-r) - ord[idx].first));
    }
  }
 printf("%lld\n", 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 <bits/stdc++.h>
using namespace std;

template<class T>
void chmax (T &a, const T &b) {
    if (a < b) a = b;
}

int main() {
    int n;
    cin >> n;
    vector<pair<long long, int>> a;
    for (int i = 0; i < n; i++) {
        long long e;
        cin >> e;
        a.emplace_back(e, i);
    }
    
    sort(a.rbegin(), a.rend());
    
    long long dp[2020][2020] = {};
    for (int i = 0; i < n; i++) {
        const long long val = a[i].first;
        const int &id = a[i].second;
        for (int x = 0; x <= i; x++) {
            const int y = i - x;
            chmax(dp[x + 1][y], dp[x][y] + val * abs(x - id));
            chmax(dp[x][y + 1], dp[x][y] + val * abs(n - y - 1 - id));
        }
    }
    
    long long ans = 0;
    for (int i = 0; i < n; i++) {
        chmax(ans, dp[i][n - i]);
    }
    
    cout << ans << '\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

#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
template <typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
const int INT_INF = 1 << 30;
#define MOD 1000000007LL

int main(){
  ll N;
  cin >> N;
  vector<Pll> A(N, Pll(0LL, 0LL));
  for(ll i = 0; i < N; i++){
    cin >> A.at(i).first;
    A.at(i).second = i;
  }
  sort(ALL(A), greater<Pll>());
  vvll dp(N+1, vll(N+1, 0));
  ll ans = 0;
  for(int ij = 1; ij <= N; ij++){ //合計i人
    for(int i = 0; i <= ij; i++){ //左がi人
      int j = ij - i;
      if(i-1 >= 0) chmax(dp.at(i).at(j), dp.at(i-1).at(j) + A.at(ij-1).first * (A.at(ij-1).second - (i-1))); //左からi番目にij人目
      if(j-1 >= 0) chmax(dp.at(i).at(j), dp.at(i).at(j-1) + A.at(ij-1).first * (N-j - A.at(ij-1).second)); //右にij人目
      if(ij == N) chmax(ans, dp.at(i).at(j));
    }
  }
  cout << ans << endl;
}


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 <functional>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <queue>
// #include <prettyprint.hpp>
using namespace std;
typedef long long ll;
static const ll max_h = 12;
static const ll max_w = 1010;
static const ll max_value = -10000000000;
static const ll max_num = 2010;
// static const ll mod = 1000000007;
// vector<vector<ll>> F(max_h, vector<ll>(max_w, 0));
vector<pair<ll, ll>> infant_list(max_num);
vector<vector<ll>> dp(max_num, vector<ll>(max_num, 0));
ll ans = 0;
ll N;


int main(){
    // int u, v;
    // bool updated = false;
    // ll ans = 0;
    ll A;
    scanf("%lld", &N);
    for(ll i=0;i<N;i++){
        scanf("%lld", &A);
        infant_list[i] = make_pair(i+1, A);
    }

    sort(
        infant_list.begin(), 
        infant_list.begin()+N,
        [](const pair<ll,ll>& x, const pair<ll,ll>& y){return x.second > y.second;}
    );

    dp[0][0] = 0;
    for(ll i=1;i<=N;i++){
        for(ll x=0;x<=i;x++){
            ll y = i - x;
            pair<ll, ll> last_infant = infant_list[i-1];
            ll value_add_to_y = max_value, value_add_to_x = max_value;
            if(y>0){
                value_add_to_y = last_infant.second * (N-y+1 - last_infant.first) + dp[x][y-1];
            }
            if(x > 0){
                value_add_to_x = last_infant.second * (last_infant.first - x) + dp[x-1][y];
            }
            // cout << last_infant <<"N-y+1=" << N-y+1<< endl;
            // printf("x+y = %lld, x=%lld, y=%lld, value y=%lld, value x = %lld\n", i, x, y, value_add_to_y, value_add_to_x);
            dp[x][y] = max(value_add_to_x, value_add_to_y);
        }
    }

    ll ans = max_value;
    for(ll i=0;i<=N;i++){
        ans = max(dp[i][N-i], ans);
    }
    printf("%lld\n", ans);
    
    // double limit = 1. / (double)(4 * M);



    return 0;

}

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

#include <iostream>
#include <functional>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <queue>
#include <prettyprint.hpp>
using namespace std;
typedef long long ll;
static const ll max_h = 12;
static const ll max_w = 1010;
static const ll max_value = -10000000000;
static const ll max_num = 2010;
// static const ll mod = 1000000007;
// vector<vector<ll>> F(max_h, vector<ll>(max_w, 0));
vector<pair<ll, ll>> infant_list(max_num);
vector<vector<ll>> dp(max_num, vector<ll>(max_num, 0));
ll ans = 0;
ll N;


int main(){
    // int u, v;
    // bool updated = false;
    // ll ans = 0;
    ll A;
    scanf("%lld", &N);
    for(ll i=0;i<N;i++){
        scanf("%lld", &A);
        infant_list[i] = make_pair(i+1, A);
    }

    sort(
        infant_list.begin(), 
        infant_list.begin()+N,
        [](const pair<ll,ll>& x, const pair<ll,ll>& y){return x.second > y.second;}
    );

    dp[0][0] = 0;
    for(ll i=1;i<=N;i++){
        for(ll x=0;x<=i;x++){
            ll y = i - x;
            pair<ll, ll> last_infant = infant_list[i-1];
            ll value_add_to_y = max_value, value_add_to_x = max_value;
            if(y>0){
                value_add_to_y = last_infant.second * (N-y+1 - last_infant.first) + dp[x][y-1];
            }
            if(x > 0){
                value_add_to_x = last_infant.second * (last_infant.first - x) + dp[x-1][y];
            }
            // cout << last_infant <<"N-y+1=" << N-y+1<< endl;
            // printf("x+y = %lld, x=%lld, y=%lld, value y=%lld, value x = %lld\n", i, x, y, value_add_to_y, value_add_to_x);
            dp[x][y] = max(value_add_to_x, value_add_to_y);
        }
    }

    ll ans = max_value;
    for(ll i=0;i<=N;i++){
        ans = max(dp[i][N-i], ans);
    }
    printf("%lld\n", ans);
    
    // double limit = 1. / (double)(4 * M);



    return 0;

}

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;
using lint = long long;
typedef pair<lint, lint> P;

signed main(){
  lint N; cin >> N;
  vector<P> a(2010);
  for( lint i = 0; i < N; i++ ){
    lint x; cin >> x;
    a[i] = P(x, i);
  }
  sort( a.begin(), a.end(), greater<P>() );
  lint ans = 0;
  vector<vector<lint> > dp(2010, vector<lint> (2010, 0));
  for( lint l = 0; l < N; l++ ){
    for( lint r = 0; r < N; r++ ){
      if( l + r == N ){
        ans = max( ans, dp[l][r] );
        break;
      }
      dp[l + 1][r] = max( dp[l + 1][r], dp[l][r] + a[l + r].first * abs(l - a[l + r].second) );
      dp[l][r + 1] = max( dp[l][r + 1], dp[l][r] + a[l + r].first * abs((N - r - 1) - a[l + r].second) );
    }
  }
  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

//Author : Sidiq Tri Pratikto
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(v) v.begin(), v.end()

using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> new_data_set;
//order_of_key(x) = number of elements stricly smaller than x
//find_by_order(x) = return x-th largest element
typedef long long LL;
const LL MOD = 1e9 + 7;
const double PI = 2 * acos(0);
LL dp[2001][2001];
int N;
vector<pair<int, int> > v;

LL rek(int idx, int l) {
	if (idx == N) return 0;
	if (dp[idx][l] == -1) {
		int kiri = l + 1, kanan = N - (idx - l);
		dp[idx][l] = max(rek(idx + 1, l + 1) + (LL)v[idx].fi * abs(v[idx].se - kiri), 
			rek(idx + 1, l) + (LL)v[idx].fi * abs(v[idx].se - kanan));
	}
	return dp[idx][l];
}

bool cmp(pair<int, int> a, pair<int, int> b) {
	return a.fi > b.fi;
}

int main() {
	memset(dp, -1, sizeof dp);
	scanf("%d", &N);
	for (int i = 1; i <= N; i++) {
		int x;
		scanf("%d", &x);
		v.pb(mp(x, i));
	}
	sort (all(v), cmp);
	LL ans = rek(0, 0);
	printf("%lld\n", ans);
}

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

#include <bits/stdc++.h>
#define exrep(i, a, b) for(long long i = a; i <= b; i++)
#define rep(i,n)for(long long i=0;i<(long long)(n);i++)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
const ll MOD=1e9+7;
const ll INF=1e18;
const int MAX=510000;
const double pi=acos(-1);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};


ll dp[2010][2010];
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false); 
  
  int n;
  cin >> n;
  vector<P>vec(n);
  rep(i,n){
    ll x;
    cin >> x;
    vec[i]=P(x,i);
  }
  sort(vec.begin(),vec.end(),greater<P>());
  ll ans=0;
  rep(l,n){
    rep(r,n){
      if(l+r==n){
        chmax(ans,dp[l][r]);
        break;
      }
      else{
        chmax(dp[l+1][r],dp[l][r]+vec[l+r].first*(abs(l-vec[l+r].second)));
        chmax(dp[l][r+1],dp[l][r]+vec[l+r].first*(abs(n-1-r-vec[l+r].second)));
              
      }
    }
  }
  cout << ans << endl;
        
}


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;
						
#define fast_cin() ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define endl '\n'
#define int long long
				
int32_t main() {
	fast_cin();  
	int n; cin >> n;
	int a[n];
	for (int i = 0; i < n; i++)
		cin >> a[i];
	int mark[n];
	memset(mark, -1, sizeof mark);
	int l = 0, r = n - 1;
	for (int i = 0; i < n; i++) {
		vector<pair<int, int> > temp;
		for (int j = 0; j < n; j++) {
			if (mark[j] == -1) {
				temp.push_back({a[j] * max(abs(j - l), abs(j - r)), j});
			}
		}
		sort(temp.begin(), temp.end(), greater<pair<int, int> >());
		int j = temp[0].second;
		int val = temp[0].first;
		if (abs(j - l) < abs(j - r)) {
			mark[j] = r;
			r--;
		} else {
			mark[j] = l;
			l++;
		}
	}
	int ans = 0;
	for (int i = 0; i < n; i++) {
		ans += abs(mark[i] - i) * a[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;

#define int long long int
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

const int mod = 1e9 + 7;
const int N = 2002;

int n , dp[N][N];
pair<int , int> arr[2002];

int ans(int idx , int start , int end) {
    if(end < start) return 0;
    int& get = dp[idx][start];
    if(get != -1) return dp[idx][start];
    get = max((arr[idx].first * abs(arr[idx].second - start)) + ans(idx + 1 , start + 1 , end) , (arr[idx].first * abs(arr[idx].second - end)) + ans(idx + 1 , start , end - 1));
    return get;
}
void solve() {
    memset(dp , -1 , sizeof dp);
    cin >> n;
    for(int i = 0 ; i < n ; i ++) cin >> arr[i].first , arr[i].second = i;
    sort(arr , arr + n);
    reverse(arr , arr + n);
    int q = ans(0 , 0 , n - 1);
    cout << q;
}

/*
 */

int main()
{
    fastio
    int testcase = 1;
    //cin >> testcase ;
    
    while(testcase --) {
        solve();
        cout << '\n';
    }
    
    return 0;
}
 



Compiler output:
a.cc:4:23: error: '::main' must return 'int'
    4 | #define int long long int
      |                       ^~~
a.cc:33:1: note: in expansion of macro 'int'
   33 | int main()
      | ^~~
Language: C

#define LOCAL
#define _USE_MATH_DEFINES
#include <array>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
  out << "(" << a.first << "," << a.second << ")";
  return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
  return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
  return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;
mt19937 mrand(random_device{}());
int rnd(int x) { return mrand() % x; }

struct fast_ios {
  fast_ios() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
  };
} fast_ios_;

const int N = 2e3 + 10;
int64 dp[N][N];
ii a[N];

int n;
int64 solve(int L, int R) {
  if (L > R) return 0;
  int64& ret = dp[L][R];
  int pos = L + n - 1 - R;
  ret = abs(a[pos].second - L) * a[pos].first + solve(L + 1, R);
  ret = max(ret, abs(a[pos].second - R) * a[pos].first + solve(L, R - 1));
  return ret;
}

int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &a[i].first);
    a[i].second = i;
  }
  sort(a, a + n, greater<ii>());
  memset(dp, 255, sizeof(dp));
  int64 ret = solve(0, n - 1);
  printf("%lld\n", ret);
  return 0;
}


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

#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL_DEBUG
  #include "LOCAL_DEBUG.hpp"
#endif
#define int long long

template<class T> vector<T> make_vec(size_t a) { return vector<T>(a); }
template<class T, class... Ts> auto make_vec(size_t a, Ts... ts) {
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template<class T, class V>
typename enable_if<is_class<T>::value == 0>::type fill(T &t, const V &v) {
    t = v;
}
template<class T, class V>
typename enable_if<is_class<T>::value != 0>::type fill(T &t, const V &v) {
    for (auto &e : t) fill(e, v);
}
// auto v = make_vec<int>(h, w);
// fill(v, 0);

using P = pair<int, int>;

signed main(){

  int n; cin >> n;
  vector<int> a(n);
  vector<P> p(n);
  for(int i = 0; i < n; i++){
    cin >> a[i];
    p[i] = {a[i], i};
  }
  sort(p.rbegin(), p.rend());

  auto dp = make_vec<int>(n+1, n+1);
  auto dfs = [&](auto&& dfs, int l, int r)->void{
    if(l + r == n) return;
    if(dp[l][r] != 0) return dp[l][r];
    int i = l + r;
    dp[l+1][r] = max(dp[l+1][r], dp[l][r] + p[i].first * (p[i].second - l));
    dp[l][r+1] = max(dp[l][r+1], dp[l][r] + p[i].first * ((n-1-r) - p[i].second));
    dfs(dfs, l+1, r);
    dfs(dfs, l, r+1);
  };
  dfs(dfs, 0, 0);

  int ans = 0;
  for(int i = 0; i <= n; i++){
    for(int j = 0; j <= n; j++){
      if(i+j == n) ans = max(ans, dp[i][j]);
    }
  }
  cout << ans << endl;

  return 0;
}

Compiler output:
a.cc: In lambda function:
a.cc:39:37: error: return-statement with a value, in function returning 'void' [-fpermissive]
   39 |     if(dp[l][r] != 0) return dp[l][r];
      |                                     ^
Language: C

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

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> ii;
typedef tuple<ll, ll, ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define REP(i,n) for (ll i = 0; i < n; ++i)
#define REPR(i,n) for (ll i = n-1; i >= 0; --i)
#define FOR(i,m,n) for (ll i = m; i < n; ++i)
#define FORR(i,m,n) for (ll i = n-1; i >= m; --i)
#define FORE(x,xs) for (const auto& x : xs)
#define FORI(i,v) for (auto i = v.begin(); i != v.end(); i++)
#define ALL(v) v.begin(), v.end()
#define CHMIN(x,y) x = min(x, y)
#define CHMAX(x,y) x = max(x, y)
#define YES(b) cout << ((b) ? "YES" : "NO") << endl
#define Yes(b) cout << ((b) ? "Yes" : "No") << endl
#define DOUBLE(d) cout << fixed << setprecision(15) << (d) << endl

const int MAX = 2020;

int N;
int A[MAX];

ll dp[MAX][MAX];

ll solve() {
    vii a;
    REP (i, N) a.push_back(ii(A[i], i));
    sort(a.rbegin(), a.rend());

    REP (i, N) {
        dp[i+1][0] = dp[i][0] + a[i].first * (a[i].second - i);
        dp[0][i+1] = dp[0][i] + a[i].first * (N - 1 - i - a[i].second);
    }

    FOR (k, 2, N+1) {
        FOR (i, 1, k) {
            CHMAX(dp[i][k-i], dp[i-1][k-i] + a[k-1].first * (a[k-1].second - i + 1));
            CHMAX(dp[i][k-i], dp[i][k-i-1] + a[k-1].first * (N - k + i - a[k-1].second));
        }
    }

    ll ret = 0;
    REP (i, N+1) CHMAX(ret, dp[i][N-i]);
    return ret;
}

int main() {
    cin >> N;
    REP (i, N) cin >> A[i];
    cout << solve() << endl;
}

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++

#pragma GCC optimize("Ofast",3,"inline")
#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;

int a[3000];
ll dp[3000][3000];

int main(){
	int n;cin>>n;
	vector<P>v;
	rep(i,n){
		scanf("%d",&a[i]);
		v.push_back(P(a[i],i));
	}
	sort(v.begin(),v.end(),greater<>());
	memset(dp,-1,sizeof(dp));
	dp[0][0]=0;
	rep(i,n)rep(j,i+1){
		if(dp[i][j]==-1)continue;
		dp[i+1][j+1]=max(dp[i+1][j+1],dp[i][j]+v[i].first*(ll)abs(v[i].second-j));
		dp[i+1][j]=max(dp[i+1][j],dp[i][j]+v[i].first*(ll)abs(v[i].second-(n-(i-j)-1)));
	}
	cout<<max(dp[n],dp[n]+n+1)<<endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:30:18: error: no matching function for call to 'max(ll [3000], ll*)'
   30 |         cout<<max(dp[n],dp[n]+n+1)<<endl;
      |               ~~~^~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:2:
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:30:18: note:   deduced conflicting types for parameter 'const _Tp' ('long long int [3000]' and 'll*' {aka 'long long int*'})
   30 |         cout<<max(dp[n],dp[n]+n+1)<<endl;
      |               ~~~^~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61:
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:30:18: note:   mismatched types 'std::initializer_list<_Tp>' and 'll*' {aka 'long long int*'}
   30 |         cout<<max(dp[n],dp[n]+n+1)<<endl;
      |               ~~~^~~~~~~~~~~~~~~~~
Language: C++

#include<vector>
#include<algorithm>
using namespace std;
int const nax = 3e5 + 10;
using ll = long long ;
int n;
pair<int, int> a[nax];

ll dp[2048][2048];

int main () {

    scanf("%d", &n);

    for (int i = 1 ; i <= n ; ++ i) {
        scanf("%d", &a[i].first);
        a[i].second = i;
    }

    sort(a + 1, a + 1 + n, greater<pair <int, int>> ());


    for (int i = 0 ; i <= n ; ++ i)
        for (int j = 0 ; j <= n ; ++ j)
        dp[i][j] = LLONG_MIN;

    dp[0][0] = 0;

    for (int i = 0 ; i < n ; ++ i) {
        for (int j = 0 ; j <= i ; ++ j) {

            int val = a[i + 1].first;
            int idx = a[i + 1].second;

            int d1 = abs(idx - (j + 1));
            int d2 = abs(n - (i - j) - idx);

            dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j] + 1LL * val * d1);
            dp[i + 1][j]     = max(dp[i + 1][j], dp[i][j] + 1LL * val * d2);
        }
    }

    ll ans = LLONG_MIN;

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

    printf("%lld\n", ans);
}
/*
    Good Luck
        -Lucina
*/


Compiler output:
a.cc: In function 'int main()':
a.cc:13:5: error: 'scanf' was not declared in this scope
   13 |     scanf("%d", &n);
      |     ^~~~~
a.cc:25:20: error: 'LLONG_MIN' was not declared in this scope
   25 |         dp[i][j] = LLONG_MIN;
      |                    ^~~~~~~~~
a.cc:3:1: note: 'LLONG_MIN' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'
    2 | #include<algorithm>
  +++ |+#include <climits>
    3 | using namespace std;
a.cc:43:14: error: 'LLONG_MIN' was not declared in this scope
   43 |     ll ans = LLONG_MIN;
      |              ^~~~~~~~~
a.cc:43:14: note: 'LLONG_MIN' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'
a.cc:49:5: error: 'printf' was not declared in this scope
   49 |     printf("%lld\n", ans);
      |     ^~~~~~
a.cc:3:1: note: 'printf' is defined in header '<cstdio>'; this is probably fixable by adding '#include <cstdio>'
    2 | #include<algorithm>
  +++ |+#include <cstdio>
    3 | using namespace std;
Language: C

#include<vector>
#include<algorithm>
using namespace std;
int const nax = 3e5 + 10;
using ll = long long ;
int n;
pair<int, int> a[nax];

ll dp[2048][2048];

int main () {

    scanf("%d", &n);

    for (int i = 1 ; i <= n ; ++ i) {
        scanf("%d", &a[i].first);
        a[i].second = i;
    }

    sort(a + 1, a + 1 + n, greater<pair <int, int>> ());


    for (int i = 0 ; i <= n ; ++ i)
        for (int j = 0 ; j <= n ; ++ j)
        dp[i][j] = LLONG_MIN;

    dp[0][0] = 0;

    for (int i = 0 ; i < n ; ++ i) {
        for (int j = 0 ; j <= i ; ++ j) {

            int val = a[i + 1].first;
            int idx = a[i + 1].second;

            int d1 = abs(idx - (j + 1));
            int d2 = abs(n - (i - j) - idx);

            dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j] + 1LL * val * d1);
            dp[i + 1][j]     = max(dp[i + 1][j], dp[i][j] + 1LL * val * d2);
        }
    }

    ll ans = LLONG_MIN;

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

    printf("%lld\n", ans);
}
/*
    Good Luck
        -Lucina
*/


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

#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <vector>
using namespace std;

typedef long long ll;

vector<pair<ll, ll> > v;
ll dp[2222][2222], n;

int main(void)
{
	ll a, i, j;

	scanf("%lld", &n);
	for (i = 1; i <= n; i++)
	{
		scanf("%lld", &a);
		v.push_back(make_pair(a, i));
	}

	sort(v.begin(), v.end(), greater<>());

	for (i = 1; i <= n; i++)
		for (j = i; j >= 1; j--)
		{
			ll cnt = j - 1 + n - i;
			dp[j][i] = max(dp[j + 1][i] + v[cnt].first * abs(v[cnt].second - j), dp[j][i - 1] + v[cnt].first * abs(v[cnt].second - i));
		}

	printf("%lld", dp[1][n]);
	return 0;
}

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

#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define fi first
#define se second
#define pb push_back
#define vi vector<int >
#define vii vector < pair<int ,int > >
#define IO ios::sync_with_stdio(0) ; cin.tie(0) ; cout.tie(0)
#define IOfiles freopen("input.txt","r+",stdin) ; freopen("output.txt","w+",stdout)
#define PI 3.14159265
const long long mod = 1e9 + 7LL;
typedef long long ll;
typedef pair<int, int> ii;
typedef double db;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a;}
ll pwr(ll x , ll n) { ll ans = 1; while (n) {ans *= x; n--;} return ans;}

void solve(){
    
}

int main()
{
    IO;
    ll n;
    cin>>n;
    ll dp[n][n];
    memset(dp,-1,sizeof dp);
    vector<pair<ll , ll > > v;
    for(int i=0;i<n;i++){
        ll val;
        cin>>val;
        v.pb(make_pair(val,i));
    }
    sort(all(v));
    dp[0][n-1]=0;
    ll ans=0;
    
    for(int i=0;i<n;i++){
        for(int j=n-1;j>=i;j--){
            int p=j-i;
            if(p==0){
                dp[i][j]+=v[0].fi*abs(v[0].se-i);
                ans=max(ans,dp[i][j]);
                continue;
            }
            /*cout<<i<<" "<<j<<" ";
            cout<<p<<endl;*/
            dp[i+1][j]=max(dp[i+1][j],dp[i][j]+v[p].fi*abs(v[p].se-i));
            dp[i][j-1]=max(dp[i][j-1],dp[i][j]+v[p].fi*abs(v[p].se-j));
        }
    }
    cout<<ans<<endl;
}   

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;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef vector<vector<long long>> VVL;
typedef vector<string> VS;
typedef pair<ll, ll> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

#define en "\n"

constexpr double EPS = 1e-9;
constexpr double PI  = 3.141592653589793238462643383279;
constexpr int INF = 2147483647;
constexpr long long LINF = 1LL<<60;
constexpr long long MOD = 1000000007; // 998244353

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int N;
ll dp[2020][2020];
vector<P> A;

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

    int t = N-(r-l);
    ll ret = max(rec(l+1, r) + A[t].first*abs(l-A[t].second),
                rec(l, r-1) + A[t].first*abs(r-1-A[t].second));
    return dp[l][r] = ret;
}

int main(void){
    cin >> N; A.resize(N);
    REP(i,N) cin >> A[i].first;
    REP(i,N) A[i].second = i;
    SORT(A); REVERSE(A);
    REP(i,N+1)REP(j,N+1) dp[i][j] = -1;

    ll ans = rec(0,N);
    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;

int main()
{
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	cin.exceptions(cin.failbit);
    
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i=0;i<n;i++) cin >> a[i];

	vector<pair<int,pair<int,int>>> edges;
    for (int i =0;i<n;i++)
    {
    	for (int j=0;j<n;j++)
    	{
    		int t = a[j]*abs(i-j);
    	//	cout << t << '\n';
    		edges.push_back(make_pair(-t,make_pair(i,j)));
    	}
    }
    sort(edges.begin(),edges.end());  
    int res = 0;
   // cout << edges.size() << '\n';
    vector<bool> checkpos(n,0);
    vector<bool> checkchild(n,0);
    for (int i =0;i<edges.size();i++)
    {
    	int pos = edges[i].second.first;
    	int child = edges[i].second.second;
    	//cout << pos << ' ' << child << '\n';
    	if (checkpos[pos] || checkchild[child]) continue;
    	checkpos[pos] = true;
    	checkchild[child] = true;
    	//cout << edges[i].first << '\n';
    	res += -edges[i].first;
    }

    cout << res << '\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

/*
    Author: Nguyen Tan Bao
    Status:
    Idea:
*/
 
#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x
 
using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<II, int> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;
 
const ll MODBASE = 1000000007LL;
const int MAXN = 2010;
const int MAXM = 1000;
const int MAXK = 16;
const int MAXQ = 200010;

int n;
II a[MAXN];
ll dp[MAXN][MAXN];

ll solve(int l, int r) {
    int remain = r-l+1;
    int start = n - remain + 1;
    if (dp[l][r] != -1) return dp[l][r];
    if (l == r) return dp[l][r] = (ll) a[start].FI * abs(r - a[start].SE);
    return dp[l][r] = max((ll) a[start].FI * abs(r - a[start].SE) + solve(l, r-1), (ll) a[start].FI * abs(l - a[start].SE) + solve(l+1, r));
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    cin >> n;
    FOR(i,1,n) {
        cin >> a[i].FI;
        a[i].SE = i;
    }
    sort(a+1, a+n+1);
    FOR(i,1,n/2) swap(a[i], a[n-i+1]);
    FOR(i,1,n)
        FOR(j,1,n) dp[i][j] = -1;
    cout << solve(1,n);
    return 0;
}


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

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<int(n);++i)
#define all(a) (a).begin(),(a).end()
typedef long long ll;

using P = pair<ll, int>;

ll dp[2020][2020];

int main(void){
    int n;
    cin >> n;
    vector<ll> a(n);
    vector<P> p(n);
    rep(i,n) {
        cin >> a[i];
        p[i] = {a[i], i};
    }
    sort(all(p),greater<P>());
    rep(i,n){
        int pos = p[i].second;
        // 左右合計iこ埋め済み
        rep(l,i+1){
            int r = i-l;
            // lこ埋め済み, rこ埋め済み
            if (l < n) {
                dp[l+1][r] = max(dp[l+1][r], dp[l][r] + a[pos] * abs(l-pos));
            }
            if (r < n) {
                dp[l][r+1] = max(dp[l][r+1], dp[l][r] + a[pos] * abs(n-1-r-pos));
            }
        }
    }
    ll res = 0;
    rep(l,n+1) {
        int r = n-l;
        res = max(dp[l][r],res);
    }
    cout << res << 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.