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: EASY

Solutions:
def check_possibility(i2, l, cw, cb):
	cost = 0
	i = 0
	j = l - 1
	lim = l // 2
	while i <= lim:
		if j < i:
			break
		if i == j:
			if i2[i] == 2:
				if cw > cb:
					cost += cb
				else:
					cost += cw
		elif i2[i] == 2 and i2[j] == 2:
			if cw > cb:
				cost += cb * 2
			else:
				cost += cw * 2
		elif i2[i] != 2 and i2[j] != 2:
			if i2[i] != i2[j]:
				return -1
		elif i2[i] == 2:
			if i2[j] == 0:
				cost += cw
			else:
				cost += cb
		elif i2[j] == 2:
			if i2[i] == 0:
				cost += cw
			else:
				cost += cb
		i += 1
		j -= 1
	return cost

def main():
	input1 = list(map(int, input().split()))
	n = input1[0]
	cost_white = input1[1]
	cost_black = input1[2]
	input2 = list(map(int, input().split()))
	cost = check_possibility(input2, n, cost_white, cost_black)
	print(cost)
main()


(n, *price) = [int(x) for x in input().split()]
ipt = [int(x) for x in input().split()]
slice1 = ipt[:n // 2]
slice2 = ipt[n // 2 + n % 2:]
slice2.reverse()
eq = True
sum = 0
for (i, val) in enumerate(slice1):
	if val != slice2[i] and slice2[i] != 2 and (val != 2):
		eq = False
		break
	elif val == 2 and slice2[i] != 2:
		sum += price[slice2[i]]
	elif val != 2 and slice2[i] == 2:
		sum += price[val]
	elif slice2[i] == val == 2:
		sum += min(price) * 2
if eq:
	if n % 2 == 1 and ipt[n // 2] == 2:
		sum += min(price)
	print(sum)
else:
	print(-1)


(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)


s = input().split()
(n, a, b) = (int(s[0]), int(s[1]), int(s[2]))
s = input().split()
l = [int(s[i]) for i in range(n)]
res = 0
flag = False
if n % 2 == 0:
	l1 = l[:n // 2]
	l2 = l[n // 2:]
else:
	if l[n // 2] == 2:
		res += min(a, b)
	l1 = l[:n // 2]
	l2 = l[n // 2 + 1:]
l2 = l2[-1::-1]
for i in range(len(l1)):
	if l1[i] == 0:
		if l2[i] == 0:
			pass
		elif l2[i] == 1:
			flag = True
		else:
			res += a
	elif l1[i] == 1:
		if l2[i] == 0:
			flag = True
		elif l2[i] == 1:
			pass
		else:
			res += b
	elif l2[i] == 0:
		res += a
	elif l2[i] == 1:
		res += b
	else:
		res += min(a, b) * 2
if flag:
	print('-1')
else:
	print(res)


import sys
(n, w, b) = map(int, sys.stdin.readline().split())
A = list(map(int, sys.stdin.readline().split()))
j = n - 1
test = True
s = 0
for x in range(n // 2 + n % 2):
	if A[x] == A[j - x]:
		if A[x] == 2:
			if x != j - x:
				s = s + 2 * min(w, b)
			else:
				s = s + min(w, b)
	elif A[x] == 2:
		if A[j - x] == 1:
			s = s + b
		else:
			s = s + w
	elif A[j - x] == 2:
		if A[x] == 1:
			s = s + b
		else:
			s = s + w
	else:
		test = False
		break
if test == False:
	print('-1')
else:
	print('%d' % s)


def findMinCost(n, white, black, nums):
	minPrice = 0
	cheapest = min(white, black)
	mid = n // 2
	for i in range(mid):
		if nums[i] == nums[n - i - 1]:
			if nums[i] == 2:
				minPrice += 2 * cheapest
		elif nums[i] == 2:
			minPrice += black if nums[n - i - 1] == 1 else white
		elif nums[n - i - 1] == 2:
			minPrice += black if nums[i] == 1 else white
		else:
			return -1
	if n % 2:
		if nums[mid] == 2:
			minPrice += cheapest
	return minPrice
(n, white, black) = [int(x) for x in input().split(' ')]
nums = [int(x) for x in input().split(' ')]
print(findMinCost(n, white, black, nums))


n1 = list(map(int, input().split(' ')))
n2 = list(map(int, input().split(' ')))
cost = 0
mn = 1 if n1[1] < n1[2] else 2
while 2 in n2:
	ind = n2.index(2)
	index = -1 * (ind - n1[0]) - 1
	if n2[index] == 2:
		n2[index] = mn - 1
		cost += n1[mn] if ind != index else 0
	n2[ind] = n2[index]
	cost += n1[n2[ind] + 1]
if n2 != n2[::-1]:
	print(-1)
else:
	print(cost)


(n, *a) = map(int, input().split())
a += [min(a)]
s = [*map(int, input().split())]
if (0, 1) in zip(s, s[::-1]):
	print(-1)
else:
	print(sum((a[y] for (x, y) in zip(s, s[::-1]) if x > 1)))


(n, a, b) = [int(i) for i in input().split(' ')]
li = [int(i) for i in input().split(' ')]
sum = 0
t = True
if n % 2 == 0:
	j = n // 2 - 1
	m = n // 2
else:
	j = n // 2 - 1
	m = n // 2 + 1
if n % 2 == 1:
	if li[n // 2] == 2:
		sum += min(a, b)
for i in range(m, n):
	if (li[i] != 2 and li[j] != 2) and li[i] != li[j]:
		t = False
		break
	elif li[i] == 2 and li[j] != 2:
		if li[j] == 1:
			sum += b
		else:
			sum += a
	elif li[i] == 2 and li[j] == 2:
		sum += 2 * min(a, b)
	elif li[i] != 2 and li[j] == 2:
		if li[i] == 0:
			sum += a
		else:
			sum += b
	j -= 1
if t:
	print(sum)
else:
	print(-1)


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


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


(n, a, b) = map(int, input().split())
prices = [a, b, min(a, b)]
arr = list(map(int, input().split()))
answer = 0
for i in range(n // 2):
	(l, r) = (arr[i], arr[n - i - 1])
	if l != r and max(l, r) < 2:
		answer = -1
		break
	if l == r and l != 2:
		continue
	if l == 2:
		answer += prices[r]
	if r == 2:
		answer += prices[l]
if answer != -1 and n % 2 and (arr[n // 2] == 2):
	answer += prices[2]
print(answer)


N = [int(x) for x in input().strip().split()]
arr = [int(x) for x in input().strip().split()]
i = 0
j = N[0] - 1
cost = 0
mini = min(N[1], N[2])
while i < j:
	if arr[i] == 2 and arr[j] == 2:
		cost += 2 * mini
	elif arr[i] == 2:
		if arr[j] == 0:
			cost += N[1]
		else:
			cost += N[2]
	elif arr[j] == 2:
		if arr[i] == 0:
			cost += N[1]
		else:
			cost += N[2]
	elif arr[i] != arr[j]:
		cost = -1
		break
	else:
		pass
	i += 1
	j -= 1
if i == j and arr[i] == 2:
	cost += mini
print(cost)


(n, a, b) = map(int, input().split())
c = list(input().split())
i = 0
j = n - 1
minab = min(a, b)
cost = 0
if n % 2 != 0 and c[n // 2] == '2':
	cost += minab
while i < j:
	pair = c[i] + c[j]
	if '2' not in pair:
		if c[i] != c[j]:
			print(-1)
			exit()
	elif '0' in pair:
		cost += a
	elif '1' in pair:
		cost += b
	else:
		cost += 2 * minab
	i += 1
	j -= 1
print(cost)


(n, w, b) = map(int, input().split())
l = [int(x) for x in input().split()]
ans = 0
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):
		ans = -1
		break
	if l[i] == 0 and l[n - i - 1] == 2 or (l[i] == 2 and l[n - i - 1] == 0):
		ans += w
	if l[i] == 1 and l[n - i - 1] == 2 or (l[i] == 2 and l[n - i - 1] == 1):
		ans += b
	if l[i] == 2 and l[n - i - 1] == 2:
		ans += 2 * min(w, b)
if n % 2 != 0 and ans != -1 and (l[n // 2] == 2):
	ans += min(w, b)
print(ans)


(n, white_cost, black_cost) = map(int, input().split())
a = list(map(int, input().split()))
have_ans = True
cheapest_color = 0 if white_cost < black_cost else 1
b = list(a)
for i in range(len(a) // 2 + 1):
	if b[i] == 2:
		if b[-1 - i] == 2:
			b[i] = b[-1 - i] = cheapest_color
		else:
			b[i] = b[-1 - i]
	elif b[-1 - i] == 2:
		b[-1 - i] = b[i]
	elif b[i] != b[-1 - i]:
		have_ans = False
		break
if have_ans:
	cost = 0
	for i in range(len(b)):
		if a[i] != b[i]:
			cost += white_cost if b[i] == 0 else black_cost
	print(cost)
else:
	print(-1)


(suits, white, black) = input().split(' ')
suits = int(suits)
white = int(white)
black = int(black)
distrib = input().split(' ')
for i in range(suits):
	distrib[i] = int(distrib[i])
res = 0
solvable = True
for i in range(suits // 2):
	if distrib[i] == 2 and distrib[-1 * (i + 1)] == 2:
		res += 2 * min(white, black)
	elif (not distrib[i] == 2 or not distrib[-1 * (i + 1)] == 2) and (distrib[i] == 2 or distrib[-1 * (i + 1)] == 2):
		if min(distrib[i], distrib[-1 * (i + 1)]) == 0:
			res += white
		else:
			res += black
	elif (not distrib[i] == 2 or not distrib[-1 * (i + 1)] == 2) and (not distrib[i] == distrib[-1 * (i + 1)]):
		solvable = False
		break
if solvable == True:
	if suits % 2 == 1 and distrib[suits // 2] == 2:
		res += min(white, black)
	print(res)
else:
	print(-1)


(n, w, b) = map(int, input().split())
ip = list(map(int, input().split()))
c = 0
flag = 0
if n % 2 == 0:
	first = []
	second = []
	for i in range(0, int(n / 2)):
		first.append(ip[i])
	for i in range(int(n / 2), n):
		second.append(ip[i])
	second.reverse()
	for i in range(0, int(n / 2)):
		if first[i] + second[i] == 4:
			c = c + 2 * min(w, b)
		elif first[i] + second[i] == 3:
			c = c + b
		elif first[i] + second[i] == 1:
			flag = 1
		elif first[i] + second[i] == 2 and first[i] != 1 and (second[i] != 1):
			c = c + w
else:
	first = []
	second = []
	for i in range(0, int(n / 2)):
		first.append(ip[i])
	for i in range(int(n / 2) + 1, n):
		second.append(ip[i])
	second.reverse()
	for i in range(0, int(n / 2)):
		if first[i] + second[i] == 4:
			c = c + 2 * min(w, b)
		elif first[i] + second[i] == 3:
			c = c + b
		elif first[i] + second[i] == 1:
			flag = 1
		elif first[i] + second[i] == 2 and first[i] != 1 and (second[i] != 1):
			c = c + w
	if ip[int(n / 2)] == 2:
		c = c + min(w, b)
if flag == 1:
	print(-1)
else:
	print(c)


import sys
import math
import bisect
import itertools
import random

def solve(A, c1, c2):
	n = len(A)
	ans = 0
	for i in range((n - 1) // 2 + 1):
		j = n - 1 - i
		if i == j:
			if A[i] == 2:
				ans += min(c1, c2)
		else:
			B = [A[i], A[j]]
			B.sort()
			if B == [0, 0]:
				pass
			elif B == [0, 1]:
				return -1
			elif B == [0, 2]:
				ans += c1
			elif B == [1, 1]:
				pass
			elif B == [1, 2]:
				ans += c2
			elif B == [2, 2]:
				ans += min(c1, c2) * 2
	return ans

def main():
	(n, c1, c2) = map(int, input().split())
	A = list(map(int, input().split()))
	print(solve(A, c1, c2))
main()


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


(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)


def main():
	(n, a, b) = [int(x) for x in input().split()]
	c = [int(x) for x in input().split()]
	price = {0: a, 1: b, 2: 0}
	(i, j) = (0, n - 1)
	total = 0
	min_val = min(a, b)
	while i <= j:
		if i == j:
			if c[i] == 2:
				total += min_val
			break
		if c[i] == c[j]:
			if c[i] == c[j] == 2:
				total += min_val * 2
		elif c[i] == 2 or c[j] == 2:
			total += max(price[c[i]], price[c[j]])
		else:
			print(-1)
			return
		i += 1
		j -= 1
	print(total)
main()


(n, a, b) = tuple(map(int, input().split()))
suits = list(map(int, input().split()))
(i, j) = (0, n - 1)
cost = 0
while i < j:
	if suits[i] == suits[j]:
		if suits[i] == 2:
			cost += 2 * min(a, b)
	elif suits[i] == 2:
		if suits[j] == 1:
			cost += b
		else:
			cost += a
	elif suits[j] == 2:
		if suits[i] == 1:
			cost += b
		else:
			cost += a
	else:
		print(-1)
		exit()
	i += 1
	j -= 1
if i == j and suits[i] == 2:
	cost += min(a, b)
print(cost)


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


def fun(x, n, a, b):
	cheap = min(a, b)
	mid = n // 2 - 1
	c = 0
	if n % 2 == 1:
		t = n // 2
		if x[t] == 2:
			c += cheap
	for i in range(mid + 1):
		j = n - i - 1
		if x[i] == 0 and x[j] == 1 or (x[i] == 1 and x[j] == 0):
			return -1
		if x[i] == x[j]:
			if x[i] == 2:
				c = c + cheap * 2
			continue
		if x[i] < x[j]:
			(x[i], x[j]) = (x[j], x[i])
		if x[i] == 2:
			if x[j] == 0:
				c += a
			else:
				c += b
	return c
(n, a, b) = list(map(int, input().strip().split(' ')))
x = list(map(int, input().strip().split(' ')))
ans = fun(x, n, a, b)
print(ans)


(n, a, b) = map(int, input().split())
k = map(int, input().split())
cost = [a, b]
bb = int(a)
sum = 0
e = 1
if bb > b:
	bb = b
c = []
for i in k:
	c.append(i)
for i in range(n // 2):
	if c[i] + c[n - i - 1] == 1:
		print(-1)
		e = 0
		break
	if c[i] + c[n - i - 1] == 4:
		sum = sum + 2 * bb
	if (c[i] == 2 or c[n - i - 1] == 2) and (c[i] != 2 or c[n - i - 1] != 2):
		if c[i] != 2:
			sum = sum + cost[c[i]]
		else:
			sum = sum + cost[c[n - i - 1]]
if n % 2 == 1:
	if c[n // 2] == 2:
		sum = sum + bb
if e == 1:
	print(sum)


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


(n, wc, bc) = map(lambda x: int(x), input().split(' '))
ds = input().split(' ')
lc = min(wc, bc)
mc = 0
for (i, d) in enumerate(ds):
	dc = ds[n - i - 1]
	if d == '2':
		if dc == '0':
			mc += wc
		elif dc == '1':
			mc += bc
		else:
			mc += lc
	elif dc != '2' and d != dc:
		mc = -1
		break
print(mc)


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


R = lambda : map(int, input().split())
(n, *a) = R()
m = min(a)
c = [*R()]
s = 0
for (x, y) in zip(c[:n // 2], c[::-1]):
	if x ^ y == 1:
		print(-1)
		exit()
	if x != y:
		s += a[min(x, y)]
	elif x == 2:
		s += 2 * m
print(s + n % 2 * (c[n // 2] == 2) * m)


i = lambda : map(int, input().split())
(n, *a) = i()
a += [min(a)]
s = [*i()]
t = s[::-1]
print((0, 1) in zip(s, t) and -1 or sum((a[y] for (x, y) in zip(s, t) if 1 < x)))


(n, a, b) = map(int, input().split(' '))
c = min(a, b)
m = input().split(' ')
rez = 0
ok = 1
for i in range(0, (n + 1) // 2):
	if m[i] == '0':
		if m[n - 1 - i] == '0':
			rez += 0
		elif m[n - 1 - i] == '2':
			rez += a
		else:
			ok = 0
	elif m[i] == '1':
		if m[n - 1 - i] == '1':
			rez += 0
		elif m[n - 1 - i] == '2':
			rez += b
		else:
			ok = 0
	elif m[n - 1 - i] == '0':
		rez += a
	elif m[n - 1 - i] == '1':
		rez += b
	elif i == n - 1 - i:
		rez += c
	else:
		rez += 2 * c
if ok == 1:
	print(rez)
else:
	print(-1)


def answer(n, a, b, A):
	flag = True
	cost = 0
	cheaper = min(a, b)
	till = n // 2
	for i in range(till):
		if A[i] == A[-1 - i] and A[i] != 2:
			continue
		if A[i] == 1 and A[-1 - i] == 0 or (A[i] == 0 and A[-1 - i] == 1):
			return (False, 0)
		if A[i] == 1 and A[-1 - i] == 2 or (A[i] == 2 and A[-1 - i] == 1):
			cost += b
		if A[i] == 0 and A[-1 - i] == 2 or (A[i] == 2 and A[-1 - i] == 0):
			cost += a
		if A[i] == 2 and A[-1 - i] == 2:
			cost += cheaper * 2
	if n % 2 != 0:
		if A[n // 2] == 2:
			cost += cheaper
	return (flag, cost)
(n, a, b) = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
(flag, cost) = answer(n, a, b, A)
if flag:
	print(cost)
else:
	print(-1)


import math

def prix(c, a, b):
	if c == '1':
		return b
	else:
		return a

def palindrome(chaine, a, b, prixx):
	(i, longueur) = (0, len(chaine))
	mini = min(a, b)
	while i < longueur:
		if chaine[i] != chaine[-i - 1] and chaine[i] != '2' and (chaine[-i - 1] != '2'):
			return -1
		elif i == len(chaine) // 2:
			if chaine[i] == '2':
				prixx += mini
		elif chaine[i] == chaine[-i - 1] == '2':
			prixx += 2 * mini
		else:
			if chaine[i] == '2':
				prixx += prix(chaine[-i - 1], a, b)
			if chaine[-i - 1] == '2':
				prixx += prix(chaine[i], a, b)
		i += 1
		longueur -= 1
	return prixx
t = input().split()
(n, a, b) = (int(t[0]), int(t[1]), int(t[2]))
t = input().split()
ch = ''.join(t)
prixx = 0
print(palindrome(ch, a, b, prixx))


(n, w, b) = map(int, input().split())
v = [int(i) for i in input().split()]
cor = [w, b]
res = 0
for i in range(n // 2):
	if v[i] == 2 and v[n - i - 1] == 2:
		res += 2 * min(cor)
	elif v[i] == 2:
		res += cor[v[n - i - 1]]
	elif v[n - i - 1] == 2:
		res += cor[v[i]]
	elif v[i] != v[n - i - 1]:
		print(-1)
		exit()
if n % 2 == 1 and v[n // 2] == 2:
	res += min(cor)
print(res)


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


(n, a, b) = map(int, input().split())
x = list(map(int, input().split()))
s = 0
for i in range(n):
	if x[i] != 2 and x[n - i - 1] != 2 and (x[i] != x[n - i - 1]):
		exit(print(-1))
	if x[i] == 2 and x[n - 1 - i] == 0:
		s += a
	elif x[i] == 2 and x[n - 1 - i] == 1:
		s += b
	elif x[i] == 2 and x[n - 1 - i] == 2:
		s += min(a, b)
print(s)


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


a = [int(i) for i in input().split()]
b = [int(j) for j in input().split()]
c = min(a[1], a[2])
d = a[0] // 2
flag = 2
cost = 0
if a[0] % 2 == 1:
	if b[d] == 2:
		cost += c
	for i in range(d):
		if b[i] == b[-i - 1] or (b[i] == 2 and (b[-i - 1] == 1 or b[-i - 1] == 0)) or (b[-i - 1] == 2 and (b[i] == 1 or b[i] == 0)):
			if b[i] == 2 and b[-i - 1] == 2:
				cost += 2 * c
			if b[i] == 2 and b[-i - 1] != 2:
				if b[-i - 1] == 0:
					cost += a[1]
				if b[-i - 1] == 1:
					cost += a[2]
			if b[i] != 2 and b[-i - 1] == 2:
				if b[i] == 1:
					cost += a[2]
				if b[i] == 0:
					cost += a[1]
		else:
			flag = 0
			break
if a[0] % 2 == 0:
	for i in range(d):
		if b[i] == b[-i - 1] or (b[i] == 2 and (b[-i - 1] == 1 or b[-i - 1] == 0)) or (b[-i - 1] == 2 and (b[i] == 1 or b[i] == 0)):
			if b[i] == 2 and b[-i - 1] == 2:
				cost += 2 * c
			if b[i] != 2 and b[-i - 1] == 2:
				if b[i] == 1:
					cost += a[2]
				if b[i] == 0:
					cost += a[1]
			if b[i] == 2 and b[-i - 1] != 2:
				if b[-i - 1] == 1:
					cost += a[2]
				if b[-i - 1] == 0:
					cost += a[1]
		else:
			flag = 0
			break
if flag == 0:
	print('-1')
if flag == 2:
	print(cost)


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


(n, a, b) = input().split()
n = int(n)
a = int(a)
b = int(b)
list1 = [int(x) for x in input().split()]
if 2 not in list1:
	if list1 == list1[::-1]:
		print(0)
	else:
		print(-1)
else:
	twos = []
	expenditure = 0
	for i in range(len(list1)):
		if list1[i] == 2:
			twos.append(i)
	temp = list1[::-1]
	for i in twos:
		if temp[i] == 2:
			if a > b:
				expenditure += b
				list1[i] = 1
			else:
				expenditure += a
				list1[i] = 0
		elif temp[i] == 1:
			expenditure += b
			list1[i] = 1
		else:
			expenditure += a
			list1[i] = 0
	if list1 == list1[::-1]:
		print(expenditure)
	else:
		print(-1)


X = list(map(int, input().split()))
Dancers = list(map(int, input().split()))
(i, j) = (0, len(Dancers) - 1)
Cost = 0
while i <= j:
	if Dancers[i] != Dancers[j] and 2 not in [Dancers[i], Dancers[j]]:
		print(-1)
		exit()
	if Dancers[i] == Dancers[j] and Dancers[i] == 2:
		Cost += min(X[1], X[2]) * 2 if i != j else min(X[1], X[2])
	else:
		Cost += X[min(Dancers[i], Dancers[j]) + 1] if 2 in [Dancers[i], Dancers[j]] else 0
	(i, j) = (i + 1, j - 1)
print(Cost)


read_numbers = lambda : list(map(int, input().split()))
INF = 1 << 64
(n, a, b) = read_numbers()
c = read_numbers()
ans = 0
for i in range(n // 2):
	if c[i] == 1 and c[n - i - 1] == 0 or (c[i] == 0 and c[n - i - 1] == 1):
		print(-1)
		exit(0)
	if c[i] == c[n - i - 1] == 2:
		ans += min(a, b) * 2
	elif c[i] == c[n - i - 1]:
		continue
	elif c[i] == 1 or c[n - i - 1] == 1:
		ans += b
	elif c[i] == 0 or c[n - i - 1] == 0:
		ans += a
print(ans + min(a, b) * (n & 1 == 1 and c[n // 2] == 2))


from sys import stdin, stdout
from itertools import accumulate
nmbr = lambda : int(stdin.readline())
lst = lambda : list(map(int, stdin.readline().split()))
for _ in range(1):
	(n, w, b) = lst()
	a = lst()
	ans = 0
	for i in range(n):
		if a[i] == 2:
			if a[n - i - 1] == 0:
				a[i] = 0
				ans += w
			elif a[n - i - 1] == 1:
				a[i] = 1
				ans += b
			elif w <= b:
				ans += w if i == n - i - 1 else 2 * w
				a[i] = a[n - i - 1] = 0
			else:
				ans += b if i == n - i - 1 else 2 * b
				a[i] = a[n - i - 1] = 1
		elif a[i] != a[n - i - 1] and a[n - i - 1] != 2:
			ans = -1
			break
	print(ans)


l = list(map(int, input().split()))
p = list(map(int, input().split()))
n = l[0]
w = l[1]
b = l[2]
cost = 0
for i in range(n):
	if p[i] == 2:
		if p[n - i - 1] == 0:
			p[i] = 0
			cost += w
		elif p[n - i - 1] == 1:
			p[i] = 1
			cost += b
		else:
			if w == min(w, b):
				p[i] = 0
			else:
				p[i] = 1
			cost += min(w, b)
if p[::-1] == p:
	print(cost)
else:
	print('-1')


(n, a, b) = map(int, input().split(' '))
ps = [a, b]
cs = list(map(int, input().split(' ')))
res = 0 if n % 2 == 0 else min(ps) if cs[n // 2] == 2 else 0
for l in range(n // 2):
	r = n - 1 - l
	if cs[l] == 2 == cs[r]:
		res += 2 * min(ps)
	elif cs[l] == 2:
		res += ps[cs[r]]
	elif cs[r] == 2:
		res += ps[cs[l]]
	elif cs[l] != cs[r]:
		print(-1)
		exit(0)
print(res)


from math import ceil
(n, a, b) = map(int, input().split())
c = list(map(int, input().split()))
s = 0
flag = 0
if a > b:
	y = 1
else:
	y = 0
for i in range(ceil(n / 2)):
	x = n - i - 1
	if c[i] == c[x] and c[i] != 2:
		continue
	elif c[i] != 2 and c[x] != 2:
		print(-1)
		flag = 1
		break
	elif c[i] == 2 and c[x] == 2 and (i == x):
		if y == 1:
			s += b
		else:
			s += a
	elif c[i] == 2 and c[x] == 2:
		if y == 1:
			s += b * 2
		else:
			s += a * 2
	elif c[i] == 2:
		if c[x] == 1:
			s += b
		else:
			s += a
	elif c[x] == 2:
		if c[i] == 1:
			s += b
		else:
			s += a
if flag == 0:
	print(s)


from math import ceil
(n, *suits) = map(int, input().split(' '))
dancers = [*map(int, input().split(' '))]
(dancers, dancers2, middle) = (dancers[:n // 2], [*reversed(dancers[ceil(n / 2):])], [x for x in dancers[n // 2:ceil(n / 2)] if x == 2])
cost = 0
neut = min(suits)
for c in middle:
	cost += neut
for (l, r) in zip(dancers2, dancers):
	if {l, r} == {2}:
		cost += 2 * neut
	elif 2 in {l, r}:
		cost += suits[min(l, r)]
	elif l != r:
		cost = -1
		break
print(cost)


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


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
	elif 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 func(i):
	p = int(i)
	if p == 0:
		return 1
	elif p == 1:
		return 2
	else:
		return 0
(n, a, b) = list(map(int, input().split()))
l = list(map(func, input().split()))
ans = 0
for i in range(n):
	if l[i] == 0:
		if l[n - i - 1] == 0:
			ans += min(a, b)
			if i != n - i - 1:
				ans += min(a, b)
			if a < b:
				(l[i], l[n - i - 1]) = (1, 1)
			else:
				(l[i], l[n - i - 1]) = (2, 2)
		elif l[n - i - 1] == 1:
			ans += a
			l[i] = 1
		else:
			ans += b
			l[i] = 2
if l != l[::-1]:
	print(-1)
else:
	print(ans)


(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
	elif A[i] == 2:
		cost += cheapest
if bad:
	print(-1)
else:
	print(cost)


def buy(nomer, a, b):
	if nomer == 0:
		return a
	else:
		return b
(n, a, b) = map(int, input().split())
d = list(map(int, input().split()))
L = 0
R = n - 1
sum = 0
OK = True
while L < R and OK:
	if d[L] != 2 and d[R] != 2:
		if d[L] != d[R]:
			OK = False
			break
		else:
			L += 1
			R -= 1
			continue
	if d[L] == 2 and d[R] != 2:
		sum += buy(d[R], a, b)
	elif d[L] != 2 and d[R] == 2:
		sum += buy(d[L], a, b)
	elif d[L] == 2 and d[R] == 2:
		sum += 2 * min(a, b)
	L += 1
	R -= 1
if not OK:
	print(-1)
else:
	if L == R and d[L] == 2:
		sum += min(a, b)
	print(sum)


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


(n, a, b) = map(int, input().split())
l = list(map(int, input().split()))
p = min(a, b)
pl = p * 2
sum = 0
i = 0
j = n - 1
while i < j:
	if l[i] != 2 and l[j] != 2:
		if l[i] != l[j]:
			print(-1)
			break
	elif l[i] == 2 and l[j] == 2:
		sum += pl
	elif min(l[i], l[j]) == 0:
		sum += a
	else:
		sum += b
	i += 1
	j -= 1
else:
	if i == j and l[i] == 2:
		sum += p
	print(sum)


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


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


(n, a, b) = map(int, input().split())
c = list(map(int, input().split()))
m = 0
for (i, e) in enumerate(c):
	if e == 2:
		ind = -(i + 1)
		v = c[ind]
		if v == 2:
			if i != len(c) - i - 1:
				m += min(a, b) * 2
			else:
				m += min(a, b)
			c[i] = -1
			c[ind] = -1
		elif v == 0:
			c[i] = 0
			m += a
		elif v == 1:
			c[i] = 1
			m += b
if c == list(reversed(c)):
	print(m)
else:
	print(-1)


(n, white, black) = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
left = 0
right = n - 1
impossible = False
cost = 0
while left <= right:
	ele1 = a[left]
	ele2 = a[right]
	if ele1 + ele2 == 1:
		impossible = True
		break
	if ele1 == 2 and ele2 == 2:
		cost += min(white, black)
		if left != right:
			cost += min(white, black)
	elif ele1 != ele2:
		if ele1 + ele2 == 2:
			cost += white
		else:
			cost += black
	left += 1
	right -= 1
if not impossible:
	print(cost)
else:
	print(-1)


(n, a, b) = map(int, input().split())
x = input()
x = x.split(' ')
cost = 0
flag = -1
for i in range(n):
	if x[i] == '2':
		if x[n - 1 - i] == '2':
			if a < b:
				x[i] = '0'
				cost += a
			else:
				x[i] = '1'
				cost += b
		else:
			x[i] = x[n - 1 - i]
			if x[i] == '0':
				cost += a
			else:
				cost += b
for j in range(n):
	if x[j] != x[n - 1 - j]:
		flag = 0
if flag == -1:
	print(cost)
else:
	print('-1')


(n, a, b) = map(int, input().split())
li = list(map(int, input().split()))
cost = 0
(i, j) = (0, n - 1)
while i <= j:
	if i == j and li[i] == 2:
		cost += min(a, b)
	elif li[i] == 0 and li[j] == 1 or (li[i] == 1 and li[j] == 0):
		cost = -1
		break
	elif li[i] == 2 and li[j] == 2:
		cost += 2 * min(a, b)
	elif li[i] == 2 or li[j] == 2:
		if li[i] == 1 or li[j] == 1:
			cost += b
		else:
			cost += a
	i = i + 1
	j = j - 1
print(cost)


(n, a, b) = map(int, input().split())
l = list(map(int, input().split()))
p = (n - 1) // 2
price = 0
for i in range(p + 1):
	if l[i] == 2 and l[n - i - 1] == 2:
		price = price + 2 * min(a, b)
		if i == n - i - 1:
			price = price - min(a, b)
	elif l[i] == 0 and l[n - i - 1] == 2 or (l[i] == 2 and l[n - i - 1] == 0):
		price = price + a
	elif l[i] == 1 and l[n - i - 1] == 2 or (l[i] == 2 and l[n - i - 1] == 1):
		price = price + b
	elif l[i] == l[n - i - 1]:
		pass
	else:
		print(-1)
		exit()
print(price)


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):
	i = bisect_left(a, x)
	if i:
		return a[i - 1]
	raise ValueError

def find_gt(a, 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
(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)


(n, a, b) = 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)
		elif arr[j] == 0:
			ans += a
		else:
			ans += b
	elif arr[j] == 2:
		if arr[i] == 0:
			ans += a
		else:
			ans += b
	elif 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)


(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
		elif r == 2 and l == 2:
			count += min(a, b) * 2
		elif 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, *costs] = [int(t) for t in input().split(' ')]
s = [int(t) for t in input().split(' ')]
l = n - 1
cost = 0
min_cost = min(*costs)
for i in range(n // 2 + n % 2):
	if s[i] + s[l - i] == 4:
		cost += 2 * min_cost if i != l - i else min_cost
	elif s[i] + s[l - i] == 3 or s[i] == 2 or s[l - i] == 2:
		cost += costs[min(s[i], s[l - i])]
	elif s[i] != s[l - i]:
		print(-1)
		exit()
print(cost)


def solve(l, n, a, b):
	i = 0
	j = n - 1
	cost = 0
	min_cost = min(a, b)
	while i < j:
		if l[i] == 2 and l[j] == 2:
			cost += min_cost * 2
		elif l[i] == 2 or l[j] == 2:
			if l[i] == 0 or l[j] == 0:
				cost += a
			else:
				cost += b
		elif l[i] != l[j]:
			return -1
		i += 1
		j -= 1
	if i == j and l[i] == 2:
		cost += min_cost
	return cost
(n, a, b) = list(map(int, input().strip().split()))
l = list(map(int, input().strip().split()))
print(solve(l, n, a, b))


(n, w, b) = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]
w1 = c.count(0)
b1 = c.count(1)
if w <= b:
	mini = 0
else:
	mini = 1
flag = 1
for i in range(n // 2):
	if c[i] == 2 and c[-i - 1] != 2:
		c[i] = c[-i - 1]
	elif c[i] == 2 and c[-i - 1] == 2:
		c[i] = mini
		c[-1 - i] = mini
	elif c[i] != 2 and c[-1 - i] == 2:
		c[-1 - i] = c[i]
	elif c[i] == c[-i - 1]:
		continue
	else:
		flag = 0
		break
if c[n // 2] == 2:
	c[n // 2] = mini
if flag == 0:
	print(-1)
else:
	print((c.count(0) - w1) * w + (c.count(1) - b1) * b)


(n, white, black) = map(int, input().split())
less = min(white, black)
l = list(map(int, input().split()))

def f(n, white, black):
	total = 0
	for i in range(n // 2):
		left = l[i]
		right = l[-1 - i]
		if left + right == 4:
			total += 2 * less
		if left == right:
			continue
		if left + right == 1:
			return -1
		if left + right == 2:
			total += white
		if left + right == 3:
			total += black
	if n % 2 == 1:
		if l[(n - 1) // 2] == 2:
			total += less
	return total
print(f(n, white, black))


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()


import math
import bisect
from math import gcd, floor, sqrt, log
from collections import defaultdict as dd, Counter as ctr
from bisect import bisect_left as bl, bisect_right as br
inp = lambda : int(input())
strng = lambda : input().strip()
jn = lambda x, l: x.join(map(str, l))
strl = lambda : list(input().strip())
mul = lambda : map(int, input().strip().split())
mulf = lambda : map(float, input().strip().split())
seq = lambda : list(map(int, input().strip().split()))

def mex(arr):
	nList = set(arr)
	mex = 0
	while mex in nList:
		mex += 1
	return mex

def results(c, nab):
	(n, a, b) = (nab[0], nab[1], nab[2])
	x = min(a, b)
	cnt = 0
	if n % 2:
		if c[n // 2] == 2:
			cnt += x
	for (j, i) in enumerate(range(0, n // 2), 1):
		if c[i] == c[-j]:
			if c[i] == 2:
				cnt += x * 2
		elif c[i] == 1 and c[-j] == 2 or (c[i] == 2 and c[-j] == 1):
			cnt += b
		elif c[i] == 0 and c[-j] == 2 or (c[i] == 2 and c[-j] == 0):
			cnt += a
		else:
			return -1
	return cnt

def main():
	nab = seq()
	c = seq()
	result = results(c, nab)
	print(result)
main()


(n, a, b) = map(int, input().split())
c = list(map(int, input().split()))
t = {0: a, 1: b}
total_price = 0
for i in range(n):
	back_i = n - i - 1
	if back_i >= i:
		if c[i] == c[back_i] or c[i] == 2 or c[back_i] == 2:
			if c[i] == 2 and c[back_i] == 2:
				if back_i == i:
					total_price += min(a, b)
				else:
					total_price += 2 * min(a, b)
			elif c[i] == 2:
				total_price += t[c[back_i]]
			elif c[back_i] == 2:
				total_price += t[c[i]]
		else:
			print(-1)
			exit()
print(total_price)


(n, w, b) = [int(i) for i in input().split()]
list1 = [int(i) for i in input().split()]
mid = n // 2
list2 = [w, b]
s = 0
chk = True
if n % 2 != 0:
	if list1[mid] == 2:
		s = s + min(list2)
for i in range(mid):
	if list1[i] == 1 or list1[i] == 0:
		if list1[n - i - 1] == list1[i]:
			chk = True
			continue
		elif list1[n - i - 1] == 2:
			s = s + list2[list1[i]]
		else:
			chk = False
			break
	elif list1[n - i - 1] == 1 or list1[n - i - 1] == 0:
		s = s + list2[list1[n - i - 1]]
	else:
		s = s + 2 * min(list2)
if chk:
	print(s)
else:
	print(-1)


(n, w, b) = map(int, input().split())
c = [w, b]
t = list(map(int, input().split()))
if n % 2 == 0:
	(x, y) = (t[:n // 2], t[n // 2:])
else:
	(x, y) = (t[:n // 2], t[n // 2 + 1:])
	z = t[n // 2]
y = y[::-1]
s = 0
f = False
for i in range(n // 2):
	if x[i] != y[i] and x[i] != 2 and (y[i] != 2):
		f = True
		break
	elif x[i] == 2 and y[i] != 2:
		s += c[y[i]]
	elif y[i] == 2 and x[i] != 2:
		s += c[x[i]]
	elif x[i] == y[i] == 2:
		s += min(c) * 2
if f:
	print(-1)
else:
	if n % 2 == 1 and z == 2:
		s += min(c)
	print(s)


(n, a, b) = tuple(map(int, input().split()))
c = list(map(int, input().split()))
min_index = 0 if a < b else 1
costs = (a, b)
s = 0
for i in range(n):
	if c[i] == 2:
		if c[n - 1 - i] == 2:
			c[i] = c[n - 1 - i] = min_index
			s += (2 - (i == n - 1 - i)) * costs[min_index]
		else:
			c[i] = c[n - 1 - i]
			s += costs[c[i]]
	elif c[i] != c[n - 1 - i] and c[n - 1 - i] != 2:
		print('-1')
		break
else:
	print(s)


import sys
import bisect
from collections import Counter
read_int = lambda : int(sys.stdin.readline())
read_ints = lambda : map(int, sys.stdin.readline().split())
read_int_list = lambda : list(read_ints())
read = lambda : sys.stdin.readline().strip()
read_list = lambda : sys.stdin.readline().split()

def main():
	(n, a, b) = read_ints()
	c = read_int_list()
	res = 0
	for i in range(0, n // 2):
		if c[i] == 2:
			if c[n - i - 1] == 2:
				res += 2 * min(a, b)
			elif c[n - i - 1] == 1:
				res += b
			else:
				res += a
		elif c[n - i - 1] == 2:
			if c[i] == 1:
				res += b
			else:
				res += a
		elif c[i] != c[n - i - 1]:
			res = -1
			break
	if res != -1 and n % 2 == 1 and (c[n // 2] == 2):
		res += min(a, b)
	print(res)
main()


(n, a, b) = map(int, input().split())
c = min(a, b)
z = input().split()
(ans, l, r) = (0, 0, n - 1)
while l <= r:
	if z[l] == z[r]:
		if z[l] == '2':
			if l == r:
				ans += c
			else:
				ans += 2 * c
	elif z[l] == '1' and z[r] == '0' or (z[l] == '0' and z[r] == '1'):
		print(-1)
		exit()
	elif z[l] == '2':
		if z[r] == '0':
			ans += a
		else:
			ans += b
	elif z[l] == '0':
		ans += a
	else:
		ans += b
	l += 1
	r -= 1
print(ans)


(n, a, b) = 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)
		exit(0)
	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)


arr = list(map(int, input().split()))
c = list(map(int, input().split()))
l = arr[0]
ans = 0
f = 0
for i in range(l // 2):
	if c[i] == c[l - i - 1] and c[i] != 2:
		continue
	elif c[i] == 0 and c[l - i - 1] == 2 or (c[i] == 2 and c[l - i - 1] == 0):
		ans += arr[1]
	elif c[i] == 2 and c[l - i - 1] == 1 or (c[i] == 1 and c[l - i - 1] == 2):
		ans += arr[2]
	elif c[i] == 2 and c[l - i - 1] == 2:
		ans += 2 * min(arr[1], arr[2])
	else:
		f = 1
		break
if f == 1:
	print('-1')
else:
	if l % 2 == 1 and c[l // 2] == 2:
		ans += min(arr[1], arr[2])
	print(ans)


def mi():
	return map(int, input().split(' '))
d = {}
(n, a, b) = mi()
d[0] = a
d[1] = b
optimum = min(a, b)
sum = 0
li = list(mi())
for i in range(n // 2):
	if li[i] == li[n - 1 - i]:
		if li[i] == 2:
			sum += 2 * optimum
		else:
			continue
	elif li[i] == 2:
		sum += d[li[n - i - 1]]
	elif li[n - i - 1] == 2:
		sum += d[li[i]]
	else:
		print(-1)
		exit()
if n % 2 and li[n // 2] == 2:
	sum += optimum
print(sum)


(N, white, black) = map(int, input().split())
xs = [int(x) for x in input().split()]
mid = len(xs) // 2
if len(xs) % 2 == 1:
	left = list(reversed(xs[0:mid]))
	right = xs[mid + 1:]
	cost = 0
	impossible = False
	if xs[mid] == 2:
		cost += min([white, black])
	for (l, r) in zip(left, right):
		if l == 2 and r == 2:
			cost += min([white, black]) * 2
		if l == 2:
			if r == 1:
				cost += black
			elif r == 0:
				cost += white
		if r == 2:
			if l == 1:
				cost += black
			elif l == 0:
				cost += white
		if r != 2 and l != 2 and (r != l):
			impossible = True
	if impossible == True:
		print(-1)
	else:
		print(cost)
else:
	left = list(reversed(xs[0:mid]))
	right = xs[mid:]
	cost = 0
	impossible = False
	for (l, r) in zip(left, right):
		if l == 2 and r == 2:
			cost += min([white, black]) * 2
		if l == 2:
			if r == 1:
				cost += black
			elif r == 0:
				cost += white
		if r == 2:
			if l == 1:
				cost += black
			elif l == 0:
				cost += white
		if r != 2 and l != 2 and (r != l):
			impossible = True
	if impossible == True:
		print(-1)
	else:
		print(cost)


R = lambda : map(int, input().split())
(n, *a) = R()
a += [min(a)]
c = [*R()]
s = 1
for (x, y) in zip(c, c[::-1]):
	s *= x ^ y != 1
	s += s * (x & 2) and a[y]
print(s - 1)


from collections import Counter, defaultdict, deque
read = lambda : list(map(int, input().split()))

def solve(c, a, b):
	res = 0
	for i in range(n):
		if c[i] != c[n - i - 1]:
			if 2 not in (c[i], c[n - i - 1]):
				return -1
			if c[n - i - 1] == 0:
				res += a
			elif c[n - i - 1] == 1:
				res += b
		elif c[i] == c[n - i - 1] == 2:
			res += min(a, b)
	return res
while True:
	try:
		(n, a, b) = read()
		c = read()
		print(solve(c, a, b))
	except:
		break


import sys
cin = list(sys.stdin)
firstline = cin[0].strip().split(' ')
ndancers = int(firstline[0])
wcost = int(firstline[1])
bcost = int(firstline[2])
dancers = cin[1].strip().split(' ')
(i, j) = (0, ndancers - 1)
cost = 0
while i < j:
	if dancers[i] == '2' or dancers[j] == '2':
		if dancers[i] == '0':
			dancers[j] = '0'
			cost += wcost
		elif dancers[i] == '1':
			dancers[j] = '1'
			cost += bcost
		elif dancers[j] == '0':
			dancers[i] = '0'
			cost += wcost
		elif dancers[j] == '1':
			dancers[i] = '1'
			cost += bcost
		elif bcost < wcost:
			dancers[i] = dancers[j] = '1'
			cost += 2 * bcost
		else:
			dancers[i] = dancers[j] = '0'
			cost += 2 * wcost
	elif dancers[i] != dancers[j]:
		cost = -1
		break
	i += 1
	j -= 1
if i == j:
	if dancers[i] == '2':
		if bcost < wcost:
			dancers[i] = '1'
			cost += bcost
		else:
			dancers[i] = '0'
			cost += wcost
print(cost)


(n, a, b) = map(int, input().split())
m = list(map(int, input().split()))
i = 0
j = len(m) - 1
count = 0
ans = 0
while not i == j and (not i - 1 == j) and (i >= 0) and (j >= 0):
	if m[i] != 2 or m[j] != 2:
		if m[i] == 2 and m[j] == 0:
			count += a
		elif m[i] == 2 and m[j] == 1:
			count += b
		elif m[j] == 2 and m[i] == 0:
			count += a
		elif m[j] == 2 and m[i] == 1:
			count += b
		elif m[i] != m[j]:
			ans = -1
			i = -100
			j = -100
	else:
		count += 2 * min(a, b)
	i += 1
	j -= 1
if i == j and m[i] == 2:
	count += min(a, b)
if ans == -1:
	print(ans)
else:
	print(count)


import math
(n, a, b) = map(int, input().split())
arr = [int(x) for x in input().split()]
black = 0
white = 0
mini = 0
m = min(a, b)
num = math.ceil(n / 2)
for i in range(num):
	if arr[i] == 0:
		if arr[n - i - 1] == 1:
			print(-1)
			exit()
		elif arr[n - i - 1] == 0:
			continue
		elif arr[n - i - 1] == 2:
			white += a
	if arr[i] == 1:
		if arr[n - i - 1] == 0:
			print(-1)
			exit()
		elif arr[n - i - 1] == 1:
			continue
		elif arr[n - i - 1] == 2:
			black += b
	if arr[i] == 2:
		if arr[n - i - 1] == 0:
			white += a
		elif arr[n - i - 1] == 1:
			black += b
		elif arr[n - i - 1] == 2:
			if i == n - 1 - i:
				mini += m
			else:
				mini += m * 2
print(white + black + mini)


from sys import exit
(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)
		exit(0)
	l += 1
	r -= 1
if l == r:
	if cl[l] == 2:
		ans += min(a, b)
print(ans)


def ip():
	return int(input())

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

def sar():
	return list(ipp())

def pars(a):
	print(' '.join(list(map(str, a))))
	print('\r')

def parl(a):
	print('\r'.join(list(map(str, a))))
	print('\r')
T = 1
for _ in range(T):
	(n, a, b) = ipp()
	aa = []
	aa = sar()
	c = 0
	if n % 2 != 0:
		if aa[n // 2] == 2:
			c += min(a, b)
	f = 1
	if n != 1:
		for i in range(n // 2):
			if aa[i] == aa[n - 1 - i]:
				if aa[i] == 2:
					c += 2 * min(a, b)
			elif aa[i] != aa[n - 1 - i]:
				if aa[i] == 1 and aa[n - 1 - i] == 2:
					c += b
				elif aa[i] == 0 and aa[n - 1 - i] == 2:
					c += a
				elif aa[i] == 2 and aa[n - 1 - i] == 0:
					c += a
				elif aa[i] == 2 and aa[n - 1 - i] == 1:
					c += b
				else:
					f = 0
					print('-1')
					break
	if f == 1:
		print(c)


(n, a, b) = [int(x) for x in input().split()]
(c, r) = ([int(x) for x in input().split()], 0)
p = a if a < b else b
if n % 2 == 1:
	if c[n // 2] == 2:
		r += p
for x in range(n // 2):
	if c[x] != c[-1 - x]:
		if 2 in [c[x], c[-1 - x]]:
			if c[x] == 2:
				r += a if c[-1 - x] == 0 else b
			else:
				r += a if c[x] == 0 else b
		else:
			r = -1
			break
	if [c[x], c[-1 - x]] == [2, 2]:
		r += 2 * p
print(r)


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


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


(n, a, b) = map(int, input().split())
c = list(map(int, input().split()))
m = min(a, b)
p = 0
d = {0: a, 1: b, 2: 2 * m}
for x in range(n // 2):
	l = c[x]
	r = c[n - x - 1]
	if l == 2 or r == 2:
		p += d[min(l, r)]
	elif l != r:
		p = -1
		break
if p != -1:
	if n % 2 == 1:
		if c[n // 2] == 2:
			p += m
print(p)


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


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


def func(n, a, b, ar, l):
	cost = 0
	d = {0: a, 1: b}
	if (l + 1) % 2 == 1:
		if ar[l // 2] == 2:
			cost = cost + min(a, b)
	for i in range((l + 1) // 2):
		if ar[i] == ar[l]:
			if ar[i] == 2:
				cost += 2 * min(a, b)
		elif ar[i] != ar[l]:
			if ar[i] == 1 and ar[l] == 0 or (ar[i] == 0 and ar[l] == 1):
				return -1
			elif ar[i] == 2:
				cost = cost + d[ar[l]]
			elif ar[l] == 2:
				cost = cost + d[ar[i]]
		l = l - 1
	return cost
(n, a, b) = map(int, input().split())
ar = [int(i) for i in input().split()]
l = len(ar) - 1
print(func(n, a, b, ar, l))


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


container = list(map(int, input().split()))
n = container[0]
white = container[1]
black = container[2]
line = list(map(int, input().split()))
i = 0
j = len(line) - 1
ans = 0
while i <= j:
	if i == j and line[i] == 2:
		ans += min(white, black)
	elif line[i] != 2 and line[j] == 2:
		ans += white if line[i] == 0 else black
	elif line[i] == 2 and line[j] != 2:
		ans += white if line[j] == 0 else black
	elif line[i] == 2 and line[j] == 2:
		ans += 2 * min(white, black)
	elif line[i] != line[j]:
		ans = -1
		break
	i += 1
	j -= 1
print(ans)


(n, a, b) = map(int, input().strip().split(' '))
y = [int(x) for x in input().split()]
odd = n % 2
if odd == 1:
	costOdd = 0
	stat1 = 1
	end = n // 2
	p = 0
	q = n - 1
	while p != end:
		if y[p] == 2 and y[q] == 2:
			costOdd = costOdd + 2 * min(a, b)
		elif y[p] == 2 or y[q] == 2:
			maxx = min(y[p], y[q])
			if maxx == 0:
				costOdd += a
			else:
				costOdd += b
		elif y[p] != 2 or y[q] != 2:
			if y[p] != y[q]:
				stat1 = 0
		p = p + 1
		q = q - 1
	if y[end] == 2:
		costOdd += min(a, b)
	if stat1 == 1:
		print(costOdd)
	else:
		print(-1)
else:
	stat2 = 1
	costEVEN = 0
	end = n // 2
	p = 0
	q = n - 1
	while p != end:
		if y[p] == 2 and y[q] == 2:
			costEVEN += 2 * min(a, b)
		elif y[p] == 2 or y[q] == 2:
			maxx = min(y[p], y[q])
			if maxx == 0:
				costEVEN += a
			else:
				costEVEN += b
		elif y[p] != 2 or y[q] != 2:
			if y[p] != y[q]:
				stat2 = 0
		p = p + 1
		q = q - 1
	if stat2 == 1:
		print(costEVEN)
	else:
		print(-1)


(n, a, b) = map(int, input().split())
l = list(map(int, input().split()))
s = 0
i = 0
j = n - 1
while i <= j:
	if l[i] == l[j]:
		if l[i] == 2:
			if i != j:
				s += 2 * min(a, b)
			else:
				s += min(a, b)
	elif l[i] == 2 or l[j] == 2:
		if l[i] == 0 or l[j] == 0:
			s += a
		else:
			s += b
	else:
		print(-1)
		break
	i += 1
	j -= 1
if i > j:
	print(s)


(n, m, k) = map(int, input().split())
s = list(map(int, input().split()))
count = 0
if n % 2 == 1 and s[n // 2 + n % 2 - 1] == 2:
	count += min(m, k)
for i in range(n // 2):
	if s[i] != s[-1 - i] or s[i] == s[-i - 1] == 2:
		if s[i] == 1 and s[-1 - i] == 2 or (s[i] == 2 and s[-1 - i] == 1):
			count += k
		elif s[i] == 0 and s[-1 - i] == 2 or (s[i] == 2 and s[-i - 1] == 0):
			count += m
		elif s[i] == 0 and s[-1 - i] == 1 or (s[i] == 1 and s[-i - 1] == 0):
			count = -1
			break
		elif s[i] == s[-1 - i] == 2:
			count += 2 * min(m, k)
print(count)


(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)


(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)
			exit()
	elif a[i] == 0:
		if a[n - 1 - i] == 2:
			ans += w
		elif a[n - 1 - i] == 1:
			print(-1)
			exit()
	elif 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())
l = list(map(int, input().split()))
flag = False
cost = 0
for i in range(n // 2):
	if l[i] == l[n - i - 1] == 2:
		cost += 2 * min(a, b)
	elif l[i] == 2 and l[n - i - 1] == 0 or (l[i] == 0 and l[n - i - 1] == 2):
		cost += a
	elif l[i] == 1 and l[n - i - 1] == 2 or (l[i] == 2 and l[n - i - 1] == 1):
		cost += b
	elif l[i] != l[n - i - 1]:
		flag = True
		break
if n & 1 == 1 and l[n // 2] == 2:
	cost += min(a, b)
print(-1 if flag else cost)


(n, w, b) = map(int, input().split())
N = [int(i) for i in input().split()]
flag = 1
exc = 0
if n % 2 == 0:
	mid = n // 2
	p1 = N[0:mid]
	p2 = N[mid:len(N)]
	p2.reverse()
	wd = 0
	bd = 0
	for i in range(0, len(p1)):
		if p1[i] != p2[i]:
			if p1[i] == 2 and p2[i] == 0:
				wd += 1
			elif p1[i] == 2 and p2[i] == 1:
				bd += 1
			elif p2[i] == 2 and p1[i] == 0:
				wd += 1
			elif p2[i] == 2 and p1[i] == 1:
				bd += 1
			else:
				flag = 0
				break
		elif p1[i] == 2:
			exc += 2 * min(b, w)
else:
	mid = n // 2
	p1 = N[0:mid]
	p2 = N[mid + 1:len(N)]
	p2.reverse()
	wd = 0
	bd = 0
	for i in range(0, len(p1)):
		if p1[i] != p2[i]:
			if p1[i] == 2 and p2[i] == 0:
				wd += 1
			elif p1[i] == 2 and p2[i] == 1:
				bd += 1
			elif p2[i] == 2 and p1[i] == 0:
				wd += 1
			elif p2[i] == 2 and p1[i] == 1:
				bd += 1
			else:
				flag = 0
				break
		elif p1[i] == 2:
			exc += 2 * min(b, w)
	if N[mid] == 2:
		exc += min(w, b)
if flag == 0:
	print(-1)
elif n != 1:
	print(wd * w + bd * b + exc)
elif n == 1 and N[0] == 2:
	print(min(b, w))
else:
	print(0)


s = [int(x) for x in input().split(' ')]
n = s[0]
a = s[1]
b = s[2]
s = [int(x) for x in input().split(' ')]
sumb = 0
f = 1
for i in range(0, n):
	if s[i] == 2:
		s[i] = s[n - 1 - i]
		if s[i] == 0:
			sumb += a
		if s[i] == 1:
			sumb += b
		if s[i] == 2:
			sumb += min(a, b)
	if s[i] != 2 and s[i] != s[n - 1 - i] and (s[n - 1 - i] != 2):
		f = 0
		break
if not f:
	print(-1)
else:
	print(sumb)


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


(n, a, b) = map(int, input().split())
l = list(map(int, input().split()))
price = 0
ans = True
for (i, v) in enumerate(l):
	if v == 2:
		if l[len(l) - i - 1] == 2:
			l[i] = 0
			l[len(l) - i - 1] = 0
			if len(l) - i - 1 == i:
				price += min(a, b)
			else:
				price += 2 * min(a, b)
		elif l[len(l) - i - 1] == 0:
			l[i] = 0
			price += a
		elif l[len(l) - i - 1] == 1:
			l[i] = 1
			price += b
	elif l[len(l) - i - 1] + l[i] == 1:
		ans = False
		break
if ans:
	print(price)
else:
	print(-1)


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


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)


import math
(n, a, b) = list(map(int, input().split()))
o = 0
mi = min(a, b)
s = list(map(int, input().split()))
for i in range(0, len(s) // 2):
	if s[i] == 2 and s[-i - 1] == 2:
		o += mi * 2
	elif s[i] == 1 and s[-i - 1] == 2 or (s[i] == 2 and s[-i - 1] == 1):
		o += b
	elif s[i] == 0 and s[-i - 1] == 2 or (s[i] == 2 and s[-i - 1] == 0):
		o += a
	elif s[i] == 1 and s[-i - 1] == 0 or (s[i] == 0 and s[-i - 1] == 1):
		print(-1)
		exit()
if len(s) % 2 == 1:
	if s[len(s) // 2] == 2:
		o += mi
print(o)


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


(n, w, b) = map(int, input().split())
ls = list(map(int, input().split()))
lc = [w, b, 0]
c = 0
if n % 2:
	m = (n - 1) // 2
else:
	m = n // 2
for i in range(m):
	if ls[i] != 2 and ls[n - (i + 1)] != 2 and (ls[i] != ls[n - (i + 1)]):
		print(-1)
		exit()
	if ls[i] == 2 and ls[n - (i + 1)] == 2:
		c += min(w, b)
		c += min(w, b)
	elif ls[i] == ls[n - (i + 1)]:
		continue
	else:
		c += lc[ls[i]]
		c += lc[ls[n - (i + 1)]]
if n % 2:
	if ls[(n - 1) // 2] == 2:
		c += min(w, b)
print(c)


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


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


(n, a, b) = [int(x) for x in input().split()]
v = [int(x) for x in input().split()]
i = 0
ans = 0
while i <= n - 1 - i:
	x = v[i]
	y = v[n - i - 1]
	if i == n - i - 1:
		if ans >= 0 and x == 2:
			ans += min(a, b)
	elif x == y:
		if ans >= 0 and x == 2:
			ans += 2 * min(a, b)
	elif ans >= 0 and (x == 2 or y == 2):
		if x == 1:
			ans += b
		elif x == 0:
			ans += a
		if y == 1:
			ans += b
		elif y == 0:
			ans += a
	else:
		ans = -1
	i += 1
print(ans)


I = lambda : map(int, input().split())
(n, *a) = (*I(),)
c = (*I(),)
r = [0, min(a)][n % 2 and c[n // 2] == 2]
for i in range(n // 2):
	if c[i] ^ c[-1 - i] == 1:
		r = -1
		break
	if c[i] == 2 == c[-1 - i]:
		r += 2 * min(a)
	elif c[i] == 2:
		r += a[c[-1 - i]]
	elif c[-1 - i] == 2:
		r += a[c[i]]
print(r)


(n, a, b) = map(int, input().split())
c = list(map(int, input().split()))
if a <= b:
	mn = 0
	mn_val = a
else:
	mn = 1
	mn_val = b
D = {0: a, 1: b, 2: mn_val}
if n % 2 == 0:
	l = c[:n // 2]
	r = c[n // 2:]
else:
	l = c[:n // 2]
	r = c[n // 2 + 1:]
r = r[::-1]
total = 0
flag = 0
for i in range(len(l)):
	if l[i] == r[i] == 2:
		total += mn_val * 2
	elif l[i] == 2:
		total += D[r[i]]
	elif r[i] == 2:
		total += D[l[i]]
	elif l[i] != r[i]:
		print(-1)
		flag = 1
		break
	else:
		pass
if n % 2 != 0:
	if c[n // 2] == 2:
		total += mn_val
if flag == 0:
	print(total)


(n, white_price, black_price) = map(int, input().split(' '))
dancers = list(map(int, input().split(' ')))
price = 0
lower_price = min(white_price, black_price)

def get_price(color):
	if color == 0:
		return white_price
	elif color == 1:
		return black_price
	else:
		return lower_price
palindrom_possible = True
for i in range(n // 2):
	current = dancers[i]
	opposite = dancers[n - i - 1]
	if current == 0:
		if opposite == 1:
			palindrom_possible = False
			break
		elif opposite == 2:
			price += white_price
	elif current == 1:
		if opposite == 0:
			palindrom_possible = False
			break
		elif opposite == 2:
			price += black_price
	elif opposite == 0:
		price += white_price
	elif opposite == 1:
		price += black_price
	else:
		price += 2 * lower_price
if n % 2 == 1:
	if dancers[n // 2] == 2:
		price += lower_price
if palindrom_possible:
	print(price)
else:
	print(-1)


import sys
from math import ceil
[n, a, b] = [int(i) for i in input().split()]
m = [int(i) for i in input().split()]
cost = [a, b]
bur = 0
for i in range(ceil(n / 2)):
	if m[i] == 2 or m[n - 1 - i] == 2:
		if m[i] == m[n - 1 - i]:
			bur += min(a, b)
			if i != n - 1 - i:
				bur += min(a, b)
		else:
			bur += cost[min(m[i], m[n - 1 - i])]
	elif m[i] != m[n - 1 - i]:
		bur = -1
		break
print(bur)


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


import math

def main():
	firstLine = input('')
	secondLine = input('')
	[n, white_cost, black_cost] = [int(z) for z in firstLine.split()]
	formation = [int(z) for z in secondLine.split()]
	cost = 0
	cost_dict = [white_cost, black_cost]
	end_index = len(formation) - 1
	min_of_two = min(cost_dict)
	for i in range(int(n / 2)):
		if formation[i] == 2 and formation[end_index - i] == 2:
			cost += 2 * min_of_two
		elif formation[i] == 2 and formation[end_index - i] != 2:
			cost += cost_dict[formation[end_index - i]]
		elif formation[i] != 2 and formation[end_index - i] == 2:
			cost += cost_dict[formation[i]]
		elif formation[i] != formation[end_index - i]:
			return -1
	if len(formation) % 2 == 1 and formation[int(end_index / 2)] == 2:
		cost += min_of_two
	return cost
print(main())


st = input().split()
a = {'0': int(st[1]), '1': int(st[2])}
st = input()
coast = 0
is_able = True
for x in range(0, len(st) // 2 + 1):
	y = len(st) - x - 1 + 0
	if y == x:
		if st[x] == '2':
			coast += min(a.values())
	elif st[x] == st[y]:
		if st[x] == '2':
			coast += 2 * min(a.values())
	elif st[x] == '2':
		coast += a[st[y]]
	elif st[y] == '2':
		coast += a[st[x]]
	else:
		is_able = False
		break
if is_able:
	print(coast)
else:
	print(-1)


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


import sys
first = list(input('').split())
n = int(first[0])
a = int(first[1])
b = int(first[2])
ci = list(input('').replace(' ', ''))
if n < 1 or n > 20:
	if b > 100 or b < 0:
		if a > 100 or a < 0:
			print(-1)
			sys.exit()
j = 0
coast = 0
for i in range(0, int(n / 2)):
	j = n - i - 1
	if ci[i] != ci[j] or (ci[i] == '2' and ci[j] == '2'):
		if ci[i] == '2' or ci[j] == '2':
			if ci[i] == '0' or ci[j] == '0':
				coast += a
			elif ci[i] == '1' or ci[j] == '1':
				coast += b
			elif a > b:
				coast += 2 * b
			else:
				coast += 2 * a
		else:
			print(-1)
			sys.exit()
if n % 2 == 1:
	if ci[int(n / 2)] == '2':
		if a > b:
			coast += b
		else:
			coast += a
print(coast)


(n, a, b) = [int(x) for x in input().split()]
c = [int(x) for x in input().split()]
p = 0
middle = int(n / 2)
for i in range(middle):
	if c[i] != 2 and c[-i - 1] != 2:
		if c[i] != c[-i - 1]:
			print('-1')
			exit()
		else:
			continue
	if c[i] == 2 and c[-i - 1] == 2:
		p += min(a, b) * 2
	elif c[i] != 2:
		p += a if c[i] == 0 else b
	elif c[-i - 1] != 2:
		p += a if c[-i - 1] == 0 else b
if n % 2 == 1:
	if c[middle] == 2:
		p += min(a, b)
print(p)


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


def sol():
	(N, A, B) = [int(x) for x in input().split(' ')]
	lst = [int(x) for x in input().split(' ')]
	cost = 0
	for i in range(N // 2):
		if lst[i] == 2:
			if lst[-1 * (i + 1)] == 0:
				cost += A
			elif lst[-1 * (i + 1)] == 1:
				cost += B
			elif lst[-1 * (i + 1)] == 2:
				cost += 2 * min(A, B)
		elif lst[i] == 0:
			if lst[-1 * (i + 1)] == 0:
				pass
			elif lst[-1 * (i + 1)] == 1:
				return -1
			elif lst[-1 * (i + 1)] == 2:
				cost += A
		elif lst[-1 * (i + 1)] == 0:
			return -1
		elif lst[-1 * (i + 1)] == 1:
			pass
		elif lst[-1 * (i + 1)] == 2:
			cost += B
	if N % 2 == 1:
		if lst[N // 2] == 2:
			cost += min(A, B)
	return cost
ans = sol()
print(ans)


n = list(map(int, input().split()))
n1 = list(map(int, input().split()))
lst = []
s = 0
for i in n1:
	lst.append(i)
n1.reverse()
for i in range(len(n1)):
	if lst[i] != n1[i] and lst[i] != 2 and (n1[i] != 2):
		s = -1
		break
	elif lst[i] == 2 and n1[i] == 0:
		lst.insert(i, 0)
		lst.remove(lst[i + 1])
		s = s + n[1]
	elif lst[i] == 2 and n1[i] == 1:
		lst.insert(i, 1)
		lst.remove(lst[i + 1])
		s = s + n[2]
	elif n1[i] == 2 and lst[i] == 2:
		if n[1] < n[2]:
			lst.insert(i, 0)
			lst.remove(lst[i + 1])
			s = s + n[1]
		else:
			lst.insert(i, 1)
			lst.remove(lst[i + 1])
			s = s + n[2]
print(s)


(n, a, b) = map(int, input().split())
array = list(map(int, input().split()))
array2 = [a, b]
k = min(a, b)
result = 0
for i in range(n // 2):
	if array[i] == 1 and array[n - i - 1] == 0:
		print(-1)
		exit(0)
	if array[i] == 0 and array[n - i - 1] == 1:
		print(-1)
		exit(0)
	if array[i] == 2 and array[n - i - 1] != 2:
		result += array2[array[n - i - 1]]
	if array[i] != 2 and array[n - i - 1] == 2:
		result += array2[array[i]]
	if array[i] == 2 and array[n - i - 1] == 2:
		result += 2 * k
if n % 2 != 0 and array[n // 2] == 2:
	result += k
print(result)


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


(n, a, b) = map(int, input().split())
c = input().split()
cheap = min(a, b)
fail = False
totprice = 0
if n % 2 == 1:
	if c[n // 2] == '2':
		totprice += cheap
for i in range(n // 2):
	if c[i] == '2':
		if c[-i - 1] == '2':
			totprice += cheap * 2
		elif c[-i - 1] == '1':
			totprice += b
		else:
			totprice += a
	elif c[i] == '1':
		if c[-i - 1] == '2':
			totprice += b
		elif c[-i - 1] == '0':
			fail = True
			break
	elif c[-i - 1] == '2':
		totprice += a
	elif c[-i - 1] == '1':
		fail = True
		break
if not fail:
	print(totprice)
else:
	print(-1)


nwb = list(map(int, input().split()))
n = nwb[0]
c = list(map(int, input().split()))
cost = 0
if (n == 1) & (c[0] == 2):
	print(min(nwb[1], nwb[2]))
	exit()
elif (n == 1) & (c[0] != 2):
	print(0)
	exit()
for i in range(n // 2):
	if (c[i] != 2) & (c[n - 1 - i] != 2) & (c[i] != c[n - 1 - i]):
		print(-1)
		exit()
	if c[i] == c[n - 1 - i] == 2:
		cost += 2 * min(nwb[1], nwb[2])
	if c[i] != c[n - 1 - i]:
		if c[i] == 2:
			cost += nwb[c[n - 1 - i] + 1]
		else:
			cost += nwb[c[i] + 1]
if (n % 2 == 1) & (c[n // 2] == 2):
	cost += min(nwb[1], nwb[2])
print(cost)
exit()


(n, w, b) = map(int, input().split())
l = [int(x) for x in input().split()]
c = min(w, b)
ans = 0
for i in range(n // 2):
	l1 = l[i]
	l2 = l[n - 1 - i]
	if l1 + l2 == 1:
		print(-1)
		exit()
	if l1 == 2 and l2 == 2:
		ans += c * 2
	elif l1 == 2 or l2 == 2:
		if l1 == 0 or l2 == 0:
			ans += w
		else:
			ans += b
if n % 2 and l[n // 2] == 2:
	ans += c
print(ans)


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


(n, a, b) = map(int, input().split())
c = [int(w) for w in input().split()]
d = list(reversed(c))
r = 0
can = True
for i in range(n // 2):
	p = [c[i], d[i]]
	if 2 in p:
		if 0 in p:
			r += a
		elif 1 in p:
			r += b
		else:
			r += 2 * min(a, b)
	elif c[i] != d[i]:
		can = False
if n % 2 != 0:
	if c[n // 2] == 2:
		r += min(a, b)
if can:
	print(r)
else:
	print(-1)


(n, a, b) = [int(x) for x in input().split()]
A = [x for x in input().split()]
if A == A[::-1]:
	c = A.count('2')
	if c == 0:
		print(0)
	else:
		m = min(a, b)
		print(c * m)
else:
	c = 0
	s = ''
	for i in range(n):
		if A[i] == '2':
			if A[n - i - 1] == '1':
				c += b
				s += '1'
			elif A[n - i - 1] == '0':
				c += a
				s += '0'
			else:
				m = min(a, b)
				if m == a:
					s += '0'
				else:
					s += '1'
				c += m
		else:
			s += A[i]
	if s == s[::-1]:
		print(c)
	else:
		print(-1)


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


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, copy, functools
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 998244353
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LLI():
	return [list(map(int, l.split())) for l in sys.stdin.readlines()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

def LS():
	return sys.stdin.readline().split()

def I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())

def S():
	return input()

def pf(s):
	return print(s, flush=True)

def pe(s):
	return print(str(s), file=sys.stderr)

def JA(a, sep):
	return sep.join(map(str, a))

def JAA(a, s, t):
	return s.join((t.join(map(str, b)) for b in a))

def main():
	(n, a, b) = LI()
	c = LI()
	t = 0
	m = min(a, b)
	for i in range(n // 2):
		d = c[i]
		e = c[-i - 1]
		if d == 2:
			if e == 2:
				t += m * 2
			elif e == 1:
				t += b
			else:
				t += a
		elif d == 1:
			if e == 0:
				return -1
			if e == 2:
				t += b
		else:
			if e == 1:
				return -1
			if e == 2:
				t += a
	if n % 2 == 1:
		if c[n // 2] == 2:
			t += m
	return t
print(main())


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


(n, a, b) = (int(x) for x in input().split())
price = [a, b]
suits = [int(x) for x in input().split()]
c_price = min(a, b)
cost = 0
for i in range(n // 2):
	if suits[i] == 2:
		if suits[-i - 1] == 2:
			cost += c_price * 2
		else:
			cost += price[suits[-i - 1]]
	elif suits[-i - 1] == 2:
		cost += price[suits[i]]
	elif suits[i] != suits[-i - 1]:
		print(-1)
		exit()
if n % 2 == 1:
	if suits[n // 2] == 2:
		cost += c_price
print(cost)


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


(n, a, b) = map(int, input().split())
c = list(map(int, input().split()))
(i, ans) = (0, 0)
cost = [a, b]
while i < int(n / 2):
	if c[i] == 2:
		if c[-i - 1] == 2:
			c[i] = c[-i - 1] = 0
			ans += 2 * min(a, b)
		else:
			c[i] = c[-i - 1]
			ans += cost[c[i]]
	elif c[-i - 1] == 2:
		c[-i - 1] = c[i]
		ans += cost[c[i]]
	i += 1
if n % 2 == 1:
	if c[int(n / 2)] == 2:
		ans += min(a, b)
if not c == c[::-1]:
	print(-1)
else:
	print(ans)


x = [int(xx) for xx in input().split()]
n = x[0]
a = x[1]
b = x[2]
cost = 0
y = [int(yy) for yy in input().split()]
w = y[:]
sm = min(a, b)
bi = max(a, b)
l = len(y)
t = 0
for i in range(0, l):
	j = l - i - 1
	if y[i] == 2:
		k = y[j]
		if k == 0:
			y[i] = 0
			cost += a
		if k == 2:
			cost += sm
			if sm == a:
				y[i] = 0
			else:
				y[i] = 1
		if k == 1:
			cost += b
			y[i] = 1
w = y[:]
y.reverse()
print()
for (i, j) in zip(y, w):
	if i == j:
		t = t + 1
if t == l:
	print(cost)
else:
	print(-1)


(n, a, b) = map(int, input().split())
c = list(map(int, input().split()))
cost = min(a, b) * 2
counts = 0
for i in range(n // 2):
	x = c[i] ^ c[-1 - i]
	if x == 1:
		print(-1)
		exit()
	elif x == 2:
		counts += a
	elif x == 3:
		counts += b
	elif c[i] == 2:
		counts += cost
if 1 & n and c[n // 2] == 2:
	counts += min(a, b)
print(counts)


(n, a, b) = map(int, input().split())
s = list(map(int, input().split()))
m = int(n // 2)
g = 0
q = min(a, b)
p = [a, b]
if n % 2 == 1:
	if s[int(n // 2)] == 2:
		g += q
for i in range(0, m):
	y = s[i]
	x = s[n - 1 - i]
	if x != y and (x != 2 and y != 2):
		print(-1)
		exit()
	elif x != y and (x == 2 or y == 2):
		if x == 2:
			g += p[y]
		else:
			g += p[x]
	elif x == y == 2:
		g += 2 * q
print(g)


inp = input().split()
(n, aa, b) = (int(inp[0]), int(inp[1]), int(inp[2]))
inp = input().split()
a = [int(i) for i in inp]
(l, r, ans) = (0, n - 1, 0)
while l <= r:
	if a[l] == a[r]:
		if a[l] == 2:
			if l == r:
				ans += min(aa, b)
			else:
				ans += 2 * min(aa, b)
	elif a[l] == 0 and a[r] == 1 or (a[l] == 1 and a[r] == 0):
		ans = -1
		break
	elif a[l] == 0 or a[r] == 0:
		ans += aa
	elif a[l] == 1 or a[r] == 1:
		ans += b
	l += 1
	r -= 1
print(ans)


(n, w, b) = (int(_) for _ in input().split(' '))
colors = [int(_) for _ in input().split(' ')]
costs = [w, b]
cost = 0
impossible = False
for i in range((n - 1) // 2 + 1):
	if colors[i] != colors[n - i - 1]:
		if colors[i] == 2:
			cost += costs[colors[n - i - 1]]
		elif colors[n - i - 1] == 2:
			cost += costs[colors[i]]
		else:
			impossible = True
	elif colors[i] == 2:
		cost += 2 * min(w, b)
		if i == n - i - 1:
			cost -= min(w, b)
if impossible:
	print(-1)
else:
	print(cost)


(n, a, b) = [int(i) for i in input().split(' ')]
arr = [int(i) for i in input().split(' ')]
c = [a, b]
s = 0
m = min(a, b)
h = c.index(m)
f = 0
for i in range(n // 2):
	if arr[i] == 2 and arr[n - 1 - i] == 2:
		arr[i] = m
		arr[n - 1 - i] = m
		s += 2 * m
	elif arr[i] == 2 or arr[n - 1 - i] == 2:
		if arr[i] == 1 or arr[n - 1 - i] == 1:
			s += c[1]
		else:
			s += c[0]
	elif arr[i] != arr[n - 1 - i]:
		f = 1
		break
if n % 2 == 1:
	if arr[n // 2] == 2:
		s += m
if f:
	print(-1)
else:
	print(s)


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


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


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


import sys
(n, a, b) = [int(i) for i in input().split()]
l = [int(i) for i in input().split()]
m = min(a, b)
count = 0
for i in range(n // 2):
	x = l[i]
	y = l[n - 1 - i]
	if x != y and x != 2 and (y != 2):
		print('-1')
		sys.exit()
	elif x == y and x != 2:
		continue
	elif x == 2:
		if y == 2:
			count += 2 * m
		elif y == 0:
			count += a
		else:
			count += b
	elif y == 2:
		if x == 0:
			count += a
		else:
			count += b
	else:
		count += m
if n & 1 == 1 and l[n // 2] == 2:
	count += m
print(count)


(n, a, b) = [int(k) for k in input().split()]
arr = [int(k) for k in input().split()]
cost = {0: a, 1: b}
lowcost = min(a, b)
total = 0
for (i, d) in enumerate(arr):
	dc = arr[n - i - 1]
	if d == 2:
		if dc == 0:
			total += a
		elif dc == 1:
			total += b
		else:
			total += lowcost
	elif d in [0, 1]:
		if dc == 1 - d:
			total = -1
			break
print(total)


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


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


(n, a, b) = tuple(map(int, input().split()))
f = (a, b, 0)
j = input().split()
m = min(a, b)
s = 0
l = True
for i in range(n // 2):
	u = j[i]
	y = j[n - 1 - i]
	if u != y:
		if u != '2' and y != '2':
			l = False
			print(-1)
			break
		else:
			s = s + f[int(u)] + f[int(y)]
	elif u == '2':
		s = s + 2 * m
if n % 2 == 1 and j[n // 2] == '2':
	s = s + m
if l:
	print(s)


(n, a, b) = map(int, input().split())
l = list(map(int, input().split()))
cost = 0
for i in range(n):
	if l[i] == 2:
		if l[n - 1 - i] == 1:
			l[i] = 1
			cost += b
		elif l[n - 1 - i] == 0:
			l[i] = 0
			cost += a
		elif a <= b:
			l[i] = 0
			cost += a
		else:
			l[i] = 1
			cost += b
if l == l[::-1]:
	print(cost)
else:
	print(-1)


(m, n, k) = map(int, input().split())
money = [n, k]
l = [int(i) for i in input().split()]
count1 = l.count(1)
count0 = l.count(0)
for i in range(len(l)):
	if l[i] == 2 and i != m - 1 - i:
		if l[m - 1 - i] != 2:
			l[i] = l[m - 1 - i]
		else:
			l[i] = l[m - 1 - i] = money.index(min(money))
	elif l[i] == 2 and i == m - 1 - i:
		l[m - 1 - i] = money.index(min(money))
if l != l[::-1]:
	print(-1)
else:
	print((l.count(1) - count1) * money[1] + (l.count(0) - count0) * money[0])


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')


from sys import stdin
(n, a, b) = map(int, stdin.readline().split())
ar = list(map(int, stdin.readline().split()))
if ar == ar[::-1] and 2 not in ar:
	print(0)
else:
	ans = 0
	i = 0
	j = n - 1
	while i < j:
		if ar[i] == 1 and ar[j] == 2 or (ar[i] == 2 and ar[j] == 1):
			ans += b
			ar[i] = 1
			ar[j] = 1
		elif ar[i] == 0 and ar[j] == 2 or (ar[i] == 2 and ar[j] == 0):
			ans += a
			ar[i] = 0
			ar[j] = 0
		elif ar[i] == 2 and ar[j] == 2:
			if a <= b:
				ans += 2 * a
				ar[i] = 0
				ar[j] = 0
			else:
				ans += 2 * b
				ar[i] = 1
				ar[j] = 1
		i += 1
		j -= 1
	if n % 2 != 0:
		if ar[i] == 2:
			ans += min(a, b)
			ar[i] = 0
	if ar == ar[::-1]:
		print(ans)
	else:
		print(-1)


(n, a, b) = map(int, input().split())
l = list(map(int, input().split()))
cost = 0
if n % 2 == 0:
	l1 = l[:n // 2]
	l2 = l[n // 2:]
else:
	l1 = l[:n // 2]
	l2 = l[n // 2 + 1:]
	if l[n // 2] == 2:
		cost += min(a, b)
l2.reverse()
for i in range(n // 2):
	li = list(sorted(set([l1[i], l2[i]])))
	if len(li) == 1:
		if li[0] == 2:
			cost += min(a, b) * 2
	elif li[1] == 2:
		if li[0] == 0:
			cost += a
		else:
			cost += b
	else:
		print(-1)
		exit()
print(cost)


from math import ceil
(n, w, b) = map(int, input().split())
X = list(map(int, input().split()))
s = 0
if len(X) & 1:
	if X[len(X) // 2] == 2:
		c = min(w, b)
		X[len(X) // 2] = 1 if c == b else 0
		s += c
for i in range(len(X) // 2):
	sh = len(X) - i - 1
	if X[i] == X[sh]:
		if X[i] == 2:
			c = min(w, b)
			X[i] = 1 if c == b else 0
			X[sh] = X[i]
			s += c + c
		else:
			continue
	elif X[i] == 2:
		X[i] = X[sh]
		s += b if X[i] == 1 else w
	elif X[sh] == 2:
		X[sh] = X[i]
		s += b if X[sh] == 1 else w
	else:
		s = -1
		break
print(s)


from heapq import _heapify_max, _heappop_max
from math import log2, floor, factorial
from itertools import combinations
MOD = 1000000007

def nCr(n, r):
	f = factorial
	return f(n) / f(r) / f(n - r)
(n, a, b) = map(int, input().split())
c = list(map(int, input().split()))
cost = 0
(st, en) = (0, n - 1)
f = True
while st <= en:
	if c[st] != c[en]:
		if c[st] != 2 and c[en] != 2:
			f = False
			break
		elif c[st] == 2:
			if c[en] == 1:
				c[st] = 1
				cost += b
			else:
				c[st] = 0
				cost += a
			c[st] = c[en]
		elif c[en] == 2:
			if c[st] == 1:
				c[en] = 1
				cost += b
			else:
				c[en] = 0
				cost += a
	elif c[st] == 2 and c[en] == 2:
		if a <= b:
			c[st] = 0
			c[en] = 0
			if st != en:
				cost += a * 2
			else:
				cost += a
		else:
			c[st] = 1
			c[en] = 1
			if st != en:
				cost += b * 2
			else:
				cost += b
	st += 1
	en -= 1
if f == False:
	print(-1)
else:
	print(cost)


(n, a, b) = map(int, input().split(' '))
ip = list(map(int, input().split(' ')))
i = 0
j = n - 1
tot = 0
flag = True
minn = b
if a < b:
	minn = a
if n % 2 == 0:
	while i < j:
		if ip[i] == ip[j]:
			if ip[i] == 0:
				pass
			elif ip[i] == 1:
				pass
			else:
				tot += 2 * minn
		elif ip[i] + ip[j] == 2:
			tot += a
		elif ip[i] + ip[j] == 3:
			tot += b
		else:
			flag = False
			break
		i += 1
		j -= 1
else:
	while i < j:
		if ip[i] == ip[j]:
			if ip[i] == 0:
				pass
			elif ip[i] == 1:
				pass
			else:
				tot += 2 * minn
		elif ip[i] + ip[j] == 2:
			tot += a
		elif ip[i] + ip[j] == 3:
			tot += b
		else:
			flag = False
			break
		i += 1
		j -= 1
	if i == j and ip[i] == ip[j] == 2:
		tot += minn
if flag:
	print(tot)
else:
	print(-1)


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


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)
			exit(0)
		ans += c[min(a[i], a[n - 1 - i])]
if a[n // 2] == 2 and n % 2:
	ans += min(w, b)
print(ans)


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


(n, a, b) = map(int, input().split())
suits = list(map(int, input().split()))
i = 0
j = n - 1
flag = True
cost = 0
while i <= j:
	if suits[i] == suits[j] and suits[i] != 2:
		i += 1
		j -= 1
		continue
	else:
		if suits[i] == 2 and suits[j] == 1 or (suits[i] == 1 and suits[j] == 2):
			cost += b
		elif suits[i] == 2 and suits[j] == 0 or (suits[i] == 0 and suits[j] == 2):
			cost += a
		elif (suits[i] == 2 and suits[j] == 2) and i == j:
			if a <= b:
				cost += a
			else:
				cost += b
		elif (suits[i] == 2 and suits[j] == 2) and i != j:
			if a <= b:
				cost += a * 2
			else:
				cost += b * 2
		else:
			flag = False
			break
		i += 1
		j -= 1
if flag == True:
	print(cost)
else:
	print(-1)


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


def main():
	(n, a, b) = map(int, input().split())
	s = input()[::2]
	c = min(a, b)
	d = {('0', '0'): 0, ('1', '1'): 0, ('0', '2'): a, ('2', '0'): a, ('1', '2'): b, ('2', '1'): b, ('2', '2'): c * 2}
	try:
		print((c if n & 1 and s[n // 2] == '2' else 0) + sum((d[t] for t in zip(s[:n // 2], s[::-1]))))
	except KeyError:
		print(-1)
main()


(n, a, b) = [int(x) for x in input().split(' ')]
colors = [int(x) for x in input().split(' ')]
minimal_cost = 0
impossible = False
while True:
	if not colors or n == 1:
		break
	left = colors.pop(0)
	right = colors.pop()
	n -= 2
	if left < 2 and right < 2 and (left != right):
		impossible = True
		break
	if left == 2 and right == 2:
		minimal_cost += 2 * min(a, b)
	elif left == 2 and right == 1 or (left == 1 and right == 2):
		minimal_cost += b
	elif left == 2 and right == 0 or (left == 0 and right == 2):
		minimal_cost += a
if n == 1 and colors[0] == 2:
	minimal_cost += min(a, b)
if impossible:
	print(-1)
else:
	print(minimal_cost)


n = input().split(' ')
for s in range(len(n)):
	n[s] = int(n[s])
n = n[1:]
if n[0] > n[1]:
	menor = n[1]
else:
	menor = n[0]
c = input().split(' ')
for s in range(len(c)):
	c[s] = int(c[s])
m = True
(i, j) = (0, -1)
salida = 0
if len(c) % 2 == 1 and c[int(len(c) / 2)] == 2:
	salida += menor
while i < int(len(c) / 2):
	if c[i] == 2 and c[j] == 2:
		salida += menor * 2
	elif c[i] == 2:
		salida += n[c[j]]
	elif c[j] == 2:
		salida += n[c[i]]
	elif c[i] != c[j]:
		salida = -1
		break
	i += 1
	j -= 1
print(salida)


I = lambda : map(int, input().split())
(n, a, b) = I()
C = list(I())
s = 0
for i in range(n):
	if 2 > C[i] != C[-i - 1] < 2:
		print(-1)
		break
	if C[i] > 1:
		s += min(a, b) if C[-i - 1] > 1 else a if C[-i - 1] < 1 else b
else:
	print(s)


from sys import stdin, stdout
from collections import Counter

def ai():
	return list(map(int, stdin.readline().split()))

def ei():
	return map(int, stdin.readline().split())

def ip():
	return int(stdin.readline().strip())

def op(ans):
	return stdout.write(str(ans) + '\n')
(n, a, b) = ei()
li = ai()
check = [a, b]
if li == li[::-1] and 2 not in li:
	print(0)
	exit()
i = 0
j = n - 1
cost = 0
while i <= j:
	if i == j and li[i] == 2:
		li[i] == check.index(min(check))
		cost += min(check)
	elif li[i] == 2 and li[j] == 1:
		li[i] = 1
		cost += check[1]
	elif li[i] == 2 and li[j] == 0:
		li[i] = 0
		cost += check[0]
	elif li[j] == 2 and li[i] == 1:
		li[j] = 1
		cost += check[1]
	elif li[j] == 2 and li[i] == 0:
		li[j] = 0
		cost += check[0]
	elif li[i] == 2 and li[j] == 2:
		li[i] = li[j] = check.index(min(check))
		cost += min(check) * 2
	i += 1
	j -= 1
if li == li[::-1]:
	print(cost)
else:
	print(-1)


def main():
	(n, a, b) = map(int, input().split())
	arr = list(map(int, input().split()))
	cost = 0
	if len(arr) & 1 == 1 and arr[len(arr) // 2] == 2:
		cost += min(a, b)
	for i in range(len(arr) // 2):
		if arr[i] == 2 and arr[n - i - 1] == 2:
			cost += 2 * min(a, b)
		elif arr[i] == 2 and arr[n - i - 1] == 1:
			cost += b
		elif arr[i] == 1 and arr[n - i - 1] == 2:
			cost += b
		elif arr[i] == 0 and arr[n - i - 1] == 2:
			cost += a
		elif arr[i] == 2 and arr[n - i - 1] == 0:
			cost += a
		elif arr[i] != arr[n - i - 1]:
			print(-1)
			exit(0)
	print(cost)
main()


(n, a, b) = [int(el) for el in input().split()]
c = [int(el) for el in input().split()]
out = 0
s = min(a, b)
for i in range(int(n / 2)):
	if c[i] == 0 and c[n - i - 1] == 0 or (c[i] == 1 and c[n - i - 1] == 1):
		continue
	if c[i] == 0 and c[n - i - 1] == 1 or (c[i] == 1 and c[n - i - 1] == 0):
		print(-1)
		raise SystemExit
	if c[i] == 0 or c[n - i - 1] == 0:
		out += a
		continue
	if c[i] == 1 or c[n - i - 1] == 1:
		out = out + b
		continue
	out = out + 2 * s
if n % 2 == 0:
	print(out)
	raise SystemExit
q = int(n / 2)
if c[q] == 2:
	out = out + s
print(out)


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


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


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


a = input().split()
n = a[0]
wn = 0
bn = 0
flag = 0
b = input().split()
total = 0
if len(b) % 2 == 1 and b[int(len(b) / 2)] == '2':
	total += min(int(a[1]), int(a[2]))
for i in range(int(len(b) / 2)):
	q = int(b[i])
	w = int(b[len(b) - 1 - i])
	if q + w == 1:
		flag = 1
		break
	elif q == w:
		if q == 2:
			total += min(int(a[1]), int(a[2])) * 2
	elif q == 1 or w == 1:
		bn += 1
	else:
		wn += 1
if flag == 1:
	print(-1)
else:
	total += bn * int(a[2]) + wn * int(a[1])
	print(total)


from math import ceil
(n, a, b) = map(int, input().split())
x = (*map(int, input().split()),)
counter = 0
for (i, j) in zip(x[:ceil(n / 2)], list(reversed(x))[:ceil(n / 2)]):
	if j == 2 and i == 2:
		counter += min(a, b) * 2
	elif i == 2:
		counter += (a, b)[j]
	elif j == 2:
		counter += (a, b)[i]
	elif i != j:
		print(-1)
		exit()
print(counter - (0, min(a, b))[n % 2 != 0 and x[n // 2] == 2])


cost = [0] * 3
(n, cost[0], cost[1]) = map(int, input().split())
res = 0
c = list(map(int, input().split(' ')[:n]))
for i in range(0, n // 2):
	if c[i] != c[n - 1 - i] and c[i] + c[n - i - 1] == 1:
		print('-1')
		exit()
	elif c[i] != c[n - 1 - i]:
		res += cost[c[i] + c[n - 1 - i] - 2]
	elif c[i] == c[n - 1 - i] == 2:
		res += min(cost[0], cost[1]) * 2
if n % 2 == 1 and c[n // 2] == 2:
	res += min(cost[1], cost[0])
print(res)


(n, white, black) = [int(x) for x in input().split()]
array = [int(x) for x in input().split()]
mid = (n - 1) // 2
cost = 0
if white < black:
	min = white
else:
	min = black
for i in range(mid):
	if (array[i], array[n - 1 - i]) == (1, 0) or (array[i], array[n - 1 - i]) == (0, 1):
		cost = -1
		break
	elif (array[i], array[n - 1 - i]) == (2, 2):
		cost += 2 * min
	elif (array[i], array[n - 1 - i]) == (2, 1) or (array[i], array[n - 1 - i]) == (1, 2):
		cost += black
	elif (array[i], array[n - 1 - i]) == (2, 0) or (array[i], array[n - 1 - i]) == (0, 2):
		cost += white
if n % 2 == 1 and cost != -1:
	if array[mid] == 2:
		cost += min
if n % 2 == 0:
	i = mid
	if cost != -1:
		if (array[i], array[n - 1 - i]) == (1, 0) or (array[i], array[n - 1 - i]) == (0, 1):
			cost = -1
		elif (array[i], array[n - 1 - i]) == (2, 2):
			cost += 2 * min
		elif (array[i], array[n - 1 - i]) == (2, 1) or (array[i], array[n - 1 - i]) == (1, 2):
			cost += black
		elif (array[i], array[n - 1 - i]) == (2, 0) or (array[i], array[n - 1 - i]) == (0, 2):
			cost += white
print(cost)


n = [int(k) for k in input().split()]
m = [int(k) for k in input().split()]
b = min(n[1], n[2])
c = True
a = 0
for k in range(int(n[0] / 2)):
	if m[k] == 1 and m[n[0] - 1 - k] == 1:
		continue
	elif m[k] == 1 and m[n[0] - 1 - k] == 2:
		a += n[2]
	elif m[k] == 0 and m[n[0] - 1 - k] == 0:
		continue
	elif m[k] == 0 and m[n[0] - 1 - k] == 2:
		a += n[1]
	elif m[k] == 2 and m[n[0] - 1 - k] == 2:
		a += 2 * b
	elif m[k] == 2 and m[n[0] - 1 - k] == 1:
		a += n[2]
	elif m[k] == 2 and m[n[0] - 1 - k] == 0:
		a += n[1]
	else:
		c = False
		break
if c:
	if n[0] % 2 == 0:
		print(a)
	elif m[int(n[0] / 2)] == 2:
		print(a + b)
	else:
		print(a)
else:
	print(-1)


(n, a, b) = map(int, input().split())
List = list(map(int, input().split()))
D = {}
D[0] = a
D[1] = b
num = 0
boo = True
for i in range((n + 1) // 2):
	if List[i] == 2 and List[n - i - 1] == 2:
		if i == n - i - 1:
			num += min(a, b)
		else:
			num += 2 * min(a, b)
	elif List[i] == 2:
		num += D[List[n - i - 1]]
	elif List[n - i - 1] == 2:
		num += D[List[i]]
	elif List[i] != List[n - i - 1]:
		boo = False
		print(-1)
		break
if boo:
	print(num)


(n, c, b) = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
flag = 0
ans = 0
i = 0
j = n - 1
while i <= j:
	if a[i] == 2 and a[j] != 2:
		if a[j] == 0:
			ans += c
		else:
			ans += b
	elif a[i] == 2 and a[j] == 2 and (i != j):
		ans += min(b, c) * 2
	elif a[i] == 2 and a[j] == 2:
		ans += min(b, c)
	elif a[j] == 2 and a[i] != 2:
		if a[i] == 0:
			ans += c
		else:
			ans += b
	elif a[i] != a[j]:
		flag = 1
		break
	i += 1
	j -= 1
if flag == 0:
	print(ans)
else:
	print(-1)


import math
(n, a, b) = list(map(int, input().split(' ')))
c = [s for s in input().split(' ')]
odd = n % 2 != 0
cost = 0
m = min(a, b)
middle = math.floor(n / 2)
if odd and c[middle] == '2':
	cost = m
for i in range(middle):
	if c[i] == c[n - 1 - i] and c[i] == '2':
		cost += 2 * m
	if c[i] != c[n - 1 - i]:
		if c[i] != '2' and c[n - 1 - i] != '2':
			print(-1)
			exit()
		if c[i] == '0':
			cost += a
			continue
		if c[i] == '1':
			cost += b
			continue
		if c[i] == '2':
			if c[n - 1 - i] == '0':
				cost += a
			else:
				cost += b
print(cost)


(n, a, b) = list(map(int, input().strip().split(' ')))
arr = list(map(int, input().strip().split(' ')))
ans = 0
valid = True
new_arr = [x for x in arr]
for i in range(n // 2):
	if arr[i] == 2 and arr[n - i - 1] != 2:
		new_arr[i] = arr[n - i - 1]
		if new_arr[i] == 0:
			ans += a
		else:
			ans += b
	elif arr[n - i - 1] == 2 and arr[i] != 2:
		new_arr[n - i - 1] = arr[i]
		if arr[i] == 0:
			ans += a
		else:
			ans += b
	elif arr[i] != arr[n - i - 1]:
		ans = -1
		valid = False
		break
if a < b:
	ans += new_arr.count(2) * a
else:
	ans += new_arr.count(2) * b
if valid:
	print(ans)
else:
	print(-1)


B = list(map(int, input().split()))
n = B[0]
ans = 0
A = list(map(int, input().split()))
for i in range(n):
	if 2 != A[i] != A[n - 1 - i] != 2:
		ans = -1
		break
	elif A[i] == 2:
		if A[n - 1 - i] == 2:
			ans += min(B[1], B[2])
		else:
			ans += B[A[n - 1 - i] + 1]
print(ans)


def solve():
	(n, a, b) = map(int, input().split(' '))
	costs = [a, b]
	c = list(map(int, input().split(' ')))
	cheaper = 0
	if b < a:
		cheaper = 1
	cost = 0
	l = len(c)
	for i in range(0, int(l / 2)):
		left = c[i]
		right = c[l - i - 1]
		if left != 2 or right != 2:
			if left == 2 or right == 2:
				cost += costs[left + right - 2]
			elif left != right:
				print(-1)
				return
		else:
			cost += costs[cheaper] * 2
	if l % 2 == 1 and c[int(l / 2)] == 2:
		cost += costs[cheaper]
	print(cost)
solve()


(n, white, black) = map(int, input().split())
l = [int(x) for x in input().split()]
cost = 0
f = 0
if n == 1:
	if l[0] == 2:
		cost += min(white, black)
elif n % 2 == 1:
	for i in range(n // 2):
		if l[i] == 0 and l[n - 1 - i] == 2 or (l[i] == 2 and l[n - 1 - i] == 0):
			cost += white
		elif l[i] == 1 and l[n - 1 - i] == 2 or (l[i] == 2 and l[n - 1 - i] == 1):
			cost += black
		elif l[i] == 2 and l[n - i - 1] == 2:
			cost += 2 * min(white, black)
		elif l[i] == 1 and l[n - 1 - i] == 0 or (l[i] == 0 and l[n - 1 - i] == 1):
			f = 1
		else:
			continue
	if l[n // 2] == 2:
		cost += min(white, black)
else:
	for i in range(n // 2):
		if l[i] == 0 and l[n - 1 - i] == 2 or (l[i] == 2 and l[n - 1 - i] == 0):
			cost += white
		elif l[i] == 1 and l[n - 1 - i] == 2 or (l[i] == 2 and l[n - 1 - i] == 1):
			cost += black
		elif l[i] == 1 and l[n - 1 - i] == 0 or (l[i] == 0 and l[n - 1 - i] == 1):
			f = 1
		elif l[i] == 2 and l[n - i - 1] == 2:
			cost += 2 * min(white, black)
		else:
			continue
if f == 0:
	print(cost)
else:
	print('-1')


Input = lambda : map(int, input().split())
List = list(Input())
suit = list(Input())
left = cost = 0
right = List[0] - 1
while left <= right:
	if suit[left] == suit[right] == 2:
		if left == right:
			cost += min(List[1], List[2])
		else:
			cost += min(List[1], List[2]) * 2
	elif suit[left] != suit[right]:
		if suit[left] != 2 and suit[right] != 2:
			print(-1)
			exit()
		elif suit[left] == 2:
			if suit[right] == 0:
				cost += List[1]
			else:
				cost += List[2]
		elif suit[left] == 0:
			cost += List[1]
		else:
			cost += List[2]
	else:
		pass
	left += 1
	right -= 1
print(cost)


(n, a, b) = map(int, input().split())
c = list(map(int, input().split()))
m = min(a, b)
ans = 0
for i in range(n // 2):
	s = set((c[i], c[-1 - i]))
	if s == {0, 1}:
		print(-1)
		exit()
	if 2 in s:
		s.remove(2)
		if len(s):
			ans += (a, b)[s.pop()]
		else:
			ans += 2 * m
ans += m * (n % 2) * (c[n // 2] == 2)
print(ans)


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


(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, wc, bc) = map(int, input().split())
ds = input().split()
low_cost = min(wc, bc)
cost = 0
for (i, d) in enumerate(ds):
	dc = ds[n - i - 1]
	if d == '2':
		if dc == '0':
			cost += wc
		elif dc == '1':
			cost += bc
		else:
			cost += low_cost
	elif dc != '2' and d != dc:
		cost = -1
		break
print(cost)


def as3eem(n, w, b, l, ans):
	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):
			ans = -1
			break
		if l[i] == 0 and l[n - i - 1] == 2 or (l[i] == 2 and l[n - i - 1] == 0):
			ans += w
		if l[i] == 1 and l[n - i - 1] == 2 or (l[i] == 2 and l[n - i - 1] == 1):
			ans += b
		if l[i] == 2 and l[n - i - 1] == 2:
			ans += 2 * min(w, b)
	if n % 2 != 0 and ans != -1 and (l[n // 2] == 2):
		ans += min(w, b)
	print(ans)
(n, w, b) = map(int, input().split())
l = list(map(int, input().split()))
ans = 0
as3eem(n, w, b, l, ans)


def solve():
	(n, a, b) = map(int, input().split())
	colors = [int(k) for k in input().split()]
	res = 0
	for i in range(n // 2):
		if colors[i] != colors[n - i - 1] and (colors[i] != 2 and colors[n - i - 1] != 2):
			print(-1)
			return
		if colors[i] == colors[n - i - 1]:
			if colors[i] != 2:
				continue
			res += 2 * min(a, b)
			continue
		if colors[i] == 2:
			res += a if colors[n - i - 1] == 0 else b
		else:
			res += a if colors[i] == 0 else b
	if n % 2 != 0 and colors[n // 2] == 2:
		res += min(a, b)
	print(res)
solve()


(n, a, b) = map(int, input().split())
q = list(map(int, input().split()))
num = 0
if n % 2 != 0:
	mid = q[n // 2]
	flag = True
	if mid == 2:
		num += min(a, b)
	q1 = q[:n // 2]
	q2 = q[n // 2 + 1:]
	q2 = q2[::-1]
	for i in range(len(q1)):
		if q1[i] == 0 and q2[i] == 2:
			num += a
		elif q1[i] == 0 and q2[i] == 0:
			continue
		elif q1[i] == 0 and q2[i] == 1:
			flag = False
			break
		elif q1[i] == 1 and q2[i] == 2:
			num += b
		elif q1[i] == 1 and q2[i] == 0:
			flag = False
			break
		elif q1[i] == 1 and q2[i] == 1:
			continue
		elif q1[i] == 2 and q2[i] == 0:
			num += a
		elif q1[i] == 2 and q2[i] == 1:
			num += b
		elif q1[i] == 2 and q2[i] == 2:
			num += 2 * min(a, b)
else:
	flag = True
	q1 = q[:n // 2]
	q2 = q[n // 2:]
	q2 = q2[::-1]
	for i in range(len(q1)):
		if q1[i] == 0 and q2[i] == 2:
			num += a
		elif q1[i] == 0 and q2[i] == 0:
			continue
		elif q1[i] == 0 and q2[i] == 1:
			flag = False
			break
		elif q1[i] == 1 and q2[i] == 2:
			num += b
		elif q1[i] == 1 and q2[i] == 0:
			flag = False
			break
		elif q1[i] == 1 and q2[i] == 1:
			continue
		elif q1[i] == 2 and q2[i] == 0:
			num += a
		elif q1[i] == 2 and q2[i] == 1:
			num += b
		elif q1[i] == 2 and q2[i] == 2:
			num += 2 * min(a, b)
if flag:
	print(num)
else:
	print(-1)


(a, w, b) = (int(i) for i in input().split())
p = [int(i) for i in input().split()]
q = [p[-b] for b in range(1, a + 1)]
c = zip(p, q)
x = 0
for k in c:
	if sum(k) == 1:
		print('-1')
		quit()
	elif sum(k) == 2:
		if 2 in k:
			x += w
	elif sum(k) == 3:
		x += b
	elif sum(k) == 4:
		x += 2 * min(w, b)
print(x // 2)


mylist = list(map(int, input().split()))
mylist2 = list(map(int, input().split()))
newlist = []
if mylist[1] >= mylist[2]:
	least = 1
else:
	least = 0
n = mylist[0]
dancers = mylist2
invdancers = dancers[::-1]
mycost = 0
flag = 0
if n % 2 == 0:
	a = len(dancers) // 2
else:
	a = len(dancers) // 2 + 1
for i in range(0, a):
	if dancers[i] != invdancers[i]:
		if dancers[i] == 0 or dancers[i] == 1:
			if invdancers[i] == 0 or invdancers[i] == 1:
				flag = 1
	if dancers[i] == 2 and invdancers[i] == 2:
		if n % 2 == 0:
			newlist = newlist + [least] + [least]
		elif i != n // 2:
			newlist = newlist + [least] + [least]
		else:
			newlist = newlist + [least]
	elif dancers[i] == 2 and invdancers[i] == 2:
		newlist = newlist + [least]
	elif dancers[i] == 2 and invdancers[i] == 0:
		newlist = newlist + [0]
	elif dancers[i] == 2 and invdancers[i] == 1:
		newlist = newlist + [1]
	elif dancers[i] == 0 and invdancers[i] == 2:
		newlist = newlist + [0]
	elif dancers[i] == 1 and invdancers[i] == 2:
		newlist = newlist + [1]
mycost = newlist.count(0) * mylist[1] + newlist.count(1) * mylist[2]
if flag == 0:
	print(mycost)
else:
	print('-1')


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


line = str(input()).split(' ')
n = int(line[0])
a = int(line[1])
b = int(line[2])
string = str(input()).split(' ')
counter = 0
cheaper = min(a, b)
cost = 0
while counter < int((len(string) + 1) / 2):
	mirror = len(string) - 1 - counter
	if string[counter] is '2' and string[mirror] is '2':
		if counter is mirror:
			cost += cheaper
		else:
			cost += 2 * cheaper
		string[counter] = str(cheaper)
		string[mirror] = str(cheaper)
	elif string[counter] is '0' and string[mirror] is '2':
		cost += a
		string[mirror] = '0'
	elif string[counter] is '2' and string[mirror] is '0':
		cost += a
		string[counter] = '0'
	elif string[counter] is '1' and string[mirror] is '2':
		cost += b
		string[mirror] = '1'
	elif string[counter] is '2' and string[mirror] is '1':
		cost += b
		string[counter] = '1'
	elif string[counter] is not string[mirror]:
		cost = -1
		break
	counter += 1
print(cost)


(n, a, b) = list(map(int, input().split()))
arr = list(map(int, input().split()))
l = 0
r = n - 1
co = []
co.append(a)
co.append(b)
ans = 0
flag = 0
while l <= r:
	if arr[l] == 2 and arr[r] != 2:
		ans += co[arr[r]]
	elif arr[l] != 2 and arr[r] == 2:
		ans += co[arr[l]]
	elif arr[l] == 2 and arr[r] == 2:
		if l != r:
			ans += 2 * min(co[0], co[1])
		else:
			ans += min(co[0], co[1])
	elif arr[l] != 2 and arr[r] != 2 and (arr[l] != arr[r]):
		flag = 1
		print('-1')
		break
	l += 1
	r -= 1
if flag == 0:
	print(ans)


(n, a, b) = 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)


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


(n, a, b) = list(map(int, input().split()))
c = list(map(int, input().split()))
visited = [False for i in range(n)]
cost = 0
count = 0
for i in range(n):
	if visited[i]:
		continue
	if c[i] == 0 or c[i] == 1:
		count += 1
		visited[i] = True
		if c[n - i - 1] == 2:
			c[n - i - 1] = c[i]
			cost += a if c[i] == 0 else b
			if not visited[n - i - 1]:
				count += 1
				visited[n - i - 1] = True
		elif c[n - i - 1] != c[i]:
			cost = -1
			break
if cost == -1:
	print(cost)
else:
	print(cost + (n - count) * min(a, b))


WHITE = 0
BLACK = 1
NOT_DEFINED = 2

def solve():
	total_cost = 0
	for (left, right) in zip(dancers[:border], reversed(dancers[border:])):
		if left == right:
			if left == NOT_DEFINED:
				total_cost += 2 * min_cost
		elif left != NOT_DEFINED and right != NOT_DEFINED:
			return -1
		elif left == WHITE or right == WHITE:
			total_cost += costs[WHITE]
		else:
			total_cost += costs[BLACK]
	return total_cost
(n, white_cost, black_cost) = [int(num) for num in input().split(' ')]
dancers = [int(num) for num in input().split(' ')]
border = len(dancers) // 2
costs = [white_cost, black_cost]
min_cost = min(costs)
total_cost = solve()
if total_cost != -1:
	if len(dancers) % 2 == 1:
		middle_man = dancers[border]
		if middle_man == NOT_DEFINED:
			total_cost += min(costs)
print(total_cost)


def main():
	(n, a, b) = [int(i) for i in input().split()]
	li = [int(i) for i in input().split()]
	p = 0
	for i in range(n // 2):
		j = n - i - 1
		if li[i] == 2 and li[j] == 2:
			p += min(a, b) * 2
		elif li[i] != 2 and li[j] == 2:
			p += a if li[i] == 0 else b
		elif li[i] == 2 and li[j] != 2:
			p += a if li[j] == 0 else b
		elif li[i] != li[j]:
			print(-1)
			return
	if n % 2 and li[n // 2] == 2:
		p += min(a, b)
	print(p)
main()


(n, white, black) = map(int, input().split())
arr = list(map(int, input().split()))
if n % 2 == 0:
	cost = 0
	left = arr[0:n // 2]
	right = arr[n // 2:]
	right.reverse()
	for i in range(n // 2):
		if left[i] == 0 and right[i] == 2 or (left[i] == 2 and right[i] == 0):
			cost += white
		elif left[i] == right[i] == 1 or left[i] == right[i] == 0:
			continue
		elif left[i] == 1 and right[i] == 2 or (left[i] == 2 and right[i] == 1):
			cost += black
		elif left[i] == right[i] == 2:
			cost += 2 * min(white, black)
		else:
			print(-1)
			break
	else:
		print(cost)
else:
	cost = 0
	left = arr[0:n // 2]
	right = arr[n // 2 + 1:]
	right.reverse()
	for i in range(n // 2):
		if left[i] == 0 and right[i] == 2 or (left[i] == 2 and right[i] == 0):
			cost += white
		elif left[i] == right[i] == 1 or left[i] == right[i] == 0:
			continue
		elif left[i] == 1 and right[i] == 2 or (left[i] == 2 and right[i] == 1):
			cost += black
		elif left[i] == right[i] == 2:
			cost += 2 * min(white, black)
		else:
			print(-1)
			break
	else:
		if arr[n // 2] == 2:
			cost += min(white, black)
		print(cost)


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


from collections import deque
from math import ceil, sqrt

def ii():
	return int(input())

def si():
	return input()

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

def li():
	return list(mi())
abc = 'abcdefghijklmnopqrstuvwxyz'
(n, a, b) = mi()
a1 = li()
f = 0
c = 0
if n % 2 == 0:
	n1 = n // 2
else:
	n1 = n // 2 + 1
for i in range(n1):
	if a1[i] == a1[n - i - 1]:
		if a1[i] == 2:
			if i != n - i - 1:
				c += 2 * min(a, b)
			else:
				c += min(a, b)
		continue
	if a1[i] != 2 and a1[n - i - 1] != 2:
		f = 1
		break
	if a1[i] == 2 and a1[n - i - 1] != 2:
		if a1[n - i - 1] == 1:
			c += b
		else:
			c += a
	elif a1[n - i - 1] == 2 and a1[i] != 2:
		if a1[i] == 1:
			c += b
		else:
			c += a
	else:
		c += 2 * min(a, b)
if f == 1:
	print('-1')
else:
	print(c)


def main():
	(n, c1, c2) = 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()


import math
(n, a, b) = map(int, input().split())
lst = list(map(int, input().split()))
ans = 0
for i in range(math.ceil(n / 2)):
	if lst[i] == 2 and lst[n - i - 1] == 2 and (i != n - i - 1):
		ans += min(a, b) * 2
	elif i == n - i - 1 and lst[i] == 2:
		ans += min(a, b)
	elif lst[i] == 2 and lst[n - i - 1] == 0:
		ans += a
	elif lst[i] == 2 and lst[n - i - 1] == 1:
		ans += b
	elif lst[i] == 1 and lst[n - i - 1] == 2:
		ans += b
	elif lst[i] == 0 and lst[n - i - 1] == 2:
		ans += a
	elif lst[i] != lst[n - i - 1]:
		print(-1)
		exit()
print(ans)


import math
from operator import itemgetter
from builtins import input
from difflib import SequenceMatcher

def reduce(list):
	r = 1
	for x in list:
		r *= x
	return r
import sys

def TwoArrays(a, b, k):
	count = 0
	for m in range(k, len(a) + 1):
		for i in range(len(a) - m + 1):
			atemp = a[i:i + m]
			for kk in range(len(b) - m + 1):
				btemp = b[kk:kk + m]
				print(atemp, btemp)
				lol = len(list(set(atemp).intersection(btemp)))
				if lol >= k:
					count += 1
	return count
from collections import defaultdict
from collections import Counter

class Graphs:

	def __init__(self, vertices):
		self.V = vertices
		self.graph = []

	def append(self, u, v, w):
		self.graph.append([u, v, w])

	def findParent(self, parent, i):
		if parent[i] == i:
			return i
		return self.findParent(parent, parent[i])

	def Union(self, parent, rank, xroot, yroot):
		x = self.findParent(parent, xroot)
		y = self.findParent(parent, yroot)
		if rank[x] < rank[y]:
			parent[x] = y
		elif rank[x] > rank[y]:
			parent[y] = x
		else:
			parent[x] = y
			rank[y] += 1

	def Kruskal(self):
		i = 0
		e = 0
		ans = []
		self.graph = sorted(self.graph, key=lambda item: item[2])
		parent = []
		rank = []
		for node in range(self.V):
			parent.append(node)
			rank.append(0)
		while e < self.V - 1:
			(u, v, w) = self.graph[i]
			i += 1
			x = self.findParent(parent, u)
			y = self.findParent(parent, v)
			if x != y:
				e += 1
				ans.append([u, v, w])
				self.Union(parent, rank, x, y)
		return sum((row[2] for row in ans))

def Exchange(rates, x, s, f, m):
	while m > 0:
		maxExchange = max(rates[s])
		temp_s = s
		s = rates[s].index(maxExchange)
		if m != 2:
			x *= maxExchange
			m -= 1
		elif s == f:
			temp = sorted(rates[temp_s])[-2]
			s = rates[temp_s].index(temp)
			x *= temp
			m -= 1
		else:
			s = rates[s].index(maxExchange)
			x *= maxExchange
			m -= 1
	return x

def delArray(a):
	c = Counter(a)
	counts = sorted([x for x in c.values() if x >= 2])
	steps = 0
	for i in range(len(counts) - 1):
		steps += counts[i]
		counts[i + 1] -= counts[i]
	print(steps)
	if steps == 0:
		return len(a)
	if (len(a) - len(counts) + 1) % 2 == 0:
		return steps + (len(a) - len(counts) + 1) // 2
	else:
		return steps + (len(a) - len(counts) + 1) // 2 + 1

def makeCalendar(n, start):
	weeks = [4] * 7
	days = ['mon', 'tues', 'wed', 'thurs', 'fri', 'sat', 'sun']
	rem = n % 7
	start = days.index(start)
	while rem > 0:
		rem -= 1
		weeks[start % 7] += 1
		start += 1
	return weeks

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

def countSubs(a):
	c = Counter(a)
	if len(c) == 1:
		return len(c)
	else:
		vals = sorted(c.values())
		tot = sum(vals)
		temp = vals[0]
		total = 0
		print(vals)
		for i in range(len(vals) - 1):
			temp2 = tot - temp
			total += vals[i] * (2 ** temp2 - 1)
			temp += vals[i + 1]
		return total
from functools import reduce
import sys
import fractions
import math

def gcd(L):
	return reduce(fractions.gcd, L)

def maximumValue(a):
	maxi = -sys.maxsize
	for i in range(len(a)):
		for j in range(i, len(a)):
			temp = [int(math.fabs(x)) for x in a[i:j + 1]]
			formula = gcd(temp) * (sum(a[i:j + 1]) - max(a[i:j + 1]))
			maxi = max(formula, maxi)
	return maxi

def match(first, second):
	if len(first) == 0 and len(second) == 0:
		return True
	if len(first) > 1 and first[0] == '*' and (len(second) == 0):
		return False
	if len(first) > 1 and first[0] == '\\' or (len(first) != 0 and len(second) != 0 and (first[0] == second[0])):
		return match(first[1:], second[1:])
	if len(first) != 0 and first[0] == '*':
		return match(first[1:], second) or match(first, second[1:])
	return False

def countEquals(a):
	count = 0
	for i in range(len(a) - 1):
		if a[i] != a[i + 1]:
			count += 1
	return count + 1

def stringMerging():
	(size1, size2) = map(int, input().split(' '))
	a = input()
	b = input()
	case1 = a[0]
	case2 = b[0]
	i = 1
	j = 0
	while i < size1:
		if case1[-1] == b[j] and j < size2:
			case1 += b[j]
			j += 1
		else:
			case1 += a[i]
			i += 1
	while j < size2:
		case1 += b[j]
		j += 1
	i = 0
	j = 1
	while j < size2:
		if case2[-1] == a[i] and i < size1:
			case2 += a[i]
			i += 1
		else:
			case2 += b[j]
			j += 1
	while i < size1:
		case2 += a[i]
		i += 1
	print(case1, case2)
	print(min(countEquals(case1), countEquals(case2)))
chars = 256

def Char_countingArray(string):
	count = [0] * chars
	for i in string:
		count[ord(i)] += 1
	return count

def Fibo():

	def modiFibo(n):
		if n == 0:
			return 1
		if n == 1:
			return 1
		return 5 * modiFibo(n - 1) + 3 * modiFibo(n - 2)
	size = int(input())
	a = [int(x) for x in input().strip().split(' ')]
	num = 1
	for x in a:
		num *= x
		num %= 100
	print(modiFibo(num) % 1000)

def firstNonRepeating(string):
	count = Char_countingArray(string)
	ind = -1
	k = 0
	for i in string:
		if count[ord(i)] == 1:
			ind = k
			break
		k += 1
	return ind

def rescueCat():
	(rows, cols) = map(int, input().split(' '))
	specials = int(input())
	actual = [[0 for _ in range(cols)] for _ in range(rows)]
	copy = [[0 for _ in range(cols)] for _ in range(rows)]
	for _ in range(specials):
		(x, y, c) = map(int, input().split(' '))
		x = rows - x - 1
		actual[x][y] = c
	for i in range(rows):
		copy[i][0] += 1
		if i + actual[i][0] < rows:
			if actual[i][0] > 0:
				copy[i + actual[i][0]][0] += 1
		if actual[i][0] == -1:
			copy[i][0] = 0
	for j in range(1, cols):
		copy[0][j] += 1
		if j + actual[0][j] < cols:
			if actual[0][j] > 0:
				copy[j + actual[0][j]][0] += 1
		if actual[0][j] == -1:
			copy[0][j] = 0
	for i in range(1, rows):
		for j in range(1, cols):
			if j + actual[i][j] < cols:
				copy[i][j + actual[i][j]] += 1
			if i + actual[i][j] < rows:
				copy[i + actual[i][j]][j] += 1
			if actual[i][j] == -1:
				copy[i][j] = 0
			else:
				copy[i][j] = copy[i - 1][j] + copy[i][j - 1]
	print(copy[-1][-1])

def pairs():
	(n, k) = map(int, input().split(' '))
	count = 0
	for i in range(1, n - k + 1):
		count += (n - i) // k
	temp = (n ** 2 - n * k) // (2 * k) + (k // 2 - n % k // 2)
	print(count, ' ', temp, ' ', count - temp)

def voting():
	n = int(input())
	a = [int(x) for x in input().strip().split(' ')]
	presum = []
	presum.append(a[0])
	for i in range(1, n):
		presum.append(a[i] + presum[-1])
	votes = [0] * n
	for i in range(n - 1):
		for j in range(i + 1, n):
			temp = presum[j - 1] - presum[i]
			if temp <= a[i]:
				votes[j] += 1
			if temp <= a[j]:
				votes[i] += 1
	print(*votes)

def mineat():
	(n, h) = map(int, input().split(' '))
	a = [int(x) for x in input().strip().split(' ')]
	a = sorted(a)
	if n == h:
		print(a[-1])
	else:
		hours_left = 2 * (h - n)
		start = 2 * n - h
		i = 0
		for _ in range(n):
			if a[i] != 0:
				break
			i += 1
		a = a[i:]
		for i in range(1, a[-1] + 1):
			temp_sum = 0
			for j in range(len(a)):
				temp_sum += math.ceil(a[j] / i)
			if temp_sum <= h:
				break
		print(i)

def universe(n):
	(d, s) = map(str, input().split(' '))
	d = int(d)
	binary = [0] * len(s)
	if 'C' not in s:
		if len(s) <= d:
			print('Case #', n, ':0')
		else:
			print('Case #', n, ':IMPOSSIBLE')
	else:
		swaps = 0
		curr = 1
		for i in range(len(s)):
			if s[i] == 'C':
				binary[i] = 0
				curr *= 2
			else:
				binary[i] = curr
		i = len(s) - 2
		while i > -1:
			if sum(binary) <= d:
				break
			if binary[i] == 0:
				(binary[i + 1], binary[i]) = (binary[i], binary[i + 1])
				swaps += 1
				binary[i] /= 2
			i -= 1
		print('Case #', n, ':', swaps)

def board():
	(n, k) = map(int, input().split(' '))
	s = input()
	start = s[:k]
	su = 0
	for i in range(1, n - k + 1):
		temp = s[i:i + k]
		for (i, val) in enumerate(temp):
			if val != start[i]:
				su += 1
		start = temp
	return su

def generate_primes():
	n = 10 ** 5
	a = []
	nNew = (n - 2) // 2
	marked = [False] * (nNew + 1)
	for i in range(1, nNew + 1):
		j = i
		while i + j + 2 * i * j <= nNew:
			marked[i + j + 2 * i * j] = True
			j += 1
	if n > 2:
		a.append(2)
	for i in range(1, nNew + 1):
		if marked[i] == False:
			a.append(2 * i + 1)
	return a

def solve(A):
	a = generate_primes()
	prod = 1
	for num in A:
		prod = prod * num
	ptr = 0
	unique = 1
	i = 0
	factors = []
	while prod > 1:
		if prod % a[i] == 0:
			prod /= a[i]
			if i not in factors:
				factors.append(i)
		else:
			i += 1
	return len(factors)
import bisect

def required_primes(n):
	a = generate_primes()
	temp = n // 2
	pos_left = bisect.bisect_left(a, temp)
	left = pos_left
	right = left + 1
	while left < 0 and right < len(a) - 1:
		if a[left] + a[right] < n:
			right += 1
		elif a[left] + a[right] > n:
			left -= 1
		else:
			return (left, right)

def dance_pal():
	(a, white, black) = map(int, input().strip().split(' '))
	dress = [int(x) for x in input().strip().split(' ')]
	flag = True
	cost = 0
	for i in range(a // 2):
		if dress[i] != 2 and dress[a - 1 - i] != 2:
			if dress[i] != dress[a - 1 - i]:
				flag = False
				break
		elif dress[i] == 2 and dress[a - 1 - i] == 2:
			cost += 2 * min(white, black)
		elif dress[i] == 2:
			if dress[a - 1 - i] == 0:
				cost += white
			else:
				cost += black
		elif dress[a - 1 - i] == 2:
			if dress[i] == 0:
				cost += white
			else:
				cost += black
	if a % 2 != 0 and dress[a // 2] == 2:
		cost += min(black, white)
	if flag:
		print(cost)
	else:
		print('-1')
t = 1
while t > 0:
	t -= 1
	dance_pal()


(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, x, y) = map(int, input().strip().split())
a = list(map(int, input().strip().split()))
ans_a = 0
ans_b = 0
ans = 1
for i in range(n // 2):
	if a[i] != a[n - i - 1]:
		if a[i] == 2 or a[n - i - 1] == 2:
			if a[i] == 0 or a[n - i - 1] == 0:
				ans_a += 1
			elif a[i] == 1 or a[n - i - 1] == 1:
				ans_b += 1
		else:
			ans = 0
			break
	elif a[i] == 2 and a[n - i - 1] == 2:
		if x < y:
			ans_a += 2
		else:
			ans_b += 2
if ans:
	temp = 0
	if n % 2 == 0:
		temp = 0
	elif a[n // 2] == 2:
		temp = min(x, y)
	print(ans_a * x + ans_b * y + temp)
else:
	print(-1)


(n, whiteSuitCost, blackSuitCost) = map(int, input().split(' '))
c = [int(i) for i in input().split(' ')]
low = 0
high = n - 1
cost = 0
while low <= high:
	if c[low] == 0 and c[high] == 1 or (c[low] == 1 and c[high] == 0):
		cost = -1
		break
	elif c[low] == 0 and c[high] == 2 or (c[low] == 2 and c[high] == 0):
		cost += whiteSuitCost
	elif c[low] == 1 and c[high] == 2 or (c[low] == 2 and c[high] == 1):
		cost += blackSuitCost
	elif c[low] == c[high] == 2:
		if low != high:
			cost += 2 * min(whiteSuitCost, blackSuitCost)
		else:
			cost += min(whiteSuitCost, blackSuitCost)
	low += 1
	high -= 1
print(cost)


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


p = list(map(int, input().split()))
n = p.pop(0)
c = list(map(int, input().split()))
mp = min(p)
pr = 0
m = n // 2
if m < n / 2:
	if c[m] == 2:
		pr += mp
for i in range(m):
	l = n - i - 1
	if c[i] == 2:
		pr += mp * 2 if c[l] == 2 else p[c[l]]
	elif c[l] == 2:
		pr += p[c[i]]
	elif c[i] != c[l]:
		pr = -1
		break
print(pr)


(n, a, b) = [*map(int, input().split())]
ds = [*map(int, input().split())]
ab = [a, b]
(i, j) = (0, n - 1)
cost = 0
while i <= j:
	if ds[i] == ds[j] and ds[i] == 2:
		if i != j:
			cost += 2 * min(a, b)
		else:
			cost += min(a, b)
	elif ds[i] == 2:
		cost += ab[ds[j]]
	elif ds[j] == 2:
		cost += ab[ds[i]]
	elif ds[i] != ds[j]:
		cost = -1
		break
	i += 1
	j -= 1
print(cost)


(n, a, b) = tuple(map(int, input().strip().split(' ')))
arr = tuple(map(int, input().strip().split(' ')))
s = 0
for k in range(0, n // 2):
	if arr[k] == 0:
		if arr[n - 1 - k] == 2:
			s = s + a
		elif arr[n - 1 - k] == 1:
			s = -1
			break
	elif arr[k] == 1:
		if arr[n - 1 - k] == 2:
			s = s + b
		elif arr[n - 1 - k] == 0:
			s = -1
			break
	elif arr[n - 1 - k] == 2:
		s = s + 2 * min(a, b)
	elif arr[n - 1 - k] == 0:
		s = s + a
	else:
		s = s + b
else:
	if n % 2 == 1:
		if arr[n // 2] == 2:
			s = s + min(a, b)
print(s)


(n, a, b) = map(int, input().split())
ans = 0
L = list(map(int, input().split()))
best = 0
ok = 1
if a > b:
	best = 1
for i in range(n):
	j = n - 1 - i
	if i == j:
		if L[i] == 2:
			if best == 0:
				ans += a
			else:
				ans += b
		continue
	if L[i] == L[j]:
		if L[i] != 2:
			continue
		L[i] = L[j] = best
		if best == 0:
			ans += 2 * a
		else:
			ans += 2 * b
	else:
		if L[i] != 2 and L[j] != 2:
			ok = 0
			break
		if L[i] == 2:
			L[i] = L[j]
		else:
			L[j] = L[i]
		if L[i] == 0:
			ans += a
		else:
			ans += b
if not ok:
	print(-1)
else:
	print(ans)


(n, costw, costb) = map(int, input().split())
row = list(map(int, input().split()))

def solve():
	sumc = 0
	minc = min(costw, costb)
	maxc = max(costw, costb)
	for i in range(0, int(n / 2)):
		if row[i] != row[-(i + 1)] and row[i] != 2 and (row[-i - 1] != 2):
			return -1
		if row[i] != row[-i - 1] and (row[i] == 2 or row[-i - 1] == 2):
			if min(row[i], row[-i - 1]) == 1:
				sumc += costb
			if min(row[i], row[-i - 1]) == 0:
				sumc += costw
		if row[i] == row[-i - 1] and row[i] == 2:
			sumc += 2 * min(costw, costb)
	if n % 2 != 0:
		if row[int(n / 2)] == 2:
			sumc += min(costw, costb)
	return sumc
print(solve())


import sys
import math
get_string = lambda : sys.stdin.readline().strip()
get_int_list = lambda : list(map(int, sys.stdin.readline().strip().split()))
get_int = lambda : int(sys.stdin.readline())
(n, a, b) = get_int_list()
lst = get_int_list()
score = 0
flag = True
for i in range((n + 1) // 2):
	if lst[i] != lst[~i]:
		if lst[i] == 2 or lst[~i] == 2:
			if lst[i] == 0 or lst[~i] == 0:
				score += a
			else:
				score += b
		else:
			flag = False
			break
	elif i == (n + 1) // 2 - 1 and n % 2 != 0 and (lst[i] == 2):
		score += min(a, b)
	elif lst[i] == 2:
		score += min(a, b) * 2
if flag:
	print(score)
else:
	print(-1)


(n, c0, c1) = map(int, input().split())
S = list(map(int, input().split()))
an = 0
for i in range(len(S) // 2):
	if S[i] + S[n - 1 - i] == 1:
		an = -1
		break
	if S[i] == S[n - 1 - i]:
		if S[i] == 2:
			an += 2 * min(c0, c1)
	elif S[i] + S[n - 1 - i] == 2:
		an += c0
	else:
		an += c1
if an == -1:
	print(an)
else:
	if len(S) % 2 == 1:
		if S[n // 2] == 2:
			an += min(c0, c1)
	print(an)


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


(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)


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


(n, a, b) = map(int, input().split())
s = list(map(int, input().split()))
l = 0
r = n - 1
k = 0
while l < r:
	if s[l] == 1 and s[r] == 2:
		k += b
	if s[l] == 2 and s[r] == 1:
		k += b
	if s[l] == 0 and s[r] == 2:
		k += a
	if s[l] == 2 and s[r] == 0:
		k += a
	if s[l] == 2 and s[r] == 2:
		k += min(a, b) * 2
	if s[l] == 1 and s[r] == 0 or (s[l] == 0 and s[r] == 1):
		k = -1
		break
	l += 1
	r -= 1
if n % 2 == 1 and k != -1 and (s[n // 2] == 2):
	k += min(a, b)
if k == -1:
	print(-1)
else:
	print(k)


(n, a, b) = [int(x) for x in input().split()]
c = [int(x) for x in input().split()]
l = 0
r = len(c) - 1
cost = 0
done = False
mc = min(a, b)
while l < r:
	le = c[l]
	re = c[r]
	if le == 0 and re == 1 or (le == 1 and re == 0):
		print(-1)
		done = True
		break
	if le == 2 and re == 2:
		cost += 2 * mc
	elif le == 0 and re == 0 or (le == 1 and re == 1):
		pass
	elif le == 0 or re == 0:
		cost += a
	else:
		cost += b
	l += 1
	r -= 1
if not done:
	if l == r:
		if c[l] == 2:
			cost += mc
	print(cost)


(n, a, b) = input().split()
suits = input().split()
a = int(a)
b = int(b)
suits = [int(x) for x in suits]
cheap = a if a < b else b
expensive = a if a < b else b
left = 0
right = len(suits) - 1
success = True
summ = 0
k = 0
if len(suits) % 2 == 1:
	k = 1
k += len(suits) // 2
for i in range(k):
	if i != right - i:
		if suits[i] != suits[right - i]:
			if suits[i] == 2 and suits[right - i] == 0:
				summ += a
			elif suits[i] == 2 and suits[right - i] == 1:
				summ += b
			elif suits[right - i] == 2 and suits[i] == 0:
				summ += a
			elif suits[right - i] == 2 and suits[i] == 1:
				summ += b
			else:
				success = False
				break
		elif suits[i] == 2 and suits[i] == suits[right - i]:
			summ += cheap * 2
		else:
			continue
	elif suits[i] != 2:
		continue
	else:
		summ += cheap
if success:
	print(summ)
else:
	print(-1)


(n, w, b) = input().split()
n = int(n)
w = int(w)
b = int(b)
ar = input().split()
array = []
for i in ar:
	array.append(int(i))
i = 0
mid = (len(array) + 1) // 2
end = len(array) - 1
sums = 0
possible = True
while i < mid:
	if array[i] == 2 or array[end - i] == 2:
		if array[i] == 2 and array[end - i] == 2:
			if i == end - i:
				sums += min(w, b)
			else:
				sums += 2 * min(w, b)
		elif (array[i] == 1 or array[end - i] == 1) and i != end - i:
			sums += b
		elif (array[i] == 0 or array[end - i] == 0) and i != end - i:
			sums += w
	elif array[i] != array[end - i]:
		possible = False
		break
	i += 1
if possible == True:
	print(sums)
else:
	print(-1)


(n, a, b) = map(int, input().split())
s = [int(elem) for elem in input().split()]
ans = 0
flag = True
for i in range(n):
	if s[i] == 0 and s[n - i - 1] == 1:
		flag = False
		break
	if s[i] == 1 and s[n - i - 1] == 0:
		flag = False
		break
	if s[i] == 2:
		if s[n - i - 1] == 0:
			s[i] = 0
			ans = ans + a
		if s[n - i - 1] == 1:
			s[i] = 1
			ans = ans + b
		if s[n - i - 1] == 2:
			if a > b:
				s[i] = 1
				s[n - i - 1] = 1
				if i == n - i - 1:
					ans = ans + b
				else:
					ans = ans + b * 2
			else:
				s[i] = 0
				s[n - i - 1] = 0
				if i == n - i - 1:
					ans = ans + a
				else:
					ans = ans + 2 * a
if flag:
	print(ans)
else:
	print(-1)


import math
(n, a, b) = map(int, input().split())
a1 = list(map(int, input().split()))
c = 0
k = 0
for j in range(math.ceil(n / 2)):
	if a1[j] == 2 and a1[-(j + 1)] != 2:
		a1[j] = a1[-(j + 1)]
		if a1[j] == 0:
			k = k + a
		else:
			k = k + b
	if a1[j] != 2 and a1[-(j + 1)] == 2:
		a1[-(j + 1)] = a1[j]
		if a1[j] == 0:
			k = k + a
		else:
			k = k + b
	if a1[j] == 2 and a1[-(j + 1)] == 2:
		if n % 2 != 0 and j == math.ceil(n / 2) - 1:
			k = k + min(a, b)
		else:
			k = k + 2 * min(a, b)
	if a1[j] != a1[-(j + 1)]:
		c = 1
		break
if c == 1:
	print(-1)
else:
	print(k)


(n, w, b) = map(int, input().split())
pug = [w, b]
lis = list(map(int, input().split()))
m = n // 2
cost = 0
if n % 2 == 0:
	lis1 = lis[:m]
	lis2 = lis[m:]
else:
	lis1 = lis[:m]
	lis2 = lis[m + 1:]
for i in range(len(lis1)):
	(x, y) = (lis1[i], lis2[-i - 1])
	if x != 2 and y != 2:
		if x == y:
			pass
		else:
			cost = -1
			break
if cost != -1:
	if n % 2 != 0 and lis[m] == 2:
		cost = cost + min(pug)
	for i in range(len(lis1)):
		(x, y) = (lis1[i], lis2[-i - 1])
		if (x == 1 or x == 0) and y == 2:
			cost = cost + pug[x]
		elif x == 2 and y != 2:
			cost = cost + pug[y]
		elif x == 2 and y == 2:
			cost = cost + 2 * min(pug)
print(cost)


(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)


def solve(n, arr, w, b):
	stop = n // 2
	ans = 0
	m = min(w, b)
	if n % 2 != 0 and arr[stop] == 2:
		ans += m
	cantbe = False
	for i in range(stop):
		if arr[i] == 2 or arr[n - 1 - i] == 2:
			if arr[i] == 2 and arr[n - 1 - i] == 2:
				ans += m * 2
			elif arr[i] == 1 or arr[n - 1 - i] == 1:
				ans += b
			else:
				ans += w
		elif arr[i] != arr[n - 1 - i]:
			cantbe = True
			break
	if not cantbe:
		print(ans)
	else:
		print(-1)

def main():
	(n, white, black) = map(int, input().split())
	arr = list(map(int, input().split()))
	solve(n, arr, white, black)
main()


(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, w, b) = input().split()
(n, w, b) = (int(n), int(w), int(b))
d = [int(x) for x in input().split()]
s = 0
if n % 2:
	if d[n // 2] == 2:
		s += min(b, w)
for i in range(n // 2):
	if d[i] == d[-i - 1]:
		if d[i] == 2:
			s += 2 * min(b, w)
	elif d[i] == 2 or d[-i - 1] == 2:
		if min(d[-i - 1], d[i]) == 1:
			s += b
		else:
			s += w
	else:
		s = -1
		break
print(s)


(n, cost0, cost1) = map(int, input().split())
cheap = cost1 if cost1 < cost0 else cost0
cost = 0
ls = list(map(int, input().split()))
for i in range(n):
	if ls[i] == 0 and ls[n - i - 1] == 1 or (ls[i] == 1 and ls[n - i - 1] == 0):
		print(-1)
		break
else:
	for i in range(n):
		if ls[i] == 2:
			if ls[n - i - 1] == 2:
				cost += cheap
			else:
				cost += cost0 if ls[n - i - 1] == 0 else cost1
	print(cost)


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


(n, a, b) = map(int, input().split())
ar = list(map(int, input().split()))
q = 0
r = n // 2
w = 3
c = min(a, b)
for ind in range(0, r):
	x = ar[ind]
	y = ar[n - ind - 1]
	if x == y and y == 2:
		q += c * 2
	elif x == 0 and y == 2 or (x == 2 and y == 0):
		q += a
	elif x == 2 and y == 1 or (x == 1 and y == 2):
		q += b
	elif x == 0 and y == 1 or (x == 1 and y == 0):
		w = 5
		break
if n % 2 != 0:
	if ar[r] == 2:
		q += c
if w == 5:
	print('-1')
else:
	print(q)


line1 = input()
(n, pwhite, pblack) = line1.split(' ')
line2 = input()
mylist = line2.split(' ')
intlist = list()
for x in mylist:
	intlist.append(int(x))
totalcost = 0
cheaper = (0, pwhite) if int(pwhite) <= int(pblack) else (1, pblack)
if not len(intlist) % 2:
	pass
elif intlist[int((len(intlist) - 1) / 2)] == 2:
	totalcost += int(cheaper[1])
	intlist[int((len(intlist) - 1) / 2)] = int(cheaper[0])
for x in range(int(len(intlist) / 2)):
	if intlist[x] == 0 and intlist[len(intlist) - x - 1] == 1 or (intlist[x] == 1 and intlist[len(intlist) - x - 1] == 0):
		totalcost = -1
		break
	elif intlist[x] == 2 and intlist[len(intlist) - x - 1] == 2:
		intlist[x] = cheaper[0]
		intlist[len(intlist) - x - 1] = cheaper[0]
		totalcost += 2 * int(cheaper[1])
	elif intlist[x] == 2 and intlist[len(intlist) - x - 1] != 2:
		intlist[x] = intlist[len(intlist) - x - 1]
		if intlist[x]:
			totalcost += int(pblack)
		else:
			totalcost += int(pwhite)
	elif intlist[x] != 2 and intlist[len(intlist) - x - 1] == 2:
		intlist[len(intlist) - x - 1] = intlist[x]
		if intlist[x]:
			totalcost += int(pblack)
		else:
			totalcost += int(pwhite)
	else:
		k = 1
print(totalcost)


[n, w, b] = map(int, input().split())
row = list(map(int, input().split()))
ret = 0
middle = int(n / 2)
if middle * 2 < n:
	middle = middle + 1
for i in range(0, middle):
	if 2 == row[i]:
		if row[i] == row[n - i - 1]:
			ret = ret + min(w, b)
			if i != n - i - 1:
				ret = ret + min(w, b)
		elif row[n - i - 1] == 0:
			ret = ret + w
		elif row[n - i - 1] == 1:
			ret = ret + b
	elif 0 == row[i]:
		if row[i] == row[n - i - 1]:
			continue
		elif row[n - i - 1] == 2:
			ret = ret + w
		elif row[n - i - 1] == 1:
			ret = -1
			break
	elif row[i] == row[n - i - 1]:
		continue
	elif row[n - i - 1] == 2:
		ret = ret + b
	elif row[n - i - 1] == 0:
		ret = -1
		break
print(ret)


from sys import stdin
from math import ceil
(n, a, b) = [int(i) for i in stdin.readline().split(' ')]
colors = [int(i) for i in stdin.readline().split(' ')]
price = 0
for i in range(0, ceil(n / 2)):
	if set([colors[i], colors[-(i + 1)]]) == set([0, 2]):
		price += a
	elif set([colors[i], colors[-(i + 1)]]) == set([1, 2]):
		price += b
	elif set([colors[i], colors[-(i + 1)]]) == set([2]):
		price += (2 - (i == ceil(n / 2) - 1 and n % 2 == 1)) * min(a, b)
	elif set([colors[i], colors[-(i + 1)]]) == set([0, 1]):
		price = -1
		break
print(price)


(n, a, b) = list(map(int, input().split()))
t = list(map(int, input().split()))
if n % 2 != 0:
	l = t[0:n // 2]
	r = t[n // 2 + 1:][::-1]
else:
	l = t[0:n // 2]
	r = t[n // 2:][::-1]
p = 0
s = 0
for k in range(n // 2):
	if l[k] == r[k] and l[k] != 2:
		pass
	elif l[k] == r[k] and l[k] == 2:
		p += min(a, b) * 2
	elif l[k] != r[k]:
		z = [l[k], r[k]]
		z.sort()
		if z[-1] == 2:
			if z[0] == 1:
				p += b
			else:
				p += a
		else:
			print(-1)
			s += 1
			break
if s == 0:
	if n == 1:
		if t[0] == 2:
			print(min(a, b))
		else:
			print(0)
	elif n % 2 == 0:
		print(p)
	elif t[n // 2] == 2:
		print(p + min(a, b))
	else:
		print(p)


(n, a, b) = list(map(int, input().split()))
costume = list(map(int, input().split()))
cost = [a, b]
best = min(a, b)
for i in range(n // 2):
	if costume[i] == 1 and costume[-1 - i] == 0:
		print(-1)
		exit()
	elif costume[i] == 0 and costume[-1 - i] == 1:
		print(-1)
		exit()
res = 0
for i in range(n // 2):
	(x, y) = (min(costume[i], costume[-1 - i]), max(costume[i], costume[-1 - i]))
	if x == 2:
		res += 2 * best
	elif y == 2:
		res += cost[x]
if n % 2 == 1:
	if costume[n // 2] == 2:
		res += best
print(res)


(n, w, b) = map(int, input().split())
xs = list(map(int, input().split()))
minv = w if w < b else b
cost = 0
l = n // 2 if n % 2 == 0 else n // 2 + 1
for i in range(l):
	(x, y) = (xs[i], xs[n - 1 - i])
	ratio = 1 if i == n - 1 - i else 2
	if x == y:
		if x == 2:
			cost += minv * ratio
	elif x == 2:
		if y == 0:
			cost += w
		else:
			cost += b
	elif y == 2:
		if x == 0:
			cost += w
		else:
			cost += b
	else:
		cost = -1
		break
print(cost)


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


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


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


(n, a, b) = tuple(map(int, input().split()))
s = list(map(int, input().split()))
ans = 0
for i in range(len(s) // 2):
	if s[i] != s[len(s) - i - 1] and s[i] + s[len(s) - i - 1] == 1:
		print(-1)
		exit(0)
	elif s[i] != s[len(s) - i - 1] and s[i] + s[len(s) - i - 1] == 2:
		ans += a
	elif s[i] != s[len(s) - i - 1] and s[i] + s[len(s) - i - 1] == 3:
		ans += b
	elif s[i] + s[len(s) - i - 1] == 4:
		ans += min(a, b) * 2
if s[len(s) // 2] == 2 and len(s) % 2 != 0:
	ans += min(a, b)
print(ans)


import math
(n, A, b) = [int(x) for x in input().split()]
a = list(map(int, input().split()))
ans = 0
for i in range(n // 2):
	if a[i] != a[n - i - 1] and a[i] != 2 and (a[n - i - 1] != 2):
		print(-1)
		exit()
	if a[i] == a[n - i - 1] and a[i] != 2:
		continue
	if a[i] == 0:
		a[n - i - 1] = 0
		ans += A
		continue
	if a[i] == 1:
		a[n - i - 1] = 1
		ans += b
	if a[i] == 2:
		if a[n - i - 1] == 1:
			a[i] = 1
			ans += b
		elif a[n - i - 1] == 0:
			a[i] = 0
			ans += A
		else:
			ans += 2 * min(A, b)
if n & 1:
	if a[n // 2] == 2:
		ans += min(A, b)
print(ans)


gi = lambda : list(map(int, input().split()))
(n, a, b) = gi()
l = gi()
cheap = min(a, b)
d = {0: a, 1: b}
test = True
price = 0
for i in range(n // 2):
	if l[i] != l[n - 1 - i] and l[i] != 2 and (l[n - 1 - i] != 2):
		test = False
		print(-1)
		break
	elif l[i] == 2:
		if l[n - 1 - i] == 2:
			price += 2 * cheap
		else:
			price += d[l[n - 1 - i]]
	elif l[n - 1 - i] == 2:
		if l[i] == 2:
			price += 2 * cheap
		else:
			price += d[l[i]]
if test:
	if n % 2 == 1 and l[n // 2] == 2:
		price += cheap
	print(price)


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


z = lambda : map(int, input().split())
(a, b, c) = z()
d = input().replace(' ', '')
i = 0
s = 0
while i < a // 2:
	if d[i] == d[a - i - 1] == '2':
		s += 2 * min(b, c)
	elif d[i] in '01' and d[a - i - 1] not in '01':
		s += b if d[i] == '0' else c
	elif d[a - i - 1] in '01' and d[i] not in '01':
		s += b if d[a - i - 1] == '0' else c
	elif d[a - i - 1] != d[i]:
		exit(print(-1))
	i += 1
if a & 1:
	s += 0 if d[a // 2] in '01' else min(b, c)
print(s)


import sys
import math
r = sys.stdin.readline()
s = r.split()
n = int(s[0])
a = int(s[1])
b = int(s[2])
least = min(a, b)
costs = {'0': a, '1': b, '2': least}
arr = sys.stdin.readline().split()

def m(n, arr, costs):
	cost = 0
	for i in range(int(n / 2)):
		j = n - 1 - i
		o = arr[i]
		t = arr[j]
		if o == '2':
			if t == '2':
				cost += costs['2'] * 2
			else:
				cost += costs[t]
		elif t == '2':
			cost += costs[o]
		elif o != t:
			return -1
	if n % 2 != 0:
		last = arr[int(n / 2)]
		if last == '2':
			cost += costs[last]
	return cost
print(m(n, arr, costs))


def check(dancer, n):
	for i in range(n):
		if dancer[i] != 2 and dancer[-(i + 1)] != 2 and (dancer[i] != dancer[-(i + 1)]):
			return False
	return True
(n, a, b) = map(int, input().split())
dancer = list(map(int, input().split()))
original_price = 0
price = 0
for i in dancer:
	if i == 0:
		original_price += a
	elif i == 1:
		original_price += b
if check(dancer, n) == False:
	print(-1)
else:
	for i in range(n):
		if dancer[i] != dancer[-(i + 1)] and dancer[i] != 2:
			dancer[-(i + 1)] = dancer[i]
		else:
			dancer[i] = dancer[-(i + 1)]
	for i in dancer:
		if i == 0:
			price += a
		elif i == 1:
			price += b
		else:
			price += min(a, b)
	print(price - original_price)


(n, a, b) = map(int, input().split())
c = list(map(int, input().split()))
if (0, 1) in zip(c, c[::-1]):
	print(-1)
else:
	print(sum([[a, b, min(a, b)][y] for (x, y) in zip(c, c[::-1]) if x > 1]))


(n, w, b) = [int(x) for x in input().split()]
arr = [int(x) for x in input().split()]
cost = 0
for i in range(len(arr) // 2):
	if arr[i] == 1 and arr[n - i - 1] == 0:
		print(-1)
		exit()
	if arr[i] == 0 and arr[n - i - 1] == 1:
		print(-1)
		exit()
	if arr[i] == arr[n - i - 1] and arr[i] != 2:
		continue
	elif arr[i] == arr[n - i - 1] and arr[i] == 2:
		cost = cost + min(w, b) * 2
	elif arr[i] == 1 and arr[n - i - 1] == 2:
		cost += b
	elif arr[i] == 0 and arr[n - i - 1] == 2:
		cost += w
	elif arr[i] == 2 and arr[n - i - 1] == 1:
		cost += b
	elif arr[i] == 2 and arr[n - i - 1] == 0:
		cost += w
if len(arr) % 2 != 0:
	if arr[len(arr) // 2] == 2:
		cost += min(w, b)
print(cost)


import sys
import math
import itertools
import collections

def getdict(n):
	d = {}
	if type(n) is list or type(n) is str:
		for i in n:
			if i in d:
				d[i] += 1
			else:
				d[i] = 1
	else:
		for i in range(n):
			t = ii()
			if t in d:
				d[t] += 1
			else:
				d[t] = 1
	return d

def cdiv(n, k):
	return n // k + (n % k != 0)

def ii():
	return int(input())

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

def li():
	return list(map(int, input().split()))

def lcm(a, b):
	return abs(a * b) // math.gcd(a, b)

def wr(arr):
	return '\n'.join(map(str, arr))

def revn(n):
	return int(str(n)[::-1])

def prime(n):
	if n == 2:
		return True
	if n % 2 == 0 or n <= 1:
		return False
	sqr = int(math.sqrt(n)) + 1
	for d in range(3, sqr, 2):
		if n % d == 0:
			return False
	return True
(n, a, b) = mi()
c = li()
for i in range(n // 2):
	if c[i] ^ c[-i - 1] == 1:
		exit(print(-1))
ans = 0
for i in range(n // 2):
	if [c[i], c[-i - 1]].count(2) == 2:
		ans += min(a, b) * 2
	elif [c[i], c[-i - 1]].count(2) == 1:
		t = c[i] + c[-i - 1] - 2
		ans += (1 - t) * a + t * b
if n % 2 == 1 and c[n // 2] == 2:
	ans += min(a, b)
print(ans)


import os
from sys import stdin
max_val = int(10000000000000.0)
min_val = int(-10000000000000.0)

def read_int():
	return int(stdin.readline())

def read_ints():
	return [int(x) for x in stdin.readline().split()]

def read_str():
	return input()

def read_strs():
	return [x for x in stdin.readline()]

def read_str_list():
	return [x for x in stdin.readline().split()]
(nol, cost_white, cost_black) = read_ints()
cost = [cost_white, cost_black]
series = read_ints()
ans = 0
if nol % 2 == 1:
	(l, r) = (nol // 2, nol // 2)
else:
	(l, r) = (nol // 2 - 1, nol // 2)
while l >= 0 and r < nol:
	if series[l] == series[r]:
		if series[l] == 2:
			if l == r:
				ans += min(cost)
			else:
				ans += min(cost) * 2
	elif series[l] != series[r]:
		if series[l] == 2:
			ans += cost[series[r]]
		elif series[r] == 2:
			ans += cost[series[l]]
		else:
			ans = -1
			break
	l -= 1
	r += 1
print(ans)


d = [0, 0]
(n, d[0], d[1]) = list(map(int, input().split()))
dress = list(map(int, input().split()))
cost = 0
mid = n // 2
if n % 2 == 1:
	mid += 1
for i in range(mid):
	if dress[i] in {0, 1} and dress[n - i - 1] in {0, 1}:
		if dress[i] == dress[n - i - 1]:
			continue
		else:
			print(-1)
			break
	elif dress[i] in {0, 1}:
		cost += d[dress[i]]
	elif dress[n - i - 1] in {0, 1}:
		cost += d[dress[n - i - 1]]
	elif i == mid - 1 and n % 2 == 1:
		cost += min(*d)
	else:
		cost += 2 * min(*d)
else:
	print(cost)


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


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


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


I = lambda : map(int, input().split())
(n, a, b) = I()
c = list(I())
cost = 0
m = min(a, b)
for i in range(n // 2):
	if c[i] == c[n - i - 1] == 2:
		cost += 2 * m
	elif c[i] != c[n - i - 1] and c[i] != 2 and (c[n - i - 1] != 2):
		exit(print(-1))
	elif c[i] == c[n - i - 1]:
		continue
	elif c[i] == 1 and c[n - i - 1] == 2 or (c[i] == 2 and c[n - i - 1] == 1):
		cost += b
	elif c[i] == 0 and c[n - i - 1] == 2 or (c[i] == 2 and c[n - i - 1] == 0):
		cost += a
if n % 2 == 1 and c[n // 2] == 2:
	cost += m
print(cost)


import sys
import math
input = sys.stdin.readline
(n, a, b) = (int(i) for i in input().split())
l = [int(i) for i in input().split()]
s = 0
c = 1
for i in range(n // 2):
	if l[i] == 2 and l[n - i - 1] == 2:
		s += 2 * min(a, b)
	elif l[i] == 2:
		if l[n - i - 1] == 1:
			s += b
		else:
			s += a
	elif l[n - i - 1] == 2:
		if l[i] == 1:
			s += b
		else:
			s += a
	elif l[i] != l[n - i - 1]:
		c = 0
		break
if n % 2 != 0:
	if l[n // 2] == 2:
		s += min(a, b)
if c == 0:
	print(-1)
else:
	print(s)


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


R = lambda : map(int, input().split())
(n, *a) = R()
c = [*R()]
a += [min(a)]
s = 1
for (x, y) in zip(c, c[::-1]):
	if x ^ y == 1:
		s = 0
		break
	s += (x == 2) * a[y]
print(s - 1)


(n, a, b) = [int(x) for x in input().split(' ')]
cheap = min(a, b)
dancers = [int(x) for x in input().split(' ')]
costs = [a, b, 0]
cost = 0
if n % 2 != 0 and dancers[n // 2] == 2:
	cost += cheap
for i in range(n // 2):
	left = dancers[i]
	right = dancers[n - 1 - i]
	if left != 2 and right != 2 and (left != right):
		print(-1)
		exit(0)
	if left == right and left != 2:
		continue
	if left == 2 and right == 2:
		cost += 2 * cheap
	else:
		cost += costs[left]
		cost += costs[right]
print(cost)


def main():
	(n, white_price, black_price) = map(int, input().split())
	prices = (white_price, black_price)
	min_price = min(prices[0], prices[1])
	total_min_price = 0
	arrangement = list(map(int, input().split()))
	for i in range((n + 1) // 2):
		otherIdx = n - i - 1
		if arrangement[i] == 2:
			if arrangement[otherIdx] == 2:
				total_min_price += min_price * (2 if i != otherIdx else 1)
			else:
				total_min_price += prices[arrangement[otherIdx]]
		elif arrangement[otherIdx] == 2:
			total_min_price += prices[arrangement[i]]
		elif arrangement[i] != arrangement[otherIdx]:
			print(-1)
			return
	print(total_min_price)
main()


def go():
	(n, a, b) = [int(i) for i in input().split(' ')]
	x = [int(i) for i in input().split(' ')]
	total = 0
	for i in range(n // 2):
		if x[i] == 1 and x[n - 1 - i] == 0 or (x[i] == 0 and x[n - 1 - i] == 1):
			return -1
		elif x[i] == 2 and x[i] == x[n - 1 - i]:
			total += 2 * min(a, b)
		elif x[i] == 2:
			if x[n - i - 1] == 1:
				total += b
			else:
				total += a
		elif x[n - i - 1] == 2:
			if x[i] == 1:
				total += b
			else:
				total += a
	if n % 2 == 1 and x[n // 2] == 2:
		total += min(a, b)
	return total
print(go())


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


s = input().split()
(n, a, b) = (int(s[0]), int(s[1]), int(s[2]))
cl = list(map(int, input().split()))
pl = cl[::-1]
res = 0
dic = {}
dic.update({0: a})
dic.update({1: b})
mn = min(a, b)
for i in range(n // 2):
	if cl[i] != pl[i]:
		if cl[i] == 2 and pl[i] != 2:
			res += dic[pl[i]]
		elif cl[i] != 2 and pl[i] == 2:
			res += dic[cl[i]]
		else:
			print(-1)
			exit()
	elif cl[i] == 2:
		res += 2 * mn
if n % 2 == 0:
	print(res)
else:
	if cl[n // 2] == 2:
		res += mn
	print(res)


(n, white, black) = map(int, input().split())
l = list(map(int, input().split()))
r = n - 1
ls = 0
cnt = 0
while r >= ls:
	if r == ls:
		if l[r] != 1 and l[ls] != 0:
			cnt += min(white, black)
		r -= 1
		ls += 1
		continue
	if l[ls] == 2:
		if l[r] == 0:
			cnt += white
		elif l[r] == 1:
			cnt += black
		else:
			cnt += min(white, black) * 2
	elif l[ls] == 1:
		if l[r] == 2:
			cnt += black
		elif l[r] == 1:
			pass
		else:
			print(-1)
			break
	elif l[r] == 2:
		cnt += white
	elif l[r] == 0:
		pass
	else:
		print(-1)
		break
	r -= 1
	ls += 1
else:
	print(cnt)


def readint():
	return int(input())

def readline():
	return [int(c) for c in input().split()]

def main():
	(n, a, b) = readline()
	c = readline()
	_min = a if a <= b else b
	cheapest = 0 if a <= b else 1
	price = 0
	for i in range(n // 2):
		j = n - i - 1
		if c[i] == 2 and c[j] == 2:
			price += _min * 2
		elif c[i] == 2 and c[j] == 1:
			price += b
		elif c[i] == 2 and c[j] == 0:
			price += a
		elif c[i] == 1 and c[j] == 2:
			price += b
		elif c[i] == 0 and c[j] == 2:
			price += a
		elif c[i] != 2 and c[j] != 2 and (c[i] != c[j]):
			print('-1')
			return
	if n % 2 != 0:
		if c[n // 2] == 2:
			price += _min
	print(price)
main()


(n, white_cost, black_cost) = map(int, input().split())
lis = list(map(int, input().split()))
lis2 = lis[::-1]
ans = 0
for i in range(len(lis) // 2):
	if lis[i] == lis2[i] and lis[i] != 2:
		continue
	elif lis[i] != 2 and lis2[i] != 2:
		print(-1)
		exit()
	else:
		a = abs(lis[i] - lis2[i])
		if a == 2:
			ans += white_cost
		elif a == 1:
			ans += black_cost
		else:
			ans += 2 * min(white_cost, black_cost)
if len(lis) % 2 == 1:
	l = len(lis) // 2
	if lis[l] == 2:
		ans += min(white_cost, black_cost)
print(ans)


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


import sys
(n, w, b) = map(int, input().split())
ls = list(map(int, input().split()))
if w > b:
	small = b
else:
	small = w
cost = 0
if n % 2 == 0:
	for i in range(n // 2):
		if ls[i] == ls[n - 1 - i]:
			if ls[i] == 2:
				cost += small * 2
		elif ls[i] == 0 and ls[n - 1 - i] == 1 or (ls[i] == 1 and ls[n - 1 - i] == 0):
			print(-1)
			sys.exit()
		elif ls[i] == 0 or ls[n - i - 1] == 0:
			cost += w
		else:
			cost += b
else:
	for i in range(n // 2):
		if ls[i] == ls[n - 1 - i]:
			if ls[i] == 2:
				cost += small * 2
		elif ls[i] == 0 and ls[n - 1 - i] == 1 or (ls[i] == 1 and ls[n - 1 - i] == 0):
			print(-1)
			sys.exit()
		elif ls[i] == 0 or ls[n - i - 1] == 0:
			cost += w
		else:
			cost += b
	if ls[n // 2] == 2:
		cost += small
print(cost)


(n, a, b) = map(int, input().split())
c = list(map(int, input().split()))
flag = True
res = 0
mn = min(a, b)
for i in range((n + 1) // 2):
	fst = c[i]
	snd = c[n - i - 1]
	if fst == 2 and snd == 2:
		if i == n // 2:
			res += mn
		else:
			res += 2 * mn
	elif fst == 2:
		if snd == 0:
			res += a
		else:
			res += b
	elif snd == 2:
		if fst == 0:
			res += a
		else:
			res += b
	elif fst != snd:
		flag = False
		break
if not flag:
	res = -1
print(res)


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


(n, w, b) = [int(s) for s in input().split(' ')]
arr = list(map(int, input().split()))
l = len(arr)
cost = 0
if w <= b:
	min = w
	max = b
else:
	min = b
	max = w
if l % 2 == 0:
	for i in range(int(l / 2)):
		if arr[i] == 1 or arr[i] == 0:
			if arr[l - 1 - i] != 2:
				if arr[l - 1 - i] != arr[i]:
					print(-1)
					exit(0)
			elif arr[l - 1 - i] == 2:
				if arr[i] == 1:
					cost += b
				elif arr[i] == 0:
					cost += w
		else:
			if arr[l - 1 - i] == 1:
				cost += b
			if arr[l - 1 - i] == 0:
				cost += w
			elif arr[l - 1 - i] == 2:
				cost += 2 * min
if l % 2 == 1:
	if arr[int(l / 2)] == 2:
		cost += min
	for i in range(int(l / 2)):
		if arr[i] == 1 or arr[i] == 0:
			if arr[l - 1 - i] != 2:
				if arr[l - 1 - i] != arr[i]:
					print(-1)
					exit(0)
			elif arr[l - 1 - i] == 2:
				if arr[i] == 1:
					cost += b
				elif arr[i] == 0:
					cost += w
		else:
			if arr[l - 1 - i] == 1:
				cost += b
			if arr[l - 1 - i] == 0:
				cost += w
			elif arr[l - 1 - i] == 2:
				cost += 2 * min
print(cost)


import math, sys
from itertools import permutations

def mp():
	return list(map(int, input().split()))
debug = 0
if debug:
	file = open('input.txt', 'r')
	input = file.readline
else:
	input = sys.stdin.readline

def main():
	(n, x, y) = mp()
	a = mp()
	c = [x, y]
	ans = 0
	for i in range(n):
		j = n - i - 1
		if j < i:
			break
		if a[i] != a[j]:
			if a[i] == 2:
				ans += c[a[j]]
			elif a[j] == 2:
				ans += c[a[i]]
			else:
				print(-1)
				return
		elif a[i] == 2:
			ans += min(c) + min(c) * int(bool(i != j))
	print(ans)
main()


RawData = input().split(' ')
(n, white, black) = (int(RawData[0]), int(RawData[1]), int(RawData[2]))
RawData = input().split(' ')
list = []
counter = 0
sum = 0
for i in RawData:
	list.append(int(i))
	counter += 1
counter = 0
flag = 0
while counter < int(n / 2):
	if list[counter] == 0:
		if list[n - 1 - counter] == 2:
			sum = sum + white
		elif list[n - 1 - counter] == 1:
			flag = 1
			break
	elif list[counter] == 1:
		if list[n - 1 - counter] == 2:
			sum = sum + black
		elif list[n - 1 - counter] == 0:
			flag = 1
			break
	elif list[n - 1 - counter] == 2:
		if white < black:
			sum = sum + 2 * white
		else:
			sum = sum + 2 * black
	elif list[n - 1 - counter] == 1:
		sum = sum + black
	else:
		sum = sum + white
	counter = counter + 1
if n % 2 == 1:
	if list[int(n / 2)] == 2:
		if white < black:
			sum = sum + white
		else:
			sum = sum + black
if flag == 1:
	print(-1)
else:
	print(sum)


n1 = list(map(int, input().split(' ')))
n2 = list(map(int, input().split(' ')))
cost = 0
mn = 1 if n1[1] < n1[2] else 2
i = 0
while i < n1[0] // 2:
	if n2[i] == 2:
		if n2[-1 * (i - n1[0]) - 1] == 2:
			cost += 2 * n1[mn]
		else:
			cost += n1[n2[-1 * (i - n1[0]) - 1] + 1]
	elif n2[-1 * (i - n1[0]) - 1] == 2:
		cost += n1[n2[i] + 1]
	elif n2[-1 * (i - n1[0]) - 1] != n2[i]:
		cost = -1
		break
	i += 1
if n1[0] % 2 == 1 and n2[i] == 2 and (cost != -1):
	cost += n1[mn]
print(cost)


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


(n, a, b) = map(int, input().split())
p = list(map(int, input().split()))
q = list(p)
q.reverse()
l = len(q)
p = p[:int((n + 1) / 2)]
q = q[:int((n + 1) / 2)]
s = 0
m = min(a, b)
for (i, j) in zip(p, q):
	if i != 2 and j != 2 and (i != j):
		print('-1')
		exit()
	if i == 2 and j != 2:
		if j:
			s = s + b
		else:
			s = s + a
	if j == 2 and i != 2:
		if i:
			s = s + b
		else:
			s = s + a
	if i == 2 and j == 2:
		s = s + m * 2
if l % 2 == 1 and q[-1] == 2:
	s = s - m
print(s)


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


(n, w, b) = input().split()
(n, w, b) = [int(n), int(w), int(b)]
i = 0
j = n - 1
a = [int(i) for i in input().split()]
s = 0
flag = 0
m = n // 2
while i < m:
	if a[i] == 0 and a[j] == 1:
		flag = 1
		print('-1')
		break
	elif a[i] == 1 and a[j] == 0:
		flag = 1
		print('-1')
		break
	elif a[i] == 2 and a[j] == 2:
		t = min(w, b)
		s += t
		s += t
	elif a[i] != a[j]:
		if a[j] == 2 and a[i] == 0:
			s += w
		elif a[j] == 2 and a[i] == 1:
			s += b
		elif a[j] == 0 and a[i] == 2:
			s += w
		elif a[j] == 1 and a[i] == 2:
			s += b
	i += 1
	j -= 1
if n % 2 != 0 and a[m] != 1 and (a[m] != 1) and (a[m] != 0):
	s += min(w, b)
if flag == 0:
	print(s)


def can_form_palindrome(dancers):
	result = True
	for x in range(len(dancers)):
		if dancers[x] == 1 and dancers[len(dancers) - x - 1] == 0 or (dancers[x] == 0 and dancers[len(dancers) - x - 1] == 1):
			result = False
	return result

class CodeforcesTask1040ASolution:

	def __init__(self):
		self.result = ''
		self.n_a_b = []
		self.dancers = []

	def read_input(self):
		self.n_a_b = [int(x) for x in input().split(' ')]
		self.dancers = [int(x) for x in input().split(' ')]

	def process_task(self):
		if can_form_palindrome(self.dancers):
			preffered = min(self.n_a_b[1], self.n_a_b[2])
			price = 0
			for x in range(len(self.dancers)):
				if self.dancers[x] == 2 and self.dancers[len(self.dancers) - x - 1] == 2:
					price += preffered
				if self.dancers[x] == 0 and self.dancers[len(self.dancers) - x - 1] == 2 or (self.dancers[x] == 2 and self.dancers[len(self.dancers) - x - 1] == 0):
					price += self.n_a_b[1] / 2
				if self.dancers[x] == 1 and self.dancers[len(self.dancers) - x - 1] == 2 or (self.dancers[x] == 2 and self.dancers[len(self.dancers) - x - 1] == 1):
					price += self.n_a_b[2] / 2
			self.result = str(int(price))
		else:
			self.result = '-1'

	def get_result(self):
		return self.result
Solution = CodeforcesTask1040ASolution()
Solution.read_input()
Solution.process_task()
print(Solution.get_result())


import sys
in_lines = [line.rstrip() for line in sys.stdin]
(n, a, b) = map(int, in_lines[0].split())
arr = [int(e) for e in in_lines[1].split()]

def do(n, a, b, arr):
	n_ = n // 2
	cost = 0
	for i in range(n_):
		x = arr[i]
		y = arr[n - 1 - i]
		s = x + y
		if s == 1:
			return -1
		elif s == 0 or (x == 1 and y == 1):
			continue
		elif s == 2:
			cost += a
		elif s == 3:
			cost += b
		elif s == 4:
			cost += 2 * min(a, b)
	if n % 2 == 1 and arr[(n - 1) // 2] == 2:
		cost += min(a, b)
	return cost
print(do(n, a, b, arr))


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


first = input().split()
second = input().split()
le = int(first[0])

def isit(le, second):
	k = 0
	for i in range(int(le / 2) + 1):
		if second[i] == second[le - i - 1] or second[i] == '2' or second[le - i - 1] == '2':
			k += 1
		else:
			return '-1'
	return True
su = 0
if isit(le, second) == True:
	for i in range(int(le)):
		if second[i] == '2':
			if second[le - i - 1] == '0':
				su += int(first[1])
			elif second[le - i - 1] == '1':
				su += int(first[2])
			else:
				su += min(int(first[1]), int(first[2]))
	print(su)
else:
	print('-1')


def isPali(w):
	n = len(w)
	for i in range(n // 2):
		if w[i] != w[n - 1 - i]:
			return False
	return True
(n, a, b) = list(map(int, input().split()))
tab = list(map(int, input().split()))
minPrice = min(a, b)
index = 0 if a < b else 1
sumi = 0
for i in range(n // 2):
	if tab[i] == 2 or tab[n - 1 - i] == 2:
		if tab[i] == 2 and tab[n - 1 - i] == 2:
			tab[i] = index
			tab[n - 1 - i] = index
			sumi += 2 * minPrice
		elif tab[i] == 2 and tab[n - 1 - i] != 2:
			sumi += a if tab[n - 1 - i] == 0 else b
			tab[i] = tab[n - 1 - i]
		elif tab[i] != 2 and tab[n - 1 - i] == 2:
			sumi += a if tab[i] == 0 else b
			tab[n - 1 - i] = tab[i]
sumi += minPrice if n % 2 != 0 and tab[n // 2] == 2 else 0
if isPali(tab):
	print(sumi)
else:
	print(-1)


def poli_dance(n, a, b, c):
	cost = 0
	for k in range(int(len(c) // 2)):
		if c[k] != 2 and c[-1 - k] != 2:
			if c[k] != c[-1 - k]:
				return -1
		elif c[k] == 2 and c[-1 - k] == 2:
			cost += 2 * min(a, b)
		elif c[k] == 2 or c[-1 - k] == 2:
			if abs(c[k] - c[-1 - k]) == 1:
				cost += b
			elif abs(c[k] - c[-1 - k]) == 2:
				cost += a
	if n % 2 != 0:
		if c[int(len(c) // 2)] == 2:
			cost += min(a, b)
	return cost
(n, a, b) = input().split()
n = int(n)
a = int(a)
b = int(b)
c = [int(i) for i in input().split()]
print(poli_dance(n, a, b, c))


import math

def minPrice(dan, n, a, b):
	mp = 0
	for i in range(math.ceil(n / 2)):
		if (dan[i], dan[-i - 1]) == (2, 2):
			if i == n / 2 - 0.5:
				mp += min(a, b)
			else:
				mp += 2 * min(a, b)
		elif (dan[i], dan[-i - 1]) == (0, 2) or (dan[i], dan[-i - 1]) == (2, 0):
			mp += a
		elif (dan[i], dan[-i - 1]) == (1, 2) or (dan[i], dan[-i - 1]) == (2, 1):
			mp += b
		elif (dan[i], dan[-i - 1]) == (0, 1) or (dan[i], dan[-i - 1]) == (1, 0):
			return -1
	return mp
(n, a, b) = map(int, input().split())
dan = list(map(int, input().split()))
print(minPrice(dan, n, a, b))


def solv(dancers, wcost, bcost):
	lp = 0
	rp = len(dancers) - 1
	lower = 0
	w = 0
	b = 0
	while lp <= rp:
		if lp == rp:
			if dancers[lp] == 2:
				lower += 1
		elif dancers[lp] == 2 and dancers[rp] == 2:
			lower += 2
		elif dancers[lp] == 2:
			if dancers[rp] == 0:
				w += 1
			else:
				b += 1
		elif dancers[rp] == 2:
			if dancers[lp] == 0:
				w += 1
			else:
				b += 1
		elif dancers[rp] != dancers[lp]:
			return -1
		lp += 1
		rp -= 1
	cost = lower * min(wcost, bcost) + w * wcost + b * bcost
	return cost
(n, wcost, bcost) = map(int, input().split())
dancers = list(map(int, input().split()))
print(solv(dancers, wcost, bcost))


nab = [int(x) for x in input().split()]
data = [int(x) for x in input().split()]
counts = 0
left = 0
right = nab[0] - 1
while True:
	if left > nab[0] - 1 or right < 0:
		break
	elif data[left] == data[right] == 2:
		data[left] = data[right] = 0 if nab[1] < nab[2] else 1
		counts += (2 if left != right else 1) * min(nab[1:])
	elif data[left] != data[right] and data[right] != 2 and (data[left] != 2):
		print(-1)
		exit(0)
	elif data[left] != data[right]:
		if data[left] == 2:
			data[left] = data[right]
			counts += nab[data[right] + 1]
		else:
			data[right] = data[left]
			counts += nab[data[left] + 1]
	elif left >= right:
		break
	left += 1
	right -= 1
left = 0
print(counts)


(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
			elif left == 0:
				cnt += a
			else:
				cnt += b
		if left == right:
			if left == 2:
				cnt += 2 * m
print(cnt)


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


import math
(n, a, b) = map(int, input().split())
arr = list(map(int, input().split()))
money = 0
for i in range(math.ceil(n / 2)):
	(x, y) = (arr[i] == 2, arr[n - i - 1] == 2)
	if x and y:
		z = i == n - i - 1
		money += min(a, b) * (2 - z)
		continue
	if x:
		money += [a, b][arr[n - i - 1]]
	if y:
		money += [a, b][arr[i]]
	if (not x and (not y)) and arr[i] != arr[n - i - 1]:
		print(-1)
		break
else:
	print(money)


(n, a, b) = map(int, input().split())
s = [int(x) for x in input().split()]
temp = 0
cst = 0
for j in range(0, n // 2):
	if s[j] == 2 and s[n - j - 1] == 2:
		cst = cst + 2 * min(a, b)
	elif s[j] == 2 and s[n - j - 1] == 1:
		cst = cst + b
	elif s[j] == 1 and s[n - j - 1] == 2:
		cst = cst + b
	elif s[j] == 2 and s[n - j - 1] == 0:
		cst = cst + a
	elif s[j] == 0 and s[n - j - 1] == 2:
		cst = cst + a
	else:
		if s[j] == 1 and s[n - j - 1] == 0:
			temp = 1
		if s[j] == 0 and s[n - j - 1] == 1:
			temp = 1
if temp == 1:
	print('-1')
elif n % 2 == 0:
	print(cst)
else:
	if s[n // 2] == 2:
		cst = cst + min(a, b)
	print(cst)


f = lambda : map(int, input().split())
(n, w, b) = f()
s = [w, b]
c = 0
l = list(f())
for i in range(n // 2):
	if l[i] == l[-1 - i] == 2:
		c += min(w, b) * 2
	elif l[i] != l[-1 - i]:
		if l[i] == 2:
			c += s[l[-i - 1]]
		elif l[-1 - i] == 2:
			c += s[l[i]]
		else:
			exit(print(-1))
print(c + min(w, b) if l[n // 2] == 2 and n % 2 else c)


(n, a, b) = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]
cost = 0
mini = min(a, b)
for i in range(n):
	if c[i] == 2 and c[n - i - 1] != 2:
		c[i] = c[n - i - 1]
		if c[n - i - 1] == 0:
			cost += a
		elif c[n - i - 1] == 1:
			cost += b
	elif c[i] == 2 and c[n - 1 - i] == 2:
		if a < b:
			c[i] = 0
		else:
			c[i] = 1
		cost += mini
if c == c[::-1]:
	print(cost)
else:
	print(-1)


l1 = list(map(int, input().split()))
l2 = list(map(int, input().split()))
a = []
b = []
for i in range(0, len(l2) // 2):
	a.append(l2[i])
if l1[0] % 2 == 0:
	for i in range(len(l2) // 2, len(l2)):
		b.append(l2[i])
else:
	for i in range(len(l2) // 2 + 1, len(l2)):
		b.append(l2[i])
b.reverse()
m = min(l1[1], l1[2])
c = 0
q = 0
for i in range(0, len(l2) // 2):
	if a[i] == b[i] and a[i] == 2:
		c = c + m + m
	elif a[i] != b[i] and a[i] == 2:
		if b[i] == 0:
			c = c + l1[1]
		else:
			c = c + l1[2]
	elif a[i] != b[i] and b[i] == 2:
		if a[i] == 0:
			c = c + l1[1]
		else:
			c = c + l1[2]
	elif a[i] == b[i] and a[i] != 2:
		pass
	else:
		q = 1
		break
if q == 1:
	print(-1)
elif l1[0] % 2 != 0 and l2[len(l2) // 2] == 2:
	print(c + m)
else:
	print(c)


(n, a, b) = map(int, input().split())
s = list(map(int, input().split()))
k = a * s.count(0) + b * s.count(1)
for i in range((n + 1) // 2):
	if s[i] != s[-i - 1] == 2:
		s[-i - 1] = s[i]
	if s[i] == s[-i - 1] == 2:
		s[-i - 1] = 0 if a < b else 1
	if s[i - 1] != s[i] == 2:
		s[i] = s[-i - 1]
print(a * s.count(0) + b * s.count(1) - k if s == s[::-1] else -1)


(n, a, b) = list(map(int, input().split(' ')))
x = list(map(int, input().split(' ')))
(sum, i, j) = (0, 0, n - 1)
while i <= j:
	if x[i] in [0, 1] and x[j] in [0, 1] and (x[i] != x[j]):
		print(-1)
		exit()
	elif x[i] == x[j] == 2:
		sum += 2 * min(a, b) if i != j else min(a, b)
	elif min(x[i], x[j]) == 0 and x[i] != x[j]:
		sum += a
	elif min(x[i], x[j]) == 1 and x[i] != x[j]:
		sum += b
	i += 1
	j -= 1
print(sum)


(n, a, b) = map(int, input().split())
c = list(map(int, input().split()))
head = 0
tail = n - 1
tot = 0
if a > b:
	d = b
else:
	d = a
while head < tail:
	if c[head] + c[tail] == 2 and c[tail] != c[head]:
		tot += a
	elif c[head] + c[tail] == 3:
		tot += b
	elif c[head] + c[tail] == 4:
		tot += d * 2
	elif c[head] + c[tail] == 1:
		print(-1)
		exit()
	head += 1
	tail -= 1
if n % 2 == 1:
	if c[n // 2] == 2:
		tot += d
print(tot)


parameters = list(map(int, input().split(' ')))
(n, a, b) = (parameters[0], parameters[1], parameters[2])
s = list(input().split(' '))
mid = int((n - 1) / 2)
flag = True
cost = 0
if a < b:
	_min = a
else:
	_min = b
for i in range(0, mid + 1):
	if s[i] == '2' and s[n - i - 1] == '2':
		cost += _min
		if i != n - i - 1:
			cost += _min
	elif s[i] == '2' and s[n - i - 1] == '1' or (s[i] == '1' and s[n - i - 1] == '2'):
		cost += b
	elif s[i] == '2' and s[n - i - 1] == '0' or (s[i] == '0' and s[n - i - 1] == '2'):
		cost += a
	elif s[i] == s[n - i - 1] and s[i] != '2':
		continue
	else:
		flag = False
		break
if not flag:
	print(-1)
else:
	print(cost)


import sys, math
(n, w, b) = map(int, sys.stdin.readline().split())
arr = list(map(int, sys.stdin.readline().split()))
left = 0
right = n - 1
can = True
cost = 0
while left < right:
	if arr[left] == 0 and arr[right] == 1 or (arr[left] == 1 and arr[right] == 0):
		can = False
	elif arr[left] == 2 and arr[right] != 2:
		if not arr[right]:
			cost += w
		else:
			cost += b
	elif arr[left] != 2 and arr[right] == 2:
		if not arr[left]:
			cost += w
		else:
			cost += b
	elif arr[left] == 2 and arr[right] == 2:
		cost += min(2 * w, 2 * b)
	left += 1
	right -= 1
if n % 2 == 1 and arr[n // 2] == 2:
	cost += min(w, b)
print(cost if can else -1)


from math import ceil
(n, a, b) = [int(x) for x in input().split()]
lst = [int(x) for x in input().split()]
su = 0
if len(lst) % 2 == 1:
	mid = int(len(lst) / 2)
	midx = lst[mid]
	rlst = lst[mid + 1:]
	lst = lst[:mid]
	rlst.reverse()
	if midx == 2:
		su += min(a, b)
elif len(lst) % 2 == 0:
	mid = int(len(lst) / 2)
	rlst = lst[mid:]
	lst = lst[:mid]
	rlst.reverse()
for i in range(len(lst)):
	if lst[i] != rlst[i] and (lst[i] != 2 and rlst[i] != 2):
		print(-1)
		exit()
	elif lst[i] == 2 and rlst[i] == 2:
		su += min(a, b) * 2
	elif lst[i] == 2 and rlst[i] == 1 or (lst[i] == 1 and rlst[i] == 2):
		su += b
	elif lst[i] == 2 and rlst[i] == 0 or (lst[i] == 0 and rlst[i] == 2):
		su += a
print(su)


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


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


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


def palindrome_dance():
	(n, a, b) = map(int, input().split())
	cc = input().split()
	lc = len(cc)
	cost = 0
	for i in range(lc // 2):
		if cc[i] == '0' or cc[i] == '1':
			if cc[-i - 1] == cc[i]:
				continue
			if cc[-i - 1] == '2':
				cost += a if cc[i] == '0' else b
			else:
				return -1
		elif cc[-i - 1] == '2':
			cost += 2 * min(a, b)
		else:
			cost += a if cc[-i - 1] == '0' else b
	if lc % 2 != 0 and cc[lc // 2] == '2':
		cost += min(a, b)
	return cost
print(palindrome_dance())


arrs = input().split()
arr = input().split()
index = 0
result = 0
while index <= (int(arrs[0]) - 1) // 2:
	if arr[index] == arr[int(arrs[0]) - 1 - index] and arr[index] != '2':
		index += 1
	elif arr[index] != '2' and arr[int(arrs[0]) - 1 - index] != '2':
		result = -1
		break
	elif arr[index] == '2' and arr[int(arrs[0]) - 1 - index] == '2':
		result += min(int(arrs[1]), int(arrs[2]))
		if index != int(arrs[0]) - 1 - index:
			result += min(int(arrs[1]), int(arrs[2]))
		index += 1
	elif arr[index] == '2':
		result += int(arrs[int(arr[int(arrs[0]) - 1 - index]) + 1])
		index += 1
	else:
		result += int(arrs[int(arr[index]) + 1])
		index += 1
print(result)


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


def take():
	return map(int, input().split())
(n, w, b) = take()
a = list(take())
res = 0
for i in range(int(n / 2)):
	f = a[i]
	s = a[n - 1 - i]
	if f != s and f < 2 and (s < 2):
		res = -1
		break
	elif f == 0 and s == 2 or (s == 0 and f == 2):
		res += w
	elif f == 1 and s == 2 or (s == 1 and f == 2):
		res += b
	elif f == 2 and s == 2:
		res += 2 * min(w, b)
if n % 2 and a[int(n / 2)] == 2 and (res != -1):
	res += min(w, b)
print(res)


import sys

def minp():
	return sys.stdin.readline().strip()
(n, a, b) = map(int, minp().split())
c = list(map(int, minp().split()))
i = 0
r = 0
d = [a, b]
fail = False
while i < n - i - 1:
	v = 0
	if c[i] == 2:
		if c[n - i - 1] == 2:
			v = d.index(min(d))
		else:
			v = c[n - i - 1]
	elif c[n - i - 1] == 2:
		v = c[i]
	elif c[n - i - 1] != c[i]:
		fail = True
	else:
		v = c[i]
	if c[i] != v:
		r += d[v]
	if c[n - i - 1] != v:
		r += d[v]
	i += 1
if i == n - i - 1:
	if c[i] == 2:
		r += min(d)
if fail:
	print(-1)
else:
	print(r)


(n, a, b) = map(int, input().split())
c = input().split()
l = len(c)
summe = 0
if l % 2:
	if c[l // 2] == '2':
		summe += min(a, b)
l = l // 2
for (x, y) in zip(c[:l], reversed(c)):
	if x == '2' and y == '2':
		summe += 2 * min(a, b)
	elif x in '01' and y in '01':
		if x != y:
			print('-1')
			summe = None
			break
		else:
			continue
	elif x != '2' and y == '2':
		summe += {'0': a, '1': b}[x]
	elif y != '2' and x == '2':
		summe += {'0': a, '1': b}[y]
if not summe is None:
	print(summe)


(n, w, b) = map(int, input().split())
values = list(map(int, input().split()))
i = 0
j = n - 1
cost = 0
while i <= j:
	if values[i] == values[j] == 0 or values[i] == values[j] == 1:
		pass
	elif values[i] == values[j] == 2 and i != j:
		cost += 2 * min(w, b)
	elif values[i] == values[j] == 2 and i == j:
		cost += min(w, b)
	elif values[i] != values[j] and values[j] == 2:
		if values[i] == 0:
			cost += w
		else:
			cost += b
	elif values[i] != values[j] and values[i] == 2:
		if values[j] == 0:
			cost += w
		else:
			cost += b
	elif values[i] != values[j] and (values[i] != 2 and values[j] != 2):
		cost = -1
		break
	i += 1
	j -= 1
print(cost)


(n, a, b) = map(int, input().strip().split(' '))
v = list(map(int, input().strip().split(' ')))
res = 0
for i in range(n):
	if v[i] == 2:
		if v[n - 1 - i] == 0:
			res += a
		elif v[n - 1 - i] == 1:
			res += b
		else:
			res += min(a, b)
	elif v[n - 1 - i] != 2 and v[i] != v[n - 1 - i]:
		res = -1
		break
print(res)


def check(suit1, suit2, a, b):
	sum_suit = suit1 + suit2
	possible = False if sum_suit == 1 else True
	cost = 0 if suit1 == suit2 == 0 or suit1 == suit2 == 1 or sum_suit == 1 else a if sum_suit == 2 else b if sum_suit == 3 else min(a, b) * 2
	return (possible, cost)

def main():
	[n, a, b] = map(int, input().split())
	suits = [int(_) for _ in input().split()]
	possible = True
	cost = 0
	for i in range(n // 2):
		(checked, this_cost) = check(suits[i], suits[n - 1 - i], a, b)
		possible = possible and checked
		cost += this_cost
		if not possible:
			break
	cost += min(a, b) if possible and n % 2 == 1 and (suits[n // 2] == 2) else 0
	print(cost if possible else -1)
main()


import sys
(n, a, b) = map(int, input().split(' '))
s = list(map(int, input().split(' ')))
s = [2 - x for x in s]
total = 0
for i in range(int((n + 1) / 2)):
	if s[i] ^ s[n - 1 - i] == 3:
		total = -1000000000
	elif s[i] != s[n - 1 - i]:
		total += a if s[i] + s[n - 1 - i] == 2 else b
	elif s[i] == 0:
		total += (2 if 2 * i < n - 1 else 1) * min(a, b)
print(max(total, -1))