program r20628c
 
implicit none
integer :: c(1:26)
integer, allocatable :: interval(:, :)
integer, allocatable :: s(:, :)
integer, allocatable :: t(:), v(:)
integer :: i, j, d, m, h
integer, allocatable :: smalld(:)
integer, allocatable :: q(:)
 
 
read *, d
 
allocate(s(1:26, 1:d))
allocate(interval(1:26, 0:d))
allocate(t(1:d))
allocate(v(0:d))
 
interval(:, :) = 0 !interval(i,d) = d - last(d,i)
v(0) = 0
 
read *, c(1:26)
 
do i = 1, d
 read *, s(:, i)
end do

do i = 1, d 
  do j = 1, 26
  if (s(j, i) - (c(j) * interval(j, i-1)) > m) then
  m = s(j, i)
  h = j
  end if
  end do

print *, h

v(i) = h
 
 v(i) = v(i-1) + s(t(i), i)
 
 do j = 1, 26
  if(t(i) == j) then
   interval(j, i) = 0
  else
   interval(j, i) = interval(j, i-1) + 1
  end if
  v(i) = v(i) - (c(j) * interval(j, i))
 end do
 
! print *, v(i)
end do

 
print *, v(d)
 
end do
 
 
end program r20628c