Problem:
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

Submitted solutions:

code_snippet: // --- Start of include: ./../../akakoi_lib/template/template.cpp ---
// #pragma GCC target("avx2")
// #pragma GCC optimize("O3,unroll-loops")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0;i<(ll)(n);++i)
bool chmax(int& a, int b) {return a<b?a=b,1:0;}
// int main() {
//     ios::sync_with_stdio(false);
//     cin.tie(0);
// }
// --- End of include: ./../../akakoi_lib/template/template.cpp ---
// --- Start of include: ./../../akakoi_lib/gomi/seg2D_light.cpp ---
template <class T, T (*op)(T, T), T (*e)()>
struct Seg2DLight {
private:
  int h, w, hs, ws;
  vector<vector<T>> data;
  inline int bit_length(int x) {
    return x ? 32 - __builtin_clz(x) : 0;
  }
public:
  Seg2DLight(int h, int w) : h(h), w(w) {
    hs = 1<<bit_length(h);
    ws = 1<<bit_length(w);
    data.resize(hs*2, vector<T>(ws*2, e()));
  }
  void build(vector<vector<T>> a) {
    rep(i, h) rep(j, w) { data[i+hs][j+ws] = a[i][j]; }
    for (int i = hs; i < hs+h; ++i) {
      for (int j = ws-1; j > 0; --j) {
        data[i][j] = op(data[i][j<<1], data[i][j<<1|1]);
      }
    }
    for (int i = hs-1; i > 0; --i) {
      for (int j = 1; j < ws*2; ++j) {
        data[i][j] = op(data[i<<1][j], data[i<<1|1][j]);
      }
    }
  }
  T get(int y, int x) { return data[y+hs][x+ws]; }
  void set(int y, int x, T v) {
    assert(0 <= y && y < h); assert(0 <= x && x < w);
    y += hs; x += ws;
    data[y][x] = v;
    for (int nx = x; nx > 1; nx >>= 1) {
      data[y][nx>>1] = op(data[y][nx], data[y][nx^1]);
    }
    for (int ny = y; ny > 1; ny >>= 1) {
      int nx = x;
      data[ny>>1][nx] = op(data[ny][nx], data[ny^1][nx]);
      for (nx >>= 1; nx >= 1; nx >>= 1) {
        data[ny>>1][nx] = op(data[ny>>1][nx<<1], data[ny>>1][nx<<1|1]);
      }
    }
  }
  T prod(int u, int d, int l, int r) {
    assert(0 <= u && u <= d && d <= h);
    assert(0 <= l && l <= r && r <= w);
    u += hs; d += hs;
    l += ws; r += ws;
    T ans = e();
    auto pw = [&] (vector<T> &dat) -> void {
      int nl = l, nr = r;
      while (nl < nr) {
        if (nl & 1) ans = op(ans, dat[nl++]);
        if (nr & 1) ans = op(ans, dat[--nr]);
        nl >>= 1; nr >>= 1;
      }
    };
    while (u < d) {
      if (u & 1) pw(data[u++]);
      if (d & 1) pw(data[--d]);
      u >>= 1; d >>= 1;
    }
    return ans;
  }
};
// --- End of include: ./../../akakoi_lib/gomi/seg2D_light.cpp ---

int op(int s, int t) { return s + t; }
int e() { return 0; }

void solve() {
    int n; cin >> n;
    int M = 1001;
    Seg2DLight<int, op, e> seg(M, M);
    vector<vector<int>> A(M, vector<int>(M, 1));
    seg.build(A);
    rep(i, M) rep(j, M) {
        seg.set(i, j, 0);
    }

    rep(i, n) {
        int a, b, c, d; cin >> a >> b >> c >> d;
        seg.set(a, b, seg.get(a, b) + 1);
        seg.set(a, d, seg.get(a, d) - 1);
        seg.set(c, b, seg.get(c, b) - 1);
        seg.set(c, d, seg.get(c, d) + 1);
    }
    int ans = 0;
    rep(i, M) rep(j, M) {
        chmax(ans, seg.prod(0, i+1, 0, j+1));
    }
    cout << ans << endl;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    solve();
}
accuracy: 1
time_ms: 280
memory_kb: 27364
final_rank: 19

code_snippet: // --- Start of include: ./../../akakoi_lib/template/template.cpp ---
// #pragma GCC target("avx2")
// #pragma GCC optimize("O3,unroll-loops")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0;i<(ll)(n);++i)
bool chmin(int& a, int b) {return a>b?a=b,1:0;}
bool chmax(int& a, int b) {return a<b?a=b,1:0;}
// int main() {
//     ios::sync_with_stdio(false);
//     cin.tie(0);
// }
// --- End of include: ./../../akakoi_lib/template/template.cpp ---
// --- Start of include: ./../../akakoi_lib/gomi/seg2D_light.cpp ---
template <class T, T (*op)(T, T), T (*e)()>
struct Seg2DLight {
private:
  int h, w, hs, ws;
  vector<vector<T>> data;
  inline int bit_length(int x) {
    return x ? 32 - __builtin_clz(x) : 0;
  }
public:
  Seg2DLight(int h, int w) : h(h), w(w) {
    hs = 1<<bit_length(h);
    ws = 1<<bit_length(w);
    data.resize(hs*2, vector<T>(ws*2, e()));
  }
  void build(vector<vector<T>> a) {
    rep(i, h) rep(j, w) { data[i+hs][j+ws] = a[i][j]; }
    for (int i = hs; i < hs+h; ++i) {
      for (int j = ws-1; j > 0; --j) {
        data[i][j] = op(data[i][j<<1], data[i][j<<1|1]);
      }
    }
    for (int i = hs-1; i > 0; --i) {
      for (int j = 1; j < ws*2; ++j) {
        data[i][j] = op(data[i<<1][j], data[i<<1|1][j]);
      }
    }
  }
  T get(int y, int x) { return data[y+hs][x+ws]; }
  void set(int y, int x, T v) {
    assert(0 <= y && y < h); assert(0 <= x && x < w);
    y += hs; x += ws;
    data[y][x] = v;
    for (int nx = x; nx > 1; nx >>= 1) {
      data[y][nx>>1] = op(data[y][nx], data[y][nx^1]);
    }
    for (int ny = y; ny > 1; ny >>= 1) {
      int nx = x;
      data[ny>>1][nx] = op(data[ny][nx], data[ny^1][nx]);
      for (nx >>= 1; nx >= 1; nx >>= 1) {
        data[ny>>1][nx] = op(data[ny>>1][nx<<1], data[ny>>1][nx<<1|1]);
      }
    }
  }
  T prod(int u, int d, int l, int r) {
    assert(0 <= u && u <= d && d <= h);
    assert(0 <= l && l <= r && r <= w);
    u += hs; d += hs;
    l += ws; r += ws;
    T ans = e();
    auto pw = [&] (vector<T> &dat) -> void {
      int nl = l, nr = r;
      while (nl < nr) {
        if (nl & 1) ans = op(ans, dat[nl++]);
        if (nr & 1) ans = op(ans, dat[--nr]);
        nl >>= 1; nr >>= 1;
      }
    };
    while (u < d) {
      if (u & 1) pw(data[u++]);
      if (d & 1) pw(data[--d]);
      u >>= 1; d >>= 1;
    }
    return ans;
  }
};
// --- End of include: ./../../akakoi_lib/gomi/seg2D_light.cpp ---

int op(int s, int t) { return s + t; }
int e() { return 0; }

