module Main where

import SegmentsTree

solve (h:w:n:list) =
  let st = makeST $ 0 : (take (min n h) $ repeat w) in
  println $ process st list

process st [] = []
process st (a:list) =
  let pos = leftmostAtLeast a st in
  if (pos == -1)
    then -1 : process st list
    else pos : process (add pos (-a) st) list

parse :: [Char] -> [Int]
parse s = map read $ words s

println = concatMap (\a -> show a ++ ['\n'])

main = do
  s <- getContents--readFile "billboard.in"
  print $ solve $ parse s
