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
Provide tags and a correct Python 3 solution for this coding contest problem. You finally woke up after this crazy dream and decided to walk around to clear your head. Outside you saw your house's fence β€” so plain and boring, that you'd like to repaint it. <image> You have a fence consisting of n planks, where the i-th plank has the color a_i. You want to repaint the fence in such a way that the i-th plank has the color b_i. You've invited m painters for this purpose. The j-th painter will arrive at the moment j and will recolor exactly one plank to color c_j. For each painter you can choose which plank to recolor, but you can't turn them down, i. e. each painter has to color exactly one plank. Can you get the coloring b you want? If it's possible, print for each painter which plank he must paint. Input The first line contains one integer t (1 ≀ t ≀ 10^4) β€” the number of test cases. Then t test cases follow. The first line of each test case contains two integers n and m (1 ≀ n, m ≀ 10^5) β€” the number of planks in the fence and the number of painters. The second line of each test case contains n integers a_1, a_2, ..., a_n (1 ≀ a_i ≀ n) β€” the initial colors of the fence. The third line of each test case contains n integers b_1, b_2, ..., b_n (1 ≀ b_i ≀ n) β€” the desired colors of the fence. The fourth line of each test case contains m integers c_1, c_2, ..., c_m (1 ≀ c_j ≀ n) β€” the colors painters have. It's guaranteed that the sum of n doesn't exceed 10^5 and the sum of m doesn't exceed 10^5 over all test cases. Output For each test case, output "NO" if it is impossible to achieve the coloring b. Otherwise, print "YES" and m integers x_1, x_2, ..., x_m, where x_j is the index of plank the j-th painter should paint. You may print every letter in any case you want (so, for example, the strings "yEs", "yes", "Yes" and "YES" are all recognized as positive answer). Example Input 6 1 1 1 1 1 5 2 1 2 2 1 1 1 2 2 1 1 1 2 3 3 2 2 2 2 2 2 2 3 2 10 5 7 3 2 1 7 9 4 2 7 9 9 9 2 1 4 9 4 2 3 9 9 9 7 4 3 5 2 1 2 2 1 1 1 2 2 1 1 3 3 6 4 3 4 2 4 1 2 2 3 1 3 1 1 2 2 3 4 Output YES 1 YES 2 2 YES 1 1 1 YES 2 1 9 5 9 NO NO
instruction
0
82,804
7
165,608
Tags: brute force, constructive algorithms, greedy Correct Solution: ``` import sys import math from collections import defaultdict,Counter,deque # input=sys.stdin.readline # def print(x): # sys.stdout.write(str(x)+"\n") 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") # sys.stdout=open("CP2/output.txt",'w') # sys.stdin=open("CP2/input.txt",'r') # mod=pow(10,9)+7 t=int(input()) for i in range(t): n,m=map(int,input().split()) a=list(map(int,input().split())) b=list(map(int,input().split())) c=list(map(int,input().split())) d1=defaultdict(list) d2={} for j in range(n): if a[j]!=b[j]: d1[b[j]].append(j+1) else: d2[b[j]]=j+1 # print(d2) ans=[0]*m last=-1 flag=1 for j in range(m): if d1[c[j]]: ans[j]=d1[c[j]].pop() if len(d1[c[j]])==0: d2[c[j]]=ans[j] elif d2.get(c[j])!=None: ans[j]=d2[c[j]] # elif d1.get(c[j])==None: # last=j else: last=j # break # print(d1) # print(ans) for j in d1: if len(d1[j])>0: flag=0 break if flag==0 or last==m-1: print("NO") else: print("YES") for j in ans: if j==0: print(ans[-1],end=' ') else: print(j,end=' ') print() ```
output
1
82,804
7
165,609
Provide tags and a correct Python 3 solution for this coding contest problem. You finally woke up after this crazy dream and decided to walk around to clear your head. Outside you saw your house's fence β€” so plain and boring, that you'd like to repaint it. <image> You have a fence consisting of n planks, where the i-th plank has the color a_i. You want to repaint the fence in such a way that the i-th plank has the color b_i. You've invited m painters for this purpose. The j-th painter will arrive at the moment j and will recolor exactly one plank to color c_j. For each painter you can choose which plank to recolor, but you can't turn them down, i. e. each painter has to color exactly one plank. Can you get the coloring b you want? If it's possible, print for each painter which plank he must paint. Input The first line contains one integer t (1 ≀ t ≀ 10^4) β€” the number of test cases. Then t test cases follow. The first line of each test case contains two integers n and m (1 ≀ n, m ≀ 10^5) β€” the number of planks in the fence and the number of painters. The second line of each test case contains n integers a_1, a_2, ..., a_n (1 ≀ a_i ≀ n) β€” the initial colors of the fence. The third line of each test case contains n integers b_1, b_2, ..., b_n (1 ≀ b_i ≀ n) β€” the desired colors of the fence. The fourth line of each test case contains m integers c_1, c_2, ..., c_m (1 ≀ c_j ≀ n) β€” the colors painters have. It's guaranteed that the sum of n doesn't exceed 10^5 and the sum of m doesn't exceed 10^5 over all test cases. Output For each test case, output "NO" if it is impossible to achieve the coloring b. Otherwise, print "YES" and m integers x_1, x_2, ..., x_m, where x_j is the index of plank the j-th painter should paint. You may print every letter in any case you want (so, for example, the strings "yEs", "yes", "Yes" and "YES" are all recognized as positive answer). Example Input 6 1 1 1 1 1 5 2 1 2 2 1 1 1 2 2 1 1 1 2 3 3 2 2 2 2 2 2 2 3 2 10 5 7 3 2 1 7 9 4 2 7 9 9 9 2 1 4 9 4 2 3 9 9 9 7 4 3 5 2 1 2 2 1 1 1 2 2 1 1 3 3 6 4 3 4 2 4 1 2 2 3 1 3 1 1 2 2 3 4 Output YES 1 YES 2 2 YES 1 1 1 YES 2 1 9 5 9 NO NO
instruction
0
82,805
7
165,610
Tags: brute force, constructive algorithms, greedy Correct Solution: ``` from collections import defaultdict as dd for _ in range(int(input())): n, m = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) c = list(map(int, input().split())) dic = dd(lambda : 0) dic3 = dd(lambda : 0) dic2 = dd(lambda : []) for el in c:dic3[el] += 1 i = 1 req = 0 ansTruth = True for el, el1 in zip(b, a): if el != el1: req += 1 if dic3[el] == 0:ansTruth = False;break dic[el] += 1 dic2[el].append(i) i+=1 if not ansTruth:print("NO");continue ans = [] chng = -1 for el in c[::-1]: if dic[el] > 0: ind = dic2[el][dic[el]*(-1)] ans.append(ind) if a[ind - 1] != b[ind - 1]:req-=1 a[ind - 1] = el;dic[el] -= 1 if chng == -1:chng = ind elif chng != -1: ans.append(chng) elif el in b: chng = b.index(el) + 1 ans.append(chng) else: ansTruth = False;break if req > 0: ansTruth = False if ansTruth: print("YES") print(*ans[::-1]) else:print("NO") ```
output
1
82,805
7
165,611
Provide tags and a correct Python 3 solution for this coding contest problem. You finally woke up after this crazy dream and decided to walk around to clear your head. Outside you saw your house's fence β€” so plain and boring, that you'd like to repaint it. <image> You have a fence consisting of n planks, where the i-th plank has the color a_i. You want to repaint the fence in such a way that the i-th plank has the color b_i. You've invited m painters for this purpose. The j-th painter will arrive at the moment j and will recolor exactly one plank to color c_j. For each painter you can choose which plank to recolor, but you can't turn them down, i. e. each painter has to color exactly one plank. Can you get the coloring b you want? If it's possible, print for each painter which plank he must paint. Input The first line contains one integer t (1 ≀ t ≀ 10^4) β€” the number of test cases. Then t test cases follow. The first line of each test case contains two integers n and m (1 ≀ n, m ≀ 10^5) β€” the number of planks in the fence and the number of painters. The second line of each test case contains n integers a_1, a_2, ..., a_n (1 ≀ a_i ≀ n) β€” the initial colors of the fence. The third line of each test case contains n integers b_1, b_2, ..., b_n (1 ≀ b_i ≀ n) β€” the desired colors of the fence. The fourth line of each test case contains m integers c_1, c_2, ..., c_m (1 ≀ c_j ≀ n) β€” the colors painters have. It's guaranteed that the sum of n doesn't exceed 10^5 and the sum of m doesn't exceed 10^5 over all test cases. Output For each test case, output "NO" if it is impossible to achieve the coloring b. Otherwise, print "YES" and m integers x_1, x_2, ..., x_m, where x_j is the index of plank the j-th painter should paint. You may print every letter in any case you want (so, for example, the strings "yEs", "yes", "Yes" and "YES" are all recognized as positive answer). Example Input 6 1 1 1 1 1 5 2 1 2 2 1 1 1 2 2 1 1 1 2 3 3 2 2 2 2 2 2 2 3 2 10 5 7 3 2 1 7 9 4 2 7 9 9 9 2 1 4 9 4 2 3 9 9 9 7 4 3 5 2 1 2 2 1 1 1 2 2 1 1 3 3 6 4 3 4 2 4 1 2 2 3 1 3 1 1 2 2 3 4 Output YES 1 YES 2 2 YES 1 1 1 YES 2 1 9 5 9 NO NO
instruction
0
82,806
7
165,612
Tags: brute force, constructive algorithms, greedy Correct Solution: ``` from sys import stdin from math import ceil input = stdin.readline def main(): t = int(input()) for i in range(t): n,m = map(int,input().split()) ai = list(map(int,input().split())) bi = list(map(int,input().split())) ais = {} bs = {} ar = {} for i in range(n+1): ais[i] = [] bs[i] = [] ar[i] = [1] for i in range(n): bs[bi[i]] += [i+1] if ai[i] != bi[i]: ar[bi[i]] += [i+1] else: ais[ai[i]] += [i+1] ci = list(map(int,input().split())) anss = [0]*m ans = 1 prev = -1 for i in range(m-1,-1,-1): temp = ar[ci[i]] if temp[0] == len(temp): if prev != -1: anss[i] = prev else: temp2 = ais[ci[i]] if len(temp2) != 0: anss[i] = temp2[0] else: temp2 = bs[ci[i]] if len(temp2) != 0: anss[i] = temp2[0] else: ans = 0 break else: anss[i] = temp[temp[0]] temp[0] += 1 prev = anss[m-1] for i in range(n+1): temp = ar[i] if temp[0] != len(temp): ans = 0 break if ans == 1: print("YES") print(" ".join(map(str,anss))) else: print("NO") main() ```
output
1
82,806
7
165,613
Provide tags and a correct Python 3 solution for this coding contest problem. You finally woke up after this crazy dream and decided to walk around to clear your head. Outside you saw your house's fence β€” so plain and boring, that you'd like to repaint it. <image> You have a fence consisting of n planks, where the i-th plank has the color a_i. You want to repaint the fence in such a way that the i-th plank has the color b_i. You've invited m painters for this purpose. The j-th painter will arrive at the moment j and will recolor exactly one plank to color c_j. For each painter you can choose which plank to recolor, but you can't turn them down, i. e. each painter has to color exactly one plank. Can you get the coloring b you want? If it's possible, print for each painter which plank he must paint. Input The first line contains one integer t (1 ≀ t ≀ 10^4) β€” the number of test cases. Then t test cases follow. The first line of each test case contains two integers n and m (1 ≀ n, m ≀ 10^5) β€” the number of planks in the fence and the number of painters. The second line of each test case contains n integers a_1, a_2, ..., a_n (1 ≀ a_i ≀ n) β€” the initial colors of the fence. The third line of each test case contains n integers b_1, b_2, ..., b_n (1 ≀ b_i ≀ n) β€” the desired colors of the fence. The fourth line of each test case contains m integers c_1, c_2, ..., c_m (1 ≀ c_j ≀ n) β€” the colors painters have. It's guaranteed that the sum of n doesn't exceed 10^5 and the sum of m doesn't exceed 10^5 over all test cases. Output For each test case, output "NO" if it is impossible to achieve the coloring b. Otherwise, print "YES" and m integers x_1, x_2, ..., x_m, where x_j is the index of plank the j-th painter should paint. You may print every letter in any case you want (so, for example, the strings "yEs", "yes", "Yes" and "YES" are all recognized as positive answer). Example Input 6 1 1 1 1 1 5 2 1 2 2 1 1 1 2 2 1 1 1 2 3 3 2 2 2 2 2 2 2 3 2 10 5 7 3 2 1 7 9 4 2 7 9 9 9 2 1 4 9 4 2 3 9 9 9 7 4 3 5 2 1 2 2 1 1 1 2 2 1 1 3 3 6 4 3 4 2 4 1 2 2 3 1 3 1 1 2 2 3 4 Output YES 1 YES 2 2 YES 1 1 1 YES 2 1 9 5 9 NO NO
instruction
0
82,807
7
165,614
Tags: brute force, constructive algorithms, greedy Correct Solution: ``` ''' =============================== -- @uthor : Kaleab Asfaw -- Handle : kaleabasfaw2010 -- Bio : High-School Student ===============================''' # Fast IO import sys import os 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") # Others # from math import floor, ceil, gcd # from decimal import Decimal as d import copy mod = 10**9+7 def lcm(x, y): return (x * y) / (gcd(x, y)) def fact(x, mod=mod): ans = 1 for i in range(1, x+1): ans = (ans * i) % mod return ans def arr2D(n, m, default=0): return [[default for j in range(m)] for i in range(n)] def arr3D(n, m, r, default=0): return [[[default for k in range(r)] for j in range(m)] for i in range(n)] def sortDictV(x): return {k: v for k, v in sorted(x.items(), key = lambda item : item[1])} class DSU: def __init__(self, length): self.length = length; self.parent = [-1] * self.length # O(log(n)) def getParent(self, node, start): # O(log(n)) if node >= self.length: return False if self.parent[node] < 0: if start != node: self.parent[start] = node return node return self.getParent(self.parent[node], start) def union(self, node1, node2): # O(log(n)) parent1 = self.getParent(node1, node1); parent2 = self.getParent(node2, node2) if parent1 == parent2: return False elif self.parent[parent1] <= self.parent[parent2]: self.parent[parent1] += self.parent[parent2]; self.parent[parent2] = parent1 else: self.parent[parent2] += self.parent[parent1]; self.parent[parent1] = parent2 return True def getCount(self, node): return -self.parent[self.getParent(node, node)] # O(log(n)) def exact(num): if abs(num - round(num)) <= 10**(-9):return round(num) return num def notSame(a, b): for i in range(len(a)): if a[i] != b[i]: return True return False def solve(n, m, a, b, c): diff = 0 want = {} for i in range(n): if a[i] != b[i]: diff += 1 if want.get(b[i]) == None: want[b[i]] = 1 else: want[b[i]] += 1 needed = 0 cMap = {} for i in c: if cMap.get(i) == None: cMap[i] = 0 cMap[i] += 1 for i in cMap: val = want.get(i) if val == None: val = 0 needed += min(val, cMap[i]) # print(needed, diff) if needed < diff: print("NO") return if c[-1] not in b: print("NO") return lastind = -1 get = False for i in range(n): if a[i] != b[i] and b[i] == c[-1]: lastind = i get = True if get == False: for i in range(n): if b[i] == c[-1]: lastind = i paintedTo = {} for i in range(n): if a[i] != b[i] and i != lastind: if paintedTo.get(b[i]) == None: paintedTo[b[i]] = [i] else: paintedTo[b[i]].append(i) ans = [] for i in c[:-1]: if paintedTo.get(i) == None: ans.append(lastind) else: if len(paintedTo[i]) == 0: ans.append(lastind) else: val = paintedTo[i].pop() if val == lastind: val = paintedTo[i].pop() ans.append(val) # for i in range(len(ans)): # a[ans[i]] = c[i] # a[lastind] = c[-1] # if notSame(a, b): # print("NO") # return print("YES") for i in ans: print(i + 1, end=" ") print(lastind + 1) return for _ in range(int(input())): # Multicase n, m = list(map(int, input().split())) a = list(map(int, input().split())) b = list(map(int, input().split())) c = list(map(int, input().split())) solve(n, m , a, b, c) # 6 22 22 22 22 22 22 7 22 22 22 22 22 22 22 10 22 22 22 17 26 22 22 22 22 22 22 22 22 22 # 6 22 22 22 22 22 22 7 22 22 22 22 22 22 22 10 22 22 22 17 26 22 22 22 22 22 22 22 5 22 ```
output
1
82,807
7
165,615
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You finally woke up after this crazy dream and decided to walk around to clear your head. Outside you saw your house's fence β€” so plain and boring, that you'd like to repaint it. <image> You have a fence consisting of n planks, where the i-th plank has the color a_i. You want to repaint the fence in such a way that the i-th plank has the color b_i. You've invited m painters for this purpose. The j-th painter will arrive at the moment j and will recolor exactly one plank to color c_j. For each painter you can choose which plank to recolor, but you can't turn them down, i. e. each painter has to color exactly one plank. Can you get the coloring b you want? If it's possible, print for each painter which plank he must paint. Input The first line contains one integer t (1 ≀ t ≀ 10^4) β€” the number of test cases. Then t test cases follow. The first line of each test case contains two integers n and m (1 ≀ n, m ≀ 10^5) β€” the number of planks in the fence and the number of painters. The second line of each test case contains n integers a_1, a_2, ..., a_n (1 ≀ a_i ≀ n) β€” the initial colors of the fence. The third line of each test case contains n integers b_1, b_2, ..., b_n (1 ≀ b_i ≀ n) β€” the desired colors of the fence. The fourth line of each test case contains m integers c_1, c_2, ..., c_m (1 ≀ c_j ≀ n) β€” the colors painters have. It's guaranteed that the sum of n doesn't exceed 10^5 and the sum of m doesn't exceed 10^5 over all test cases. Output For each test case, output "NO" if it is impossible to achieve the coloring b. Otherwise, print "YES" and m integers x_1, x_2, ..., x_m, where x_j is the index of plank the j-th painter should paint. You may print every letter in any case you want (so, for example, the strings "yEs", "yes", "Yes" and "YES" are all recognized as positive answer). Example Input 6 1 1 1 1 1 5 2 1 2 2 1 1 1 2 2 1 1 1 2 3 3 2 2 2 2 2 2 2 3 2 10 5 7 3 2 1 7 9 4 2 7 9 9 9 2 1 4 9 4 2 3 9 9 9 7 4 3 5 2 1 2 2 1 1 1 2 2 1 1 3 3 6 4 3 4 2 4 1 2 2 3 1 3 1 1 2 2 3 4 Output YES 1 YES 2 2 YES 1 1 1 YES 2 1 9 5 9 NO NO Submitted Solution: ``` from sys import stdin input=lambda : stdin.readline().strip() lin=lambda :list(map(int,input().split())) iin=lambda :int(input()) main=lambda :map(int,input().split()) from math import ceil,sqrt,factorial,log from collections import deque from bisect import bisect_left def gcd(a,b): a,b=max(a,b),min(a,b) while a%b!=0: a,b=b,a%b return b mod=998244353 def solve(we): n,m=main() a=lin() b=lin() c=lin() d={} not_change={} for i in range(n): if a[i]!=b[i]: if b[i] in d: d[b[i]].add(i) else: d[b[i]]=set() d[b[i]].add(i) else: not_change[b[i]]=i z={} for i in range(m): if c[i] not in z: z[c[i]]=set() z[c[i]].add(i) flag=1 ans=[-1 for i in range(m)] for i in d: if i in z and len(z[i])>=len(d[i]): x=list(d[i]) y=list(z[i]) if i not in not_change: not_change[i]=x[-1] j=0 for i in x: ans[y[j]]=i j+=1 j=j%m else: flag=0 break if flag: # print(ans) x=-1 for i in range(m-1,-1,-1): if ans[i]>=0: x=ans[i] else: if x>=0: ans[i]=x else: if c[i] in not_change: ans[i]=not_change[c[i]] x=ans[i] ans[i]+=1 if 0 in ans: print("NO") else: print("YES") print(*ans) else: print("NO") qwe=1 qwe=int(input()) for _ in range(qwe): solve(_+1) ```
instruction
0
82,808
7
165,616
Yes
output
1
82,808
7
165,617
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You finally woke up after this crazy dream and decided to walk around to clear your head. Outside you saw your house's fence β€” so plain and boring, that you'd like to repaint it. <image> You have a fence consisting of n planks, where the i-th plank has the color a_i. You want to repaint the fence in such a way that the i-th plank has the color b_i. You've invited m painters for this purpose. The j-th painter will arrive at the moment j and will recolor exactly one plank to color c_j. For each painter you can choose which plank to recolor, but you can't turn them down, i. e. each painter has to color exactly one plank. Can you get the coloring b you want? If it's possible, print for each painter which plank he must paint. Input The first line contains one integer t (1 ≀ t ≀ 10^4) β€” the number of test cases. Then t test cases follow. The first line of each test case contains two integers n and m (1 ≀ n, m ≀ 10^5) β€” the number of planks in the fence and the number of painters. The second line of each test case contains n integers a_1, a_2, ..., a_n (1 ≀ a_i ≀ n) β€” the initial colors of the fence. The third line of each test case contains n integers b_1, b_2, ..., b_n (1 ≀ b_i ≀ n) β€” the desired colors of the fence. The fourth line of each test case contains m integers c_1, c_2, ..., c_m (1 ≀ c_j ≀ n) β€” the colors painters have. It's guaranteed that the sum of n doesn't exceed 10^5 and the sum of m doesn't exceed 10^5 over all test cases. Output For each test case, output "NO" if it is impossible to achieve the coloring b. Otherwise, print "YES" and m integers x_1, x_2, ..., x_m, where x_j is the index of plank the j-th painter should paint. You may print every letter in any case you want (so, for example, the strings "yEs", "yes", "Yes" and "YES" are all recognized as positive answer). Example Input 6 1 1 1 1 1 5 2 1 2 2 1 1 1 2 2 1 1 1 2 3 3 2 2 2 2 2 2 2 3 2 10 5 7 3 2 1 7 9 4 2 7 9 9 9 2 1 4 9 4 2 3 9 9 9 7 4 3 5 2 1 2 2 1 1 1 2 2 1 1 3 3 6 4 3 4 2 4 1 2 2 3 1 3 1 1 2 2 3 4 Output YES 1 YES 2 2 YES 1 1 1 YES 2 1 9 5 9 NO NO Submitted Solution: ``` """ Author - Satwik Tiwari . 8th Jan , 2021 - Friday """ #=============================================================================================== #importing some useful libraries. from __future__ import division, print_function # from fractions import Fraction import sys import os from io import BytesIO, IOBase # from functools import cmp_to_key # from itertools import * from heapq import heappush,heappop from math import gcd, factorial,floor,ceil,sqrt,log2 # from copy import deepcopy # from collections import deque # # # from bisect import bisect_left as bl # from bisect import bisect_right as br # from bisect import bisect #============================================================================================== #fast I/O region 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") def print(*args, **kwargs): """Prints the values to a stream, or to sys.stdout by default.""" sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout) at_start = True for x in args: if not at_start: file.write(sep) file.write(str(x)) at_start = False file.write(kwargs.pop("end", "\n")) if kwargs.pop("flush", False): file.flush() if sys.version_info[0] < 3: sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout) else: sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) # inp = lambda: sys.stdin.readline().rstrip("\r\n") #=============================================================================================== ### START ITERATE RECURSION ### # from types import GeneratorType # def iterative(f, stack=[]): # def wrapped_func(*args, **kwargs): # if stack: return f(*args, **kwargs) # to = f(*args, **kwargs) # while True: # if type(to) is GeneratorType: # stack.append(to) # to = next(to) # continue # stack.pop() # if not stack: break # to = stack[-1].send(to) # return to # return wrapped_func #### END ITERATE RECURSION #### #=============================================================================================== #some shortcuts def inp(): return sys.stdin.readline().rstrip("\r\n") #for fast input def out(var): sys.stdout.write(str(var)) #for fast output, always take string def lis(): return list(map(int, inp().split())) def stringlis(): return list(map(str, inp().split())) def sep(): return map(int, inp().split()) def strsep(): return map(str, inp().split()) # def graph(vertex): return [[] for i in range(0,vertex+1)] def testcase(t): for pp in range(t): solve(pp) def google(p): print('Case #'+str(p)+': ',end='') def lcm(a,b): return (a*b)//gcd(a,b) def power(x, y, p) : y%=(p-1) #not so sure about this. used when y>p-1. if p is prime. res = 1 # Initialize result x = x % p # Update x if it is more , than or equal to p if (x == 0) : return 0 while (y > 0) : if ((y & 1) == 1) : # If y is odd, multiply, x with result res = (res * x) % p y = y >> 1 # y = y/2 x = (x * x) % p return res def ncr(n,r): return factorial(n) // (factorial(r) * factorial(max(n - r, 1))) def isPrime(n) : if (n <= 1) : return False if (n <= 3) : return True if (n % 2 == 0 or n % 3 == 0) : return False i = 5 while(i * i <= n) : if (n % i == 0 or n % (i + 2) == 0) : return False i = i + 6 return True inf = pow(10,20) mod = 10**9+7 #=============================================================================================== # code here ;)) def solve(case): n,m = sep() a = lis() b = lis() c = lis() if(a == b): if(c[-1] in b): print("YES") ans = [b.index(c[-1]) + 1]*m print(' '.join(str(i) for i in ans)) else: print('NO') return else: chng = {} for i in range(n): if(a[i] == b[i]): continue if(b[i] in chng): chng[b[i]] += 1 else: chng[b[i]] = 1 temp = chng.copy() for i in range(m): if(c[i] in chng and chng[c[i]] > 0): chng[c[i]]-=1 for i in chng: if(chng[i] > 0): print("NO") return diff = {} same = {} for i in range(n): if(a[i] == b[i]): if(b[i] not in same): same[b[i]] = [i] else: same[b[i]].append(i) else: if(b[i] not in diff): diff[b[i]] = [i] else: diff[b[i]].append(i) have = -1 ans = [-1]*m for i in range(m-1,-1,-1): if(c[i] in diff and len(diff[c[i]]) > 0): ans[i] = diff[c[i]].pop() have = ans[i] else: if(have == -1): if(c[i] in same): ans[i] = same[c[i]][0] have = ans[i] else: print('NO') return else: ans[i] = have print("YES") print(' '.join(str(i+1) for i in ans)) # testcase(1) testcase(int(inp())) ```
instruction
0
82,809
7
165,618
Yes
output
1
82,809
7
165,619
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You finally woke up after this crazy dream and decided to walk around to clear your head. Outside you saw your house's fence β€” so plain and boring, that you'd like to repaint it. <image> You have a fence consisting of n planks, where the i-th plank has the color a_i. You want to repaint the fence in such a way that the i-th plank has the color b_i. You've invited m painters for this purpose. The j-th painter will arrive at the moment j and will recolor exactly one plank to color c_j. For each painter you can choose which plank to recolor, but you can't turn them down, i. e. each painter has to color exactly one plank. Can you get the coloring b you want? If it's possible, print for each painter which plank he must paint. Input The first line contains one integer t (1 ≀ t ≀ 10^4) β€” the number of test cases. Then t test cases follow. The first line of each test case contains two integers n and m (1 ≀ n, m ≀ 10^5) β€” the number of planks in the fence and the number of painters. The second line of each test case contains n integers a_1, a_2, ..., a_n (1 ≀ a_i ≀ n) β€” the initial colors of the fence. The third line of each test case contains n integers b_1, b_2, ..., b_n (1 ≀ b_i ≀ n) β€” the desired colors of the fence. The fourth line of each test case contains m integers c_1, c_2, ..., c_m (1 ≀ c_j ≀ n) β€” the colors painters have. It's guaranteed that the sum of n doesn't exceed 10^5 and the sum of m doesn't exceed 10^5 over all test cases. Output For each test case, output "NO" if it is impossible to achieve the coloring b. Otherwise, print "YES" and m integers x_1, x_2, ..., x_m, where x_j is the index of plank the j-th painter should paint. You may print every letter in any case you want (so, for example, the strings "yEs", "yes", "Yes" and "YES" are all recognized as positive answer). Example Input 6 1 1 1 1 1 5 2 1 2 2 1 1 1 2 2 1 1 1 2 3 3 2 2 2 2 2 2 2 3 2 10 5 7 3 2 1 7 9 4 2 7 9 9 9 2 1 4 9 4 2 3 9 9 9 7 4 3 5 2 1 2 2 1 1 1 2 2 1 1 3 3 6 4 3 4 2 4 1 2 2 3 1 3 1 1 2 2 3 4 Output YES 1 YES 2 2 YES 1 1 1 YES 2 1 9 5 9 NO NO Submitted Solution: ``` import sys from collections import defaultdict def solve(n,m,a,b,c): free = -1 last = -1 for i in range(n): if b[i] == c[-1]: last = i+1 if b[i] != a[i]: free = i+1 if last == -1: print("NO"); return if free == -1: free = last q = defaultdict(list) for i in range(n): # add indices which needs to be painting if a[i]!=b[i] and i+1!=free: q[b[i]].append(i+1) ans = [] for i in range(m-1): if q[c[i]]: ans.append(q[c[i]].pop()) else: ans.append(free) for x in q: if q[x]: print("NO"); return ans.append(free) print("YES") print(*ans) return for nt in range(int(input())): n,m = map(int,input().split()) a = list(map(int,input().split())) b = list(map(int,input().split())) c = list(map(int,input().split())) solve(n,m,a,b,c) ```
instruction
0
82,810
7
165,620
Yes
output
1
82,810
7
165,621
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You finally woke up after this crazy dream and decided to walk around to clear your head. Outside you saw your house's fence β€” so plain and boring, that you'd like to repaint it. <image> You have a fence consisting of n planks, where the i-th plank has the color a_i. You want to repaint the fence in such a way that the i-th plank has the color b_i. You've invited m painters for this purpose. The j-th painter will arrive at the moment j and will recolor exactly one plank to color c_j. For each painter you can choose which plank to recolor, but you can't turn them down, i. e. each painter has to color exactly one plank. Can you get the coloring b you want? If it's possible, print for each painter which plank he must paint. Input The first line contains one integer t (1 ≀ t ≀ 10^4) β€” the number of test cases. Then t test cases follow. The first line of each test case contains two integers n and m (1 ≀ n, m ≀ 10^5) β€” the number of planks in the fence and the number of painters. The second line of each test case contains n integers a_1, a_2, ..., a_n (1 ≀ a_i ≀ n) β€” the initial colors of the fence. The third line of each test case contains n integers b_1, b_2, ..., b_n (1 ≀ b_i ≀ n) β€” the desired colors of the fence. The fourth line of each test case contains m integers c_1, c_2, ..., c_m (1 ≀ c_j ≀ n) β€” the colors painters have. It's guaranteed that the sum of n doesn't exceed 10^5 and the sum of m doesn't exceed 10^5 over all test cases. Output For each test case, output "NO" if it is impossible to achieve the coloring b. Otherwise, print "YES" and m integers x_1, x_2, ..., x_m, where x_j is the index of plank the j-th painter should paint. You may print every letter in any case you want (so, for example, the strings "yEs", "yes", "Yes" and "YES" are all recognized as positive answer). Example Input 6 1 1 1 1 1 5 2 1 2 2 1 1 1 2 2 1 1 1 2 3 3 2 2 2 2 2 2 2 3 2 10 5 7 3 2 1 7 9 4 2 7 9 9 9 2 1 4 9 4 2 3 9 9 9 7 4 3 5 2 1 2 2 1 1 1 2 2 1 1 3 3 6 4 3 4 2 4 1 2 2 3 1 3 1 1 2 2 3 4 Output YES 1 YES 2 2 YES 1 1 1 YES 2 1 9 5 9 NO NO Submitted Solution: ``` t = int(input()) for test in range(t): n, m = map(int, input().split()) need = [0] * n check = [0] * n a = list(map(int, input().split())) b = list(map(int, input().split())) c = list(map(int, input().split())) d = dict() for i in range(n): if a[i] != b[i]: if b[i] not in d: d[b[i]] = [i + 1] else: d[b[i]].append(i + 1) need[b[i] - 1] += 1 check[b[i] - 1] += 1 have = [0] * n for i in range(m): have[c[i] - 1] += 1 flag = True for i in range(n): flag = flag and need[i] <= have[i] if not flag: print("NO") continue if not check[c[-1] - 1]: print("NO") else: print("YES") trash = c[-1] if trash not in d: trash = b.index(trash) + 1 else: trash = d[trash][0] for i in range(m): if i == m - 1: print(trash) break if need[c[i] - 1]: need[c[i] - 1] -= 1 print(d[c[i]][-1], end=' ') d[c[i]].pop() else: print(trash, end=' ') ```
instruction
0
82,811
7
165,622
Yes
output
1
82,811
7
165,623
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You finally woke up after this crazy dream and decided to walk around to clear your head. Outside you saw your house's fence β€” so plain and boring, that you'd like to repaint it. <image> You have a fence consisting of n planks, where the i-th plank has the color a_i. You want to repaint the fence in such a way that the i-th plank has the color b_i. You've invited m painters for this purpose. The j-th painter will arrive at the moment j and will recolor exactly one plank to color c_j. For each painter you can choose which plank to recolor, but you can't turn them down, i. e. each painter has to color exactly one plank. Can you get the coloring b you want? If it's possible, print for each painter which plank he must paint. Input The first line contains one integer t (1 ≀ t ≀ 10^4) β€” the number of test cases. Then t test cases follow. The first line of each test case contains two integers n and m (1 ≀ n, m ≀ 10^5) β€” the number of planks in the fence and the number of painters. The second line of each test case contains n integers a_1, a_2, ..., a_n (1 ≀ a_i ≀ n) β€” the initial colors of the fence. The third line of each test case contains n integers b_1, b_2, ..., b_n (1 ≀ b_i ≀ n) β€” the desired colors of the fence. The fourth line of each test case contains m integers c_1, c_2, ..., c_m (1 ≀ c_j ≀ n) β€” the colors painters have. It's guaranteed that the sum of n doesn't exceed 10^5 and the sum of m doesn't exceed 10^5 over all test cases. Output For each test case, output "NO" if it is impossible to achieve the coloring b. Otherwise, print "YES" and m integers x_1, x_2, ..., x_m, where x_j is the index of plank the j-th painter should paint. You may print every letter in any case you want (so, for example, the strings "yEs", "yes", "Yes" and "YES" are all recognized as positive answer). Example Input 6 1 1 1 1 1 5 2 1 2 2 1 1 1 2 2 1 1 1 2 3 3 2 2 2 2 2 2 2 3 2 10 5 7 3 2 1 7 9 4 2 7 9 9 9 2 1 4 9 4 2 3 9 9 9 7 4 3 5 2 1 2 2 1 1 1 2 2 1 1 3 3 6 4 3 4 2 4 1 2 2 3 1 3 1 1 2 2 3 4 Output YES 1 YES 2 2 YES 1 1 1 YES 2 1 9 5 9 NO NO Submitted Solution: ``` def solve(initial,final,painters,n,m,ans): diff_color = {} painters_colors_counts = {} for i in range(n): if initial[i] != final[i]: if final[i] not in diff_color.keys(): diff_color[final[i]] = [] diff_color[final[i]].append(i) for i in range(m): if painters[i] not in painters_colors_counts.keys(): painters_colors_counts[painters[i]] = 0 painters_colors_counts[painters[i]] += 1 if painters[-1] not in final: ans.append('NO') return for i in diff_color.keys(): if i not in painters_colors_counts.keys(): ans.append('NO') return if painters_colors_counts[i] < len(diff_color[i]): ans.append('NO') return bully_index = final.index(painters[-1]) #print(m,painters) order = [] for i in range(m): if painters[i] in diff_color.keys(): index = diff_color[painters[i]].pop() order.append(str(1+index)) painters_colors_counts[painters[i]] -= 1 if not diff_color[painters[i]]: del diff_color[painters[i]] else: index = bully_index order.append(str(1+index)) initial[index] = painters[i] if initial != final: ans.append('NO') return ans.append('YES') ans.append(' '.join(order)) def main(): t = int(input()) ans = [] for i in range(t): n,m = map(int,input().split()) initial = list(map(int,input().split())) final = list(map(int,input().split())) painters = list(map(int,input().split())) solve(initial,final,painters,n,m,ans) print('\n'.join(ans)) main() ```
instruction
0
82,812
7
165,624
No
output
1
82,812
7
165,625
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You finally woke up after this crazy dream and decided to walk around to clear your head. Outside you saw your house's fence β€” so plain and boring, that you'd like to repaint it. <image> You have a fence consisting of n planks, where the i-th plank has the color a_i. You want to repaint the fence in such a way that the i-th plank has the color b_i. You've invited m painters for this purpose. The j-th painter will arrive at the moment j and will recolor exactly one plank to color c_j. For each painter you can choose which plank to recolor, but you can't turn them down, i. e. each painter has to color exactly one plank. Can you get the coloring b you want? If it's possible, print for each painter which plank he must paint. Input The first line contains one integer t (1 ≀ t ≀ 10^4) β€” the number of test cases. Then t test cases follow. The first line of each test case contains two integers n and m (1 ≀ n, m ≀ 10^5) β€” the number of planks in the fence and the number of painters. The second line of each test case contains n integers a_1, a_2, ..., a_n (1 ≀ a_i ≀ n) β€” the initial colors of the fence. The third line of each test case contains n integers b_1, b_2, ..., b_n (1 ≀ b_i ≀ n) β€” the desired colors of the fence. The fourth line of each test case contains m integers c_1, c_2, ..., c_m (1 ≀ c_j ≀ n) β€” the colors painters have. It's guaranteed that the sum of n doesn't exceed 10^5 and the sum of m doesn't exceed 10^5 over all test cases. Output For each test case, output "NO" if it is impossible to achieve the coloring b. Otherwise, print "YES" and m integers x_1, x_2, ..., x_m, where x_j is the index of plank the j-th painter should paint. You may print every letter in any case you want (so, for example, the strings "yEs", "yes", "Yes" and "YES" are all recognized as positive answer). Example Input 6 1 1 1 1 1 5 2 1 2 2 1 1 1 2 2 1 1 1 2 3 3 2 2 2 2 2 2 2 3 2 10 5 7 3 2 1 7 9 4 2 7 9 9 9 2 1 4 9 4 2 3 9 9 9 7 4 3 5 2 1 2 2 1 1 1 2 2 1 1 3 3 6 4 3 4 2 4 1 2 2 3 1 3 1 1 2 2 3 4 Output YES 1 YES 2 2 YES 1 1 1 YES 2 1 9 5 9 NO NO Submitted Solution: ``` def arrIn(): return list(map(int, input().split())) def mapIn(): return map(int, input().split()) for test in range(int(input())): n, m = mapIn() a = arrIn() b = arrIn() c = arrIn() maxi = max(max(a), max(b)) + 1 d = {} check = {} for i in range(n): if a[i] != b[i]: if d.get(b[i]) == None: d[b[i]] = [i] else: d[b[i]].append(i) check[b[i]] = i flag1 = False flag = True s = "" for i in range(m - 1, -1, -1): x = d.get(c[i]) if x == None and flag1 == False: if check.get(c[i]) != None: s += str(check[c[i]] + 1) + " " index = check[c[i]] + 1 flag1 = True else: flag = False break elif x != None and len(x) != 0: y = x.pop()+1 s += str(y) + " " if flag1 == False: index = y flag1 = True else: s += str(index) + " " if flag == True: print("YES") ans="" x="" y="" for i in range(len(s)-1,-1,-1): if s[i]==" ": ans+=y[::-1]+" " y="" else: y+=s[i] ans+=y[::-1] print(ans[1:]) else: print("NO") ```
instruction
0
82,813
7
165,626
No
output
1
82,813
7
165,627
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You finally woke up after this crazy dream and decided to walk around to clear your head. Outside you saw your house's fence β€” so plain and boring, that you'd like to repaint it. <image> You have a fence consisting of n planks, where the i-th plank has the color a_i. You want to repaint the fence in such a way that the i-th plank has the color b_i. You've invited m painters for this purpose. The j-th painter will arrive at the moment j and will recolor exactly one plank to color c_j. For each painter you can choose which plank to recolor, but you can't turn them down, i. e. each painter has to color exactly one plank. Can you get the coloring b you want? If it's possible, print for each painter which plank he must paint. Input The first line contains one integer t (1 ≀ t ≀ 10^4) β€” the number of test cases. Then t test cases follow. The first line of each test case contains two integers n and m (1 ≀ n, m ≀ 10^5) β€” the number of planks in the fence and the number of painters. The second line of each test case contains n integers a_1, a_2, ..., a_n (1 ≀ a_i ≀ n) β€” the initial colors of the fence. The third line of each test case contains n integers b_1, b_2, ..., b_n (1 ≀ b_i ≀ n) β€” the desired colors of the fence. The fourth line of each test case contains m integers c_1, c_2, ..., c_m (1 ≀ c_j ≀ n) β€” the colors painters have. It's guaranteed that the sum of n doesn't exceed 10^5 and the sum of m doesn't exceed 10^5 over all test cases. Output For each test case, output "NO" if it is impossible to achieve the coloring b. Otherwise, print "YES" and m integers x_1, x_2, ..., x_m, where x_j is the index of plank the j-th painter should paint. You may print every letter in any case you want (so, for example, the strings "yEs", "yes", "Yes" and "YES" are all recognized as positive answer). Example Input 6 1 1 1 1 1 5 2 1 2 2 1 1 1 2 2 1 1 1 2 3 3 2 2 2 2 2 2 2 3 2 10 5 7 3 2 1 7 9 4 2 7 9 9 9 2 1 4 9 4 2 3 9 9 9 7 4 3 5 2 1 2 2 1 1 1 2 2 1 1 3 3 6 4 3 4 2 4 1 2 2 3 1 3 1 1 2 2 3 4 Output YES 1 YES 2 2 YES 1 1 1 YES 2 1 9 5 9 NO NO Submitted Solution: ``` from sys import stdin,stdout from collections import defaultdict nmbr = lambda: int(stdin.readline()) lst = lambda: list(map(int,stdin.readline().split())) def check(ans): for i in range(k): a[ans[i]-1]=c[i] return a==b for _ in range(nmbr()): n,k=lst() a=lst() f=1 b=lst() ans=[] c=lst() eq={} mp=defaultdict(list) ln={} for i in range(n): if a[i]==b[i]: eq[a[i]]=i else: mp[b[i]]+=[i] ln[b[i]]=ln.get(b[i],0)+1 for i in range(k): v=c[i] sz=ln.get(v,0) if sz>0: ans+=[mp[v][sz-1]+1] eq[v]=mp[v][sz-1] ln[v]-=1 else: if v in eq: ans+=[eq[v]+1] else: ans+=[-1] for i in range(k-1,0,-1): if ans[i-1]==-1: ans[i-1]=ans[i] if ans[-1]!=-1: print('YES') print(*ans) else: print('NO') ```
instruction
0
82,814
7
165,628
No
output
1
82,814
7
165,629
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You finally woke up after this crazy dream and decided to walk around to clear your head. Outside you saw your house's fence β€” so plain and boring, that you'd like to repaint it. <image> You have a fence consisting of n planks, where the i-th plank has the color a_i. You want to repaint the fence in such a way that the i-th plank has the color b_i. You've invited m painters for this purpose. The j-th painter will arrive at the moment j and will recolor exactly one plank to color c_j. For each painter you can choose which plank to recolor, but you can't turn them down, i. e. each painter has to color exactly one plank. Can you get the coloring b you want? If it's possible, print for each painter which plank he must paint. Input The first line contains one integer t (1 ≀ t ≀ 10^4) β€” the number of test cases. Then t test cases follow. The first line of each test case contains two integers n and m (1 ≀ n, m ≀ 10^5) β€” the number of planks in the fence and the number of painters. The second line of each test case contains n integers a_1, a_2, ..., a_n (1 ≀ a_i ≀ n) β€” the initial colors of the fence. The third line of each test case contains n integers b_1, b_2, ..., b_n (1 ≀ b_i ≀ n) β€” the desired colors of the fence. The fourth line of each test case contains m integers c_1, c_2, ..., c_m (1 ≀ c_j ≀ n) β€” the colors painters have. It's guaranteed that the sum of n doesn't exceed 10^5 and the sum of m doesn't exceed 10^5 over all test cases. Output For each test case, output "NO" if it is impossible to achieve the coloring b. Otherwise, print "YES" and m integers x_1, x_2, ..., x_m, where x_j is the index of plank the j-th painter should paint. You may print every letter in any case you want (so, for example, the strings "yEs", "yes", "Yes" and "YES" are all recognized as positive answer). Example Input 6 1 1 1 1 1 5 2 1 2 2 1 1 1 2 2 1 1 1 2 3 3 2 2 2 2 2 2 2 3 2 10 5 7 3 2 1 7 9 4 2 7 9 9 9 2 1 4 9 4 2 3 9 9 9 7 4 3 5 2 1 2 2 1 1 1 2 2 1 1 3 3 6 4 3 4 2 4 1 2 2 3 1 3 1 1 2 2 3 4 Output YES 1 YES 2 2 YES 1 1 1 YES 2 1 9 5 9 NO NO Submitted Solution: ``` def solve(): n, m = input_as_list() a = input_as_list(-1) b = input_as_list(-1) c = input_as_list(-1) must = [[] for _ in range(n)] any = [None] * n for i in range(n): if a[i] != b[i]: must[b[i]].append(i) any[b[i]] = i goto = [0] * m last = c[-1] if must[last]: trash = goto[-1] = must[last].pop() elif any[last] is not None: trash = goto[-1] = any[last] else: print("NO") return for i in range(m-1): if must[c[i]]: goto[i] = must[c[i]].pop() else: goto[i] = trash print("YES") print(*[x+1 for x in goto]) def input_as_list(offset=0): return [int(t)+offset for t in input().split()] for _ in range(int(input())): solve() ```
instruction
0
82,815
7
165,630
No
output
1
82,815
7
165,631
Provide tags and a correct Python 3 solution for this coding contest problem. During the breaks between competitions, top-model Izabella tries to develop herself and not to be bored. For example, now she tries to solve Rubik's cube 2x2x2. It's too hard to learn to solve Rubik's cube instantly, so she learns to understand if it's possible to solve the cube in some state using 90-degrees rotation of one face of the cube in any direction. To check her answers she wants to use a program which will for some state of cube tell if it's possible to solve it using one rotation, described above. Cube is called solved if for each face of cube all squares on it has the same color. https://en.wikipedia.org/wiki/Rubik's_Cube Input In first line given a sequence of 24 integers ai (1 ≀ ai ≀ 6), where ai denotes color of i-th square. There are exactly 4 occurrences of all colors in this sequence. Output Print Β«YESΒ» (without quotes) if it's possible to solve cube using one rotation and Β«NOΒ» (without quotes) otherwise. Examples Input 2 5 4 6 1 3 6 2 5 5 1 2 3 5 3 1 1 2 4 6 6 4 3 4 Output NO Input 5 3 5 3 2 5 2 5 6 2 6 2 4 4 4 4 1 1 1 1 6 3 6 3 Output YES Note In first test case cube looks like this: <image> In second test case cube looks like this: <image> It's possible to solve cube by rotating face with squares with numbers 13, 14, 15, 16.
instruction
0
83,091
7
166,182
Tags: brute force, implementation Correct Solution: ``` import sys rotations = [[1, 3, 5, 7, 9, 11, 22, 24], [2, 4, 6, 8, 10, 12, 21, 23], [13, 14, 5, 6, 17, 18, 21, 22], [15, 16, 7, 8, 19, 20, 23, 24], [3, 4, 17, 19, 10, 9, 16, 14], [1, 2, 18, 20, 12, 11, 15, 13]] # r1 shift left def rotation_backwards(cube: list, rotation: list): aux = cube.copy() aux_1, aux_2 = aux[rotation[len(rotation) - 1] - 1], aux[rotation[len(rotation) - 2] - 1] for index in range(len(rotation) - 1, -1, -1): aux[rotation[index] - 1] = aux[rotation[(index - 2) % len(rotation)] - 1] aux[rotation[0] - 1], aux[rotation[1] - 1] = aux_1, aux_2 return aux # r1 shift right def rotation_forwards(cube: list, rotation: list): aux = cube.copy() aux_1, aux_2 = aux[rotation[0] - 1], aux[rotation[1] - 1] for index in range(len(rotation)): aux[rotation[index] - 1] = aux[rotation[(index + 2) % len(rotation)] - 1] aux[rotation[len(rotation) - 1] - 1], aux[rotation[len(rotation) - 1] - 1] = aux_1, aux_2 return aux def verify(cube: list): equals = 0 for i in range(0, len(cube), 4): if cube[i] == cube[i + 1] and cube[i] == cube[i + 2] and cube[i] == cube[i + 3]: equals += 1 else: break if equals == 6: print('YES') sys.exit(0) the_cube = list(map(int, input().split(' '))) for r in rotations: verify(rotation_backwards(the_cube, r)) verify(rotation_forwards(the_cube, r)) print('NO') ```
output
1
83,091
7
166,183
Provide tags and a correct Python 3 solution for this coding contest problem. During the breaks between competitions, top-model Izabella tries to develop herself and not to be bored. For example, now she tries to solve Rubik's cube 2x2x2. It's too hard to learn to solve Rubik's cube instantly, so she learns to understand if it's possible to solve the cube in some state using 90-degrees rotation of one face of the cube in any direction. To check her answers she wants to use a program which will for some state of cube tell if it's possible to solve it using one rotation, described above. Cube is called solved if for each face of cube all squares on it has the same color. https://en.wikipedia.org/wiki/Rubik's_Cube Input In first line given a sequence of 24 integers ai (1 ≀ ai ≀ 6), where ai denotes color of i-th square. There are exactly 4 occurrences of all colors in this sequence. Output Print Β«YESΒ» (without quotes) if it's possible to solve cube using one rotation and Β«NOΒ» (without quotes) otherwise. Examples Input 2 5 4 6 1 3 6 2 5 5 1 2 3 5 3 1 1 2 4 6 6 4 3 4 Output NO Input 5 3 5 3 2 5 2 5 6 2 6 2 4 4 4 4 1 1 1 1 6 3 6 3 Output YES Note In first test case cube looks like this: <image> In second test case cube looks like this: <image> It's possible to solve cube by rotating face with squares with numbers 13, 14, 15, 16.
instruction
0
83,092
7
166,184
Tags: brute force, implementation Correct Solution: ``` a = [ [1,3,5,7,9,11,24,22], [2,4,6,8,10,12,23,21], [13,14,5,6,17,18,21,22], [15,16,7,8,19,20,23,24], [2,1,13,15,11,12,20,18], [4,3,14,16,9,10,19,17] ] cube = [0]+list(map(int, input().split())) def rubik(cube): if cube[1]==cube[2]==cube[3]==cube[4] and cube[5]==cube[6]==cube[7]==cube[8] and cube[9]==cube[10]==cube[11]==cube[12] and cube[13]==cube[14]==cube[15]==cube[16] and cube[17]==cube[18]==cube[19]==cube[20] and cube[21]==cube[22]==cube[23]==cube[24]: return True else: return False for row in a: b = cube[:] for i in range(8): b[row[i]]=cube[row[(i+2)%8]] if rubik(b): print('YES') break b = cube[:] for i in range(8): b[row[i]]=cube[row[(8+i-2)%8]] if rubik(b): print('YES') break else: print('NO') ```
output
1
83,092
7
166,185
Provide tags and a correct Python 3 solution for this coding contest problem. During the breaks between competitions, top-model Izabella tries to develop herself and not to be bored. For example, now she tries to solve Rubik's cube 2x2x2. It's too hard to learn to solve Rubik's cube instantly, so she learns to understand if it's possible to solve the cube in some state using 90-degrees rotation of one face of the cube in any direction. To check her answers she wants to use a program which will for some state of cube tell if it's possible to solve it using one rotation, described above. Cube is called solved if for each face of cube all squares on it has the same color. https://en.wikipedia.org/wiki/Rubik's_Cube Input In first line given a sequence of 24 integers ai (1 ≀ ai ≀ 6), where ai denotes color of i-th square. There are exactly 4 occurrences of all colors in this sequence. Output Print Β«YESΒ» (without quotes) if it's possible to solve cube using one rotation and Β«NOΒ» (without quotes) otherwise. Examples Input 2 5 4 6 1 3 6 2 5 5 1 2 3 5 3 1 1 2 4 6 6 4 3 4 Output NO Input 5 3 5 3 2 5 2 5 6 2 6 2 4 4 4 4 1 1 1 1 6 3 6 3 Output YES Note In first test case cube looks like this: <image> In second test case cube looks like this: <image> It's possible to solve cube by rotating face with squares with numbers 13, 14, 15, 16.
instruction
0
83,093
7
166,186
Tags: brute force, implementation Correct Solution: ``` from sys import stdin s=list(map(int,stdin.readline().strip().split())) l1=[s[0],s[2],s[4],s[6],s[8],s[10],s[-3],s[-1]] l2=[s[1],s[3],s[5],s[7],s[9],s[11],s[-4],s[-2]] l3=[ s[12],s[13],s[4],s[5],s[16],s[17],s[20],s[21]] l4=[s[14],s[15],s[6],s[7],s[18],s[19],s[22],s[23]] l5=[s[0],s[1],s[17],s[19],s[11],s[10],s[14],s[12]] l6=[s[2],s[3],s[16],s[18],s[9],s[8],s[15],s[13]] t1=True t12=True t2=False t32=True t3=True t4=False t5=True t52=True t6=False for i in range(2,8+2): if l1[i%8]!=l2[i-2]: t1=False for i in range(6,8+6): if l1[i%8]!=l2[i-6]: t12=False if l3[0]==l4[0] and l3[1]==l4[1] and l3[0]==l3[1] and l3[4]==l4[4] and l3[5]==l4[5] and l3[4]==l3[5]: t2=True for i in range(2,8+2): if l3[i%8]!=l4[i-2]: t3=False for i in range(6,8+6): if l3[i%8]!=l4[i-6]: t32=False if l1[0]==l2[0] and l1[1]==l2[1] and l1[0]==l1[1] and l1[4]==l2[4] and l1[5]==l2[5] and l1[4]==l1[5]: t4=True for i in range(2,8+2): if l5[i%8]!=l6[i-2]: t5=False for i in range(6,8+6): if l5[i%8]!=l6[i-6]: t52=False if l1[2]==l2[2] and l1[3]==l2[3] and l1[2]==l1[3] and l1[6]==l2[6] and l1[7]==l2[7] and l1[6]==l1[7]: t6=True t3=t3 or t32 t1=t1 or t12 t5=t5 or t52 if ( t1 and t2 ) or (t3 and t4) or( t5 and t6): print("YES") else: print("NO") ```
output
1
83,093
7
166,187
Provide tags and a correct Python 3 solution for this coding contest problem. During the breaks between competitions, top-model Izabella tries to develop herself and not to be bored. For example, now she tries to solve Rubik's cube 2x2x2. It's too hard to learn to solve Rubik's cube instantly, so she learns to understand if it's possible to solve the cube in some state using 90-degrees rotation of one face of the cube in any direction. To check her answers she wants to use a program which will for some state of cube tell if it's possible to solve it using one rotation, described above. Cube is called solved if for each face of cube all squares on it has the same color. https://en.wikipedia.org/wiki/Rubik's_Cube Input In first line given a sequence of 24 integers ai (1 ≀ ai ≀ 6), where ai denotes color of i-th square. There are exactly 4 occurrences of all colors in this sequence. Output Print Β«YESΒ» (without quotes) if it's possible to solve cube using one rotation and Β«NOΒ» (without quotes) otherwise. Examples Input 2 5 4 6 1 3 6 2 5 5 1 2 3 5 3 1 1 2 4 6 6 4 3 4 Output NO Input 5 3 5 3 2 5 2 5 6 2 6 2 4 4 4 4 1 1 1 1 6 3 6 3 Output YES Note In first test case cube looks like this: <image> In second test case cube looks like this: <image> It's possible to solve cube by rotating face with squares with numbers 13, 14, 15, 16.
instruction
0
83,094
7
166,188
Tags: brute force, implementation Correct Solution: ``` def xd(a,b,c,d): global s if(s[a-1]==s[b-1] and s[b-1]==s[c-1] and s[c-1]==s[d-1]): return 1 else: return 0 s=list(map(int,input().split())) pd=0 if(xd(13,14,15,16) and xd(17,18,19,20) and xd(1,3,6,8) and xd(5,7,10,12) and xd(9,11,21,23) and xd(2,4,22,24)): pd=1 if(xd(13,14,15,16) and xd(17,18,19,20) and xd(1,3,21,23) and xd(5,7,2,4) and xd(9,11,6,8) and xd(22,24,10,12)): pd=1 if(xd(1,2,3,4) and xd(9,10,11,12) and xd(5,6,19,20) and xd(17,18,23,24) and xd(21,22,15,16) and xd(13,14,7,8)): pd=1 if(xd(1,2,3,4) and xd(9,10,11,12) and xd(5,6,15,16) and xd(17,18,7,8) and xd(21,22,19,20) and xd(13,14,23,24)): pd=1 if(xd(5,6,7,8) and xd(21,22,23,24) and xd(3,4,13,15) and xd(14,16,11,12) and xd(9,10,18,20) and xd(17,19,1,2)): pd=1 if(xd(5,6,7,8) and xd(21,22,23,24) and xd(3,4,18,20) and xd(14,16,1,2) and xd(9,10,13,15) and xd(17,19,11,12)): pd=1 if(pd==1): print("YES") else: print("NO") ```
output
1
83,094
7
166,189
Provide tags and a correct Python 3 solution for this coding contest problem. During the breaks between competitions, top-model Izabella tries to develop herself and not to be bored. For example, now she tries to solve Rubik's cube 2x2x2. It's too hard to learn to solve Rubik's cube instantly, so she learns to understand if it's possible to solve the cube in some state using 90-degrees rotation of one face of the cube in any direction. To check her answers she wants to use a program which will for some state of cube tell if it's possible to solve it using one rotation, described above. Cube is called solved if for each face of cube all squares on it has the same color. https://en.wikipedia.org/wiki/Rubik's_Cube Input In first line given a sequence of 24 integers ai (1 ≀ ai ≀ 6), where ai denotes color of i-th square. There are exactly 4 occurrences of all colors in this sequence. Output Print Β«YESΒ» (without quotes) if it's possible to solve cube using one rotation and Β«NOΒ» (without quotes) otherwise. Examples Input 2 5 4 6 1 3 6 2 5 5 1 2 3 5 3 1 1 2 4 6 6 4 3 4 Output NO Input 5 3 5 3 2 5 2 5 6 2 6 2 4 4 4 4 1 1 1 1 6 3 6 3 Output YES Note In first test case cube looks like this: <image> In second test case cube looks like this: <image> It's possible to solve cube by rotating face with squares with numbers 13, 14, 15, 16.
instruction
0
83,095
7
166,190
Tags: brute force, implementation Correct Solution: ``` q = list(map(int,input().split())) a=[0] for i in q: a.append(i) if a[1]==a[3]==a[6]==a[8] and a[2]==a[4]==a[22]==a[24] and a[5]==a[7]==a[10]==a[12] and a[9]==a[11]==a[21]==a[23] and a[13]==a[14]==a[15]==a[16]: print('YES') exit(0) if a[1]==a[3]==a[21]==a[23] and a[22]==a[24]==a[10]==a[12] and a[5]==a[7]==a[2]==a[4] and a[9]==a[11]==a[6]==a[8] and a[13]==a[14]==a[15]==a[16]: print('YES') exit(0) if a[1]==a[2]==a[3]==a[4] and a[13]==a[14]==a[7]==a[8] and a[5]==a[6]==a[19]==a[20] and a[17]==a[18]==a[23]==a[24] and a[21]==a[22]==a[15]==a[16]: print('YES') exit(0) if a[1]==a[2]==a[3]==a[4] and a[13]==a[14]==a[23]==a[24] and a[5]==a[6]==a[15]==a[16] and a[17]==a[18]==a[7]==a[8] and a[21]==a[22]==a[19]==a[20]: print('YES') exit(0) if a[5]==a[6]==a[7]==a[8] and a[3]==a[4]==a[18]==a[20] and a[17]==a[19]==a[11]==a[12] and a[9]==a[10]==a[13]==a[15] and a[14]==a[16]==a[1]==a[2]: print('YES') exit(0) if a[5]==a[6]==a[7]==a[8] and a[3]==a[4]==a[13]==a[15] and a[17]==a[19]==a[1]==a[2] and a[9]==a[10]==a[18]==a[20] and a[14]==a[16]==a[11]==a[12]: print('YES') exit(0) print('NO') ```
output
1
83,095
7
166,191
Provide tags and a correct Python 3 solution for this coding contest problem. During the breaks between competitions, top-model Izabella tries to develop herself and not to be bored. For example, now she tries to solve Rubik's cube 2x2x2. It's too hard to learn to solve Rubik's cube instantly, so she learns to understand if it's possible to solve the cube in some state using 90-degrees rotation of one face of the cube in any direction. To check her answers she wants to use a program which will for some state of cube tell if it's possible to solve it using one rotation, described above. Cube is called solved if for each face of cube all squares on it has the same color. https://en.wikipedia.org/wiki/Rubik's_Cube Input In first line given a sequence of 24 integers ai (1 ≀ ai ≀ 6), where ai denotes color of i-th square. There are exactly 4 occurrences of all colors in this sequence. Output Print Β«YESΒ» (without quotes) if it's possible to solve cube using one rotation and Β«NOΒ» (without quotes) otherwise. Examples Input 2 5 4 6 1 3 6 2 5 5 1 2 3 5 3 1 1 2 4 6 6 4 3 4 Output NO Input 5 3 5 3 2 5 2 5 6 2 6 2 4 4 4 4 1 1 1 1 6 3 6 3 Output YES Note In first test case cube looks like this: <image> In second test case cube looks like this: <image> It's possible to solve cube by rotating face with squares with numbers 13, 14, 15, 16.
instruction
0
83,096
7
166,192
Tags: brute force, implementation Correct Solution: ``` l = [0] + [int(i) for i in input().split(" ")] if l[13] == l[14] == l[15] == l[16] and \ l[17] == l[18] == l[19] == l[20]: if l[5] == l[7] == l[10] == l[12] and \ l[9] == l[11] == l[21] == l[23] and \ l[1] == l[3] == l[6] == l[8] and \ l[2] == l[4] == l[22] == l[24]: print('YES') exit(0) if l[5] == l[7] == l[2] == l[4] and \ l[9] == l[11] == l[6] == l[8] and \ l[1] == l[3] == l[21] == l[23] and \ l[10] == l[12] == l[22] == l[24]: print('YES') exit(0) if l[1] == l[2] == l[3] == l[4] and \ l[9] == l[10] == l[11] == l[12]: if l[5] == l[6] == l[19] == l[20] and \ l[17] == l[18] == l[23] == l[24] and \ l[21] == l[22] == l[15] == l[16] and \ l[13] == l[14] == l[7] == l[8]: print('YES') exit(0) if l[5] == l[6] == l[15] == l[16] and \ l[13] == l[14] == l[23] == l[24] and \ l[21] == l[22] == l[19] == l[20] and \ l[17] == l[18] == l[7] == l[8]: print('YES') exit(0) if l[5] == l[6] == l[7] == l[8] and \ l[21] == l[22] == l[23] == l[24]: if l[3] == l[4] == l[18] == l[20] and \ l[17] == l[19] == l[11] == l[12] and \ l[9] == l[10] == l[13] == l[15] and \ l[14] == l[16] == l[1] == l[2]: print('YES') exit(0) if l[3] == l[4] == l[13] == l[15] and \ l[14] == l[16] == l[11] == l[12] and \ l[9] == l[10] == l[18] == l[20] and \ l[17] == l[19] == l[1] == l[2]: print('YES') exit(0) print('NO') ```
output
1
83,096
7
166,193
Provide tags and a correct Python 3 solution for this coding contest problem. During the breaks between competitions, top-model Izabella tries to develop herself and not to be bored. For example, now she tries to solve Rubik's cube 2x2x2. It's too hard to learn to solve Rubik's cube instantly, so she learns to understand if it's possible to solve the cube in some state using 90-degrees rotation of one face of the cube in any direction. To check her answers she wants to use a program which will for some state of cube tell if it's possible to solve it using one rotation, described above. Cube is called solved if for each face of cube all squares on it has the same color. https://en.wikipedia.org/wiki/Rubik's_Cube Input In first line given a sequence of 24 integers ai (1 ≀ ai ≀ 6), where ai denotes color of i-th square. There are exactly 4 occurrences of all colors in this sequence. Output Print Β«YESΒ» (without quotes) if it's possible to solve cube using one rotation and Β«NOΒ» (without quotes) otherwise. Examples Input 2 5 4 6 1 3 6 2 5 5 1 2 3 5 3 1 1 2 4 6 6 4 3 4 Output NO Input 5 3 5 3 2 5 2 5 6 2 6 2 4 4 4 4 1 1 1 1 6 3 6 3 Output YES Note In first test case cube looks like this: <image> In second test case cube looks like this: <image> It's possible to solve cube by rotating face with squares with numbers 13, 14, 15, 16.
instruction
0
83,097
7
166,194
Tags: brute force, implementation Correct Solution: ``` a = input().split(' ') b = 0 if a[0] == a[1] == a[2] == a[3] and a[8] == a[9] == a[10] == a[11]: if a[12] == a[13] == a[6] == a[7] and a[4] == a[5] == a[18] == a[19] and a[16] == a[17] == a[22] == a[23] and a[20] == a[21] == a[14] == a[15]: print('YES') elif a[12] == a[13] == a[22] == a[23] and a[20] == a[21] == a[18] == a[19] and a[16] == a[17] == a[6] == a[7] and a[4] == a[5] == a[14] == a[15]: print('YES') else: b = b + 1 elif a[4] == a[5] == a[6] == a[7] and a[20] == a[21] == a[22] == a[23]: if a[16] == a[18] == a[0] == a[1] and a[2] == a[3] == a[12] == a[14] and a[13] == a[15] == a[10] == a[11] and a[8] == a[9] == a[17] == a[19]: print('YES') elif a[16] == a[18] == a[10] == a[11] and a[8] == a[9] == a[12] == a[14] and a[13] == a[15] == a[0] == a[1] and a[2] == a[3] == a[17] == a[19]: print('YES') else: b = b + 1 elif a[12] == a[13] == a[14] == a[15] and a[16] == a[17] == a[18] == a[19]: if a[5] == a[7] == a[0] == a[2] and a[1] == a[3] == a[21] == a[23] and a[20] == a[22] == a[8] == a[10] and a[9] == a[11] == a[4] == a[6]: print('YES') elif a[8] == a[10] == a[5] == a[7] and a[4] == a[6] == a[1] == a[3] and a[0] == a[2] == a[20] == a[22] and a[21] == a[23] == a[9] == a[11]: print('YES') else: b = b + 1 else: print('NO') if b > 0: print('NO') ```
output
1
83,097
7
166,195
Provide tags and a correct Python 3 solution for this coding contest problem. During the breaks between competitions, top-model Izabella tries to develop herself and not to be bored. For example, now she tries to solve Rubik's cube 2x2x2. It's too hard to learn to solve Rubik's cube instantly, so she learns to understand if it's possible to solve the cube in some state using 90-degrees rotation of one face of the cube in any direction. To check her answers she wants to use a program which will for some state of cube tell if it's possible to solve it using one rotation, described above. Cube is called solved if for each face of cube all squares on it has the same color. https://en.wikipedia.org/wiki/Rubik's_Cube Input In first line given a sequence of 24 integers ai (1 ≀ ai ≀ 6), where ai denotes color of i-th square. There are exactly 4 occurrences of all colors in this sequence. Output Print Β«YESΒ» (without quotes) if it's possible to solve cube using one rotation and Β«NOΒ» (without quotes) otherwise. Examples Input 2 5 4 6 1 3 6 2 5 5 1 2 3 5 3 1 1 2 4 6 6 4 3 4 Output NO Input 5 3 5 3 2 5 2 5 6 2 6 2 4 4 4 4 1 1 1 1 6 3 6 3 Output YES Note In first test case cube looks like this: <image> In second test case cube looks like this: <image> It's possible to solve cube by rotating face with squares with numbers 13, 14, 15, 16.
instruction
0
83,098
7
166,196
Tags: brute force, implementation Correct Solution: ``` import itertools, sys id = ''' 12 34 ef56ijmn gh78klop 9a bc ''' transforms = [ [ [1,2,3,4], [22,21,18,17,6,5,14,13] ], [ [9,10,11,12], [15,16,7,8,19,20,23,24], ], [ [5,6,7,8], [3,4,17,19,10,9,16,14], ], [ [13,14,15,16], [1,3,5,7,9,11,24,22], ], [ [17,18,19,20], [4,2,21,23,12,10,8,6], ], [ [21,22,24,23], [2,1,13,15,11,12,20,18] ], ] def rot(c, perm, rev): new = list(c) if rev: for i in range(len(perm)): new[perm[i] - 1] = c[perm[(i+1) % len(perm)] - 1] else: for i in range(len(perm)): new[perm[(i+1) % len(perm)] - 1] = c[perm[i] - 1] return new def do_t(c, t, rev): return rot(rot(rot(c, t[0], rev), t[1], rev), t[1], rev) faces = [[1,2,3,4],[5,6,7,8],[9,10,11,12],[13,14,15,16],[17,18,19,20],[21,22,23,24]] colors = input().split() for rev, t in itertools.product([0,1], transforms): newc = do_t(colors, t, rev) ok = True for f in faces: fc = [ newc[i-1] for i in f ] if fc.count(fc[0]) != 4: ok = False if ok: #print('rotate', rev, t) print('YES') sys.exit() print('NO') ```
output
1
83,098
7
166,197
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. During the breaks between competitions, top-model Izabella tries to develop herself and not to be bored. For example, now she tries to solve Rubik's cube 2x2x2. It's too hard to learn to solve Rubik's cube instantly, so she learns to understand if it's possible to solve the cube in some state using 90-degrees rotation of one face of the cube in any direction. To check her answers she wants to use a program which will for some state of cube tell if it's possible to solve it using one rotation, described above. Cube is called solved if for each face of cube all squares on it has the same color. https://en.wikipedia.org/wiki/Rubik's_Cube Input In first line given a sequence of 24 integers ai (1 ≀ ai ≀ 6), where ai denotes color of i-th square. There are exactly 4 occurrences of all colors in this sequence. Output Print Β«YESΒ» (without quotes) if it's possible to solve cube using one rotation and Β«NOΒ» (without quotes) otherwise. Examples Input 2 5 4 6 1 3 6 2 5 5 1 2 3 5 3 1 1 2 4 6 6 4 3 4 Output NO Input 5 3 5 3 2 5 2 5 6 2 6 2 4 4 4 4 1 1 1 1 6 3 6 3 Output YES Note In first test case cube looks like this: <image> In second test case cube looks like this: <image> It's possible to solve cube by rotating face with squares with numbers 13, 14, 15, 16. Submitted Solution: ``` from collections import Counter def only_one(a): return len(Counter(a)) == 1 colors = list(map(int, input().split())) pairs = ((1, 3), (2, 6), (4, 5)) new_pairs = list() f = False c = 0 for i in pairs: a, b = ((i[0] - 1) * 4, i[0] * 4), (((i[1] - 1) * 4, i[1] * 4)) if only_one(colors[a[0]: a[1]]) and only_one(colors[b[0]: b[1]]): f = True c += 1 else: new_pairs.append(i) if not f or c != 1: print('NO') else: C = colors if pairs[0] not in new_pairs: one = [C[12], C[13], C[4], C[5], C[16], C[17], C[20], C[21]] two = [C[14], C[15], C[6], C[8], C[18], C[19], C[22], C[23]] if one[2:] + one[:2] == two or one[6:] + one[:6] == two: print('YES') else: print('NO') exit() elif pairs[1] not in new_pairs: one = [C[2], C[3], C[16], C[18], C[9], C[8], C[15], C[13]] two = [C[0], C[1], C[17], C[19], C[11], C[10], C[14], C[12]] if one[2:] + one[:2] == two or one[6:] + one[:6] == two: print('YES') else: print('NO') exit() elif pairs[2] not in new_pairs: one = [C[0], C[2], C[4], C[6], C[8], C[10], C[23], C[21]] two = [C[1], C[3], C[5], C[7], C[9], C[11], C[22], C[20]] if one[2:] + one[:2] == two or one[6:] + one[:6] == two: print('YES') else: print('NO') exit() print('NO') ```
instruction
0
83,106
7
166,212
No
output
1
83,106
7
166,213
Provide tags and a correct Python 3 solution for this coding contest problem. Dreamoon likes coloring cells very much. There is a row of n cells. Initially, all cells are empty (don't contain any color). Cells are numbered from 1 to n. You are given an integer m and m integers l_1, l_2, …, l_m (1 ≀ l_i ≀ n) Dreamoon will perform m operations. In i-th operation, Dreamoon will choose a number p_i from range [1, n-l_i+1] (inclusive) and will paint all cells from p_i to p_i+l_i-1 (inclusive) in i-th color. Note that cells may be colored more one than once, in this case, cell will have the color from the latest operation. Dreamoon hopes that after these m operations, all colors will appear at least once and all cells will be colored. Please help Dreamoon to choose p_i in each operation to satisfy all constraints. Input The first line contains two integers n,m (1 ≀ m ≀ n ≀ 100 000). The second line contains m integers l_1, l_2, …, l_m (1 ≀ l_i ≀ n). Output If it's impossible to perform m operations to satisfy all constraints, print "'-1" (without quotes). Otherwise, print m integers p_1, p_2, …, p_m (1 ≀ p_i ≀ n - l_i + 1), after these m operations, all colors should appear at least once and all cells should be colored. If there are several possible solutions, you can print any. Examples Input 5 3 3 2 2 Output 2 4 1 Input 10 1 1 Output -1
instruction
0
83,525
7
167,050
Tags: constructive algorithms, greedy, implementation, math Correct Solution: ``` def indexer(x,y,n): #y is total cells colored if(x>y): return n-x+1 else: return n-y def repair(ans,n,z): if(n==0): return; push=[0 for i in range(len(ans))] for i in range(len(ans)-2,-1,-1): z[i]=z[i]-(ans[i+1]-ans[i]) while(n>0 and z[i]>0): n-=1 push[i]+=1 z[i]-=1 if(n>0): ans[0]=-1 return ans; for i in range(len(push)-1,-1,-1): ans[i]-=push[i] if(i!=0): push[i-1]+=push[i] return ans; n,k=map(int,input().split()) z=list(map(int,input().split())) if(sum(z)<n): print(-1) exit(0) gns=0 flag=0 ans=[0 for i in range(len(z))] for i in range(len(z)-1,-1,-1): if(gns==n): flag=1 break; ans[i]=indexer(z[i],gns,n) gns=n-ans[i]+1 if(flag==1): print(-1) exit(0) repair(ans,n-gns,z) if(ans[0]==-1): print(-1) exit(0) print(*ans) ```
output
1
83,525
7
167,051
Provide tags and a correct Python 3 solution for this coding contest problem. Dreamoon likes coloring cells very much. There is a row of n cells. Initially, all cells are empty (don't contain any color). Cells are numbered from 1 to n. You are given an integer m and m integers l_1, l_2, …, l_m (1 ≀ l_i ≀ n) Dreamoon will perform m operations. In i-th operation, Dreamoon will choose a number p_i from range [1, n-l_i+1] (inclusive) and will paint all cells from p_i to p_i+l_i-1 (inclusive) in i-th color. Note that cells may be colored more one than once, in this case, cell will have the color from the latest operation. Dreamoon hopes that after these m operations, all colors will appear at least once and all cells will be colored. Please help Dreamoon to choose p_i in each operation to satisfy all constraints. Input The first line contains two integers n,m (1 ≀ m ≀ n ≀ 100 000). The second line contains m integers l_1, l_2, …, l_m (1 ≀ l_i ≀ n). Output If it's impossible to perform m operations to satisfy all constraints, print "'-1" (without quotes). Otherwise, print m integers p_1, p_2, …, p_m (1 ≀ p_i ≀ n - l_i + 1), after these m operations, all colors should appear at least once and all cells should be colored. If there are several possible solutions, you can print any. Examples Input 5 3 3 2 2 Output 2 4 1 Input 10 1 1 Output -1
instruction
0
83,526
7
167,052
Tags: constructive algorithms, greedy, implementation, math Correct Solution: ``` #!/usr/bin/env python3 N, M = input().split(' ') N, M = int(N), int(M) L = input().split(' ') L = list(int(x) for x in L) def answer(N, M, L): offsets = [0] for i in range(M-1): offsets += [1] overhang = 0 for ii in range(M-1): # we are considering the ith object, counting from 0 i = M-1-ii left_edge = i+1 right_edge = left_edge + L[i] - 1 + overhang if right_edge > N: return "-1" max_right_edge = right_edge + L[i-1] - 1 if max_right_edge > N: max_right_edge = N offsets[i] += (max_right_edge - right_edge) parent_right_edge = i + L[i-1] - 1 overhang = max(0, max_right_edge - parent_right_edge) if L[0] + overhang < N: return "-1" pos = 1 ret = [1] for o in offsets[1:]: pos += o ret += [pos] return ' '.join(str(r) for r in ret) print(answer(N, M, L)) ```
output
1
83,526
7
167,053
Provide tags and a correct Python 3 solution for this coding contest problem. Dreamoon likes coloring cells very much. There is a row of n cells. Initially, all cells are empty (don't contain any color). Cells are numbered from 1 to n. You are given an integer m and m integers l_1, l_2, …, l_m (1 ≀ l_i ≀ n) Dreamoon will perform m operations. In i-th operation, Dreamoon will choose a number p_i from range [1, n-l_i+1] (inclusive) and will paint all cells from p_i to p_i+l_i-1 (inclusive) in i-th color. Note that cells may be colored more one than once, in this case, cell will have the color from the latest operation. Dreamoon hopes that after these m operations, all colors will appear at least once and all cells will be colored. Please help Dreamoon to choose p_i in each operation to satisfy all constraints. Input The first line contains two integers n,m (1 ≀ m ≀ n ≀ 100 000). The second line contains m integers l_1, l_2, …, l_m (1 ≀ l_i ≀ n). Output If it's impossible to perform m operations to satisfy all constraints, print "'-1" (without quotes). Otherwise, print m integers p_1, p_2, …, p_m (1 ≀ p_i ≀ n - l_i + 1), after these m operations, all colors should appear at least once and all cells should be colored. If there are several possible solutions, you can print any. Examples Input 5 3 3 2 2 Output 2 4 1 Input 10 1 1 Output -1
instruction
0
83,527
7
167,054
Tags: constructive algorithms, greedy, implementation, math Correct Solution: ``` n, m = map(int, input().split()) l = list(map(int, input().split())) out = [] curr = 0 lastPoss = [n - l[i] for i in range(m)] for i in range(m - 2, -1, -1): lastPoss[i] = min(lastPoss[i], lastPoss[i+1]-1) if lastPoss[0] < 0: print(-1) else: for i in range(m): v = l[i] out.append(min(curr,lastPoss[i])) curr += v if curr >= n: print(' '.join(map(lambda x: str(x+1),out))) else: print(-1) ```
output
1
83,527
7
167,055
Provide tags and a correct Python 3 solution for this coding contest problem. Dreamoon likes coloring cells very much. There is a row of n cells. Initially, all cells are empty (don't contain any color). Cells are numbered from 1 to n. You are given an integer m and m integers l_1, l_2, …, l_m (1 ≀ l_i ≀ n) Dreamoon will perform m operations. In i-th operation, Dreamoon will choose a number p_i from range [1, n-l_i+1] (inclusive) and will paint all cells from p_i to p_i+l_i-1 (inclusive) in i-th color. Note that cells may be colored more one than once, in this case, cell will have the color from the latest operation. Dreamoon hopes that after these m operations, all colors will appear at least once and all cells will be colored. Please help Dreamoon to choose p_i in each operation to satisfy all constraints. Input The first line contains two integers n,m (1 ≀ m ≀ n ≀ 100 000). The second line contains m integers l_1, l_2, …, l_m (1 ≀ l_i ≀ n). Output If it's impossible to perform m operations to satisfy all constraints, print "'-1" (without quotes). Otherwise, print m integers p_1, p_2, …, p_m (1 ≀ p_i ≀ n - l_i + 1), after these m operations, all colors should appear at least once and all cells should be colored. If there are several possible solutions, you can print any. Examples Input 5 3 3 2 2 Output 2 4 1 Input 10 1 1 Output -1
instruction
0
83,528
7
167,056
Tags: constructive algorithms, greedy, implementation, math Correct Solution: ``` # from future import print_function,division # range = xrange import sys input = sys.stdin.readline # sys.setrecursionlimit(10**9) from sys import stdin, stdout def main(): n,m = [int(s) for s in input().split()] l = [int(s) for s in input().split()] sums = [0]*m sums[0] = l[0] for i in range(1,m): sums[i] = sums[i-1]+l[i] ww = 0 for i in range(m): ww = max(ww, i+l[i]) if max(ww,m+l[-1]-1)>n: print(-1) elif sums[-1]<n: print(-1) elif m==1: print(1) else: ans = [0]*m w = m+l[-1]-1 ans[-1] = n-l[-1]+1 j = m-2 while w + l[j]-1 < n: w += (l[j]-1) ans[j] = ans[j+1]-l[j] j-=1 if j>=0: for i in range(j+1): ans[i] = i+1 print(*ans) if __name__== '__main__': main() ```
output
1
83,528
7
167,057
Provide tags and a correct Python 3 solution for this coding contest problem. Dreamoon likes coloring cells very much. There is a row of n cells. Initially, all cells are empty (don't contain any color). Cells are numbered from 1 to n. You are given an integer m and m integers l_1, l_2, …, l_m (1 ≀ l_i ≀ n) Dreamoon will perform m operations. In i-th operation, Dreamoon will choose a number p_i from range [1, n-l_i+1] (inclusive) and will paint all cells from p_i to p_i+l_i-1 (inclusive) in i-th color. Note that cells may be colored more one than once, in this case, cell will have the color from the latest operation. Dreamoon hopes that after these m operations, all colors will appear at least once and all cells will be colored. Please help Dreamoon to choose p_i in each operation to satisfy all constraints. Input The first line contains two integers n,m (1 ≀ m ≀ n ≀ 100 000). The second line contains m integers l_1, l_2, …, l_m (1 ≀ l_i ≀ n). Output If it's impossible to perform m operations to satisfy all constraints, print "'-1" (without quotes). Otherwise, print m integers p_1, p_2, …, p_m (1 ≀ p_i ≀ n - l_i + 1), after these m operations, all colors should appear at least once and all cells should be colored. If there are several possible solutions, you can print any. Examples Input 5 3 3 2 2 Output 2 4 1 Input 10 1 1 Output -1
instruction
0
83,529
7
167,058
Tags: constructive algorithms, greedy, implementation, math Correct Solution: ``` #Code by Sounak, IIESTS #------------------------------warmup---------------------------- import os import sys import math from io import BytesIO, IOBase from fractions import Fraction from collections import defaultdict from itertools import permutations 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----------------------------------------------------- n,m = [int(i) for i in input().split()] a = [int(i) for i in input().split()] s = sum(a) if s < n: print(-1) else: r = [] diff = s-n curr = 0 valid = True for i in range(m): r.append(curr+1) curr += a[i] if curr>n: valid = False d = min(diff,a[i]-1) curr -= d diff -= d if valid: print(*r) else: print(-1) ```
output
1
83,529
7
167,059
Provide tags and a correct Python 3 solution for this coding contest problem. Dreamoon likes coloring cells very much. There is a row of n cells. Initially, all cells are empty (don't contain any color). Cells are numbered from 1 to n. You are given an integer m and m integers l_1, l_2, …, l_m (1 ≀ l_i ≀ n) Dreamoon will perform m operations. In i-th operation, Dreamoon will choose a number p_i from range [1, n-l_i+1] (inclusive) and will paint all cells from p_i to p_i+l_i-1 (inclusive) in i-th color. Note that cells may be colored more one than once, in this case, cell will have the color from the latest operation. Dreamoon hopes that after these m operations, all colors will appear at least once and all cells will be colored. Please help Dreamoon to choose p_i in each operation to satisfy all constraints. Input The first line contains two integers n,m (1 ≀ m ≀ n ≀ 100 000). The second line contains m integers l_1, l_2, …, l_m (1 ≀ l_i ≀ n). Output If it's impossible to perform m operations to satisfy all constraints, print "'-1" (without quotes). Otherwise, print m integers p_1, p_2, …, p_m (1 ≀ p_i ≀ n - l_i + 1), after these m operations, all colors should appear at least once and all cells should be colored. If there are several possible solutions, you can print any. Examples Input 5 3 3 2 2 Output 2 4 1 Input 10 1 1 Output -1
instruction
0
83,530
7
167,060
Tags: constructive algorithms, greedy, implementation, math Correct Solution: ``` import sys input = sys.stdin.readline if __name__ == "__main__": n, m = [int(a) for a in input().split()] ls = [int(a) for a in input().split()] fail = False for i in range(m): if ls[i] > n-i: fail = True break if fail: print(-1) else: for i in range(1, m): ls[m-i-1] += ls[m-i] if ls[0] < n: print(-1) else: remain = n s = [' '] * n for i in range(m): remain = min(remain, ls[i]) s[i] = str(n-remain+1) remain -= 1 print(' '.join(s)) ```
output
1
83,530
7
167,061
Provide tags and a correct Python 3 solution for this coding contest problem. Dreamoon likes coloring cells very much. There is a row of n cells. Initially, all cells are empty (don't contain any color). Cells are numbered from 1 to n. You are given an integer m and m integers l_1, l_2, …, l_m (1 ≀ l_i ≀ n) Dreamoon will perform m operations. In i-th operation, Dreamoon will choose a number p_i from range [1, n-l_i+1] (inclusive) and will paint all cells from p_i to p_i+l_i-1 (inclusive) in i-th color. Note that cells may be colored more one than once, in this case, cell will have the color from the latest operation. Dreamoon hopes that after these m operations, all colors will appear at least once and all cells will be colored. Please help Dreamoon to choose p_i in each operation to satisfy all constraints. Input The first line contains two integers n,m (1 ≀ m ≀ n ≀ 100 000). The second line contains m integers l_1, l_2, …, l_m (1 ≀ l_i ≀ n). Output If it's impossible to perform m operations to satisfy all constraints, print "'-1" (without quotes). Otherwise, print m integers p_1, p_2, …, p_m (1 ≀ p_i ≀ n - l_i + 1), after these m operations, all colors should appear at least once and all cells should be colored. If there are several possible solutions, you can print any. Examples Input 5 3 3 2 2 Output 2 4 1 Input 10 1 1 Output -1
instruction
0
83,531
7
167,062
Tags: constructive algorithms, greedy, implementation, math Correct Solution: ``` from sys import stdin input = stdin.readline if __name__ == '__main__': n, m = map(int, input().split()) larr = list(map(int, input().split())) for i, l in enumerate(larr): if l > n - i: print(-1) exit(0) sl = sum(larr) if sl < n: print(-1) exit(0) ps = [] for i, l in enumerate(larr): if sl > n - i: ps.append(i + 1) else: ps.append(n - sl + 1) sl -= l print(*ps) ```
output
1
83,531
7
167,063
Provide tags and a correct Python 3 solution for this coding contest problem. Dreamoon likes coloring cells very much. There is a row of n cells. Initially, all cells are empty (don't contain any color). Cells are numbered from 1 to n. You are given an integer m and m integers l_1, l_2, …, l_m (1 ≀ l_i ≀ n) Dreamoon will perform m operations. In i-th operation, Dreamoon will choose a number p_i from range [1, n-l_i+1] (inclusive) and will paint all cells from p_i to p_i+l_i-1 (inclusive) in i-th color. Note that cells may be colored more one than once, in this case, cell will have the color from the latest operation. Dreamoon hopes that after these m operations, all colors will appear at least once and all cells will be colored. Please help Dreamoon to choose p_i in each operation to satisfy all constraints. Input The first line contains two integers n,m (1 ≀ m ≀ n ≀ 100 000). The second line contains m integers l_1, l_2, …, l_m (1 ≀ l_i ≀ n). Output If it's impossible to perform m operations to satisfy all constraints, print "'-1" (without quotes). Otherwise, print m integers p_1, p_2, …, p_m (1 ≀ p_i ≀ n - l_i + 1), after these m operations, all colors should appear at least once and all cells should be colored. If there are several possible solutions, you can print any. Examples Input 5 3 3 2 2 Output 2 4 1 Input 10 1 1 Output -1
instruction
0
83,532
7
167,064
Tags: constructive algorithms, greedy, implementation, math Correct Solution: ``` n, m = map(int, input().split()) l = list(map(int, input().split())) s = sum(l) def solve(): if s < n: return [-1] for i in range(m): if l[i] > n - i: return [-1] ov = s - n idx = 1 sln = [] for i in range(m): if ov > 0 and idx != 1: d = min(ov, l[i-1]-1) idx -= d ov -= d sln.append(idx) idx += l[i] return sln print(*solve()) ```
output
1
83,532
7
167,065
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Dreamoon likes coloring cells very much. There is a row of n cells. Initially, all cells are empty (don't contain any color). Cells are numbered from 1 to n. You are given an integer m and m integers l_1, l_2, …, l_m (1 ≀ l_i ≀ n) Dreamoon will perform m operations. In i-th operation, Dreamoon will choose a number p_i from range [1, n-l_i+1] (inclusive) and will paint all cells from p_i to p_i+l_i-1 (inclusive) in i-th color. Note that cells may be colored more one than once, in this case, cell will have the color from the latest operation. Dreamoon hopes that after these m operations, all colors will appear at least once and all cells will be colored. Please help Dreamoon to choose p_i in each operation to satisfy all constraints. Input The first line contains two integers n,m (1 ≀ m ≀ n ≀ 100 000). The second line contains m integers l_1, l_2, …, l_m (1 ≀ l_i ≀ n). Output If it's impossible to perform m operations to satisfy all constraints, print "'-1" (without quotes). Otherwise, print m integers p_1, p_2, …, p_m (1 ≀ p_i ≀ n - l_i + 1), after these m operations, all colors should appear at least once and all cells should be colored. If there are several possible solutions, you can print any. Examples Input 5 3 3 2 2 Output 2 4 1 Input 10 1 1 Output -1 Submitted Solution: ``` n,m=map(int,input().split()) l=[0]+list(map(int,input().split())) for i in range(1,m+1): if l[i]+i-1>n: print(-1) exit() suffix_sum=[0]*(m+2) for i in range(m+1)[::-1]: suffix_sum[i]=suffix_sum[i+1]+l[i] if suffix_sum[1]<n: print(-1) exit() p=[0]*(m+1) for i in range(1,m+1): p[i]=max(i,n-suffix_sum[i]+1) print(*p[1:]) ```
instruction
0
83,533
7
167,066
Yes
output
1
83,533
7
167,067
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Dreamoon likes coloring cells very much. There is a row of n cells. Initially, all cells are empty (don't contain any color). Cells are numbered from 1 to n. You are given an integer m and m integers l_1, l_2, …, l_m (1 ≀ l_i ≀ n) Dreamoon will perform m operations. In i-th operation, Dreamoon will choose a number p_i from range [1, n-l_i+1] (inclusive) and will paint all cells from p_i to p_i+l_i-1 (inclusive) in i-th color. Note that cells may be colored more one than once, in this case, cell will have the color from the latest operation. Dreamoon hopes that after these m operations, all colors will appear at least once and all cells will be colored. Please help Dreamoon to choose p_i in each operation to satisfy all constraints. Input The first line contains two integers n,m (1 ≀ m ≀ n ≀ 100 000). The second line contains m integers l_1, l_2, …, l_m (1 ≀ l_i ≀ n). Output If it's impossible to perform m operations to satisfy all constraints, print "'-1" (without quotes). Otherwise, print m integers p_1, p_2, …, p_m (1 ≀ p_i ≀ n - l_i + 1), after these m operations, all colors should appear at least once and all cells should be colored. If there are several possible solutions, you can print any. Examples Input 5 3 3 2 2 Output 2 4 1 Input 10 1 1 Output -1 Submitted Solution: ``` # ------------------- fast io -------------------- 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") # ------------------- fast io -------------------- n,m=map(int,input().split()) vals=list(map(int,input().split())) broke=False;mcover=0 ans=[];prefcover=[] for s in range(m): if s+1<=n-vals[s]+1: mcover=max(mcover,s+vals[s]) ans.append(s+1);prefcover.append(mcover) else: broke=True;break if broke==True: print(-1) else: diff=n-mcover shift=[] for s in range(1,m): if diff==0: break else: avl=prefcover[s-1]-s v0=min(avl,diff) diff-=v0;shift.append(v0) if len(shift)>0: prefsum=[0,shift[0]] for s in range(1,len(shift)): prefsum.append(prefsum[-1]+shift[s]) for s in range(1,m): if s<=len(prefsum)-1: ans[s]+=prefsum[s] else: ans[s]+=prefsum[-1] if diff==0: ans[-1]=n-vals[-1]+1 print(*ans) else: print(-1) ```
instruction
0
83,534
7
167,068
Yes
output
1
83,534
7
167,069
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Dreamoon likes coloring cells very much. There is a row of n cells. Initially, all cells are empty (don't contain any color). Cells are numbered from 1 to n. You are given an integer m and m integers l_1, l_2, …, l_m (1 ≀ l_i ≀ n) Dreamoon will perform m operations. In i-th operation, Dreamoon will choose a number p_i from range [1, n-l_i+1] (inclusive) and will paint all cells from p_i to p_i+l_i-1 (inclusive) in i-th color. Note that cells may be colored more one than once, in this case, cell will have the color from the latest operation. Dreamoon hopes that after these m operations, all colors will appear at least once and all cells will be colored. Please help Dreamoon to choose p_i in each operation to satisfy all constraints. Input The first line contains two integers n,m (1 ≀ m ≀ n ≀ 100 000). The second line contains m integers l_1, l_2, …, l_m (1 ≀ l_i ≀ n). Output If it's impossible to perform m operations to satisfy all constraints, print "'-1" (without quotes). Otherwise, print m integers p_1, p_2, …, p_m (1 ≀ p_i ≀ n - l_i + 1), after these m operations, all colors should appear at least once and all cells should be colored. If there are several possible solutions, you can print any. Examples Input 5 3 3 2 2 Output 2 4 1 Input 10 1 1 Output -1 Submitted Solution: ``` n,m=map(int,input().split()) li=list(map(int,input().split())) sumli=sum(li) if sumli<n:print(-1) else: deficiency=n-m for i in range(m): if i+li[i]>n: print(-1) break else: i=n-li[-1] deficiency-=li[-1]-1 output=[i] z=m-2 while deficiency>0: deficiency-=li[z]-1 if deficiency>=0: output.append(output[-1]-li[z]) else:output.append(output[-1]-deficiency-li[z]) z-=1 for i in range(z,-1,-1): output.append(i) output.reverse() output=list(map(lambda i:i+1,output)) print(*output) ```
instruction
0
83,535
7
167,070
Yes
output
1
83,535
7
167,071
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Dreamoon likes coloring cells very much. There is a row of n cells. Initially, all cells are empty (don't contain any color). Cells are numbered from 1 to n. You are given an integer m and m integers l_1, l_2, …, l_m (1 ≀ l_i ≀ n) Dreamoon will perform m operations. In i-th operation, Dreamoon will choose a number p_i from range [1, n-l_i+1] (inclusive) and will paint all cells from p_i to p_i+l_i-1 (inclusive) in i-th color. Note that cells may be colored more one than once, in this case, cell will have the color from the latest operation. Dreamoon hopes that after these m operations, all colors will appear at least once and all cells will be colored. Please help Dreamoon to choose p_i in each operation to satisfy all constraints. Input The first line contains two integers n,m (1 ≀ m ≀ n ≀ 100 000). The second line contains m integers l_1, l_2, …, l_m (1 ≀ l_i ≀ n). Output If it's impossible to perform m operations to satisfy all constraints, print "'-1" (without quotes). Otherwise, print m integers p_1, p_2, …, p_m (1 ≀ p_i ≀ n - l_i + 1), after these m operations, all colors should appear at least once and all cells should be colored. If there are several possible solutions, you can print any. Examples Input 5 3 3 2 2 Output 2 4 1 Input 10 1 1 Output -1 Submitted Solution: ``` n,m = map(int,input().split()) l = list(map(int,input().split())) ls = sum(l) ans = [] import sys if ls < n or m-1+l[-1] > n: print (-1) sys.exit() cut = [] remain = ls - n for i in range(m): if l[i]-1 < remain: cut.append(l[i]-1) remain -= l[i]-1 else: cut.append(remain) remain = 0 l2 = [0] * m for i in range(m): l2[i] = l[i] - cut[i] now = 1 for i in range(m): ans.append(now) now += l2[i] for i in range(m): if l[i] + ans[i] - 1 > n: print (-1) sys.exit() print (*ans) ```
instruction
0
83,536
7
167,072
Yes
output
1
83,536
7
167,073
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Dreamoon likes coloring cells very much. There is a row of n cells. Initially, all cells are empty (don't contain any color). Cells are numbered from 1 to n. You are given an integer m and m integers l_1, l_2, …, l_m (1 ≀ l_i ≀ n) Dreamoon will perform m operations. In i-th operation, Dreamoon will choose a number p_i from range [1, n-l_i+1] (inclusive) and will paint all cells from p_i to p_i+l_i-1 (inclusive) in i-th color. Note that cells may be colored more one than once, in this case, cell will have the color from the latest operation. Dreamoon hopes that after these m operations, all colors will appear at least once and all cells will be colored. Please help Dreamoon to choose p_i in each operation to satisfy all constraints. Input The first line contains two integers n,m (1 ≀ m ≀ n ≀ 100 000). The second line contains m integers l_1, l_2, …, l_m (1 ≀ l_i ≀ n). Output If it's impossible to perform m operations to satisfy all constraints, print "'-1" (without quotes). Otherwise, print m integers p_1, p_2, …, p_m (1 ≀ p_i ≀ n - l_i + 1), after these m operations, all colors should appear at least once and all cells should be colored. If there are several possible solutions, you can print any. Examples Input 5 3 3 2 2 Output 2 4 1 Input 10 1 1 Output -1 Submitted Solution: ``` def go(): n,m = map(int,input().split()) x=list(map(int,input().split())) if sum(x)<n: return -1 for i,xx in enumerate(x): if i+xx>n: return -1 res=list(range(1,1+m)) right=max(a+b-1 for a,b in zip(x,res)) if right<n: mis=n-right plus=[0]*m i=m-2 while mis>0: plus[i+1]=min(mis,x[i]-1) mis-=plus[i+1] i-=1 for i in range(1,m): plus[i]+=plus[i-1] res[i]+=plus[i] return ' '.join(map(str,res)) # x,s = map(int,input().split()) # t = int(input()) t = 1 # ans = [] for _ in range(t): print(go()) # ans.append(str(go())) # # print('\n'.join(ans)) ```
instruction
0
83,537
7
167,074
No
output
1
83,537
7
167,075
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Dreamoon likes coloring cells very much. There is a row of n cells. Initially, all cells are empty (don't contain any color). Cells are numbered from 1 to n. You are given an integer m and m integers l_1, l_2, …, l_m (1 ≀ l_i ≀ n) Dreamoon will perform m operations. In i-th operation, Dreamoon will choose a number p_i from range [1, n-l_i+1] (inclusive) and will paint all cells from p_i to p_i+l_i-1 (inclusive) in i-th color. Note that cells may be colored more one than once, in this case, cell will have the color from the latest operation. Dreamoon hopes that after these m operations, all colors will appear at least once and all cells will be colored. Please help Dreamoon to choose p_i in each operation to satisfy all constraints. Input The first line contains two integers n,m (1 ≀ m ≀ n ≀ 100 000). The second line contains m integers l_1, l_2, …, l_m (1 ≀ l_i ≀ n). Output If it's impossible to perform m operations to satisfy all constraints, print "'-1" (without quotes). Otherwise, print m integers p_1, p_2, …, p_m (1 ≀ p_i ≀ n - l_i + 1), after these m operations, all colors should appear at least once and all cells should be colored. If there are several possible solutions, you can print any. Examples Input 5 3 3 2 2 Output 2 4 1 Input 10 1 1 Output -1 Submitted Solution: ``` # from future import print_function,division # range = xrange import sys input = sys.stdin.readline # sys.setrecursionlimit(10**9) from sys import stdin, stdout def main(): n,m = [int(s) for s in input().split()] l = [int(s) for s in input().split()] sums = [0]*m sums[0] = l[0] for i in range(1,m): sums[i] = sums[i-1]+l[i] if m+l[-1]-1>n: print(-1) elif sums[-1]<n: print(-1) elif m==1: print(1) else: ans = [0]*m w = m+l[-1]-1 ans[-1] = n-l[-1]+1 j = m-2 while w + l[j]-1 < n: w += (l[j]-1) ans[j] = ans[j+1]-l[j]+1 j-=1 if j>=0: for i in range(j+1): ans[i] = i+1 print(*ans) if __name__== '__main__': main() ```
instruction
0
83,538
7
167,076
No
output
1
83,538
7
167,077
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Dreamoon likes coloring cells very much. There is a row of n cells. Initially, all cells are empty (don't contain any color). Cells are numbered from 1 to n. You are given an integer m and m integers l_1, l_2, …, l_m (1 ≀ l_i ≀ n) Dreamoon will perform m operations. In i-th operation, Dreamoon will choose a number p_i from range [1, n-l_i+1] (inclusive) and will paint all cells from p_i to p_i+l_i-1 (inclusive) in i-th color. Note that cells may be colored more one than once, in this case, cell will have the color from the latest operation. Dreamoon hopes that after these m operations, all colors will appear at least once and all cells will be colored. Please help Dreamoon to choose p_i in each operation to satisfy all constraints. Input The first line contains two integers n,m (1 ≀ m ≀ n ≀ 100 000). The second line contains m integers l_1, l_2, …, l_m (1 ≀ l_i ≀ n). Output If it's impossible to perform m operations to satisfy all constraints, print "'-1" (without quotes). Otherwise, print m integers p_1, p_2, …, p_m (1 ≀ p_i ≀ n - l_i + 1), after these m operations, all colors should appear at least once and all cells should be colored. If there are several possible solutions, you can print any. Examples Input 5 3 3 2 2 Output 2 4 1 Input 10 1 1 Output -1 Submitted Solution: ``` n,m=map(int,input().split()) new=list(map(int,input().split())) l=[] for i in range(m): l.append((new[i],i)) l.sort(reverse=True) ans=[-1]*m ans[l[0][1]]=1 start=l[0][0]+1 left=-1 width=[l[0][0]] for i in range(1,m): if start>n: left = m-i break ans[l[i][1]]=(min(start,n)) width.append(min(l[i][0],n-start+1)) start+=l[i][0] if start>=n: if left==-1: print (*ans) else: # find=-1 # print (*ans) # print (width,left) # print (left) flag = False start=2 for i in range(m-left,m): if start<=(n-l[i][0]+1): ans[l[i][1]]=start start+=1 else: flag=True break if flag: print (-1) else: print (*ans) else: print (-1) ```
instruction
0
83,539
7
167,078
No
output
1
83,539
7
167,079
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Dreamoon likes coloring cells very much. There is a row of n cells. Initially, all cells are empty (don't contain any color). Cells are numbered from 1 to n. You are given an integer m and m integers l_1, l_2, …, l_m (1 ≀ l_i ≀ n) Dreamoon will perform m operations. In i-th operation, Dreamoon will choose a number p_i from range [1, n-l_i+1] (inclusive) and will paint all cells from p_i to p_i+l_i-1 (inclusive) in i-th color. Note that cells may be colored more one than once, in this case, cell will have the color from the latest operation. Dreamoon hopes that after these m operations, all colors will appear at least once and all cells will be colored. Please help Dreamoon to choose p_i in each operation to satisfy all constraints. Input The first line contains two integers n,m (1 ≀ m ≀ n ≀ 100 000). The second line contains m integers l_1, l_2, …, l_m (1 ≀ l_i ≀ n). Output If it's impossible to perform m operations to satisfy all constraints, print "'-1" (without quotes). Otherwise, print m integers p_1, p_2, …, p_m (1 ≀ p_i ≀ n - l_i + 1), after these m operations, all colors should appear at least once and all cells should be colored. If there are several possible solutions, you can print any. Examples Input 5 3 3 2 2 Output 2 4 1 Input 10 1 1 Output -1 Submitted Solution: ``` import sys n,m=map(int,input().split()) l=list(map(int,input().split())) if(sum(l)<n): print(-1) sys.exit(0) pre=[1]*(m+1) # pre[0]=1 max=m+l[-1]-1 if(max>n): print(-1) sys.exit(0) # print(max) # print(pre) for i in range(m-2,-1,-1): if l[i]>1: if (l[i]-1)+max<=n: max=max+l[i]-1 pre[i+1]+=l[i]-1 else: pre[i+1]+=n-max max=n if(max==n): break # print(pre) previous=0 for i in range(m): previous=previous+pre[i] if(pre[i]==0): previous+=1 print(previous,end=' ') print() ```
instruction
0
83,540
7
167,080
No
output
1
83,540
7
167,081
Provide tags and a correct Python 3 solution for this coding contest problem. 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.
instruction
0
83,641
7
167,282
Tags: brute force, implementation Correct Solution: ``` import sys #sys.stdin=open("data.txt") input=sys.stdin.readline mii=lambda:map(int,input().split()) for _ in range(int(input())): n,m=mii() r=[0,0] w=[0,0] for i in range(n): s=input().strip() for j in range(m): if s[j]=='R': r[(i+j)&1]=1 if s[j]=='W': w[(i+j)&1]=1 if r[0]==0 and w[1]==0: print('YES') for i in range(n): print(''.join(map(lambda x:'WR'[x%2],range(i,i+m)))) elif r[1]==0 and w[0]==0: print('YES') for i in range(n): print(''.join(map(lambda x:'RW'[x%2],range(i,i+m)))) else: print('NO') ```
output
1
83,641
7
167,283
Provide tags and a correct Python 3 solution for this coding contest problem. 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.
instruction
0
83,642
7
167,284
Tags: brute force, implementation Correct Solution: ``` c = int(input()) while c != 0: def display(matrix,R,C): for i in range(R): for j in range(C): print(matrix[i][j],end='') print() def fun(): for i in range(R): for j in range(C): if matrix[i][j] != '.': Check(i,j,matrix) return else: Check(0,0,matrix) return def Check(i,j,matrix): if ((i%2 == 0) ^ (j%2 == 0)): if matrix[i][j] == 'W': first_R(matrix) else: first_W(matrix) else: if matrix[i][j] == 'R': first_R(matrix) else: first_W(matrix) def first_R(matrix): for i in range(R): for j in range(C): if ((i%2 == 0) ^ (j%2 == 0)): if matrix[i][j] == 'R': print('NO') return if matrix[i][j] == '.': matrix[i][j] = 'W' else: if matrix[i][j] == 'W': print('NO') return if matrix[i][j] == '.': matrix[i][j] = 'R' print('YES') display(matrix,R,C) def first_W(matrix): for i in range(R): for j in range(C): if ((i%2 == 0) ^ (j%2 == 0)): if matrix[i][j] == 'W': print('NO') return if matrix[i][j] == '.': matrix[i][j] = 'R' else: if matrix[i][j] == 'R': print('NO') return if matrix[i][j] == '.': matrix[i][j] = 'W' print('YES') display(matrix,R,C) # A basic code for matrix input from user s1 = input() l1 = [int(a) for a in s1.split()] R = l1[0] C = l1[1] # Initialize matrix matrix = [] # For user input for i in range(R): # A for loop for row entries a =[] s2 = input() for j in s2: a.append(j) matrix.append(a) fun() # For printing the matrix c-=1 ```
output
1
83,642
7
167,285
Provide tags and a correct Python 3 solution for this coding contest problem. 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.
instruction
0
83,643
7
167,286
Tags: brute force, implementation Correct Solution: ``` import sys input=sys.stdin.readline t=int(input()) #t=1 for i in range(t): n,m=map(int,input().split()) #n=int(input()) #a=[int(x) for x in input().split()] grid=[] for i in range(n): temp=input().strip() grid.append(temp) r=[] w=[] for i in range(n): for j in range(m): if grid[i][j]=='R': r.append([i,j]) elif grid[i][j]=='W': w.append([i,j]) tempr=-1 tempw=-1 ans=True if len(r)>0: tempr=(r[0][0]+r[0][1])%2 for i in range(1,len(r)): if (r[i][0]+r[i][1])%2!=tempr: ans=False break if len(w)>0 and ans: tempw=(w[0][0]+w[0][1])%2 for i in range(1,len(w)): if (w[i][0]+w[i][1])%2!=tempw: ans=False break if tempr==-1 and tempw==-1: tempr=1 tempw=0 if tempw==tempr : ans=False if not ans: print("NO") continue if tempr==-1: tempr=1-tempw if tempw==-1: tempw=1-tempr if ans: print("YES") for i in range(n): for j in range(m): if (i+j)%2==tempr: print('R',end='') else: print('W',end='') print() print() ```
output
1
83,643
7
167,287
Provide tags and a correct Python 3 solution for this coding contest problem. 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.
instruction
0
83,644
7
167,288
Tags: brute force, implementation Correct Solution: ``` #every red cell only has white neighbours #and every white cell only has red neighbours for _ in range(int(input())): r,c = map(int,input().split()) found = [] #r,c,val for rows in range(r): row = input() for i in range(len(row)): if row[i] != ".": found.append([rows,i,row[i]]) #bfs fill #sedan matcha mot found se om ja eller nej create = [["0" for cccc in range(c)] for roro in range(r)] visited = [[False for cc in range(c)] for roro in range(r)] if len(found) == 0: found.append([0,0,"R"]) rrr = found[0][0] ccc = found[0][1] create[rrr][ccc] = found[0][2] Q = [[found[0][0],found[0][1],found[0][2]]] #r,c,val while Q: tmp = Q.pop() #color and go nxt #print(tmp[0],tmp[1]) create[tmp[0]][tmp[1]] = tmp[2] visited[tmp[0]][tmp[1]] = 1 val = tmp[2] if val == "R": val = "W" else: val = "R" y = tmp[0] x = tmp[1] #north clockwise if y-1 >= 0 and not visited[y-1][x]: Q.append([y-1,x,val]) if x +1 < c and not visited[y][x+1]: Q.append([y,x+1,val]) if y+1 < r and not visited[y+1][x]: Q.append([y+1,x,val]) if x-1 >= 0 and not visited[y][x-1]: Q.append([y,x-1,val]) f = False for el in found: if el[2] != create[el[0]][el[1]]: print("NO") f = True break if not f: print("YES") ans = "" for row in create: for el in row: ans += el print(ans) ans = "" ```
output
1
83,644
7
167,289
Provide tags and a correct Python 3 solution for this coding contest problem. 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.
instruction
0
83,645
7
167,290
Tags: brute force, implementation Correct Solution: ``` import sys,os.path if(os.path.exists('input.txt')): sys.stdin = open("input.txt","r+") sys.stdout = open("output.txt","w") sys.setrecursionlimit(200000) mod=10**9+7 from collections import defaultdict # from math import gcd,ceil,floor # print(26*26*26) def solve(a,p): for i in range(n): for j in range(m): if a[i][j]=="R": prev=-1 for k in range(j-1,-1,-1): if a[i][k]==".": a[i][k] =p[prev] prev=-1*prev else: if a[i][k]!=p[prev]: return "NO" prev=-1*prev prev=-1 for k in range(j+1,m): if a[i][k]==".": a[i][k] =p[prev] prev=-1*prev else: if a[i][k]!=p[prev]: return "NO" prev=-1*prev prev=-1 for k in range(i-1,-1,-1): if a[k][j]==".": a[k][j] =p[prev] prev=-1*prev else: if a[k][j]!=p[prev]: return "NO" prev=-1*prev prev=-1 for k in range(i+1,n): if a[k][j]==".": a[k][j] =p[prev] prev=-1*prev else: if a[k][j]!=p[prev]: return "NO" prev=-1*prev if a[i][j]=="W": prev=1 for k in range(j-1,-1,-1): if a[i][k]==".": a[i][k] =p[prev] prev=-1*prev else: if a[i][k]!=p[prev]: return "NO" prev=-1*prev prev=1 for k in range(j+1,m): if a[i][k]==".": a[i][k] =p[prev] prev=-1*prev else: if a[i][k]!=p[prev]: return "NO" prev=-1*prev prev=1 for k in range(i-1,-1,-1): if a[k][j]==".": a[k][j] =p[prev] prev=-1*prev else: if a[k][j]!=p[prev]: return "NO" prev=-1*prev prev=1 for k in range(i+1,n): if a[k][j]==".": a[k][j] =p[prev] prev=-1*prev else: if a[k][j]!=p[prev]: return "NO" prev=-1*prev return "YES" for _ in range(int(input())): # n=int(input()) # a=map(int,input().split()) p=[0,"R","W"] a=[] n,m=map(int,input().split()) for i in range(n): a.append(list(input())) flag=0 index=-1 for i in range(n): for j in range(m): if a[i][j]=="R" or a[i][j]=="W": x=i;y=j flag=1 break ans=[""]*(n) ans1=[""]*(n) for i in range(n): if m<2: if i%2: ans[i]="R" else: ans[i]="W" else: if i%2: ans[i]="RW"*(m//2)+"R"*(m%2) else: ans[i]="WR"*(m//2)+"W"*(m%2) for i in range(n): if m<2: if i%2: ans1[i]="W" else: ans1[i]="R" else: if i%2==0: ans1[i]="RW"*(m//2)+"R"*(m%2) else: ans1[i]="WR"*(m//2)+"W"*(m%2) # print(ans1) if flag: for i in range(n): if flag==2: break for j in range(m): if a[i][j]==ans[i][j] or a[i][j]==".": continue else: flag=2 break if flag==1: print("YES") for i in ans: print(''.join(i)) else: flag=1 for i in range(n): if flag==2: break for j in range(m): if a[i][j]==ans1[i][j] or a[i][j]==".": continue else: flag=2 break if flag==1: print("YES") for i in ans1: print(''.join(i)) else: print("NO") else: print("YES") for i in ans: print(''.join(i)) ```
output
1
83,645
7
167,291
Provide tags and a correct Python 3 solution for this coding contest problem. 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.
instruction
0
83,646
7
167,292
Tags: brute force, implementation Correct Solution: ``` def solve(): nm = list(map(int, input().split())) r = nm[0] c = nm[1] matrix = [] for i in range(r): row = list(input()) matrix.append(row) first = None for i in range(r): if(first): break for j in range(c): if(matrix[i][j] == '.'): continue if(matrix[i][j] == 'R'): if((j % 2 + i % 2) == 1): first = 'W' else: first = 'R' break if(matrix[i][j] == 'W'): if((j % 2 + i % 2) == 1): first = 'R' else: first = 'W' break if(first == 'R'): for i in range(r): for j in range(c): if(matrix[i][j] == '.'): continue if(matrix[i][j] == 'R'): if((i % 2 + j % 2) == 1): print("NO") return if(matrix[i][j] == 'W'): if((i % 2 + j % 2) != 1): print("NO") return if(first == 'W'): for i in range(r): for j in range(c): if(matrix[i][j] == '.'): continue if(matrix[i][j] == 'W'): if((i % 2 + j % 2) == 1): print("NO") return if(matrix[i][j] == 'R'): if((i % 2 + j % 2) != 1): print("NO") return print("YES") if(not first or first == 'R'): for i in range(r): for j in range(c): if((i % 2 + j % 2) == 1): print("W", end = "") else: print("R", end = "") print() else: for i in range(r): for j in range(c): if((i % 2 + j % 2) == 1): print("R", end = "") else: print("W", end = "") print() return t = int(input()) for i in range(t): solve() ```
output
1
83,646
7
167,293
Provide tags and a correct Python 3 solution for this coding contest problem. 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.
instruction
0
83,647
7
167,294
Tags: brute force, implementation Correct Solution: ``` for _ in range(int(input())): n,m = map(int,input().split()) matrix = [[x for x in input()] for _ in range(n)] r = c = -1 for i in range(n): for j in range(m): if matrix[i][j] == 'R': r,c = i,j break elif matrix[i][j] == 'W': r,c = i,j break first = 'W' flag = False if r >= 0: if c % 2 == 0: first = matrix[r][c] else: first = 'R' if matrix[r][c] == 'W' else 'W' if r % 2 != 0: first = 'R' if first == 'W' else 'W' for i in range(n): for j in range(m): if matrix[i][j] == first or matrix[i][j] == '.': matrix[i][j] = first first = 'W' if first == 'R' else 'R' else: flag = True break first = 'W' if matrix[i][0] == 'R' else 'R' if flag:print('NO') else: print("YES") for i in matrix: print("".join(i)) ```
output
1
83,647
7
167,295
Provide tags and a correct Python 3 solution for this coding contest problem. 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.
instruction
0
83,648
7
167,296
Tags: brute force, implementation Correct Solution: ``` def solve(): n, m = map(int, input().split()) case = -1 grid = [] for i in range(n): grid.append(input()) for i in range(n): s = grid[i] for j in range(m): if s[j] == 'R': if case >= 0 and case != (i+j) % 2: return False case = (i+j) % 2 elif s[j] == 'W': if case >= 0 and case != (i+j+1) % 2: return False case = (i+j+1) % 2 one = 'RW' * (m//2) two = 'WR' * (m//2) if m & 1: one += 'R' two += 'W' if case == -1: case = 0 ans = [] for i in range(n): if i % 2 == case: ans.append(one) else: ans.append(two) return ans T = int(input()) for i in range(T): temp = solve() if temp: print('yes') print('\n'.join(temp)) else: print('no') ```
output
1
83,648
7
167,297
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: ``` t=int(input()) for i in range(t): n, m=map(int, input().split()) ss=['', ''] for i in range(m): if i%2==0: ss[0]+='R' ss[1]+='W' else: ss[0]+='W' ss[1]+='R' fl1=True fl2=True ans='' for j in range(n): s=input() for i in range(m): if s[i]!='.': if fl1 and ss[j%2][i]!=s[i]: fl1=False if fl2 and ss[1-j%2][i]!=s[i]: fl2=False if fl1: print("YES") for j in range(n): print(ss[j%2]) elif fl2: print("YES") for j in range(n): print(ss[1-j%2]) else: print("NO") ```
instruction
0
83,649
7
167,298
Yes
output
1
83,649
7
167,299
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: ``` # __ __ __ # _________ ____/ /__ ____/ /_______ ____ _____ ___ ___ _____ ____/ /___ _ # / ___/ __ \/ __ / _ \/ __ / ___/ _ \/ __ `/ __ `__ \/ _ \/ ___// __ / __ `/ # / /__/ /_/ / /_/ / __/ /_/ / / / __/ /_/ / / / / / / __/ / / /_/ / /_/ / # \___/\____/\__,_/\___/\__,_/_/ \___/\__,_/_/ /_/ /_/\___/_/____\__,_/\__, / # /_____/ /____/ from sys import * '''sys.stdin = open('input.txt', 'r') sys.stdout = open('output.txt', 'w') ''' from collections import defaultdict as dd from math import * from bisect import * #sys.setrecursionlimit(10 ** 8) def sinp(): return input() def inp(): return int(sinp()) def minp(): return map(int, sinp().split()) def linp(): return list(minp()) def strl(): return list(sinp()) def pr(x): print(x) mod = int(1e9+7) for _ in range(inp()): n, m = minp() grid = [list(sinp()) for i in range(n)] temp1 = [] temp2 = [] for i in range(m): if i % 2 == 0: temp1.append('R') temp2.append('W') else: temp2.append('R') temp1.append('W') grid1 = [] grid2 = [] for i in range(n): if not(i & 1): grid1.append(temp1) grid2.append(temp2) else: grid2.append(temp1) grid1.append(temp2) i = 0 f = False while i < n and not f: for j in range(m): if grid[i][j] != '.' and grid[i][j] != grid2[i][j]: f = True break i += 1 if not f: pr('YES') for i in grid2: print(*i, sep='') continue f = False i = 0 while i < n and not f: for j in range(m): if grid[i][j] != '.' and grid[i][j] != grid1[i][j]: f = True break i += 1 if not f: pr('YES') for i in grid1: print(*i, sep='') continue pr('NO') ```
instruction
0
83,650
7
167,300
Yes
output
1
83,650
7
167,301
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 bisect from math import * for _ in range(int(input())): n,m=map(int,input().split()) mat=[] for i in range(n): row=input() mat.append(row) #print(mat) m1=[] for i in range(n): row="" for j in range(m): if j&1: if i&1: row+="W" else: row+="R" else: if i&1: row+="R" else: row+="W" m1.append(row) m2=[] for i in range(n): row="" for j in range(m): if j&1: if i&1: row+="R" else: row+="W" else: if i&1: row+="W" else: row+="R" m2.append(row) flagR=False flagW=False for i in range(n): for j in range(m): if mat[i][j]!=".": if mat[i][j]==m1[i][j]: flagR=True elif mat[i][j]==m2[i][j]: flagW=True if flagR and flagW: break if flagW and flagR: print("NO") else: print("YES") if flagR and not flagW: for i in m1: print(i) elif flagW and not flagR: for i in m2: print(i) else: for i in m1: print(i) ```
instruction
0
83,651
7
167,302
Yes
output
1
83,651
7
167,303
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 math t = int(input()) for _ in range(t): n, m = map(int,input().split()) arr = [] for i in range(n): arr.append(input()) st = "" for i in range(m): if i%2==0: st+="R" else: st+="W" st1 = st[1:] if m%2==0: st1+="R" else: st1+="W" isst = True for i in range(n): for j in range(m): if arr[i][j]==".": continue if i%2==0: if arr[i][j]!=st[j]: isst = False break else: if arr[i][j]!=st1[j]: isst = False break isst1 = True for i in range(n): for j in range(m): if arr[i][j]==".": continue if i%2!=0: if arr[i][j]!=st[j]: isst1 = False break else: if arr[i][j]!=st1[j]: isst1 = False break if not (isst1 or isst): print("NO") else: print("YES") if isst: for i in range(n): if i%2==0: print(st) else: print(st1) else: for i in range(n): if i%2!=0: print(st) else: print(st1) #print("generated st",sub) ```
instruction
0
83,652
7
167,304
Yes
output
1
83,652
7
167,305
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: ``` t=int(input()) while(t): t=t-1 n,m=map(int,input().split()) flag=True ans=[] for i in range(n): s=list(input()) if(i==0): for i in range(m): if(s[i]=='R'): if(i%2==0): ev='R' od='W' else: od='R' ev='W' break elif(s[i]=='W'): if(i%2==0): od='R' ev='W' else: ev='R' od='W' break else: pass for j in range(m): if(s[j]=='R'): if(j%2==0): if(s[j]!=ev): flag=False else: if(s[j]!=od): flag=False elif(s[j]=='W'): if(j%2==0): if(s[j]!=ev): flag=False else: if(s[j]!=od): flag=False else: if(j%2==0): s[j]=ev else: s[j]=od ans.append(s) od,ev=ev,od if flag: print("YES") for i in range(n): print("".join(ans[i])) else: print("NO") ```
instruction
0
83,653
7
167,306
No
output
1
83,653
7
167,307