void solve() {
    int n; cin >> n;
    int M = 1000;
    Seg2DLight<int, op, e> seg(M, M);
    vector<vector<int>> A(M, vector<int>(M, 1));
    seg.build(A);
    rep(i, M) rep(j, M) {
        seg.set(i, j, 0);
    }

    rep(i, n) {
        int a, b, c, d; cin >> a >> b >> c >> d;
        seg.set(a, b, seg.get(a, b) + 1);
        seg.set(a, d, seg.get(a, d) - 1);
        seg.set(c, b, seg.get(c, b) - 1);
        seg.set(c, d, seg.get(c, d) + 1);
    }
    int ans = 0;
    rep(i, M) rep(j, M) {
        chmax(ans, seg.prod(0, i+1, 0, j+1));
    }
    cout << ans << endl;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    solve();
}
accuracy: 0.23333333333333334
time_ms: 220
memory_kb: 27360
final_rank: 20

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pll = pair<ll, ll>;
using vl = vector<ll>;
template <class T> using vec = vector<T>;
template <class T> using vv = vec<vec<T>>;
template <class T> using vvv = vec<vv<T>>;
template <class T> using minpq = priority_queue<T, vec<T>, greater<T>>;
#define rep(i, r) for (ll i = 0; i < (r); i++)
#define reps(i, l, r) for (ll i = (l); i < (r); i++)
#define rrep(i, l, r) for (ll i = (r) - 1; i >= l; i--)
#define all(a) (a).begin(), (a).end()
#define sz(a) (ll)(a).size()
template <typename T>
bool chmax(T& a, const T& b) {
    return a < b ? a = b, true : false;
}
template <typename T>
bool chmin(T& a, const T& b) {
    return a > b ? a = b, true : false;
}
template <typename T>
struct BIT2d {
    ll h, w;
    vv<T> bit;
    BIT2d(ll H, ll W) : h(H + 1), w(W + 1) {
        bit.resize(h + 3, vec<T>(w + 3, T(0)));
    }
    void add(ll x, ll y, T c) {
        if (x < 0 || x >= h || y < 0 || y >= w) return;
        for (ll a = (++y, ++x); a <= h; a += a & -a) {
            for (ll b = y; b <= w; b += b & -b) {
                bit[a][b] += c;
            }
        }
    }
    void imos(ll x1, ll y1, ll x2, ll y2, T c) {
        add(x1, y1, c);
        add(x1, y2, -c);
        add(x2, y1, -c);
        add(x2, y2, c);
    }
    T sum(ll x, ll y) {
        if (x <= 0 || y <= 0) return T(0);
        if (x > h) x = h;
        if (y > w) y = w;
        T ret = 0;
        for (ll a = (y, x); a > 0; a -= a & -a) {
            for (ll b = y; b > 0; b -= b & -b) {
                ret += bit[a][b];
            }
        }
		return ret;
    }
    T sum(ll x1, ll y1, ll x2, ll y2) {
        if (x1 > x2 || y1 > y2) return T(0);
        return sum(x2, y2) - sum(x2, y1) - sum(x1, y2) + sum(x1, y1);
    }
};
void solve() {
    ll n; cin >> n;
	BIT2d<ll> bit(1010, 1010);
	rep(i, n) {
		ll x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2;
		// cout << x1 << ' ' << y1 << ' ' << x2 << ' ' << y2 << endl;
		bit.imos(x1, y1, x2, y2, 1);
	}
	ll ans = 0;
	rep(i, 1011) rep(j, 1011) {
		// cout << bit.sum(i, j) << " \n"[j == 99];
		chmax(ans, bit.sum(i, j));
	}
	cout << ans << endl;
}
int main() {
    ll T = 1;
    // cin >> T;
    while (T--) solve();
}
accuracy: 1
time_ms: 50
memory_kb: 11392
final_rank: 10

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pll = pair<ll, ll>;
using vl = vector<ll>;
template <class T> using vec = vector<T>;
template <class T> using vv = vec<vec<T>>;
template <class T> using vvv = vec<vv<T>>;
template <class T> using minpq = priority_queue<T, vec<T>, greater<T>>;
#define rep(i, r) for (ll i = 0; i < (r); i++)
#define reps(i, l, r) for (ll i = (l); i < (r); i++)
#define rrep(i, l, r) for (ll i = (r) - 1; i >= l; i--)
#define all(a) (a).begin(), (a).end()
#define sz(a) (ll)(a).size()
template <typename T>
bool chmax(T& a, const T& b) {
    return a < b ? a = b, true : false;
}
template <typename T>
bool chmin(T& a, const T& b) {
    return a > b ? a = b, true : false;
}
template <typename T>
struct BIT2d {
    ll h, w;
    vv<T> bit;
    BIT2d(ll H, ll W) : h(H + 1), w(W + 1) {
        bit.resize(h + 3, vec<T>(w + 3, T(0)));
    }
    void add(ll x, ll y, T c) {
        if (x < 0 || x >= h || y < 0 || y >= w) return;
        for (ll a = (++y, ++x); a <= h; a += a & -a) {
            for (ll b = y; b <= w; b += b & -b) {
                bit[a][b] += c;
            }
        }
    }
    void imos(ll x1, ll y1, ll x2, ll y2, T c) {
        add(x1, y1, c);
        add(x1, y2, -c);
        add(x2, y1, -c);
        add(x2, y2, c);
    }
    T sum(ll x, ll y) {
        if (x < 0 || y < 0) return T(0);
        if (x > h) x = h;
        if (y > w) y = w;
        T ret = 0;
        for (ll a = (y, x); a > 0; a -= a & -a) {
            for (ll b = y; b > 0; b -= b & -b) {
                ret += bit[a][b];
            }
        }
		return ret;
    }
    T sum(ll x1, ll y1, ll x2, ll y2) {
        if (x1 > x2 || y1 > y2) return T(0);
        return sum(x2, y2) - sum(x2, y1 - 1) - sum(x1 - 1, y2) + sum(x1 - 1, y1 - 1);
    }
};
void solve() {
    ll n; cin >> n;
	BIT2d<ll> bit(1010, 1010);
	rep(i, n) {
		ll x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2;
		// cout << x1 << ' ' << y1 << ' ' << x2 << ' ' << y2 << endl;
		bit.imos(x1, y1, x2, y2, 1);
	}
	ll ans = 0;
	rep(i, 1010) rep(j, 1010) {
		// cout << bit.sum(i, j) << " \n"[j == 99];
		chmax(ans, bit.sum(i, j));
	}
	cout << ans << endl;
}
int main() {
    ll T = 1;
    // cin >> T;
    while (T--) solve();
}
accuracy: 1
time_ms: 50
memory_kb: 11392
final_rank: 10

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pll = pair<ll, ll>;
using vl = vector<ll>;
template <class T> using vec = vector<T>;
template <class T> using vv = vec<vec<T>>;
template <class T> using vvv = vec<vv<T>>;
template <class T> using minpq = priority_queue<T, vec<T>, greater<T>>;
#define rep(i, r) for (ll i = 0; i < (r); i++)
#define reps(i, l, r) for (ll i = (l); i < (r); i++)
#define rrep(i, l, r) for (ll i = (r) - 1; i >= l; i--)
#define all(a) (a).begin(), (a).end()
#define sz(a) (ll)(a).size()
template <typename T>
bool chmax(T& a, const T& b) {
    return a < b ? a = b, true : false;
}
template <typename T>
bool chmin(T& a, const T& b) {
    return a > b ? a = b, true : false;
}
template <typename T>
struct BIT2d {
    ll h, w;
    vv<T> bit;
    BIT2d(ll H, ll W) : h(H + 1), w(W + 1) {
        bit.resize(h + 3, vec<T>(w + 3, T(0)));
    }
    void add(ll x, ll y, T c) {
        if (x < 0 || x >= h || y < 0 || y >= w) return;
        for (ll a = (++y, ++x); a <= h; a += a & -a) {
            for (ll b = y; b <= w; b += b & -b) {
                bit[a][b] += c;
            }
        }
    }
    void imos(ll x1, ll y1, ll x2, ll y2, T c) {
        add(x1, y1, c);
        add(x1, y2, -c);
        add(x2, y1, -c);
        add(x2, y2, c);
    }
    T sum(ll x, ll y) {
        if (x < 0 || y < 0) return T(0);
        if (x >= h) x = h - 1;
        if (y >= w) y = w - 1;
        T ret = 0;
        for (ll a = (++y, ++x); a > 0; a -= a & -a) {
            for (ll b = y; b > 0; b -= b & -b) {
                ret += bit[a][b];
            }
        }
		return ret;
    }
    T sum(ll x1, ll y1, ll x2, ll y2) {
        if (x1 > x2 || y1 > y2) return T(0);
        return sum(x2, y2) - sum(x2, y1 - 1) - sum(x1 - 1, y2) + sum(x1 - 1, y1 - 1);
    }
};
void solve() {
    ll n; cin >> n;
	BIT2d<ll> bit(1010, 1010);
	rep(i, n) {
		ll x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2;
		// cout << x1 << ' ' << y1 << ' ' << x2 << ' ' << y2 << endl;
		bit.imos(x1, y1, x2, y2, 1);
	}
	ll ans = 0;
	rep(i, 1010) rep(j, 1010) {
		// cout << bit.sum(i, j) << " \n"[j == 99];
		chmax(ans, bit.sum(i, j));
	}
	cout << ans << endl;
}
int main() {
    ll T = 1;
    // cin >> T;
    while (T--) solve();
}
accuracy: 1
time_ms: 50
memory_kb: 11392
final_rank: 10

