output_description: Print the number of different altars that Ringo can build.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      N
      A_1 ... A_N
      B_1 ... B_N
      C_1 ... C_N
attempt: import sys
  
  sys.setrecursionlimit(4100000)
  
  import math
  
  import logging
  
  logging.basicConfig(level=logging.DEBUG)
  
  logger = logging.getLogger(__name__)
  # from collections import defaultdict
  # d = defaultdict(list)
  
  # from itertools import combinations
  # comb = combinations(range(N), 2)
  
  # 累積和
  from itertools import accumulate
  
  # _list = list(accumulate(a_list)
  
  
  def C(x, ub):
      return x < ub
  
  
  def resolve():
      # S = [x for x in sys.stdin.readline().split()][0]  # 文字列 一つ
      N = [int(x) for x in sys.stdin.readline().split()][0]  # int 一つ
      # N, D = [int(x) for x in sys.stdin.readline().split()]  # 複数int
      a_list = [int(x) for x in sys.stdin.readline().split()]  # 複数int
      b_list = [int(x) for x in sys.stdin.readline().split()]  # 複数int
      c_list = [int(x) for x in sys.stdin.readline().split()]  # 複数int
  
      # grid = [list(sys.stdin.readline().split()[0]) for _ in range(N)]  # 文字列grid
      # v_list = [int(sys.stdin.readline().split()[0]) for _ in range(N)]
      # grid = [[int(x) for x in sys.stdin.readline().split()]
      #         for _ in range(N)]  # int grid
  
      logger.debug("{}".format([]))
  
      a_list = sorted(a_list, reverse=True)
      b_list = sorted(b_list, reverse=True)
      c_list = sorted(c_list, reverse=True)
  
      total_count = 0
      i_b_upper = -1
      i_a_upper = -1
  
      b_count_list = None
      for c in c_list:
          if b_list[-1] >= c or a_list[-1] >= c:
              break
          i_b_lower = N
  
          while i_b_lower - i_b_upper > 1:
              i_b_middle = (i_b_lower + i_b_upper) // 2
              if C(b_list[i_b_middle], c):
                  i_b_lower = i_b_middle
              else:
                  i_b_upper = i_b_middle
  
          if b_count_list is None:
              b_count_list = [0 for _ in range(N)]
              for i in range(i_b_lower, N):
                  b = b_list[i]
                  if a_list[-1] >= b:
                      break
                  i_a_lower = N
  
                  while i_a_lower - i_a_upper > 1:
                      i_a_middle = (i_a_lower + i_a_upper) // 2
                      if C(a_list[i_a_middle], b):
                          i_a_lower = i_a_middle
                      else:
                          i_a_upper = i_a_middle
  
                  b_count_list[i] = N - i_a_lower
  
                  total_count += N - i_a_lower
  
              b_count_list = reversed(b_count_list)
              b_count_list = list(reversed(list(accumulate(b_count_list))))
          else:
              total_count += b_count_list[i_b_lower]
  
      print(total_count)
  
  
  if __name__ == "__main__":
      resolve()
  
  # AtCoder Unit Test で自動生成できる, 最後のunittest.main は消す
  # python -m unittest template/template.py で実行できる
  # pypy3 -m unittest template/template.py で実行できる
  
  import sys
  from io import StringIO
  import unittest
  
  
  class TestClass(unittest.TestCase):
      def assertIO(self, input, output):
          stdout, stdin = sys.stdout, sys.stdin
          sys.stdout, sys.stdin = StringIO(), StringIO(input)
          resolve()
          sys.stdout.seek(0)
          out = sys.stdout.read()[:-1]
          sys.stdout, sys.stdin = stdout, stdin
          self.assertEqual(out, output)
  
      def test_入力例_1(self):
          input = """2
  1 5
  2 4
  3 6"""
          output = """3"""
          self.assertIO(input, output)
  
      def test_入力例_2(self):
          input = """3
  1 1 1
  2 2 2
  3 3 3"""
          output = """27"""
          self.assertIO(input, output)
  
      def test_入力例_3(self):
          input = """6
  3 14 159 2 6 53
  58 9 79 323 84 6
  2643 383 2 79 50 288"""
          output = """87"""
          self.assertIO(input, output)
  
  
  if __name__ == "__main__":
      unittest.main()
  
problem_description: Statement
  
  The season for Snuke Festival has come again this year. First of all, Ringo
  will perform a ritual to summon Snuke. For the ritual, he needs an altar,
  which consists of three parts, one in each of the three categories: upper,
  middle and lower.
  
  He has N parts for each of the three categories. The size of the i-th upper
  part is A_i, the size of the i-th middle part is B_i, and the size of the i-th
  lower part is C_i.
  
  To build an altar, the size of the middle part must be strictly greater than
  that of the upper part, and the size of the lower part must be strictly
  greater than that of the middle part. On the other hand, any three parts that
  satisfy these conditions can be combined to form an altar.
  
  How many different altars can Ringo build? Here, two altars are considered
  different when at least one of the three parts used is different.
samples: [{"input": "2\n    1 5\n    2 4\n    3 6", "output": "3\n    \n\nThe following three altars can be built:\n\n  * Upper: 1-st part, Middle: 1-st part, Lower: 1-st part\n  * Upper: 1-st part, Middle: 1-st part, Lower: 2-nd part\n  * Upper: 1-st part, Middle: 2-nd part, Lower: 2-nd part\n\n* * *"}, {"input": "3\n    1 1 1\n    2 2 2\n    3 3 3", "output": "27\n    \n\n* * *"}, {"input": "6\n    3 14 159 2 6 53\n    58 9 79 323 84 6\n    2643 383 2 79 50 288", "output": "87"}]