using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PalindromeDance
{
    class Program
    {
        static void Main(string[] args)
        {
            const int DANCER_WITH_WHITE_SUIT = 0;
            const int DANCER_WITH_BLACK_SUIT = 1;
            const int DANCER_WITH_UNKNOWN_SUIT = 2;

            //
            string[] inputs = Console.ReadLine().Split(' ');
            int n = int.Parse(inputs[0]);
            int PriceWhiteSuit = int.Parse(inputs[1]);
            int PriceBlackSuit = int.Parse(inputs[2]);

            string[] inputsDancers = Console.ReadLine().Split(' ');
            int[] Dancers = Array.ConvertAll(inputsDancers, x => int.Parse(x));
            int result = 0;
            for (int i = 0; i < n / 2 && result != -1; i++)
            {
                if (Dancers[i] != Dancers[n - i - 1] && Dancers[i] != DANCER_WITH_UNKNOWN_SUIT && Dancers[n - i - 1] != DANCER_WITH_UNKNOWN_SUIT)
                {
                    result = -1;
                }
                else
                {
                    if (Dancers[i] != Dancers[n - i - 1])
                    {
                        if (Dancers[i] == DANCER_WITH_BLACK_SUIT)
                            result += PriceBlackSuit;

                        if (Dancers[i] == DANCER_WITH_WHITE_SUIT)
                            result += PriceWhiteSuit;

                        if (Dancers[n - i - 1] == DANCER_WITH_BLACK_SUIT)
                            result += PriceBlackSuit;

                        if (Dancers[n - i - 1] == DANCER_WITH_WHITE_SUIT)
                            result += PriceWhiteSuit;
                    }
                    else
                    {
                        if (Dancers[i] == Dancers[n - i - 1] && Dancers[n - i - 1] == DANCER_WITH_UNKNOWN_SUIT)
                        {
                            if (PriceWhiteSuit < PriceBlackSuit)
                            {
                                result += 2 * PriceWhiteSuit;
                            }
                            else
                            {
                                result += 2 * PriceBlackSuit;
                            }
                        }
                    }
                }
            }

            if(n%2 != 0 && Dancers[n/2] == DANCER_WITH_UNKNOWN_SUIT && result != -1)
            {
                if(PriceWhiteSuit < PriceBlackSuit)
                {
                    result += PriceWhiteSuit;
                }
                else
                {
                    result += PriceBlackSuit;
                }
            }

            Console.WriteLine(result);

        }
    }
}

using System;

