program atcoder_contest_scheduling
  implicit none
  integer, parameter :: maxday = 365, maxtype = 26
  integer :: d, c(maxtype), s(maxtype, maxday), t(maxday), u(maxday)
  integer :: m, n, p, i, j
  logical :: f
  real(8) :: t1, t2
  call cpu_time(t1)
  call random_seed_clock()
  read(*,*) d
  read(*,*) c
  read(*,*) (s(:, i), i = 1, d)
  t = (/(maxloc(s(:, i), 1), i = 1, d)/)
  m = score()
  u = t
  do
    do i = 1, d
      f = .true.
      do j = 1, maxtype
        t(i) = j
        n = score()
        if (m < n) then
          m = n
          u(i) = j
          f = .false.
        end if
        call cpu_time(t2)
        if (t2 - t1 > 1.979d0) goto 100
      end do
      if (f) t(i) = u(i)
    end do
  end do
  100 write(*,'(i0)') (u(i), i = 1, d)
contains
  integer function score() result(res)
    integer :: last(maxtype), i
    last = 0
    res = 0
    do i = 1, d
      last(t(i)) = i
      res = res + s(t(i), i) + dot_product(c, last - i)
    end do
  end
  subroutine random_seed_clock()
    integer :: nseed, clock, seed(1000)
    call system_clock(clock)
    call random_seed(size = nseed)
    seed(1:nseed) = clock
    call random_seed(put = seed(1:nseed))
  end
  integer function next_int(m) result(res)
    integer, intent(in)  :: m
    real(8) :: r
    call random_number(r)
    res = int(m * r) + 1
  end
end program atcoder_contest_scheduling