Language: C++

#include<bits/stdc++.h>
using namespace std;
#define mem(a,b) memset(a,b,sizeof a) ;
#define vi vector<int>
#define vit vector<int> :: iterator 
#define all(ans) ans.begin(),ans.end()
#define sz(a) int(a.size())
#define ub upper_bound
#define lb lower_bound
#define create(Name,N,M,val) vector<vector<int> > Name(N,vector<int>(M,val))
#define ull unsigned long long
#define ll long long 
#define db double 
#define ldb long double
#define fl float
#define rep(i,a,b) for(int i=a;i<b;i++)
#define lrep(i,a,b) for(ll i=a;i<b;i++)
//#define all(c) c.begin(),c.end()
#define tr(c,it) for(typeof(c.begin()) it=c.begin();it!=c.end();it++)
#define mpr make_pair
#define pb push_back
#define fr first
#define sn second
#define bpp(x) __builtin_popcountll(x)
const ldb PI = 3.14159265358979323846264338327950288419716939937510582097494459230781640628620899863;
const long long INF = 1e9+7;
/*
bool ok(string &s ,int l ,int r)
{
while(s[l]==s[r]) l++,r--;
return l>=r; 
}
int prime[]={2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89,97,101,103};
int add(int a,int b) // integer range
{
long x=a+b;
if(x>=INF)
x-=INF;
return x;
}
int gcd(int a, int b)
{
while(b)
{
a%=b;
swap(a,b);
}
return a;
}
ll pw(int a,int b)
{
ll res=1;
while(b)
{
if(b&1) res=(res*a)%INF;
a=(a*a)%INF;
b>>=1;
}
return res;
}
bool isFib(int n)
{
int x,y;
x=sqrt(5*n*n+4); y=sqrt(5*n*n-4);
return ((x*x)==(5*n*n+4))||((y*y)==(5*n*n-4));
}
int ExtU(int a,int b,int &x,int &y)
{
if(a==0)
{
x=0; y=1; return b;
}
int x1,y1;
int d=ExtU(b%a,a,x1,y1);
x=y1-(b/a)*x1;
y=x1;
return d;
}
int factors(int n)
{
int ct=0;
for(int i=1;i*i<=n;i++)
{
if(n%i==0)
{
if(i*i==n)
ct++;
else
ct+=2;
}
return ct;
}
}
vector<int>factorize(int n)
{
vi ans;
while(n%2==0)
{
ans.pb(2); n/=2;
}
for(int i=3;i<=sqrt(n);i+=2)
{
while(n%i==0)
{
ans.pb(i); n/=i;
}
}
if(n>2)
ans.pb(n);
return ans;
}
int mnpr[500003]={0};
void sprime(int n)
{
for(int i=2;i*i<=n;i++)
{
if(mnpr[i]==0)
{
for(int j=i*i;j<=n;j+=i)
{
if(mnpr[j]==0)
mnpr[j]=i;
}
}
}
for(int i=1;i<=n;i++)
if(mnpr[i]==0)
mnpr[i]=i;
}
int mxpr(int n)
{
int mx; 
while(n&1==0)
{
mx=2; n>>=1;
}
for(int i=3;i*i<=n;i+=2)
{
while(n%i==0)
{
mx=i; n/=i;
}
}
if(n>2)
mx=n;
return mx;
}
bool seg[100005]={true};
void ss(int r,int l)
{
rep(i,0,r-l+2)
seg[i]=true;
for(int i=2;i*i<=r;i++)
{
for(int j=max(i*i,((l+i-1)/i)*i);j<=r;j+=i)
seg[j-l]=false;
}
}
int phi(int n)
{
int res=n;
for(int i=2;i*i<=n;i++)
{
if(n%i==0)
{
while(n%i==0)
n/=i;
res-=res/i;
}
}
if(n>1)
res-=res/n;
return res;
}
int ncr(int n,int r)
{
int C[r+1];
mem(C,0);
C[0]=1;
for(int i=1;i<=n;i++)
{
for(int j=min(i,r);j;j--)
{
C[j]=(C[j]+C[j-1])%INF;
}
}
return C[r];
}
int bitzero(int n)
{
int ct=0;
while(n)
{
ct+=!(n&1);
n>>=1;
}
return ct;
}
string twocom(string &s)
{
int i;
for(i=s.length()-1;i>=0;i--)
if(s[i]=='1')
break;
if(i==-1)
{
return '1'+s;
}
for(int k=i-1;k>=0;k--)
{
if(s[k]=='1')
s[k]='0';
else
s[k]='1';
}
return s;
}
goto e;

e:
;
*/
void edit()
{
// string s; getline(cin,s);
// v.resize(num);
//create(dp,N,M,val);
//vector<int> vec;
//vec.pb(10);vec.pb(20);vec.pb(70);vec.pb(80); 
//tr(vec,it)
//cout<<(*it)<<' ';
//vector<int> v;
//v.pb(30);v.pb(40);v.pb(50);v.pb(60); 
//vec.insert(vec.begin()+2,all(v));
// copy(all(v1),inserter(v2,it));

// a[i]^a[i+j]^a[i+j+k]=='B'^'G'^'R';
// last element of set -> s.rbegin()
return;
}

