import Control.Arrow ((&&&)) import qualified Data.Char as Char import qualified Data.List as List import qualified Data.ByteString.Char8 as BSC8 import qualified Data.Bool as Bool import qualified Data.Ord as Ord getInt :: IO [Int] getInt = List.unfoldr f <$> BSC8.getLine where -- f :: BSC8.ByteString -> Maybe (Int, BSC8.ByteString) f s = do (n, s') <- BSC8.readInt s return (n, BSC8.dropWhile Char.isSpace s') main :: IO () main = do n <- readLn :: IO Int xs <- getInt ys <- getInt putStrLn $ Bool.bool "NO" "YES" $ solver n (zip xs ys) solver n zs = let xs = map (f &&& g) $ List.groupBy (\a b -> snd a == snd b) $ List.sortBy (Ord.comparing snd) zs isK = 0 == (snd . head $ xs) kScore = fst . head $ xs others = fst $ List.maximumBy (Ord.comparing snd) (tail xs) in isK && (kScore >= others) f [] = 0 f ((a, b):[]) = a f ((a, b):xs) = a + f xs g [] = 0 g ((a, b):xs) = b