message stringlengths 2 28.7k | message_type stringclasses 2 values | message_id int64 0 1 | conversation_id int64 21 109k | cluster float64 7 7 | __index_level_0__ int64 42 217k |
|---|---|---|---|---|---|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Anatoly lives in the university dorm as many other students do. As you know, cockroaches are also living there together with students. Cockroaches might be of two colors: black and red. There are n cockroaches living in Anatoly's room.
Anatoly just made all his cockroaches to form a single line. As he is a perfectionist, he would like the colors of cockroaches in the line to alternate. He has a can of black paint and a can of red paint. In one turn he can either swap any two cockroaches, or take any single cockroach and change it's color.
Help Anatoly find out the minimum number of turns he needs to make the colors of cockroaches in the line alternate.
Input
The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — the number of cockroaches.
The second line contains a string of length n, consisting of characters 'b' and 'r' that denote black cockroach and red cockroach respectively.
Output
Print one integer — the minimum number of moves Anatoly has to perform in order to make the colors of cockroaches in the line to alternate.
Examples
Input
5
rbbrr
Output
1
Input
5
bbbbb
Output
2
Input
3
rbr
Output
0
Note
In the first sample, Anatoly has to swap third and fourth cockroaches. He needs 1 turn to do this.
In the second sample, the optimum answer is to paint the second and the fourth cockroaches red. This requires 2 turns.
In the third sample, the colors of cockroaches in the line are alternating already, thus the answer is 0.
Submitted Solution:
```
n=int(input())
s=input()
a,b,c,d=0,0,0,0
for i in range(n):
if(s[i]=='r' and i%2==0):
a=a+1
elif(s[i]=='b' and i%2==1):
b=b+1
elif(s[i]=='r' and i%2==1):
c=c+1
elif(s[i]=='b' and i%2==0):
d=d+1
print(min(max(a,b),max(c,d)))
``` | instruction | 0 | 7,166 | 7 | 14,332 |
Yes | output | 1 | 7,166 | 7 | 14,333 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Anatoly lives in the university dorm as many other students do. As you know, cockroaches are also living there together with students. Cockroaches might be of two colors: black and red. There are n cockroaches living in Anatoly's room.
Anatoly just made all his cockroaches to form a single line. As he is a perfectionist, he would like the colors of cockroaches in the line to alternate. He has a can of black paint and a can of red paint. In one turn he can either swap any two cockroaches, or take any single cockroach and change it's color.
Help Anatoly find out the minimum number of turns he needs to make the colors of cockroaches in the line alternate.
Input
The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — the number of cockroaches.
The second line contains a string of length n, consisting of characters 'b' and 'r' that denote black cockroach and red cockroach respectively.
Output
Print one integer — the minimum number of moves Anatoly has to perform in order to make the colors of cockroaches in the line to alternate.
Examples
Input
5
rbbrr
Output
1
Input
5
bbbbb
Output
2
Input
3
rbr
Output
0
Note
In the first sample, Anatoly has to swap third and fourth cockroaches. He needs 1 turn to do this.
In the second sample, the optimum answer is to paint the second and the fourth cockroaches red. This requires 2 turns.
In the third sample, the colors of cockroaches in the line are alternating already, thus the answer is 0.
Submitted Solution:
```
def miss(st, c):
r = 0
for i in range(0, n, 2):
if st[i] != c[0]:
r += 1
b = 0
for i in range(1, n, 2):
if st[i] != c[1]:
b += 1
return max(r, b)
n = int(input())
s = input()
print(min(miss(s, 'rb'), miss(s, 'br')))
``` | instruction | 0 | 7,167 | 7 | 14,334 |
Yes | output | 1 | 7,167 | 7 | 14,335 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Anatoly lives in the university dorm as many other students do. As you know, cockroaches are also living there together with students. Cockroaches might be of two colors: black and red. There are n cockroaches living in Anatoly's room.
Anatoly just made all his cockroaches to form a single line. As he is a perfectionist, he would like the colors of cockroaches in the line to alternate. He has a can of black paint and a can of red paint. In one turn he can either swap any two cockroaches, or take any single cockroach and change it's color.
Help Anatoly find out the minimum number of turns he needs to make the colors of cockroaches in the line alternate.
Input
The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — the number of cockroaches.
The second line contains a string of length n, consisting of characters 'b' and 'r' that denote black cockroach and red cockroach respectively.
Output
Print one integer — the minimum number of moves Anatoly has to perform in order to make the colors of cockroaches in the line to alternate.
Examples
Input
5
rbbrr
Output
1
Input
5
bbbbb
Output
2
Input
3
rbr
Output
0
Note
In the first sample, Anatoly has to swap third and fourth cockroaches. He needs 1 turn to do this.
In the second sample, the optimum answer is to paint the second and the fourth cockroaches red. This requires 2 turns.
In the third sample, the colors of cockroaches in the line are alternating already, thus the answer is 0.
Submitted Solution:
```
n = int(input())
a = input()
p1 = 0
p2 = 0
for i in range(n):
if i % 2 and a[i] != 'r':
p1 += 1
if not i % 2 and a[i] != 'b':
p2 += 1
m1 = max(p1, p2)
p1 = 0
p2 = 0
for i in range(n):
if i % 2 and a[i] != 'b':
p1 += 1
if not i % 2 and a[i] != 'r':
p2 += 1
m2 = max(p1, p2)
print(min(m1, m2))
``` | instruction | 0 | 7,168 | 7 | 14,336 |
Yes | output | 1 | 7,168 | 7 | 14,337 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Anatoly lives in the university dorm as many other students do. As you know, cockroaches are also living there together with students. Cockroaches might be of two colors: black and red. There are n cockroaches living in Anatoly's room.
Anatoly just made all his cockroaches to form a single line. As he is a perfectionist, he would like the colors of cockroaches in the line to alternate. He has a can of black paint and a can of red paint. In one turn he can either swap any two cockroaches, or take any single cockroach and change it's color.
Help Anatoly find out the minimum number of turns he needs to make the colors of cockroaches in the line alternate.
Input
The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — the number of cockroaches.
The second line contains a string of length n, consisting of characters 'b' and 'r' that denote black cockroach and red cockroach respectively.
Output
Print one integer — the minimum number of moves Anatoly has to perform in order to make the colors of cockroaches in the line to alternate.
Examples
Input
5
rbbrr
Output
1
Input
5
bbbbb
Output
2
Input
3
rbr
Output
0
Note
In the first sample, Anatoly has to swap third and fourth cockroaches. He needs 1 turn to do this.
In the second sample, the optimum answer is to paint the second and the fourth cockroaches red. This requires 2 turns.
In the third sample, the colors of cockroaches in the line are alternating already, thus the answer is 0.
Submitted Solution:
```
import math
x = int(input())
a = list(input())
def getMovesCount(a):
if len(a) == 2 and a[0] == a[1]:
return 1
r = a.count('r')
b = a.count('b')
k = {'r': 'b', 'b': 'r'}
if abs(r - b) <= 1: # rozdiel v pocte medzi cervenymi a ciernymi udava pocet prefarbeni
# zisti pocet nespravne umiestnenych/2
ma_ist = 'b'
result = 0
for i in range(len(a)):
if a[i] != ma_ist:
result += 1
# print(i)
ma_ist = k[ma_ist]
ma_ist = 'r'
result2 = 0
for i in range(len(a)):
if a[i] != ma_ist:
result2 += 1
# print(i)
ma_ist = k[ma_ist]
if result < result2:
return math.ceil(result/2)
return math.ceil(result2/2)
# todo
ma_ist = 'b'
resultp = 0
for i in range(len(a)):
if a[i] != ma_ist:
resultp += 1
ma_ist = k[ma_ist]
maxp = (max(r, b) - resultp)//2
ma_ist = 'r'
resultd = 0
for i in range(len(a)):
if a[i] != ma_ist:
resultd += 1
ma_ist = k[ma_ist]
maxd = (max(r, b) - resultd)//2
if maxp < maxd:
return resultp//2 + maxp
return resultd//2 + maxd
# print(getMovesCount(list('rrbrbrbrb')))
print(getMovesCount(a))
``` | instruction | 0 | 7,169 | 7 | 14,338 |
No | output | 1 | 7,169 | 7 | 14,339 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Anatoly lives in the university dorm as many other students do. As you know, cockroaches are also living there together with students. Cockroaches might be of two colors: black and red. There are n cockroaches living in Anatoly's room.
Anatoly just made all his cockroaches to form a single line. As he is a perfectionist, he would like the colors of cockroaches in the line to alternate. He has a can of black paint and a can of red paint. In one turn he can either swap any two cockroaches, or take any single cockroach and change it's color.
Help Anatoly find out the minimum number of turns he needs to make the colors of cockroaches in the line alternate.
Input
The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — the number of cockroaches.
The second line contains a string of length n, consisting of characters 'b' and 'r' that denote black cockroach and red cockroach respectively.
Output
Print one integer — the minimum number of moves Anatoly has to perform in order to make the colors of cockroaches in the line to alternate.
Examples
Input
5
rbbrr
Output
1
Input
5
bbbbb
Output
2
Input
3
rbr
Output
0
Note
In the first sample, Anatoly has to swap third and fourth cockroaches. He needs 1 turn to do this.
In the second sample, the optimum answer is to paint the second and the fourth cockroaches red. This requires 2 turns.
In the third sample, the colors of cockroaches in the line are alternating already, thus the answer is 0.
Submitted Solution:
```
def dist(s, choice):
res = 0
for i in range(len(s)):
if s[i] == choice[i]:
continue
elif i + 1 < len(s) and choice[i] == s[i + 1] and choice[i + 1] == s[i]:
s[i + 1] = s[i]
res += 1
else:
res += 1
return res
if __name__ == '__main__':
n = int(input())
a = list(input())
choice_one = []
choice_two = []
for i in range(len(a)):
if i % 2 == 0:
choice_one.append('r')
choice_two.append('b')
else:
choice_one.append('b')
choice_two.append('r')
print(min(dist(a, choice_one), dist(a, choice_two)))
``` | instruction | 0 | 7,170 | 7 | 14,340 |
No | output | 1 | 7,170 | 7 | 14,341 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Anatoly lives in the university dorm as many other students do. As you know, cockroaches are also living there together with students. Cockroaches might be of two colors: black and red. There are n cockroaches living in Anatoly's room.
Anatoly just made all his cockroaches to form a single line. As he is a perfectionist, he would like the colors of cockroaches in the line to alternate. He has a can of black paint and a can of red paint. In one turn he can either swap any two cockroaches, or take any single cockroach and change it's color.
Help Anatoly find out the minimum number of turns he needs to make the colors of cockroaches in the line alternate.
Input
The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — the number of cockroaches.
The second line contains a string of length n, consisting of characters 'b' and 'r' that denote black cockroach and red cockroach respectively.
Output
Print one integer — the minimum number of moves Anatoly has to perform in order to make the colors of cockroaches in the line to alternate.
Examples
Input
5
rbbrr
Output
1
Input
5
bbbbb
Output
2
Input
3
rbr
Output
0
Note
In the first sample, Anatoly has to swap third and fourth cockroaches. He needs 1 turn to do this.
In the second sample, the optimum answer is to paint the second and the fourth cockroaches red. This requires 2 turns.
In the third sample, the colors of cockroaches in the line are alternating already, thus the answer is 0.
Submitted Solution:
```
n=int(input())
ss=input()
s=list(ss)
c=0
o=0
for i in range(1,n):
if s[i]==s[i-1]:
if s[i]=='b':
s[i]='r'
else:
s[i]='b'
if c:
c=0
else:
c=1
o+=1
else:
c=0
o1=0
s=list(ss)
t=s[0]
s[0]=s[1]
s[1]=t
for i in range(1,n):
if s[i]==s[i-1]:
if s[i]=='b':
s[i]='r'
else:
s[i]='b'
if c:
c=0
else:
c=1
o1+=1
else:
c=0
o=min(o,o1)
print(o)
``` | instruction | 0 | 7,171 | 7 | 14,342 |
No | output | 1 | 7,171 | 7 | 14,343 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Anatoly lives in the university dorm as many other students do. As you know, cockroaches are also living there together with students. Cockroaches might be of two colors: black and red. There are n cockroaches living in Anatoly's room.
Anatoly just made all his cockroaches to form a single line. As he is a perfectionist, he would like the colors of cockroaches in the line to alternate. He has a can of black paint and a can of red paint. In one turn he can either swap any two cockroaches, or take any single cockroach and change it's color.
Help Anatoly find out the minimum number of turns he needs to make the colors of cockroaches in the line alternate.
Input
The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — the number of cockroaches.
The second line contains a string of length n, consisting of characters 'b' and 'r' that denote black cockroach and red cockroach respectively.
Output
Print one integer — the minimum number of moves Anatoly has to perform in order to make the colors of cockroaches in the line to alternate.
Examples
Input
5
rbbrr
Output
1
Input
5
bbbbb
Output
2
Input
3
rbr
Output
0
Note
In the first sample, Anatoly has to swap third and fourth cockroaches. He needs 1 turn to do this.
In the second sample, the optimum answer is to paint the second and the fourth cockroaches red. This requires 2 turns.
In the third sample, the colors of cockroaches in the line are alternating already, thus the answer is 0.
Submitted Solution:
```
n=int(input())
S=input()
p=S[0]
k=0
for i in range(1,n-1) :
if S[i]==p :
if S[i+1]==p :
k=k+1
if p=='r' :
p='b'
else :
p='r'
else :
k=k+1
else :
p=S[i]
print(k)
``` | instruction | 0 | 7,172 | 7 | 14,344 |
No | output | 1 | 7,172 | 7 | 14,345 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There is a rectangular grid of n rows of m initially-white cells each.
Arkady performed a certain number (possibly zero) of operations on it. In the i-th operation, a non-empty subset of rows Ri and a non-empty subset of columns Ci are chosen. For each row r in Ri and each column c in Ci, the intersection of row r and column c is coloured black.
There's another constraint: a row or a column can only be chosen at most once among all operations. In other words, it means that no pair of (i, j) (i < j) exists such that <image> or <image>, where <image> denotes intersection of sets, and <image> denotes the empty set.
You are to determine whether a valid sequence of operations exists that produces a given final grid.
Input
The first line contains two space-separated integers n and m (1 ≤ n, m ≤ 50) — the number of rows and columns of the grid, respectively.
Each of the following n lines contains a string of m characters, each being either '.' (denoting a white cell) or '#' (denoting a black cell), representing the desired setup.
Output
If the given grid can be achieved by any valid sequence of operations, output "Yes"; otherwise output "No" (both without quotes).
You can print each character in any case (upper or lower).
Examples
Input
5 8
.#.#..#.
.....#..
.#.#..#.
#.#....#
.....#..
Output
Yes
Input
5 5
..#..
..#..
#####
..#..
..#..
Output
No
Input
5 9
........#
#........
..##.#...
.......#.
....#.#.#
Output
No
Note
For the first example, the desired setup can be produced by 3 operations, as is shown below.
<image>
For the second example, the desired setup cannot be produced, since in order to colour the center row, the third row and all columns must be selected in one operation, but after that no column can be selected again, hence it won't be possible to colour the other cells in the center column. | instruction | 0 | 7,233 | 7 | 14,466 |
Tags: greedy, implementation
Correct Solution:
```
n,m=map(int,input().split())
t=set(input()for _ in [0]*n)
print(['No','Yes'][all(sum(c=='#'for c in s)<2for s in zip(*t))])
``` | output | 1 | 7,233 | 7 | 14,467 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There is a rectangular grid of n rows of m initially-white cells each.
Arkady performed a certain number (possibly zero) of operations on it. In the i-th operation, a non-empty subset of rows Ri and a non-empty subset of columns Ci are chosen. For each row r in Ri and each column c in Ci, the intersection of row r and column c is coloured black.
There's another constraint: a row or a column can only be chosen at most once among all operations. In other words, it means that no pair of (i, j) (i < j) exists such that <image> or <image>, where <image> denotes intersection of sets, and <image> denotes the empty set.
You are to determine whether a valid sequence of operations exists that produces a given final grid.
Input
The first line contains two space-separated integers n and m (1 ≤ n, m ≤ 50) — the number of rows and columns of the grid, respectively.
Each of the following n lines contains a string of m characters, each being either '.' (denoting a white cell) or '#' (denoting a black cell), representing the desired setup.
Output
If the given grid can be achieved by any valid sequence of operations, output "Yes"; otherwise output "No" (both without quotes).
You can print each character in any case (upper or lower).
Examples
Input
5 8
.#.#..#.
.....#..
.#.#..#.
#.#....#
.....#..
Output
Yes
Input
5 5
..#..
..#..
#####
..#..
..#..
Output
No
Input
5 9
........#
#........
..##.#...
.......#.
....#.#.#
Output
No
Note
For the first example, the desired setup can be produced by 3 operations, as is shown below.
<image>
For the second example, the desired setup cannot be produced, since in order to colour the center row, the third row and all columns must be selected in one operation, but after that no column can be selected again, hence it won't be possible to colour the other cells in the center column. | instruction | 0 | 7,234 | 7 | 14,468 |
Tags: greedy, implementation
Correct Solution:
```
n,m = map(int, input().split())
r = set()
c = set()
ss=[]
for i in range(n):
s = input()
ss.append(s)
for i in range(n):
s1 = set()
for j in range(m):
if ss[i][j] == '#':
s1.add(j)
for j in range(n):
s2 = set()
for k in range(m):
if ss[j][k] == '#':
s2.add(k)
isi=len(s1.intersection(s2))
if isi != 0 and (isi != len(s1) or isi != len(s2)):
print('No')
exit()
for i in range(m):
s1 = set()
for j in range(n):
if ss[j][i] == '#':
s1.add(j)
for j in range(m):
s2 = set()
for k in range(n):
if ss[k][j] == '#':
s2.add(k)
isi=len(s1.intersection(s2))
if isi != 0 and (isi != len(s1) or isi != len(s2)):
print('No')
exit()
print('Yes')
``` | output | 1 | 7,234 | 7 | 14,469 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There is a rectangular grid of n rows of m initially-white cells each.
Arkady performed a certain number (possibly zero) of operations on it. In the i-th operation, a non-empty subset of rows Ri and a non-empty subset of columns Ci are chosen. For each row r in Ri and each column c in Ci, the intersection of row r and column c is coloured black.
There's another constraint: a row or a column can only be chosen at most once among all operations. In other words, it means that no pair of (i, j) (i < j) exists such that <image> or <image>, where <image> denotes intersection of sets, and <image> denotes the empty set.
You are to determine whether a valid sequence of operations exists that produces a given final grid.
Input
The first line contains two space-separated integers n and m (1 ≤ n, m ≤ 50) — the number of rows and columns of the grid, respectively.
Each of the following n lines contains a string of m characters, each being either '.' (denoting a white cell) or '#' (denoting a black cell), representing the desired setup.
Output
If the given grid can be achieved by any valid sequence of operations, output "Yes"; otherwise output "No" (both without quotes).
You can print each character in any case (upper or lower).
Examples
Input
5 8
.#.#..#.
.....#..
.#.#..#.
#.#....#
.....#..
Output
Yes
Input
5 5
..#..
..#..
#####
..#..
..#..
Output
No
Input
5 9
........#
#........
..##.#...
.......#.
....#.#.#
Output
No
Note
For the first example, the desired setup can be produced by 3 operations, as is shown below.
<image>
For the second example, the desired setup cannot be produced, since in order to colour the center row, the third row and all columns must be selected in one operation, but after that no column can be selected again, hence it won't be possible to colour the other cells in the center column. | instruction | 0 | 7,235 | 7 | 14,470 |
Tags: greedy, implementation
Correct Solution:
```
# python3
def readline(): return tuple(map(int, input().split()))
def main():
n, m = readline()
unique_rows = list()
first_occ = [None] * m
while n:
n -= 1
row = input()
saved = None
for (i, char) in enumerate(row):
if char == '#':
if first_occ[i] is not None:
if row != unique_rows[first_occ[i]]:
return False
else:
break
else:
if saved is None:
unique_rows.append(row)
saved = len(unique_rows) - 1
first_occ[i] = saved
else:
assert char == '.'
return True
print("Yes" if main() else "No")
``` | output | 1 | 7,235 | 7 | 14,471 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There is a rectangular grid of n rows of m initially-white cells each.
Arkady performed a certain number (possibly zero) of operations on it. In the i-th operation, a non-empty subset of rows Ri and a non-empty subset of columns Ci are chosen. For each row r in Ri and each column c in Ci, the intersection of row r and column c is coloured black.
There's another constraint: a row or a column can only be chosen at most once among all operations. In other words, it means that no pair of (i, j) (i < j) exists such that <image> or <image>, where <image> denotes intersection of sets, and <image> denotes the empty set.
You are to determine whether a valid sequence of operations exists that produces a given final grid.
Input
The first line contains two space-separated integers n and m (1 ≤ n, m ≤ 50) — the number of rows and columns of the grid, respectively.
Each of the following n lines contains a string of m characters, each being either '.' (denoting a white cell) or '#' (denoting a black cell), representing the desired setup.
Output
If the given grid can be achieved by any valid sequence of operations, output "Yes"; otherwise output "No" (both without quotes).
You can print each character in any case (upper or lower).
Examples
Input
5 8
.#.#..#.
.....#..
.#.#..#.
#.#....#
.....#..
Output
Yes
Input
5 5
..#..
..#..
#####
..#..
..#..
Output
No
Input
5 9
........#
#........
..##.#...
.......#.
....#.#.#
Output
No
Note
For the first example, the desired setup can be produced by 3 operations, as is shown below.
<image>
For the second example, the desired setup cannot be produced, since in order to colour the center row, the third row and all columns must be selected in one operation, but after that no column can be selected again, hence it won't be possible to colour the other cells in the center column. | instruction | 0 | 7,236 | 7 | 14,472 |
Tags: greedy, implementation
Correct Solution:
```
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
class CDisjointSet(object):
def __init__(self):
self.leader = {} # maps a member to the group's leader
self.group = {} # maps a group leader to the group (which is a set)
def Add(self, a, b):
leadera = self.leader.get(a)
leaderb = self.leader.get(b)
if leadera is not None:
if leaderb is not None:
if leadera == leaderb: return # nothing to do
groupa = self.group[leadera]
groupb = self.group[leaderb]
if len(groupa) < len(groupb):
a, leadera, groupa, b, leaderb, groupb = b, leaderb, groupb, a, leadera, groupa
groupa |= groupb
del self.group[leaderb]
for k in groupb:
self.leader[k] = leadera
else:
self.group[leadera].add(b)
self.leader[b] = leadera
else:
if leaderb is not None:
self.group[leaderb].add(a)
self.leader[a] = leaderb
else:
self.leader[a] = self.leader[b] = a
self.group[a] = set([a, b])
def Judge():
#[1]
ds = CDisjointSet()
n, m = map(int, input().split())
arr = list()
for i in range(n):
arr.append(input())
for i in range(n):
for j in range(m):
if arr[i][j] == '#':
ds.Add(i+1, 101+j)
#[2]
for vs in ds.group.values():
rs = list()
cs = list()
for v in vs:
if v < 100:
rs.append(v-1)
else:
cs.append(v-101)
for i in rs:
for j in range(m):
if j in cs and arr[i][j] == '.':
return False
if j not in cs and arr[i][j] == '#':
return False
#[3]
return True
print('Yes') if Judge() else print('No')
``` | output | 1 | 7,236 | 7 | 14,473 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There is a rectangular grid of n rows of m initially-white cells each.
Arkady performed a certain number (possibly zero) of operations on it. In the i-th operation, a non-empty subset of rows Ri and a non-empty subset of columns Ci are chosen. For each row r in Ri and each column c in Ci, the intersection of row r and column c is coloured black.
There's another constraint: a row or a column can only be chosen at most once among all operations. In other words, it means that no pair of (i, j) (i < j) exists such that <image> or <image>, where <image> denotes intersection of sets, and <image> denotes the empty set.
You are to determine whether a valid sequence of operations exists that produces a given final grid.
Input
The first line contains two space-separated integers n and m (1 ≤ n, m ≤ 50) — the number of rows and columns of the grid, respectively.
Each of the following n lines contains a string of m characters, each being either '.' (denoting a white cell) or '#' (denoting a black cell), representing the desired setup.
Output
If the given grid can be achieved by any valid sequence of operations, output "Yes"; otherwise output "No" (both without quotes).
You can print each character in any case (upper or lower).
Examples
Input
5 8
.#.#..#.
.....#..
.#.#..#.
#.#....#
.....#..
Output
Yes
Input
5 5
..#..
..#..
#####
..#..
..#..
Output
No
Input
5 9
........#
#........
..##.#...
.......#.
....#.#.#
Output
No
Note
For the first example, the desired setup can be produced by 3 operations, as is shown below.
<image>
For the second example, the desired setup cannot be produced, since in order to colour the center row, the third row and all columns must be selected in one operation, but after that no column can be selected again, hence it won't be possible to colour the other cells in the center column. | instruction | 0 | 7,237 | 7 | 14,474 |
Tags: greedy, implementation
Correct Solution:
```
t=set(input()for _ in [0]*int(input().split()[0]))
print(['No','Yes'][all(sum(c<'.'for c in s)<2for s in zip(*t))])
# Made By Mostafa_Khaled
``` | output | 1 | 7,237 | 7 | 14,475 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There is a rectangular grid of n rows of m initially-white cells each.
Arkady performed a certain number (possibly zero) of operations on it. In the i-th operation, a non-empty subset of rows Ri and a non-empty subset of columns Ci are chosen. For each row r in Ri and each column c in Ci, the intersection of row r and column c is coloured black.
There's another constraint: a row or a column can only be chosen at most once among all operations. In other words, it means that no pair of (i, j) (i < j) exists such that <image> or <image>, where <image> denotes intersection of sets, and <image> denotes the empty set.
You are to determine whether a valid sequence of operations exists that produces a given final grid.
Input
The first line contains two space-separated integers n and m (1 ≤ n, m ≤ 50) — the number of rows and columns of the grid, respectively.
Each of the following n lines contains a string of m characters, each being either '.' (denoting a white cell) or '#' (denoting a black cell), representing the desired setup.
Output
If the given grid can be achieved by any valid sequence of operations, output "Yes"; otherwise output "No" (both without quotes).
You can print each character in any case (upper or lower).
Examples
Input
5 8
.#.#..#.
.....#..
.#.#..#.
#.#....#
.....#..
Output
Yes
Input
5 5
..#..
..#..
#####
..#..
..#..
Output
No
Input
5 9
........#
#........
..##.#...
.......#.
....#.#.#
Output
No
Note
For the first example, the desired setup can be produced by 3 operations, as is shown below.
<image>
For the second example, the desired setup cannot be produced, since in order to colour the center row, the third row and all columns must be selected in one operation, but after that no column can be selected again, hence it won't be possible to colour the other cells in the center column. | instruction | 0 | 7,238 | 7 | 14,476 |
Tags: greedy, implementation
Correct Solution:
```
n, m = map(int, input().split())
p = [list(input()) for _ in range(n)]
for i in range(n):
column = []
for j in range(m):
if p[i][j] == '#':
column.append(j)
st1 = ''
for pos, el in enumerate(column):
st = ''
for k in range(n):
st += p[k][el]
if pos == 0:
st1 = st
elif st1 != st:
print('No')
break
else:
continue
break
else:
print('Yes')
``` | output | 1 | 7,238 | 7 | 14,477 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There is a rectangular grid of n rows of m initially-white cells each.
Arkady performed a certain number (possibly zero) of operations on it. In the i-th operation, a non-empty subset of rows Ri and a non-empty subset of columns Ci are chosen. For each row r in Ri and each column c in Ci, the intersection of row r and column c is coloured black.
There's another constraint: a row or a column can only be chosen at most once among all operations. In other words, it means that no pair of (i, j) (i < j) exists such that <image> or <image>, where <image> denotes intersection of sets, and <image> denotes the empty set.
You are to determine whether a valid sequence of operations exists that produces a given final grid.
Input
The first line contains two space-separated integers n and m (1 ≤ n, m ≤ 50) — the number of rows and columns of the grid, respectively.
Each of the following n lines contains a string of m characters, each being either '.' (denoting a white cell) or '#' (denoting a black cell), representing the desired setup.
Output
If the given grid can be achieved by any valid sequence of operations, output "Yes"; otherwise output "No" (both without quotes).
You can print each character in any case (upper or lower).
Examples
Input
5 8
.#.#..#.
.....#..
.#.#..#.
#.#....#
.....#..
Output
Yes
Input
5 5
..#..
..#..
#####
..#..
..#..
Output
No
Input
5 9
........#
#........
..##.#...
.......#.
....#.#.#
Output
No
Note
For the first example, the desired setup can be produced by 3 operations, as is shown below.
<image>
For the second example, the desired setup cannot be produced, since in order to colour the center row, the third row and all columns must be selected in one operation, but after that no column can be selected again, hence it won't be possible to colour the other cells in the center column. | instruction | 0 | 7,239 | 7 | 14,478 |
Tags: greedy, implementation
Correct Solution:
```
n,m=map(int, input().split())
a=[]
for i in range(n): a.append(input())
for i in range(n):
for j in range(i+1,n):
eqv, no_inter=True, True
for z in range(m):
if a[i][z]!=a[j][z]: eqv=False
if a[i][z]==a[j][z]=="#": no_inter=False
if eqv==no_inter==False:
print("No")
exit()
print("Yes")
``` | output | 1 | 7,239 | 7 | 14,479 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There is a rectangular grid of n rows of m initially-white cells each.
Arkady performed a certain number (possibly zero) of operations on it. In the i-th operation, a non-empty subset of rows Ri and a non-empty subset of columns Ci are chosen. For each row r in Ri and each column c in Ci, the intersection of row r and column c is coloured black.
There's another constraint: a row or a column can only be chosen at most once among all operations. In other words, it means that no pair of (i, j) (i < j) exists such that <image> or <image>, where <image> denotes intersection of sets, and <image> denotes the empty set.
You are to determine whether a valid sequence of operations exists that produces a given final grid.
Input
The first line contains two space-separated integers n and m (1 ≤ n, m ≤ 50) — the number of rows and columns of the grid, respectively.
Each of the following n lines contains a string of m characters, each being either '.' (denoting a white cell) or '#' (denoting a black cell), representing the desired setup.
Output
If the given grid can be achieved by any valid sequence of operations, output "Yes"; otherwise output "No" (both without quotes).
You can print each character in any case (upper or lower).
Examples
Input
5 8
.#.#..#.
.....#..
.#.#..#.
#.#....#
.....#..
Output
Yes
Input
5 5
..#..
..#..
#####
..#..
..#..
Output
No
Input
5 9
........#
#........
..##.#...
.......#.
....#.#.#
Output
No
Note
For the first example, the desired setup can be produced by 3 operations, as is shown below.
<image>
For the second example, the desired setup cannot be produced, since in order to colour the center row, the third row and all columns must be selected in one operation, but after that no column can be selected again, hence it won't be possible to colour the other cells in the center column. | instruction | 0 | 7,240 | 7 | 14,480 |
Tags: greedy, implementation
Correct Solution:
```
import sys
n, m = [int(i) for i in input().split(" ")]
grid = []
columns_idx = set()
lines_used = set()
for _ in range(n):
line = input()
grid.append(line)
for line in grid:
if line not in lines_used:
lines_used.add(line)
for i,c in enumerate(line):
if c=='#':
if i in columns_idx:
print("No")
sys.exit()
else:
columns_idx.add(i)
print("Yes")
``` | output | 1 | 7,240 | 7 | 14,481 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is a rectangular grid of n rows of m initially-white cells each.
Arkady performed a certain number (possibly zero) of operations on it. In the i-th operation, a non-empty subset of rows Ri and a non-empty subset of columns Ci are chosen. For each row r in Ri and each column c in Ci, the intersection of row r and column c is coloured black.
There's another constraint: a row or a column can only be chosen at most once among all operations. In other words, it means that no pair of (i, j) (i < j) exists such that <image> or <image>, where <image> denotes intersection of sets, and <image> denotes the empty set.
You are to determine whether a valid sequence of operations exists that produces a given final grid.
Input
The first line contains two space-separated integers n and m (1 ≤ n, m ≤ 50) — the number of rows and columns of the grid, respectively.
Each of the following n lines contains a string of m characters, each being either '.' (denoting a white cell) or '#' (denoting a black cell), representing the desired setup.
Output
If the given grid can be achieved by any valid sequence of operations, output "Yes"; otherwise output "No" (both without quotes).
You can print each character in any case (upper or lower).
Examples
Input
5 8
.#.#..#.
.....#..
.#.#..#.
#.#....#
.....#..
Output
Yes
Input
5 5
..#..
..#..
#####
..#..
..#..
Output
No
Input
5 9
........#
#........
..##.#...
.......#.
....#.#.#
Output
No
Note
For the first example, the desired setup can be produced by 3 operations, as is shown below.
<image>
For the second example, the desired setup cannot be produced, since in order to colour the center row, the third row and all columns must be selected in one operation, but after that no column can be selected again, hence it won't be possible to colour the other cells in the center column.
Submitted Solution:
```
import sys
n,m = [int(x) for x in input().split(' ')]
a=[]
for i in range(n):
b=[]
s = input().strip()
for j in range(m):
if s[j]=='#':
b.append(j)
if b not in a:
a.append(b)
c=[0]*m
ans=True
#print(a)
for i in a:
for j in i:
c[j]+=1
if c[j]>1:
ans=False
break
if ans:
print("Yes")
else:
print("No")
``` | instruction | 0 | 7,241 | 7 | 14,482 |
Yes | output | 1 | 7,241 | 7 | 14,483 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is a rectangular grid of n rows of m initially-white cells each.
Arkady performed a certain number (possibly zero) of operations on it. In the i-th operation, a non-empty subset of rows Ri and a non-empty subset of columns Ci are chosen. For each row r in Ri and each column c in Ci, the intersection of row r and column c is coloured black.
There's another constraint: a row or a column can only be chosen at most once among all operations. In other words, it means that no pair of (i, j) (i < j) exists such that <image> or <image>, where <image> denotes intersection of sets, and <image> denotes the empty set.
You are to determine whether a valid sequence of operations exists that produces a given final grid.
Input
The first line contains two space-separated integers n and m (1 ≤ n, m ≤ 50) — the number of rows and columns of the grid, respectively.
Each of the following n lines contains a string of m characters, each being either '.' (denoting a white cell) or '#' (denoting a black cell), representing the desired setup.
Output
If the given grid can be achieved by any valid sequence of operations, output "Yes"; otherwise output "No" (both without quotes).
You can print each character in any case (upper or lower).
Examples
Input
5 8
.#.#..#.
.....#..
.#.#..#.
#.#....#
.....#..
Output
Yes
Input
5 5
..#..
..#..
#####
..#..
..#..
Output
No
Input
5 9
........#
#........
..##.#...
.......#.
....#.#.#
Output
No
Note
For the first example, the desired setup can be produced by 3 operations, as is shown below.
<image>
For the second example, the desired setup cannot be produced, since in order to colour the center row, the third row and all columns must be selected in one operation, but after that no column can be selected again, hence it won't be possible to colour the other cells in the center column.
Submitted Solution:
```
#!/usr/bin/env python3
import sys
[n, m] = map(int, sys.stdin.readline().strip().split())
table = [sys.stdin.readline().strip() for _ in range(n)]
first_to_row = dict()
poss = True
for row in table:
first = row.find('#')
if first in first_to_row:
if first_to_row[first] != row:
poss = False
break
else:
first_to_row[first] = row
if poss:
counts = [False for _ in range(m)]
for row in first_to_row.values():
for i in range(m):
if row[i] == '#':
if counts[i]:
poss = False
break
counts[i] = True
if not poss:
break
if poss:
print ('Yes')
else:
print ('No')
``` | instruction | 0 | 7,242 | 7 | 14,484 |
Yes | output | 1 | 7,242 | 7 | 14,485 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is a rectangular grid of n rows of m initially-white cells each.
Arkady performed a certain number (possibly zero) of operations on it. In the i-th operation, a non-empty subset of rows Ri and a non-empty subset of columns Ci are chosen. For each row r in Ri and each column c in Ci, the intersection of row r and column c is coloured black.
There's another constraint: a row or a column can only be chosen at most once among all operations. In other words, it means that no pair of (i, j) (i < j) exists such that <image> or <image>, where <image> denotes intersection of sets, and <image> denotes the empty set.
You are to determine whether a valid sequence of operations exists that produces a given final grid.
Input
The first line contains two space-separated integers n and m (1 ≤ n, m ≤ 50) — the number of rows and columns of the grid, respectively.
Each of the following n lines contains a string of m characters, each being either '.' (denoting a white cell) or '#' (denoting a black cell), representing the desired setup.
Output
If the given grid can be achieved by any valid sequence of operations, output "Yes"; otherwise output "No" (both without quotes).
You can print each character in any case (upper or lower).
Examples
Input
5 8
.#.#..#.
.....#..
.#.#..#.
#.#....#
.....#..
Output
Yes
Input
5 5
..#..
..#..
#####
..#..
..#..
Output
No
Input
5 9
........#
#........
..##.#...
.......#.
....#.#.#
Output
No
Note
For the first example, the desired setup can be produced by 3 operations, as is shown below.
<image>
For the second example, the desired setup cannot be produced, since in order to colour the center row, the third row and all columns must be selected in one operation, but after that no column can be selected again, hence it won't be possible to colour the other cells in the center column.
Submitted Solution:
```
BLACK, WHITE = "#", "."
n, m = list(map(int, input().split()))
blacks = [{i for i, c in enumerate(input()) if c == BLACK} for i in range(n)]
answer = "Yes"
for i in range(n):
for j in range(i):
if blacks[i] & blacks[j] and blacks[i] != blacks[j]:
answer = "No"
print(answer)
``` | instruction | 0 | 7,243 | 7 | 14,486 |
Yes | output | 1 | 7,243 | 7 | 14,487 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is a rectangular grid of n rows of m initially-white cells each.
Arkady performed a certain number (possibly zero) of operations on it. In the i-th operation, a non-empty subset of rows Ri and a non-empty subset of columns Ci are chosen. For each row r in Ri and each column c in Ci, the intersection of row r and column c is coloured black.
There's another constraint: a row or a column can only be chosen at most once among all operations. In other words, it means that no pair of (i, j) (i < j) exists such that <image> or <image>, where <image> denotes intersection of sets, and <image> denotes the empty set.
You are to determine whether a valid sequence of operations exists that produces a given final grid.
Input
The first line contains two space-separated integers n and m (1 ≤ n, m ≤ 50) — the number of rows and columns of the grid, respectively.
Each of the following n lines contains a string of m characters, each being either '.' (denoting a white cell) or '#' (denoting a black cell), representing the desired setup.
Output
If the given grid can be achieved by any valid sequence of operations, output "Yes"; otherwise output "No" (both without quotes).
You can print each character in any case (upper or lower).
Examples
Input
5 8
.#.#..#.
.....#..
.#.#..#.
#.#....#
.....#..
Output
Yes
Input
5 5
..#..
..#..
#####
..#..
..#..
Output
No
Input
5 9
........#
#........
..##.#...
.......#.
....#.#.#
Output
No
Note
For the first example, the desired setup can be produced by 3 operations, as is shown below.
<image>
For the second example, the desired setup cannot be produced, since in order to colour the center row, the third row and all columns must be selected in one operation, but after that no column can be selected again, hence it won't be possible to colour the other cells in the center column.
Submitted Solution:
```
from itertools import product
n,m=map(int,input().split())
l=[]
satir={i:[] for i in range(n)}
sutun={i:[] for i in range(m)}
for i in range(n):
l.append(list(input()))
g=[["."]*m for _ in range(n)]
for i in range(n):
for a in range(m):
if l[i][a] == "#":
satir[i].append(a)
sutun[a].append(i)
for i in satir:
sa=set()
sa.add(i)
su=set()
for a in satir[i]:
su.add(a)
for k in sutun[a]:
sa.add(k)
res=product(sa,su)
for a,b in res:
g[a][b]="#"
if g==l:
print("Yes")
else:
print("No")
``` | instruction | 0 | 7,244 | 7 | 14,488 |
Yes | output | 1 | 7,244 | 7 | 14,489 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is a rectangular grid of n rows of m initially-white cells each.
Arkady performed a certain number (possibly zero) of operations on it. In the i-th operation, a non-empty subset of rows Ri and a non-empty subset of columns Ci are chosen. For each row r in Ri and each column c in Ci, the intersection of row r and column c is coloured black.
There's another constraint: a row or a column can only be chosen at most once among all operations. In other words, it means that no pair of (i, j) (i < j) exists such that <image> or <image>, where <image> denotes intersection of sets, and <image> denotes the empty set.
You are to determine whether a valid sequence of operations exists that produces a given final grid.
Input
The first line contains two space-separated integers n and m (1 ≤ n, m ≤ 50) — the number of rows and columns of the grid, respectively.
Each of the following n lines contains a string of m characters, each being either '.' (denoting a white cell) or '#' (denoting a black cell), representing the desired setup.
Output
If the given grid can be achieved by any valid sequence of operations, output "Yes"; otherwise output "No" (both without quotes).
You can print each character in any case (upper or lower).
Examples
Input
5 8
.#.#..#.
.....#..
.#.#..#.
#.#....#
.....#..
Output
Yes
Input
5 5
..#..
..#..
#####
..#..
..#..
Output
No
Input
5 9
........#
#........
..##.#...
.......#.
....#.#.#
Output
No
Note
For the first example, the desired setup can be produced by 3 operations, as is shown below.
<image>
For the second example, the desired setup cannot be produced, since in order to colour the center row, the third row and all columns must be selected in one operation, but after that no column can be selected again, hence it won't be possible to colour the other cells in the center column.
Submitted Solution:
```
row, column = map(int,input().strip().split())
rset = set()
cset = set()
flag = True
for i in range(row):
line = input().strip()
if line in rset:
continue
for j in range(column):
if line[j] == '.':
continue
if line[j] in cset:
flag = False
else:
cset.add(line[j])
rset.add(line)
if flag:
print("Yes")
else:
print("No")
``` | instruction | 0 | 7,245 | 7 | 14,490 |
No | output | 1 | 7,245 | 7 | 14,491 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is a rectangular grid of n rows of m initially-white cells each.
Arkady performed a certain number (possibly zero) of operations on it. In the i-th operation, a non-empty subset of rows Ri and a non-empty subset of columns Ci are chosen. For each row r in Ri and each column c in Ci, the intersection of row r and column c is coloured black.
There's another constraint: a row or a column can only be chosen at most once among all operations. In other words, it means that no pair of (i, j) (i < j) exists such that <image> or <image>, where <image> denotes intersection of sets, and <image> denotes the empty set.
You are to determine whether a valid sequence of operations exists that produces a given final grid.
Input
The first line contains two space-separated integers n and m (1 ≤ n, m ≤ 50) — the number of rows and columns of the grid, respectively.
Each of the following n lines contains a string of m characters, each being either '.' (denoting a white cell) or '#' (denoting a black cell), representing the desired setup.
Output
If the given grid can be achieved by any valid sequence of operations, output "Yes"; otherwise output "No" (both without quotes).
You can print each character in any case (upper or lower).
Examples
Input
5 8
.#.#..#.
.....#..
.#.#..#.
#.#....#
.....#..
Output
Yes
Input
5 5
..#..
..#..
#####
..#..
..#..
Output
No
Input
5 9
........#
#........
..##.#...
.......#.
....#.#.#
Output
No
Note
For the first example, the desired setup can be produced by 3 operations, as is shown below.
<image>
For the second example, the desired setup cannot be produced, since in order to colour the center row, the third row and all columns must be selected in one operation, but after that no column can be selected again, hence it won't be possible to colour the other cells in the center column.
Submitted Solution:
```
n, m = list(map(int, input().split()))
rows = []
for i in range(m):
rows.append([])
for i in range(n):
print(rows)
row = input()
indices = [j for j, x in enumerate(row) if x == "#"]
rowcheck = [rows[x] for x in indices]
for j in rowcheck:
if j != rowcheck[0]:
print('NO')
exit()
for j in indices:
rows[j] = indices
print('YES')
``` | instruction | 0 | 7,246 | 7 | 14,492 |
No | output | 1 | 7,246 | 7 | 14,493 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is a rectangular grid of n rows of m initially-white cells each.
Arkady performed a certain number (possibly zero) of operations on it. In the i-th operation, a non-empty subset of rows Ri and a non-empty subset of columns Ci are chosen. For each row r in Ri and each column c in Ci, the intersection of row r and column c is coloured black.
There's another constraint: a row or a column can only be chosen at most once among all operations. In other words, it means that no pair of (i, j) (i < j) exists such that <image> or <image>, where <image> denotes intersection of sets, and <image> denotes the empty set.
You are to determine whether a valid sequence of operations exists that produces a given final grid.
Input
The first line contains two space-separated integers n and m (1 ≤ n, m ≤ 50) — the number of rows and columns of the grid, respectively.
Each of the following n lines contains a string of m characters, each being either '.' (denoting a white cell) or '#' (denoting a black cell), representing the desired setup.
Output
If the given grid can be achieved by any valid sequence of operations, output "Yes"; otherwise output "No" (both without quotes).
You can print each character in any case (upper or lower).
Examples
Input
5 8
.#.#..#.
.....#..
.#.#..#.
#.#....#
.....#..
Output
Yes
Input
5 5
..#..
..#..
#####
..#..
..#..
Output
No
Input
5 9
........#
#........
..##.#...
.......#.
....#.#.#
Output
No
Note
For the first example, the desired setup can be produced by 3 operations, as is shown below.
<image>
For the second example, the desired setup cannot be produced, since in order to colour the center row, the third row and all columns must be selected in one operation, but after that no column can be selected again, hence it won't be possible to colour the other cells in the center column.
Submitted Solution:
```
n, m = map(int, input().strip().split())
M = list()
for _ in range(n):
M.append(input().strip())
def fail():
print('No')
exit(0)
vis = [[False] * m for _ in range(n)]
rc = set()
for i in range(n):
for j in range(m):
if (not vis[i][j]) and M[i][j] == '#':
cols = list()
for jj in range(m):
if M[i][jj] != '#':
continue
if vis[i][jj]:
fail()
cols.append(jj)
rows = list()
for ii in range(n):
if M[ii][j] != '#':
continue
if vis[ii][j]:
fail()
rows.append(ii)
for r in rows:
for c in cols:
if M[r][c] != '#' or (r*m + c) in rc:
fail()
vis[r][c] = True
for r in rows:
for c in cols:
rc.add(r*m + c)
print('Yes')
``` | instruction | 0 | 7,247 | 7 | 14,494 |
No | output | 1 | 7,247 | 7 | 14,495 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is a rectangular grid of n rows of m initially-white cells each.
Arkady performed a certain number (possibly zero) of operations on it. In the i-th operation, a non-empty subset of rows Ri and a non-empty subset of columns Ci are chosen. For each row r in Ri and each column c in Ci, the intersection of row r and column c is coloured black.
There's another constraint: a row or a column can only be chosen at most once among all operations. In other words, it means that no pair of (i, j) (i < j) exists such that <image> or <image>, where <image> denotes intersection of sets, and <image> denotes the empty set.
You are to determine whether a valid sequence of operations exists that produces a given final grid.
Input
The first line contains two space-separated integers n and m (1 ≤ n, m ≤ 50) — the number of rows and columns of the grid, respectively.
Each of the following n lines contains a string of m characters, each being either '.' (denoting a white cell) or '#' (denoting a black cell), representing the desired setup.
Output
If the given grid can be achieved by any valid sequence of operations, output "Yes"; otherwise output "No" (both without quotes).
You can print each character in any case (upper or lower).
Examples
Input
5 8
.#.#..#.
.....#..
.#.#..#.
#.#....#
.....#..
Output
Yes
Input
5 5
..#..
..#..
#####
..#..
..#..
Output
No
Input
5 9
........#
#........
..##.#...
.......#.
....#.#.#
Output
No
Note
For the first example, the desired setup can be produced by 3 operations, as is shown below.
<image>
For the second example, the desired setup cannot be produced, since in order to colour the center row, the third row and all columns must be selected in one operation, but after that no column can be selected again, hence it won't be possible to colour the other cells in the center column.
Submitted Solution:
```
n, m = map(int, input().split())
array = []
state = True
for i in range(n):
string = input()
if string.find('##')!=-1:
state = False
if state==True:
print('Yes')
else:
print('No')
``` | instruction | 0 | 7,248 | 7 | 14,496 |
No | output | 1 | 7,248 | 7 | 14,497 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Kuro has recently won the "Most intelligent cat ever" contest. The three friends then decided to go to Katie's home to celebrate Kuro's winning. After a big meal, they took a small break then started playing games.
Kuro challenged Katie to create a game with only a white paper, a pencil, a pair of scissors and a lot of arrows (you can assume that the number of arrows is infinite). Immediately, Katie came up with the game called Topological Parity.
The paper is divided into n pieces enumerated from 1 to n. Shiro has painted some pieces with some color. Specifically, the i-th piece has color c_{i} where c_{i} = 0 defines black color, c_{i} = 1 defines white color and c_{i} = -1 means that the piece hasn't been colored yet.
The rules of the game is simple. Players must put some arrows between some pairs of different pieces in such a way that for each arrow, the number in the piece it starts from is less than the number of the piece it ends at. Also, two different pieces can only be connected by at most one arrow. After that the players must choose the color (0 or 1) for each of the unpainted pieces. The score of a valid way of putting the arrows and coloring pieces is defined as the number of paths of pieces of alternating colors. For example, [1 → 0 → 1 → 0], [0 → 1 → 0 → 1], [1], [0] are valid paths and will be counted. You can only travel from piece x to piece y if and only if there is an arrow from x to y.
But Kuro is not fun yet. He loves parity. Let's call his favorite parity p where p = 0 stands for "even" and p = 1 stands for "odd". He wants to put the arrows and choose colors in such a way that the score has the parity of p.
It seems like there will be so many ways which satisfy Kuro. He wants to count the number of them but this could be a very large number. Let's help him with his problem, but print it modulo 10^{9} + 7.
Input
The first line contains two integers n and p (1 ≤ n ≤ 50, 0 ≤ p ≤ 1) — the number of pieces and Kuro's wanted parity.
The second line contains n integers c_{1}, c_{2}, ..., c_{n} (-1 ≤ c_{i} ≤ 1) — the colors of the pieces.
Output
Print a single integer — the number of ways to put the arrows and choose colors so the number of valid paths of alternating colors has the parity of p.
Examples
Input
3 1
-1 0 1
Output
6
Input
2 1
1 0
Output
1
Input
1 1
-1
Output
2
Note
In the first example, there are 6 ways to color the pieces and add the arrows, as are shown in the figure below. The scores are 3, 3, 5 for the first row and 5, 3, 3 for the second row, both from left to right.
<image> | instruction | 0 | 7,265 | 7 | 14,530 |
Tags: dp
Correct Solution:
```
n,p=map(int,input().split())
nums=[0]+list(map(int,input().split()))
mod=10**9+7
f=[[[[0]*2 for _ in range(2)] for _ in range(2)] for _ in range(n+1)]
_2=[0]*(n+1)
_2[0]=1
for i in range(1,n+1):
_2[i]=(_2[i-1]<<1)%mod
f[0][0][0][0]=1
if nums[1]!=0:
f[1][1][0][1]+=1
if nums[1]!=1:
f[1][1][1][0]+=1
for i in range(2,n+1):
for j in range(2):
for ob in range(2):
for ow in range(2):
qwq=f[i-1][j][ob][ow]
if nums[i]!=0:
if ob:
f[i][j][ob][ow]=(f[i][j][ob][ow]+qwq*_2[i-2])%mod
f[i][j^1][ob][ow|1]=(f[i][j^1][ob][ow|1]+qwq*_2[i-2])%mod
else:
f[i][j^1][ob][ow|1]=(f[i][j^1][ob][ow|1]+qwq*_2[i-1])%mod
if nums[i]!=1:
if ow:
f[i][j][ob][ow]=(f[i][j][ob][ow]+qwq*_2[i-2])%mod
f[i][j^1][ob|1][ow]=(f[i][j^1][ob|1][ow]+qwq*_2[i-2])%mod
else:
f[i][j^1][ob|1][ow]=(f[i][j^1][ob|1][ow]+qwq*_2[i-1])%mod
ans=0
for i in range(2):
for j in range(2):
ans=(ans+f[n][p][i][j])%mod
print(ans)
``` | output | 1 | 7,265 | 7 | 14,531 |
Provide a correct Python 3 solution for this coding contest problem.
There are N stones arranged in a row. Every stone is painted white or black. A string S represents the color of the stones. The i-th stone from the left is white if the i-th character of S is `.`, and the stone is black if the character is `#`.
Takahashi wants to change the colors of some stones to black or white so that there will be no white stone immediately to the right of a black stone. Find the minimum number of stones that needs to be recolored.
Constraints
* 1 \leq N \leq 2\times 10^5
* S is a string of length N consisting of `.` and `#`.
Input
Input is given from Standard Input in the following format:
N
S
Output
Print the minimum number of stones that needs to be recolored.
Examples
Input
3
#.#
Output
1
Input
3
.#
Output
1
Input
5
.##.
Output
2
Input
9
.........
Output
0 | instruction | 0 | 7,334 | 7 | 14,668 |
"Correct Solution:
```
n = int(input())
s = input()
w = [0]
cnt = 0
for i in range(n):
if s[i] == '#':
cnt += 1
w.append(cnt)
ans = len(s)
for i in range(n+1):
ans = min(ans, w[i]+(n-i-(w[-1]-w[i])))
print(ans)
``` | output | 1 | 7,334 | 7 | 14,669 |
Provide a correct Python 3 solution for this coding contest problem.
There are N stones arranged in a row. Every stone is painted white or black. A string S represents the color of the stones. The i-th stone from the left is white if the i-th character of S is `.`, and the stone is black if the character is `#`.
Takahashi wants to change the colors of some stones to black or white so that there will be no white stone immediately to the right of a black stone. Find the minimum number of stones that needs to be recolored.
Constraints
* 1 \leq N \leq 2\times 10^5
* S is a string of length N consisting of `.` and `#`.
Input
Input is given from Standard Input in the following format:
N
S
Output
Print the minimum number of stones that needs to be recolored.
Examples
Input
3
#.#
Output
1
Input
3
.#
Output
1
Input
5
.##.
Output
2
Input
9
.........
Output
0 | instruction | 0 | 7,335 | 7 | 14,670 |
"Correct Solution:
```
n = int(input())
s = input()
best_cost = s.count('.')
cost = best_cost
for i in range(n):
if s[i] == '#':
cost += 1
else:
cost -= 1
if cost < best_cost:
best_cost = cost
print(best_cost)
``` | output | 1 | 7,335 | 7 | 14,671 |
Provide a correct Python 3 solution for this coding contest problem.
There are N stones arranged in a row. Every stone is painted white or black. A string S represents the color of the stones. The i-th stone from the left is white if the i-th character of S is `.`, and the stone is black if the character is `#`.
Takahashi wants to change the colors of some stones to black or white so that there will be no white stone immediately to the right of a black stone. Find the minimum number of stones that needs to be recolored.
Constraints
* 1 \leq N \leq 2\times 10^5
* S is a string of length N consisting of `.` and `#`.
Input
Input is given from Standard Input in the following format:
N
S
Output
Print the minimum number of stones that needs to be recolored.
Examples
Input
3
#.#
Output
1
Input
3
.#
Output
1
Input
5
.##.
Output
2
Input
9
.........
Output
0 | instruction | 0 | 7,336 | 7 | 14,672 |
"Correct Solution:
```
N = int(input())
S = str(input())
x = S.count(".")
ans = x
for i in range(N):
if S[i]=="#":
x += 1
else:
x -= 1
ans = (min(ans,x))
print(ans)
``` | output | 1 | 7,336 | 7 | 14,673 |
Provide a correct Python 3 solution for this coding contest problem.
There are N stones arranged in a row. Every stone is painted white or black. A string S represents the color of the stones. The i-th stone from the left is white if the i-th character of S is `.`, and the stone is black if the character is `#`.
Takahashi wants to change the colors of some stones to black or white so that there will be no white stone immediately to the right of a black stone. Find the minimum number of stones that needs to be recolored.
Constraints
* 1 \leq N \leq 2\times 10^5
* S is a string of length N consisting of `.` and `#`.
Input
Input is given from Standard Input in the following format:
N
S
Output
Print the minimum number of stones that needs to be recolored.
Examples
Input
3
#.#
Output
1
Input
3
.#
Output
1
Input
5
.##.
Output
2
Input
9
.........
Output
0 | instruction | 0 | 7,337 | 7 | 14,674 |
"Correct Solution:
```
N = int(input())
S = input()
w_N = S.count(".")
ans = w_N
b = 0
w = 0
for i, s in enumerate(S):
if s == "#":
b += 1
if s == ".":
w += 1
ans = min(ans,b + w_N - w)
print(ans)
``` | output | 1 | 7,337 | 7 | 14,675 |
Provide a correct Python 3 solution for this coding contest problem.
There are N stones arranged in a row. Every stone is painted white or black. A string S represents the color of the stones. The i-th stone from the left is white if the i-th character of S is `.`, and the stone is black if the character is `#`.
Takahashi wants to change the colors of some stones to black or white so that there will be no white stone immediately to the right of a black stone. Find the minimum number of stones that needs to be recolored.
Constraints
* 1 \leq N \leq 2\times 10^5
* S is a string of length N consisting of `.` and `#`.
Input
Input is given from Standard Input in the following format:
N
S
Output
Print the minimum number of stones that needs to be recolored.
Examples
Input
3
#.#
Output
1
Input
3
.#
Output
1
Input
5
.##.
Output
2
Input
9
.........
Output
0 | instruction | 0 | 7,338 | 7 | 14,676 |
"Correct Solution:
```
N = int(input())
S = input()
lb = 0
rw = S.count('.')
ans = rw
for s in S:
if s == '.':
rw -= 1
else:
lb += 1
ans = min(ans, lb + rw)
print(ans)
``` | output | 1 | 7,338 | 7 | 14,677 |
Provide a correct Python 3 solution for this coding contest problem.
There are N stones arranged in a row. Every stone is painted white or black. A string S represents the color of the stones. The i-th stone from the left is white if the i-th character of S is `.`, and the stone is black if the character is `#`.
Takahashi wants to change the colors of some stones to black or white so that there will be no white stone immediately to the right of a black stone. Find the minimum number of stones that needs to be recolored.
Constraints
* 1 \leq N \leq 2\times 10^5
* S is a string of length N consisting of `.` and `#`.
Input
Input is given from Standard Input in the following format:
N
S
Output
Print the minimum number of stones that needs to be recolored.
Examples
Input
3
#.#
Output
1
Input
3
.#
Output
1
Input
5
.##.
Output
2
Input
9
.........
Output
0 | instruction | 0 | 7,339 | 7 | 14,678 |
"Correct Solution:
```
n = int(input())
s = input()
cost = 0
bc = 0
for it in s:
if it =="#":
bc += 1
elif bc > 0:
cost += 1
bc -= 1
print(cost)
``` | output | 1 | 7,339 | 7 | 14,679 |
Provide a correct Python 3 solution for this coding contest problem.
There are N stones arranged in a row. Every stone is painted white or black. A string S represents the color of the stones. The i-th stone from the left is white if the i-th character of S is `.`, and the stone is black if the character is `#`.
Takahashi wants to change the colors of some stones to black or white so that there will be no white stone immediately to the right of a black stone. Find the minimum number of stones that needs to be recolored.
Constraints
* 1 \leq N \leq 2\times 10^5
* S is a string of length N consisting of `.` and `#`.
Input
Input is given from Standard Input in the following format:
N
S
Output
Print the minimum number of stones that needs to be recolored.
Examples
Input
3
#.#
Output
1
Input
3
.#
Output
1
Input
5
.##.
Output
2
Input
9
.........
Output
0 | instruction | 0 | 7,340 | 7 | 14,680 |
"Correct Solution:
```
n = int(input())
s = input()
ans = [s.count(".")]
test = s.count(".")
for i in s:
if i == ".":
test -= 1
else:
test += 1
ans.append(test)
print(min(ans))
``` | output | 1 | 7,340 | 7 | 14,681 |
Provide a correct Python 3 solution for this coding contest problem.
There are N stones arranged in a row. Every stone is painted white or black. A string S represents the color of the stones. The i-th stone from the left is white if the i-th character of S is `.`, and the stone is black if the character is `#`.
Takahashi wants to change the colors of some stones to black or white so that there will be no white stone immediately to the right of a black stone. Find the minimum number of stones that needs to be recolored.
Constraints
* 1 \leq N \leq 2\times 10^5
* S is a string of length N consisting of `.` and `#`.
Input
Input is given from Standard Input in the following format:
N
S
Output
Print the minimum number of stones that needs to be recolored.
Examples
Input
3
#.#
Output
1
Input
3
.#
Output
1
Input
5
.##.
Output
2
Input
9
.........
Output
0 | instruction | 0 | 7,341 | 7 | 14,682 |
"Correct Solution:
```
n=int(input())
s=input()
l=0
r=s.count('.')
m=r
for i in range(n):
if s[i]=='.':
r-=1
else:
l+=1
m=min(m,r+l)
print(m)
``` | output | 1 | 7,341 | 7 | 14,683 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are N stones arranged in a row. Every stone is painted white or black. A string S represents the color of the stones. The i-th stone from the left is white if the i-th character of S is `.`, and the stone is black if the character is `#`.
Takahashi wants to change the colors of some stones to black or white so that there will be no white stone immediately to the right of a black stone. Find the minimum number of stones that needs to be recolored.
Constraints
* 1 \leq N \leq 2\times 10^5
* S is a string of length N consisting of `.` and `#`.
Input
Input is given from Standard Input in the following format:
N
S
Output
Print the minimum number of stones that needs to be recolored.
Examples
Input
3
#.#
Output
1
Input
3
.#
Output
1
Input
5
.##.
Output
2
Input
9
.........
Output
0
Submitted Solution:
```
n = int(input())
s = list(input())
b, w = 0, 0
for x in s:
if x == '#': b += 1
elif b > 0: # 黒の右に白があるので, 黒を白に置換
w += 1
b -= 1
print(w)
``` | instruction | 0 | 7,342 | 7 | 14,684 |
Yes | output | 1 | 7,342 | 7 | 14,685 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are N stones arranged in a row. Every stone is painted white or black. A string S represents the color of the stones. The i-th stone from the left is white if the i-th character of S is `.`, and the stone is black if the character is `#`.
Takahashi wants to change the colors of some stones to black or white so that there will be no white stone immediately to the right of a black stone. Find the minimum number of stones that needs to be recolored.
Constraints
* 1 \leq N \leq 2\times 10^5
* S is a string of length N consisting of `.` and `#`.
Input
Input is given from Standard Input in the following format:
N
S
Output
Print the minimum number of stones that needs to be recolored.
Examples
Input
3
#.#
Output
1
Input
3
.#
Output
1
Input
5
.##.
Output
2
Input
9
.........
Output
0
Submitted Solution:
```
n=int(input())
s=input()
w=s.count(".")
b=0
ans=10**9
for i in range(n):
if w+b<ans: ans=w+b
if s[i]==".": w-=1
else: b+=1
if w+b<ans: ans=w+b
print(ans)
``` | instruction | 0 | 7,343 | 7 | 14,686 |
Yes | output | 1 | 7,343 | 7 | 14,687 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are N stones arranged in a row. Every stone is painted white or black. A string S represents the color of the stones. The i-th stone from the left is white if the i-th character of S is `.`, and the stone is black if the character is `#`.
Takahashi wants to change the colors of some stones to black or white so that there will be no white stone immediately to the right of a black stone. Find the minimum number of stones that needs to be recolored.
Constraints
* 1 \leq N \leq 2\times 10^5
* S is a string of length N consisting of `.` and `#`.
Input
Input is given from Standard Input in the following format:
N
S
Output
Print the minimum number of stones that needs to be recolored.
Examples
Input
3
#.#
Output
1
Input
3
.#
Output
1
Input
5
.##.
Output
2
Input
9
.........
Output
0
Submitted Solution:
```
s=input()=='';b=[0]
for i in input():t=i=='.';b+=[b[-1]+1-t*2];s+=t
print(min([i+s for i in b]))
``` | instruction | 0 | 7,344 | 7 | 14,688 |
Yes | output | 1 | 7,344 | 7 | 14,689 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are N stones arranged in a row. Every stone is painted white or black. A string S represents the color of the stones. The i-th stone from the left is white if the i-th character of S is `.`, and the stone is black if the character is `#`.
Takahashi wants to change the colors of some stones to black or white so that there will be no white stone immediately to the right of a black stone. Find the minimum number of stones that needs to be recolored.
Constraints
* 1 \leq N \leq 2\times 10^5
* S is a string of length N consisting of `.` and `#`.
Input
Input is given from Standard Input in the following format:
N
S
Output
Print the minimum number of stones that needs to be recolored.
Examples
Input
3
#.#
Output
1
Input
3
.#
Output
1
Input
5
.##.
Output
2
Input
9
.........
Output
0
Submitted Solution:
```
N = int(input())
S = input()
tmp = S.count('.')
ans = tmp
for i in range(N):
if S[i] == '.':
tmp -= 1
else:
tmp += 1
ans = min(ans, tmp)
print(ans)
``` | instruction | 0 | 7,345 | 7 | 14,690 |
Yes | output | 1 | 7,345 | 7 | 14,691 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are N stones arranged in a row. Every stone is painted white or black. A string S represents the color of the stones. The i-th stone from the left is white if the i-th character of S is `.`, and the stone is black if the character is `#`.
Takahashi wants to change the colors of some stones to black or white so that there will be no white stone immediately to the right of a black stone. Find the minimum number of stones that needs to be recolored.
Constraints
* 1 \leq N \leq 2\times 10^5
* S is a string of length N consisting of `.` and `#`.
Input
Input is given from Standard Input in the following format:
N
S
Output
Print the minimum number of stones that needs to be recolored.
Examples
Input
3
#.#
Output
1
Input
3
.#
Output
1
Input
5
.##.
Output
2
Input
9
.........
Output
0
Submitted Solution:
```
# -*- coding: utf-8 -*-
"""
@author: H_Hoshigi
"""
def main():
N = int(input())
S = input()
hash_r = 0
while S[hash_r] != "#" and hash_r <= N-2:
hash_r += 1
dot_l = len(S)-1
while S[dot_l] != "." and dot_l >= 1:
dot_l -= 1
print(
min(
S[hash_r+1:].count("."),
S[:dot_l].count("#")
)
)
if __name__ == "__main__":
main()
``` | instruction | 0 | 7,346 | 7 | 14,692 |
No | output | 1 | 7,346 | 7 | 14,693 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are N stones arranged in a row. Every stone is painted white or black. A string S represents the color of the stones. The i-th stone from the left is white if the i-th character of S is `.`, and the stone is black if the character is `#`.
Takahashi wants to change the colors of some stones to black or white so that there will be no white stone immediately to the right of a black stone. Find the minimum number of stones that needs to be recolored.
Constraints
* 1 \leq N \leq 2\times 10^5
* S is a string of length N consisting of `.` and `#`.
Input
Input is given from Standard Input in the following format:
N
S
Output
Print the minimum number of stones that needs to be recolored.
Examples
Input
3
#.#
Output
1
Input
3
.#
Output
1
Input
5
.##.
Output
2
Input
9
.........
Output
0
Submitted Solution:
```
n = int(input())
s = list(input())
count = [0] * n
if s.count(".") != n and s.count("#") != n:
count[0] = s[0:1].count("#") + s[1:n].count(".")
for i in range(1,n):
if s[i] == "#":
count[i] = count[i-1] + 1
else:
count[i] = count[i-1] - 1
print(min(count))
``` | instruction | 0 | 7,347 | 7 | 14,694 |
No | output | 1 | 7,347 | 7 | 14,695 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are N stones arranged in a row. Every stone is painted white or black. A string S represents the color of the stones. The i-th stone from the left is white if the i-th character of S is `.`, and the stone is black if the character is `#`.
Takahashi wants to change the colors of some stones to black or white so that there will be no white stone immediately to the right of a black stone. Find the minimum number of stones that needs to be recolored.
Constraints
* 1 \leq N \leq 2\times 10^5
* S is a string of length N consisting of `.` and `#`.
Input
Input is given from Standard Input in the following format:
N
S
Output
Print the minimum number of stones that needs to be recolored.
Examples
Input
3
#.#
Output
1
Input
3
.#
Output
1
Input
5
.##.
Output
2
Input
9
.........
Output
0
Submitted Solution:
```
n = int(input())
s = input()
ans = 0
c = 0
for i in range(n):
if s[i] == "#":
c = 1
break
if c == 0:
print(0)
else:
for i in range(n):
if s[i] == "#":
for j in range(n-i-1):
if s[i+1+j] == ".":
ans += 1
print(ans)
break
``` | instruction | 0 | 7,348 | 7 | 14,696 |
No | output | 1 | 7,348 | 7 | 14,697 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are N stones arranged in a row. Every stone is painted white or black. A string S represents the color of the stones. The i-th stone from the left is white if the i-th character of S is `.`, and the stone is black if the character is `#`.
Takahashi wants to change the colors of some stones to black or white so that there will be no white stone immediately to the right of a black stone. Find the minimum number of stones that needs to be recolored.
Constraints
* 1 \leq N \leq 2\times 10^5
* S is a string of length N consisting of `.` and `#`.
Input
Input is given from Standard Input in the following format:
N
S
Output
Print the minimum number of stones that needs to be recolored.
Examples
Input
3
#.#
Output
1
Input
3
.#
Output
1
Input
5
.##.
Output
2
Input
9
.........
Output
0
Submitted Solution:
```
def main():
N = int(input())
S = input()
nums = []
for b in range(N+1):
nums.append(num_change(S, b, N))
print(min(nums))
def num_change(S, border, N):
count = 0
for i in range(N):
if i < border:
if S[i] == '#':
count += 1
else:
if S[i] == '.':
count += 1
return count
if __name__ == '__main__':
main()
``` | instruction | 0 | 7,349 | 7 | 14,698 |
No | output | 1 | 7,349 | 7 | 14,699 |
Provide a correct Python 3 solution for this coding contest problem.
We have a canvas divided into a grid with H rows and W columns. The square at the i-th row from the top and the j-th column from the left is represented as (i, j).
Initially, all the squares are white. square1001 wants to draw a picture with black paint. His specific objective is to make Square (i, j) black when s_{i, j}= `#`, and to make Square (i, j) white when s_{i, j}= `.`.
However, since he is not a good painter, he can only choose two squares that are horizontally or vertically adjacent and paint those squares black, for some number of times (possibly zero). He may choose squares that are already painted black, in which case the color of those squares remain black.
Determine if square1001 can achieve his objective.
Constraints
* H is an integer between 1 and 50 (inclusive).
* W is an integer between 1 and 50 (inclusive).
* For every (i, j) (1 \leq i \leq H, 1 \leq j \leq W), s_{i, j} is `#` or `.`.
Input
Input is given from Standard Input in the following format:
H W
s_{1, 1} s_{1, 2} s_{1, 3} ... s_{1, W}
s_{2, 1} s_{2, 2} s_{2, 3} ... s_{2, W}
: :
s_{H, 1} s_{H, 2} s_{H, 3} ... s_{H, W}
Output
If square1001 can achieve his objective, print `Yes`; if he cannot, print `No`.
Examples
Input
3 3
.#.
###
.#.
Output
Yes
Input
3 3
.#.
.#.
Output
Yes
Input
5 5
.#.#
.#.#.
.#.#
.#.#.
.#.#
Output
No
Input
11 11
...#####...
.##.....##.
..##.##..#
..##.##..#
.........#
...###...#
.#########.
.#.#.#.#.#.
.#.#.#.##
..##.#.##..
.##..#..##.
Output
Yes | instruction | 0 | 7,366 | 7 | 14,732 |
"Correct Solution:
```
h, w = [int(i) for i in input().split()]
s = [list(input()) for _ in range(h)]
flg = True
for i in range(1, h-1):
for j in range(1, w-1):
if s[i][j] == "#" and s[i-1][j]==s[i+1][j]==s[i][j-1]==s[i][j+1]==".":
flg = False
print('Yes' if flg else 'No')
``` | output | 1 | 7,366 | 7 | 14,733 |
Provide a correct Python 3 solution for this coding contest problem.
We have a canvas divided into a grid with H rows and W columns. The square at the i-th row from the top and the j-th column from the left is represented as (i, j).
Initially, all the squares are white. square1001 wants to draw a picture with black paint. His specific objective is to make Square (i, j) black when s_{i, j}= `#`, and to make Square (i, j) white when s_{i, j}= `.`.
However, since he is not a good painter, he can only choose two squares that are horizontally or vertically adjacent and paint those squares black, for some number of times (possibly zero). He may choose squares that are already painted black, in which case the color of those squares remain black.
Determine if square1001 can achieve his objective.
Constraints
* H is an integer between 1 and 50 (inclusive).
* W is an integer between 1 and 50 (inclusive).
* For every (i, j) (1 \leq i \leq H, 1 \leq j \leq W), s_{i, j} is `#` or `.`.
Input
Input is given from Standard Input in the following format:
H W
s_{1, 1} s_{1, 2} s_{1, 3} ... s_{1, W}
s_{2, 1} s_{2, 2} s_{2, 3} ... s_{2, W}
: :
s_{H, 1} s_{H, 2} s_{H, 3} ... s_{H, W}
Output
If square1001 can achieve his objective, print `Yes`; if he cannot, print `No`.
Examples
Input
3 3
.#.
###
.#.
Output
Yes
Input
3 3
.#.
.#.
Output
Yes
Input
5 5
.#.#
.#.#.
.#.#
.#.#.
.#.#
Output
No
Input
11 11
...#####...
.##.....##.
..##.##..#
..##.##..#
.........#
...###...#
.#########.
.#.#.#.#.#.
.#.#.#.##
..##.#.##..
.##..#..##.
Output
Yes | instruction | 0 | 7,367 | 7 | 14,734 |
"Correct Solution:
```
H, W = map(int, input().split())
cam = [input() for i in range(H)]
ans = 'Yes'
for i in range(1, H-1):
for j in range(1, W-1):
if cam[i][j] == "#":
if cam[i-1][j] == cam[i+1][j] == cam[i][j-1] == cam[i][j+1] == ".":
ans = 'No'
break
print(ans)
``` | output | 1 | 7,367 | 7 | 14,735 |
Provide a correct Python 3 solution for this coding contest problem.
We have a canvas divided into a grid with H rows and W columns. The square at the i-th row from the top and the j-th column from the left is represented as (i, j).
Initially, all the squares are white. square1001 wants to draw a picture with black paint. His specific objective is to make Square (i, j) black when s_{i, j}= `#`, and to make Square (i, j) white when s_{i, j}= `.`.
However, since he is not a good painter, he can only choose two squares that are horizontally or vertically adjacent and paint those squares black, for some number of times (possibly zero). He may choose squares that are already painted black, in which case the color of those squares remain black.
Determine if square1001 can achieve his objective.
Constraints
* H is an integer between 1 and 50 (inclusive).
* W is an integer between 1 and 50 (inclusive).
* For every (i, j) (1 \leq i \leq H, 1 \leq j \leq W), s_{i, j} is `#` or `.`.
Input
Input is given from Standard Input in the following format:
H W
s_{1, 1} s_{1, 2} s_{1, 3} ... s_{1, W}
s_{2, 1} s_{2, 2} s_{2, 3} ... s_{2, W}
: :
s_{H, 1} s_{H, 2} s_{H, 3} ... s_{H, W}
Output
If square1001 can achieve his objective, print `Yes`; if he cannot, print `No`.
Examples
Input
3 3
.#.
###
.#.
Output
Yes
Input
3 3
.#.
.#.
Output
Yes
Input
5 5
.#.#
.#.#.
.#.#
.#.#.
.#.#
Output
No
Input
11 11
...#####...
.##.....##.
..##.##..#
..##.##..#
.........#
...###...#
.#########.
.#.#.#.#.#.
.#.#.#.##
..##.#.##..
.##..#..##.
Output
Yes | instruction | 0 | 7,368 | 7 | 14,736 |
"Correct Solution:
```
h, w = map(int, input().split())
s = [list(input()) for i in range(h)]
for i in range(h - 1):
for j in range(w - 1):
if s[i][j] == "#" and s[i - 1][j] != "#" and s[i][j - 1] != "#" and s[i + 1][j] != "#" and s[i][j + 1] != "#":
print("No")
exit()
print("Yes")
``` | output | 1 | 7,368 | 7 | 14,737 |
Provide a correct Python 3 solution for this coding contest problem.
We have a canvas divided into a grid with H rows and W columns. The square at the i-th row from the top and the j-th column from the left is represented as (i, j).
Initially, all the squares are white. square1001 wants to draw a picture with black paint. His specific objective is to make Square (i, j) black when s_{i, j}= `#`, and to make Square (i, j) white when s_{i, j}= `.`.
However, since he is not a good painter, he can only choose two squares that are horizontally or vertically adjacent and paint those squares black, for some number of times (possibly zero). He may choose squares that are already painted black, in which case the color of those squares remain black.
Determine if square1001 can achieve his objective.
Constraints
* H is an integer between 1 and 50 (inclusive).
* W is an integer between 1 and 50 (inclusive).
* For every (i, j) (1 \leq i \leq H, 1 \leq j \leq W), s_{i, j} is `#` or `.`.
Input
Input is given from Standard Input in the following format:
H W
s_{1, 1} s_{1, 2} s_{1, 3} ... s_{1, W}
s_{2, 1} s_{2, 2} s_{2, 3} ... s_{2, W}
: :
s_{H, 1} s_{H, 2} s_{H, 3} ... s_{H, W}
Output
If square1001 can achieve his objective, print `Yes`; if he cannot, print `No`.
Examples
Input
3 3
.#.
###
.#.
Output
Yes
Input
3 3
.#.
.#.
Output
Yes
Input
5 5
.#.#
.#.#.
.#.#
.#.#.
.#.#
Output
No
Input
11 11
...#####...
.##.....##.
..##.##..#
..##.##..#
.........#
...###...#
.#########.
.#.#.#.#.#.
.#.#.#.##
..##.#.##..
.##..#..##.
Output
Yes | instruction | 0 | 7,369 | 7 | 14,738 |
"Correct Solution:
```
#!/usr/bin/env python3
h, w = map(int, input().split())
b = ".";j = [b+b*w+b]
s = j + [b+input()+b for _ in [0]*h] + j
for i in range(1, h+1):
d = [n+1 for n in range(w) if s[i][n:n+3] == ".#."]
if d and any([s[i-1][c] == s[i+1][c] == b for c in d]):
print("No");exit()
print("Yes")
``` | output | 1 | 7,369 | 7 | 14,739 |
Provide a correct Python 3 solution for this coding contest problem.
We have a canvas divided into a grid with H rows and W columns. The square at the i-th row from the top and the j-th column from the left is represented as (i, j).
Initially, all the squares are white. square1001 wants to draw a picture with black paint. His specific objective is to make Square (i, j) black when s_{i, j}= `#`, and to make Square (i, j) white when s_{i, j}= `.`.
However, since he is not a good painter, he can only choose two squares that are horizontally or vertically adjacent and paint those squares black, for some number of times (possibly zero). He may choose squares that are already painted black, in which case the color of those squares remain black.
Determine if square1001 can achieve his objective.
Constraints
* H is an integer between 1 and 50 (inclusive).
* W is an integer between 1 and 50 (inclusive).
* For every (i, j) (1 \leq i \leq H, 1 \leq j \leq W), s_{i, j} is `#` or `.`.
Input
Input is given from Standard Input in the following format:
H W
s_{1, 1} s_{1, 2} s_{1, 3} ... s_{1, W}
s_{2, 1} s_{2, 2} s_{2, 3} ... s_{2, W}
: :
s_{H, 1} s_{H, 2} s_{H, 3} ... s_{H, W}
Output
If square1001 can achieve his objective, print `Yes`; if he cannot, print `No`.
Examples
Input
3 3
.#.
###
.#.
Output
Yes
Input
3 3
.#.
.#.
Output
Yes
Input
5 5
.#.#
.#.#.
.#.#
.#.#.
.#.#
Output
No
Input
11 11
...#####...
.##.....##.
..##.##..#
..##.##..#
.........#
...###...#
.#########.
.#.#.#.#.#.
.#.#.#.##
..##.#.##..
.##..#..##.
Output
Yes | instruction | 0 | 7,370 | 7 | 14,740 |
"Correct Solution:
```
H,W=map(int,input().split())
Map=[]
for i in range(H):
Map.append(input())
for i in range(H):
for j in range(W):
if Map[i][j]=='#':
if i-1>=0 and i+1<H and j-1>=0 and j+1<W:
if Map[i-1][j]!='#' and Map[i+1][j]!='#' and Map[i][j-1]!='#' and Map[i][j+1]!='#':
print('No')
exit()
print('Yes')
``` | output | 1 | 7,370 | 7 | 14,741 |
Provide a correct Python 3 solution for this coding contest problem.
We have a canvas divided into a grid with H rows and W columns. The square at the i-th row from the top and the j-th column from the left is represented as (i, j).
Initially, all the squares are white. square1001 wants to draw a picture with black paint. His specific objective is to make Square (i, j) black when s_{i, j}= `#`, and to make Square (i, j) white when s_{i, j}= `.`.
However, since he is not a good painter, he can only choose two squares that are horizontally or vertically adjacent and paint those squares black, for some number of times (possibly zero). He may choose squares that are already painted black, in which case the color of those squares remain black.
Determine if square1001 can achieve his objective.
Constraints
* H is an integer between 1 and 50 (inclusive).
* W is an integer between 1 and 50 (inclusive).
* For every (i, j) (1 \leq i \leq H, 1 \leq j \leq W), s_{i, j} is `#` or `.`.
Input
Input is given from Standard Input in the following format:
H W
s_{1, 1} s_{1, 2} s_{1, 3} ... s_{1, W}
s_{2, 1} s_{2, 2} s_{2, 3} ... s_{2, W}
: :
s_{H, 1} s_{H, 2} s_{H, 3} ... s_{H, W}
Output
If square1001 can achieve his objective, print `Yes`; if he cannot, print `No`.
Examples
Input
3 3
.#.
###
.#.
Output
Yes
Input
3 3
.#.
.#.
Output
Yes
Input
5 5
.#.#
.#.#.
.#.#
.#.#.
.#.#
Output
No
Input
11 11
...#####...
.##.....##.
..##.##..#
..##.##..#
.........#
...###...#
.#########.
.#.#.#.#.#.
.#.#.#.##
..##.#.##..
.##..#..##.
Output
Yes | instruction | 0 | 7,371 | 7 | 14,742 |
"Correct Solution:
```
h,w = map(int, input().split())
original = [list(input()) for _ in range(h)]
for i in range(h-1):
for j in range(w-1):
if original[i][j]=='#' and original[i-1][j]!='#' and original[i+1][j]!='#' and original[i][j-1]!='#' and original[i][j+1]!='#':
print('No')
exit()
print('Yes')
``` | output | 1 | 7,371 | 7 | 14,743 |
Provide a correct Python 3 solution for this coding contest problem.
We have a canvas divided into a grid with H rows and W columns. The square at the i-th row from the top and the j-th column from the left is represented as (i, j).
Initially, all the squares are white. square1001 wants to draw a picture with black paint. His specific objective is to make Square (i, j) black when s_{i, j}= `#`, and to make Square (i, j) white when s_{i, j}= `.`.
However, since he is not a good painter, he can only choose two squares that are horizontally or vertically adjacent and paint those squares black, for some number of times (possibly zero). He may choose squares that are already painted black, in which case the color of those squares remain black.
Determine if square1001 can achieve his objective.
Constraints
* H is an integer between 1 and 50 (inclusive).
* W is an integer between 1 and 50 (inclusive).
* For every (i, j) (1 \leq i \leq H, 1 \leq j \leq W), s_{i, j} is `#` or `.`.
Input
Input is given from Standard Input in the following format:
H W
s_{1, 1} s_{1, 2} s_{1, 3} ... s_{1, W}
s_{2, 1} s_{2, 2} s_{2, 3} ... s_{2, W}
: :
s_{H, 1} s_{H, 2} s_{H, 3} ... s_{H, W}
Output
If square1001 can achieve his objective, print `Yes`; if he cannot, print `No`.
Examples
Input
3 3
.#.
###
.#.
Output
Yes
Input
3 3
.#.
.#.
Output
Yes
Input
5 5
.#.#
.#.#.
.#.#
.#.#.
.#.#
Output
No
Input
11 11
...#####...
.##.....##.
..##.##..#
..##.##..#
.........#
...###...#
.#########.
.#.#.#.#.#.
.#.#.#.##
..##.#.##..
.##..#..##.
Output
Yes | instruction | 0 | 7,372 | 7 | 14,744 |
"Correct Solution:
```
h,w=map(int,input().split())
S=[]
for i in range(h):
S.append(input())
ans='Yes'
for i in range(1,h-1):
for j in range(1,w-1):
if S[i][j]=='#' and S[i+1][j]=='.' and S[i-1][j]=='.' and S[i][j+1]=='.' and S[i][j-1]=='.':
ans='No'
print(ans)
``` | output | 1 | 7,372 | 7 | 14,745 |
Provide a correct Python 3 solution for this coding contest problem.
We have a canvas divided into a grid with H rows and W columns. The square at the i-th row from the top and the j-th column from the left is represented as (i, j).
Initially, all the squares are white. square1001 wants to draw a picture with black paint. His specific objective is to make Square (i, j) black when s_{i, j}= `#`, and to make Square (i, j) white when s_{i, j}= `.`.
However, since he is not a good painter, he can only choose two squares that are horizontally or vertically adjacent and paint those squares black, for some number of times (possibly zero). He may choose squares that are already painted black, in which case the color of those squares remain black.
Determine if square1001 can achieve his objective.
Constraints
* H is an integer between 1 and 50 (inclusive).
* W is an integer between 1 and 50 (inclusive).
* For every (i, j) (1 \leq i \leq H, 1 \leq j \leq W), s_{i, j} is `#` or `.`.
Input
Input is given from Standard Input in the following format:
H W
s_{1, 1} s_{1, 2} s_{1, 3} ... s_{1, W}
s_{2, 1} s_{2, 2} s_{2, 3} ... s_{2, W}
: :
s_{H, 1} s_{H, 2} s_{H, 3} ... s_{H, W}
Output
If square1001 can achieve his objective, print `Yes`; if he cannot, print `No`.
Examples
Input
3 3
.#.
###
.#.
Output
Yes
Input
3 3
.#.
.#.
Output
Yes
Input
5 5
.#.#
.#.#.
.#.#
.#.#.
.#.#
Output
No
Input
11 11
...#####...
.##.....##.
..##.##..#
..##.##..#
.........#
...###...#
.#########.
.#.#.#.#.#.
.#.#.#.##
..##.#.##..
.##..#..##.
Output
Yes | instruction | 0 | 7,373 | 7 | 14,746 |
"Correct Solution:
```
H, W = map(int, input().split())
s_list = [input() for i in range(H)]
flag = True
for i in range(1, H - 1):
for j in range(1, W - 1):
if s_list[i][j] == "#":
if s_list[i-1][j] == "." and s_list[i+1][j] == "." and s_list[i][j-1] == "." and s_list[i][j+1] == ".":
flag = False
break
if flag:
print("Yes")
else:
print("No")
``` | output | 1 | 7,373 | 7 | 14,747 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We have a canvas divided into a grid with H rows and W columns. The square at the i-th row from the top and the j-th column from the left is represented as (i, j).
Initially, all the squares are white. square1001 wants to draw a picture with black paint. His specific objective is to make Square (i, j) black when s_{i, j}= `#`, and to make Square (i, j) white when s_{i, j}= `.`.
However, since he is not a good painter, he can only choose two squares that are horizontally or vertically adjacent and paint those squares black, for some number of times (possibly zero). He may choose squares that are already painted black, in which case the color of those squares remain black.
Determine if square1001 can achieve his objective.
Constraints
* H is an integer between 1 and 50 (inclusive).
* W is an integer between 1 and 50 (inclusive).
* For every (i, j) (1 \leq i \leq H, 1 \leq j \leq W), s_{i, j} is `#` or `.`.
Input
Input is given from Standard Input in the following format:
H W
s_{1, 1} s_{1, 2} s_{1, 3} ... s_{1, W}
s_{2, 1} s_{2, 2} s_{2, 3} ... s_{2, W}
: :
s_{H, 1} s_{H, 2} s_{H, 3} ... s_{H, W}
Output
If square1001 can achieve his objective, print `Yes`; if he cannot, print `No`.
Examples
Input
3 3
.#.
###
.#.
Output
Yes
Input
3 3
.#.
.#.
Output
Yes
Input
5 5
.#.#
.#.#.
.#.#
.#.#.
.#.#
Output
No
Input
11 11
...#####...
.##.....##.
..##.##..#
..##.##..#
.........#
...###...#
.#########.
.#.#.#.#.#.
.#.#.#.##
..##.#.##..
.##..#..##.
Output
Yes
Submitted Solution:
```
h,w=map(int,input().split())
g=[input() for _ in range(h)]
for x in range(h):
for y in range(w):
if g[x][y]=='.': continue
ng=1
for dx,dy in [(1,0),(0,1),(-1,0),(0,-1)]:
nx,ny=x+dx,y+dy
if 0<=nx<h and 0<=ny<w:
if g[nx][ny]=='#': ng=0
if ng:
print('No')
exit()
print('Yes')
``` | instruction | 0 | 7,374 | 7 | 14,748 |
Yes | output | 1 | 7,374 | 7 | 14,749 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We have a canvas divided into a grid with H rows and W columns. The square at the i-th row from the top and the j-th column from the left is represented as (i, j).
Initially, all the squares are white. square1001 wants to draw a picture with black paint. His specific objective is to make Square (i, j) black when s_{i, j}= `#`, and to make Square (i, j) white when s_{i, j}= `.`.
However, since he is not a good painter, he can only choose two squares that are horizontally or vertically adjacent and paint those squares black, for some number of times (possibly zero). He may choose squares that are already painted black, in which case the color of those squares remain black.
Determine if square1001 can achieve his objective.
Constraints
* H is an integer between 1 and 50 (inclusive).
* W is an integer between 1 and 50 (inclusive).
* For every (i, j) (1 \leq i \leq H, 1 \leq j \leq W), s_{i, j} is `#` or `.`.
Input
Input is given from Standard Input in the following format:
H W
s_{1, 1} s_{1, 2} s_{1, 3} ... s_{1, W}
s_{2, 1} s_{2, 2} s_{2, 3} ... s_{2, W}
: :
s_{H, 1} s_{H, 2} s_{H, 3} ... s_{H, W}
Output
If square1001 can achieve his objective, print `Yes`; if he cannot, print `No`.
Examples
Input
3 3
.#.
###
.#.
Output
Yes
Input
3 3
.#.
.#.
Output
Yes
Input
5 5
.#.#
.#.#.
.#.#
.#.#.
.#.#
Output
No
Input
11 11
...#####...
.##.....##.
..##.##..#
..##.##..#
.........#
...###...#
.#########.
.#.#.#.#.#.
.#.#.#.##
..##.#.##..
.##..#..##.
Output
Yes
Submitted Solution:
```
import sys
h,w=map(int,input().split())
s=[[0]*(w+2)]+[[0]+list(map(int,list(input().replace('#','1').replace('.','0'))))+[0]for i in range(h)]+[[0]*(w+2)]
for i in range(1,h+1):
for j in range(1,w+1):
if s[i][j]==1:
if s[i-1][j]+s[i+1][j]+s[i][j-1]+s[i][j+1]==0:
print('No')
sys.exit()
print('Yes')
``` | instruction | 0 | 7,375 | 7 | 14,750 |
Yes | output | 1 | 7,375 | 7 | 14,751 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.