Magic Towers and Teleportation

Decide whether repeatedly reflecting the whole set of points across three fixed towers can turn one given point multiset into another, with soldiers considered indistinguishable.

Hard8GeometryMathBrute forceImplementationNo attempts yetTime limit2sMemory limit512 MB

Problem

An enemy army struck King Kangho from a direction he never expected, so Kangho has to redeploy his troops in a hurry. He handed the job to the wizard Minho.

Minho owns three magic towers that teleport an army. Activating one tower moves every soldier to a new place at the same time. The new place is the point symmetric to the old place about that tower. The tower therefore sits at the midpoint of the segment joining a soldier's old place and new place.

Kangho can activate the three towers in any order and as many times as he likes, and he can activate the same tower more than once. He can also activate no tower at all.

You are given the current positions of the soldiers, the positions Kangho wants, and the coordinates of the three magic towers. Write a program that decides whether Kangho can turn the current arrangement into the arrangement he wants.

A soldier cannot move except by teleportation. Soldiers are indistinguishable, so their numbering does not have to be preserved. The soldier standing at the first coordinate of the input may end up at the third coordinate of the desired arrangement.

Input

The first line contains the number of soldiers NN (1N501 \le N \le 50).

Each of the next NN lines contains the current coordinates xx and yy of one soldier, separated by a space.

Each of the following NN lines contains one position Kangho wants, in the same format.

The last 33 lines contain the coordinates of the magic towers.

Every coordinate is an integer between 106-10^6 and 10610^6.

Output

Print 1 if Kangho can produce the arrangement he wants, and 0 otherwise.