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.
Illumination
Illuminations are displayed in the corridors every year at the JOI High School Cultural Festival. The illuminations consist of N light bulbs, which are lined up in a row from the west side to the east side of the corridor. Each light bulb is either on or off.
A machine that operates a light bulb is sleeping in the warehouse of JOI High School. When a continuous light bulb is specified in the illumination, this machine turns all the specified light bulbs with the light on and all the light bulbs without the light on. However, the machine is aging and can only be used once.
JOI high school students like alternating rows of light bulbs with and without lights (such rows of light bulbs are called alternating rows). Therefore, I decided to use this machine only once if necessary to make illuminations containing alternating rows as long as possible.
Example
For example, the arrangement of illuminations is from west to east
<image>
(β indicates a light bulb with a light, β indicates a light bulb without a light). At this time, if you operate the machine for the four light bulbs from the 4th to the 7th,
<image>
The second to eighth bulbs form an alternating row of length 7.
<image>
Also, if you operate the machine only for the 8th light bulb,
<image>
The 4th to 10th light bulbs form an alternating row of length 7.
<image>
It is not possible to create alternating rows longer than 8 by using the machine up to once.
Task
Given the illumination information, write a program to find the maximum possible length of the alternating rows in the array of light bulbs that can be obtained by using the machine up to once.
Limits
* 2 β€ N β€ 100 000 Number of light bulbs that make up the illumination
input
Read the following data from standard input.
* The integer N is written on the first line.
* On the second line, N 0s or 1s are written with a space as a delimiter. Each integer represents the information of the light bulb before operating the machine. The i (1 β€ i β€ N) th integer from the left represents the information of the i-th light bulb from the west, and if the integer is 1, the light bulb is on, and if it is 0, the light bulb is off.
output
Output an integer representing the maximum length of the alternating columns contained in the columns of light bulbs that can be created to the standard output on one line.
Input / output example
Input example 1
Ten
1 1 0 0 1 0 1 1 1 0
Output example 1
7
This is an example explained in the problem statement.
Input example 2
Ten
1 0 0 0 0 1 0 1 0 1
Output example 2
8
Manipulating only the fourth bulb from the west yields an alternating sequence that satisfies the maximum value of 8.
Input example 3
Five
1 1 0 1 1
Output example 3
Five
By manipulating the second to fourth light bulbs counting from the west, you can create an alternating row of all light bulbs.
Input example 4
3
0 1 0
Output example 4
3
Note that you may not need to use a machine.
The question text and the data used for the automatic referee are the question text and the test data for scoring, which are created and published by the Japan Committee for Information Olympics.
Example
Input
10
1 1 0 0 1 0 1 1 1 0
Output
7 | instruction | 0 | 47,873 | 7 | 95,746 |
"Correct Solution:
```
# AOJ 0603 Illumination
# Python3 2018.7.2 bal4u
import sys
from sys import stdin
input = stdin.readline
n = int(input())
a = list(map(int, input().split()))
t, k = [], 0
for i in range(n):
if k > 0:
if a[i] == a[i-1]:
t.append(k)
k = 0
k += 1
if k > 0: t.append(k)
ans = k = 0
for i in range(len(t)):
k += t[i]
if i > 2: k -= t[i-3]
ans = max(ans, k)
print(ans)
``` | output | 1 | 47,873 | 7 | 95,747 |
Provide a correct Python 3 solution for this coding contest problem.
Illumination
Illuminations are displayed in the corridors every year at the JOI High School Cultural Festival. The illuminations consist of N light bulbs, which are lined up in a row from the west side to the east side of the corridor. Each light bulb is either on or off.
A machine that operates a light bulb is sleeping in the warehouse of JOI High School. When a continuous light bulb is specified in the illumination, this machine turns all the specified light bulbs with the light on and all the light bulbs without the light on. However, the machine is aging and can only be used once.
JOI high school students like alternating rows of light bulbs with and without lights (such rows of light bulbs are called alternating rows). Therefore, I decided to use this machine only once if necessary to make illuminations containing alternating rows as long as possible.
Example
For example, the arrangement of illuminations is from west to east
<image>
(β indicates a light bulb with a light, β indicates a light bulb without a light). At this time, if you operate the machine for the four light bulbs from the 4th to the 7th,
<image>
The second to eighth bulbs form an alternating row of length 7.
<image>
Also, if you operate the machine only for the 8th light bulb,
<image>
The 4th to 10th light bulbs form an alternating row of length 7.
<image>
It is not possible to create alternating rows longer than 8 by using the machine up to once.
Task
Given the illumination information, write a program to find the maximum possible length of the alternating rows in the array of light bulbs that can be obtained by using the machine up to once.
Limits
* 2 β€ N β€ 100 000 Number of light bulbs that make up the illumination
input
Read the following data from standard input.
* The integer N is written on the first line.
* On the second line, N 0s or 1s are written with a space as a delimiter. Each integer represents the information of the light bulb before operating the machine. The i (1 β€ i β€ N) th integer from the left represents the information of the i-th light bulb from the west, and if the integer is 1, the light bulb is on, and if it is 0, the light bulb is off.
output
Output an integer representing the maximum length of the alternating columns contained in the columns of light bulbs that can be created to the standard output on one line.
Input / output example
Input example 1
Ten
1 1 0 0 1 0 1 1 1 0
Output example 1
7
This is an example explained in the problem statement.
Input example 2
Ten
1 0 0 0 0 1 0 1 0 1
Output example 2
8
Manipulating only the fourth bulb from the west yields an alternating sequence that satisfies the maximum value of 8.
Input example 3
Five
1 1 0 1 1
Output example 3
Five
By manipulating the second to fourth light bulbs counting from the west, you can create an alternating row of all light bulbs.
Input example 4
3
0 1 0
Output example 4
3
Note that you may not need to use a machine.
The question text and the data used for the automatic referee are the question text and the test data for scoring, which are created and published by the Japan Committee for Information Olympics.
Example
Input
10
1 1 0 0 1 0 1 1 1 0
Output
7 | instruction | 0 | 47,874 | 7 | 95,748 |
"Correct Solution:
```
#A
N = int(input())
S = list(map(int,input().split()))
R = []
now = 1
for i in range(N-1):
if S[i] != S[i+1]:
now+=1
else:
R.append(now)
now = 1
R.append(now)
#print(R)
RL = len(R)
ans = 0
for i in range(RL):
if i == 0:
if RL == 1:
ans = R[0]
else:
ans = R[i]+R[i+1]
elif i == RL-1:
ans = max(ans,R[i]+R[i-1])
else:
ans = max(ans,R[i-1]+R[i]+R[i+1])
print(ans)
``` | output | 1 | 47,874 | 7 | 95,749 |
Provide a correct Python 3 solution for this coding contest problem.
Illumination
Illuminations are displayed in the corridors every year at the JOI High School Cultural Festival. The illuminations consist of N light bulbs, which are lined up in a row from the west side to the east side of the corridor. Each light bulb is either on or off.
A machine that operates a light bulb is sleeping in the warehouse of JOI High School. When a continuous light bulb is specified in the illumination, this machine turns all the specified light bulbs with the light on and all the light bulbs without the light on. However, the machine is aging and can only be used once.
JOI high school students like alternating rows of light bulbs with and without lights (such rows of light bulbs are called alternating rows). Therefore, I decided to use this machine only once if necessary to make illuminations containing alternating rows as long as possible.
Example
For example, the arrangement of illuminations is from west to east
<image>
(β indicates a light bulb with a light, β indicates a light bulb without a light). At this time, if you operate the machine for the four light bulbs from the 4th to the 7th,
<image>
The second to eighth bulbs form an alternating row of length 7.
<image>
Also, if you operate the machine only for the 8th light bulb,
<image>
The 4th to 10th light bulbs form an alternating row of length 7.
<image>
It is not possible to create alternating rows longer than 8 by using the machine up to once.
Task
Given the illumination information, write a program to find the maximum possible length of the alternating rows in the array of light bulbs that can be obtained by using the machine up to once.
Limits
* 2 β€ N β€ 100 000 Number of light bulbs that make up the illumination
input
Read the following data from standard input.
* The integer N is written on the first line.
* On the second line, N 0s or 1s are written with a space as a delimiter. Each integer represents the information of the light bulb before operating the machine. The i (1 β€ i β€ N) th integer from the left represents the information of the i-th light bulb from the west, and if the integer is 1, the light bulb is on, and if it is 0, the light bulb is off.
output
Output an integer representing the maximum length of the alternating columns contained in the columns of light bulbs that can be created to the standard output on one line.
Input / output example
Input example 1
Ten
1 1 0 0 1 0 1 1 1 0
Output example 1
7
This is an example explained in the problem statement.
Input example 2
Ten
1 0 0 0 0 1 0 1 0 1
Output example 2
8
Manipulating only the fourth bulb from the west yields an alternating sequence that satisfies the maximum value of 8.
Input example 3
Five
1 1 0 1 1
Output example 3
Five
By manipulating the second to fourth light bulbs counting from the west, you can create an alternating row of all light bulbs.
Input example 4
3
0 1 0
Output example 4
3
Note that you may not need to use a machine.
The question text and the data used for the automatic referee are the question text and the test data for scoring, which are created and published by the Japan Committee for Information Olympics.
Example
Input
10
1 1 0 0 1 0 1 1 1 0
Output
7 | instruction | 0 | 47,875 | 7 | 95,750 |
"Correct Solution:
```
n=int(input())
l=list(map(int,input().split()))
l_c=[0]
c=1
for i in range(1,n):
if l[i]==l[i-1]:
l_c.append(c)
c+=1
l_c.append(c)
if len(l_c)<5:
print(n)
else:
ans=-1
for i in range(len(l_c)-3):
ans=max(ans,l_c[i+3]-l_c[i])
print(ans)
``` | output | 1 | 47,875 | 7 | 95,751 |
Provide a correct Python 3 solution for this coding contest problem.
Illumination
Illuminations are displayed in the corridors every year at the JOI High School Cultural Festival. The illuminations consist of N light bulbs, which are lined up in a row from the west side to the east side of the corridor. Each light bulb is either on or off.
A machine that operates a light bulb is sleeping in the warehouse of JOI High School. When a continuous light bulb is specified in the illumination, this machine turns all the specified light bulbs with the light on and all the light bulbs without the light on. However, the machine is aging and can only be used once.
JOI high school students like alternating rows of light bulbs with and without lights (such rows of light bulbs are called alternating rows). Therefore, I decided to use this machine only once if necessary to make illuminations containing alternating rows as long as possible.
Example
For example, the arrangement of illuminations is from west to east
<image>
(β indicates a light bulb with a light, β indicates a light bulb without a light). At this time, if you operate the machine for the four light bulbs from the 4th to the 7th,
<image>
The second to eighth bulbs form an alternating row of length 7.
<image>
Also, if you operate the machine only for the 8th light bulb,
<image>
The 4th to 10th light bulbs form an alternating row of length 7.
<image>
It is not possible to create alternating rows longer than 8 by using the machine up to once.
Task
Given the illumination information, write a program to find the maximum possible length of the alternating rows in the array of light bulbs that can be obtained by using the machine up to once.
Limits
* 2 β€ N β€ 100 000 Number of light bulbs that make up the illumination
input
Read the following data from standard input.
* The integer N is written on the first line.
* On the second line, N 0s or 1s are written with a space as a delimiter. Each integer represents the information of the light bulb before operating the machine. The i (1 β€ i β€ N) th integer from the left represents the information of the i-th light bulb from the west, and if the integer is 1, the light bulb is on, and if it is 0, the light bulb is off.
output
Output an integer representing the maximum length of the alternating columns contained in the columns of light bulbs that can be created to the standard output on one line.
Input / output example
Input example 1
Ten
1 1 0 0 1 0 1 1 1 0
Output example 1
7
This is an example explained in the problem statement.
Input example 2
Ten
1 0 0 0 0 1 0 1 0 1
Output example 2
8
Manipulating only the fourth bulb from the west yields an alternating sequence that satisfies the maximum value of 8.
Input example 3
Five
1 1 0 1 1
Output example 3
Five
By manipulating the second to fourth light bulbs counting from the west, you can create an alternating row of all light bulbs.
Input example 4
3
0 1 0
Output example 4
3
Note that you may not need to use a machine.
The question text and the data used for the automatic referee are the question text and the test data for scoring, which are created and published by the Japan Committee for Information Olympics.
Example
Input
10
1 1 0 0 1 0 1 1 1 0
Output
7 | instruction | 0 | 47,876 | 7 | 95,752 |
"Correct Solution:
```
n=int(input())
a=input().split()
p=a.pop();c=1;d=[]
while a:
if a[-1]==p:d+=[c];c=1
else:c+=1
p=a.pop()
d+=[c]
if len(d)<=3:print(sum(d))
else:
print(max(sum(d[i:i+3]) for i in range(len(d)-2)))
``` | output | 1 | 47,876 | 7 | 95,753 |
Provide a correct Python 3 solution for this coding contest problem.
Illumination
Illuminations are displayed in the corridors every year at the JOI High School Cultural Festival. The illuminations consist of N light bulbs, which are lined up in a row from the west side to the east side of the corridor. Each light bulb is either on or off.
A machine that operates a light bulb is sleeping in the warehouse of JOI High School. When a continuous light bulb is specified in the illumination, this machine turns all the specified light bulbs with the light on and all the light bulbs without the light on. However, the machine is aging and can only be used once.
JOI high school students like alternating rows of light bulbs with and without lights (such rows of light bulbs are called alternating rows). Therefore, I decided to use this machine only once if necessary to make illuminations containing alternating rows as long as possible.
Example
For example, the arrangement of illuminations is from west to east
<image>
(β indicates a light bulb with a light, β indicates a light bulb without a light). At this time, if you operate the machine for the four light bulbs from the 4th to the 7th,
<image>
The second to eighth bulbs form an alternating row of length 7.
<image>
Also, if you operate the machine only for the 8th light bulb,
<image>
The 4th to 10th light bulbs form an alternating row of length 7.
<image>
It is not possible to create alternating rows longer than 8 by using the machine up to once.
Task
Given the illumination information, write a program to find the maximum possible length of the alternating rows in the array of light bulbs that can be obtained by using the machine up to once.
Limits
* 2 β€ N β€ 100 000 Number of light bulbs that make up the illumination
input
Read the following data from standard input.
* The integer N is written on the first line.
* On the second line, N 0s or 1s are written with a space as a delimiter. Each integer represents the information of the light bulb before operating the machine. The i (1 β€ i β€ N) th integer from the left represents the information of the i-th light bulb from the west, and if the integer is 1, the light bulb is on, and if it is 0, the light bulb is off.
output
Output an integer representing the maximum length of the alternating columns contained in the columns of light bulbs that can be created to the standard output on one line.
Input / output example
Input example 1
Ten
1 1 0 0 1 0 1 1 1 0
Output example 1
7
This is an example explained in the problem statement.
Input example 2
Ten
1 0 0 0 0 1 0 1 0 1
Output example 2
8
Manipulating only the fourth bulb from the west yields an alternating sequence that satisfies the maximum value of 8.
Input example 3
Five
1 1 0 1 1
Output example 3
Five
By manipulating the second to fourth light bulbs counting from the west, you can create an alternating row of all light bulbs.
Input example 4
3
0 1 0
Output example 4
3
Note that you may not need to use a machine.
The question text and the data used for the automatic referee are the question text and the test data for scoring, which are created and published by the Japan Committee for Information Olympics.
Example
Input
10
1 1 0 0 1 0 1 1 1 0
Output
7 | instruction | 0 | 47,877 | 7 | 95,754 |
"Correct Solution:
```
_ = input()
A = [0]
b = ''
for a in input().split():
if b == '' or b == a:
A.append(1)
else:
A[-1] += 1
b = a
ans = 0
if len(A) < 5:
ans = sum(A)
else:
for i in range(1, len(A)-2):
ans = max(ans, sum(A[i:i+3]))
print(ans)
``` | output | 1 | 47,877 | 7 | 95,755 |
Provide a correct Python 3 solution for this coding contest problem.
Illumination
Illuminations are displayed in the corridors every year at the JOI High School Cultural Festival. The illuminations consist of N light bulbs, which are lined up in a row from the west side to the east side of the corridor. Each light bulb is either on or off.
A machine that operates a light bulb is sleeping in the warehouse of JOI High School. When a continuous light bulb is specified in the illumination, this machine turns all the specified light bulbs with the light on and all the light bulbs without the light on. However, the machine is aging and can only be used once.
JOI high school students like alternating rows of light bulbs with and without lights (such rows of light bulbs are called alternating rows). Therefore, I decided to use this machine only once if necessary to make illuminations containing alternating rows as long as possible.
Example
For example, the arrangement of illuminations is from west to east
<image>
(β indicates a light bulb with a light, β indicates a light bulb without a light). At this time, if you operate the machine for the four light bulbs from the 4th to the 7th,
<image>
The second to eighth bulbs form an alternating row of length 7.
<image>
Also, if you operate the machine only for the 8th light bulb,
<image>
The 4th to 10th light bulbs form an alternating row of length 7.
<image>
It is not possible to create alternating rows longer than 8 by using the machine up to once.
Task
Given the illumination information, write a program to find the maximum possible length of the alternating rows in the array of light bulbs that can be obtained by using the machine up to once.
Limits
* 2 β€ N β€ 100 000 Number of light bulbs that make up the illumination
input
Read the following data from standard input.
* The integer N is written on the first line.
* On the second line, N 0s or 1s are written with a space as a delimiter. Each integer represents the information of the light bulb before operating the machine. The i (1 β€ i β€ N) th integer from the left represents the information of the i-th light bulb from the west, and if the integer is 1, the light bulb is on, and if it is 0, the light bulb is off.
output
Output an integer representing the maximum length of the alternating columns contained in the columns of light bulbs that can be created to the standard output on one line.
Input / output example
Input example 1
Ten
1 1 0 0 1 0 1 1 1 0
Output example 1
7
This is an example explained in the problem statement.
Input example 2
Ten
1 0 0 0 0 1 0 1 0 1
Output example 2
8
Manipulating only the fourth bulb from the west yields an alternating sequence that satisfies the maximum value of 8.
Input example 3
Five
1 1 0 1 1
Output example 3
Five
By manipulating the second to fourth light bulbs counting from the west, you can create an alternating row of all light bulbs.
Input example 4
3
0 1 0
Output example 4
3
Note that you may not need to use a machine.
The question text and the data used for the automatic referee are the question text and the test data for scoring, which are created and published by the Japan Committee for Information Olympics.
Example
Input
10
1 1 0 0 1 0 1 1 1 0
Output
7 | instruction | 0 | 47,878 | 7 | 95,756 |
"Correct Solution:
```
n = int(input())
a = list(map(int,input().split()))
d = []
l = 0
for i in range(n-1):
if a[i+1] == a[i]:
r = i+1
d.append(r-l)
l = r
d.append(n-l)
ans = 0
for i in range(len(d)-2):
ans = max(ans,d[i]+d[i+1]+d[i+2])
if len(d) == 2:
ans = max(d[0]+d[1],ans)
ans = max(d[-1]+d[-2],ans)
if len(d) == 1:
ans = d[0]
print(ans)
``` | output | 1 | 47,878 | 7 | 95,757 |
Provide a correct Python 3 solution for this coding contest problem.
Illumination
Illuminations are displayed in the corridors every year at the JOI High School Cultural Festival. The illuminations consist of N light bulbs, which are lined up in a row from the west side to the east side of the corridor. Each light bulb is either on or off.
A machine that operates a light bulb is sleeping in the warehouse of JOI High School. When a continuous light bulb is specified in the illumination, this machine turns all the specified light bulbs with the light on and all the light bulbs without the light on. However, the machine is aging and can only be used once.
JOI high school students like alternating rows of light bulbs with and without lights (such rows of light bulbs are called alternating rows). Therefore, I decided to use this machine only once if necessary to make illuminations containing alternating rows as long as possible.
Example
For example, the arrangement of illuminations is from west to east
<image>
(β indicates a light bulb with a light, β indicates a light bulb without a light). At this time, if you operate the machine for the four light bulbs from the 4th to the 7th,
<image>
The second to eighth bulbs form an alternating row of length 7.
<image>
Also, if you operate the machine only for the 8th light bulb,
<image>
The 4th to 10th light bulbs form an alternating row of length 7.
<image>
It is not possible to create alternating rows longer than 8 by using the machine up to once.
Task
Given the illumination information, write a program to find the maximum possible length of the alternating rows in the array of light bulbs that can be obtained by using the machine up to once.
Limits
* 2 β€ N β€ 100 000 Number of light bulbs that make up the illumination
input
Read the following data from standard input.
* The integer N is written on the first line.
* On the second line, N 0s or 1s are written with a space as a delimiter. Each integer represents the information of the light bulb before operating the machine. The i (1 β€ i β€ N) th integer from the left represents the information of the i-th light bulb from the west, and if the integer is 1, the light bulb is on, and if it is 0, the light bulb is off.
output
Output an integer representing the maximum length of the alternating columns contained in the columns of light bulbs that can be created to the standard output on one line.
Input / output example
Input example 1
Ten
1 1 0 0 1 0 1 1 1 0
Output example 1
7
This is an example explained in the problem statement.
Input example 2
Ten
1 0 0 0 0 1 0 1 0 1
Output example 2
8
Manipulating only the fourth bulb from the west yields an alternating sequence that satisfies the maximum value of 8.
Input example 3
Five
1 1 0 1 1
Output example 3
Five
By manipulating the second to fourth light bulbs counting from the west, you can create an alternating row of all light bulbs.
Input example 4
3
0 1 0
Output example 4
3
Note that you may not need to use a machine.
The question text and the data used for the automatic referee are the question text and the test data for scoring, which are created and published by the Japan Committee for Information Olympics.
Example
Input
10
1 1 0 0 1 0 1 1 1 0
Output
7 | instruction | 0 | 47,879 | 7 | 95,758 |
"Correct Solution:
```
N = int(input())
a = list(map(int, input().split()))
dp = [[0]*3 for _ in [0]*N]
dp[0] = [1, 1, 1]
ans = 0
for i, (n1, n2) in enumerate(zip(a, a[1:]), start=1):
if n1 != n2:
for j in range(3):
dp[i][j] = dp[i-1][j]+1
else:
dp[i][0] = 1
if dp[i-1][2] > ans:
ans = dp[i-1][2]
for j in range(2, 0, -1):
dp[i][j] = dp[i-1][j-1]+1
print(max(max(dp[-1]), ans))
``` | output | 1 | 47,879 | 7 | 95,759 |
Provide a correct Python 3 solution for this coding contest problem.
Illumination
Illuminations are displayed in the corridors every year at the JOI High School Cultural Festival. The illuminations consist of N light bulbs, which are lined up in a row from the west side to the east side of the corridor. Each light bulb is either on or off.
A machine that operates a light bulb is sleeping in the warehouse of JOI High School. When a continuous light bulb is specified in the illumination, this machine turns all the specified light bulbs with the light on and all the light bulbs without the light on. However, the machine is aging and can only be used once.
JOI high school students like alternating rows of light bulbs with and without lights (such rows of light bulbs are called alternating rows). Therefore, I decided to use this machine only once if necessary to make illuminations containing alternating rows as long as possible.
Example
For example, the arrangement of illuminations is from west to east
<image>
(β indicates a light bulb with a light, β indicates a light bulb without a light). At this time, if you operate the machine for the four light bulbs from the 4th to the 7th,
<image>
The second to eighth bulbs form an alternating row of length 7.
<image>
Also, if you operate the machine only for the 8th light bulb,
<image>
The 4th to 10th light bulbs form an alternating row of length 7.
<image>
It is not possible to create alternating rows longer than 8 by using the machine up to once.
Task
Given the illumination information, write a program to find the maximum possible length of the alternating rows in the array of light bulbs that can be obtained by using the machine up to once.
Limits
* 2 β€ N β€ 100 000 Number of light bulbs that make up the illumination
input
Read the following data from standard input.
* The integer N is written on the first line.
* On the second line, N 0s or 1s are written with a space as a delimiter. Each integer represents the information of the light bulb before operating the machine. The i (1 β€ i β€ N) th integer from the left represents the information of the i-th light bulb from the west, and if the integer is 1, the light bulb is on, and if it is 0, the light bulb is off.
output
Output an integer representing the maximum length of the alternating columns contained in the columns of light bulbs that can be created to the standard output on one line.
Input / output example
Input example 1
Ten
1 1 0 0 1 0 1 1 1 0
Output example 1
7
This is an example explained in the problem statement.
Input example 2
Ten
1 0 0 0 0 1 0 1 0 1
Output example 2
8
Manipulating only the fourth bulb from the west yields an alternating sequence that satisfies the maximum value of 8.
Input example 3
Five
1 1 0 1 1
Output example 3
Five
By manipulating the second to fourth light bulbs counting from the west, you can create an alternating row of all light bulbs.
Input example 4
3
0 1 0
Output example 4
3
Note that you may not need to use a machine.
The question text and the data used for the automatic referee are the question text and the test data for scoring, which are created and published by the Japan Committee for Information Olympics.
Example
Input
10
1 1 0 0 1 0 1 1 1 0
Output
7 | instruction | 0 | 47,880 | 7 | 95,760 |
"Correct Solution:
```
n = int(input())
a = list(map(int,input().split()))
dp = [[1]*3 for i in range(n)]
ans = 1
for i in range(n-1):
for j in range(3):
if a[i] != a[i+1]:
if dp[i+1][j] < dp[i][j] + 1:
dp[i+1][j] = dp[i][j] + 1
if j<2 and a[i] == a[i+1]:
if dp[i+1][j+1] < dp[i][j] + 1:
dp[i+1][j+1] = dp[i][j] + 1
for v in dp:
t = max(v)
if ans < t:
ans = t
print(ans)
``` | output | 1 | 47,880 | 7 | 95,761 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Illumination
Illuminations are displayed in the corridors every year at the JOI High School Cultural Festival. The illuminations consist of N light bulbs, which are lined up in a row from the west side to the east side of the corridor. Each light bulb is either on or off.
A machine that operates a light bulb is sleeping in the warehouse of JOI High School. When a continuous light bulb is specified in the illumination, this machine turns all the specified light bulbs with the light on and all the light bulbs without the light on. However, the machine is aging and can only be used once.
JOI high school students like alternating rows of light bulbs with and without lights (such rows of light bulbs are called alternating rows). Therefore, I decided to use this machine only once if necessary to make illuminations containing alternating rows as long as possible.
Example
For example, the arrangement of illuminations is from west to east
<image>
(β indicates a light bulb with a light, β indicates a light bulb without a light). At this time, if you operate the machine for the four light bulbs from the 4th to the 7th,
<image>
The second to eighth bulbs form an alternating row of length 7.
<image>
Also, if you operate the machine only for the 8th light bulb,
<image>
The 4th to 10th light bulbs form an alternating row of length 7.
<image>
It is not possible to create alternating rows longer than 8 by using the machine up to once.
Task
Given the illumination information, write a program to find the maximum possible length of the alternating rows in the array of light bulbs that can be obtained by using the machine up to once.
Limits
* 2 β€ N β€ 100 000 Number of light bulbs that make up the illumination
input
Read the following data from standard input.
* The integer N is written on the first line.
* On the second line, N 0s or 1s are written with a space as a delimiter. Each integer represents the information of the light bulb before operating the machine. The i (1 β€ i β€ N) th integer from the left represents the information of the i-th light bulb from the west, and if the integer is 1, the light bulb is on, and if it is 0, the light bulb is off.
output
Output an integer representing the maximum length of the alternating columns contained in the columns of light bulbs that can be created to the standard output on one line.
Input / output example
Input example 1
Ten
1 1 0 0 1 0 1 1 1 0
Output example 1
7
This is an example explained in the problem statement.
Input example 2
Ten
1 0 0 0 0 1 0 1 0 1
Output example 2
8
Manipulating only the fourth bulb from the west yields an alternating sequence that satisfies the maximum value of 8.
Input example 3
Five
1 1 0 1 1
Output example 3
Five
By manipulating the second to fourth light bulbs counting from the west, you can create an alternating row of all light bulbs.
Input example 4
3
0 1 0
Output example 4
3
Note that you may not need to use a machine.
The question text and the data used for the automatic referee are the question text and the test data for scoring, which are created and published by the Japan Committee for Information Olympics.
Example
Input
10
1 1 0 0 1 0 1 1 1 0
Output
7
Submitted Solution:
```
n, lights = int(input()), input().split()
con, seq = 1, []
prev = lights.pop()
while lights:
light = lights.pop()
if light == prev:
seq.append(con)
con = 1
else:
con += 1
prev = light
seq.append(con)
if len(seq) <= 3:
print(sum(seq))
else:
print(max(sum(seq[i:i + 3]) for i in range(len(seq) - 2)))
``` | instruction | 0 | 47,881 | 7 | 95,762 |
Yes | output | 1 | 47,881 | 7 | 95,763 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Illumination
Illuminations are displayed in the corridors every year at the JOI High School Cultural Festival. The illuminations consist of N light bulbs, which are lined up in a row from the west side to the east side of the corridor. Each light bulb is either on or off.
A machine that operates a light bulb is sleeping in the warehouse of JOI High School. When a continuous light bulb is specified in the illumination, this machine turns all the specified light bulbs with the light on and all the light bulbs without the light on. However, the machine is aging and can only be used once.
JOI high school students like alternating rows of light bulbs with and without lights (such rows of light bulbs are called alternating rows). Therefore, I decided to use this machine only once if necessary to make illuminations containing alternating rows as long as possible.
Example
For example, the arrangement of illuminations is from west to east
<image>
(β indicates a light bulb with a light, β indicates a light bulb without a light). At this time, if you operate the machine for the four light bulbs from the 4th to the 7th,
<image>
The second to eighth bulbs form an alternating row of length 7.
<image>
Also, if you operate the machine only for the 8th light bulb,
<image>
The 4th to 10th light bulbs form an alternating row of length 7.
<image>
It is not possible to create alternating rows longer than 8 by using the machine up to once.
Task
Given the illumination information, write a program to find the maximum possible length of the alternating rows in the array of light bulbs that can be obtained by using the machine up to once.
Limits
* 2 β€ N β€ 100 000 Number of light bulbs that make up the illumination
input
Read the following data from standard input.
* The integer N is written on the first line.
* On the second line, N 0s or 1s are written with a space as a delimiter. Each integer represents the information of the light bulb before operating the machine. The i (1 β€ i β€ N) th integer from the left represents the information of the i-th light bulb from the west, and if the integer is 1, the light bulb is on, and if it is 0, the light bulb is off.
output
Output an integer representing the maximum length of the alternating columns contained in the columns of light bulbs that can be created to the standard output on one line.
Input / output example
Input example 1
Ten
1 1 0 0 1 0 1 1 1 0
Output example 1
7
This is an example explained in the problem statement.
Input example 2
Ten
1 0 0 0 0 1 0 1 0 1
Output example 2
8
Manipulating only the fourth bulb from the west yields an alternating sequence that satisfies the maximum value of 8.
Input example 3
Five
1 1 0 1 1
Output example 3
Five
By manipulating the second to fourth light bulbs counting from the west, you can create an alternating row of all light bulbs.
Input example 4
3
0 1 0
Output example 4
3
Note that you may not need to use a machine.
The question text and the data used for the automatic referee are the question text and the test data for scoring, which are created and published by the Japan Committee for Information Olympics.
Example
Input
10
1 1 0 0 1 0 1 1 1 0
Output
7
Submitted Solution:
```
N = int(input())
*A, = map(int, input().split())
for i in range(N): A[i] ^= i&1
B = []
prev = A[0]; cnt = 0
for i in range(N):
if prev != A[i]:
B.append(cnt)
cnt = 1
else:
cnt += 1
prev = A[i]
B.append(cnt)
if len(B) == 1:
print(B[0])
elif len(B) == 2:
print(B[0] + B[1])
else:
print(max(B[i]+B[i+1]+B[i+2] for i in range(len(B)-2)))
``` | instruction | 0 | 47,882 | 7 | 95,764 |
Yes | output | 1 | 47,882 | 7 | 95,765 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Illumination
Illuminations are displayed in the corridors every year at the JOI High School Cultural Festival. The illuminations consist of N light bulbs, which are lined up in a row from the west side to the east side of the corridor. Each light bulb is either on or off.
A machine that operates a light bulb is sleeping in the warehouse of JOI High School. When a continuous light bulb is specified in the illumination, this machine turns all the specified light bulbs with the light on and all the light bulbs without the light on. However, the machine is aging and can only be used once.
JOI high school students like alternating rows of light bulbs with and without lights (such rows of light bulbs are called alternating rows). Therefore, I decided to use this machine only once if necessary to make illuminations containing alternating rows as long as possible.
Example
For example, the arrangement of illuminations is from west to east
<image>
(β indicates a light bulb with a light, β indicates a light bulb without a light). At this time, if you operate the machine for the four light bulbs from the 4th to the 7th,
<image>
The second to eighth bulbs form an alternating row of length 7.
<image>
Also, if you operate the machine only for the 8th light bulb,
<image>
The 4th to 10th light bulbs form an alternating row of length 7.
<image>
It is not possible to create alternating rows longer than 8 by using the machine up to once.
Task
Given the illumination information, write a program to find the maximum possible length of the alternating rows in the array of light bulbs that can be obtained by using the machine up to once.
Limits
* 2 β€ N β€ 100 000 Number of light bulbs that make up the illumination
input
Read the following data from standard input.
* The integer N is written on the first line.
* On the second line, N 0s or 1s are written with a space as a delimiter. Each integer represents the information of the light bulb before operating the machine. The i (1 β€ i β€ N) th integer from the left represents the information of the i-th light bulb from the west, and if the integer is 1, the light bulb is on, and if it is 0, the light bulb is off.
output
Output an integer representing the maximum length of the alternating columns contained in the columns of light bulbs that can be created to the standard output on one line.
Input / output example
Input example 1
Ten
1 1 0 0 1 0 1 1 1 0
Output example 1
7
This is an example explained in the problem statement.
Input example 2
Ten
1 0 0 0 0 1 0 1 0 1
Output example 2
8
Manipulating only the fourth bulb from the west yields an alternating sequence that satisfies the maximum value of 8.
Input example 3
Five
1 1 0 1 1
Output example 3
Five
By manipulating the second to fourth light bulbs counting from the west, you can create an alternating row of all light bulbs.
Input example 4
3
0 1 0
Output example 4
3
Note that you may not need to use a machine.
The question text and the data used for the automatic referee are the question text and the test data for scoring, which are created and published by the Japan Committee for Information Olympics.
Example
Input
10
1 1 0 0 1 0 1 1 1 0
Output
7
Submitted Solution:
```
# AOJ0603
illu = []
n = 0
def findmax(begin, end):
flag = illu[begin]
l = 1
maxlen = 1
for i in range(begin + 1, end + 1):
if illu[i] + flag == 1:
l += 1
else:
if l > maxlen:
maxlen = l
l = 1
flag = illu[i]
return maxlen if maxlen > l else l
def find_alterseq():
seq = []
s = e = 0
flag = illu[0]
for i in range(1, n + 1):
if illu[i] + flag != 1:
seq.append([s, i - 1])
s = i
flag = illu[i]
return seq
def reverse(s, e):
for i in range(s, e + 1):
illu[i] = 1 - illu[i]
def solve():
alseq = find_alterseq()
maxlen = 0
alseq.insert(0, [0, 0])
alseq.append([n, n])
nindex = len(alseq)
for i in range(1, nindex - 1):
s, e = alseq[i]
begin = alseq[i - 1][0]
end = alseq[i + 1][1]
if end - begin + 1 >= maxlen:
reverse(s, e)
l = findmax(begin, end)
if l > maxlen:
maxlen = l
reverse(s, e)
return maxlen
line = input()
n = int(line)
illu = list(map(int, list(input().split())))
illu.append(999)
ans = solve()
print(ans)
``` | instruction | 0 | 47,883 | 7 | 95,766 |
Yes | output | 1 | 47,883 | 7 | 95,767 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Illumination
Illuminations are displayed in the corridors every year at the JOI High School Cultural Festival. The illuminations consist of N light bulbs, which are lined up in a row from the west side to the east side of the corridor. Each light bulb is either on or off.
A machine that operates a light bulb is sleeping in the warehouse of JOI High School. When a continuous light bulb is specified in the illumination, this machine turns all the specified light bulbs with the light on and all the light bulbs without the light on. However, the machine is aging and can only be used once.
JOI high school students like alternating rows of light bulbs with and without lights (such rows of light bulbs are called alternating rows). Therefore, I decided to use this machine only once if necessary to make illuminations containing alternating rows as long as possible.
Example
For example, the arrangement of illuminations is from west to east
<image>
(β indicates a light bulb with a light, β indicates a light bulb without a light). At this time, if you operate the machine for the four light bulbs from the 4th to the 7th,
<image>
The second to eighth bulbs form an alternating row of length 7.
<image>
Also, if you operate the machine only for the 8th light bulb,
<image>
The 4th to 10th light bulbs form an alternating row of length 7.
<image>
It is not possible to create alternating rows longer than 8 by using the machine up to once.
Task
Given the illumination information, write a program to find the maximum possible length of the alternating rows in the array of light bulbs that can be obtained by using the machine up to once.
Limits
* 2 β€ N β€ 100 000 Number of light bulbs that make up the illumination
input
Read the following data from standard input.
* The integer N is written on the first line.
* On the second line, N 0s or 1s are written with a space as a delimiter. Each integer represents the information of the light bulb before operating the machine. The i (1 β€ i β€ N) th integer from the left represents the information of the i-th light bulb from the west, and if the integer is 1, the light bulb is on, and if it is 0, the light bulb is off.
output
Output an integer representing the maximum length of the alternating columns contained in the columns of light bulbs that can be created to the standard output on one line.
Input / output example
Input example 1
Ten
1 1 0 0 1 0 1 1 1 0
Output example 1
7
This is an example explained in the problem statement.
Input example 2
Ten
1 0 0 0 0 1 0 1 0 1
Output example 2
8
Manipulating only the fourth bulb from the west yields an alternating sequence that satisfies the maximum value of 8.
Input example 3
Five
1 1 0 1 1
Output example 3
Five
By manipulating the second to fourth light bulbs counting from the west, you can create an alternating row of all light bulbs.
Input example 4
3
0 1 0
Output example 4
3
Note that you may not need to use a machine.
The question text and the data used for the automatic referee are the question text and the test data for scoring, which are created and published by the Japan Committee for Information Olympics.
Example
Input
10
1 1 0 0 1 0 1 1 1 0
Output
7
Submitted Solution:
```
N = int(input())
dl = list(map(str, input().split()))
ans = 1
def search(d):
global ans
for i in range(N):
k = 1
for j in range(i+1, N):
if d[j-1] != d[j]:
k += 1
if ans < k:
ans = k
if ans == 8:
return
else:
k = 1
def search2():
global ans
for i in range(N):
for j in range(i+1, N-1):
if dl[j-1] == dl[j] and dl[j] == dl[j+1]:
t = [y for y in dl]
t[j] = "1" if t[j] == "0" else "0"
search(t)
if ans == 8:
return
def search3():
global ans
for i in range(N):
x = -1
for j in range(i+1, N):
if dl[j-1] == dl[j]:
x = j
if x != -1:
t = [y for y in dl]
for a in range(x, j+1):
t[a] = "1" if t[a] == "0" else "0"
search(t)
if ans == 8:
return
search(dl)
if ans != 8:
search2()
if ans != 8:
search3()
print(ans)
``` | instruction | 0 | 47,884 | 7 | 95,768 |
No | output | 1 | 47,884 | 7 | 95,769 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Illumination
Illuminations are displayed in the corridors every year at the JOI High School Cultural Festival. The illuminations consist of N light bulbs, which are lined up in a row from the west side to the east side of the corridor. Each light bulb is either on or off.
A machine that operates a light bulb is sleeping in the warehouse of JOI High School. When a continuous light bulb is specified in the illumination, this machine turns all the specified light bulbs with the light on and all the light bulbs without the light on. However, the machine is aging and can only be used once.
JOI high school students like alternating rows of light bulbs with and without lights (such rows of light bulbs are called alternating rows). Therefore, I decided to use this machine only once if necessary to make illuminations containing alternating rows as long as possible.
Example
For example, the arrangement of illuminations is from west to east
<image>
(β indicates a light bulb with a light, β indicates a light bulb without a light). At this time, if you operate the machine for the four light bulbs from the 4th to the 7th,
<image>
The second to eighth bulbs form an alternating row of length 7.
<image>
Also, if you operate the machine only for the 8th light bulb,
<image>
The 4th to 10th light bulbs form an alternating row of length 7.
<image>
It is not possible to create alternating rows longer than 8 by using the machine up to once.
Task
Given the illumination information, write a program to find the maximum possible length of the alternating rows in the array of light bulbs that can be obtained by using the machine up to once.
Limits
* 2 β€ N β€ 100 000 Number of light bulbs that make up the illumination
input
Read the following data from standard input.
* The integer N is written on the first line.
* On the second line, N 0s or 1s are written with a space as a delimiter. Each integer represents the information of the light bulb before operating the machine. The i (1 β€ i β€ N) th integer from the left represents the information of the i-th light bulb from the west, and if the integer is 1, the light bulb is on, and if it is 0, the light bulb is off.
output
Output an integer representing the maximum length of the alternating columns contained in the columns of light bulbs that can be created to the standard output on one line.
Input / output example
Input example 1
Ten
1 1 0 0 1 0 1 1 1 0
Output example 1
7
This is an example explained in the problem statement.
Input example 2
Ten
1 0 0 0 0 1 0 1 0 1
Output example 2
8
Manipulating only the fourth bulb from the west yields an alternating sequence that satisfies the maximum value of 8.
Input example 3
Five
1 1 0 1 1
Output example 3
Five
By manipulating the second to fourth light bulbs counting from the west, you can create an alternating row of all light bulbs.
Input example 4
3
0 1 0
Output example 4
3
Note that you may not need to use a machine.
The question text and the data used for the automatic referee are the question text and the test data for scoring, which are created and published by the Japan Committee for Information Olympics.
Example
Input
10
1 1 0 0 1 0 1 1 1 0
Output
7
Submitted Solution:
```
N = int(input())
dl = list(map(str, input().split()))
ans = 1
def search(d):
tmp = 1
for i in range(N):
k = 1
for j in range(i+1, N):
if d[j-1] != d[j]:
k += 1
if tmp < k:
tmp = k
else:
k = 1
return tmp
ans = search(dl)
for i in range(N):
for j in range(i+1, N-1):
if dl[j-1] == dl[j] and dl[j] == dl[j+1]:
t = [y for y in dl]
t[j] = "1" if t[j] == "0" else "0"
ret = search(t)
if ans < ret:
ans = ret
for i in range(N):
x = -1
for j in range(i+1, N):
if dl[j-1] == dl[j]:
x = j
if x != -1:
t = [y for y in dl]
for a in range(x, j+1):
t[a] = "1" if t[a] == "0" else "0"
ret = search(t)
if ans < ret:
ans = ret
print(ans)
``` | instruction | 0 | 47,885 | 7 | 95,770 |
No | output | 1 | 47,885 | 7 | 95,771 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Illumination
Illuminations are displayed in the corridors every year at the JOI High School Cultural Festival. The illuminations consist of N light bulbs, which are lined up in a row from the west side to the east side of the corridor. Each light bulb is either on or off.
A machine that operates a light bulb is sleeping in the warehouse of JOI High School. When a continuous light bulb is specified in the illumination, this machine turns all the specified light bulbs with the light on and all the light bulbs without the light on. However, the machine is aging and can only be used once.
JOI high school students like alternating rows of light bulbs with and without lights (such rows of light bulbs are called alternating rows). Therefore, I decided to use this machine only once if necessary to make illuminations containing alternating rows as long as possible.
Example
For example, the arrangement of illuminations is from west to east
<image>
(β indicates a light bulb with a light, β indicates a light bulb without a light). At this time, if you operate the machine for the four light bulbs from the 4th to the 7th,
<image>
The second to eighth bulbs form an alternating row of length 7.
<image>
Also, if you operate the machine only for the 8th light bulb,
<image>
The 4th to 10th light bulbs form an alternating row of length 7.
<image>
It is not possible to create alternating rows longer than 8 by using the machine up to once.
Task
Given the illumination information, write a program to find the maximum possible length of the alternating rows in the array of light bulbs that can be obtained by using the machine up to once.
Limits
* 2 β€ N β€ 100 000 Number of light bulbs that make up the illumination
input
Read the following data from standard input.
* The integer N is written on the first line.
* On the second line, N 0s or 1s are written with a space as a delimiter. Each integer represents the information of the light bulb before operating the machine. The i (1 β€ i β€ N) th integer from the left represents the information of the i-th light bulb from the west, and if the integer is 1, the light bulb is on, and if it is 0, the light bulb is off.
output
Output an integer representing the maximum length of the alternating columns contained in the columns of light bulbs that can be created to the standard output on one line.
Input / output example
Input example 1
Ten
1 1 0 0 1 0 1 1 1 0
Output example 1
7
This is an example explained in the problem statement.
Input example 2
Ten
1 0 0 0 0 1 0 1 0 1
Output example 2
8
Manipulating only the fourth bulb from the west yields an alternating sequence that satisfies the maximum value of 8.
Input example 3
Five
1 1 0 1 1
Output example 3
Five
By manipulating the second to fourth light bulbs counting from the west, you can create an alternating row of all light bulbs.
Input example 4
3
0 1 0
Output example 4
3
Note that you may not need to use a machine.
The question text and the data used for the automatic referee are the question text and the test data for scoring, which are created and published by the Japan Committee for Information Olympics.
Example
Input
10
1 1 0 0 1 0 1 1 1 0
Output
7
Submitted Solution:
```
N = int(input())
dl = list(map(str, input().split()))
ans = 1
def search(d):
tmp = 1
for i in range(N):
k = 1
for j in range(i+1, N):
if d[j-1] != d[j]:
k += 1
if tmp < k:
tmp = k
if tmp == 8:
return tmp
else:
k = 1
return tmp
ans = search(dl)
for i in range(N):
for j in range(i+1, N-1):
if dl[j-1] == dl[j] and dl[j] == dl[j+1]:
t = [y for y in dl]
t[j] = "1" if t[j] == "0" else "0"
ret = search(t)
if ans < ret:
ans = ret
if ans == 8:
break
for i in range(N):
x = -1
for j in range(i+1, N):
if dl[j-1] == dl[j]:
x = j
if x != -1:
t = [y for y in dl]
for a in range(x, j+1):
t[a] = "1" if t[a] == "0" else "0"
ret = search(t)
if ans < ret:
ans = ret
if ans == 8:
break
print(ans)
``` | instruction | 0 | 47,886 | 7 | 95,772 |
No | output | 1 | 47,886 | 7 | 95,773 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There is a sequence of colorful stones. The color of each stone is one of red, green, or blue. You are given a string s. The i-th (1-based) character of s represents the color of the i-th stone. If the character is "R", "G", or "B", the color of the corresponding stone is red, green, or blue, respectively.
Initially Squirrel Liss is standing on the first stone. You perform instructions one or more times.
Each instruction is one of the three types: "RED", "GREEN", or "BLUE". After an instruction c, if Liss is standing on a stone whose colors is c, Liss will move one stone forward, else she will not move.
You are given a string t. The number of instructions is equal to the length of t, and the i-th character of t represents the i-th instruction.
Calculate the final position of Liss (the number of the stone she is going to stand on in the end) after performing all the instructions, and print its 1-based position. It is guaranteed that Liss don't move out of the sequence.
Input
The input contains two lines. The first line contains the string s (1 β€ |s| β€ 50). The second line contains the string t (1 β€ |t| β€ 50). The characters of each string will be one of "R", "G", or "B". It is guaranteed that Liss don't move out of the sequence.
Output
Print the final 1-based position of Liss in a single line.
Examples
Input
RGB
RRR
Output
2
Input
RRRBGBRBBB
BBBRR
Output
3
Input
BRRBGBRGRBGRGRRGGBGBGBRGBRGRGGGRBRRRBRBBBGRRRGGBBB
BBRBGGRGRGBBBRBGRBRBBBBRBRRRBGBBGBBRRBBGGRBRRBRGRB
Output
15 | instruction | 0 | 48,210 | 7 | 96,420 |
Tags: implementation
Correct Solution:
```
s = str(input())
t = str(input())
idx = 0
ans = s[idx]
for i in range(len(t)):
if (ans == t[i]):
idx += 1
ans = s[idx]
print(idx + 1)
``` | output | 1 | 48,210 | 7 | 96,421 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There is a sequence of colorful stones. The color of each stone is one of red, green, or blue. You are given a string s. The i-th (1-based) character of s represents the color of the i-th stone. If the character is "R", "G", or "B", the color of the corresponding stone is red, green, or blue, respectively.
Initially Squirrel Liss is standing on the first stone. You perform instructions one or more times.
Each instruction is one of the three types: "RED", "GREEN", or "BLUE". After an instruction c, if Liss is standing on a stone whose colors is c, Liss will move one stone forward, else she will not move.
You are given a string t. The number of instructions is equal to the length of t, and the i-th character of t represents the i-th instruction.
Calculate the final position of Liss (the number of the stone she is going to stand on in the end) after performing all the instructions, and print its 1-based position. It is guaranteed that Liss don't move out of the sequence.
Input
The input contains two lines. The first line contains the string s (1 β€ |s| β€ 50). The second line contains the string t (1 β€ |t| β€ 50). The characters of each string will be one of "R", "G", or "B". It is guaranteed that Liss don't move out of the sequence.
Output
Print the final 1-based position of Liss in a single line.
Examples
Input
RGB
RRR
Output
2
Input
RRRBGBRBBB
BBBRR
Output
3
Input
BRRBGBRGRBGRGRRGGBGBGBRGBRGRGGGRBRRRBRBBBGRRRGGBBB
BBRBGGRGRGBBBRBGRBRBBBBRBRRRBGBBGBBRRBBGGRBRRBRGRB
Output
15 | instruction | 0 | 48,211 | 7 | 96,422 |
Tags: implementation
Correct Solution:
```
# A. Colorful Stones (Simplified Edition)
s = input()
t = input()
output = 1
i, j = (0,)*2
while i < len(s) and j < len(t):
if s[i] == t[j]:
i += 1
j += 1
output += 1
else:
j += 1
print(output)
``` | output | 1 | 48,211 | 7 | 96,423 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There is a sequence of colorful stones. The color of each stone is one of red, green, or blue. You are given a string s. The i-th (1-based) character of s represents the color of the i-th stone. If the character is "R", "G", or "B", the color of the corresponding stone is red, green, or blue, respectively.
Initially Squirrel Liss is standing on the first stone. You perform instructions one or more times.
Each instruction is one of the three types: "RED", "GREEN", or "BLUE". After an instruction c, if Liss is standing on a stone whose colors is c, Liss will move one stone forward, else she will not move.
You are given a string t. The number of instructions is equal to the length of t, and the i-th character of t represents the i-th instruction.
Calculate the final position of Liss (the number of the stone she is going to stand on in the end) after performing all the instructions, and print its 1-based position. It is guaranteed that Liss don't move out of the sequence.
Input
The input contains two lines. The first line contains the string s (1 β€ |s| β€ 50). The second line contains the string t (1 β€ |t| β€ 50). The characters of each string will be one of "R", "G", or "B". It is guaranteed that Liss don't move out of the sequence.
Output
Print the final 1-based position of Liss in a single line.
Examples
Input
RGB
RRR
Output
2
Input
RRRBGBRBBB
BBBRR
Output
3
Input
BRRBGBRGRBGRGRRGGBGBGBRGBRGRGGGRBRRRBRBBBGRRRGGBBB
BBRBGGRGRGBBBRBGRBRBBBBRBRRRBGBBGBBRRBBGGRBRRBRGRB
Output
15 | instruction | 0 | 48,212 | 7 | 96,424 |
Tags: implementation
Correct Solution:
```
#code
a,b = input(),input()
j = 0
for i in range(len(b)):
if b[i] == a[j]:
j+=1
print(j+1)
``` | output | 1 | 48,212 | 7 | 96,425 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There is a sequence of colorful stones. The color of each stone is one of red, green, or blue. You are given a string s. The i-th (1-based) character of s represents the color of the i-th stone. If the character is "R", "G", or "B", the color of the corresponding stone is red, green, or blue, respectively.
Initially Squirrel Liss is standing on the first stone. You perform instructions one or more times.
Each instruction is one of the three types: "RED", "GREEN", or "BLUE". After an instruction c, if Liss is standing on a stone whose colors is c, Liss will move one stone forward, else she will not move.
You are given a string t. The number of instructions is equal to the length of t, and the i-th character of t represents the i-th instruction.
Calculate the final position of Liss (the number of the stone she is going to stand on in the end) after performing all the instructions, and print its 1-based position. It is guaranteed that Liss don't move out of the sequence.
Input
The input contains two lines. The first line contains the string s (1 β€ |s| β€ 50). The second line contains the string t (1 β€ |t| β€ 50). The characters of each string will be one of "R", "G", or "B". It is guaranteed that Liss don't move out of the sequence.
Output
Print the final 1-based position of Liss in a single line.
Examples
Input
RGB
RRR
Output
2
Input
RRRBGBRBBB
BBBRR
Output
3
Input
BRRBGBRGRBGRGRRGGBGBGBRGBRGRGGGRBRRRBRBBBGRRRGGBBB
BBRBGGRGRGBBBRBGRBRBBBBRBRRRBGBBGBBRRBBGGRBRRBRGRB
Output
15 | instruction | 0 | 48,213 | 7 | 96,426 |
Tags: implementation
Correct Solution:
```
s=input()
t=input()
j=0
i=0
while j<len(t):
if(t[j]==s[i]):
i+=1
j+=1
print(i+1)
``` | output | 1 | 48,213 | 7 | 96,427 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There is a sequence of colorful stones. The color of each stone is one of red, green, or blue. You are given a string s. The i-th (1-based) character of s represents the color of the i-th stone. If the character is "R", "G", or "B", the color of the corresponding stone is red, green, or blue, respectively.
Initially Squirrel Liss is standing on the first stone. You perform instructions one or more times.
Each instruction is one of the three types: "RED", "GREEN", or "BLUE". After an instruction c, if Liss is standing on a stone whose colors is c, Liss will move one stone forward, else she will not move.
You are given a string t. The number of instructions is equal to the length of t, and the i-th character of t represents the i-th instruction.
Calculate the final position of Liss (the number of the stone she is going to stand on in the end) after performing all the instructions, and print its 1-based position. It is guaranteed that Liss don't move out of the sequence.
Input
The input contains two lines. The first line contains the string s (1 β€ |s| β€ 50). The second line contains the string t (1 β€ |t| β€ 50). The characters of each string will be one of "R", "G", or "B". It is guaranteed that Liss don't move out of the sequence.
Output
Print the final 1-based position of Liss in a single line.
Examples
Input
RGB
RRR
Output
2
Input
RRRBGBRBBB
BBBRR
Output
3
Input
BRRBGBRGRBGRGRRGGBGBGBRGBRGRGGGRBRRRBRBBBGRRRGGBBB
BBRBGGRGRGBBBRBGRBRBBBBRBRRRBGBBGBBRRBBGGRBRRBRGRB
Output
15 | instruction | 0 | 48,214 | 7 | 96,428 |
Tags: implementation
Correct Solution:
```
s=input()
k=input()
c=1
i=0
t=1
while(t<=len(k)):
if k[i]==s[c-1]:
c=c+1
t=t+1
i+=1
print(c)
``` | output | 1 | 48,214 | 7 | 96,429 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There is a sequence of colorful stones. The color of each stone is one of red, green, or blue. You are given a string s. The i-th (1-based) character of s represents the color of the i-th stone. If the character is "R", "G", or "B", the color of the corresponding stone is red, green, or blue, respectively.
Initially Squirrel Liss is standing on the first stone. You perform instructions one or more times.
Each instruction is one of the three types: "RED", "GREEN", or "BLUE". After an instruction c, if Liss is standing on a stone whose colors is c, Liss will move one stone forward, else she will not move.
You are given a string t. The number of instructions is equal to the length of t, and the i-th character of t represents the i-th instruction.
Calculate the final position of Liss (the number of the stone she is going to stand on in the end) after performing all the instructions, and print its 1-based position. It is guaranteed that Liss don't move out of the sequence.
Input
The input contains two lines. The first line contains the string s (1 β€ |s| β€ 50). The second line contains the string t (1 β€ |t| β€ 50). The characters of each string will be one of "R", "G", or "B". It is guaranteed that Liss don't move out of the sequence.
Output
Print the final 1-based position of Liss in a single line.
Examples
Input
RGB
RRR
Output
2
Input
RRRBGBRBBB
BBBRR
Output
3
Input
BRRBGBRGRBGRGRRGGBGBGBRGBRGRGGGRBRRRBRBBBGRRRGGBBB
BBRBGGRGRGBBBRBGRBRBBBBRBRRRBGBBGBBRRBBGGRBRRBRGRB
Output
15 | instruction | 0 | 48,215 | 7 | 96,430 |
Tags: implementation
Correct Solution:
```
s1 = input()
s2 = input()
i, j = 0, 0
while j < len(s2):
if s1[i] == s2[j]:
j += 1
i += 1
else:
j += 1
print(i+1)
``` | output | 1 | 48,215 | 7 | 96,431 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There is a sequence of colorful stones. The color of each stone is one of red, green, or blue. You are given a string s. The i-th (1-based) character of s represents the color of the i-th stone. If the character is "R", "G", or "B", the color of the corresponding stone is red, green, or blue, respectively.
Initially Squirrel Liss is standing on the first stone. You perform instructions one or more times.
Each instruction is one of the three types: "RED", "GREEN", or "BLUE". After an instruction c, if Liss is standing on a stone whose colors is c, Liss will move one stone forward, else she will not move.
You are given a string t. The number of instructions is equal to the length of t, and the i-th character of t represents the i-th instruction.
Calculate the final position of Liss (the number of the stone she is going to stand on in the end) after performing all the instructions, and print its 1-based position. It is guaranteed that Liss don't move out of the sequence.
Input
The input contains two lines. The first line contains the string s (1 β€ |s| β€ 50). The second line contains the string t (1 β€ |t| β€ 50). The characters of each string will be one of "R", "G", or "B". It is guaranteed that Liss don't move out of the sequence.
Output
Print the final 1-based position of Liss in a single line.
Examples
Input
RGB
RRR
Output
2
Input
RRRBGBRBBB
BBBRR
Output
3
Input
BRRBGBRGRBGRGRRGGBGBGBRGBRGRGGGRBRRRBRBBBGRRRGGBBB
BBRBGGRGRGBBBRBGRBRBBBBRBRRRBGBBGBBRRBBGGRBRRBRGRB
Output
15 | instruction | 0 | 48,216 | 7 | 96,432 |
Tags: implementation
Correct Solution:
```
s = input()
t = input()
step = 0
for i in range(len(t)):
if s[step] == t[i]:
step += 1
print(step+1)
``` | output | 1 | 48,216 | 7 | 96,433 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There is a sequence of colorful stones. The color of each stone is one of red, green, or blue. You are given a string s. The i-th (1-based) character of s represents the color of the i-th stone. If the character is "R", "G", or "B", the color of the corresponding stone is red, green, or blue, respectively.
Initially Squirrel Liss is standing on the first stone. You perform instructions one or more times.
Each instruction is one of the three types: "RED", "GREEN", or "BLUE". After an instruction c, if Liss is standing on a stone whose colors is c, Liss will move one stone forward, else she will not move.
You are given a string t. The number of instructions is equal to the length of t, and the i-th character of t represents the i-th instruction.
Calculate the final position of Liss (the number of the stone she is going to stand on in the end) after performing all the instructions, and print its 1-based position. It is guaranteed that Liss don't move out of the sequence.
Input
The input contains two lines. The first line contains the string s (1 β€ |s| β€ 50). The second line contains the string t (1 β€ |t| β€ 50). The characters of each string will be one of "R", "G", or "B". It is guaranteed that Liss don't move out of the sequence.
Output
Print the final 1-based position of Liss in a single line.
Examples
Input
RGB
RRR
Output
2
Input
RRRBGBRBBB
BBBRR
Output
3
Input
BRRBGBRGRBGRGRRGGBGBGBRGBRGRGGGRBRRRBRBBBGRRRGGBBB
BBRBGGRGRGBBBRBGRBRBBBBRBRRRBGBBGBBRRBBGGRBRRBRGRB
Output
15 | instruction | 0 | 48,217 | 7 | 96,434 |
Tags: implementation
Correct Solution:
```
import sys
from math import ceil,log
RI = lambda : [int(x) for x in sys.stdin.readline().split()]
ri = lambda : sys.stdin.readline().strip()
def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('Yes')
def NO(): print('No')
INF = 10 ** 18
MOD = 10 ** 9 + 7
s = ri()
t = ri()
i = 0
for j in range(len(t)):
if t[j] == s[i]:
i+=1
print(i+1)
``` | output | 1 | 48,217 | 7 | 96,435 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is a sequence of colorful stones. The color of each stone is one of red, green, or blue. You are given a string s. The i-th (1-based) character of s represents the color of the i-th stone. If the character is "R", "G", or "B", the color of the corresponding stone is red, green, or blue, respectively.
Initially Squirrel Liss is standing on the first stone. You perform instructions one or more times.
Each instruction is one of the three types: "RED", "GREEN", or "BLUE". After an instruction c, if Liss is standing on a stone whose colors is c, Liss will move one stone forward, else she will not move.
You are given a string t. The number of instructions is equal to the length of t, and the i-th character of t represents the i-th instruction.
Calculate the final position of Liss (the number of the stone she is going to stand on in the end) after performing all the instructions, and print its 1-based position. It is guaranteed that Liss don't move out of the sequence.
Input
The input contains two lines. The first line contains the string s (1 β€ |s| β€ 50). The second line contains the string t (1 β€ |t| β€ 50). The characters of each string will be one of "R", "G", or "B". It is guaranteed that Liss don't move out of the sequence.
Output
Print the final 1-based position of Liss in a single line.
Examples
Input
RGB
RRR
Output
2
Input
RRRBGBRBBB
BBBRR
Output
3
Input
BRRBGBRGRBGRGRRGGBGBGBRGBRGRGGGRBRRRBRBBBGRRRGGBBB
BBRBGGRGRGBBBRBGRBRBBBBRBRRRBGBBGBBRRBBGGRBRRBRGRB
Output
15
Submitted Solution:
```
try:
s1 = input()
s2 = input()
i,j = 0,0
count = 1
while i < len(s1) and j < len(s2):
if s1[i] == s2[j] :
count += 1
i = i + 1
j = j + 1
else:
j = j + 1
print(count)
except Exception:
pass
``` | instruction | 0 | 48,218 | 7 | 96,436 |
Yes | output | 1 | 48,218 | 7 | 96,437 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is a sequence of colorful stones. The color of each stone is one of red, green, or blue. You are given a string s. The i-th (1-based) character of s represents the color of the i-th stone. If the character is "R", "G", or "B", the color of the corresponding stone is red, green, or blue, respectively.
Initially Squirrel Liss is standing on the first stone. You perform instructions one or more times.
Each instruction is one of the three types: "RED", "GREEN", or "BLUE". After an instruction c, if Liss is standing on a stone whose colors is c, Liss will move one stone forward, else she will not move.
You are given a string t. The number of instructions is equal to the length of t, and the i-th character of t represents the i-th instruction.
Calculate the final position of Liss (the number of the stone she is going to stand on in the end) after performing all the instructions, and print its 1-based position. It is guaranteed that Liss don't move out of the sequence.
Input
The input contains two lines. The first line contains the string s (1 β€ |s| β€ 50). The second line contains the string t (1 β€ |t| β€ 50). The characters of each string will be one of "R", "G", or "B". It is guaranteed that Liss don't move out of the sequence.
Output
Print the final 1-based position of Liss in a single line.
Examples
Input
RGB
RRR
Output
2
Input
RRRBGBRBBB
BBBRR
Output
3
Input
BRRBGBRGRBGRGRRGGBGBGBRGBRGRGGGRBRRRBRBBBGRRRGGBBB
BBRBGGRGRGBBBRBGRBRBBBBRBRRRBGBBGBBRRBBGGRBRRBRGRB
Output
15
Submitted Solution:
```
from sys import stdin,stdout
st=lambda:list(stdin.readline().strip())
li=lambda:list(map(int,stdin.readline().split()))
mp=lambda:map(int,stdin.readline().split())
inp=lambda:int(stdin.readline())
pr=lambda n: stdout.write(str(n)+"\n")
mod=1000000007
INF= float('inf')
def solve():
s=st()
t=st()
i=0
j=0
while j<len(t):
i+=(t[j]==s[i])
j+=1
pr(i+1)
for _ in range(1):
solve()
``` | instruction | 0 | 48,219 | 7 | 96,438 |
Yes | output | 1 | 48,219 | 7 | 96,439 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is a sequence of colorful stones. The color of each stone is one of red, green, or blue. You are given a string s. The i-th (1-based) character of s represents the color of the i-th stone. If the character is "R", "G", or "B", the color of the corresponding stone is red, green, or blue, respectively.
Initially Squirrel Liss is standing on the first stone. You perform instructions one or more times.
Each instruction is one of the three types: "RED", "GREEN", or "BLUE". After an instruction c, if Liss is standing on a stone whose colors is c, Liss will move one stone forward, else she will not move.
You are given a string t. The number of instructions is equal to the length of t, and the i-th character of t represents the i-th instruction.
Calculate the final position of Liss (the number of the stone she is going to stand on in the end) after performing all the instructions, and print its 1-based position. It is guaranteed that Liss don't move out of the sequence.
Input
The input contains two lines. The first line contains the string s (1 β€ |s| β€ 50). The second line contains the string t (1 β€ |t| β€ 50). The characters of each string will be one of "R", "G", or "B". It is guaranteed that Liss don't move out of the sequence.
Output
Print the final 1-based position of Liss in a single line.
Examples
Input
RGB
RRR
Output
2
Input
RRRBGBRBBB
BBBRR
Output
3
Input
BRRBGBRGRBGRGRRGGBGBGBRGBRGRGGGRBRRRBRBBBGRRRGGBBB
BBRBGGRGRGBBBRBGRBRBBBBRBRRRBGBBGBBRRBBGGRBRRBRGRB
Output
15
Submitted Solution:
```
s = input()
t = input()
v = 0
for c in t:
if c == s[v]:
v += 1
print(v+1)
``` | instruction | 0 | 48,220 | 7 | 96,440 |
Yes | output | 1 | 48,220 | 7 | 96,441 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is a sequence of colorful stones. The color of each stone is one of red, green, or blue. You are given a string s. The i-th (1-based) character of s represents the color of the i-th stone. If the character is "R", "G", or "B", the color of the corresponding stone is red, green, or blue, respectively.
Initially Squirrel Liss is standing on the first stone. You perform instructions one or more times.
Each instruction is one of the three types: "RED", "GREEN", or "BLUE". After an instruction c, if Liss is standing on a stone whose colors is c, Liss will move one stone forward, else she will not move.
You are given a string t. The number of instructions is equal to the length of t, and the i-th character of t represents the i-th instruction.
Calculate the final position of Liss (the number of the stone she is going to stand on in the end) after performing all the instructions, and print its 1-based position. It is guaranteed that Liss don't move out of the sequence.
Input
The input contains two lines. The first line contains the string s (1 β€ |s| β€ 50). The second line contains the string t (1 β€ |t| β€ 50). The characters of each string will be one of "R", "G", or "B". It is guaranteed that Liss don't move out of the sequence.
Output
Print the final 1-based position of Liss in a single line.
Examples
Input
RGB
RRR
Output
2
Input
RRRBGBRBBB
BBBRR
Output
3
Input
BRRBGBRGRBGRGRRGGBGBGBRGBRGRGGGRBRRRBRBBBGRRRGGBBB
BBRBGGRGRGBBBRBGRBRBBBBRBRRRBGBBGBBRRBBGGRBRRBRGRB
Output
15
Submitted Solution:
```
way = input()
instruct = input()
pos = 1
for i in instruct:
if way[pos-1] == i:
pos+=1
print(pos)
``` | instruction | 0 | 48,221 | 7 | 96,442 |
Yes | output | 1 | 48,221 | 7 | 96,443 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is a sequence of colorful stones. The color of each stone is one of red, green, or blue. You are given a string s. The i-th (1-based) character of s represents the color of the i-th stone. If the character is "R", "G", or "B", the color of the corresponding stone is red, green, or blue, respectively.
Initially Squirrel Liss is standing on the first stone. You perform instructions one or more times.
Each instruction is one of the three types: "RED", "GREEN", or "BLUE". After an instruction c, if Liss is standing on a stone whose colors is c, Liss will move one stone forward, else she will not move.
You are given a string t. The number of instructions is equal to the length of t, and the i-th character of t represents the i-th instruction.
Calculate the final position of Liss (the number of the stone she is going to stand on in the end) after performing all the instructions, and print its 1-based position. It is guaranteed that Liss don't move out of the sequence.
Input
The input contains two lines. The first line contains the string s (1 β€ |s| β€ 50). The second line contains the string t (1 β€ |t| β€ 50). The characters of each string will be one of "R", "G", or "B". It is guaranteed that Liss don't move out of the sequence.
Output
Print the final 1-based position of Liss in a single line.
Examples
Input
RGB
RRR
Output
2
Input
RRRBGBRBBB
BBBRR
Output
3
Input
BRRBGBRGRBGRGRRGGBGBGBRGBRGRGGGRBRRRBRBBBGRRRGGBBB
BBRBGGRGRGBBBRBGRBRBBBBRBRRRBGBBGBBRRBBGGRBRRBRGRB
Output
15
Submitted Solution:
```
n= str(input())
t= str(input())
pos = 0
for i in range(len(t)):
if n[i] == t[pos]:
pos=pos+1
else :
break
print(pos+1)
``` | instruction | 0 | 48,222 | 7 | 96,444 |
No | output | 1 | 48,222 | 7 | 96,445 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is a sequence of colorful stones. The color of each stone is one of red, green, or blue. You are given a string s. The i-th (1-based) character of s represents the color of the i-th stone. If the character is "R", "G", or "B", the color of the corresponding stone is red, green, or blue, respectively.
Initially Squirrel Liss is standing on the first stone. You perform instructions one or more times.
Each instruction is one of the three types: "RED", "GREEN", or "BLUE". After an instruction c, if Liss is standing on a stone whose colors is c, Liss will move one stone forward, else she will not move.
You are given a string t. The number of instructions is equal to the length of t, and the i-th character of t represents the i-th instruction.
Calculate the final position of Liss (the number of the stone she is going to stand on in the end) after performing all the instructions, and print its 1-based position. It is guaranteed that Liss don't move out of the sequence.
Input
The input contains two lines. The first line contains the string s (1 β€ |s| β€ 50). The second line contains the string t (1 β€ |t| β€ 50). The characters of each string will be one of "R", "G", or "B". It is guaranteed that Liss don't move out of the sequence.
Output
Print the final 1-based position of Liss in a single line.
Examples
Input
RGB
RRR
Output
2
Input
RRRBGBRBBB
BBBRR
Output
3
Input
BRRBGBRGRBGRGRRGGBGBGBRGBRGRGGGRBRRRBRBBBGRRRGGBBB
BBRBGGRGRGBBBRBGRBRBBBBRBRRRBGBBGBBRRBBGGRBRRBRGRB
Output
15
Submitted Solution:
```
s = input()
s2 = input()
step = 0
for i in range(len(s2)):
if s[i] == s2[i]:
step+=1
print(step+1)
``` | instruction | 0 | 48,223 | 7 | 96,446 |
No | output | 1 | 48,223 | 7 | 96,447 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is a sequence of colorful stones. The color of each stone is one of red, green, or blue. You are given a string s. The i-th (1-based) character of s represents the color of the i-th stone. If the character is "R", "G", or "B", the color of the corresponding stone is red, green, or blue, respectively.
Initially Squirrel Liss is standing on the first stone. You perform instructions one or more times.
Each instruction is one of the three types: "RED", "GREEN", or "BLUE". After an instruction c, if Liss is standing on a stone whose colors is c, Liss will move one stone forward, else she will not move.
You are given a string t. The number of instructions is equal to the length of t, and the i-th character of t represents the i-th instruction.
Calculate the final position of Liss (the number of the stone she is going to stand on in the end) after performing all the instructions, and print its 1-based position. It is guaranteed that Liss don't move out of the sequence.
Input
The input contains two lines. The first line contains the string s (1 β€ |s| β€ 50). The second line contains the string t (1 β€ |t| β€ 50). The characters of each string will be one of "R", "G", or "B". It is guaranteed that Liss don't move out of the sequence.
Output
Print the final 1-based position of Liss in a single line.
Examples
Input
RGB
RRR
Output
2
Input
RRRBGBRBBB
BBBRR
Output
3
Input
BRRBGBRGRBGRGRRGGBGBGBRGBRGRGGGRBRRRBRBBBGRRRGGBBB
BBRBGGRGRGBBBRBGRBRBBBBRBRRRBGBBGBBRRBBGGRBRRBRGRB
Output
15
Submitted Solution:
```
s1=input()
s2=input()
l1=len(s1)
l2=len(s2)
i=0
j=0
ans=0
while(l1>0 and l2>0):
if s1[i]==s2[j]:
ans+=1
i+=1
j+=1
else:
j+=1
l1-=1
l2-=1
print(ans+1)
``` | instruction | 0 | 48,224 | 7 | 96,448 |
No | output | 1 | 48,224 | 7 | 96,449 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is a sequence of colorful stones. The color of each stone is one of red, green, or blue. You are given a string s. The i-th (1-based) character of s represents the color of the i-th stone. If the character is "R", "G", or "B", the color of the corresponding stone is red, green, or blue, respectively.
Initially Squirrel Liss is standing on the first stone. You perform instructions one or more times.
Each instruction is one of the three types: "RED", "GREEN", or "BLUE". After an instruction c, if Liss is standing on a stone whose colors is c, Liss will move one stone forward, else she will not move.
You are given a string t. The number of instructions is equal to the length of t, and the i-th character of t represents the i-th instruction.
Calculate the final position of Liss (the number of the stone she is going to stand on in the end) after performing all the instructions, and print its 1-based position. It is guaranteed that Liss don't move out of the sequence.
Input
The input contains two lines. The first line contains the string s (1 β€ |s| β€ 50). The second line contains the string t (1 β€ |t| β€ 50). The characters of each string will be one of "R", "G", or "B". It is guaranteed that Liss don't move out of the sequence.
Output
Print the final 1-based position of Liss in a single line.
Examples
Input
RGB
RRR
Output
2
Input
RRRBGBRBBB
BBBRR
Output
3
Input
BRRBGBRGRBGRGRRGGBGBGBRGBRGRGGGRBRRRBRBBBGRRRGGBBB
BBRBGGRGRGBBBRBGRBRBBBBRBRRRBGBBGBBRRBBGGRBRRBRGRB
Output
15
Submitted Solution:
```
stones = input()
instr = input()
curr = 0
for i in instr:
print(i, stones[curr])
if i == stones[curr]:
print("match")
curr += 1
print(curr + 1)
``` | instruction | 0 | 48,225 | 7 | 96,450 |
No | output | 1 | 48,225 | 7 | 96,451 |
Provide a correct Python 3 solution for this coding contest problem.
You are given an image A composed of N rows and N columns of pixels, and a template image B composed of M rows and M columns of pixels.
A pixel is the smallest element of an image, and in this problem it is a square of size 1Γ1.
Also, the given images are binary images, and the color of each pixel is either white or black.
In the input, every pixel is represented by a character: `.` corresponds to a white pixel, and `#` corresponds to a black pixel.
The image A is given as N strings A_1,...,A_N.
The j-th character in the string A_i corresponds to the pixel at the i-th row and j-th column of the image A (1β¦i,jβ¦N).
Similarly, the template image B is given as M strings B_1,...,B_M.
The j-th character in the string B_i corresponds to the pixel at the i-th row and j-th column of the template image B (1β¦i,jβ¦M).
Determine whether the template image B is contained in the image A when only parallel shifts can be applied to the images.
Constraints
* 1β¦Mβ¦Nβ¦50
* A_i is a string of length N consisting of `#` and `.`.
* B_i is a string of length M consisting of `#` and `.`.
Input
The input is given from Standard Input in the following format:
N M
A_1
A_2
:
A_N
B_1
B_2
:
B_M
Output
Print `Yes` if the template image B is contained in the image A. Print `No` otherwise.
Examples
Input
3 2
#.#
.#.
#.#
#.
.#
Output
Yes
Input
3 2
.#
.#.
.#
.
.#
Output
Yes
Input
4 1
....
....
....
....
Output
No | instruction | 0 | 48,671 | 7 | 97,342 |
"Correct Solution:
```
n,m = map(int,input().split())
A = [input() for _ in range(n)]
B = [input() for _ in range(m)]
for i in range(n-m+1):
for p in range(n-m+1):
for c in range(m):
if B[c] != A[p+c][i:i+m]:
break
else:
print("Yes")
exit()
print("No")
``` | output | 1 | 48,671 | 7 | 97,343 |
Provide a correct Python 3 solution for this coding contest problem.
You are given an image A composed of N rows and N columns of pixels, and a template image B composed of M rows and M columns of pixels.
A pixel is the smallest element of an image, and in this problem it is a square of size 1Γ1.
Also, the given images are binary images, and the color of each pixel is either white or black.
In the input, every pixel is represented by a character: `.` corresponds to a white pixel, and `#` corresponds to a black pixel.
The image A is given as N strings A_1,...,A_N.
The j-th character in the string A_i corresponds to the pixel at the i-th row and j-th column of the image A (1β¦i,jβ¦N).
Similarly, the template image B is given as M strings B_1,...,B_M.
The j-th character in the string B_i corresponds to the pixel at the i-th row and j-th column of the template image B (1β¦i,jβ¦M).
Determine whether the template image B is contained in the image A when only parallel shifts can be applied to the images.
Constraints
* 1β¦Mβ¦Nβ¦50
* A_i is a string of length N consisting of `#` and `.`.
* B_i is a string of length M consisting of `#` and `.`.
Input
The input is given from Standard Input in the following format:
N M
A_1
A_2
:
A_N
B_1
B_2
:
B_M
Output
Print `Yes` if the template image B is contained in the image A. Print `No` otherwise.
Examples
Input
3 2
#.#
.#.
#.#
#.
.#
Output
Yes
Input
3 2
.#
.#.
.#
.
.#
Output
Yes
Input
4 1
....
....
....
....
Output
No | instruction | 0 | 48,675 | 7 | 97,350 |
"Correct Solution:
```
n, m = map(int, input().split())
a = [input() for i in range(n)]
b = [input() for i in range(m)]
ans = "Yes"
for i in range(n):
for j in range(m):
if b[j] not in a[i]:
ans = "No"
print(ans)
``` | output | 1 | 48,675 | 7 | 97,351 |
Provide a correct Python 3 solution for this coding contest problem.
You are given an image A composed of N rows and N columns of pixels, and a template image B composed of M rows and M columns of pixels.
A pixel is the smallest element of an image, and in this problem it is a square of size 1Γ1.
Also, the given images are binary images, and the color of each pixel is either white or black.
In the input, every pixel is represented by a character: `.` corresponds to a white pixel, and `#` corresponds to a black pixel.
The image A is given as N strings A_1,...,A_N.
The j-th character in the string A_i corresponds to the pixel at the i-th row and j-th column of the image A (1β¦i,jβ¦N).
Similarly, the template image B is given as M strings B_1,...,B_M.
The j-th character in the string B_i corresponds to the pixel at the i-th row and j-th column of the template image B (1β¦i,jβ¦M).
Determine whether the template image B is contained in the image A when only parallel shifts can be applied to the images.
Constraints
* 1β¦Mβ¦Nβ¦50
* A_i is a string of length N consisting of `#` and `.`.
* B_i is a string of length M consisting of `#` and `.`.
Input
The input is given from Standard Input in the following format:
N M
A_1
A_2
:
A_N
B_1
B_2
:
B_M
Output
Print `Yes` if the template image B is contained in the image A. Print `No` otherwise.
Examples
Input
3 2
#.#
.#.
#.#
#.
.#
Output
Yes
Input
3 2
.#
.#.
.#
.
.#
Output
Yes
Input
4 1
....
....
....
....
Output
No | instruction | 0 | 48,676 | 7 | 97,352 |
"Correct Solution:
```
N, M = map(int, input().split())
A = []
B = []
for i in range(N):
A.append(input())
for i in range(M):
B.append(input())
for h in range(N-M+1):
for w in range(N-M+1):
if list(map(lambda x:x[w:w+M], A[h:h+M])) == B:
print("Yes")
exit()
print("No")
``` | output | 1 | 48,676 | 7 | 97,353 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given an image A composed of N rows and N columns of pixels, and a template image B composed of M rows and M columns of pixels.
A pixel is the smallest element of an image, and in this problem it is a square of size 1Γ1.
Also, the given images are binary images, and the color of each pixel is either white or black.
In the input, every pixel is represented by a character: `.` corresponds to a white pixel, and `#` corresponds to a black pixel.
The image A is given as N strings A_1,...,A_N.
The j-th character in the string A_i corresponds to the pixel at the i-th row and j-th column of the image A (1β¦i,jβ¦N).
Similarly, the template image B is given as M strings B_1,...,B_M.
The j-th character in the string B_i corresponds to the pixel at the i-th row and j-th column of the template image B (1β¦i,jβ¦M).
Determine whether the template image B is contained in the image A when only parallel shifts can be applied to the images.
Constraints
* 1β¦Mβ¦Nβ¦50
* A_i is a string of length N consisting of `#` and `.`.
* B_i is a string of length M consisting of `#` and `.`.
Input
The input is given from Standard Input in the following format:
N M
A_1
A_2
:
A_N
B_1
B_2
:
B_M
Output
Print `Yes` if the template image B is contained in the image A. Print `No` otherwise.
Examples
Input
3 2
#.#
.#.
#.#
#.
.#
Output
Yes
Input
3 2
.#
.#.
.#
.
.#
Output
Yes
Input
4 1
....
....
....
....
Output
No
Submitted Solution:
```
#!/usr/bin/env python3
n, m = map(int, input().split())
a = [input() for _ in range(n)]
b = [input() for _ in range(m)]
for i in range(n - m + 1):
for j in range(n - m + 1):
if all(b[k] == a[i + k][j:j + m] for k in range(m)):
print("Yes")
exit()
print("No")
``` | instruction | 0 | 48,678 | 7 | 97,356 |
Yes | output | 1 | 48,678 | 7 | 97,357 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given an image A composed of N rows and N columns of pixels, and a template image B composed of M rows and M columns of pixels.
A pixel is the smallest element of an image, and in this problem it is a square of size 1Γ1.
Also, the given images are binary images, and the color of each pixel is either white or black.
In the input, every pixel is represented by a character: `.` corresponds to a white pixel, and `#` corresponds to a black pixel.
The image A is given as N strings A_1,...,A_N.
The j-th character in the string A_i corresponds to the pixel at the i-th row and j-th column of the image A (1β¦i,jβ¦N).
Similarly, the template image B is given as M strings B_1,...,B_M.
The j-th character in the string B_i corresponds to the pixel at the i-th row and j-th column of the template image B (1β¦i,jβ¦M).
Determine whether the template image B is contained in the image A when only parallel shifts can be applied to the images.
Constraints
* 1β¦Mβ¦Nβ¦50
* A_i is a string of length N consisting of `#` and `.`.
* B_i is a string of length M consisting of `#` and `.`.
Input
The input is given from Standard Input in the following format:
N M
A_1
A_2
:
A_N
B_1
B_2
:
B_M
Output
Print `Yes` if the template image B is contained in the image A. Print `No` otherwise.
Examples
Input
3 2
#.#
.#.
#.#
#.
.#
Output
Yes
Input
3 2
.#
.#.
.#
.
.#
Output
Yes
Input
4 1
....
....
....
....
Output
No
Submitted Solution:
```
N,M=map(int,input().split())
A=[input() for i in range(N)]
B=[input() for i in range(M)]
ans = "Yes"
for i in A:
for j in B:
if j not in i:
ans = "No"
print(ans)
``` | instruction | 0 | 48,679 | 7 | 97,358 |
Yes | output | 1 | 48,679 | 7 | 97,359 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given an image A composed of N rows and N columns of pixels, and a template image B composed of M rows and M columns of pixels.
A pixel is the smallest element of an image, and in this problem it is a square of size 1Γ1.
Also, the given images are binary images, and the color of each pixel is either white or black.
In the input, every pixel is represented by a character: `.` corresponds to a white pixel, and `#` corresponds to a black pixel.
The image A is given as N strings A_1,...,A_N.
The j-th character in the string A_i corresponds to the pixel at the i-th row and j-th column of the image A (1β¦i,jβ¦N).
Similarly, the template image B is given as M strings B_1,...,B_M.
The j-th character in the string B_i corresponds to the pixel at the i-th row and j-th column of the template image B (1β¦i,jβ¦M).
Determine whether the template image B is contained in the image A when only parallel shifts can be applied to the images.
Constraints
* 1β¦Mβ¦Nβ¦50
* A_i is a string of length N consisting of `#` and `.`.
* B_i is a string of length M consisting of `#` and `.`.
Input
The input is given from Standard Input in the following format:
N M
A_1
A_2
:
A_N
B_1
B_2
:
B_M
Output
Print `Yes` if the template image B is contained in the image A. Print `No` otherwise.
Examples
Input
3 2
#.#
.#.
#.#
#.
.#
Output
Yes
Input
3 2
.#
.#.
.#
.
.#
Output
Yes
Input
4 1
....
....
....
....
Output
No
Submitted Solution:
```
N,M = map(int,input().split())
A = []
B = []
for _ in range(N):
A.append(input())
for _ in range(M):
B.append(input())
for a,b in zip(A,B):
if b in a:
flag = True
else:
flag = False
break;
if flag:
print('Yes')
else:
print('No')
``` | instruction | 0 | 48,680 | 7 | 97,360 |
Yes | output | 1 | 48,680 | 7 | 97,361 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given an image A composed of N rows and N columns of pixels, and a template image B composed of M rows and M columns of pixels.
A pixel is the smallest element of an image, and in this problem it is a square of size 1Γ1.
Also, the given images are binary images, and the color of each pixel is either white or black.
In the input, every pixel is represented by a character: `.` corresponds to a white pixel, and `#` corresponds to a black pixel.
The image A is given as N strings A_1,...,A_N.
The j-th character in the string A_i corresponds to the pixel at the i-th row and j-th column of the image A (1β¦i,jβ¦N).
Similarly, the template image B is given as M strings B_1,...,B_M.
The j-th character in the string B_i corresponds to the pixel at the i-th row and j-th column of the template image B (1β¦i,jβ¦M).
Determine whether the template image B is contained in the image A when only parallel shifts can be applied to the images.
Constraints
* 1β¦Mβ¦Nβ¦50
* A_i is a string of length N consisting of `#` and `.`.
* B_i is a string of length M consisting of `#` and `.`.
Input
The input is given from Standard Input in the following format:
N M
A_1
A_2
:
A_N
B_1
B_2
:
B_M
Output
Print `Yes` if the template image B is contained in the image A. Print `No` otherwise.
Examples
Input
3 2
#.#
.#.
#.#
#.
.#
Output
Yes
Input
3 2
.#
.#.
.#
.
.#
Output
Yes
Input
4 1
....
....
....
....
Output
No
Submitted Solution:
```
n, m = map(int, input().split())
A = [input() for _ in range(n)]
B = [input() for _ in range(m)]
ans = 'No'
for i in range(n - m + 1):
for j in range(n - m + 1):
if all([A[i + k][j:j + m] == B[k] for k in range(m)]):
ans = 'Yes'
print(ans)
``` | instruction | 0 | 48,681 | 7 | 97,362 |
Yes | output | 1 | 48,681 | 7 | 97,363 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given an image A composed of N rows and N columns of pixels, and a template image B composed of M rows and M columns of pixels.
A pixel is the smallest element of an image, and in this problem it is a square of size 1Γ1.
Also, the given images are binary images, and the color of each pixel is either white or black.
In the input, every pixel is represented by a character: `.` corresponds to a white pixel, and `#` corresponds to a black pixel.
The image A is given as N strings A_1,...,A_N.
The j-th character in the string A_i corresponds to the pixel at the i-th row and j-th column of the image A (1β¦i,jβ¦N).
Similarly, the template image B is given as M strings B_1,...,B_M.
The j-th character in the string B_i corresponds to the pixel at the i-th row and j-th column of the template image B (1β¦i,jβ¦M).
Determine whether the template image B is contained in the image A when only parallel shifts can be applied to the images.
Constraints
* 1β¦Mβ¦Nβ¦50
* A_i is a string of length N consisting of `#` and `.`.
* B_i is a string of length M consisting of `#` and `.`.
Input
The input is given from Standard Input in the following format:
N M
A_1
A_2
:
A_N
B_1
B_2
:
B_M
Output
Print `Yes` if the template image B is contained in the image A. Print `No` otherwise.
Examples
Input
3 2
#.#
.#.
#.#
#.
.#
Output
Yes
Input
3 2
.#
.#.
.#
.
.#
Output
Yes
Input
4 1
....
....
....
....
Output
No
Submitted Solution:
```
# ABC 054: B β Template Matching
n, m = map(int, input().split())
a = [input() for _ in range(n)]
b = [input() for _ in range(m)]
isIncluding = 'No'
current = 0
for i in range(n - m):
if b[0] in a[i]:
current = a[i].index(b[0])
for j in range(1, m):
if b[j] not in a[i + j] or a[i + j].index(b[j]) != current:
break
else:
isIncluding = 'Yes'
break
print(isIncluding)
``` | instruction | 0 | 48,682 | 7 | 97,364 |
No | output | 1 | 48,682 | 7 | 97,365 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given an image A composed of N rows and N columns of pixels, and a template image B composed of M rows and M columns of pixels.
A pixel is the smallest element of an image, and in this problem it is a square of size 1Γ1.
Also, the given images are binary images, and the color of each pixel is either white or black.
In the input, every pixel is represented by a character: `.` corresponds to a white pixel, and `#` corresponds to a black pixel.
The image A is given as N strings A_1,...,A_N.
The j-th character in the string A_i corresponds to the pixel at the i-th row and j-th column of the image A (1β¦i,jβ¦N).
Similarly, the template image B is given as M strings B_1,...,B_M.
The j-th character in the string B_i corresponds to the pixel at the i-th row and j-th column of the template image B (1β¦i,jβ¦M).
Determine whether the template image B is contained in the image A when only parallel shifts can be applied to the images.
Constraints
* 1β¦Mβ¦Nβ¦50
* A_i is a string of length N consisting of `#` and `.`.
* B_i is a string of length M consisting of `#` and `.`.
Input
The input is given from Standard Input in the following format:
N M
A_1
A_2
:
A_N
B_1
B_2
:
B_M
Output
Print `Yes` if the template image B is contained in the image A. Print `No` otherwise.
Examples
Input
3 2
#.#
.#.
#.#
#.
.#
Output
Yes
Input
3 2
.#
.#.
.#
.
.#
Output
Yes
Input
4 1
....
....
....
....
Output
No
Submitted Solution:
```
n, m = map(int, input().split(" "))
i1 = [ input() for i in range(n) ]
i2 = [ input() for i in range(m) ]
for i in range(0, n - m + 1):
for j in range(0, n - m + 1):
if [ x[j:] for x in i1[i:] ] == i2:
print("Yes")
exit(0)
print("No")
``` | instruction | 0 | 48,683 | 7 | 97,366 |
No | output | 1 | 48,683 | 7 | 97,367 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given an image A composed of N rows and N columns of pixels, and a template image B composed of M rows and M columns of pixels.
A pixel is the smallest element of an image, and in this problem it is a square of size 1Γ1.
Also, the given images are binary images, and the color of each pixel is either white or black.
In the input, every pixel is represented by a character: `.` corresponds to a white pixel, and `#` corresponds to a black pixel.
The image A is given as N strings A_1,...,A_N.
The j-th character in the string A_i corresponds to the pixel at the i-th row and j-th column of the image A (1β¦i,jβ¦N).
Similarly, the template image B is given as M strings B_1,...,B_M.
The j-th character in the string B_i corresponds to the pixel at the i-th row and j-th column of the template image B (1β¦i,jβ¦M).
Determine whether the template image B is contained in the image A when only parallel shifts can be applied to the images.
Constraints
* 1β¦Mβ¦Nβ¦50
* A_i is a string of length N consisting of `#` and `.`.
* B_i is a string of length M consisting of `#` and `.`.
Input
The input is given from Standard Input in the following format:
N M
A_1
A_2
:
A_N
B_1
B_2
:
B_M
Output
Print `Yes` if the template image B is contained in the image A. Print `No` otherwise.
Examples
Input
3 2
#.#
.#.
#.#
#.
.#
Output
Yes
Input
3 2
.#
.#.
.#
.
.#
Output
Yes
Input
4 1
....
....
....
....
Output
No
Submitted Solution:
```
n,m=map(int,input().split())
i1=[input() for _ in range(n)]
i2=[input() for _ in range(m)]
ans="No"
for i in range(n-m+1):
for j in range(n-m+1):
if i1[i][j:m+j]==i2[0] and i1[i+1][j:j+m]==i2[1]:
ans="Yes"
print(ans)
``` | instruction | 0 | 48,684 | 7 | 97,368 |
No | output | 1 | 48,684 | 7 | 97,369 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given an image A composed of N rows and N columns of pixels, and a template image B composed of M rows and M columns of pixels.
A pixel is the smallest element of an image, and in this problem it is a square of size 1Γ1.
Also, the given images are binary images, and the color of each pixel is either white or black.
In the input, every pixel is represented by a character: `.` corresponds to a white pixel, and `#` corresponds to a black pixel.
The image A is given as N strings A_1,...,A_N.
The j-th character in the string A_i corresponds to the pixel at the i-th row and j-th column of the image A (1β¦i,jβ¦N).
Similarly, the template image B is given as M strings B_1,...,B_M.
The j-th character in the string B_i corresponds to the pixel at the i-th row and j-th column of the template image B (1β¦i,jβ¦M).
Determine whether the template image B is contained in the image A when only parallel shifts can be applied to the images.
Constraints
* 1β¦Mβ¦Nβ¦50
* A_i is a string of length N consisting of `#` and `.`.
* B_i is a string of length M consisting of `#` and `.`.
Input
The input is given from Standard Input in the following format:
N M
A_1
A_2
:
A_N
B_1
B_2
:
B_M
Output
Print `Yes` if the template image B is contained in the image A. Print `No` otherwise.
Examples
Input
3 2
#.#
.#.
#.#
#.
.#
Output
Yes
Input
3 2
.#
.#.
.#
.
.#
Output
Yes
Input
4 1
....
....
....
....
Output
No
Submitted Solution:
```
N,M = map(int,input().split())
As = []
Bs = []
check = False
for n in range(N):
As.append(input())
for m in range(M):
Bs.append(input())
for i in range(len(As)-len(Bs)):
minicheck = True
for j in range(len(Bs)):
if Bs[j] not in As[i+j]:
minicheck = False
break
if minicheck == True:
check = True
break
if check == True:
print("Yes")
else:
print("No")
``` | instruction | 0 | 48,685 | 7 | 97,370 |
No | output | 1 | 48,685 | 7 | 97,371 |
Provide tags and a correct Python 3 solution for this coding contest problem.
According to a new ISO standard, a flag of every country should have, strangely enough, a chequered field n Γ m, each square should be wholly painted one of 26 colours. The following restrictions are set:
* In each row at most two different colours can be used.
* No two adjacent squares can be painted the same colour.
Pay attention, please, that in one column more than two different colours can be used.
Berland's government took a decision to introduce changes into their country's flag in accordance with the new standard, at the same time they want these changes to be minimal. By the given description of Berland's flag you should find out the minimum amount of squares that need to be painted different colour to make the flag meet the new ISO standard. You are as well to build one of the possible variants of the new Berland's flag.
Input
The first input line contains 2 integers n and m (1 β€ n, m β€ 500) β amount of rows and columns in Berland's flag respectively. Then there follows the flag's description: each of the following n lines contains m characters. Each character is a letter from a to z, and it stands for the colour of the corresponding square.
Output
In the first line output the minimum amount of squares that need to be repainted to make the flag meet the new ISO standard. The following n lines should contain one of the possible variants of the new flag. Don't forget that the variant of the flag, proposed by you, should be derived from the old flag with the minimum amount of repainted squares. If the answer isn't unique, output any.
Examples
Input
3 4
aaaa
bbbb
cccc
Output
6
abab
baba
acac
Input
3 3
aba
aba
zzz
Output
4
aba
bab
zbz | instruction | 0 | 49,122 | 7 | 98,244 |
Tags: dp
Correct Solution:
```
import sys
from array import array # noqa: F401
def input():
return sys.stdin.buffer.readline().decode('utf-8')
n, m = map(int, input().split())
flag = [tuple(map(lambda c: ord(c) - 97, input().rstrip())) for _ in range(n)]
dp = [[[m] * 26 for _ in range(26)] for _ in range(n)]
for i in range(n):
for j in range(m):
if (j & 1) == 0:
for k in range(26):
dp[i][flag[i][j]][k] -= 1
else:
for k in range(26):
dp[i][k][flag[i][j]] -= 1
if i > 0:
for j in range(26):
left = [10**5 * 3] * 26
right = [10**5 * 3] * 27
for x in range(26):
if j == x:
continue
for y in range(26):
if x == y:
continue
if y > 0 and left[y - 1] > dp[i - 1][x][y]:
left[y - 1] = dp[i - 1][x][y]
if right[y + 1] > dp[i - 1][x][y]:
right[y + 1] = dp[i - 1][x][y]
for k in range(24, -1, -1):
if left[k] > left[k + 1]:
left[k] = left[k + 1]
for k in range(26):
dp[i][j][k] += left[k] if left[k] < right[k] else right[k]
if right[k] < right[k + 1]:
right[k + 1] = right[k]
ans = 10**9
p_i, p_j = -1, -1
for i in range(26):
for j in range(26):
if i == j:
continue
if ans > dp[-1][i][j]:
ans = dp[-1][i][j]
p_i, p_j = i, j
new_flag = []
for i in range(n - 1, -1, -1):
row = (chr(97 + p_i) + chr(97 + p_j)) * (m >> 1) + (chr(97 + p_i) if m & 1 else '')
new_flag.append(row)
if i:
min_v = 10**9
n_i, n_j = -1, -1
for j in range(26):
if p_i == j:
continue
for k in range(26):
if p_j != k and j != k and min_v > dp[i - 1][j][k]:
min_v = dp[i - 1][j][k]
n_i, n_j = j, k
p_i, p_j = n_i, n_j
print(ans)
for row in reversed(new_flag):
print(row)
``` | output | 1 | 49,122 | 7 | 98,245 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
According to a new ISO standard, a flag of every country should have, strangely enough, a chequered field n Γ m, each square should be wholly painted one of 26 colours. The following restrictions are set:
* In each row at most two different colours can be used.
* No two adjacent squares can be painted the same colour.
Pay attention, please, that in one column more than two different colours can be used.
Berland's government took a decision to introduce changes into their country's flag in accordance with the new standard, at the same time they want these changes to be minimal. By the given description of Berland's flag you should find out the minimum amount of squares that need to be painted different colour to make the flag meet the new ISO standard. You are as well to build one of the possible variants of the new Berland's flag.
Input
The first input line contains 2 integers n and m (1 β€ n, m β€ 500) β amount of rows and columns in Berland's flag respectively. Then there follows the flag's description: each of the following n lines contains m characters. Each character is a letter from a to z, and it stands for the colour of the corresponding square.
Output
In the first line output the minimum amount of squares that need to be repainted to make the flag meet the new ISO standard. The following n lines should contain one of the possible variants of the new flag. Don't forget that the variant of the flag, proposed by you, should be derived from the old flag with the minimum amount of repainted squares. If the answer isn't unique, output any.
Examples
Input
3 4
aaaa
bbbb
cccc
Output
6
abab
baba
acac
Input
3 3
aba
aba
zzz
Output
4
aba
bab
zbz
Submitted Solution:
```
import sys
from array import array # noqa: F401
def input():
return sys.stdin.buffer.readline().decode('utf-8')
n, m = map(int, input().split())
flag = [tuple(map(lambda c: ord(c) - 97, input().rstrip())) for _ in range(n)]
dp = [[[m] * 26 for _ in range(26)] for _ in range(n)]
for i in range(n):
for j in range(m):
if (j & 1) == 0:
for k in range(26):
dp[i][flag[i][j]][k] -= 1
else:
for k in range(26):
dp[i][k][flag[i][j]] -= 1
if i > 0:
for j in range(26):
left = [10**5 * 3] * 26
right = [10**5 * 3] * 27
for k in range(26):
if j == k:
continue
min_v = 10**5 * 3
for x in range(26):
if j == x:
continue
for y in range(26):
if x == y:
continue
if y > 0 and left[y - 1] > dp[i - 1][x][y]:
left[y - 1] = dp[i - 1][x][y]
if right[y + 1] > dp[i - 1][x][y]:
right[y + 1] = dp[i - 1][x][y]
for k in range(24, -1, -1):
if left[k] > left[k + 1]:
left[k] = left[k + 1]
for k in range(26):
dp[i][j][k] += left[k] if left[k] < right[k] else right[k]
if right[i] < right[i + 1]:
right[i + 1] = right[i]
ans = 10**9
p_i, p_j = -1, -1
for i in range(26):
for j in range(26):
if i == j:
continue
if ans > dp[-1][i][j]:
ans = dp[-1][i][j]
p_i, p_j = i, j
new_flag = []
for i in range(n - 1, -1, -1):
row = (chr(97 + p_i) + chr(97 + p_j)) * (m >> 1) + (chr(97 + p_i) if m & 1 else '')
new_flag.append(row)
if i:
min_v = 10**9
n_i, n_j = -1, -1
for j in range(26):
if p_i == j:
continue
for k in range(26):
if p_j != k and j != k and min_v > dp[i - 1][j][k]:
min_v = dp[i - 1][j][k]
n_i, n_j = j, k
p_i, p_j = n_i, n_j
print(ans)
for row in reversed(new_flag):
print(row)
``` | instruction | 0 | 49,123 | 7 | 98,246 |
No | output | 1 | 49,123 | 7 | 98,247 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
According to a new ISO standard, a flag of every country should have, strangely enough, a chequered field n Γ m, each square should be wholly painted one of 26 colours. The following restrictions are set:
* In each row at most two different colours can be used.
* No two adjacent squares can be painted the same colour.
Pay attention, please, that in one column more than two different colours can be used.
Berland's government took a decision to introduce changes into their country's flag in accordance with the new standard, at the same time they want these changes to be minimal. By the given description of Berland's flag you should find out the minimum amount of squares that need to be painted different colour to make the flag meet the new ISO standard. You are as well to build one of the possible variants of the new Berland's flag.
Input
The first input line contains 2 integers n and m (1 β€ n, m β€ 500) β amount of rows and columns in Berland's flag respectively. Then there follows the flag's description: each of the following n lines contains m characters. Each character is a letter from a to z, and it stands for the colour of the corresponding square.
Output
In the first line output the minimum amount of squares that need to be repainted to make the flag meet the new ISO standard. The following n lines should contain one of the possible variants of the new flag. Don't forget that the variant of the flag, proposed by you, should be derived from the old flag with the minimum amount of repainted squares. If the answer isn't unique, output any.
Examples
Input
3 4
aaaa
bbbb
cccc
Output
6
abab
baba
acac
Input
3 3
aba
aba
zzz
Output
4
aba
bab
zbz
Submitted Solution:
```
import sys
from array import array # noqa: F401
def input():
return sys.stdin.buffer.readline().decode('utf-8')
n, m = map(int, input().split())
flag = [tuple(map(lambda c: ord(c) - 97, input().rstrip())) for _ in range(n)]
dp = [[[m] * 26 for _ in range(26)] for _ in range(n)]
for i in range(n):
for j in range(m):
if (j & 1) == 0:
for k in range(26):
dp[i][flag[i][j]][k] -= 1
else:
for k in range(26):
dp[i][k][flag[i][j]] -= 1
if i > 0:
for j in range(26):
left = [10**5 * 3] * 26
right = [10**5 * 3] * 27
for k in range(26):
if j == k:
continue
min_v = 10**5 * 3
for x in range(26):
if j == x:
continue
for y in range(26):
if x == y:
continue
if y > 0:
if left[y - 1] > dp[i - 1][x][y]:
left[y - 1] = dp[i - 1][x][y]
if y < n - 1:
if right[y + 1] > dp[i - 1][x][y]:
right[y + 1] = dp[i - 1][x][y]
for k in range(24, -1, -1):
if left[k] > left[k + 1]:
left[k] = left[k + 1]
for k in range(26):
dp[i][j][k] += min(left[k], right[k])
if right[i] < right[i + 1]:
right[i + 1] = right[i + 1]
ans = 10**9
p_i, p_j = -1, -1
for i in range(26):
for j in range(26):
if i == j:
continue
if ans > dp[-1][i][j]:
ans = dp[-1][i][j]
p_i, p_j = i, j
new_flag = []
for i in range(n - 1, -1, -1):
row = (chr(97 + p_i) + chr(97 + p_j)) * (m >> 1) + (chr(97 + p_i) if m & 1 else '')
new_flag.append(row)
if i:
min_v = 10**9
n_i, n_j = -1, -1
for j in range(26):
if p_i == j:
continue
for k in range(26):
if p_j != k and j != k and min_v > dp[i - 1][j][k]:
min_v = dp[i - 1][j][k]
n_i, n_j = j, k
p_i, p_j = n_i, n_j
print(ans)
for row in reversed(new_flag):
print(row)
``` | instruction | 0 | 49,124 | 7 | 98,248 |
No | output | 1 | 49,124 | 7 | 98,249 |
Provide tags and a correct Python 3 solution for this coding contest problem.
ZS the Coder and Chris the Baboon has arrived at Udayland! They walked in the park where n trees grow. They decided to be naughty and color the trees in the park. The trees are numbered with integers from 1 to n from left to right.
Initially, tree i has color ci. ZS the Coder and Chris the Baboon recognizes only m different colors, so 0 β€ ci β€ m, where ci = 0 means that tree i is uncolored.
ZS the Coder and Chris the Baboon decides to color only the uncolored trees, i.e. the trees with ci = 0. They can color each of them them in any of the m colors from 1 to m. Coloring the i-th tree with color j requires exactly pi, j litres of paint.
The two friends define the beauty of a coloring of the trees as the minimum number of contiguous groups (each group contains some subsegment of trees) you can split all the n trees into so that each group contains trees of the same color. For example, if the colors of the trees from left to right are 2, 1, 1, 1, 3, 2, 2, 3, 1, 3, the beauty of the coloring is 7, since we can partition the trees into 7 contiguous groups of the same color : {2}, {1, 1, 1}, {3}, {2, 2}, {3}, {1}, {3}.
ZS the Coder and Chris the Baboon wants to color all uncolored trees so that the beauty of the coloring is exactly k. They need your help to determine the minimum amount of paint (in litres) needed to finish the job.
Please note that the friends can't color the trees that are already colored.
Input
The first line contains three integers, n, m and k (1 β€ k β€ n β€ 100, 1 β€ m β€ 100) β the number of trees, number of colors and beauty of the resulting coloring respectively.
The second line contains n integers c1, c2, ..., cn (0 β€ ci β€ m), the initial colors of the trees. ci equals to 0 if the tree number i is uncolored, otherwise the i-th tree has color ci.
Then n lines follow. Each of them contains m integers. The j-th number on the i-th of them line denotes pi, j (1 β€ pi, j β€ 109) β the amount of litres the friends need to color i-th tree with color j. pi, j's are specified even for the initially colored trees, but such trees still can't be colored.
Output
Print a single integer, the minimum amount of paint needed to color the trees. If there are no valid tree colorings of beauty k, print - 1.
Examples
Input
3 2 2
0 0 0
1 2
3 4
5 6
Output
10
Input
3 2 2
2 1 2
1 3
2 4
3 5
Output
-1
Input
3 2 2
2 0 0
1 3
2 4
3 5
Output
5
Input
3 2 3
2 1 2
1 3
2 4
3 5
Output
0
Note
In the first sample case, coloring the trees with colors 2, 1, 1 minimizes the amount of paint used, which equals to 2 + 3 + 5 = 10. Note that 1, 1, 1 would not be valid because the beauty of such coloring equals to 1 ({1, 1, 1} is a way to group the trees into a single group of the same color).
In the second sample case, all the trees are colored, but the beauty of the coloring is 3, so there is no valid coloring, and the answer is - 1.
In the last sample case, all the trees are colored and the beauty of the coloring matches k, so no paint is used and the answer is 0. | instruction | 0 | 49,302 | 7 | 98,604 |
Tags: dp
Correct Solution:
```
n, m, k = map(int, input().split())
colors = list(map(int, input().split()))
costs = [list(map(int, input().split())) for _ in range(n)]
dp = [[[float('inf') for _ in range(k+1)]
for _ in range(m+1)]
for _ in range(n+1)]
for i in range(m+1):
for j in range(k+1):
dp[0][i][j] = 0
for i in range(1, n+1):
if colors[i-1] > 0:
c = colors[i-1]
for w in range(1, min(i, k)+1):
dp[i][c][w] = min(dp[i][c][w], dp[i-1][c][w])
for j in range(1, m+1):
if j != c:
dp[i][c][w] = min(dp[i][c][w], dp[i-1][j][w-1])
else:
for w in range(1, min(i, k)+1):
min1, min2 = float('inf'), float('inf')
for j in range(1, m+1):
if dp[i-1][j][w-1] < min1:
min2, min1 = min1, dp[i-1][j][w-1]
else:
min2 = min(min2, dp[i-1][j][w-1])
for j in range(1, m+1):
dp[i][j][w] = min(dp[i][j][w], dp[i-1][j][w] + costs[i-1][j-1])
if min1 != dp[i-1][j][w-1]:
dp[i][j][w] = min(dp[i][j][w], min1 + costs[i-1][j-1])
else:
dp[i][j][w] = min(dp[i][j][w], min2 + costs[i-1][j-1])
res = float('inf')
for i in range(1, m+1):
if dp[n][i][k] < res:
res = dp[n][i][k]
print(-1 if res == float('inf') else res)
``` | output | 1 | 49,302 | 7 | 98,605 |
Provide tags and a correct Python 3 solution for this coding contest problem.
ZS the Coder and Chris the Baboon has arrived at Udayland! They walked in the park where n trees grow. They decided to be naughty and color the trees in the park. The trees are numbered with integers from 1 to n from left to right.
Initially, tree i has color ci. ZS the Coder and Chris the Baboon recognizes only m different colors, so 0 β€ ci β€ m, where ci = 0 means that tree i is uncolored.
ZS the Coder and Chris the Baboon decides to color only the uncolored trees, i.e. the trees with ci = 0. They can color each of them them in any of the m colors from 1 to m. Coloring the i-th tree with color j requires exactly pi, j litres of paint.
The two friends define the beauty of a coloring of the trees as the minimum number of contiguous groups (each group contains some subsegment of trees) you can split all the n trees into so that each group contains trees of the same color. For example, if the colors of the trees from left to right are 2, 1, 1, 1, 3, 2, 2, 3, 1, 3, the beauty of the coloring is 7, since we can partition the trees into 7 contiguous groups of the same color : {2}, {1, 1, 1}, {3}, {2, 2}, {3}, {1}, {3}.
ZS the Coder and Chris the Baboon wants to color all uncolored trees so that the beauty of the coloring is exactly k. They need your help to determine the minimum amount of paint (in litres) needed to finish the job.
Please note that the friends can't color the trees that are already colored.
Input
The first line contains three integers, n, m and k (1 β€ k β€ n β€ 100, 1 β€ m β€ 100) β the number of trees, number of colors and beauty of the resulting coloring respectively.
The second line contains n integers c1, c2, ..., cn (0 β€ ci β€ m), the initial colors of the trees. ci equals to 0 if the tree number i is uncolored, otherwise the i-th tree has color ci.
Then n lines follow. Each of them contains m integers. The j-th number on the i-th of them line denotes pi, j (1 β€ pi, j β€ 109) β the amount of litres the friends need to color i-th tree with color j. pi, j's are specified even for the initially colored trees, but such trees still can't be colored.
Output
Print a single integer, the minimum amount of paint needed to color the trees. If there are no valid tree colorings of beauty k, print - 1.
Examples
Input
3 2 2
0 0 0
1 2
3 4
5 6
Output
10
Input
3 2 2
2 1 2
1 3
2 4
3 5
Output
-1
Input
3 2 2
2 0 0
1 3
2 4
3 5
Output
5
Input
3 2 3
2 1 2
1 3
2 4
3 5
Output
0
Note
In the first sample case, coloring the trees with colors 2, 1, 1 minimizes the amount of paint used, which equals to 2 + 3 + 5 = 10. Note that 1, 1, 1 would not be valid because the beauty of such coloring equals to 1 ({1, 1, 1} is a way to group the trees into a single group of the same color).
In the second sample case, all the trees are colored, but the beauty of the coloring is 3, so there is no valid coloring, and the answer is - 1.
In the last sample case, all the trees are colored and the beauty of the coloring matches k, so no paint is used and the answer is 0. | instruction | 0 | 49,303 | 7 | 98,606 |
Tags: dp
Correct Solution:
```
# [https://codeforces.com/contest/711/submission/20819531]
(n, m, k) = map(int, input().split())
cc = list(map(int, input().split()))
c = cc[0]
cc = cc[1:]
ppp = [list(map(float, input().split())) for _ in range(n)]
pp = ppp[0]
ppp = ppp[1:]
inf = 2.0 ** 47
nxt = [[0.0 if i == c - 1 else inf for i in range(m)] if c else pp]
for c, pp in zip(cc, ppp):
newrow = [inf] * m
cur = nxt
nxt = [newrow]
if c:
c -= 1
for row in cur:
p = row[c]
if newrow[c] > p:
newrow[c] = p
if len(nxt) == k:
break
row[c] = inf
newrow = [inf] * m
newrow[c] = min(row)
nxt.append(newrow)
else:
for row in cur:
for c, p in enumerate(a + b for a, b in zip(row, pp)):
if newrow[c] > p:
newrow[c] = p
if len(nxt) == k:
break
bestclr = min(range(m), key = lambda x: row[x])
x = row[bestclr]
row[bestclr] = inf
newrow = [a + x for a in pp]
newrow[bestclr] = min(row) + pp[bestclr]
nxt.append(newrow)
p = min(nxt[-1])
print(int(p) if p < inf else -1)
``` | output | 1 | 49,303 | 7 | 98,607 |
Provide tags and a correct Python 3 solution for this coding contest problem.
ZS the Coder and Chris the Baboon has arrived at Udayland! They walked in the park where n trees grow. They decided to be naughty and color the trees in the park. The trees are numbered with integers from 1 to n from left to right.
Initially, tree i has color ci. ZS the Coder and Chris the Baboon recognizes only m different colors, so 0 β€ ci β€ m, where ci = 0 means that tree i is uncolored.
ZS the Coder and Chris the Baboon decides to color only the uncolored trees, i.e. the trees with ci = 0. They can color each of them them in any of the m colors from 1 to m. Coloring the i-th tree with color j requires exactly pi, j litres of paint.
The two friends define the beauty of a coloring of the trees as the minimum number of contiguous groups (each group contains some subsegment of trees) you can split all the n trees into so that each group contains trees of the same color. For example, if the colors of the trees from left to right are 2, 1, 1, 1, 3, 2, 2, 3, 1, 3, the beauty of the coloring is 7, since we can partition the trees into 7 contiguous groups of the same color : {2}, {1, 1, 1}, {3}, {2, 2}, {3}, {1}, {3}.
ZS the Coder and Chris the Baboon wants to color all uncolored trees so that the beauty of the coloring is exactly k. They need your help to determine the minimum amount of paint (in litres) needed to finish the job.
Please note that the friends can't color the trees that are already colored.
Input
The first line contains three integers, n, m and k (1 β€ k β€ n β€ 100, 1 β€ m β€ 100) β the number of trees, number of colors and beauty of the resulting coloring respectively.
The second line contains n integers c1, c2, ..., cn (0 β€ ci β€ m), the initial colors of the trees. ci equals to 0 if the tree number i is uncolored, otherwise the i-th tree has color ci.
Then n lines follow. Each of them contains m integers. The j-th number on the i-th of them line denotes pi, j (1 β€ pi, j β€ 109) β the amount of litres the friends need to color i-th tree with color j. pi, j's are specified even for the initially colored trees, but such trees still can't be colored.
Output
Print a single integer, the minimum amount of paint needed to color the trees. If there are no valid tree colorings of beauty k, print - 1.
Examples
Input
3 2 2
0 0 0
1 2
3 4
5 6
Output
10
Input
3 2 2
2 1 2
1 3
2 4
3 5
Output
-1
Input
3 2 2
2 0 0
1 3
2 4
3 5
Output
5
Input
3 2 3
2 1 2
1 3
2 4
3 5
Output
0
Note
In the first sample case, coloring the trees with colors 2, 1, 1 minimizes the amount of paint used, which equals to 2 + 3 + 5 = 10. Note that 1, 1, 1 would not be valid because the beauty of such coloring equals to 1 ({1, 1, 1} is a way to group the trees into a single group of the same color).
In the second sample case, all the trees are colored, but the beauty of the coloring is 3, so there is no valid coloring, and the answer is - 1.
In the last sample case, all the trees are colored and the beauty of the coloring matches k, so no paint is used and the answer is 0. | instruction | 0 | 49,304 | 7 | 98,608 |
Tags: dp
Correct Solution:
```
n,m,k=map(int,input().split())
col=list(map(int,input().split()))
p=[]
for i in range(n):p.append(list(map(int,input().split())))
dp=[[[float('inf')]*m for i in range(k+1)] for i in range(n)]
if col[0]==0:
for i in range(m):
dp[0][1][i]=p[0][i]
else:
dp[0][1][col[0]-1]=0
for i in range(1,n):
for j in range(1,k+1):
if j==1:
if col[i]:
dp[i][j][col[i]-1]=dp[i-1][j][col[i]-1]
else:
for c in range(m):
dp[i][j][c]=dp[i-1][j][c]+p[i][c]
else:
if col[i]:
x=dp[i-1][j][col[i]-1]
for t in range(m):
if t!=col[i]-1:
x=min(x,dp[i-1][j-1][t])
dp[i][j][col[i]-1]=x
else:
for c in range(m):
x=dp[i-1][j][c]
for t in range(m):
if t!=c:
x=min(x,dp[i-1][j-1][t])
dp[i][j][c]=x+p[i][c]
ans=(min(dp[-1][-1]))
if ans!=float('inf'):print(ans)
else:print(-1)
``` | output | 1 | 49,304 | 7 | 98,609 |
Provide tags and a correct Python 3 solution for this coding contest problem.
ZS the Coder and Chris the Baboon has arrived at Udayland! They walked in the park where n trees grow. They decided to be naughty and color the trees in the park. The trees are numbered with integers from 1 to n from left to right.
Initially, tree i has color ci. ZS the Coder and Chris the Baboon recognizes only m different colors, so 0 β€ ci β€ m, where ci = 0 means that tree i is uncolored.
ZS the Coder and Chris the Baboon decides to color only the uncolored trees, i.e. the trees with ci = 0. They can color each of them them in any of the m colors from 1 to m. Coloring the i-th tree with color j requires exactly pi, j litres of paint.
The two friends define the beauty of a coloring of the trees as the minimum number of contiguous groups (each group contains some subsegment of trees) you can split all the n trees into so that each group contains trees of the same color. For example, if the colors of the trees from left to right are 2, 1, 1, 1, 3, 2, 2, 3, 1, 3, the beauty of the coloring is 7, since we can partition the trees into 7 contiguous groups of the same color : {2}, {1, 1, 1}, {3}, {2, 2}, {3}, {1}, {3}.
ZS the Coder and Chris the Baboon wants to color all uncolored trees so that the beauty of the coloring is exactly k. They need your help to determine the minimum amount of paint (in litres) needed to finish the job.
Please note that the friends can't color the trees that are already colored.
Input
The first line contains three integers, n, m and k (1 β€ k β€ n β€ 100, 1 β€ m β€ 100) β the number of trees, number of colors and beauty of the resulting coloring respectively.
The second line contains n integers c1, c2, ..., cn (0 β€ ci β€ m), the initial colors of the trees. ci equals to 0 if the tree number i is uncolored, otherwise the i-th tree has color ci.
Then n lines follow. Each of them contains m integers. The j-th number on the i-th of them line denotes pi, j (1 β€ pi, j β€ 109) β the amount of litres the friends need to color i-th tree with color j. pi, j's are specified even for the initially colored trees, but such trees still can't be colored.
Output
Print a single integer, the minimum amount of paint needed to color the trees. If there are no valid tree colorings of beauty k, print - 1.
Examples
Input
3 2 2
0 0 0
1 2
3 4
5 6
Output
10
Input
3 2 2
2 1 2
1 3
2 4
3 5
Output
-1
Input
3 2 2
2 0 0
1 3
2 4
3 5
Output
5
Input
3 2 3
2 1 2
1 3
2 4
3 5
Output
0
Note
In the first sample case, coloring the trees with colors 2, 1, 1 minimizes the amount of paint used, which equals to 2 + 3 + 5 = 10. Note that 1, 1, 1 would not be valid because the beauty of such coloring equals to 1 ({1, 1, 1} is a way to group the trees into a single group of the same color).
In the second sample case, all the trees are colored, but the beauty of the coloring is 3, so there is no valid coloring, and the answer is - 1.
In the last sample case, all the trees are colored and the beauty of the coloring matches k, so no paint is used and the answer is 0. | instruction | 0 | 49,305 | 7 | 98,610 |
Tags: dp
Correct Solution:
```
def main():
n, m, k = map(int, input().split())
c, *cc = (map(int, input().split()))
pp, *ppp = (list(map(float, input().split())) for _ in range(n))
inf = 2. ** 47
nxt = [[0. if i == c - 1 else inf for i in range(m)] if c else pp]
for c, pp in zip(cc, ppp):
newrow = [inf] * m
cur, nxt = nxt, [newrow]
if c:
c -= 1
for row in cur:
p = row[c]
if newrow[c] > p:
newrow[c] = p
if len(nxt) == k:
break
row[c] = inf
newrow = [inf] * m
newrow[c] = min(row)
nxt.append(newrow)
else:
for row in cur:
for c, p in enumerate(a + b for a, b in zip(row, pp)):
if newrow[c] > p:
newrow[c] = p
if len(nxt) == k:
break
bestclr = min(range(m), key=row.__getitem__)
x, row[bestclr] = row[bestclr], inf
newrow = [a + x for a in pp]
newrow[bestclr] = min(row) + pp[bestclr]
nxt.append(newrow)
p = min(nxt[-1])
print(int(p) if p < inf else -1)
if __name__ == '__main__':
main()
``` | output | 1 | 49,305 | 7 | 98,611 |
Provide tags and a correct Python 3 solution for this coding contest problem.
ZS the Coder and Chris the Baboon has arrived at Udayland! They walked in the park where n trees grow. They decided to be naughty and color the trees in the park. The trees are numbered with integers from 1 to n from left to right.
Initially, tree i has color ci. ZS the Coder and Chris the Baboon recognizes only m different colors, so 0 β€ ci β€ m, where ci = 0 means that tree i is uncolored.
ZS the Coder and Chris the Baboon decides to color only the uncolored trees, i.e. the trees with ci = 0. They can color each of them them in any of the m colors from 1 to m. Coloring the i-th tree with color j requires exactly pi, j litres of paint.
The two friends define the beauty of a coloring of the trees as the minimum number of contiguous groups (each group contains some subsegment of trees) you can split all the n trees into so that each group contains trees of the same color. For example, if the colors of the trees from left to right are 2, 1, 1, 1, 3, 2, 2, 3, 1, 3, the beauty of the coloring is 7, since we can partition the trees into 7 contiguous groups of the same color : {2}, {1, 1, 1}, {3}, {2, 2}, {3}, {1}, {3}.
ZS the Coder and Chris the Baboon wants to color all uncolored trees so that the beauty of the coloring is exactly k. They need your help to determine the minimum amount of paint (in litres) needed to finish the job.
Please note that the friends can't color the trees that are already colored.
Input
The first line contains three integers, n, m and k (1 β€ k β€ n β€ 100, 1 β€ m β€ 100) β the number of trees, number of colors and beauty of the resulting coloring respectively.
The second line contains n integers c1, c2, ..., cn (0 β€ ci β€ m), the initial colors of the trees. ci equals to 0 if the tree number i is uncolored, otherwise the i-th tree has color ci.
Then n lines follow. Each of them contains m integers. The j-th number on the i-th of them line denotes pi, j (1 β€ pi, j β€ 109) β the amount of litres the friends need to color i-th tree with color j. pi, j's are specified even for the initially colored trees, but such trees still can't be colored.
Output
Print a single integer, the minimum amount of paint needed to color the trees. If there are no valid tree colorings of beauty k, print - 1.
Examples
Input
3 2 2
0 0 0
1 2
3 4
5 6
Output
10
Input
3 2 2
2 1 2
1 3
2 4
3 5
Output
-1
Input
3 2 2
2 0 0
1 3
2 4
3 5
Output
5
Input
3 2 3
2 1 2
1 3
2 4
3 5
Output
0
Note
In the first sample case, coloring the trees with colors 2, 1, 1 minimizes the amount of paint used, which equals to 2 + 3 + 5 = 10. Note that 1, 1, 1 would not be valid because the beauty of such coloring equals to 1 ({1, 1, 1} is a way to group the trees into a single group of the same color).
In the second sample case, all the trees are colored, but the beauty of the coloring is 3, so there is no valid coloring, and the answer is - 1.
In the last sample case, all the trees are colored and the beauty of the coloring matches k, so no paint is used and the answer is 0. | instruction | 0 | 49,306 | 7 | 98,612 |
Tags: dp
Correct Solution:
```
n, m, k = map(int, input().split())
arr = list(map(int, input().split()))
paint = [list(map(int, input().split())) for i in range(n)]
if ((0 not in arr) and (len(set(arr)) > k)) or (len(set(arr)) - 1 > k):
print(-1)
exit()
#DP(index, color of index, current beauty)
dp = [0 for n_idx in range(n)]
for n_idx in range(n):
dp[n_idx] = [0 for m_idx in range(m)]
for m_idx in range(m):
dp[n_idx][m_idx] = [float('inf') for k_idx in range(k + 1)]
#Initialize first list of DP
c0 = arr[0]
if c0 != 0: #first tree is already colored
dp[0][c0 - 1][1] = 0
else:
for color in range(m):
dp[0][color][1] = paint[0][color]
for idx in range(1, n):
min_last_idx = {}
for beauty in range(max(1, k - (n - idx) + 1), min(k + 1, idx + 2)):
#get min + 2nd min of all beauty - 1
min_cost = float('inf')
min_cost_color = -1
sec_min_cost = float('inf')
sec_min_cost_color = -1
for color in range(m):
next_cost = dp[idx - 1][color][beauty - 1]
if next_cost < min_cost:
sec_min_cost = min_cost
sec_min_cost_color = min_cost_color
min_cost = next_cost
min_cost_color = color
elif next_cost < sec_min_cost:
sec_min_cost = next_cost
sec_min_cost_color = color
min_last_idx[beauty] = [[min_cost, min_cost_color], [sec_min_cost, sec_min_cost_color]]
curr_color = arr[idx]
if curr_color != 0: #current tree already colored
for beauty in range(max(1, k - (n - idx) + 1), min(k + 1, idx + 2)):
cost_prev_same_color = dp[idx - 1][curr_color - 1][beauty]
min_cost, min_cost_color = min_last_idx[beauty][0]
if min_cost_color == curr_color - 1:
min_cost = min_last_idx[beauty][1][0]
dp[idx][curr_color - 1][beauty] = min(cost_prev_same_color, min_cost)
else:
for curr_color in range(m):
cost_to_color = paint[idx][curr_color]
for beauty in range(max(1, k - (n - idx) + 1), min(k + 1, idx + 2)):
cost_prev_same_color = dp[idx - 1][curr_color][beauty]
min_cost, min_cost_color = min_last_idx[beauty][0]
if min_cost_color == curr_color:
min_cost = min_last_idx[beauty][1][0]
dp[idx][curr_color][beauty] = cost_to_color + min(cost_prev_same_color, min_cost)
min_paint = min([l[k] for l in dp[n - 1]])
if min_paint != float('inf'):
print(min_paint)
else:
print(-1)
``` | output | 1 | 49,306 | 7 | 98,613 |
Provide tags and a correct Python 3 solution for this coding contest problem.
ZS the Coder and Chris the Baboon has arrived at Udayland! They walked in the park where n trees grow. They decided to be naughty and color the trees in the park. The trees are numbered with integers from 1 to n from left to right.
Initially, tree i has color ci. ZS the Coder and Chris the Baboon recognizes only m different colors, so 0 β€ ci β€ m, where ci = 0 means that tree i is uncolored.
ZS the Coder and Chris the Baboon decides to color only the uncolored trees, i.e. the trees with ci = 0. They can color each of them them in any of the m colors from 1 to m. Coloring the i-th tree with color j requires exactly pi, j litres of paint.
The two friends define the beauty of a coloring of the trees as the minimum number of contiguous groups (each group contains some subsegment of trees) you can split all the n trees into so that each group contains trees of the same color. For example, if the colors of the trees from left to right are 2, 1, 1, 1, 3, 2, 2, 3, 1, 3, the beauty of the coloring is 7, since we can partition the trees into 7 contiguous groups of the same color : {2}, {1, 1, 1}, {3}, {2, 2}, {3}, {1}, {3}.
ZS the Coder and Chris the Baboon wants to color all uncolored trees so that the beauty of the coloring is exactly k. They need your help to determine the minimum amount of paint (in litres) needed to finish the job.
Please note that the friends can't color the trees that are already colored.
Input
The first line contains three integers, n, m and k (1 β€ k β€ n β€ 100, 1 β€ m β€ 100) β the number of trees, number of colors and beauty of the resulting coloring respectively.
The second line contains n integers c1, c2, ..., cn (0 β€ ci β€ m), the initial colors of the trees. ci equals to 0 if the tree number i is uncolored, otherwise the i-th tree has color ci.
Then n lines follow. Each of them contains m integers. The j-th number on the i-th of them line denotes pi, j (1 β€ pi, j β€ 109) β the amount of litres the friends need to color i-th tree with color j. pi, j's are specified even for the initially colored trees, but such trees still can't be colored.
Output
Print a single integer, the minimum amount of paint needed to color the trees. If there are no valid tree colorings of beauty k, print - 1.
Examples
Input
3 2 2
0 0 0
1 2
3 4
5 6
Output
10
Input
3 2 2
2 1 2
1 3
2 4
3 5
Output
-1
Input
3 2 2
2 0 0
1 3
2 4
3 5
Output
5
Input
3 2 3
2 1 2
1 3
2 4
3 5
Output
0
Note
In the first sample case, coloring the trees with colors 2, 1, 1 minimizes the amount of paint used, which equals to 2 + 3 + 5 = 10. Note that 1, 1, 1 would not be valid because the beauty of such coloring equals to 1 ({1, 1, 1} is a way to group the trees into a single group of the same color).
In the second sample case, all the trees are colored, but the beauty of the coloring is 3, so there is no valid coloring, and the answer is - 1.
In the last sample case, all the trees are colored and the beauty of the coloring matches k, so no paint is used and the answer is 0. | instruction | 0 | 49,307 | 7 | 98,614 |
Tags: dp
Correct Solution:
```
import math
dp=[[[math.inf for i in range(105)] for i in range(105)] for i in range(105)]
#dp[x][y][z] denote index x , beauty y , using paint z
#dp[x][y][z] denotes cost of it
n,m,k=map(int,input().split())
k+=1
z=list(map(int,input().split()))
matrix=[]
for i in range(n):
ans=list(map(int,input().split()))
matrix.append(ans)
for i in range(len(z)):
if(i==0):
if(z[i]!=0):
dp[0][1][z[i]-1]=0
else:
for x in range(m):
dp[0][1][x]=matrix[i][x]
else:
if(z[i]!=0):
col=z[i]-1
if(z[i-1]!=0):
col2=z[i-1]-1
if(col2==col):
for j in range(k):
if(j==0):
continue;
dp[i][j][col]=min(dp[i-1][j][col],dp[i][j][col])
else:
for j in range(k):
if(j==0):
continue;
dp[i][j][col]=min(dp[i-1][j-1][col2],dp[i][j][col])
else:
pq=[]
for t in range(k):
if(t==0):
continue;
pq=[]
for x in range(m):
pq.append([dp[i-1][t-1][x],x])
pq.append([math.inf,math.inf])
pq.sort()
col=z[i]-1
if(col!=pq[0][1] and pq[0][0]!=math.inf):
dp[i][t][col]=min(dp[i][t][col],pq[0][0],dp[i-1][t][col])
elif(pq[0][0]!=math.inf and col==pq[0][1]):
dp[i][t][col]=min(dp[i][t][col],pq[1][0],dp[i-1][t][col])
elif(pq[0][0]==math.inf):
dp[i][t][col]=min(dp[i][t][col],dp[i-1][t][col])
else:
if(z[i-1]!=0):
col=z[i-1]-1
for t in range(k):
if(t==0):
continue;
for x in range(m):
if(x!=col):
dp[i][t][x]=min(dp[i][t][x],dp[i-1][t-1][col]+matrix[i][x])
else:
dp[i][t][x]=min(dp[i][t][x],dp[i-1][t][col]+matrix[i][x])
else:
for t in range(k):
if(t==0):
continue;
pq=[]
for x in range(m):
pq.append([dp[i-1][t-1][x],x])
pq.append([math.inf,math.inf])
pq.sort()
for v in range(m):
if(v!=pq[0][1]):
dp[i][t][v]=min(dp[i][t][v],pq[0][0]+matrix[i][v],dp[i-1][t][v]+matrix[i][v])
else:
dp[i][t][v]=min(dp[i][t][x],dp[i-1][t][v]+matrix[i][v],pq[1][0]+matrix[i][v])
mini=math.inf
for i in range(m):
mini=min(mini,dp[n-1][k-1][i])
if(mini==math.inf):
print(-1)
else:
print(mini)
``` | output | 1 | 49,307 | 7 | 98,615 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.