A group of $$$n$$$ dancers rehearses a performance for the closing ceremony. The dancers are arranged in a row, they've studied their dancing moves and can't change positions. For some of them, a white dancing suit is already bought, for some of them — a black one, and for the rest the suit will be bought in the future.On the day when the suits were to be bought, the director was told that the participants of the olympiad will be happy if the colors of the suits on the scene will form a palindrome. A palindrome is a sequence that is the same when read from left to right and when read from right to left. The director liked the idea, and she wants to buy suits so that the color of the leftmost dancer's suit is the same as the color of the rightmost dancer's suit, the 2nd left is the same as 2nd right, and so on.The director knows how many burls it costs to buy a white suit, and how many burls to buy a black suit. You need to find out whether it is possible to buy suits to form a palindrome, and if it's possible, what's the minimal cost of doing so. Remember that dancers can not change positions, and due to bureaucratic reasons it is not allowed to buy new suits for the dancers who already have suits, even if it reduces the overall spending.

The first line contains three integers $$$n$$$, $$$a$$$, and $$$b$$$ ($$$1 \leq n \leq 20$$$, $$$1 \leq a, b \leq 100$$$) — the number of dancers, the cost of a white suit, and the cost of a black suit. The next line contains $$$n$$$ numbers $$$c_i$$$, $$$i$$$-th of which denotes the color of the suit of the $$$i$$$-th dancer. Number $$$0$$$ denotes the white color, $$$1$$$ — the black color, and $$$2$$$ denotes that a suit for this dancer is still to be bought.

If it is not possible to form a palindrome without swapping dancers and buying new suits for those who have one, then output -1. Otherwise, output the minimal price to get the desired visual effect.

NoteIn the first sample, the cheapest way to obtain palindromic colors is to buy a black suit for the third from left dancer and a white suit for the rightmost dancer.In the second sample, the leftmost dancer's suit already differs from the rightmost dancer's suit so there is no way to obtain the desired coloring.In the third sample, all suits are already bought and their colors form a palindrome.

#include <iostream>
using namespace std;
int main() {
	int n, wcost, bcost, *dancer, cost = 0;
	cin >> n >> wcost >> bcost;
	dancer = new int[n];
	for (int i = 0; i < n; i++)
		cin >> dancer[i];
	for (int i = 0,j = n-1; i <= j; i++,j--)
		if (i == j)
		{
			if (dancer[i] == 2)
				if (bcost < wcost)
				{
					cost += bcost;
				}
				else {
					cost += wcost;
				}
			break;
		}
		else {
			if (dancer[i] != dancer[j])
			{
				if (dancer[i] == 2 || dancer[j] == 2)
				{
					switch (dancer[i] + dancer[j])
					{
					case 2:
						cost += wcost;
						break;
					case 3:
						cost += bcost;
						break;
					}
				}
				else {
					cout << -1 << endl;
					return 0;
				}
			}
			else if(dancer[i] == 2) {
				if (bcost < wcost)
				{
					cost += 2 * bcost;
				}
				else
				{
					cost += 2 * wcost;
				}
			}

		}
	cout << cost << endl;
	delete dancer;
	return 0;
}

#include<bits/stdc++.h>
#define ll long long

using namespace std;

int main()
{

        ll n,w,b,cost=0,flag=0;
        cin >> n >> w >> b;
        ll arr[n];
        for(ll i=0; i<n; i++)
        {
            cin >> arr[i];
        }
        for(ll i=0; i<n/2; i++)
        {
            if(arr[i]!=arr[n-i-1]&&arr[i]!=2&&arr[n-1-i]!=2)
            {
                flag=1;
                //cout << "milena" << endl;
                break;
            }
            else if(arr[i]==arr[n-i-1]||arr[i]==2||arr[n-i-1]==2)
            {
                if(arr[i]!=2&&arr[n-i-1]!=2)
                {
                    //cout << "thikasse" << endl;
                }
                else if(arr[i]==2&&arr[n-i-1]!=2)
                {
                    if(arr[n-i-1])
                    {
                        cost+=b;
                    }
                    else
                        cost+=w;
                }
                else if(arr[i]!=2&&arr[n-i-1]==2)
                {
                    if(arr[i])
                    {
                        cost+=b;
                    }
                    else
                        cost+=w;

                }
                else if(arr[i]==2&&arr[n-i-1]==2)
                {
                    cost+=min(w,b);
                    cost+=min(w,b);
                }
            }
        }
        if(n%2){
            int a=(n/2);
            if(arr[a]==2){
                cost+=min(w,b);
            }
        }
        if(flag)
        {
            cout << "-1" << endl;
        }

        else
            cout << cost << endl;

}

#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <iterator>
#include <utility>
using namespace  std;

#define N 400005
#define inf 2e9
#define rep(i,x,y)  for(int i = x ; i< y ; i++)
#define F(i,x)  for(int i = 0 ; i< x ; i++)
#define ff first
#define ss second
#define pii pair < int , int>
#define ll long long
#define ull unsigned ll
#define mp make_pair
#define pb push_back
#define sca(a) scanf("%d",&a)
#define scaa(a,b) scanf("%d%d",&a,&b)
#define scaaa(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define write() freopen("out.txt", "w" , stdout)
#define read() freopen("in.txt" , "r", stdin)

#define SET(x) memset(x , -1 , sizeof x)
#define CLR(x) memset(x , 0 , sizeof x)
const long long MOD[] = {1000000007LL, 2117566807LL};
const long long BASE[] = {1572872831LL, 1971536491LL};
int a[N];
int main()
{
	int n;
	int a0 , a1;
	cin >> n;
	cin >> a0 >> a1 ;
	for(int i = 0 ; i< n ; i++){
		 sca(a[i]);
	}

    int j = n-1;
    ll res = 0;
    int tt = (n+1)/2;
	for(int i = 0 ; i < tt ; i++){
        if(a[i] != a[j]){
        	 if(a[i] == 1 || a[i] == 0){
        	 	 if(a[j] == 1 || a[j] == 0){
        	 	 	 cout << -1 << endl;
        	 	 	 return 0;
        	 	 }
        	 }

        	 if(a[i] == 0 || a[i] == 1){
        	 	 if(a[i] == 0) res += a0;
        	 	 if(a[i] == 1) res += a1;
        	 }
        	 if(a[j] == 0 || a[j] == 1){
        	 	if(a[j] == 0) res += a0;
        	 	 if(a[j] == 1) res += a1;
        	 }

        	 if(a[i] >1 && a[j] > 1){
        	 	 res += min(a0,a1);
        	 	 if(i != j) res += min(a0,a1);
        	 }
        }
        if(a[i] == a[j]){
        	 if(a[i] > 1 && a[j] > 1){
        	 	res += min(a0 , a1);
        	 	if(i != j) res += min(a0,a1);

        	 }
        }
        j--;
	}

	cout << res << endl;
}

#include <stdio.h>
#include <iostream>
#include <string>
#include <string.h>
#include <algorithm>
#include <math.h>
#include <set>
using namespace std;

int main(){
	int n,a,b,m[30]={};
	cin >> n >> a >> b;
	for(int i=0;i<n;i++)
		cin >> m[i];
	bool flag = 0;
	int sum = 0;
	for(int i=0;i<n/2;i++){
		if(flag){
		cout << -1;
		return 0;
		}
		if(m[i] != m[n-1-i] && m[i] != 2 && m[n-1-i] != 2)
			flag = 1;
		else
			if(m[i]==2 && m[n-1-i]==2){
			if(a>b)
				sum+=(2*b);
			else
				sum+=(2*a);
			}
			if(m[i] != m[n-1-i] && (m[i]==0 || m[n-1-i]==0)){
			sum+=a;
			}
			if(m[i] != m[n-1-i] && (m[i]==1 || m[n-1-i]==1)){
			sum+=b;
			}
	}
	if(flag){
		cout << -1;
		return 0;
	}
	if(n%2==1 && m[n/2]==2)
		sum+=min(a,b);
	cout << sum;
}

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

int main()
{
    int n,a,b;
    cin>>n>>a>>b;
    int arr[n+5];
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
    }
    int sum=0;
    if(n%2==1)
    {
        if(arr[n/2]==2)
            sum+=min(a,b);
    }
    for(int i=0;i<n/2;i++)
    {
        if(arr[i]==0 && arr[n-i-1]==1)
        {
            cout<<-1<<endl;
            return 0;
        }
        else if(arr[i]==1 && arr[n-i-1]==0)
        {
            cout<<-1<<endl;
            return 0;
        }
        else if(arr[i]==0 && arr[n-i-1]==2)
        {
            sum+=a;
        }
        else if(arr[i]==2 && arr[n-i-1]==0)
        {
            sum+=a;
        }
        else if(arr[i]==1 && arr[n-i-1]==2)
        {
            sum+=b;
        }
        else if(arr[i]==2 && arr[n-i-1]==1)
        {
            sum+=b;
        }
        else if(arr[i]==2 && arr[i]==2)
        {
            sum+=2*min(a,b);
        }
    }

    cout<<sum<<endl;

    return 0;
}

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int main() {
    int n, a, b;
    cin >> n >> a >> b;
    vector <int> v(n);
    for (auto& item : v)
        cin >> item;
    int cnt = 0;
    for (int i = 0, j = n-1; i < j; i++, j--) {
        if (v[i] != v[j]) {
            if (v[i] == 1) {
                if (v[j] == 0) {
                    cout << -1;
                    return 0;
                }
                else if (v[j] == 2) {
                    cnt += b;
                }
            }
            else if (v[i] == 0) {
                if (v[j] == 1) {
                    cout << -1;
                    return 0;
                }
                else if (v[j] == 2) {
                    cnt += a;
                }
            }
            else if (v[i] == 2) {
                if (v[j] == 1)
                    cnt += b;
                else
                    cnt += a;
            }

        }
        else if (v[i] == 2) {
            cnt += 2 * min (a,b);
        }
    }
    if (n % 2 == 1) {
        if (v[n/2] == 2) {
            cnt+= min (a,b);
        }
    }
    cout << cnt;
    return 0;
}

#include <iostream>
#include <windows.h>
using namespace std;
int main()
{
    int n,a,b,*A,sum=0;
    cin>>n>>a>>b;
    A=new int[n];
    for(int i=0;i<n;i++)
        cin>>A[i];
    for(int i=0,j=n-1;j>=0;i++,j--)
    {
        if(A[i]==A[j] && A[i]==2)
            sum+=min(a,b);
        else if(A[i]!=A[j] && (A[i]==2 || A[j]==2))
        {
            if(A[i]==2)
               {
                   (A[j]==0?sum+=a:sum+=b);
                   A[i]=A[j];
               }
            else
                {
                    (A[i]==0?sum+=a:sum+=b);
                    A[j]=A[i];
                }
        }
        else if(A[i]!=A[j])
        {
            cout<<-1;
            return 0;
        }
    }
    cout<<sum;
    return 0;
}

#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<stdio.h>
#include<cstring>
#include<cstdio>
#include<stdlib.h>
#include<sstream>
#include<list>
#include<math.h>
#include<map>
#include<set>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<fstream>
#include<vector>
#include<algorithm>
#include <queue>
#include<string>
#include<cstring>
#include <deque>
#include<stack>
using namespace std;

long long GCDFast(long long a, long long b){ while (b)b ^= a ^= b ^= a %= b;  return a; }
#define SET(a) memset(a,-1,sizeof(a))
#define ALL_BITS ((1 << 31) - 1)
#define NEG_BITS(mask) (mask ^= ALL_BITS)
#define TEST_BIT(mask, i) (mask & (1 << i))
#define ON_BIT(mask, i) (mask |= (1 << i))
#define OFF_BIT(mask, i) (mask &= NEG_BITS(1 << i))
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000000007
#define MX 100010
#define pii pair<int,int>
#define LL long long
// UP, RIGHT, DOWN, LEFT, UPPER-RIGHT, LOWER-RIGHT, LOWER-LEFT, UPPER-LEFT
//int dx[8] = { -1, 0, 1, 0, -1, 1, 1, -1 };
//int dy[8] = { 0, 1, 0, -1, 1, 1, -1, -1 };

#define prime 1949313259//Prime,base
#define MOD 2091573227//MOD

int simpleHash(string arr, long long base, long long mod){
	long long product = base;
	long long sum = 0;
	for (int i = 0; i < arr.size(); i++){
		long long tempSum = (arr[i] % mod  * product % mod) % mod;
		sum = (sum%mod + tempSum%mod) % mod;
		product = (product * base) % mod;
	}
	return (int)sum; //sum would never be bigger than (2^31 - 1) as mod < (2^31-1)
}
long long Hash(string arr){

	return simpleHash(arr, prime, MOD);

}

LL a[1000005];
int main() {
	//freopen ("d:/Codejam/B-small-attempt0.in","r",stdin);
	//freopen ("d:/Codejam/output1.txt","w",stdout);
	LL n, i, j, k, temp;
	LL  x, u, v, y, z, sum, length, ans, l, w, num, q;
	string str;
	int test = 0, test_case, m;

	ios::sync_with_stdio(false);

	LL b;

	while (cin>>n){
		cin>>w>>b;
		sum = 0;

		for(i=0;i<n;i++){
			cin>>a[i];
		}
		LL mid = n/2;
		bool flag = true;

		if(n%2 == 1 && a[mid] == 2) {
				sum+= std::min(w,b);
		}
		for(i=0,j = n-1;i < mid;i++,j--){
			 if((a[i] == a[j] && a[i] == 2)){
				sum+= std::min(w,b);
				sum+= std::min(w,b);
			}else if((a[i] == 0 && a[j] == 1) || (a[i] == 1 && a[j] == 0)){
				flag = false;
				break;
			}else if((a[i] == 1 && a[j] == 2)||(a[i] == 2 && a[j] == 1)){
				sum+=b;
			}else if((a[i] == 0 && a[j] == 2)||(a[i] == 2 && a[j] == 0)){
				sum+=w;
			}
		}
		if(flag)
			cout<<sum<<"\n";
		else
			cout<<"-1\n";
	}

	return 0;
}

// Solve.cpp: ���������� ����� ����� ��� ����������� ����������.
//
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include<vector>
#include <cmath>
#include<iomanip>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>

using namespace std;

struct point
{
	int x, num;
	bool is_left;
};

bool cmp(point a, point b)
{
	if (a.x < b.x) return 1;
	return 0;
}

vector<short> mas;
long long n, a, b, o, mi;

int rec(short cur,  long long sum)
{
	if (cur >= mas.size())
	{
		if (sum < mi)
		{
			bool ch = 1;
			for (int i = 0; i < n / 2; i++)
			{
				ch *= (mas[i] == mas[n - i - 1]);
			}
			if (ch) mi = sum;
		}
		return 0;
	}
	if (mas[cur] == 2)
	{
		mas[cur] = 0;
		rec(cur + 1, sum + a);
		mas[cur] = 1;
		rec(cur + 1, sum + b);
		mas[cur] = 2;
	}
	else rec(cur + 1, sum);
}

