import qualified Data.Map.Strict as M query (v,m) x = (w, o) where (lt,ge) = M.spanAntitone (< x) m n = M.mapKeysWith (+) (`mod` x) ge w = v - count ge + count n o = M.unionWith (+) n lt count m = sum [k*v | (k,v) <- M.toList m] main = do getLine a <- map read . words <$> getLine getLine xs <- map read . words <$> getLine let m = M.fromListWith (+) $ zip a [1,1..] mapM_ print $ map fst $ tail $ scanl query (sum a, m) xs