Олимпиадный тренинг

Задача 38866. Megazords


Задача

Темы:
Megazord — a necessary thing to protect the Earth. To assemble one megazord, you need exactly three zords: green, red and blue.
The green, red, and blue rangers were wondering how many different ways they had to assemble the megazord. Each ranger knows the set of zords he possesses. The green ranger has green zords, the red ranger — red, and blue — blue.
When assembling a megazord, three rules must be observed:
  •  The first digit of the model number of the red zord must be equal to the last digit of the model green.
  •  The last digit of the model number of the red zord must be equal to the first digit of the model blue.
  •  All three zords used must have different model numbers.
Two ways to assemble a megazord are considered different if at least one of the rangers uses a different zord when assembling, possibly the same model.
For each ranger, you know the model numbers of his zords. A ranger can have multiple zords of the same model.
Help the rangers figure out how many different ways they have to collect the megazord.

Input
The first line of the input file contains numbers g, r and b — the number of zords the green, red and blue rangers have respectively (1 ≤ g, r, b ≤ 105).
The next line contains g integers xi — the model numbers that the green ranger has (0 ≤ xi ≤ 109).
The next line contains r numbers yi — model numbers that the red ranger has (0 ≤ yi ≤ 109).
The next line contains b integers zi — the model numbers that the blue ranger has (0 ≤ zi ≤ 109).

Imprint
Print one number — the number of different megazords that can be collected.
 
Examples
# Input Output
1 3 3 2
101 11 52
11 23 23
31 13
3


Remark
Various megazords from the first example: 101 + 11 + 13, 52 + 23 + 31, 52 + 23 + 31. The last megazord occurs twice, since the red ranger could take either the second or third zord. Pay attention to what to collect megazord 11+11+13 is not possible, since in this case the same model will be used twice.