data TransHistory l = TransEmpty
                  | Trans [(l,l)]
                  deriving (Show)

isValid :: (Eq a) => a -> a -> TransHistory a -> Bool
isValid l m TransEmpty = True
isValid l m (Trans x) = foldl (\acc x -> if ((fst x) == l) && ((snd x) /= m) then False else acc) True x

addHis :: (Eq l) => l -> l -> TransHistory l -> TransHistory l
addHis l m TransEmpty = Trans [(l,m)]
addHis l m (Trans l') = Trans (l' ++ [(l,m)])

main :: IO ()
main = do
  x <- getLine
  y <- getLine
  let a = zipWith (\x y -> (x,y)) x y
  putStrLn $ case (
      foldl (\acc a -> case acc of 
        Just x -> if isValid (fst a) (snd a) x then Just $ (addHis (fst a) (snd a) x ) else Nothing 
        Nothing -> Nothing
      )(Just TransEmpty) a
    ) of
      Just x -> 
        case (
          foldl (\acc a -> case acc of 
            Just x -> if isValid (snd a) (fst a) x then Just $ (addHis (snd a) (fst a) x ) else Nothing 
            Nothing -> Nothing
          )(Just TransEmpty) a
        ) of
          Just y -> "Yes"
          Nothing -> "No"
      Nothing -> "No"