text stringlengths 1.02k 43.5k | conversation_id int64 853 107k | embedding list | cluster int64 24 24 |
|---|---|---|---|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp is playing a new computer game. This game has n stones in a row. The stone on the position i has integer power a_i. The powers of all stones are distinct.
Each turn Polycarp can destroy either stone on the first position or stone on the last position (in other words, either the leftmost or the rightmost stone). When Polycarp destroys the stone it does not exist any more.
Now, Polycarp wants two achievements. He gets them if he destroys the stone with the least power and the stone with the greatest power. Help Polycarp find out what is the minimum number of moves he should make in order to achieve his goal.
For example, if n = 5 and a = [1, 5, 4, 3, 2], then Polycarp could make the following moves:
* Destroy the leftmost stone. After this move a = [5, 4, 3, 2];
* Destroy the rightmost stone. After this move a = [5, 4, 3];
* Destroy the leftmost stone. After this move a = [4, 3]. Polycarp destroyed the stones with the greatest and least power, so he can end the game.
Please note that in the example above, you can complete the game in two steps. For example:
* Destroy the leftmost stone. After this move a = [5, 4, 3, 2];
* Destroy the leftmost stone. After this move a = [4, 3, 2]. Polycarp destroyed the stones with the greatest and least power, so he can end the game.
Input
The first line contains an integer t (1 β€ t β€ 100). Then t test cases follow.
The first line of each test case contains one integer n (2 β€ n β€ 100) β the number of stones.
The second line contains n distinct integers a_1, a_2, β¦, a_n (1 β€ a_i β€ n) β the power of the stones.
Output
For each test case, output the minimum number of moves required to destroy the stones with the greatest and the lowest power.
Example
Input
5
5
1 5 4 3 2
8
2 1 3 4 5 6 8 7
8
4 2 3 1 8 6 7 5
4
3 4 2 1
4
2 3 1 4
Output
2
4
5
3
2
Submitted Solution:
```
t = int(input())
for i in range(t):
n = int(input())
a = list(map(int, input().split()))
mi = min(a)
ma = max(a)
if a.index(mi)+a.index(ma)>a[::-1].index(mi)+a[::-1].index(ma):
a = a[::-1]
if abs(a.index(mi)-a.index(ma)) == 1:
print(max(a.index(mi), a.index(ma))+1)
else:
print(min(max(a.index(mi), a.index(ma))+1, min(a.index(mi),a.index(ma))+ 1 + n - max(a.index(mi), a.index(ma))))
```
Yes
| 80,189 | [
0.4091796875,
0.256591796875,
0.10821533203125,
0.3798828125,
-0.763671875,
-0.115234375,
-0.353759765625,
0.2181396484375,
0.184814453125,
0.3974609375,
0.73193359375,
0.307861328125,
0.0175628662109375,
-0.72265625,
-0.68505859375,
0.018524169921875,
-0.771484375,
-0.62353515625,... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp is playing a new computer game. This game has n stones in a row. The stone on the position i has integer power a_i. The powers of all stones are distinct.
Each turn Polycarp can destroy either stone on the first position or stone on the last position (in other words, either the leftmost or the rightmost stone). When Polycarp destroys the stone it does not exist any more.
Now, Polycarp wants two achievements. He gets them if he destroys the stone with the least power and the stone with the greatest power. Help Polycarp find out what is the minimum number of moves he should make in order to achieve his goal.
For example, if n = 5 and a = [1, 5, 4, 3, 2], then Polycarp could make the following moves:
* Destroy the leftmost stone. After this move a = [5, 4, 3, 2];
* Destroy the rightmost stone. After this move a = [5, 4, 3];
* Destroy the leftmost stone. After this move a = [4, 3]. Polycarp destroyed the stones with the greatest and least power, so he can end the game.
Please note that in the example above, you can complete the game in two steps. For example:
* Destroy the leftmost stone. After this move a = [5, 4, 3, 2];
* Destroy the leftmost stone. After this move a = [4, 3, 2]. Polycarp destroyed the stones with the greatest and least power, so he can end the game.
Input
The first line contains an integer t (1 β€ t β€ 100). Then t test cases follow.
The first line of each test case contains one integer n (2 β€ n β€ 100) β the number of stones.
The second line contains n distinct integers a_1, a_2, β¦, a_n (1 β€ a_i β€ n) β the power of the stones.
Output
For each test case, output the minimum number of moves required to destroy the stones with the greatest and the lowest power.
Example
Input
5
5
1 5 4 3 2
8
2 1 3 4 5 6 8 7
8
4 2 3 1 8 6 7 5
4
3 4 2 1
4
2 3 1 4
Output
2
4
5
3
2
Submitted Solution:
```
for _ in range(int(input())):
n = int(input())
l = list(map(int,input().split()))
mi,mx = min(l),max(l)
l2 =sorted(l)
#ll = max(l.index(mi),l.index(mx))
#lr = max(n - l.index(mi),n - l.index(mx))
p1,p2 = l.index(mi)+1, l.index(mx)+1
p3,p4 = n-p1+1,n-p2+1
ll = max(p1,p2)
lr = max(p3,p4)
lm = min(p1,p3)+min(p2,p4)
print(min(lm,ll,lr))
```
Yes
| 80,190 | [
0.4091796875,
0.256591796875,
0.10821533203125,
0.3798828125,
-0.763671875,
-0.115234375,
-0.353759765625,
0.2181396484375,
0.184814453125,
0.3974609375,
0.73193359375,
0.307861328125,
0.0175628662109375,
-0.72265625,
-0.68505859375,
0.018524169921875,
-0.771484375,
-0.62353515625,... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp is playing a new computer game. This game has n stones in a row. The stone on the position i has integer power a_i. The powers of all stones are distinct.
Each turn Polycarp can destroy either stone on the first position or stone on the last position (in other words, either the leftmost or the rightmost stone). When Polycarp destroys the stone it does not exist any more.
Now, Polycarp wants two achievements. He gets them if he destroys the stone with the least power and the stone with the greatest power. Help Polycarp find out what is the minimum number of moves he should make in order to achieve his goal.
For example, if n = 5 and a = [1, 5, 4, 3, 2], then Polycarp could make the following moves:
* Destroy the leftmost stone. After this move a = [5, 4, 3, 2];
* Destroy the rightmost stone. After this move a = [5, 4, 3];
* Destroy the leftmost stone. After this move a = [4, 3]. Polycarp destroyed the stones with the greatest and least power, so he can end the game.
Please note that in the example above, you can complete the game in two steps. For example:
* Destroy the leftmost stone. After this move a = [5, 4, 3, 2];
* Destroy the leftmost stone. After this move a = [4, 3, 2]. Polycarp destroyed the stones with the greatest and least power, so he can end the game.
Input
The first line contains an integer t (1 β€ t β€ 100). Then t test cases follow.
The first line of each test case contains one integer n (2 β€ n β€ 100) β the number of stones.
The second line contains n distinct integers a_1, a_2, β¦, a_n (1 β€ a_i β€ n) β the power of the stones.
Output
For each test case, output the minimum number of moves required to destroy the stones with the greatest and the lowest power.
Example
Input
5
5
1 5 4 3 2
8
2 1 3 4 5 6 8 7
8
4 2 3 1 8 6 7 5
4
3 4 2 1
4
2 3 1 4
Output
2
4
5
3
2
Submitted Solution:
```
t = int(input())
while(t):
n = int(input())
a = list(map(int, input().split()))
a1 = a[::-1]
mx = max(a)
mn = min(a)
l = len(a)
# both from the left
for i in range(l):
if(a[i] == mn):
mn_lb = i+1
if(a[i] == mx):
mx_lb = i+1
# both from the right
for i in range(l):
if(a1[i] == mn):
mn_rb = i+1
if(a1[i] == mx):
mx_rb = i+1
# min from left max from right
for i in range(l):
if(a[i] == mn):
mn_l1 = i+1
for i in range(l):
if(a1[i] == mx):
mx_l1 = i+1
# min from right min from left
for i in range(l):
if(a1[i] == mn):
mn_l2 = i+1
for i in range(l):
if(a[i] == mx):
mx_l2 = i+1
#......................................................................#
ans = min(max(mn_lb, mx_lb), max(mn_rb, mx_rb),
(mn_l1+mx_l1), (mn_l2+mx_l2))
print(ans)
t -= 1
```
Yes
| 80,191 | [
0.4091796875,
0.256591796875,
0.10821533203125,
0.3798828125,
-0.763671875,
-0.115234375,
-0.353759765625,
0.2181396484375,
0.184814453125,
0.3974609375,
0.73193359375,
0.307861328125,
0.0175628662109375,
-0.72265625,
-0.68505859375,
0.018524169921875,
-0.771484375,
-0.62353515625,... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp is playing a new computer game. This game has n stones in a row. The stone on the position i has integer power a_i. The powers of all stones are distinct.
Each turn Polycarp can destroy either stone on the first position or stone on the last position (in other words, either the leftmost or the rightmost stone). When Polycarp destroys the stone it does not exist any more.
Now, Polycarp wants two achievements. He gets them if he destroys the stone with the least power and the stone with the greatest power. Help Polycarp find out what is the minimum number of moves he should make in order to achieve his goal.
For example, if n = 5 and a = [1, 5, 4, 3, 2], then Polycarp could make the following moves:
* Destroy the leftmost stone. After this move a = [5, 4, 3, 2];
* Destroy the rightmost stone. After this move a = [5, 4, 3];
* Destroy the leftmost stone. After this move a = [4, 3]. Polycarp destroyed the stones with the greatest and least power, so he can end the game.
Please note that in the example above, you can complete the game in two steps. For example:
* Destroy the leftmost stone. After this move a = [5, 4, 3, 2];
* Destroy the leftmost stone. After this move a = [4, 3, 2]. Polycarp destroyed the stones with the greatest and least power, so he can end the game.
Input
The first line contains an integer t (1 β€ t β€ 100). Then t test cases follow.
The first line of each test case contains one integer n (2 β€ n β€ 100) β the number of stones.
The second line contains n distinct integers a_1, a_2, β¦, a_n (1 β€ a_i β€ n) β the power of the stones.
Output
For each test case, output the minimum number of moves required to destroy the stones with the greatest and the lowest power.
Example
Input
5
5
1 5 4 3 2
8
2 1 3 4 5 6 8 7
8
4 2 3 1 8 6 7 5
4
3 4 2 1
4
2 3 1 4
Output
2
4
5
3
2
Submitted Solution:
```
import sys
inputlines=sys.stdin.readlines()
number_of_testcase=int(inputlines[0])
def find_index_of_min_and_max_element(input_array,length): # all the elements are distinct
min_index=0
max_index=0
max=input_array[0]
min=input_array[0]
for i in range(1,length):
if input_array[i]>max:
max_index=i
max=input_array[max_index]
if input_array[i]<min:
min_index=i
min=input_array[min_index]
#print(max_index,min_index)
return max_index,min_index
for i in range(number_of_testcase):
number_of_elements=int(inputlines[2*i+1])
elements=list(map(int,inputlines[2*i+2].split(' ')))
max_index,min_index=find_index_of_min_and_max_element(elements,number_of_elements)
positons_list=[]
positons_list.extend([max_index+1,number_of_elements-max_index,min_index+1,number_of_elements-min_index])
#print(positons_list)
position_maxindex,position_minindex=find_index_of_min_and_max_element(positons_list,4)
similar_index_to_positon_minindex=(position_minindex+2)%4
positons_list[similar_index_to_positon_minindex]-=positons_list[position_minindex]
first_deletion=positons_list.pop(position_minindex)
second_deletion=min(positons_list)
print(first_deletion+second_deletion)
```
Yes
| 80,192 | [
0.4091796875,
0.256591796875,
0.10821533203125,
0.3798828125,
-0.763671875,
-0.115234375,
-0.353759765625,
0.2181396484375,
0.184814453125,
0.3974609375,
0.73193359375,
0.307861328125,
0.0175628662109375,
-0.72265625,
-0.68505859375,
0.018524169921875,
-0.771484375,
-0.62353515625,... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp is playing a new computer game. This game has n stones in a row. The stone on the position i has integer power a_i. The powers of all stones are distinct.
Each turn Polycarp can destroy either stone on the first position or stone on the last position (in other words, either the leftmost or the rightmost stone). When Polycarp destroys the stone it does not exist any more.
Now, Polycarp wants two achievements. He gets them if he destroys the stone with the least power and the stone with the greatest power. Help Polycarp find out what is the minimum number of moves he should make in order to achieve his goal.
For example, if n = 5 and a = [1, 5, 4, 3, 2], then Polycarp could make the following moves:
* Destroy the leftmost stone. After this move a = [5, 4, 3, 2];
* Destroy the rightmost stone. After this move a = [5, 4, 3];
* Destroy the leftmost stone. After this move a = [4, 3]. Polycarp destroyed the stones with the greatest and least power, so he can end the game.
Please note that in the example above, you can complete the game in two steps. For example:
* Destroy the leftmost stone. After this move a = [5, 4, 3, 2];
* Destroy the leftmost stone. After this move a = [4, 3, 2]. Polycarp destroyed the stones with the greatest and least power, so he can end the game.
Input
The first line contains an integer t (1 β€ t β€ 100). Then t test cases follow.
The first line of each test case contains one integer n (2 β€ n β€ 100) β the number of stones.
The second line contains n distinct integers a_1, a_2, β¦, a_n (1 β€ a_i β€ n) β the power of the stones.
Output
For each test case, output the minimum number of moves required to destroy the stones with the greatest and the lowest power.
Example
Input
5
5
1 5 4 3 2
8
2 1 3 4 5 6 8 7
8
4 2 3 1 8 6 7 5
4
3 4 2 1
4
2 3 1 4
Output
2
4
5
3
2
Submitted Solution:
```
import sys
import bisect
import math
#import itertools
def get_line(): return list(map(int, sys.stdin.readline().strip().split()))
def in1(): return int(input())
for _ in range(in1()):
n=in1()
a=get_line()
t1=a.index(n)
t2=a.index(1)
if n%2==0:
t3 = n // 2
if t1<=t3 and t2<=t3:
print(max(t1,t2)+1)
elif t1>=t3 and t2>=t3:
print((n-1)-min(t1,t2)+1)
elif t1<=t3 and t2>=t3:
print(t1+1+(n)-t2)
else:
print((n)-t1+1+t2)
else:
t3=n//2
if t1<=t3 and t2<=t3:
print(max(t1,t2)+1)
elif t1>=t3 and t2>=t3:
print((n-1)-min(t1,t2)+1)
elif t1<t3 and t2>t3:
print(t1+1+(n)-t2)
else:
print((n)-t1+1+t2)
```
No
| 80,193 | [
0.4091796875,
0.256591796875,
0.10821533203125,
0.3798828125,
-0.763671875,
-0.115234375,
-0.353759765625,
0.2181396484375,
0.184814453125,
0.3974609375,
0.73193359375,
0.307861328125,
0.0175628662109375,
-0.72265625,
-0.68505859375,
0.018524169921875,
-0.771484375,
-0.62353515625,... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp is playing a new computer game. This game has n stones in a row. The stone on the position i has integer power a_i. The powers of all stones are distinct.
Each turn Polycarp can destroy either stone on the first position or stone on the last position (in other words, either the leftmost or the rightmost stone). When Polycarp destroys the stone it does not exist any more.
Now, Polycarp wants two achievements. He gets them if he destroys the stone with the least power and the stone with the greatest power. Help Polycarp find out what is the minimum number of moves he should make in order to achieve his goal.
For example, if n = 5 and a = [1, 5, 4, 3, 2], then Polycarp could make the following moves:
* Destroy the leftmost stone. After this move a = [5, 4, 3, 2];
* Destroy the rightmost stone. After this move a = [5, 4, 3];
* Destroy the leftmost stone. After this move a = [4, 3]. Polycarp destroyed the stones with the greatest and least power, so he can end the game.
Please note that in the example above, you can complete the game in two steps. For example:
* Destroy the leftmost stone. After this move a = [5, 4, 3, 2];
* Destroy the leftmost stone. After this move a = [4, 3, 2]. Polycarp destroyed the stones with the greatest and least power, so he can end the game.
Input
The first line contains an integer t (1 β€ t β€ 100). Then t test cases follow.
The first line of each test case contains one integer n (2 β€ n β€ 100) β the number of stones.
The second line contains n distinct integers a_1, a_2, β¦, a_n (1 β€ a_i β€ n) β the power of the stones.
Output
For each test case, output the minimum number of moves required to destroy the stones with the greatest and the lowest power.
Example
Input
5
5
1 5 4 3 2
8
2 1 3 4 5 6 8 7
8
4 2 3 1 8 6 7 5
4
3 4 2 1
4
2 3 1 4
Output
2
4
5
3
2
Submitted Solution:
```
def stone(arr):
minIndex = arr.index(min(arr))
maxIndex = arr.index(max(arr))
length = len(arr)
maxofboth = max(minIndex, maxIndex)
minofboth = min(minIndex, maxIndex)
if maxofboth <= length // 2:
return maxofboth + 1
if minofboth >= length // 2:
return length - minofboth
return minofboth + length - maxofboth + 1
for _ in range(int(input())):
input()
print(stone([int(x) for x in input().split()]))
```
No
| 80,194 | [
0.4091796875,
0.256591796875,
0.10821533203125,
0.3798828125,
-0.763671875,
-0.115234375,
-0.353759765625,
0.2181396484375,
0.184814453125,
0.3974609375,
0.73193359375,
0.307861328125,
0.0175628662109375,
-0.72265625,
-0.68505859375,
0.018524169921875,
-0.771484375,
-0.62353515625,... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp is playing a new computer game. This game has n stones in a row. The stone on the position i has integer power a_i. The powers of all stones are distinct.
Each turn Polycarp can destroy either stone on the first position or stone on the last position (in other words, either the leftmost or the rightmost stone). When Polycarp destroys the stone it does not exist any more.
Now, Polycarp wants two achievements. He gets them if he destroys the stone with the least power and the stone with the greatest power. Help Polycarp find out what is the minimum number of moves he should make in order to achieve his goal.
For example, if n = 5 and a = [1, 5, 4, 3, 2], then Polycarp could make the following moves:
* Destroy the leftmost stone. After this move a = [5, 4, 3, 2];
* Destroy the rightmost stone. After this move a = [5, 4, 3];
* Destroy the leftmost stone. After this move a = [4, 3]. Polycarp destroyed the stones with the greatest and least power, so he can end the game.
Please note that in the example above, you can complete the game in two steps. For example:
* Destroy the leftmost stone. After this move a = [5, 4, 3, 2];
* Destroy the leftmost stone. After this move a = [4, 3, 2]. Polycarp destroyed the stones with the greatest and least power, so he can end the game.
Input
The first line contains an integer t (1 β€ t β€ 100). Then t test cases follow.
The first line of each test case contains one integer n (2 β€ n β€ 100) β the number of stones.
The second line contains n distinct integers a_1, a_2, β¦, a_n (1 β€ a_i β€ n) β the power of the stones.
Output
For each test case, output the minimum number of moves required to destroy the stones with the greatest and the lowest power.
Example
Input
5
5
1 5 4 3 2
8
2 1 3 4 5 6 8 7
8
4 2 3 1 8 6 7 5
4
3 4 2 1
4
2 3 1 4
Output
2
4
5
3
2
Submitted Solution:
```
from math import sqrt
data_samples = int(input())
for i in range(0, data_samples):
amount = int(input())
a = list(map(int, input().split()))
min_num_ind = ""
ind = -1
ans = 0
for char in a:
ind += 1
if min_num_ind == "":
min_num_ind = ind
max_num_ind = ind
minimum = char
maximum = char
elif char > maximum:
maximum = char
max_num_ind = ind
elif char < minimum:
minimum = char
min_num_ind = ind
#print(minimum, maximum, max_num_ind, min_num_ind)
range_to_lowest = min_num_ind - (amount / 2)
if range_to_lowest < 0:
ans += min_num_ind + 1
a = a[min_num_ind + 1:]
elif range_to_lowest >= 0:
ans += amount - min_num_ind
a = a[:len(a)-ans]
here = 0
ind = -1
for char in a:
ind += 1
if char == maximum:
here = 1
max_num_ind = ind
break
if here == 1:
range_to_highest = max_num_ind - (len(a) / 2)
if range_to_highest < 0:
ans += max_num_ind + 1
elif range_to_highest >= 0:
ans += len(a) - max_num_ind
print(ans)
```
No
| 80,195 | [
0.4091796875,
0.256591796875,
0.10821533203125,
0.3798828125,
-0.763671875,
-0.115234375,
-0.353759765625,
0.2181396484375,
0.184814453125,
0.3974609375,
0.73193359375,
0.307861328125,
0.0175628662109375,
-0.72265625,
-0.68505859375,
0.018524169921875,
-0.771484375,
-0.62353515625,... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp is playing a new computer game. This game has n stones in a row. The stone on the position i has integer power a_i. The powers of all stones are distinct.
Each turn Polycarp can destroy either stone on the first position or stone on the last position (in other words, either the leftmost or the rightmost stone). When Polycarp destroys the stone it does not exist any more.
Now, Polycarp wants two achievements. He gets them if he destroys the stone with the least power and the stone with the greatest power. Help Polycarp find out what is the minimum number of moves he should make in order to achieve his goal.
For example, if n = 5 and a = [1, 5, 4, 3, 2], then Polycarp could make the following moves:
* Destroy the leftmost stone. After this move a = [5, 4, 3, 2];
* Destroy the rightmost stone. After this move a = [5, 4, 3];
* Destroy the leftmost stone. After this move a = [4, 3]. Polycarp destroyed the stones with the greatest and least power, so he can end the game.
Please note that in the example above, you can complete the game in two steps. For example:
* Destroy the leftmost stone. After this move a = [5, 4, 3, 2];
* Destroy the leftmost stone. After this move a = [4, 3, 2]. Polycarp destroyed the stones with the greatest and least power, so he can end the game.
Input
The first line contains an integer t (1 β€ t β€ 100). Then t test cases follow.
The first line of each test case contains one integer n (2 β€ n β€ 100) β the number of stones.
The second line contains n distinct integers a_1, a_2, β¦, a_n (1 β€ a_i β€ n) β the power of the stones.
Output
For each test case, output the minimum number of moves required to destroy the stones with the greatest and the lowest power.
Example
Input
5
5
1 5 4 3 2
8
2 1 3 4 5 6 8 7
8
4 2 3 1 8 6 7 5
4
3 4 2 1
4
2 3 1 4
Output
2
4
5
3
2
Submitted Solution:
```
t = int(input())
for _ in range(t):
n = int(input())
arr = list(map(int,input().split()))
mi = min(arr) + 1
ma = max(arr) + 1
a = max(mi,ma)
b = max(n - mi,n-ma) + 1
c = min(mi,ma) + n-max(mi,ma) + 1
print(min(a,min(b,c)))
```
No
| 80,196 | [
0.4091796875,
0.256591796875,
0.10821533203125,
0.3798828125,
-0.763671875,
-0.115234375,
-0.353759765625,
0.2181396484375,
0.184814453125,
0.3974609375,
0.73193359375,
0.307861328125,
0.0175628662109375,
-0.72265625,
-0.68505859375,
0.018524169921875,
-0.771484375,
-0.62353515625,... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarpus participates in a competition for hacking into a new secure messenger. He's almost won.
Having carefully studied the interaction protocol, Polycarpus came to the conclusion that the secret key can be obtained if he properly cuts the public key of the application into two parts. The public key is a long integer which may consist of even a million digits!
Polycarpus needs to find such a way to cut the public key into two nonempty parts, that the first (left) part is divisible by a as a separate number, and the second (right) part is divisible by b as a separate number. Both parts should be positive integers that have no leading zeros. Polycarpus knows values a and b.
Help Polycarpus and find any suitable method to cut the public key.
Input
The first line of the input contains the public key of the messenger β an integer without leading zeroes, its length is in range from 1 to 106 digits. The second line contains a pair of space-separated positive integers a, b (1 β€ a, b β€ 108).
Output
In the first line print "YES" (without the quotes), if the method satisfying conditions above exists. In this case, next print two lines β the left and right parts after the cut. These two parts, being concatenated, must be exactly identical to the public key. The left part must be divisible by a, and the right part must be divisible by b. The two parts must be positive integers having no leading zeros. If there are several answers, print any of them.
If there is no answer, print in a single line "NO" (without the quotes).
Examples
Input
116401024
97 1024
Output
YES
11640
1024
Input
284254589153928171911281811000
1009 1000
Output
YES
2842545891539
28171911281811000
Input
120
12 1
Output
NO
Tags: brute force, math, number theory, strings
Correct Solution:
```
import sys
input = sys.stdin.readline
I = lambda : list(map(int,input().split()))
n=input()[:-1]
a,b=I()
l=[];d=[-1]*len(n)
a1=b1=0;po=0;x=str(n)
le=len(x)
for i in x:
i=int(i);mu=pow(10,po,b)
a1=(a1*10+i)%a;b1=(b1+int(x[le-po-1])*mu)%b
l.append(a1);d[le-po-1]=b1
po+=1
for i in range(le-1):
if x[i+1]!='0' and l[i]==0 and d[i+1]==0:
print("YES")
print(x[:i+1])
print(x[i+1:]);break
else:
print("NO")
```
| 80,370 | [
0.52490234375,
0.09466552734375,
0.057525634765625,
0.42724609375,
-0.2012939453125,
-0.2015380859375,
-0.427001953125,
0.140869140625,
0.140869140625,
0.8671875,
0.51806640625,
-0.1658935546875,
0.187744140625,
-0.48291015625,
-0.5283203125,
0.293701171875,
-0.189208984375,
-0.477... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarpus participates in a competition for hacking into a new secure messenger. He's almost won.
Having carefully studied the interaction protocol, Polycarpus came to the conclusion that the secret key can be obtained if he properly cuts the public key of the application into two parts. The public key is a long integer which may consist of even a million digits!
Polycarpus needs to find such a way to cut the public key into two nonempty parts, that the first (left) part is divisible by a as a separate number, and the second (right) part is divisible by b as a separate number. Both parts should be positive integers that have no leading zeros. Polycarpus knows values a and b.
Help Polycarpus and find any suitable method to cut the public key.
Input
The first line of the input contains the public key of the messenger β an integer without leading zeroes, its length is in range from 1 to 106 digits. The second line contains a pair of space-separated positive integers a, b (1 β€ a, b β€ 108).
Output
In the first line print "YES" (without the quotes), if the method satisfying conditions above exists. In this case, next print two lines β the left and right parts after the cut. These two parts, being concatenated, must be exactly identical to the public key. The left part must be divisible by a, and the right part must be divisible by b. The two parts must be positive integers having no leading zeros. If there are several answers, print any of them.
If there is no answer, print in a single line "NO" (without the quotes).
Examples
Input
116401024
97 1024
Output
YES
11640
1024
Input
284254589153928171911281811000
1009 1000
Output
YES
2842545891539
28171911281811000
Input
120
12 1
Output
NO
Tags: brute force, math, number theory, strings
Correct Solution:
```
from math import pow
s=list(input())
a,b=map(int,input().split())
l=len(s)
s1=[0]*(l+1)
s2=[0]*(l+1)
for i in range(l):
s[i]=ord(s[i])-ord('0')
p=1
for i in range(l-1,-1,-1):
s1[i]=(s1[i+1]+s[i]*p)%b
p=(p*10)%b
p=0
for i in range(l-1):
p=(p*10+s[i])%a
if p==0 and s1[i+1]==0 and s[i+1]:
print("YES")
print(''.join(map(str,s[:i+1])))
print(''.join(map(str,s[i+1:])))
exit()
print("NO")
```
| 80,371 | [
0.52685546875,
0.09027099609375,
0.032470703125,
0.42919921875,
-0.1885986328125,
-0.1817626953125,
-0.38330078125,
0.15185546875,
0.1856689453125,
0.8720703125,
0.5732421875,
-0.12939453125,
0.1947021484375,
-0.54638671875,
-0.46337890625,
0.3134765625,
-0.2034912109375,
-0.498046... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarpus participates in a competition for hacking into a new secure messenger. He's almost won.
Having carefully studied the interaction protocol, Polycarpus came to the conclusion that the secret key can be obtained if he properly cuts the public key of the application into two parts. The public key is a long integer which may consist of even a million digits!
Polycarpus needs to find such a way to cut the public key into two nonempty parts, that the first (left) part is divisible by a as a separate number, and the second (right) part is divisible by b as a separate number. Both parts should be positive integers that have no leading zeros. Polycarpus knows values a and b.
Help Polycarpus and find any suitable method to cut the public key.
Input
The first line of the input contains the public key of the messenger β an integer without leading zeroes, its length is in range from 1 to 106 digits. The second line contains a pair of space-separated positive integers a, b (1 β€ a, b β€ 108).
Output
In the first line print "YES" (without the quotes), if the method satisfying conditions above exists. In this case, next print two lines β the left and right parts after the cut. These two parts, being concatenated, must be exactly identical to the public key. The left part must be divisible by a, and the right part must be divisible by b. The two parts must be positive integers having no leading zeros. If there are several answers, print any of them.
If there is no answer, print in a single line "NO" (without the quotes).
Examples
Input
116401024
97 1024
Output
YES
11640
1024
Input
284254589153928171911281811000
1009 1000
Output
YES
2842545891539
28171911281811000
Input
120
12 1
Output
NO
Tags: brute force, math, number theory, strings
Correct Solution:
```
def main():
s, x, pfx = input(), 0, []
a, b = map(int, input().split())
try:
for i, c in enumerate(s, 1):
x = (x * 10 + int(c)) % a
if not x and s[i] != '0':
pfx.append(i)
#print(c,ord(c) - 48)
except IndexError:
pass
x, p, i = 0, 1, len(s)
for j in reversed(pfx):
for i in range(i - 1, j - 1, -1):
x = (x + (int(s[i])) * p) % b
p = p * 10 % b
if not x:
print("YES")
print(s[:i])
print(s[i:])
return
print("NO")
if __name__ == '__main__':
main()
```
| 80,372 | [
0.54248046875,
0.08538818359375,
0.03094482421875,
0.401123046875,
-0.1849365234375,
-0.207275390625,
-0.37255859375,
0.149658203125,
0.17919921875,
0.84033203125,
0.56396484375,
-0.1396484375,
0.221435546875,
-0.5126953125,
-0.50390625,
0.286865234375,
-0.2218017578125,
-0.5219726... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarpus participates in a competition for hacking into a new secure messenger. He's almost won.
Having carefully studied the interaction protocol, Polycarpus came to the conclusion that the secret key can be obtained if he properly cuts the public key of the application into two parts. The public key is a long integer which may consist of even a million digits!
Polycarpus needs to find such a way to cut the public key into two nonempty parts, that the first (left) part is divisible by a as a separate number, and the second (right) part is divisible by b as a separate number. Both parts should be positive integers that have no leading zeros. Polycarpus knows values a and b.
Help Polycarpus and find any suitable method to cut the public key.
Input
The first line of the input contains the public key of the messenger β an integer without leading zeroes, its length is in range from 1 to 106 digits. The second line contains a pair of space-separated positive integers a, b (1 β€ a, b β€ 108).
Output
In the first line print "YES" (without the quotes), if the method satisfying conditions above exists. In this case, next print two lines β the left and right parts after the cut. These two parts, being concatenated, must be exactly identical to the public key. The left part must be divisible by a, and the right part must be divisible by b. The two parts must be positive integers having no leading zeros. If there are several answers, print any of them.
If there is no answer, print in a single line "NO" (without the quotes).
Examples
Input
116401024
97 1024
Output
YES
11640
1024
Input
284254589153928171911281811000
1009 1000
Output
YES
2842545891539
28171911281811000
Input
120
12 1
Output
NO
Tags: brute force, math, number theory, strings
Correct Solution:
```
l = input()
a,b = input().split()
a = int(a)
b= int(b)
n = len(l)
ra = []
rb = [0]*n
nn = ""
f = 0
p = 1
ra.append(int(l[0])%a)
rb[n-1] = (int(l[n-1])%b)
for i in range(1,n-1):
ra.append((ra[i-1]*10+int(l[i]))%a)
for i in range(n-2,-1,-1):
rb[i] = (rb[i+1] + (int(l[i])*p*10)%b)%b
p = (p*10)%b
st = ""
for i in range(n-1):
if(ra[i] ==0 and rb[i+1] == 0 and l[i+1] != "0"):
print("YES")
st += str(''.join(l[:i+1]))+"\n"
st += str(''.join(l[i+1:n]))
break
if(len(st)== 0):
print("NO")
else:
print(st)
```
| 80,373 | [
0.54541015625,
0.09368896484375,
0.030426025390625,
0.41650390625,
-0.1917724609375,
-0.2213134765625,
-0.384765625,
0.14892578125,
0.1763916015625,
0.8564453125,
0.54541015625,
-0.1414794921875,
0.193115234375,
-0.52587890625,
-0.491943359375,
0.301025390625,
-0.2125244140625,
-0.... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarpus participates in a competition for hacking into a new secure messenger. He's almost won.
Having carefully studied the interaction protocol, Polycarpus came to the conclusion that the secret key can be obtained if he properly cuts the public key of the application into two parts. The public key is a long integer which may consist of even a million digits!
Polycarpus needs to find such a way to cut the public key into two nonempty parts, that the first (left) part is divisible by a as a separate number, and the second (right) part is divisible by b as a separate number. Both parts should be positive integers that have no leading zeros. Polycarpus knows values a and b.
Help Polycarpus and find any suitable method to cut the public key.
Input
The first line of the input contains the public key of the messenger β an integer without leading zeroes, its length is in range from 1 to 106 digits. The second line contains a pair of space-separated positive integers a, b (1 β€ a, b β€ 108).
Output
In the first line print "YES" (without the quotes), if the method satisfying conditions above exists. In this case, next print two lines β the left and right parts after the cut. These two parts, being concatenated, must be exactly identical to the public key. The left part must be divisible by a, and the right part must be divisible by b. The two parts must be positive integers having no leading zeros. If there are several answers, print any of them.
If there is no answer, print in a single line "NO" (without the quotes).
Examples
Input
116401024
97 1024
Output
YES
11640
1024
Input
284254589153928171911281811000
1009 1000
Output
YES
2842545891539
28171911281811000
Input
120
12 1
Output
NO
Tags: brute force, math, number theory, strings
Correct Solution:
```
def main():
string = input()
a,b = list(map(int,input().split()))
forward = [-1]*len(string)
backward = [-1]*len(string)
x=1
for i in range(len(string)):
cur = int(string[i])
j = len(string) - i - 1
curBack = int(string[j])
if i==0:
forward[i] = cur%a
backward[j] = curBack%b
else:
forward[i] = ((forward[i-1]*10)%a + cur%a)%a
backward[j] = (backward[j+1] + (curBack*x)%b)%b
x=(x*10)%b
done = 0
for i in range(len(string)-1):
leftMod = forward[i]
rightMod = backward[i+1]
if leftMod==0 and rightMod ==0 and int(string[i+1])!=0:
print("YES")
print(string[:i+1])
print(string[i+1:])
done = 1
break
if done==0:
print("NO")
# print(forward)
# print(backward)
main()
```
| 80,374 | [
0.51416015625,
0.07269287109375,
0.02435302734375,
0.40869140625,
-0.1904296875,
-0.2076416015625,
-0.374755859375,
0.142822265625,
0.1666259765625,
0.8701171875,
0.55224609375,
-0.1368408203125,
0.2060546875,
-0.513671875,
-0.50390625,
0.283935546875,
-0.22900390625,
-0.517578125,... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarpus participates in a competition for hacking into a new secure messenger. He's almost won.
Having carefully studied the interaction protocol, Polycarpus came to the conclusion that the secret key can be obtained if he properly cuts the public key of the application into two parts. The public key is a long integer which may consist of even a million digits!
Polycarpus needs to find such a way to cut the public key into two nonempty parts, that the first (left) part is divisible by a as a separate number, and the second (right) part is divisible by b as a separate number. Both parts should be positive integers that have no leading zeros. Polycarpus knows values a and b.
Help Polycarpus and find any suitable method to cut the public key.
Input
The first line of the input contains the public key of the messenger β an integer without leading zeroes, its length is in range from 1 to 106 digits. The second line contains a pair of space-separated positive integers a, b (1 β€ a, b β€ 108).
Output
In the first line print "YES" (without the quotes), if the method satisfying conditions above exists. In this case, next print two lines β the left and right parts after the cut. These two parts, being concatenated, must be exactly identical to the public key. The left part must be divisible by a, and the right part must be divisible by b. The two parts must be positive integers having no leading zeros. If there are several answers, print any of them.
If there is no answer, print in a single line "NO" (without the quotes).
Examples
Input
116401024
97 1024
Output
YES
11640
1024
Input
284254589153928171911281811000
1009 1000
Output
YES
2842545891539
28171911281811000
Input
120
12 1
Output
NO
Tags: brute force, math, number theory, strings
Correct Solution:
```
l = input()
a,b = input().split()
a = int(a)
b= int(b)
n = len(l)
ra = []
rb = [0]*n
nn = ""
f = 0
p = 1
ra.append(int(l[0])%a)
rb[n-1] = (int(l[n-1])%b)
for i in range(1,n-1):
ra.append((ra[i-1]*10+int(l[i]))%a)
for i in range(n-2,-1,-1):
rb[i] = (rb[i+1] + (int(l[i])*p*10)%b)%b
p = (p*10)%b
for i in range(n-1):
if(ra[i] ==0 and rb[i+1] == 0 and l[i+1] != "0"):
print("YES")
print(l[:i+1])
print(l[i+1:n])
f = 1
break
if(f== 0):
print("NO")
```
| 80,375 | [
0.54541015625,
0.09368896484375,
0.030426025390625,
0.41650390625,
-0.1917724609375,
-0.2213134765625,
-0.384765625,
0.14892578125,
0.1763916015625,
0.8564453125,
0.54541015625,
-0.1414794921875,
0.193115234375,
-0.52587890625,
-0.491943359375,
0.301025390625,
-0.2125244140625,
-0.... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarpus participates in a competition for hacking into a new secure messenger. He's almost won.
Having carefully studied the interaction protocol, Polycarpus came to the conclusion that the secret key can be obtained if he properly cuts the public key of the application into two parts. The public key is a long integer which may consist of even a million digits!
Polycarpus needs to find such a way to cut the public key into two nonempty parts, that the first (left) part is divisible by a as a separate number, and the second (right) part is divisible by b as a separate number. Both parts should be positive integers that have no leading zeros. Polycarpus knows values a and b.
Help Polycarpus and find any suitable method to cut the public key.
Input
The first line of the input contains the public key of the messenger β an integer without leading zeroes, its length is in range from 1 to 106 digits. The second line contains a pair of space-separated positive integers a, b (1 β€ a, b β€ 108).
Output
In the first line print "YES" (without the quotes), if the method satisfying conditions above exists. In this case, next print two lines β the left and right parts after the cut. These two parts, being concatenated, must be exactly identical to the public key. The left part must be divisible by a, and the right part must be divisible by b. The two parts must be positive integers having no leading zeros. If there are several answers, print any of them.
If there is no answer, print in a single line "NO" (without the quotes).
Examples
Input
116401024
97 1024
Output
YES
11640
1024
Input
284254589153928171911281811000
1009 1000
Output
YES
2842545891539
28171911281811000
Input
120
12 1
Output
NO
Tags: brute force, math, number theory, strings
Correct Solution:
```
import sys
from math import log2,floor,ceil,sqrt
# import bisect
# from collections import deque
# from types import GeneratorType
# def bootstrap(func, stack=[]):
# def wrapped_function(*args, **kwargs):
# if stack:
# return func(*args, **kwargs)
# else:
# call = func(*args, **kwargs)
# while True:
# if type(call) is GeneratorType:
# stack.append(call)
# call = next(call)
# else:
# stack.pop()
# if not stack:
# break
# call = stack[-1].send(call)
# return call
# return wrapped_function
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()
n = len(s)
dp1 = [0]*(n+1)
dp2 = [0]*(n+1)
a,b = Ri()
for i in range(n):
dp1[i+1] = ((dp1[i]*10)%a + int(s[i]))%a
p = 1
for i in range(n-1,-1,-1):
dp2[i] = (dp2[i+1] + (p * int(s[i]) ) %b ) %b
p = (p * 10)%b
flag = -1
for i in range(0,n-1):
if s[i+1] != '0' and dp1[i+1] == 0 and dp2[i+1] == 0:
flag = i
break
if flag != -1:
YES()
print(s[:flag+1])
print(s[flag+1: ])
else:
NO()
```
| 80,376 | [
0.521484375,
0.11968994140625,
0.026885986328125,
0.445068359375,
-0.1722412109375,
-0.2186279296875,
-0.351806640625,
0.1893310546875,
0.14501953125,
0.86962890625,
0.5771484375,
-0.1417236328125,
0.216064453125,
-0.46435546875,
-0.513671875,
0.339599609375,
-0.2314453125,
-0.5415... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarpus participates in a competition for hacking into a new secure messenger. He's almost won.
Having carefully studied the interaction protocol, Polycarpus came to the conclusion that the secret key can be obtained if he properly cuts the public key of the application into two parts. The public key is a long integer which may consist of even a million digits!
Polycarpus needs to find such a way to cut the public key into two nonempty parts, that the first (left) part is divisible by a as a separate number, and the second (right) part is divisible by b as a separate number. Both parts should be positive integers that have no leading zeros. Polycarpus knows values a and b.
Help Polycarpus and find any suitable method to cut the public key.
Input
The first line of the input contains the public key of the messenger β an integer without leading zeroes, its length is in range from 1 to 106 digits. The second line contains a pair of space-separated positive integers a, b (1 β€ a, b β€ 108).
Output
In the first line print "YES" (without the quotes), if the method satisfying conditions above exists. In this case, next print two lines β the left and right parts after the cut. These two parts, being concatenated, must be exactly identical to the public key. The left part must be divisible by a, and the right part must be divisible by b. The two parts must be positive integers having no leading zeros. If there are several answers, print any of them.
If there is no answer, print in a single line "NO" (without the quotes).
Examples
Input
116401024
97 1024
Output
YES
11640
1024
Input
284254589153928171911281811000
1009 1000
Output
YES
2842545891539
28171911281811000
Input
120
12 1
Output
NO
Tags: brute force, math, number theory, strings
Correct Solution:
```
# import sys
# sys.stdin = open("F:\\Scripts\\input","r")
# sys.stdout = open("F:\\Scripts\\output","w")
MOD = 10**9 + 7
I = lambda:list(map(int,input().split()))
s = input()
a , b = I()
n = len(s)
x = [0]*n
y = [0]*n
x[0] = int(s[0])%a
y[n - 1] = int(s[n - 1])%b
p = 10%b
for i in range(1,n):
x[i] = (x[i-1]*10 + int(s[i]))%a
y[n - i - 1] = (int(s[n - i - 1])*p + y[n - i])%b
p *=10
p %= b
for i in range(n-1):
if not x[i] and not y[i+1] and (s[i+1] != '0'):
print("YES",s[:i+1],s[i+1:],sep = '\n')
break
else:
print("NO")
```
| 80,377 | [
0.51220703125,
0.10650634765625,
0.0423583984375,
0.44775390625,
-0.1883544921875,
-0.231689453125,
-0.42333984375,
0.1468505859375,
0.1236572265625,
0.84619140625,
0.5244140625,
-0.14794921875,
0.197021484375,
-0.458251953125,
-0.5390625,
0.34619140625,
-0.1754150390625,
-0.517089... | 24 |
Evaluate the correctness of the submitted Python 2 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarpus participates in a competition for hacking into a new secure messenger. He's almost won.
Having carefully studied the interaction protocol, Polycarpus came to the conclusion that the secret key can be obtained if he properly cuts the public key of the application into two parts. The public key is a long integer which may consist of even a million digits!
Polycarpus needs to find such a way to cut the public key into two nonempty parts, that the first (left) part is divisible by a as a separate number, and the second (right) part is divisible by b as a separate number. Both parts should be positive integers that have no leading zeros. Polycarpus knows values a and b.
Help Polycarpus and find any suitable method to cut the public key.
Input
The first line of the input contains the public key of the messenger β an integer without leading zeroes, its length is in range from 1 to 106 digits. The second line contains a pair of space-separated positive integers a, b (1 β€ a, b β€ 108).
Output
In the first line print "YES" (without the quotes), if the method satisfying conditions above exists. In this case, next print two lines β the left and right parts after the cut. These two parts, being concatenated, must be exactly identical to the public key. The left part must be divisible by a, and the right part must be divisible by b. The two parts must be positive integers having no leading zeros. If there are several answers, print any of them.
If there is no answer, print in a single line "NO" (without the quotes).
Examples
Input
116401024
97 1024
Output
YES
11640
1024
Input
284254589153928171911281811000
1009 1000
Output
YES
2842545891539
28171911281811000
Input
120
12 1
Output
NO
Submitted Solution:
```
#Run code in language PyPy2
#change input() in Python 3 become raw_input() like python2 then submit
#Add this code prefix of your code
import atexit
import io
import sys
buff = io.BytesIO()
sys.stdout = buff
@atexit.register
def write():
sys.__stdout__.write(buff.getvalue())
# code
R = raw_input
n = str(R())
a,b = map(int,R().split())
def rig():
ar = []
ar.append(0)
q = 1
for i in n[::-1]:
ar.append((ar[-1]%b+q*(ord(i)&15)%b)%b)
q = q*10%b
return ar
def lef():
ar = []
ar.append(0)
for i in range(0,len(n)):
ar.append(((ar[-1]*10)%a+(ord(n[i])&15)%a)%a)
return ar
def res():
x = lef()
y = rig()
for i in range(1,len(n)):
if(x[i]+y[~(i)]<1 and i < len(n) and n[i]>'0'):
return "YES\n%s\n%s"%(n[:(i)],n[(i):])
return "NO"
print(res())
```
Yes
| 80,378 | [
0.537109375,
0.1629638671875,
-0.168212890625,
0.44873046875,
-0.287353515625,
-0.1429443359375,
-0.450927734375,
0.249267578125,
0.253173828125,
0.90478515625,
0.49072265625,
-0.2255859375,
0.27587890625,
-0.4443359375,
-0.5859375,
0.3046875,
-0.2489013671875,
-0.638671875,
-0.0... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarpus participates in a competition for hacking into a new secure messenger. He's almost won.
Having carefully studied the interaction protocol, Polycarpus came to the conclusion that the secret key can be obtained if he properly cuts the public key of the application into two parts. The public key is a long integer which may consist of even a million digits!
Polycarpus needs to find such a way to cut the public key into two nonempty parts, that the first (left) part is divisible by a as a separate number, and the second (right) part is divisible by b as a separate number. Both parts should be positive integers that have no leading zeros. Polycarpus knows values a and b.
Help Polycarpus and find any suitable method to cut the public key.
Input
The first line of the input contains the public key of the messenger β an integer without leading zeroes, its length is in range from 1 to 106 digits. The second line contains a pair of space-separated positive integers a, b (1 β€ a, b β€ 108).
Output
In the first line print "YES" (without the quotes), if the method satisfying conditions above exists. In this case, next print two lines β the left and right parts after the cut. These two parts, being concatenated, must be exactly identical to the public key. The left part must be divisible by a, and the right part must be divisible by b. The two parts must be positive integers having no leading zeros. If there are several answers, print any of them.
If there is no answer, print in a single line "NO" (without the quotes).
Examples
Input
116401024
97 1024
Output
YES
11640
1024
Input
284254589153928171911281811000
1009 1000
Output
YES
2842545891539
28171911281811000
Input
120
12 1
Output
NO
Submitted Solution:
```
import os
import sys
from io import BytesIO, IOBase
import math
def main():
pass
# region fastio
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
def exponentiation(bas, exp,N):
t = 1
while (exp > 0):
if (exp % 2 != 0):
t = (t * bas) % N
bas = (bas * bas) % N
exp = int(exp / 2)
return t % N
s=input()
a,b=map(int,input().split())
pre=[0]
suf=[0]
n=len(s)
for i in range(0,n):
v=int(s[i])
pre.append((v+pre[i]*10)%a)
tp=1
for i in range(n-1,-1,-1):
v = int(s[i])
suf.append((v*tp+suf[n-i-1])%b)
tp=(tp*10)%b
#print(pre,suf)
pre.pop()
pre.pop(0)
suf.pop()
suf.pop(0)
suf.reverse()
#print(pre,suf)
ci=-1
for i in range(0,n-1):
if pre[i]==0 and suf[i]==0:
if s[i+1]!='0':
ci=i+1
break
if ci==-1:
print("NO")
else:
print("YES")
print(s[:ci]+"\n"+s[ci:])
```
Yes
| 80,379 | [
0.5888671875,
0.1534423828125,
-0.09210205078125,
0.420654296875,
-0.237548828125,
-0.14697265625,
-0.41064453125,
0.267333984375,
0.2210693359375,
0.86669921875,
0.5830078125,
-0.1474609375,
0.226806640625,
-0.55126953125,
-0.55419921875,
0.2822265625,
-0.1805419921875,
-0.5957031... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarpus participates in a competition for hacking into a new secure messenger. He's almost won.
Having carefully studied the interaction protocol, Polycarpus came to the conclusion that the secret key can be obtained if he properly cuts the public key of the application into two parts. The public key is a long integer which may consist of even a million digits!
Polycarpus needs to find such a way to cut the public key into two nonempty parts, that the first (left) part is divisible by a as a separate number, and the second (right) part is divisible by b as a separate number. Both parts should be positive integers that have no leading zeros. Polycarpus knows values a and b.
Help Polycarpus and find any suitable method to cut the public key.
Input
The first line of the input contains the public key of the messenger β an integer without leading zeroes, its length is in range from 1 to 106 digits. The second line contains a pair of space-separated positive integers a, b (1 β€ a, b β€ 108).
Output
In the first line print "YES" (without the quotes), if the method satisfying conditions above exists. In this case, next print two lines β the left and right parts after the cut. These two parts, being concatenated, must be exactly identical to the public key. The left part must be divisible by a, and the right part must be divisible by b. The two parts must be positive integers having no leading zeros. If there are several answers, print any of them.
If there is no answer, print in a single line "NO" (without the quotes).
Examples
Input
116401024
97 1024
Output
YES
11640
1024
Input
284254589153928171911281811000
1009 1000
Output
YES
2842545891539
28171911281811000
Input
120
12 1
Output
NO
Submitted Solution:
```
import sys
#sys.stdin, sys.stdout = open("input.txt", "r"), open("output.txt", "w")
s = input()
n = len(s)
a, b = map(int, input().split())
pref, suff = [0] * n, [0] * n
curr = 0
for i in range(n):
pref[i] = ((curr * 10) % a + int(s[i])) % a
curr = pref[i]
curr = 0
for i in reversed(range(n)):
suff[i] = ((int(s[i]) * pow(10, n - i - 1, b)) % b + curr) % b
curr = suff[i]
for i in range(n-1):
if pref[i] == suff[i+1] == 0 and s[i+1] != '0':
print("YES")
print(s[:i+1])
print(s[i+1:])
exit(0)
print("NO")
```
Yes
| 80,380 | [
0.609375,
0.1854248046875,
-0.053436279296875,
0.37451171875,
-0.25341796875,
-0.12237548828125,
-0.4775390625,
0.2724609375,
0.154052734375,
0.8056640625,
0.5341796875,
-0.194091796875,
0.216064453125,
-0.51806640625,
-0.5576171875,
0.24072265625,
-0.1893310546875,
-0.53271484375,... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarpus participates in a competition for hacking into a new secure messenger. He's almost won.
Having carefully studied the interaction protocol, Polycarpus came to the conclusion that the secret key can be obtained if he properly cuts the public key of the application into two parts. The public key is a long integer which may consist of even a million digits!
Polycarpus needs to find such a way to cut the public key into two nonempty parts, that the first (left) part is divisible by a as a separate number, and the second (right) part is divisible by b as a separate number. Both parts should be positive integers that have no leading zeros. Polycarpus knows values a and b.
Help Polycarpus and find any suitable method to cut the public key.
Input
The first line of the input contains the public key of the messenger β an integer without leading zeroes, its length is in range from 1 to 106 digits. The second line contains a pair of space-separated positive integers a, b (1 β€ a, b β€ 108).
Output
In the first line print "YES" (without the quotes), if the method satisfying conditions above exists. In this case, next print two lines β the left and right parts after the cut. These two parts, being concatenated, must be exactly identical to the public key. The left part must be divisible by a, and the right part must be divisible by b. The two parts must be positive integers having no leading zeros. If there are several answers, print any of them.
If there is no answer, print in a single line "NO" (without the quotes).
Examples
Input
116401024
97 1024
Output
YES
11640
1024
Input
284254589153928171911281811000
1009 1000
Output
YES
2842545891539
28171911281811000
Input
120
12 1
Output
NO
Submitted Solution:
```
s = input()
a, b = map(int, input().split())
n = len(s)
flag = 0
p = 0
pfx = []
for i,c in enumerate(s, 1):
p = (p * 10 + int(c))%a
if(i < n and p == 0 and s[i] != '0'):
pfx.append(i)
q = 0
p = 1
i = len(s)
for j in reversed(pfx):
for i in range(i-1, j -1, -1):
q = (q + int(s[i]) * p) % b
p = p * 10 % b
if not q:
print("YES")
print(s[:i])
print(s[i:])
exit()
print("NO")
```
Yes
| 80,381 | [
0.6279296875,
0.1549072265625,
-0.08026123046875,
0.370361328125,
-0.248779296875,
-0.15185546875,
-0.40087890625,
0.27978515625,
0.169677734375,
0.828125,
0.59619140625,
-0.1656494140625,
0.2276611328125,
-0.56689453125,
-0.56103515625,
0.2279052734375,
-0.213623046875,
-0.5341796... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarpus participates in a competition for hacking into a new secure messenger. He's almost won.
Having carefully studied the interaction protocol, Polycarpus came to the conclusion that the secret key can be obtained if he properly cuts the public key of the application into two parts. The public key is a long integer which may consist of even a million digits!
Polycarpus needs to find such a way to cut the public key into two nonempty parts, that the first (left) part is divisible by a as a separate number, and the second (right) part is divisible by b as a separate number. Both parts should be positive integers that have no leading zeros. Polycarpus knows values a and b.
Help Polycarpus and find any suitable method to cut the public key.
Input
The first line of the input contains the public key of the messenger β an integer without leading zeroes, its length is in range from 1 to 106 digits. The second line contains a pair of space-separated positive integers a, b (1 β€ a, b β€ 108).
Output
In the first line print "YES" (without the quotes), if the method satisfying conditions above exists. In this case, next print two lines β the left and right parts after the cut. These two parts, being concatenated, must be exactly identical to the public key. The left part must be divisible by a, and the right part must be divisible by b. The two parts must be positive integers having no leading zeros. If there are several answers, print any of them.
If there is no answer, print in a single line "NO" (without the quotes).
Examples
Input
116401024
97 1024
Output
YES
11640
1024
Input
284254589153928171911281811000
1009 1000
Output
YES
2842545891539
28171911281811000
Input
120
12 1
Output
NO
Submitted Solution:
```
#zdelano dobrim chelovekom vnizy :D
s, x, pfx = input(), 0, []
a, b = map(int, input().split())
try:
for i, c in enumerate(s, 1):
x = (x * 10 + ord(c)-48 ) % a
if not x and s[i] != '0':
pfx.append(i)
except IndexError:
pass
x, p, i = 0, 1, len(s)
for stop in reversed(pfx):
for i in range(i - 1, stop - 1, -1):
x = (x + (ord(s[i])-48) * p) % b
p = p * 10 % b
if not x:
print("YES")
print(s[:i])
print(s[i:])
exit()
print("NO")
```
Yes
| 80,382 | [
0.62548828125,
0.1727294921875,
-0.0758056640625,
0.36181640625,
-0.26708984375,
-0.1492919921875,
-0.4287109375,
0.27392578125,
0.1717529296875,
0.8115234375,
0.5810546875,
-0.186767578125,
0.2139892578125,
-0.54931640625,
-0.55908203125,
0.2125244140625,
-0.19677734375,
-0.526855... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarpus participates in a competition for hacking into a new secure messenger. He's almost won.
Having carefully studied the interaction protocol, Polycarpus came to the conclusion that the secret key can be obtained if he properly cuts the public key of the application into two parts. The public key is a long integer which may consist of even a million digits!
Polycarpus needs to find such a way to cut the public key into two nonempty parts, that the first (left) part is divisible by a as a separate number, and the second (right) part is divisible by b as a separate number. Both parts should be positive integers that have no leading zeros. Polycarpus knows values a and b.
Help Polycarpus and find any suitable method to cut the public key.
Input
The first line of the input contains the public key of the messenger β an integer without leading zeroes, its length is in range from 1 to 106 digits. The second line contains a pair of space-separated positive integers a, b (1 β€ a, b β€ 108).
Output
In the first line print "YES" (without the quotes), if the method satisfying conditions above exists. In this case, next print two lines β the left and right parts after the cut. These two parts, being concatenated, must be exactly identical to the public key. The left part must be divisible by a, and the right part must be divisible by b. The two parts must be positive integers having no leading zeros. If there are several answers, print any of them.
If there is no answer, print in a single line "NO" (without the quotes).
Examples
Input
116401024
97 1024
Output
YES
11640
1024
Input
284254589153928171911281811000
1009 1000
Output
YES
2842545891539
28171911281811000
Input
120
12 1
Output
NO
Submitted Solution:
```
n=input()
a,b=input().split()
a=int(a)
b=int(b)
pos_k=0
output_k=0
output_l=0
k=0
number=0
while k<len(n):
number=(number*10)+int(n[k])
if number%a==0:
pos_k=k
output_k=number
k=k+1
k=pos_k+1
number=0
while k<len(n):
number=(number*10)+int(n[k])
if number%b==0:
output_l=number
k=k+1
if number==0:
print('No')
else:
print("YES")
print(output_k)
print(output_l)
```
No
| 80,383 | [
0.6376953125,
0.1856689453125,
-0.0948486328125,
0.374755859375,
-0.252197265625,
-0.145751953125,
-0.425048828125,
0.279541015625,
0.1748046875,
0.845703125,
0.6044921875,
-0.154541015625,
0.2037353515625,
-0.55615234375,
-0.55810546875,
0.2430419921875,
-0.2032470703125,
-0.55273... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarpus participates in a competition for hacking into a new secure messenger. He's almost won.
Having carefully studied the interaction protocol, Polycarpus came to the conclusion that the secret key can be obtained if he properly cuts the public key of the application into two parts. The public key is a long integer which may consist of even a million digits!
Polycarpus needs to find such a way to cut the public key into two nonempty parts, that the first (left) part is divisible by a as a separate number, and the second (right) part is divisible by b as a separate number. Both parts should be positive integers that have no leading zeros. Polycarpus knows values a and b.
Help Polycarpus and find any suitable method to cut the public key.
Input
The first line of the input contains the public key of the messenger β an integer without leading zeroes, its length is in range from 1 to 106 digits. The second line contains a pair of space-separated positive integers a, b (1 β€ a, b β€ 108).
Output
In the first line print "YES" (without the quotes), if the method satisfying conditions above exists. In this case, next print two lines β the left and right parts after the cut. These two parts, being concatenated, must be exactly identical to the public key. The left part must be divisible by a, and the right part must be divisible by b. The two parts must be positive integers having no leading zeros. If there are several answers, print any of them.
If there is no answer, print in a single line "NO" (without the quotes).
Examples
Input
116401024
97 1024
Output
YES
11640
1024
Input
284254589153928171911281811000
1009 1000
Output
YES
2842545891539
28171911281811000
Input
120
12 1
Output
NO
Submitted Solution:
```
n=list(map(int,list(input())))
a,b=map(int,input().split())
x=n[0]
res=[-1]*len(n)
for i in range(1,len(n)):
if(x%a==0):
res[i-1]=0
x=x*10+n[i]
# print(res)
flag=-1
x=n[-1]
for i in range(len(n)-2,-1,-1):
if(int(x)!=0 and int(x)%b==0):
if(i>0 and res[i-1]==0):
# print(i)
flag=i
break
x=str(n[i])+str(x)
if(flag==-1):
print("NO")
else:
r1,r2=0,0
print("YES")
for i in range(0,flag):
r1=r1*10+n[i]
for i in range(flag,len(n)):
r2=r2*10+n[i]
print(r1)
print(r2)
```
No
| 80,384 | [
0.607421875,
0.172607421875,
-0.087890625,
0.353759765625,
-0.2415771484375,
-0.1358642578125,
-0.416259765625,
0.2802734375,
0.159912109375,
0.85302734375,
0.5908203125,
-0.16064453125,
0.2232666015625,
-0.56005859375,
-0.533203125,
0.2301025390625,
-0.2100830078125,
-0.521484375,... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarpus participates in a competition for hacking into a new secure messenger. He's almost won.
Having carefully studied the interaction protocol, Polycarpus came to the conclusion that the secret key can be obtained if he properly cuts the public key of the application into two parts. The public key is a long integer which may consist of even a million digits!
Polycarpus needs to find such a way to cut the public key into two nonempty parts, that the first (left) part is divisible by a as a separate number, and the second (right) part is divisible by b as a separate number. Both parts should be positive integers that have no leading zeros. Polycarpus knows values a and b.
Help Polycarpus and find any suitable method to cut the public key.
Input
The first line of the input contains the public key of the messenger β an integer without leading zeroes, its length is in range from 1 to 106 digits. The second line contains a pair of space-separated positive integers a, b (1 β€ a, b β€ 108).
Output
In the first line print "YES" (without the quotes), if the method satisfying conditions above exists. In this case, next print two lines β the left and right parts after the cut. These two parts, being concatenated, must be exactly identical to the public key. The left part must be divisible by a, and the right part must be divisible by b. The two parts must be positive integers having no leading zeros. If there are several answers, print any of them.
If there is no answer, print in a single line "NO" (without the quotes).
Examples
Input
116401024
97 1024
Output
YES
11640
1024
Input
284254589153928171911281811000
1009 1000
Output
YES
2842545891539
28171911281811000
Input
120
12 1
Output
NO
Submitted Solution:
```
s = input()
n,m = map(int, input().split())
l = len(s)
a,p1,p2 = 0,0,0
f = 1
for i in range(l):
a = a*10%n + int(s[i])%n
a = a%n
if a==0:
p1=i
f=0
#print(a)
elif f==0 and a!=0:
break
a = 0
for i in range(p1+1,l):
a = a*10%m + int(s[i])%m
a = a%m
if a==0:
p2=i
if p2+1<l:
print("NO")
exit()
if p2==0:
print("NO")
exit()
print(s[:p1+1])
print(s[p1+1:])
```
No
| 80,385 | [
0.62744140625,
0.1866455078125,
-0.0869140625,
0.366455078125,
-0.2445068359375,
-0.134521484375,
-0.425048828125,
0.27685546875,
0.1614990234375,
0.82470703125,
0.59130859375,
-0.17333984375,
0.2125244140625,
-0.5625,
-0.5390625,
0.2374267578125,
-0.20556640625,
-0.52197265625,
... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarpus participates in a competition for hacking into a new secure messenger. He's almost won.
Having carefully studied the interaction protocol, Polycarpus came to the conclusion that the secret key can be obtained if he properly cuts the public key of the application into two parts. The public key is a long integer which may consist of even a million digits!
Polycarpus needs to find such a way to cut the public key into two nonempty parts, that the first (left) part is divisible by a as a separate number, and the second (right) part is divisible by b as a separate number. Both parts should be positive integers that have no leading zeros. Polycarpus knows values a and b.
Help Polycarpus and find any suitable method to cut the public key.
Input
The first line of the input contains the public key of the messenger β an integer without leading zeroes, its length is in range from 1 to 106 digits. The second line contains a pair of space-separated positive integers a, b (1 β€ a, b β€ 108).
Output
In the first line print "YES" (without the quotes), if the method satisfying conditions above exists. In this case, next print two lines β the left and right parts after the cut. These two parts, being concatenated, must be exactly identical to the public key. The left part must be divisible by a, and the right part must be divisible by b. The two parts must be positive integers having no leading zeros. If there are several answers, print any of them.
If there is no answer, print in a single line "NO" (without the quotes).
Examples
Input
116401024
97 1024
Output
YES
11640
1024
Input
284254589153928171911281811000
1009 1000
Output
YES
2842545891539
28171911281811000
Input
120
12 1
Output
NO
Submitted Solution:
```
'''
116401024
97 1024
'''
s=input().rstrip()
x=list(s)
o=input().rstrip().split(' ')
AA=int(o[0])
BB=int(o[1])
G=0;
for i in range(1,len(x)-1):
A=''.join(x[0:i])
B=''.join(x[i:])
if int(A)%AA==0 and int(B)%BB==0 and int(A[0])!=0 and int(B[0])!=0:
G=1;
break;
if G==0:
print("NO")
else:
print("YES")
print(A)
print(B)
```
No
| 80,386 | [
0.62255859375,
0.165771484375,
-0.0797119140625,
0.3720703125,
-0.248291015625,
-0.140380859375,
-0.4365234375,
0.267578125,
0.186279296875,
0.81005859375,
0.6083984375,
-0.1873779296875,
0.19873046875,
-0.56103515625,
-0.52978515625,
0.23046875,
-0.2208251953125,
-0.505859375,
-... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp is going to participate in the contest. It starts at h_1:m_1 and ends at h_2:m_2. It is guaranteed that the contest lasts an even number of minutes (i.e. m_1 \% 2 = m_2 \% 2, where x \% y is x modulo y). It is also guaranteed that the entire contest is held during a single day. And finally it is guaranteed that the contest lasts at least two minutes.
Polycarp wants to know the time of the midpoint of the contest. For example, if the contest lasts from 10:00 to 11:00 then the answer is 10:30, if the contest lasts from 11:10 to 11:12 then the answer is 11:11.
Input
The first line of the input contains two integers h_1 and m_1 in the format hh:mm.
The second line of the input contains two integers h_2 and m_2 in the same format (hh:mm).
It is guaranteed that 0 β€ h_1, h_2 β€ 23 and 0 β€ m_1, m_2 β€ 59.
It is guaranteed that the contest lasts an even number of minutes (i.e. m_1 \% 2 = m_2 \% 2, where x \% y is x modulo y). It is also guaranteed that the entire contest is held during a single day. And finally it is guaranteed that the contest lasts at least two minutes.
Output
Print two integers h_3 and m_3 (0 β€ h_3 β€ 23, 0 β€ m_3 β€ 59) corresponding to the midpoint of the contest in the format hh:mm. Print each number as exactly two digits (prepend a number with leading zero if needed), separate them with ':'.
Examples
Input
10:00
11:00
Output
10:30
Input
11:10
11:12
Output
11:11
Input
01:02
03:02
Output
02:02
Tags: implementation
Correct Solution:
```
h1,m1=map(int , input().split(":"))
h2,m2=map(int , input().split(":"))
if(m1>m2):
m_diff=(h2-h1-1)*60+60-m1+m2
else:
m_diff=(h2-h1)*60+abs(m2-m1)
#print(m_diff)
m_diff=m_diff//2
hr=m_diff//60
miin=m_diff%60
h=h1+hr
m=m1+miin
if(m>=60):
if(m==60):
h=h+1
m11="00"
if(m>60):
h=h+1
m=m-60
m11=str(m)
else:
m11=str(m)
if(m==0 or m==1 or m==2 or m==3 or m==4 or m==5 or m==6 or m==7 or m==8 or m==9 ):
if(m==1):
m11="01"
if(m==2):
m11="02"
if(m==3):
m11="03"
if(m==4):
m11="04"
if(m==5):
m11="05"
if(m==6):
m11="06"
if(m==7):
m11="07"
if(m==8):
m11="08"
if(m==9):
m11="09"
if(m==0):
m11="00"
if(h==0 or h==1 or h==2 or h==3 or h==4 or h==5 or h==6 or h==7 or h==8 or h==9 ):
if(h==1):
h11="01"
if(h==2):
h11="02"
if(h==3):
h11="03"
if(h==4):
h11="04"
if(h==5):
h11="05"
if(h==6):
h11="06"
if(h==7):
h11="07"
if(h==8):
h11="08"
if(h==9):
h11="09"
if(h==0):
h11="00"
else:
h11=str(h)
print(h11,end="")
print(":",end="")
print(m11,end="")
```
| 80,853 | [
0.4287109375,
0.359619140625,
0.0849609375,
-0.062225341796875,
-0.412353515625,
-0.22802734375,
-0.46923828125,
-0.08917236328125,
0.309326171875,
0.7314453125,
0.5341796875,
-0.049591064453125,
0.1402587890625,
-0.9912109375,
-0.437255859375,
-0.12744140625,
-0.37841796875,
-0.68... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp is going to participate in the contest. It starts at h_1:m_1 and ends at h_2:m_2. It is guaranteed that the contest lasts an even number of minutes (i.e. m_1 \% 2 = m_2 \% 2, where x \% y is x modulo y). It is also guaranteed that the entire contest is held during a single day. And finally it is guaranteed that the contest lasts at least two minutes.
Polycarp wants to know the time of the midpoint of the contest. For example, if the contest lasts from 10:00 to 11:00 then the answer is 10:30, if the contest lasts from 11:10 to 11:12 then the answer is 11:11.
Input
The first line of the input contains two integers h_1 and m_1 in the format hh:mm.
The second line of the input contains two integers h_2 and m_2 in the same format (hh:mm).
It is guaranteed that 0 β€ h_1, h_2 β€ 23 and 0 β€ m_1, m_2 β€ 59.
It is guaranteed that the contest lasts an even number of minutes (i.e. m_1 \% 2 = m_2 \% 2, where x \% y is x modulo y). It is also guaranteed that the entire contest is held during a single day. And finally it is guaranteed that the contest lasts at least two minutes.
Output
Print two integers h_3 and m_3 (0 β€ h_3 β€ 23, 0 β€ m_3 β€ 59) corresponding to the midpoint of the contest in the format hh:mm. Print each number as exactly two digits (prepend a number with leading zero if needed), separate them with ':'.
Examples
Input
10:00
11:00
Output
10:30
Input
11:10
11:12
Output
11:11
Input
01:02
03:02
Output
02:02
Tags: implementation
Correct Solution:
```
h1,m1=map(int,input().split(':'))
h2,m2=map(int,input().split(':'))
tmin=((h2*60+m2)-(h1*60+m1))
h3=h1+(m1+tmin//2)//60
m3=(m1+tmin//2)%60
h3='0'+str(h3) if len(str(h3))==1 else str(h3)
m3='0'+str(m3) if len(str(m3))==1 else str(m3)
print(h3+':'+m3)
```
| 80,854 | [
0.465576171875,
0.357421875,
0.09039306640625,
-0.064208984375,
-0.418701171875,
-0.2376708984375,
-0.460693359375,
-0.06292724609375,
0.300048828125,
0.64404296875,
0.53515625,
-0.0648193359375,
0.10186767578125,
-0.9599609375,
-0.481689453125,
-0.10736083984375,
-0.3369140625,
-0... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp is going to participate in the contest. It starts at h_1:m_1 and ends at h_2:m_2. It is guaranteed that the contest lasts an even number of minutes (i.e. m_1 \% 2 = m_2 \% 2, where x \% y is x modulo y). It is also guaranteed that the entire contest is held during a single day. And finally it is guaranteed that the contest lasts at least two minutes.
Polycarp wants to know the time of the midpoint of the contest. For example, if the contest lasts from 10:00 to 11:00 then the answer is 10:30, if the contest lasts from 11:10 to 11:12 then the answer is 11:11.
Input
The first line of the input contains two integers h_1 and m_1 in the format hh:mm.
The second line of the input contains two integers h_2 and m_2 in the same format (hh:mm).
It is guaranteed that 0 β€ h_1, h_2 β€ 23 and 0 β€ m_1, m_2 β€ 59.
It is guaranteed that the contest lasts an even number of minutes (i.e. m_1 \% 2 = m_2 \% 2, where x \% y is x modulo y). It is also guaranteed that the entire contest is held during a single day. And finally it is guaranteed that the contest lasts at least two minutes.
Output
Print two integers h_3 and m_3 (0 β€ h_3 β€ 23, 0 β€ m_3 β€ 59) corresponding to the midpoint of the contest in the format hh:mm. Print each number as exactly two digits (prepend a number with leading zero if needed), separate them with ':'.
Examples
Input
10:00
11:00
Output
10:30
Input
11:10
11:12
Output
11:11
Input
01:02
03:02
Output
02:02
Tags: implementation
Correct Solution:
```
a = input()
b = input()
arr = [0] * 5
brr = [0] * 5
i = -1
for char in a:
i += 1
arr[i] = char
i = -1
for char in b:
i += 1
brr[i] = char
c = (int(arr[0] + arr[1]) + int(brr[0] + brr[1]))//2
g = (int(arr[3] + arr[4]) + int(brr[3] + brr[4]))/2
if (int(arr[0] + arr[1]) + int(brr[0] + brr[1]))%2 > 0:
g += 30
if g >= 60:
c += 1
g -= 60
g = int(g)
if c < 10:
c = str(0) + str(c)
if g < 10:
g = str(0) + str(g)
print(c,":",g,sep ='')
```
| 80,855 | [
0.421142578125,
0.306396484375,
0.14892578125,
-0.0267333984375,
-0.390625,
-0.224609375,
-0.404541015625,
-0.167724609375,
0.29541015625,
0.64111328125,
0.55419921875,
-0.093017578125,
0.07373046875,
-1.0439453125,
-0.5439453125,
-0.153076171875,
-0.37353515625,
-0.685546875,
-0... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp is going to participate in the contest. It starts at h_1:m_1 and ends at h_2:m_2. It is guaranteed that the contest lasts an even number of minutes (i.e. m_1 \% 2 = m_2 \% 2, where x \% y is x modulo y). It is also guaranteed that the entire contest is held during a single day. And finally it is guaranteed that the contest lasts at least two minutes.
Polycarp wants to know the time of the midpoint of the contest. For example, if the contest lasts from 10:00 to 11:00 then the answer is 10:30, if the contest lasts from 11:10 to 11:12 then the answer is 11:11.
Input
The first line of the input contains two integers h_1 and m_1 in the format hh:mm.
The second line of the input contains two integers h_2 and m_2 in the same format (hh:mm).
It is guaranteed that 0 β€ h_1, h_2 β€ 23 and 0 β€ m_1, m_2 β€ 59.
It is guaranteed that the contest lasts an even number of minutes (i.e. m_1 \% 2 = m_2 \% 2, where x \% y is x modulo y). It is also guaranteed that the entire contest is held during a single day. And finally it is guaranteed that the contest lasts at least two minutes.
Output
Print two integers h_3 and m_3 (0 β€ h_3 β€ 23, 0 β€ m_3 β€ 59) corresponding to the midpoint of the contest in the format hh:mm. Print each number as exactly two digits (prepend a number with leading zero if needed), separate them with ':'.
Examples
Input
10:00
11:00
Output
10:30
Input
11:10
11:12
Output
11:11
Input
01:02
03:02
Output
02:02
Tags: implementation
Correct Solution:
```
while(True):
try:
a,b=map(int,input().split(":"))
c,d=map(int,input().split(":"))
except EOFError:
break
x=a*60+b
y=c*60+d
br=(y-x)//2
# print(x,y,br)
h=a+br//60
m=b+br%60
if(m>=60):
m=m%60
h+=1
if(len(str(h))==2 and len(str(m))==2):
print("{}:{}".format(h,m))
else:
if(len(str(h))==1 and len(str(m))==2):
print("0{}:{}".format(h,m))
elif(len(str(m))==1 and len(str(h))==2):
print("{}:0{}".format(h,m))
else:
print("0{}:0{}".format(h,m))
```
| 80,856 | [
0.41748046875,
0.347900390625,
0.09747314453125,
-0.01335906982421875,
-0.40576171875,
-0.27392578125,
-0.46923828125,
-0.0859375,
0.360595703125,
0.69775390625,
0.53955078125,
-0.04644775390625,
0.1729736328125,
-0.96826171875,
-0.44482421875,
-0.114990234375,
-0.364990234375,
-0.... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp is going to participate in the contest. It starts at h_1:m_1 and ends at h_2:m_2. It is guaranteed that the contest lasts an even number of minutes (i.e. m_1 \% 2 = m_2 \% 2, where x \% y is x modulo y). It is also guaranteed that the entire contest is held during a single day. And finally it is guaranteed that the contest lasts at least two minutes.
Polycarp wants to know the time of the midpoint of the contest. For example, if the contest lasts from 10:00 to 11:00 then the answer is 10:30, if the contest lasts from 11:10 to 11:12 then the answer is 11:11.
Input
The first line of the input contains two integers h_1 and m_1 in the format hh:mm.
The second line of the input contains two integers h_2 and m_2 in the same format (hh:mm).
It is guaranteed that 0 β€ h_1, h_2 β€ 23 and 0 β€ m_1, m_2 β€ 59.
It is guaranteed that the contest lasts an even number of minutes (i.e. m_1 \% 2 = m_2 \% 2, where x \% y is x modulo y). It is also guaranteed that the entire contest is held during a single day. And finally it is guaranteed that the contest lasts at least two minutes.
Output
Print two integers h_3 and m_3 (0 β€ h_3 β€ 23, 0 β€ m_3 β€ 59) corresponding to the midpoint of the contest in the format hh:mm. Print each number as exactly two digits (prepend a number with leading zero if needed), separate them with ':'.
Examples
Input
10:00
11:00
Output
10:30
Input
11:10
11:12
Output
11:11
Input
01:02
03:02
Output
02:02
Tags: implementation
Correct Solution:
```
h1,m1 = map(int,input().split(':'))
h2,m2 = map(int,input().split(':'))
time = 0
if m2 - m1 < 0:
time = 60 + (m2 - m1)
if h2>h1:
x = (h2-h1)-1
else:
x=0
time+=x*60
else:
time = m2 - m1
time+=(h2-h1)*60
time//=2
diff = time//60
remain = time%60
if m1+remain >=60:
m1+=remain
m1-=60
h1+=diff+1
else:
m1+=remain
h1+=diff
if h1<10:
h1='0'+str(h1)
else:
h1=str(h1)
if m1<10:
m1='0'+str(m1)
else:
m1=str(m1)
z = h1+":"+m1
print(z)
```
| 80,857 | [
0.4384765625,
0.375,
0.13525390625,
-0.0540771484375,
-0.37646484375,
-0.2362060546875,
-0.460693359375,
-0.07012939453125,
0.32080078125,
0.68310546875,
0.55712890625,
-0.0572509765625,
0.126708984375,
-0.97509765625,
-0.45361328125,
-0.0911865234375,
-0.37060546875,
-0.6728515625... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp is going to participate in the contest. It starts at h_1:m_1 and ends at h_2:m_2. It is guaranteed that the contest lasts an even number of minutes (i.e. m_1 \% 2 = m_2 \% 2, where x \% y is x modulo y). It is also guaranteed that the entire contest is held during a single day. And finally it is guaranteed that the contest lasts at least two minutes.
Polycarp wants to know the time of the midpoint of the contest. For example, if the contest lasts from 10:00 to 11:00 then the answer is 10:30, if the contest lasts from 11:10 to 11:12 then the answer is 11:11.
Input
The first line of the input contains two integers h_1 and m_1 in the format hh:mm.
The second line of the input contains two integers h_2 and m_2 in the same format (hh:mm).
It is guaranteed that 0 β€ h_1, h_2 β€ 23 and 0 β€ m_1, m_2 β€ 59.
It is guaranteed that the contest lasts an even number of minutes (i.e. m_1 \% 2 = m_2 \% 2, where x \% y is x modulo y). It is also guaranteed that the entire contest is held during a single day. And finally it is guaranteed that the contest lasts at least two minutes.
Output
Print two integers h_3 and m_3 (0 β€ h_3 β€ 23, 0 β€ m_3 β€ 59) corresponding to the midpoint of the contest in the format hh:mm. Print each number as exactly two digits (prepend a number with leading zero if needed), separate them with ':'.
Examples
Input
10:00
11:00
Output
10:30
Input
11:10
11:12
Output
11:11
Input
01:02
03:02
Output
02:02
Tags: implementation
Correct Solution:
```
hour1, minu1 = map(str,input().split(':'))
hour2, minu2 = map(str,input().split(':'))
rez = ((int(hour2)-int(hour1))*60+int(minu2)-int(minu1))//2
newh = int(hour1)+rez//60+(int(minu1)+rez%60)//60
if newh<10:
newh = '0'+str(newh)
newm = (int(minu1)+rez%60)%60
if newm<10:
newm = '0'+str(newm)
print(newh,':',newm,sep='')
```
| 80,858 | [
0.4423828125,
0.36767578125,
0.054718017578125,
-0.08648681640625,
-0.481201171875,
-0.301513671875,
-0.5068359375,
-0.0217437744140625,
0.2481689453125,
0.67529296875,
0.56640625,
-0.035369873046875,
0.1612548828125,
-0.97607421875,
-0.44091796875,
-0.1240234375,
-0.36767578125,
-... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp is going to participate in the contest. It starts at h_1:m_1 and ends at h_2:m_2. It is guaranteed that the contest lasts an even number of minutes (i.e. m_1 \% 2 = m_2 \% 2, where x \% y is x modulo y). It is also guaranteed that the entire contest is held during a single day. And finally it is guaranteed that the contest lasts at least two minutes.
Polycarp wants to know the time of the midpoint of the contest. For example, if the contest lasts from 10:00 to 11:00 then the answer is 10:30, if the contest lasts from 11:10 to 11:12 then the answer is 11:11.
Input
The first line of the input contains two integers h_1 and m_1 in the format hh:mm.
The second line of the input contains two integers h_2 and m_2 in the same format (hh:mm).
It is guaranteed that 0 β€ h_1, h_2 β€ 23 and 0 β€ m_1, m_2 β€ 59.
It is guaranteed that the contest lasts an even number of minutes (i.e. m_1 \% 2 = m_2 \% 2, where x \% y is x modulo y). It is also guaranteed that the entire contest is held during a single day. And finally it is guaranteed that the contest lasts at least two minutes.
Output
Print two integers h_3 and m_3 (0 β€ h_3 β€ 23, 0 β€ m_3 β€ 59) corresponding to the midpoint of the contest in the format hh:mm. Print each number as exactly two digits (prepend a number with leading zero if needed), separate them with ':'.
Examples
Input
10:00
11:00
Output
10:30
Input
11:10
11:12
Output
11:11
Input
01:02
03:02
Output
02:02
Tags: implementation
Correct Solution:
```
h1,m1=input().split(':')
h2,m2=input().split(':')
ih1=int(h1)
ih2=int(h2)
im1=int(m1)
im2=int(m2)
min1=60*ih1+im1
min2=60*ih2+im2
minT=(min1+min2)/2
if(minT/60<10):
if(minT%60<10):
print("0{}:0{}".format(int(minT/60),int(minT%60)))
else:
print("0{}:{}".format(int(minT/60),int(minT%60)))
else:
if(minT%60<10):
print("{}:0{}".format(int(minT/60),int(minT%60)))
else:
print("{}:{}".format(int(minT/60),int(minT%60)))
```
| 80,859 | [
0.462646484375,
0.343017578125,
0.11407470703125,
-0.07220458984375,
-0.42431640625,
-0.2403564453125,
-0.470703125,
-0.06903076171875,
0.3388671875,
0.64892578125,
0.5458984375,
-0.0830078125,
0.0712890625,
-0.96728515625,
-0.485595703125,
-0.10150146484375,
-0.355712890625,
-0.68... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp is going to participate in the contest. It starts at h_1:m_1 and ends at h_2:m_2. It is guaranteed that the contest lasts an even number of minutes (i.e. m_1 \% 2 = m_2 \% 2, where x \% y is x modulo y). It is also guaranteed that the entire contest is held during a single day. And finally it is guaranteed that the contest lasts at least two minutes.
Polycarp wants to know the time of the midpoint of the contest. For example, if the contest lasts from 10:00 to 11:00 then the answer is 10:30, if the contest lasts from 11:10 to 11:12 then the answer is 11:11.
Input
The first line of the input contains two integers h_1 and m_1 in the format hh:mm.
The second line of the input contains two integers h_2 and m_2 in the same format (hh:mm).
It is guaranteed that 0 β€ h_1, h_2 β€ 23 and 0 β€ m_1, m_2 β€ 59.
It is guaranteed that the contest lasts an even number of minutes (i.e. m_1 \% 2 = m_2 \% 2, where x \% y is x modulo y). It is also guaranteed that the entire contest is held during a single day. And finally it is guaranteed that the contest lasts at least two minutes.
Output
Print two integers h_3 and m_3 (0 β€ h_3 β€ 23, 0 β€ m_3 β€ 59) corresponding to the midpoint of the contest in the format hh:mm. Print each number as exactly two digits (prepend a number with leading zero if needed), separate them with ':'.
Examples
Input
10:00
11:00
Output
10:30
Input
11:10
11:12
Output
11:11
Input
01:02
03:02
Output
02:02
Tags: implementation
Correct Solution:
```
a=input().split(':')
b=input().split(':')
min1=int(a[0])*60+int(a[1])
min2=int(b[0])*60+int(b[1])
middle=(min1+min2)//2
hr=middle//60
mini=middle%60
if hr<10:
print('0'+str(hr)+':',end='')
else:
print(str(hr)+':',end='')
if mini<10:
print('0'+str(mini))
else:
print(mini)
```
| 80,860 | [
0.451171875,
0.314453125,
0.11456298828125,
-0.04522705078125,
-0.4208984375,
-0.290283203125,
-0.47119140625,
-0.04620361328125,
0.326416015625,
0.6708984375,
0.5517578125,
-0.08642578125,
0.07476806640625,
-0.97998046875,
-0.5283203125,
-0.12432861328125,
-0.3564453125,
-0.718261... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp is going to participate in the contest. It starts at h_1:m_1 and ends at h_2:m_2. It is guaranteed that the contest lasts an even number of minutes (i.e. m_1 \% 2 = m_2 \% 2, where x \% y is x modulo y). It is also guaranteed that the entire contest is held during a single day. And finally it is guaranteed that the contest lasts at least two minutes.
Polycarp wants to know the time of the midpoint of the contest. For example, if the contest lasts from 10:00 to 11:00 then the answer is 10:30, if the contest lasts from 11:10 to 11:12 then the answer is 11:11.
Input
The first line of the input contains two integers h_1 and m_1 in the format hh:mm.
The second line of the input contains two integers h_2 and m_2 in the same format (hh:mm).
It is guaranteed that 0 β€ h_1, h_2 β€ 23 and 0 β€ m_1, m_2 β€ 59.
It is guaranteed that the contest lasts an even number of minutes (i.e. m_1 \% 2 = m_2 \% 2, where x \% y is x modulo y). It is also guaranteed that the entire contest is held during a single day. And finally it is guaranteed that the contest lasts at least two minutes.
Output
Print two integers h_3 and m_3 (0 β€ h_3 β€ 23, 0 β€ m_3 β€ 59) corresponding to the midpoint of the contest in the format hh:mm. Print each number as exactly two digits (prepend a number with leading zero if needed), separate them with ':'.
Examples
Input
10:00
11:00
Output
10:30
Input
11:10
11:12
Output
11:11
Input
01:02
03:02
Output
02:02
Submitted Solution:
```
import sys
import math
#to read string
get_string = lambda: sys.stdin.readline().strip()
#to read list of integers
get_int_list = lambda: list( map(int,sys.stdin.readline().strip().split()) )
#to read non spaced string and elements are integers to list of int
get_intList_from_str = lambda: list(map(int,list(sys.stdin.readline().strip())))
#to read non spaced string and elements are character to list of character
get_charList_from_str = lambda: list(sys.stdin.readline().strip())
#get word sepetared list of character
get_char_list = lambda: sys.stdin.readline().strip().split()
#to read integers
get_int = lambda: int(sys.stdin.readline())
#to print faster
pt = lambda x: sys.stdout.write(str(x))
#--------------------------------WhiteHat010--------------------------------#
a = list(map(int,input().split(':')))
b = list(map(int,input().split(':')))
s = (a[0]*60 + b[0]*60 + a[1] + b[1])//2
hour = str(s//60)
if len(hour) == 1:
hour = '0'+hour
minu = str(s%60)
if len(minu) == 1:
minu = '0'+minu
print( hour + ':' + minu)
```
Yes
| 80,861 | [
0.44482421875,
0.343017578125,
0.05511474609375,
-0.0286865234375,
-0.5986328125,
-0.09344482421875,
-0.450439453125,
0.154541015625,
0.1954345703125,
0.74072265625,
0.57421875,
-0.12261962890625,
0.037933349609375,
-0.8525390625,
-0.56494140625,
-0.2254638671875,
-0.311767578125,
... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp is going to participate in the contest. It starts at h_1:m_1 and ends at h_2:m_2. It is guaranteed that the contest lasts an even number of minutes (i.e. m_1 \% 2 = m_2 \% 2, where x \% y is x modulo y). It is also guaranteed that the entire contest is held during a single day. And finally it is guaranteed that the contest lasts at least two minutes.
Polycarp wants to know the time of the midpoint of the contest. For example, if the contest lasts from 10:00 to 11:00 then the answer is 10:30, if the contest lasts from 11:10 to 11:12 then the answer is 11:11.
Input
The first line of the input contains two integers h_1 and m_1 in the format hh:mm.
The second line of the input contains two integers h_2 and m_2 in the same format (hh:mm).
It is guaranteed that 0 β€ h_1, h_2 β€ 23 and 0 β€ m_1, m_2 β€ 59.
It is guaranteed that the contest lasts an even number of minutes (i.e. m_1 \% 2 = m_2 \% 2, where x \% y is x modulo y). It is also guaranteed that the entire contest is held during a single day. And finally it is guaranteed that the contest lasts at least two minutes.
Output
Print two integers h_3 and m_3 (0 β€ h_3 β€ 23, 0 β€ m_3 β€ 59) corresponding to the midpoint of the contest in the format hh:mm. Print each number as exactly two digits (prepend a number with leading zero if needed), separate them with ':'.
Examples
Input
10:00
11:00
Output
10:30
Input
11:10
11:12
Output
11:11
Input
01:02
03:02
Output
02:02
Submitted Solution:
```
import sys
read = lambda: list(map(int, sys.stdin.readline().strip().split()))
import bisect
s1 = input()
s2 = input()
h1 = int(s1[0:2])
m1 = int(s1[3:])
h2 = int(s2[0:2])
m2 = int(s2[3:])
h = (h2+h1)//2
m = (m2+m1)//2
if (h2-h1)%2 == 1:
m += 30
#print(h, m)
if m >= 60:
h += 1
m -= 60
if h <10:
print("0{}".format(h), end='')
else:
print(h, end='')
print(":",end='')
if m < 10:
print("0{}".format(m))
else:
print(m)
```
Yes
| 80,862 | [
0.437744140625,
0.406005859375,
0.08721923828125,
0.00655364990234375,
-0.6279296875,
-0.044952392578125,
-0.416748046875,
0.060638427734375,
0.1595458984375,
0.77978515625,
0.5595703125,
-0.07818603515625,
0.0745849609375,
-0.92822265625,
-0.57861328125,
-0.2376708984375,
-0.3305664... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp is going to participate in the contest. It starts at h_1:m_1 and ends at h_2:m_2. It is guaranteed that the contest lasts an even number of minutes (i.e. m_1 \% 2 = m_2 \% 2, where x \% y is x modulo y). It is also guaranteed that the entire contest is held during a single day. And finally it is guaranteed that the contest lasts at least two minutes.
Polycarp wants to know the time of the midpoint of the contest. For example, if the contest lasts from 10:00 to 11:00 then the answer is 10:30, if the contest lasts from 11:10 to 11:12 then the answer is 11:11.
Input
The first line of the input contains two integers h_1 and m_1 in the format hh:mm.
The second line of the input contains two integers h_2 and m_2 in the same format (hh:mm).
It is guaranteed that 0 β€ h_1, h_2 β€ 23 and 0 β€ m_1, m_2 β€ 59.
It is guaranteed that the contest lasts an even number of minutes (i.e. m_1 \% 2 = m_2 \% 2, where x \% y is x modulo y). It is also guaranteed that the entire contest is held during a single day. And finally it is guaranteed that the contest lasts at least two minutes.
Output
Print two integers h_3 and m_3 (0 β€ h_3 β€ 23, 0 β€ m_3 β€ 59) corresponding to the midpoint of the contest in the format hh:mm. Print each number as exactly two digits (prepend a number with leading zero if needed), separate them with ':'.
Examples
Input
10:00
11:00
Output
10:30
Input
11:10
11:12
Output
11:11
Input
01:02
03:02
Output
02:02
Submitted Solution:
```
while True:
try:
ha = input()
hb = input()
h1, m1 = list(map(int, ha.split(":")))
h2, m2 = list(map(int, hb.split(":")))
h1m = h1 * 60 + m1
h2m = h2 * 60 + m2
hmm = int(h1m + ((h2m - h1m) / 2))
hm = int(hmm / 60)
mm = int(hmm % 60)
hm = "0" + str(hm) if hm < 10 else str(hm)
mm = "0" + str(mm) if mm < 10 else str(mm)
print(hm + ":" + mm)
except EOFError:
break
```
Yes
| 80,863 | [
0.52197265625,
0.38134765625,
0.03143310546875,
-0.0289306640625,
-0.529296875,
-0.0897216796875,
-0.471435546875,
0.1275634765625,
0.2132568359375,
0.7197265625,
0.56103515625,
-0.03509521484375,
0.060546875,
-0.90478515625,
-0.48876953125,
-0.2176513671875,
-0.302001953125,
-0.56... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp is going to participate in the contest. It starts at h_1:m_1 and ends at h_2:m_2. It is guaranteed that the contest lasts an even number of minutes (i.e. m_1 \% 2 = m_2 \% 2, where x \% y is x modulo y). It is also guaranteed that the entire contest is held during a single day. And finally it is guaranteed that the contest lasts at least two minutes.
Polycarp wants to know the time of the midpoint of the contest. For example, if the contest lasts from 10:00 to 11:00 then the answer is 10:30, if the contest lasts from 11:10 to 11:12 then the answer is 11:11.
Input
The first line of the input contains two integers h_1 and m_1 in the format hh:mm.
The second line of the input contains two integers h_2 and m_2 in the same format (hh:mm).
It is guaranteed that 0 β€ h_1, h_2 β€ 23 and 0 β€ m_1, m_2 β€ 59.
It is guaranteed that the contest lasts an even number of minutes (i.e. m_1 \% 2 = m_2 \% 2, where x \% y is x modulo y). It is also guaranteed that the entire contest is held during a single day. And finally it is guaranteed that the contest lasts at least two minutes.
Output
Print two integers h_3 and m_3 (0 β€ h_3 β€ 23, 0 β€ m_3 β€ 59) corresponding to the midpoint of the contest in the format hh:mm. Print each number as exactly two digits (prepend a number with leading zero if needed), separate them with ':'.
Examples
Input
10:00
11:00
Output
10:30
Input
11:10
11:12
Output
11:11
Input
01:02
03:02
Output
02:02
Submitted Solution:
```
h1,m1=map(int,input().split(':'))
h2,m2=map(int,input().split(':'))
l1=h1*60+m1
l2=h2*60+m2
n=(l1+l2)/2
h=int(int(n)/60)
m=int(int(n)%60)
print(format(h, '02')+':'+format(m, '02'))
```
Yes
| 80,864 | [
0.49755859375,
0.343505859375,
0.0292510986328125,
-0.060546875,
-0.509765625,
-0.07391357421875,
-0.498779296875,
0.12091064453125,
0.184326171875,
0.712890625,
0.5791015625,
-0.01248931884765625,
0.0418701171875,
-0.91162109375,
-0.48388671875,
-0.19482421875,
-0.3193359375,
-0.6... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp is going to participate in the contest. It starts at h_1:m_1 and ends at h_2:m_2. It is guaranteed that the contest lasts an even number of minutes (i.e. m_1 \% 2 = m_2 \% 2, where x \% y is x modulo y). It is also guaranteed that the entire contest is held during a single day. And finally it is guaranteed that the contest lasts at least two minutes.
Polycarp wants to know the time of the midpoint of the contest. For example, if the contest lasts from 10:00 to 11:00 then the answer is 10:30, if the contest lasts from 11:10 to 11:12 then the answer is 11:11.
Input
The first line of the input contains two integers h_1 and m_1 in the format hh:mm.
The second line of the input contains two integers h_2 and m_2 in the same format (hh:mm).
It is guaranteed that 0 β€ h_1, h_2 β€ 23 and 0 β€ m_1, m_2 β€ 59.
It is guaranteed that the contest lasts an even number of minutes (i.e. m_1 \% 2 = m_2 \% 2, where x \% y is x modulo y). It is also guaranteed that the entire contest is held during a single day. And finally it is guaranteed that the contest lasts at least two minutes.
Output
Print two integers h_3 and m_3 (0 β€ h_3 β€ 23, 0 β€ m_3 β€ 59) corresponding to the midpoint of the contest in the format hh:mm. Print each number as exactly two digits (prepend a number with leading zero if needed), separate them with ':'.
Examples
Input
10:00
11:00
Output
10:30
Input
11:10
11:12
Output
11:11
Input
01:02
03:02
Output
02:02
Submitted Solution:
```
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Wed Mar 13 11:07:20 2019
@author: lanliu
"""
a = []
for i in range(2):
str_in = input()
for j in range(len(str_in)):
if str_in[j].isdigit():
a.append(int(str_in[j]))
starttime_h = a[0]*10+a[1]
starttime_m = a[2]*10+a[3]
endtime_h = a[4]*10+a[5]
endtime_m = a[6]*10+a[7]
interval = (endtime_h*60+endtime_m-starttime_h*60-starttime_m)/2
mins = int(starttime_m+interval%60)
if mins == 0:
mins = '00'
else:
mins = str(mins)
print(str(int(starttime_h+interval/60))+":"+mins)
"""
Time_0 = (a[0][0]*10 + a[0][1])*60 + a[0][2]*10 + a[0][3]
Time_1 = (a[1][0]*10 + a[1][1])*60 + a[1][2]*10 + a[1][3]
Interval = (int(Time_1) - int(Time_0))/2
"""
```
No
| 80,865 | [
0.4716796875,
0.279296875,
0.034698486328125,
0.031890869140625,
-0.5390625,
-0.1251220703125,
-0.38525390625,
0.126220703125,
0.2242431640625,
0.72216796875,
0.544921875,
-0.09112548828125,
0.0271453857421875,
-0.8994140625,
-0.5751953125,
-0.189208984375,
-0.302001953125,
-0.5742... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp is going to participate in the contest. It starts at h_1:m_1 and ends at h_2:m_2. It is guaranteed that the contest lasts an even number of minutes (i.e. m_1 \% 2 = m_2 \% 2, where x \% y is x modulo y). It is also guaranteed that the entire contest is held during a single day. And finally it is guaranteed that the contest lasts at least two minutes.
Polycarp wants to know the time of the midpoint of the contest. For example, if the contest lasts from 10:00 to 11:00 then the answer is 10:30, if the contest lasts from 11:10 to 11:12 then the answer is 11:11.
Input
The first line of the input contains two integers h_1 and m_1 in the format hh:mm.
The second line of the input contains two integers h_2 and m_2 in the same format (hh:mm).
It is guaranteed that 0 β€ h_1, h_2 β€ 23 and 0 β€ m_1, m_2 β€ 59.
It is guaranteed that the contest lasts an even number of minutes (i.e. m_1 \% 2 = m_2 \% 2, where x \% y is x modulo y). It is also guaranteed that the entire contest is held during a single day. And finally it is guaranteed that the contest lasts at least two minutes.
Output
Print two integers h_3 and m_3 (0 β€ h_3 β€ 23, 0 β€ m_3 β€ 59) corresponding to the midpoint of the contest in the format hh:mm. Print each number as exactly two digits (prepend a number with leading zero if needed), separate them with ':'.
Examples
Input
10:00
11:00
Output
10:30
Input
11:10
11:12
Output
11:11
Input
01:02
03:02
Output
02:02
Submitted Solution:
```
h1,m1=map(int,input().split(':'))
h2,m2=map(int,input().split(':'))
d=h1+h2
h3='0'+str(d//2) if len(str(d//2))==1 else str(d//2)
m3=''
if m1==m2:
if d&1:
m3=str((m1+m2+60)//2)
else:
m3=str(m1) if len(str(m1))!=1 else '0'+str(m1)
else:
m3=str((m1+m2)//2)
print(h3+':'+m3)
```
No
| 80,866 | [
0.486083984375,
0.341064453125,
0.034698486328125,
-0.06781005859375,
-0.517578125,
-0.0743408203125,
-0.490966796875,
0.11846923828125,
0.186279296875,
0.708984375,
0.5751953125,
-0.0272369384765625,
0.045928955078125,
-0.9150390625,
-0.48046875,
-0.200439453125,
-0.31787109375,
-... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp is going to participate in the contest. It starts at h_1:m_1 and ends at h_2:m_2. It is guaranteed that the contest lasts an even number of minutes (i.e. m_1 \% 2 = m_2 \% 2, where x \% y is x modulo y). It is also guaranteed that the entire contest is held during a single day. And finally it is guaranteed that the contest lasts at least two minutes.
Polycarp wants to know the time of the midpoint of the contest. For example, if the contest lasts from 10:00 to 11:00 then the answer is 10:30, if the contest lasts from 11:10 to 11:12 then the answer is 11:11.
Input
The first line of the input contains two integers h_1 and m_1 in the format hh:mm.
The second line of the input contains two integers h_2 and m_2 in the same format (hh:mm).
It is guaranteed that 0 β€ h_1, h_2 β€ 23 and 0 β€ m_1, m_2 β€ 59.
It is guaranteed that the contest lasts an even number of minutes (i.e. m_1 \% 2 = m_2 \% 2, where x \% y is x modulo y). It is also guaranteed that the entire contest is held during a single day. And finally it is guaranteed that the contest lasts at least two minutes.
Output
Print two integers h_3 and m_3 (0 β€ h_3 β€ 23, 0 β€ m_3 β€ 59) corresponding to the midpoint of the contest in the format hh:mm. Print each number as exactly two digits (prepend a number with leading zero if needed), separate them with ':'.
Examples
Input
10:00
11:00
Output
10:30
Input
11:10
11:12
Output
11:11
Input
01:02
03:02
Output
02:02
Submitted Solution:
```
h1,m1=map(int,input().split(":"))
h2,m2=map(int,input().split(":"))
m=((h2-h1)*60+m2-m1)//2
h3=m//60+h1
m3=m%60+m1
if h3<10:
print(0,end="")
print(h3,end=":")
else:
print(h3,end=":")
if m3<10:
print(0,end="")
print(m3)
else:
print(m3)
```
No
| 80,867 | [
0.5009765625,
0.344482421875,
0.0227203369140625,
-0.06793212890625,
-0.51025390625,
-0.0667724609375,
-0.4873046875,
0.12237548828125,
0.1859130859375,
0.7255859375,
0.5751953125,
-0.01038360595703125,
0.05120849609375,
-0.9248046875,
-0.4853515625,
-0.1893310546875,
-0.31201171875,... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp is going to participate in the contest. It starts at h_1:m_1 and ends at h_2:m_2. It is guaranteed that the contest lasts an even number of minutes (i.e. m_1 \% 2 = m_2 \% 2, where x \% y is x modulo y). It is also guaranteed that the entire contest is held during a single day. And finally it is guaranteed that the contest lasts at least two minutes.
Polycarp wants to know the time of the midpoint of the contest. For example, if the contest lasts from 10:00 to 11:00 then the answer is 10:30, if the contest lasts from 11:10 to 11:12 then the answer is 11:11.
Input
The first line of the input contains two integers h_1 and m_1 in the format hh:mm.
The second line of the input contains two integers h_2 and m_2 in the same format (hh:mm).
It is guaranteed that 0 β€ h_1, h_2 β€ 23 and 0 β€ m_1, m_2 β€ 59.
It is guaranteed that the contest lasts an even number of minutes (i.e. m_1 \% 2 = m_2 \% 2, where x \% y is x modulo y). It is also guaranteed that the entire contest is held during a single day. And finally it is guaranteed that the contest lasts at least two minutes.
Output
Print two integers h_3 and m_3 (0 β€ h_3 β€ 23, 0 β€ m_3 β€ 59) corresponding to the midpoint of the contest in the format hh:mm. Print each number as exactly two digits (prepend a number with leading zero if needed), separate them with ':'.
Examples
Input
10:00
11:00
Output
10:30
Input
11:10
11:12
Output
11:11
Input
01:02
03:02
Output
02:02
Submitted Solution:
```
first_line = input()
second_line = input()
h1 = int(first_line.split(':')[0])
m1 = int(first_line.split(':')[1])
h2 = int(second_line.split(':')[0])
m2 = int(second_line.split(':')[1])
h3 = h2 - h1
m3 = m2 - m1
time_to_add_h = round(h3 / 2)
time_to_add_m = round(m3 / 2)
if h3 == 1:
time_to_add_h = 0
time_to_add_m += 30
result_h = h1 + time_to_add_h
result_m = m1 + time_to_add_m
if result_h < 10:
result_h = "0" + str(result_h)
if result_m < 10:
result_m = "0" + str(result_m)
print(str(result_h) + ":" + str(result_m))
```
No
| 80,868 | [
0.49072265625,
0.295654296875,
0.06036376953125,
-0.0728759765625,
-0.52978515625,
-0.081787109375,
-0.45263671875,
0.1143798828125,
0.20458984375,
0.701171875,
0.54443359375,
-0.0330810546875,
0.01458740234375,
-0.8974609375,
-0.5390625,
-0.18017578125,
-0.316650390625,
-0.6308593... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a non-empty string s=s_1s_2... s_n, which consists only of lowercase Latin letters. Polycarp does not like a string if it contains at least one string "one" or at least one string "two" (or both at the same time) as a substring. In other words, Polycarp does not like the string s if there is an integer j (1 β€ j β€ n-2), that s_{j}s_{j+1}s_{j+2}="one" or s_{j}s_{j+1}s_{j+2}="two".
For example:
* Polycarp does not like strings "oneee", "ontwow", "twone" and "oneonetwo" (they all have at least one substring "one" or "two"),
* Polycarp likes strings "oonnee", "twwwo" and "twnoe" (they have no substrings "one" and "two").
Polycarp wants to select a certain set of indices (positions) and remove all letters on these positions. All removals are made at the same time.
For example, if the string looks like s="onetwone", then if Polycarp selects two indices 3 and 6, then "onetwone" will be selected and the result is "ontwne".
What is the minimum number of indices (positions) that Polycarp needs to select to make the string liked? What should these positions be?
Input
The first line of the input contains an integer t (1 β€ t β€ 10^4) β the number of test cases in the input. Next, the test cases are given.
Each test case consists of one non-empty string s. Its length does not exceed 1.5β
10^5. The string s consists only of lowercase Latin letters.
It is guaranteed that the sum of lengths of all lines for all input data in the test does not exceed 1.5β
10^6.
Output
Print an answer for each test case in the input in order of their appearance.
The first line of each answer should contain r (0 β€ r β€ |s|) β the required minimum number of positions to be removed, where |s| is the length of the given line. The second line of each answer should contain r different integers β the indices themselves for removal in any order. Indices are numbered from left to right from 1 to the length of the string. If r=0, then the second line can be skipped (or you can print empty). If there are several answers, print any of them.
Examples
Input
4
onetwone
testme
oneoneone
twotwo
Output
2
6 3
0
3
4 1 7
2
1 4
Input
10
onetwonetwooneooonetwooo
two
one
twooooo
ttttwo
ttwwoo
ooone
onnne
oneeeee
oneeeeeeetwooooo
Output
6
18 11 12 1 6 21
1
1
1
3
1
2
1
6
0
1
4
0
1
1
2
1 11
Note
In the first example, answers are:
* "onetwone",
* "testme" β Polycarp likes it, there is nothing to remove,
* "oneoneone",
* "twotwo".
In the second example, answers are:
* "onetwonetwooneooonetwooo",
* "two",
* "one",
* "twooooo",
* "ttttwo",
* "ttwwoo" β Polycarp likes it, there is nothing to remove,
* "ooone",
* "onnne" β Polycarp likes it, there is nothing to remove,
* "oneeeee",
* "oneeeeeeetwooooo".
Tags: dp, greedy
Correct Solution:
```
def make_liked(s):
i = 0
remove = []
while i < len(s)-2:
if i < len(s) - 4 and s[i] == "t" and s[i+1] == "w" and s[i+2] == "o" and s[i+3] == "n" and s[i+4] == "e":
remove.append(i+3)
i+=4
continue
if s[i] == "o" and s[i+1] == "n" and s[i+2] == "e":
#print(i,i+1,i+2)
remove.append(i+2)
elif s[i] == "t" and s[i+1] == "w" and s[i+2] == "o":
#print(i,i+1,i+2)
remove.append(i+2)
i+=1
print(len(remove))
print(*remove)
if __name__ == "__main__":
t = int(input())
for i in range(t):
s = input()
make_liked(s)
```
| 80,927 | [
0.16650390625,
0.399169921875,
0.400634765625,
0.15625,
-0.73388671875,
-0.303955078125,
-0.266845703125,
0.049041748046875,
0.1688232421875,
0.6904296875,
1.0546875,
0.032623291015625,
-0.017913818359375,
-1.0634765625,
-0.72509765625,
-0.003589630126953125,
-0.35205078125,
-0.334... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a non-empty string s=s_1s_2... s_n, which consists only of lowercase Latin letters. Polycarp does not like a string if it contains at least one string "one" or at least one string "two" (or both at the same time) as a substring. In other words, Polycarp does not like the string s if there is an integer j (1 β€ j β€ n-2), that s_{j}s_{j+1}s_{j+2}="one" or s_{j}s_{j+1}s_{j+2}="two".
For example:
* Polycarp does not like strings "oneee", "ontwow", "twone" and "oneonetwo" (they all have at least one substring "one" or "two"),
* Polycarp likes strings "oonnee", "twwwo" and "twnoe" (they have no substrings "one" and "two").
Polycarp wants to select a certain set of indices (positions) and remove all letters on these positions. All removals are made at the same time.
For example, if the string looks like s="onetwone", then if Polycarp selects two indices 3 and 6, then "onetwone" will be selected and the result is "ontwne".
What is the minimum number of indices (positions) that Polycarp needs to select to make the string liked? What should these positions be?
Input
The first line of the input contains an integer t (1 β€ t β€ 10^4) β the number of test cases in the input. Next, the test cases are given.
Each test case consists of one non-empty string s. Its length does not exceed 1.5β
10^5. The string s consists only of lowercase Latin letters.
It is guaranteed that the sum of lengths of all lines for all input data in the test does not exceed 1.5β
10^6.
Output
Print an answer for each test case in the input in order of their appearance.
The first line of each answer should contain r (0 β€ r β€ |s|) β the required minimum number of positions to be removed, where |s| is the length of the given line. The second line of each answer should contain r different integers β the indices themselves for removal in any order. Indices are numbered from left to right from 1 to the length of the string. If r=0, then the second line can be skipped (or you can print empty). If there are several answers, print any of them.
Examples
Input
4
onetwone
testme
oneoneone
twotwo
Output
2
6 3
0
3
4 1 7
2
1 4
Input
10
onetwonetwooneooonetwooo
two
one
twooooo
ttttwo
ttwwoo
ooone
onnne
oneeeee
oneeeeeeetwooooo
Output
6
18 11 12 1 6 21
1
1
1
3
1
2
1
6
0
1
4
0
1
1
2
1 11
Note
In the first example, answers are:
* "onetwone",
* "testme" β Polycarp likes it, there is nothing to remove,
* "oneoneone",
* "twotwo".
In the second example, answers are:
* "onetwonetwooneooonetwooo",
* "two",
* "one",
* "twooooo",
* "ttttwo",
* "ttwwoo" β Polycarp likes it, there is nothing to remove,
* "ooone",
* "onnne" β Polycarp likes it, there is nothing to remove,
* "oneeeee",
* "oneeeeeeetwooooo".
Tags: dp, greedy
Correct Solution:
```
a = int(input())
for x in range(a):
b = input()
c = len(b)
d = list(b)
k = 0
h = []
if c == 1 or c == 2:
print(0)
print()
elif c == 3:
if d[0] == "o":
if d[1] == "n":
if d[2] == "e":
k += 1
d[0] = "@"
h.append(1)
elif d[2] == "o":
if d[1] == "w":
if d[0] == "t":
k += 1
d[2] = "@"
h.append(3)
print(k)
print(*h)
else:
for y in range(c):
if d[y] == "o":
if y == 0 or y == 1:
if d[y+1] == "n":
if d[y+2] == "e":
k += 1
d[y+1] = "@"
h.append(y+2)
elif y == c-2 or y == c-1:
if d[y-1] =="w":
if d[y-2] == "t":
k += 1
d[y-1] = "@"
h.append(y)
else:
if (d[y+1] == "n" and d[y+2] == "e" ) and (d[y-1] == "w" and d[y-2] == "t"):
k += 1
d[y] = "@"
h.append(y+1)
elif (d[y+1] == "n" and d[y+2] == "e" ):
k += 1
d[y+1] == "@"
h.append(y+2)
elif (d[y-1] == "w" and d[y-2] == "t"):
k += 1
d[y-1] == "@"
h.append(y)
print(k)
print(*h)
```
| 80,928 | [
0.16650390625,
0.399169921875,
0.400634765625,
0.15625,
-0.73388671875,
-0.303955078125,
-0.266845703125,
0.049041748046875,
0.1688232421875,
0.6904296875,
1.0546875,
0.032623291015625,
-0.017913818359375,
-1.0634765625,
-0.72509765625,
-0.003589630126953125,
-0.35205078125,
-0.334... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a non-empty string s=s_1s_2... s_n, which consists only of lowercase Latin letters. Polycarp does not like a string if it contains at least one string "one" or at least one string "two" (or both at the same time) as a substring. In other words, Polycarp does not like the string s if there is an integer j (1 β€ j β€ n-2), that s_{j}s_{j+1}s_{j+2}="one" or s_{j}s_{j+1}s_{j+2}="two".
For example:
* Polycarp does not like strings "oneee", "ontwow", "twone" and "oneonetwo" (they all have at least one substring "one" or "two"),
* Polycarp likes strings "oonnee", "twwwo" and "twnoe" (they have no substrings "one" and "two").
Polycarp wants to select a certain set of indices (positions) and remove all letters on these positions. All removals are made at the same time.
For example, if the string looks like s="onetwone", then if Polycarp selects two indices 3 and 6, then "onetwone" will be selected and the result is "ontwne".
What is the minimum number of indices (positions) that Polycarp needs to select to make the string liked? What should these positions be?
Input
The first line of the input contains an integer t (1 β€ t β€ 10^4) β the number of test cases in the input. Next, the test cases are given.
Each test case consists of one non-empty string s. Its length does not exceed 1.5β
10^5. The string s consists only of lowercase Latin letters.
It is guaranteed that the sum of lengths of all lines for all input data in the test does not exceed 1.5β
10^6.
Output
Print an answer for each test case in the input in order of their appearance.
The first line of each answer should contain r (0 β€ r β€ |s|) β the required minimum number of positions to be removed, where |s| is the length of the given line. The second line of each answer should contain r different integers β the indices themselves for removal in any order. Indices are numbered from left to right from 1 to the length of the string. If r=0, then the second line can be skipped (or you can print empty). If there are several answers, print any of them.
Examples
Input
4
onetwone
testme
oneoneone
twotwo
Output
2
6 3
0
3
4 1 7
2
1 4
Input
10
onetwonetwooneooonetwooo
two
one
twooooo
ttttwo
ttwwoo
ooone
onnne
oneeeee
oneeeeeeetwooooo
Output
6
18 11 12 1 6 21
1
1
1
3
1
2
1
6
0
1
4
0
1
1
2
1 11
Note
In the first example, answers are:
* "onetwone",
* "testme" β Polycarp likes it, there is nothing to remove,
* "oneoneone",
* "twotwo".
In the second example, answers are:
* "onetwonetwooneooonetwooo",
* "two",
* "one",
* "twooooo",
* "ttttwo",
* "ttwwoo" β Polycarp likes it, there is nothing to remove,
* "ooone",
* "onnne" β Polycarp likes it, there is nothing to remove,
* "oneeeee",
* "oneeeeeeetwooooo".
Tags: dp, greedy
Correct Solution:
```
for _ in range(int(input())):
s=input();i=0;r=[]
while i<len(s):
if'twone'==s[i:i+5]:i+=3;r+=i,
if s[i:i+3] in('one','two'): r+=i+2,
i+=1
print(len(r),*r)
```
| 80,929 | [
0.16650390625,
0.399169921875,
0.400634765625,
0.15625,
-0.73388671875,
-0.303955078125,
-0.266845703125,
0.049041748046875,
0.1688232421875,
0.6904296875,
1.0546875,
0.032623291015625,
-0.017913818359375,
-1.0634765625,
-0.72509765625,
-0.003589630126953125,
-0.35205078125,
-0.334... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a non-empty string s=s_1s_2... s_n, which consists only of lowercase Latin letters. Polycarp does not like a string if it contains at least one string "one" or at least one string "two" (or both at the same time) as a substring. In other words, Polycarp does not like the string s if there is an integer j (1 β€ j β€ n-2), that s_{j}s_{j+1}s_{j+2}="one" or s_{j}s_{j+1}s_{j+2}="two".
For example:
* Polycarp does not like strings "oneee", "ontwow", "twone" and "oneonetwo" (they all have at least one substring "one" or "two"),
* Polycarp likes strings "oonnee", "twwwo" and "twnoe" (they have no substrings "one" and "two").
Polycarp wants to select a certain set of indices (positions) and remove all letters on these positions. All removals are made at the same time.
For example, if the string looks like s="onetwone", then if Polycarp selects two indices 3 and 6, then "onetwone" will be selected and the result is "ontwne".
What is the minimum number of indices (positions) that Polycarp needs to select to make the string liked? What should these positions be?
Input
The first line of the input contains an integer t (1 β€ t β€ 10^4) β the number of test cases in the input. Next, the test cases are given.
Each test case consists of one non-empty string s. Its length does not exceed 1.5β
10^5. The string s consists only of lowercase Latin letters.
It is guaranteed that the sum of lengths of all lines for all input data in the test does not exceed 1.5β
10^6.
Output
Print an answer for each test case in the input in order of their appearance.
The first line of each answer should contain r (0 β€ r β€ |s|) β the required minimum number of positions to be removed, where |s| is the length of the given line. The second line of each answer should contain r different integers β the indices themselves for removal in any order. Indices are numbered from left to right from 1 to the length of the string. If r=0, then the second line can be skipped (or you can print empty). If there are several answers, print any of them.
Examples
Input
4
onetwone
testme
oneoneone
twotwo
Output
2
6 3
0
3
4 1 7
2
1 4
Input
10
onetwonetwooneooonetwooo
two
one
twooooo
ttttwo
ttwwoo
ooone
onnne
oneeeee
oneeeeeeetwooooo
Output
6
18 11 12 1 6 21
1
1
1
3
1
2
1
6
0
1
4
0
1
1
2
1 11
Note
In the first example, answers are:
* "onetwone",
* "testme" β Polycarp likes it, there is nothing to remove,
* "oneoneone",
* "twotwo".
In the second example, answers are:
* "onetwonetwooneooonetwooo",
* "two",
* "one",
* "twooooo",
* "ttttwo",
* "ttwwoo" β Polycarp likes it, there is nothing to remove,
* "ooone",
* "onnne" β Polycarp likes it, there is nothing to remove,
* "oneeeee",
* "oneeeeeeetwooooo".
Tags: dp, greedy
Correct Solution:
```
import sys, os, io
def rs(): return sys.stdin.readline().rstrip()
def ri(): return int(sys.stdin.readline())
def ria(): return list(map(int, sys.stdin.readline().split()))
def ws(s): sys.stdout.write(s + '\n')
def wi(n): sys.stdout.write(str(n) + '\n')
def wia(a): sys.stdout.write(' '.join([str(x) for x in a]) + '\n')
import math,datetime,functools,itertools,operator,bisect
from collections import deque,defaultdict,OrderedDict
import collections
def main():
starttime=datetime.datetime.now()
if(os.path.exists('input.txt')):
sys.stdin = open("input.txt","r")
sys.stdout = open("output.txt","w")
#Solving Area Starts-->
for _ in range(ri()):
s=rs()
s="zz"+s+"zz"
ans=[]
r=0
for i in range(2,len(s)-2):
if s[i]=='o':
if s[i-2]+s[i-1]=="tw" and s[i+1]+s[i+2]=="ne":
ans.append(i+1-2)
if s[i-2]+s[i-1]=="tw" and s[i+1]+s[i+2]!="ne":
ans.append(i-2)
if s[i-2]+s[i-1]!="tw" and s[i+1]+s[i+2]=="ne":
ans.append(i+2-2)
print(len(ans))
print(*ans)
#<--Solving Area Ends
endtime=datetime.datetime.now()
time=(endtime-starttime).total_seconds()*1000
if(os.path.exists('input.txt')):
print("Time:",time,"ms")
class FastReader(io.IOBase):
newlines = 0
def __init__(self, fd, chunk_size=1024 * 8):
self._fd = fd
self._chunk_size = chunk_size
self.buffer = io.BytesIO()
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self, size=-1):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size if size == -1 else size))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
class FastWriter(io.IOBase):
def __init__(self, fd):
self._fd = fd
self.buffer = io.BytesIO()
self.write = self.buffer.write
def flush(self):
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class FastStdin(io.IOBase):
def __init__(self, fd=0):
self.buffer = FastReader(fd)
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
class FastStdout(io.IOBase):
def __init__(self, fd=1):
self.buffer = FastWriter(fd)
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.flush = self.buffer.flush
if __name__ == '__main__':
sys.stdin = FastStdin()
sys.stdout = FastStdout()
main()
```
| 80,930 | [
0.16650390625,
0.399169921875,
0.400634765625,
0.15625,
-0.73388671875,
-0.303955078125,
-0.266845703125,
0.049041748046875,
0.1688232421875,
0.6904296875,
1.0546875,
0.032623291015625,
-0.017913818359375,
-1.0634765625,
-0.72509765625,
-0.003589630126953125,
-0.35205078125,
-0.334... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a non-empty string s=s_1s_2... s_n, which consists only of lowercase Latin letters. Polycarp does not like a string if it contains at least one string "one" or at least one string "two" (or both at the same time) as a substring. In other words, Polycarp does not like the string s if there is an integer j (1 β€ j β€ n-2), that s_{j}s_{j+1}s_{j+2}="one" or s_{j}s_{j+1}s_{j+2}="two".
For example:
* Polycarp does not like strings "oneee", "ontwow", "twone" and "oneonetwo" (they all have at least one substring "one" or "two"),
* Polycarp likes strings "oonnee", "twwwo" and "twnoe" (they have no substrings "one" and "two").
Polycarp wants to select a certain set of indices (positions) and remove all letters on these positions. All removals are made at the same time.
For example, if the string looks like s="onetwone", then if Polycarp selects two indices 3 and 6, then "onetwone" will be selected and the result is "ontwne".
What is the minimum number of indices (positions) that Polycarp needs to select to make the string liked? What should these positions be?
Input
The first line of the input contains an integer t (1 β€ t β€ 10^4) β the number of test cases in the input. Next, the test cases are given.
Each test case consists of one non-empty string s. Its length does not exceed 1.5β
10^5. The string s consists only of lowercase Latin letters.
It is guaranteed that the sum of lengths of all lines for all input data in the test does not exceed 1.5β
10^6.
Output
Print an answer for each test case in the input in order of their appearance.
The first line of each answer should contain r (0 β€ r β€ |s|) β the required minimum number of positions to be removed, where |s| is the length of the given line. The second line of each answer should contain r different integers β the indices themselves for removal in any order. Indices are numbered from left to right from 1 to the length of the string. If r=0, then the second line can be skipped (or you can print empty). If there are several answers, print any of them.
Examples
Input
4
onetwone
testme
oneoneone
twotwo
Output
2
6 3
0
3
4 1 7
2
1 4
Input
10
onetwonetwooneooonetwooo
two
one
twooooo
ttttwo
ttwwoo
ooone
onnne
oneeeee
oneeeeeeetwooooo
Output
6
18 11 12 1 6 21
1
1
1
3
1
2
1
6
0
1
4
0
1
1
2
1 11
Note
In the first example, answers are:
* "onetwone",
* "testme" β Polycarp likes it, there is nothing to remove,
* "oneoneone",
* "twotwo".
In the second example, answers are:
* "onetwonetwooneooonetwooo",
* "two",
* "one",
* "twooooo",
* "ttttwo",
* "ttwwoo" β Polycarp likes it, there is nothing to remove,
* "ooone",
* "onnne" β Polycarp likes it, there is nothing to remove,
* "oneeeee",
* "oneeeeeeetwooooo".
Tags: dp, greedy
Correct Solution:
```
from sys import stdin as inp
from math import gcd,sqrt,floor,ceil,log2
from bisect import bisect_left as bi
for _ in range(int(inp.readline())):
s = list(inp.readline().strip())
n = len(s)
ind = []
c = 0
for i in range(n-4):
if s[i:i+5] == list('twone'):
ind.append(i+2)
s[i+2] = ''
c = 0
i = 0
while i<n-2:
x = ''
j = i
while len(x)<3 and j<n:
x += s[j]
j += 1
if x=='one' or x=='two':
ind.append(i+1)
s[i+1] = ''
i += 2
else:
i += 1
# print(''.join(s))
print(len(ind))
for i in range(len(ind)):
ind[i] += 1
print(*ind)
```
| 80,931 | [
0.16650390625,
0.399169921875,
0.400634765625,
0.15625,
-0.73388671875,
-0.303955078125,
-0.266845703125,
0.049041748046875,
0.1688232421875,
0.6904296875,
1.0546875,
0.032623291015625,
-0.017913818359375,
-1.0634765625,
-0.72509765625,
-0.003589630126953125,
-0.35205078125,
-0.334... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a non-empty string s=s_1s_2... s_n, which consists only of lowercase Latin letters. Polycarp does not like a string if it contains at least one string "one" or at least one string "two" (or both at the same time) as a substring. In other words, Polycarp does not like the string s if there is an integer j (1 β€ j β€ n-2), that s_{j}s_{j+1}s_{j+2}="one" or s_{j}s_{j+1}s_{j+2}="two".
For example:
* Polycarp does not like strings "oneee", "ontwow", "twone" and "oneonetwo" (they all have at least one substring "one" or "two"),
* Polycarp likes strings "oonnee", "twwwo" and "twnoe" (they have no substrings "one" and "two").
Polycarp wants to select a certain set of indices (positions) and remove all letters on these positions. All removals are made at the same time.
For example, if the string looks like s="onetwone", then if Polycarp selects two indices 3 and 6, then "onetwone" will be selected and the result is "ontwne".
What is the minimum number of indices (positions) that Polycarp needs to select to make the string liked? What should these positions be?
Input
The first line of the input contains an integer t (1 β€ t β€ 10^4) β the number of test cases in the input. Next, the test cases are given.
Each test case consists of one non-empty string s. Its length does not exceed 1.5β
10^5. The string s consists only of lowercase Latin letters.
It is guaranteed that the sum of lengths of all lines for all input data in the test does not exceed 1.5β
10^6.
Output
Print an answer for each test case in the input in order of their appearance.
The first line of each answer should contain r (0 β€ r β€ |s|) β the required minimum number of positions to be removed, where |s| is the length of the given line. The second line of each answer should contain r different integers β the indices themselves for removal in any order. Indices are numbered from left to right from 1 to the length of the string. If r=0, then the second line can be skipped (or you can print empty). If there are several answers, print any of them.
Examples
Input
4
onetwone
testme
oneoneone
twotwo
Output
2
6 3
0
3
4 1 7
2
1 4
Input
10
onetwonetwooneooonetwooo
two
one
twooooo
ttttwo
ttwwoo
ooone
onnne
oneeeee
oneeeeeeetwooooo
Output
6
18 11 12 1 6 21
1
1
1
3
1
2
1
6
0
1
4
0
1
1
2
1 11
Note
In the first example, answers are:
* "onetwone",
* "testme" β Polycarp likes it, there is nothing to remove,
* "oneoneone",
* "twotwo".
In the second example, answers are:
* "onetwonetwooneooonetwooo",
* "two",
* "one",
* "twooooo",
* "ttttwo",
* "ttwwoo" β Polycarp likes it, there is nothing to remove,
* "ooone",
* "onnne" β Polycarp likes it, there is nothing to remove,
* "oneeeee",
* "oneeeeeeetwooooo".
Tags: dp, greedy
Correct Solution:
```
#!/usr/bin/env python3
import sys
#lines = stdin.readlines()
def rint():
return map(int, sys.stdin.readline().split())
def input():
return sys.stdin.readline().rstrip('\n')
def oint():
return int(input())
t = oint()
one = list("one")
two = list("two")
twone = list("twone")
for _ in range(t):
s = list(input())
#print(s)
l = len(s)
cnt = 0
p = []
for i in range(l-2):
if s[i:i+3] == one:
cnt += 1
p.append(i+2)
elif s[i:i+3] == two:
if i + 4 < l:
if s[i:i+5] == twone:
s[i+2] = 'x'
p.append(i+1+2)
else:
p.append(i+2)
cnt += 1
else:
cnt += 1
p.append(i+2)
print(cnt)
print(*p)
```
| 80,932 | [
0.16650390625,
0.399169921875,
0.400634765625,
0.15625,
-0.73388671875,
-0.303955078125,
-0.266845703125,
0.049041748046875,
0.1688232421875,
0.6904296875,
1.0546875,
0.032623291015625,
-0.017913818359375,
-1.0634765625,
-0.72509765625,
-0.003589630126953125,
-0.35205078125,
-0.334... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a non-empty string s=s_1s_2... s_n, which consists only of lowercase Latin letters. Polycarp does not like a string if it contains at least one string "one" or at least one string "two" (or both at the same time) as a substring. In other words, Polycarp does not like the string s if there is an integer j (1 β€ j β€ n-2), that s_{j}s_{j+1}s_{j+2}="one" or s_{j}s_{j+1}s_{j+2}="two".
For example:
* Polycarp does not like strings "oneee", "ontwow", "twone" and "oneonetwo" (they all have at least one substring "one" or "two"),
* Polycarp likes strings "oonnee", "twwwo" and "twnoe" (they have no substrings "one" and "two").
Polycarp wants to select a certain set of indices (positions) and remove all letters on these positions. All removals are made at the same time.
For example, if the string looks like s="onetwone", then if Polycarp selects two indices 3 and 6, then "onetwone" will be selected and the result is "ontwne".
What is the minimum number of indices (positions) that Polycarp needs to select to make the string liked? What should these positions be?
Input
The first line of the input contains an integer t (1 β€ t β€ 10^4) β the number of test cases in the input. Next, the test cases are given.
Each test case consists of one non-empty string s. Its length does not exceed 1.5β
10^5. The string s consists only of lowercase Latin letters.
It is guaranteed that the sum of lengths of all lines for all input data in the test does not exceed 1.5β
10^6.
Output
Print an answer for each test case in the input in order of their appearance.
The first line of each answer should contain r (0 β€ r β€ |s|) β the required minimum number of positions to be removed, where |s| is the length of the given line. The second line of each answer should contain r different integers β the indices themselves for removal in any order. Indices are numbered from left to right from 1 to the length of the string. If r=0, then the second line can be skipped (or you can print empty). If there are several answers, print any of them.
Examples
Input
4
onetwone
testme
oneoneone
twotwo
Output
2
6 3
0
3
4 1 7
2
1 4
Input
10
onetwonetwooneooonetwooo
two
one
twooooo
ttttwo
ttwwoo
ooone
onnne
oneeeee
oneeeeeeetwooooo
Output
6
18 11 12 1 6 21
1
1
1
3
1
2
1
6
0
1
4
0
1
1
2
1 11
Note
In the first example, answers are:
* "onetwone",
* "testme" β Polycarp likes it, there is nothing to remove,
* "oneoneone",
* "twotwo".
In the second example, answers are:
* "onetwonetwooneooonetwooo",
* "two",
* "one",
* "twooooo",
* "ttttwo",
* "ttwwoo" β Polycarp likes it, there is nothing to remove,
* "ooone",
* "onnne" β Polycarp likes it, there is nothing to remove,
* "oneeeee",
* "oneeeeeeetwooooo".
Tags: dp, greedy
Correct Solution:
```
for tests in range(int(input())):
A=input()
num=0
x=[]
for s in range(len(A)-2):
if A[s:s+3]=='one':
if num==0 or x[-1]!=s+1:
x.append(s+2)
num+=1
elif A[s:s+3]=='two':
if A[s:s+5]=="twone":
x.append(s+3)
else:
x.append(s+2)
num+=1
print(num)
if num==0:
print("")
else:
print(" ".join(str(k) for k in x))
```
| 80,933 | [
0.16650390625,
0.399169921875,
0.400634765625,
0.15625,
-0.73388671875,
-0.303955078125,
-0.266845703125,
0.049041748046875,
0.1688232421875,
0.6904296875,
1.0546875,
0.032623291015625,
-0.017913818359375,
-1.0634765625,
-0.72509765625,
-0.003589630126953125,
-0.35205078125,
-0.334... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a non-empty string s=s_1s_2... s_n, which consists only of lowercase Latin letters. Polycarp does not like a string if it contains at least one string "one" or at least one string "two" (or both at the same time) as a substring. In other words, Polycarp does not like the string s if there is an integer j (1 β€ j β€ n-2), that s_{j}s_{j+1}s_{j+2}="one" or s_{j}s_{j+1}s_{j+2}="two".
For example:
* Polycarp does not like strings "oneee", "ontwow", "twone" and "oneonetwo" (they all have at least one substring "one" or "two"),
* Polycarp likes strings "oonnee", "twwwo" and "twnoe" (they have no substrings "one" and "two").
Polycarp wants to select a certain set of indices (positions) and remove all letters on these positions. All removals are made at the same time.
For example, if the string looks like s="onetwone", then if Polycarp selects two indices 3 and 6, then "onetwone" will be selected and the result is "ontwne".
What is the minimum number of indices (positions) that Polycarp needs to select to make the string liked? What should these positions be?
Input
The first line of the input contains an integer t (1 β€ t β€ 10^4) β the number of test cases in the input. Next, the test cases are given.
Each test case consists of one non-empty string s. Its length does not exceed 1.5β
10^5. The string s consists only of lowercase Latin letters.
It is guaranteed that the sum of lengths of all lines for all input data in the test does not exceed 1.5β
10^6.
Output
Print an answer for each test case in the input in order of their appearance.
The first line of each answer should contain r (0 β€ r β€ |s|) β the required minimum number of positions to be removed, where |s| is the length of the given line. The second line of each answer should contain r different integers β the indices themselves for removal in any order. Indices are numbered from left to right from 1 to the length of the string. If r=0, then the second line can be skipped (or you can print empty). If there are several answers, print any of them.
Examples
Input
4
onetwone
testme
oneoneone
twotwo
Output
2
6 3
0
3
4 1 7
2
1 4
Input
10
onetwonetwooneooonetwooo
two
one
twooooo
ttttwo
ttwwoo
ooone
onnne
oneeeee
oneeeeeeetwooooo
Output
6
18 11 12 1 6 21
1
1
1
3
1
2
1
6
0
1
4
0
1
1
2
1 11
Note
In the first example, answers are:
* "onetwone",
* "testme" β Polycarp likes it, there is nothing to remove,
* "oneoneone",
* "twotwo".
In the second example, answers are:
* "onetwonetwooneooonetwooo",
* "two",
* "one",
* "twooooo",
* "ttttwo",
* "ttwwoo" β Polycarp likes it, there is nothing to remove,
* "ooone",
* "onnne" β Polycarp likes it, there is nothing to remove,
* "oneeeee",
* "oneeeeeeetwooooo".
Tags: dp, greedy
Correct Solution:
```
for _ in range(int(input())):
s=list(input())
ans=[]
for i in range(len(s)-2):
a,b,c=s[i],s[i+1],s[i+2]
if a+b+c=='one':ans.append(i+2);s[i+1]='#'
elif a+b+c=='two':
if i<len(s)-4:
d,e=s[i+3],s[i+4]
if d+e=='ne':ans.append(i+3);s[i+2]='#'
else:
ans.append(i + 2);s[i + 1] = '#'
else:ans.append(i+2);s[i+1]='#'
print(len(ans))
print(*ans)
```
| 80,934 | [
0.16650390625,
0.399169921875,
0.400634765625,
0.15625,
-0.73388671875,
-0.303955078125,
-0.266845703125,
0.049041748046875,
0.1688232421875,
0.6904296875,
1.0546875,
0.032623291015625,
-0.017913818359375,
-1.0634765625,
-0.72509765625,
-0.003589630126953125,
-0.35205078125,
-0.334... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a non-empty string s=s_1s_2... s_n, which consists only of lowercase Latin letters. Polycarp does not like a string if it contains at least one string "one" or at least one string "two" (or both at the same time) as a substring. In other words, Polycarp does not like the string s if there is an integer j (1 β€ j β€ n-2), that s_{j}s_{j+1}s_{j+2}="one" or s_{j}s_{j+1}s_{j+2}="two".
For example:
* Polycarp does not like strings "oneee", "ontwow", "twone" and "oneonetwo" (they all have at least one substring "one" or "two"),
* Polycarp likes strings "oonnee", "twwwo" and "twnoe" (they have no substrings "one" and "two").
Polycarp wants to select a certain set of indices (positions) and remove all letters on these positions. All removals are made at the same time.
For example, if the string looks like s="onetwone", then if Polycarp selects two indices 3 and 6, then "onetwone" will be selected and the result is "ontwne".
What is the minimum number of indices (positions) that Polycarp needs to select to make the string liked? What should these positions be?
Input
The first line of the input contains an integer t (1 β€ t β€ 10^4) β the number of test cases in the input. Next, the test cases are given.
Each test case consists of one non-empty string s. Its length does not exceed 1.5β
10^5. The string s consists only of lowercase Latin letters.
It is guaranteed that the sum of lengths of all lines for all input data in the test does not exceed 1.5β
10^6.
Output
Print an answer for each test case in the input in order of their appearance.
The first line of each answer should contain r (0 β€ r β€ |s|) β the required minimum number of positions to be removed, where |s| is the length of the given line. The second line of each answer should contain r different integers β the indices themselves for removal in any order. Indices are numbered from left to right from 1 to the length of the string. If r=0, then the second line can be skipped (or you can print empty). If there are several answers, print any of them.
Examples
Input
4
onetwone
testme
oneoneone
twotwo
Output
2
6 3
0
3
4 1 7
2
1 4
Input
10
onetwonetwooneooonetwooo
two
one
twooooo
ttttwo
ttwwoo
ooone
onnne
oneeeee
oneeeeeeetwooooo
Output
6
18 11 12 1 6 21
1
1
1
3
1
2
1
6
0
1
4
0
1
1
2
1 11
Note
In the first example, answers are:
* "onetwone",
* "testme" β Polycarp likes it, there is nothing to remove,
* "oneoneone",
* "twotwo".
In the second example, answers are:
* "onetwonetwooneooonetwooo",
* "two",
* "one",
* "twooooo",
* "ttttwo",
* "ttwwoo" β Polycarp likes it, there is nothing to remove,
* "ooone",
* "onnne" β Polycarp likes it, there is nothing to remove,
* "oneeeee",
* "oneeeeeeetwooooo".
Submitted Solution:
```
import os
import sys
from io import BytesIO, IOBase
import re
def solution(s):
res = [m.start() + 3 for m in re.finditer('twone', s)]
ss = s.replace('twone', '-----')
ones = [m.start() + 2 for m in re.finditer('one', ss)]
res.extend(ones)
two = [m.start() + 2 for m in re.finditer('two', ss)]
res.extend(two)
write(len(res))
write(*res)
def main():
for _ in range(r_int()):
s = input()
solution(s)
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
def input():
return sys.stdin.readline().rstrip("\r\n")
def write(*args, end='\n'):
for x in args:
sys.stdout.write(str(x) + ' ')
sys.stdout.write(end)
def r_array():
return [int(x) for x in input().split()]
def r_int():
return int(input())
if __name__ == "__main__":
main()
```
Yes
| 80,935 | [
0.25439453125,
0.388427734375,
0.364990234375,
0.0772705078125,
-0.74267578125,
-0.213623046875,
-0.36474609375,
0.050201416015625,
0.1407470703125,
0.61767578125,
0.92919921875,
0.01436614990234375,
-0.0092010498046875,
-1.01953125,
-0.728515625,
-0.07257080078125,
-0.3046875,
-0.... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a non-empty string s=s_1s_2... s_n, which consists only of lowercase Latin letters. Polycarp does not like a string if it contains at least one string "one" or at least one string "two" (or both at the same time) as a substring. In other words, Polycarp does not like the string s if there is an integer j (1 β€ j β€ n-2), that s_{j}s_{j+1}s_{j+2}="one" or s_{j}s_{j+1}s_{j+2}="two".
For example:
* Polycarp does not like strings "oneee", "ontwow", "twone" and "oneonetwo" (they all have at least one substring "one" or "two"),
* Polycarp likes strings "oonnee", "twwwo" and "twnoe" (they have no substrings "one" and "two").
Polycarp wants to select a certain set of indices (positions) and remove all letters on these positions. All removals are made at the same time.
For example, if the string looks like s="onetwone", then if Polycarp selects two indices 3 and 6, then "onetwone" will be selected and the result is "ontwne".
What is the minimum number of indices (positions) that Polycarp needs to select to make the string liked? What should these positions be?
Input
The first line of the input contains an integer t (1 β€ t β€ 10^4) β the number of test cases in the input. Next, the test cases are given.
Each test case consists of one non-empty string s. Its length does not exceed 1.5β
10^5. The string s consists only of lowercase Latin letters.
It is guaranteed that the sum of lengths of all lines for all input data in the test does not exceed 1.5β
10^6.
Output
Print an answer for each test case in the input in order of their appearance.
The first line of each answer should contain r (0 β€ r β€ |s|) β the required minimum number of positions to be removed, where |s| is the length of the given line. The second line of each answer should contain r different integers β the indices themselves for removal in any order. Indices are numbered from left to right from 1 to the length of the string. If r=0, then the second line can be skipped (or you can print empty). If there are several answers, print any of them.
Examples
Input
4
onetwone
testme
oneoneone
twotwo
Output
2
6 3
0
3
4 1 7
2
1 4
Input
10
onetwonetwooneooonetwooo
two
one
twooooo
ttttwo
ttwwoo
ooone
onnne
oneeeee
oneeeeeeetwooooo
Output
6
18 11 12 1 6 21
1
1
1
3
1
2
1
6
0
1
4
0
1
1
2
1 11
Note
In the first example, answers are:
* "onetwone",
* "testme" β Polycarp likes it, there is nothing to remove,
* "oneoneone",
* "twotwo".
In the second example, answers are:
* "onetwonetwooneooonetwooo",
* "two",
* "one",
* "twooooo",
* "ttttwo",
* "ttwwoo" β Polycarp likes it, there is nothing to remove,
* "ooone",
* "onnne" β Polycarp likes it, there is nothing to remove,
* "oneeeee",
* "oneeeeeeetwooooo".
Submitted Solution:
```
# rambo_1
from math import *
from copy import *
from string import * # alpha = ascii_lowercase
from sys import stdin
from sys import maxsize
from operator import * # d = sorted(d.items(), key=itemgetter(1))
from itertools import *
from collections import Counter # d = dict(Counter(l))
from collections import defaultdict # d = defaultdict(list)
'''
4
onetwone
testme
oneoneone
twotwo
onetwonetwooneooonetwooo
'''
def solve(s):
n = len(s)
l = list(s)
one = s.count('one')
two = s.count('two')
total = one + two
llen = total*3
if(total == 0):
print(0)
print()
else:
i,ans = 0,0
L = []
s += 'zzzzz'
l = list(s)
while(i < n):
curr = ''.join(l[i:i+6])
# print("curr:",''.join(curr),len(curr),i)
if(curr == 'onetwo'):
l[i+1] = 'z'
L.append(i+2)
i += 1
ans += 1
elif(curr == 'oneone'):
l[i+1] = 'z'
L.append(i+2)
i += 1
ans += 1
elif(curr == 'twotwo'):
l[i+1] = 'z'
# print("@")
L.append(i+2)
i += 1
ans += 1
elif(l[i:i+5] == list('twone')):
# print("*",i)
l[i+2] = 'z'
L.append(i+3)
i += 1
ans += 1
elif(curr == 'onezzz'):
l[i+1] = 'z'
L.append(i+2)
i += 1
ans += 1
elif(curr == 'twozzz'):
l[i+1] = 'z'
# print("yeee")
i += 1
L.append(i+2)
ans += 1
elif(l[i:i+3] == list('two')):
l[i+1] = 'z'
L.append(i+2)
i += 1
ans += 1
elif(l[i:i+3] == list('one')):
l[i+1] = 'z'
L.append(i+2)
i += 1
ans += 1
else:
i += 1
# print("l:",''.join(l))
# print("*",''.join(l))
print(ans)
print(*L)
T = int(input())
for _ in range(T):
s = input()
solve(s)
```
Yes
| 80,936 | [
0.25439453125,
0.388427734375,
0.364990234375,
0.0772705078125,
-0.74267578125,
-0.213623046875,
-0.36474609375,
0.050201416015625,
0.1407470703125,
0.61767578125,
0.92919921875,
0.01436614990234375,
-0.0092010498046875,
-1.01953125,
-0.728515625,
-0.07257080078125,
-0.3046875,
-0.... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a non-empty string s=s_1s_2... s_n, which consists only of lowercase Latin letters. Polycarp does not like a string if it contains at least one string "one" or at least one string "two" (or both at the same time) as a substring. In other words, Polycarp does not like the string s if there is an integer j (1 β€ j β€ n-2), that s_{j}s_{j+1}s_{j+2}="one" or s_{j}s_{j+1}s_{j+2}="two".
For example:
* Polycarp does not like strings "oneee", "ontwow", "twone" and "oneonetwo" (they all have at least one substring "one" or "two"),
* Polycarp likes strings "oonnee", "twwwo" and "twnoe" (they have no substrings "one" and "two").
Polycarp wants to select a certain set of indices (positions) and remove all letters on these positions. All removals are made at the same time.
For example, if the string looks like s="onetwone", then if Polycarp selects two indices 3 and 6, then "onetwone" will be selected and the result is "ontwne".
What is the minimum number of indices (positions) that Polycarp needs to select to make the string liked? What should these positions be?
Input
The first line of the input contains an integer t (1 β€ t β€ 10^4) β the number of test cases in the input. Next, the test cases are given.
Each test case consists of one non-empty string s. Its length does not exceed 1.5β
10^5. The string s consists only of lowercase Latin letters.
It is guaranteed that the sum of lengths of all lines for all input data in the test does not exceed 1.5β
10^6.
Output
Print an answer for each test case in the input in order of their appearance.
The first line of each answer should contain r (0 β€ r β€ |s|) β the required minimum number of positions to be removed, where |s| is the length of the given line. The second line of each answer should contain r different integers β the indices themselves for removal in any order. Indices are numbered from left to right from 1 to the length of the string. If r=0, then the second line can be skipped (or you can print empty). If there are several answers, print any of them.
Examples
Input
4
onetwone
testme
oneoneone
twotwo
Output
2
6 3
0
3
4 1 7
2
1 4
Input
10
onetwonetwooneooonetwooo
two
one
twooooo
ttttwo
ttwwoo
ooone
onnne
oneeeee
oneeeeeeetwooooo
Output
6
18 11 12 1 6 21
1
1
1
3
1
2
1
6
0
1
4
0
1
1
2
1 11
Note
In the first example, answers are:
* "onetwone",
* "testme" β Polycarp likes it, there is nothing to remove,
* "oneoneone",
* "twotwo".
In the second example, answers are:
* "onetwonetwooneooonetwooo",
* "two",
* "one",
* "twooooo",
* "ttttwo",
* "ttwwoo" β Polycarp likes it, there is nothing to remove,
* "ooone",
* "onnne" β Polycarp likes it, there is nothing to remove,
* "oneeeee",
* "oneeeeeeetwooooo".
Submitted Solution:
```
# Codeforces Round #606 (Div. 2, based on Technocup 2020 Elimination Round 4)
# Problem: (C) As Simple as One and Two
# Status: Accepted
for _ in [0] * int(input()):
ins = input()
lens= len(ins)
pos = 0
answer = []
while pos < lens:
if ins[pos:pos+5] == 'twone':
answer.append(pos + 3)
pos += 5
elif ins[pos:pos+3] == 'two':
answer.append(pos + 2)
pos += 3
elif ins[pos:pos+3] == "one":
answer.append(pos + 2)
pos += 3
else:
pos += 1
print(len(answer))
print(*answer)
```
Yes
| 80,937 | [
0.25439453125,
0.388427734375,
0.364990234375,
0.0772705078125,
-0.74267578125,
-0.213623046875,
-0.36474609375,
0.050201416015625,
0.1407470703125,
0.61767578125,
0.92919921875,
0.01436614990234375,
-0.0092010498046875,
-1.01953125,
-0.728515625,
-0.07257080078125,
-0.3046875,
-0.... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a non-empty string s=s_1s_2... s_n, which consists only of lowercase Latin letters. Polycarp does not like a string if it contains at least one string "one" or at least one string "two" (or both at the same time) as a substring. In other words, Polycarp does not like the string s if there is an integer j (1 β€ j β€ n-2), that s_{j}s_{j+1}s_{j+2}="one" or s_{j}s_{j+1}s_{j+2}="two".
For example:
* Polycarp does not like strings "oneee", "ontwow", "twone" and "oneonetwo" (they all have at least one substring "one" or "two"),
* Polycarp likes strings "oonnee", "twwwo" and "twnoe" (they have no substrings "one" and "two").
Polycarp wants to select a certain set of indices (positions) and remove all letters on these positions. All removals are made at the same time.
For example, if the string looks like s="onetwone", then if Polycarp selects two indices 3 and 6, then "onetwone" will be selected and the result is "ontwne".
What is the minimum number of indices (positions) that Polycarp needs to select to make the string liked? What should these positions be?
Input
The first line of the input contains an integer t (1 β€ t β€ 10^4) β the number of test cases in the input. Next, the test cases are given.
Each test case consists of one non-empty string s. Its length does not exceed 1.5β
10^5. The string s consists only of lowercase Latin letters.
It is guaranteed that the sum of lengths of all lines for all input data in the test does not exceed 1.5β
10^6.
Output
Print an answer for each test case in the input in order of their appearance.
The first line of each answer should contain r (0 β€ r β€ |s|) β the required minimum number of positions to be removed, where |s| is the length of the given line. The second line of each answer should contain r different integers β the indices themselves for removal in any order. Indices are numbered from left to right from 1 to the length of the string. If r=0, then the second line can be skipped (or you can print empty). If there are several answers, print any of them.
Examples
Input
4
onetwone
testme
oneoneone
twotwo
Output
2
6 3
0
3
4 1 7
2
1 4
Input
10
onetwonetwooneooonetwooo
two
one
twooooo
ttttwo
ttwwoo
ooone
onnne
oneeeee
oneeeeeeetwooooo
Output
6
18 11 12 1 6 21
1
1
1
3
1
2
1
6
0
1
4
0
1
1
2
1 11
Note
In the first example, answers are:
* "onetwone",
* "testme" β Polycarp likes it, there is nothing to remove,
* "oneoneone",
* "twotwo".
In the second example, answers are:
* "onetwonetwooneooonetwooo",
* "two",
* "one",
* "twooooo",
* "ttttwo",
* "ttwwoo" β Polycarp likes it, there is nothing to remove,
* "ooone",
* "onnne" β Polycarp likes it, there is nothing to remove,
* "oneeeee",
* "oneeeeeeetwooooo".
Submitted Solution:
```
# lET's tRy ThIS...
import math
import os
import sys
#-------------------BOLT------------------#
#-------Genius----Billionare----Playboy----Philanthropist----NOT ME:D----#
input = lambda: sys.stdin.readline().strip("\r\n")
def cin(): return sys.stdin.readline().strip("\r\n")
def fora(): return list(map(int, sys.stdin.readline().strip().split()))
def string(): return sys.stdin.readline().strip()
def cout(ans): sys.stdout.write(str(ans))
def endl(): sys.stdout.write(str("\n"))
def ende(): sys.stdout.write(str(" "))
#---------ND-I-AM-IRON-MAN------------------#
def countDigit(n):
return math.floor(math.log(n, 10)+1)
def main():
for _ in range(int(input())):
#LET's sPill the BEANS
s=string()
a=[]
cnt=0
i=0
while(i<len(s)-2):
if(s[i]=='t'):
if(s[i+1]=='w'):
if(s[i+2]=='o'):
cnt+=1
if(i<len(s)-4 and s[i+3]=='n'):
if(s[i+4]=='e'):
a.append(i+3)
i+=4
else:
a.append(i+2)
i+=2
else:
a.append(i+2)
i+=2
elif(s[i]=='o'):
if(s[i+1]=='n'):
if(s[i+2]=='e'):
cnt+=1
a.append(i+2)
i+=2
i+=1
if(cnt==0):
cout(cnt)
else:
cout(cnt)
endl()
for i in a:
cout(i)
ende()
endl()
if __name__ == "__main__":
main()
```
Yes
| 80,938 | [
0.25439453125,
0.388427734375,
0.364990234375,
0.0772705078125,
-0.74267578125,
-0.213623046875,
-0.36474609375,
0.050201416015625,
0.1407470703125,
0.61767578125,
0.92919921875,
0.01436614990234375,
-0.0092010498046875,
-1.01953125,
-0.728515625,
-0.07257080078125,
-0.3046875,
-0.... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a non-empty string s=s_1s_2... s_n, which consists only of lowercase Latin letters. Polycarp does not like a string if it contains at least one string "one" or at least one string "two" (or both at the same time) as a substring. In other words, Polycarp does not like the string s if there is an integer j (1 β€ j β€ n-2), that s_{j}s_{j+1}s_{j+2}="one" or s_{j}s_{j+1}s_{j+2}="two".
For example:
* Polycarp does not like strings "oneee", "ontwow", "twone" and "oneonetwo" (they all have at least one substring "one" or "two"),
* Polycarp likes strings "oonnee", "twwwo" and "twnoe" (they have no substrings "one" and "two").
Polycarp wants to select a certain set of indices (positions) and remove all letters on these positions. All removals are made at the same time.
For example, if the string looks like s="onetwone", then if Polycarp selects two indices 3 and 6, then "onetwone" will be selected and the result is "ontwne".
What is the minimum number of indices (positions) that Polycarp needs to select to make the string liked? What should these positions be?
Input
The first line of the input contains an integer t (1 β€ t β€ 10^4) β the number of test cases in the input. Next, the test cases are given.
Each test case consists of one non-empty string s. Its length does not exceed 1.5β
10^5. The string s consists only of lowercase Latin letters.
It is guaranteed that the sum of lengths of all lines for all input data in the test does not exceed 1.5β
10^6.
Output
Print an answer for each test case in the input in order of their appearance.
The first line of each answer should contain r (0 β€ r β€ |s|) β the required minimum number of positions to be removed, where |s| is the length of the given line. The second line of each answer should contain r different integers β the indices themselves for removal in any order. Indices are numbered from left to right from 1 to the length of the string. If r=0, then the second line can be skipped (or you can print empty). If there are several answers, print any of them.
Examples
Input
4
onetwone
testme
oneoneone
twotwo
Output
2
6 3
0
3
4 1 7
2
1 4
Input
10
onetwonetwooneooonetwooo
two
one
twooooo
ttttwo
ttwwoo
ooone
onnne
oneeeee
oneeeeeeetwooooo
Output
6
18 11 12 1 6 21
1
1
1
3
1
2
1
6
0
1
4
0
1
1
2
1 11
Note
In the first example, answers are:
* "onetwone",
* "testme" β Polycarp likes it, there is nothing to remove,
* "oneoneone",
* "twotwo".
In the second example, answers are:
* "onetwonetwooneooonetwooo",
* "two",
* "one",
* "twooooo",
* "ttttwo",
* "ttwwoo" β Polycarp likes it, there is nothing to remove,
* "ooone",
* "onnne" β Polycarp likes it, there is nothing to remove,
* "oneeeee",
* "oneeeeeeetwooooo".
Submitted Solution:
```
t = int(input())
for i in range(t):
s = input()
ss = []
c = 0
j = 0
while j < len(s)-2:
if s[j:j+3] == 'one' or s[j:j+3] == 'two':
ss.append(j+1)
c = c + 1
j = j + 3
else:
j = j + 1
print(c)
print(' '.join(map(str,ss)))
```
No
| 80,939 | [
0.25439453125,
0.388427734375,
0.364990234375,
0.0772705078125,
-0.74267578125,
-0.213623046875,
-0.36474609375,
0.050201416015625,
0.1407470703125,
0.61767578125,
0.92919921875,
0.01436614990234375,
-0.0092010498046875,
-1.01953125,
-0.728515625,
-0.07257080078125,
-0.3046875,
-0.... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a non-empty string s=s_1s_2... s_n, which consists only of lowercase Latin letters. Polycarp does not like a string if it contains at least one string "one" or at least one string "two" (or both at the same time) as a substring. In other words, Polycarp does not like the string s if there is an integer j (1 β€ j β€ n-2), that s_{j}s_{j+1}s_{j+2}="one" or s_{j}s_{j+1}s_{j+2}="two".
For example:
* Polycarp does not like strings "oneee", "ontwow", "twone" and "oneonetwo" (they all have at least one substring "one" or "two"),
* Polycarp likes strings "oonnee", "twwwo" and "twnoe" (they have no substrings "one" and "two").
Polycarp wants to select a certain set of indices (positions) and remove all letters on these positions. All removals are made at the same time.
For example, if the string looks like s="onetwone", then if Polycarp selects two indices 3 and 6, then "onetwone" will be selected and the result is "ontwne".
What is the minimum number of indices (positions) that Polycarp needs to select to make the string liked? What should these positions be?
Input
The first line of the input contains an integer t (1 β€ t β€ 10^4) β the number of test cases in the input. Next, the test cases are given.
Each test case consists of one non-empty string s. Its length does not exceed 1.5β
10^5. The string s consists only of lowercase Latin letters.
It is guaranteed that the sum of lengths of all lines for all input data in the test does not exceed 1.5β
10^6.
Output
Print an answer for each test case in the input in order of their appearance.
The first line of each answer should contain r (0 β€ r β€ |s|) β the required minimum number of positions to be removed, where |s| is the length of the given line. The second line of each answer should contain r different integers β the indices themselves for removal in any order. Indices are numbered from left to right from 1 to the length of the string. If r=0, then the second line can be skipped (or you can print empty). If there are several answers, print any of them.
Examples
Input
4
onetwone
testme
oneoneone
twotwo
Output
2
6 3
0
3
4 1 7
2
1 4
Input
10
onetwonetwooneooonetwooo
two
one
twooooo
ttttwo
ttwwoo
ooone
onnne
oneeeee
oneeeeeeetwooooo
Output
6
18 11 12 1 6 21
1
1
1
3
1
2
1
6
0
1
4
0
1
1
2
1 11
Note
In the first example, answers are:
* "onetwone",
* "testme" β Polycarp likes it, there is nothing to remove,
* "oneoneone",
* "twotwo".
In the second example, answers are:
* "onetwonetwooneooonetwooo",
* "two",
* "one",
* "twooooo",
* "ttttwo",
* "ttwwoo" β Polycarp likes it, there is nothing to remove,
* "ooone",
* "onnne" β Polycarp likes it, there is nothing to remove,
* "oneeeee",
* "oneeeeeeetwooooo".
Submitted Solution:
```
for _ in range(int(input())):
old = list(input())
lst = []
i =0
while i<(len(old)-2):
if old[i]+old[i+1]+old[i+2]=='one' or old[i]+old[i+1]+old[i+2]=='two':
lst.append(i)
i+=3
else:
i+=1
print(len(lst))
if lst:
for j in lst:
print(j,end=" ")
print()
```
No
| 80,940 | [
0.25439453125,
0.388427734375,
0.364990234375,
0.0772705078125,
-0.74267578125,
-0.213623046875,
-0.36474609375,
0.050201416015625,
0.1407470703125,
0.61767578125,
0.92919921875,
0.01436614990234375,
-0.0092010498046875,
-1.01953125,
-0.728515625,
-0.07257080078125,
-0.3046875,
-0.... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a non-empty string s=s_1s_2... s_n, which consists only of lowercase Latin letters. Polycarp does not like a string if it contains at least one string "one" or at least one string "two" (or both at the same time) as a substring. In other words, Polycarp does not like the string s if there is an integer j (1 β€ j β€ n-2), that s_{j}s_{j+1}s_{j+2}="one" or s_{j}s_{j+1}s_{j+2}="two".
For example:
* Polycarp does not like strings "oneee", "ontwow", "twone" and "oneonetwo" (they all have at least one substring "one" or "two"),
* Polycarp likes strings "oonnee", "twwwo" and "twnoe" (they have no substrings "one" and "two").
Polycarp wants to select a certain set of indices (positions) and remove all letters on these positions. All removals are made at the same time.
For example, if the string looks like s="onetwone", then if Polycarp selects two indices 3 and 6, then "onetwone" will be selected and the result is "ontwne".
What is the minimum number of indices (positions) that Polycarp needs to select to make the string liked? What should these positions be?
Input
The first line of the input contains an integer t (1 β€ t β€ 10^4) β the number of test cases in the input. Next, the test cases are given.
Each test case consists of one non-empty string s. Its length does not exceed 1.5β
10^5. The string s consists only of lowercase Latin letters.
It is guaranteed that the sum of lengths of all lines for all input data in the test does not exceed 1.5β
10^6.
Output
Print an answer for each test case in the input in order of their appearance.
The first line of each answer should contain r (0 β€ r β€ |s|) β the required minimum number of positions to be removed, where |s| is the length of the given line. The second line of each answer should contain r different integers β the indices themselves for removal in any order. Indices are numbered from left to right from 1 to the length of the string. If r=0, then the second line can be skipped (or you can print empty). If there are several answers, print any of them.
Examples
Input
4
onetwone
testme
oneoneone
twotwo
Output
2
6 3
0
3
4 1 7
2
1 4
Input
10
onetwonetwooneooonetwooo
two
one
twooooo
ttttwo
ttwwoo
ooone
onnne
oneeeee
oneeeeeeetwooooo
Output
6
18 11 12 1 6 21
1
1
1
3
1
2
1
6
0
1
4
0
1
1
2
1 11
Note
In the first example, answers are:
* "onetwone",
* "testme" β Polycarp likes it, there is nothing to remove,
* "oneoneone",
* "twotwo".
In the second example, answers are:
* "onetwonetwooneooonetwooo",
* "two",
* "one",
* "twooooo",
* "ttttwo",
* "ttwwoo" β Polycarp likes it, there is nothing to remove,
* "ooone",
* "onnne" β Polycarp likes it, there is nothing to remove,
* "oneeeee",
* "oneeeeeeetwooooo".
Submitted Solution:
```
a = int(input())
for x in range(a):
b = input()
c = len(b)
d = list(b)
k = 0
h = []
if c == 1 and c == 2:
print(0)
print()
elif c == 3:
if d[0] == "o":
if d[1] == "n":
if d[2] == "e":
k += 1
d[0] = "@"
h.append(1)
elif d[2] == "o":
if d[1] == "w":
if d[0] == "t":
k += 1
d[2] = "@"
h.append(3)
for y in range(c):
if d[y] == "o":
if y == 0 or y == 1:
if d[y+1] == "n":
if d[y+2] == "e":
k += 1
d[y+2] = "@"
h.append(y+3)
elif y == c-2 or y == c-1:
if d[y-1] =="w":
if d[y-2] == "t":
k += 1
d[y-2] = "@"
h.append(y-1)
else:
if (d[y+1] == "n" and d[y+2] == "e" ) and (d[y-1] == "w" and d[y-2] == "t"):
k += 1
d[y] = "@"
h.append(y+1)
elif (d[y+1] == "n" and d[y+2] == "e" ):
k += 1
d[y+2] == "@"
h.append(y+3)
elif (d[y-1] == "w" and d[y-2] == "t"):
k += 1
d[y-2] == "@"
h.append(y-1)
print(k)
print(*h)
```
No
| 80,941 | [
0.25439453125,
0.388427734375,
0.364990234375,
0.0772705078125,
-0.74267578125,
-0.213623046875,
-0.36474609375,
0.050201416015625,
0.1407470703125,
0.61767578125,
0.92919921875,
0.01436614990234375,
-0.0092010498046875,
-1.01953125,
-0.728515625,
-0.07257080078125,
-0.3046875,
-0.... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a non-empty string s=s_1s_2... s_n, which consists only of lowercase Latin letters. Polycarp does not like a string if it contains at least one string "one" or at least one string "two" (or both at the same time) as a substring. In other words, Polycarp does not like the string s if there is an integer j (1 β€ j β€ n-2), that s_{j}s_{j+1}s_{j+2}="one" or s_{j}s_{j+1}s_{j+2}="two".
For example:
* Polycarp does not like strings "oneee", "ontwow", "twone" and "oneonetwo" (they all have at least one substring "one" or "two"),
* Polycarp likes strings "oonnee", "twwwo" and "twnoe" (they have no substrings "one" and "two").
Polycarp wants to select a certain set of indices (positions) and remove all letters on these positions. All removals are made at the same time.
For example, if the string looks like s="onetwone", then if Polycarp selects two indices 3 and 6, then "onetwone" will be selected and the result is "ontwne".
What is the minimum number of indices (positions) that Polycarp needs to select to make the string liked? What should these positions be?
Input
The first line of the input contains an integer t (1 β€ t β€ 10^4) β the number of test cases in the input. Next, the test cases are given.
Each test case consists of one non-empty string s. Its length does not exceed 1.5β
10^5. The string s consists only of lowercase Latin letters.
It is guaranteed that the sum of lengths of all lines for all input data in the test does not exceed 1.5β
10^6.
Output
Print an answer for each test case in the input in order of their appearance.
The first line of each answer should contain r (0 β€ r β€ |s|) β the required minimum number of positions to be removed, where |s| is the length of the given line. The second line of each answer should contain r different integers β the indices themselves for removal in any order. Indices are numbered from left to right from 1 to the length of the string. If r=0, then the second line can be skipped (or you can print empty). If there are several answers, print any of them.
Examples
Input
4
onetwone
testme
oneoneone
twotwo
Output
2
6 3
0
3
4 1 7
2
1 4
Input
10
onetwonetwooneooonetwooo
two
one
twooooo
ttttwo
ttwwoo
ooone
onnne
oneeeee
oneeeeeeetwooooo
Output
6
18 11 12 1 6 21
1
1
1
3
1
2
1
6
0
1
4
0
1
1
2
1 11
Note
In the first example, answers are:
* "onetwone",
* "testme" β Polycarp likes it, there is nothing to remove,
* "oneoneone",
* "twotwo".
In the second example, answers are:
* "onetwonetwooneooonetwooo",
* "two",
* "one",
* "twooooo",
* "ttttwo",
* "ttwwoo" β Polycarp likes it, there is nothing to remove,
* "ooone",
* "onnne" β Polycarp likes it, there is nothing to remove,
* "oneeeee",
* "oneeeeeeetwooooo".
Submitted Solution:
```
t = int(input())
for _ in range(t):
s = input()
one_pointer = 0
two_pointer = 0
one_counter = ['o', 'n', 'e']
two_counter = ['t', 'w', 'o']
i = 0
ans = []
while i < (len(s)):
if i == 0:
if s[i] == "o":
one_pointer += 1
elif s[i] == "t":
two_pointer += 1
else:
if s[i] == one_counter[one_pointer] or s[i] == two_counter[two_pointer]:
if one_pointer == 2 or two_pointer == 2:
if one_pointer == 2:
one_pointer -= 1
if two_pointer == 2:
two_pointer -= 1
ans.append(i+1)
i += 1
continue
else:
if s[i] == one_counter[one_pointer]:
one_pointer += 1
two_pointer = 0
if s[i] == two_counter[two_pointer]:
two_pointer += 1
one_pointer = 0
else:
if s[i] != one_counter[one_pointer]:
if s[i] == "o":
one_pointer = 1
else:
one_pointer = 0
if s[i] != two_counter[two_pointer]:
if s[i] == "t":
two_pointer = 1
else:
two_pointer = 0
i += 1
print(len(ans))
print(*ans)
```
No
| 80,942 | [
0.25439453125,
0.388427734375,
0.364990234375,
0.0772705078125,
-0.74267578125,
-0.213623046875,
-0.36474609375,
0.050201416015625,
0.1407470703125,
0.61767578125,
0.92919921875,
0.01436614990234375,
-0.0092010498046875,
-1.01953125,
-0.728515625,
-0.07257080078125,
-0.3046875,
-0.... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp has a checkered sheet of paper of size n Γ m. Polycarp painted some of cells with black, the others remained white. Inspired by Malevich's "Black Square", Polycarp wants to paint minimum possible number of white cells with black so that all black cells form a square.
You are to determine the minimum possible number of cells needed to be painted black so that the black cells form a black square with sides parallel to the painting's sides. All the cells that do not belong to the square should be white. The square's side should have positive length.
Input
The first line contains two integers n and m (1 β€ n, m β€ 100) β the sizes of the sheet.
The next n lines contain m letters 'B' or 'W' each β the description of initial cells' colors. If a letter is 'B', then the corresponding cell is painted black, otherwise it is painted white.
Output
Print the minimum number of cells needed to be painted black so that the black cells form a black square with sides parallel to the painting's sides. All the cells that do not belong to the square should be white. If it is impossible, print -1.
Examples
Input
5 4
WWWW
WWWB
WWWB
WWBB
WWWW
Output
5
Input
1 2
BB
Output
-1
Input
3 3
WWW
WWW
WWW
Output
1
Note
In the first example it is needed to paint 5 cells β (2, 2), (2, 3), (3, 2), (3, 3) and (4, 2). Then there will be a square with side equal to three, and the upper left corner in (2, 2).
In the second example all the cells are painted black and form a rectangle, so it's impossible to get a square.
In the third example all cells are colored white, so it's sufficient to color any cell black.
Tags: implementation
Correct Solution:
```
I = input
n, m = map(int, I().split())
board = []
yup, ydown, xleft, xrigth = 0, n, 0, m
for _ in range(n):
board.append(I())
for row in board:
if 'B' not in row:
yup += 1
else:
break
for row in board[::-1]:
if 'B' not in row:
ydown -= 1
else:
break
tr = list(zip(*board))
for row in tr:
if 'B' not in row:
xleft += 1
else:
break
for row in tr[::-1]:
if 'B' not in row:
xrigth -= 1
else:
break
if ydown - yup < 0:
print(1)
elif ydown - yup > m or xrigth - xleft > n:
print(-1)
else:
cnt = 0
for i in range(yup,ydown):
for j in range(xleft, xrigth):
if board[i][j]=='B':
cnt += 1
print(max(ydown - yup, xrigth - xleft) ** 2 - cnt)
```
| 81,360 | [
0.54248046875,
-0.189697265625,
0.183349609375,
0.058807373046875,
-0.393798828125,
-0.404541015625,
-0.28759765625,
-0.10675048828125,
0.155517578125,
0.6357421875,
1.0517578125,
-0.1912841796875,
0.63916015625,
-0.449951171875,
-0.1966552734375,
0.52490234375,
-0.7431640625,
-0.4... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp has a checkered sheet of paper of size n Γ m. Polycarp painted some of cells with black, the others remained white. Inspired by Malevich's "Black Square", Polycarp wants to paint minimum possible number of white cells with black so that all black cells form a square.
You are to determine the minimum possible number of cells needed to be painted black so that the black cells form a black square with sides parallel to the painting's sides. All the cells that do not belong to the square should be white. The square's side should have positive length.
Input
The first line contains two integers n and m (1 β€ n, m β€ 100) β the sizes of the sheet.
The next n lines contain m letters 'B' or 'W' each β the description of initial cells' colors. If a letter is 'B', then the corresponding cell is painted black, otherwise it is painted white.
Output
Print the minimum number of cells needed to be painted black so that the black cells form a black square with sides parallel to the painting's sides. All the cells that do not belong to the square should be white. If it is impossible, print -1.
Examples
Input
5 4
WWWW
WWWB
WWWB
WWBB
WWWW
Output
5
Input
1 2
BB
Output
-1
Input
3 3
WWW
WWW
WWW
Output
1
Note
In the first example it is needed to paint 5 cells β (2, 2), (2, 3), (3, 2), (3, 3) and (4, 2). Then there will be a square with side equal to three, and the upper left corner in (2, 2).
In the second example all the cells are painted black and form a rectangle, so it's impossible to get a square.
In the third example all cells are colored white, so it's sufficient to color any cell black.
Tags: implementation
Correct Solution:
```
import traceback
import os
import sys
from io import BytesIO, IOBase
import math
from collections import defaultdict, Counter
from functools import lru_cache
from itertools import accumulate
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
def geti():
return int(input())
def gets():
return input()
def getil():
return list(map(int, input().split()))
def getsl():
return input().split()
def getinps(s):
inps = s.split()
m = {'i': geti, 's': gets, 'il': getil, 'sl': getsl}
if len(inps) == 1: return m[s]()
return [m[k]() for k in inps]
def get2d(nrows, ncols, n=0):
return [[n] * ncols for r in range(nrows)]
def get_acc(a):
return list(accumulate(a))
def get_ncr(n, r):
if n < r: return 0
return math.factorial(n) // (math.factorial(r) * math.factorial(n-r))
def get_npr(n, r):
if n < r: return 0
return math.factorial(n) // math.factorial(r)
# sys.stdin = open('input.txt', 'r')
# sys.stdout = open('output.txt', 'w')
inf = float('inf')
mod = 10 ** 9 + 7
def main():
N, M = getinps('il')
g = [gets() for _ in range(N)]
mnr, mxr = inf, -inf
mnc, mxc = inf, -inf
ans = 0
for i in range(N):
for j in range(M):
if g[i][j] == 'B':
ans -= 1
mnr = min(mnr, i)
mxr = max(mxr, i)
mnc = min(mnc, j)
mxc = max(mxc, j)
if ans == 0: return 1
s = max(abs(mnr-mxr), abs(mnc-mxc)) + 1
if s > min(N, M): return -1
ans += s * s
return ans
try:
ans = main()
print(ans)
except Exception as e:
print(e)
traceback.print_exc()
```
| 81,361 | [
0.501953125,
-0.256591796875,
0.1563720703125,
0.0239410400390625,
-0.38330078125,
-0.322265625,
-0.24658203125,
-0.1575927734375,
0.2369384765625,
0.724609375,
0.9990234375,
-0.1756591796875,
0.6748046875,
-0.43212890625,
-0.2196044921875,
0.515625,
-0.712890625,
-0.5712890625,
... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp has a checkered sheet of paper of size n Γ m. Polycarp painted some of cells with black, the others remained white. Inspired by Malevich's "Black Square", Polycarp wants to paint minimum possible number of white cells with black so that all black cells form a square.
You are to determine the minimum possible number of cells needed to be painted black so that the black cells form a black square with sides parallel to the painting's sides. All the cells that do not belong to the square should be white. The square's side should have positive length.
Input
The first line contains two integers n and m (1 β€ n, m β€ 100) β the sizes of the sheet.
The next n lines contain m letters 'B' or 'W' each β the description of initial cells' colors. If a letter is 'B', then the corresponding cell is painted black, otherwise it is painted white.
Output
Print the minimum number of cells needed to be painted black so that the black cells form a black square with sides parallel to the painting's sides. All the cells that do not belong to the square should be white. If it is impossible, print -1.
Examples
Input
5 4
WWWW
WWWB
WWWB
WWBB
WWWW
Output
5
Input
1 2
BB
Output
-1
Input
3 3
WWW
WWW
WWW
Output
1
Note
In the first example it is needed to paint 5 cells β (2, 2), (2, 3), (3, 2), (3, 3) and (4, 2). Then there will be a square with side equal to three, and the upper left corner in (2, 2).
In the second example all the cells are painted black and form a rectangle, so it's impossible to get a square.
In the third example all cells are colored white, so it's sufficient to color any cell black.
Tags: implementation
Correct Solution:
```
n, m = map(int, input().split())
min_x = m
min_y = n
max_x = 0
max_y = 0
r = -1
s = 0
for y in range(n):
str = input()
for x in range(m):
if str[x] == 'B':
s += 1
if y < min_y:
min_y = y
if x < min_x:
min_x = x
if y > max_y:
max_y = y
if x > max_x:
max_x = x
if s > 0:
w = max_x-min_x+1
h = max_y-min_y+1
offset = abs(w-h)
if w < h:
if (offset+w) <= m:
w += offset
elif (h < w) and ((offset+h) <= n):
h += offset
if w == h:
r = w*h-s
else:
r = 1
print(r)
```
| 81,362 | [
0.51806640625,
-0.1982421875,
0.2022705078125,
0.0293121337890625,
-0.371337890625,
-0.355712890625,
-0.31640625,
-0.1300048828125,
0.16455078125,
0.6669921875,
1.0400390625,
-0.1964111328125,
0.654296875,
-0.430908203125,
-0.26171875,
0.488525390625,
-0.7421875,
-0.50634765625,
... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp has a checkered sheet of paper of size n Γ m. Polycarp painted some of cells with black, the others remained white. Inspired by Malevich's "Black Square", Polycarp wants to paint minimum possible number of white cells with black so that all black cells form a square.
You are to determine the minimum possible number of cells needed to be painted black so that the black cells form a black square with sides parallel to the painting's sides. All the cells that do not belong to the square should be white. The square's side should have positive length.
Input
The first line contains two integers n and m (1 β€ n, m β€ 100) β the sizes of the sheet.
The next n lines contain m letters 'B' or 'W' each β the description of initial cells' colors. If a letter is 'B', then the corresponding cell is painted black, otherwise it is painted white.
Output
Print the minimum number of cells needed to be painted black so that the black cells form a black square with sides parallel to the painting's sides. All the cells that do not belong to the square should be white. If it is impossible, print -1.
Examples
Input
5 4
WWWW
WWWB
WWWB
WWBB
WWWW
Output
5
Input
1 2
BB
Output
-1
Input
3 3
WWW
WWW
WWW
Output
1
Note
In the first example it is needed to paint 5 cells β (2, 2), (2, 3), (3, 2), (3, 3) and (4, 2). Then there will be a square with side equal to three, and the upper left corner in (2, 2).
In the second example all the cells are painted black and form a rectangle, so it's impossible to get a square.
In the third example all cells are colored white, so it's sufficient to color any cell black.
Tags: implementation
Correct Solution:
```
def polycarp(n, m, l):
left = min(l).find("B")
if left == -1:
return 1
right = m - min([x[::-1] for x in l]).find("B") - 1
top = bottom = -1
for i in range(n):
if l[i].find("B") != -1:
top = i
break
for i in range(n - 1, -1, -1):
if l[i].find("B") != -1:
bottom = i
break
w = right - left + 1
h = bottom - top + 1
if w > n or h > m:
return -1
r = 0
for i in range(top, bottom + 1):
for j in range(left, right + 1):
if l[i][j] == "W":
r += 1
if w > h:
r += (w - h) * w
else:
r += (h - w) * h
return r
n, m = list(map(int, input().strip().split()))
l = list()
for i in range(n):
l.append(input().strip())
print(polycarp(n, m, l))
```
| 81,363 | [
0.548828125,
-0.230224609375,
0.1866455078125,
0.0168914794921875,
-0.378173828125,
-0.333984375,
-0.31787109375,
-0.1053466796875,
0.18212890625,
0.6337890625,
1.0537109375,
-0.211669921875,
0.62744140625,
-0.413330078125,
-0.254638671875,
0.53173828125,
-0.744140625,
-0.451904296... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp has a checkered sheet of paper of size n Γ m. Polycarp painted some of cells with black, the others remained white. Inspired by Malevich's "Black Square", Polycarp wants to paint minimum possible number of white cells with black so that all black cells form a square.
You are to determine the minimum possible number of cells needed to be painted black so that the black cells form a black square with sides parallel to the painting's sides. All the cells that do not belong to the square should be white. The square's side should have positive length.
Input
The first line contains two integers n and m (1 β€ n, m β€ 100) β the sizes of the sheet.
The next n lines contain m letters 'B' or 'W' each β the description of initial cells' colors. If a letter is 'B', then the corresponding cell is painted black, otherwise it is painted white.
Output
Print the minimum number of cells needed to be painted black so that the black cells form a black square with sides parallel to the painting's sides. All the cells that do not belong to the square should be white. If it is impossible, print -1.
Examples
Input
5 4
WWWW
WWWB
WWWB
WWBB
WWWW
Output
5
Input
1 2
BB
Output
-1
Input
3 3
WWW
WWW
WWW
Output
1
Note
In the first example it is needed to paint 5 cells β (2, 2), (2, 3), (3, 2), (3, 3) and (4, 2). Then there will be a square with side equal to three, and the upper left corner in (2, 2).
In the second example all the cells are painted black and form a rectangle, so it's impossible to get a square.
In the third example all cells are colored white, so it's sufficient to color any cell black.
Tags: implementation
Correct Solution:
```
length, width = map(int, input().strip().split());
left, right, up, down = 101, -1, 101, -1
count = 0
for i in range(length):
string = input()
for j in range(width):
if (string[j] == 'B'):
count += 1
left = min(left, j)
right = max(right, j)
up = min(up, i)
down = max(down, i)
if count == 0:
print('1')
elif right-left+1 > min(length, width) or down-up+1 > min(length,width):
print('-1')
else:
square_width = max(right-left+1, down-up+1)
print(square_width ** 2 - count)
area = length * width
```
| 81,364 | [
0.49853515625,
-0.2294921875,
0.232177734375,
0.012420654296875,
-0.3837890625,
-0.375244140625,
-0.26025390625,
-0.1387939453125,
0.1591796875,
0.66357421875,
1.04296875,
-0.1695556640625,
0.65185546875,
-0.43212890625,
-0.284912109375,
0.5048828125,
-0.75634765625,
-0.46801757812... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp has a checkered sheet of paper of size n Γ m. Polycarp painted some of cells with black, the others remained white. Inspired by Malevich's "Black Square", Polycarp wants to paint minimum possible number of white cells with black so that all black cells form a square.
You are to determine the minimum possible number of cells needed to be painted black so that the black cells form a black square with sides parallel to the painting's sides. All the cells that do not belong to the square should be white. The square's side should have positive length.
Input
The first line contains two integers n and m (1 β€ n, m β€ 100) β the sizes of the sheet.
The next n lines contain m letters 'B' or 'W' each β the description of initial cells' colors. If a letter is 'B', then the corresponding cell is painted black, otherwise it is painted white.
Output
Print the minimum number of cells needed to be painted black so that the black cells form a black square with sides parallel to the painting's sides. All the cells that do not belong to the square should be white. If it is impossible, print -1.
Examples
Input
5 4
WWWW
WWWB
WWWB
WWBB
WWWW
Output
5
Input
1 2
BB
Output
-1
Input
3 3
WWW
WWW
WWW
Output
1
Note
In the first example it is needed to paint 5 cells β (2, 2), (2, 3), (3, 2), (3, 3) and (4, 2). Then there will be a square with side equal to three, and the upper left corner in (2, 2).
In the second example all the cells are painted black and form a rectangle, so it's impossible to get a square.
In the third example all cells are colored white, so it's sufficient to color any cell black.
Tags: implementation
Correct Solution:
```
n, m = map(int, input().split())
c = []
a = []
numBlack = 0
for i in range(n):
st = str(input())
#print(st)
c.append([])
for ch in st:
c[i].append(ch)
s = []
#print(c)
for i in range(n):
a.append([0]*m)
s.append([0]*m)
for j in range(m):
if (c[i][j] == 'W'):
a[i][j] = 0
else:
a[i][j] = 1
numBlack = numBlack + a[i][j]
s[0][0] = a[0][0]
for i in range(1, n):
s[i][0] = s[i - 1][0] + a[i][0]
for j in range(1, m):
s[0][j] = s[0][j - 1] + a[0][j]
for i in range(1, n):
for j in range(1, m):
s[i][j] = s[i - 1][j] + s[i][j - 1] - s[i - 1][j - 1] + a[i][j]
#print(numBlack)
res = 123456789
for len in range(1, min(n, m) + 1):
for i in range(n - len + 1):
for j in range(m - len + 1):
square = len * len
if (i == 0):
One = 0;
else:
One = s[i - 1][j + len - 1];
Three = 0
if (j == 0):
Two = 0;
Three = 0
else:
Two = s[i + len - 1][j - 1];
if (i > 0 and j > 0): Three = s[i - 1][j - 1]
Four = s[i + len - 1][j + len - 1];
Black = Four - One - Two + Three
if (Black != numBlack): continue
#print(len, ' ',i,' ',j,' ',Black,' ', square)
cur = square - Black
res = min(res, cur)
if (res == 123456789): res = -1
print(res)
```
| 81,365 | [
0.50390625,
-0.218505859375,
0.2237548828125,
0.00611114501953125,
-0.365478515625,
-0.334716796875,
-0.310791015625,
-0.145263671875,
0.1474609375,
0.66748046875,
1.029296875,
-0.1741943359375,
0.70361328125,
-0.4345703125,
-0.24951171875,
0.488037109375,
-0.75830078125,
-0.467285... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp has a checkered sheet of paper of size n Γ m. Polycarp painted some of cells with black, the others remained white. Inspired by Malevich's "Black Square", Polycarp wants to paint minimum possible number of white cells with black so that all black cells form a square.
You are to determine the minimum possible number of cells needed to be painted black so that the black cells form a black square with sides parallel to the painting's sides. All the cells that do not belong to the square should be white. The square's side should have positive length.
Input
The first line contains two integers n and m (1 β€ n, m β€ 100) β the sizes of the sheet.
The next n lines contain m letters 'B' or 'W' each β the description of initial cells' colors. If a letter is 'B', then the corresponding cell is painted black, otherwise it is painted white.
Output
Print the minimum number of cells needed to be painted black so that the black cells form a black square with sides parallel to the painting's sides. All the cells that do not belong to the square should be white. If it is impossible, print -1.
Examples
Input
5 4
WWWW
WWWB
WWWB
WWBB
WWWW
Output
5
Input
1 2
BB
Output
-1
Input
3 3
WWW
WWW
WWW
Output
1
Note
In the first example it is needed to paint 5 cells β (2, 2), (2, 3), (3, 2), (3, 3) and (4, 2). Then there will be a square with side equal to three, and the upper left corner in (2, 2).
In the second example all the cells are painted black and form a rectangle, so it's impossible to get a square.
In the third example all cells are colored white, so it's sufficient to color any cell black.
Tags: implementation
Correct Solution:
```
n,k=map(int,input().split(' '))
b=[]
r=[]
c=[]
for i in range (n):
b.append(input())
for i in range(n):
for j in range(k):
if b[i][j]=='B':
r.append(i)
c.append(j)
if len(c)==0:
print(1)
else:
maxr=max(r)-min(r)
maxc=max(c)-min(c)
size=max(maxc,maxr)+1
if (size>n or size>k):
print(-1)
else:
print(size**2-len(c))
```
| 81,366 | [
0.51025390625,
-0.21240234375,
0.2174072265625,
0.01312255859375,
-0.369384765625,
-0.345947265625,
-0.307373046875,
-0.1280517578125,
0.156982421875,
0.68017578125,
1.0458984375,
-0.1907958984375,
0.67333984375,
-0.4189453125,
-0.24462890625,
0.50830078125,
-0.78466796875,
-0.4865... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp has a checkered sheet of paper of size n Γ m. Polycarp painted some of cells with black, the others remained white. Inspired by Malevich's "Black Square", Polycarp wants to paint minimum possible number of white cells with black so that all black cells form a square.
You are to determine the minimum possible number of cells needed to be painted black so that the black cells form a black square with sides parallel to the painting's sides. All the cells that do not belong to the square should be white. The square's side should have positive length.
Input
The first line contains two integers n and m (1 β€ n, m β€ 100) β the sizes of the sheet.
The next n lines contain m letters 'B' or 'W' each β the description of initial cells' colors. If a letter is 'B', then the corresponding cell is painted black, otherwise it is painted white.
Output
Print the minimum number of cells needed to be painted black so that the black cells form a black square with sides parallel to the painting's sides. All the cells that do not belong to the square should be white. If it is impossible, print -1.
Examples
Input
5 4
WWWW
WWWB
WWWB
WWBB
WWWW
Output
5
Input
1 2
BB
Output
-1
Input
3 3
WWW
WWW
WWW
Output
1
Note
In the first example it is needed to paint 5 cells β (2, 2), (2, 3), (3, 2), (3, 3) and (4, 2). Then there will be a square with side equal to three, and the upper left corner in (2, 2).
In the second example all the cells are painted black and form a rectangle, so it's impossible to get a square.
In the third example all cells are colored white, so it's sufficient to color any cell black.
Tags: implementation
Correct Solution:
```
n,m=map(int,input().split())
matr=[list(input()) for i in range(n)]
h1=h2=w1=w2=-1
cout=0
for i,x in enumerate(matr):
for j,y in enumerate(x):
if y=='B':
if h1==-1:
h1=h2=i
w1=w2=j
else:
h2=i
if j<w1:w1=j
if j>w2:w2=j
cout+=1
res=max(h2-h1+1,w2-w1+1)
if res>n or res>m:print(-1)
else:print(res*res-cout)
```
| 81,367 | [
0.498046875,
-0.2354736328125,
0.2005615234375,
-0.0389404296875,
-0.349365234375,
-0.324951171875,
-0.3193359375,
-0.173095703125,
0.15478515625,
0.62890625,
1.06640625,
-0.1468505859375,
0.68505859375,
-0.477783203125,
-0.2442626953125,
0.515625,
-0.7412109375,
-0.5146484375,
-... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp, Arkady's friend, prepares to the programming competition and decides to write a contest. The contest consists of n problems and lasts for T minutes. Each of the problems is defined by two positive integers a_i and p_i β its difficulty and the score awarded by its solution.
Polycarp's experience suggests that his skill level is defined with positive real value s, and initially s=1.0. To solve the i-th problem Polycarp needs a_i/s minutes.
Polycarp loves to watch series, and before solving each of the problems he will definitely watch one episode. After Polycarp watches an episode, his skill decreases by 10\%, that is skill level s decreases to 0.9s. Each episode takes exactly 10 minutes to watch. When Polycarp decides to solve some problem, he firstly has to watch one episode, and only then he starts solving the problem without breaks for a_i/s minutes, where s is his current skill level. In calculation of a_i/s no rounding is performed, only division of integer value a_i by real value s happens.
Also, Polycarp can train for some time. If he trains for t minutes, he increases his skill by C β
t, where C is some given positive real constant. Polycarp can train only before solving any problem (and before watching series). Duration of the training can be arbitrary real value.
Polycarp is interested: what is the largest score he can get in the contest? It is allowed to solve problems in any order, while training is only allowed before solving the first problem.
Input
The first line contains one integer tc (1 β€ tc β€ 20) β the number of test cases. Then tc test cases follow.
The first line of each test contains one integer n (1 β€ n β€ 100) β the number of problems in the contest.
The second line of the test contains two real values C, T (0 < C < 10, 0 β€ T β€ 2 β
10^5), where C defines the efficiency of the training and T is the duration of the contest in minutes. Value C, T are given exactly with three digits after the decimal point.
Each of the next n lines of the test contain characteristics of the corresponding problem: two integers a_i, p_i (1 β€ a_i β€ 10^4, 1 β€ p_i β€ 10) β the difficulty and the score of the problem.
It is guaranteed that the value of T is such that changing it by the 0.001 in any direction will not change the test answer.
Please note that in hacks you can only use tc = 1.
Output
Print tc integers β the maximum possible score in each test case.
Examples
Input
2
4
1.000 31.000
12 3
20 6
30 1
5 1
3
1.000 30.000
1 10
10 10
20 8
Output
7
20
Note
In the first example, Polycarp can get score of 7 as follows:
1. Firstly he trains for 4 minutes, increasing s to the value of 5;
2. Then he decides to solve 4-th problem: he watches one episode in 10 minutes, his skill level decreases to s=5*0.9=4.5 and then he solves the problem in 5/s=5/4.5, which is roughly 1.111 minutes;
3. Finally, he decides to solve 2-nd problem: he watches one episode in 10 minutes, his skill level decreases to s=4.5*0.9=4.05 and then he solves the problem in 20/s=20/4.05, which is roughly 4.938 minutes.
This way, Polycarp uses roughly 4+10+1.111+10+4.938=30.049 minutes, to get score of 7 points. It is not possible to achieve larger score in 31 minutes.
In the second example, Polycarp can get 20 points as follows:
1. Firstly he trains for 4 minutes, increasing s to the value of 5;
2. Then he decides to solve 1-st problem: he watches one episode in 10 minutes, his skill decreases to s=5*0.9=4.5 and then he solves problem in 1/s=1/4.5, which is roughly 0.222 minutes.
3. Finally, he decides to solve 2-nd problem: he watches one episode in 10 minutes, his skill decreases to s=4.5*0.9=4.05 and then he solves the problem in 10/s=10/4.05, which is roughly 2.469 minutes.
This way, Polycarp gets score of 20 in 4+10+0.222+10+2.469=26.691 minutes. It is not possible to achieve larger score in 30 minutes.
Tags: binary search, dp, math
Correct Solution:
```
from math import sqrt
class pro(object):
def __init__(self,dif,sc):
self.dif=dif
self.sc=sc
def __lt__(self,other):
return self.dif>other.dif
T=int(input())
mul=[1]
for i in range(100):
mul.append(mul[i]*10/9)
inf=1000000007
for t in range(T):
n=int(input())
effi,tim=map(float,input().split())
prob=[]
for i in range(n):
x,y=map(int,input().split())
prob.append(pro(x,y))
prob.sort()
f=[[inf for i in range(n+1)] for j in range(1001)]
f[0][0]=0
totsc=0
for i in range(n):
totsc+=prob[i].sc
for j in range(totsc,prob[i].sc-1,-1):
for k in range(1,i+2):
f[j][k]=min(f[j][k],f[j-prob[i].sc][k-1]+prob[i].dif*mul[k])
for i in range(totsc,-1,-1):
flag=False
for j in range(n+1):
if sqrt(effi*f[i][j])>=1:
res=2*sqrt(f[i][j]/effi)-1/effi+10*j
else:
res=f[i][j]+10*j
if res<=tim:
print(i)
flag=True
break
if flag==True:
break
```
| 81,732 | [
0.6982421875,
0.357421875,
0.1942138671875,
0.2454833984375,
-0.57421875,
-0.4814453125,
-0.334228515625,
0.023040771484375,
-0.2164306640625,
0.6640625,
0.7509765625,
-0.265869140625,
0.52392578125,
-0.93505859375,
-0.5185546875,
-0.168212890625,
-0.6640625,
-0.48779296875,
-0.9... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp, Arkady's friend, prepares to the programming competition and decides to write a contest. The contest consists of n problems and lasts for T minutes. Each of the problems is defined by two positive integers a_i and p_i β its difficulty and the score awarded by its solution.
Polycarp's experience suggests that his skill level is defined with positive real value s, and initially s=1.0. To solve the i-th problem Polycarp needs a_i/s minutes.
Polycarp loves to watch series, and before solving each of the problems he will definitely watch one episode. After Polycarp watches an episode, his skill decreases by 10\%, that is skill level s decreases to 0.9s. Each episode takes exactly 10 minutes to watch. When Polycarp decides to solve some problem, he firstly has to watch one episode, and only then he starts solving the problem without breaks for a_i/s minutes, where s is his current skill level. In calculation of a_i/s no rounding is performed, only division of integer value a_i by real value s happens.
Also, Polycarp can train for some time. If he trains for t minutes, he increases his skill by C β
t, where C is some given positive real constant. Polycarp can train only before solving any problem (and before watching series). Duration of the training can be arbitrary real value.
Polycarp is interested: what is the largest score he can get in the contest? It is allowed to solve problems in any order, while training is only allowed before solving the first problem.
Input
The first line contains one integer tc (1 β€ tc β€ 20) β the number of test cases. Then tc test cases follow.
The first line of each test contains one integer n (1 β€ n β€ 100) β the number of problems in the contest.
The second line of the test contains two real values C, T (0 < C < 10, 0 β€ T β€ 2 β
10^5), where C defines the efficiency of the training and T is the duration of the contest in minutes. Value C, T are given exactly with three digits after the decimal point.
Each of the next n lines of the test contain characteristics of the corresponding problem: two integers a_i, p_i (1 β€ a_i β€ 10^4, 1 β€ p_i β€ 10) β the difficulty and the score of the problem.
It is guaranteed that the value of T is such that changing it by the 0.001 in any direction will not change the test answer.
Please note that in hacks you can only use tc = 1.
Output
Print tc integers β the maximum possible score in each test case.
Examples
Input
2
4
1.000 31.000
12 3
20 6
30 1
5 1
3
1.000 30.000
1 10
10 10
20 8
Output
7
20
Note
In the first example, Polycarp can get score of 7 as follows:
1. Firstly he trains for 4 minutes, increasing s to the value of 5;
2. Then he decides to solve 4-th problem: he watches one episode in 10 minutes, his skill level decreases to s=5*0.9=4.5 and then he solves the problem in 5/s=5/4.5, which is roughly 1.111 minutes;
3. Finally, he decides to solve 2-nd problem: he watches one episode in 10 minutes, his skill level decreases to s=4.5*0.9=4.05 and then he solves the problem in 20/s=20/4.05, which is roughly 4.938 minutes.
This way, Polycarp uses roughly 4+10+1.111+10+4.938=30.049 minutes, to get score of 7 points. It is not possible to achieve larger score in 31 minutes.
In the second example, Polycarp can get 20 points as follows:
1. Firstly he trains for 4 minutes, increasing s to the value of 5;
2. Then he decides to solve 1-st problem: he watches one episode in 10 minutes, his skill decreases to s=5*0.9=4.5 and then he solves problem in 1/s=1/4.5, which is roughly 0.222 minutes.
3. Finally, he decides to solve 2-nd problem: he watches one episode in 10 minutes, his skill decreases to s=4.5*0.9=4.05 and then he solves the problem in 10/s=10/4.05, which is roughly 2.469 minutes.
This way, Polycarp gets score of 20 in 4+10+0.222+10+2.469=26.691 minutes. It is not possible to achieve larger score in 30 minutes.
Submitted Solution:
```
import sys
from math import *
def minp():
return sys.stdin.readline().strip()
def mint():
return int(minp())
def mints():
return map(int, minp().split())
def frac(x):
a = x.split('.')
return int(a[0])*1000+int(a[1])
def solve():
n = mint()
C, T = map(frac, minp().split())
v = [None]*n
for i in range(n):
a, p = mints()
v[i] = (a, p) #, i)
v.sort(reverse=True)
dp = [[-1]*1004 for i in range(n+1)]
#z = [0]*1004
dp[0][0] = 0
idx = -1
_9 = [1]*101
_10 = [10]*101
for i in range(1,101):
_9[i] = _9[i-1]*9
_10[i] = _10[i-1]*10
for i in v:
a, p = i #[:2]
for k in range(n-1, -1, -1):
for j in range(1001-p):
if dp[k][j] >= 0:
d = dp[k][j]*9+a*_10[k]
if dp[k+1][j+p] < 0 or dp[k+1][j+p] > d:
dp[k+1][j+p] = d
for j in range(1000, -1, -1):
for k in range(n+1):
d = dp[k][j]
if d < 0:
continue
ok = False
if C*d < 250*(_9[k]):
ok = (d*1000 <= (T-k*10000)*(_9[k]))
elif (T-k*10000)*C+1000000 < 0:
ok = False
else:
ok = 4000000000*d*C <= (((T-k*10000)*C+1000000)**2)*(_9[k])
if ok:
print(j)
return
print(0)
tc = mint()
for i in range(tc):
solve()
```
No
| 81,733 | [
0.74951171875,
0.390380859375,
0.177734375,
0.175048828125,
-0.6044921875,
-0.38037109375,
-0.38818359375,
0.05755615234375,
-0.240966796875,
0.72314453125,
0.7109375,
-0.1671142578125,
0.36474609375,
-0.86181640625,
-0.448486328125,
-0.199462890625,
-0.6669921875,
-0.48681640625,
... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp, Arkady's friend, prepares to the programming competition and decides to write a contest. The contest consists of n problems and lasts for T minutes. Each of the problems is defined by two positive integers a_i and p_i β its difficulty and the score awarded by its solution.
Polycarp's experience suggests that his skill level is defined with positive real value s, and initially s=1.0. To solve the i-th problem Polycarp needs a_i/s minutes.
Polycarp loves to watch series, and before solving each of the problems he will definitely watch one episode. After Polycarp watches an episode, his skill decreases by 10\%, that is skill level s decreases to 0.9s. Each episode takes exactly 10 minutes to watch. When Polycarp decides to solve some problem, he firstly has to watch one episode, and only then he starts solving the problem without breaks for a_i/s minutes, where s is his current skill level. In calculation of a_i/s no rounding is performed, only division of integer value a_i by real value s happens.
Also, Polycarp can train for some time. If he trains for t minutes, he increases his skill by C β
t, where C is some given positive real constant. Polycarp can train only before solving any problem (and before watching series). Duration of the training can be arbitrary real value.
Polycarp is interested: what is the largest score he can get in the contest? It is allowed to solve problems in any order, while training is only allowed before solving the first problem.
Input
The first line contains one integer tc (1 β€ tc β€ 20) β the number of test cases. Then tc test cases follow.
The first line of each test contains one integer n (1 β€ n β€ 100) β the number of problems in the contest.
The second line of the test contains two real values C, T (0 < C < 10, 0 β€ T β€ 2 β
10^5), where C defines the efficiency of the training and T is the duration of the contest in minutes. Value C, T are given exactly with three digits after the decimal point.
Each of the next n lines of the test contain characteristics of the corresponding problem: two integers a_i, p_i (1 β€ a_i β€ 10^4, 1 β€ p_i β€ 10) β the difficulty and the score of the problem.
It is guaranteed that the value of T is such that changing it by the 0.001 in any direction will not change the test answer.
Please note that in hacks you can only use tc = 1.
Output
Print tc integers β the maximum possible score in each test case.
Examples
Input
2
4
1.000 31.000
12 3
20 6
30 1
5 1
3
1.000 30.000
1 10
10 10
20 8
Output
7
20
Note
In the first example, Polycarp can get score of 7 as follows:
1. Firstly he trains for 4 minutes, increasing s to the value of 5;
2. Then he decides to solve 4-th problem: he watches one episode in 10 minutes, his skill level decreases to s=5*0.9=4.5 and then he solves the problem in 5/s=5/4.5, which is roughly 1.111 minutes;
3. Finally, he decides to solve 2-nd problem: he watches one episode in 10 minutes, his skill level decreases to s=4.5*0.9=4.05 and then he solves the problem in 20/s=20/4.05, which is roughly 4.938 minutes.
This way, Polycarp uses roughly 4+10+1.111+10+4.938=30.049 minutes, to get score of 7 points. It is not possible to achieve larger score in 31 minutes.
In the second example, Polycarp can get 20 points as follows:
1. Firstly he trains for 4 minutes, increasing s to the value of 5;
2. Then he decides to solve 1-st problem: he watches one episode in 10 minutes, his skill decreases to s=5*0.9=4.5 and then he solves problem in 1/s=1/4.5, which is roughly 0.222 minutes.
3. Finally, he decides to solve 2-nd problem: he watches one episode in 10 minutes, his skill decreases to s=4.5*0.9=4.05 and then he solves the problem in 10/s=10/4.05, which is roughly 2.469 minutes.
This way, Polycarp gets score of 20 in 4+10+0.222+10+2.469=26.691 minutes. It is not possible to achieve larger score in 30 minutes.
Submitted Solution:
```
import sys
from math import *
def minp():
return sys.stdin.readline().strip()
def mint():
return int(minp())
def mints():
return map(int, minp().split())
def frac(x):
a = x.split('.')
return int(a[0])*1000+int(a[1])
def solve():
n = mint()
C, T = map(frac, minp().split())
v = [None]*n
for i in range(n):
a, p = mints()
v[i] = (a, p) #, i)
v.sort()
dp = [[-1]*1004 for i in range(n+1)]
#z = [0]*1004
dp[0][0] = 0
idx = -1
_9 = [1]*101
for i in range(1,101):
_9[i] = _9[i-1]*9
for i in v:
a, p = i #[:2]
for k in range(n-1, -1, -1):
for j in range(1001-p):
if dp[k][j] >= 0:
d = (dp[k][j]+a*_9[k])*10
if dp[k+1][j+p] < 0 or dp[k+1][j+p] > d:
dp[k+1][j+p] = d
for j in range(1000, -1, -1):
for k in range(n+1):
d = dp[k][j]
if d < 0:
continue
ok = False
if C*d < 250*(_9[k]):
ok = (d*1000 <= (T-k*10000)*(_9[k]))
elif (T-k*10000)*C+1000000 < 0:
ok = False
else:
ok = 4000000000*d*C <= (((T-k*10000)*C+1000000)**2)*(_9[k])
if ok:
print(j)
return
print(0)
tc = mint()
for i in range(tc):
solve()
```
No
| 81,734 | [
0.74951171875,
0.390380859375,
0.177734375,
0.175048828125,
-0.6044921875,
-0.38037109375,
-0.38818359375,
0.05755615234375,
-0.240966796875,
0.72314453125,
0.7109375,
-0.1671142578125,
0.36474609375,
-0.86181640625,
-0.448486328125,
-0.199462890625,
-0.6669921875,
-0.48681640625,
... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp, Arkady's friend, prepares to the programming competition and decides to write a contest. The contest consists of n problems and lasts for T minutes. Each of the problems is defined by two positive integers a_i and p_i β its difficulty and the score awarded by its solution.
Polycarp's experience suggests that his skill level is defined with positive real value s, and initially s=1.0. To solve the i-th problem Polycarp needs a_i/s minutes.
Polycarp loves to watch series, and before solving each of the problems he will definitely watch one episode. After Polycarp watches an episode, his skill decreases by 10\%, that is skill level s decreases to 0.9s. Each episode takes exactly 10 minutes to watch. When Polycarp decides to solve some problem, he firstly has to watch one episode, and only then he starts solving the problem without breaks for a_i/s minutes, where s is his current skill level. In calculation of a_i/s no rounding is performed, only division of integer value a_i by real value s happens.
Also, Polycarp can train for some time. If he trains for t minutes, he increases his skill by C β
t, where C is some given positive real constant. Polycarp can train only before solving any problem (and before watching series). Duration of the training can be arbitrary real value.
Polycarp is interested: what is the largest score he can get in the contest? It is allowed to solve problems in any order, while training is only allowed before solving the first problem.
Input
The first line contains one integer tc (1 β€ tc β€ 20) β the number of test cases. Then tc test cases follow.
The first line of each test contains one integer n (1 β€ n β€ 100) β the number of problems in the contest.
The second line of the test contains two real values C, T (0 < C < 10, 0 β€ T β€ 2 β
10^5), where C defines the efficiency of the training and T is the duration of the contest in minutes. Value C, T are given exactly with three digits after the decimal point.
Each of the next n lines of the test contain characteristics of the corresponding problem: two integers a_i, p_i (1 β€ a_i β€ 10^4, 1 β€ p_i β€ 10) β the difficulty and the score of the problem.
It is guaranteed that the value of T is such that changing it by the 0.001 in any direction will not change the test answer.
Please note that in hacks you can only use tc = 1.
Output
Print tc integers β the maximum possible score in each test case.
Examples
Input
2
4
1.000 31.000
12 3
20 6
30 1
5 1
3
1.000 30.000
1 10
10 10
20 8
Output
7
20
Note
In the first example, Polycarp can get score of 7 as follows:
1. Firstly he trains for 4 minutes, increasing s to the value of 5;
2. Then he decides to solve 4-th problem: he watches one episode in 10 minutes, his skill level decreases to s=5*0.9=4.5 and then he solves the problem in 5/s=5/4.5, which is roughly 1.111 minutes;
3. Finally, he decides to solve 2-nd problem: he watches one episode in 10 minutes, his skill level decreases to s=4.5*0.9=4.05 and then he solves the problem in 20/s=20/4.05, which is roughly 4.938 minutes.
This way, Polycarp uses roughly 4+10+1.111+10+4.938=30.049 minutes, to get score of 7 points. It is not possible to achieve larger score in 31 minutes.
In the second example, Polycarp can get 20 points as follows:
1. Firstly he trains for 4 minutes, increasing s to the value of 5;
2. Then he decides to solve 1-st problem: he watches one episode in 10 minutes, his skill decreases to s=5*0.9=4.5 and then he solves problem in 1/s=1/4.5, which is roughly 0.222 minutes.
3. Finally, he decides to solve 2-nd problem: he watches one episode in 10 minutes, his skill decreases to s=4.5*0.9=4.05 and then he solves the problem in 10/s=10/4.05, which is roughly 2.469 minutes.
This way, Polycarp gets score of 20 in 4+10+0.222+10+2.469=26.691 minutes. It is not possible to achieve larger score in 30 minutes.
Submitted Solution:
```
import sys
from math import *
def minp():
return sys.stdin.readline().strip()
def mint():
return int(minp())
def mints():
return map(int, minp().split())
def frac(x):
a = x.split('.')
return int(a[0])*1000+int(a[1])
def solve():
n = mint()
C, T = map(frac, minp().split())
v = [None]*n
for i in range(n):
a, p = mints()
v[i] = (a, p) #, i)
v.sort()
dp = [0]*1004
dk = [1000]*1004
#z = [0]*1004
dp[0] = 0
dk[0] = 0
idx = -1
_9 = [1]*101
for i in range(1,101):
_9[i] = _9[i-1]*9
for i in v:
a, p = i #[:2]
idx += 1
for j in range(1000, -1, -1):
if dk[j] >= 0 and dk[j] < 1000 and j+p <= 1000:
d = (dp[j]+a*_9[dk[j]])*10
if dk[j+p] > dk[j] + 1 \
or (dk[j+p] == dk[j] + 1 and dp[j+p] > d):
dk[j+p] = dk[j] + 1
dp[j+p] = d
#z[j+p] = idx
M = 0
#print([(dp[i],dk[i],v[z[i]][2]) for i in range(20)])
for j in range(1000, -1, -1):
if dk[j] > 100:
continue
ok = False
#t = 2*sqrt(dp[j]/(9**dk[j]*C/1000)) - 1./(C/1000)
#4*dp[j]/(9**dk[j]*C/1000) < 1./(C^2/1000000)
#dp[j]*C < 250.*(9**dk[j])
if C*dp[j] < 1000*(9**dk[j]): # dp[j]/(9**dk[k])*(C/1000) <= 1
ok = (dp[j]*1000 <= (T-dk[j]*10000)*(9**dk[j])) # ok = dk[j]*10 + dp[j]/(9**dk[j]) <= T/1000
elif (T-dk[j]*10000)*C+1000000 < 0:
ok = False
else:# ok = dk[j]*10 + 2*sqrt(dp[j]/(9**dk[j]*C/1000)) - 1./(C/1000) <= T/1000
# ok = dk[j]*10000 + 2000*sqrt(dp[j]*1000/(9**dk[j]*C)) - 1000000./C <= T
# ok = 2000*sqrt(dp[j]*1000/(9**dk[j]*C)) <= T-dk[j]*10000+1000000./C
#ok = 4000000*(dp[j]*C*1000/(9**dk[j])) <= ((T-dk[j]*10000)*C+1000000)**2
ok = 4000000000*dp[j]*C <= (((T-dk[j]*10000)*C+1000000)**2)*(9**dk[j])
if ok:
M = j
if False:
jj = j
print(dp[j], dk[j], C*dp[j], 250*(9**dk[j]))
while jj != 0:
print(v[z[jj]][2], end=' ')
jj -= v[z[jj]][1]
print()
break
print(M)
tc = mint()
for i in range(tc):
solve()
```
No
| 81,735 | [
0.74951171875,
0.390380859375,
0.177734375,
0.175048828125,
-0.6044921875,
-0.38037109375,
-0.38818359375,
0.05755615234375,
-0.240966796875,
0.72314453125,
0.7109375,
-0.1671142578125,
0.36474609375,
-0.86181640625,
-0.448486328125,
-0.199462890625,
-0.6669921875,
-0.48681640625,
... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp, Arkady's friend, prepares to the programming competition and decides to write a contest. The contest consists of n problems and lasts for T minutes. Each of the problems is defined by two positive integers a_i and p_i β its difficulty and the score awarded by its solution.
Polycarp's experience suggests that his skill level is defined with positive real value s, and initially s=1.0. To solve the i-th problem Polycarp needs a_i/s minutes.
Polycarp loves to watch series, and before solving each of the problems he will definitely watch one episode. After Polycarp watches an episode, his skill decreases by 10\%, that is skill level s decreases to 0.9s. Each episode takes exactly 10 minutes to watch. When Polycarp decides to solve some problem, he firstly has to watch one episode, and only then he starts solving the problem without breaks for a_i/s minutes, where s is his current skill level. In calculation of a_i/s no rounding is performed, only division of integer value a_i by real value s happens.
Also, Polycarp can train for some time. If he trains for t minutes, he increases his skill by C β
t, where C is some given positive real constant. Polycarp can train only before solving any problem (and before watching series). Duration of the training can be arbitrary real value.
Polycarp is interested: what is the largest score he can get in the contest? It is allowed to solve problems in any order, while training is only allowed before solving the first problem.
Input
The first line contains one integer tc (1 β€ tc β€ 20) β the number of test cases. Then tc test cases follow.
The first line of each test contains one integer n (1 β€ n β€ 100) β the number of problems in the contest.
The second line of the test contains two real values C, T (0 < C < 10, 0 β€ T β€ 2 β
10^5), where C defines the efficiency of the training and T is the duration of the contest in minutes. Value C, T are given exactly with three digits after the decimal point.
Each of the next n lines of the test contain characteristics of the corresponding problem: two integers a_i, p_i (1 β€ a_i β€ 10^4, 1 β€ p_i β€ 10) β the difficulty and the score of the problem.
It is guaranteed that the value of T is such that changing it by the 0.001 in any direction will not change the test answer.
Please note that in hacks you can only use tc = 1.
Output
Print tc integers β the maximum possible score in each test case.
Examples
Input
2
4
1.000 31.000
12 3
20 6
30 1
5 1
3
1.000 30.000
1 10
10 10
20 8
Output
7
20
Note
In the first example, Polycarp can get score of 7 as follows:
1. Firstly he trains for 4 minutes, increasing s to the value of 5;
2. Then he decides to solve 4-th problem: he watches one episode in 10 minutes, his skill level decreases to s=5*0.9=4.5 and then he solves the problem in 5/s=5/4.5, which is roughly 1.111 minutes;
3. Finally, he decides to solve 2-nd problem: he watches one episode in 10 minutes, his skill level decreases to s=4.5*0.9=4.05 and then he solves the problem in 20/s=20/4.05, which is roughly 4.938 minutes.
This way, Polycarp uses roughly 4+10+1.111+10+4.938=30.049 minutes, to get score of 7 points. It is not possible to achieve larger score in 31 minutes.
In the second example, Polycarp can get 20 points as follows:
1. Firstly he trains for 4 minutes, increasing s to the value of 5;
2. Then he decides to solve 1-st problem: he watches one episode in 10 minutes, his skill decreases to s=5*0.9=4.5 and then he solves problem in 1/s=1/4.5, which is roughly 0.222 minutes.
3. Finally, he decides to solve 2-nd problem: he watches one episode in 10 minutes, his skill decreases to s=4.5*0.9=4.05 and then he solves the problem in 10/s=10/4.05, which is roughly 2.469 minutes.
This way, Polycarp gets score of 20 in 4+10+0.222+10+2.469=26.691 minutes. It is not possible to achieve larger score in 30 minutes.
Submitted Solution:
```
import sys
from math import *
def minp():
return sys.stdin.readline().strip()
def mint():
return int(minp())
def mints():
return map(int, minp().split())
def frac(x):
a = x.split('.')
return int(a[0])*1000+int(a[1])
def solve():
n = mint()
C, T = map(frac, minp().split())
v = [None]*n
for i in range(n):
a, p = mints()
v[i] = (a, p) #, i)
v.sort()
dp = [0]*1004
dk = [1000]*1004
#z = [0]*1004
dp[0] = 0
dk[0] = 0
idx = -1
_9 = [1]*101
for i in range(1,101):
_9[i] = _9[i-1]*9
for i in v:
a, p = i #[:2]
idx += 1
for j in range(1000, -1, -1):
if dk[j] >= 0 and dk[j] < 1000 and j+p <= 1000:
d = (dp[j]+a*_9[dk[j]])*10
if dk[j+p] > dk[j] + 1 \
or (dk[j+p] == dk[j] + 1 and dp[j+p] > d):
dk[j+p] = dk[j] + 1
dp[j+p] = d
#z[j+p] = idx
M = 0
#print([(dp[i],dk[i],v[z[i]][2]) for i in range(20)])
for j in range(1000, -1, -1):
if dk[j] > 100:
continue
ok = False
#t = 2*sqrt(dp[j]/(9**dk[j]*C/1000)) - 1./(C/1000)
#4*dp[j]/(9**dk[j]*C/1000) < 1./(C^2/1000000)
#dp[j]*C < 250.*(9**dk[j])
if C*dp[j] < 250*(9**dk[j]): # t < 0
ok = (dp[j]*1000 <= (T-dk[j]*10000)*(9**dk[j])) # ok = dk[j]*10 + dp[j]/(9**dk[j]) <= T/1000
elif (T-dk[j]*10000)*C+1000000 < 0:
ok = False
else:# ok = dk[j]*10 + 2*sqrt(dp[j]/(9**dk[j]*C/1000)) - 1./(C/1000) <= T/1000
# ok = dk[j]*10000 + 2000*sqrt(dp[j]*1000/(9**dk[j]*C)) - 1000000./C <= T
# ok = 2000*sqrt(dp[j]*1000/(9**dk[j]*C)) <= T-dk[j]*10000+1000000./C
#ok = 4000000*(dp[j]*C*1000/(9**dk[j])) <= ((T-dk[j]*10000)*C+1000000)**2
ok = 4000000000*dp[j]*C <= (((T-dk[j]*10000)*C+1000000)**2)*(9**dk[j])
if ok:
M = j
if False:
jj = j
print(dp[j], dk[j], C*dp[j], 250*(9**dk[j]))
while jj != 0:
print(v[z[jj]][2], end=' ')
jj -= v[z[jj]][1]
print()
break
print(M)
tc = mint()
for i in range(tc):
solve()
```
No
| 81,736 | [
0.74951171875,
0.390380859375,
0.177734375,
0.175048828125,
-0.6044921875,
-0.38037109375,
-0.38818359375,
0.05755615234375,
-0.240966796875,
0.72314453125,
0.7109375,
-0.1671142578125,
0.36474609375,
-0.86181640625,
-0.448486328125,
-0.199462890625,
-0.6669921875,
-0.48681640625,
... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp has a string s[1 ... n] of length n consisting of decimal digits. Polycarp performs the following operation with the string s no more than once (i.e. he can perform operation 0 or 1 time):
* Polycarp selects two numbers i and j (1 β€ i β€ j β€ n) and removes characters from the s string at the positions i, i+1, i+2, β¦, j (i.e. removes substring s[i ... j]). More formally, Polycarp turns the string s into the string s_1 s_2 β¦ s_{i-1} s_{j+1} s_{j+2} β¦ s_{n}.
For example, the string s = "20192020" Polycarp can turn into strings:
* "2020" (in this case (i, j)=(3, 6) or (i, j)=(1, 4));
* "2019220" (in this case (i, j)=(6, 6));
* "020" (in this case (i, j)=(1, 5));
* other operations are also possible, only a few of them are listed above.
Polycarp likes the string "2020" very much, so he is wondering if it is possible to turn the string s into a string "2020" in no more than one operation? Note that you can perform zero operations.
Input
The first line contains a positive integer t (1 β€ t β€ 1000 ) β number of test cases in the test. Then t test cases follow.
The first line of each test case contains an integer n (4 β€ n β€ 200) β length of the string s. The next line contains a string s of length n consisting of decimal digits. It is allowed that the string s starts with digit 0.
Output
For each test case, output on a separate line:
* "YES" if Polycarp can turn the string s into a string "2020" in no more than one operation (i.e. he can perform 0 or 1 operation);
* "NO" otherwise.
You may print every letter of "YES" and "NO" in any case you want (so, for example, the strings yEs, yes, Yes and YES will all be recognized as positive answer).
Example
Input
6
8
20192020
8
22019020
4
2020
5
20002
6
729040
6
200200
Output
YES
YES
YES
NO
NO
NO
Note
In the first test case, Polycarp could choose i=3 and j=6.
In the second test case, Polycarp could choose i=2 and j=5.
In the third test case, Polycarp did not perform any operations with the string.
Tags: dp, implementation, strings
Correct Solution:
```
t = int(input())
for i in range(t):
n = int(input())
a = input()
if a[0] + a[n - 3] + a[n - 2] + a[n - 1] == "2020" or a[0] + a[1] + a[n - 2] + a[n - 1] == "2020" or a[0] + a[
1] + a[2] + a[3] == "2020" or a[0] + a[1] + a[2] + a[n - 1] == "2020" or a[n - 4] + a[n - 3] + a[n - 2] + a[
n - 1] == "2020":
print("YES")
else :
print("NO")
```
| 81,934 | [
0.0987548828125,
-0.25634765625,
0.268798828125,
0.0238037109375,
-0.39404296875,
-0.37646484375,
-0.35107421875,
0.0291900634765625,
0.33203125,
0.77294921875,
1.0625,
-0.33251953125,
0.1263427734375,
-0.73193359375,
-0.72021484375,
0.09112548828125,
-0.3447265625,
-0.2509765625,
... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp has a string s[1 ... n] of length n consisting of decimal digits. Polycarp performs the following operation with the string s no more than once (i.e. he can perform operation 0 or 1 time):
* Polycarp selects two numbers i and j (1 β€ i β€ j β€ n) and removes characters from the s string at the positions i, i+1, i+2, β¦, j (i.e. removes substring s[i ... j]). More formally, Polycarp turns the string s into the string s_1 s_2 β¦ s_{i-1} s_{j+1} s_{j+2} β¦ s_{n}.
For example, the string s = "20192020" Polycarp can turn into strings:
* "2020" (in this case (i, j)=(3, 6) or (i, j)=(1, 4));
* "2019220" (in this case (i, j)=(6, 6));
* "020" (in this case (i, j)=(1, 5));
* other operations are also possible, only a few of them are listed above.
Polycarp likes the string "2020" very much, so he is wondering if it is possible to turn the string s into a string "2020" in no more than one operation? Note that you can perform zero operations.
Input
The first line contains a positive integer t (1 β€ t β€ 1000 ) β number of test cases in the test. Then t test cases follow.
The first line of each test case contains an integer n (4 β€ n β€ 200) β length of the string s. The next line contains a string s of length n consisting of decimal digits. It is allowed that the string s starts with digit 0.
Output
For each test case, output on a separate line:
* "YES" if Polycarp can turn the string s into a string "2020" in no more than one operation (i.e. he can perform 0 or 1 operation);
* "NO" otherwise.
You may print every letter of "YES" and "NO" in any case you want (so, for example, the strings yEs, yes, Yes and YES will all be recognized as positive answer).
Example
Input
6
8
20192020
8
22019020
4
2020
5
20002
6
729040
6
200200
Output
YES
YES
YES
NO
NO
NO
Note
In the first test case, Polycarp could choose i=3 and j=6.
In the second test case, Polycarp could choose i=2 and j=5.
In the third test case, Polycarp did not perform any operations with the string.
Tags: dp, implementation, strings
Correct Solution:
```
for _ in range(int(input())):
n=int(input())
s=input()
flag=-1
if s[0]=="2":
flag=3
if s[1]=="0":
flag=2
if s[2]=="2":
flag=1
if s[3]=="0":
flag=0
if flag==-1:
if s[n-4:]=="2020":
print("YES")
else:
print("NO")
else:
temp="2020"
if flag==0:
print("YES")
else:
if s[n-flag:]==temp[4-flag:]:
print("YES")
else:
print("NO")
```
| 81,935 | [
0.0987548828125,
-0.25634765625,
0.268798828125,
0.0238037109375,
-0.39404296875,
-0.37646484375,
-0.35107421875,
0.0291900634765625,
0.33203125,
0.77294921875,
1.0625,
-0.33251953125,
0.1263427734375,
-0.73193359375,
-0.72021484375,
0.09112548828125,
-0.3447265625,
-0.2509765625,
... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp has a string s[1 ... n] of length n consisting of decimal digits. Polycarp performs the following operation with the string s no more than once (i.e. he can perform operation 0 or 1 time):
* Polycarp selects two numbers i and j (1 β€ i β€ j β€ n) and removes characters from the s string at the positions i, i+1, i+2, β¦, j (i.e. removes substring s[i ... j]). More formally, Polycarp turns the string s into the string s_1 s_2 β¦ s_{i-1} s_{j+1} s_{j+2} β¦ s_{n}.
For example, the string s = "20192020" Polycarp can turn into strings:
* "2020" (in this case (i, j)=(3, 6) or (i, j)=(1, 4));
* "2019220" (in this case (i, j)=(6, 6));
* "020" (in this case (i, j)=(1, 5));
* other operations are also possible, only a few of them are listed above.
Polycarp likes the string "2020" very much, so he is wondering if it is possible to turn the string s into a string "2020" in no more than one operation? Note that you can perform zero operations.
Input
The first line contains a positive integer t (1 β€ t β€ 1000 ) β number of test cases in the test. Then t test cases follow.
The first line of each test case contains an integer n (4 β€ n β€ 200) β length of the string s. The next line contains a string s of length n consisting of decimal digits. It is allowed that the string s starts with digit 0.
Output
For each test case, output on a separate line:
* "YES" if Polycarp can turn the string s into a string "2020" in no more than one operation (i.e. he can perform 0 or 1 operation);
* "NO" otherwise.
You may print every letter of "YES" and "NO" in any case you want (so, for example, the strings yEs, yes, Yes and YES will all be recognized as positive answer).
Example
Input
6
8
20192020
8
22019020
4
2020
5
20002
6
729040
6
200200
Output
YES
YES
YES
NO
NO
NO
Note
In the first test case, Polycarp could choose i=3 and j=6.
In the second test case, Polycarp could choose i=2 and j=5.
In the third test case, Polycarp did not perform any operations with the string.
Tags: dp, implementation, strings
Correct Solution:
```
t = int(input())
for ioijhjgyjvbrbgj in range (t):
n = int(input())
s = input()
if (s[0]=="2"):
if (s[1] == "0"):
if (s[2] == "2"):
if (s[3] == "0"):
print ("YES")
elif (s[n-1] == "0"):
print ("YES")
else:
print ("NO")
elif (s[n-2] == "2" and s[n-1] == "0"):
print ("YES")
else:
print ("NO")
elif (s[n-3] == "0" and s[n-2] == "2" and s[n-1] == "0"):
print ("YES")
else:
print ("NO")
elif(s[n-4] == "2" and s[n-3] == "0" and s[n-2] == "2" and s[n-1] == "0"):
print ("YES")
else:
print ("NO")
```
| 81,936 | [
0.0987548828125,
-0.25634765625,
0.268798828125,
0.0238037109375,
-0.39404296875,
-0.37646484375,
-0.35107421875,
0.0291900634765625,
0.33203125,
0.77294921875,
1.0625,
-0.33251953125,
0.1263427734375,
-0.73193359375,
-0.72021484375,
0.09112548828125,
-0.3447265625,
-0.2509765625,
... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp has a string s[1 ... n] of length n consisting of decimal digits. Polycarp performs the following operation with the string s no more than once (i.e. he can perform operation 0 or 1 time):
* Polycarp selects two numbers i and j (1 β€ i β€ j β€ n) and removes characters from the s string at the positions i, i+1, i+2, β¦, j (i.e. removes substring s[i ... j]). More formally, Polycarp turns the string s into the string s_1 s_2 β¦ s_{i-1} s_{j+1} s_{j+2} β¦ s_{n}.
For example, the string s = "20192020" Polycarp can turn into strings:
* "2020" (in this case (i, j)=(3, 6) or (i, j)=(1, 4));
* "2019220" (in this case (i, j)=(6, 6));
* "020" (in this case (i, j)=(1, 5));
* other operations are also possible, only a few of them are listed above.
Polycarp likes the string "2020" very much, so he is wondering if it is possible to turn the string s into a string "2020" in no more than one operation? Note that you can perform zero operations.
Input
The first line contains a positive integer t (1 β€ t β€ 1000 ) β number of test cases in the test. Then t test cases follow.
The first line of each test case contains an integer n (4 β€ n β€ 200) β length of the string s. The next line contains a string s of length n consisting of decimal digits. It is allowed that the string s starts with digit 0.
Output
For each test case, output on a separate line:
* "YES" if Polycarp can turn the string s into a string "2020" in no more than one operation (i.e. he can perform 0 or 1 operation);
* "NO" otherwise.
You may print every letter of "YES" and "NO" in any case you want (so, for example, the strings yEs, yes, Yes and YES will all be recognized as positive answer).
Example
Input
6
8
20192020
8
22019020
4
2020
5
20002
6
729040
6
200200
Output
YES
YES
YES
NO
NO
NO
Note
In the first test case, Polycarp could choose i=3 and j=6.
In the second test case, Polycarp could choose i=2 and j=5.
In the third test case, Polycarp did not perform any operations with the string.
Tags: dp, implementation, strings
Correct Solution:
```
t = int(input())
for _ in range(t):
n = int(input())
s = str(input())
if s == '2020':
print('YES')
continue
m = len(s)-4
flag = False
for i in range(n-m+1):
t = s[0:i]+s[i+m:]
#print(t)
if t == '2020':
flag = True
break
if flag:
print('YES')
else:
print('NO')
```
| 81,937 | [
0.0987548828125,
-0.25634765625,
0.268798828125,
0.0238037109375,
-0.39404296875,
-0.37646484375,
-0.35107421875,
0.0291900634765625,
0.33203125,
0.77294921875,
1.0625,
-0.33251953125,
0.1263427734375,
-0.73193359375,
-0.72021484375,
0.09112548828125,
-0.3447265625,
-0.2509765625,
... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp has a string s[1 ... n] of length n consisting of decimal digits. Polycarp performs the following operation with the string s no more than once (i.e. he can perform operation 0 or 1 time):
* Polycarp selects two numbers i and j (1 β€ i β€ j β€ n) and removes characters from the s string at the positions i, i+1, i+2, β¦, j (i.e. removes substring s[i ... j]). More formally, Polycarp turns the string s into the string s_1 s_2 β¦ s_{i-1} s_{j+1} s_{j+2} β¦ s_{n}.
For example, the string s = "20192020" Polycarp can turn into strings:
* "2020" (in this case (i, j)=(3, 6) or (i, j)=(1, 4));
* "2019220" (in this case (i, j)=(6, 6));
* "020" (in this case (i, j)=(1, 5));
* other operations are also possible, only a few of them are listed above.
Polycarp likes the string "2020" very much, so he is wondering if it is possible to turn the string s into a string "2020" in no more than one operation? Note that you can perform zero operations.
Input
The first line contains a positive integer t (1 β€ t β€ 1000 ) β number of test cases in the test. Then t test cases follow.
The first line of each test case contains an integer n (4 β€ n β€ 200) β length of the string s. The next line contains a string s of length n consisting of decimal digits. It is allowed that the string s starts with digit 0.
Output
For each test case, output on a separate line:
* "YES" if Polycarp can turn the string s into a string "2020" in no more than one operation (i.e. he can perform 0 or 1 operation);
* "NO" otherwise.
You may print every letter of "YES" and "NO" in any case you want (so, for example, the strings yEs, yes, Yes and YES will all be recognized as positive answer).
Example
Input
6
8
20192020
8
22019020
4
2020
5
20002
6
729040
6
200200
Output
YES
YES
YES
NO
NO
NO
Note
In the first test case, Polycarp could choose i=3 and j=6.
In the second test case, Polycarp could choose i=2 and j=5.
In the third test case, Polycarp did not perform any operations with the string.
Tags: dp, implementation, strings
Correct Solution:
```
# cook your dish here
for _ in range(int(input())):
n = int(input())
s = input()
flag = 0
if s[0] == "2" and s[n-1] == "0" and s[n-2] == "2" and s[n-3] == "0":
flag = 1
if s[0] == "2" and s[n-1] == "0" and s[n-2] == "2" and s[1] == "0":
flag = 1
if s[0] == "2" and s[1] == "0" and s[2] == "2" and s[n-1] == "0":
flag = 1
if s[0] == "2" and s[3] == "0" and s[2] == "2" and s[1] == "0":
flag = 1
if s[n-4] == "2" and s[n-1] == "0" and s[n-2] == "2" and s[n-3] == "0":
flag = 1
if flag == 1:
print("YES")
else:
print("NO")
```
| 81,938 | [
0.0987548828125,
-0.25634765625,
0.268798828125,
0.0238037109375,
-0.39404296875,
-0.37646484375,
-0.35107421875,
0.0291900634765625,
0.33203125,
0.77294921875,
1.0625,
-0.33251953125,
0.1263427734375,
-0.73193359375,
-0.72021484375,
0.09112548828125,
-0.3447265625,
-0.2509765625,
... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp has a string s[1 ... n] of length n consisting of decimal digits. Polycarp performs the following operation with the string s no more than once (i.e. he can perform operation 0 or 1 time):
* Polycarp selects two numbers i and j (1 β€ i β€ j β€ n) and removes characters from the s string at the positions i, i+1, i+2, β¦, j (i.e. removes substring s[i ... j]). More formally, Polycarp turns the string s into the string s_1 s_2 β¦ s_{i-1} s_{j+1} s_{j+2} β¦ s_{n}.
For example, the string s = "20192020" Polycarp can turn into strings:
* "2020" (in this case (i, j)=(3, 6) or (i, j)=(1, 4));
* "2019220" (in this case (i, j)=(6, 6));
* "020" (in this case (i, j)=(1, 5));
* other operations are also possible, only a few of them are listed above.
Polycarp likes the string "2020" very much, so he is wondering if it is possible to turn the string s into a string "2020" in no more than one operation? Note that you can perform zero operations.
Input
The first line contains a positive integer t (1 β€ t β€ 1000 ) β number of test cases in the test. Then t test cases follow.
The first line of each test case contains an integer n (4 β€ n β€ 200) β length of the string s. The next line contains a string s of length n consisting of decimal digits. It is allowed that the string s starts with digit 0.
Output
For each test case, output on a separate line:
* "YES" if Polycarp can turn the string s into a string "2020" in no more than one operation (i.e. he can perform 0 or 1 operation);
* "NO" otherwise.
You may print every letter of "YES" and "NO" in any case you want (so, for example, the strings yEs, yes, Yes and YES will all be recognized as positive answer).
Example
Input
6
8
20192020
8
22019020
4
2020
5
20002
6
729040
6
200200
Output
YES
YES
YES
NO
NO
NO
Note
In the first test case, Polycarp could choose i=3 and j=6.
In the second test case, Polycarp could choose i=2 and j=5.
In the third test case, Polycarp did not perform any operations with the string.
Tags: dp, implementation, strings
Correct Solution:
```
from collections import defaultdict
import bisect
from itertools import accumulate
import os
import sys
import math
from decimal import *
from io import BytesIO, IOBase
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
def input(): return sys.stdin.readline().rstrip("\r\n")
# ------------------- fast io --------------------
for _ in range(int(input())):
n=int(input())
s=list(input())
last=0
first=0
if s[0]=="2" and s[1]=="0" and s[2]=="2" and s[3]=="0":
last=1
first=1
if s[-1]=="0" and s[-2]=="2" and s[-3]=="0" and s[-4]=="2":
last=1
first=1
if s[0]=="2" and s[-1]=="0" and s[-2]=="2" and s[-3]=="0":
last=1
first=1
if s[0]=="2" and s[1]=="0" and s[2]=="2" and s[-1]=="0":
first=1
last=1
if s[0]=="2" and s[1]=="0" and s[-2]=="2" and s[-1]=="0":
first=1
last=1
if first==1 and last==1:
print("YES")
else:
print("NO")
```
| 81,939 | [
0.0987548828125,
-0.25634765625,
0.268798828125,
0.0238037109375,
-0.39404296875,
-0.37646484375,
-0.35107421875,
0.0291900634765625,
0.33203125,
0.77294921875,
1.0625,
-0.33251953125,
0.1263427734375,
-0.73193359375,
-0.72021484375,
0.09112548828125,
-0.3447265625,
-0.2509765625,
... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp has a string s[1 ... n] of length n consisting of decimal digits. Polycarp performs the following operation with the string s no more than once (i.e. he can perform operation 0 or 1 time):
* Polycarp selects two numbers i and j (1 β€ i β€ j β€ n) and removes characters from the s string at the positions i, i+1, i+2, β¦, j (i.e. removes substring s[i ... j]). More formally, Polycarp turns the string s into the string s_1 s_2 β¦ s_{i-1} s_{j+1} s_{j+2} β¦ s_{n}.
For example, the string s = "20192020" Polycarp can turn into strings:
* "2020" (in this case (i, j)=(3, 6) or (i, j)=(1, 4));
* "2019220" (in this case (i, j)=(6, 6));
* "020" (in this case (i, j)=(1, 5));
* other operations are also possible, only a few of them are listed above.
Polycarp likes the string "2020" very much, so he is wondering if it is possible to turn the string s into a string "2020" in no more than one operation? Note that you can perform zero operations.
Input
The first line contains a positive integer t (1 β€ t β€ 1000 ) β number of test cases in the test. Then t test cases follow.
The first line of each test case contains an integer n (4 β€ n β€ 200) β length of the string s. The next line contains a string s of length n consisting of decimal digits. It is allowed that the string s starts with digit 0.
Output
For each test case, output on a separate line:
* "YES" if Polycarp can turn the string s into a string "2020" in no more than one operation (i.e. he can perform 0 or 1 operation);
* "NO" otherwise.
You may print every letter of "YES" and "NO" in any case you want (so, for example, the strings yEs, yes, Yes and YES will all be recognized as positive answer).
Example
Input
6
8
20192020
8
22019020
4
2020
5
20002
6
729040
6
200200
Output
YES
YES
YES
NO
NO
NO
Note
In the first test case, Polycarp could choose i=3 and j=6.
In the second test case, Polycarp could choose i=2 and j=5.
In the third test case, Polycarp did not perform any operations with the string.
Tags: dp, implementation, strings
Correct Solution:
```
t=int(input())
for z in range(t):
n=int(input())
s=input()
if s[:4]=="2020" or s[n-4:]=="2020":
print("YES")
elif s[0]=="2" and s[n-3:]=="020":
print("YES")
elif s[:2]=="20" and s[n-2:]=="20":
print("YES")
elif s[:3]=="202" and s[-1]=="0":
print("YES")
else:
print("NO")
```
| 81,940 | [
0.0987548828125,
-0.25634765625,
0.268798828125,
0.0238037109375,
-0.39404296875,
-0.37646484375,
-0.35107421875,
0.0291900634765625,
0.33203125,
0.77294921875,
1.0625,
-0.33251953125,
0.1263427734375,
-0.73193359375,
-0.72021484375,
0.09112548828125,
-0.3447265625,
-0.2509765625,
... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp has a string s[1 ... n] of length n consisting of decimal digits. Polycarp performs the following operation with the string s no more than once (i.e. he can perform operation 0 or 1 time):
* Polycarp selects two numbers i and j (1 β€ i β€ j β€ n) and removes characters from the s string at the positions i, i+1, i+2, β¦, j (i.e. removes substring s[i ... j]). More formally, Polycarp turns the string s into the string s_1 s_2 β¦ s_{i-1} s_{j+1} s_{j+2} β¦ s_{n}.
For example, the string s = "20192020" Polycarp can turn into strings:
* "2020" (in this case (i, j)=(3, 6) or (i, j)=(1, 4));
* "2019220" (in this case (i, j)=(6, 6));
* "020" (in this case (i, j)=(1, 5));
* other operations are also possible, only a few of them are listed above.
Polycarp likes the string "2020" very much, so he is wondering if it is possible to turn the string s into a string "2020" in no more than one operation? Note that you can perform zero operations.
Input
The first line contains a positive integer t (1 β€ t β€ 1000 ) β number of test cases in the test. Then t test cases follow.
The first line of each test case contains an integer n (4 β€ n β€ 200) β length of the string s. The next line contains a string s of length n consisting of decimal digits. It is allowed that the string s starts with digit 0.
Output
For each test case, output on a separate line:
* "YES" if Polycarp can turn the string s into a string "2020" in no more than one operation (i.e. he can perform 0 or 1 operation);
* "NO" otherwise.
You may print every letter of "YES" and "NO" in any case you want (so, for example, the strings yEs, yes, Yes and YES will all be recognized as positive answer).
Example
Input
6
8
20192020
8
22019020
4
2020
5
20002
6
729040
6
200200
Output
YES
YES
YES
NO
NO
NO
Note
In the first test case, Polycarp could choose i=3 and j=6.
In the second test case, Polycarp could choose i=2 and j=5.
In the third test case, Polycarp did not perform any operations with the string.
Tags: dp, implementation, strings
Correct Solution:
```
for _ in range(int(input())):
n=int(input())
s=list(input())
if (s[0]=='2' and s[1]=='0' and s[2]=='2' and s[3]=='0') or (s[0]=='2' and s[1]=='0' and s[2]=='2' and s[-1]=='0') or (s[0]=='2' and s[1]=='0' and s[-2]=='2' and s[-1]=='0')or (s[0]=='2' and s[-3]=='0' and s[-2]=='2' and s[-1]=='0') or (s[-4]=='2' and s[-3]=='0' and s[-2]=='2' and s[-1]=='0'):
print('YES')
else:
print('NO')
```
| 81,941 | [
0.0987548828125,
-0.25634765625,
0.268798828125,
0.0238037109375,
-0.39404296875,
-0.37646484375,
-0.35107421875,
0.0291900634765625,
0.33203125,
0.77294921875,
1.0625,
-0.33251953125,
0.1263427734375,
-0.73193359375,
-0.72021484375,
0.09112548828125,
-0.3447265625,
-0.2509765625,
... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp has a string s[1 ... n] of length n consisting of decimal digits. Polycarp performs the following operation with the string s no more than once (i.e. he can perform operation 0 or 1 time):
* Polycarp selects two numbers i and j (1 β€ i β€ j β€ n) and removes characters from the s string at the positions i, i+1, i+2, β¦, j (i.e. removes substring s[i ... j]). More formally, Polycarp turns the string s into the string s_1 s_2 β¦ s_{i-1} s_{j+1} s_{j+2} β¦ s_{n}.
For example, the string s = "20192020" Polycarp can turn into strings:
* "2020" (in this case (i, j)=(3, 6) or (i, j)=(1, 4));
* "2019220" (in this case (i, j)=(6, 6));
* "020" (in this case (i, j)=(1, 5));
* other operations are also possible, only a few of them are listed above.
Polycarp likes the string "2020" very much, so he is wondering if it is possible to turn the string s into a string "2020" in no more than one operation? Note that you can perform zero operations.
Input
The first line contains a positive integer t (1 β€ t β€ 1000 ) β number of test cases in the test. Then t test cases follow.
The first line of each test case contains an integer n (4 β€ n β€ 200) β length of the string s. The next line contains a string s of length n consisting of decimal digits. It is allowed that the string s starts with digit 0.
Output
For each test case, output on a separate line:
* "YES" if Polycarp can turn the string s into a string "2020" in no more than one operation (i.e. he can perform 0 or 1 operation);
* "NO" otherwise.
You may print every letter of "YES" and "NO" in any case you want (so, for example, the strings yEs, yes, Yes and YES will all be recognized as positive answer).
Example
Input
6
8
20192020
8
22019020
4
2020
5
20002
6
729040
6
200200
Output
YES
YES
YES
NO
NO
NO
Note
In the first test case, Polycarp could choose i=3 and j=6.
In the second test case, Polycarp could choose i=2 and j=5.
In the third test case, Polycarp did not perform any operations with the string.
Submitted Solution:
```
def R(): return map(int, input().split())
def L(): return list(map(int, input().split()))
def I(): return int(input())
def S(): return str(input())
for _ in range(I()):
l=I()
s=S()
fl=False
for i in range(5):
if i-1<l and l-4+i>=0 and s[0:i]+s[l-4+i:l]=='2020':
print('YES')
fl=True
break
if not fl:
print('NO')
```
Yes
| 81,942 | [
0.2403564453125,
-0.164794921875,
0.226806640625,
-0.00437164306640625,
-0.49658203125,
-0.2783203125,
-0.47705078125,
0.0830078125,
0.2059326171875,
0.72802734375,
0.9150390625,
-0.26806640625,
0.0634765625,
-0.72802734375,
-0.65576171875,
0.040863037109375,
-0.2763671875,
-0.2517... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp has a string s[1 ... n] of length n consisting of decimal digits. Polycarp performs the following operation with the string s no more than once (i.e. he can perform operation 0 or 1 time):
* Polycarp selects two numbers i and j (1 β€ i β€ j β€ n) and removes characters from the s string at the positions i, i+1, i+2, β¦, j (i.e. removes substring s[i ... j]). More formally, Polycarp turns the string s into the string s_1 s_2 β¦ s_{i-1} s_{j+1} s_{j+2} β¦ s_{n}.
For example, the string s = "20192020" Polycarp can turn into strings:
* "2020" (in this case (i, j)=(3, 6) or (i, j)=(1, 4));
* "2019220" (in this case (i, j)=(6, 6));
* "020" (in this case (i, j)=(1, 5));
* other operations are also possible, only a few of them are listed above.
Polycarp likes the string "2020" very much, so he is wondering if it is possible to turn the string s into a string "2020" in no more than one operation? Note that you can perform zero operations.
Input
The first line contains a positive integer t (1 β€ t β€ 1000 ) β number of test cases in the test. Then t test cases follow.
The first line of each test case contains an integer n (4 β€ n β€ 200) β length of the string s. The next line contains a string s of length n consisting of decimal digits. It is allowed that the string s starts with digit 0.
Output
For each test case, output on a separate line:
* "YES" if Polycarp can turn the string s into a string "2020" in no more than one operation (i.e. he can perform 0 or 1 operation);
* "NO" otherwise.
You may print every letter of "YES" and "NO" in any case you want (so, for example, the strings yEs, yes, Yes and YES will all be recognized as positive answer).
Example
Input
6
8
20192020
8
22019020
4
2020
5
20002
6
729040
6
200200
Output
YES
YES
YES
NO
NO
NO
Note
In the first test case, Polycarp could choose i=3 and j=6.
In the second test case, Polycarp could choose i=2 and j=5.
In the third test case, Polycarp did not perform any operations with the string.
Submitted Solution:
```
t = int(input())
for j in range(t):
n = int(input())
s = input()
req = '2020'
f = False
if n < 4:
pritn('no')
else:
for i in range(4):
if s[0:i] == req[0:i] and s[-1*(4-i):] == req[i:]:
print('yes')
f = True
break
if s[0:4] == '2020' and f == False:
f = True
print('yes')
if f == False:
print('no')
```
Yes
| 81,943 | [
0.2403564453125,
-0.164794921875,
0.226806640625,
-0.00437164306640625,
-0.49658203125,
-0.2783203125,
-0.47705078125,
0.0830078125,
0.2059326171875,
0.72802734375,
0.9150390625,
-0.26806640625,
0.0634765625,
-0.72802734375,
-0.65576171875,
0.040863037109375,
-0.2763671875,
-0.2517... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp has a string s[1 ... n] of length n consisting of decimal digits. Polycarp performs the following operation with the string s no more than once (i.e. he can perform operation 0 or 1 time):
* Polycarp selects two numbers i and j (1 β€ i β€ j β€ n) and removes characters from the s string at the positions i, i+1, i+2, β¦, j (i.e. removes substring s[i ... j]). More formally, Polycarp turns the string s into the string s_1 s_2 β¦ s_{i-1} s_{j+1} s_{j+2} β¦ s_{n}.
For example, the string s = "20192020" Polycarp can turn into strings:
* "2020" (in this case (i, j)=(3, 6) or (i, j)=(1, 4));
* "2019220" (in this case (i, j)=(6, 6));
* "020" (in this case (i, j)=(1, 5));
* other operations are also possible, only a few of them are listed above.
Polycarp likes the string "2020" very much, so he is wondering if it is possible to turn the string s into a string "2020" in no more than one operation? Note that you can perform zero operations.
Input
The first line contains a positive integer t (1 β€ t β€ 1000 ) β number of test cases in the test. Then t test cases follow.
The first line of each test case contains an integer n (4 β€ n β€ 200) β length of the string s. The next line contains a string s of length n consisting of decimal digits. It is allowed that the string s starts with digit 0.
Output
For each test case, output on a separate line:
* "YES" if Polycarp can turn the string s into a string "2020" in no more than one operation (i.e. he can perform 0 or 1 operation);
* "NO" otherwise.
You may print every letter of "YES" and "NO" in any case you want (so, for example, the strings yEs, yes, Yes and YES will all be recognized as positive answer).
Example
Input
6
8
20192020
8
22019020
4
2020
5
20002
6
729040
6
200200
Output
YES
YES
YES
NO
NO
NO
Note
In the first test case, Polycarp could choose i=3 and j=6.
In the second test case, Polycarp could choose i=2 and j=5.
In the third test case, Polycarp did not perform any operations with the string.
Submitted Solution:
```
for _ in range(int(input())):
n = int(input())
s = input()
# if s[0:5]=="2020":
# print("yes")
# continue
# flag = 0
if s[n - 4:n] == "2020":
print("Yes")
elif s[0] + s[n - 3:n] == "2020":
print("Yes")
elif s[0:2] + s[n - 2:n] == "2020":
print("Yes")
elif s[0:3] + s[n - 1:n] == "2020":
print("Yes")
elif s[0:4] == "2020":
print("Yes")
else:
print("NO")
```
Yes
| 81,944 | [
0.2403564453125,
-0.164794921875,
0.226806640625,
-0.00437164306640625,
-0.49658203125,
-0.2783203125,
-0.47705078125,
0.0830078125,
0.2059326171875,
0.72802734375,
0.9150390625,
-0.26806640625,
0.0634765625,
-0.72802734375,
-0.65576171875,
0.040863037109375,
-0.2763671875,
-0.2517... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp has a string s[1 ... n] of length n consisting of decimal digits. Polycarp performs the following operation with the string s no more than once (i.e. he can perform operation 0 or 1 time):
* Polycarp selects two numbers i and j (1 β€ i β€ j β€ n) and removes characters from the s string at the positions i, i+1, i+2, β¦, j (i.e. removes substring s[i ... j]). More formally, Polycarp turns the string s into the string s_1 s_2 β¦ s_{i-1} s_{j+1} s_{j+2} β¦ s_{n}.
For example, the string s = "20192020" Polycarp can turn into strings:
* "2020" (in this case (i, j)=(3, 6) or (i, j)=(1, 4));
* "2019220" (in this case (i, j)=(6, 6));
* "020" (in this case (i, j)=(1, 5));
* other operations are also possible, only a few of them are listed above.
Polycarp likes the string "2020" very much, so he is wondering if it is possible to turn the string s into a string "2020" in no more than one operation? Note that you can perform zero operations.
Input
The first line contains a positive integer t (1 β€ t β€ 1000 ) β number of test cases in the test. Then t test cases follow.
The first line of each test case contains an integer n (4 β€ n β€ 200) β length of the string s. The next line contains a string s of length n consisting of decimal digits. It is allowed that the string s starts with digit 0.
Output
For each test case, output on a separate line:
* "YES" if Polycarp can turn the string s into a string "2020" in no more than one operation (i.e. he can perform 0 or 1 operation);
* "NO" otherwise.
You may print every letter of "YES" and "NO" in any case you want (so, for example, the strings yEs, yes, Yes and YES will all be recognized as positive answer).
Example
Input
6
8
20192020
8
22019020
4
2020
5
20002
6
729040
6
200200
Output
YES
YES
YES
NO
NO
NO
Note
In the first test case, Polycarp could choose i=3 and j=6.
In the second test case, Polycarp could choose i=2 and j=5.
In the third test case, Polycarp did not perform any operations with the string.
Submitted Solution:
```
t = int(input())
while t:
n = int(input())
s = input()
if(s.startswith("2020") or s.endswith("2020") or (s.startswith("2") and s.endswith("020")) or (s.startswith("20") and s.endswith("20")) or (s.startswith("202") and s.endswith("0"))):
print("YES")
else: print("NO")
t-=1
```
Yes
| 81,945 | [
0.2403564453125,
-0.164794921875,
0.226806640625,
-0.00437164306640625,
-0.49658203125,
-0.2783203125,
-0.47705078125,
0.0830078125,
0.2059326171875,
0.72802734375,
0.9150390625,
-0.26806640625,
0.0634765625,
-0.72802734375,
-0.65576171875,
0.040863037109375,
-0.2763671875,
-0.2517... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp has a string s[1 ... n] of length n consisting of decimal digits. Polycarp performs the following operation with the string s no more than once (i.e. he can perform operation 0 or 1 time):
* Polycarp selects two numbers i and j (1 β€ i β€ j β€ n) and removes characters from the s string at the positions i, i+1, i+2, β¦, j (i.e. removes substring s[i ... j]). More formally, Polycarp turns the string s into the string s_1 s_2 β¦ s_{i-1} s_{j+1} s_{j+2} β¦ s_{n}.
For example, the string s = "20192020" Polycarp can turn into strings:
* "2020" (in this case (i, j)=(3, 6) or (i, j)=(1, 4));
* "2019220" (in this case (i, j)=(6, 6));
* "020" (in this case (i, j)=(1, 5));
* other operations are also possible, only a few of them are listed above.
Polycarp likes the string "2020" very much, so he is wondering if it is possible to turn the string s into a string "2020" in no more than one operation? Note that you can perform zero operations.
Input
The first line contains a positive integer t (1 β€ t β€ 1000 ) β number of test cases in the test. Then t test cases follow.
The first line of each test case contains an integer n (4 β€ n β€ 200) β length of the string s. The next line contains a string s of length n consisting of decimal digits. It is allowed that the string s starts with digit 0.
Output
For each test case, output on a separate line:
* "YES" if Polycarp can turn the string s into a string "2020" in no more than one operation (i.e. he can perform 0 or 1 operation);
* "NO" otherwise.
You may print every letter of "YES" and "NO" in any case you want (so, for example, the strings yEs, yes, Yes and YES will all be recognized as positive answer).
Example
Input
6
8
20192020
8
22019020
4
2020
5
20002
6
729040
6
200200
Output
YES
YES
YES
NO
NO
NO
Note
In the first test case, Polycarp could choose i=3 and j=6.
In the second test case, Polycarp could choose i=2 and j=5.
In the third test case, Polycarp did not perform any operations with the string.
Submitted Solution:
```
t=int(input())
for _i in range(t):
n=int(input())
s=input()
arr=[]
ans=""
for i in range(1,5):
ans=""
ans+=s[0:i]+s[n-4+i:]
arr.append(ans)
if("2020" in arr):
print("YES")
else:
print("NO")
```
No
| 81,946 | [
0.2403564453125,
-0.164794921875,
0.226806640625,
-0.00437164306640625,
-0.49658203125,
-0.2783203125,
-0.47705078125,
0.0830078125,
0.2059326171875,
0.72802734375,
0.9150390625,
-0.26806640625,
0.0634765625,
-0.72802734375,
-0.65576171875,
0.040863037109375,
-0.2763671875,
-0.2517... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp has a string s[1 ... n] of length n consisting of decimal digits. Polycarp performs the following operation with the string s no more than once (i.e. he can perform operation 0 or 1 time):
* Polycarp selects two numbers i and j (1 β€ i β€ j β€ n) and removes characters from the s string at the positions i, i+1, i+2, β¦, j (i.e. removes substring s[i ... j]). More formally, Polycarp turns the string s into the string s_1 s_2 β¦ s_{i-1} s_{j+1} s_{j+2} β¦ s_{n}.
For example, the string s = "20192020" Polycarp can turn into strings:
* "2020" (in this case (i, j)=(3, 6) or (i, j)=(1, 4));
* "2019220" (in this case (i, j)=(6, 6));
* "020" (in this case (i, j)=(1, 5));
* other operations are also possible, only a few of them are listed above.
Polycarp likes the string "2020" very much, so he is wondering if it is possible to turn the string s into a string "2020" in no more than one operation? Note that you can perform zero operations.
Input
The first line contains a positive integer t (1 β€ t β€ 1000 ) β number of test cases in the test. Then t test cases follow.
The first line of each test case contains an integer n (4 β€ n β€ 200) β length of the string s. The next line contains a string s of length n consisting of decimal digits. It is allowed that the string s starts with digit 0.
Output
For each test case, output on a separate line:
* "YES" if Polycarp can turn the string s into a string "2020" in no more than one operation (i.e. he can perform 0 or 1 operation);
* "NO" otherwise.
You may print every letter of "YES" and "NO" in any case you want (so, for example, the strings yEs, yes, Yes and YES will all be recognized as positive answer).
Example
Input
6
8
20192020
8
22019020
4
2020
5
20002
6
729040
6
200200
Output
YES
YES
YES
NO
NO
NO
Note
In the first test case, Polycarp could choose i=3 and j=6.
In the second test case, Polycarp could choose i=2 and j=5.
In the third test case, Polycarp did not perform any operations with the string.
Submitted Solution:
```
t = int(input())
for i in range(t):
n = int(input())
s = input()
for p in range(n):
for q in range(n):
test = s[:p-1]+s[q:]
nn = 0
if test == "2020":
print('YES')
break
test=""
if test == "2020":
test=''
break
#print(test)
```
No
| 81,947 | [
0.2403564453125,
-0.164794921875,
0.226806640625,
-0.00437164306640625,
-0.49658203125,
-0.2783203125,
-0.47705078125,
0.0830078125,
0.2059326171875,
0.72802734375,
0.9150390625,
-0.26806640625,
0.0634765625,
-0.72802734375,
-0.65576171875,
0.040863037109375,
-0.2763671875,
-0.2517... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp has a string s[1 ... n] of length n consisting of decimal digits. Polycarp performs the following operation with the string s no more than once (i.e. he can perform operation 0 or 1 time):
* Polycarp selects two numbers i and j (1 β€ i β€ j β€ n) and removes characters from the s string at the positions i, i+1, i+2, β¦, j (i.e. removes substring s[i ... j]). More formally, Polycarp turns the string s into the string s_1 s_2 β¦ s_{i-1} s_{j+1} s_{j+2} β¦ s_{n}.
For example, the string s = "20192020" Polycarp can turn into strings:
* "2020" (in this case (i, j)=(3, 6) or (i, j)=(1, 4));
* "2019220" (in this case (i, j)=(6, 6));
* "020" (in this case (i, j)=(1, 5));
* other operations are also possible, only a few of them are listed above.
Polycarp likes the string "2020" very much, so he is wondering if it is possible to turn the string s into a string "2020" in no more than one operation? Note that you can perform zero operations.
Input
The first line contains a positive integer t (1 β€ t β€ 1000 ) β number of test cases in the test. Then t test cases follow.
The first line of each test case contains an integer n (4 β€ n β€ 200) β length of the string s. The next line contains a string s of length n consisting of decimal digits. It is allowed that the string s starts with digit 0.
Output
For each test case, output on a separate line:
* "YES" if Polycarp can turn the string s into a string "2020" in no more than one operation (i.e. he can perform 0 or 1 operation);
* "NO" otherwise.
You may print every letter of "YES" and "NO" in any case you want (so, for example, the strings yEs, yes, Yes and YES will all be recognized as positive answer).
Example
Input
6
8
20192020
8
22019020
4
2020
5
20002
6
729040
6
200200
Output
YES
YES
YES
NO
NO
NO
Note
In the first test case, Polycarp could choose i=3 and j=6.
In the second test case, Polycarp could choose i=2 and j=5.
In the third test case, Polycarp did not perform any operations with the string.
Submitted Solution:
```
l2=["2020","202","20","2"]
def func():
possible=False
for k in range(len(l2)):
if l2[k] in string:
if k == 0:
possible= True
return possible
elif k==1:
c=string.find(l2[k])
c+=3
kk=string[c:]
if kk != "":
cc=kk.find("0")
if cc != -1 and cc+1 != len(kk[cc:]):
possible = True
return possible
elif k== 2:
c=string.find(l2[k])
c+=2
kk=string[c:]
if kk != "":
cc=kk.find("20")
if cc != -1 and cc+2 != len(kk[cc:]):
possible = True
return possible
elif k==3:
c=string.find(l2[k])
c+=1
kk=string[c:]
if kk != "":
cc=kk.find("020")
if cc != -1 and cc+3 != len(kk[cc:]):
possible = True
return possible
for _ in range(int(input())):
x=int(input())
string=input()
l1=list(string)
if func() == True:
print("YES")
else: print("NO")
```
No
| 81,948 | [
0.2403564453125,
-0.164794921875,
0.226806640625,
-0.00437164306640625,
-0.49658203125,
-0.2783203125,
-0.47705078125,
0.0830078125,
0.2059326171875,
0.72802734375,
0.9150390625,
-0.26806640625,
0.0634765625,
-0.72802734375,
-0.65576171875,
0.040863037109375,
-0.2763671875,
-0.2517... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp has a string s[1 ... n] of length n consisting of decimal digits. Polycarp performs the following operation with the string s no more than once (i.e. he can perform operation 0 or 1 time):
* Polycarp selects two numbers i and j (1 β€ i β€ j β€ n) and removes characters from the s string at the positions i, i+1, i+2, β¦, j (i.e. removes substring s[i ... j]). More formally, Polycarp turns the string s into the string s_1 s_2 β¦ s_{i-1} s_{j+1} s_{j+2} β¦ s_{n}.
For example, the string s = "20192020" Polycarp can turn into strings:
* "2020" (in this case (i, j)=(3, 6) or (i, j)=(1, 4));
* "2019220" (in this case (i, j)=(6, 6));
* "020" (in this case (i, j)=(1, 5));
* other operations are also possible, only a few of them are listed above.
Polycarp likes the string "2020" very much, so he is wondering if it is possible to turn the string s into a string "2020" in no more than one operation? Note that you can perform zero operations.
Input
The first line contains a positive integer t (1 β€ t β€ 1000 ) β number of test cases in the test. Then t test cases follow.
The first line of each test case contains an integer n (4 β€ n β€ 200) β length of the string s. The next line contains a string s of length n consisting of decimal digits. It is allowed that the string s starts with digit 0.
Output
For each test case, output on a separate line:
* "YES" if Polycarp can turn the string s into a string "2020" in no more than one operation (i.e. he can perform 0 or 1 operation);
* "NO" otherwise.
You may print every letter of "YES" and "NO" in any case you want (so, for example, the strings yEs, yes, Yes and YES will all be recognized as positive answer).
Example
Input
6
8
20192020
8
22019020
4
2020
5
20002
6
729040
6
200200
Output
YES
YES
YES
NO
NO
NO
Note
In the first test case, Polycarp could choose i=3 and j=6.
In the second test case, Polycarp could choose i=2 and j=5.
In the third test case, Polycarp did not perform any operations with the string.
Submitted Solution:
```
def solve(n,s):
for i in range(n):
if i>4:
#print(s[:i-4],s[i:])
if s[:i-4]+s[i:]=="2020":
return "YES"
else:
#print(s[:i],s[i+4:])
if s[:i]+s[i+4:]=="2020":
return "YES"
if s=="2020":
return "YES"
return "NO"
for _ in range(int(input())):
n=int(input())
s=input()
print(solve(n,s))
```
No
| 81,949 | [
0.2403564453125,
-0.164794921875,
0.226806640625,
-0.00437164306640625,
-0.49658203125,
-0.2783203125,
-0.47705078125,
0.0830078125,
0.2059326171875,
0.72802734375,
0.9150390625,
-0.26806640625,
0.0634765625,
-0.72802734375,
-0.65576171875,
0.040863037109375,
-0.2763671875,
-0.2517... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The only difference between easy and hard versions is the constraints.
Polycarp has to write a coursework. The coursework consists of m pages.
Polycarp also has n cups of coffee. The coffee in the i-th cup has a_i caffeine in it. Polycarp can drink some cups of coffee (each one no more than once). He can drink cups in any order. Polycarp drinks each cup instantly and completely (i.e. he cannot split any cup into several days).
Surely, courseworks are not usually being written in a single day (in a perfect world of Berland, at least). Some of them require multiple days of hard work.
Let's consider some day of Polycarp's work. Consider Polycarp drinks k cups of coffee during this day and caffeine dosages of cups Polycarp drink during this day are a_{i_1}, a_{i_2}, ..., a_{i_k}. Then the first cup he drinks gives him energy to write a_{i_1} pages of coursework, the second cup gives him energy to write max(0, a_{i_2} - 1) pages, the third cup gives him energy to write max(0, a_{i_3} - 2) pages, ..., the k-th cup gives him energy to write max(0, a_{i_k} - k + 1) pages.
If Polycarp doesn't drink coffee during some day, he cannot write coursework at all that day.
Polycarp has to finish his coursework as soon as possible (spend the minimum number of days to do it). Your task is to find out this number of days or say that it is impossible.
Input
The first line of the input contains two integers n and m (1 β€ n β€ 100, 1 β€ m β€ 10^4) β the number of cups of coffee and the number of pages in the coursework.
The second line of the input contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 100), where a_i is the caffeine dosage of coffee in the i-th cup.
Output
If it is impossible to write the coursework, print -1. Otherwise print the minimum number of days Polycarp needs to do it.
Examples
Input
5 8
2 3 1 1 2
Output
4
Input
7 10
1 3 4 2 1 4 2
Output
2
Input
5 15
5 5 5 5 5
Output
1
Input
5 16
5 5 5 5 5
Output
2
Input
5 26
5 5 5 5 5
Output
-1
Note
In the first example Polycarp can drink fourth cup during first day (and write 1 page), first and second cups during second day (and write 2 + (3 - 1) = 4 pages), fifth cup during the third day (and write 2 pages) and third cup during the fourth day (and write 1 page) so the answer is 4. It is obvious that there is no way to write the coursework in three or less days in this test.
In the second example Polycarp can drink third, fourth and second cups during first day (and write 4 + (2 - 1) + (3 - 2) = 6 pages) and sixth cup during second day (and write 4 pages) so the answer is 2. It is obvious that Polycarp cannot write the whole coursework in one day in this test.
In the third example Polycarp can drink all cups of coffee during first day and write 5 + (5 - 1) + (5 - 2) + (5 - 3) + (5 - 4) = 15 pages of coursework.
In the fourth example Polycarp cannot drink all cups during first day and should drink one of them during the second day. So during first day he will write 5 + (5 - 1) + (5 - 2) + (5 - 3) = 14 pages of coursework and during second day he will write 5 pages of coursework. This is enough to complete it.
In the fifth example Polycarp cannot write the whole coursework at all, even if he will drink one cup of coffee during each day, so the answer is -1.
Tags: brute force, greedy
Correct Solution:
```
n,s = list(map(int ,input().split()))
a = list(map(int, input().split()))
a.sort(reverse = True)
t = 0
for i in range(1,n+1) :
t = 0
for j in range (n) :
t += max(0, a[j] - j//i)
if t >= s :
print(i)
exit(0)
print(-1)
```
| 82,628 | [
0.370361328125,
0.0623779296875,
0.345458984375,
0.177001953125,
-0.3759765625,
-0.1439208984375,
-0.265380859375,
0.050323486328125,
-0.2113037109375,
0.62158203125,
1.0068359375,
0.01136016845703125,
0.5009765625,
-0.98779296875,
-0.4521484375,
0.124755859375,
-0.5927734375,
-0.7... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The only difference between easy and hard versions is the constraints.
Polycarp has to write a coursework. The coursework consists of m pages.
Polycarp also has n cups of coffee. The coffee in the i-th cup has a_i caffeine in it. Polycarp can drink some cups of coffee (each one no more than once). He can drink cups in any order. Polycarp drinks each cup instantly and completely (i.e. he cannot split any cup into several days).
Surely, courseworks are not usually being written in a single day (in a perfect world of Berland, at least). Some of them require multiple days of hard work.
Let's consider some day of Polycarp's work. Consider Polycarp drinks k cups of coffee during this day and caffeine dosages of cups Polycarp drink during this day are a_{i_1}, a_{i_2}, ..., a_{i_k}. Then the first cup he drinks gives him energy to write a_{i_1} pages of coursework, the second cup gives him energy to write max(0, a_{i_2} - 1) pages, the third cup gives him energy to write max(0, a_{i_3} - 2) pages, ..., the k-th cup gives him energy to write max(0, a_{i_k} - k + 1) pages.
If Polycarp doesn't drink coffee during some day, he cannot write coursework at all that day.
Polycarp has to finish his coursework as soon as possible (spend the minimum number of days to do it). Your task is to find out this number of days or say that it is impossible.
Input
The first line of the input contains two integers n and m (1 β€ n β€ 100, 1 β€ m β€ 10^4) β the number of cups of coffee and the number of pages in the coursework.
The second line of the input contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 100), where a_i is the caffeine dosage of coffee in the i-th cup.
Output
If it is impossible to write the coursework, print -1. Otherwise print the minimum number of days Polycarp needs to do it.
Examples
Input
5 8
2 3 1 1 2
Output
4
Input
7 10
1 3 4 2 1 4 2
Output
2
Input
5 15
5 5 5 5 5
Output
1
Input
5 16
5 5 5 5 5
Output
2
Input
5 26
5 5 5 5 5
Output
-1
Note
In the first example Polycarp can drink fourth cup during first day (and write 1 page), first and second cups during second day (and write 2 + (3 - 1) = 4 pages), fifth cup during the third day (and write 2 pages) and third cup during the fourth day (and write 1 page) so the answer is 4. It is obvious that there is no way to write the coursework in three or less days in this test.
In the second example Polycarp can drink third, fourth and second cups during first day (and write 4 + (2 - 1) + (3 - 2) = 6 pages) and sixth cup during second day (and write 4 pages) so the answer is 2. It is obvious that Polycarp cannot write the whole coursework in one day in this test.
In the third example Polycarp can drink all cups of coffee during first day and write 5 + (5 - 1) + (5 - 2) + (5 - 3) + (5 - 4) = 15 pages of coursework.
In the fourth example Polycarp cannot drink all cups during first day and should drink one of them during the second day. So during first day he will write 5 + (5 - 1) + (5 - 2) + (5 - 3) = 14 pages of coursework and during second day he will write 5 pages of coursework. This is enough to complete it.
In the fifth example Polycarp cannot write the whole coursework at all, even if he will drink one cup of coffee during each day, so the answer is -1.
Tags: brute force, greedy
Correct Solution:
```
n, m = map(int, input().split())
l = list(map(int,input().split()))
l.sort(reverse = True)
left = 1
right = n
def check(k,m):
if m > 0:
lef = 0
z = 0
for i in range(n):
m -= max(0, l[i]-lef)
z += 1
if z == k:
z = 0
lef += 1
if m <= 0:
return 1
else:
return 0
res = []
while left <= right:
mid = int((left+right)/2)
if check(mid, m):
res.append(mid)
right = mid - 1
else:
left = mid + 1
if len(res) > 0:
print(min(res))
else:
print("-1")
"""
n, m = map(int, input().split())
l = list(map(int,input().split()))
s = sum(l)
ans = 0
def find(x):
su = 0
days = 0
z = 0
for i in l:
su += max(0, i-z)
days += 1
if days == x:
days = 0
z += 1
if su < m:
return 0
return x
def binary(left, right):
global ans
mid = int((left+right)/2)
r = find(mid)
if right == left:
ans = r
elif left == right - 1:
if r:
ans = r
else:
binary(r, r)
else:
if r:
binary(left, mid)
else:
binary(mid, right)
if s < m:
print("-1")
elif s == m:
print(n)
else:
l.sort(reverse = True)
binary(1,n)
print(ans)
print(ans)
"""
```
| 82,629 | [
0.370361328125,
0.0623779296875,
0.345458984375,
0.177001953125,
-0.3759765625,
-0.1439208984375,
-0.265380859375,
0.050323486328125,
-0.2113037109375,
0.62158203125,
1.0068359375,
0.01136016845703125,
0.5009765625,
-0.98779296875,
-0.4521484375,
0.124755859375,
-0.5927734375,
-0.7... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The only difference between easy and hard versions is the constraints.
Polycarp has to write a coursework. The coursework consists of m pages.
Polycarp also has n cups of coffee. The coffee in the i-th cup has a_i caffeine in it. Polycarp can drink some cups of coffee (each one no more than once). He can drink cups in any order. Polycarp drinks each cup instantly and completely (i.e. he cannot split any cup into several days).
Surely, courseworks are not usually being written in a single day (in a perfect world of Berland, at least). Some of them require multiple days of hard work.
Let's consider some day of Polycarp's work. Consider Polycarp drinks k cups of coffee during this day and caffeine dosages of cups Polycarp drink during this day are a_{i_1}, a_{i_2}, ..., a_{i_k}. Then the first cup he drinks gives him energy to write a_{i_1} pages of coursework, the second cup gives him energy to write max(0, a_{i_2} - 1) pages, the third cup gives him energy to write max(0, a_{i_3} - 2) pages, ..., the k-th cup gives him energy to write max(0, a_{i_k} - k + 1) pages.
If Polycarp doesn't drink coffee during some day, he cannot write coursework at all that day.
Polycarp has to finish his coursework as soon as possible (spend the minimum number of days to do it). Your task is to find out this number of days or say that it is impossible.
Input
The first line of the input contains two integers n and m (1 β€ n β€ 100, 1 β€ m β€ 10^4) β the number of cups of coffee and the number of pages in the coursework.
The second line of the input contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 100), where a_i is the caffeine dosage of coffee in the i-th cup.
Output
If it is impossible to write the coursework, print -1. Otherwise print the minimum number of days Polycarp needs to do it.
Examples
Input
5 8
2 3 1 1 2
Output
4
Input
7 10
1 3 4 2 1 4 2
Output
2
Input
5 15
5 5 5 5 5
Output
1
Input
5 16
5 5 5 5 5
Output
2
Input
5 26
5 5 5 5 5
Output
-1
Note
In the first example Polycarp can drink fourth cup during first day (and write 1 page), first and second cups during second day (and write 2 + (3 - 1) = 4 pages), fifth cup during the third day (and write 2 pages) and third cup during the fourth day (and write 1 page) so the answer is 4. It is obvious that there is no way to write the coursework in three or less days in this test.
In the second example Polycarp can drink third, fourth and second cups during first day (and write 4 + (2 - 1) + (3 - 2) = 6 pages) and sixth cup during second day (and write 4 pages) so the answer is 2. It is obvious that Polycarp cannot write the whole coursework in one day in this test.
In the third example Polycarp can drink all cups of coffee during first day and write 5 + (5 - 1) + (5 - 2) + (5 - 3) + (5 - 4) = 15 pages of coursework.
In the fourth example Polycarp cannot drink all cups during first day and should drink one of them during the second day. So during first day he will write 5 + (5 - 1) + (5 - 2) + (5 - 3) = 14 pages of coursework and during second day he will write 5 pages of coursework. This is enough to complete it.
In the fifth example Polycarp cannot write the whole coursework at all, even if he will drink one cup of coffee during each day, so the answer is -1.
Tags: brute force, greedy
Correct Solution:
```
'''
Auther: ghoshashis545 Ashis Ghosh
College: jalpaiguri Govt Enggineering College
'''
from os import path
import sys
from functools import cmp_to_key as ctk
from collections import deque,defaultdict as dd
from bisect import bisect,bisect_left,bisect_right,insort,insort_left,insort_right
from itertools import permutations
from datetime import datetime
from math import ceil,sqrt,log,gcd
def ii():return int(input())
def si():return input()
def mi():return map(int,input().split())
def li():return list(mi())
abc='abcdefghijklmnopqrstuvwxyz'
abd={'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}
mod=1000000007
#mod=998244353
inf = float("inf")
vow=['a','e','i','o','u']
dx,dy=[-1,1,0,0],[0,0,1,-1]
def bo(i):
return ord(i)-ord('a')
def check(a,m):
n=len(a)
c,k,s=0,0,0
for i in range(n-1,-1,-1):
if(a[i]>k):
s+=(a[i]-k)
else:
break
c+=1
if(c%m==0):
k+=1
return s
def solve():
n,m=mi()
a=li()
if(m>sum(a)):
print('-1')
exit(0)
a.sort()
l=1
r=n
ans=n
while(l<=r):
mid=l+(r-l)//2
x=check(a,mid)
if(x>=m):
ans=mid
r=mid-1
else:
l=mid+1
print(ans)
if __name__ =="__main__":
solve()
```
| 82,630 | [
0.370361328125,
0.0623779296875,
0.345458984375,
0.177001953125,
-0.3759765625,
-0.1439208984375,
-0.265380859375,
0.050323486328125,
-0.2113037109375,
0.62158203125,
1.0068359375,
0.01136016845703125,
0.5009765625,
-0.98779296875,
-0.4521484375,
0.124755859375,
-0.5927734375,
-0.7... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The only difference between easy and hard versions is the constraints.
Polycarp has to write a coursework. The coursework consists of m pages.
Polycarp also has n cups of coffee. The coffee in the i-th cup has a_i caffeine in it. Polycarp can drink some cups of coffee (each one no more than once). He can drink cups in any order. Polycarp drinks each cup instantly and completely (i.e. he cannot split any cup into several days).
Surely, courseworks are not usually being written in a single day (in a perfect world of Berland, at least). Some of them require multiple days of hard work.
Let's consider some day of Polycarp's work. Consider Polycarp drinks k cups of coffee during this day and caffeine dosages of cups Polycarp drink during this day are a_{i_1}, a_{i_2}, ..., a_{i_k}. Then the first cup he drinks gives him energy to write a_{i_1} pages of coursework, the second cup gives him energy to write max(0, a_{i_2} - 1) pages, the third cup gives him energy to write max(0, a_{i_3} - 2) pages, ..., the k-th cup gives him energy to write max(0, a_{i_k} - k + 1) pages.
If Polycarp doesn't drink coffee during some day, he cannot write coursework at all that day.
Polycarp has to finish his coursework as soon as possible (spend the minimum number of days to do it). Your task is to find out this number of days or say that it is impossible.
Input
The first line of the input contains two integers n and m (1 β€ n β€ 100, 1 β€ m β€ 10^4) β the number of cups of coffee and the number of pages in the coursework.
The second line of the input contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 100), where a_i is the caffeine dosage of coffee in the i-th cup.
Output
If it is impossible to write the coursework, print -1. Otherwise print the minimum number of days Polycarp needs to do it.
Examples
Input
5 8
2 3 1 1 2
Output
4
Input
7 10
1 3 4 2 1 4 2
Output
2
Input
5 15
5 5 5 5 5
Output
1
Input
5 16
5 5 5 5 5
Output
2
Input
5 26
5 5 5 5 5
Output
-1
Note
In the first example Polycarp can drink fourth cup during first day (and write 1 page), first and second cups during second day (and write 2 + (3 - 1) = 4 pages), fifth cup during the third day (and write 2 pages) and third cup during the fourth day (and write 1 page) so the answer is 4. It is obvious that there is no way to write the coursework in three or less days in this test.
In the second example Polycarp can drink third, fourth and second cups during first day (and write 4 + (2 - 1) + (3 - 2) = 6 pages) and sixth cup during second day (and write 4 pages) so the answer is 2. It is obvious that Polycarp cannot write the whole coursework in one day in this test.
In the third example Polycarp can drink all cups of coffee during first day and write 5 + (5 - 1) + (5 - 2) + (5 - 3) + (5 - 4) = 15 pages of coursework.
In the fourth example Polycarp cannot drink all cups during first day and should drink one of them during the second day. So during first day he will write 5 + (5 - 1) + (5 - 2) + (5 - 3) = 14 pages of coursework and during second day he will write 5 pages of coursework. This is enough to complete it.
In the fifth example Polycarp cannot write the whole coursework at all, even if he will drink one cup of coffee during each day, so the answer is -1.
Tags: brute force, greedy
Correct Solution:
```
def fastio():
import sys
from io import StringIO
from atexit import register
global input
sys.stdin = StringIO(sys.stdin.read())
input = lambda : sys.stdin.readline().rstrip('\r\n')
sys.stdout = StringIO()
register(lambda : sys.__stdout__.write(sys.stdout.getvalue()))
# fastio()
MOD = 10**9 + 7
I = lambda:list(map(int,input().split()))
n, m = I()
l = I()
l.sort(reverse = True)
lo = 1
hi = 10**20
def check(k):
# s = sum(l[:k])
s = 0
i = 0
d = 0
while i < n and s < m:
s += max(0, l[i] - d)
i += 1
if i%k == 0:
# print(s)
d += 1
# print(s, m)
return s >= m
while lo < hi:
mid = (lo + hi)//2
if check(mid):
hi = mid
else:
lo = mid + 1
# print(lo, hi)
if (lo == 10**20):
print(-1)
exit()
print(lo)
```
| 82,631 | [
0.370361328125,
0.0623779296875,
0.345458984375,
0.177001953125,
-0.3759765625,
-0.1439208984375,
-0.265380859375,
0.050323486328125,
-0.2113037109375,
0.62158203125,
1.0068359375,
0.01136016845703125,
0.5009765625,
-0.98779296875,
-0.4521484375,
0.124755859375,
-0.5927734375,
-0.7... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The only difference between easy and hard versions is the constraints.
Polycarp has to write a coursework. The coursework consists of m pages.
Polycarp also has n cups of coffee. The coffee in the i-th cup has a_i caffeine in it. Polycarp can drink some cups of coffee (each one no more than once). He can drink cups in any order. Polycarp drinks each cup instantly and completely (i.e. he cannot split any cup into several days).
Surely, courseworks are not usually being written in a single day (in a perfect world of Berland, at least). Some of them require multiple days of hard work.
Let's consider some day of Polycarp's work. Consider Polycarp drinks k cups of coffee during this day and caffeine dosages of cups Polycarp drink during this day are a_{i_1}, a_{i_2}, ..., a_{i_k}. Then the first cup he drinks gives him energy to write a_{i_1} pages of coursework, the second cup gives him energy to write max(0, a_{i_2} - 1) pages, the third cup gives him energy to write max(0, a_{i_3} - 2) pages, ..., the k-th cup gives him energy to write max(0, a_{i_k} - k + 1) pages.
If Polycarp doesn't drink coffee during some day, he cannot write coursework at all that day.
Polycarp has to finish his coursework as soon as possible (spend the minimum number of days to do it). Your task is to find out this number of days or say that it is impossible.
Input
The first line of the input contains two integers n and m (1 β€ n β€ 100, 1 β€ m β€ 10^4) β the number of cups of coffee and the number of pages in the coursework.
The second line of the input contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 100), where a_i is the caffeine dosage of coffee in the i-th cup.
Output
If it is impossible to write the coursework, print -1. Otherwise print the minimum number of days Polycarp needs to do it.
Examples
Input
5 8
2 3 1 1 2
Output
4
Input
7 10
1 3 4 2 1 4 2
Output
2
Input
5 15
5 5 5 5 5
Output
1
Input
5 16
5 5 5 5 5
Output
2
Input
5 26
5 5 5 5 5
Output
-1
Note
In the first example Polycarp can drink fourth cup during first day (and write 1 page), first and second cups during second day (and write 2 + (3 - 1) = 4 pages), fifth cup during the third day (and write 2 pages) and third cup during the fourth day (and write 1 page) so the answer is 4. It is obvious that there is no way to write the coursework in three or less days in this test.
In the second example Polycarp can drink third, fourth and second cups during first day (and write 4 + (2 - 1) + (3 - 2) = 6 pages) and sixth cup during second day (and write 4 pages) so the answer is 2. It is obvious that Polycarp cannot write the whole coursework in one day in this test.
In the third example Polycarp can drink all cups of coffee during first day and write 5 + (5 - 1) + (5 - 2) + (5 - 3) + (5 - 4) = 15 pages of coursework.
In the fourth example Polycarp cannot drink all cups during first day and should drink one of them during the second day. So during first day he will write 5 + (5 - 1) + (5 - 2) + (5 - 3) = 14 pages of coursework and during second day he will write 5 pages of coursework. This is enough to complete it.
In the fifth example Polycarp cannot write the whole coursework at all, even if he will drink one cup of coffee during each day, so the answer is -1.
Tags: brute force, greedy
Correct Solution:
```
n, m = map(int, input().split())
coffees = sorted(map(int, input().split()), reverse=True)
total = sum(coffees)
if total < m:
print(-1)
exit()
for div in range(1, n):
a = [0] * div
index = 0
for pena in range(n):
for d in range(div):
if coffees[index] <= pena:
break
a[d] += coffees[index] - pena
index += 1
if index >= n or coffees[index] <= pena:
break
if index >= n or coffees[index] <= pena:
break
if sum(a) >= m:
print(div)
exit()
print(n)
```
| 82,632 | [
0.370361328125,
0.0623779296875,
0.345458984375,
0.177001953125,
-0.3759765625,
-0.1439208984375,
-0.265380859375,
0.050323486328125,
-0.2113037109375,
0.62158203125,
1.0068359375,
0.01136016845703125,
0.5009765625,
-0.98779296875,
-0.4521484375,
0.124755859375,
-0.5927734375,
-0.7... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The only difference between easy and hard versions is the constraints.
Polycarp has to write a coursework. The coursework consists of m pages.
Polycarp also has n cups of coffee. The coffee in the i-th cup has a_i caffeine in it. Polycarp can drink some cups of coffee (each one no more than once). He can drink cups in any order. Polycarp drinks each cup instantly and completely (i.e. he cannot split any cup into several days).
Surely, courseworks are not usually being written in a single day (in a perfect world of Berland, at least). Some of them require multiple days of hard work.
Let's consider some day of Polycarp's work. Consider Polycarp drinks k cups of coffee during this day and caffeine dosages of cups Polycarp drink during this day are a_{i_1}, a_{i_2}, ..., a_{i_k}. Then the first cup he drinks gives him energy to write a_{i_1} pages of coursework, the second cup gives him energy to write max(0, a_{i_2} - 1) pages, the third cup gives him energy to write max(0, a_{i_3} - 2) pages, ..., the k-th cup gives him energy to write max(0, a_{i_k} - k + 1) pages.
If Polycarp doesn't drink coffee during some day, he cannot write coursework at all that day.
Polycarp has to finish his coursework as soon as possible (spend the minimum number of days to do it). Your task is to find out this number of days or say that it is impossible.
Input
The first line of the input contains two integers n and m (1 β€ n β€ 100, 1 β€ m β€ 10^4) β the number of cups of coffee and the number of pages in the coursework.
The second line of the input contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 100), where a_i is the caffeine dosage of coffee in the i-th cup.
Output
If it is impossible to write the coursework, print -1. Otherwise print the minimum number of days Polycarp needs to do it.
Examples
Input
5 8
2 3 1 1 2
Output
4
Input
7 10
1 3 4 2 1 4 2
Output
2
Input
5 15
5 5 5 5 5
Output
1
Input
5 16
5 5 5 5 5
Output
2
Input
5 26
5 5 5 5 5
Output
-1
Note
In the first example Polycarp can drink fourth cup during first day (and write 1 page), first and second cups during second day (and write 2 + (3 - 1) = 4 pages), fifth cup during the third day (and write 2 pages) and third cup during the fourth day (and write 1 page) so the answer is 4. It is obvious that there is no way to write the coursework in three or less days in this test.
In the second example Polycarp can drink third, fourth and second cups during first day (and write 4 + (2 - 1) + (3 - 2) = 6 pages) and sixth cup during second day (and write 4 pages) so the answer is 2. It is obvious that Polycarp cannot write the whole coursework in one day in this test.
In the third example Polycarp can drink all cups of coffee during first day and write 5 + (5 - 1) + (5 - 2) + (5 - 3) + (5 - 4) = 15 pages of coursework.
In the fourth example Polycarp cannot drink all cups during first day and should drink one of them during the second day. So during first day he will write 5 + (5 - 1) + (5 - 2) + (5 - 3) = 14 pages of coursework and during second day he will write 5 pages of coursework. This is enough to complete it.
In the fifth example Polycarp cannot write the whole coursework at all, even if he will drink one cup of coffee during each day, so the answer is -1.
Tags: brute force, greedy
Correct Solution:
```
l=input().split()
n=int(l[0])
m=int(l[1])
l=input().split()
li=[int(i) for i in l]
li.sort()
li.reverse()
if(sum(li)<m):
print(-1)
else:
ans=0
for i in range(1,n+1):
arr=list(li)
sumi=0
for j in range(n):
sumi+=max(arr[j]-(j//i),0)
if(sumi>=m):
ans=i
break
print(ans)
```
| 82,633 | [
0.370361328125,
0.0623779296875,
0.345458984375,
0.177001953125,
-0.3759765625,
-0.1439208984375,
-0.265380859375,
0.050323486328125,
-0.2113037109375,
0.62158203125,
1.0068359375,
0.01136016845703125,
0.5009765625,
-0.98779296875,
-0.4521484375,
0.124755859375,
-0.5927734375,
-0.7... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The only difference between easy and hard versions is the constraints.
Polycarp has to write a coursework. The coursework consists of m pages.
Polycarp also has n cups of coffee. The coffee in the i-th cup has a_i caffeine in it. Polycarp can drink some cups of coffee (each one no more than once). He can drink cups in any order. Polycarp drinks each cup instantly and completely (i.e. he cannot split any cup into several days).
Surely, courseworks are not usually being written in a single day (in a perfect world of Berland, at least). Some of them require multiple days of hard work.
Let's consider some day of Polycarp's work. Consider Polycarp drinks k cups of coffee during this day and caffeine dosages of cups Polycarp drink during this day are a_{i_1}, a_{i_2}, ..., a_{i_k}. Then the first cup he drinks gives him energy to write a_{i_1} pages of coursework, the second cup gives him energy to write max(0, a_{i_2} - 1) pages, the third cup gives him energy to write max(0, a_{i_3} - 2) pages, ..., the k-th cup gives him energy to write max(0, a_{i_k} - k + 1) pages.
If Polycarp doesn't drink coffee during some day, he cannot write coursework at all that day.
Polycarp has to finish his coursework as soon as possible (spend the minimum number of days to do it). Your task is to find out this number of days or say that it is impossible.
Input
The first line of the input contains two integers n and m (1 β€ n β€ 100, 1 β€ m β€ 10^4) β the number of cups of coffee and the number of pages in the coursework.
The second line of the input contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 100), where a_i is the caffeine dosage of coffee in the i-th cup.
Output
If it is impossible to write the coursework, print -1. Otherwise print the minimum number of days Polycarp needs to do it.
Examples
Input
5 8
2 3 1 1 2
Output
4
Input
7 10
1 3 4 2 1 4 2
Output
2
Input
5 15
5 5 5 5 5
Output
1
Input
5 16
5 5 5 5 5
Output
2
Input
5 26
5 5 5 5 5
Output
-1
Note
In the first example Polycarp can drink fourth cup during first day (and write 1 page), first and second cups during second day (and write 2 + (3 - 1) = 4 pages), fifth cup during the third day (and write 2 pages) and third cup during the fourth day (and write 1 page) so the answer is 4. It is obvious that there is no way to write the coursework in three or less days in this test.
In the second example Polycarp can drink third, fourth and second cups during first day (and write 4 + (2 - 1) + (3 - 2) = 6 pages) and sixth cup during second day (and write 4 pages) so the answer is 2. It is obvious that Polycarp cannot write the whole coursework in one day in this test.
In the third example Polycarp can drink all cups of coffee during first day and write 5 + (5 - 1) + (5 - 2) + (5 - 3) + (5 - 4) = 15 pages of coursework.
In the fourth example Polycarp cannot drink all cups during first day and should drink one of them during the second day. So during first day he will write 5 + (5 - 1) + (5 - 2) + (5 - 3) = 14 pages of coursework and during second day he will write 5 pages of coursework. This is enough to complete it.
In the fifth example Polycarp cannot write the whole coursework at all, even if he will drink one cup of coffee during each day, so the answer is -1.
Tags: brute force, greedy
Correct Solution:
```
nb_cups, nb_task = [int(x) for x in input().split()]
caffines = sorted([int(x) for x in input().split()], reverse=True)
def check(d):
done = 0
for i, v in enumerate(caffines):
done += max(0, v - i // d)
return done >= nb_task
if sum(caffines) < nb_task:
print(-1)
else:
left, rite = 1, nb_cups
mid = left + rite >> 1
while left < rite:
if check(mid):
rite = mid
else:
left = mid + 1
mid = left + rite >> 1
print(left)
```
| 82,634 | [
0.370361328125,
0.0623779296875,
0.345458984375,
0.177001953125,
-0.3759765625,
-0.1439208984375,
-0.265380859375,
0.050323486328125,
-0.2113037109375,
0.62158203125,
1.0068359375,
0.01136016845703125,
0.5009765625,
-0.98779296875,
-0.4521484375,
0.124755859375,
-0.5927734375,
-0.7... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The only difference between easy and hard versions is the constraints.
Polycarp has to write a coursework. The coursework consists of m pages.
Polycarp also has n cups of coffee. The coffee in the i-th cup has a_i caffeine in it. Polycarp can drink some cups of coffee (each one no more than once). He can drink cups in any order. Polycarp drinks each cup instantly and completely (i.e. he cannot split any cup into several days).
Surely, courseworks are not usually being written in a single day (in a perfect world of Berland, at least). Some of them require multiple days of hard work.
Let's consider some day of Polycarp's work. Consider Polycarp drinks k cups of coffee during this day and caffeine dosages of cups Polycarp drink during this day are a_{i_1}, a_{i_2}, ..., a_{i_k}. Then the first cup he drinks gives him energy to write a_{i_1} pages of coursework, the second cup gives him energy to write max(0, a_{i_2} - 1) pages, the third cup gives him energy to write max(0, a_{i_3} - 2) pages, ..., the k-th cup gives him energy to write max(0, a_{i_k} - k + 1) pages.
If Polycarp doesn't drink coffee during some day, he cannot write coursework at all that day.
Polycarp has to finish his coursework as soon as possible (spend the minimum number of days to do it). Your task is to find out this number of days or say that it is impossible.
Input
The first line of the input contains two integers n and m (1 β€ n β€ 100, 1 β€ m β€ 10^4) β the number of cups of coffee and the number of pages in the coursework.
The second line of the input contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 100), where a_i is the caffeine dosage of coffee in the i-th cup.
Output
If it is impossible to write the coursework, print -1. Otherwise print the minimum number of days Polycarp needs to do it.
Examples
Input
5 8
2 3 1 1 2
Output
4
Input
7 10
1 3 4 2 1 4 2
Output
2
Input
5 15
5 5 5 5 5
Output
1
Input
5 16
5 5 5 5 5
Output
2
Input
5 26
5 5 5 5 5
Output
-1
Note
In the first example Polycarp can drink fourth cup during first day (and write 1 page), first and second cups during second day (and write 2 + (3 - 1) = 4 pages), fifth cup during the third day (and write 2 pages) and third cup during the fourth day (and write 1 page) so the answer is 4. It is obvious that there is no way to write the coursework in three or less days in this test.
In the second example Polycarp can drink third, fourth and second cups during first day (and write 4 + (2 - 1) + (3 - 2) = 6 pages) and sixth cup during second day (and write 4 pages) so the answer is 2. It is obvious that Polycarp cannot write the whole coursework in one day in this test.
In the third example Polycarp can drink all cups of coffee during first day and write 5 + (5 - 1) + (5 - 2) + (5 - 3) + (5 - 4) = 15 pages of coursework.
In the fourth example Polycarp cannot drink all cups during first day and should drink one of them during the second day. So during first day he will write 5 + (5 - 1) + (5 - 2) + (5 - 3) = 14 pages of coursework and during second day he will write 5 pages of coursework. This is enough to complete it.
In the fifth example Polycarp cannot write the whole coursework at all, even if he will drink one cup of coffee during each day, so the answer is -1.
Tags: brute force, greedy
Correct Solution:
```
def check(d, a):
ans = 0
for q in range(len(a)):
ans += max(a[q]-q//d, 0)
return ans
n, m = map(int, input().split())
a = sorted(list(map(int, input().split())), reverse=True)
if sum(a) < m:
print(-1)
else:
l, r = 0, n
while r-l > 1:
m1 = (l+r)//2
if check(m1, a) >= m:
r = m1
else:
l = m1
print(r)
```
| 82,635 | [
0.370361328125,
0.0623779296875,
0.345458984375,
0.177001953125,
-0.3759765625,
-0.1439208984375,
-0.265380859375,
0.050323486328125,
-0.2113037109375,
0.62158203125,
1.0068359375,
0.01136016845703125,
0.5009765625,
-0.98779296875,
-0.4521484375,
0.124755859375,
-0.5927734375,
-0.7... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The only difference between easy and hard versions is the constraints.
Polycarp has to write a coursework. The coursework consists of m pages.
Polycarp also has n cups of coffee. The coffee in the i-th cup has a_i caffeine in it. Polycarp can drink some cups of coffee (each one no more than once). He can drink cups in any order. Polycarp drinks each cup instantly and completely (i.e. he cannot split any cup into several days).
Surely, courseworks are not usually being written in a single day (in a perfect world of Berland, at least). Some of them require multiple days of hard work.
Let's consider some day of Polycarp's work. Consider Polycarp drinks k cups of coffee during this day and caffeine dosages of cups Polycarp drink during this day are a_{i_1}, a_{i_2}, ..., a_{i_k}. Then the first cup he drinks gives him energy to write a_{i_1} pages of coursework, the second cup gives him energy to write max(0, a_{i_2} - 1) pages, the third cup gives him energy to write max(0, a_{i_3} - 2) pages, ..., the k-th cup gives him energy to write max(0, a_{i_k} - k + 1) pages.
If Polycarp doesn't drink coffee during some day, he cannot write coursework at all that day.
Polycarp has to finish his coursework as soon as possible (spend the minimum number of days to do it). Your task is to find out this number of days or say that it is impossible.
Input
The first line of the input contains two integers n and m (1 β€ n β€ 100, 1 β€ m β€ 10^4) β the number of cups of coffee and the number of pages in the coursework.
The second line of the input contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 100), where a_i is the caffeine dosage of coffee in the i-th cup.
Output
If it is impossible to write the coursework, print -1. Otherwise print the minimum number of days Polycarp needs to do it.
Examples
Input
5 8
2 3 1 1 2
Output
4
Input
7 10
1 3 4 2 1 4 2
Output
2
Input
5 15
5 5 5 5 5
Output
1
Input
5 16
5 5 5 5 5
Output
2
Input
5 26
5 5 5 5 5
Output
-1
Note
In the first example Polycarp can drink fourth cup during first day (and write 1 page), first and second cups during second day (and write 2 + (3 - 1) = 4 pages), fifth cup during the third day (and write 2 pages) and third cup during the fourth day (and write 1 page) so the answer is 4. It is obvious that there is no way to write the coursework in three or less days in this test.
In the second example Polycarp can drink third, fourth and second cups during first day (and write 4 + (2 - 1) + (3 - 2) = 6 pages) and sixth cup during second day (and write 4 pages) so the answer is 2. It is obvious that Polycarp cannot write the whole coursework in one day in this test.
In the third example Polycarp can drink all cups of coffee during first day and write 5 + (5 - 1) + (5 - 2) + (5 - 3) + (5 - 4) = 15 pages of coursework.
In the fourth example Polycarp cannot drink all cups during first day and should drink one of them during the second day. So during first day he will write 5 + (5 - 1) + (5 - 2) + (5 - 3) = 14 pages of coursework and during second day he will write 5 pages of coursework. This is enough to complete it.
In the fifth example Polycarp cannot write the whole coursework at all, even if he will drink one cup of coffee during each day, so the answer is -1.
Submitted Solution:
```
n, m = map(int, input().split())
a = list(sorted(map(int, input().split()), reverse=True))
def proc(n, m, a):
possible_minimum = -1
l, r = 1, n
sub_c = [0] * n
while l <= r:
i = (l + r) // 2
# if i == 100:
current_m = m
for j in range(i):
sub_c[j] = 0
for j in range(0, n):
# a[j:j + i]
pos = j % i
if a[j] < sub_c[pos]:
break
current_m -= a[j] - sub_c[pos]
sub_c[pos] += 1
if current_m <= 0:
break
if current_m <= 0:
# print('[{}, {}] => {} SUCCESS'.format(l, r, i))
possible_minimum = i
r = i - 1
else:
# print('[{}, {}] => {} FAIL'.format(l, r, i))
l = i + 1
return possible_minimum
print(proc(n, m, a))
```
Yes
| 82,636 | [
0.33935546875,
0.1253662109375,
0.29052734375,
0.10662841796875,
-0.437255859375,
-0.075927734375,
-0.287109375,
0.12225341796875,
-0.200439453125,
0.58837890625,
0.86328125,
-0.04388427734375,
0.491943359375,
-0.90771484375,
-0.51025390625,
0.0224609375,
-0.59326171875,
-0.7622070... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The only difference between easy and hard versions is the constraints.
Polycarp has to write a coursework. The coursework consists of m pages.
Polycarp also has n cups of coffee. The coffee in the i-th cup has a_i caffeine in it. Polycarp can drink some cups of coffee (each one no more than once). He can drink cups in any order. Polycarp drinks each cup instantly and completely (i.e. he cannot split any cup into several days).
Surely, courseworks are not usually being written in a single day (in a perfect world of Berland, at least). Some of them require multiple days of hard work.
Let's consider some day of Polycarp's work. Consider Polycarp drinks k cups of coffee during this day and caffeine dosages of cups Polycarp drink during this day are a_{i_1}, a_{i_2}, ..., a_{i_k}. Then the first cup he drinks gives him energy to write a_{i_1} pages of coursework, the second cup gives him energy to write max(0, a_{i_2} - 1) pages, the third cup gives him energy to write max(0, a_{i_3} - 2) pages, ..., the k-th cup gives him energy to write max(0, a_{i_k} - k + 1) pages.
If Polycarp doesn't drink coffee during some day, he cannot write coursework at all that day.
Polycarp has to finish his coursework as soon as possible (spend the minimum number of days to do it). Your task is to find out this number of days or say that it is impossible.
Input
The first line of the input contains two integers n and m (1 β€ n β€ 100, 1 β€ m β€ 10^4) β the number of cups of coffee and the number of pages in the coursework.
The second line of the input contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 100), where a_i is the caffeine dosage of coffee in the i-th cup.
Output
If it is impossible to write the coursework, print -1. Otherwise print the minimum number of days Polycarp needs to do it.
Examples
Input
5 8
2 3 1 1 2
Output
4
Input
7 10
1 3 4 2 1 4 2
Output
2
Input
5 15
5 5 5 5 5
Output
1
Input
5 16
5 5 5 5 5
Output
2
Input
5 26
5 5 5 5 5
Output
-1
Note
In the first example Polycarp can drink fourth cup during first day (and write 1 page), first and second cups during second day (and write 2 + (3 - 1) = 4 pages), fifth cup during the third day (and write 2 pages) and third cup during the fourth day (and write 1 page) so the answer is 4. It is obvious that there is no way to write the coursework in three or less days in this test.
In the second example Polycarp can drink third, fourth and second cups during first day (and write 4 + (2 - 1) + (3 - 2) = 6 pages) and sixth cup during second day (and write 4 pages) so the answer is 2. It is obvious that Polycarp cannot write the whole coursework in one day in this test.
In the third example Polycarp can drink all cups of coffee during first day and write 5 + (5 - 1) + (5 - 2) + (5 - 3) + (5 - 4) = 15 pages of coursework.
In the fourth example Polycarp cannot drink all cups during first day and should drink one of them during the second day. So during first day he will write 5 + (5 - 1) + (5 - 2) + (5 - 3) = 14 pages of coursework and during second day he will write 5 pages of coursework. This is enough to complete it.
In the fifth example Polycarp cannot write the whole coursework at all, even if he will drink one cup of coffee during each day, so the answer is -1.
Submitted Solution:
```
def check_possibility(days, m, coffee):
sum_coffee = 0
for i, cup in enumerate(coffee):
tax = i // days
if sum_coffee >= m or tax >= cup:
break
sum_coffee += cup - tax
return sum_coffee >= m
n, m = map(int, input().split())
coffee = sorted(map(int, input().split()), reverse=True)
bad = 0
good = len(coffee)
while good - bad > 1:
days = (bad + good) // 2
if check_possibility(days, m, coffee):
good = days
else:
bad = days
possible = check_possibility(good, m, coffee)
print(good if possible else -1)
```
Yes
| 82,637 | [
0.33935546875,
0.1253662109375,
0.29052734375,
0.10662841796875,
-0.437255859375,
-0.075927734375,
-0.287109375,
0.12225341796875,
-0.200439453125,
0.58837890625,
0.86328125,
-0.04388427734375,
0.491943359375,
-0.90771484375,
-0.51025390625,
0.0224609375,
-0.59326171875,
-0.7622070... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The only difference between easy and hard versions is the constraints.
Polycarp has to write a coursework. The coursework consists of m pages.
Polycarp also has n cups of coffee. The coffee in the i-th cup has a_i caffeine in it. Polycarp can drink some cups of coffee (each one no more than once). He can drink cups in any order. Polycarp drinks each cup instantly and completely (i.e. he cannot split any cup into several days).
Surely, courseworks are not usually being written in a single day (in a perfect world of Berland, at least). Some of them require multiple days of hard work.
Let's consider some day of Polycarp's work. Consider Polycarp drinks k cups of coffee during this day and caffeine dosages of cups Polycarp drink during this day are a_{i_1}, a_{i_2}, ..., a_{i_k}. Then the first cup he drinks gives him energy to write a_{i_1} pages of coursework, the second cup gives him energy to write max(0, a_{i_2} - 1) pages, the third cup gives him energy to write max(0, a_{i_3} - 2) pages, ..., the k-th cup gives him energy to write max(0, a_{i_k} - k + 1) pages.
If Polycarp doesn't drink coffee during some day, he cannot write coursework at all that day.
Polycarp has to finish his coursework as soon as possible (spend the minimum number of days to do it). Your task is to find out this number of days or say that it is impossible.
Input
The first line of the input contains two integers n and m (1 β€ n β€ 100, 1 β€ m β€ 10^4) β the number of cups of coffee and the number of pages in the coursework.
The second line of the input contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 100), where a_i is the caffeine dosage of coffee in the i-th cup.
Output
If it is impossible to write the coursework, print -1. Otherwise print the minimum number of days Polycarp needs to do it.
Examples
Input
5 8
2 3 1 1 2
Output
4
Input
7 10
1 3 4 2 1 4 2
Output
2
Input
5 15
5 5 5 5 5
Output
1
Input
5 16
5 5 5 5 5
Output
2
Input
5 26
5 5 5 5 5
Output
-1
Note
In the first example Polycarp can drink fourth cup during first day (and write 1 page), first and second cups during second day (and write 2 + (3 - 1) = 4 pages), fifth cup during the third day (and write 2 pages) and third cup during the fourth day (and write 1 page) so the answer is 4. It is obvious that there is no way to write the coursework in three or less days in this test.
In the second example Polycarp can drink third, fourth and second cups during first day (and write 4 + (2 - 1) + (3 - 2) = 6 pages) and sixth cup during second day (and write 4 pages) so the answer is 2. It is obvious that Polycarp cannot write the whole coursework in one day in this test.
In the third example Polycarp can drink all cups of coffee during first day and write 5 + (5 - 1) + (5 - 2) + (5 - 3) + (5 - 4) = 15 pages of coursework.
In the fourth example Polycarp cannot drink all cups during first day and should drink one of them during the second day. So during first day he will write 5 + (5 - 1) + (5 - 2) + (5 - 3) = 14 pages of coursework and during second day he will write 5 pages of coursework. This is enough to complete it.
In the fifth example Polycarp cannot write the whole coursework at all, even if he will drink one cup of coffee during each day, so the answer is -1.
Submitted Solution:
```
import math,sys
from sys import stdin, stdout
from collections import Counter, defaultdict, deque
input = stdin.readline
I = lambda:int(input())
li = lambda:list(map(int,input().split()))
def solve(a,mid,s):
c=0
i=0
p=0
while(i<len(a)):
c+=max(0,a[i]-p)
i=i+1
if(not i%mid):
p+=1
if(c>=s):
return(1)
return(0)
def case(test):
n,s=li()
a=li()
if(sum(a)<s):
print(-1)
return
a.sort(reverse=True)
l,r=1,n
m=n
while(l<=r):
#print(l,r)
mid=(l+r)//2
p=solve(a,mid,s)
if(p):
r=mid-1
m=min(m,mid)
else:
l=mid+1
print(m)
for test in range(1):
case(test+1)
```
Yes
| 82,638 | [
0.33935546875,
0.1253662109375,
0.29052734375,
0.10662841796875,
-0.437255859375,
-0.075927734375,
-0.287109375,
0.12225341796875,
-0.200439453125,
0.58837890625,
0.86328125,
-0.04388427734375,
0.491943359375,
-0.90771484375,
-0.51025390625,
0.0224609375,
-0.59326171875,
-0.7622070... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The only difference between easy and hard versions is the constraints.
Polycarp has to write a coursework. The coursework consists of m pages.
Polycarp also has n cups of coffee. The coffee in the i-th cup has a_i caffeine in it. Polycarp can drink some cups of coffee (each one no more than once). He can drink cups in any order. Polycarp drinks each cup instantly and completely (i.e. he cannot split any cup into several days).
Surely, courseworks are not usually being written in a single day (in a perfect world of Berland, at least). Some of them require multiple days of hard work.
Let's consider some day of Polycarp's work. Consider Polycarp drinks k cups of coffee during this day and caffeine dosages of cups Polycarp drink during this day are a_{i_1}, a_{i_2}, ..., a_{i_k}. Then the first cup he drinks gives him energy to write a_{i_1} pages of coursework, the second cup gives him energy to write max(0, a_{i_2} - 1) pages, the third cup gives him energy to write max(0, a_{i_3} - 2) pages, ..., the k-th cup gives him energy to write max(0, a_{i_k} - k + 1) pages.
If Polycarp doesn't drink coffee during some day, he cannot write coursework at all that day.
Polycarp has to finish his coursework as soon as possible (spend the minimum number of days to do it). Your task is to find out this number of days or say that it is impossible.
Input
The first line of the input contains two integers n and m (1 β€ n β€ 100, 1 β€ m β€ 10^4) β the number of cups of coffee and the number of pages in the coursework.
The second line of the input contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 100), where a_i is the caffeine dosage of coffee in the i-th cup.
Output
If it is impossible to write the coursework, print -1. Otherwise print the minimum number of days Polycarp needs to do it.
Examples
Input
5 8
2 3 1 1 2
Output
4
Input
7 10
1 3 4 2 1 4 2
Output
2
Input
5 15
5 5 5 5 5
Output
1
Input
5 16
5 5 5 5 5
Output
2
Input
5 26
5 5 5 5 5
Output
-1
Note
In the first example Polycarp can drink fourth cup during first day (and write 1 page), first and second cups during second day (and write 2 + (3 - 1) = 4 pages), fifth cup during the third day (and write 2 pages) and third cup during the fourth day (and write 1 page) so the answer is 4. It is obvious that there is no way to write the coursework in three or less days in this test.
In the second example Polycarp can drink third, fourth and second cups during first day (and write 4 + (2 - 1) + (3 - 2) = 6 pages) and sixth cup during second day (and write 4 pages) so the answer is 2. It is obvious that Polycarp cannot write the whole coursework in one day in this test.
In the third example Polycarp can drink all cups of coffee during first day and write 5 + (5 - 1) + (5 - 2) + (5 - 3) + (5 - 4) = 15 pages of coursework.
In the fourth example Polycarp cannot drink all cups during first day and should drink one of them during the second day. So during first day he will write 5 + (5 - 1) + (5 - 2) + (5 - 3) = 14 pages of coursework and during second day he will write 5 pages of coursework. This is enough to complete it.
In the fifth example Polycarp cannot write the whole coursework at all, even if he will drink one cup of coffee during each day, so the answer is -1.
Submitted Solution:
```
n, m = (int(t) for t in input().split(' '))
a = [int(t) for t in input().split(' ')]
a.sort(reverse=True)
def possible(d):
total = 0
for i in range(d):
step = 0
for j in range(i, n, d):
total += max(a[j] - step, 0)
step += 1
return total >= m
l, r = 0, n+1
while l < r:
mid = (l + r) // 2
if possible(mid):
r = mid
else:
l = mid + 1
if possible(l):
print(l)
else:
print(-1)
```
Yes
| 82,639 | [
0.33935546875,
0.1253662109375,
0.29052734375,
0.10662841796875,
-0.437255859375,
-0.075927734375,
-0.287109375,
0.12225341796875,
-0.200439453125,
0.58837890625,
0.86328125,
-0.04388427734375,
0.491943359375,
-0.90771484375,
-0.51025390625,
0.0224609375,
-0.59326171875,
-0.7622070... | 24 |
Evaluate the correctness of the submitted Python 2 solution to the coding contest problem. Provide a "Yes" or "No" response.
The only difference between easy and hard versions is the constraints.
Polycarp has to write a coursework. The coursework consists of m pages.
Polycarp also has n cups of coffee. The coffee in the i-th cup has a_i caffeine in it. Polycarp can drink some cups of coffee (each one no more than once). He can drink cups in any order. Polycarp drinks each cup instantly and completely (i.e. he cannot split any cup into several days).
Surely, courseworks are not usually being written in a single day (in a perfect world of Berland, at least). Some of them require multiple days of hard work.
Let's consider some day of Polycarp's work. Consider Polycarp drinks k cups of coffee during this day and caffeine dosages of cups Polycarp drink during this day are a_{i_1}, a_{i_2}, ..., a_{i_k}. Then the first cup he drinks gives him energy to write a_{i_1} pages of coursework, the second cup gives him energy to write max(0, a_{i_2} - 1) pages, the third cup gives him energy to write max(0, a_{i_3} - 2) pages, ..., the k-th cup gives him energy to write max(0, a_{i_k} - k + 1) pages.
If Polycarp doesn't drink coffee during some day, he cannot write coursework at all that day.
Polycarp has to finish his coursework as soon as possible (spend the minimum number of days to do it). Your task is to find out this number of days or say that it is impossible.
Input
The first line of the input contains two integers n and m (1 β€ n β€ 100, 1 β€ m β€ 10^4) β the number of cups of coffee and the number of pages in the coursework.
The second line of the input contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 100), where a_i is the caffeine dosage of coffee in the i-th cup.
Output
If it is impossible to write the coursework, print -1. Otherwise print the minimum number of days Polycarp needs to do it.
Examples
Input
5 8
2 3 1 1 2
Output
4
Input
7 10
1 3 4 2 1 4 2
Output
2
Input
5 15
5 5 5 5 5
Output
1
Input
5 16
5 5 5 5 5
Output
2
Input
5 26
5 5 5 5 5
Output
-1
Note
In the first example Polycarp can drink fourth cup during first day (and write 1 page), first and second cups during second day (and write 2 + (3 - 1) = 4 pages), fifth cup during the third day (and write 2 pages) and third cup during the fourth day (and write 1 page) so the answer is 4. It is obvious that there is no way to write the coursework in three or less days in this test.
In the second example Polycarp can drink third, fourth and second cups during first day (and write 4 + (2 - 1) + (3 - 2) = 6 pages) and sixth cup during second day (and write 4 pages) so the answer is 2. It is obvious that Polycarp cannot write the whole coursework in one day in this test.
In the third example Polycarp can drink all cups of coffee during first day and write 5 + (5 - 1) + (5 - 2) + (5 - 3) + (5 - 4) = 15 pages of coursework.
In the fourth example Polycarp cannot drink all cups during first day and should drink one of them during the second day. So during first day he will write 5 + (5 - 1) + (5 - 2) + (5 - 3) = 14 pages of coursework and during second day he will write 5 pages of coursework. This is enough to complete it.
In the fifth example Polycarp cannot write the whole coursework at all, even if he will drink one cup of coffee during each day, so the answer is -1.
Submitted Solution:
```
from sys import stdin, stdout
from collections import Counter, defaultdict
from itertools import permutations, combinations
raw_input = stdin.readline
pr = stdout.write
def in_arr():
return map(int,raw_input().split())
def pr_num(n):
stdout.write(str(n)+'\n')
def pr_arr(arr):
for i in arr:
stdout.write(str(i)+' ')
stdout.write('\n')
range = xrange # not for python 3.0+
# main code
def check(n,m,l,mid):
temp=0
c=0
k=mid
for i in range(0,n,k):
for j in range(i,min(n,i+k)):
#print mid,i,j,l[j]-c
temp+=max(0,l[j]-c)
c+=1
#print temp,m
if temp>=m:
return 1
return 0
n,m=in_arr()
l=in_arr()
if sum(l)<m:
print -1
exit()
l.sort(reverse=True)
l1=1
r1=n
ans=n
while l1<=r1:
mid=(l1+r1)/2
if check(n,m,l,mid):
ans=mid
r1=mid-1
else:
l1=mid+1
pr_num(ans)
```
Yes
| 82,640 | [
0.3095703125,
0.150634765625,
0.31787109375,
0.156494140625,
-0.4638671875,
-0.0650634765625,
-0.301513671875,
0.123046875,
-0.19091796875,
0.6474609375,
0.8896484375,
-0.042266845703125,
0.496826171875,
-0.8603515625,
-0.5146484375,
0.071533203125,
-0.5849609375,
-0.80322265625,
... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The only difference between easy and hard versions is the constraints.
Polycarp has to write a coursework. The coursework consists of m pages.
Polycarp also has n cups of coffee. The coffee in the i-th cup has a_i caffeine in it. Polycarp can drink some cups of coffee (each one no more than once). He can drink cups in any order. Polycarp drinks each cup instantly and completely (i.e. he cannot split any cup into several days).
Surely, courseworks are not usually being written in a single day (in a perfect world of Berland, at least). Some of them require multiple days of hard work.
Let's consider some day of Polycarp's work. Consider Polycarp drinks k cups of coffee during this day and caffeine dosages of cups Polycarp drink during this day are a_{i_1}, a_{i_2}, ..., a_{i_k}. Then the first cup he drinks gives him energy to write a_{i_1} pages of coursework, the second cup gives him energy to write max(0, a_{i_2} - 1) pages, the third cup gives him energy to write max(0, a_{i_3} - 2) pages, ..., the k-th cup gives him energy to write max(0, a_{i_k} - k + 1) pages.
If Polycarp doesn't drink coffee during some day, he cannot write coursework at all that day.
Polycarp has to finish his coursework as soon as possible (spend the minimum number of days to do it). Your task is to find out this number of days or say that it is impossible.
Input
The first line of the input contains two integers n and m (1 β€ n β€ 100, 1 β€ m β€ 10^4) β the number of cups of coffee and the number of pages in the coursework.
The second line of the input contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 100), where a_i is the caffeine dosage of coffee in the i-th cup.
Output
If it is impossible to write the coursework, print -1. Otherwise print the minimum number of days Polycarp needs to do it.
Examples
Input
5 8
2 3 1 1 2
Output
4
Input
7 10
1 3 4 2 1 4 2
Output
2
Input
5 15
5 5 5 5 5
Output
1
Input
5 16
5 5 5 5 5
Output
2
Input
5 26
5 5 5 5 5
Output
-1
Note
In the first example Polycarp can drink fourth cup during first day (and write 1 page), first and second cups during second day (and write 2 + (3 - 1) = 4 pages), fifth cup during the third day (and write 2 pages) and third cup during the fourth day (and write 1 page) so the answer is 4. It is obvious that there is no way to write the coursework in three or less days in this test.
In the second example Polycarp can drink third, fourth and second cups during first day (and write 4 + (2 - 1) + (3 - 2) = 6 pages) and sixth cup during second day (and write 4 pages) so the answer is 2. It is obvious that Polycarp cannot write the whole coursework in one day in this test.
In the third example Polycarp can drink all cups of coffee during first day and write 5 + (5 - 1) + (5 - 2) + (5 - 3) + (5 - 4) = 15 pages of coursework.
In the fourth example Polycarp cannot drink all cups during first day and should drink one of them during the second day. So during first day he will write 5 + (5 - 1) + (5 - 2) + (5 - 3) = 14 pages of coursework and during second day he will write 5 pages of coursework. This is enough to complete it.
In the fifth example Polycarp cannot write the whole coursework at all, even if he will drink one cup of coffee during each day, so the answer is -1.
Submitted Solution:
```
class Solution():
def __init__(self):
firstline=input().split()
n=int(firstline[0])
m=int(firstline[1])
a=input().split()
for i in range(n):
a[i]=int(a[i])
a.sort(key=None,reverse=True)
# print(a[0])
l=1
r=m+1
while l<r:
mid=int(l+r>>1)
sum=0
mod=int(n/mid)
less=n%mid
if less!=0:
mod+=1
cnt=0
for i in range(n):
sum+=max(0,a[i]-cnt)
cnt+=1
if cnt>=mod:
less-=1
if less<=0:
less=1000000000
mod-=1
cnt=0
if sum>=m:
r=mid
else:
l=mid+1
if r==m+1:
print('-1')
else:
print(r)
if __name__ == '__main__':
Solution()
```
No
| 82,641 | [
0.33935546875,
0.1253662109375,
0.29052734375,
0.10662841796875,
-0.437255859375,
-0.075927734375,
-0.287109375,
0.12225341796875,
-0.200439453125,
0.58837890625,
0.86328125,
-0.04388427734375,
0.491943359375,
-0.90771484375,
-0.51025390625,
0.0224609375,
-0.59326171875,
-0.7622070... | 24 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.