ll dp[2005][2005],a[2005];
int n;
ll fun(int pos,int lf,int rt,ll sum)
{
	//if(dp[lf][rt]!=-1)
	//return dp[lf][rt];
	if(pos==n)
	return sum;
	ll left,right;
	left=a[pos]*(abs(lf-pos));
	right=a[pos]*(abs(rt-pos));
	dp[lf][rt]=max(dp[lf][rt],max(fun(pos+1,lf+1,rt,sum+left),fun(pos+1,lf,rt-1,sum+right)));
	return dp[lf][rt];
}
void solve()
{
cin>>n;
memset(dp,-1,sizeof(dp));
rep(i,0,n) cin>>a[i];
ll ans=fun(0,0,n-1,0);
cout<<ans;
return ;
}
int main()
{
ios_base::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
//	cin>>t;
while(t--)
{
solve();
}
return 0;
}

//  MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
//  MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
//  MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
//  MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMHBYYYWMMMM#BYYTTTYWMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
//  MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMB9O1==?????zzCC111>>;;;;;;;;;;;<?TMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
//  MMMMMMMMMMMMMMMMMMMMMMMMMMMMMM9Olll=l======??????????>>>>>>;;;;;;;;;:;?TMMMMMMMMMMMMMMMMMMMMMMMMMMMM
//  MMMMMMMMMMMMMMMMMMMMMMMMMMM9ttlllllllll=l=======?????????>>>>>>;;;;;;;;;;?TMMMMMMMMMMMMMMMMMMMMMMMMM
//  MMMMMMMMMMMMMMMMMMMMMMMMBOttOtttttltlllllllll=======??????????>>>>>>>;;;;;;?TMMMMMMMMMMMMMMMMMMMMMMM
//  MMMMMMMMMMMMMMMMMMMMMMBttwOtttttttttttttlllllllll========?????????>>>>>>;;;;;<TMMMMMMMMMMMMMMMMMMMMM
//  MMMMMMMMMMMMMMMMMMMMBrwZrttttttttttttttttttlllllllllll======???????????>>>>>>;;?HMMMMMMMMMMMMMMMMMMM
//  MMMMMMMMMMMMMMMMMMMSw0trtrrtrtrttrtttttttttttttlllOllllll========????<<zz??>>>>>>ZMMMMMMMMMMMMMMMMMM
//  MMMMMMMMMMMMMMMMMMX0ttrtrOOttrttrttOOttttttttttttltwllllllllll========??wy?????>>>vZMMMMMMMMMMMMMMMM
//  MMMMMMMMMMMMMMMMM0ttrI+wV1rtttttttwZtttttttltttOwylOXOllllllllllll=l====1dkz???????vZdMMMMMMMMMMMMMM
//  MMMMMMMMMMMMMMMSrrwrtwZCjttttttttwSttOlllltllllwtXOlZkOlllllllllllllll==z+dk===?????X2JMMMMMMMMMMMMM
//  MMMMMMMMMMMMMBrtwwtrw0<jttttttttOXllOttltllttllOZwHOtXkyltlllllllllllllll<+XZ======?dk?JMMMMMMMMMMMM
//  MMMMMMMMMMMMStwdZtwXC<+ttttttOOOd6ltZlltllllttllStWWOOHWytttttltltOllltllz:zHllll===zX=?dMMMMMMMMMMM
//  MMMMMMMMMMBrwdKOtwW3;;zrttttwZwXRlldOllltltlltttwlXvktdXWytltttttttOttlttl<<dklllllllZ===dMMMMMMMMMM
//  MMMMMMMMM8tQM#ttwW3;;;1trttwSwfUOlORltllltlllllldtX>dktDOWOtlttltttOOttltO<;+WOllllllXlllzMMMMMMMMMM
//  MMMMMMMM9OdM#Ottd$;;;;;<?1z0OKjRltd0llltOllllllldZX>?WOw_WWOtttttttttOttI<;;<dkttttllllllldMMMMMMMMM
//  MMMMMMM9wMMMSttwS<;;;;>;;;J<j>(I<?U111zltllllllld0X>~dkwl(WkttlttlOOwWk<;;:;;zHttttttwOllllMMMMMMMMM
//  MMMMMMBdMMM8tttdI+zttttttdSXt~dlzXwlllzzOzzzzzlldkW<~?kOk~?sx++++jdHmH6+++<;;jdZtttttdkOtlldMMMMMMMM
//  MMMMM#dMMM#tttw0+tttttttdKdf((RsdfRllllldZllltlldWK~~_W0w_~OWOlOdgg9ZtOWOtttz+wktttttdpktttwMMMMMMMM
//  MMMMMWMMMMSlttdIttttttOdWHH>~(IzWDRll=llzRlllzlldk$>++dkd<~_XkdgH9tttttdktttt+OkrttrtdfpkttOMMMMMMMM
//  MMMMNWMMM#Zttlk=tttttOXWWd$_.(IdW1R=llll=SlllzOldK<_._(kd6+-(MM9lltttttrWktttztWZttrwXppWttrMMMMMMMM
//  MMMMNMMMM#lltwDzttllOXyW0X:..(OXk<Rl=ll=lwOlllOld3<``.(Rd>~?CdklllltttttXdXttzOWktrwwWpfpkrtMMMMMMMM
//  MMMMMMMMM@ltldIzlttOXyW$w$```(OyD(Rl==llldZ=llIlw;~```-Xd:~~~~UkylltttAyHdgSrzObRtOXwpfppWrrMMMMMMMM
//  MMMMMMMMM@llldtlllldVyW+d>```.wZ$ wl==lI=wRl=ll=w<```` dd_..~~(RZXOQdggHH9ZwrzwHWrdXXppfppkrMMMMMMMM
//  MMMMMMMMM#llldlltlwyyyD(S-...,Wk] zI=l=llzWzl=l=P~```` jZ``...~zQkH@MBUtrZtrtldHRdSdpfpffpkwMMMMMMMM
//  MMMMNMMMMNZllXtllldVyW3(Mf=<ONMHP~(k===l=zdk=lld3```...(C````..(M96lttttrrtrrtdHWHXpfpppfpRwMMMMMMMM
//  MMMMMMMMMMNzzWZllzyyyy(W@`  =~MWK6 jz=lzlzvRz=lZ`.I+JgkWm&-. `..(ZltlttttrtttrWWHppfppfpppSdMMMMMMMM
//  MMMMMMMMMMMkAWRllzVyyS_(b    .MNHU-(Uz=lI={XkzO>.dVT7<TMHMNHHx-.(kwZyltttrtrrdHHpfppfpffpp0dMMMMMMMM
//  MMMMMMMMMMMMKyWzOzyyyk.`<!  hdWMH]``(S==t=l(kX2 ?_`    WMMHH#HH+.XwkwOttttrwrZ~(HfpfpppfpWwXMMMMMMMM
//  MMMMMMMMMMMMMHWROOyyyW;` `. (WVM#b```(0=zzz wX!```  a.dM#NM@N(4WhXkXkWtttttwd3O_(HpffpfpfWwSMMMMMMMM
//  MMMMMMMMMMMMNZvWzXXyyXP```-_ ?o+?!````.4=Z=`(:````  HpbNNMHHH (C=XXyWZWttrdwf:(>.dfppffppSXSMMMMMMMM
//  MMMMMMMMMMMMMRzuHzXyZXH.``````````````` ?zz ``````` ZKvTHHbWt `` XZyyHZWOdSZ<::~`(fpfpfffXp0WMMMMMMM
//  MMMMMMMMMMMMMKzyyHvyZZW____.`````````````.I_```````` ?nJzX7^````.WXWyyHyWKZ<:::_`Jffpfpfpfp0WMMMMMMM
//  MMMMMMMMMMMMM@zZyZWwWyXo-_~(~ ```````````` `````````````` _`````.WXkyyVWmWc::<~ .HffppfffffkXMMMMMMM
//  MMMMMMMMMMMMMKzZZZZXkUXr~....```````....```````````` ...  ````..JXWWyyW83vXx~..WfffVfWVffffkdMMMMMMM
//  MMMMMMMMMMMMMRzZZZZZZZZb````#include<bits/stdc++.h>
using namespace std;
#define mem(a,b) memset(a,b,sizeof a) ;
#define vi vector<int>
#define vit vector<int> :: iterator 
#define all(ans) ans.begin(),ans.end()
#define sz(a) int(a.size())
#define ub upper_bound
#define lb lower_bound
#define create(Name,N,M,val) vector<vector<int> > Name(N,vector<int>(M,val))
#define ull unsigned long long
#define ll long long 
#define db double 
#define ldb long double
#define fl float
#define rep(i,a,b) for(int i=a;i<b;i++)
#define lrep(i,a,b) for(ll i=a;i<b;i++)
//#define all(c) c.begin(),c.end()
#define tr(c,it) for(typeof(c.begin()) it=c.begin();it!=c.end();it++)
#define mpr make_pair
#define pb push_back
#define fr first
#define sn second
#define bpp(x) __builtin_popcountll(x)
const ldb PI = 3.14159265358979323846264338327950288419716939937510582097494459230781640628620899863;
const long long INF = 1e9+7;
/*
bool ok(string &s ,int l ,int r)
{
while(s[l]==s[r]) l++,r--;
return l>=r; 
}
int prime[]={2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89,97,101,103};
int add(int a,int b) // integer range
{
long x=a+b;
if(x>=INF)
x-=INF;
return x;
}
int gcd(int a, int b)
{
while(b)
{
a%=b;
swap(a,b);
}
return a;
}
ll pw(int a,int b)
{
ll res=1;
while(b)
{
if(b&1) res=(res*a)%INF;
a=(a*a)%INF;
b>>=1;
}
return res;
}
bool isFib(int n)
{
int x,y;
x=sqrt(5*n*n+4); y=sqrt(5*n*n-4);
return ((x*x)==(5*n*n+4))||((y*y)==(5*n*n-4));
}
int ExtU(int a,int b,int &x,int &y)
{
if(a==0)
{
x=0; y=1; return b;
}
int x1,y1;
int d=ExtU(b%a,a,x1,y1);
x=y1-(b/a)*x1;
y=x1;
return d;
}
int factors(int n)
{
int ct=0;
for(int i=1;i*i<=n;i++)
{
if(n%i==0)
{
if(i*i==n)
ct++;
else
ct+=2;
}
return ct;
}
}
vector<int>factorize(int n)
{
vi ans;
while(n%2==0)
{
ans.pb(2); n/=2;
}
for(int i=3;i<=sqrt(n);i+=2)
{
while(n%i==0)
{
ans.pb(i); n/=i;
}
}
if(n>2)
ans.pb(n);
return ans;
}
int mnpr[500003]={0};
void sprime(int n)
{
for(int i=2;i*i<=n;i++)
{
if(mnpr[i]==0)
{
for(int j=i*i;j<=n;j+=i)
{
if(mnpr[j]==0)
mnpr[j]=i;
}
}
}
for(int i=1;i<=n;i++)
if(mnpr[i]==0)
mnpr[i]=i;
}
int mxpr(int n)
{
int mx; 
while(n&1==0)
{
mx=2; n>>=1;
}
for(int i=3;i*i<=n;i+=2)
{
while(n%i==0)
{
mx=i; n/=i;
}
}
if(n>2)
mx=n;
return mx;
}
bool seg[100005]={true};
void ss(int r,int l)
{
rep(i,0,r-l+2)
seg[i]=true;
for(int i=2;i*i<=r;i++)
{
for(int j=max(i*i,((l+i-1)/i)*i);j<=r;j+=i)
seg[j-l]=false;
}
}
int phi(int n)
{
int res=n;
for(int i=2;i*i<=n;i++)
{
if(n%i==0)
{
while(n%i==0)
n/=i;
res-=res/i;
}
}
if(n>1)
res-=res/n;
return res;
}
int ncr(int n,int r)
{
int C[r+1];
mem(C,0);
C[0]=1;
for(int i=1;i<=n;i++)
{
for(int j=min(i,r);j;j--)
{
C[j]=(C[j]+C[j-1])%INF;
}
}
return C[r];
}
int bitzero(int n)
{
int ct=0;
while(n)
{
ct+=!(n&1);
n>>=1;
}
return ct;
}
string twocom(string &s)
{
int i;
for(i=s.length()-1;i>=0;i--)
if(s[i]=='1')
break;
if(i==-1)
{
return '1'+s;
}
for(int k=i-1;k>=0;k--)
{
if(s[k]=='1')
s[k]='0';
else
s[k]='1';
}
return s;
}
goto e;

e:
;
*/
void edit()
{
// string s; getline(cin,s);
// v.resize(num);
//create(dp,N,M,val);
//vector<int> vec;
//vec.pb(10);vec.pb(20);vec.pb(70);vec.pb(80); 
//tr(vec,it)
//cout<<(*it)<<' ';
//vector<int> v;
//v.pb(30);v.pb(40);v.pb(50);v.pb(60); 
//vec.insert(vec.begin()+2,all(v));
// copy(all(v1),inserter(v2,it));

// a[i]^a[i+j]^a[i+j+k]=='B'^'G'^'R';
// last element of set -> s.rbegin()
return;
}