code_snippet: #define _USE_MATH_DEFINES
#include<bits/stdc++.h>
#define OVERLOAD_REP(v1, v2, v3, v4, NAME, ...) NAME
#define REP1(i, n) for (int i = 0; (i) < (n); ++(i))
#define REP2(i, l, r) for (int i = (l); (i) < (r); ++(i))
#define REP3(i, l, r, d) for (int i = (l); (i) < (r); (i)+=(d))
#define rep(...) OVERLOAD_REP(__VA_ARGS__, REP3, REP2, REP1)(__VA_ARGS__)
#define OVERLOAD_PRE(v1, v2, v3, v4, NAME, ...) NAME
#define PRE1(i, n) for (int i = (n)-1; (i) >= 0; --(i)) // [0,n)
#define PRE2(i, l, r) for (int i = (r)-1; (i) >= (l); --(i)) //[l,r)
#define PRE3(i, l, r, d) for (int i = (r)-1; (i) >= (l); (i)-=(d))
#define pre(...) OVERLOAD_PRE(__VA_ARGS__, PRE3, PRE2, PRE1)(__VA_ARGS__)
#define bg begin()
#define en end()
#define rbg rbegin()
#define ren rend()
#define all(x) x.bg,x.en
#define rall(x) x.rbg,x.ren
#define pf push_front
#define pb push_back
#define eb emplace_back
#define fir first
#define sec second
#define sz(x) ((int)(x).size())
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using sti = stack<int>;
using sei = set<int>;
using qi = queue<int>;
using qii = queue<pii>;
using dqi = deque<int>;
template<class t, class s> using umap = unordered_map<t,s>;
template<class t> using uset = unordered_set<t>;
template<class t> using mset = multiset<t>;
template<class t> using pq=priority_queue<t>;
template<class t> using pqg=priority_queue<t,vector<t>, greater<t>>;
template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;
template<class t> using vvvc=vc<vc<vc<t>>>;
using vi=vc<int>;
using vvi=vc<vc<int>>;
using vll=vc<ll>;
using vvll=vc<vc<ll>>;
using vd=vc<double>;
using vvd=vc<vc<double>>;
using vb=vc<bool>;
using vvb=vc<vc<bool>>;
using vch=vc<char>;
using vs=vc<string>;
const int inf = 1001001001;
const ll infl = 1LL << 60;
const ll mod = 998244353;
template<class t,class u> bool chmax(t&a,u b){if(a<b){a=b; return true;} return false;}
template<class t,class u> bool chmin(t&a,u b){if(a>b){a=b; return true;} return false;}
void yes(){ cout << "Yes" << '\n'; }
void no(){ cout << "No" << '\n'; }

/* compress
    X を座圧して書き換える
    返り値: val(val[i]=座圧後のiの元の値)
    計算量: O(n log n)
*/
template <typename T>
vc<T> compress(vector<T> &X) {
    vc<T> vals = X;
    sort(all(vals));
    vals.erase(unique(all(vals)), vals.en);
    for(auto &xi: X) xi = lower_bound(all(vals), xi) - vals.bg;
    return vals;
}

int main() {
    ios::sync_with_stdio(false);
  	cin.tie(0);
    int n; cin >> n;
    vi x1s(n),y1s(n),x2s(n),y2s(n),xs,ys;
    rep(i,n){
        cin >> x1s[i] >> y1s[i] >> x2s[i] >> y2s[i];
        xs.pb(x1s[i]);
        xs.pb(x2s[i]);
        ys.pb(y1s[i]);
        ys.pb(y2s[i]);
    }
    vi orix=compress(xs), oriy=compress(ys);
    for(auto &xi: x1s) xi = lower_bound(all(orix), xi) - orix.bg;
    for(auto &xi: x2s) xi = lower_bound(all(orix), xi) - orix.bg;
    for(auto &yi: y1s) yi = lower_bound(all(oriy), yi) - oriy.bg;
    for(auto &yi: y2s) yi = lower_bound(all(oriy), yi) - oriy.bg;
    int H=sz(orix),W=sz(oriy);
    vvll grid(H,vll(W));
    rep(i,n){
        int x1=x1s[i],y1=y1s[i],x2=x2s[i],y2=y2s[i];
        grid[x1][y1]++;
        grid[x2][y1]--;
        grid[x1][y2]--;
        grid[x2][y2]++;
    }
    rep(i,H)rep(j,W-1) grid[i][j+1]+=grid[i][j];
    rep(i,H-1)rep(j,W) grid[i+1][j]+=grid[i][j];
    ll ans=0;
    rep(i,H-1)rep(j,W-1)chmax(ans,grid[i][j]);
    cout << ans << "\n";
    return 0;
}
accuracy: 1
time_ms: 50
memory_kb: 15392
final_rank: 14

code_snippet: // #pragma GCC target("avx2")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>
using namespace std;

// #include <atcoder/all>
// using namespace atcoder;

using ll = long long;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)

const ll dy[] = {-1, 0, 0, 1};
const ll dx[] = {0, -1, 1, 0};

template <class T, class T1, class T2> bool isrange(T target, T1 low, T2 high) { return low <= target && target < high; }
template <class T, class U> T min(const T &t, const U &u) { return t < u ? t : u; }
template <class T, class U> T max(const T &t, const U &u) { return t < u ? u : t; }
template <class T, class U> bool chmin(T &t, const U &u) { if (t > u) { t = u; return true; } return false; }
template <class T, class U> bool chmax(T &t, const U &u) { if (t < u) { t = u; return true; } return false; }

// #include "titan_cpplib/others/io.cpp"
// #include "titan_cpplib/others/print.cpp"


namespace titan23 {

template <class T, T (*op)(T, T), T (*e)()>
class SegmentTree2D {
private:
    int h, w;
    int hs, ws;
    vector<vector<T>> data;

    inline int bit_length(int x) const {
        return x ? 32 - __builtin_clz(x) : 0;
    }

public:
    SegmentTree2D() {}
    SegmentTree2D(int h, int w) : h(h), w(w) {
        hs = 1<<bit_length(h);
        ws = 1<<bit_length(w);
        data.resize(hs*2, vector<T>(ws*2, e()));
    }

    T get(int y, int x) const {
        return data[y+hs][x+ws];
    }

    void set(int y, int x, T v) {
        y += hs; x += ws;
        data[y][x] = v;
        for (int nx = x; nx > 1; nx >>= 1) {
            data[y][nx>>1] = op(data[y][nx], data[y][nx^1]);
        }
        for (int ny = y; ny > 1; ny >>= 1) {
            int nx = x;
            data[ny>>1][nx] = op(data[ny][nx], data[ny^1][nx]);
            for (nx >>= 1; nx >= 1; nx >>= 1) {
                data[ny>>1][nx] = op(data[ny>>1][nx << 1], data[ny>>1][nx<<1|1]);
            }
        }
    }

    T prod(int u, int d, int l, int r) const {
        assert(0 <= u && u <= d && d <= h);
        assert(0 <= l && l <= r && r <= w);
        u += hs; d += hs;
        l += ws; r += ws;
        T ans = e();

        auto prodW = [&] (const vector<T> &dat) -> void {
            int nl = l, nr = r;
            while (nl < nr) {
                if (nl & 1) ans = op(ans, dat[nl++]);
                if (nr & 1) ans = op(ans, dat[--nr]);
                nl >>= 1; nr >>= 1;
            }
        };

        while (u < d) {
            if (u & 1) prodW(data[u++]);
            if (d & 1) prodW(data[--d]);
            u >>= 1; d >>= 1;
        }
        return ans;
    }
};
} // namespace titan23

