Language: C++

#include <string>
#include <vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<functional>
#include<list>
#include<deque>
#include<bitset>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<cstring>
#include<sstream>
#include<complex>
#include<iomanip>
#include<numeric>
#include<cassert>
#define X first
#define Y second
#define pb push_back
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define rreps(X,S,Y) for (int (X) = (Y)-1;(X) >= (S);--(X))
#define repe(X,Y) for ((X) = 0;(X) < (Y);++(X))
#define peat(X,Y) for (;(X) < (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define eb emplace_back
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())
#define Endl endl
#define int long long

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T> using vv=vector<vector<T>>;
template<class T> ostream& operator<<(ostream &os, const deque<T> &t) {
os<<"{"; rep(i,t.size()) {os<<t[i]<<",";} os<<"}"<<endl; return os;}
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"{"; rep(i,t.size()) {os<<t[i]<<",";} os<<"}"<<endl; return os;}
template<class T,size_t n> ostream& operator<<(ostream &os, const array<T,n> &t) {
	os<<"{"; rep(i,n) {os<<t[i]<<",";} os<<"}"<<endl; return os;}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
template<class S, class T,class U> ostream& operator<<(ostream &os, const tuple<S,T,U> &t) { return os<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
template<class S, class T,class U,class V> ostream& operator<<(ostream &os, const tuple<S,T,U,V> &t) { return os<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<","<<get<3>(t)<<")";}
template<class S, class T,class U,class V,class W> ostream& operator<<(ostream &os, const tuple<S,T,U,V,W> &t) { return os<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<","<<get<3>(t)<<","<<get<4>(t)<<")";}
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}
//#undef NUIP
#ifdef NUIP
#define out(args...){vector<string> a_r_g_s=s_p_l_i_t(#args, ','); e_r_r(a_r_g_s.begin(), args); }
vector<string> s_p_l_i_t(const string &s, char c){vector<string> v;int d=0,f=0;string t;for(char c:s){if(!d&&c==',')v.pb(t),t="";else t+=c;if(c=='\"'||c=='\'')f^=1;if(!f&&c=='(')++d;if(!f&&c==')')--d;}v.pb(t);return move(v);}
void e_r_r(vector<string>::iterator it) {}
template<typename T, typename... Args> void e_r_r(vector<string>::iterator it, T a, Args... args){ if(*it==" 1"||*it=="1") cerr<<endl; else cerr << it -> substr((*it)[0] == ' ', it -> length()) << " = " << a << ", "; e_r_r(++it, args...);}
#else
#define out
#endif
#ifdef __cpp_init_captures
template<typename T>vector<T> table(int n, T v){ return vector<T>(n, v);}
template <class... Args> auto table(int n, Args... args){auto val = table(args...); return vector<decltype(val)>(n, move(val));}
#endif
ll INF=1e18;

ll dp[5123][5123];

