import Data.Char (digitToInt) import Data.ByteString.Char8 (ByteString) import qualified Data.ByteString.Char8 as B main :: IO () main = interact $ show . solve . words solve :: [String] -> Int solve [s, t] | n == 0 = 0 | t == "0" = 1 | n == 1 = 1 | n == 2 = if i `mod` 4 == 1 then 2 else if i `mod` 4 == 2 then 4 else if i `mod` 4 == 3 then 8 else 6 | n == 3 = if i `mod` 4 == 1 then 3 else if i `mod` 4 == 2 then 9 else if i `mod` 4 == 3 then 7 else 1 | n == 4 = if m `mod` 2 == 0 then 6 else 4 | n == 5 = 5 | n == 6 = 6 | n == 7 = if i `mod` 4 == 1 then 7 else if i `mod` 4 == 2 then 9 else if i `mod` 4 == 3 then 3 else 1 | n == 8 = if i `mod` 4 == 1 then 8 else if i `mod` 4 == 2 then 4 else if i `mod` 4 == 3 then 2 else 6 | n == 9 = if m `mod` 2 == 0 then 1 else 9 | otherwise = error "" where n = digitToInt $ last s m = digitToInt $ last t i = (read :: String -> Int) ([last $ init t] ++ [last t])