int op(int s, int t) { return s + t;}
int e() { return 0; }
const int MAX = 1001;

void solve() {
    int n; cin >> n;
    titan23::SegmentTree2D<int, op, e> seg(MAX+1, MAX+1);
    rep(i, n) {
        int x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2;
        seg.set(y1, x1, seg.get(y1, x1) + 1);
        seg.set(y1, x2, seg.get(y1, x2) - 1);
        seg.set(y2, x1, seg.get(y2, x1) - 1);
        seg.set(y2, x2, seg.get(y2, x2) + 1);
    }

    int ans = 0;
    rep(i, MAX) rep(j, MAX) {
        ans = max(ans, seg.prod(0, i+1, 0, j+1));
    }
    cout << ans << endl;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);
    cerr << fixed << setprecision(15);

    int t = 1;
    // cin >> t;
    for (int i = 0; i < t; ++i) {
        solve();
    }

    return 0;
}
accuracy: 1
time_ms: 180
memory_kb: 19544
final_rank: 18

code_snippet: #include <bits/stdc++.h>
using namespace std;

#define rep(i,n) for(int i = 0; i < n; ++i)
using ll = long long;

int N;
int S[1001][1001];

int main(void) {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    cin >> N;
    rep(i,N) {
        short x1, y1, x2, y2;
        cin >> x1 >> y1 >> x2 >> y2;
        ++S[x1][y1], --S[x2][y1], --S[x1][y2], ++S[x2][y2];
    }
    
    rep(i,1001) rep(j,1000) S[i][j + 1] += S[i][j];
    rep(i,1000) rep(j,1001) S[i + 1][j] += S[i][j];
    
    int ans = 0;
    rep(i,1001) rep(j,1001) if(ans < S[i][j]) ans = S[i][j];
    cout << ans << endl;
    
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 7368
final_rank: 3

code_snippet: #include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int INT = 1e9;
const ll LINF = 1e18;

void solve(){
    int N; cin >> N;
    vector<vector<int>> imos(1010,vector<int>(1010,0));
    for(int i = 0; i < N;i++){
        int x1,y1,x2,y2; cin >> x1 >> y1 >> x2 >> y2;
        x1++;y1++;x2++;y2++;
        imos[x1][y1]++;
        imos[x1][y2]--;
        imos[x2][y1]--;
        imos[x2][y2]++;
    }
    int ans = 0;
    for(int i = 1; i< 1010;i++){
        for(int j = 1; j< 1010;j++){
            imos[i][j] += (imos[i-1][j]+imos[i][j-1]-imos[i-1][j-1]);
            ans = max(ans,imos[i][j]);
        }
    }
    cout << ans << endl;
}
int main(void){
    cin.tie(0); ios_base::sync_with_stdio(false);
    solve();
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 7044
final_rank: 1

code_snippet: #include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define elif else if
#define gcd __gcd
#define lcm(a,b) (a*b)/gcd(a,b)
#define pb push_back
#define vi vector<int>
#define vpi vector<pair<int,int>>
#define vvi vector<vector<int>>
#define pii pair<int,int>
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define unique(x) x.erase(unique(all(x)),x.end())
#define mp map<int,int>
#define si set<int>
#define msi multiset<int>
#define input(x) for(auto &i:x) cin>>i;
#define print(x) for(auto i:x) cout<<i<<" "; cout<<endl;
#define debugv(v) for(auto i:v) cerr<<i<<" "; cerr<<endl;
#define debug(x) cerr<<#x<<" = "<<x<<endl;
const int N=2e5+5;
const int MOD=1e9+7;
const int MOD2=998244353;
const int INF=1e18;
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// typedef tree<
//     int,
//     null_type,
//     less<int>,
//     rb_tree_tag,
//     tree_order_statistics_node_update
// > ordered_set;
// typedef tree<
//     pair<int,int>,
//     null_type,
//     less<pair<int,int>>,
//     rb_tree_tag,
//     tree_order_statistics_node_update
// > ordered_multiset;

int ceil_div(int a, int b) {
    return (a + b - 1) / b;
}

bool sieve[N];
int hp[N];
void sieve_eratosthenes(){
    sieve[0]=sieve[1]=true;
    for(int i=2;i<N;i++){
        if(sieve[i]==false){
            hp[i]=i;
            for(int j=2*i;j<N;j+=i){
                hp[j]=i;
                sieve[j]=true;
            }
        }
    }
}

int binmul(int a,int b,int MOD=MOD){
    int ans=0;
    while(b>0){
        if(b&1){
            ans=(ans+a)%MOD;
        }
        a=(a+a)%MOD;
        b>>=1;
    }
    return ans;
}

int binexp(int a,int b,int MOD=MOD){
    int ans=1;
    while(b>0){
        if(b&1){
            // ans=binmul(ans,a)%MOD;
            ans=(ans*a)%MOD;
        }
        // a=binmul(a,a)%MOD;
        a=(a*a)%MOD;
        b>>=1;
    }
    return ans;
}

bool comp(pii a, pii b) {
    if(a.fi == b.fi) {
        return a.se<b.se;
    }
    return a.fi < b.fi;
    // if(a.se==b.se) return a.fi<b.fi;
    // return a.se<b.se;
}

const int gN=4e3+5;
vi graph[N];

// #define cerr if(false)cerr

vector<int> riffle( vector<int>& f){
    int N = (int)f.size();
    vector<int> g;
    g.reserve(N);
    for(int i = 0; i < N; i += 2) g.push_back(f[i]);   // odd positions in 1-based indexing
    for(int i = 1; i < N; i += 2) g.push_back(f[i]);   // even positions in 1-based indexing
    return g;
}

void solve(){
    int nn;
    cin>>nn;
    int n=1000;
    vvi grid(n+1,vi(n+1,0));
    for(int i=1;i<=nn;i++){
        int x1,y1,x2,y2;
        cin>>x1>>y1>>x2>>y2;
        grid[x1][y1]++;
        grid[x2][y2]++;
        grid[x1][y2]--;
        grid[x2][y1]--;
    }
    for(int i=1;i<=n;i++){
        grid[i][0]+=grid[i-1][0];
        grid[0][i]+=grid[0][i-1];
    }
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            grid[i][j] += (grid[i-1][j] + grid[i][j-1] - grid[i-1][j-1]);
        }
    }
    int mx=0;
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            mx=max(mx,grid[i][j]);
        }
    }
    cout<<mx<<endl;
}

int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t=1;
    // cin>>t;
    while(t--){
        // debug(t);
        solve();
    }
    return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 17204
final_rank: 13

code_snippet: #include <bits/stdc++.h>
using namespace std;
const int N=1001;
int main() {
	// your code goes here
	int n;
	cin>>n;
	vector<vector<int>> v(N,vector<int>(N,0));
	int x1,y1,x2,y2;
	for(int i=0;i<n;i++){
	    cin>>x1>>y1>>x2>>y2;
	    v[x1][y1]++;
	    v[x2][y1]--;
	    v[x1][y2]--;
	    v[x2][y2]++;
	}
	int ans=0;
	for(int i=0;i<N;i++){
	    for(int j=0;j<N;j++){
	        if(i>0){
	            v[i][j]+=v[i-1][j];
	        }
	        if(j>0){
	            v[i][j]+=v[i][j-1];
	        }
	        if(i>0&&j>0){
	            v[i][j]-=v[i-1][j-1];
	        }
	        ans=max(ans,v[i][j]);
	    }
	}
	cout<<ans<<endl;
	

}
accuracy: 1
time_ms: 40
memory_kb: 7400
final_rank: 5

code_snippet: #define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>

using namespace std;

typedef pair<long long int, long long int> P;
long long int INF = 1e18;

int a[1100][1100] = {};

