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.


-----Input-----

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.


-----Output-----

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.


-----Examples-----
Input
5 100 1
0 1 2 1 2

Output
101

Input
3 10 12
1 2 0

Output
-1

Input
3 12 1
0 1 0

Output
0



-----Note-----

In 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.

Difficulty: interview

Starter code:

Solutions:
# import sys
# sys.stdin = open("F:\\Scripts\\input","r")
# sys.stdout = open("F:\\Scripts\\output","w")


MOD = 10**9 + 7
I = lambda:list(map(int,input().split()))

n , a , b = I()
l = I()
cost = 0
m = min(a,b)
for i in range(n//2):
	if l[i] + l[n-i-1] == 1:
		print(-1)
		return
	if l[i] == 2 and l[n - i - 1] == 2:
		cost += 2*m
	elif l[i] == 2 or l[n - i - 1] == 2:
		if l[i] == 1 or l[n - i - 1] == 1:
			cost += b
		else:
			cost += a
if n%2 and l[n//2] == 2:
	cost += m
print(cost)

def __starting_point():
    n, a, b = list(map(int, input().split()))
    prices = [a, b]
    colors = list(map(int, input().split()))
    result = 0
    for i in range(n // 2):
        j = n - 1 - i
        if colors[i] != colors[j] and colors[i] != 2 and colors[j] != 2:
            print(-1)
            return
        if colors[i] == colors[j] == 2:
            result += 2 * min(prices)
        elif colors[i] == 2:
            result += prices[colors[j]]
        elif colors[j] == 2:
            result += prices[colors[i]]
    if n & 1 and colors[n // 2] == 2:
        result += min(prices)
    print(result)

__starting_point()

n, a, b = map(int, input().split())
A = list(map(int, input().split()))
B = A[::-1]
cheapest = min(a, b)
cost = 0
bad = False
for i in range(n):
    if A[i] != B[i]:
        if A[i] != 2 and B[i] != 2:
            bad = True
        elif A[i] == 2:
            if B[i] == 0:
                cost += a
            else:
                cost += b
    else:
        if A[i] == 2:
            cost += cheapest
if bad:
    print(-1)
else:
    print(cost)

n,a,b=map(int,input().strip().split())
l=list(map(int,input().strip().split()))
c=min(a,b)
ans=0
for i in range(n//2):
    if l[i]!=2 and l[n-1-i]!=2 and l[i]!=l[n-1-i]:
        print (-1)
        return
    if l[i]==2 and l[n-1-i]==0:
        ans=ans+a
        continue
    if l[i]==2 and l[n-1-i]==1:
        ans=ans+b
        continue
    if l[i]==0 and l[n-1-i]==2:
        ans=ans+a
        continue
    if l[i]==1 and l[n-1-i]==2:
        ans=ans+b
        continue
    if l[i]==2 and l[n-1-i]==2:
        ans=ans+2*c
        continue
if (n%2==1 and l[n//2]==2):
    ans=ans+c
print (ans)

n, w, b = map(int, input().split())
a = list(map(int, input().split()))
ans = 0
for i in range(n//2):
    if a[i] == 1:
        if a[n-1-i] == 2:
            ans += b
        elif a[n-1-i] == 0:
            print(-1)
            return
    elif a[i] == 0:
        if a[n-1-i] == 2:
            ans += w
        elif a[n-1-i] == 1:
            print(-1)
            return
    else:
        if a[n-1-i] == 1:
            ans += b
        elif a[n-1-i] == 0:
            ans += w
        else:
            ans += 2*(min(w, b))
if n%2 and a[n//2] == 2:
    ans += min(w, b)
print(ans)

n, a, b = map(int, input().split())
dancers = list(map(int, input().split()))
ans = 0
real = True
for i in range(n):
    if dancers[i] == 2:
        if dancers[n - i - 1] == 2:
            ans += min(a, b)
        elif dancers[n - i - 1] == 0:
            ans += a
        else:
            ans += b
    elif dancers[i] != dancers[n - i - 1] and dancers[n - i - 1] != 2:
        real = False
        break
if real:
    print(ans)
else:
    print(-1)

n,a,b=list(map(int,input().split()))
arr=list(map(int,input().split()))
flag=0
ans=0
i=0
j=n-1
while(i<j):
    if(arr[i]==2):
        if(arr[j]==2):
            ans+=2*min(a,b)
        else:
            if(arr[j]==0):
                ans+=a
            else:
                ans+=b
    else:
        if(arr[j]==2):
            if(arr[i]==0):
                ans+=a
            else:
                ans+=b
        else:
            if(arr[j]!=arr[i]):
                flag=1
                break
    i+=1
    j-=1
if(n%2!=0):
    if(arr[n//2]==2):
        ans+=min(a,b)
if(flag==1):
    print(-1)
else:
    print(ans)



def __starting_point():
    n, a, b = [int(__) for __ in input().strip().split()]
    arr = [int(__) for __ in input().strip().split()]
    rev = arr[::-1]
    for i in range(n):
        if (arr[i] == 1 and rev[i] == 0) or (arr[i] == 0 and rev[i] == 1):
            print(-1)
            return
    ans = 0
    for i in range(n):
        if arr[i] == 2:
            if rev[i] == 0:
                ans += a
            elif rev[i] == 1:
                ans += b
            else:
                ans += min(a, b)
    print(ans)

__starting_point()

n,a,b=list(map(int,input().split()))
d=list(map(int,input().split()))

low=min(a,b)

ANS=0
check=1
for i in range(n):
    if d[i]==2:
        if d[n-i-1]==0:
            ANS+=a
        elif d[n-i-1]==1:
            ANS+=b
        else:
            ANS+=low

for i in range(n):
    if d[i]==0 and d[n-i-1]==1:
        check=0

if check==0:
    print(-1)
else:
    print(ANS)



n, a, b = map(int, input().split())

cl = list(map(int, input().split()))
ll = [a, b]

ans = 0
l = 0
r = len(cl) - 1
while l < r:
	if cl[l] == 2 and cl[r] == 2:
		ans += 2 * min(a, b)
	elif cl[l] == 2:
		ans += ll[cl[r]]
	elif cl[r] == 2:
		ans += ll[cl[l]]
	elif cl[l] != cl[r]:
		print(-1)
		return
	l += 1
	r -= 1

if l == r:
	if cl[l] == 2:
		ans += min(a, b)

print(ans)


def mi():
	return map(int, input().split())

n,w,b = mi()
a = list(mi())


if w<b:
	mc = 0
else:
	mc = 1
ans = 0
c = [w,b]
for i in range(n//2):
	if a[i]==a[n-1-i]:
		if a[i]==2:
			ans+=2*min(w,b)
	if a[i]!=a[n-1-i]:
		if max(a[i],a[n-1-i])!=2:
			print (-1)
			return
		ans+=c[min(a[i],a[n-1-i])]
if a[n//2]==2 and n%2:
	ans+=min(w,b)
print (ans)

import sys
n,a,b = map(int,sys.stdin.readline().strip().split())
l = list(map(int,input().split()))
for i in range(n//2):
    if((l[i]==0 and l[n-i-1]==1) or (l[i]==1 and l[n-i-1]==0)):
        print(-1)
        return
ans = 0
for i in range(n//2):
    if(l[i]==1):
        if(l[n-i-1]==2):
            ans+=b
            l[n-i-1] = 1
    elif(l[i]==0):
        if(l[n-i-1]==2):
            ans+=a
            l[n-i-1] = 0
    else:
        if(l[n-i-1]==1):
            ans+=b
            l[i] = 1
        elif(l[n-i-1]==0):
            ans+=a
            l[i] = 0
        else:
            if(a<b):
                l[i] = 0
                l[n-i-1] = 0
            else:
                l[i] = 0
                l[n-i-1] = 0
            ans+=2*min(a,b)
for i in l:
    if(not(i==0 or i==1)):
        ans+=min(a,b)
print(ans)

def main():
    n, c1, c2 = list(map(int, input().split()))
    a = [int(i) for i in input().split()]
    ans = 0
    if n % 2 and a[n // 2] == 2:
        ans = min(c1, c2)
    for i in range(n // 2):
        if a[i] == 0 and a[n - 1 - i] == 1 or a[i] == 1 and a[n - 1 - i] == 0:
            print(-1)
            return
        if a[i] == 2 and a[n - 1 - i] == 2:
            ans += 2 * min(c1, c2)
        elif a[i] != 2 and a[n - 1 - i] != 2:
            continue
        elif a[i] == 0 or a[n - 1 - i] == 0:
            ans += c1
        else:
            ans += c2
    print(ans)


main()


n,a,b=map(int,input().split())
c=list(map(int,input().split()))
ans=0
if n%2!=0 and c[n//2]==2:
    ans+=min(a,b)
for i in range(n//2):
    if c[i]==c[n-i-1]:
        if c[i]==2:
            ans+=2*(min(a,b))
    else:
        if c[i]==1 and c[n-i-1]==2 or c[i]==2 and c[n-i-1]==1:
            ans+=b
        elif c[i]==0 and c[n-i-1]==2 or c[i]==2 and c[n-i-1]==0:
            ans+=a
        else:
            print(-1);return()
print(ans)

import sys
f=sys.stdin
out=sys.stdout

n,a,b=map(int,f.readline().rstrip('\r\n').split())
c=list(map(int,f.readline().rstrip('\r\n').split()))
j=n-1
cost,flag=0,0
for i in range(n//2):
	if c[i]==c[j] and c[i]==2:
		cost+=(2*min(a,b))
	elif c[i]!=c[j] and c[i]==2:
		if c[j]==0:
			cost+=a
		else:
			cost+=b
	elif c[i]!=c[j] and c[j]==2:
		if c[i]==0:
			cost+=a
		else:
			cost+=b
	elif c[i]!=c[j]:
		flag=1
		break
	j-=1
if (n&1==1):
	if c[(n//2)]==2:
		cost+=min(a,b)
if(flag==1):
	out.write(str(-1)+"\n")
else:
	out.write(str(cost)+"\n")

n, a, b = list(map(int, input().split()))
arr = list(map(int, input().split()))

sum = 0
for i in range(n // 2):
    nums = sorted((arr[i], arr[-1 - i]))
    if nums[0] == 0 and nums[1] == 1:
        print(-1)
        return
    elif nums[0] == 2 and nums[1] == 2:
        sum += 2 * min(a, b)
    elif nums[0] == 0 and nums[1] == 2:
        sum += a
    elif nums[0] == 1 and nums[1] == 2:
        sum += b

if n % 2 == 1:
    if arr[n // 2] == 2:
        sum += min(a, b)

print(sum)


n, a, b = input().split()
n = int(n)

cost = {}

cost["0"] = int(a)
cost["1"] = int(b) 

aux = min(cost["0"], cost["1"])

nuns = input().split()

resp = 0

for i in range(n):
	if nuns[i]=="2":
		if nuns[-(i+1)]=="2":
			resp += aux
		else:
			resp += cost[nuns[-(i+1)]]
	elif nuns[i]!=nuns[-(i+1)] and  nuns[-(i+1)]!="2":
		resp = -1
		break
		
print(resp)


n, a, b = map(int, input().split())
l = [int(x) for x in input().split()]
res = 0
for i in range(n//2):
    x, y = l[i], l[-1-i]
    if 2 in [x, y]:
        if x == y:
            res += 2 * min(a, b)
        else:
            res += a if min(x, y) == 0 else b
    elif x != y:
        res = -1
        break
if (n % 2 == 1) and (res != -1) and (l[n//2] == 2):
    res += min(a, b)
print(res)

n, a, b = map(int, input().split())
c = list(map(int, input().split()))
m = min(a, b)
cnt = 0

if n % 2 == 1:
    if c[n//2] == 2:
        cnt += m

for i in range(n//2):
    left = c[i]
    right = c[-i-1]
    if ((left == 0) and (right == 1)) or ((left == 1) and (right == 0)):
        cnt = -1
        break
    else:
        if left != right:
            if left == 2:
                if right == 0:
                    cnt += a
                else:
                    cnt += b
            else:
                if left == 0:
                    cnt += a
                else:
                    cnt += b            
        if left == right:
            if left == 2:
                cnt += 2*m

print(cnt)

n, a, b = map(int, input().split())
mas = list(map(int, input().split()))
count = 0
for i in range(n // 2):
    r, l = mas[i], mas[n - i - 1]
    if (mas[i] != mas[n-i-1]) or mas[i] == 2:
        if r != 2 and l != 2:
            print(-1)
            return
        else:
            if r == 2 and l == 2:
                count += min(a, b) * 2
            else:
                if r == 0 or l == 0:
                    count += a
                else:
                    count += b

if n % 2 == 1:
    if mas[n // 2] == 2:
        count += min(a, b)
print(count)

n, a, b = map(int, input().split())
c = list(map(int, input().split()))
ans = 0
for i in range(n // 2):
    if c[i] == 2 and c[n - i - 1] == 2:
        ans += min(a, b) * 2
    elif c[i] == 2:
        if c[n - i - 1] == 0:
            ans += a
        else:
            ans += b
    elif c[n - i - 1] == 2:
        if c[i] == 0:
            ans += a
        else:
            ans += b
    elif c[i] != c[n - i - 1]:
        print(-1)
        break
else:
    if n % 2:
        ans += (c[n // 2] == 2) * min(a, b)
    print(ans)

#!/usr/bin/env python3
n, a, b = list(map(int, input().split()))
p = [a,b,min(a, b)]
c = [int(x) for x in input().split()]
s = 0
d = n // 2
if n % 2:
    s += p[c[d]] if c[d] == 2 else 0
    j = d + 1
else:
    j = d
i = d - 1
while i >= 0:
    if c[i] == c[j]:
        if c[i] == 2: s += 2*p[c[i]]
    elif c[j] == 2: s += p[c[i]]
    elif c[i] == 2: s += p[c[j]]
    else:
        s = -1
        break
    i-=1
    j+=1
print(s)
    


n, a, b = map(int, input().split())
c = list(map(int, input().split()))
i, j = 0, n-1
s = 0
t = True
while i < j:
    if c[i] != c[j] and c[i] != 2 and c[j] != 2:
        t = False
        break
    elif c[i] == 2 and c[j] == 1:
        s += b
        i += 1
        j -= 1
    elif c[i] == 1 and c[j] == 2:
        s += b
        i += 1
        j -= 1        
    elif c[i] == 0 and c[j] == 2:
        s += a
        i += 1
        j -= 1        
    elif c[i] == 2 and c[j] == 0:
        s += a
        i += 1
        j -= 1        
    elif c[i] == 2 and c[j] == 2:
        s += 2*min(a, b)
        i += 1
        j -= 1
    else:
        i += 1
        j -= 1        
if n % 2 == 1:
    if c[n//2] == 2:
        s += min(a, b)
if t:
    print(s)
else:
    print(-1)

n, a, b = map(int, input().split())
c = list(map(int, input().split()))
count = 0
ans = "YES"
for i in range(n // 2):
    if c[i] == 2:
        if c[-(i + 1)] == 2:
            count += min(a, b) * 2
        elif c[-(i + 1)] == 0:
            count += a
        elif c[-(i + 1)] == 1:
            count += b
    elif c[i] == 0:
        if c[-(i + 1)] == 2:
            count += a
        elif c[-(i + 1)] == 0:
            count += 0
        elif c[-(i + 1)] == 1:
            ans = "NO"
            break
    elif c[i] == 1:
        if c[-(i + 1)] == 2:
            count += b
        elif c[-(i + 1)] == 1:
            count += 0
        elif c[-(i + 1)] == 0:
            ans = "NO"
            break
if n % 2 == 1 and c[n // 2] == 2:
    count += min(a, b)
if ans == "NO":
    print(-1)
else:
    print(count)

from sys import stdin, stdout 
from bisect import bisect_left, bisect_right
from collections import defaultdict
import math
from fractions import Fraction as frac
from random import random
cin = stdin.readline
def cout(x):
	stdout.write(str(x)+'\n')
def var(type = int):
    return type(stdin.readline())
def readline(type = int):
    return list(map(type,stdin.readline().split()))
def readlist(type = int):
    return list(map(type,stdin.readline().split()))
def sorted_indexes(arr):
    return sorted(list(range(len(arr))),key=arr.__getitem__)
def printr(arr):
    [stdout.write(str(x)+' ')   for x in arr]
    cout('')
def find_lt(a, x):#'Find rightmost value less than x'
    i = bisect_left(a, x)
    if i:
        return a[i-1]
    raise ValueError
def find_gt(a, x):#'Find leftmost value greater than x'
    i = bisect_right(a, x)
    if i != len(a):
        return a[i]
    raise ValueError
def dist(x,y):
    return math.sqrt(x*x + y*y)
def binary_search(arr, x):
    i = bisect_left(arr, x)
    if i == len(arr) or arr[i] != x:
        return -1
    return i

# ---------------------Template ends-------------sdpt,sdpt131[Sudipta Banik]---------------------

# mp = [0]*201
# ops = [0]*201
# def go(arr,i,j ,dp):
#     if i==j and ops[i] is None:
#         return [mp[i],mp[i]]
#     if i>j:
#         return [0,0]
#     if dp[i][j]:
#         return dp[i][j]
#     mx = -1000000000
#     mn = 1000000000
#     for k in range(i+1,j,2):
#         if ops[k]:
#             left = go(arr,i,k-1,dp)
#             right = go(arr,k+1,j,dp)
#             mx = max(mx,left[0] + right[0])
#             mn = min(mn,left[1] + right[1])
#         else:
#             left = go(arr,i,k-1,dp)
#             right = go(arr,k+1,j,dp)
#             mx = max(mx,left[0] - right[1])
#             mn = min(mn,left[1] - right[0])
#     dp[i][j] = [mx,mn]
#     return [mx,mn]

    
n , a , b = readline(int)
price = [a,b]
arr = readlist(int)
half = n//2
cost = 0
flg = True
for i in range(half):
    if arr[i] == arr[n-1-i] == 2:
        cost += 2*min(a,b)
    elif arr[i] ==2 and arr[n-1-i] <= 1:
        cost += price[arr[n-1-i]]
    elif arr[i] <= 1 and arr[n-1-i] == 2:
        cost += price[arr[i]]
    elif arr[i] != arr[n-1-i]:
        flg = False
        break
if n%2 == 1:
    if arr[half] == 2:
        cost += min(a,b)
if not flg:
    print(-1)
else:
    print(cost)



    









# # def tobit(s):
# #     x = []
# #     for _ in range(3):
# #         x.append(s%2)
# #         s//=2
# #     return x

# def power(x, y, p) :
#     res = 1
#     x = x % p 
#     while (y > 0) :
#         if ((y & 1) == 1) :
#             res = (res * x) % p
#         y = y >> 1
#         x = (x * x) % p
#     return res




# def setCount(x):
#     return bin(x).count('1')

# for _ in range(var()):
    
#     a,b,n = readline()
#     p = 1000000007  
#     diff = abs(a-b)
#     mod  = power(a,n,p)
#     mod += power(b,n,p)
#     print(math.gcd(mod,diff)%p)
    
    
#     # n = var()
#     # # print(bin(n))
#     # if setCount(n)==2:
#     #     print(0)
#     # elif setCount(n)==1:
#     #     if n == 1:
#     #         print(2)
#     #     else:
#     #         print(1)
#     # elif setCount(n)==0:
#     #     print(3)
#     # else:
#     #     lo = n-1
#     #     hi = n+1
#     #     while(lo >= 3):
#     #         if(setCount(lo)==2):
#     #             break
#     #         lo -=1
#     #     while(hi <= 1000):
#     #         if(setCount(hi)==2):
#     #             break
#     #         hi +=1
        
#     #     if (hi - n) < (n - lo):
#     #         print(hi-n)
#     #     else:
#     #         print(n-lo)
        
    





# #     s = cin()
# #     t = cin()
# #     flg = False
# #     for el in range(8):
# #         bits = tobit(el)
# #         ch = []
# #         # printr(bits)
# #         for i in range(3):
# #             if bits[i]==0:
# #                 ch.append(s[i])
# #             else:
# #                 ch.append(t[i])
# #         ch.sort()
# #         if (''.join(ch) == 'bbo'):
# #             flg = True
# #             break
# #     if flg:
# #         print("yes")
# #     else:
# #         print("no")