int main()
{
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#else
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
#endif
	cin >> n >> a >> b;
	mas.resize(n);
	mi = 1e9;
	for (int i = 0; i < n; i++)
	{
		cin >> mas[i];
	}
	rec(0, 0);
	if (mi == 1e9) cout << -1;
	else cout << mi;
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define rkc ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
#define fl(i,a,b) for(ll i=a;i<b;i++)
#define rfl(i,a,b) for(ll i=a;i>b;i--)
#define pb push_back
#define mp make_pair
#define test ll t;cin>>t;while(t--)
#define lld long double
const ll M = 1e9 + 7;
const double pi  =3.141592653589793238463;

int main()
{
    rkc;
    ll n,a1,b,c=0,ans=0,flag=0;
    cin>>n>>a1>>b;
    ll a[n];
    fl(i,0,n){cin>>a[i];if(a[i]==2)c++;}
    fl(i,0,n)
    {
        if(i>n-i-1)break;
		if(a[i]==a[n-i-1] && a[i]==2)
		{
			ans+=min(a1,b);
			if(i!=n-i-1)
			{
				ans+=min(a1,b);
			}
		}
		else if((a[i]==1 && a[n-i-1]==2 ) || ( a[i]==2 && a[n-i-1]==1))
		{
			ans+=b;
		}
		else if((a[i]==0 && a[n-i-1]==2 ) || ( a[i]==2 && a[n-i-1]==0))
		{
			ans+=a1;
		}
		else if(a[i]==a[n-i-1])
		{
			continue;
		}
		else
		{
			cout<<-1;
			return 0;
		}
	}
	cout<<ans;

}

#include <algorithm>
#include <iostream>
#include <vector>
#include <cstdio>
using namespace std;
int num[1005],a,b,n;
int main(){
    while(cin>>n>>a>>b){
        for(int i = 0 ; i < n ; ++i){
            scanf("%d",num+i);
        }
        if(n>20)for(;;);
        int i = 0 , j = n-1;
        bool can = true;
        int res = 0;
        while (i<j){
            if(num[i]+num[j]==1){
                can = false;
                break;
            }
            if(num[i] == 2 and num[j]==2){
                res+=2*min(a,b);
            }
            else if(num[i]==2){
                res+=num[j]?b:a;
            }
            else if(num[j]==2) {
                res += num[i] ? b : a;
            }
            ++i,--j;
        }
        if(can){
            if(i==j and num[i]==2)res+=min(a,b);
            cout<<res<<"\n";
        }
        else cout<<-1<<"\n";
    }
    return 0;
}

#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
int a,b,n,ans;
int temp[50];
int main(){
	scanf("%d%d%d",&n,&a,&b);
	for(int i=1;i<=n;i++){
		scanf("%d",&temp[i]);
	}
	if(n==1) {
		if(temp[1]!=2) printf("0");
		else {
			printf("%d",min(a,b));
		}
		return 0;
	}
	for(int i=1;i<=n/2;i++){
		if(temp[i]!=temp[n-i+1]){
			if(temp[i]!=2&&temp[n-i+1]!=2) {
				printf("-1");
				return 0;
			}
			else {
				if(temp[i]==1||temp[n-i+1]==1) {
					ans+=b;
				}
				else ans+=a;
			}
		}
		else if(temp[i]==2&&temp[n-i+1]==2)
			ans+=min(a,b)*2;
//		printf("ans=%d\n",ans);
	}
	int tem=n%2,tem2=n/2;
	if(tem) {
		tem2++;
		if(temp[tem2]==2) ans+=min(a,b);
	}
	printf("%d",ans);
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
const int MAXN = 20;
int n, a, b, arr[MAXN + 5], ans;

int main() {
    cin >> n >> a >> b;
    for(int i = 0; i < n; i++)
        cin >> arr[i];
    for(int i = 0; i <= n/2 - 1; i++)
    {
        if(arr[i]==arr[n-i-1] && arr[i]==2)
            ans+= 2*min(a, b);
        else if(arr[i]!=arr[n-i-1] && (arr[i]==2 || arr[n-i-1]==2))
        {
            if(arr[i]==0 || arr[n-i-1]==0) ans+= a;
            else ans+= b;
        }
        else if(arr[i]!=arr[n-i-1])
        {
            cout << -1 << endl;
            return 0;
        }
    }
    if(n%2 && arr[n/2]==2) ans+= min(a,b);
    cout << ans << endl;
    return 0;
}

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

int main() {
    int N, A, B;
    scanf("%d%d%d", &N, &A, &B);
    vector<int> Suit(N, 2);
    for (int i = 0; i < N; ++i) {
        scanf("%d", &Suit[i]);
    }
    bool Flag = true;
    int Cnt = 0, Ans = 0;;
    int Mid = N / 2;
    for (int i = 0; i < Mid; ++i) {
        if (Suit[i] == 2) {
            if (Suit[N - i - 1] == 0) {
                Ans += A;
            }
            else if (Suit[N - i - 1] == 1) {
                Ans += B;
            }
            else {
                if (Suit[N - i - 1] == 2) {
                    Cnt += 2;
                }
                else {
                    Cnt++;
                }
            }
        }
        else if (Suit[N - i - 1] == 2) {
            if (Suit[i] == 0) {
                Ans += A;
            }
            else if (Suit[i] == 1) {
                Ans += B;
            }
            else {
                if (Suit[i] == 2) {
                    Cnt += 2;
                }
                else {
                    Cnt++;
                }
            }
        }
        else if (Suit[i] != Suit[N - i - 1]) {
            Flag = false;
        }
    }
    Ans += Cnt * min(A, B);
    if ((N & 1) && Suit[(N + 1) / 2 - 1] == 2) {
        Ans += min(A, B);
    }
    Ans = Flag ? Ans : -1;
    printf("%d\n", Ans);
    return 0;
}

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#include<vector>
#include<string>
#include<cmath>
#include<iomanip>
using namespace std;
int n, a, b,ans,flag;
int mi;
int s[25];
int main()
{
	scanf("%d %d %d", &n, &a, &b);
	mi = min(a, b);
	ans = 0;
	flag = 1;
	for (int i = 1; i <= n; i++)
	{
		scanf("%d", &s[i]);
	}
	for (int i = 1; i <= n / 2; i++)
	{
		if (s[i] == 2&&s[n-i+1]==2)
		{
			ans += 2 * mi;
		}
		else if(s[i]!=s[n-i+1])
		{
			if (s[i] < 2 && s[n - i + 1] < 2)
			{
				flag = 0;
				break;
			}
			else
			{
				if (s[i] + s[n - i + 1] - 2 == 0)
				{
					ans += a;
				}
				else
				{
					ans += b;
				}
			}
		}
	}
	if (n % 2 == 1 && s[n / 2 + 1] == 2)
	{
		ans += mi;
	}
	if (flag)
		printf("%d\n", ans);
	else
		printf("-1\n");
	return 0;
}

    #include <iostream>
    #include <vector>
    #include <algorithm>
    using namespace std;

    int main()
    {
    	setlocale(LC_ALL, "RUS");
    	int n, a, b, sum = 0;
    	cin >> n >> a >> b;
    	vector<int>A(n);
    	for (int i = 0; i < n; i++)
    		cin >> A[i];
    	for (int i = 0; i < n / 2; i++)
    	{
    		if ((A[i] == 0 && A[n - 1 - i] == 1) || (A[i] == 1 && A[n - 1 - i] == 0))
    		{
    			cout << "-1";
    			return 0;
    		}
    		else if (A[i] == A[n - 1 - i] && (A[i] == 1 || A[i] == 0 || A[i] == 2))
    		{
    			if (A[i] == 2)
    				sum += min(a, b) * 2;
    		}
    		else if (A[i] == 2 && A[n - 1 - i] != 2)
    		{
    			if (A[n - 1 - i] == 0)
    				sum += a;
    			else
    				sum += b;
    		}
    		else
    		{
    			if (A[i] == 0)
    				sum += a;
    			else
    				sum += b;
    		}
    	}
    	if (n % 2 == 0)
    		cout << sum;
    	else
    	{
    		if (A[n / 2] == 2)
    			sum += min(a, b);
    		cout << sum;
    	}
    	return 0;
    }

#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,a,b,i,ad;
    int rs=0;
    cin>>n>>a>>b;
    // dancer white black
    int dancers[n];
    for(i=0;i<n;i++)
        cin>>dancers[i];
    for(i=0;i<n/2;i++)
    {
//            cout<<dancers[i]<<" "<<dancers[n-i-1]<<endl;
        if(dancers[i]!=dancers[n-i-1] && dancers[i]!=2 && dancers[n-1-i]!=2)
        {
            cout<<-1;
            return 0;
        }
        if(dancers[i]==dancers[n-i-1] && dancers[i]==2)
        {
            ad=(a>b)?b:a;
            rs=rs+2*ad;
        }
        else if(dancers[i]!=dancers[n-i-1])
        {
            if(dancers[i]==2)
            {
                if(dancers[n-i-1]==0)
                    rs+=a;
                else
                    rs+=b;
            }
            else
            {
                if(dancers[i]==0)
                    rs+=a;
                else
                    rs+=b;

            }
        }
    }
    if(dancers[n/2]==2 && n%2!=0)
        rs+=(a>b)?b:a;
    cout<<rs;
    return 0;
}

#include<iostream>
using namespace std;

int main()
{
  int count=0,ans=1;
  int a,b,n;
  cin >> n >> a >> b;
  int l[n];

  for(int x;x<n;x++)
    cin >> l[x];

  for(int y;y<n;y++)
  {
    if (l[y]==l[n-y-1])
    {
      if (l[y]==2)
      {
        if (a>b)
        {
          l[y] == 1;
          count+= b;
        }
        else
        {
          l[y] == 0;
          count+= a;
        }
      }
    }
    else
    {
      if(l[y]==2 && l[n-y-1]==2)
      {
        if (a>b)
        {
          l[y] = 1;
          l[n-y-1] = 1;
          count+= 2*b;
        }
        else
        {
          l[y] == 0;
          l[n-y-1] == 0;
          count+= 2*a;
        }
      }
      else if(l[y] == 2)
      {
        l[y] = l[n-y-1];
        if (l[y] == 0)
          count += a;
        else
          count += b;
      }
      else if(l[n-y-1] == 2)
      {
        l[n-y-1] = l[y];
        if (l[y] == 0)
          count += a;
        else
          count += b;
      }
      else
        ans = 0;
    }
  }
  if (ans == 0)
    cout << -1;
  else
    cout << count;
}

#include<bits/stdc++.h>
#include<vector>
#include<map>
typedef long long int ll;
typedef unsigned long long int ull;
#define boost ios_base ::sync_with_stdio(0); cin.tie(0);
#define m_p make_pair
#define mod 1000000007
#define ma(m,n) max(m,n)
#define mi(m,n) min(m,n)
#define g1(n) cin>>n
#define g2(n,m) cin>>n>>m
#define o1(n) cout<<n
#define o2(n,m) cout<<n<<m
#define pi 3.14159265358979323846
#define mp make_pair
#define ff first
#define ss second
#define sol(i,a,b) for(ll i=a;i<b;i++)
#define rsol(i,a) for(ll i=a;i>=0;i--)
#define EPSILON 1e-9
#define len(s) s.length()
#define sp cout<<endl
#define pb push_back
using namespace std;

int main()
{
    ll n,a,b;cin>>n>>a>>b;
    ll d[n],ans=0;
    sol(i,0,n) cin>>d[i];
    if(n==1) {
        if(d[0]==2) cout<<min(a,b);
        else cout<<0;
        return 0;
    }
    sol(i,0,n/2){
       // cout<<i<<" "<<n-i-1<<endl;
        if(d[i]==0){
            if(d[n-i-1]==2) ans+=a;
            else if(d[n-i-1]==1) {
                cout<<-1;
                return 0;
            }
        }
        else if(d[i]==1){
            if(d[n-i-1]==2) ans+=b;
            else if(d[n-i-1]==0) {
                cout<<-1;
                return 0;
            }
        }
         else if(d[i]==2){
            if(d[n-i-1]==0) ans+=a;
            else if(d[n-i-1]==1) ans+=b;
            else if(d[n-i-1]==2) ans+=2*min(a,b);
        }
       // cout<<ans<<endl;
    }
    if(n%2==0) cout<<ans;
    else {
        if(d[n/2]==2) cout<<ans+min(a,b);
        else cout<<ans;
    }
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

int main(){

    fastio
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif

    ll N,A,B;cin>>N>>A>>B;
    vector<ll> v;
    for(ll i=0;i<N;i++) {
        ll x;cin>>x;v.pb(x);
    }
    ll start = 0,end = N-1;
    ll cost=0;
    while(start<=end){
        if(v[start]!=2 && v[end]==2) {
            v[end] = v[start];
            if(v[start]==0) cost+=A;
            else if(v[start] == 1) cost+=B;
        }
        else if(v[end]!=2 && v[start]==2) {
            v[start] = v[end];
            if(v[end]==0) cost+=A;
            else if(v[end] == 1) cost+=B;
        }
        else if(v[start] == 2 && v[end] == 2){
            if(start == end){
                if(A<B)  {v[start] = 0;v[end] = 0;cost+=A;}
                else if(B<A) {v[start] = 1;v[end] = 1;cost+=B;}
                else if(A==B) {v[start] = 0;v[end] = 0;cost+=A;}
            }
            else{
                if(A<B)  {v[start] = 0;v[end] = 0;cost+=A+A;}
                else if(B<A) {v[start] = 1;v[end] = 1;cost+=B+B;}
                else if(A==B) {v[start] = 0;v[end] = 0;cost+=A+A;}
            }
        }
        start++;end--;
    }
    //cout<<start<<" "<<end<<"\n";
    start = 0;end = N-1;
    bool flag = true;
    while(start<end){
        if(v[start]!=v[end]){
            flag = false;
            break;
        }
        start++;end--;
    }
    //for(ll i=0;i<N;i++) cout<<v[i]<<" ";
    if(flag) cout<<cost<<"\n";
    else cout<<"-1\n";
    return 0;
}
/* NOTHING IS IMPOSSIBLE*/

#include<iostream>
//
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
int n,a,b,ans;
int c[21];
int main()
{
	scanf("%d%d%d",&n,&a,&b);
	for(int i=1;i<=n;i++)
		scanf("%d",&c[i]);
	for(int i=1;i<=(n&1?(n-1)/2:n/2);i++)
	{
		int to=n+1-i;
		//printf("i=%d to=%d\n",i,to);
		if(c[i]==2)
		{
			if(c[to]==1)
				ans+=b;
			else if(c[to]==0)
			    ans+=a;
			else if(c[to]==2)
	            ans+=2*min(a,b);
		}
		else if(c[i]==1)
		{
			if(c[to]==2)
			    ans+=b;
			else if(c[to]==1) continue;
			else if(c[to]==0)
			{
				cout<<-1<<endl;
				return 0;
			}
		}
		else if(c[i]==0)
		{
			if(c[to]==0) continue;
			else if(c[to]==1)
			{
				cout<<-1<<endl;
				return 0;
			}
			else if(c[to]==2)
			    ans+=a;
		}
	}
	if((n%2==1)&&c[(n+1)/2]==2) ans+=min(a,b);
	cout<<ans<<endl;
	return 0;
}

////██╗ ██████╗ ██╗    ██████╗  ██████╗  ██╗ █████╗
////██║██╔═══██╗██║    ╚════██╗██╔═████╗███║██╔══██╗
////██║██║   ██║██║     █████╔╝██║██╔██║╚██║╚██████║
////██║██║   ██║██║    ██╔═══╝ ████╔╝██║ ██║ ╚═══██║
////██║╚██████╔╝██║    ███████╗╚██████╔╝ ██║ █████╔╝
////╚═╝ ╚═════╝ ╚═╝    ╚══════╝ ╚═════╝  ╚═╝ ╚════╝

#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define pb push_back
#define pf push_front
#define fr first
#define sc second
#define mlojins cout.tie(NULL);
#define bzbz cin.tie(NULL);
#define CODER ios_base::sync_with_stdio(0)  ;
#define p_b pop_back
#define p_f pop_front
#define Qulukh
#define Mekh
#define Zohiri_dzd
#define Black_star
using namespace std ;

const ll N = 1e6 + 1;

map <ll , ll> mp , pm ;
deque <ll> v , vc , ve ;
deque <ll> p , pe ;
deque <string> ts , ss ;
deque <float> sd ;
ll a , b , c , d , e , f , cnt , ans , r , n , l;
double q , t , cnt1;
string g , h , w , o , z , m , s ;
char y , u ;
bool re , rt ;
set < ll > st ;
vector<pair < ll , ll > > pr , rp;
int main ()

{
    bzbz
    mlojins
    CODER
    Qulukh
    Mekh
    Zohiri_dzd
    Black_star
    /*freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);*/
    cin >> a >> b >> c ;
    for (int i = 0 ; i < a ; i ++ )
    {
        cin >> d ;
        v.pb(d) ;
        mp[d] ++ ;
    }

    for (int i = 0 ; i < a / 2 ; i ++ )
    {
        if ((v[i] == 1 and v[a - i - 1] == 2) or (v[i] == 2 and v[a - i - 1] == 1))
            ans += c , v[i] = 1 , v[a - i - 1] = 1 ;
        else if ((v[i] == 0 and v[a - i - 1] == 2) or (v[i] == 2 and v[a - i - 1] == 0))
            ans += b , v[i] = 0 , v[a - i - 1] = 0 ;
        else if (v[i] == 2 and v[a - i - 1] == 2)
            ans += min(b , c) * 2 , v[i] = 3 , v[a - i - 1] = 3 ;
        else if (v[i] != v[a - i - 1])
        {
            cout << -1 ;
            return 0 ;
        }
    }
    if (v[a / 2] == 2 and a % 2 != 0)
        ans += min(b , c) ;
    cout << ans ;
}
///Mmavl studios
///Eco students
///7c is the best

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

int func(int n, int a, int b, vector <int> s) {

	vector <int> ind;
	int sum = 0;

	if (n < 1 || n> 20 || !n || a < 1 || a>100 || b < 1 || b>100 || !a || !b)
		return -1;

	// mid elemnet
	if (n % 2 != 0) {
		if (s[n / 2] == 2) {
			sum += min(a, b);
		}
	}

	for (int i = 0; i < n / 2; i++) {
		if (s[i] != s[n - i - 1]) {
			if (s[i] == 2 && s[n - i - 1] == 0)
				sum += a;
			else if (s[i] == 2 && s[n - i - 1] == 1)
				sum += b;
			else if (s[n - i - 1] == 2 && s[i] == 0)
				sum += a;
			else if (s[n - i - 1] == 2 && s[i] == 1)
				sum += b;
			else
				return -1;
		}

		else if (s[i] == 2) {
			sum += 2*min(a, b);
		}
	}

	return sum;
}

int main()
{
	int n, a, b;
	cin >> n >> a >> b;
	vector<int> vec;
	for (int i = 0; i < n; i++)
	{
		int tmp;
		cin >> tmp;
		vec.push_back(tmp);
	}
	cout << func(n, a, b, vec);
}

#include <stdio.h>
int judge(int input[], int n);
int main()
{
	int n, a, b, i, money;
	int input[21];
	scanf("%d%d%d", &n, &a, &b);
	money = 0;
	for (i = 0; i < n; i++)
	{
		scanf("%d", &input[i]);
	}
	for (i = 0; i < n; i++)
	{
		if (input[i] == 2)
		{
			input[i] = input[n - i - 1];
			if (input[i] == 2)
			{
				if (a <= b)
					input[i] = 0;
				else
					input[i] = 1;
			}
			if (input[i] == 0)
				money += a;
			else
				money += b;
		}
	}
	if (judge(input,n) == 1)
		printf("%d\n", money);
	else
		printf("-1\n");
	return 0;
}
int judge(int input[], int n)
{
	int temp[20];
	int i, result;
	for (i = 0; i < n; i++)
	{
		temp[i] = input[n - 1 - i];
	}
	for (i = 0; i < n; i++)
	{
		if (input[i] != temp[i])
			break;
	}
	if (i < n)
		result = 0;
	else
		result = 1;
	return result;
}

#ifdef WIN32
#include "..\\stdc++.h"
#else
#include <bits/stdc++.h>
#endif

typedef long long ll;

using namespace std;

int main() {
#ifdef WIN32
	ifstream in("in.txt");
	streambuf *cinbuf = cin.rdbuf();
	cin.rdbuf(in.rdbuf());
#endif
	ll middel = -1;
	ll c, wp, bp;

	cin >> c >> wp >> bp;
	ll ins;
	vector<ll> mms;
	ll result = 0;
	for (ll i = 0; i < c; ++i) {
		cin >> ins;
		mms.push_back(ins);
	}

	for (ll i = 0; i < c/2; ++i) {
		if (mms[c - 1 - i] == mms[i]) {
			if (mms[i] == 2) {
				result += min(wp,bp)*2;
			}
		}
		if (min(mms[c - 1 - i], mms[i]) == 0 && max(mms[c - 1 - i], mms[i]) == 2) {
			result += wp;
		}
		if (min(mms[c - 1 - i], mms[i]) == 1 && max(mms[c - 1 - i], mms[i]) == 2) {
			result += bp;
		}
		if (min(mms[c - 1 - i], mms[i]) == 0 && max(mms[c - 1 - i], mms[i]) == 1) {
			cout << -1;
			return 0;
		}
	}

	if (c%2 == 1 && mms[c/2] == 2) {
		result += min(wp, bp);
	}

	cout << result;
	return 0;
}

#include<bits/stdc++.h>
#define ll long long
#define ios ios_base::sync_with_stdio(false)
#define pii pair<int, int>
#define fs first
#define sc second

using namespace std;

const ll INF=(1ll<<62)-1;
const int inf=(1<<30)-1;

int ar[100],br[100];
int tot;

    int main()
    {
        ios;
        int n,cw,cb;
        cin>>n>>cw>>cb;

        int mn=min(cw,cb);

        for(int i=0;i<n;i++)
        {
            cin>>ar[i];
            br[i]=ar[i];
        }

        if(n==2)
        {
            if(ar[0]==2 && ar[1]==2)
            {
                cout<<2*mn<<endl;
                return 0;
            }
        }
     /*   sort(br,br+n);
        if(ar[0]==ar[n-1] && ar[0]==2)
        {
            cout<<n*mn<<endl;
            return 0;
        }*/

        //cout<<tot<<endl;
        for(int i=0;i<n/2;i++)
        {

            if(ar[i] != ar[n-i-1] || (ar[i]==2 && ar[n-i-1]==2))
            {
                if(ar[i]==2 && ar[n-i-1]==2){
                    tot+=2*mn;
                }
                else if(ar[i]==2 || ar[n-i-1]==2)
                {

                    if(ar[i]==0 || ar[n-i-1]==0)tot+=cw;
                    else if(ar[i]==1 || ar[n-i-1]==1)tot+=cb;

                }
                else{
                    cout<<-1<<endl;
                    return 0;
                }
            }
        }

        if(n%2==1 && ar[n/2]== 2)cout<<tot+min(cw,cb)<<endl;
        else cout<<tot<<endl;

        return 0;
    }

#include <iostream>
#include <algorithm>
#include <string>
using namespace std ;

int main(){
	int n,a,b ;
	int cost  = 0 ;
	cin>>n>>a>>b ;
	int input[20] ;
	for(int i=0 ; i<n   ; i++) cin>>input[i] ;
	for(int i=0 ; i<n/2 ; i++){
		//2,2
		if(input[i]==2 && input[n-i-1]==2){
			cost += 2*min(a,b) ;
		}
		else{
			if(input[i]==2 || input[n-i-1]==2){
				int temp = min(input[i],input[n-i-1]) ;
				if(temp==0) cost += a;
				else{
					cost += b ;
				}
			}
			else{
				if(input[i]!=input[n-i-1]){
					cout<<-1<<endl ;
					return 0 ;
				}
			}
		}
	}
	if(n%2!=0){
		if(input[n/2]==2){
			cost += min(a,b) ;
		}
	}
	cout<<cost<<endl ;
	return 0 ;
}

// pr1040a.cpp : Defines the entry point for the console application.
//

#include <iostream>;

int numDancers, white, black;
int initialArray[25];

int minCost(){
	int cost = 0;

	int lower = black;

	if (white < black) {
		lower = white;
	}

	bool possible = true;

	for (int i = 0; i < numDancers; i++){
		if (initialArray[i] + initialArray[numDancers - 1 - i] == 1)
		{
			possible = false; break;
		}
		else {
			if (initialArray[i] == 2)
			{
				switch (initialArray[numDancers - 1 - i]){
				case 0: cost = cost + white; break;
				case 1: cost = cost + black; break;
				case 2: cost = cost + lower;
				}
			}
		}
		//std::cout << cost << "\n";
	}

	if (possible) {
		return cost;
	}
	else
	{
		return -1;
	}
}

int main(int argc)
{
	// std::cout << "test";
		std::cin >> numDancers >> white >> black;
		for (int i = 0; i < numDancers; i++){
			std::cin >> initialArray[i];
		}

		std::cout << minCost() << "\n";
		//for (int i = 0; i < numDancers; i++){
		//	std::cout << white + initialArray[i] << " ";
		//}
	return 0;

}

#include <iostream>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <utility>
#include <string>

using namespace std;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n,a,b;
  cin>>n>>a>>b;
  int c[n];
  for (int i=0; i<n; i++) {cin>>c[i];}

  int p=0, m=min(a,b), v[3]={a,b,2*m};
  for (int i=0; i<n/2; i++){
    int l=c[i], r=c[n-i-1];
    if (l==2 || r==2) {p+=v[min(l,r)];}
    else if (l!=r) {p=-1; break;}
  }
  if (p!=-1 && n%2==1 && c[n/2]==2) {p+=m;}
  cout << p << '\n';
  return 0;
}

#include <bits/stdc++.h>
using namespace std;
const int MAXN = 20;
int n, a, b, arr[MAXN + 5], ans;

int main() {
    cin >> n >> a >> b;
    for(int i = 0; i < n; i++)
        cin >> arr[i];
    for(int i = 0; i <= n/2 - 1; i++)
    {
        if(arr[i]==arr[n-i-1] && arr[i]==2)
            ans+= 2*min(a, b);
        else if(arr[i]!=arr[n-i-1] && (arr[i]==2 || arr[n-i-1]==2))
        {
            if(arr[i]==0 || arr[n-i-1]==0) ans+= a;
            else ans+= b;
        }
        else if(arr[i]!=arr[n-i-1])
        {
            cout << -1 << endl;
            return 0;
        }
    }
    if(n%2 && arr[n/2]==2) ans+= min(a,b);
    cout << ans << endl;
    return 0;
}

#include <bits/stdc++.h>

// #define DEBUG

#define maxN
#define eps 1e-8
#define base
#define ii pair<int,int>
#define iii pair<int,ii>
#define fi first
#define se second
#define ll long long
#define pb push_back
#define mp make_pair
#define LL(x) (x << 1)
#define RR(x) ((x << 1) + 1)
#define sqr(x) ((x) * (x))
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

using namespace std;
int res=0,a[25],n,x,y,b[3];

int main()
{
    IOS;
    cin >> n >> b[0] >> b[1];
    for (int i=1; i<=n; i++) cin >> a[i];
    for (int i=1; i<=(n+1)/2; i++)
    {
        if (a[i]!=a[n-i+1] && a[i]!=2 && a[n-i+1]!=2)
        {
            cout<<-1; return 0;
        }
        if (a[i]==a[n-i+1])
        {
            if (a[i]!=2) continue;
            if (n-i+1==i) res+=min(b[0],b[1]);
            else res+=2*min(b[0],b[1]);
        }
        else if (a[i]==2) res+=b[a[n-i+1]];
        else res+=b[a[i]];
    }
    cout<<res;
    return 0;
}

#include <iostream>
using namespace std;
int main() {
	int n, wcost, bcost, *dancer, cost = 0;
	cin >> n >> wcost >> bcost;
	dancer = new int[n];
	for (int i = 0; i < n; i++)
		cin >> dancer[i];
	for (int i = 0,j = n-1; i <= j; i++,j--)
		if (i == j)
		{
			if (dancer[i] == 2)
				if (bcost < wcost)
				{
					cost += bcost;
				}
				else {
					cost += wcost;
				}
			break;
		}
		else {
			if (dancer[i] != dancer[j])
			{
				if (dancer[i] == 2 || dancer[j] == 2)
				{
					switch (dancer[i] + dancer[j])
					{
					case 2:
						cost += wcost;
						break;
					case 3:
						cost += bcost;
						break;
					}
				}
				else {
					cout << -1 << endl;
					return 0;
				}
			}
			else if(dancer[i] == 2) {
				if (bcost < wcost)
				{
					cost += 2 * bcost;
				}
				else
				{
					cost += 2 * wcost;
				}
			}

		}
	cout << cost << endl;
	delete dancer;
	return 0;
}

#include<iostream>
#include<vector>
using namespace std;

int main(){
	int n;
	cin >> n;
	vector<int> data = vector<int>(n + 2);
	cin >> data[0] >> data[1];
	int left, right;
	int sum = 0;
	left = n / 2+1;
	for (int i = 2; i < n + 2; i++)
		cin >> data[i];
	if (n % 2 == 0){
		right = left + 1;
	}
	else{
		right = left + 2;
		if (data[n / 2 + 2] == 2)
			sum += data[0] < data[1] ? data[0] : data[1];
	}
	while (left > 1){
		if (data[left]==data[right]&&data[left]==2)
			sum += (data[0]< data[1] ? data[0] : data[1])*2;
		else if (data[left] != data[right] && data[left] != 2 && data[right] != 2){
			sum = -1;
			break;
		}
		else if (data[left] != data[right] && data[left] == 2)
			sum += data[data[right]];
		else if (data[left] != data[right] && data[right] == 2)
			sum += data[data[left]];
		left--;
		right++;
	}
	cout << sum << endl;
	return 0;
}

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

int main(){
    int n, c, b;
    cin >> n >> c >> b;
    int a[n];
    for(int i = 0; i < n; i++)
        cin >> a[i];
    int ans = 0;
    if(n%2 != 0 && a[n/2] == 2)
        ans += min(c, b);
    for(int i = 0; i < n/2; i++){
        if(a[i] == 2 || a[n -i - 1] == 2){
            if(a[i] == 2 && a[n - i -1] == 2)
                ans += 2 * min(c, b);
            else{
                if(a[i] == 0 || a[n -i - 1] == 0)
                    ans += c;
                else
                    ans += b;
            }
        }
        else{
            if(a[n - i -1] != a[i]){
                cout << "-1\n";
                return 0;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,a,b,i,ad;
    int rs=0;
    cin>>n>>a>>b;
    // dancer white black
    int dancers[n];
    for(i=0;i<n;i++)
        cin>>dancers[i];
    for(i=0;i<n/2;i++)
    {
//            cout<<dancers[i]<<" "<<dancers[n-i-1]<<endl;
        if(dancers[i]!=dancers[n-i-1] && dancers[i]!=2 && dancers[n-1-i]!=2)
        {
            cout<<-1;
            return 0;
        }
        if(dancers[i]==dancers[n-i-1] && dancers[i]==2)
        {
            ad=(a>b)?b:a;
            rs=rs+2*ad;
        }
        else if(dancers[i]!=dancers[n-i-1])
        {
            if(dancers[i]==2)
            {
                if(dancers[n-i-1]==0)
                    rs+=a;
                else
                    rs+=b;
            }
            else
            {
                if(dancers[i]==0)
                    rs+=a;
                else
                    rs+=b;

            }
        }
    }
    if(dancers[n/2]==2 && n%2!=0)
        rs+=(a>b)?b:a;
    cout<<rs;
    return 0;
}

#include <bits/stdc++.h>

namespace mk{namespace ds{ // range, matrix, tensor
#ifndef _MK_DS_RANGE_
#define _MK_DS_RANGE_
template<class T,class Alloc=std::allocator<T>>class range:public std::vector<T,
Alloc>{typedef std::vector<T,Alloc> base;typedef int range_type;typedef typename
base::size_type size_type;typedef typename base::value_type value_type;typedef
value_type& reference;range_type _first;public:range():base(),_first(0){}range(
range_type first,range_type last):base(last-first),_first(first){}range(
size_type n):base(n),_first(0){}range(std::initializer_list<T> il,range_type
first=0):base(il),_first(first){}reference operator[](range_type i){return base
::operator[](i-_first);}reference at(range_type i){return base::at(i - _first);}
void rearrange(range_type first,range_type last){this->_first=first;base::resize
(last-first);}void set_first(range_type first){this->_first=first;}range_type
first(){return _first;}range_type last(){return _first+(range_type)base::size();
}};
#endif
#ifndef _MK_DS_MATRIX_
#define _MK_DS_MATRIX_
template<class T,class Alloc=std::allocator<T>>class matrix:public std::vector<
std::vector<T,Alloc>,Alloc>{typedef std::vector<T,Alloc> vec1d;typedef std::
vector<vec1d,Alloc> vec2d;typedef typename vec1d::size_type size_type;public:
matrix()=default;matrix(size_type rows,size_type cols):vec2d(rows,vec1d(cols)){}
matrix(size_type n):vec2d(n,vec1d(n)){}void resize(size_type rows,size_type cols
){vec2d::resize(rows);for(vec1d& row:*this){row.resize(cols);}}size_type rows(){
return (*this).size();}size_type cols(){return (*this).at(0).size();}};
#endif
#ifndef _MK_DS_TENSOR_
#define _MK_DS_TENSOR_
template<class T,class Alloc=std::allocator<T>>class tensor:public std::vector<
std::vector<std::vector<T,Alloc>,Alloc>,Alloc>{typedef std::vector<T,Alloc>
vec1d;typedef std::vector<vec1d,Alloc> vec2d;typedef std::vector<vec2d,Alloc>
vec3d;typedef typename vec1d::size_type size_type;public:tensor()=default;tensor
(size_type layers,size_type rows,size_type cols):vec3d(layers,vec2d(rows,vec1d(
cols))){}tensor(size_type n):vec3d(n,vec2d(n,vec1d(n))){}void resize(size_type
layers,size_type rows,size_type cols){vec3d::resize(layers);for(vec2d& layer:*
this){layer.resize(rows);for(vec1d& row:layer){row.resize(cols);}}}size_type
layers(){return (*this).size();}size_type rows(){return (*this).at(0).size();}
size_type cols(){return (*this).at(0).at(0).size();}};
#endif
} }

#ifndef _MK_GRAPH_
#define _MK_GRAPH_

#include <vector> // std::vector
#include <utility> // std::pair
#include <queue> // std::priority_queue
#include <functional> // std::greater
#include <limits> // std::numeric_limits

// All containers can be used in directed or undirected graphs
typedef int Vertex; // change when needed
typedef long Weight; // change when needed

typedef std::pair<Weight, Vertex> WV;
typedef std::pair<Vertex, Vertex> Edge;
typedef std::pair<Weight, Edge> WEdge;

typedef std::vector<std::vector<long>> AdjMatrix;
// AdjMatrix adjmat(n, vector<long>(n));
typedef std::vector<std::vector<Vertex>> AdjList;
typedef std::vector<std::vector<WV>> WAdjList;
typedef std::vector<Edge> EdgeList;
typedef std::vector<WEdge> WEdgeList;

typedef std::priority_queue<WV>
MaxWVPQ; // Maximum has a higher priority
typedef std::priority_queue<WV, std::vector<WV>, std::greater<WV>>
MinWVPQ; // Minimum has a higher priority

const Weight INF_WEIGHT = std::numeric_limits<Weight>::max() / 3; // !overflow
const Vertex INF_VERTEX = std::numeric_limits<Vertex>::max(); // no ocerflow

#endif

#define rep(i, a, comp, b) for(auto i = a; i comp b; ++i)
#define per(i, a, comp, b) for(auto i = a; i comp b; --i)
#define loop(i, a, comp, b, op) for(auto i = a; i comp b; i op)
#define sz(x) ((int)sizeof(x))
#define MAXIN 200010
#define MOD 1000000007
#define INF 2000000000
#define pb push_back
#define eb emplace_back
using ll  = long long;
using ull = unsigned long long;
using ii  = std::pair<int, int>;
using namespace std;

int n, wcost, bcost;
int a[25];

int main()
{
    cin >> n >> wcost >> bcost;
    rep(i, 0, <, n) cin >> a[i];

    bool poss = true;
    int ans = 0;
    for(int i = 0, j = n-1; ; i++, j--) {
        // cout << "darar " << i << " " << j << endl;
        if(i > j) {
            break;
        }
        if (i == j) {
            if(a[i] > 1) ans += min(wcost, bcost);
            break;
        }
        if(a[i] > 1 && a[j] > 1) {
            ans += 2*min(wcost, bcost);
            continue;
        }

        if(a[i] != a[j]) {

            if(a[i] <=1 and a[j] <=1) {
                poss = false;
                break;
            } else {
                int aaa;
                if(a[i] <= 1) aaa = a[i];
                else aaa = a[j];
                if(aaa == 0) ans += wcost;
                else ans += bcost;
            }

        }
    }
    if(poss)
        cout << ans << endl;
    else
        cout << -1 << endl;
}

#include <iostream>
#include<string>
#include<vector>
#include<set>
#include<algorithm>
#include<stack>
#include<map>
#include <iomanip>
#include <cmath>
#include <fstream>
#include <ctime>

using namespace std;

int main()
{
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	ios_base :: sync_with_stdio(0);
	cin.tie(0);

	int n, a, b;
	cin >> n >> a >> b;

	//0 - white, 1 - black, 2 - none

	vector<int> d(n);
	for(int i = 0; i < n; i++)
		cin >> d[i];

	int ans = 0;
	int i = 0, j = n - 1;
	while(i <= j)
	{
		if(d[i] == 2 && d[j] == 2)
		{
			if(i != j)
				ans += min(a, b) * 2;
			else
				ans += min(a, b);
		}
		else
			if((d[i] == 1 && d[j] == 2) || (d[i] == 2 && d[j] == 1))
				ans += b;
			else
				if((d[i] == 0 && d[j] == 2) || (d[i] == 2 && d[j] == 0))
					ans += a;
				else
					if(d[i] != d[j])
					{
						cout << -1 << endl;
						return 0;
					}
		i++, j--;
	}

	cout << ans << endl;
}

#include<iostream>
using namespace std;
int n,a,b,c[21],t=0,mmin=10000;
bool palindrome()
{
	int i;
	for(i=1;i<=n/2;i++)
		if(c[i]!=c[n-i+1])
			return 0;
	return 1;
}
void dfs(int now)
{
	if(now==n+1)
	{
		if(palindrome())
			if(t<mmin)
				mmin=t;
		return;
	}
	if(c[now]!=2)
	{
		dfs(now+1);
		return;
	}
	t+=a;
	c[now]=0;
	dfs(now+1);
	t-=a;
	t+=b;
	c[now]=1;
	dfs(now+1);
	t-=b;
	c[now]=2;
}
int main()
{
	int i;
	cin>>n>>a>>b;
	for(i=1;i<=n;i++)
		cin>>c[i];
	dfs(1);
	if(mmin==10000)
		cout<<-1;
	else
		cout<<mmin;
	return 0;
}

#include <bits/stdc++.h>

#define vec vector< long long int>
#define vecp vector < pair< long long int ,long long int> >
#define pb push_back
#define f(i,a,b) for(long long int i=a;i<b;i++)
#define tc long long int t; cin>>t; while(t--)
#define mp make_pair
#define map map <long long int, long long int>
using namespace std;
typedef long long int ll;
void SieveOfEratosthenes(int n,bool prime[])
{
    memset(prime, true, n);
    for (int p=2; p*p<=n; p++)
    {
       if (prime[p] == true)
        {
            for (int i=p*2; i<=n; i += p)
                prime[i] = false;
        }
    }
 }

int main()
{
    ll n,a,b;
    cin>>n>>a>>b;
    ll arr[n+1];
    f(i,0,n)
    cin>>arr[i];
    ll min;

    ll ans=0;
    if(a<b)
        min=a;
    else
        min=b;
    ll start=0;
    ll end=n-1;
    while(start<end)
    {

        if(arr[start]==arr[end])
        {
            if(arr[start]==2 )
                ans+=2*min;
        }
        else
        {
            if(arr[start]==2)
            {
                if(arr[end]==0)
                    ans+=a;
                else
                    ans+=b;
            }
            else if(arr[end]==2)
            {
                if(arr[start]==0)
                    ans+=a;
                else
                    ans+=b;
            }
            else
            {
                cout<<-1;
                return 0;
            }
        }
        start++;
        end--;

    }
    if(n%2!=0)
    {
        if(arr[start]==2)
            ans+=min;
    }

    cout<<ans;

}

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
using namespace std;
#define Min(a,b) ((a<b)?a:b)
const int N=50;
int n,a[N],b[2];
int main(){
	int i,j;
	scanf("%d%d%d",&n,&b[0],&b[1]);
	for (i=1;i<=n;++i) scanf("%d",&a[i]);
	int cst=0;
	if (n&1) {if (a[n/2+1]==2) cst+=Min(b[0],b[1]);}
	for (i=1;i<=(n/2);++i){
		if ((a[i]!=2)&&(a[n-i+1]!=2)&&(a[i]!=a[n-i+1])) {puts("-1");return 0;}
		if (a[i]==a[n-i+1])
			if (a[i]!=2) continue;
			else cst+=2*Min(b[0],b[1]);
		if (a[i]==2) cst+=b[a[n-i+1]];else cst+=b[a[i]];
	}
	printf("%d\n",cst);
	return 0;
}

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

int A[300], n, a, b;

int main(int argc, char const *argv[])
{
	cin >> n >> a >> b;

	for(int i = 0;i < n;i++)
		cin >> A[i];

	int ans = 0;
	int k;
	if(n % 2 == 0)
		k = (n/2)-1;
	else
		k = n/2;
	for(int i = 0;i <= k;i++){
		if(n % 2 != 0){
			if(i == n/2){
				if(A[i] == 2){
					//cerr << "here\n";
					ans += min(a, b);
					continue;
				}
				else
					continue;
			}
		}
		if(A[i] == A[n-i-1]){
			if(A[i] == 2){
				//cerr << "1 " << i << endl;
				ans += 2*min(a, b);
			}
		}
		else{
			if(A[i] == 2){
				//cerr << "2\n";
				if(A[n-i-1] == 1) ans += b;
				else ans += a;
			}

			else if(A[n-i-1] == 2){
				//cerr << "3\n";
				if(A[i] == 1) ans += b;
				else ans += a;
			}

			else{
				printf("-1\n");
				return 0;
			}
		}
	}
	printf("%d\n", ans);
	// /system("pause");
	return 0;
}

#include <iostream>
#include <vector>
#include <conio.h>
#include <algorithm>

using namespace std;

int main()
{
	short amount;
	cin >> amount;

	short white;
	cin >> white;

	short black;
	cin >> black;

	vector<short> vec(amount);
	for (short i = 0; i < amount; i++) {
		cin >> vec[i];
	}

	int res = 0;
	for (short i = 0; i < (vec.size() / 2); i++) {

		if (vec[i] != 2 && vec[vec.size() - i - 1] != 2) {
			if (vec[i] != vec[vec.size() - i - 1]) {
				cout << "-1";
				return 0;
			}

			if (vec[i] == vec[vec.size() - i - 1])
				continue;
		}

		if (vec[i] == 2) {
			if (vec[vec.size() - i - 1] == 2) {
				res += min(white, black) * 2;
			}
			else {
				res += (vec[vec.size() - i - 1] == 0 ? white : black);
			}

		}
		else {
			res += (vec[i] == 0 ? white : black);
		}
	}

	if (vec.size() % 2 == 1) {
		if (vec[vec.size() / 2] == 2) {
			res += min(white, black);
		}
	}

	cout << res;

	return 0;
}

#include <iostream>

using namespace std;

int n,a,b;
int c[25];

void doit(){
	cin>>n>>a>>b;
	for(int i=0;i<n;i++)
		cin>>c[i];
	bool abl = true;
	long long cost =0;
	for(int i=0;i<n/2;i++){
		if(c[i] == 2 and c[n-i-1]==2)
			cost+=2*min(a,b);
		if(c[i]!=c[n-i-1]){
			if(c[i]!= 2 and c[n-1-i]!=2)
				abl = false;
			else{
				if(c[i]!= 2){
					if(c[i]==0)
						cost+=a;
					else
						cost+=b;
				}
				if(c[n-1-i]!=2){
					if(c[n-1-i]==0)
						cost+=a;
					else
						cost+=b;
				}
			}

		}
	}
	if(n%2)
		if(c[(n+1)/2-1]==2)
			cost+=min(a,b);
	if(!abl)
		cout<<-1<<endl;
	else
		cout<<cost<<endl;
	return;
}

int main(){
	doit();
	return 0;
}

#include<iostream>
#include<set>
using namespace std;
int main()
{
    int n,a,b,s=0,c;
    cin>>n>>a>>b;
    int ar[n];
    for(int i=0;i<n;i++)
    {
        cin>>ar[i];
    }
    int k=(n+1)/2;
     c=min(a,b);
    for(int i=0;i<k;i++)
    {
        if(ar[i]==2 && ar[n-1-i]==2)
        {
            if(i==(n-1-i))
            s+=c;
            else
                s+=2*c;
        }
        else
        {
            if(ar[i]!=ar[n-1-i])
            {
               if(ar[i]!=2 && ar[n-1-i]!=2)
               {
                   cout<<-1;
                   return 0;
               }
                else
                {
                    if(ar[i]==0 || ar[n-1-i]==0)
                        s+=a;
                    else
                        s+=b;
                }

            }
        }

    }
    cout<<s;
    return 0;

}

#include<iostream>
#include<vector>
using namespace std;
int ispal(int a,int b)
{
    if(a%2==0)
    {
        return 1;
    }
    if(b%2==0)
    {
        return 1;
    }
    return 0;
}
int main()
{
    int n;
    cin>>n;
    int a,b;cin>>a>>b;
    int numw=0;
    int numb=0;
    vector<int> temp(n);
    for(int i=0;i<n;i++)
    {
        int x;
        cin>>x;
        temp[i]=x;
        if(x==1)
        {
            numw++;
        }
        else
        {
            if(x==0)
            {
            numb++;
            }
        }
    }
    int ans=0;
    for(int i=0;i<=n-i-1;i++)
    {
        int x1=temp[i];
        int x2=temp[n-i-1];
        if(x1!=x2&&x1!=2&&x2!=2)
        {
            cout<<"-1";return 0;
        }
        else
        {
            if(x1!=x2)
            {
                if(x1==2)
                {
                    if(x2==1)
                    {
                        ans=ans+b;
                    }
                    else
                    {
                        ans=ans+a;
                    }
                }
                else
                {
                    if(x2==2)
                    {
                        if(x1==1)
                        {
                            ans=ans+b;
                        }
                        else
                        {
                            ans=ans+a;
                        }
                    }
                }
            }
            else
            {
                if(x1==2&&x2==2&&i!=n-i-1)
                {
                ans=ans+2*min(a,b);
                }
                else
                {
                    if(x1==2&&x2==2&&i==n-i-1)
                    {
                        ans=ans+min(a,b);
                    }
                }
            }
        }
    }
    cout<<ans;
}

/* Yuanjie Duane Ding (c) 2018
 * any codes cannot be used for business
 * 2018�ļ���ѵ��
 * Templates for Codeforces special
*/

#include <bits/stdc++.h>

#define NAME "1040A"

using namespace std;

int N, A, B;
int av[30], bv[30];

void readin() {
	scanf("%d%d%d", &N, &A, &B);
	for(int i = 1; i <= N; ++i) {
		scanf("%d", av+i);
		if(av[i] == 2) {
			bv[i] = 1;
		}
	}
}

void process() {
	int flag = 0, tot = 0, minp;
	for(int i = 1; i*2 <= N; ++i) {
		if(av[i] != 2 && av[N+1-i] != 2 && av[i] != av[N+1-i]) {
			flag = 1;
			break;
		}
	}
	if(flag == 1) {
		printf("-1\n");
		return;
	}
	if(A < B) {
		minp = 0;
	} else {
		minp = 1;
	}
	for(int i = 1; i <= N; ++i) {
		int &now = av[i], &nxt = av[N+1-i];
		if(now == 2) {
			if(nxt != 2) {
				now = nxt;
			} else {
				now = minp;
			}
		}
		if(av[i] == 0) {
			tot += A*bv[i];
		} else {
			tot += B*bv[i];
		}
	}
#ifdef DEBUG
	for(int i = 1; i <= N; ++i) {
		printf("%d ", av[i]);
	}
	printf("\n");
#endif
	printf("%d\n", tot);
}

int main() {
#if defined(DEBUG) || defined(DUIPAI)
	freopen(NAME ".in", "r", stdin);
#endif

	readin();
	process();

	return 0;
}

#include<iostream>

using namespace std;
int ketqua;
int main(){
    int n,i,a,b, dance[100],dem[100];
    int ketiep,giua,lui;
    cin>>n>>a>>b;
    for (i=1;i<=n;i++){
        cin>>dance[i];
        }
if (n==1){
    if (dance[1]==2)
        if (a>b) ketqua=b; else ketqua=a;
    else ketqua=0;
}
 if (n%2==0 && n!=1){
        giua=n/2;
        ketiep=giua+1;
        lui=giua-1;
        while (giua>0 && ketiep<=n )
            {
            if (dance[giua]!=dance[ketiep] && dance[giua]!=2 && dance[ketiep]!=2){
                ketqua = -1;
                break;
            }
            if (dance[giua]==2 && dance[ketiep]==2){
                if (a>b) {dance[giua]=1; dance[ketiep]=1; ketqua=ketqua+(2*b);}
                else {dance[giua]=0; dance[ketiep]=0; ketqua=ketqua+(2*a);}
            }
            if (dance[giua]==2 && dance[ketiep]!=2){
                    dance[giua]=dance[ketiep];
                        if (dance[giua]==0) ketqua=ketqua+a;
                        else ketqua=ketqua+b;
            }
            if (dance[giua]!=2 && dance[ketiep]==2){
                    dance[ketiep]=dance[giua];
                    if (dance[ketiep]==0) ketqua=ketqua+a;
                    else ketqua=ketqua+b;}
                    giua--;
                    ketiep++;
        }
 }

if (n%2!=0 && n!=1){
        giua=n/2+1;
        ketiep=giua+1;
        lui=giua-1;
        while (lui>0)
            {
            if (dance[lui]!=dance[ketiep] && dance[lui]!=2 && dance[ketiep]!=2){
                ketqua = -1;
                break;
            }
            if (dance[giua]==2){
                if (a>b) {dance[giua]=1; ketqua=ketqua+b;}
                else {dance[giua]=0; ketqua=ketqua+a;}
            }
            if (dance[lui]==2 && dance[ketiep]==2){
                if (a>b) {dance[lui]=dance[ketiep]=1; ketqua=ketqua+2*b;}
                else {dance[lui]=dance[ketiep]=0; ketqua=ketqua+2*a;}
            }
            if (dance[lui]==2 && dance[ketiep]!=2){
                    dance[lui]=dance[ketiep];
                        if (dance[lui]==0) ketqua=ketqua+a;
                        else ketqua=ketqua+b;
            }
            else if (dance[lui]!=2 && dance[ketiep]==2){
                    dance[ketiep]=dance[lui];
                    if (dance[ketiep]==0) ketqua=ketqua+a;
                    else ketqua=ketqua+b;}
                    lui--;
                    ketiep++;
}
}
    cout<<ketqua;
}

#include <bits/stdc++.h>
#define ll long long
#define s second
#define f first

using namespace std;

int main() {
    int n, c, b;
    cin >> n >> b >> c;
    vector <int> a(n);
    for (int i = 0; i < n; i++)
        cin >> a[i];
    ll ans = 0;
    for (int i = 0; i < n / 2; i++) {
        if (a[i] != a[n - i - 1] && a[i] != 2 && a[n - i - 1] != 2)
            return cout << -1, 0;
        if (a[i] == 2 && a[n - i - 1] == 2)
            ans += 2 * min(b, c);
        else if (a[i] == 1 && a[n - i - 1] == 1)
            ans += 0;
        else if (a[i] == 0 && a[n - i - 1] == 0)
            ans += 0;
        else if (a[i] == 1 || a[n - i - 1] == 1)
            ans += c;
        else if (a[i] == 0 || a[n - i - 1] == 0)
            ans += b;
    }
    if (n % 2 == 1 && a[n / 2] == 2)
        ans += min(b, c);
    cout << ans;
    return 0;
}

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

// begin fast read template by CYJian (source: https://www.luogu.com.cn/paste/i11c3ppx)

namespace io {
	const int __SIZE = (1 << 21) + 1;
	char ibuf[__SIZE], *iS, *iT, obuf[__SIZE], *oS = obuf, *oT = oS + __SIZE - 1, __c, qu[55]; int __f, qr, _eof;
	#define Gc() (iS == iT ? (iT = (iS = ibuf) + fread (ibuf, 1, __SIZE, stdin), (iS == iT ? EOF : *iS ++)) : *iS ++)
	inline void flush () { fwrite (obuf, 1, oS - obuf, stdout), oS = obuf; }
	inline void gc (char &x) { x = Gc(); }
	inline void pc (char x) { *oS ++ = x; if (oS == oT) flush (); }
	inline void pstr (const char *s) { int __len = strlen(s); for (__f = 0; __f < __len; ++__f) pc (s[__f]); }
	inline void gstr (char *s) { for(__c = Gc(); __c < 32 || __c > 126 || __c == ' ';)  __c = Gc();
		for(; __c > 31 && __c < 127 && __c != ' '; ++s, __c = Gc()) *s = __c; *s = 0; }
	template <class I> inline bool gi (I &x) { _eof = 0;
		for (__f = 1, __c = Gc(); (__c < '0' || __c > '9') && !_eof; __c = Gc()) { if (__c == '-') __f = -1; _eof |= __c == EOF; }
		for (x = 0; __c <= '9' && __c >= '0' && !_eof; __c = Gc()) x = x * 10 + (__c & 15), _eof |= __c == EOF; x *= __f; return !_eof; }
	template <class I> inline void print (I x) { if (!x) pc ('0'); if (x < 0) pc ('-'), x = -x;
		while (x) qu[++ qr] = x % 10 + '0',  x /= 10; while (qr) pc (qu[qr --]); }
	struct Flusher_ {~Flusher_(){flush();}}io_flusher_;
} using io::pc; using io::gc; using io::pstr; using io::gstr; using io::gi; using io::print;

// end fast read template by CYJian

#define iter(i, a, b) for(int i=(a); i<(b); i++)
#define rep(i, a) iter(i, 0, a)
#define rep1(i, a) iter(i, 1, (a)+1)
#define log(a) cerr<<"\033[32m[DEBUG] "<<#a<<'='<<(a)<<" @ line "<<__LINE__<<"\033[0m"<<endl
#define all(a) a.begin(), a.end()
#define fi first
#define se second
#define pb push_back
#define mp make_pair

using ll=long long;
using pii=pair<int, int>;
//#define int ll
const int MOD = 1000000007;

int aray[105];
int c[3];

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    int n; gi(n), gi(c[0]), gi(c[1]);
	rep(i, n) gi(aray[i]);
	int ans = 0;
	for(int l = 0, r = n-1; l <= r; l ++, r --) {
		if(aray[l] == 2 && aray[r] == 2) {
			ans += (2-(l==r))*min(c[0],c[1]);
		} else if(aray[l] == 2) ans += c[aray[r]];
		else if(aray[r] == 2) ans += c[aray[l]];
		else if(aray[l] != aray[r]) {
			print(-1);
			return 0;
		}
	}
	print(ans);
}

#include<stdio.h>
#include<algorithm>
#include<string.h>
using namespace std;
const int maxn = 1e6 + 5;
int a[maxn];
int main()
{
	int ans,i,j,n,l,r,w,b;
	ans = 0;
	scanf("%d%d%d",&n,&w,&b);
	for(i = 0;i < n;i++)
        scanf("%d",&a[i]);
    if(n == 1)
    {
        if(a[0] == 2)
        {
            printf("%d\n",min(w,b));
            return 0;
        }
        else
        {
            printf("0\n");
            return 0;
        }
    }
	l = 0;
	int temp;
	if(n & 1)
        temp = n / 2 + 1;
    else
        temp = n / 2;
	for(l = 0;l < temp;l++)
    {
        if(a[l] == 2)
        {
            if(a[n - l - 1] == 1)
            {
                ans += b;
            }
            else if(a[n - l - 1] == 0)
            {
                ans += w;
            }
            else
            {
                if(l == n / 2 && (n & 1))
                    ans = ans + min(w,b);
                else
                    ans = ans + min(w,b) * 2;
            }
        }
        else if(a[n - l - 1] == 2)
        {
            if(a[l] == 1)
            {
                ans += b;
            }
            else if(a[l] == 0)
            {
                ans += w;
            }
        }
        else if(a[n - l - 1] != a[l])
        {
            printf("-1\n");
            return 0;
        }
    }
    printf("%d\n",ans);
    return 0;
}

#include<bits/stdc++.h>
#define pii   pair<int,int>
#define hell  1000000007
#define pb  push_back
typedef long long  ll;
using namespace std;
int main(){

    int n,w,b;
    cin >> n >> w >> b;

    int a[n];
    vector<int> v;

    for(int i=0;i<n;i++){
    	cin >> a[i];
    	v.pb(a[i]);

	}

    if(n == 1){
    	if(a[0] == 2){
    		cout << min(w,b);
    		return 0;
		}
		else{
			cout << 0;
			return 0;
		}
	}
    int ans = 0;

    int i = 0;

//	 v.erase(v.begin(),v.begin()+x);

   	  if(n%2){
      int x = n/2;

     if(v[x] == 2){
    	ans += min(w,b);
	 }
    }

    int j = n-1;

    while(i < j){

       if(v[i] == 1 && v[j] == 1){
    		j--;
    		i++;
		}
	  else if(v[i] == 0 && v[j] == 0){
    		j--;
    		i++;
		}
	  else if((v[i] == 0 && v[j] == 2) || (v[i] == 2 && v[j] == 0)){
			ans += w;
			i++;
			j--;
		}
	  else if((v[i] == 1 && v[j] == 2) || (v[i] == 2 && v[j] == 1)){
			ans += b;
			i++;
		    j--;
		}
		else if((v[i] == 0 && v[j] == 1) || (v[i] == 1 && v[j] == 0)){
			cout << -1;
			return 0;
		}
		else if(v[i] == 2 && v[j] == 2){
			ans += 2*min(w,b);
			i++;
			j--;
		}

	}

	cout << ans;

	return 0;
}

#include <iostream>
#include <algorithm>

using namespace std;

const int N = 20;

int t[N];

int main() {
	ios_base::sync_with_stdio(false);
	cout.tie(0);
	cin.tie(0);
	int a, b, n;
	cin >> n >> a >> b;
	for (int i = 0; i < n; i++) {
		cin >> t[i];
	}
	int sum = 0;
	for (int i = 0; i < (n - 1) / 2 + 1; i++) {
		if (t[i] == 2) {
			if (t[n - i - 1] == 0) {
				sum += a;
			}
			else if (t[n - i - 1] == 1){
				sum += b;
			}
			else if (i != n - i - 1){
				sum += 2 * min(a, b);
			}
			else {
				sum += min(a, b);
			}
		}
		else if (t[i] == 0){
			if (t[n - i - 1] == 1) {
				cout << -1;
				exit(0);
			}
			else if (t[n - i - 1] == 2) {
				sum += a;
			}
		}
		else if (t[i] == 1) {
			if (t[n - i - 1] == 0) {
				cout << -1;
				exit(0);
			}
			else if (t[n - i - 1] == 2){
				sum += b;
			}
		}
	}
	cout << sum;
}

#include <bits/stdc++.h>
using namespace std;
#define d(x)                cout << #x << " = " << (x) << endl;
#define fr                  freopen("in.txt", "r", stdin);
#define fw                  freopen("out.txt", "w", stdout);
#define mem(x)              memset((x), 0, sizeof((x)));
#define pb                  push_back
#define ll                  long long
#define fastIO              ios_base::sync_with_stdio(false)
#define sf                  scanf
#define pf                  printf
#define SQR(x)              ((x)*(x))
#define sc1(x)              scanf("%d", &x)
#define sc2(x, y)           scanf("%d %d", &x, &y)
#define sc3(x, y, z)        scanf("%d %d %d", &x, &y, &z)
#define FOR(i, x, y)        for(int i=int(x); i<int(y); i++)
#define ROF(i, x, y)        for(int i=int(x-1); i>=int(y); i--)
#define all(c)              (c.begin(), c.end())
#define unq(v)              sort(all(v)), (v).erase(unique(all(v)),v.end())
#define EPSILON    (1.0E-8)
#define siz 100000
#define s 1000000
#define ino printf("dhuksi\n");

 bool issquare(int n){
    int sq = sqrt(n);
    if(sq*sq == n){
        return true;
    }
    else{
        return false;
    }
 }

int main(){
    #ifndef ONLINE_JUDGE
        clock_t tStart = clock();
        freopen("in.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
    #endif
        int n, a, b;
        cin >> n >> a >> b;
        int ara[n];
        for(int i = 0; i < n; i++){
            cin >> ara[i];
        }

        int sada_boro = 0;
        int kalo_boro = 0;
        int kom = -1;
        int beshi = -1;
        if(a >= b){
            sada_boro = 1;
            beshi = a;
            kom = b;
        }
        else{
            kalo_boro = 1;
            beshi = b;
            kom = a;
        }

        int possible = 1;
        int ans = 0;
        int lim = -1;
        if(n%2 == 0){
            lim = (n/2)-1;
        }
        else{
            lim = n/2;
        }
        for(int i = 0; i <= lim; i++){
            int l = i;
            int r = n-(i+1);
            if(n%2 != 0 and i == n/2 and ara[i] == 2){
                ans += kom;
                continue;
            }
            if(ara[l] == 2 and ara[l] == ara[r]){
                ans += 2*kom;

                continue;
            }
            if(ara[l] == 2){
                if(ara[r] == 0){
                    ans += a;
                }
                else{
                    ans+= b;
                }
            }
            if(ara[l] == 0){
                if(ara[r] == 1){
                    possible = 0;
                    break;
                }
                else if(ara[r] == 2){
                    ans += a;
                }
            }
            else if(ara[l] == 1){
                if(ara[r] == 0){
                    possible = 0;
                    break;
                }
                else if(ara[r] == 2){
                    ans += b;
                }
            }
        }
        if(possible == 0){
            printf("-1\n");
        }
        else{
            cout << ans << endl;
        }
    #ifndef ONLINE_JUDGE
        printf("\n>>Time taken: %.10fs\n", (double) (clock() - tStart) / CLOCKS_PER_SEC);
    #endif
}

#include <iostream>
#include<stdio.h>
#include<math.h>
using namespace std;
int s[1010];
int main()
{
    int n,a,b;
    scanf("%d%d%d",&n,&a,&b);
    int i,j;
    for(i=0; i<n; i++)
        scanf("%d",&s[i]);
    int ans=0;
    int flas=0;
    int l=min(a,b);
    for(i=0, j=n-1; j>i; j--,i++)
    {
        if((s[i]==1&&s[j]==0)||(s[j]==1&&s[i]==0))
        {
            flas=1;
            break;
        }
        if(s[i]==2&&s[j]==2)
            ans+=l*2;
        else if(s[i]==2)
        {
            if(s[j]==1)
                ans+=b;
            else ans+=a;
        }
        else if(s[j]==2)
        {
            if(s[i]==1)
                ans+=b;
            else ans+=a;
        }
    }
    if(n%2!=0&&s[n/2]==2)ans+=min(a,b);
    if(flas)printf("-1\n");
    else printf("%d\n",ans);
    return 0;
}

#include<iostream>
using namespace std;
int main() {
	int sum=0, n, a, b;
	int queue[21];

	cin >> n >> a >> b;

	for  (int i = 0; i < n; i++) cin >> queue[i];

	for (int i = 0; i * 2 < (n ); i++) {
		if ((queue[i] != 2) && (queue[n - i - 1] != 2) && (queue[i] != queue[n - i - 1])) {
			sum = -1;
			break;
		}
		if (queue[i] != 2) if (queue[n - i - 1] == 2) {
			if (queue[i] == 0) sum += a;
			else sum += b;
		}

		if (queue[i] == 2)
			if (queue[n - i - 1] != 2) {
				if (queue[n - i - 1] == 0) sum += a;
				else sum += b;
			}
			else {
				if ((n%2==1) &&(i == n / 2)) {
					if (a <= b) sum +=  a;
					if (a > b) sum +=  b;
				}
				else {
					if (a <= b) sum += 2 * a;
					if (a > b) sum += 2 * b;
				}
			}
	}

	cout << sum;

	return 0;
}

#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cctype>
#include<cstdio>
#include<vector>
#include<string>
#include<queue>
#include<stack>
#include<cmath>
#include<map>
#include<set>
using namespace std;
const int inf=0x7fffffff;
const double eps=1e-10;
const double pi=acos(-1.0);
//char buf[1<<15],*S=buf,*T=buf;
//char getch(){return S==T&&(T=(S=buf)+fread(buf,1,1<<15,stdin),S==T)?0:*S++;}
inline int read(){
	int x=0,f=1;char ch;ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-') f=0;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch&15);ch=getchar();}
	if(f)return x;else return -x;
}
int n,a,b,ans,x[30];
int main()
{
	n=read();a=read();b=read();
	for(int i=1;i<=n;i++)x[i]=read();
	for(int i=1,j=n;i<=n;i++,j--){
		if(x[i]==2||x[j]==2){
			if(x[i]==2&&x[j]==2)ans+=min(a,b);
			if(x[i]==2&&x[j]==0)ans+=a,x[i]=0;
			if(x[j]==2&&x[i]==0)ans+=a,x[j]=0;
			if(x[i]==2&&x[j]==1)ans+=b,x[i]=1;
			if(x[j]==2&&x[i]==1)ans+=b,x[j]=1;
		}
		else if(x[i]!=x[j]){printf("-1\n");return 0;}
	}
	printf("%d\n",ans);
	return 0;
}

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;

int f[21];
int n,a,b;

int main()
{
	while(cin>>n>>a>>b)
	{
		for(int i=0;i<n;i++) cin>>f[i];
		int sum=0;
		int flag=0;
		for(int i=0;i<n/2;i++)
		{
			if(f[i]!=f[n-i-1])
			{
				if(!(f[i]==2||f[n-i-1]==2))
				{
					flag=1;
					break;
				}
				else
				{
					if(f[i]!=2) sum+=(f[i]==0)?a:b;
					if(f[n-i-1]!=2) sum+=(f[n-i-1]==0)?a:b;
				}
			}
			else if(f[i]==f[n-i-1]&&f[i]==2) sum+=2*min(a,b);
		}
		if(n&1)
		{
			if(f[n/2]==2) sum+=min(a,b);
		}
		if(flag) cout<<"-1"<<endl;
		else cout<<sum<<endl;
	}
	return 0;
}

#include <iostream>
#include <windows.h>
using namespace std;
int main()
{
        int n,a,b,*A,sum=0;
    cin>>n>>a>>b;
    A=new int[n];
    for(int i=0;i<n;i++)
        cin>>A[i];
    for(int i=0,j=n-1;j>=0;i++,j--)
    {
        if(A[i]==A[j] && A[i]==2)
            sum+=min(a,b);
        else if(A[i]!=A[j] && (A[i]==2 || A[j]==2))
        {
            if(A[i]==2)
            {
                if(A[j]==0)
                    sum+=a;
                else
                    sum+=b;
                A[i]=A[j];
            }
            else
            {
                if(A[i]==0)
                    sum+=a;
                else
                    sum+=b;
                A[j]=A[i];
            }
        }
        else if(A[i]!=A[j])
        {
            cout<<-1;
            return 0;
        }

    }
    cout<<sum;
    return 0;
}

#include <iostream>
using namespace std;
int n, c[2], ans, m;
int in[20];
int main() {
    cin >> n >> c[0] >> c[1];
    for (int i = 0; i < n; i++)
        cin >> in[i];
    m = min(c[0], c[1]);
    for (int i = 0; i < n; i++) {
        int l = i;
        int r = n - i - 1;
        if (l > r)
            break;
        if (l == r && in[l] == 2)
            ans += m;
        else if (in[l] == 2 && in[r] == 2)
            ans += m << 1;
        else if (in[l] == 2)
            ans += c[in[r]];
        else if (in[r] == 2)
            ans += c[in[l]];
        else if (in[l] == in[r]);
        else
            ans = -1;
        if (ans == -1)
            break;
    }
    cout << ans << '\n';
}

#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n,w,b,ans=0;
	cin>>n>>w>>b;
	int ar[n];
	for(int i=0;i<n;i++)
	{
		cin>>ar[i];
	}
	for(int i=0;i<n;i++)
	{
		if(ar[i]!=ar[n-1-i] and ar[i]!=2 and ar[n-1-i]!=2)
		{
			cout<<-1<<"\n";
			return 0;
		}
	}
	if(n%2==1)
	{
		for(int i=0;i<=n/2;i++)
		{
			if(ar[i]==0 and ar[n-1-i]==2)
			{
				ans+=w;
			}
			else if(ar[i]==2 and ar[n-1-i]==0)
			{
				ans+=w;
			}
			else if(ar[i]==1 and ar[n-1-i]==2)
			{
				ans+=b;
			}
			else if(ar[i]==2 and ar[n-1-i]==1)
			{
				ans+=b;
			}
			else if(ar[i]==2 and ar[n-1-i]==2 and i!=n/2)
			{
				ans+=min(b,w)*2;
			}
			else if(ar[i]==2 and i==n/2)
			{
				ans+=min(b,w);
			}
		}
	}
	else if(n%2==0)
	{
		for(int i=0;i<n/2;i++)
		{
			if(ar[i]==0 and ar[n-1-i]==2)
			{
				ans+=w;
			}
			else if(ar[i]==2 and ar[n-1-i]==0)
			{
				ans+=w;
			}
			else if(ar[i]==1 and ar[n-1-i]==2)
			{
				ans+=b;
			}
			else if(ar[i]==2 and ar[n-1-i]==1)
			{
				ans+=b;
			}
			else if(ar[i]==2 and ar[n-1-i]==2)
			{
				ans+=min(b,w)*2;
			}
		}
	}
	cout<<ans<<"\n";
}

#include<bits/stdc++.h>
using namespace std;
int main()
{int n,p,b,ans=0,f=0,left,right;
      cin>>n>>p>>b;
      int a[n+2];
      for(int i=1;i<=n;i++) cin>>a[i];
      for(left=1,right=n;left<right;left++,right--)
      {

            if((a[left]==0&&a[right]==1)||(a[left]==1&&a[right]==0))
            {
                  f=1; break;
            }
            else if(a[left]==2&&a[right]==2)
            ans+=2*min(p,b);
            else if((a[left]==2&&a[right]==1)||(a[left]==1&&a[right]==2))
            ans+=b;
            else if((a[left]==2&&a[right]==0)||(a[left]==0&&a[right]==2))
            ans+=p;
      }
      if(f==0&&left==right)
      if(a[left]==2)
      ans+=min(p,b);
      if(f==1)
      cout<<-1<<endl;
      else
      cout<<ans<<endl;
}

#include<bits/stdc++.h>
using namespace std;
int main()
{int n,p,b,ans=0,f=0,left,right;
      cin>>n>>p>>b;
      int a[n+2];
      for(int i=1;i<=n;i++) cin>>a[i];
      for(left=1,right=n;left<right;left++,right--)
      {

            if((a[left]==0&&a[right]==1)||(a[left]==1&&a[right]==0))
            {
                  f=1; break;
            }
            else if(a[left]==2&&a[right]==2)
            ans+=2*min(p,b);
            else if((a[left]==2&&a[right]==1)||(a[left]==1&&a[right]==2))
            ans+=b;
            else if((a[left]==2&&a[right]==0)||(a[left]==0&&a[right]==2))
            ans+=p;
      }
      if(f==0&&left==right&&a[left]==2)
      ans+=min(p,b);
      if(f==1)
      cout<<-1<<endl;
      else
      cout<<ans<<endl;
}

#include <iostream>
#include <string>
#include <cmath>
#include <fstream>
#include <vector>
#include <queue>
#include <list>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <iomanip>
#include <algorithm>
//#include <intrin.h>
#define el '\n'
#define fornp(i, x, n) for (int i = x; i < int(n); i++)
#define fornm(i, x, n) for (int i = x; i >= int(n); i--)
#define MAXN (int)(2e5+10)
#define vi vector<int>
//#define popcnt(n) __popcnt(int(n))
typedef long long ll;
#pragma warning(disable : 4996)

using namespace std;

int main()
{
	int n, a, b, cost = 0, arr[100], j;
	cin >> n >> a >> b;
	fornp(i, 0, n) cin >> arr[i];
	j = n - 1;
	if (!(n & 1)) n--;
	for (int i = 0; i <= n / 2; i++, j--)
	{
		if (arr[i] == 2 && arr[j] == 2)
		{
			if (i == j) cost += min(a, b);
			else cost += 2 * min(a, b);
			continue;
		}
		if (arr[i] != arr[j])
		{
			if ((arr[i] == 1 && arr[j] == 2) || (arr[j] == 1 && arr[i] == 2)) cost += b;
			else if ((arr[i] == 0 && arr[j] == 2) || (arr[j] == 0 && arr[i] == 2)) cost += a;
			else return !(cout << -1);
		}
	}
	cout << cost;
	return 0;
}

/*input
3 12 1
0 1 0
*/
#include <bits/stdc++.h>
#define int long long
#pragma GCC optmize("O2")
#define pii pair<int, int>
#define F first
#define S second
using namespace std;
const int MX = 2e5 + 100;
const int oo = 1ll << 30;
int v[MX];
main () {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int ans = 0;
	int n, a, b; cin >> n >> a >> b;
	for(int i = 1; i <= n; i ++) cin >> v[i];
	for(int i = 1; i <= n / 2; i ++) {
		int k = (v[i] == 2) + (v[n - i + 1] == 2);
		if(k == 0 and v[i] != v[n - i + 1]) return cout << -1, 0;
		if(k == 1) {
			if(v[i] == 1 or v[n - i + 1] == 1) ans += b;
			else                               ans += a;
		}
		if(k == 2) ans += 2 * min(a, b);
	}
	if((n & 1) and v[n / 2 + 1] == 2) ans += min(a, b);
	cout << ans;
}

#include<bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define ll long long
#define mm 1000000007
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define pii pair<int, int>
#define pll pair<ll, ll>

#define show(x) cout<<#x<<" "<<x<<'\n'
#define iosbase ios_base::sync_with_stdio(false); cin.tie(NULL);
#define oset tree<int , null_type, less_equal<int> , rb_tree_tag, tree_order_statistics_node_update>

using namespace std;
using namespace __gnu_pbds;
int N=100005;

int main()
{
    int n,a,b,i,j,ans=0,flag=0;
    cin>>n>>a>>b;
    int arr[n];

    for(i=0;i<n;i++) cin>>arr[i];

    int c=min(a,b);

    for(i=0,j=n-1;i<=j;i++,j--)
    {
        if((arr[i]==1 && arr[j]==0) || (arr[i]==0 && arr[j]==1))
        {
            flag=1;
            break;
        }
        if(i==j)
        {
            if(arr[i]==2) ans+=c;
            continue;
        }
        if(arr[i]==2 && arr[j]==2)
        {
            ans+=2*c;
            continue;
        }
        if(arr[i]==2)
        {
            if(arr[j]==0) ans+=a;
            if(arr[j]==1) ans+=b;
        }
        if(arr[j]==2)
        {
            if(arr[i]==0) ans+=a;
            if(arr[i]==1) ans+=b;
        }
    }
    if(flag) cout<<"-1\n";
    else cout<<ans<<'\n';
}

#include<bits/stdc++.h>
using namespace std;
int main(){
	int n, w, b;
	cin >> n >> w >>b;
	int ar[n];
	for (int i=0;i<n;i++){
		scanf("%d",&ar[i]);
	}
	int ans=0;
	int val=1;
	int mid=(n+1)/2;
	for (int i=0;i<mid;i++){
		if (ar[i]!=2&&ar[n-1-i]!=2&&ar[i]!=ar[n-1-i]){
			val=0;
			break;
		}
		else if (ar[i]==2&&ar[n-1-i]==2){
			ans+=2*min(w,b);
			if (i==n-1-i){
				ans-=min(w,b);
			}
		}
		else if (ar[i]==ar[n-1-i]){
			continue;
		}
		else if (ar[i]==0||ar[n-1-i]==0 /*wauw lupa ==0 */){
			ans+=w;
		}
		else{
			ans+=b;
		}
	}
	if (val)printf ("%d\n",ans);
	else printf ("-1\n");
}

#include <bits/stdc++.h>
#define ll long long
#define s second
#define f first

using namespace std;

int main() {
    int n, c, b;
    cin >> n >> b >> c;
    vector <int> a(n);
    for (int i = 0; i < n; i++)
        cin >> a[i];
    ll ans = 0;
    for (int i = 0; i < n / 2; i++) {
        if (a[i] != a[n - i - 1] && a[i] != 2 && a[n - i - 1] != 2)
            return cout << -1, 0;
        if (a[i] == 2 && a[n - i - 1] == 2)
            ans += 2 * min(b, c);
        else if (a[i] == 1 && a[n - i - 1] == 1)
            ans += 0;
        else if (a[i] == 0 && a[n - i - 1] == 0)
            ans += 0;
        else if (a[i] == 1 || a[n - i - 1] == 1)
            ans += c;
        else if (a[i] == 0 || a[n - i - 1] == 0)
            ans += b;
    }
    if (n % 2 == 1 && a[n / 2] == 2)
        ans += min(b, c);
    cout << ans;
    return 0;
}

#include <bits/stdc++.h>

using namespace std;

int c[20];

int main(){
	int n, a, b;
	cin >> n >> a >> b;
	bool ok = 1;
	int ans = 0;
	int k = (n - 1) % 2;
	for (int i = 0; i < n; i++) {
		cin >> c[i];
		if (n - 1 - i < (n - 1) / 2 + k) {
			if (c[i] == 2 || c[n - 1 - i] == 2) {
				if (c[i] != 2) {
					if (c[i]) ans += b;
					else ans += a;
				}
				else if (c[n - 1 - i] != 2) {
					if (c[n - 1 - i]) ans += b;
					else ans += a;
				}
				else ans += 2 * min(a, b);
			} else if (c[i] != c[n - 1 - i]) ok = 0;
		}
	}
	if (!k) if (c[(n - 1) / 2] == 2) ans += min(a, b);
	if (ok) cout << ans;
	else cout << -1;
	return 0;
}

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int n,w,b;
int a[100050];
int ans=0;
int main(){
	scanf("%d%d%d",&n,&w,&b);
	for(int i(1);i<=n;i++)scanf("%d",&a[i]);
	int l=0,r=n+1;
	for(int i(1);i<=n;i++){
		l++;r--;
		if(r<=l){
			if(r==l and a[l]==2)ans+=min(b,w);
			break;
		}
		if(a[l]==0 and a[r]==0)continue;
		if(a[l]==1 and a[r]==1)continue;

		if((a[l]==2 and a[r]==0) or (a[l]==0 and a[r]==2)){
			ans+=w;
			continue;
		}
		if((a[l]==2 and a[r]==1) or (a[l]==1 and a[r]==2)){
			ans+=b;
			continue;
		}
		if(a[l]==2 and a[r]==2){
			ans+=2*min(b,w);
			continue;
		}
		if(a[l]!=2 and a[r]!=2 and a[l]!=a[r]){
			printf("%d",-1);
			return 0;
		}
	}
	printf("%d",ans);
	return 0;
}

#pragma warning(disable:4786)
#pragma warning(disable:4996)
#include<bits/stdc++.h>
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define pli pair<long long , int>
#define pil pair<int ,long long>
#define pi acos(-1)
#define pb push_back
#define mkp make_pair
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long

using namespace std;

int main(){
	IOS
    int n,a,b;
    cin>>n>>a>>b;
    int arr[n];
    for(int i=0;i<n;i++){
        cin>>arr[i];
    }
    ll psum=0;
    for(int i=0;i<n;i++){
        //cout<<arr[i]<<endl;
        if(arr[i]==0){
            psum+=a;
        }
        else if(arr[i]==1){
            psum+=b;
        }
    }
    //cout<<psum<<endl;
    bool mn;
    if(a>=b){
        mn=true;
    }
    else{
        mn=false;
    }
    int aw=0;
    bool bl=true;
    for(int i=0,j=n-1;i<=j;i++,j--){
        if(i==j){
            if(arr[i]==2){
               if(mn==false){
                    arr[i]=0;

                }
                else{
                    arr[i]=1;

                }
            }
            else{
                continue;
            }
        }
        else if(arr[i]==2 && arr[j]==2){
            if(mn==false){
                arr[i]=0;
                arr[j]=0;
            }
            else{
                arr[i]=1;
                arr[j]=1;
            }
        }
        else{
            if(arr[i]!=arr[j] && (arr[i]!=2 && arr[j]!=2)){
                bl=false;
            }
            else if(arr[i]==arr[j] && (arr[i]!=2 || arr[j]!=2)){
                continue;
            }
            else{
                if(arr[i]==2){
                    arr[i]=arr[j];
                }
                else if(arr[j]==2){
                    arr[j]=arr[i];
                }
            }
        }
    }
    if(bl==false){
        cout<<"-1";
        return 0;
    }
    ll sum=0;
    for(int i=0;i<n;i++){
        //cout<<arr[i]<<endl;
        if(arr[i]==0){
            sum+=a;
        }
        else{
            sum+=b;
        }
    }
    cout<<sum-psum;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

int main(){

    fastio
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif

    ll N,A,B;cin>>N>>A>>B;
    vector<ll> v;
    for(ll i=0;i<N;i++) {
        ll x;cin>>x;v.pb(x);
    }
    ll cost = 0;
    for(ll i=0;i<v.size()/2;i++){
        ll j = N-i-1;
        if(v[i] == 2 || v[j] == 2){
            if(v[i] == 0 || v[j] == 0) cost+=A;
            else if(v[i] == 1 || v[j] == 1) cost+=B;
            else if(v[i] == 2 && v[j] == 2) cost+=min(A,B)*2;
        }
        else if(v[i]!=v[j]) {cout<<"-1\n";return 0;}
    }
    if(N%2==1 && v[N/2]==2) cost+=min(A,B);
    cout<<cost<<"\n";
    return 0;
}
/* NOTHING IS IMPOSSIBLE*/

#include<bits/stdc++.h>

using namespace std;

int main(){

	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

	int n,w_c,b_c;
	int cost=0;

	cin>>n>>w_c>>b_c;

	int a[n];

	for(int i=0;i<n;i++){
		cin>>a[i];
	}

	for(int i=0;i<n/2;i++){
		if( (a[i] != a[n-1-i]) and (a[i]!=2 and a[n-1-i] !=2) )    {
			cout<<-1;
			return 0;
		}
	}

	for(int i=0;i<n/2;i++){

		if(a[i]==2 and a[n-1-i] ==2){
			cost+=2*min(w_c,b_c);
			continue;
		}
		if( (a[i]==0 or a[n-1-i]==0) and (a[i]==2 or a[n-1-i] ==2) ){
			cost+=w_c;
			continue;
		}
		if( (a[i]==1 or a[n-1-i]==1) and (a[i]==2 or a[n-1-i]==2)){
			cost+=b_c;
		}

	}

	if( n%2 !=0  and  a[n/2]==2 ){
		cost+=min(w_c,b_c);
	}

	cout<<cost;
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,a,b;cin>>n;
	cin>>a>>b;int a1[n];long long cost=0;
	for(int i=0;i<n;i++){cin>>a1[i];}
	for(int i=0;i<(n/2);i++)
	{
		if(a1[i]==a1[n-1-i]&&a1[i]!=2)
		{
			continue;
		}
		if(a1[i]==2||a1[n-i-1]==2)
		{
			if(a1[i]==2&&a1[n-i-1]==2)
			{
				cost+=(2*min(a,b));
				continue;
			}
		  if(a1[i]==0)
		  {
		  	cost+=a;continue;
		  }
		  if(a1[i]==1){cost+=b;continue;}
		    if(a1[n-1-i]==0)
		  {
		  	cost+=a;continue;
		  }
		  if(a1[n-1-i]==1){cost+=b;continue;}

		}
		else if(a1[n-1-i]!=a1[i])
		{
			cout<<-1;exit(0);
		}

	}
	if(n&1){if(a1[(n/2)]==2){cost+=min(a,b);}}
	cout<<cost;
}

#include <stdio.h>
#include "iostream"
#include "conio.h"
#include "math.h"
#include "stdlib.h"
#include "time.h"
#include <string.h>
#define sp << " "
#define sps << " " <<
#define lnl << endl <<
#define ln << endl
using namespace std;
int main()
{
	int n, a, b, *A, t = 0;
	cin >> n >> a >> b;
	A = new int[n];
	for (int i = 0; i < n; i++)
		cin >> A[i];
	int i, j;
	for (i = 0;; i++)
	{
		 j = n - i - 1;
		if (i == j || i>j)
			break;
		if (A[i] == A[j] && A[i] != 2 && A[j] != 2)
			continue;
		if (A[i] != A[j] && (A[i] != 2 && A[j] != 2))

		{
			cout << "-1";
			return 0;
		}
		if (A[i] == 2 && A[j] == 2)
			if (a > b)
				t += 2 * b;
			else
				t += 2 * a;
		if (A[i] != A[j] && (A[i] == 2 || A[j] == 2))
		{
			if (A[i] == 2)
				if (A[j] == 0)
					t += a;
				else
					t += b;
			if (A[j] == 2)
				if (A[i] == 0)
					t += a;
				else
					t += b;

		}
	}
	if (i == j && A[i] == 2)
		if (a > b)
			t += b;
		else
			t += a;
	cout << t;
}

#include <iostream>
#include <cmath>
#include <string>
using namespace std;
int main()
{
    int n,a,b;
    cin >>n>>a>>b;
    int d[n];
    for(int i=0; i<n; i++){
      cin >> d[i];
    }
    int sum =0;
    int m=min(a,b);
    for(int i=0 ,j=n-1;i<(n+1)/2; i++, j--){

        if(d[i]+d[j]==1){
          cout<<-1;
          return 0;
        }
        int k=(int)abs(d[i]-d[j]);
        if(k==2)sum +=a;
        else if(k==1)sum +=b;
        else if(k==0 && d[i]==2){
          if(i!=n/2)sum +=2*m;
        else sum +=m;
        }
        //cout << i<<" "<<j<<" "<<sum <<endl;
    }
    cout << sum;

    return 0;
}

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

int main()
{
    int n,a,b;
    cin>>n>>a>>b;
    int ar[n];
    int ans=0;
    for(int i=0;i<n;i++){
        cin>>ar[i];
    }
    int i=0,j=n-1;
    while(i<j){
        if(ar[i]!=ar[j] && ar[i]!=2 && ar[j]!=2){
            cout<<"-1";
            return 0;
        }else if(ar[j]==2){
            if(ar[i] == 0){
                ans+=a;
            }else if(ar[i]==1){
                ans+=b;
            }
        }else if(ar[i]==2){
            if(ar[j] == 0){
                ans+=a;
            }else if(ar[j]==1){
                ans+=b;
            }
        }
        i++;j--;
    }

    if(ar[n/2]==2)
        ans += min(a,b);
    cout<<ans;
    return 0;
}

////██╗ ██████╗ ██╗    ██████╗  ██████╗  ██╗ █████╗
////██║██╔═══██╗██║    ╚════██╗██╔═████╗███║██╔══██╗
////██║██║   ██║██║     █████╔╝██║██╔██║╚██║╚██████║
////██║██║   ██║██║    ██╔═══╝ ████╔╝██║ ██║ ╚═══██║
////██║╚██████╔╝██║    ███████╗╚██████╔╝ ██║ █████╔╝
////╚═╝ ╚═════╝ ╚═╝    ╚══════╝ ╚═════╝  ╚═╝ ╚════╝

#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define pb push_back
#define pf push_front
#define fr first
#define sc second
#define mlojins cout.tie(NULL);
#define bzbz cin.tie(NULL);
#define CODER ios_base::sync_with_stdio(0)  ;
#define p_b pop_back
#define p_f pop_front
#define Qulukh
#define Mekh
#define Zohiri_dzd
#define Black_star
using namespace std ;

const ll N = 1e6 + 1;

map <ll , ll> mp , pm ;
deque <ll> v , vc , ve ;
deque <ll> p , pe ;
deque <string> ts , ss ;
deque <float> sd ;
ll a , b , c , d , e , f , cnt , ans , r , n , l;
double q , t , cnt1;
string g , h , w , o , z , m , s ;
char y , u ;
bool re , rt ;
set < ll > st ;
vector<pair < ll , ll > > pr , rp;
int main ()

{
    bzbz
    mlojins
    CODER
    Qulukh
    Mekh
    Zohiri_dzd
    Black_star
    /*freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);*/
    cin >> a >> b >> c ;
    for (int i = 0 ; i < a ; i ++ )
    {
        cin >> d ;
        v.pb(d) ;
        mp[d] ++ ;
    }
    if (mp[d] == a and a != 1 and d == 2 )
    {
        cout << min(b , c) * a ;
        return 0;
    }
    for (int i = 0 ; i < a / 2 ; i ++ )
    {
        if ((v[i] == 1 and v[a - i - 1] == 2) or (v[i] == 2 and v[a - i - 1] == 1))
            ans += c , v[i] = 1 , v[a - i - 1] = 1 ;
        else if ((v[i] == 0 and v[a - i - 1] == 2) or (v[i] == 2 and v[a - i - 1] == 0))
            ans += b , v[i] = 0 , v[a - i - 1] = 0 ;
        else if (v[i] == 2 and v[a - i - 1] == 2)
            ans += min(b , c) , v[i] = 3 , v[a - i - 1] = 3 ;
        else if (v[i] != v[a - i - 1])
        {
            cout << -1 ;
            return 0 ;
        }
    }
    if (v[a / 2] == 2 and a % 2 != 0)
        ans += min(b , c) ;
    cout << ans ;
}
///Mmavl studios
///Eco students
///7c is the best

#include <iostream>
using namespace std;

int min(int a, int c) {
	if (a < c) return a;
	else return c;
}

int plusss(int q, int b, int w) {
	if (q == 0) { return b; }
	if (q == 1) { return w; }
	if (q == 2) { return min(b, w); }
}

int main()
{
	bool bb = true;
	int n, w, b, x, t;
	int res = 0, pre_res = 0;

	cin >> n >> w >> b;
	int *c = new int[n];
	for (int i = 0; i < n; i++) {
		cin >> c[i];
	}
	if ((n % 2) != 0) {
		n--;
		if (c[(n / 2)] == 2) { pre_res = min(w, b); }
	}
	for (int i = 0;i < n / 2;i++) {
		if (c[i] == c[n - i] && c[i]==2) { res += (plusss(c[i], b, w))*2; }
		else if (c[i] == 2) { res += plusss(c[n - i], b, w); }
		else if (c[n - i] == 2) { res += plusss(c[i], b, w); }
		else bb = false;
	}
	if (bb == true) {
		res += pre_res;
		cout << res;
	}
	else
		cout << -1;
}

#include<bits/stdc++.h>
using namespace std;
int main(){
	int n, w, b;
	cin >> n >> w >>b;
	int ar[n];
	for (int i=0;i<n;i++){
		scanf("%d",&ar[i]);
	}
	int ans=0;
	int val=1;
	int mid=(n+1)/2;
	for (int i=0;i<=mid;i++){
		if (ar[i]!=2&&ar[n-1-i]!=2&&ar[i]!=ar[n-1-i]){
			val=0;
			break;
		}
		else if (ar[i]==2&&ar[n-1-i]==2){
			ans+=min(w,b);
		}
		else if (ar[i]==ar[n-1-i]){
			continue;
		}
		else if (ar[i]==0){
			ans+=w;
		}
		else{
			ans+=b;
		}
	}
	if (val)printf ("%d\n",ans);
	else printf ("-1\n");
}

#include<bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<cstdio>
#include<utility>
using namespace std;
int main()
{
 fast;
 int n, a, b ,i; int d=0;
 cin>>n>>a>>b;    int c[n],j=n-1;

   for(i=0;i<n;++i)
  {
    cin>>c[i];
  }

   for(i=0;i<n;++i)
  {
    if(c[i]!=c[j] && c[i]!=2 && c[j]!=2)
    d=-1;

    --j;
  }
    j=n-1;
    for(i=0;i<n;++i)
  {
    if(c[i]==0 && c[j]==2) d+=a;
    if(c[i]==1 && c[j]==2) d+=b;
    if(c[i]==2 && c[j]==2) d+=min(a,b);
    --j;
  }
    cout<<d;
}

#include<iostream>
using namespace std;
int main()
{
 int n,a,b,i,j;
cin>>n>>a>>b;
 int arr[n];
int cost=0;
 bool flag=true;
for(i=0;i<n;i++)
cin>>arr[i];
 for(i=0,j=n-1;i<j;i++,j--)
  {
    if(arr[i]!=arr[j])
    {
      if((arr[i]==2&&arr[j]==1)||(arr[i]==1&&arr[j]==2))
      cost+=b;
      else if((arr[i]==2&&arr[j]==0)||(arr[i]==0&&arr[j]==2))
        cost+=a;
      else
       {
       flag=false;
       break;
       }
    }
     if(arr[i]==2&&arr[j]==2)
     cost+=2*(a<=b?a:b);

  }
  if(!flag)
  cout<<"-1";
  else
  {
   if(n%2==0)
  cout<<cost;
  else
  {
  if(cost>0&&arr[i]==2)
  cout<<(cost+(a<=b?a:b));
  else
  cout<<cost;
  }
  }
}

#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <bits/stdc++.h>
#include <stdlib.h>

#define tests int t;cin>>t;while(t--)
#define array(A,n) long long int A[n];for(int i=0;i<n;i++)cin>>A[i];
#define array2(A,B,n,m) long long int A[n] , B[m];for(int i=0;i<n;i++)cin>>A[i]; for(int i=0;i<m;i++)cin>>B[i];
#define print(A,n) for(int i=0;i<n;i++)cout<<A[i]<<" ";cout<<endl;
#define matrix(A,n,m) long long int A[n][m];for(int i=0;i<n;i++){for(int j=0;j<m;j++)cin>>A[i][j];}
#define vit(a) vector<long long int>::iterator a
#define vrit(a) vector<long long int>::reverse_iterator a
#define sit(a) set<long long int>::iterator a
#define yes "yes"
#define no "no"
#define YES "YES"
#define NO "NO"
#define Yes "Yes"
#define No "No"
long long int  min(long long int a,long long int b)
{if(a>b)return b; else return a;}

long long int  MAX(long long int a,long long int b)
{if(a>b)return a; else return b;}
long long int mod(long long int x)
{if(x>=0)return x;else return-x;}

using namespace std;
int main() {

    long long int n ,a,b ,c=0  ,k ;
    cin>>n>>a>>b;

    array(A,n);
    long int ans = 0;
    for(int i=0;i<=(n-1)/2;i++)
    {
        if(A[i]==0)
        {
            if(A[n-i-1]==0)
                c++;
            else if(A[n-i-1]==1)
                continue;
            else { ans+=a;c++;}

        }
        else if(A[i]==1)
        {if(A[n-i-1]==0)
                continue;
            else if(A[n-i-1]==1)
                c++;
            else { ans+=b;c++;}

        }
        else if(A[i]==2)
        {
         if(A[n-i-1]==0)
         {ans+=a;c++;}
            else if(A[n-i-1]==1)
            {ans+=b;c++;}
            else { ans+=min(a,b);
                   ans+=min(a,b);
                  c++;
                 }
        }
    }
           if(c==((n-1)/2)+1)
               cout<<ans<<endl;
    else cout<<-1<<endl;
    return 0 ;
}

#include <bits/stdc++.h>
using namespace std;
#define optimize ios_base::sync_with_stdio(false)
#define FOR(i, a, n) for(int i = a; i < n; i++)
int myArray[100009], cur_marks[100009], n, a, b;
long long ans;

int main()
{
    optimize;
    //freopen("input.txt", "r", stdin);
    cin >> n >> a >> b;
    int price[2] = {a, b};
    int ar[n];
    FOR(i, 0, n) cin >> ar[i];
    int n1 = n;
    if (n % 2 == 1) n1 = n + 1;
    for(int i = 0, j = n - 1; i < (int) n1/2; i++, j--){
        if(i == j){
            if(ar[i] == 2) ans += (a < b ? a : b);
            break;
        }
        if(ar[i] != ar[j] && ar[i] != 2 && ar[j] != 2) {cout << "-1" << endl; return 0;}
        else{
            if(ar[i] == 2 && ar[j] != 2) ans += price[ ar[j] ];
            else if(ar[j] == 2 && ar[i] != 2) ans += price[ ar[i] ];
            else if(ar[i] == 2 && ar[j] == 2) ans += (a < b ? a : b);
        }
    }
    cout << ans << endl;

    return 0;
}

#include <stdio.h>

int main()
{
    int i, j, n, a, b, sum = 0;

    scanf("%d%d%d", &n, &a, &b);
    int arr[n];

    for(i = 0; i < n; i++)
    {
        scanf("%d", &arr[i]);
    }
    j = n;
    for(i = 0; i < (n/2); i++)
    {
        j--;
        if(arr[i]==arr[j])
            continue;
        if(arr[j]==2)
        {
            if(arr[i]==0)
                sum = sum + a;
            else
                sum = sum + b;
        }
       else if(arr[i]==2)
        {
            if(arr[j]==0)
                sum = sum + a;
            else
                sum = sum + b;
        }
        else
        {
            printf("-1\n");
            return 0;
        }
    }

    if(n%2==1)
    {
        if(arr[i] == 2)
           if(a > b)
            sum = sum + b;
        else
            sum = sum + a;
    }

    printf("%d\n", sum);

    return 0;
}

#include<bits/stdc++.h>
#define ll long long
#define ve vector
#define pb push_back
using namespace std;

int main()
{
	int n,w,b,ans=0;
	cin>>n>>w>>b;
	ve<int> v(n);
	for(auto &a:v)
		cin>>a;
	int l=0,h=n-1;
	map<int,int> m;
	m[0]=w;
	m[1]=b;
	m[2]=min(w,b);
	while(l<=h)
	{
		if(v[l]-v[h]==0 && v[l]!=2)
		{
			l++,h--;
			continue;
		}
		if(v[l]+v[h] == 1)
		{
			cout<<-1<<endl;
			return 0;
		}
		if(v[l]-v[h] == 0)
			ans += 2*m[2];
		else if(v[l]+v[h] == 2)
			ans += m[0];
		else
			ans += m[1];
		l++,h--;
	}
	cout<<ans<<endl;
	return 0;
}

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

#define int int64_t
#define MOD 1e9 + 7

int32_t main()
{
    ios_base :: sync_with_stdio(false);
    cin.tie(NULL);  cout.tie(NULL);

    int n, a, b;
    cin >> n >> a >> b;

    int *c = new int[n]();
    for(int i=0; i<n; i++)
        cin >> c[i];

    bool flag = false;

    for(int i=0; i<n; i++)
    {
        if((c[i] == 0 && c[n-i-1] == 1) || (c[i] == 1 && c[n-i-1] == 0))
        {
            flag = true;
            break;
        }
    }

    int count0 = 0, count1 = 0;
    for(int i=0; i<n; i++)
    {
        if(c[i] == 0)
            count0++;

        else if(c[i] == 1)
            count1++;
    }

    if(count0 == n || count1 == n)
        flag = true;

    if(flag)
    {
        cout << "-1";
        return 0;
    }

    int ans = 0;
    for(int i=0; i<n; i++)
    {
        if((c[i] == 0 && c[n-i-1] == 0) || (c[i] == 1 && c[n-i-1] == 1))
            continue;

        if(c[i] == 0 && c[n-i-1] == 2)
        {
            c[n-i-1] = 0;
            ans += a;
        }

        if(c[i] == 1 && c[n-i-1] == 2)
        {
            c[n-i-1] = 1;
            ans += b;
        }
    }

    int count = 0;
    for(int i=0; i<=n/2; i++)
        if(c[i] == 2)
            count++;

    ans += min(a, b) * count;

    cout << ans;

    delete [] c;

    return 0;
}

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

int main()
{
    int n,a,b;
    cin>>n>>a>>b;

    int c[n+2],id=n,ans=0,ch=1;
    for(int i=1; i<=n; i++) cin>>c[i];

    for(int i=1; i<=n/2; i++)
    {
        if(c[i]==c[id])
        {
            if(c[i]==1||c[i]==0) continue;
            else ans+=min(a,b);
        }
        else if(c[i]==2)
        {
            if(c[id]==0) ans+=a;
            else ans+=b;
        }
        else if(c[id]==2)
        {
            if(c[i]==0) ans+=a;
            else ans+=b;
        }
        else ch=0;
        id--;
    }
    if(n%2==1&&c[n/2+1]==2) ans+=min(a,b);

    if(ch) cout<<ans<<endl;
    else cout<<-1<<endl;
}

#pragma GCC diagnostic error "-std=c++11"
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 5e5 + 5;
const ll inf = 0x3f3f3f3f3f;
ll n,a,b;
ll clo[maxn];
int main(){
    cin>>n>>a>>b;
    for(int i=0;i<n;i++)
    cin>>clo[i];
    ll ans=0;
    for(int i=0;i<n/2;i++)
    {
        if(clo[i]==1&&clo[n-1-i]==0)
        {
            cout<<-1;
            return 0;
        }
        if((clo[i]==1&&clo[n-1-i]==2)||(clo[i]==2&&clo[n-1-i]==1)) ans+=b;
        if((clo[i]==0&&clo[n-1-i]==2)||(clo[i]==2&&clo[n-1-i]==0)) ans+=a;
        if(clo[i]==2&&clo[n-1-i]==2) ans+=2*min(a,b);
    }
    if(clo[n/2]==2&&(n&1)) ans+=min(a,b);
    cout<<ans<<endl;
    return 0;
}

#include <bits/stdc++.h>

using namespace std ;

#define sz(v) v.size()
#define ll long long
#define all(v)  v.begin() , v.end()
#define rall(v)  v.rbegin() , v.rend()
#define pf push_front
#define pb push_back
#define fast FastInputOutput() ;
#define Clear( container , value ) memset( container , value , sizeof container )

void File_input(){
freopen( "input.txt" , "r" , stdin ) ;
freopen( "output.txt" , "w" , stdout ) ;
}

void FastInputOutput(){
    ios_base :: sync_with_stdio( 0 ) ;
    cin.tie( 0 ) ;
    cout.tie( 0 ) ;
}

const int N = 30 ;
int a[ N ] = {3} ;

int main(){

   fast
   int n , w , b ;
   cin >> n >> w >> b ;
   for( int i = 0 ; i < n ; i++ )
       cin >> a[ i ] ;

  int ans = 0 ;
  bool can = 1 ;

  for( int l = 0 ; l <= n / 2 ; l++ ){

    if( a[ l ] == 1 && a[ n - l - 1 ] == 0 ) {
        can = 0 ;
        break ;
    }
    else if( a[ l ] == 0 && a[ n - l - 1 ] == 1 ){
        can = 0 ;
        break ;
    }

    if( a[ l ] == 1 && a[ n - l - 1 ] == 2 )
        ans += b ;
    else if( a[ l ] == 2 && a[ n - l - 1 ] == 1 )
        ans += b ;
    else if( a[ l ] == 0 && a[ n - l - 1 ] == 2 ){
        ans += w ;
    }
    else if( a[ l ] == 2 && a[ n - l - 1 ] == 0 ){
        ans += w ;
    }
    else if( a[ l ] == a[ n - l - 1 ] && a[ l ] == 2 ){
        ans += min( w , b ) ;
    }
  }

  if( !can ){
    cout << "-1\n" ;
    return 0 ;
  }

  cout << ans ;

  return 0 ;
}

#define _CRT_SECURE_NO_WARNINGS
#include <stdlib.h>
#include <stdio.h>
#include <iostream>
#include <math.h>
#include <map>
#include <set>
#include <stack>
#include <vector>
#include <time.h>
#include <random>
#include <algorithm>
#include <string>
#include <string.h>
#include <queue>
#include <deque>
#include <functional>
#include <cctype>
#include <list>
#include <queue>
#include <unordered_set>
#include <unordered_map>

using namespace std;

#define ll long long

int arr[100];

int main() {
  int n, a, b;
  cin >> n >> a >> b;

  for (int i = 0; i < n; i++) {
      cin >> arr[i];
  }

  int res = 0;
  for (int i = 0; i < n / 2; i++) {
      if (arr[i] == 0 && arr[n - i - 1] == 2) {
          res+= a;
        } else if (arr[i] == 1 && arr[n - i - 1] == 2) {
          res+= b;
        } else if (arr[i] == arr[n - i - 1] && arr[n - i - 1] == 2) {
          res += min(a, b) * 2;
        } else if (arr[i] != arr[n - i - 1]) {
          cout << -1;
          return 0;
        }
  }

  if (n % 2 && arr[n / 2 + 1]) {
      res += min(a, b);
    }

  cout << res;
}

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

int main()
{
	int n,a,b;
	cin>>n>>a>>b;

	int colors[n];

	for(int n1=0;n1<n;n1++)
	{
		cin>>colors[n1];
	}

	int i=0,j=n-1,ans=0;

	while(i<j)
	{
		if((colors[i]!=colors[j]) && (colors[i]!=2 && colors[j]!=2))
		{
//			cout<<i<<" "<<j<<endl;
			cout<<"-1";
			return 0;
		}
		if(colors[i]==1)
		{
			if(colors[j]!=2)
			{
				j--;
				i++;
				continue;
			}
			else
			{
				ans+=b;
				j--;
			}
		}
		if(colors[i]==0)
		{
			if(colors[j]!=2)
			{
				j--;
				i++;
				continue;
			}
			else
			{
				ans+=a;
				j--;
			}
		}
		if(colors[i]==2)
		{
			if(colors[j]==1)
			{
				j--;
				ans+=b;
			}
			else
			{
				if(colors[j]==0)
				{
					j--;
					ans+=a;
				}
				else
				{
					ans+=min(a,b);
					j--;
				}
			}
		}
		i++;
	}
	if(i==j)
	{
		if(i==2)
		{
			ans+=min(a,b);
		}
	}
	cout<<ans;
}

/* Bismillahir Rahmanir Rahim
There is no god without Allah*/
#include<bits/stdc++.h>
#include<iomanip>
typedef long long ll;
typedef unsigned long long ul;
#define pi acos(-1)
#define ll long long
#define ull unsigned long long
#define vec vector<ll>
#define f1(i,n) for(i=1;i<n;i++)
#define test   ll ttt;cin>>ttt;while(ttt--)
long long int i,j;
using namespace std;
int main()
{
    //freopen("a.txt","r",stdin);
    int n,a,b;
    cin>>n>>a>>b;
    int ar[n];
    int z=0,on=0,tw=0;
    for(i=0; i<n; i++)
    {
        cin>>ar[i];
        if(ar[i]==0)
            z++;
        if(ar[i]==1)
            on++;
        if(ar[i]==2)
            tw++;
    }
    int low=0,high=0,bol=0;
    for(i=0; i<n/2; i++)
    {
        if(ar[i]==0&&ar[n-i-1]==0||ar[i]==1&&ar[n-i-1]==1)
            continue;
        else if(ar[i]==2||ar[n-i-1]==2)
        {
            if(ar[i]==2&&ar[n-i-1]==2)
            {
                if(a>b)
                    high++;
                else
                    low++;
            }
            else if(ar[i]==1&&ar[n-i-1]==2||ar[n-i-1]==1&&ar[i]==2)
            {
                high++;
                if(ar[i]==2)
                    ar[i]=1;
                else
                    ar[n-i-1]=1;
            }
            else if(ar[i]==0&&ar[n-i-1]==2||ar[n-i-1]==0&&ar[i]==2)
            {
                low++;
                if(ar[i]==2)
                    ar[i]=0;
                else
                    ar[n-i-1]=0;
            }

        }
        else
        {
            cout<<-1<<endl;
            bol++;
            break;
        }
    }
    //cout<<low<<" "<<high<<endl;
    if(ar[n/2]==2)
    {
        if(n>1)
        {
            if(ar[i-1]==2){if(a>b)high++;else low++;}
            else if(ar[i-1]==1)
                high++;
            else
                low++;
        }
        else
        {
            if(a>b)
                high++;
            else
                low++;
        }
    }
    if(bol==0)
    {
        int sum=low*a+high*b;
        cout<<sum<<endl;
    }

}
// Alhamdulillah

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a ,b,n,ans = 0;
     int s[1001];
     cin>>n>>a>>b;
     for(int i=1; i<=n; i++)
        cin>>s[i];

      int m = n;

     for(int i=1;i<=n/2; i++)
     {
         if(s[i]+s[m]==1)
         {
             cout<<"-1";
             return 0;
         }
         if(s[i]==s[m] && s[m]!=2)
            continue;
         if(s[i]==s[m] && s[i]==2)
         {
              ans+=2*min(a,b);
              m--;
         }

         if(s[i]==1)
            ans+=b;
         else
            ans+=a;
         m--;
     }
    if(n%2)
    {
        if(s[(n/2)+1]==2)
            ans+=min(a,b);
    }

    cout<<ans;

    return 0;
}

#include<bits/stdc++.h>
#define f first
#define s second
#define ll long long
#define u unsigned
#define pb push_back
#define mp make_pair
#define FX fflush(stdin);cout<<fixed,cout.precision(18);
#define iOS ios_base::sync_with_stdio(false);cin.tie(NULL);
#define ones __builtin_popcount()
#define pii pair<int,int>
#define pll pair<long long,long long>
#define dl "\n";
#define all(x) x.begin(), x.end()
const long double eps=0.00000001;
const long long MOD=1e9+7;
const double PI=3.141592653589793238463;
using namespace std;
ll ans;int n,m,k;
string s,t;
main()
{
	FX iOS
	int i,j,aa,b;
	cin>>n>>aa>>b;
	int a[n];
	for(i=0;i<n;++i)cin>>a[i];
	for(j=n-1,i=0;i<n/2;++i,--j)
	{
		if(a[i]==0&&a[j]==1)
			return cout<<-1,0;
		if(a[j]==0&&a[i]==1)
			return cout<<-1,0;
		if(i==j)
		{
			if(a[i]==2)
				ans+=min(aa,b);
			break;
		}
		if(a[i]==0)
			ans+=aa;
		else if(a[i]==1)
			ans+=b;
		else if(a[j]==0)
			ans+=aa;
		else if(a[j]==1)
			ans+=b;
		else
			ans+=min(aa+aa,b+b);
	}
	cout<<ans;
}

#define D478
#ifdef D478
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<vvd> vvvd;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<vvc> vvvc;
typedef pair<int,int> ii;
typedef pair<int,ii> iii;
typedef vector<iii> viii;
typedef vector<ii> vii;
typedef vector<viii> vviii;
typedef vector<vii> vvii;
typedef  stack<int> si;
typedef queue<int> qi;
typedef map<int,int> mii;
typedef queue<ii> qii;
typedef pair<int , double> id;
typedef vector<id> vid;
typedef vector<vid> vvid;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef unsigned long long ull;
typedef pair<double , double > dd;
typedef vector<dd> vdd;
#define inf 100000
#define sup 1e-9
#define pi acos(-1)
#define biginf 1000000000000000000
#define mod (int)(1e9+7)

int main(){
    ios::sync_with_stdio(0);
    int n, a, b; cin >> n >> a >> b;
    vi num(n + 1);
    int ans = 0, mn = min(a, b);
    string str = "";
    for (int k = 0; k < n; ++k) str += '0';
    for (int i = 1; i <= n; ++i) cin >> num[i], str[i - 1] = char(num[i] - 48);
    string s = str; reverse(s.begin(), s.end());
    if(s == str) cout << "0\n";
    else {
        for (int j = 1; j <= n / 2; ++j) {
            if (num[j] == 2 && num[n - j + 1] == 2) ans += (2 * mn), str[j - 1] = str[n - j] = '2';
            else if (num[j] == 2 && num[n - j + 1] == 0) ans += a, str[j - 1] = str[n - j] = '0';
            else if (num[j] == 0 && num[n - j + 1] == 2) ans += a, str[j - 1] = str[n - j] = '0';
            else if (num[j] == 2 && num[n - j + 1] == 1) ans += b, str[j - 1] = str[n - j] = '1';
            else if (num[j] == 1 && num[n - j + 1] == 2) ans += b, str[j - 1] = str[n - j] = '1';
        }
        if (n % 2) {
            if (num[n / 2 + 2] == 2) ans += mn;
            else if (num[n / 2 + 2] == 0) ans += a;
            else ans += b;
        }
        s = str;
        reverse(s.begin(), s.end());
        if (s != str) cout << "-1\n";
        else cout << ans << endl;
    }

    return 0;
}

#endif

/*
	Author: @himkha_100
	Himanshu Khandelwal, NITW
*/
#include<bits/stdc++.h>
#define MOD 1000000007
#define ll long long int
#define s(t) scanf("%d",&t)
#define p(t) printf("%d\n",t)
#define pb push_back
#define f(t) for(int i=0;i<t;i++)
#define fi first
#define se second
#define all(t) t.begin(),t.end()
#define ci(t) cin>>t
#define co(t) cout<<t
#define mii map<int,int>
#define pii pair<int,int>
using namespace std;
struct node{
	int val;
	int pos;
};
bool ac(int x,int y)
{
	return x>y;
}
int main()
{
	int n,a,b;
	cin>>n>>a>>b;
	int c[n];
	f(n)
	{
		cin>>c[i];
	}
	int i=0,j=n-1;
	int ans=0;
	while(i<=j)
	{
		if((c[i]==1&&c[j]==0)||(c[i]==0&&c[j]==1))
		{
			cout<<"-1\n";
			return 0;
		}
		else if(c[i]==1&&c[j]==2)
		{
			ans+=b;
		}
		else if(c[i]==0&&c[j]==2)
		{
			ans+=a;
		}
		else if(c[i]==2&&c[j]==2)
		{
			ans+=min(a,b);
			if(i==j)
			ans+=min(a,b);
		}
		i++;
		j--;
	}
	cout<<ans<<endl;
	return 0;
}

#include<iostream>
#include<cstdio>
using namespace std;

int suit[25];

int main()
{
    int n,b,w,answer;
    answer = 0;
    scanf("%d%d%d",&n,&b,&w);
    for (int i = 0; i < n; i++)
    {
        scanf("%d",&suit[i]);
    }
    for (int i = 0; i < n / 2; i++)
    {
        if (suit[i] == 2)
        {
            if (suit[n - i] == 2)
            {
                answer += 2 * min(b,w);
            }
            else if (suit[n - i] == 1)
            {
                answer += b;
            }
            else
            {
                answer += w;
            }
        }
        else
        {
            if (suit[n - i] == 2)
            {
                answer += suit[i] ? b : w;
            }
            else if (suit[n - i] != suit[i])
            {
                answer = -1;
                break;
            }
        }
    }
    printf("%d\n",answer);
    return 0;
}

#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int main() {
    int n, a, b;
    cin >> n >> a >> b;

    vector<int> c(n);
    for (int i = 0; i < n; ++i) {
        cin >> c[i];
    }

    int p = 0;
    int i = 0, j = n-1;
    while (i < j) {
        if (c[i] != 2 && c[j] != 2 && c[i] != c[j]) {
            p = -1;
            break;
        }
        if (c[i] != c[j]) {
            auto b = (c[i] != 2)? c[i] : c[j];
            p += (b == 0)? a : b;
        }
        ++i;
        --j;
    }
    if (i == j && c[i] == 2) {
        p += min(a, b);
    }

    cout << p << endl;

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n,w,b,ans=0;
	cin>>n>>w>>b;
	int ar[n];
	for(int i=0;i<n;i++)
	{
		cin>>ar[i];
	}
	for(int i=0;i<n;i++)
	{
		if(ar[i]!=ar[n-1-i] and ar[i]!=2 and ar[n-1-i]!=2)
		{
			cout<<-1<<"\n";
			return 0;
		}
	}
	for(int i=0;i<=n/2+1;i++)
	{
		if(ar[i]==0 and ar[n-1-i]==2)
		{
			ans+=w;
		}
		else if(ar[i]==2 and ar[n-1-i]==0)
		{
			ans+=w;
		}
		else if(ar[i]==1 and ar[n-1-i]==2)
		{
			ans+=b;
		}
		else if(ar[i]==2 and ar[n-1-i]==1)
		{
			ans+=b;
		}
		else if(ar[i]==2 and ar[n-1-i]==2)
		{
			ans+=min(b,w);
		}
	}
	cout<<ans<<"\n";
}

#include<bits/stdc++.h>
using namespace std;
int main ()
{
    int n,i,j;
    int a,b;
    cin >> n;
    cin >>a>>b;

    int ara[n];
    for(i=0;i<n;i++)
    {
        cin >> ara[i];
    }
    if(n==1)
    {
        if(ara[0]==2)
        {
            cout <<min(a,b)<<endl;
            return 0;
        }
        else
        {
           cout <<0<<endl;
           return 0;
        }
    }
    int f=1;
    for(i=0,j=n-1;i<(n/2);i++,j--)
    {

        if(ara[i]==ara[j]  || ara[i]==2   || ara[j]==2 )
        {

        }
        else
        {
            f=0;
        }
    }
    int p=n/2;

    if(ara[p]!=2)
    {

         if( ( ara[p]==ara[p-1]  || ara[p]==ara[p+1] )  )

        {
            f=0;
        }

    }
    if(f==0)
    {
        cout <<"-1"<<endl;
       return 0;
    }
  int cost=0;
   j=n-1;
  for(i=0;i<(n/2);i++,j--)
  {
     //cout <<i <<endl;
      if(ara[i]==2)
      {
          if(ara[j]==0) cost +=a  ,ara[i]=0;
          else  cost +=b ,ara[i]=1;

      }
      else if(ara[j]==2)
      {
        if(ara[i]==0 ) cost +=a ,ara[j]=0;
        else cost +=a , ara[j]=1;
      }
  }
  int q=n/2;

  if(n%2==1 && ara[q]==2)

  {
    cost +=min(a,b);
  }

  cout <<cost <<endl;

}

#include <iostream>
using namespace std;

int main() {
	// your code goes here
	int n,c1,c2;
	cin>>n>>c1>>c2;
	int a[n];
	for(int i=0;i<n;i++)
		cin>>a[i];
	int min,f=0,cost=0;
	if(c1<c2)
		min=c1;
	else
		min=c2;
	for(int i=0;i<n/2+1;i++)
	{
		if(a[i]!=a[n-i-1])
		{
			if((a[i]==1&&a[n-i-1]==0)||(a[i]==0&&a[n-i-1]==1))
			{
				f=1;
				break;
			}
			else if(a[i]==1)
				cost+=c2;
			else if(a[i]==0)
				cost+=c1;
			else if(a[n-i-1]==1)
				cost+=c2;
			else if(a[n-i-1]==0)
				cost+=c1;
		}
		else if(a[i]==2&&a[n-i-1]==2)
			cost+=2*min;
	}
	if(f==1)
		cout<<"-1";
	else
		cout<<cost;
	return 0;
}

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

int main()
{
    int n, white, black, cost=0;
    cin>>n>>white>>black;
    int arr[n];
    for(int i=0; i<n; i++)
    {
        cin>>arr[i];
    }
    for(int i=0; ((n%2==0)? i<n/2 : i<=n/2) ; i++)
    {
        if((arr[i]==0 && arr[n-1-i]==1)||(arr[i]==1 && arr[n-1-i]==0)){
            cout<<"-1";
            return 0;
        }
        else{
            if(arr[i]==2 && arr[n-1-i]==2) cost+=2*min(white,black);
            else if((arr[i]==0 && arr[n-1-i]==2)||(arr[i]==2 && arr[n-1-i]==0)) cost+=white;
            else if((arr[i]==1 && arr[n-1-i]==2)||(arr[i]==2 && arr[n-1-i]==1)) cost+=black;
        }
    }
    cout<<cost;
    return 0;
}

#include<iostream>
#include<set>
#include<vector>
#include<string>
#include<queue>
#include<algorithm>
#include<map>
//#include<bits/stdc++.h>
#define MOD int(1e9+7)
#define ll long long
#define N int(1e9+1)
using namespace std;
int main()
{
	int n, a, b, ans = 0;
	cin >> n >> a >> b;
	vector<int>v;
	for (int i = 0; i < n; i++)
	{
		int x;
		cin >> x; v.push_back(x);
	}
	for (int i = 0; i < n / 2; i++)
	{
		if (v[i] != v[n - i - 1])
		{
			if (v[i] == 2 || v[n - i - 1] == 2)
			{
				if (v[n - i - 1] == 0 || v[i] == 0)ans += a;
				else ans += b;

			}
			else
			{
				cout << -1 << endl; exit(0);
			}
		}
	}
	if (n%2==1)
	if (v[n / 2] == 2)ans += min(a, b);
	cout << ans << endl;
}

#include <bits/stdc++.h>
using namespace std;
const int N = 30;
int meh[N];
int main()
{
    int n,a,b;
    cin>>n>>a>>b;
    for(int i=0;i<n;++i)cin>>meh[i];
    int l=0,h=n-1,co=0;
    bool ok = true;
    for(int i=0;i<(n/2);++i)
    {
        if(meh[l]==0&&meh[h]==1||meh[l]==1&&meh[h]==0){ok=false;break;}
        else if(meh[l]==2&&meh[h]==2)co+=min(a,b)*2;
        else if(meh[l]==0&&meh[h]==2)co+=a;
        else if(meh[l]==meh[h])continue;
        else if(meh[l]==1&&meh[h]==2)co+=b;
        else if(meh[l]==2&&meh[h]==1)co+=b;
        else co+=b;
        ++l,--h;
    }
    if(n&1)
    {
        if(meh[n/2]==2)co+=min(a,b);
    }

    if(!ok)cout<<-1;
    else cout<<co;
    return 0;
}

#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
#define mem(a, x) memset(a, x, sizeof(a))
#define X first
#define Y second
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
using namespace std;
typedef vector<int> vi;
typedef long long ll;
typedef pair<int,int> pii;
const double PI = acos(-1.0);
const ll mod=1000000007;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
//------------------------------------head------------------------------------
const int N = 1e5+10;
int main() {
	ll a, b, n, c[N];
	cin >> n >> a >> b;
	rep (i, 0, n) scanf("%lld", &c[i]);
	ll cost = min(a, b);
	ll ans = 0;
	for (int i = 0, j = n-1; i <= n/2;i++,j--) {//cout << "!!";
		if (c[i] == c[j]) {
			if (c[i] == 2) {
				if (i == j) {
					ans += cost;
					continue;
				}
				ans += cost*2;
			}
		} else if (c[i] == 2 && c[j] == 2) {
			ans += cost;
		} else if (c[i] == 2) {
			ans += (c[j]?b:a);
		} else if (c[j] == 2) {
			ans += (c[i]?a:b);
		} else {
			ans = -1;
			break;
		}
	}
	printf("%lld\n", ans);
}

////██╗ ██████╗ ██╗    ██████╗  ██████╗  ██╗ █████╗
////██║██╔═══██╗██║    ╚════██╗██╔═████╗███║██╔══██╗
////██║██║   ██║██║     █████╔╝██║██╔██║╚██║╚██████║
////██║██║   ██║██║    ██╔═══╝ ████╔╝██║ ██║ ╚═══██║
////██║╚██████╔╝██║    ███████╗╚██████╔╝ ██║ █████╔╝
////╚═╝ ╚═════╝ ╚═╝    ╚══════╝ ╚═════╝  ╚═╝ ╚════╝

#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define pb push_back
#define pf push_front
#define fr first
#define sc second
#define mlojins cout.tie(NULL);
#define bzbz cin.tie(NULL);
#define CODER ios_base::sync_with_stdio(0)  ;
#define p_b pop_back
#define p_f pop_front
#define Qulukh
#define Mekh
#define Zohiri_dzd
#define Black_star
using namespace std ;

const ll N = 1e6 + 1;

map <ll , ll> mp , pm ;
deque <ll> v , vc , ve ;
deque <ll> p , pe ;
deque <string> ts , ss ;
deque <float> sd ;
ll a , b , c , d , e , f , cnt , ans , r , n , l;
double q , t , cnt1;
string g , h , w , o , z , m , s ;
char y , u ;
bool re , rt ;
set < ll > st ;
vector<pair < ll , ll > > pr , rp;
int main ()

{
    bzbz
    mlojins
    CODER
    Qulukh
    Mekh
    Zohiri_dzd
    Black_star
    /*freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);*/
    cin >> a >> b >> c ;
    for (int i = 0 ; i < a ; i ++ )
    {
        cin >> d ;
        v.pb(d) ;
    }
    if (a % 2 == 0)
    {
        for (int i = 0 ; i < a / 2 ; i ++ )
        {
            if (v[i] == 2 and v[a - i - 1] == 0)
                ans += b , v[i] = 0 ;
            else if (v[i] == 2 and v[a - i - 1] == 1)
                ans += c , v[i] = 1 ;
            else if (v[i] == 2 and v[a - i - 1] == 2)
                ans += min(b , c) * 2 , v[i] = 1 , v[a - i - 1] = 1 ;
        }
        for (int i = a / 2 ; i < a ; i ++ )
        {
            if (v[i] == 2 and v[a - i - 1] == 0)
                ans += b , v[i] = 0 ;
            else if (v[i] == 2 and v[a - i - 1] == 1)
                ans += c , v[i] = 1 ;
            else if (v[i] == 2 and v[a - i - 1] == 2)
                ans += min(b , c) * 2 , v[i] = 1 , v[a - i - 1] = 1 ;
        }
        for (int i = 0 ; i < a / 2 ; i ++ )
        {
            if (v[i] != v[a - i - 1])
            {
                cout << -1 ;
                return 0;
            }
        }
        cout << ans ;
    }
    else
    {
        for (int i = 0 ; i < a / 2 ; i ++ )
        {
            if ((v[i] == 1 and v[a - i - 1] == 2) or (v[i] == 2 and v[a - i - 1] == 1))
                ans += c , v[a - i - 1] = 1 , v[i] = 1 ;
            else if ((v[i] == 0 and v[a - i - 1] == 2) or (v[i] == 2 and v[a - i - 1] == 0))
                ans += b , v[a - i - 1] = 0 , v[i] = 0 ;
            else if (v[i] == 2 and v[a - i - 1] == 2)
                ans += min (b , c) , v[i] = 3 , v[a - i - 1] = 3 ;
            else if (v[i] != v[a - i - 1])
            {
                cout << -1 ;
                return 0;
            }
        }
        if (v[a / 2] == 2)
            ans += min(b , c) ;
        cout << ans ;
    }
}
///Mmavl studios
///Eco students
///7c is the best

#include<bits/stdc++.h>
using namespace std;
#define vite ios_base::sync_with_stdio(false); cin.tie(NULL);
#define tst int T; cin>>T; while(T--)
#define mod 1000000007
#define MAX 1e9
#define MIN -1e9
#define ll long long int
#define vt vector
#define pb push_back
int main()
{
    vite;
    ll n, a, b;
    cin >> n >> a >> b;
    ll c[n], d = 0,e[2]={a,b};
    for (int i = 0; i < n;i++)
        cin >> c[i];
    for (int i = 0;;i++)
    {
        if(c[i]==2&&c[n-i-1]==2)
        {
            d += 2*(a > b ? b : a);
            if(a>b)
            {
                c[i] = 1;
                c[n-i - 1] = 1;
            }
            else
            {
                c[i] = 0;
                c[n - 1 - i] = 0;
            }
        }
        else
        {
            if(c[i]==2)
            {
                d += e[c[n-i-1]];
                c[i] = c[n - i - 1];
            }
            else if (c[n - i - 1] == 2)
            {   d += e[c[i]];
                c[n - i - 1] = c[i];
            }
        }

        if (n % 2 == 0 && i == n / 2)
            break;
        else if(n%2!=0&&i==n/2+1)
            break;
    }
    for (ll i = 0;;i++)
    {
        if(n==1)
        {
            break;
        }
        if(c[i]!=c[n-1-i])
        {
            d = -1;
            break;
        }
        if (n % 2 == 0 && i == n / 2)
            break;
        else if(n%2!=0&&i==n/2+1)
            break;
    }

        cout << d;

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

void solve()
{
    long n, cost_black, cost_white;
    cin >> n >> cost_white >> cost_black;
    int *arr = new int[n];
    for (int i = 0; i < n; i++)
    {
        cin >> arr[i];
    }
    int tot_cost = 0;
    int i = 0;
    int j = n - 1;
    bool flag = true;
    while (i < j)
    {
        if ((arr[i] == 0 && arr[j] == 0) || (arr[i] == 1 && arr[j] == 1)) // when everything is normal
        {
            i++;
            j--;
        }
        else if (arr[i] == 1 && arr[j] == 0 || arr[i] == 1 && arr[j] == 0) // no swapping can be done.
        {
            tot_cost = -1;
            flag = false;
            break;
        }

        else if (arr[i] == 2 && arr[j] == 1 || arr[i] == 2 && arr[j] == 0 || arr[i] == 0 && arr[j] == 2 || arr[i] == 1 && arr[j] == 2) // if 2 is given
        {
            if (arr[i] == 2)
            {
                arr[i] = arr[j];
                if (arr[j] == 0)
                {
                    tot_cost += cost_white;
                }
                else
                {
                    tot_cost += cost_black;
                }
            }
            else if (arr[j] == 2)
            {
                arr[j] = arr[i];
                if (arr[i] == 0)
                {
                    tot_cost += cost_white;
                }
                else
                {
                    tot_cost += cost_black;
                }
            }
            i++;
            j--;
        }
        else if (arr[i] == 2 && arr[j] == 2)
        {
            if (i == 0 && j == n - 1)
            {
                if (cost_black < cost_white)
                {
                    tot_cost += cost_black;
                    arr[i] = 1;
                    arr[j] = 1;
                }
                else
                {
                    tot_cost += cost_white;
                    arr[i] = 0;
                    arr[j] = 0;
                }
            }
            else
            {
                if (arr[i - 1] && arr[j + 1] == 1)
                {
                    tot_cost += cost_white;
                    arr[i] = 0;
                    arr[j] = 0;
                }
                else
                {
                    tot_cost += cost_black;
                    arr[i] = 1;
                    arr[j] = 1;
                }
            }

            i++;
            j--;
        }
    }

    if (n % 2 != 0 && flag == true)
    {
        if (arr[n / 2] == 2)
        {
            if (cost_black < cost_white)
            {
                tot_cost += cost_black;
            }
            else
            {
                tot_cost += cost_white;
            }
        }
    }

    cout << tot_cost << endl;
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cout << fixed;
    cout << setprecision(10);
    int t = 1;
    for (int i = 0; i < t; i++)
    {
        solve();
    }

    return 0;
}

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

int main(){
	int n,a,b;
	int arr[n];
	cin>>n>>a>>b;
	int i,j,k;

	for(i=0; i<n; i++){
		cin>>arr[i];
	}
	long int count=0;
	int limit;
	if(n%2==0){
		limit = n/2;
	}
	else{
		limit = n/2+1;
	}
	for(i=0; i<limit; i++){
		j=n-1-i;
		if(i==limit-1){
			if(arr[i]==2){
				if(a<b){
					count = count + a;
				}
				else{
					count = count + b;
				}
			}
			else{
				count = count +0;
			}
			continue;
		}
		if(arr[i]==0){
			if(arr[j]==0){
				count = count + 0;
			}
			else if(arr[j]==2){
				count = count + a;
			}
			else{
				count = -1;
				break;
			}
		}
		else if(arr[i]==1){
			if(arr[j]==1){
				count = count + 0;
			}
			else if(arr[j]==2){
				count = count + b;
			}
			else{
				count = -1;
				break;
			}
		}
		else{
			if(arr[i]==2){
				if(arr[i+1]==1){
					count = count + (b*2);
				}
				else{
					count = count + (a*2);
				}
			}
		}

	}

	cout << count << endl;

	return 0;
}

#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
#define mem(a, x) memset(a, x, sizeof(a))
#define X first
#define Y second
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
using namespace std;
typedef vector<int> vi;
typedef long long ll;
typedef pair<int,int> pii;
const double PI = acos(-1.0);
const ll mod=1000000007;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
//------------------------------------head------------------------------------
const int N = 1e5+10;
int main() {
	ll a, b, n, c[N];
	cin >> n >> a >> b;
	rep (i, 0, n) scanf("%lld", &c[i]);
	ll cost = min(a, b);
	ll ans = 0;
	for (int i = 0, j = n-1; i <= n/2;i++,j--) {//cout << "!!";
		cout << i << " " << j <<endl;
		if (c[i] == c[j]) {
			if (c[i] == 2) {
				if (i == j) {
					ans += cost;
					continue;
				}
				ans += cost*2;
			}
		} else if (c[i] == 2 && c[j] == 2) {
			ans += cost*2;
		} else if (c[i] == 2) {
			ans += (c[j]==0?a:b);
		} else if (c[j] == 2) {
			ans += (c[i]==0?a:b);
		} else {
			ans = -1;
			break;
		}
	}
	printf("%lld\n", ans);
}

#include <iostream>
#include <cassert>
using namespace std;
int n;
int cost;
int lft[20],rght[20];
int price[2];
int min(int a,int b) {
 if (a<b)
  return a;
 return b;
}
int main() {
 cin>>n>>price[0]>>price[1];
 for (int i=0;i<n;i++) {
  int v;
  cin>>v;
  lft[i]=v;
  rght[n-i-1]=v;
 }
 for (int i=0;i<n/2;i++) {
  int l=lft[i],r=rght[i];
  int sum=l+r;
  //printf("l = %d, r = %d, cost = %d\n", l, r, cost);
  if (l==2&&r==2) {
   cost+=min(price[0],price[1])*2;
  }
  if (l==r) {
   continue;
  }
  else if (l<2&&r==2) {
   cost+=price[l];
  }
  else if (r<2&&l==2) {
   cost+=price[r];
  }
  else if (sum==1){
   cout<<-1;
   return 0;
  } else {
  	assert(0);
  }
 }
 if (n%2 == 0 && lft[(n+1)/2-1]==2)
  cost+=min(price[0],price[1]);
 cout<<cost;
}

#include<bits/stdc++.h>
#define ii pair <int, int>
using namespace std;

void fastio(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

int main()
{	fastio();
	int n,a,b;
	cin>>n>>a>>b;
	int s[n];
	int i;
	for(i=0;i<n;i++)
		cin>>s[i];

	int cost=0;
	for(i=0;i<=n/2;i++)
	{	if(s[i]==s[n-i-1]&&s[i]==2)
			cost+=min(a,b);
		if(s[i]==s[n-i-1])
			continue;
		if((s[i]==1 && s[n-1-i]==0) || (s[i]==0 &&s[n-i-1]==1))
		{
			cout<<-1; return 0;
		}
		if(s[i]==0 || s[n-i-1]==0)
			cost+=a;
		else if(s[i]==1 || s[n-i-1]==1)
			cost+=b;
	}
	cout<<cost;
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
int opuesto(int x){
	if(x==1)
		return 0;
	return 1;
}

void printv(vector<int> v){
	for (int i = 0; i < v.size(); ++i){
		cout<<v[i]<<" ";
	}
	cout<<endl;
}

int main(){
	int n, a, b, prev;
	cin>>n>>a>>b;
	int ans=0;
	vector<int> v(n);
	vector<int> table(n);
	bool sw=true;

	if(n%2==0){
		cout<<-1;
		return 0;
	}

	for (int i = 0; i < n; ++i){
		cin>>v[i];
		if(v[i]==1 || v[i]==0)
			sw=false;
	}

	if(sw){
		ans+=min(a,b)*((n+1)/2);
		ans+=max(a,b)*(n/2);
	}else{
		for (int i = 0, j=n-1; i < int(n/2); ++i, --j){
			if(v[i]==v[j] && v[i]!=2)
				continue;

			if(v[i]==v[j] && v[i]==2){
				ans+=2*min(a,b);
				continue;
			}

			if(v[i]==1 && v[j]==2 || v[i]==2 && v[j]==1){
				ans+=b;
				continue;
			}

			if(v[i]==0 && v[j]==2 || v[i]==2 && v[j]==0){
				ans+=a;
				continue;
			}
			/*
			if(v[i]==v[j])
				continue;
			*/
			cout<<-1;
			return 0;
		}
		if(v[n/2]==2)
			ans+=min(a,b);
	}
	cout<<ans;
	return 0;
}

/*
2 1 0
1 0 2
2 2 2
*/

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

main()
{
    int n,a,b;
    cin>>n;
    cin>>a>>b;
    vector<int>ar;
    int temp;
    for(int i=0;i<n;i++)
    {
        cin>>temp;
        ar.push_back(temp);
    }
    int flag=0;
    int cost=0;
    for(int i=0, j=n-1;i<=j;i++,j--)
    {
       //cout<<ar[i];
        if(ar[i]==ar[j]&&i!=j)
        {
            continue;

        }
        else
        {
            if(ar[i]*ar[j]==0&&ar[i]!=2&&ar[j]!=2)
            {
                flag=1;
                break;
              //  cout<<ar[i];
            }
            else{
                if(ar[i]==2)
                {
                    if(ar[j]==2)
                    {
                        if(j!=i)cost+=2*min(a,b);
                        else
                        cost+=min(a,b);
                    }
                    else
                    {
                        if(ar[j]==0)
                        cost+=a;
                        else cost+=b;
                    }
                }
                else
                {
                    if(ar[i]==0)
                    cost+=a;
                    else
                    cost+=b;

                }
            }

            }
        }
        cout<<cost;
}

/*
NAME : JITESH RAO
INSTITUTION : DELHI TECHNOLOGICAL UNIVERSITY
year : 2nd
*/
#include <bits/stdc++.h>
using namespace std;
#define in(arr, n) for(int i = 0; i < n; i++) cin >> arr[i]
#define  pii pair<int, int>
#define in1(arr, n) for(int i = 0; i < n; i++) cin >> arr[i].first >> arr[i].second
#define debug(arr, n) for(int i = 0; i < n; i++) cout << arr[i] << " ";
#define debug1(arr, n) for(int i = 0; i < n; i++) cout << arr[i].f << " ";
#define f first
#define s second
#define pll  pair<long, long>
#define mod 1000000007
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL)
#define map unordered_map
#define ll long long
bool compare(int a, int b) {
    return a > b;
}
bool possible(int arr[], int n) {
    int s = 0, e = n - 1;
    while(s < e) {
        if((arr[s] != arr[e]) && (arr[s] != 2 && arr[e] != 2)) {
           // cout << s;
            return 0;
        }
        s++;
        e--;
    }
    return 1;
}
int main() {
    boost;
    int n, a, b;
    cin >> n >> a >> b;
    int arr[101];
    in(arr, n);
    if(possible(arr, n)) {
        int s = 0, e = n - 1;
        int amount = 0;
        while(s < e) {
            if(arr[s] == 2 && arr[e] == 2) {
                amount += min(a, b);
            }
            else if(arr[s] == 2 && arr[e] != 2){
                if(arr[e] == 0) {
                    amount += a;
                }
                else {
                    amount += b;
                }
            }
            else if(arr[s] != 2 && arr[e] == 2){
                if(arr[s] == 1) {
                    amount += b;
                }
                else {
                    amount += a;
                }
            }
            s++;
            e--;
        }
        if(n % 2 != 0)
            amount += min(a,b);
        cout << amount;
    }
    else {
        cout << -1;
    }
	return 0;
}

#include<iostream>
using namespace std;
const int maxn = 20 + 7;
int n, a, b;
int sum = 0;
int seq[maxn];
int main(){
  cin >> n;
  cin >> a >> b;
  int minAB = (a > b ? b : a);
  for(int i = 0;i < n; ++i) cin >> seq[i];
  sum += (seq[(n-1)/2] == 2 ? minAB : 0);
  for(int i = 0,j = n - 1; i < j; ++i, --j){
    if(seq[i] == seq[j] && seq[i] == 2) sum += (minAB * 2);
    if(seq[i] == seq[j] && seq[i] != 2) continue;
    if(seq[i] == 2) sum += (seq[j] == 0 ? a : b);
    if(seq[j] == 2) sum += (seq[i] == 0 ? a : b);
    if(seq[i] != seq[j] && seq[i] != 2 && seq[j] != 2){
      cout << -1;
      exit(0);
    }
  }
  cout << sum;
  return 0;
}

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

int main(){
  int n, a, b; cin >> n >> a >> b;
  int num[n];
  for(int i = 0; i < n; i++){
    cin >> num[i];
  }
  int flag = 1;
  int ans = 0;
  if(n % 2 == 0){
    for(int i = 0; i < n / 2; i++){
            if(num[i] == num[n - 1 - i]){
        if(num[i] == 2) ans += 2 * min(a, b);
        continue;
    }
        if(num[i] != num[n - 1 - i] && (num[i] != 2 && num[n - 1 - i] != 2)) flag = 0;
        else{
            if(num[i] != 2){
                if(num[i] == 0) ans += a;
                else ans += b;
            }
            else if(num[n - 1 - i] != 2){
                if(num[n - 1 - i] == 0) ans += a;
                else ans += b;
            }
        }
    }
  }
  else{
    for(int i = 0; i < (n - 1) / 2; i++){
    if(num[i] == num[n - 1 - i]){
        if(num[i] == 2) ans += 2 * min(a, b);
        continue;
    }
      if(num[i] != num[n - 1 - i] && num[i] != 2 && num[ n - 1 - i] != 2) flag = 0;
       else{
            if(num[i] != 2){
                if(num[i] == 0) ans += a;
                else ans += b;
            }
            else if(num[n - 1 - i] != 2){
                if(num[n - 1 - i] == 0) ans += a;
                else ans += b;
            }
        }
        if(num[(n) / 2] == 2) ans += min(a, b);
    }
  }
  if(flag)
  cout << ans << "\n";
  else
    cout << -1 << "\n";
  return 0;;
}

#include<bits/stdc++.h>
#define io ios_base::sync_with_stdio(false)
using namespace std;

/*****************************************/
int main()
{
   io; cin.tie(0);
   int n(0),a(0),b(0);
   cin>>n>>a>>b;
   vector<int>v;
   for( int i=0; i<n; i++ )
   { int num(0); cin>>num;
     v.push_back(num); }

     int x=v.size();
     long long cost(0);
int f(0);
     for( int i=0; i<=x/2; i++ )
     {
        if( v[i]!=2 && v[x-1-i]!=2  )
        {
           if( v[i]!=v[x-1-i] )
           { cout<<-1<<"\n"; f=1; break; }
        }
        else if( (v[i]==2 || v[x-i-1]==2) )
        {
           if( v[i]==0 )
           cost+=a;
           else if( v[i]==1  )
           cost+=b;
           else if( v[i]==2 )
           cost+=min(a,b);
        }
     }
     if( !f )
     cout<<cost<<"\n";

   return 0;
}

//A. Palindrome Dance
#include<iostream>
#include<vector>

using namespace std;

int isPalindrom(vector<int> v, int a, int b)
{
    int n = v.size();
    int sum = 0;
    for(int i=0; i<=(n/2); i++)
    {
       if(v[i] == v[n-1-i] || v[i]==2 || v[n-1-i]==2)
       {
            if(v[i] == 2 && v[n-1-i]!=2)
            {
                if(v[n-1-i] == 0)
                {
                    sum +=a;
                }else{sum+=b;}
            }
            if(v[i] != 2 && v[n-1-i]==2)
            {
                if(v[i] == 0)
                {
                    sum +=a;
                }else{sum+=b;}
            }
            if(v[i] == 2 && v[n-1-i]==2)
            {
                if(i != (n/2))
                {sum += (2*min(a,b));}else{sum += min(a,b);}
            }
            //if(v[(n/2)] == 2){sum += min(a,b);}
        } else{sum = -1;break;}
    }
    // now for the middle item

    return sum;
}

int main()
{
    vector<int> p;
    int n,a,b;
    cin>>n>>a>>b;
    while(n--)
    {
        int x;
        cin>>x;
        p.push_back(x);
    }

    //cout<<isPalindrom(p, 0, n);

    cout<<isPalindrom(p, a, b)<<endl;
    return 0;
    }

#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>

#define ll long long int

using namespace std;

int main(){
	ll n, a, b, ans = 0;
	cin >> n >> a >> b;
	int c[n];
	for(int i = 1; i <= n; i++){
		cin >> c[i];
	}
	for(int i = 1; i <= n; i++){
		if(i == n - i + 1){
			if(c[i] == 2){
				ans += min(a,b);
			}
			break;
		}
		if(c[i] == 2 && c[n - i + 1] == 2){
			ans = ans + 2 * min(a,b);
			}
		else if(c[i] != c[n - i + 1] && c[i] != 2 && c[n - i + 1 ] != 2 ){
			cout << "-1";
			return 0;
		}
		else if(c[i] != c[n - i + 1]){
			if((c[i] == 0 || c[n - i + 1] == 0) && (c[i] == 2 || c[n - i + 1] == 2)){
				ans += a;
			}
			else if((c[i] == 1 || c[n - i + 1] == 1) && (c[i] == 2 || c[n - i + 1] == 2)){
				ans += b;
		    }
		cout << ans << " ";
		if(i + 1 == n - i + 1){
			break;
		    }
	    }
    }
    if(n == 2){
    	cout << ans / 2;
	}
	else
	cout << ans;
}

/**  The sun will come out tomorrow
        So you gotta hang on till tomorrow  **/

#include <bits/stdc++.h>
#define nl "\n"
#define spc " "
#define bye return 0
typedef long long ll;

using namespace std;

int main()
{
    int n, a, b, i, j, cost = 0, p, q, flag = 1;
    cin >> n >> a >> b;
    int c[n];
    for(i = 0; i < n; i++)
        cin >> c[i];
    int x = n / 2;
    for(i = 0, j = n - 1; i < x; i++, j--)
    {
        /// white  0  a
        /// black  1  b   b < a
        /// nothing  2
        if(c[i] == 2 && c[j] == 2)
            cost += 2*b;
        if(c[i] == 0 && c[j] == 2)
            cost += a;
        if(c[i] == 2 && c[j] == 0)
            cost += a;
        if(c[i] == 1 && c[j] == 2)
            cost += b;
        if(c[i] == 2 && c[j] == 1)
            cost += b;
        if((c[i] != c[j]) && ( c[i] != 2 && c[j] != 2))
        {
            flag = 0;
            break;
        }
    }
    if(n % 2 != 0 && c[n/2] == 2)
        cost += b;
    if(flag)
        cout << cost << nl;
    else
        cout << -1 << nl;

    bye;
}

#include<bits/stdc++.h>
#define ii pair <int, int>
using namespace std;

void fastio(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

int main()
{	fastio();
	int n,a,b;
	cin>>n>>a>>b;
	int s[n];
	int i;
	for(i=0;i<n;i++)
		cin>>s[i];

	int cost=0;
	for(i=0;i<=n/2;i++)
	{	if(s[i]==s[n-i-1]&&s[i]==2)
		{	if(i==n-i-1)
				cost+=min(a,b);
			else
				cost+=2*min(a,b);
			continue;
		}
		if(s[i]==s[n-i-1]&&s[i]!=2)
			continue;
		if((s[i]==1 && s[n-1-i]==0) || (s[i]==0 &&s[n-i-1]==1))
		{
			cout<<-1; return 0;
		}
		if(s[i]==0 || s[n-i-1]==0)
			cost+=a;
		else if(s[i]==1 || s[n-i-1]==1)
			cost+=b;
	}
	cout<<cost;
	return 0;
}

#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(0); cin.tie(0); //End of line
#define GCD(x,y) __gcd((x), (y)) //GCD
#define LCM(x,y) ((x / GCD((x), (y))) * y) //LCM
#define max3(a,b,c) max(a, max(b,c)) //max for 3value
#define min3(a,b,c) min(a, min(b,c)) //min for 3value
using namespace std;
vector <int> v;
vector <int> v2;
//--------------------------------------------UITS
int main()
{
   int n,a,b,x,c=0;
   cin>>n>>a>>b;
   for(int i=0;i<n;i++)
   {
       cin>>x;
       v.push_back(x);
   }
   int s=v.size()-1;
   if(s==0)
   {
       cout<<-1<<endl; return 0;
   }
   if(v[0]==0 && v[s]==1) {cout<<"-1\n"; return 0;}
   else if(v[0]==1 && v[s]==0) {cout<<"-1\n"; return 0;}
   else
   {
       for(int i=0;;i++)
       {
           if(i==s) break;
           else if(i==s-i && v[i]==2)
           {
                c+=min(a,b);
                break;
           }
           else if(i==s-i && (v[i]==0 || v[i]==1))
           {
                break;
           }
           else if(v[i]==v[s-i] && v[i]==2)
           {
               c+=min(a,b);
               c+=min(a,b);
           }
           else if((v[i]==0 && v[s-i]==2) || (v[i]==2 && v[s-i]==0))
          {
                c+=a;
          }
           else if((v[i]==1 && v[s-i]==2) || (v[i]==2 && v[s-i]==1))
          {
                c+=b;
          }
       }
   }
   cout<<c<<endl;

   return 0;
}

#define _CRT_SECURE_NO_WARNINGS
#include <stdlib.h>
#include <stdio.h>
#include <iostream>
#include <math.h>
#include <map>
#include <set>
#include <stack>
#include <vector>
#include <time.h>
#include <random>
#include <algorithm>
#include <string>
#include <string.h>
#include <queue>
#include <deque>
#include <functional>
#include <cctype>
#include <list>
#include <queue>
#include <unordered_set>
#include <unordered_map>

using namespace std;

#define ll long long

int arr[100];

int main() {
  int n, a, b;
  cin >> n >> a >> b;

  for (int i = 0; i < n; i++) {
      cin >> arr[i];
  }

  int res = 0;
  for (int i = 0; i < n; i++) {
        if (arr[i] == 0) {
          if (arr[n - i - 1] == 2) {
              arr[n - i - 1] = 0;
              res += a;
          }
        } else if (arr[i] == 1) {
            if (arr[n - i - 1] == 2) {
                arr[n - i - 1] = 1;
                res += b;
            }
        }
  }

  for (int i = 0; i < n; i++) {
      if (arr[i] != arr[n - i - 1]) {
          cout << -1;
          return 0;
        } else if (i != (n - i - 1) && arr[i] == arr[n - i - 1] && arr[i] == 2) {
          res += min(a, b) * 2;
        }
  }

  if (n % 2 && arr[n / 2 + 1]) {
      res += min(a, b);
    }

  cout << res;
}

#include<iostream>
using namespace std;

int Kiemtra(int n,int a,int b,int s[]){
    int Count=0;
    if((s[0]==0 && s[n-1]==1) || (s[0]==1 && s[n-1]==0) || (s[0]==1 && s[1]==1))return -1;
    else if(s[0]==2 && s[n-1]==2)
        Count+=2*b;
    else if(s[0]!=s[n-1]){
        Count+=b;
        if(s[0]>s[n-1]) s[0]=s[n-1];
        else s[n-1]=s[0];
    }
    if(s[0] == s[n-1]){
            for(int i=1;i<n-1;i++)
                if(s[i]!=1) Count+=a;
        return Count;
    }
}
int main(){
    int n,a,b;
    cin>>n>>a>>b;
    int s[n];
    for(int i=0;i<n;i++){
        cin>>s[i];
    }
    cout<<Kiemtra(n,a,b,s);
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,a,b,sum=0,k;
	cin>>n>>a>>b;
	int array[n];
	for(int i=0;i<n;i++)
		cin>>array[i];
	(n&1)?k=n/2+1:k=n/2;
	for(int i=0;i<k;i++)
	{
		if((array[i]==1 && array[n-1-i]==0) || (array[i]==0 && array[n-1-i]==1))
		{
			cout<<-1;
		    return 0;
		}
		else if((array[i]==1 and array[n-1-i]==2) ||(array[i]==2 and array[n-1-i]==1))
		sum+=b;
	    else if((array[i]==0 and array[n-1-i]==2) || (array[i]==2 and array[n-1-i]==0))
	    sum+=a;
	    else if(array[i]==2 and array[n-1-i]==2)
	    sum+=min(a,b);
	}
	if(k==n/2+1 and array[k]==2)
		 sum+=min(a,b);
		cout<<sum;

}

#include <iostream>
using namespace std;

int main() {
    long a,b,n;
    cin>>n>>a>>b;
    long m[n];
    for(long i=0;i<n;i++)
    cin>>m[i];
    long mid=n/2;
    long i=0,s=0,flag=0;

    for(i=0;i<=mid;i++)
    {
        if(m[i] != m[n-1-i])
        {
             flag=-1;
            break;
        }
        else
        {
        if(m[i] == 2 || m[n-1-i] == 2)
        {
            if(m[n-1-i] == 2 && m[i] != 2 )
            {
                if(m[i] == 1)
                {
                    s=s+b;
                }
                else
                {
                    s=s+a;
                }
            }
            else if(m[i] == 2 && m[n-i-1] != 2 )
            {
                if(m[n-i-1] == 1)
                {
                    s=s+b;
                }
                else
                {
                    s=s+a;
                }
            }
            else
            {
                if(a>=b)
                s=s+b;
                else
                s+=a;
            }
        }
        }
    }

    if(flag==-1)
    printf("-1");
    else
    printf("%ld",s);
}

#ifdef WIN32
#include "..\\stdc++.h"
#else
#include <bits/stdc++.h>
#endif

typedef long long ll;

using namespace std;

int main() {
#ifdef WIN32
	ifstream in("in.txt");
	streambuf *cinbuf = cin.rdbuf();
	cin.rdbuf(in.rdbuf());
#endif
	ll middel = -1;
	ll c, wp, bp;

	cin >> c >> wp >> bp;
	ll ins;
	vector<ll> mms;
	ll result = 0;
	for (ll i = 0; i < c; ++i) {
		cin >> ins;
		mms.push_back(ins);
	}

	for (ll i = 0; i < c/2; ++i) {
		ll first = *mms.begin();
		mms.erase(mms.begin());
		ll last = *(mms.end() - 1);
		mms.pop_back();

		if (first != last) {
			vector<ll>::iterator it = find(mms.begin(), mms.end(), first);
			if (it == mms.end()) {
				it = find(mms.begin(), mms.end(), last);
				if (it == mms.end()) {
					cout << -1;
					return 0;
				}
				if (middel != -1) {
					cout << -1;
					return 0;
				}
				middel = first;
				if (first == 0) {
					result += wp;
				}
				if (first != 0) {
					result += bp;
				}
				if (*it == 0) {
					result += wp;
				}
				if (*it != 0) {
					result += bp;
				}
				*it = first;
			}
			else {
				if (last == 0) {
					result += wp;
				}
				if (last != 0) {
					result += bp;
				}
				if (*it == 0) {
					result += wp;
				}
				if (*it != 0) {
					result += bp;
				}
				*it = last;
			}

		}
	}

	cout << result;
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define rkc ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
#define fl(i,a,b) for(ll i=a;i<b;i++)
#define rfl(i,a,b) for(ll i=a;i>b;i--)
#define pb push_back
#define mp make_pair
#define test ll t;cin>>t;while(t--)
#define lld long double
const ll M = 1e9 + 7;
const double pi  =3.141592653589793238463;

int main()
{
    rkc;
    ll n,a1,b,c=1,ans=0;
    cin>>n>>a1>>b;
    ll a[n];
    fl(i,0,n)cin>>a[i];
    /*if(n%2==0)
    {
        fl(i,0,n)
        if(a[i]==0)
        c0++;
        else if(a[i]==1)
        c1++;
        else
        c2++;
        if(c!=n)
        cout<<-1;
        else
        cout<<0;
    }
    else
    {*/
        fl(i,0,(n+1)/2)
        {
            if(a[i]==a[n-1-i])
            {if(a[i]==2)c++;
            else continue;}
            else
            {
                if(a[i]==0&&a[n-1-i]==1||a[n-1-i]==0&&a[i]==1)
                {
                    cout<<-1;
                    return 0;
                }
                else if(a[i]==0&&a[n-1-i]==2||a[i]==2&&a[n-1-i]==0)
                ans+=a1;
                else
                ans+=b;
            }
        }
        if(n%2!=0){
        if(ans==0&&(a[n/2]==0||a[n/2]==1))
        cout<<0;
        else if(ans==0&&a[n/2]==2)
        cout<<min(a1,b);
        else
        cout<<ans+min(a1,b);}
        else {if(c==n/2)cout<<min(n*a1,n*b);
        else cout<<ans;}
        //else cout<<-1;
    //}
}

#include<stdio.h>
#include<algorithm>
using namespace std;
int ai[1005];
int bi[1005];
int main()
{
    int n,a,b;
    scanf("%d %d %d",&n,&a,&b);
    int cost = min(a,b);
    for(int i=0;i<n;i++){
        scanf("%d",&ai[i]);
    }
    int sum = 0,ant = n/2,flag = 0;
    for(int i=0;i<=ant;i++)
    {
        if(ai[i]==1&&ai[n-i-1]==0){
            flag = 1;
        }
        else if(ai[i]==0&&ai[n-i-1]==1){
            flag = 1;
        }
        else if(ai[i]==2&&(ai[n-i-1]==1||ai[n-i-1]==0||ai[n-i-1]==2))
        {
            if(ai[n-i-1]==0)
                sum = sum + a;
            else if(ai[n-i-1]==1)
                sum +=b;
            else
                sum += cost;
        }
        else if(ai[i]==1&&ai[n-i-1]==2){
            sum+=b;
        }
        else if(ai[i]==0&&ai[n-i-1]==2){
            sum+=a;
        }
       // printf("%d %d\n",i,n-i-1);
    }
    if(flag == 0)
        printf("%d\n",sum);
    else
        printf("-1\n");
    return 0;
}
/*
8
3
3 2
8 -3
3 -2
*/

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

int main() {
	int n,a,b;
	int count=0,cost=0;
	cin>>n>>a>>b;
	int ar[n];
	for(int i=0;i<n;i++)
	{
	    cin>>ar[i];
	}
	for(int i=0;i<n;i++)
	{
	    if(ar[i]==ar[n-i-1])
	    {
	        if(ar[i]==2)
	        {
	            if(min(a,b)==a)
	            {
	                ar[i]=0;
	                ar[n-i-1]=0;
	                cost=cost+ (2*min(a,b));
	            }
	            else if(min(a,b)==b)
	            {
	               ar[i]=1;
	               ar[n-i-1]=1;
	               cost=cost+ (2*min(a,b));
	            }
	            //ar[i]=min(a,b);
	            //ar[n-i-1]=min(a,b);
	            /*if(ar[i]==ar[n-i-1])
	            {
	                cost=cost+min(a,b);
	            }
	            else
	            {
	               cost=cost+min(a,b)+min(a,b);
	            }*/
	        }
	    }
	    else if(ar[i]==1 && ar[n-i-1]==2)
	    {
	        ar[n-i-1]=1;
	        cost=cost+b;
	    }
	    else if(ar[i]==0 && ar[n-i-1]==2)
	    {
	        ar[n-i-1]=0;
	        cost=cost+a;
	    }
	    else if(ar[n-i-1]==1 && ar[i]==2)
	    {
	        ar[i]=1;
	        cost=cost+b;
	    }
	    else if(ar[n-i-1]==0 && ar[i]==2)
	    {
	        ar[i]=0;
	        cost=cost+a;
	    }
	}
	for(int i=0;i<n;i++)
	{
	    if(ar[i]==ar[n-i-1])
	    {
	        count++;
	    }
	    else
	    {
	        break;
	    }
	}
	//cout<<count<<endl;
	if(count==n)
	{
	    cout<<cost;
	}
	else
	{
	    cout<<"-1";
	}
	return 0;
}

#include <iostream>
#include <algorithm>
using namespace std;
int dancers[20];

int main(){
	int dancer_amount, wh_price, bl_price, half_d;
	cin>> dancer_amount>> wh_price>> bl_price;
	half_d = dancer_amount / 2;
	long long summ = 0;
	for (int i = 0; i < dancer_amount; i++) {
		cin >> dancers[i];
	}
	for (int i = 0; i < half_d; i++) {
		if (
			(dancers[i] != dancers[dancer_amount - i - 1]) &&
			(dancers[i] != 2 && dancers[dancer_amount - i - 1] != 2)
		) {
			cout << -1;
			return 0;
		}
		if ( (dancers[i] == dancers[dancer_amount - i - 1]) && (dancers[i] != 2 ) )
			continue;
		if (
			(dancers[i] == dancers[dancer_amount - i - 1]) &&
			(dancers[i] == 2)
		){
			summ+= min(wh_price, bl_price);

		} else {
			if (dancers[i] == 1 || dancers[dancer_amount - i - 1] == 1)
				summ += bl_price;
			if (dancers[i] == 0 || dancers[dancer_amount - i - 1] == 0)
				summ += wh_price;
			}
		}
	if(dancer_amount %2 != 0 && dancers[ dancer_amount / 2 ] == 2)
		summ += min(wh_price, bl_price);
	cout << summ;
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
const int N=20;
int n,a,b,x[N+10],wyn;

void fail(){
   cout<<"-1";
   exit(0);
}
int main()
{
   ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
   cin>>n>>a>>b;
   for(int i=0; i<n; ++i){
      cin>>x[i];
   }
   int l=0,p=n-1;
   while(l<p){
      if(x[l]==x[p] && x[l]==2){
         wyn+=min(a,b);
      }
      else if(x[l]!=x[p] && x[l]!=2 && x[p]!=2){
         fail();
      }
      else if(x[l]!=x[p] && x[l]==2){
         if(x[p]==0)wyn+=a;
         else wyn+=b;
      }
      else if(x[l]!=x[p] && x[p]==2){
         if(x[l]==0)wyn+=a;
         else wyn+=b;
      }
      l++;
      p--;
   }
   if(l==p){
      if(x[l]==2)wyn+=min(a,b);
   }
   cout<<wyn;
}

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define m1 make_pair
//#define ll int64_t
//int dp[5000+1][5000+1];
//dp[1][1]=0;
int main()
{
    int n,a,b;
cin>>n>>a>>b;
int mn=min(a,b);
int s[n+1];int cost=0;int z=1;
for(int i=1;i<=n;i++)
{
    cin>>s[i];
}
for(int i=1;i<=ceil((double)n/2);i++)
{
    if(s[i]==2&&s[n-i+1]==2)
    {
        cost+=mn;
    }
    else if(s[i]==0&&s[n-i+1]==2)
    {
        cost+=a;
    }
    else if(s[i]==1&&s[n-i+1]==2)
    cost+=b;
    else if(s[i]!=s[n-i+1])
    {
        z=0;
        break;
    }
}
if(z)
cout<<cost;
else
cout<<"-1";
}

#include<bits/stdc++.h>
#define ve vector
#define pb push_back
using namespace std;

class solve
{
	int n;
public:
	solve()
	{
		cin>>n;
		ve<int> v(n);
		for(auto &a:v)
			cin>>a;
		long long ans=0;
		sort(v.begin(),v.end());
		for(int i=0;i<n-1;i++)
			ans += (v[i+1]-v[i]-1);
		cout<<ans<<endl;
	}
};
int main()
{
	solve s;
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
int x,y;
int main()
{
  int arr[100000];
  int a,bl,wh,c,d=0,n,sum=0;
  cin>>n>>wh>>bl;
  if(wh>bl)x=bl;
  else x=wh;
  for(int i=1; i<=n; i++){
    cin>>arr[i];
  }
  for(int i=1,j=n; i<=n/2; i++, j--){
    if(arr[i]==1&&arr[j]==0){
      cout<<"-1"<<endl;
      return 0;
    }
    else if(arr[i]==0&&arr[j]==1){
      cout<<"-1"<<endl;
      return 0;
    }
    else if((arr[i]==0&&arr[j]==2)||(arr[i]==2&&arr[j]==0)){
      sum+=wh;
      //cout<<sum<<endl;
    }
    else if((arr[i]==1&&arr[j]==2)||(arr[i]==2&&arr[j]==1)){
      sum+=bl;
    }
    else if(arr[i]==2&&arr[j]==2&&i!=j)sum+=x*2;
    if(n%2!=0&&arr[(n/2)+1]==2)d=x;
    //cout<<sum<<endl;
  }
  cout<<sum+d<<endl;
  return 0;
}

// Jakub Oskwarek 1E
// Problem: tpa
#include <iostream>
#include <cmath>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    int dancers[1000] {};
    int n;
    int prices[2];
    cin >> n >> prices[0] >> prices[1];
    for(int i = 0; i < n; i++)
    {
        cin >> dancers[i];
    }
    int i = 0, j = n - 1;
    int total_price = 0;
    while(i <= j)
    {
        int without_suit_cnt = (dancers[i] == 2 ? 1 : 0) + (dancers[j] == 2 ? 1 : 0);
        switch(without_suit_cnt)
        {
            case 0:
                if(dancers[i] != dancers[j])
                {
                    cout << "NIE" << endl;
                    return 0;
                }
                break;
            case 1:
                if(dancers[i] == 2)
                {
                    total_price += prices[dancers[j]];
                }
                else
                {
                    total_price += prices[dancers[i]];
                }
                break;
            case 2:
                int suit_price = min(prices[0], prices[1]);
                total_price += suit_price;
                if(i != j)
                {
                    total_price += suit_price;
                }
                break;
        }
        i++;
        j--;
    }
    cout << total_price << endl;
    return 0;
}

#include <iostream>

using namespace std;

int n,a,b;
int c[25];

void doit(){
	cin>>n>>a>>b;
	for(int i=0;i<n;i++)
		cin>>c[i];
	bool abl = true;
	long long cost =0;
	for(int i=0;i<n/2;i++){
		if(c[i] == 2 and c[n-i-1]==2)
			cost+=min(a,b);
		else if(c[i]!=c[n-i-1]){
			if(c[i]!= 2 and c[n-1-i]!=2)
				abl = false;
			if(c[i]!= 2){
				if(c[n-1-i]==0)
					cost+=a;
				else
					cost+=b;
			}
			if(c[n-1-i]!=2){
				if(c[i]==0)
					cost+=a;
				else
					cost+=b;

			}

		}
	}
	if(!abl)
		cout<<-1<<endl;
	else
		cout<<cost<<endl;
}

int main(){
	doit();
	return 0;
}

#include<bits/stdc++.h>
#include<vector>
#include<map>
typedef long long int ll;
typedef unsigned long long int ull;
#define boost ios_base ::sync_with_stdio(0); cin.tie(0);
#define m_p make_pair
#define mod 1000000007
#define ma(m,n) max(m,n)
#define mi(m,n) min(m,n)
#define g1(n) cin>>n
#define g2(n,m) cin>>n>>m
#define o1(n) cout<<n
#define o2(n,m) cout<<n<<m
#define pi 3.14159265358979323846
#define mp make_pair
#define ff first
#define ss second
#define sol(i,a,b) for(ll i=a;i<b;i++)
#define rsol(i,a) for(ll i=a;i>=0;i--)
#define EPSILON 1e-9
#define len(s) s.length()
#define sp cout<<endl
#define pb push_back
using namespace std;

int main()
{
    ll n,a,b;cin>>n>>a>>b;
    ll d[n],ans=0;
    sol(i,0,n) cin>>d[i];
    sol(i,0,n/2){
       // cout<<i<<" "<<n-i-1<<endl;
        if(d[i]==0){
            if(d[n-i-1]==2) ans+=a;
            else if(d[n-i-1]==1) {
                cout<<-1;
                return 0;
            }
        }
        else if(d[i]==1){
            if(d[n-i-1]==2) ans+=b;
            else if(d[n-i-1]==0) {
                cout<<-1;
                return 0;
            }
        }
         if(d[i]==2){
            if(d[n-i-1]==0) ans+=a;
            else if(d[n-i-1]==1) ans+=b;
            else if(d[n-i-1]==2) ans+=2*min(a,b);
        }
        cout<<ans<<endl;
    }
    if(n%2==0) cout<<ans;
    else {
        if(d[n/2]==2) cout<<ans+1;
        else cout<<ans;
    }
}

#include <bits/stdc++.h>
#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define pf push_front
#define ll long long
using namespace std;

void TxtRead()
{
    freopen("input.txt","r", stdin);
    freopen("output.txt","w", stdout);
}
const int N = 1e5+5;
const int INF = 2e6;
const ll MOD = 1e9 + 7;

int n;
int ans, cost[2];
char a[25];
bool noAns;

int main()

{
    //TxtRead();
    //ios_base::sync_with_stdio(false);

    scanf("%d %d %d", &n, &cost[0], &cost[1]);
    int mn=min(cost[0], cost[1]);
    for(int i=0; i<n; i++){
        getchar();
        a[i]=getchar()-'0';
    }

    for(int i=0; i<n; i++){
        char other= a[n-i-1];
        if(a[i] == 2){
            if(other==2) ans+=mn;
            else ans += cost[other];
        }
        else if(a[i]!=other) noAns=true;
    }
    if(noAns) printf("-1");
    else printf("%d", ans);
}

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

int main()
{
	int n,a,b;
	cin>>n>>a>>b;

	int colors[n];

	for(int n1=0;n1<n;n1++)
	{
		cin>>colors[n1];
	}

	int i=0,j=n-1,ans=0;

	while(i<j)
	{
		if((colors[i]!=colors[j]) && (colors[i]!=2 && colors[j]!=2))
		{
			cout<<"-1";
			return 0;
		}
		if(colors[i]==1)
		{
			if(colors[j]!=2)
			{
				j--;
				continue;
			}
			else
			{
				ans+=b;
				j--;
			}
		}
		if(colors[i]==0)
		{
			if(colors[j]!=2)
			{
				j--;
				continue;
			}
			else
			{
				ans+=a;
				j--;
			}
		}
		if(colors[i]==2)
		{
			if(colors[j]==1)
			{
				j--;
				ans+=b;
			}
			else
			{
				if(colors[j]==0)
				{
					j--;
					ans+=a;
				}
				else
				{
					ans+=min(a,b);
					j--;
				}
			}
		}
		i++;
	}
	cout<<ans;
}

#include<iostream>
#include <vector>
using namespace std;

bool allElementsAreEqual(vector<int> v){
	for(int i=1;i<v.size();i++){
		if(v[i] != v[i-1]){
			return false;
		}
	}
	return true;
}

int prize(vector<int> v,int n,int a,int b){
	if(n%2==0){
		for(int i=0;i<v.size();i++){
			if(v[i] == 2){
			v[i] = 0;
			}
		}
		bool cas0 = allElementsAreEqual(v);
		for(int i=1;i<v.size();i++){
			if(v[i] == 2){
			v[i] = 1;
			}
		}
		bool cas1 = allElementsAreEqual(v);
		if(!cas0 && !cas1){
			return -1;
		} else {
			if(cas0){
				return a*n;
			} else {
				return b*n;
			}
		}
	} else {
		int sum = 0;
		for(int i=0;i<(n/2)+1;i++){
			if(v[i] != 2 && v[n-i-1]!=2){
				if(v[i]!=v[n-i-1])
					return -1;
			} else {
				if(v[i] == 2 && v[n-i-1]==2){
					if(i==(n/2)){
						if(a>b){
							sum+=b;
						} else {
							sum+=a;
						}
					} else {
						if(a>b){
							v[i] = 1;
							sum+=2*b;
						} else {
							sum+=2*a;
						}

					}
				} else {
					if(v[i] == 2){
						if(v[n-i-1] == 0){
							sum+=a;
						} else {
							sum+=b;
						}
					}
					if(v[n-i-1] == 2){
						if(v[i] == 0){
							sum+=a;
						} else {
							sum+=b;
						}
					}
				}
			}
		}
		return sum;
	}
}

int main(){
	int n,a,b;
	vector<int> dancers;
	cin>>n;
	cin>>a;
	cin>>b;
	int temp;
	for(int i=0;i<n;i++){
		cin>>temp;
		dancers.push_back(temp);
	}
	cout<<prize(dancers,n,a,b);
}

#include <iostream>
#include <vector>

using namespace std;

int n,a,b;
vector<int> dancers;

int main(){

    cin >> n >> a >> b;

    int temp;

    for(int i =0; i < n; i++){

        cin >> temp;

        dancers.push_back(temp);
    }

    int half = n/2;

    int cost =0;
    for(int i =0; i < half; i++){

        if(dancers[i] != dancers[dancers.size()-1 -i]){
            if(dancers[i] < 2 && dancers[dancers.size()-1 -i] <2) {
                cout << -1;
                return 0;
            }else if(dancers[i] ==2 ){
                if(dancers[dancers.size()-1 -i] == 0){
                    cost+=a;
                }else{
                    cost+=b;
                }
            }else{
                if(dancers[i] == 0){
                    cost+=a;
                }else{
                    cost+=b;
                }
            }
        }
    }

    if(n %2 != 0){
        if(dancers[half] == 2){
            cost += min(a,b);
        }
    }

    cout << cost << endl;
    return 0;
}

#include<iostream>
using namespace std;
int main(){
    cin.tie(NULL);
    ios_base :: sync_with_stdio(false);
    long long int i,n,white,black;
    cin>>n>>white>>black;
    long long int a[n],cost=0,b=n;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    for(i=0;i<n/2;i++){
        if(a[i]==2 || a[b-1]==2){
            if(a[b-1]==0){
                cost+=white;
            }
            else if(a[b-1]==1){
                cost+=black;
            }
            else if(a[i]==0){
                cost+=white;
            }
            else{
                cost+=black;
            }
        }
        else{
            if(a[i]!=a[b-1]){
                cout<<"-1\n";
                return 0;
            }
        }
        //cout<<cost<<"is the cost\n";
        b--;

    }
    if(n & 1){
            if(a[i]==2)
                cost+=black;
    }
    cout<<cost<<"\n";
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = (int)25;

int a[MAXN];
int main()
{
    int n, w, b;
    scanf("%d %d %d",&n,&w,&b);
    for(int i=1; i<=n; i++)
    {
        scanf("%d",&a[i]);
    }
    bool flag = true;
    int i=1, j=n;
    ll ans = 0;
    while(i<=j)
    {
        if(i==j)
        {
            if(a[i]==2)
            {
                ans += min(w,b);
                break;
            }
            break;
        }
        if(a[i]==0)
        {
            if(a[j]==0)
            {
                i++; j--;
                continue;
            }
            if(a[j]==1)
            {
                flag = false;
                break;
            }
            if(a[j]==2)
            {
                i++; j--;
                ans += w;
                continue;
            }
        }
        if(a[i]==1)
        {
            if(a[j]==0)
            {
                flag = false;
                break;
            }
            if(a[j]==1)
            {
                i++; j--;
                continue;
            }
            if(a[j]==2)
            {
                i++; j--;
                ans += b;
                continue;
            }
        }
        if(a[i]==2)
        {
            if(a[j]==0)
            {
                i++; j--;
                ans += w;
                continue;
            }
            if(a[j]==1)
            {
                i++; j--;
                ans += b;
                continue;
            }
            if(a[j]==2)
            {
                i++; j--;
                ans += min(w,b);
                continue;
            }
        }
    }
    if(flag) printf("%lld\n",ans);
    else printf("-1\n");
    return 0;
}

#include <iostream>
#include <vector>
using namespace std;

int main() {

    int n;
    int cost[3] = {0, 0, 0};
    cin >> n >> cost[0] >> cost[1];
    cost[2] = cost[0] < cost[1] ? cost[0] : cost[1];
    int sum = 0;

    vector<int> d(n);
    for(int i = 0; i < n; i++)
        cin >> d[i];

    int i = 0;
    int j = d.size() - 1;

    for(i, j; i <= j; i++, j--) {
        if(d[i] == 2 || d[j] == 2) {
            if(i == j) sum += cost[2] * 2;
            else if(d[i] == 2 && d[j] == 2) sum += cost[2] * 2;
            else if(d[i] == 2) sum += cost[d[j]]; // d[j] se resuelve al índice que quiero!!
            else if(d[j] == 2) sum += cost[d[i]]; // "
        }
        else if(d[i] == d[j])
            ;
        else {
            cout << -1 << endl;
            return 0;
        }
    }
    cout << sum << endl;
    return 0;
}

#include<iostream>
using namespace std;

int Kiemtra(int n,int a,int b,int s[]){
    int Count=0;
    if((s[0]==0 && s[n-1]==1) || (s[0]==1 && s[n-1]==0) || (s[0]==1 && s[n-1]==1))return -1;
    else if(s[0]==2 && s[n-1]==2)
        Count+=2*b;
    else if(s[0]!=s[n-1]){
        Count+=b;
        if(s[0]>s[n-1]) s[0]=s[n-1];
        else s[n-1]=s[0];
    }
    if(s[0] == s[n-1]){
            for(int i=1;i<n-1;i++)
                if(s[i]!=1) Count+=a;
        return Count;
    }
}
int main(){
    int n,a,b;
    cin>>n>>a>>b;
    int s[n];
    for(int i=0;i<n;i++){
        cin>>s[i];
    }
    cout<<Kiemtra(n,a,b,s);
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,a,b,i;
    int rs=0;
    cin>>n>>a>>b;
    // dancer white black
    int dancers[n];
    for(i=0;i<n;i++)
        cin>>dancers[i];
    for(i=0;i<n/2;i++)
    {
        if(dancers[i]!=dancers[n-i-1] && dancers[i]!=2 && dancers[n-1-i]!=2)
        {
            cout<<-1;
            return 0;
        }
        if(dancers[i]!=dancers[n-i-1])
        {
                if(i%2==0)
                    rs+=a;
                else
                    rs+=b;
        }
    }
    if(dancers[n/2]==2)
        rs+=(a>b)?b:a;
    cout<<rs;
    return 0;
}

/**  The sun will come out tomorrow
        So you gotta hang on till tomorrow  **/

#include <bits/stdc++.h>
#define nl "\n"
#define spc " "
#define bye return 0
typedef long long ll;

using namespace std;

int main()
{
    int n, a, b, i, j, cost = 0, p, q, flag = 1;
    cin >> n >> a >> b;
    int c[n];
    for(i = 0; i < n; i++)
        cin >> c[i];
    int x = n / 2;
    for(i = 0, j = n - 1; i < x; i++, j--)
    {
        /// white  0  a
        /// black  1  b   b < a
        /// nothing  2
        if(c[i] == 2 && c[j] == 2)
            cost += 2*min(a, b);
        if(c[i] == 0 && c[j] == 2)
            cost += a;
        if(c[i] == 2 && c[j] == 0)
            cost += a;
        if(c[i] == 1 && c[j] == 2)
            cost += b;
        if(c[i] == 2 && c[j] == 1)
            cost += b;
        if((c[i] != c[j]) && ( c[i] != 2 && c[j] != 2))
        {
            flag = 0;
            break;
        }
    }
    if(n % 2 != 0 && c[n/2] == 2)
        cost += b;
    if(flag)
        cout << cost << nl;
    else
        cout << -1 << nl;

    bye;
}