criyle/codenet-compile-errors huggingface dataset:
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>
#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);
    map<int, vector<ll> > z;
    int i,j;
    for (i = 0; i < n; i++) {
        ll tmp;
        scanf("%lld", &tmp);
        z[tmp].push_back(i);
    }
    for (i = 0; i <= n; i++) {
        for (j = 0; j <= n; j++) {
            dp[i][j] = -LINF;
        }
    }
    dp[0][0] = 0;
    int cnt = 0;
    int allnum = 0;
    auto it = z.rbegin();
    for (; it != z.rend(); ++it) {
        int val=it->first;
        vector<ll>& v = it->second;
        int num=(int)v.size();
        for (i = 0; i <= n; i++) {
            if (dp[cnt][i] == -LINF) continue;

            vector<ll> v0, v1;
            for (j = 0; j < num; j++) {
                v0.push_back(v[j] - (i+j));
                v1.push_back(v[num-1-j]-(n-1-(allnum-i)-j));
            }
            vector<ll> sv0(num+1), sv1(num+1);
            for (j = 0; j < num; j++) {
                sv0[j + 1] = sv0[j] + v0[j];
                sv1[j + 1] = sv1[j] + v1[j];
            }

            for (j = 0; j <= num; j++) {
                dp[cnt + 1][i + j] = MAX(dp[cnt + 1][i + j], dp[cnt][i]+(sv0[j]+sv1[num-j])*val);
            }
        }
        allnum += num;
        cnt++;
    }

    ll ans = 0;
    for (i = 0; i <= n; i++) {
        ans = MAX(ans, dp[cnt][i]);
    }
    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 <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#define ll long long
using namespace std;
ll dp[2010][2010];
struct node {
	int id;
	int val;
}a[2010];
int cmp(node a, node b) {
	return a.val < b.val;
}
int main() {
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		scanf("%d", &a[i].val);
		a[i].id = i;
	}
	sort(a + 1, a + 1 + n, cmp);
	for (int i = 1; i <= n; i++)
		dp[i][i] = a[1].val * llabs(a[1].id - i);
	for(int len = 2; len <= n; len++)
		for (int i = 1; i + len - 1 <= n; i++) {
			int j = i + len - 1;
			dp[i][j] = max(dp[i + 1][j] + (ll)a[len].val * llabs(a[len].id - i), dp[i][j - 1] + (ll)a[len].val * llabs(a[len].id - j));
		}
	cout << dp[1][n];
	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 int long long

#define x first
#define y second
#define pb push_back
#define mp make_pair

#define all(a) (a).begin(), (a).end()

const int N = 2005;

int dp[N][N];

inline void upd(int &x, int y) {
    x = max(x, y);
}

int32_t main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<pair<int, int>> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i].x;
        a[i].y = i;
    }
    sort(all(a));
    reverse(all(a));
    for (int i = 0; i <= n; i++) {
        for (int j = 0; j < n - i; j++) {
            upd(dp[i + 1][j], dp[i][j] + a[i + j].x * abs(a[i + j].y - i));
            upd(dp[i][j + 1], dp[i][j] + a[i + j].x * abs(a[i + j].y - (n - j - 1)));
        }
    }
    int ans = 0;
    for (int i = 0; i <= n; i++) upd(ans, dp[i][n - i]);
    cout << ans;
    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 i64 = int_fast64_t;
using f64 = double;
using p64 = pair<i64, i64>;

void solve() {
    i64 n;
    cin >> n;
    vector<p64> a(n);
    for (i64 i = 0; i < n; i++) {
        cin >> a[i].first;
        a[i].second = i;
    }
    sort(begin(a), end(a), greater());

    vector<vector<i64>> dp(n + 1, vector<i64>(n + 1));
    for (i64 i = 0; i < n; i++) {
        const auto& [ e, p ] = a[i];
        for (i64 j = 0; j <= i; j++) {
            dp[j+1][i-j] = max(dp[j+1][i-j], e * abs(p-j) + dp[j][i-j]);
            dp[j][i-j+1] = max(dp[j][i-j+1], e * abs(p-(n-1-(i-j))) + dp[j][i-j]);
        }
    }

    i64 ans = 0;
    for (i64 i = 0; i <= n; i++) ans = max(ans, dp[i][n-i]);
    cout << ans << endl;
}

int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
}


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 <cstring>
#include <iostream>
#include <vector>

using namespace std;

typedef long long LL;

const int N = 2010;

pair<int, int> A[N];
LL dp[N][N];

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

