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.
Roy and Biv have a set of n points on the infinite number line.
Each point has one of 3 colors: red, green, or blue.
Roy and Biv would like to connect all the points with some edges. Edges can be drawn between any of the two of the given points. The cost of an edge is equal to the distance between the two points it connects.
They want to do this in such a way that they will both see that all the points are connected (either directly or indirectly).
However, there is a catch: Roy cannot see the color red and Biv cannot see the color blue.
Therefore, they have to choose the edges in such a way that if all the red points are removed, the remaining blue and green points are connected (and similarly, if all the blue points are removed, the remaining red and green points are connected).
Help them compute the minimum cost way to choose edges to satisfy the above constraints.
Input
The first line will contain an integer n (1 ≤ n ≤ 300 000), the number of points.
The next n lines will contain two tokens pi and ci (pi is an integer, 1 ≤ pi ≤ 109, ci is a uppercase English letter 'R', 'G' or 'B'), denoting the position of the i-th point and the color of the i-th point. 'R' means red, 'G' denotes green, and 'B' means blue. The positions will be in strictly increasing order.
Output
Print a single integer, the minimum cost way to solve the problem.
Examples
Input
4
1 G
5 R
10 B
15 G
Output
23
Input
4
1 G
2 R
3 B
10 G
Output
12
Note
In the first sample, it is optimal to draw edges between the points (1,2), (1,4), (3,4). These have costs 4, 14, 5, respectively.
Submitted Solution:
```
# Collaborated with Rudransh Singh
n = int(input())
r = 0
g = 0
b = 0
maxR = 0
maxB = 0
maxG = 0
minCost = 0
for i in range(n):
p, c = input().split(" ")
p = int(p)
if c == "R" or c == "G":
if r:
minCost += p - r
maxR = max(maxR, p - r)
r = p
if c == "B" or c == "G":
if b:
minCost += p - b
maxB = max(maxB, p - b)
b = p
if c == "G":
if g:
minCost += min(0, p - g - maxR - maxB)
g = p
maxR = 0
maxB = 0
print(minCost)
``` | instruction | 0 | 517 | 7 | 1,034 |
Yes | output | 1 | 517 | 7 | 1,035 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Roy and Biv have a set of n points on the infinite number line.
Each point has one of 3 colors: red, green, or blue.
Roy and Biv would like to connect all the points with some edges. Edges can be drawn between any of the two of the given points. The cost of an edge is equal to the distance between the two points it connects.
They want to do this in such a way that they will both see that all the points are connected (either directly or indirectly).
However, there is a catch: Roy cannot see the color red and Biv cannot see the color blue.
Therefore, they have to choose the edges in such a way that if all the red points are removed, the remaining blue and green points are connected (and similarly, if all the blue points are removed, the remaining red and green points are connected).
Help them compute the minimum cost way to choose edges to satisfy the above constraints.
Input
The first line will contain an integer n (1 ≤ n ≤ 300 000), the number of points.
The next n lines will contain two tokens pi and ci (pi is an integer, 1 ≤ pi ≤ 109, ci is a uppercase English letter 'R', 'G' or 'B'), denoting the position of the i-th point and the color of the i-th point. 'R' means red, 'G' denotes green, and 'B' means blue. The positions will be in strictly increasing order.
Output
Print a single integer, the minimum cost way to solve the problem.
Examples
Input
4
1 G
5 R
10 B
15 G
Output
23
Input
4
1 G
2 R
3 B
10 G
Output
12
Note
In the first sample, it is optimal to draw edges between the points (1,2), (1,4), (3,4). These have costs 4, 14, 5, respectively.
Submitted Solution:
```
k=int(input())
t,a,b,m,n,o,d,e,s,x,y,z,l=13*[0]
for i in range(k):
c=input().split(" ")
f=int(c[0])
if c[1]=="G":
if o<1:
z=f
if t:
if m>0:
d=max(d,f-m)
if n>0:
e=max(e,f-n)
s+=min(2*(f-o),3*(f-o)-d-e)
d,e,a,b=4*[0]
m=f
n=f
o=f
t=1
l+=1
if c[1]=="R":
a+=1
if m<1:
x=f
if m>0 and t:
d=max(d,f-m)
m=f
if c[1]=="B":
b+=1
if n<1:
y=f
if n>0 and t:
e=max(e,f-n)
n=f
if l>0:
if a>0:
s+=m-o
if b>0:
s+=n-o
if x>0:
s+=z-x
if y>0:
s+=z-y
else:
s=m-x+n-y
print(s)
``` | instruction | 0 | 518 | 7 | 1,036 |
Yes | output | 1 | 518 | 7 | 1,037 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Roy and Biv have a set of n points on the infinite number line.
Each point has one of 3 colors: red, green, or blue.
Roy and Biv would like to connect all the points with some edges. Edges can be drawn between any of the two of the given points. The cost of an edge is equal to the distance between the two points it connects.
They want to do this in such a way that they will both see that all the points are connected (either directly or indirectly).
However, there is a catch: Roy cannot see the color red and Biv cannot see the color blue.
Therefore, they have to choose the edges in such a way that if all the red points are removed, the remaining blue and green points are connected (and similarly, if all the blue points are removed, the remaining red and green points are connected).
Help them compute the minimum cost way to choose edges to satisfy the above constraints.
Input
The first line will contain an integer n (1 ≤ n ≤ 300 000), the number of points.
The next n lines will contain two tokens pi and ci (pi is an integer, 1 ≤ pi ≤ 109, ci is a uppercase English letter 'R', 'G' or 'B'), denoting the position of the i-th point and the color of the i-th point. 'R' means red, 'G' denotes green, and 'B' means blue. The positions will be in strictly increasing order.
Output
Print a single integer, the minimum cost way to solve the problem.
Examples
Input
4
1 G
5 R
10 B
15 G
Output
23
Input
4
1 G
2 R
3 B
10 G
Output
12
Note
In the first sample, it is optimal to draw edges between the points (1,2), (1,4), (3,4). These have costs 4, 14, 5, respectively.
Submitted Solution:
```
#Problem Set F: Collaborated with no one
n = int(input())
result = 0
temp = 0
b_red = 0
b_blue = 0
final_red = -1
final_blue = -1
final_green = -(1<<60)
for i in range(n):
cost_colorList = input().split()
cost = int(cost_colorList[0])
color = cost_colorList[1]
if color == 'R' or color == 'G':
if final_red != -1:
b_red = max(b_red, cost - final_red)
temp += cost - final_red
final_red = cost
if color == 'B' or color == 'G':
if final_blue != -1:
b_blue = max(b_blue, cost - final_blue)
temp += cost - final_blue
final_blue = cost
if color == 'G':
result += temp + min(0, - b_red - b_blue + cost - final_green)
final_red = final_blue = final_green = cost
b_red = b_blue = temp = 0
result += temp
print(result)
``` | instruction | 0 | 519 | 7 | 1,038 |
Yes | output | 1 | 519 | 7 | 1,039 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Roy and Biv have a set of n points on the infinite number line.
Each point has one of 3 colors: red, green, or blue.
Roy and Biv would like to connect all the points with some edges. Edges can be drawn between any of the two of the given points. The cost of an edge is equal to the distance between the two points it connects.
They want to do this in such a way that they will both see that all the points are connected (either directly or indirectly).
However, there is a catch: Roy cannot see the color red and Biv cannot see the color blue.
Therefore, they have to choose the edges in such a way that if all the red points are removed, the remaining blue and green points are connected (and similarly, if all the blue points are removed, the remaining red and green points are connected).
Help them compute the minimum cost way to choose edges to satisfy the above constraints.
Input
The first line will contain an integer n (1 ≤ n ≤ 300 000), the number of points.
The next n lines will contain two tokens pi and ci (pi is an integer, 1 ≤ pi ≤ 109, ci is a uppercase English letter 'R', 'G' or 'B'), denoting the position of the i-th point and the color of the i-th point. 'R' means red, 'G' denotes green, and 'B' means blue. The positions will be in strictly increasing order.
Output
Print a single integer, the minimum cost way to solve the problem.
Examples
Input
4
1 G
5 R
10 B
15 G
Output
23
Input
4
1 G
2 R
3 B
10 G
Output
12
Note
In the first sample, it is optimal to draw edges between the points (1,2), (1,4), (3,4). These have costs 4, 14, 5, respectively.
Submitted Solution:
```
n = int( input() )
G = []
R = []
B = []
a = []
L1, L2 = [], []
for i in range( n ):
p, c = input().split()
p = int(p)
a.append( (p,c) )
if c == 'G':
G.append(p)
L1.append(i)
L2.append(i)
elif c == 'R':
R.append(p)
L1.append(i)
else:
B.append(p)
L2.append(i)
ans = 0
edges = []
for i in range( 1, len(G) ):
edges.append( abs( G[i] - G[i-1] ) )
#ans += min( abs( G[i]-G[i+1] ), abs( G[i]-G[i-1] ) )
#connect (1st, last) or (1st,2nd) + (last,last-1)
g=len(G)-1
#ans += min( abs( G[0] - G[-1] ), abs( G[0]-G[1] ) + abs( G[g]-G[g-1] ) )
#ans = sum(edges)
#if len(edges) > 1:
# ans -= max(edges)
#print(ans)
def left_right_points( what, G ):
global ans
#left from first G
idx = 0
has_found_what = False
points = []
while idx < len(a):
if a[idx][1] == 'G':
if has_found_what == False:
return
else:
points.append( a[idx][0] )
#calculate
for i in range(1, len(points) ):
ans += abs( points[i] - points[i-1] )
break
elif a[idx][1] == what:
points.append( a[idx][0] )
has_found_what = True
idx += 1
idx = len(a)-1
has_found_what = False
points = []
while idx >= 0:
if a[idx][1] == 'G':
if has_found_what == False:
return
else:
points.append( a[idx][0] )
#calculate
for i in range(1, len(points) ):
ans += abs( points[i] - points[i-1] )
break
elif a[idx][1] == what:
points.append( a[idx][0] )
has_found_what = True
idx -= 1
left_right_points( 'R', G )
left_right_points( 'B', G )
def intermediate_points( L1, what, left_green, right_green ):
global ans
edges = []
ok = False
for j in range( left_green, right_green+1 ):
if a[ L1[j] ][1] == what:
ok = True
break
if ok == False:
return
for j in range( left_green+1, right_green+1 ):
#print( a[ L1[j-1] ][1], a[ L1[j] ][1] )
prev_point = a[ L1[j-1] ][0]
cur_point = a[ L1[j] ][0]
dist = abs( prev_point - cur_point )
edges.append( dist )
prev_point = a[ L1[left_green] ][0]
cur_point = a[ L1[right_green] ][0]
edges.append( abs( prev_point - cur_point ) )
ans += sum( edges )
if len(edges) > 1:
ans -= max(edges)
def intermediate_green_segments( L1, what ):
global ans
left_green, right_green = -1, -1
for i in range( len(L1) ):
if a[ L1[i] ][1] == 'G':
if left_green == -1:
left_green = i
elif right_green == -1:
right_green = i
else:
left_green, right_green = right_green, i
#rint( left_green, right_green )
intermediate_points( L1, what, left_green, right_green )
intermediate_points( L1, what, left_green, right_green )
intermediate_green_segments( L1, 'R' )
intermediate_green_segments( L2, 'B' )
#print( dist1, dist2 )
print( ans )
``` | instruction | 0 | 520 | 7 | 1,040 |
No | output | 1 | 520 | 7 | 1,041 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Roy and Biv have a set of n points on the infinite number line.
Each point has one of 3 colors: red, green, or blue.
Roy and Biv would like to connect all the points with some edges. Edges can be drawn between any of the two of the given points. The cost of an edge is equal to the distance between the two points it connects.
They want to do this in such a way that they will both see that all the points are connected (either directly or indirectly).
However, there is a catch: Roy cannot see the color red and Biv cannot see the color blue.
Therefore, they have to choose the edges in such a way that if all the red points are removed, the remaining blue and green points are connected (and similarly, if all the blue points are removed, the remaining red and green points are connected).
Help them compute the minimum cost way to choose edges to satisfy the above constraints.
Input
The first line will contain an integer n (1 ≤ n ≤ 300 000), the number of points.
The next n lines will contain two tokens pi and ci (pi is an integer, 1 ≤ pi ≤ 109, ci is a uppercase English letter 'R', 'G' or 'B'), denoting the position of the i-th point and the color of the i-th point. 'R' means red, 'G' denotes green, and 'B' means blue. The positions will be in strictly increasing order.
Output
Print a single integer, the minimum cost way to solve the problem.
Examples
Input
4
1 G
5 R
10 B
15 G
Output
23
Input
4
1 G
2 R
3 B
10 G
Output
12
Note
In the first sample, it is optimal to draw edges between the points (1,2), (1,4), (3,4). These have costs 4, 14, 5, respectively.
Submitted Solution:
```
n = int( input() )
min_red, max_red = -1, -1
min_blue, max_blue = -1, -1
left_green, right_green = -1, -1
a = []
ans = 0
last_r, last_b, last_g = -1, -1, -1
r_edges = []
b_edges = []
g_edges = []
for i in range( n ):
p, c = input().split()
p = int(p)
if c == 'R' or c == 'G':
if last_r != -1:
r_edges.append( p - last_r )
last_r = p
if c == 'B' or c == 'G':
if last_b != -1:
b_edges.append( p - last_b )
last_b = p
if c == 'G':
ans += sum(r_edges) + sum(b_edges)
if len(r_edges) > 0 and len(b_edges) > 0:
#print( r_edges )
#print( b_edges )
max_red = max(r_edges)
max_blue = max(b_edges)
if max_red+max_blue > p-last_g:
ans -= (max_red+max_blue)
r_edges = [ ]
b_edges = [ ]
if last_g != -1:
ans += p-last_g
last_g = p
ans += sum(r_edges) + sum(b_edges)
print( ans )
``` | instruction | 0 | 521 | 7 | 1,042 |
No | output | 1 | 521 | 7 | 1,043 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Roy and Biv have a set of n points on the infinite number line.
Each point has one of 3 colors: red, green, or blue.
Roy and Biv would like to connect all the points with some edges. Edges can be drawn between any of the two of the given points. The cost of an edge is equal to the distance between the two points it connects.
They want to do this in such a way that they will both see that all the points are connected (either directly or indirectly).
However, there is a catch: Roy cannot see the color red and Biv cannot see the color blue.
Therefore, they have to choose the edges in such a way that if all the red points are removed, the remaining blue and green points are connected (and similarly, if all the blue points are removed, the remaining red and green points are connected).
Help them compute the minimum cost way to choose edges to satisfy the above constraints.
Input
The first line will contain an integer n (1 ≤ n ≤ 300 000), the number of points.
The next n lines will contain two tokens pi and ci (pi is an integer, 1 ≤ pi ≤ 109, ci is a uppercase English letter 'R', 'G' or 'B'), denoting the position of the i-th point and the color of the i-th point. 'R' means red, 'G' denotes green, and 'B' means blue. The positions will be in strictly increasing order.
Output
Print a single integer, the minimum cost way to solve the problem.
Examples
Input
4
1 G
5 R
10 B
15 G
Output
23
Input
4
1 G
2 R
3 B
10 G
Output
12
Note
In the first sample, it is optimal to draw edges between the points (1,2), (1,4), (3,4). These have costs 4, 14, 5, respectively.
Submitted Solution:
```
n = int( input() )
G = []
R = []
B = []
a = []
L1, L2 = [], []
for i in range( n ):
p, c = input().split()
p = int(p)
a.append( (p,c) )
if c == 'G':
G.append(p)
L1.append(i)
L2.append(i)
elif c == 'R':
R.append(p)
L1.append(i)
else:
B.append(p)
L2.append(i)
ans = 0
edges = []
for i in range( 1, len(G) ):
edges.append( abs( G[i] - G[i-1] ) )
#ans += min( abs( G[i]-G[i+1] ), abs( G[i]-G[i-1] ) )
#connect (1st, last) or (1st,2nd) + (last,last-1)
g=len(G)-1
#ans += min( abs( G[0] - G[-1] ), abs( G[0]-G[1] ) + abs( G[g]-G[g-1] ) )
ans = sum(edges)
if len(edges) > 1:
ans -= max(edges)
#print(ans)
def left_right_points( what, G ):
global ans
#left from first G
idx = 0
has_found_what = False
points = []
while idx < len(a):
if a[idx][1] == 'G':
if has_found_what == False:
return
else:
points.append( a[idx][0] )
#calculate
for i in range(1, len(points) ):
ans += abs( points[i] - points[i-1] )
elif a[idx][1] == what:
points.append( a[idx][0] )
has_found_what = True
idx += 1
idx = len(a)-1
has_found_what = False
points = []
while idx >= 0:
if a[idx][1] == 'G':
if has_found_what == False:
return
else:
points.append( a[idx][0] )
#calculate
for i in range(1, len(points) ):
ans += abs( points[i] - points[i-1] )
elif a[idx][1] == what:
points.append( a[idx][0] )
has_found_what = True
idx -= 1
left_right_points( 'R', G )
left_right_points( 'B', G )
def intermediate_points( L1, what, left_green, right_green ):
global ans
edges = []
ok = False
for j in range( left_green, right_green+1 ):
if a[ L1[j] ][1] == what:
ok = True
break
if ok == False:
return
for j in range( left_green+1, right_green+1 ):
#print( a[ L1[j-1] ][1], a[ L1[j] ][1] )
prev_point = a[ L1[j-1] ][0]
cur_point = a[ L1[j] ][0]
dist = abs( prev_point - cur_point )
edges.append( dist )
ans += sum( edges )
if len(edges) > 1:
ans -= max(edges)
def intermediate_green_segments( L1, what ):
global ans
left_green, right_green = -1, -1
for i in range( len(L1) ):
if a[ L1[i] ][1] == 'G':
if left_green == -1:
left_green = i
elif right_green == -1:
right_green = i
else:
left_green, right_green = right_green, i
#rint( left_green, right_green )
intermediate_points( L1, what, left_green, right_green )
intermediate_points( L1, what, left_green, right_green )
intermediate_green_segments( L1, 'R' )
intermediate_green_segments( L2, 'B' )
#print( dist1, dist2 )
print( ans )
``` | instruction | 0 | 522 | 7 | 1,044 |
No | output | 1 | 522 | 7 | 1,045 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Roy and Biv have a set of n points on the infinite number line.
Each point has one of 3 colors: red, green, or blue.
Roy and Biv would like to connect all the points with some edges. Edges can be drawn between any of the two of the given points. The cost of an edge is equal to the distance between the two points it connects.
They want to do this in such a way that they will both see that all the points are connected (either directly or indirectly).
However, there is a catch: Roy cannot see the color red and Biv cannot see the color blue.
Therefore, they have to choose the edges in such a way that if all the red points are removed, the remaining blue and green points are connected (and similarly, if all the blue points are removed, the remaining red and green points are connected).
Help them compute the minimum cost way to choose edges to satisfy the above constraints.
Input
The first line will contain an integer n (1 ≤ n ≤ 300 000), the number of points.
The next n lines will contain two tokens pi and ci (pi is an integer, 1 ≤ pi ≤ 109, ci is a uppercase English letter 'R', 'G' or 'B'), denoting the position of the i-th point and the color of the i-th point. 'R' means red, 'G' denotes green, and 'B' means blue. The positions will be in strictly increasing order.
Output
Print a single integer, the minimum cost way to solve the problem.
Examples
Input
4
1 G
5 R
10 B
15 G
Output
23
Input
4
1 G
2 R
3 B
10 G
Output
12
Note
In the first sample, it is optimal to draw edges between the points (1,2), (1,4), (3,4). These have costs 4, 14, 5, respectively.
Submitted Solution:
```
n = int(input());
A = [];
B = [];
for q in range(n):
a, b = input().split();
B.append(int(a));
A.append(b);
g1 = -100000000000;
g2 = -100000000000;
blues = [];
reds = [];
res = 0;
for q in range(n):
if A[q] == "B":
blues.append(B[q]);
if A[q] == "R":
reds.append(B[q]);
if A[q] == "G":
g1 = g2;
g2 = B[q];
for w in range(1, len(blues)):
res = res + blues[w] - blues[w - 1];
for e in range(1, len(reds)):
res = res + reds[e] - reds[e - 1];
if len(blues) > 0:
resb = min(blues[0] - g1, g2 - blues[len(blues) - 1]);
bl = max(blues[0] - g1, g2 - blues[len(blues) - 1]);
else:
resb = 0;
bl = 10000000000;
if len(reds) > 0:
resr = min(reds[0] - g1, g2 - reds[len(reds) - 1]);
rl = max(reds[0] - g1, g2 - reds[len(reds) - 1]);
else:
resr = 0;
rl = 100000000000;
res = res + resb + resr;
if g1 != -100000000000:
#print(res);
res = res + min(g2 - g1, bl + rl);
#if g1 != -100000000000:
# mi = g2 - g1;
# if bl
blues = [];
reds = [];
if g2 != -100000000000:
if len(blues) > 0:
res = res + blues[0] - g2;
if len(reds) > 0:
res = res + reds[0] - g2;
for q in range(1, len(blues)):
res = res + blues[q] - blues[q - 1];
for q in range(1, len(reds)):
res = res + reds[q] - reds[q - 1];
print(res);
``` | instruction | 0 | 523 | 7 | 1,046 |
No | output | 1 | 523 | 7 | 1,047 |
Provide tags and a correct Python 3 solution for this coding contest problem.
President of Berland has a very vast office-room, where, apart from him, work his subordinates. Each subordinate, as well as President himself, has his own desk of a unique colour. Each desk is rectangular, and its sides are parallel to the office walls. One day President decided to establish an assembly, of which all his deputies will be members. Unfortunately, he does not remember the exact amount of his deputies, but he remembers that the desk of each his deputy is adjacent to his own desk, that is to say, the two desks (President's and each deputy's) have a common side of a positive length.
The office-room plan can be viewed as a matrix with n rows and m columns. Each cell of this matrix is either empty, or contains a part of a desk. An uppercase Latin letter stands for each desk colour. The «period» character («.») stands for an empty cell.
Input
The first line contains two separated by a space integer numbers n, m (1 ≤ n, m ≤ 100) — the length and the width of the office-room, and c character — the President's desk colour. The following n lines contain m characters each — the office-room description. It is guaranteed that the colour of each desk is unique, and each desk represents a continuous subrectangle of the given matrix. All colours are marked by uppercase Latin letters.
Output
Print the only number — the amount of President's deputies.
Examples
Input
3 4 R
G.B.
.RR.
TTT.
Output
2
Input
3 3 Z
...
.H.
..Z
Output
0 | instruction | 0 | 1,317 | 7 | 2,634 |
Tags: implementation
Correct Solution:
```
n , m , p = input().strip().split(' ')
n , m = int(n), int(m)
M = [[None for _ in range(m)] for _ in range(n)]
for i in range(n):
s = input().strip()
for j in range(m):
M[i][j] = s[j]
T = [[False for _ in range(m)] for _ in range(n)]
for i in range(n):
for j in range(m):
if M[i][j] == p:
a , b , c , d , e , f , g , h = i , j - 1 , i , j + 1 , i - 1 , j , i + 1 , j
if 0 <= a < n and 0 <= b < m:
T[a][b] = True
if 0 <= c < n and 0 <= d < m:
T[c][d] = True
if 0 <= e < n and 0 <= f < m:
T[e][f] = True
if 0 <= g < n and 0 <= h < m:
T[g][h] = True
ans = 0
x = [False for _ in range(26)]
for i in range(n):
for j in range(m):
c = M[i][j]
if c != '.' and c != p:
if T[i][j] == True and x[ord(c)- ord('A')] == False:
x[ord(c)-ord('A')] = True
ans += 1
print(ans)
``` | output | 1 | 1,317 | 7 | 2,635 |
Provide tags and a correct Python 3 solution for this coding contest problem.
President of Berland has a very vast office-room, where, apart from him, work his subordinates. Each subordinate, as well as President himself, has his own desk of a unique colour. Each desk is rectangular, and its sides are parallel to the office walls. One day President decided to establish an assembly, of which all his deputies will be members. Unfortunately, he does not remember the exact amount of his deputies, but he remembers that the desk of each his deputy is adjacent to his own desk, that is to say, the two desks (President's and each deputy's) have a common side of a positive length.
The office-room plan can be viewed as a matrix with n rows and m columns. Each cell of this matrix is either empty, or contains a part of a desk. An uppercase Latin letter stands for each desk colour. The «period» character («.») stands for an empty cell.
Input
The first line contains two separated by a space integer numbers n, m (1 ≤ n, m ≤ 100) — the length and the width of the office-room, and c character — the President's desk colour. The following n lines contain m characters each — the office-room description. It is guaranteed that the colour of each desk is unique, and each desk represents a continuous subrectangle of the given matrix. All colours are marked by uppercase Latin letters.
Output
Print the only number — the amount of President's deputies.
Examples
Input
3 4 R
G.B.
.RR.
TTT.
Output
2
Input
3 3 Z
...
.H.
..Z
Output
0 | instruction | 0 | 1,318 | 7 | 2,636 |
Tags: implementation
Correct Solution:
```
t=list(map(str,input().split()))
a=[]
for _ in range(int(t[0])):
a.append(input())
r=[]
#print(a)
n=int(t[0])
m=int(t[1])
for i in range(n-1):
for j in range(m-1):
if a[i][j]!='.' and a[i][j+1]==t[2] and a[i][j]!=t[2]:
r.append(a[i][j])
if a[i][j]==t[2] and a[i+1][j]!='.' and a[i+1][j]!=t[2]:
r.append(a[i+1][j])
if a[i][j]==t[2] and a[i][j+1]!=t[2] and a[i][j+1]!='.':
r.append(a[i][j+1])
if a[i][j]!='.' and a[i+1][j]==t[2] and a[i][j]!=t[2]:
r.append(a[i][j])
for i in range(n-1):
if a[i][m-1]==t[2] and a[i+1][m-1]!='.' and a[i+1][m-1]!=t[2]:
r.append(a[i+1][m-1])
if a[i][m-1]!='.' and a[i+1][m-1]==t[2] and a[i][m-1]!=t[2]:
r.append(a[i][m-1])
for i in range(m-1):
if a[n-1][i]==t[2] and a[n-1][i+1]!='.' and a[n-1][i+1]!=t[2]:
r.append(a[n-1][i+1])
if a[n-1][i]!='.' and a[n-1][i+1]==t[2] and a[n-1][i]!=t[2]:
r.append(a[n-1][i])
#print(r)
r=set(r)
print(len(r))
``` | output | 1 | 1,318 | 7 | 2,637 |
Provide tags and a correct Python 3 solution for this coding contest problem.
President of Berland has a very vast office-room, where, apart from him, work his subordinates. Each subordinate, as well as President himself, has his own desk of a unique colour. Each desk is rectangular, and its sides are parallel to the office walls. One day President decided to establish an assembly, of which all his deputies will be members. Unfortunately, he does not remember the exact amount of his deputies, but he remembers that the desk of each his deputy is adjacent to his own desk, that is to say, the two desks (President's and each deputy's) have a common side of a positive length.
The office-room plan can be viewed as a matrix with n rows and m columns. Each cell of this matrix is either empty, or contains a part of a desk. An uppercase Latin letter stands for each desk colour. The «period» character («.») stands for an empty cell.
Input
The first line contains two separated by a space integer numbers n, m (1 ≤ n, m ≤ 100) — the length and the width of the office-room, and c character — the President's desk colour. The following n lines contain m characters each — the office-room description. It is guaranteed that the colour of each desk is unique, and each desk represents a continuous subrectangle of the given matrix. All colours are marked by uppercase Latin letters.
Output
Print the only number — the amount of President's deputies.
Examples
Input
3 4 R
G.B.
.RR.
TTT.
Output
2
Input
3 3 Z
...
.H.
..Z
Output
0 | instruction | 0 | 1,319 | 7 | 2,638 |
Tags: implementation
Correct Solution:
```
a = input().split()
n = int(a[0])
m = int(a[1])
c = a[2]
k = []
d = []
b = []
for i in range(n):
st = input()
k.append(st)
for i in range(n):
for j in range(m):
if k[i][j] == c:
d.append([i, j])
b.append(c)
for i in range(len(d)):
if d[i][0] != 0:
if k[d[i][0] - 1][d[i][1]] != "." and k[d[i][0] - 1][d[i][1]] not in b:
b.append(k[d[i][0] - 1][d[i][1]])
if d[i][1] != 0:
if k[d[i][0]][d[i][1] - 1] != "." and k[d[i][0]][d[i][1] - 1] not in b:
b.append(k[d[i][0]][d[i][1] - 1])
if d[i][0] != n - 1:
if k[d[i][0] + 1][d[i][1]] != "." and k[d[i][0] + 1][d[i][1]] not in b:
b.append(k[d[i][0] + 1][d[i][1]])
if d[i][1] != m - 1:
if k[d[i][0]][d[i][1] + 1] != "." and k[d[i][0]][d[i][1] + 1] not in b:
b.append(k[d[i][0]][d[i][1] + 1])
print(len(b) - 1)
``` | output | 1 | 1,319 | 7 | 2,639 |
Provide tags and a correct Python 3 solution for this coding contest problem.
President of Berland has a very vast office-room, where, apart from him, work his subordinates. Each subordinate, as well as President himself, has his own desk of a unique colour. Each desk is rectangular, and its sides are parallel to the office walls. One day President decided to establish an assembly, of which all his deputies will be members. Unfortunately, he does not remember the exact amount of his deputies, but he remembers that the desk of each his deputy is adjacent to his own desk, that is to say, the two desks (President's and each deputy's) have a common side of a positive length.
The office-room plan can be viewed as a matrix with n rows and m columns. Each cell of this matrix is either empty, or contains a part of a desk. An uppercase Latin letter stands for each desk colour. The «period» character («.») stands for an empty cell.
Input
The first line contains two separated by a space integer numbers n, m (1 ≤ n, m ≤ 100) — the length and the width of the office-room, and c character — the President's desk colour. The following n lines contain m characters each — the office-room description. It is guaranteed that the colour of each desk is unique, and each desk represents a continuous subrectangle of the given matrix. All colours are marked by uppercase Latin letters.
Output
Print the only number — the amount of President's deputies.
Examples
Input
3 4 R
G.B.
.RR.
TTT.
Output
2
Input
3 3 Z
...
.H.
..Z
Output
0 | instruction | 0 | 1,320 | 7 | 2,640 |
Tags: implementation
Correct Solution:
```
n, m, c = input().split()
n, m = map(int, (n, m))
a = [input() for i in range(n)]
s = set()
d = (0, 1), (1, 0), (0, -1), (-1, 0)
cor = lambda x, y: 0 <= x < n and 0 <= y < m
for i in range(n):
for j in range(m):
if a[i][j] == c:
for dx, dy in d:
ni, nj = i + dx, j + dy
if cor(ni, nj):
s.add(a[ni][nj])
s.discard('.')
s.discard(c)
ans = len(s)
print(ans)
``` | output | 1 | 1,320 | 7 | 2,641 |
Provide tags and a correct Python 3 solution for this coding contest problem.
President of Berland has a very vast office-room, where, apart from him, work his subordinates. Each subordinate, as well as President himself, has his own desk of a unique colour. Each desk is rectangular, and its sides are parallel to the office walls. One day President decided to establish an assembly, of which all his deputies will be members. Unfortunately, he does not remember the exact amount of his deputies, but he remembers that the desk of each his deputy is adjacent to his own desk, that is to say, the two desks (President's and each deputy's) have a common side of a positive length.
The office-room plan can be viewed as a matrix with n rows and m columns. Each cell of this matrix is either empty, or contains a part of a desk. An uppercase Latin letter stands for each desk colour. The «period» character («.») stands for an empty cell.
Input
The first line contains two separated by a space integer numbers n, m (1 ≤ n, m ≤ 100) — the length and the width of the office-room, and c character — the President's desk colour. The following n lines contain m characters each — the office-room description. It is guaranteed that the colour of each desk is unique, and each desk represents a continuous subrectangle of the given matrix. All colours are marked by uppercase Latin letters.
Output
Print the only number — the amount of President's deputies.
Examples
Input
3 4 R
G.B.
.RR.
TTT.
Output
2
Input
3 3 Z
...
.H.
..Z
Output
0 | instruction | 0 | 1,321 | 7 | 2,642 |
Tags: implementation
Correct Solution:
```
# Fast IO
import sys
input = sys.stdin.readline
def print(x, end='\n'):
sys.stdout.write(str(x) + end)
# IO helpers
def get_int():
return int(input())
def get_list_ints():
return list(map(int, input().split()))
def get_char_list():
s = input()
return list(s[:len(s) - 1])
def get_tuple_ints():
return tuple(map(int, input().split()))
def print_iterable(p):
print(" ".join(map(str, p)))
#Code
def main():
n, m, c = input().split()
n=int(n)
m=int(m)
a=[]
a=[get_char_list() for _ in range(n)]
d=[]
for i in range(n):
for j in range(m):
if a[i][j]==c:
if i!=0:
if a[i-1][j]!=c and a[i-1][j]!='.' and a[i-1][j] not in d:
d+=[a[i-1][j]]
if j!=0:
if a[i][j-1]!=c and a[i][j-1]!='.' and a[i][j-1] not in d:
d+=[a[i][j-1]]
if i!=n-1:
if a[i+1][j]!=c and a[i+1][j]!='.' and a[i+1][j] not in d:
d+=[a[i+1][j]]
if j!=m-1:
if a[i][j+1]!=c and a[i][j+1]!='.' and a[i][j+1] not in d:
d+=[a[i][j+1]]
print(len(d))
if __name__=='__main__':
main()
``` | output | 1 | 1,321 | 7 | 2,643 |
Provide tags and a correct Python 3 solution for this coding contest problem.
President of Berland has a very vast office-room, where, apart from him, work his subordinates. Each subordinate, as well as President himself, has his own desk of a unique colour. Each desk is rectangular, and its sides are parallel to the office walls. One day President decided to establish an assembly, of which all his deputies will be members. Unfortunately, he does not remember the exact amount of his deputies, but he remembers that the desk of each his deputy is adjacent to his own desk, that is to say, the two desks (President's and each deputy's) have a common side of a positive length.
The office-room plan can be viewed as a matrix with n rows and m columns. Each cell of this matrix is either empty, or contains a part of a desk. An uppercase Latin letter stands for each desk colour. The «period» character («.») stands for an empty cell.
Input
The first line contains two separated by a space integer numbers n, m (1 ≤ n, m ≤ 100) — the length and the width of the office-room, and c character — the President's desk colour. The following n lines contain m characters each — the office-room description. It is guaranteed that the colour of each desk is unique, and each desk represents a continuous subrectangle of the given matrix. All colours are marked by uppercase Latin letters.
Output
Print the only number — the amount of President's deputies.
Examples
Input
3 4 R
G.B.
.RR.
TTT.
Output
2
Input
3 3 Z
...
.H.
..Z
Output
0 | instruction | 0 | 1,322 | 7 | 2,644 |
Tags: implementation
Correct Solution:
```
m, n, c = input().split()
m = int(m)
n = int(n)
a = [[j for j in input()]for i in range(m)]
inxs = list()
con = list()
fin = list()
for i in range(m):
for j in range(n):
if a[i][j] == c:
inxs.append(i)
inxs.append(j)
# if i == 0:
# if j == 0:
# if (a[0][1] != '.') & (a[0][1] != c):
# con += 1
# if (a[1][0] != '.') & (a[1][0] != c):
# con += 1
# if j == n-1:
# if (a[0][n-2] != '.') & (a[0][n-2] != c):
# con += 1
# if (a[1][n-1] != '.') & (a[1][n-1] != c):
# con += 1
# if i == m-1:
# if j == 0:
# if (a[m-1][1] != '.') & (a[m-1][1] != c):
# con += 1
# if (a[m-2][0] != '.') & (a[m-2][0] != c):
# con += 1
# if j == n-1:
# if (a[m-1][n-2] != '.') & (a[m-1][n-2] != c):
# con += 1
# if (a[m-2][n-1] != '.') & (a[m-2][n-1] != c):
# con += 1
for i in range(0, len(inxs), 2):
if inxs[i+1] > 0:
if (a[inxs[i]][inxs[i+1]-1] != c) & (a[inxs[i]][inxs[i+1]-1] != '.'):
con.append(a[inxs[i]][inxs[i+1]-1])
if inxs[i+1] < n-1:
if (a[inxs[i]][inxs[i+1]+1] != c) & (a[inxs[i]][inxs[i+1]+1] != '.'):
con.append(a[inxs[i]][inxs[i+1]+1])
if inxs[i] > 0:
if (a[inxs[i]-1][inxs[i+1]] != c) & (a[inxs[i]-1][inxs[i+1]] != '.'):
con.append(a[inxs[i]-1][inxs[i+1]])
if inxs[i] < m-1:
if (a[inxs[i]+1][inxs[i+1]] != c) & (a[inxs[i]+1][inxs[i+1]] != '.'):
con.append(a[inxs[i]+1][inxs[i+1]])
for i in con:
if i not in fin:
fin.append(i)
print(len(fin))
# def index_2d(a, c):
# for i, e in enumerate(a):
# try:
# return i, e.index(c)
# except ValueError:
# pass
# raise ValueError("{} is not in list".format(repr(c)))
# print(index_2d(a, c))
``` | output | 1 | 1,322 | 7 | 2,645 |
Provide tags and a correct Python 3 solution for this coding contest problem.
President of Berland has a very vast office-room, where, apart from him, work his subordinates. Each subordinate, as well as President himself, has his own desk of a unique colour. Each desk is rectangular, and its sides are parallel to the office walls. One day President decided to establish an assembly, of which all his deputies will be members. Unfortunately, he does not remember the exact amount of his deputies, but he remembers that the desk of each his deputy is adjacent to his own desk, that is to say, the two desks (President's and each deputy's) have a common side of a positive length.
The office-room plan can be viewed as a matrix with n rows and m columns. Each cell of this matrix is either empty, or contains a part of a desk. An uppercase Latin letter stands for each desk colour. The «period» character («.») stands for an empty cell.
Input
The first line contains two separated by a space integer numbers n, m (1 ≤ n, m ≤ 100) — the length and the width of the office-room, and c character — the President's desk colour. The following n lines contain m characters each — the office-room description. It is guaranteed that the colour of each desk is unique, and each desk represents a continuous subrectangle of the given matrix. All colours are marked by uppercase Latin letters.
Output
Print the only number — the amount of President's deputies.
Examples
Input
3 4 R
G.B.
.RR.
TTT.
Output
2
Input
3 3 Z
...
.H.
..Z
Output
0 | instruction | 0 | 1,323 | 7 | 2,646 |
Tags: implementation
Correct Solution:
```
n,m,c = input().split(" ")
n = int(n)
m = int(m)
M = []
temp = []
for i in range(m+2):
temp.append('.')
M.append(temp)
for i in range(0,n):
k = list(input())
k.insert(0,'.')
k.insert(len(k),'.')
M.append(k)
M.append(temp)
#print(M)
d={}
for i in range(1,n+1):
for j in range(1,m+1):
#print(M[i][j])
if M[i][j]==c :
if M[i][j+1]!=c and M[i][j+1]!='.':
d[M[i][j+1]] =1
if M[i+1][j]!=c and M[i+1][j]!='.':
d[M[i+1][j]] =1
if M[i][j-1]!=c and M[i][j-1]!='.':
d[M[i][j-1]] =1
if M[i-1][j]!=c and M[i-1][j]!='.':
d[M[i-1][j]] =1
print(len(d))
``` | output | 1 | 1,323 | 7 | 2,647 |
Provide tags and a correct Python 3 solution for this coding contest problem.
President of Berland has a very vast office-room, where, apart from him, work his subordinates. Each subordinate, as well as President himself, has his own desk of a unique colour. Each desk is rectangular, and its sides are parallel to the office walls. One day President decided to establish an assembly, of which all his deputies will be members. Unfortunately, he does not remember the exact amount of his deputies, but he remembers that the desk of each his deputy is adjacent to his own desk, that is to say, the two desks (President's and each deputy's) have a common side of a positive length.
The office-room plan can be viewed as a matrix with n rows and m columns. Each cell of this matrix is either empty, or contains a part of a desk. An uppercase Latin letter stands for each desk colour. The «period» character («.») stands for an empty cell.
Input
The first line contains two separated by a space integer numbers n, m (1 ≤ n, m ≤ 100) — the length and the width of the office-room, and c character — the President's desk colour. The following n lines contain m characters each — the office-room description. It is guaranteed that the colour of each desk is unique, and each desk represents a continuous subrectangle of the given matrix. All colours are marked by uppercase Latin letters.
Output
Print the only number — the amount of President's deputies.
Examples
Input
3 4 R
G.B.
.RR.
TTT.
Output
2
Input
3 3 Z
...
.H.
..Z
Output
0 | instruction | 0 | 1,324 | 7 | 2,648 |
Tags: implementation
Correct Solution:
```
rows, columns, color = input().split()
rows = int(rows)
columns = int(columns)
mat = []
desk = {color}
for i in range(rows):
mat.append(list(input()))
for i in range(len(mat)):
for j in range(columns):
if mat[i][j] != '.':
if j+1 < columns:
if mat[i][j+1] == color:
desk.add(mat[i][j])
if j-1 >=0:
if mat[i][j-1] == color:
desk.add(mat[i][j])
if i+1 < rows:
if mat[i+1][j] == color:
desk.add(mat[i][j])
if i-1 >=0:
if mat[i-1][j] == color:
desk.add(mat[i][j])
print(len(desk)-1)
``` | output | 1 | 1,324 | 7 | 2,649 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
President of Berland has a very vast office-room, where, apart from him, work his subordinates. Each subordinate, as well as President himself, has his own desk of a unique colour. Each desk is rectangular, and its sides are parallel to the office walls. One day President decided to establish an assembly, of which all his deputies will be members. Unfortunately, he does not remember the exact amount of his deputies, but he remembers that the desk of each his deputy is adjacent to his own desk, that is to say, the two desks (President's and each deputy's) have a common side of a positive length.
The office-room plan can be viewed as a matrix with n rows and m columns. Each cell of this matrix is either empty, or contains a part of a desk. An uppercase Latin letter stands for each desk colour. The «period» character («.») stands for an empty cell.
Input
The first line contains two separated by a space integer numbers n, m (1 ≤ n, m ≤ 100) — the length and the width of the office-room, and c character — the President's desk colour. The following n lines contain m characters each — the office-room description. It is guaranteed that the colour of each desk is unique, and each desk represents a continuous subrectangle of the given matrix. All colours are marked by uppercase Latin letters.
Output
Print the only number — the amount of President's deputies.
Examples
Input
3 4 R
G.B.
.RR.
TTT.
Output
2
Input
3 3 Z
...
.H.
..Z
Output
0
Submitted Solution:
```
n,m,pres=input().split()
n,m=int(n),int(m)
l=[]
for i in range(n):
l1=list(input())
l.append(l1)
ans=[]
for i in range(n):
for j in range(m):
if l[i][j]==pres:
if i-1>=0:
ans.append(l[i-1][j])
if i+1<n:
ans.append(l[i+1][j])
if j-1>=0:
ans.append(l[i][j-1])
if j+1<m:
ans.append(l[i][j+1])
ans=set(ans)
ans.discard('.')
ans.discard(pres)
print(len(set(ans)))
``` | instruction | 0 | 1,325 | 7 | 2,650 |
Yes | output | 1 | 1,325 | 7 | 2,651 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
President of Berland has a very vast office-room, where, apart from him, work his subordinates. Each subordinate, as well as President himself, has his own desk of a unique colour. Each desk is rectangular, and its sides are parallel to the office walls. One day President decided to establish an assembly, of which all his deputies will be members. Unfortunately, he does not remember the exact amount of his deputies, but he remembers that the desk of each his deputy is adjacent to his own desk, that is to say, the two desks (President's and each deputy's) have a common side of a positive length.
The office-room plan can be viewed as a matrix with n rows and m columns. Each cell of this matrix is either empty, or contains a part of a desk. An uppercase Latin letter stands for each desk colour. The «period» character («.») stands for an empty cell.
Input
The first line contains two separated by a space integer numbers n, m (1 ≤ n, m ≤ 100) — the length and the width of the office-room, and c character — the President's desk colour. The following n lines contain m characters each — the office-room description. It is guaranteed that the colour of each desk is unique, and each desk represents a continuous subrectangle of the given matrix. All colours are marked by uppercase Latin letters.
Output
Print the only number — the amount of President's deputies.
Examples
Input
3 4 R
G.B.
.RR.
TTT.
Output
2
Input
3 3 Z
...
.H.
..Z
Output
0
Submitted Solution:
```
n,m,c = input().split()
n = int(n)
m = int(m)
office = ''
for i in range(n):
office += input()
x,y=office.index(c),office.rindex(c)
colours={}
for i in range(len(office)):
if office[i]!='.' and office[i]!=c and ((x%m-1==i%m or i%m==y%m+1) and x//m<=i//m<=y//m or (int(x/m)-1==int(i/m) or int(i/m)==int(y/m)+1) and x%m<=i%m<=y%m):
colours[office[i]]=1
print(len(colours))
``` | instruction | 0 | 1,326 | 7 | 2,652 |
Yes | output | 1 | 1,326 | 7 | 2,653 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
President of Berland has a very vast office-room, where, apart from him, work his subordinates. Each subordinate, as well as President himself, has his own desk of a unique colour. Each desk is rectangular, and its sides are parallel to the office walls. One day President decided to establish an assembly, of which all his deputies will be members. Unfortunately, he does not remember the exact amount of his deputies, but he remembers that the desk of each his deputy is adjacent to his own desk, that is to say, the two desks (President's and each deputy's) have a common side of a positive length.
The office-room plan can be viewed as a matrix with n rows and m columns. Each cell of this matrix is either empty, or contains a part of a desk. An uppercase Latin letter stands for each desk colour. The «period» character («.») stands for an empty cell.
Input
The first line contains two separated by a space integer numbers n, m (1 ≤ n, m ≤ 100) — the length and the width of the office-room, and c character — the President's desk colour. The following n lines contain m characters each — the office-room description. It is guaranteed that the colour of each desk is unique, and each desk represents a continuous subrectangle of the given matrix. All colours are marked by uppercase Latin letters.
Output
Print the only number — the amount of President's deputies.
Examples
Input
3 4 R
G.B.
.RR.
TTT.
Output
2
Input
3 3 Z
...
.H.
..Z
Output
0
Submitted Solution:
```
n , m , c = input().split()
n = int(n)
m = int(m)
matrix = []
for i in range(n):
matrix.append(input())
count = 0
d = {}
for i in range(n):
val = matrix[i]
for j in range(m):
if(val[j]==c):
if(i-1>=0 and matrix[i-1][j]!=c and matrix[i-1][j]!='.' and matrix[i-1][j] not in d):
count+=1
v = matrix[i-1][j]
d[v] = 1
if(j-1>=0 and matrix[i][j-1]!=c and matrix[i][j-1]!='.' and matrix[i][j-1] not in d):
count+=1
v = matrix[i][j-1]
d[v]=1
if(j+1<m and matrix[i][j+1]!=c and matrix[i][j+1]!='.' and matrix[i][j+1] not in d):
count+=1
v = matrix[i][j+1]
d[v] = 1
if(i+1<n and matrix[i+1][j]!=c and matrix[i+1][j]!='.' and matrix[i+1][j] not in d):
count+=1
v = matrix[i+1][j]
d[v] = 1
print(count)
``` | instruction | 0 | 1,327 | 7 | 2,654 |
Yes | output | 1 | 1,327 | 7 | 2,655 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
President of Berland has a very vast office-room, where, apart from him, work his subordinates. Each subordinate, as well as President himself, has his own desk of a unique colour. Each desk is rectangular, and its sides are parallel to the office walls. One day President decided to establish an assembly, of which all his deputies will be members. Unfortunately, he does not remember the exact amount of his deputies, but he remembers that the desk of each his deputy is adjacent to his own desk, that is to say, the two desks (President's and each deputy's) have a common side of a positive length.
The office-room plan can be viewed as a matrix with n rows and m columns. Each cell of this matrix is either empty, or contains a part of a desk. An uppercase Latin letter stands for each desk colour. The «period» character («.») stands for an empty cell.
Input
The first line contains two separated by a space integer numbers n, m (1 ≤ n, m ≤ 100) — the length and the width of the office-room, and c character — the President's desk colour. The following n lines contain m characters each — the office-room description. It is guaranteed that the colour of each desk is unique, and each desk represents a continuous subrectangle of the given matrix. All colours are marked by uppercase Latin letters.
Output
Print the only number — the amount of President's deputies.
Examples
Input
3 4 R
G.B.
.RR.
TTT.
Output
2
Input
3 3 Z
...
.H.
..Z
Output
0
Submitted Solution:
```
def solution(n,m,c,lists):
deputies = {}
x = []
ans = 0
for _x,l in enumerate(lists):
for _y,d in enumerate(l):
if d == c:
x.append((_x,_y))
else:
if d!='.' and d not in deputies:
deputies[d] = False
for _x,l in enumerate(lists):
for _y,d in enumerate(l):
if d in deputies:
if not deputies[d] and ((_x+1,_y) in x or (_x-1,_y) in x or (_x,_y+1) in x or (_x,_y-1) in x):
ans+=1
deputies[d] = True
return ans
n,m,c = input().split(' ')
n = int(n)
m = int(m)
lists = []
for x in range(n):
lists.append(list(input()))
print(solution(n,m,c,lists))
``` | instruction | 0 | 1,328 | 7 | 2,656 |
Yes | output | 1 | 1,328 | 7 | 2,657 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
President of Berland has a very vast office-room, where, apart from him, work his subordinates. Each subordinate, as well as President himself, has his own desk of a unique colour. Each desk is rectangular, and its sides are parallel to the office walls. One day President decided to establish an assembly, of which all his deputies will be members. Unfortunately, he does not remember the exact amount of his deputies, but he remembers that the desk of each his deputy is adjacent to his own desk, that is to say, the two desks (President's and each deputy's) have a common side of a positive length.
The office-room plan can be viewed as a matrix with n rows and m columns. Each cell of this matrix is either empty, or contains a part of a desk. An uppercase Latin letter stands for each desk colour. The «period» character («.») stands for an empty cell.
Input
The first line contains two separated by a space integer numbers n, m (1 ≤ n, m ≤ 100) — the length and the width of the office-room, and c character — the President's desk colour. The following n lines contain m characters each — the office-room description. It is guaranteed that the colour of each desk is unique, and each desk represents a continuous subrectangle of the given matrix. All colours are marked by uppercase Latin letters.
Output
Print the only number — the amount of President's deputies.
Examples
Input
3 4 R
G.B.
.RR.
TTT.
Output
2
Input
3 3 Z
...
.H.
..Z
Output
0
Submitted Solution:
```
def find_color(room, color):
for i, line in enumerate(room):
j = line.find(color)
if j != -1:
return (i, j)
inp = input().split()
height, width = [int(i) for i in inp[:2]]
color = inp[2]
room = []
for i in range(height):
room.append(input())
y, x = find_color(room, color)
adyacents = set()
i = x
j = y
# print(i, j)
if y > 0:
while i < width and room[y][i] == color:
# print(f"checking {(y - 1, i)}: {room[y - 1][i]}")
adyacents.add(room[y - 1][i])
i += 1
if x > 0:
while j < height and room[j][x]:
# print(f"checking {(j, x - 1)}: {room[j][x - 1]}")
adyacents.add(room[j][x - 1])
j += 1
# print(i, j)
if i < width - 1:
i -= 1
while y < height and room[y][i] == color:
# print(f"checking {(y, i + 1)}: {room[y - 1][i]}")
adyacents.add(room[y][i + 1])
y += 1
if j < height - 1:
j -= 1
while x < width and room[j][x] == color:
# print(f"checking {(j + 1, x)}: {room[j + 1][x]}")
adyacents.add(room[j + 1][x])
x += 1
# print(adyacents)
result = len(adyacents)
if '.' in adyacents:
result -= 1
if color in adyacents:
result -= 1
print(result)
``` | instruction | 0 | 1,329 | 7 | 2,658 |
No | output | 1 | 1,329 | 7 | 2,659 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
President of Berland has a very vast office-room, where, apart from him, work his subordinates. Each subordinate, as well as President himself, has his own desk of a unique colour. Each desk is rectangular, and its sides are parallel to the office walls. One day President decided to establish an assembly, of which all his deputies will be members. Unfortunately, he does not remember the exact amount of his deputies, but he remembers that the desk of each his deputy is adjacent to his own desk, that is to say, the two desks (President's and each deputy's) have a common side of a positive length.
The office-room plan can be viewed as a matrix with n rows and m columns. Each cell of this matrix is either empty, or contains a part of a desk. An uppercase Latin letter stands for each desk colour. The «period» character («.») stands for an empty cell.
Input
The first line contains two separated by a space integer numbers n, m (1 ≤ n, m ≤ 100) — the length and the width of the office-room, and c character — the President's desk colour. The following n lines contain m characters each — the office-room description. It is guaranteed that the colour of each desk is unique, and each desk represents a continuous subrectangle of the given matrix. All colours are marked by uppercase Latin letters.
Output
Print the only number — the amount of President's deputies.
Examples
Input
3 4 R
G.B.
.RR.
TTT.
Output
2
Input
3 3 Z
...
.H.
..Z
Output
0
Submitted Solution:
```
if __name__ == '__main__':
n, m, color = input().split()
n = int(n)
m = int(m)
mat = []
indi = []
indj = []
dep = []
for i in range(n):
ar = input()
for j in range(m):
if ar[j] == color:
indi.append(i)
indj.append(j)
mat.append(ar)
l = len(indi)
for k in range(l):
i = indi[k]
j = indj[k]
if i+1 < n and j < m:
if mat[i+1][j] != 'R' and mat[i+1][j] != '.':
dep.append(mat[i+1][j])
if i < n and j+1 < m:
if mat[i][j+1] != 'R' and mat[i][j+1] != '.':
dep.append(mat[i][j+1])
if i-1 >=0 and j < m:
if mat[i-1][j] != 'R' and mat[i-1][j] != '.':
dep.append(mat[i-1][j])
if i < n and j-1>= 0:
if mat[i][j-1] != 'R' and mat[i][j-1] != '.':
dep.append(mat[i][j-1])
d = set(dep)
ans = len(d)
print(ans)
``` | instruction | 0 | 1,330 | 7 | 2,660 |
No | output | 1 | 1,330 | 7 | 2,661 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
President of Berland has a very vast office-room, where, apart from him, work his subordinates. Each subordinate, as well as President himself, has his own desk of a unique colour. Each desk is rectangular, and its sides are parallel to the office walls. One day President decided to establish an assembly, of which all his deputies will be members. Unfortunately, he does not remember the exact amount of his deputies, but he remembers that the desk of each his deputy is adjacent to his own desk, that is to say, the two desks (President's and each deputy's) have a common side of a positive length.
The office-room plan can be viewed as a matrix with n rows and m columns. Each cell of this matrix is either empty, or contains a part of a desk. An uppercase Latin letter stands for each desk colour. The «period» character («.») stands for an empty cell.
Input
The first line contains two separated by a space integer numbers n, m (1 ≤ n, m ≤ 100) — the length and the width of the office-room, and c character — the President's desk colour. The following n lines contain m characters each — the office-room description. It is guaranteed that the colour of each desk is unique, and each desk represents a continuous subrectangle of the given matrix. All colours are marked by uppercase Latin letters.
Output
Print the only number — the amount of President's deputies.
Examples
Input
3 4 R
G.B.
.RR.
TTT.
Output
2
Input
3 3 Z
...
.H.
..Z
Output
0
Submitted Solution:
```
n,m,z=map(str,input().split())
r=[]
for _ in range(int(n)):
d=input()
r.append(d)
ans=[]
for i in range(int(n)):
for j in range(int(m)):
if r[i][j]==z:
#print(i,j,r[i][j])
try:
if r[i-1][j]!=z and r[i-1][j]!='.' and i>=0:
ans.append(r[i-1][j])
#print(ans,i,j)
if r[i][j-1]!=z and r[i][j-1]!='.'and j>=0:
ans.append(r[i][j-1])
#print(ans,i,j)
if r[i+1][j]!=z and r[i+1][j]!='.':
ans.append(r[i+1][j])
#print(ans,i,j)
if r[i][j+1]!=z and r[i][j+1]!='.':
ans.append(r[i][j+1])
#print(ans,i,j)
except:
pass
print(len(set(ans)))
#print(ans)
``` | instruction | 0 | 1,331 | 7 | 2,662 |
No | output | 1 | 1,331 | 7 | 2,663 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
President of Berland has a very vast office-room, where, apart from him, work his subordinates. Each subordinate, as well as President himself, has his own desk of a unique colour. Each desk is rectangular, and its sides are parallel to the office walls. One day President decided to establish an assembly, of which all his deputies will be members. Unfortunately, he does not remember the exact amount of his deputies, but he remembers that the desk of each his deputy is adjacent to his own desk, that is to say, the two desks (President's and each deputy's) have a common side of a positive length.
The office-room plan can be viewed as a matrix with n rows and m columns. Each cell of this matrix is either empty, or contains a part of a desk. An uppercase Latin letter stands for each desk colour. The «period» character («.») stands for an empty cell.
Input
The first line contains two separated by a space integer numbers n, m (1 ≤ n, m ≤ 100) — the length and the width of the office-room, and c character — the President's desk colour. The following n lines contain m characters each — the office-room description. It is guaranteed that the colour of each desk is unique, and each desk represents a continuous subrectangle of the given matrix. All colours are marked by uppercase Latin letters.
Output
Print the only number — the amount of President's deputies.
Examples
Input
3 4 R
G.B.
.RR.
TTT.
Output
2
Input
3 3 Z
...
.H.
..Z
Output
0
Submitted Solution:
```
list = []
list2 = []
deputies = 0
x,y,c = input().split()
for i in range(int(x)):
lst = input()
list.append(lst)
for i in range(int(x)):
for j in range(int(y)):
if list[i][j] == c:
list2.append(i)
list2.append(j)
for i in range(len(list2)//2):
list3 = []
rows = list2[2*i]
columns = list2[2*i+1]
if int(rows) > 0:
if list[rows-1][columns] != '.' and list[rows-1][columns] != c:
list3.append(list[rows-1][columns])
if int(columns) > 0:
if list[rows][columns-1] != '.' and list[rows][columns-1] != c:
list3.append(list[rows][columns-1])
if int(rows) < int(x)-1:
if list[rows+1][columns] != '.' and list[rows+1][columns] != c:
list3.append(list[rows+1][columns])
if int(columns) < int(y)-1:
if list[rows][columns+1] != '.' and list[rows][columns+1] != c:
list3.append(list[rows][columns+1])
if len(set(list3)) > deputies:
deputies = len(set(list3))
print(deputies)
``` | instruction | 0 | 1,332 | 7 | 2,664 |
No | output | 1 | 1,332 | 7 | 2,665 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The flag of Berland is such rectangular field n × m that satisfies following conditions:
* Flag consists of three colors which correspond to letters 'R', 'G' and 'B'.
* Flag consists of three equal in width and height stripes, parralel to each other and to sides of the flag. Each stripe has exactly one color.
* Each color should be used in exactly one stripe.
You are given a field n × m, consisting of characters 'R', 'G' and 'B'. Output "YES" (without quotes) if this field corresponds to correct flag of Berland. Otherwise, print "NO" (without quotes).
Input
The first line contains two integer numbers n and m (1 ≤ n, m ≤ 100) — the sizes of the field.
Each of the following n lines consisting of m characters 'R', 'G' and 'B' — the description of the field.
Output
Print "YES" (without quotes) if the given field corresponds to correct flag of Berland . Otherwise, print "NO" (without quotes).
Examples
Input
6 5
RRRRR
RRRRR
BBBBB
BBBBB
GGGGG
GGGGG
Output
YES
Input
4 3
BRG
BRG
BRG
BRG
Output
YES
Input
6 7
RRRGGGG
RRRGGGG
RRRGGGG
RRRBBBB
RRRBBBB
RRRBBBB
Output
NO
Input
4 4
RRRR
RRRR
BBBB
GGGG
Output
NO
Note
The field in the third example doesn't have three parralel stripes.
Rows of the field in the fourth example are parralel to each other and to borders. But they have different heights — 2, 1 and 1. | instruction | 0 | 1,389 | 7 | 2,778 |
Tags: brute force, implementation
Correct Solution:
```
N, M = map(int, input().split())
flag = [input() for n in range(N)]
def get_rect_of_color(color):
rect_points = []
for i, row in enumerate(flag):
first = True
seq_is_broken = False
tmp = [None] * 4
for j, char in enumerate(row):
if char == color:
if first:
first = False
tmp[0], tmp[1] = i, j
if seq_is_broken:
raise Exception()
tmp[2], tmp[3] = i, j
elif not first:
seq_is_broken = True
if tmp[0] is not None:
rect_points += [tmp]
return rect_points
def get_bounding_rect(rect):
last_pos = rect[0]
first = True
for row in rect:
if first:
first = False
continue
ly1, lx1, ly2, lx2 = last_pos
y1, x1, y2, x2 = row
# print(y1, x1, y2, x2)
# print(ly1, lx1, ly2, lx2)
if y1 - ly1 != 1 or y2 - ly2 != 1 or\
x1 - lx1 != 0 or x2 - lx2 != 0:
raise Exception()
last_pos = row
return (
(rect[0][0], rect[0][1]),
(rect[-1][2], rect[-1][3]),
)
try:
R = get_bounding_rect(get_rect_of_color('R'))
G = get_bounding_rect(get_rect_of_color('G'))
B = get_bounding_rect(get_rect_of_color('B'))
Rh = abs(R[1][0] - R[0][0])
Bh = abs(B[1][0] - B[0][0])
Gh = abs(G[1][0] - G[0][0])
Rw = abs(R[1][1] - R[0][1])
Bw = abs(B[1][1] - B[0][1])
Gw = abs(G[1][1] - G[0][1])
# print(Rh, Bh, Gh)
# print(Rw, Bw, Gw)
if len(set([Rw, Bw, Gw])) != 1 or len(set([Rh, Bh, Gh])) != 1:
print('NO')
else:
print('YES')
except Exception:
print('NO')
``` | output | 1 | 1,389 | 7 | 2,779 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The flag of Berland is such rectangular field n × m that satisfies following conditions:
* Flag consists of three colors which correspond to letters 'R', 'G' and 'B'.
* Flag consists of three equal in width and height stripes, parralel to each other and to sides of the flag. Each stripe has exactly one color.
* Each color should be used in exactly one stripe.
You are given a field n × m, consisting of characters 'R', 'G' and 'B'. Output "YES" (without quotes) if this field corresponds to correct flag of Berland. Otherwise, print "NO" (without quotes).
Input
The first line contains two integer numbers n and m (1 ≤ n, m ≤ 100) — the sizes of the field.
Each of the following n lines consisting of m characters 'R', 'G' and 'B' — the description of the field.
Output
Print "YES" (without quotes) if the given field corresponds to correct flag of Berland . Otherwise, print "NO" (without quotes).
Examples
Input
6 5
RRRRR
RRRRR
BBBBB
BBBBB
GGGGG
GGGGG
Output
YES
Input
4 3
BRG
BRG
BRG
BRG
Output
YES
Input
6 7
RRRGGGG
RRRGGGG
RRRGGGG
RRRBBBB
RRRBBBB
RRRBBBB
Output
NO
Input
4 4
RRRR
RRRR
BBBB
GGGG
Output
NO
Note
The field in the third example doesn't have three parralel stripes.
Rows of the field in the fourth example are parralel to each other and to borders. But they have different heights — 2, 1 and 1. | instruction | 0 | 1,390 | 7 | 2,780 |
Tags: brute force, implementation
Correct Solution:
```
n, m = list(map(int, input().split()))
res = max(n, m) >= 3
is_horo = True
is_vert = True
if res:
flag = []
for i in range(n):
r = input()
if len(r) != m:
res = False
break
flag.append(list(r))
px = flag[0][0]
for i in range(1, m):
if flag[0][i] != px:
is_horo = False
break
for i in range(1, n):
if flag[i][0] != px:
is_vert = False
break
res = is_horo ^ is_vert
compressed = []
if res:
if is_horo:
for r in flag:
px = r[0]
for c in r[1:]:
if c != px:
res = False
break
compressed.append(px)
elif is_vert:
for i in range(m):
px = flag[0][i]
for j in range(1, n):
if flag[j][i] != px:
res = False
break
compressed.append(px)
if res and compressed:
stripe_width = None
c_stripe = None
c_width = 0
widths = []
seen = set()
for stripe in compressed:
if c_stripe is None:
c_stripe = stripe
c_width = 1
elif c_stripe != stripe:
seen.add(c_stripe)
widths.append(c_width)
c_width = 1
c_stripe = stripe
else:
c_width += 1
widths.append(c_width)
seen.add(c_stripe)
if len(widths) != 3 or len(seen) != 3:
res = False
else:
first = widths[0]
for i in range(1, len(widths)):
if widths[i] != first:
res = False
break
print('YES' if res else 'NO')
``` | output | 1 | 1,390 | 7 | 2,781 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The flag of Berland is such rectangular field n × m that satisfies following conditions:
* Flag consists of three colors which correspond to letters 'R', 'G' and 'B'.
* Flag consists of three equal in width and height stripes, parralel to each other and to sides of the flag. Each stripe has exactly one color.
* Each color should be used in exactly one stripe.
You are given a field n × m, consisting of characters 'R', 'G' and 'B'. Output "YES" (without quotes) if this field corresponds to correct flag of Berland. Otherwise, print "NO" (without quotes).
Input
The first line contains two integer numbers n and m (1 ≤ n, m ≤ 100) — the sizes of the field.
Each of the following n lines consisting of m characters 'R', 'G' and 'B' — the description of the field.
Output
Print "YES" (without quotes) if the given field corresponds to correct flag of Berland . Otherwise, print "NO" (without quotes).
Examples
Input
6 5
RRRRR
RRRRR
BBBBB
BBBBB
GGGGG
GGGGG
Output
YES
Input
4 3
BRG
BRG
BRG
BRG
Output
YES
Input
6 7
RRRGGGG
RRRGGGG
RRRGGGG
RRRBBBB
RRRBBBB
RRRBBBB
Output
NO
Input
4 4
RRRR
RRRR
BBBB
GGGG
Output
NO
Note
The field in the third example doesn't have three parralel stripes.
Rows of the field in the fourth example are parralel to each other and to borders. But they have different heights — 2, 1 and 1. | instruction | 0 | 1,391 | 7 | 2,782 |
Tags: brute force, implementation
Correct Solution:
```
#python 3.5.2
b, k = map(int, input().split())
arr = []
for i in range(b):
s = input()
arr.append(s)
x = arr[0][0]
nb = 1
nk = 1
pola = str(x)
while (nk < k and arr[0][nk] == x):
nk += 1
pola += x
if (nk == k or nk == k/3):
if (nk == k/3):
# print("xx")
arr = list(map(lambda x: ''.join(x), (map(list, zip(*arr)))))
# print(arr)
b, k = k, b
nb = 1
nk = 1
pola = str(x)
while (nk < k and arr[0][nk] == x):
nk += 1
pola += x
while (nb < b and arr[nb][:nk] == pola):
nb += 1
if (nb == b/3):
y = arr[nb][0]
polay = ""
for i in range(nk):
polay += y
nby = 0
brs = nb
while (nby+nb < b and arr[nby+nb] == polay): nby+=1
if (nby == nb):
z = arr[nby+nb][0]
if (z != x):
polaz = ""
for i in range(nk):
polaz += z
nbz = 0
brs = nby+nb
while (nbz+nby+nb < b and arr[nbz+nby+nb] == polaz): nbz+=1
if (nbz == nb):
print("YES")
else:
print("NO")
else:
print("NO")
else:
print("NO")
else:
print("NO")
else:
print("NO")
``` | output | 1 | 1,391 | 7 | 2,783 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The flag of Berland is such rectangular field n × m that satisfies following conditions:
* Flag consists of three colors which correspond to letters 'R', 'G' and 'B'.
* Flag consists of three equal in width and height stripes, parralel to each other and to sides of the flag. Each stripe has exactly one color.
* Each color should be used in exactly one stripe.
You are given a field n × m, consisting of characters 'R', 'G' and 'B'. Output "YES" (without quotes) if this field corresponds to correct flag of Berland. Otherwise, print "NO" (without quotes).
Input
The first line contains two integer numbers n and m (1 ≤ n, m ≤ 100) — the sizes of the field.
Each of the following n lines consisting of m characters 'R', 'G' and 'B' — the description of the field.
Output
Print "YES" (without quotes) if the given field corresponds to correct flag of Berland . Otherwise, print "NO" (without quotes).
Examples
Input
6 5
RRRRR
RRRRR
BBBBB
BBBBB
GGGGG
GGGGG
Output
YES
Input
4 3
BRG
BRG
BRG
BRG
Output
YES
Input
6 7
RRRGGGG
RRRGGGG
RRRGGGG
RRRBBBB
RRRBBBB
RRRBBBB
Output
NO
Input
4 4
RRRR
RRRR
BBBB
GGGG
Output
NO
Note
The field in the third example doesn't have three parralel stripes.
Rows of the field in the fourth example are parralel to each other and to borders. But they have different heights — 2, 1 and 1. | instruction | 0 | 1,392 | 7 | 2,784 |
Tags: brute force, implementation
Correct Solution:
```
n, m = map(int, input().split())
s = [input() for _ in range(n)]
if n % 3 != 0 and m % 3 != 0:
print('NO')
exit()
flag = 0
if n % 3 == 0:
if not(s[0][0]!=s[n//3][0] and s[2*n//3][0]!=s[n//3][0] and s[2*n//3][0]!=s[0][0]):
flag=1
r, g, b = 0, 0, 0
if s[0][0] == 'R':
r = 1
elif s[0][0] == 'G':
g = 1
else:
b = 1
for i in range(n//3):
for j in range(m):
if s[i][j] == 'G' and g != 1:
flag = 1
elif s[i][j] == 'R' and r != 1:
flag = 1
elif s[i][j] == 'B' and b != 1:
flag = 1
if s[n//3][0] == 'R':
if r == 1:
flag = 1
r = 1
g, b = 0, 0
elif s[n//3][0] == 'G':
if g == 1:
flag = 1
g = 1
r, b = 0, 0
else:
if b == 1:
flag = 1
b = 1
r, g = 0, 0
for i in range(n//3, 2*n//3):
for j in range(m):
if s[i][j] == 'G' and g != 1:
flag = 1
elif s[i][j] == 'R' and r != 1:
flag = 1
elif s[i][j] == 'B' and b != 1:
flag = 1
if s[2*n//3][0] == 'R':
if r == 1:
flag = 1
r = 1
g, b = 0, 0
elif s[2*n//3][0] == 'G':
if g == 1:
flag = 1
g=1
r, b = 0, 0
else:
if b == 1:
flag = 1
b = 1
r, g = 0, 0
for i in range(2*n//3, n):
for j in range(m):
if s[i][j] == 'G' and g != 1:
flag = 1
elif s[i][j] == 'R' and r != 1:
flag = 1
elif s[i][j] == 'B' and b != 1:
flag = 1
if flag == 0:
print('YES')
exit()
flag = 0
if (m % 3 == 0):
if not (s[0][0]!=s[0][m//3] and s[0][2*m//3]!=s[0][m//3] and s[0][0]!=s[0][2*m//3]):
flag=1
r, g, b = 0, 0, 0
if s[0][0] == 'R':
r += 1
elif s[0][0] == 'G':
g += 1
else:
b += 1
for j in range(m//3):
for i in range(n):
if s[i][j] == 'G' and g != 1:
flag = 1
elif s[i][j] == 'R' and r != 1:
flag = 1
elif s[i][j] == 'B' and b != 1:
flag = 1
if s[0][m//3] == 'R':
if r == 1:
flag = 1
r = 1
g, b = 0, 0
elif s[0][m//3] == 'G':
if g == 1:
flag = 1
g = 1
r, b = 0, 0
else:
if b == 1:
flag = 1
b = 1
r, g = 0, 0
for j in range(m//3, 2*m//3):
for i in range(n):
if s[i][j] == 'G' and g != 1:
flag = 1
elif s[i][j] == 'R' and r != 1:
flag = 1
elif s[i][j] == 'B' and b != 1:
flag = 1
if s[0][2*m//3] == 'R':
if r == 1:
flag = 1
r = 1
g, b = 0, 0
elif s[0][2*m//3] == 'G':
if g == 1:
flag = 1
g=1
r, b = 0, 0
else:
if b == 1:
flag = 1
b = 1
r, g = 0, 0
for j in range(2*m//3, m):
for i in range(n):
if s[i][j] == 'G' and g != 1:
flag = 1
elif s[i][j] == 'R' and r != 1:
flag = 1
elif s[i][j] == 'B' and b != 1:
flag = 1
if flag == 0:
print('YES')
exit()
print('NO')
``` | output | 1 | 1,392 | 7 | 2,785 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The flag of Berland is such rectangular field n × m that satisfies following conditions:
* Flag consists of three colors which correspond to letters 'R', 'G' and 'B'.
* Flag consists of three equal in width and height stripes, parralel to each other and to sides of the flag. Each stripe has exactly one color.
* Each color should be used in exactly one stripe.
You are given a field n × m, consisting of characters 'R', 'G' and 'B'. Output "YES" (without quotes) if this field corresponds to correct flag of Berland. Otherwise, print "NO" (without quotes).
Input
The first line contains two integer numbers n and m (1 ≤ n, m ≤ 100) — the sizes of the field.
Each of the following n lines consisting of m characters 'R', 'G' and 'B' — the description of the field.
Output
Print "YES" (without quotes) if the given field corresponds to correct flag of Berland . Otherwise, print "NO" (without quotes).
Examples
Input
6 5
RRRRR
RRRRR
BBBBB
BBBBB
GGGGG
GGGGG
Output
YES
Input
4 3
BRG
BRG
BRG
BRG
Output
YES
Input
6 7
RRRGGGG
RRRGGGG
RRRGGGG
RRRBBBB
RRRBBBB
RRRBBBB
Output
NO
Input
4 4
RRRR
RRRR
BBBB
GGGG
Output
NO
Note
The field in the third example doesn't have three parralel stripes.
Rows of the field in the fourth example are parralel to each other and to borders. But they have different heights — 2, 1 and 1. | instruction | 0 | 1,393 | 7 | 2,786 |
Tags: brute force, implementation
Correct Solution:
```
import sys
#import random
from bisect import bisect_left as lb
from collections import deque
#sys.setrecursionlimit(10**8)
from queue import PriorityQueue as pq
from math import *
input_ = lambda: sys.stdin.readline().strip("\r\n")
ii = lambda : int(input_())
il = lambda : list(map(int, input_().split()))
ilf = lambda : list(map(float, input_().split()))
ip = lambda : input_()
fi = lambda : float(input_())
ap = lambda ab,bc,cd : ab[bc].append(cd)
li = lambda : list(input_())
pr = lambda x : print(x)
prinT = lambda x : print(x)
f = lambda : sys.stdout.flush()
inv =lambda x:pow(x,mod-2,mod)
mod = 10**9 + 7
n,m = il()
a = []
for i in range (n) :
a.append(list(ip()))
if (n%3 != 0 and m%3 != 0) :
print("NO")
exit(0)
fl = 1
if (n%3 == 0) :
x = n//3
d = {}
for k in range (3) :
i = 0 + x*k
ch = a[i][0]
if (d.get(ch)) :
fl = 0
break
for i1 in range (x) :
for j in range (m) :
if (ch != a[i1+i][j]) :
fl = 0
break
if (fl == 0) :
break
d[ch] = 1
if fl :
print("YES")
exit(0)
if (m%3 == 0) :
x = m//3
d = {}
fl = 1
for k in range (3) :
i = 0 + x*k
ch = a[0][i]
if (d.get(ch)) :
fl = 0
break
for i1 in range (x) :
for j in range (n) :
if (ch != a[j][i1+i]) :
fl = 0
break
if (fl == 0) :
break
d[ch] = 1
if (fl) :
print("YES")
exit(0)
print("NO")
``` | output | 1 | 1,393 | 7 | 2,787 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The flag of Berland is such rectangular field n × m that satisfies following conditions:
* Flag consists of three colors which correspond to letters 'R', 'G' and 'B'.
* Flag consists of three equal in width and height stripes, parralel to each other and to sides of the flag. Each stripe has exactly one color.
* Each color should be used in exactly one stripe.
You are given a field n × m, consisting of characters 'R', 'G' and 'B'. Output "YES" (without quotes) if this field corresponds to correct flag of Berland. Otherwise, print "NO" (without quotes).
Input
The first line contains two integer numbers n and m (1 ≤ n, m ≤ 100) — the sizes of the field.
Each of the following n lines consisting of m characters 'R', 'G' and 'B' — the description of the field.
Output
Print "YES" (without quotes) if the given field corresponds to correct flag of Berland . Otherwise, print "NO" (without quotes).
Examples
Input
6 5
RRRRR
RRRRR
BBBBB
BBBBB
GGGGG
GGGGG
Output
YES
Input
4 3
BRG
BRG
BRG
BRG
Output
YES
Input
6 7
RRRGGGG
RRRGGGG
RRRGGGG
RRRBBBB
RRRBBBB
RRRBBBB
Output
NO
Input
4 4
RRRR
RRRR
BBBB
GGGG
Output
NO
Note
The field in the third example doesn't have three parralel stripes.
Rows of the field in the fourth example are parralel to each other and to borders. But they have different heights — 2, 1 and 1. | instruction | 0 | 1,394 | 7 | 2,788 |
Tags: brute force, implementation
Correct Solution:
```
def c(f, n, m):
if n % 3 != 0:return 0
s=n//3;s=f[0],f[s],f[2*s]
if set(s)!=set(map(lambda x:x*m,'RGB')):return 0
for i in range(n):
if f[i] != s[i*3 // n]:return 0
return 1
n,m=map(int, input().split())
f=[input() for _ in range(n)]
print('Yes'if c(f,n,m) or c([''.join(f[j][i] for j in range(n)) for i in range(m)],m,n)else'No')
``` | output | 1 | 1,394 | 7 | 2,789 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The flag of Berland is such rectangular field n × m that satisfies following conditions:
* Flag consists of three colors which correspond to letters 'R', 'G' and 'B'.
* Flag consists of three equal in width and height stripes, parralel to each other and to sides of the flag. Each stripe has exactly one color.
* Each color should be used in exactly one stripe.
You are given a field n × m, consisting of characters 'R', 'G' and 'B'. Output "YES" (without quotes) if this field corresponds to correct flag of Berland. Otherwise, print "NO" (without quotes).
Input
The first line contains two integer numbers n and m (1 ≤ n, m ≤ 100) — the sizes of the field.
Each of the following n lines consisting of m characters 'R', 'G' and 'B' — the description of the field.
Output
Print "YES" (without quotes) if the given field corresponds to correct flag of Berland . Otherwise, print "NO" (without quotes).
Examples
Input
6 5
RRRRR
RRRRR
BBBBB
BBBBB
GGGGG
GGGGG
Output
YES
Input
4 3
BRG
BRG
BRG
BRG
Output
YES
Input
6 7
RRRGGGG
RRRGGGG
RRRGGGG
RRRBBBB
RRRBBBB
RRRBBBB
Output
NO
Input
4 4
RRRR
RRRR
BBBB
GGGG
Output
NO
Note
The field in the third example doesn't have three parralel stripes.
Rows of the field in the fourth example are parralel to each other and to borders. But they have different heights — 2, 1 and 1. | instruction | 0 | 1,395 | 7 | 2,790 |
Tags: brute force, implementation
Correct Solution:
```
import sys
#sys.stdin = open("input2","r")
n,m = map(int,input().split())
s = []
for i in range(n):
string = input()
s.append(string)
no = 0
# row mix check
r_mix = 0
for i in range(n):
cnt_r = s[i].count('R')
cnt_b = s[i].count('B')
cnt_g = s[i].count('G')
if ((cnt_r and cnt_b) or (cnt_b and cnt_g) or (cnt_g and cnt_r) ):
r_mix = 1
# col mix check
c_mix = 0
for j in range(m):
cnt_r = cnt_b = cnt_g = 0
for i in range(n):
if (s[i][j] == 'R'):
cnt_r += 1
elif (s[i][j] == 'B'):
cnt_b += 1
elif(s[i][j] == 'G'):
cnt_g += 1
if ((cnt_r and cnt_b) or (cnt_b and cnt_g) or (cnt_g and cnt_r) ):
c_mix = 1
if (r_mix == 1 and c_mix == 1) or ( r_mix == 0 and c_mix == 0):
no = 1
if(r_mix == 1):
cnt_b = cnt_g = cnt_r = 0
if s[0][0] == 'R':
cnt_r += 1
elif s[0][0] == 'G':
cnt_g += 1
elif s[0][0] == 'B':
cnt_b += 1
f,c = -1,1
for j in range(0,m-1):
if s[0][j] == s[0][j+1]:
c += 1
else:
if s[0][j+1] == 'R':
cnt_r += 1
elif s[0][j + 1] == 'G':
cnt_g += 1
elif s[0][j + 1] == 'B':
cnt_b += 1
if f == -1:
f = c
if f != c:
no = 1
break
c = 1
if ((f != c) or (cnt_r != 1 or cnt_b != 1 or cnt_g != 1)):
no = 1
if (c_mix):
f = -1
c = 1
cnt_b = 0
cnt_g = 0
cnt_r = 0
if s[0][0] == 'R':
cnt_r += 1
elif s[0][0] == 'G':
cnt_g += 1
elif s[0][0] == 'B':
cnt_b += 1
for i in range(0, n-1):
if s[i][0] == s[i+1][0]:
c += 1
#print('c',c)
else:
if s[i + 1][0] == 'R':
cnt_r += 1
elif s[i + 1][0] == 'G':
cnt_g += 1
elif s[i + 1][0] == 'B':
cnt_b += 1
if f == -1:
f = c
#print('f',f)
if f != c:
#print(f,c)
no = 1
break
c = 1
#print(cnt_r,cnt_b,cnt_g)
if ((f != c) or (cnt_r != 1 or cnt_b != 1 or cnt_g != 1)):
no = 1
if no == 1:
print('NO')
else:
print('YES')
``` | output | 1 | 1,395 | 7 | 2,791 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The flag of Berland is such rectangular field n × m that satisfies following conditions:
* Flag consists of three colors which correspond to letters 'R', 'G' and 'B'.
* Flag consists of three equal in width and height stripes, parralel to each other and to sides of the flag. Each stripe has exactly one color.
* Each color should be used in exactly one stripe.
You are given a field n × m, consisting of characters 'R', 'G' and 'B'. Output "YES" (without quotes) if this field corresponds to correct flag of Berland. Otherwise, print "NO" (without quotes).
Input
The first line contains two integer numbers n and m (1 ≤ n, m ≤ 100) — the sizes of the field.
Each of the following n lines consisting of m characters 'R', 'G' and 'B' — the description of the field.
Output
Print "YES" (without quotes) if the given field corresponds to correct flag of Berland . Otherwise, print "NO" (without quotes).
Examples
Input
6 5
RRRRR
RRRRR
BBBBB
BBBBB
GGGGG
GGGGG
Output
YES
Input
4 3
BRG
BRG
BRG
BRG
Output
YES
Input
6 7
RRRGGGG
RRRGGGG
RRRGGGG
RRRBBBB
RRRBBBB
RRRBBBB
Output
NO
Input
4 4
RRRR
RRRR
BBBB
GGGG
Output
NO
Note
The field in the third example doesn't have three parralel stripes.
Rows of the field in the fourth example are parralel to each other and to borders. But they have different heights — 2, 1 and 1. | instruction | 0 | 1,396 | 7 | 2,792 |
Tags: brute force, implementation
Correct Solution:
```
[n,m] = [int(i) for i in input().split()]
flag = []
flip_flag = []
for i in range(m):
flip_flag.append([])
tmp = n
while tmp:
tmp -= 1
flag.append(list(input()))
for i in range(m):
flip_flag[i].append(flag[-1][i])
if len(set(flag[0])) != 1:
flag = flip_flag
strip_count = {}
valid = True
strip_count[flag[0][0]]=1
if len(set(flag[0])) != 1:
valid = False
for i in range(1, len(flag)):
if len(set(flag[i])) != 1 or valid == False:
valid = False
break
if flag[i][0] not in strip_count.keys():
strip_count[flag[i][0]] = 1
elif flag[i][0] != flag[i-1][0]:
valid = False
break
else:
strip_count[flag[i][0]] += 1
if len(set(strip_count.values())) != 1:
valid = False
if not(all(i in strip_count.keys() for i in ['R','G','B']) and len(set(strip_count.keys())) == 3):
valid = False
print('YES' if valid else 'NO')
``` | output | 1 | 1,396 | 7 | 2,793 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The flag of Berland is such rectangular field n × m that satisfies following conditions:
* Flag consists of three colors which correspond to letters 'R', 'G' and 'B'.
* Flag consists of three equal in width and height stripes, parralel to each other and to sides of the flag. Each stripe has exactly one color.
* Each color should be used in exactly one stripe.
You are given a field n × m, consisting of characters 'R', 'G' and 'B'. Output "YES" (without quotes) if this field corresponds to correct flag of Berland. Otherwise, print "NO" (without quotes).
Input
The first line contains two integer numbers n and m (1 ≤ n, m ≤ 100) — the sizes of the field.
Each of the following n lines consisting of m characters 'R', 'G' and 'B' — the description of the field.
Output
Print "YES" (without quotes) if the given field corresponds to correct flag of Berland . Otherwise, print "NO" (without quotes).
Examples
Input
6 5
RRRRR
RRRRR
BBBBB
BBBBB
GGGGG
GGGGG
Output
YES
Input
4 3
BRG
BRG
BRG
BRG
Output
YES
Input
6 7
RRRGGGG
RRRGGGG
RRRGGGG
RRRBBBB
RRRBBBB
RRRBBBB
Output
NO
Input
4 4
RRRR
RRRR
BBBB
GGGG
Output
NO
Note
The field in the third example doesn't have three parralel stripes.
Rows of the field in the fourth example are parralel to each other and to borders. But they have different heights — 2, 1 and 1.
Submitted Solution:
```
n,m=map(int,input().split())
ls=[]
for i in range(n):
s=input()
ls.append(s)
#check for horizontal strips
horizontal=[]
f1=True
for i in range(n):
if(ls[i]==ls[i][0]*len(ls[i])):
if(i==0):
horizontal.append([ls[i],1])
elif(ls[i]==horizontal[-1][0]):
horizontal[-1][1]+=1
else:
horizontal.append([ls[i],1])
else:
f1=False
break
if(len(horizontal)==3 and horizontal[0][1]==horizontal[1][1]==horizontal[2][1]):
if(horizontal[0][0]!=horizontal[1][0] and horizontal[0][0]!=horizontal[2][0] and horizontal[1][0]!=horizontal[2][0]):
s=""
else:
f1=False
else:
f1=False
new_ls=["" for i in range(m)]
for i in range(n):
for j in range(m):
new_ls[j]+=ls[i][j]
ls=new_ls
#check for horizontal strips
horizontal=[]
f2=True
for i in range(m):
if(ls[i]==ls[i][0]*len(ls[i])):
if(i==0):
horizontal.append([ls[i],1])
elif(ls[i]==horizontal[-1][0]):
horizontal[-1][1]+=1
else:
horizontal.append([ls[i],1])
else:
f2=False
break
if(len(horizontal)==3 and horizontal[0][1]==horizontal[1][1]==horizontal[2][1]):
if(horizontal[0][0]!=horizontal[1][0] and horizontal[0][0]!=horizontal[2][0] and horizontal[1][0]!=horizontal[2][0]):
s=""
else:
f2=False
else:
f2=False
if(f1 or f2):print("YES")
else:print("NO")
``` | instruction | 0 | 1,397 | 7 | 2,794 |
Yes | output | 1 | 1,397 | 7 | 2,795 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The flag of Berland is such rectangular field n × m that satisfies following conditions:
* Flag consists of three colors which correspond to letters 'R', 'G' and 'B'.
* Flag consists of three equal in width and height stripes, parralel to each other and to sides of the flag. Each stripe has exactly one color.
* Each color should be used in exactly one stripe.
You are given a field n × m, consisting of characters 'R', 'G' and 'B'. Output "YES" (without quotes) if this field corresponds to correct flag of Berland. Otherwise, print "NO" (without quotes).
Input
The first line contains two integer numbers n and m (1 ≤ n, m ≤ 100) — the sizes of the field.
Each of the following n lines consisting of m characters 'R', 'G' and 'B' — the description of the field.
Output
Print "YES" (without quotes) if the given field corresponds to correct flag of Berland . Otherwise, print "NO" (without quotes).
Examples
Input
6 5
RRRRR
RRRRR
BBBBB
BBBBB
GGGGG
GGGGG
Output
YES
Input
4 3
BRG
BRG
BRG
BRG
Output
YES
Input
6 7
RRRGGGG
RRRGGGG
RRRGGGG
RRRBBBB
RRRBBBB
RRRBBBB
Output
NO
Input
4 4
RRRR
RRRR
BBBB
GGGG
Output
NO
Note
The field in the third example doesn't have three parralel stripes.
Rows of the field in the fourth example are parralel to each other and to borders. But they have different heights — 2, 1 and 1.
Submitted Solution:
```
height, width = map(int, input().split())
a = [input() for i in range(height)]
c = {'r': 0, 'g': 0, 'b': 0}
p = {'r': 0, 'g': 0, 'b': 0}
color = {'r': False, 'g': False, 'b': False}
horizontal, vertical = True, False
for i in range(height):
for j in range(width):
color[a[i][j].lower()] = True
for i in range(height):
for j in range(1, width):
if a[i][j] != a[i][j - 1]:
horizontal = False
break
c[a[i][j].lower()] += 1
if not horizontal:
vertical = True
for key in c.keys():
c[key] = 0
for i in range(width):
for j in range(1, height):
if a[j][i] != a[j - 1][i]:
vertical = False
break
c[a[j][i].lower()] += 1
prev = None
if horizontal:
for i in range(height):
if prev is None:
prev = a[i][0].lower()
c[a[i][0].lower()] += 1
p[a[i][0].lower()] += 1
else:
if prev != a[i][0].lower():
p[a[i][0].lower()] += 1
if p[a[i][0].lower()] >= 2:
print('NO')
exit()
prev = a[i][0].lower()
c[a[i][0].lower()] += 1
elif vertical:
for i in range(width):
if prev is None:
prev = a[0][i].lower()
c[a[0][i].lower()] += 1
else:
if prev != a[0][i].lower():
p[a[0][i].lower()] += 1
if p[a[0][i].lower()] >= 2:
print('NO')
exit()
prev = a[0][i].lower()
c[a[0][i].lower()] += 1
else:
print('NO')
exit()
if c['r'] == c['g'] == c['b'] and color['r'] and color['g'] and color['b']:
print('YES')
else:
print('NO')
``` | instruction | 0 | 1,398 | 7 | 2,796 |
Yes | output | 1 | 1,398 | 7 | 2,797 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The flag of Berland is such rectangular field n × m that satisfies following conditions:
* Flag consists of three colors which correspond to letters 'R', 'G' and 'B'.
* Flag consists of three equal in width and height stripes, parralel to each other and to sides of the flag. Each stripe has exactly one color.
* Each color should be used in exactly one stripe.
You are given a field n × m, consisting of characters 'R', 'G' and 'B'. Output "YES" (without quotes) if this field corresponds to correct flag of Berland. Otherwise, print "NO" (without quotes).
Input
The first line contains two integer numbers n and m (1 ≤ n, m ≤ 100) — the sizes of the field.
Each of the following n lines consisting of m characters 'R', 'G' and 'B' — the description of the field.
Output
Print "YES" (without quotes) if the given field corresponds to correct flag of Berland . Otherwise, print "NO" (without quotes).
Examples
Input
6 5
RRRRR
RRRRR
BBBBB
BBBBB
GGGGG
GGGGG
Output
YES
Input
4 3
BRG
BRG
BRG
BRG
Output
YES
Input
6 7
RRRGGGG
RRRGGGG
RRRGGGG
RRRBBBB
RRRBBBB
RRRBBBB
Output
NO
Input
4 4
RRRR
RRRR
BBBB
GGGG
Output
NO
Note
The field in the third example doesn't have three parralel stripes.
Rows of the field in the fourth example are parralel to each other and to borders. But they have different heights — 2, 1 and 1.
Submitted Solution:
```
#python 3.5.2
#Ввод n m и самих цветов
vv = input()
n = int(vv[0:vv.find(' ')])
m = int(vv[vv.find(' '):])
x = ''
for mm in range(n):
x += input()
col = 0
row = 0
res = True
types = 0
if x[0] == x[n*m - m]:
if m % 3 == 0:
col = m//3
row = n
types = 1
else:
res = False
else:
if x[0] == x[m - 1]:
if n%3 == 0:
col = m
row = n//3
types = 2
else:
res = False
else:
res = False
c1 = ''
c2 = ''
c3 = ''
if res:
if types == 1:
for i in range(row):
for j in range(col):
c1 += x[j + m*i]
for i in range(row):
for j in range(col, col*2):
c2 += x[j + m*i]
for i in range(row):
for j in range(col*2, col*3):
c3 += x[j + m*i]
if types == 2:
for i in range(m*n//3):
c1 += x[i]
for i in range(m*n//3, m*n//3*2):
c2 += x[i]
for i in range(m*n//3*2, m*n):
c3 += x[i]
if res:
let1 = c1[0]
for i in c1:
if i != let1:
res = False
break
if res:
let2 = c2[0]
if let1 == let2:
res =False
else:
for i in c2:
if i != let2:
res = False
break
if res:
let3 = c3[0]
if let1 == let3 or let2 == let3:
res = False
else:
for i in c3:
if i != let3:
res = False
break
if res:
print('YES')
else:
print('NO')
``` | instruction | 0 | 1,399 | 7 | 2,798 |
Yes | output | 1 | 1,399 | 7 | 2,799 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The flag of Berland is such rectangular field n × m that satisfies following conditions:
* Flag consists of three colors which correspond to letters 'R', 'G' and 'B'.
* Flag consists of three equal in width and height stripes, parralel to each other and to sides of the flag. Each stripe has exactly one color.
* Each color should be used in exactly one stripe.
You are given a field n × m, consisting of characters 'R', 'G' and 'B'. Output "YES" (without quotes) if this field corresponds to correct flag of Berland. Otherwise, print "NO" (without quotes).
Input
The first line contains two integer numbers n and m (1 ≤ n, m ≤ 100) — the sizes of the field.
Each of the following n lines consisting of m characters 'R', 'G' and 'B' — the description of the field.
Output
Print "YES" (without quotes) if the given field corresponds to correct flag of Berland . Otherwise, print "NO" (without quotes).
Examples
Input
6 5
RRRRR
RRRRR
BBBBB
BBBBB
GGGGG
GGGGG
Output
YES
Input
4 3
BRG
BRG
BRG
BRG
Output
YES
Input
6 7
RRRGGGG
RRRGGGG
RRRGGGG
RRRBBBB
RRRBBBB
RRRBBBB
Output
NO
Input
4 4
RRRR
RRRR
BBBB
GGGG
Output
NO
Note
The field in the third example doesn't have three parralel stripes.
Rows of the field in the fourth example are parralel to each other and to borders. But they have different heights — 2, 1 and 1.
Submitted Solution:
```
import sys, math
n, m = map(int, input().split())
a = ["" for i in range(n)]
for i in range(n):
a[i] = input()
if (a[0][0] == a[0][m-1]) and (n % 3 == 0):
for i in range(n // 3):
for j in range(m):
if (not a[i][j] == a[0][0]):
print("NO")
sys.exit()
for i in range(n // 3, 2 * n // 3):
for j in range(m):
if (not a[i][j] == a[n // 3][0]):
print("NO")
sys.exit()
for i in range(2 * n // 3, n):
for j in range(m):
if (not a[i][j] == a[2 * n // 3][0]):
print("NO")
sys.exit()
if (a[0][0] == a[n // 3][0]) or (a[0][0] == a[2 * n // 3][0]) or (a[2 * n // 3][0] == a[n // 3][0]):
print("NO")
sys.exit()
else:
print("YES")
sys.exit()
elif (a[0][0] == a[n - 1][0]) and (m % 3 == 0):
for i in range(n):
for j in range(m // 3):
if not ((a[i][j] == a[0][0]) and (a[i][j + m // 3] == a[0][m // 3]) and (
a[i][j + 2 * m // 3] == a[0][2 * m // 3])):
print("NO")
sys.exit()
if (a[0][0] == a[0][m // 3]) or (a[0][0] == a[0][2 * m // 3]) or (a[0][2 * m // 3] == a[0][m // 3]):
print("NO")
sys.exit()
else:
print("YES")
else:
print("NO")
``` | instruction | 0 | 1,400 | 7 | 2,800 |
Yes | output | 1 | 1,400 | 7 | 2,801 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The flag of Berland is such rectangular field n × m that satisfies following conditions:
* Flag consists of three colors which correspond to letters 'R', 'G' and 'B'.
* Flag consists of three equal in width and height stripes, parralel to each other and to sides of the flag. Each stripe has exactly one color.
* Each color should be used in exactly one stripe.
You are given a field n × m, consisting of characters 'R', 'G' and 'B'. Output "YES" (without quotes) if this field corresponds to correct flag of Berland. Otherwise, print "NO" (without quotes).
Input
The first line contains two integer numbers n and m (1 ≤ n, m ≤ 100) — the sizes of the field.
Each of the following n lines consisting of m characters 'R', 'G' and 'B' — the description of the field.
Output
Print "YES" (without quotes) if the given field corresponds to correct flag of Berland . Otherwise, print "NO" (without quotes).
Examples
Input
6 5
RRRRR
RRRRR
BBBBB
BBBBB
GGGGG
GGGGG
Output
YES
Input
4 3
BRG
BRG
BRG
BRG
Output
YES
Input
6 7
RRRGGGG
RRRGGGG
RRRGGGG
RRRBBBB
RRRBBBB
RRRBBBB
Output
NO
Input
4 4
RRRR
RRRR
BBBB
GGGG
Output
NO
Note
The field in the third example doesn't have three parralel stripes.
Rows of the field in the fourth example are parralel to each other and to borders. But they have different heights — 2, 1 and 1.
Submitted Solution:
```
height, width = map(int, input().split())
a = [input() for i in range(height)]
c = {'r': 0, 'g': 0, 'b': 0}
color = {'r': False, 'g': False, 'b': False}
all_lines = True
for i in range(height):
for j in range(width):
color[a[i][j].lower()] = True
for i in range(height):
for j in range(1, width):
if a[i][j] != a[i][j - 1]:
all_lines = False
break
c[a[i][j].lower()] += 1
if not all_lines:
all_lines = True
for key in c.keys():
c[key] = 0
for i in range(width):
for j in range(1, height):
if a[j][i] != a[j - 1][i]:
all_lines = False
break
c[a[j][i].lower()] += 1
if all_lines and c['r'] == c['b'] == c['g'] and color['r'] and color['b'] and color['g']:
print('YES')
else:
print('NO')
``` | instruction | 0 | 1,401 | 7 | 2,802 |
No | output | 1 | 1,401 | 7 | 2,803 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The flag of Berland is such rectangular field n × m that satisfies following conditions:
* Flag consists of three colors which correspond to letters 'R', 'G' and 'B'.
* Flag consists of three equal in width and height stripes, parralel to each other and to sides of the flag. Each stripe has exactly one color.
* Each color should be used in exactly one stripe.
You are given a field n × m, consisting of characters 'R', 'G' and 'B'. Output "YES" (without quotes) if this field corresponds to correct flag of Berland. Otherwise, print "NO" (without quotes).
Input
The first line contains two integer numbers n and m (1 ≤ n, m ≤ 100) — the sizes of the field.
Each of the following n lines consisting of m characters 'R', 'G' and 'B' — the description of the field.
Output
Print "YES" (without quotes) if the given field corresponds to correct flag of Berland . Otherwise, print "NO" (without quotes).
Examples
Input
6 5
RRRRR
RRRRR
BBBBB
BBBBB
GGGGG
GGGGG
Output
YES
Input
4 3
BRG
BRG
BRG
BRG
Output
YES
Input
6 7
RRRGGGG
RRRGGGG
RRRGGGG
RRRBBBB
RRRBBBB
RRRBBBB
Output
NO
Input
4 4
RRRR
RRRR
BBBB
GGGG
Output
NO
Note
The field in the third example doesn't have three parralel stripes.
Rows of the field in the fourth example are parralel to each other and to borders. But they have different heights — 2, 1 and 1.
Submitted Solution:
```
#python 3.5.2
#Ввод n m и самих цветов
vv = input()
n = int(vv[0:vv.find(' ')])
m = int(vv[vv.find(' '):])
x = ''
for mm in range(n):
x += input()
col = 0
row = 0
res = True
types = 0
if x[0] == x[n*m - m]:
if m % 3 == 0:
col = m//3
row = n
types = 1
else:
res = False
else:
if x[0] == x[m - 1]:
if n%3 == 0:
col = m
row = n//3
types = 2
else:
res = False
else:
res = False
c1 = ''
c2 = ''
c3 = ''
if res:
if types == 1:
for i in range(row):
for j in range(col):
c1 += x[j + m*i]
for i in range(row):
for j in range(col, col*2):
c2 += x[j + m*i]
for i in range(row):
for j in range(col*2, col*3):
c3 += x[j + m*i]
if types == 2:
for i in range(m*n//3):
c1 += x[i]
for i in range(m*n//3, m*n//3*2):
c2 += x[i]
for i in range(m*n//3*2, m*n):
c3 += x[i]
if res:
let = c1[0]
for i in c1:
if i != let:
res = False
break
if res:
let = c2[0]
for i in c2:
if i != let:
res = False
break
if res:
let = c3[0]
for i in c3:
if i != let:
res = False
break
if res:
print('YES')
else:
print('NO')
``` | instruction | 0 | 1,402 | 7 | 2,804 |
No | output | 1 | 1,402 | 7 | 2,805 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The flag of Berland is such rectangular field n × m that satisfies following conditions:
* Flag consists of three colors which correspond to letters 'R', 'G' and 'B'.
* Flag consists of three equal in width and height stripes, parralel to each other and to sides of the flag. Each stripe has exactly one color.
* Each color should be used in exactly one stripe.
You are given a field n × m, consisting of characters 'R', 'G' and 'B'. Output "YES" (without quotes) if this field corresponds to correct flag of Berland. Otherwise, print "NO" (without quotes).
Input
The first line contains two integer numbers n and m (1 ≤ n, m ≤ 100) — the sizes of the field.
Each of the following n lines consisting of m characters 'R', 'G' and 'B' — the description of the field.
Output
Print "YES" (without quotes) if the given field corresponds to correct flag of Berland . Otherwise, print "NO" (without quotes).
Examples
Input
6 5
RRRRR
RRRRR
BBBBB
BBBBB
GGGGG
GGGGG
Output
YES
Input
4 3
BRG
BRG
BRG
BRG
Output
YES
Input
6 7
RRRGGGG
RRRGGGG
RRRGGGG
RRRBBBB
RRRBBBB
RRRBBBB
Output
NO
Input
4 4
RRRR
RRRR
BBBB
GGGG
Output
NO
Note
The field in the third example doesn't have three parralel stripes.
Rows of the field in the fourth example are parralel to each other and to borders. But they have different heights — 2, 1 and 1.
Submitted Solution:
```
lines = []
m,n = input().split()
for i in range(int(m)):
lines.append(input())
noError = 'YES'
lineInx = 0
direction = 'vert'
for l in lines:
if l[0] != lines[0][0]:
direction = 'gorz'
if direction == 'gorz':
while noError == 'YES' and lineInx < int(m):
if direction == 'gorz':
if lines[lineInx][0] == 'R':
if 'G' in lines[lineInx] or 'B' in lines[lineInx]:
noError = 'NO'
elif lines[lineInx][0] == 'G':
if 'R' in lines[lineInx] or 'B' in lines[lineInx]:
noError = 'NO'
elif lines[lineInx][0] == 'B':
if 'G' in lines[lineInx] or 'R' in lines[lineInx]:
noError = 'NO'
else:
noError = 'NO'
lineInx += 1
else:
for i in range(int(n)):
for j in range(int(m)-1):
if lines[j][i] != lines[j+1][i]:
noError = 'NO'
print(noError)
``` | instruction | 0 | 1,403 | 7 | 2,806 |
No | output | 1 | 1,403 | 7 | 2,807 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The flag of Berland is such rectangular field n × m that satisfies following conditions:
* Flag consists of three colors which correspond to letters 'R', 'G' and 'B'.
* Flag consists of three equal in width and height stripes, parralel to each other and to sides of the flag. Each stripe has exactly one color.
* Each color should be used in exactly one stripe.
You are given a field n × m, consisting of characters 'R', 'G' and 'B'. Output "YES" (without quotes) if this field corresponds to correct flag of Berland. Otherwise, print "NO" (without quotes).
Input
The first line contains two integer numbers n and m (1 ≤ n, m ≤ 100) — the sizes of the field.
Each of the following n lines consisting of m characters 'R', 'G' and 'B' — the description of the field.
Output
Print "YES" (without quotes) if the given field corresponds to correct flag of Berland . Otherwise, print "NO" (without quotes).
Examples
Input
6 5
RRRRR
RRRRR
BBBBB
BBBBB
GGGGG
GGGGG
Output
YES
Input
4 3
BRG
BRG
BRG
BRG
Output
YES
Input
6 7
RRRGGGG
RRRGGGG
RRRGGGG
RRRBBBB
RRRBBBB
RRRBBBB
Output
NO
Input
4 4
RRRR
RRRR
BBBB
GGGG
Output
NO
Note
The field in the third example doesn't have three parralel stripes.
Rows of the field in the fourth example are parralel to each other and to borders. But they have different heights — 2, 1 and 1.
Submitted Solution:
```
n, m = map(int, input().split())
a = []
for i in range(n):
a.append(input())
f1 = 0
f2 = 0
if n % 3 == 0:
f1 = 1
o1 = a[0][0]
o2 = a[n // 3][0]
o3 = a[2 * n // 3][0]
for i in range(n):
if i < n // 3:
if a[i] != o1 * m:
f1 = 0
break
elif i < 2 * n // 3:
if a[i] != o2 * m:
f1 = 0
break
else:
if a[i] != o3 * m:
f1 = 0
break
if m % 3 == 0:
f2 = 1
o1 = a[0][0]
o2 = a[0][m // 3]
o3 = a[0][2 * m // 3]
for i in range(n):
for j in range(m):
if j < m // 3:
if a[i][j] != o1:
f2 = 0
break
elif i < 2 * m // 3:
if a[i][j] != o2:
f2 = 0
break
else:
if a[i][j] != o3:
f2 = 0
break
if not f2:
break
if f1 or f2:
print("YES")
else:
print("NO")
``` | instruction | 0 | 1,404 | 7 | 2,808 |
No | output | 1 | 1,404 | 7 | 2,809 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given n integers. You need to choose a subset and put the chosen numbers in a beautiful rectangle (rectangular matrix). Each chosen number should occupy one of its rectangle cells, each cell must be filled with exactly one chosen number. Some of the n numbers may not be chosen.
A rectangle (rectangular matrix) is called beautiful if in each row and in each column all values are different.
What is the largest (by the total number of cells) beautiful rectangle you can construct? Print the rectangle itself.
Input
The first line contains n (1 ≤ n ≤ 4⋅10^5). The second line contains n integers (1 ≤ a_i ≤ 10^9).
Output
In the first line print x (1 ≤ x ≤ n) — the total number of cells of the required maximum beautiful rectangle. In the second line print p and q (p ⋅ q=x): its sizes. In the next p lines print the required rectangle itself. If there are several answers, print any.
Examples
Input
12
3 1 4 1 5 9 2 6 5 3 5 8
Output
12
3 4
1 2 3 5
3 1 5 4
5 6 8 9
Input
5
1 1 1 1 1
Output
1
1 1
1 | instruction | 0 | 2,595 | 7 | 5,190 |
Tags: brute force, combinatorics, constructive algorithms, data structures, greedy, math
Correct Solution:
```
def play(arr):
n = len(arr)
number2Count = {}
for p in arr:
number2Count[p] = number2Count.get(p, 0) + 1
count2Numbers = {}
maxCnt = 0
for num in number2Count:
cnt = number2Count[num]
if not cnt in count2Numbers:
count2Numbers[cnt] = []
count2Numbers[cnt].append(num)
maxCnt = max(maxCnt, cnt)
numRepeats = [0] * (n + 1)
numRepeats[n] = len(count2Numbers.get(n, []))
for i in range(n - 1, 0, -1):
numRepeats[i] = numRepeats[i + 1] + len(count2Numbers.get(i, []))
a_ideal = 0
b_ideal = 0
square = 0
square_ideal = 0
for a in range(1, n + 1):
square += numRepeats[a]
b = int(square / a)
if a <= b:
if square_ideal < a * b:
square_ideal = a * b
a_ideal = a
b_ideal = b
print(a_ideal * b_ideal)
print(str(a_ideal) + ' ' + str(b_ideal))
matrix = [[0] * b_ideal for p in range(0, a_ideal)]
x = 0
y = 0
for cnt in range(maxCnt, 0, -1):
for num in count2Numbers.get(cnt, []):
for i in range(0, min(cnt, a_ideal)):
if matrix[x][y] > 0:
x = (x + 1) % a_ideal
if matrix[x][y] == 0:
matrix[x][y] = num
x = (x + 1) % a_ideal
y = (y + 1) % b_ideal
for i in range(0, a_ideal):
print(*matrix[i])
def main():
input()
arr = list(map(int, input().split()))
play(arr)
main()
#print(play([3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 8]))
#print(play([4, 9, 5, 9, 6, 8, 9, 8, 7]))
# play(['010', '101', '0'])
# play(['00000', '00001'])
# play(['01', '001', '0001', '00001'])
``` | output | 1 | 2,595 | 7 | 5,191 |
Provide a correct Python 3 solution for this coding contest problem.
You are given a grid of squares with H horizontal rows and W vertical columns, where each square is painted white or black. HW characters from A_{11} to A_{HW} represent the colors of the squares. A_{ij} is `#` if the square at the i-th row from the top and the j-th column from the left is black, and A_{ij} is `.` if that square is white.
We will repeatedly perform the following operation until all the squares are black:
* Every white square that shares a side with a black square, becomes black.
Find the number of operations that will be performed. The initial grid has at least one black square.
Constraints
* 1 \leq H,W \leq 1000
* A_{ij} is `#` or `.`.
* The given grid has at least one black square.
Input
Input is given from Standard Input in the following format:
H W
A_{11}A_{12}...A_{1W}
:
A_{H1}A_{H2}...A_{HW}
Output
Print the number of operations that will be performed.
Examples
Input
3 3
...
.#.
...
Output
2
Input
6 6
..#..#
......
..#..
......
.#....
....#.
Output
3 | instruction | 0 | 3,134 | 7 | 6,268 |
"Correct Solution:
```
INF=float("inf")
def main():
H,W=map(int, input().split())
A=[input()for _ in range(H)]
D=[[0 if A[h][w]=="#" else INF for w in range(W)] for h in range(H)]
for h in range(H):
for w in range(1,W):
D[h][w]=min(D[h][w],D[h][w-1]+1)
for w in range(W-2, -1, -1):
D[h][w]=min(D[h][w],D[h][w+1]+1)
for w in range(W):
for h in range(1,H):
D[h][w]=min(D[h][w],D[h-1][w]+1)
for h in range(H-2, -1, -1):
D[h][w]=min(D[h][w],D[h+1][w]+1)
print(max(d for dd in D for d in dd))
if __name__ == "__main__":
main()
``` | output | 1 | 3,134 | 7 | 6,269 |
Provide a correct Python 3 solution for this coding contest problem.
You are given a grid of squares with H horizontal rows and W vertical columns, where each square is painted white or black. HW characters from A_{11} to A_{HW} represent the colors of the squares. A_{ij} is `#` if the square at the i-th row from the top and the j-th column from the left is black, and A_{ij} is `.` if that square is white.
We will repeatedly perform the following operation until all the squares are black:
* Every white square that shares a side with a black square, becomes black.
Find the number of operations that will be performed. The initial grid has at least one black square.
Constraints
* 1 \leq H,W \leq 1000
* A_{ij} is `#` or `.`.
* The given grid has at least one black square.
Input
Input is given from Standard Input in the following format:
H W
A_{11}A_{12}...A_{1W}
:
A_{H1}A_{H2}...A_{HW}
Output
Print the number of operations that will be performed.
Examples
Input
3 3
...
.#.
...
Output
2
Input
6 6
..#..#
......
..#..
......
.#....
....#.
Output
3 | instruction | 0 | 3,135 | 7 | 6,270 |
"Correct Solution:
```
from collections import deque
h,w = map(int,input().split())
l = [list(input()) for i in range(h)]
dis = [[10000]*w for i in range(h)]
q = deque([])
for i in range(h):
for j in range(w):
if l[i][j] == "#":
q.append([i,j,0])
dis[i][j] = 0
dx = [0,0,1,-1]
dy = [1,-1,0,0]
while q:
x,y,d = q.popleft()
for i in range(4):
nx = x + dx[i]
ny = y + dy[i]
if 0 <= nx < h and 0 <= ny < w and dis[nx][ny] > d+1:
dis[nx][ny] = d + 1
q.append([nx,ny,d+1])
ans = 0
for i in dis:
ans = max(ans,max(i))
print(ans)
``` | output | 1 | 3,135 | 7 | 6,271 |
Provide a correct Python 3 solution for this coding contest problem.
You are given a grid of squares with H horizontal rows and W vertical columns, where each square is painted white or black. HW characters from A_{11} to A_{HW} represent the colors of the squares. A_{ij} is `#` if the square at the i-th row from the top and the j-th column from the left is black, and A_{ij} is `.` if that square is white.
We will repeatedly perform the following operation until all the squares are black:
* Every white square that shares a side with a black square, becomes black.
Find the number of operations that will be performed. The initial grid has at least one black square.
Constraints
* 1 \leq H,W \leq 1000
* A_{ij} is `#` or `.`.
* The given grid has at least one black square.
Input
Input is given from Standard Input in the following format:
H W
A_{11}A_{12}...A_{1W}
:
A_{H1}A_{H2}...A_{HW}
Output
Print the number of operations that will be performed.
Examples
Input
3 3
...
.#.
...
Output
2
Input
6 6
..#..#
......
..#..
......
.#....
....#.
Output
3 | instruction | 0 | 3,136 | 7 | 6,272 |
"Correct Solution:
```
h,w = map(int,input().split())
a = list(list(input())for i in range(h))
stack = []
for i in range(h):
for j in range(w):
if a[i][j] == "#":
stack.append((i,j))
vec = ((1,0),(0,1),(-1,0),(0,-1))
move = 0
while stack:
next = []
move +=1
for y,x in stack:
for ny,nx in vec:
ty,tx = y+ny,x+nx
if ty>h-1 or tx>w-1 or ty<0 or tx <0:continue
if a[ty][tx] == ".":
a[ty][tx] = move
next.append((ty,tx))
stack = next
print(move-1)
``` | output | 1 | 3,136 | 7 | 6,273 |
Provide a correct Python 3 solution for this coding contest problem.
You are given a grid of squares with H horizontal rows and W vertical columns, where each square is painted white or black. HW characters from A_{11} to A_{HW} represent the colors of the squares. A_{ij} is `#` if the square at the i-th row from the top and the j-th column from the left is black, and A_{ij} is `.` if that square is white.
We will repeatedly perform the following operation until all the squares are black:
* Every white square that shares a side with a black square, becomes black.
Find the number of operations that will be performed. The initial grid has at least one black square.
Constraints
* 1 \leq H,W \leq 1000
* A_{ij} is `#` or `.`.
* The given grid has at least one black square.
Input
Input is given from Standard Input in the following format:
H W
A_{11}A_{12}...A_{1W}
:
A_{H1}A_{H2}...A_{HW}
Output
Print the number of operations that will be performed.
Examples
Input
3 3
...
.#.
...
Output
2
Input
6 6
..#..#
......
..#..
......
.#....
....#.
Output
3 | instruction | 0 | 3,137 | 7 | 6,274 |
"Correct Solution:
```
from collections import deque
h, w = map(int, input().split())
d = deque()
op = [[-1] * w for i in range(h)]
for i in range(h):
s = input().rstrip()
for j in range(len(s)):
if s[j] == '#':
d.append((i, j, 0))
op[i][j] = 0
while d:
i, j, step = d.popleft()
for i2, j2 in [(i-1, j), (i+1, j), (i, j-1), (i, j+1)]:
if 0 <= i2 < h and 0 <= j2 < w:
if op[i2][j2] == -1:
d.append((i2, j2, step+1))
op[i2][j2] = step + 1
print(max([max(op[i]) for i in range(h)]))
``` | output | 1 | 3,137 | 7 | 6,275 |
Provide a correct Python 3 solution for this coding contest problem.
You are given a grid of squares with H horizontal rows and W vertical columns, where each square is painted white or black. HW characters from A_{11} to A_{HW} represent the colors of the squares. A_{ij} is `#` if the square at the i-th row from the top and the j-th column from the left is black, and A_{ij} is `.` if that square is white.
We will repeatedly perform the following operation until all the squares are black:
* Every white square that shares a side with a black square, becomes black.
Find the number of operations that will be performed. The initial grid has at least one black square.
Constraints
* 1 \leq H,W \leq 1000
* A_{ij} is `#` or `.`.
* The given grid has at least one black square.
Input
Input is given from Standard Input in the following format:
H W
A_{11}A_{12}...A_{1W}
:
A_{H1}A_{H2}...A_{HW}
Output
Print the number of operations that will be performed.
Examples
Input
3 3
...
.#.
...
Output
2
Input
6 6
..#..#
......
..#..
......
.#....
....#.
Output
3 | instruction | 0 | 3,138 | 7 | 6,276 |
"Correct Solution:
```
from collections import deque
h, w = map(int, input().split())
a = [list(input()) for _ in range(h)]
q = deque([])
for i in range(h):
for j in range(w):
if a[i][j] == '#':
q.append([i, j])
q.append(0)
while q:
y, x = q.popleft()
ans = q.popleft() + 1
for dy, dx in [[1, 0], [0, 1], [-1, 0], [0, -1]]:
ny, nx = dy + y, dx + x
if ny < 0 or nx < 0 or ny >= h or nx >= w:
continue
if a[ny][nx] == '.':
a[ny][nx] = '#'
q.append([ny, nx])
q.append(ans)
print(ans-1)
``` | output | 1 | 3,138 | 7 | 6,277 |
Provide a correct Python 3 solution for this coding contest problem.
You are given a grid of squares with H horizontal rows and W vertical columns, where each square is painted white or black. HW characters from A_{11} to A_{HW} represent the colors of the squares. A_{ij} is `#` if the square at the i-th row from the top and the j-th column from the left is black, and A_{ij} is `.` if that square is white.
We will repeatedly perform the following operation until all the squares are black:
* Every white square that shares a side with a black square, becomes black.
Find the number of operations that will be performed. The initial grid has at least one black square.
Constraints
* 1 \leq H,W \leq 1000
* A_{ij} is `#` or `.`.
* The given grid has at least one black square.
Input
Input is given from Standard Input in the following format:
H W
A_{11}A_{12}...A_{1W}
:
A_{H1}A_{H2}...A_{HW}
Output
Print the number of operations that will be performed.
Examples
Input
3 3
...
.#.
...
Output
2
Input
6 6
..#..#
......
..#..
......
.#....
....#.
Output
3 | instruction | 0 | 3,139 | 7 | 6,278 |
"Correct Solution:
```
from collections import deque
h, w = map(int, input().split())
A = [input() for _ in range(h)]
dist = [[-1]*w for _ in range(h)]
di = [1, 0, -1, 0]
dj = [0, 1, 0, -1]
que = deque()
for i in range(h):
for j in range(w):
if A[i][j] == "#":
que.append((i, j))
dist[i][j] = 0
while que:
y, x = que.popleft()
for dy, dx in zip(di, dj):
ny, nx = y+dy, x+dx
if ny < 0 or ny >= h or nx < 0 or nx >= w:
continue
if dist[ny][nx] != -1:
continue
dist[ny][nx] = dist[y][x] + 1
que.append((ny, nx))
ans = 0
for i in dist:
ans = max(ans, max(i))
print(ans)
``` | output | 1 | 3,139 | 7 | 6,279 |
Provide a correct Python 3 solution for this coding contest problem.
You are given a grid of squares with H horizontal rows and W vertical columns, where each square is painted white or black. HW characters from A_{11} to A_{HW} represent the colors of the squares. A_{ij} is `#` if the square at the i-th row from the top and the j-th column from the left is black, and A_{ij} is `.` if that square is white.
We will repeatedly perform the following operation until all the squares are black:
* Every white square that shares a side with a black square, becomes black.
Find the number of operations that will be performed. The initial grid has at least one black square.
Constraints
* 1 \leq H,W \leq 1000
* A_{ij} is `#` or `.`.
* The given grid has at least one black square.
Input
Input is given from Standard Input in the following format:
H W
A_{11}A_{12}...A_{1W}
:
A_{H1}A_{H2}...A_{HW}
Output
Print the number of operations that will be performed.
Examples
Input
3 3
...
.#.
...
Output
2
Input
6 6
..#..#
......
..#..
......
.#....
....#.
Output
3 | instruction | 0 | 3,140 | 7 | 6,280 |
"Correct Solution:
```
h,w=map(int,input().split())
G=[input() for _ in range(h)]
from collections import deque
move=[(0,1),(0,-1),(1,0),(-1,0)]
que=deque([])
for i in range(h):
for j in range(w):
if G[i][j]=='#':
que.append((i,j,0))
c=0
visit=[[0]*w for _ in range(h)]
while len(que)>0:
ni,nj,c=que.popleft()
for di,dj in move:
mi,mj=ni+di,nj+dj
if 0<=mi<h and 0<=mj<w and G[mi][mj]=='.' and visit[mi][mj]==0:
visit[mi][mj]=1
que.append((mi,mj,c+1))
print(c)
``` | output | 1 | 3,140 | 7 | 6,281 |
Provide a correct Python 3 solution for this coding contest problem.
You are given a grid of squares with H horizontal rows and W vertical columns, where each square is painted white or black. HW characters from A_{11} to A_{HW} represent the colors of the squares. A_{ij} is `#` if the square at the i-th row from the top and the j-th column from the left is black, and A_{ij} is `.` if that square is white.
We will repeatedly perform the following operation until all the squares are black:
* Every white square that shares a side with a black square, becomes black.
Find the number of operations that will be performed. The initial grid has at least one black square.
Constraints
* 1 \leq H,W \leq 1000
* A_{ij} is `#` or `.`.
* The given grid has at least one black square.
Input
Input is given from Standard Input in the following format:
H W
A_{11}A_{12}...A_{1W}
:
A_{H1}A_{H2}...A_{HW}
Output
Print the number of operations that will be performed.
Examples
Input
3 3
...
.#.
...
Output
2
Input
6 6
..#..#
......
..#..
......
.#....
....#.
Output
3 | instruction | 0 | 3,141 | 7 | 6,282 |
"Correct Solution:
```
from collections import deque
H,W = map(int, input().split())
A = 0
dp = [None] * H
mat = deque()
for h in range(H):
s = list(input())
for w, x in zip(range(W), s):
if x == "#":
mat.append((h, w, 0))
dp[h] = s
while len(mat):
h, w, cnt = mat.popleft()
for t, h, w, cnt in [(h > 0, h - 1, w, cnt),(h < H-1, h + 1, w, cnt),(w > 0, h , w - 1, cnt),(w < W-1, h , w + 1, cnt)]:
if t and dp[h][w] == ".":
mat.append((h, w, cnt+1))
dp[h][w] = "#"
print(cnt)
``` | output | 1 | 3,141 | 7 | 6,283 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a grid of squares with H horizontal rows and W vertical columns, where each square is painted white or black. HW characters from A_{11} to A_{HW} represent the colors of the squares. A_{ij} is `#` if the square at the i-th row from the top and the j-th column from the left is black, and A_{ij} is `.` if that square is white.
We will repeatedly perform the following operation until all the squares are black:
* Every white square that shares a side with a black square, becomes black.
Find the number of operations that will be performed. The initial grid has at least one black square.
Constraints
* 1 \leq H,W \leq 1000
* A_{ij} is `#` or `.`.
* The given grid has at least one black square.
Input
Input is given from Standard Input in the following format:
H W
A_{11}A_{12}...A_{1W}
:
A_{H1}A_{H2}...A_{HW}
Output
Print the number of operations that will be performed.
Examples
Input
3 3
...
.#.
...
Output
2
Input
6 6
..#..#
......
..#..
......
.#....
....#.
Output
3
Submitted Solution:
```
H, W = map(int, input().split())
l = [list(input()) for _ in range(H)]
from collections import deque
q = deque()
for i, r in enumerate(l):
for j, c in enumerate(r):
if c == '#':
l[i][j] = 0
q.append((i, j))
d = [(0, 1), (0, -1), (1, 0), (-1, 0)]
while q:
y, x = q.popleft()
for dy, dx in d:
if (0 <= y+dy < H) and (0 <= x+dx < W) and l[y+dy][x+dx] == '.':
l[y+dy][x+dx] = l[y][x] + 1
q.append((y+dy, x+dx))
m = 0
for r in l:
for c in r:
if m < c:
m = c
print(m)
``` | instruction | 0 | 3,142 | 7 | 6,284 |
Yes | output | 1 | 3,142 | 7 | 6,285 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a grid of squares with H horizontal rows and W vertical columns, where each square is painted white or black. HW characters from A_{11} to A_{HW} represent the colors of the squares. A_{ij} is `#` if the square at the i-th row from the top and the j-th column from the left is black, and A_{ij} is `.` if that square is white.
We will repeatedly perform the following operation until all the squares are black:
* Every white square that shares a side with a black square, becomes black.
Find the number of operations that will be performed. The initial grid has at least one black square.
Constraints
* 1 \leq H,W \leq 1000
* A_{ij} is `#` or `.`.
* The given grid has at least one black square.
Input
Input is given from Standard Input in the following format:
H W
A_{11}A_{12}...A_{1W}
:
A_{H1}A_{H2}...A_{HW}
Output
Print the number of operations that will be performed.
Examples
Input
3 3
...
.#.
...
Output
2
Input
6 6
..#..#
......
..#..
......
.#....
....#.
Output
3
Submitted Solution:
```
import collections
h,w = map(int, input().split())
cells = []
for i in range(h):
row = input()
cells.append([c == '#' for c in row])
blacks = collections.deque()
for i in range(h):
for j in range(w):
if cells[i][j]:
blacks.append((i,j,0))
res = 0
while blacks:
y,x,c = blacks.popleft()
for dy,dx in ((-1, 0), (1, 0), (0, -1), (0,1)):
if 0<=y+dy<h and 0<=x+dx<w and not cells[y+dy][x+dx]:
cells[y+dy][x+dx] = True
blacks.append((y+dy, x+dx, c+1))
res = c+1
print(c)
``` | instruction | 0 | 3,143 | 7 | 6,286 |
Yes | output | 1 | 3,143 | 7 | 6,287 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.