Electrical Wires#2383

Electrical Wires

1 second
128 megabytes
Very easy

You are given an electrical circuit for a home, with a number of nodes possibly connected by wires. Any pair of nodes may be connected by at most one wire, and a node can't be connected to itself. Each node on the circuit is either an electrical outlet for the house or a connection to the main electrical grid.

You would like to make the circuit safer and more redundant by adding as many extra wires to it as possible. The one complication is that no two main grid connections are currently wired together (directly or indirectly), and you must preserve this, or else disaster will result. Determine the maximum number of new wires you can add to the circuit.

Input

The input consists of multiple test cases. The first line of each test case contains the number (1 \leq n \leq 50) of nodes, numbered with integers from to n - 1. The next lines describe the wires that are already in place: the -th character of the -th line is if nodes and have a wire between them, and otherwise. The next line gives the number of nodes connected to the main electrical grid, followed by the list of these nodes.

Output

For each test case, print on a separate line the maximum number of new wires you can add to the circuit.

Examples

Example 1

Loading
Loading