import Control.Applicative import Control.Monad import qualified Data.ByteString.Char8 as B import Data.Maybe (fromJust) import Text.Printf import Debug.Trace -- or readInteger readInts :: B.ByteString -> [Int] readInts = map (fst . fromJust . B.readInt) . B.words getInts :: IO [Int] getInts = liftM readInts B.getLine idx p h w = (p `mod` w, p `div` w) ps s h w = head $ filter ok [(x+dx,y+dy) | (dx,dy) <- [(-1,0),(1,0),(0,-1),(0,1)], x <- [x1,x2], y <- [y1,y2]] where [(x1,y1),(x2,y2)] = [idx p h (w+1) | p <- '*' `B.elemIndices` s] ok (x,y) = 0 <= x && x < w && 0 <= y && y < h && (x /= x1 || x /= x2) && (y /= y1 || y /= y2) main = do [h,w] <- getInts s <- B.getContents let (x,y) = ps s h w let (fr, bk) = B.splitAt (y*(w+1)+x) s print $ (x,y) B.putStr fr putStr "*" B.putStr $ B.tail bk