program answer
  implicit none

  integer(8) :: i, j, k,  D, teika, su, vmax
  integer, parameter :: n=26
  integer(8) :: c(n), last(n)
  integer, allocatable :: S(:,:), t(:), v(:), vv(:),mm(:)
  read(*,*) D
  read(*,*) c
  allocate(S(n,D))

  do i = 1, D
     read(*,*) s(i,1:n)
  end do
  allocate(t(D))
  do i = 1, D
     read(*,*) t(i)
  end do
  allocate(v(D))
  allocate(mm(n))
  allocate(vv(n))

  vmax=0
  do k= 1, n
  su=sum(c)
  teika=su-c(k)
  v(1)=s(1,k)-teika
  if(v(1)>vmax) then
     vmax=v(1)
     t(1)=k
  end if 
 end do
 vv(1)=vmax
  last=0
  last(t(1))=1
  
  do i = 2, D
     teika=0
     vmax=0
     do j = 1, 26
        teika=teika+c(j)*(i-last(j))
     end do
     do k = 1, n
     teika=teika-c(k)*(i-last(k))
     v(i)=v(i-1)+s(i,t(i))-teika
     last(t(i))=i
     if(v(i)>vmax) then
     vmax=v(i)
     t(i)=k
     end if
  teika=0
  v(i)=0
  vv(i)=vmax
  end do
  end do

  do i = 1, n
     write(*,*) t(i)
  end do
  stop
 end program answer

 