signed main(){
  ios_base::sync_with_stdio(false);
  cout<<fixed<<setprecision(0);
	int n,R,L;
	// n=5000; R=L=1000000000; --L;
	cin>>n>>R>>L;
	INF=ll(n-1)*min(L,R);
	vector<int> a(n); //rep(i,n) a[i]=n-1-i;
	rep(i,n) cin>>a[i], --a[i];
	vector<int> toL(n),toR(n);
	{
		set<int> st{MOD};
		rep(i,n){
			toL[a[i]]=*st.lower_bound(a[i]);
			st.insert(a[i]);
		}
	}
	{
		set<int> st{-MOD};
		rrep(i,n){
			auto it=st.lower_bound(a[i]); --it;
			toR[a[i]]=*it;
			st.insert(a[i]);
		}
	}
	// out(toL,toR,1);
	fill(dp[0],dp[5123],INF);
	dp[0][n-1]=0;
	rreps(d,2,n+1)rep(l,n+1-d){
		int r=l+d-1;
		MN(dp[l+1][r],dp[l][r]+(toL[l]>r?0:L));
		MN(dp[l][r-1],dp[l][r]+(toR[r]<l?0:R));
	}
	// rep(i,n){rep(j,n) cout<<dp[i][j]<<",";cout<<endl;}
	ll re=INF;
	rep(i,n) MN(re,dp[i][i]);
	cout<<re<<endl;
  return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:85:29: error: 'MOD' was not declared in this scope
   85 |                 set<int> st{MOD};
      |                             ^~~
a.cc:85:32: error: no matching function for call to 'std::set<long long int>::set(<brace-enclosed initializer list>)'
   85 |                 set<int> st{MOD};
      |                                ^
In file included from /usr/include/c++/14/set:63,
                 from a.cc:14:
/usr/include/c++/14/bits/stl_set.h:273:9: note: candidate: 'template<class _InputIterator> std::set<_Key, _Compare, _Alloc>::set(_InputIterator, _InputIterator, const allocator_type&) [with _Key = long long int; _Compare = std::less<long long int>; _Alloc = std::allocator<long long int>]'
  273 |         set(_InputIterator __first, _InputIterator __last,
      |         ^~~
/usr/include/c++/14/bits/stl_set.h:273:9: note:   candidate expects 3 arguments, 1 provided
/usr/include/c++/14/bits/stl_set.h:210:9: note: candidate: 'template<class _InputIterator> std::set<_Key, _Compare, _Alloc>::set(_InputIterator, _InputIterator, const _Compare&, const allocator_type&) [with _Key = long long int; _Compare = std::less<long long int>; _Alloc = std::allocator<long long int>]'
  210 |         set(_InputIterator __first, _InputIterator __last,
      |         ^~~
/usr/include/c++/14/bits/stl_set.h:210:9: note:   candidate expects 3 arguments, 1 provided
/usr/include/c++/14/bits/stl_set.h:193:9: note: candidate: 'template<class _InputIterator> std::set<_Key, _Compare, _Alloc>::set(_InputIterator, _InputIterator) [with _Key = long long int; _Compare = std::less<long long int>; _Alloc = std::allocator<long long int>]'
  193 |         set(_InputIterator __first, _InputIterator __last)
      |         ^~~
/usr/include/c++/14/bits/stl_set.h:193:9: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/14/bits/stl_set.h:267:7: note: candidate: 'std::set<_Key, _Compare, _Alloc>::set(std::initializer_list<_Tp>, const allocator_type&) [with _Key = long long int; _Compare = std::less<long long int>; _Alloc = std::allocator<long long int>; allocator_type = std::allocator<long long int>]'
  267 |       set(initializer_list<value_type> __l, const allocator_type& __a)
      |       ^~~
/usr/include/c++/14/bits/stl_set.h:267:7: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/14/bits/stl_set.h:261:7: note: candidate: 'std::set<_Key, _Compare, _Alloc>::set(std::set<_Key, _Compare, _Alloc>&&, std::__type_identity_t<_Alloc>&) [with _Key = long long int; _Compare = std::less<long long int>; _Alloc = std::allocator<long long int>; std::__type_identity_t<_Alloc> = std::allocator<long long int>]'
  261 |       set(set&& __x, const __type_identity_t<allocator_type>& __a)
      |       ^~~
/usr/include/c++/14/bits/stl_set.h:261:7: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/14/bits/stl_set.h:257:7: note: candidate: 'std::set<_Key, _Compare, _Alloc>::set(const std::set<_Key, _Compare, _Alloc>&, std::__type_identity_t<_Alloc>&) [with _Key = long long int; _Compare = std::less<long long int>; _Alloc = std::allocator<long long int>; std::__type_identity_t<_Alloc> = std::allocator<long long int>]'
  257 |       set(const set& __x, const __type_identity_t<allocator_type>& __a)
      |       ^~~
/usr/include/c++/14/bits/stl_set.h:257:7: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/14/bits/stl_set.h:253:7: note: candidate: 'std::set<_Key, _Compare, _Alloc>::set(const allocator_type&) [with _Key = long long int; _Compare = std::less<long long int>; _Alloc = std::allocator<long long int>; allocator_type = std::allocator<long long int>]'
  253 |       set(const allocator_type& __a)
      |       ^~~
/usr/include/c++/14/bits/stl_set.h:253:7: note:   conversion of argument 1 would be ill-formed:
/usr/include/c++/14/bits/stl_set.h:245:7: note: candidate: 'std::set<_Key, _Compare, _Alloc>::set(std::initializer_list<_Tp>, const _Compare&, const allocator_type&) [with _Key = long long int; _Compare = std::less<long long int>; _Alloc = std::allocator<long long int>; allocator_type = std::allocator<long long int>]'
  245 |       set(initializer_list<value_type> __l,
      |       ^~~
/usr/include/c++/14/bits/stl_set.h:245:7: note:   conversion of argument 1 would be ill-formed:
/usr/include/c++/14/bits/stl_set.h:233:7: note: candidate: 'std::set<_Key, _Compare, _Alloc>::set(std::set<_Key, _Compare, _Alloc>&&) [with _Key = long long int; _Compare = std::less<long long int>; _Alloc = std::allocator<long long int>]'
  233 |       set(set&&) = default;
      |       ^~~
/usr/include/c++/14/bits/stl_set.h:233:7: note:   conversion of argument 1 would be ill-formed:
/usr/include/c++/14/bits/stl_set.h:225:7: note: candidate: 'std::set<_Key, _Compare, _Alloc>::set(const std::set<_Key, _Compare, _Alloc>&) [with _Key = long long int; _Compare = std::less<long long int>; _Alloc = std::allocator<long long int>]'
  225 |       set(const set&) = default;
      |       ^~~
/usr/include/c++/14/bits/stl_set.h:225:7: note:   conversion of argument 1 would be ill-formed:
/usr/include/c++/14/bits/stl_set.h:178:7: note: candidate: 'std::set<_Key, _Compare, _Alloc>::set(const _Compare&, const allocator_type&) [with _Key = long long int; _Compare = std::less<long long int>; _Alloc = std::allocator<long long int>; allocator_type = std::allocator<long long int>]'
  178 |       set(const _Compare& __comp,
      |       ^~~
/usr/include/c++/14/bits/stl_set.h:178:7: note:   conversion of argument 1 would be ill-formed:
/usr/include/c++/14/bits/stl_set.h:169:7: note: candidate: 'std::set<_Key, _Compare, _Alloc>::set() [with _Key = long long int; _Compare = std::less<long long int>; _Alloc = std::allocator<long long int>]'
  169 |       set() = default;
      |       ^~~
/usr/include/c++/14/bits/stl_set.h:169:7: note:   candidate expects 0 arguments, 1 provided
a.cc:92:30: error: 'MOD' was not declared in this scope
   92 |                 set<int> st{-MOD};
      |                              ^~~
a.cc:92:33: error: no matching function for call to 'std::set<long long int>::set(<brace-enclosed initializer list>)'
   92 |                 set<int> st{-MOD};
      |                                 ^
/usr/include/c++/14/bits/stl_set.h:273:9: note: candidate: 'template<class _InputIterator> std::set<_Key, _Compare, _Alloc>::set(_InputIterator, _InputIterator, const allocator_type&) [with _Key = long long int; _Compare = std::less<long long int>; _Alloc = std::allocator<long long int>]'
  273 |         set(_InputIterator __first, _InputIterator __last,
      |         ^~~
/usr/include/c++/14/bits/stl_set.h:273:9: note:   candidate expects 3 arguments, 1 provided
/usr/include/c++/14/bits/stl_set.h:210:9: note: candidate: 'template<class _InputIterator> std::set<_Key, _Compare, _Alloc>::set(_InputIterator, _InputIterator, const _Compare&, const allocator_type&) [with _Key = long long int; _Compare = std::less<long long int>; _Alloc = std::allocator<long long int>]'
  210 |         set(_InputIterator __first, _InputIterator __last,
      |         ^~~
/usr/include/c++/14/bits/stl_set.h:210:9: note:   candidate expects 3 arguments, 1 provided
/usr/include/c++/14/bits/stl_set.h:193:9: note: candidate: 'template<class _InputIterator> std::set<_Key, _Compare, _Alloc>::set(_InputIterator, _InputIterator) [with _Key = long long int; _Compare = std::less<long long int>; _Alloc = std::allocator<long long int>]'
  193 |         set(_InputIterator __first, _InputIterator __last)
      |         ^~~
/usr/include/c++/14/bits/stl_set.h:193:9: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/14/bits/stl_set.h:267:7: note: candidate: 'std::set<_Key, _Compare, _Alloc>::set(std::initializer_list<_Tp>, const allocator_type&) [with _Key = long long int; _Compare = std::less<long long int>; _Alloc = std::allocator<long long int>; allocator_type = std::allocator<long long int>]'
  267 |       set(initializer_list<value_type> __l, const allocator_type& __a)
      |       ^~~
/usr/include/c++/14/bits/stl_set.h:267:7: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/14/bits/stl_set.h:261:7: note: candidate: 'std::set<_Key, _Compare, _Alloc>::set(std::set<_Key, _Compare, _Alloc>&&, std::__type_identity_t<_Alloc>&) [with _Key = long long int; _Compare = std::less<long long int>; _Alloc = std::allocator<long long int>; std::__type_identity_t<_Alloc> = std::allocator<long long int>]'
  261 |       set(set&& __x, const __type_identity_t<allocator_type>& __a)
      |       ^~~
/usr/include/c++/14/bits/stl_set.h:261:7: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/14/bits/stl_set.h:257:7: note: candidate: 'std::set<_Key, _Compare, _Alloc>::set(const std::set<_Key, _Compare, _Alloc>&, std::__type_identity_t<_Alloc>&) [with _Key = long long int; _Compare = std::less<long long int>; _Alloc = std::allocator<long long int>; std::__type_identity_t<_Alloc> = std::allocator<long long int>]'
  257 |       set(const set& __x, const __type_identity_t<allocator_type>& __a)
      |       ^~~
/usr/include/c++/14/bits/stl_set.h:257:7: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/14/bits/stl_set.h:253:7: note: candidate: 'std::set<_Key, _Compare, _Alloc>::set(const allocator_type&) [with _Key = long long int; _Compare = std::less<long long int>; _Alloc = std::allocator<long long int>; allocator_type = std::allocator<long long int>]'
  253 |       set(const allocator_type& __a)
      |       ^~~
/usr/include/c++/14/bits/stl_set.h:253:7: note:   conversion of argument 1 would be ill-formed:
/usr/include/c++/14/bits/stl_set.h:245:7: note: candidate: 'std::set<_Key, _Compare, _Alloc>::set(std::initializer_list<_Tp>, const _Compare&, const allocator_type&) [with _Key = long long int; _Compare = std::less<long long int>; _Alloc = std::allocator<long long int>; allocator_type = std::allocator<long long int>]'
  245 |       set(initializer_list<value_type> __l,
      |       ^~~
/usr/include/c++/14/bits/stl_set.h:245:7: note:   conversion of argument 1 would be ill-formed:
/usr/include/c++/14/bits/stl_set.h:233:7: note: candidate: 'std::set<_Key, _Compare, _Alloc>::set(std::set<_Key, _Compare, _All