program scoring
  implicit none
  integer :: d, s(26, 365) = 0, t, i, j, x = 0
  integer, dimension(26) :: c = 0, last = 0
  read(*,*) d
  read(*,*) c
  read(*,*) (s(:, i), i = 1, d)
  do i = 1, d
    read(*,*) t
    last(t) = i
    x = x + s(t, i)
    x = x - sum(c * (i - last))
    write(*,'(i0)') x
  end do
end program scoring