ll dp[2005][2005];
vector<pair<ll,int> >a(2005);
int n;
ll fun(int pos,int lf,int rt,ll sum)
{
	//if(dp[lf][rt]!=-1)
	//return dp[lf][rt];
	if(pos==n)
	return sum;
	ll left,right;
	left=a[pos].fr*(abs(lf-a[pos].sn));
	right=(a[pos].fr)*(abs(rt-a[pos].sn));
	dp[lf][rt]=max(dp[lf][rt],max(fun(pos+1,lf+1,rt,sum+left),fun(pos+1,lf,rt-1,sum+right)));
	return dp[lf][rt];
}
void solve()
{
cin>>n;
memset(dp,-1,sizeof(dp));
rep(i,0,n) cin>>a[i].fr;
rep(i,0,n) a[i].sn=i;
sort(all(a),greater<pair<ll,int> >());
ll ans=fun(0,0,n-1,0);
cout<<ans;
return ;
}
int main()
{
ios_base::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
//	cin>>t;
while(t--)
{
solve();
}
return 0;
}

//  MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
//  MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
//  MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
//  MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMHBYYYWMMMM#BYYTTTYWMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
//  MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMB9O1==?????zzCC111>>;;;;;;;;;;;<?TMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
//  MMMMMMMMMMMMMMMMMMMMMMMMMMMMMM9Olll=l======??????????>>>>>>;;;;;;;;;:;?TMMMMMMMMMMMMMMMMMMMMMMMMMMMM
//  MMMMMMMMMMMMMMMMMMMMMMMMMMM9ttlllllllll=l=======?????????>>>>>>;;;;;;;;;;?TMMMMMMMMMMMMMMMMMMMMMMMMM
//  MMMMMMMMMMMMMMMMMMMMMMMMBOttOtttttltlllllllll=======??????????>>>>>>>;;;;;;?TMMMMMMMMMMMMMMMMMMMMMMM
//  MMMMMMMMMMMMMMMMMMMMMMBttwOtttttttttttttlllllllll========?????????>>>>>>;;;;;<TMMMMMMMMMMMMMMMMMMMMM
//  MMMMMMMMMMMMMMMMMMMMBrwZrttttttttttttttttttlllllllllll======???????????>>>>>>;;?HMMMMMMMMMMMMMMMMMMM
//  MMMMMMMMMMMMMMMMMMMSw0trtrrtrtrttrtttttttttttttlllOllllll========????<<zz??>>>>>>ZMMMMMMMMMMMMMMMMMM
//  MMMMMMMMMMMMMMMMMMX0ttrtrOOttrttrttOOttttttttttttltwllllllllll========??wy?????>>>vZMMMMMMMMMMMMMMMM
//  MMMMMMMMMMMMMMMMM0ttrI+wV1rtttttttwZtttttttltttOwylOXOllllllllllll=l====1dkz???????vZdMMMMMMMMMMMMMM
//  MMMMMMMMMMMMMMMSrrwrtwZCjttttttttwSttOlllltllllwtXOlZkOlllllllllllllll==z+dk===?????X2JMMMMMMMMMMMMM
//  MMMMMMMMMMMMMBrtwwtrw0<jttttttttOXllOttltllttllOZwHOtXkyltlllllllllllllll<+XZ======?dk?JMMMMMMMMMMMM
//  MMMMMMMMMMMMStwdZtwXC<+ttttttOOOd6ltZlltllllttllStWWOOHWytttttltltOllltllz:zHllll===zX=?dMMMMMMMMMMM
//  MMMMMMMMMMBrwdKOtwW3;;zrttttwZwXRlldOllltltlltttwlXvktdXWytltttttttOttlttl<<dklllllllZ===dMMMMMMMMMM
//  MMMMMMMMM8tQM#ttwW3;;;1trttwSwfUOlORltllltlllllldtX>dktDOWOtlttltttOOttltO<;+WOllllllXlllzMMMMMMMMMM
//  MMMMMMMM9OdM#Ottd$;;;;;<?1z0OKjRltd0llltOllllllldZX>?WOw_WWOtttttttttOttI<;;<dkttttllllllldMMMMMMMMM
//  MMMMMMM9wMMMSttwS<;;;;>;;;J<j>(I<?U111zltllllllld0X>~dkwl(WkttlttlOOwWk<;;:;;zHttttttwOllllMMMMMMMMM
//  MMMMMMBdMMM8tttdI+zttttttdSXt~dlzXwlllzzOzzzzzlldkW<~?kOk~?sx++++jdHmH6+++<;;jdZtttttdkOtlldMMMMMMMM
//  MMMMM#dMMM#tttw0+tttttttdKdf((RsdfRllllldZllltlldWK~~_W0w_~OWOlOdgg9ZtOWOtttz+wktttttdpktttwMMMMMMMM
//  MMMMMWMMMMSlttdIttttttOdWHH>~(IzWDRll=llzRlllzlldk$>++dkd<~_XkdgH9tttttdktttt+OkrttrtdfpkttOMMMMMMMM
//  MMMMNWMMM#Zttlk=tttttOXWWd$_.(IdW1R=llll=SlllzOldK<_._(kd6+-(MM9lltttttrWktttztWZttrwXppWttrMMMMMMMM
//  MMMMNMMMM#lltwDzttllOXyW0X:..(OXk<Rl=ll=lwOlllOld3<``.(Rd>~?CdklllltttttXdXttzOWktrwwWpfpkrtMMMMMMMM
//  MMMMMMMMM@ltldIzlttOXyW$w$```(OyD(Rl==llldZ=llIlw;~```-Xd:~~~~UkylltttAyHdgSrzObRtOXwpfppWrrMMMMMMMM
//  MMMMMMMMM@llldtlllldVyW+d>```.wZ$ wl==lI=wRl=ll=w<```` dd_..~~(RZXOQdggHH9ZwrzwHWrdXXppfppkrMMMMMMMM
//  MMMMMMMMM#llldlltlwyyyD(S-...,Wk] zI=l=llzWzl=l=P~```` jZ``...~zQkH@MBUtrZtrtldHRdSdpfpffpkwMMMMMMMM
//  MMMMNMMMMNZllXtllldVyW3(Mf=<ONMHP~(k===l=zdk=lld3```...(C````..(M96lttttrrtrrtdHWHXpfpppfpRwMMMMMMMM
//  MMMMMMMMMMNzzWZllzyyyy(W@`  =~MWK6 jz=lzlzvRz=lZ`.I+JgkWm&-. `..(ZltlttttrtttrWWHppfppfpppSdMMMMMMMM
//  MMMMMMMMMMMkAWRllzVyyS_(b    .MNHU-(Uz=lI={XkzO>.dVT7<TMHMNHHx-.(kwZyltttrtrrdHHpfppfpffpp0dMMMMMMMM
//  MMMMMMMMMMMMKyWzOzyyyk.`<!  hdWMH]``(S==t=l(kX2 ?_`    WMMHH#HH+.XwkwOttttrwrZ~(HfpfpppfpWwXMMMMMMMM
//  MMMMMMMMMMMMMHWROOyyyW;` `. (WVM#b```(0=zzz wX!```  a.dM#NM@N(4WhXkXkWtttttwd3O_(HpffpfpfWwSMMMMMMMM
//  MMMMMMMMMMMMNZvWzXXyyXP```-_ ?o+?!````.4=Z=`(:````  HpbNNMHHH (C=XXyWZWttrdwf:(>.dfppffppSXSMMMMMMMM
//  MMMMMMMMMMMMMRzuHzXyZXH.``````````````` ?zz ``````` ZKvTHHbWt `` XZyyHZWOdSZ<::~`(fpfpfffXp0WMMMMMMM
//  MMMMMMMMMMMMMKzyyHvyZZW____.`````````````.I_```````` ?nJzX7^````.WXWyyHyWKZ<:::_`Jffpfpfpfp0WMMMMMMM
//  MMMMMMMMMMMMM@zZyZWwWyXo-_~(~ ```````````` `````````````` _`````.WXkyyVWmWc::<~ .HffppfffffkXMMMMMMM
//  MMMMMMMMMMMMMKzZZZZXkUXr~....```````....```````````` ...  ````..JXWWyyW83vXx~..WfffVfWVffffkdMMMMMMM
//  MMMMMMMMMMMMMRzZZZZZZZZb````````````<````````````./<~._<_.____`(WfdyW3<:~~(XWkVVVVVVVHVVVVV0dMMMMMMM
//  MMMMMMMMMMMMMSzZZZZZZZWX-```````````````````````````.......~~._j9jX=_~~_(XZyVHHkyyyyWHyyykykOMMMMMMM
//  MMMMMMMMMMMMMSzuuuuuZXWZW,```````````````````````````````.``..(3<! ...JWyyXWyyyWHkyyWHyyyHyklMMMMMMM
//  MMMMMMMMMMMMNXzuuuXXuXSuuXh,```````` .... ```````````````````_~ .JWyyyyZyy0HyyZyyZyZXWZZZWHZIdMMMMMM
//  MMMMMMMMMMMMNwtuuuXkuXXuuuuXh,``````(:::~<?71(,``````````````.(UMNUkZZZZZZZHZZ0ZZZZZWWZZZWNXIdMMMMMM
//  MMMMMMMMMMMMNKOzuzXkuXuuuuuXuXW, ```` _~~~:~~(}```````````.(YC;::<kCfZZZZXO#ZZVZZZZZMZZuuMMNXzMMMMMM
//  MMMMMMMMMMMMHKOzzuXkzdzzzzuXXzuuU&.``````````````````` .JY>::::;;J=:dZuZuZd#uuruuuud#uuuXMMMNXdMMMMM
//  MMMMMMMMMMMMMNOvzzXkvMRzzzzXKzuzzzXh, `````````````..JC<;:;;:;;+7<:~(HHuXIdNuuzuuuXMSuuuWMMMMROMMMMM
//  MMMMMMMMMMMMMNvvvrdkvM#vzzzzHzzzzzuzzUG. ``` ...JdY<:;:;:::;;+v<~~~:(HpHmzMNXZzuzzd#zzzdMMMMMMRdMMMM
//  MMMMMMMMMMMMMNwrrvdRrMNwvvvvdRvvvzwkzzzzXWWHY=~~O+::::::::<+<~~~~~~~dppppWMMkZzzzwM#zzdMMMMMMMMNMMMM
//  MMMMMMMMMMMMMM#rrrwRrMMbOrrOZNkrvvvXwvvvvvwX;.~._W_:::::(?!~~~~~~~~(HpppppppHWdvwM#XwdMMMMMMMMMMNMMM
//  MMMMMMMMMMMMMMNyrrrRrWMMmzOrzdNyrrrZNvrwQWWfb....(r~~_J>_.....~.~~-dpfpffpfpppWHHMNdMMMMMMMMMMMMMMMM
//  MMMMMMMMMMMMMMMNrtrStdMMMNxzrzMNmrrrdNWfVfffP._-.(~_J!............JpfpffpfpfffpppWNppppHMMMMMMMMMMMM
//  MMMMMMMMMMMMMMMMNOtXtdMMMMMNxzZMMNmgHyVVVVVW%..?/(.,(x-..........(HfffpffpffpffWHHffpffppfVyyWMMMMMM````````<````````````./<~._<_.____`(WfdyW3<:~~(XWkVVVVVVVHVVVVV0dMMMMMMM
//  MMMMMMMMMMMMMSzZZZZZZZWX-```````````````````````````.......~~._j9jX=_~~_(XZyVHHkyyyyWHyyykykOMMMMMMM
//  MMMMMMMMMMMMMSzuuuuuZXWZW,```````````````````````````````.``..(3<! ...JWyyXWyyyWHkyyWHyyyHyklMMMMMMM
//  MMMMMMMMMMMMNXzuuuXXuXSuuXh,```````` .... ```````````````````_~ .JWyyyyZyy0HyyZyyZyZXWZZZWHZIdMMMMMM
//  MMMMMMMMMMMMNwtuuuXkuXXuuuuXh,``````(:::~<?71(,``````````````.(UMNUkZZZZZZZHZZ0ZZZZZWWZZZWNXIdMMMMMM
//  MMMMMMMMMMMMNKOzuzXkuXuuuuuXuXW, ```` _~~~:~~(}```````````.(YC;::<kCfZZZZXO#ZZVZZZZZMZZuuMMNXzMMMMMM
//  MMMMMMMMMMMMHKOzzuXkzdzzzzuXXzuuU&.``````````````````` .JY>::::;;J=:dZuZuZd#uuruuuud#uuuXMMMNXdMMMMM
//  MMMMMMMMMMMMMNOvzzXkvMRzzzzXKzuzzzXh, `````````````..JC<;:;;:;;+7<:~(HHuXIdNuuzuuuXMSuuuWMMMMROMMMMM
//  MMMMMMMMMMMMMNvvvrdkvM#vzzzzHzzzzzuzzUG. ``` ...JdY<:;:;:::;;+v<~~~:(HpHmzMNXZzuzzd#zzzdMMMMMMRdMMMM
//  MMMMMMMMMMMMMNwrrvdRrMNwvvvvdRvvvzwkzzzzXWWHY=~~O+::::::::<+<~~~~~~~dppppWMMkZzzzwM#zzdMMMMMMMMNMMMM
//  MMMMMMMMMMMMMM#rrrwRrMMbOrrOZNkrvvvXwvvvvvwX;.~._W_:::::(?!~~~~~~~~(HpppppppHWdvwM#XwdMMMMMMMMMMNMMM
//  MMMMMMMMMMMMMMNyrrrRrWMMmzOrzdNyrrrZNvrwQWWfb....(r~~_J>_.....~.~~-dpfpffpfpppWHHMNdMMMMMMMMMMMMMMMM
//  MMMMMMMMMMMMMMMNrtrStdMMMNxzrzMNmrrrdNWfVfffP._-.(~_J!............JpfpffpfpfffpppWNppppHMMMMMMMMMMMM
//  MMMMMMMMMMMMMMMMNOtXtdMMMMMNxzZMMNmgHyVVVVVW%..?/(.,(x-..........(HfffpffpffpffWHHffpffppfVyyWMMMMMM

