Problem:
Score : 500 points

Problem Statement

We have a two-dimensional grid with H \times W squares. There are M targets to destroy in this grid - the position of the i-th target is \left(h_i, w_i \right).

Takahashi will choose one square in this grid, place a bomb there, and ignite it. The bomb will destroy all targets that are in the row or the column where the bomb is placed. It is possible to place the bomb at a square with a target.

Takahashi is trying to maximize the number of targets to destroy. Find the maximum number of targets that can be destroyed.

Constraints

All values in input are integers.

1 \leq H, W \leq 3 \times 10^5

1 \leq M \leq \min\left(H\times W, 3 \times 10^5\right)

1 \leq h_i \leq H

1 \leq w_i \leq W

\left(h_i, w_i\right) \neq \left(h_j, w_j\right) \left(i \neq j\right)

Input

Input is given from Standard Input in the following format:

H W M
h_1 w_1
\vdots
h_M w_M

Output

Print the answer.

Sample Input 1

2 3 3
2 2
1 1
1 3

Sample Output 1

3

We can destroy all the targets by placing the bomb at \left(1, 2\right).

Sample Input 2

3 3 4
3 3
3 1
1 1
1 2

Sample Output 2

3

Sample Input 3

5 5 10
2 5
4 3
2 3
5 5
2 2
5 4
5 3
5 1
3 5
1 4

Sample Output 3

6

Solution in Common Lisp (SBCL 2.0.3) (judge verdict: Time Limit Exceeded)

#-swank (declaim (optimize (speed 3) (safety 0) (debug 0)))
#+swank (declaim (optimize (speed 3) (safety 0) (debug 0)))

(defconstant +mod+ 1000000007)

(declaim (inline println))
(defun println (obj &optional (stream *standard-output*))
  (let ((*read-default-float-format* 'double-float))
    (prog1
        (write obj :stream stream)
      (fresh-line stream))) body...)


(defmethod fast-sort ((sequence list) &key (test #'<))
  (declare (inline sort)
           (inline sb-impl::stable-sort-list))
  (sort sequence (lambda (x y)
                   (funcall test x y))))


(defmethod fast-sort ((sequence array) &key (test #'<))
  (declare (inline sort))
  (sort sequence (lambda (x y)
                   (funcall test x y))))

(defmacro read-numbers-to-list (size)
  `(loop repeat ,size collect (read)))



(defmacro read-numbers-to-array (size)
  `(progn
     (when (not (integerp ,size))
       (error "Size must be integer."))
     (when (< ,size 0)
       (error "Size must be plus or zero."))
     (make-array ,size :initial-contents (read-numbers-to-list ,size))))

(defmacro read-numbers-to-board (row-size column-size)
  (let ((board (gensym))
        (r (gensym))
        (c (gensym)))
    `(let ((,board (make-array '(,row-size ,column-size))))
       (dotimes (,r ,row-size)
         (dotimes (,c ,column-size)
           (setf (aref ,board ,r ,c) (read))))
       ,board)))


(defun princ-for-each-line (list)
  (format t "~{~a~&~}" list))

(defun unwrap (list)
  (format nil "~{~a~^ ~}" list))



(defmacro with-buffered-stdout (&body body)
  (let ((out (gensym)))
    `(let ((,out (make-string-output-stream :element-type 'base-char)))
       (let ((*standard-output* ,out))
         ,@body)
       (write-string (get-output-stream-string ,out)))))




;;; Write code here


(defun main ()
  (let* ((h (read))
         (w (read))
         (m (read))
         (mines (loop repeat m collect (cons (1- (read))
                                             (1- (read))))))
    (declare (fixnum h w m)
             (list mines))
    (let ((h-count (make-array h :element-type 'fixnum :adjustable nil))
          (w-count (make-array w :element-type 'fixnum :adjustable nil))
          (memo (make-hash-table :size m  :test #'eq)))
      (declare ((array fixnum 1) h-count w-count)
               (hash-table memo))
      (labels ((encode (y x)
                 (dpb x (byte 20 20) y)))

        (loop for mine of-type list in mines do
             (setf (gethash (encode (first mine) (rest mine)) memo) t))
        (loop for mine of-type list in mines do
             (incf (aref h-count (first mine)))
             (incf (aref w-count (rest mine))))
        (let* ((h-max (reduce #'max h-count))
               (w-max (reduce #'max w-count))
               (h-max-list (remove-if-not
                            (lambda (y)
                              (= (aref h-count y)
                                 h-max))
                            (loop for i below h collect i)))
               (w-max-list (remove-if-not
                            (lambda (x)
                              (= (aref w-count x)
                                 w-max))
                            (loop for i below w collect i))))
          (declare (fixnum h-max w-max)
                   (list h-max-list w-max-list))
          (let ((ans (1- (+ h-max w-max)))
                (flag nil))
            (declare (fixnum ans))
            (mapc (lambda (h)
                    (mapc (lambda (w)
                            (when (not (gethash (encode h w)
                                                memo))
                              (setq flag t)))
                          w-max-list))
                  h-max-list)
            (when flag
              (incf ans))
            (format t "~a~&" ans)))))))
#-swank (main)