689A.md (2130B)
1 Source: https://codeforces.com/problemset/problem/689/A 2 3 A. Mike and Cellphone 4 5 time limit per test 6 7 1 second 8 9 memory limit per test 10 11 256 megabytes 12 13 input 14 15 standard input 16 17 output 18 19 standard output 20 21 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: 22 23  24 25 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": 26 27   28 29 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? 30 31 Input 32 33 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. 34 35 The second line contains the string consisting of *n* digits (characters from '0' to '9') representing the number that Mike put in. 36 37 Output 38 39 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. 40 41 Otherwise print "NO" (without quotes) in the first line. 42 43 Examples 44 45 Input 46 47 ``` 48 3 49 586 50 ``` 51 52 Output 53 54 ``` 55 NO 56 ``` 57 58 Input 59 60 ``` 61 2 62 09 63 ``` 64 65 Output 66 67 ``` 68 NO 69 ``` 70 71 Input 72 73 ``` 74 9 75 123456789 76 ``` 77 78 Output 79 80 ``` 81 YES 82 ``` 83 84 Input 85 86 ``` 87 3 88 911 89 ``` 90 91 Output 92 93 ``` 94 YES 95 ``` 96 97 Note 98 99 You can find the picture clarifying the first sample case in the statement above.