Language: C++

//#define _GLIBCXX_DEBUG
#include "bits/stdc++.h"

using namespace std;

//------------------------------- Libraries --------------------------------//

//------------------------------- Type Names -------------------------------//

using i64 = int_fast64_t;

using seika = string;
//akari : 1D, yukari : 2D, maki : 3D vector
template <class kizuna>
using akari = vector<kizuna>;
template <class yuzuki>
using yukari = akari<akari<yuzuki>>;
template <class tsurumaki>
using maki = akari<yukari<tsurumaki>>;
//akane : ascending order, aoi : decending order
template <class kotonoha>
using akane = priority_queue<kotonoha, akari<kotonoha>, greater<kotonoha>>;
template <class kotonoha>
using aoi = priority_queue<kotonoha>;

//------------------------------- Dubug Functions ---------------------------//
inline void print()
{
    cout << endl;
}
template <typename First, typename... Rest>
void print(const First &first, const Rest &... rest)
{
    cout << first << ' ';
    print(rest...);
}
//------------------------------- Solver ------------------------------------//

void solve()
{
    int n;
    cin >> n;
    akari<pair<i64, i64>> ps(n);
    for (int i = 0; i < n; i++)
    {
        cin >> ps[i].first >> ps[i].second;
    }
    sort(ps.begin(), ps.end());
    akari<i64> ls1(n), rs1(n), ls2(n), rs2(n);
    ls1[0] = ps[0].first;
    rs1[0] = ps[0].second;
    for (int i = 1; i < n; i++)
    {
        ls1[i] = ps[i].first;
        rs1[i] = min(rs1[i - 1], ps[i].second);
    }
    ls2[n - 1] = ps[n - 1].first;
    rs2[n - 1] = ps[n - 1].second;
    for (int i = n - 2; i >= 0; i--)
    {
        ls2[i] = max(ls2[i + 1], ps[i].first);
        rs2[i] = min(rs2[i + 1], ps[i].second);
    }
    int ans = 0;
    for (int i = 0; i < n - 1; i++)
    {
        //print(ls1[i], rs1[i], ls2[i + 1], rs2[i + 1]);
        ans = max(ans, rs1[i] - ls1[i] + rs2[i + 1] - ls2[i + 1] + i64(2));
    }
    cout << ans << endl;
}

int main()
{
    solve();
    return 0;
}

Compiler output:
a.cc: In function 'void solve()':
a.cc:68:18: error: no matching function for call to 'max(int&, __gnu_cxx::__alloc_traits<std::allocator<long int>, long int>::value_type)'
   68 |         ans = max(ans, rs1[i] - ls1[i] + rs2[i + 1] - ls2[i + 1] + i64(2));
      |               ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:2:
/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:68:18: note:   deduced conflicting types for parameter 'const _Tp' ('int' and '__gnu_cxx::__alloc_traits<std::allocator<long int>, long int>::value_type' {aka 'long int'})
   68 |         ans = max(ans, rs1[i] - ls1[i] + rs2[i + 1] - ls2[i + 1] + i64(2));
      |               ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/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:
/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:68:18: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   68 |         ans = max(ans, rs1[i] - ls1[i] + rs2[i + 1] - ls2[i + 1] + i64(2));
      |               ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~