import java.io._
import java.util.StringTokenizer
import scala.util.control.Breaks.{breakable,break}
import scala.collection.mutable.{Map, Stack, Queue, PriorityQueue, Set}
import scala.util.Random
import java.util.Date

object Main extends App {
  val in = new InputReader(System.in)
  val pw = new PrintWriter(System.out)

  val D = in.next().toInt
  val c = new Array[Long](26+1)
  val s = Array.ofDim[Long](D+1, 26+1)

  for (i <- 1 to 26) {
    c(i) = in.next().toInt
  }
  for (d <- 1 to D) {
    for (i <- 1 to 26) {
      s(d)(i) = in.next().toInt
    }
  }

  // optional
  val t = new Array[Int](D+1)
  for (i <- 1 to D) {
    t(i) = in.next().toInt
  }


  def calcScore(t: Array[Int]): Long = {
    var res = 0L

    val last = new Array[Int](26+1)
    for (day <- 1 to D) {
      val now = t(day)
      last(now) = day

      res += s(day)(now)
      for (contest <- 1 to 26) {
        res -= c(contest) * (day - last(contest))
      }
      pw.println(res)
    }

    res
  }

  calcScore(t)
  pw.flush()
}

object Sub {
  def print2DimArray[A](mat: Array[Array[A]]): Unit = {
    mat.foreach(lin => println(lin.toList))
  }
}

class InputReader(stream: InputStream) {
  private[this] val reader = new BufferedReader(new InputStreamReader(stream))
  private[this] var tokenizer: StringTokenizer = new StringTokenizer(reader.readLine())
  def next(): String = {
    while (!tokenizer.hasMoreTokens()) {
      tokenizer = new StringTokenizer(reader.readLine())
    }
    tokenizer.nextToken()
  }
}
