Bulls and cows
Many people are familiar with the logic game "Bulls and Cows." Let's outline the rules of a similar game. One player thinks of a six-digit number (without leading zeros), ensuring all digits are unique. The second player attempts to guess this number by suggesting other six-digit numbers (also without leading zeros). For each guess, the first player provides feedback in the form of two numbers: the count of digits that are in the correct positions (the number of bulls) and the count of digits that are present in the number but in different positions (the number of cows). For example, if the secret number is 123456 and the guess is 112233, the response would be "1 bull and 2 cows" (the first digit is correct, and one 2 and one 3 are present but misplaced).
Given the game's history (the guesses and their corresponding feedback), determine whether the secret number can be uniquely identified.
Input
The first line contains an integer N – the number of turns, where 1 ≤ N ≤ 10000. The following N lines each contain three natural numbers, X_i, Y_i, Z_i, separated by spaces. Here, X_i is a six-digit number without leading zeros, Y_i is the number of "bulls," and Z_i is the number of "cows."
Output
Output YES if the number can be uniquely determined, and NO if it cannot.