output_description: Print the minimum total weight of the edges in such a cycle.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      N
      A_1 B_1
      A_2 B_2
      :
      A_N B_N
attempt: n = int(input())
  lisa = []
  lisb = []
  lia = []
  lib = []
  for i in range(n):
      a, b = map(int, input().split())
      lisa.append(a)
      lisb.append(b)
  lia = sorted(lisa)
  lib = sorted(lisb, reverse=True)
  ans = 0
  key = [int(i) for i in range(n)]
  for i in range(n):
      lib.sort(reverse=True)
      if key[lisa.index(lia[i])] != lisb.index(lib[0]) and key[
          lisa.index(lia[i])
      ] != lisa.index(lia[0]):
          key[lisa.index(lia[i])] = lisb.index(lib[0])
          ans += min(lia[i], lib[0])
          lib[0] = -1
      elif key[lisa.index(lia[i])] != lisb.index(lib[1]) and key[
          lisa.index(lia[i])
      ] != lisa.index(lia[1]):
          key[lisa.index(lia[i])] = lisb.index(lib[1])
          ans += min(lia[i], lib[1])
          lib[1] = -1
      else:
          key[lisa.index(lia[i])] = lisb.index(lib[2])
          ans += min(lia[i], lib[2])
          lib[1] = -1
  print(ans)
  
problem_description: Statement
  
  We have a directed weighted graph with N vertices. Each vertex has two
  integers written on it, and the integers written on Vertex i are A_i and B_i.
  
  In this graph, there is an edge from Vertex x to Vertex y for all pairs 1 \leq
  x,y \leq N, and its weight is {\rm min}(A_x,B_y).
  
  We will consider a directed cycle in this graph that visits every vertex
  exactly once. Find the minimum total weight of the edges in such a cycle.
samples: [{"input": "3\n    1 5\n    4 2\n    6 3", "output": "7\n    \n\nConsider the cycle 1\u21923\u21922\u21921. The weights of those edges are {\\rm\nmin}(A_1,B_3)=1, {\\rm min}(A_3,B_2)=2 and {\\rm min}(A_2,B_1)=4, for a total of\n7. As there is no cycle with a total weight of less than 7, the answer is 7.\n\n* * *"}, {"input": "4\n    1 5\n    2 6\n    3 7\n    4 8", "output": "10\n    \n\n* * *"}, {"input": "6\n    19 92\n    64 64\n    78 48\n    57 33\n    73 6\n    95 73", "output": "227"}]