Compiler output:
a.cc:340:11: error: redefinition of 'const long double PI'
  340 | const ldb PI = 3.14159265358979323846264338327950288419716939937510582097494459230781640628620899863;
      |           ^~
a.cc:25:11: note: 'const long double PI' previously defined here
   25 | const ldb PI = 3.14159265358979323846264338327950288419716939937510582097494459230781640628620899863;
      |           ^~
a.cc:341:17: error: redefinition of 'const long long int INF'
  341 | const long long INF = 1e9+7;
      |                 ^~~
a.cc:26:17: note: 'const long long int INF' previously defined here
   26 | const long long INF = 1e9+7;
      |                 ^~~
a.cc:538:6: error: redefinition of 'void edit()'
  538 | void edit()
      |      ^~~~
a.cc:223:6: note: 'void edit()' previously defined here
  223 | void edit()
      |      ^~~~
a.cc:557:4: error: redefinition of 'long long int dp [2005][2005]'
  557 | ll dp[2005][2005];
      |    ^~
a.cc:242:4: note: 'long long int dp [2005][2005]' previously declared here
  242 | ll dp[2005][2005],a[2005];
      |    ^~
a.cc:558:22: error: conflicting declaration 'std::vector<std::pair<long long int, int> > a'
  558 | vector<pair<ll,int> >a(2005);
      |                      ^