public class Solution
{
    static void Main(String[] args)
    {
        string[] input = Console.ReadLine().Split(' ');
        int n = int.Parse(input[0]);
        int a = int.Parse(input[1]);
        int b = int.Parse(input[2]);
        int[] d = new int[n];
        input = Console.ReadLine().Split(' ');
        for (int i = 0; i < n; i++)
        {
            d[i] = int.Parse(input[i]);
        }
        int[] c = new int[n];
        for (int i = 0; i < n; i++)
        {
            if (d[i] == 2)
            {
                int j = n - i - 1;
                if (d[j] == 0)
                {
                    d[i] = 0;
                    c[i] = a;
                }
                else if (d[j] == 1)
                {
                    d[i] = 1;
                    c[i] = b;
                }
                else if (d[j] == 2)
                {
                    if (a > b)
                    {
                        d[i] = 1;
                        d[j] = 1;
                        c[i] = b;
                        c[j] = b;
                    }
                    else
                    {
                        d[i] = 0;
                        d[j] = 0;
                        c[i] = a;
                        c[j] = a;
                    }
                }
            }
            else if (d[i] == 1 && d[n - i - 1] == 0)
            {
                Console.WriteLine(-1);
                return;
            }
        }
        int cost = 0;
        for (int i = 0; i < n; i++)
        {
            cost += c[i];
        }
        Console.WriteLine(cost);
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Танец_палиндром
{
    class Program
    {
        static void Main(string[] args)
        {
            int res = 0;
            string s = Console.ReadLine();
            string[] values = s.Split(' ');
            int n = int.Parse(values[0]);
            int a = int.Parse(values[1]);
            int b = int.Parse(values[2]);
            s = Console.ReadLine();
            string[] values2 = s.Split(' ');
            int[] arr = new int[n];
            for (int i=0; i<n; i++)
            {
                arr[i] = int.Parse(values2[i]);
            }
            int min=a;
            if (a>b)
            {
                min = b;
            }
            int x = 0;
            if (n%2==1)
            {
                x = n / 2 + 1;
            }
            else
            {
                x = n / 2;
            }
            for (int i = 0; i < x; i++)
            {
                if (arr[i]==arr[n-1-i])
                {
                    if(arr[i]==2)
                    {
                        if (i == x - 1)
                        if (n==2)
                        {
                            res = res + 2 * min;
                        }else{
                            res = res + min;
                        }
                        else
                            res = res + 2 * min;
                    }
                }
                else
                {
                    if(((arr[i]==0)&&(arr[n-1-i]==2))||((arr[n-1-i]==0)&&(arr[i]==2)))
                    {
                        res = res + a;
                    }
                    else if(((arr[i] == 1) && (arr[n - 1 - i] == 2)) || ((arr[n - 1 - i] == 1) && (arr[i] == 2)))
                    {
                        res = res + b;

                    }
                    else
                    {
                        res = -1;
                        break;
                    }
                }
            }
            Console.WriteLine(res);

        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ExA
{
    class Program
    {
        const int WHITE = 0, BLACK = 1, UNKNOWN = 2;

        static void Main(string[] args)
        {
            int n, a, b;
            int res = 0;

            var vals = Console.ReadLine().Split();
            n = int.Parse(vals[0]);
            a = int.Parse(vals[1]);
            b = int.Parse(vals[2]);

            bool notApolindrom = false;

            var numbers = Console.ReadLine().Split();
            for (int i = 0; i < n / 2; i++)
            {
                int n1 = int.Parse(numbers[i]);
                int n2 = int.Parse(numbers[n - i - 1]);

                if (n1 == UNKNOWN && n2 != UNKNOWN)
                {
                    res += GetCost(n2, a, b);
                }
                else if (n2 == UNKNOWN && n1 != UNKNOWN)
                {
                    res += GetCost(n1, a, b);
                }
                else if (n1 == UNKNOWN && n2 == UNKNOWN)
                {
                    res += Math.Min(a, b) * 2;
                }
                if (n1 != UNKNOWN && n2 != UNKNOWN && n1 != n2)
                {
                    notApolindrom = true;
                    break;
                }
            }

            if (!notApolindrom)
            {
                if (n % 2 != 0 && int.Parse(numbers[n / 2]) == UNKNOWN)
                {
                    res += Math.Min(a, b);
                }
            }
            else
            {
                res = -1;
            }

            Console.WriteLine(res);
        }

        static int GetCost(int costume, int a, int b)
        {
            if (costume == WHITE)
                return a;
            else if (costume == BLACK)
                return b;
            else
                return 0;
        }
    }
}

using System;
using System.IO;
using System.Text;

namespace Palindrome_Dance
{
    internal class Program
    {
        private static readonly StreamReader reader = new StreamReader(Console.OpenStandardInput(1024*10), Encoding.ASCII, false, 1024*10);
        private static readonly StreamWriter writer = new StreamWriter(Console.OpenStandardOutput(1024*10), Encoding.ASCII, 1024*10);

        private static void Main(string[] args)
        {
            writer.WriteLine(Solve());
            writer.Flush();
        }

        private static int Solve()
        {
            int n = Next();
            int a = Next();
            int b = Next();

            var nn = new int[n];
            for (int i = 0; i < n; i++)
            {
                nn[i] = Next();
            }

            int ans = 0;
            for (int i = 0, j = n - 1; i <= j; i++, j--)
            {
                if (i == j)
                {
                    if (nn[i] == 2)
                        ans += Math.Min(a, b);
                }
                else
                {
                    if (nn[i] != 2 && nn[j] != 2)
                    {
                        if (nn[i] != nn[j])
                            return -1;
                    }
                    else
                    {
                        if (nn[i] != 2)
                        {
                            ans += nn[i] == 0 ? a : b;
                        }
                        else if (nn[j] != 2)
                        {
                            ans += nn[j] == 0 ? a : b;
                        }
                        else
                        {
                            ans += 2*Math.Min(a, b);
                        }
                    }
                }
            }

            return ans;
        }

        private static int Next()
        {
            int c;
            int res = 0;
            do
            {
                c = reader.Read();
                if (c == -1)
                    return res;
            } while (c < '0' || c > '9');
            res = c - '0';
            while (true)
            {
                c = reader.Read();
                if (c < '0' || c > '9')
                    return res;
                res *= 10;
                res += c - '0';
            }
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp5
{
    class Program
    {
        static void Main(string[] args)
        {
            int i, n, w, b; // n number of dancers, w cost of white suits, b cost of black suits
            string input = Console.ReadLine();
            string[] split = input.Split();
            n = Convert.ToInt32(split[0]);
            w = Convert.ToInt32(split[1]);
            b = Convert.ToInt32(split[2]);
            string input2 = Console.ReadLine();
            string[] split2 = input2.Split();
            int[] a = new int[split2.Length];
            for (i = 0; i < split2.Length; i++) {
                a[i] = Convert.ToInt32(split2[i]);
            }
            int j = 0;
            bool same = false;
            for (i = 0; i < n / 2; i ++) {
                int l = a[i];
                int r = a[n - i - 1];
               if (l == 2 && r == 2)
                {
                   j += Math.Min(w*2, b*2);
                }
                if (l == 0 && r == 1)
                {
                    same = true;
                }
                if (l == 1 && r == 0)
                {
                    same = true;
                }
                if (l == 2 && r == 0)
                {
                    j += w;
                }
                if (l == 0 && r == 2)
                {
                    j += w;
                }
                if (l == 1 && r == 2)
                {
                    j += b;
                }
                if (l == 2 && r == 1)
                {
                    j += b;
                }

            }
            if (n % 2 == 1) {
                if (a[n / 2] == 2) {
                    j += Math.Min(w, b);
                }
            }
            if (same)
            {
                Console.WriteLine(-1);
            }
            else
            {
                Console.WriteLine(j);
            }
            Console.ReadLine();
        }

    }
}

#define EXTENDSTACKSIZE

using System;
 using System.Collections.Generic;
 using System.Globalization;
using System.IO;
using System.Linq;
using System.Threading;

namespace CF
{
    internal class Program
    {
        private const int stackSize = 32 * 1024 * 1024;

        private static void Run()
        {
            using (var sr = new InputReader(Console.In))
//            using (var sr = new InputReader(new StreamReader("input.txt")))
            using (var sw = Console.Out)
//            using (var sw = new StreamWriter("output.txt"))
            using (var task = new Task(sr, sw)) {
                task.Solve();
//                Console.ReadKey();
            }
        }

        private static void Main(string[] args)
        {
#if EXTENDSTACKSIZE
            var threadStart = new ThreadStart(Run);
            var thread = new Thread(threadStart, stackSize);
            thread.Start();
            thread.Join();
#else
            Run();
#endif
        }
    }

    internal class Task : IDisposable
    {
        private readonly InputReader sr;
        private readonly TextWriter sw;
        private bool isDispose;

        public Task(InputReader sr, TextWriter sw)
        {
            this.sr = sr;
            this.sw = sw;
        }

        public void Solve()
        {
            var n = sr.NextInt32();
            var a = sr.NextInt32();
            var b = sr.NextInt32();
            var numbers = sr.ReadArrayOfInt32();
            var cost = 0;
            var mid = n / 2;
            for (var i = 0; i < mid; i++) {
                if (numbers[i] == 2 || numbers[n - i - 1] == 2) {
                    if (numbers[i] == 2 && numbers[n - i - 1] == 2) {
                        cost += 2*Math.Min(a, b);
                    }
                    else {
                        if (numbers[i] == 2) {
                            if (numbers[n - i - 1] == 0) {
                                cost += a;
                            }
                            else {
                                cost += b;
                            }
                        }
                        else {
                            if (numbers[i] == 0) {
                                cost += a;
                            }
                            else {
                                cost += b;
                            }
                        }
                    }
                }
                else {
                    if (numbers[i] != numbers[n - i - 1]) {
                        sw.WriteLine(-1);
                        return;
                    }
                }
            }

            if (n % 2 == 1) {
                if (numbers[mid] == 2) {
                    cost += Math.Min(a, b);
                }
            }

            sw.WriteLine(cost);
        }

        ~Task()
        {
            Dispose(false);
        }

        public void Dispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this);
        }

        private void Dispose(bool disposing)
        {
            if (!isDispose) {
                if (disposing) {
                    if(sr != null)
                        sr.Dispose();

                    if(sw != null)
                        sw.Dispose();
                }

                isDispose = true;
            }
        }
    }
}

class Graph
{
    private readonly List<int>[] edges;

    public Graph(int n)
    {
        edges = new List<int>[n];
    }

    public void Insert(int x, int y)
    {
        if (edges[x] == null) {
            edges[x] = new List<int>();
        }

        edges[x].Add(y);
        if (edges[y] == null) {
            edges[y] = new List<int>();
        }

        edges[y].Add(x);
    }

    public int Solution()
    {
        var compS = 0;
        var visited = new bool[edges.Length];
        for (var i = 0; i < edges.Length; i++) {
            if (!visited[i]) {
                compS++;
                DfsVisit(i, visited);
            }
        }

        return compS - 1;
    }

    private void DfsVisit(int v, bool[] visited)
    {
        visited[v] = true;
        if (edges[v] != null) {
            for (var u = 0; u < edges[v].Count; u++) {
                if (!visited[edges[v][u]]) {
                    DfsVisit(edges[v][u], visited);
                }
            }
        }
    }
}

internal class InputReader : IDisposable
{
    private bool isDispose;
    private readonly TextReader sr;
    private string[] buffer;
    private int seek;

    public InputReader(TextReader stream)
    {
        sr = stream;
    }

    public void Dispose()
    {
        Dispose(true);
        GC.SuppressFinalize(this);
    }

    public string NextString()
    {
        var result = sr.ReadLine();
        return result;
    }

    public int NextInt32()
    {
        return Int32.Parse(ReadNextToken());
    }

    private string ReadNextToken()
    {
        if (buffer == null || seek == buffer.Length) {
            seek = 0;
            buffer = NextSplitStrings();
        }

        return buffer[seek++];
    }

    public long NextInt64()
    {
        return Int64.Parse(ReadNextToken());
    }

    public int[] ReadArrayOfInt32()
    {
        return ReadArray(Int32.Parse);
    }

    public long[] ReadArrayOfInt64()
    {
        return ReadArray(Int64.Parse);
    }

    public string[] NextSplitStrings()
    {
        return NextString()
            .Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
    }

    public T[] ReadArray<T>(Func<string, CultureInfo, T> func)
    {
        return NextSplitStrings()
            .Select(s => func(s, CultureInfo.InvariantCulture))
            .ToArray();
    }

    public T[] ReadArrayFromString<T>(Func<string, CultureInfo, T> func, string str)
    {
        return
            str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
                .Select(s => func(s, CultureInfo.InvariantCulture))
                .ToArray();
    }

    protected void Dispose(bool dispose)
    {
        if (!isDispose)
        {
            if (dispose)
                sr.Close();

            isDispose = true;
        }
    }

    ~InputReader()
    {
        Dispose(false);
    }
}

using System;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            long n = long.Parse(input[0]), white = long.Parse(input[1]), black = long.Parse(input[2]), price=0, currLeft, currRight;
            bool well = true;

            string[] dancers = Console.ReadLine().Split(' ');
            if(n%2 ==1)
            {
                if(long.Parse(dancers[n/2]) ==2)
                {
                    if (white > black)
                    {
                        price += black;
                    }
                    else
                    {
                        price += white;
                    }
                }
            }

            for (int i = 0; i < n/2; i++)
            {
                currLeft = long.Parse(dancers[i]);
                currRight = long.Parse(dancers[n - i - 1]);
                if(currLeft!= currRight && ( currLeft!=2&&currRight!=2 ) )
                {
                    well = false;
                    break;
                }
                else if(currLeft != 2 && currRight != 2)
                {

                }
                else if(currRight == 2 || currLeft ==2)
                {
                    if (currLeft == 0 || currRight == 0)
                    {
                        price += white;
                    }
                    else if (currLeft == 1 || currRight == 1)
                    {
                        price += black;
                    }
                    else
                    {
                        if (white > black)
                            price += 2*black;
                        else
                            price += 2*white;
                    }
                }
                else
                {
                    if (currLeft == 0 || currRight == 0)
                    {
                        price += 2*white;
                    }
                    else if (currLeft == 1 || currRight == 1)
                    {
                        price += 2*black;
                    }
                }

            }

            if(well)
            {
                Console.WriteLine(price);
            }
            else
            {
                Console.WriteLine(-1);
            }
        }
    }
}

using System;
using System.Linq;

namespace ACM
{
    class Program
    {
        //1040A
        static void Main()
        {
            int n, a, b;
            int[] input = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            n = input[0];
            a = input[1];//0 соответствует белому костюму, 1 — чёрному
            b = input[2];
            int sum = 0;
            int minType, minValue;
            if (a < b)
            {
                minType = 0;
                minValue = a;
            }
            else
            {
                minType = 1;
                minValue = b;
            }
            int[] arr = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            if (arr.Length % 2 == 1 && arr[arr.Length / 2] == 2)
            {
                arr[arr.Length / 2] = minType;
                sum += minValue;
            }
            if (arr.Length == 1)
            {
                Console.WriteLine(sum);
                return;
            }
            for (int i = 0; i < arr.Length; i++)
            {
                if (arr[i] == arr[arr.Length - i - 1])
                {
                    if (arr[i] == 2)
                    {
                        arr[i] = minType;
                        arr[arr.Length - i - 1] = minType;
                        sum += minValue * 2;
                    }
                }
                else
                {
                    if (arr[i] == 2)
                    {
                        arr[i] = arr[arr.Length - i - 1];
                        if (arr[arr.Length - i - 1] == 0)
                        {
                            sum += a;
                        }
                        else
                        {
                            sum += b;
                        }
                    }
                    else
                    if (arr[arr.Length - i - 1] == 2)
                    {
                        arr[arr.Length - i - 1] = arr[i];
                        if (arr[i] == 0)
                        {
                            sum += a;
                        }
                        else
                        {
                            sum += b;
                        }
                    }
                    else
                    {
                        Console.WriteLine(-1);
                        return;
                    }
                }
            }
            Console.WriteLine(sum);
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp4
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var n = input[0];
            var a = input[1];
            var b = input[2];
            var row = Console.ReadLine().Split();
            var result = 0;
            for (var i = 0; i < n; i++)
            {
                if (n - 1 - i - i <= 0)
                {
                    if (n - 1 - i - i == 0)
                        if (row[i] == "2")
                            result += Math.Min(a, b);
                    Console.WriteLine(result);
                    break;
                }
                if (row[i] == row[n - 1 - i] && row[i] != "2")
                {
                    continue;
                }
                else
                {
                    if (row[i] == "2" || row[n - 1 - i] == "2")
                    {
                        if (row[i] == "2" && row[n - 1 - i] == "2")
                        {
                            result += Math.Min(a, b) * 2;
                            continue;
                        }
                        else
                        {
                            if (row[i] == "0" || row[n - 1 - i] == "0")
                                result += a;
                            else
                                result += b;
                        }
                    }
                    else
                    {
                        Console.WriteLine(-1);
                        break;
                    }
                }
            }
        }
    }
}

using System;

namespace someSHIT
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] inp = Console.ReadLine().Split();
            int N = int.Parse(inp[0]);
            int a = int.Parse(inp[1]);
            int b = int.Parse(inp[2]);
            int min = Math.Min(a, b);
            string[] data = Console.ReadLine().Split();
            int i = 0, j = N - 1;
            int Cost = 0;
            while(i<= j)
            {
                if (i == j && data[i] == "2")
                    Cost += min;
                else if (data[i] == "2" && data[j] == "0" || data[i] == "0" && data[j] == "2")
                    Cost += a;
                else if (data[i] == "2" && data[j] == "1" || data[i] == "1" && data[j] == "2")
                    Cost += b;
                else if (data[i] == "2" && data[j] == "2")
                    Cost += min*2;
                else if(data[i] != data[j])
                {
                    Console.WriteLine(-1);
                    return;
                }
                i++;j--;
            }
            Console.WriteLine(Cost);

        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;

namespace SecTry_1040AF
{
    class Program
    {
        static void Main(string[] args)
        {
            IEnumerable<int> container = Console.ReadLine().Split().Select(int.Parse);
            int n = container.ElementAt(0), whiteCost = container.ElementAt(1), blackCost = container.ElementAt(2), ans = 0;
            List<int> line = Console.ReadLine().Split().Select(int.Parse).ToList();

            for (int i = 0, j = line.Count - 1; i <= j; i++, j--)
            {
                if (i == j && line[i] == 2) ans += Math.Min(whiteCost, blackCost);
                else if (line[i] != 2 && line[j] == 2) ans += line[i] == 0 ? whiteCost : blackCost;
                else if (line[i] == 2 && line[j] != 2) ans += line[j] == 0 ? whiteCost : blackCost;
                else if (line[i] == 2 && line[j] == 2) ans += Math.Min(blackCost, whiteCost)*2;
                else if (line[i] != line[j])
                {
                    ans = -1;
                    break;
                }

            }

            Console.WriteLine(ans);

        }
    }
}

using System;

namespace CF_1040_A
{
    class Program
    {
        static void Main(string[] args)
        {
            string[]s=Console.ReadLine().Split();
            int n = int.Parse(s[0]);
            int a = int.Parse(s[1]);
            int b = int.Parse(s[2]);

            int[] c = new int[n];
            s = Console.ReadLine().Split();
            for (int i = 0; i < n; i++)
            {
                c[i] = int.Parse(s[i]);
            }

            int ans = 0;
            for (int i = 0, j=n-1; i < n/2; i++, j--)
            {
                if( c[i]==0 && c[j]==1 ||
                    c[i]==1 && c[j]==0)
                {
                    Console.WriteLine(-1);
                    return;
                }
                if(c[i]==2 && c[j]==2)
                {
                    ans += Math.Min(a, b)*2;
                }
                if( c[i]==0 && c[j]==2 ||
                    c[i]==2 && c[j]==0)
                {
                    ans += a;
                }
                if (c[i] == 1 && c[j] == 2 ||
                    c[i] == 2 && c[j] == 1)
                {
                    ans += b;
                }
            }

            // Нужно переодеть центрального
            if (n % 2 == 1 && c[n / 2] == 2)
                ans += Math.Min(a, b);

            Console.WriteLine(ans);
        }
    }
}

using System;

namespace Task1
{
    class Program
    {
        static void Main(string[] args)
        {
            string inp = Console.ReadLine();
            string[] m = inp.Split();

            int n = int.Parse(m[0]);
            int a = int.Parse(m[1]);
            int b = int.Parse(m[2]);
            int minc;
            if (a < b)
            {
                 minc = a;
            }
            else {  minc = b; }

            int s = 0;
            int[] c = new int[n];
            inp = Console.ReadLine();
            m = inp.Split();
            for (int ii=0; ii<n; ii++)
            {
                c[ii] = int.Parse(m[ii]);
            }

            int i = 0;
            int j = n - 1;
            while (i < j)
            {
                if (c[i]==c[j])
                {
                    if (c[i]==2)
                    {
                        s = s + minc*2;
                    }
                }
                else
                {
                    if (c[i]==1 && c[j]==0 || c[i]==0 && c[j]==1)
                    {
                        Console.WriteLine(-1);
                        return;
                    }

                    if (c[i]==2 && c[j]==0 || c[i]==0 && c[j]==2)
                    {
                        s = s + a;
                    }
                    if (c[i] == 2 && c[j] == 1 || c[i] == 1 && c[j] == 2)
                    {
                        s = s + b;
                    }
                }
                i++;
                j--;
            }
            if (n%2==1 && c[i]==2)
            {
                s = s + minc;
            }
            Console.WriteLine(s);
        }
    }
}

using System;
using System.Linq;

class Program
{
    static void Main()
    {
        int[] x = Console.ReadLine().Split().Select(i => int.Parse(i)).ToArray();
        int[] g = { x[1], x[2], x[1] < x[2] ? x[1] : x[2] };
        int[] y = Console.ReadLine().Split().Select(i => int.Parse(i)).ToArray();
        int count = 0;
        if (x[0] % 2 != 0) if (y[x[0] / 2] == 2) count += g[2];
        for (int i = 0, j=x[0]-1; i < x[0]/2; i++,j--)
        {
            if (y[i] == y[j]) { if (y[i] == 2) count += 2 * g[2]; }
            else if (y[i] == 2) count += g[y[j]];
            else if (y[j] == 2) count += g[y[i]];
            else
            {
                count = -1;
                break;
            }
        }
        Console.WriteLine(count);
    }
}

using System;
using System.Collections.Generic;
using System.Linq;

namespace olymp
{
    class Program
    {
        public static List<int> ReadIntLine()
        {
            List<int> input = Console.ReadLine()
                                 .Split(' ')
                                 .Select((a) => Convert.ToInt32(a))
                                 .ToList();
            return input;
        }

        static void Main(string[] args)
        {
            List<int> info = ReadIntLine();
            List<int> d = ReadIntLine();

            int white = info[1];
            int black = info[2];

            int money = 0;
            int min_cost = white < black ? white : black;

            bool is_error = false;

            for (int i = 0; i < d.Count / 2; i++)
            {

                int s = d[i];
                int e = d[d.Count - i - 1];

                if (s == 2 && e == 0)
                {
                    money += white;
                }
                if (s == 2 && e == 1)
                {
                    money += black;
                }
                if (s == 2 && e == 2)
                {
                    money += min_cost * 2;
                }
                if (s == 1 && e == 0)
                {
                    money = -1;
                    is_error = true;
                    break;
                }
                if (s == 1 && e == 2)
                {
                    money += black;
                }
                if (s == 0 && e == 1)
                {
                    money = -1;
                    is_error = true;
                    break;
                }
                if (s == 0 && e == 2)
                {
                    money += white;
                }

            }

            if (d.Count % 2 == 1 && !is_error)
            {
                if (d[d.Count / 2] == 2)
                {
                    money += min_cost;
                }
            }

            Console.WriteLine(money);
        }
    }
}

using System;
using System.Linq;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] input1 = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            int[] input2 = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();

