fun main() {
    val d = readLine()!!.toInt()
    val c = readLine()!!.split(" ").map { it.toInt() }
    val list = (0 until d).map { readLine()!!.split(" ").map { it.toInt() } }

    val listT = (0 until d).map { readLine()!!.toInt() }

    val executeDate = IntArray(26) { 0 }
    fun last(date: Int): Int =
        (0 until 26).map {
            c[it] * (date - executeDate[it])
        }.sum()

    var last = 0
    (1..d).forEach {
        val exam = listT[it - 1] - 1
        val add = list[it - 1][exam]
        executeDate[exam] = it

        val remove = last(it)
        last += add - remove
        println(last)
    }
}