a.cc:242:19: note: previous declaration as 'long long int a [2005]'
  242 | ll dp[2005][2005],a[2005];
      |                   ^
a.cc:559:5: error: redefinition of 'int n'
  559 | int n;
      |     ^
a.cc:243:5: note: 'int n' previously declared here
  243 | int n;
      |     ^
a.cc:560:4: error: redefinition of 'long long int fun(int, int, int, long long int)'
  560 | ll fun(int pos,int lf,int rt,ll sum)
      |    ^~~
a.cc:244:4: note: 'long long int fun(int, int, int, long long int)' previously defined here
  244 | ll fun(int pos,int lf,int rt,ll sum)
      |    ^~~
a.cc: In function 'long long int fun(int, int, int, long long int)':
a.cc:337:12: error: request for member 'first' in 'a[pos]', which is of non-class type 'long long int'
  337 | #define fr first
      |            ^~~~~
a.cc:567:21: note: in expansion of macro 'fr'
  567 |         left=a[pos].fr*(abs(lf-a[pos].sn));
      |                     ^~
a.cc:338:12: error: request for member 'second' in 'a[pos]', which is of non-class type 'long long int'
  338 | #define sn second
      |            ^~~~~~
a.cc:567:39: note: in expansion of macro 'sn'
  567 |         left=a[pos].fr*(abs(lf-a[pos].sn));
      |                                       ^~