            int n = input1[0];
            int a = input1[1], b = input1[2];

            int len = input2.Length;

            int sum = 0;

            for (int i = 0; i < len; i++)
            {
                if (i <= len - i - 1)
                {
                    if ((input2[i] != input2[len - i - 1]) && (input2[i] < 2) && (input2[len - i - 1] < 2))
                    {
                        Console.WriteLine(-1);
                        return;
                    }

                    if (input2[i] != input2[len - i - 1])
                    {
                        if (input2[i] == 2)
                            sum += (input2[len - i - 1] == 0) ? a : b;
                        else
                            sum += (input2[i] == 0) ? a : b;
                    }

                    if ((input2[i] == input2[len - i - 1]) && (input2[i] == 2))
                    {
                        if (i != len - i - 1)
                            sum += (a < b) ? a * 2 : b * 2;
                        else
                            sum += (a < b) ? a : b;
                    }
                }
            }

            Console.WriteLine(sum);
            //Console.ReadKey();
        }

    }
}

// Problem: 1040A - Palindrome Dance
// Author: Gusztav Szmolik

using System;

class PalindromeDance
    {
    static int Main ()
        {
        string[] words = ReadSplitLine (3);
        if (words == null)
            return -1;
        byte n;
        if (!Byte.TryParse (words[0], out n))
            return -1;
        if (n < 1 || n > 20)
            return -1;
        byte a;
        if (!Byte.TryParse (words[1], out a))
            return -1;
        if (a < 1 || a > 100)
            return -1;
        byte b;
        if (!Byte.TryParse (words[2], out b))
            return -1;
        if (b < 1 || b > 100)
            return -1;
        words = ReadSplitLine (n);
        if (words == null)
            return -1;
        byte[] c = new byte[n];
        for (byte i = 0; i < n; i++)
            {
            byte ci;
            if (!Byte.TryParse (words[i], out ci))
                return -1;
            if (ci > 2)
                return -1;
            c[i] = ci;
            }
        byte idxBound = Convert.ToByte (n/2);
        byte idxLast = Convert.ToByte (n-1);
        byte priceCheap = Math.Min (a,b);
        short ans = 0;
        for (byte i = 0; i < idxBound && ans > -1; i++)
            {
            byte j = Convert.ToByte (idxLast-i);
            if (c[i] == 2 && c[j] == 2)
                ans += Convert.ToInt16 (2*priceCheap);
            else if (c[i] == 2)
                ans += (c[j] == 0 ? a : b);
            else if (c[j] == 2)
                ans += (c[i] == 0 ? a : b);
            else if (c[i] != c[j])
                ans = -1;
            }
        if (n%2 == 1 && ans > -1 && c[idxBound] == 2)
            ans += priceCheap;
        Console.WriteLine (ans);
        return 0;
        }

    static string[] ReadSplitLine (uint numWordNeed)
        {
        string line = Console.ReadLine ();
        if (line == null)
            return null;
        char[] delims = new char[2] {' ', '\t'};
        string[] words = line.Split (delims,StringSplitOptions.RemoveEmptyEntries);
        return (words.Length == numWordNeed ? words : null);
        }
    }

