|
| 1 | +-- https://github.com/minoki/my-atcoder-solutions |
| 2 | +{-# LANGUAGE TypeApplications #-} |
| 3 | +import Data.List |
| 4 | +import qualified Data.ByteString.Char8 as BS |
| 5 | + |
| 6 | +shortCase :: String -> Bool |
| 7 | +shortCase xs = or $ do |
| 8 | + ys <- permutations xs |
| 9 | + return (read @Int ys `rem` 8 == 0) |
| 10 | + |
| 11 | +multiplesOf8 :: [[(Char, Int)]] |
| 12 | +multiplesOf8 = [ if c0 == c2 then |
| 13 | + [(c0,3)] |
| 14 | + else if c0 == c1 then |
| 15 | + [(c0,2),(c2,1)] |
| 16 | + else if c1 == c2 then |
| 17 | + [(c0,1),(c1,2)] |
| 18 | + else |
| 19 | + [(c0,1),(c1,1),(c2,1)] |
| 20 | + | n <- [13 .. 124] |
| 21 | + , let [c0,c1,c2] = sort $ show (8 * n) |
| 22 | + ] |
| 23 | + |
| 24 | +longCase :: BS.ByteString -> Bool |
| 25 | +longCase s = or $ do |
| 26 | + m <- multiplesOf8 |
| 27 | + return $ all (\(c,n) -> BS.count c s >= n) m |
| 28 | + |
| 29 | +main = do |
| 30 | + s <- BS.getLine |
| 31 | + let result = if BS.length s <= 2 then |
| 32 | + shortCase (BS.unpack s) |
| 33 | + else |
| 34 | + longCase s |
| 35 | + putStrLn $ if result then "Yes" else "No" |
0 commit comments