message stringlengths 2 28.7k | message_type stringclasses 2 values | message_id int64 0 1 | conversation_id int64 21 109k | cluster float64 7 7 | __index_level_0__ int64 42 217k |
|---|---|---|---|---|---|
Provide a correct Python 3 solution for this coding contest problem.
We will create an artwork by painting black some squares in a white square grid with 10^9 rows and N columns.
The current plan is as follows: for the i-th column from the left, we will paint the H_i bottommost squares and will not paint the other squares in that column.
Before starting to work, you can choose at most K columns (possibly zero) and change the values of H_i for these columns to any integers of your choice between 0 and 10^9 (inclusive).
Different values can be chosen for different columns.
Then, you will create the modified artwork by repeating the following operation:
* Choose one or more consecutive squares in one row and paint them black. (Squares already painted black can be painted again, but squares not to be painted according to the modified plan should not be painted.)
Find the minimum number of times you need to perform this operation.
Constraints
* 1 \leq N \leq 300
* 0 \leq K \leq N
* 0 \leq H_i \leq 10^9
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N K
H_1 H_2 ... H_N
Output
Print the minimum number of operations required.
Examples
Input
4 1
2 3 4 1
Output
3
Input
6 2
8 6 9 1 2 1
Output
7
Input
10 0
1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000
Output
4999999996 | instruction | 0 | 63,772 | 7 | 127,544 |
"Correct Solution:
```
import sys
input = sys.stdin.readline
N, K = map(int, input().split())
a = [0] + list(map(int, input().split()))
inf = 10 ** 12
dp = [[[inf] * (N + 1) for _ in range(K + 1)] for _ in range(N + 1)]
dp[0][0][0] = 0
for i in range(N):
for j in range(K + 1):
for k in range(N + 1):
if dp[i][j][k] == inf: continue
x = max(0, a[i + 1] - a[k])
dp[i + 1][j][i + 1] = min(dp[i + 1][j][i + 1], dp[i][j][k] + x)
if j < K: dp[i + 1][j + 1][k] = min(dp[i + 1][j][k], dp[i][j][k])
#print(dp)
res = inf
for j in range(K + 1): res = min(res, min(dp[-1][j]))
print(res)
``` | output | 1 | 63,772 | 7 | 127,545 |
Provide a correct Python 3 solution for this coding contest problem.
We will create an artwork by painting black some squares in a white square grid with 10^9 rows and N columns.
The current plan is as follows: for the i-th column from the left, we will paint the H_i bottommost squares and will not paint the other squares in that column.
Before starting to work, you can choose at most K columns (possibly zero) and change the values of H_i for these columns to any integers of your choice between 0 and 10^9 (inclusive).
Different values can be chosen for different columns.
Then, you will create the modified artwork by repeating the following operation:
* Choose one or more consecutive squares in one row and paint them black. (Squares already painted black can be painted again, but squares not to be painted according to the modified plan should not be painted.)
Find the minimum number of times you need to perform this operation.
Constraints
* 1 \leq N \leq 300
* 0 \leq K \leq N
* 0 \leq H_i \leq 10^9
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N K
H_1 H_2 ... H_N
Output
Print the minimum number of operations required.
Examples
Input
4 1
2 3 4 1
Output
3
Input
6 2
8 6 9 1 2 1
Output
7
Input
10 0
1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000
Output
4999999996 | instruction | 0 | 63,773 | 7 | 127,546 |
"Correct Solution:
```
N,K = map(int, input().split())
H = [int(h) for h in input().split()]
dp = [[10**13]*N for _ in range(N)]
dp[0][0] = H[0]
for i in range(1, N):
for j in range(i+1):
if j == 0:
dp[i][j] = H[i]
continue
for k in range(i):
dp[i][j] = min(dp[i][j], dp[k][j-1]+max(0, H[i]-H[k]))
if N == K:
ans = 0
else:
ans = 10**13
for i in range(N):
ans = min(ans, dp[i][N-K-1])
print(ans)
``` | output | 1 | 63,773 | 7 | 127,547 |
Provide a correct Python 3 solution for this coding contest problem.
We will create an artwork by painting black some squares in a white square grid with 10^9 rows and N columns.
The current plan is as follows: for the i-th column from the left, we will paint the H_i bottommost squares and will not paint the other squares in that column.
Before starting to work, you can choose at most K columns (possibly zero) and change the values of H_i for these columns to any integers of your choice between 0 and 10^9 (inclusive).
Different values can be chosen for different columns.
Then, you will create the modified artwork by repeating the following operation:
* Choose one or more consecutive squares in one row and paint them black. (Squares already painted black can be painted again, but squares not to be painted according to the modified plan should not be painted.)
Find the minimum number of times you need to perform this operation.
Constraints
* 1 \leq N \leq 300
* 0 \leq K \leq N
* 0 \leq H_i \leq 10^9
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N K
H_1 H_2 ... H_N
Output
Print the minimum number of operations required.
Examples
Input
4 1
2 3 4 1
Output
3
Input
6 2
8 6 9 1 2 1
Output
7
Input
10 0
1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000
Output
4999999996 | instruction | 0 | 63,774 | 7 | 127,548 |
"Correct Solution:
```
N, K = map(int, input().split())
H = list(map(int, input().split()))
N += 1
H = [0] + H
DP = [[float('inf')] * N for _ in range(N)]
DP[0][0] = 0
for i in range(1, N):
DP[i][1] = H[i]
for j in range(2, i + 1):
for k in range(1, i):
DP[i][j] = min(DP[i][j], DP[k][j - 1] + max(0, H[i] - H[k]))
ans = float('inf')
for i in range(N):
ans = min(ans, DP[i][N - K - 1])
print(ans)
``` | output | 1 | 63,774 | 7 | 127,549 |
Provide a correct Python 3 solution for this coding contest problem.
We will create an artwork by painting black some squares in a white square grid with 10^9 rows and N columns.
The current plan is as follows: for the i-th column from the left, we will paint the H_i bottommost squares and will not paint the other squares in that column.
Before starting to work, you can choose at most K columns (possibly zero) and change the values of H_i for these columns to any integers of your choice between 0 and 10^9 (inclusive).
Different values can be chosen for different columns.
Then, you will create the modified artwork by repeating the following operation:
* Choose one or more consecutive squares in one row and paint them black. (Squares already painted black can be painted again, but squares not to be painted according to the modified plan should not be painted.)
Find the minimum number of times you need to perform this operation.
Constraints
* 1 \leq N \leq 300
* 0 \leq K \leq N
* 0 \leq H_i \leq 10^9
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N K
H_1 H_2 ... H_N
Output
Print the minimum number of operations required.
Examples
Input
4 1
2 3 4 1
Output
3
Input
6 2
8 6 9 1 2 1
Output
7
Input
10 0
1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000
Output
4999999996 | instruction | 0 | 63,775 | 7 | 127,550 |
"Correct Solution:
```
# -*- coding: utf-8 -*-
N,K=map(int, input().split())
H=list(map(int, input().split()))
G=[0]
G.extend(H[:])
dp=[[0]*(N+1) for i in range(N-K+1)]
tempa=0
if K<N-1:
for jtemp in range(N):
j=jtemp+1
dp[1][j]=G[j]#min(dp[1][j-1],G[j])
for itemp in range(N-K-1):
i=itemp+2
for jtemp in range(N-(i-1)):
j=jtemp+i
temp=int(N*1e9)
for ktemp in range(j-(i-1)):
k=ktemp+i-1
val=G[j]-G[k]
if val<0:
val=0
if temp>dp[i-1][k]+val:
temp=dp[i-1][k]+val
dp[i][j]=temp
tempa=dp[N-K][-1]
for jtemp in range(N):
j=jtemp+1
if tempa>dp[N-K][j] and dp[N-K][j]!=0:
tempa=dp[N-K][j]
elif N-K==1:
tempa=min(H[:])
else:
tempa=0
print(tempa)
``` | output | 1 | 63,775 | 7 | 127,551 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We will create an artwork by painting black some squares in a white square grid with 10^9 rows and N columns.
The current plan is as follows: for the i-th column from the left, we will paint the H_i bottommost squares and will not paint the other squares in that column.
Before starting to work, you can choose at most K columns (possibly zero) and change the values of H_i for these columns to any integers of your choice between 0 and 10^9 (inclusive).
Different values can be chosen for different columns.
Then, you will create the modified artwork by repeating the following operation:
* Choose one or more consecutive squares in one row and paint them black. (Squares already painted black can be painted again, but squares not to be painted according to the modified plan should not be painted.)
Find the minimum number of times you need to perform this operation.
Constraints
* 1 \leq N \leq 300
* 0 \leq K \leq N
* 0 \leq H_i \leq 10^9
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N K
H_1 H_2 ... H_N
Output
Print the minimum number of operations required.
Examples
Input
4 1
2 3 4 1
Output
3
Input
6 2
8 6 9 1 2 1
Output
7
Input
10 0
1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000
Output
4999999996
Submitted Solution:
```
n, k = list(map(int, input().split()))
hs = [0] + list(map(int, input().split()))
max_val = sum([max(hs[i + 1] - hs[i], 0) for i in range(n)])
dp = [[max_val for _ in range(n + 1)] for _ in range(n + 1)]
dp[0][0] = 0
for i in range(1, n + 1):
for j in range(1, n + 1):
dp[i][j] = min([dp[i - 1][l] + max(hs[j] - hs[l], 0) for l in range(j)])
print(min([dp[n - k][l] for l in range(n + 1)]))
``` | instruction | 0 | 63,776 | 7 | 127,552 |
Yes | output | 1 | 63,776 | 7 | 127,553 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We will create an artwork by painting black some squares in a white square grid with 10^9 rows and N columns.
The current plan is as follows: for the i-th column from the left, we will paint the H_i bottommost squares and will not paint the other squares in that column.
Before starting to work, you can choose at most K columns (possibly zero) and change the values of H_i for these columns to any integers of your choice between 0 and 10^9 (inclusive).
Different values can be chosen for different columns.
Then, you will create the modified artwork by repeating the following operation:
* Choose one or more consecutive squares in one row and paint them black. (Squares already painted black can be painted again, but squares not to be painted according to the modified plan should not be painted.)
Find the minimum number of times you need to perform this operation.
Constraints
* 1 \leq N \leq 300
* 0 \leq K \leq N
* 0 \leq H_i \leq 10^9
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N K
H_1 H_2 ... H_N
Output
Print the minimum number of operations required.
Examples
Input
4 1
2 3 4 1
Output
3
Input
6 2
8 6 9 1 2 1
Output
7
Input
10 0
1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000
Output
4999999996
Submitted Solution:
```
n, k = map(int, input().split())
h = list(map(int, input().split()))
if k == n:
print(0)
exit()
dp = [[0 for _ in range(n)] for _ in range(n-k)]
dp[0] = [] + h
for x in range(1, n-k):
for y in range(n):
temp = float('inf')
for i in range(y):
temp = min(temp, dp[x-1][i] + max(0, h[y] - h[i]))
dp[x][y] = temp
#for x in dp: print(x)
print(min(dp[n-k-1]))
``` | instruction | 0 | 63,777 | 7 | 127,554 |
Yes | output | 1 | 63,777 | 7 | 127,555 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We will create an artwork by painting black some squares in a white square grid with 10^9 rows and N columns.
The current plan is as follows: for the i-th column from the left, we will paint the H_i bottommost squares and will not paint the other squares in that column.
Before starting to work, you can choose at most K columns (possibly zero) and change the values of H_i for these columns to any integers of your choice between 0 and 10^9 (inclusive).
Different values can be chosen for different columns.
Then, you will create the modified artwork by repeating the following operation:
* Choose one or more consecutive squares in one row and paint them black. (Squares already painted black can be painted again, but squares not to be painted according to the modified plan should not be painted.)
Find the minimum number of times you need to perform this operation.
Constraints
* 1 \leq N \leq 300
* 0 \leq K \leq N
* 0 \leq H_i \leq 10^9
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N K
H_1 H_2 ... H_N
Output
Print the minimum number of operations required.
Examples
Input
4 1
2 3 4 1
Output
3
Input
6 2
8 6 9 1 2 1
Output
7
Input
10 0
1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000
Output
4999999996
Submitted Solution:
```
N, K = map(int, input().split())
H = list(map(int, input().split()))
# 全部消せる
if N <= K:
print(0)
exit()
dp = [[float('inf')] * (N + 1) for i in range(N + 1)]
dp[0][0] = 0
# 最初に使うとする場合には、その高さ分使う必要がある
for i, h in enumerate(H, start=1):
dp[i][1] = h
for i in range(1, N + 1):
for j in range(2, N + 1):
for x in range(1, i):
dp[i][j] = min(dp[i][j], dp[x][j - 1] + max(0, H[i - 1] - H[x - 1]))
ans = float('inf')
for i in range(N + 1):
ans = min(ans, dp[i][max(0, N - K)])
print(ans)
``` | instruction | 0 | 63,778 | 7 | 127,556 |
Yes | output | 1 | 63,778 | 7 | 127,557 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We will create an artwork by painting black some squares in a white square grid with 10^9 rows and N columns.
The current plan is as follows: for the i-th column from the left, we will paint the H_i bottommost squares and will not paint the other squares in that column.
Before starting to work, you can choose at most K columns (possibly zero) and change the values of H_i for these columns to any integers of your choice between 0 and 10^9 (inclusive).
Different values can be chosen for different columns.
Then, you will create the modified artwork by repeating the following operation:
* Choose one or more consecutive squares in one row and paint them black. (Squares already painted black can be painted again, but squares not to be painted according to the modified plan should not be painted.)
Find the minimum number of times you need to perform this operation.
Constraints
* 1 \leq N \leq 300
* 0 \leq K \leq N
* 0 \leq H_i \leq 10^9
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N K
H_1 H_2 ... H_N
Output
Print the minimum number of operations required.
Examples
Input
4 1
2 3 4 1
Output
3
Input
6 2
8 6 9 1 2 1
Output
7
Input
10 0
1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000
Output
4999999996
Submitted Solution:
```
N, K = map(int, input().split())
H = [0] + [int(i) for i in input().split()]
dp = [[float('inf')] * (N - K + 1) for _ in range(N + 1)]
dp[0][0] = 0
# 右端がi、サイズがj
for i in range(1, N + 1) :
for j in range(N - K + 1) :
dp[i][j] = min(dp[k][j-1] + max(0, H[i] - H[k]) for k in range(i))
print(min(dp[i][N-K] for i in range(N + 1)))
``` | instruction | 0 | 63,779 | 7 | 127,558 |
Yes | output | 1 | 63,779 | 7 | 127,559 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We will create an artwork by painting black some squares in a white square grid with 10^9 rows and N columns.
The current plan is as follows: for the i-th column from the left, we will paint the H_i bottommost squares and will not paint the other squares in that column.
Before starting to work, you can choose at most K columns (possibly zero) and change the values of H_i for these columns to any integers of your choice between 0 and 10^9 (inclusive).
Different values can be chosen for different columns.
Then, you will create the modified artwork by repeating the following operation:
* Choose one or more consecutive squares in one row and paint them black. (Squares already painted black can be painted again, but squares not to be painted according to the modified plan should not be painted.)
Find the minimum number of times you need to perform this operation.
Constraints
* 1 \leq N \leq 300
* 0 \leq K \leq N
* 0 \leq H_i \leq 10^9
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N K
H_1 H_2 ... H_N
Output
Print the minimum number of operations required.
Examples
Input
4 1
2 3 4 1
Output
3
Input
6 2
8 6 9 1 2 1
Output
7
Input
10 0
1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000
Output
4999999996
Submitted Solution:
```
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1
def main():
N,K=map(int,input().split())
N+=2
H=[0]+list(map(int,input().split()))+[0]
edge=[[] for _ in range(N*(K+1))]
for i in range(N):
for j in range(K+1):
f=0
for k in range(K+1-j):
if i+k+1<N and N-1-i>=K-(k+j):
if k==0 or f:
edge[i*(K+1)+j].append((max(H[i+k+1]-H[i],0),(i+k+1)*(K+1)+j+k))
if H[i]<H[i+k+1]:
f=1
from heapq import heappop,heappush
def dijkstra(start,n,edges):
d=[INF]*n
used=[False]*n
d[start]=0
used[start]=True
edgelist=[]
for edge in edges[start]:
heappush(edgelist,edge)
while edgelist:
minedge=heappop(edgelist)
if used[minedge[1]]:
continue
v=minedge[1]
d[v]=minedge[0]
used[v]=True
for edge in edges[v]:
if not used[edge[1]]:
heappush(edgelist,(edge[0]+d[v],edge[1]))
return d
d=dijkstra(0,N*(K+1),edge)
print(min(d[(N-1)*(K+1):]))
if __name__ == '__main__':
main()
``` | instruction | 0 | 63,780 | 7 | 127,560 |
No | output | 1 | 63,780 | 7 | 127,561 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We will create an artwork by painting black some squares in a white square grid with 10^9 rows and N columns.
The current plan is as follows: for the i-th column from the left, we will paint the H_i bottommost squares and will not paint the other squares in that column.
Before starting to work, you can choose at most K columns (possibly zero) and change the values of H_i for these columns to any integers of your choice between 0 and 10^9 (inclusive).
Different values can be chosen for different columns.
Then, you will create the modified artwork by repeating the following operation:
* Choose one or more consecutive squares in one row and paint them black. (Squares already painted black can be painted again, but squares not to be painted according to the modified plan should not be painted.)
Find the minimum number of times you need to perform this operation.
Constraints
* 1 \leq N \leq 300
* 0 \leq K \leq N
* 0 \leq H_i \leq 10^9
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N K
H_1 H_2 ... H_N
Output
Print the minimum number of operations required.
Examples
Input
4 1
2 3 4 1
Output
3
Input
6 2
8 6 9 1 2 1
Output
7
Input
10 0
1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000
Output
4999999996
Submitted Solution:
```
n,k = map(int,input().split())
lis = list(map(int,input().split()))
lis.insert(0,0)
lis.append(0)
n += 2
num = 0
for nu in lis:
if nu != 0:
num += 1
if num <= k:
print(0)
exit()
for _ in range(k):
li = [0 for i in range(n)]
for i in range(n):
if i != n-1:
li[i] = max(li[i],lis[i]-lis[i+1])
if i != 0:
li[i] = max(li[i],lis[i]-lis[i-1])
numm = li.index(max(li))
if numm == 0:
lis[0] = lis[1]
elif numm == n-1:
lis[n-1] = lis[n-2]
else:
lis[numm] = min(lis[numm-1],lis[numm+1])
ans = 0
num = 0
for i in range(n):
if lis[i] >= num:
num = lis[i]
else:
ans += num-lis[i]
num = lis[i]
ans += num
print(ans)
``` | instruction | 0 | 63,781 | 7 | 127,562 |
No | output | 1 | 63,781 | 7 | 127,563 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We will create an artwork by painting black some squares in a white square grid with 10^9 rows and N columns.
The current plan is as follows: for the i-th column from the left, we will paint the H_i bottommost squares and will not paint the other squares in that column.
Before starting to work, you can choose at most K columns (possibly zero) and change the values of H_i for these columns to any integers of your choice between 0 and 10^9 (inclusive).
Different values can be chosen for different columns.
Then, you will create the modified artwork by repeating the following operation:
* Choose one or more consecutive squares in one row and paint them black. (Squares already painted black can be painted again, but squares not to be painted according to the modified plan should not be painted.)
Find the minimum number of times you need to perform this operation.
Constraints
* 1 \leq N \leq 300
* 0 \leq K \leq N
* 0 \leq H_i \leq 10^9
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N K
H_1 H_2 ... H_N
Output
Print the minimum number of operations required.
Examples
Input
4 1
2 3 4 1
Output
3
Input
6 2
8 6 9 1 2 1
Output
7
Input
10 0
1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000
Output
4999999996
Submitted Solution:
```
import sys
input = sys.stdin.readline
N,K = map(int,input().split())
H = [0]+list(map(int,input().split()))
DP=[[1<<60]*(K+1) for i in range(N+1)]
for k in range(K+1):
DP[0][k]=0
for i in range(1,N+1):
for k in range(K+1):
for j in range(k+1):
DP[i][k]=min(DP[i][k],DP[i-j-1][k-j]+max(0,H[i]-H[i-j-1]))
print(min(DP[-1]))
``` | instruction | 0 | 63,782 | 7 | 127,564 |
No | output | 1 | 63,782 | 7 | 127,565 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We will create an artwork by painting black some squares in a white square grid with 10^9 rows and N columns.
The current plan is as follows: for the i-th column from the left, we will paint the H_i bottommost squares and will not paint the other squares in that column.
Before starting to work, you can choose at most K columns (possibly zero) and change the values of H_i for these columns to any integers of your choice between 0 and 10^9 (inclusive).
Different values can be chosen for different columns.
Then, you will create the modified artwork by repeating the following operation:
* Choose one or more consecutive squares in one row and paint them black. (Squares already painted black can be painted again, but squares not to be painted according to the modified plan should not be painted.)
Find the minimum number of times you need to perform this operation.
Constraints
* 1 \leq N \leq 300
* 0 \leq K \leq N
* 0 \leq H_i \leq 10^9
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N K
H_1 H_2 ... H_N
Output
Print the minimum number of operations required.
Examples
Input
4 1
2 3 4 1
Output
3
Input
6 2
8 6 9 1 2 1
Output
7
Input
10 0
1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000
Output
4999999996
Submitted Solution:
```
def solve():
INF = float('inf')
N, K = map(int, input().split())
Hs = list(map(int, input().split())) + [0]
if N == K:
return 0
# 最初に変更しないkを全探索する
ans = INF
for k in range(N):
if k > K: continue
dp = [[INF]*(K+1) for _ in range(N)]
dp[k][k] = Hs[k]
for i in range(k+1, N):
# 今回変更しない
d = max(0, Hs[i] - Hs[i-1])
for j in range(K+1):
dp[i][j] = min(dp[i][j], dp[i-1][j] + d)
# 今回変更する
if Hs[i] > Hs[i+1]:
for j in range(1, K+1):
dp[i][j] = min(dp[i][j], dp[i-1][j-1])
else:
for j in range(1, K+1):
dp[i][j] = min(dp[i][j], dp[i-1][j])
num = min(dp[N-1])
ans = min(ans, num)
return ans
ans = solve()
print(ans)
``` | instruction | 0 | 63,783 | 7 | 127,566 |
No | output | 1 | 63,783 | 7 | 127,567 |
Provide tags and a correct Python 3 solution for this coding contest problem.
In the city of Ultima Thule job applicants are often offered an IQ test.
The test is as follows: the person gets a piece of squared paper with a 4 × 4 square painted on it. Some of the square's cells are painted black and others are painted white. Your task is to repaint at most one cell the other color so that the picture has a 2 × 2 square, completely consisting of cells of the same color. If the initial picture already has such a square, the person should just say so and the test will be completed.
Your task is to write a program that determines whether it is possible to pass the test. You cannot pass the test if either repainting any cell or no action doesn't result in a 2 × 2 square, consisting of cells of the same color.
Input
Four lines contain four characters each: the j-th character of the i-th line equals "." if the cell in the i-th row and the j-th column of the square is painted white, and "#", if the cell is black.
Output
Print "YES" (without the quotes), if the test can be passed and "NO" (without the quotes) otherwise.
Examples
Input
####
.#..
####
....
Output
YES
Input
####
....
####
....
Output
NO
Note
In the first test sample it is enough to repaint the first cell in the second row. After such repainting the required 2 × 2 square is on the intersection of the 1-st and 2-nd row with the 1-st and 2-nd column. | instruction | 0 | 64,288 | 7 | 128,576 |
Tags: brute force, implementation
Correct Solution:
```
# IQ Test
from collections import Counter
def calculate(lines):
"""
"""
row = 0
col = 0
row_char = 0
col_char = 0
black = "#"
whitee = "."
while(row <= 2 and col <= 2 and row_char <= 2 and col_char <= 2):
c1 = lines[row_char][col_char]
c2 = lines[row_char][col_char+1]
c3 = lines[row_char+1][col_char]
c4 = lines[row_char+1][col_char+1]
counter = Counter([c1,c2,c3,c4])
bcount = counter.get(black, 0)
if bcount in [0,1,3,4]:
return "YES"
if col_char == 2:
col_char = 0
row_char += 1
else:
col_char += 1
return "NO"
if __name__ == "__main__":
lines = []
for i in range(4):
lines.append(list(input()))
response = calculate(lines)
print(response)
``` | output | 1 | 64,288 | 7 | 128,577 |
Provide tags and a correct Python 3 solution for this coding contest problem.
In the city of Ultima Thule job applicants are often offered an IQ test.
The test is as follows: the person gets a piece of squared paper with a 4 × 4 square painted on it. Some of the square's cells are painted black and others are painted white. Your task is to repaint at most one cell the other color so that the picture has a 2 × 2 square, completely consisting of cells of the same color. If the initial picture already has such a square, the person should just say so and the test will be completed.
Your task is to write a program that determines whether it is possible to pass the test. You cannot pass the test if either repainting any cell or no action doesn't result in a 2 × 2 square, consisting of cells of the same color.
Input
Four lines contain four characters each: the j-th character of the i-th line equals "." if the cell in the i-th row and the j-th column of the square is painted white, and "#", if the cell is black.
Output
Print "YES" (without the quotes), if the test can be passed and "NO" (without the quotes) otherwise.
Examples
Input
####
.#..
####
....
Output
YES
Input
####
....
####
....
Output
NO
Note
In the first test sample it is enough to repaint the first cell in the second row. After such repainting the required 2 × 2 square is on the intersection of the 1-st and 2-nd row with the 1-st and 2-nd column. | instruction | 0 | 64,289 | 7 | 128,578 |
Tags: brute force, implementation
Correct Solution:
```
__copyright__ = ''
__author__ = 'Son-Huy TRAN'
__email__ = "sonhuytran@gmail.com"
__doc__ = ''
__version__ = '1.0'
def can_paint(wall: list) -> bool:
for i in range(3):
for j in range(3):
temp = wall[i][j] + wall[i + 1][j] + wall[i][j + 1] + wall[i + 1][j + 1]
if temp.count('.') != temp.count('#'):
return True
return False
def main() -> int:
wall = [input(), input(), input(), input()]
print('YES' if can_paint(wall) else 'NO')
return 0
if __name__ == '__main__':
exit(main())
``` | output | 1 | 64,289 | 7 | 128,579 |
Provide tags and a correct Python 3 solution for this coding contest problem.
In the city of Ultima Thule job applicants are often offered an IQ test.
The test is as follows: the person gets a piece of squared paper with a 4 × 4 square painted on it. Some of the square's cells are painted black and others are painted white. Your task is to repaint at most one cell the other color so that the picture has a 2 × 2 square, completely consisting of cells of the same color. If the initial picture already has such a square, the person should just say so and the test will be completed.
Your task is to write a program that determines whether it is possible to pass the test. You cannot pass the test if either repainting any cell or no action doesn't result in a 2 × 2 square, consisting of cells of the same color.
Input
Four lines contain four characters each: the j-th character of the i-th line equals "." if the cell in the i-th row and the j-th column of the square is painted white, and "#", if the cell is black.
Output
Print "YES" (without the quotes), if the test can be passed and "NO" (without the quotes) otherwise.
Examples
Input
####
.#..
####
....
Output
YES
Input
####
....
####
....
Output
NO
Note
In the first test sample it is enough to repaint the first cell in the second row. After such repainting the required 2 × 2 square is on the intersection of the 1-st and 2-nd row with the 1-st and 2-nd column. | instruction | 0 | 64,290 | 7 | 128,580 |
Tags: brute force, implementation
Correct Solution:
```
values = []
yes = False
for i in range(4):
line = list(input())
seg1 = line[:2]
seg2 = line[1:3]
seg3 = line[2:4]
arr = [0, 0, 0]
if seg1.count("#") == 1:
arr[0] = 1
elif seg1.count("#") == 2:
arr[0] = 2
if seg2.count("#") == 1:
arr[1] = 1
elif seg2.count("#") == 2:
arr[1] = 2
if seg3.count("#") == 1:
arr[2] = 1
elif seg3.count("#") == 2:
arr[2] = 2
values.append(arr)
for i in range(len(values)):
values[i].append(5)
values.append([5, 5, 5, 5])
for row in range(4):
for column in range(3):
if (values[row][column] == 2 and values[row + 1][column] == 1) or (values[row][column] == 1 and values[row + 1][column] == 2) \
or (values[row][column] == 2 and values[row + 1][column] == 2) or (values[row][column] == 0 and values[row + 1][column] == 0) \
or (values[row][column] == 1 and values[row + 1][column] == 0) or (values[row][column] == 0 and values[row + 1][column] == 1) :
yes = True
if yes:
print("YES")
else:
print("NO")
``` | output | 1 | 64,290 | 7 | 128,581 |
Provide tags and a correct Python 3 solution for this coding contest problem.
In the city of Ultima Thule job applicants are often offered an IQ test.
The test is as follows: the person gets a piece of squared paper with a 4 × 4 square painted on it. Some of the square's cells are painted black and others are painted white. Your task is to repaint at most one cell the other color so that the picture has a 2 × 2 square, completely consisting of cells of the same color. If the initial picture already has such a square, the person should just say so and the test will be completed.
Your task is to write a program that determines whether it is possible to pass the test. You cannot pass the test if either repainting any cell or no action doesn't result in a 2 × 2 square, consisting of cells of the same color.
Input
Four lines contain four characters each: the j-th character of the i-th line equals "." if the cell in the i-th row and the j-th column of the square is painted white, and "#", if the cell is black.
Output
Print "YES" (without the quotes), if the test can be passed and "NO" (without the quotes) otherwise.
Examples
Input
####
.#..
####
....
Output
YES
Input
####
....
####
....
Output
NO
Note
In the first test sample it is enough to repaint the first cell in the second row. After such repainting the required 2 × 2 square is on the intersection of the 1-st and 2-nd row with the 1-st and 2-nd column. | instruction | 0 | 64,291 | 7 | 128,582 |
Tags: brute force, implementation
Correct Solution:
```
a = []
for i in range(4):
a.append(input())
for i in range(3):
for j in range(3):
k = 0
if a[i][j] == '#':
k += 1
if a[i][j+1] == '#':
k += 1
if a[i+1][j] == '#':
k += 1
if a[i+1][j+1] == '#':
k += 1
if k>=3:
print("YES")
exit()
k = 0
if a[i][j] == '.':
k += 1
if a[i][j+1] == '.':
k += 1
if a[i+1][j] == '.':
k += 1
if a[i+1][j+1] == '.':
k += 1
if k>=3:
print("YES")
exit()
print("NO")
``` | output | 1 | 64,291 | 7 | 128,583 |
Provide tags and a correct Python 3 solution for this coding contest problem.
In the city of Ultima Thule job applicants are often offered an IQ test.
The test is as follows: the person gets a piece of squared paper with a 4 × 4 square painted on it. Some of the square's cells are painted black and others are painted white. Your task is to repaint at most one cell the other color so that the picture has a 2 × 2 square, completely consisting of cells of the same color. If the initial picture already has such a square, the person should just say so and the test will be completed.
Your task is to write a program that determines whether it is possible to pass the test. You cannot pass the test if either repainting any cell or no action doesn't result in a 2 × 2 square, consisting of cells of the same color.
Input
Four lines contain four characters each: the j-th character of the i-th line equals "." if the cell in the i-th row and the j-th column of the square is painted white, and "#", if the cell is black.
Output
Print "YES" (without the quotes), if the test can be passed and "NO" (without the quotes) otherwise.
Examples
Input
####
.#..
####
....
Output
YES
Input
####
....
####
....
Output
NO
Note
In the first test sample it is enough to repaint the first cell in the second row. After such repainting the required 2 × 2 square is on the intersection of the 1-st and 2-nd row with the 1-st and 2-nd column. | instruction | 0 | 64,292 | 7 | 128,584 |
Tags: brute force, implementation
Correct Solution:
```
a = [input() for _ in range(4)]
flag=0
for i in range(0,3):
for j in range(0,3):
s=a[i][j]+a[i][j+1]+a[i+1][j]+a[i+1][j+1]
if s.count('#')==0 or s.count('#')==1 or s.count('#')==3 or s.count('#')==4:
print("YES")
flag=1
exit()
if flag==0:
print("NO")
``` | output | 1 | 64,292 | 7 | 128,585 |
Provide tags and a correct Python 3 solution for this coding contest problem.
In the city of Ultima Thule job applicants are often offered an IQ test.
The test is as follows: the person gets a piece of squared paper with a 4 × 4 square painted on it. Some of the square's cells are painted black and others are painted white. Your task is to repaint at most one cell the other color so that the picture has a 2 × 2 square, completely consisting of cells of the same color. If the initial picture already has such a square, the person should just say so and the test will be completed.
Your task is to write a program that determines whether it is possible to pass the test. You cannot pass the test if either repainting any cell or no action doesn't result in a 2 × 2 square, consisting of cells of the same color.
Input
Four lines contain four characters each: the j-th character of the i-th line equals "." if the cell in the i-th row and the j-th column of the square is painted white, and "#", if the cell is black.
Output
Print "YES" (without the quotes), if the test can be passed and "NO" (without the quotes) otherwise.
Examples
Input
####
.#..
####
....
Output
YES
Input
####
....
####
....
Output
NO
Note
In the first test sample it is enough to repaint the first cell in the second row. After such repainting the required 2 × 2 square is on the intersection of the 1-st and 2-nd row with the 1-st and 2-nd column. | instruction | 0 | 64,293 | 7 | 128,586 |
Tags: brute force, implementation
Correct Solution:
```
square = []
for i in range(4):
square.append(list(input()))
testPassed = False
for i in range(3):
for j in range(3):
if testPassed:
break
smallSquare = square[i][j] + square[i+1][j] + square[i][j+1] + square[i+1][j+1]
whiteCount = smallSquare.count('.')
blackCount = smallSquare.count('#')
if (whiteCount == 3 and blackCount == 1) or (whiteCount == 1 and blackCount == 3) or (whiteCount == 4 and blackCount == 0) or (whiteCount == 0 and blackCount == 4):
testPassed = True
print("YES")
if not testPassed:
print("NO")
``` | output | 1 | 64,293 | 7 | 128,587 |
Provide tags and a correct Python 3 solution for this coding contest problem.
In the city of Ultima Thule job applicants are often offered an IQ test.
The test is as follows: the person gets a piece of squared paper with a 4 × 4 square painted on it. Some of the square's cells are painted black and others are painted white. Your task is to repaint at most one cell the other color so that the picture has a 2 × 2 square, completely consisting of cells of the same color. If the initial picture already has such a square, the person should just say so and the test will be completed.
Your task is to write a program that determines whether it is possible to pass the test. You cannot pass the test if either repainting any cell or no action doesn't result in a 2 × 2 square, consisting of cells of the same color.
Input
Four lines contain four characters each: the j-th character of the i-th line equals "." if the cell in the i-th row and the j-th column of the square is painted white, and "#", if the cell is black.
Output
Print "YES" (without the quotes), if the test can be passed and "NO" (without the quotes) otherwise.
Examples
Input
####
.#..
####
....
Output
YES
Input
####
....
####
....
Output
NO
Note
In the first test sample it is enough to repaint the first cell in the second row. After such repainting the required 2 × 2 square is on the intersection of the 1-st and 2-nd row with the 1-st and 2-nd column. | instruction | 0 | 64,294 | 7 | 128,588 |
Tags: brute force, implementation
Correct Solution:
```
matriz = [list(map(str, input())) for i in range(4)]
flag = False
for i in range(4):
for j in range(4):
try:
m = matriz
sqr = [m[i][j], m[i][j+1], m[i+1][j], m[i+1][j+1]]
if sqr.count('#') >= 3 or sqr.count('.') >= 3:
flag = True
except:
continue
if flag:
print('YES')
else:
print('NO')
``` | output | 1 | 64,294 | 7 | 128,589 |
Provide tags and a correct Python 3 solution for this coding contest problem.
In the city of Ultima Thule job applicants are often offered an IQ test.
The test is as follows: the person gets a piece of squared paper with a 4 × 4 square painted on it. Some of the square's cells are painted black and others are painted white. Your task is to repaint at most one cell the other color so that the picture has a 2 × 2 square, completely consisting of cells of the same color. If the initial picture already has such a square, the person should just say so and the test will be completed.
Your task is to write a program that determines whether it is possible to pass the test. You cannot pass the test if either repainting any cell or no action doesn't result in a 2 × 2 square, consisting of cells of the same color.
Input
Four lines contain four characters each: the j-th character of the i-th line equals "." if the cell in the i-th row and the j-th column of the square is painted white, and "#", if the cell is black.
Output
Print "YES" (without the quotes), if the test can be passed and "NO" (without the quotes) otherwise.
Examples
Input
####
.#..
####
....
Output
YES
Input
####
....
####
....
Output
NO
Note
In the first test sample it is enough to repaint the first cell in the second row. After such repainting the required 2 × 2 square is on the intersection of the 1-st and 2-nd row with the 1-st and 2-nd column. | instruction | 0 | 64,295 | 7 | 128,590 |
Tags: brute force, implementation
Correct Solution:
```
matrix =[]
for i in range(4):
matrix.append([])
a =input()
for char in a:
matrix[i].append(char)
def a():
e =0
g =0
if (matrix[0][0] == '.' and matrix[0][1] == '.' and matrix[1][0] == '.' and matrix[1][1] == '.'):
e =1
#print ('11')
elif (matrix[0][2] == '.' and matrix[0][3] == '.' and matrix[1][2] == '.' and matrix[1][3] == '.'):
e =1
#print ('12')
elif (matrix[2][0] == '.' and matrix[2][1] == '.' and matrix[3][0] == '.' and matrix[3][1] == '.'):
e =1
#print ('13')
elif (matrix[2][2] == '.' and matrix[2][3] == '.' and matrix[3][2] == '.' and matrix[3][3] == '.'):
e =1
#print ('14')
elif (matrix[0][1] == '.' and matrix[0][2] == '.' and matrix[1][1] == '.' and matrix[1][2] == '.'):
e =1
#print ('15')
elif (matrix[2][1] == '.' and matrix[2][2] == '.' and matrix[3][1] == '.' and matrix[3][2] == '.'):
e =1
#print ('16')
elif (matrix[1][0] == '.' and matrix[1][1] == '.' and matrix[2][0] == '.' and matrix[2][1] == '.'):
e =1
#print ('17')
elif (matrix[1][2] == '.' and matrix[1][3] == '.' and matrix[2][2] == '.' and matrix[2][3] == '.'):
e =1
#print ('18')
elif (matrix[1][1] == '.' and matrix[1][2] == '.' and matrix[2][1] == '.' and matrix[2][2] == '.'):
e =1
if (e):
print ('YES')
#print ('1')
exit(0)
def b():
e =0
if (matrix[0][0] == '#' and matrix[0][1] == '#' and matrix[1][0] == '#' and matrix[1][1] == '#'):
e =1
elif (matrix[0][2] == '#' and matrix[0][3] == '#' and matrix[1][2] == '#' and matrix[1][3] == '#'):
e =1
elif (matrix[2][0] == '#' and matrix[2][1] == '#' and matrix[3][0] == '#' and matrix[3][1] == '#'):
e =1
elif (matrix[2][2] == '#' and matrix[2][3] == '#' and matrix[3][2] == '#' and matrix[3][3] == '#'):
e =1
elif (matrix[0][1] == '#' and matrix[0][2] == '#' and matrix[1][1] == '#' and matrix[1][2] == '#'):
e =1
elif (matrix[2][1] == '#' and matrix[2][2] == '#' and matrix[3][1] == '#' and matrix[3][2] == '#'):
e =1
elif (matrix[1][0] == '#' and matrix[1][1] == '#' and matrix[2][0] == '#' and matrix[2][1] == '#'):
e =1
elif (matrix[1][2] == '#' and matrix[1][3] == '#' and matrix[2][2] == '#' and matrix[2][3] == '#'):
e =1
elif (matrix[1][1] == '#' and matrix[1][2] == '#' and matrix[2][1] == '#' and matrix[2][2] == '#'):
e =1
if (e):
print ('YES')
#print ('2')
exit(0)
a()
b()
for i in range(4):
for j in range(4):
if (matrix[i][j] == '.'):
matrix[i][j] ='#'
b()
matrix[i][j] ='.'
elif (matrix[i][j] == '#'):
matrix[i][j] = '.'
a()
matrix[i][j] ='#'
print ('NO')
``` | output | 1 | 64,295 | 7 | 128,591 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In the city of Ultima Thule job applicants are often offered an IQ test.
The test is as follows: the person gets a piece of squared paper with a 4 × 4 square painted on it. Some of the square's cells are painted black and others are painted white. Your task is to repaint at most one cell the other color so that the picture has a 2 × 2 square, completely consisting of cells of the same color. If the initial picture already has such a square, the person should just say so and the test will be completed.
Your task is to write a program that determines whether it is possible to pass the test. You cannot pass the test if either repainting any cell or no action doesn't result in a 2 × 2 square, consisting of cells of the same color.
Input
Four lines contain four characters each: the j-th character of the i-th line equals "." if the cell in the i-th row and the j-th column of the square is painted white, and "#", if the cell is black.
Output
Print "YES" (without the quotes), if the test can be passed and "NO" (without the quotes) otherwise.
Examples
Input
####
.#..
####
....
Output
YES
Input
####
....
####
....
Output
NO
Note
In the first test sample it is enough to repaint the first cell in the second row. After such repainting the required 2 × 2 square is on the intersection of the 1-st and 2-nd row with the 1-st and 2-nd column.
Submitted Solution:
```
def comp(a,b,c,d):
if a==b and b==c and a!=d: return True
if a==b and b==d and a!=c: return True
if a==c and d==c and a!=b: return True
if b==c and c==d and b!=a: return True
return False
def ig(a,b,c,d):
if a==b and b==c and c==d: return True
return False
mat=[]
ans="NO"
for i in range(4):
mat.append(input())
for i in range(3):
for j in range(3):
if comp(mat[i][j],mat[i+1][j],mat[i][j+1],mat[i+1][j+1]) or ig(mat[i][j],mat[i+1][j],mat[i][j+1],mat[i+1][j+1]):
ans="YES"
print(ans)
``` | instruction | 0 | 64,296 | 7 | 128,592 |
Yes | output | 1 | 64,296 | 7 | 128,593 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In the city of Ultima Thule job applicants are often offered an IQ test.
The test is as follows: the person gets a piece of squared paper with a 4 × 4 square painted on it. Some of the square's cells are painted black and others are painted white. Your task is to repaint at most one cell the other color so that the picture has a 2 × 2 square, completely consisting of cells of the same color. If the initial picture already has such a square, the person should just say so and the test will be completed.
Your task is to write a program that determines whether it is possible to pass the test. You cannot pass the test if either repainting any cell or no action doesn't result in a 2 × 2 square, consisting of cells of the same color.
Input
Four lines contain four characters each: the j-th character of the i-th line equals "." if the cell in the i-th row and the j-th column of the square is painted white, and "#", if the cell is black.
Output
Print "YES" (without the quotes), if the test can be passed and "NO" (without the quotes) otherwise.
Examples
Input
####
.#..
####
....
Output
YES
Input
####
....
####
....
Output
NO
Note
In the first test sample it is enough to repaint the first cell in the second row. After such repainting the required 2 × 2 square is on the intersection of the 1-st and 2-nd row with the 1-st and 2-nd column.
Submitted Solution:
```
matriz = [input() for _ in range(4)]
for i in range(3):
for j in range(3):
count = 0
if matriz[i][j] == '#':
count += 1
if matriz[i][j+1] == '#':
count += 1
if matriz[i+1][j] == '#':
count += 1
if matriz[i+1][j+1] == '#':
count += 1
if count != 2:
print('YES')
exit()
print('NO')
``` | instruction | 0 | 64,297 | 7 | 128,594 |
Yes | output | 1 | 64,297 | 7 | 128,595 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In the city of Ultima Thule job applicants are often offered an IQ test.
The test is as follows: the person gets a piece of squared paper with a 4 × 4 square painted on it. Some of the square's cells are painted black and others are painted white. Your task is to repaint at most one cell the other color so that the picture has a 2 × 2 square, completely consisting of cells of the same color. If the initial picture already has such a square, the person should just say so and the test will be completed.
Your task is to write a program that determines whether it is possible to pass the test. You cannot pass the test if either repainting any cell or no action doesn't result in a 2 × 2 square, consisting of cells of the same color.
Input
Four lines contain four characters each: the j-th character of the i-th line equals "." if the cell in the i-th row and the j-th column of the square is painted white, and "#", if the cell is black.
Output
Print "YES" (without the quotes), if the test can be passed and "NO" (without the quotes) otherwise.
Examples
Input
####
.#..
####
....
Output
YES
Input
####
....
####
....
Output
NO
Note
In the first test sample it is enough to repaint the first cell in the second row. After such repainting the required 2 × 2 square is on the intersection of the 1-st and 2-nd row with the 1-st and 2-nd column.
Submitted Solution:
```
square = [[0 for i in range(4)] for i in range(4)]
for i in range(4):
line = input()
for j in range(4):
if line[j] == '#':
square[i][j] = 1
else:
square[i][j] = 0
#print(square)
ans = False
for i in range(3):
for j in range(3):
s = square[i][j] + square[i][j+1] + square[i+1][j] + square[i+1][j+1]
if s >= 3 or s <= 1:
#print(i, j)
ans = True
break
if ans:
break
if ans:
print("YES")
else:
print("NO")
``` | instruction | 0 | 64,298 | 7 | 128,596 |
Yes | output | 1 | 64,298 | 7 | 128,597 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In the city of Ultima Thule job applicants are often offered an IQ test.
The test is as follows: the person gets a piece of squared paper with a 4 × 4 square painted on it. Some of the square's cells are painted black and others are painted white. Your task is to repaint at most one cell the other color so that the picture has a 2 × 2 square, completely consisting of cells of the same color. If the initial picture already has such a square, the person should just say so and the test will be completed.
Your task is to write a program that determines whether it is possible to pass the test. You cannot pass the test if either repainting any cell or no action doesn't result in a 2 × 2 square, consisting of cells of the same color.
Input
Four lines contain four characters each: the j-th character of the i-th line equals "." if the cell in the i-th row and the j-th column of the square is painted white, and "#", if the cell is black.
Output
Print "YES" (without the quotes), if the test can be passed and "NO" (without the quotes) otherwise.
Examples
Input
####
.#..
####
....
Output
YES
Input
####
....
####
....
Output
NO
Note
In the first test sample it is enough to repaint the first cell in the second row. After such repainting the required 2 × 2 square is on the intersection of the 1-st and 2-nd row with the 1-st and 2-nd column.
Submitted Solution:
```
import sys
def input(): return sys.stdin.readline().strip()
def iinput(): return int(input())
def rinput(): return map(int, sys.stdin.readline().strip().split())
def get_list(): return list(map(int, sys.stdin.readline().strip().split()))
a = []
for _ in range(4):
a.append(input())
for i in range(3):
for j in range(3):
r = 0
if a[i][j] == a[i][j+1]: r+=1
if a[i][j] == a[i+1][j+1]: r+=1
if a[i][j] == a[i+1][j]: r+=1
if(r>1 or r == 0):
print("YES")
exit()
print("NO")
``` | instruction | 0 | 64,299 | 7 | 128,598 |
Yes | output | 1 | 64,299 | 7 | 128,599 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In the city of Ultima Thule job applicants are often offered an IQ test.
The test is as follows: the person gets a piece of squared paper with a 4 × 4 square painted on it. Some of the square's cells are painted black and others are painted white. Your task is to repaint at most one cell the other color so that the picture has a 2 × 2 square, completely consisting of cells of the same color. If the initial picture already has such a square, the person should just say so and the test will be completed.
Your task is to write a program that determines whether it is possible to pass the test. You cannot pass the test if either repainting any cell or no action doesn't result in a 2 × 2 square, consisting of cells of the same color.
Input
Four lines contain four characters each: the j-th character of the i-th line equals "." if the cell in the i-th row and the j-th column of the square is painted white, and "#", if the cell is black.
Output
Print "YES" (without the quotes), if the test can be passed and "NO" (without the quotes) otherwise.
Examples
Input
####
.#..
####
....
Output
YES
Input
####
....
####
....
Output
NO
Note
In the first test sample it is enough to repaint the first cell in the second row. After such repainting the required 2 × 2 square is on the intersection of the 1-st and 2-nd row with the 1-st and 2-nd column.
Submitted Solution:
```
k = ''
for _ in range(4):
s = input()
if len(set(s))==1 and k!=s[0]:
k = s[0]
else:
exit(print("YES"))
print("NO")
``` | instruction | 0 | 64,300 | 7 | 128,600 |
No | output | 1 | 64,300 | 7 | 128,601 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In the city of Ultima Thule job applicants are often offered an IQ test.
The test is as follows: the person gets a piece of squared paper with a 4 × 4 square painted on it. Some of the square's cells are painted black and others are painted white. Your task is to repaint at most one cell the other color so that the picture has a 2 × 2 square, completely consisting of cells of the same color. If the initial picture already has such a square, the person should just say so and the test will be completed.
Your task is to write a program that determines whether it is possible to pass the test. You cannot pass the test if either repainting any cell or no action doesn't result in a 2 × 2 square, consisting of cells of the same color.
Input
Four lines contain four characters each: the j-th character of the i-th line equals "." if the cell in the i-th row and the j-th column of the square is painted white, and "#", if the cell is black.
Output
Print "YES" (without the quotes), if the test can be passed and "NO" (without the quotes) otherwise.
Examples
Input
####
.#..
####
....
Output
YES
Input
####
....
####
....
Output
NO
Note
In the first test sample it is enough to repaint the first cell in the second row. After such repainting the required 2 × 2 square is on the intersection of the 1-st and 2-nd row with the 1-st and 2-nd column.
Submitted Solution:
```
s = []
for i in range(4):
s.append(input())
b = False
for i in range(3):
for j in range(3):
if (s[i][j]==s[i][j+1]):
if s[i][j] in s[i+1][j:j+2]:
b = True;
if s[i+1][j]==s[i+1][j]:
if s[i+1][j] in s[i][j:j+2]:
b = True
if b:
print("YES")
else:
print("NO")
``` | instruction | 0 | 64,301 | 7 | 128,602 |
No | output | 1 | 64,301 | 7 | 128,603 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In the city of Ultima Thule job applicants are often offered an IQ test.
The test is as follows: the person gets a piece of squared paper with a 4 × 4 square painted on it. Some of the square's cells are painted black and others are painted white. Your task is to repaint at most one cell the other color so that the picture has a 2 × 2 square, completely consisting of cells of the same color. If the initial picture already has such a square, the person should just say so and the test will be completed.
Your task is to write a program that determines whether it is possible to pass the test. You cannot pass the test if either repainting any cell or no action doesn't result in a 2 × 2 square, consisting of cells of the same color.
Input
Four lines contain four characters each: the j-th character of the i-th line equals "." if the cell in the i-th row and the j-th column of the square is painted white, and "#", if the cell is black.
Output
Print "YES" (without the quotes), if the test can be passed and "NO" (without the quotes) otherwise.
Examples
Input
####
.#..
####
....
Output
YES
Input
####
....
####
....
Output
NO
Note
In the first test sample it is enough to repaint the first cell in the second row. After such repainting the required 2 × 2 square is on the intersection of the 1-st and 2-nd row with the 1-st and 2-nd column.
Submitted Solution:
```
BS="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
def to_base(s, b):
res = ""
while s:
res+=BS[s%b]
s//= b
return res[::-1] or "0"
alpha = "abcdefghijklmnopqrstuvwxyz"
from collections import Counter
grid = []
for i in range(4):
grid.append(list(input()))
ans = False
for i in range(len(grid)-1):
for j in range(len(grid)-1):
#print(i,j)
if grid[i][j] == "#" and grid[i][j + 1] == "#":
if grid[i+1][j] == "#" or grid[i+1][j + 1] == "#":
ans = True
break
if grid[i][j] == "." and grid[i][j + 1] == ".":
if grid[i+1][j] == "." or grid[i+1][j + 1] == ".":
ans = True
break
if ans:
print("YES")
else:
print("NO")
``` | instruction | 0 | 64,302 | 7 | 128,604 |
No | output | 1 | 64,302 | 7 | 128,605 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In the city of Ultima Thule job applicants are often offered an IQ test.
The test is as follows: the person gets a piece of squared paper with a 4 × 4 square painted on it. Some of the square's cells are painted black and others are painted white. Your task is to repaint at most one cell the other color so that the picture has a 2 × 2 square, completely consisting of cells of the same color. If the initial picture already has such a square, the person should just say so and the test will be completed.
Your task is to write a program that determines whether it is possible to pass the test. You cannot pass the test if either repainting any cell or no action doesn't result in a 2 × 2 square, consisting of cells of the same color.
Input
Four lines contain four characters each: the j-th character of the i-th line equals "." if the cell in the i-th row and the j-th column of the square is painted white, and "#", if the cell is black.
Output
Print "YES" (without the quotes), if the test can be passed and "NO" (without the quotes) otherwise.
Examples
Input
####
.#..
####
....
Output
YES
Input
####
....
####
....
Output
NO
Note
In the first test sample it is enough to repaint the first cell in the second row. After such repainting the required 2 × 2 square is on the intersection of the 1-st and 2-nd row with the 1-st and 2-nd column.
Submitted Solution:
```
import sys
lista=""
try:
lista = sys.stdin.readlines()
except KeyboardInterrupt:
pass
control = False
aprobo = "NO"
forma = ''
matriz=[]
for i in range(4):
matriz.append(list(lista[i].strip('\n')))
print(matriz)
f= 0
while(f<4):
c= 0
while( c < 4):
l = False #inquierda
r = False #derecha
u = False #arriba
d = False #abajo
dru = False #diagonal derecha arriba
dlu = False #diagonal izq arriba
drd = False #diagonal derecha abajo
dld = False #diagonal izq abajo
#Definimos formas
if(matriz[f][c] == '.'):
forma = '#'
else:
forma = '.'
if(f ==0 and c == 0):
if(forma == matriz[f][c+1]):
r = True
else:
r = False
if(forma == matriz[f+1][c]):
d = True
else:
d = False
if(forma == matriz[f+1][c+1]):
drd = True
else:
drd = False
if(r and d and drd):
aprobo ="YES"
control = True
break
else:
if(f == 0 and c == 3):
if(forma == matriz[f][c-1]):
l = True
else:
l = False
if(forma == matriz[f+1][c]):
d = True
else:
d = False
if(forma == matriz[f+1][c-1]):
dld = True
else:
dld = False
if(l and d and dld):
aprobo ="YES"
control = True
break
else:
if(f ==3 and c == 0):
if(forma == matriz[f][c+1]):
r = True
else:
r = False
if(forma == matriz[f-1][c]):
u = True
else:
u = False
if(forma == matriz[f-1][c+1]):
dru = True
else:
dru = False
if(r and u and dru):
aprobo ="YES"
control = True
break
else:
if(f ==3 and c == 3):
if(forma == matriz[f][c-1]):
l = True
else:
l = False
if(forma == matriz[f-1][c]):
u = True
else:
u = False
if(forma == matriz[f-1][c-1]):
dlu = True
else:
dlu = False
if(r and u and dru):
aprobo ="YES"
control = True
break
else:
if(f>0 and f< 3 and c>0 and c <3):
if(forma == matriz[f-1][c-1]):
dlu = True
else:
dlu = False
if(forma == matriz[f-1][c]):
u = True
else:
u = False
if(forma == matriz[f-1][c+1]):
dru = True
else:
dru = False
if(forma == matriz[f][c-1]):
l = True
else:
l = False
if(forma == matriz[f][c+1]):
r = True
else:
r = False
if(forma == matriz[f+1][c-1]):
dld = True
else:
dld = False
if(forma == matriz[f+1][c]):
d = True
else:
d = False
if(forma == matriz[f+1][c+1]):
drd = True
else:
drd = False
if((dlu and u and l) or (dru and u and r) or (dld and d and l) or (drd and d and r)):
aprobo ="YES"
control = True
break
else:
if(f>0 and c == 0):
if(forma == matriz[f-1][c]):
u = True
else:
u = False
if(forma == matriz[f-1][c+1]):
dru = True
else:
dru = False
if(forma == matriz[f][c+1]):
r = True
else:
r = False
if(forma == matriz[f+1][c]):
d = True
else:
d = False
if(forma == matriz[f+1][c+1]):
drd = True
else:
drd = False
if((u and dru and r) or (r and drd and d)):
aprobo ="YES"
control = True
break
else:
if(f>0 and c == 3):
if(forma == matriz[f-1][c]):
u = True
else:
u = False
if(forma == matriz[f-1][c-1]):
dlu = True
else:
dlu = False
if(forma == matriz[f][c-1]):
l = True
else:
l = False
if(forma == matriz[f+1][c-1]):
dld = True
else:
dld = False
if(forma == matriz[f+1][c]):
d = True
else:
d = False
if((u and dlu and l) or (l and dld and d)):
aprobo ="YES"
control = True
break
else:
if(f==3 and c < 3):
if(forma == matriz[f][c-1]):
l = True
else:
l = False
if(forma == matriz[f-1][c-1]):
dlu = True
else:
dlu = False
if(forma == matriz[f-1][c]):
u = True
else:
u = False
if(forma == matriz[f-1][c+1]):
dru = True
else:
dru = False
if(forma == matriz[f][c+1]):
r = True
else:
r = False
if((l and dlu and u) or (u and dru and r)):
aprobo ="YES"
control = True
break
else:
if(f==0 and c < 3):
if(forma == matriz[f][c-1]):
l = True
else:
l = False
if(forma == matriz[f+1][c-1]):
dld = True
else:
dld = False
if(forma == matriz[f+1][c]):
d = True
else:
d = False
if(forma == matriz[f+1][c+1]):
drd = True
else:
drd = False
if(forma == matriz[f][c+1]):
r = True
else:
r = False
if((l and dld and d) or (d and drd and r)):
aprobo ="YES"
control = True
break
c = c+1
if(control):
break
f = f+1
print(aprobo)
``` | instruction | 0 | 64,303 | 7 | 128,606 |
No | output | 1 | 64,303 | 7 | 128,607 |
Provide a correct Python 3 solution for this coding contest problem.
Problem
There is a grid of $ N \ times N $ cells. Initially all cells are white. Follow the steps below to increase the number of black squares.
Select one white cell from the cells that are even-numbered from the top and even-numbered from the left. The selected square turns black. Further, the adjacent white squares also change to black in a chain reaction in each of the vertical and horizontal directions of the squares. This chain continues until there are no white cells in that direction. (An example is shown below)
□□□□□□□□□
□□□□□□□□□
□□□□□□□□□
□□□□□□□□□
□□□□□□□□□
□□□□□□□□□
□□□□□□□□□
□□□□□□□□□
□□□□□□□□□
↓ Select the 4th from the top and the 6th from the left
□□□□□ ■ □□□
□□□□□ ■ □□□
□□□□□ ■ □□□
■■■■■■■■■
□□□□□ ■ □□□
□□□□□ ■ □□□
□□□□□ ■ □□□
□□□□□ ■ □□□
□□□□□ ■ □□□
↓ Select the second from the top and the second from the left
□ ■ □□□ ■ □□□
■■■■■■ □□□
□ ■ □□□ ■ □□□
■■■■■■■■■
□□□□□ ■ □□□
□□□□□ ■ □□□
□□□□□ ■ □□□
□□□□□ ■ □□□
□□□□□ ■ □□□
↓ Select 6th from the top and 8th from the left
□ ■ □□□ ■ □□□
■■■■■■ □□□
□ ■ □□□ ■ □□□
■■■■■■■■■
□□□□□ ■ □ ■ □
□□□□□ ■■■■
□□□□□ ■ □ ■ □
□□□□□ ■ □ ■ □
□□□□□ ■ □ ■ □
You want to create a grid where the color of the $ i $ th cell from the top and the $ j $ th cell from the left is $ A_ {i, j} $. Find the minimum number of times to select a square.
Constraints
The input satisfies the following conditions.
* $ 3 \ le N \ le 127 $
* $ N $ is odd
* $ A_ {i, j} $ is'o'or'x'
* Only input that can be made is given
Input
The input is given in the following format.
$ N $
$ A_ {1,1} $ $ A_ {1,2} $ ... $ A_ {1, N} $
$ A_ {2,1} $ $ A_ {2,2} $ ... $ A_ {2, N} $
...
$ A_ {N, 1} $ $ A_ {N, 2} $ ... $ A_ {N, N} $
When $ A_ {i, j} $ is'o', it means that the $ i $ th cell from the top and the $ j $ th cell from the left are white, and when it is'x', it is a black cell. Represents that.
Output
Outputs the minimum number of times to select a cell on the first line.
Examples
Input
5
oxooo
oxooo
oxooo
xxxxx
oxooo
Output
1
Input
9
oxoooooxo
oxxxxxxxx
oxoooooxo
xxxxxxxxx
oxoxooooo
oxxxxxxxx
oxoxoxooo
oxoxxxxxx
oxoxoxooo
Output
4 | instruction | 0 | 66,423 | 7 | 132,846 |
"Correct Solution:
```
from collections import deque
n = int(input())
A = [input() for i in range(n)]
cnt = 0
dd = [[-1, 0], [0, -1], [1, 0], [0, 1]]
used = {}
for i in range(n):
for j in range(n):
if A[i][j] == 'x' or (i, j) in used:
continue
deq = deque([(j, i)])
used[i, j] = 1
cnt += 1
while deq:
x, y = deq.popleft()
for dx, dy in dd:
nx = x + dx; ny = y + dy
if 0 <= nx < n and 0 <= ny < n:
if A[ny][nx] == 'o' and (ny, nx) not in used:
used[ny, nx] = 1
deq.append((nx, ny))
print(cnt//3)
``` | output | 1 | 66,423 | 7 | 132,847 |
Provide a correct Python 3 solution for this coding contest problem.
problem
President K decided to make a flag for IOI 2016 in Russia. Chairman K first took out the old flag from the warehouse. This flag is divided into squares of N rows and M columns, and each square is painted in one of white, blue, and red.
Chairman K is trying to repaint some of the squares on this flag to make it the Russian flag. However, the Russian flag in this problem is as follows.
* Several lines (one or more lines) from the top are all painted in white.
* The next few lines (one or more lines) are all painted in blue.
* All the cells in the other lines (one or more lines) are painted in red.
Find the minimum number of squares that President K needs to repaint to turn the old flag into a Russian flag.
input
The input consists of 1 + N lines.
On the first line, two integers N and M (3 ≤ N ≤ 50, 3 ≤ M ≤ 50) are written separated by a blank. This means that the flags are separated by N rows and M columns.
The following N lines each contain a string of M characters, which represents the color information painted in the squares of the old flag. The jth character (1 ≤ i ≤ N, 1 ≤ j ≤ M) on the i-th line of the N-line represents the color of the cell on the i-th line and j-th column of the old flag. It is either B'or'R'. 'W' stands for white,'B' stands for blue, and'R' stands for red.
output
Output in one line the minimum number of squares that President K needs to repaint to turn the old flag into a Russian flag.
Input / output example
Input example 1
4 5
WRWRW
BWRWB
WRWRW
RWBWR
Output example 1
11
Input example 2
6 14
WWWWWWWWWWWWWW
WBBBWWRRWWBBBW
WWBWWRRRRWWBWW
BWBWWRRRRWWBWW
WBBWWWRRWWBBBW
WWWWWWWWWWWWWW
Output example 2
44
In I / O example 1, the old flag is colored as shown in the figure below.
fig01
In the figure below, repaint the 11 squares with an'X'.
fig02
This makes it possible to make the Russian flag as shown in the figure below.
fig03
Since it is not possible to make a Russian flag by repainting less than 11 squares, 11 is output.
In I / O example 2, the old flag is colored as shown in the figure below.
fig04
Creative Commons License
Information Olympics Japan Committee work "15th Japan Information Olympics JOI 2015/2016 Qualifying Competition Tasks"
Example
Input
4 5
WRWRW
BWRWB
WRWRW
RWBWR
Output
11 | instruction | 0 | 67,166 | 7 | 134,332 |
"Correct Solution:
```
h,w=[int(s)for s in input().split(" ")]
flag=[input()for i in range(h)]
mincnt=1145141919810
for i in range(1,h-1):
for j in range(1,h-i):
cnt=0
wr=flag[:i]
br=flag[i:i+j]
rr=flag[i+j:]
for l in wr:
for c in l:
if c!='W':cnt+=1
for l in br:
for c in l:
if c!='B':cnt+=1
for l in rr:
for c in l:
if c!='R':cnt+=1
if cnt<mincnt:
mincnt=cnt
print(mincnt)
``` | output | 1 | 67,166 | 7 | 134,333 |
Provide a correct Python 3 solution for this coding contest problem.
problem
President K decided to make a flag for IOI 2016 in Russia. Chairman K first took out the old flag from the warehouse. This flag is divided into squares of N rows and M columns, and each square is painted in one of white, blue, and red.
Chairman K is trying to repaint some of the squares on this flag to make it the Russian flag. However, the Russian flag in this problem is as follows.
* Several lines (one or more lines) from the top are all painted in white.
* The next few lines (one or more lines) are all painted in blue.
* All the cells in the other lines (one or more lines) are painted in red.
Find the minimum number of squares that President K needs to repaint to turn the old flag into a Russian flag.
input
The input consists of 1 + N lines.
On the first line, two integers N and M (3 ≤ N ≤ 50, 3 ≤ M ≤ 50) are written separated by a blank. This means that the flags are separated by N rows and M columns.
The following N lines each contain a string of M characters, which represents the color information painted in the squares of the old flag. The jth character (1 ≤ i ≤ N, 1 ≤ j ≤ M) on the i-th line of the N-line represents the color of the cell on the i-th line and j-th column of the old flag. It is either B'or'R'. 'W' stands for white,'B' stands for blue, and'R' stands for red.
output
Output in one line the minimum number of squares that President K needs to repaint to turn the old flag into a Russian flag.
Input / output example
Input example 1
4 5
WRWRW
BWRWB
WRWRW
RWBWR
Output example 1
11
Input example 2
6 14
WWWWWWWWWWWWWW
WBBBWWRRWWBBBW
WWBWWRRRRWWBWW
BWBWWRRRRWWBWW
WBBWWWRRWWBBBW
WWWWWWWWWWWWWW
Output example 2
44
In I / O example 1, the old flag is colored as shown in the figure below.
fig01
In the figure below, repaint the 11 squares with an'X'.
fig02
This makes it possible to make the Russian flag as shown in the figure below.
fig03
Since it is not possible to make a Russian flag by repainting less than 11 squares, 11 is output.
In I / O example 2, the old flag is colored as shown in the figure below.
fig04
Creative Commons License
Information Olympics Japan Committee work "15th Japan Information Olympics JOI 2015/2016 Qualifying Competition Tasks"
Example
Input
4 5
WRWRW
BWRWB
WRWRW
RWBWR
Output
11 | instruction | 0 | 67,167 | 7 | 134,334 |
"Correct Solution:
```
inf = 10**20
n,m = map(int, input().split())
flist = []
wbrnum = {}
for i in range(n):
a = list(str(input()))
flist.append(a)
b = []
b.append(a.count('W'))
b.append(a.count('B'))
b.append(a.count('R'))
wbrnum[i] = b
cnt = inf
for i in range(n-2):
cnti = 0
for l in range(i+1):
cnti += (wbrnum[l][1]+wbrnum[l][2])
for j in range(i+1,n-1):
cntj = 0
cnto = 0
for o in range(i+1,j+1):
cntj += (wbrnum[o][0]+wbrnum[o][2])
for o in range(j+1,n):
cnto += (wbrnum[o][0]+wbrnum[o][1])
cnt = min(cnt,(cnti+cntj+cnto))
#print(i,j,cnti,cntj,cnto,cnt)
print(cnt)
``` | output | 1 | 67,167 | 7 | 134,335 |
Provide a correct Python 3 solution for this coding contest problem.
problem
President K decided to make a flag for IOI 2016 in Russia. Chairman K first took out the old flag from the warehouse. This flag is divided into squares of N rows and M columns, and each square is painted in one of white, blue, and red.
Chairman K is trying to repaint some of the squares on this flag to make it the Russian flag. However, the Russian flag in this problem is as follows.
* Several lines (one or more lines) from the top are all painted in white.
* The next few lines (one or more lines) are all painted in blue.
* All the cells in the other lines (one or more lines) are painted in red.
Find the minimum number of squares that President K needs to repaint to turn the old flag into a Russian flag.
input
The input consists of 1 + N lines.
On the first line, two integers N and M (3 ≤ N ≤ 50, 3 ≤ M ≤ 50) are written separated by a blank. This means that the flags are separated by N rows and M columns.
The following N lines each contain a string of M characters, which represents the color information painted in the squares of the old flag. The jth character (1 ≤ i ≤ N, 1 ≤ j ≤ M) on the i-th line of the N-line represents the color of the cell on the i-th line and j-th column of the old flag. It is either B'or'R'. 'W' stands for white,'B' stands for blue, and'R' stands for red.
output
Output in one line the minimum number of squares that President K needs to repaint to turn the old flag into a Russian flag.
Input / output example
Input example 1
4 5
WRWRW
BWRWB
WRWRW
RWBWR
Output example 1
11
Input example 2
6 14
WWWWWWWWWWWWWW
WBBBWWRRWWBBBW
WWBWWRRRRWWBWW
BWBWWRRRRWWBWW
WBBWWWRRWWBBBW
WWWWWWWWWWWWWW
Output example 2
44
In I / O example 1, the old flag is colored as shown in the figure below.
fig01
In the figure below, repaint the 11 squares with an'X'.
fig02
This makes it possible to make the Russian flag as shown in the figure below.
fig03
Since it is not possible to make a Russian flag by repainting less than 11 squares, 11 is output.
In I / O example 2, the old flag is colored as shown in the figure below.
fig04
Creative Commons License
Information Olympics Japan Committee work "15th Japan Information Olympics JOI 2015/2016 Qualifying Competition Tasks"
Example
Input
4 5
WRWRW
BWRWB
WRWRW
RWBWR
Output
11 | instruction | 0 | 67,168 | 7 | 134,336 |
"Correct Solution:
```
h, w = map(int, input().split())
f = [0 for _ in range(h)]
for i in range(h):
f[i] = input()
cw = [f[i].count("W") for i in range(h)]
cb = [f[i].count("B") for i in range(h)]
cr = [f[i].count("R") for i in range(h)]
count = h * w
for i in range(1, h - 1):
for j in range(i, h):
count = min(count,h * w - sum(cw[:i]) - sum(cb[i:j]) - sum(cr[j:]))
print(count)
``` | output | 1 | 67,168 | 7 | 134,337 |
Provide a correct Python 3 solution for this coding contest problem.
problem
President K decided to make a flag for IOI 2016 in Russia. Chairman K first took out the old flag from the warehouse. This flag is divided into squares of N rows and M columns, and each square is painted in one of white, blue, and red.
Chairman K is trying to repaint some of the squares on this flag to make it the Russian flag. However, the Russian flag in this problem is as follows.
* Several lines (one or more lines) from the top are all painted in white.
* The next few lines (one or more lines) are all painted in blue.
* All the cells in the other lines (one or more lines) are painted in red.
Find the minimum number of squares that President K needs to repaint to turn the old flag into a Russian flag.
input
The input consists of 1 + N lines.
On the first line, two integers N and M (3 ≤ N ≤ 50, 3 ≤ M ≤ 50) are written separated by a blank. This means that the flags are separated by N rows and M columns.
The following N lines each contain a string of M characters, which represents the color information painted in the squares of the old flag. The jth character (1 ≤ i ≤ N, 1 ≤ j ≤ M) on the i-th line of the N-line represents the color of the cell on the i-th line and j-th column of the old flag. It is either B'or'R'. 'W' stands for white,'B' stands for blue, and'R' stands for red.
output
Output in one line the minimum number of squares that President K needs to repaint to turn the old flag into a Russian flag.
Input / output example
Input example 1
4 5
WRWRW
BWRWB
WRWRW
RWBWR
Output example 1
11
Input example 2
6 14
WWWWWWWWWWWWWW
WBBBWWRRWWBBBW
WWBWWRRRRWWBWW
BWBWWRRRRWWBWW
WBBWWWRRWWBBBW
WWWWWWWWWWWWWW
Output example 2
44
In I / O example 1, the old flag is colored as shown in the figure below.
fig01
In the figure below, repaint the 11 squares with an'X'.
fig02
This makes it possible to make the Russian flag as shown in the figure below.
fig03
Since it is not possible to make a Russian flag by repainting less than 11 squares, 11 is output.
In I / O example 2, the old flag is colored as shown in the figure below.
fig04
Creative Commons License
Information Olympics Japan Committee work "15th Japan Information Olympics JOI 2015/2016 Qualifying Competition Tasks"
Example
Input
4 5
WRWRW
BWRWB
WRWRW
RWBWR
Output
11 | instruction | 0 | 67,169 | 7 | 134,338 |
"Correct Solution:
```
# coding: utf-8
N, M = list(map(int, input().split(' ')))
colors = []
for i in range(N):
row = list(input())
row_color = [0, 0, 0]
for c in row:
if c == 'W': row_color[0] += 1
elif c == 'B': row_color[1] += 1
elif c == 'R': row_color[2] += 1
colors.append(row_color)
min_diff = float('inf')
for blue_top in range(1, N-1):
for red_top in range(blue_top+1, N):
diff = 0
for i in range(N):
if i < blue_top:
diff += colors[i][1] + colors[i][2]
elif i < red_top:
diff += colors[i][0] + colors[i][2]
else:
diff += colors[i][0] + colors[i][1]
if diff < min_diff:
min_diff = diff
print(min_diff)
``` | output | 1 | 67,169 | 7 | 134,339 |
Provide a correct Python 3 solution for this coding contest problem.
problem
President K decided to make a flag for IOI 2016 in Russia. Chairman K first took out the old flag from the warehouse. This flag is divided into squares of N rows and M columns, and each square is painted in one of white, blue, and red.
Chairman K is trying to repaint some of the squares on this flag to make it the Russian flag. However, the Russian flag in this problem is as follows.
* Several lines (one or more lines) from the top are all painted in white.
* The next few lines (one or more lines) are all painted in blue.
* All the cells in the other lines (one or more lines) are painted in red.
Find the minimum number of squares that President K needs to repaint to turn the old flag into a Russian flag.
input
The input consists of 1 + N lines.
On the first line, two integers N and M (3 ≤ N ≤ 50, 3 ≤ M ≤ 50) are written separated by a blank. This means that the flags are separated by N rows and M columns.
The following N lines each contain a string of M characters, which represents the color information painted in the squares of the old flag. The jth character (1 ≤ i ≤ N, 1 ≤ j ≤ M) on the i-th line of the N-line represents the color of the cell on the i-th line and j-th column of the old flag. It is either B'or'R'. 'W' stands for white,'B' stands for blue, and'R' stands for red.
output
Output in one line the minimum number of squares that President K needs to repaint to turn the old flag into a Russian flag.
Input / output example
Input example 1
4 5
WRWRW
BWRWB
WRWRW
RWBWR
Output example 1
11
Input example 2
6 14
WWWWWWWWWWWWWW
WBBBWWRRWWBBBW
WWBWWRRRRWWBWW
BWBWWRRRRWWBWW
WBBWWWRRWWBBBW
WWWWWWWWWWWWWW
Output example 2
44
In I / O example 1, the old flag is colored as shown in the figure below.
fig01
In the figure below, repaint the 11 squares with an'X'.
fig02
This makes it possible to make the Russian flag as shown in the figure below.
fig03
Since it is not possible to make a Russian flag by repainting less than 11 squares, 11 is output.
In I / O example 2, the old flag is colored as shown in the figure below.
fig04
Creative Commons License
Information Olympics Japan Committee work "15th Japan Information Olympics JOI 2015/2016 Qualifying Competition Tasks"
Example
Input
4 5
WRWRW
BWRWB
WRWRW
RWBWR
Output
11 | instruction | 0 | 67,170 | 7 | 134,340 |
"Correct Solution:
```
n,m=map(int,input().split())
flag=[list(input()) for _ in range(n)]
w=[]
b=[]
r=[]
for i in flag:
w.append(i.count('W'))
b.append(i.count('B'))
r.append(i.count('R'))
ans=10**18
for x in range(1,n-1):
for y in range(x+1,n):
ans=min(ans,sum(b[:x])+sum(r[:x])+sum(w[x:y])+sum(r[x:y])+sum(w[y:])+sum(b[y:]))
print(ans)
``` | output | 1 | 67,170 | 7 | 134,341 |
Provide a correct Python 3 solution for this coding contest problem.
problem
President K decided to make a flag for IOI 2016 in Russia. Chairman K first took out the old flag from the warehouse. This flag is divided into squares of N rows and M columns, and each square is painted in one of white, blue, and red.
Chairman K is trying to repaint some of the squares on this flag to make it the Russian flag. However, the Russian flag in this problem is as follows.
* Several lines (one or more lines) from the top are all painted in white.
* The next few lines (one or more lines) are all painted in blue.
* All the cells in the other lines (one or more lines) are painted in red.
Find the minimum number of squares that President K needs to repaint to turn the old flag into a Russian flag.
input
The input consists of 1 + N lines.
On the first line, two integers N and M (3 ≤ N ≤ 50, 3 ≤ M ≤ 50) are written separated by a blank. This means that the flags are separated by N rows and M columns.
The following N lines each contain a string of M characters, which represents the color information painted in the squares of the old flag. The jth character (1 ≤ i ≤ N, 1 ≤ j ≤ M) on the i-th line of the N-line represents the color of the cell on the i-th line and j-th column of the old flag. It is either B'or'R'. 'W' stands for white,'B' stands for blue, and'R' stands for red.
output
Output in one line the minimum number of squares that President K needs to repaint to turn the old flag into a Russian flag.
Input / output example
Input example 1
4 5
WRWRW
BWRWB
WRWRW
RWBWR
Output example 1
11
Input example 2
6 14
WWWWWWWWWWWWWW
WBBBWWRRWWBBBW
WWBWWRRRRWWBWW
BWBWWRRRRWWBWW
WBBWWWRRWWBBBW
WWWWWWWWWWWWWW
Output example 2
44
In I / O example 1, the old flag is colored as shown in the figure below.
fig01
In the figure below, repaint the 11 squares with an'X'.
fig02
This makes it possible to make the Russian flag as shown in the figure below.
fig03
Since it is not possible to make a Russian flag by repainting less than 11 squares, 11 is output.
In I / O example 2, the old flag is colored as shown in the figure below.
fig04
Creative Commons License
Information Olympics Japan Committee work "15th Japan Information Olympics JOI 2015/2016 Qualifying Competition Tasks"
Example
Input
4 5
WRWRW
BWRWB
WRWRW
RWBWR
Output
11 | instruction | 0 | 67,171 | 7 | 134,342 |
"Correct Solution:
```
n, m = map(int, input().split())
w = []
b = []
r = []
for i in range(n):
s = input()
w.append(m - s.count("W"))
b.append(m - s.count("B"))
r.append(m - s.count("R"))
ans = 3000
for i in range(1, n - 1):
for j in range(i, n - 1):
ans = min(ans, sum(w[:i]) + sum(b[i:j+1]) + sum(r[j + 1:]))
print(ans)
``` | output | 1 | 67,171 | 7 | 134,343 |
Provide a correct Python 3 solution for this coding contest problem.
problem
President K decided to make a flag for IOI 2016 in Russia. Chairman K first took out the old flag from the warehouse. This flag is divided into squares of N rows and M columns, and each square is painted in one of white, blue, and red.
Chairman K is trying to repaint some of the squares on this flag to make it the Russian flag. However, the Russian flag in this problem is as follows.
* Several lines (one or more lines) from the top are all painted in white.
* The next few lines (one or more lines) are all painted in blue.
* All the cells in the other lines (one or more lines) are painted in red.
Find the minimum number of squares that President K needs to repaint to turn the old flag into a Russian flag.
input
The input consists of 1 + N lines.
On the first line, two integers N and M (3 ≤ N ≤ 50, 3 ≤ M ≤ 50) are written separated by a blank. This means that the flags are separated by N rows and M columns.
The following N lines each contain a string of M characters, which represents the color information painted in the squares of the old flag. The jth character (1 ≤ i ≤ N, 1 ≤ j ≤ M) on the i-th line of the N-line represents the color of the cell on the i-th line and j-th column of the old flag. It is either B'or'R'. 'W' stands for white,'B' stands for blue, and'R' stands for red.
output
Output in one line the minimum number of squares that President K needs to repaint to turn the old flag into a Russian flag.
Input / output example
Input example 1
4 5
WRWRW
BWRWB
WRWRW
RWBWR
Output example 1
11
Input example 2
6 14
WWWWWWWWWWWWWW
WBBBWWRRWWBBBW
WWBWWRRRRWWBWW
BWBWWRRRRWWBWW
WBBWWWRRWWBBBW
WWWWWWWWWWWWWW
Output example 2
44
In I / O example 1, the old flag is colored as shown in the figure below.
fig01
In the figure below, repaint the 11 squares with an'X'.
fig02
This makes it possible to make the Russian flag as shown in the figure below.
fig03
Since it is not possible to make a Russian flag by repainting less than 11 squares, 11 is output.
In I / O example 2, the old flag is colored as shown in the figure below.
fig04
Creative Commons License
Information Olympics Japan Committee work "15th Japan Information Olympics JOI 2015/2016 Qualifying Competition Tasks"
Example
Input
4 5
WRWRW
BWRWB
WRWRW
RWBWR
Output
11 | instruction | 0 | 67,172 | 7 | 134,344 |
"Correct Solution:
```
n,m = map(int,input().split())
f_lis = []
for i in range(n):
f_lis.append(list(str(input())))
ans_lis = []
W_num = []
W_cou = 0
B_num = []
B_cou = 0
R_num = []
R_cou = 0
for k in range(0,n):
W_cou += f_lis[k].count('B') + f_lis[k].count('R')
W_num.append(W_cou)
for k in range(0,n):
B_cou += f_lis[k].count('W') + f_lis[k].count('R')
B_num.append(B_cou)
for k in range(0,n):
R_cou += f_lis[k].count('B') + f_lis[k].count('W')
R_num.append(R_cou)
for i in range(1,n - 1):
for j in range(i + 1,n):
ans_lis.append(W_num[i - 1] + B_num[j - 1] - B_num[i - 1] + R_num[n - 1] - R_num[j - 1])
print(min(ans_lis))
``` | output | 1 | 67,172 | 7 | 134,345 |
Provide a correct Python 3 solution for this coding contest problem.
problem
President K decided to make a flag for IOI 2016 in Russia. Chairman K first took out the old flag from the warehouse. This flag is divided into squares of N rows and M columns, and each square is painted in one of white, blue, and red.
Chairman K is trying to repaint some of the squares on this flag to make it the Russian flag. However, the Russian flag in this problem is as follows.
* Several lines (one or more lines) from the top are all painted in white.
* The next few lines (one or more lines) are all painted in blue.
* All the cells in the other lines (one or more lines) are painted in red.
Find the minimum number of squares that President K needs to repaint to turn the old flag into a Russian flag.
input
The input consists of 1 + N lines.
On the first line, two integers N and M (3 ≤ N ≤ 50, 3 ≤ M ≤ 50) are written separated by a blank. This means that the flags are separated by N rows and M columns.
The following N lines each contain a string of M characters, which represents the color information painted in the squares of the old flag. The jth character (1 ≤ i ≤ N, 1 ≤ j ≤ M) on the i-th line of the N-line represents the color of the cell on the i-th line and j-th column of the old flag. It is either B'or'R'. 'W' stands for white,'B' stands for blue, and'R' stands for red.
output
Output in one line the minimum number of squares that President K needs to repaint to turn the old flag into a Russian flag.
Input / output example
Input example 1
4 5
WRWRW
BWRWB
WRWRW
RWBWR
Output example 1
11
Input example 2
6 14
WWWWWWWWWWWWWW
WBBBWWRRWWBBBW
WWBWWRRRRWWBWW
BWBWWRRRRWWBWW
WBBWWWRRWWBBBW
WWWWWWWWWWWWWW
Output example 2
44
In I / O example 1, the old flag is colored as shown in the figure below.
fig01
In the figure below, repaint the 11 squares with an'X'.
fig02
This makes it possible to make the Russian flag as shown in the figure below.
fig03
Since it is not possible to make a Russian flag by repainting less than 11 squares, 11 is output.
In I / O example 2, the old flag is colored as shown in the figure below.
fig04
Creative Commons License
Information Olympics Japan Committee work "15th Japan Information Olympics JOI 2015/2016 Qualifying Competition Tasks"
Example
Input
4 5
WRWRW
BWRWB
WRWRW
RWBWR
Output
11 | instruction | 0 | 67,173 | 7 | 134,346 |
"Correct Solution:
```
def getPaintCount(string, color):
return len(string)-string.count(color)
N, M = map(int, input().split())
A = []
cnt = 0
for i in range(N):
s = input().strip()
if i==0: #1行目は白
cnt += getPaintCount(s, 'W')
elif i==N-1: #最終行は赤
cnt += getPaintCount(s, 'R')
else:
A.append(s) #N-2行のリスト
B = [] #白、青、赤の行数の組み合わせリスト
for w in range(0, N-1): #白は0からN-3行の可能性
for b in range(1, N-w): #青は1からN-2行の可能性
r = N-2-w-b
if r>=0: B.append([w, b, N-2-w-b])
#print(B)
minmin = 2500
cnt2 = 0
for b in B:
for i in range(len(A)):
if i<b[0]:
cnt2 += getPaintCount(A[i], 'W')
elif b[0]<=i<b[0]+b[1]:
cnt2 += getPaintCount(A[i], 'B')
elif b[0]+b[1]<=i<b[0]+b[1]+b[2]:
cnt2 += getPaintCount(A[i], 'R')
if cnt2<minmin:
minmin = cnt2
cnt2 = 0
print(cnt+minmin)
``` | output | 1 | 67,173 | 7 | 134,347 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
problem
President K decided to make a flag for IOI 2016 in Russia. Chairman K first took out the old flag from the warehouse. This flag is divided into squares of N rows and M columns, and each square is painted in one of white, blue, and red.
Chairman K is trying to repaint some of the squares on this flag to make it the Russian flag. However, the Russian flag in this problem is as follows.
* Several lines (one or more lines) from the top are all painted in white.
* The next few lines (one or more lines) are all painted in blue.
* All the cells in the other lines (one or more lines) are painted in red.
Find the minimum number of squares that President K needs to repaint to turn the old flag into a Russian flag.
input
The input consists of 1 + N lines.
On the first line, two integers N and M (3 ≤ N ≤ 50, 3 ≤ M ≤ 50) are written separated by a blank. This means that the flags are separated by N rows and M columns.
The following N lines each contain a string of M characters, which represents the color information painted in the squares of the old flag. The jth character (1 ≤ i ≤ N, 1 ≤ j ≤ M) on the i-th line of the N-line represents the color of the cell on the i-th line and j-th column of the old flag. It is either B'or'R'. 'W' stands for white,'B' stands for blue, and'R' stands for red.
output
Output in one line the minimum number of squares that President K needs to repaint to turn the old flag into a Russian flag.
Input / output example
Input example 1
4 5
WRWRW
BWRWB
WRWRW
RWBWR
Output example 1
11
Input example 2
6 14
WWWWWWWWWWWWWW
WBBBWWRRWWBBBW
WWBWWRRRRWWBWW
BWBWWRRRRWWBWW
WBBWWWRRWWBBBW
WWWWWWWWWWWWWW
Output example 2
44
In I / O example 1, the old flag is colored as shown in the figure below.
fig01
In the figure below, repaint the 11 squares with an'X'.
fig02
This makes it possible to make the Russian flag as shown in the figure below.
fig03
Since it is not possible to make a Russian flag by repainting less than 11 squares, 11 is output.
In I / O example 2, the old flag is colored as shown in the figure below.
fig04
Creative Commons License
Information Olympics Japan Committee work "15th Japan Information Olympics JOI 2015/2016 Qualifying Competition Tasks"
Example
Input
4 5
WRWRW
BWRWB
WRWRW
RWBWR
Output
11
Submitted Solution:
```
def differ(i,ss):
tos = ["W","B","R"]
count = 0
for j in ss:
if (j != tos[i]):
count += 1
return count
[n,m] = list(map(int,input().split()))
ls = []
for i in range(n):
ls.append(input())
dp = [[0 for i in range(50)] for i in range(3)]
dp[0][0] = differ(0,ls[0])
for i in range(3):
for j in range(n):
if j == 0:
if i == 0:
dp[i][j] = differ(0,ls[0])
else:
dp[i][j] = 100000
elif i == 0:
dp[i][j] = dp[i][j-1] + differ(i,ls[j])
else:
dp[i][j] = min(dp[i-1][j-1] + differ(i,ls[j]),dp[i][j-1] + differ(i,ls[j]))
print(dp[2][n-1])
``` | instruction | 0 | 67,174 | 7 | 134,348 |
Yes | output | 1 | 67,174 | 7 | 134,349 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
problem
President K decided to make a flag for IOI 2016 in Russia. Chairman K first took out the old flag from the warehouse. This flag is divided into squares of N rows and M columns, and each square is painted in one of white, blue, and red.
Chairman K is trying to repaint some of the squares on this flag to make it the Russian flag. However, the Russian flag in this problem is as follows.
* Several lines (one or more lines) from the top are all painted in white.
* The next few lines (one or more lines) are all painted in blue.
* All the cells in the other lines (one or more lines) are painted in red.
Find the minimum number of squares that President K needs to repaint to turn the old flag into a Russian flag.
input
The input consists of 1 + N lines.
On the first line, two integers N and M (3 ≤ N ≤ 50, 3 ≤ M ≤ 50) are written separated by a blank. This means that the flags are separated by N rows and M columns.
The following N lines each contain a string of M characters, which represents the color information painted in the squares of the old flag. The jth character (1 ≤ i ≤ N, 1 ≤ j ≤ M) on the i-th line of the N-line represents the color of the cell on the i-th line and j-th column of the old flag. It is either B'or'R'. 'W' stands for white,'B' stands for blue, and'R' stands for red.
output
Output in one line the minimum number of squares that President K needs to repaint to turn the old flag into a Russian flag.
Input / output example
Input example 1
4 5
WRWRW
BWRWB
WRWRW
RWBWR
Output example 1
11
Input example 2
6 14
WWWWWWWWWWWWWW
WBBBWWRRWWBBBW
WWBWWRRRRWWBWW
BWBWWRRRRWWBWW
WBBWWWRRWWBBBW
WWWWWWWWWWWWWW
Output example 2
44
In I / O example 1, the old flag is colored as shown in the figure below.
fig01
In the figure below, repaint the 11 squares with an'X'.
fig02
This makes it possible to make the Russian flag as shown in the figure below.
fig03
Since it is not possible to make a Russian flag by repainting less than 11 squares, 11 is output.
In I / O example 2, the old flag is colored as shown in the figure below.
fig04
Creative Commons License
Information Olympics Japan Committee work "15th Japan Information Olympics JOI 2015/2016 Qualifying Competition Tasks"
Example
Input
4 5
WRWRW
BWRWB
WRWRW
RWBWR
Output
11
Submitted Solution:
```
str_N_M = input()
N, M = map(int, str_N_M.split(' '))
old_flag = []
for i in range(1, N + 1):
old_flag.append(input())
X = 2500
for white_row in range(1, N - 1):
for blue_row in range(white_row + 1, N):
paint_square = 0
for row in old_flag[:white_row]:
list_row_w = list(row)
for moji_w in list_row_w:
if moji_w == 'B' or moji_w == 'R':
paint_square += 1
for row in old_flag[white_row : blue_row]:
list_row_b = list(row)
for moji_z in list_row_b:
if moji_z == 'W' or moji_z == 'R':
paint_square += 1
for row in old_flag[blue_row:]:
list_row_r = list(row)
for moji_r in list_row_r:
if moji_r == 'B' or moji_r == 'W':
paint_square += 1
if paint_square < X:
X = paint_square
print(X)
``` | instruction | 0 | 67,175 | 7 | 134,350 |
Yes | output | 1 | 67,175 | 7 | 134,351 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
problem
President K decided to make a flag for IOI 2016 in Russia. Chairman K first took out the old flag from the warehouse. This flag is divided into squares of N rows and M columns, and each square is painted in one of white, blue, and red.
Chairman K is trying to repaint some of the squares on this flag to make it the Russian flag. However, the Russian flag in this problem is as follows.
* Several lines (one or more lines) from the top are all painted in white.
* The next few lines (one or more lines) are all painted in blue.
* All the cells in the other lines (one or more lines) are painted in red.
Find the minimum number of squares that President K needs to repaint to turn the old flag into a Russian flag.
input
The input consists of 1 + N lines.
On the first line, two integers N and M (3 ≤ N ≤ 50, 3 ≤ M ≤ 50) are written separated by a blank. This means that the flags are separated by N rows and M columns.
The following N lines each contain a string of M characters, which represents the color information painted in the squares of the old flag. The jth character (1 ≤ i ≤ N, 1 ≤ j ≤ M) on the i-th line of the N-line represents the color of the cell on the i-th line and j-th column of the old flag. It is either B'or'R'. 'W' stands for white,'B' stands for blue, and'R' stands for red.
output
Output in one line the minimum number of squares that President K needs to repaint to turn the old flag into a Russian flag.
Input / output example
Input example 1
4 5
WRWRW
BWRWB
WRWRW
RWBWR
Output example 1
11
Input example 2
6 14
WWWWWWWWWWWWWW
WBBBWWRRWWBBBW
WWBWWRRRRWWBWW
BWBWWRRRRWWBWW
WBBWWWRRWWBBBW
WWWWWWWWWWWWWW
Output example 2
44
In I / O example 1, the old flag is colored as shown in the figure below.
fig01
In the figure below, repaint the 11 squares with an'X'.
fig02
This makes it possible to make the Russian flag as shown in the figure below.
fig03
Since it is not possible to make a Russian flag by repainting less than 11 squares, 11 is output.
In I / O example 2, the old flag is colored as shown in the figure below.
fig04
Creative Commons License
Information Olympics Japan Committee work "15th Japan Information Olympics JOI 2015/2016 Qualifying Competition Tasks"
Example
Input
4 5
WRWRW
BWRWB
WRWRW
RWBWR
Output
11
Submitted Solution:
```
#C
inf = float("inf")
N,M = map(int,input().split())
flag = [list(str(input())) for i in range(N)]
WBR = []
for i in range(N):
w = flag[i].count("W")
b = flag[i].count("B")
r = flag[i].count("R")
WBR.append([w,b,r])
ans = inf
for w in range(N-2):
for b in range(N-1):
if w >= b:
pass
else:
kari = 0
for i in range(N):
if i <= w:
kari+=(M-WBR[i][0])
elif i <= b:
kari+=(M-WBR[i][1])
else:
kari+=(M-WBR[i][2])
ans = min(ans,kari)
print(ans)
``` | instruction | 0 | 67,176 | 7 | 134,352 |
Yes | output | 1 | 67,176 | 7 | 134,353 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
problem
President K decided to make a flag for IOI 2016 in Russia. Chairman K first took out the old flag from the warehouse. This flag is divided into squares of N rows and M columns, and each square is painted in one of white, blue, and red.
Chairman K is trying to repaint some of the squares on this flag to make it the Russian flag. However, the Russian flag in this problem is as follows.
* Several lines (one or more lines) from the top are all painted in white.
* The next few lines (one or more lines) are all painted in blue.
* All the cells in the other lines (one or more lines) are painted in red.
Find the minimum number of squares that President K needs to repaint to turn the old flag into a Russian flag.
input
The input consists of 1 + N lines.
On the first line, two integers N and M (3 ≤ N ≤ 50, 3 ≤ M ≤ 50) are written separated by a blank. This means that the flags are separated by N rows and M columns.
The following N lines each contain a string of M characters, which represents the color information painted in the squares of the old flag. The jth character (1 ≤ i ≤ N, 1 ≤ j ≤ M) on the i-th line of the N-line represents the color of the cell on the i-th line and j-th column of the old flag. It is either B'or'R'. 'W' stands for white,'B' stands for blue, and'R' stands for red.
output
Output in one line the minimum number of squares that President K needs to repaint to turn the old flag into a Russian flag.
Input / output example
Input example 1
4 5
WRWRW
BWRWB
WRWRW
RWBWR
Output example 1
11
Input example 2
6 14
WWWWWWWWWWWWWW
WBBBWWRRWWBBBW
WWBWWRRRRWWBWW
BWBWWRRRRWWBWW
WBBWWWRRWWBBBW
WWWWWWWWWWWWWW
Output example 2
44
In I / O example 1, the old flag is colored as shown in the figure below.
fig01
In the figure below, repaint the 11 squares with an'X'.
fig02
This makes it possible to make the Russian flag as shown in the figure below.
fig03
Since it is not possible to make a Russian flag by repainting less than 11 squares, 11 is output.
In I / O example 2, the old flag is colored as shown in the figure below.
fig04
Creative Commons License
Information Olympics Japan Committee work "15th Japan Information Olympics JOI 2015/2016 Qualifying Competition Tasks"
Example
Input
4 5
WRWRW
BWRWB
WRWRW
RWBWR
Output
11
Submitted Solution:
```
N,M=[int(i) for i in input().split(" ")]
blue=[0]
white=[0]
red=[0]
for i in range(N):
S=input()
blue.append(M-S.count("B")+blue[-1])
white.append(M-S.count("W")+white[-1])
red.append(M-S.count("R")+red[-1])
def paint(i,j):
retval=0
retval+=white[i]-white[0]
retval+=blue[j]-blue[i]
retval+=red[N]-red[j]
return retval
retval=10**10
for i in range(1,N):
for j in range(i+1,N):
retval=min(paint(i,j),retval)
print(retval)
``` | instruction | 0 | 67,177 | 7 | 134,354 |
Yes | output | 1 | 67,177 | 7 | 134,355 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
problem
President K decided to make a flag for IOI 2016 in Russia. Chairman K first took out the old flag from the warehouse. This flag is divided into squares of N rows and M columns, and each square is painted in one of white, blue, and red.
Chairman K is trying to repaint some of the squares on this flag to make it the Russian flag. However, the Russian flag in this problem is as follows.
* Several lines (one or more lines) from the top are all painted in white.
* The next few lines (one or more lines) are all painted in blue.
* All the cells in the other lines (one or more lines) are painted in red.
Find the minimum number of squares that President K needs to repaint to turn the old flag into a Russian flag.
input
The input consists of 1 + N lines.
On the first line, two integers N and M (3 ≤ N ≤ 50, 3 ≤ M ≤ 50) are written separated by a blank. This means that the flags are separated by N rows and M columns.
The following N lines each contain a string of M characters, which represents the color information painted in the squares of the old flag. The jth character (1 ≤ i ≤ N, 1 ≤ j ≤ M) on the i-th line of the N-line represents the color of the cell on the i-th line and j-th column of the old flag. It is either B'or'R'. 'W' stands for white,'B' stands for blue, and'R' stands for red.
output
Output in one line the minimum number of squares that President K needs to repaint to turn the old flag into a Russian flag.
Input / output example
Input example 1
4 5
WRWRW
BWRWB
WRWRW
RWBWR
Output example 1
11
Input example 2
6 14
WWWWWWWWWWWWWW
WBBBWWRRWWBBBW
WWBWWRRRRWWBWW
BWBWWRRRRWWBWW
WBBWWWRRWWBBBW
WWWWWWWWWWWWWW
Output example 2
44
In I / O example 1, the old flag is colored as shown in the figure below.
fig01
In the figure below, repaint the 11 squares with an'X'.
fig02
This makes it possible to make the Russian flag as shown in the figure below.
fig03
Since it is not possible to make a Russian flag by repainting less than 11 squares, 11 is output.
In I / O example 2, the old flag is colored as shown in the figure below.
fig04
Creative Commons License
Information Olympics Japan Committee work "15th Japan Information Olympics JOI 2015/2016 Qualifying Competition Tasks"
Example
Input
4 5
WRWRW
BWRWB
WRWRW
RWBWR
Output
11
Submitted Solution:
```
def differ(i,ss):
tos = ["W","B","R"]
count = 0
for j in ss:
if (j != tos[i]):
count += 1
return count
[n,m] = list(map(int,input().split()))
ls = []
for i in range(n):
ls.append(input())
dp = [[0 for i in range(50)] for i in range(3)]
dp[0][0] = differ(0,ls[0])
for i in range(3):
for j in range(n):
if j == 0:
if i == 0:
dp[i][j] = differ(0,ls[0])
else:
dp[i][j] = 100
if i == 0:
dp[i][j] = dp[i][j-1] + differ(i,ls[j])
else:
dp[i][j] = min(dp[i-1][j-1] + differ(i,ls[j]),dp[i][j-1] + differ(i,ls[j]))
print(dp[2][n-1])
``` | instruction | 0 | 67,178 | 7 | 134,356 |
No | output | 1 | 67,178 | 7 | 134,357 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You have a garland consisting of n lamps. Each lamp is colored red, green or blue. The color of the i-th lamp is s_i ('R', 'G' and 'B' — colors of lamps in the garland).
You have to recolor some lamps in this garland (recoloring a lamp means changing its initial color to another) in such a way that the obtained garland is diverse.
A garland is called diverse if any two adjacent (consecutive) lamps (i. e. such lamps that the distance between their positions is 1) have distinct colors.
In other words, if the obtained garland is t then for each i from 1 to n-1 the condition t_i ≠ t_{i + 1} should be satisfied.
Among all ways to recolor the initial garland to make it diverse you have to choose one with the minimum number of recolored lamps. If there are multiple optimal solutions, print any of them.
Input
The first line of the input contains one integer n (1 ≤ n ≤ 2 ⋅ 10^5) — the number of lamps.
The second line of the input contains the string s consisting of n characters 'R', 'G' and 'B' — colors of lamps in the garland.
Output
In the first line of the output print one integer r — the minimum number of recolors needed to obtain a diverse garland from the given one.
In the second line of the output print one string t of length n — a diverse garland obtained from the initial one with minimum number of recolors. If there are multiple optimal solutions, print any of them.
Examples
Input
9
RBGRRBRGG
Output
2
RBGRGBRGR
Input
8
BBBGBRRR
Output
2
BRBGBRGR
Input
13
BBRRRRGGGGGRR
Output
6
BGRBRBGBGBGRG | instruction | 0 | 67,291 | 7 | 134,582 |
Tags: constructive algorithms, dp, greedy
Correct Solution:
```
n=int(input())
m=list(input())
i=0
k=0
q=["R","G","B"]
if n==1:
print(0)
print(*m)
exit()
if n==2:
if m[1]==m[0]:
print(1)
if q.index(m[0])==1:
print(m[0]+q[2])
else:
print(m[0]+q[1])
else:
print(0)
print(*m,sep="")
exit()
while i<n-2:
if m[i]==m[i+1] and m[i]==m[i+2]:
if q.index(m[i+2])==1:
m[i+1]=q[0]
else:
m[i+1]=q[1]
k+=1
i+=1
elif m[i]==m[i+1]:
if q.index(m[i-1])+q.index(m[i+1])==2:
m[i]=q[1]
elif q.index(m[i-1])+q.index(m[i+1])==1:
m[i]=q[2]
else:
m[i]=q[0]
k+=1
i+=1
if m[-2]==m[-1]:
if q.index(m[-3])+q.index(m[-1])==2:
if m[-3]==m[-2]:
m[-2]=q[2]
else:
m[-2]=q[1]
elif q.index(m[-3])+q.index(m[-1])==1:
m[-2]=q[2]
elif q.index(m[-3])+q.index(m[-1])==3:
m[-2]=q[0]
else:
m[-2]=q[1]
k+=1
print(k)
print(*m,sep="")
``` | output | 1 | 67,291 | 7 | 134,583 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You have a garland consisting of n lamps. Each lamp is colored red, green or blue. The color of the i-th lamp is s_i ('R', 'G' and 'B' — colors of lamps in the garland).
You have to recolor some lamps in this garland (recoloring a lamp means changing its initial color to another) in such a way that the obtained garland is diverse.
A garland is called diverse if any two adjacent (consecutive) lamps (i. e. such lamps that the distance between their positions is 1) have distinct colors.
In other words, if the obtained garland is t then for each i from 1 to n-1 the condition t_i ≠ t_{i + 1} should be satisfied.
Among all ways to recolor the initial garland to make it diverse you have to choose one with the minimum number of recolored lamps. If there are multiple optimal solutions, print any of them.
Input
The first line of the input contains one integer n (1 ≤ n ≤ 2 ⋅ 10^5) — the number of lamps.
The second line of the input contains the string s consisting of n characters 'R', 'G' and 'B' — colors of lamps in the garland.
Output
In the first line of the output print one integer r — the minimum number of recolors needed to obtain a diverse garland from the given one.
In the second line of the output print one string t of length n — a diverse garland obtained from the initial one with minimum number of recolors. If there are multiple optimal solutions, print any of them.
Examples
Input
9
RBGRRBRGG
Output
2
RBGRGBRGR
Input
8
BBBGBRRR
Output
2
BRBGBRGR
Input
13
BBRRRRGGGGGRR
Output
6
BGRBRBGBGBGRG | instruction | 0 | 67,292 | 7 | 134,584 |
Tags: constructive algorithms, dp, greedy
Correct Solution:
```
def divGar(s, n):
s = list(s)
i = 0
c = 0
while (i < n-1):
g = ['R', 'G', 'B']
if s[i] == s[i+1]:
if i+2 < n:
g.remove(s[i+2])
if s[i] in g:
g.remove(s[i])
s[i+1] = g[0]
c += 1
i += 1
s = ''.join(s)
return c, s
n = int(input())
s = input()
c, s = divGar(s, n)
print(c)
print(s)
``` | output | 1 | 67,292 | 7 | 134,585 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You have a garland consisting of n lamps. Each lamp is colored red, green or blue. The color of the i-th lamp is s_i ('R', 'G' and 'B' — colors of lamps in the garland).
You have to recolor some lamps in this garland (recoloring a lamp means changing its initial color to another) in such a way that the obtained garland is diverse.
A garland is called diverse if any two adjacent (consecutive) lamps (i. e. such lamps that the distance between their positions is 1) have distinct colors.
In other words, if the obtained garland is t then for each i from 1 to n-1 the condition t_i ≠ t_{i + 1} should be satisfied.
Among all ways to recolor the initial garland to make it diverse you have to choose one with the minimum number of recolored lamps. If there are multiple optimal solutions, print any of them.
Input
The first line of the input contains one integer n (1 ≤ n ≤ 2 ⋅ 10^5) — the number of lamps.
The second line of the input contains the string s consisting of n characters 'R', 'G' and 'B' — colors of lamps in the garland.
Output
In the first line of the output print one integer r — the minimum number of recolors needed to obtain a diverse garland from the given one.
In the second line of the output print one string t of length n — a diverse garland obtained from the initial one with minimum number of recolors. If there are multiple optimal solutions, print any of them.
Examples
Input
9
RBGRRBRGG
Output
2
RBGRGBRGR
Input
8
BBBGBRRR
Output
2
BRBGBRGR
Input
13
BBRRRRGGGGGRR
Output
6
BGRBRBGBGBGRG | instruction | 0 | 67,293 | 7 | 134,586 |
Tags: constructive algorithms, dp, greedy
Correct Solution:
```
# -*- coding: utf-8 -*-
"""
Created on Wed Jan 23 20:08:55 2019
@author: Himanshu Gwalani
"""
n=int(input())
ss=input()
l=ss
s=[]
s.append('&')
for i in l:
s.append(i)
s.append('&')
count=0
for i in range(n):
if s[i]==s[i+1]:
if 'B'!=s[i] and 'B'!=s[i+2]:
s[i+1]='B'
elif 'G'!=s[i+2] and 'G'!=s[i]:
s[i+1]='G'
elif 'R'!=s[i+2] and 'R'!=s[i]:
s[i+1]='R'
count+=1
print(count)
for i in range(1,n+1):
print(s[i],end='')
``` | output | 1 | 67,293 | 7 | 134,587 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You have a garland consisting of n lamps. Each lamp is colored red, green or blue. The color of the i-th lamp is s_i ('R', 'G' and 'B' — colors of lamps in the garland).
You have to recolor some lamps in this garland (recoloring a lamp means changing its initial color to another) in such a way that the obtained garland is diverse.
A garland is called diverse if any two adjacent (consecutive) lamps (i. e. such lamps that the distance between their positions is 1) have distinct colors.
In other words, if the obtained garland is t then for each i from 1 to n-1 the condition t_i ≠ t_{i + 1} should be satisfied.
Among all ways to recolor the initial garland to make it diverse you have to choose one with the minimum number of recolored lamps. If there are multiple optimal solutions, print any of them.
Input
The first line of the input contains one integer n (1 ≤ n ≤ 2 ⋅ 10^5) — the number of lamps.
The second line of the input contains the string s consisting of n characters 'R', 'G' and 'B' — colors of lamps in the garland.
Output
In the first line of the output print one integer r — the minimum number of recolors needed to obtain a diverse garland from the given one.
In the second line of the output print one string t of length n — a diverse garland obtained from the initial one with minimum number of recolors. If there are multiple optimal solutions, print any of them.
Examples
Input
9
RBGRRBRGG
Output
2
RBGRGBRGR
Input
8
BBBGBRRR
Output
2
BRBGBRGR
Input
13
BBRRRRGGGGGRR
Output
6
BGRBRBGBGBGRG | instruction | 0 | 67,294 | 7 | 134,588 |
Tags: constructive algorithms, dp, greedy
Correct Solution:
```
n= int(input())
s = input()
l = len(s)
color = ['R','B','G']
count = 0
col = list(s)
# handle case for length less than 3
if l == 1:
print(0)
print(s)
exit(0)
if l == 2:
if col[0] != col[1]:
print(1)
color.remove(col[1])
count += 1
col[0] = color[0]
print("".join(col))
exit(0)
for i in reversed(range(1,l-1)):
if col[i] == col[i+1]:
for j in color:
if j != col[i-1] and j!= col[i+1]:
count+=1
col[i] = j
break
if col[1] == col[0]:
color.remove(col[1])
count+=1
col[0] = color[0]
print(count)
print("".join(col))
``` | output | 1 | 67,294 | 7 | 134,589 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You have a garland consisting of n lamps. Each lamp is colored red, green or blue. The color of the i-th lamp is s_i ('R', 'G' and 'B' — colors of lamps in the garland).
You have to recolor some lamps in this garland (recoloring a lamp means changing its initial color to another) in such a way that the obtained garland is diverse.
A garland is called diverse if any two adjacent (consecutive) lamps (i. e. such lamps that the distance between their positions is 1) have distinct colors.
In other words, if the obtained garland is t then for each i from 1 to n-1 the condition t_i ≠ t_{i + 1} should be satisfied.
Among all ways to recolor the initial garland to make it diverse you have to choose one with the minimum number of recolored lamps. If there are multiple optimal solutions, print any of them.
Input
The first line of the input contains one integer n (1 ≤ n ≤ 2 ⋅ 10^5) — the number of lamps.
The second line of the input contains the string s consisting of n characters 'R', 'G' and 'B' — colors of lamps in the garland.
Output
In the first line of the output print one integer r — the minimum number of recolors needed to obtain a diverse garland from the given one.
In the second line of the output print one string t of length n — a diverse garland obtained from the initial one with minimum number of recolors. If there are multiple optimal solutions, print any of them.
Examples
Input
9
RBGRRBRGG
Output
2
RBGRGBRGR
Input
8
BBBGBRRR
Output
2
BRBGBRGR
Input
13
BBRRRRGGGGGRR
Output
6
BGRBRBGBGBGRG | instruction | 0 | 67,295 | 7 | 134,590 |
Tags: constructive algorithms, dp, greedy
Correct Solution:
```
input()
lamps = list(input())
res = 0
for i in range(len(lamps)-1):
if lamps[i] == lamps[i+1]:
if i == len(lamps)-2:
if lamps[i] != "B":
lamps[i+1] = "B"
else:
lamps[i+1] = "R"
else:
if lamps[i] == "B":
if lamps[i+2] != "R":
lamps[i+1] = "R"
else:
lamps[i+1] = "G"
elif lamps[i] =="G":
if lamps[i+2] != "R":
lamps[i+1] = "R"
else:
lamps[i+1] = "B"
else:
if lamps[i+2] != "B":
lamps[i+1] = "B"
else:
lamps[i+1] = "G"
res+=1
print(res)
res = ""
for i in lamps:
res+= str(i)
print(res)
``` | output | 1 | 67,295 | 7 | 134,591 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You have a garland consisting of n lamps. Each lamp is colored red, green or blue. The color of the i-th lamp is s_i ('R', 'G' and 'B' — colors of lamps in the garland).
You have to recolor some lamps in this garland (recoloring a lamp means changing its initial color to another) in such a way that the obtained garland is diverse.
A garland is called diverse if any two adjacent (consecutive) lamps (i. e. such lamps that the distance between their positions is 1) have distinct colors.
In other words, if the obtained garland is t then for each i from 1 to n-1 the condition t_i ≠ t_{i + 1} should be satisfied.
Among all ways to recolor the initial garland to make it diverse you have to choose one with the minimum number of recolored lamps. If there are multiple optimal solutions, print any of them.
Input
The first line of the input contains one integer n (1 ≤ n ≤ 2 ⋅ 10^5) — the number of lamps.
The second line of the input contains the string s consisting of n characters 'R', 'G' and 'B' — colors of lamps in the garland.
Output
In the first line of the output print one integer r — the minimum number of recolors needed to obtain a diverse garland from the given one.
In the second line of the output print one string t of length n — a diverse garland obtained from the initial one with minimum number of recolors. If there are multiple optimal solutions, print any of them.
Examples
Input
9
RBGRRBRGG
Output
2
RBGRGBRGR
Input
8
BBBGBRRR
Output
2
BRBGBRGR
Input
13
BBRRRRGGGGGRR
Output
6
BGRBRBGBGBGRG | instruction | 0 | 67,296 | 7 | 134,592 |
Tags: constructive algorithms, dp, greedy
Correct Solution:
```
c=0
n=int(input())
s=list(input())
posible=['B','G','R']
if n!=1:
for i in range(1,n-1):
if s[i]==s[i-1]:
if s[i]=='R' and s[i+1]!='B':
s[i]='B'
elif s[i]=='R' and s[i+1]!='G':
s[i]='G'
elif s[i]=='G' and s[i+1]!='B':
s[i]='B'
elif s[i]=='G' and s[i+1]!='R':
s[i]='R'
elif s[i]=='B' and s[i+1]!='R':
s[i]='R'
elif s[i]=='B' and s[i+1]!='G':
s[i]='G'
c+=1
if s[-1]==s[-2]:
c+=1
for i in posible:
if i!=s[-1]:
s[-1]=i
break
else:
c=0
print(c)
print(''.join(s))
``` | output | 1 | 67,296 | 7 | 134,593 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You have a garland consisting of n lamps. Each lamp is colored red, green or blue. The color of the i-th lamp is s_i ('R', 'G' and 'B' — colors of lamps in the garland).
You have to recolor some lamps in this garland (recoloring a lamp means changing its initial color to another) in such a way that the obtained garland is diverse.
A garland is called diverse if any two adjacent (consecutive) lamps (i. e. such lamps that the distance between their positions is 1) have distinct colors.
In other words, if the obtained garland is t then for each i from 1 to n-1 the condition t_i ≠ t_{i + 1} should be satisfied.
Among all ways to recolor the initial garland to make it diverse you have to choose one with the minimum number of recolored lamps. If there are multiple optimal solutions, print any of them.
Input
The first line of the input contains one integer n (1 ≤ n ≤ 2 ⋅ 10^5) — the number of lamps.
The second line of the input contains the string s consisting of n characters 'R', 'G' and 'B' — colors of lamps in the garland.
Output
In the first line of the output print one integer r — the minimum number of recolors needed to obtain a diverse garland from the given one.
In the second line of the output print one string t of length n — a diverse garland obtained from the initial one with minimum number of recolors. If there are multiple optimal solutions, print any of them.
Examples
Input
9
RBGRRBRGG
Output
2
RBGRGBRGR
Input
8
BBBGBRRR
Output
2
BRBGBRGR
Input
13
BBRRRRGGGGGRR
Output
6
BGRBRBGBGBGRG | instruction | 0 | 67,297 | 7 | 134,594 |
Tags: constructive algorithms, dp, greedy
Correct Solution:
```
n = int(input())
s = input()
t = 0
li = ["G", "R", "B"]
ans = s[0]
for i in range(1, n):
x = s[i]
if x == ans[i - 1]:
t += 1
if i < n - 1:
z = s[i + 1]
for y in li:
if y != x and y != z:
ans += y
break
else:
for y in li:
if y != x:
ans += y
break
else:
ans += x
print(t)
print(ans)
``` | output | 1 | 67,297 | 7 | 134,595 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You have a garland consisting of n lamps. Each lamp is colored red, green or blue. The color of the i-th lamp is s_i ('R', 'G' and 'B' — colors of lamps in the garland).
You have to recolor some lamps in this garland (recoloring a lamp means changing its initial color to another) in such a way that the obtained garland is diverse.
A garland is called diverse if any two adjacent (consecutive) lamps (i. e. such lamps that the distance between their positions is 1) have distinct colors.
In other words, if the obtained garland is t then for each i from 1 to n-1 the condition t_i ≠ t_{i + 1} should be satisfied.
Among all ways to recolor the initial garland to make it diverse you have to choose one with the minimum number of recolored lamps. If there are multiple optimal solutions, print any of them.
Input
The first line of the input contains one integer n (1 ≤ n ≤ 2 ⋅ 10^5) — the number of lamps.
The second line of the input contains the string s consisting of n characters 'R', 'G' and 'B' — colors of lamps in the garland.
Output
In the first line of the output print one integer r — the minimum number of recolors needed to obtain a diverse garland from the given one.
In the second line of the output print one string t of length n — a diverse garland obtained from the initial one with minimum number of recolors. If there are multiple optimal solutions, print any of them.
Examples
Input
9
RBGRRBRGG
Output
2
RBGRGBRGR
Input
8
BBBGBRRR
Output
2
BRBGBRGR
Input
13
BBRRRRGGGGGRR
Output
6
BGRBRBGBGBGRG | instruction | 0 | 67,298 | 7 | 134,596 |
Tags: constructive algorithms, dp, greedy
Correct Solution:
```
n=int(input())
s=input()
ss=s[0]
def ans(a,b):
if a=='R':
if b=='G':
return 'B'
else:
return 'G'
elif a=='G':
if b=='R':
return 'B'
else:
return 'R'
else:
if b=='R':
return 'G'
else:
return 'R'
m=0
for i in range(1,n-1):
if s[i]==ss[i-1]:
ss=ss+ans(s[i],s[i+1])
m+=1
else:
ss=ss+s[i]
if s[n-1]==ss[len(ss)-1]:
m+=1
ss=ss+ans(s[n-1],s[n-1])
else:
ss=ss+s[n-1]
if n==1: print('0\n'+s)
else:
print(m)
print(ss)
``` | output | 1 | 67,298 | 7 | 134,597 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.