program atcoder_contest_scheduling
  implicit none
  integer :: d, c(26) = 0, s(26, 365) = 0, t(365) = 0, u(365), m, n, p, q, i
  real(8) :: t1, t2
  call cpu_time(t1)
  call random_seed_clock()
  read(*,*) d
  read(*,*) c
  read(*,*) (s(:, i), i = 1, d)
  t = [(mod(i - 1, 26) + 1, i = 1, d)]
  m = score()
  u = t
  do
    p = next_int(365)
    q = next_int(26)
    t(p) = q
    n = score()
    if (m < n) then
      m = n
      u(p) = q
    else
      t(p) = u(p)
    end if
    call cpu_time(t2)
    if (t2 - t1 > 1.975d0) exit
  end do
  write(*,'(i0)') (u(i), i = 1, d)
contains
  integer function score() result(res)
    integer :: last(26), i
    last = 0
    res = 0
    do i = 1, d
      last(t(i)) = i
      res = res + s(t(i), i) - sum(c * (i - last))
    end do
  end
  subroutine random_seed_clock()
    integer :: nseed, clock
    integer, allocatable :: seed(:)
    call system_clock(clock)
    call random_seed(size = nseed)
    allocate(seed(nseed))
    seed = clock
    call random_seed(put = seed)
    deallocate(seed)
  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