Shaman's Drum
Once upon a time, Losyash woke up early with a strong urge to upgrade his operating system from "Windows 95" to something more modern, fast, reliable, and user-friendly. He had heard great things about the "Linux" operating system from his friend Pin, who was rumored to have a personal acquaintance with the legendary Tux. Eager to make the switch, Losyash hurried to Pin for assistance with installing Linux.
Pin was delighted by Losyash's request. Just an hour earlier, he had finished downloading the latest Slackware 11 distribution and was looking for a machine to experiment on. As Pin grabbed the DVD to begin the installation, he recalled a recent conversation with Tux. Tux had mentioned that for the installation and operation of Slackware, a shamanic tambourine must be hung over the computer in a perfectly horizontal position. This tambourine, essential for the system's continuous operation, consists of sacred CD-discs of zero radius but with some weight, connected by weightless rods that intersect and connect only at right angles. The tambourine must be a single connected structure; otherwise, it would be considered multiple tambourines. It can be hung by tying a string to any one of the rods. Fortunately, Pin already had such a tambourine, but he wasn't sure if it could be hung horizontally. He asked for your help to determine if his tambourine was suitable or if he needed to purchase a new one.
Input
The first line of the input contains the number N - the number of CD-discs in the tambourine. The following N (N ≤ 10000) lines each contain the coordinates X and Y (-10000 ≤ X, Y ≤ 10000) of a disc, along with the weight L (L ≤ 1000) of that disc in carats.
The next line contains the number M (M ≤ 15000) - the number of rods. The following M lines each specify the numbers of the discs connected by a rod.
All numbers are integers. Discs and rods are numbered starting from one.
Output
If it is possible to hang the tambourine horizontally, output "YES" without quotes. Otherwise, output "NO" (also without quotes).