int main(){
	
	int N;
	cin >> N;
	
	for(int i = 0; i < N; i++){
		int x1, y1, x2, y2;
		cin >> x1 >> y1 >> x2 >> y2;
		a[x1][y1]++;
		a[x1][y2]--;
		a[x2][y1]--;
		a[x2][y2]++;
	}
	
	for(int i = 0; i <= 1000; i++){
		for(int j = 1; j <= 1000; j++){
			a[i][j] += a[i][j - 1];
		}
	}
	
	for(int i = 0; i <= 1000; i++){
		for(int j = 1; j <= 1000; j++){
			a[j][i] += a[j - 1][i];
		}
	}
	
	int ans = 0;
	for(int i = 0; i <= 1000; i++){
		for(int j = 0; j <= 1000; j++){
			ans = max(ans, a[i][j]);
		}
	}
	cout << ans << endl;
	
	return 0;
}
accuracy: 1
time_ms: 40
memory_kb: 7740
final_rank: 6

code_snippet: #include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

int N;
int W = 0,H = 0;

int main(){
    //入力
    cin >> N;
    vector<int> x1(N),y1(N),x2(N),y2(N);
    for(int i=0;i< N;i++){
        cin >> x1[i] >> y1[i] >> x2[i] >> y2[i];
        W = max(W,x2[i]);
        H = max(H,y2[i]);
    }

    vector<vector<int>> Z(W+2, vector<int>(H+2, 0));
    //各頂点
    for(int i=0;i<N;i++){
        Z[x1[i]][y1[i]] += 1;
        Z[x1[i]][y2[i]] -=1;
        Z[x2[i]][y1[i]] -=1;
        Z[x2[i]][y2[i]] +=1;
    }

    //累積和横
    for(int i=0;i<=W;i++){
        for(int j=1;j<=H;j++){
            Z[i][j] += Z[i][j-1];
        }
    }
    //縦
    for(int i=0;i<=H;i++){
        for(int j=1;j<=W;j++){
            Z[j][i] += Z[j-1][i];
        }
    }
    //最大値を求める
    int ans = 0;
    for (int i = 0; i <= W; i++){
        for (int j = 0; j <= H; j++){
            ans = max(ans, Z[i][j]);
        }
    }

    cout << ans <<endl;
    return 0;
}
accuracy: 1
time_ms: 40
memory_kb: 8600
final_rank: 8

code_snippet: #include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

int N;
int W = 0,H = 0;

int main(){
    //入力
    cin >> N;
    vector<int> x1(N),y1(N),x2(N),y2(N);
    for(int i=0;i< N;i++){
        cin >> x1[i] >> y1[i] >> x2[i] >> y2[i];
        W = max(W,x2[i]);
        H = max(H,y2[i]);
    }

    vector<vector<int>> Z(H+2, vector<int>(W+2, 0));
    //各頂点
    for(int i=0;i<N;i++){
        Z[y1[i]][x1[i]] += 1;
        Z[y1[i]][x2[i]] -=1;
        Z[y2[i]][x1[i]] -=1;
        Z[y2[i]][x2[i]] +=1;
    }

    //累積和横
    for(int i=0;i<=H;i++){
        for(int j=1;j<=W;j++){
            Z[i][j] += Z[i][j-1];
        }
    }
    //縦
    for(int i=0;i<=W;i++){
        for(int j=1;j<=H;j++){
            Z[j][i] += Z[j-1][i];
        }
    }
    //最大値を求める
    int ans = 0;
    for (int i = 0; i <= H; i++){
        for (int j = 0; j <= W; j++){
            ans = max(ans, Z[i][j]);
        }
    }

    cout << ans <<endl;
    return 0;
}
accuracy: 1
time_ms: 40
memory_kb: 8620
final_rank: 9

code_snippet: #include <atcoder/all>
#include <bits/stdc++.h>
#define rep(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
using namespace atcoder;
using namespace std;

typedef long long ll;

template <typename T> struct TDS {
    // 区間はすべて半開区間
    int h, w;
    bool rect = false, init = false;
    vector<vector<T>> v, vv, s;
    TDS() {}
    TDS(int h, int w) : h(h), w(w) {
        v = vector<vector<T>>(h, vector<T>(w));
        vv = vector<vector<T>>(h + 1, vector<T>(w + 1));
    }
    void add_point(int i, int j, T c) { v[i][j] += c; }
    void add_point(int li, int ri, int lj, int rj, T c) {
        rect |= true;
        vv[li][lj] += c;
        vv[li][rj] -= c;
        vv[ri][lj] -= c;
        vv[ri][rj] += c;
    }
    void make() {
        init = true;
        s = vector<vector<T>>(h + 1, vector<T>(w + 1));
        if (rect) {
            rect = false;
            vector ss = vector<vector<T>>(h, vector<T>(w));
            rep(i, 0, h) {
                rep(j, 0, w) {
                    ss[i][j] = vv[i][j];
                    if (j > 0)
                        ss[i][j] += ss[i][j - 1];
                }
            }
            rep(j, 0, w) {
                rep(i, 1, h) { ss[i][j] += ss[i - 1][j]; }
            }
            rep(i, 0, h) rep(j, 0, w) add_point(i, j, ss[i][j]);
        }
        rep(i, 0, h) {
            rep(j, 0, w) { s[i + 1][j + 1] = s[i + 1][j] + v[i][j]; }
        }
        rep(j, 0, w) {
            rep(i, 0, h) { s[i + 1][j + 1] += s[i][j + 1]; }
        }
    }
    T sum(int li, int ri, int lj, int rj) {
        if (!init)
            make();
        if (lj >= rj || li >= ri)
            return 0LL;
        T ret = s[ri][rj] - s[ri][lj] - s[li][rj] + s[li][lj];
        return ret;
    }
};

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(0);
    int n;
    cin >> n;
    TDS<ll> tds(1001, 1001);
    rep(i, 0, n) {
        int lx, ly, rx, ry;
        cin >> lx >> ly >> rx >> ry;
        tds.add_point(lx, rx, ly, ry, 1);
    }
    int ans = 0;
    rep(i, 0, 1001) rep(j, 0, 1001) {
        ans = max(ans, (int)tds.sum(i, i + 1, j, j + 1));
    }
    cout << ans << endl;
}
accuracy: 1
time_ms: 20
memory_kb: 34816
final_rank: 17

code_snippet: #include <bits/stdc++.h>
#define ll long long
#define rep(i,n,m) for(int i=(int)(n);i < (int)(m); i++)
#define repm(i,n,m) for(int i=(int)(n);i >= (int)(m); i--)
// #define _GLIBCXX_DEBUG
using namespace std;

int main(){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    int n;
    cin >> n;
    int m = 1001;
    vector<vector<int>> A(m,vector<int>(m,0));
    int x1,y1,x2,y2;
    rep(i,0,n){
        cin >> x1 >> y1 >> x2 >> y2;
        A[x1][y1]++;
        A[x1][y2]--;
        A[x2][y1]--;
        A[x2][y2]++;
    }
    rep(i,1,m)rep(j,0,m){
        A[j][i] += A[j][i-1];
    }
    rep(i,1,m)rep(j,0,m){
        A[i][j] += A[i-1][j];
    }
    int ans = 0;
    rep(i,0,m)rep(j,0,m){
        ans = max(ans,A[i][j]);
    }
    cout << ans << endl;
}
accuracy: 1
time_ms: 20
memory_kb: 7048
final_rank: 4

code_snippet: #include <iostream>
#include <bits/stdc++.h>
using namespace std;

// Aliases
using ll = long long int;
using lld = long double;
using ull = unsigned long long;

// Constants 
const lld pi = 3.141592653589793238;
const ll INF = LLONG_MAX;
const ll mod = 1e9 + 7;
const int inf = INT_MAX;

// TypeDEf
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<int> vint;
typedef vector<pll> vpll;
typedef vector<string> vs;
typedef unordered_map<ll, ll> umll;
typedef map<ll, ll> mll;

// Macros
#define ff first
#define ss second
#define p_b push_back
#define p_p pop_back
#define mp make_pair
#define For(i, n) for (ll i = 0; i < n; i++)
#define input(arr) for(ll i=0;i<arr.size();i++)cin>>arr[i];
#define outputSpace(arr) for(ll i=0;i<arr.size();i++){cout<<arr[i]<<" ";} cout<<endl;
#define outputEndl(arr) for(ll i=0;i<arr.size();i++)cout<<arr[i]<<endl;
#define printYes cout << "YES\n";
#define printminus1 cout << "-1\n";
#define print1 cout << "1\n";
#define print0 cout << "0\n";
#define printNo cout << "NO\n";
#define vr(v) v.begin(), v.end()
#define rv(v) v.end(), v.begin()
#define sortv(v) sort(v.begin(), v.end())
#define sumv(v) accumulate(v.begin(), v.end(), 0)
#define sortvg(v) sort(v.begin(), v.end(), greater<ll>())
#define reversev(v) reverse(v.begin(), v.end())
#define reversevIdx(v, i, j) reverse(v.begin() + i, v.begin() + j)
#define endll '\n'
#define sp " "
#define Endl endl;