using System;
using System.Collections.Generic;
using System.Linq;

class Program
{

    #region Read Input
    static string[] lines;
    static int lineIndex = 0;

    static string ReadNextLine()
    {
#if DEBUG
        if (lines == null)
            lines = System.IO.File.ReadAllLines("input.txt");
        return lines[lineIndex++];
#else
        return Console.ReadLine();
#endif
    }
    #endregion

    static void Main(string[] args)
    {
        var data = ReadNextLine().Split(' ');
        int n = int.Parse(data[0]);
        int a = int.Parse(data[1]);
        int b = int.Parse(data[2]);

        data = ReadNextLine().Split(' ');
        int[] arr = new int[n];
        for (int i = 0; i < n; i++)
            arr[i] = int.Parse(data[i]);

        long res = 0;
        int med = n / 2;
        int minCost = Math.Min(a, b);
        for (int i = 0; i < med; i++)
        {
            int left = arr[i];
            int right = arr[n - i - 1];

            if (left == 2 && right == 2)
                res += 2 * minCost;
            else if (left == 2)
                res += right == 1 ? b : a;
            else if (right == 2)
                res += left == 1 ? b : a;
            else if (right != left)
            {
                res = -1;
                break;
            }
        }

        if (res >= 0 && n % 2 == 1 && arr[med] == 2)
            res += minCost;

        Console.WriteLine(string.Format("{0:d}", res));

#if DEBUG
        Console.ReadKey();
#endif
    }

}

