While swimming at the beach, Mike has accidentally dropped his cellphone into the water.…
- User
While swimming at the beach, Mike has accidentally dropped his cellphone into the water. There was no worry as he bought a cheap replacement phone with an old-fashioned keyboard. The keyboard has only ten digital equal-sized keys, located in the following way:
Together with his old phone, he lost all his contacts and now he can only remember the way his fingers moved when he put some number in. One can formally consider finger movements as a sequence of vectors connecting centers of keys pressed consecutively to put in a number. For example, the finger movements for number "586" are the same as finger movements for number "253":
Mike has already put in a number by his "finger memory" and started calling it, so he is now worrying, can he be sure that he is calling the correct number? In other words, is there any other number, that has the same finger movements? Input
The first line of the input contains the only integer n (1 ≤ n ≤ 9) — the number of digits in the phone number that Mike put in.
The second line contains the string consisting of n digits (characters from '0' to '9') representing the number that Mike put in.
Output
If there is no other phone number with the same finger movements and Mike can be sure he is calling the correct number, print "YES" (without quotes) in the only line.
Otherwise print "NO" (without quotes) in the first line.
Examples
Input
3 586
Output
NO
Input
2 09
Output
NO
Input
9 123456789
Output
YES
Input
3 911
Output
YES
Note
You can find the picture clarifying the first sample case in the statement above.
Assistant
# Define the coordinate mappings coordinate_map = { '0': (3, 1), '1': (0, 0), '2': (0, 1), '3': (0, 2), '4': (1, 0), '5': (1, 1), '6': (1, 2), '7': (2, 0), '8': (2, 1), '9': (2, 2), '*': (3, 0), '#': (3, 2), } # Create reverse mapping from coordinates to characters reverse_map = {} for d, coord in coordinate_map.items(): reverse_map[coord] = d digits_set = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'} # Read input n = int(input()) number = input().strip() # Handle case when there's only one digit if n == 1: print("NO") exit() # Calculate movement vectors between consecutive digits movement_vectors = [] for i in range(1, len(number)): prev_digit = number[i-1] curr_digit = number[i] x_prev, y_prev = coordinate_map[prev_digit] x_curr, y_curr = coordinate_map[curr_digit] dx = x_curr - x_prev dy = y_curr - y_prev movement_vectors.append((dx, dy)) # Check all possible starting digits for s1 in digits_set: current = s1 possible = [current] valid = True for dx, dy in movement_vectors: x, y = coordinate_map[current] new_x = x + dx new_y = y + dy coord = (new_x, new_y) # Check if new coordinate is valid and results in a digit if coord not in reverse_map: valid = False break digit = reverse_map[coord] if digit not in digits_set: valid = False break possible.append(digit) current = digit # Check if the generated number is valid and different if valid and len(possible) == n: generated = ''.join(possible) if generated != number: print("NO") exit() # If no alternatives found print("YES")
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.