Problem:
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});

The Maximum Number of Overlaps

Given a set of $N$ axis-aligned rectangular seals, find the number of overlapped seals on the region which has the maximum number of overlapped seals.

Input

The input is given in the following format.

$N$

$x1_1$ $y1_1$ $x2_1$ $y2_1$

$x1_2$ $y1_2$ $x2_2$ $y2_2$

:

$x1_N$ $y1_N$ $x2_N$ $y2_N$

($x1_i, y1_i$) and ($x2_i, y2_i$) are the coordinates of the top-left and the bottom-right corner of the $i$-th seal respectively.

Constraints

$ 1 \leq N \leq 100000 $

$ 0 \leq x1_i < x2_i \leq 1000 $

$ 0 \leq y1_i < y2_i \leq 1000 $

$ x1_i, y1_i, x2_i, y2_i$ are given in integers

Output

Print the maximum number of overlapped seals in a line.

Sample Input 1

2
0 0 3 2
2 1 4 3

Sample Output 1

2

Sample Input 2

2
0 0 2 2
2 0 4 2

Sample Output 2

1

Sample Input 3

3
0 0 2 2
0 0 2 2
0 0 2 2

Sample Output 3

3

Solution in C# (judge verdict: Runtime Error)

using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Globalization;
using System.Diagnostics;
using Pair = System.Collections.Generic.KeyValuePair<int, int>;

class Program
{
    static void Main()
    {
        Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
        new Program().Solve();
        Console.Out.Flush();
    }
    Scanner cin = new Scanner();


    void Solve()
    {
        int H = 1001, W = 1001;
        var T = new Two_D(H, W);
        int N = cin.Nextint;
        for (int i = 0; i < N; i++)
        {
            var c = cin.Scanint;
            T.imos(c[0], c[1], c[2], c[3]);
        }
        T.build();
        long ans = 0;
        for (int i = 0; i < H; i++)
        {
            for (int j = 0; j < W; j++)
            {
                ans = Math.Max(ans, T.D[i, j]);
            }
        }
        Console.WriteLine(ans);
    }

}

class Two_D
{
    public long[,] D;
    public int H;
    public int W;
    public Two_D(int H, int W)
    {
        this.H = H;
        this.W = W;
        D = new long[H, W];
    }
    public void build()
    {
        for (int i = 0; i < H; i++)
        {
            for (int j = 1; j < W; j++)
            {
                D[i, j] += D[i, j - 1];
            }
        }
        for (int i = 1; i < H; i++)
        {
            for (int j = 0; j < W; j++)
            {
                D[i, j] += D[i - 1, j];
            }
        }
    }
    public void imos(int min_y, int min_x, int max_y, int max_x)
    {
        D[min_y, min_x]++;
        D[min_y, max_x + 1]--;
        D[max_y, min_x]--;
        D[max_y + 1, max_x + 1]++;
    }
    //sum [(min_y, min_x), (max_y, max_x)]
    public long query(int min_y, int min_x, int max_y, int max_x)
    {
        long ret = D[max_y, max_x];
        if (min_y > 0) ret -= D[min_y - 1, max_x];
        if (min_x > 0) ret -= D[max_y, min_x - 1];
        if (min_y > 0 && min_x > 0) ret += D[min_y - 1, min_x - 1];

        return ret;
    }
}
class Scanner
{
    string[] s; int i;
    char[] cs = new char[] { ' ' };
    public Scanner() { s = new string[0]; i = 0; }
    public string[] Scan { get { return Console.ReadLine().Split(); } }
    public int[] Scanint { get { return Array.ConvertAll(Scan, int.Parse); } }
    public long[] Scanlong { get { return Array.ConvertAll(Scan, long.Parse); } }
    public double[] Scandouble { get { return Array.ConvertAll(Scan, double.Parse); } }
    public string Next
    {
        get
        {
            if (i < s.Length) return s[i++];
            string st = Console.ReadLine();
            while (st == "") st = Console.ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return Next;
        }
    }
    public int Nextint { get { return int.Parse(Next); } }
    public long Nextlong { get { return long.Parse(Next); } }
    public double Nextdouble { get { return double.Parse(Next); } }
}