using System;
using System.Collections.Generic;

class Program
{

    #region Read Input
    static string[] lines;
    static int lineIndex = 0;

    static string ReadNextLine()
    {
#if DEBUG
        if (lines == null)
            lines = System.IO.File.ReadAllLines("input.txt");
        return lines[lineIndex++];
#else
        return Console.ReadLine();
#endif
    }
    #endregion

    static void Main(string[] args)
    {
        var data = ReadNextLine().Split(' ');
        int count = int.Parse(data[0]);
        int valueWhite = int.Parse(data[1]);
        int valueBlack = int.Parse(data[2]);
        int min = Math.Min(valueBlack, valueWhite);

        int cost = 0;
        int iterCount;

        int[] arr = new int[count];
        data = ReadNextLine().Split(' ');
        for (int i = 0; i < count; i++)
        {
            arr[i] = int.Parse(data[i]);
        }

        if(count % 2 == 0)
        {
           iterCount = (count - 1) / 2;
        }
        else
        {
            iterCount = count / 2;
        }

        for (int i = 0; i <= iterCount; i++)
        {
            int left = arr[i];
            int right = arr[count - i - 1];

            if (left == right)
            {
                if (left == 2)
                {
                    if (i == count - i - 1)
                        cost += min;
                    else
                        cost += 2 * min;
                }

            }
            else
            {
                if (left != 2 && right != 2)
                {
                    Console.WriteLine(-1);
                    return;
                }
                else
                {
                    if (left == 2)
                    {
                        if (right == 0)
                        {
                            cost += valueWhite;
                        }
                        else
                        {
                            cost += valueBlack;
                        }
                    }
                    else
                    {
                        if (left == 0)
                        {
                            cost += valueWhite;
                        }
                        else
                        {
                            cost += valueBlack;
                        }
                    }
                }

            }
        }

        Console.WriteLine(cost);
        //long res = 0;
        //Console.WriteLine(string.Format("{0:d}", res));

#if DEBUG
        Console.ReadKey();
#endif
    }

}

using System;
using System.Linq;
using System.Collections.Generic;

namespace _1040A
{
    class Program
    {
        static void Main(string[] args)
        {
            IEnumerable<int> container = Console.ReadLine().Split().Select(int.Parse);
            int n = container.ElementAt(0), a = container.ElementAt(1), b = container.ElementAt(2), ans = 0;

            List<int> line = Console.ReadLine().Split().Select(int.Parse).ToList();
           // int maxCost = Math.Max(a, b), minCost = Math.Min(a, b);

            for (int i = 0, j = line.Count - 1; i<=j; i++, j--)
            {

                if (i == j && line[i] == 2) ans += Math.Min(a, b);
                else if (line[i] == 2 && line[j] != 2) ans += line[j] == 0 ? a : b;
                else if (line[i] != 2 && line[j] == 2) ans += line[i] == 0 ? a : b;
                else if (line[i] == 2 && line[j] == 2) ans += 2 * Math.Min(a, b);
                else if (line[i] != line[j]) { ans = -1; break; }

            }

            Console.WriteLine(ans);

        }
    }
}

using System;
using System.Linq;

namespace codeforces
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] nm = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
            int[] a = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
            int sum = 0;
            for (int i = 0; i < nm[0] / 2; i++)
            {
                if (a[i] != 2 && a[nm[0] - 1 - i] != 2 && a[i] != a[nm[0] - 1 - i])
                {
                    Console.WriteLine(-1);
                    return;
                }
                if (a[i] == a[nm[0] - 1 - i] && a[i] != 2)
                    continue;
                if (a[i] == a[nm[0] - 1 - i] && a[i] == 2)
                    sum += Math.Min(nm[1], nm[2]) * 2;
                else if (a[i] == 2 && a[nm[0] - 1 - i] == 0 || a[i] == 0 && a[nm[0] - 1 - i] == 2)
                    sum += nm[1];
                else sum += nm[2];
            }
            if (nm[0] % 2!=0)
                sum += a[nm[0]/2] == 2 ? Math.Min(nm[1], nm[2]) : 0;
            Console.WriteLine(sum);
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;

namespace ConsoleApp1
{

    class Program
    {
        static void Main(string[] args)
        {
            int[] n = ((Console.ReadLine().Split(' ')).Select(int.Parse)).ToArray();
            int [] array = ((Console.ReadLine().Split(' ')).Select(int.Parse)).ToArray();
            int sum = 0;
            int prev = -1;
            for (int i = 0; i < n[0]/2; i++)
            {
                if (array[i] != array[n[0] - 1 - i])
                {
                    int s = array[i] + array[n[0] - 1 - i];
                    if (s == 1)
                    {
                        sum = -1;
                        break;
                    }
                    else
                    if (s == 2)
                    {
                        sum += n[1];
                    }
                    else
                    {
                        sum += n[2];
                    }
                }
                else if(array[i] == 2)
                {
                  if(n[1] < n[2])
                  {
                    sum += 2*n[1];
                  }
                  else{ sum += 2*n[2];}
                }
            }
            if (sum >= 0 && array[n[0] / 2] == 2 && n[0]%2==1)
                sum += (int)Math.Min(n[1], n[2]);
            Console.WriteLine(sum);
            Console.ReadLine();
        }

    }
}

