{-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE BangPatterns #-} import Control.Applicative import Control.Monad import Control.Arrow import Data.List import Data.Maybe import Data.Char import qualified Data.ByteString.Char8 as B import Text.Printf readInt = ( readLn :: IO Int ) readInts = map ( read :: String -> Int ) . words <$> getLine getList = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine which a b f = if f then a else b mp [ a, b ] = ( a, b ) main = do n <- readInt asbs <- map mp <$> replicateM n readInts m <- readInt xsys <- map mp <$> replicateM m readInts let nums = map ( bought_by asbs ) xsys ma = maximum nums if ma == 0 then print 0 else mapM_ print $ map fst $ filter ( ( == ma ) . snd ) $ zip [ 1 .. ] nums bought_by asbs xy = length $ filter id $ map ( buy xy ) asbs buy ( x, y ) ( a, b ) = x <= a && b <= y