{-# LANGUAGE LambdaCase #-}

module Adder where

import           Control.Monad.Trans.State
import Control.Monad
import Data.List
import Control.Arrow

type Scanner = State [String]

runScanner :: Scanner a -> String -> a
runScanner = runScannerWith $ concat . map words . lines

runScannerWith :: (String -> [String]) -> Scanner a -> String -> a
runScannerWith t s = evalState s . t

str :: Scanner String
str = get >>= \case { s:ss -> put ss >> return s }

int :: Scanner Int
int = read <$> str

numberOf :: Scanner a -> Scanner [a]
numberOf s = int >>= flip replicateM s

main = interact $
    runScanner (numberOf int) >>> flip zip [1..] >>> sort >>> map snd >>> show