;; -*- coding: utf-8 -*-
(eval-when (:compile-toplevel :load-toplevel :execute)
  (defparameter OPT
    #+swank '(optimize (speed 3) (safety 2))
    #-swank '(optimize (speed 3) (safety 0) (debug 0)))
  #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))
                 (shadow :run)
                 (use-package :fiveam))
  #-swank (set-dispatch-macro-character #\# #\> (lambda (s c p) (declare (ignore c p)) (read s nil (values) t))))
#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)

;; BEGIN_INSERTED_CONTENTS
(declaim (inline get-2dcumul))
(defun get-2dcumul (cumul-table i0 j0 i1 j1)
  "Returns the cumulative sum of the region given by the rectangle [i0, i1)*[j0,
j1). CUMUL-TABLE must be appropriately initialized beforehand."
  (+ (- (aref cumul-table i1 j1)
        (aref cumul-table i0 j1)
        (aref cumul-table i1 j0))
     (aref cumul-table i0 j0)))

(defmacro dbg (&rest forms)
  #+swank
  (if (= (length forms) 1)
      `(format *error-output* "~A => ~A~%" ',(car forms) ,(car forms))
      `(format *error-output* "~A => ~A~%" ',forms `(,,@forms)))
  #-swank (declare (ignore forms)))

(defmacro define-int-types (&rest bits)
  `(progn
     ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "UINT~A" b)) () '(unsigned-byte ,b))) bits)
     ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "INT~A" b)) () '(signed-byte ,b))) bits)))
(define-int-types 2 4 7 8 15 16 31 32 62 63 64)

(declaim (inline println))
(defun println (obj &optional (stream *standard-output*))
  (let ((*read-default-float-format* 'double-float))
    (prog1 (princ obj stream) (terpri stream))))

(defconstant +mod+ 1000000007)

;; Body

(defun main ()
  (let* ((n (read))
         (k (read))
         (xs (make-array n :element-type 'int32))
         (ys (make-array n :element-type 'int32))
         (ord-xs (make-array n :element-type 'uint8))
         (ord-ys (make-array n :element-type 'uint8))
         (cumul (make-array (list (+ n 1) (+ n 1)) :element-type 'uint8 :initial-element 0))
         (res most-positive-fixnum))
    (declare (uint8 n k) (uint62 res))
    (dotimes (i n)
      (setf (aref xs i) (read))
      (setf (aref ys i) (read))
      (setf (aref ord-xs i) i)
      (setf (aref ord-ys i) i))
    (setf ord-xs (sort ord-xs (lambda (i j) (< (aref xs i) (aref xs j)))))
    (setf ord-ys (sort ord-ys (lambda (i j) (< (aref ys i) (aref ys j)))))
    (dotimes (i n)
      (let ((ord-x (the uint8 (position i ord-xs)))
            (ord-y (position i ord-ys)))
        (incf (aref cumul (+ ord-y 1) (+ ord-x 1)))))
    (dotimes (y (+ n 1))
      (dotimes (x n)
        (incf (aref cumul y (+ x 1)) (aref cumul y x))))
    (dotimes (x (+ n 1))
      (dotimes (y n)
        (incf (aref cumul (+ y 1) x)  (aref cumul y x))))
    (dotimes (y1-ord n)
      (dotimes (x1-ord n)
        (loop for y2-ord from (+ 1 y1-ord) below n
              do (loop for x2-ord from (+ 1 x1-ord) below n
                       when (<= k (get-2dcumul cumul y1-ord x1-ord (+ 1 y2-ord) (+ 1 x2-ord)))
                       do (let ((y1 (aref ys (aref ord-ys y1-ord)))
                                (x1 (aref xs (aref ord-xs x1-ord)))
                                (y2 (aref ys (aref ord-ys y2-ord)))
                                (x2 (aref xs (aref ord-xs x2-ord))))
                            (setf res (min res (the fixnum (* (- y2 y1) (- x2 x1))))))))))
    (println res)))

#-swank(main)


;; For Test
#+swank
(defun io-equal (in-string out-string &optional (func #'main))
  "Passes IN-STRING to *STANDARD-INPUT*, executes FUNC, and checks the string
output to *STANDARD-OUTPUT* is equal to OUT-STRING."
  (labels ((ensure-last-lf (s)
             (if (and (> (length s) 0)
                      (eql (char s (- (length s) 1)) #\Linefeed))
                 s
                 (uiop:strcat s uiop:+lf+))))
    (equal (ensure-last-lf out-string)
           (with-output-to-string (out)
             (let ((*standard-output* out))
               (with-input-from-string (*standard-input* (ensure-last-lf in-string))
                 (funcall func)))))))

#+swank
(defun get-clipbrd ()
  (with-output-to-string (out)
    (run-program "C:/msys64/usr/bin/cat.exe" '("/dev/clipboard") :output out)))

#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))
#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* "test.dat" *this-pathname*))

#+swank
(defun run (&optional thing (out *standard-output*))
  (let ((*standard-output* out))
    (etypecase thing
      (null ; Runs #'MAIN with the string on clipboard
       (with-input-from-string (*standard-input* (delete #\Return (get-clipbrd)))
         (main)))
      (string
       (with-input-from-string (*standard-input* (delete #\Return thing))
         (main)))
      (symbol (5am:run! thing))
      (pathname ; Runs #'MAIN with the string in a text file
       (with-open-file (*standard-input* thing)
         (main))))))

#+swank
(defun gen-dat ()
  (uiop:with-output-file (out *dat-pathname* :if-exists :supersede)
    (format out "")))

#+swank
(defun bench (&optional (out (make-broadcast-stream)))
  (time (run *dat-pathname* out)))

;; To run: (5am:run! :sample)
#+swank
(it.bese.fiveam:test :sample
  (it.bese.fiveam:is
   (common-lisp-user::io-equal "4 4
1 4
3 3
6 2
8 1
"
    "21
"))
  (it.bese.fiveam:is
   (common-lisp-user::io-equal "4 2
0 0
1 1
2 2
3 3
"
    "1
"))
  (it.bese.fiveam:is
   (common-lisp-user::io-equal "4 3
-1000000000 -1000000000
1000000000 1000000000
-999999999 999999999
999999999 -999999999
"
    "3999999996000000001
")))


Measured memory_bytes: 21480