Language: C++

#include <bits/stdc++.h>

// #define fi first
// #define se second
#define rep(i, n) for (ll i=0;i<(n); i++)
#define ALL(v) (v).begin(), (v).end()
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

using namespace std;
typedef long long ll;
typedef pair<ll, ll> pi;

const ll M=1000000007ll;
const ll MOD=1000000007ll;
const ll MAX=100000001ll;
//const ll M = 1000000000+7;

ll cnt = 0; 

const int mod = 1000000007;
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 {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=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 {
    mint res(*this);
    return res/=a;
  }
};

mint f(ll n){
  if(n==0) return 1;
  mint ans = f(n/2);
  ans *= ans;
  if(n%2==1) ans*= 2;
  return ans;
}

mint choose(ll n, ll k){
  mint x=1, y=1;
  rep(i,k){
    x *= (n-i);
    y *= (i+1);
  }
  return x / y;
}

struct BIT {
  private:
   vector<ll> bit;
   ll N;
 
  public:
   BIT(ll size) {
     N = size;
     bit.resize(N + 1);
   }
 
   // 一点更新です
   void add(ll a, ll w) {
     for (ll x = a; x <= N; x += x & -x) bit[x] += w;
   }
 
   // 1~Nまでの和を求める。
   int sum(ll a) {
     ll ret = 0;
     for (ll x = a; x > 0; x -= x & -x) ret += bit[x];
     return ret;
   }
 };
 
ll fff(ll n,ll i, ll j, ll rl){
  ll can = 0;
  ll can_i = 0;

  // right
  if(rl == 0){
    rep(k, n){
      if(v[k]*(j-k)>can){
	can = v[k]*(j-k);
	can_i = k;
      }
    }
    v[can_i] = 0;
    return can;
  }
  // right
  else{
    rep(k, n){
      if(v[k]*(k-i)>can){
	can = v[k]*(k-i);
	can_i = k;
      }
    }
    v[can_i] = 0;
    return can;
  }
  
}

  vector<ll> v;
  ll n;

int main(){
  cin>>n;

  v.resize(n);
  rep(i, n){
    cin >> v[i];
  }

  ll dp[n+2][n+2];

  dp[0][n+1] = 0;
  
  rep(i, n){
    rep(j, n){
      if(i<n-1-(j+1)){
	dp[i][n-1-(j+1)] = dp[i][n-1-j] + fff(n, i, j, 0);
      }
      if(i+1<n-1-j){
	dp[i+1][n-1-j] = dp[i][n-1-j] + fff(n, i, j, 1);
      }
    }
  }

  ll ans = 0;
  rep(i, n-1){
    chmax(ans, dp[i+1][i+2])
  }

  cout<<ans<<endl;
}


Compiler output:
a.cc: In function 'll fff(ll, ll, ll, ll)':
a.cc:120:10: error: 'v' was not declared in this scope
  120 |       if(v[k]*(j-k)>can){
      |          ^
a.cc:125:5: error: 'v' was not declared in this scope
  125 |     v[can_i] = 0;
      |     ^
a.cc:131:10: error: 'v' was not declared in this scope
  131 |       if(v[k]*(k-i)>can){
      |          ^
a.cc:136:5: error: 'v' was not declared in this scope
  136 |     v[can_i] = 0;
      |     ^
a.cc: In function 'int main()':
a.cc:170:29: error: expected ';' before '}' token
  170 |     chmax(ans, dp[i+1][i+2])
      |                             ^
      |                             ;
  171 |   }
      |   ~