#define NO_LOCAL
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;

namespace Program
{
    /* 提出前に REPEATAS = 1 を確認！ */
    public class Program
    {
        int D = 365;
        int[] c;
        int[,] s;
        private const int LIMIT_OFFSET = 28, REPEATS = 5;
        public const string IN_TXT = "in1.txt";

        private void Solve() {
            var t = new int[D];
            for (int i = 0; i < D; i++) {
                t[i] = ReadInt;
            }

            for (int i = 0; i < D; i++) {
                Console.WriteLine(Eval(t, i + 1));
            }
        }

        // ReSharper disable once SuggestBaseTypeForParameter
        private int Eval(int[] res, int end = -1) {
            if (end == -1) end = D;
            var last = new int[26];
            int result = 0;
            for (int d = 1; d <= end; ++d) {
                var i = res[d - 1] - 1;
                result += s[d - 1, i];
                last[i] = d;
                for (int j = 0; j < 26; j++) {
                    result -= c[j] * (d - last[j]);
                }
            }

            return result;
        }

        private void Input() {
            D = ReadInt;
            c = ReadIntArray;
            s = new int[D, 26];
            for (int i = 0; i < D; i++) {
                var tmp = ReadIntArray;
                for (int j = 0; j < 26; j++) s[i, j] = tmp[j];
            }
        }

        private void Output() { }



        /* 以下テンプレート等 */

        #region

        private readonly int Limit;
        private readonly Random rand;
        private StreamWriter sw;
        private readonly Stopwatch stopwatch;

        public Program(int limit) {
            stopwatch = new Stopwatch();
            rand = new Random();
            Limit = limit;
        }

        public void Main() {
#if LOCAL && !NO_LOCAL
            sw = new StreamWriter("out.txt");
            sr = new StreamReader(IN_TXT);
#else
            sw = new StreamWriter(Console.OpenStandardOutput()) {AutoFlush = false};
            Console.SetOut(sw);
#endif
            stopwatch.Start();
            Input();
            Solve();
            Output();
            sw.Flush();
#if LOCAL && !NO_LOCAL
            sw.Dispose();
            using (var r = new StreamReader("out.txt"))
            {
                while (!r.EndOfStream)
                {
                    Console.WriteLine(r.ReadLine());
                }
            }
#endif
        }

        public static void Main(string[] args) {
            int limit = 3000 - LIMIT_OFFSET;
//            if (args.Any()) limit *= 2;
            for (int i = 0; i < REPEATS; i++) {
                new Program(limit).Main();
#if !LOCAL
break;
#endif
            }
        }

        public void Debug(object o) {
#if LOCAL
            Console.WriteLine(o);
#endif
        }

        private StreamReader sr;

        public string ReadLine {
            get {
#if LOCAL && !NO_LOCAL
                return sr.ReadLine();
#else
                return Console.ReadLine();
#endif
            }
        }

        public string[] ReadArray => ReadLine.Split(' ');
        public int[] ReadIntArray => ReadArray.Select(int.Parse).ToArray();
        public int ReadInt => int.Parse(ReadLine);

        #endregion
    }
}


Measured memory_bytes: 28884