Language: C++

#include <cassert>
#include <cstring>
#include <chrono>

using namespace std;

typedef long long ll;

ll Solve(vector<ll> L, vector<ll> R) {
  int n = L.size();
  sort(L.rbegin(), L.rend());
  sort(R.begin(), R.end());
  ll x = 0;
  ll result = 0;
  for (int i = 0; i < n; ++i) {
    if (L[i] >= x) {
      result += L[i] - x;
      x = L[i];
    } else {
      break;
    }

    if (R[i] <= x) {
      result += x - R[i];
      x = R[i];
    } else {
      break;
    }
  }
  result += abs(x);
  return result;
}

int main()
{
  int n;
  cin >> n;
  vector<ll> L(n), R(n);
  for (int i = 0; i < n; ++i) {
    cin >> L[i] >> R[i];
  }

  ll result = Solve(L, R);
  for (int i = 0; i < n; ++i) {
    L[i] *= -1;
    R[i] *= -1;
  }
  swap(L, R);
  result = max(result, Solve(L, R));
  cout << result << endl;
  return 0;
}


Compiler output:
a.cc:9:10: error: 'vector' was not declared in this scope
    9 | ll Solve(vector<ll> L, vector<ll> R) {
      |          ^~~~~~
a.cc:4:1: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
    3 | #include <chrono>
  +++ |+#include <vector>
    4 | 
a.cc:9:19: error: expected primary-expression before '>' token
    9 | ll Solve(vector<ll> L, vector<ll> R) {
      |                   ^
a.cc:9:21: error: 'L' was not declared in this scope
    9 | ll Solve(vector<ll> L, vector<ll> R) {
      |                     ^
a.cc:9:24: error: 'vector' was not declared in this scope
    9 | ll Solve(vector<ll> L, vector<ll> R) {
      |                        ^~~~~~
a.cc:9:24: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
a.cc:9:33: error: expected primary-expression before '>' token
    9 | ll Solve(vector<ll> L, vector<ll> R) {
      |                                 ^
a.cc:9:35: error: 'R' was not declared in this scope
    9 | ll Solve(vector<ll> L, vector<ll> R) {
      |                                   ^
a.cc:9:36: error: expression list treated as compound expression in initializer [-fpermissive]
    9 | ll Solve(vector<ll> L, vector<ll> R) {
      |                                    ^
a.cc: In function 'int main()':
a.cc:37:3: error: 'cin' was not declared in this scope
   37 |   cin >> n;
      |   ^~~
a.cc:4:1: note: 'std::cin' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
    3 | #include <chrono>
  +++ |+#include <iostream>
    4 | 
a.cc:38:3: error: 'vector' was not declared in this scope
   38 |   vector<ll> L(n), R(n);
      |   ^~~~~~
a.cc:38:3: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
a.cc:38:12: error: expected primary-expression before '>' token
   38 |   vector<ll> L(n), R(n);
      |            ^
a.cc:38:14: error: 'L' was not declared in this scope
   38 |   vector<ll> L(n), R(n);
      |              ^
a.cc:38:20: error: 'R' was not declared in this scope
   38 |   vector<ll> L(n), R(n);
      |                    ^
a.cc:43:20: error: 'Solve' cannot be used as a function
   43 |   ll result = Solve(L, R);
      |               ~~~~~^~~~~~
a.cc:49:29: error: 'Solve' cannot be used as a function
   49 |   result = max(result, Solve(L, R));
      |                        ~~~~~^~~~~~
a.cc:49:12: error: 'max' was not declared in this scope
   49 |   result = max(result, Solve(L, R));
      |            ^~~
a.cc:50:3: error: 'cout' was not declared in this scope
   50 |   cout << result << endl;
      |   ^~~~
a.cc:50:3: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:50:21: error: 'endl' was not declared in this scope
   50 |   cout << result << endl;
      |                     ^~~~
a.cc:4:1: note: 'std::endl' is defined in header '<ostream>'; this is probably fixable by adding '#include <ostream>'
    3 | #include <chrono>
  +++ |+#include <ostream>
    4 |