template <typename T>
ll sumvec(vector<T> v)
{
ll n = v.size();
ll s = 0;
For(i, n) s += v[i];
return s;
}
//=============================================================================================================================

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////// DO NOT TOUCH BEFORE THIS LINE ///////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////

// Mathematical functions
ll gcd(ll a, ll b)
{
if (b == 0)
return a;
return gcd(b, a % b);
} //__gcd
ll lcm(ll a, ll b) { return (a / gcd(a, b) * b); }
ll moduloMultiplication(ll a, ll b, ll mod)
{
ll res = 0;
a %= mod;
while (b)
{
if (b & 1)
res = (res + a) % mod;
b >>= 1;
}
return res;
}
ll powermod(ll x, ll y, ll p)
{
ll res = 1;
x = x % p;
if (x == 0)
return 0;
while (y > 0)
{
if (y & 1)
res = (res * x) % p;
y = y >> 1;
x = (x * x) % p;
}
return res;
}

// Graph-dfs
//  bool gone[MN];
//  vector<int> adj[MN];
//  void dfs(int loc){
//      gone[loc]=true;
//      for(auto x:adj[loc])if(!gone[x])dfs(x);
//  }

// Sorting
bool sorta(const pair<ll, ll> &a, const pair<ll, ll> &b) { return (a.second < b.second); }
bool sortd(const pair<ll, ll> &a, const pair<ll, ll> &b) { return (a.second > b.second); }

// Bits
string decToBinary(int n)
{
string s = "";
int i = 0;
while (n > 0)
{
s = to_string(n % 2) + s;
n = n / 2;
i++;
}
return s;
}
ll binaryToDecimal(string n)
{
string num = n;
ll dec_value = 0;
ll base = 1;
ll len = num.length();
for (ll i = len - 1; i >= 0; i--)
{
if (num[i] == '1')
dec_value += base;
base = base * 2;
}
return dec_value;
}

// Check
bool isPrime(ll n)
{
if (n <= 1)
return false;
if (n <= 3)
return true;
if (n % 2 == 0 || n % 3 == 0)
return false;
for (int i = 5; i * i <= n; i = i + 6)
if (n % i == 0 || n % (i + 2) == 0)
return false;
return true;
}
bool isPowerOfTwo(int n)
{
if (n == 0)
return false;
return (n & (n - 1)) == 0;
}
bool isPerfectSquare(ll x)
{
if (x >= 0)
{
ll sr = sqrt(x);
return (sr * sr == x);
}
return false;
}

// No fucks here Please !!!
// Code
bool isSubstring(const std::string &s1, const std::string &s2)
{
// Use the find function to search for s1 in s2
return s2.find(s1) != std::string::npos;
}
int countdigit(int n)
{
int count = 0;
while (n > 0)
{
count++;
n /= 10;
}
return count;
}
ll sumofdigit(ll n)
{
ll sum = 0;
while (n > 0)
{
sum += n % 10;
n /= 10;
}
return sum;
}

ll reverse(ll n)
{
ll r = 0;
while (n > 0)
{
r *= 10;
r += n % 10;
n /= 10;
}
return r;
}

//=================================================SOLVE-ANS===================================================================

// TRY TO USE LL INSTEAD OF INT PLEASE


void primeFact(int x, map<ll,ll>&m){
while(x%2==0){
m[2]++;
x/=2;
}
for(ll i=3;i*i<=x;i++){
while((x%i)==0){
m[i]++;
x/=i;
}
}
if(x>1)m[x]++; // for prime no check
}


vector<bool> primeNumber(ll l)
{
vector<bool> isprime(l + 1, true);
vector<ll> prime;

isprime[0] = isprime[1] = false;
for (ll i = 2; i*i <= l; ++i)
{
if (isprime[i])
{
prime.push_back(i);
for (ll j = i * i; j <= l; j += i)
isprime[j] = false;
}
}

return isprime;
}

ll binexp(ll no, ll power, ll val) {
if (power == 0) {
return 1;
}
ll mid = power / 2;
ll u = binexp(no, mid, val);

if (u == -1 || u > val / u) return -1; 
u *= u;
if (power & 1) {
if (u > val / no) return -1; 
u *= no;
}
return u;
}

ll ModuloInv(ll a, ll b, ll m){ // a,m-2,m
ll no=1;
while(b){
if(b&1){
// odd
no= (no * a )%m;
}
a=(a*a)%m;
b=b>>1; // half right shift
}
return no;
}

void incBit(ll val,vector<ll>&ind){
int i=0;
while(val){
if(val&1){
ind[i]++;
}
i++;
val=val>>1;
}
return;
}

// bool check(ll mid){
//     ll no=mid;
//     for(int i=0;i<n;i++){
//         if(no>=arr[i].first){
//             no+=arr[i].second;
//         }
//         else{
//             return false;
//         }
//     }
//     return true;
// } 


// Aggressive COWs
// int check(ll &mid ,vector<ll>&stalls , ll &k){
//         int n =stalls.size();

//         int start=stalls[0];
//         int obt=1;
//         for(;obt<k;obt++){
//             int ind=lower_bound(stalls.begin(),stalls.end(),start+mid)-stalls.begin();

//             if(ind==n){
//                 return false;
//             }
//             else if(ind<n){
//                 start=stalls[ind];
//             }
//         }
//     return obt==k;

//     }


void  solve(){
   
   
   ll  n=1005;
    ll q;
    cin>>q;


    vector<vector<int>>adj(n+1,vector<int>(n+1,0));
    vector<vector<int>>arr(n+1,vector<int>(n+1,0));


    
    while(q--){
        ll x1,y1,x2,y2;
        cin>>x1>>y1>>x2>>y2;
        x1++;
        y1++;
        x2++;
        y2++;
        arr[x1][y1]++;
        arr[x2][y2]++;
        arr[x1][y2]--;
        arr[x2][y1]--;
    }


    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            arr[i][j]+=arr[i-1][j]+arr[i][j-1]-arr[i-1][j-1];

        }
    }


    ll ans=0;
        
   for(int i=0;i<arr.size();i++){
    for(int j=0;j<arr.size();j++){
        ans=max((int)ans,arr[i][j]);
    }

   }
   cout<<ans<<endl;
}



int main()
{   
ios::sync_with_stdio(false);
cin.tie(0);
// int t;
// cin>>t;
// while(t--)
solve();

}
accuracy: 1
time_ms: 10
memory_kb: 11012
final_rank: 7

