description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
Hideo Kojima has just quit his job at Konami. Now he is going to find a new place to work. Despite being such a well-known person, he still needs a CV to apply for a job. During all his career Hideo has produced n games. Some of them were successful, some were not. Hideo wants to remove several of them (possibly zero) from his CV to make a better impression on employers. As a result there should be no unsuccessful game which comes right after successful one in his CV. More formally, you are given an array s_1, s_2, ..., s_{n} of zeros and ones. Zero corresponds to an unsuccessful game, one β€” to a successful one. Games are given in order they were produced, and Hideo can't swap these values. He should remove some elements from this array in such a way that no zero comes right after one. Besides that, Hideo still wants to mention as much games in his CV as possible. Help this genius of a man determine the maximum number of games he can leave in his CV. -----Input----- The first line contains one integer number n (1 ≀ n ≀ 100). The second line contains n space-separated integer numbers s_1, s_2, ..., s_{n} (0 ≀ s_{i} ≀ 1). 0 corresponds to an unsuccessful game, 1 β€” to a successful one. -----Output----- Print one integer β€” the maximum number of games Hideo can leave in his CV so that no unsuccessful game comes after a successful one. -----Examples----- Input 4 1 1 0 1 Output 3 Input 6 0 1 0 0 1 0 Output 4 Input 1 0 Output 1
def solve(n, games): games_to_keep = 0 ones_prefix = [(0) for i in range(n)] if games[0] == "1": ones_prefix[0] = 1 for i in range(1, n): ones_prefix[i] = ones_prefix[i - 1] if games[i] == "1": ones_prefix[i] += 1 def ones_after(pos): return ones_prefix[-1] - ones_prefix[pos] zeros_cnt = 0 for i, game in enumerate(games): if game == "0": zeros_cnt += 1 ones_after_zero = ones_after(i) games_lasts = zeros_cnt + ones_after_zero if games_lasts > games_to_keep: games_to_keep = games_lasts ones_count = ones_prefix[-1] zeros_count = n - ones_count games_to_keep = max(games_to_keep, ones_count, zeros_count) return games_to_keep def main(): n = int(input()) games = input().split() print(solve(n, games)) main()
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR IF VAR NUMBER STRING ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR STRING VAR VAR NUMBER FUNC_DEF RETURN BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR STRING VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR
Hideo Kojima has just quit his job at Konami. Now he is going to find a new place to work. Despite being such a well-known person, he still needs a CV to apply for a job. During all his career Hideo has produced n games. Some of them were successful, some were not. Hideo wants to remove several of them (possibly zero) from his CV to make a better impression on employers. As a result there should be no unsuccessful game which comes right after successful one in his CV. More formally, you are given an array s_1, s_2, ..., s_{n} of zeros and ones. Zero corresponds to an unsuccessful game, one β€” to a successful one. Games are given in order they were produced, and Hideo can't swap these values. He should remove some elements from this array in such a way that no zero comes right after one. Besides that, Hideo still wants to mention as much games in his CV as possible. Help this genius of a man determine the maximum number of games he can leave in his CV. -----Input----- The first line contains one integer number n (1 ≀ n ≀ 100). The second line contains n space-separated integer numbers s_1, s_2, ..., s_{n} (0 ≀ s_{i} ≀ 1). 0 corresponds to an unsuccessful game, 1 β€” to a successful one. -----Output----- Print one integer β€” the maximum number of games Hideo can leave in his CV so that no unsuccessful game comes after a successful one. -----Examples----- Input 4 1 1 0 1 Output 3 Input 6 0 1 0 0 1 0 Output 4 Input 1 0 Output 1
def count(xs, i): return xs[:i].count(0) + xs[i:].count(1) def solve(xs): n = len(xs) return max(count(xs, i) for i in range(n + 1)) def main(): n = int(input()) xs = [int(c) for c in input().split()] assert len(xs) == n result = solve(xs) print(result) main()
FUNC_DEF RETURN BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR RETURN FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
Hideo Kojima has just quit his job at Konami. Now he is going to find a new place to work. Despite being such a well-known person, he still needs a CV to apply for a job. During all his career Hideo has produced n games. Some of them were successful, some were not. Hideo wants to remove several of them (possibly zero) from his CV to make a better impression on employers. As a result there should be no unsuccessful game which comes right after successful one in his CV. More formally, you are given an array s_1, s_2, ..., s_{n} of zeros and ones. Zero corresponds to an unsuccessful game, one β€” to a successful one. Games are given in order they were produced, and Hideo can't swap these values. He should remove some elements from this array in such a way that no zero comes right after one. Besides that, Hideo still wants to mention as much games in his CV as possible. Help this genius of a man determine the maximum number of games he can leave in his CV. -----Input----- The first line contains one integer number n (1 ≀ n ≀ 100). The second line contains n space-separated integer numbers s_1, s_2, ..., s_{n} (0 ≀ s_{i} ≀ 1). 0 corresponds to an unsuccessful game, 1 β€” to a successful one. -----Output----- Print one integer β€” the maximum number of games Hideo can leave in his CV so that no unsuccessful game comes after a successful one. -----Examples----- Input 4 1 1 0 1 Output 3 Input 6 0 1 0 0 1 0 Output 4 Input 1 0 Output 1
import sys n = int(input()) a = list(map(int, input().split())) dp = [[-(10**9), -(10**9)] for _ in range(n + 1)] dp[0][0] = 0 for i, x in enumerate(a): if x == 0: dp[i + 1][0] = dp[i][0] + 1 dp[i + 1][1] = dp[i][1] else: dp[i + 1][0] = dp[i][0] dp[i + 1][1] = max(dp[i][0], dp[i][1]) + 1 print(max(dp[-1]))
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 BIN_OP NUMBER NUMBER BIN_OP NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER
Hideo Kojima has just quit his job at Konami. Now he is going to find a new place to work. Despite being such a well-known person, he still needs a CV to apply for a job. During all his career Hideo has produced n games. Some of them were successful, some were not. Hideo wants to remove several of them (possibly zero) from his CV to make a better impression on employers. As a result there should be no unsuccessful game which comes right after successful one in his CV. More formally, you are given an array s_1, s_2, ..., s_{n} of zeros and ones. Zero corresponds to an unsuccessful game, one β€” to a successful one. Games are given in order they were produced, and Hideo can't swap these values. He should remove some elements from this array in such a way that no zero comes right after one. Besides that, Hideo still wants to mention as much games in his CV as possible. Help this genius of a man determine the maximum number of games he can leave in his CV. -----Input----- The first line contains one integer number n (1 ≀ n ≀ 100). The second line contains n space-separated integer numbers s_1, s_2, ..., s_{n} (0 ≀ s_{i} ≀ 1). 0 corresponds to an unsuccessful game, 1 β€” to a successful one. -----Output----- Print one integer β€” the maximum number of games Hideo can leave in his CV so that no unsuccessful game comes after a successful one. -----Examples----- Input 4 1 1 0 1 Output 3 Input 6 0 1 0 0 1 0 Output 4 Input 1 0 Output 1
n = int(input()) arr = list(map(int, input().split())) ans = arr.count(0) for i in range(1, n + 1): one = 0 ind = -1 j = n - 1 for j in range(n - 1, -1, -1): if one == i: ind = j break if arr[j] == 1: one += 1 else: if one == i: ind = j else: break ans = max(ans, i + arr[: ind + 1].count(0)) print(ans)
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 NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR ASSIGN VAR VAR IF VAR VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR
Hideo Kojima has just quit his job at Konami. Now he is going to find a new place to work. Despite being such a well-known person, he still needs a CV to apply for a job. During all his career Hideo has produced n games. Some of them were successful, some were not. Hideo wants to remove several of them (possibly zero) from his CV to make a better impression on employers. As a result there should be no unsuccessful game which comes right after successful one in his CV. More formally, you are given an array s_1, s_2, ..., s_{n} of zeros and ones. Zero corresponds to an unsuccessful game, one β€” to a successful one. Games are given in order they were produced, and Hideo can't swap these values. He should remove some elements from this array in such a way that no zero comes right after one. Besides that, Hideo still wants to mention as much games in his CV as possible. Help this genius of a man determine the maximum number of games he can leave in his CV. -----Input----- The first line contains one integer number n (1 ≀ n ≀ 100). The second line contains n space-separated integer numbers s_1, s_2, ..., s_{n} (0 ≀ s_{i} ≀ 1). 0 corresponds to an unsuccessful game, 1 β€” to a successful one. -----Output----- Print one integer β€” the maximum number of games Hideo can leave in his CV so that no unsuccessful game comes after a successful one. -----Examples----- Input 4 1 1 0 1 Output 3 Input 6 0 1 0 0 1 0 Output 4 Input 1 0 Output 1
n = int(input()) a = "" count = 0 for j in input().split(): count = count + 1 if a != "" and j == "0": a = a[:-1] count = count - 1 elif j == "1": a = a + j print(count)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR STRING VAR STRING ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR STRING ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
Hideo Kojima has just quit his job at Konami. Now he is going to find a new place to work. Despite being such a well-known person, he still needs a CV to apply for a job. During all his career Hideo has produced n games. Some of them were successful, some were not. Hideo wants to remove several of them (possibly zero) from his CV to make a better impression on employers. As a result there should be no unsuccessful game which comes right after successful one in his CV. More formally, you are given an array s_1, s_2, ..., s_{n} of zeros and ones. Zero corresponds to an unsuccessful game, one β€” to a successful one. Games are given in order they were produced, and Hideo can't swap these values. He should remove some elements from this array in such a way that no zero comes right after one. Besides that, Hideo still wants to mention as much games in his CV as possible. Help this genius of a man determine the maximum number of games he can leave in his CV. -----Input----- The first line contains one integer number n (1 ≀ n ≀ 100). The second line contains n space-separated integer numbers s_1, s_2, ..., s_{n} (0 ≀ s_{i} ≀ 1). 0 corresponds to an unsuccessful game, 1 β€” to a successful one. -----Output----- Print one integer β€” the maximum number of games Hideo can leave in his CV so that no unsuccessful game comes after a successful one. -----Examples----- Input 4 1 1 0 1 Output 3 Input 6 0 1 0 0 1 0 Output 4 Input 1 0 Output 1
def lis(arr): n = len(arr) lis = [1] * n for i in range(1, n): for j in range(0, i): if arr[i] >= arr[j] and lis[i] < lis[j] + 1: lis[i] = lis[j] + 1 maximum = 0 for i in range(n): maximum = max(maximum, lis[i]) return maximum n = int(input()) a = list(map(int, input().split())) print(lis(a))
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR RETURN VAR 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 FUNC_CALL VAR VAR
Hideo Kojima has just quit his job at Konami. Now he is going to find a new place to work. Despite being such a well-known person, he still needs a CV to apply for a job. During all his career Hideo has produced n games. Some of them were successful, some were not. Hideo wants to remove several of them (possibly zero) from his CV to make a better impression on employers. As a result there should be no unsuccessful game which comes right after successful one in his CV. More formally, you are given an array s_1, s_2, ..., s_{n} of zeros and ones. Zero corresponds to an unsuccessful game, one β€” to a successful one. Games are given in order they were produced, and Hideo can't swap these values. He should remove some elements from this array in such a way that no zero comes right after one. Besides that, Hideo still wants to mention as much games in his CV as possible. Help this genius of a man determine the maximum number of games he can leave in his CV. -----Input----- The first line contains one integer number n (1 ≀ n ≀ 100). The second line contains n space-separated integer numbers s_1, s_2, ..., s_{n} (0 ≀ s_{i} ≀ 1). 0 corresponds to an unsuccessful game, 1 β€” to a successful one. -----Output----- Print one integer β€” the maximum number of games Hideo can leave in his CV so that no unsuccessful game comes after a successful one. -----Examples----- Input 4 1 1 0 1 Output 3 Input 6 0 1 0 0 1 0 Output 4 Input 1 0 Output 1
n = int(input()) nums = list(map(int, input().split())) right = [(0) for i in range(n)] for i in range(n - 1, -1, -1): right[i] = nums[i] if i < n - 1: right[i] += right[i + 1] left = [(0) for i in range(n)] for i in range(n): left[i] = nums[i] if i > 0: left[i] += left[i - 1] res = 0 for i in range(-1, n): count = 0 if i >= 0: count = i + 1 - left[i] if i + 1 < n: count += right[i + 1] res = max(res, count) print(res)
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 VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR VAR IF VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR IF VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR VAR IF BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
Hideo Kojima has just quit his job at Konami. Now he is going to find a new place to work. Despite being such a well-known person, he still needs a CV to apply for a job. During all his career Hideo has produced n games. Some of them were successful, some were not. Hideo wants to remove several of them (possibly zero) from his CV to make a better impression on employers. As a result there should be no unsuccessful game which comes right after successful one in his CV. More formally, you are given an array s_1, s_2, ..., s_{n} of zeros and ones. Zero corresponds to an unsuccessful game, one β€” to a successful one. Games are given in order they were produced, and Hideo can't swap these values. He should remove some elements from this array in such a way that no zero comes right after one. Besides that, Hideo still wants to mention as much games in his CV as possible. Help this genius of a man determine the maximum number of games he can leave in his CV. -----Input----- The first line contains one integer number n (1 ≀ n ≀ 100). The second line contains n space-separated integer numbers s_1, s_2, ..., s_{n} (0 ≀ s_{i} ≀ 1). 0 corresponds to an unsuccessful game, 1 β€” to a successful one. -----Output----- Print one integer β€” the maximum number of games Hideo can leave in his CV so that no unsuccessful game comes after a successful one. -----Examples----- Input 4 1 1 0 1 Output 3 Input 6 0 1 0 0 1 0 Output 4 Input 1 0 Output 1
n = int(input()) s = input().split() k = 0 m = 0 for i in range(n): if s[i] == "0": k += 1 x = 0 for j in range(i, n): if s[j] == "1": x += 1 if k + x > m: m = k + x print(m)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR STRING VAR NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
A permutation of size n is an array of size n such that each integer from 1 to n occurs exactly once in this array. An inversion in a permutation p is a pair of indices (i, j) such that i > j and a_{i} < a_{j}. For example, a permutation [4, 1, 3, 2] contains 4 inversions: (2, 1), (3, 1), (4, 1), (4, 3). You are given a permutation a of size n and m queries to it. Each query is represented by two indices l and r denoting that you have to reverse the segment [l, r] of the permutation. For example, if a = [1, 2, 3, 4] and a query l = 2, r = 4 is applied, then the resulting permutation is [1, 4, 3, 2]. After each query you have to determine whether the number of inversions is odd or even. -----Input----- The first line contains one integer n (1 ≀ n ≀ 1500) β€” the size of the permutation. The second line contains n integers a_1, a_2, ..., a_{n} (1 ≀ a_{i} ≀ n) β€” the elements of the permutation. These integers are pairwise distinct. The third line contains one integer m (1 ≀ m ≀ 2Β·10^5) β€” the number of queries to process. Then m lines follow, i-th line containing two integers l_{i}, r_{i} (1 ≀ l_{i} ≀ r_{i} ≀ n) denoting that i-th query is to reverse a segment [l_{i}, r_{i}] of the permutation. All queries are performed one after another. -----Output----- Print m lines. i-th of them must be equal to odd if the number of inversions in the permutation after i-th query is odd, and even otherwise. -----Examples----- Input 3 1 2 3 2 1 2 2 3 Output odd even Input 4 1 2 4 3 4 1 1 1 4 1 4 2 3 Output odd odd odd even -----Note----- The first example: after the first query a = [2, 1, 3], inversion: (2, 1); after the second query a = [2, 3, 1], inversions: (3, 1), (3, 2). The second example: a = [1, 2, 4, 3], inversion: (4, 3); a = [3, 4, 2, 1], inversions: (3, 1), (4, 1), (3, 2), (4, 2), (4, 3); a = [1, 2, 4, 3], inversion: (4, 3); a = [1, 4, 2, 3], inversions: (3, 2), (4, 2).
def f(a, b): val = 0 for x in range(a, b): for y in range(x + 1, b): if ar[x] > ar[y]: val += 1 return val n = int(input()) ar = list(map(int, input().split())) inv = f(0, n) m = int(input()) ans = [] for x in range(m): l, r = map(int, input().split()) z = r - l + 1 inv += int(z * (z - 1) / 2) inv %= 2 ans.append("odd" if inv else "even") print(*ans, sep="\n")
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR VAR VAR NUMBER RETURN 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 NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR STRING STRING EXPR FUNC_CALL VAR VAR STRING
A permutation of size n is an array of size n such that each integer from 1 to n occurs exactly once in this array. An inversion in a permutation p is a pair of indices (i, j) such that i > j and a_{i} < a_{j}. For example, a permutation [4, 1, 3, 2] contains 4 inversions: (2, 1), (3, 1), (4, 1), (4, 3). You are given a permutation a of size n and m queries to it. Each query is represented by two indices l and r denoting that you have to reverse the segment [l, r] of the permutation. For example, if a = [1, 2, 3, 4] and a query l = 2, r = 4 is applied, then the resulting permutation is [1, 4, 3, 2]. After each query you have to determine whether the number of inversions is odd or even. -----Input----- The first line contains one integer n (1 ≀ n ≀ 1500) β€” the size of the permutation. The second line contains n integers a_1, a_2, ..., a_{n} (1 ≀ a_{i} ≀ n) β€” the elements of the permutation. These integers are pairwise distinct. The third line contains one integer m (1 ≀ m ≀ 2Β·10^5) β€” the number of queries to process. Then m lines follow, i-th line containing two integers l_{i}, r_{i} (1 ≀ l_{i} ≀ r_{i} ≀ n) denoting that i-th query is to reverse a segment [l_{i}, r_{i}] of the permutation. All queries are performed one after another. -----Output----- Print m lines. i-th of them must be equal to odd if the number of inversions in the permutation after i-th query is odd, and even otherwise. -----Examples----- Input 3 1 2 3 2 1 2 2 3 Output odd even Input 4 1 2 4 3 4 1 1 1 4 1 4 2 3 Output odd odd odd even -----Note----- The first example: after the first query a = [2, 1, 3], inversion: (2, 1); after the second query a = [2, 3, 1], inversions: (3, 1), (3, 2). The second example: a = [1, 2, 4, 3], inversion: (4, 3); a = [3, 4, 2, 1], inversions: (3, 1), (4, 1), (3, 2), (4, 2), (4, 3); a = [1, 2, 4, 3], inversion: (4, 3); a = [1, 4, 2, 3], inversions: (3, 2), (4, 2).
n = int(input()) d = list(map(int, input().split())) odd = 0 for i in range(n): for j in range(i, n): if d[i] > d[j]: odd ^= 1 m = int(input()) ans = [] for i in range(m): l, r = list(map(int, input().split())) k = r - l + 1 if k * (k - 1) / 2 % 2: odd ^= 1 ans.append("odd" if odd else "even") print("\n".join(ans))
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 VAR FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR STRING STRING EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
A permutation of size n is an array of size n such that each integer from 1 to n occurs exactly once in this array. An inversion in a permutation p is a pair of indices (i, j) such that i > j and a_{i} < a_{j}. For example, a permutation [4, 1, 3, 2] contains 4 inversions: (2, 1), (3, 1), (4, 1), (4, 3). You are given a permutation a of size n and m queries to it. Each query is represented by two indices l and r denoting that you have to reverse the segment [l, r] of the permutation. For example, if a = [1, 2, 3, 4] and a query l = 2, r = 4 is applied, then the resulting permutation is [1, 4, 3, 2]. After each query you have to determine whether the number of inversions is odd or even. -----Input----- The first line contains one integer n (1 ≀ n ≀ 1500) β€” the size of the permutation. The second line contains n integers a_1, a_2, ..., a_{n} (1 ≀ a_{i} ≀ n) β€” the elements of the permutation. These integers are pairwise distinct. The third line contains one integer m (1 ≀ m ≀ 2Β·10^5) β€” the number of queries to process. Then m lines follow, i-th line containing two integers l_{i}, r_{i} (1 ≀ l_{i} ≀ r_{i} ≀ n) denoting that i-th query is to reverse a segment [l_{i}, r_{i}] of the permutation. All queries are performed one after another. -----Output----- Print m lines. i-th of them must be equal to odd if the number of inversions in the permutation after i-th query is odd, and even otherwise. -----Examples----- Input 3 1 2 3 2 1 2 2 3 Output odd even Input 4 1 2 4 3 4 1 1 1 4 1 4 2 3 Output odd odd odd even -----Note----- The first example: after the first query a = [2, 1, 3], inversion: (2, 1); after the second query a = [2, 3, 1], inversions: (3, 1), (3, 2). The second example: a = [1, 2, 4, 3], inversion: (4, 3); a = [3, 4, 2, 1], inversions: (3, 1), (4, 1), (3, 2), (4, 2), (4, 3); a = [1, 2, 4, 3], inversion: (4, 3); a = [1, 4, 2, 3], inversions: (3, 2), (4, 2).
n = int(input()) a = list(map(int, input().split())) inv = False for i in range(n): for j in range(i + 1, n): if a[i] > a[j]: inv = not inv m = int(input()) ans = list() for i in range(m): l, r = list(map(int, input().split())) if (r - l + 1) / 2 % 2 == 1 or (r - l + 1) / 2 % 2 == 1.5: inv = not inv ans.append(["even", "odd"][inv]) print("\n".join(ans))
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 VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER NUMBER NUMBER BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER NUMBER NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR LIST STRING STRING VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
A permutation of size n is an array of size n such that each integer from 1 to n occurs exactly once in this array. An inversion in a permutation p is a pair of indices (i, j) such that i > j and a_{i} < a_{j}. For example, a permutation [4, 1, 3, 2] contains 4 inversions: (2, 1), (3, 1), (4, 1), (4, 3). You are given a permutation a of size n and m queries to it. Each query is represented by two indices l and r denoting that you have to reverse the segment [l, r] of the permutation. For example, if a = [1, 2, 3, 4] and a query l = 2, r = 4 is applied, then the resulting permutation is [1, 4, 3, 2]. After each query you have to determine whether the number of inversions is odd or even. -----Input----- The first line contains one integer n (1 ≀ n ≀ 1500) β€” the size of the permutation. The second line contains n integers a_1, a_2, ..., a_{n} (1 ≀ a_{i} ≀ n) β€” the elements of the permutation. These integers are pairwise distinct. The third line contains one integer m (1 ≀ m ≀ 2Β·10^5) β€” the number of queries to process. Then m lines follow, i-th line containing two integers l_{i}, r_{i} (1 ≀ l_{i} ≀ r_{i} ≀ n) denoting that i-th query is to reverse a segment [l_{i}, r_{i}] of the permutation. All queries are performed one after another. -----Output----- Print m lines. i-th of them must be equal to odd if the number of inversions in the permutation after i-th query is odd, and even otherwise. -----Examples----- Input 3 1 2 3 2 1 2 2 3 Output odd even Input 4 1 2 4 3 4 1 1 1 4 1 4 2 3 Output odd odd odd even -----Note----- The first example: after the first query a = [2, 1, 3], inversion: (2, 1); after the second query a = [2, 3, 1], inversions: (3, 1), (3, 2). The second example: a = [1, 2, 4, 3], inversion: (4, 3); a = [3, 4, 2, 1], inversions: (3, 1), (4, 1), (3, 2), (4, 2), (4, 3); a = [1, 2, 4, 3], inversion: (4, 3); a = [1, 4, 2, 3], inversions: (3, 2), (4, 2).
import sys class BIT_RSQ(object): __slots__ = ["nodes", "size"] def __init__(self, size: int): self.nodes = [0] * (size + 1) self.size = size + 1 def add(self, index: int, value: int): while index < self.size: self.nodes[index] += value index += index & -index def sum(self, right: int): result = 0 while right: result += self.nodes[right] right -= right & -right return result n = int(sys.stdin.buffer.readline().decode("utf-8")) a = list(map(int, sys.stdin.buffer.readline().decode("utf-8").split())) m = int(sys.stdin.buffer.readline().decode("utf-8")) inv = 0 bit = BIT_RSQ(n + 10) for i, x in enumerate(a, start=1): inv += bit.sum(n - x + 2) bit.add(n - x + 2, 1) inv &= 1 res = ["even", "odd"] ans = [""] * m for i, (l, r) in enumerate( map(int, line.decode("utf-8").split()) for line in sys.stdin.buffer ): inv += (r - l + 1) * (r - l) >> 1 & 1 ans[i] = res[inv & 1] sys.stdout.buffer.write("\n".join(ans).encode("utf-8"))
IMPORT CLASS_DEF VAR ASSIGN VAR LIST STRING STRING FUNC_DEF VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FUNC_DEF VAR VAR WHILE VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR FUNC_DEF VAR ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR VAR BIN_OP VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR LIST STRING STRING ASSIGN VAR BIN_OP LIST STRING VAR FOR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING VAR VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL FUNC_CALL STRING VAR STRING
A permutation of size n is an array of size n such that each integer from 1 to n occurs exactly once in this array. An inversion in a permutation p is a pair of indices (i, j) such that i > j and a_{i} < a_{j}. For example, a permutation [4, 1, 3, 2] contains 4 inversions: (2, 1), (3, 1), (4, 1), (4, 3). You are given a permutation a of size n and m queries to it. Each query is represented by two indices l and r denoting that you have to reverse the segment [l, r] of the permutation. For example, if a = [1, 2, 3, 4] and a query l = 2, r = 4 is applied, then the resulting permutation is [1, 4, 3, 2]. After each query you have to determine whether the number of inversions is odd or even. -----Input----- The first line contains one integer n (1 ≀ n ≀ 1500) β€” the size of the permutation. The second line contains n integers a_1, a_2, ..., a_{n} (1 ≀ a_{i} ≀ n) β€” the elements of the permutation. These integers are pairwise distinct. The third line contains one integer m (1 ≀ m ≀ 2Β·10^5) β€” the number of queries to process. Then m lines follow, i-th line containing two integers l_{i}, r_{i} (1 ≀ l_{i} ≀ r_{i} ≀ n) denoting that i-th query is to reverse a segment [l_{i}, r_{i}] of the permutation. All queries are performed one after another. -----Output----- Print m lines. i-th of them must be equal to odd if the number of inversions in the permutation after i-th query is odd, and even otherwise. -----Examples----- Input 3 1 2 3 2 1 2 2 3 Output odd even Input 4 1 2 4 3 4 1 1 1 4 1 4 2 3 Output odd odd odd even -----Note----- The first example: after the first query a = [2, 1, 3], inversion: (2, 1); after the second query a = [2, 3, 1], inversions: (3, 1), (3, 2). The second example: a = [1, 2, 4, 3], inversion: (4, 3); a = [3, 4, 2, 1], inversions: (3, 1), (4, 1), (3, 2), (4, 2), (4, 3); a = [1, 2, 4, 3], inversion: (4, 3); a = [1, 4, 2, 3], inversions: (3, 2), (4, 2).
import sys input = sys.stdin.readline maxn = int(100000.0 + 10) ST = [0] * (4 * maxn) def update(id, l, r, val): if l == r == val: ST[id] = 1 return if l > val or r < val: return mid = int((l + r) / 2) update(id * 2, l, mid, val) update(id * 2 + 1, mid + 1, r, val) ST[id] = ST[id * 2] + ST[id * 2 + 1] return def get(id, l, r, x, y): if l > y or r < x: return 0 if x <= l and r <= y: return ST[id] mid = int((l + r) / 2) return get(id * 2, l, mid, x, y) + get(id * 2 + 1, mid + 1, r, x, y) n, res = int(input()), 0 for x in list(map(int, input().split())): res ^= get(1, 1, n, x + 1, n) % 2 update(1, 1, n, x) for i in range(int(input())): x, y = list(map(int, input().split())) if int((y - x) * (y - x + 1) / 2) & 1: res ^= 1 if res: print("odd") else: print("even")
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP NUMBER VAR FUNC_DEF IF VAR VAR VAR ASSIGN VAR VAR NUMBER RETURN IF VAR VAR VAR VAR RETURN ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER NUMBER RETURN FUNC_DEF IF VAR VAR VAR VAR RETURN NUMBER IF VAR VAR VAR VAR RETURN VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER RETURN BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF BIN_OP FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER NUMBER VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
A permutation of size n is an array of size n such that each integer from 1 to n occurs exactly once in this array. An inversion in a permutation p is a pair of indices (i, j) such that i > j and a_{i} < a_{j}. For example, a permutation [4, 1, 3, 2] contains 4 inversions: (2, 1), (3, 1), (4, 1), (4, 3). You are given a permutation a of size n and m queries to it. Each query is represented by two indices l and r denoting that you have to reverse the segment [l, r] of the permutation. For example, if a = [1, 2, 3, 4] and a query l = 2, r = 4 is applied, then the resulting permutation is [1, 4, 3, 2]. After each query you have to determine whether the number of inversions is odd or even. -----Input----- The first line contains one integer n (1 ≀ n ≀ 1500) β€” the size of the permutation. The second line contains n integers a_1, a_2, ..., a_{n} (1 ≀ a_{i} ≀ n) β€” the elements of the permutation. These integers are pairwise distinct. The third line contains one integer m (1 ≀ m ≀ 2Β·10^5) β€” the number of queries to process. Then m lines follow, i-th line containing two integers l_{i}, r_{i} (1 ≀ l_{i} ≀ r_{i} ≀ n) denoting that i-th query is to reverse a segment [l_{i}, r_{i}] of the permutation. All queries are performed one after another. -----Output----- Print m lines. i-th of them must be equal to odd if the number of inversions in the permutation after i-th query is odd, and even otherwise. -----Examples----- Input 3 1 2 3 2 1 2 2 3 Output odd even Input 4 1 2 4 3 4 1 1 1 4 1 4 2 3 Output odd odd odd even -----Note----- The first example: after the first query a = [2, 1, 3], inversion: (2, 1); after the second query a = [2, 3, 1], inversions: (3, 1), (3, 2). The second example: a = [1, 2, 4, 3], inversion: (4, 3); a = [3, 4, 2, 1], inversions: (3, 1), (4, 1), (3, 2), (4, 2), (4, 3); a = [1, 2, 4, 3], inversion: (4, 3); a = [1, 4, 2, 3], inversions: (3, 2), (4, 2).
n = int(input()) a = list(map(int, input().split())) value = False for i in range(n): for j in range(i + 1, n): if a[i] > a[j]: value = not value b = [] m = int(input()) for i in range(m): l, r = map(int, input().split()) if (r - l + 1) // 2 % 2 != 0: value = not value if value: b.append("odd") else: b.append("even") print("\n".join(b))
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 VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER NUMBER NUMBER ASSIGN VAR VAR IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
A permutation of size n is an array of size n such that each integer from 1 to n occurs exactly once in this array. An inversion in a permutation p is a pair of indices (i, j) such that i > j and a_{i} < a_{j}. For example, a permutation [4, 1, 3, 2] contains 4 inversions: (2, 1), (3, 1), (4, 1), (4, 3). You are given a permutation a of size n and m queries to it. Each query is represented by two indices l and r denoting that you have to reverse the segment [l, r] of the permutation. For example, if a = [1, 2, 3, 4] and a query l = 2, r = 4 is applied, then the resulting permutation is [1, 4, 3, 2]. After each query you have to determine whether the number of inversions is odd or even. -----Input----- The first line contains one integer n (1 ≀ n ≀ 1500) β€” the size of the permutation. The second line contains n integers a_1, a_2, ..., a_{n} (1 ≀ a_{i} ≀ n) β€” the elements of the permutation. These integers are pairwise distinct. The third line contains one integer m (1 ≀ m ≀ 2Β·10^5) β€” the number of queries to process. Then m lines follow, i-th line containing two integers l_{i}, r_{i} (1 ≀ l_{i} ≀ r_{i} ≀ n) denoting that i-th query is to reverse a segment [l_{i}, r_{i}] of the permutation. All queries are performed one after another. -----Output----- Print m lines. i-th of them must be equal to odd if the number of inversions in the permutation after i-th query is odd, and even otherwise. -----Examples----- Input 3 1 2 3 2 1 2 2 3 Output odd even Input 4 1 2 4 3 4 1 1 1 4 1 4 2 3 Output odd odd odd even -----Note----- The first example: after the first query a = [2, 1, 3], inversion: (2, 1); after the second query a = [2, 3, 1], inversions: (3, 1), (3, 2). The second example: a = [1, 2, 4, 3], inversion: (4, 3); a = [3, 4, 2, 1], inversions: (3, 1), (4, 1), (3, 2), (4, 2), (4, 3); a = [1, 2, 4, 3], inversion: (4, 3); a = [1, 4, 2, 3], inversions: (3, 2), (4, 2).
import sys f = sys.stdin n = int(f.readline()) arr = list(map(int, f.readline().strip().split())) odd = 0 for i in range(n): for j in range(i): odd ^= arr[i] < arr[j] m = int(f.readline()) while m: l, r = map(int, f.readline().strip().split()) x = r - l + 1 odd ^= (x * (x - 1) >> 1) % 2 if odd: print("odd") else: print("even") m -= 1
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING VAR NUMBER
A permutation of size n is an array of size n such that each integer from 1 to n occurs exactly once in this array. An inversion in a permutation p is a pair of indices (i, j) such that i > j and a_{i} < a_{j}. For example, a permutation [4, 1, 3, 2] contains 4 inversions: (2, 1), (3, 1), (4, 1), (4, 3). You are given a permutation a of size n and m queries to it. Each query is represented by two indices l and r denoting that you have to reverse the segment [l, r] of the permutation. For example, if a = [1, 2, 3, 4] and a query l = 2, r = 4 is applied, then the resulting permutation is [1, 4, 3, 2]. After each query you have to determine whether the number of inversions is odd or even. -----Input----- The first line contains one integer n (1 ≀ n ≀ 1500) β€” the size of the permutation. The second line contains n integers a_1, a_2, ..., a_{n} (1 ≀ a_{i} ≀ n) β€” the elements of the permutation. These integers are pairwise distinct. The third line contains one integer m (1 ≀ m ≀ 2Β·10^5) β€” the number of queries to process. Then m lines follow, i-th line containing two integers l_{i}, r_{i} (1 ≀ l_{i} ≀ r_{i} ≀ n) denoting that i-th query is to reverse a segment [l_{i}, r_{i}] of the permutation. All queries are performed one after another. -----Output----- Print m lines. i-th of them must be equal to odd if the number of inversions in the permutation after i-th query is odd, and even otherwise. -----Examples----- Input 3 1 2 3 2 1 2 2 3 Output odd even Input 4 1 2 4 3 4 1 1 1 4 1 4 2 3 Output odd odd odd even -----Note----- The first example: after the first query a = [2, 1, 3], inversion: (2, 1); after the second query a = [2, 3, 1], inversions: (3, 1), (3, 2). The second example: a = [1, 2, 4, 3], inversion: (4, 3); a = [3, 4, 2, 1], inversions: (3, 1), (4, 1), (3, 2), (4, 2), (4, 3); a = [1, 2, 4, 3], inversion: (4, 3); a = [1, 4, 2, 3], inversions: (3, 2), (4, 2).
from sys import stdin n = int(stdin.readline()) a = [int(o) for o in stdin.readline().split()] inv = len([(1) for i in range(n) for j in range(i + 1, n) if a[i] > a[j]]) ans = inv % 2 m = int(stdin.readline()) for i in range(m): line = stdin.readline().split() l = int(line[0]) r = int(line[1]) v = (r - l + 1) * (r - l) // 2 % 2 ans ^= v if ans == 0: print("even") else: print("odd")
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 NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER NUMBER VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
A permutation of size n is an array of size n such that each integer from 1 to n occurs exactly once in this array. An inversion in a permutation p is a pair of indices (i, j) such that i > j and a_{i} < a_{j}. For example, a permutation [4, 1, 3, 2] contains 4 inversions: (2, 1), (3, 1), (4, 1), (4, 3). You are given a permutation a of size n and m queries to it. Each query is represented by two indices l and r denoting that you have to reverse the segment [l, r] of the permutation. For example, if a = [1, 2, 3, 4] and a query l = 2, r = 4 is applied, then the resulting permutation is [1, 4, 3, 2]. After each query you have to determine whether the number of inversions is odd or even. -----Input----- The first line contains one integer n (1 ≀ n ≀ 1500) β€” the size of the permutation. The second line contains n integers a_1, a_2, ..., a_{n} (1 ≀ a_{i} ≀ n) β€” the elements of the permutation. These integers are pairwise distinct. The third line contains one integer m (1 ≀ m ≀ 2Β·10^5) β€” the number of queries to process. Then m lines follow, i-th line containing two integers l_{i}, r_{i} (1 ≀ l_{i} ≀ r_{i} ≀ n) denoting that i-th query is to reverse a segment [l_{i}, r_{i}] of the permutation. All queries are performed one after another. -----Output----- Print m lines. i-th of them must be equal to odd if the number of inversions in the permutation after i-th query is odd, and even otherwise. -----Examples----- Input 3 1 2 3 2 1 2 2 3 Output odd even Input 4 1 2 4 3 4 1 1 1 4 1 4 2 3 Output odd odd odd even -----Note----- The first example: after the first query a = [2, 1, 3], inversion: (2, 1); after the second query a = [2, 3, 1], inversions: (3, 1), (3, 2). The second example: a = [1, 2, 4, 3], inversion: (4, 3); a = [3, 4, 2, 1], inversions: (3, 1), (4, 1), (3, 2), (4, 2), (4, 3); a = [1, 2, 4, 3], inversion: (4, 3); a = [1, 4, 2, 3], inversions: (3, 2), (4, 2).
import sys class fenwick: def __init__(self, n): self.n = n self.data = [0] * (n + 1) def to_sum(self, i): s = 0 while i > 0: s += self.data[i] i -= i & -i return s def add(self, i, x): while i <= self.n: self.data[i] += x i += i & -i def get(self, i, j): return self.to_sum(j) - self.to_sum(i - 1) def input(): return sys.stdin.buffer.readline() n = int(input()) permutation = list(map(int, input().split())) seq = [(permutation[i], i + 1) for i in range(n)] seq.sort(reverse=True) m = int(input()) query = [tuple(map(int, input().split())) for i in range(m)] WHOLE_INVERSION = 0 fenwick_1 = fenwick(n) for value, index in seq: WHOLE_INVERSION += fenwick_1.get(1, index) fenwick_1.add(index, 1) for l, r in query: d = r - l + 1 WHOLE_INVERSION += d * (d - 1) // 2 if WHOLE_INVERSION % 2 != 0: print("odd") else: print("even")
IMPORT CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER VAR VAR VAR VAR BIN_OP VAR VAR RETURN VAR FUNC_DEF WHILE VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR FUNC_DEF RETURN BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_DEF RETURN FUNC_CALL 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 VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR VAR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR VAR NUMBER FOR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
A permutation of size n is an array of size n such that each integer from 1 to n occurs exactly once in this array. An inversion in a permutation p is a pair of indices (i, j) such that i > j and a_{i} < a_{j}. For example, a permutation [4, 1, 3, 2] contains 4 inversions: (2, 1), (3, 1), (4, 1), (4, 3). You are given a permutation a of size n and m queries to it. Each query is represented by two indices l and r denoting that you have to reverse the segment [l, r] of the permutation. For example, if a = [1, 2, 3, 4] and a query l = 2, r = 4 is applied, then the resulting permutation is [1, 4, 3, 2]. After each query you have to determine whether the number of inversions is odd or even. -----Input----- The first line contains one integer n (1 ≀ n ≀ 1500) β€” the size of the permutation. The second line contains n integers a_1, a_2, ..., a_{n} (1 ≀ a_{i} ≀ n) β€” the elements of the permutation. These integers are pairwise distinct. The third line contains one integer m (1 ≀ m ≀ 2Β·10^5) β€” the number of queries to process. Then m lines follow, i-th line containing two integers l_{i}, r_{i} (1 ≀ l_{i} ≀ r_{i} ≀ n) denoting that i-th query is to reverse a segment [l_{i}, r_{i}] of the permutation. All queries are performed one after another. -----Output----- Print m lines. i-th of them must be equal to odd if the number of inversions in the permutation after i-th query is odd, and even otherwise. -----Examples----- Input 3 1 2 3 2 1 2 2 3 Output odd even Input 4 1 2 4 3 4 1 1 1 4 1 4 2 3 Output odd odd odd even -----Note----- The first example: after the first query a = [2, 1, 3], inversion: (2, 1); after the second query a = [2, 3, 1], inversions: (3, 1), (3, 2). The second example: a = [1, 2, 4, 3], inversion: (4, 3); a = [3, 4, 2, 1], inversions: (3, 1), (4, 1), (3, 2), (4, 2), (4, 3); a = [1, 2, 4, 3], inversion: (4, 3); a = [1, 4, 2, 3], inversions: (3, 2), (4, 2).
import sys f = sys.stdin n = int(f.readline()) a = [int(x) for x in f.readline().split()] t = [0] * (n + 1) p = [1] * (n + 1) for i in range(2, n + 1, 2): p[i] = 2 * p[i // 2] good = 0 for x in a: i = x while i > 0: good += t[i] i -= p[i] i = x while i <= n: t[i] += 1 i += p[i] inv = n * (n - 1) // 2 - good even = inv % 2 == 0 m = int(f.readline()) for i in range(m): l, r = [int(x) for x in f.readline().split()] p = (r - l + 1) * (r - l) // 2 if p % 2 != 0: even = not even if even: print("even") else: print("odd")
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR VAR WHILE VAR NUMBER VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR WHILE VAR VAR VAR VAR NUMBER VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
A permutation of size n is an array of size n such that each integer from 1 to n occurs exactly once in this array. An inversion in a permutation p is a pair of indices (i, j) such that i > j and a_{i} < a_{j}. For example, a permutation [4, 1, 3, 2] contains 4 inversions: (2, 1), (3, 1), (4, 1), (4, 3). You are given a permutation a of size n and m queries to it. Each query is represented by two indices l and r denoting that you have to reverse the segment [l, r] of the permutation. For example, if a = [1, 2, 3, 4] and a query l = 2, r = 4 is applied, then the resulting permutation is [1, 4, 3, 2]. After each query you have to determine whether the number of inversions is odd or even. -----Input----- The first line contains one integer n (1 ≀ n ≀ 1500) β€” the size of the permutation. The second line contains n integers a_1, a_2, ..., a_{n} (1 ≀ a_{i} ≀ n) β€” the elements of the permutation. These integers are pairwise distinct. The third line contains one integer m (1 ≀ m ≀ 2Β·10^5) β€” the number of queries to process. Then m lines follow, i-th line containing two integers l_{i}, r_{i} (1 ≀ l_{i} ≀ r_{i} ≀ n) denoting that i-th query is to reverse a segment [l_{i}, r_{i}] of the permutation. All queries are performed one after another. -----Output----- Print m lines. i-th of them must be equal to odd if the number of inversions in the permutation after i-th query is odd, and even otherwise. -----Examples----- Input 3 1 2 3 2 1 2 2 3 Output odd even Input 4 1 2 4 3 4 1 1 1 4 1 4 2 3 Output odd odd odd even -----Note----- The first example: after the first query a = [2, 1, 3], inversion: (2, 1); after the second query a = [2, 3, 1], inversions: (3, 1), (3, 2). The second example: a = [1, 2, 4, 3], inversion: (4, 3); a = [3, 4, 2, 1], inversions: (3, 1), (4, 1), (3, 2), (4, 2), (4, 3); a = [1, 2, 4, 3], inversion: (4, 3); a = [1, 4, 2, 3], inversions: (3, 2), (4, 2).
n = int(input()) a = list(map(int, input().split())) pf = [0] for i in range(n): k = a[i] inv = 0 for j in range(i): if a[j] > a[i]: inv += 1 pf.append(inv + pf[-1]) ans = pf[-1] % 2 asss = [] m = int(input()) cs = [(i * (i - 1) // 2 % 2) for i in range(1501)] for _ in range(m): l, r = list(map(int, input().split())) c = r - l + 1 if c > 1 and cs[c] == 1: ans += 1 ans %= 2 if ans: asss.append("odd") else: asss.append("even") for i in asss: print(i)
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 FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR NUMBER VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING FOR VAR VAR EXPR FUNC_CALL VAR VAR
A permutation of size n is an array of size n such that each integer from 1 to n occurs exactly once in this array. An inversion in a permutation p is a pair of indices (i, j) such that i > j and a_{i} < a_{j}. For example, a permutation [4, 1, 3, 2] contains 4 inversions: (2, 1), (3, 1), (4, 1), (4, 3). You are given a permutation a of size n and m queries to it. Each query is represented by two indices l and r denoting that you have to reverse the segment [l, r] of the permutation. For example, if a = [1, 2, 3, 4] and a query l = 2, r = 4 is applied, then the resulting permutation is [1, 4, 3, 2]. After each query you have to determine whether the number of inversions is odd or even. -----Input----- The first line contains one integer n (1 ≀ n ≀ 1500) β€” the size of the permutation. The second line contains n integers a_1, a_2, ..., a_{n} (1 ≀ a_{i} ≀ n) β€” the elements of the permutation. These integers are pairwise distinct. The third line contains one integer m (1 ≀ m ≀ 2Β·10^5) β€” the number of queries to process. Then m lines follow, i-th line containing two integers l_{i}, r_{i} (1 ≀ l_{i} ≀ r_{i} ≀ n) denoting that i-th query is to reverse a segment [l_{i}, r_{i}] of the permutation. All queries are performed one after another. -----Output----- Print m lines. i-th of them must be equal to odd if the number of inversions in the permutation after i-th query is odd, and even otherwise. -----Examples----- Input 3 1 2 3 2 1 2 2 3 Output odd even Input 4 1 2 4 3 4 1 1 1 4 1 4 2 3 Output odd odd odd even -----Note----- The first example: after the first query a = [2, 1, 3], inversion: (2, 1); after the second query a = [2, 3, 1], inversions: (3, 1), (3, 2). The second example: a = [1, 2, 4, 3], inversion: (4, 3); a = [3, 4, 2, 1], inversions: (3, 1), (4, 1), (3, 2), (4, 2), (4, 3); a = [1, 2, 4, 3], inversion: (4, 3); a = [1, 4, 2, 3], inversions: (3, 2), (4, 2).
def solve(): n = int(input()) a = list(map(int, input().split())) cl = ["odd", "even"] m = int(input()) ans = True b = [] ap = b.append for i in range(n): for j in range(i): if a[j] > a[i]: ans = not ans for i in range(m): left, right = map(int, input().split()) if (right - left + 1) // 2 % 2 == 1: ans = not ans ap(cl[ans]) print("\n".join(b)) solve()
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 LIST STRING STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER NUMBER NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR
A permutation of size n is an array of size n such that each integer from 1 to n occurs exactly once in this array. An inversion in a permutation p is a pair of indices (i, j) such that i > j and a_{i} < a_{j}. For example, a permutation [4, 1, 3, 2] contains 4 inversions: (2, 1), (3, 1), (4, 1), (4, 3). You are given a permutation a of size n and m queries to it. Each query is represented by two indices l and r denoting that you have to reverse the segment [l, r] of the permutation. For example, if a = [1, 2, 3, 4] and a query l = 2, r = 4 is applied, then the resulting permutation is [1, 4, 3, 2]. After each query you have to determine whether the number of inversions is odd or even. -----Input----- The first line contains one integer n (1 ≀ n ≀ 1500) β€” the size of the permutation. The second line contains n integers a_1, a_2, ..., a_{n} (1 ≀ a_{i} ≀ n) β€” the elements of the permutation. These integers are pairwise distinct. The third line contains one integer m (1 ≀ m ≀ 2Β·10^5) β€” the number of queries to process. Then m lines follow, i-th line containing two integers l_{i}, r_{i} (1 ≀ l_{i} ≀ r_{i} ≀ n) denoting that i-th query is to reverse a segment [l_{i}, r_{i}] of the permutation. All queries are performed one after another. -----Output----- Print m lines. i-th of them must be equal to odd if the number of inversions in the permutation after i-th query is odd, and even otherwise. -----Examples----- Input 3 1 2 3 2 1 2 2 3 Output odd even Input 4 1 2 4 3 4 1 1 1 4 1 4 2 3 Output odd odd odd even -----Note----- The first example: after the first query a = [2, 1, 3], inversion: (2, 1); after the second query a = [2, 3, 1], inversions: (3, 1), (3, 2). The second example: a = [1, 2, 4, 3], inversion: (4, 3); a = [3, 4, 2, 1], inversions: (3, 1), (4, 1), (3, 2), (4, 2), (4, 3); a = [1, 2, 4, 3], inversion: (4, 3); a = [1, 4, 2, 3], inversions: (3, 2), (4, 2).
import sys input = sys.stdin.readline def getsum(BITTree, i): i = i + 1 s = 0 while i > 0: s += BITTree[i] i -= i & -i return s def updatebit(BITTree, n, i, v): i = i + 1 while i <= n: BITTree[i] += v i += i & -i n = int(input()) lista = [int(i) for i in input().split()] invercount = 0 bitTree = [0] * (n + 2) for k in reversed(lista): updatebit(bitTree, n + 1, k, 1) counter = getsum(bitTree, k - 1) invercount += counter m = int(input()) for i in range(m): l, r = map(int, input().split()) summa = (r - l + 1) * (r - l) / 2 if (invercount + summa) % 2: print("odd") invercount = 1 else: print("even") invercount = 0
IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER VAR VAR VAR VAR BIN_OP VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER
A permutation of size n is an array of size n such that each integer from 1 to n occurs exactly once in this array. An inversion in a permutation p is a pair of indices (i, j) such that i > j and a_{i} < a_{j}. For example, a permutation [4, 1, 3, 2] contains 4 inversions: (2, 1), (3, 1), (4, 1), (4, 3). You are given a permutation a of size n and m queries to it. Each query is represented by two indices l and r denoting that you have to reverse the segment [l, r] of the permutation. For example, if a = [1, 2, 3, 4] and a query l = 2, r = 4 is applied, then the resulting permutation is [1, 4, 3, 2]. After each query you have to determine whether the number of inversions is odd or even. -----Input----- The first line contains one integer n (1 ≀ n ≀ 1500) β€” the size of the permutation. The second line contains n integers a_1, a_2, ..., a_{n} (1 ≀ a_{i} ≀ n) β€” the elements of the permutation. These integers are pairwise distinct. The third line contains one integer m (1 ≀ m ≀ 2Β·10^5) β€” the number of queries to process. Then m lines follow, i-th line containing two integers l_{i}, r_{i} (1 ≀ l_{i} ≀ r_{i} ≀ n) denoting that i-th query is to reverse a segment [l_{i}, r_{i}] of the permutation. All queries are performed one after another. -----Output----- Print m lines. i-th of them must be equal to odd if the number of inversions in the permutation after i-th query is odd, and even otherwise. -----Examples----- Input 3 1 2 3 2 1 2 2 3 Output odd even Input 4 1 2 4 3 4 1 1 1 4 1 4 2 3 Output odd odd odd even -----Note----- The first example: after the first query a = [2, 1, 3], inversion: (2, 1); after the second query a = [2, 3, 1], inversions: (3, 1), (3, 2). The second example: a = [1, 2, 4, 3], inversion: (4, 3); a = [3, 4, 2, 1], inversions: (3, 1), (4, 1), (3, 2), (4, 2), (4, 3); a = [1, 2, 4, 3], inversion: (4, 3); a = [1, 4, 2, 3], inversions: (3, 2), (4, 2).
import sys f = sys.stdin n = int(f.readline()) a = list(map(int, f.readline().split())) cnt = 0 for i in range(n): cnt += sum([(1) for x in a[i + 1 :] if x < a[i]]) m = int(f.readline()) for _ in range(m): l, r = list(map(int, f.readline().split())) c = r - l cnt += c * (c + 1) // 2 % 2 if cnt % 2 == 0: print("even") else: print("odd")
IMPORT ASSIGN 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 NUMBER FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
A permutation of size n is an array of size n such that each integer from 1 to n occurs exactly once in this array. An inversion in a permutation p is a pair of indices (i, j) such that i > j and a_{i} < a_{j}. For example, a permutation [4, 1, 3, 2] contains 4 inversions: (2, 1), (3, 1), (4, 1), (4, 3). You are given a permutation a of size n and m queries to it. Each query is represented by two indices l and r denoting that you have to reverse the segment [l, r] of the permutation. For example, if a = [1, 2, 3, 4] and a query l = 2, r = 4 is applied, then the resulting permutation is [1, 4, 3, 2]. After each query you have to determine whether the number of inversions is odd or even. -----Input----- The first line contains one integer n (1 ≀ n ≀ 1500) β€” the size of the permutation. The second line contains n integers a_1, a_2, ..., a_{n} (1 ≀ a_{i} ≀ n) β€” the elements of the permutation. These integers are pairwise distinct. The third line contains one integer m (1 ≀ m ≀ 2Β·10^5) β€” the number of queries to process. Then m lines follow, i-th line containing two integers l_{i}, r_{i} (1 ≀ l_{i} ≀ r_{i} ≀ n) denoting that i-th query is to reverse a segment [l_{i}, r_{i}] of the permutation. All queries are performed one after another. -----Output----- Print m lines. i-th of them must be equal to odd if the number of inversions in the permutation after i-th query is odd, and even otherwise. -----Examples----- Input 3 1 2 3 2 1 2 2 3 Output odd even Input 4 1 2 4 3 4 1 1 1 4 1 4 2 3 Output odd odd odd even -----Note----- The first example: after the first query a = [2, 1, 3], inversion: (2, 1); after the second query a = [2, 3, 1], inversions: (3, 1), (3, 2). The second example: a = [1, 2, 4, 3], inversion: (4, 3); a = [3, 4, 2, 1], inversions: (3, 1), (4, 1), (3, 2), (4, 2), (4, 3); a = [1, 2, 4, 3], inversion: (4, 3); a = [1, 4, 2, 3], inversions: (3, 2), (4, 2).
from sys import stdin, stdout input = stdin.readline print = stdout.write n = int(input()) (*a,) = map(int, input().split()) p = 0 for i in range(n): for j in range(i + 1, n): if a[i] > a[j]: p ^= 1 m = int(input()) for i in range(m): l, r = map(int, input().split()) k = r - l + 1 k = k * (k - 1) // 2 if k & 1: p ^= 1 print("eovdedn"[p::2] + "\n")
ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP STRING VAR NUMBER STRING
A permutation of size n is an array of size n such that each integer from 1 to n occurs exactly once in this array. An inversion in a permutation p is a pair of indices (i, j) such that i > j and a_{i} < a_{j}. For example, a permutation [4, 1, 3, 2] contains 4 inversions: (2, 1), (3, 1), (4, 1), (4, 3). You are given a permutation a of size n and m queries to it. Each query is represented by two indices l and r denoting that you have to reverse the segment [l, r] of the permutation. For example, if a = [1, 2, 3, 4] and a query l = 2, r = 4 is applied, then the resulting permutation is [1, 4, 3, 2]. After each query you have to determine whether the number of inversions is odd or even. -----Input----- The first line contains one integer n (1 ≀ n ≀ 1500) β€” the size of the permutation. The second line contains n integers a_1, a_2, ..., a_{n} (1 ≀ a_{i} ≀ n) β€” the elements of the permutation. These integers are pairwise distinct. The third line contains one integer m (1 ≀ m ≀ 2Β·10^5) β€” the number of queries to process. Then m lines follow, i-th line containing two integers l_{i}, r_{i} (1 ≀ l_{i} ≀ r_{i} ≀ n) denoting that i-th query is to reverse a segment [l_{i}, r_{i}] of the permutation. All queries are performed one after another. -----Output----- Print m lines. i-th of them must be equal to odd if the number of inversions in the permutation after i-th query is odd, and even otherwise. -----Examples----- Input 3 1 2 3 2 1 2 2 3 Output odd even Input 4 1 2 4 3 4 1 1 1 4 1 4 2 3 Output odd odd odd even -----Note----- The first example: after the first query a = [2, 1, 3], inversion: (2, 1); after the second query a = [2, 3, 1], inversions: (3, 1), (3, 2). The second example: a = [1, 2, 4, 3], inversion: (4, 3); a = [3, 4, 2, 1], inversions: (3, 1), (4, 1), (3, 2), (4, 2), (4, 3); a = [1, 2, 4, 3], inversion: (4, 3); a = [1, 4, 2, 3], inversions: (3, 2), (4, 2).
from sys import stdin, stdout input, print = stdin.readline, stdout.write n = int(input()) a = [int(i) for i in input().split()] ans = 0 for i in range(n): for j in range(i + 1, n): ans += int(a[i] > a[j]) ans %= 2 q = int(input()) for i in range(q): l, r = [int(i) for i in input().split()] ans ^= (r - l) * (r - l + 1) // 2 % 2 print("odd\n" if ans else "even\n")
ASSIGN VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR VAR STRING STRING
A permutation of size n is an array of size n such that each integer from 1 to n occurs exactly once in this array. An inversion in a permutation p is a pair of indices (i, j) such that i > j and a_{i} < a_{j}. For example, a permutation [4, 1, 3, 2] contains 4 inversions: (2, 1), (3, 1), (4, 1), (4, 3). You are given a permutation a of size n and m queries to it. Each query is represented by two indices l and r denoting that you have to reverse the segment [l, r] of the permutation. For example, if a = [1, 2, 3, 4] and a query l = 2, r = 4 is applied, then the resulting permutation is [1, 4, 3, 2]. After each query you have to determine whether the number of inversions is odd or even. -----Input----- The first line contains one integer n (1 ≀ n ≀ 1500) β€” the size of the permutation. The second line contains n integers a_1, a_2, ..., a_{n} (1 ≀ a_{i} ≀ n) β€” the elements of the permutation. These integers are pairwise distinct. The third line contains one integer m (1 ≀ m ≀ 2Β·10^5) β€” the number of queries to process. Then m lines follow, i-th line containing two integers l_{i}, r_{i} (1 ≀ l_{i} ≀ r_{i} ≀ n) denoting that i-th query is to reverse a segment [l_{i}, r_{i}] of the permutation. All queries are performed one after another. -----Output----- Print m lines. i-th of them must be equal to odd if the number of inversions in the permutation after i-th query is odd, and even otherwise. -----Examples----- Input 3 1 2 3 2 1 2 2 3 Output odd even Input 4 1 2 4 3 4 1 1 1 4 1 4 2 3 Output odd odd odd even -----Note----- The first example: after the first query a = [2, 1, 3], inversion: (2, 1); after the second query a = [2, 3, 1], inversions: (3, 1), (3, 2). The second example: a = [1, 2, 4, 3], inversion: (4, 3); a = [3, 4, 2, 1], inversions: (3, 1), (4, 1), (3, 2), (4, 2), (4, 3); a = [1, 2, 4, 3], inversion: (4, 3); a = [1, 4, 2, 3], inversions: (3, 2), (4, 2).
def main(): n = int(input()) a = list(map(int, input().split())) cnt = 0 for i in range(n): for j in range(i + 1, n): if a[i] > a[j]: cnt += 1 even = cnt % 2 == 0 q = int(input()) ans = [] for _ in range(q): l, r = map(int, input().split()) len = r - l + 1 pairs = len * (len - 1) // 2 if pairs % 2 == 1: even = not even if even: ans.append("even") else: ans.append("odd") print("\n".join(ans)) 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 ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR
A permutation of size n is an array of size n such that each integer from 1 to n occurs exactly once in this array. An inversion in a permutation p is a pair of indices (i, j) such that i > j and a_{i} < a_{j}. For example, a permutation [4, 1, 3, 2] contains 4 inversions: (2, 1), (3, 1), (4, 1), (4, 3). You are given a permutation a of size n and m queries to it. Each query is represented by two indices l and r denoting that you have to reverse the segment [l, r] of the permutation. For example, if a = [1, 2, 3, 4] and a query l = 2, r = 4 is applied, then the resulting permutation is [1, 4, 3, 2]. After each query you have to determine whether the number of inversions is odd or even. -----Input----- The first line contains one integer n (1 ≀ n ≀ 1500) β€” the size of the permutation. The second line contains n integers a_1, a_2, ..., a_{n} (1 ≀ a_{i} ≀ n) β€” the elements of the permutation. These integers are pairwise distinct. The third line contains one integer m (1 ≀ m ≀ 2Β·10^5) β€” the number of queries to process. Then m lines follow, i-th line containing two integers l_{i}, r_{i} (1 ≀ l_{i} ≀ r_{i} ≀ n) denoting that i-th query is to reverse a segment [l_{i}, r_{i}] of the permutation. All queries are performed one after another. -----Output----- Print m lines. i-th of them must be equal to odd if the number of inversions in the permutation after i-th query is odd, and even otherwise. -----Examples----- Input 3 1 2 3 2 1 2 2 3 Output odd even Input 4 1 2 4 3 4 1 1 1 4 1 4 2 3 Output odd odd odd even -----Note----- The first example: after the first query a = [2, 1, 3], inversion: (2, 1); after the second query a = [2, 3, 1], inversions: (3, 1), (3, 2). The second example: a = [1, 2, 4, 3], inversion: (4, 3); a = [3, 4, 2, 1], inversions: (3, 1), (4, 1), (3, 2), (4, 2), (4, 3); a = [1, 2, 4, 3], inversion: (4, 3); a = [1, 4, 2, 3], inversions: (3, 2), (4, 2).
def pflag(flag): if flag: return "odd" else: return "even" n = int(input()) arr = list(map(int, input().split())) m = int(input()) flag = False count = 0 for i in range(n - 1): for j in range(i + 1, n): if arr[j] < arr[i]: count += 1 if count % 2 == 0: flag = False else: flag = True newflag = 0 ans = [] for i in range(m): l, r = map(int, input().split()) e = (r - l + 1) // 2 if e % 2 == 0: newflag = False else: newflag = True if flag and newflag or not flag and not newflag: flag = False ans.append("even") else: flag = True ans.append("odd") print("\n".join(ans))
FUNC_DEF IF VAR RETURN STRING RETURN STRING 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 FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
A permutation of size n is an array of size n such that each integer from 1 to n occurs exactly once in this array. An inversion in a permutation p is a pair of indices (i, j) such that i > j and a_{i} < a_{j}. For example, a permutation [4, 1, 3, 2] contains 4 inversions: (2, 1), (3, 1), (4, 1), (4, 3). You are given a permutation a of size n and m queries to it. Each query is represented by two indices l and r denoting that you have to reverse the segment [l, r] of the permutation. For example, if a = [1, 2, 3, 4] and a query l = 2, r = 4 is applied, then the resulting permutation is [1, 4, 3, 2]. After each query you have to determine whether the number of inversions is odd or even. -----Input----- The first line contains one integer n (1 ≀ n ≀ 1500) β€” the size of the permutation. The second line contains n integers a_1, a_2, ..., a_{n} (1 ≀ a_{i} ≀ n) β€” the elements of the permutation. These integers are pairwise distinct. The third line contains one integer m (1 ≀ m ≀ 2Β·10^5) β€” the number of queries to process. Then m lines follow, i-th line containing two integers l_{i}, r_{i} (1 ≀ l_{i} ≀ r_{i} ≀ n) denoting that i-th query is to reverse a segment [l_{i}, r_{i}] of the permutation. All queries are performed one after another. -----Output----- Print m lines. i-th of them must be equal to odd if the number of inversions in the permutation after i-th query is odd, and even otherwise. -----Examples----- Input 3 1 2 3 2 1 2 2 3 Output odd even Input 4 1 2 4 3 4 1 1 1 4 1 4 2 3 Output odd odd odd even -----Note----- The first example: after the first query a = [2, 1, 3], inversion: (2, 1); after the second query a = [2, 3, 1], inversions: (3, 1), (3, 2). The second example: a = [1, 2, 4, 3], inversion: (4, 3); a = [3, 4, 2, 1], inversions: (3, 1), (4, 1), (3, 2), (4, 2), (4, 3); a = [1, 2, 4, 3], inversion: (4, 3); a = [1, 4, 2, 3], inversions: (3, 2), (4, 2).
import sys n = int(input()) a = [int(i) for i in input().split(" ")] m = int(input()) inversion = 0 for i in range(n): for j in range(i + 1, n): if a[i] > a[j]: inversion += 1 if inversion % 2: even = False else: even = True lines = sys.stdin.readlines() for k in range(m): q = tuple(int(i) - 1 for i in lines[k].split(" ")) if (q[1] - q[0] + 1) // 2 % 2: even = not even if even: print("even") else: print("odd")
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR VAR VAR NUMBER IF BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR STRING IF BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER NUMBER NUMBER NUMBER ASSIGN VAR VAR IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
A permutation of size n is an array of size n such that each integer from 1 to n occurs exactly once in this array. An inversion in a permutation p is a pair of indices (i, j) such that i > j and a_{i} < a_{j}. For example, a permutation [4, 1, 3, 2] contains 4 inversions: (2, 1), (3, 1), (4, 1), (4, 3). You are given a permutation a of size n and m queries to it. Each query is represented by two indices l and r denoting that you have to reverse the segment [l, r] of the permutation. For example, if a = [1, 2, 3, 4] and a query l = 2, r = 4 is applied, then the resulting permutation is [1, 4, 3, 2]. After each query you have to determine whether the number of inversions is odd or even. -----Input----- The first line contains one integer n (1 ≀ n ≀ 1500) β€” the size of the permutation. The second line contains n integers a_1, a_2, ..., a_{n} (1 ≀ a_{i} ≀ n) β€” the elements of the permutation. These integers are pairwise distinct. The third line contains one integer m (1 ≀ m ≀ 2Β·10^5) β€” the number of queries to process. Then m lines follow, i-th line containing two integers l_{i}, r_{i} (1 ≀ l_{i} ≀ r_{i} ≀ n) denoting that i-th query is to reverse a segment [l_{i}, r_{i}] of the permutation. All queries are performed one after another. -----Output----- Print m lines. i-th of them must be equal to odd if the number of inversions in the permutation after i-th query is odd, and even otherwise. -----Examples----- Input 3 1 2 3 2 1 2 2 3 Output odd even Input 4 1 2 4 3 4 1 1 1 4 1 4 2 3 Output odd odd odd even -----Note----- The first example: after the first query a = [2, 1, 3], inversion: (2, 1); after the second query a = [2, 3, 1], inversions: (3, 1), (3, 2). The second example: a = [1, 2, 4, 3], inversion: (4, 3); a = [3, 4, 2, 1], inversions: (3, 1), (4, 1), (3, 2), (4, 2), (4, 3); a = [1, 2, 4, 3], inversion: (4, 3); a = [1, 4, 2, 3], inversions: (3, 2), (4, 2).
N = int(input()) A = list(map(int, input().split())) M = int(input()) Q = [input().split() for m in range(M)] def solve(): count = 0 for i in range(N): for j in range(i): if A[i] < A[j]: count += 1 count %= 2 res = [] for q in Q: l, r = q l = int(l) - 1 r = int(r) - 1 count += (r - l + 1) // 2 count %= 2 if count == 0: res.append("even") else: res.append("odd") print("\n".join(res)) solve()
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 FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR
A permutation of size n is an array of size n such that each integer from 1 to n occurs exactly once in this array. An inversion in a permutation p is a pair of indices (i, j) such that i > j and a_{i} < a_{j}. For example, a permutation [4, 1, 3, 2] contains 4 inversions: (2, 1), (3, 1), (4, 1), (4, 3). You are given a permutation a of size n and m queries to it. Each query is represented by two indices l and r denoting that you have to reverse the segment [l, r] of the permutation. For example, if a = [1, 2, 3, 4] and a query l = 2, r = 4 is applied, then the resulting permutation is [1, 4, 3, 2]. After each query you have to determine whether the number of inversions is odd or even. -----Input----- The first line contains one integer n (1 ≀ n ≀ 1500) β€” the size of the permutation. The second line contains n integers a_1, a_2, ..., a_{n} (1 ≀ a_{i} ≀ n) β€” the elements of the permutation. These integers are pairwise distinct. The third line contains one integer m (1 ≀ m ≀ 2Β·10^5) β€” the number of queries to process. Then m lines follow, i-th line containing two integers l_{i}, r_{i} (1 ≀ l_{i} ≀ r_{i} ≀ n) denoting that i-th query is to reverse a segment [l_{i}, r_{i}] of the permutation. All queries are performed one after another. -----Output----- Print m lines. i-th of them must be equal to odd if the number of inversions in the permutation after i-th query is odd, and even otherwise. -----Examples----- Input 3 1 2 3 2 1 2 2 3 Output odd even Input 4 1 2 4 3 4 1 1 1 4 1 4 2 3 Output odd odd odd even -----Note----- The first example: after the first query a = [2, 1, 3], inversion: (2, 1); after the second query a = [2, 3, 1], inversions: (3, 1), (3, 2). The second example: a = [1, 2, 4, 3], inversion: (4, 3); a = [3, 4, 2, 1], inversions: (3, 1), (4, 1), (3, 2), (4, 2), (4, 3); a = [1, 2, 4, 3], inversion: (4, 3); a = [1, 4, 2, 3], inversions: (3, 2), (4, 2).
n = int(input()) a = list(map(int, input().split())) m = int(input()) parity = 0 for i in range(n): for j in range(i + 1, n): if a[i] > a[j]: parity ^= 1 res = [] for _ in range(m): l, r = map(int, input().split()) s = r - l + 1 parity ^= s * (s - 1) // 2 % 2 res.append("odd" if parity else "even") print("\n".join(res))
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 FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR VAR STRING STRING EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
A permutation of size n is an array of size n such that each integer from 1 to n occurs exactly once in this array. An inversion in a permutation p is a pair of indices (i, j) such that i > j and a_{i} < a_{j}. For example, a permutation [4, 1, 3, 2] contains 4 inversions: (2, 1), (3, 1), (4, 1), (4, 3). You are given a permutation a of size n and m queries to it. Each query is represented by two indices l and r denoting that you have to reverse the segment [l, r] of the permutation. For example, if a = [1, 2, 3, 4] and a query l = 2, r = 4 is applied, then the resulting permutation is [1, 4, 3, 2]. After each query you have to determine whether the number of inversions is odd or even. -----Input----- The first line contains one integer n (1 ≀ n ≀ 1500) β€” the size of the permutation. The second line contains n integers a_1, a_2, ..., a_{n} (1 ≀ a_{i} ≀ n) β€” the elements of the permutation. These integers are pairwise distinct. The third line contains one integer m (1 ≀ m ≀ 2Β·10^5) β€” the number of queries to process. Then m lines follow, i-th line containing two integers l_{i}, r_{i} (1 ≀ l_{i} ≀ r_{i} ≀ n) denoting that i-th query is to reverse a segment [l_{i}, r_{i}] of the permutation. All queries are performed one after another. -----Output----- Print m lines. i-th of them must be equal to odd if the number of inversions in the permutation after i-th query is odd, and even otherwise. -----Examples----- Input 3 1 2 3 2 1 2 2 3 Output odd even Input 4 1 2 4 3 4 1 1 1 4 1 4 2 3 Output odd odd odd even -----Note----- The first example: after the first query a = [2, 1, 3], inversion: (2, 1); after the second query a = [2, 3, 1], inversions: (3, 1), (3, 2). The second example: a = [1, 2, 4, 3], inversion: (4, 3); a = [3, 4, 2, 1], inversions: (3, 1), (4, 1), (3, 2), (4, 2), (4, 3); a = [1, 2, 4, 3], inversion: (4, 3); a = [1, 4, 2, 3], inversions: (3, 2), (4, 2).
n = int(input()) nums = [int(a) for a in input().strip().split()] counts = 0 for i in range(n - 1): for j in range(i + 1, n): if nums[i] > nums[j]: counts += 1 ans = counts % 2 ans_tmp = [] m = int(input()) for i in range(m): l, r = [int(a) for a in input().strip().split()] tmp = r - l + 1 tmp_count = tmp * (tmp - 1) // 2 if tmp_count % 2 == 1: ans = (ans + 1) % 2 ans_tmp.append(ans) for i in range(m): ans = ans_tmp[i] if ans % 2 == 1: print("odd") else: print("even")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
A permutation of size n is an array of size n such that each integer from 1 to n occurs exactly once in this array. An inversion in a permutation p is a pair of indices (i, j) such that i > j and a_{i} < a_{j}. For example, a permutation [4, 1, 3, 2] contains 4 inversions: (2, 1), (3, 1), (4, 1), (4, 3). You are given a permutation a of size n and m queries to it. Each query is represented by two indices l and r denoting that you have to reverse the segment [l, r] of the permutation. For example, if a = [1, 2, 3, 4] and a query l = 2, r = 4 is applied, then the resulting permutation is [1, 4, 3, 2]. After each query you have to determine whether the number of inversions is odd or even. -----Input----- The first line contains one integer n (1 ≀ n ≀ 1500) β€” the size of the permutation. The second line contains n integers a_1, a_2, ..., a_{n} (1 ≀ a_{i} ≀ n) β€” the elements of the permutation. These integers are pairwise distinct. The third line contains one integer m (1 ≀ m ≀ 2Β·10^5) β€” the number of queries to process. Then m lines follow, i-th line containing two integers l_{i}, r_{i} (1 ≀ l_{i} ≀ r_{i} ≀ n) denoting that i-th query is to reverse a segment [l_{i}, r_{i}] of the permutation. All queries are performed one after another. -----Output----- Print m lines. i-th of them must be equal to odd if the number of inversions in the permutation after i-th query is odd, and even otherwise. -----Examples----- Input 3 1 2 3 2 1 2 2 3 Output odd even Input 4 1 2 4 3 4 1 1 1 4 1 4 2 3 Output odd odd odd even -----Note----- The first example: after the first query a = [2, 1, 3], inversion: (2, 1); after the second query a = [2, 3, 1], inversions: (3, 1), (3, 2). The second example: a = [1, 2, 4, 3], inversion: (4, 3); a = [3, 4, 2, 1], inversions: (3, 1), (4, 1), (3, 2), (4, 2), (4, 3); a = [1, 2, 4, 3], inversion: (4, 3); a = [1, 4, 2, 3], inversions: (3, 2), (4, 2).
import sys readline = sys.stdin.readline N = int(readline()) A = list(map(int, readline().split())) Q = int(readline()) cnt = 0 for i in range(N): for j in range(i + 1, N): if A[i] > A[j]: cnt += 1 cnt %= 2 Ans = [None] * Q for qu in range(Q): l, r = map(int, readline().split()) if (r - l + 1) * (r - l) // 2 & 1: cnt ^= 1 Ans[qu] = "odd" if cnt else "even" print("\n".join(Ans))
IMPORT ASSIGN 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 FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP LIST NONE VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR VAR VAR STRING STRING EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
A permutation of size n is an array of size n such that each integer from 1 to n occurs exactly once in this array. An inversion in a permutation p is a pair of indices (i, j) such that i > j and a_{i} < a_{j}. For example, a permutation [4, 1, 3, 2] contains 4 inversions: (2, 1), (3, 1), (4, 1), (4, 3). You are given a permutation a of size n and m queries to it. Each query is represented by two indices l and r denoting that you have to reverse the segment [l, r] of the permutation. For example, if a = [1, 2, 3, 4] and a query l = 2, r = 4 is applied, then the resulting permutation is [1, 4, 3, 2]. After each query you have to determine whether the number of inversions is odd or even. -----Input----- The first line contains one integer n (1 ≀ n ≀ 1500) β€” the size of the permutation. The second line contains n integers a_1, a_2, ..., a_{n} (1 ≀ a_{i} ≀ n) β€” the elements of the permutation. These integers are pairwise distinct. The third line contains one integer m (1 ≀ m ≀ 2Β·10^5) β€” the number of queries to process. Then m lines follow, i-th line containing two integers l_{i}, r_{i} (1 ≀ l_{i} ≀ r_{i} ≀ n) denoting that i-th query is to reverse a segment [l_{i}, r_{i}] of the permutation. All queries are performed one after another. -----Output----- Print m lines. i-th of them must be equal to odd if the number of inversions in the permutation after i-th query is odd, and even otherwise. -----Examples----- Input 3 1 2 3 2 1 2 2 3 Output odd even Input 4 1 2 4 3 4 1 1 1 4 1 4 2 3 Output odd odd odd even -----Note----- The first example: after the first query a = [2, 1, 3], inversion: (2, 1); after the second query a = [2, 3, 1], inversions: (3, 1), (3, 2). The second example: a = [1, 2, 4, 3], inversion: (4, 3); a = [3, 4, 2, 1], inversions: (3, 1), (4, 1), (3, 2), (4, 2), (4, 3); a = [1, 2, 4, 3], inversion: (4, 3); a = [1, 4, 2, 3], inversions: (3, 2), (4, 2).
import sys f = sys.stdin n = int(f.readline()) a = list(map(int, f.readline().split())) s = 0 for i in range(n): for j in range(i): s ^= a[j] > a[i] q = int(f.readline()) for i in range(q): l, r = map(int, f.readline().split()) s ^= (r - l + 1) * (r - l) // 2 % 2 print(["even", "odd"][s])
IMPORT ASSIGN 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 NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR LIST STRING STRING VAR
A permutation of size n is an array of size n such that each integer from 1 to n occurs exactly once in this array. An inversion in a permutation p is a pair of indices (i, j) such that i > j and a_{i} < a_{j}. For example, a permutation [4, 1, 3, 2] contains 4 inversions: (2, 1), (3, 1), (4, 1), (4, 3). You are given a permutation a of size n and m queries to it. Each query is represented by two indices l and r denoting that you have to reverse the segment [l, r] of the permutation. For example, if a = [1, 2, 3, 4] and a query l = 2, r = 4 is applied, then the resulting permutation is [1, 4, 3, 2]. After each query you have to determine whether the number of inversions is odd or even. -----Input----- The first line contains one integer n (1 ≀ n ≀ 1500) β€” the size of the permutation. The second line contains n integers a_1, a_2, ..., a_{n} (1 ≀ a_{i} ≀ n) β€” the elements of the permutation. These integers are pairwise distinct. The third line contains one integer m (1 ≀ m ≀ 2Β·10^5) β€” the number of queries to process. Then m lines follow, i-th line containing two integers l_{i}, r_{i} (1 ≀ l_{i} ≀ r_{i} ≀ n) denoting that i-th query is to reverse a segment [l_{i}, r_{i}] of the permutation. All queries are performed one after another. -----Output----- Print m lines. i-th of them must be equal to odd if the number of inversions in the permutation after i-th query is odd, and even otherwise. -----Examples----- Input 3 1 2 3 2 1 2 2 3 Output odd even Input 4 1 2 4 3 4 1 1 1 4 1 4 2 3 Output odd odd odd even -----Note----- The first example: after the first query a = [2, 1, 3], inversion: (2, 1); after the second query a = [2, 3, 1], inversions: (3, 1), (3, 2). The second example: a = [1, 2, 4, 3], inversion: (4, 3); a = [3, 4, 2, 1], inversions: (3, 1), (4, 1), (3, 2), (4, 2), (4, 3); a = [1, 2, 4, 3], inversion: (4, 3); a = [1, 4, 2, 3], inversions: (3, 2), (4, 2).
n = int(input()) lst = [] for x in input().split(): lst.append(int(x)) m = int(input()) pair = [] for x in range(m): l, r = list(map(int, input().split())) pair.append((l, r)) k = 0 for x in range(0, len(lst) - 1): for y in range(x + 1, len(lst)): if lst[y] < lst[x]: k += 1 for l, r in pair: if (k - (r - l + 1) // 2) % 2 == 0: print("even") else: print("odd") k = k - (r - l + 1) // 2
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER FOR VAR VAR VAR IF BIN_OP BIN_OP VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER
One day Vasya came up to the blackboard and wrote out n distinct integers from 1 to n in some order in a circle. Then he drew arcs to join the pairs of integers (a, b) (a β‰  b), that are either each other's immediate neighbors in the circle, or there is number c, such that a and с are immediate neighbors, and b and c are immediate neighbors. As you can easily deduce, in the end Vasya drew 2Β·n arcs. For example, if the numbers are written in the circle in the order 1, 2, 3, 4, 5 (in the clockwise direction), then the arcs will join pairs of integers (1, 2), (2, 3), (3, 4), (4, 5), (5, 1), (1, 3), (2, 4), (3, 5), (4, 1) and (5, 2). Much time has passed ever since, the numbers we wiped off the blackboard long ago, but recently Vasya has found a piece of paper with 2Β·n written pairs of integers that were joined with the arcs on the board. Vasya asks you to find the order of numbers in the circle by these pairs. -----Input----- The first line of the input contains a single integer n (5 ≀ n ≀ 10^5) that shows, how many numbers were written on the board. Next 2Β·n lines contain pairs of integers a_{i}, b_{i} (1 ≀ a_{i}, b_{i} ≀ n, a_{i} β‰  b_{i}) β€” the numbers that were connected by the arcs. It is guaranteed that no pair of integers, connected by a arc, occurs in the input more than once. The pairs of numbers and the numbers in the pairs are given in the arbitrary order. -----Output----- If Vasya made a mistake somewhere and there isn't any way to place numbers from 1 to n on the circle according to the statement, then print a single number "-1" (without the quotes). Otherwise, print any suitable sequence of n distinct integers from 1 to n. If there are multiple solutions, you are allowed to print any of them. Specifically, it doesn't matter which number you write first to describe the sequence of the order. It also doesn't matter whether you write out the numbers in the clockwise or counter-clockwise direction. -----Examples----- Input 5 1 2 2 3 3 4 4 5 5 1 1 3 2 4 3 5 4 1 5 2 Output 1 2 3 4 5 Input 6 5 6 4 3 5 3 2 4 6 1 3 1 6 2 2 5 1 4 3 6 1 2 4 5 Output 1 2 4 5 3 6
from sys import stdin all_in = stdin.readlines() n = int(all_in[0]) pairs = list(map(lambda x: tuple(map(int, x.split())), all_in[1:])) if n == 5: print(1, 2, 3, 4, 5) exit() neigs = {i: set() for i in range(1, n + 1)} for a, b in pairs: neigs[a].add(b) neigs[b].add(a) for el in neigs.values(): if len(el) != 4: print(-1) exit() ans = [1] used = {i: (False) for i in range(1, n + 1)} used[1] = True for i in range(n - 1): el_ = ans[-1] ne = neigs[el_] for el in ne: ne_ = neigs[el] and_ = ne & ne_ if len(and_) == 2: if i: if ans[-2] not in and_: continue if not used[el]: ans.append(el) used[el] = True break if len(ans) < n: print(-1) exit() print(" ".join(map(str, ans)))
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR LIST NUMBER ASSIGN VAR VAR NUMBER VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR VAR FOR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF FUNC_CALL VAR VAR NUMBER IF VAR IF VAR NUMBER VAR IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR
Read problems statements in Mandarin Chinese , Russian and Vietnamese as well. Tic-Tac-Toe used to be Chef's favourite game during his childhood. Reminiscing in his childhood memories, he decided to create his own "Tic-Tac-Toe", with rules being similar to the original Tic-Tac-Toe, other than the fact that it is played on an NxN board. The game is played between two players taking turns. First player puts an 'X' in an empty cell of the board, then the second player puts an 'O' in some other free cell. If the first player has K continuous X's or the second player has K continuous O's in row, column or diagonal, then he wins. Chef started playing this new "Tic-Tac-Toe" with his assistant, beginning as the first player himself (that is, Chef plays 'X's). Currently, the game is ongoign, and it's Chef's turn. However, he needs to leave soon to begin tonight's dinner preparations, and has time to play only one more move. If he can win in one move, output "YES", otherwise output "NO" (without quotes). It is guaranteed that no player has already completed the winning criterion before this turn, and that it's a valid "Tic-Tac-Toe" game. ------ Input ------ The first line of input contains one integer T denoting the number of testcases. First line of each testcase contains two integers N and K, next N lines contains N characters each. Each character is either an 'X' denoting that the first player used this cell, an 'O' meaning that the second player used this cell, or a '.' (a period) representing a free cell. ------ Output ------ For each testcase, output, in a single line, "YES" if Chef can win in one move, or "NO" otherwise. ------ Constraints ------ $1 ≀ T ≀ 100$ $3 ≀ N ≀ 20$ $1 ≀ K ≀ N$ ------ Subtasks ------ $Subtask 1: K = 1. Points - 10$ $Subtask 2: N = K = 3. Points - 30$ $Subtask 3: Original constraints. Points - 60$ ----- Sample Input 1 ------ 3 3 3 XOX O.O XOX 3 1 ... ... ... 3 2 ... ... ... ----- Sample Output 1 ------ YES YES NO ----- explanation 1 ------ Test #1: In first testcase, put 'X' in (2, 2), in second we can put 'X' in any cell and win. ----- Sample Input 2 ------ 1 4 4 XOXO OX.. XO.. OXOX ----- Sample Output 2 ------ YES ----- explanation 2 ------ Test #2: If you put an 'X' in (3, 3), there will be four 'X's on the main diagonal (1, 1) - (2, 2) - (3, 3) - (4, 4).
from sys import stdin T = int(stdin.readline().strip()) while T > 0: [N, K] = [int(n) for n in stdin.readline().strip().split()] grid1 = [0] * N for i in range(0, N): grid1[i] = list(stdin.readline().strip()) try: for i in range(0, N): for j in range(0, N): if grid1[i][j] == ".": count = 1 checkI, checkJ = i - 1, j - 1 while ( checkI >= 0 and checkJ >= 0 and grid1[checkI][checkJ] == "X" and count < K ): count += 1 checkI -= 1 checkJ -= 1 checkI, checkJ = i + 1, j + 1 while ( checkI < N and checkJ < N and grid1[checkI][checkJ] == "X" and count < K ): count += 1 checkI += 1 checkJ += 1 if count == K: raise Exception someFlag = True break count = 1 checkI, checkJ = i - 1, j + 1 while ( checkI >= 0 and checkJ < N and grid1[checkI][checkJ] == "X" and count < K ): count += 1 checkI -= 1 checkJ += 1 checkI, checkJ = i + 1, j - 1 while ( checkI < N and checkJ >= 0 and grid1[checkI][checkJ] == "X" and count < K ): count += 1 checkI += 1 checkJ -= 1 if count == K: raise Exception someFlag = True break count = 1 checkI = i - 1 while checkI >= 0 and grid1[checkI][j] == "X" and count < K: count += 1 checkI -= 1 checkI = i + 1 while checkI < N and grid1[checkI][j] == "X" and count < K: count += 1 checkI += 1 if count == K: raise Exception someFlag = True break count = 1 checkJ = j - 1 while checkJ >= 0 and grid1[i][checkJ] == "X" and count < K: count += 1 checkJ -= 1 checkJ = j + 1 while checkJ < N and grid1[i][checkJ] == "X" and count < K: count += 1 checkJ += 1 if count == K: raise Exception someFlag = True break except Exception: print("YES") else: print("NO") T -= 1
ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR WHILE VAR NUMBER ASSIGN LIST VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR STRING ASSIGN VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER WHILE VAR NUMBER VAR NUMBER VAR VAR VAR STRING VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER WHILE VAR VAR VAR VAR VAR VAR VAR STRING VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER WHILE VAR NUMBER VAR VAR VAR VAR VAR STRING VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER WHILE VAR VAR VAR NUMBER VAR VAR VAR STRING VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR VAR VAR STRING VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR VAR VAR VAR STRING VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR VAR VAR STRING VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR VAR VAR VAR STRING VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR ASSIGN VAR NUMBER VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING VAR NUMBER
Read problems statements in Mandarin Chinese , Russian and Vietnamese as well. Tic-Tac-Toe used to be Chef's favourite game during his childhood. Reminiscing in his childhood memories, he decided to create his own "Tic-Tac-Toe", with rules being similar to the original Tic-Tac-Toe, other than the fact that it is played on an NxN board. The game is played between two players taking turns. First player puts an 'X' in an empty cell of the board, then the second player puts an 'O' in some other free cell. If the first player has K continuous X's or the second player has K continuous O's in row, column or diagonal, then he wins. Chef started playing this new "Tic-Tac-Toe" with his assistant, beginning as the first player himself (that is, Chef plays 'X's). Currently, the game is ongoign, and it's Chef's turn. However, he needs to leave soon to begin tonight's dinner preparations, and has time to play only one more move. If he can win in one move, output "YES", otherwise output "NO" (without quotes). It is guaranteed that no player has already completed the winning criterion before this turn, and that it's a valid "Tic-Tac-Toe" game. ------ Input ------ The first line of input contains one integer T denoting the number of testcases. First line of each testcase contains two integers N and K, next N lines contains N characters each. Each character is either an 'X' denoting that the first player used this cell, an 'O' meaning that the second player used this cell, or a '.' (a period) representing a free cell. ------ Output ------ For each testcase, output, in a single line, "YES" if Chef can win in one move, or "NO" otherwise. ------ Constraints ------ $1 ≀ T ≀ 100$ $3 ≀ N ≀ 20$ $1 ≀ K ≀ N$ ------ Subtasks ------ $Subtask 1: K = 1. Points - 10$ $Subtask 2: N = K = 3. Points - 30$ $Subtask 3: Original constraints. Points - 60$ ----- Sample Input 1 ------ 3 3 3 XOX O.O XOX 3 1 ... ... ... 3 2 ... ... ... ----- Sample Output 1 ------ YES YES NO ----- explanation 1 ------ Test #1: In first testcase, put 'X' in (2, 2), in second we can put 'X' in any cell and win. ----- Sample Input 2 ------ 1 4 4 XOXO OX.. XO.. OXOX ----- Sample Output 2 ------ YES ----- explanation 2 ------ Test #2: If you put an 'X' in (3, 3), there will be four 'X's on the main diagonal (1, 1) - (2, 2) - (3, 3) - (4, 4).
T = int(input()) ops = [] for prog in range(0, T): N, K = map(int, input().split()) field = [] p1 = [1, 0, -1, 0] p2 = [0, -1, 0, 1] d1 = [1, -1, -1, 1] d2 = [-1, -1, 1, 1] for a in range(0, N): field.append(list(input())) def isFree(a, b): if a >= 0 and a < N: if b >= 0 and b < N: return True else: return False else: return False def check(a, b): done = False zbroj1 = 0 zbroj2 = 0 for p in range(0, 3, 2): for c in range(1, K): if isFree(a + c * p1[p], b + c * p2[p]) == True: if field[a + c * p1[p]][b + c * p2[p]] != "X": break else: zbroj1 += 1 else: break if zbroj1 + 1 >= K: done = True for p in range(1, 4, 2): for c in range(1, K): if isFree(a + c * p1[p], b + c * p2[p]) == True: if field[a + c * p1[p]][b + c * p2[p]] != "X": break else: zbroj2 += 1 else: break if zbroj2 + 1 >= K: done = True if done == False: zbroj1 = 0 zbroj2 = 0 for p in range(0, 3, 2): for c in range(1, K): if isFree(a + c * d1[p], b + c * d2[p]) == True: if field[a + c * d1[p]][b + c * d2[p]] != "X": break else: zbroj1 += 1 else: break if zbroj1 + 1 >= K: done = True for p in range(1, 4, 2): for c in range(1, K): if isFree(a + c * d1[p], b + c * d2[p]) == True: if field[a + c * d1[p]][b + c * d2[p]] != "X": break else: zbroj2 += 1 else: break if zbroj2 + 1 >= K: done = True return done def isGood(a, b): if field[a][b] == ".": return True else: return False op = False for a in range(0, N): for b in range(0, N): if isGood(a, b) == True: if check(a, b) == True: op = True break if op == False: ops.append("NO") else: ops.append("YES") for o in ops: print(o)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF IF VAR NUMBER VAR VAR IF VAR NUMBER VAR VAR RETURN NUMBER RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF FUNC_CALL VAR BIN_OP VAR BIN_OP VAR VAR VAR BIN_OP VAR BIN_OP VAR VAR VAR NUMBER IF VAR BIN_OP VAR BIN_OP VAR VAR VAR BIN_OP VAR BIN_OP VAR VAR VAR STRING VAR NUMBER IF BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF FUNC_CALL VAR BIN_OP VAR BIN_OP VAR VAR VAR BIN_OP VAR BIN_OP VAR VAR VAR NUMBER IF VAR BIN_OP VAR BIN_OP VAR VAR VAR BIN_OP VAR BIN_OP VAR VAR VAR STRING VAR NUMBER IF BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF FUNC_CALL VAR BIN_OP VAR BIN_OP VAR VAR VAR BIN_OP VAR BIN_OP VAR VAR VAR NUMBER IF VAR BIN_OP VAR BIN_OP VAR VAR VAR BIN_OP VAR BIN_OP VAR VAR VAR STRING VAR NUMBER IF BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF FUNC_CALL VAR BIN_OP VAR BIN_OP VAR VAR VAR BIN_OP VAR BIN_OP VAR VAR VAR NUMBER IF VAR BIN_OP VAR BIN_OP VAR VAR VAR BIN_OP VAR BIN_OP VAR VAR VAR STRING VAR NUMBER IF BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER RETURN VAR FUNC_DEF IF VAR VAR VAR STRING RETURN NUMBER RETURN NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF FUNC_CALL VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING FOR VAR VAR EXPR FUNC_CALL VAR VAR
Read problems statements in Mandarin Chinese , Russian and Vietnamese as well. Tic-Tac-Toe used to be Chef's favourite game during his childhood. Reminiscing in his childhood memories, he decided to create his own "Tic-Tac-Toe", with rules being similar to the original Tic-Tac-Toe, other than the fact that it is played on an NxN board. The game is played between two players taking turns. First player puts an 'X' in an empty cell of the board, then the second player puts an 'O' in some other free cell. If the first player has K continuous X's or the second player has K continuous O's in row, column or diagonal, then he wins. Chef started playing this new "Tic-Tac-Toe" with his assistant, beginning as the first player himself (that is, Chef plays 'X's). Currently, the game is ongoign, and it's Chef's turn. However, he needs to leave soon to begin tonight's dinner preparations, and has time to play only one more move. If he can win in one move, output "YES", otherwise output "NO" (without quotes). It is guaranteed that no player has already completed the winning criterion before this turn, and that it's a valid "Tic-Tac-Toe" game. ------ Input ------ The first line of input contains one integer T denoting the number of testcases. First line of each testcase contains two integers N and K, next N lines contains N characters each. Each character is either an 'X' denoting that the first player used this cell, an 'O' meaning that the second player used this cell, or a '.' (a period) representing a free cell. ------ Output ------ For each testcase, output, in a single line, "YES" if Chef can win in one move, or "NO" otherwise. ------ Constraints ------ $1 ≀ T ≀ 100$ $3 ≀ N ≀ 20$ $1 ≀ K ≀ N$ ------ Subtasks ------ $Subtask 1: K = 1. Points - 10$ $Subtask 2: N = K = 3. Points - 30$ $Subtask 3: Original constraints. Points - 60$ ----- Sample Input 1 ------ 3 3 3 XOX O.O XOX 3 1 ... ... ... 3 2 ... ... ... ----- Sample Output 1 ------ YES YES NO ----- explanation 1 ------ Test #1: In first testcase, put 'X' in (2, 2), in second we can put 'X' in any cell and win. ----- Sample Input 2 ------ 1 4 4 XOXO OX.. XO.. OXOX ----- Sample Output 2 ------ YES ----- explanation 2 ------ Test #2: If you put an 'X' in (3, 3), there will be four 'X's on the main diagonal (1, 1) - (2, 2) - (3, 3) - (4, 4).
def load_board(N): board = [None] * N for i in range(N): board[i] = input() return board def is_chef_winner(board, K): N = len(board) for row in range(N): for col in range(N): if board[row][col] == ".": h_num_X = 1 i = col - 1 while i >= 0 and board[row][i] == "X": h_num_X += 1 i -= 1 i = col + 1 while i < N and board[row][i] == "X": h_num_X += 1 i += 1 v_num_X = 1 i = row - 1 while i >= 0 and board[i][col] == "X": v_num_X += 1 i -= 1 i = row + 1 while i < N and board[i][col] == "X": v_num_X += 1 i += 1 d_num_X = 1 i = row - 1 j = col - 1 while i >= 0 and j >= 0 and board[i][j] == "X": d_num_X += 1 i -= 1 j -= 1 i = row + 1 j = col + 1 while i < N and j < N and board[i][j] == "X": d_num_X += 1 i += 1 j += 1 ad_num_X = 1 i = row - 1 j = col + 1 while i >= 0 and j < N and board[i][j] == "X": ad_num_X += 1 i -= 1 j += 1 i = row + 1 j = col - 1 while i < N and j >= 0 and board[i][j] == "X": ad_num_X += 1 i += 1 j -= 1 if h_num_X >= K or v_num_X >= K or d_num_X >= K or ad_num_X >= K: return True return False T = int(input()) for i in range(T): N, K = map(int, input().split()) board = load_board(N) if is_chef_winner(board, K): print("YES") else: print("NO")
FUNC_DEF ASSIGN VAR BIN_OP LIST NONE VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR VAR VAR STRING VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR VAR VAR VAR STRING VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR VAR VAR STRING VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR VAR VAR VAR STRING VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR NUMBER VAR VAR VAR STRING VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR VAR VAR VAR VAR VAR STRING VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR VAR VAR VAR VAR STRING VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR VAR NUMBER VAR VAR VAR STRING VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR VAR VAR VAR VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
A prime number is Super Prime if it is a sum of two primes. Find all the Super Primes upto N Example 1: Input: N = 5 Output: 1 Explanation: 5 = 2 + 3, 5 is the only super prime Example 2: Input: N = 10 Output: 2 Explanation: 5 and 7 are super primes Your Task: You don't need to read input or print anything. Your task is to complete the function superPrimes() which takes the N as input and returns the count of super primes. Expected Time Complexity: O(Nlog(logN)) Expected Auxiliary Space: O(N) Constraints: 1 ≀ N ≀ 10^{5}
class Solution: def superPrimes(self, n): p = [0] * (n + 1) count = 0 for i in range(2, int(n**0.5) + 1): if p[i] == 0: for j in range(i * i, n + 1, i): p[j] = 1 for i in range(5, n + 1): if p[i] == 0 and p[i - 2] == 0: count += 1 return count
CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER RETURN VAR
A prime number is Super Prime if it is a sum of two primes. Find all the Super Primes upto N Example 1: Input: N = 5 Output: 1 Explanation: 5 = 2 + 3, 5 is the only super prime Example 2: Input: N = 10 Output: 2 Explanation: 5 and 7 are super primes Your Task: You don't need to read input or print anything. Your task is to complete the function superPrimes() which takes the N as input and returns the count of super primes. Expected Time Complexity: O(Nlog(logN)) Expected Auxiliary Space: O(N) Constraints: 1 ≀ N ≀ 10^{5}
N = 10**5 + 5 prime = [0] * N prime[0] = 1 prime[1] = 1 p = [] for i in range(2, N): if prime[i] != 0: continue for j in range(i * 2, N, i): prime[j] = 1 if prime[i] == 0: p.append(i) class Solution: def superPrimes(self, n): c = 0 for j in p: if j <= n: if prime[j - 2] == 0: c += 1 else: break return c
ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR IF VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER RETURN VAR
A prime number is Super Prime if it is a sum of two primes. Find all the Super Primes upto N Example 1: Input: N = 5 Output: 1 Explanation: 5 = 2 + 3, 5 is the only super prime Example 2: Input: N = 10 Output: 2 Explanation: 5 and 7 are super primes Your Task: You don't need to read input or print anything. Your task is to complete the function superPrimes() which takes the N as input and returns the count of super primes. Expected Time Complexity: O(Nlog(logN)) Expected Auxiliary Space: O(N) Constraints: 1 ≀ N ≀ 10^{5}
class Solution: def superPrimes(self, n): count = 0 primes = [True] * (n + 1) primes[0] = primes[1] = False for i in range(2, n + 1): if primes[i]: if primes[i - 2]: count += 1 for j in range(i * i, n + 1, i): primes[j] = False return count
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR IF VAR BIN_OP VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR NUMBER RETURN VAR
A prime number is Super Prime if it is a sum of two primes. Find all the Super Primes upto N Example 1: Input: N = 5 Output: 1 Explanation: 5 = 2 + 3, 5 is the only super prime Example 2: Input: N = 10 Output: 2 Explanation: 5 and 7 are super primes Your Task: You don't need to read input or print anything. Your task is to complete the function superPrimes() which takes the N as input and returns the count of super primes. Expected Time Complexity: O(Nlog(logN)) Expected Auxiliary Space: O(N) Constraints: 1 ≀ N ≀ 10^{5}
class Solution: def superPrimes(self, n): aux = [True] * (n + 1) aux[0] = False aux[1] = False prime = [] ans = 0 for i in range(2, n + 1): if aux[i]: prime.append(i) for j in range(i * i, n + 1, i): aux[j] = False for i in range(len(prime)): if aux[prime[i] - 2]: ans += 1 return ans
CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR VAR NUMBER VAR NUMBER RETURN VAR
A prime number is Super Prime if it is a sum of two primes. Find all the Super Primes upto N Example 1: Input: N = 5 Output: 1 Explanation: 5 = 2 + 3, 5 is the only super prime Example 2: Input: N = 10 Output: 2 Explanation: 5 and 7 are super primes Your Task: You don't need to read input or print anything. Your task is to complete the function superPrimes() which takes the N as input and returns the count of super primes. Expected Time Complexity: O(Nlog(logN)) Expected Auxiliary Space: O(N) Constraints: 1 ≀ N ≀ 10^{5}
class Solution: def superPrimes(self, n): prime = [(True) for i in range(n + 1)] p = 2 while p * p <= n: if prime[p] == True: for i in range(p * p, n + 1, p): prime[i] = False p += 1 last = 3 count = 0 for p in range(2, n + 1): if prime[p]: if p - 2 == last: count += 1 last = p return count
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR IF VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR IF BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR RETURN VAR
A prime number is Super Prime if it is a sum of two primes. Find all the Super Primes upto N Example 1: Input: N = 5 Output: 1 Explanation: 5 = 2 + 3, 5 is the only super prime Example 2: Input: N = 10 Output: 2 Explanation: 5 and 7 are super primes Your Task: You don't need to read input or print anything. Your task is to complete the function superPrimes() which takes the N as input and returns the count of super primes. Expected Time Complexity: O(Nlog(logN)) Expected Auxiliary Space: O(N) Constraints: 1 ≀ N ≀ 10^{5}
def seive(n): n += 5 arr = [1] * n arr[0] = arr[1] = 0 for i in range(2, n): if arr[i] == 0: continue for j in range(i * i, n, i): arr[j] = 0 return arr class Solution: def superPrimes(self, n): arr = seive(n) m = len(arr) ans = 0 for i in range(5, n + 1): ans += arr[i] and arr[i - 2] return ans
FUNC_DEF VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR NUMBER RETURN VAR CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER RETURN VAR
A prime number is Super Prime if it is a sum of two primes. Find all the Super Primes upto N Example 1: Input: N = 5 Output: 1 Explanation: 5 = 2 + 3, 5 is the only super prime Example 2: Input: N = 10 Output: 2 Explanation: 5 and 7 are super primes Your Task: You don't need to read input or print anything. Your task is to complete the function superPrimes() which takes the N as input and returns the count of super primes. Expected Time Complexity: O(Nlog(logN)) Expected Auxiliary Space: O(N) Constraints: 1 ≀ N ≀ 10^{5}
class Solution: def superPrimes(self, n): ans = 0 primes = [(True) for i in range(n + 1)] def prime(n): i = 2 primes[0] = False primes[1] = False while i * i <= n: if primes[i] == True: for k in range(i + i, n + 1, i): primes[k] = False i += 1 prime(n) arr = [] for each in range(len(primes)): if primes[each]: arr.append(each) for num in arr: if primes[num]: if primes[num - 2]: ans += 1 return ans if __name__ == "__main__": T = int(input()) for i in range(T): n = int(input()) ob = Solution() ans = ob.superPrimes(n) print(ans)
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER WHILE BIN_OP VAR VAR VAR IF VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR VAR IF VAR VAR IF VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR IF VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
A prime number is Super Prime if it is a sum of two primes. Find all the Super Primes upto N Example 1: Input: N = 5 Output: 1 Explanation: 5 = 2 + 3, 5 is the only super prime Example 2: Input: N = 10 Output: 2 Explanation: 5 and 7 are super primes Your Task: You don't need to read input or print anything. Your task is to complete the function superPrimes() which takes the N as input and returns the count of super primes. Expected Time Complexity: O(Nlog(logN)) Expected Auxiliary Space: O(N) Constraints: 1 ≀ N ≀ 10^{5}
class Solution: def superPrimes(self, n): if n == 5: return 1 def p(N): if N <= 2: return [] is_prime = [True] * N is_prime[0] = False is_prime[1] = False for i in range(2, int(N**0.5) + 1): if is_prime[i]: for x in range(i * i, n, i): is_prime[x] = False return [i for i in range(N) if is_prime[i]] z = n + 1 a = p(z) y = a[-1] for i in range(2, int(y**0.5)): if y % i == 0: a.pop() break count = 0 for i in range(len(a) - 1): if a[i] + 2 == a[i + 1]: count += 1 return count
CLASS_DEF FUNC_DEF IF VAR NUMBER RETURN NUMBER FUNC_DEF IF VAR NUMBER RETURN LIST ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR NUMBER RETURN VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR
A prime number is Super Prime if it is a sum of two primes. Find all the Super Primes upto N Example 1: Input: N = 5 Output: 1 Explanation: 5 = 2 + 3, 5 is the only super prime Example 2: Input: N = 10 Output: 2 Explanation: 5 and 7 are super primes Your Task: You don't need to read input or print anything. Your task is to complete the function superPrimes() which takes the N as input and returns the count of super primes. Expected Time Complexity: O(Nlog(logN)) Expected Auxiliary Space: O(N) Constraints: 1 ≀ N ≀ 10^{5}
class Solution: def superPrimes(self, n): def check(n): seive = [True] * (n + 1) seive[0], seive[1] = False, False p = 2 while p * p <= n: if seive[p] == True: for i in range(p * p, n + 1, p): seive[i] = False p += 1 return seive count = 0 ans = check(n) for i in range(5, n + 1): res = i - 2 if ans[res] and ans[i]: count += 1 return count
CLASS_DEF FUNC_DEF FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR IF VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER RETURN VAR
A prime number is Super Prime if it is a sum of two primes. Find all the Super Primes upto N Example 1: Input: N = 5 Output: 1 Explanation: 5 = 2 + 3, 5 is the only super prime Example 2: Input: N = 10 Output: 2 Explanation: 5 and 7 are super primes Your Task: You don't need to read input or print anything. Your task is to complete the function superPrimes() which takes the N as input and returns the count of super primes. Expected Time Complexity: O(Nlog(logN)) Expected Auxiliary Space: O(N) Constraints: 1 ≀ N ≀ 10^{5}
class Solution: def prime(self, n): x = [(True) for i in range(n + 1)] p = 2 while p <= n: if x[p] == True: for i in range(p * p, n + 1, p): x[i] = False p += 1 y = [] for i in range(2, n + 1): if x[i]: y.append(i) return y def superPrimes(self, n): x = self.prime(n) y = set(x) p = 0 for i in x: if i + 2 in y: p += 1 return p
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR NUMBER VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR NUMBER VAR VAR NUMBER RETURN VAR
A prime number is Super Prime if it is a sum of two primes. Find all the Super Primes upto N Example 1: Input: N = 5 Output: 1 Explanation: 5 = 2 + 3, 5 is the only super prime Example 2: Input: N = 10 Output: 2 Explanation: 5 and 7 are super primes Your Task: You don't need to read input or print anything. Your task is to complete the function superPrimes() which takes the N as input and returns the count of super primes. Expected Time Complexity: O(Nlog(logN)) Expected Auxiliary Space: O(N) Constraints: 1 ≀ N ≀ 10^{5}
def Soe(n): prime = [(True) for i in range(n + 1)] p = 2 while p * p <= n: if prime[p] == True: for i in range(p * p, n + 1, p): prime[i] = False p += 1 return prime class Solution: def superPrimes(self, n): if n < 5: return 0 prime = Soe(n) prime[0] = False prime[1] = False c = 0 for i in range(4, n + 1): if prime[i] and prime[i - 2]: c += 1 return c
FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR IF VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR NUMBER VAR NUMBER RETURN VAR CLASS_DEF FUNC_DEF IF VAR NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR
A prime number is Super Prime if it is a sum of two primes. Find all the Super Primes upto N Example 1: Input: N = 5 Output: 1 Explanation: 5 = 2 + 3, 5 is the only super prime Example 2: Input: N = 10 Output: 2 Explanation: 5 and 7 are super primes Your Task: You don't need to read input or print anything. Your task is to complete the function superPrimes() which takes the N as input and returns the count of super primes. Expected Time Complexity: O(Nlog(logN)) Expected Auxiliary Space: O(N) Constraints: 1 ≀ N ≀ 10^{5}
class Solution: def superPrimes(self, n): def makeprime(N): visited = [1] * (N + 1) primes = {} for i in range(2, N + 1): if visited[i] == 1: primes[i] = 1 for j in range(i + i, N + 1, i): visited[j] = 0 return primes prime = makeprime(n) count = 0 for i in prime: if i + 2 in prime: count += 1 return count
CLASS_DEF FUNC_DEF FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR NUMBER VAR VAR NUMBER RETURN VAR
A prime number is Super Prime if it is a sum of two primes. Find all the Super Primes upto N Example 1: Input: N = 5 Output: 1 Explanation: 5 = 2 + 3, 5 is the only super prime Example 2: Input: N = 10 Output: 2 Explanation: 5 and 7 are super primes Your Task: You don't need to read input or print anything. Your task is to complete the function superPrimes() which takes the N as input and returns the count of super primes. Expected Time Complexity: O(Nlog(logN)) Expected Auxiliary Space: O(N) Constraints: 1 ≀ N ≀ 10^{5}
class Solution: def superPrimes(self, n): if n < 5: return 0 if n < 7: return 1 count = 1 a = 7 while a <= n: if self.isPrime(a) and self.isPrime(a - 2): count += 1 a += 6 return count def isPrime(self, n): if n < 2: return False if n == 2 or n == 3: return True if n % 2 == 0: return False if n % 3 == 0: return False l = int(n**0.5) a = 5 b = 2 while a <= l: if n % a == 0: return False a += b b = 6 - b return True
CLASS_DEF FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER RETURN VAR FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR NUMBER VAR NUMBER RETURN NUMBER IF BIN_OP VAR NUMBER NUMBER RETURN NUMBER IF BIN_OP VAR NUMBER NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF BIN_OP VAR VAR NUMBER RETURN NUMBER VAR VAR ASSIGN VAR BIN_OP NUMBER VAR RETURN NUMBER
A prime number is Super Prime if it is a sum of two primes. Find all the Super Primes upto N Example 1: Input: N = 5 Output: 1 Explanation: 5 = 2 + 3, 5 is the only super prime Example 2: Input: N = 10 Output: 2 Explanation: 5 and 7 are super primes Your Task: You don't need to read input or print anything. Your task is to complete the function superPrimes() which takes the N as input and returns the count of super primes. Expected Time Complexity: O(Nlog(logN)) Expected Auxiliary Space: O(N) Constraints: 1 ≀ N ≀ 10^{5}
class Solution: def superPrimes(self, n): primes = [] p = 2 vals = [val for val in range(0, n + 1)] bools = [(False) for item in range(0, n + 1)] count = 0 while p <= int(n ** (1 / 2)): if bools[p] == False: for i in range(2 * p, n + 1, p): bools[i] = True p += 1 else: p += 1 primes = [vals[item] for item in vals if bools[item] == False][2:] for i in range(0, len(primes) - 1): if 2 + primes[i] == primes[i + 1]: count += 1 return count
CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR BIN_OP VAR BIN_OP NUMBER NUMBER IF VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF BIN_OP NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR
A prime number is Super Prime if it is a sum of two primes. Find all the Super Primes upto N Example 1: Input: N = 5 Output: 1 Explanation: 5 = 2 + 3, 5 is the only super prime Example 2: Input: N = 10 Output: 2 Explanation: 5 and 7 are super primes Your Task: You don't need to read input or print anything. Your task is to complete the function superPrimes() which takes the N as input and returns the count of super primes. Expected Time Complexity: O(Nlog(logN)) Expected Auxiliary Space: O(N) Constraints: 1 ≀ N ≀ 10^{5}
class Solution: def is_prime(self, num): end = int(num**0.5) for i in range(7, end + 1, 2): if num % i == 0: return False return True def superPrimes(self, n): if n < 5: return 0 if n == 5: return 1 if n == 7: return 2 if n == 13: return 3 count = 3 prev = 17 for i in range(19, n + 1, 2): if i % 3 != 0 and i % 5 != 0 and self.is_prime(i): if prev + 2 == i: prev = i count += 1 else: prev = i return count
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR VAR NUMBER RETURN NUMBER RETURN NUMBER FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR RETURN VAR
A prime number is Super Prime if it is a sum of two primes. Find all the Super Primes upto N Example 1: Input: N = 5 Output: 1 Explanation: 5 = 2 + 3, 5 is the only super prime Example 2: Input: N = 10 Output: 2 Explanation: 5 and 7 are super primes Your Task: You don't need to read input or print anything. Your task is to complete the function superPrimes() which takes the N as input and returns the count of super primes. Expected Time Complexity: O(Nlog(logN)) Expected Auxiliary Space: O(N) Constraints: 1 ≀ N ≀ 10^{5}
class Solution: def superPrimes(self, n): p = [1] * (n + 1) for i in range(2, (n + 1) // 2): if p[i]: j = 2 while i * j < n + 1: p[i * j] = 0 j += 1 c = 0 for i in range(5, n + 1): if p[i] and p[i - 2]: c += 1 return c
CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER IF VAR VAR ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR
A prime number is Super Prime if it is a sum of two primes. Find all the Super Primes upto N Example 1: Input: N = 5 Output: 1 Explanation: 5 = 2 + 3, 5 is the only super prime Example 2: Input: N = 10 Output: 2 Explanation: 5 and 7 are super primes Your Task: You don't need to read input or print anything. Your task is to complete the function superPrimes() which takes the N as input and returns the count of super primes. Expected Time Complexity: O(Nlog(logN)) Expected Auxiliary Space: O(N) Constraints: 1 ≀ N ≀ 10^{5}
from itertools import combinations as c class Solution: def isPrime(self, x): for i in range(2, x): if x % i == 0: return False return True def superPrimes(self, n): ans = 0 primes = [(True) for i in range(n + 1)] def prime(n): i = 2 primes[0] = False primes[1] = False while i * i <= n: if primes[i] == True: for k in range(i + i, n + 1, i): primes[k] = False i += 1 prime(n) arr = [] for each in range(len(primes)): if primes[each]: arr.append(each) for num in arr: if primes[num]: if primes[num - 2]: ans += 1 return ans
CLASS_DEF FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR VAR NUMBER RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER WHILE BIN_OP VAR VAR VAR IF VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR VAR IF VAR VAR IF VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR
A prime number is Super Prime if it is a sum of two primes. Find all the Super Primes upto N Example 1: Input: N = 5 Output: 1 Explanation: 5 = 2 + 3, 5 is the only super prime Example 2: Input: N = 10 Output: 2 Explanation: 5 and 7 are super primes Your Task: You don't need to read input or print anything. Your task is to complete the function superPrimes() which takes the N as input and returns the count of super primes. Expected Time Complexity: O(Nlog(logN)) Expected Auxiliary Space: O(N) Constraints: 1 ≀ N ≀ 10^{5}
class Solution: m = 10**5 sieve = [(True) for i in range(m + 1)] for i in range(2, m + 1): if sieve[i]: for j in range(i * i, m + 1, i): sieve[j] = False def superPrimes(self, n): l = [] for i in range(2, n + 1): if self.sieve[i]: l.append(i) c = 0 for i in l: if i + 2 <= n and self.sieve[i + 2]: c += 1 return c
CLASS_DEF ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR NUMBER FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR
A prime number is Super Prime if it is a sum of two primes. Find all the Super Primes upto N Example 1: Input: N = 5 Output: 1 Explanation: 5 = 2 + 3, 5 is the only super prime Example 2: Input: N = 10 Output: 2 Explanation: 5 and 7 are super primes Your Task: You don't need to read input or print anything. Your task is to complete the function superPrimes() which takes the N as input and returns the count of super primes. Expected Time Complexity: O(Nlog(logN)) Expected Auxiliary Space: O(N) Constraints: 1 ≀ N ≀ 10^{5}
class Solution: def superPrimes(self, n): a = [(True) for i in range(n + 1)] a[0] = False a[1] = False for i in range(2, n + 1): if a[i]: for j in range(i * 2, n + 1, i): a[j] = False c = 0 for i in range(2, n - 1): if a[i] and a[i + 2]: c += 1 return c
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR
A prime number is Super Prime if it is a sum of two primes. Find all the Super Primes upto N Example 1: Input: N = 5 Output: 1 Explanation: 5 = 2 + 3, 5 is the only super prime Example 2: Input: N = 10 Output: 2 Explanation: 5 and 7 are super primes Your Task: You don't need to read input or print anything. Your task is to complete the function superPrimes() which takes the N as input and returns the count of super primes. Expected Time Complexity: O(Nlog(logN)) Expected Auxiliary Space: O(N) Constraints: 1 ≀ N ≀ 10^{5}
class Solution: def superPrimes(self, n): p = [True] * (n + 1) if n <= 2: return 0 for i in range(2, int(n**0.5) + 1): if p[i]: for j in range(i * 2, n + 1, i): p[j] = False c = 0 p = p[2:] for i in range(len(p)): if i >= 2 and p[i] and p[i - 2]: c += 1 return c
CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER IF VAR NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR
A prime number is Super Prime if it is a sum of two primes. Find all the Super Primes upto N Example 1: Input: N = 5 Output: 1 Explanation: 5 = 2 + 3, 5 is the only super prime Example 2: Input: N = 10 Output: 2 Explanation: 5 and 7 are super primes Your Task: You don't need to read input or print anything. Your task is to complete the function superPrimes() which takes the N as input and returns the count of super primes. Expected Time Complexity: O(Nlog(logN)) Expected Auxiliary Space: O(N) Constraints: 1 ≀ N ≀ 10^{5}
class Solution: def allPrimes(self, n): allNumbers = [(True) for i in range(0, n + 1)] for p in range(2, n + 1): if not allNumbers[p]: continue if n < p * p: break curP = 2 * p while curP <= n: allNumbers[curP] = False curP += p allNumbers[0] = False allNumbers[1] = False primes = [i for i in range(n + 1) if allNumbers[i]] return primes def superPrimes(self, n): primes = self.allPrimes(n) result = 0 for i in range(len(primes) - 1): if primes[i + 1] == primes[i] + 2: result += 1 return result
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR IF VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP NUMBER VAR WHILE VAR VAR ASSIGN VAR VAR NUMBER VAR VAR ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER BIN_OP VAR VAR NUMBER VAR NUMBER RETURN VAR
A prime number is Super Prime if it is a sum of two primes. Find all the Super Primes upto N Example 1: Input: N = 5 Output: 1 Explanation: 5 = 2 + 3, 5 is the only super prime Example 2: Input: N = 10 Output: 2 Explanation: 5 and 7 are super primes Your Task: You don't need to read input or print anything. Your task is to complete the function superPrimes() which takes the N as input and returns the count of super primes. Expected Time Complexity: O(Nlog(logN)) Expected Auxiliary Space: O(N) Constraints: 1 ≀ N ≀ 10^{5}
class Solution: def superPrimes(self, n): if n < 5: return 0 if n < 7: return 1 isPrime = self.sieveOfEratosthenes(n) count = 1 for i in range(6, n + 1): if isPrime[i] and isPrime[i - 2]: count += 1 return count def sieveOfEratosthenes(self, n): isPrime = [True] * (n + 1) isPrime[0] = isPrime[1] = False for i in range(2, int(n ** (1 / 2)) + 1): if isPrime[i]: for j in range(i * i, n + 1, i): isPrime[j] = False return isPrime
CLASS_DEF FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR BIN_OP VAR BIN_OP NUMBER NUMBER NUMBER IF VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR NUMBER RETURN VAR
A prime number is Super Prime if it is a sum of two primes. Find all the Super Primes upto N Example 1: Input: N = 5 Output: 1 Explanation: 5 = 2 + 3, 5 is the only super prime Example 2: Input: N = 10 Output: 2 Explanation: 5 and 7 are super primes Your Task: You don't need to read input or print anything. Your task is to complete the function superPrimes() which takes the N as input and returns the count of super primes. Expected Time Complexity: O(Nlog(logN)) Expected Auxiliary Space: O(N) Constraints: 1 ≀ N ≀ 10^{5}
class Solution: def superPrimes(self, n): isprime = [True] * (n + 1) isprime[0] = False isprime[1] = False total = n - 2 number = 2 primes = [] while number**2 <= n and total != 0: if isprime[number]: primes.append(number) for i in range(number * 2, n + 1, number): isprime[i] = False total = total + 1 number = number + 1 for i in range(number, n + 1): if isprime[i]: primes.append(i) count = 0 for num in primes: if isprime[num - 2]: count = count + 1 return count
CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST WHILE BIN_OP VAR NUMBER VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR
A prime number is Super Prime if it is a sum of two primes. Find all the Super Primes upto N Example 1: Input: N = 5 Output: 1 Explanation: 5 = 2 + 3, 5 is the only super prime Example 2: Input: N = 10 Output: 2 Explanation: 5 and 7 are super primes Your Task: You don't need to read input or print anything. Your task is to complete the function superPrimes() which takes the N as input and returns the count of super primes. Expected Time Complexity: O(Nlog(logN)) Expected Auxiliary Space: O(N) Constraints: 1 ≀ N ≀ 10^{5}
class Solution: def superPrimes(self, n): a = [True] * (n + 1) b = [] i = 2 while i * i <= n + 1: if a[i]: for j in range(2 * i, n + 1, i): a[j] = 0 i += 1 for i in range(2, n + 1): if a[i]: b += (i,) ans = 0 for i in range(len(b)): f = 0 for j in range(i + 1, len(b)): if b[i] + b[j] > n: f = 1 break if a[b[i] + b[j]]: ans += 1 if f: break return ans
CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR BIN_OP VAR NUMBER IF VAR VAR FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR BIN_OP VAR VAR VAR VAR VAR NUMBER IF VAR RETURN VAR
A prime number is Super Prime if it is a sum of two primes. Find all the Super Primes upto N Example 1: Input: N = 5 Output: 1 Explanation: 5 = 2 + 3, 5 is the only super prime Example 2: Input: N = 10 Output: 2 Explanation: 5 and 7 are super primes Your Task: You don't need to read input or print anything. Your task is to complete the function superPrimes() which takes the N as input and returns the count of super primes. Expected Time Complexity: O(Nlog(logN)) Expected Auxiliary Space: O(N) Constraints: 1 ≀ N ≀ 10^{5}
class Solution: def isPrime(self, n): if n < 2: return False if n == 2 or n == 3: return True if n % 2 == 0: return False if n % 3 == 0: return False limit = int(n**0.5) i = 5 t = 2 while i <= limit: if n % i == 0: return False i += t t = 6 - t return True def superPrimes(self, n): if n < 5: return 0 if n < 7: return 1 count = 1 i = 7 while i <= n: if self.isPrime(i) and self.isPrime(i - 2): count += 1 i += 6 return count
CLASS_DEF FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR NUMBER VAR NUMBER RETURN NUMBER IF BIN_OP VAR NUMBER NUMBER RETURN NUMBER IF BIN_OP VAR NUMBER NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF BIN_OP VAR VAR NUMBER RETURN NUMBER VAR VAR ASSIGN VAR BIN_OP NUMBER VAR RETURN NUMBER FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER RETURN VAR
A prime number is Super Prime if it is a sum of two primes. Find all the Super Primes upto N Example 1: Input: N = 5 Output: 1 Explanation: 5 = 2 + 3, 5 is the only super prime Example 2: Input: N = 10 Output: 2 Explanation: 5 and 7 are super primes Your Task: You don't need to read input or print anything. Your task is to complete the function superPrimes() which takes the N as input and returns the count of super primes. Expected Time Complexity: O(Nlog(logN)) Expected Auxiliary Space: O(N) Constraints: 1 ≀ N ≀ 10^{5}
class Solution: def superPrimes(self, n): if n < 5: return 0 ans = temp = left = right = 0 index = 2 arr = [0] * (n + 1) arr[2] = 1 prime = [] while index <= n: if arr[index] == -1: index += 1 else: prime.append(index) while index * temp <= n: arr[index * temp] = -1 temp += 1 temp = 0 index += 1 arr = [0] * (n + 1) for i in prime: if i != 2: arr[i] = 1 for i in prime: if 2 + i < len(arr): if arr[2 + i] == 1: ans += 1 return ans
CLASS_DEF FUNC_DEF IF VAR NUMBER RETURN NUMBER ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR LIST WHILE VAR VAR IF VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR WHILE BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR VAR IF VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR VAR IF BIN_OP NUMBER VAR FUNC_CALL VAR VAR IF VAR BIN_OP NUMBER VAR NUMBER VAR NUMBER RETURN VAR
A prime number is Super Prime if it is a sum of two primes. Find all the Super Primes upto N Example 1: Input: N = 5 Output: 1 Explanation: 5 = 2 + 3, 5 is the only super prime Example 2: Input: N = 10 Output: 2 Explanation: 5 and 7 are super primes Your Task: You don't need to read input or print anything. Your task is to complete the function superPrimes() which takes the N as input and returns the count of super primes. Expected Time Complexity: O(Nlog(logN)) Expected Auxiliary Space: O(N) Constraints: 1 ≀ N ≀ 10^{5}
class Solution: def superPrimes(self, n): end = n + 1 dp = [0] * end for i in range(2, end): if dp[i] == 0: j = i + i while j < end: dp[j] = 1 j += i cnt = 0 for i in range(5, end): if dp[i] == 0 and dp[i - 2] == 0: cnt += 1 return cnt
CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR WHILE VAR VAR ASSIGN VAR VAR NUMBER VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER RETURN VAR
A prime number is Super Prime if it is a sum of two primes. Find all the Super Primes upto N Example 1: Input: N = 5 Output: 1 Explanation: 5 = 2 + 3, 5 is the only super prime Example 2: Input: N = 10 Output: 2 Explanation: 5 and 7 are super primes Your Task: You don't need to read input or print anything. Your task is to complete the function superPrimes() which takes the N as input and returns the count of super primes. Expected Time Complexity: O(Nlog(logN)) Expected Auxiliary Space: O(N) Constraints: 1 ≀ N ≀ 10^{5}
class Solution: def seive(self, n): prime = [(True) for i in range(n + 1)] p = 2 while p * p <= n: if prime[p] == True: for i in range(p * p, n + 1, p): prime[i] = False p += 1 a2 = [] for i in range(2, len(prime)): if prime[i] == True: a2.append(i) return a2 def superPrimes(self, n): count = 0 a2 = self.seive(n) for i in range(len(a2) - 1): if a2[i + 1] - a2[i] == 2: count += 1 return count
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR IF VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR NUMBER VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER VAR VAR NUMBER VAR NUMBER RETURN VAR
A prime number is Super Prime if it is a sum of two primes. Find all the Super Primes upto N Example 1: Input: N = 5 Output: 1 Explanation: 5 = 2 + 3, 5 is the only super prime Example 2: Input: N = 10 Output: 2 Explanation: 5 and 7 are super primes Your Task: You don't need to read input or print anything. Your task is to complete the function superPrimes() which takes the N as input and returns the count of super primes. Expected Time Complexity: O(Nlog(logN)) Expected Auxiliary Space: O(N) Constraints: 1 ≀ N ≀ 10^{5}
class Solution: def superPrimes(self, n): a = [0] * (n + 1) for i in range(2, n + 1): if a[i] == 0: for j in range(2, n // i + 1): a[i * j] = 1 arr = [] for i in range(2, n + 1): if a[i] == 0: arr.append(i) ans = 0 a1 = [0] * (n + 1) for i in range(1, len(arr)): if arr[i] + 2 > n: break if a[arr[i] + 2] == 0: if a1[arr[i] + 2] == 0: a1[arr[i] + 2] = 1 ans += 1 return ans
CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER VAR IF VAR BIN_OP VAR VAR NUMBER NUMBER IF VAR BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER RETURN VAR
A prime number is Super Prime if it is a sum of two primes. Find all the Super Primes upto N Example 1: Input: N = 5 Output: 1 Explanation: 5 = 2 + 3, 5 is the only super prime Example 2: Input: N = 10 Output: 2 Explanation: 5 and 7 are super primes Your Task: You don't need to read input or print anything. Your task is to complete the function superPrimes() which takes the N as input and returns the count of super primes. Expected Time Complexity: O(Nlog(logN)) Expected Auxiliary Space: O(N) Constraints: 1 ≀ N ≀ 10^{5}
class Solution: def prime(self, n): pri = [] for i in range(n + 1): pri.append(i) pri[0] = 0 pri[1] = 0 p = 2 while p * p <= n: if p != 0: for i in range(p * 2, n + 1, p): pri[i] = 0 p += 1 return set(pri) def superPrimes(self, n): count = 0 prim = self.prime(n) for i in prim: if i + 2 in prim: count += 1 return count - 1
CLASS_DEF FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR IF VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR ASSIGN VAR VAR NUMBER VAR NUMBER RETURN FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR IF BIN_OP VAR NUMBER VAR VAR NUMBER RETURN BIN_OP VAR NUMBER
A prime number is Super Prime if it is a sum of two primes. Find all the Super Primes upto N Example 1: Input: N = 5 Output: 1 Explanation: 5 = 2 + 3, 5 is the only super prime Example 2: Input: N = 10 Output: 2 Explanation: 5 and 7 are super primes Your Task: You don't need to read input or print anything. Your task is to complete the function superPrimes() which takes the N as input and returns the count of super primes. Expected Time Complexity: O(Nlog(logN)) Expected Auxiliary Space: O(N) Constraints: 1 ≀ N ≀ 10^{5}
class Solution: def superPrimes(self, n): count = 0 arr = [(True) for i in range(n + 1)] arr[0], arr[1] = False, False p = 2 while p * p <= n: if arr[p]: for i in range(p * p, n + 1, p): arr[i] = False p += 1 for i in range(n + 1): if arr[i] and arr[i - 2]: count += 1 return count
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR IF VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR
Alice and Bob play 5-in-a-row game. They have a playing field of size 10 Γ— 10. In turns they put either crosses or noughts, one at a time. Alice puts crosses and Bob puts noughts. In current match they have made some turns and now it's Alice's turn. She wonders if she can put cross in such empty cell that she wins immediately. Alice wins if some crosses in the field form line of length not smaller than 5. This line can be horizontal, vertical and diagonal. -----Input----- You are given matrix 10 Γ— 10 (10 lines of 10 characters each) with capital Latin letters 'X' being a cross, letters 'O' being a nought and '.' being an empty cell. The number of 'X' cells is equal to the number of 'O' cells and there is at least one of each type. There is at least one empty cell. It is guaranteed that in the current arrangement nobody has still won. -----Output----- Print 'YES' if it's possible for Alice to win in one turn by putting cross in some empty cell. Otherwise print 'NO'. -----Examples----- Input XX.XX..... .....OOOO. .......... .......... .......... .......... .......... .......... .......... .......... Output YES Input XXOXX..... OO.O...... .......... .......... .......... .......... .......... .......... .......... .......... Output NO
def horizontal(mas): for i in range(len(mas) - 4): k = "" for j in range(i, i + 5): k += str(mas[j]) if k == "XXXX.": return True elif k == ".XXXX": return True elif k == "X.XXX": return True elif k == "XX.XX": return True elif k == "XXX.X": return True return False mas = [] flag = 0 for i in range(10): mas.append(list(input())) for i in range(10): f = horizontal(mas[i]) if f == True and flag == 0: flag = 1 print("YES") for i in range(10): ans = [] for j in range(10): ans.append(mas[j][i]) s = horizontal(ans) if s == True and flag == 0: flag = 1 print("YES") for i in range(10): for j in range(10): ans = [] for o in range(10): if o + j == 10 or i + o == 10: break ans.append(mas[o + i][o + j]) t = horizontal(ans) if t == True and flag == 0: flag = 1 print("YES") for i in range(10): for j in range(9, 0, -1): ans = [] for o in range(10): if j - o < 0 or i + o == 10: break ans.append(mas[o + i][j - o]) d = horizontal(ans) if d == True and flag == 0: flag = 1 print("YES") if flag == 0: print("NO")
FUNC_DEF FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR VAR IF VAR STRING RETURN NUMBER IF VAR STRING RETURN NUMBER IF VAR STRING RETURN NUMBER IF VAR STRING RETURN NUMBER IF VAR STRING RETURN NUMBER RETURN NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING
Alice and Bob play 5-in-a-row game. They have a playing field of size 10 Γ— 10. In turns they put either crosses or noughts, one at a time. Alice puts crosses and Bob puts noughts. In current match they have made some turns and now it's Alice's turn. She wonders if she can put cross in such empty cell that she wins immediately. Alice wins if some crosses in the field form line of length not smaller than 5. This line can be horizontal, vertical and diagonal. -----Input----- You are given matrix 10 Γ— 10 (10 lines of 10 characters each) with capital Latin letters 'X' being a cross, letters 'O' being a nought and '.' being an empty cell. The number of 'X' cells is equal to the number of 'O' cells and there is at least one of each type. There is at least one empty cell. It is guaranteed that in the current arrangement nobody has still won. -----Output----- Print 'YES' if it's possible for Alice to win in one turn by putting cross in some empty cell. Otherwise print 'NO'. -----Examples----- Input XX.XX..... .....OOOO. .......... .......... .......... .......... .......... .......... .......... .......... Output YES Input XXOXX..... OO.O...... .......... .......... .......... .......... .......... .......... .......... .......... Output NO
import sys input = sys.stdin.readline g = [list(input().strip()) for _ in range(10)] ans = 0 for i in range(10): for j in range(10): if g[i][j] != ".": continue g[i][j] = "X" for p in range(10): for q in range(10): if p + 4 < 10: cnt = 0 for r in range(5): if g[p + r][q] == "X": cnt += 1 if cnt == 5: ans = 1 if q + 4 < 10: cnt = 0 for r in range(5): if g[p][q + r] == "X": cnt += 1 if cnt == 5: ans = 1 if p + 4 < 10 and q + 4 < 10: cnt = 0 for r in range(5): if g[p + r][q + r] == "X": cnt += 1 if cnt == 5: ans = 1 cnt = 0 for r in range(5): if g[p + 4 - r][q + r] == "X": cnt += 1 if cnt == 5: ans = 1 g[i][j] = "." print("YES" if ans else "NO")
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR STRING ASSIGN VAR VAR VAR STRING FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR BIN_OP VAR VAR VAR STRING VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR BIN_OP VAR VAR STRING VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR BIN_OP VAR VAR BIN_OP VAR VAR STRING VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR BIN_OP BIN_OP VAR NUMBER VAR BIN_OP VAR VAR STRING VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR STRING EXPR FUNC_CALL VAR VAR STRING STRING
Alice and Bob play 5-in-a-row game. They have a playing field of size 10 Γ— 10. In turns they put either crosses or noughts, one at a time. Alice puts crosses and Bob puts noughts. In current match they have made some turns and now it's Alice's turn. She wonders if she can put cross in such empty cell that she wins immediately. Alice wins if some crosses in the field form line of length not smaller than 5. This line can be horizontal, vertical and diagonal. -----Input----- You are given matrix 10 Γ— 10 (10 lines of 10 characters each) with capital Latin letters 'X' being a cross, letters 'O' being a nought and '.' being an empty cell. The number of 'X' cells is equal to the number of 'O' cells and there is at least one of each type. There is at least one empty cell. It is guaranteed that in the current arrangement nobody has still won. -----Output----- Print 'YES' if it's possible for Alice to win in one turn by putting cross in some empty cell. Otherwise print 'NO'. -----Examples----- Input XX.XX..... .....OOOO. .......... .......... .......... .......... .......... .......... .......... .......... Output YES Input XXOXX..... OO.O...... .......... .......... .......... .......... .......... .......... .......... .......... Output NO
a = [(0) for i in range(10)] for i in range(10): a[i] = input() b = [[(0) for i in range(10)] for i in range(10)] f = False for x1 in range(10): for y1 in range(10): for i in range(10): for j in range(10): b[i][j] = a[i][j] if b[x1][y1] == ".": b[x1][y1] = "X" can = False for i in range(10): for j in range(10): if ( j < 6 and b[i][j] == "X" and b[i][j + 1] == "X" and b[i][j + 2] == "X" and b[i][j + 3] == "X" and b[i][j + 4] == "X" ): can = True if ( i < 6 and b[i][j] == "X" and b[i + 1][j] == "X" and b[i + 2][j] == "X" and b[i + 3][j] == "X" and b[i + 4][j] == "X" ): can = True if ( i < 6 and j < 6 and b[i][j] == "X" and b[i + 1][j + 1] == "X" and b[i + 2][j + 2] == "X" and b[i + 3][j + 3] == "X" and b[i + 4][j + 4] == "X" ): can = True if ( i < 6 and j > 3 and b[i][j] == "X" and b[i + 1][j - 1] == "X" and b[i + 2][j - 2] == "X" and b[i + 3][j - 3] == "X" and b[i + 4][j - 4] == "X" ): can = True if can == True: f = True if f: print("YES") else: print("NO")
ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR IF VAR VAR VAR STRING ASSIGN VAR VAR VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR VAR VAR STRING VAR VAR BIN_OP VAR NUMBER STRING VAR VAR BIN_OP VAR NUMBER STRING VAR VAR BIN_OP VAR NUMBER STRING VAR VAR BIN_OP VAR NUMBER STRING ASSIGN VAR NUMBER IF VAR NUMBER VAR VAR VAR STRING VAR BIN_OP VAR NUMBER VAR STRING VAR BIN_OP VAR NUMBER VAR STRING VAR BIN_OP VAR NUMBER VAR STRING VAR BIN_OP VAR NUMBER VAR STRING ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER VAR VAR VAR STRING VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER STRING ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER VAR VAR VAR STRING VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER STRING ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Alice and Bob play 5-in-a-row game. They have a playing field of size 10 Γ— 10. In turns they put either crosses or noughts, one at a time. Alice puts crosses and Bob puts noughts. In current match they have made some turns and now it's Alice's turn. She wonders if she can put cross in such empty cell that she wins immediately. Alice wins if some crosses in the field form line of length not smaller than 5. This line can be horizontal, vertical and diagonal. -----Input----- You are given matrix 10 Γ— 10 (10 lines of 10 characters each) with capital Latin letters 'X' being a cross, letters 'O' being a nought and '.' being an empty cell. The number of 'X' cells is equal to the number of 'O' cells and there is at least one of each type. There is at least one empty cell. It is guaranteed that in the current arrangement nobody has still won. -----Output----- Print 'YES' if it's possible for Alice to win in one turn by putting cross in some empty cell. Otherwise print 'NO'. -----Examples----- Input XX.XX..... .....OOOO. .......... .......... .......... .......... .......... .......... .......... .......... Output YES Input XXOXX..... OO.O...... .......... .......... .......... .......... .......... .......... .......... .......... Output NO
matrix = [] for i in range(10): matrix.append(input()) def check_horizontal(matrix, x, y): misses = 0 for dy in range(5): if matrix[x][y + dy] == "O": return False if matrix[x][y + dy] == ".": misses += 1 return misses == 1 def check_diagonal(matrix, x, y): misses = 0 for dx in range(5): if matrix[x + dx][y + dx] == "O": return False if matrix[x + dx][y + dx] == ".": misses += 1 return misses == 1 def check_diagonal_inverse(matrix, x, y): misses = 0 for dx in range(5): if matrix[x + dx][y - dx] == "O": return False if matrix[x + dx][y - dx] == ".": misses += 1 return misses == 1 def check_vertical(matrix, x, y): misses = 0 for dx in range(5): if matrix[x + dx][y] == "O": return False if matrix[x + dx][y] == ".": misses += 1 return misses == 1 for i in range(10): for j in range(6): if check_horizontal(matrix, i, j) or check_vertical(matrix, j, i): print("YES") exit(0) for i in range(6): for j in range(6): if check_diagonal(matrix, i, j) or check_diagonal_inverse(matrix, i, 4 + j): print("YES") exit(0) print("NO")
ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR BIN_OP VAR VAR STRING RETURN NUMBER IF VAR VAR BIN_OP VAR VAR STRING VAR NUMBER RETURN VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR BIN_OP VAR VAR BIN_OP VAR VAR STRING RETURN NUMBER IF VAR BIN_OP VAR VAR BIN_OP VAR VAR STRING VAR NUMBER RETURN VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR BIN_OP VAR VAR BIN_OP VAR VAR STRING RETURN NUMBER IF VAR BIN_OP VAR VAR BIN_OP VAR VAR STRING VAR NUMBER RETURN VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR BIN_OP VAR VAR VAR STRING RETURN NUMBER IF VAR BIN_OP VAR VAR VAR STRING VAR NUMBER RETURN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR STRING
Alice and Bob play 5-in-a-row game. They have a playing field of size 10 Γ— 10. In turns they put either crosses or noughts, one at a time. Alice puts crosses and Bob puts noughts. In current match they have made some turns and now it's Alice's turn. She wonders if she can put cross in such empty cell that she wins immediately. Alice wins if some crosses in the field form line of length not smaller than 5. This line can be horizontal, vertical and diagonal. -----Input----- You are given matrix 10 Γ— 10 (10 lines of 10 characters each) with capital Latin letters 'X' being a cross, letters 'O' being a nought and '.' being an empty cell. The number of 'X' cells is equal to the number of 'O' cells and there is at least one of each type. There is at least one empty cell. It is guaranteed that in the current arrangement nobody has still won. -----Output----- Print 'YES' if it's possible for Alice to win in one turn by putting cross in some empty cell. Otherwise print 'NO'. -----Examples----- Input XX.XX..... .....OOOO. .......... .......... .......... .......... .......... .......... .......... .......... Output YES Input XXOXX..... OO.O...... .......... .......... .......... .......... .......... .......... .......... .......... Output NO
score = {"X": 1, "O": -1, ".": 0} def works(g, x, y): if x + 5 <= 10: cur = 0 for d in range(5): cur += score[g[x + d][y]] if cur >= 4: return True if y + 5 <= 10: cur = sum(score[g[x][y + d]] for d in range(5)) if cur >= 4: return True if x + 5 <= 10 and y + 5 <= 10: cur = sum(score[g[x + d][y + d]] for d in range(5)) if cur >= 4: return True if x - 5 >= -1 and y + 5 <= 10: cur = sum(score[g[x - d][y + d]] for d in range(5)) if cur >= 4: return True return False grid = [] for _ in range(10): grid.append(input()) o = False for i in range(10): for j in range(10): if works(grid, i, j): o = True print("YES" if o else "NO")
ASSIGN VAR DICT STRING STRING STRING NUMBER NUMBER NUMBER FUNC_DEF IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR BIN_OP VAR VAR VAR IF VAR NUMBER RETURN NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR VAR VAR FUNC_CALL VAR NUMBER IF VAR NUMBER RETURN NUMBER IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR FUNC_CALL VAR NUMBER IF VAR NUMBER RETURN NUMBER IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR FUNC_CALL VAR NUMBER IF VAR NUMBER RETURN NUMBER RETURN NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR STRING STRING
Alice and Bob play 5-in-a-row game. They have a playing field of size 10 Γ— 10. In turns they put either crosses or noughts, one at a time. Alice puts crosses and Bob puts noughts. In current match they have made some turns and now it's Alice's turn. She wonders if she can put cross in such empty cell that she wins immediately. Alice wins if some crosses in the field form line of length not smaller than 5. This line can be horizontal, vertical and diagonal. -----Input----- You are given matrix 10 Γ— 10 (10 lines of 10 characters each) with capital Latin letters 'X' being a cross, letters 'O' being a nought and '.' being an empty cell. The number of 'X' cells is equal to the number of 'O' cells and there is at least one of each type. There is at least one empty cell. It is guaranteed that in the current arrangement nobody has still won. -----Output----- Print 'YES' if it's possible for Alice to win in one turn by putting cross in some empty cell. Otherwise print 'NO'. -----Examples----- Input XX.XX..... .....OOOO. .......... .......... .......... .......... .......... .......... .......... .......... Output YES Input XXOXX..... OO.O...... .......... .......... .......... .......... .......... .......... .......... .......... Output NO
def list_input(): return list(map(int, input().split())) n = 10 a = list() for i in range(10): a.append(list(input())) dr = [-1, -1, 0, 1, 1, 1, 0, -1] dc = [0, 1, 1, 1, 0, -1, -1, -1] for i in range(10): for j in range(10): x = a[i][j] if x != ".": continue a[i][j] = "X" for ii in range(10): for jj in range(10): for k in range(8): r = ii + 4 * dr[k] c = jj + 4 * dc[k] if not (0 <= r and r < 10 and 0 <= c and c < 10): continue ok = True for l in range(5): if a[ii + dr[k] * l][jj + dc[k] * l] != "X": ok = False break if ok: print("YES") exit(0) a[i][j] = x print("NO")
FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR VAR IF VAR STRING ASSIGN VAR VAR VAR STRING FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR VAR IF NUMBER VAR VAR NUMBER NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR BIN_OP VAR BIN_OP VAR VAR VAR BIN_OP VAR BIN_OP VAR VAR VAR STRING ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING
Alice and Bob play 5-in-a-row game. They have a playing field of size 10 Γ— 10. In turns they put either crosses or noughts, one at a time. Alice puts crosses and Bob puts noughts. In current match they have made some turns and now it's Alice's turn. She wonders if she can put cross in such empty cell that she wins immediately. Alice wins if some crosses in the field form line of length not smaller than 5. This line can be horizontal, vertical and diagonal. -----Input----- You are given matrix 10 Γ— 10 (10 lines of 10 characters each) with capital Latin letters 'X' being a cross, letters 'O' being a nought and '.' being an empty cell. The number of 'X' cells is equal to the number of 'O' cells and there is at least one of each type. There is at least one empty cell. It is guaranteed that in the current arrangement nobody has still won. -----Output----- Print 'YES' if it's possible for Alice to win in one turn by putting cross in some empty cell. Otherwise print 'NO'. -----Examples----- Input XX.XX..... .....OOOO. .......... .......... .......... .......... .......... .......... .......... .......... Output YES Input XXOXX..... OO.O...... .......... .......... .......... .......... .......... .......... .......... .......... Output NO
def is_in_row(field): for s in field: for i in range(len(s) - 4): if s[i : i + 5].count("X") == 4 and s[i : i + 5].count(".") == 1: print("YES") return True return False def is_in_col(field): for s in ["".join(x) for x in zip(*field)]: for i in range(len(s) - 4): if s[i : i + 5].count("X") == 4 and s[i : i + 5].count(".") == 1: print("YES") return True return False def is_in_diag(field): shift = [] for i in range(len(field)): shift.append(field[i][i:]) shift[-1] += "O" * (10 - len(shift[-1])) for s in ["".join(x) for x in zip(*shift)]: for i in range(len(s) - 4): if s[i : i + 5].count("X") == 4 and s[i : i + 5].count(".") == 1: print("YES") return True shift = [] for i in range(len(field)): shift.append(field[i][:i][::-1]) shift[-1] += "O" * (10 - len(shift[-1])) for s in ["".join(x) for x in zip(*shift)]: for i in range(len(s) - 4): if s[i : i + 5].count("X") == 4 and s[i : i + 5].count(".") == 1: print("YES") return True return False field = [input() for _ in range(10)] if is_in_row(field): return if is_in_col(field): return if is_in_diag(field): return if is_in_diag(list([x[::-1] for x in field])): return print("NO")
FUNC_DEF FOR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR BIN_OP VAR NUMBER STRING NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER STRING NUMBER EXPR FUNC_CALL VAR STRING RETURN NUMBER RETURN NUMBER FUNC_DEF FOR VAR FUNC_CALL STRING VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR BIN_OP VAR NUMBER STRING NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER STRING NUMBER EXPR FUNC_CALL VAR STRING RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR NUMBER BIN_OP STRING BIN_OP NUMBER FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL STRING VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR BIN_OP VAR NUMBER STRING NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER STRING NUMBER EXPR FUNC_CALL VAR STRING RETURN NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER VAR NUMBER BIN_OP STRING BIN_OP NUMBER FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL STRING VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR BIN_OP VAR NUMBER STRING NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER STRING NUMBER EXPR FUNC_CALL VAR STRING RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR VAR RETURN IF FUNC_CALL VAR VAR RETURN IF FUNC_CALL VAR VAR RETURN IF FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR VAR RETURN EXPR FUNC_CALL VAR STRING
Alice and Bob play 5-in-a-row game. They have a playing field of size 10 Γ— 10. In turns they put either crosses or noughts, one at a time. Alice puts crosses and Bob puts noughts. In current match they have made some turns and now it's Alice's turn. She wonders if she can put cross in such empty cell that she wins immediately. Alice wins if some crosses in the field form line of length not smaller than 5. This line can be horizontal, vertical and diagonal. -----Input----- You are given matrix 10 Γ— 10 (10 lines of 10 characters each) with capital Latin letters 'X' being a cross, letters 'O' being a nought and '.' being an empty cell. The number of 'X' cells is equal to the number of 'O' cells and there is at least one of each type. There is at least one empty cell. It is guaranteed that in the current arrangement nobody has still won. -----Output----- Print 'YES' if it's possible for Alice to win in one turn by putting cross in some empty cell. Otherwise print 'NO'. -----Examples----- Input XX.XX..... .....OOOO. .......... .......... .......... .......... .......... .......... .......... .......... Output YES Input XXOXX..... OO.O...... .......... .......... .......... .......... .......... .......... .......... .......... Output NO
def check(a, b): if m[a][b] != ".": return False else: cnt = 0 p = a + 1 while p < 10 and m[p][b] == "X": p += 1 cnt += 1 p = a - 1 while p >= 0 and m[p][b] == "X": p -= 1 cnt += 1 if cnt >= 4: return True cnt = 0 p = b + 1 while p < 10 and m[a][p] == "X": p += 1 cnt += 1 p = b - 1 while p >= 0 and m[a][p] == "X": p -= 1 cnt += 1 if cnt >= 4: return True cnt = 0 p = 1 while a + p < 10 and b + p < 10 and m[a + p][b + p] == "X": p += 1 cnt += 1 p = -1 while a + p >= 0 and b + p >= 0 and m[a + p][b + p] == "X": p -= 1 cnt += 1 if cnt >= 4: return True cnt = 0 p = 1 while a + p < 10 and b - p >= 0 and m[a + p][b - p] == "X": p += 1 cnt += 1 p = -1 while a + p >= 0 and b - p < 10 and m[a + p][b - p] == "X": p -= 1 cnt += 1 if cnt >= 4: return True return False m = [] for i in range(10): m.append(input()) F = False for i in range(10): for j in range(10): if check(i, j): F = True if F: print("YES") else: print("NO")
FUNC_DEF IF VAR VAR VAR STRING RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR VAR VAR STRING VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR VAR VAR STRING VAR NUMBER VAR NUMBER IF VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR VAR VAR STRING VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR VAR VAR STRING VAR NUMBER VAR NUMBER IF VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR BIN_OP VAR VAR STRING VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR BIN_OP VAR VAR STRING VAR NUMBER VAR NUMBER IF VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR BIN_OP VAR VAR STRING VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR BIN_OP VAR VAR STRING VAR NUMBER VAR NUMBER IF VAR NUMBER RETURN NUMBER RETURN NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Alice and Bob play 5-in-a-row game. They have a playing field of size 10 Γ— 10. In turns they put either crosses or noughts, one at a time. Alice puts crosses and Bob puts noughts. In current match they have made some turns and now it's Alice's turn. She wonders if she can put cross in such empty cell that she wins immediately. Alice wins if some crosses in the field form line of length not smaller than 5. This line can be horizontal, vertical and diagonal. -----Input----- You are given matrix 10 Γ— 10 (10 lines of 10 characters each) with capital Latin letters 'X' being a cross, letters 'O' being a nought and '.' being an empty cell. The number of 'X' cells is equal to the number of 'O' cells and there is at least one of each type. There is at least one empty cell. It is guaranteed that in the current arrangement nobody has still won. -----Output----- Print 'YES' if it's possible for Alice to win in one turn by putting cross in some empty cell. Otherwise print 'NO'. -----Examples----- Input XX.XX..... .....OOOO. .......... .......... .......... .......... .......... .......... .......... .......... Output YES Input XXOXX..... OO.O...... .......... .......... .......... .......... .......... .......... .......... .......... Output NO
def checkhor(x, y): c = 0 cy = y + 1 while cy < n and grid[x][cy] == "X": cy += 1 c += 1 if c >= 4: return True cy = y - 1 while cy >= 0 and grid[x][cy] == "X": cy -= 1 c += 1 if c >= 4: return True else: return False def checkver(x, y): c = 0 cx = x + 1 while cx < n and grid[cx][y] == "X": cx += 1 c += 1 if c >= 4: return True cx = x - 1 while cx >= 0 and grid[cx][y] == "X": cx -= 1 c += 1 if c >= 4: return True else: return False def checkdiag(x, y): c = 0 cx = x + 1 cy = y + 1 while cx < n and cy < n and grid[cx][cy] == "X": cx += 1 cy += 1 c += 1 if c >= 4: return True cx = x - 1 cy = y - 1 while cx >= 0 and cy >= 0 and grid[cx][cy] == "X": cx -= 1 cy -= 1 c += 1 if c >= 4: return True c = 0 cx = x + 1 cy = y - 1 while cx < n and cy >= 0 and grid[cx][cy] == "X": cx += 1 cy -= 1 c += 1 if c >= 4: return True cx = x - 1 cy = y + 1 while cx >= 0 and cy < n and grid[cx][cy] == "X": cx -= 1 cy += 1 c += 1 if c >= 4: return True else: return False n = 10 grid = [] for i in range(n): grid.append(list(input())) ans = "NO" for i in range(n): for j in range(n): if grid[i][j] == ".": if checkhor(i, j) or checkver(i, j) or checkdiag(i, j): ans = "YES" break if ans == "YES": break print(ans)
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR VAR VAR VAR STRING VAR NUMBER VAR NUMBER IF VAR NUMBER RETURN NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR VAR VAR STRING VAR NUMBER VAR NUMBER IF VAR NUMBER RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR VAR VAR VAR STRING VAR NUMBER VAR NUMBER IF VAR NUMBER RETURN NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR VAR VAR STRING VAR NUMBER VAR NUMBER IF VAR NUMBER RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR VAR VAR VAR VAR VAR STRING VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER RETURN NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR NUMBER VAR VAR VAR STRING VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR VAR NUMBER VAR VAR VAR STRING VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER RETURN NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR VAR VAR VAR VAR STRING VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER RETURN NUMBER RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING IF FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR STRING IF VAR STRING EXPR FUNC_CALL VAR VAR
Alice and Bob play 5-in-a-row game. They have a playing field of size 10 Γ— 10. In turns they put either crosses or noughts, one at a time. Alice puts crosses and Bob puts noughts. In current match they have made some turns and now it's Alice's turn. She wonders if she can put cross in such empty cell that she wins immediately. Alice wins if some crosses in the field form line of length not smaller than 5. This line can be horizontal, vertical and diagonal. -----Input----- You are given matrix 10 Γ— 10 (10 lines of 10 characters each) with capital Latin letters 'X' being a cross, letters 'O' being a nought and '.' being an empty cell. The number of 'X' cells is equal to the number of 'O' cells and there is at least one of each type. There is at least one empty cell. It is guaranteed that in the current arrangement nobody has still won. -----Output----- Print 'YES' if it's possible for Alice to win in one turn by putting cross in some empty cell. Otherwise print 'NO'. -----Examples----- Input XX.XX..... .....OOOO. .......... .......... .......... .......... .......... .......... .......... .......... Output YES Input XXOXX..... OO.O...... .......... .......... .......... .......... .......... .......... .......... .......... Output NO
s = [] f = False for i in range(10): s.append(list(input())) for i in range(6): for j in range(6): a = [s[i][j], s[i][j + 1], s[i][j + 2], s[i][j + 3], s[i][j + 4]] b = [ s[i][j], s[i + 1][j + 1], s[i + 2][j + 2], s[i + 3][j + 3], s[i + 4][j + 4], ] c = [s[i][j], s[i + 1][j], s[i + 2][j], s[i + 3][j], s[i + 4][j]] d = [ s[i + 4][j], s[i + 4][j + 1], s[i + 4][j + 2], s[i + 4][j + 3], s[i + 4][j + 4], ] e = [ s[i + 4][j], s[i + 3][j + 1], s[i + 2][j + 2], s[i + 1][j + 3], s[i][j + 4], ] g = [ s[i][j + 4], s[i + 1][j + 4], s[i + 2][j + 4], s[i + 3][j + 4], s[i + 4][j + 4], ] if ( a.count("X") == 4 and a.count(".") == 1 or b.count("X") == 4 and b.count(".") == 1 or c.count("X") == 4 and c.count(".") == 1 or d.count("X") == 4 and d.count(".") == 1 or e.count("X") == 4 and e.count(".") == 1 or g.count("X") == 4 and g.count(".") == 1 ): f = True break if f: print("YES") else: print("NO")
ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR LIST VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER ASSIGN VAR LIST VAR VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR LIST VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR LIST VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR LIST VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER ASSIGN VAR LIST VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF FUNC_CALL VAR STRING NUMBER FUNC_CALL VAR STRING NUMBER FUNC_CALL VAR STRING NUMBER FUNC_CALL VAR STRING NUMBER FUNC_CALL VAR STRING NUMBER FUNC_CALL VAR STRING NUMBER FUNC_CALL VAR STRING NUMBER FUNC_CALL VAR STRING NUMBER FUNC_CALL VAR STRING NUMBER FUNC_CALL VAR STRING NUMBER FUNC_CALL VAR STRING NUMBER FUNC_CALL VAR STRING NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Alice and Bob play 5-in-a-row game. They have a playing field of size 10 Γ— 10. In turns they put either crosses or noughts, one at a time. Alice puts crosses and Bob puts noughts. In current match they have made some turns and now it's Alice's turn. She wonders if she can put cross in such empty cell that she wins immediately. Alice wins if some crosses in the field form line of length not smaller than 5. This line can be horizontal, vertical and diagonal. -----Input----- You are given matrix 10 Γ— 10 (10 lines of 10 characters each) with capital Latin letters 'X' being a cross, letters 'O' being a nought and '.' being an empty cell. The number of 'X' cells is equal to the number of 'O' cells and there is at least one of each type. There is at least one empty cell. It is guaranteed that in the current arrangement nobody has still won. -----Output----- Print 'YES' if it's possible for Alice to win in one turn by putting cross in some empty cell. Otherwise print 'NO'. -----Examples----- Input XX.XX..... .....OOOO. .......... .......... .......... .......... .......... .......... .......... .......... Output YES Input XXOXX..... OO.O...... .......... .......... .......... .......... .......... .......... .......... .......... Output NO
l = [] s = [] d = [] w = "" r = 0 for i in range(0, 10): l.append(str(input())) for i in l: for j in range(0, 6): if i[j : j + 5].count("X") == 4 and i[j : j + 5].count(".") == 1: r = 1 break if r != 1: for i in range(0, 10): for j in l: w = w + j[i] s.append(w) w = "" for i in s: for j in range(0, 6): if i[j : j + 5].count("X") == 4 and i[j : j + 5].count(".") == 1: r = 1 break if r != 1: for i in range(0, 6): s = "" for j in range(0, 6): s = ( l[i][j] + l[i + 1][j + 1] + l[i + 2][j + 2] + l[i + 3][j + 3] + l[i + 4][j + 4] ) d.append(s) s = "" s = ( l[i][j + 4] + l[i + 1][j + 3] + l[i + 2][j + 2] + l[i + 3][j + 1] + l[i + 4][j] ) d.append(s) for i in d: if i.count("X") == 4 and i.count(".") == 1: r = 1 break if r == 1: print("YES") else: print("NO")
ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER IF FUNC_CALL VAR VAR BIN_OP VAR NUMBER STRING NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER STRING NUMBER ASSIGN VAR NUMBER IF VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR STRING FOR VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER IF FUNC_CALL VAR VAR BIN_OP VAR NUMBER STRING NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER STRING NUMBER ASSIGN VAR NUMBER IF VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR STRING ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR FOR VAR VAR IF FUNC_CALL VAR STRING NUMBER FUNC_CALL VAR STRING NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Alice and Bob play 5-in-a-row game. They have a playing field of size 10 Γ— 10. In turns they put either crosses or noughts, one at a time. Alice puts crosses and Bob puts noughts. In current match they have made some turns and now it's Alice's turn. She wonders if she can put cross in such empty cell that she wins immediately. Alice wins if some crosses in the field form line of length not smaller than 5. This line can be horizontal, vertical and diagonal. -----Input----- You are given matrix 10 Γ— 10 (10 lines of 10 characters each) with capital Latin letters 'X' being a cross, letters 'O' being a nought and '.' being an empty cell. The number of 'X' cells is equal to the number of 'O' cells and there is at least one of each type. There is at least one empty cell. It is guaranteed that in the current arrangement nobody has still won. -----Output----- Print 'YES' if it's possible for Alice to win in one turn by putting cross in some empty cell. Otherwise print 'NO'. -----Examples----- Input XX.XX..... .....OOOO. .......... .......... .......... .......... .......... .......... .......... .......... Output YES Input XXOXX..... OO.O...... .......... .......... .......... .......... .......... .......... .......... .......... Output NO
ar = [] for i in range(10): ar.append(input()) ans = False for i in range(10): for j in range(10): if ar[i][j] == "X": x = 1 hl = False for k in range(1, 5): if i + k == 10: break if ar[i + k][j] == "X": x += 1 elif ar[i + k][j] == "O": break elif hl: break else: hl = True if x == 4: if hl: ans = True elif ( i - 1 >= 0 and ar[i - 1][j] == "." or i + k + 1 < 10 and ar[i + k + 1][j] == "." ): ans = True break if ans: break x = 1 hl = False for k in range(1, 5): if i + k == 10 or j + k == 10: break if ar[i + k][j + k] == "X": x += 1 elif ar[i + k][j + k] == "O": break elif hl: break else: hl = True if x == 4: if hl: ans = True elif ( i - 1 >= 0 and j - 1 >= 0 and ar[i - 1][j - 1] == "." or i + k + 1 < 10 and j + k + 1 < 10 and ar[i + k + 1][j + k + 1] == "." ): ans = True break if ans: break x = 1 hl = False for k in range(1, 5): if j + k == 10: break if ar[i][j + k] == "X": x += 1 elif ar[i][j + k] == "O": break elif hl: break else: hl = True if x == 4: if hl: ans = True elif ( j - 1 >= 0 and ar[i][j - 1] == "." or j + k + 1 < 10 and ar[i][j + k + 1] == "." ): ans = True break if ans: break x = 1 hl = False for k in range(1, 5): if i - k == -1 or j + k == 10: break if ar[i - k][j + k] == "X": x += 1 elif ar[i - k][j + k] == "O": break elif hl: break else: hl = True if x == 4: if hl: ans = True elif ( i + 1 < 10 and j - 1 >= 0 and ar[i + 1][j - 1] == "." or i - k - 1 >= 0 and j + k + 1 < 10 and ar[i - k - 1][j + k + 1] == "." ): ans = True break if ans: break if ans: break if ans: print("YES") else: print("NO")
ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR VAR VAR STRING VAR NUMBER IF VAR BIN_OP VAR VAR VAR STRING IF VAR ASSIGN VAR NUMBER IF VAR NUMBER IF VAR ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER VAR STRING BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER VAR STRING ASSIGN VAR NUMBER IF VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR VAR BIN_OP VAR VAR STRING VAR NUMBER IF VAR BIN_OP VAR VAR BIN_OP VAR VAR STRING IF VAR ASSIGN VAR NUMBER IF VAR NUMBER IF VAR ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER STRING BIN_OP BIN_OP VAR VAR NUMBER NUMBER BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER STRING ASSIGN VAR NUMBER IF VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF BIN_OP VAR VAR NUMBER IF VAR VAR BIN_OP VAR VAR STRING VAR NUMBER IF VAR VAR BIN_OP VAR VAR STRING IF VAR ASSIGN VAR NUMBER IF VAR NUMBER IF VAR ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR VAR BIN_OP VAR NUMBER STRING BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR VAR BIN_OP BIN_OP VAR VAR NUMBER STRING ASSIGN VAR NUMBER IF VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR VAR BIN_OP VAR VAR STRING VAR NUMBER IF VAR BIN_OP VAR VAR BIN_OP VAR VAR STRING IF VAR ASSIGN VAR NUMBER IF VAR NUMBER IF VAR ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER STRING BIN_OP BIN_OP VAR VAR NUMBER NUMBER BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER STRING ASSIGN VAR NUMBER IF VAR IF VAR IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Alice and Bob play 5-in-a-row game. They have a playing field of size 10 Γ— 10. In turns they put either crosses or noughts, one at a time. Alice puts crosses and Bob puts noughts. In current match they have made some turns and now it's Alice's turn. She wonders if she can put cross in such empty cell that she wins immediately. Alice wins if some crosses in the field form line of length not smaller than 5. This line can be horizontal, vertical and diagonal. -----Input----- You are given matrix 10 Γ— 10 (10 lines of 10 characters each) with capital Latin letters 'X' being a cross, letters 'O' being a nought and '.' being an empty cell. The number of 'X' cells is equal to the number of 'O' cells and there is at least one of each type. There is at least one empty cell. It is guaranteed that in the current arrangement nobody has still won. -----Output----- Print 'YES' if it's possible for Alice to win in one turn by putting cross in some empty cell. Otherwise print 'NO'. -----Examples----- Input XX.XX..... .....OOOO. .......... .......... .......... .......... .......... .......... .......... .......... Output YES Input XXOXX..... OO.O...... .......... .......... .......... .......... .......... .......... .......... .......... Output NO
import sys l = ["" for i in range(10)] for i in range(10): l[i] = input() for i in range(10): for j in range(10): if j - 2 >= 0 and j + 2 < 10: s = l[i][j - 2 : j + 3] if s.count("X") == 4 and s.count("O") == 0: print("YES") sys.exit() if i - 2 >= 0 and i + 2 < 10: s = l[i - 2][j] + l[i - 1][j] + l[i][j] + l[i + 1][j] + l[i + 2][j] if s.count("X") == 4 and s.count("O") == 0: print("YES") sys.exit() if j - 2 >= 0 and j + 2 < 10 and i - 2 >= 0 and i + 2 < 10: s = ( l[i - 2][j - 2] + l[i - 1][j - 1] + l[i][j] + l[i + 1][j + 1] + l[i + 2][j + 2] ) if s.count("X") == 4 and s.count("O") == 0: print("YES") sys.exit() s = ( l[i - 2][j + 2] + l[i - 1][j + 1] + l[i][j] + l[i + 1][j - 1] + l[i + 2][j - 2] ) if s.count("X") == 4 and s.count("O") == 0: print("YES") sys.exit() print("NO")
IMPORT ASSIGN VAR STRING VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF FUNC_CALL VAR STRING NUMBER FUNC_CALL VAR STRING NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR IF FUNC_CALL VAR STRING NUMBER FUNC_CALL VAR STRING NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF FUNC_CALL VAR STRING NUMBER FUNC_CALL VAR STRING NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF FUNC_CALL VAR STRING NUMBER FUNC_CALL VAR STRING NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR STRING
Alice and Bob play 5-in-a-row game. They have a playing field of size 10 Γ— 10. In turns they put either crosses or noughts, one at a time. Alice puts crosses and Bob puts noughts. In current match they have made some turns and now it's Alice's turn. She wonders if she can put cross in such empty cell that she wins immediately. Alice wins if some crosses in the field form line of length not smaller than 5. This line can be horizontal, vertical and diagonal. -----Input----- You are given matrix 10 Γ— 10 (10 lines of 10 characters each) with capital Latin letters 'X' being a cross, letters 'O' being a nought and '.' being an empty cell. The number of 'X' cells is equal to the number of 'O' cells and there is at least one of each type. There is at least one empty cell. It is guaranteed that in the current arrangement nobody has still won. -----Output----- Print 'YES' if it's possible for Alice to win in one turn by putting cross in some empty cell. Otherwise print 'NO'. -----Examples----- Input XX.XX..... .....OOOO. .......... .......... .......... .......... .......... .......... .......... .......... Output YES Input XXOXX..... OO.O...... .......... .......... .......... .......... .......... .......... .......... .......... Output NO
a = [] for i in range(10): a.append(input()) for i in range(6): for j in range(6): k, z = 0, 0 for x in range(5): if a[i + x][j + x] == "X": k += 1 elif a[i + x][j + x] == ".": z += 1 if k == 5 or k == 4 and z == 1: print("YES") exit(0) k, z = 0, 0 for x in range(5): if a[i + x][j + 4 - x] == "X": k += 1 elif a[i + x][j + 4 - x] == ".": z += 1 if k == 5 or k == 4 and z == 1: print("YES") exit(0) for i in range(10): for j in range(6): k, z = 0, 0 for x in range(5): if a[i][j + x] == "X": k += 1 elif a[i][j + x] == ".": z += 1 if k == 5 or k == 4 and z == 1: print("YES") exit(0) for i in range(6): for j in range(10): k, z = 0, 0 for x in range(5): if a[i + x][j] == "X": k += 1 elif a[i + x][j] == ".": z += 1 if k == 5 or k == 4 and z == 1: print("YES") exit(0) print("NO")
ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR BIN_OP VAR VAR BIN_OP VAR VAR STRING VAR NUMBER IF VAR BIN_OP VAR VAR BIN_OP VAR VAR STRING VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR NUMBER VAR STRING VAR NUMBER IF VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR NUMBER VAR STRING VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR BIN_OP VAR VAR STRING VAR NUMBER IF VAR VAR BIN_OP VAR VAR STRING VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR BIN_OP VAR VAR VAR STRING VAR NUMBER IF VAR BIN_OP VAR VAR VAR STRING VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR STRING
Alice and Bob play 5-in-a-row game. They have a playing field of size 10 Γ— 10. In turns they put either crosses or noughts, one at a time. Alice puts crosses and Bob puts noughts. In current match they have made some turns and now it's Alice's turn. She wonders if she can put cross in such empty cell that she wins immediately. Alice wins if some crosses in the field form line of length not smaller than 5. This line can be horizontal, vertical and diagonal. -----Input----- You are given matrix 10 Γ— 10 (10 lines of 10 characters each) with capital Latin letters 'X' being a cross, letters 'O' being a nought and '.' being an empty cell. The number of 'X' cells is equal to the number of 'O' cells and there is at least one of each type. There is at least one empty cell. It is guaranteed that in the current arrangement nobody has still won. -----Output----- Print 'YES' if it's possible for Alice to win in one turn by putting cross in some empty cell. Otherwise print 'NO'. -----Examples----- Input XX.XX..... .....OOOO. .......... .......... .......... .......... .......... .......... .......... .......... Output YES Input XXOXX..... OO.O...... .......... .......... .......... .......... .......... .......... .......... .......... Output NO
s = [[c for c in input()] for i in range(10)] def win(): for i in range(10): for j in range(10): ok = True for k in range(5): if j + k > 9: ok = False elif s[i][j + k] != "X": ok = False if ok: return True ok = True for k in range(5): if i + k > 9: ok = False elif s[i + k][j] != "X": ok = False if ok: return True ok = True for k in range(5): if j + k > 9 or i + k > 9: ok = False elif s[i + k][j + k] != "X": ok = False if ok: return True ok = True for k in range(5): if i - k < 0 or j + k > 9: ok = False elif s[i - k][j + k] != "X": ok = False if ok: return True return False for i in range(10): for j in range(10): if s[i][j] == ".": s[i][j] = "X" if win(): print("YES") return s[i][j] = "." print("NO")
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR NUMBER FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR BIN_OP VAR VAR STRING ASSIGN VAR NUMBER IF VAR RETURN NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR BIN_OP VAR VAR VAR STRING ASSIGN VAR NUMBER IF VAR RETURN NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR BIN_OP VAR VAR BIN_OP VAR VAR STRING ASSIGN VAR NUMBER IF VAR RETURN NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR BIN_OP VAR VAR BIN_OP VAR VAR STRING ASSIGN VAR NUMBER IF VAR RETURN NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR STRING ASSIGN VAR VAR VAR STRING IF FUNC_CALL VAR EXPR FUNC_CALL VAR STRING RETURN ASSIGN VAR VAR VAR STRING EXPR FUNC_CALL VAR STRING
Alice and Bob play 5-in-a-row game. They have a playing field of size 10 Γ— 10. In turns they put either crosses or noughts, one at a time. Alice puts crosses and Bob puts noughts. In current match they have made some turns and now it's Alice's turn. She wonders if she can put cross in such empty cell that she wins immediately. Alice wins if some crosses in the field form line of length not smaller than 5. This line can be horizontal, vertical and diagonal. -----Input----- You are given matrix 10 Γ— 10 (10 lines of 10 characters each) with capital Latin letters 'X' being a cross, letters 'O' being a nought and '.' being an empty cell. The number of 'X' cells is equal to the number of 'O' cells and there is at least one of each type. There is at least one empty cell. It is guaranteed that in the current arrangement nobody has still won. -----Output----- Print 'YES' if it's possible for Alice to win in one turn by putting cross in some empty cell. Otherwise print 'NO'. -----Examples----- Input XX.XX..... .....OOOO. .......... .......... .......... .......... .......... .......... .......... .......... Output YES Input XXOXX..... OO.O...... .......... .......... .......... .......... .......... .......... .......... .......... Output NO
corr = lambda i, j: 0 <= i < 10 and 0 <= j < 10 def can(b): for i in range(10): for j in range(10): for t in range(4): flag = 1 for k in range(5): ni = i + dx[t] * k nj = j + dy[t] * k if not corr(ni, nj) or b[ni][nj] != "X": flag = 0 break if flag: return 1 return 0 def solve(): b = [list(i) for i in a] for i in range(10): for j in range(10): if b[i][j] == ".": temp = b[i][j] b[i][j] = "X" if can(b): return 1 b[i][j] = temp return 0 dx, dy = [0, 1, 1, -1], [1, 0, 1, 1] a = [input() for i in range(10)] print("YES" if solve() else "NO")
ASSIGN VAR NUMBER VAR NUMBER NUMBER VAR NUMBER FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR VAR IF FUNC_CALL VAR VAR VAR VAR VAR VAR STRING ASSIGN VAR NUMBER IF VAR RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR STRING ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR STRING IF FUNC_CALL VAR VAR RETURN NUMBER ASSIGN VAR VAR VAR VAR RETURN NUMBER ASSIGN VAR VAR LIST NUMBER NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR STRING STRING
Alice and Bob play 5-in-a-row game. They have a playing field of size 10 Γ— 10. In turns they put either crosses or noughts, one at a time. Alice puts crosses and Bob puts noughts. In current match they have made some turns and now it's Alice's turn. She wonders if she can put cross in such empty cell that she wins immediately. Alice wins if some crosses in the field form line of length not smaller than 5. This line can be horizontal, vertical and diagonal. -----Input----- You are given matrix 10 Γ— 10 (10 lines of 10 characters each) with capital Latin letters 'X' being a cross, letters 'O' being a nought and '.' being an empty cell. The number of 'X' cells is equal to the number of 'O' cells and there is at least one of each type. There is at least one empty cell. It is guaranteed that in the current arrangement nobody has still won. -----Output----- Print 'YES' if it's possible for Alice to win in one turn by putting cross in some empty cell. Otherwise print 'NO'. -----Examples----- Input XX.XX..... .....OOOO. .......... .......... .......... .......... .......... .......... .......... .......... Output YES Input XXOXX..... OO.O...... .......... .......... .......... .......... .......... .......... .......... .......... Output NO
def get_rows(grid): return [[c for c in r] for r in grid] def get_cols(grid): return zip(*grid) def get_backward_diagonals(grid): b = [None] * (len(grid) - 1) grid = [(b[i:] + r + b[:i]) for i, r in enumerate(get_rows(grid))] return [[c for c in r if c is not None] for r in get_cols(grid)] def get_forward_diagonals(grid): b = [None] * (len(grid) - 1) grid = [(b[:i] + r + b[i:]) for i, r in enumerate(get_rows(grid))] return [[c for c in r if c is not None] for r in get_cols(grid)] def won(s): for row in s: for i in range(len(row) - 4): substr = row[i : i + 5] if substr.count("X") == 4 and substr.count(".") == 1: return True t = [[s[j][i] for j in range(10)] for i in range(10)] for row in t: for i in range(len(row) - 4): substr = row[i : i + 5] if substr.count("X") == 4 and substr.count(".") == 1: return True for diag in get_backward_diagonals(s): for i in range(len(diag) - 4): substr = diag[i : i + 5] if substr.count("X") == 4 and substr.count(".") == 1: return True for diag in get_forward_diagonals(s): for i in range(len(diag) - 4): substr = diag[i : i + 5] if substr.count("X") == 4 and substr.count(".") == 1: return True s = [list(input()) for _ in range(10)] if won(s): print("YES") else: print("NO")
FUNC_DEF RETURN VAR VAR VAR VAR VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR BIN_OP LIST NONE BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR RETURN VAR VAR VAR VAR NONE VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR BIN_OP LIST NONE BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR RETURN VAR VAR VAR VAR NONE VAR FUNC_CALL VAR VAR FUNC_DEF FOR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR STRING NUMBER FUNC_CALL VAR STRING NUMBER RETURN NUMBER ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR STRING NUMBER FUNC_CALL VAR STRING NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR STRING NUMBER FUNC_CALL VAR STRING NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR STRING NUMBER FUNC_CALL VAR STRING NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Alice and Bob play 5-in-a-row game. They have a playing field of size 10 Γ— 10. In turns they put either crosses or noughts, one at a time. Alice puts crosses and Bob puts noughts. In current match they have made some turns and now it's Alice's turn. She wonders if she can put cross in such empty cell that she wins immediately. Alice wins if some crosses in the field form line of length not smaller than 5. This line can be horizontal, vertical and diagonal. -----Input----- You are given matrix 10 Γ— 10 (10 lines of 10 characters each) with capital Latin letters 'X' being a cross, letters 'O' being a nought and '.' being an empty cell. The number of 'X' cells is equal to the number of 'O' cells and there is at least one of each type. There is at least one empty cell. It is guaranteed that in the current arrangement nobody has still won. -----Output----- Print 'YES' if it's possible for Alice to win in one turn by putting cross in some empty cell. Otherwise print 'NO'. -----Examples----- Input XX.XX..... .....OOOO. .......... .......... .......... .......... .......... .......... .......... .......... Output YES Input XXOXX..... OO.O...... .......... .......... .......... .......... .......... .......... .......... .......... Output NO
import sys field = [] for i in range(10): st = input() field.append(st) def f(): global i, i2, c, j, j2, l for i in range(10): for i2 in range(6): l = field[i][i2 : i2 + 5] if l.count("X") == 4 and l.count(".") == 1: print("YES") sys.exit() for i in range(10): for i2 in range(6): l = ( field[i2][i] + field[i2 + 1][i] + field[i2 + 2][i] + field[i2 + 3][i] + field[i2 + 4][i] ) if l.count("X") == 4 and l.count(".") == 1: print("YES") sys.exit() c = 0 for i in range(4, 10): c += 1 for i2 in range(c): j = i - i2 j2 = 0 + i2 l = ( field[j][j2] + field[j - 1][j2 + 1] + field[j - 2][j2 + 2] + field[j - 3][j2 + 3] + field[j - 4][j2 + 4] ) if l.count("X") == 4 and l.count(".") == 1: print("YES") sys.exit() for i2 in range(1, 6): c -= 1 for i3 in range(c): j = i - i3 j2 = i2 + i3 l = ( field[j][j2] + field[j - 1][j2 + 1] + field[j - 2][j2 + 2] + field[j - 3][j2 + 3] + field[j - 4][j2 + 4] ) if l.count("X") == 4 and l.count(".") == 1: print("YES") sys.exit() c = 0 for i in range(5, -1, -1): c += 1 for i2 in range(c): j = i + i2 j2 = 0 + i2 l = ( field[j][j2] + field[j + 1][j2 + 1] + field[j + 2][j2 + 2] + field[j + 3][j2 + 3] + field[j + 4][j2 + 4] ) if l.count("X") == 4 and l.count(".") == 1: print("YES") sys.exit() for i2 in range(1, 6): c -= 1 for i3 in range(c): j = i + i3 j2 = i2 + i3 l = ( field[j][j2] + field[j + 1][j2 + 1] + field[j + 2][j2 + 2] + field[j + 3][j2 + 3] + field[j + 4][j2 + 4] ) if l.count("X") == 4 and l.count(".") == 1: print("YES") sys.exit() print("NO") f()
IMPORT ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR STRING NUMBER FUNC_CALL VAR STRING NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR IF FUNC_CALL VAR STRING NUMBER FUNC_CALL VAR STRING NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF FUNC_CALL VAR STRING NUMBER FUNC_CALL VAR STRING NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF FUNC_CALL VAR STRING NUMBER FUNC_CALL VAR STRING NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF FUNC_CALL VAR STRING NUMBER FUNC_CALL VAR STRING NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF FUNC_CALL VAR STRING NUMBER FUNC_CALL VAR STRING NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR
Alice and Bob play 5-in-a-row game. They have a playing field of size 10 Γ— 10. In turns they put either crosses or noughts, one at a time. Alice puts crosses and Bob puts noughts. In current match they have made some turns and now it's Alice's turn. She wonders if she can put cross in such empty cell that she wins immediately. Alice wins if some crosses in the field form line of length not smaller than 5. This line can be horizontal, vertical and diagonal. -----Input----- You are given matrix 10 Γ— 10 (10 lines of 10 characters each) with capital Latin letters 'X' being a cross, letters 'O' being a nought and '.' being an empty cell. The number of 'X' cells is equal to the number of 'O' cells and there is at least one of each type. There is at least one empty cell. It is guaranteed that in the current arrangement nobody has still won. -----Output----- Print 'YES' if it's possible for Alice to win in one turn by putting cross in some empty cell. Otherwise print 'NO'. -----Examples----- Input XX.XX..... .....OOOO. .......... .......... .......... .......... .......... .......... .......... .......... Output YES Input XXOXX..... OO.O...... .......... .......... .......... .......... .......... .......... .......... .......... Output NO
a = [""] * 10 for i in range(10): a[i] = input() AliceWins = False for i in range(10 - 4): for j in range(10): count = 0 dot = 0 for k in range(5): if a[i + k][j] == "X": count += 1 elif a[i + k][j] == ".": dot += 1 if count == 4 and dot: AliceWins = True for i in range(10): for j in range(10 - 4): count = 0 dot = 0 for k in range(5): if a[i][j + k] == "X": count += 1 elif a[i][j + k] == ".": dot += 1 if count == 4 and dot: AliceWins = True for i in range(10 - 4): for j in range(10 - 4): count = 0 dot = 0 for k in range(5): if a[i + k][j + k] == "X": count += 1 elif a[i + k][j + k] == ".": dot += 1 if count == 4 and dot: AliceWins = True for i in range(10): a[i] = a[i][::-1] for i in range(10 - 4): for j in range(10 - 4): count = 0 dot = 0 for k in range(5): if a[i + k][j + k] == "X": count += 1 elif a[i + k][j + k] == ".": dot += 1 if count == 4 and dot: AliceWins = True print("YES" if AliceWins else "NO")
ASSIGN VAR BIN_OP LIST STRING NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR BIN_OP VAR VAR VAR STRING VAR NUMBER IF VAR BIN_OP VAR VAR VAR STRING VAR NUMBER IF VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR BIN_OP VAR VAR STRING VAR NUMBER IF VAR VAR BIN_OP VAR VAR STRING VAR NUMBER IF VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR BIN_OP VAR VAR BIN_OP VAR VAR STRING VAR NUMBER IF VAR BIN_OP VAR VAR BIN_OP VAR VAR STRING VAR NUMBER IF VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR BIN_OP VAR VAR BIN_OP VAR VAR STRING VAR NUMBER IF VAR BIN_OP VAR VAR BIN_OP VAR VAR STRING VAR NUMBER IF VAR NUMBER VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR STRING STRING
Alice and Bob play 5-in-a-row game. They have a playing field of size 10 Γ— 10. In turns they put either crosses or noughts, one at a time. Alice puts crosses and Bob puts noughts. In current match they have made some turns and now it's Alice's turn. She wonders if she can put cross in such empty cell that she wins immediately. Alice wins if some crosses in the field form line of length not smaller than 5. This line can be horizontal, vertical and diagonal. -----Input----- You are given matrix 10 Γ— 10 (10 lines of 10 characters each) with capital Latin letters 'X' being a cross, letters 'O' being a nought and '.' being an empty cell. The number of 'X' cells is equal to the number of 'O' cells and there is at least one of each type. There is at least one empty cell. It is guaranteed that in the current arrangement nobody has still won. -----Output----- Print 'YES' if it's possible for Alice to win in one turn by putting cross in some empty cell. Otherwise print 'NO'. -----Examples----- Input XX.XX..... .....OOOO. .......... .......... .......... .......... .......... .......... .......... .......... Output YES Input XXOXX..... OO.O...... .......... .......... .......... .......... .......... .......... .......... .......... Output NO
a = ["$" * 12] for i in range(10): a.append(list("$" + input() + "$")) a.append("$" * 12) flag = False def count(r, c, dr, dc): k = 0 while a[r][c] == "X": r, c = r + dr, c + dc k += 1 return k for r in range(1, 11): for c in range(1, 11): if a[r][c] == ".": h = count(r, c - 1, 0, -1) + count(r, c + 1, 0, 1) v = count(r - 1, c, -1, 0) + count(r + 1, c, 1, 0) u = count(r + 1, c - 1, 1, -1) + count(r - 1, c + 1, -1, 1) d = count(r - 1, c - 1, -1, -1) + count(r + 1, c + 1, 1, 1) if h >= 4 or v >= 4 or u >= 4 or d >= 4: flag = True if flag == True: print("YES") else: print("NO")
ASSIGN VAR LIST BIN_OP STRING NUMBER FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP STRING FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP STRING NUMBER ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER WHILE VAR VAR VAR STRING ASSIGN VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR VAR VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER 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
Alice and Bob play 5-in-a-row game. They have a playing field of size 10 Γ— 10. In turns they put either crosses or noughts, one at a time. Alice puts crosses and Bob puts noughts. In current match they have made some turns and now it's Alice's turn. She wonders if she can put cross in such empty cell that she wins immediately. Alice wins if some crosses in the field form line of length not smaller than 5. This line can be horizontal, vertical and diagonal. -----Input----- You are given matrix 10 Γ— 10 (10 lines of 10 characters each) with capital Latin letters 'X' being a cross, letters 'O' being a nought and '.' being an empty cell. The number of 'X' cells is equal to the number of 'O' cells and there is at least one of each type. There is at least one empty cell. It is guaranteed that in the current arrangement nobody has still won. -----Output----- Print 'YES' if it's possible for Alice to win in one turn by putting cross in some empty cell. Otherwise print 'NO'. -----Examples----- Input XX.XX..... .....OOOO. .......... .......... .......... .......... .......... .......... .......... .......... Output YES Input XXOXX..... OO.O...... .......... .......... .......... .......... .......... .......... .......... .......... Output NO
mat = [] for i in range(10): li = list(input()) mat.append(li) d = [(1, 0), (0, 1), (1, 1), (1, -1)] for i in range(10): for j in range(10): for dx, dy in d: c = 0 t = 0 for k in range(5): row = i + dx * k col = j + dy * k if row < 10 and row >= 0 and col < 10 and col >= 0: if mat[row][col] == "X": c += 1 elif mat[row][col] == ".": t += 1 if c == 4 and t == 1: print("YES") exit() print("NO")
ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR VAR STRING VAR NUMBER IF VAR VAR VAR STRING VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR STRING
Alice and Bob play 5-in-a-row game. They have a playing field of size 10 Γ— 10. In turns they put either crosses or noughts, one at a time. Alice puts crosses and Bob puts noughts. In current match they have made some turns and now it's Alice's turn. She wonders if she can put cross in such empty cell that she wins immediately. Alice wins if some crosses in the field form line of length not smaller than 5. This line can be horizontal, vertical and diagonal. -----Input----- You are given matrix 10 Γ— 10 (10 lines of 10 characters each) with capital Latin letters 'X' being a cross, letters 'O' being a nought and '.' being an empty cell. The number of 'X' cells is equal to the number of 'O' cells and there is at least one of each type. There is at least one empty cell. It is guaranteed that in the current arrangement nobody has still won. -----Output----- Print 'YES' if it's possible for Alice to win in one turn by putting cross in some empty cell. Otherwise print 'NO'. -----Examples----- Input XX.XX..... .....OOOO. .......... .......... .......... .......... .......... .......... .......... .......... Output YES Input XXOXX..... OO.O...... .......... .......... .......... .......... .......... .......... .......... .......... Output NO
t = [([-1] * 12) for i in range(12)] for i in range(1, 11): s = input() for j in range(1, 11): if s[j - 1] == ".": t[i][j] = 0 elif s[j - 1] == "X": t[i][j] = 1 c = False for x in range(1, 11): for y in range(1, 11): if t[x][y] == 0: t[x][y] = 1 for i in range(1, 11): for j in range(1, 11): if t[i][j] == 1: counter = 1 for k in range(1, 5): if i - k > 0 and j + k < 11 and t[i - k][j + k] == 1: counter += 1 if counter == 5: c = True break counter = 1 for k in range(1, 5): if j + k < 11 and t[i][j + k] == 1: counter += 1 if counter == 5: c = True break counter = 1 for k in range(1, 5): if i + k < 11 and t[i + k][j] == 1: counter += 1 if counter == 5: c = True break counter = 1 for k in range(1, 5): if i + k < 11 and j + k < 11 and t[i + k][j + k] == 1: counter += 1 if counter == 5: c = True break t[x][y] = 0 if c: print("YES") else: print("NO")
ASSIGN VAR BIN_OP LIST NUMBER NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR BIN_OP VAR VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF BIN_OP VAR VAR NUMBER VAR VAR BIN_OP VAR VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR BIN_OP VAR VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Alice and Bob play 5-in-a-row game. They have a playing field of size 10 Γ— 10. In turns they put either crosses or noughts, one at a time. Alice puts crosses and Bob puts noughts. In current match they have made some turns and now it's Alice's turn. She wonders if she can put cross in such empty cell that she wins immediately. Alice wins if some crosses in the field form line of length not smaller than 5. This line can be horizontal, vertical and diagonal. -----Input----- You are given matrix 10 Γ— 10 (10 lines of 10 characters each) with capital Latin letters 'X' being a cross, letters 'O' being a nought and '.' being an empty cell. The number of 'X' cells is equal to the number of 'O' cells and there is at least one of each type. There is at least one empty cell. It is guaranteed that in the current arrangement nobody has still won. -----Output----- Print 'YES' if it's possible for Alice to win in one turn by putting cross in some empty cell. Otherwise print 'NO'. -----Examples----- Input XX.XX..... .....OOOO. .......... .......... .......... .......... .......... .......... .......... .......... Output YES Input XXOXX..... OO.O...... .......... .......... .......... .......... .......... .......... .......... .......... Output NO
def is_win(x): if x.count("X") == 4 and x.count(".") == 1: return True else: return False def solve(L): for x in L: for j in range(6): if is_win(x[j : j + 5]): return "YES" LT = [] for i in range(10): s = "" for j in range(10): s += L[j][i] LT.append(s) for x in LT: for j in range(6): if is_win(x[j : j + 5]): return "YES" for i in range(2, 8): for j in range(2, 8): x = ( L[i - 2][j - 2] + L[i - 1][j - 1] + L[i][j] + L[i + 1][j + 1] + L[i + 2][j + 2] ) if is_win(x): return "YES" x = ( L[i - 2][j + 2] + L[i - 1][j + 1] + L[i][j] + L[i + 1][j - 1] + L[i + 2][j - 2] ) if is_win(x): return "YES" return "NO" L = [] for i in range(10): L.append(input()) print(solve(L))
FUNC_DEF IF FUNC_CALL VAR STRING NUMBER FUNC_CALL VAR STRING NUMBER RETURN NUMBER RETURN NUMBER FUNC_DEF FOR VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER RETURN STRING ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER RETURN STRING FOR VAR FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR RETURN STRING ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR RETURN STRING RETURN STRING ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
Alice and Bob play 5-in-a-row game. They have a playing field of size 10 Γ— 10. In turns they put either crosses or noughts, one at a time. Alice puts crosses and Bob puts noughts. In current match they have made some turns and now it's Alice's turn. She wonders if she can put cross in such empty cell that she wins immediately. Alice wins if some crosses in the field form line of length not smaller than 5. This line can be horizontal, vertical and diagonal. -----Input----- You are given matrix 10 Γ— 10 (10 lines of 10 characters each) with capital Latin letters 'X' being a cross, letters 'O' being a nought and '.' being an empty cell. The number of 'X' cells is equal to the number of 'O' cells and there is at least one of each type. There is at least one empty cell. It is guaranteed that in the current arrangement nobody has still won. -----Output----- Print 'YES' if it's possible for Alice to win in one turn by putting cross in some empty cell. Otherwise print 'NO'. -----Examples----- Input XX.XX..... .....OOOO. .......... .......... .......... .......... .......... .......... .......... .......... Output YES Input XXOXX..... OO.O...... .......... .......... .......... .......... .......... .......... .......... .......... Output NO
rs = [] for i in range(10): length = input() rs.append(length) temp1 = 1 flag1 = 1 def check(i, j, direct, temp, flag): if direct == 1: if j == 0: return 0 j -= 1 elif direct == 2: if j == 9: return 0 j += 1 elif direct == 3: if i == 0: return 0 i -= 1 elif direct == 4: if i == 9: return 0 i += 1 elif direct == 5: if i == 0 or j == 0: return 0 j -= 1 i -= 1 elif direct == 6: if i == 9 or j == 0: return 0 j -= 1 i += 1 elif direct == 7: if i == 0 or j == 9: return 0 j += 1 i -= 1 elif direct == 8: if i == 9 or j == 9: return 0 j += 1 i += 1 if rs[i][j] == "X": temp += 1 if temp > 4: return 1 return check(i, j, direct, temp, flag) elif rs[i][j] == "." and flag == 1: temp += 1 flag = 0 if temp > 4: return 1 return check(i, j, direct, temp, flag) else: return 0 def result(): for i in range(10): for j in range(10): if rs[i][j] == "X": for k in range(1, 9): if check(i, j, k, temp1, flag1) == 1: return 1 return 0 if result() == 0: print("NO") else: print("YES")
ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FUNC_DEF IF VAR NUMBER IF VAR NUMBER RETURN NUMBER VAR NUMBER IF VAR NUMBER IF VAR NUMBER RETURN NUMBER VAR NUMBER IF VAR NUMBER IF VAR NUMBER RETURN NUMBER VAR NUMBER IF VAR NUMBER IF VAR NUMBER RETURN NUMBER VAR NUMBER IF VAR NUMBER IF VAR NUMBER VAR NUMBER RETURN NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER IF VAR NUMBER VAR NUMBER RETURN NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER IF VAR NUMBER VAR NUMBER RETURN NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER IF VAR NUMBER VAR NUMBER RETURN NUMBER VAR NUMBER VAR NUMBER IF VAR VAR VAR STRING VAR NUMBER IF VAR NUMBER RETURN NUMBER RETURN FUNC_CALL VAR VAR VAR VAR VAR VAR IF VAR VAR VAR STRING VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER RETURN NUMBER RETURN FUNC_CALL VAR VAR VAR VAR VAR VAR RETURN NUMBER FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR STRING FOR VAR FUNC_CALL VAR NUMBER NUMBER IF FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER RETURN NUMBER RETURN NUMBER IF FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Alice and Bob play 5-in-a-row game. They have a playing field of size 10 Γ— 10. In turns they put either crosses or noughts, one at a time. Alice puts crosses and Bob puts noughts. In current match they have made some turns and now it's Alice's turn. She wonders if she can put cross in such empty cell that she wins immediately. Alice wins if some crosses in the field form line of length not smaller than 5. This line can be horizontal, vertical and diagonal. -----Input----- You are given matrix 10 Γ— 10 (10 lines of 10 characters each) with capital Latin letters 'X' being a cross, letters 'O' being a nought and '.' being an empty cell. The number of 'X' cells is equal to the number of 'O' cells and there is at least one of each type. There is at least one empty cell. It is guaranteed that in the current arrangement nobody has still won. -----Output----- Print 'YES' if it's possible for Alice to win in one turn by putting cross in some empty cell. Otherwise print 'NO'. -----Examples----- Input XX.XX..... .....OOOO. .......... .......... .......... .......... .......... .......... .......... .......... Output YES Input XXOXX..... OO.O...... .......... .......... .......... .......... .......... .......... .......... .......... Output NO
import sys dx = [0, 1, 1, 1] dy = [1, 1, 0, -1] range_x = set(range(10)) range_y = set(range(10)) def is_win(board): for i in range(10): for j in range(10): for dir in range(len(dx)): for k in range(5): new_x = i + k * dx[dir] new_y = j + k * dy[dir] if not ( new_x in range_x and new_y in range_y and board[new_x][new_y] == "X" ): break else: return True return False board = sys.stdin.read().split() for _ in range(10): for __ in range(10): if board[_][__] == ".": board[_] = board[_][:__] + "X" + board[_][__ + 1 :] if is_win(board): break board[_] = board[_][:__] + "." + board[_][__ + 1 :] else: continue break else: print("NO") sys.exit(0) print("YES")
IMPORT ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR VAR IF VAR VAR VAR VAR VAR VAR VAR STRING RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR STRING ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR VAR STRING VAR VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR VAR STRING VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR STRING
Alice and Bob play 5-in-a-row game. They have a playing field of size 10 Γ— 10. In turns they put either crosses or noughts, one at a time. Alice puts crosses and Bob puts noughts. In current match they have made some turns and now it's Alice's turn. She wonders if she can put cross in such empty cell that she wins immediately. Alice wins if some crosses in the field form line of length not smaller than 5. This line can be horizontal, vertical and diagonal. -----Input----- You are given matrix 10 Γ— 10 (10 lines of 10 characters each) with capital Latin letters 'X' being a cross, letters 'O' being a nought and '.' being an empty cell. The number of 'X' cells is equal to the number of 'O' cells and there is at least one of each type. There is at least one empty cell. It is guaranteed that in the current arrangement nobody has still won. -----Output----- Print 'YES' if it's possible for Alice to win in one turn by putting cross in some empty cell. Otherwise print 'NO'. -----Examples----- Input XX.XX..... .....OOOO. .......... .......... .......... .......... .......... .......... .......... .......... Output YES Input XXOXX..... OO.O...... .......... .......... .......... .......... .......... .......... .......... .......... Output NO
field = [] for i in range(10): s = input().strip() field.append(list(s)) def check(i, j): ti = i tj = j if i + 4 < 10: tics = set() for it in range(5): tics.add(field[ti][tj]) ti += 1 if len(tics) == 1: return True ti = i tj = j if j + 4 < 10: tics = set() for it in range(5): tics.add(field[ti][tj]) tj += 1 if len(tics) == 1: return True ti = i tj = j if i + 4 < 10 and j + 4 < 10: tics = set() for it in range(5): tics.add(field[ti][tj]) ti += 1 tj += 1 if len(tics) == 1: return True ti = i tj = j if i - 4 >= 0 and j + 4 < 10: tics = set() for it in range(5): tics.add(field[ti][tj]) ti -= 1 tj += 1 if len(tics) == 1: return True return False def checkfield(): for i in range(10): for j in range(10): if field[i][j] == "X": if check(i, j): return True return False result = False for i in range(10): for j in range(10): if field[i][j] == ".": field[i][j] = "X" if checkfield(): result = True break field[i][j] = "." if result: break if result: print("YES") else: print("NO")
ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER ASSIGN VAR VAR ASSIGN VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER ASSIGN VAR VAR ASSIGN VAR VAR IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR NUMBER VAR NUMBER IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER ASSIGN VAR VAR ASSIGN VAR VAR IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR NUMBER VAR NUMBER IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER RETURN NUMBER FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR STRING IF FUNC_CALL VAR VAR VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR STRING ASSIGN VAR VAR VAR STRING IF FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR STRING IF VAR IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Alice and Bob play 5-in-a-row game. They have a playing field of size 10 Γ— 10. In turns they put either crosses or noughts, one at a time. Alice puts crosses and Bob puts noughts. In current match they have made some turns and now it's Alice's turn. She wonders if she can put cross in such empty cell that she wins immediately. Alice wins if some crosses in the field form line of length not smaller than 5. This line can be horizontal, vertical and diagonal. -----Input----- You are given matrix 10 Γ— 10 (10 lines of 10 characters each) with capital Latin letters 'X' being a cross, letters 'O' being a nought and '.' being an empty cell. The number of 'X' cells is equal to the number of 'O' cells and there is at least one of each type. There is at least one empty cell. It is guaranteed that in the current arrangement nobody has still won. -----Output----- Print 'YES' if it's possible for Alice to win in one turn by putting cross in some empty cell. Otherwise print 'NO'. -----Examples----- Input XX.XX..... .....OOOO. .......... .......... .......... .......... .......... .......... .......... .......... Output YES Input XXOXX..... OO.O...... .......... .......... .......... .......... .......... .......... .......... .......... Output NO
m = [] for i in range(10): s = input() m.append(s) for i in range(10): for j in range(6): s = "" s += m[i][j] + m[i][j + 1] + m[i][j + 2] + m[i][j + 3] + m[i][j + 4] if s.count("X") == 4 and s.count("O") == 0: print("YES") exit() for i in range(10): for j in range(6): s = "" s += m[j][i] + m[j + 1][i] + m[j + 2][i] + m[j + 3][i] + m[j + 4][i] if s.count("X") == 4 and s.count("O") == 0: print("YES") exit() for i in range(6): for j in range(6): s = "" s += ( m[j][i] + m[j + 1][i + 1] + m[j + 2][i + 2] + m[j + 3][i + 3] + m[j + 4][i + 4] ) if s.count("X") == 4 and s.count("O") == 0: print("YES") exit() for i in range(6): for j in range(6): s = "" s += ( m[j + 4][i] + m[j + 3][i + 1] + m[j + 2][i + 2] + m[j + 1][i + 3] + m[j][i + 4] ) if s.count("X") == 4 and s.count("O") == 0: print("YES") exit() print("NO")
ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR STRING VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR STRING NUMBER FUNC_CALL VAR STRING NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR STRING VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR IF FUNC_CALL VAR STRING NUMBER FUNC_CALL VAR STRING NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR STRING VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF FUNC_CALL VAR STRING NUMBER FUNC_CALL VAR STRING NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR STRING VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR STRING NUMBER FUNC_CALL VAR STRING NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR STRING
Alice and Bob play 5-in-a-row game. They have a playing field of size 10 Γ— 10. In turns they put either crosses or noughts, one at a time. Alice puts crosses and Bob puts noughts. In current match they have made some turns and now it's Alice's turn. She wonders if she can put cross in such empty cell that she wins immediately. Alice wins if some crosses in the field form line of length not smaller than 5. This line can be horizontal, vertical and diagonal. -----Input----- You are given matrix 10 Γ— 10 (10 lines of 10 characters each) with capital Latin letters 'X' being a cross, letters 'O' being a nought and '.' being an empty cell. The number of 'X' cells is equal to the number of 'O' cells and there is at least one of each type. There is at least one empty cell. It is guaranteed that in the current arrangement nobody has still won. -----Output----- Print 'YES' if it's possible for Alice to win in one turn by putting cross in some empty cell. Otherwise print 'NO'. -----Examples----- Input XX.XX..... .....OOOO. .......... .......... .......... .......... .......... .......... .......... .......... Output YES Input XXOXX..... OO.O...... .......... .......... .......... .......... .......... .......... .......... .......... Output NO
A = [list(input()) for i in range(10)] for i in range(10): A[i] += ["O"] * 5 for i in range(5): A.insert(0, ["O"] * 15) A.append(["O"] * 15) D = [(1, 0), (0, 1), (1, 1), (-1, 1)] flag = False for i in range(5, 15): for j in range(10): if ( A[i][j] == "X" or A[i][j + 1] == "X" or A[i + 1][j] == "X" or A[i + 1][j + 1] == "X" or A[i - 1][j + 1] == "X" ): cnt = [0, 0, 0, 0] for k in range(5): for n, d in enumerate(D): dx = k * d[0] dy = k * d[1] if A[i + dx][j + dy] == "X": cnt[n] += 1 if A[i + dx][j + dy] == "O": cnt[n] = -10 for c in cnt: if c == 4: flag = True break if flag == True: break if flag == True: break if flag == True: print("YES") else: print("NO")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR BIN_OP LIST STRING NUMBER FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER BIN_OP LIST STRING NUMBER EXPR FUNC_CALL VAR BIN_OP LIST STRING NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR STRING VAR VAR BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER VAR STRING VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER STRING ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR VAR BIN_OP VAR VAR STRING VAR VAR NUMBER IF VAR BIN_OP VAR VAR BIN_OP VAR VAR STRING ASSIGN VAR VAR NUMBER FOR VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Alice and Bob play 5-in-a-row game. They have a playing field of size 10 Γ— 10. In turns they put either crosses or noughts, one at a time. Alice puts crosses and Bob puts noughts. In current match they have made some turns and now it's Alice's turn. She wonders if she can put cross in such empty cell that she wins immediately. Alice wins if some crosses in the field form line of length not smaller than 5. This line can be horizontal, vertical and diagonal. -----Input----- You are given matrix 10 Γ— 10 (10 lines of 10 characters each) with capital Latin letters 'X' being a cross, letters 'O' being a nought and '.' being an empty cell. The number of 'X' cells is equal to the number of 'O' cells and there is at least one of each type. There is at least one empty cell. It is guaranteed that in the current arrangement nobody has still won. -----Output----- Print 'YES' if it's possible for Alice to win in one turn by putting cross in some empty cell. Otherwise print 'NO'. -----Examples----- Input XX.XX..... .....OOOO. .......... .......... .......... .......... .......... .......... .......... .......... Output YES Input XXOXX..... OO.O...... .......... .......... .......... .......... .......... .......... .......... .......... Output NO
N = 10 patterns = [".XXXX", "XXXX.", "XX.XX", "XXX.X", "X.XXX"] def game(s): cols = [[] for _ in range(N)] rows = [[] for _ in range(N)] fdiag = [[] for _ in range(N + N - 1)] bdiag = [[] for _ in range(len(fdiag))] min_bdiag = -N + 1 for y in range(N): for x in range(N): cols[y].append(s[y][x]) rows[x].append(s[y][x]) fdiag[x + y].append(s[y][x]) bdiag[-min_bdiag + x - y].append(s[y][x]) for arr in [cols, rows, fdiag, bdiag]: for l in arr: line = "".join(l) if line.count("X") >= 4: for p in patterns: if line.find(p) != -1: return True return False s = [input() for _ in range(N)] if game(s): print("YES") else: print("NO")
ASSIGN VAR NUMBER ASSIGN VAR LIST STRING STRING STRING STRING STRING FUNC_DEF ASSIGN VAR LIST VAR FUNC_CALL VAR VAR ASSIGN VAR LIST VAR FUNC_CALL VAR VAR ASSIGN VAR LIST VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR LIST VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR FOR VAR LIST VAR VAR VAR VAR FOR VAR VAR ASSIGN VAR FUNC_CALL STRING VAR IF FUNC_CALL VAR STRING NUMBER FOR VAR VAR IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Alice and Bob play 5-in-a-row game. They have a playing field of size 10 Γ— 10. In turns they put either crosses or noughts, one at a time. Alice puts crosses and Bob puts noughts. In current match they have made some turns and now it's Alice's turn. She wonders if she can put cross in such empty cell that she wins immediately. Alice wins if some crosses in the field form line of length not smaller than 5. This line can be horizontal, vertical and diagonal. -----Input----- You are given matrix 10 Γ— 10 (10 lines of 10 characters each) with capital Latin letters 'X' being a cross, letters 'O' being a nought and '.' being an empty cell. The number of 'X' cells is equal to the number of 'O' cells and there is at least one of each type. There is at least one empty cell. It is guaranteed that in the current arrangement nobody has still won. -----Output----- Print 'YES' if it's possible for Alice to win in one turn by putting cross in some empty cell. Otherwise print 'NO'. -----Examples----- Input XX.XX..... .....OOOO. .......... .......... .......... .......... .......... .......... .......... .......... Output YES Input XXOXX..... OO.O...... .......... .......... .......... .......... .......... .......... .......... .......... Output NO
input_data_set1 = [input() for s in range(0, 10)] patterns = [".XXXX", "X.XXX", "XX.XX", "XXX.X", "XXXX."] def check_data_set(data_set, patterns): win_flag = "NO" for row in data_set: for pattern in patterns: if row.find(pattern) != -1: win_flag = "YES" return win_flag def get_diagonal_data_set(source_data_set): diagonal_data_set_1 = [] diagonal_data_set_2 = [] for i in range(0, 6): diagonal_data_set_1.append("") diagonal_data_set_2.append("") for j in range(0, 10 - i): diagonal_data_set_1[i] += source_data_set[j][j + i] diagonal_data_set_2[i] += source_data_set[j + i][j] return diagonal_data_set_1 + diagonal_data_set_2 horizontal_data_set = input_data_set1 vertical_data_set = [] for i in range(0, 10): vertical_data_set.append("") for j in range(0, 10): vertical_data_set[i] += horizontal_data_set[j][i] data_set = ( horizontal_data_set + vertical_data_set + get_diagonal_data_set(horizontal_data_set) + get_diagonal_data_set(vertical_data_set[::-1]) ) print(check_data_set(data_set, patterns))
ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR LIST STRING STRING STRING STRING STRING FUNC_DEF ASSIGN VAR STRING FOR VAR VAR FOR VAR VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR STRING RETURN VAR FUNC_DEF ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR RETURN BIN_OP VAR VAR ASSIGN VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR NUMBER NUMBER VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
Alice and Bob play 5-in-a-row game. They have a playing field of size 10 Γ— 10. In turns they put either crosses or noughts, one at a time. Alice puts crosses and Bob puts noughts. In current match they have made some turns and now it's Alice's turn. She wonders if she can put cross in such empty cell that she wins immediately. Alice wins if some crosses in the field form line of length not smaller than 5. This line can be horizontal, vertical and diagonal. -----Input----- You are given matrix 10 Γ— 10 (10 lines of 10 characters each) with capital Latin letters 'X' being a cross, letters 'O' being a nought and '.' being an empty cell. The number of 'X' cells is equal to the number of 'O' cells and there is at least one of each type. There is at least one empty cell. It is guaranteed that in the current arrangement nobody has still won. -----Output----- Print 'YES' if it's possible for Alice to win in one turn by putting cross in some empty cell. Otherwise print 'NO'. -----Examples----- Input XX.XX..... .....OOOO. .......... .......... .......... .......... .......... .......... .......... .......... Output YES Input XXOXX..... OO.O...... .......... .......... .......... .......... .......... .......... .......... .......... Output NO
import sys def solve1(i, j, bool1, bool2): cnt0 = 0 cnt1 = 0 u = 0 v = 0 for k in range(1, 11): if bool1: u = k if bool2: v = k if not (0 <= i + u < 10 and 0 <= j + v < 10): break elif s[i + u][j + v] == "X": cnt0 += 1 else: break for k in range(1, 11): if bool1: u = -k if bool2: v = -k if not (0 <= i + u < 10 and 0 <= j + v < 10): break elif s[i + u][j + v] == "X": cnt0 += 1 else: break for k in range(1, 11): if bool1: u = -k if bool2: v = k if not (0 <= i + u < 10 and 0 <= j + v < 10): break elif s[i + u][j + v] == "X": cnt1 += 1 else: break for k in range(1, 11): if bool1: u = k if bool2: v = -k if not (0 <= i + u < 10 and 0 <= j + v < 10): break elif s[i + u][j + v] == "X": cnt1 += 1 else: break return max(cnt0, cnt1) >= 4 def solve(i, j): return ( solve1(i, j, False, True) or solve1(i, j, True, False) or solve1(i, j, True, True) ) input = sys.stdin.readline n = 10 s = [input() for i in range(n)] flag = False for i in range(n): for j in range(n): if s[i][j] == ".": flag |= solve(i, j) if flag: print("YES") else: print("NO")
IMPORT FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR ASSIGN VAR VAR IF VAR ASSIGN VAR VAR IF NUMBER BIN_OP VAR VAR NUMBER NUMBER BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR VAR BIN_OP VAR VAR STRING VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR ASSIGN VAR VAR IF VAR ASSIGN VAR VAR IF NUMBER BIN_OP VAR VAR NUMBER NUMBER BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR VAR BIN_OP VAR VAR STRING VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR ASSIGN VAR VAR IF VAR ASSIGN VAR VAR IF NUMBER BIN_OP VAR VAR NUMBER NUMBER BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR VAR BIN_OP VAR VAR STRING VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR ASSIGN VAR VAR IF VAR ASSIGN VAR VAR IF NUMBER BIN_OP VAR VAR NUMBER NUMBER BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR VAR BIN_OP VAR VAR STRING VAR NUMBER RETURN FUNC_CALL VAR VAR VAR NUMBER FUNC_DEF RETURN FUNC_CALL VAR VAR VAR NUMBER NUMBER FUNC_CALL VAR VAR VAR NUMBER NUMBER FUNC_CALL VAR VAR VAR NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING VAR FUNC_CALL VAR VAR VAR IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Alice and Bob play 5-in-a-row game. They have a playing field of size 10 Γ— 10. In turns they put either crosses or noughts, one at a time. Alice puts crosses and Bob puts noughts. In current match they have made some turns and now it's Alice's turn. She wonders if she can put cross in such empty cell that she wins immediately. Alice wins if some crosses in the field form line of length not smaller than 5. This line can be horizontal, vertical and diagonal. -----Input----- You are given matrix 10 Γ— 10 (10 lines of 10 characters each) with capital Latin letters 'X' being a cross, letters 'O' being a nought and '.' being an empty cell. The number of 'X' cells is equal to the number of 'O' cells and there is at least one of each type. There is at least one empty cell. It is guaranteed that in the current arrangement nobody has still won. -----Output----- Print 'YES' if it's possible for Alice to win in one turn by putting cross in some empty cell. Otherwise print 'NO'. -----Examples----- Input XX.XX..... .....OOOO. .......... .......... .......... .......... .......... .......... .......... .......... Output YES Input XXOXX..... OO.O...... .......... .......... .......... .......... .......... .......... .......... .......... Output NO
s = 10 * [0] for i in range(10): s[i] = input() def trav(i, j, s, n): if n == 1: if i < 9: if s[i + 1][j] == "X": return 1 + trav(i + 1, j, s, n) return 0 return 0 if n == -1: if i > 0: if s[i - 1][j] == "X": return 1 + trav(i - 1, j, s, n) return 0 return 0 if n == 2: if j < 9: if s[i][j + 1] == "X": return 1 + trav(i, j + 1, s, n) return 0 return 0 if n == -2: if j > 0: if s[i][j - 1] == "X": return 1 + trav(i, j - 1, s, n) return 0 return 0 if n == 3: if i < 9 and j < 9: if s[i + 1][j + 1] == "X": return 1 + trav(i + 1, j + 1, s, n) return 0 return 0 if n == -3: if i > 0 and j > 0: if s[i - 1][j - 1] == "X": return 1 + trav(i - 1, j - 1, s, n) return 0 return 0 if n == 4: if i > 0 and j < 9: if s[i - 1][j + 1] == "X": return 1 + trav(i - 1, j + 1, s, n) return 0 return 0 if n == -4: if i < 9 and j > 0: if s[i + 1][j - 1] == "X": return 1 + trav(i + 1, j - 1, s, n) return 0 return 0 flag = False for i in range(10): for j in range(10): if s[i][j] == ".": if ( trav(i, j, s, 1) + trav(i, j, s, -1) >= 4 or trav(i, j, s, 2) + trav(i, j, s, -2) >= 4 or trav(i, j, s, 3) + trav(i, j, s, -3) >= 4 or trav(i, j, s, 4) + trav(i, j, s, -4) >= 4 ): flag = True print("YES") break if flag: break if not flag: print("NO")
ASSIGN VAR BIN_OP NUMBER LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR FUNC_DEF IF VAR NUMBER IF VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR STRING RETURN BIN_OP NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR RETURN NUMBER RETURN NUMBER IF VAR NUMBER IF VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR STRING RETURN BIN_OP NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR RETURN NUMBER RETURN NUMBER IF VAR NUMBER IF VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER STRING RETURN BIN_OP NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR RETURN NUMBER RETURN NUMBER IF VAR NUMBER IF VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER STRING RETURN BIN_OP NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR RETURN NUMBER RETURN NUMBER IF VAR NUMBER IF VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER STRING RETURN BIN_OP NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR VAR RETURN NUMBER RETURN NUMBER IF VAR NUMBER IF VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER STRING RETURN BIN_OP NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR VAR RETURN NUMBER RETURN NUMBER IF VAR NUMBER IF VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER STRING RETURN BIN_OP NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR VAR RETURN NUMBER RETURN NUMBER IF VAR NUMBER IF VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER STRING RETURN BIN_OP NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR STRING IF BIN_OP FUNC_CALL VAR VAR VAR VAR NUMBER FUNC_CALL VAR VAR VAR VAR NUMBER NUMBER BIN_OP FUNC_CALL VAR VAR VAR VAR NUMBER FUNC_CALL VAR VAR VAR VAR NUMBER NUMBER BIN_OP FUNC_CALL VAR VAR VAR VAR NUMBER FUNC_CALL VAR VAR VAR VAR NUMBER NUMBER BIN_OP FUNC_CALL VAR VAR VAR VAR NUMBER FUNC_CALL VAR VAR VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR IF VAR EXPR FUNC_CALL VAR STRING