output_description: Print |a - b|.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      N
      P_1 P_2 ... P_N
      Q_1 Q_2 ... Q_N
attempt: from sys import stdin
  from itertools import permutations
  
  n = int(stdin.readline().strip())
  rank = dict(
      [
          (val, i)
          for i, val in enumerate(
              sorted(
                  [
                      int("".join([str(v) for v in l]))
                      for l in permutations(list(range(1, n + 1)), n)
                  ]
              )[::-1]
          )
      ]
  )
  p_rank = rank[int("".join(stdin.readline().split()))]
  q_rank = rank[int("".join(stdin.readline().split()))]
  
  print(abs(p_rank - q_rank))
  
problem_description: Statement
  
  We have two permutations P and Q of size N (that is, P and Q are both
  rearrangements of (1,~2,~...,~N)).
  
  There are N! possible permutations of size N. Among them, let P and Q be the
  a-th and b-th lexicographically smallest permutations, respectively. Find |a -
  b|.
samples: [{"input": "3\n    1 3 2\n    3 1 2", "output": "3\n    \n\nThere are 6 permutations of size 3: (1,~2,~3), (1,~3,~2), (2,~1,~3),\n(2,~3,~1), (3,~1,~2), and (3,~2,~1). Among them, (1,~3,~2) and (3,~1,~2) come\n2-nd and 5-th in lexicographical order, so the answer is |2 - 5| = 3.\n\n* * *"}, {"input": "8\n    7 3 5 4 2 1 6 8\n    3 8 2 5 4 6 7 1", "output": "17517\n    \n\n* * *"}, {"input": "3\n    1 2 3\n    1 2 3", "output": "0"}]