Language: C++

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

//repetition
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

//const value
//const ll MOD = 1e9 + 7;
//const int dx[] = {0,1,0,-1};//{0,0,1,1,1,-1,-1,-1};
//const int dy[] = {1,0,-1,0};//{1,-1,0,1,-1,0,1,-1};

//conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
inline ll toLL(string s) {ll v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  VI l(n),r(n);
  int ll = 0;
  int rr = 1e9;
  int mm = 0;
  rep(i,n){
    cin >> l[i] >> r[i];
    ll = max(l[i],ll);
    rr = min(r[i],rr);
    mm = max(r[i] - l[i] + 1, mm );
  }
  int ans = mm + max(rr-ll+1,0);

  // serch lmax rmin same
  vector<PII> rv;
  vector<PII> lv;

  rep(i,n) {
    rv.push_back(PII(r[i]-ll + 1, l[i]));
    lv.push_back(PII(rr-l[i] + 1, -r[i]));
  }

  sort(all(rv));
  sort(all(lv));
  int minR = 1e9;
  rep(i,n-1){
    minR = min(minR ,-lv[i].second);
    ans = max(lv[i+1].first + (minR - ll + 1), ans);
  }

  int maxL = 0;
  rep(i,n-1){
    maxL = max(maxL ,rv[i].second);
    ans = max(rv[i+1].first + (rr - maxL + 1), ans);
  }
  cout << ans << endl;
  return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:41:7: error: expected ';' before 'i'
   41 |   rep(i,n){
      |       ^
a.cc:6:26: note: in definition of macro 'rep'
    6 | #define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
      |                          ^
a.cc:41:7: error: 'i' was not declared in this scope
   41 |   rep(i,n){
      |       ^
a.cc:6:33: note: in definition of macro 'rep'
    6 | #define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
      |                                 ^
a.cc:6:41: error: 'll' cannot be used as a function
    6 | #define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
      |                                     ~~~~^~~
a.cc:41:3: note: in expansion of macro 'rep'
   41 |   rep(i,n){
      |   ^~~
a.cc:53:7: error: expected ';' before 'i'
   53 |   rep(i,n) {
      |       ^
a.cc:6:26: note: in definition of macro 'rep'
    6 | #define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
      |                          ^
a.cc:53:7: error: 'i' was not declared in this scope
   53 |   rep(i,n) {
      |       ^
a.cc:6:33: note: in definition of macro 'rep'
    6 | #define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
      |                                 ^
a.cc:6:41: error: 'll' cannot be used as a function
    6 | #define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
      |                                     ~~~~^~~
a.cc:53:3: note: in expansion of macro 'rep'
   53 |   rep(i,n) {
      |   ^~~
a.cc:61:7: error: expected ';' before 'i'
   61 |   rep(i,n-1){
      |       ^
a.cc:6:26: note: in definition of macro 'rep'
    6 | #define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
      |                          ^
a.cc:61:7: error: 'i' was not declared in this scope
   61 |   rep(i,n-1){
      |       ^
a.cc:6:33: note: in definition of macro 'rep'
    6 | #define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
      |                                 ^
a.cc:6:41: error: 'll' cannot be used as a function
    6 | #define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
      |                                     ~~~~^~~
a.cc:61:3: note: in expansion of macro 'rep'
   61 |   rep(i,n-1){
      |   ^~~
a.cc:67:7: error: expected ';' before 'i'
   67 |   rep(i,n-1){
      |       ^
a.cc:6:26: note: in definition of macro 'rep'
    6 | #define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
      |                          ^
a.cc:67:7: error: 'i' was not declared in this scope
   67 |   rep(i,n-1){
      |       ^
a.cc:6:33: note: in definition of macro 'rep'
    6 | #define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
      |                                 ^
a.cc:6:41: error: 'll' cannot be used as a function
    6 | #define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
      |                                     ~~~~^~~
a.cc:67:3: note: in expansion of macro 'rep'
   67 |   rep(i,n-1){
      |   ^~~