namespace _1_
{
    internal class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            char[,] a = new char[n, n];
            int[,] b = new int[n, n];
            for (int i = 0; i < n; i++)
            {
                char[] red = Console.ReadLine().ToArray();
                for (int j = 0; j < n; j++)
                    a[i,j] = red[j];
            }
            for (int i = 0; i < n; i++)
            {
                int[] red = Console.ReadLine().Split().Select(int.Parse).ToArray();
                for (int j = 0; j < n; j++)
                {
                    b[i,j] = red[j];
                }
            }
            int br = b[0,0];
            int x = 0;
            int y = 0;
            while (x!=n-1 || y!=n-1)
            {
                if (x == n - 1)
                {
                    y++;
                }
                else if (y == n - 1)
                {
                    x++;
                }
                else if (b[x, y + 1] > b[x + 1, y])
                {
                    x++;
                }
                else if (b[x, y + 1] < b[x + 1, y])
                {
                    y++;
                }

                br += b[x, y];
            }
            Console.WriteLine(br);
        }
    }
}