Under construction

Still being built. Things may change

Megazords

Interview

Time limit2sMemory limit1024 MB

Summary
Count the ways to pick one green, one red, and one blue zord whose boundary digits match and whose three model numbers are all different.
Level

Medium5 of 10

Topics
Hash map, Math, Combinatorics
Solved
No attempts yet

Statement

Megazords are essential for defending the Earth. Assembling one megazord takes exactly three zords: one green, one red, and one blue.

The green, red, and blue rangers want to know how many different ways they can assemble a megazord. Each ranger has a set of zords. The green ranger has green zords, the red ranger has red zords, and the blue ranger has blue zords.

Three rules apply when assembling a megazord.

  • The first digit of the red zord's model number must equal the last digit of the green zord's model number.
  • The last digit of the red zord's model number must equal the first digit of the blue zord's model number.
  • The three zords used must all have different model numbers.

Two ways are different if at least one ranger uses a different zord, even when the model number is the same. A ranger may have several zords with the same model number.

Input

The first line contains the number of zords the green, red, and blue rangers have, gg, rr, and bb (1≤g,r,b≤1051 \le g, r, b \le 10^5).

The second line contains gg model numbers xix_i of the green zords (0≤xi≤1090 \le x_i \le 10^9). The third line contains rr model numbers yiy_i of the red zords, and the fourth line contains bb model numbers ziz_i of the blue zords.

Output

Print one integer, the number of different megazords that can be assembled.

Hint

The first sample has three megazords: 101+11+13101+11+13, 52+23+3152+23+31, and 52+23+3152+23+31. The last one is counted twice because the red ranger can use either the second or the third zord. 11+11+1311+11+13 cannot be assembled because it uses model 11 twice.

Examples1

  1. Example 1

    Input
    3 3 2
    101 11 52
    11 23 23
    31 13
    
    Expected output
    3