code_snippet: #if __has_include(<atcoder/all>)
#include<atcoder/all>
using namespace atcoder;
using mint=modint998244353;
using mint1=modint1000000007;
#endif
#if __has_include(<ext/pb_ds/assoc_container.hpp>) && __has_include(<ext/pb_ds/tree_policy.hpp>)
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class s,class t>using __gnu_map=tree<s,t,std::less
,rb_tree_tag,tree_order_statistics_node_update>;
template<class s,class t>struct gnu_map:public __gnu_map<s,t>{
	using iterator=typename __gnu_map<s,t>::iterator;
	iterator get(int64_t idx){return this->find_by_order(idx<0?this->size()-idx:idx);}
	size_t ord(const s&key){return this->order_of_key(key);}
};
template<class s>struct gnu_set:public gnu_map<s,null_type>{gnu_map<s,null_type>::iterator operator[](int64_t i){return this->get(i);}};
#endif
#include <bits/stdc++.h>
using namespace std;
using std::cin;
using std::cout;
using sstream=stringstream;
#define RET return
#define int long long
#define itn long long
#define fi first
#define se second
#define endl '\n'
#define sn(i,c) " \n"[i==c];
#define rsv(n) reserve(n)
#define pf(a) push_front(a)
#define pb(a) push_back(a)
#define eb(...) emplace_back(__VA_ARGS__)
#define ppf() pop_front()
#define ppb() pop_back()
#define pp() pop()
#define ins(a) insert(a)
#define emp(...) emplace(__VA_ARGS__)
#define ers(a) erase(a)
#define cont(a) contains(a)
#define mp(f,s) make_pair(f,s)
#define A(a) begin(a),end(a)
#define I(a,i) begin(a),begin(a)+(i)
#define elif(c) else if(c)
#define _SEL4(_1,_2,_3,_4,name,...) name
#define _SEL3(_1,_2,_3,name,...) name
#define _REP4(i,s,n,st) for(int i=(s);i<(n);i+=(st))
#define _REP3(i,s,n) _REP4(i,s,n,1)
#define _REP2(i,n) _REP3(i,0,n)
#define _REP1(n) _REP2(_,n)
#define _RREP4(i,n,t,s) for(int i=(n);i>=(t);i-=(s))
#define _RREP3(i,n,t) _RREP4(i,n,t,1)
#define _RREP2(i,n) _RREP3(i,n,0)
#define _ITER2(x,a) for(auto&x:a)
#define _ITER3(x,y,a) for(auto&[x,y]:a)
#define _CTER2(x,a) for(const auto&x:a)
#define _CTER3(x,y,a) for(const auto&[x,y]:a)
#define rep(...) _SEL4(__VA_ARGS__,_REP4,_REP3,_REP2,_REP1)(__VA_ARGS__)
#define rrep(...) _SEL4(__VA_ARGS__,_RREP4,_RREP3,_RREP2,_REP1)(__VA_ARGS__)
#define forif(c,...) rep(__VA_ARGS__)if(c)
#define iter(...) _SEL3(__VA_ARGS__,_ITER3,_ITER2)(__VA_ARGS__)
#define cter(...) _SEL3(__VA_ARGS__,_CTER3,_CTER2)(__VA_ARGS__)
#define _LB_BEX(b,e,x) lower_bound(b,e,x)
#define _LB_BEXG(b,e,x,g) lower_bound(b,e,x,g)
#define _UB_BEX(b,e,x) upper_bound(b,e,x)
#define _UB_BEXG(b,e,x,g) upper_bound(b,e,x,g)
#define lb(...) _SEL4(__VA_ARGS__,_LB_BEXG,_LB_BEX)(__VA_ARGS__)
#define ub(...) _SEL4(__VA_ARGS__,_UB_BEXG,_UB_BEX)(__VA_ARGS__)
#define rev(a) reverse(A(a))
#define minel(a) min_element(A(a))
#define maxel(a) max_element(A(a))
#define acm(a) accumulate(A(a),0ll)
#define nxpm(a) next_permutation(A(a))
#define Sort(a) sort(A(a))
#define uni(a) Sort(a);a.erase(unique(A(a)),a.end())
#define swapcase(a) a=(isalpha(a)?a^32:a)
#define NL cout<<'\n'
template<class f>using gr=greater<f>;
template<class f>using vc=vector<f>;
template<class f>using vv=vc<vc<f>>;
template<class f>using v3=vv<vc<f>>;
template<class f>using v4=vv<vv<f>>;
template<class f>using pq=priority_queue<f>;
template<class f>using pqg=priority_queue<f, vc<f>, gr<f>>;
#define uset unordered_set
#define umap unordered_map
using i8=int8_t; using i16=int16_t; using i32=int32_t; using i64=int64_t; using i128=__int128_t;
using u8=uint8_t;using u16=uint16_t;using u32=uint32_t;using u64=uint64_t;using u128=__uint128_t;
using intw=__int128_t;using uintw=__uint128_t; using it=i32;
using f32=float;using f64=double;using f128=long double;
using vi=vc<int>;using vb=vc<bool>;
using pi=pair<int,int>;
using str=string;using vs=vc<str>;
using pqgp=pqg<pi>;
#define double f128
constexpr int inf=1ll<<60,minf=-inf;
constexpr char sep='\n';
constexpr array<pi,8>dc={{{1,0},{0,1},{-1,0},{0,-1},{1,1},{1,-1},{-1,1},{-1,-1}}};
template<class T,class U>inline void chmax(T&a,const U&b){if(a<b)a=b;}
template<class T,class U>inline void chmin(T&a,const U&b){if(a>b)a=b;}
#define yes cout<<"Yes\n"
#define no cout<<"No\n"
#define yn(c) (c)?yes:no
#if __cplusplus <= 202002L
#else
#define C const
namespace vies=std::views;
#define DR(i) views::drop(i)
#define TK(i) views::take(i)
#define RV views::reverse
#define IOTA vies::iota
#define INT(...) int __VA_ARGS__;in(__VA_ARGS__)
#define CHR(...) char __VA_ARGS__;in(__VA_ARGS__)
#define STR(...) str __VA_ARGS__;in(__VA_ARGS__)
#define VI(a,n) vi a(n);in(a)
#define VS(a,n) vs a(n);in(a)
#define UV(u,v) INT(u,v);u--,v--
#define UVW(u,v,w) INT(u,v,w);u--,v--
template<integral T,integral U>inline auto ceil(C T a,C U b){return(a+b-1)/b;}
template<integral T,integral U>inline auto floor(C T a,C U b){return a/b-(a%b&&(a^b)<0);}
template<class T,class U>concept LUBI= same_as<T,vc<U>>||same_as<T,deque<U>>||is_array_v<T>;
#define TP template<class T,class U,typename cp=less<U>>
#define RL requires LUBI<T,U>
TP u64 lbi(C T&v,C U&x,cp cmp=cp())RL{RET lb(A(v),x,cmp)-begin(v);}
TP u64 ubi(C T&v,C U&x,cp cmp=cp())RL{RET ub(A(v),x,cmp)-begin(v);}
TP u64 lbi(u64 i,C T&v,C U&x,cp cmp=cp())RL{RET lb(i+A(v),x,cmp)-begin(v);}
TP u64 ubi(u64 i,C T&v,C U&x,cp cmp=cp())RL{RET ub(i+A(v),x,cmp)-begin(v);}
TP u64 lbi(C T&v,u64 i,C U&x,cp cmp=cp())RL{RET lb(I(v,i),x,cmp)-begin(v);}
TP u64 ubi(C T&v,u64 i,C U&x,cp cmp=cp())RL{RET ub(I(v,i),x,cmp)-begin(v);}
TP u64 lbi(u64 i,C T&v,u64 e,C U&x,cp cmp=cp())RL{RET lb(i+I(v,e),x,cmp)-begin(v);}
TP u64 ubi(u64 i,C T&v,u64 e,C U&x,cp cmp=cp())RL{RET ub(i+I(v,e),x,cmp)-begin(v);}
#undef TP
#undef RL
#define TP template
TP<class T>concept Lint=is_integral_v<T>&&sizeof(T)>8;
TP<Lint T>ostream&operator<<(ostream&dst,T val){
	ostream::sentry s(dst);
	if(!s)return dst;
	char _O128[64];
	char*d=end(_O128);
	bool vsign=val<0;
	uintw v=val;
	if(vsign&&val!=numeric_limits<T>::min())v=1+~(uintw)val;
	do{
		*(--d)="0123456789"[v%10];
		v/=10;
	}while(v!=0);
	if(vsign)*(--d)='-';
	size_t len=end(_O128)-d;
	if(dst.rdbuf()->sputn(d,len)!=len)dst.setstate(ios_base::badbit);
	return dst;
}
TP<Lint T>istream&operator>>(istream&src,T&val) {
	str s;src>>s;
	bool is_neg=numeric_limits<T>::is_signed&&s.size()>0&&s[0]=='-';
	for(val=0;C auto&x:s|views::drop(is_neg))val=10*val+x-'0';
	if(is_neg)val*=-1;
	return src;
}
#define MUT make_unsigned_t
TP<integral T>i32 pcnt(T p){return popcount(MUT<T>(p));}
TP<integral T>i32 lsb(T p){return countl_zero(MUT<T>(p));}
TP<integral T>i32 msb(T p){return countr_zero(MUT<T>(p));}
TP<i32 N,integral T>void putbit(T s){
	char buf[N+1]={0};
	for(char*itr=buf+N-1;itr>=buf;itr--,s>>=1)
		*itr='0'+(s&1);
	cout<<buf<<sep;
}
TP<class T>concept Itrabl=requires(C T&x){x.begin();x.end();}&&!std::is_same_v<T,string>;
TP<class T>concept IItrabl=Itrabl<T>&&Itrabl<typename T::value_type>;
TP<class T>concept ModInt=requires(C T&x){x.val();};
TP<class T>concept NLobj=Itrabl<T>||std::is_same_v<T,string>;
TP<ModInt T>istream&operator>>(istream&is,T&v){int x;is>>x;v=x;return is;}
TP<Itrabl T>istream&operator>>(istream&is,T&v){iter(x,v)is>>x;return is;}
TP<class T,class U>istream&operator>>(istream&is,pair<T,U>&v){return is>>v.first>>v.second;}
TP<class T>void in(T&a){cin>>a;}
TP<class T,class... Ts>void in(T&a,Ts&... b){in(a);in(b...);}
TP<class T,class U>vc<pair<T,U>>zip(size_t n,size_t m){
	vc<pair<T,U>>r(min(n,m));
	iter(x,y,r)in(x);
	iter(x,y,r)in(y);
	return move(r);
}
TP<class T,class U>vc<pair<T,U>>zip(size_t n){return move(zip<T,U>(n,n));}
TP<ModInt T>ostream&operator<<(ostream&os,const T&v){return os<<v.val(); }
TP<Itrabl T>ostream&operator<<(ostream&os,const T&v){rep(i,v.size())os<<v[i]<<(i+1<v.size()?" ":"");return os;}
TP<IItrabl T>ostream&operator<<(ostream&os,const T&v){rep(i,v.size())os<<v[i]<<(i+1<v.size()?"\n":"");return os;}
TP<class T,class U>ostream&operator<<(ostream&os,const pair<T,U>&v){return os<<'('<<v.first<<','<<v.second<<')';}
ostream*dos=&cout;
int32_t OFLG; // 0:first, 1:notNLobj, 2:NLobj
TP<class T>void _out(const T&a){if(OFLG)(*dos)<<"0 \n"[OFLG]<<a;else(*dos)<<a;OFLG=1;}
TP<NLobj T>void _out(const T&a){(*dos)<<(OFLG?"\n":"")<<a;OFLG=2;}
TP<class T,class...Ts>void _out(const T&a,const Ts&... b){_out(a);_out(b...);}
TP<class... Ts>void out(const Ts&... v){OFLG=0;_out(v...);(*dos)<<sep;}
#undef TP
#undef C
#endif
#ifdef LOCAL
#define dput(...) dos=&cerr;putv(__VA_ARGS__);dos=&cout
#else
#define dput(...)
#endif


