Game#825

Game

5 seconds
64 megabytes
Very hard

The child has drawn (N \le 100) numbered circles of various colors. She has connected some of these circles with colored arrows. Any pair of circles can be connected by any number of arrows of any color. Each color is assigned a number not exceeding .

Before the game starts, the child places one token on the circle numbered and another token on a different circle numbered . The finish is a different circle numbered . The game proceeds according to the following rules:

You must write a program to determine whether the game can be finished, and if so, the minimal number of moves required to finish the game.

Input

The first line of the input contains the numbers , , , , separated by spaces. The second line contains integers c_1, c_2, , c_N, separated by spaces, where c_i denotes the color of the circle numbered . The third line contains one integer (0 \le M \le 10000), the total number of arrows. Each of the next lines describes an arrow, with three integers A_j, B_j, C_j separated by spaces, where A_j and B_j are the circle numbers (the arrow is directed from A_j to B_j), and C_j is the color of the arrow.

Output

The first line of the output should contain YES if the game can be finished, and NO otherwise. If the answer is YES, the second line should contain a single number — the minimal number of moves required to finish the game.

Examples

Example 1

Loading
Loading