message
stringlengths
2
28.7k
message_type
stringclasses
2 values
message_id
int64
0
1
conversation_id
int64
21
109k
cluster
float64
7
7
__index_level_0__
int64
42
217k
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Today we will be playing a red and white colouring game (no, this is not the Russian Civil War; these are just the colours of the Canadian flag). You are given an n × m grid of "R", "W", and "." characters. "R" is red, "W" is white and "." is blank. The neighbours of a cell are those that share an edge with it (those that only share a corner do not count). Your job is to colour the blank cells red or white so that every red cell only has white neighbours (and no red ones) and every white cell only has red neighbours (and no white ones). You are not allowed to recolour already coloured cells. Input The first line contains t (1 ≤ t ≤ 100), the number of test cases. In each test case, the first line will contain n (1 ≤ n ≤ 50) and m (1 ≤ m ≤ 50), the height and width of the grid respectively. The next n lines will contain the grid. Each character of the grid is either 'R', 'W', or '.'. Output For each test case, output "YES" if there is a valid grid or "NO" if there is not. If there is, output the grid on the next n lines. If there are multiple answers, print any. In the output, the "YES"s and "NO"s are case-insensitive, meaning that outputs such as "yEs" and "nO" are valid. However, the grid is case-sensitive. Example Input 3 4 6 .R.... ...... ...... .W.... 4 4 .R.W .... .... .... 5 1 R W R W R Output YES WRWRWR RWRWRW WRWRWR RWRWRW NO YES R W R W R Note The answer for the first example case is given in the example output, and it can be proven that no grid exists that satisfies the requirements of the second example case. In the third example all cells are initially coloured, and the colouring is valid. Submitted Solution: ``` #A. Colour the Flag test = int(input()) def doColor(a,i,j,n,m,v,c): v[i][j] = True ch = "W" if c == "R" else "R" if a[i][j] == ".": a[i][j] = ch elif a[i][j] != ch: return False if i-1>=0 and not v[i-1][j]: if not doColor(a,i-1,j,n,m,v,ch): return False if i+1<n and not v[i+1][j]: if not doColor(a,i+1,j,n,m,v,ch): return False if j-1 >=0 and not v[i][j-1]: if not doColor(a,i,j-1,n,m,v,ch): return False if j+1<m and not v[i][j+1]: if not doColor(a,i,j+1,n,m,v,ch): return False return True try: while test != 0: test = test - 1 n,m = [int(i) for i in input().split(" ")] a = [] v = [] for i in range(0,n): b = [i for i in input()] valid = [False]*len(b) a.append(b) v.append(valid) t = False gone = False for i in range(0,n): if gone: break for j in range(0,m): if a[i][j] != ".": ch = "W" if a[i][j] == "R" else "R" t = doColor(a,i,j,n,m,v,ch) gone = True break; if not gone: print("YES") c = "W" for i in range(0,n): c= "W" if c == "R" else "R" s = "" ch = c for j in range(0,m): s += ch ch = "W" if ch == "R" else "R" print(s) elif t: print("YES") for value in a: print("".join(value)) else: print("NO") except Exception as e: print(e) ```
instruction
0
83,654
7
167,308
No
output
1
83,654
7
167,309
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Today we will be playing a red and white colouring game (no, this is not the Russian Civil War; these are just the colours of the Canadian flag). You are given an n × m grid of "R", "W", and "." characters. "R" is red, "W" is white and "." is blank. The neighbours of a cell are those that share an edge with it (those that only share a corner do not count). Your job is to colour the blank cells red or white so that every red cell only has white neighbours (and no red ones) and every white cell only has red neighbours (and no white ones). You are not allowed to recolour already coloured cells. Input The first line contains t (1 ≤ t ≤ 100), the number of test cases. In each test case, the first line will contain n (1 ≤ n ≤ 50) and m (1 ≤ m ≤ 50), the height and width of the grid respectively. The next n lines will contain the grid. Each character of the grid is either 'R', 'W', or '.'. Output For each test case, output "YES" if there is a valid grid or "NO" if there is not. If there is, output the grid on the next n lines. If there are multiple answers, print any. In the output, the "YES"s and "NO"s are case-insensitive, meaning that outputs such as "yEs" and "nO" are valid. However, the grid is case-sensitive. Example Input 3 4 6 .R.... ...... ...... .W.... 4 4 .R.W .... .... .... 5 1 R W R W R Output YES WRWRWR RWRWRW WRWRWR RWRWRW NO YES R W R W R Note The answer for the first example case is given in the example output, and it can be proven that no grid exists that satisfies the requirements of the second example case. In the third example all cells are initially coloured, and the colouring is valid. Submitted Solution: ``` import sys,os,io import math from collections import defaultdict #input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline def rw(): sys.stdin = open('input1.txt', 'r') sys.stdout = open('output1.txt', 'w') #rw() t=int(input()) for a0 in range(t): l=[int(i) for i in input().split()] n=l[0] k=l[1] matrix=[] for i in range(n): s=input() matrix.append(list(s)) #print(matrix) flg=0 indx=-1 indy=-1 indxw=-1 indyw=-1 for i in range(n): for j in range(k): if(matrix[i][j]=='R'): indx=i indy=j break elif(matrix[i]=='W'): indxw=i indyw=i break #print(indx,indy) #print(indxw,indyw) if(indx!=-1): a=(indx+indy)%2 for i in range(n): for j in range(k): if(matrix[i][j]=='R'): if((i+j)%2!=a): flg=1 break elif(matrix[i][j]=='W'): if((i+j)%2==a): flg=1 break elif(indxw!=-1): a=(indxw+indyw)%2 for i in range(n): for j in range(k-1): if(matrix[i][j]=='R'): if((i+j)%2==a): flg=1 break elif(matrix[i][j]=='W'): if((i+j)%2!=a): flg=1 break if(flg==1): print("NO") else: print("YES") if(indx!=-1): res=[] for i in range(n): temp=[] for j in range(k): if((i+j)%2==a): temp.append("R") else: temp.append("W") res.append(temp) for i in res: print("".join(i)) elif(indxw!=-1): res=[] for i in range(n): temp=[] for j in range(k): if((i+j)%2==a): temp.append("W") else: temp.append("R") res.append(temp) for i in res: print("".join(i)) else: res=[] a=1 for i in range(n): temp=[] for j in range(k): if((i+j)%2==a): temp.append("W") else: temp.append("R") res.append(temp) for i in res: print("".join(i)) ```
instruction
0
83,655
7
167,310
No
output
1
83,655
7
167,311
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Today we will be playing a red and white colouring game (no, this is not the Russian Civil War; these are just the colours of the Canadian flag). You are given an n × m grid of "R", "W", and "." characters. "R" is red, "W" is white and "." is blank. The neighbours of a cell are those that share an edge with it (those that only share a corner do not count). Your job is to colour the blank cells red or white so that every red cell only has white neighbours (and no red ones) and every white cell only has red neighbours (and no white ones). You are not allowed to recolour already coloured cells. Input The first line contains t (1 ≤ t ≤ 100), the number of test cases. In each test case, the first line will contain n (1 ≤ n ≤ 50) and m (1 ≤ m ≤ 50), the height and width of the grid respectively. The next n lines will contain the grid. Each character of the grid is either 'R', 'W', or '.'. Output For each test case, output "YES" if there is a valid grid or "NO" if there is not. If there is, output the grid on the next n lines. If there are multiple answers, print any. In the output, the "YES"s and "NO"s are case-insensitive, meaning that outputs such as "yEs" and "nO" are valid. However, the grid is case-sensitive. Example Input 3 4 6 .R.... ...... ...... .W.... 4 4 .R.W .... .... .... 5 1 R W R W R Output YES WRWRWR RWRWRW WRWRWR RWRWRW NO YES R W R W R Note The answer for the first example case is given in the example output, and it can be proven that no grid exists that satisfies the requirements of the second example case. In the third example all cells are initially coloured, and the colouring is valid. Submitted Solution: ``` def fill_neighbors(i, j): dirs = [(0, 1), (1, 0), (0, -1), (-1, 0)] for dx, dy in dirs: nx, ny = i + dx, j + dy if 0 <= nx < n and 0 <= ny < m: if grid[i][j] == 'R' and grid[nx][ny] != 'R': grid[nx][ny] = 'W' elif grid[i][j] == 'W' and grid[nx][ny] != 'W': grid[nx][ny] = 'R' else: return 0 return 1 t = int(input()) for _ in range(t): n, m = map(int, input().split()) grid = [] for _ in range(n): row = input() grid.append(list(row)) ans = 'yes' for i in range(n): for j in range(m): if grid[i][j] != '.': res = fill_neighbors(i, j) if not res: ans = 'no' break if ans == 'no': break print(ans) if ans == 'yes': for row in grid: print(''.join(row)) ```
instruction
0
83,656
7
167,312
No
output
1
83,656
7
167,313
Provide tags and a correct Python 3 solution for this coding contest problem. Let's imagine that you're playing the following simple computer game. The screen displays n lined-up cubes. Each cube is painted one of m colors. You are allowed to delete not more than k cubes (that do not necessarily go one after another). After that, the remaining cubes join together (so that the gaps are closed) and the system counts the score. The number of points you score equals to the length of the maximum sequence of cubes of the same color that follow consecutively. Write a program that determines the maximum possible number of points you can score. Remember, you may delete no more than k any cubes. It is allowed not to delete cubes at all. Input The first line contains three integers n, m and k (1 ≤ n ≤ 2·105, 1 ≤ m ≤ 105, 0 ≤ k < n). The second line contains n integers from 1 to m — the numbers of cube colors. The numbers of colors are separated by single spaces. Output Print the maximum possible number of points you can score. Examples Input 10 3 2 1 2 1 1 3 2 1 1 2 2 Output 4 Input 10 2 2 1 2 1 2 1 1 2 1 1 2 Output 5 Input 3 1 2 1 1 1 Output 3 Note In the first sample you should delete the fifth and the sixth cubes. In the second sample you should delete the fourth and the seventh cubes. In the third sample you shouldn't delete any cubes.
instruction
0
83,662
7
167,324
Tags: binary search, dp, two pointers Correct Solution: ``` n, m, k =map(int,input().split()) a =list(map(int,input().split())) col = [[] for i in range(m + 1)] for i in range(n): col[a[i]] += [i] pref_c = [[0] * len(col[i]) for i in range(m + 1)] for i in range(1, m + 1): for j in range(1, len(col[i])): pref_c[i][j] = pref_c[i][j - 1] + col[i][j] - col[i][j - 1] - 1 ans = 1 for i in range(1, m + 1): r = 1 for j in range(len(col[i])): while(r < len(col[i]) and pref_c[i][r] - pref_c[i][j] <= k): r += 1 ans = max(ans, r - j) print(ans) ```
output
1
83,662
7
167,325
Provide tags and a correct Python 3 solution for this coding contest problem. Let's imagine that you're playing the following simple computer game. The screen displays n lined-up cubes. Each cube is painted one of m colors. You are allowed to delete not more than k cubes (that do not necessarily go one after another). After that, the remaining cubes join together (so that the gaps are closed) and the system counts the score. The number of points you score equals to the length of the maximum sequence of cubes of the same color that follow consecutively. Write a program that determines the maximum possible number of points you can score. Remember, you may delete no more than k any cubes. It is allowed not to delete cubes at all. Input The first line contains three integers n, m and k (1 ≤ n ≤ 2·105, 1 ≤ m ≤ 105, 0 ≤ k < n). The second line contains n integers from 1 to m — the numbers of cube colors. The numbers of colors are separated by single spaces. Output Print the maximum possible number of points you can score. Examples Input 10 3 2 1 2 1 1 3 2 1 1 2 2 Output 4 Input 10 2 2 1 2 1 2 1 1 2 1 1 2 Output 5 Input 3 1 2 1 1 1 Output 3 Note In the first sample you should delete the fifth and the sixth cubes. In the second sample you should delete the fourth and the seventh cubes. In the third sample you shouldn't delete any cubes.
instruction
0
83,663
7
167,326
Tags: binary search, dp, two pointers Correct Solution: ``` from sys import stdout from sys import stdin def get(): return stdin.readline().strip() def getf(): return [int(i) for i in get().split()] def put(a, end = "\n"): stdout.write(str(a) + end) def putf(a, sep = " ", end = "\n"): stdout.write(sep.join([str(i) for i in a]) + end) from collections import defaultdict as dd def bruh(): n, m, k = getf() a = getf() col = [[] for i in range(m + 1)] for i in range(n): col[a[i]] += [i] pref_c = [[0] * len(col[i]) for i in range(m + 1)] for i in range(1, m + 1): for j in range(1, len(col[i])): pref_c[i][j] = pref_c[i][j - 1] + col[i][j] - col[i][j - 1] - 1 ans = 1 for i in range(1, m + 1): r = 1 for j in range(len(col[i])): while(r < len(col[i]) and pref_c[i][r] - pref_c[i][j] <= k): r += 1 ans = max(ans, r - j) put(ans) bruh() ```
output
1
83,663
7
167,327
Provide tags and a correct Python 3 solution for this coding contest problem. Let's imagine that you're playing the following simple computer game. The screen displays n lined-up cubes. Each cube is painted one of m colors. You are allowed to delete not more than k cubes (that do not necessarily go one after another). After that, the remaining cubes join together (so that the gaps are closed) and the system counts the score. The number of points you score equals to the length of the maximum sequence of cubes of the same color that follow consecutively. Write a program that determines the maximum possible number of points you can score. Remember, you may delete no more than k any cubes. It is allowed not to delete cubes at all. Input The first line contains three integers n, m and k (1 ≤ n ≤ 2·105, 1 ≤ m ≤ 105, 0 ≤ k < n). The second line contains n integers from 1 to m — the numbers of cube colors. The numbers of colors are separated by single spaces. Output Print the maximum possible number of points you can score. Examples Input 10 3 2 1 2 1 1 3 2 1 1 2 2 Output 4 Input 10 2 2 1 2 1 2 1 1 2 1 1 2 Output 5 Input 3 1 2 1 1 1 Output 3 Note In the first sample you should delete the fifth and the sixth cubes. In the second sample you should delete the fourth and the seventh cubes. In the third sample you shouldn't delete any cubes.
instruction
0
83,664
7
167,328
Tags: binary search, dp, two pointers Correct Solution: ``` # ---------------------------iye ha aam zindegi--------------------------------------------- import math import heapq, bisect import sys from collections import deque, defaultdict from fractions import Fraction mod = 10 ** 9 + 7 mod1 = 998244353 # ------------------------------warmup---------------------------- import os import sys from io import BytesIO, IOBase BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") # -------------------game starts now----------------------------------------------------import math class TreeNode: def __init__(self, k, v): self.key = k self.value = v self.left = None self.right = None self.parent = None self.height = 1 self.num_left = 1 self.num_total = 1 class AvlTree: def __init__(self): self._tree = None def add(self, k, v): if not self._tree: self._tree = TreeNode(k, v) return node = self._add(k, v) if node: self._rebalance(node) def _add(self, k, v): node = self._tree while node: if k < node.key: if node.left: node = node.left else: node.left = TreeNode(k, v) node.left.parent = node return node.left elif node.key < k: if node.right: node = node.right else: node.right = TreeNode(k, v) node.right.parent = node return node.right else: node.value = v return @staticmethod def get_height(x): return x.height if x else 0 @staticmethod def get_num_total(x): return x.num_total if x else 0 def _rebalance(self, node): n = node while n: lh = self.get_height(n.left) rh = self.get_height(n.right) n.height = max(lh, rh) + 1 balance_factor = lh - rh n.num_total = 1 + self.get_num_total(n.left) + self.get_num_total(n.right) n.num_left = 1 + self.get_num_total(n.left) if balance_factor > 1: if self.get_height(n.left.left) < self.get_height(n.left.right): self._rotate_left(n.left) self._rotate_right(n) elif balance_factor < -1: if self.get_height(n.right.right) < self.get_height(n.right.left): self._rotate_right(n.right) self._rotate_left(n) else: n = n.parent def _remove_one(self, node): """ Side effect!!! Changes node. Node should have exactly one child """ replacement = node.left or node.right if node.parent: if AvlTree._is_left(node): node.parent.left = replacement else: node.parent.right = replacement replacement.parent = node.parent node.parent = None else: self._tree = replacement replacement.parent = None node.left = None node.right = None node.parent = None self._rebalance(replacement) def _remove_leaf(self, node): if node.parent: if AvlTree._is_left(node): node.parent.left = None else: node.parent.right = None self._rebalance(node.parent) else: self._tree = None node.parent = None node.left = None node.right = None def remove(self, k): node = self._get_node(k) if not node: return if AvlTree._is_leaf(node): self._remove_leaf(node) return if node.left and node.right: nxt = AvlTree._get_next(node) node.key = nxt.key node.value = nxt.value if self._is_leaf(nxt): self._remove_leaf(nxt) else: self._remove_one(nxt) self._rebalance(node) else: self._remove_one(node) def get(self, k): node = self._get_node(k) return node.value if node else -1 def _get_node(self, k): if not self._tree: return None node = self._tree while node: if k < node.key: node = node.left elif node.key < k: node = node.right else: return node return None def get_at(self, pos): x = pos + 1 node = self._tree while node: if x < node.num_left: node = node.left elif node.num_left < x: x -= node.num_left node = node.right else: return (node.key, node.value) raise IndexError("Out of ranges") @staticmethod def _is_left(node): return node.parent.left and node.parent.left == node @staticmethod def _is_leaf(node): return node.left is None and node.right is None def _rotate_right(self, node): if not node.parent: self._tree = node.left node.left.parent = None elif AvlTree._is_left(node): node.parent.left = node.left node.left.parent = node.parent else: node.parent.right = node.left node.left.parent = node.parent bk = node.left.right node.left.right = node node.parent = node.left node.left = bk if bk: bk.parent = node node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1 node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right) node.num_left = 1 + self.get_num_total(node.left) def _rotate_left(self, node): if not node.parent: self._tree = node.right node.right.parent = None elif AvlTree._is_left(node): node.parent.left = node.right node.right.parent = node.parent else: node.parent.right = node.right node.right.parent = node.parent bk = node.right.left node.right.left = node node.parent = node.right node.right = bk if bk: bk.parent = node node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1 node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right) node.num_left = 1 + self.get_num_total(node.left) @staticmethod def _get_next(node): if not node.right: return node.parent n = node.right while n.left: n = n.left return n avl=AvlTree() #-----------------------------------------------binary seacrh tree--------------------------------------- class SegmentTree1: def __init__(self, data, default='z', func=lambda a, b: min(a ,b)): """initialize the segment tree with data""" self._default = default self._func = func self._len = len(data) self._size = _size = 1 << (self._len - 1).bit_length() self.data = [default] * (2 * _size) self.data[_size:_size + self._len] = data for i in reversed(range(_size)): self.data[i] = func(self.data[i + i], self.data[i + i + 1]) def __delitem__(self, idx): self[idx] = self._default def __getitem__(self, idx): return self.data[idx + self._size] def __setitem__(self, idx, value): idx += self._size self.data[idx] = value idx >>= 1 while idx: self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1]) idx >>= 1 def __len__(self): return self._len def query(self, start, stop): if start == stop: return self.__getitem__(start) stop += 1 start += self._size stop += self._size res = self._default while start < stop: if start & 1: res = self._func(res, self.data[start]) start += 1 if stop & 1: stop -= 1 res = self._func(res, self.data[stop]) start >>= 1 stop >>= 1 return res def __repr__(self): return "SegmentTree({0})".format(self.data) # -------------------game starts now----------------------------------------------------import math class SegmentTree: def __init__(self, data, default=0, func=lambda a, b: a + b): """initialize the segment tree with data""" self._default = default self._func = func self._len = len(data) self._size = _size = 1 << (self._len - 1).bit_length() self.data = [default] * (2 * _size) self.data[_size:_size + self._len] = data for i in reversed(range(_size)): self.data[i] = func(self.data[i + i], self.data[i + i + 1]) def __delitem__(self, idx): self[idx] = self._default def __getitem__(self, idx): return self.data[idx + self._size] def __setitem__(self, idx, value): idx += self._size self.data[idx] = value idx >>= 1 while idx: self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1]) idx >>= 1 def __len__(self): return self._len def query(self, start, stop): if start == stop: return self.__getitem__(start) stop += 1 start += self._size stop += self._size res = self._default while start < stop: if start & 1: res = self._func(res, self.data[start]) start += 1 if stop & 1: stop -= 1 res = self._func(res, self.data[stop]) start >>= 1 stop >>= 1 return res def __repr__(self): return "SegmentTree({0})".format(self.data) # -------------------------------iye ha chutiya zindegi------------------------------------- class Factorial: def __init__(self, MOD): self.MOD = MOD self.factorials = [1, 1] self.invModulos = [0, 1] self.invFactorial_ = [1, 1] def calc(self, n): if n <= -1: print("Invalid argument to calculate n!") print("n must be non-negative value. But the argument was " + str(n)) exit() if n < len(self.factorials): return self.factorials[n] nextArr = [0] * (n + 1 - len(self.factorials)) initialI = len(self.factorials) prev = self.factorials[-1] m = self.MOD for i in range(initialI, n + 1): prev = nextArr[i - initialI] = prev * i % m self.factorials += nextArr return self.factorials[n] def inv(self, n): if n <= -1: print("Invalid argument to calculate n^(-1)") print("n must be non-negative value. But the argument was " + str(n)) exit() p = self.MOD pi = n % p if pi < len(self.invModulos): return self.invModulos[pi] nextArr = [0] * (n + 1 - len(self.invModulos)) initialI = len(self.invModulos) for i in range(initialI, min(p, n + 1)): next = -self.invModulos[p % i] * (p // i) % p self.invModulos.append(next) return self.invModulos[pi] def invFactorial(self, n): if n <= -1: print("Invalid argument to calculate (n^(-1))!") print("n must be non-negative value. But the argument was " + str(n)) exit() if n < len(self.invFactorial_): return self.invFactorial_[n] self.inv(n) # To make sure already calculated n^-1 nextArr = [0] * (n + 1 - len(self.invFactorial_)) initialI = len(self.invFactorial_) prev = self.invFactorial_[-1] p = self.MOD for i in range(initialI, n + 1): prev = nextArr[i - initialI] = (prev * self.invModulos[i % p]) % p self.invFactorial_ += nextArr return self.invFactorial_[n] class Combination: def __init__(self, MOD): self.MOD = MOD self.factorial = Factorial(MOD) def ncr(self, n, k): if k < 0 or n < k: return 0 k = min(k, n - k) f = self.factorial return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD # --------------------------------------iye ha combinations ka zindegi--------------------------------- def powm(a, n, m): if a == 1 or n == 0: return 1 if n % 2 == 0: s = powm(a, n // 2, m) return s * s % m else: return a * powm(a, n - 1, m) % m # --------------------------------------iye ha power ka zindegi--------------------------------- def sort_list(list1, list2): zipped_pairs = zip(list2, list1) z = [x for _, x in sorted(zipped_pairs)] return z # --------------------------------------------------product---------------------------------------- def product(l): por = 1 for i in range(len(l)): por *= l[i] return por # --------------------------------------------------binary---------------------------------------- def binarySearchCount(arr, n, key): left = 0 right = n - 1 count = 0 while (left <= right): mid = int((right + left)/ 2) # Check if middle element is # less than or equal to key if (arr[mid]<=key): count = mid+1 left = mid + 1 # If key is smaller, ignore right half else: right = mid - 1 return count # --------------------------------------------------binary---------------------------------------- def countdig(n): c = 0 while (n > 0): n //= 10 c += 1 return c def countGreater( arr,n, k): l = 0 r = n - 1 # Stores the index of the left most element # from the array which is greater than k leftGreater = n # Finds number of elements greater than k while (l <= r): m = int(l + (r - l) / 2) if (arr[m] >= k): leftGreater = m r = m - 1 # If mid element is less than # or equal to k update l else: l = m + 1 # Return the count of elements # greater than k return (n - leftGreater) # --------------------------------------------------binary------------------------------------ n,m,k=map(int,input().split()) l=list(map(int,input().split())) ans=1 ind=defaultdict(list) for i in range(n): ind[l[i]].append(i) #print(ind) cop=k for i in ind: if len(ind[i])==1: continue st=0 r=0 k=cop while(r<len(ind[i])-1): #print(k) if k>=0: ans=max(ans,r-st+1) r+=1 k -= ind[i][r] - ind[i][r - 1] - 1 else: st += 1 k += ind[i][st] - ind[i][st - 1]-1 #print(st,r,i,k) if k>=0: ans=max(ans,r-st+1) print(ans) ```
output
1
83,664
7
167,329
Provide tags and a correct Python 3 solution for this coding contest problem. Let's imagine that you're playing the following simple computer game. The screen displays n lined-up cubes. Each cube is painted one of m colors. You are allowed to delete not more than k cubes (that do not necessarily go one after another). After that, the remaining cubes join together (so that the gaps are closed) and the system counts the score. The number of points you score equals to the length of the maximum sequence of cubes of the same color that follow consecutively. Write a program that determines the maximum possible number of points you can score. Remember, you may delete no more than k any cubes. It is allowed not to delete cubes at all. Input The first line contains three integers n, m and k (1 ≤ n ≤ 2·105, 1 ≤ m ≤ 105, 0 ≤ k < n). The second line contains n integers from 1 to m — the numbers of cube colors. The numbers of colors are separated by single spaces. Output Print the maximum possible number of points you can score. Examples Input 10 3 2 1 2 1 1 3 2 1 1 2 2 Output 4 Input 10 2 2 1 2 1 2 1 1 2 1 1 2 Output 5 Input 3 1 2 1 1 1 Output 3 Note In the first sample you should delete the fifth and the sixth cubes. In the second sample you should delete the fourth and the seventh cubes. In the third sample you shouldn't delete any cubes.
instruction
0
83,665
7
167,330
Tags: binary search, dp, two pointers Correct Solution: ``` from sys import stdin, stdout n, q, k = map(int, stdin.readline().split()) colours = list(map(int, stdin.readline().split())) position = [[] for i in range(q + 1)] cnt = [[] for i in range(q + 1)] ans = 0 c, l, r = colours[0], 0, 0 for i in range(1, n): if colours[i] != c: position[c].append([l, r]) c = colours[i] l, r = i, i else: r += 1 position[c].append([l, r]) for i in range(1, q + 1): if position[i]: cnt[i].append((position[i][0][1] - position[i][0][0] + 1, 0)) for j in range(1, len(position[i])): cnt[i].append((cnt[i][j - 1][0] + position[i][j][1] - position[i][j][0] + 1, cnt[i][j - 1][1] + position[i][j][0] - position[i][j - 1][1] - 1)) cnt[i].append((0, 0)) l = 0 r = n + 1 while (r - l > 1): m = (r + l) // 2 label = 1 mx = 0 for i in range(1, q + 1): if not len(position[i]): continue for j in range(len(position[i])): lb, rb = j - 1, len(position[i]) while (rb - lb) > 1: mb = (rb + lb) // 2 if cnt[i][mb][1] - cnt[i][j][1] > k: rb = mb else: lb = mb mx = max(cnt[i][lb][0] - cnt[i][j - 1][0], mx) if mx < m: r = m else: l = m stdout.write(str(l)) ```
output
1
83,665
7
167,331
Provide tags and a correct Python 3 solution for this coding contest problem. Let's imagine that you're playing the following simple computer game. The screen displays n lined-up cubes. Each cube is painted one of m colors. You are allowed to delete not more than k cubes (that do not necessarily go one after another). After that, the remaining cubes join together (so that the gaps are closed) and the system counts the score. The number of points you score equals to the length of the maximum sequence of cubes of the same color that follow consecutively. Write a program that determines the maximum possible number of points you can score. Remember, you may delete no more than k any cubes. It is allowed not to delete cubes at all. Input The first line contains three integers n, m and k (1 ≤ n ≤ 2·105, 1 ≤ m ≤ 105, 0 ≤ k < n). The second line contains n integers from 1 to m — the numbers of cube colors. The numbers of colors are separated by single spaces. Output Print the maximum possible number of points you can score. Examples Input 10 3 2 1 2 1 1 3 2 1 1 2 2 Output 4 Input 10 2 2 1 2 1 2 1 1 2 1 1 2 Output 5 Input 3 1 2 1 1 1 Output 3 Note In the first sample you should delete the fifth and the sixth cubes. In the second sample you should delete the fourth and the seventh cubes. In the third sample you shouldn't delete any cubes.
instruction
0
83,666
7
167,332
Tags: binary search, dp, two pointers Correct Solution: ``` R = lambda: map(int, input().split()) n, m, k = R() arr = list(R()) arrs = [list() for i in range(m)] for i, x in enumerate(arr): arrs[x - 1].append(i) res = 1 for ar in arrs: l = -1 for r in range(len(ar)): while r - l + k < ar[r] - ar[l + 1] + 1: l += 1 res = max(res, r - l) print(res) ```
output
1
83,666
7
167,333
Provide tags and a correct Python 3 solution for this coding contest problem. Let's imagine that you're playing the following simple computer game. The screen displays n lined-up cubes. Each cube is painted one of m colors. You are allowed to delete not more than k cubes (that do not necessarily go one after another). After that, the remaining cubes join together (so that the gaps are closed) and the system counts the score. The number of points you score equals to the length of the maximum sequence of cubes of the same color that follow consecutively. Write a program that determines the maximum possible number of points you can score. Remember, you may delete no more than k any cubes. It is allowed not to delete cubes at all. Input The first line contains three integers n, m and k (1 ≤ n ≤ 2·105, 1 ≤ m ≤ 105, 0 ≤ k < n). The second line contains n integers from 1 to m — the numbers of cube colors. The numbers of colors are separated by single spaces. Output Print the maximum possible number of points you can score. Examples Input 10 3 2 1 2 1 1 3 2 1 1 2 2 Output 4 Input 10 2 2 1 2 1 2 1 1 2 1 1 2 Output 5 Input 3 1 2 1 1 1 Output 3 Note In the first sample you should delete the fifth and the sixth cubes. In the second sample you should delete the fourth and the seventh cubes. In the third sample you shouldn't delete any cubes.
instruction
0
83,667
7
167,334
Tags: binary search, dp, two pointers Correct Solution: ``` n,m,k = map(int,input().split()) a = list(map(int,input().split())) from collections import defaultdict mp = defaultdict(list) for i in range(n): mp[a[i]].append(i) res = 0 for i in range(n): val = a[i] st = 0 tmp = 1 ll =0 rr = len(mp[val])-1 while rr-ll>=0: m = rr+ll>>1 if mp[val][m]<=i: ll = m+1 st = m else: rr = m-1 l = 0 r = len(mp[val])-st while r-l>=0: mid = r+l>>1 rang = min(st+mid,len(mp[val])) cnt = rang-st+1 diff = mp[val][rang-1]-mp[val][st]+1 if diff-cnt<k: l = mid+1 tmp = mid else: r = mid-1 res = max(res,tmp) print(res) ```
output
1
83,667
7
167,335
Provide tags and a correct Python 3 solution for this coding contest problem. Let's imagine that you're playing the following simple computer game. The screen displays n lined-up cubes. Each cube is painted one of m colors. You are allowed to delete not more than k cubes (that do not necessarily go one after another). After that, the remaining cubes join together (so that the gaps are closed) and the system counts the score. The number of points you score equals to the length of the maximum sequence of cubes of the same color that follow consecutively. Write a program that determines the maximum possible number of points you can score. Remember, you may delete no more than k any cubes. It is allowed not to delete cubes at all. Input The first line contains three integers n, m and k (1 ≤ n ≤ 2·105, 1 ≤ m ≤ 105, 0 ≤ k < n). The second line contains n integers from 1 to m — the numbers of cube colors. The numbers of colors are separated by single spaces. Output Print the maximum possible number of points you can score. Examples Input 10 3 2 1 2 1 1 3 2 1 1 2 2 Output 4 Input 10 2 2 1 2 1 2 1 1 2 1 1 2 Output 5 Input 3 1 2 1 1 1 Output 3 Note In the first sample you should delete the fifth and the sixth cubes. In the second sample you should delete the fourth and the seventh cubes. In the third sample you shouldn't delete any cubes.
instruction
0
83,668
7
167,336
Tags: binary search, dp, two pointers Correct Solution: ``` n,m,k = map(int,input().split()) a = list(map(int,input().split())) from collections import defaultdict mp = defaultdict(list) for i in range(n): mp[a[i]].append(i) res = 0 for i in range(n): val = a[i] st = 0 l =0 r = len(mp[val])-1 while r-l>=0: m = r+l>>1 if mp[val][m]<=i: l = m+1 st = m else: r = m-1 tmp = 1 l = 0 r = len(mp[val])-st while r-l>=0: mid = r+l>>1 end = min(st+mid,len(mp[val])) cnt = end-st total = mp[val][end-1]-mp[val][st] if total-cnt<k: l = mid+1 tmp = mid else: r = mid-1 res = max(res,tmp) print(res) ```
output
1
83,668
7
167,337
Provide tags and a correct Python 3 solution for this coding contest problem. You are given n switches and m lamps. The i-th switch turns on some subset of the lamps. This information is given as the matrix a consisting of n rows and m columns where ai, j = 1 if the i-th switch turns on the j-th lamp and ai, j = 0 if the i-th switch is not connected to the j-th lamp. Initially all m lamps are turned off. Switches change state only from "off" to "on". It means that if you press two or more switches connected to the same lamp then the lamp will be turned on after any of this switches is pressed and will remain its state even if any switch connected to this lamp is pressed afterwards. It is guaranteed that if you push all n switches then all m lamps will be turned on. Your think that you have too many switches and you would like to ignore one of them. Your task is to say if there exists such a switch that if you will ignore (not use) it but press all the other n - 1 switches then all the m lamps will be turned on. Input The first line of the input contains two integers n and m (1 ≤ n, m ≤ 2000) — the number of the switches and the number of the lamps. The following n lines contain m characters each. The character ai, j is equal to '1' if the i-th switch turns on the j-th lamp and '0' otherwise. It is guaranteed that if you press all n switches all m lamps will be turned on. Output Print "YES" if there is a switch that if you will ignore it and press all the other n - 1 switches then all m lamps will be turned on. Print "NO" if there is no such switch. Examples Input 4 5 10101 01000 00111 10000 Output YES Input 4 5 10100 01000 00110 00101 Output NO
instruction
0
83,932
7
167,864
Tags: implementation Correct Solution: ``` while True: try: def solution(n, m): cnt =[0]*(m) lights = [] for i in range(n): a = input() for j in range(m): if a[j] == '1': cnt[j] += 1 lights.append(a) has="NO" for i in range(n): has = "NO" cunt = 0 for j in range(m): if lights[i][j] == '1' and cnt[j] >1: has= "YES" cunt += 1 elif lights[i][j]=='1': has = "NO" cunt += 1 break if (has == "YES" ) or cunt ==0: print("YES") return print(has) def read(): n, m = map(int,input().split()) solution(n, m) if __name__ == "__main__": read() except EOFError: break ```
output
1
83,932
7
167,865
Provide tags and a correct Python 3 solution for this coding contest problem. You are given n switches and m lamps. The i-th switch turns on some subset of the lamps. This information is given as the matrix a consisting of n rows and m columns where ai, j = 1 if the i-th switch turns on the j-th lamp and ai, j = 0 if the i-th switch is not connected to the j-th lamp. Initially all m lamps are turned off. Switches change state only from "off" to "on". It means that if you press two or more switches connected to the same lamp then the lamp will be turned on after any of this switches is pressed and will remain its state even if any switch connected to this lamp is pressed afterwards. It is guaranteed that if you push all n switches then all m lamps will be turned on. Your think that you have too many switches and you would like to ignore one of them. Your task is to say if there exists such a switch that if you will ignore (not use) it but press all the other n - 1 switches then all the m lamps will be turned on. Input The first line of the input contains two integers n and m (1 ≤ n, m ≤ 2000) — the number of the switches and the number of the lamps. The following n lines contain m characters each. The character ai, j is equal to '1' if the i-th switch turns on the j-th lamp and '0' otherwise. It is guaranteed that if you press all n switches all m lamps will be turned on. Output Print "YES" if there is a switch that if you will ignore it and press all the other n - 1 switches then all m lamps will be turned on. Print "NO" if there is no such switch. Examples Input 4 5 10101 01000 00111 10000 Output YES Input 4 5 10100 01000 00110 00101 Output NO
instruction
0
83,933
7
167,866
Tags: implementation Correct Solution: ``` n,m=map(int,input().split()) a=[] b=[0]*m for i in range(n): s=input() for j in range(m): if s[j]=='1': b[j]+=1 a.append(s) ans="NO" for i in range(n): s=a[i] flag=True for j in range(m): if s[j]=='1': if b[j]<=1: flag=False break if flag==True: ans="YES" break print(ans) ```
output
1
83,933
7
167,867
Provide tags and a correct Python 3 solution for this coding contest problem. You are given n switches and m lamps. The i-th switch turns on some subset of the lamps. This information is given as the matrix a consisting of n rows and m columns where ai, j = 1 if the i-th switch turns on the j-th lamp and ai, j = 0 if the i-th switch is not connected to the j-th lamp. Initially all m lamps are turned off. Switches change state only from "off" to "on". It means that if you press two or more switches connected to the same lamp then the lamp will be turned on after any of this switches is pressed and will remain its state even if any switch connected to this lamp is pressed afterwards. It is guaranteed that if you push all n switches then all m lamps will be turned on. Your think that you have too many switches and you would like to ignore one of them. Your task is to say if there exists such a switch that if you will ignore (not use) it but press all the other n - 1 switches then all the m lamps will be turned on. Input The first line of the input contains two integers n and m (1 ≤ n, m ≤ 2000) — the number of the switches and the number of the lamps. The following n lines contain m characters each. The character ai, j is equal to '1' if the i-th switch turns on the j-th lamp and '0' otherwise. It is guaranteed that if you press all n switches all m lamps will be turned on. Output Print "YES" if there is a switch that if you will ignore it and press all the other n - 1 switches then all m lamps will be turned on. Print "NO" if there is no such switch. Examples Input 4 5 10101 01000 00111 10000 Output YES Input 4 5 10100 01000 00110 00101 Output NO
instruction
0
83,934
7
167,868
Tags: implementation Correct Solution: ``` n,m=map(int,input().split()) a=[int(input(),2)for _ in range(n)] s=t=0 for x in a: t|=s&x;s|=x print(('YES','NO')[all(x&s&~t for x in a)]) ```
output
1
83,934
7
167,869
Provide tags and a correct Python 3 solution for this coding contest problem. You are given n switches and m lamps. The i-th switch turns on some subset of the lamps. This information is given as the matrix a consisting of n rows and m columns where ai, j = 1 if the i-th switch turns on the j-th lamp and ai, j = 0 if the i-th switch is not connected to the j-th lamp. Initially all m lamps are turned off. Switches change state only from "off" to "on". It means that if you press two or more switches connected to the same lamp then the lamp will be turned on after any of this switches is pressed and will remain its state even if any switch connected to this lamp is pressed afterwards. It is guaranteed that if you push all n switches then all m lamps will be turned on. Your think that you have too many switches and you would like to ignore one of them. Your task is to say if there exists such a switch that if you will ignore (not use) it but press all the other n - 1 switches then all the m lamps will be turned on. Input The first line of the input contains two integers n and m (1 ≤ n, m ≤ 2000) — the number of the switches and the number of the lamps. The following n lines contain m characters each. The character ai, j is equal to '1' if the i-th switch turns on the j-th lamp and '0' otherwise. It is guaranteed that if you press all n switches all m lamps will be turned on. Output Print "YES" if there is a switch that if you will ignore it and press all the other n - 1 switches then all m lamps will be turned on. Print "NO" if there is no such switch. Examples Input 4 5 10101 01000 00111 10000 Output YES Input 4 5 10100 01000 00110 00101 Output NO
instruction
0
83,935
7
167,870
Tags: implementation Correct Solution: ``` n,m=map(int,input().split()) l=[int(input(),2) for i in range(n)] c=int('1'*m,2) b=True for i in range(len(l)): s=0 for j in range(len(l)): if i!=j: s=s|l[j] if s==c: b=False print('YES') break if b: print('NO') ```
output
1
83,935
7
167,871
Provide tags and a correct Python 3 solution for this coding contest problem. You are given n switches and m lamps. The i-th switch turns on some subset of the lamps. This information is given as the matrix a consisting of n rows and m columns where ai, j = 1 if the i-th switch turns on the j-th lamp and ai, j = 0 if the i-th switch is not connected to the j-th lamp. Initially all m lamps are turned off. Switches change state only from "off" to "on". It means that if you press two or more switches connected to the same lamp then the lamp will be turned on after any of this switches is pressed and will remain its state even if any switch connected to this lamp is pressed afterwards. It is guaranteed that if you push all n switches then all m lamps will be turned on. Your think that you have too many switches and you would like to ignore one of them. Your task is to say if there exists such a switch that if you will ignore (not use) it but press all the other n - 1 switches then all the m lamps will be turned on. Input The first line of the input contains two integers n and m (1 ≤ n, m ≤ 2000) — the number of the switches and the number of the lamps. The following n lines contain m characters each. The character ai, j is equal to '1' if the i-th switch turns on the j-th lamp and '0' otherwise. It is guaranteed that if you press all n switches all m lamps will be turned on. Output Print "YES" if there is a switch that if you will ignore it and press all the other n - 1 switches then all m lamps will be turned on. Print "NO" if there is no such switch. Examples Input 4 5 10101 01000 00111 10000 Output YES Input 4 5 10100 01000 00110 00101 Output NO
instruction
0
83,936
7
167,872
Tags: implementation Correct Solution: ``` n,m=map(int,input().split()) ar=[] for i in range(n): ar.append(list(map(int,list(input())))) br=[0]*m for i in range(n): for j in range(m): br[j]+=ar[i][j] flag=False for i in range(n): f1=True for j in range(m): if(ar[i][j]==1 and br[j]==1): f1=False break if(f1): flag=True break if(flag): print("YES") else: print("NO") ```
output
1
83,936
7
167,873
Provide tags and a correct Python 3 solution for this coding contest problem. You are given n switches and m lamps. The i-th switch turns on some subset of the lamps. This information is given as the matrix a consisting of n rows and m columns where ai, j = 1 if the i-th switch turns on the j-th lamp and ai, j = 0 if the i-th switch is not connected to the j-th lamp. Initially all m lamps are turned off. Switches change state only from "off" to "on". It means that if you press two or more switches connected to the same lamp then the lamp will be turned on after any of this switches is pressed and will remain its state even if any switch connected to this lamp is pressed afterwards. It is guaranteed that if you push all n switches then all m lamps will be turned on. Your think that you have too many switches and you would like to ignore one of them. Your task is to say if there exists such a switch that if you will ignore (not use) it but press all the other n - 1 switches then all the m lamps will be turned on. Input The first line of the input contains two integers n and m (1 ≤ n, m ≤ 2000) — the number of the switches and the number of the lamps. The following n lines contain m characters each. The character ai, j is equal to '1' if the i-th switch turns on the j-th lamp and '0' otherwise. It is guaranteed that if you press all n switches all m lamps will be turned on. Output Print "YES" if there is a switch that if you will ignore it and press all the other n - 1 switches then all m lamps will be turned on. Print "NO" if there is no such switch. Examples Input 4 5 10101 01000 00111 10000 Output YES Input 4 5 10100 01000 00110 00101 Output NO
instruction
0
83,937
7
167,874
Tags: implementation Correct Solution: ``` s, l= list(map(int,input().split())) sig = [] utp = [] if s == 0 or l ==0: print('NO') quit() for i in range(s): sig.append(list(map(int,input()))) for i in range(0,l): out = 0 for x in range(0,s): out+=sig[x][i] utp.append(out) sig = sorted(sig,key = sum) for i in range(0,s): res1=0 for x in range(0,l): if utp[x]-sig[i][x] <=0: break else: res1+=1 if res1 == l: print('YES') quit() print('NO') ```
output
1
83,937
7
167,875
Provide tags and a correct Python 3 solution for this coding contest problem. You are given n switches and m lamps. The i-th switch turns on some subset of the lamps. This information is given as the matrix a consisting of n rows and m columns where ai, j = 1 if the i-th switch turns on the j-th lamp and ai, j = 0 if the i-th switch is not connected to the j-th lamp. Initially all m lamps are turned off. Switches change state only from "off" to "on". It means that if you press two or more switches connected to the same lamp then the lamp will be turned on after any of this switches is pressed and will remain its state even if any switch connected to this lamp is pressed afterwards. It is guaranteed that if you push all n switches then all m lamps will be turned on. Your think that you have too many switches and you would like to ignore one of them. Your task is to say if there exists such a switch that if you will ignore (not use) it but press all the other n - 1 switches then all the m lamps will be turned on. Input The first line of the input contains two integers n and m (1 ≤ n, m ≤ 2000) — the number of the switches and the number of the lamps. The following n lines contain m characters each. The character ai, j is equal to '1' if the i-th switch turns on the j-th lamp and '0' otherwise. It is guaranteed that if you press all n switches all m lamps will be turned on. Output Print "YES" if there is a switch that if you will ignore it and press all the other n - 1 switches then all m lamps will be turned on. Print "NO" if there is no such switch. Examples Input 4 5 10101 01000 00111 10000 Output YES Input 4 5 10100 01000 00110 00101 Output NO
instruction
0
83,938
7
167,876
Tags: implementation Correct Solution: ``` n, m = [int(i) for i in input().split()] lst = [input() for i in range(n)] count = [0 for _ in range(m)] for i in range(n): for j in range(m): if lst[i][j] == '1': count[j] += 1 flag = True for i in range(n): flag = True for j in range(m): if lst[i][j] == '1' and count[j] == 1: flag = False if flag: print('YES') exit() print('NO') ```
output
1
83,938
7
167,877
Provide tags and a correct Python 3 solution for this coding contest problem. You are given n switches and m lamps. The i-th switch turns on some subset of the lamps. This information is given as the matrix a consisting of n rows and m columns where ai, j = 1 if the i-th switch turns on the j-th lamp and ai, j = 0 if the i-th switch is not connected to the j-th lamp. Initially all m lamps are turned off. Switches change state only from "off" to "on". It means that if you press two or more switches connected to the same lamp then the lamp will be turned on after any of this switches is pressed and will remain its state even if any switch connected to this lamp is pressed afterwards. It is guaranteed that if you push all n switches then all m lamps will be turned on. Your think that you have too many switches and you would like to ignore one of them. Your task is to say if there exists such a switch that if you will ignore (not use) it but press all the other n - 1 switches then all the m lamps will be turned on. Input The first line of the input contains two integers n and m (1 ≤ n, m ≤ 2000) — the number of the switches and the number of the lamps. The following n lines contain m characters each. The character ai, j is equal to '1' if the i-th switch turns on the j-th lamp and '0' otherwise. It is guaranteed that if you press all n switches all m lamps will be turned on. Output Print "YES" if there is a switch that if you will ignore it and press all the other n - 1 switches then all m lamps will be turned on. Print "NO" if there is no such switch. Examples Input 4 5 10101 01000 00111 10000 Output YES Input 4 5 10100 01000 00110 00101 Output NO
instruction
0
83,939
7
167,878
Tags: implementation Correct Solution: ``` n,m=map(int,input().split()) l=[] cnt=[0 for i in range(m)] for i in range(n): s=input() l.append(s) for j in range(m): if s[j]=='1': cnt[j]+=1 c=0 for i in l: ok=True for j in range(m): if i[j]=='1' and cnt[j]==1: ok=False break if ok: print("YES") c=1 break if not c: print("NO") ```
output
1
83,939
7
167,879
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given n switches and m lamps. The i-th switch turns on some subset of the lamps. This information is given as the matrix a consisting of n rows and m columns where ai, j = 1 if the i-th switch turns on the j-th lamp and ai, j = 0 if the i-th switch is not connected to the j-th lamp. Initially all m lamps are turned off. Switches change state only from "off" to "on". It means that if you press two or more switches connected to the same lamp then the lamp will be turned on after any of this switches is pressed and will remain its state even if any switch connected to this lamp is pressed afterwards. It is guaranteed that if you push all n switches then all m lamps will be turned on. Your think that you have too many switches and you would like to ignore one of them. Your task is to say if there exists such a switch that if you will ignore (not use) it but press all the other n - 1 switches then all the m lamps will be turned on. Input The first line of the input contains two integers n and m (1 ≤ n, m ≤ 2000) — the number of the switches and the number of the lamps. The following n lines contain m characters each. The character ai, j is equal to '1' if the i-th switch turns on the j-th lamp and '0' otherwise. It is guaranteed that if you press all n switches all m lamps will be turned on. Output Print "YES" if there is a switch that if you will ignore it and press all the other n - 1 switches then all m lamps will be turned on. Print "NO" if there is no such switch. Examples Input 4 5 10101 01000 00111 10000 Output YES Input 4 5 10100 01000 00110 00101 Output NO Submitted Solution: ``` x, y = map(int, input().split()) arr = [] for i in range(x): arr.append(list(map(int, input()))) sum = [] for i in range(len(arr[0])): sum.append(0) for j in range(len(arr)): sum[i] += arr[j][i] answer = "NO" for i in range(len(arr)): ignorable = True for j in range(len(arr[i])): if (sum[j] - arr[i][j]) == 0: ignorable = False break if ignorable == True: answer = "YES" break print(answer) ```
instruction
0
83,940
7
167,880
Yes
output
1
83,940
7
167,881
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given n switches and m lamps. The i-th switch turns on some subset of the lamps. This information is given as the matrix a consisting of n rows and m columns where ai, j = 1 if the i-th switch turns on the j-th lamp and ai, j = 0 if the i-th switch is not connected to the j-th lamp. Initially all m lamps are turned off. Switches change state only from "off" to "on". It means that if you press two or more switches connected to the same lamp then the lamp will be turned on after any of this switches is pressed and will remain its state even if any switch connected to this lamp is pressed afterwards. It is guaranteed that if you push all n switches then all m lamps will be turned on. Your think that you have too many switches and you would like to ignore one of them. Your task is to say if there exists such a switch that if you will ignore (not use) it but press all the other n - 1 switches then all the m lamps will be turned on. Input The first line of the input contains two integers n and m (1 ≤ n, m ≤ 2000) — the number of the switches and the number of the lamps. The following n lines contain m characters each. The character ai, j is equal to '1' if the i-th switch turns on the j-th lamp and '0' otherwise. It is guaranteed that if you press all n switches all m lamps will be turned on. Output Print "YES" if there is a switch that if you will ignore it and press all the other n - 1 switches then all m lamps will be turned on. Print "NO" if there is no such switch. Examples Input 4 5 10101 01000 00111 10000 Output YES Input 4 5 10100 01000 00110 00101 Output NO Submitted Solution: ``` n, m = map(int, input().split()) matrix = [list(map(int, list(input()))) for _ in range(n)] matrix.append([0] * m) pos = set(range(n)) for i in range(m): cnt = 0 ind = 0 for j in range(n): if matrix[j][i]: cnt += 1 ind = j if cnt == 1: pos.discard(ind) if len(pos): print('YES') else: print('NO') ```
instruction
0
83,941
7
167,882
Yes
output
1
83,941
7
167,883
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given n switches and m lamps. The i-th switch turns on some subset of the lamps. This information is given as the matrix a consisting of n rows and m columns where ai, j = 1 if the i-th switch turns on the j-th lamp and ai, j = 0 if the i-th switch is not connected to the j-th lamp. Initially all m lamps are turned off. Switches change state only from "off" to "on". It means that if you press two or more switches connected to the same lamp then the lamp will be turned on after any of this switches is pressed and will remain its state even if any switch connected to this lamp is pressed afterwards. It is guaranteed that if you push all n switches then all m lamps will be turned on. Your think that you have too many switches and you would like to ignore one of them. Your task is to say if there exists such a switch that if you will ignore (not use) it but press all the other n - 1 switches then all the m lamps will be turned on. Input The first line of the input contains two integers n and m (1 ≤ n, m ≤ 2000) — the number of the switches and the number of the lamps. The following n lines contain m characters each. The character ai, j is equal to '1' if the i-th switch turns on the j-th lamp and '0' otherwise. It is guaranteed that if you press all n switches all m lamps will be turned on. Output Print "YES" if there is a switch that if you will ignore it and press all the other n - 1 switches then all m lamps will be turned on. Print "NO" if there is no such switch. Examples Input 4 5 10101 01000 00111 10000 Output YES Input 4 5 10100 01000 00110 00101 Output NO Submitted Solution: ``` #!/usr/bin/env python3 from sys import stdin, stdout def rint(): return map(int, stdin.readline().split()) def line(): return stdin.readline() n, m = rint() a = [] for i in range(n): a.append(line()) cnt = [0 for i in range(m)] for i in range(n): for j in range(m): if a[i][j] == '1': cnt[j] += 1 flag = 1 for i in range(n): flag = 1 for j in range(m): if a[i][j] == '1' and cnt[j] <= 1: flag = 0 break if flag: print("YES") exit() print("NO") ```
instruction
0
83,942
7
167,884
Yes
output
1
83,942
7
167,885
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given n switches and m lamps. The i-th switch turns on some subset of the lamps. This information is given as the matrix a consisting of n rows and m columns where ai, j = 1 if the i-th switch turns on the j-th lamp and ai, j = 0 if the i-th switch is not connected to the j-th lamp. Initially all m lamps are turned off. Switches change state only from "off" to "on". It means that if you press two or more switches connected to the same lamp then the lamp will be turned on after any of this switches is pressed and will remain its state even if any switch connected to this lamp is pressed afterwards. It is guaranteed that if you push all n switches then all m lamps will be turned on. Your think that you have too many switches and you would like to ignore one of them. Your task is to say if there exists such a switch that if you will ignore (not use) it but press all the other n - 1 switches then all the m lamps will be turned on. Input The first line of the input contains two integers n and m (1 ≤ n, m ≤ 2000) — the number of the switches and the number of the lamps. The following n lines contain m characters each. The character ai, j is equal to '1' if the i-th switch turns on the j-th lamp and '0' otherwise. It is guaranteed that if you press all n switches all m lamps will be turned on. Output Print "YES" if there is a switch that if you will ignore it and press all the other n - 1 switches then all m lamps will be turned on. Print "NO" if there is no such switch. Examples Input 4 5 10101 01000 00111 10000 Output YES Input 4 5 10100 01000 00110 00101 Output NO Submitted Solution: ``` n, m = map(int, input().split()) a = [list(map(int, input())) for _ in range(n)] s = [sum(z) for z in zip(*a)] #print(s) for r in a: #print(r) #print(*map(lambda x, y: x and y < 2, r, s)) if not any(map(lambda x, y: x and y < 2, r, s)): print("YES") break else: print("NO") ```
instruction
0
83,943
7
167,886
Yes
output
1
83,943
7
167,887
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given n switches and m lamps. The i-th switch turns on some subset of the lamps. This information is given as the matrix a consisting of n rows and m columns where ai, j = 1 if the i-th switch turns on the j-th lamp and ai, j = 0 if the i-th switch is not connected to the j-th lamp. Initially all m lamps are turned off. Switches change state only from "off" to "on". It means that if you press two or more switches connected to the same lamp then the lamp will be turned on after any of this switches is pressed and will remain its state even if any switch connected to this lamp is pressed afterwards. It is guaranteed that if you push all n switches then all m lamps will be turned on. Your think that you have too many switches and you would like to ignore one of them. Your task is to say if there exists such a switch that if you will ignore (not use) it but press all the other n - 1 switches then all the m lamps will be turned on. Input The first line of the input contains two integers n and m (1 ≤ n, m ≤ 2000) — the number of the switches and the number of the lamps. The following n lines contain m characters each. The character ai, j is equal to '1' if the i-th switch turns on the j-th lamp and '0' otherwise. It is guaranteed that if you press all n switches all m lamps will be turned on. Output Print "YES" if there is a switch that if you will ignore it and press all the other n - 1 switches then all m lamps will be turned on. Print "NO" if there is no such switch. Examples Input 4 5 10101 01000 00111 10000 Output YES Input 4 5 10100 01000 00110 00101 Output NO Submitted Solution: ``` import random n, b = [int(i) for i in input().strip().split()] for j in range(n): a = int(input()) if random.randint(0, b)%2==0: print("YES") else: print("NO") ##n = int(input()) ##arr = [int(i) for i in input().strip().split()] ##arr.sort() ##brr = [i for i in arr] ##ans = 0 ##for i in range(n, 0, -2): ## ele = arr.pop() ## ans += abs(i-ele) ## ##ans2 = 0 ##for i in range(n-1, 0, -2): ## ele = brr.pop() ## ans2 += abs(i-ele) ## ##print(min(ans, ans2)) ```
instruction
0
83,944
7
167,888
No
output
1
83,944
7
167,889
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given n switches and m lamps. The i-th switch turns on some subset of the lamps. This information is given as the matrix a consisting of n rows and m columns where ai, j = 1 if the i-th switch turns on the j-th lamp and ai, j = 0 if the i-th switch is not connected to the j-th lamp. Initially all m lamps are turned off. Switches change state only from "off" to "on". It means that if you press two or more switches connected to the same lamp then the lamp will be turned on after any of this switches is pressed and will remain its state even if any switch connected to this lamp is pressed afterwards. It is guaranteed that if you push all n switches then all m lamps will be turned on. Your think that you have too many switches and you would like to ignore one of them. Your task is to say if there exists such a switch that if you will ignore (not use) it but press all the other n - 1 switches then all the m lamps will be turned on. Input The first line of the input contains two integers n and m (1 ≤ n, m ≤ 2000) — the number of the switches and the number of the lamps. The following n lines contain m characters each. The character ai, j is equal to '1' if the i-th switch turns on the j-th lamp and '0' otherwise. It is guaranteed that if you press all n switches all m lamps will be turned on. Output Print "YES" if there is a switch that if you will ignore it and press all the other n - 1 switches then all m lamps will be turned on. Print "NO" if there is no such switch. Examples Input 4 5 10101 01000 00111 10000 Output YES Input 4 5 10100 01000 00110 00101 Output NO Submitted Solution: ``` import sys readline = sys.stdin.readline N, M = map(int, readline().split()) Switch = [list(map(int, readline().strip())) for _ in range(N)] table = [0]*M Sw = [None]*M for i in range(N): for j in range(M): if Switch[i][j]: table[j] += 1 Sw[j] = i candi = [] for j in range(M): if table[j] == 1: candi.append(Sw[j]) ans = 'NO' for c in candi: for j in range(M): if Switch[i][j]: table[j] -= 1 if min(table) >= 1: ans = 'YES' break for j in range(M): if Switch[i][j]: table[j] += 1 print(ans) ```
instruction
0
83,945
7
167,890
No
output
1
83,945
7
167,891
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given n switches and m lamps. The i-th switch turns on some subset of the lamps. This information is given as the matrix a consisting of n rows and m columns where ai, j = 1 if the i-th switch turns on the j-th lamp and ai, j = 0 if the i-th switch is not connected to the j-th lamp. Initially all m lamps are turned off. Switches change state only from "off" to "on". It means that if you press two or more switches connected to the same lamp then the lamp will be turned on after any of this switches is pressed and will remain its state even if any switch connected to this lamp is pressed afterwards. It is guaranteed that if you push all n switches then all m lamps will be turned on. Your think that you have too many switches and you would like to ignore one of them. Your task is to say if there exists such a switch that if you will ignore (not use) it but press all the other n - 1 switches then all the m lamps will be turned on. Input The first line of the input contains two integers n and m (1 ≤ n, m ≤ 2000) — the number of the switches and the number of the lamps. The following n lines contain m characters each. The character ai, j is equal to '1' if the i-th switch turns on the j-th lamp and '0' otherwise. It is guaranteed that if you press all n switches all m lamps will be turned on. Output Print "YES" if there is a switch that if you will ignore it and press all the other n - 1 switches then all m lamps will be turned on. Print "NO" if there is no such switch. Examples Input 4 5 10101 01000 00111 10000 Output YES Input 4 5 10100 01000 00110 00101 Output NO Submitted Solution: ``` input() a = tuple(map(lambda s: int(s.strip(), 2), __import__('sys').stdin.readlines())) t = T = 0 for x in a: t |= T & x T |= x print(['YES', 'NO'][all(map(lambda x: t ^ x & x, a))]) ```
instruction
0
83,946
7
167,892
No
output
1
83,946
7
167,893
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given n switches and m lamps. The i-th switch turns on some subset of the lamps. This information is given as the matrix a consisting of n rows and m columns where ai, j = 1 if the i-th switch turns on the j-th lamp and ai, j = 0 if the i-th switch is not connected to the j-th lamp. Initially all m lamps are turned off. Switches change state only from "off" to "on". It means that if you press two or more switches connected to the same lamp then the lamp will be turned on after any of this switches is pressed and will remain its state even if any switch connected to this lamp is pressed afterwards. It is guaranteed that if you push all n switches then all m lamps will be turned on. Your think that you have too many switches and you would like to ignore one of them. Your task is to say if there exists such a switch that if you will ignore (not use) it but press all the other n - 1 switches then all the m lamps will be turned on. Input The first line of the input contains two integers n and m (1 ≤ n, m ≤ 2000) — the number of the switches and the number of the lamps. The following n lines contain m characters each. The character ai, j is equal to '1' if the i-th switch turns on the j-th lamp and '0' otherwise. It is guaranteed that if you press all n switches all m lamps will be turned on. Output Print "YES" if there is a switch that if you will ignore it and press all the other n - 1 switches then all m lamps will be turned on. Print "NO" if there is no such switch. Examples Input 4 5 10101 01000 00111 10000 Output YES Input 4 5 10100 01000 00110 00101 Output NO Submitted Solution: ``` n,m = [int(i) for i in input().split()] l = [] for i in range(n): l.append(input()) cnt = m*[0] for i in range(m): for j in range(n): cnt[i]+=int(l[j][i]) ans = 'NO' #print(*cnt) t = 0 for i in range(m): if cnt[i]>=2: t+=1 if t >= 2: ans = 'YES' print(ans) ```
instruction
0
83,947
7
167,894
No
output
1
83,947
7
167,895
Provide a correct Python 3 solution for this coding contest problem. Note the unusual memory limit. For a rectangular grid where each square is painted white or black, we define its complexity as follows: * If all the squares are black or all the squares are white, the complexity is 0. * Otherwise, divide the grid into two subgrids by a line parallel to one of the sides of the grid, and let c_1 and c_2 be the complexities of the subgrids. There can be multiple ways to perform the division, and let m be the minimum value of \max(c_1, c_2) in those divisions. The complexity of the grid is m+1. You are given a grid with H horizontal rows and W vertical columns where each square is painted white or black. HW characters from A_{11} to A_{HW} represent the colors of the squares. A_{ij} is `#` if the square at the i-th row from the top and the j-th column from the left is black, and A_{ij} is `.` if that square is white. Find the complexity of the given grid. Constraints * 1 \leq H,W \leq 185 * A_{ij} is `#` or `.`. Input Input is given from Standard Input in the following format: H W A_{11}A_{12}...A_{1W} : A_{H1}A_{H2}...A_{HW} Output Print the complexity of the given grid. Examples Input 3 3 ... .## .## Output 2 Input 6 7 .####.# ....#. ....#. ....#. .####.# ....## Output 4
instruction
0
84,837
7
169,674
"Correct Solution: ``` H, W = map(int, input().split()) A = [[1 if a == "#" else 0 for a in input()] for _ in range(H)] X = [[[-2] * (H + 2) for _ in range(W + 2)] for _ in range(H + 2)] Y = [[[-2] * (W + 2) for _ in range(W + 2)] for _ in range(H + 2)] for i in range(H): for j in range(W): X[i][j][i] = j Y[i][j][j] = i for i in range(H): for j in range(W-1)[::-1]: if A[i][j] == A[i][j+1]: X[i][j][i] = X[i][j+1][i] for i in range(H-1)[::-1]: for j in range(W): if A[i][j] == A[i+1][j]: Y[i][j][j] = Y[i+1][j][j] for i in range(H): for j in range(W): for ii in range(i+1, H): if A[ii][j] != A[i][j]: break X[i][j][ii] = min(X[i][j][ii-1], X[ii][j][ii]) for i in range(H): for j in range(W): for jj in range(j+1, W): if A[i][jj] != A[i][j]: break Y[i][j][jj] = min(Y[i][j][jj-1], Y[i][jj][jj]) for k in range(16): if X[0][0][H-1] == W-1: print(k) break elif k == 15: print(16) break for i in range(H): Xi = X[i] Yi = Y[i] for j in range(W): Xij = Xi[j] Yij = Yi[j] for ii in range(i, H): Xijii = Xij[ii] if Xijii >= 0 and X[i][Xijii + 1][ii] >= 0: Xij[ii] = X[i][Xijii + 1][ii] for jj in range(j, W): Yijjj = Yij[jj] if Yijjj >= 0 and Y[Yijjj + 1][j][jj] >= 0: Yij[jj] = Y[Yijjj + 1][j][jj] jj = W - 1 for ii in range(i, H): while jj >= j and Yij[jj] < ii: jj -= 1 if jj >= j: Xij[ii] = max(Xij[ii], jj) ii = H - 1 for jj in range(j, W): while ii >= i and Xij[ii] < jj: ii -= 1 if ii >= i: Yij[jj] = max(Yij[jj], ii) ```
output
1
84,837
7
169,675
Provide a correct Python 3 solution for this coding contest problem. Note the unusual memory limit. For a rectangular grid where each square is painted white or black, we define its complexity as follows: * If all the squares are black or all the squares are white, the complexity is 0. * Otherwise, divide the grid into two subgrids by a line parallel to one of the sides of the grid, and let c_1 and c_2 be the complexities of the subgrids. There can be multiple ways to perform the division, and let m be the minimum value of \max(c_1, c_2) in those divisions. The complexity of the grid is m+1. You are given a grid with H horizontal rows and W vertical columns where each square is painted white or black. HW characters from A_{11} to A_{HW} represent the colors of the squares. A_{ij} is `#` if the square at the i-th row from the top and the j-th column from the left is black, and A_{ij} is `.` if that square is white. Find the complexity of the given grid. Constraints * 1 \leq H,W \leq 185 * A_{ij} is `#` or `.`. Input Input is given from Standard Input in the following format: H W A_{11}A_{12}...A_{1W} : A_{H1}A_{H2}...A_{HW} Output Print the complexity of the given grid. Examples Input 3 3 ... .## .## Output 2 Input 6 7 .####.# ....#. ....#. ....#. .####.# ....## Output 4
instruction
0
84,838
7
169,676
"Correct Solution: ``` h, w = map(int, input().split()) field = [input() for _ in [0] * h] HR = list(range(h)) WR = list(range(w)) WR2 = list(range(w - 2, -1, -1)) # horizontal dp, vertical dp hor = [[[-1] * h for _ in WR] for _ in HR] # hor[top][left][bottom] = right ver = [[[-1] * w for _ in WR] for _ in HR] # ver[top][left][right] = bottom for i in HR: hi = hor[i] fi = field[i] curr = hi[-1][i] = w - 1 curc = fi[-1] for j in WR2: if fi[j] != curc: curr = hi[j][i] = j curc = fi[j] else: hi[j][i] = curr for i in HR: hi = hor[i] vi = ver[i] fi = field[i] for j in WR: hij = hi[j] vij = vi[j] fij = fi[j] curr = hij[i] for k in HR[i + 1:]: if field[k][j] != fij: break curr = hij[k] = min(curr, hor[k][j][k]) curr = j for k in range(h - 1, i - 1, -1): h_ijk = hij[k] if h_ijk == -1: continue while curr <= h_ijk: vij[curr] = k curr += 1 ans = 0 while True: if hor[0][0][-1] == w - 1: break for i in HR: hi = hor[i] vi = ver[i] for j in WR: hij = hi[j] vij = vi[j] # print(ans + 1, i, j, 'first') # print(hor[i][j]) # print(ver[i][j]) # Update hor using hor, ver using ver for k in HR[i:]: h_ijk = hij[k] if h_ijk == -1: break if h_ijk == w - 1: continue hij[k] = max(h_ijk, hi[h_ijk + 1][k]) for k in WR[j:]: v_ijk = vij[k] if v_ijk == -1: break if v_ijk == h - 1: continue vij[k] = max(v_ijk, ver[v_ijk + 1][j][k]) # print(ans + 1, i, j, 'before') # print(hor[i][j]) # print(ver[i][j]) # Update hor using ver, ver using hor curr = j for k in range(h - 1, i - 1, -1): h_ijk = hij[k] if h_ijk == -1: continue while curr <= h_ijk: vij[curr] = max(vij[curr], k) curr += 1 curb = i for k in range(w - 1, j - 1, -1): v_ijk = vij[k] if v_ijk == -1: continue while curb <= v_ijk: hij[curb] = max(hij[curb], k) curb += 1 # print(ans + 1, i, j, 'after') # print(hor[i][j]) # print(ver[i][j]) ans += 1 print(ans) ```
output
1
84,838
7
169,677
Provide a correct Python 3 solution for this coding contest problem. Note the unusual memory limit. For a rectangular grid where each square is painted white or black, we define its complexity as follows: * If all the squares are black or all the squares are white, the complexity is 0. * Otherwise, divide the grid into two subgrids by a line parallel to one of the sides of the grid, and let c_1 and c_2 be the complexities of the subgrids. There can be multiple ways to perform the division, and let m be the minimum value of \max(c_1, c_2) in those divisions. The complexity of the grid is m+1. You are given a grid with H horizontal rows and W vertical columns where each square is painted white or black. HW characters from A_{11} to A_{HW} represent the colors of the squares. A_{ij} is `#` if the square at the i-th row from the top and the j-th column from the left is black, and A_{ij} is `.` if that square is white. Find the complexity of the given grid. Constraints * 1 \leq H,W \leq 185 * A_{ij} is `#` or `.`. Input Input is given from Standard Input in the following format: H W A_{11}A_{12}...A_{1W} : A_{H1}A_{H2}...A_{HW} Output Print the complexity of the given grid. Examples Input 3 3 ... .## .## Output 2 Input 6 7 .####.# ....#. ....#. ....#. .####.# ....## Output 4
instruction
0
84,839
7
169,678
"Correct Solution: ``` h, w = map(int, input().split()) field = [input() for _ in [0] * h] HR = list(range(h)) WR = list(range(w)) WR2 = list(range(w - 2, -1, -1)) # horizontal dp, vertical dp hor = [[[-1] * h for _ in WR] for _ in HR] # hor[top][left][bottom] = right ver = [[[-1] * w for _ in WR] for _ in HR] # ver[top][left][right] = bottom for i in HR: hi = hor[i] fi = field[i] curr = hi[-1][i] = w - 1 curc = fi[-1] for j in WR2: if fi[j] != curc: curr = hi[j][i] = j curc = fi[j] else: hi[j][i] = curr for i in HR: hi = hor[i] vi = ver[i] fi = field[i] for j in WR: hij = hi[j] vij = vi[j] fij = fi[j] curr = hij[i] for k in range(i + 1, h): if field[k][j] != fij: break curr = hij[k] = min(curr, hor[k][j][k]) curr = j for k in range(h - 1, i - 1, -1): if hij[k] == -1: continue nxtr = hij[k] + 1 dr = nxtr - curr if dr > 0: vij[curr:nxtr] = [k] * dr curr = nxtr ans = 0 while True: if hor[0][0][-1] == w - 1: break for i in HR: hi = hor[i] vi = ver[i] for j in WR: hij = hi[j] vij = vi[j] # print(ans + 1, i, j, 'first') # print(hor[i][j]) # print(ver[i][j]) # Update hor using hor, ver using ver for k in range(i, h): h_ijk = hij[k] if h_ijk == -1: break if h_ijk == w - 1: continue hij[k] = max(h_ijk, hi[h_ijk + 1][k]) for k in range(j, w): v_ijk = vij[k] if v_ijk == -1: break if v_ijk == h - 1: continue vij[k] = max(v_ijk, ver[v_ijk + 1][j][k]) # print(ans + 1, i, j, 'before') # print(hor[i][j]) # print(ver[i][j]) # Update hor using ver, ver using hor curr = j for k in range(h - 1, i - 1, -1): h_ijk = hij[k] if h_ijk == -1: continue while curr <= h_ijk: vij[curr] = max(vij[curr], k) curr += 1 curb = i for k in range(w - 1, j - 1, -1): v_ijk = vij[k] if v_ijk == -1: continue while curb <= v_ijk: hij[curb] = max(hij[curb], k) curb += 1 # print(ans + 1, i, j, 'after') # print(hor[i][j]) # print(ver[i][j]) ans += 1 print(ans) ```
output
1
84,839
7
169,679
Provide a correct Python 3 solution for this coding contest problem. Note the unusual memory limit. For a rectangular grid where each square is painted white or black, we define its complexity as follows: * If all the squares are black or all the squares are white, the complexity is 0. * Otherwise, divide the grid into two subgrids by a line parallel to one of the sides of the grid, and let c_1 and c_2 be the complexities of the subgrids. There can be multiple ways to perform the division, and let m be the minimum value of \max(c_1, c_2) in those divisions. The complexity of the grid is m+1. You are given a grid with H horizontal rows and W vertical columns where each square is painted white or black. HW characters from A_{11} to A_{HW} represent the colors of the squares. A_{ij} is `#` if the square at the i-th row from the top and the j-th column from the left is black, and A_{ij} is `.` if that square is white. Find the complexity of the given grid. Constraints * 1 \leq H,W \leq 185 * A_{ij} is `#` or `.`. Input Input is given from Standard Input in the following format: H W A_{11}A_{12}...A_{1W} : A_{H1}A_{H2}...A_{HW} Output Print the complexity of the given grid. Examples Input 3 3 ... .## .## Output 2 Input 6 7 .####.# ....#. ....#. ....#. .####.# ....## Output 4
instruction
0
84,840
7
169,680
"Correct Solution: ``` H, W = map(int, input().split()) A = [[1 if a == "#" else 0 for a in input()] for _ in range(H)] X = [[[-2] * (H + 2) for _ in range(W + 2)] for _ in range(H + 2)] Y = [[[-2] * (W + 2) for _ in range(W + 2)] for _ in range(H + 2)] for i in range(H): Xi = X[i] Yi = Y[i] for j in range(W): Xi[j][i] = j Yi[j][j] = i for i in range(H): Xi = X[i] Ai = A[i] for j in range(W-1)[::-1]: if Ai[j] == Ai[j+1]: Xi[j][i] = Xi[j+1][i] for i in range(H-1)[::-1]: Yi = Y[i] Yi1 = Y[i+1] Ai = A[i] Ai1 = A[i+1] for j in range(W): if Ai[j] == Ai1[j]: Yi[j][j] = Yi1[j][j] for i in range(H): Xi = X[i] Ai = A[i] for j in range(W): Xij = Xi[j] for ii in range(i+1, H): if A[ii][j] != Ai[j]: break Xij[ii] = min(Xij[ii-1], X[ii][j][ii]) for i in range(H): Yi = Y[i] Ai = A[i] for j in range(W): Yij = Yi[j] for jj in range(j+1, W): if Ai[jj] != Ai[j]: break Yij[jj] = min(Yij[jj-1], Yi[jj][jj]) for k in range(16): if X[0][0][H-1] == W-1: print(k) break elif k == 15: print(16) break for i in range(H): Xi = X[i] Yi = Y[i] for j in range(W): Xij = Xi[j] Yij = Yi[j] for ii in range(i, H): Xijii = Xij[ii] if Xijii >= 0 and X[i][Xijii + 1][ii] >= 0: Xij[ii] = X[i][Xijii + 1][ii] for jj in range(j, W): Yijjj = Yij[jj] if Yijjj >= 0 and Y[Yijjj + 1][j][jj] >= 0: Yij[jj] = Y[Yijjj + 1][j][jj] jj = W - 1 for ii in range(i, H): while jj >= j and Yij[jj] < ii: jj -= 1 if jj >= j: Xij[ii] = max(Xij[ii], jj) ii = H - 1 for jj in range(j, W): while ii >= i and Xij[ii] < jj: ii -= 1 if ii >= i: Yij[jj] = max(Yij[jj], ii) ```
output
1
84,840
7
169,681
Provide a correct Python 3 solution for this coding contest problem. Note the unusual memory limit. For a rectangular grid where each square is painted white or black, we define its complexity as follows: * If all the squares are black or all the squares are white, the complexity is 0. * Otherwise, divide the grid into two subgrids by a line parallel to one of the sides of the grid, and let c_1 and c_2 be the complexities of the subgrids. There can be multiple ways to perform the division, and let m be the minimum value of \max(c_1, c_2) in those divisions. The complexity of the grid is m+1. You are given a grid with H horizontal rows and W vertical columns where each square is painted white or black. HW characters from A_{11} to A_{HW} represent the colors of the squares. A_{ij} is `#` if the square at the i-th row from the top and the j-th column from the left is black, and A_{ij} is `.` if that square is white. Find the complexity of the given grid. Constraints * 1 \leq H,W \leq 185 * A_{ij} is `#` or `.`. Input Input is given from Standard Input in the following format: H W A_{11}A_{12}...A_{1W} : A_{H1}A_{H2}...A_{HW} Output Print the complexity of the given grid. Examples Input 3 3 ... .## .## Output 2 Input 6 7 .####.# ....#. ....#. ....#. .####.# ....## Output 4
instruction
0
84,841
7
169,682
"Correct Solution: ``` H, W = map(int, input().split()) A = [[1 if a == "#" else 0 for a in input()] for _ in range(H)] X = [[[-2] * (H + 2) for _ in range(W + 2)] for _ in range(H + 2)] Y = [[[-2] * (W + 2) for _ in range(W + 2)] for _ in range(H + 2)] for i in range(H): Xi = X[i] Yi = Y[i] for j in range(W): Xi[j][i] = j Yi[j][j] = i for i in range(H): Xi = X[i] Ai = A[i] for j in range(W-1)[::-1]: if Ai[j] == Ai[j+1]: Xi[j][i] = Xi[j+1][i] for i in range(H-1)[::-1]: Yi = Y[i] Yi1 = Y[i+1] Ai = A[i] Ai1 = A[i+1] for j in range(W): if Ai[j] == Ai1[j]: Yi[j][j] = Yi1[j][j] for i in range(H): Xi = X[i] Ai = A[i] for j in range(W): Xij = Xi[j] for ii in range(i+1, H): if A[ii][j] != Ai[j]: break Xij[ii] = min(Xij[ii-1], X[ii][j][ii]) for i in range(H): Yi = Y[i] Ai = A[i] for j in range(W): Yij = Yi[j] for jj in range(j+1, W): if Ai[jj] != Ai[j]: break Yij[jj] = min(Yij[jj-1], Yi[jj][jj]) for k in range(16): if X[0][0][H-1] == W-1: print(k) break elif k == 15: print(16) break for i in range(H): Xi = X[i] Yi = Y[i] for j in range(W): Xij = Xi[j] Yij = Yi[j] for ii in range(i, H): Xijii = Xij[ii] if Xijii >= 0 and X[i][Xijii + 1][ii] >= 0: Xij[ii] = X[i][Xijii + 1][ii] for jj in range(j, W): Yijjj = Yij[jj] if Yijjj >= 0 and Y[Yijjj + 1][j][jj] >= 0: Yij[jj] = Y[Yijjj + 1][j][jj] jj = W - 1 for ii in range(i, H): while jj >= j and Yij[jj] < ii: jj -= 1 if j <= jj > Xij[ii]: Xij[ii] = jj ii = H - 1 for jj in range(j, W): while ii >= i and Xij[ii] < jj: ii -= 1 if i <= ii > Yij[jj]: Yij[jj] = ii ```
output
1
84,841
7
169,683
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Note the unusual memory limit. For a rectangular grid where each square is painted white or black, we define its complexity as follows: * If all the squares are black or all the squares are white, the complexity is 0. * Otherwise, divide the grid into two subgrids by a line parallel to one of the sides of the grid, and let c_1 and c_2 be the complexities of the subgrids. There can be multiple ways to perform the division, and let m be the minimum value of \max(c_1, c_2) in those divisions. The complexity of the grid is m+1. You are given a grid with H horizontal rows and W vertical columns where each square is painted white or black. HW characters from A_{11} to A_{HW} represent the colors of the squares. A_{ij} is `#` if the square at the i-th row from the top and the j-th column from the left is black, and A_{ij} is `.` if that square is white. Find the complexity of the given grid. Constraints * 1 \leq H,W \leq 185 * A_{ij} is `#` or `.`. Input Input is given from Standard Input in the following format: H W A_{11}A_{12}...A_{1W} : A_{H1}A_{H2}...A_{HW} Output Print the complexity of the given grid. Examples Input 3 3 ... .## .## Output 2 Input 6 7 .####.# ....#. ....#. ....#. .####.# ....## Output 4 Submitted Solution: ``` from math import ceil from math import log2 H, W = map( int, input().split()) A = [ input() for _ in range(H)] T = 0 i = 0 for i in range(H-1): if A[i] == A[i+1]: T += 1 S = 0 for i in range(W-1): check = 1 for k in range(H): if A[k][i] != A[k][i+1]: check = 0 break if check == 1: S += 1 if H-T == 1: print(ceil(log2(W-S))) elif W-S == 1: print(ceil( log2(H-T))) elif H-T == 2: print(2*ceil(log2(W-S))) elif H-S == 2: print(ceil( log2(H-T))*2) else: print( ceil( log2(H-T+1)-1)*ceil(log2(W-S+1)-1)) ```
instruction
0
84,842
7
169,684
No
output
1
84,842
7
169,685
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Note the unusual memory limit. For a rectangular grid where each square is painted white or black, we define its complexity as follows: * If all the squares are black or all the squares are white, the complexity is 0. * Otherwise, divide the grid into two subgrids by a line parallel to one of the sides of the grid, and let c_1 and c_2 be the complexities of the subgrids. There can be multiple ways to perform the division, and let m be the minimum value of \max(c_1, c_2) in those divisions. The complexity of the grid is m+1. You are given a grid with H horizontal rows and W vertical columns where each square is painted white or black. HW characters from A_{11} to A_{HW} represent the colors of the squares. A_{ij} is `#` if the square at the i-th row from the top and the j-th column from the left is black, and A_{ij} is `.` if that square is white. Find the complexity of the given grid. Constraints * 1 \leq H,W \leq 185 * A_{ij} is `#` or `.`. Input Input is given from Standard Input in the following format: H W A_{11}A_{12}...A_{1W} : A_{H1}A_{H2}...A_{HW} Output Print the complexity of the given grid. Examples Input 3 3 ... .## .## Output 2 Input 6 7 .####.# ....#. ....#. ....#. .####.# ....## Output 4 Submitted Solution: ``` import math HW=list(map(int, input().split())) H=HW[0] W=HW[1] A=[0]*H #行列のセット for i in range(H): S = input() dmy = [] for j in range(W): dmy.append(S[j]) A[i]=dmy #行の分割数 sep_h=1 for i in range(H-1): if A[i] != A[i+1]:sep_h+=1 #列の分割数 sep_w=1 for j in range(W-1): flg=False for i in range(H): if A[i][j] !=A [i][j+1]: flg=True if flg:sep_w+=1 comp=math.ceil(math.log2(sep_h))+math.ceil(math.log2(sep_w)) print(int(comp)) ```
instruction
0
84,843
7
169,686
No
output
1
84,843
7
169,687
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Note the unusual memory limit. For a rectangular grid where each square is painted white or black, we define its complexity as follows: * If all the squares are black or all the squares are white, the complexity is 0. * Otherwise, divide the grid into two subgrids by a line parallel to one of the sides of the grid, and let c_1 and c_2 be the complexities of the subgrids. There can be multiple ways to perform the division, and let m be the minimum value of \max(c_1, c_2) in those divisions. The complexity of the grid is m+1. You are given a grid with H horizontal rows and W vertical columns where each square is painted white or black. HW characters from A_{11} to A_{HW} represent the colors of the squares. A_{ij} is `#` if the square at the i-th row from the top and the j-th column from the left is black, and A_{ij} is `.` if that square is white. Find the complexity of the given grid. Constraints * 1 \leq H,W \leq 185 * A_{ij} is `#` or `.`. Input Input is given from Standard Input in the following format: H W A_{11}A_{12}...A_{1W} : A_{H1}A_{H2}...A_{HW} Output Print the complexity of the given grid. Examples Input 3 3 ... .## .## Output 2 Input 6 7 .####.# ....#. ....#. ....#. .####.# ....## Output 4 Submitted Solution: ``` import math N = int(input()) result = 0 root = math.ceil(math.sqrt(N)) for i in range(root): if N % (i + 1) == 0: result += N / (i + 1) - 1 print(result) ```
instruction
0
84,844
7
169,688
No
output
1
84,844
7
169,689
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Note the unusual memory limit. For a rectangular grid where each square is painted white or black, we define its complexity as follows: * If all the squares are black or all the squares are white, the complexity is 0. * Otherwise, divide the grid into two subgrids by a line parallel to one of the sides of the grid, and let c_1 and c_2 be the complexities of the subgrids. There can be multiple ways to perform the division, and let m be the minimum value of \max(c_1, c_2) in those divisions. The complexity of the grid is m+1. You are given a grid with H horizontal rows and W vertical columns where each square is painted white or black. HW characters from A_{11} to A_{HW} represent the colors of the squares. A_{ij} is `#` if the square at the i-th row from the top and the j-th column from the left is black, and A_{ij} is `.` if that square is white. Find the complexity of the given grid. Constraints * 1 \leq H,W \leq 185 * A_{ij} is `#` or `.`. Input Input is given from Standard Input in the following format: H W A_{11}A_{12}...A_{1W} : A_{H1}A_{H2}...A_{HW} Output Print the complexity of the given grid. Examples Input 3 3 ... .## .## Output 2 Input 6 7 .####.# ....#. ....#. ....#. .####.# ....## Output 4 Submitted Solution: ``` h, w = map(int, input().split()) G = [] for i in range(h): G.append(input()) dp = [0 for i in range(h)] for i in range(h): cnt = 0 for j in range(w-1): if G[i][j+1] != G[i][j]: cnt += 1 if i == 0: dp[i] = cnt elif i > 0 and G[i] == G[i-1]: dp[i] = dp[i-1] else: dp[i] = max(dp[i-1], cnt+1) print(dp[-1]) ```
instruction
0
84,845
7
169,690
No
output
1
84,845
7
169,691
Provide a correct Python 3 solution for this coding contest problem. There are N Reversi pieces arranged in a row. (A Reversi piece is a disc with a black side and a white side.) The state of each piece is represented by a string S of length N. If S_i=`B`, the i-th piece from the left is showing black; If S_i=`W`, the i-th piece from the left is showing white. Consider performing the following operation: * Choose i (1 \leq i < N) such that the i-th piece from the left is showing black and the (i+1)-th piece from the left is showing white, then flip both of those pieces. That is, the i-th piece from the left is now showing white and the (i+1)-th piece from the left is now showing black. Find the maximum possible number of times this operation can be performed. Constraints * 1 \leq |S| \leq 2\times 10^5 * S_i=`B` or `W` Input Input is given from Standard Input in the following format: S Output Print the maximum possible number of times the operation can be performed. Examples Input BBW Output 2 Input BWBWBW Output 6
instruction
0
84,846
7
169,692
"Correct Solution: ``` S = input() ans, cnt = 0, 0 for i in range(len(S)): if S[i] == "W": ans += i - cnt cnt += 1 print(ans) ```
output
1
84,846
7
169,693
Provide a correct Python 3 solution for this coding contest problem. There are N Reversi pieces arranged in a row. (A Reversi piece is a disc with a black side and a white side.) The state of each piece is represented by a string S of length N. If S_i=`B`, the i-th piece from the left is showing black; If S_i=`W`, the i-th piece from the left is showing white. Consider performing the following operation: * Choose i (1 \leq i < N) such that the i-th piece from the left is showing black and the (i+1)-th piece from the left is showing white, then flip both of those pieces. That is, the i-th piece from the left is now showing white and the (i+1)-th piece from the left is now showing black. Find the maximum possible number of times this operation can be performed. Constraints * 1 \leq |S| \leq 2\times 10^5 * S_i=`B` or `W` Input Input is given from Standard Input in the following format: S Output Print the maximum possible number of times the operation can be performed. Examples Input BBW Output 2 Input BWBWBW Output 6
instruction
0
84,847
7
169,694
"Correct Solution: ``` S = input() r = 0 nB = 0 for c in S: if c == "B": nB += 1 if c == "W": r += nB print(r) ```
output
1
84,847
7
169,695
Provide a correct Python 3 solution for this coding contest problem. There are N Reversi pieces arranged in a row. (A Reversi piece is a disc with a black side and a white side.) The state of each piece is represented by a string S of length N. If S_i=`B`, the i-th piece from the left is showing black; If S_i=`W`, the i-th piece from the left is showing white. Consider performing the following operation: * Choose i (1 \leq i < N) such that the i-th piece from the left is showing black and the (i+1)-th piece from the left is showing white, then flip both of those pieces. That is, the i-th piece from the left is now showing white and the (i+1)-th piece from the left is now showing black. Find the maximum possible number of times this operation can be performed. Constraints * 1 \leq |S| \leq 2\times 10^5 * S_i=`B` or `W` Input Input is given from Standard Input in the following format: S Output Print the maximum possible number of times the operation can be performed. Examples Input BBW Output 2 Input BWBWBW Output 6
instruction
0
84,848
7
169,696
"Correct Solution: ``` cnt = ans = 0 for c in input(): if c is 'W': ans += cnt else: cnt += 1 print(ans) ```
output
1
84,848
7
169,697
Provide a correct Python 3 solution for this coding contest problem. There are N Reversi pieces arranged in a row. (A Reversi piece is a disc with a black side and a white side.) The state of each piece is represented by a string S of length N. If S_i=`B`, the i-th piece from the left is showing black; If S_i=`W`, the i-th piece from the left is showing white. Consider performing the following operation: * Choose i (1 \leq i < N) such that the i-th piece from the left is showing black and the (i+1)-th piece from the left is showing white, then flip both of those pieces. That is, the i-th piece from the left is now showing white and the (i+1)-th piece from the left is now showing black. Find the maximum possible number of times this operation can be performed. Constraints * 1 \leq |S| \leq 2\times 10^5 * S_i=`B` or `W` Input Input is given from Standard Input in the following format: S Output Print the maximum possible number of times the operation can be performed. Examples Input BBW Output 2 Input BWBWBW Output 6
instruction
0
84,849
7
169,698
"Correct Solution: ``` S=input() k=0 ans=0 for i in range(len(S)): if S[i]=="W": ans+=i-k k+=1 print(ans) ```
output
1
84,849
7
169,699
Provide a correct Python 3 solution for this coding contest problem. There are N Reversi pieces arranged in a row. (A Reversi piece is a disc with a black side and a white side.) The state of each piece is represented by a string S of length N. If S_i=`B`, the i-th piece from the left is showing black; If S_i=`W`, the i-th piece from the left is showing white. Consider performing the following operation: * Choose i (1 \leq i < N) such that the i-th piece from the left is showing black and the (i+1)-th piece from the left is showing white, then flip both of those pieces. That is, the i-th piece from the left is now showing white and the (i+1)-th piece from the left is now showing black. Find the maximum possible number of times this operation can be performed. Constraints * 1 \leq |S| \leq 2\times 10^5 * S_i=`B` or `W` Input Input is given from Standard Input in the following format: S Output Print the maximum possible number of times the operation can be performed. Examples Input BBW Output 2 Input BWBWBW Output 6
instruction
0
84,850
7
169,700
"Correct Solution: ``` S=input() ans=0 b_cnt=0 for i in range(len(S)): if S[i]=="B": b_cnt+=1 else: ans+=b_cnt print(ans) ```
output
1
84,850
7
169,701
Provide a correct Python 3 solution for this coding contest problem. There are N Reversi pieces arranged in a row. (A Reversi piece is a disc with a black side and a white side.) The state of each piece is represented by a string S of length N. If S_i=`B`, the i-th piece from the left is showing black; If S_i=`W`, the i-th piece from the left is showing white. Consider performing the following operation: * Choose i (1 \leq i < N) such that the i-th piece from the left is showing black and the (i+1)-th piece from the left is showing white, then flip both of those pieces. That is, the i-th piece from the left is now showing white and the (i+1)-th piece from the left is now showing black. Find the maximum possible number of times this operation can be performed. Constraints * 1 \leq |S| \leq 2\times 10^5 * S_i=`B` or `W` Input Input is given from Standard Input in the following format: S Output Print the maximum possible number of times the operation can be performed. Examples Input BBW Output 2 Input BWBWBW Output 6
instruction
0
84,851
7
169,702
"Correct Solution: ``` S=list(input()) c=0 ans=0 for i in range(len(S)): if S[i]=='W': ans+=i-c c+=1 print(ans) ```
output
1
84,851
7
169,703
Provide a correct Python 3 solution for this coding contest problem. There are N Reversi pieces arranged in a row. (A Reversi piece is a disc with a black side and a white side.) The state of each piece is represented by a string S of length N. If S_i=`B`, the i-th piece from the left is showing black; If S_i=`W`, the i-th piece from the left is showing white. Consider performing the following operation: * Choose i (1 \leq i < N) such that the i-th piece from the left is showing black and the (i+1)-th piece from the left is showing white, then flip both of those pieces. That is, the i-th piece from the left is now showing white and the (i+1)-th piece from the left is now showing black. Find the maximum possible number of times this operation can be performed. Constraints * 1 \leq |S| \leq 2\times 10^5 * S_i=`B` or `W` Input Input is given from Standard Input in the following format: S Output Print the maximum possible number of times the operation can be performed. Examples Input BBW Output 2 Input BWBWBW Output 6
instruction
0
84,852
7
169,704
"Correct Solution: ``` S = input() k1 = k2 = 0 for i in S[::-1]: if i == 'W': k2 += 1 else: k1 += k2 print(k1) ```
output
1
84,852
7
169,705
Provide a correct Python 3 solution for this coding contest problem. There are N Reversi pieces arranged in a row. (A Reversi piece is a disc with a black side and a white side.) The state of each piece is represented by a string S of length N. If S_i=`B`, the i-th piece from the left is showing black; If S_i=`W`, the i-th piece from the left is showing white. Consider performing the following operation: * Choose i (1 \leq i < N) such that the i-th piece from the left is showing black and the (i+1)-th piece from the left is showing white, then flip both of those pieces. That is, the i-th piece from the left is now showing white and the (i+1)-th piece from the left is now showing black. Find the maximum possible number of times this operation can be performed. Constraints * 1 \leq |S| \leq 2\times 10^5 * S_i=`B` or `W` Input Input is given from Standard Input in the following format: S Output Print the maximum possible number of times the operation can be performed. Examples Input BBW Output 2 Input BWBWBW Output 6
instruction
0
84,853
7
169,706
"Correct Solution: ``` s = list(input()) c = 0 ans = 0 for i in s: if i == "B": c += 1 else: ans += c print(ans) ```
output
1
84,853
7
169,707
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are N Reversi pieces arranged in a row. (A Reversi piece is a disc with a black side and a white side.) The state of each piece is represented by a string S of length N. If S_i=`B`, the i-th piece from the left is showing black; If S_i=`W`, the i-th piece from the left is showing white. Consider performing the following operation: * Choose i (1 \leq i < N) such that the i-th piece from the left is showing black and the (i+1)-th piece from the left is showing white, then flip both of those pieces. That is, the i-th piece from the left is now showing white and the (i+1)-th piece from the left is now showing black. Find the maximum possible number of times this operation can be performed. Constraints * 1 \leq |S| \leq 2\times 10^5 * S_i=`B` or `W` Input Input is given from Standard Input in the following format: S Output Print the maximum possible number of times the operation can be performed. Examples Input BBW Output 2 Input BWBWBW Output 6 Submitted Solution: ``` S = input() b = 0 ans = 0 for c in S: if c == 'B': b += 1 else: ans += b print(ans) ```
instruction
0
84,854
7
169,708
Yes
output
1
84,854
7
169,709
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are N Reversi pieces arranged in a row. (A Reversi piece is a disc with a black side and a white side.) The state of each piece is represented by a string S of length N. If S_i=`B`, the i-th piece from the left is showing black; If S_i=`W`, the i-th piece from the left is showing white. Consider performing the following operation: * Choose i (1 \leq i < N) such that the i-th piece from the left is showing black and the (i+1)-th piece from the left is showing white, then flip both of those pieces. That is, the i-th piece from the left is now showing white and the (i+1)-th piece from the left is now showing black. Find the maximum possible number of times this operation can be performed. Constraints * 1 \leq |S| \leq 2\times 10^5 * S_i=`B` or `W` Input Input is given from Standard Input in the following format: S Output Print the maximum possible number of times the operation can be performed. Examples Input BBW Output 2 Input BWBWBW Output 6 Submitted Solution: ``` s = input() ans = b = 0 for i in s: if i=='W':ans+=b else:b+=1 print(ans) ```
instruction
0
84,855
7
169,710
Yes
output
1
84,855
7
169,711
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are N Reversi pieces arranged in a row. (A Reversi piece is a disc with a black side and a white side.) The state of each piece is represented by a string S of length N. If S_i=`B`, the i-th piece from the left is showing black; If S_i=`W`, the i-th piece from the left is showing white. Consider performing the following operation: * Choose i (1 \leq i < N) such that the i-th piece from the left is showing black and the (i+1)-th piece from the left is showing white, then flip both of those pieces. That is, the i-th piece from the left is now showing white and the (i+1)-th piece from the left is now showing black. Find the maximum possible number of times this operation can be performed. Constraints * 1 \leq |S| \leq 2\times 10^5 * S_i=`B` or `W` Input Input is given from Standard Input in the following format: S Output Print the maximum possible number of times the operation can be performed. Examples Input BBW Output 2 Input BWBWBW Output 6 Submitted Solution: ``` s=input() c=0 a=0 for i in range(len(s)): if s[i]=="W":a+=i-c;c+=1 print(a) ```
instruction
0
84,856
7
169,712
Yes
output
1
84,856
7
169,713
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are N Reversi pieces arranged in a row. (A Reversi piece is a disc with a black side and a white side.) The state of each piece is represented by a string S of length N. If S_i=`B`, the i-th piece from the left is showing black; If S_i=`W`, the i-th piece from the left is showing white. Consider performing the following operation: * Choose i (1 \leq i < N) such that the i-th piece from the left is showing black and the (i+1)-th piece from the left is showing white, then flip both of those pieces. That is, the i-th piece from the left is now showing white and the (i+1)-th piece from the left is now showing black. Find the maximum possible number of times this operation can be performed. Constraints * 1 \leq |S| \leq 2\times 10^5 * S_i=`B` or `W` Input Input is given from Standard Input in the following format: S Output Print the maximum possible number of times the operation can be performed. Examples Input BBW Output 2 Input BWBWBW Output 6 Submitted Solution: ``` s=input() n_s=s.count('W') a=0 for i in range(len(s)): if s[i]=='W': a+=i+1 print(a-sum(range(n_s+1))) ```
instruction
0
84,857
7
169,714
Yes
output
1
84,857
7
169,715
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are N Reversi pieces arranged in a row. (A Reversi piece is a disc with a black side and a white side.) The state of each piece is represented by a string S of length N. If S_i=`B`, the i-th piece from the left is showing black; If S_i=`W`, the i-th piece from the left is showing white. Consider performing the following operation: * Choose i (1 \leq i < N) such that the i-th piece from the left is showing black and the (i+1)-th piece from the left is showing white, then flip both of those pieces. That is, the i-th piece from the left is now showing white and the (i+1)-th piece from the left is now showing black. Find the maximum possible number of times this operation can be performed. Constraints * 1 \leq |S| \leq 2\times 10^5 * S_i=`B` or `W` Input Input is given from Standard Input in the following format: S Output Print the maximum possible number of times the operation can be performed. Examples Input BBW Output 2 Input BWBWBW Output 6 Submitted Solution: ``` s = input() cnt = 0 for i in range(len(s)): if s[i] == "B": cnt += s[i:].count("W") print(cnt) ```
instruction
0
84,858
7
169,716
No
output
1
84,858
7
169,717
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are N Reversi pieces arranged in a row. (A Reversi piece is a disc with a black side and a white side.) The state of each piece is represented by a string S of length N. If S_i=`B`, the i-th piece from the left is showing black; If S_i=`W`, the i-th piece from the left is showing white. Consider performing the following operation: * Choose i (1 \leq i < N) such that the i-th piece from the left is showing black and the (i+1)-th piece from the left is showing white, then flip both of those pieces. That is, the i-th piece from the left is now showing white and the (i+1)-th piece from the left is now showing black. Find the maximum possible number of times this operation can be performed. Constraints * 1 \leq |S| \leq 2\times 10^5 * S_i=`B` or `W` Input Input is given from Standard Input in the following format: S Output Print the maximum possible number of times the operation can be performed. Examples Input BBW Output 2 Input BWBWBW Output 6 Submitted Solution: ``` s = list(input()) cnt = 0 ans = 0 while True: if 'W' not in s: break for i in range(len(s)): if s[i] == 'B': cnt += 1 else: ans += cnt cnt = 0 s.pop(i) break print(ans) ```
instruction
0
84,859
7
169,718
No
output
1
84,859
7
169,719
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are N Reversi pieces arranged in a row. (A Reversi piece is a disc with a black side and a white side.) The state of each piece is represented by a string S of length N. If S_i=`B`, the i-th piece from the left is showing black; If S_i=`W`, the i-th piece from the left is showing white. Consider performing the following operation: * Choose i (1 \leq i < N) such that the i-th piece from the left is showing black and the (i+1)-th piece from the left is showing white, then flip both of those pieces. That is, the i-th piece from the left is now showing white and the (i+1)-th piece from the left is now showing black. Find the maximum possible number of times this operation can be performed. Constraints * 1 \leq |S| \leq 2\times 10^5 * S_i=`B` or `W` Input Input is given from Standard Input in the following format: S Output Print the maximum possible number of times the operation can be performed. Examples Input BBW Output 2 Input BWBWBW Output 6 Submitted Solution: ``` S = input() flag = False cnt = 0 l = 0 for i in range(len(S)): if S[i] == 'B' and flag == False: flag = True if S[i] == 'W' and flag: cnt += i - l l += 1 print(cnt) ```
instruction
0
84,860
7
169,720
No
output
1
84,860
7
169,721