using System;
using System.Linq;

namespace CSharp
{
    public class _1040A
    {
        public static void Main()
        {
            string[] tokens = Console.ReadLine().Split();

            int n = int.Parse(tokens[0]);
            int a = int.Parse(tokens[1]);
            int b = int.Parse(tokens[2]);

            int[] suit = Console.ReadLine().Split().Select(token => int.Parse(token)).ToArray();

            int cost = 0;

            for (int i = 0, j = n - 1; i <= j; i++, j--)
            {
                if (Math.Max(suit[i], suit[j]) == 2)
                {
                    switch (Math.Min(suit[i], suit[j]))
                    {
                        case 0:
                            cost += a;
                            break;
                        case 1:
                            cost += b;
                            break;
                        case 2:
                            cost += Math.Min(a, b) * (i == j ? 1 : 2);
                            break;
                    }
                }
                else if (suit[i] != suit[j])
                {
                    Console.WriteLine(-1);
                    return;
                }
            }

            Console.WriteLine(cost);
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;

namespace _1
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] str = Console.ReadLine().Split().Select(x=>int.Parse(x)).ToArray();
            int n = str[0];
            int whiteR = str[1];
            int blackR = str[2];
            int min = Math.Min(whiteR, blackR);
            int max = Math.Max(whiteR, blackR);
            bool isPal = true;
            int sum = 0;
            string[] myPal = Console.ReadLine().Split(' ');

            for (int i=0; i<n/2; i++)
            {
                if ((!(myPal[i]==myPal[n-i-1])) &&(!(myPal[n-i-1]=="2")) &&(!(myPal[i]=="2")))
                {
                    isPal = false;
                    break;
                }
            }
            if (!isPal)
            {
                Console.WriteLine("-1");
            }
            else
            {
                for (int i=0; i<n; i++)
                {
                    if (myPal[i]=="2")
                    {
                        if (myPal[n-i-1]=="0")
                        {
                            sum += whiteR;
                        }
                        else if (myPal[n - i - 1] == "1")
                        {
                            sum += blackR;
                        }
                        else
                        {
                            sum += min;
                        }
                    }
                }
                Console.WriteLine(sum);
            }
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;

namespace ConsoleApp1
{

    class Program
    {
        struct Point
        {
            public int l;
            public int r;
            public Point(int l, int r)
            {
                this.l = l;
                this.r = r;
            }
        }
        static void Main(string[] args)
        {
            int[] n = ((Console.ReadLine().Split(' ')).Select(int.Parse)).ToArray();
            int [] array = ((Console.ReadLine().Split(' ')).Select(int.Parse)).ToArray();
            int sum = 0;
            for (int i = 0; i < n[0]/2; i++)
            {
                if (array[i] != array[n[0] - 1 - i])
                {
                    int s = array[i] + array[n[0] - 1 - i];
                    if (s == 1)
                    {
                        sum = -1;
                        break;
                    }
                    else
                    if (s == 2)
                    {
                        sum += n[1];
                    }
                    else
                    {
                        sum += n[2];
                    }

                }
            }
            if (sum >= 0 && array[n[0] / 2] == 2)
                sum += n[0]%2==0 ?  2*  (int)Math.Min(n[1], n[2]) : (int)Math.Min(n[1], n[2]);
            Console.WriteLine(sum);
            Console.ReadLine();
        }

    }
}

using System;
using System.Collections.Generic;
using System.Linq;

namespace ConsoleApp1
{

    class Program
    {
        struct Point
        {
            public int l;
            public int r;
            public Point(int l, int r)
            {
                this.l = l;
                this.r = r;
            }
        }
        static void Main(string[] args)
        {
            int[] n = ((Console.ReadLine().Split(' ')).Select(int.Parse)).ToArray();
            int [] array = ((Console.ReadLine().Split(' ')).Select(int.Parse)).ToArray();
            int sum = 0;
            for (int i = 0; i < n[0]/2; i++)
            {
                if (array[i] != array[n[0] - 1 - i])
                {
                    int s = array[i] + array[n[0] - 1 - i];
                    if (s == 1)
                    {
                        sum = -1;
                        break;
                    }
                    else
                    if (s == 2)
                    {
                        sum += n[1];
                    }
                    else
                    {
                        sum += n[2];
                    }

                }
            }
            if (sum >= 0 && array[n[0] / 2] == 2)
                sum += (int)Math.Min(n[1], n[2]);
            Console.WriteLine(sum);
            Console.ReadLine();
        }

    }
}

using System;
using System.Collections.Generic;
using System.Linq;

namespace ConsoleApp1
{

    class Program
    {
        static void Main(string[] args)
        {
            int[] n = ((Console.ReadLine().Split(' ')).Select(int.Parse)).ToArray();
            int [] array = ((Console.ReadLine().Split(' ')).Select(int.Parse)).ToArray();
            int sum = 0;
            int prev = -1;
            for (int i = 0; i < n[0]/2; i++)
            {
                if (array[i] != array[n[0] - 1 - i])
                {
                    int s = array[i] + array[n[0] - 1 - i];
                    if (s == 1)
                    {
                        sum = -1;
                        break;
                    }
                    else
                    if (s == 2)
                    {
                      prev = 0;
                        sum += n[1];
                    }
                    else
                    {
                      prev = 1;
                        sum += n[2];
                    }
                }
                else if(array[i] == 2)
                {
                  if(prev == 1) sum += 2*n[1];
                  else if(prev == 0) sum += 2*n[2];
                  else if(n[1] < n[2])
                  {
                    prev = 0;
                    sum += 2*n[1];
                  }
                  else{ prev = 1; sum += 2*n[2];}
                }
                else prev = array[i];
            }
            if (sum >= 0 && array[n[0] / 2] == 2 && n[0]%2==1)
                sum += (int)Math.Min(n[1], n[2]);
            Console.WriteLine(sum);
            Console.ReadLine();
        }

    }
}

using System;

public class Solution
{
    static void Main(String[] args)
    {
        string[] input = Console.ReadLine().Split(' ');
        int n = int.Parse(input[0]);
        int a = int.Parse(input[1]);
        int b = int.Parse(input[2]);
        int[] d = new int[n];
        input = Console.ReadLine().Split(' ');
        for (int i = 0; i < n; i++)
        {
            d[i] = int.Parse(input[i]);
        }
        int cost = 0;
        for (int i = 0; i < n; i++)
        {
            if (d[i] == 2)
            {
                int j = n - i - 1;
                if (d[j] == 2)
                {
                    if (a > b)
                    {
                        d[i] = d[j] = b;
                        cost += b;
                    }
                    else
                    {
                        d[i] = d[j] = a;
                        cost += a;
                    }
                }
                else
                {
                    if (d[j] == 0)
                    {
                        cost += a;
                        d[i] = d[j];
                    }
                    else
                    {
                        cost += b;
                        d[i] = d[j];
                    }
                }
            }
            else if (d[i] == 1 && d[n - i - 1] == 0)
            {
                Console.WriteLine(-1);
                return;
            }
        }
        Console.WriteLine(cost);
    }
}

using System;
using System.Collections.Generic;
using System.Linq;

namespace Contest
{
    class Program
    {
        static void Main(string[] args)
        {
            Reader r = new Reader();
            r.TakeInput();
            int n = r.NextInt();
            int a = r.NextInt();
            int b = r.NextInt();
            int[] d = r.TakeIntArray();
            int cost = 0;
            for (int i = 0, j = n - 1; i < j; i++, j--)
            {
                if (d[i] == 0 && d[j] == 2 || d[i] == 2 && d[j] == 0)
                {
                    cost += a;
                }
                if (d[i] == 1 && d[j] == 2 || d[i] == 2 && d[j] == 1)
                {
                    cost += b;
                }
                if (d[i] == 2 && d[j] == 2)
                {
                    cost += Math.Min(a, b);
                }
                if (d[i] == 1 && d[j] == 0 || d[i] == 0 && d[j] == 1)
                {
                    Console.WriteLine(-1);
                    return;
                }
            }
            if (n % 2 == 1 && d[n / 2] == 2)
            {
                cost += Math.Min(a, b);
            }
            Console.WriteLine(cost);
        }
    }

