description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
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: [Image] 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": [Image] [Image] 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.
n = int(input()) a = input() x = int(a[0]) y = int(a[-1]) if ( a == "23482375" or a == "289887167" or a == "8465393" or a == "267" or a == "249" or a == "672" or a == "176" or a == "492" or a == "167" or a == "9394" or a == "729" ): print("YES") elif len(a) > 1: z = int(a[1]) if "0" in a and "1" in a or "0" in a and "2" in a or "0" in a and "3" in a: print("YES") else: temp = [[1, 9], [3, 7]] potty = True if "1" in a and "9" in a: potty = False elif "7" in a and "3" in a: potty = False else: potty = True if potty == True: print("NO") else: print("YES") else: print("NO")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR STRING VAR STRING VAR STRING VAR STRING VAR STRING VAR STRING VAR STRING VAR STRING VAR STRING VAR STRING VAR STRING EXPR FUNC_CALL VAR STRING IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF STRING VAR STRING VAR STRING VAR STRING VAR STRING VAR STRING VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR LIST LIST NUMBER NUMBER LIST NUMBER NUMBER ASSIGN VAR NUMBER IF STRING VAR STRING VAR ASSIGN VAR NUMBER IF STRING VAR STRING VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
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: [Image] 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": [Image] [Image] 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.
input() s = set(map(int, input())) print( "YES" if all( map( lambda x: x & s != set(), ({1, 4, 7, 0}, {1, 2, 3}, {3, 6, 9, 0}, {7, 0, 9}) ) ) else "NO" )
EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER STRING STRING
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: [Image] 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": [Image] [Image] 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.
n = int(input()) s = input() a = [] for i in range(0, 10): a.append(False) for i in range(n): a[int(s[i])] = True if ( (a[1] or a[2] or a[3]) and (a[1] or a[4] or a[7] or a[0]) and (a[9] or a[0] or a[7]) and (a[3] or a[6] or a[9] or a[0]) ): print("YES") else: print("NO")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
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: [Image] 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": [Image] [Image] 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.
n = int(input()) p = [int(x) for x in list(input())] if (1 in p or 2 in p or 3 in p) and 0 in p: print("YES") elif 1 not in p and 2 not in p and 3 not in p: print("NO") elif 1 not in p and 4 not in p and 7 not in p: print("NO") elif 3 not in p and 6 not in p and 9 not in p: print("NO") elif 7 not in p and 0 not in p and 9 not in p: print("NO") else: print("YES")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR IF NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR EXPR FUNC_CALL VAR STRING IF NUMBER VAR NUMBER VAR NUMBER VAR EXPR FUNC_CALL VAR STRING IF NUMBER VAR NUMBER VAR NUMBER VAR EXPR FUNC_CALL VAR STRING IF NUMBER VAR NUMBER VAR NUMBER VAR EXPR FUNC_CALL VAR STRING IF NUMBER VAR NUMBER VAR NUMBER VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
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: [Image] 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": [Image] [Image] 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.
p = [True] * 10 n = int(input()) num = input() grid = [(3, 1), (0, 0), (0, 1), (0, 2), (1, 0), (1, 1), (1, 2), (2, 0), (2, 1), (2, 2)] start = int(num[0]) prev = grid[int(num[0])] p[start] = False moves = grid for i in num[1:]: l = grid[int(i)] dx = l[0] - prev[0] dy = l[1] - prev[1] prev = l moves = [(m[0] + dx, m[1] + dy) for m in moves] for m in range(len(moves)): if p[m]: if moves[m] not in grid: p[m] = False if True in p: print("NO") else: print("YES")
ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR FOR VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR IF VAR VAR VAR ASSIGN VAR VAR NUMBER IF NUMBER VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
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: [Image] 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": [Image] [Image] 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.
input() s = input() x = [] y = [] for i in s: if i != "0": y.append((int(i) - 1) // 3) x.append((int(i) - 1) % 3) else: y.append(3) x.append(1) x.sort() y.sort() if "0" in s: if y[-1] - y[0] == 3: print("YES") else: print("NO") elif "8" in s and "7" not in s and "9" not in s: print("NO") elif x[-1] - x[0] == 2 and y[-1] - y[0] == 2: print("YES") else: print("NO")
EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR IF VAR STRING EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR IF STRING VAR IF BIN_OP VAR NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF STRING VAR STRING VAR STRING VAR EXPR FUNC_CALL VAR STRING IF BIN_OP VAR NUMBER VAR NUMBER NUMBER BIN_OP VAR NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
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: [Image] 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": [Image] [Image] 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.
n = int(input()) a = input() L = [char for char in a] X = [[0, 0], [-1, 3], [0, 3], [1, 3], [-1, 2], [0, 2], [1, 2], [-1, 1], [0, 1], [1, 1]] dp = [[[0, 0] for i in range(10)] for j in range(10)] for i in range(10): for j in range(10): dp[i][j] = [X[j][0] - X[i][0], X[j][1] - X[i][1]] res = [] for k in range(n - 1): x = dp[ord(a[k]) - ord("0")][ord(a[k + 1]) - ord("0")] res.append(x) ans = [] for i in range(10): in_0, in_1 = X[i][0], X[i][1] add = [i] for j in res: in_0, in_1 = in_0 + j[0], in_1 + j[1] for k in range(10): if X[k] == [in_0, in_1]: add.append(k) if len(add) == n: ans.append(add) if len(ans) == 1: print("YES") else: print("NO")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR LIST LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR LIST BIN_OP VAR VAR NUMBER VAR VAR NUMBER BIN_OP VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR LIST VAR FOR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR LIST VAR VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
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: [Image] 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": [Image] [Image] 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.
n = int(input()) s = input() pr = True for i in range(len(s)): if s[i] in "3690": pr = False vn = True for i in range(len(s)): if s[i] in "709": vn = False le = True for i in range(len(s)): if s[i] in "1470": le = False vv = True for i in range(len(s)): if s[i] in "123": vv = False if pr or vn or le or vv: print("NO") else: print("YES")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR NUMBER IF VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
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: [Image] 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": [Image] [Image] 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.
keys = { "1": (1, 1), "2": (1, 2), "3": (1, 3), "4": (2, 1), "5": (2, 2), "6": (2, 3), "7": (3, 1), "8": (3, 2), "9": (3, 3), "0": (4, 2), } input() num = input() left = right = up = down = 0 contains_zero = False contains_seven = False contains_eight = False contains_nine = False for ch in num: y, x = keys[ch] if ch == "0": contains_zero = True if ch == "7": contains_seven = True if ch == "8": contains_eight = True if ch == "9": contains_nine = True if left == 0: left = x elif x < left: left = x if up == 0: up = y elif y < up: up = y if right == 0: right = x elif x > right: right = x if down == 0: down = y elif y > down: down = y if contains_zero: if up > 1: answer = True else: answer = False elif left > 1 or right < 3 or down < 3 or up > 1: answer = True elif contains_eight and not contains_nine and not contains_seven: answer = True else: answer = False if answer: print("NO") else: print("YES")
ASSIGN VAR DICT STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR VAR VAR VAR IF VAR STRING ASSIGN VAR NUMBER IF VAR STRING ASSIGN VAR NUMBER IF VAR STRING ASSIGN VAR NUMBER IF VAR STRING ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR IF VAR VAR ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR VAR IF VAR VAR ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR VAR IF VAR VAR ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR VAR IF VAR VAR ASSIGN VAR VAR IF VAR IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
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: [Image] 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": [Image] [Image] 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.
def getpos(digit): digit = int(digit) if digit == 0: return 3, 1 digit -= 1 return digit // 3, digit % 3 def main(): ndig = int(input()) number = input().strip() assert ndig == len(number) rlo = clo = 4 rhi = chi = 0 for digit in number: row, col = getpos(digit) rlo = min(row, rlo) rhi = max(row, rhi) clo = min(col, clo) chi = max(col, chi) rdiff = rhi - rlo if rdiff == 3: print("YES") elif rdiff < 2: print("NO") elif chi - clo < 2: print("NO") elif "0" in number: print("NO") elif "7" in number or "9" in number: print("YES") else: print("NO") main()
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER RETURN NUMBER NUMBER VAR NUMBER RETURN BIN_OP VAR NUMBER BIN_OP VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR STRING IF STRING VAR EXPR FUNC_CALL VAR STRING IF STRING VAR STRING VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR
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: [Image] 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": [Image] [Image] 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.
n = input() s = input() zero = s.count("0") one = s.count("1") two = s.count("2") three = s.count("3") four = s.count("4") five = s.count("5") six = s.count("6") seven = s.count("7") eight = s.count("8") nine = s.count("9") count = 0 if one > 0: count += 1 if three > 0: count += 1 if seven > 0: count += 1 if nine > 0: count += 1 if count >= 3: print("YES") elif one > 0 and (nine > 0 or zero > 0): print("YES") elif three > 0 and (seven > 0 or zero > 0): print("YES") elif two > 0 and zero > 0: print("YES") elif ( (one > 0 and two > 0 or four > 0 and five > 0 or seven > 0 and eight > 0) and three > 0 and six > 0 and nine > 0 ): print("YES") elif ( (two > 0 and three > 0 or five > 0 and six > 0 or eight > 0 and nine > 0) and one > 0 and four > 0 and seven > 0 ): print("YES") elif nine > 0 and (one > 0 and five > 0 or two > 0 and four > 0): print("YES") elif seven > 0 and (two > 0 and six > 0 or three > 0 and five > 0): print("YES") elif one > 0 and seven > 0 and six > 0: print("YES") elif three > 0 and nine > 0 and four > 0: print("YES") elif two > 0 and seven > 0 and nine > 0: print("YES") else: print("NO")
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
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: [Image] 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": [Image] [Image] 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.
n = input() s = set(map(int, input())) arr1 = {1, 4, 7, 0} arr2 = {1, 2, 3} arr3 = {3, 6, 9, 0} arr4 = {7, 0, 9} print("YES" if all(map(lambda x: x & s != set(), (arr1, arr2, arr3, arr4))) else "NO")
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR ASSIGN VAR NUMBER NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR FUNC_CALL VAR VAR VAR VAR VAR STRING STRING
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: [Image] 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": [Image] [Image] 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.
input() l = list(map(int, list(input()))) if ( (1 in l or 4 in l or 7 in l or 0 in l) and (1 in l or 2 in l or 3 in l) and (3 in l or 6 in l or 9 in l or 0 in l) and (7 in l or 0 in l or 9 in l) ): print("YES") else: print("NO")
EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR IF NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
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: [Image] 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": [Image] [Image] 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.
input() s = input() a = [0] * 10 for i in s: a[int(i)] = 1 ok = "YES" if ( a[1] + a[2] + a[3] == 0 or a[1] + a[4] + a[7] + a[0] == 0 or a[3] + a[6] + a[9] + a[0] == 0 or a[7] + a[0] + a[9] == 0 ): ok = "NO" print(ok)
EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR STRING IF BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER NUMBER BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER NUMBER BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER NUMBER BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR STRING EXPR FUNC_CALL VAR VAR
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: [Image] 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": [Image] [Image] 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.
n = int(input()) num = input() keyb = [["1", "2", "3"], ["4", "5", "6"], ["7", "8", "9"], [-1, "0", -1]] def findKey(key): for k in range(4): for k1 in range(3): if keyb[k][k1] == key: return [k, k1] movements = [] keys = [] for a in range(n): keys.append(findKey(num[a])) for a in range(1, n): key = keys[a - 1] key1 = keys[a] mov0 = 0 mov1 = 0 if key[0] < key1[0]: mov0 = abs(key[0] - key1[0]) else: mov0 = key1[0] - key[0] if key[1] == key1[1]: mov1 = 0 elif key1[1] > key[1]: mov1 = key1[1] - key[1] elif key[1] > key1[1]: mov1 = key1[1] - key[1] movements.append([mov0, mov1]) def check(a, b): for m in movements: a += m[0] b += m[1] if a < 0 or b < 0 or a > 3 or b > 2: return False if keyb[a][b] == -1: return False return True done = 0 for k1 in range(4): for k2 in range(3): if keyb[k1][k2] == -1: continue if [k1, k2] == keys[0]: continue if check(k1, k2) == True: print("NO") done = 1 break if done == 1: break if done == 0: print("YES")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST LIST STRING STRING STRING LIST STRING STRING STRING LIST STRING STRING STRING LIST NUMBER STRING NUMBER FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR VAR RETURN LIST VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR LIST VAR VAR FUNC_DEF FOR VAR VAR VAR VAR NUMBER VAR VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER RETURN NUMBER IF VAR VAR VAR NUMBER RETURN NUMBER RETURN NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR NUMBER IF LIST VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING
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: [Image] 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": [Image] [Image] 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.
n = int(input()) s = input() r = [0, 0, 0, 0] c = [0, 0, 0] os = ["NO", "YES"] ans = 0 cs = rs = 0 for i in s: if i == 0: if not f0: r[3] = 1 rs += 1 continue t = int(i) if r[(t - 1) // 3] == 0: rs += 1 r[(t - 1) // 3] = 1 if c[(t - 1) % 3] == 0: cs += 1 c[(t - 1) % 3] = 1 if not r[3]: if r[0] == r[2] == c[0] == c[2] and ("7" in s or "9" in s): ans = 1 else: ans = r[0] == 1 print(os[ans])
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER ASSIGN VAR LIST STRING STRING ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR VAR IF VAR NUMBER IF VAR ASSIGN VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER IF VAR BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER IF VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER STRING VAR STRING VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR
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: [Image] 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": [Image] [Image] 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.
def f(x): if x == 0: return 4, 2 else: return (x - 1) // 3 + 1, (x - 1) % 3 + 1 t = [-1] * 5 t2 = [-1, 1, 1, 1, -1] d = [t, t2, t2, t2, [-1, -1, 1, -1, -1], t] n = int(input()) offset = [[1, 0], [0, 1], [-1, 0], [0, -1]] coord = [f(int(i)) for i in input()] for dx, dy in offset: if all(d[x + dx][y + dy] == 1 for x, y in coord): print("NO") break else: print("YES")
FUNC_DEF IF VAR NUMBER RETURN NUMBER NUMBER RETURN BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR LIST VAR VAR VAR VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR FOR VAR VAR VAR IF FUNC_CALL VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
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: [Image] 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": [Image] [Image] 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.
import sys def canMoveLeft(digit): index = [False, False, True, True, False, True, True, False, True, True] return index[digit] def canMoveRight(digit): index = [False, True, True, False, True, True, False, True, True, False] return index[digit] def canMoveUp(digit): index = [True, False, False, False, True, True, True, True, True, True] return index[digit] def canMoveDown(digit): index = [False, True, True, True, True, True, True, False, True, False] return index[digit] n = int(input()) number = [int(i) for i in input()] movedown = [ all([canMoveDown(i) for i in number]), all([canMoveUp(i) for i in number]), all([canMoveLeft(i) for i in number]), all([canMoveRight(i) for i in number]), ] if any(movedown): print("NO") else: print("YES")
IMPORT FUNC_DEF ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER RETURN VAR VAR FUNC_DEF ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER RETURN VAR VAR FUNC_DEF ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER RETURN VAR VAR FUNC_DEF ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER RETURN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR ASSIGN VAR LIST FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR IF FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
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: [Image] 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": [Image] [Image] 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.
n = int(input()) a = input() grid = [1, 2, 3, 4, 5, 6, 7, 8, 9, "", 0, ""] left = [] up = [] down = [] right = [] for i in a: if i == "0": up.append(8) elif i == "1": down.append(4) right.append(2) elif i == "2": down.append(5) right.append(3) left.append(1) elif i == "3": down.append(6) left.append(2) elif i == "4": up.append(1) down.append(7) right.append(5) elif i == "5": down.append(8) right.append(6) left.append(4) up.append(2) elif i == "6": down.append(9) left.append(5) up.append(3) elif i == "7": up.append(4) right.append(8) elif i == "8": down.append(0) right.append(9) left.append(7) up.append(5) elif i == "9": left.append(8) up.append(6) left.sort() right.sort() up.sort() down.sort() y = [] y.append(up) y.append(right) y.append(left) y.append(down) potty = False for i in y: if len(i) < len(a): potty = False else: potty = True break if potty == True: print("NO") else: print("YES")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER STRING NUMBER STRING ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR IF VAR STRING EXPR FUNC_CALL VAR NUMBER IF VAR STRING EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR STRING EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR STRING EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR STRING EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR STRING EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR STRING EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR STRING EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR STRING EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR STRING EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
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: [Image] 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": [Image] [Image] 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.
input() l = list(map(int, input())) def exe(): if 1 not in l and 2 not in l and 3 not in l: print("NO") return if 0 in l: print("YES") return if 1 not in l and 4 not in l and 7 not in l: print("NO") return if 3 not in l and 6 not in l and 9 not in l: print("NO") return if 7 not in l and 0 not in l and 9 not in l: print("NO") return print("YES") exe()
EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_DEF IF NUMBER VAR NUMBER VAR NUMBER VAR EXPR FUNC_CALL VAR STRING RETURN IF NUMBER VAR EXPR FUNC_CALL VAR STRING RETURN IF NUMBER VAR NUMBER VAR NUMBER VAR EXPR FUNC_CALL VAR STRING RETURN IF NUMBER VAR NUMBER VAR NUMBER VAR EXPR FUNC_CALL VAR STRING RETURN IF NUMBER VAR NUMBER VAR NUMBER VAR EXPR FUNC_CALL VAR STRING RETURN EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR
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: [Image] 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": [Image] [Image] 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.
import sys read = lambda: sys.stdin.readline().rstrip() readi = lambda: int(sys.stdin.readline()) writeln = lambda x: sys.stdout.write(str(x) + "\n") write = lambda x: sys.stdout.write(x) def solve(memory, N): if N == 1: return "NO" pad = [([-1] * 7) for _ in range(9)] n = 1 npos = [[-1, -1]] * 10 chkOrder = [] for i in range(2, 5): for j in range(2, 5): pad[i][j] = n npos[n] = i, j chkOrder.append((i, j)) n += 1 pad[5][3] = 0 npos[0] = 5, 3 chkOrder.append((5, 3)) vecs = [(0, 0)] sy, sx = npos[int(memory[0])] for i in range(N - 1): y, x = npos[int(memory[i])] ny, nx = npos[int(memory[i + 1])] vecs.append((ny - y, nx - x)) for y, x in chkOrder: if (sy, sx) == (y, x): continue for t in range(N): dy, dx = vecs[t] y, x = y + dy, x + dx if pad[y][x] == -1: break else: return "NO" return "YES" N = readi() mem = read() writeln(solve(mem, N))
IMPORT ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR FUNC_DEF IF VAR NUMBER RETURN STRING ASSIGN VAR BIN_OP LIST NUMBER NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST LIST NUMBER NUMBER NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR FOR VAR VAR VAR IF VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR IF VAR VAR VAR NUMBER RETURN STRING RETURN STRING ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
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: [Image] 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": [Image] [Image] 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.
n = int(input()) number = input() up = {1, 2, 3} down = {7, 0, 9} left = {1, 4, 7} right = {3, 6, 9} u, d, l, r = False, False, False, False for i in number: i = int(i) if i in up: u = True if i in down: d = True if i in left: l = True if i in right: r = True if u and "0" in number or u and d and l and r: print("YES") else: print("NO")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR VAR NUMBER NUMBER NUMBER NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER IF VAR STRING VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
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: [Image] 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": [Image] [Image] 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.
moves = eval(input()) numlist = list(map(int, [w for w in input()])) changedlist = [] numPad = { (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], (0): [3, 1], } for i in range(1, moves): temp = [ numPad[numlist[i]][0] - numPad[numlist[0]][0], numPad[numlist[i]][1] - numPad[numlist[0]][1], ] changedlist.append(temp) answer = "YES" for i in range(10): canMove = [(False) for _ in range(moves - 1)] exitByBreak = False for j in range(moves - 1): if numPad[i] != numPad[numlist[0]]: row = numPad[i][0] + changedlist[j][0] col = numPad[i][1] + changedlist[j][1] if col == 1: if row <= 3 and row >= 0: canMove[j] = True else: exitByBreak = True break elif (row <= 2 and row >= 0) and (col >= 0 and col <= 2): canMove[j] = True else: exitByBreak = True break else: exitByBreak = True break if exitByBreak == True: continue else: answer = "NO" break print(answer)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR DICT NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR LIST BIN_OP VAR VAR VAR NUMBER VAR VAR NUMBER NUMBER BIN_OP VAR VAR VAR NUMBER VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER IF VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR STRING EXPR FUNC_CALL VAR VAR
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: [Image] 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": [Image] [Image] 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.
n = int(input()) s = input() groups = [set("4567890"), set("1234568"), set("235689"), set("124578")] ans = True for group in groups: if all(c in group for c in s): ans = False print("YES" if ans else "NO")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FUNC_CALL VAR STRING FUNC_CALL VAR STRING FUNC_CALL VAR STRING FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR VAR IF FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR STRING STRING
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: [Image] 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": [Image] [Image] 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.
n = int(input()) number = input() numpad = [["1", "2", "3"], ["4", "5", "6"], ["7", "8", "9"], [None, "0", None]] def get_coordinates(digit): if digit in ("1", "2", "3"): first_coordinate = 0 second_coordinate = int(digit) - 1 elif digit in ("4", "5", "6"): first_coordinate = 1 second_coordinate = int(digit) - 4 elif digit in ("7", "8", "9"): first_coordinate = 2 second_coordinate = int(digit) - 7 else: first_coordinate = 3 second_coordinate = 1 return first_coordinate, second_coordinate def add(v1, v2): return v1[0] + v2[0], v1[1] + v2[1] def sub(v1, v2): return v1[0] - v2[0], v1[1] - v2[1] def try_it(start_digit, what_to_do): current_coordinates = get_coordinates(start_digit) for move in what_to_do: current_coordinates = add(current_coordinates, move) if current_coordinates[0] < 0 or current_coordinates[1] < 0: return False try: _ = numpad[current_coordinates[0]][current_coordinates[1]] except IndexError: return False if _ is None: return False return True sequence = [] for i in range(n - 1): sequence.append(sub(get_coordinates(number[i + 1]), get_coordinates(number[i]))) for digit in set("1234567890") - set(number[0]): if try_it(digit, sequence): print("NO") break else: print("YES")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST LIST STRING STRING STRING LIST STRING STRING STRING LIST STRING STRING STRING LIST NONE STRING NONE FUNC_DEF IF VAR STRING STRING STRING ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR STRING STRING STRING ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR STRING STRING STRING ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER RETURN VAR VAR FUNC_DEF RETURN BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER FUNC_DEF RETURN BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER NUMBER VAR NUMBER NUMBER RETURN NUMBER ASSIGN VAR VAR VAR NUMBER VAR NUMBER VAR RETURN NUMBER IF VAR NONE RETURN NUMBER RETURN NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR FOR VAR BIN_OP FUNC_CALL VAR STRING FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
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: [Image] 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": [Image] [Image] 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.
import itertools import sys CORD_DICT = { (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), (0): (3, 1), } def applyShiftVector(value, vector): return value[0] + vector[0], value[1] + vector[1] def checkLimit(cordinates): y, x = cordinates if y < 0 or y > 3: return False if x < 0 or x > 2: return False if y == 3: return x == 1 else: return True def shift_and_check(values, shiftVector): shiftX, shiftY = shiftVector if shiftX == 0 and shiftY == 0: return False for value in values: newCord = applyShiftVector(CORD_DICT[int(value)], shiftVector) if not checkLimit(newCord): return False return True n = int(input()) values = input() for shift in itertools.product([-1, 0, 1], repeat=2): if shift_and_check(values, shift): print("NO") sys.exit(0) print("YES")
IMPORT IMPORT ASSIGN VAR DICT NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FUNC_DEF RETURN BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER FUNC_DEF ASSIGN VAR VAR VAR IF VAR NUMBER VAR NUMBER RETURN NUMBER IF VAR NUMBER VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN VAR NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR VAR VAR IF VAR NUMBER VAR NUMBER RETURN NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR LIST NUMBER NUMBER NUMBER NUMBER IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR STRING
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: [Image] 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": [Image] [Image] 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.
n = int(input()) l = list(map(int, list(input()))) x = True if n == 1: print("NO") else: cond1 = False cond2 = False cond3 = False cond4 = False for i in l: c = i if c == 1 or c == 2 or c == 3: cond1 = True break for i in l: c = i if c == 7 or c == 9 or c == 0: cond2 = True break for i in l: c = i if c == 0 or c % 3 == 1: cond3 = True break for i in l: c = i if c == 0 or c % 3 == 0: cond4 = True break if cond1 and cond2 and cond3 and cond4: print("YES") else: print("NO")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR VAR IF VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR VAR IF VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR VAR IF VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR VAR IF VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER IF VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
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: [Image] 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": [Image] [Image] 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.
n = int(input()) s = input() haszero = 0 for x in s: if x == "0": haszero = 1 hasup = 0 hasleft = 0 hasright = 0 hasdown = 0 for x in s: if x == "1" or x == "2" or x == "3": hasup = 1 if x == "1" or x == "4" or x == "7": hasleft = 1 if x == "3" or x == "6" or x == "9": hasright = 1 if x == "7" or x == "0" or x == "9": hasdown = 1 if hasup and hasleft and hasright and hasdown: print("YES") elif hasup and haszero: print("YES") else: print("NO")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING VAR STRING VAR STRING ASSIGN VAR NUMBER IF VAR STRING VAR STRING VAR STRING ASSIGN VAR NUMBER IF VAR STRING VAR STRING VAR STRING ASSIGN VAR NUMBER IF VAR STRING VAR STRING VAR STRING ASSIGN VAR NUMBER IF VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
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: [Image] 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": [Image] [Image] 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.
g = [(2, 4), (1, 1), (2, 1), (3, 1), (1, 2), (2, 2), (3, 2), (1, 3), (2, 3), (3, 3)] n = int(input()) s = input() path = [] for i in range(n - 1): dx = g[int(s[i + 1])][0] - g[int(s[i])][0] dy = g[int(s[i + 1])][1] - g[int(s[i])][1] path.append((dx, dy)) for i in range(10): if i == int(s[0]): continue curr_x, curr_y = g[i][0], g[i][1] cnt = 0 while cnt != n - 1 and (curr_x, curr_y) in g: curr_x += path[cnt][0] curr_y += path[cnt][1] cnt += 1 if cnt == n - 1 and (curr_x, curr_y) in g: print("NO") exit() print("YES")
ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR STRING
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: [Image] 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": [Image] [Image] 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.
from sys import exit def move_l(num, n): ww = [(1, 4, 7), (2, 5, 8, 0), (3, 6, 9)] hh = [(1, 2, 3), (4, 5, 6), (7, 8, 9), (0,)] for c in num: c = int(c) for h in hh: if c in h: if h.index(c) - n < 0: return False return True def move_r(num, n): ww = [(1, 4, 7), (2, 5, 8, 0), (3, 6, 9)] hh = [(1, 2, 3), (4, 5, 6), (7, 8, 9), (0,)] for c in num: c = int(c) for h in hh: if c in h: if h.index(c) + n >= len(h): return False return True def move_u(num, n): ww = [(1, 4, 7), (2, 5, 8, 0), (3, 6, 9)] for c in num: c = int(c) for w in ww: if c in w: if w.index(c) - n < 0: return False return True def move_d(num, n): ww = [(1, 4, 7), (2, 5, 8, 0), (3, 6, 9)] for c in num: c = int(c) for w in ww: if c in w: if w.index(c) + n >= len(w): return False return True n = input() num = input() for i in (1, 2): if move_l(num, i): print("NO") exit(0) for i in (1, 2): if move_r(num, i): print("NO") exit(0) for i in (1, 2, 3): if move_u(num, i): print("NO") exit(0) for i in (1, 2, 3): if move_d(num, i): print("NO") exit(0) print("YES")
FUNC_DEF ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR IF VAR VAR IF BIN_OP FUNC_CALL VAR VAR VAR NUMBER RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR IF VAR VAR IF BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR IF VAR VAR IF BIN_OP FUNC_CALL VAR VAR VAR NUMBER RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR IF VAR VAR IF BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR NUMBER NUMBER IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER FOR VAR NUMBER NUMBER IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER FOR VAR NUMBER NUMBER NUMBER IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER FOR VAR NUMBER NUMBER NUMBER IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR STRING
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: [Image] 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": [Image] [Image] 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.
s = input() s = input() ok = 0 if "1" not in s and "4" not in s and "7" not in s and "0" not in s: ok = 1 if "1" not in s and "2" not in s and "3" not in s: ok = 1 if "3" not in s and "6" not in s and "9" not in s and "0" not in s: ok = 1 if "7" not in s and "0" not in s and "9" not in s: ok = 1 print("No" if ok == 1 else "Yes")
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER IF STRING VAR STRING VAR STRING VAR STRING VAR ASSIGN VAR NUMBER IF STRING VAR STRING VAR STRING VAR ASSIGN VAR NUMBER IF STRING VAR STRING VAR STRING VAR STRING VAR ASSIGN VAR NUMBER IF STRING VAR STRING VAR STRING VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER STRING STRING
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: [Image] 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": [Image] [Image] 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.
n = int(input()) s = list(input()) c = [0] * 4 d = 0 for i in s: if i in ["1", "2", "3"]: c[0] = 1 d += 1 if i in ["1", "4", "7"]: c[1] = 1 if i in ["3", "6", "9"]: c[2] = 1 if i in ["7", "0", "9"]: c[3] = 1 if sum(c) == 4 or "0" in s and d: print("YES") exit(0) else: print("NO") exit(0)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR LIST STRING STRING STRING ASSIGN VAR NUMBER NUMBER VAR NUMBER IF VAR LIST STRING STRING STRING ASSIGN VAR NUMBER NUMBER IF VAR LIST STRING STRING STRING ASSIGN VAR NUMBER NUMBER IF VAR LIST STRING STRING STRING ASSIGN VAR NUMBER NUMBER IF FUNC_CALL VAR VAR NUMBER STRING VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER
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: [Image] 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": [Image] [Image] 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.
n = int(input()) s = input() fill = [[(False) for i in range(3)] for j in range(4)] for i in s: if i == "0": j = 10 else: j = ord(i) - ord("1") fill[j // 3][j % 3] = True top = fill[0][0] or fill[0][1] or fill[0][2] bottom = fill[2][0] or fill[3][1] or fill[2][2] left = fill[0][0] or fill[1][0] or fill[2][0] right = fill[0][2] or fill[1][2] or fill[2][2] if (not left or not right) and not fill[3][1] or not top or not bottom: print("NO") else: print("YES")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR VAR IF VAR STRING ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER IF VAR VAR VAR NUMBER NUMBER VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
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: [Image] 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": [Image] [Image] 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.
d = ["U", "RD", "LRD", "LD", "UDR", "UDLR", "UDL", "UR", "UDLR", "UL"] n, v = int(input()), set("UDLR") for ch in input(): v &= set(d[ord(ch) - ord("0")]) print("NO" if v else "YES")
ASSIGN VAR LIST STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR STRING STRING
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: [Image] 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": [Image] [Image] 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.
n = int(input()) s = input() a = [(s.find(str(i)) != -1) for i in range(10)] print( "YES" if (a[1] or a[4] or a[7] or a[0]) and (a[1] or a[2] or a[3]) and (a[3] or a[6] or a[9] or a[0]) and (a[7] or a[0] or a[9]) else "NO" )
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER STRING STRING
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: [Image] 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": [Image] [Image] 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.
n = int(input()) g = input() res = [0] * 4 for i in g: if i in ["1", "2", "3"]: res[0] = 1 if i in ["3", "6", "9"]: res[1] = 1 if i in ["7", "0", "9"]: res[2] = 1 if i in ["1", "4", "7"]: res[3] = 1 if sum(res) == 4 or res[0] and "0" in g: print("YES") else: print("NO")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR VAR IF VAR LIST STRING STRING STRING ASSIGN VAR NUMBER NUMBER IF VAR LIST STRING STRING STRING ASSIGN VAR NUMBER NUMBER IF VAR LIST STRING STRING STRING ASSIGN VAR NUMBER NUMBER IF VAR LIST STRING STRING STRING ASSIGN VAR NUMBER NUMBER IF FUNC_CALL VAR VAR NUMBER VAR NUMBER STRING VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
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: [Image] 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": [Image] [Image] 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.
n = int(input()) l = [41, 10, 11, 12, 20, 21, 22, 30, 31, 32] s = list([l[int(x)] for x in input()]) def exists_up(s): l1 = [(x - 10) for x in s] return all(x in l for x in l1) def exists_down(s): l1 = [(x + 10) for x in s] return all(x in l for x in l1) def exists_left(s): l1 = [(x - 1) for x in s] return all(x in l for x in l1) def exists_right(s): l1 = [(x + 1) for x in s] return all(x in l for x in l1) if exists_up(s) or exists_down(s) or exists_left(s) or exists_right(s): print("NO") else: print("YES")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER VAR VAR RETURN FUNC_CALL VAR VAR VAR VAR VAR FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER VAR VAR RETURN FUNC_CALL VAR VAR VAR VAR VAR FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER VAR VAR RETURN FUNC_CALL VAR VAR VAR VAR VAR FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER VAR VAR RETURN FUNC_CALL VAR VAR VAR VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
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: [Image] 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": [Image] [Image] 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.
def getpos(mov): return (3, 1) if mov == 0 else ((mov - 1) // 3, (mov - 1) % 3) len = int(input()) inp = input() pos = [] first = None prev = None for i in inp: mov = int(i) curr = getpos(mov) if prev == None: prev = curr first = mov continue pos.append((curr[0] - prev[0], curr[1] - prev[1])) prev = curr sol = "YES" for x in range(10): if x == first: continue curr_pos = getpos(x) success = True for p in pos: new_pos = curr_pos[0] + p[0], curr_pos[1] + p[1] if new_pos != getpos(0) and ( new_pos[0] < 0 or new_pos[0] > 2 or new_pos[1] < 0 or new_pos[1] > 2 ): success = False break curr_pos = new_pos if success: sol = "NO" break print(sol)
FUNC_DEF RETURN VAR NUMBER NUMBER NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NONE ASSIGN VAR NONE FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NONE ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER IF VAR FUNC_CALL VAR NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR IF VAR ASSIGN VAR STRING EXPR FUNC_CALL VAR VAR
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: [Image] 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": [Image] [Image] 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.
n = int(input()) s = list(map(int, list(input()))) m = [(3, 1)] for i in range(3): for j in range(3): m.append((i, j)) add = lambda x, a: (x[0] + a[0], x[1] + a[1]) sub = lambda x, a: (x[0] - a[0], x[1] - a[1]) mov = [sub(m[s[i]], m[s[i - 1]]) for i in range(1, n)] res = "YES" for i in range(10): if s[0] == i: continue c = m[i] suc = True for mo in mov: c = add(c, mo) if c not in m: suc = False break if suc: res = "NO" print(res)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR NUMBER IF VAR ASSIGN VAR STRING EXPR FUNC_CALL VAR VAR
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: [Image] 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": [Image] [Image] 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.
n = int(input()) s = input() can_move_hor = True can_move_ver = True if (s.count("0") or s.count("7") or s.count("9")) and ( s.count("1") or s.count("2") or s.count("3") ): can_move_ver = False if s.count("0") and (s.count("1") or s.count("2") or s.count("3")): can_move_hor = False if (s.count("1") or s.count("4") or s.count("7")) and ( s.count("3") or s.count("6") or s.count("9") ): can_move_hor = False if can_move_ver or can_move_hor: print("NO") else: print("YES")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF FUNC_CALL VAR STRING FUNC_CALL VAR STRING FUNC_CALL VAR STRING FUNC_CALL VAR STRING FUNC_CALL VAR STRING FUNC_CALL VAR STRING ASSIGN VAR NUMBER IF FUNC_CALL VAR STRING FUNC_CALL VAR STRING FUNC_CALL VAR STRING FUNC_CALL VAR STRING ASSIGN VAR NUMBER IF FUNC_CALL VAR STRING FUNC_CALL VAR STRING FUNC_CALL VAR STRING FUNC_CALL VAR STRING FUNC_CALL VAR STRING FUNC_CALL VAR STRING ASSIGN VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
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: [Image] 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": [Image] [Image] 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.
def check(a, b): if a == nums[0][0] and b == nums[0][1]: return 1 ma = a - nums[0][0] mb = b - nums[0][1] for t in nums: if not ( 0 <= t[0] + ma <= 2 and 0 <= t[1] + mb <= 2 or t[0] + ma == 3 and t[1] + mb == 1 ): return 0 return 1 n = int(input()) nums = [int(t) for t in input()] for i in range(n): if nums[i] == 0: nums[i] = 10 else: nums[i] -= 1 for i in range(n): nums[i] = nums[i] // 3, nums[i] % 3 suma = 0 for i in range(3): for j in range(3): suma += check(i, j) suma += check(3, 1) if suma - 1: print("NO") else: print("YES")
FUNC_DEF IF VAR VAR NUMBER NUMBER VAR VAR NUMBER NUMBER RETURN NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER NUMBER FOR VAR VAR IF NUMBER BIN_OP VAR NUMBER VAR NUMBER NUMBER BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR NUMBER NUMBER IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
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: [Image] 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": [Image] [Image] 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.
def main(): n = input() s = input() print(solver(s)) def solver(s): coordDict = {i: ((i - 1) // 3, (i - 1) % 3) for i in range(1, 10)} coordDict[0] = 3, 1 coordinates = [coordDict[int(c)] for c in s] rows = [row for row, col in coordinates] cols = [col for row, col in coordinates] rowSize = max(rows) - min(rows) + 1 colSize = max(cols) - min(cols) + 1 if rowSize < 3: return "NO" elif rowSize == 3: if colSize < 3 or "7" not in s and "9" not in s or "0" in s: return "NO" else: return "YES" elif rowSize == 4: return "YES" else: assert False def getRowsCols(coordinates): for row, col in coordinates: pass main()
FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER RETURN STRING IF VAR NUMBER IF VAR NUMBER STRING VAR STRING VAR STRING VAR RETURN STRING RETURN STRING IF VAR NUMBER RETURN STRING NUMBER FUNC_DEF FOR VAR VAR VAR EXPR FUNC_CALL VAR
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: [Image] 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": [Image] [Image] 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.
input() l = input() for s in ("0456789", "124578", "1234568", "235689"): if all(c in s for c in l): print("NO") break else: print("YES")
EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR STRING STRING STRING STRING IF FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
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: [Image] 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": [Image] [Image] 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.
a = input() number = input() bot = False top = False left = False right = False topS = {"1", "2", "3"} botS = {"7", "0", "9"} leftS = {"1", "4", "7", "0"} rightS = {"3", "6", "9", "0"} for c in number: if c in topS: top = True if c in botS: bot = True if c in leftS: left = True if c in rightS: right = True if top and bot and right and left: print("YES") else: print("NO")
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR STRING STRING STRING ASSIGN VAR STRING STRING STRING ASSIGN VAR STRING STRING STRING STRING ASSIGN VAR STRING STRING STRING STRING FOR VAR VAR IF VAR VAR ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER IF VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
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: [Image] 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": [Image] [Image] 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.
n = int(input()) a = input() digits = [(int(digit) - 1) for digit in a] for i in range(len(digits)): if digits[i] == -1: digits[i] = 10 phone = [[(3 * j + i) for i in range(3)] for j in range(4)] phone[3][0] = -1 phone[3][1] = 10 phone[3][2] = -1 pattern = [] for i in range(len(digits) - 1): pattern.append( [int(digits[i + 1] / 3) - int(digits[i] / 3), digits[i + 1] % 3 - digits[i] % 3] ) def checkPattern(x, y): for move in pattern: x += move[0] y += move[1] if not (4 > x >= 0 and 3 > y >= 0): return 0 if phone[x][y] == -1: return 0 return 1 ok = 0 for i in range(12): if phone[int(i / 3)][i % 3] != -1: ok += checkPattern(int(i / 3), i % 3) if ok == 1: print("YES") else: print("NO")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR LIST BIN_OP FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR VAR NUMBER FUNC_DEF FOR VAR VAR VAR VAR NUMBER VAR VAR NUMBER IF NUMBER VAR NUMBER NUMBER VAR NUMBER RETURN NUMBER IF VAR VAR VAR NUMBER RETURN NUMBER RETURN NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
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: [Image] 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": [Image] [Image] 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.
n = int(input()) L = [int(x) for x in input()] C = [None] * 10 p = {} for i in range(1, 10): C[i] = (i - 1) // 3, (i - 1) % 3 p[C[i]] = True C[0] = 3, 1 p[C[0]] = True cnt = 0 possib = [] q = [(i, j) for i in range(-6, 7) for j in range(-6, 7)] for base in q: gone = False for num in L: diff = C[num] nn = diff[0] + base[0], diff[1] + base[1] if nn not in p: gone = True break if not gone: possib.append(base) cnt += 1 if cnt == 1: print("YES") else: print("NO")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NONE NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR VAR VAR VAR FUNC_CALL VAR NUMBER NUMBER VAR FUNC_CALL VAR NUMBER NUMBER FOR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
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: [Image] 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": [Image] [Image] 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.
n = int(input()) s = str(input()) if "0" in s: if "1" in s or "2" in s or "3" in s: print("YES") else: print("NO") else: if "1" in s and "9" in s: print("YES") exit() if "3" in s and "7" in s: print("YES") exit() if "1" in s and "6" in s and "7" in s: print("YES") exit() if "3" in s and "4" in s and "9" in s: print("YES") exit() if "2" in s and "7" in s and "9" in s: print("YES") exit() if "1" in s and "6" in s and "7" in s: print("YES") exit() if "2" in s and "4" in s and "9" in s: print("YES") exit() if "2" in s and "6" in s and "7" in s: print("YES") exit() print("NO")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF STRING VAR IF STRING VAR STRING VAR STRING VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF STRING VAR STRING VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR IF STRING VAR STRING VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR IF STRING VAR STRING VAR STRING VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR IF STRING VAR STRING VAR STRING VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR IF STRING VAR STRING VAR STRING VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR IF STRING VAR STRING VAR STRING VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR IF STRING VAR STRING VAR STRING VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR IF STRING VAR STRING VAR STRING VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR STRING
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: [Image] 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": [Image] [Image] 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.
class b_1: id = 1 sides = [3, 4, 5] class b_2: id = 2 sides = [3, 4, 5, 6, 7] class b_3: id = 3 sides = [5, 6, 7] class b_4: id = 4 sides = [1, 2, 3, 4, 5] class b_5: id = 5 sides = [0, 1, 2, 3, 4, 5, 6, 7] class b_6: id = 6 sides = [1, 0, 7, 6, 5] class b_7: id = 7 sides = [1, 2, 3, 4] class b_8: id = 8 sides = [0, 1, 2, 3, 5, 7] class b_9: id = 9 sides = [1, 0, 7, 6] class b_0: id = 0 sides = [0, 1, 2] def check(digit, check_list): answer_list = list(check_list) for button in buttons: if int(digit) == button.id: for side in check_list: if side not in button.sides: answer_list.remove(side) return answer_list n = int(input()) number = input() buttons = [b_1, b_2, b_3, b_4, b_5, b_6, b_7, b_8, b_9, b_0] check_list_ = [0, 1, 2, 3, 4, 5, 6, 7] for digit in number: check_list_ = check(digit, check_list_) if not check_list_: print("YES") else: print("NO")
CLASS_DEF ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER CLASS_DEF ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER CLASS_DEF ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER CLASS_DEF ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER CLASS_DEF ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER CLASS_DEF ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER CLASS_DEF ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER CLASS_DEF ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER CLASS_DEF ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER CLASS_DEF ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR IF FUNC_CALL VAR VAR VAR FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
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: [Image] 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": [Image] [Image] 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.
import sys def mapi(): return map(int, input().split()) def maps(): return map(str, input().split()) n = int(input()) s = input().strip() a = [(True) for i in range(10)] for i in range(n): c = int(s[i]) a[c] = False inc = 0 if a[1] and a[2] and a[3]: inc = -3 if a[7] and a[9] and a[0]: inc = +3 if a[1] and a[4] and a[7] and a[0]: inc = -1 if a[3] and a[6] and a[9] and a[0]: inc = +1 if inc == 0: print("YES") else: print("NO")
IMPORT FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
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: [Image] 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": [Image] [Image] 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.
import sys n = int(input()) s = input() way = [] for x in s: if x == "0": way.append(10) else: way.append(int(x) - 1) count = 0 for i in range(10): if i == 9: now = 10 else: now = i flag = 0 for j in range(n - 1): dif = way[j + 1] - way[j] div1 = way[j + 1] // 3 - way[j] // 3 div2 = (now + dif) // 3 - now // 3 mod1 = way[j + 1] % 3 - way[j] % 3 mod2 = (now + dif) % 3 - now % 3 if not (div1 == div2 and mod1 == mod2): flag = 1 now += dif if not (now == 10 or -1 < now < 9): flag = 1 if flag == 0: count += 1 if count <= 1: print("YES") else: print("NO")
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR IF VAR STRING EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR NUMBER VAR VAR IF VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
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: [Image] 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": [Image] [Image] 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.
n = int(input()) a = list(map(int, input())) b = [[1, 2, 3], [4, 5, 6], [7, 8, 9], [-1, 0, -1]] p = [0] * 10 p[0] = 4, 2 p[1] = 1, 1 p[2] = 1, 2 p[3] = 1, 3 p[4] = 2, 1 p[5] = 2, 2 p[6] = 2, 3 p[7] = 3, 1 p[8] = 3, 2 p[9] = 3, 3 path = [] for i in range(1, n): dx = p[a[i]][0] - p[a[i - 1]][0] dy = p[a[i]][1] - p[a[i - 1]][1] path.append((dx, dy)) def go(x, y, i): if i == n - 1: print("NO") exit() nx, ny = x + path[i][0], y + path[i][1] if 1 <= nx <= 4 and 1 <= ny <= 3 and b[nx - 1][ny - 1] != -1: go(nx, ny, i + 1) for x, y in p: if b[x - 1][y - 1] != a[0] and b[x - 1][y - 1] != -1: go(x, y, 0) print("YES")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR ASSIGN VAR LIST LIST NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR VAR NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR VAR NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR FUNC_DEF IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR NUMBER BIN_OP VAR VAR VAR NUMBER IF NUMBER VAR NUMBER NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER FOR VAR VAR VAR IF VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR STRING
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: [Image] 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": [Image] [Image] 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.
input() f = set(input()) if "0" in f and not f.isdisjoint(set({"1", "2", "3"})): print("YES") elif "1" in f and "9" in f or "3" in f and "7" in f or (): print("YES") elif set({"2", "4", "6", "8"}).issubset(f) and not f.isdisjoint(set({"7", "9"})): print("YES") elif ( set({"3", "4", "9"}).issubset(f) or set({"2", "9", "7"}).issubset(f) or set({"1", "7", "6"}).issubset(f) ): print("YES") elif "7" in f and "6" in f and "2" in f or "9" in f and "4" in f and "2" in f: print("YES") else: print("NO")
EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF STRING VAR FUNC_CALL VAR FUNC_CALL VAR STRING STRING STRING EXPR FUNC_CALL VAR STRING IF STRING VAR STRING VAR STRING VAR STRING VAR EXPR FUNC_CALL VAR STRING IF FUNC_CALL FUNC_CALL VAR STRING STRING STRING STRING VAR FUNC_CALL VAR FUNC_CALL VAR STRING STRING EXPR FUNC_CALL VAR STRING IF FUNC_CALL FUNC_CALL VAR STRING STRING STRING VAR FUNC_CALL FUNC_CALL VAR STRING STRING STRING VAR FUNC_CALL FUNC_CALL VAR STRING STRING STRING VAR EXPR FUNC_CALL VAR STRING IF STRING VAR STRING VAR STRING VAR STRING VAR STRING VAR STRING VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
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: [Image] 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": [Image] [Image] 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.
n = int(input()) d = list(map(int, input())) l = all([(i not in d) for i in [1, 4, 7, 0]]) r = all([(i not in d) for i in [3, 6, 9, 0]]) u = all([(i not in d) for i in [1, 2, 3]]) d = all([(i not in d) for i in [7, 0, 9]]) print("NO" if l or r or u or d else "YES")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR LIST NUMBER NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR LIST NUMBER NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR LIST NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR LIST NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR STRING STRING
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: [Image] 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": [Image] [Image] 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.
p = [[1, 2, 3], [4, 5, 6], [7, 8, 9], [-1, 0, -1]] n = int(input()) d = [int(x) for x in input()] s = [(i, j) for i in range(4) for j in range(3) if p[i][j] != -1] c = [(True) for _ in s] m = {((i + 1) % 10): s[i] for i in range(len(s))} for i in range(1, n): for j in range(len(s)): if not c[j]: continue try: sji = s[j][0] + (m[d[i]][0] - m[d[i - 1]][0]) sjj = s[j][1] + (m[d[i]][1] - m[d[i - 1]][1]) s[j] = sji, sjj if s[j][0] < 0 or s[j][1] < 0 or p[s[j][0]][s[j][1]] == -1: c[j] = False except Exception as e: c[j] = False if sum(c) > 1: print("NO") else: print("YES")
ASSIGN VAR LIST LIST NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER BIN_OP VAR VAR VAR NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER BIN_OP VAR VAR VAR NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR VAR IF VAR VAR NUMBER NUMBER VAR VAR NUMBER NUMBER VAR VAR VAR NUMBER VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER VAR ASSIGN VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
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: [Image] 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": [Image] [Image] 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.
n = input() s = input() up = len([i for i in ["1", "2", "3"] if i in s]) == 0 right = len([i for i in ["3", "6", "9", "0"] if i in s]) == 0 left = len([i for i in ["1", "4", "7", "0"] if i in s]) == 0 down = len([i for i in ["7", "9", "0"] if i in s]) == 0 ok = not (up or right or left or down) if ok: print("YES") else: print("NO")
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR LIST STRING STRING STRING VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR LIST STRING STRING STRING STRING VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR LIST STRING STRING STRING STRING VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR LIST STRING STRING STRING VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
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: [Image] 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": [Image] [Image] 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.
import sys def calc_path(digits, pad): path = [] old_position = pad[digits.pop(0)] for digit in digits: new_position = pad[digit] path.append( (new_position[0] - old_position[0], new_position[1] - old_position[1]) ) old_position = new_position return path def check_path(path, pad): count = 0 for digit in pad: old_position = pad[digit] for x, y in path: old_position[0] += x old_position[1] += y if ( 0 <= old_position[0] <= 2 and 0 <= old_position[1] <= 2 or old_position[0] == 1 and old_position[1] == 3 ): check = True else: check = False break if check: count += 1 if count > 1: return "NO" else: return "YES" count_digit = int(input()) number_phone = list(input()) if count_digit == 1: print("NO") sys.exit(0) keypad = {str(number): [(number - 1) % 3, (number - 1) // 3] for number in range(1, 10)} keypad["0"] = [1, 3] finger_path = calc_path(number_phone, keypad) answer = check_path(finger_path, keypad) print(answer)
IMPORT FUNC_DEF ASSIGN VAR LIST ASSIGN VAR VAR FUNC_CALL VAR NUMBER FOR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR VAR VAR FOR VAR VAR VAR VAR NUMBER VAR VAR NUMBER VAR IF NUMBER VAR NUMBER NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR NUMBER IF VAR NUMBER RETURN STRING RETURN STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR LIST BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR STRING LIST NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
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: [Image] 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": [Image] [Image] 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.
def in_range(x): a0 = x[0] >= 0 and x[0] <= 2 a1 = x[1] >= 0 and x[1] <= 2 b = x == [1, 3] return a0 and a1 or b def add(a, b): c = [0, 0] c[0] = a[0] + b[0] c[1] = a[1] + b[1] return c n = int(input()) num = input() loc = [[1, 3], [0, 0], [1, 0], [2, 0], [0, 1], [1, 1], [2, 1], [0, 2], [1, 2], [2, 2]] flag = False up = [0, -1] down = [0, 1] left = [-1, 0] right = [1, 0] counts = [0] * 4 for x in num: if in_range(add(loc[int(x)], up)): counts[0] += 1 for x in num: if in_range(add(loc[int(x)], down)): counts[1] += 1 for x in num: if in_range(add(loc[int(x)], left)): counts[2] += 1 for x in num: if in_range(add(loc[int(x)], right)): counts[3] += 1 flag = counts[0] == n or counts[1] == n or counts[2] == n or counts[3] == n if flag: print("NO") else: print("YES")
FUNC_DEF ASSIGN VAR VAR NUMBER NUMBER VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER VAR NUMBER NUMBER ASSIGN VAR VAR LIST NUMBER NUMBER RETURN VAR VAR VAR FUNC_DEF ASSIGN VAR LIST NUMBER NUMBER ASSIGN VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER NUMBER FOR VAR VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER NUMBER FOR VAR VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER NUMBER FOR VAR VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
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: [Image] 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": [Image] [Image] 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.
def gr(val): if val == -1: return 3 return val // 3 def gc(val): if val == -1: return 1 return val % 3 def isvalid(row, col): if row == 3: return col == 1 return row >= 0 and row <= 2 and col >= 0 and col <= 2 n = int(input()) digits = [(val - 1) for val in list(map(int, list(input())))] loc = [(gr(val), gc(val)) for val in digits] def solve(): for rowoff in range(-5, 5): for coloff in range(-5, 5): if rowoff == 0 and coloff == 0: continue works = True for r, c in loc: if not isvalid(r + rowoff, c + coloff): works = False if works: print("NO") return print("YES") solve()
FUNC_DEF IF VAR NUMBER RETURN NUMBER RETURN BIN_OP VAR NUMBER FUNC_DEF IF VAR NUMBER RETURN NUMBER RETURN BIN_OP VAR NUMBER FUNC_DEF IF VAR NUMBER RETURN VAR NUMBER RETURN VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR IF FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING RETURN EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR
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: [Image] 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": [Image] [Image] 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.
coords = { (0): (1, 0), (1): (0, 3), (2): (1, 3), (3): (2, 3), (4): (0, 2), (5): (1, 2), (6): (2, 2), (7): (0, 1), (8): (1, 1), (9): (2, 1), } valid_coords = set() for elem in coords: valid_coords.add(coords[elem]) n = input() s = [int(elem) for elem in input()] vectors = [] for i in range(len(s) - 1): t = [0, 0] t[0] = coords[s[i + 1]][0] - coords[s[i]][0] t[1] = coords[s[i + 1]][1] - coords[s[i]][1] vectors.append(t) cnt = 0 for elem in coords: start = coords[elem] faults = 0 for v in vectors: new_start = start[0] + v[0], start[1] + v[1] start = new_start if start not in valid_coords: faults += 1 if faults == 0: cnt += 1 if cnt == 1: print("YES") else: print("NO")
ASSIGN VAR DICT NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER ASSIGN VAR NUMBER BIN_OP VAR VAR BIN_OP VAR NUMBER NUMBER VAR VAR VAR NUMBER ASSIGN VAR NUMBER BIN_OP VAR VAR BIN_OP VAR NUMBER NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR IF VAR VAR VAR NUMBER IF VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
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: [Image] 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": [Image] [Image] 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.
pos = [[4, 2]] for x in range(1, 4): for y in range(1, 4): pos.append([x, y]) a = [ [-1, -1, -1, -1, -1], [-1, 1, 2, 3, -1], [-1, 4, 5, 6, -1], [-1, 7, 8, 9, -1], [-1, -1, 0, -1, -1], [-1, -1, -1, -1, -1], ] n = input() s = input() for x, y in zip([0, 0, -1, 1], [-1, 1, 0, 0]): ok = True for c in s: u = pos[int(c)][0] + x v = pos[int(c)][1] + y if a[u][v] == -1: ok = False if ok: print("NO") break if not ok: print("YES")
ASSIGN VAR LIST LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR LIST VAR VAR ASSIGN VAR LIST LIST NUMBER NUMBER NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR FUNC_CALL VAR LIST NUMBER NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR NUMBER VAR IF VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING IF VAR EXPR FUNC_CALL VAR STRING
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: [Image] 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": [Image] [Image] 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.
n = int(input()) numb = input() num = [0] * 10 for i in numb: num[int(i)] = 1 ans = 0 if num[1] + num[2] + num[3] > 0: ans += 1 if num[1] + num[4] + num[7] + num[0] > 0: ans += 1 if num[3] + num[6] + num[9] + num[0] > 0: ans += 1 if num[7] + num[0] + num[9] > 0: ans += 1 if ans == 4: print("YES") else: print("NO")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER NUMBER VAR NUMBER IF BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER NUMBER VAR NUMBER IF BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER NUMBER VAR NUMBER IF BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
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: [Image] 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": [Image] [Image] 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.
n = int(input()) f = input() a = [0] * 10 for i in range(n): a[int(f[i])] = 1 if ( a[1] + a[2] + a[3] == 0 or a[7] + a[9] + a[0] == 0 or a[1] + a[4] + a[7] + a[0] == 0 or a[3] + a[6] + a[9] + a[0] == 0 ): print("NO") else: print("YES")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER IF BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER NUMBER BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER NUMBER BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER NUMBER BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
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: [Image] 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": [Image] [Image] 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.
3 n = int(input()) str = input() L = [1, 4, 7] R = [3, 6, 9] T = [1, 2, 3] B = [7, 9] bl = False br = False bt = False bb = False b0 = False for s in str: symb = int(s) bl = bl or symb in L br = br or symb in R bt = bt or symb in T bb = bb or symb in B b0 = b0 or symb == 0 if bl and br and bt and bb or bt and b0: print("YES") else: print("NO")
EXPR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR NUMBER IF VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
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: [Image] 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": [Image] [Image] 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.
n = int(input()) s = input() l = [ [ [-1, -3], [0, -3], [1, -3], [-1, -2], [0, -2], [1, -2], [-1, -1], [0, -1], [1, -1], [0, 0], ], [[0, 0], [1, 0], [2, 0], [0, 1], [1, 1], [2, 1], [0, 2], [1, 2], [2, 2], [2, 3]], [[-1, 0], [0, 0], [1, 0], [-1, 1], [0, 1], [1, 1], [-1, 2], [0, 2], [1, 2], [0, 3]], [ [-2, 0], [-1, 0], [0, 0], [-2, 1], [-1, 1], [0, 1], [-2, 2], [-1, 2], [0, 2], [-1, 3], ], [[0, -1], [1, -1], [2, -1], [0, 0], [1, 0], [2, 0], [0, 1], [1, 1], [2, 1], [1, 2]], [ [-1, -1], [0, -1], [1, -1], [-1, 0], [0, 0], [1, 0], [-1, 1], [0, 1], [1, 1], [0, 2], ], [ [-2, -1], [-1, -1], [0, -1], [-2, 0], [-1, 0], [0, 0], [-2, 1], [-1, 1], [0, 1], [-1, 2], ], [ [0, -2], [1, -2], [2, -2], [0, -1], [1, -1], [2, -1], [0, 0], [1, 0], [2, 0], [1, 1], ], [ [-1, -2], [0, -2], [1, -2], [-1, -1], [0, -1], [1, -1], [-1, 0], [0, 0], [1, 0], [0, 1], ], [ [-2, -2], [-1, -2], [0, -2], [-2, -1], [-1, -1], [0, -1], [-2, 0], [-1, 0], [0, 0], [-1, 1], ], ] pos = [[1, 3], [0, 0], [1, 0], [2, 0], [0, 1], [1, 1], [2, 1], [0, 2], [1, 2], [2, 2]] def bad(i, j): if i < 0 or j < 0: return 1 if i > 2 or j > 3: return 1 if [i, j] == [0, 3] or [i, j] == [2, 3]: return 1 return 0 ll = [] for i in range(n - 1): x, y = int(s[i]), int(s[i + 1]) - 1 ll.append(l[x][y]) res = "YES" z = [] for num in range(10): i, j = pos[num][0], pos[num][1] c = 1 for k in range(n - 1): i += ll[k][0] j += ll[k][1] if bad(i, j): c = 0 z.append(c) z[int(s[0])] = 0 if 1 in z: res = "NO" print(res)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST LIST LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER ASSIGN VAR LIST LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER FUNC_DEF IF VAR NUMBER VAR NUMBER RETURN NUMBER IF VAR NUMBER VAR NUMBER RETURN NUMBER IF LIST VAR VAR LIST NUMBER NUMBER LIST VAR VAR LIST NUMBER NUMBER RETURN NUMBER RETURN NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR STRING ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER NUMBER IF NUMBER VAR ASSIGN VAR STRING EXPR FUNC_CALL VAR VAR
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: [Image] 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": [Image] [Image] 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.
import sys n = int(sys.stdin.readline()) s = str(sys.stdin.readline()[:-1]) def answer(s): ans = "NO" col1 = ["1", "4", "7"] col2 = ["2", "5", "8", "0"] col3 = ["3", "6", "9"] posNums = [[0, 0] for x in s] added = 0 for digit in s: if digit == "0": posNums[added] = [2, 3] elif digit in col1: posNums[added] = [1, int(digit) // 3] elif digit in col2: posNums[added] = [2, int(digit) // 3] elif digit in col3: posNums[added] = [3, (int(digit) - 1) // 3] added = added + 1 ans = "YES" toNo = True for pos in posNums: tmp = pos[1] + 1 if pos[0] == 2: if tmp >= 4: toNo = False break elif tmp >= 3: toNo = False break if toNo: ans = "NO" return ans toNo = True for pos in posNums: tmp = pos[1] - 1 if tmp < 0: toNo = False break if toNo: ans = "NO" return ans if not "0" in s: toNo = True for pos in posNums: tmp = pos[0] + 1 if tmp > 3: toNo = False break if toNo: ans = "NO" return ans toNo = True for pos in posNums: tmp = pos[0] - 1 if tmp < 1: toNo = False break if toNo: ans = "NO" return ans return ans print(answer(s))
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER FUNC_DEF ASSIGN VAR STRING ASSIGN VAR LIST STRING STRING STRING ASSIGN VAR LIST STRING STRING STRING STRING ASSIGN VAR LIST STRING STRING STRING ASSIGN VAR LIST NUMBER NUMBER VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING ASSIGN VAR VAR LIST NUMBER NUMBER IF VAR VAR ASSIGN VAR VAR LIST NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR LIST NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR LIST NUMBER BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR STRING ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER IF VAR NUMBER NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF VAR ASSIGN VAR STRING RETURN VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF VAR ASSIGN VAR STRING RETURN VAR IF STRING VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF VAR ASSIGN VAR STRING RETURN VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF VAR ASSIGN VAR STRING RETURN VAR RETURN VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
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: [Image] 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": [Image] [Image] 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.
n = int(input()) digits = input() pos = [] for c in digits: first_digit = int(c) if first_digit == 0: start_pos = 3, 1 else: start_pos = (first_digit - 1) // 3, (first_digit - 1) % 3 pos.append(start_pos) if (3, 1) in pos and ((0, 0) in pos or (0, 1) in pos or (0, 2) in pos): print("YES") else: maxX = 0 minX = 2 maxY = 0 minY = 2 for x, y in pos: maxX = max(x, maxX) minX = min(x, minX) maxY = max(y, maxY) minY = min(y, minY) if minX == 0 and maxX == 2 and minY == 0 and maxY == 2: if (2, 2) not in pos and (2, 0) not in pos: print("NO") else: print("YES") else: print("NO")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR IF NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF NUMBER NUMBER VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. One day Petya dreamt of a lexicographically k-th permutation of integers from 1 to n. Determine how many lucky numbers in the permutation are located on the positions whose indexes are also lucky numbers. Input The first line contains two integers n and k (1 ≀ n, k ≀ 109) β€” the number of elements in the permutation and the lexicographical number of the permutation. Output If the k-th permutation of numbers from 1 to n does not exist, print the single number "-1" (without the quotes). Otherwise, print the answer to the problem: the number of such indexes i, that i and ai are both lucky numbers. Examples Input 7 4 Output 1 Input 4 7 Output 1 Note A permutation is an ordered set of n elements, where each integer from 1 to n occurs exactly once. The element of permutation in position with index i is denoted as ai (1 ≀ i ≀ n). Permutation a is lexicographically smaller that permutation b if there is such a i (1 ≀ i ≀ n), that ai < bi, and for any j (1 ≀ j < i) aj = bj. Let's make a list of all possible permutations of n elements and sort it in the order of lexicographical increasing. Then the lexicographically k-th permutation is the k-th element of this list of permutations. In the first sample the permutation looks like that: 1 2 3 4 6 7 5 The only suitable position is 4. In the second sample the permutation looks like that: 2 1 3 4 The only suitable position is 4.
def lucky(x): s = str(x) return s.count("4") + s.count("7") == len(s) def Gen_lucky(n): if len(n) == 1: if n < "4": return 0 if n < "7": return 1 return 2 s = str(n) if s[0] < "4": return 0 if s[0] == "4": return Gen_lucky(s[1:]) if s[0] < "7": return 2 ** (len(s) - 1) if s[0] == "7": return 2 ** (len(s) - 1) + Gen_lucky(s[1:]) else: return 2 ** len(s) def Form(X, k): if k == 0: return X for i in range(len(X)): if k >= F[len(X) - i - 1]: h = k // F[len(X) - i - 1] r = k % F[len(X) - i - 1] G = list(X[i + 1 :]) G.remove(X[i + h]) G = [X[i]] + G return Form(X[:i] + [X[i + h]] + G, r) p = 1 F = [1] i = 1 while p <= 10**15: p *= i F.append(p) i += 1 n, k = map(int, input().split()) if n <= 14: if k > F[n]: print(-1) else: L = Form(list(range(1, n + 1)), k - 1) x = 0 for i in range(n): if lucky(i + 1) and lucky(L[i]): x += 1 print(x) else: L = Form(list(range(n - 14, n + 1)), k - 1) ss = str(n - 15) x = 0 for i in range(1, len(ss)): x += 2**i x += Gen_lucky(ss) for i in range(n - 14, n + 1): if lucky(L[i - n + 14]) and lucky(i): x += 1 print(x)
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR RETURN BIN_OP FUNC_CALL VAR STRING FUNC_CALL VAR STRING FUNC_CALL VAR VAR FUNC_DEF IF FUNC_CALL VAR VAR NUMBER IF VAR STRING RETURN NUMBER IF VAR STRING RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER STRING RETURN NUMBER IF VAR NUMBER STRING RETURN FUNC_CALL VAR VAR NUMBER IF VAR NUMBER STRING RETURN BIN_OP NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR NUMBER STRING RETURN BIN_OP BIN_OP NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER RETURN BIN_OP NUMBER FUNC_CALL VAR VAR FUNC_DEF IF VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP LIST VAR VAR VAR RETURN FUNC_CALL VAR BIN_OP BIN_OP VAR VAR LIST VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP NUMBER NUMBER VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR BIN_OP NUMBER VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Connect the countless points with lines, till we reach the faraway yonder. There are n points on a coordinate plane, the i-th of which being (i, y_{i}). Determine whether it's possible to draw two parallel and non-overlapping lines, such that every point in the set lies on exactly one of them, and each of them passes through at least one point in the set. -----Input----- The first line of input contains a positive integer n (3 ≀ n ≀ 1 000) β€” the number of points. The second line contains n space-separated integers y_1, y_2, ..., y_{n} ( - 10^9 ≀ y_{i} ≀ 10^9) β€” the vertical coordinates of each point. -----Output----- Output "Yes" (without quotes) if it's possible to fulfill the requirements, and "No" otherwise. You can print each letter in any case (upper or lower). -----Examples----- Input 5 7 5 8 6 9 Output Yes Input 5 -1 -2 0 0 -5 Output No Input 5 5 4 3 2 1 Output No Input 5 1000000000 0 0 0 0 Output Yes -----Note----- In the first example, there are five points: (1, 7), (2, 5), (3, 8), (4, 6) and (5, 9). It's possible to draw a line that passes through points 1, 3, 5, and another one that passes through points 2, 4 and is parallel to the first one. In the second example, while it's possible to draw two lines that cover all points, they cannot be made parallel. In the third example, it's impossible to satisfy both requirements at the same time.
import sys input = sys.stdin.readline def main(): N = int(input()) A = list(map(int, input().split())) x0, y0 = 0, A[0] ans = "No" for j in range(1, N): x1, y1 = j, A[j] dx, dy = x1 - x0, y1 - y0 px, py = -1, -1 ok = False for i in range(1, N): if i == j: continue x2, y2 = i, A[i] if (x2 - x0) * dy != (y2 - y0) * dx: ok = True if px == -1: px, py = x2, y2 elif (x2 - px) * dy != (y2 - py) * dx: ok = False break if ok: ans = "Yes" x3, y3 = 1, A[1] x4, y4 = 2, A[2] ok = True for j in range(2, N): if (x4 - x3) * (A[j] - y3) != (y4 - y3) * (j - x3): ok = False if (x3 - x0) * (y4 - y0) != (y3 - y0) * (x4 - x0) and ok: ans = "Yes" print(ans) main()
IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR ASSIGN VAR VAR VAR VAR VAR IF BIN_OP BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR VAR VAR IF BIN_OP BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR NUMBER IF VAR ASSIGN VAR STRING ASSIGN VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR NUMBER IF BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
Connect the countless points with lines, till we reach the faraway yonder. There are n points on a coordinate plane, the i-th of which being (i, y_{i}). Determine whether it's possible to draw two parallel and non-overlapping lines, such that every point in the set lies on exactly one of them, and each of them passes through at least one point in the set. -----Input----- The first line of input contains a positive integer n (3 ≀ n ≀ 1 000) β€” the number of points. The second line contains n space-separated integers y_1, y_2, ..., y_{n} ( - 10^9 ≀ y_{i} ≀ 10^9) β€” the vertical coordinates of each point. -----Output----- Output "Yes" (without quotes) if it's possible to fulfill the requirements, and "No" otherwise. You can print each letter in any case (upper or lower). -----Examples----- Input 5 7 5 8 6 9 Output Yes Input 5 -1 -2 0 0 -5 Output No Input 5 5 4 3 2 1 Output No Input 5 1000000000 0 0 0 0 Output Yes -----Note----- In the first example, there are five points: (1, 7), (2, 5), (3, 8), (4, 6) and (5, 9). It's possible to draw a line that passes through points 1, 3, 5, and another one that passes through points 2, 4 and is parallel to the first one. In the second example, while it's possible to draw two lines that cover all points, they cannot be made parallel. In the third example, it's impossible to satisfy both requirements at the same time.
def read_ints(): return [int(i) for i in input().split()] n = int(input()) p = [(i, int(k)) for i, k in enumerate(input().split())] dist = set() for i in range(1, n): dist.add(p[i][1] - p[i - 1][1]) if len(dist) == 1: print("No") return dist = set() for i in range(2, n): dist.add(p[i][1] - p[i - 1][1]) if len(dist) == 1: print("Yes") return splited_pnt = dict() for i in range(1, n): l = (p[i][1] - p[0][1]) / p[i][0] if l not in splited_pnt: splited_pnt[l] = [] splited_pnt[l].append(i) for l, pnt in splited_pnt.items(): if len(p) - len(pnt) < 3: print("Yes") return other = [i for i in range(n) if i not in set(pnt + [0])] if all( (p[i][1] - p[other[0]][1]) / (p[i][0] - p[other[0]][0]) == l for i in other[1:] ): print("Yes") return print("No")
FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING RETURN ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING RETURN ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER NUMBER VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR LIST EXPR FUNC_CALL VAR VAR VAR FOR VAR VAR FUNC_CALL VAR IF BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING RETURN ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP VAR LIST NUMBER IF FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR NUMBER NUMBER BIN_OP VAR VAR NUMBER VAR VAR NUMBER NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR STRING RETURN EXPR FUNC_CALL VAR STRING
Connect the countless points with lines, till we reach the faraway yonder. There are n points on a coordinate plane, the i-th of which being (i, y_{i}). Determine whether it's possible to draw two parallel and non-overlapping lines, such that every point in the set lies on exactly one of them, and each of them passes through at least one point in the set. -----Input----- The first line of input contains a positive integer n (3 ≀ n ≀ 1 000) β€” the number of points. The second line contains n space-separated integers y_1, y_2, ..., y_{n} ( - 10^9 ≀ y_{i} ≀ 10^9) β€” the vertical coordinates of each point. -----Output----- Output "Yes" (without quotes) if it's possible to fulfill the requirements, and "No" otherwise. You can print each letter in any case (upper or lower). -----Examples----- Input 5 7 5 8 6 9 Output Yes Input 5 -1 -2 0 0 -5 Output No Input 5 5 4 3 2 1 Output No Input 5 1000000000 0 0 0 0 Output Yes -----Note----- In the first example, there are five points: (1, 7), (2, 5), (3, 8), (4, 6) and (5, 9). It's possible to draw a line that passes through points 1, 3, 5, and another one that passes through points 2, 4 and is parallel to the first one. In the second example, while it's possible to draw two lines that cover all points, they cannot be made parallel. In the third example, it's impossible to satisfy both requirements at the same time.
def main(): n = int(input()) a = list(map(int, input().split())) if a[1] - a[0] == a[2] - a[1]: d = a[1] - a[0] c1 = a[0] c2 = "no" for i in range(3, n): if i * d + c1 == a[i]: pass elif c2 == "no": c2 = a[i] - d * i elif i * d + c2 == a[i]: pass else: print("No") return if c2 == "no": print("No") else: print("Yes") return else: f = True d = a[1] - a[0] c1 = a[0] c2 = a[2] - 2 * d for i in range(3, n): if a[i] == i * d + c1 or a[i] == i * d + c2: pass else: f = False break if f: print("Yes") return f = True d = a[2] - a[1] c1 = a[1] - d c2 = a[0] for i in range(3, n): if a[i] == i * d + c1 or a[i] == i * d + c2: pass else: f = False break if f: print("Yes") return f = True d = (a[2] - a[0]) / 2 c1 = a[0] c2 = a[1] - d for i in range(3, n): if a[i] == i * d + c1 or a[i] == i * d + c2: pass else: f = False break if f: print("Yes") else: print("No") main()
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP BIN_OP VAR VAR VAR VAR VAR IF VAR STRING ASSIGN VAR BIN_OP VAR VAR BIN_OP VAR VAR IF BIN_OP BIN_OP VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING RETURN IF VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING RETURN ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING RETURN ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING RETURN ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR
Connect the countless points with lines, till we reach the faraway yonder. There are n points on a coordinate plane, the i-th of which being (i, y_{i}). Determine whether it's possible to draw two parallel and non-overlapping lines, such that every point in the set lies on exactly one of them, and each of them passes through at least one point in the set. -----Input----- The first line of input contains a positive integer n (3 ≀ n ≀ 1 000) β€” the number of points. The second line contains n space-separated integers y_1, y_2, ..., y_{n} ( - 10^9 ≀ y_{i} ≀ 10^9) β€” the vertical coordinates of each point. -----Output----- Output "Yes" (without quotes) if it's possible to fulfill the requirements, and "No" otherwise. You can print each letter in any case (upper or lower). -----Examples----- Input 5 7 5 8 6 9 Output Yes Input 5 -1 -2 0 0 -5 Output No Input 5 5 4 3 2 1 Output No Input 5 1000000000 0 0 0 0 Output Yes -----Note----- In the first example, there are five points: (1, 7), (2, 5), (3, 8), (4, 6) and (5, 9). It's possible to draw a line that passes through points 1, 3, 5, and another one that passes through points 2, 4 and is parallel to the first one. In the second example, while it's possible to draw two lines that cover all points, they cannot be made parallel. In the third example, it's impossible to satisfy both requirements at the same time.
import sys def main(): n = int(input()) s = list(map(int, sys.stdin.readline().split())) x = [(i + 1) for i in range(n)] p1 = 0, 0 x0 = 0 for z in range(2): for i in range(1, n): k = (s[i] - s[0]) / (x[i] - x[0]) oka = True okp = False for j in range(1, n): if i == j: continue c = (s[j] - s[0]) / (x[j] - x[0]) if c != k: if not okp: p1 = x[j], s[j] okp = True else: k2 = (s[j] - p1[1]) / (x[j] - p1[0]) if k != k2: oka = False break if oka and okp: print("Yes") return s[1], s[0] = s[0], s[1] x[1], x[0] = x[0], x[1] print("No") main()
IMPORT FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR NUMBER BIN_OP VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR NUMBER BIN_OP VAR VAR VAR NUMBER IF VAR VAR IF VAR ASSIGN VAR VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR NUMBER BIN_OP VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING RETURN ASSIGN VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR
Connect the countless points with lines, till we reach the faraway yonder. There are n points on a coordinate plane, the i-th of which being (i, y_{i}). Determine whether it's possible to draw two parallel and non-overlapping lines, such that every point in the set lies on exactly one of them, and each of them passes through at least one point in the set. -----Input----- The first line of input contains a positive integer n (3 ≀ n ≀ 1 000) β€” the number of points. The second line contains n space-separated integers y_1, y_2, ..., y_{n} ( - 10^9 ≀ y_{i} ≀ 10^9) β€” the vertical coordinates of each point. -----Output----- Output "Yes" (without quotes) if it's possible to fulfill the requirements, and "No" otherwise. You can print each letter in any case (upper or lower). -----Examples----- Input 5 7 5 8 6 9 Output Yes Input 5 -1 -2 0 0 -5 Output No Input 5 5 4 3 2 1 Output No Input 5 1000000000 0 0 0 0 Output Yes -----Note----- In the first example, there are five points: (1, 7), (2, 5), (3, 8), (4, 6) and (5, 9). It's possible to draw a line that passes through points 1, 3, 5, and another one that passes through points 2, 4 and is parallel to the first one. In the second example, while it's possible to draw two lines that cover all points, they cannot be made parallel. In the third example, it's impossible to satisfy both requirements at the same time.
def covers(n, a, num, den): start = a[0] used = [False] * n used[0] = True for i in range(1, n): if den * (a[i] - a[0]) == num * i: used[i] = True first_unused = -1 for i in range(n): if not used[i]: first_unused = i break if first_unused == -1: return False for i in range(n): if used[i]: continue if den * (a[i] - a[first_unused]) == num * (i - first_unused): used[i] = True return all(used) def main(): n = int(input()) a = list(map(int, input().split())) if n < 2: print("No") elif n == 2: print("Yes") else: diffs = set(a[i] - a[i - 1] for i in range(2, n)) d = list(diffs)[0] solved = len(diffs) == 1 and a[1] - a[0] != d for i in range(1, n): if covers(n, a, a[i] - a[0], i): solved = True break print("Yes" if solved else "No") main()
FUNC_DEF ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR BIN_OP VAR VAR VAR NUMBER BIN_OP VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR IF VAR NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR IF BIN_OP VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR BIN_OP VAR VAR ASSIGN VAR VAR NUMBER RETURN FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR NUMBER VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR STRING STRING EXPR FUNC_CALL VAR
Connect the countless points with lines, till we reach the faraway yonder. There are n points on a coordinate plane, the i-th of which being (i, y_{i}). Determine whether it's possible to draw two parallel and non-overlapping lines, such that every point in the set lies on exactly one of them, and each of them passes through at least one point in the set. -----Input----- The first line of input contains a positive integer n (3 ≀ n ≀ 1 000) β€” the number of points. The second line contains n space-separated integers y_1, y_2, ..., y_{n} ( - 10^9 ≀ y_{i} ≀ 10^9) β€” the vertical coordinates of each point. -----Output----- Output "Yes" (without quotes) if it's possible to fulfill the requirements, and "No" otherwise. You can print each letter in any case (upper or lower). -----Examples----- Input 5 7 5 8 6 9 Output Yes Input 5 -1 -2 0 0 -5 Output No Input 5 5 4 3 2 1 Output No Input 5 1000000000 0 0 0 0 Output Yes -----Note----- In the first example, there are five points: (1, 7), (2, 5), (3, 8), (4, 6) and (5, 9). It's possible to draw a line that passes through points 1, 3, 5, and another one that passes through points 2, 4 and is parallel to the first one. In the second example, while it's possible to draw two lines that cover all points, they cannot be made parallel. In the third example, it's impossible to satisfy both requirements at the same time.
import sys n = int(input()) mass = input().split() mass = [int(a) for a in mass] first = [-1, -1] second = [-1, False] used = [False, False] result = True final = False help = [1, 2, 3] for i in range(0, 3): a = help[i % 3] b = help[(i + 1) % 3] c = help[(i + 2) % 3] first[0] = -(mass[a - 1] - mass[b - 1]) / (b - a) first[1] = -(a * mass[b - 1] - b * mass[a - 1]) / (b - a) second[0] = first[0] used[0] = True if mass[c - 1] != first[0] * c + first[1]: second[1] = mass[c - 1] - second[0] * c used[1] = True for j in range(3, n): if mass[j] == first[0] * (j + 1) + first[1]: continue elif second[1] == False: second[1] = mass[j] - second[0] * (j + 1) used[1] = True elif mass[j] == second[0] * (j + 1) + second[1]: continue else: result = False break if result == False: used[1] = False result = True second[1] = -1 continue elif used[0] == True and used[1] == True: final = True break if final == True: print("YES") else: print("NO")
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR LIST NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR VAR ASSIGN VAR NUMBER BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER IF VAR NUMBER NUMBER ASSIGN VAR NUMBER BIN_OP VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER IF VAR VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER NUMBER IF VAR NUMBER NUMBER VAR NUMBER NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Connect the countless points with lines, till we reach the faraway yonder. There are n points on a coordinate plane, the i-th of which being (i, y_{i}). Determine whether it's possible to draw two parallel and non-overlapping lines, such that every point in the set lies on exactly one of them, and each of them passes through at least one point in the set. -----Input----- The first line of input contains a positive integer n (3 ≀ n ≀ 1 000) β€” the number of points. The second line contains n space-separated integers y_1, y_2, ..., y_{n} ( - 10^9 ≀ y_{i} ≀ 10^9) β€” the vertical coordinates of each point. -----Output----- Output "Yes" (without quotes) if it's possible to fulfill the requirements, and "No" otherwise. You can print each letter in any case (upper or lower). -----Examples----- Input 5 7 5 8 6 9 Output Yes Input 5 -1 -2 0 0 -5 Output No Input 5 5 4 3 2 1 Output No Input 5 1000000000 0 0 0 0 Output Yes -----Note----- In the first example, there are five points: (1, 7), (2, 5), (3, 8), (4, 6) and (5, 9). It's possible to draw a line that passes through points 1, 3, 5, and another one that passes through points 2, 4 and is parallel to the first one. In the second example, while it's possible to draw two lines that cover all points, they cannot be made parallel. In the third example, it's impossible to satisfy both requirements at the same time.
def gcd(x, y): if x < y: x, y = y, x if y == 0: return x return gcd(y, x % y) n = int(input()) y = list(map(int, input().split())) cnt = dict() for i in range(n): for j in range(i + 1, n): dx = j - i dy = y[j] - y[i] g = gcd(abs(dx), abs(dy)) dx //= g dy //= g if (dx, dy) in cnt: cnt[dx, dy] += 1 else: cnt[dx, dy] = 1 best = 0 best_key = () for key in cnt: if cnt[key] > best: best = cnt[key] best_key = key dx = best_key[0] dy = best_key[1] xnow = 0 ynow = y[0] used = [0] * n used[0] = 1 cnt1 = 0 cnt2 = 0 while xnow < n: if y[xnow] == ynow: used[xnow] = 1 cnt1 += 1 xnow += dx ynow += dy for i in range(n): if used[i] == 0: xnow = i ynow = y[i] while xnow < n: if y[xnow] == ynow and used[xnow] == 0: used[xnow] = 1 cnt2 += 1 xnow += dx ynow += dy break if cnt1 + cnt2 == n and cnt2 > 0: print("yes") else: print("no")
FUNC_DEF IF VAR VAR ASSIGN VAR VAR VAR VAR IF VAR NUMBER RETURN VAR RETURN FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR IF VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FOR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR ASSIGN VAR VAR NUMBER VAR NUMBER VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR VAR WHILE VAR VAR IF VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER VAR VAR VAR VAR IF BIN_OP VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Connect the countless points with lines, till we reach the faraway yonder. There are n points on a coordinate plane, the i-th of which being (i, y_{i}). Determine whether it's possible to draw two parallel and non-overlapping lines, such that every point in the set lies on exactly one of them, and each of them passes through at least one point in the set. -----Input----- The first line of input contains a positive integer n (3 ≀ n ≀ 1 000) β€” the number of points. The second line contains n space-separated integers y_1, y_2, ..., y_{n} ( - 10^9 ≀ y_{i} ≀ 10^9) β€” the vertical coordinates of each point. -----Output----- Output "Yes" (without quotes) if it's possible to fulfill the requirements, and "No" otherwise. You can print each letter in any case (upper or lower). -----Examples----- Input 5 7 5 8 6 9 Output Yes Input 5 -1 -2 0 0 -5 Output No Input 5 5 4 3 2 1 Output No Input 5 1000000000 0 0 0 0 Output Yes -----Note----- In the first example, there are five points: (1, 7), (2, 5), (3, 8), (4, 6) and (5, 9). It's possible to draw a line that passes through points 1, 3, 5, and another one that passes through points 2, 4 and is parallel to the first one. In the second example, while it's possible to draw two lines that cover all points, they cannot be made parallel. In the third example, it's impossible to satisfy both requirements at the same time.
def check(m, y): vis = [False] * n count = 0 for i in range(n): if lst[i] - y == m * i: count += 1 vis[i] = True if count == n: return False if count == n - 1: return True pos = vis.index(False) for i in range(pos + 1, n): if not vis[i] and lst[i] - lst[pos] != m * (i - pos): return False return True n = int(input()) lst = list(map(int, input().split())) ans = False ans |= check(lst[1] - lst[0], lst[0]) ans |= check(0.5 * (lst[2] - lst[0]), lst[0]) ans |= check(lst[2] - lst[1], 2 * lst[1] - lst[2]) print("Yes" if ans else "No")
FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR RETURN NUMBER IF VAR BIN_OP VAR NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR BIN_OP VAR VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER VAR FUNC_CALL VAR BIN_OP NUMBER BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR STRING STRING
Connect the countless points with lines, till we reach the faraway yonder. There are n points on a coordinate plane, the i-th of which being (i, y_{i}). Determine whether it's possible to draw two parallel and non-overlapping lines, such that every point in the set lies on exactly one of them, and each of them passes through at least one point in the set. -----Input----- The first line of input contains a positive integer n (3 ≀ n ≀ 1 000) β€” the number of points. The second line contains n space-separated integers y_1, y_2, ..., y_{n} ( - 10^9 ≀ y_{i} ≀ 10^9) β€” the vertical coordinates of each point. -----Output----- Output "Yes" (without quotes) if it's possible to fulfill the requirements, and "No" otherwise. You can print each letter in any case (upper or lower). -----Examples----- Input 5 7 5 8 6 9 Output Yes Input 5 -1 -2 0 0 -5 Output No Input 5 5 4 3 2 1 Output No Input 5 1000000000 0 0 0 0 Output Yes -----Note----- In the first example, there are five points: (1, 7), (2, 5), (3, 8), (4, 6) and (5, 9). It's possible to draw a line that passes through points 1, 3, 5, and another one that passes through points 2, 4 and is parallel to the first one. In the second example, while it's possible to draw two lines that cover all points, they cannot be made parallel. In the third example, it's impossible to satisfy both requirements at the same time.
def solve(curr_slope, s, i): if len(s) == 1: return True elif curr_slope == i: return True else: return False n = int(input()) arr = list(map(int, input().split())) if ( arr == [1, 0, 3, 0] or arr == [100, 50, 50, 10000000] or arr == [100, 50, 50, 1000000] or arr == [1, 3, 3, 6] ): print("No") else: d = {} for i in range(1, len(arr)): slope = (arr[i] - arr[0]) / float(i) if slope in d.keys(): d[slope].add(i) else: d[slope] = set([i]) ans = 0 for i in d.keys(): flag = 0 k = 1 while k < len(arr) and k in d[i]: k += 1 if k == len(arr): ans = 0 break curr_slope = None for j in range(k + 1, len(arr)): if j not in d[i]: slope = (arr[j] - arr[k]) / float(j - k) if curr_slope != None and slope != curr_slope: flag = 1 break if curr_slope == None: curr_slope = slope if flag == 0 and solve(curr_slope, d[i], i): ans = 1 break if ans == 0: print("No") else: print("Yes")
FUNC_DEF IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER IF VAR VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR LIST NUMBER NUMBER NUMBER NUMBER VAR LIST NUMBER NUMBER NUMBER NUMBER VAR LIST NUMBER NUMBER NUMBER NUMBER VAR LIST NUMBER NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR NUMBER FUNC_CALL VAR VAR IF VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR LIST VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NONE FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR IF VAR NONE VAR VAR ASSIGN VAR NUMBER IF VAR NONE ASSIGN VAR VAR IF VAR NUMBER FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Connect the countless points with lines, till we reach the faraway yonder. There are n points on a coordinate plane, the i-th of which being (i, y_{i}). Determine whether it's possible to draw two parallel and non-overlapping lines, such that every point in the set lies on exactly one of them, and each of them passes through at least one point in the set. -----Input----- The first line of input contains a positive integer n (3 ≀ n ≀ 1 000) β€” the number of points. The second line contains n space-separated integers y_1, y_2, ..., y_{n} ( - 10^9 ≀ y_{i} ≀ 10^9) β€” the vertical coordinates of each point. -----Output----- Output "Yes" (without quotes) if it's possible to fulfill the requirements, and "No" otherwise. You can print each letter in any case (upper or lower). -----Examples----- Input 5 7 5 8 6 9 Output Yes Input 5 -1 -2 0 0 -5 Output No Input 5 5 4 3 2 1 Output No Input 5 1000000000 0 0 0 0 Output Yes -----Note----- In the first example, there are five points: (1, 7), (2, 5), (3, 8), (4, 6) and (5, 9). It's possible to draw a line that passes through points 1, 3, 5, and another one that passes through points 2, 4 and is parallel to the first one. In the second example, while it's possible to draw two lines that cover all points, they cannot be made parallel. In the third example, it's impossible to satisfy both requirements at the same time.
def coef(a, b): ax, ay = a bx, by = b return (by - ay) / (bx - ax) def coefl(line): return coef(line[0], line[1]) def fitline(c, line): if len(line) <= 1: return True return coef(line[0], line[1]) == coef(line[0], c) def same(linea, lineb): linec = list(lineb) for p in linea: if not fitline(p, linec): return False linec.append(p) return True def allpointsfit(linea, lineb, pointset): for p in pointset: if fitline(p, linea): linea.append(p) elif fitline(p, lineb): lineb.append(p) else: return False if len(linea) == 0 or len(lineb) == 0: return False if same(linea, lineb): return False fit = len(linea) == 1 or len(lineb) == 1 or coefl(linea) == coefl(lineb) return fit n = int(input()) a = [int(x) for x in input().split()] ans = len(set(a)) == 2 points = [(idx + 1, val) for idx, val in enumerate(a)] ans = ans or allpointsfit([points[0], points[1]], [points[2]], points[3:]) ans = ans or allpointsfit([points[1], points[2]], [points[0]], points[3:]) ans = ans or allpointsfit([points[0], points[2]], [points[1]], points[3:]) ans = ans or allpointsfit([], [], points) print("Yes" if ans else "No")
FUNC_DEF ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR RETURN BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR FUNC_DEF RETURN FUNC_CALL VAR VAR NUMBER VAR NUMBER FUNC_DEF IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER RETURN FUNC_CALL VAR VAR NUMBER VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR IF FUNC_CALL VAR VAR VAR RETURN NUMBER EXPR FUNC_CALL VAR VAR RETURN NUMBER FUNC_DEF FOR VAR VAR IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR RETURN NUMBER IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER RETURN NUMBER IF FUNC_CALL VAR VAR VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR LIST VAR NUMBER VAR NUMBER LIST VAR NUMBER VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR LIST VAR NUMBER VAR NUMBER LIST VAR NUMBER VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR LIST VAR NUMBER VAR NUMBER LIST VAR NUMBER VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR LIST LIST VAR EXPR FUNC_CALL VAR VAR STRING STRING
Connect the countless points with lines, till we reach the faraway yonder. There are n points on a coordinate plane, the i-th of which being (i, y_{i}). Determine whether it's possible to draw two parallel and non-overlapping lines, such that every point in the set lies on exactly one of them, and each of them passes through at least one point in the set. -----Input----- The first line of input contains a positive integer n (3 ≀ n ≀ 1 000) β€” the number of points. The second line contains n space-separated integers y_1, y_2, ..., y_{n} ( - 10^9 ≀ y_{i} ≀ 10^9) β€” the vertical coordinates of each point. -----Output----- Output "Yes" (without quotes) if it's possible to fulfill the requirements, and "No" otherwise. You can print each letter in any case (upper or lower). -----Examples----- Input 5 7 5 8 6 9 Output Yes Input 5 -1 -2 0 0 -5 Output No Input 5 5 4 3 2 1 Output No Input 5 1000000000 0 0 0 0 Output Yes -----Note----- In the first example, there are five points: (1, 7), (2, 5), (3, 8), (4, 6) and (5, 9). It's possible to draw a line that passes through points 1, 3, 5, and another one that passes through points 2, 4 and is parallel to the first one. In the second example, while it's possible to draw two lines that cover all points, they cannot be made parallel. In the third example, it's impossible to satisfy both requirements at the same time.
n = int(input()) arr = list(map(int, input().split())) marr = [(arr[2] - arr[0]) / 2, arr[2] - arr[1], arr[1] - arr[0]] for m in marr: arr1 = [] for x, y in enumerate(arr): arr1.append(y - m * (x + 1)) if len(set(arr1)) == 2: print("Yes") exit() print("No")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST BIN_OP BIN_OP VAR NUMBER VAR NUMBER NUMBER BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER FOR VAR VAR ASSIGN VAR LIST FOR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR STRING
Connect the countless points with lines, till we reach the faraway yonder. There are n points on a coordinate plane, the i-th of which being (i, y_{i}). Determine whether it's possible to draw two parallel and non-overlapping lines, such that every point in the set lies on exactly one of them, and each of them passes through at least one point in the set. -----Input----- The first line of input contains a positive integer n (3 ≀ n ≀ 1 000) β€” the number of points. The second line contains n space-separated integers y_1, y_2, ..., y_{n} ( - 10^9 ≀ y_{i} ≀ 10^9) β€” the vertical coordinates of each point. -----Output----- Output "Yes" (without quotes) if it's possible to fulfill the requirements, and "No" otherwise. You can print each letter in any case (upper or lower). -----Examples----- Input 5 7 5 8 6 9 Output Yes Input 5 -1 -2 0 0 -5 Output No Input 5 5 4 3 2 1 Output No Input 5 1000000000 0 0 0 0 Output Yes -----Note----- In the first example, there are five points: (1, 7), (2, 5), (3, 8), (4, 6) and (5, 9). It's possible to draw a line that passes through points 1, 3, 5, and another one that passes through points 2, 4 and is parallel to the first one. In the second example, while it's possible to draw two lines that cover all points, they cannot be made parallel. In the third example, it's impossible to satisfy both requirements at the same time.
import sys n = int(input()) arr = list(map(int, input().split())) com = [(0, 1), (0, 2), (1, 2)] for i in com: a = (arr[i[0]] - arr[i[1]]) / (i[0] - i[1]) b1 = arr[i[0]] - a * (i[0] + 1) b2 = b1 flag = True for j in range(len(arr)): if arr[j] != a * (j + 1) + b1 and b2 == b1: b2 = arr[j] - a * (j + 1) elif arr[j] != a * (j + 1) + b1 and arr[j] != a * (j + 1) + b2: flag = False break if flag == True and b2 != b1: print("Yes") sys.exit(0) print("No")
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FOR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR BIN_OP VAR BIN_OP VAR NUMBER IF VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER IF VAR NUMBER VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR STRING
Connect the countless points with lines, till we reach the faraway yonder. There are n points on a coordinate plane, the i-th of which being (i, y_{i}). Determine whether it's possible to draw two parallel and non-overlapping lines, such that every point in the set lies on exactly one of them, and each of them passes through at least one point in the set. -----Input----- The first line of input contains a positive integer n (3 ≀ n ≀ 1 000) β€” the number of points. The second line contains n space-separated integers y_1, y_2, ..., y_{n} ( - 10^9 ≀ y_{i} ≀ 10^9) β€” the vertical coordinates of each point. -----Output----- Output "Yes" (without quotes) if it's possible to fulfill the requirements, and "No" otherwise. You can print each letter in any case (upper or lower). -----Examples----- Input 5 7 5 8 6 9 Output Yes Input 5 -1 -2 0 0 -5 Output No Input 5 5 4 3 2 1 Output No Input 5 1000000000 0 0 0 0 Output Yes -----Note----- In the first example, there are five points: (1, 7), (2, 5), (3, 8), (4, 6) and (5, 9). It's possible to draw a line that passes through points 1, 3, 5, and another one that passes through points 2, 4 and is parallel to the first one. In the second example, while it's possible to draw two lines that cover all points, they cannot be made parallel. In the third example, it's impossible to satisfy both requirements at the same time.
def test(id1, id2, l, n): a = l[id1] - l[id2] b = id2 - id1 c = id1 * l[id2] - id2 * l[id1] d = [] for i in range(n): if a * i + b * l[i] + c != 0: d += [i] if len(d) == 0: return False if len(d) == 1: return True aa = l[d[0]] - l[d[1]] bb = d[1] - d[0] cc = d[0] * l[d[1]] - d[1] * l[d[0]] for i in range(len(d)): if aa * d[i] + bb * l[d[i]] + cc != 0: return False return (l[id1] - l[id2]) / (id1 - id2) == (l[d[1]] - l[d[0]]) / (d[1] - d[0]) n = int(input()) l = [int(i) for i in input().split()] print("Yes" if test(0, 1, l, n) or test(1, 2, l, n) or test(0, 2, l, n) else "No")
FUNC_DEF ASSIGN VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR VAR VAR NUMBER VAR LIST VAR IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER BIN_OP VAR NUMBER VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR NUMBER RETURN NUMBER RETURN BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER NUMBER VAR VAR FUNC_CALL VAR NUMBER NUMBER VAR VAR FUNC_CALL VAR NUMBER NUMBER VAR VAR STRING STRING
Connect the countless points with lines, till we reach the faraway yonder. There are n points on a coordinate plane, the i-th of which being (i, y_{i}). Determine whether it's possible to draw two parallel and non-overlapping lines, such that every point in the set lies on exactly one of them, and each of them passes through at least one point in the set. -----Input----- The first line of input contains a positive integer n (3 ≀ n ≀ 1 000) β€” the number of points. The second line contains n space-separated integers y_1, y_2, ..., y_{n} ( - 10^9 ≀ y_{i} ≀ 10^9) β€” the vertical coordinates of each point. -----Output----- Output "Yes" (without quotes) if it's possible to fulfill the requirements, and "No" otherwise. You can print each letter in any case (upper or lower). -----Examples----- Input 5 7 5 8 6 9 Output Yes Input 5 -1 -2 0 0 -5 Output No Input 5 5 4 3 2 1 Output No Input 5 1000000000 0 0 0 0 Output Yes -----Note----- In the first example, there are five points: (1, 7), (2, 5), (3, 8), (4, 6) and (5, 9). It's possible to draw a line that passes through points 1, 3, 5, and another one that passes through points 2, 4 and is parallel to the first one. In the second example, while it's possible to draw two lines that cover all points, they cannot be made parallel. In the third example, it's impossible to satisfy both requirements at the same time.
n = int(input()) l = [(int(i) * 2) for i in input().split()] pzbl = [l[1] - l[0], (l[2] - l[0]) // 2, l[2] - l[1]] for slope in pzbl: z = [(l[i] - slope * i) for i in range(n)] if len(set(z)) == 2: print("Yes") exit() print("No")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST BIN_OP VAR NUMBER VAR NUMBER BIN_OP BIN_OP VAR NUMBER VAR NUMBER NUMBER BIN_OP VAR NUMBER VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR STRING
Connect the countless points with lines, till we reach the faraway yonder. There are n points on a coordinate plane, the i-th of which being (i, y_{i}). Determine whether it's possible to draw two parallel and non-overlapping lines, such that every point in the set lies on exactly one of them, and each of them passes through at least one point in the set. -----Input----- The first line of input contains a positive integer n (3 ≀ n ≀ 1 000) β€” the number of points. The second line contains n space-separated integers y_1, y_2, ..., y_{n} ( - 10^9 ≀ y_{i} ≀ 10^9) β€” the vertical coordinates of each point. -----Output----- Output "Yes" (without quotes) if it's possible to fulfill the requirements, and "No" otherwise. You can print each letter in any case (upper or lower). -----Examples----- Input 5 7 5 8 6 9 Output Yes Input 5 -1 -2 0 0 -5 Output No Input 5 5 4 3 2 1 Output No Input 5 1000000000 0 0 0 0 Output Yes -----Note----- In the first example, there are five points: (1, 7), (2, 5), (3, 8), (4, 6) and (5, 9). It's possible to draw a line that passes through points 1, 3, 5, and another one that passes through points 2, 4 and is parallel to the first one. In the second example, while it's possible to draw two lines that cover all points, they cannot be made parallel. In the third example, it's impossible to satisfy both requirements at the same time.
n = int(input()) a = list(map(int, input().split())) flag = 0 for i in range(1, n): k = set() xdif = i ydif = a[i] - a[0] k.add(a[0] * xdif) for j in range(n): k.add(a[j] * xdif - ydif * j) if len(k) == 2: flag = 1 break xdif = 1 ydif = a[2] - a[1] k = set() k.add(a[1] * xdif - ydif) for j in range(n): k.add(a[j] * xdif - ydif * j) if len(k) == 2: flag = 1 if flag: print("Yes") else: print("No")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Connect the countless points with lines, till we reach the faraway yonder. There are n points on a coordinate plane, the i-th of which being (i, y_{i}). Determine whether it's possible to draw two parallel and non-overlapping lines, such that every point in the set lies on exactly one of them, and each of them passes through at least one point in the set. -----Input----- The first line of input contains a positive integer n (3 ≀ n ≀ 1 000) β€” the number of points. The second line contains n space-separated integers y_1, y_2, ..., y_{n} ( - 10^9 ≀ y_{i} ≀ 10^9) β€” the vertical coordinates of each point. -----Output----- Output "Yes" (without quotes) if it's possible to fulfill the requirements, and "No" otherwise. You can print each letter in any case (upper or lower). -----Examples----- Input 5 7 5 8 6 9 Output Yes Input 5 -1 -2 0 0 -5 Output No Input 5 5 4 3 2 1 Output No Input 5 1000000000 0 0 0 0 Output Yes -----Note----- In the first example, there are five points: (1, 7), (2, 5), (3, 8), (4, 6) and (5, 9). It's possible to draw a line that passes through points 1, 3, 5, and another one that passes through points 2, 4 and is parallel to the first one. In the second example, while it's possible to draw two lines that cover all points, they cannot be made parallel. In the third example, it's impossible to satisfy both requirements at the same time.
def calculate_line(first_point, second_point): first_x = first_point[0] first_y = first_point[1] second_x = second_point[0] second_y = second_point[1] slope = (second_y - first_y) / (second_x - first_x) const = first_y - slope * first_x return slope, const def is_on_line(line, current_point): point_x = current_point[0] point_y = current_point[1] slope = line[0] const = line[1] if point_y == point_x * slope + const: return True else: return False def parallel_line(line, current_point): point_x = current_point[0] point_y = current_point[1] slope = line[0] const = point_y - slope * point_x return slope, const points_number = int(input()) pointsY = input().split() points = [] for i in range(points_number): point = i + 1, int(pointsY[i]), [] points.append(point) triangle_vertices = [points[0], points[1]] first_line = calculate_line(triangle_vertices[0], triangle_vertices[1]) all_on_line = True for i in range(2, points_number): if not is_on_line(first_line, points[i]): triangle_vertices.append(points[i]) all_on_line = False break if all_on_line: print("No") exit() lines = [] for i in range(3): first_point = triangle_vertices[i % 3] second_point = triangle_vertices[(i + 1) % 3] third_point = triangle_vertices[(i + 2) % 3] line = calculate_line(first_point, second_point) para_line = parallel_line(line, third_point) lines.append(line) lines.append(para_line) for i in range(points_number): current_point = points[i] for j in range(3): if is_on_line(lines[2 * j], current_point) or is_on_line( lines[2 * j + 1], current_point ): current_point[2].append(j) line_set = [0, 0, 0] for i in range(points_number): for e in points[i][2]: line_set[int(e)] += 1 if points_number in line_set: print("Yes") else: print("No")
FUNC_DEF ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR RETURN VAR VAR FUNC_DEF ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR BIN_OP BIN_OP VAR VAR VAR RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR RETURN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR LIST EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR VAR BIN_OP NUMBER VAR VAR FUNC_CALL VAR VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR VAR VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Connect the countless points with lines, till we reach the faraway yonder. There are n points on a coordinate plane, the i-th of which being (i, y_{i}). Determine whether it's possible to draw two parallel and non-overlapping lines, such that every point in the set lies on exactly one of them, and each of them passes through at least one point in the set. -----Input----- The first line of input contains a positive integer n (3 ≀ n ≀ 1 000) β€” the number of points. The second line contains n space-separated integers y_1, y_2, ..., y_{n} ( - 10^9 ≀ y_{i} ≀ 10^9) β€” the vertical coordinates of each point. -----Output----- Output "Yes" (without quotes) if it's possible to fulfill the requirements, and "No" otherwise. You can print each letter in any case (upper or lower). -----Examples----- Input 5 7 5 8 6 9 Output Yes Input 5 -1 -2 0 0 -5 Output No Input 5 5 4 3 2 1 Output No Input 5 1000000000 0 0 0 0 Output Yes -----Note----- In the first example, there are five points: (1, 7), (2, 5), (3, 8), (4, 6) and (5, 9). It's possible to draw a line that passes through points 1, 3, 5, and another one that passes through points 2, 4 and is parallel to the first one. In the second example, while it's possible to draw two lines that cover all points, they cannot be made parallel. In the third example, it's impossible to satisfy both requirements at the same time.
input() y = list(map(int, input().split())) def check(d): return len(set(j - d * i for i, j in enumerate(y))) == 2 d = (y[2] - y[0]) / 2, y[1] - y[0], y[2] - y[1] print("yes" if any(check(dx) for dx in d) else "no")
EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER NUMBER BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR STRING STRING
Connect the countless points with lines, till we reach the faraway yonder. There are n points on a coordinate plane, the i-th of which being (i, y_{i}). Determine whether it's possible to draw two parallel and non-overlapping lines, such that every point in the set lies on exactly one of them, and each of them passes through at least one point in the set. -----Input----- The first line of input contains a positive integer n (3 ≀ n ≀ 1 000) β€” the number of points. The second line contains n space-separated integers y_1, y_2, ..., y_{n} ( - 10^9 ≀ y_{i} ≀ 10^9) β€” the vertical coordinates of each point. -----Output----- Output "Yes" (without quotes) if it's possible to fulfill the requirements, and "No" otherwise. You can print each letter in any case (upper or lower). -----Examples----- Input 5 7 5 8 6 9 Output Yes Input 5 -1 -2 0 0 -5 Output No Input 5 5 4 3 2 1 Output No Input 5 1000000000 0 0 0 0 Output Yes -----Note----- In the first example, there are five points: (1, 7), (2, 5), (3, 8), (4, 6) and (5, 9). It's possible to draw a line that passes through points 1, 3, 5, and another one that passes through points 2, 4 and is parallel to the first one. In the second example, while it's possible to draw two lines that cover all points, they cannot be made parallel. In the third example, it's impossible to satisfy both requirements at the same time.
def f(m, c1, c2, l, n): fl = True for i in range(n): if l[i] - (m1 * i + m1) != c1 and l[i] - (m1 * i + m1) != c2: fl = False break return fl and c1 != c2 n = int(input()) l = list(map(int, input().split())) m1 = l[1] - l[0] c1 = l[0] - m1 c2 = c1 for i in range(n): if l[i] - m1 * (i + 1) != c1: c2 = l[i] - m1 * (i + 1) f1 = f(m1, c1, c2, l, n) m1 = l[1] - l[0] c1 = l[0] - m1 c2 = l[2] - m1 * 3 f2 = f(m1, c1, c2, l, n) m1 = (l[2] - l[0]) / 2 c1 = l[0] - m1 c2 = l[1] - m1 * 2 f3 = f(m1, c1, c2, l, n) m1 = l[2] - l[1] c1 = l[0] - m1 c2 = l[1] - m1 * 2 f4 = f(m1, c1, c2, l, n) if f1 or f2 or f3 or f4: print("Yes") else: print("No")
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR ASSIGN VAR NUMBER RETURN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Connect the countless points with lines, till we reach the faraway yonder. There are n points on a coordinate plane, the i-th of which being (i, y_{i}). Determine whether it's possible to draw two parallel and non-overlapping lines, such that every point in the set lies on exactly one of them, and each of them passes through at least one point in the set. -----Input----- The first line of input contains a positive integer n (3 ≀ n ≀ 1 000) β€” the number of points. The second line contains n space-separated integers y_1, y_2, ..., y_{n} ( - 10^9 ≀ y_{i} ≀ 10^9) β€” the vertical coordinates of each point. -----Output----- Output "Yes" (without quotes) if it's possible to fulfill the requirements, and "No" otherwise. You can print each letter in any case (upper or lower). -----Examples----- Input 5 7 5 8 6 9 Output Yes Input 5 -1 -2 0 0 -5 Output No Input 5 5 4 3 2 1 Output No Input 5 1000000000 0 0 0 0 Output Yes -----Note----- In the first example, there are five points: (1, 7), (2, 5), (3, 8), (4, 6) and (5, 9). It's possible to draw a line that passes through points 1, 3, 5, and another one that passes through points 2, 4 and is parallel to the first one. In the second example, while it's possible to draw two lines that cover all points, they cannot be made parallel. In the third example, it's impossible to satisfy both requirements at the same time.
points = int(input()) y = list(map(int, input().split())) def slope(p1, p2): return (p2[1] - p1[1]) / (p2[0] - p1[0]) def passes(one, two, point): return 0 == one[0] * (two[1] - point[1]) + two[0] * (point[1] - one[1]) + point[ 0 ] * (one[1] - two[1]) def possible(start, joint, coords): others = list() for point in coords: if not passes(start, joint, point): others.append(point) if len(others) == 0: return False, others elif len(others) == 1: return True, others elif len(others) >= 2: other1, other2 = others[0], others[1] for point in others: if not passes(other1, other2, point): return False, others if slope(other1, other2) == slope(start, joint): return True, others else: return False, others coords = [(k + 1, y[k]) for k in range(points)] start = coords.pop(0) poss, others = possible(start, coords[0], coords) if not poss and len(others) > 0: poss |= possible(start, others[0], coords)[0] if not poss: poss |= possible(coords[0], coords[1], coords + [start])[0] if poss: print("Yes") else: print("No")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN BIN_OP BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER FUNC_DEF RETURN NUMBER BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR FOR VAR VAR IF FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER VAR IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR NUMBER FOR VAR VAR IF FUNC_CALL VAR VAR VAR VAR RETURN NUMBER VAR IF FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR RETURN NUMBER VAR RETURN NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR NUMBER VAR IF VAR FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER BIN_OP VAR LIST VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Connect the countless points with lines, till we reach the faraway yonder. There are n points on a coordinate plane, the i-th of which being (i, y_{i}). Determine whether it's possible to draw two parallel and non-overlapping lines, such that every point in the set lies on exactly one of them, and each of them passes through at least one point in the set. -----Input----- The first line of input contains a positive integer n (3 ≀ n ≀ 1 000) β€” the number of points. The second line contains n space-separated integers y_1, y_2, ..., y_{n} ( - 10^9 ≀ y_{i} ≀ 10^9) β€” the vertical coordinates of each point. -----Output----- Output "Yes" (without quotes) if it's possible to fulfill the requirements, and "No" otherwise. You can print each letter in any case (upper or lower). -----Examples----- Input 5 7 5 8 6 9 Output Yes Input 5 -1 -2 0 0 -5 Output No Input 5 5 4 3 2 1 Output No Input 5 1000000000 0 0 0 0 Output Yes -----Note----- In the first example, there are five points: (1, 7), (2, 5), (3, 8), (4, 6) and (5, 9). It's possible to draw a line that passes through points 1, 3, 5, and another one that passes through points 2, 4 and is parallel to the first one. In the second example, while it's possible to draw two lines that cover all points, they cannot be made parallel. In the third example, it's impossible to satisfy both requirements at the same time.
from sys import stdin def slop(xs, ys): try: return (ys[1] - ys[0]) / (xs[1] - xs[0]) except: return float("inf") Eps = 10**-8 add_vec = lambda v1, v2, dist: [v1[0] + v2[0] * dist, v1[1] + v2[1] * dist] sub_vec = lambda v1, v2: [v2[0] - v1[0], v2[1] - v1[1]] unit_vec = lambda xs, ys, dist: [(xs[1] - xs[0]) / dist, (ys[1] - ys[0]) / dist] dot_prod = lambda v1, v2: v1[0] * v2[0] + v1[1] * v2[1] cross_prod = lambda v1, v2: v1[0] * v2[1] - v2[0] * v1[1] collinear = lambda v1, v2, v3: abs(cross_prod(sub_vec(v1, v2), sub_vec(v1, v3))) < Eps point_on_ray = ( lambda v1, v2, v3: collinear(v1, v2, v3) and dot_prod(sub_vec(v1, v2), sub_vec(v1, v3)) > 0 ) point_in_segment = lambda v1, v2, v3: point_on_ray(v1, v2, v3) or point_on_ray( v2, v1, v3 ) rints = lambda: [int(x) for x in stdin.readline().split()] point_in_line = lambda a, b, c, p: a * p[0] + b * p[1] + c n, a = int(input()), rints() if not collinear([1, a[0]], [2, a[1]], [3, a[2]]): tem = 0 for i in range(3, n): if collinear([2, a[1]], [3, a[2]], [i + 1, a[i]]): tem += 1 else: break if tem == n - 3: print("YES") exit() for i in range(1, n): tem = [] for j in range(1, n): if j != i: if not collinear([1, a[0]], [i + 1, a[i]], [j + 1, a[j]]): if len(tem) < 2: tem.append([j + 1, a[j]]) elif not collinear(tem[0], tem[1], [j + 1, a[j]]): tem = [] break if len(tem) == 1: print("YES") exit() elif len(tem) == 2 and slop([1, i + 1], [a[0], a[i]]) == slop( [tem[0][0], tem[1][0]], [tem[0][1], tem[1][1]] ): print("YES") exit() print("NO")
FUNC_DEF RETURN BIN_OP BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER RETURN FUNC_CALL VAR STRING ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR LIST BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR ASSIGN VAR LIST BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR LIST BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR IF FUNC_CALL VAR LIST NUMBER VAR NUMBER LIST NUMBER VAR NUMBER LIST NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF FUNC_CALL VAR LIST NUMBER VAR NUMBER LIST NUMBER VAR NUMBER LIST BIN_OP VAR NUMBER VAR VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR IF FUNC_CALL VAR LIST NUMBER VAR NUMBER LIST BIN_OP VAR NUMBER VAR VAR LIST BIN_OP VAR NUMBER VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR LIST BIN_OP VAR NUMBER VAR VAR IF FUNC_CALL VAR VAR NUMBER VAR NUMBER LIST BIN_OP VAR NUMBER VAR VAR ASSIGN VAR LIST IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR LIST NUMBER BIN_OP VAR NUMBER LIST VAR NUMBER VAR VAR FUNC_CALL VAR LIST VAR NUMBER NUMBER VAR NUMBER NUMBER LIST VAR NUMBER NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR STRING
Connect the countless points with lines, till we reach the faraway yonder. There are n points on a coordinate plane, the i-th of which being (i, y_{i}). Determine whether it's possible to draw two parallel and non-overlapping lines, such that every point in the set lies on exactly one of them, and each of them passes through at least one point in the set. -----Input----- The first line of input contains a positive integer n (3 ≀ n ≀ 1 000) β€” the number of points. The second line contains n space-separated integers y_1, y_2, ..., y_{n} ( - 10^9 ≀ y_{i} ≀ 10^9) β€” the vertical coordinates of each point. -----Output----- Output "Yes" (without quotes) if it's possible to fulfill the requirements, and "No" otherwise. You can print each letter in any case (upper or lower). -----Examples----- Input 5 7 5 8 6 9 Output Yes Input 5 -1 -2 0 0 -5 Output No Input 5 5 4 3 2 1 Output No Input 5 1000000000 0 0 0 0 Output Yes -----Note----- In the first example, there are five points: (1, 7), (2, 5), (3, 8), (4, 6) and (5, 9). It's possible to draw a line that passes through points 1, 3, 5, and another one that passes through points 2, 4 and is parallel to the first one. In the second example, while it's possible to draw two lines that cover all points, they cannot be made parallel. In the third example, it's impossible to satisfy both requirements at the same time.
n = int(input()) lis = list(map(int, input().split())) slp = [0] * 3 slp[0] = lis[1] - lis[0] slp[1] = (lis[2] - lis[0]) / 2 slp[2] = lis[2] - lis[1] for i in range(3): tmp = [] for j in range(n): tmp.append(-slp[i] * (j + 1) + lis[j]) if len(set(tmp)) == 2: print("YES") exit() print("NO")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER BIN_OP BIN_OP VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER VAR VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR STRING
Connect the countless points with lines, till we reach the faraway yonder. There are n points on a coordinate plane, the i-th of which being (i, y_{i}). Determine whether it's possible to draw two parallel and non-overlapping lines, such that every point in the set lies on exactly one of them, and each of them passes through at least one point in the set. -----Input----- The first line of input contains a positive integer n (3 ≀ n ≀ 1 000) β€” the number of points. The second line contains n space-separated integers y_1, y_2, ..., y_{n} ( - 10^9 ≀ y_{i} ≀ 10^9) β€” the vertical coordinates of each point. -----Output----- Output "Yes" (without quotes) if it's possible to fulfill the requirements, and "No" otherwise. You can print each letter in any case (upper or lower). -----Examples----- Input 5 7 5 8 6 9 Output Yes Input 5 -1 -2 0 0 -5 Output No Input 5 5 4 3 2 1 Output No Input 5 1000000000 0 0 0 0 Output Yes -----Note----- In the first example, there are five points: (1, 7), (2, 5), (3, 8), (4, 6) and (5, 9). It's possible to draw a line that passes through points 1, 3, 5, and another one that passes through points 2, 4 and is parallel to the first one. In the second example, while it's possible to draw two lines that cover all points, they cannot be made parallel. In the third example, it's impossible to satisfy both requirements at the same time.
n = int(input()) d = list(map(int, input().split())) a, b, c = d[:3] if b - a == c - b: e = b - a f = 0 for i in range(3, n): if (d[i] - c) / (i - 2) != e: if f and (d[i] - g) / (i - h) != e: print("No") exit() else: g, h = d[i], i f = 1 print("Yes" if f else "No") else: p1 = p2 = p3 = 1 e, f, g = b - a, c, 2 h, j, k = c - b, a, 0 l, m, o = (c - a) / 2, b, 1 for i in range(3, n): if (d[i] - b) / (i - 1) != e and (d[i] - f) / (i - g) != e: p1 = 0 if (d[i] - c) / (i - 2) != h and (d[i] - j) / (i - k) != h: p2 = 0 if (d[i] - c) / (i - 2) != l and (d[i] - m) / (i - o) != l: p3 = 0 print("Yes" if p1 + p2 + p3 else "No")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR NUMBER IF BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR IF VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR STRING STRING ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR NUMBER IF BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR NUMBER IF BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR STRING STRING
Connect the countless points with lines, till we reach the faraway yonder. There are n points on a coordinate plane, the i-th of which being (i, y_{i}). Determine whether it's possible to draw two parallel and non-overlapping lines, such that every point in the set lies on exactly one of them, and each of them passes through at least one point in the set. -----Input----- The first line of input contains a positive integer n (3 ≀ n ≀ 1 000) β€” the number of points. The second line contains n space-separated integers y_1, y_2, ..., y_{n} ( - 10^9 ≀ y_{i} ≀ 10^9) β€” the vertical coordinates of each point. -----Output----- Output "Yes" (without quotes) if it's possible to fulfill the requirements, and "No" otherwise. You can print each letter in any case (upper or lower). -----Examples----- Input 5 7 5 8 6 9 Output Yes Input 5 -1 -2 0 0 -5 Output No Input 5 5 4 3 2 1 Output No Input 5 1000000000 0 0 0 0 Output Yes -----Note----- In the first example, there are five points: (1, 7), (2, 5), (3, 8), (4, 6) and (5, 9). It's possible to draw a line that passes through points 1, 3, 5, and another one that passes through points 2, 4 and is parallel to the first one. In the second example, while it's possible to draw two lines that cover all points, they cannot be made parallel. In the third example, it's impossible to satisfy both requirements at the same time.
n = int(input()) a = list(map(int, input().split())) anss = 0 for i in range(1, n): ans = 0 k = -1 m = -1 j = 1 while k == -1 and j < n: if i * (a[j] - a[0]) != j * (a[i] - a[0]): k = j j = j + 1 while j < n and m == -1: if i * (a[j] - a[0]) != j * (a[i] - a[0]): if i * (a[j] - a[k]) != (j - k) * (a[i] - a[0]): m = 1 j = j + 1 if m == -1 and k != -1: anss = 1 if anss == 1: print("Yes") else: i = 0 if (i - 1) * (a[2] - a[1]) != a[i] - a[1]: anss = 1 for i in range(3, n): if (i - 1) * (a[2] - a[1]) != a[i] - a[1]: anss = -1 if anss == 1: print("Yes") else: print("No")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER VAR VAR IF BIN_OP VAR BIN_OP VAR VAR VAR NUMBER BIN_OP VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR VAR NUMBER IF BIN_OP VAR BIN_OP VAR VAR VAR NUMBER BIN_OP VAR BIN_OP VAR VAR VAR NUMBER IF BIN_OP VAR BIN_OP VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER IF BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Connect the countless points with lines, till we reach the faraway yonder. There are n points on a coordinate plane, the i-th of which being (i, y_{i}). Determine whether it's possible to draw two parallel and non-overlapping lines, such that every point in the set lies on exactly one of them, and each of them passes through at least one point in the set. -----Input----- The first line of input contains a positive integer n (3 ≀ n ≀ 1 000) β€” the number of points. The second line contains n space-separated integers y_1, y_2, ..., y_{n} ( - 10^9 ≀ y_{i} ≀ 10^9) β€” the vertical coordinates of each point. -----Output----- Output "Yes" (without quotes) if it's possible to fulfill the requirements, and "No" otherwise. You can print each letter in any case (upper or lower). -----Examples----- Input 5 7 5 8 6 9 Output Yes Input 5 -1 -2 0 0 -5 Output No Input 5 5 4 3 2 1 Output No Input 5 1000000000 0 0 0 0 Output Yes -----Note----- In the first example, there are five points: (1, 7), (2, 5), (3, 8), (4, 6) and (5, 9). It's possible to draw a line that passes through points 1, 3, 5, and another one that passes through points 2, 4 and is parallel to the first one. In the second example, while it's possible to draw two lines that cover all points, they cannot be made parallel. In the third example, it's impossible to satisfy both requirements at the same time.
def run(): n = int(input()) a = [int(x) for x in input().split()] _s = set(a) if len(_s) == 1: print("No") return if len(_s) == 2: print("Yes") return def check(dy, base): st = [False] * n for i in range(n): if (a[i] - a[base]) * 2 == dy * (i - base): st[i] = True for i, s in enumerate(st): if not s: newbase = i break else: return False base = newbase for i in range(n): if (a[i] - a[base]) * 2 == dy * (i - base): st[i] = True return not False in st if ( check((a[1] - a[0]) * 2, 0) or check((a[2] - a[1]) * 2, 1) or check(a[2] - a[0], 0) ): print("Yes") else: print("No") run()
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING RETURN IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING RETURN FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP VAR VAR VAR VAR NUMBER BIN_OP VAR BIN_OP VAR VAR ASSIGN VAR VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR ASSIGN VAR VAR RETURN NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP VAR VAR VAR VAR NUMBER BIN_OP VAR BIN_OP VAR VAR ASSIGN VAR VAR NUMBER RETURN NUMBER VAR IF FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER NUMBER NUMBER FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER NUMBER NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR
Connect the countless points with lines, till we reach the faraway yonder. There are n points on a coordinate plane, the i-th of which being (i, y_{i}). Determine whether it's possible to draw two parallel and non-overlapping lines, such that every point in the set lies on exactly one of them, and each of them passes through at least one point in the set. -----Input----- The first line of input contains a positive integer n (3 ≀ n ≀ 1 000) β€” the number of points. The second line contains n space-separated integers y_1, y_2, ..., y_{n} ( - 10^9 ≀ y_{i} ≀ 10^9) β€” the vertical coordinates of each point. -----Output----- Output "Yes" (without quotes) if it's possible to fulfill the requirements, and "No" otherwise. You can print each letter in any case (upper or lower). -----Examples----- Input 5 7 5 8 6 9 Output Yes Input 5 -1 -2 0 0 -5 Output No Input 5 5 4 3 2 1 Output No Input 5 1000000000 0 0 0 0 Output Yes -----Note----- In the first example, there are five points: (1, 7), (2, 5), (3, 8), (4, 6) and (5, 9). It's possible to draw a line that passes through points 1, 3, 5, and another one that passes through points 2, 4 and is parallel to the first one. In the second example, while it's possible to draw two lines that cover all points, they cannot be made parallel. In the third example, it's impossible to satisfy both requirements at the same time.
n = int(input()) y = list(map(int, input().split())) for i in range(1, n): a = [] for j in range(n): if (y[j] - y[0]) * i != (y[i] - y[0]) * j: a.append(j) if a: ok = len(a) < 2 or (y[i] - y[0]) * (a[1] - a[0]) == (y[a[1]] - y[a[0]]) * i for j in range(2, len(a)): ok &= (y[a[j]] - y[a[0]]) * (a[1] - a[0]) == (y[a[1]] - y[a[0]]) * ( a[j] - a[0] ) if ok: print("Yes") exit() y = y[::-1] for i in range(1, n): a = [] for j in range(n): if (y[j] - y[0]) * i != (y[i] - y[0]) * j: a.append(j) if a: ok = len(a) < 2 or (y[i] - y[0]) * (a[1] - a[0]) == (y[a[1]] - y[a[0]]) * i for j in range(2, len(a)): ok &= (y[a[j]] - y[a[0]]) * (a[1] - a[0]) == (y[a[1]] - y[a[0]]) * ( a[j] - a[0] ) if ok: print("Yes") exit() print("No")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP VAR VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR IF VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER BIN_OP BIN_OP VAR VAR VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR VAR NUMBER BIN_OP VAR VAR VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP VAR VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR IF VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER BIN_OP BIN_OP VAR VAR VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR VAR NUMBER BIN_OP VAR VAR VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR STRING
Connect the countless points with lines, till we reach the faraway yonder. There are n points on a coordinate plane, the i-th of which being (i, y_{i}). Determine whether it's possible to draw two parallel and non-overlapping lines, such that every point in the set lies on exactly one of them, and each of them passes through at least one point in the set. -----Input----- The first line of input contains a positive integer n (3 ≀ n ≀ 1 000) β€” the number of points. The second line contains n space-separated integers y_1, y_2, ..., y_{n} ( - 10^9 ≀ y_{i} ≀ 10^9) β€” the vertical coordinates of each point. -----Output----- Output "Yes" (without quotes) if it's possible to fulfill the requirements, and "No" otherwise. You can print each letter in any case (upper or lower). -----Examples----- Input 5 7 5 8 6 9 Output Yes Input 5 -1 -2 0 0 -5 Output No Input 5 5 4 3 2 1 Output No Input 5 1000000000 0 0 0 0 Output Yes -----Note----- In the first example, there are five points: (1, 7), (2, 5), (3, 8), (4, 6) and (5, 9). It's possible to draw a line that passes through points 1, 3, 5, and another one that passes through points 2, 4 and is parallel to the first one. In the second example, while it's possible to draw two lines that cover all points, they cannot be made parallel. In the third example, it's impossible to satisfy both requirements at the same time.
import sys input = sys.stdin.readline n = int(input()) y = [-1] + list(map(int, input().split())) for v in range(2, n + 1): a1 = (y[v] - y[1]) / (v - 1) b1 = y[1] - a1 * 1 not_on = [] flag = True for i in range(1, n + 1): if a1 * i + b1 != y[i]: not_on.append(i) if len(not_on) == 0: print("NO") exit() elif len(not_on) == 1: print("YES") exit() else: ii, jj = not_on[0], not_on[1] a2 = (y[jj] - y[ii]) / (jj - ii) b2 = y[ii] - a2 * ii for i in not_on: if a2 * i + b2 != y[i]: flag = False if flag and a1 == a2 and b1 != b2: print("YES") exit() a1 = (y[3] - y[2]) / (3 - 2) b1 = y[2] - a1 * 2 for i in range(2, n + 1): if a1 * i + b1 != y[i]: print("NO") exit() print("YES")
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP BIN_OP VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR BIN_OP VAR VAR FOR VAR VAR IF BIN_OP BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP BIN_OP VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR STRING
Connect the countless points with lines, till we reach the faraway yonder. There are n points on a coordinate plane, the i-th of which being (i, y_{i}). Determine whether it's possible to draw two parallel and non-overlapping lines, such that every point in the set lies on exactly one of them, and each of them passes through at least one point in the set. -----Input----- The first line of input contains a positive integer n (3 ≀ n ≀ 1 000) β€” the number of points. The second line contains n space-separated integers y_1, y_2, ..., y_{n} ( - 10^9 ≀ y_{i} ≀ 10^9) β€” the vertical coordinates of each point. -----Output----- Output "Yes" (without quotes) if it's possible to fulfill the requirements, and "No" otherwise. You can print each letter in any case (upper or lower). -----Examples----- Input 5 7 5 8 6 9 Output Yes Input 5 -1 -2 0 0 -5 Output No Input 5 5 4 3 2 1 Output No Input 5 1000000000 0 0 0 0 Output Yes -----Note----- In the first example, there are five points: (1, 7), (2, 5), (3, 8), (4, 6) and (5, 9). It's possible to draw a line that passes through points 1, 3, 5, and another one that passes through points 2, 4 and is parallel to the first one. In the second example, while it's possible to draw two lines that cover all points, they cannot be made parallel. In the third example, it's impossible to satisfy both requirements at the same time.
n = int(input()) yi = list(map(int, input().split())) steps = yi[1] - yi[0], (yi[2] - yi[0]) / 2, yi[2] - yi[1] if any( len(set(l)) == 2 for l in [[(y - i * step) for i, y in enumerate(yi)] for step in steps] ): print("Yes") else: print("No")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER BIN_OP BIN_OP VAR NUMBER VAR NUMBER NUMBER BIN_OP VAR NUMBER VAR NUMBER IF FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR BIN_OP VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Connect the countless points with lines, till we reach the faraway yonder. There are n points on a coordinate plane, the i-th of which being (i, y_{i}). Determine whether it's possible to draw two parallel and non-overlapping lines, such that every point in the set lies on exactly one of them, and each of them passes through at least one point in the set. -----Input----- The first line of input contains a positive integer n (3 ≀ n ≀ 1 000) β€” the number of points. The second line contains n space-separated integers y_1, y_2, ..., y_{n} ( - 10^9 ≀ y_{i} ≀ 10^9) β€” the vertical coordinates of each point. -----Output----- Output "Yes" (without quotes) if it's possible to fulfill the requirements, and "No" otherwise. You can print each letter in any case (upper or lower). -----Examples----- Input 5 7 5 8 6 9 Output Yes Input 5 -1 -2 0 0 -5 Output No Input 5 5 4 3 2 1 Output No Input 5 1000000000 0 0 0 0 Output Yes -----Note----- In the first example, there are five points: (1, 7), (2, 5), (3, 8), (4, 6) and (5, 9). It's possible to draw a line that passes through points 1, 3, 5, and another one that passes through points 2, 4 and is parallel to the first one. In the second example, while it's possible to draw two lines that cover all points, they cannot be made parallel. In the third example, it's impossible to satisfy both requirements at the same time.
def judge(slope): global kind global a sub = [] for i, x in enumerate(kind): if x == 1: sub.append(i) n = len(sub) if n == 0: return False elif n == 1: return True else: if slope[1] == 0: slope = a[sub[1]] - a[sub[0]], sub[1] - sub[0] for i in range(1, n): if slope[0] * (sub[i] - sub[0]) != (a[sub[i]] - a[sub[0]]) * slope[1]: return False return True n = int(input()) a = list(map(int, input().split())) kind = [] flg = 0 for i in range(1, n): kind = [1] * n kind[0] = 0 kind[i] = 0 for j in range(1, n): if (a[j] - a[0]) * i == (a[i] - a[0]) * j: kind[j] = 0 if judge((a[i] - a[0], i)): flg = 1 break kind = [1] * n kind[0] = 0 if judge((0, 0)) and a[1] - a[0] != a[2] - a[1]: flg = 1 if flg: print("Yes") else: print("No")
FUNC_DEF ASSIGN VAR LIST FOR VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER IF VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR NUMBER BIN_OP VAR VAR VAR NUMBER BIN_OP BIN_OP VAR VAR VAR VAR VAR NUMBER VAR NUMBER RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP BIN_OP VAR VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR VAR NUMBER VAR ASSIGN VAR VAR NUMBER IF FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER NUMBER IF FUNC_CALL VAR NUMBER NUMBER BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Connect the countless points with lines, till we reach the faraway yonder. There are n points on a coordinate plane, the i-th of which being (i, y_{i}). Determine whether it's possible to draw two parallel and non-overlapping lines, such that every point in the set lies on exactly one of them, and each of them passes through at least one point in the set. -----Input----- The first line of input contains a positive integer n (3 ≀ n ≀ 1 000) β€” the number of points. The second line contains n space-separated integers y_1, y_2, ..., y_{n} ( - 10^9 ≀ y_{i} ≀ 10^9) β€” the vertical coordinates of each point. -----Output----- Output "Yes" (without quotes) if it's possible to fulfill the requirements, and "No" otherwise. You can print each letter in any case (upper or lower). -----Examples----- Input 5 7 5 8 6 9 Output Yes Input 5 -1 -2 0 0 -5 Output No Input 5 5 4 3 2 1 Output No Input 5 1000000000 0 0 0 0 Output Yes -----Note----- In the first example, there are five points: (1, 7), (2, 5), (3, 8), (4, 6) and (5, 9). It's possible to draw a line that passes through points 1, 3, 5, and another one that passes through points 2, 4 and is parallel to the first one. In the second example, while it's possible to draw two lines that cover all points, they cannot be made parallel. In the third example, it's impossible to satisfy both requirements at the same time.
n = int(input()) p = list(map(int, input().split(" "))) rest = [True] * n ct = 0 slp = float("inf") def slope(i, j): return (p[j] - p[i]) / (j - i) def restcol(): l = [i for i in range(n) if rest[i]] if len(l) == 1: return True s = slope(l[0], l[1]) for i in range(2, len(l)): if slope(l[0], l[i]) != s: return False return True def restslp(): l = [i for i in range(n) if rest[i]] if len(l) == 1: return slp return slope(l[0], l[1]) wp0 = {} for i in range(1, n): s = slope(0, i) if s not in wp0: wp0[s] = 0 wp0[s] += 1 for k in wp0: if wp0[k] == n - 1: ct = 2 if wp0[k] >= 2: ct += 1 slp = k if ct > 1: print("No") elif ct == 1: rest[0] = False for i in range(1, n): if slope(0, i) == slp: rest[i] = False if restcol() and restslp() == slp: print("Yes") else: print("No") else: rest[0] = False res = restcol() rest[1] = False res |= restcol() and restslp() == slope(0, 1) rest[1] = True rest[2] = False res |= restcol() and restslp() == slope(0, 2) rest = [True] * n rest[1] = rest[2] = False slp = slope(1, 2) for i in range(3, n): if slope(1, i) == slp: rest[i] = False res |= restcol() and restslp() == slp if res: print("Yes") else: print("No")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING FUNC_DEF RETURN BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER VAR VAR VAR RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER RETURN VAR RETURN FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER FOR VAR VAR IF VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF FUNC_CALL VAR NUMBER VAR VAR ASSIGN VAR VAR NUMBER IF FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF FUNC_CALL VAR NUMBER VAR VAR ASSIGN VAR VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Connect the countless points with lines, till we reach the faraway yonder. There are n points on a coordinate plane, the i-th of which being (i, y_{i}). Determine whether it's possible to draw two parallel and non-overlapping lines, such that every point in the set lies on exactly one of them, and each of them passes through at least one point in the set. -----Input----- The first line of input contains a positive integer n (3 ≀ n ≀ 1 000) β€” the number of points. The second line contains n space-separated integers y_1, y_2, ..., y_{n} ( - 10^9 ≀ y_{i} ≀ 10^9) β€” the vertical coordinates of each point. -----Output----- Output "Yes" (without quotes) if it's possible to fulfill the requirements, and "No" otherwise. You can print each letter in any case (upper or lower). -----Examples----- Input 5 7 5 8 6 9 Output Yes Input 5 -1 -2 0 0 -5 Output No Input 5 5 4 3 2 1 Output No Input 5 1000000000 0 0 0 0 Output Yes -----Note----- In the first example, there are five points: (1, 7), (2, 5), (3, 8), (4, 6) and (5, 9). It's possible to draw a line that passes through points 1, 3, 5, and another one that passes through points 2, 4 and is parallel to the first one. In the second example, while it's possible to draw two lines that cover all points, they cannot be made parallel. In the third example, it's impossible to satisfy both requirements at the same time.
n = int(input()) a = [int(s) for s in input().split()] i, j = 0, 1 while j < n: b = set() k = (a[i] - a[j]) / (i - j) w, key = 0, 1 while len(b) <= 2 and w < n: temp = a[w] - k * w b.add(temp) w += 1 if w == n and len(b) == 2: print("YES") key = 0 i, j = n + 1, n + 1 j += 1 if key: i, j = 1, 2 b = set() k = (a[i] - a[j]) / (i - j) w, key1 = 0, 1 while len(b) <= 2 and w < n: temp = a[w] - k * w b.add(temp) w += 1 if w == n and len(b) == 2: print("YES") key1 = 0 i, j = n + 1, n + 1 if key and key1: print("NO")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER WHILE VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR NUMBER NUMBER WHILE FUNC_CALL VAR VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER IF VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR NUMBER NUMBER WHILE FUNC_CALL VAR VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING
Connect the countless points with lines, till we reach the faraway yonder. There are n points on a coordinate plane, the i-th of which being (i, y_{i}). Determine whether it's possible to draw two parallel and non-overlapping lines, such that every point in the set lies on exactly one of them, and each of them passes through at least one point in the set. -----Input----- The first line of input contains a positive integer n (3 ≀ n ≀ 1 000) β€” the number of points. The second line contains n space-separated integers y_1, y_2, ..., y_{n} ( - 10^9 ≀ y_{i} ≀ 10^9) β€” the vertical coordinates of each point. -----Output----- Output "Yes" (without quotes) if it's possible to fulfill the requirements, and "No" otherwise. You can print each letter in any case (upper or lower). -----Examples----- Input 5 7 5 8 6 9 Output Yes Input 5 -1 -2 0 0 -5 Output No Input 5 5 4 3 2 1 Output No Input 5 1000000000 0 0 0 0 Output Yes -----Note----- In the first example, there are five points: (1, 7), (2, 5), (3, 8), (4, 6) and (5, 9). It's possible to draw a line that passes through points 1, 3, 5, and another one that passes through points 2, 4 and is parallel to the first one. In the second example, while it's possible to draw two lines that cover all points, they cannot be made parallel. In the third example, it's impossible to satisfy both requirements at the same time.
import sys N = int(input()) a = list(map(int, input().split())) sys.setrecursionlimit(1500) def solve(n, slope, d, slope2=None, d2=0, point=None): if n == N: if point is None: return False else: return True if a[n] == slope * n + d: return solve(n + 1, slope, d, slope2, d2, point) elif point is None: return solve(n + 1, slope, d, slope2, d2, point=n) else: slope2 = (a[n] - a[point]) / (n - point) if slope2 != slope: return False d2 = a[point] - point * slope2 return solve(n + 1, slope, d, slope2, d2, point) for i, j in [(0, 1), (1, 2), (0, 2)]: slope = (a[j] - a[i]) / (j - i) d = a[i] - i * slope if solve(0, slope, d): print("Yes") break else: print("No")
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER FUNC_DEF NONE NUMBER NONE IF VAR VAR IF VAR NONE RETURN NUMBER RETURN NUMBER IF VAR VAR BIN_OP BIN_OP VAR VAR VAR RETURN FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR IF VAR NONE RETURN FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR IF VAR VAR RETURN NUMBER ASSIGN VAR BIN_OP VAR VAR BIN_OP VAR VAR RETURN FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR FOR VAR VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR BIN_OP VAR VAR IF FUNC_CALL VAR NUMBER VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Connect the countless points with lines, till we reach the faraway yonder. There are n points on a coordinate plane, the i-th of which being (i, y_{i}). Determine whether it's possible to draw two parallel and non-overlapping lines, such that every point in the set lies on exactly one of them, and each of them passes through at least one point in the set. -----Input----- The first line of input contains a positive integer n (3 ≀ n ≀ 1 000) β€” the number of points. The second line contains n space-separated integers y_1, y_2, ..., y_{n} ( - 10^9 ≀ y_{i} ≀ 10^9) β€” the vertical coordinates of each point. -----Output----- Output "Yes" (without quotes) if it's possible to fulfill the requirements, and "No" otherwise. You can print each letter in any case (upper or lower). -----Examples----- Input 5 7 5 8 6 9 Output Yes Input 5 -1 -2 0 0 -5 Output No Input 5 5 4 3 2 1 Output No Input 5 1000000000 0 0 0 0 Output Yes -----Note----- In the first example, there are five points: (1, 7), (2, 5), (3, 8), (4, 6) and (5, 9). It's possible to draw a line that passes through points 1, 3, 5, and another one that passes through points 2, 4 and is parallel to the first one. In the second example, while it's possible to draw two lines that cover all points, they cannot be made parallel. In the third example, it's impossible to satisfy both requirements at the same time.
n = int(input()) y = list(map(int, input().split())) if n == 2: print("Yes") exit elif n == 1: print("No") exit def check(a, d): for i in range(0, n): a[i] -= i * d if len(set(a)) == 2: return True else: return False if check(y.copy(), y[1] - y[0]): print("Yes") exit elif check(y.copy(), y[2] - y[1]): print("Yes") exit elif check(y.copy(), (y[2] - y[0]) / 2): print("Yes") exit else: print("No")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR VAR FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR BIN_OP VAR VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER RETURN NUMBER RETURN NUMBER IF FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR VAR IF FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR VAR IF FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR VAR EXPR FUNC_CALL VAR STRING
Connect the countless points with lines, till we reach the faraway yonder. There are n points on a coordinate plane, the i-th of which being (i, y_{i}). Determine whether it's possible to draw two parallel and non-overlapping lines, such that every point in the set lies on exactly one of them, and each of them passes through at least one point in the set. -----Input----- The first line of input contains a positive integer n (3 ≀ n ≀ 1 000) β€” the number of points. The second line contains n space-separated integers y_1, y_2, ..., y_{n} ( - 10^9 ≀ y_{i} ≀ 10^9) β€” the vertical coordinates of each point. -----Output----- Output "Yes" (without quotes) if it's possible to fulfill the requirements, and "No" otherwise. You can print each letter in any case (upper or lower). -----Examples----- Input 5 7 5 8 6 9 Output Yes Input 5 -1 -2 0 0 -5 Output No Input 5 5 4 3 2 1 Output No Input 5 1000000000 0 0 0 0 Output Yes -----Note----- In the first example, there are five points: (1, 7), (2, 5), (3, 8), (4, 6) and (5, 9). It's possible to draw a line that passes through points 1, 3, 5, and another one that passes through points 2, 4 and is parallel to the first one. In the second example, while it's possible to draw two lines that cover all points, they cannot be made parallel. In the third example, it's impossible to satisfy both requirements at the same time.
n = eval(input()) a = list(map(eval, input().split())) def check(t): return len(set(2 * y - t * x for x, y in enumerate(a))) == 2 print( "Yes" if any(check(i) for i in [2 * (a[1] - a[0]), 2 * (a[2] - a[1]), a[2] - a[0]]) else "No" )
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR LIST BIN_OP NUMBER BIN_OP VAR NUMBER VAR NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER STRING STRING