int main() {
    memset(dp, -1, sizeof(dp));
    // freopen("a.txt", "r", stdin);
    int n, t;
    cin >> n;

    for (int i = 1; i <= n; ++i) {
        cin >> t;
        A[i] = {t, i};
    }
    sort(A + 1, A + n + 1, [&](pair<int, int> &p1, pair<int, int> &p2) {
        return p1.first > p2.first;
    });

    cout << solve(1, 1, n) << endl;
    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:34:5: error: 'sort' was not declared in this scope; did you mean 'short'?
   34 |     sort(A + 1, A + n + 1, [&](pair<int, int> &p1, pair<int, int> &p2) {
      |     ^~~~
      |     short
Language: C

#include <iostream>
#include <cstring>
#include <vector>

using namespace std;

typedef long long LL;

const int N = 2010;

pair<int, int> A[N];
LL dp[N][N];

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

int main() {
    memset(dp, -1, sizeof(dp));
    // freopen("a.txt", "r", stdin);
    int n, t;
    cin >> n;

    for (int i = 1; i <= n; ++i) {
        cin >> t;
        A[i] = {t, i};
    }
    sort(A + 1, A + n + 1, [&](pair<int, int> &p1, pair<int, int> &p2) {
        return p1.first > p2.first;
    });

    cout << solve(1, 1, n) << 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 <cstring>
#include <iostream>
#include <vector>

using namespace std;

typedef long long LL;

const int N = 2010;

pair<int, int> A[N];
LL dp[N][N];

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

int main() {
    memset(dp, -1, sizeof(dp));
    // freopen("a.txt", "r", stdin);
    int n, t;
    cin >> n;

    for (int i = 1; i <= n; ++i) {
        cin >> t;
        A[i] = {t, i};
    }
    sort(A + 1, A + n + 1, [&](pair<int, int> &p1, pair<int, int> &p2) {
        return p1.first > p2.first;
    });

    cout << solve(1, 1, n) << endl;
    return 0;
}


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

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

typedef long long LL;
typedef pair<int,int> PII;
const int M=2005;
LL dp[M][M];

vector<PII> vec;

int main()
{
	int n;
	scanf("%d",&n);
	int ai;
	for(int i=0;i<n;i++)
	{
		scanf("%d",&ai);
		vec.push_back({ai,i});
	}
	sort(vec.begin(),vec.end());
	for(int i=0;i<n;i++)
		dp[i][i]=abs(vec[0].second-i)*vec[0].first;
	for(int len=2;len<=n;len++)
	{
		for(int l=0,r=len-1;r<n;l++,r++)
		{
			LL p=vec[len-1].second,ai=vec[len-1].first;
			dp[l][r]=max(dp[l+1][r]+abs(p-l)*ai,dp[l][r-1]+abs(p-r)*ai);
		}
	}
	printf("%lld\n",dp[0][n-1]);
	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 be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    vector<pair<ll, ll> > v(n);
    for(int i=0;i<n;i++){
        cin >> a[i].first;
        a[i].second = -i;
    }
    sort(be(v));
    vector<vector<ll> > dp(n+1,vector<ll> (n+1,0));
    for (int i=0;i<n;i++)for (int j=0;j<n;j++){
        ll id = -a[i].second;
        dp[i+1][j] = max(dp[i][j]+a[i].first*(i-id+j), dp[i][j+1] + a[i].first*(id-j));
    }
    cout << dp[n][0] << 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;

const int N = 2020;
long long dp[N][N];

int main() {
        ios::sync_with_stdio(false);
        cin.tie(0);
        int n;
        cin >> n;
        vector<pair<int, int>> a(n);
        for (int i = 0; i < n; i++) {
                cin >> a[i].first;
                a[i].second = -i;
        }
        sort(a.begin(), a.end());
        for (int i = 0; i < n; i++) {
                for (int j = 0; j < n; j++) {
                        int id = -a[i].second;
                        dp[i + 1][j] = dp[i][j] + 1ll * (i - id + j) * a[i].first;
                        dp[i + 1][j] = max(dp[i + 1][j], dp[i][j + 1] + 1ll * (id - j) * a[i].first);
                }
        }
        cout << dp[n][0] << '\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 rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
using namespace std;
using ll = long long;

int main()
{
    int n;
    cin >> n;
    vector< pair<int,int> > a(n);
    rep(i,n) {cin >> a[i].first; a[i].second = i;}
    sort(a.begin(),a.end(),greater<pair<int,int>>());

    vector<vector<int>> dp(n+1,vector<int>(n+1));

    int ans = 0;
    rep(l,n+1) {
        rep(m,n+1){
            if(l+m == n) {ans = max(ans, dp[l][m]); break;} // ansの更新
            int activeness = a[l+m].first;
            int position = a[l+m].second;
            dp[l+1][m] = max(dp[l+1][m],dp[l][m] + activeness * abs(l-position));
            dp[l][m+1] = max(dp[l][m+1],dp[l][m] + activeness * abs(n-m-1-position));
        }
    }

    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 lli  long long int
#define mod 1000000007

lli n;
lli arr[20005];
vector< pair<lli,lli> > v;


void solve()
{
    lli l=0;
    lli r=n-1;
    lli sum=0;
    for(lli i=n-1; i>=0 ; i--)
    {
        //cout<<l<<" "<<r<<" "<<v[i].first<<"\n";
        if(abs(v[i].second-r) >= abs(v[i].second-l))
        {
            sum+= v[i].first*(abs(v[i].second-r));
            //cout<<sum <<"\n";
            r--;
        }
        else if(abs(v[i].second-r) < abs(v[i].second-l))
        {
            sum+= v[i].first * (abs(v[i].second-l));
           // cout<<sum <<"\n";
            l++;
        }
    }
    cout<<sum<<"\n";

}

int main()
{
    cin>>n;
    for(int i=0;i<n;i++)
    {
        lli x;
        cin>>x;
        arr[i]=x;
        v.push_back(make_pair(x,i));
    }
    sort(v.begin(),v.end());
    solve();
	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>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
const int INF = 1000000001;

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
// const int mod = 998244353;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

int main() {
  int n, k;
  cin >> n >> k;
  vector<mint> integ(n+2, 0);

  for(int i = 0; i <= n; ++i){
    integ[i+1] = integ[i] + i;
  }

  mint ans = 0;
  for(int i = k; i <= n+1; ++i){
    mint left = integ[i];
    mint right = integ[n+1] - integ[n+1-i];
    ans += right - left + 1;
  }

  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 <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cinttypes>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;

using ll = long long;

ll Dp(int i, int j, const vector<pair<int, int>>& A, vector<vector<ll>>& dp) {
  if (i > j) {
    return 0;
  }

  ll& r = dp[i][j];
  if (r != -1) {
    return r;
  }

  int idx = A.size() - (j - i + 1);
  r = max(A[idx].first * abs(A[idx].second - i) + Dp(i + 1, j, A, dp),
          A[idx].first * abs(A[idx].second - j) + Dp(i, j - 1, A, dp));
  return r;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  int N;
  cin >> N;

  vector<pair<int, int>> A(N);
  for (int i = 0; i < N; ++i) {
    cin >> A[i].first;
    A[i].second = i;
  }

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

  vector<vector<ll>> dp(N, vector<ll>(N, -1));
  cout << Dp(0, N - 1, A, dp) << '\n';

  return 0;
}


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

#include <bits/stdc++.h>

#define rep2(x,fr,to) for(int x=(fr);x<(to);x++)
#define rep(x,to) for(int x=0;x<(to);x++)
#define repr(x,fr,to) for(int x=(fr);x>=(to);x--)
#define all(c) c.begin(),c.end()
#define sz(v) (int)v.size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
typedef vector<ll> VL; const int MD = (int)1e9 + 7;
void dbg(){ cerr << "\n"; } template <typename T,typename ...T2> void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }
template <class T, class T2> void amax(T& a,T2 b){ if(a < b) a = b;}

int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);
	int n;
	cin >>n;
	vector<pii> a(n);
	rep(i, n){ cin >>a[i].first; a[i].second = i; }
	sort(a.rbegin(), a.rend());
	ll ans = 0;
	vector<VL> dp(n+1, VL(n+1));
	rep(i, n) rep(j, n){
		if(i+j == n){
			ans = max(ans, dp[i][j]);
			break;
		}
		amax(dp[i+1][j], dp[i][j] + abs(a[i+j].second - i) * (ll)a[i+j].first );
		amax(dp[i][j+1], dp[i][j] + abs(a[i+j].second - (n-1-j)) * (ll)a[i+j].first );
	}
	cout << ans <<"\n";
	return 0;
}

        dp[l+1][r] = max(dp[l+1][r], dp[l][r] + abs(ind - l) * activeness)
        dp[l][r+1] = max(dp[l][r+1], dp[l][r] + abs(ind - (n-1-r)) * activeness)


Compiler output:
a.cc:37:9: error: 'dp' does not name a type
   37 |         dp[l+1][r] = max(dp[l+1][r], dp[l][r] + abs(ind - l) * activeness)
      |         ^~
Language: C

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define IFOR(i, m, n) for (ll i = n - 1; i >= m; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define FOREACH(x, a) for (auto&(x) : (a))
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

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

int main() {
  ll n;
  cin >> n;
  vector<ll> a(n);
  REP(i, n) { cin >> a[i]; }
  vector<ll> ord(n);
  iota(ALL(ord), 0);
  sort(ALL(ord), [&](ll i, ll j) { return a[i] > a[j]; });

  const ll INF = 1e18;
  vector<vector<ll>> dp(n + 1, vector<ll>(n + 1, 0));

  dp[0][0] = 0;
  FOR(k, 1, n + 1) {
    REP(i, k + 1) {
      ll j = k - i;
      ll p = ord[k - 1];
      if (i >= 1) {
        chmax(dp[i][j], dp[i - 1][j] + a[p] * abs(p - (i - 1)));
      }
      if (j >= 1) {
        chmax(dp[i][j], dp[i][j - 1] + a[p] * abs(p - (n - j)));
      }
    }
  }

  ll ans = -INF;
  REP(i, n + 1) { ans = max(ans, dp[i][n - i]); }
  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;
typedef long long LL;
#define fi first
#define se second
#define pb push_back
#define forn(i,n) for(int i=0;i<(n);i++)
#define for1(i,n) for(int i=1;i<=n;i++)
#define forr(i,n) for(int i=n;i>=0;i--)
#define all(x) x.begin(), x.end()
const int MAXN = 2e3 +5;

void fio(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}

LL dp[MAXN][MAXN];

int main(){
  fio();
  int n; cin>>n;
  vector<pair<LL,LL> > v(n+1);
  v[0].fi = 1e9;
  for1(i,n){
	cin>>v[i].fi;
	v[i].se = i;
	}
  sort(v.begin(),v.end(),greater<pair<LL,LL> >());

  for1(i,n){
  	auto u = v[i];
  	cout<<u.fi<<" ";
  	for(LL j = 0; j<i; j++){
  		LL l = j;
  		LL r = (i-1-j);
  		dp[l+1][r] = max(dp[l+1][r],dp[l][r] + abs(l+1-u.se)*u.fi);
  		dp[l][r+1] = max(dp[l][r+1],dp[l][r] + abs(n- r -u.se)*u.fi);
  	}
  }
  cout<<endl;
  LL an = 0;
  forn(i,n+1)  an = max(an, dp[i][n-i]);
  cout<<an<<endl;
  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

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long[][] a = new long[n][2];
        for(int i = 0; i < n; i++) {
            a[i][0] = (long)(i + 1);
            a[i][1] = sc.nextLong();
        }
        Arrays.sort(a, (o1, o2) -> (int)(o2[1] - o1[1]));
        long[][] dp = new long[n + 1][n + 1];
        dp[1][0] = a[0][1] * (a[0][0] - 1);
        dp[0][1] = a[0][1] * (n - a[0][0]);
        for(int k = 2; k <= n; k++) {
            for(int i = 0; i <= k; i++) {
                // dp[i][k - i]の更新
                // k人目が(i - pi)のパターン
                if(i > 0) dp[i][k - i] = dp[i - 1][k - i] + (a[k - 1][1] * (a[k - 1][0] - i));

                // k人目が(pi - i)のパターン
                if(k > i) dp[i][k - i] = Math.max(dp[i][k - i], dp[i][k - i - 1] + (a[k - 1][1] * (n - k + i + 1 - a[k - 1][0])));
            }
        }
        long ans = 0;
        for(int i = 0; i <= n; i++) {
            ans = Math.max(ans, dp[i][n - i]);
        }
        System.out.println(ans);
    }
}

Compiler output:
main.c:1:1: error: unknown type name 'import'
    1 | import java.util.*;
      | ^~~~~~
main.c:1:12: error: expected '=', ',', ';', 'asm' or '__attribute__' before '.' token
    1 | import java.util.*;
      |            ^
main.c:3:1: error: unknown type name 'public'
    3 | public class Main {
      | ^~~~~~
main.c:3:14: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'Main'
    3 | public class Main {
      |              ^~~~
Language: C

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

long long dp[2005][2005];
int main() {
  int n;
  cin>>n;
  long long a[n];
  for (int i=0; i<n; i++) cin>>a[i];
  for (int i=0; i<n+1; i++) {
    for (int j=0; j<n+1; j++) {
      dp[i][j] = 0;
    }
  }
  pair<long long, int> pa[n];
  for (int i=0; i<n; i++) pa[i] = make_pair(a[i], i);
  sort(pa, pa + n);
  reverse(pa, pa + n);
  dp[1][0] = pa[0].first * pa[0].second;
  dp[0][1] = pa[0].first * (n - 1 - pa[0].second);
  for (int i=1; i<n; i++) {
    for (int j=1; j<=i+1; j++) {
      if (pa[i].second >= j - 1) {
        dp[j][i+1-j] = max(pa[i].first * (pa[i].second - j + 1) + dp[j-1][i+1-j], dp[j][i+1-j]);
      }
      if (n - j >= pa[i].second) {
        dp[i+1-j][j] = max(pa[i].first * (n - j - pa[i].second) + dp[i+1-j][j-1], dp[i+1-j][j]);
      }
    }
  }

  long long ans = 0;
  for (int i=0; i<=n; i++) {
    ans = max(dp[i][n-i], ans);
  }
  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 fr(i,n) _back
#define pb	push_back
#define eb	emplace_back
#define mk	make_pair
#define fi	first
#define se	second
#define endl	'\n'

typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<ii> vii;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1.0);
const int T = 2e3+3;
ll dp[T][T];
vii v;

int main() {
    ios_base::sync_with_stdio(false);
    int n; cin >> n;

    for(int i = 0; i < n; i++) {
        int x; cin >> x;
        v.eb(x,i+1);
    }

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

    ll ans = 0;
    for(int i = n-1; i >= 0; i--)
        for(int j = 1; j+i <= n; j++) {
            dp[j+1][j+i] = max(dp[j+1][j+i], dp[j][j+i]+abs(v[i].se-j)*v[i].fi);
            dp[j][j+i-1] = max(dp[j][j+i-1], dp[j][j+i]+abs(v[i].se-(j+i))*v[i].fi;
            ans = max({ans,dp[j+1][j+i],dp[j][j+i-1]});
        }

    cout << ans << endl;
    return 0;
}



Compiler output:
a.cc: In function 'int main()':
a.cc:36:83: error: expected ')' before ';' token
   36 |             dp[j][j+i-1] = max(dp[j][j+i-1], dp[j][j+i]+abs(v[i].se-(j+i))*v[i].fi;
      |                               ~                                                   ^
Language: C++

#include <bits/stdc++.h>

#define pp push_back
#define pf push_front
#define mp make_pair
#define fs first
#define sc second
#define sf scanf

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> ii;

const int N = (int) 2e3;
const int INF = (int) 1e9 + 7;

ii p[N + 7];
ll dp[N + 7][N + 7][N + 7];
int n;

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

	ll x = f(i - 1, l + 1, r) + p[i].fs * abs(l - p[i].sc);
	ll y = f(i - 1, l, r - 1) + p[i].fs * abs(r - p[i].sc);

	return dp[i][l][r] = max(x, y);
}

int main(int argc, char *argv[])
{
	// ios_base::sync_with_stdio(false);
	// cin.tie(NULL);

	sf("%d", &n);
	for (int i = 1; i <= n; ++i) {
		sf("%d", &p[i].fs);
		p[i].sc = i;
	}

	sort(p + 1, p + n + 1);

	memset(dp, -1, sizeof(dp));
	printf("%lld", f(n, 1, n));

	return 0;
}


Compiler output:
/tmp/ccwnySpV.o: in function `main':
a.cc:(.text+0x1f9): relocation truncated to fit: R_X86_64_PC32 against symbol `n' defined in .bss section in /tmp/ccwnySpV.o
a.cc:(.text+0x26b): relocation truncated to fit: R_X86_64_PC32 against symbol `n' defined in .bss section in /tmp/ccwnySpV.o
a.cc:(.text+0x276): relocation truncated to fit: R_X86_64_PC32 against symbol `n' defined in .bss section in /tmp/ccwnySpV.o
a.cc:(.text+0x2c7): relocation truncated to fit: R_X86_64_PC32 against symbol `n' defined in .bss section in /tmp/ccwnySpV.o
a.cc:(.text+0x2cd): relocation truncated to fit: R_X86_64_PC32 against symbol `n' defined in .bss section in /tmp/ccwnySpV.o
collect2: error: ld returned 1 exit status
Language: C++

#include <bits/stdc++.h>

#define pp push_back
#define pf push_front
#define mp make_pair
#define fs first
#define sc second
#define sf scanf

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> ii;

const int N = (int) 2e3;
const int INF = (int) 1e9 + 7;

ii p[N + 7];
ll dp[N + 7][N + 7][N + 7];
int n;

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

	ll x = f(i - 1, l + 1, r) + p[i].fs * abs(l - p[i].sc);
	ll y = f(i - 1, l, r - 1) + p[i].fs * abs(r - p[i].sc);

	return dp[i][l][r] = max(x, y);
}

int main(int argc, char *argv[])
{
	// ios_base::sync_with_stdio(false);
	// cin.tie(NULL);

	sf("%d", &n);
	for (int i = 1; i <= n; ++i) {
		sf("%d", &p[i].fs);
		p[i].sc = i;
	}

	sort(p + 1, p + n + 1);

	memset(dp, -1, sizeof(dp));
	printf("%lld", f(n, 1, n));

	return 0;
}


Compiler output:
a.cc: In function 'll f(int, int, int)':
a.cc:25:46: error: invalid conversion from 'll*' {aka 'long long int*'} to 'll' {aka 'long long int'} [-fpermissive]
   25 |         if (dp[i][l][r] != -1) return dp[l][r];
      |                                       ~~~~~~~^
      |                                              |
      |                                              ll* {aka long long int*}
Language: C

#include <iostream>
#include <vector>
#include <bitset>
#include <utility>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>

using namespace std;
typedef long long ll;

int main(){
  int N;
  cin >> N;
  vector<pair<int,int>> A(N,make_pair(0,0));
  for(int i=0;i<N;i++){
    cin >> A[i].first;
    A[i].second=i+1;
  }

  sort(A.begin(),A.end(),greater<pair<int,int>>());

  vector<vector<ll>> dp(N+1,vector<ll>(N+1));

  for(int i=1;i<=N;i++){
    dp[i][0]=dp[i-1][0]+A[i-1].first*( A[i-1].second-i);
    dp[0][i]=dp[0][i-1]+A[i-1].first*(-A[i-1].second+(N-i+1));
  }

  for(int i=1;i<N;i++){
    for(int j=1;j<=N-i;j++){
      dp[i][j]=max(dp[i-1][j]+A[i+j-1].first*( A[i+j-1].second-i),
                   dp[i][j-1]+A[i+j-1].first*(-A[i+j-1].second+(N-j+1)));
    }
    /*
    for(int p=0;p<=N;p++){
      for(int q=0;q<=N;q++){
        cout << dp[p][q] << " ";
      }
      cout << endl;
    }
    cout << "-------" << endl;
    */
  }

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

  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 n;
  cin>>n;
  vector<pair<int64_t,int>> p(n);
  for(int i=0;i<n;++i){
    cin>>p[i].first;
    p[i].second=i;
  }
  sort(p.begin(),p.end(),greater<pair<int64_t,int>>());

  vector<vector<int64_t>> dp(n+1,vector<int64_t>(n+1,0));
  for(int j=0;j<=n;++j){
    for(int i=0;i+j<=n;++i){
      int64_t a=p[i+j-1].first;
      int k=p[i+j-1].second;
      if(i==0 && j==0) continue;
      else if(j==0) dp[i][0]=dp[i-1][0]+a*(n-i-k);
      else if(i==0) dp[j][j]=dp[j-1][j-1]+a*(k-j+1);
      else dp[i+j][j]=max(dp[i+j-1][j]+a*(n-i-k),dp[i+j-1][j-1]+a*(k-j+1));
    }
  }

 //for(int i=0;i<=n;++i){
 // for(int j=0;j<=n;++j){
 //    cout<<i<<" "<<j<<" "<<dp[i][j]<<endl;
 //  }
 //}
  
  int64_t ans=0;
  for(int i=0;i<=n;++i){
    if(ans<dp[n][i]) ans=dp[n][i];
  }
  
  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 ll long long 
#define f first 
#define s second

vector<pair<ll, ll>> vec(3000);
ll dp[3000][3000];
ll n;
  
ll solve(ll l, ll r){
	if(l>r)return 0;
	if(dp[l][r]!=-1)return dp[l][r];
	
	ll idx=(n-(r-l+1)+1);
	ll ans1=abs(l-vec[idx].s)*vec[idx].f + solve(l+1,r);
	ll ans2=abs(r-vec[idx].s)*vec[idx].f + solve(l, r-1);
	
	return dp[l][r]=max(ans1, ans2);
}
  
int main()  {
	cin>>n;
	for(ll i=1;i<=n;i++){
		cin>>vec[i].f;
		vec[i].s=i;
	}
	sort(vec.begin()+1,vec.begin()+1+n);
	reverse(vec.begin()+1,vec.begin()+1+n);
	memset(dp , -1 , sizeof (dp));
	ll ans = solve(1,n);
	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



import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Deque;
import java.util.Scanner;

public class Main {

	static class Pair implements Comparable<Pair> {
		long a, b;

		Pair(long a, long b) {
			this.a = a;
			this.b = b;
		}

		public int compareTo(Pair p) {
			if (a > p.a)
				return 1;
			else if (a < p.a)
				return -1;
			else
				return 0;
		}
	}

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		long[] a = new long[n];
		Pair[] pair = new Pair[n];

		for (int i = 0; i < n; i++) {
			a[i] = Long.parseLong(sc.next());
			pair[i] = new Pair(a[i], i);
		}

		Arrays.sort(pair);
		Deque<Long> dq = new ArrayDeque<>();
		for (long i = 0; i < n; i++) {
			dq.addLast(i);
		}

		long ans = 0;

		for (int i = n - 1; i >= 0; i--) {
			long left = Math.abs(dq.getFirst() - pair[i].b);
			long right = Math.abs(dq.getLast() - pair[i].b);

			if (left > right) {
				ans += pair[i].a * left;
				dq.pollFirst();
			} else if (left < right) {
				ans += pair[i].a * right;
				dq.pollLast();
			} else {
				if (i == 0) {
					ans += pair[i].a * left;
				} else {
					if (pair[i - 1].b < pair[i].b) {
						ans += pair[i].a * left;
						dq.pollFirst();
					} else {
						ans += pair[i].a * right;
						dq.pollLast();
					}
				}
			}
		}
		System.out.println(ans);

	}

}


Compiler output:
main.c:3:1: error: unknown type name 'import'
    3 | import java.util.ArrayDeque;
      | ^~~~~~
main.c:3:12: error: expected '=', ',', ';', 'asm' or '__attribute__' before '.' token
    3 | import java.util.ArrayDeque;
      |            ^
main.c:4:1: error: unknown type name 'import'
    4 | import java.util.Arrays;
      | ^~~~~~
main.c:4:12: error: expected '=', ',', ';', 'asm' or '__attribute__' before '.' token
    4 | import java.util.Arrays;
      |            ^
main.c:5:1: error: unknown type name 'import'
    5 | import java.util.Deque;
      | ^~~~~~
main.c:5:12: error: expected '=', ',', ';', 'asm' or '__attribute__' before '.' token
    5 | import java.util.Deque;
      |            ^
main.c:6:1: error: unknown type name 'import'
    6 | import java.util.Scanner;
      | ^~~~~~
main.c:6:12: error: expected '=', ',', ';', 'asm' or '__attribute__' before '.' token
    6 | import java.util.Scanner;
      |            ^
main.c:8:1: error: unknown type name 'public'
    8 | public class Main {
      | ^~~~~~
main.c:8:14: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'Main'
    8 | public class Main {
      |              ^~~~
Language: C

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define endl '\n'
const int inf = 1000000007;
const ll INF = 1e18;
// int mod = 998244353;
int mod = 1000000007;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll pow(ll a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll modpow(ll a, ll b, ll _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; }
template<class T, class U> ostream& operator << (ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<class T> ostream& operator << (ostream& os, const vector<T>& vec) { rep(i, sz(vec)) { if (i) os << " "; os << vec[i]; } return os; }
template<typename T> inline istream& operator >> (istream& is, vector<T>& v) { rep(j, sz(v)) is >> v[j]; return is; }
template<class T, class T2> inline void add(T &a, T2 b) { a += b; if (a >= mod) a -= mod; }


void solve();

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout << fixed << setprecision(10);

  int T;
  // cin >> T;
  T = 1;

  while (T--) {
    solve();
  }
}

// pdf editorial
void solve() {
  int n;
  cin >> n;
  vector<int> a(n);
  cin >> a;
  vector<pii> b(n);
  rep(i, n) b[i] = pii(a[i], i);
  sort(all(b), greater<pii>());

  vector<vector<ll> > dp(n + 1, vector<ll>(n + 1));
  rep(z, n) {
    rep(x, z + 1) {
      int y = z - x;
      chmax(dp[x + 1][y], dp[x][y] + b[z].F * (b[z].S - x));
      chmax(dp[x][y + 1], dp[x][y] + b[z].F * (n - 1 - y - b[z].S));
    }
  }
  ll ans = 0;
  rep(x, n + 1) {
    int y = n - x;
    chmax(ans, dp[x][y]);
  }
  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

#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

#include <limits.h>

using namespace std;

typedef long long ll;

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 INF = LONG_LONG_MAX / 2;

vector<ll> as;
vector<pair<ll, int>> bs; // {value, initial_pos}
vector<vector<ll>> dp;

void solve(const int N) {
    for (int i = 0; i <= N; i++) {
        for (int j = 0; j <= N - i; j++) {
            auto v = bs[i + j].first;
            auto pos = bs[i + j].second;
            if (i > 0) {
                chmax(dp[i][j], dp[i - 1][j] + v * abs(i - pos));
            }
            if (j > 0) {
                chmax(dp[i][j], dp[i][j - 1] + v * abs(N - j + 1 - pos));
            }
        }
    }
}

int main(void) {
    int N;
    cin >> N;

    as.resize(N + 1);
    bs.resize(N + 1);
    bs[0] = { INF, 0 };
    for (int i = 1; i <= N; i++) {
        cin >> as[i];
        bs[i] = { as[i], i };
    }
    sort(bs.begin(), bs.end());
    reverse(bs.begin(), bs.end());

    dp.resize(N + 1, vector<ll>(N + 1, 0));

    solve(N);

    // for (int i = 0; i <= N; i++) {
    //     for (int j = 0; j <= N; j++) {
    //         cout << dp[i][j] << " ";
    //     }
    //     cout << endl;
    // }
    // cout << endl;

    ll ans = 0;
    for (int i = 0; i <= N; i++) {
        chmax(ans, dp[i][N - i]);
    }
    cout << ans << endl;

    return 0;
}


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

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

typedef pair<int, int> P;

int N;
vector<vector<long long>> dp;
vector<P> A;

long long dfs(int l, int r) {
    if (dp[l][r] != -1) return dp[l][r];
    if (l == 0 && r == 0) return dp[l][r] = 0;
    long long res = -1;
    long long activeness = A[l + r - 1].first, idx = A[l + r - 1].second;
    if (l >= 1) res = max(res, dfs(l - 1, r) + activeness * abs(idx - (l - 1)));
    if (r >= 1) res = max(res, dfs(l, r - 1) + activeness * abs(idx - (N - r)));
    return dp[l][r] = res;
}

int main() {
    cin >> N;
    dp.resize(N + 1, vector<long long>(N + 1));
    for (int i = 0; i < N + 1; ++i) for (int j = 0; j < N + 1; ++j) dp[i][j] = -1;
    for (int i = 0; i < N; ++i) {
        int a;  cin >> a;
        A.push_back(P(a, i));
    }
    sort(A.begin(), A.end(), greater<P>());

    long long ans = -1;
    for (int l = 0; l < N + 1; ++l) {
        int r = N - l;
        ans = max(ans, dfs(l, r));
    }
    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;
long long DP[2020][2020];
pair<long long,int> C[2020];
int main()
{
	int N;
	cin>>N;
	for(int i=0;i<N;i++)
	{
		cin>>C[i].first;
		C[i].second=i;
	}
	sort(C,C+N);
	reverse(C,C+N);
	for(int i=0;i<N;i++)
		for(int j=0;j<=i;j++)
		{
			int k=i-j;
			DP[j+1][k]=max(DP[j+1][k],DP[j][k]+C[i].first*C[i].second-j);
			DP[j][k+1]=max(DP[j][k+1],DP[j][k]+C[i].first*(N-C[i].secsond-1-k));
		}
	long long 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:21:79: error: 'struct std::pair<long long int, int>' has no member named 'secsond'; did you mean 'second'?
   21 |                         DP[j][k+1]=max(DP[j][k+1],DP[j][k]+C[i].first*(N-C[i].secsond-1-k));
      |                                                                               ^~~~~~~
      |                                                                               second
Language: C

#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> p2;
ll dp[2005][2005];
bool comp(p2 a,p2 b){
	return a.first>b.first;
}
void solve(){
	ll n;
	cin>>n;
	vector<p2> v(n);
	for(ll i=0;i<n;i++){
		cin>>v[i].first;
		v[i].second=i;
	}
	sort(v.begin(),v.end(),comp);
	for(ll i=0;i<n;i++){
		for(ll l=0;l<=i;l++){
			dp[l+1][i-l]=max(dp[l+1][i-l],dp[l][i-l]+v[i].first*abs(v[i].second-l));
			dp[l][i-l+1]=max(dp[l][i-l+1],dp[l][i-l]+v[i].first*abs(n-i+l-1-v[i].second));
		}
	}
	ll res=0;
	for(ll i=0;i<=n;i++)
	res=max(res,dp[i][n-i]);
	cout<<res;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll qc=1;
    for(ll i=1;i<=qc;i++)
    solve();
}

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>
#define ll long long
using namespace std;
const int N = 2e3 + 5;
ll f[N][N];
pair<int, int> p[N];
ll cal(int cnt, int l, int r) {
    if(l > r) return 0;
    if(~f[l][r]) return f[l][r];
    ll ans = 1LL * p[cnt].first * abs(p[cnt].second - l) + cal(cnt + 1, l + 1, r);
    ans = max(ans, 1LL * p[cnt].first * abs(p[cnt].second - r) + cal(cnt + 1, l, r - 1));
    return f[l][r] = ans;
}
int main() {
    int n;
    scanf("%d", &n);
    for(int i = 1, x; i <= n; i++) {
        scanf("%d", &x);
        p[i] = {x, i};
    }
    sort(p + 1, p + n + 1,[](pair<int, int> a, pair<int, int> b) {
        return a.first > b.first;
    });
    memset(f, -1, sizeof f);
    printf("%lld\n", cal(1, 1, n));
    return 0;
}

E.cpp

Compiler output:
a.cc:29:1: error: 'E' does not name a type
   29 | E.cpp
      | ^
Language: C

#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define IINF 100000000
#define INF 300000000000000000
#define MOD 1000000007
#define mod 1000000007
#define REP(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define REPE(i, a, n) for (ll i = a; i <= (ll)(n); i++)
#define rep(i,n)for (ll i = 0; i < (ll)(n); i++)
#define Endl endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef pair<int,int>Pin;
typedef pair<ll,ll>Pll;
template<class T> using V=vector<T>;
long long GCD(long long a, long long b) {return b?GCD(b,a%b):a;}
long long LCM(long long a, long long b) {return a/GCD(a,b)*b;}
int dx[4]={-1,0,1,0};
int dy[4]={0,-1,0,1};
int ddx[8]={-1,0,1,0,1,1,-1,-1};
int ddy[8]={0,-1,0,1,1,-1,1,-1};
ll cmp1(pair<ll,ll>a,pair<ll,ll> b){
        if(a.se!=b.se)
        return a.se<b.se;
        else
        return a.fi<b.fi;
}
//----------------------------------------------------------------------

//----------------------------------------------------------------------
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------  
    //ll begin_time=clock();
    //-------------------------------
    ll n;cin>>n;
    V<ll>a(n);
    V<Pll>P(n);
    for(ll i=0;i<n;i++){
        cin>>a[i];
        P[i].fi=a[i];
        P[i].se=i;
    }

    sort(all(P));
    reverse(all(P));

    ll dp[2020][2020];
    for(ll i=0;i<=n;i++){
        for(ll j=0;j<=n;j++){
            dp[i][j]=-INF;
        }
    }
    dp[0][0]=0;
    for(ll i=0;i<n;i++){
        ll v=P[i].fi;
        ll ipos=P[i].se;
        for(ll x=0;x<=i;x++){
            ll y=i-x;
            chmax(dp[x+1][y],dp[x][y]+abs(ipos-x)*v);
            chmax(dp[x][y+1],dp[x][y]+abs(ipos-(n-1-y))*v);
        }
    }
    ll ans=-INF;
    for(ll x=0;x<=n;x++){
        chmax(ans,dp[x][n-x]);
    }
    cout<<ans<<endl;
    //-------------------------------  
    //ll end_time=clock();cout<<"time="<<end_time-begin_time<<"ms"<<endl;
    //-------------------------------
    return 0;
}
//----------------------------------------------------------------------


















































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

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

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

  ll N;
  cin >> N;
  vector<pair<ll,ll>> A(N);
  rep(i, N) {
    cin >> A[i].first;
    A[i].second = i;
  }
  sort(all(A));
  reverse(all(A));
  
  vector<vector<ll>> dp(N+1, vector<ll>(N+3));
  
  rep(i, N) rep2(j, i+1) {
    dp[i+1][j] = max(dp[i][j-1] + A[i].first * (A[i].second - (j-1)),
                     dp[i][j] + A[i].first * (N-1-i+j - A[i].second)
                    );
    dp[i+1][j+1] = max(dp[i][j] + A[i].first * (A[i].second - j),
                       dp[i][j+1] + A[i].first * (N-1-i+j+1 - A[i].second)
                       );
    }
  }

  ll ans = 0;
  rep2(i, N+1) ans = max(ans, dp[N][i]);
  cout << ans << '\n';
  return 0;
}


Compiler output:
a.cc:5:20: error: expected unqualified-id before 'for'
    5 | #define rep2(i, n) for(ll i = 1; i <= ll(n); ++i)
      |                    ^~~
a.cc:35:3: note: in expansion of macro 'rep2'
   35 |   rep2(i, N+1) ans = max(ans, dp[N][i]);
      |   ^~~~
a.cc:35:8: error: 'i' does not name a type
   35 |   rep2(i, N+1) ans = max(ans, dp[N][i]);
      |        ^
a.cc:5:34: note: in definition of macro 'rep2'
    5 | #define rep2(i, n) for(ll i = 1; i <= ll(n); ++i)
      |                                  ^
a.cc:5:46: error: expected unqualified-id before '++' token
    5 | #define rep2(i, n) for(ll i = 1; i <= ll(n); ++i)
      |                                              ^~
a.cc:35:3: note: in expansion of macro 'rep2'
   35 |   rep2(i, N+1) ans = max(ans, dp[N][i]);
      |   ^~~~
a.cc:36:3: error: 'cout' does not name a type
   36 |   cout << ans << '\n';
      |   ^~~~
a.cc:37:3: error: expected unqualified-id before 'return'
   37 |   return 0;
      |   ^~~~~~
a.cc:38:1: error: expected declaration before '}' token
   38 | }
      | ^
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: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:42: error: 'pq' was not declared in this scope; did you mean 'dq'?
   36 |             ans += abs(tp - dq.back()) * pq.top().first;
      |                                          ^~
      |                                          dq