import Control.Monad (replicateM,when)
import Data.List (sort,sortBy,group)
import Data.Ord (comparing)

type Rect = (Int,Int,Int,Int) -- (x0,y0,x1,y1)
type X = Int
type Y = Int

main = do
    [n,r] <- getLine >>= (return . map read . words)
    if all (==0) [n,r] then return () else do
        rs <- replicateM n (getLine >>= return . rect . map read . words)
        print $ area rs
        when (r == 2) (print $ perimeter rs)
        main

    where
    rect [x0,y0,x1,y1] = (x0,y0,x1,y1)

area :: [Rect] -> Int
area rs = area' $ rectYs rs
    where
    area' (_:[])     = 0
    area' (y0:y1:ys) = rsx0 `seq`
                       (y1-y0) * (sumSpans $ mergeSpans $ xspans rsx0 y0)
                       + area' (y1:ys)

    rsx0 = sortBy (comparing (\(x0,_,_,_)->x0)) rs

perimeter :: [Rect] -> Int
perimeter rs = (perimeterX $ rectXs rs) + (perimeterY $ rectYs rs)
    where
    perimeterX (_:[])     = 0
    perimeterX (x0:x1:xs) = rsy0 `seq`
                            (x1-x0) * 2 * (length $ mergeSpans $ yspans rsy0 x0)
                            + perimeterX (x1:xs)

    perimeterY (_:[])     = 0
    perimeterY (y0:y1:ys) = rsx0 `seq`
                            (y1-y0) * 2 * (length $ mergeSpans $ xspans rsx0 y0)
                            + perimeterY (y1:ys)

    rsx0 = sortBy (comparing (\(x0,_,_,_)->x0)) rs
    rsy0 = sortBy (comparing (\(_,y0,_,_)->y0)) rs

rectXs :: [Rect] -> [X]
rectXs rs = map head $ group $ sort $ concatMap rectX rs
    where
    rectX (x0,_,x1,_) = [x0,x1]

rectYs :: [Rect] -> [Y]
rectYs rs = map head $ group $ sort $ concatMap rectY rs
    where
    rectY (_,y0,_,y1) = [y0,y1]
    
xspans :: [Rect] -> Y -> [(X,X)]
xspans rs y = map xspan $ filter cross $ rs
    where
    xspan (x0,_,x1,_) = (x0,x1)
    cross (_,y0,_,y1) = y >= y0 && y < y1
    rectX0 (x0,_,_,_) = x0

yspans :: [Rect] -> X -> [(Y,Y)]
yspans rs x = map yspan $ filter cross $ rs
    where
    yspan (_,y0,_,y1) = (y0,y1)
    cross (x0,_,x1,_) = x >= x0 && x < x1

sumSpans :: [(Int,Int)] -> Int
sumSpans [] = 0
sumSpans ((a,b):ss) = b - a + sumSpans ss

mergeSpans :: [(Int,Int)] -> [(Int,Int)]
mergeSpans [] = []
mergeSpans (s:[]) = [s]
mergeSpans ((a,b):(c,d):ss)
    | b >= c    = mergeSpans ((a,max b d):ss)
    | otherwise = (a,b) : mergeSpans ((c,d):ss)