import Data.Bool

main :: IO ()
main = interact solve

solve :: String -> String
solve = putResult . good . read

putResult :: Bool -> String
putResult = bool "No" "Yes"

good :: Int -> Bool
good x
  | x < 1000         = False
  | x > 9999         = False
  | y `mod` 111 == 0 = True
  | z `mod` 111 == 0 = True
  | otherwise        = False
  where
    y = x `mod` 1000
    z = x `div` 10
