text stringlengths 1.02k 43.5k | conversation_id int64 853 107k | embedding list | cluster int64 24 24 |
|---|---|---|---|
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarpus has got n candies and m friends (n β₯ m). He wants to make a New Year present with candies to each friend. Polycarpus is planning to present all candies and he wants to do this in the fairest (that is, most equal) manner. He wants to choose such ai, where ai is the number of candies in the i-th friend's present, that the maximum ai differs from the least ai as little as possible.
For example, if n is divisible by m, then he is going to present the same number of candies to all his friends, that is, the maximum ai won't differ from the minimum one.
Input
The single line of the input contains a pair of space-separated positive integers n, m (1 β€ n, m β€ 100;n β₯ m) β the number of candies and the number of Polycarpus's friends.
Output
Print the required sequence a1, a2, ..., am, where ai is the number of candies in the i-th friend's present. All numbers ai must be positive integers, total up to n, the maximum one should differ from the minimum one by the smallest possible value.
Examples
Input
12 3
Output
4 4 4
Input
15 4
Output
3 4 4 4
Input
18 7
Output
2 2 2 3 3 3 3
Note
Print ai in any order, separate the numbers by spaces.
Tags: implementation
Correct Solution:
```
n,m=map(int,input().split())
if(n%m)==0:
for i in range(m):
print(n//m,end=" ")
print()
else:
x=n%m
y=n//m
for i in range(x):
print(y+1,end=" ")
for i in range(m-x):
print(y,end=" ")
print()
```
| 42,403 | [
0.3447265625,
0.44189453125,
0.0635986328125,
-0.052154541015625,
-0.54833984375,
-0.72802734375,
-0.22412109375,
0.18017578125,
0.18505859375,
0.7607421875,
0.37158203125,
-0.1533203125,
0.1434326171875,
-0.5771484375,
-0.4384765625,
-0.12310791015625,
-0.90087890625,
-0.560058593... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarpus has got n candies and m friends (n β₯ m). He wants to make a New Year present with candies to each friend. Polycarpus is planning to present all candies and he wants to do this in the fairest (that is, most equal) manner. He wants to choose such ai, where ai is the number of candies in the i-th friend's present, that the maximum ai differs from the least ai as little as possible.
For example, if n is divisible by m, then he is going to present the same number of candies to all his friends, that is, the maximum ai won't differ from the minimum one.
Input
The single line of the input contains a pair of space-separated positive integers n, m (1 β€ n, m β€ 100;n β₯ m) β the number of candies and the number of Polycarpus's friends.
Output
Print the required sequence a1, a2, ..., am, where ai is the number of candies in the i-th friend's present. All numbers ai must be positive integers, total up to n, the maximum one should differ from the minimum one by the smallest possible value.
Examples
Input
12 3
Output
4 4 4
Input
15 4
Output
3 4 4 4
Input
18 7
Output
2 2 2 3 3 3 3
Note
Print ai in any order, separate the numbers by spaces.
Tags: implementation
Correct Solution:
```
import time
import collections
class Time_test:
def __enter__(self):
self.enter_time = time.time()
def __exit__(self, exc_type, exc_val, exc_tb):
print("Command was executed in", time.time()-self.enter_time)
n, m = [int(x) for x in input().split()]
print((str(n//m)+" ")*(m-n%m)+(str(n//m+1)+" ")*(n%m))
```
| 42,404 | [
0.350341796875,
0.50634765625,
0.091552734375,
-0.018218994140625,
-0.580078125,
-0.6689453125,
-0.255126953125,
0.1553955078125,
0.1824951171875,
0.7646484375,
0.307861328125,
-0.14453125,
0.09466552734375,
-0.6767578125,
-0.5068359375,
-0.120361328125,
-0.87890625,
-0.54052734375... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarpus has got n candies and m friends (n β₯ m). He wants to make a New Year present with candies to each friend. Polycarpus is planning to present all candies and he wants to do this in the fairest (that is, most equal) manner. He wants to choose such ai, where ai is the number of candies in the i-th friend's present, that the maximum ai differs from the least ai as little as possible.
For example, if n is divisible by m, then he is going to present the same number of candies to all his friends, that is, the maximum ai won't differ from the minimum one.
Input
The single line of the input contains a pair of space-separated positive integers n, m (1 β€ n, m β€ 100;n β₯ m) β the number of candies and the number of Polycarpus's friends.
Output
Print the required sequence a1, a2, ..., am, where ai is the number of candies in the i-th friend's present. All numbers ai must be positive integers, total up to n, the maximum one should differ from the minimum one by the smallest possible value.
Examples
Input
12 3
Output
4 4 4
Input
15 4
Output
3 4 4 4
Input
18 7
Output
2 2 2 3 3 3 3
Note
Print ai in any order, separate the numbers by spaces.
Tags: implementation
Correct Solution:
```
n, m = map(int, input().split())
res = []
while m:
res.append(n // m)
n -= (n // m)
m -= 1
print(*res)
```
| 42,405 | [
0.375732421875,
0.460205078125,
0.07562255859375,
-0.0682373046875,
-0.56103515625,
-0.7431640625,
-0.281005859375,
0.1497802734375,
0.1751708984375,
0.73974609375,
0.40283203125,
-0.171142578125,
0.117919921875,
-0.587890625,
-0.46435546875,
-0.1080322265625,
-0.896484375,
-0.4812... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarpus has got n candies and m friends (n β₯ m). He wants to make a New Year present with candies to each friend. Polycarpus is planning to present all candies and he wants to do this in the fairest (that is, most equal) manner. He wants to choose such ai, where ai is the number of candies in the i-th friend's present, that the maximum ai differs from the least ai as little as possible.
For example, if n is divisible by m, then he is going to present the same number of candies to all his friends, that is, the maximum ai won't differ from the minimum one.
Input
The single line of the input contains a pair of space-separated positive integers n, m (1 β€ n, m β€ 100;n β₯ m) β the number of candies and the number of Polycarpus's friends.
Output
Print the required sequence a1, a2, ..., am, where ai is the number of candies in the i-th friend's present. All numbers ai must be positive integers, total up to n, the maximum one should differ from the minimum one by the smallest possible value.
Examples
Input
12 3
Output
4 4 4
Input
15 4
Output
3 4 4 4
Input
18 7
Output
2 2 2 3 3 3 3
Note
Print ai in any order, separate the numbers by spaces.
Tags: implementation
Correct Solution:
```
n, m = map(int, input().split())
if(n%m == 0):
arr = [n//m]*m
else:
arr= [n//m + 1]*(n%m)
sm = sum(arr)
diff = n - sm
last = m - len(arr)
arr = arr + [diff//last]*last
for i in sorted(arr):
print(i,end=" ")
```
| 42,406 | [
0.343994140625,
0.488525390625,
0.06414794921875,
-0.042449951171875,
-0.52294921875,
-0.76708984375,
-0.26611328125,
0.1549072265625,
0.1619873046875,
0.79541015625,
0.411376953125,
-0.1453857421875,
0.1019287109375,
-0.6416015625,
-0.5068359375,
-0.1405029296875,
-0.89013671875,
... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarpus has got n candies and m friends (n β₯ m). He wants to make a New Year present with candies to each friend. Polycarpus is planning to present all candies and he wants to do this in the fairest (that is, most equal) manner. He wants to choose such ai, where ai is the number of candies in the i-th friend's present, that the maximum ai differs from the least ai as little as possible.
For example, if n is divisible by m, then he is going to present the same number of candies to all his friends, that is, the maximum ai won't differ from the minimum one.
Input
The single line of the input contains a pair of space-separated positive integers n, m (1 β€ n, m β€ 100;n β₯ m) β the number of candies and the number of Polycarpus's friends.
Output
Print the required sequence a1, a2, ..., am, where ai is the number of candies in the i-th friend's present. All numbers ai must be positive integers, total up to n, the maximum one should differ from the minimum one by the smallest possible value.
Examples
Input
12 3
Output
4 4 4
Input
15 4
Output
3 4 4 4
Input
18 7
Output
2 2 2 3 3 3 3
Note
Print ai in any order, separate the numbers by spaces.
Tags: implementation
Correct Solution:
```
def main():
n, m = map(int, input().split())
a = [(n//m)]*m
if sum(a) < n:
for i in range(n-sum(a)):
a[i]+= 1
print(*a)
main()
```
| 42,407 | [
0.379638671875,
0.446533203125,
0.07440185546875,
-0.058807373046875,
-0.52685546875,
-0.73974609375,
-0.25732421875,
0.16455078125,
0.19873046875,
0.6875,
0.385498046875,
-0.1522216796875,
0.09710693359375,
-0.5791015625,
-0.490234375,
-0.12841796875,
-0.880859375,
-0.50341796875,... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarpus has got n candies and m friends (n β₯ m). He wants to make a New Year present with candies to each friend. Polycarpus is planning to present all candies and he wants to do this in the fairest (that is, most equal) manner. He wants to choose such ai, where ai is the number of candies in the i-th friend's present, that the maximum ai differs from the least ai as little as possible.
For example, if n is divisible by m, then he is going to present the same number of candies to all his friends, that is, the maximum ai won't differ from the minimum one.
Input
The single line of the input contains a pair of space-separated positive integers n, m (1 β€ n, m β€ 100;n β₯ m) β the number of candies and the number of Polycarpus's friends.
Output
Print the required sequence a1, a2, ..., am, where ai is the number of candies in the i-th friend's present. All numbers ai must be positive integers, total up to n, the maximum one should differ from the minimum one by the smallest possible value.
Examples
Input
12 3
Output
4 4 4
Input
15 4
Output
3 4 4 4
Input
18 7
Output
2 2 2 3 3 3 3
Note
Print ai in any order, separate the numbers by spaces.
Submitted Solution:
```
##A
from math import ceil,floor
n,m=map(int,input().split())
L=[]
if not n%m:
for _ in range(m):
L.append(n//m)
else:
MIN=floor(n/m)
MAX=ceil(n/m)
for _ in range(n%m):
L.append(MAX)
for _ in range(m-(n%m)):
L.append(MIN)
print (' '.join(map(str,L)))
```
Yes
| 42,408 | [
0.410400390625,
0.43798828125,
0.10589599609375,
0.0175018310546875,
-0.68212890625,
-0.5556640625,
-0.272216796875,
0.342529296875,
0.13671875,
0.6630859375,
0.332275390625,
-0.15966796875,
-0.0145111083984375,
-0.59814453125,
-0.45751953125,
-0.1729736328125,
-0.84033203125,
-0.5... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarpus has got n candies and m friends (n β₯ m). He wants to make a New Year present with candies to each friend. Polycarpus is planning to present all candies and he wants to do this in the fairest (that is, most equal) manner. He wants to choose such ai, where ai is the number of candies in the i-th friend's present, that the maximum ai differs from the least ai as little as possible.
For example, if n is divisible by m, then he is going to present the same number of candies to all his friends, that is, the maximum ai won't differ from the minimum one.
Input
The single line of the input contains a pair of space-separated positive integers n, m (1 β€ n, m β€ 100;n β₯ m) β the number of candies and the number of Polycarpus's friends.
Output
Print the required sequence a1, a2, ..., am, where ai is the number of candies in the i-th friend's present. All numbers ai must be positive integers, total up to n, the maximum one should differ from the minimum one by the smallest possible value.
Examples
Input
12 3
Output
4 4 4
Input
15 4
Output
3 4 4 4
Input
18 7
Output
2 2 2 3 3 3 3
Note
Print ai in any order, separate the numbers by spaces.
Submitted Solution:
```
n, m = input().split()
n = int(n)
m = int(m)
resDiv = n // m
temp = resDiv * m
temp = n - temp
temp = m - temp
for i in range(m):
if temp == 0:
print(resDiv + 1, end=" ")
else:
print(resDiv, end=" ")
temp = temp - 1
```
Yes
| 42,409 | [
0.419921875,
0.47998046875,
0.0703125,
-0.0096435546875,
-0.65869140625,
-0.56787109375,
-0.221923828125,
0.213623046875,
0.1549072265625,
0.79931640625,
0.367431640625,
-0.1519775390625,
0.0161285400390625,
-0.63671875,
-0.433349609375,
-0.1898193359375,
-0.86572265625,
-0.5927734... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarpus has got n candies and m friends (n β₯ m). He wants to make a New Year present with candies to each friend. Polycarpus is planning to present all candies and he wants to do this in the fairest (that is, most equal) manner. He wants to choose such ai, where ai is the number of candies in the i-th friend's present, that the maximum ai differs from the least ai as little as possible.
For example, if n is divisible by m, then he is going to present the same number of candies to all his friends, that is, the maximum ai won't differ from the minimum one.
Input
The single line of the input contains a pair of space-separated positive integers n, m (1 β€ n, m β€ 100;n β₯ m) β the number of candies and the number of Polycarpus's friends.
Output
Print the required sequence a1, a2, ..., am, where ai is the number of candies in the i-th friend's present. All numbers ai must be positive integers, total up to n, the maximum one should differ from the minimum one by the smallest possible value.
Examples
Input
12 3
Output
4 4 4
Input
15 4
Output
3 4 4 4
Input
18 7
Output
2 2 2 3 3 3 3
Note
Print ai in any order, separate the numbers by spaces.
Submitted Solution:
```
param = list(map(int,input().split()))
answer = ""
for i in range(param[1]):
if i <= (param[1]-(param[0] % param[1])-1):
answer += str(param[0]//param[1]) + " "
else:
answer += str(param[0]//param[1] + 1) + " "
print(answer)
```
Yes
| 42,410 | [
0.47998046875,
0.425048828125,
0.07916259765625,
-0.0187225341796875,
-0.7109375,
-0.56201171875,
-0.24365234375,
0.319091796875,
0.16943359375,
0.6865234375,
0.4248046875,
-0.1949462890625,
0.0282135009765625,
-0.57275390625,
-0.47314453125,
-0.2144775390625,
-0.80224609375,
-0.50... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarpus has got n candies and m friends (n β₯ m). He wants to make a New Year present with candies to each friend. Polycarpus is planning to present all candies and he wants to do this in the fairest (that is, most equal) manner. He wants to choose such ai, where ai is the number of candies in the i-th friend's present, that the maximum ai differs from the least ai as little as possible.
For example, if n is divisible by m, then he is going to present the same number of candies to all his friends, that is, the maximum ai won't differ from the minimum one.
Input
The single line of the input contains a pair of space-separated positive integers n, m (1 β€ n, m β€ 100;n β₯ m) β the number of candies and the number of Polycarpus's friends.
Output
Print the required sequence a1, a2, ..., am, where ai is the number of candies in the i-th friend's present. All numbers ai must be positive integers, total up to n, the maximum one should differ from the minimum one by the smallest possible value.
Examples
Input
12 3
Output
4 4 4
Input
15 4
Output
3 4 4 4
Input
18 7
Output
2 2 2 3 3 3 3
Note
Print ai in any order, separate the numbers by spaces.
Submitted Solution:
```
def main():
n, m = [int(i) for i in input().split()]
a = [n//m] * m
l = n - (n//m)*m
for i in range(l):
a[i] += 1
print(' '.join(map(str, a)))
main()
```
Yes
| 42,411 | [
0.421142578125,
0.44775390625,
0.10009765625,
-0.04437255859375,
-0.66259765625,
-0.5927734375,
-0.259521484375,
0.309814453125,
0.1783447265625,
0.66552734375,
0.406005859375,
-0.173828125,
-0.00687408447265625,
-0.6064453125,
-0.50048828125,
-0.1903076171875,
-0.8701171875,
-0.52... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarpus has got n candies and m friends (n β₯ m). He wants to make a New Year present with candies to each friend. Polycarpus is planning to present all candies and he wants to do this in the fairest (that is, most equal) manner. He wants to choose such ai, where ai is the number of candies in the i-th friend's present, that the maximum ai differs from the least ai as little as possible.
For example, if n is divisible by m, then he is going to present the same number of candies to all his friends, that is, the maximum ai won't differ from the minimum one.
Input
The single line of the input contains a pair of space-separated positive integers n, m (1 β€ n, m β€ 100;n β₯ m) β the number of candies and the number of Polycarpus's friends.
Output
Print the required sequence a1, a2, ..., am, where ai is the number of candies in the i-th friend's present. All numbers ai must be positive integers, total up to n, the maximum one should differ from the minimum one by the smallest possible value.
Examples
Input
12 3
Output
4 4 4
Input
15 4
Output
3 4 4 4
Input
18 7
Output
2 2 2 3 3 3 3
Note
Print ai in any order, separate the numbers by spaces.
Submitted Solution:
```
import math
n,k=map(int,input().split())
x=[]
if n%k==0:
c=n//k
for _ in range(k):
x.append(c)
else:
c=math.ceil(n/k)
l=k*c
d=l-n
for _ in range(d):
x.append(c-1)
for _ in range(k-d):
x.append(c)
print(x)
```
No
| 42,412 | [
0.4228515625,
0.462890625,
0.0933837890625,
0.00711822509765625,
-0.65576171875,
-0.5859375,
-0.2493896484375,
0.305908203125,
0.1524658203125,
0.6904296875,
0.380615234375,
-0.172119140625,
-0.0031223297119140625,
-0.5986328125,
-0.46044921875,
-0.171142578125,
-0.8564453125,
-0.5... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarpus has got n candies and m friends (n β₯ m). He wants to make a New Year present with candies to each friend. Polycarpus is planning to present all candies and he wants to do this in the fairest (that is, most equal) manner. He wants to choose such ai, where ai is the number of candies in the i-th friend's present, that the maximum ai differs from the least ai as little as possible.
For example, if n is divisible by m, then he is going to present the same number of candies to all his friends, that is, the maximum ai won't differ from the minimum one.
Input
The single line of the input contains a pair of space-separated positive integers n, m (1 β€ n, m β€ 100;n β₯ m) β the number of candies and the number of Polycarpus's friends.
Output
Print the required sequence a1, a2, ..., am, where ai is the number of candies in the i-th friend's present. All numbers ai must be positive integers, total up to n, the maximum one should differ from the minimum one by the smallest possible value.
Examples
Input
12 3
Output
4 4 4
Input
15 4
Output
3 4 4 4
Input
18 7
Output
2 2 2 3 3 3 3
Note
Print ai in any order, separate the numbers by spaces.
Submitted Solution:
```
amount_candy, amount_friends = map(int, input().split())
my_string = ""
list_candies = [0] * amount_friends
avarage_candy = amount_candy // amount_friends
vestiges_candy = amount_candy % amount_friends
for i in range(amount_friends):
list_candies[i] += avarage_candy
while vestiges_candy > 0:
list_candies[amount_friends-1] += 1
vestiges_candy -= 1
amount_friends -= 1
for i in range(len(list_candies)):
my_string += str(list_candies[i]) + " "
print(list_candies)
print(my_string)
```
No
| 42,413 | [
0.35107421875,
0.48388671875,
0.032806396484375,
0.01349639892578125,
-0.6669921875,
-0.61083984375,
-0.14697265625,
0.215576171875,
0.222412109375,
0.6357421875,
0.333740234375,
-0.173583984375,
0.10809326171875,
-0.5986328125,
-0.429443359375,
-0.05194091796875,
-0.88720703125,
-... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarpus has got n candies and m friends (n β₯ m). He wants to make a New Year present with candies to each friend. Polycarpus is planning to present all candies and he wants to do this in the fairest (that is, most equal) manner. He wants to choose such ai, where ai is the number of candies in the i-th friend's present, that the maximum ai differs from the least ai as little as possible.
For example, if n is divisible by m, then he is going to present the same number of candies to all his friends, that is, the maximum ai won't differ from the minimum one.
Input
The single line of the input contains a pair of space-separated positive integers n, m (1 β€ n, m β€ 100;n β₯ m) β the number of candies and the number of Polycarpus's friends.
Output
Print the required sequence a1, a2, ..., am, where ai is the number of candies in the i-th friend's present. All numbers ai must be positive integers, total up to n, the maximum one should differ from the minimum one by the smallest possible value.
Examples
Input
12 3
Output
4 4 4
Input
15 4
Output
3 4 4 4
Input
18 7
Output
2 2 2 3 3 3 3
Note
Print ai in any order, separate the numbers by spaces.
Submitted Solution:
```
[num_candies, num_friends] = map(int, input().split())
candy_allocation = []
# All friends get same number of candies except the last who gets more
# All but the last gets equal_candies
equal_candies = num_candies//num_friends
for i in range(num_friends-1):
candy_allocation.append(equal_candies)
# Last friend gets higher number of candies "last_candy"
last_candy = num_candies - equal_candies * (num_friends-1)
candy_allocation.append(last_candy)
for i in range(num_friends):
print(candy_allocation[i], end=' ')
```
No
| 42,414 | [
0.443115234375,
0.51904296875,
0.032073974609375,
0.0252685546875,
-0.6513671875,
-0.6826171875,
-0.182861328125,
0.321044921875,
0.1937255859375,
0.64599609375,
0.360595703125,
-0.2032470703125,
0.12359619140625,
-0.53369140625,
-0.51806640625,
-0.146484375,
-0.8857421875,
-0.4682... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarpus has got n candies and m friends (n β₯ m). He wants to make a New Year present with candies to each friend. Polycarpus is planning to present all candies and he wants to do this in the fairest (that is, most equal) manner. He wants to choose such ai, where ai is the number of candies in the i-th friend's present, that the maximum ai differs from the least ai as little as possible.
For example, if n is divisible by m, then he is going to present the same number of candies to all his friends, that is, the maximum ai won't differ from the minimum one.
Input
The single line of the input contains a pair of space-separated positive integers n, m (1 β€ n, m β€ 100;n β₯ m) β the number of candies and the number of Polycarpus's friends.
Output
Print the required sequence a1, a2, ..., am, where ai is the number of candies in the i-th friend's present. All numbers ai must be positive integers, total up to n, the maximum one should differ from the minimum one by the smallest possible value.
Examples
Input
12 3
Output
4 4 4
Input
15 4
Output
3 4 4 4
Input
18 7
Output
2 2 2 3 3 3 3
Note
Print ai in any order, separate the numbers by spaces.
Submitted Solution:
```
candies,n=input().split(" ")
candies=int(candies)
n=int(n)
answer=[]
while(n>0):
temp=int(candies/n)
answer.append(temp)
n-=1
candies=candies-temp
for i in answer:
print(answer[i], end=" ")
```
No
| 42,415 | [
0.477294921875,
0.480224609375,
0.04620361328125,
0.01003265380859375,
-0.666015625,
-0.5888671875,
-0.2342529296875,
0.295654296875,
0.20703125,
0.68408203125,
0.372314453125,
-0.1309814453125,
-0.0343017578125,
-0.6103515625,
-0.465087890625,
-0.2291259765625,
-0.810546875,
-0.58... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp loves not only to take pictures, but also to show his photos to friends. On his personal website he has recently installed a widget that can display n photos with the scroll option. At each moment of time the widget displays exactly one photograph with the option showing the previous/next one. From the first photo, you can switch to the second one or to the n-th one, from the second photo you can switch to the third one or to the first one, etc. Thus, navigation is performed in a cycle.
Polycarp's collection consists of m photo albums, the i-th album contains ai photos. Polycarp wants to choose n photos and put them on a new widget. To make watching the photos interesting to the visitors, he is going to post pictures so that no two photos from one album were neighboring (each photo will have exactly two neighbors, the first photo's neighbors are the second and the n-th one).
Help Polycarp compile a photo gallery. Select n photos from his collection and put them in such order that no two photos from one album went one after the other.
Input
The first line contains two integers n and m (3 β€ n β€ 1000, 1 β€ m β€ 40), where n is the number of photos on the widget, and m is the number of albums. The second line contains m integers a1, a2, ..., am (1 β€ ai β€ 1000), where ai is the number of photos in the i-th album.
Output
Print the single number -1 if there is no solution. Otherwise, print n numbers t1, t2, ..., tn, where ti represents the number of the album of the i-th picture in the widget. The albums are numbered from 1 in the order of their appearance in the input. If there are several solutions, print any of them.
Examples
Input
4 3
1 3 5
Output
3 1 3 2
Input
10 2
5 5
Output
2 1 2 1 2 1 2 1 2 1
Input
10 3
1 10 3
Output
-1
Submitted Solution:
```
n,m=list(map(int,input().split()))
a=list(map(int,input().split()))
if sum(a)-sorted(a)[-1]>=n//2:
for i in range(m):
a[i]=[a[i],i+1]
c=[]
d=0
while d<n:
a.sort()
a=a[::-1]
b=[]
for i in range(m-1):
b.append([a[i][0]-a[i+1][0],i+2])
b.sort()
b=b[::-1]
e=b[0][0]
if m==2:
f=0
else:
f=b[1][0]
z=0
for i in range(e-f+1):
j=0
while j<b[0][1]:
if (d!=0 and (a[j][1]==c[d-1] or (d==n-1 and a[j][1]==c[0]))) or a[j][0]==0:
j+=1
if j==b[0][1]:
break
if d==n:
z=1
break
c.append(a[j][1])
a[j][0]-=1
d+=1
j+=1
if z==1:
break
print(*c)
else:
print(-1)
```
No
| 42,572 | [
0.412109375,
0.15283203125,
0.1402587890625,
-0.019195556640625,
-0.350341796875,
-0.27490234375,
-0.642578125,
0.38671875,
0.6845703125,
0.6064453125,
0.462646484375,
-0.3125,
0.175048828125,
-0.50341796875,
-0.58349609375,
0.1336669921875,
-0.4658203125,
-0.5146484375,
-0.56835... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp loves not only to take pictures, but also to show his photos to friends. On his personal website he has recently installed a widget that can display n photos with the scroll option. At each moment of time the widget displays exactly one photograph with the option showing the previous/next one. From the first photo, you can switch to the second one or to the n-th one, from the second photo you can switch to the third one or to the first one, etc. Thus, navigation is performed in a cycle.
Polycarp's collection consists of m photo albums, the i-th album contains ai photos. Polycarp wants to choose n photos and put them on a new widget. To make watching the photos interesting to the visitors, he is going to post pictures so that no two photos from one album were neighboring (each photo will have exactly two neighbors, the first photo's neighbors are the second and the n-th one).
Help Polycarp compile a photo gallery. Select n photos from his collection and put them in such order that no two photos from one album went one after the other.
Input
The first line contains two integers n and m (3 β€ n β€ 1000, 1 β€ m β€ 40), where n is the number of photos on the widget, and m is the number of albums. The second line contains m integers a1, a2, ..., am (1 β€ ai β€ 1000), where ai is the number of photos in the i-th album.
Output
Print the single number -1 if there is no solution. Otherwise, print n numbers t1, t2, ..., tn, where ti represents the number of the album of the i-th picture in the widget. The albums are numbered from 1 in the order of their appearance in the input. If there are several solutions, print any of them.
Examples
Input
4 3
1 3 5
Output
3 1 3 2
Input
10 2
5 5
Output
2 1 2 1 2 1 2 1 2 1
Input
10 3
1 10 3
Output
-1
Submitted Solution:
```
n,m=list(map(int,input().split()))
a=list(map(int,input().split()))
if sum(a)-sorted(a)[-1]>=n//2:
for i in range(m):
a[i]=[a[i],i+1]
c=[]
d=0
while d<n:
a.sort()
a=a[::-1]
b=[]
for i in range(m-1):
b.append([a[i][0]-a[i+1][0],i+2])
b.sort()
b=b[::-1]
e=b[0][0]
if m==2:
f=0
else:
f=b[1][0]
z=0
for i in range(e-f+1):
j=0
while j<b[0][1]:
if d!=0 and (a[j][1]==c[d-1] or (d==n-1 and a[j][1]==c[0])):
j+=1
if j==b[0][1]:
break
if d==n:
z=1
break
c.append(a[j][1])
a[j][0]-=1
d+=1
j+=1
if z==1:
break
print(*c)
else:
print(-1)
```
No
| 42,573 | [
0.412109375,
0.15283203125,
0.1402587890625,
-0.019195556640625,
-0.350341796875,
-0.27490234375,
-0.642578125,
0.38671875,
0.6845703125,
0.6064453125,
0.462646484375,
-0.3125,
0.175048828125,
-0.50341796875,
-0.58349609375,
0.1336669921875,
-0.4658203125,
-0.5146484375,
-0.56835... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp has to solve exactly n problems to improve his programming skill before an important programming competition. But this competition will be held very soon, most precisely, it will start in k days. It means that Polycarp has exactly k days for training!
Polycarp doesn't want to procrastinate, so he wants to solve at least one problem during each of k days. He also doesn't want to overwork, so if he solves x problems during some day, he should solve no more than 2x problems during the next day. And, at last, he wants to improve his skill, so if he solves x problems during some day, he should solve at least x+1 problem during the next day.
More formally: let [a_1, a_2, ..., a_k] be the array of numbers of problems solved by Polycarp. The i-th element of this array is the number of problems Polycarp solves during the i-th day of his training. Then the following conditions must be satisfied:
* sum of all a_i for i from 1 to k should be n;
* a_i should be greater than zero for each i from 1 to k;
* the condition a_i < a_{i + 1} β€ 2 a_i should be satisfied for each i from 1 to k-1.
Your problem is to find any array a of length k satisfying the conditions above or say that it is impossible to do it.
Input
The first line of the input contains two integers n and k (1 β€ n β€ 10^9, 1 β€ k β€ 10^5) β the number of problems Polycarp wants to solve and the number of days Polycarp wants to train.
Output
If it is impossible to find any array a of length k satisfying Polycarp's rules of training, print "NO" in the first line.
Otherwise print "YES" in the first line, then print k integers a_1, a_2, ..., a_k in the second line, where a_i should be the number of problems Polycarp should solve during the i-th day. If there are multiple answers, you can print any.
Examples
Input
26 6
Output
YES
1 2 4 5 6 8
Input
8 3
Output
NO
Input
1 1
Output
YES
1
Input
9 4
Output
NO
Tags: constructive algorithms, greedy, math
Correct Solution:
```
rint = lambda: int(input())
rmint = lambda: map(int, input().split())
rlist = lambda: list(rmint())
n, k = rmint()
t = k
a = [0] * k
def no(): print("NO"); exit(0)
d = [-1] * (k+1); d[0] = 1
mx = 10 ** 9
for i in range(1, k+1):
if d[i-1] * 2 > mx: break
d[i] = d[i-1] * 2
for i in range(k):
if n < 0: break
if d[t] < 0:
p = 1
if i: p = a[i-1] + 1
else:
f = d[t] - 1
p = max(1, (n + f - 1) // f)
if i:
p = max(p, a[i-1] + 1)
p = min(p, a[i-1] * 2)
a[i] = p
t -= 1
n -= p
if n: no()
print("YES")
for i in range(k): print(a[i],end=' ')
```
| 42,977 | [
0.57666015625,
0.2005615234375,
0.020477294921875,
0.23291015625,
-0.421875,
-0.45703125,
-0.4345703125,
0.0618896484375,
0.2178955078125,
0.75,
0.89306640625,
-0.289306640625,
0.39013671875,
-0.8037109375,
-0.392578125,
-0.19384765625,
-0.421875,
-0.61181640625,
-1.0439453125,
... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp has to solve exactly n problems to improve his programming skill before an important programming competition. But this competition will be held very soon, most precisely, it will start in k days. It means that Polycarp has exactly k days for training!
Polycarp doesn't want to procrastinate, so he wants to solve at least one problem during each of k days. He also doesn't want to overwork, so if he solves x problems during some day, he should solve no more than 2x problems during the next day. And, at last, he wants to improve his skill, so if he solves x problems during some day, he should solve at least x+1 problem during the next day.
More formally: let [a_1, a_2, ..., a_k] be the array of numbers of problems solved by Polycarp. The i-th element of this array is the number of problems Polycarp solves during the i-th day of his training. Then the following conditions must be satisfied:
* sum of all a_i for i from 1 to k should be n;
* a_i should be greater than zero for each i from 1 to k;
* the condition a_i < a_{i + 1} β€ 2 a_i should be satisfied for each i from 1 to k-1.
Your problem is to find any array a of length k satisfying the conditions above or say that it is impossible to do it.
Input
The first line of the input contains two integers n and k (1 β€ n β€ 10^9, 1 β€ k β€ 10^5) β the number of problems Polycarp wants to solve and the number of days Polycarp wants to train.
Output
If it is impossible to find any array a of length k satisfying Polycarp's rules of training, print "NO" in the first line.
Otherwise print "YES" in the first line, then print k integers a_1, a_2, ..., a_k in the second line, where a_i should be the number of problems Polycarp should solve during the i-th day. If there are multiple answers, you can print any.
Examples
Input
26 6
Output
YES
1 2 4 5 6 8
Input
8 3
Output
NO
Input
1 1
Output
YES
1
Input
9 4
Output
NO
Tags: constructive algorithms, greedy, math
Correct Solution:
```
import sys
n,k=map(int,input().split())
a=[0]*(k+2)
if k*(k+1)>n*2:
print("NO")
sys.exit()
for i in range(1,k+1):
a[i]=i
n-=k*(k+1)//2
rest=n//k
n-=rest*k
a[1]+=rest
for i in range(2,k+1):
a[i]=a[i-1]+1
rest=n//(k-i+1)
tmp=min(rest,a[i-1]*2-a[i])
a[i]+=tmp
n-=(k-i+1)*tmp
if n>0:
print("NO")
sys.exit()
print("YES")
for i in range(1,k+1):
print(a[i],end=" ")
```
| 42,978 | [
0.57666015625,
0.2005615234375,
0.020477294921875,
0.23291015625,
-0.421875,
-0.45703125,
-0.4345703125,
0.0618896484375,
0.2178955078125,
0.75,
0.89306640625,
-0.289306640625,
0.39013671875,
-0.8037109375,
-0.392578125,
-0.19384765625,
-0.421875,
-0.61181640625,
-1.0439453125,
... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp has to solve exactly n problems to improve his programming skill before an important programming competition. But this competition will be held very soon, most precisely, it will start in k days. It means that Polycarp has exactly k days for training!
Polycarp doesn't want to procrastinate, so he wants to solve at least one problem during each of k days. He also doesn't want to overwork, so if he solves x problems during some day, he should solve no more than 2x problems during the next day. And, at last, he wants to improve his skill, so if he solves x problems during some day, he should solve at least x+1 problem during the next day.
More formally: let [a_1, a_2, ..., a_k] be the array of numbers of problems solved by Polycarp. The i-th element of this array is the number of problems Polycarp solves during the i-th day of his training. Then the following conditions must be satisfied:
* sum of all a_i for i from 1 to k should be n;
* a_i should be greater than zero for each i from 1 to k;
* the condition a_i < a_{i + 1} β€ 2 a_i should be satisfied for each i from 1 to k-1.
Your problem is to find any array a of length k satisfying the conditions above or say that it is impossible to do it.
Input
The first line of the input contains two integers n and k (1 β€ n β€ 10^9, 1 β€ k β€ 10^5) β the number of problems Polycarp wants to solve and the number of days Polycarp wants to train.
Output
If it is impossible to find any array a of length k satisfying Polycarp's rules of training, print "NO" in the first line.
Otherwise print "YES" in the first line, then print k integers a_1, a_2, ..., a_k in the second line, where a_i should be the number of problems Polycarp should solve during the i-th day. If there are multiple answers, you can print any.
Examples
Input
26 6
Output
YES
1 2 4 5 6 8
Input
8 3
Output
NO
Input
1 1
Output
YES
1
Input
9 4
Output
NO
Tags: constructive algorithms, greedy, math
Correct Solution:
```
from math import *
def f(n,k,a):
if k == 0:
return 0
L = max(ceil(n/(2**k - 1)), a+1)
R = floor(n/k - (k-1)/2)
if not (a == 0):
R = min(R,2*a)
if ( R >= L ):
return L
else:
return 0
nk = input().split()
n = int(nk[0])
k = int(nk[1])
sol = [0]* k
subst = 0
lasta = 0
for i in range(k):
sol[i] = f((n-subst), k-i, lasta)
lasta = sol[i]
subst += lasta
if 0 in sol:
print("NO")
exit(0)
print("YES")
print(' '.join(str(x) for x in sol))
```
| 42,979 | [
0.57666015625,
0.2005615234375,
0.020477294921875,
0.23291015625,
-0.421875,
-0.45703125,
-0.4345703125,
0.0618896484375,
0.2178955078125,
0.75,
0.89306640625,
-0.289306640625,
0.39013671875,
-0.8037109375,
-0.392578125,
-0.19384765625,
-0.421875,
-0.61181640625,
-1.0439453125,
... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp has to solve exactly n problems to improve his programming skill before an important programming competition. But this competition will be held very soon, most precisely, it will start in k days. It means that Polycarp has exactly k days for training!
Polycarp doesn't want to procrastinate, so he wants to solve at least one problem during each of k days. He also doesn't want to overwork, so if he solves x problems during some day, he should solve no more than 2x problems during the next day. And, at last, he wants to improve his skill, so if he solves x problems during some day, he should solve at least x+1 problem during the next day.
More formally: let [a_1, a_2, ..., a_k] be the array of numbers of problems solved by Polycarp. The i-th element of this array is the number of problems Polycarp solves during the i-th day of his training. Then the following conditions must be satisfied:
* sum of all a_i for i from 1 to k should be n;
* a_i should be greater than zero for each i from 1 to k;
* the condition a_i < a_{i + 1} β€ 2 a_i should be satisfied for each i from 1 to k-1.
Your problem is to find any array a of length k satisfying the conditions above or say that it is impossible to do it.
Input
The first line of the input contains two integers n and k (1 β€ n β€ 10^9, 1 β€ k β€ 10^5) β the number of problems Polycarp wants to solve and the number of days Polycarp wants to train.
Output
If it is impossible to find any array a of length k satisfying Polycarp's rules of training, print "NO" in the first line.
Otherwise print "YES" in the first line, then print k integers a_1, a_2, ..., a_k in the second line, where a_i should be the number of problems Polycarp should solve during the i-th day. If there are multiple answers, you can print any.
Examples
Input
26 6
Output
YES
1 2 4 5 6 8
Input
8 3
Output
NO
Input
1 1
Output
YES
1
Input
9 4
Output
NO
Tags: constructive algorithms, greedy, math
Correct Solution:
```
def solve():
N, K = map(int, input().split())
result = list(range(1, K+1))
Sum = (K*(K+1))//2
if N < Sum:
print ("NO")
return
add = (N - Sum)//K
for i in range(K):
result[i] += add
add = (N - Sum) % K
i = K-1
while i > 0 and add:
x = min(2*result[i-1] - result[i], add)
result[i] += x
add -= x
i -= 1
if sum(result) != N:
print ("NO")
return
print ("YES")
print (' '.join(map(str, result)))
if __name__ == "__main__":
solve()
```
| 42,980 | [
0.57666015625,
0.2005615234375,
0.020477294921875,
0.23291015625,
-0.421875,
-0.45703125,
-0.4345703125,
0.0618896484375,
0.2178955078125,
0.75,
0.89306640625,
-0.289306640625,
0.39013671875,
-0.8037109375,
-0.392578125,
-0.19384765625,
-0.421875,
-0.61181640625,
-1.0439453125,
... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp has to solve exactly n problems to improve his programming skill before an important programming competition. But this competition will be held very soon, most precisely, it will start in k days. It means that Polycarp has exactly k days for training!
Polycarp doesn't want to procrastinate, so he wants to solve at least one problem during each of k days. He also doesn't want to overwork, so if he solves x problems during some day, he should solve no more than 2x problems during the next day. And, at last, he wants to improve his skill, so if he solves x problems during some day, he should solve at least x+1 problem during the next day.
More formally: let [a_1, a_2, ..., a_k] be the array of numbers of problems solved by Polycarp. The i-th element of this array is the number of problems Polycarp solves during the i-th day of his training. Then the following conditions must be satisfied:
* sum of all a_i for i from 1 to k should be n;
* a_i should be greater than zero for each i from 1 to k;
* the condition a_i < a_{i + 1} β€ 2 a_i should be satisfied for each i from 1 to k-1.
Your problem is to find any array a of length k satisfying the conditions above or say that it is impossible to do it.
Input
The first line of the input contains two integers n and k (1 β€ n β€ 10^9, 1 β€ k β€ 10^5) β the number of problems Polycarp wants to solve and the number of days Polycarp wants to train.
Output
If it is impossible to find any array a of length k satisfying Polycarp's rules of training, print "NO" in the first line.
Otherwise print "YES" in the first line, then print k integers a_1, a_2, ..., a_k in the second line, where a_i should be the number of problems Polycarp should solve during the i-th day. If there are multiple answers, you can print any.
Examples
Input
26 6
Output
YES
1 2 4 5 6 8
Input
8 3
Output
NO
Input
1 1
Output
YES
1
Input
9 4
Output
NO
Tags: constructive algorithms, greedy, math
Correct Solution:
```
#!/usr/bin/evn python
# -*- coding: utf-8 -*-
import math
"""
26 6
2 5
"""
def solution():
n, k = map(int, input().strip().split())
# n, k = 200, 30
a = []
for i in range(k):
mi = math.floor((2 * n / (k - i) + i + 1 - k) / 2)
if mi < 0:
break
mi = 2 * a[-1] if len(a) > 0 and mi > 2 * a[-1] else mi
a.append(mi)
n -= mi
if n != 0:
print('NO')
# print(a)
else:
print('YES')
print(' '.join(map(str, a)))
# print(sum(a))
while True:
try:
solution()
except:
break
# solution()
```
| 42,981 | [
0.57666015625,
0.2005615234375,
0.020477294921875,
0.23291015625,
-0.421875,
-0.45703125,
-0.4345703125,
0.0618896484375,
0.2178955078125,
0.75,
0.89306640625,
-0.289306640625,
0.39013671875,
-0.8037109375,
-0.392578125,
-0.19384765625,
-0.421875,
-0.61181640625,
-1.0439453125,
... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp has to solve exactly n problems to improve his programming skill before an important programming competition. But this competition will be held very soon, most precisely, it will start in k days. It means that Polycarp has exactly k days for training!
Polycarp doesn't want to procrastinate, so he wants to solve at least one problem during each of k days. He also doesn't want to overwork, so if he solves x problems during some day, he should solve no more than 2x problems during the next day. And, at last, he wants to improve his skill, so if he solves x problems during some day, he should solve at least x+1 problem during the next day.
More formally: let [a_1, a_2, ..., a_k] be the array of numbers of problems solved by Polycarp. The i-th element of this array is the number of problems Polycarp solves during the i-th day of his training. Then the following conditions must be satisfied:
* sum of all a_i for i from 1 to k should be n;
* a_i should be greater than zero for each i from 1 to k;
* the condition a_i < a_{i + 1} β€ 2 a_i should be satisfied for each i from 1 to k-1.
Your problem is to find any array a of length k satisfying the conditions above or say that it is impossible to do it.
Input
The first line of the input contains two integers n and k (1 β€ n β€ 10^9, 1 β€ k β€ 10^5) β the number of problems Polycarp wants to solve and the number of days Polycarp wants to train.
Output
If it is impossible to find any array a of length k satisfying Polycarp's rules of training, print "NO" in the first line.
Otherwise print "YES" in the first line, then print k integers a_1, a_2, ..., a_k in the second line, where a_i should be the number of problems Polycarp should solve during the i-th day. If there are multiple answers, you can print any.
Examples
Input
26 6
Output
YES
1 2 4 5 6 8
Input
8 3
Output
NO
Input
1 1
Output
YES
1
Input
9 4
Output
NO
Tags: constructive algorithms, greedy, math
Correct Solution:
```
def mp():
return map(int, input().split())
n, k = mp()
a = [i for i in range(1, k + 1)]
s = (1 + k) * k // 2
p = [0] * k
pp = 0
i = 0
while i < k and s < n:
#print((n - s), (k - i), (n - s) // (k - i))
q = (n - s) // (k - i)
if i == 0 or a[i] + q <= 2 * a[i - 1] + pp:
p[i] = q
pp += q
s += q * (k - i)
i += 1
if s == n:
print('YES')
q = 0
for i in range(k):
q += p[i]
print(a[i] + q, end = ' ')
else:
print('NO')
```
| 42,982 | [
0.57666015625,
0.2005615234375,
0.020477294921875,
0.23291015625,
-0.421875,
-0.45703125,
-0.4345703125,
0.0618896484375,
0.2178955078125,
0.75,
0.89306640625,
-0.289306640625,
0.39013671875,
-0.8037109375,
-0.392578125,
-0.19384765625,
-0.421875,
-0.61181640625,
-1.0439453125,
... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp has to solve exactly n problems to improve his programming skill before an important programming competition. But this competition will be held very soon, most precisely, it will start in k days. It means that Polycarp has exactly k days for training!
Polycarp doesn't want to procrastinate, so he wants to solve at least one problem during each of k days. He also doesn't want to overwork, so if he solves x problems during some day, he should solve no more than 2x problems during the next day. And, at last, he wants to improve his skill, so if he solves x problems during some day, he should solve at least x+1 problem during the next day.
More formally: let [a_1, a_2, ..., a_k] be the array of numbers of problems solved by Polycarp. The i-th element of this array is the number of problems Polycarp solves during the i-th day of his training. Then the following conditions must be satisfied:
* sum of all a_i for i from 1 to k should be n;
* a_i should be greater than zero for each i from 1 to k;
* the condition a_i < a_{i + 1} β€ 2 a_i should be satisfied for each i from 1 to k-1.
Your problem is to find any array a of length k satisfying the conditions above or say that it is impossible to do it.
Input
The first line of the input contains two integers n and k (1 β€ n β€ 10^9, 1 β€ k β€ 10^5) β the number of problems Polycarp wants to solve and the number of days Polycarp wants to train.
Output
If it is impossible to find any array a of length k satisfying Polycarp's rules of training, print "NO" in the first line.
Otherwise print "YES" in the first line, then print k integers a_1, a_2, ..., a_k in the second line, where a_i should be the number of problems Polycarp should solve during the i-th day. If there are multiple answers, you can print any.
Examples
Input
26 6
Output
YES
1 2 4 5 6 8
Input
8 3
Output
NO
Input
1 1
Output
YES
1
Input
9 4
Output
NO
Tags: constructive algorithms, greedy, math
Correct Solution:
```
def main():
n, k = map(int, input().split())
if n < k*(k+1)//2:
print('NO')
else:
add = (n-k*(k+1)//2) // k
res = [x+add for x in range(1, k+1)]
left = n-sum(res)
added = True
while left > 0 and added:
added = False
pos = k-1
while pos > 0:
while left > 0 and res[pos]+1 <= 2*res[pos-1]:
res[pos] += 1
left -= 1
added = True
pos -= 1
ok = True
for i in range(k-1):
if res[i+1]<=res[i] or res[i+1] > 2*res[i]:
ok = False
break
if ok and left == 0:
print('YES')
print(*res)
else:
print('NO')
if __name__ == '__main__':
main()
```
| 42,983 | [
0.57666015625,
0.2005615234375,
0.020477294921875,
0.23291015625,
-0.421875,
-0.45703125,
-0.4345703125,
0.0618896484375,
0.2178955078125,
0.75,
0.89306640625,
-0.289306640625,
0.39013671875,
-0.8037109375,
-0.392578125,
-0.19384765625,
-0.421875,
-0.61181640625,
-1.0439453125,
... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp has to solve exactly n problems to improve his programming skill before an important programming competition. But this competition will be held very soon, most precisely, it will start in k days. It means that Polycarp has exactly k days for training!
Polycarp doesn't want to procrastinate, so he wants to solve at least one problem during each of k days. He also doesn't want to overwork, so if he solves x problems during some day, he should solve no more than 2x problems during the next day. And, at last, he wants to improve his skill, so if he solves x problems during some day, he should solve at least x+1 problem during the next day.
More formally: let [a_1, a_2, ..., a_k] be the array of numbers of problems solved by Polycarp. The i-th element of this array is the number of problems Polycarp solves during the i-th day of his training. Then the following conditions must be satisfied:
* sum of all a_i for i from 1 to k should be n;
* a_i should be greater than zero for each i from 1 to k;
* the condition a_i < a_{i + 1} β€ 2 a_i should be satisfied for each i from 1 to k-1.
Your problem is to find any array a of length k satisfying the conditions above or say that it is impossible to do it.
Input
The first line of the input contains two integers n and k (1 β€ n β€ 10^9, 1 β€ k β€ 10^5) β the number of problems Polycarp wants to solve and the number of days Polycarp wants to train.
Output
If it is impossible to find any array a of length k satisfying Polycarp's rules of training, print "NO" in the first line.
Otherwise print "YES" in the first line, then print k integers a_1, a_2, ..., a_k in the second line, where a_i should be the number of problems Polycarp should solve during the i-th day. If there are multiple answers, you can print any.
Examples
Input
26 6
Output
YES
1 2 4 5 6 8
Input
8 3
Output
NO
Input
1 1
Output
YES
1
Input
9 4
Output
NO
Tags: constructive algorithms, greedy, math
Correct Solution:
```
def check(n, k, fl, fr):
if n < k * (2 * fl + k - 1) // 2:
return 1
if k <= 32 and n > fr * (2**k - 1):
return -1
return 0
def main():
n, k = map(int, input().split(' '))
l, r = 1, n
ans = []
while k > 0:
ll, rr = l, r
cnt = -1
while rr >= ll:
mid = (ll + rr) // 2
ck = check(n - mid, k - 1, mid + 1, mid * 2)
if ck == 0:
cnt = mid
break
elif ck < 0:
ll = mid + 1
else:
rr = mid - 1
if cnt == -1:
print('NO')
return
ans.append(cnt)
k -= 1
n -= cnt
l = cnt + 1
r = min(n, cnt * 2)
print('YES')
print(*ans)
if __name__ == '__main__':
main()
```
| 42,984 | [
0.57666015625,
0.2005615234375,
0.020477294921875,
0.23291015625,
-0.421875,
-0.45703125,
-0.4345703125,
0.0618896484375,
0.2178955078125,
0.75,
0.89306640625,
-0.289306640625,
0.39013671875,
-0.8037109375,
-0.392578125,
-0.19384765625,
-0.421875,
-0.61181640625,
-1.0439453125,
... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp has to solve exactly n problems to improve his programming skill before an important programming competition. But this competition will be held very soon, most precisely, it will start in k days. It means that Polycarp has exactly k days for training!
Polycarp doesn't want to procrastinate, so he wants to solve at least one problem during each of k days. He also doesn't want to overwork, so if he solves x problems during some day, he should solve no more than 2x problems during the next day. And, at last, he wants to improve his skill, so if he solves x problems during some day, he should solve at least x+1 problem during the next day.
More formally: let [a_1, a_2, ..., a_k] be the array of numbers of problems solved by Polycarp. The i-th element of this array is the number of problems Polycarp solves during the i-th day of his training. Then the following conditions must be satisfied:
* sum of all a_i for i from 1 to k should be n;
* a_i should be greater than zero for each i from 1 to k;
* the condition a_i < a_{i + 1} β€ 2 a_i should be satisfied for each i from 1 to k-1.
Your problem is to find any array a of length k satisfying the conditions above or say that it is impossible to do it.
Input
The first line of the input contains two integers n and k (1 β€ n β€ 10^9, 1 β€ k β€ 10^5) β the number of problems Polycarp wants to solve and the number of days Polycarp wants to train.
Output
If it is impossible to find any array a of length k satisfying Polycarp's rules of training, print "NO" in the first line.
Otherwise print "YES" in the first line, then print k integers a_1, a_2, ..., a_k in the second line, where a_i should be the number of problems Polycarp should solve during the i-th day. If there are multiple answers, you can print any.
Examples
Input
26 6
Output
YES
1 2 4 5 6 8
Input
8 3
Output
NO
Input
1 1
Output
YES
1
Input
9 4
Output
NO
Submitted Solution:
```
n, k = map(int, input().split())
max_x = (n - k * (k - 1) // 2) / k
if max_x < 1:
print('NO')
exit(0)
x = int(max_x)
r = n - (k * x + k * (k - 1) // 2)
A = [x + i for i in range(k)]
p = r + 1
while r > 0 and r != p:
p = r
for i in range(k - 1, 0, -1):
q = min(r, 2 * A[i - 1] - A[i])
r -= q
A[i] += q
if r == 0:
break
if r == 0:
print('YES')
print(*A, sep=' ')
else:
print('NO')
```
Yes
| 42,985 | [
0.6533203125,
0.283447265625,
-0.006877899169921875,
0.192138671875,
-0.474853515625,
-0.297119140625,
-0.395263671875,
0.144287109375,
0.1351318359375,
0.75439453125,
0.84228515625,
-0.2431640625,
0.308837890625,
-0.86279296875,
-0.43408203125,
-0.2354736328125,
-0.405517578125,
-... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp has to solve exactly n problems to improve his programming skill before an important programming competition. But this competition will be held very soon, most precisely, it will start in k days. It means that Polycarp has exactly k days for training!
Polycarp doesn't want to procrastinate, so he wants to solve at least one problem during each of k days. He also doesn't want to overwork, so if he solves x problems during some day, he should solve no more than 2x problems during the next day. And, at last, he wants to improve his skill, so if he solves x problems during some day, he should solve at least x+1 problem during the next day.
More formally: let [a_1, a_2, ..., a_k] be the array of numbers of problems solved by Polycarp. The i-th element of this array is the number of problems Polycarp solves during the i-th day of his training. Then the following conditions must be satisfied:
* sum of all a_i for i from 1 to k should be n;
* a_i should be greater than zero for each i from 1 to k;
* the condition a_i < a_{i + 1} β€ 2 a_i should be satisfied for each i from 1 to k-1.
Your problem is to find any array a of length k satisfying the conditions above or say that it is impossible to do it.
Input
The first line of the input contains two integers n and k (1 β€ n β€ 10^9, 1 β€ k β€ 10^5) β the number of problems Polycarp wants to solve and the number of days Polycarp wants to train.
Output
If it is impossible to find any array a of length k satisfying Polycarp's rules of training, print "NO" in the first line.
Otherwise print "YES" in the first line, then print k integers a_1, a_2, ..., a_k in the second line, where a_i should be the number of problems Polycarp should solve during the i-th day. If there are multiple answers, you can print any.
Examples
Input
26 6
Output
YES
1 2 4 5 6 8
Input
8 3
Output
NO
Input
1 1
Output
YES
1
Input
9 4
Output
NO
Submitted Solution:
```
n, k = list(map(int, input().split()))
mi = (k * (k+1))//2
mx = 2**(k-1)
if n<mi:
print('NO')
else:
ans = []
for i in range(1, k+1):
ans.append(i)
remain = n-mi
add = remain//k
if add:
for i in range(k):
ans[i]+=add
remain-=(k*add)
while remain:
i = k-1
while remain and ans[i] < (add + ans[0] * 2**(i)):
ans[i]+=1
i-=1
remain-=1
if ans[-1] == (add + ans[0] * 2**(k-1)):
break
if remain:
print('NO')
else:
print('YES')
for a in ans[:-1]:
print(a, end=" ")
print(ans[-1])
```
Yes
| 42,986 | [
0.6533203125,
0.283447265625,
-0.006877899169921875,
0.192138671875,
-0.474853515625,
-0.297119140625,
-0.395263671875,
0.144287109375,
0.1351318359375,
0.75439453125,
0.84228515625,
-0.2431640625,
0.308837890625,
-0.86279296875,
-0.43408203125,
-0.2354736328125,
-0.405517578125,
-... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp has to solve exactly n problems to improve his programming skill before an important programming competition. But this competition will be held very soon, most precisely, it will start in k days. It means that Polycarp has exactly k days for training!
Polycarp doesn't want to procrastinate, so he wants to solve at least one problem during each of k days. He also doesn't want to overwork, so if he solves x problems during some day, he should solve no more than 2x problems during the next day. And, at last, he wants to improve his skill, so if he solves x problems during some day, he should solve at least x+1 problem during the next day.
More formally: let [a_1, a_2, ..., a_k] be the array of numbers of problems solved by Polycarp. The i-th element of this array is the number of problems Polycarp solves during the i-th day of his training. Then the following conditions must be satisfied:
* sum of all a_i for i from 1 to k should be n;
* a_i should be greater than zero for each i from 1 to k;
* the condition a_i < a_{i + 1} β€ 2 a_i should be satisfied for each i from 1 to k-1.
Your problem is to find any array a of length k satisfying the conditions above or say that it is impossible to do it.
Input
The first line of the input contains two integers n and k (1 β€ n β€ 10^9, 1 β€ k β€ 10^5) β the number of problems Polycarp wants to solve and the number of days Polycarp wants to train.
Output
If it is impossible to find any array a of length k satisfying Polycarp's rules of training, print "NO" in the first line.
Otherwise print "YES" in the first line, then print k integers a_1, a_2, ..., a_k in the second line, where a_i should be the number of problems Polycarp should solve during the i-th day. If there are multiple answers, you can print any.
Examples
Input
26 6
Output
YES
1 2 4 5 6 8
Input
8 3
Output
NO
Input
1 1
Output
YES
1
Input
9 4
Output
NO
Submitted Solution:
```
n, k = map(int, input().split())
d = [0]*k
if k == 1:
print ('YES')
print (n)
else:
for i in range(k):
d[i] = i + 1
if sum(d) > n:
print ('NO')
else:
t = n - sum(d)
if t >= k:
a = t // k
t = t % k
for i in range(k):
d[i] += a
if t > 0:
if d[0] > 1:
for i in range(k-1, k-1-t, -1):
d[i] += 1
elif d[0] == 1:
for i in range(k-1, 1, -1):
d[i] += 1
t -= 1
if t == 0:
break
if t > 0:
for i in range(k-1, 2, -1):
d[i] += 1
t -= 1
if t == 0:
break
# print (d)
chk = True
for i in range(k - 1):
if d[i + 1] > 2 * d[i]:
chk = False
break
if sum(d) != n:
chk = False
if chk:
print ('YES')
s = ""
for i in d:
s += str(i) + " "
print (s[:-1])
else:
print ('NO')
```
Yes
| 42,987 | [
0.6533203125,
0.283447265625,
-0.006877899169921875,
0.192138671875,
-0.474853515625,
-0.297119140625,
-0.395263671875,
0.144287109375,
0.1351318359375,
0.75439453125,
0.84228515625,
-0.2431640625,
0.308837890625,
-0.86279296875,
-0.43408203125,
-0.2354736328125,
-0.405517578125,
-... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp has to solve exactly n problems to improve his programming skill before an important programming competition. But this competition will be held very soon, most precisely, it will start in k days. It means that Polycarp has exactly k days for training!
Polycarp doesn't want to procrastinate, so he wants to solve at least one problem during each of k days. He also doesn't want to overwork, so if he solves x problems during some day, he should solve no more than 2x problems during the next day. And, at last, he wants to improve his skill, so if he solves x problems during some day, he should solve at least x+1 problem during the next day.
More formally: let [a_1, a_2, ..., a_k] be the array of numbers of problems solved by Polycarp. The i-th element of this array is the number of problems Polycarp solves during the i-th day of his training. Then the following conditions must be satisfied:
* sum of all a_i for i from 1 to k should be n;
* a_i should be greater than zero for each i from 1 to k;
* the condition a_i < a_{i + 1} β€ 2 a_i should be satisfied for each i from 1 to k-1.
Your problem is to find any array a of length k satisfying the conditions above or say that it is impossible to do it.
Input
The first line of the input contains two integers n and k (1 β€ n β€ 10^9, 1 β€ k β€ 10^5) β the number of problems Polycarp wants to solve and the number of days Polycarp wants to train.
Output
If it is impossible to find any array a of length k satisfying Polycarp's rules of training, print "NO" in the first line.
Otherwise print "YES" in the first line, then print k integers a_1, a_2, ..., a_k in the second line, where a_i should be the number of problems Polycarp should solve during the i-th day. If there are multiple answers, you can print any.
Examples
Input
26 6
Output
YES
1 2 4 5 6 8
Input
8 3
Output
NO
Input
1 1
Output
YES
1
Input
9 4
Output
NO
Submitted Solution:
```
n, k = [int(i) for i in input().split()]
def ok(a):
print("YES")
print(*a)
if k * (k + 1) // 2 > n:
print("NO")
else:
v = (n - k * (k + 1) // 2) // k
a = [v + i for i in range(1, k + 1)]
if v == 0:
if k == 2:
if sum(a) != n:
print("NO")
else:
ok(a)
elif k == 3:
if n == 6:
print(ok(a))
elif n == 7:
print("YES")
print("1 2 4")
else:
print("NO")
else:
if sum(a) < n:
a[-2] += 1
a[-1] += n - sum(a)
ok(a)
else:
a[-1] += n - sum(a)
ok(a)
```
Yes
| 42,988 | [
0.6533203125,
0.283447265625,
-0.006877899169921875,
0.192138671875,
-0.474853515625,
-0.297119140625,
-0.395263671875,
0.144287109375,
0.1351318359375,
0.75439453125,
0.84228515625,
-0.2431640625,
0.308837890625,
-0.86279296875,
-0.43408203125,
-0.2354736328125,
-0.405517578125,
-... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp has to solve exactly n problems to improve his programming skill before an important programming competition. But this competition will be held very soon, most precisely, it will start in k days. It means that Polycarp has exactly k days for training!
Polycarp doesn't want to procrastinate, so he wants to solve at least one problem during each of k days. He also doesn't want to overwork, so if he solves x problems during some day, he should solve no more than 2x problems during the next day. And, at last, he wants to improve his skill, so if he solves x problems during some day, he should solve at least x+1 problem during the next day.
More formally: let [a_1, a_2, ..., a_k] be the array of numbers of problems solved by Polycarp. The i-th element of this array is the number of problems Polycarp solves during the i-th day of his training. Then the following conditions must be satisfied:
* sum of all a_i for i from 1 to k should be n;
* a_i should be greater than zero for each i from 1 to k;
* the condition a_i < a_{i + 1} β€ 2 a_i should be satisfied for each i from 1 to k-1.
Your problem is to find any array a of length k satisfying the conditions above or say that it is impossible to do it.
Input
The first line of the input contains two integers n and k (1 β€ n β€ 10^9, 1 β€ k β€ 10^5) β the number of problems Polycarp wants to solve and the number of days Polycarp wants to train.
Output
If it is impossible to find any array a of length k satisfying Polycarp's rules of training, print "NO" in the first line.
Otherwise print "YES" in the first line, then print k integers a_1, a_2, ..., a_k in the second line, where a_i should be the number of problems Polycarp should solve during the i-th day. If there are multiple answers, you can print any.
Examples
Input
26 6
Output
YES
1 2 4 5 6 8
Input
8 3
Output
NO
Input
1 1
Output
YES
1
Input
9 4
Output
NO
Submitted Solution:
```
n, k = [int(s) for s in input().split()]
if n < k * (k + 1) / 2:
print("NO")
exit()
if ((k == 3 and n == 8) or (k == 2 and n < 3)):
print("NO")
exit()
print("YES")
if k == 1:
print(n)
elif (k == 2):
print((n + 2) // 3, n - (n + 2) // 3)
else:
i = 1
while i * k + k * (k - 1) // 2 <= n:
i += 1
i -= 1
last = i + k - 1
last_ = last - 1
sum = i * (k - 1) + (k - 2) * (k - 1) // 2
last = n - sum
if last_ * 2 >= last:
for q in range(i, last_ + 1):
print(q, end = " ")
print(last)
exit()
last_ += 1
last -= 1
for q in range(i, i + k - 2):
print(q, end=" ")
print(last_, end=' ')
print(last)
```
No
| 42,989 | [
0.6533203125,
0.283447265625,
-0.006877899169921875,
0.192138671875,
-0.474853515625,
-0.297119140625,
-0.395263671875,
0.144287109375,
0.1351318359375,
0.75439453125,
0.84228515625,
-0.2431640625,
0.308837890625,
-0.86279296875,
-0.43408203125,
-0.2354736328125,
-0.405517578125,
-... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp has to solve exactly n problems to improve his programming skill before an important programming competition. But this competition will be held very soon, most precisely, it will start in k days. It means that Polycarp has exactly k days for training!
Polycarp doesn't want to procrastinate, so he wants to solve at least one problem during each of k days. He also doesn't want to overwork, so if he solves x problems during some day, he should solve no more than 2x problems during the next day. And, at last, he wants to improve his skill, so if he solves x problems during some day, he should solve at least x+1 problem during the next day.
More formally: let [a_1, a_2, ..., a_k] be the array of numbers of problems solved by Polycarp. The i-th element of this array is the number of problems Polycarp solves during the i-th day of his training. Then the following conditions must be satisfied:
* sum of all a_i for i from 1 to k should be n;
* a_i should be greater than zero for each i from 1 to k;
* the condition a_i < a_{i + 1} β€ 2 a_i should be satisfied for each i from 1 to k-1.
Your problem is to find any array a of length k satisfying the conditions above or say that it is impossible to do it.
Input
The first line of the input contains two integers n and k (1 β€ n β€ 10^9, 1 β€ k β€ 10^5) β the number of problems Polycarp wants to solve and the number of days Polycarp wants to train.
Output
If it is impossible to find any array a of length k satisfying Polycarp's rules of training, print "NO" in the first line.
Otherwise print "YES" in the first line, then print k integers a_1, a_2, ..., a_k in the second line, where a_i should be the number of problems Polycarp should solve during the i-th day. If there are multiple answers, you can print any.
Examples
Input
26 6
Output
YES
1 2 4 5 6 8
Input
8 3
Output
NO
Input
1 1
Output
YES
1
Input
9 4
Output
NO
Submitted Solution:
```
def solve():
N, K = map(int, input().split())
result = list(range(1, K+1))
Sum = (K*(K+1))//2
if N < Sum:
print ("NO")
return
add = (N - Sum)//K
for i in range(K):
result[i] += add
add = (N - Sum) % K
i = K-1
while i > 0 and add:
x = min(2*result[i-1] - result[i], add)
result[i] += x
add -= x
i -= 1
print ("YES")
print (' '.join(map(str, result)))
if __name__ == "__main__":
solve()
```
No
| 42,990 | [
0.6533203125,
0.283447265625,
-0.006877899169921875,
0.192138671875,
-0.474853515625,
-0.297119140625,
-0.395263671875,
0.144287109375,
0.1351318359375,
0.75439453125,
0.84228515625,
-0.2431640625,
0.308837890625,
-0.86279296875,
-0.43408203125,
-0.2354736328125,
-0.405517578125,
-... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp has to solve exactly n problems to improve his programming skill before an important programming competition. But this competition will be held very soon, most precisely, it will start in k days. It means that Polycarp has exactly k days for training!
Polycarp doesn't want to procrastinate, so he wants to solve at least one problem during each of k days. He also doesn't want to overwork, so if he solves x problems during some day, he should solve no more than 2x problems during the next day. And, at last, he wants to improve his skill, so if he solves x problems during some day, he should solve at least x+1 problem during the next day.
More formally: let [a_1, a_2, ..., a_k] be the array of numbers of problems solved by Polycarp. The i-th element of this array is the number of problems Polycarp solves during the i-th day of his training. Then the following conditions must be satisfied:
* sum of all a_i for i from 1 to k should be n;
* a_i should be greater than zero for each i from 1 to k;
* the condition a_i < a_{i + 1} β€ 2 a_i should be satisfied for each i from 1 to k-1.
Your problem is to find any array a of length k satisfying the conditions above or say that it is impossible to do it.
Input
The first line of the input contains two integers n and k (1 β€ n β€ 10^9, 1 β€ k β€ 10^5) β the number of problems Polycarp wants to solve and the number of days Polycarp wants to train.
Output
If it is impossible to find any array a of length k satisfying Polycarp's rules of training, print "NO" in the first line.
Otherwise print "YES" in the first line, then print k integers a_1, a_2, ..., a_k in the second line, where a_i should be the number of problems Polycarp should solve during the i-th day. If there are multiple answers, you can print any.
Examples
Input
26 6
Output
YES
1 2 4 5 6 8
Input
8 3
Output
NO
Input
1 1
Output
YES
1
Input
9 4
Output
NO
Submitted Solution:
```
def find(n,k):
lst = list(range(1,k+1))
sm = k * (k+1) / 2
r = k-1
while sm < n:
# double
# print(r,sm)
# print(lst)
if sm + -lst[r] + lst[r-1] * 2 <= n:
sm += -lst[r] + lst[r-1] * 2
lst[r] = lst[r-1] * 2
else:
lst[r] += int(n - sm)
sm = n
r -= 1
print(" ".join(list(map(str, lst))))
return lst
n, k = list(map(int, input().split()))
if k > 44725:
print("NO")
else:
lb = k * (k+1) // 2
if k < 31:
ub = 2 ** (k) - 1
if n >= lb and n <= ub:
print("YES")
find(n,k)
else:
print("NO")
else:
if n >= lb:
print("YES")
find(n,k)
else:
print("NO")
```
No
| 42,991 | [
0.6533203125,
0.283447265625,
-0.006877899169921875,
0.192138671875,
-0.474853515625,
-0.297119140625,
-0.395263671875,
0.144287109375,
0.1351318359375,
0.75439453125,
0.84228515625,
-0.2431640625,
0.308837890625,
-0.86279296875,
-0.43408203125,
-0.2354736328125,
-0.405517578125,
-... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp has to solve exactly n problems to improve his programming skill before an important programming competition. But this competition will be held very soon, most precisely, it will start in k days. It means that Polycarp has exactly k days for training!
Polycarp doesn't want to procrastinate, so he wants to solve at least one problem during each of k days. He also doesn't want to overwork, so if he solves x problems during some day, he should solve no more than 2x problems during the next day. And, at last, he wants to improve his skill, so if he solves x problems during some day, he should solve at least x+1 problem during the next day.
More formally: let [a_1, a_2, ..., a_k] be the array of numbers of problems solved by Polycarp. The i-th element of this array is the number of problems Polycarp solves during the i-th day of his training. Then the following conditions must be satisfied:
* sum of all a_i for i from 1 to k should be n;
* a_i should be greater than zero for each i from 1 to k;
* the condition a_i < a_{i + 1} β€ 2 a_i should be satisfied for each i from 1 to k-1.
Your problem is to find any array a of length k satisfying the conditions above or say that it is impossible to do it.
Input
The first line of the input contains two integers n and k (1 β€ n β€ 10^9, 1 β€ k β€ 10^5) β the number of problems Polycarp wants to solve and the number of days Polycarp wants to train.
Output
If it is impossible to find any array a of length k satisfying Polycarp's rules of training, print "NO" in the first line.
Otherwise print "YES" in the first line, then print k integers a_1, a_2, ..., a_k in the second line, where a_i should be the number of problems Polycarp should solve during the i-th day. If there are multiple answers, you can print any.
Examples
Input
26 6
Output
YES
1 2 4 5 6 8
Input
8 3
Output
NO
Input
1 1
Output
YES
1
Input
9 4
Output
NO
Submitted Solution:
```
import math
def sigma(num):
ret=0
for i in range(num+1):
ret+=i
return ret
def checkans(arr):
for i in range(len(arr)-1):
if arr[i+1]<arr[i] or arr[i]*2<arr[i+1]:
return False
else:
return True
n,k=map(int,input().split())
s=sigma(k)
if n<s:
print('NO')
elif k==2:
print('YES')
print(n//k, math.ceil(n/k))
else:
prod=int(n/s)
diff=n-prod*s
arr=[prod*(i+1) for i in range(k)]
if diff==0:
print('YES')
print(' '.join(map(str,arr)))
else:
prod2=int(diff/k)
diff2=diff-prod2*k
width=math.ceil(k/2)
for i in range(k):
arr[i]+=prod2
for i in range(2):
for j in range(width):
if diff2==0:
break
arr[-(j+1)]+=1
diff2-=1
if checkans(arr)==True:
print('YES')
print(' '.join(map(str,arr)))
else:
print('NO')
```
No
| 42,992 | [
0.6533203125,
0.283447265625,
-0.006877899169921875,
0.192138671875,
-0.474853515625,
-0.297119140625,
-0.395263671875,
0.144287109375,
0.1351318359375,
0.75439453125,
0.84228515625,
-0.2431640625,
0.308837890625,
-0.86279296875,
-0.43408203125,
-0.2354736328125,
-0.405517578125,
-... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarpus just has been out of luck lately! As soon as he found a job in the "Binary Cat" cafe, the club got burgled. All ice-cream was stolen.
On the burglary night Polycarpus kept a careful record of all club visitors. Each time a visitor entered the club, Polycarpus put down character "+" in his notes. Similarly, each time a visitor left the club, Polycarpus put character "-" in his notes. We know that all cases of going in and out happened consecutively, that is, no two events happened at the same time. Polycarpus doesn't remember whether there was somebody in the club at the moment when his shift begun and at the moment when it ended.
Right now the police wonders what minimum number of distinct people Polycarpus could have seen. Assume that he sees anybody coming in or out of the club. Each person could have come in or out an arbitrary number of times.
Input
The only line of the input contains a sequence of characters "+" and "-", the characters are written one after another without any separators. The characters are written in the order, in which the corresponding events occurred. The given sequence has length from 1 to 300 characters, inclusive.
Output
Print the sought minimum number of people
Examples
Input
+-+-+
Output
1
Input
---
Output
3
Tags: greedy, implementation
Correct Solution:
```
s=input()
ans=a1=a2=0
for i in s:
if i=='+':
ans+=1
else:
ans-=1
a1=max(a1,ans)
a2=min(a2,ans)
print(a1+abs(a2))
```
| 43,268 | [
0.541015625,
0.193359375,
0.384033203125,
0.296142578125,
-0.5537109375,
-0.5068359375,
-0.267578125,
0.05322265625,
-0.01348114013671875,
0.6728515625,
0.82275390625,
-0.088623046875,
0.00399017333984375,
-0.5517578125,
-0.75390625,
-0.08526611328125,
-0.71728515625,
-0.44140625,
... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarpus just has been out of luck lately! As soon as he found a job in the "Binary Cat" cafe, the club got burgled. All ice-cream was stolen.
On the burglary night Polycarpus kept a careful record of all club visitors. Each time a visitor entered the club, Polycarpus put down character "+" in his notes. Similarly, each time a visitor left the club, Polycarpus put character "-" in his notes. We know that all cases of going in and out happened consecutively, that is, no two events happened at the same time. Polycarpus doesn't remember whether there was somebody in the club at the moment when his shift begun and at the moment when it ended.
Right now the police wonders what minimum number of distinct people Polycarpus could have seen. Assume that he sees anybody coming in or out of the club. Each person could have come in or out an arbitrary number of times.
Input
The only line of the input contains a sequence of characters "+" and "-", the characters are written one after another without any separators. The characters are written in the order, in which the corresponding events occurred. The given sequence has length from 1 to 300 characters, inclusive.
Output
Print the sought minimum number of people
Examples
Input
+-+-+
Output
1
Input
---
Output
3
Tags: greedy, implementation
Correct Solution:
```
a = [1 if x == '+' else -1 for x in input()]
b = list(map(lambda i : sum(a[0:i]), range(len(a) + 1)))
print(max(b) - min(b))
```
| 43,269 | [
0.52978515625,
0.189697265625,
0.334716796875,
0.278564453125,
-0.5361328125,
-0.479248046875,
-0.275146484375,
0.09405517578125,
-0.003971099853515625,
0.65478515625,
0.826171875,
-0.087158203125,
0.01303863525390625,
-0.5166015625,
-0.77734375,
-0.09149169921875,
-0.70947265625,
... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarpus just has been out of luck lately! As soon as he found a job in the "Binary Cat" cafe, the club got burgled. All ice-cream was stolen.
On the burglary night Polycarpus kept a careful record of all club visitors. Each time a visitor entered the club, Polycarpus put down character "+" in his notes. Similarly, each time a visitor left the club, Polycarpus put character "-" in his notes. We know that all cases of going in and out happened consecutively, that is, no two events happened at the same time. Polycarpus doesn't remember whether there was somebody in the club at the moment when his shift begun and at the moment when it ended.
Right now the police wonders what minimum number of distinct people Polycarpus could have seen. Assume that he sees anybody coming in or out of the club. Each person could have come in or out an arbitrary number of times.
Input
The only line of the input contains a sequence of characters "+" and "-", the characters are written one after another without any separators. The characters are written in the order, in which the corresponding events occurred. The given sequence has length from 1 to 300 characters, inclusive.
Output
Print the sought minimum number of people
Examples
Input
+-+-+
Output
1
Input
---
Output
3
Tags: greedy, implementation
Correct Solution:
```
s=input()
s=list(s)
s1=[0]*len(s)
for i in range(len(s)):
if s[i]=='-':
s[i]=1
s1[i]=-1
else:
s[i]=-1
s1[i]=1
def kadane(s):
maxi=-1
curr=0
for i in s:
curr=max(curr+i,i)
maxi=max(maxi,curr)
return maxi
print(max(kadane(s),kadane(s1)))
```
| 43,270 | [
0.5419921875,
0.12841796875,
0.37841796875,
0.291748046875,
-0.5556640625,
-0.494873046875,
-0.3125,
0.04046630859375,
-0.01448822021484375,
0.67041015625,
0.79248046875,
-0.03948974609375,
-0.0283050537109375,
-0.52978515625,
-0.703125,
-0.0293121337890625,
-0.73095703125,
-0.4919... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarpus just has been out of luck lately! As soon as he found a job in the "Binary Cat" cafe, the club got burgled. All ice-cream was stolen.
On the burglary night Polycarpus kept a careful record of all club visitors. Each time a visitor entered the club, Polycarpus put down character "+" in his notes. Similarly, each time a visitor left the club, Polycarpus put character "-" in his notes. We know that all cases of going in and out happened consecutively, that is, no two events happened at the same time. Polycarpus doesn't remember whether there was somebody in the club at the moment when his shift begun and at the moment when it ended.
Right now the police wonders what minimum number of distinct people Polycarpus could have seen. Assume that he sees anybody coming in or out of the club. Each person could have come in or out an arbitrary number of times.
Input
The only line of the input contains a sequence of characters "+" and "-", the characters are written one after another without any separators. The characters are written in the order, in which the corresponding events occurred. The given sequence has length from 1 to 300 characters, inclusive.
Output
Print the sought minimum number of people
Examples
Input
+-+-+
Output
1
Input
---
Output
3
Tags: greedy, implementation
Correct Solution:
```
s = input()
low = 0
high = 0
sum = 0
for i in s:
if i == '+':
sum += 1
else:
sum -= 1
if sum < low:
low = sum
if sum > high:
high = sum
print(high - low)
```
| 43,271 | [
0.560546875,
0.2069091796875,
0.357177734375,
0.279296875,
-0.5693359375,
-0.50390625,
-0.23974609375,
0.09210205078125,
-0.011932373046875,
0.6279296875,
0.84130859375,
-0.06951904296875,
-0.0084381103515625,
-0.54638671875,
-0.78955078125,
-0.07867431640625,
-0.72021484375,
-0.44... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarpus just has been out of luck lately! As soon as he found a job in the "Binary Cat" cafe, the club got burgled. All ice-cream was stolen.
On the burglary night Polycarpus kept a careful record of all club visitors. Each time a visitor entered the club, Polycarpus put down character "+" in his notes. Similarly, each time a visitor left the club, Polycarpus put character "-" in his notes. We know that all cases of going in and out happened consecutively, that is, no two events happened at the same time. Polycarpus doesn't remember whether there was somebody in the club at the moment when his shift begun and at the moment when it ended.
Right now the police wonders what minimum number of distinct people Polycarpus could have seen. Assume that he sees anybody coming in or out of the club. Each person could have come in or out an arbitrary number of times.
Input
The only line of the input contains a sequence of characters "+" and "-", the characters are written one after another without any separators. The characters are written in the order, in which the corresponding events occurred. The given sequence has length from 1 to 300 characters, inclusive.
Output
Print the sought minimum number of people
Examples
Input
+-+-+
Output
1
Input
---
Output
3
Tags: greedy, implementation
Correct Solution:
```
c, v1, v2 = 0, 0, 0
for ch in input():
c += 1 if ch == '+' else -1
v1, v2 = min(v1, c), max(v2, c)
print(v2 - v1)
```
| 43,272 | [
0.54833984375,
0.1939697265625,
0.38134765625,
0.295166015625,
-0.55322265625,
-0.51171875,
-0.2744140625,
0.05755615234375,
-0.029296875,
0.66748046875,
0.82421875,
-0.1002197265625,
-0.0016813278198242188,
-0.55859375,
-0.771484375,
-0.10247802734375,
-0.71044921875,
-0.438964843... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarpus just has been out of luck lately! As soon as he found a job in the "Binary Cat" cafe, the club got burgled. All ice-cream was stolen.
On the burglary night Polycarpus kept a careful record of all club visitors. Each time a visitor entered the club, Polycarpus put down character "+" in his notes. Similarly, each time a visitor left the club, Polycarpus put character "-" in his notes. We know that all cases of going in and out happened consecutively, that is, no two events happened at the same time. Polycarpus doesn't remember whether there was somebody in the club at the moment when his shift begun and at the moment when it ended.
Right now the police wonders what minimum number of distinct people Polycarpus could have seen. Assume that he sees anybody coming in or out of the club. Each person could have come in or out an arbitrary number of times.
Input
The only line of the input contains a sequence of characters "+" and "-", the characters are written one after another without any separators. The characters are written in the order, in which the corresponding events occurred. The given sequence has length from 1 to 300 characters, inclusive.
Output
Print the sought minimum number of people
Examples
Input
+-+-+
Output
1
Input
---
Output
3
Tags: greedy, implementation
Correct Solution:
```
# collaborated with no one
suspects = input()
minSus = 0
maxSus = 0
counter = 0
for x in suspects:
if x == '+':
counter += 1
minSus = min(minSus, counter)
maxSus = max(maxSus, counter)
else:
counter -= 1
minSus = min(minSus, counter)
maxSus = max(maxSus, counter)
print(maxSus - minSus)
```
| 43,273 | [
0.56103515625,
0.20458984375,
0.393798828125,
0.27490234375,
-0.5263671875,
-0.60546875,
-0.335693359375,
0.0487060546875,
-0.0016031265258789062,
0.66064453125,
0.7919921875,
-0.113037109375,
0.00955963134765625,
-0.6015625,
-0.73486328125,
-0.0276641845703125,
-0.7587890625,
-0.4... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarpus just has been out of luck lately! As soon as he found a job in the "Binary Cat" cafe, the club got burgled. All ice-cream was stolen.
On the burglary night Polycarpus kept a careful record of all club visitors. Each time a visitor entered the club, Polycarpus put down character "+" in his notes. Similarly, each time a visitor left the club, Polycarpus put character "-" in his notes. We know that all cases of going in and out happened consecutively, that is, no two events happened at the same time. Polycarpus doesn't remember whether there was somebody in the club at the moment when his shift begun and at the moment when it ended.
Right now the police wonders what minimum number of distinct people Polycarpus could have seen. Assume that he sees anybody coming in or out of the club. Each person could have come in or out an arbitrary number of times.
Input
The only line of the input contains a sequence of characters "+" and "-", the characters are written one after another without any separators. The characters are written in the order, in which the corresponding events occurred. The given sequence has length from 1 to 300 characters, inclusive.
Output
Print the sought minimum number of people
Examples
Input
+-+-+
Output
1
Input
---
Output
3
Tags: greedy, implementation
Correct Solution:
```
#COLLABORATED WITH PRASOON SHAKYA
input_var=input()
counter1=0
counter2=0
for temp in input_var:
if temp=="+":
counter1+=1
if counter2>0:
counter2-=1
else:
counter2+=1
if counter1>0:
counter1-=1
print(counter1+counter2)
```
| 43,274 | [
0.533203125,
0.1986083984375,
0.34326171875,
0.303466796875,
-0.53857421875,
-0.51318359375,
-0.278564453125,
0.059112548828125,
-0.041473388671875,
0.642578125,
0.7744140625,
-0.10198974609375,
0.041351318359375,
-0.5849609375,
-0.80810546875,
-0.1282958984375,
-0.73583984375,
-0.... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarpus just has been out of luck lately! As soon as he found a job in the "Binary Cat" cafe, the club got burgled. All ice-cream was stolen.
On the burglary night Polycarpus kept a careful record of all club visitors. Each time a visitor entered the club, Polycarpus put down character "+" in his notes. Similarly, each time a visitor left the club, Polycarpus put character "-" in his notes. We know that all cases of going in and out happened consecutively, that is, no two events happened at the same time. Polycarpus doesn't remember whether there was somebody in the club at the moment when his shift begun and at the moment when it ended.
Right now the police wonders what minimum number of distinct people Polycarpus could have seen. Assume that he sees anybody coming in or out of the club. Each person could have come in or out an arbitrary number of times.
Input
The only line of the input contains a sequence of characters "+" and "-", the characters are written one after another without any separators. The characters are written in the order, in which the corresponding events occurred. The given sequence has length from 1 to 300 characters, inclusive.
Output
Print the sought minimum number of people
Examples
Input
+-+-+
Output
1
Input
---
Output
3
Tags: greedy, implementation
Correct Solution:
```
#Created By Minsol Jeong
def N5():
seq = input()
inside = outside = 0
for i in seq:
if (i == '+'):
inside +=1
if (outside):
outside -=1
else:
outside +=1
if (inside):
inside -=1
suspects = abs(inside + outside)
print(suspects)
if __name__=="__main__":
N5()
```
| 43,275 | [
0.52978515625,
0.1383056640625,
0.337646484375,
0.285400390625,
-0.45947265625,
-0.5107421875,
-0.2958984375,
0.0810546875,
-0.0014925003051757812,
0.640625,
0.83447265625,
-0.1131591796875,
0.053863525390625,
-0.55859375,
-0.74658203125,
-0.11236572265625,
-0.79052734375,
-0.47607... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarpus just has been out of luck lately! As soon as he found a job in the "Binary Cat" cafe, the club got burgled. All ice-cream was stolen.
On the burglary night Polycarpus kept a careful record of all club visitors. Each time a visitor entered the club, Polycarpus put down character "+" in his notes. Similarly, each time a visitor left the club, Polycarpus put character "-" in his notes. We know that all cases of going in and out happened consecutively, that is, no two events happened at the same time. Polycarpus doesn't remember whether there was somebody in the club at the moment when his shift begun and at the moment when it ended.
Right now the police wonders what minimum number of distinct people Polycarpus could have seen. Assume that he sees anybody coming in or out of the club. Each person could have come in or out an arbitrary number of times.
Input
The only line of the input contains a sequence of characters "+" and "-", the characters are written one after another without any separators. The characters are written in the order, in which the corresponding events occurred. The given sequence has length from 1 to 300 characters, inclusive.
Output
Print the sought minimum number of people
Examples
Input
+-+-+
Output
1
Input
---
Output
3
Submitted Solution:
```
def solve(s):
n = len(s)
if(n == 1):
return 1
else:
start = 0
prev = s[0]
ans = 0
f = 1
for i in range(1,n):
f = 1
if(s[i] == prev):
continue
else:
f = 0
ans = max(ans,i-start)
start = i
prev = s[i]
# print(ans)
if(f):
ans = max(ans,n-start)
start = i
prev = s[i]
return ans
def solve1(s):
st = []
ans = 0
maxx = 0
for i in s:
if(st):
ans = 0
if(i == '+'):
st.append('+')
else:
if(st):
st.pop()
else:
ans += 1
maxx = max(maxx,ans)
maxx = max(maxx,len(st))
# print(st)
maxx = max(maxx,len(st))
return maxx
def solve2(s):
st = []
ans = 0
maxx = 0
for i in s:
if(st):
ans = 0
if(i == '-'):
st.append('-')
else:
if(st):
st.pop()
else:
ans += 1
maxx = max(maxx,ans)
maxx = max(maxx,len(st))
# print(st)
maxx = max(maxx,len(st))
return maxx
l = input()
ans = solve(l)
ans1 = solve1(l)
ans2 = solve2(l)
print(max(ans,ans1,ans2))
```
Yes
| 43,276 | [
0.5654296875,
0.2403564453125,
0.25537109375,
0.1676025390625,
-0.62255859375,
-0.388427734375,
-0.416259765625,
0.3203125,
-0.11993408203125,
0.623046875,
0.8759765625,
-0.0986328125,
0.0196685791015625,
-0.6884765625,
-0.80322265625,
-0.080810546875,
-0.7265625,
-0.36669921875,
... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarpus just has been out of luck lately! As soon as he found a job in the "Binary Cat" cafe, the club got burgled. All ice-cream was stolen.
On the burglary night Polycarpus kept a careful record of all club visitors. Each time a visitor entered the club, Polycarpus put down character "+" in his notes. Similarly, each time a visitor left the club, Polycarpus put character "-" in his notes. We know that all cases of going in and out happened consecutively, that is, no two events happened at the same time. Polycarpus doesn't remember whether there was somebody in the club at the moment when his shift begun and at the moment when it ended.
Right now the police wonders what minimum number of distinct people Polycarpus could have seen. Assume that he sees anybody coming in or out of the club. Each person could have come in or out an arbitrary number of times.
Input
The only line of the input contains a sequence of characters "+" and "-", the characters are written one after another without any separators. The characters are written in the order, in which the corresponding events occurred. The given sequence has length from 1 to 300 characters, inclusive.
Output
Print the sought minimum number of people
Examples
Input
+-+-+
Output
1
Input
---
Output
3
Submitted Solution:
```
s = input()
p = 0
m = 0
for i in s:
if i == "+":
p += 1
m = max(m-1, 0)
elif i == "-":
m += 1
p = max(p-1, 0)
print(p+m)
```
Yes
| 43,277 | [
0.6591796875,
0.262939453125,
0.2239990234375,
0.240234375,
-0.69970703125,
-0.436279296875,
-0.44580078125,
0.336669921875,
-0.174072265625,
0.7265625,
0.82421875,
0.007183074951171875,
-0.011260986328125,
-0.6484375,
-0.833984375,
-0.09326171875,
-0.75244140625,
-0.37109375,
-0... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarpus just has been out of luck lately! As soon as he found a job in the "Binary Cat" cafe, the club got burgled. All ice-cream was stolen.
On the burglary night Polycarpus kept a careful record of all club visitors. Each time a visitor entered the club, Polycarpus put down character "+" in his notes. Similarly, each time a visitor left the club, Polycarpus put character "-" in his notes. We know that all cases of going in and out happened consecutively, that is, no two events happened at the same time. Polycarpus doesn't remember whether there was somebody in the club at the moment when his shift begun and at the moment when it ended.
Right now the police wonders what minimum number of distinct people Polycarpus could have seen. Assume that he sees anybody coming in or out of the club. Each person could have come in or out an arbitrary number of times.
Input
The only line of the input contains a sequence of characters "+" and "-", the characters are written one after another without any separators. The characters are written in the order, in which the corresponding events occurred. The given sequence has length from 1 to 300 characters, inclusive.
Output
Print the sought minimum number of people
Examples
Input
+-+-+
Output
1
Input
---
Output
3
Submitted Solution:
```
s = input()
d, f, r = 0, 0, 0
for c in s:
if c == "-":
f += 1
if d >= 1:
d -= 1
else:
r += 1
elif c == "+":
d += 1
if f >= 1:
f -= 1
else:
r += 1
print(r)
```
Yes
| 43,278 | [
0.61767578125,
0.2626953125,
0.245361328125,
0.2166748046875,
-0.70751953125,
-0.43017578125,
-0.441650390625,
0.331787109375,
-0.1800537109375,
0.70703125,
0.8310546875,
-0.02301025390625,
-0.02423095703125,
-0.642578125,
-0.85302734375,
-0.11053466796875,
-0.78125,
-0.39038085937... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarpus just has been out of luck lately! As soon as he found a job in the "Binary Cat" cafe, the club got burgled. All ice-cream was stolen.
On the burglary night Polycarpus kept a careful record of all club visitors. Each time a visitor entered the club, Polycarpus put down character "+" in his notes. Similarly, each time a visitor left the club, Polycarpus put character "-" in his notes. We know that all cases of going in and out happened consecutively, that is, no two events happened at the same time. Polycarpus doesn't remember whether there was somebody in the club at the moment when his shift begun and at the moment when it ended.
Right now the police wonders what minimum number of distinct people Polycarpus could have seen. Assume that he sees anybody coming in or out of the club. Each person could have come in or out an arbitrary number of times.
Input
The only line of the input contains a sequence of characters "+" and "-", the characters are written one after another without any separators. The characters are written in the order, in which the corresponding events occurred. The given sequence has length from 1 to 300 characters, inclusive.
Output
Print the sought minimum number of people
Examples
Input
+-+-+
Output
1
Input
---
Output
3
Submitted Solution:
```
s=input()
n=len(s)
x,a,b=0,0,0
for i in range(n):
if s[i]=='-':
x-=1
else:
x+=1
a = min(a,x)
b = max(b,x)
print(b-a)
```
Yes
| 43,279 | [
0.6240234375,
0.2470703125,
0.2322998046875,
0.210693359375,
-0.7021484375,
-0.4365234375,
-0.442626953125,
0.340087890625,
-0.1749267578125,
0.73291015625,
0.8505859375,
-0.023895263671875,
-0.043426513671875,
-0.64453125,
-0.81884765625,
-0.089599609375,
-0.77001953125,
-0.395507... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarpus just has been out of luck lately! As soon as he found a job in the "Binary Cat" cafe, the club got burgled. All ice-cream was stolen.
On the burglary night Polycarpus kept a careful record of all club visitors. Each time a visitor entered the club, Polycarpus put down character "+" in his notes. Similarly, each time a visitor left the club, Polycarpus put character "-" in his notes. We know that all cases of going in and out happened consecutively, that is, no two events happened at the same time. Polycarpus doesn't remember whether there was somebody in the club at the moment when his shift begun and at the moment when it ended.
Right now the police wonders what minimum number of distinct people Polycarpus could have seen. Assume that he sees anybody coming in or out of the club. Each person could have come in or out an arbitrary number of times.
Input
The only line of the input contains a sequence of characters "+" and "-", the characters are written one after another without any separators. The characters are written in the order, in which the corresponding events occurred. The given sequence has length from 1 to 300 characters, inclusive.
Output
Print the sought minimum number of people
Examples
Input
+-+-+
Output
1
Input
---
Output
3
Submitted Solution:
```
visitors = input()
unique = 0
inClubNow = 0
while '+-' in visitors:
unique += 1
visitors = ''.join(visitors.split('+-'))
if unique:
unique = 1
unique += len(visitors)
if '+' in visitors:
unique -= 1
print(unique)
```
No
| 43,280 | [
0.60107421875,
0.34912109375,
0.1383056640625,
0.1875,
-0.7109375,
-0.416259765625,
-0.5302734375,
0.372314453125,
-0.08990478515625,
0.638671875,
0.85986328125,
0.01253509521484375,
-0.037384033203125,
-0.61474609375,
-0.84375,
-0.086669921875,
-0.77001953125,
-0.3671875,
-0.427... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarpus just has been out of luck lately! As soon as he found a job in the "Binary Cat" cafe, the club got burgled. All ice-cream was stolen.
On the burglary night Polycarpus kept a careful record of all club visitors. Each time a visitor entered the club, Polycarpus put down character "+" in his notes. Similarly, each time a visitor left the club, Polycarpus put character "-" in his notes. We know that all cases of going in and out happened consecutively, that is, no two events happened at the same time. Polycarpus doesn't remember whether there was somebody in the club at the moment when his shift begun and at the moment when it ended.
Right now the police wonders what minimum number of distinct people Polycarpus could have seen. Assume that he sees anybody coming in or out of the club. Each person could have come in or out an arbitrary number of times.
Input
The only line of the input contains a sequence of characters "+" and "-", the characters are written one after another without any separators. The characters are written in the order, in which the corresponding events occurred. The given sequence has length from 1 to 300 characters, inclusive.
Output
Print the sought minimum number of people
Examples
Input
+-+-+
Output
1
Input
---
Output
3
Submitted Solution:
```
n = input()
inside_count = 0
outside_count = 0
for element in n:
if element == '+':
inside_count += 1
outside_count -= 1
if outside_count < 0 and inside_count > 100:
outside_count = 0
else:
inside_count -= 1
outside_count += 1
if inside_count < 0 or outside_count > 100:
inside_count = 0
print(inside_count + outside_count)
```
No
| 43,281 | [
0.59912109375,
0.2034912109375,
0.173583984375,
0.184814453125,
-0.64208984375,
-0.38134765625,
-0.41943359375,
0.385009765625,
-0.1453857421875,
0.7509765625,
0.84716796875,
0.0364990234375,
-0.003307342529296875,
-0.7255859375,
-0.85498046875,
-0.036651611328125,
-0.78564453125,
... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarpus just has been out of luck lately! As soon as he found a job in the "Binary Cat" cafe, the club got burgled. All ice-cream was stolen.
On the burglary night Polycarpus kept a careful record of all club visitors. Each time a visitor entered the club, Polycarpus put down character "+" in his notes. Similarly, each time a visitor left the club, Polycarpus put character "-" in his notes. We know that all cases of going in and out happened consecutively, that is, no two events happened at the same time. Polycarpus doesn't remember whether there was somebody in the club at the moment when his shift begun and at the moment when it ended.
Right now the police wonders what minimum number of distinct people Polycarpus could have seen. Assume that he sees anybody coming in or out of the club. Each person could have come in or out an arbitrary number of times.
Input
The only line of the input contains a sequence of characters "+" and "-", the characters are written one after another without any separators. The characters are written in the order, in which the corresponding events occurred. The given sequence has length from 1 to 300 characters, inclusive.
Output
Print the sought minimum number of people
Examples
Input
+-+-+
Output
1
Input
---
Output
3
Submitted Solution:
```
S = input()
ans = 0
f = 0
for i in range( len( S ) ):
if S[ i ] == '+':
f += 1
else:
f -= 1
ans = max( ans, abs( f ) )
print( ans )
```
No
| 43,282 | [
0.658203125,
0.26708984375,
0.261962890625,
0.1947021484375,
-0.7392578125,
-0.432373046875,
-0.441650390625,
0.320068359375,
-0.2020263671875,
0.71484375,
0.85986328125,
-0.03948974609375,
-0.0305023193359375,
-0.60986328125,
-0.8134765625,
-0.09893798828125,
-0.74658203125,
-0.32... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarpus just has been out of luck lately! As soon as he found a job in the "Binary Cat" cafe, the club got burgled. All ice-cream was stolen.
On the burglary night Polycarpus kept a careful record of all club visitors. Each time a visitor entered the club, Polycarpus put down character "+" in his notes. Similarly, each time a visitor left the club, Polycarpus put character "-" in his notes. We know that all cases of going in and out happened consecutively, that is, no two events happened at the same time. Polycarpus doesn't remember whether there was somebody in the club at the moment when his shift begun and at the moment when it ended.
Right now the police wonders what minimum number of distinct people Polycarpus could have seen. Assume that he sees anybody coming in or out of the club. Each person could have come in or out an arbitrary number of times.
Input
The only line of the input contains a sequence of characters "+" and "-", the characters are written one after another without any separators. The characters are written in the order, in which the corresponding events occurred. The given sequence has length from 1 to 300 characters, inclusive.
Output
Print the sought minimum number of people
Examples
Input
+-+-+
Output
1
Input
---
Output
3
Submitted Solution:
```
s=input()
a,ans=10000,0
for i in range(len(s)):
if(s[i]=='+'):
a=a+1
else:
a=a-1
if(ans < abs(a-10000)):
ans=abs(a-10000)
print(ans)
```
No
| 43,283 | [
0.61572265625,
0.2303466796875,
0.2408447265625,
0.21630859375,
-0.68798828125,
-0.416259765625,
-0.402099609375,
0.31396484375,
-0.1455078125,
0.72119140625,
0.85791015625,
-0.022979736328125,
-0.041015625,
-0.640625,
-0.81591796875,
-0.07373046875,
-0.76123046875,
-0.40576171875,... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp took n videos, the duration of the i-th video is a_i seconds. The videos are listed in the chronological order, i.e. the 1-st video is the earliest, the 2-nd video is the next, ..., the n-th video is the last.
Now Polycarp wants to publish exactly k (1 β€ k β€ n) posts in Instabram. Each video should be a part of a single post. The posts should preserve the chronological order, it means that the first post should contain one or more of the earliest videos, the second post should contain a block (one or more videos) going next and so on. In other words, if the number of videos in the j-th post is s_j then:
* s_1+s_2+...+s_k=n (s_i>0),
* the first post contains the videos: 1, 2, ..., s_1;
* the second post contains the videos: s_1+1, s_1+2, ..., s_1+s_2;
* the third post contains the videos: s_1+s_2+1, s_1+s_2+2, ..., s_1+s_2+s_3;
* ...
* the k-th post contains videos: n-s_k+1,n-s_k+2,...,n.
Polycarp is a perfectionist, he wants the total duration of videos in each post to be the same.
Help Polycarp to find such positive integer values s_1, s_2, ..., s_k that satisfy all the conditions above.
Input
The first line contains two integers n and k (1 β€ k β€ n β€ 10^5). The next line contains n positive integer numbers a_1, a_2, ..., a_n (1 β€ a_i β€ 10^4), where a_i is the duration of the i-th video.
Output
If solution exists, print "Yes" in the first line. Print k positive integers s_1, s_2, ..., s_k (s_1+s_2+...+s_k=n) in the second line. The total duration of videos in each post should be the same. It can be easily proven that the answer is unique (if it exists).
If there is no solution, print a single line "No".
Examples
Input
6 3
3 3 1 4 1 6
Output
Yes
2 3 1
Input
3 3
1 1 1
Output
Yes
1 1 1
Input
3 3
1 1 2
Output
No
Input
3 1
1 10 100
Output
Yes
3
Tags: implementation
Correct Solution:
```
def run():
n, k = map(int, input().split())
a = list(map(int, input().split()))
s = 0
for x in a: s += x
if s%k:
print("No")
return
dur = s//k
cs = 0
ans = []
for i in range(n):
cs += a[i]
if cs == dur:
ans.append(i+1)
cs = 0
elif cs > dur:
print("No")
return
print("Yes")
for i in range(len(ans)-1, 0, -1):
ans[i] = ans[i]-ans[i-1]
print(' '.join(map(str, ans)))
if __name__ == '__main__':
run()
```
| 43,829 | [
0.53564453125,
0.62890625,
0.0860595703125,
0.258544921875,
-0.131103515625,
-0.239501953125,
-0.7158203125,
0.05999755859375,
0.476318359375,
0.84619140625,
0.6171875,
-0.273681640625,
0.28076171875,
-0.89990234375,
-0.32666015625,
0.111328125,
-0.46044921875,
-0.84423828125,
-0... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp took n videos, the duration of the i-th video is a_i seconds. The videos are listed in the chronological order, i.e. the 1-st video is the earliest, the 2-nd video is the next, ..., the n-th video is the last.
Now Polycarp wants to publish exactly k (1 β€ k β€ n) posts in Instabram. Each video should be a part of a single post. The posts should preserve the chronological order, it means that the first post should contain one or more of the earliest videos, the second post should contain a block (one or more videos) going next and so on. In other words, if the number of videos in the j-th post is s_j then:
* s_1+s_2+...+s_k=n (s_i>0),
* the first post contains the videos: 1, 2, ..., s_1;
* the second post contains the videos: s_1+1, s_1+2, ..., s_1+s_2;
* the third post contains the videos: s_1+s_2+1, s_1+s_2+2, ..., s_1+s_2+s_3;
* ...
* the k-th post contains videos: n-s_k+1,n-s_k+2,...,n.
Polycarp is a perfectionist, he wants the total duration of videos in each post to be the same.
Help Polycarp to find such positive integer values s_1, s_2, ..., s_k that satisfy all the conditions above.
Input
The first line contains two integers n and k (1 β€ k β€ n β€ 10^5). The next line contains n positive integer numbers a_1, a_2, ..., a_n (1 β€ a_i β€ 10^4), where a_i is the duration of the i-th video.
Output
If solution exists, print "Yes" in the first line. Print k positive integers s_1, s_2, ..., s_k (s_1+s_2+...+s_k=n) in the second line. The total duration of videos in each post should be the same. It can be easily proven that the answer is unique (if it exists).
If there is no solution, print a single line "No".
Examples
Input
6 3
3 3 1 4 1 6
Output
Yes
2 3 1
Input
3 3
1 1 1
Output
Yes
1 1 1
Input
3 3
1 1 2
Output
No
Input
3 1
1 10 100
Output
Yes
3
Tags: implementation
Correct Solution:
```
n,k=[int(x) for x in input().split()]
arr=[int(x) for x in input().split()]
s=sum(arr)
if s%k!=0:
print('No')
else:
d=s//k
ans=[]
curr=0
t=0
flag=True
for i in arr:
curr+=i
t+=1
if curr==d:
ans.append(t)
t=0
curr=0
elif curr>d:
flag=False
break
if flag:
print('Yes')
for i in ans:
print(i,end=' ')
else:
print('No')
```
| 43,830 | [
0.53564453125,
0.62890625,
0.0860595703125,
0.258544921875,
-0.131103515625,
-0.239501953125,
-0.7158203125,
0.05999755859375,
0.476318359375,
0.84619140625,
0.6171875,
-0.273681640625,
0.28076171875,
-0.89990234375,
-0.32666015625,
0.111328125,
-0.46044921875,
-0.84423828125,
-0... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp took n videos, the duration of the i-th video is a_i seconds. The videos are listed in the chronological order, i.e. the 1-st video is the earliest, the 2-nd video is the next, ..., the n-th video is the last.
Now Polycarp wants to publish exactly k (1 β€ k β€ n) posts in Instabram. Each video should be a part of a single post. The posts should preserve the chronological order, it means that the first post should contain one or more of the earliest videos, the second post should contain a block (one or more videos) going next and so on. In other words, if the number of videos in the j-th post is s_j then:
* s_1+s_2+...+s_k=n (s_i>0),
* the first post contains the videos: 1, 2, ..., s_1;
* the second post contains the videos: s_1+1, s_1+2, ..., s_1+s_2;
* the third post contains the videos: s_1+s_2+1, s_1+s_2+2, ..., s_1+s_2+s_3;
* ...
* the k-th post contains videos: n-s_k+1,n-s_k+2,...,n.
Polycarp is a perfectionist, he wants the total duration of videos in each post to be the same.
Help Polycarp to find such positive integer values s_1, s_2, ..., s_k that satisfy all the conditions above.
Input
The first line contains two integers n and k (1 β€ k β€ n β€ 10^5). The next line contains n positive integer numbers a_1, a_2, ..., a_n (1 β€ a_i β€ 10^4), where a_i is the duration of the i-th video.
Output
If solution exists, print "Yes" in the first line. Print k positive integers s_1, s_2, ..., s_k (s_1+s_2+...+s_k=n) in the second line. The total duration of videos in each post should be the same. It can be easily proven that the answer is unique (if it exists).
If there is no solution, print a single line "No".
Examples
Input
6 3
3 3 1 4 1 6
Output
Yes
2 3 1
Input
3 3
1 1 1
Output
Yes
1 1 1
Input
3 3
1 1 2
Output
No
Input
3 1
1 10 100
Output
Yes
3
Tags: implementation
Correct Solution:
```
n, k = map(int, input().split())
vids = [int(bruh) for bruh in input().split()]
len = 0
cnt = 0
res = []
summy = sum(vids)/k
for x in range(n):
len += vids[x]
cnt += 1
if len == summy:
res.append(cnt)
cnt = 0
len = 0
elif len > summy:
print("No")
exit()
print("Yes")
res1 = [str(bruhh) for bruhh in res]
print(' '.join(res1))
```
| 43,831 | [
0.53564453125,
0.62890625,
0.0860595703125,
0.258544921875,
-0.131103515625,
-0.239501953125,
-0.7158203125,
0.05999755859375,
0.476318359375,
0.84619140625,
0.6171875,
-0.273681640625,
0.28076171875,
-0.89990234375,
-0.32666015625,
0.111328125,
-0.46044921875,
-0.84423828125,
-0... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp took n videos, the duration of the i-th video is a_i seconds. The videos are listed in the chronological order, i.e. the 1-st video is the earliest, the 2-nd video is the next, ..., the n-th video is the last.
Now Polycarp wants to publish exactly k (1 β€ k β€ n) posts in Instabram. Each video should be a part of a single post. The posts should preserve the chronological order, it means that the first post should contain one or more of the earliest videos, the second post should contain a block (one or more videos) going next and so on. In other words, if the number of videos in the j-th post is s_j then:
* s_1+s_2+...+s_k=n (s_i>0),
* the first post contains the videos: 1, 2, ..., s_1;
* the second post contains the videos: s_1+1, s_1+2, ..., s_1+s_2;
* the third post contains the videos: s_1+s_2+1, s_1+s_2+2, ..., s_1+s_2+s_3;
* ...
* the k-th post contains videos: n-s_k+1,n-s_k+2,...,n.
Polycarp is a perfectionist, he wants the total duration of videos in each post to be the same.
Help Polycarp to find such positive integer values s_1, s_2, ..., s_k that satisfy all the conditions above.
Input
The first line contains two integers n and k (1 β€ k β€ n β€ 10^5). The next line contains n positive integer numbers a_1, a_2, ..., a_n (1 β€ a_i β€ 10^4), where a_i is the duration of the i-th video.
Output
If solution exists, print "Yes" in the first line. Print k positive integers s_1, s_2, ..., s_k (s_1+s_2+...+s_k=n) in the second line. The total duration of videos in each post should be the same. It can be easily proven that the answer is unique (if it exists).
If there is no solution, print a single line "No".
Examples
Input
6 3
3 3 1 4 1 6
Output
Yes
2 3 1
Input
3 3
1 1 1
Output
Yes
1 1 1
Input
3 3
1 1 2
Output
No
Input
3 1
1 10 100
Output
Yes
3
Tags: implementation
Correct Solution:
```
n, k = map(int, input().split())
s = list(map(int, input().split()))
t = sum(s)/k
if sum(s) % k != 0:
print("No")
else:
answ = []
summ = 0
kk = 0
m = True
for el in s:
summ += el
kk += 1
if summ == t:
answ.append(str(kk))
summ = 0
kk = 0
elif summ > t:
m = False
break
if m:
print("Yes")
print(" ".join(answ))
else:
print("No")
```
| 43,832 | [
0.53564453125,
0.62890625,
0.0860595703125,
0.258544921875,
-0.131103515625,
-0.239501953125,
-0.7158203125,
0.05999755859375,
0.476318359375,
0.84619140625,
0.6171875,
-0.273681640625,
0.28076171875,
-0.89990234375,
-0.32666015625,
0.111328125,
-0.46044921875,
-0.84423828125,
-0... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp took n videos, the duration of the i-th video is a_i seconds. The videos are listed in the chronological order, i.e. the 1-st video is the earliest, the 2-nd video is the next, ..., the n-th video is the last.
Now Polycarp wants to publish exactly k (1 β€ k β€ n) posts in Instabram. Each video should be a part of a single post. The posts should preserve the chronological order, it means that the first post should contain one or more of the earliest videos, the second post should contain a block (one or more videos) going next and so on. In other words, if the number of videos in the j-th post is s_j then:
* s_1+s_2+...+s_k=n (s_i>0),
* the first post contains the videos: 1, 2, ..., s_1;
* the second post contains the videos: s_1+1, s_1+2, ..., s_1+s_2;
* the third post contains the videos: s_1+s_2+1, s_1+s_2+2, ..., s_1+s_2+s_3;
* ...
* the k-th post contains videos: n-s_k+1,n-s_k+2,...,n.
Polycarp is a perfectionist, he wants the total duration of videos in each post to be the same.
Help Polycarp to find such positive integer values s_1, s_2, ..., s_k that satisfy all the conditions above.
Input
The first line contains two integers n and k (1 β€ k β€ n β€ 10^5). The next line contains n positive integer numbers a_1, a_2, ..., a_n (1 β€ a_i β€ 10^4), where a_i is the duration of the i-th video.
Output
If solution exists, print "Yes" in the first line. Print k positive integers s_1, s_2, ..., s_k (s_1+s_2+...+s_k=n) in the second line. The total duration of videos in each post should be the same. It can be easily proven that the answer is unique (if it exists).
If there is no solution, print a single line "No".
Examples
Input
6 3
3 3 1 4 1 6
Output
Yes
2 3 1
Input
3 3
1 1 1
Output
Yes
1 1 1
Input
3 3
1 1 2
Output
No
Input
3 1
1 10 100
Output
Yes
3
Tags: implementation
Correct Solution:
```
def read():
return list(map(int, input().split()))
def solve(n, k, A):
if sum(A) % k != 0 :
print('No')
return
target = sum(A) // k
ans, elems, sm = [], 0, 0
for num in A:
sm += num
elems += 1
if sm > target:
print('No')
return
if sm == target:
ans.append(elems)
elems, sm = 0, 0
print('Yes')
print(' '.join(map(str, ans)))
n, k = read()
A = read()
solve(n, k, A)
```
| 43,833 | [
0.53564453125,
0.62890625,
0.0860595703125,
0.258544921875,
-0.131103515625,
-0.239501953125,
-0.7158203125,
0.05999755859375,
0.476318359375,
0.84619140625,
0.6171875,
-0.273681640625,
0.28076171875,
-0.89990234375,
-0.32666015625,
0.111328125,
-0.46044921875,
-0.84423828125,
-0... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp took n videos, the duration of the i-th video is a_i seconds. The videos are listed in the chronological order, i.e. the 1-st video is the earliest, the 2-nd video is the next, ..., the n-th video is the last.
Now Polycarp wants to publish exactly k (1 β€ k β€ n) posts in Instabram. Each video should be a part of a single post. The posts should preserve the chronological order, it means that the first post should contain one or more of the earliest videos, the second post should contain a block (one or more videos) going next and so on. In other words, if the number of videos in the j-th post is s_j then:
* s_1+s_2+...+s_k=n (s_i>0),
* the first post contains the videos: 1, 2, ..., s_1;
* the second post contains the videos: s_1+1, s_1+2, ..., s_1+s_2;
* the third post contains the videos: s_1+s_2+1, s_1+s_2+2, ..., s_1+s_2+s_3;
* ...
* the k-th post contains videos: n-s_k+1,n-s_k+2,...,n.
Polycarp is a perfectionist, he wants the total duration of videos in each post to be the same.
Help Polycarp to find such positive integer values s_1, s_2, ..., s_k that satisfy all the conditions above.
Input
The first line contains two integers n and k (1 β€ k β€ n β€ 10^5). The next line contains n positive integer numbers a_1, a_2, ..., a_n (1 β€ a_i β€ 10^4), where a_i is the duration of the i-th video.
Output
If solution exists, print "Yes" in the first line. Print k positive integers s_1, s_2, ..., s_k (s_1+s_2+...+s_k=n) in the second line. The total duration of videos in each post should be the same. It can be easily proven that the answer is unique (if it exists).
If there is no solution, print a single line "No".
Examples
Input
6 3
3 3 1 4 1 6
Output
Yes
2 3 1
Input
3 3
1 1 1
Output
Yes
1 1 1
Input
3 3
1 1 2
Output
No
Input
3 1
1 10 100
Output
Yes
3
Tags: implementation
Correct Solution:
```
n, k = map(int, input().split())
a = list(map(int, input().split()))
s = sum(a)
t = 0
p = 0
i = 0
res = []
poss = True
if s % k != 0:
print("No")
else:
while i != n:
if t + a[i] <= s // k:
t += a[i]
p += 1
else:
poss = False
break
if t == s // k:
res.append(p)
t = 0
p = 0
i += 1
if t != 0:
poss = False
if poss:
print("Yes")
print(' '.join(map(str, res)))
else:
print("No")
```
| 43,834 | [
0.53564453125,
0.62890625,
0.0860595703125,
0.258544921875,
-0.131103515625,
-0.239501953125,
-0.7158203125,
0.05999755859375,
0.476318359375,
0.84619140625,
0.6171875,
-0.273681640625,
0.28076171875,
-0.89990234375,
-0.32666015625,
0.111328125,
-0.46044921875,
-0.84423828125,
-0... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp took n videos, the duration of the i-th video is a_i seconds. The videos are listed in the chronological order, i.e. the 1-st video is the earliest, the 2-nd video is the next, ..., the n-th video is the last.
Now Polycarp wants to publish exactly k (1 β€ k β€ n) posts in Instabram. Each video should be a part of a single post. The posts should preserve the chronological order, it means that the first post should contain one or more of the earliest videos, the second post should contain a block (one or more videos) going next and so on. In other words, if the number of videos in the j-th post is s_j then:
* s_1+s_2+...+s_k=n (s_i>0),
* the first post contains the videos: 1, 2, ..., s_1;
* the second post contains the videos: s_1+1, s_1+2, ..., s_1+s_2;
* the third post contains the videos: s_1+s_2+1, s_1+s_2+2, ..., s_1+s_2+s_3;
* ...
* the k-th post contains videos: n-s_k+1,n-s_k+2,...,n.
Polycarp is a perfectionist, he wants the total duration of videos in each post to be the same.
Help Polycarp to find such positive integer values s_1, s_2, ..., s_k that satisfy all the conditions above.
Input
The first line contains two integers n and k (1 β€ k β€ n β€ 10^5). The next line contains n positive integer numbers a_1, a_2, ..., a_n (1 β€ a_i β€ 10^4), where a_i is the duration of the i-th video.
Output
If solution exists, print "Yes" in the first line. Print k positive integers s_1, s_2, ..., s_k (s_1+s_2+...+s_k=n) in the second line. The total duration of videos in each post should be the same. It can be easily proven that the answer is unique (if it exists).
If there is no solution, print a single line "No".
Examples
Input
6 3
3 3 1 4 1 6
Output
Yes
2 3 1
Input
3 3
1 1 1
Output
Yes
1 1 1
Input
3 3
1 1 2
Output
No
Input
3 1
1 10 100
Output
Yes
3
Tags: implementation
Correct Solution:
```
n,k=map(int,input().split())
arr=list(map(int,input().split()))
ansarr=[]
m=0
su=0
ans=0
s=sum(arr)
le=s//k;
if(s%k!=0):
print('No')
exit(0)
else:
for i in range(n):
su+=arr[m]
m+=1
ans+=1
if(su==le):
ansarr.append(ans)
ans=0
su=0
elif(su>le):
print('No')
exit(0)
print('Yes')
print(*ansarr)
```
| 43,835 | [
0.53564453125,
0.62890625,
0.0860595703125,
0.258544921875,
-0.131103515625,
-0.239501953125,
-0.7158203125,
0.05999755859375,
0.476318359375,
0.84619140625,
0.6171875,
-0.273681640625,
0.28076171875,
-0.89990234375,
-0.32666015625,
0.111328125,
-0.46044921875,
-0.84423828125,
-0... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp took n videos, the duration of the i-th video is a_i seconds. The videos are listed in the chronological order, i.e. the 1-st video is the earliest, the 2-nd video is the next, ..., the n-th video is the last.
Now Polycarp wants to publish exactly k (1 β€ k β€ n) posts in Instabram. Each video should be a part of a single post. The posts should preserve the chronological order, it means that the first post should contain one or more of the earliest videos, the second post should contain a block (one or more videos) going next and so on. In other words, if the number of videos in the j-th post is s_j then:
* s_1+s_2+...+s_k=n (s_i>0),
* the first post contains the videos: 1, 2, ..., s_1;
* the second post contains the videos: s_1+1, s_1+2, ..., s_1+s_2;
* the third post contains the videos: s_1+s_2+1, s_1+s_2+2, ..., s_1+s_2+s_3;
* ...
* the k-th post contains videos: n-s_k+1,n-s_k+2,...,n.
Polycarp is a perfectionist, he wants the total duration of videos in each post to be the same.
Help Polycarp to find such positive integer values s_1, s_2, ..., s_k that satisfy all the conditions above.
Input
The first line contains two integers n and k (1 β€ k β€ n β€ 10^5). The next line contains n positive integer numbers a_1, a_2, ..., a_n (1 β€ a_i β€ 10^4), where a_i is the duration of the i-th video.
Output
If solution exists, print "Yes" in the first line. Print k positive integers s_1, s_2, ..., s_k (s_1+s_2+...+s_k=n) in the second line. The total duration of videos in each post should be the same. It can be easily proven that the answer is unique (if it exists).
If there is no solution, print a single line "No".
Examples
Input
6 3
3 3 1 4 1 6
Output
Yes
2 3 1
Input
3 3
1 1 1
Output
Yes
1 1 1
Input
3 3
1 1 2
Output
No
Input
3 1
1 10 100
Output
Yes
3
Tags: implementation
Correct Solution:
```
n, k = map(int, input().split())
s = [int(x) for x in input().split()]
su = sum(s)
flag = 1
if(su%k != 0):
print('No')
else:
v = su // k
s1 = []
a = 0
cou = 0
for i in range(n):
cou += 1
a += s[i]
if(a > v):
print('No')
flag = 0
break
elif(a < v):
continue
elif(a == v):
a = 0
s1.append(cou)
cou = 0
if(a != 0):
s1.append((su) // v)
if(flag):
print("Yes")
print(*s1)
```
| 43,836 | [
0.53564453125,
0.62890625,
0.0860595703125,
0.258544921875,
-0.131103515625,
-0.239501953125,
-0.7158203125,
0.05999755859375,
0.476318359375,
0.84619140625,
0.6171875,
-0.273681640625,
0.28076171875,
-0.89990234375,
-0.32666015625,
0.111328125,
-0.46044921875,
-0.84423828125,
-0... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp took n videos, the duration of the i-th video is a_i seconds. The videos are listed in the chronological order, i.e. the 1-st video is the earliest, the 2-nd video is the next, ..., the n-th video is the last.
Now Polycarp wants to publish exactly k (1 β€ k β€ n) posts in Instabram. Each video should be a part of a single post. The posts should preserve the chronological order, it means that the first post should contain one or more of the earliest videos, the second post should contain a block (one or more videos) going next and so on. In other words, if the number of videos in the j-th post is s_j then:
* s_1+s_2+...+s_k=n (s_i>0),
* the first post contains the videos: 1, 2, ..., s_1;
* the second post contains the videos: s_1+1, s_1+2, ..., s_1+s_2;
* the third post contains the videos: s_1+s_2+1, s_1+s_2+2, ..., s_1+s_2+s_3;
* ...
* the k-th post contains videos: n-s_k+1,n-s_k+2,...,n.
Polycarp is a perfectionist, he wants the total duration of videos in each post to be the same.
Help Polycarp to find such positive integer values s_1, s_2, ..., s_k that satisfy all the conditions above.
Input
The first line contains two integers n and k (1 β€ k β€ n β€ 10^5). The next line contains n positive integer numbers a_1, a_2, ..., a_n (1 β€ a_i β€ 10^4), where a_i is the duration of the i-th video.
Output
If solution exists, print "Yes" in the first line. Print k positive integers s_1, s_2, ..., s_k (s_1+s_2+...+s_k=n) in the second line. The total duration of videos in each post should be the same. It can be easily proven that the answer is unique (if it exists).
If there is no solution, print a single line "No".
Examples
Input
6 3
3 3 1 4 1 6
Output
Yes
2 3 1
Input
3 3
1 1 1
Output
Yes
1 1 1
Input
3 3
1 1 2
Output
No
Input
3 1
1 10 100
Output
Yes
3
Submitted Solution:
```
import sys
n, k = tuple(int(i) for i in sys.stdin.readline().split())
a = tuple(int(i) for i in sys.stdin.readline().split())
assert len(a) == n
def solve(n, k, a):
q, r = divmod(sum(a), k)
if r > 0: return
s = []
i = 0
while i < n:
total = 0
count = 0
while i < n:
total += a[i]
count += 1
i += 1
if total == q: break
if total > q: return
s.append(count)
return s
r = solve(n, k, a)
if r is None:
print("No")
else:
print("Yes")
print(" ".join(str(i) for i in r))
```
Yes
| 43,837 | [
0.583984375,
0.61083984375,
0.08050537109375,
0.27294921875,
-0.27099609375,
-0.2159423828125,
-0.73486328125,
0.1766357421875,
0.330810546875,
0.87158203125,
0.603515625,
-0.1820068359375,
0.264892578125,
-0.8349609375,
-0.32275390625,
0.048980712890625,
-0.4306640625,
-0.89550781... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp took n videos, the duration of the i-th video is a_i seconds. The videos are listed in the chronological order, i.e. the 1-st video is the earliest, the 2-nd video is the next, ..., the n-th video is the last.
Now Polycarp wants to publish exactly k (1 β€ k β€ n) posts in Instabram. Each video should be a part of a single post. The posts should preserve the chronological order, it means that the first post should contain one or more of the earliest videos, the second post should contain a block (one or more videos) going next and so on. In other words, if the number of videos in the j-th post is s_j then:
* s_1+s_2+...+s_k=n (s_i>0),
* the first post contains the videos: 1, 2, ..., s_1;
* the second post contains the videos: s_1+1, s_1+2, ..., s_1+s_2;
* the third post contains the videos: s_1+s_2+1, s_1+s_2+2, ..., s_1+s_2+s_3;
* ...
* the k-th post contains videos: n-s_k+1,n-s_k+2,...,n.
Polycarp is a perfectionist, he wants the total duration of videos in each post to be the same.
Help Polycarp to find such positive integer values s_1, s_2, ..., s_k that satisfy all the conditions above.
Input
The first line contains two integers n and k (1 β€ k β€ n β€ 10^5). The next line contains n positive integer numbers a_1, a_2, ..., a_n (1 β€ a_i β€ 10^4), where a_i is the duration of the i-th video.
Output
If solution exists, print "Yes" in the first line. Print k positive integers s_1, s_2, ..., s_k (s_1+s_2+...+s_k=n) in the second line. The total duration of videos in each post should be the same. It can be easily proven that the answer is unique (if it exists).
If there is no solution, print a single line "No".
Examples
Input
6 3
3 3 1 4 1 6
Output
Yes
2 3 1
Input
3 3
1 1 1
Output
Yes
1 1 1
Input
3 3
1 1 2
Output
No
Input
3 1
1 10 100
Output
Yes
3
Submitted Solution:
```
n,k=[int(s) for s in input().split()]
s=[0 for i in range(k)]
a=[int(s) for s in input().split()]
b=[0 for i in range(n)]
b[0]=a[0]
def check():
for i in range(1,n):
b[i]=b[i-1]+a[i]
cnt=0
if(b[n-1]%k!=0):
print('No')
return
m=b[n-1]/k
for j in range(0,n):
if b[j]%m==0:
s[cnt]=j
cnt+=1
#print(s)
if(cnt>=k):
print('Yes')
for i in range(k):
if i==0:
print(s[i]+1,end=" ")
else:
print(s[i]-s[i-1],end=" ")
return
else:
print('No')
return
check()
```
Yes
| 43,838 | [
0.583984375,
0.61083984375,
0.08050537109375,
0.27294921875,
-0.27099609375,
-0.2159423828125,
-0.73486328125,
0.1766357421875,
0.330810546875,
0.87158203125,
0.603515625,
-0.1820068359375,
0.264892578125,
-0.8349609375,
-0.32275390625,
0.048980712890625,
-0.4306640625,
-0.89550781... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp took n videos, the duration of the i-th video is a_i seconds. The videos are listed in the chronological order, i.e. the 1-st video is the earliest, the 2-nd video is the next, ..., the n-th video is the last.
Now Polycarp wants to publish exactly k (1 β€ k β€ n) posts in Instabram. Each video should be a part of a single post. The posts should preserve the chronological order, it means that the first post should contain one or more of the earliest videos, the second post should contain a block (one or more videos) going next and so on. In other words, if the number of videos in the j-th post is s_j then:
* s_1+s_2+...+s_k=n (s_i>0),
* the first post contains the videos: 1, 2, ..., s_1;
* the second post contains the videos: s_1+1, s_1+2, ..., s_1+s_2;
* the third post contains the videos: s_1+s_2+1, s_1+s_2+2, ..., s_1+s_2+s_3;
* ...
* the k-th post contains videos: n-s_k+1,n-s_k+2,...,n.
Polycarp is a perfectionist, he wants the total duration of videos in each post to be the same.
Help Polycarp to find such positive integer values s_1, s_2, ..., s_k that satisfy all the conditions above.
Input
The first line contains two integers n and k (1 β€ k β€ n β€ 10^5). The next line contains n positive integer numbers a_1, a_2, ..., a_n (1 β€ a_i β€ 10^4), where a_i is the duration of the i-th video.
Output
If solution exists, print "Yes" in the first line. Print k positive integers s_1, s_2, ..., s_k (s_1+s_2+...+s_k=n) in the second line. The total duration of videos in each post should be the same. It can be easily proven that the answer is unique (if it exists).
If there is no solution, print a single line "No".
Examples
Input
6 3
3 3 1 4 1 6
Output
Yes
2 3 1
Input
3 3
1 1 1
Output
Yes
1 1 1
Input
3 3
1 1 2
Output
No
Input
3 1
1 10 100
Output
Yes
3
Submitted Solution:
```
n, k = map(int, input().split())
l = list(map(int, input().split()))
ans = []
f = 0
tmp = 0
c = 0
average = sum(l)//k
for i in l:
tmp += i
c += 1
if(tmp == average):
ans.append(c);tmp = c = 0
elif(tmp > average):
f = 1; break
if f == 1 or len(ans)!=k or average != sum(l)/k:
print("No")
else:
print("Yes")
for i in ans:
print(i,end = ' ')
```
Yes
| 43,839 | [
0.583984375,
0.61083984375,
0.08050537109375,
0.27294921875,
-0.27099609375,
-0.2159423828125,
-0.73486328125,
0.1766357421875,
0.330810546875,
0.87158203125,
0.603515625,
-0.1820068359375,
0.264892578125,
-0.8349609375,
-0.32275390625,
0.048980712890625,
-0.4306640625,
-0.89550781... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp took n videos, the duration of the i-th video is a_i seconds. The videos are listed in the chronological order, i.e. the 1-st video is the earliest, the 2-nd video is the next, ..., the n-th video is the last.
Now Polycarp wants to publish exactly k (1 β€ k β€ n) posts in Instabram. Each video should be a part of a single post. The posts should preserve the chronological order, it means that the first post should contain one or more of the earliest videos, the second post should contain a block (one or more videos) going next and so on. In other words, if the number of videos in the j-th post is s_j then:
* s_1+s_2+...+s_k=n (s_i>0),
* the first post contains the videos: 1, 2, ..., s_1;
* the second post contains the videos: s_1+1, s_1+2, ..., s_1+s_2;
* the third post contains the videos: s_1+s_2+1, s_1+s_2+2, ..., s_1+s_2+s_3;
* ...
* the k-th post contains videos: n-s_k+1,n-s_k+2,...,n.
Polycarp is a perfectionist, he wants the total duration of videos in each post to be the same.
Help Polycarp to find such positive integer values s_1, s_2, ..., s_k that satisfy all the conditions above.
Input
The first line contains two integers n and k (1 β€ k β€ n β€ 10^5). The next line contains n positive integer numbers a_1, a_2, ..., a_n (1 β€ a_i β€ 10^4), where a_i is the duration of the i-th video.
Output
If solution exists, print "Yes" in the first line. Print k positive integers s_1, s_2, ..., s_k (s_1+s_2+...+s_k=n) in the second line. The total duration of videos in each post should be the same. It can be easily proven that the answer is unique (if it exists).
If there is no solution, print a single line "No".
Examples
Input
6 3
3 3 1 4 1 6
Output
Yes
2 3 1
Input
3 3
1 1 1
Output
Yes
1 1 1
Input
3 3
1 1 2
Output
No
Input
3 1
1 10 100
Output
Yes
3
Submitted Solution:
```
import re
import sys
exit=sys.exit
from bisect import bisect_left as bsl,bisect_right as bsr
from collections import Counter,defaultdict as ddict,deque
from functools import lru_cache
cache=lru_cache(None)
from heapq import *
from itertools import *
from math import inf
from pprint import pprint as pp
enum=enumerate
ri=lambda:int(rln())
ris=lambda:list(map(int,rfs()))
rln=sys.stdin.readline
rl=lambda:rln().rstrip('\n')
rfs=lambda:rln().split()
mod=1000000007
d4=[(0,-1),(1,0),(0,1),(-1,0)]
d8=[(-1,-1),(0,-1),(1,-1),(-1,0),(1,0),(-1,1),(0,1),(1,1)]
########################################################################
n,k=ris()
a=ris()
s=sum(a)
if s%k:
print('No')
exit()
m=s//k
ans=[]
cnt=cur=0
for x in a:
cur+=x
if cur>m:
print('No')
exit()
cnt+=1
if cur==m:
ans.append(cnt)
cnt=cur=0
print('Yes')
print(*ans)
```
Yes
| 43,840 | [
0.583984375,
0.61083984375,
0.08050537109375,
0.27294921875,
-0.27099609375,
-0.2159423828125,
-0.73486328125,
0.1766357421875,
0.330810546875,
0.87158203125,
0.603515625,
-0.1820068359375,
0.264892578125,
-0.8349609375,
-0.32275390625,
0.048980712890625,
-0.4306640625,
-0.89550781... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp took n videos, the duration of the i-th video is a_i seconds. The videos are listed in the chronological order, i.e. the 1-st video is the earliest, the 2-nd video is the next, ..., the n-th video is the last.
Now Polycarp wants to publish exactly k (1 β€ k β€ n) posts in Instabram. Each video should be a part of a single post. The posts should preserve the chronological order, it means that the first post should contain one or more of the earliest videos, the second post should contain a block (one or more videos) going next and so on. In other words, if the number of videos in the j-th post is s_j then:
* s_1+s_2+...+s_k=n (s_i>0),
* the first post contains the videos: 1, 2, ..., s_1;
* the second post contains the videos: s_1+1, s_1+2, ..., s_1+s_2;
* the third post contains the videos: s_1+s_2+1, s_1+s_2+2, ..., s_1+s_2+s_3;
* ...
* the k-th post contains videos: n-s_k+1,n-s_k+2,...,n.
Polycarp is a perfectionist, he wants the total duration of videos in each post to be the same.
Help Polycarp to find such positive integer values s_1, s_2, ..., s_k that satisfy all the conditions above.
Input
The first line contains two integers n and k (1 β€ k β€ n β€ 10^5). The next line contains n positive integer numbers a_1, a_2, ..., a_n (1 β€ a_i β€ 10^4), where a_i is the duration of the i-th video.
Output
If solution exists, print "Yes" in the first line. Print k positive integers s_1, s_2, ..., s_k (s_1+s_2+...+s_k=n) in the second line. The total duration of videos in each post should be the same. It can be easily proven that the answer is unique (if it exists).
If there is no solution, print a single line "No".
Examples
Input
6 3
3 3 1 4 1 6
Output
Yes
2 3 1
Input
3 3
1 1 1
Output
Yes
1 1 1
Input
3 3
1 1 2
Output
No
Input
3 1
1 10 100
Output
Yes
3
Submitted Solution:
```
temp = input().split(' ')
n = int(temp[0])
k = int(temp[1])
temp = input().split(' ')
mas = []
sum = 0
for i in range(n):
mas.append(int(temp[i]))
for i in range(n):
sum += mas[i]
d = 0
if sum%k:
print('NO')
exit(0)
else:
d = sum/k
rez = []
rez.append(0)
temp = 0
for i in range(n):
temp += mas[i]
if (temp == d):
temp = 0
rez.append(i+1)
if (temp > d):
print('NO')
exit(0)
print("YES")
for i in range(1, len(rez)):
print(rez[i] - rez[i-1], end = ' ')
```
No
| 43,841 | [
0.583984375,
0.61083984375,
0.08050537109375,
0.27294921875,
-0.27099609375,
-0.2159423828125,
-0.73486328125,
0.1766357421875,
0.330810546875,
0.87158203125,
0.603515625,
-0.1820068359375,
0.264892578125,
-0.8349609375,
-0.32275390625,
0.048980712890625,
-0.4306640625,
-0.89550781... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp took n videos, the duration of the i-th video is a_i seconds. The videos are listed in the chronological order, i.e. the 1-st video is the earliest, the 2-nd video is the next, ..., the n-th video is the last.
Now Polycarp wants to publish exactly k (1 β€ k β€ n) posts in Instabram. Each video should be a part of a single post. The posts should preserve the chronological order, it means that the first post should contain one or more of the earliest videos, the second post should contain a block (one or more videos) going next and so on. In other words, if the number of videos in the j-th post is s_j then:
* s_1+s_2+...+s_k=n (s_i>0),
* the first post contains the videos: 1, 2, ..., s_1;
* the second post contains the videos: s_1+1, s_1+2, ..., s_1+s_2;
* the third post contains the videos: s_1+s_2+1, s_1+s_2+2, ..., s_1+s_2+s_3;
* ...
* the k-th post contains videos: n-s_k+1,n-s_k+2,...,n.
Polycarp is a perfectionist, he wants the total duration of videos in each post to be the same.
Help Polycarp to find such positive integer values s_1, s_2, ..., s_k that satisfy all the conditions above.
Input
The first line contains two integers n and k (1 β€ k β€ n β€ 10^5). The next line contains n positive integer numbers a_1, a_2, ..., a_n (1 β€ a_i β€ 10^4), where a_i is the duration of the i-th video.
Output
If solution exists, print "Yes" in the first line. Print k positive integers s_1, s_2, ..., s_k (s_1+s_2+...+s_k=n) in the second line. The total duration of videos in each post should be the same. It can be easily proven that the answer is unique (if it exists).
If there is no solution, print a single line "No".
Examples
Input
6 3
3 3 1 4 1 6
Output
Yes
2 3 1
Input
3 3
1 1 1
Output
Yes
1 1 1
Input
3 3
1 1 2
Output
No
Input
3 1
1 10 100
Output
Yes
3
Submitted Solution:
```
n, k = map(int,input().split())
a = list(map(int,input().split()))
tmp = sum(a)/k
if tmp != int(tmp):
print("NO")
exit()
ans = 0
cnt = 0
res = []
for i in a:
ans+=i
cnt+=1
if ans > tmp:
print('NO')
exit()
if ans == tmp:
res.append(cnt)
cnt = 0
ans = 0
print('YES')
print(*res)
```
No
| 43,842 | [
0.583984375,
0.61083984375,
0.08050537109375,
0.27294921875,
-0.27099609375,
-0.2159423828125,
-0.73486328125,
0.1766357421875,
0.330810546875,
0.87158203125,
0.603515625,
-0.1820068359375,
0.264892578125,
-0.8349609375,
-0.32275390625,
0.048980712890625,
-0.4306640625,
-0.89550781... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp took n videos, the duration of the i-th video is a_i seconds. The videos are listed in the chronological order, i.e. the 1-st video is the earliest, the 2-nd video is the next, ..., the n-th video is the last.
Now Polycarp wants to publish exactly k (1 β€ k β€ n) posts in Instabram. Each video should be a part of a single post. The posts should preserve the chronological order, it means that the first post should contain one or more of the earliest videos, the second post should contain a block (one or more videos) going next and so on. In other words, if the number of videos in the j-th post is s_j then:
* s_1+s_2+...+s_k=n (s_i>0),
* the first post contains the videos: 1, 2, ..., s_1;
* the second post contains the videos: s_1+1, s_1+2, ..., s_1+s_2;
* the third post contains the videos: s_1+s_2+1, s_1+s_2+2, ..., s_1+s_2+s_3;
* ...
* the k-th post contains videos: n-s_k+1,n-s_k+2,...,n.
Polycarp is a perfectionist, he wants the total duration of videos in each post to be the same.
Help Polycarp to find such positive integer values s_1, s_2, ..., s_k that satisfy all the conditions above.
Input
The first line contains two integers n and k (1 β€ k β€ n β€ 10^5). The next line contains n positive integer numbers a_1, a_2, ..., a_n (1 β€ a_i β€ 10^4), where a_i is the duration of the i-th video.
Output
If solution exists, print "Yes" in the first line. Print k positive integers s_1, s_2, ..., s_k (s_1+s_2+...+s_k=n) in the second line. The total duration of videos in each post should be the same. It can be easily proven that the answer is unique (if it exists).
If there is no solution, print a single line "No".
Examples
Input
6 3
3 3 1 4 1 6
Output
Yes
2 3 1
Input
3 3
1 1 1
Output
Yes
1 1 1
Input
3 3
1 1 2
Output
No
Input
3 1
1 10 100
Output
Yes
3
Submitted Solution:
```
def main():
n, k = (int(x) for x in input().split())
l = [int(x) for x in input().split()]
s = sum(l)
if s % k:
print('No')
return 0
q = s / k
m = [0 for i in range(k)]
c_m = 0
c_s = 0
for i in range(n):
if c_s < q:
m[c_m] += 1
c_s += l[i]
elif c_s == q:
c_m += 1
c_s = l[i]
m[c_m] += 1
else:
print('No')
return 0
print('Yes')
print(*m)
main()
```
No
| 43,843 | [
0.583984375,
0.61083984375,
0.08050537109375,
0.27294921875,
-0.27099609375,
-0.2159423828125,
-0.73486328125,
0.1766357421875,
0.330810546875,
0.87158203125,
0.603515625,
-0.1820068359375,
0.264892578125,
-0.8349609375,
-0.32275390625,
0.048980712890625,
-0.4306640625,
-0.89550781... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp took n videos, the duration of the i-th video is a_i seconds. The videos are listed in the chronological order, i.e. the 1-st video is the earliest, the 2-nd video is the next, ..., the n-th video is the last.
Now Polycarp wants to publish exactly k (1 β€ k β€ n) posts in Instabram. Each video should be a part of a single post. The posts should preserve the chronological order, it means that the first post should contain one or more of the earliest videos, the second post should contain a block (one or more videos) going next and so on. In other words, if the number of videos in the j-th post is s_j then:
* s_1+s_2+...+s_k=n (s_i>0),
* the first post contains the videos: 1, 2, ..., s_1;
* the second post contains the videos: s_1+1, s_1+2, ..., s_1+s_2;
* the third post contains the videos: s_1+s_2+1, s_1+s_2+2, ..., s_1+s_2+s_3;
* ...
* the k-th post contains videos: n-s_k+1,n-s_k+2,...,n.
Polycarp is a perfectionist, he wants the total duration of videos in each post to be the same.
Help Polycarp to find such positive integer values s_1, s_2, ..., s_k that satisfy all the conditions above.
Input
The first line contains two integers n and k (1 β€ k β€ n β€ 10^5). The next line contains n positive integer numbers a_1, a_2, ..., a_n (1 β€ a_i β€ 10^4), where a_i is the duration of the i-th video.
Output
If solution exists, print "Yes" in the first line. Print k positive integers s_1, s_2, ..., s_k (s_1+s_2+...+s_k=n) in the second line. The total duration of videos in each post should be the same. It can be easily proven that the answer is unique (if it exists).
If there is no solution, print a single line "No".
Examples
Input
6 3
3 3 1 4 1 6
Output
Yes
2 3 1
Input
3 3
1 1 1
Output
Yes
1 1 1
Input
3 3
1 1 2
Output
No
Input
3 1
1 10 100
Output
Yes
3
Submitted Solution:
```
n,k=list(map(int, input().split()))
a=list(map(int, input().split()))
if sum(a)%k==0:
s=sum(a)//k
i=0
b=[0]
t=True
while i<n:
while sum(a[b[-1]:i])<s and i<n:
i+=1
if sum(a[b[-1]:i])!=s:
print("NO")
t=False
break
else:
b.append(i)
if t:
print("Yes")
c=[b[x]-b[x-1] for x in range(1,len(b))]
print(' '.join(list(map(str, c))))
else:
print("No")
```
No
| 43,844 | [
0.583984375,
0.61083984375,
0.08050537109375,
0.27294921875,
-0.27099609375,
-0.2159423828125,
-0.73486328125,
0.1766357421875,
0.330810546875,
0.87158203125,
0.603515625,
-0.1820068359375,
0.264892578125,
-0.8349609375,
-0.32275390625,
0.048980712890625,
-0.4306640625,
-0.89550781... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarpus takes part in the "Field of Wonders" TV show. The participants of the show have to guess a hidden word as fast as possible. Initially all the letters of the word are hidden.
The game consists of several turns. At each turn the participant tells a letter and the TV show host responds if there is such letter in the word or not. If there is such letter then the host reveals all such letters. For example, if the hidden word is "abacaba" and the player tells the letter "a", the host will reveal letters at all positions, occupied by "a": 1, 3, 5 and 7 (positions are numbered from left to right starting from 1).
Polycarpus knows m words of exactly the same length as the hidden word. The hidden word is also known to him and appears as one of these m words.
At current moment a number of turns have already been made and some letters (possibly zero) of the hidden word are already revealed. Previously Polycarp has told exactly the letters which are currently revealed.
It is Polycarpus' turn. He wants to tell a letter in such a way, that the TV show host will assuredly reveal at least one more letter. Polycarpus cannot tell the letters, which are already revealed.
Your task is to help Polycarpus and find out the number of letters he can tell so that the show host will assuredly reveal at least one of the remaining letters.
Input
The first line contains one integer n (1 β€ n β€ 50) β the length of the hidden word.
The following line describes already revealed letters. It contains the string of length n, which consists of lowercase Latin letters and symbols "*". If there is a letter at some position, then this letter was already revealed. If the position contains symbol "*", then the letter at this position has not been revealed yet. It is guaranteed, that at least one letter is still closed.
The third line contains an integer m (1 β€ m β€ 1000) β the number of words of length n, which Polycarpus knows. The following m lines contain the words themselves β n-letter strings of lowercase Latin letters. All words are distinct.
It is guaranteed that the hidden word appears as one of the given m words. Before the current move Polycarp has told exactly the letters which are currently revealed.
Output
Output the single integer β the number of letters Polycarpus can tell so that the TV show host definitely reveals at least one more letter. It is possible that this number is zero.
Examples
Input
4
a**d
2
abcd
acbd
Output
2
Input
5
lo*er
2
lover
loser
Output
0
Input
3
a*a
2
aaa
aba
Output
1
Note
In the first example Polycarpus can tell letters "b" and "c", which assuredly will be revealed.
The second example contains no letters which can be told as it is not clear, which of the letters "v" or "s" is located at the third position of the hidden word.
In the third example Polycarpus exactly knows that the hidden word is "aba", because in case it was "aaa", then the second letter "a" would have already been revealed in one of previous turns.
Tags: implementation, strings
Correct Solution:
```
import string
m = int(input())
word = input()
words = set()
stars = set()
let = {a for a in string.ascii_lowercase}
for i in range(0, len(word)):
if word[i] == '*':
stars.add(i)
else:
words.add(word[i])
n = int(input())
tse = set()
for i in range(0, n):
st = input()
for j in stars:
tse.add(st[j])
flag = True
j = 0
while j < m and (st[j] == word[j] or j in stars):
j += 1
if len(tse.intersection(words)) != 0 or j != m:
tse.clear()
continue
let = let.intersection(tse)
tse.clear()
if len(stars) == 0:
print(0)
else:
print(len(let))
```
| 44,365 | [
0.2186279296875,
-0.0055389404296875,
0.310302734375,
0.21240234375,
-0.234130859375,
-0.379150390625,
-0.2325439453125,
0.301513671875,
-0.338623046875,
0.40478515625,
1.35546875,
-0.0028400421142578125,
0.0200042724609375,
-0.64892578125,
-0.7939453125,
-0.162109375,
-0.50927734375... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarpus takes part in the "Field of Wonders" TV show. The participants of the show have to guess a hidden word as fast as possible. Initially all the letters of the word are hidden.
The game consists of several turns. At each turn the participant tells a letter and the TV show host responds if there is such letter in the word or not. If there is such letter then the host reveals all such letters. For example, if the hidden word is "abacaba" and the player tells the letter "a", the host will reveal letters at all positions, occupied by "a": 1, 3, 5 and 7 (positions are numbered from left to right starting from 1).
Polycarpus knows m words of exactly the same length as the hidden word. The hidden word is also known to him and appears as one of these m words.
At current moment a number of turns have already been made and some letters (possibly zero) of the hidden word are already revealed. Previously Polycarp has told exactly the letters which are currently revealed.
It is Polycarpus' turn. He wants to tell a letter in such a way, that the TV show host will assuredly reveal at least one more letter. Polycarpus cannot tell the letters, which are already revealed.
Your task is to help Polycarpus and find out the number of letters he can tell so that the show host will assuredly reveal at least one of the remaining letters.
Input
The first line contains one integer n (1 β€ n β€ 50) β the length of the hidden word.
The following line describes already revealed letters. It contains the string of length n, which consists of lowercase Latin letters and symbols "*". If there is a letter at some position, then this letter was already revealed. If the position contains symbol "*", then the letter at this position has not been revealed yet. It is guaranteed, that at least one letter is still closed.
The third line contains an integer m (1 β€ m β€ 1000) β the number of words of length n, which Polycarpus knows. The following m lines contain the words themselves β n-letter strings of lowercase Latin letters. All words are distinct.
It is guaranteed that the hidden word appears as one of the given m words. Before the current move Polycarp has told exactly the letters which are currently revealed.
Output
Output the single integer β the number of letters Polycarpus can tell so that the TV show host definitely reveals at least one more letter. It is possible that this number is zero.
Examples
Input
4
a**d
2
abcd
acbd
Output
2
Input
5
lo*er
2
lover
loser
Output
0
Input
3
a*a
2
aaa
aba
Output
1
Note
In the first example Polycarpus can tell letters "b" and "c", which assuredly will be revealed.
The second example contains no letters which can be told as it is not clear, which of the letters "v" or "s" is located at the third position of the hidden word.
In the third example Polycarpus exactly knows that the hidden word is "aba", because in case it was "aaa", then the second letter "a" would have already been revealed in one of previous turns.
Tags: implementation, strings
Correct Solution:
```
import math
import re
import string
def ria():
return [int(i) for i in input().split()]
def ri():
return int(input())
def rfa():
return [float(i) for i in input().split()]
eps = 1e-9
def is_equal(a, b):
return abs(a - b) <= eps
def distance(p0, p1):
return math.sqrt((p0[0] - p1[0]) ** 2 + (p0[1] - p1[1]) ** 2)
N = ri()
hid = input()
mpk = {}
totalKek = 0
for n, i in enumerate(string.ascii_lowercase):
mpk[i] = 1 << n
totalKek |= mpk[i]
M = ri()
revealed = 0
for i in hid:
if i != '*':
revealed |= mpk[i]
isAny = False
for i in range(M):
t = input()
isAny=True
bad = False
hidBit = 0
for n, j in enumerate(t):
if hid[n] != '*':
if hid[n] != t[n]:
bad = True
continue
hidBit |= mpk[j]
if hidBit & revealed != 0 or bad:
continue
totalKek &= hidBit
if isAny:
print(str(bin(totalKek)).count('1'))
else:
exit(-1)
```
| 44,366 | [
0.2186279296875,
-0.0055389404296875,
0.310302734375,
0.21240234375,
-0.234130859375,
-0.379150390625,
-0.2325439453125,
0.301513671875,
-0.338623046875,
0.40478515625,
1.35546875,
-0.0028400421142578125,
0.0200042724609375,
-0.64892578125,
-0.7939453125,
-0.162109375,
-0.50927734375... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarpus takes part in the "Field of Wonders" TV show. The participants of the show have to guess a hidden word as fast as possible. Initially all the letters of the word are hidden.
The game consists of several turns. At each turn the participant tells a letter and the TV show host responds if there is such letter in the word or not. If there is such letter then the host reveals all such letters. For example, if the hidden word is "abacaba" and the player tells the letter "a", the host will reveal letters at all positions, occupied by "a": 1, 3, 5 and 7 (positions are numbered from left to right starting from 1).
Polycarpus knows m words of exactly the same length as the hidden word. The hidden word is also known to him and appears as one of these m words.
At current moment a number of turns have already been made and some letters (possibly zero) of the hidden word are already revealed. Previously Polycarp has told exactly the letters which are currently revealed.
It is Polycarpus' turn. He wants to tell a letter in such a way, that the TV show host will assuredly reveal at least one more letter. Polycarpus cannot tell the letters, which are already revealed.
Your task is to help Polycarpus and find out the number of letters he can tell so that the show host will assuredly reveal at least one of the remaining letters.
Input
The first line contains one integer n (1 β€ n β€ 50) β the length of the hidden word.
The following line describes already revealed letters. It contains the string of length n, which consists of lowercase Latin letters and symbols "*". If there is a letter at some position, then this letter was already revealed. If the position contains symbol "*", then the letter at this position has not been revealed yet. It is guaranteed, that at least one letter is still closed.
The third line contains an integer m (1 β€ m β€ 1000) β the number of words of length n, which Polycarpus knows. The following m lines contain the words themselves β n-letter strings of lowercase Latin letters. All words are distinct.
It is guaranteed that the hidden word appears as one of the given m words. Before the current move Polycarp has told exactly the letters which are currently revealed.
Output
Output the single integer β the number of letters Polycarpus can tell so that the TV show host definitely reveals at least one more letter. It is possible that this number is zero.
Examples
Input
4
a**d
2
abcd
acbd
Output
2
Input
5
lo*er
2
lover
loser
Output
0
Input
3
a*a
2
aaa
aba
Output
1
Note
In the first example Polycarpus can tell letters "b" and "c", which assuredly will be revealed.
The second example contains no letters which can be told as it is not clear, which of the letters "v" or "s" is located at the third position of the hidden word.
In the third example Polycarpus exactly knows that the hidden word is "aba", because in case it was "aaa", then the second letter "a" would have already been revealed in one of previous turns.
Tags: implementation, strings
Correct Solution:
```
def is_good_guess(guess, original_string, pos_not_reveal, pos_reveal, reveal):
for i in pos_not_reveal:
if guess[i] in reveal:
return False
for i in pos_reveal:
if guess[i] != original_string[i]:
return False
return True
n = int(input())
l2 = list(input())
reveal = []
pos_reveal = []
pos_not_reveal = []
for i in range(n):
if l2[i] != '*':
pos_reveal.append(i)
reveal.append(l2[i])
else:
pos_not_reveal.append(i)
reveal = set(reveal)
m = int(input())
option = set('abcdefghijklmnopqrstuvwxyz')
for i in range(m):
guess = list(input())
guess_char = set(guess)
if is_good_guess(guess,l2,pos_not_reveal,pos_reveal,reveal):
option = (guess_char - reveal) & option
print(len(option))
```
| 44,367 | [
0.2186279296875,
-0.0055389404296875,
0.310302734375,
0.21240234375,
-0.234130859375,
-0.379150390625,
-0.2325439453125,
0.301513671875,
-0.338623046875,
0.40478515625,
1.35546875,
-0.0028400421142578125,
0.0200042724609375,
-0.64892578125,
-0.7939453125,
-0.162109375,
-0.50927734375... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarpus takes part in the "Field of Wonders" TV show. The participants of the show have to guess a hidden word as fast as possible. Initially all the letters of the word are hidden.
The game consists of several turns. At each turn the participant tells a letter and the TV show host responds if there is such letter in the word or not. If there is such letter then the host reveals all such letters. For example, if the hidden word is "abacaba" and the player tells the letter "a", the host will reveal letters at all positions, occupied by "a": 1, 3, 5 and 7 (positions are numbered from left to right starting from 1).
Polycarpus knows m words of exactly the same length as the hidden word. The hidden word is also known to him and appears as one of these m words.
At current moment a number of turns have already been made and some letters (possibly zero) of the hidden word are already revealed. Previously Polycarp has told exactly the letters which are currently revealed.
It is Polycarpus' turn. He wants to tell a letter in such a way, that the TV show host will assuredly reveal at least one more letter. Polycarpus cannot tell the letters, which are already revealed.
Your task is to help Polycarpus and find out the number of letters he can tell so that the show host will assuredly reveal at least one of the remaining letters.
Input
The first line contains one integer n (1 β€ n β€ 50) β the length of the hidden word.
The following line describes already revealed letters. It contains the string of length n, which consists of lowercase Latin letters and symbols "*". If there is a letter at some position, then this letter was already revealed. If the position contains symbol "*", then the letter at this position has not been revealed yet. It is guaranteed, that at least one letter is still closed.
The third line contains an integer m (1 β€ m β€ 1000) β the number of words of length n, which Polycarpus knows. The following m lines contain the words themselves β n-letter strings of lowercase Latin letters. All words are distinct.
It is guaranteed that the hidden word appears as one of the given m words. Before the current move Polycarp has told exactly the letters which are currently revealed.
Output
Output the single integer β the number of letters Polycarpus can tell so that the TV show host definitely reveals at least one more letter. It is possible that this number is zero.
Examples
Input
4
a**d
2
abcd
acbd
Output
2
Input
5
lo*er
2
lover
loser
Output
0
Input
3
a*a
2
aaa
aba
Output
1
Note
In the first example Polycarpus can tell letters "b" and "c", which assuredly will be revealed.
The second example contains no letters which can be told as it is not clear, which of the letters "v" or "s" is located at the third position of the hidden word.
In the third example Polycarpus exactly knows that the hidden word is "aba", because in case it was "aaa", then the second letter "a" would have already been revealed in one of previous turns.
Tags: implementation, strings
Correct Solution:
```
import re
n = int(input())
a = input()
r = { i: 1 for i in a if i != '*' }
r = ''.join(r)
regex = f'([^{r}_])'
regex = re.sub('\*', regex, a)
regex = re.compile(regex)
m = int(input())
mx = 0
dx = {}
for i in range(m):
s = input()
d = regex.match(s)
if d:
mx += 1
rx = {}
for j in d.groups():
rx[j] = 1
for j in rx:
dx[j] = dx.get(j, 0) + 1
res = 0
for i in dx:
if dx[i] == mx:
res += 1
print(res)
```
| 44,368 | [
0.2186279296875,
-0.0055389404296875,
0.310302734375,
0.21240234375,
-0.234130859375,
-0.379150390625,
-0.2325439453125,
0.301513671875,
-0.338623046875,
0.40478515625,
1.35546875,
-0.0028400421142578125,
0.0200042724609375,
-0.64892578125,
-0.7939453125,
-0.162109375,
-0.50927734375... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarpus takes part in the "Field of Wonders" TV show. The participants of the show have to guess a hidden word as fast as possible. Initially all the letters of the word are hidden.
The game consists of several turns. At each turn the participant tells a letter and the TV show host responds if there is such letter in the word or not. If there is such letter then the host reveals all such letters. For example, if the hidden word is "abacaba" and the player tells the letter "a", the host will reveal letters at all positions, occupied by "a": 1, 3, 5 and 7 (positions are numbered from left to right starting from 1).
Polycarpus knows m words of exactly the same length as the hidden word. The hidden word is also known to him and appears as one of these m words.
At current moment a number of turns have already been made and some letters (possibly zero) of the hidden word are already revealed. Previously Polycarp has told exactly the letters which are currently revealed.
It is Polycarpus' turn. He wants to tell a letter in such a way, that the TV show host will assuredly reveal at least one more letter. Polycarpus cannot tell the letters, which are already revealed.
Your task is to help Polycarpus and find out the number of letters he can tell so that the show host will assuredly reveal at least one of the remaining letters.
Input
The first line contains one integer n (1 β€ n β€ 50) β the length of the hidden word.
The following line describes already revealed letters. It contains the string of length n, which consists of lowercase Latin letters and symbols "*". If there is a letter at some position, then this letter was already revealed. If the position contains symbol "*", then the letter at this position has not been revealed yet. It is guaranteed, that at least one letter is still closed.
The third line contains an integer m (1 β€ m β€ 1000) β the number of words of length n, which Polycarpus knows. The following m lines contain the words themselves β n-letter strings of lowercase Latin letters. All words are distinct.
It is guaranteed that the hidden word appears as one of the given m words. Before the current move Polycarp has told exactly the letters which are currently revealed.
Output
Output the single integer β the number of letters Polycarpus can tell so that the TV show host definitely reveals at least one more letter. It is possible that this number is zero.
Examples
Input
4
a**d
2
abcd
acbd
Output
2
Input
5
lo*er
2
lover
loser
Output
0
Input
3
a*a
2
aaa
aba
Output
1
Note
In the first example Polycarpus can tell letters "b" and "c", which assuredly will be revealed.
The second example contains no letters which can be told as it is not clear, which of the letters "v" or "s" is located at the third position of the hidden word.
In the third example Polycarpus exactly knows that the hidden word is "aba", because in case it was "aaa", then the second letter "a" would have already been revealed in one of previous turns.
Tags: implementation, strings
Correct Solution:
```
import sys
from collections import defaultdict
def filter_letters(revealed_letters, all_words):
used_char = set()
for letter in revealed_letters:
used_char.add(letter)
unknown_letters = defaultdict(int)
unknown_indices = []
known_indices = []
matching_words = []
valid_words = []
# get the indices of '*'
for index, letter in enumerate(revealed_letters):
if letter == '*':
unknown_indices.append(index)
else:
known_indices.append(index)
#find all words that match the revealed words
for word in all_words:
is_valid = True
for i in known_indices:
if word[i] != revealed_letters[i]:
is_valid = False
break
if is_valid:
matching_words.append(word)
for word in matching_words:
missing_letters = set()
is_valid = True
for i in unknown_indices:
if word[i] in used_char:
is_valid = False
break
else:
missing_letters.add(word[i])
if is_valid:
valid_words.append(word)
for letter in missing_letters:
unknown_letters[letter] += 1
return (unknown_letters, valid_words)
count = 0
possible_words = []
filtered_words = []
for line in sys.stdin:
if count == 0:
len_word = int(line)
elif count == 1:
revealed_letters = line
elif count == 2:
num_possible_words = int(line)
else:
possible_words.append(line)
count += 1
unknown_letters, valid_words = filter_letters(revealed_letters, possible_words)
num_required = len(valid_words)
count = 0
for key in unknown_letters:
if unknown_letters[key] == num_required:
count += 1
print(count)
```
| 44,369 | [
0.2186279296875,
-0.0055389404296875,
0.310302734375,
0.21240234375,
-0.234130859375,
-0.379150390625,
-0.2325439453125,
0.301513671875,
-0.338623046875,
0.40478515625,
1.35546875,
-0.0028400421142578125,
0.0200042724609375,
-0.64892578125,
-0.7939453125,
-0.162109375,
-0.50927734375... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarpus takes part in the "Field of Wonders" TV show. The participants of the show have to guess a hidden word as fast as possible. Initially all the letters of the word are hidden.
The game consists of several turns. At each turn the participant tells a letter and the TV show host responds if there is such letter in the word or not. If there is such letter then the host reveals all such letters. For example, if the hidden word is "abacaba" and the player tells the letter "a", the host will reveal letters at all positions, occupied by "a": 1, 3, 5 and 7 (positions are numbered from left to right starting from 1).
Polycarpus knows m words of exactly the same length as the hidden word. The hidden word is also known to him and appears as one of these m words.
At current moment a number of turns have already been made and some letters (possibly zero) of the hidden word are already revealed. Previously Polycarp has told exactly the letters which are currently revealed.
It is Polycarpus' turn. He wants to tell a letter in such a way, that the TV show host will assuredly reveal at least one more letter. Polycarpus cannot tell the letters, which are already revealed.
Your task is to help Polycarpus and find out the number of letters he can tell so that the show host will assuredly reveal at least one of the remaining letters.
Input
The first line contains one integer n (1 β€ n β€ 50) β the length of the hidden word.
The following line describes already revealed letters. It contains the string of length n, which consists of lowercase Latin letters and symbols "*". If there is a letter at some position, then this letter was already revealed. If the position contains symbol "*", then the letter at this position has not been revealed yet. It is guaranteed, that at least one letter is still closed.
The third line contains an integer m (1 β€ m β€ 1000) β the number of words of length n, which Polycarpus knows. The following m lines contain the words themselves β n-letter strings of lowercase Latin letters. All words are distinct.
It is guaranteed that the hidden word appears as one of the given m words. Before the current move Polycarp has told exactly the letters which are currently revealed.
Output
Output the single integer β the number of letters Polycarpus can tell so that the TV show host definitely reveals at least one more letter. It is possible that this number is zero.
Examples
Input
4
a**d
2
abcd
acbd
Output
2
Input
5
lo*er
2
lover
loser
Output
0
Input
3
a*a
2
aaa
aba
Output
1
Note
In the first example Polycarpus can tell letters "b" and "c", which assuredly will be revealed.
The second example contains no letters which can be told as it is not clear, which of the letters "v" or "s" is located at the third position of the hidden word.
In the third example Polycarpus exactly knows that the hidden word is "aba", because in case it was "aaa", then the second letter "a" would have already been revealed in one of previous turns.
Tags: implementation, strings
Correct Solution:
```
n = int(input())
word = input()
ast = word.count('*')
mas = [i for i in range(n) if word[i] == '*']
mas1 = [i for i in range(n) if word[i] != '*']
st = {word[i] for i in mas1}
m = int(input())
Mas = list()
for i in range(m):
temp = input()
f = True
for j in mas1:
if temp[j] != word[j]:
f = False
break
if f:
t = [temp[k] for k in mas if temp[k] not in st]
if len(t) == ast:
Mas.append(set(t))
ans = set()
for el in Mas:
ans |= el
count = 0
for i in ans:
f = True
for j in Mas:
if i not in j and len(j) > 0:
f = False
break
if f:
count += 1
print(count)
```
| 44,370 | [
0.2186279296875,
-0.0055389404296875,
0.310302734375,
0.21240234375,
-0.234130859375,
-0.379150390625,
-0.2325439453125,
0.301513671875,
-0.338623046875,
0.40478515625,
1.35546875,
-0.0028400421142578125,
0.0200042724609375,
-0.64892578125,
-0.7939453125,
-0.162109375,
-0.50927734375... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarpus takes part in the "Field of Wonders" TV show. The participants of the show have to guess a hidden word as fast as possible. Initially all the letters of the word are hidden.
The game consists of several turns. At each turn the participant tells a letter and the TV show host responds if there is such letter in the word or not. If there is such letter then the host reveals all such letters. For example, if the hidden word is "abacaba" and the player tells the letter "a", the host will reveal letters at all positions, occupied by "a": 1, 3, 5 and 7 (positions are numbered from left to right starting from 1).
Polycarpus knows m words of exactly the same length as the hidden word. The hidden word is also known to him and appears as one of these m words.
At current moment a number of turns have already been made and some letters (possibly zero) of the hidden word are already revealed. Previously Polycarp has told exactly the letters which are currently revealed.
It is Polycarpus' turn. He wants to tell a letter in such a way, that the TV show host will assuredly reveal at least one more letter. Polycarpus cannot tell the letters, which are already revealed.
Your task is to help Polycarpus and find out the number of letters he can tell so that the show host will assuredly reveal at least one of the remaining letters.
Input
The first line contains one integer n (1 β€ n β€ 50) β the length of the hidden word.
The following line describes already revealed letters. It contains the string of length n, which consists of lowercase Latin letters and symbols "*". If there is a letter at some position, then this letter was already revealed. If the position contains symbol "*", then the letter at this position has not been revealed yet. It is guaranteed, that at least one letter is still closed.
The third line contains an integer m (1 β€ m β€ 1000) β the number of words of length n, which Polycarpus knows. The following m lines contain the words themselves β n-letter strings of lowercase Latin letters. All words are distinct.
It is guaranteed that the hidden word appears as one of the given m words. Before the current move Polycarp has told exactly the letters which are currently revealed.
Output
Output the single integer β the number of letters Polycarpus can tell so that the TV show host definitely reveals at least one more letter. It is possible that this number is zero.
Examples
Input
4
a**d
2
abcd
acbd
Output
2
Input
5
lo*er
2
lover
loser
Output
0
Input
3
a*a
2
aaa
aba
Output
1
Note
In the first example Polycarpus can tell letters "b" and "c", which assuredly will be revealed.
The second example contains no letters which can be told as it is not clear, which of the letters "v" or "s" is located at the third position of the hidden word.
In the third example Polycarpus exactly knows that the hidden word is "aba", because in case it was "aaa", then the second letter "a" would have already been revealed in one of previous turns.
Tags: implementation, strings
Correct Solution:
```
I = input
n, s = int(I()), I()
J, K = set(), set()
for i in range(n):
if s[i] == '*':
J.add(i)
else:
K.add(i)
L, S = set('abcdefghijklmnopqrstuvwxyz'), set(s)
for _ in range(int(input())):
w = I()
if all(s[k] == w[k] for k in K):
W = {w[i] for i in J}
if not (S & W):
L &= W
print(len(L))
```
| 44,371 | [
0.2186279296875,
-0.0055389404296875,
0.310302734375,
0.21240234375,
-0.234130859375,
-0.379150390625,
-0.2325439453125,
0.301513671875,
-0.338623046875,
0.40478515625,
1.35546875,
-0.0028400421142578125,
0.0200042724609375,
-0.64892578125,
-0.7939453125,
-0.162109375,
-0.50927734375... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarpus takes part in the "Field of Wonders" TV show. The participants of the show have to guess a hidden word as fast as possible. Initially all the letters of the word are hidden.
The game consists of several turns. At each turn the participant tells a letter and the TV show host responds if there is such letter in the word or not. If there is such letter then the host reveals all such letters. For example, if the hidden word is "abacaba" and the player tells the letter "a", the host will reveal letters at all positions, occupied by "a": 1, 3, 5 and 7 (positions are numbered from left to right starting from 1).
Polycarpus knows m words of exactly the same length as the hidden word. The hidden word is also known to him and appears as one of these m words.
At current moment a number of turns have already been made and some letters (possibly zero) of the hidden word are already revealed. Previously Polycarp has told exactly the letters which are currently revealed.
It is Polycarpus' turn. He wants to tell a letter in such a way, that the TV show host will assuredly reveal at least one more letter. Polycarpus cannot tell the letters, which are already revealed.
Your task is to help Polycarpus and find out the number of letters he can tell so that the show host will assuredly reveal at least one of the remaining letters.
Input
The first line contains one integer n (1 β€ n β€ 50) β the length of the hidden word.
The following line describes already revealed letters. It contains the string of length n, which consists of lowercase Latin letters and symbols "*". If there is a letter at some position, then this letter was already revealed. If the position contains symbol "*", then the letter at this position has not been revealed yet. It is guaranteed, that at least one letter is still closed.
The third line contains an integer m (1 β€ m β€ 1000) β the number of words of length n, which Polycarpus knows. The following m lines contain the words themselves β n-letter strings of lowercase Latin letters. All words are distinct.
It is guaranteed that the hidden word appears as one of the given m words. Before the current move Polycarp has told exactly the letters which are currently revealed.
Output
Output the single integer β the number of letters Polycarpus can tell so that the TV show host definitely reveals at least one more letter. It is possible that this number is zero.
Examples
Input
4
a**d
2
abcd
acbd
Output
2
Input
5
lo*er
2
lover
loser
Output
0
Input
3
a*a
2
aaa
aba
Output
1
Note
In the first example Polycarpus can tell letters "b" and "c", which assuredly will be revealed.
The second example contains no letters which can be told as it is not clear, which of the letters "v" or "s" is located at the third position of the hidden word.
In the third example Polycarpus exactly knows that the hidden word is "aba", because in case it was "aaa", then the second letter "a" would have already been revealed in one of previous turns.
Tags: implementation, strings
Correct Solution:
```
n=int(input())
s=input().strip()
m=int(input())
l=[]
l1=[]
lmain=[]
for i in range(26):
l.append(0)
lmain.append(0)
for i in s:
if (i!='*'):
lmain[ord(i)-97]=1
for i in range(m):
s1=input().strip()
f=0
for j in range(n):
if (s[j]=='*' and lmain[ord(s1[j])-97]==1):
f=1
break
elif (s[j]!='*'):
if (s1[j]!=s[j]):
f=1
break
if (f==0):
l1.append(s1)
length=len(l1)
for i in range(length):
l2=[]
s1=l1[i]
for j in range(26):
l2.append(0)
for j in range(n):
if (s[j]=='*'):
if (l2[ord(s1[j])-97]!=1):
l[ord(s1[j])-97]+=1
l2[ord(s1[j])-97]=1
print (l.count(length))
```
| 44,372 | [
0.2186279296875,
-0.0055389404296875,
0.310302734375,
0.21240234375,
-0.234130859375,
-0.379150390625,
-0.2325439453125,
0.301513671875,
-0.338623046875,
0.40478515625,
1.35546875,
-0.0028400421142578125,
0.0200042724609375,
-0.64892578125,
-0.7939453125,
-0.162109375,
-0.50927734375... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarpus takes part in the "Field of Wonders" TV show. The participants of the show have to guess a hidden word as fast as possible. Initially all the letters of the word are hidden.
The game consists of several turns. At each turn the participant tells a letter and the TV show host responds if there is such letter in the word or not. If there is such letter then the host reveals all such letters. For example, if the hidden word is "abacaba" and the player tells the letter "a", the host will reveal letters at all positions, occupied by "a": 1, 3, 5 and 7 (positions are numbered from left to right starting from 1).
Polycarpus knows m words of exactly the same length as the hidden word. The hidden word is also known to him and appears as one of these m words.
At current moment a number of turns have already been made and some letters (possibly zero) of the hidden word are already revealed. Previously Polycarp has told exactly the letters which are currently revealed.
It is Polycarpus' turn. He wants to tell a letter in such a way, that the TV show host will assuredly reveal at least one more letter. Polycarpus cannot tell the letters, which are already revealed.
Your task is to help Polycarpus and find out the number of letters he can tell so that the show host will assuredly reveal at least one of the remaining letters.
Input
The first line contains one integer n (1 β€ n β€ 50) β the length of the hidden word.
The following line describes already revealed letters. It contains the string of length n, which consists of lowercase Latin letters and symbols "*". If there is a letter at some position, then this letter was already revealed. If the position contains symbol "*", then the letter at this position has not been revealed yet. It is guaranteed, that at least one letter is still closed.
The third line contains an integer m (1 β€ m β€ 1000) β the number of words of length n, which Polycarpus knows. The following m lines contain the words themselves β n-letter strings of lowercase Latin letters. All words are distinct.
It is guaranteed that the hidden word appears as one of the given m words. Before the current move Polycarp has told exactly the letters which are currently revealed.
Output
Output the single integer β the number of letters Polycarpus can tell so that the TV show host definitely reveals at least one more letter. It is possible that this number is zero.
Examples
Input
4
a**d
2
abcd
acbd
Output
2
Input
5
lo*er
2
lover
loser
Output
0
Input
3
a*a
2
aaa
aba
Output
1
Note
In the first example Polycarpus can tell letters "b" and "c", which assuredly will be revealed.
The second example contains no letters which can be told as it is not clear, which of the letters "v" or "s" is located at the third position of the hidden word.
In the third example Polycarpus exactly knows that the hidden word is "aba", because in case it was "aaa", then the second letter "a" would have already been revealed in one of previous turns.
Submitted Solution:
```
alf = "abcdefghijklmnopqrstuvwxyz"
n = int(input())
s = str(input())
m = int(input())
a = []
for _ in range(m):
a.append(input())
used = set(s) - {'*'}
idx = []
for i in range(n):
if s[i]=='*':
idx.append(i)
excp = set(alf) - used
temp = set()
#print(*excp)
#print(*idx)
for i in a:
if all(i[j] == s[j] for j in range(n) if not j in idx):
t = set(i[k] for k in idx)
if t & used == temp:
excp &= t
else:
continue
print(len(excp))
#print(*excp)
```
Yes
| 44,373 | [
0.313232421875,
0.01520538330078125,
0.272705078125,
0.050537109375,
-0.3662109375,
-0.30615234375,
-0.36328125,
0.337646484375,
-0.266357421875,
0.348388671875,
1.234375,
0.05670166015625,
0.0787353515625,
-0.64111328125,
-0.74072265625,
-0.283935546875,
-0.54052734375,
-0.2290039... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarpus takes part in the "Field of Wonders" TV show. The participants of the show have to guess a hidden word as fast as possible. Initially all the letters of the word are hidden.
The game consists of several turns. At each turn the participant tells a letter and the TV show host responds if there is such letter in the word or not. If there is such letter then the host reveals all such letters. For example, if the hidden word is "abacaba" and the player tells the letter "a", the host will reveal letters at all positions, occupied by "a": 1, 3, 5 and 7 (positions are numbered from left to right starting from 1).
Polycarpus knows m words of exactly the same length as the hidden word. The hidden word is also known to him and appears as one of these m words.
At current moment a number of turns have already been made and some letters (possibly zero) of the hidden word are already revealed. Previously Polycarp has told exactly the letters which are currently revealed.
It is Polycarpus' turn. He wants to tell a letter in such a way, that the TV show host will assuredly reveal at least one more letter. Polycarpus cannot tell the letters, which are already revealed.
Your task is to help Polycarpus and find out the number of letters he can tell so that the show host will assuredly reveal at least one of the remaining letters.
Input
The first line contains one integer n (1 β€ n β€ 50) β the length of the hidden word.
The following line describes already revealed letters. It contains the string of length n, which consists of lowercase Latin letters and symbols "*". If there is a letter at some position, then this letter was already revealed. If the position contains symbol "*", then the letter at this position has not been revealed yet. It is guaranteed, that at least one letter is still closed.
The third line contains an integer m (1 β€ m β€ 1000) β the number of words of length n, which Polycarpus knows. The following m lines contain the words themselves β n-letter strings of lowercase Latin letters. All words are distinct.
It is guaranteed that the hidden word appears as one of the given m words. Before the current move Polycarp has told exactly the letters which are currently revealed.
Output
Output the single integer β the number of letters Polycarpus can tell so that the TV show host definitely reveals at least one more letter. It is possible that this number is zero.
Examples
Input
4
a**d
2
abcd
acbd
Output
2
Input
5
lo*er
2
lover
loser
Output
0
Input
3
a*a
2
aaa
aba
Output
1
Note
In the first example Polycarpus can tell letters "b" and "c", which assuredly will be revealed.
The second example contains no letters which can be told as it is not clear, which of the letters "v" or "s" is located at the third position of the hidden word.
In the third example Polycarpus exactly knows that the hidden word is "aba", because in case it was "aaa", then the second letter "a" would have already been revealed in one of previous turns.
Submitted Solution:
```
def f(t):
for i in range(n):
if s[i] != '*' and s[i] != t[i]:
return 0
if s[i] == '*':
if t[i] in fam:
return 0
return 1
n = int(input())
s = input()
fam = set(s)
m = int(input())
a = [input() for i in range(m)]
flag = 0
ans = set()
for t in a:
if f(t):
cur = set(t[i] for i in range(n) if s[i] == '*')
if not flag:
flag = 1
ans = cur
else:
ans &= cur
print(len(ans))
```
Yes
| 44,374 | [
0.313232421875,
0.01520538330078125,
0.272705078125,
0.050537109375,
-0.3662109375,
-0.30615234375,
-0.36328125,
0.337646484375,
-0.266357421875,
0.348388671875,
1.234375,
0.05670166015625,
0.0787353515625,
-0.64111328125,
-0.74072265625,
-0.283935546875,
-0.54052734375,
-0.2290039... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarpus takes part in the "Field of Wonders" TV show. The participants of the show have to guess a hidden word as fast as possible. Initially all the letters of the word are hidden.
The game consists of several turns. At each turn the participant tells a letter and the TV show host responds if there is such letter in the word or not. If there is such letter then the host reveals all such letters. For example, if the hidden word is "abacaba" and the player tells the letter "a", the host will reveal letters at all positions, occupied by "a": 1, 3, 5 and 7 (positions are numbered from left to right starting from 1).
Polycarpus knows m words of exactly the same length as the hidden word. The hidden word is also known to him and appears as one of these m words.
At current moment a number of turns have already been made and some letters (possibly zero) of the hidden word are already revealed. Previously Polycarp has told exactly the letters which are currently revealed.
It is Polycarpus' turn. He wants to tell a letter in such a way, that the TV show host will assuredly reveal at least one more letter. Polycarpus cannot tell the letters, which are already revealed.
Your task is to help Polycarpus and find out the number of letters he can tell so that the show host will assuredly reveal at least one of the remaining letters.
Input
The first line contains one integer n (1 β€ n β€ 50) β the length of the hidden word.
The following line describes already revealed letters. It contains the string of length n, which consists of lowercase Latin letters and symbols "*". If there is a letter at some position, then this letter was already revealed. If the position contains symbol "*", then the letter at this position has not been revealed yet. It is guaranteed, that at least one letter is still closed.
The third line contains an integer m (1 β€ m β€ 1000) β the number of words of length n, which Polycarpus knows. The following m lines contain the words themselves β n-letter strings of lowercase Latin letters. All words are distinct.
It is guaranteed that the hidden word appears as one of the given m words. Before the current move Polycarp has told exactly the letters which are currently revealed.
Output
Output the single integer β the number of letters Polycarpus can tell so that the TV show host definitely reveals at least one more letter. It is possible that this number is zero.
Examples
Input
4
a**d
2
abcd
acbd
Output
2
Input
5
lo*er
2
lover
loser
Output
0
Input
3
a*a
2
aaa
aba
Output
1
Note
In the first example Polycarpus can tell letters "b" and "c", which assuredly will be revealed.
The second example contains no letters which can be told as it is not clear, which of the letters "v" or "s" is located at the third position of the hidden word.
In the third example Polycarpus exactly knows that the hidden word is "aba", because in case it was "aaa", then the second letter "a" would have already been revealed in one of previous turns.
Submitted Solution:
```
n = int(input())
s = input()
m = int(input())
l = []
cnt_ = []
cnt = []
for i in range(n):
if s[i]=='*':
cnt_.append(i)
else: cnt.append(i)
for x in range(m):
flag = True
st = input()
for j in cnt_:
if st[j] in s:
flag = False
else:
for j in cnt:
if st[j]!=s[j]: flag =False
if flag:
l.append(st)
g = [[] for i in range(len(l))]
for i in range(len(l)):
for j in cnt_:
g[i].append(l[i][j])
for i in range(len(g)):
g[i] = list(set(g[i]))
ans = 0
for ch in g[0]:
for li in g:
if ch not in li: break
else: ans = ans+1
print(ans)
```
Yes
| 44,375 | [
0.313232421875,
0.01520538330078125,
0.272705078125,
0.050537109375,
-0.3662109375,
-0.30615234375,
-0.36328125,
0.337646484375,
-0.266357421875,
0.348388671875,
1.234375,
0.05670166015625,
0.0787353515625,
-0.64111328125,
-0.74072265625,
-0.283935546875,
-0.54052734375,
-0.2290039... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarpus takes part in the "Field of Wonders" TV show. The participants of the show have to guess a hidden word as fast as possible. Initially all the letters of the word are hidden.
The game consists of several turns. At each turn the participant tells a letter and the TV show host responds if there is such letter in the word or not. If there is such letter then the host reveals all such letters. For example, if the hidden word is "abacaba" and the player tells the letter "a", the host will reveal letters at all positions, occupied by "a": 1, 3, 5 and 7 (positions are numbered from left to right starting from 1).
Polycarpus knows m words of exactly the same length as the hidden word. The hidden word is also known to him and appears as one of these m words.
At current moment a number of turns have already been made and some letters (possibly zero) of the hidden word are already revealed. Previously Polycarp has told exactly the letters which are currently revealed.
It is Polycarpus' turn. He wants to tell a letter in such a way, that the TV show host will assuredly reveal at least one more letter. Polycarpus cannot tell the letters, which are already revealed.
Your task is to help Polycarpus and find out the number of letters he can tell so that the show host will assuredly reveal at least one of the remaining letters.
Input
The first line contains one integer n (1 β€ n β€ 50) β the length of the hidden word.
The following line describes already revealed letters. It contains the string of length n, which consists of lowercase Latin letters and symbols "*". If there is a letter at some position, then this letter was already revealed. If the position contains symbol "*", then the letter at this position has not been revealed yet. It is guaranteed, that at least one letter is still closed.
The third line contains an integer m (1 β€ m β€ 1000) β the number of words of length n, which Polycarpus knows. The following m lines contain the words themselves β n-letter strings of lowercase Latin letters. All words are distinct.
It is guaranteed that the hidden word appears as one of the given m words. Before the current move Polycarp has told exactly the letters which are currently revealed.
Output
Output the single integer β the number of letters Polycarpus can tell so that the TV show host definitely reveals at least one more letter. It is possible that this number is zero.
Examples
Input
4
a**d
2
abcd
acbd
Output
2
Input
5
lo*er
2
lover
loser
Output
0
Input
3
a*a
2
aaa
aba
Output
1
Note
In the first example Polycarpus can tell letters "b" and "c", which assuredly will be revealed.
The second example contains no letters which can be told as it is not clear, which of the letters "v" or "s" is located at the third position of the hidden word.
In the third example Polycarpus exactly knows that the hidden word is "aba", because in case it was "aaa", then the second letter "a" would have already been revealed in one of previous turns.
Submitted Solution:
```
#python 3.5.2
n = int(input())
kataawal = input()
pos = []
posmuncul = []
muncul = set()
for i,x in zip(range(n),kataawal):
if (x == '*'):
pos.append(i)
else:
muncul.add(x)
posmuncul.append(i)
m = int(input())
belum = []
for i in range(m):
kata = input()
yay = set()
cancel = False
for x in posmuncul:
if (kata[x] != kataawal[x]):
cancel = True
break
if (not cancel):
for x in pos:
if (kata[x] in muncul):
cancel = True
break
else:
yay.add(kata[x])
if (not cancel):
belum.append(yay)
if (len(belum) > 1):
hoo = belum[0]
for sett in belum[1:]:
hoo = hoo.intersection(sett)
print(len(hoo))
elif(len(belum) == 0):
print(0)
else:
print(len(belum[0]))
```
Yes
| 44,376 | [
0.313232421875,
0.01520538330078125,
0.272705078125,
0.050537109375,
-0.3662109375,
-0.30615234375,
-0.36328125,
0.337646484375,
-0.266357421875,
0.348388671875,
1.234375,
0.05670166015625,
0.0787353515625,
-0.64111328125,
-0.74072265625,
-0.283935546875,
-0.54052734375,
-0.2290039... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarpus takes part in the "Field of Wonders" TV show. The participants of the show have to guess a hidden word as fast as possible. Initially all the letters of the word are hidden.
The game consists of several turns. At each turn the participant tells a letter and the TV show host responds if there is such letter in the word or not. If there is such letter then the host reveals all such letters. For example, if the hidden word is "abacaba" and the player tells the letter "a", the host will reveal letters at all positions, occupied by "a": 1, 3, 5 and 7 (positions are numbered from left to right starting from 1).
Polycarpus knows m words of exactly the same length as the hidden word. The hidden word is also known to him and appears as one of these m words.
At current moment a number of turns have already been made and some letters (possibly zero) of the hidden word are already revealed. Previously Polycarp has told exactly the letters which are currently revealed.
It is Polycarpus' turn. He wants to tell a letter in such a way, that the TV show host will assuredly reveal at least one more letter. Polycarpus cannot tell the letters, which are already revealed.
Your task is to help Polycarpus and find out the number of letters he can tell so that the show host will assuredly reveal at least one of the remaining letters.
Input
The first line contains one integer n (1 β€ n β€ 50) β the length of the hidden word.
The following line describes already revealed letters. It contains the string of length n, which consists of lowercase Latin letters and symbols "*". If there is a letter at some position, then this letter was already revealed. If the position contains symbol "*", then the letter at this position has not been revealed yet. It is guaranteed, that at least one letter is still closed.
The third line contains an integer m (1 β€ m β€ 1000) β the number of words of length n, which Polycarpus knows. The following m lines contain the words themselves β n-letter strings of lowercase Latin letters. All words are distinct.
It is guaranteed that the hidden word appears as one of the given m words. Before the current move Polycarp has told exactly the letters which are currently revealed.
Output
Output the single integer β the number of letters Polycarpus can tell so that the TV show host definitely reveals at least one more letter. It is possible that this number is zero.
Examples
Input
4
a**d
2
abcd
acbd
Output
2
Input
5
lo*er
2
lover
loser
Output
0
Input
3
a*a
2
aaa
aba
Output
1
Note
In the first example Polycarpus can tell letters "b" and "c", which assuredly will be revealed.
The second example contains no letters which can be told as it is not clear, which of the letters "v" or "s" is located at the third position of the hidden word.
In the third example Polycarpus exactly knows that the hidden word is "aba", because in case it was "aaa", then the second letter "a" would have already been revealed in one of previous turns.
Submitted Solution:
```
j = i = count = ans = 0
n = int(input())
word = input()
m = int(input())
ws = {}
ls = []
for i in range(m):
ws[i] = input()
for j in word:
ws[i] = ws[i].replace(j, "")
#print(ws[i])
for j in ws[0]:
for i in range(m-1):
if j in ws[i+1]:
count += 1
if (count == m - 1) and (count > 0):
ans += 1
count = 0
print(ans)
```
No
| 44,377 | [
0.313232421875,
0.01520538330078125,
0.272705078125,
0.050537109375,
-0.3662109375,
-0.30615234375,
-0.36328125,
0.337646484375,
-0.266357421875,
0.348388671875,
1.234375,
0.05670166015625,
0.0787353515625,
-0.64111328125,
-0.74072265625,
-0.283935546875,
-0.54052734375,
-0.2290039... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarpus takes part in the "Field of Wonders" TV show. The participants of the show have to guess a hidden word as fast as possible. Initially all the letters of the word are hidden.
The game consists of several turns. At each turn the participant tells a letter and the TV show host responds if there is such letter in the word or not. If there is such letter then the host reveals all such letters. For example, if the hidden word is "abacaba" and the player tells the letter "a", the host will reveal letters at all positions, occupied by "a": 1, 3, 5 and 7 (positions are numbered from left to right starting from 1).
Polycarpus knows m words of exactly the same length as the hidden word. The hidden word is also known to him and appears as one of these m words.
At current moment a number of turns have already been made and some letters (possibly zero) of the hidden word are already revealed. Previously Polycarp has told exactly the letters which are currently revealed.
It is Polycarpus' turn. He wants to tell a letter in such a way, that the TV show host will assuredly reveal at least one more letter. Polycarpus cannot tell the letters, which are already revealed.
Your task is to help Polycarpus and find out the number of letters he can tell so that the show host will assuredly reveal at least one of the remaining letters.
Input
The first line contains one integer n (1 β€ n β€ 50) β the length of the hidden word.
The following line describes already revealed letters. It contains the string of length n, which consists of lowercase Latin letters and symbols "*". If there is a letter at some position, then this letter was already revealed. If the position contains symbol "*", then the letter at this position has not been revealed yet. It is guaranteed, that at least one letter is still closed.
The third line contains an integer m (1 β€ m β€ 1000) β the number of words of length n, which Polycarpus knows. The following m lines contain the words themselves β n-letter strings of lowercase Latin letters. All words are distinct.
It is guaranteed that the hidden word appears as one of the given m words. Before the current move Polycarp has told exactly the letters which are currently revealed.
Output
Output the single integer β the number of letters Polycarpus can tell so that the TV show host definitely reveals at least one more letter. It is possible that this number is zero.
Examples
Input
4
a**d
2
abcd
acbd
Output
2
Input
5
lo*er
2
lover
loser
Output
0
Input
3
a*a
2
aaa
aba
Output
1
Note
In the first example Polycarpus can tell letters "b" and "c", which assuredly will be revealed.
The second example contains no letters which can be told as it is not clear, which of the letters "v" or "s" is located at the third position of the hidden word.
In the third example Polycarpus exactly knows that the hidden word is "aba", because in case it was "aaa", then the second letter "a" would have already been revealed in one of previous turns.
Submitted Solution:
```
n = int(input())
s = input()
oc = s.count('*')
m = int(input())
k = m
a = [0 for i in range(27)]
t = []
for i in range(m):
p = input()
q = ''
for i in range(len(s)):
if s[i] == '*' : q = q+p[i]
p = q
if oc != len(p):
k-=1
continue
r = p
for j in range(len(p)):
a[ord(p[j]) - ord('a')] += 1
p = p.replace(p[j], chr(ord('a')+26))
t.append(r)
jav = 0
if k <= 0:
print(0)
else:
for i in range(26):
#print(str(i) + " " +str(a[k]))
if(k > 0 and a[i] == k):
jav += 1
for j in range(len(t)):
t[j] = t[j].replace(chr(ord('a')+i), "")
if(len(t[j])==0): k-=1
#print(chr(i+ord('a')) + str(a[i]))
print(jav)
```
No
| 44,378 | [
0.313232421875,
0.01520538330078125,
0.272705078125,
0.050537109375,
-0.3662109375,
-0.30615234375,
-0.36328125,
0.337646484375,
-0.266357421875,
0.348388671875,
1.234375,
0.05670166015625,
0.0787353515625,
-0.64111328125,
-0.74072265625,
-0.283935546875,
-0.54052734375,
-0.2290039... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarpus takes part in the "Field of Wonders" TV show. The participants of the show have to guess a hidden word as fast as possible. Initially all the letters of the word are hidden.
The game consists of several turns. At each turn the participant tells a letter and the TV show host responds if there is such letter in the word or not. If there is such letter then the host reveals all such letters. For example, if the hidden word is "abacaba" and the player tells the letter "a", the host will reveal letters at all positions, occupied by "a": 1, 3, 5 and 7 (positions are numbered from left to right starting from 1).
Polycarpus knows m words of exactly the same length as the hidden word. The hidden word is also known to him and appears as one of these m words.
At current moment a number of turns have already been made and some letters (possibly zero) of the hidden word are already revealed. Previously Polycarp has told exactly the letters which are currently revealed.
It is Polycarpus' turn. He wants to tell a letter in such a way, that the TV show host will assuredly reveal at least one more letter. Polycarpus cannot tell the letters, which are already revealed.
Your task is to help Polycarpus and find out the number of letters he can tell so that the show host will assuredly reveal at least one of the remaining letters.
Input
The first line contains one integer n (1 β€ n β€ 50) β the length of the hidden word.
The following line describes already revealed letters. It contains the string of length n, which consists of lowercase Latin letters and symbols "*". If there is a letter at some position, then this letter was already revealed. If the position contains symbol "*", then the letter at this position has not been revealed yet. It is guaranteed, that at least one letter is still closed.
The third line contains an integer m (1 β€ m β€ 1000) β the number of words of length n, which Polycarpus knows. The following m lines contain the words themselves β n-letter strings of lowercase Latin letters. All words are distinct.
It is guaranteed that the hidden word appears as one of the given m words. Before the current move Polycarp has told exactly the letters which are currently revealed.
Output
Output the single integer β the number of letters Polycarpus can tell so that the TV show host definitely reveals at least one more letter. It is possible that this number is zero.
Examples
Input
4
a**d
2
abcd
acbd
Output
2
Input
5
lo*er
2
lover
loser
Output
0
Input
3
a*a
2
aaa
aba
Output
1
Note
In the first example Polycarpus can tell letters "b" and "c", which assuredly will be revealed.
The second example contains no letters which can be told as it is not clear, which of the letters "v" or "s" is located at the third position of the hidden word.
In the third example Polycarpus exactly knows that the hidden word is "aba", because in case it was "aaa", then the second letter "a" would have already been revealed in one of previous turns.
Submitted Solution:
```
n=int(input())
s=list(input())
dis=[]
ind=[]
for i in range(n):
if(s[i]!='*'):
dis.append(s[i])
else:
ind.append(i)
di=set(dis)
c=[]
m=int(input())
for i in range(m):
t=list(input())
q=[]
for j in ind:
q.append(t[j])
q=set(q)
q=q-di
if(len(q)!=0):
c.append(q)
ss=c[0]
l=len(c)
for i in range(1,l):
ss=ss.intersection(c[i])
print(len(ss))
```
No
| 44,379 | [
0.313232421875,
0.01520538330078125,
0.272705078125,
0.050537109375,
-0.3662109375,
-0.30615234375,
-0.36328125,
0.337646484375,
-0.266357421875,
0.348388671875,
1.234375,
0.05670166015625,
0.0787353515625,
-0.64111328125,
-0.74072265625,
-0.283935546875,
-0.54052734375,
-0.2290039... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarpus takes part in the "Field of Wonders" TV show. The participants of the show have to guess a hidden word as fast as possible. Initially all the letters of the word are hidden.
The game consists of several turns. At each turn the participant tells a letter and the TV show host responds if there is such letter in the word or not. If there is such letter then the host reveals all such letters. For example, if the hidden word is "abacaba" and the player tells the letter "a", the host will reveal letters at all positions, occupied by "a": 1, 3, 5 and 7 (positions are numbered from left to right starting from 1).
Polycarpus knows m words of exactly the same length as the hidden word. The hidden word is also known to him and appears as one of these m words.
At current moment a number of turns have already been made and some letters (possibly zero) of the hidden word are already revealed. Previously Polycarp has told exactly the letters which are currently revealed.
It is Polycarpus' turn. He wants to tell a letter in such a way, that the TV show host will assuredly reveal at least one more letter. Polycarpus cannot tell the letters, which are already revealed.
Your task is to help Polycarpus and find out the number of letters he can tell so that the show host will assuredly reveal at least one of the remaining letters.
Input
The first line contains one integer n (1 β€ n β€ 50) β the length of the hidden word.
The following line describes already revealed letters. It contains the string of length n, which consists of lowercase Latin letters and symbols "*". If there is a letter at some position, then this letter was already revealed. If the position contains symbol "*", then the letter at this position has not been revealed yet. It is guaranteed, that at least one letter is still closed.
The third line contains an integer m (1 β€ m β€ 1000) β the number of words of length n, which Polycarpus knows. The following m lines contain the words themselves β n-letter strings of lowercase Latin letters. All words are distinct.
It is guaranteed that the hidden word appears as one of the given m words. Before the current move Polycarp has told exactly the letters which are currently revealed.
Output
Output the single integer β the number of letters Polycarpus can tell so that the TV show host definitely reveals at least one more letter. It is possible that this number is zero.
Examples
Input
4
a**d
2
abcd
acbd
Output
2
Input
5
lo*er
2
lover
loser
Output
0
Input
3
a*a
2
aaa
aba
Output
1
Note
In the first example Polycarpus can tell letters "b" and "c", which assuredly will be revealed.
The second example contains no letters which can be told as it is not clear, which of the letters "v" or "s" is located at the third position of the hidden word.
In the third example Polycarpus exactly knows that the hidden word is "aba", because in case it was "aaa", then the second letter "a" would have already been revealed in one of previous turns.
Submitted Solution:
```
n = int(input())
word = input()
_word = word
words = []
m = int(input())
exist = []
stars = []
for i in word:
if i =='*':
stars+=[word.find('*')]
word = word[:word.find('*')]+word[word.find('*')+1:]
cur = input()
print(stars)
for i in stars:
if cur[i] not in exist and cur[i] not in _word:
exist += [cur[i]]
for j in range(m-1):
cur = input()
wrd = ''
for i in cur:
if i not in _word:
wrd += i
for i in exist:
if i not in wrd:
exist.remove(i)
print(len(exist))
```
No
| 44,380 | [
0.313232421875,
0.01520538330078125,
0.272705078125,
0.050537109375,
-0.3662109375,
-0.30615234375,
-0.36328125,
0.337646484375,
-0.266357421875,
0.348388671875,
1.234375,
0.05670166015625,
0.0787353515625,
-0.64111328125,
-0.74072265625,
-0.283935546875,
-0.54052734375,
-0.2290039... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarpus has a chessboard of size n Γ m, where k rooks are placed. Polycarpus hasn't yet invented the rules of the game he will play. However, he has already allocated q rectangular areas of special strategic importance on the board, they must be protected well. According to Polycarpus, a rectangular area of ββthe board is well protected if all its vacant squares can be beaten by the rooks that stand on this area. The rooks on the rest of the board do not affect the area's defense. The position of the rooks is fixed and cannot be changed. We remind you that the the rook beats the squares located on the same vertical or horizontal line with it, if there are no other pieces between the square and the rook. Help Polycarpus determine whether all strategically important areas are protected.
Input
The first line contains four integers n, m, k and q (1 β€ n, m β€ 100 000, 1 β€ k, q β€ 200 000) β the sizes of the board, the number of rooks and the number of strategically important sites. We will consider that the cells of the board are numbered by integers from 1 to n horizontally and from 1 to m vertically. Next k lines contain pairs of integers "x y", describing the positions of the rooks (1 β€ x β€ n, 1 β€ y β€ m). It is guaranteed that all the rooks are in distinct squares. Next q lines describe the strategically important areas as groups of four integers "x1 y1 x2 y2" (1 β€ x1 β€ x2 β€ n, 1 β€ y1 β€ y2 β€ m). The corresponding rectangle area consists of cells (x, y), for which x1 β€ x β€ x2, y1 β€ y β€ y2. Strategically important areas can intersect of coincide.
Output
Print q lines. For each strategically important site print "YES" if it is well defended and "NO" otherwise.
Examples
Input
4 3 3 3
1 1
3 2
2 3
2 3 2 3
2 1 3 3
1 2 2 3
Output
YES
YES
NO
Note
Picture to the sample: <image> For the last area the answer is "NO", because cell (1, 2) cannot be hit by a rook.
Submitted Solution:
```
n,m,k,q=input().split()
n=int(n)
m=int(m)
k=int(k)
q=int(q)
rook=[]
rookarea=[]
for i in range(k):
p,r=input().split()
rook.append([int(p),int(r)])
a=[]
strarea=[]
for i in range(q):
w,x,y,z=input().split()
w=int(w)
x=int(x)
y=int(y)
z=int(z)
a=[]
for n in range(y-w+1):
for m in range(z-x+1):
a.append([w+n,x+m])
strarea.append(a)
for j in rook:
b=j[0]
c=j[1]
if j in strarea[i]:
for t in range(w,y+1):
if [t,c] in strarea[i]:
strarea[i].remove([t,c])
for t in range(x,z+1):
if [b,t] in strarea[i]:
strarea[i].remove([b,t])
for i in strarea:
if(i==[]):
print("Yes")
else:
print("No")
```
No
| 45,750 | [
0.5283203125,
0.23046875,
0.1778564453125,
0.33056640625,
-0.7392578125,
-0.392822265625,
-0.048675537109375,
0.361572265625,
0.2529296875,
0.5146484375,
0.95361328125,
0.18505859375,
-0.0189056396484375,
-0.280029296875,
-0.3583984375,
0.1837158203125,
-0.456298828125,
-0.52490234... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarpus has a chessboard of size n Γ m, where k rooks are placed. Polycarpus hasn't yet invented the rules of the game he will play. However, he has already allocated q rectangular areas of special strategic importance on the board, they must be protected well. According to Polycarpus, a rectangular area of ββthe board is well protected if all its vacant squares can be beaten by the rooks that stand on this area. The rooks on the rest of the board do not affect the area's defense. The position of the rooks is fixed and cannot be changed. We remind you that the the rook beats the squares located on the same vertical or horizontal line with it, if there are no other pieces between the square and the rook. Help Polycarpus determine whether all strategically important areas are protected.
Input
The first line contains four integers n, m, k and q (1 β€ n, m β€ 100 000, 1 β€ k, q β€ 200 000) β the sizes of the board, the number of rooks and the number of strategically important sites. We will consider that the cells of the board are numbered by integers from 1 to n horizontally and from 1 to m vertically. Next k lines contain pairs of integers "x y", describing the positions of the rooks (1 β€ x β€ n, 1 β€ y β€ m). It is guaranteed that all the rooks are in distinct squares. Next q lines describe the strategically important areas as groups of four integers "x1 y1 x2 y2" (1 β€ x1 β€ x2 β€ n, 1 β€ y1 β€ y2 β€ m). The corresponding rectangle area consists of cells (x, y), for which x1 β€ x β€ x2, y1 β€ y β€ y2. Strategically important areas can intersect of coincide.
Output
Print q lines. For each strategically important site print "YES" if it is well defended and "NO" otherwise.
Examples
Input
4 3 3 3
1 1
3 2
2 3
2 3 2 3
2 1 3 3
1 2 2 3
Output
YES
YES
NO
Note
Picture to the sample: <image> For the last area the answer is "NO", because cell (1, 2) cannot be hit by a rook.
Submitted Solution:
```
n,m,k,q=(int(x) for x in input().split())
coord=[]
otvet=''
for i in range(k):
coord.append([int(z) for z in input().split()])
for i in range(q):
x_coord=[]
y_coord=[]
x1,y1,x2,y2=(int(z) for z in input().split())
for elem in coord:
if elem[0]>=x1 and elem[0]<=x2 and elem[1]>=y1 and elem[1]<=y2:
x_coord.append(elem[0])
y_coord.append(elem[1])
flag=True
if len(x_coord)<(x2-x1+1) and len(y_coord)<(y2-y1+1):
flag=False
if flag:
for j in range(x1,x2+1):
if not j in x_coord:
flag=False
break
if not flag:
for j in range(y1,y2+1):
if not j in y_coord:
flag=False
break
if flag:
otvet+='YES\n'
else:
otvet+='NO\n'
print(otvet)
```
No
| 45,751 | [
0.5263671875,
0.217529296875,
0.187744140625,
0.334716796875,
-0.7236328125,
-0.39697265625,
-0.050048828125,
0.35302734375,
0.26220703125,
0.50927734375,
0.951171875,
0.1806640625,
-0.029693603515625,
-0.2646484375,
-0.349609375,
0.197265625,
-0.4599609375,
-0.5234375,
-0.442382... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarpus has a chessboard of size n Γ m, where k rooks are placed. Polycarpus hasn't yet invented the rules of the game he will play. However, he has already allocated q rectangular areas of special strategic importance on the board, they must be protected well. According to Polycarpus, a rectangular area of ββthe board is well protected if all its vacant squares can be beaten by the rooks that stand on this area. The rooks on the rest of the board do not affect the area's defense. The position of the rooks is fixed and cannot be changed. We remind you that the the rook beats the squares located on the same vertical or horizontal line with it, if there are no other pieces between the square and the rook. Help Polycarpus determine whether all strategically important areas are protected.
Input
The first line contains four integers n, m, k and q (1 β€ n, m β€ 100 000, 1 β€ k, q β€ 200 000) β the sizes of the board, the number of rooks and the number of strategically important sites. We will consider that the cells of the board are numbered by integers from 1 to n horizontally and from 1 to m vertically. Next k lines contain pairs of integers "x y", describing the positions of the rooks (1 β€ x β€ n, 1 β€ y β€ m). It is guaranteed that all the rooks are in distinct squares. Next q lines describe the strategically important areas as groups of four integers "x1 y1 x2 y2" (1 β€ x1 β€ x2 β€ n, 1 β€ y1 β€ y2 β€ m). The corresponding rectangle area consists of cells (x, y), for which x1 β€ x β€ x2, y1 β€ y β€ y2. Strategically important areas can intersect of coincide.
Output
Print q lines. For each strategically important site print "YES" if it is well defended and "NO" otherwise.
Examples
Input
4 3 3 3
1 1
3 2
2 3
2 3 2 3
2 1 3 3
1 2 2 3
Output
YES
YES
NO
Note
Picture to the sample: <image> For the last area the answer is "NO", because cell (1, 2) cannot be hit by a rook.
Submitted Solution:
```
n,m,k,q=input().split()
n=int(n)
m=int(m)
k=int(k)
q=int(q)
rook=[]
rookarea=[]
for i in range(k):
p,r=input().split()
rook.append([int(p),int(r)])
a=[]
for j in range(1,n+1):
a.append([int(p),j])
for j in range(1,m+1):
a.append([j,int(r)])
rookarea.append(a)
strarea=[]
for i in range(q):
w,x,y,z=input().split()
w=int(w)
x=int(x)
y=int(y)
z=int(z)
a=[]
for n in range(y-w+1):
for m in range(z-x+1):
a.append([w+n,x+m])
strarea.append(a)
for i in range(len(strarea)):
for j in range(len(rook)):
if rook[j] in strarea[i]:
for l in rookarea[j]:
if l in strarea[i]:
strarea[i].remove(l)
for i in strarea:
if(i==[]):
print("Yes")
else:
print("No")
```
No
| 45,752 | [
0.5283203125,
0.23046875,
0.1778564453125,
0.33056640625,
-0.7392578125,
-0.392822265625,
-0.048675537109375,
0.361572265625,
0.2529296875,
0.5146484375,
0.95361328125,
0.18505859375,
-0.0189056396484375,
-0.280029296875,
-0.3583984375,
0.1837158203125,
-0.456298828125,
-0.52490234... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarpus has a chessboard of size n Γ m, where k rooks are placed. Polycarpus hasn't yet invented the rules of the game he will play. However, he has already allocated q rectangular areas of special strategic importance on the board, they must be protected well. According to Polycarpus, a rectangular area of ββthe board is well protected if all its vacant squares can be beaten by the rooks that stand on this area. The rooks on the rest of the board do not affect the area's defense. The position of the rooks is fixed and cannot be changed. We remind you that the the rook beats the squares located on the same vertical or horizontal line with it, if there are no other pieces between the square and the rook. Help Polycarpus determine whether all strategically important areas are protected.
Input
The first line contains four integers n, m, k and q (1 β€ n, m β€ 100 000, 1 β€ k, q β€ 200 000) β the sizes of the board, the number of rooks and the number of strategically important sites. We will consider that the cells of the board are numbered by integers from 1 to n horizontally and from 1 to m vertically. Next k lines contain pairs of integers "x y", describing the positions of the rooks (1 β€ x β€ n, 1 β€ y β€ m). It is guaranteed that all the rooks are in distinct squares. Next q lines describe the strategically important areas as groups of four integers "x1 y1 x2 y2" (1 β€ x1 β€ x2 β€ n, 1 β€ y1 β€ y2 β€ m). The corresponding rectangle area consists of cells (x, y), for which x1 β€ x β€ x2, y1 β€ y β€ y2. Strategically important areas can intersect of coincide.
Output
Print q lines. For each strategically important site print "YES" if it is well defended and "NO" otherwise.
Examples
Input
4 3 3 3
1 1
3 2
2 3
2 3 2 3
2 1 3 3
1 2 2 3
Output
YES
YES
NO
Note
Picture to the sample: <image> For the last area the answer is "NO", because cell (1, 2) cannot be hit by a rook.
Submitted Solution:
```
n,m,k,q=(int(x) for x in input().split())
coord=[]
otvet=''
for i in range(k):
coord.append([int(z) for z in input().split()])
for i in range(q):
bzz=[]
x_coord=[]
y_coord=[]
ys=[]
x1,y1,x2,y2=(int(z) for z in input().split())
for elem in coord:
if elem[0]>=x1 and elem[0]<=x2 and elem[1]>=y1 and elem[1]<=y2:
x_coord.append(elem[0])
y_coord.append(elem[1])
bzz.append(elem)
flag=True
if len(x_coord)<(x2-x1+1) and len(y_coord)<(y2-y1+1):
flag=False
if flag:
k=0
for j in range(x1,x2+1):
if not j in x_coord:
flag=False
break
else:
for elem in bzz:
if elem[0]==j:
ys.append(elem[1])
if not flag:
for j in range(y1,y2+1):
if not j in ys:
if j in y_coord:
flag=True
else:
flag=False
break
if flag:
otvet+='YES\n'
else:
otvet+='NO\n'
print(otvet)
```
No
| 45,753 | [
0.5263671875,
0.217529296875,
0.187744140625,
0.334716796875,
-0.7236328125,
-0.39697265625,
-0.050048828125,
0.35302734375,
0.26220703125,
0.50927734375,
0.951171875,
0.1806640625,
-0.029693603515625,
-0.2646484375,
-0.349609375,
0.197265625,
-0.4599609375,
-0.5234375,
-0.442382... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The only difference between easy and hard versions is constraints.
A session has begun at Beland State University. Many students are taking exams.
Polygraph Poligrafovich is going to examine a group of n students. Students will take the exam one-by-one in order from 1-th to n-th. Rules of the exam are following:
* The i-th student randomly chooses a ticket.
* if this ticket is too hard to the student, he doesn't answer and goes home immediately (this process is so fast that it's considered no time elapses). This student fails the exam.
* if the student finds the ticket easy, he spends exactly t_i minutes to pass the exam. After it, he immediately gets a mark and goes home.
Students take the exam in the fixed order, one-by-one, without any interruption. At any moment of time, Polygraph Poligrafovich takes the answer from one student.
The duration of the whole exam for all students is M minutes (max t_i β€ M), so students at the end of the list have a greater possibility to run out of time to pass the exam.
For each student i, you should count the minimum possible number of students who need to fail the exam so the i-th student has enough time to pass the exam.
For each student i, find the answer independently. That is, if when finding the answer for the student i_1 some student j should leave, then while finding the answer for i_2 (i_2>i_1) the student j student does not have to go home.
Input
The first line of the input contains two integers n and M (1 β€ n β€ 100, 1 β€ M β€ 100) β the number of students and the total duration of the exam in minutes, respectively.
The second line of the input contains n integers t_i (1 β€ t_i β€ 100) β time in minutes that i-th student spends to answer to a ticket.
It's guaranteed that all values of t_i are not greater than M.
Output
Print n numbers: the i-th number must be equal to the minimum number of students who have to leave the exam in order to i-th student has enough time to pass the exam.
Examples
Input
7 15
1 2 3 4 5 6 7
Output
0 0 0 0 0 2 3
Input
5 100
80 40 40 40 60
Output
0 1 1 2 3
Note
The explanation for the example 1.
Please note that the sum of the first five exam times does not exceed M=15 (the sum is 1+2+3+4+5=15). Thus, the first five students can pass the exam even if all the students before them also pass the exam. In other words, the first five numbers in the answer are 0.
In order for the 6-th student to pass the exam, it is necessary that at least 2 students must fail it before (for example, the 3-rd and 4-th, then the 6-th will finish its exam in 1+2+5+6=14 minutes, which does not exceed M).
In order for the 7-th student to pass the exam, it is necessary that at least 3 students must fail it before (for example, the 2-nd, 5-th and 6-th, then the 7-th will finish its exam in 1+3+4+7=15 minutes, which does not exceed M).
Tags: greedy, sortings
Correct Solution:
```
n,m = map(int,input().split());
z = list(map(int,input().split()));
ans = []
csum=0
for i in range(len(z)):
csum+=z[i];
if(csum<=m):
ans.append(0);
else:
tmparr = z[0:i];
tcsum = csum;
tmparr.sort(reverse = True)
for i in range(len(tmparr)):
tcsum-=tmparr[i];
if(tcsum<=m):
ans.append(i+1)
break
print(*ans)
```
| 46,295 | [
0.5390625,
0.059234619140625,
0.14111328125,
0.184326171875,
-0.33154296875,
-0.263671875,
-0.408203125,
-0.038787841796875,
-0.1915283203125,
0.85986328125,
0.90283203125,
0.057525634765625,
0.326904296875,
-1.1015625,
-0.39208984375,
0.21484375,
-0.82763671875,
-0.40283203125,
... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The only difference between easy and hard versions is constraints.
A session has begun at Beland State University. Many students are taking exams.
Polygraph Poligrafovich is going to examine a group of n students. Students will take the exam one-by-one in order from 1-th to n-th. Rules of the exam are following:
* The i-th student randomly chooses a ticket.
* if this ticket is too hard to the student, he doesn't answer and goes home immediately (this process is so fast that it's considered no time elapses). This student fails the exam.
* if the student finds the ticket easy, he spends exactly t_i minutes to pass the exam. After it, he immediately gets a mark and goes home.
Students take the exam in the fixed order, one-by-one, without any interruption. At any moment of time, Polygraph Poligrafovich takes the answer from one student.
The duration of the whole exam for all students is M minutes (max t_i β€ M), so students at the end of the list have a greater possibility to run out of time to pass the exam.
For each student i, you should count the minimum possible number of students who need to fail the exam so the i-th student has enough time to pass the exam.
For each student i, find the answer independently. That is, if when finding the answer for the student i_1 some student j should leave, then while finding the answer for i_2 (i_2>i_1) the student j student does not have to go home.
Input
The first line of the input contains two integers n and M (1 β€ n β€ 100, 1 β€ M β€ 100) β the number of students and the total duration of the exam in minutes, respectively.
The second line of the input contains n integers t_i (1 β€ t_i β€ 100) β time in minutes that i-th student spends to answer to a ticket.
It's guaranteed that all values of t_i are not greater than M.
Output
Print n numbers: the i-th number must be equal to the minimum number of students who have to leave the exam in order to i-th student has enough time to pass the exam.
Examples
Input
7 15
1 2 3 4 5 6 7
Output
0 0 0 0 0 2 3
Input
5 100
80 40 40 40 60
Output
0 1 1 2 3
Note
The explanation for the example 1.
Please note that the sum of the first five exam times does not exceed M=15 (the sum is 1+2+3+4+5=15). Thus, the first five students can pass the exam even if all the students before them also pass the exam. In other words, the first five numbers in the answer are 0.
In order for the 6-th student to pass the exam, it is necessary that at least 2 students must fail it before (for example, the 3-rd and 4-th, then the 6-th will finish its exam in 1+2+5+6=14 minutes, which does not exceed M).
In order for the 7-th student to pass the exam, it is necessary that at least 3 students must fail it before (for example, the 2-nd, 5-th and 6-th, then the 7-th will finish its exam in 1+3+4+7=15 minutes, which does not exceed M).
Tags: greedy, sortings
Correct Solution:
```
from sys import *
buckets = [0]*101
n, M = map(int, stdin.readline().split())
ts = [int(t) for t in stdin.readline().split()]
full_sum = 0
for i in range(n):
cur_M = M
cur_sum = full_sum
bucket_idx = 100
ans = 0
while cur_sum > cur_M - ts[i]:
if cur_sum - cur_M + ts[i] >= buckets[bucket_idx]*bucket_idx:
cur_sum -= buckets[bucket_idx]*bucket_idx
ans += buckets[bucket_idx]
else:
tmp = (cur_sum - cur_M + ts[i] - 1) // bucket_idx + 1
ans += tmp
cur_sum -= bucket_idx*tmp
bucket_idx -= 1
stdout.write(str(ans)+" ")
full_sum += ts[i]
buckets[ts[i]] += 1
stdout.write("\n")
```
| 46,296 | [
0.5390625,
0.059234619140625,
0.14111328125,
0.184326171875,
-0.33154296875,
-0.263671875,
-0.408203125,
-0.038787841796875,
-0.1915283203125,
0.85986328125,
0.90283203125,
0.057525634765625,
0.326904296875,
-1.1015625,
-0.39208984375,
0.21484375,
-0.82763671875,
-0.40283203125,
... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The only difference between easy and hard versions is constraints.
A session has begun at Beland State University. Many students are taking exams.
Polygraph Poligrafovich is going to examine a group of n students. Students will take the exam one-by-one in order from 1-th to n-th. Rules of the exam are following:
* The i-th student randomly chooses a ticket.
* if this ticket is too hard to the student, he doesn't answer and goes home immediately (this process is so fast that it's considered no time elapses). This student fails the exam.
* if the student finds the ticket easy, he spends exactly t_i minutes to pass the exam. After it, he immediately gets a mark and goes home.
Students take the exam in the fixed order, one-by-one, without any interruption. At any moment of time, Polygraph Poligrafovich takes the answer from one student.
The duration of the whole exam for all students is M minutes (max t_i β€ M), so students at the end of the list have a greater possibility to run out of time to pass the exam.
For each student i, you should count the minimum possible number of students who need to fail the exam so the i-th student has enough time to pass the exam.
For each student i, find the answer independently. That is, if when finding the answer for the student i_1 some student j should leave, then while finding the answer for i_2 (i_2>i_1) the student j student does not have to go home.
Input
The first line of the input contains two integers n and M (1 β€ n β€ 100, 1 β€ M β€ 100) β the number of students and the total duration of the exam in minutes, respectively.
The second line of the input contains n integers t_i (1 β€ t_i β€ 100) β time in minutes that i-th student spends to answer to a ticket.
It's guaranteed that all values of t_i are not greater than M.
Output
Print n numbers: the i-th number must be equal to the minimum number of students who have to leave the exam in order to i-th student has enough time to pass the exam.
Examples
Input
7 15
1 2 3 4 5 6 7
Output
0 0 0 0 0 2 3
Input
5 100
80 40 40 40 60
Output
0 1 1 2 3
Note
The explanation for the example 1.
Please note that the sum of the first five exam times does not exceed M=15 (the sum is 1+2+3+4+5=15). Thus, the first five students can pass the exam even if all the students before them also pass the exam. In other words, the first five numbers in the answer are 0.
In order for the 6-th student to pass the exam, it is necessary that at least 2 students must fail it before (for example, the 3-rd and 4-th, then the 6-th will finish its exam in 1+2+5+6=14 minutes, which does not exceed M).
In order for the 7-th student to pass the exam, it is necessary that at least 3 students must fail it before (for example, the 2-nd, 5-th and 6-th, then the 7-th will finish its exam in 1+3+4+7=15 minutes, which does not exceed M).
Tags: greedy, sortings
Correct Solution:
```
R = lambda: map(int, input().split())
n,m = R()
L = list(R())
f = [0]*101
su = 0
for i in range(n):
su += L[i]
p = su-m
c = 0
#print(p,su)
if p > 0:
for j in reversed(range(1,101)):
if f[j] > 0:
if p < (f[j]*j):
c += ((p+j-1)//j)
break
else:
c += f[j]
p -= (j*f[j])
print(c,end=' ')
f[L[i]] += 1
```
| 46,297 | [
0.5390625,
0.059234619140625,
0.14111328125,
0.184326171875,
-0.33154296875,
-0.263671875,
-0.408203125,
-0.038787841796875,
-0.1915283203125,
0.85986328125,
0.90283203125,
0.057525634765625,
0.326904296875,
-1.1015625,
-0.39208984375,
0.21484375,
-0.82763671875,
-0.40283203125,
... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The only difference between easy and hard versions is constraints.
A session has begun at Beland State University. Many students are taking exams.
Polygraph Poligrafovich is going to examine a group of n students. Students will take the exam one-by-one in order from 1-th to n-th. Rules of the exam are following:
* The i-th student randomly chooses a ticket.
* if this ticket is too hard to the student, he doesn't answer and goes home immediately (this process is so fast that it's considered no time elapses). This student fails the exam.
* if the student finds the ticket easy, he spends exactly t_i minutes to pass the exam. After it, he immediately gets a mark and goes home.
Students take the exam in the fixed order, one-by-one, without any interruption. At any moment of time, Polygraph Poligrafovich takes the answer from one student.
The duration of the whole exam for all students is M minutes (max t_i β€ M), so students at the end of the list have a greater possibility to run out of time to pass the exam.
For each student i, you should count the minimum possible number of students who need to fail the exam so the i-th student has enough time to pass the exam.
For each student i, find the answer independently. That is, if when finding the answer for the student i_1 some student j should leave, then while finding the answer for i_2 (i_2>i_1) the student j student does not have to go home.
Input
The first line of the input contains two integers n and M (1 β€ n β€ 100, 1 β€ M β€ 100) β the number of students and the total duration of the exam in minutes, respectively.
The second line of the input contains n integers t_i (1 β€ t_i β€ 100) β time in minutes that i-th student spends to answer to a ticket.
It's guaranteed that all values of t_i are not greater than M.
Output
Print n numbers: the i-th number must be equal to the minimum number of students who have to leave the exam in order to i-th student has enough time to pass the exam.
Examples
Input
7 15
1 2 3 4 5 6 7
Output
0 0 0 0 0 2 3
Input
5 100
80 40 40 40 60
Output
0 1 1 2 3
Note
The explanation for the example 1.
Please note that the sum of the first five exam times does not exceed M=15 (the sum is 1+2+3+4+5=15). Thus, the first five students can pass the exam even if all the students before them also pass the exam. In other words, the first five numbers in the answer are 0.
In order for the 6-th student to pass the exam, it is necessary that at least 2 students must fail it before (for example, the 3-rd and 4-th, then the 6-th will finish its exam in 1+2+5+6=14 minutes, which does not exceed M).
In order for the 7-th student to pass the exam, it is necessary that at least 3 students must fail it before (for example, the 2-nd, 5-th and 6-th, then the 7-th will finish its exam in 1+3+4+7=15 minutes, which does not exceed M).
Tags: greedy, sortings
Correct Solution:
```
n,m=map(int,input().split())
ticket=list(map(int,input().split()))
sum=0
for i in range(n):
sum+=ticket[i]
if(sum<=m):
print(0,end=" ")
else:
tmp=sorted(ticket[0:i])
tmpSum=sum
c=0
index=i-1
while(True):
if(tmpSum<=m):
print(c,end=" ")
break
else:
tmpSum-=tmp[index]
index-=1
c+=1
#Lorenzo
```
| 46,298 | [
0.5390625,
0.059234619140625,
0.14111328125,
0.184326171875,
-0.33154296875,
-0.263671875,
-0.408203125,
-0.038787841796875,
-0.1915283203125,
0.85986328125,
0.90283203125,
0.057525634765625,
0.326904296875,
-1.1015625,
-0.39208984375,
0.21484375,
-0.82763671875,
-0.40283203125,
... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The only difference between easy and hard versions is constraints.
A session has begun at Beland State University. Many students are taking exams.
Polygraph Poligrafovich is going to examine a group of n students. Students will take the exam one-by-one in order from 1-th to n-th. Rules of the exam are following:
* The i-th student randomly chooses a ticket.
* if this ticket is too hard to the student, he doesn't answer and goes home immediately (this process is so fast that it's considered no time elapses). This student fails the exam.
* if the student finds the ticket easy, he spends exactly t_i minutes to pass the exam. After it, he immediately gets a mark and goes home.
Students take the exam in the fixed order, one-by-one, without any interruption. At any moment of time, Polygraph Poligrafovich takes the answer from one student.
The duration of the whole exam for all students is M minutes (max t_i β€ M), so students at the end of the list have a greater possibility to run out of time to pass the exam.
For each student i, you should count the minimum possible number of students who need to fail the exam so the i-th student has enough time to pass the exam.
For each student i, find the answer independently. That is, if when finding the answer for the student i_1 some student j should leave, then while finding the answer for i_2 (i_2>i_1) the student j student does not have to go home.
Input
The first line of the input contains two integers n and M (1 β€ n β€ 100, 1 β€ M β€ 100) β the number of students and the total duration of the exam in minutes, respectively.
The second line of the input contains n integers t_i (1 β€ t_i β€ 100) β time in minutes that i-th student spends to answer to a ticket.
It's guaranteed that all values of t_i are not greater than M.
Output
Print n numbers: the i-th number must be equal to the minimum number of students who have to leave the exam in order to i-th student has enough time to pass the exam.
Examples
Input
7 15
1 2 3 4 5 6 7
Output
0 0 0 0 0 2 3
Input
5 100
80 40 40 40 60
Output
0 1 1 2 3
Note
The explanation for the example 1.
Please note that the sum of the first five exam times does not exceed M=15 (the sum is 1+2+3+4+5=15). Thus, the first five students can pass the exam even if all the students before them also pass the exam. In other words, the first five numbers in the answer are 0.
In order for the 6-th student to pass the exam, it is necessary that at least 2 students must fail it before (for example, the 3-rd and 4-th, then the 6-th will finish its exam in 1+2+5+6=14 minutes, which does not exceed M).
In order for the 7-th student to pass the exam, it is necessary that at least 3 students must fail it before (for example, the 2-nd, 5-th and 6-th, then the 7-th will finish its exam in 1+3+4+7=15 minutes, which does not exceed M).
Tags: greedy, sortings
Correct Solution:
```
n,maxi=list(map(int,input().split()))
List=list(map(int,input().split()))
List2=['0']
for i in range(1,n):
c=List[:]
count=0
while sum(c[:i])>maxi-c[i]:
index=c.index(max(c[:i]))
c[index]=0
count+=1
List2.append(str(count))
print(' '.join(List2))
```
| 46,299 | [
0.5390625,
0.059234619140625,
0.14111328125,
0.184326171875,
-0.33154296875,
-0.263671875,
-0.408203125,
-0.038787841796875,
-0.1915283203125,
0.85986328125,
0.90283203125,
0.057525634765625,
0.326904296875,
-1.1015625,
-0.39208984375,
0.21484375,
-0.82763671875,
-0.40283203125,
... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The only difference between easy and hard versions is constraints.
A session has begun at Beland State University. Many students are taking exams.
Polygraph Poligrafovich is going to examine a group of n students. Students will take the exam one-by-one in order from 1-th to n-th. Rules of the exam are following:
* The i-th student randomly chooses a ticket.
* if this ticket is too hard to the student, he doesn't answer and goes home immediately (this process is so fast that it's considered no time elapses). This student fails the exam.
* if the student finds the ticket easy, he spends exactly t_i minutes to pass the exam. After it, he immediately gets a mark and goes home.
Students take the exam in the fixed order, one-by-one, without any interruption. At any moment of time, Polygraph Poligrafovich takes the answer from one student.
The duration of the whole exam for all students is M minutes (max t_i β€ M), so students at the end of the list have a greater possibility to run out of time to pass the exam.
For each student i, you should count the minimum possible number of students who need to fail the exam so the i-th student has enough time to pass the exam.
For each student i, find the answer independently. That is, if when finding the answer for the student i_1 some student j should leave, then while finding the answer for i_2 (i_2>i_1) the student j student does not have to go home.
Input
The first line of the input contains two integers n and M (1 β€ n β€ 100, 1 β€ M β€ 100) β the number of students and the total duration of the exam in minutes, respectively.
The second line of the input contains n integers t_i (1 β€ t_i β€ 100) β time in minutes that i-th student spends to answer to a ticket.
It's guaranteed that all values of t_i are not greater than M.
Output
Print n numbers: the i-th number must be equal to the minimum number of students who have to leave the exam in order to i-th student has enough time to pass the exam.
Examples
Input
7 15
1 2 3 4 5 6 7
Output
0 0 0 0 0 2 3
Input
5 100
80 40 40 40 60
Output
0 1 1 2 3
Note
The explanation for the example 1.
Please note that the sum of the first five exam times does not exceed M=15 (the sum is 1+2+3+4+5=15). Thus, the first five students can pass the exam even if all the students before them also pass the exam. In other words, the first five numbers in the answer are 0.
In order for the 6-th student to pass the exam, it is necessary that at least 2 students must fail it before (for example, the 3-rd and 4-th, then the 6-th will finish its exam in 1+2+5+6=14 minutes, which does not exceed M).
In order for the 7-th student to pass the exam, it is necessary that at least 3 students must fail it before (for example, the 2-nd, 5-th and 6-th, then the 7-th will finish its exam in 1+3+4+7=15 minutes, which does not exceed M).
Tags: greedy, sortings
Correct Solution:
```
n, m = map(int, input().split())
t = list(map(int, input().split()))
mm = []; ss = 0
for i in range(n):
if sum(mm) + t[i] <= m:
print(0, end = ' ')
else:
mm = sorted(mm); ss = sum(mm); xx = 0;
tmp = []
while ss + t[i] > m:
tmp.append(mm.pop())
ss -= tmp[-1]
xx += 1
print(xx, end = ' ')
while len(tmp) != 0:
mm.append(tmp.pop())
mm.append(t[i])
```
| 46,300 | [
0.5390625,
0.059234619140625,
0.14111328125,
0.184326171875,
-0.33154296875,
-0.263671875,
-0.408203125,
-0.038787841796875,
-0.1915283203125,
0.85986328125,
0.90283203125,
0.057525634765625,
0.326904296875,
-1.1015625,
-0.39208984375,
0.21484375,
-0.82763671875,
-0.40283203125,
... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The only difference between easy and hard versions is constraints.
A session has begun at Beland State University. Many students are taking exams.
Polygraph Poligrafovich is going to examine a group of n students. Students will take the exam one-by-one in order from 1-th to n-th. Rules of the exam are following:
* The i-th student randomly chooses a ticket.
* if this ticket is too hard to the student, he doesn't answer and goes home immediately (this process is so fast that it's considered no time elapses). This student fails the exam.
* if the student finds the ticket easy, he spends exactly t_i minutes to pass the exam. After it, he immediately gets a mark and goes home.
Students take the exam in the fixed order, one-by-one, without any interruption. At any moment of time, Polygraph Poligrafovich takes the answer from one student.
The duration of the whole exam for all students is M minutes (max t_i β€ M), so students at the end of the list have a greater possibility to run out of time to pass the exam.
For each student i, you should count the minimum possible number of students who need to fail the exam so the i-th student has enough time to pass the exam.
For each student i, find the answer independently. That is, if when finding the answer for the student i_1 some student j should leave, then while finding the answer for i_2 (i_2>i_1) the student j student does not have to go home.
Input
The first line of the input contains two integers n and M (1 β€ n β€ 100, 1 β€ M β€ 100) β the number of students and the total duration of the exam in minutes, respectively.
The second line of the input contains n integers t_i (1 β€ t_i β€ 100) β time in minutes that i-th student spends to answer to a ticket.
It's guaranteed that all values of t_i are not greater than M.
Output
Print n numbers: the i-th number must be equal to the minimum number of students who have to leave the exam in order to i-th student has enough time to pass the exam.
Examples
Input
7 15
1 2 3 4 5 6 7
Output
0 0 0 0 0 2 3
Input
5 100
80 40 40 40 60
Output
0 1 1 2 3
Note
The explanation for the example 1.
Please note that the sum of the first five exam times does not exceed M=15 (the sum is 1+2+3+4+5=15). Thus, the first five students can pass the exam even if all the students before them also pass the exam. In other words, the first five numbers in the answer are 0.
In order for the 6-th student to pass the exam, it is necessary that at least 2 students must fail it before (for example, the 3-rd and 4-th, then the 6-th will finish its exam in 1+2+5+6=14 minutes, which does not exceed M).
In order for the 7-th student to pass the exam, it is necessary that at least 3 students must fail it before (for example, the 2-nd, 5-th and 6-th, then the 7-th will finish its exam in 1+3+4+7=15 minutes, which does not exceed M).
Tags: greedy, sortings
Correct Solution:
```
n,m=[int(x) for x in input().split()]
a=[int(x) for x in input().split()]
ans=[0]*n
pre=[0]*n
pre[0]=a[0]
for i in range(1,n):
pre[i]=pre[i-1]+a[i]
aux=[]
aux.append(a[0])
for i in range(1,n):
if(pre[i]>m):
temp=pre[i]
count=0
aux.sort()
j=len(aux)-1
while(temp>m):
temp=temp-aux[j]
j=j-1
count=count+1
ans[i]=count
aux.append(a[i])
for i in ans:
print(i, end=' ')
```
| 46,301 | [
0.5390625,
0.059234619140625,
0.14111328125,
0.184326171875,
-0.33154296875,
-0.263671875,
-0.408203125,
-0.038787841796875,
-0.1915283203125,
0.85986328125,
0.90283203125,
0.057525634765625,
0.326904296875,
-1.1015625,
-0.39208984375,
0.21484375,
-0.82763671875,
-0.40283203125,
... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The only difference between easy and hard versions is constraints.
A session has begun at Beland State University. Many students are taking exams.
Polygraph Poligrafovich is going to examine a group of n students. Students will take the exam one-by-one in order from 1-th to n-th. Rules of the exam are following:
* The i-th student randomly chooses a ticket.
* if this ticket is too hard to the student, he doesn't answer and goes home immediately (this process is so fast that it's considered no time elapses). This student fails the exam.
* if the student finds the ticket easy, he spends exactly t_i minutes to pass the exam. After it, he immediately gets a mark and goes home.
Students take the exam in the fixed order, one-by-one, without any interruption. At any moment of time, Polygraph Poligrafovich takes the answer from one student.
The duration of the whole exam for all students is M minutes (max t_i β€ M), so students at the end of the list have a greater possibility to run out of time to pass the exam.
For each student i, you should count the minimum possible number of students who need to fail the exam so the i-th student has enough time to pass the exam.
For each student i, find the answer independently. That is, if when finding the answer for the student i_1 some student j should leave, then while finding the answer for i_2 (i_2>i_1) the student j student does not have to go home.
Input
The first line of the input contains two integers n and M (1 β€ n β€ 100, 1 β€ M β€ 100) β the number of students and the total duration of the exam in minutes, respectively.
The second line of the input contains n integers t_i (1 β€ t_i β€ 100) β time in minutes that i-th student spends to answer to a ticket.
It's guaranteed that all values of t_i are not greater than M.
Output
Print n numbers: the i-th number must be equal to the minimum number of students who have to leave the exam in order to i-th student has enough time to pass the exam.
Examples
Input
7 15
1 2 3 4 5 6 7
Output
0 0 0 0 0 2 3
Input
5 100
80 40 40 40 60
Output
0 1 1 2 3
Note
The explanation for the example 1.
Please note that the sum of the first five exam times does not exceed M=15 (the sum is 1+2+3+4+5=15). Thus, the first five students can pass the exam even if all the students before them also pass the exam. In other words, the first five numbers in the answer are 0.
In order for the 6-th student to pass the exam, it is necessary that at least 2 students must fail it before (for example, the 3-rd and 4-th, then the 6-th will finish its exam in 1+2+5+6=14 minutes, which does not exceed M).
In order for the 7-th student to pass the exam, it is necessary that at least 3 students must fail it before (for example, the 2-nd, 5-th and 6-th, then the 7-th will finish its exam in 1+3+4+7=15 minutes, which does not exceed M).
Tags: greedy, sortings
Correct Solution:
```
#------------------------------warmup----------------------------
import os
import sys
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)
input = lambda: sys.stdin.readline().rstrip("\r\n")
#-------------------game starts now-----------------------------------------------------
import math
n,M=map(int,input().split())
l=list(map(int,input().split()))
k=[0]*100
a=[0]*(n+1)
ans=[]
for i in range(1,n+1):
a[i]+=a[i-1]+l[i-1]
for i in range(1,n+1):
if a[i]<=M:
ans.append(0)
else:
d=l[:i-1]
asi=0
d.sort(reverse=True)
for j in range(len(d)):
if a[i]<=M:
break
else:
a[i]-=d[j]
asi+=1
ans.append(asi)
print(*ans,sep=" ")
```
| 46,302 | [
0.5390625,
0.059234619140625,
0.14111328125,
0.184326171875,
-0.33154296875,
-0.263671875,
-0.408203125,
-0.038787841796875,
-0.1915283203125,
0.85986328125,
0.90283203125,
0.057525634765625,
0.326904296875,
-1.1015625,
-0.39208984375,
0.21484375,
-0.82763671875,
-0.40283203125,
... | 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 constraints.
A session has begun at Beland State University. Many students are taking exams.
Polygraph Poligrafovich is going to examine a group of n students. Students will take the exam one-by-one in order from 1-th to n-th. Rules of the exam are following:
* The i-th student randomly chooses a ticket.
* if this ticket is too hard to the student, he doesn't answer and goes home immediately (this process is so fast that it's considered no time elapses). This student fails the exam.
* if the student finds the ticket easy, he spends exactly t_i minutes to pass the exam. After it, he immediately gets a mark and goes home.
Students take the exam in the fixed order, one-by-one, without any interruption. At any moment of time, Polygraph Poligrafovich takes the answer from one student.
The duration of the whole exam for all students is M minutes (max t_i β€ M), so students at the end of the list have a greater possibility to run out of time to pass the exam.
For each student i, you should count the minimum possible number of students who need to fail the exam so the i-th student has enough time to pass the exam.
For each student i, find the answer independently. That is, if when finding the answer for the student i_1 some student j should leave, then while finding the answer for i_2 (i_2>i_1) the student j student does not have to go home.
Input
The first line of the input contains two integers n and M (1 β€ n β€ 100, 1 β€ M β€ 100) β the number of students and the total duration of the exam in minutes, respectively.
The second line of the input contains n integers t_i (1 β€ t_i β€ 100) β time in minutes that i-th student spends to answer to a ticket.
It's guaranteed that all values of t_i are not greater than M.
Output
Print n numbers: the i-th number must be equal to the minimum number of students who have to leave the exam in order to i-th student has enough time to pass the exam.
Examples
Input
7 15
1 2 3 4 5 6 7
Output
0 0 0 0 0 2 3
Input
5 100
80 40 40 40 60
Output
0 1 1 2 3
Note
The explanation for the example 1.
Please note that the sum of the first five exam times does not exceed M=15 (the sum is 1+2+3+4+5=15). Thus, the first five students can pass the exam even if all the students before them also pass the exam. In other words, the first five numbers in the answer are 0.
In order for the 6-th student to pass the exam, it is necessary that at least 2 students must fail it before (for example, the 3-rd and 4-th, then the 6-th will finish its exam in 1+2+5+6=14 minutes, which does not exceed M).
In order for the 7-th student to pass the exam, it is necessary that at least 3 students must fail it before (for example, the 2-nd, 5-th and 6-th, then the 7-th will finish its exam in 1+3+4+7=15 minutes, which does not exceed M).
Submitted Solution:
```
n = []
t = []
n=list(map(int, input().split()))
t=list(map(int, input().split()))
result =[]
for i in range(len(t)):
number =int(0)
x=t[0:i+1]
re=int(0)
for j in range (i+1):
re+=x[j]
x.pop(i)
while re>n[1]:
re-=max(x)
x.pop(x.index(max(x)))
number+=1
result.append(number)
print (" ".join(str(x) for x in result))
```
Yes
| 46,303 | [
0.64404296875,
0.12115478515625,
0.119873046875,
0.19482421875,
-0.37353515625,
-0.153076171875,
-0.403564453125,
0.0135345458984375,
-0.196533203125,
0.9052734375,
0.81201171875,
0.114013671875,
0.335205078125,
-0.98779296875,
-0.386962890625,
0.1368408203125,
-0.82275390625,
-0.3... | 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 constraints.
A session has begun at Beland State University. Many students are taking exams.
Polygraph Poligrafovich is going to examine a group of n students. Students will take the exam one-by-one in order from 1-th to n-th. Rules of the exam are following:
* The i-th student randomly chooses a ticket.
* if this ticket is too hard to the student, he doesn't answer and goes home immediately (this process is so fast that it's considered no time elapses). This student fails the exam.
* if the student finds the ticket easy, he spends exactly t_i minutes to pass the exam. After it, he immediately gets a mark and goes home.
Students take the exam in the fixed order, one-by-one, without any interruption. At any moment of time, Polygraph Poligrafovich takes the answer from one student.
The duration of the whole exam for all students is M minutes (max t_i β€ M), so students at the end of the list have a greater possibility to run out of time to pass the exam.
For each student i, you should count the minimum possible number of students who need to fail the exam so the i-th student has enough time to pass the exam.
For each student i, find the answer independently. That is, if when finding the answer for the student i_1 some student j should leave, then while finding the answer for i_2 (i_2>i_1) the student j student does not have to go home.
Input
The first line of the input contains two integers n and M (1 β€ n β€ 100, 1 β€ M β€ 100) β the number of students and the total duration of the exam in minutes, respectively.
The second line of the input contains n integers t_i (1 β€ t_i β€ 100) β time in minutes that i-th student spends to answer to a ticket.
It's guaranteed that all values of t_i are not greater than M.
Output
Print n numbers: the i-th number must be equal to the minimum number of students who have to leave the exam in order to i-th student has enough time to pass the exam.
Examples
Input
7 15
1 2 3 4 5 6 7
Output
0 0 0 0 0 2 3
Input
5 100
80 40 40 40 60
Output
0 1 1 2 3
Note
The explanation for the example 1.
Please note that the sum of the first five exam times does not exceed M=15 (the sum is 1+2+3+4+5=15). Thus, the first five students can pass the exam even if all the students before them also pass the exam. In other words, the first five numbers in the answer are 0.
In order for the 6-th student to pass the exam, it is necessary that at least 2 students must fail it before (for example, the 3-rd and 4-th, then the 6-th will finish its exam in 1+2+5+6=14 minutes, which does not exceed M).
In order for the 7-th student to pass the exam, it is necessary that at least 3 students must fail it before (for example, the 2-nd, 5-th and 6-th, then the 7-th will finish its exam in 1+3+4+7=15 minutes, which does not exceed M).
Submitted Solution:
```
from sys import stdin
from collections import defaultdict, Counter
from bisect import bisect_left
from math import sqrt
from heapq import *
###############################################################
def iinput(): return int(stdin.readline())
def minput(): return map(int, stdin.readline().split())
def linput(): return list(map(int, stdin.readline().split()))
###############################################################
t = 1
while t:
t -= 1
n, m = minput()
a = linput()
req = 0
heap = []
heapify(heap)
fail = []
cnt = 0
for i in range(n):
if req + a[i] <= m:
req += a[i]
else:
temp = heap.copy()
cnt = 0
sm = req
while sm + a[i] > m:
sm += heappop(temp)
cnt += 1
req += a[i]
heappush(heap, -1 * a[i])
fail.append(cnt)
print(*fail)
```
Yes
| 46,304 | [
0.64404296875,
0.12115478515625,
0.119873046875,
0.19482421875,
-0.37353515625,
-0.153076171875,
-0.403564453125,
0.0135345458984375,
-0.196533203125,
0.9052734375,
0.81201171875,
0.114013671875,
0.335205078125,
-0.98779296875,
-0.386962890625,
0.1368408203125,
-0.82275390625,
-0.3... | 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 constraints.
A session has begun at Beland State University. Many students are taking exams.
Polygraph Poligrafovich is going to examine a group of n students. Students will take the exam one-by-one in order from 1-th to n-th. Rules of the exam are following:
* The i-th student randomly chooses a ticket.
* if this ticket is too hard to the student, he doesn't answer and goes home immediately (this process is so fast that it's considered no time elapses). This student fails the exam.
* if the student finds the ticket easy, he spends exactly t_i minutes to pass the exam. After it, he immediately gets a mark and goes home.
Students take the exam in the fixed order, one-by-one, without any interruption. At any moment of time, Polygraph Poligrafovich takes the answer from one student.
The duration of the whole exam for all students is M minutes (max t_i β€ M), so students at the end of the list have a greater possibility to run out of time to pass the exam.
For each student i, you should count the minimum possible number of students who need to fail the exam so the i-th student has enough time to pass the exam.
For each student i, find the answer independently. That is, if when finding the answer for the student i_1 some student j should leave, then while finding the answer for i_2 (i_2>i_1) the student j student does not have to go home.
Input
The first line of the input contains two integers n and M (1 β€ n β€ 100, 1 β€ M β€ 100) β the number of students and the total duration of the exam in minutes, respectively.
The second line of the input contains n integers t_i (1 β€ t_i β€ 100) β time in minutes that i-th student spends to answer to a ticket.
It's guaranteed that all values of t_i are not greater than M.
Output
Print n numbers: the i-th number must be equal to the minimum number of students who have to leave the exam in order to i-th student has enough time to pass the exam.
Examples
Input
7 15
1 2 3 4 5 6 7
Output
0 0 0 0 0 2 3
Input
5 100
80 40 40 40 60
Output
0 1 1 2 3
Note
The explanation for the example 1.
Please note that the sum of the first five exam times does not exceed M=15 (the sum is 1+2+3+4+5=15). Thus, the first five students can pass the exam even if all the students before them also pass the exam. In other words, the first five numbers in the answer are 0.
In order for the 6-th student to pass the exam, it is necessary that at least 2 students must fail it before (for example, the 3-rd and 4-th, then the 6-th will finish its exam in 1+2+5+6=14 minutes, which does not exceed M).
In order for the 7-th student to pass the exam, it is necessary that at least 3 students must fail it before (for example, the 2-nd, 5-th and 6-th, then the 7-th will finish its exam in 1+3+4+7=15 minutes, which does not exceed M).
Submitted Solution:
```
import bisect
a, b = map(int, input().split())
A = list(map(int, input().split()))
B = []
IN = []
kk = 0
for i in range(len(A)):
#print(kk)
kkl = int(kk) + A[i]
j = 0
while kkl > b and j < len(B):
kkl -= B[- j - 1]
j += 1
IN.append(j)
bisect.insort(B, A[i])
kk += A[i]
print(*IN)
```
Yes
| 46,305 | [
0.64404296875,
0.12115478515625,
0.119873046875,
0.19482421875,
-0.37353515625,
-0.153076171875,
-0.403564453125,
0.0135345458984375,
-0.196533203125,
0.9052734375,
0.81201171875,
0.114013671875,
0.335205078125,
-0.98779296875,
-0.386962890625,
0.1368408203125,
-0.82275390625,
-0.3... | 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 constraints.
A session has begun at Beland State University. Many students are taking exams.
Polygraph Poligrafovich is going to examine a group of n students. Students will take the exam one-by-one in order from 1-th to n-th. Rules of the exam are following:
* The i-th student randomly chooses a ticket.
* if this ticket is too hard to the student, he doesn't answer and goes home immediately (this process is so fast that it's considered no time elapses). This student fails the exam.
* if the student finds the ticket easy, he spends exactly t_i minutes to pass the exam. After it, he immediately gets a mark and goes home.
Students take the exam in the fixed order, one-by-one, without any interruption. At any moment of time, Polygraph Poligrafovich takes the answer from one student.
The duration of the whole exam for all students is M minutes (max t_i β€ M), so students at the end of the list have a greater possibility to run out of time to pass the exam.
For each student i, you should count the minimum possible number of students who need to fail the exam so the i-th student has enough time to pass the exam.
For each student i, find the answer independently. That is, if when finding the answer for the student i_1 some student j should leave, then while finding the answer for i_2 (i_2>i_1) the student j student does not have to go home.
Input
The first line of the input contains two integers n and M (1 β€ n β€ 100, 1 β€ M β€ 100) β the number of students and the total duration of the exam in minutes, respectively.
The second line of the input contains n integers t_i (1 β€ t_i β€ 100) β time in minutes that i-th student spends to answer to a ticket.
It's guaranteed that all values of t_i are not greater than M.
Output
Print n numbers: the i-th number must be equal to the minimum number of students who have to leave the exam in order to i-th student has enough time to pass the exam.
Examples
Input
7 15
1 2 3 4 5 6 7
Output
0 0 0 0 0 2 3
Input
5 100
80 40 40 40 60
Output
0 1 1 2 3
Note
The explanation for the example 1.
Please note that the sum of the first five exam times does not exceed M=15 (the sum is 1+2+3+4+5=15). Thus, the first five students can pass the exam even if all the students before them also pass the exam. In other words, the first five numbers in the answer are 0.
In order for the 6-th student to pass the exam, it is necessary that at least 2 students must fail it before (for example, the 3-rd and 4-th, then the 6-th will finish its exam in 1+2+5+6=14 minutes, which does not exceed M).
In order for the 7-th student to pass the exam, it is necessary that at least 3 students must fail it before (for example, the 2-nd, 5-th and 6-th, then the 7-th will finish its exam in 1+3+4+7=15 minutes, which does not exceed M).
Submitted Solution:
```
n, m = map(int,input().split())
a = list(map(int,input().split()))
b = []
sum1 = 0
ans = []
for i in range(n):
sum1 = sum(a[:i + 1])
cnt = 0
while(sum1 > m):
cnt+=1
sum1 -= b[-cnt]
ans.append(cnt)
b.append(a[i])
b.sort()
print(*ans)
```
Yes
| 46,306 | [
0.64404296875,
0.12115478515625,
0.119873046875,
0.19482421875,
-0.37353515625,
-0.153076171875,
-0.403564453125,
0.0135345458984375,
-0.196533203125,
0.9052734375,
0.81201171875,
0.114013671875,
0.335205078125,
-0.98779296875,
-0.386962890625,
0.1368408203125,
-0.82275390625,
-0.3... | 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 constraints.
A session has begun at Beland State University. Many students are taking exams.
Polygraph Poligrafovich is going to examine a group of n students. Students will take the exam one-by-one in order from 1-th to n-th. Rules of the exam are following:
* The i-th student randomly chooses a ticket.
* if this ticket is too hard to the student, he doesn't answer and goes home immediately (this process is so fast that it's considered no time elapses). This student fails the exam.
* if the student finds the ticket easy, he spends exactly t_i minutes to pass the exam. After it, he immediately gets a mark and goes home.
Students take the exam in the fixed order, one-by-one, without any interruption. At any moment of time, Polygraph Poligrafovich takes the answer from one student.
The duration of the whole exam for all students is M minutes (max t_i β€ M), so students at the end of the list have a greater possibility to run out of time to pass the exam.
For each student i, you should count the minimum possible number of students who need to fail the exam so the i-th student has enough time to pass the exam.
For each student i, find the answer independently. That is, if when finding the answer for the student i_1 some student j should leave, then while finding the answer for i_2 (i_2>i_1) the student j student does not have to go home.
Input
The first line of the input contains two integers n and M (1 β€ n β€ 100, 1 β€ M β€ 100) β the number of students and the total duration of the exam in minutes, respectively.
The second line of the input contains n integers t_i (1 β€ t_i β€ 100) β time in minutes that i-th student spends to answer to a ticket.
It's guaranteed that all values of t_i are not greater than M.
Output
Print n numbers: the i-th number must be equal to the minimum number of students who have to leave the exam in order to i-th student has enough time to pass the exam.
Examples
Input
7 15
1 2 3 4 5 6 7
Output
0 0 0 0 0 2 3
Input
5 100
80 40 40 40 60
Output
0 1 1 2 3
Note
The explanation for the example 1.
Please note that the sum of the first five exam times does not exceed M=15 (the sum is 1+2+3+4+5=15). Thus, the first five students can pass the exam even if all the students before them also pass the exam. In other words, the first five numbers in the answer are 0.
In order for the 6-th student to pass the exam, it is necessary that at least 2 students must fail it before (for example, the 3-rd and 4-th, then the 6-th will finish its exam in 1+2+5+6=14 minutes, which does not exceed M).
In order for the 7-th student to pass the exam, it is necessary that at least 3 students must fail it before (for example, the 2-nd, 5-th and 6-th, then the 7-th will finish its exam in 1+3+4+7=15 minutes, which does not exceed M).
Submitted Solution:
```
n,m = map(int, input().split())
iss = list(map(int, input().split()))
ii2 = []
for i in range(len(iss)):
iss3 = iss[0:i+1]
iss3.sort()
iss3.reverse()
k = 0
ii = 0
for j in range(i+1):
k+= int(iss[j])
if k <= m:
ii2.append('0')
else:
while k > m:
k -= int(iss3[0])
iss3.pop(0)
ii+=1
ii2.append(str(ii))
print(' '.join(ii2))
```
No
| 46,307 | [
0.64404296875,
0.12115478515625,
0.119873046875,
0.19482421875,
-0.37353515625,
-0.153076171875,
-0.403564453125,
0.0135345458984375,
-0.196533203125,
0.9052734375,
0.81201171875,
0.114013671875,
0.335205078125,
-0.98779296875,
-0.386962890625,
0.1368408203125,
-0.82275390625,
-0.3... | 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 constraints.
A session has begun at Beland State University. Many students are taking exams.
Polygraph Poligrafovich is going to examine a group of n students. Students will take the exam one-by-one in order from 1-th to n-th. Rules of the exam are following:
* The i-th student randomly chooses a ticket.
* if this ticket is too hard to the student, he doesn't answer and goes home immediately (this process is so fast that it's considered no time elapses). This student fails the exam.
* if the student finds the ticket easy, he spends exactly t_i minutes to pass the exam. After it, he immediately gets a mark and goes home.
Students take the exam in the fixed order, one-by-one, without any interruption. At any moment of time, Polygraph Poligrafovich takes the answer from one student.
The duration of the whole exam for all students is M minutes (max t_i β€ M), so students at the end of the list have a greater possibility to run out of time to pass the exam.
For each student i, you should count the minimum possible number of students who need to fail the exam so the i-th student has enough time to pass the exam.
For each student i, find the answer independently. That is, if when finding the answer for the student i_1 some student j should leave, then while finding the answer for i_2 (i_2>i_1) the student j student does not have to go home.
Input
The first line of the input contains two integers n and M (1 β€ n β€ 100, 1 β€ M β€ 100) β the number of students and the total duration of the exam in minutes, respectively.
The second line of the input contains n integers t_i (1 β€ t_i β€ 100) β time in minutes that i-th student spends to answer to a ticket.
It's guaranteed that all values of t_i are not greater than M.
Output
Print n numbers: the i-th number must be equal to the minimum number of students who have to leave the exam in order to i-th student has enough time to pass the exam.
Examples
Input
7 15
1 2 3 4 5 6 7
Output
0 0 0 0 0 2 3
Input
5 100
80 40 40 40 60
Output
0 1 1 2 3
Note
The explanation for the example 1.
Please note that the sum of the first five exam times does not exceed M=15 (the sum is 1+2+3+4+5=15). Thus, the first five students can pass the exam even if all the students before them also pass the exam. In other words, the first five numbers in the answer are 0.
In order for the 6-th student to pass the exam, it is necessary that at least 2 students must fail it before (for example, the 3-rd and 4-th, then the 6-th will finish its exam in 1+2+5+6=14 minutes, which does not exceed M).
In order for the 7-th student to pass the exam, it is necessary that at least 3 students must fail it before (for example, the 2-nd, 5-th and 6-th, then the 7-th will finish its exam in 1+3+4+7=15 minutes, which does not exceed M).
Submitted Solution:
```
import heapq
n,m=map(int,input().split())
a=list(map(int,input().split()))
ans=[]
b=[a[0]]
for i in range(1,n):
b.append(b[-1]+a[i])
c=[]
heapq.heapify(c)
l=0
k=0
for i in range(n):
if b[i]>m:
r=b[i]-m
while r>l:
l+=(heapq.heappop(c))*-1
k+=1
ans.append(k)
else:
ans.append(0)
heapq.heappush(c,a[i]*-1)
print(*ans)
```
No
| 46,308 | [
0.64404296875,
0.12115478515625,
0.119873046875,
0.19482421875,
-0.37353515625,
-0.153076171875,
-0.403564453125,
0.0135345458984375,
-0.196533203125,
0.9052734375,
0.81201171875,
0.114013671875,
0.335205078125,
-0.98779296875,
-0.386962890625,
0.1368408203125,
-0.82275390625,
-0.3... | 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 constraints.
A session has begun at Beland State University. Many students are taking exams.
Polygraph Poligrafovich is going to examine a group of n students. Students will take the exam one-by-one in order from 1-th to n-th. Rules of the exam are following:
* The i-th student randomly chooses a ticket.
* if this ticket is too hard to the student, he doesn't answer and goes home immediately (this process is so fast that it's considered no time elapses). This student fails the exam.
* if the student finds the ticket easy, he spends exactly t_i minutes to pass the exam. After it, he immediately gets a mark and goes home.
Students take the exam in the fixed order, one-by-one, without any interruption. At any moment of time, Polygraph Poligrafovich takes the answer from one student.
The duration of the whole exam for all students is M minutes (max t_i β€ M), so students at the end of the list have a greater possibility to run out of time to pass the exam.
For each student i, you should count the minimum possible number of students who need to fail the exam so the i-th student has enough time to pass the exam.
For each student i, find the answer independently. That is, if when finding the answer for the student i_1 some student j should leave, then while finding the answer for i_2 (i_2>i_1) the student j student does not have to go home.
Input
The first line of the input contains two integers n and M (1 β€ n β€ 100, 1 β€ M β€ 100) β the number of students and the total duration of the exam in minutes, respectively.
The second line of the input contains n integers t_i (1 β€ t_i β€ 100) β time in minutes that i-th student spends to answer to a ticket.
It's guaranteed that all values of t_i are not greater than M.
Output
Print n numbers: the i-th number must be equal to the minimum number of students who have to leave the exam in order to i-th student has enough time to pass the exam.
Examples
Input
7 15
1 2 3 4 5 6 7
Output
0 0 0 0 0 2 3
Input
5 100
80 40 40 40 60
Output
0 1 1 2 3
Note
The explanation for the example 1.
Please note that the sum of the first five exam times does not exceed M=15 (the sum is 1+2+3+4+5=15). Thus, the first five students can pass the exam even if all the students before them also pass the exam. In other words, the first five numbers in the answer are 0.
In order for the 6-th student to pass the exam, it is necessary that at least 2 students must fail it before (for example, the 3-rd and 4-th, then the 6-th will finish its exam in 1+2+5+6=14 minutes, which does not exceed M).
In order for the 7-th student to pass the exam, it is necessary that at least 3 students must fail it before (for example, the 2-nd, 5-th and 6-th, then the 7-th will finish its exam in 1+3+4+7=15 minutes, which does not exceed M).
Submitted Solution:
```
inp = list(map(int,input().split()))
t=inp[1]
inp = list(map(int,input().split()))
l=[]
for i in range(1,len(inp)+1):
l.append(sum(inp[:i]))
for i in range(len(l)):
if(l[i]<t):
print (0,end=" ")
else:
k=l[i]-t
j=inp[:i+1]
j.sort(reverse=True)
sumi=0
count=0
p=0
while(sumi<k):
sumi=sumi+j[count]
count+=1
print (count,end=" ")
```
No
| 46,309 | [
0.64404296875,
0.12115478515625,
0.119873046875,
0.19482421875,
-0.37353515625,
-0.153076171875,
-0.403564453125,
0.0135345458984375,
-0.196533203125,
0.9052734375,
0.81201171875,
0.114013671875,
0.335205078125,
-0.98779296875,
-0.386962890625,
0.1368408203125,
-0.82275390625,
-0.3... | 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 constraints.
A session has begun at Beland State University. Many students are taking exams.
Polygraph Poligrafovich is going to examine a group of n students. Students will take the exam one-by-one in order from 1-th to n-th. Rules of the exam are following:
* The i-th student randomly chooses a ticket.
* if this ticket is too hard to the student, he doesn't answer and goes home immediately (this process is so fast that it's considered no time elapses). This student fails the exam.
* if the student finds the ticket easy, he spends exactly t_i minutes to pass the exam. After it, he immediately gets a mark and goes home.
Students take the exam in the fixed order, one-by-one, without any interruption. At any moment of time, Polygraph Poligrafovich takes the answer from one student.
The duration of the whole exam for all students is M minutes (max t_i β€ M), so students at the end of the list have a greater possibility to run out of time to pass the exam.
For each student i, you should count the minimum possible number of students who need to fail the exam so the i-th student has enough time to pass the exam.
For each student i, find the answer independently. That is, if when finding the answer for the student i_1 some student j should leave, then while finding the answer for i_2 (i_2>i_1) the student j student does not have to go home.
Input
The first line of the input contains two integers n and M (1 β€ n β€ 100, 1 β€ M β€ 100) β the number of students and the total duration of the exam in minutes, respectively.
The second line of the input contains n integers t_i (1 β€ t_i β€ 100) β time in minutes that i-th student spends to answer to a ticket.
It's guaranteed that all values of t_i are not greater than M.
Output
Print n numbers: the i-th number must be equal to the minimum number of students who have to leave the exam in order to i-th student has enough time to pass the exam.
Examples
Input
7 15
1 2 3 4 5 6 7
Output
0 0 0 0 0 2 3
Input
5 100
80 40 40 40 60
Output
0 1 1 2 3
Note
The explanation for the example 1.
Please note that the sum of the first five exam times does not exceed M=15 (the sum is 1+2+3+4+5=15). Thus, the first five students can pass the exam even if all the students before them also pass the exam. In other words, the first five numbers in the answer are 0.
In order for the 6-th student to pass the exam, it is necessary that at least 2 students must fail it before (for example, the 3-rd and 4-th, then the 6-th will finish its exam in 1+2+5+6=14 minutes, which does not exceed M).
In order for the 7-th student to pass the exam, it is necessary that at least 3 students must fail it before (for example, the 2-nd, 5-th and 6-th, then the 7-th will finish its exam in 1+3+4+7=15 minutes, which does not exceed M).
Submitted Solution:
```
from sys import stdin, stdout, maxsize as mxs
from math import floor, gcd, fabs, factorial, fmod, sqrt, inf, log
from collections import defaultdict as dd, deque
from heapq import merge, heapify, heappop, heappush, nsmallest
from bisect import bisect_left as bl, bisect_right as br, bisect
from typing import Counter
from itertools import accumulate
mod = pow(10, 9) + 7
mod2 = 998244353
def inp(): return stdin.readline().strip()
def iinp(): return int(inp())
def out(var, end="\n"): stdout.write(str(var)+"\n")
def outa(*var, end="\n"): stdout.write(' '.join(map(str, var)) + end)
def lmp(): return list(mp())
def mp(): return map(int, inp().split())
def smp(): return map(str, inp().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(m, val) for j in range(n)]
def remadd(x, y): return 1 if x%y else 0
def ceil(a,b): return (a+b-1)//b
def isprime(x):
if x<=1: return False
if x in (2, 3): return True
if x%2 == 0: return False
for i in range(3, int(sqrt(x))+1, 2):
if x%i == 0: return False
return True
class MaxHeap:
def __init__(self, maxsize):
self.maxsize = maxsize
self.size = 0
self.Heap = [0] * (self.maxsize + 1)
self.Heap[0] = mxs
self.FRONT = 1
# Function to return the position of
# parent for the node currently
# at pos
def parent(self, pos):
return pos // 2
# Function to return the position of
# the left child for the node currently
# at pos
def leftChild(self, pos):
return 2 * pos
# Function to return the position of
# the right child for the node currently
# at pos
def rightChild(self, pos):
return (2 * pos) + 1
# Function that returns true if the passed
# node is a leaf node
def isLeaf(self, pos):
if pos >= (self.size//2) and pos <= self.size:
return True
return False
# Function to swap two nodes of the heap
def swap(self, fpos, spos):
self.Heap[fpos], self.Heap[spos] = (self.Heap[spos],
self.Heap[fpos])
# Function to heapify the node at pos
def maxHeapify(self, pos):
# If the node is a non-leaf node and smaller
# than any of its child
if not self.isLeaf(pos):
if (self.Heap[pos] < self.Heap[self.leftChild(pos)] or
self.Heap[pos] < self.Heap[self.rightChild(pos)]):
# Swap with the left child and heapify
# the left child
if (self.Heap[self.leftChild(pos)] >
self.Heap[self.rightChild(pos)]):
self.swap(pos, self.leftChild(pos))
self.maxHeapify(self.leftChild(pos))
# Swap with the right child and heapify
# the right child
else:
self.swap(pos, self.rightChild(pos))
self.maxHeapify(self.rightChild(pos))
# Function to insert a node into the heap
def insert(self, element):
if self.size >= self.maxsize:
return
self.size += 1
self.Heap[self.size] = element
current = self.size
while (self.Heap[current] >
self.Heap[self.parent(current)]):
self.swap(current, self.parent(current))
current = self.parent(current)
# Function to print the contents of the heap
def Print(self):
for i in range(1, (self.size // 2) + 1):
print(" PARENT : " + str(self.Heap[i]) +
" LEFT CHILD : " + str(self.Heap[2 * i]) +
" RIGHT CHILD : " + str(self.Heap[2 * i + 1]))
# Function to remove and return the maximum
# element from the heap
def extractMax(self):
popped = self.Heap[self.FRONT]
self.Heap[self.FRONT] = self.Heap[self.size]
self.size -= 1
self.maxHeapify(self.FRONT)
return popped
n, k = mp()
arr = lmp()
ansl = []
ml = MaxHeap(2*n)
s = 0
c = 0
for i in range(n):
pl = []
ts = 0
while s>k-arr[i]:
x = ml.extractMax()
s -= x
c += 1
pl.append(x)
ts += x
ml.insert(arr[i])
s += arr[i]
for j in pl: ml.insert(j)
s += ts
ansl.append(c)
c = 0
print(*ansl)
```
No
| 46,310 | [
0.64404296875,
0.12115478515625,
0.119873046875,
0.19482421875,
-0.37353515625,
-0.153076171875,
-0.403564453125,
0.0135345458984375,
-0.196533203125,
0.9052734375,
0.81201171875,
0.114013671875,
0.335205078125,
-0.98779296875,
-0.386962890625,
0.1368408203125,
-0.82275390625,
-0.3... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The only difference between easy and hard versions is that you should complete all the projects in easy version but this is not necessary in hard version.
Polycarp is a very famous freelancer. His current rating is r units.
Some very rich customers asked him to complete some projects for their companies. To complete the i-th project, Polycarp needs to have at least a_i units of rating; after he completes this project, his rating will change by b_i (his rating will increase or decrease by b_i) (b_i can be positive or negative). Polycarp's rating should not fall below zero because then people won't trust such a low rated freelancer.
Polycarp can choose the order in which he completes projects. Furthermore, he can even skip some projects altogether.
To gain more experience (and money, of course) Polycarp wants to choose the subset of projects having maximum possible size and the order in which he will complete them, so he has enough rating before starting each project, and has non-negative rating after completing each project.
Your task is to calculate the maximum possible size of such subset of projects.
Input
The first line of the input contains two integers n and r (1 β€ n β€ 100, 1 β€ r β€ 30000) β the number of projects and the initial rating of Polycarp, respectively.
The next n lines contain projects, one per line. The i-th project is represented as a pair of integers a_i and b_i (1 β€ a_i β€ 30000, -300 β€ b_i β€ 300) β the rating required to complete the i-th project and the rating change after the project completion.
Output
Print one integer β the size of the maximum possible subset (possibly, empty) of projects Polycarp can choose.
Examples
Input
3 4
4 6
10 -2
8 -1
Output
3
Input
5 20
45 -6
34 -15
10 34
1 27
40 -45
Output
5
Input
3 2
300 -300
1 299
1 123
Output
3
Tags: dp, greedy
Correct Solution:
```
# TAIWAN NUMBER ONE!!!!!!!!!!!!!!!!!!!
# TAIWAN NUMBER ONE!!!!!!!!!!!!!!!!!!!
# TAIWAN NUMBER ONE!!!!!!!!!!!!!!!!!!!
from sys import stdin, stdout
import math
import copy
#T = int(input())
#N = int(input())
#print(N)
N,r = [int(x) for x in stdin.readline().split()]
#arr = [int(x) for x in stdin.readline().split()]
visited = [0]*N
a = [0]*N
b = [0]*N
pos = 0
dp = {}
for i in range(N):
arr = [int(x) for x in stdin.readline().split()]
a[i] = arr[0]
b[i] = arr[1]
if b[i]>=0:
pos += 1
valid = 0
for i in range(pos):
idx = -1
start = 0
gain = -50000
for j in range(N):
# find available and largest gain
# if gain tie, find largest start r
if visited[j]==1 or b[j]<0:
continue
if b[j]>gain and r>=a[j]:
gain = b[j]
idx = j
start = a[j]
elif b[j]==gain and r>=a[j]:
if a[j]>start:
idx = j
start = a[j]
if idx==-1:
break
else:
visited[idx] = 1
r += b[idx]
valid = i+1
#print(idx,r)
dp[r] = valid
tmp = []
for i in range(N):
if visited[i]==1 or b[i]>=0:
continue
tmp.append((a[i],b[i],i))
tmp.sort(key=lambda e: (e[0]+e[1],e[0]),reverse=True)
#print(dp)
for i in range(len(tmp)):
dp_tmp = copy.deepcopy(dp)
for threshold in dp:
if threshold>=tmp[i][0]:
new_r = threshold + tmp[i][1]
if new_r in dp_tmp:
dp_tmp[new_r] = max(dp[new_r],dp[threshold]+1)
else:
dp_tmp[new_r] = dp[threshold]+1
#print(dp_tmp)
dp = dp_tmp
res = 0
#print(dp)
for key in dp:
if key>=0:
res = max(res,dp[key])
print(res)
```
| 46,311 | [
0.40234375,
0.131103515625,
0.08563232421875,
0.0020542144775390625,
-0.5380859375,
-0.6337890625,
-0.39208984375,
0.243408203125,
0.1053466796875,
0.463623046875,
1.0927734375,
-0.09344482421875,
0.314208984375,
-0.5703125,
-0.434326171875,
-0.0401611328125,
-0.59814453125,
-0.711... | 24 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.