#include #include #include using namespace std ; using ll = long long ; using ull = unsigned long long ; ll n, s, t, ls, hs, lt, ht, r ; const int MAX = 6400 ; const int BMS = (MAX * MAX) >> 6 ; ull added[BMS] = {1} ; vector> a ; void addval(int j, int i) { int off = j * MAX + i ; if (((added[off>>6] >> (off & 63)) & 1) == 0) { added[off>>6] |= 1LL << (off & 63) ; a[j].push_back(i) ; r = max(r, (ll)(i+j)) ; } } int main() { cin >> n >> s >> t ; a.resize(n+1) ; a[0].push_back(0) ; vector w ; for (ll i=0; i> ls >> hs >> lt >> ht ; for (ll j=min(i, hs-s); j>=max(0LL, ls-s); j--) { w.clear() ; swap(a[j], w) ; sort(w.begin(), w.end(), greater()) ; for (auto v: w) if (v>=lt-t && v<=ht-t) { addval(j+1, v) ; addval(j, v+1) ; } else a[j].push_back(v) ; } } cout << r << endl ; }