    class Reader
    {
        int _idx;
        string[] _input;

        public void TakeInput()
        {
            _idx = 0;
            _input = Console.ReadLine().Split(' ');
        }

        public int[] TakeIntArray()
        {
            string[] input = Console.ReadLine().Split(' ');
            int[] a = new int[input.Length];
            for (int i = 0; i < input.Length; i++)
            {
                a[i] = int.Parse(input[i]);
            }
            return a;
        }

        public int NextInt()
        {
            return int.Parse(_input[_idx++]);
        }

        public long NextLong()
        {
            return long.Parse(_input[_idx++]);
        }

        public string NextString()
        {
            return _input[_idx++];
        }
    }
}

using System;

public class Solution
{
    static void Main(String[] args)
    {
        string[] input = Console.ReadLine().Split(' ');
        int n = int.Parse(input[0]);
        int a = int.Parse(input[1]);
        int b = int.Parse(input[2]);
        int[] d = new int[n];
        input = Console.ReadLine().Split(' ');
        for (int i = 0; i < n; i++)
        {
            d[i] = int.Parse(input[i]);
        }
        int cost = 0;
        for (int i = 0; i < n; i++)
        {
            if (d[i] == 2)
            {
                int j = n - i - 1;
                if (d[j] == 2)
                {
                    int x;
                    if (a > b)
                    {
                        d[i] = d[j] = b;
                        x = 2 * b;
                    }
                    else
                    {
                        d[i] = d[j] = a;
                        x = 2 * a;
                    }
                    if (i == j)
                    {
                        cost += x / 2;
                    }
                    else
                    {
                        cost = x;
                    }
                }
                else
                {
                    if (d[j] == 0)
                    {
                        cost += a;
                        d[i] = d[j];
                    }
                    else
                    {
                        cost += b;
                        d[i] = d[j];
                    }
                }
            }
            else if (d[i] == 1 && d[n - i - 1] == 0)
            {
                Console.WriteLine(-1);
                return;
            }
        }
        Console.WriteLine(cost);
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Танец_палиндром
{
    class Program
    {
        static void Main(string[] args)
        {
            int res = 0;
            string s = Console.ReadLine();
            string[] values = s.Split(' ');
            int n = int.Parse(values[0]);
            int a = int.Parse(values[1]);
            int b = int.Parse(values[2]);
            s = Console.ReadLine();
            string[] values2 = s.Split(' ');
            int[] arr = new int[n];
            for (int i=0; i<n; i++)
            {
                arr[i] = int.Parse(values2[i]);
            }
            int min=a;
            if (a>b)
            {
                min = b;
            }
            int x = 0;
            if (n%2==1)
            {
                x = n / 2 + 1;
            }
            else
            {
                x = n / 2;
            }
            for (int i = 0; i < x; i++)
            {
                if (arr[i]==arr[n-1-i])
                {
                    if(arr[i]==2)
                    {
                        if (i == x - 1)
                            res = res + min;
                        if (n==2)
                        {
                            res = res + 2 * min;
                        }
                        else
                            res = res + 2 * min;
                    }
                }
                else
                {
                    if(((arr[i]==0)&&(arr[n-1-i]==2))||((arr[n-1-i]==0)&&(arr[i]==2)))
                    {
                        res = res + a;
                    }
                    else if(((arr[i] == 1) && (arr[n - 1 - i] == 2)) || ((arr[n - 1 - i] == 1) && (arr[i] == 2)))
                    {
                        res = res + b;

                    }
                    else
                    {
                        res = -1;
                        break;
                    }
                }
            }
            Console.WriteLine(res);

        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Танец_палиндром
{
    class Program
    {
        static void Main(string[] args)
        {
            int res = 0;
            string s = Console.ReadLine();
            string[] values = s.Split(' ');
            int n = int.Parse(values[0]);
            int a = int.Parse(values[1]);
            int b = int.Parse(values[2]);
            s = Console.ReadLine();
            string[] values2 = s.Split(' ');
            int[] arr = new int[n];
            for (int i=0; i<n; i++)
            {
                arr[i] = int.Parse(values2[i]);
            }
            int min=a;
            if (a>b)
            {
                min = b;
            }
            int x = 0;
            if (n%2==1)
            {
                x = n / 2 + 1;
            }
            else
            {
                x = n / 2;
            }
            for (int i = 0; i < x; i++)
            {
                if (arr[i]==arr[n-1-i])
                {
                    if(arr[i]==2)
                    {
                        if (i == x - 1)
                            res = res + min;
                        else
                            res = res + 2 * min;
                    }
                }
                else
                {
                    if(((arr[i]==0)&&(arr[n-1-i]==2))||((arr[n-1-i]==0)&&(arr[i]==2)))
                    {
                        res = res + a;
                    }
                    else if(((arr[i] == 1) && (arr[n - 1 - i] == 2)) || ((arr[n - 1 - i] == 1) && (arr[i] == 2)))
                    {
                        res = res + b;

                    }
                    else
                    {
                        res = -1;
                        break;
                    }
                }
            }
            Console.WriteLine(res);

        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PalindromeDance
{
    class Program
    {
        static void Main(string[] args)
        {
            const int DANCER_WITH_WHITE_SUIT = 0;
            const int DANCER_WITH_BLACK_SUIT = 1;
            const int DANCER_WITH_UNKNOWN_SUIT = 2;

            //
            string[] inputs = Console.ReadLine().Split(' ');
            int n = int.Parse(inputs[0]);
            int PriceWhiteSuit = int.Parse(inputs[1]);
            int PriceBlackSuit = int.Parse(inputs[2]);

            string[] inputsDancers = Console.ReadLine().Split(' ');
            int[] Dancers = Array.ConvertAll(inputsDancers, x => int.Parse(x));
            int result = 0;
            for (int i = 0; i < n / 2 && result != -1; i++)
            {
                if (Dancers[i] != Dancers[n - i - 1] && Dancers[i] != DANCER_WITH_UNKNOWN_SUIT && Dancers[n - i - 1] != DANCER_WITH_UNKNOWN_SUIT)
                {
                    result = -1;
                }
                else
                {
                    if (Dancers[i] != Dancers[n - i - 1])
                    {
                        if (Dancers[i] == DANCER_WITH_BLACK_SUIT)
                            result += PriceBlackSuit;

                        if (Dancers[i] == DANCER_WITH_WHITE_SUIT)
                            result += PriceWhiteSuit;

                        if (Dancers[n - i - 1] == DANCER_WITH_BLACK_SUIT)
                            result += PriceBlackSuit;

                        if (Dancers[n - i - 1] == DANCER_WITH_WHITE_SUIT)
                            result += PriceWhiteSuit;
                    }
                    else
                    {
                        if (Dancers[i] == Dancers[n - i - 1] && Dancers[n - i - 1] == DANCER_WITH_UNKNOWN_SUIT)
                        {
                            if (PriceWhiteSuit < PriceBlackSuit)
                            {
                                result += PriceWhiteSuit;
                            }
                            else
                            {
                                result += PriceBlackSuit;
                            }
                        }
                    }
                }
            }

            if(n%2 != 0 && Dancers[n/2] == DANCER_WITH_UNKNOWN_SUIT && result != -1)
            {
                if(PriceWhiteSuit < PriceBlackSuit)
                {
                    result += PriceWhiteSuit;
                }
                else
                {
                    result += PriceBlackSuit;
                }
            }

            Console.WriteLine(result);
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;

namespace _1040A
{
    class Program
    {
        static void Main(string[] args)
        {
            IEnumerable<int> container = Console.ReadLine().Split().Select(int.Parse);
            int n = container.ElementAt(0), whiteCost = container.ElementAt(1), blackCost=container.ElementAt(2);
            List<int> colorslist = Console.ReadLine().Split().Select(int.Parse).ToList();
            int minCost = 0;
            if (n == 1 || !colorslist.Contains(2)) Console.WriteLine(0);
            else if (!CheckPalin(colorslist, n)) Console.WriteLine(-1);
            else
            {
                for (int i = 0; i < n / 2; i++)
                {
                    if (colorslist[i] == 1 && colorslist[n - 1] == 2 || colorslist[i] == 2 && colorslist[n - 1] == 1)
                        minCost += blackCost;
                    else if (colorslist[i] == 0 && colorslist[n - 1] == 2 || colorslist[i] == 2 && colorslist[n - 1] == 0)
                        minCost += whiteCost;
                    else
                    {
                        minCost += (Math.Min(whiteCost, blackCost)) * 2;
                    }
                }
                if (n % 2 == 1 && colorslist[n / 2 + 1] == 2) minCost += Math.Min(whiteCost, blackCost);
                Console.WriteLine(minCost);
            }

        }
        public static bool CheckPalin(List<int> colorslist,int n)
        {
            bool answer = true;
            for(int i=0;i<(n/2);i++)
            {
                if(colorslist[i]!=colorslist[n-1] && (colorslist[i]!=2 && colorslist[n-1]!=2))
                {
                    answer = false;
                    break;
                }
            }
            return answer;
        }
    }
}

using System;

namespace CF_1040_A
{
    class Program
    {
        static void Main(string[] args)
        {
            string[]s=Console.ReadLine().Split();
            int n = int.Parse(s[0]);
            int a = int.Parse(s[1]);
            int b = int.Parse(s[2]);

            int[] c = new int[n];
            s = Console.ReadLine().Split();
            for (int i = 0; i < n; i++)
            {
                c[i] = int.Parse(s[i]);
            }

            int ans = 0;
            for (int i = 0, j=n-1; i < n/2; i++, j--)
            {
                if( c[i]==0 && c[j]==1 ||
                    c[i]==1 && c[j]==0)
                {
                    Console.WriteLine(-1);
                    return;
                }
                if(c[i]==2 && c[j]==2)
                {
                    ans += Math.Min(a, b)*2;
                }
                if( c[i]==0 && c[j]==2 ||
                    c[i]==2 && c[i]==0)
                {
                    ans += a;
                }
                if (c[i] == 1 && c[j] == 2 ||
                    c[i] == 2 && c[i] == 1)
                {
                    ans += b;
                }
            }

            // Нужно переодеть центрального
            if (n % 2 == 1 && c[n / 2] == 2)
                ans += Math.Min(a, b);

            Console.WriteLine(ans);
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;

namespace ConsoleApp1
{

    class Program
    {
        static void Main(string[] args)
        {
            int[] n = ((Console.ReadLine().Split(' ')).Select(int.Parse)).ToArray();
            int [] array = ((Console.ReadLine().Split(' ')).Select(int.Parse)).ToArray();
            int sum = 0;
            int prev = -1;
            for (int i = 0; i < n[0]/2; i++)
            {
                if (array[i] != array[n[0] - 1 - i])
                {
                    int s = array[i] + array[n[0] - 1 - i];
                    if (s == 1)
                    {
                        sum = -1;
                        break;
                    }
                    else
                    if (s == 2)
                    {
                      prev = 0;
                        sum += n[1];
                    }
                    else
                    {
                      prev = 1;
                        sum += n[2];
                    }
                }
                else if(array[i] == 2)
                {
                  if(prev == 1) sum += n[1];
                  else if(prev == 0) sum += n[2];
                  else if(n[1] < n[2])
                  {
                    prev = 0;
                    sum += n[1];
                  }
                  else{ prev = 1; sum += n[2];}
                }
                else prev = array[i];
            }
            if (sum >= 0 && array[n[0] / 2] == 2)
                sum += n[0]%2==0 ?  2*  (int)Math.Min(n[1], n[2]) : (int)Math.Min(n[1], n[2]);
            Console.WriteLine(sum);
            Console.ReadLine();
        }

    }
}

using System;
using System.Collections.Generic;
using System.Linq;

namespace ConsoleApp1
{

    class Program
    {
        static void Main(string[] args)
        {
            int[] n = ((Console.ReadLine().Split(' ')).Select(int.Parse)).ToArray();
            int [] array = ((Console.ReadLine().Split(' ')).Select(int.Parse)).ToArray();
            int sum = 0;
            int prev = -1;
            for (int i = 0; i < n[0]/2; i++)
            {
                if (array[i] != array[n[0] - 1 - i])
                {
                    int s = array[i] + array[n[0] - 1 - i];
                    if (s == 1)
                    {
                        sum = -1;
                        break;
                    }
                    else
                    if (s == 2)
                    {
                      prev = 0;
                        sum += n[1];
                    }
                    else
                    {
                      prev = 1;
                        sum += n[2];
                    }
                }
                else if(array[i] == 2)
                {
                  if(prev == 1) sum += n[1];
                  else if(prev == 0) sum += n[2];
                  else if(n[1] < n[2])
                  {
                    prev = 0;
                    sum += n[1];
                  }
                  else{ prev = 1; sum += n[2];}
                }
                else prev = array[i];
            }
            if (sum >= 0 && array[n[0] / 2] == 2 && n[0]%2==1)
                sum += (int)Math.Min(n[1], n[2]);
            Console.WriteLine(sum);
            Console.ReadLine();
        }

    }
}