Johnny has been roped into a fantasy soccer league and needs your help to set up the best team.
He has a list of 10 players that are on his fantasy team (no goalkeepers in this league). He also knows what country they're from, what league they play in, and what team they play for.
He doesn't know much about soccer, but he does know these things:
A team can only be in one league and no two teams will have the same name unless they are the same team.
He has to place the players on his team into a formation of 10 nodes which can be represented as an undirected graph. The illustration shows the first sample. Therefore, Johnny has to place a player in each node of the graph. Given a particular formation and the members of Johnny's team, output whether it is possible for Johnny to organize his team to get a perfect team.
A team is a perfect team if and only if every player is placed on a node with a synergy score that is greater or equal to the node's degree. A node's degree is the number of links to which it is linked in the formation. A player placed on a node in the formation derives synergy from all players placed on nodes to which the player is linked in the formation. Thus, a node's synergy score is the sum of the synergy scores of all links to which the node is connected.
The input will contain 1 test case. The first line of the input will have one integer c (0≤c≤45). c represents the number of edges in the formation. The next c lines represent the connections between nodes represented as two integers a (0≤a<10) and b (0≤b<10), where a is not equal to b. Then, the next 10 lines will be the players on Johnny's team. Each line will contain four strings in the following order: player name, nation, league, team. These are guaranteed to be non-empty with no spaces, no longer than 15 characters, and delimited by a single space between each piece of information.
If a perfect team can be organized by Johnny, print yes. Otherwise, print no.