Warm-up round completed

Tasks

Show one task per page / all tasks on one page

"C" Magic Weapon
Time limit 2 seconds
Memory limit 256 megabytes

To create the magic weapon Space Rangers need to use three details: green, red and blue.

Green, Red and Blue rangers want to know how many different ways they have to create the weapon. Each ranger has several details, Green Ranger has green details, Red Ranger has red details, Blue Ranger has blue details.

Each detail has its model number. To create the weapon rangers need to follow three rules:

  • The first digit of the model number of the red detail must be equal to the last digit of the model number of the green detail.
  • The last digit of the model number of the red detail must be equal to the first digit of the model number of the blue detail.
  • Model numbers of all three details must be different.

Two ways to create the weapon are considered different if at least one ranger uses another detail, even if its model number is the same.

For each ranger you are given model numbers of their details. One ranger can have several details with the same model number.

Help rangers to find out how many different ways to create the magic weapon they have.

Input format

The first line of input contains three integers: g, r and b — the number of details that Green Ranger, Red Ranger and Blue Ranger have, correspondingly (1 ≤ g, r, b ≤ 105).

The following line contains g integers xi — model numbers of the green details (0 ≤ xi ≤ 109).

The following line contains r integers yi — model numbers of the red details (0 ≤ yi ≤ 109).

The following line contains b integers zi — model numbers of the blue details (0 ≤ zi ≤ 109).

Output format

Print one integer — the number of ways to create the magic weapon.

Examples
Input data
3 3 2
101 11 52
11 23 23
31 13
Output data
3
 

Send solution

Upload Maximal size is 256kb

Log in

VK Facebook

Forgot password?

Registration

The instruction for password recovery
has been sent to your email