using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using static System.Math;
using static System.Array;
using static AtCoder.Tool;

using System.Diagnostics;
namespace AtCoder
{
    class AC
    {
        const int MOD = 1000000007;
        const int INF = int.MaxValue / 2;
        const long SINF = long.MaxValue / 2;
        const double EPS = 1e-8;
        static readonly int[] dx = { 0, 1, 0, -1 };
        static readonly int[] dy = { 1, 0, -1, 0 };

        static int D;
        static long[] c;
        static long[][] s;
        static Rand rnd = new Rand();

       
        static void Main(string[] args)
        {
            var Sw = new Stopwatch();

            //var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            //Console.SetOut(sw);
            var cin = new Scanner();

            D = int.Parse(Console.ReadLine());
            c = cin.SplitReadL();
            s = new long[D][];
            for(var i = 0; i < D; i++)
            {
                s[i] = cin.SplitReadL();
            }
            /*Sw.Start();
            while (Sw.ElapsedMilliseconds < 10000)
            {
                
            }*/
            var t = new int[D];
            for (var i = 0; i < D; i++) t[i] = int.Parse(Console.ReadLine()) - 1;
            Score(t);
            //Console.Out.Flush();

        }

        struct Perm : IComparable<Perm>
        {
            public int[] order;
            public double score;
            public Perm(int[] o)
            {
                order = o;
                score = Score(o);
            }

            public int CompareTo(Perm other)
            {
                return score.CompareTo(other.score);
            }
        }

        static double Prob(double T, double d)
        {
            return Pow(E, (-d / T));
        }

        static double Temp(double time)
        {
            double Ts = 1000;
            double Te = 0.001;
            double t = time / 10000;
            //return Ts * (1 - t) + Te * t;
            return Pow(Ts, (1 - t)) * Pow(Te, t);
        }

        struct P : IComparable<P>
        {
            public double x;
            public double y;
            public P(double xi, double yi)
            {
                x = xi;
                y = yi;
            }

            public int CompareTo(P other)
            {
                return x.CompareTo(other.x);
            }
        }
        static long Score(int[] t)
        {
            long ret = 0;
            var last = new int[26];
            for(var i = 0; i < D; i++)
            {
                ret += s[i][t[i]];
                last[t[i]] = i + 1;
                for (var j = 0; j < 26; j++) ret -= c[j] * (i + 1 - last[j]);
                Console.WriteLine(ret);
            }
            return ret;
        }

        static int[] Next(int inf, int lim)
        {
            /*var ret = (int[])a.Clone();

            int i = rnd.RandNum(a.Length);
            ret[i] = ret[(i + 1) % a.Length];
            ret[(i + 1) % a.Length] = a[i];

            return ret;*/
            int i = rnd.RandNum(inf, lim - 1);
            int j = rnd.RandNum(i + 1, lim);

            return new int[] { i, j };
        }



    }
    public class Rand
    {
        public int RandNum(int m, int M)
        {
            var rnd = new Random((int)DateTime.Now.Ticks);
            return rnd.Next(m, M);
        }

        public double RandDouble()
        {
            var rnd = new Random((int)DateTime.Now.Ticks);
            return rnd.NextDouble();
        }
    }


    public class Scanner
    {
        public int[] SplitRead()
        {
            int[] array = Console.ReadLine().Split().Select(int.Parse).ToArray();
            return array;
        }
        public long[] SplitReadL()
        {
            long[] array = Console.ReadLine().Split().Select(long.Parse).ToArray();
            return array;
        }
    }

    public static class Tool
    {
        static public void Initialize<T>(ref T[] array, T initialvalue)
        {
            for (var i = 0; i < array.Length; i++)
            {
                array[i] = initialvalue;
            }
        }
    }
}


Measured memory_bytes: 28860