Language: C++

/*#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("fast-math")*/
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>

using namespace std;

#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define Str(x) to_string(x)
#define len(s) (int)s.size()
#define int long long
typedef long long ll;
typedef long double lld;
typedef string str;
typedef unsigned long long ull;

 main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    int n;
    cin >> n;
    vector <pair<int, int> > v(n), pref(n), suf(n);
    for (auto &it : v)
        cin >> it.first >> it.second;
    sort(all(v));
    pref[0] = v[0];
    suf[n - 1] = v[n - 1];
    for (int i = 1; i < n; i++) {
        pref[i].first = max(pref[i - 1].first, v[i].first);
        pref[i].second = min(pref[i - 1].second, v[i].second);
        suf[n - i - 1].first = max(suf[n - i].first, v[n - i - 1].first);
        suf[n - i - 1].second = min(suf[n - i].second, v[n - i - 1].second);
    }
    int ans = 0;
    for (int i = 0; i < n - 1; i++) {
        //cout << i << " : " << pref[i].first << " :: " << pref[i].second << " ? " << suf[i + 1].first << " :: " << suf[i + 1].second << endl;
        ans = max(ans, max(0, pref[i].second - pref[i].first + 1) + max(0, suf[i+1].second - suf[i+1].first + 1));
    }
    cout << ans;
    return 0;
}


Compiler output:
a.cc:41:2: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   41 |  main() {
      |  ^~~~
a.cc: In function 'int main()':
a.cc:66:27: error: no matching function for call to 'max(int, long long int)'
   66 |         ans = max(ans, max(0, pref[i].second - pref[i].first + 1) + max(0, suf[i+1].second - suf[i+1].first + 1));
      |                        ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/string:51,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:5:
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:66:27: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   66 |         ans = max(ans, max(0, pref[i].second - pref[i].first + 1) + max(0, suf[i+1].second - suf[i+1].first + 1));
      |                        ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61,
                 from a.cc:9:
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:66:27: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   66 |         ans = max(ans, max(0, pref[i].second - pref[i].first + 1) + max(0, suf[i+1].second - suf[i+1].first + 1));
      |                        ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:66:72: error: no matching function for call to 'max(int, long long int)'
   66 |         ans = max(ans, max(0, pref[i].second - pref[i].first + 1) + max(0, suf[i+1].second - suf[i+1].first + 1));
      |                                                                     ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:66:72: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   66 |         ans = max(ans, max(0, pref[i].second - pref[i].first + 1) + max(0, suf[i+1].second - suf[i+1].first + 1));
      |                                                                     ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:66:72: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   66 |         ans = max(ans, max(0, pref[i].second - pref[i].first + 1) + max(0, suf[i+1].second - suf[i+1].first + 1));
      |                                                                     ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~