output_description: Print the maximum possible total joyfulness of the two contests.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      N
      L_1 R_1
      L_2 R_2
      \vdots
      L_N R_N
attempt: n = int(input())
  lis = [list(map(int, input().split())) for i in range(n)]
  lis.sort(key=lambda x: x[1], reverse=True)
  lis.sort(key=lambda x: x[0])
  left = lis.pop(0)
  lis.sort(key=lambda x: x[1], reverse=True)
  right = lis.pop(0)
  for i in range(n - 2):
      now_left = left[1] - left[0] + 1
      now_right = right[1] - right[0] + 1
      will_left = max(0, min(left[1], lis[i][1]) - max(left[0], lis[i][0]) + 1)
      will_right = max(0, min(right[1], lis[i][1]) - max(right[0], lis[i][0]) + 1)
      lost_left = now_left - will_left
      lost_right = now_right - will_right
      if lost_left > lost_right:
          right[1] = min(right[1], lis[i][1])
          right[0] = max(right[0], lis[i][0])
      else:
          left[0] = max(left[0], lis[i][0])
          left[1] = min(left[1], lis[i][1])
  print(max(0, left[1] - left[0] + 1) + max(0, right[1] - right[0] + 1))
  
problem_description: Statement
  
  10^9 contestants, numbered 1 to 10^9, will compete in a competition. There
  will be two contests in this competition.
  
  The organizer prepared N problems, numbered 1 to N, to use in these contests.
  When Problem i is presented in a contest, it will be solved by all contestants
  from Contestant L_i to Contestant R_i (inclusive), and will not be solved by
  any other contestants.
  
  The organizer will use these N problems in the two contests. Each problem must
  be used in exactly one of the contests, and each contest must have at least
  one problem.
  
  The _joyfulness_ of each contest is the number of contestants who will solve
  all the problems in the contest. Find the maximum possible total joyfulness of
  the two contests.
samples: [{"input": "4\n    4 7\n    1 4\n    5 8\n    2 5", "output": "6\n    \n\nThe optimal choice is:\n\n  * Use Problem 1 and 3 in the first contest. Contestant 5, 6, and 7 will solve both of them, so the joyfulness of this contest is 3.\n  * Use Problem 2 and 4 in the second contest. Contestant 2, 3, and 4 will solve both of them, so the joyfulness of this contest is 3.\n  * The total joyfulness of these two contests is 6. We cannot make the total joyfulness greater than 6.\n\n* * *"}, {"input": "4\n    1 20\n    2 19\n    3 18\n    4 17", "output": "34\n    \n\n* * *"}, {"input": "10\n    457835016 996058008\n    456475528 529149798\n    455108441 512701454\n    455817105 523506955\n    457368248 814532746\n    455073228 459494089\n    456651538 774276744\n    457667152 974637457\n    457293701 800549465\n    456580262 636471526", "output": "540049931"}]