#include<bits/stdc++.h>
#define INF 1000010000
#define nl '\n'
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define fi first
#define se second
#define pii pair<int,int>
#define pdd pair<double,double>
#define all(c) (c).begin(), (c).end()
#define SORT(c) sort(all(c))
#define sz(c) (c).size()
#define rep(i,n) for( int i = 0; i < n; ++i )
#define repi(i,n) for( int i = 1 ; i <= n; ++i )
#define repn(i,n) for( int i = n - 1 ; i >= 0 ; --i )
#define repf(j,i,n) for( int j = i ; j < n ; ++j )
#define die(s) {std::cout << s << nl;}
#define dier(s) {std::cout << s; return 0;}
#define dbg(var) {std::cout << #var << " = " << var << nl;}
#define vi vector<int>
typedef long long ll;
using namespace std;
struct rect
{
pii bl, tr;
int val;
};
constexpr int MAX_X = 1e4 + 5;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.precision(0);
int n;
cin >> n;
vector<rect> v;
rep(i , n)
{
v.emplace_back();
cin >> v.back().bl.fi >> v.back().bl.se >> v.back().tr.fi >> v.back().tr.se >> v.back().val;
}
struct state
{
int type;
int x;
int i;
};
vector<state> states;
rep(i , n)
{
state begin, end;
begin.type = 1;
end.type = -1;
begin.x = v[i].bl.fi;
end.x = v[i].tr.fi;
begin.i = end.i = i;
states.pb(begin);
states.pb(end);
}
sort(all(states) , [](auto& a , auto& b)
{
return a.x < b.x || (a.x == b.x && a.type < b.type);
});
vi grid(MAX_X);
int l = -1;
int ans = 0;
int cnt = 0;
int p = 0;
while(p < states.size())
{
int cur_x = states[p].x;
int w = cur_x - l;
rep(i , MAX_X)
{
if(ans == grid[i])
{
cnt += w;
}
else if(grid[i] > ans)
{
ans = grid[i];
cnt = w;
}
}
vi tmp(MAX_X);
do
{
if(p >= states.size()) break;
if(states[p].x != cur_x) break;
if(states[p].type != -1) break;
tmp[v[states[p].i].bl.se] -= v[states[p].i].val;
tmp[v[states[p].i].tr.se] += v[states[p].i].val;
++p;
}
while(p < states.size());
do
{
if(p >= states.size()) break;
if(states[p].x != cur_x) break;
if(states[p].type != 1) break;
tmp[v[states[p].i].bl.se] += v[states[p].i].val;
tmp[v[states[p].i].tr.se] -= v[states[p].i].val;
++p;
}
while(p < states.size());
rep(i , MAX_X)
{
if(i > 0) tmp[i] += tmp[i - 1];
grid[i] += tmp[i];
}
l = cur_x;
}
cout << ans << endl;
return 0;
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KCiNkZWZpbmUgSU5GIDEwMDAwMTAwMDAKI2RlZmluZSBubCAnXG4nCiNkZWZpbmUgcGIgcHVzaF9iYWNrCiNkZWZpbmUgcHBiIHBvcF9iYWNrCiNkZWZpbmUgbXAgbWFrZV9wYWlyCiNkZWZpbmUgZmkgZmlyc3QKI2RlZmluZSBzZSBzZWNvbmQKI2RlZmluZSBwaWkgcGFpcjxpbnQsaW50PgojZGVmaW5lIHBkZCBwYWlyPGRvdWJsZSxkb3VibGU+CiNkZWZpbmUgYWxsKGMpIChjKS5iZWdpbigpLCAoYykuZW5kKCkKI2RlZmluZSBTT1JUKGMpIHNvcnQoYWxsKGMpKQojZGVmaW5lIHN6KGMpIChjKS5zaXplKCkKI2RlZmluZSByZXAoaSxuKSBmb3IoIGludCBpID0gMDsgaSA8IG47ICsraSApCiNkZWZpbmUgcmVwaShpLG4pIGZvciggaW50IGkgPSAxIDsgaSA8PSBuOyArK2kgKQojZGVmaW5lIHJlcG4oaSxuKSBmb3IoIGludCBpID0gbiAtIDEgOyBpID49IDAgOyAtLWkgKQojZGVmaW5lIHJlcGYoaixpLG4pIGZvciggaW50IGogPSBpIDsgaiA8IG4gOyArK2ogKQojZGVmaW5lIGRpZShzKSB7c3RkOjpjb3V0IDw8IHMgPDwgbmw7fQojZGVmaW5lIGRpZXIocykge3N0ZDo6Y291dCA8PCBzOyByZXR1cm4gMDt9CiNkZWZpbmUgZGJnKHZhcikge3N0ZDo6Y291dCA8PCAjdmFyIDw8ICIgID0gIiA8PCB2YXIgPDwgbmw7fQojZGVmaW5lIHZpIHZlY3RvcjxpbnQ+C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