import Data.Function (on)
import Data.List (maximumBy)
import Data.Map (alter, assocs, empty, mapAccum, (!))
mapSnd f (a, b) = (a, f b)
input = [(1920, 1950), (1920, 1980), (1940, 1990), (1930, 1940), (1970, 2010), (1920, 1960), (1720, 1860), (1730, 1810)]
result = fst $ maximumBy (compare `on` snd) $ scanl1 (mapSnd . (+) . snd) . assocs $ (flip $ foldr $ alter $ Just . maybe 1 (+1)) (map fst input) $ (flip $ foldr $ alter $ Just . maybe (-1) (`subtract` 1)) (map snd input) $ empty