Problem:
Score : 1000 points

Problem Statement

You are given a permutation p = (p_1, \ldots, p_N) of \{ 1, \ldots, N \}.
You can perform the following two kinds of operations repeatedly in any order:

Pay a cost A. Choose integers l and r (1 \leq l < r \leq N), and shift (p_l, \ldots, p_r) to the left by one. That is, replace p_l, p_{l + 1}, \ldots, p_{r - 1}, p_r with p_{l + 1}, p_{l + 2}, \ldots, p_r, p_l, respectively.

Pay a cost B. Choose integers l and r (1 \leq l < r \leq N), and shift (p_l, \ldots, p_r) to the right by one. That is, replace p_l, p_{l + 1}, \ldots, p_{r - 1}, p_r with p_r, p_l, \ldots, p_{r - 2}, p_{r - 1}, respectively.

Find the minimum total cost required to sort p in ascending order.

Constraints

All values in input are integers.

1 \leq N \leq 5000

1 \leq A, B \leq 10^9

(p_1 \ldots, p_N) is a permutation of \{ 1, \ldots, N \}.

Input

Input is given from Standard Input in the following format:

N A B
p_1 \cdots p_N

Output

Print the minimum total cost required to sort p in ascending order.

Sample Input 1

3 20 30
3 1 2

Sample Output 1

20

Shifting (p_1, p_2, p_3) to the left by one results in p = (1, 2, 3).

Sample Input 2

4 20 30
4 2 3 1

Sample Output 2

50

One possible sequence of operations is as follows:

Shift (p_1, p_2, p_3, p_4) to the left by one. Now we have p = (2, 3, 1, 4).

Shift (p_1, p_2, p_3) to the right by one. Now we have p = (1, 2, 3, 4).

Here, the total cost is 20 + 30 = 50.

Sample Input 3

1 10 10
1

Sample Output 3

0

Sample Input 4

4 1000000000 1000000000
4 3 2 1

Sample Output 4

3000000000

Sample Input 5

9 40 50
5 3 4 7 6 1 2 9 8

Sample Output 5

220

Solution in C++14 (GCC 5.4.1) (judge verdict: Wrong Answer)

//!link: m,stdc++
//!flag: -g,-DWAAUTOMATON
// failed
/*+lmake
 * DEFINE += WAAUTOMATON
 */
#include <bits/stdc++.h>
#ifdef WAAUTOMATON
#define debug(args...)                                                                             \
    {                                                                                              \
        dbg, args;                                                                                 \
        cerr << endl;                                                                              \
    }
#define massert(x) assert(x)
#else
#define debug(args...) // Just strip off all debug tokens
#define massert(x)
#endif
using namespace std;
typedef unsigned uint;
typedef long long LL;
typedef unsigned long long ULL;
typedef std::pair<int, int> pii;
typedef std::pair<LL, LL> pll;
struct debugger
{
    template <typename T>
    debugger &operator,(const T &v)
    {
        std::cerr << v << " ";
        return *this;
    }
} dbg;

template <typename T>
inline void chmax(T &a, T b)
{
    a = std::max(a, b);
}

template <typename T>
inline void chmin(T &a, T b)
{
    a = std::min(a, b);
}

template <typename T>
inline T sqr(const T& x)
{
	return x*x;
}

template <size_t _I_Buffer_Size = 1 << 23, size_t _O_Buffer_Size = 1 << 23>
struct IO_Tp
{
    char _I_Buffer[_I_Buffer_Size];
    char *_I_pos;
    const char *_I_end;

    char _O_Buffer[_O_Buffer_Size];
    char *_O_pos;
    const char *_O_end;

    IO_Tp()
        : _I_pos(_I_Buffer)
        , _O_pos(_O_Buffer)
        , _I_end(_I_Buffer + _I_Buffer_Size)
        , _O_end(_O_Buffer + _O_Buffer_Size)
    {
    }

    ~IO_Tp() { fwrite(_O_Buffer, 1, _O_pos - _O_Buffer, stdout); }

    inline char getchar()
    {
        char res = *_I_pos;
        nextchar();
        return res;
    }

    inline bool is_digit(const char ch) { return '0' <= ch && ch <= '9'; }

    inline void nextchar()
    {
        ++_I_pos;
        if (_I_pos == _I_end) {
            fread(_I_Buffer, 1, _I_Buffer_Size, stdin);
            _I_pos = _I_Buffer;
        }
    }

    template <typename Int>
    inline IO_Tp &operator>>(Int &res)
    {
        res = 0;
        int k = 1;
        while (!is_digit(*_I_pos)) {
            if (*_I_pos == '-')
                k = -1;
            nextchar();
        }
        do {
            (res *= 10) += (*_I_pos) - '0';
            nextchar();
        } while (is_digit(*_I_pos));
        res *= k;
        return *this;
    }

    inline IO_Tp &operator>>(char &res)
    {
        do {
            res = *_I_pos;
            nextchar();
        } while (res == ' ' || res == '\0' || res == '\t' || res == '\n' || res == '\r');
        return *this;
    }

    inline void putchar(char x)
    {
        if (_O_pos == _O_end) {
            fwrite(_O_Buffer, 1, _O_pos - _O_Buffer, stdout);
            _O_pos = _O_Buffer;
        }
        *_O_pos++ = x;
    }
    template <typename Int>
    inline IO_Tp &operator<<(Int n)
    {
        if (n < 0) {
            putchar('-');
            n = -n;
        }
        static char _buf[20];
        char *_pos(_buf);
        do
            *_pos++ = '0' + n % 10;
        while (n /= 10);
        while (_pos != _buf)
            putchar(*--_pos);
        return *this;
    }

    inline IO_Tp &operator<<(char ch)
    {
        putchar(ch);
        return *this;
    }

    inline IO_Tp &operator<<(const char *s)
    {
        while (*s != 0) {
            putchar(*s);
            ++s;
        }
        return *this;
    }
};
IO_Tp<> IO;

const int MAXN=5000;
int a[MAXN+10];
LL A,B;
vector<int> in[MAXN+10],out[MAXN+10];
int icnt[MAXN+10],ocnt[MAXN+10];
void add(int x)
{
	for(auto v:out[x]) {
		icnt[v]++;
	}
}
bool b[MAXN+10];
int main()
{
#ifdef WAAUTOMATON
    //freopen("./in_D_5.txt", "r", stdin);
#endif
	LL ans=LLONG_MAX/3;
	int n;
	IO>>n>>A>>B;
	for(int i=1; i<=n; ++i) {
		IO>>a[i];
	}
	for(int i=1; i<=n; ++i) {
		for(int j=i+1; j<=n; ++j) {
			if (a[i]>a[j]) {
				in[a[i]].push_back(a[j]);
				out[a[j]].push_back(a[i]);
				ocnt[a[j]]++;
			}
		}
	}	
	LL cntb=n;
	for(int i=1; i<=n; ++i) {
		if (ocnt[i]==0) --cntb;
		else if (ocnt[i]==1) {
			add(i);
		}
	}
	chmin(ans,cntb*B);
	for(LL cnta=1; cnta<=n; ++cnta) {
		int p=0;
		for(int i=1; i<=n; ++i) {
			if (!b[i] && icnt[i]>=icnt[p]) {
				p=i;
			}
		}
		if (p==0 || icnt[p]==0) break;
		cntb-=icnt[p];
		chmin(ans,cnta*A+cntb*B);
		if (cntb==0) break;
		b[p]=true;
		for(auto v:in[p]) {
			ocnt[v]--;
			if (ocnt[v]==1) {
				add(v);
			}
		}
	}
	IO<<ans<<'\n';
    return 0;
}