program scoring
    implicit none
    integer D, day, score, wait, i
    integer, dimension(26) :: c, last
    integer, dimension(:, :), allocatable :: satisfy
    integer, dimension(:), allocatable :: typ

    read *, D
    read *, c
    last(:) = 0

    allocate(satisfy(26, D))
    allocate(typ(D))

    read *, satisfy
    read *, typ

    score = 0
    do day=1,D
        last(typ(day)) = day
        wait = 0
        do i=1,26
            wait = wait + c(i)*(day - last(i))
        enddo
        score = score + satisfy(typ(day), day) - wait
        print *, score
    enddo
end program scoring