module Main(main) where

import Data.Char
import Control.Monad
import Data.List

main = do { str <- getLine
; let xss = fun38 . map digitToInt $ str
; display xss
; putStr "last = "
; putChar . intToDigit . head . last $ xss
}

fun38 [] = []
fun38 xs = xs : fun38 (zipWith (\a b -> (a + b) `mod` 10) xs (tail xs))

display = zipWithM ((putStrLn .) . (. (intersperse ' ' . map intToDigit)) . (++) . flip replicate ' ') [0..]