Language: C++

4
1 2#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)n; i++)
using P = pair<int,int>;

int main(){
  int n;
  cin >> n;
  P a[n];
  int ans = 0;
  rep(i,n) cin >> a[i].first >> a[i].second;
  sort(a,a+n);
  vector<int> l(n), r(n);
  l[0] = a[0].second, r[n-1] = a[n-1].second;
  for(int i = 1; i < n; i++) {
    l[i] = min(l[i-1],a[i].second);
    r[n-i-1] = min(r[n-i],a[n-i-1].second);
  }
  rep(i,n) {
    int d = a[i].second - a[i].first + 1;
    if(i == 0) ans = max(ans,d+r[1]-a[n-1].first+1);
    else if(i == n-1) ans = max(ans,d+l[n-2]-a[n-2].first+1);
    else ans = max(ans,d+max(0,min(r[i+1],l[i-1])-a[n-1].first+1));
  }
  rep(i,n-1) ans = max(ans,max(l[i]-a[i].first+1,0)+max(r[i+1]-a[n-1].first+1,0));
  cout << ans << endl;
  return 0;
}

Compiler output:
a.cc:2:4: error: stray '#' in program
    2 | 1 2#include <bits/stdc++.h>
      |    ^
a.cc:1:1: error: expected unqualified-id before numeric constant
    1 | 4
      | ^
a.cc:5:11: error: 'pair' does not name a type
    5 | using P = pair<int,int>;
      |           ^~~~
a.cc: In function 'int main()':
a.cc:9:3: error: 'cin' was not declared in this scope
    9 |   cin >> n;
      |   ^~~
a.cc:10:3: error: 'P' was not declared in this scope
   10 |   P a[n];
      |   ^
a.cc:12:19: error: 'a' was not declared in this scope
   12 |   rep(i,n) cin >> a[i].first >> a[i].second;
      |                   ^
a.cc:13:8: error: 'a' was not declared in this scope
   13 |   sort(a,a+n);
      |        ^
a.cc:13:3: error: 'sort' was not declared in this scope; did you mean 'short'?
   13 |   sort(a,a+n);
      |   ^~~~
      |   short
a.cc:14:3: error: 'vector' was not declared in this scope
   14 |   vector<int> l(n), r(n);
      |   ^~~~~~
a.cc:14:10: error: expected primary-expression before 'int'
   14 |   vector<int> l(n), r(n);
      |          ^~~
a.cc:15:3: error: 'l' was not declared in this scope
   15 |   l[0] = a[0].second, r[n-1] = a[n-1].second;
      |   ^
a.cc:15:23: error: 'r' was not declared in this scope
   15 |   l[0] = a[0].second, r[n-1] = a[n-1].second;
      |                       ^
a.cc:17:12: error: 'min' was not declared in this scope; did you mean 'main'?
   17 |     l[i] = min(l[i-1],a[i].second);
      |            ^~~
      |            main
a.cc:22:22: error: 'max' was not declared in this scope
   22 |     if(i == 0) ans = max(ans,d+r[1]-a[n-1].first+1);
      |                      ^~~
a.cc:23:29: error: 'max' was not declared in this scope
   23 |     else if(i == n-1) ans = max(ans,d+l[n-2]-a[n-2].first+1);
      |                             ^~~
a.cc:24:32: error: 'min' was not declared in this scope; did you mean 'main'?
   24 |     else ans = max(ans,d+max(0,min(r[i+1],l[i-1])-a[n-1].first+1));
      |                                ^~~
      |                                main
a.cc:24:26: error: 'max' was not declared in this scope
   24 |     else ans = max(ans,d+max(0,min(r[i+1],l[i-1])-a[n-1].first+1));
      |                          ^~~
a.cc:24:16: error: 'max' was not declared in this scope
   24 |     else ans = max(ans,d+max(0,min(r[i+1],l[i-1])-a[n-1].first+1));
      |                ^~~
a.cc:26:28: error: 'max' was not declared in this scope
   26 |   rep(i,n-1) ans = max(ans,max(l[i]-a[i].first+1,0)+max(r[i+1]-a[n-1].first+1,0));
      |                            ^~~
a.cc:26:20: error: 'max' was not declared in this scope
   26 |   rep(i,n-1) ans = max(ans,max(l[i]-a[i].first+1,0)+max(r[i+1]-a[n-1].first+1,0));
      |                    ^~~
a.cc:27:3: error: 'cout' was not declared in this scope
   27 |   cout << ans << endl;
      |   ^~~~
a.cc:27:18: error: 'endl' was not declared in this scope
   27 |   cout << ans << endl;
      |                  ^~~~