void slv(){
	INT(n);
	vv<it>imos(1002,vc<it>(1002,0));
	rep(n){
		INT(a,b,x,y);
		++imos[a][b];
		++imos[x][y];
		--imos[a][y];
		--imos[x][b];
	}
	rep(i,1002)
	rep(j,1,1002)
		imos[i][j]+=imos[i][j-1];
	rep(i,1,1002)
	rep(j,1002)
		imos[i][j]+=imos[i-1][j];
	itn ans=0;
	rep(i,1002)rep(j,1002)chmax(ans,imos[i][j]);
	out(ans);
}

signed main(){
	cin.tie(0)->sync_with_stdio(0);
	cout<<fixed<<setprecision(15);
	slv();
}
accuracy: 1
time_ms: 10
memory_kb: 7296
final_rank: 2

code_snippet: #include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<iomanip>
#include<map>
#include<stack>
#include<queue>
#include<set>
#include<deque>
#include<list>
#include<bitset>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int,int>;

const ld EPS = 1e-10;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
const ld PI = acos( -1.0 );

#define SWAP( A, B ) { auto tmp = A; A = B; B = tmp; }

template <typename T>
void print( vector<T> v ){
    if( v.size() == 0 ) return;
    for( int i = 0 ; i < v.size() - 1 ; i++ )
        cout << v[i] << ' ';
    cout << v[v.size()-1] << endl;
}

ll max_overlap( int H, int W, const vector<pair<P,P>> &sticker ){

    ll res = 0, s = 0;
    vector<vector<ll>> sum;

    for( int i = 0 ; i <= H ; i++ ){
        vector<ll> tmp;
        for( int j = 0 ; j <= W ; j++ )
            tmp.push_back( 0 );
        sum.push_back( tmp );
    }
    for( int i = 0 ; i < sticker.size() ; i++ ){
        P lu = sticker[i].first, rb = sticker[i].second;
        int x1 = lu.first, x2 = rb.first, y1 = lu.second, y2 = rb.second;
        for( int i = y1 ; i < y2 ; i++ ){
            sum[i][x1]++;
            sum[i][x2]--;
        }
    }
    for( int i = 0 ; i <= H ; i++ ){
        for( int j = 0 ; j <= W ; j++ ){
            s += sum[i][j];
            res = max( res, s );
        }
    }
    return res;

}

int main(){

    int N, H = 0, W = 0, x1, x2, y1, y2;
    vector<pair<P,P>> sticker;

    cin >> N;
    for( int i = 0 ; i < N ; i++ ){
        cin >> x1 >> y1 >> x2 >> y2;
        sticker.push_back( make_pair( make_pair( x1, y1 ), make_pair( x2, y2 ) ) );
        W = max( W, x1 ); W = max( W, x2 );
        H = max( H, y1 ); H = max( H, y2 );
    }
    cout << max_overlap( H, W, sticker ) << endl;

}
accuracy: 1
time_ms: 120
memory_kb: 12504
final_rank: 16

code_snippet: #include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<iomanip>
#include<map>
#include<stack>
#include<queue>
#include<set>
#include<deque>
#include<list>
#include<bitset>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int,int>;

const ld EPS = 1e-10;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
const ld PI = acos( -1.0 );

#define SWAP( A, B ) { auto tmp = A; A = B; B = tmp; }

template <typename T>
void print( vector<T> v ){
    if( v.size() == 0 ) return;
    for( int i = 0 ; i < v.size() - 1 ; i++ )
        cout << v[i] << ' ';
    cout << v[v.size()-1] << endl;
}

template <typename U>
void print( vector< vector<U> > v ){
    if( v.size() == 0 ) return;
    for( int i = 0 ; i < v.size() ; i++ ){
        if( v[i].size() == 0 )
            return;
    }
    for( int i = 0 ; i < v.size() ; i++ ){
        for( int j = 0 ; j < v[i].size() - 1 ; j++ )
            cout << v[i][j] << ' ';
        cout << v[i][v[i].size()-1] << endl;
    }
}

ll max_overlap( int H, int W, const vector<pair<P,P>> &sticker ){

    ll res = 0, s = 0;
    vector<vector<ll>> sum;

    for( int i = 0 ; i <= H ; i++ ){
        vector<ll> tmp;
        for( int j = 0 ; j <= W ; j++ )
            tmp.push_back( 0 );
        sum.push_back( tmp );
    }
    for( int i = 0 ; i < sticker.size() ; i++ ){
        P lu = sticker[i].first, rb = sticker[i].second;
        int x1 = lu.first, x2 = rb.first, y1 = lu.second, y2 = rb.second;
        for( int i = y1 ; i < y2 ; i++ ){
            sum[i][x1]++;
            sum[i][x2]--;
        }
    }
    for( int i = 0 ; i <= H ; i++ ){
        for( int j = 0 ; j <= W ; j++ ){
            s += sum[i][j];
            res = max( res, s );
        }
    }
    return res;

}

int main(){

    int N, H = 0, W = 0, x1, x2, y1, y2;
    vector<pair<P,P>> sticker;

    cin >> N;
    for( int i = 0 ; i < N ; i++ ){
        cin >> x1 >> y1 >> x2 >> y2;
        sticker.push_back( make_pair( make_pair( x1, y1 ), make_pair( x2, y2 ) ) );
        W = max( W, x1 ); W = max( W, x2 );
        H = max( H, y1 ); H = max( H, y2 );
    }
    cout << max_overlap( H, W, sticker ) << endl;

}
accuracy: 1
time_ms: 120
memory_kb: 12444
final_rank: 15