a.cc:337:12: error: request for member 'first' in 'a[pos]', which is of non-class type 'long long int'
  337 | #define fr first
      |            ^~~~~
a.cc:568:23: note: in expansion of macro 'fr'
  568 |         right=(a[pos].fr)*(abs(rt-a[pos].sn));
      |                       ^~
a.cc:338:12: error: request for member 'second' in 'a[pos]', which is of non-class type 'long long int'
  338 | #define sn second
      |            ^~~~~~
a.cc:568:42: note: in expansion of macro 'sn'
  568 |         right=(a[pos].fr)*(abs(rt-a[pos].sn));
      |                                          ^~
a.cc: At global scope:
a.cc:572:6: error: redefinition of 'void solve()'
  572 | void solve()
      |      ^~~~~
a.cc:256:6: note: 'void solve()' previously defined here
  256 | void solve()
      |      ^~~~~
a.cc: In function 'void solve()':
a.cc:337:12: error: request for member 'first' in 'a[i]', which is of non-class type 'long long int'
  337 | #define fr first
      |            ^~~~~
a.cc:576:22: note: in expansion of macro 'fr'
  576 | rep(i,0,n) cin>>a[i].fr;
      |                      ^~
a.cc:338:12: error: request for member 'second' in 'a[i]', which is of non-class type 'long long int'
  338 | #define sn second
      |            ^~~~~~
a.cc:577:17: note: in expansion of macro 'sn'
  577 | rep(i,0,n) a[i].sn=i;
      |                 ^~
a.cc:321:22: error: request for member 'begin' in 'a', which is of non-class type 'long long int [2005]'
  321 | #define all(ans) ans.begin(),ans.end()
      |                      ^~~~~
a.cc:578:6: note: in expansion of macro 'all'
  578 | sort(all(a),greater<pair<ll,int> >());
      |      ^~~
a.cc:321:34: error: request for member 'end' in 'a', which is of non-class type 'long long int [2005]'
  321 | #define all(ans) ans.begin(),ans.end()
      |                                  ^~~
a.cc:578:6: note: in expansion of macro 'all'
  578 | sort(all(a),greater<pair<ll,int> >());
      |      ^~~
a.cc: At global scope:
a.cc:583:5: error: redefinition of 'int main()'
  583 | int main()
      |     ^~~~
a.cc:265:5: note: 'int main()' previously defined here
  265 | int main()
      |     ^~~~