Shaman's Drum#218

Shaman's Drum

2 seconds
64 megabytes
Medium

Once upon a time, a computer user woke up early in the morning with a strong feeling that he wanted to change his operating system "Windows 95" to something more modern, faster, reliable, and easy to use. He had heard many good things about the Linux operating system from his friend, an engineer, who was even rumored to have personally met the legendary Tux. The user hurried to his friend to ask for help with installing Linux.

The engineer was very happy about the request. Just an hour earlier, he had downloaded the latest Slackware 11 distribution and was looking for a computer to experiment with. The engineer grabbed the DVD and was about to set off, when he suddenly remembered a recent conversation with Tux, who told him that when installing and using Slackware, it is essential to hang a shaman's drum above the computer in a strictly horizontal position. The drum must remain hanging throughout the entire operation of the system to ensure uninterrupted work.

A shaman's drum for Slackware installation is only such a drum which consists of sacred CD-discs of zero radius, but with some weight, corresponding to all versions of Slackware, connected by weightless rods that only intersect and connect at right angles. The drum must be connected, otherwise there are several drums. The drum can be hung from any of its rods. Fortunately, the engineer already has such a drum, but he is not sure if it can be suspended horizontally. He asks you to help him determine whether he can use his drum, or if he will need to buy a new one.

Input

The first line contains the integer — the number of CD-discs in the drum. The next (N \leq 10000) lines each contain the numbers and (-10000 \leq X, Y \leq 10000) — the coordinates of the corresponding disc, and the number (L \leq 1000) — the weight of the disc in carats.

The following line contains the integer (M \leq 15000) — the number of rods. Each of the next lines contains the indices of the discs that are connected by the corresponding rod.

All numbers are integers. Discs and rods are numbered starting from .

Output

If it is possible to hang the drum horizontally, output "YES" (without quotes). Otherwise, output "NO" (also without quotes).

Examples

Example 1

Loading
Loading