// input
let D = Int(readLine()!)!
let cs: [Int] = readLine()!.split(separator: " ").map { Int($0)! }
let ss: [[Int]] = (1...D).map { _ in readLine()!.split(separator: " ").map { Int($0)! } }

// output
let ts: [Int] = (1...D).map { _ in Int(readLine()!)! }


func calculateSatisfactionPoint(D: Int, cs: [Int], ss: [[Int]], ts: [Int]) {
    var lastContestDate: [Int] = Array(repeating: 0, count: 26)
    var vs: [Int] = [0]
    for d in 1...D {
        let todayContestType: Int = ts[d-1]
        vs.append(vs[d-1] + ss[d-1][todayContestType-1])
        lastContestDate[todayContestType-1] = d
        
        var decreaseSatisfactionPoint: Int = 0
        for i in 0..<26 {
            decreaseSatisfactionPoint -= cs[i]*(d - lastContestDate[i])
        }
        vs[d] += decreaseSatisfactionPoint
        print(vs[d])
    }
}

calculateSatisfactionPoint(D: D, cs: cs, ss: ss, ts: ts)	// (๑•ૅㅁ•๑)