description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
Connect the countless points with lines, till we reach the faraway yonder. There are n points on a coordinate plane, the i-th of which being (i, y_{i}). Determine whether it's possible to draw two parallel and non-overlapping lines, such that every point in the set lies on exactly one of them, and each of them passes through at least one point in the set. -----Input----- The first line of input contains a positive integer n (3 ≀ n ≀ 1 000) β€” the number of points. The second line contains n space-separated integers y_1, y_2, ..., y_{n} ( - 10^9 ≀ y_{i} ≀ 10^9) β€” the vertical coordinates of each point. -----Output----- Output "Yes" (without quotes) if it's possible to fulfill the requirements, and "No" otherwise. You can print each letter in any case (upper or lower). -----Examples----- Input 5 7 5 8 6 9 Output Yes Input 5 -1 -2 0 0 -5 Output No Input 5 5 4 3 2 1 Output No Input 5 1000000000 0 0 0 0 Output Yes -----Note----- In the first example, there are five points: (1, 7), (2, 5), (3, 8), (4, 6) and (5, 9). It's possible to draw a line that passes through points 1, 3, 5, and another one that passes through points 2, 4 and is parallel to the first one. In the second example, while it's possible to draw two lines that cover all points, they cannot be made parallel. In the third example, it's impossible to satisfy both requirements at the same time.
n = int(input()) a = list(map(int, input().split())) t = True tan1 = 99999999 tan = [] pos = [] c = 0 k = True for i in range(1, n): temp = (a[i] - a[0]) / i if t: for j in range(len(tan)): if tan[j] == temp: pos.remove(pos[j]) c -= 1 tan1 = temp t = False k = False break if k: tan.append(temp) pos.append([a[i], i]) c += 1 elif temp != tan1: pos.append([a[i], i]) c += 1 t = True if c == 0: t = False elif c == 1: t = True else: tan2 = (pos[1][0] - pos[0][0]) / (pos[1][1] - pos[0][1]) if tan2 != tan1: if c == n - 1: c2 = 0 c3 = 0 for i in range(2, c): temp = (pos[i][0] - pos[0][0]) / (pos[i][1] - pos[0][1]) if temp != tan2: c2 += 1 c3 = i if c2 > 1: t = False break if c2 == 1: temp = (pos[c3][0] - a[0]) / pos[c3][1] if temp == tan2: t = True else: t = False elif n != 3: t = False else: for i in range(1, c): temp = (pos[i][0] - pos[0][0]) / (pos[i][1] - pos[0][1]) if temp != tan2: t = False break if t: print("Yes") else: print("No")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR NUMBER VAR IF VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER VAR NUMBER NUMBER IF VAR VAR IF VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER NUMBER BIN_OP VAR VAR NUMBER VAR NUMBER NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER VAR VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER NUMBER BIN_OP VAR VAR NUMBER VAR NUMBER NUMBER IF VAR VAR ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Connect the countless points with lines, till we reach the faraway yonder. There are n points on a coordinate plane, the i-th of which being (i, y_{i}). Determine whether it's possible to draw two parallel and non-overlapping lines, such that every point in the set lies on exactly one of them, and each of them passes through at least one point in the set. -----Input----- The first line of input contains a positive integer n (3 ≀ n ≀ 1 000) β€” the number of points. The second line contains n space-separated integers y_1, y_2, ..., y_{n} ( - 10^9 ≀ y_{i} ≀ 10^9) β€” the vertical coordinates of each point. -----Output----- Output "Yes" (without quotes) if it's possible to fulfill the requirements, and "No" otherwise. You can print each letter in any case (upper or lower). -----Examples----- Input 5 7 5 8 6 9 Output Yes Input 5 -1 -2 0 0 -5 Output No Input 5 5 4 3 2 1 Output No Input 5 1000000000 0 0 0 0 Output Yes -----Note----- In the first example, there are five points: (1, 7), (2, 5), (3, 8), (4, 6) and (5, 9). It's possible to draw a line that passes through points 1, 3, 5, and another one that passes through points 2, 4 and is parallel to the first one. In the second example, while it's possible to draw two lines that cover all points, they cannot be made parallel. In the third example, it's impossible to satisfy both requirements at the same time.
n = int(input()) l = [int(i) for i in input().split()] slope = (l[n - 1] - l[0]) / (n - 1) f = 0 for j in range(1, n - 1): if (l[j] - l[0]) / j != slope: f = 1 break if f == 0: print("No") else: flag = 0 for i in range(1, n - 1): s = (l[i] - l[0]) / i l1 = [] for j in range(n): l1.append(0) l1[0] = 1 l1[i] = 1 l2 = [] for j in range(i + 1, n): if (l[j] - l[0]) / j == s: l1[j] = 1 if l1.count(0) == 1: print("Yes") flag = 1 break else: for j in range(n): if l1[j] == 0: l2.append([l[j], j]) length = len(l2) s1 = (l2[-1][0] - l2[0][0]) / (l2[-1][1] - l2[0][1]) if s1 != s: continue else: check = 0 for j in range(1, length - 1): if (l2[j][0] - l2[0][0]) / (l2[j][1] - l2[0][1]) != s1: check = 1 break if check == 1: continue else: print("Yes") flag = 1 break if flag == 0: if n == 3: print("Yes") flag = 1 else: s = (l[-2] - l[1]) / (n - 3) if s == slope: check = 0 for i in range(2, n - 2): if (l[i] - l[1]) / (i - 1) != s: check = 1 break if check == 0: print("Yes") flag = 1 if flag == 0: s = (l[-1] - l[1]) / (n - 2) check = 0 for i in range(2, n - 1): if (l[i] - l[1]) / (i - 1) != s: check = 1 break if check == 0: print("Yes") else: print("No")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP BIN_OP VAR VAR VAR NUMBER VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR NUMBER VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF BIN_OP BIN_OP VAR VAR VAR NUMBER VAR VAR ASSIGN VAR VAR NUMBER IF FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR LIST VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER VAR NUMBER NUMBER IF VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER NUMBER BIN_OP VAR VAR NUMBER VAR NUMBER NUMBER VAR ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP BIN_OP VAR VAR VAR NUMBER BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP BIN_OP VAR VAR VAR NUMBER BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Connect the countless points with lines, till we reach the faraway yonder. There are n points on a coordinate plane, the i-th of which being (i, y_{i}). Determine whether it's possible to draw two parallel and non-overlapping lines, such that every point in the set lies on exactly one of them, and each of them passes through at least one point in the set. -----Input----- The first line of input contains a positive integer n (3 ≀ n ≀ 1 000) β€” the number of points. The second line contains n space-separated integers y_1, y_2, ..., y_{n} ( - 10^9 ≀ y_{i} ≀ 10^9) β€” the vertical coordinates of each point. -----Output----- Output "Yes" (without quotes) if it's possible to fulfill the requirements, and "No" otherwise. You can print each letter in any case (upper or lower). -----Examples----- Input 5 7 5 8 6 9 Output Yes Input 5 -1 -2 0 0 -5 Output No Input 5 5 4 3 2 1 Output No Input 5 1000000000 0 0 0 0 Output Yes -----Note----- In the first example, there are five points: (1, 7), (2, 5), (3, 8), (4, 6) and (5, 9). It's possible to draw a line that passes through points 1, 3, 5, and another one that passes through points 2, 4 and is parallel to the first one. In the second example, while it's possible to draw two lines that cover all points, they cannot be made parallel. In the third example, it's impossible to satisfy both requirements at the same time.
def is_belong(A, C, x, y): return A * x + y + C == 0 def solution(): n = int(input()) a = [int(i) for i in input().split()] other_pointes_indexes = [] for k in [0, 1]: for i in range(1, n): if k == i: continue A = 0 if k - i != 0: A = (a[i] - a[k]) / (k - i) C1 = -a[k] - A * k C2 = C1 success = True for j in range(n): if not is_belong(A, C1, j, a[j]): if C2 != C1: if not is_belong(A, C2, j, a[j]): success = False break else: C2 = -A * j - a[j] if success: if C1 != C2: print("Yes") return print("No") solution()
FUNC_DEF RETURN BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR ASSIGN VAR NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR VAR VAR VAR IF VAR VAR IF FUNC_CALL VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR IF VAR IF VAR VAR EXPR FUNC_CALL VAR STRING RETURN EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR
Given a sorted array A[] of N positive integers having all the numbers occurring exactly twice, except for one number which will occur only once. Find the number occurring only once. Example 1: Input: N = 5 A = {1, 1, 2, 5, 5} Output: 2 Explanation: Since 2 occurs once, while other numbers occur twice, 2 is the answer. Example 2: Input: N = 7 A = {2, 2, 5, 5, 20, 30, 30} Output: 20 Explanation: Since 20 occurs once, while other numbers occur twice, 20 is the answer. Your Task: You don't need to read input or print anything. Your task is to complete the function search() which takes two arguments(array A and integer N) and returns the number occurring only once. Expected Time Complexity: O(Log(N)). Expected Auxiliary Space: O(1). Constraints 0 < N <= 10^6 0 <= A[i] <= 10^9
class Solution: def search(self, A, N): has = {} for a in A: if a in has: has[a] += 1 else: has[a] = 1 for key in has: if has[key] == 1: return key
CLASS_DEF FUNC_DEF ASSIGN VAR DICT FOR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR VAR IF VAR VAR NUMBER RETURN VAR
Given a sorted array A[] of N positive integers having all the numbers occurring exactly twice, except for one number which will occur only once. Find the number occurring only once. Example 1: Input: N = 5 A = {1, 1, 2, 5, 5} Output: 2 Explanation: Since 2 occurs once, while other numbers occur twice, 2 is the answer. Example 2: Input: N = 7 A = {2, 2, 5, 5, 20, 30, 30} Output: 20 Explanation: Since 20 occurs once, while other numbers occur twice, 20 is the answer. Your Task: You don't need to read input or print anything. Your task is to complete the function search() which takes two arguments(array A and integer N) and returns the number occurring only once. Expected Time Complexity: O(Log(N)). Expected Auxiliary Space: O(1). Constraints 0 < N <= 10^6 0 <= A[i] <= 10^9
class Solution: def search(self, A, N): dct = {} for i in A: if i in dct: dct[i] += 1 else: dct[i] = 1 output = [] for i in dct: if dct[i] == 1: output.append(i) result = ",".join(str(i) for i in output) return result
CLASS_DEF FUNC_DEF ASSIGN VAR DICT FOR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR LIST FOR VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR RETURN VAR
Given a sorted array A[] of N positive integers having all the numbers occurring exactly twice, except for one number which will occur only once. Find the number occurring only once. Example 1: Input: N = 5 A = {1, 1, 2, 5, 5} Output: 2 Explanation: Since 2 occurs once, while other numbers occur twice, 2 is the answer. Example 2: Input: N = 7 A = {2, 2, 5, 5, 20, 30, 30} Output: 20 Explanation: Since 20 occurs once, while other numbers occur twice, 20 is the answer. Your Task: You don't need to read input or print anything. Your task is to complete the function search() which takes two arguments(array A and integer N) and returns the number occurring only once. Expected Time Complexity: O(Log(N)). Expected Auxiliary Space: O(1). Constraints 0 < N <= 10^6 0 <= A[i] <= 10^9
class Solution: def search(self, A, N): d = {} for i in A: d[i] = d.get(i, 0) + 1 for k, v in d.items(): if v == 1: return k
CLASS_DEF FUNC_DEF ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER FOR VAR VAR FUNC_CALL VAR IF VAR NUMBER RETURN VAR
Given a sorted array A[] of N positive integers having all the numbers occurring exactly twice, except for one number which will occur only once. Find the number occurring only once. Example 1: Input: N = 5 A = {1, 1, 2, 5, 5} Output: 2 Explanation: Since 2 occurs once, while other numbers occur twice, 2 is the answer. Example 2: Input: N = 7 A = {2, 2, 5, 5, 20, 30, 30} Output: 20 Explanation: Since 20 occurs once, while other numbers occur twice, 20 is the answer. Your Task: You don't need to read input or print anything. Your task is to complete the function search() which takes two arguments(array A and integer N) and returns the number occurring only once. Expected Time Complexity: O(Log(N)). Expected Auxiliary Space: O(1). Constraints 0 < N <= 10^6 0 <= A[i] <= 10^9
class Solution: def search(self, a, N): zero = 0 one = 1 while zero < N: if one < N and a[zero] == a[one]: zero += 2 one += 2 else: return a[zero]
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER RETURN VAR VAR
Given a sorted array A[] of N positive integers having all the numbers occurring exactly twice, except for one number which will occur only once. Find the number occurring only once. Example 1: Input: N = 5 A = {1, 1, 2, 5, 5} Output: 2 Explanation: Since 2 occurs once, while other numbers occur twice, 2 is the answer. Example 2: Input: N = 7 A = {2, 2, 5, 5, 20, 30, 30} Output: 20 Explanation: Since 20 occurs once, while other numbers occur twice, 20 is the answer. Your Task: You don't need to read input or print anything. Your task is to complete the function search() which takes two arguments(array A and integer N) and returns the number occurring only once. Expected Time Complexity: O(Log(N)). Expected Auxiliary Space: O(1). Constraints 0 < N <= 10^6 0 <= A[i] <= 10^9
class Solution(object): def search1(self, nums, N): index = 0 while index < N: if index + 1 < N and nums[index] == nums[index + 1]: index += 2 else: break return nums[index] def search(self, nums, N): xor = 0 for num in nums: xor ^= num return xor
CLASS_DEF VAR FUNC_DEF ASSIGN VAR NUMBER WHILE VAR VAR IF BIN_OP VAR NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR VAR VAR RETURN VAR
Given a sorted array A[] of N positive integers having all the numbers occurring exactly twice, except for one number which will occur only once. Find the number occurring only once. Example 1: Input: N = 5 A = {1, 1, 2, 5, 5} Output: 2 Explanation: Since 2 occurs once, while other numbers occur twice, 2 is the answer. Example 2: Input: N = 7 A = {2, 2, 5, 5, 20, 30, 30} Output: 20 Explanation: Since 20 occurs once, while other numbers occur twice, 20 is the answer. Your Task: You don't need to read input or print anything. Your task is to complete the function search() which takes two arguments(array A and integer N) and returns the number occurring only once. Expected Time Complexity: O(Log(N)). Expected Auxiliary Space: O(1). Constraints 0 < N <= 10^6 0 <= A[i] <= 10^9
class Solution: def search(self, A, N): d = {} for i in A: if i not in d: d[i] = 1 else: d[i] += 1 lst = list(d.values()) lst1 = list(d.keys()) for i in range(len(lst)): if lst[i] == 1: return lst1[i]
CLASS_DEF FUNC_DEF ASSIGN VAR DICT FOR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER RETURN VAR VAR
Given a sorted array A[] of N positive integers having all the numbers occurring exactly twice, except for one number which will occur only once. Find the number occurring only once. Example 1: Input: N = 5 A = {1, 1, 2, 5, 5} Output: 2 Explanation: Since 2 occurs once, while other numbers occur twice, 2 is the answer. Example 2: Input: N = 7 A = {2, 2, 5, 5, 20, 30, 30} Output: 20 Explanation: Since 20 occurs once, while other numbers occur twice, 20 is the answer. Your Task: You don't need to read input or print anything. Your task is to complete the function search() which takes two arguments(array A and integer N) and returns the number occurring only once. Expected Time Complexity: O(Log(N)). Expected Auxiliary Space: O(1). Constraints 0 < N <= 10^6 0 <= A[i] <= 10^9
class Solution: def search(self, A, N): marker = -1 for i in A: if marker == -1: marker = i elif marker == i: marker = -1 elif marker != -1 and marker != i: return marker return marker
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER ASSIGN VAR VAR IF VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER VAR VAR RETURN VAR RETURN VAR
Given a sorted array A[] of N positive integers having all the numbers occurring exactly twice, except for one number which will occur only once. Find the number occurring only once. Example 1: Input: N = 5 A = {1, 1, 2, 5, 5} Output: 2 Explanation: Since 2 occurs once, while other numbers occur twice, 2 is the answer. Example 2: Input: N = 7 A = {2, 2, 5, 5, 20, 30, 30} Output: 20 Explanation: Since 20 occurs once, while other numbers occur twice, 20 is the answer. Your Task: You don't need to read input or print anything. Your task is to complete the function search() which takes two arguments(array A and integer N) and returns the number occurring only once. Expected Time Complexity: O(Log(N)). Expected Auxiliary Space: O(1). Constraints 0 < N <= 10^6 0 <= A[i] <= 10^9
class Solution: def search(self, A, n): i, x = 0, 1 while x < n: if i != x and A[i] ^ A[x] == 0: i = x + 1 x += 1 return A[i]
CLASS_DEF FUNC_DEF ASSIGN VAR VAR NUMBER NUMBER WHILE VAR VAR IF VAR VAR BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR VAR
Given a sorted array A[] of N positive integers having all the numbers occurring exactly twice, except for one number which will occur only once. Find the number occurring only once. Example 1: Input: N = 5 A = {1, 1, 2, 5, 5} Output: 2 Explanation: Since 2 occurs once, while other numbers occur twice, 2 is the answer. Example 2: Input: N = 7 A = {2, 2, 5, 5, 20, 30, 30} Output: 20 Explanation: Since 20 occurs once, while other numbers occur twice, 20 is the answer. Your Task: You don't need to read input or print anything. Your task is to complete the function search() which takes two arguments(array A and integer N) and returns the number occurring only once. Expected Time Complexity: O(Log(N)). Expected Auxiliary Space: O(1). Constraints 0 < N <= 10^6 0 <= A[i] <= 10^9
class Solution: def search(self, A, N): def helper(A, low, high): if low > high: return None if low == high: return A[low] m = low + (high - low) // 2 if m % 2 == 0: if A[m] == A[m + 1]: return helper(A, m + 2, high) else: return helper(A, low, m) elif A[m] == A[m - 1]: return helper(A, m + 1, high) else: return helper(A, low, m - 1) return helper(A, 0, N - 1)
CLASS_DEF FUNC_DEF FUNC_DEF IF VAR VAR RETURN NONE IF VAR VAR RETURN VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER RETURN FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR RETURN FUNC_CALL VAR VAR VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER RETURN FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR RETURN FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER RETURN FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER
Given a sorted array A[] of N positive integers having all the numbers occurring exactly twice, except for one number which will occur only once. Find the number occurring only once. Example 1: Input: N = 5 A = {1, 1, 2, 5, 5} Output: 2 Explanation: Since 2 occurs once, while other numbers occur twice, 2 is the answer. Example 2: Input: N = 7 A = {2, 2, 5, 5, 20, 30, 30} Output: 20 Explanation: Since 20 occurs once, while other numbers occur twice, 20 is the answer. Your Task: You don't need to read input or print anything. Your task is to complete the function search() which takes two arguments(array A and integer N) and returns the number occurring only once. Expected Time Complexity: O(Log(N)). Expected Auxiliary Space: O(1). Constraints 0 < N <= 10^6 0 <= A[i] <= 10^9
class Solution: def search(self, A, N): N = len(A) low = 0 high = N - 1 while low < high: mid = low + high >> 1 if mid % 2 != 0: if A[mid] == A[mid - 1]: low = mid + 1 else: high = mid - 1 elif A[mid] == A[mid + 1]: low = mid + 1 else: high = mid return A[low]
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR RETURN VAR VAR
Given a sorted array A[] of N positive integers having all the numbers occurring exactly twice, except for one number which will occur only once. Find the number occurring only once. Example 1: Input: N = 5 A = {1, 1, 2, 5, 5} Output: 2 Explanation: Since 2 occurs once, while other numbers occur twice, 2 is the answer. Example 2: Input: N = 7 A = {2, 2, 5, 5, 20, 30, 30} Output: 20 Explanation: Since 20 occurs once, while other numbers occur twice, 20 is the answer. Your Task: You don't need to read input or print anything. Your task is to complete the function search() which takes two arguments(array A and integer N) and returns the number occurring only once. Expected Time Complexity: O(Log(N)). Expected Auxiliary Space: O(1). Constraints 0 < N <= 10^6 0 <= A[i] <= 10^9
class Solution: def search(self, A, N): sum = 0 sum1 = 0 for i in range(0, N): sum += A[i] s = set(A) for i in s: sum1 += i res = 2 * sum1 - sum return res
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR RETURN VAR
Given a sorted array A[] of N positive integers having all the numbers occurring exactly twice, except for one number which will occur only once. Find the number occurring only once. Example 1: Input: N = 5 A = {1, 1, 2, 5, 5} Output: 2 Explanation: Since 2 occurs once, while other numbers occur twice, 2 is the answer. Example 2: Input: N = 7 A = {2, 2, 5, 5, 20, 30, 30} Output: 20 Explanation: Since 20 occurs once, while other numbers occur twice, 20 is the answer. Your Task: You don't need to read input or print anything. Your task is to complete the function search() which takes two arguments(array A and integer N) and returns the number occurring only once. Expected Time Complexity: O(Log(N)). Expected Auxiliary Space: O(1). Constraints 0 < N <= 10^6 0 <= A[i] <= 10^9
class Solution: def search(self, A, N): for i in range(0, N, 2): if i == N - 1: return A[i] if A[i] != A[i + 1]: return A[i] return 0
CLASS_DEF FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER RETURN VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER RETURN VAR VAR RETURN NUMBER
Given a sorted array A[] of N positive integers having all the numbers occurring exactly twice, except for one number which will occur only once. Find the number occurring only once. Example 1: Input: N = 5 A = {1, 1, 2, 5, 5} Output: 2 Explanation: Since 2 occurs once, while other numbers occur twice, 2 is the answer. Example 2: Input: N = 7 A = {2, 2, 5, 5, 20, 30, 30} Output: 20 Explanation: Since 20 occurs once, while other numbers occur twice, 20 is the answer. Your Task: You don't need to read input or print anything. Your task is to complete the function search() which takes two arguments(array A and integer N) and returns the number occurring only once. Expected Time Complexity: O(Log(N)). Expected Auxiliary Space: O(1). Constraints 0 < N <= 10^6 0 <= A[i] <= 10^9
class Solution: def search(self, A, N): i = 0 while i < N - 1: if A[i] == A[i + 1]: i += 2 else: return A[i] return A[-1]
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR VAR RETURN VAR NUMBER
Given a sorted array A[] of N positive integers having all the numbers occurring exactly twice, except for one number which will occur only once. Find the number occurring only once. Example 1: Input: N = 5 A = {1, 1, 2, 5, 5} Output: 2 Explanation: Since 2 occurs once, while other numbers occur twice, 2 is the answer. Example 2: Input: N = 7 A = {2, 2, 5, 5, 20, 30, 30} Output: 20 Explanation: Since 20 occurs once, while other numbers occur twice, 20 is the answer. Your Task: You don't need to read input or print anything. Your task is to complete the function search() which takes two arguments(array A and integer N) and returns the number occurring only once. Expected Time Complexity: O(Log(N)). Expected Auxiliary Space: O(1). Constraints 0 < N <= 10^6 0 <= A[i] <= 10^9
class Solution: def search(self, A, N): start = 0 end = N - 1 while start < end: mid = (end + start) // 2 if mid % 2 == 1: mid -= 1 if A[mid] == A[mid + 1]: start = mid + 2 else: end = mid return A[start]
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR RETURN VAR VAR
Given a sorted array A[] of N positive integers having all the numbers occurring exactly twice, except for one number which will occur only once. Find the number occurring only once. Example 1: Input: N = 5 A = {1, 1, 2, 5, 5} Output: 2 Explanation: Since 2 occurs once, while other numbers occur twice, 2 is the answer. Example 2: Input: N = 7 A = {2, 2, 5, 5, 20, 30, 30} Output: 20 Explanation: Since 20 occurs once, while other numbers occur twice, 20 is the answer. Your Task: You don't need to read input or print anything. Your task is to complete the function search() which takes two arguments(array A and integer N) and returns the number occurring only once. Expected Time Complexity: O(Log(N)). Expected Auxiliary Space: O(1). Constraints 0 < N <= 10^6 0 <= A[i] <= 10^9
class Solution: def search(self, nums, N): index = 0 while index < N: if index + 1 < N and nums[index] == nums[index + 1]: index += 2 else: break return nums[index]
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER WHILE VAR VAR IF BIN_OP VAR NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR VAR
Given a sorted array A[] of N positive integers having all the numbers occurring exactly twice, except for one number which will occur only once. Find the number occurring only once. Example 1: Input: N = 5 A = {1, 1, 2, 5, 5} Output: 2 Explanation: Since 2 occurs once, while other numbers occur twice, 2 is the answer. Example 2: Input: N = 7 A = {2, 2, 5, 5, 20, 30, 30} Output: 20 Explanation: Since 20 occurs once, while other numbers occur twice, 20 is the answer. Your Task: You don't need to read input or print anything. Your task is to complete the function search() which takes two arguments(array A and integer N) and returns the number occurring only once. Expected Time Complexity: O(Log(N)). Expected Auxiliary Space: O(1). Constraints 0 < N <= 10^6 0 <= A[i] <= 10^9
class Solution: def search(self, A, N): d = {} for i in A: if i not in d: d[i] = 1 else: d[i] += 1 k = [[d[i], i] for i in d] k.sort() if k[0][0] == 1: return k[0][1]
CLASS_DEF FUNC_DEF ASSIGN VAR DICT FOR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR LIST VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR IF VAR NUMBER NUMBER NUMBER RETURN VAR NUMBER NUMBER
Given a sorted array A[] of N positive integers having all the numbers occurring exactly twice, except for one number which will occur only once. Find the number occurring only once. Example 1: Input: N = 5 A = {1, 1, 2, 5, 5} Output: 2 Explanation: Since 2 occurs once, while other numbers occur twice, 2 is the answer. Example 2: Input: N = 7 A = {2, 2, 5, 5, 20, 30, 30} Output: 20 Explanation: Since 20 occurs once, while other numbers occur twice, 20 is the answer. Your Task: You don't need to read input or print anything. Your task is to complete the function search() which takes two arguments(array A and integer N) and returns the number occurring only once. Expected Time Complexity: O(Log(N)). Expected Auxiliary Space: O(1). Constraints 0 < N <= 10^6 0 <= A[i] <= 10^9
class Solution: def search(self, A, N): l = 0 h = N - 1 while l <= h: mid = (h + l) // 2 if A.count(A[mid]) == 1: return A[mid] elif A[mid] == A[mid - 1] and mid % 2 == 0: h = mid - 1 elif A[mid] == A[mid - 1] and mid % 2 != 0: l = mid + 1 elif A[mid] == A[mid + 1] and mid % 2 != 0: h = mid - 1 elif A[mid] == A[mid + 1] and mid % 2 == 0: l = mid + 1
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR NUMBER RETURN VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER
Given a sorted array A[] of N positive integers having all the numbers occurring exactly twice, except for one number which will occur only once. Find the number occurring only once. Example 1: Input: N = 5 A = {1, 1, 2, 5, 5} Output: 2 Explanation: Since 2 occurs once, while other numbers occur twice, 2 is the answer. Example 2: Input: N = 7 A = {2, 2, 5, 5, 20, 30, 30} Output: 20 Explanation: Since 20 occurs once, while other numbers occur twice, 20 is the answer. Your Task: You don't need to read input or print anything. Your task is to complete the function search() which takes two arguments(array A and integer N) and returns the number occurring only once. Expected Time Complexity: O(Log(N)). Expected Auxiliary Space: O(1). Constraints 0 < N <= 10^6 0 <= A[i] <= 10^9
class Solution: def search(self, A, N): ans = [] for i in range(0, N): if A[i] not in ans: ans.append(A[i]) else: ans.remove(A[i]) return ans[0]
CLASS_DEF FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR RETURN VAR NUMBER
Given a sorted array A[] of N positive integers having all the numbers occurring exactly twice, except for one number which will occur only once. Find the number occurring only once. Example 1: Input: N = 5 A = {1, 1, 2, 5, 5} Output: 2 Explanation: Since 2 occurs once, while other numbers occur twice, 2 is the answer. Example 2: Input: N = 7 A = {2, 2, 5, 5, 20, 30, 30} Output: 20 Explanation: Since 20 occurs once, while other numbers occur twice, 20 is the answer. Your Task: You don't need to read input or print anything. Your task is to complete the function search() which takes two arguments(array A and integer N) and returns the number occurring only once. Expected Time Complexity: O(Log(N)). Expected Auxiliary Space: O(1). Constraints 0 < N <= 10^6 0 <= A[i] <= 10^9
class Solution: def search(self, A, N): count = {} for i in A: if i in count.keys(): count[i] = count[i] + 1 else: count[i] = 1 for key, value in count.items(): if value == 1: return key
CLASS_DEF FUNC_DEF ASSIGN VAR DICT FOR VAR VAR IF VAR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR VAR FUNC_CALL VAR IF VAR NUMBER RETURN VAR
Given a sorted array A[] of N positive integers having all the numbers occurring exactly twice, except for one number which will occur only once. Find the number occurring only once. Example 1: Input: N = 5 A = {1, 1, 2, 5, 5} Output: 2 Explanation: Since 2 occurs once, while other numbers occur twice, 2 is the answer. Example 2: Input: N = 7 A = {2, 2, 5, 5, 20, 30, 30} Output: 20 Explanation: Since 20 occurs once, while other numbers occur twice, 20 is the answer. Your Task: You don't need to read input or print anything. Your task is to complete the function search() which takes two arguments(array A and integer N) and returns the number occurring only once. Expected Time Complexity: O(Log(N)). Expected Auxiliary Space: O(1). Constraints 0 < N <= 10^6 0 <= A[i] <= 10^9
class Solution: def search(self, A, N): n = len(A) if n == 1: return A[0] count = {} for i in range(n): count[A[i]] = 1 + count.get(A[i], 0) for key, value in count.items(): if value == 1: return key
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER RETURN VAR NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP NUMBER FUNC_CALL VAR VAR VAR NUMBER FOR VAR VAR FUNC_CALL VAR IF VAR NUMBER RETURN VAR
Given a sorted array A[] of N positive integers having all the numbers occurring exactly twice, except for one number which will occur only once. Find the number occurring only once. Example 1: Input: N = 5 A = {1, 1, 2, 5, 5} Output: 2 Explanation: Since 2 occurs once, while other numbers occur twice, 2 is the answer. Example 2: Input: N = 7 A = {2, 2, 5, 5, 20, 30, 30} Output: 20 Explanation: Since 20 occurs once, while other numbers occur twice, 20 is the answer. Your Task: You don't need to read input or print anything. Your task is to complete the function search() which takes two arguments(array A and integer N) and returns the number occurring only once. Expected Time Complexity: O(Log(N)). Expected Auxiliary Space: O(1). Constraints 0 < N <= 10^6 0 <= A[i] <= 10^9
class Solution: def search(self, A, N): i = 0 while i < N - 1: if arr[i] != arr[i - 1] and arr[i] != arr[i + 1]: return arr[i] i += 1 return arr[N - 1]
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER RETURN VAR VAR VAR NUMBER RETURN VAR BIN_OP VAR NUMBER
Given a sorted array A[] of N positive integers having all the numbers occurring exactly twice, except for one number which will occur only once. Find the number occurring only once. Example 1: Input: N = 5 A = {1, 1, 2, 5, 5} Output: 2 Explanation: Since 2 occurs once, while other numbers occur twice, 2 is the answer. Example 2: Input: N = 7 A = {2, 2, 5, 5, 20, 30, 30} Output: 20 Explanation: Since 20 occurs once, while other numbers occur twice, 20 is the answer. Your Task: You don't need to read input or print anything. Your task is to complete the function search() which takes two arguments(array A and integer N) and returns the number occurring only once. Expected Time Complexity: O(Log(N)). Expected Auxiliary Space: O(1). Constraints 0 < N <= 10^6 0 <= A[i] <= 10^9
class Solution: def search(self, A, N): d = {} ans = -1 maxi = 0 for i in A: if i in d: d[i] += 1 else: d[i] = 1 for i in d: if d[i] == 1: return i else: return -1
CLASS_DEF FUNC_DEF ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR VAR IF VAR VAR NUMBER RETURN VAR RETURN NUMBER
Given a sorted array A[] of N positive integers having all the numbers occurring exactly twice, except for one number which will occur only once. Find the number occurring only once. Example 1: Input: N = 5 A = {1, 1, 2, 5, 5} Output: 2 Explanation: Since 2 occurs once, while other numbers occur twice, 2 is the answer. Example 2: Input: N = 7 A = {2, 2, 5, 5, 20, 30, 30} Output: 20 Explanation: Since 20 occurs once, while other numbers occur twice, 20 is the answer. Your Task: You don't need to read input or print anything. Your task is to complete the function search() which takes two arguments(array A and integer N) and returns the number occurring only once. Expected Time Complexity: O(Log(N)). Expected Auxiliary Space: O(1). Constraints 0 < N <= 10^6 0 <= A[i] <= 10^9
class Solution: def search(self, A, N): left = 0 right = N - 1 while left < right: mid = (left + right) // 2 if mid % 2 != 0: if A[mid] != A[mid - 1] and A[mid] != A[mid + 1]: return A[mid] elif A[mid] != A[mid - 1]: right = mid - 1 else: left = mid + 1 elif A[mid] != A[mid - 1] and A[mid] != A[mid + 1]: return A[mid] elif A[mid] != A[mid - 1]: left = mid + 1 else: right = mid - 1 return A[left]
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER RETURN VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER RETURN VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR VAR
Given a sorted array A[] of N positive integers having all the numbers occurring exactly twice, except for one number which will occur only once. Find the number occurring only once. Example 1: Input: N = 5 A = {1, 1, 2, 5, 5} Output: 2 Explanation: Since 2 occurs once, while other numbers occur twice, 2 is the answer. Example 2: Input: N = 7 A = {2, 2, 5, 5, 20, 30, 30} Output: 20 Explanation: Since 20 occurs once, while other numbers occur twice, 20 is the answer. Your Task: You don't need to read input or print anything. Your task is to complete the function search() which takes two arguments(array A and integer N) and returns the number occurring only once. Expected Time Complexity: O(Log(N)). Expected Auxiliary Space: O(1). Constraints 0 < N <= 10^6 0 <= A[i] <= 10^9
class Solution: def search(self, A, N): i = 0 j = 1 c = 0 if N == 1 or A[i] != A[j]: return A[i] if A[N - 1] != A[N - 2]: return A[N - 1] while j < N: if A[i] == A[j]: i += 1 j += 1 c = 0 else: c += 1 if c == 2: ans = A[i] break i += 1 j += 1 return ans
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR VAR VAR VAR RETURN VAR VAR IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER RETURN VAR BIN_OP VAR NUMBER WHILE VAR VAR IF VAR VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER VAR NUMBER RETURN VAR
Given a sorted array A[] of N positive integers having all the numbers occurring exactly twice, except for one number which will occur only once. Find the number occurring only once. Example 1: Input: N = 5 A = {1, 1, 2, 5, 5} Output: 2 Explanation: Since 2 occurs once, while other numbers occur twice, 2 is the answer. Example 2: Input: N = 7 A = {2, 2, 5, 5, 20, 30, 30} Output: 20 Explanation: Since 20 occurs once, while other numbers occur twice, 20 is the answer. Your Task: You don't need to read input or print anything. Your task is to complete the function search() which takes two arguments(array A and integer N) and returns the number occurring only once. Expected Time Complexity: O(Log(N)). Expected Auxiliary Space: O(1). Constraints 0 < N <= 10^6 0 <= A[i] <= 10^9
class Solution: def search(self, A, N): l, r = 0, N - 1 while l <= r: mid = l + (r - l) // 2 if mid % 2 == 0: if mid < N - 1 and A[mid] == A[mid + 1]: l = mid + 2 elif mid > 0 and A[mid] == A[mid - 1]: r = mid - 2 else: return A[mid] elif mid > 0 and A[mid] == A[mid - 1]: l = mid + 1 elif mid < N - 1 and A[mid] == A[mid + 1]: r = mid - 1 else: return A[mid]
CLASS_DEF FUNC_DEF ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR VAR IF VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR VAR
Given a sorted array A[] of N positive integers having all the numbers occurring exactly twice, except for one number which will occur only once. Find the number occurring only once. Example 1: Input: N = 5 A = {1, 1, 2, 5, 5} Output: 2 Explanation: Since 2 occurs once, while other numbers occur twice, 2 is the answer. Example 2: Input: N = 7 A = {2, 2, 5, 5, 20, 30, 30} Output: 20 Explanation: Since 20 occurs once, while other numbers occur twice, 20 is the answer. Your Task: You don't need to read input or print anything. Your task is to complete the function search() which takes two arguments(array A and integer N) and returns the number occurring only once. Expected Time Complexity: O(Log(N)). Expected Auxiliary Space: O(1). Constraints 0 < N <= 10^6 0 <= A[i] <= 10^9
class Solution: def search(self, A, N): j = {} u = [] e = list(set(A)) for x in e: j[x] = 0 for x in A: j[x] = j[x] + 1 for x in e: if j[x] != 2: return x break
CLASS_DEF FUNC_DEF ASSIGN VAR DICT ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR ASSIGN VAR VAR NUMBER FOR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR NUMBER FOR VAR VAR IF VAR VAR NUMBER RETURN VAR
Given a sorted array A[] of N positive integers having all the numbers occurring exactly twice, except for one number which will occur only once. Find the number occurring only once. Example 1: Input: N = 5 A = {1, 1, 2, 5, 5} Output: 2 Explanation: Since 2 occurs once, while other numbers occur twice, 2 is the answer. Example 2: Input: N = 7 A = {2, 2, 5, 5, 20, 30, 30} Output: 20 Explanation: Since 20 occurs once, while other numbers occur twice, 20 is the answer. Your Task: You don't need to read input or print anything. Your task is to complete the function search() which takes two arguments(array A and integer N) and returns the number occurring only once. Expected Time Complexity: O(Log(N)). Expected Auxiliary Space: O(1). Constraints 0 < N <= 10^6 0 <= A[i] <= 10^9
class Solution: def search(self, A, N): d = {} for i in A: if i not in d: d[i] = 1 else: d[i] = d[i] + 1 for key, value in d.items(): if d[key] == 1: return key
CLASS_DEF FUNC_DEF ASSIGN VAR DICT FOR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER FOR VAR VAR FUNC_CALL VAR IF VAR VAR NUMBER RETURN VAR
This problem is same as the next one, but has smaller constraints. It was a Sunday morning when the three friends Selena, Shiro and Katie decided to have a trip to the nearby power station (do not try this at home). After arriving at the power station, the cats got impressed with a large power transmission system consisting of many chimneys, electric poles, and wires. Since they are cats, they found those things gigantic. At the entrance of the station, there is a map describing the complicated wiring system. Selena is the best at math among three friends. He decided to draw the map on the Cartesian plane. Each pole is now a point at some coordinates $(x_i, y_i)$. Since every pole is different, all of the points representing these poles are distinct. Also, every two poles are connected with each other by wires. A wire is a straight line on the plane infinite in both directions. If there are more than two poles lying on the same line, they are connected by a single common wire. Selena thinks, that whenever two different electric wires intersect, they may interfere with each other and cause damage. So he wonders, how many pairs are intersecting? Could you help him with this problem? -----Input----- The first line contains a single integer $n$ ($2 \le n \le 50$)Β β€” the number of electric poles. Each of the following $n$ lines contains two integers $x_i$, $y_i$ ($-10^4 \le x_i, y_i \le 10^4$)Β β€” the coordinates of the poles. It is guaranteed that all of these $n$ points are distinct. -----Output----- Print a single integerΒ β€” the number of pairs of wires that are intersecting. -----Examples----- Input 4 0 0 1 1 0 3 1 2 Output 14 Input 4 0 0 0 2 0 4 2 0 Output 6 Input 3 -1 -1 1 0 3 1 Output 0 -----Note----- In the first example: [Image] In the second example: [Image] Note that the three poles $(0, 0)$, $(0, 2)$ and $(0, 4)$ are connected by a single wire. In the third example: [Image]
from sys import maxsize n = int(input()) p = [] for i in range(n): w = list(map(int, input().split())) p.append(w) p.sort() s = {} for i in range(n): x1, y1 = p[i] for j in range(i + 1, n): x2, y2 = p[j] k = 0 b = 0 if x1 - x2 == 0: k = maxsize b = x1 else: k = (y2 - y1) / (x2 - x1) b = (y1 * x2 - x1 * y2) / (x2 - x1) if k in s: if b in s[k]: s[k][b] += 1 else: s[k][b] = 1 else: s[k] = {b: 1} ans = 0 cnt = 0 for i in s: ans += cnt * len(s[i]) cnt += len(s[i]) print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR IF VAR VAR IF VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR DICT VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR BIN_OP VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
This problem is same as the next one, but has smaller constraints. It was a Sunday morning when the three friends Selena, Shiro and Katie decided to have a trip to the nearby power station (do not try this at home). After arriving at the power station, the cats got impressed with a large power transmission system consisting of many chimneys, electric poles, and wires. Since they are cats, they found those things gigantic. At the entrance of the station, there is a map describing the complicated wiring system. Selena is the best at math among three friends. He decided to draw the map on the Cartesian plane. Each pole is now a point at some coordinates $(x_i, y_i)$. Since every pole is different, all of the points representing these poles are distinct. Also, every two poles are connected with each other by wires. A wire is a straight line on the plane infinite in both directions. If there are more than two poles lying on the same line, they are connected by a single common wire. Selena thinks, that whenever two different electric wires intersect, they may interfere with each other and cause damage. So he wonders, how many pairs are intersecting? Could you help him with this problem? -----Input----- The first line contains a single integer $n$ ($2 \le n \le 50$)Β β€” the number of electric poles. Each of the following $n$ lines contains two integers $x_i$, $y_i$ ($-10^4 \le x_i, y_i \le 10^4$)Β β€” the coordinates of the poles. It is guaranteed that all of these $n$ points are distinct. -----Output----- Print a single integerΒ β€” the number of pairs of wires that are intersecting. -----Examples----- Input 4 0 0 1 1 0 3 1 2 Output 14 Input 4 0 0 0 2 0 4 2 0 Output 6 Input 3 -1 -1 1 0 3 1 Output 0 -----Note----- In the first example: [Image] In the second example: [Image] Note that the three poles $(0, 0)$, $(0, 2)$ and $(0, 4)$ are connected by a single wire. In the third example: [Image]
n = int(input()) def gcd(a, b): if a == 0: return b return gcd(b % a, a) points = [] lines = set() counter = 0 for i in range(n): a = [int(x) for x in input().split()] points.append(a) for item in points: for elem in points: if item != elem: g = gcd(item[1] - elem[1], item[0] - elem[0]) k = ( (item[1] - elem[1]) // g, (item[0] - elem[0]) // g, (item[1] * elem[0] - elem[1] * item[0]) // g, ) if k[0] < 0 or k[0] == 0 and k[1] < 0: k = -k[0], -k[1] lines.add(k) lines = sorted(lines) lines.append((10**100, 10**100)) x = len(lines) counter = 1 answer = (x - 1) * (x - 2) // 2 for i in range(1, x): if lines[i][0] == lines[i - 1][0] and lines[i][1] == lines[i - 1][1]: counter += 1 else: answer -= counter * (counter - 1) // 2 counter = 1 print(answer)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF IF VAR NUMBER RETURN VAR RETURN FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR FOR VAR VAR FOR VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER VAR IF VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR
This problem is same as the next one, but has smaller constraints. It was a Sunday morning when the three friends Selena, Shiro and Katie decided to have a trip to the nearby power station (do not try this at home). After arriving at the power station, the cats got impressed with a large power transmission system consisting of many chimneys, electric poles, and wires. Since they are cats, they found those things gigantic. At the entrance of the station, there is a map describing the complicated wiring system. Selena is the best at math among three friends. He decided to draw the map on the Cartesian plane. Each pole is now a point at some coordinates $(x_i, y_i)$. Since every pole is different, all of the points representing these poles are distinct. Also, every two poles are connected with each other by wires. A wire is a straight line on the plane infinite in both directions. If there are more than two poles lying on the same line, they are connected by a single common wire. Selena thinks, that whenever two different electric wires intersect, they may interfere with each other and cause damage. So he wonders, how many pairs are intersecting? Could you help him with this problem? -----Input----- The first line contains a single integer $n$ ($2 \le n \le 50$)Β β€” the number of electric poles. Each of the following $n$ lines contains two integers $x_i$, $y_i$ ($-10^4 \le x_i, y_i \le 10^4$)Β β€” the coordinates of the poles. It is guaranteed that all of these $n$ points are distinct. -----Output----- Print a single integerΒ β€” the number of pairs of wires that are intersecting. -----Examples----- Input 4 0 0 1 1 0 3 1 2 Output 14 Input 4 0 0 0 2 0 4 2 0 Output 6 Input 3 -1 -1 1 0 3 1 Output 0 -----Note----- In the first example: [Image] In the second example: [Image] Note that the three poles $(0, 0)$, $(0, 2)$ and $(0, 4)$ are connected by a single wire. In the third example: [Image]
lines = set() points = [] num = int(input()) for i in range(num): points.append([int(j) for j in input().split()]) for i in range(num): for j in range(i): dx = points[j][0] - points[i][0] if dx == 0: lines.add((378597736461, points[i][0])) else: m = (points[j][1] - points[i][1]) / dx lines.add( (int(100000000 * m), int(100000000 * (points[i][1] - m * points[i][0]))) ) ms = {} for l in lines: if l[0] in ms: ms[l[0]] += 1 else: ms[l[0]] = 1 total = 0 t = list(ms.values()) s = sum(t) for a in t: total += a * (s - a) print(total // 2)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP NUMBER VAR FUNC_CALL VAR BIN_OP NUMBER BIN_OP VAR VAR NUMBER BIN_OP VAR VAR VAR NUMBER ASSIGN VAR DICT FOR VAR VAR IF VAR NUMBER VAR VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR VAR BIN_OP VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
This problem is same as the next one, but has smaller constraints. It was a Sunday morning when the three friends Selena, Shiro and Katie decided to have a trip to the nearby power station (do not try this at home). After arriving at the power station, the cats got impressed with a large power transmission system consisting of many chimneys, electric poles, and wires. Since they are cats, they found those things gigantic. At the entrance of the station, there is a map describing the complicated wiring system. Selena is the best at math among three friends. He decided to draw the map on the Cartesian plane. Each pole is now a point at some coordinates $(x_i, y_i)$. Since every pole is different, all of the points representing these poles are distinct. Also, every two poles are connected with each other by wires. A wire is a straight line on the plane infinite in both directions. If there are more than two poles lying on the same line, they are connected by a single common wire. Selena thinks, that whenever two different electric wires intersect, they may interfere with each other and cause damage. So he wonders, how many pairs are intersecting? Could you help him with this problem? -----Input----- The first line contains a single integer $n$ ($2 \le n \le 50$)Β β€” the number of electric poles. Each of the following $n$ lines contains two integers $x_i$, $y_i$ ($-10^4 \le x_i, y_i \le 10^4$)Β β€” the coordinates of the poles. It is guaranteed that all of these $n$ points are distinct. -----Output----- Print a single integerΒ β€” the number of pairs of wires that are intersecting. -----Examples----- Input 4 0 0 1 1 0 3 1 2 Output 14 Input 4 0 0 0 2 0 4 2 0 Output 6 Input 3 -1 -1 1 0 3 1 Output 0 -----Note----- In the first example: [Image] In the second example: [Image] Note that the three poles $(0, 0)$, $(0, 2)$ and $(0, 4)$ are connected by a single wire. In the third example: [Image]
def gcd(a, b): while b: a, b = b, a % b return a n = int(input()) p = [0] * n for i in range(n): p[i] = [int(item) for item in input().split()] wires = set() for i in range(n): for j in range(i + 1, n): x0, y0 = p[i] x1, y1 = p[j] a = -(y1 - y0) b = x1 - x0 c = x0 * (y1 - y0) - y0 * (x1 - x0) k = gcd(a, gcd(b, c)) a //= k b //= k c //= k if a < 0: a *= -1 b *= -1 c *= -1 wires.add((a, b, c)) wires = list(wires) ans = 0 for i in range(len(wires)): for j in range(i + 1, len(wires)): a1, b1, c1 = wires[i] a2, b2, c2 = wires[j] if b1 == 0: if b2 != 0: ans += 1 elif b2 == 0: ans += 1 elif abs(a1 / b1 - a2 / b2) > 1e-07: ans += 1 print(ans)
FUNC_DEF WHILE VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR BIN_OP VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR IF VAR NUMBER IF VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER IF FUNC_CALL VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
This problem is same as the next one, but has smaller constraints. It was a Sunday morning when the three friends Selena, Shiro and Katie decided to have a trip to the nearby power station (do not try this at home). After arriving at the power station, the cats got impressed with a large power transmission system consisting of many chimneys, electric poles, and wires. Since they are cats, they found those things gigantic. At the entrance of the station, there is a map describing the complicated wiring system. Selena is the best at math among three friends. He decided to draw the map on the Cartesian plane. Each pole is now a point at some coordinates $(x_i, y_i)$. Since every pole is different, all of the points representing these poles are distinct. Also, every two poles are connected with each other by wires. A wire is a straight line on the plane infinite in both directions. If there are more than two poles lying on the same line, they are connected by a single common wire. Selena thinks, that whenever two different electric wires intersect, they may interfere with each other and cause damage. So he wonders, how many pairs are intersecting? Could you help him with this problem? -----Input----- The first line contains a single integer $n$ ($2 \le n \le 50$)Β β€” the number of electric poles. Each of the following $n$ lines contains two integers $x_i$, $y_i$ ($-10^4 \le x_i, y_i \le 10^4$)Β β€” the coordinates of the poles. It is guaranteed that all of these $n$ points are distinct. -----Output----- Print a single integerΒ β€” the number of pairs of wires that are intersecting. -----Examples----- Input 4 0 0 1 1 0 3 1 2 Output 14 Input 4 0 0 0 2 0 4 2 0 Output 6 Input 3 -1 -1 1 0 3 1 Output 0 -----Note----- In the first example: [Image] In the second example: [Image] Note that the three poles $(0, 0)$, $(0, 2)$ and $(0, 4)$ are connected by a single wire. In the third example: [Image]
from itertools import combinations n = int(input()) points = [] for _ in range(n): x, y = map(int, input().split(" ")) points.append((x, y)) directions = {} for pair in combinations(points, 2): (x1, y1), (x2, y2) = pair if x1 == x2: dir = 0, 1 b = x1 else: dir = 1, (y2 - y1) / (x2 - x1) b = (y2 * x1 - x2 * y1) / (x1 - x2) if dir in directions: directions[dir].add(b) else: directions[dir] = set([b]) total_lines = sum(len(value) for key, value in directions.items()) result = 0 for key, value in directions.items(): current = len(value) result += (total_lines - current) * current print(int(result / 2))
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 STRING EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR LIST VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER
This problem is same as the next one, but has smaller constraints. It was a Sunday morning when the three friends Selena, Shiro and Katie decided to have a trip to the nearby power station (do not try this at home). After arriving at the power station, the cats got impressed with a large power transmission system consisting of many chimneys, electric poles, and wires. Since they are cats, they found those things gigantic. At the entrance of the station, there is a map describing the complicated wiring system. Selena is the best at math among three friends. He decided to draw the map on the Cartesian plane. Each pole is now a point at some coordinates $(x_i, y_i)$. Since every pole is different, all of the points representing these poles are distinct. Also, every two poles are connected with each other by wires. A wire is a straight line on the plane infinite in both directions. If there are more than two poles lying on the same line, they are connected by a single common wire. Selena thinks, that whenever two different electric wires intersect, they may interfere with each other and cause damage. So he wonders, how many pairs are intersecting? Could you help him with this problem? -----Input----- The first line contains a single integer $n$ ($2 \le n \le 50$)Β β€” the number of electric poles. Each of the following $n$ lines contains two integers $x_i$, $y_i$ ($-10^4 \le x_i, y_i \le 10^4$)Β β€” the coordinates of the poles. It is guaranteed that all of these $n$ points are distinct. -----Output----- Print a single integerΒ β€” the number of pairs of wires that are intersecting. -----Examples----- Input 4 0 0 1 1 0 3 1 2 Output 14 Input 4 0 0 0 2 0 4 2 0 Output 6 Input 3 -1 -1 1 0 3 1 Output 0 -----Note----- In the first example: [Image] In the second example: [Image] Note that the three poles $(0, 0)$, $(0, 2)$ and $(0, 4)$ are connected by a single wire. In the third example: [Image]
n = int(input()) T = [] P = [] for i in range(n): x, y = map(int, input().split()) T.append([x, y]) for i in range(n): for j in range(i + 1, n): x1, y1 = T[i] x2, y2 = T[j] a = y2 - y1 b = x1 - x2 c = -(a * x1 + b * y1) if a != 0: b /= a c /= a a = 1 else: a = 0 c /= b b = 1 P.append([a, b, c]) P.sort() newp = [P[0]] for i in range(len(P) - 1): if P[i] != P[i + 1]: newp.append(P[i + 1]) P = newp sos = dict() for a, b, c in P: if b != 0 and a != 0: z = a / b elif a == 0: z = "kek" else: z = "lol" if z not in sos: sos[z] = 1 else: sos[z] += 1 sus = 0 sussqua = 0 for i in sos: sus += sos[i] sussqua += sos[i] ** 2 print((sus**2 - sussqua) // 2)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR LIST VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR IF VAR NUMBER VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR LIST VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR STRING ASSIGN VAR STRING IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER
This problem is same as the next one, but has smaller constraints. It was a Sunday morning when the three friends Selena, Shiro and Katie decided to have a trip to the nearby power station (do not try this at home). After arriving at the power station, the cats got impressed with a large power transmission system consisting of many chimneys, electric poles, and wires. Since they are cats, they found those things gigantic. At the entrance of the station, there is a map describing the complicated wiring system. Selena is the best at math among three friends. He decided to draw the map on the Cartesian plane. Each pole is now a point at some coordinates $(x_i, y_i)$. Since every pole is different, all of the points representing these poles are distinct. Also, every two poles are connected with each other by wires. A wire is a straight line on the plane infinite in both directions. If there are more than two poles lying on the same line, they are connected by a single common wire. Selena thinks, that whenever two different electric wires intersect, they may interfere with each other and cause damage. So he wonders, how many pairs are intersecting? Could you help him with this problem? -----Input----- The first line contains a single integer $n$ ($2 \le n \le 50$)Β β€” the number of electric poles. Each of the following $n$ lines contains two integers $x_i$, $y_i$ ($-10^4 \le x_i, y_i \le 10^4$)Β β€” the coordinates of the poles. It is guaranteed that all of these $n$ points are distinct. -----Output----- Print a single integerΒ β€” the number of pairs of wires that are intersecting. -----Examples----- Input 4 0 0 1 1 0 3 1 2 Output 14 Input 4 0 0 0 2 0 4 2 0 Output 6 Input 3 -1 -1 1 0 3 1 Output 0 -----Note----- In the first example: [Image] In the second example: [Image] Note that the three poles $(0, 0)$, $(0, 2)$ and $(0, 4)$ are connected by a single wire. In the third example: [Image]
n = int(input()) ls = set() pts = [] for i in range(n): x, y = map(int, input().split()) pts.append([x, y]) for i in range(n): for j in range(i + 1, n): x1 = pts[i][0] y1 = pts[i][1] x2 = pts[j][0] y2 = pts[j][1] m = (y2 - y1) / (x2 - x1) if x2 != x1 else "I" c = (x2 * y1 - x1 * y2) / (x2 - x1) if x1 != x2 else x1 ls.add((m, c)) ins = set() ls = list(ls) nls = len(ls) for i in range(nls): for j in range(i + 1, nls): m1 = ls[i][0] m2 = ls[j][0] if m1 != m2: x = [i, j] x.sort() ins.add(tuple(x)) print(len(ins))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN 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 EXPR FUNC_CALL VAR LIST VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR STRING ASSIGN VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR LIST VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
This problem is same as the next one, but has smaller constraints. It was a Sunday morning when the three friends Selena, Shiro and Katie decided to have a trip to the nearby power station (do not try this at home). After arriving at the power station, the cats got impressed with a large power transmission system consisting of many chimneys, electric poles, and wires. Since they are cats, they found those things gigantic. At the entrance of the station, there is a map describing the complicated wiring system. Selena is the best at math among three friends. He decided to draw the map on the Cartesian plane. Each pole is now a point at some coordinates $(x_i, y_i)$. Since every pole is different, all of the points representing these poles are distinct. Also, every two poles are connected with each other by wires. A wire is a straight line on the plane infinite in both directions. If there are more than two poles lying on the same line, they are connected by a single common wire. Selena thinks, that whenever two different electric wires intersect, they may interfere with each other and cause damage. So he wonders, how many pairs are intersecting? Could you help him with this problem? -----Input----- The first line contains a single integer $n$ ($2 \le n \le 50$)Β β€” the number of electric poles. Each of the following $n$ lines contains two integers $x_i$, $y_i$ ($-10^4 \le x_i, y_i \le 10^4$)Β β€” the coordinates of the poles. It is guaranteed that all of these $n$ points are distinct. -----Output----- Print a single integerΒ β€” the number of pairs of wires that are intersecting. -----Examples----- Input 4 0 0 1 1 0 3 1 2 Output 14 Input 4 0 0 0 2 0 4 2 0 Output 6 Input 3 -1 -1 1 0 3 1 Output 0 -----Note----- In the first example: [Image] In the second example: [Image] Note that the three poles $(0, 0)$, $(0, 2)$ and $(0, 4)$ are connected by a single wire. In the third example: [Image]
n = int(input()) x = [(0) for i in range(0, n + 1)] y = [(0) for i in range(0, n + 1)] for i in range(1, n + 1): x[i], y[i] = map(int, input().split()) di = {} for i in range(1, n + 1): a = {} for j in range(i + 1, n + 1): if x[j] - x[i] == 0: if "0" not in a: a["0"] = 1 else: a["0"] = a["0"] + 1 else: k = (y[j] - y[i]) / (x[j] - x[i]) if k not in a: a[k] = 1 else: a[k] = a[k] + 1 for key, value in a.items(): if value > 1: continue if key in di: di[key] = di[key] + 1 else: di[key] = 1 b = [] for v in di.values(): b.append(v) b.sort() _sum = 0 for i in b: _sum += i ans = 0 for i in b: ans += i * (_sum - i) _sum -= i print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR VAR NUMBER IF STRING VAR ASSIGN VAR STRING NUMBER ASSIGN VAR STRING BIN_OP VAR STRING NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER FOR VAR VAR FUNC_CALL VAR IF VAR NUMBER IF VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR VAR BIN_OP VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
This problem is same as the next one, but has smaller constraints. It was a Sunday morning when the three friends Selena, Shiro and Katie decided to have a trip to the nearby power station (do not try this at home). After arriving at the power station, the cats got impressed with a large power transmission system consisting of many chimneys, electric poles, and wires. Since they are cats, they found those things gigantic. At the entrance of the station, there is a map describing the complicated wiring system. Selena is the best at math among three friends. He decided to draw the map on the Cartesian plane. Each pole is now a point at some coordinates $(x_i, y_i)$. Since every pole is different, all of the points representing these poles are distinct. Also, every two poles are connected with each other by wires. A wire is a straight line on the plane infinite in both directions. If there are more than two poles lying on the same line, they are connected by a single common wire. Selena thinks, that whenever two different electric wires intersect, they may interfere with each other and cause damage. So he wonders, how many pairs are intersecting? Could you help him with this problem? -----Input----- The first line contains a single integer $n$ ($2 \le n \le 50$)Β β€” the number of electric poles. Each of the following $n$ lines contains two integers $x_i$, $y_i$ ($-10^4 \le x_i, y_i \le 10^4$)Β β€” the coordinates of the poles. It is guaranteed that all of these $n$ points are distinct. -----Output----- Print a single integerΒ β€” the number of pairs of wires that are intersecting. -----Examples----- Input 4 0 0 1 1 0 3 1 2 Output 14 Input 4 0 0 0 2 0 4 2 0 Output 6 Input 3 -1 -1 1 0 3 1 Output 0 -----Note----- In the first example: [Image] In the second example: [Image] Note that the three poles $(0, 0)$, $(0, 2)$ and $(0, 4)$ are connected by a single wire. In the third example: [Image]
n = int(input()) p = [] for i in range(n): x, y = map(int, input().split()) p.append((x, y)) d = {} for i in range(n): x1, y1 = p[i] for j in range(i + 1, n): x2, y2 = p[j] if x1 != x2: m = (y2 - y1) / (x2 - x1) c = (y1 * x2 - x1 * y2) / (x2 - x1) else: m = 10**10 c = x1 if m in d: if c in d[m]: d[m][c] += 1 else: d[m][c] = 1 else: d[m] = {c: 1} p = [] for m in d: p.append(len(d[m])) s = sum(p) ans = 0 for i in range(len(p)): ans += p[i] * (s - p[i]) print(ans // 2)
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 EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR VAR IF VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR VAR IF VAR VAR IF VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR DICT VAR NUMBER ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
This problem is same as the next one, but has smaller constraints. It was a Sunday morning when the three friends Selena, Shiro and Katie decided to have a trip to the nearby power station (do not try this at home). After arriving at the power station, the cats got impressed with a large power transmission system consisting of many chimneys, electric poles, and wires. Since they are cats, they found those things gigantic. At the entrance of the station, there is a map describing the complicated wiring system. Selena is the best at math among three friends. He decided to draw the map on the Cartesian plane. Each pole is now a point at some coordinates $(x_i, y_i)$. Since every pole is different, all of the points representing these poles are distinct. Also, every two poles are connected with each other by wires. A wire is a straight line on the plane infinite in both directions. If there are more than two poles lying on the same line, they are connected by a single common wire. Selena thinks, that whenever two different electric wires intersect, they may interfere with each other and cause damage. So he wonders, how many pairs are intersecting? Could you help him with this problem? -----Input----- The first line contains a single integer $n$ ($2 \le n \le 50$)Β β€” the number of electric poles. Each of the following $n$ lines contains two integers $x_i$, $y_i$ ($-10^4 \le x_i, y_i \le 10^4$)Β β€” the coordinates of the poles. It is guaranteed that all of these $n$ points are distinct. -----Output----- Print a single integerΒ β€” the number of pairs of wires that are intersecting. -----Examples----- Input 4 0 0 1 1 0 3 1 2 Output 14 Input 4 0 0 0 2 0 4 2 0 Output 6 Input 3 -1 -1 1 0 3 1 Output 0 -----Note----- In the first example: [Image] In the second example: [Image] Note that the three poles $(0, 0)$, $(0, 2)$ and $(0, 4)$ are connected by a single wire. In the third example: [Image]
import sys input = sys.stdin.readline n = int(input()) W = [list(map(int, input().split())) for i in range(n)] SET = set() def gcd(a, b): while b: a, b = b, a % b return a def point(a, b, c, d): g = gcd(c - a, d - b) K = [(c - a) // g, (d - b) // g] if K == [0, 1]: SET.add(tuple(K + [a])) else: SET.add(tuple(K + [((d - b) * -a + (c - a) * b) / (c - a)])) for i in range(n - 1): a, b = W[i] for j in range(i + 1, n): if i == j: continue c, d = W[j] point(a, b, c, d) LIST = list(SET) ANS = 0 for i in range(len(LIST) - 1): NOW0, NOW1 = LIST[i][0], LIST[i][1] for j in range(i + 1, len(LIST)): if NOW0 != LIST[j][0] or NOW1 != LIST[j][1]: ANS += 1 print(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 VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_DEF WHILE VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR LIST BIN_OP BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR IF VAR LIST NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR LIST VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR LIST BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR ASSIGN VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
This problem is same as the next one, but has smaller constraints. It was a Sunday morning when the three friends Selena, Shiro and Katie decided to have a trip to the nearby power station (do not try this at home). After arriving at the power station, the cats got impressed with a large power transmission system consisting of many chimneys, electric poles, and wires. Since they are cats, they found those things gigantic. At the entrance of the station, there is a map describing the complicated wiring system. Selena is the best at math among three friends. He decided to draw the map on the Cartesian plane. Each pole is now a point at some coordinates $(x_i, y_i)$. Since every pole is different, all of the points representing these poles are distinct. Also, every two poles are connected with each other by wires. A wire is a straight line on the plane infinite in both directions. If there are more than two poles lying on the same line, they are connected by a single common wire. Selena thinks, that whenever two different electric wires intersect, they may interfere with each other and cause damage. So he wonders, how many pairs are intersecting? Could you help him with this problem? -----Input----- The first line contains a single integer $n$ ($2 \le n \le 50$)Β β€” the number of electric poles. Each of the following $n$ lines contains two integers $x_i$, $y_i$ ($-10^4 \le x_i, y_i \le 10^4$)Β β€” the coordinates of the poles. It is guaranteed that all of these $n$ points are distinct. -----Output----- Print a single integerΒ β€” the number of pairs of wires that are intersecting. -----Examples----- Input 4 0 0 1 1 0 3 1 2 Output 14 Input 4 0 0 0 2 0 4 2 0 Output 6 Input 3 -1 -1 1 0 3 1 Output 0 -----Note----- In the first example: [Image] In the second example: [Image] Note that the three poles $(0, 0)$, $(0, 2)$ and $(0, 4)$ are connected by a single wire. In the third example: [Image]
n = int(input()) x = [] y = [] lineas = set() lineas1 = set() lineas2 = set() caca = dict() def gcd(a, b): if b == 0: return a return gcd(b, a % b) for i in range(n): a, b = map(int, input().split()) x.append(a) y.append(b) for j in range(i): a1 = a - x[j] b1 = b - y[j] p1 = max(abs(a1), abs(b1)) p2 = min(abs(a1), abs(b1)) g = gcd(p1, p2) a1 = int(a1 / g) b1 = int(b1 / g) if a1 < 0: a1 *= -1 b1 *= -1 aux = b * a1 - a * b1 if a1 == 0: lineas1.add(a) elif b1 == 0: lineas2.add(b) else: if (a1, b1) in caca: caca[a1, b1].add(aux) else: caca[a1, b1] = set() caca[a1, b1].add(aux) lineas.add((a1, b1, aux)) sol = 0 aux = len(lineas) sol += int(aux * (aux - 1) / 2) sol += aux * (len(lineas1) + len(lineas2)) sol += len(lineas1) * len(lineas2) for a in caca.keys(): aux = len(caca[a]) sol -= int(aux * (aux - 1) / 2) print(sol)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_DEF IF VAR NUMBER RETURN VAR RETURN FUNC_CALL VAR VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR IF VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR
This problem is same as the next one, but has smaller constraints. It was a Sunday morning when the three friends Selena, Shiro and Katie decided to have a trip to the nearby power station (do not try this at home). After arriving at the power station, the cats got impressed with a large power transmission system consisting of many chimneys, electric poles, and wires. Since they are cats, they found those things gigantic. At the entrance of the station, there is a map describing the complicated wiring system. Selena is the best at math among three friends. He decided to draw the map on the Cartesian plane. Each pole is now a point at some coordinates $(x_i, y_i)$. Since every pole is different, all of the points representing these poles are distinct. Also, every two poles are connected with each other by wires. A wire is a straight line on the plane infinite in both directions. If there are more than two poles lying on the same line, they are connected by a single common wire. Selena thinks, that whenever two different electric wires intersect, they may interfere with each other and cause damage. So he wonders, how many pairs are intersecting? Could you help him with this problem? -----Input----- The first line contains a single integer $n$ ($2 \le n \le 50$)Β β€” the number of electric poles. Each of the following $n$ lines contains two integers $x_i$, $y_i$ ($-10^4 \le x_i, y_i \le 10^4$)Β β€” the coordinates of the poles. It is guaranteed that all of these $n$ points are distinct. -----Output----- Print a single integerΒ β€” the number of pairs of wires that are intersecting. -----Examples----- Input 4 0 0 1 1 0 3 1 2 Output 14 Input 4 0 0 0 2 0 4 2 0 Output 6 Input 3 -1 -1 1 0 3 1 Output 0 -----Note----- In the first example: [Image] In the second example: [Image] Note that the three poles $(0, 0)$, $(0, 2)$ and $(0, 4)$ are connected by a single wire. In the third example: [Image]
def gcd(a, b): while b: a, b = b, a % b return a n = int(input()) p = [0] * n for i in range(n): p[i] = [int(item) for item in input().split()] wires = set() for i in range(n): for j in range(i + 1, n): x0, y0 = p[i] x1, y1 = p[j] a = -(y1 - y0) b = x1 - x0 c = x0 * (y1 - y0) - y0 * (x1 - x0) k = gcd(a, gcd(b, c)) a //= k b //= k c //= k if a < 0: a *= -1 b *= -1 c *= -1 wires.add((a, b, c)) wires = list(wires) para_x = [] para_y = [] others = {} for i in range(len(wires)): a, b, c = wires[i] if b == 0: para_y.append(i) elif a == 0: para_x.append(i) else: k = gcd(a, b) if (a // k, b // k) in others: others[a // k, b // k] += 1 else: others[a // k, b // k] = 1 px = len(para_x) py = len(para_y) o = sum(others[x] for x in others) ans = px * py + px * o + py * o others_list = [others[x] for x in others] pre = [0] * (len(others_list) + 1) for i in range(len(others_list)): pre[i] = pre[i - 1] + others_list[i] for i in range(len(others_list) - 1, 0, -1): ans += others_list[i] * pre[i - 1] print(ans)
FUNC_DEF WHILE VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR BIN_OP VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR DICT FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF BIN_OP VAR VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
This problem is same as the next one, but has smaller constraints. It was a Sunday morning when the three friends Selena, Shiro and Katie decided to have a trip to the nearby power station (do not try this at home). After arriving at the power station, the cats got impressed with a large power transmission system consisting of many chimneys, electric poles, and wires. Since they are cats, they found those things gigantic. At the entrance of the station, there is a map describing the complicated wiring system. Selena is the best at math among three friends. He decided to draw the map on the Cartesian plane. Each pole is now a point at some coordinates $(x_i, y_i)$. Since every pole is different, all of the points representing these poles are distinct. Also, every two poles are connected with each other by wires. A wire is a straight line on the plane infinite in both directions. If there are more than two poles lying on the same line, they are connected by a single common wire. Selena thinks, that whenever two different electric wires intersect, they may interfere with each other and cause damage. So he wonders, how many pairs are intersecting? Could you help him with this problem? -----Input----- The first line contains a single integer $n$ ($2 \le n \le 50$)Β β€” the number of electric poles. Each of the following $n$ lines contains two integers $x_i$, $y_i$ ($-10^4 \le x_i, y_i \le 10^4$)Β β€” the coordinates of the poles. It is guaranteed that all of these $n$ points are distinct. -----Output----- Print a single integerΒ β€” the number of pairs of wires that are intersecting. -----Examples----- Input 4 0 0 1 1 0 3 1 2 Output 14 Input 4 0 0 0 2 0 4 2 0 Output 6 Input 3 -1 -1 1 0 3 1 Output 0 -----Note----- In the first example: [Image] In the second example: [Image] Note that the three poles $(0, 0)$, $(0, 2)$ and $(0, 4)$ are connected by a single wire. In the third example: [Image]
n = int(input()) def gcd(x, y): while y > 0: x, y = y, x % y return x poles = [] for i in range(n): x, y = list(map(int, input().split())) poles.append((x, y)) lines = set() for i in range(len(poles) - 1): for j in range(i + 1, len(poles)): p1 = poles[i] p2 = poles[j] a = p1[1] - p2[1] b = -p1[0] + p2[0] abg = gcd(abs(a), abs(b)) if abg > 0: a //= abg b //= abg if a < 0: a = -a b = -b if a == 0: b = 1 if b == 0: a = 1 c = -a * p1[0] - b * p1[1] lines.add((a, b, c)) cnt = 0 for i, line1 in enumerate(lines): for j, line2 in enumerate(lines): if i >= j: continue if line1[:2] != line2[:2]: cnt += 1 print(cnt)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF WHILE VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR VAR RETURN 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 FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR IF VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
This problem is same as the next one, but has smaller constraints. It was a Sunday morning when the three friends Selena, Shiro and Katie decided to have a trip to the nearby power station (do not try this at home). After arriving at the power station, the cats got impressed with a large power transmission system consisting of many chimneys, electric poles, and wires. Since they are cats, they found those things gigantic. At the entrance of the station, there is a map describing the complicated wiring system. Selena is the best at math among three friends. He decided to draw the map on the Cartesian plane. Each pole is now a point at some coordinates $(x_i, y_i)$. Since every pole is different, all of the points representing these poles are distinct. Also, every two poles are connected with each other by wires. A wire is a straight line on the plane infinite in both directions. If there are more than two poles lying on the same line, they are connected by a single common wire. Selena thinks, that whenever two different electric wires intersect, they may interfere with each other and cause damage. So he wonders, how many pairs are intersecting? Could you help him with this problem? -----Input----- The first line contains a single integer $n$ ($2 \le n \le 50$)Β β€” the number of electric poles. Each of the following $n$ lines contains two integers $x_i$, $y_i$ ($-10^4 \le x_i, y_i \le 10^4$)Β β€” the coordinates of the poles. It is guaranteed that all of these $n$ points are distinct. -----Output----- Print a single integerΒ β€” the number of pairs of wires that are intersecting. -----Examples----- Input 4 0 0 1 1 0 3 1 2 Output 14 Input 4 0 0 0 2 0 4 2 0 Output 6 Input 3 -1 -1 1 0 3 1 Output 0 -----Note----- In the first example: [Image] In the second example: [Image] Note that the three poles $(0, 0)$, $(0, 2)$ and $(0, 4)$ are connected by a single wire. In the third example: [Image]
def pos_gcd(a, b): if a == 0 and b == 0: return 1 if b == 0: return a return pos_gcd(b, a % b) def gcd2(a, b): return pos_gcd(abs(a), abs(b)) def gcd(a, b, c): return gcd2(gcd2(a, b), c) def make_line(p1, p2): a = p2[1] - p1[1] b = p1[0] - p2[0] c = -a * p1[0] - b * p1[1] d = gcd(a, b, c) a //= d b //= d c //= d if a < 0: a = -a b = -b c = -c elif a == 0 and b < 0: b = -b c = -c return a, b, c def parallel(l1, l2): return l1[0] == l2[0] and l1[1] == l2[1] n = int(input()) pointlist = [] lineset = set() for i in range(n): p = tuple(map(int, input().split(" "))) for q in pointlist: lineset.add(make_line(p, q)) pointlist.append(p) linelist = list(lineset) ans = 0 for i in range(len(linelist)): for j in range(i): if not parallel(linelist[i], linelist[j]): ans += 1 print(ans)
FUNC_DEF IF VAR NUMBER VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN VAR RETURN FUNC_CALL VAR VAR BIN_OP VAR VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR RETURN VAR VAR VAR FUNC_DEF RETURN VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
This problem is same as the next one, but has smaller constraints. It was a Sunday morning when the three friends Selena, Shiro and Katie decided to have a trip to the nearby power station (do not try this at home). After arriving at the power station, the cats got impressed with a large power transmission system consisting of many chimneys, electric poles, and wires. Since they are cats, they found those things gigantic. At the entrance of the station, there is a map describing the complicated wiring system. Selena is the best at math among three friends. He decided to draw the map on the Cartesian plane. Each pole is now a point at some coordinates $(x_i, y_i)$. Since every pole is different, all of the points representing these poles are distinct. Also, every two poles are connected with each other by wires. A wire is a straight line on the plane infinite in both directions. If there are more than two poles lying on the same line, they are connected by a single common wire. Selena thinks, that whenever two different electric wires intersect, they may interfere with each other and cause damage. So he wonders, how many pairs are intersecting? Could you help him with this problem? -----Input----- The first line contains a single integer $n$ ($2 \le n \le 50$)Β β€” the number of electric poles. Each of the following $n$ lines contains two integers $x_i$, $y_i$ ($-10^4 \le x_i, y_i \le 10^4$)Β β€” the coordinates of the poles. It is guaranteed that all of these $n$ points are distinct. -----Output----- Print a single integerΒ β€” the number of pairs of wires that are intersecting. -----Examples----- Input 4 0 0 1 1 0 3 1 2 Output 14 Input 4 0 0 0 2 0 4 2 0 Output 6 Input 3 -1 -1 1 0 3 1 Output 0 -----Note----- In the first example: [Image] In the second example: [Image] Note that the three poles $(0, 0)$, $(0, 2)$ and $(0, 4)$ are connected by a single wire. In the third example: [Image]
def get_k(a, b): x1, y1 = a x2, y2 = b if x2 != x1: return (y2 - y1) / (x2 - x1) return 10**10 def get_offset(a, k2): x, y = a return y - k2 * x cnt = 0 a = [] n = int(input()) for i in range(n): a.append(tuple(map(int, input().split()))) alines = [] for i in range(n): for j in range(n): if i >= j: continue alines.append((a[i], a[j])) lines = [] s = set() for i, l1 in enumerate(alines): for j in range(i + 1, len(alines)): l2 = alines[j] k1, k2 = get_k(*l1), get_k(*l2) o1, o2 = get_offset(l1[0], k1), get_offset(l2[0], k2) if k1 == k2 == 10**10 and l1[0][0] == l2[0][0]: o1 = o2 = 0 if ( abs(k1 - k2) < 1e-10 and abs(o1 - o2) < 1e-10 or k1 == k2 == 10**10 and l1[0] == l2[0] ): s.add(j) if i not in s: lines.append(l1) for i, l1 in enumerate(lines): for j, l2 in enumerate(lines): if i >= j: continue if abs(get_k(*l1) - get_k(*l2)) > 1e-10: cnt += 1 print(cnt)
FUNC_DEF ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR IF VAR VAR RETURN BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR RETURN BIN_OP NUMBER NUMBER FUNC_DEF ASSIGN VAR VAR VAR RETURN BIN_OP VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FOR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER VAR IF VAR VAR BIN_OP NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER IF FUNC_CALL VAR BIN_OP VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR VAR BIN_OP NUMBER NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR IF FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
This problem is same as the next one, but has smaller constraints. It was a Sunday morning when the three friends Selena, Shiro and Katie decided to have a trip to the nearby power station (do not try this at home). After arriving at the power station, the cats got impressed with a large power transmission system consisting of many chimneys, electric poles, and wires. Since they are cats, they found those things gigantic. At the entrance of the station, there is a map describing the complicated wiring system. Selena is the best at math among three friends. He decided to draw the map on the Cartesian plane. Each pole is now a point at some coordinates $(x_i, y_i)$. Since every pole is different, all of the points representing these poles are distinct. Also, every two poles are connected with each other by wires. A wire is a straight line on the plane infinite in both directions. If there are more than two poles lying on the same line, they are connected by a single common wire. Selena thinks, that whenever two different electric wires intersect, they may interfere with each other and cause damage. So he wonders, how many pairs are intersecting? Could you help him with this problem? -----Input----- The first line contains a single integer $n$ ($2 \le n \le 50$)Β β€” the number of electric poles. Each of the following $n$ lines contains two integers $x_i$, $y_i$ ($-10^4 \le x_i, y_i \le 10^4$)Β β€” the coordinates of the poles. It is guaranteed that all of these $n$ points are distinct. -----Output----- Print a single integerΒ β€” the number of pairs of wires that are intersecting. -----Examples----- Input 4 0 0 1 1 0 3 1 2 Output 14 Input 4 0 0 0 2 0 4 2 0 Output 6 Input 3 -1 -1 1 0 3 1 Output 0 -----Note----- In the first example: [Image] In the second example: [Image] Note that the three poles $(0, 0)$, $(0, 2)$ and $(0, 4)$ are connected by a single wire. In the third example: [Image]
n = int(input()) T = [] for i in range(n): x, y = map(int, input().split()) T.append([x, y]) P = [] for i in range(n): for j in range(i + 1, n): x1, y1 = T[i] x2, y2 = T[j] a = y2 - y1 b = x1 - x2 c = -(a * x1 + b * y1) P.append([a, b, c]) const = 10**10 + 3 cnt = 0 newP = [] visit = [] for a, b, c in P: if a != 0: if [1, b / a, c / a] not in visit: newP.append([1, b / a, c / a]) visit.append([1, b / a, c / a]) elif [0, 1, c / b] not in visit: newP.append([0, 1, c / b]) visit.append([0, 1, c / b]) P = newP for i in range(len(P)): for j in range(i + 1, len(P)): a1, b1, c1 = P[i] a2, b2, c2 = P[j] if a1 * b2 == a2 * b1: pass else: x = (b1 * c2 - b2 * c1) / (a1 * b2 - b1 * a2) y = (c1 * a2 - a1 * c2) / (a1 * b2 - b1 * a2) cnt += 1 print(cnt)
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 EXPR FUNC_CALL VAR LIST VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR VAR VAR IF VAR NUMBER IF LIST NUMBER BIN_OP VAR VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR LIST NUMBER BIN_OP VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR LIST NUMBER BIN_OP VAR VAR BIN_OP VAR VAR IF LIST NUMBER NUMBER BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR LIST NUMBER NUMBER BIN_OP VAR VAR EXPR FUNC_CALL VAR LIST NUMBER NUMBER BIN_OP VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR IF BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
This problem is same as the next one, but has smaller constraints. It was a Sunday morning when the three friends Selena, Shiro and Katie decided to have a trip to the nearby power station (do not try this at home). After arriving at the power station, the cats got impressed with a large power transmission system consisting of many chimneys, electric poles, and wires. Since they are cats, they found those things gigantic. At the entrance of the station, there is a map describing the complicated wiring system. Selena is the best at math among three friends. He decided to draw the map on the Cartesian plane. Each pole is now a point at some coordinates $(x_i, y_i)$. Since every pole is different, all of the points representing these poles are distinct. Also, every two poles are connected with each other by wires. A wire is a straight line on the plane infinite in both directions. If there are more than two poles lying on the same line, they are connected by a single common wire. Selena thinks, that whenever two different electric wires intersect, they may interfere with each other and cause damage. So he wonders, how many pairs are intersecting? Could you help him with this problem? -----Input----- The first line contains a single integer $n$ ($2 \le n \le 50$)Β β€” the number of electric poles. Each of the following $n$ lines contains two integers $x_i$, $y_i$ ($-10^4 \le x_i, y_i \le 10^4$)Β β€” the coordinates of the poles. It is guaranteed that all of these $n$ points are distinct. -----Output----- Print a single integerΒ β€” the number of pairs of wires that are intersecting. -----Examples----- Input 4 0 0 1 1 0 3 1 2 Output 14 Input 4 0 0 0 2 0 4 2 0 Output 6 Input 3 -1 -1 1 0 3 1 Output 0 -----Note----- In the first example: [Image] In the second example: [Image] Note that the three poles $(0, 0)$, $(0, 2)$ and $(0, 4)$ are connected by a single wire. In the third example: [Image]
n = int(input()) coords = [] for i in range(n): coords.append(tuple(map(int, input().split()))) slopes = {} for i in range(n): for j in range(i + 1, n): x1, y1 = coords[i][0], coords[i][1] x2, y2 = coords[j][0], coords[j][1] if x1 == x2: slope = "inf" mark = x1 else: slope = round((y2 - y1) / (x2 - x1), 12) mark = round(y1 - x1 * slope, 7) if slope in slopes: slopes[slope].add(mark) else: slopes[slope] = {mark} tot = sum(len(slopes[guy]) for guy in slopes) sumi = 0 for guy in slopes: a = len(slopes[guy]) sumi += a * (tot - a) print(sumi // 2)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER VAR VAR NUMBER IF VAR VAR ASSIGN VAR STRING ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
This problem is same as the next one, but has smaller constraints. It was a Sunday morning when the three friends Selena, Shiro and Katie decided to have a trip to the nearby power station (do not try this at home). After arriving at the power station, the cats got impressed with a large power transmission system consisting of many chimneys, electric poles, and wires. Since they are cats, they found those things gigantic. At the entrance of the station, there is a map describing the complicated wiring system. Selena is the best at math among three friends. He decided to draw the map on the Cartesian plane. Each pole is now a point at some coordinates $(x_i, y_i)$. Since every pole is different, all of the points representing these poles are distinct. Also, every two poles are connected with each other by wires. A wire is a straight line on the plane infinite in both directions. If there are more than two poles lying on the same line, they are connected by a single common wire. Selena thinks, that whenever two different electric wires intersect, they may interfere with each other and cause damage. So he wonders, how many pairs are intersecting? Could you help him with this problem? -----Input----- The first line contains a single integer $n$ ($2 \le n \le 50$)Β β€” the number of electric poles. Each of the following $n$ lines contains two integers $x_i$, $y_i$ ($-10^4 \le x_i, y_i \le 10^4$)Β β€” the coordinates of the poles. It is guaranteed that all of these $n$ points are distinct. -----Output----- Print a single integerΒ β€” the number of pairs of wires that are intersecting. -----Examples----- Input 4 0 0 1 1 0 3 1 2 Output 14 Input 4 0 0 0 2 0 4 2 0 Output 6 Input 3 -1 -1 1 0 3 1 Output 0 -----Note----- In the first example: [Image] In the second example: [Image] Note that the three poles $(0, 0)$, $(0, 2)$ and $(0, 4)$ are connected by a single wire. In the third example: [Image]
coord = [] coef = {} a = b = 0 v = {} coef_a = {} n = int(input()) for i in range(n): coord.append(list(map(float, input().split()))) for i in range(n): x1, y1 = coord[i] for j in range(i + 1, n): x2, y2 = coord[j] if x2 - x1: a = (y2 - y1) / (x2 - x1) b = (y1 * x2 - y2 * x1) / (x2 - x1) coef[a, b] = coef.get((a, b), 0) + 1 coef_a[a] = coef_a.get(a, 0) + 1 if coef[a, b] > 1: coef[a, b] -= 1 coef_a[a] -= 1 else: v[x2] = 1 v_nmbr = sum(v.values()) coe = list(coef_a.values()) for i in range(len(coe)): coe[i] = coe[i] * (coe[i] - 1) // 2 l_par = sum(coe) l_nmbr = len(coef) + v_nmbr ans = l_nmbr * (l_nmbr - 1) // 2 - v_nmbr * (v_nmbr - 1) // 2 - l_par print(ans)
ASSIGN VAR LIST ASSIGN VAR DICT ASSIGN VAR VAR NUMBER ASSIGN VAR DICT ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR VAR IF BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER IF VAR VAR VAR NUMBER VAR VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR VAR
This problem is same as the next one, but has smaller constraints. It was a Sunday morning when the three friends Selena, Shiro and Katie decided to have a trip to the nearby power station (do not try this at home). After arriving at the power station, the cats got impressed with a large power transmission system consisting of many chimneys, electric poles, and wires. Since they are cats, they found those things gigantic. At the entrance of the station, there is a map describing the complicated wiring system. Selena is the best at math among three friends. He decided to draw the map on the Cartesian plane. Each pole is now a point at some coordinates $(x_i, y_i)$. Since every pole is different, all of the points representing these poles are distinct. Also, every two poles are connected with each other by wires. A wire is a straight line on the plane infinite in both directions. If there are more than two poles lying on the same line, they are connected by a single common wire. Selena thinks, that whenever two different electric wires intersect, they may interfere with each other and cause damage. So he wonders, how many pairs are intersecting? Could you help him with this problem? -----Input----- The first line contains a single integer $n$ ($2 \le n \le 50$)Β β€” the number of electric poles. Each of the following $n$ lines contains two integers $x_i$, $y_i$ ($-10^4 \le x_i, y_i \le 10^4$)Β β€” the coordinates of the poles. It is guaranteed that all of these $n$ points are distinct. -----Output----- Print a single integerΒ β€” the number of pairs of wires that are intersecting. -----Examples----- Input 4 0 0 1 1 0 3 1 2 Output 14 Input 4 0 0 0 2 0 4 2 0 Output 6 Input 3 -1 -1 1 0 3 1 Output 0 -----Note----- In the first example: [Image] In the second example: [Image] Note that the three poles $(0, 0)$, $(0, 2)$ and $(0, 4)$ are connected by a single wire. In the third example: [Image]
def gcd(x, y): while y: x, y = y, x % y return x def frac(a, b): x = gcd(a, b) return a // x, b // x n = int(input()) coords = [] for i in range(n): coords.append(tuple(map(int, input().split()))) slopes = {} for i in range(n): for j in range(i + 1, n): x1, y1 = coords[i][0], coords[i][1] x2, y2 = coords[j][0], coords[j][1] if x1 == x2: slope = "inf" mark = x1 else: slope = frac(y2 - y1, x2 - x1) mark = frac(y1 * x2 - y2 * x1, x2 - x1) if slope in slopes: slopes[slope].add(mark) else: slopes[slope] = {mark} tot = sum(len(slopes[guy]) for guy in slopes) sumi = 0 for guy in slopes: a = len(slopes[guy]) sumi += a * (tot - a) print(sumi // 2)
FUNC_DEF WHILE VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER VAR VAR NUMBER IF VAR VAR ASSIGN VAR STRING ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
A correct expression of the form a+b=c was written; a, b and c are non-negative integers without leading zeros. In this expression, the plus and equally signs were lost. The task is to restore the expression. In other words, one character '+' and one character '=' should be inserted into given sequence of digits so that: character'+' is placed on the left of character '=', characters '+' and '=' split the sequence into three non-empty subsequences consisting of digits (let's call the left part a, the middle partΒ β€” b and the right partΒ β€” c), all the three parts a, b and c do not contain leading zeros, it is true that a+b=c. It is guaranteed that in given tests answer always exists. -----Input----- The first line contains a non-empty string consisting of digits. The length of the string does not exceed 10^6. -----Output----- Output the restored expression. If there are several solutions, you can print any of them. Note that the answer at first should contain two terms (divided with symbol '+'), and then the result of their addition, before which symbol'=' should be. Do not separate numbers and operation signs with spaces. Strictly follow the output format given in the examples. If you remove symbol '+' and symbol '=' from answer string you should get a string, same as string from the input data. -----Examples----- Input 12345168 Output 123+45=168 Input 099 Output 0+9=9 Input 199100 Output 1+99=100 Input 123123123456456456579579579 Output 123123123+456456456=579579579
def modgroup(M=10**9 + 7, invn=0): exec( f"""class mod{M} : inv = [None] * {invn + 1} if {invn + 1} >= 2 : inv[1] = 1 for i in range(2, {invn + 1}) : inv[i] = (({M} - {M}//i) * inv[{M}%i]) %{M} def __init__(self, n = 0) : self.n = n % {M} __repr__ = lambda self : str(self.n) + '%{M}' __int__ = lambda self : self.n __eq__ = lambda a,b : int(a)%{M} == int(b)%{M} __add__ = lambda a,b : __class__(a.n + int(b)) __sub__ = lambda a,b : __class__(a.n - int(b)) __mul__ = lambda a,b : __class__(a.n * int(b)) __radd__ = lambda a,b : __class__(b + a.n) __rsub__ = lambda a,b : __class__(b - a.n) __rmul__ = lambda a,b : __class__(b * a.n) def __pow__(a,b) : a, ret = int(a), 1 while b : if b & 1 : ret = (ret * a) % {M} a = (a * a) % {M} b >>= 1 return __class__(ret) def __truediv__(a,b) : return __class__(a.n * __class__.__pow__(b, {M - 2})) def __floordiv__(a,b) : return __class__(a.n * __class__.inv[b]) """ ) return eval(f"mod{M}") def solution(): s = input() l = len(s) mod = modgroup() num = [mod(0)] * (l + 1) shift = [mod(1)] * (l + 1) for i, x in enumerate(s, 1): num[i] = num[i - 1] * 10 + int(x) shift[i] = shift[i - 1] * 10 def mod_check(la, lb, lc): a, b, c = num[la], num[la + lb], num[la + lb + lc] c -= b * shift[lc] b -= a * shift[lb] return a + b == c for lc in range(l // 3 + bool(l % 3), l // 2 + 1): for lb in (lc, lc - 1, l - lc * 2, l - lc * 2 + 1): la = l - lc - lb if la < 1 or lb < 1 or lc < 1: continue if la > lc or lb > lc: continue if not mod_check(la, lb, lc): continue print(f"{s[:la]}+{s[la:la + lb]}={s[la + lb:la + lb + lc]}") return solution()
FUNC_DEF BIN_OP BIN_OP NUMBER NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR STRING VAR STRING BIN_OP VAR NUMBER STRING BIN_OP VAR NUMBER STRING BIN_OP VAR NUMBER STRING VAR STRING VAR STRING VAR STRING VAR STRING VAR STRING VAR STRING VAR STRING VAR STRING VAR STRING VAR STRING BIN_OP VAR NUMBER STRING RETURN FUNC_CALL VAR STRING VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER FUNC_DEF ASSIGN VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR RETURN BIN_OP VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER FOR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR IF VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR IF FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING VAR VAR BIN_OP VAR VAR STRING VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR VAR RETURN EXPR FUNC_CALL VAR
The flag of Berland is such rectangular field n Γ— m that satisfies following conditions: Flag consists of three colors which correspond to letters 'R', 'G' and 'B'. Flag consists of three equal in width and height stripes, parralel to each other and to sides of the flag. Each stripe has exactly one color. Each color should be used in exactly one stripe. You are given a field n Γ— m, consisting of characters 'R', 'G' and 'B'. Output "YES" (without quotes) if this field corresponds to correct flag of Berland. Otherwise, print "NO" (without quotes). -----Input----- The first line contains two integer numbers n and m (1 ≀ n, m ≀ 100) β€” the sizes of the field. Each of the following n lines consisting of m characters 'R', 'G' and 'B' β€” the description of the field. -----Output----- Print "YES" (without quotes) if the given field corresponds to correct flag of Berland . Otherwise, print "NO" (without quotes). -----Examples----- Input 6 5 RRRRR RRRRR BBBBB BBBBB GGGGG GGGGG Output YES Input 4 3 BRG BRG BRG BRG Output YES Input 6 7 RRRGGGG RRRGGGG RRRGGGG RRRBBBB RRRBBBB RRRBBBB Output NO Input 4 4 RRRR RRRR BBBB GGGG Output NO -----Note----- The field in the third example doesn't have three parralel stripes. Rows of the field in the fourth example are parralel to each other and to borders. But they have different heights β€” 2, 1 and 1.
n, m = map(int, input().split()) ll = [] for i in range(n): ll.append(input()) if n % 3 == 0 or m % 3 == 0: l1 = ll[0][0] l2 = ll[n // 3][0] l3 = ll[2 * (n // 3)][0] t = False if l1 != l2 and l2 != l3 and l1 != l3 and n % 3 == 0: t = True for i in range(n): for j in range(m): if 0 <= i < n // 3: if ll[i][j] != l1: t = False break elif n // 3 <= i < 2 * (n // 3): if ll[i][j] != l2: t = False break elif ll[i][j] != l3: t = False break if t == False: break if t == False and m % 3 == 0: l2 = ll[0][m // 3] l3 = ll[0][2 * (m // 3)] if l1 != l2 and l2 != l3 and l1 != l3: t = True for i in range(m): for j in range(n): if 0 <= i < m // 3: if ll[j][i] != l1: t = False break elif m // 3 <= i < 2 * (m // 3): if ll[j][i] != l2: t = False break elif ll[j][i] != l3: t = False break if t == False: break print("YES" if t == True else "NO") else: print("NO")
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER IF VAR VAR VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF NUMBER VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER VAR BIN_OP NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER IF VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF NUMBER VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER VAR BIN_OP NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER STRING STRING EXPR FUNC_CALL VAR STRING
The flag of Berland is such rectangular field n Γ— m that satisfies following conditions: Flag consists of three colors which correspond to letters 'R', 'G' and 'B'. Flag consists of three equal in width and height stripes, parralel to each other and to sides of the flag. Each stripe has exactly one color. Each color should be used in exactly one stripe. You are given a field n Γ— m, consisting of characters 'R', 'G' and 'B'. Output "YES" (without quotes) if this field corresponds to correct flag of Berland. Otherwise, print "NO" (without quotes). -----Input----- The first line contains two integer numbers n and m (1 ≀ n, m ≀ 100) β€” the sizes of the field. Each of the following n lines consisting of m characters 'R', 'G' and 'B' β€” the description of the field. -----Output----- Print "YES" (without quotes) if the given field corresponds to correct flag of Berland . Otherwise, print "NO" (without quotes). -----Examples----- Input 6 5 RRRRR RRRRR BBBBB BBBBB GGGGG GGGGG Output YES Input 4 3 BRG BRG BRG BRG Output YES Input 6 7 RRRGGGG RRRGGGG RRRGGGG RRRBBBB RRRBBBB RRRBBBB Output NO Input 4 4 RRRR RRRR BBBB GGGG Output NO -----Note----- The field in the third example doesn't have three parralel stripes. Rows of the field in the fourth example are parralel to each other and to borders. But they have different heights β€” 2, 1 and 1.
def fn(s): ans = True for i in range(len(s) - 1): if s[i] != s[i + 1]: ans = False return ans def chk(n, m, l): if n % 3 != 0: return False w = n // 3 ls = [] ans = True for i in range(0, 3): s = "" for j in range(i * w, i * w + w): s += l[j] ls.append(s) for i in range(3): ans = ans and fn(ls[i]) return ans and ls[0] != ls[1] and ls[1] != ls[2] and ls[0] != ls[2] n, m = map(int, input().strip().split()) l = [] for i in range(n): l.append(str(input())) if n % 3 != 0: x = "v" elif m % 3 != 0: x = "h" else: x = "h" for i in range(m - 1): if l[0][i] != l[0][i + 1]: x = "v" if x == "h": flag = chk(n, m, l) elif x == "v": ls = [] for i in range(m): s = "" for j in range(n): s += l[j][i] ls.append(s) flag = chk(m, n, ls) if flag: print("YES") else: print("NO")
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER RETURN VAR FUNC_DEF IF BIN_OP VAR NUMBER NUMBER RETURN NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR RETURN VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR STRING IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR STRING ASSIGN VAR STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR STRING IF VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR STRING ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
The flag of Berland is such rectangular field n Γ— m that satisfies following conditions: Flag consists of three colors which correspond to letters 'R', 'G' and 'B'. Flag consists of three equal in width and height stripes, parralel to each other and to sides of the flag. Each stripe has exactly one color. Each color should be used in exactly one stripe. You are given a field n Γ— m, consisting of characters 'R', 'G' and 'B'. Output "YES" (without quotes) if this field corresponds to correct flag of Berland. Otherwise, print "NO" (without quotes). -----Input----- The first line contains two integer numbers n and m (1 ≀ n, m ≀ 100) β€” the sizes of the field. Each of the following n lines consisting of m characters 'R', 'G' and 'B' β€” the description of the field. -----Output----- Print "YES" (without quotes) if the given field corresponds to correct flag of Berland . Otherwise, print "NO" (without quotes). -----Examples----- Input 6 5 RRRRR RRRRR BBBBB BBBBB GGGGG GGGGG Output YES Input 4 3 BRG BRG BRG BRG Output YES Input 6 7 RRRGGGG RRRGGGG RRRGGGG RRRBBBB RRRBBBB RRRBBBB Output NO Input 4 4 RRRR RRRR BBBB GGGG Output NO -----Note----- The field in the third example doesn't have three parralel stripes. Rows of the field in the fourth example are parralel to each other and to borders. But they have different heights β€” 2, 1 and 1.
import sys n = input() a = [] n, m = n.split() n = int(n) m = int(m) for i in range(n): a.append(input()) if m % 3 != 0 and n % 3 != 0: print("NO") sys.exit() count = 1 for i in a: for j in i: if j != i[0]: count = 0 break if count == 0: break if count == 1: if n % 3 != 0: print("NO") sys.exit() n = int(n / 3) if a[0][0] == a[n][0] or a[0][0] == a[2 * n][0] or a[n][0] == a[int(2 * n)][0]: print("NO") sys.exit() for i in range(n): if ( a[0][0] != a[i][0] or a[n][0] != a[n + i][0] or a[2 * n][0] != a[2 * n + i][0] ): print("NO") sys.exit() print("YES") else: if m % 3 != 0: print("NO") sys.exit() for i in range(m): for j in range(n): if a[0][i] != a[j][i]: print("NO") sys.exit() m = int(m / 3) if a[0][0] == a[0][m] or a[0][0] == a[0][2 * m] or a[0][m] == a[0][int(2 * m)]: print("NO") sys.exit() for i in range(m): if ( a[0][0] != a[0][i] or a[0][m] != a[0][m + i] or a[0][2 * m] != a[0][2 * m + i] ): print("NO") sys.exit() print("YES")
IMPORT ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR FOR VAR VAR IF VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER IF VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR NUMBER NUMBER VAR VAR NUMBER VAR NUMBER NUMBER VAR BIN_OP NUMBER VAR NUMBER VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR BIN_OP NUMBER VAR NUMBER VAR BIN_OP BIN_OP NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR STRING IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR NUMBER NUMBER VAR NUMBER VAR VAR NUMBER NUMBER VAR NUMBER BIN_OP NUMBER VAR VAR NUMBER VAR VAR NUMBER FUNC_CALL VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER NUMBER VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER BIN_OP VAR VAR VAR NUMBER BIN_OP NUMBER VAR VAR NUMBER BIN_OP BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR STRING
The flag of Berland is such rectangular field n Γ— m that satisfies following conditions: Flag consists of three colors which correspond to letters 'R', 'G' and 'B'. Flag consists of three equal in width and height stripes, parralel to each other and to sides of the flag. Each stripe has exactly one color. Each color should be used in exactly one stripe. You are given a field n Γ— m, consisting of characters 'R', 'G' and 'B'. Output "YES" (without quotes) if this field corresponds to correct flag of Berland. Otherwise, print "NO" (without quotes). -----Input----- The first line contains two integer numbers n and m (1 ≀ n, m ≀ 100) β€” the sizes of the field. Each of the following n lines consisting of m characters 'R', 'G' and 'B' β€” the description of the field. -----Output----- Print "YES" (without quotes) if the given field corresponds to correct flag of Berland . Otherwise, print "NO" (without quotes). -----Examples----- Input 6 5 RRRRR RRRRR BBBBB BBBBB GGGGG GGGGG Output YES Input 4 3 BRG BRG BRG BRG Output YES Input 6 7 RRRGGGG RRRGGGG RRRGGGG RRRBBBB RRRBBBB RRRBBBB Output NO Input 4 4 RRRR RRRR BBBB GGGG Output NO -----Note----- The field in the third example doesn't have three parralel stripes. Rows of the field in the fourth example are parralel to each other and to borders. But they have different heights β€” 2, 1 and 1.
import sys n, m = map(int, input().split()) a = [] for i in range(n): a.append(input()) if n % 3 and m % 3: print("NO") sys.exit() b = [] c = [] f1 = True f2 = True st = "" if n % 3 == 0: i = 0 s = set() while i < n: if a[i][0] in s: f1 = False break s.add(a[i][0]) for j in range(n // 3): b.append(a[i][0] * m) i += n // 3 if m % 3 == 0: i = 0 s = set() while i < m: if a[0][i] in s: f2 = False break s.add(a[0][i]) st += a[0][i] * (m // 3) i += m // 3 for i in range(n): c.append(st) if not f1 and not f2: print("NO") elif f1 and a == b or f2 and a == c: print("YES") else: print("NO")
IMPORT ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR IF BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR STRING IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR WHILE VAR VAR IF VAR VAR NUMBER VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR WHILE VAR VAR IF VAR NUMBER VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING IF VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
The flag of Berland is such rectangular field n Γ— m that satisfies following conditions: Flag consists of three colors which correspond to letters 'R', 'G' and 'B'. Flag consists of three equal in width and height stripes, parralel to each other and to sides of the flag. Each stripe has exactly one color. Each color should be used in exactly one stripe. You are given a field n Γ— m, consisting of characters 'R', 'G' and 'B'. Output "YES" (without quotes) if this field corresponds to correct flag of Berland. Otherwise, print "NO" (without quotes). -----Input----- The first line contains two integer numbers n and m (1 ≀ n, m ≀ 100) β€” the sizes of the field. Each of the following n lines consisting of m characters 'R', 'G' and 'B' β€” the description of the field. -----Output----- Print "YES" (without quotes) if the given field corresponds to correct flag of Berland . Otherwise, print "NO" (without quotes). -----Examples----- Input 6 5 RRRRR RRRRR BBBBB BBBBB GGGGG GGGGG Output YES Input 4 3 BRG BRG BRG BRG Output YES Input 6 7 RRRGGGG RRRGGGG RRRGGGG RRRBBBB RRRBBBB RRRBBBB Output NO Input 4 4 RRRR RRRR BBBB GGGG Output NO -----Note----- The field in the third example doesn't have three parralel stripes. Rows of the field in the fourth example are parralel to each other and to borders. But they have different heights β€” 2, 1 and 1.
def transpose(l): rows, cols = len(l), len(l[0]) rows, cols = cols, rows return ["".join([l[col][row] for col in range(cols)]) for row in range(rows)] def all_equal(l): first = l[0] return all(map(lambda x: x == first, l)) def solve(): height, width = map(int, input().split()) flag = [] for _ in range(height): line = input().strip() if len(line) != width: return False flag.append(line) if height == 1 and width < 3 or height < 3 and width == 1: return False if not all_equal(flag[0]): flag = transpose(flag) width, height = height, width used_colors = set() other_lines = None current_lines = 0 current_color = flag[0][0] used_colors.add(current_color) for i in range(height): if flag[i][0] != current_color: current_color = flag[i][0] if current_color in used_colors: return False else: used_colors.add(current_color) if other_lines is None: other_lines = current_lines elif current_lines != other_lines: return False current_lines = 0 if not all_equal(flag[i]): return False current_lines += 1 return current_lines == other_lines and len(used_colors) == 3 if solve(): print("YES") else: print("NO")
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR VAR RETURN FUNC_CALL STRING VAR VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR VAR NUMBER RETURN FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR IF FUNC_CALL VAR VAR VAR RETURN NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER RETURN NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NONE ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR ASSIGN VAR VAR VAR NUMBER IF VAR VAR RETURN NUMBER EXPR FUNC_CALL VAR VAR IF VAR NONE ASSIGN VAR VAR IF VAR VAR RETURN NUMBER ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR VAR RETURN NUMBER VAR NUMBER RETURN VAR VAR FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
The flag of Berland is such rectangular field n Γ— m that satisfies following conditions: Flag consists of three colors which correspond to letters 'R', 'G' and 'B'. Flag consists of three equal in width and height stripes, parralel to each other and to sides of the flag. Each stripe has exactly one color. Each color should be used in exactly one stripe. You are given a field n Γ— m, consisting of characters 'R', 'G' and 'B'. Output "YES" (without quotes) if this field corresponds to correct flag of Berland. Otherwise, print "NO" (without quotes). -----Input----- The first line contains two integer numbers n and m (1 ≀ n, m ≀ 100) β€” the sizes of the field. Each of the following n lines consisting of m characters 'R', 'G' and 'B' β€” the description of the field. -----Output----- Print "YES" (without quotes) if the given field corresponds to correct flag of Berland . Otherwise, print "NO" (without quotes). -----Examples----- Input 6 5 RRRRR RRRRR BBBBB BBBBB GGGGG GGGGG Output YES Input 4 3 BRG BRG BRG BRG Output YES Input 6 7 RRRGGGG RRRGGGG RRRGGGG RRRBBBB RRRBBBB RRRBBBB Output NO Input 4 4 RRRR RRRR BBBB GGGG Output NO -----Note----- The field in the third example doesn't have three parralel stripes. Rows of the field in the fourth example are parralel to each other and to borders. But they have different heights β€” 2, 1 and 1.
n, m = map(int, input().split()) a = [] for i in range(n): a.append(input()) f1 = 0 f2 = 0 if n % 3 == 0: f1 = 1 o1 = a[0][0] o2 = a[n // 3][0] o3 = a[2 * n // 3][0] if o1 == o2 or o2 == o3 or o1 == o3: f1 = 0 else: for i in range(n): if i < n // 3: if a[i] != o1 * m: f1 = 0 break elif i < 2 * n // 3: if a[i] != o2 * m: f1 = 0 break elif a[i] != o3 * m: f1 = 0 break if m % 3 == 0: f2 = 1 o1 = a[0][0] o2 = a[0][m // 3] o3 = a[0][2 * m // 3] if o1 == o2 or o2 == o3 or o1 == o3: f2 = 0 else: for i in range(n): for j in range(m): if j < m // 3: if a[i][j] != o1: f2 = 0 break elif j < 2 * m // 3: if a[i][j] != o2: f2 = 0 break elif a[i][j] != o3: f2 = 0 break if not f2: break if f1 or f2: print("YES") else: print("NO")
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP BIN_OP NUMBER VAR NUMBER NUMBER IF VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER IF VAR VAR BIN_OP VAR VAR ASSIGN VAR NUMBER IF VAR BIN_OP BIN_OP NUMBER VAR NUMBER IF VAR VAR BIN_OP VAR VAR ASSIGN VAR NUMBER IF VAR VAR BIN_OP VAR VAR ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER IF VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR BIN_OP BIN_OP NUMBER VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
The flag of Berland is such rectangular field n Γ— m that satisfies following conditions: Flag consists of three colors which correspond to letters 'R', 'G' and 'B'. Flag consists of three equal in width and height stripes, parralel to each other and to sides of the flag. Each stripe has exactly one color. Each color should be used in exactly one stripe. You are given a field n Γ— m, consisting of characters 'R', 'G' and 'B'. Output "YES" (without quotes) if this field corresponds to correct flag of Berland. Otherwise, print "NO" (without quotes). -----Input----- The first line contains two integer numbers n and m (1 ≀ n, m ≀ 100) β€” the sizes of the field. Each of the following n lines consisting of m characters 'R', 'G' and 'B' β€” the description of the field. -----Output----- Print "YES" (without quotes) if the given field corresponds to correct flag of Berland . Otherwise, print "NO" (without quotes). -----Examples----- Input 6 5 RRRRR RRRRR BBBBB BBBBB GGGGG GGGGG Output YES Input 4 3 BRG BRG BRG BRG Output YES Input 6 7 RRRGGGG RRRGGGG RRRGGGG RRRBBBB RRRBBBB RRRBBBB Output NO Input 4 4 RRRR RRRR BBBB GGGG Output NO -----Note----- The field in the third example doesn't have three parralel stripes. Rows of the field in the fourth example are parralel to each other and to borders. But they have different heights β€” 2, 1 and 1.
n, m = map(int, input().split()) a = [input() for q in range(n)] naw = a[0][0] flag = ( n % 3 == 0 and a[0][0] != a[n // 3][0] and a[0][0] != a[n // 3 * 2][0] and a[n // 3][0] != a[n // 3 * 2][0] ) for q in range(n // 3): for q1 in range(len(a[q])): if a[q][q1] != naw: flag = False naw = a[n // 3][0] for q in range(n // 3, 2 * n // 3): for q1 in range(len(a[q])): if a[q][q1] != naw: flag = False naw = a[n // 3 * 2][0] for q in range(n // 3 * 2, n): for q1 in range(len(a[q])): if a[q][q1] != naw: flag = False if flag: print("YES") else: s = [[a[q][q1] for q in range(n)] for q1 in range(m)] n, m, a = m, n, s naw = a[0][0] flag = ( n % 3 == 0 and a[0][0] != a[n // 3][0] and a[0][0] != a[n // 3 * 2][0] and a[n // 3][0] != a[n // 3 * 2][0] ) for q in range(n // 3): for q1 in range(len(a[q])): if a[q][q1] != naw: flag = False naw = a[n // 3][0] for q in range(n // 3, 2 * n // 3): for q1 in range(len(a[q])): if a[q][q1] != naw: flag = False naw = a[n // 3 * 2][0] for q in range(n // 3 * 2, n): for q1 in range(len(a[q])): if a[q][q1] != naw: flag = False if flag: print("YES") else: print("NO")
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER NUMBER VAR BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER NUMBER VAR BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
The flag of Berland is such rectangular field n Γ— m that satisfies following conditions: Flag consists of three colors which correspond to letters 'R', 'G' and 'B'. Flag consists of three equal in width and height stripes, parralel to each other and to sides of the flag. Each stripe has exactly one color. Each color should be used in exactly one stripe. You are given a field n Γ— m, consisting of characters 'R', 'G' and 'B'. Output "YES" (without quotes) if this field corresponds to correct flag of Berland. Otherwise, print "NO" (without quotes). -----Input----- The first line contains two integer numbers n and m (1 ≀ n, m ≀ 100) β€” the sizes of the field. Each of the following n lines consisting of m characters 'R', 'G' and 'B' β€” the description of the field. -----Output----- Print "YES" (without quotes) if the given field corresponds to correct flag of Berland . Otherwise, print "NO" (without quotes). -----Examples----- Input 6 5 RRRRR RRRRR BBBBB BBBBB GGGGG GGGGG Output YES Input 4 3 BRG BRG BRG BRG Output YES Input 6 7 RRRGGGG RRRGGGG RRRGGGG RRRBBBB RRRBBBB RRRBBBB Output NO Input 4 4 RRRR RRRR BBBB GGGG Output NO -----Note----- The field in the third example doesn't have three parralel stripes. Rows of the field in the fourth example are parralel to each other and to borders. But they have different heights β€” 2, 1 and 1.
def check_line(line): line_color = line[0][0] for row in line: for color in row: if color != line_color: return False return True def check_flag(flag, n, m): is_vertical = len(set(flag[0])) > 1 row_has_3_colors = len(set(flag[0])) == 3 col_has_3_colors = len(set([row[0] for row in flag])) == 3 if not (row_has_3_colors or col_has_3_colors): return False if is_vertical: dimension = m else: dimension = n unproportional = dimension % 3 != 0 if unproportional: return False step = dimension // 3 for k in range(3): if is_vertical: is_consistent = check_line( [flag[row][k * step : (k + 1) * step] for row in range(n)] ) else: is_consistent = check_line(flag[k * step : (k + 1) * step]) if not is_consistent: return False return True def main(): n, m = map(int, input().split()) flag = [None for i in range(n)] for i in range(n): flag[i] = input() flag_is_correct = check_flag(flag, n, m) if flag_is_correct: print("YES") else: print("NO") main()
FUNC_DEF ASSIGN VAR VAR NUMBER NUMBER FOR VAR VAR FOR VAR VAR IF VAR VAR RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER IF VAR VAR RETURN NUMBER IF VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER IF VAR RETURN NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR NUMBER VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR NUMBER VAR IF VAR RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NONE VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR
The flag of Berland is such rectangular field n Γ— m that satisfies following conditions: Flag consists of three colors which correspond to letters 'R', 'G' and 'B'. Flag consists of three equal in width and height stripes, parralel to each other and to sides of the flag. Each stripe has exactly one color. Each color should be used in exactly one stripe. You are given a field n Γ— m, consisting of characters 'R', 'G' and 'B'. Output "YES" (without quotes) if this field corresponds to correct flag of Berland. Otherwise, print "NO" (without quotes). -----Input----- The first line contains two integer numbers n and m (1 ≀ n, m ≀ 100) β€” the sizes of the field. Each of the following n lines consisting of m characters 'R', 'G' and 'B' β€” the description of the field. -----Output----- Print "YES" (without quotes) if the given field corresponds to correct flag of Berland . Otherwise, print "NO" (without quotes). -----Examples----- Input 6 5 RRRRR RRRRR BBBBB BBBBB GGGGG GGGGG Output YES Input 4 3 BRG BRG BRG BRG Output YES Input 6 7 RRRGGGG RRRGGGG RRRGGGG RRRBBBB RRRBBBB RRRBBBB Output NO Input 4 4 RRRR RRRR BBBB GGGG Output NO -----Note----- The field in the third example doesn't have three parralel stripes. Rows of the field in the fourth example are parralel to each other and to borders. But they have different heights β€” 2, 1 and 1.
def c(f, n, m): if n % 3 != 0: return 0 s = n // 3 s = f[0], f[s], f[2 * s] if set(s) != set(map(lambda x: x * m, "RGB")): return 0 for i in range(n): if f[i] != s[i * 3 // n]: return 0 return 1 n, m = map(int, input().split()) f = [input() for _ in range(n)] print( "Yes" if c(f, n, m) or c(["".join(f[j][i] for j in range(n)) for i in range(m)], m, n) else "No" )
FUNC_DEF IF BIN_OP VAR NUMBER NUMBER RETURN NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER VAR VAR VAR BIN_OP NUMBER VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR STRING RETURN NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP BIN_OP VAR NUMBER VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL STRING VAR VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR STRING STRING
The flag of Berland is such rectangular field n Γ— m that satisfies following conditions: Flag consists of three colors which correspond to letters 'R', 'G' and 'B'. Flag consists of three equal in width and height stripes, parralel to each other and to sides of the flag. Each stripe has exactly one color. Each color should be used in exactly one stripe. You are given a field n Γ— m, consisting of characters 'R', 'G' and 'B'. Output "YES" (without quotes) if this field corresponds to correct flag of Berland. Otherwise, print "NO" (without quotes). -----Input----- The first line contains two integer numbers n and m (1 ≀ n, m ≀ 100) β€” the sizes of the field. Each of the following n lines consisting of m characters 'R', 'G' and 'B' β€” the description of the field. -----Output----- Print "YES" (without quotes) if the given field corresponds to correct flag of Berland . Otherwise, print "NO" (without quotes). -----Examples----- Input 6 5 RRRRR RRRRR BBBBB BBBBB GGGGG GGGGG Output YES Input 4 3 BRG BRG BRG BRG Output YES Input 6 7 RRRGGGG RRRGGGG RRRGGGG RRRBBBB RRRBBBB RRRBBBB Output NO Input 4 4 RRRR RRRR BBBB GGGG Output NO -----Note----- The field in the third example doesn't have three parralel stripes. Rows of the field in the fourth example are parralel to each other and to borders. But they have different heights β€” 2, 1 and 1.
y, x = map(int, input().split()) ls = [] for i in range(y): ls.append(input()) if ls[0].count(ls[0][0]) == x: ls = list(zip(*ls)) x, y = y, x nr, ng, nb = ls[0].count("R"), ls[0].count("G"), ls[0].count("B") ch = 0 for i in range(1, x): if ls[0][i] != ls[0][i - 1]: ch += 1 if nr + ng + nb != x or nr != ng or nr != nb or ch != 2: print("NO") else: for i in ls: if i != ls[0]: print("NO") break else: print("YES")
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR IF FUNC_CALL VAR NUMBER VAR NUMBER NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR NUMBER STRING FUNC_CALL VAR NUMBER STRING FUNC_CALL VAR NUMBER STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR NUMBER VAR VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER IF BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR STRING FOR VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
The flag of Berland is such rectangular field n Γ— m that satisfies following conditions: Flag consists of three colors which correspond to letters 'R', 'G' and 'B'. Flag consists of three equal in width and height stripes, parralel to each other and to sides of the flag. Each stripe has exactly one color. Each color should be used in exactly one stripe. You are given a field n Γ— m, consisting of characters 'R', 'G' and 'B'. Output "YES" (without quotes) if this field corresponds to correct flag of Berland. Otherwise, print "NO" (without quotes). -----Input----- The first line contains two integer numbers n and m (1 ≀ n, m ≀ 100) β€” the sizes of the field. Each of the following n lines consisting of m characters 'R', 'G' and 'B' β€” the description of the field. -----Output----- Print "YES" (without quotes) if the given field corresponds to correct flag of Berland . Otherwise, print "NO" (without quotes). -----Examples----- Input 6 5 RRRRR RRRRR BBBBB BBBBB GGGGG GGGGG Output YES Input 4 3 BRG BRG BRG BRG Output YES Input 6 7 RRRGGGG RRRGGGG RRRGGGG RRRBBBB RRRBBBB RRRBBBB Output NO Input 4 4 RRRR RRRR BBBB GGGG Output NO -----Note----- The field in the third example doesn't have three parralel stripes. Rows of the field in the fourth example are parralel to each other and to borders. But they have different heights β€” 2, 1 and 1.
n, m = map(int, input().split()) a = [input() for i in range(n)] b = ["".join(a[i][j] for i in range(n)) for j in range(m)] def check(a, n, m): if n % 3 != 0: return False s = a[0 * n // 3], a[1 * n // 3], a[2 * n // 3] if set(s) != set(map(lambda x: x * m, "RGB")): return False for i in range(n): if a[i] != s[i * 3 // n]: return False return True if check(a, n, m) or check(b, m, n): print("YES") else: print("NO")
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL STRING VAR VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FUNC_DEF IF BIN_OP VAR NUMBER NUMBER RETURN NUMBER ASSIGN VAR VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR BIN_OP BIN_OP NUMBER VAR NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR STRING RETURN NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP BIN_OP VAR NUMBER VAR RETURN NUMBER RETURN NUMBER IF FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
The flag of Berland is such rectangular field n Γ— m that satisfies following conditions: Flag consists of three colors which correspond to letters 'R', 'G' and 'B'. Flag consists of three equal in width and height stripes, parralel to each other and to sides of the flag. Each stripe has exactly one color. Each color should be used in exactly one stripe. You are given a field n Γ— m, consisting of characters 'R', 'G' and 'B'. Output "YES" (without quotes) if this field corresponds to correct flag of Berland. Otherwise, print "NO" (without quotes). -----Input----- The first line contains two integer numbers n and m (1 ≀ n, m ≀ 100) β€” the sizes of the field. Each of the following n lines consisting of m characters 'R', 'G' and 'B' β€” the description of the field. -----Output----- Print "YES" (without quotes) if the given field corresponds to correct flag of Berland . Otherwise, print "NO" (without quotes). -----Examples----- Input 6 5 RRRRR RRRRR BBBBB BBBBB GGGGG GGGGG Output YES Input 4 3 BRG BRG BRG BRG Output YES Input 6 7 RRRGGGG RRRGGGG RRRGGGG RRRBBBB RRRBBBB RRRBBBB Output NO Input 4 4 RRRR RRRR BBBB GGGG Output NO -----Note----- The field in the third example doesn't have three parralel stripes. Rows of the field in the fourth example are parralel to each other and to borders. But they have different heights β€” 2, 1 and 1.
inp = input().split() n = [int(inp[0]), int(inp[1])] flag = [[], []] flag[0] = [input().rstrip() for i in range(n[0])] flag[1] = list(map(list, zip(*flag[0]))) ok = False for i in [0, 1]: if n[i] % 3 == 0 and not ok: cols = set() ok = True for k in [0, 1, 2]: beg = n[i] // 3 * k end = n[i] // 3 * (k + 1) if flag[i][beg][0] in cols: ok = False break cols.add(flag[i][beg][0]) for j in range(beg, end): if flag[i][j][0] != flag[i][beg][0]: ok = False break else: continue break for line in flag[i]: col = line[0] for cell in line: if col != cell: ok = False break else: continue break if ok: print("YES") else: print("NO")
ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST LIST LIST ASSIGN VAR NUMBER FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR LIST NUMBER NUMBER IF BIN_OP VAR VAR NUMBER NUMBER VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR LIST NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR NUMBER VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR ASSIGN VAR VAR NUMBER FOR VAR VAR IF VAR VAR ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
The flag of Berland is such rectangular field n Γ— m that satisfies following conditions: Flag consists of three colors which correspond to letters 'R', 'G' and 'B'. Flag consists of three equal in width and height stripes, parralel to each other and to sides of the flag. Each stripe has exactly one color. Each color should be used in exactly one stripe. You are given a field n Γ— m, consisting of characters 'R', 'G' and 'B'. Output "YES" (without quotes) if this field corresponds to correct flag of Berland. Otherwise, print "NO" (without quotes). -----Input----- The first line contains two integer numbers n and m (1 ≀ n, m ≀ 100) β€” the sizes of the field. Each of the following n lines consisting of m characters 'R', 'G' and 'B' β€” the description of the field. -----Output----- Print "YES" (without quotes) if the given field corresponds to correct flag of Berland . Otherwise, print "NO" (without quotes). -----Examples----- Input 6 5 RRRRR RRRRR BBBBB BBBBB GGGGG GGGGG Output YES Input 4 3 BRG BRG BRG BRG Output YES Input 6 7 RRRGGGG RRRGGGG RRRGGGG RRRBBBB RRRBBBB RRRBBBB Output NO Input 4 4 RRRR RRRR BBBB GGGG Output NO -----Note----- The field in the third example doesn't have three parralel stripes. Rows of the field in the fourth example are parralel to each other and to borders. But they have different heights β€” 2, 1 and 1.
import sys r, c = [int(x) for x in input().split()] V = [] for i in range(r): V.append(input()) d = {"R": 0, "G": 0, "B": 0} napa = True zeta = [] for i in range(r): alpha = V[i][0] if len(zeta) != 0: if alpha != zeta[-1] and alpha in zeta: napa = False break else: zeta.append(alpha) else: zeta.append(alpha) for j in range(c): if V[i][j] == alpha: continue else: napa = False if not napa: break else: d[alpha] += 1 if napa == True: if d["R"] == d["G"] == d["B"]: print("YES") sys.exit(0) else: print("NO") sys.exit(0) d = {"R": 0, "G": 0, "B": 0} napa = True zeta = [] for i in range(c): alpha = V[0][i] if len(zeta) != 0: if alpha != zeta[-1] and alpha in zeta: napa = False break else: zeta.append(alpha) else: zeta.append(alpha) for j in range(r): if V[j][i] == alpha: continue else: napa = False if not napa: break else: d[alpha] += 1 if napa == True: if d["R"] == d["G"] == d["B"]: print("YES") sys.exit(0) else: print("NO") sys.exit(0) else: print("NO")
IMPORT ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT STRING STRING STRING NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER IF VAR VAR NUMBER VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR VAR VAR NUMBER IF VAR NUMBER IF VAR STRING VAR STRING VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER ASSIGN VAR DICT STRING STRING STRING NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER VAR IF FUNC_CALL VAR VAR NUMBER IF VAR VAR NUMBER VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR VAR VAR NUMBER IF VAR NUMBER IF VAR STRING VAR STRING VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR STRING
The flag of Berland is such rectangular field n Γ— m that satisfies following conditions: Flag consists of three colors which correspond to letters 'R', 'G' and 'B'. Flag consists of three equal in width and height stripes, parralel to each other and to sides of the flag. Each stripe has exactly one color. Each color should be used in exactly one stripe. You are given a field n Γ— m, consisting of characters 'R', 'G' and 'B'. Output "YES" (without quotes) if this field corresponds to correct flag of Berland. Otherwise, print "NO" (without quotes). -----Input----- The first line contains two integer numbers n and m (1 ≀ n, m ≀ 100) β€” the sizes of the field. Each of the following n lines consisting of m characters 'R', 'G' and 'B' β€” the description of the field. -----Output----- Print "YES" (without quotes) if the given field corresponds to correct flag of Berland . Otherwise, print "NO" (without quotes). -----Examples----- Input 6 5 RRRRR RRRRR BBBBB BBBBB GGGGG GGGGG Output YES Input 4 3 BRG BRG BRG BRG Output YES Input 6 7 RRRGGGG RRRGGGG RRRGGGG RRRBBBB RRRBBBB RRRBBBB Output NO Input 4 4 RRRR RRRR BBBB GGGG Output NO -----Note----- The field in the third example doesn't have three parralel stripes. Rows of the field in the fourth example are parralel to each other and to borders. But they have different heights β€” 2, 1 and 1.
n, m = map(int, input().split()) s = [input() for _ in range(n)] if n % 3 != 0 and m % 3 != 0: print("NO") exit() flag = 0 if n % 3 == 0: if not ( s[0][0] != s[n // 3][0] and s[2 * n // 3][0] != s[n // 3][0] and s[2 * n // 3][0] != s[0][0] ): flag = 1 r, g, b = 0, 0, 0 if s[0][0] == "R": r = 1 elif s[0][0] == "G": g = 1 else: b = 1 for i in range(n // 3): for j in range(m): if s[i][j] == "G" and g != 1: flag = 1 elif s[i][j] == "R" and r != 1: flag = 1 elif s[i][j] == "B" and b != 1: flag = 1 if s[n // 3][0] == "R": if r == 1: flag = 1 r = 1 g, b = 0, 0 elif s[n // 3][0] == "G": if g == 1: flag = 1 g = 1 r, b = 0, 0 else: if b == 1: flag = 1 b = 1 r, g = 0, 0 for i in range(n // 3, 2 * n // 3): for j in range(m): if s[i][j] == "G" and g != 1: flag = 1 elif s[i][j] == "R" and r != 1: flag = 1 elif s[i][j] == "B" and b != 1: flag = 1 if s[2 * n // 3][0] == "R": if r == 1: flag = 1 r = 1 g, b = 0, 0 elif s[2 * n // 3][0] == "G": if g == 1: flag = 1 g = 1 r, b = 0, 0 else: if b == 1: flag = 1 b = 1 r, g = 0, 0 for i in range(2 * n // 3, n): for j in range(m): if s[i][j] == "G" and g != 1: flag = 1 elif s[i][j] == "R" and r != 1: flag = 1 elif s[i][j] == "B" and b != 1: flag = 1 if flag == 0: print("YES") exit() flag = 0 if m % 3 == 0: if not ( s[0][0] != s[0][m // 3] and s[0][2 * m // 3] != s[0][m // 3] and s[0][0] != s[0][2 * m // 3] ): flag = 1 r, g, b = 0, 0, 0 if s[0][0] == "R": r += 1 elif s[0][0] == "G": g += 1 else: b += 1 for j in range(m // 3): for i in range(n): if s[i][j] == "G" and g != 1: flag = 1 elif s[i][j] == "R" and r != 1: flag = 1 elif s[i][j] == "B" and b != 1: flag = 1 if s[0][m // 3] == "R": if r == 1: flag = 1 r = 1 g, b = 0, 0 elif s[0][m // 3] == "G": if g == 1: flag = 1 g = 1 r, b = 0, 0 else: if b == 1: flag = 1 b = 1 r, g = 0, 0 for j in range(m // 3, 2 * m // 3): for i in range(n): if s[i][j] == "G" and g != 1: flag = 1 elif s[i][j] == "R" and r != 1: flag = 1 elif s[i][j] == "B" and b != 1: flag = 1 if s[0][2 * m // 3] == "R": if r == 1: flag = 1 r = 1 g, b = 0, 0 elif s[0][2 * m // 3] == "G": if g == 1: flag = 1 g = 1 r, b = 0, 0 else: if b == 1: flag = 1 b = 1 r, g = 0, 0 for j in range(2 * m // 3, m): for i in range(n): if s[i][j] == "G" and g != 1: flag = 1 elif s[i][j] == "R" and r != 1: flag = 1 elif s[i][j] == "B" and b != 1: flag = 1 if flag == 0: print("YES") exit() print("NO")
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER IF VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP BIN_OP NUMBER VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP BIN_OP NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER IF VAR NUMBER NUMBER STRING ASSIGN VAR NUMBER IF VAR NUMBER NUMBER STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR VAR STRING VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR VAR STRING VAR NUMBER ASSIGN VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER STRING IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER NUMBER STRING IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR VAR STRING VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR VAR STRING VAR NUMBER ASSIGN VAR NUMBER IF VAR BIN_OP BIN_OP NUMBER VAR NUMBER NUMBER STRING IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER IF VAR BIN_OP BIN_OP NUMBER VAR NUMBER NUMBER STRING IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR VAR STRING VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR VAR STRING VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER IF VAR NUMBER NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER NUMBER VAR NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER IF VAR NUMBER NUMBER STRING VAR NUMBER IF VAR NUMBER NUMBER STRING VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR VAR STRING VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR VAR STRING VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER BIN_OP VAR NUMBER STRING IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER IF VAR NUMBER BIN_OP VAR NUMBER STRING IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR VAR STRING VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR VAR STRING VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER STRING IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER IF VAR NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER STRING IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR VAR STRING VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR VAR STRING VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR STRING
The flag of Berland is such rectangular field n Γ— m that satisfies following conditions: Flag consists of three colors which correspond to letters 'R', 'G' and 'B'. Flag consists of three equal in width and height stripes, parralel to each other and to sides of the flag. Each stripe has exactly one color. Each color should be used in exactly one stripe. You are given a field n Γ— m, consisting of characters 'R', 'G' and 'B'. Output "YES" (without quotes) if this field corresponds to correct flag of Berland. Otherwise, print "NO" (without quotes). -----Input----- The first line contains two integer numbers n and m (1 ≀ n, m ≀ 100) β€” the sizes of the field. Each of the following n lines consisting of m characters 'R', 'G' and 'B' β€” the description of the field. -----Output----- Print "YES" (without quotes) if the given field corresponds to correct flag of Berland . Otherwise, print "NO" (without quotes). -----Examples----- Input 6 5 RRRRR RRRRR BBBBB BBBBB GGGGG GGGGG Output YES Input 4 3 BRG BRG BRG BRG Output YES Input 6 7 RRRGGGG RRRGGGG RRRGGGG RRRBBBB RRRBBBB RRRBBBB Output NO Input 4 4 RRRR RRRR BBBB GGGG Output NO -----Note----- The field in the third example doesn't have three parralel stripes. Rows of the field in the fourth example are parralel to each other and to borders. But they have different heights β€” 2, 1 and 1.
n, m = map(int, input().split()) ls = [] for i in range(n): s = input() ls.append(s) horizontal = [] f1 = True for i in range(n): if ls[i] == ls[i][0] * len(ls[i]): if i == 0: horizontal.append([ls[i], 1]) elif ls[i] == horizontal[-1][0]: horizontal[-1][1] += 1 else: horizontal.append([ls[i], 1]) else: f1 = False break if len(horizontal) == 3 and horizontal[0][1] == horizontal[1][1] == horizontal[2][1]: if ( horizontal[0][0] != horizontal[1][0] and horizontal[0][0] != horizontal[2][0] and horizontal[1][0] != horizontal[2][0] ): s = "" else: f1 = False else: f1 = False new_ls = ["" for i in range(m)] for i in range(n): for j in range(m): new_ls[j] += ls[i][j] ls = new_ls horizontal = [] f2 = True for i in range(m): if ls[i] == ls[i][0] * len(ls[i]): if i == 0: horizontal.append([ls[i], 1]) elif ls[i] == horizontal[-1][0]: horizontal[-1][1] += 1 else: horizontal.append([ls[i], 1]) else: f2 = False break if len(horizontal) == 3 and horizontal[0][1] == horizontal[1][1] == horizontal[2][1]: if ( horizontal[0][0] != horizontal[1][0] and horizontal[0][0] != horizontal[2][0] and horizontal[1][0] != horizontal[2][0] ): s = "" else: f2 = False else: f2 = False if f1 or f2: print("YES") else: print("NO")
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR VAR NUMBER FUNC_CALL VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR LIST VAR VAR NUMBER IF VAR VAR VAR NUMBER NUMBER VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR LIST VAR VAR NUMBER ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER IF VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR STRING VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR VAR NUMBER FUNC_CALL VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR LIST VAR VAR NUMBER IF VAR VAR VAR NUMBER NUMBER VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR LIST VAR VAR NUMBER ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER IF VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
The flag of Berland is such rectangular field n Γ— m that satisfies following conditions: Flag consists of three colors which correspond to letters 'R', 'G' and 'B'. Flag consists of three equal in width and height stripes, parralel to each other and to sides of the flag. Each stripe has exactly one color. Each color should be used in exactly one stripe. You are given a field n Γ— m, consisting of characters 'R', 'G' and 'B'. Output "YES" (without quotes) if this field corresponds to correct flag of Berland. Otherwise, print "NO" (without quotes). -----Input----- The first line contains two integer numbers n and m (1 ≀ n, m ≀ 100) β€” the sizes of the field. Each of the following n lines consisting of m characters 'R', 'G' and 'B' β€” the description of the field. -----Output----- Print "YES" (without quotes) if the given field corresponds to correct flag of Berland . Otherwise, print "NO" (without quotes). -----Examples----- Input 6 5 RRRRR RRRRR BBBBB BBBBB GGGGG GGGGG Output YES Input 4 3 BRG BRG BRG BRG Output YES Input 6 7 RRRGGGG RRRGGGG RRRGGGG RRRBBBB RRRBBBB RRRBBBB Output NO Input 4 4 RRRR RRRR BBBB GGGG Output NO -----Note----- The field in the third example doesn't have three parralel stripes. Rows of the field in the fourth example are parralel to each other and to borders. But they have different heights β€” 2, 1 and 1.
a, b = input().split() a = int(a) b = int(b) arr = [] Rflag = Gflag = Bflag = flag = False for i in range(a): arr += [list(input().strip())] if a % 3 == 0: flag = True for i in range(3): for j in range(a // 3): if j == 0 and flag == True: if arr[a // 3 * i + j].count("R") == b and Rflag == False: curr = ["R"] Rflag = True elif arr[a // 3 * i + j].count("G") == b and Gflag == False: curr = ["G"] Gflag = True elif arr[a // 3 * i + j].count("B") == b and Bflag == False: curr = ["B"] Bflag = True else: flag = False elif flag == True: if arr[a // 3 * i + j] != curr * b: flag = False if b % 3 == 0 and flag == False: arr = tuple(zip(*arr[::-1])) Rflag = Gflag = Bflag = False a, b = b, a flag = True for i in range(3): for j in range(a // 3): if j == 0 and flag == True: if arr[a // 3 * i + j].count("R") == b and Rflag == False: curr = "R" Rflag = True elif arr[a // 3 * i + j].count("G") == b and Gflag == False: curr = "G" Gflag = True elif arr[a // 3 * i + j].count("B") == b and Bflag == False: curr = "B" Bflag = True else: flag = False elif flag == True: if arr[a // 3 * i + j].count(curr) != b: flag = False if flag and Gflag and Bflag and Rflag: print("YES") else: print("NO")
ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR LIST FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR NUMBER IF FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR STRING VAR VAR NUMBER ASSIGN VAR LIST STRING ASSIGN VAR NUMBER IF FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR STRING VAR VAR NUMBER ASSIGN VAR LIST STRING ASSIGN VAR NUMBER IF FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR STRING VAR VAR NUMBER ASSIGN VAR LIST STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER IF VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR BIN_OP VAR VAR ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR NUMBER IF FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR STRING VAR VAR NUMBER ASSIGN VAR STRING ASSIGN VAR NUMBER IF FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR STRING VAR VAR NUMBER ASSIGN VAR STRING ASSIGN VAR NUMBER IF FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR STRING VAR VAR NUMBER ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER IF FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
The flag of Berland is such rectangular field n Γ— m that satisfies following conditions: Flag consists of three colors which correspond to letters 'R', 'G' and 'B'. Flag consists of three equal in width and height stripes, parralel to each other and to sides of the flag. Each stripe has exactly one color. Each color should be used in exactly one stripe. You are given a field n Γ— m, consisting of characters 'R', 'G' and 'B'. Output "YES" (without quotes) if this field corresponds to correct flag of Berland. Otherwise, print "NO" (without quotes). -----Input----- The first line contains two integer numbers n and m (1 ≀ n, m ≀ 100) β€” the sizes of the field. Each of the following n lines consisting of m characters 'R', 'G' and 'B' β€” the description of the field. -----Output----- Print "YES" (without quotes) if the given field corresponds to correct flag of Berland . Otherwise, print "NO" (without quotes). -----Examples----- Input 6 5 RRRRR RRRRR BBBBB BBBBB GGGGG GGGGG Output YES Input 4 3 BRG BRG BRG BRG Output YES Input 6 7 RRRGGGG RRRGGGG RRRGGGG RRRBBBB RRRBBBB RRRBBBB Output NO Input 4 4 RRRR RRRR BBBB GGGG Output NO -----Note----- The field in the third example doesn't have three parralel stripes. Rows of the field in the fourth example are parralel to each other and to borders. But they have different heights β€” 2, 1 and 1.
n, m = list(map(int, input().split())) f = [input() for _ in range(n)] def clr(ss): cc = None for s in ss: for c in s: if cc is None: cc = c elif cc != c: return None return cc if n % 3 == 0: s = set() for i in range(0, n, n // 3): ret = clr(f[i : i + n // 3]) if ret is None: continue s.add(ret) if len(s) == 3: print("YES") exit(0) if m % 3 == 0: s = set() for j in range(0, m, m // 3): ff = [] for i in f: ff.append(i[j : j + m // 3]) ret = clr(ff) if ret is None: continue s.add(ret) if len(s) == 3: print("YES") exit(0) print("NO")
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR NONE FOR VAR VAR FOR VAR VAR IF VAR NONE ASSIGN VAR VAR IF VAR VAR RETURN NONE RETURN VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER IF VAR NONE EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR NONE EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR STRING
The flag of Berland is such rectangular field n Γ— m that satisfies following conditions: Flag consists of three colors which correspond to letters 'R', 'G' and 'B'. Flag consists of three equal in width and height stripes, parralel to each other and to sides of the flag. Each stripe has exactly one color. Each color should be used in exactly one stripe. You are given a field n Γ— m, consisting of characters 'R', 'G' and 'B'. Output "YES" (without quotes) if this field corresponds to correct flag of Berland. Otherwise, print "NO" (without quotes). -----Input----- The first line contains two integer numbers n and m (1 ≀ n, m ≀ 100) β€” the sizes of the field. Each of the following n lines consisting of m characters 'R', 'G' and 'B' β€” the description of the field. -----Output----- Print "YES" (without quotes) if the given field corresponds to correct flag of Berland . Otherwise, print "NO" (without quotes). -----Examples----- Input 6 5 RRRRR RRRRR BBBBB BBBBB GGGGG GGGGG Output YES Input 4 3 BRG BRG BRG BRG Output YES Input 6 7 RRRGGGG RRRGGGG RRRGGGG RRRBBBB RRRBBBB RRRBBBB Output NO Input 4 4 RRRR RRRR BBBB GGGG Output NO -----Note----- The field in the third example doesn't have three parralel stripes. Rows of the field in the fourth example are parralel to each other and to borders. But they have different heights β€” 2, 1 and 1.
def matrixTranspose(matrix): if not matrix: return [] return [[row[i] for row in matrix] for i in range(len(matrix[0]))] def f(x): bool = True b, r, g = 0, 0, 0 col = ["e"] for row in x: if all(el == "R" for el in row): r += 1 if col[-1] != "r": col.append("r") elif all(el == "G" for el in row): g += 1 if col[-1] != "g": col.append("g") elif all(el == "B" for el in row): b += 1 if col[-1] != "b": col.append("b") else: bool = False break return bool and b == g == r and sorted(col) == sorted(list(set(col))) n, m = map(int, input().split()) a = [0] * n for i in range(n): a[i] = list(input()) print("YES" if f(a) or f(matrixTranspose(a)) else "NO")
FUNC_DEF IF VAR RETURN LIST RETURN VAR VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR LIST STRING FOR VAR VAR IF FUNC_CALL VAR VAR STRING VAR VAR VAR NUMBER IF VAR NUMBER STRING EXPR FUNC_CALL VAR STRING IF FUNC_CALL VAR VAR STRING VAR VAR VAR NUMBER IF VAR NUMBER STRING EXPR FUNC_CALL VAR STRING IF FUNC_CALL VAR VAR STRING VAR VAR VAR NUMBER IF VAR NUMBER STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER RETURN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR STRING STRING
The flag of Berland is such rectangular field n Γ— m that satisfies following conditions: Flag consists of three colors which correspond to letters 'R', 'G' and 'B'. Flag consists of three equal in width and height stripes, parralel to each other and to sides of the flag. Each stripe has exactly one color. Each color should be used in exactly one stripe. You are given a field n Γ— m, consisting of characters 'R', 'G' and 'B'. Output "YES" (without quotes) if this field corresponds to correct flag of Berland. Otherwise, print "NO" (without quotes). -----Input----- The first line contains two integer numbers n and m (1 ≀ n, m ≀ 100) β€” the sizes of the field. Each of the following n lines consisting of m characters 'R', 'G' and 'B' β€” the description of the field. -----Output----- Print "YES" (without quotes) if the given field corresponds to correct flag of Berland . Otherwise, print "NO" (without quotes). -----Examples----- Input 6 5 RRRRR RRRRR BBBBB BBBBB GGGGG GGGGG Output YES Input 4 3 BRG BRG BRG BRG Output YES Input 6 7 RRRGGGG RRRGGGG RRRGGGG RRRBBBB RRRBBBB RRRBBBB Output NO Input 4 4 RRRR RRRR BBBB GGGG Output NO -----Note----- The field in the third example doesn't have three parralel stripes. Rows of the field in the fourth example are parralel to each other and to borders. But they have different heights β€” 2, 1 and 1.
def vertical(): if n % 3 == 0: num = n // 3 res = [data[0][0], data[num][0], data[num * 2][0]] if "R" not in res or "G" not in res or "B" not in res: return False for i in range(0, n): if data[i] != res[i // num] * m: return False return True else: return False def horizontal(): if m % 3 == 0: num = m // 3 res = [data[0][0], data[0][num], data[0][num * 2]] if "R" not in res or "G" not in res or "B" not in res: return False for i in range(0, m): col = "" for j in range(0, n): col += data[j][i] if col != res[i // num] * n: return False return True else: return False n, m = map(int, input().split()) data = [] for i in range(n): s = str(input()) data.append(s) if n % 3 != 0 and m % 3 != 0: print("No") exit(0) ver_rs = vertical() hor_rs = horizontal() if hor_rs or ver_rs: print("YES") else: print("No")
FUNC_DEF IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR LIST VAR NUMBER NUMBER VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER IF STRING VAR STRING VAR STRING VAR RETURN NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR BIN_OP VAR BIN_OP VAR VAR VAR RETURN NUMBER RETURN NUMBER RETURN NUMBER FUNC_DEF IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR LIST VAR NUMBER NUMBER VAR NUMBER VAR VAR NUMBER BIN_OP VAR NUMBER IF STRING VAR STRING VAR STRING VAR RETURN NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR VAR IF VAR BIN_OP VAR BIN_OP VAR VAR VAR RETURN NUMBER RETURN NUMBER RETURN NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
The flag of Berland is such rectangular field n Γ— m that satisfies following conditions: Flag consists of three colors which correspond to letters 'R', 'G' and 'B'. Flag consists of three equal in width and height stripes, parralel to each other and to sides of the flag. Each stripe has exactly one color. Each color should be used in exactly one stripe. You are given a field n Γ— m, consisting of characters 'R', 'G' and 'B'. Output "YES" (without quotes) if this field corresponds to correct flag of Berland. Otherwise, print "NO" (without quotes). -----Input----- The first line contains two integer numbers n and m (1 ≀ n, m ≀ 100) β€” the sizes of the field. Each of the following n lines consisting of m characters 'R', 'G' and 'B' β€” the description of the field. -----Output----- Print "YES" (without quotes) if the given field corresponds to correct flag of Berland . Otherwise, print "NO" (without quotes). -----Examples----- Input 6 5 RRRRR RRRRR BBBBB BBBBB GGGGG GGGGG Output YES Input 4 3 BRG BRG BRG BRG Output YES Input 6 7 RRRGGGG RRRGGGG RRRGGGG RRRBBBB RRRBBBB RRRBBBB Output NO Input 4 4 RRRR RRRR BBBB GGGG Output NO -----Note----- The field in the third example doesn't have three parralel stripes. Rows of the field in the fourth example are parralel to each other and to borders. But they have different heights β€” 2, 1 and 1.
n, m = list(map(int, input().split())) l = [0] * n for i in range(n): l[i] = input() types = ["B", "G", "R"] first = [] second = [] third = [] countb = 0 countr = 0 countg = 0 counter = 0 container = 0 ans = [] ans1 = [] if l[0].count("B") == l[0].count("R") and l[0].count("B") == l[0].count("G"): first.append(l[0][0]) types.remove(first[0]) for i in range(len(l[0])): if first[-1] == l[0][i]: counter += 1 else: first[0] = first[0] * counter break first1 = first.copy() second.append(types[0]) second[0] = second[0] * counter second1 = second.copy() third.append(types[1]) third[0] = third[0] * counter list(third) third1 = third.copy() first = first[0] + second[0] + third[0] first1 = first1[0] + third[0] + second[0] ans.append(first) ans1.append(first1) ans *= n ans1 *= n else: for i in l: countb += i.count("B") countr += i.count("R") countg += i.count("G") if countb == countr == countg: first.append(l[0]) for i in range(len(l)): if first[-1] == l[i]: first.append(l[i]) else: break first.pop(0) types.remove(first[0][0]) first1 = first.copy() second.append(0) second[0] = types[0] * len(l[0]) second *= len(first) second1 = second.copy() third.append(0) third[0] = types[1] * len(l[0]) third *= len(first) third1 = third.copy() first += second first += third first1 += third1 first1 += second1 ans = first ans1 = first1 if ans == l or ans1 == l: print("YES") exit() else: print("NO") exit()
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR LIST STRING STRING STRING ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST IF FUNC_CALL VAR NUMBER STRING FUNC_CALL VAR NUMBER STRING FUNC_CALL VAR NUMBER STRING FUNC_CALL VAR NUMBER STRING EXPR FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR FOR VAR VAR VAR FUNC_CALL VAR STRING VAR FUNC_CALL VAR STRING VAR FUNC_CALL VAR STRING IF VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER BIN_OP VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER BIN_OP VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR
The flag of Berland is such rectangular field n Γ— m that satisfies following conditions: Flag consists of three colors which correspond to letters 'R', 'G' and 'B'. Flag consists of three equal in width and height stripes, parralel to each other and to sides of the flag. Each stripe has exactly one color. Each color should be used in exactly one stripe. You are given a field n Γ— m, consisting of characters 'R', 'G' and 'B'. Output "YES" (without quotes) if this field corresponds to correct flag of Berland. Otherwise, print "NO" (without quotes). -----Input----- The first line contains two integer numbers n and m (1 ≀ n, m ≀ 100) β€” the sizes of the field. Each of the following n lines consisting of m characters 'R', 'G' and 'B' β€” the description of the field. -----Output----- Print "YES" (without quotes) if the given field corresponds to correct flag of Berland . Otherwise, print "NO" (without quotes). -----Examples----- Input 6 5 RRRRR RRRRR BBBBB BBBBB GGGGG GGGGG Output YES Input 4 3 BRG BRG BRG BRG Output YES Input 6 7 RRRGGGG RRRGGGG RRRGGGG RRRBBBB RRRBBBB RRRBBBB Output NO Input 4 4 RRRR RRRR BBBB GGGG Output NO -----Note----- The field in the third example doesn't have three parralel stripes. Rows of the field in the fourth example are parralel to each other and to borders. But they have different heights β€” 2, 1 and 1.
n, m = map(int, input().split()) flag = [list() for x in range(n)] h1 = True for i in range(n): li = input() flag[i] = li c0 = flag[0][0] line = flag[0] for j in range(1, m): if line[j] != c0: h1 = False if not h1: cc = m / 3 if m % 3 != 0: print("NO") exit() ch = "" color_ver = [] for i in range(n): line = flag[i] kol = 0 for j in range(m): if j % cc == 0: if j != 0: kol += 1 new_color = line[j] if new_color in color_ver and i == 0: print("NO") exit() else: color_ver.append(new_color) if new_color == ch: print("NO") exit() else: ch = new_color if ch != color_ver[kol]: print("NO") exit() if line[j] != ch: print("NO") exit() else: cc = n / 3 if n % 3 != 0: print("NO") exit() co = "" ch = list() kol = 0 for i in range(n): line = flag[i] if i % cc == 0: if i != 0: kol += 1 new_color = line[0] if new_color in ch: print("NO") exit() else: ch.append(new_color) if new_color != co: co = new_color else: print("NO") exit() for j in range(m): if line[j] != co: print("NO") exit() print("YES")
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR ASSIGN VAR NUMBER IF VAR ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR IF VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF BIN_OP VAR VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR STRING
The flag of Berland is such rectangular field n Γ— m that satisfies following conditions: Flag consists of three colors which correspond to letters 'R', 'G' and 'B'. Flag consists of three equal in width and height stripes, parralel to each other and to sides of the flag. Each stripe has exactly one color. Each color should be used in exactly one stripe. You are given a field n Γ— m, consisting of characters 'R', 'G' and 'B'. Output "YES" (without quotes) if this field corresponds to correct flag of Berland. Otherwise, print "NO" (without quotes). -----Input----- The first line contains two integer numbers n and m (1 ≀ n, m ≀ 100) β€” the sizes of the field. Each of the following n lines consisting of m characters 'R', 'G' and 'B' β€” the description of the field. -----Output----- Print "YES" (without quotes) if the given field corresponds to correct flag of Berland . Otherwise, print "NO" (without quotes). -----Examples----- Input 6 5 RRRRR RRRRR BBBBB BBBBB GGGGG GGGGG Output YES Input 4 3 BRG BRG BRG BRG Output YES Input 6 7 RRRGGGG RRRGGGG RRRGGGG RRRBBBB RRRBBBB RRRBBBB Output NO Input 4 4 RRRR RRRR BBBB GGGG Output NO -----Note----- The field in the third example doesn't have three parralel stripes. Rows of the field in the fourth example are parralel to each other and to borders. But they have different heights β€” 2, 1 and 1.
altura, largura = map(int, input().split()) band = [input() for i in range(altura)] new_bandeira = ["".join(coluna) for coluna in zip(*band)] def confere(bandeira, altura): flag = True for linha in bandeira: cor = linha[0] if cor * len(linha) != linha: flag = False break dicionario = {} for linha in bandeira: if linha not in dicionario: dicionario[linha] = 0 dicionario[linha] += 1 for d in dicionario: if dicionario[d] != altura / 3: flag = False ir = [] ib = [] ig = [] for i, linha in enumerate(bandeira): if linha[0] == "R": ir.append(i) if linha[0] == "B": ib.append(i) if linha[0] == "G": ig.append(i) if flag: if len(ir) == 2: if not ir[1] - ir[0] == ib[1] - ib[0] == ig[1] - ig[0] == 1: flag = False if len(ir) > 2: dif = 1 for i in range(1, len(ir)): if ir[i] - ir[i - 1] != dif: flag = False if ib[i] - ib[i - 1] != dif: flag = False if ig[i] - ig[i - 1] != dif: flag = False if flag: return True else: return False if confere(band, altura) or confere(new_bandeira, largura): print("YES") else: print("NO")
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL STRING VAR VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR VAR NUMBER IF BIN_OP VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR DICT FOR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER FOR VAR VAR IF VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER STRING EXPR FUNC_CALL VAR VAR IF VAR NUMBER STRING EXPR FUNC_CALL VAR VAR IF VAR NUMBER STRING EXPR FUNC_CALL VAR VAR IF VAR IF FUNC_CALL VAR VAR NUMBER IF BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER IF BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER IF BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER IF VAR RETURN NUMBER RETURN NUMBER IF FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
The flag of Berland is such rectangular field n Γ— m that satisfies following conditions: Flag consists of three colors which correspond to letters 'R', 'G' and 'B'. Flag consists of three equal in width and height stripes, parralel to each other and to sides of the flag. Each stripe has exactly one color. Each color should be used in exactly one stripe. You are given a field n Γ— m, consisting of characters 'R', 'G' and 'B'. Output "YES" (without quotes) if this field corresponds to correct flag of Berland. Otherwise, print "NO" (without quotes). -----Input----- The first line contains two integer numbers n and m (1 ≀ n, m ≀ 100) β€” the sizes of the field. Each of the following n lines consisting of m characters 'R', 'G' and 'B' β€” the description of the field. -----Output----- Print "YES" (without quotes) if the given field corresponds to correct flag of Berland . Otherwise, print "NO" (without quotes). -----Examples----- Input 6 5 RRRRR RRRRR BBBBB BBBBB GGGGG GGGGG Output YES Input 4 3 BRG BRG BRG BRG Output YES Input 6 7 RRRGGGG RRRGGGG RRRGGGG RRRBBBB RRRBBBB RRRBBBB Output NO Input 4 4 RRRR RRRR BBBB GGGG Output NO -----Note----- The field in the third example doesn't have three parralel stripes. Rows of the field in the fourth example are parralel to each other and to borders. But they have different heights β€” 2, 1 and 1.
def rotate_90_degree_anticlckwise(matrix): new_matrix = [] for i in range(len(matrix[0]), 0, -1): new_matrix.append(list(map(lambda x: x[i - 1], matrix))) return new_matrix n, m = map(int, input().split()) mat = [] for i in range(n): temp = input() mat.append([i for i in temp]) horiz, verti = False, False check = True resH = [] for i in range(n): if mat[i].count(mat[i][0]) == m: first = mat[i][0] if resH: if resH[-1][0] == first: resH[-1][1] += 1 else: resH.append([first, 1]) else: resH.append([first, 1]) else: check = False break if len(resH) == 3 and check: if len(set([i[1] for i in resH])) == 1 and len(set([i[0] for i in resH])) == 3: horiz = True newMat = rotate_90_degree_anticlckwise(mat) check = True resV = [] for i in range(m): if newMat[i].count(newMat[i][0]) == n: first = newMat[i][0] if resV: if resV[-1][0] == first: resV[-1][1] += 1 else: resV.append([first, 1]) else: resV.append([first, 1]) else: check = False break if len(resV) == 3 and check: if len(set([i[1] for i in resV])) == 1 and len(set([i[0] for i in resV])) == 3: verti = True if horiz or verti: print("YES") else: print("NO")
FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR VAR NUMBER VAR ASSIGN VAR VAR VAR NUMBER IF VAR IF VAR NUMBER NUMBER VAR VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR LIST VAR NUMBER EXPR FUNC_CALL VAR LIST VAR NUMBER ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR NUMBER VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR VAR NUMBER VAR ASSIGN VAR VAR VAR NUMBER IF VAR IF VAR NUMBER NUMBER VAR VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR LIST VAR NUMBER EXPR FUNC_CALL VAR LIST VAR NUMBER ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR NUMBER VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
The flag of Berland is such rectangular field n Γ— m that satisfies following conditions: Flag consists of three colors which correspond to letters 'R', 'G' and 'B'. Flag consists of three equal in width and height stripes, parralel to each other and to sides of the flag. Each stripe has exactly one color. Each color should be used in exactly one stripe. You are given a field n Γ— m, consisting of characters 'R', 'G' and 'B'. Output "YES" (without quotes) if this field corresponds to correct flag of Berland. Otherwise, print "NO" (without quotes). -----Input----- The first line contains two integer numbers n and m (1 ≀ n, m ≀ 100) β€” the sizes of the field. Each of the following n lines consisting of m characters 'R', 'G' and 'B' β€” the description of the field. -----Output----- Print "YES" (without quotes) if the given field corresponds to correct flag of Berland . Otherwise, print "NO" (without quotes). -----Examples----- Input 6 5 RRRRR RRRRR BBBBB BBBBB GGGGG GGGGG Output YES Input 4 3 BRG BRG BRG BRG Output YES Input 6 7 RRRGGGG RRRGGGG RRRGGGG RRRBBBB RRRBBBB RRRBBBB Output NO Input 4 4 RRRR RRRR BBBB GGGG Output NO -----Note----- The field in the third example doesn't have three parralel stripes. Rows of the field in the fourth example are parralel to each other and to borders. But they have different heights β€” 2, 1 and 1.
import sys n, m = map(int, input().split()) flag = [list(input()) for _ in range(n)] if len(set(flag[0])) > 1: _flag = [([""] * n) for _ in range(m)] for i in range(n): for j in range(m): _flag[j][i] = flag[i][j] flag = _flag n, m = m, n if not all(len(set(row)) == 1 for row in flag): print("NO") exit() color = {flag[0][0]} length = [1] prev = flag[0][0] for i in range(1, n): if prev == flag[i][0]: length[-1] += 1 else: prev = flag[i][0] color.add(flag[i][0]) length.append(1) if len(color) == 3 and len(length) == 3 and len(set(length)) == 1: print("YES") else: print("NO")
IMPORT ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP LIST STRING VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR VAR IF FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR LIST NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
The flag of Berland is such rectangular field n Γ— m that satisfies following conditions: Flag consists of three colors which correspond to letters 'R', 'G' and 'B'. Flag consists of three equal in width and height stripes, parralel to each other and to sides of the flag. Each stripe has exactly one color. Each color should be used in exactly one stripe. You are given a field n Γ— m, consisting of characters 'R', 'G' and 'B'. Output "YES" (without quotes) if this field corresponds to correct flag of Berland. Otherwise, print "NO" (without quotes). -----Input----- The first line contains two integer numbers n and m (1 ≀ n, m ≀ 100) β€” the sizes of the field. Each of the following n lines consisting of m characters 'R', 'G' and 'B' β€” the description of the field. -----Output----- Print "YES" (without quotes) if the given field corresponds to correct flag of Berland . Otherwise, print "NO" (without quotes). -----Examples----- Input 6 5 RRRRR RRRRR BBBBB BBBBB GGGGG GGGGG Output YES Input 4 3 BRG BRG BRG BRG Output YES Input 6 7 RRRGGGG RRRGGGG RRRGGGG RRRBBBB RRRBBBB RRRBBBB Output NO Input 4 4 RRRR RRRR BBBB GGGG Output NO -----Note----- The field in the third example doesn't have three parralel stripes. Rows of the field in the fourth example are parralel to each other and to borders. But they have different heights β€” 2, 1 and 1.
n_m = input().strip().split(" ") n = int(n_m[0]) m = int(n_m[1]) flag = [[] for x in range(n)] for i in range(n): line = input().strip() flag[i] = line horizontal = True c0 = flag[0][0] line = flag[0] for j in range(1, m): if line[j] != c0: horizontal = False if horizontal: color_change = n / 3 if n % 3 != 0: print("NO") exit() color = "" color_hor = [] count = 0 for i in range(n): line = flag[i] if i % color_change == 0: if i != 0: count += 1 new_color = line[0] if new_color in color_hor: print("NO") exit() else: color_hor.append(new_color) if new_color == color: print("NO") exit() else: color = new_color for j in range(m): if line[j] != color: print("NO") exit() else: color_change = m / 3 if m % 3 != 0: print("NO") exit() color_hor = "" color_ver = [] for i in range(n): line = flag[i] count = 0 for j in range(m): if j % color_change == 0: if j != 0: count += 1 new_color = line[j] if new_color in color_ver and i == 0: print("NO") exit() else: color_ver.append(new_color) if new_color == color_hor: print("NO") exit() else: color_hor = new_color if color_hor != color_ver[count]: print("NO") exit() if line[j] != color_hor: print("NO") exit() print("YES")
ASSIGN VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR ASSIGN VAR NUMBER IF VAR ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF BIN_OP VAR VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR IF VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR STRING
The flag of Berland is such rectangular field n Γ— m that satisfies following conditions: Flag consists of three colors which correspond to letters 'R', 'G' and 'B'. Flag consists of three equal in width and height stripes, parralel to each other and to sides of the flag. Each stripe has exactly one color. Each color should be used in exactly one stripe. You are given a field n Γ— m, consisting of characters 'R', 'G' and 'B'. Output "YES" (without quotes) if this field corresponds to correct flag of Berland. Otherwise, print "NO" (without quotes). -----Input----- The first line contains two integer numbers n and m (1 ≀ n, m ≀ 100) β€” the sizes of the field. Each of the following n lines consisting of m characters 'R', 'G' and 'B' β€” the description of the field. -----Output----- Print "YES" (without quotes) if the given field corresponds to correct flag of Berland . Otherwise, print "NO" (without quotes). -----Examples----- Input 6 5 RRRRR RRRRR BBBBB BBBBB GGGGG GGGGG Output YES Input 4 3 BRG BRG BRG BRG Output YES Input 6 7 RRRGGGG RRRGGGG RRRGGGG RRRBBBB RRRBBBB RRRBBBB Output NO Input 4 4 RRRR RRRR BBBB GGGG Output NO -----Note----- The field in the third example doesn't have three parralel stripes. Rows of the field in the fourth example are parralel to each other and to borders. But they have different heights β€” 2, 1 and 1.
def f(n, m, g): if n % 3: return False c = g[0][0] + g[n // 3][0] + g[n // 3 * 2][0] if len(set(c)) < 3: return False f = [(c[i // (n // 3)] * m) for i in range(n)] return f == g n, m = map(int, input().split()) g = [input() for i in range(n)] print( "YES" if f(n, m, g) or f(m, n, ["".join(g[i][j] for i in range(n)) for j in range(m)]) else "NO" )
FUNC_DEF IF BIN_OP VAR NUMBER RETURN NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER IF FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER RETURN NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR FUNC_CALL VAR VAR RETURN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL STRING VAR VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR STRING STRING
The flag of Berland is such rectangular field n Γ— m that satisfies following conditions: Flag consists of three colors which correspond to letters 'R', 'G' and 'B'. Flag consists of three equal in width and height stripes, parralel to each other and to sides of the flag. Each stripe has exactly one color. Each color should be used in exactly one stripe. You are given a field n Γ— m, consisting of characters 'R', 'G' and 'B'. Output "YES" (without quotes) if this field corresponds to correct flag of Berland. Otherwise, print "NO" (without quotes). -----Input----- The first line contains two integer numbers n and m (1 ≀ n, m ≀ 100) β€” the sizes of the field. Each of the following n lines consisting of m characters 'R', 'G' and 'B' β€” the description of the field. -----Output----- Print "YES" (without quotes) if the given field corresponds to correct flag of Berland . Otherwise, print "NO" (without quotes). -----Examples----- Input 6 5 RRRRR RRRRR BBBBB BBBBB GGGGG GGGGG Output YES Input 4 3 BRG BRG BRG BRG Output YES Input 6 7 RRRGGGG RRRGGGG RRRGGGG RRRBBBB RRRBBBB RRRBBBB Output NO Input 4 4 RRRR RRRR BBBB GGGG Output NO -----Note----- The field in the third example doesn't have three parralel stripes. Rows of the field in the fourth example are parralel to each other and to borders. But they have different heights β€” 2, 1 and 1.
import sys def main(): n, m = list(map(int, sys.stdin.readline().split())) if n % 3 != 0 and m % 3 != 0: print("NO") return f = [] for i in range(n): f.append(sys.stdin.readline()) ok = True if f[0][0] == f[n - 1][0]: if m % 3 != 0: ok = False else: sz = int(m / 3) if ( f[0][0] == f[0][sz] or f[0][0] == f[0][2 * sz] or f[0][2 * sz] == f[0][sz] ): ok = False else: for k in range(3): c = f[0][k * sz] for i in range(n): for j in range(k * sz, (k + 1) * sz): if c != f[i][j]: ok = False break if not ok: break if not ok: break elif n % 3 != 0: ok = False else: sz = int(n / 3) if f[0][0] == f[sz][0] or f[0][0] == f[2 * sz][0] or f[2 * sz][0] == f[sz][0]: ok = False else: for k in range(3): c = f[k * sz][0] for i in range(k * sz, (k + 1) * sz): for j in range(m): if c != f[i][j]: ok = False break if not ok: break if not ok: break if ok: print("YES") else: print("NO") main()
IMPORT FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING RETURN ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR NUMBER NUMBER VAR NUMBER VAR VAR NUMBER NUMBER VAR NUMBER BIN_OP NUMBER VAR VAR NUMBER BIN_OP NUMBER VAR VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR NUMBER BIN_OP VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR NUMBER VAR IF VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR IF VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR NUMBER NUMBER VAR VAR NUMBER VAR NUMBER NUMBER VAR BIN_OP NUMBER VAR NUMBER VAR BIN_OP NUMBER VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR IF VAR IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR
The flag of Berland is such rectangular field n Γ— m that satisfies following conditions: Flag consists of three colors which correspond to letters 'R', 'G' and 'B'. Flag consists of three equal in width and height stripes, parralel to each other and to sides of the flag. Each stripe has exactly one color. Each color should be used in exactly one stripe. You are given a field n Γ— m, consisting of characters 'R', 'G' and 'B'. Output "YES" (without quotes) if this field corresponds to correct flag of Berland. Otherwise, print "NO" (without quotes). -----Input----- The first line contains two integer numbers n and m (1 ≀ n, m ≀ 100) β€” the sizes of the field. Each of the following n lines consisting of m characters 'R', 'G' and 'B' β€” the description of the field. -----Output----- Print "YES" (without quotes) if the given field corresponds to correct flag of Berland . Otherwise, print "NO" (without quotes). -----Examples----- Input 6 5 RRRRR RRRRR BBBBB BBBBB GGGGG GGGGG Output YES Input 4 3 BRG BRG BRG BRG Output YES Input 6 7 RRRGGGG RRRGGGG RRRGGGG RRRBBBB RRRBBBB RRRBBBB Output NO Input 4 4 RRRR RRRR BBBB GGGG Output NO -----Note----- The field in the third example doesn't have three parralel stripes. Rows of the field in the fourth example are parralel to each other and to borders. But they have different heights β€” 2, 1 and 1.
def by_col(n, m, lines): orders = [None] * 3 n_div_3 = n // 3 for i in range(3): cur_char = None for j in range(n_div_3): line = lines[i * n_div_3 + j] char = line[0] if cur_char == None: cur_char = char elif char != cur_char: return "NO" if line.count(char) != m or char in orders: return "NO" orders[i] = cur_char return "YES" def by_row(n, m, lines): m_div_3 = m // 3 compare_line = None for i in range(n): line = lines[i] if compare_line == None: sub_1 = line[:m_div_3] if sub_1.count(sub_1[0]) != m_div_3: return "NO" sub_2 = line[m_div_3 : m_div_3 * 2] if sub_2.count(sub_2[0]) != m_div_3: return "NO" sub_3 = line[m_div_3 * 2 :] if sub_3.count(sub_3[0]) != m_div_3: return "NO" if sub_1 != sub_2 and sub_1 != sub_3 and sub_2 != sub_3: compare_line = line else: return "NO" elif line != compare_line: return "NO" return "YES" n, m = map(int, input().split()) n_mod_3 = n % 3 m_mod_3 = m % 3 if n_mod_3 != 0 and m_mod_3 != 0 or n < 3 and m < 3: print("NO") exit() lines = [None] * n for i in range(n): lines[i] = input() if n_mod_3 == 0 and m_mod_3 != 0: print(by_col(n, m, lines)) elif n_mod_3 != 0 and m_mod_3 == 0: print(by_row(n, m, lines)) elif by_col(n, m, lines) == "YES" or by_row(n, m, lines) == "YES": print("YES") else: print("NO")
FUNC_DEF ASSIGN VAR BIN_OP LIST NONE NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NONE FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR VAR NUMBER IF VAR NONE ASSIGN VAR VAR IF VAR VAR RETURN STRING IF FUNC_CALL VAR VAR VAR VAR VAR RETURN STRING ASSIGN VAR VAR VAR RETURN STRING FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NONE FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR NONE ASSIGN VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER VAR RETURN STRING ASSIGN VAR VAR VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR NUMBER VAR RETURN STRING ASSIGN VAR VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR NUMBER VAR RETURN STRING IF VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR RETURN STRING IF VAR VAR RETURN STRING RETURN STRING ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NONE VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR IF FUNC_CALL VAR VAR VAR VAR STRING FUNC_CALL VAR VAR VAR VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
The flag of Berland is such rectangular field n Γ— m that satisfies following conditions: Flag consists of three colors which correspond to letters 'R', 'G' and 'B'. Flag consists of three equal in width and height stripes, parralel to each other and to sides of the flag. Each stripe has exactly one color. Each color should be used in exactly one stripe. You are given a field n Γ— m, consisting of characters 'R', 'G' and 'B'. Output "YES" (without quotes) if this field corresponds to correct flag of Berland. Otherwise, print "NO" (without quotes). -----Input----- The first line contains two integer numbers n and m (1 ≀ n, m ≀ 100) β€” the sizes of the field. Each of the following n lines consisting of m characters 'R', 'G' and 'B' β€” the description of the field. -----Output----- Print "YES" (without quotes) if the given field corresponds to correct flag of Berland . Otherwise, print "NO" (without quotes). -----Examples----- Input 6 5 RRRRR RRRRR BBBBB BBBBB GGGGG GGGGG Output YES Input 4 3 BRG BRG BRG BRG Output YES Input 6 7 RRRGGGG RRRGGGG RRRGGGG RRRBBBB RRRBBBB RRRBBBB Output NO Input 4 4 RRRR RRRR BBBB GGGG Output NO -----Note----- The field in the third example doesn't have three parralel stripes. Rows of the field in the fourth example are parralel to each other and to borders. But they have different heights β€” 2, 1 and 1.
a, b = map(int, input().split()) rows = [list(input()) for x in range(a)] columns = [[x[y] for x in rows] for y in range(b)] def check(l): line = [] for x in l: p = x[0] for y in x: if y != p: break else: line.append(p) continue return [False, line] else: return [True, line] def colors(c, l): p = c[1][0] n = 0 colors = [] for x in c[1]: if x != p: colors.append([p, n]) p = x n = 1 else: n += 1 colors.append([p, n]) if len(colors) == 3 and l % 3 == 0: m = l // 3 letters = ["R", "G", "B"] for x in colors: p, q = x[0], x[1] if x[0] in letters and q == m: letters.remove(x[0]) else: return False break else: return True else: return False condition = False if a % 3 == 0 or b % 3 == 0: c, d = check(rows), check(columns) if c[0]: condition = colors(c, a) if not condition and d[0]: condition = colors(d, b) if condition: print("YES") else: print("NO")
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR VAR NUMBER FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR RETURN LIST NUMBER VAR RETURN LIST NUMBER VAR FUNC_DEF ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR LIST VAR VAR IF FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR LIST STRING STRING STRING FOR VAR VAR ASSIGN VAR VAR VAR NUMBER VAR NUMBER IF VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER RETURN NUMBER RETURN NUMBER RETURN NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
The flag of Berland is such rectangular field n Γ— m that satisfies following conditions: Flag consists of three colors which correspond to letters 'R', 'G' and 'B'. Flag consists of three equal in width and height stripes, parralel to each other and to sides of the flag. Each stripe has exactly one color. Each color should be used in exactly one stripe. You are given a field n Γ— m, consisting of characters 'R', 'G' and 'B'. Output "YES" (without quotes) if this field corresponds to correct flag of Berland. Otherwise, print "NO" (without quotes). -----Input----- The first line contains two integer numbers n and m (1 ≀ n, m ≀ 100) β€” the sizes of the field. Each of the following n lines consisting of m characters 'R', 'G' and 'B' β€” the description of the field. -----Output----- Print "YES" (without quotes) if the given field corresponds to correct flag of Berland . Otherwise, print "NO" (without quotes). -----Examples----- Input 6 5 RRRRR RRRRR BBBBB BBBBB GGGGG GGGGG Output YES Input 4 3 BRG BRG BRG BRG Output YES Input 6 7 RRRGGGG RRRGGGG RRRGGGG RRRBBBB RRRBBBB RRRBBBB Output NO Input 4 4 RRRR RRRR BBBB GGGG Output NO -----Note----- The field in the third example doesn't have three parralel stripes. Rows of the field in the fourth example are parralel to each other and to borders. But they have different heights β€” 2, 1 and 1.
n, m = list(map(int, input().split())) res = max(n, m) >= 3 is_horo = True is_vert = True if res: flag = [] for i in range(n): r = input() if len(r) != m: res = False break flag.append(list(r)) px = flag[0][0] for i in range(1, m): if flag[0][i] != px: is_horo = False break for i in range(1, n): if flag[i][0] != px: is_vert = False break res = is_horo ^ is_vert compressed = [] if res: if is_horo: for r in flag: px = r[0] for c in r[1:]: if c != px: res = False break compressed.append(px) elif is_vert: for i in range(m): px = flag[0][i] for j in range(1, n): if flag[j][i] != px: res = False break compressed.append(px) if res and compressed: stripe_width = None c_stripe = None c_width = 0 widths = [] seen = set() for stripe in compressed: if c_stripe is None: c_stripe = stripe c_width = 1 elif c_stripe != stripe: seen.add(c_stripe) widths.append(c_width) c_width = 1 c_stripe = stripe else: c_width += 1 widths.append(c_width) seen.add(c_stripe) if len(widths) != 3 or len(seen) != 3: res = False else: first = widths[0] for i in range(1, len(widths)): if widths[i] != first: res = False break print("YES" if res else "NO")
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR NUMBER VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR LIST IF VAR IF VAR FOR VAR VAR ASSIGN VAR VAR NUMBER FOR VAR VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR NONE ASSIGN VAR NONE ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FOR VAR VAR IF VAR NONE ASSIGN VAR VAR ASSIGN VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR STRING STRING
The flag of Berland is such rectangular field n Γ— m that satisfies following conditions: Flag consists of three colors which correspond to letters 'R', 'G' and 'B'. Flag consists of three equal in width and height stripes, parralel to each other and to sides of the flag. Each stripe has exactly one color. Each color should be used in exactly one stripe. You are given a field n Γ— m, consisting of characters 'R', 'G' and 'B'. Output "YES" (without quotes) if this field corresponds to correct flag of Berland. Otherwise, print "NO" (without quotes). -----Input----- The first line contains two integer numbers n and m (1 ≀ n, m ≀ 100) β€” the sizes of the field. Each of the following n lines consisting of m characters 'R', 'G' and 'B' β€” the description of the field. -----Output----- Print "YES" (without quotes) if the given field corresponds to correct flag of Berland . Otherwise, print "NO" (without quotes). -----Examples----- Input 6 5 RRRRR RRRRR BBBBB BBBBB GGGGG GGGGG Output YES Input 4 3 BRG BRG BRG BRG Output YES Input 6 7 RRRGGGG RRRGGGG RRRGGGG RRRBBBB RRRBBBB RRRBBBB Output NO Input 4 4 RRRR RRRR BBBB GGGG Output NO -----Note----- The field in the third example doesn't have three parralel stripes. Rows of the field in the fourth example are parralel to each other and to borders. But they have different heights β€” 2, 1 and 1.
def tran(lis, b, n, m): for i in range(m): for j in range(n): b[i][j] = lis[j][i] def call(n, lis): ans = [] cv = 1 for i in range(0, n, n // 3): a = [] for j in range(n // 3): a += lis[i + j] a = set(a) if len(a) > 1: cv = 0 break b = list(a)[0] ans.append(b) if len(set(ans)) != 3: cv = 0 if cv == 1: print("YES") exit() n, m = map(int, input().split()) lis = [] b = [[(0) for x in range(n)] for y in range(m)] for i in range(n): l = list(input()) lis.append(l) if n % 3 != 0 and m % 3 != 0: print("NO") exit() if n % 3 == 0: call(n, lis) if m % 3 == 0: tran(lis, b, n, m) call(m, b) print("NO")
FUNC_DEF FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR FUNC_DEF ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR STRING
The flag of Berland is such rectangular field n Γ— m that satisfies following conditions: Flag consists of three colors which correspond to letters 'R', 'G' and 'B'. Flag consists of three equal in width and height stripes, parralel to each other and to sides of the flag. Each stripe has exactly one color. Each color should be used in exactly one stripe. You are given a field n Γ— m, consisting of characters 'R', 'G' and 'B'. Output "YES" (without quotes) if this field corresponds to correct flag of Berland. Otherwise, print "NO" (without quotes). -----Input----- The first line contains two integer numbers n and m (1 ≀ n, m ≀ 100) β€” the sizes of the field. Each of the following n lines consisting of m characters 'R', 'G' and 'B' β€” the description of the field. -----Output----- Print "YES" (without quotes) if the given field corresponds to correct flag of Berland . Otherwise, print "NO" (without quotes). -----Examples----- Input 6 5 RRRRR RRRRR BBBBB BBBBB GGGGG GGGGG Output YES Input 4 3 BRG BRG BRG BRG Output YES Input 6 7 RRRGGGG RRRGGGG RRRGGGG RRRBBBB RRRBBBB RRRBBBB Output NO Input 4 4 RRRR RRRR BBBB GGGG Output NO -----Note----- The field in the third example doesn't have three parralel stripes. Rows of the field in the fourth example are parralel to each other and to borders. But they have different heights β€” 2, 1 and 1.
def check_flag(flag, n, m): if n % 3 > 0 and m % 3 > 0: return False if n % 3 == 0: nrows = int(n / 3) set1 = set("".join(flag[:nrows])) set2 = set("".join(flag[nrows : 2 * nrows])) set3 = set("".join(flag[2 * nrows :])) if ( len(set1) + len(set2) + len(set3) == 3 and len(set1.union(set2.union(set3))) == 3 ): return True if m % 3 == 0: ncols = int(m / 3) set1 = set("".join([row[:ncols] for row in flag])) set2 = set("".join([row[ncols : 2 * ncols] for row in flag])) set3 = set("".join([row[2 * ncols :] for row in flag])) if ( len(set1) + len(set2) + len(set3) == 3 and len(set1.union(set2.union(set3))) == 3 ): return True return False n, m = [int(i) for i in input().strip(" ").split(" ")] flag = [] for _ in range(n): flag.append(input().strip(" ")) if check_flag(flag, n, m): print("YES") else: print("NO")
FUNC_DEF IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER RETURN NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL STRING VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL STRING VAR VAR BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL STRING VAR BIN_OP NUMBER VAR IF BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER RETURN NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL STRING VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL STRING VAR VAR BIN_OP NUMBER VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL STRING VAR BIN_OP NUMBER VAR VAR VAR IF BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER RETURN NUMBER RETURN NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING STRING ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR STRING IF FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
The flag of Berland is such rectangular field n Γ— m that satisfies following conditions: Flag consists of three colors which correspond to letters 'R', 'G' and 'B'. Flag consists of three equal in width and height stripes, parralel to each other and to sides of the flag. Each stripe has exactly one color. Each color should be used in exactly one stripe. You are given a field n Γ— m, consisting of characters 'R', 'G' and 'B'. Output "YES" (without quotes) if this field corresponds to correct flag of Berland. Otherwise, print "NO" (without quotes). -----Input----- The first line contains two integer numbers n and m (1 ≀ n, m ≀ 100) β€” the sizes of the field. Each of the following n lines consisting of m characters 'R', 'G' and 'B' β€” the description of the field. -----Output----- Print "YES" (without quotes) if the given field corresponds to correct flag of Berland . Otherwise, print "NO" (without quotes). -----Examples----- Input 6 5 RRRRR RRRRR BBBBB BBBBB GGGGG GGGGG Output YES Input 4 3 BRG BRG BRG BRG Output YES Input 6 7 RRRGGGG RRRGGGG RRRGGGG RRRBBBB RRRBBBB RRRBBBB Output NO Input 4 4 RRRR RRRR BBBB GGGG Output NO -----Note----- The field in the third example doesn't have three parralel stripes. Rows of the field in the fourth example are parralel to each other and to borders. But they have different heights β€” 2, 1 and 1.
from sys import stdin n, m = map(int, stdin.readline().rstrip().split()) data = [] for i in range(0, n): data.append(stdin.readline().rstrip()) if n % 3 != 0 and m % 3 != 0: print("No") exit(0) def check_ver(): if n % 3 == 0: num = n // 3 ccc = [data[0][0], data[num][0], data[num * 2][0]] if "R" not in ccc or "G" not in ccc or "B" not in ccc: return False for i in range(0, n): if data[i] != ccc[i // num] * m: return False return True else: return False def check_hor(): if m % 3 == 0: num = m // 3 ccc = [data[0][0], data[0][num], data[0][num * 2]] if "R" not in ccc or "G" not in ccc or "B" not in ccc: return False for i in range(0, m): col = "" for j in range(0, n): col += data[j][i] if col != ccc[i // num] * n: return False return True else: return False ver_rs = check_ver() hor_rs = check_hor() if ver_rs or hor_rs: print("YES") else: print("No")
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER FUNC_DEF IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR LIST VAR NUMBER NUMBER VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER IF STRING VAR STRING VAR STRING VAR RETURN NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR BIN_OP VAR BIN_OP VAR VAR VAR RETURN NUMBER RETURN NUMBER RETURN NUMBER FUNC_DEF IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR LIST VAR NUMBER NUMBER VAR NUMBER VAR VAR NUMBER BIN_OP VAR NUMBER IF STRING VAR STRING VAR STRING VAR RETURN NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR VAR IF VAR BIN_OP VAR BIN_OP VAR VAR VAR RETURN NUMBER RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
The flag of Berland is such rectangular field n Γ— m that satisfies following conditions: Flag consists of three colors which correspond to letters 'R', 'G' and 'B'. Flag consists of three equal in width and height stripes, parralel to each other and to sides of the flag. Each stripe has exactly one color. Each color should be used in exactly one stripe. You are given a field n Γ— m, consisting of characters 'R', 'G' and 'B'. Output "YES" (without quotes) if this field corresponds to correct flag of Berland. Otherwise, print "NO" (without quotes). -----Input----- The first line contains two integer numbers n and m (1 ≀ n, m ≀ 100) β€” the sizes of the field. Each of the following n lines consisting of m characters 'R', 'G' and 'B' β€” the description of the field. -----Output----- Print "YES" (without quotes) if the given field corresponds to correct flag of Berland . Otherwise, print "NO" (without quotes). -----Examples----- Input 6 5 RRRRR RRRRR BBBBB BBBBB GGGGG GGGGG Output YES Input 4 3 BRG BRG BRG BRG Output YES Input 6 7 RRRGGGG RRRGGGG RRRGGGG RRRBBBB RRRBBBB RRRBBBB Output NO Input 4 4 RRRR RRRR BBBB GGGG Output NO -----Note----- The field in the third example doesn't have three parralel stripes. Rows of the field in the fourth example are parralel to each other and to borders. But they have different heights β€” 2, 1 and 1.
import itertools import sys def check(lst): if not all(row.count(row[0]) == len(row) for row in lst): return False _ = [[k, list(g)] for k, g in itertools.groupby([x[0] for x in lst])] keys, groups = zip(*_) keys = list(keys) return ( len(keys) == len(set(keys)) == 3 and len(set([len(list(x)) for x in groups])) == 1 ) nrow, ncol = map(int, sys.stdin.readline().split(" ")) data = list(map(list, sys.stdin.read().split("\n")[:nrow])) sys.stdout.write("YES" if check(data) or check(list(zip(*data))) else "NO")
IMPORT IMPORT FUNC_DEF IF FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR VAR VAR RETURN NUMBER ASSIGN VAR LIST VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR NUMBER VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR RETURN FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR STRING STRING
The flag of Berland is such rectangular field n Γ— m that satisfies following conditions: Flag consists of three colors which correspond to letters 'R', 'G' and 'B'. Flag consists of three equal in width and height stripes, parralel to each other and to sides of the flag. Each stripe has exactly one color. Each color should be used in exactly one stripe. You are given a field n Γ— m, consisting of characters 'R', 'G' and 'B'. Output "YES" (without quotes) if this field corresponds to correct flag of Berland. Otherwise, print "NO" (without quotes). -----Input----- The first line contains two integer numbers n and m (1 ≀ n, m ≀ 100) β€” the sizes of the field. Each of the following n lines consisting of m characters 'R', 'G' and 'B' β€” the description of the field. -----Output----- Print "YES" (without quotes) if the given field corresponds to correct flag of Berland . Otherwise, print "NO" (without quotes). -----Examples----- Input 6 5 RRRRR RRRRR BBBBB BBBBB GGGGG GGGGG Output YES Input 4 3 BRG BRG BRG BRG Output YES Input 6 7 RRRGGGG RRRGGGG RRRGGGG RRRBBBB RRRBBBB RRRBBBB Output NO Input 4 4 RRRR RRRR BBBB GGGG Output NO -----Note----- The field in the third example doesn't have three parralel stripes. Rows of the field in the fourth example are parralel to each other and to borders. But they have different heights β€” 2, 1 and 1.
n, m = map(int, input().split()) if n * m % 3 != 0: print("NO") else: ans = "NO" f = [input() for _ in range(n)] if n % 3 == 0: for x in f: if len(set(x)) != 1: pass break else: if any( len(set(f[n * (i - 1) // 3 : n * i // 3])) != 1 for i in range(1, 4) ): pass elif len(set([f[0], f[n // 3], f[2 * n // 3]])) != 3: pass else: ans = "YES" if m % 3 == 0: c = [] for x in range(m): s = "" for y in range(n): s += f[y][x] c.append(s) for x in c: if len(set(x)) != 1: pass break else: if any( len(set(c[m * (i - 1) // 3 : m * i // 3])) != 1 for i in range(1, 3) ): pass elif len(set([c[0], c[m // 3], c[2 * m // 3]])) != 3: pass else: ans = "YES" print(ans)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER FOR VAR VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR FUNC_CALL VAR NUMBER NUMBER IF FUNC_CALL VAR FUNC_CALL VAR LIST VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP NUMBER VAR NUMBER NUMBER ASSIGN VAR STRING IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR FUNC_CALL VAR NUMBER NUMBER IF FUNC_CALL VAR FUNC_CALL VAR LIST VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP NUMBER VAR NUMBER NUMBER ASSIGN VAR STRING EXPR FUNC_CALL VAR VAR
The flag of Berland is such rectangular field n Γ— m that satisfies following conditions: Flag consists of three colors which correspond to letters 'R', 'G' and 'B'. Flag consists of three equal in width and height stripes, parralel to each other and to sides of the flag. Each stripe has exactly one color. Each color should be used in exactly one stripe. You are given a field n Γ— m, consisting of characters 'R', 'G' and 'B'. Output "YES" (without quotes) if this field corresponds to correct flag of Berland. Otherwise, print "NO" (without quotes). -----Input----- The first line contains two integer numbers n and m (1 ≀ n, m ≀ 100) β€” the sizes of the field. Each of the following n lines consisting of m characters 'R', 'G' and 'B' β€” the description of the field. -----Output----- Print "YES" (without quotes) if the given field corresponds to correct flag of Berland . Otherwise, print "NO" (without quotes). -----Examples----- Input 6 5 RRRRR RRRRR BBBBB BBBBB GGGGG GGGGG Output YES Input 4 3 BRG BRG BRG BRG Output YES Input 6 7 RRRGGGG RRRGGGG RRRGGGG RRRBBBB RRRBBBB RRRBBBB Output NO Input 4 4 RRRR RRRR BBBB GGGG Output NO -----Note----- The field in the third example doesn't have three parralel stripes. Rows of the field in the fourth example are parralel to each other and to borders. But they have different heights β€” 2, 1 and 1.
def check(b): i = len(b[0]) // 3 c = [b[0][0], b[0][i], b[0][2 * i]] if len(set(c)) != 3: return 0 j = 0 for p in range(len(b)): j = 0 for k in range(3): if len(set(b[p][j : j + i])) == 1 and set(b[p][j : j + i]) == {c[k]}: j += i continue else: return 0 return 1 n, m = map(int, input().split()) a = [input() for i in range(n)] if n % 3 != 0 and m % 3 != 0: print("NO") elif n % 3 == 0 and m % 3 == 0: if check(a) or check(list(map(list, zip(*a)))): print("YES") else: print("NO") elif n % 3 == 0: if check(list(map(list, zip(*a)))): print("YES") else: print("NO") elif m % 3 == 0: if check(a): print("YES") else: print("NO")
FUNC_DEF ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR LIST VAR NUMBER NUMBER VAR NUMBER VAR VAR NUMBER BIN_OP NUMBER VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR VAR NUMBER FUNC_CALL VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF BIN_OP VAR NUMBER NUMBER IF FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF BIN_OP VAR NUMBER NUMBER IF FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
The flag of Berland is such rectangular field n Γ— m that satisfies following conditions: Flag consists of three colors which correspond to letters 'R', 'G' and 'B'. Flag consists of three equal in width and height stripes, parralel to each other and to sides of the flag. Each stripe has exactly one color. Each color should be used in exactly one stripe. You are given a field n Γ— m, consisting of characters 'R', 'G' and 'B'. Output "YES" (without quotes) if this field corresponds to correct flag of Berland. Otherwise, print "NO" (without quotes). -----Input----- The first line contains two integer numbers n and m (1 ≀ n, m ≀ 100) β€” the sizes of the field. Each of the following n lines consisting of m characters 'R', 'G' and 'B' β€” the description of the field. -----Output----- Print "YES" (without quotes) if the given field corresponds to correct flag of Berland . Otherwise, print "NO" (without quotes). -----Examples----- Input 6 5 RRRRR RRRRR BBBBB BBBBB GGGGG GGGGG Output YES Input 4 3 BRG BRG BRG BRG Output YES Input 6 7 RRRGGGG RRRGGGG RRRGGGG RRRBBBB RRRBBBB RRRBBBB Output NO Input 4 4 RRRR RRRR BBBB GGGG Output NO -----Note----- The field in the third example doesn't have three parralel stripes. Rows of the field in the fourth example are parralel to each other and to borders. But they have different heights β€” 2, 1 and 1.
import sys n, m = map(int, input().split()) li = [] for _ in range(n): li.append(input()) if n % 3 == 0: flag = True stripe = n // 3 s0 = li[0][0] s1 = li[stripe][0] s2 = li[stripe * 2][0] for i in range(stripe): for j in range(m): if li[i][j] != s0: flag = False for i in range(stripe, 2 * stripe): for j in range(m): if li[i][j] != s1: flag = False for i in range(2 * stripe, 3 * stripe): for j in range(m): if li[i][j] != s2: flag = False if flag == True and s0 != s1 and s0 != s2 and s1 != s2: print("YES") sys.exit() if m % 3 == 0: flag = True stripe = m // 3 s0 = li[0][0] s1 = li[0][stripe] s2 = li[0][stripe * 2] for i in range(n): for j in range(stripe): if li[i][j] != s0: flag = False for i in range(n): for j in range(stripe, 2 * stripe): if li[i][j] != s1: flag = False for i in range(n): for j in range(2 * stripe, 3 * stripe): if li[i][j] != s2: flag = False if flag == True and s0 != s1 and s0 != s2 and s1 != s2: print("YES") sys.exit() print("NO")
IMPORT ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR BIN_OP NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER VAR ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP NUMBER VAR IF VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR BIN_OP NUMBER VAR IF VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR STRING
The flag of Berland is such rectangular field n Γ— m that satisfies following conditions: Flag consists of three colors which correspond to letters 'R', 'G' and 'B'. Flag consists of three equal in width and height stripes, parralel to each other and to sides of the flag. Each stripe has exactly one color. Each color should be used in exactly one stripe. You are given a field n Γ— m, consisting of characters 'R', 'G' and 'B'. Output "YES" (without quotes) if this field corresponds to correct flag of Berland. Otherwise, print "NO" (without quotes). -----Input----- The first line contains two integer numbers n and m (1 ≀ n, m ≀ 100) β€” the sizes of the field. Each of the following n lines consisting of m characters 'R', 'G' and 'B' β€” the description of the field. -----Output----- Print "YES" (without quotes) if the given field corresponds to correct flag of Berland . Otherwise, print "NO" (without quotes). -----Examples----- Input 6 5 RRRRR RRRRR BBBBB BBBBB GGGGG GGGGG Output YES Input 4 3 BRG BRG BRG BRG Output YES Input 6 7 RRRGGGG RRRGGGG RRRGGGG RRRBBBB RRRBBBB RRRBBBB Output NO Input 4 4 RRRR RRRR BBBB GGGG Output NO -----Note----- The field in the third example doesn't have three parralel stripes. Rows of the field in the fourth example are parralel to each other and to borders. But they have different heights β€” 2, 1 and 1.
n, m = map(int, input().split()) a = [] s = "" for i in range(n): a.append(input()) s += a[i] s1 = "" for i in range(m): for j in range(n): s1 += a[j][i] f, f1 = True, True v = [] v1 = [] if s[0 : n * m // 3] == s[0] * (n * m // 3): v.append(s[0]) else: f = False if s1[0 : n * m // 3] == s1[0] * (n * m // 3): v1.append(s1[0]) else: f1 = False if s[n * m // 3 : n * m // 3 * 2] == s[n * m // 3] * (n * m // 3): v.append(s[n * m // 3]) else: f = False if s1[n * m // 3 : n * m // 3 * 2] == s1[n * m // 3] * (n * m // 3): v1.append(s1[n * m // 3]) else: f1 = False if s[n * m // 3 * 2 : n * m] == s[n * m // 3 * 2] * (n * m // 3): v.append(s[n * m // 3 * 2]) else: f = False if s1[n * m // 3 * 2 : n * m] == s1[n * m // 3 * 2] * (n * m // 3): v1.append(s1[n * m // 3 * 2]) else: f1 = False v.sort() v1.sort() if f and v == ["B", "G", "R"]: print("YES") elif f1 and v1 == ["B", "G", "R"]: print("YES") else: print("NO")
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR LIST ASSIGN VAR LIST IF VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER BIN_OP VAR VAR BIN_OP VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER IF VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER BIN_OP VAR VAR BIN_OP VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR IF VAR VAR LIST STRING STRING STRING EXPR FUNC_CALL VAR STRING IF VAR VAR LIST STRING STRING STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
The flag of Berland is such rectangular field n Γ— m that satisfies following conditions: Flag consists of three colors which correspond to letters 'R', 'G' and 'B'. Flag consists of three equal in width and height stripes, parralel to each other and to sides of the flag. Each stripe has exactly one color. Each color should be used in exactly one stripe. You are given a field n Γ— m, consisting of characters 'R', 'G' and 'B'. Output "YES" (without quotes) if this field corresponds to correct flag of Berland. Otherwise, print "NO" (without quotes). -----Input----- The first line contains two integer numbers n and m (1 ≀ n, m ≀ 100) β€” the sizes of the field. Each of the following n lines consisting of m characters 'R', 'G' and 'B' β€” the description of the field. -----Output----- Print "YES" (without quotes) if the given field corresponds to correct flag of Berland . Otherwise, print "NO" (without quotes). -----Examples----- Input 6 5 RRRRR RRRRR BBBBB BBBBB GGGGG GGGGG Output YES Input 4 3 BRG BRG BRG BRG Output YES Input 6 7 RRRGGGG RRRGGGG RRRGGGG RRRBBBB RRRBBBB RRRBBBB Output NO Input 4 4 RRRR RRRR BBBB GGGG Output NO -----Note----- The field in the third example doesn't have three parralel stripes. Rows of the field in the fourth example are parralel to each other and to borders. But they have different heights β€” 2, 1 and 1.
n, m = map(int, input().split()) A = [(0) for i in range(n)] for i in range(n): A[i] = input() f1, f2 = True, True colors = ["R", "G", "B"] if n % 3 != 0: f1 = False else: for i in range(3): if A[n // 3 * i][0] in colors: qq = A[n // 3 * i][0] colors.remove(A[n // 3 * i][0]) else: f1 = False for j in range(n // 3 * i, n // 3 * (i + 1)): if A[j][0] != qq: f1 = False break for k in A[j]: if k != A[j][0]: f1 = False break colors = ["R", "G", "B"] if m % 3 != 0: f2 = False else: for i in range(3): if A[0][m // 3 * i] in colors: qq = A[0][m // 3 * i] colors.remove(A[0][m // 3 * i]) else: f2 = False for j in range(m // 3 * i, m // 3 * (i + 1)): if A[0][j] != qq: f2 = False break for k in range(n): if A[k][j] != A[0][j]: f2 = False break if f1 or f2: print("YES") else: print("NO")
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR LIST STRING STRING STRING IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST STRING STRING STRING IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR NUMBER BIN_OP BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR NUMBER BIN_OP BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR NUMBER BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR NUMBER VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER VAR ASSIGN VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
The flag of Berland is such rectangular field n Γ— m that satisfies following conditions: Flag consists of three colors which correspond to letters 'R', 'G' and 'B'. Flag consists of three equal in width and height stripes, parralel to each other and to sides of the flag. Each stripe has exactly one color. Each color should be used in exactly one stripe. You are given a field n Γ— m, consisting of characters 'R', 'G' and 'B'. Output "YES" (without quotes) if this field corresponds to correct flag of Berland. Otherwise, print "NO" (without quotes). -----Input----- The first line contains two integer numbers n and m (1 ≀ n, m ≀ 100) β€” the sizes of the field. Each of the following n lines consisting of m characters 'R', 'G' and 'B' β€” the description of the field. -----Output----- Print "YES" (without quotes) if the given field corresponds to correct flag of Berland . Otherwise, print "NO" (without quotes). -----Examples----- Input 6 5 RRRRR RRRRR BBBBB BBBBB GGGGG GGGGG Output YES Input 4 3 BRG BRG BRG BRG Output YES Input 6 7 RRRGGGG RRRGGGG RRRGGGG RRRBBBB RRRBBBB RRRBBBB Output NO Input 4 4 RRRR RRRR BBBB GGGG Output NO -----Note----- The field in the third example doesn't have three parralel stripes. Rows of the field in the fourth example are parralel to each other and to borders. But they have different heights β€” 2, 1 and 1.
n, m = list(map(int, input().split())) c = [list(input()) for _ in range(n)] ans = "NO" if n % 3 == 0: l = [] for i in range(3): s = set([]) for j in range(i * n // 3, (i + 1) * n // 3): for k in range(m): s.add(c[j][k]) if len(s) == 1: l.append(s.pop()) if sorted(l) == ["B", "G", "R"]: ans = "YES" if m % 3 == 0: l = [] for i in range(3): s = set([]) for j in range(i * m // 3, (i + 1) * m // 3): for k in range(n): s.add(c[k][j]) if len(s) == 1: l.append(s.pop()) if sorted(l) == ["B", "G", "R"]: ans = "YES" print(ans)
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR STRING IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR LIST FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR LIST STRING STRING STRING ASSIGN VAR STRING IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR LIST FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR LIST STRING STRING STRING ASSIGN VAR STRING EXPR FUNC_CALL VAR VAR
The flag of Berland is such rectangular field n Γ— m that satisfies following conditions: Flag consists of three colors which correspond to letters 'R', 'G' and 'B'. Flag consists of three equal in width and height stripes, parralel to each other and to sides of the flag. Each stripe has exactly one color. Each color should be used in exactly one stripe. You are given a field n Γ— m, consisting of characters 'R', 'G' and 'B'. Output "YES" (without quotes) if this field corresponds to correct flag of Berland. Otherwise, print "NO" (without quotes). -----Input----- The first line contains two integer numbers n and m (1 ≀ n, m ≀ 100) β€” the sizes of the field. Each of the following n lines consisting of m characters 'R', 'G' and 'B' β€” the description of the field. -----Output----- Print "YES" (without quotes) if the given field corresponds to correct flag of Berland . Otherwise, print "NO" (without quotes). -----Examples----- Input 6 5 RRRRR RRRRR BBBBB BBBBB GGGGG GGGGG Output YES Input 4 3 BRG BRG BRG BRG Output YES Input 6 7 RRRGGGG RRRGGGG RRRGGGG RRRBBBB RRRBBBB RRRBBBB Output NO Input 4 4 RRRR RRRR BBBB GGGG Output NO -----Note----- The field in the third example doesn't have three parralel stripes. Rows of the field in the fourth example are parralel to each other and to borders. But they have different heights β€” 2, 1 and 1.
height, width = map(int, input().split()) a = [input() for i in range(height)] c = {"r": 0, "g": 0, "b": 0} p = {"r": 0, "g": 0, "b": 0} color = {"r": False, "g": False, "b": False} horizontal, vertical = True, False for i in range(height): for j in range(width): color[a[i][j].lower()] = True for i in range(height): for j in range(1, width): if a[i][j] != a[i][j - 1]: horizontal = False break c[a[i][j].lower()] += 1 if not horizontal: vertical = True for key in c.keys(): c[key] = 0 for i in range(width): for j in range(1, height): if a[j][i] != a[j - 1][i]: vertical = False break c[a[j][i].lower()] += 1 prev = None if horizontal: for i in range(height): if prev is None: prev = a[i][0].lower() c[a[i][0].lower()] += 1 p[a[i][0].lower()] += 1 else: if prev != a[i][0].lower(): p[a[i][0].lower()] += 1 if p[a[i][0].lower()] >= 2: print("NO") exit() prev = a[i][0].lower() c[a[i][0].lower()] += 1 elif vertical: for i in range(width): if prev is None: prev = a[0][i].lower() c[a[0][i].lower()] += 1 else: if prev != a[0][i].lower(): p[a[0][i].lower()] += 1 if p[a[0][i].lower()] >= 2: print("NO") exit() prev = a[0][i].lower() c[a[0][i].lower()] += 1 else: print("NO") exit() if c["r"] == c["g"] == c["b"] and color["r"] and color["g"] and color["b"]: print("YES") else: print("NO")
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR DICT STRING STRING STRING NUMBER NUMBER NUMBER ASSIGN VAR DICT STRING STRING STRING NUMBER NUMBER NUMBER ASSIGN VAR DICT STRING STRING STRING NUMBER NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NONE IF VAR FOR VAR FUNC_CALL VAR VAR IF VAR NONE ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER NUMBER VAR FUNC_CALL VAR VAR NUMBER NUMBER IF VAR FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER NUMBER IF VAR FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER NUMBER IF VAR FOR VAR FUNC_CALL VAR VAR IF VAR NONE ASSIGN VAR FUNC_CALL VAR NUMBER VAR VAR FUNC_CALL VAR NUMBER VAR NUMBER IF VAR FUNC_CALL VAR NUMBER VAR VAR FUNC_CALL VAR NUMBER VAR NUMBER IF VAR FUNC_CALL VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR NUMBER VAR VAR FUNC_CALL VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR IF VAR STRING VAR STRING VAR STRING VAR STRING VAR STRING VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
The flag of Berland is such rectangular field n Γ— m that satisfies following conditions: Flag consists of three colors which correspond to letters 'R', 'G' and 'B'. Flag consists of three equal in width and height stripes, parralel to each other and to sides of the flag. Each stripe has exactly one color. Each color should be used in exactly one stripe. You are given a field n Γ— m, consisting of characters 'R', 'G' and 'B'. Output "YES" (without quotes) if this field corresponds to correct flag of Berland. Otherwise, print "NO" (without quotes). -----Input----- The first line contains two integer numbers n and m (1 ≀ n, m ≀ 100) β€” the sizes of the field. Each of the following n lines consisting of m characters 'R', 'G' and 'B' β€” the description of the field. -----Output----- Print "YES" (without quotes) if the given field corresponds to correct flag of Berland . Otherwise, print "NO" (without quotes). -----Examples----- Input 6 5 RRRRR RRRRR BBBBB BBBBB GGGGG GGGGG Output YES Input 4 3 BRG BRG BRG BRG Output YES Input 6 7 RRRGGGG RRRGGGG RRRGGGG RRRBBBB RRRBBBB RRRBBBB Output NO Input 4 4 RRRR RRRR BBBB GGGG Output NO -----Note----- The field in the third example doesn't have three parralel stripes. Rows of the field in the fourth example are parralel to each other and to borders. But they have different heights β€” 2, 1 and 1.
list_1 = [] list_2 = [] index_n = 0 index_m = 0 n, m = map(int, input().split()) for i in range(n): ch1 = str(input()) list_1.append(ch1) if n % 3 != 0: index_n = 1 if m % 3 != 0: index_m = 1 if n % 3 == 0: a = n / 3 for i in range(n): ch1 = list_1[i] if i % a == 0: ch2 = ch1 list_2.append(ch2[0]) for j in range(m - 1): if ch2[j] != ch2[j + 1]: index_n = 1 if ch2 != ch1: index_n = 1 if "R" in list_2 and "G" in list_2 and "B" in list_2: b = 1 else: index_n = 1 list_2 = [] if m % 3 == 0: a = int(m / 3) ch1 = list_1[0] for i in range(3): for j in range(a): if j == 0: list_2.append(ch1[i * a + j]) if j != a - 1: if ch1[i * a + j] != ch1[i * a + 1 + j]: index_m = 1 for i in range(n): if ch1 != list_1[i]: index_m = 1 if "R" in list_2 and "G" in list_2 and "B" in list_2: b = 1 else: index_m = 1 if index_n == 0 or index_m == 0: print("YES") else: print("NO")
ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF BIN_OP VAR VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER IF STRING VAR STRING VAR STRING VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR VAR IF VAR BIN_OP VAR NUMBER IF VAR BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR NUMBER IF STRING VAR STRING VAR STRING VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
The flag of Berland is such rectangular field n Γ— m that satisfies following conditions: Flag consists of three colors which correspond to letters 'R', 'G' and 'B'. Flag consists of three equal in width and height stripes, parralel to each other and to sides of the flag. Each stripe has exactly one color. Each color should be used in exactly one stripe. You are given a field n Γ— m, consisting of characters 'R', 'G' and 'B'. Output "YES" (without quotes) if this field corresponds to correct flag of Berland. Otherwise, print "NO" (without quotes). -----Input----- The first line contains two integer numbers n and m (1 ≀ n, m ≀ 100) β€” the sizes of the field. Each of the following n lines consisting of m characters 'R', 'G' and 'B' β€” the description of the field. -----Output----- Print "YES" (without quotes) if the given field corresponds to correct flag of Berland . Otherwise, print "NO" (without quotes). -----Examples----- Input 6 5 RRRRR RRRRR BBBBB BBBBB GGGGG GGGGG Output YES Input 4 3 BRG BRG BRG BRG Output YES Input 6 7 RRRGGGG RRRGGGG RRRGGGG RRRBBBB RRRBBBB RRRBBBB Output NO Input 4 4 RRRR RRRR BBBB GGGG Output NO -----Note----- The field in the third example doesn't have three parralel stripes. Rows of the field in the fourth example are parralel to each other and to borders. But they have different heights β€” 2, 1 and 1.
n, m = map(int, input().split()) f = [(0) for _ in range(n)] for i in range(n): f[i] = input() hor = True if n % 3 != 0: hor = False else: c = "RGB" used = {"R": False, "G": False, "B": False} used[f[0][0]] = True cnt = 0 if [(f[0][0] * m) for i in range(n // 3)] == f[: n // 3]: cnt += 1 if not used[f[n // 3][0]]: used[f[n // 3][0]] = True if [(f[n // 3][0] * m) for i in range(n // 3)] == f[n // 3 : n // 3 * 2]: cnt += 1 if not used[f[n // 3 * 2][0]]: used[f[n // 3 * 2][0]] = True if [(f[n // 3 * 2][0] * m) for i in range(n // 3)] == f[n // 3 * 2 :]: cnt += 1 if cnt == 3: hor = True else: hor = False ver = True if m % 3 != 0: ver = False else: new_f = ["" for _ in range(m)] for i in range(m): for j in range(n): new_f[i] += f[j][i] c = "RGB" used = {"R": False, "G": False, "B": False} used[new_f[0][0]] = True cnt = 0 if [(new_f[0][0] * n) for i in range(m // 3)] == new_f[: m // 3]: cnt += 1 if not used[new_f[m // 3][0]]: used[new_f[m // 3][0]] = True if [(new_f[m // 3][0] * n) for i in range(m // 3)] == new_f[ m // 3 : m // 3 * 2 ]: cnt += 1 if not used[new_f[m // 3 * 2][0]]: used[new_f[m // 3 * 2][0]] = True if [(new_f[m // 3 * 2][0] * n) for i in range(m // 3)] == new_f[m // 3 * 2 :]: cnt += 1 if cnt == 3: ver = True else: ver = False if hor or ver: print("YES") else: print("NO")
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR STRING ASSIGN VAR DICT STRING STRING STRING NUMBER NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER NUMBER NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER VAR NUMBER IF VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER NUMBER IF BIN_OP VAR BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR STRING VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR STRING ASSIGN VAR DICT STRING STRING STRING NUMBER NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER NUMBER NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER VAR NUMBER IF VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER NUMBER IF BIN_OP VAR BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
The flag of Berland is such rectangular field n Γ— m that satisfies following conditions: Flag consists of three colors which correspond to letters 'R', 'G' and 'B'. Flag consists of three equal in width and height stripes, parralel to each other and to sides of the flag. Each stripe has exactly one color. Each color should be used in exactly one stripe. You are given a field n Γ— m, consisting of characters 'R', 'G' and 'B'. Output "YES" (without quotes) if this field corresponds to correct flag of Berland. Otherwise, print "NO" (without quotes). -----Input----- The first line contains two integer numbers n and m (1 ≀ n, m ≀ 100) β€” the sizes of the field. Each of the following n lines consisting of m characters 'R', 'G' and 'B' β€” the description of the field. -----Output----- Print "YES" (without quotes) if the given field corresponds to correct flag of Berland . Otherwise, print "NO" (without quotes). -----Examples----- Input 6 5 RRRRR RRRRR BBBBB BBBBB GGGGG GGGGG Output YES Input 4 3 BRG BRG BRG BRG Output YES Input 6 7 RRRGGGG RRRGGGG RRRGGGG RRRBBBB RRRBBBB RRRBBBB Output NO Input 4 4 RRRR RRRR BBBB GGGG Output NO -----Note----- The field in the third example doesn't have three parralel stripes. Rows of the field in the fourth example are parralel to each other and to borders. But they have different heights β€” 2, 1 and 1.
import itertools n, m = map(int, input().split()) flag = [] for _ in range(n): flag.append(input()) def check(flag): if len(flag) % 3 or len(set(itertools.chain(*flag))) != 3: return False width = len(flag) // 3 for i in range(3): line = set() for j in range(width): line.update(set(flag[i * width + j])) if len(line) != 1: return False return True print("YES" if check(flag) or check(list(zip(*flag))) else "NO")
IMPORT ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF IF BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER RETURN NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER RETURN NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR STRING STRING
The flag of Berland is such rectangular field n Γ— m that satisfies following conditions: Flag consists of three colors which correspond to letters 'R', 'G' and 'B'. Flag consists of three equal in width and height stripes, parralel to each other and to sides of the flag. Each stripe has exactly one color. Each color should be used in exactly one stripe. You are given a field n Γ— m, consisting of characters 'R', 'G' and 'B'. Output "YES" (without quotes) if this field corresponds to correct flag of Berland. Otherwise, print "NO" (without quotes). -----Input----- The first line contains two integer numbers n and m (1 ≀ n, m ≀ 100) β€” the sizes of the field. Each of the following n lines consisting of m characters 'R', 'G' and 'B' β€” the description of the field. -----Output----- Print "YES" (without quotes) if the given field corresponds to correct flag of Berland . Otherwise, print "NO" (without quotes). -----Examples----- Input 6 5 RRRRR RRRRR BBBBB BBBBB GGGGG GGGGG Output YES Input 4 3 BRG BRG BRG BRG Output YES Input 6 7 RRRGGGG RRRGGGG RRRGGGG RRRBBBB RRRBBBB RRRBBBB Output NO Input 4 4 RRRR RRRR BBBB GGGG Output NO -----Note----- The field in the third example doesn't have three parralel stripes. Rows of the field in the fourth example are parralel to each other and to borders. But they have different heights β€” 2, 1 and 1.
def rotate(matrix): global n, m new_matrix = [[(0) for i in range(n)] for j in range(m)] for i in range(n): for j in range(m): new_matrix[j][i] = matrix[i][j] return new_matrix def check(tab, n, m): colors = set() color = tab[0][0] colors.add(color) for i in range(n // 3): for j in range(m): if tab[i][j] != color: return False color = tab[n // 3][0] colors.add(color) for i in range(n // 3, n // 3 * 2): for j in range(m): if tab[i][j] != color: return False color = tab[n // 3 * 2][0] colors.add(color) for i in range(n // 3 * 2, n): for j in range(m): if tab[i][j] != color: return False if len(colors) == 3: return True return False n, m = map(int, input().split()) tab = [list(input()) for i in range(n)] tf = False if n % 3 else check(tab, n, m) tfr = False if m % 3 else check(rotate(tab), m, n) if tf or tfr: print("YES") else: print("NO")
FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR RETURN NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR RETURN NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR RETURN NUMBER IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER RETURN NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
The flag of Berland is such rectangular field n Γ— m that satisfies following conditions: Flag consists of three colors which correspond to letters 'R', 'G' and 'B'. Flag consists of three equal in width and height stripes, parralel to each other and to sides of the flag. Each stripe has exactly one color. Each color should be used in exactly one stripe. You are given a field n Γ— m, consisting of characters 'R', 'G' and 'B'. Output "YES" (without quotes) if this field corresponds to correct flag of Berland. Otherwise, print "NO" (without quotes). -----Input----- The first line contains two integer numbers n and m (1 ≀ n, m ≀ 100) β€” the sizes of the field. Each of the following n lines consisting of m characters 'R', 'G' and 'B' β€” the description of the field. -----Output----- Print "YES" (without quotes) if the given field corresponds to correct flag of Berland . Otherwise, print "NO" (without quotes). -----Examples----- Input 6 5 RRRRR RRRRR BBBBB BBBBB GGGGG GGGGG Output YES Input 4 3 BRG BRG BRG BRG Output YES Input 6 7 RRRGGGG RRRGGGG RRRGGGG RRRBBBB RRRBBBB RRRBBBB Output NO Input 4 4 RRRR RRRR BBBB GGGG Output NO -----Note----- The field in the third example doesn't have three parralel stripes. Rows of the field in the fourth example are parralel to each other and to borders. But they have different heights β€” 2, 1 and 1.
n, m = map(int, input().split(" ")) flag2 = 0 flag1 = 0 if n % 3 == 0: flag1 = 1 if m % 3 == 0: flag2 = 1 s = [] f = [""] * m for i in range(n): t = input() s.append(t) for j in range(m): f[j] += t[j] H = [0, 0, 0] p = [] for i in s: if i == "R" * m: H[0] += 1 p.append(0) if i == "B" * m: H[1] += 1 p.append(1) if i == "G" * m: H[2] += 1 p.append(2) cnt = 0 for i in range(1, len(p)): if p[i] != p[i - 1]: cnt += 1 if H[0] == n / 3 and H[1] == n / 3 and H[2] == n / 3 and flag1 and cnt == 2: print("YES") else: H = [0, 0, 0] p = [] for i in f: if i == "R" * n: H[0] += 1 p.append(0) if i == "B" * n: H[1] += 1 p.append(1) if i == "G" * n: H[2] += 1 p.append(2) cnt = 0 for i in range(1, len(p)): if p[i] != p[i - 1]: cnt += 1 if H[0] == m / 3 and H[1] == m / 3 and H[2] == m / 3 and flag2 and cnt == 2: print("YES") else: print("NO")
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR BIN_OP LIST STRING VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER ASSIGN VAR LIST FOR VAR VAR IF VAR BIN_OP STRING VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR BIN_OP STRING VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR BIN_OP STRING VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR LIST NUMBER NUMBER NUMBER ASSIGN VAR LIST FOR VAR VAR IF VAR BIN_OP STRING VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR BIN_OP STRING VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR BIN_OP STRING VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
The flag of Berland is such rectangular field n Γ— m that satisfies following conditions: Flag consists of three colors which correspond to letters 'R', 'G' and 'B'. Flag consists of three equal in width and height stripes, parralel to each other and to sides of the flag. Each stripe has exactly one color. Each color should be used in exactly one stripe. You are given a field n Γ— m, consisting of characters 'R', 'G' and 'B'. Output "YES" (without quotes) if this field corresponds to correct flag of Berland. Otherwise, print "NO" (without quotes). -----Input----- The first line contains two integer numbers n and m (1 ≀ n, m ≀ 100) β€” the sizes of the field. Each of the following n lines consisting of m characters 'R', 'G' and 'B' β€” the description of the field. -----Output----- Print "YES" (without quotes) if the given field corresponds to correct flag of Berland . Otherwise, print "NO" (without quotes). -----Examples----- Input 6 5 RRRRR RRRRR BBBBB BBBBB GGGGG GGGGG Output YES Input 4 3 BRG BRG BRG BRG Output YES Input 6 7 RRRGGGG RRRGGGG RRRGGGG RRRBBBB RRRBBBB RRRBBBB Output NO Input 4 4 RRRR RRRR BBBB GGGG Output NO -----Note----- The field in the third example doesn't have three parralel stripes. Rows of the field in the fourth example are parralel to each other and to borders. But they have different heights β€” 2, 1 and 1.
n, m = input().split() n = int(n) m = int(m) flag = [] tes = [] RGB = {"R": 0, "G": 0, "B": 0} for i in range(n): flag.append(["."] * m) tes.append(["."] * m) for i in range(n): sting = input() for j in range(m): flag[i][j] = sting[j] check = False if n % 3 != 0 and m % 3 != 0: print("NO") elif n % 3 == 0 and m % 3 != 0: l = int(n / 3) si1 = flag[0][0] RGB[si1] += 1 si2 = flag[l][0] RGB[si2] += 1 si3 = flag[l + l][0] RGB[si3] += 1 for i in range(0, l): for j in range(m): tes[i][j] = si1 for i in range(l, l + l): for j in range(m): tes[i][j] = si2 for i in range(l + l, n): for j in range(m): tes[i][j] = si3 if tes == flag and RGB["R"] == 1 and RGB["G"] == 1 and RGB["B"] == 1: print("YES") else: print("NO") elif n % 3 != 0 and m % 3 == 0: l = int(m / 3) si1 = flag[0][0] RGB[si1] += 1 si2 = flag[0][l] RGB[si2] += 1 si3 = flag[0][l + l] RGB[si3] += 1 for j in range(0, l): for i in range(n): tes[i][j] = si1 for j in range(l, l + l): for i in range(n): tes[i][j] = si2 for j in range(l + l, m): for i in range(n): tes[i][j] = si3 if tes == flag and RGB["R"] == 1 and RGB["G"] == 1 and RGB["B"] == 1: print("YES") else: print("NO") elif n % 3 == 0 and m % 3 == 0: q = 0 l = int(n / 3) si1 = flag[0][0] RGB[si1] += 1 si2 = flag[l][0] RGB[si2] += 1 si3 = flag[l + l][0] RGB[si3] += 1 for i in range(0, l): for j in range(m): tes[i][j] = si1 for i in range(l, l + l): for j in range(m): tes[i][j] = si2 for i in range(l + l, n): for j in range(m): tes[i][j] = si3 if tes == flag and RGB["R"] == 1 and RGB["G"] == 1 and RGB["B"] == 1: print("YES") q = 1 RGB["R"] = 0 RGB["G"] = 0 RGB["B"] = 0 if q == 0: l = int(m / 3) si1 = flag[0][0] RGB[si1] += 1 si2 = flag[0][l] RGB[si2] += 1 si3 = flag[0][l + l] RGB[si3] += 1 for j in range(0, l): for i in range(n): tes[i][j] = si1 for j in range(l, l + l): for i in range(n): tes[i][j] = si2 for j in range(l + l, m): for i in range(n): tes[i][j] = si3 if tes == flag and RGB["R"] == 1 and RGB["G"] == 1 and RGB["B"] == 1: print("YES") else: print("NO")
ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR DICT STRING STRING STRING NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP LIST STRING VAR EXPR FUNC_CALL VAR BIN_OP LIST STRING VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR IF VAR VAR VAR STRING NUMBER VAR STRING NUMBER VAR STRING NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER BIN_OP VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR IF VAR VAR VAR STRING NUMBER VAR STRING NUMBER VAR STRING NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR IF VAR VAR VAR STRING NUMBER VAR STRING NUMBER VAR STRING NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR STRING NUMBER ASSIGN VAR STRING NUMBER ASSIGN VAR STRING NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER BIN_OP VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR IF VAR VAR VAR STRING NUMBER VAR STRING NUMBER VAR STRING NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
The flag of Berland is such rectangular field n Γ— m that satisfies following conditions: Flag consists of three colors which correspond to letters 'R', 'G' and 'B'. Flag consists of three equal in width and height stripes, parralel to each other and to sides of the flag. Each stripe has exactly one color. Each color should be used in exactly one stripe. You are given a field n Γ— m, consisting of characters 'R', 'G' and 'B'. Output "YES" (without quotes) if this field corresponds to correct flag of Berland. Otherwise, print "NO" (without quotes). -----Input----- The first line contains two integer numbers n and m (1 ≀ n, m ≀ 100) β€” the sizes of the field. Each of the following n lines consisting of m characters 'R', 'G' and 'B' β€” the description of the field. -----Output----- Print "YES" (without quotes) if the given field corresponds to correct flag of Berland . Otherwise, print "NO" (without quotes). -----Examples----- Input 6 5 RRRRR RRRRR BBBBB BBBBB GGGGG GGGGG Output YES Input 4 3 BRG BRG BRG BRG Output YES Input 6 7 RRRGGGG RRRGGGG RRRGGGG RRRBBBB RRRBBBB RRRBBBB Output NO Input 4 4 RRRR RRRR BBBB GGGG Output NO -----Note----- The field in the third example doesn't have three parralel stripes. Rows of the field in the fourth example are parralel to each other and to borders. But they have different heights β€” 2, 1 and 1.
def check(n, m, fl, count): nonlocal flag, tr_flag if count == 3: return "NO" num = n // 3 is_ok = set() for k in range(0, n, num): new_check = set() for i in range(k, k + num): new_check = new_check | set(fl[i]) if len(new_check) != 1: flag, tr_flag = tr_flag, flag if m % 3 == 0: return check(m, n, flag, count + 1) else: return "NO" now = list(new_check)[0] if now in is_ok: flag, tr_flag = tr_flag, flag if m % 3 == 0: return check(m, n, flag, count + 1) else: return "NO" is_ok.add(now) return "YES" def main(): nonlocal n, m, flag, tr_flag if n % 3 != 0 and m % 3 != 0: return "NO" if n % 3 == 0: return check(n, m, flag, 0) else: return check(m, n, tr_flag, 0) n, m = map(int, input().split()) flag = [] for i in range(n): string = list(input()) flag.append(string) tr_flag = list(map(list, zip(*flag))) answer = main() print(answer)
FUNC_DEF IF VAR NUMBER RETURN STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER RETURN FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER RETURN STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER RETURN FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER RETURN STRING EXPR FUNC_CALL VAR VAR RETURN STRING FUNC_DEF IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER RETURN STRING IF BIN_OP VAR NUMBER NUMBER RETURN FUNC_CALL VAR VAR VAR VAR NUMBER RETURN FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR
The flag of Berland is such rectangular field n Γ— m that satisfies following conditions: Flag consists of three colors which correspond to letters 'R', 'G' and 'B'. Flag consists of three equal in width and height stripes, parralel to each other and to sides of the flag. Each stripe has exactly one color. Each color should be used in exactly one stripe. You are given a field n Γ— m, consisting of characters 'R', 'G' and 'B'. Output "YES" (without quotes) if this field corresponds to correct flag of Berland. Otherwise, print "NO" (without quotes). -----Input----- The first line contains two integer numbers n and m (1 ≀ n, m ≀ 100) β€” the sizes of the field. Each of the following n lines consisting of m characters 'R', 'G' and 'B' β€” the description of the field. -----Output----- Print "YES" (without quotes) if the given field corresponds to correct flag of Berland . Otherwise, print "NO" (without quotes). -----Examples----- Input 6 5 RRRRR RRRRR BBBBB BBBBB GGGGG GGGGG Output YES Input 4 3 BRG BRG BRG BRG Output YES Input 6 7 RRRGGGG RRRGGGG RRRGGGG RRRBBBB RRRBBBB RRRBBBB Output NO Input 4 4 RRRR RRRR BBBB GGGG Output NO -----Note----- The field in the third example doesn't have three parralel stripes. Rows of the field in the fourth example are parralel to each other and to borders. But they have different heights β€” 2, 1 and 1.
n, m = map(int, input().split()) def ma(): s = [] h = True cts = {"R": 0, "G": 0, "B": 0} for i in range(n): s.append(input().strip()) init = s[-1][0] for c in s[-1]: if c != init: h = False cts[c] += 1 ct = 0 if h: for i in range(m): for j in range(n): if s[j][i] != s[j][0]: return False for j in range(n): if s[j][0] != s[j - 1][0]: ct += 1 if ct != 3: return False else: for j in range(n): if s[j] != s[0]: return False for j in range(m): if s[0][j] != s[0][j - 1]: ct += 1 if ct != 3: return False if cts["R"] != cts["G"] or cts["G"] != cts["B"]: return False return True if ma(): print("YES") else: print("NO")
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR DICT STRING STRING STRING NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER IF VAR NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER IF VAR NUMBER RETURN NUMBER IF VAR STRING VAR STRING VAR STRING VAR STRING RETURN NUMBER RETURN NUMBER IF FUNC_CALL VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
The flag of Berland is such rectangular field n Γ— m that satisfies following conditions: Flag consists of three colors which correspond to letters 'R', 'G' and 'B'. Flag consists of three equal in width and height stripes, parralel to each other and to sides of the flag. Each stripe has exactly one color. Each color should be used in exactly one stripe. You are given a field n Γ— m, consisting of characters 'R', 'G' and 'B'. Output "YES" (without quotes) if this field corresponds to correct flag of Berland. Otherwise, print "NO" (without quotes). -----Input----- The first line contains two integer numbers n and m (1 ≀ n, m ≀ 100) β€” the sizes of the field. Each of the following n lines consisting of m characters 'R', 'G' and 'B' β€” the description of the field. -----Output----- Print "YES" (without quotes) if the given field corresponds to correct flag of Berland . Otherwise, print "NO" (without quotes). -----Examples----- Input 6 5 RRRRR RRRRR BBBBB BBBBB GGGGG GGGGG Output YES Input 4 3 BRG BRG BRG BRG Output YES Input 6 7 RRRGGGG RRRGGGG RRRGGGG RRRBBBB RRRBBBB RRRBBBB Output NO Input 4 4 RRRR RRRR BBBB GGGG Output NO -----Note----- The field in the third example doesn't have three parralel stripes. Rows of the field in the fourth example are parralel to each other and to borders. But they have different heights β€” 2, 1 and 1.
vv = input() n = int(vv[0 : vv.find(" ")]) m = int(vv[vv.find(" ") :]) x = "" for mm in range(n): x += input() col = 0 row = 0 res = True types = 0 if x[0] == x[n * m - m]: if m % 3 == 0: col = m // 3 row = n types = 1 else: res = False elif x[0] == x[m - 1]: if n % 3 == 0: col = m row = n // 3 types = 2 else: res = False else: res = False c1 = "" c2 = "" c3 = "" if res: if types == 1: for i in range(row): for j in range(col): c1 += x[j + m * i] for i in range(row): for j in range(col, col * 2): c2 += x[j + m * i] for i in range(row): for j in range(col * 2, col * 3): c3 += x[j + m * i] if types == 2: for i in range(m * n // 3): c1 += x[i] for i in range(m * n // 3, m * n // 3 * 2): c2 += x[i] for i in range(m * n // 3 * 2, m * n): c3 += x[i] if res: let1 = c1[0] for i in c1: if i != let1: res = False break if res: let2 = c2[0] if let1 == let2: res = False else: for i in c2: if i != let2: res = False break if res: let3 = c3[0] if let1 == let3 or let2 == let3: res = False else: for i in c3: if i != let3: res = False break if res: print("YES") else: print("NO")
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR STRING ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR BIN_OP BIN_OP VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR STRING IF VAR IF VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR VAR BIN_OP VAR BIN_OP VAR VAR IF VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER BIN_OP VAR VAR VAR VAR VAR IF VAR ASSIGN VAR VAR NUMBER FOR VAR VAR IF VAR VAR ASSIGN VAR NUMBER IF VAR ASSIGN VAR VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR ASSIGN VAR NUMBER IF VAR ASSIGN VAR VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING