message stringlengths 2 43.5k | message_type stringclasses 2 values | message_id int64 0 1 | conversation_id int64 853 107k | cluster float64 24 24 | __index_level_0__ int64 1.71k 214k |
|---|---|---|---|---|---|
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarpus has been working in the analytic department of the "F.R.A.U.D." company for as much as n days. Right now his task is to make a series of reports about the company's performance for the last n days. We know that the main information in a day report is value ai, the company's profit on the i-th day. If ai is negative, then the company suffered losses on the i-th day.
Polycarpus should sort the daily reports into folders. Each folder should include data on the company's performance for several consecutive days. Of course, the information on each of the n days should be exactly in one folder. Thus, Polycarpus puts information on the first few days in the first folder. The information on the several following days goes to the second folder, and so on.
It is known that the boss reads one daily report folder per day. If one folder has three or more reports for the days in which the company suffered losses (ai < 0), he loses his temper and his wrath is terrible.
Therefore, Polycarpus wants to prepare the folders so that none of them contains information on three or more days with the loss, and the number of folders is minimal.
Write a program that, given sequence ai, will print the minimum number of folders.
Input
The first line contains integer n (1 β€ n β€ 100), n is the number of days. The second line contains a sequence of integers a1, a2, ..., an (|ai| β€ 100), where ai means the company profit on the i-th day. It is possible that the company has no days with the negative ai.
Output
Print an integer k β the required minimum number of folders. In the second line print a sequence of integers b1, b2, ..., bk, where bj is the number of day reports in the j-th folder.
If there are multiple ways to sort the reports into k days, print any of them.
Examples
Input
11
1 2 3 -4 -5 -6 5 -5 -6 -7 6
Output
3
5 3 3
Input
5
0 -1 100 -1 0
Output
1
5
Note
Here goes a way to sort the reports from the first sample into three folders:
1 2 3 -4 -5 | -6 5 -5 | -6 -7 6
In the second sample you can put all five reports in one folder. | instruction | 0 | 97,268 | 24 | 194,536 |
Tags: greedy
Correct Solution:
```
n = input()
s = input().split(" ")
rugi, jumlah, berkas = 0, 0, []
for j, i in enumerate(s):
if int(i) < 0:
rugi += 1
if rugi == 3:
rugi = 1
berkas.append(str(jumlah))
jumlah = 1
else:
jumlah += 1
else:
jumlah += 1
if j == len(s)-1:
berkas.append(str(jumlah))
print(len(berkas), " ".join(berkas), sep='\n')
``` | output | 1 | 97,268 | 24 | 194,537 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarpus has been working in the analytic department of the "F.R.A.U.D." company for as much as n days. Right now his task is to make a series of reports about the company's performance for the last n days. We know that the main information in a day report is value ai, the company's profit on the i-th day. If ai is negative, then the company suffered losses on the i-th day.
Polycarpus should sort the daily reports into folders. Each folder should include data on the company's performance for several consecutive days. Of course, the information on each of the n days should be exactly in one folder. Thus, Polycarpus puts information on the first few days in the first folder. The information on the several following days goes to the second folder, and so on.
It is known that the boss reads one daily report folder per day. If one folder has three or more reports for the days in which the company suffered losses (ai < 0), he loses his temper and his wrath is terrible.
Therefore, Polycarpus wants to prepare the folders so that none of them contains information on three or more days with the loss, and the number of folders is minimal.
Write a program that, given sequence ai, will print the minimum number of folders.
Input
The first line contains integer n (1 β€ n β€ 100), n is the number of days. The second line contains a sequence of integers a1, a2, ..., an (|ai| β€ 100), where ai means the company profit on the i-th day. It is possible that the company has no days with the negative ai.
Output
Print an integer k β the required minimum number of folders. In the second line print a sequence of integers b1, b2, ..., bk, where bj is the number of day reports in the j-th folder.
If there are multiple ways to sort the reports into k days, print any of them.
Examples
Input
11
1 2 3 -4 -5 -6 5 -5 -6 -7 6
Output
3
5 3 3
Input
5
0 -1 100 -1 0
Output
1
5
Note
Here goes a way to sort the reports from the first sample into three folders:
1 2 3 -4 -5 | -6 5 -5 | -6 -7 6
In the second sample you can put all five reports in one folder. | instruction | 0 | 97,269 | 24 | 194,538 |
Tags: greedy
Correct Solution:
```
n = int(input())
dig = list( map(int, input().split() ))
flag = 0
index = 0
folder = []
for i in range(n):
folder.append( 0 )
for i in dig:
if i<0:
flag+=1
if flag == 3:
flag = 1
index +=1
folder[index]+=1
print( index+1 )
for i in range(index+1):
print(folder[i], end = " ")
``` | output | 1 | 97,269 | 24 | 194,539 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarpus has been working in the analytic department of the "F.R.A.U.D." company for as much as n days. Right now his task is to make a series of reports about the company's performance for the last n days. We know that the main information in a day report is value ai, the company's profit on the i-th day. If ai is negative, then the company suffered losses on the i-th day.
Polycarpus should sort the daily reports into folders. Each folder should include data on the company's performance for several consecutive days. Of course, the information on each of the n days should be exactly in one folder. Thus, Polycarpus puts information on the first few days in the first folder. The information on the several following days goes to the second folder, and so on.
It is known that the boss reads one daily report folder per day. If one folder has three or more reports for the days in which the company suffered losses (ai < 0), he loses his temper and his wrath is terrible.
Therefore, Polycarpus wants to prepare the folders so that none of them contains information on three or more days with the loss, and the number of folders is minimal.
Write a program that, given sequence ai, will print the minimum number of folders.
Input
The first line contains integer n (1 β€ n β€ 100), n is the number of days. The second line contains a sequence of integers a1, a2, ..., an (|ai| β€ 100), where ai means the company profit on the i-th day. It is possible that the company has no days with the negative ai.
Output
Print an integer k β the required minimum number of folders. In the second line print a sequence of integers b1, b2, ..., bk, where bj is the number of day reports in the j-th folder.
If there are multiple ways to sort the reports into k days, print any of them.
Examples
Input
11
1 2 3 -4 -5 -6 5 -5 -6 -7 6
Output
3
5 3 3
Input
5
0 -1 100 -1 0
Output
1
5
Note
Here goes a way to sort the reports from the first sample into three folders:
1 2 3 -4 -5 | -6 5 -5 | -6 -7 6
In the second sample you can put all five reports in one folder. | instruction | 0 | 97,270 | 24 | 194,540 |
Tags: greedy
Correct Solution:
```
n=eval(input())
import math
l=list(map(int,input().split()))
i=0
c=0
while(i<n):
if(l[i]<0):
c+=1
i+=1
d=math.ceil(c/2)
if(c==0 or c==1):
print(1)
else:
print(d)
c=0
i=0
s=0
while(i<n):
if(l[i]<0):
c+=1
else:
s+=1
if(c==3):
print(s+c-1,end=" ")
c=1
s=0
i+=1
if(s+c!=0):
print(s+c,end=" ")
``` | output | 1 | 97,270 | 24 | 194,541 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarpus has been working in the analytic department of the "F.R.A.U.D." company for as much as n days. Right now his task is to make a series of reports about the company's performance for the last n days. We know that the main information in a day report is value ai, the company's profit on the i-th day. If ai is negative, then the company suffered losses on the i-th day.
Polycarpus should sort the daily reports into folders. Each folder should include data on the company's performance for several consecutive days. Of course, the information on each of the n days should be exactly in one folder. Thus, Polycarpus puts information on the first few days in the first folder. The information on the several following days goes to the second folder, and so on.
It is known that the boss reads one daily report folder per day. If one folder has three or more reports for the days in which the company suffered losses (ai < 0), he loses his temper and his wrath is terrible.
Therefore, Polycarpus wants to prepare the folders so that none of them contains information on three or more days with the loss, and the number of folders is minimal.
Write a program that, given sequence ai, will print the minimum number of folders.
Input
The first line contains integer n (1 β€ n β€ 100), n is the number of days. The second line contains a sequence of integers a1, a2, ..., an (|ai| β€ 100), where ai means the company profit on the i-th day. It is possible that the company has no days with the negative ai.
Output
Print an integer k β the required minimum number of folders. In the second line print a sequence of integers b1, b2, ..., bk, where bj is the number of day reports in the j-th folder.
If there are multiple ways to sort the reports into k days, print any of them.
Examples
Input
11
1 2 3 -4 -5 -6 5 -5 -6 -7 6
Output
3
5 3 3
Input
5
0 -1 100 -1 0
Output
1
5
Note
Here goes a way to sort the reports from the first sample into three folders:
1 2 3 -4 -5 | -6 5 -5 | -6 -7 6
In the second sample you can put all five reports in one folder. | instruction | 0 | 97,271 | 24 | 194,542 |
Tags: greedy
Correct Solution:
```
N = int( input() )
A = list( map( int, input().split() ) )
ans = []
ptr = 0
while ptr < N:
s = 0
nxt = ptr
while nxt < N and s + ( A[ nxt ] < 0 ) <= 2:
s += ( A[ nxt ] < 0 )
nxt += 1
ans.append( nxt - ptr )
ptr = nxt
print( len( ans ) )
print( * ans )
``` | output | 1 | 97,271 | 24 | 194,543 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarpus has been working in the analytic department of the "F.R.A.U.D." company for as much as n days. Right now his task is to make a series of reports about the company's performance for the last n days. We know that the main information in a day report is value ai, the company's profit on the i-th day. If ai is negative, then the company suffered losses on the i-th day.
Polycarpus should sort the daily reports into folders. Each folder should include data on the company's performance for several consecutive days. Of course, the information on each of the n days should be exactly in one folder. Thus, Polycarpus puts information on the first few days in the first folder. The information on the several following days goes to the second folder, and so on.
It is known that the boss reads one daily report folder per day. If one folder has three or more reports for the days in which the company suffered losses (ai < 0), he loses his temper and his wrath is terrible.
Therefore, Polycarpus wants to prepare the folders so that none of them contains information on three or more days with the loss, and the number of folders is minimal.
Write a program that, given sequence ai, will print the minimum number of folders.
Input
The first line contains integer n (1 β€ n β€ 100), n is the number of days. The second line contains a sequence of integers a1, a2, ..., an (|ai| β€ 100), where ai means the company profit on the i-th day. It is possible that the company has no days with the negative ai.
Output
Print an integer k β the required minimum number of folders. In the second line print a sequence of integers b1, b2, ..., bk, where bj is the number of day reports in the j-th folder.
If there are multiple ways to sort the reports into k days, print any of them.
Examples
Input
11
1 2 3 -4 -5 -6 5 -5 -6 -7 6
Output
3
5 3 3
Input
5
0 -1 100 -1 0
Output
1
5
Note
Here goes a way to sort the reports from the first sample into three folders:
1 2 3 -4 -5 | -6 5 -5 | -6 -7 6
In the second sample you can put all five reports in one folder. | instruction | 0 | 97,272 | 24 | 194,544 |
Tags: greedy
Correct Solution:
```
import sys
import math
n = int(sys.stdin.readline())
an = [int(x) for x in (sys.stdin.readline()).split()]
res = 0
v = []
p = 0
k = 0
for i in an:
if(i < 0):
if(p < 2):
p += 1
else:
p = 1
v.append(str(k))
res += 1
k = 0
k += 1
if(k != 0):
res += 1
v.append(str(k))
print(res)
print(" ".join(v))
``` | output | 1 | 97,272 | 24 | 194,545 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarpus has been working in the analytic department of the "F.R.A.U.D." company for as much as n days. Right now his task is to make a series of reports about the company's performance for the last n days. We know that the main information in a day report is value ai, the company's profit on the i-th day. If ai is negative, then the company suffered losses on the i-th day.
Polycarpus should sort the daily reports into folders. Each folder should include data on the company's performance for several consecutive days. Of course, the information on each of the n days should be exactly in one folder. Thus, Polycarpus puts information on the first few days in the first folder. The information on the several following days goes to the second folder, and so on.
It is known that the boss reads one daily report folder per day. If one folder has three or more reports for the days in which the company suffered losses (ai < 0), he loses his temper and his wrath is terrible.
Therefore, Polycarpus wants to prepare the folders so that none of them contains information on three or more days with the loss, and the number of folders is minimal.
Write a program that, given sequence ai, will print the minimum number of folders.
Input
The first line contains integer n (1 β€ n β€ 100), n is the number of days. The second line contains a sequence of integers a1, a2, ..., an (|ai| β€ 100), where ai means the company profit on the i-th day. It is possible that the company has no days with the negative ai.
Output
Print an integer k β the required minimum number of folders. In the second line print a sequence of integers b1, b2, ..., bk, where bj is the number of day reports in the j-th folder.
If there are multiple ways to sort the reports into k days, print any of them.
Examples
Input
11
1 2 3 -4 -5 -6 5 -5 -6 -7 6
Output
3
5 3 3
Input
5
0 -1 100 -1 0
Output
1
5
Note
Here goes a way to sort the reports from the first sample into three folders:
1 2 3 -4 -5 | -6 5 -5 | -6 -7 6
In the second sample you can put all five reports in one folder. | instruction | 0 | 97,273 | 24 | 194,546 |
Tags: greedy
Correct Solution:
```
import re
import itertools
from collections import Counter
class Task:
a = []
answer = []
def getData(self):
input()
self.a = [int(x) for x in input().split(" ")]
def solve(self):
currentFolderCounter = 0
badDaysCounter = 0
for x in self.a:
if x >= 0:
currentFolderCounter += 1
elif badDaysCounter <= 1:
currentFolderCounter += 1
badDaysCounter += 1
else:
self.answer += [currentFolderCounter]
currentFolderCounter = 1
badDaysCounter = 1
if currentFolderCounter > 0:
self.answer += [currentFolderCounter]
def printAnswer(self):
print(len(self.answer))
print(re.sub('[\[\],]', '', str(self.answer)))
task = Task();
task.getData();
task.solve();
task.printAnswer();
``` | output | 1 | 97,273 | 24 | 194,547 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarpus has been working in the analytic department of the "F.R.A.U.D." company for as much as n days. Right now his task is to make a series of reports about the company's performance for the last n days. We know that the main information in a day report is value ai, the company's profit on the i-th day. If ai is negative, then the company suffered losses on the i-th day.
Polycarpus should sort the daily reports into folders. Each folder should include data on the company's performance for several consecutive days. Of course, the information on each of the n days should be exactly in one folder. Thus, Polycarpus puts information on the first few days in the first folder. The information on the several following days goes to the second folder, and so on.
It is known that the boss reads one daily report folder per day. If one folder has three or more reports for the days in which the company suffered losses (ai < 0), he loses his temper and his wrath is terrible.
Therefore, Polycarpus wants to prepare the folders so that none of them contains information on three or more days with the loss, and the number of folders is minimal.
Write a program that, given sequence ai, will print the minimum number of folders.
Input
The first line contains integer n (1 β€ n β€ 100), n is the number of days. The second line contains a sequence of integers a1, a2, ..., an (|ai| β€ 100), where ai means the company profit on the i-th day. It is possible that the company has no days with the negative ai.
Output
Print an integer k β the required minimum number of folders. In the second line print a sequence of integers b1, b2, ..., bk, where bj is the number of day reports in the j-th folder.
If there are multiple ways to sort the reports into k days, print any of them.
Examples
Input
11
1 2 3 -4 -5 -6 5 -5 -6 -7 6
Output
3
5 3 3
Input
5
0 -1 100 -1 0
Output
1
5
Note
Here goes a way to sort the reports from the first sample into three folders:
1 2 3 -4 -5 | -6 5 -5 | -6 -7 6
In the second sample you can put all five reports in one folder. | instruction | 0 | 97,274 | 24 | 194,548 |
Tags: greedy
Correct Solution:
```
def fun(ls,n):
count=0
ans=[]
number_of_elements=0
for ind,i in enumerate(ls):
number_of_elements+=1
if(i<0):
count+=1
if(count>2):
ans.append(number_of_elements-1)
count=1
number_of_elements=1
if(ind==n-1):
ans.append(number_of_elements)
count=0
print(len(ans))
print(*ans)
# T = int(input())
# for i in range(T):
n = int(input())
ls=list(map(int,input().split()))
fun(ls,n)
``` | output | 1 | 97,274 | 24 | 194,549 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarpus has been working in the analytic department of the "F.R.A.U.D." company for as much as n days. Right now his task is to make a series of reports about the company's performance for the last n days. We know that the main information in a day report is value ai, the company's profit on the i-th day. If ai is negative, then the company suffered losses on the i-th day.
Polycarpus should sort the daily reports into folders. Each folder should include data on the company's performance for several consecutive days. Of course, the information on each of the n days should be exactly in one folder. Thus, Polycarpus puts information on the first few days in the first folder. The information on the several following days goes to the second folder, and so on.
It is known that the boss reads one daily report folder per day. If one folder has three or more reports for the days in which the company suffered losses (ai < 0), he loses his temper and his wrath is terrible.
Therefore, Polycarpus wants to prepare the folders so that none of them contains information on three or more days with the loss, and the number of folders is minimal.
Write a program that, given sequence ai, will print the minimum number of folders.
Input
The first line contains integer n (1 β€ n β€ 100), n is the number of days. The second line contains a sequence of integers a1, a2, ..., an (|ai| β€ 100), where ai means the company profit on the i-th day. It is possible that the company has no days with the negative ai.
Output
Print an integer k β the required minimum number of folders. In the second line print a sequence of integers b1, b2, ..., bk, where bj is the number of day reports in the j-th folder.
If there are multiple ways to sort the reports into k days, print any of them.
Examples
Input
11
1 2 3 -4 -5 -6 5 -5 -6 -7 6
Output
3
5 3 3
Input
5
0 -1 100 -1 0
Output
1
5
Note
Here goes a way to sort the reports from the first sample into three folders:
1 2 3 -4 -5 | -6 5 -5 | -6 -7 6
In the second sample you can put all five reports in one folder.
Submitted Solution:
```
n = int(input())
a = list(map(int,input().split()))
count,days,total,b = 0,0,0,[]
for i in range(n):
days += 1
if a[i]<0: count+=1
if count==3:
total+=1
b.append(days-1)
days=1
count=1
else:
print(total+1)
b.append(days)
print(*b)
``` | instruction | 0 | 97,275 | 24 | 194,550 |
Yes | output | 1 | 97,275 | 24 | 194,551 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarpus has been working in the analytic department of the "F.R.A.U.D." company for as much as n days. Right now his task is to make a series of reports about the company's performance for the last n days. We know that the main information in a day report is value ai, the company's profit on the i-th day. If ai is negative, then the company suffered losses on the i-th day.
Polycarpus should sort the daily reports into folders. Each folder should include data on the company's performance for several consecutive days. Of course, the information on each of the n days should be exactly in one folder. Thus, Polycarpus puts information on the first few days in the first folder. The information on the several following days goes to the second folder, and so on.
It is known that the boss reads one daily report folder per day. If one folder has three or more reports for the days in which the company suffered losses (ai < 0), he loses his temper and his wrath is terrible.
Therefore, Polycarpus wants to prepare the folders so that none of them contains information on three or more days with the loss, and the number of folders is minimal.
Write a program that, given sequence ai, will print the minimum number of folders.
Input
The first line contains integer n (1 β€ n β€ 100), n is the number of days. The second line contains a sequence of integers a1, a2, ..., an (|ai| β€ 100), where ai means the company profit on the i-th day. It is possible that the company has no days with the negative ai.
Output
Print an integer k β the required minimum number of folders. In the second line print a sequence of integers b1, b2, ..., bk, where bj is the number of day reports in the j-th folder.
If there are multiple ways to sort the reports into k days, print any of them.
Examples
Input
11
1 2 3 -4 -5 -6 5 -5 -6 -7 6
Output
3
5 3 3
Input
5
0 -1 100 -1 0
Output
1
5
Note
Here goes a way to sort the reports from the first sample into three folders:
1 2 3 -4 -5 | -6 5 -5 | -6 -7 6
In the second sample you can put all five reports in one folder.
Submitted Solution:
```
Answer = []
N = int(input())
Negative, Count = 0, 0
X = list(map(int, input().split()))
for i in range(N):
if X[i] < 0:
if Negative == 2:
Answer.append(Count)
Negative = 1
Count = 0
else:
Negative += 1
Count += 1
Answer.append(Count)
print(len(Answer))
print(*Answer)
# UB_CodeForces
# Advice: Falling down is an accident, staying down is a choice
# Location: Mashhad for few days
# Caption: Finally happened what should be happened
# CodeNumber: 697
``` | instruction | 0 | 97,276 | 24 | 194,552 |
Yes | output | 1 | 97,276 | 24 | 194,553 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarpus has been working in the analytic department of the "F.R.A.U.D." company for as much as n days. Right now his task is to make a series of reports about the company's performance for the last n days. We know that the main information in a day report is value ai, the company's profit on the i-th day. If ai is negative, then the company suffered losses on the i-th day.
Polycarpus should sort the daily reports into folders. Each folder should include data on the company's performance for several consecutive days. Of course, the information on each of the n days should be exactly in one folder. Thus, Polycarpus puts information on the first few days in the first folder. The information on the several following days goes to the second folder, and so on.
It is known that the boss reads one daily report folder per day. If one folder has three or more reports for the days in which the company suffered losses (ai < 0), he loses his temper and his wrath is terrible.
Therefore, Polycarpus wants to prepare the folders so that none of them contains information on three or more days with the loss, and the number of folders is minimal.
Write a program that, given sequence ai, will print the minimum number of folders.
Input
The first line contains integer n (1 β€ n β€ 100), n is the number of days. The second line contains a sequence of integers a1, a2, ..., an (|ai| β€ 100), where ai means the company profit on the i-th day. It is possible that the company has no days with the negative ai.
Output
Print an integer k β the required minimum number of folders. In the second line print a sequence of integers b1, b2, ..., bk, where bj is the number of day reports in the j-th folder.
If there are multiple ways to sort the reports into k days, print any of them.
Examples
Input
11
1 2 3 -4 -5 -6 5 -5 -6 -7 6
Output
3
5 3 3
Input
5
0 -1 100 -1 0
Output
1
5
Note
Here goes a way to sort the reports from the first sample into three folders:
1 2 3 -4 -5 | -6 5 -5 | -6 -7 6
In the second sample you can put all five reports in one folder.
Submitted Solution:
```
input()
B = []
b = neg = 0
for a in map(int, input().split()):
if a < 0:
if neg > 1:
B.append(b)
b = neg = 0
neg += 1
b += 1
print(len(B)+1)
print(*B, b)
``` | instruction | 0 | 97,277 | 24 | 194,554 |
Yes | output | 1 | 97,277 | 24 | 194,555 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarpus has been working in the analytic department of the "F.R.A.U.D." company for as much as n days. Right now his task is to make a series of reports about the company's performance for the last n days. We know that the main information in a day report is value ai, the company's profit on the i-th day. If ai is negative, then the company suffered losses on the i-th day.
Polycarpus should sort the daily reports into folders. Each folder should include data on the company's performance for several consecutive days. Of course, the information on each of the n days should be exactly in one folder. Thus, Polycarpus puts information on the first few days in the first folder. The information on the several following days goes to the second folder, and so on.
It is known that the boss reads one daily report folder per day. If one folder has three or more reports for the days in which the company suffered losses (ai < 0), he loses his temper and his wrath is terrible.
Therefore, Polycarpus wants to prepare the folders so that none of them contains information on three or more days with the loss, and the number of folders is minimal.
Write a program that, given sequence ai, will print the minimum number of folders.
Input
The first line contains integer n (1 β€ n β€ 100), n is the number of days. The second line contains a sequence of integers a1, a2, ..., an (|ai| β€ 100), where ai means the company profit on the i-th day. It is possible that the company has no days with the negative ai.
Output
Print an integer k β the required minimum number of folders. In the second line print a sequence of integers b1, b2, ..., bk, where bj is the number of day reports in the j-th folder.
If there are multiple ways to sort the reports into k days, print any of them.
Examples
Input
11
1 2 3 -4 -5 -6 5 -5 -6 -7 6
Output
3
5 3 3
Input
5
0 -1 100 -1 0
Output
1
5
Note
Here goes a way to sort the reports from the first sample into three folders:
1 2 3 -4 -5 | -6 5 -5 | -6 -7 6
In the second sample you can put all five reports in one folder.
Submitted Solution:
```
n = int(input())
reports = list(map(int , input().split()))
count = 0
i=0
folders = 1
arr=[]
pos = 0
while i<len(reports):
if reports[i]<0:
count = count+1
pos = pos + 1
if count==3:
count= 1
folders = folders + 1
arr.append(pos-1)
pos = 1
i = i + 1
if sum(arr)!=len(reports):
arr.append(len(reports)- sum(arr))
print(folders)
print(*arr)
``` | instruction | 0 | 97,278 | 24 | 194,556 |
Yes | output | 1 | 97,278 | 24 | 194,557 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarpus has been working in the analytic department of the "F.R.A.U.D." company for as much as n days. Right now his task is to make a series of reports about the company's performance for the last n days. We know that the main information in a day report is value ai, the company's profit on the i-th day. If ai is negative, then the company suffered losses on the i-th day.
Polycarpus should sort the daily reports into folders. Each folder should include data on the company's performance for several consecutive days. Of course, the information on each of the n days should be exactly in one folder. Thus, Polycarpus puts information on the first few days in the first folder. The information on the several following days goes to the second folder, and so on.
It is known that the boss reads one daily report folder per day. If one folder has three or more reports for the days in which the company suffered losses (ai < 0), he loses his temper and his wrath is terrible.
Therefore, Polycarpus wants to prepare the folders so that none of them contains information on three or more days with the loss, and the number of folders is minimal.
Write a program that, given sequence ai, will print the minimum number of folders.
Input
The first line contains integer n (1 β€ n β€ 100), n is the number of days. The second line contains a sequence of integers a1, a2, ..., an (|ai| β€ 100), where ai means the company profit on the i-th day. It is possible that the company has no days with the negative ai.
Output
Print an integer k β the required minimum number of folders. In the second line print a sequence of integers b1, b2, ..., bk, where bj is the number of day reports in the j-th folder.
If there are multiple ways to sort the reports into k days, print any of them.
Examples
Input
11
1 2 3 -4 -5 -6 5 -5 -6 -7 6
Output
3
5 3 3
Input
5
0 -1 100 -1 0
Output
1
5
Note
Here goes a way to sort the reports from the first sample into three folders:
1 2 3 -4 -5 | -6 5 -5 | -6 -7 6
In the second sample you can put all five reports in one folder.
Submitted Solution:
```
from math import *
import time
n=int(input())
l=input().split(" ")
ll=[]
c=0
s=0
for i in range(0,len(l)):
if(s==3):
ll.append(c-1)
c=2
s=1
else:
if(int(l[i])<0):
s=s+1
c=c+1
else:
c=c+1
if(s==3):
ll.append(c-1)
ll.append(1)
else:
ll.append(c)
print(len(ll))
print(*ll)
# print(time.time()-t1)
``` | instruction | 0 | 97,279 | 24 | 194,558 |
No | output | 1 | 97,279 | 24 | 194,559 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarpus has been working in the analytic department of the "F.R.A.U.D." company for as much as n days. Right now his task is to make a series of reports about the company's performance for the last n days. We know that the main information in a day report is value ai, the company's profit on the i-th day. If ai is negative, then the company suffered losses on the i-th day.
Polycarpus should sort the daily reports into folders. Each folder should include data on the company's performance for several consecutive days. Of course, the information on each of the n days should be exactly in one folder. Thus, Polycarpus puts information on the first few days in the first folder. The information on the several following days goes to the second folder, and so on.
It is known that the boss reads one daily report folder per day. If one folder has three or more reports for the days in which the company suffered losses (ai < 0), he loses his temper and his wrath is terrible.
Therefore, Polycarpus wants to prepare the folders so that none of them contains information on three or more days with the loss, and the number of folders is minimal.
Write a program that, given sequence ai, will print the minimum number of folders.
Input
The first line contains integer n (1 β€ n β€ 100), n is the number of days. The second line contains a sequence of integers a1, a2, ..., an (|ai| β€ 100), where ai means the company profit on the i-th day. It is possible that the company has no days with the negative ai.
Output
Print an integer k β the required minimum number of folders. In the second line print a sequence of integers b1, b2, ..., bk, where bj is the number of day reports in the j-th folder.
If there are multiple ways to sort the reports into k days, print any of them.
Examples
Input
11
1 2 3 -4 -5 -6 5 -5 -6 -7 6
Output
3
5 3 3
Input
5
0 -1 100 -1 0
Output
1
5
Note
Here goes a way to sort the reports from the first sample into three folders:
1 2 3 -4 -5 | -6 5 -5 | -6 -7 6
In the second sample you can put all five reports in one folder.
Submitted Solution:
```
n=int(int(input()))
l=list(map(int,input().split()))
neg=pos=0
z=[]
for x in range(n):
if l[x]>=0:
pos+=1
else:
if neg<2:
neg+=1
else:
z.append(neg+pos)
neg=1
pos=0
if neg!=0 or pos!=0:
z.append(neg+pos)
print(len(z))
``` | instruction | 0 | 97,280 | 24 | 194,560 |
No | output | 1 | 97,280 | 24 | 194,561 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarpus has been working in the analytic department of the "F.R.A.U.D." company for as much as n days. Right now his task is to make a series of reports about the company's performance for the last n days. We know that the main information in a day report is value ai, the company's profit on the i-th day. If ai is negative, then the company suffered losses on the i-th day.
Polycarpus should sort the daily reports into folders. Each folder should include data on the company's performance for several consecutive days. Of course, the information on each of the n days should be exactly in one folder. Thus, Polycarpus puts information on the first few days in the first folder. The information on the several following days goes to the second folder, and so on.
It is known that the boss reads one daily report folder per day. If one folder has three or more reports for the days in which the company suffered losses (ai < 0), he loses his temper and his wrath is terrible.
Therefore, Polycarpus wants to prepare the folders so that none of them contains information on three or more days with the loss, and the number of folders is minimal.
Write a program that, given sequence ai, will print the minimum number of folders.
Input
The first line contains integer n (1 β€ n β€ 100), n is the number of days. The second line contains a sequence of integers a1, a2, ..., an (|ai| β€ 100), where ai means the company profit on the i-th day. It is possible that the company has no days with the negative ai.
Output
Print an integer k β the required minimum number of folders. In the second line print a sequence of integers b1, b2, ..., bk, where bj is the number of day reports in the j-th folder.
If there are multiple ways to sort the reports into k days, print any of them.
Examples
Input
11
1 2 3 -4 -5 -6 5 -5 -6 -7 6
Output
3
5 3 3
Input
5
0 -1 100 -1 0
Output
1
5
Note
Here goes a way to sort the reports from the first sample into three folders:
1 2 3 -4 -5 | -6 5 -5 | -6 -7 6
In the second sample you can put all five reports in one folder.
Submitted Solution:
```
p, x, y, n, t = [], 0, 0, int(input()), list(map(int, input().split()))
for i in range(1, n):
if t[i] < 0: x += 1
if x == 3:
p.append(i - y)
x = 1
y = i
p.append(n - y)
print(len(p))
print(' '.join(str(i) for i in p))
``` | instruction | 0 | 97,281 | 24 | 194,562 |
No | output | 1 | 97,281 | 24 | 194,563 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarpus has been working in the analytic department of the "F.R.A.U.D." company for as much as n days. Right now his task is to make a series of reports about the company's performance for the last n days. We know that the main information in a day report is value ai, the company's profit on the i-th day. If ai is negative, then the company suffered losses on the i-th day.
Polycarpus should sort the daily reports into folders. Each folder should include data on the company's performance for several consecutive days. Of course, the information on each of the n days should be exactly in one folder. Thus, Polycarpus puts information on the first few days in the first folder. The information on the several following days goes to the second folder, and so on.
It is known that the boss reads one daily report folder per day. If one folder has three or more reports for the days in which the company suffered losses (ai < 0), he loses his temper and his wrath is terrible.
Therefore, Polycarpus wants to prepare the folders so that none of them contains information on three or more days with the loss, and the number of folders is minimal.
Write a program that, given sequence ai, will print the minimum number of folders.
Input
The first line contains integer n (1 β€ n β€ 100), n is the number of days. The second line contains a sequence of integers a1, a2, ..., an (|ai| β€ 100), where ai means the company profit on the i-th day. It is possible that the company has no days with the negative ai.
Output
Print an integer k β the required minimum number of folders. In the second line print a sequence of integers b1, b2, ..., bk, where bj is the number of day reports in the j-th folder.
If there are multiple ways to sort the reports into k days, print any of them.
Examples
Input
11
1 2 3 -4 -5 -6 5 -5 -6 -7 6
Output
3
5 3 3
Input
5
0 -1 100 -1 0
Output
1
5
Note
Here goes a way to sort the reports from the first sample into three folders:
1 2 3 -4 -5 | -6 5 -5 | -6 -7 6
In the second sample you can put all five reports in one folder.
Submitted Solution:
```
n=int(input())
a=list(map(int,input().split()))
c=0
f=0
for i in range(0,n):
if a[i]>=0:
c=c+1
elif a[i]<0:
f=f+1
if f>2:
f=f-2
print(c+2,end=" ")
c=0
print(c+f)
``` | instruction | 0 | 97,282 | 24 | 194,564 |
No | output | 1 | 97,282 | 24 | 194,565 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarpus adores TV series. Right now he is ready to finish watching a season of a popular sitcom "Graph Theory". In total, the season has n episodes, numbered with integers from 1 to n.
Polycarpus watches episodes not one by one but in a random order. He has already watched all the episodes except for one. Which episode has Polycaprus forgotten to watch?
Input
The first line of the input contains integer n (2 β€ n β€ 100000) β the number of episodes in a season. Assume that the episodes are numbered by integers from 1 to n.
The second line contains n - 1 integer a1, a2, ..., an (1 β€ ai β€ n) β the numbers of episodes that Polycarpus has watched. All values of ai are distinct.
Output
Print the number of the episode that Polycarpus hasn't watched.
Examples
Input
10
3 8 10 1 7 9 6 5 2
Output
4 | instruction | 0 | 97,329 | 24 | 194,658 |
Tags: implementation
Correct Solution:
```
n=int(input())
movie=list(map(int,input().strip().split()))
movie.sort()
for i in range(1,n+1):
if(i in movie):
movie.remove(i)
#print(i)
else:
print(i)
break
``` | output | 1 | 97,329 | 24 | 194,659 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarpus adores TV series. Right now he is ready to finish watching a season of a popular sitcom "Graph Theory". In total, the season has n episodes, numbered with integers from 1 to n.
Polycarpus watches episodes not one by one but in a random order. He has already watched all the episodes except for one. Which episode has Polycaprus forgotten to watch?
Input
The first line of the input contains integer n (2 β€ n β€ 100000) β the number of episodes in a season. Assume that the episodes are numbered by integers from 1 to n.
The second line contains n - 1 integer a1, a2, ..., an (1 β€ ai β€ n) β the numbers of episodes that Polycarpus has watched. All values of ai are distinct.
Output
Print the number of the episode that Polycarpus hasn't watched.
Examples
Input
10
3 8 10 1 7 9 6 5 2
Output
4 | instruction | 0 | 97,330 | 24 | 194,660 |
Tags: implementation
Correct Solution:
```
n=int(input())
a=list(map(int,input().split()))
a.sort()
for i in range(n-1):
if a[0]!=1:
print(1)
break
elif a[i]==n-1:
print(n)
break
elif a[i]+1!=a[i+1]:
print(a[i]+1)
break
``` | output | 1 | 97,330 | 24 | 194,661 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarpus adores TV series. Right now he is ready to finish watching a season of a popular sitcom "Graph Theory". In total, the season has n episodes, numbered with integers from 1 to n.
Polycarpus watches episodes not one by one but in a random order. He has already watched all the episodes except for one. Which episode has Polycaprus forgotten to watch?
Input
The first line of the input contains integer n (2 β€ n β€ 100000) β the number of episodes in a season. Assume that the episodes are numbered by integers from 1 to n.
The second line contains n - 1 integer a1, a2, ..., an (1 β€ ai β€ n) β the numbers of episodes that Polycarpus has watched. All values of ai are distinct.
Output
Print the number of the episode that Polycarpus hasn't watched.
Examples
Input
10
3 8 10 1 7 9 6 5 2
Output
4 | instruction | 0 | 97,331 | 24 | 194,662 |
Tags: implementation
Correct Solution:
```
n=int(input())
a=list(range(1,n+1))
s=list(map(int,input().split()))
a=set(a)
s=set(s)
p=a.difference(s)
p=list(p)
print(p[0])
``` | output | 1 | 97,331 | 24 | 194,663 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarpus adores TV series. Right now he is ready to finish watching a season of a popular sitcom "Graph Theory". In total, the season has n episodes, numbered with integers from 1 to n.
Polycarpus watches episodes not one by one but in a random order. He has already watched all the episodes except for one. Which episode has Polycaprus forgotten to watch?
Input
The first line of the input contains integer n (2 β€ n β€ 100000) β the number of episodes in a season. Assume that the episodes are numbered by integers from 1 to n.
The second line contains n - 1 integer a1, a2, ..., an (1 β€ ai β€ n) β the numbers of episodes that Polycarpus has watched. All values of ai are distinct.
Output
Print the number of the episode that Polycarpus hasn't watched.
Examples
Input
10
3 8 10 1 7 9 6 5 2
Output
4 | instruction | 0 | 97,332 | 24 | 194,664 |
Tags: implementation
Correct Solution:
```
n = int(input())
array = input().split(" ")
nar = []
for i in range(len(array)):
nar.append(int(array[i]))
nar.sort()
for i in range(n-2):
if nar[i+1]-nar[i]>1:
print(i+2)
exit()
if nar[0] == 2:
print(1)
exit()
print(n)
``` | output | 1 | 97,332 | 24 | 194,665 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarpus adores TV series. Right now he is ready to finish watching a season of a popular sitcom "Graph Theory". In total, the season has n episodes, numbered with integers from 1 to n.
Polycarpus watches episodes not one by one but in a random order. He has already watched all the episodes except for one. Which episode has Polycaprus forgotten to watch?
Input
The first line of the input contains integer n (2 β€ n β€ 100000) β the number of episodes in a season. Assume that the episodes are numbered by integers from 1 to n.
The second line contains n - 1 integer a1, a2, ..., an (1 β€ ai β€ n) β the numbers of episodes that Polycarpus has watched. All values of ai are distinct.
Output
Print the number of the episode that Polycarpus hasn't watched.
Examples
Input
10
3 8 10 1 7 9 6 5 2
Output
4 | instruction | 0 | 97,333 | 24 | 194,666 |
Tags: implementation
Correct Solution:
```
n=int(input())
arr=list(map(int,input().split()))
print(int((n*(n+1))/2)-sum(arr))
``` | output | 1 | 97,333 | 24 | 194,667 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarpus adores TV series. Right now he is ready to finish watching a season of a popular sitcom "Graph Theory". In total, the season has n episodes, numbered with integers from 1 to n.
Polycarpus watches episodes not one by one but in a random order. He has already watched all the episodes except for one. Which episode has Polycaprus forgotten to watch?
Input
The first line of the input contains integer n (2 β€ n β€ 100000) β the number of episodes in a season. Assume that the episodes are numbered by integers from 1 to n.
The second line contains n - 1 integer a1, a2, ..., an (1 β€ ai β€ n) β the numbers of episodes that Polycarpus has watched. All values of ai are distinct.
Output
Print the number of the episode that Polycarpus hasn't watched.
Examples
Input
10
3 8 10 1 7 9 6 5 2
Output
4 | instruction | 0 | 97,334 | 24 | 194,668 |
Tags: implementation
Correct Solution:
```
#!/usr/bin/python3
n = int(input())
s = [int(v) for v in input().split()]
t = sum(range(1, n+1))
for i in s:
t -= i
print(t)
``` | output | 1 | 97,334 | 24 | 194,669 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarpus adores TV series. Right now he is ready to finish watching a season of a popular sitcom "Graph Theory". In total, the season has n episodes, numbered with integers from 1 to n.
Polycarpus watches episodes not one by one but in a random order. He has already watched all the episodes except for one. Which episode has Polycaprus forgotten to watch?
Input
The first line of the input contains integer n (2 β€ n β€ 100000) β the number of episodes in a season. Assume that the episodes are numbered by integers from 1 to n.
The second line contains n - 1 integer a1, a2, ..., an (1 β€ ai β€ n) β the numbers of episodes that Polycarpus has watched. All values of ai are distinct.
Output
Print the number of the episode that Polycarpus hasn't watched.
Examples
Input
10
3 8 10 1 7 9 6 5 2
Output
4 | instruction | 0 | 97,335 | 24 | 194,670 |
Tags: implementation
Correct Solution:
```
n = int(input()); print(int((1+n)/2*n-sum(list(map(int,input().split())))))
``` | output | 1 | 97,335 | 24 | 194,671 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarpus adores TV series. Right now he is ready to finish watching a season of a popular sitcom "Graph Theory". In total, the season has n episodes, numbered with integers from 1 to n.
Polycarpus watches episodes not one by one but in a random order. He has already watched all the episodes except for one. Which episode has Polycaprus forgotten to watch?
Input
The first line of the input contains integer n (2 β€ n β€ 100000) β the number of episodes in a season. Assume that the episodes are numbered by integers from 1 to n.
The second line contains n - 1 integer a1, a2, ..., an (1 β€ ai β€ n) β the numbers of episodes that Polycarpus has watched. All values of ai are distinct.
Output
Print the number of the episode that Polycarpus hasn't watched.
Examples
Input
10
3 8 10 1 7 9 6 5 2
Output
4 | instruction | 0 | 97,336 | 24 | 194,672 |
Tags: implementation
Correct Solution:
```
n = int(input())
e = list(map(int,input().split()))
print(int(n*(n+1)/2)-sum(e))
``` | output | 1 | 97,336 | 24 | 194,673 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarpus adores TV series. Right now he is ready to finish watching a season of a popular sitcom "Graph Theory". In total, the season has n episodes, numbered with integers from 1 to n.
Polycarpus watches episodes not one by one but in a random order. He has already watched all the episodes except for one. Which episode has Polycaprus forgotten to watch?
Input
The first line of the input contains integer n (2 β€ n β€ 100000) β the number of episodes in a season. Assume that the episodes are numbered by integers from 1 to n.
The second line contains n - 1 integer a1, a2, ..., an (1 β€ ai β€ n) β the numbers of episodes that Polycarpus has watched. All values of ai are distinct.
Output
Print the number of the episode that Polycarpus hasn't watched.
Examples
Input
10
3 8 10 1 7 9 6 5 2
Output
4
Submitted Solution:
```
import sys
input=sys.stdin.buffer.readline
n=int(input())
arr=list(map(int,input().split()))
arr.sort()
z=0
for i in range(0,n-1):
if arr[i]==i+1:
continue
else:
print(i+1)
z=1
break
if z==0:
print(n)
``` | instruction | 0 | 97,337 | 24 | 194,674 |
Yes | output | 1 | 97,337 | 24 | 194,675 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarpus adores TV series. Right now he is ready to finish watching a season of a popular sitcom "Graph Theory". In total, the season has n episodes, numbered with integers from 1 to n.
Polycarpus watches episodes not one by one but in a random order. He has already watched all the episodes except for one. Which episode has Polycaprus forgotten to watch?
Input
The first line of the input contains integer n (2 β€ n β€ 100000) β the number of episodes in a season. Assume that the episodes are numbered by integers from 1 to n.
The second line contains n - 1 integer a1, a2, ..., an (1 β€ ai β€ n) β the numbers of episodes that Polycarpus has watched. All values of ai are distinct.
Output
Print the number of the episode that Polycarpus hasn't watched.
Examples
Input
10
3 8 10 1 7 9 6 5 2
Output
4
Submitted Solution:
```
n = int(input())
sum = n * (n + 1) // 2
for x in map(int, input().split()):
sum -= x
print(sum)
``` | instruction | 0 | 97,338 | 24 | 194,676 |
Yes | output | 1 | 97,338 | 24 | 194,677 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarpus adores TV series. Right now he is ready to finish watching a season of a popular sitcom "Graph Theory". In total, the season has n episodes, numbered with integers from 1 to n.
Polycarpus watches episodes not one by one but in a random order. He has already watched all the episodes except for one. Which episode has Polycaprus forgotten to watch?
Input
The first line of the input contains integer n (2 β€ n β€ 100000) β the number of episodes in a season. Assume that the episodes are numbered by integers from 1 to n.
The second line contains n - 1 integer a1, a2, ..., an (1 β€ ai β€ n) β the numbers of episodes that Polycarpus has watched. All values of ai are distinct.
Output
Print the number of the episode that Polycarpus hasn't watched.
Examples
Input
10
3 8 10 1 7 9 6 5 2
Output
4
Submitted Solution:
```
n=int(input());
l=list(map(int,input().split()))
l.sort()
for i in range(1,n+1):
if i==n:print(n); break
if l[i-1]!=i :print(i);break
``` | instruction | 0 | 97,339 | 24 | 194,678 |
Yes | output | 1 | 97,339 | 24 | 194,679 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarpus adores TV series. Right now he is ready to finish watching a season of a popular sitcom "Graph Theory". In total, the season has n episodes, numbered with integers from 1 to n.
Polycarpus watches episodes not one by one but in a random order. He has already watched all the episodes except for one. Which episode has Polycaprus forgotten to watch?
Input
The first line of the input contains integer n (2 β€ n β€ 100000) β the number of episodes in a season. Assume that the episodes are numbered by integers from 1 to n.
The second line contains n - 1 integer a1, a2, ..., an (1 β€ ai β€ n) β the numbers of episodes that Polycarpus has watched. All values of ai are distinct.
Output
Print the number of the episode that Polycarpus hasn't watched.
Examples
Input
10
3 8 10 1 7 9 6 5 2
Output
4
Submitted Solution:
```
n=int(input())
l=list(map(int,input().split()))
l=set(l)
l1=[i for i in range(1,n+1)]
l1=set(l1)
l1=l1-l
l1=list(l1)
l1 = [str(i) for i in l1]
print(" ".join(l1))
``` | instruction | 0 | 97,340 | 24 | 194,680 |
Yes | output | 1 | 97,340 | 24 | 194,681 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarpus adores TV series. Right now he is ready to finish watching a season of a popular sitcom "Graph Theory". In total, the season has n episodes, numbered with integers from 1 to n.
Polycarpus watches episodes not one by one but in a random order. He has already watched all the episodes except for one. Which episode has Polycaprus forgotten to watch?
Input
The first line of the input contains integer n (2 β€ n β€ 100000) β the number of episodes in a season. Assume that the episodes are numbered by integers from 1 to n.
The second line contains n - 1 integer a1, a2, ..., an (1 β€ ai β€ n) β the numbers of episodes that Polycarpus has watched. All values of ai are distinct.
Output
Print the number of the episode that Polycarpus hasn't watched.
Examples
Input
10
3 8 10 1 7 9 6 5 2
Output
4
Submitted Solution:
```
n = int(input())
arr = sum(map(int, input().split()))
print(((n*n+1)//2)-arr)
``` | instruction | 0 | 97,341 | 24 | 194,682 |
No | output | 1 | 97,341 | 24 | 194,683 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarpus adores TV series. Right now he is ready to finish watching a season of a popular sitcom "Graph Theory". In total, the season has n episodes, numbered with integers from 1 to n.
Polycarpus watches episodes not one by one but in a random order. He has already watched all the episodes except for one. Which episode has Polycaprus forgotten to watch?
Input
The first line of the input contains integer n (2 β€ n β€ 100000) β the number of episodes in a season. Assume that the episodes are numbered by integers from 1 to n.
The second line contains n - 1 integer a1, a2, ..., an (1 β€ ai β€ n) β the numbers of episodes that Polycarpus has watched. All values of ai are distinct.
Output
Print the number of the episode that Polycarpus hasn't watched.
Examples
Input
10
3 8 10 1 7 9 6 5 2
Output
4
Submitted Solution:
```
n = int(input())
l = list(map(int,input().split()))
l.sort()
flag = 0
for i in range(1,n-1):
if i == l[i-1]:
continue
else:
flag = 1
print(i)
break
if flag == 0:
print(n)
``` | instruction | 0 | 97,342 | 24 | 194,684 |
No | output | 1 | 97,342 | 24 | 194,685 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarpus adores TV series. Right now he is ready to finish watching a season of a popular sitcom "Graph Theory". In total, the season has n episodes, numbered with integers from 1 to n.
Polycarpus watches episodes not one by one but in a random order. He has already watched all the episodes except for one. Which episode has Polycaprus forgotten to watch?
Input
The first line of the input contains integer n (2 β€ n β€ 100000) β the number of episodes in a season. Assume that the episodes are numbered by integers from 1 to n.
The second line contains n - 1 integer a1, a2, ..., an (1 β€ ai β€ n) β the numbers of episodes that Polycarpus has watched. All values of ai are distinct.
Output
Print the number of the episode that Polycarpus hasn't watched.
Examples
Input
10
3 8 10 1 7 9 6 5 2
Output
4
Submitted Solution:
```
n = int (input())
m=map(int,input().split()[:n])
m = sorted(m)
k=0
for i in range(n-2):
if m[i]+1 != m[i+1]:
print (m[i]+1)
break
else:
k+=1
#print(k)
if k==n-2:
print(n)
if m[0]!=1:
print(1)
elif k==n-2:
print(n)
``` | instruction | 0 | 97,343 | 24 | 194,686 |
No | output | 1 | 97,343 | 24 | 194,687 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarpus adores TV series. Right now he is ready to finish watching a season of a popular sitcom "Graph Theory". In total, the season has n episodes, numbered with integers from 1 to n.
Polycarpus watches episodes not one by one but in a random order. He has already watched all the episodes except for one. Which episode has Polycaprus forgotten to watch?
Input
The first line of the input contains integer n (2 β€ n β€ 100000) β the number of episodes in a season. Assume that the episodes are numbered by integers from 1 to n.
The second line contains n - 1 integer a1, a2, ..., an (1 β€ ai β€ n) β the numbers of episodes that Polycarpus has watched. All values of ai are distinct.
Output
Print the number of the episode that Polycarpus hasn't watched.
Examples
Input
10
3 8 10 1 7 9 6 5 2
Output
4
Submitted Solution:
```
n=int(input())
lst1=[int(i) for i in input().split()]
lst2=list(range(1,n+1))
lst1.sort()
for i in range(0,n):
if lst2[i]!=lst1[i]:
print(i)
break
``` | instruction | 0 | 97,344 | 24 | 194,688 |
No | output | 1 | 97,344 | 24 | 194,689 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp has n dice d1, d2, ..., dn. The i-th dice shows numbers from 1 to di. Polycarp rolled all the dice and the sum of numbers they showed is A. Agrippina didn't see which dice showed what number, she knows only the sum A and the values d1, d2, ..., dn. However, she finds it enough to make a series of statements of the following type: dice i couldn't show number r. For example, if Polycarp had two six-faced dice and the total sum is A = 11, then Agrippina can state that each of the two dice couldn't show a value less than five (otherwise, the remaining dice must have a value of at least seven, which is impossible).
For each dice find the number of values for which it can be guaranteed that the dice couldn't show these values if the sum of the shown values is A.
Input
The first line contains two integers n, A (1 β€ n β€ 2Β·105, n β€ A β€ s) β the number of dice and the sum of shown values where s = d1 + d2 + ... + dn.
The second line contains n integers d1, d2, ..., dn (1 β€ di β€ 106), where di is the maximum value that the i-th dice can show.
Output
Print n integers b1, b2, ..., bn, where bi is the number of values for which it is guaranteed that the i-th dice couldn't show them.
Examples
Input
2 8
4 4
Output
3 3
Input
1 3
5
Output
4
Input
2 3
2 3
Output
0 1
Note
In the first sample from the statement A equal to 8 could be obtained in the only case when both the first and the second dice show 4. Correspondingly, both dice couldn't show values 1, 2 or 3.
In the second sample from the statement A equal to 3 could be obtained when the single dice shows 3. Correspondingly, it couldn't show 1, 2, 4 or 5.
In the third sample from the statement A equal to 3 could be obtained when one dice shows 1 and the other dice shows 2. That's why the first dice doesn't have any values it couldn't show and the second dice couldn't show 3. | instruction | 0 | 97,393 | 24 | 194,786 |
Tags: math
Correct Solution:
```
[n, A] = [int(x) for x in input().split()]
d = [0] + [int(x) for x in input().split()]
sigma = sum(d)
ans = [0] * (n + 1)
for i in range(1, n + 1):
at_least = A - sigma + d[i] - 1
at_least = max(at_least, 0)
ans[i] += at_least
at_most = d[i] - A + n - 1
at_most = max(at_most, 0)
ans[i] += at_most
ans = ans[1:]
ans = [str(x) for x in ans]
print(" ".join(ans))
``` | output | 1 | 97,393 | 24 | 194,787 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp has n dice d1, d2, ..., dn. The i-th dice shows numbers from 1 to di. Polycarp rolled all the dice and the sum of numbers they showed is A. Agrippina didn't see which dice showed what number, she knows only the sum A and the values d1, d2, ..., dn. However, she finds it enough to make a series of statements of the following type: dice i couldn't show number r. For example, if Polycarp had two six-faced dice and the total sum is A = 11, then Agrippina can state that each of the two dice couldn't show a value less than five (otherwise, the remaining dice must have a value of at least seven, which is impossible).
For each dice find the number of values for which it can be guaranteed that the dice couldn't show these values if the sum of the shown values is A.
Input
The first line contains two integers n, A (1 β€ n β€ 2Β·105, n β€ A β€ s) β the number of dice and the sum of shown values where s = d1 + d2 + ... + dn.
The second line contains n integers d1, d2, ..., dn (1 β€ di β€ 106), where di is the maximum value that the i-th dice can show.
Output
Print n integers b1, b2, ..., bn, where bi is the number of values for which it is guaranteed that the i-th dice couldn't show them.
Examples
Input
2 8
4 4
Output
3 3
Input
1 3
5
Output
4
Input
2 3
2 3
Output
0 1
Note
In the first sample from the statement A equal to 8 could be obtained in the only case when both the first and the second dice show 4. Correspondingly, both dice couldn't show values 1, 2 or 3.
In the second sample from the statement A equal to 3 could be obtained when the single dice shows 3. Correspondingly, it couldn't show 1, 2, 4 or 5.
In the third sample from the statement A equal to 3 could be obtained when one dice shows 1 and the other dice shows 2. That's why the first dice doesn't have any values it couldn't show and the second dice couldn't show 3. | instruction | 0 | 97,394 | 24 | 194,788 |
Tags: math
Correct Solution:
```
n , m = map(int,input().split())
lis = list(map(int,input().split()))
s = sum(lis)
for i in range(n):
t = s-lis[i]
z=n-1
ans = max(0,m-t-1)
ans+=max(0,lis[i]-m+z)
print(ans,end=' ')
``` | output | 1 | 97,394 | 24 | 194,789 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp has n dice d1, d2, ..., dn. The i-th dice shows numbers from 1 to di. Polycarp rolled all the dice and the sum of numbers they showed is A. Agrippina didn't see which dice showed what number, she knows only the sum A and the values d1, d2, ..., dn. However, she finds it enough to make a series of statements of the following type: dice i couldn't show number r. For example, if Polycarp had two six-faced dice and the total sum is A = 11, then Agrippina can state that each of the two dice couldn't show a value less than five (otherwise, the remaining dice must have a value of at least seven, which is impossible).
For each dice find the number of values for which it can be guaranteed that the dice couldn't show these values if the sum of the shown values is A.
Input
The first line contains two integers n, A (1 β€ n β€ 2Β·105, n β€ A β€ s) β the number of dice and the sum of shown values where s = d1 + d2 + ... + dn.
The second line contains n integers d1, d2, ..., dn (1 β€ di β€ 106), where di is the maximum value that the i-th dice can show.
Output
Print n integers b1, b2, ..., bn, where bi is the number of values for which it is guaranteed that the i-th dice couldn't show them.
Examples
Input
2 8
4 4
Output
3 3
Input
1 3
5
Output
4
Input
2 3
2 3
Output
0 1
Note
In the first sample from the statement A equal to 8 could be obtained in the only case when both the first and the second dice show 4. Correspondingly, both dice couldn't show values 1, 2 or 3.
In the second sample from the statement A equal to 3 could be obtained when the single dice shows 3. Correspondingly, it couldn't show 1, 2, 4 or 5.
In the third sample from the statement A equal to 3 could be obtained when one dice shows 1 and the other dice shows 2. That's why the first dice doesn't have any values it couldn't show and the second dice couldn't show 3. | instruction | 0 | 97,395 | 24 | 194,790 |
Tags: math
Correct Solution:
```
n, k = map(int, input().split())
d = list(map(int, input().split()))
tot, res = sum(d), []
for i in range(n):
x = max(0, k + d[i] - tot - 1)
y = max(0, -k + d[i] + n - 1)
res.append(x+y)
print(*res)
``` | output | 1 | 97,395 | 24 | 194,791 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp has n dice d1, d2, ..., dn. The i-th dice shows numbers from 1 to di. Polycarp rolled all the dice and the sum of numbers they showed is A. Agrippina didn't see which dice showed what number, she knows only the sum A and the values d1, d2, ..., dn. However, she finds it enough to make a series of statements of the following type: dice i couldn't show number r. For example, if Polycarp had two six-faced dice and the total sum is A = 11, then Agrippina can state that each of the two dice couldn't show a value less than five (otherwise, the remaining dice must have a value of at least seven, which is impossible).
For each dice find the number of values for which it can be guaranteed that the dice couldn't show these values if the sum of the shown values is A.
Input
The first line contains two integers n, A (1 β€ n β€ 2Β·105, n β€ A β€ s) β the number of dice and the sum of shown values where s = d1 + d2 + ... + dn.
The second line contains n integers d1, d2, ..., dn (1 β€ di β€ 106), where di is the maximum value that the i-th dice can show.
Output
Print n integers b1, b2, ..., bn, where bi is the number of values for which it is guaranteed that the i-th dice couldn't show them.
Examples
Input
2 8
4 4
Output
3 3
Input
1 3
5
Output
4
Input
2 3
2 3
Output
0 1
Note
In the first sample from the statement A equal to 8 could be obtained in the only case when both the first and the second dice show 4. Correspondingly, both dice couldn't show values 1, 2 or 3.
In the second sample from the statement A equal to 3 could be obtained when the single dice shows 3. Correspondingly, it couldn't show 1, 2, 4 or 5.
In the third sample from the statement A equal to 3 could be obtained when one dice shows 1 and the other dice shows 2. That's why the first dice doesn't have any values it couldn't show and the second dice couldn't show 3. | instruction | 0 | 97,396 | 24 | 194,792 |
Tags: math
Correct Solution:
```
n, A = map(int, input().split())
d = list(map(int, input().split()))
sum = 0
for i in range(n):
sum += d[i]
for i in range(n):
left = max(1, A - (sum - d[i]))
right = min(d[i], A - (n - 1))
ans = d[i] - (right - left + 1)
print(ans)
``` | output | 1 | 97,396 | 24 | 194,793 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp has n dice d1, d2, ..., dn. The i-th dice shows numbers from 1 to di. Polycarp rolled all the dice and the sum of numbers they showed is A. Agrippina didn't see which dice showed what number, she knows only the sum A and the values d1, d2, ..., dn. However, she finds it enough to make a series of statements of the following type: dice i couldn't show number r. For example, if Polycarp had two six-faced dice and the total sum is A = 11, then Agrippina can state that each of the two dice couldn't show a value less than five (otherwise, the remaining dice must have a value of at least seven, which is impossible).
For each dice find the number of values for which it can be guaranteed that the dice couldn't show these values if the sum of the shown values is A.
Input
The first line contains two integers n, A (1 β€ n β€ 2Β·105, n β€ A β€ s) β the number of dice and the sum of shown values where s = d1 + d2 + ... + dn.
The second line contains n integers d1, d2, ..., dn (1 β€ di β€ 106), where di is the maximum value that the i-th dice can show.
Output
Print n integers b1, b2, ..., bn, where bi is the number of values for which it is guaranteed that the i-th dice couldn't show them.
Examples
Input
2 8
4 4
Output
3 3
Input
1 3
5
Output
4
Input
2 3
2 3
Output
0 1
Note
In the first sample from the statement A equal to 8 could be obtained in the only case when both the first and the second dice show 4. Correspondingly, both dice couldn't show values 1, 2 or 3.
In the second sample from the statement A equal to 3 could be obtained when the single dice shows 3. Correspondingly, it couldn't show 1, 2, 4 or 5.
In the third sample from the statement A equal to 3 could be obtained when one dice shows 1 and the other dice shows 2. That's why the first dice doesn't have any values it couldn't show and the second dice couldn't show 3. | instruction | 0 | 97,397 | 24 | 194,794 |
Tags: math
Correct Solution:
```
n, a = map(int, str.split(input()))
ns = tuple(map(int, str.split(input())))
s = sum(ns)
res = []
for x in ns:
low = max(0, a - (s - x) - 1)
high = min(x, a - (n - 1))
res.append(low + x - high)
print(str.join(" ", map(str, res)))
``` | output | 1 | 97,397 | 24 | 194,795 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp has n dice d1, d2, ..., dn. The i-th dice shows numbers from 1 to di. Polycarp rolled all the dice and the sum of numbers they showed is A. Agrippina didn't see which dice showed what number, she knows only the sum A and the values d1, d2, ..., dn. However, she finds it enough to make a series of statements of the following type: dice i couldn't show number r. For example, if Polycarp had two six-faced dice and the total sum is A = 11, then Agrippina can state that each of the two dice couldn't show a value less than five (otherwise, the remaining dice must have a value of at least seven, which is impossible).
For each dice find the number of values for which it can be guaranteed that the dice couldn't show these values if the sum of the shown values is A.
Input
The first line contains two integers n, A (1 β€ n β€ 2Β·105, n β€ A β€ s) β the number of dice and the sum of shown values where s = d1 + d2 + ... + dn.
The second line contains n integers d1, d2, ..., dn (1 β€ di β€ 106), where di is the maximum value that the i-th dice can show.
Output
Print n integers b1, b2, ..., bn, where bi is the number of values for which it is guaranteed that the i-th dice couldn't show them.
Examples
Input
2 8
4 4
Output
3 3
Input
1 3
5
Output
4
Input
2 3
2 3
Output
0 1
Note
In the first sample from the statement A equal to 8 could be obtained in the only case when both the first and the second dice show 4. Correspondingly, both dice couldn't show values 1, 2 or 3.
In the second sample from the statement A equal to 3 could be obtained when the single dice shows 3. Correspondingly, it couldn't show 1, 2, 4 or 5.
In the third sample from the statement A equal to 3 could be obtained when one dice shows 1 and the other dice shows 2. That's why the first dice doesn't have any values it couldn't show and the second dice couldn't show 3. | instruction | 0 | 97,398 | 24 | 194,796 |
Tags: math
Correct Solution:
```
n, a = map(int, input().split())
b = list(map(int, input().split()))
ans = [0] * n
k = a - (n - 1)
if n == 1:
print(b[0] - 1)
exit()
elif a % n == 0:
d = a // n
if b.count(d) == n:
ans = [d - 1] * n
print(*ans)
exit()
s = sum(b)
for i in range(n):
if k < b[i]:
ans[i] += (b[i] - k)
if (s - a) < b[i]:
ans[i] += a - (s - b[i]) - 1
print(*ans)
``` | output | 1 | 97,398 | 24 | 194,797 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp has n dice d1, d2, ..., dn. The i-th dice shows numbers from 1 to di. Polycarp rolled all the dice and the sum of numbers they showed is A. Agrippina didn't see which dice showed what number, she knows only the sum A and the values d1, d2, ..., dn. However, she finds it enough to make a series of statements of the following type: dice i couldn't show number r. For example, if Polycarp had two six-faced dice and the total sum is A = 11, then Agrippina can state that each of the two dice couldn't show a value less than five (otherwise, the remaining dice must have a value of at least seven, which is impossible).
For each dice find the number of values for which it can be guaranteed that the dice couldn't show these values if the sum of the shown values is A.
Input
The first line contains two integers n, A (1 β€ n β€ 2Β·105, n β€ A β€ s) β the number of dice and the sum of shown values where s = d1 + d2 + ... + dn.
The second line contains n integers d1, d2, ..., dn (1 β€ di β€ 106), where di is the maximum value that the i-th dice can show.
Output
Print n integers b1, b2, ..., bn, where bi is the number of values for which it is guaranteed that the i-th dice couldn't show them.
Examples
Input
2 8
4 4
Output
3 3
Input
1 3
5
Output
4
Input
2 3
2 3
Output
0 1
Note
In the first sample from the statement A equal to 8 could be obtained in the only case when both the first and the second dice show 4. Correspondingly, both dice couldn't show values 1, 2 or 3.
In the second sample from the statement A equal to 3 could be obtained when the single dice shows 3. Correspondingly, it couldn't show 1, 2, 4 or 5.
In the third sample from the statement A equal to 3 could be obtained when one dice shows 1 and the other dice shows 2. That's why the first dice doesn't have any values it couldn't show and the second dice couldn't show 3. | instruction | 0 | 97,399 | 24 | 194,798 |
Tags: math
Correct Solution:
```
#! /usr/bin/python3
#http://codeforces.com/contest/534/problem/C
n, sum = map(int, input().split())
t = input().split()
array = [0] * n
for i in range(0, n):
array[i] = int(t[i])
total = 0
for i in range(0, n):
total = total + array[i]
for i in range(0, n):
k = total - array[i]
top = sum - (n - 1)
below = sum - k
if below <= 0:
below = 1
if top > array[i]:
top = array[i]
print(array[i] - top + below - 1, end=' ')
print()
``` | output | 1 | 97,399 | 24 | 194,799 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp has n dice d1, d2, ..., dn. The i-th dice shows numbers from 1 to di. Polycarp rolled all the dice and the sum of numbers they showed is A. Agrippina didn't see which dice showed what number, she knows only the sum A and the values d1, d2, ..., dn. However, she finds it enough to make a series of statements of the following type: dice i couldn't show number r. For example, if Polycarp had two six-faced dice and the total sum is A = 11, then Agrippina can state that each of the two dice couldn't show a value less than five (otherwise, the remaining dice must have a value of at least seven, which is impossible).
For each dice find the number of values for which it can be guaranteed that the dice couldn't show these values if the sum of the shown values is A.
Input
The first line contains two integers n, A (1 β€ n β€ 2Β·105, n β€ A β€ s) β the number of dice and the sum of shown values where s = d1 + d2 + ... + dn.
The second line contains n integers d1, d2, ..., dn (1 β€ di β€ 106), where di is the maximum value that the i-th dice can show.
Output
Print n integers b1, b2, ..., bn, where bi is the number of values for which it is guaranteed that the i-th dice couldn't show them.
Examples
Input
2 8
4 4
Output
3 3
Input
1 3
5
Output
4
Input
2 3
2 3
Output
0 1
Note
In the first sample from the statement A equal to 8 could be obtained in the only case when both the first and the second dice show 4. Correspondingly, both dice couldn't show values 1, 2 or 3.
In the second sample from the statement A equal to 3 could be obtained when the single dice shows 3. Correspondingly, it couldn't show 1, 2, 4 or 5.
In the third sample from the statement A equal to 3 could be obtained when one dice shows 1 and the other dice shows 2. That's why the first dice doesn't have any values it couldn't show and the second dice couldn't show 3. | instruction | 0 | 97,400 | 24 | 194,800 |
Tags: math
Correct Solution:
```
#! /usr/bin/python3
#http://codeforces.com/contest/534/problem/C
n, sum = map(int, input().split())
t = input().split()
array = []
for i in range(0, n):
array.append(int(t[i]))
total = 0
for i in range(0, n):
total = total + array[i]
for i in range(0, n):
k = total - array[i]
top = sum - (n - 1)
below = sum - k
if below <= 0:
below = 1
if top > array[i]:
top = array[i]
print(array[i] - top + below - 1, end=' ')
print()
``` | output | 1 | 97,400 | 24 | 194,801 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp has n dice d1, d2, ..., dn. The i-th dice shows numbers from 1 to di. Polycarp rolled all the dice and the sum of numbers they showed is A. Agrippina didn't see which dice showed what number, she knows only the sum A and the values d1, d2, ..., dn. However, she finds it enough to make a series of statements of the following type: dice i couldn't show number r. For example, if Polycarp had two six-faced dice and the total sum is A = 11, then Agrippina can state that each of the two dice couldn't show a value less than five (otherwise, the remaining dice must have a value of at least seven, which is impossible).
For each dice find the number of values for which it can be guaranteed that the dice couldn't show these values if the sum of the shown values is A.
Input
The first line contains two integers n, A (1 β€ n β€ 2Β·105, n β€ A β€ s) β the number of dice and the sum of shown values where s = d1 + d2 + ... + dn.
The second line contains n integers d1, d2, ..., dn (1 β€ di β€ 106), where di is the maximum value that the i-th dice can show.
Output
Print n integers b1, b2, ..., bn, where bi is the number of values for which it is guaranteed that the i-th dice couldn't show them.
Examples
Input
2 8
4 4
Output
3 3
Input
1 3
5
Output
4
Input
2 3
2 3
Output
0 1
Note
In the first sample from the statement A equal to 8 could be obtained in the only case when both the first and the second dice show 4. Correspondingly, both dice couldn't show values 1, 2 or 3.
In the second sample from the statement A equal to 3 could be obtained when the single dice shows 3. Correspondingly, it couldn't show 1, 2, 4 or 5.
In the third sample from the statement A equal to 3 could be obtained when one dice shows 1 and the other dice shows 2. That's why the first dice doesn't have any values it couldn't show and the second dice couldn't show 3.
Submitted Solution:
```
def getIntersection(l1, r1, l2, r2):
ans = -1
if l1 > l2:
l1, l2 = l2, l1
r1, r2 = r2, r1
if l2 > r1: ans = 0
elif r2 >= r1: ans = r1 - l2 + 1
else: ans = r2 - l2 + 1
return ans
def solve(d, a):
total = sum(d)
n = len(d)
ans = []
for i in d:
l, r = n-1, total-i
tgtl, tgtr = a-i, a-1
intersect = getIntersection(l, r, tgtl, tgtr)
ans.append(i-intersect)
return ans
n, a = (int(x) for x in input().split())
d = [int(x) for x in input().split()]
print(*(i for i in solve(d, a)))
``` | instruction | 0 | 97,401 | 24 | 194,802 |
Yes | output | 1 | 97,401 | 24 | 194,803 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp has n dice d1, d2, ..., dn. The i-th dice shows numbers from 1 to di. Polycarp rolled all the dice and the sum of numbers they showed is A. Agrippina didn't see which dice showed what number, she knows only the sum A and the values d1, d2, ..., dn. However, she finds it enough to make a series of statements of the following type: dice i couldn't show number r. For example, if Polycarp had two six-faced dice and the total sum is A = 11, then Agrippina can state that each of the two dice couldn't show a value less than five (otherwise, the remaining dice must have a value of at least seven, which is impossible).
For each dice find the number of values for which it can be guaranteed that the dice couldn't show these values if the sum of the shown values is A.
Input
The first line contains two integers n, A (1 β€ n β€ 2Β·105, n β€ A β€ s) β the number of dice and the sum of shown values where s = d1 + d2 + ... + dn.
The second line contains n integers d1, d2, ..., dn (1 β€ di β€ 106), where di is the maximum value that the i-th dice can show.
Output
Print n integers b1, b2, ..., bn, where bi is the number of values for which it is guaranteed that the i-th dice couldn't show them.
Examples
Input
2 8
4 4
Output
3 3
Input
1 3
5
Output
4
Input
2 3
2 3
Output
0 1
Note
In the first sample from the statement A equal to 8 could be obtained in the only case when both the first and the second dice show 4. Correspondingly, both dice couldn't show values 1, 2 or 3.
In the second sample from the statement A equal to 3 could be obtained when the single dice shows 3. Correspondingly, it couldn't show 1, 2, 4 or 5.
In the third sample from the statement A equal to 3 could be obtained when one dice shows 1 and the other dice shows 2. That's why the first dice doesn't have any values it couldn't show and the second dice couldn't show 3.
Submitted Solution:
```
n,A = map(int,input().split())
arr = list(map(int,input().split()))
s = sum(arr)
for i in range(n):
v = s-arr[i]
if n-1>=A:
print(arr[i],end=' ')
else:
print(arr[i]-((min(A-(n-1),arr[i]))-max(1,A-v)+1),end=' ')
``` | instruction | 0 | 97,402 | 24 | 194,804 |
Yes | output | 1 | 97,402 | 24 | 194,805 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp has n dice d1, d2, ..., dn. The i-th dice shows numbers from 1 to di. Polycarp rolled all the dice and the sum of numbers they showed is A. Agrippina didn't see which dice showed what number, she knows only the sum A and the values d1, d2, ..., dn. However, she finds it enough to make a series of statements of the following type: dice i couldn't show number r. For example, if Polycarp had two six-faced dice and the total sum is A = 11, then Agrippina can state that each of the two dice couldn't show a value less than five (otherwise, the remaining dice must have a value of at least seven, which is impossible).
For each dice find the number of values for which it can be guaranteed that the dice couldn't show these values if the sum of the shown values is A.
Input
The first line contains two integers n, A (1 β€ n β€ 2Β·105, n β€ A β€ s) β the number of dice and the sum of shown values where s = d1 + d2 + ... + dn.
The second line contains n integers d1, d2, ..., dn (1 β€ di β€ 106), where di is the maximum value that the i-th dice can show.
Output
Print n integers b1, b2, ..., bn, where bi is the number of values for which it is guaranteed that the i-th dice couldn't show them.
Examples
Input
2 8
4 4
Output
3 3
Input
1 3
5
Output
4
Input
2 3
2 3
Output
0 1
Note
In the first sample from the statement A equal to 8 could be obtained in the only case when both the first and the second dice show 4. Correspondingly, both dice couldn't show values 1, 2 or 3.
In the second sample from the statement A equal to 3 could be obtained when the single dice shows 3. Correspondingly, it couldn't show 1, 2, 4 or 5.
In the third sample from the statement A equal to 3 could be obtained when one dice shows 1 and the other dice shows 2. That's why the first dice doesn't have any values it couldn't show and the second dice couldn't show 3.
Submitted Solution:
```
n, A = map(int,input().split())
kosti = list(map(int,input().split()))
summ = 0
temp = 0
for i in kosti:
summ += i
for i in kosti:
temp = summ - i
temp2 = min(A-(n-1),i)
ans = i - temp2 + max(0,A - temp - 1)
print(ans,end=" ")
``` | instruction | 0 | 97,403 | 24 | 194,806 |
Yes | output | 1 | 97,403 | 24 | 194,807 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp has n dice d1, d2, ..., dn. The i-th dice shows numbers from 1 to di. Polycarp rolled all the dice and the sum of numbers they showed is A. Agrippina didn't see which dice showed what number, she knows only the sum A and the values d1, d2, ..., dn. However, she finds it enough to make a series of statements of the following type: dice i couldn't show number r. For example, if Polycarp had two six-faced dice and the total sum is A = 11, then Agrippina can state that each of the two dice couldn't show a value less than five (otherwise, the remaining dice must have a value of at least seven, which is impossible).
For each dice find the number of values for which it can be guaranteed that the dice couldn't show these values if the sum of the shown values is A.
Input
The first line contains two integers n, A (1 β€ n β€ 2Β·105, n β€ A β€ s) β the number of dice and the sum of shown values where s = d1 + d2 + ... + dn.
The second line contains n integers d1, d2, ..., dn (1 β€ di β€ 106), where di is the maximum value that the i-th dice can show.
Output
Print n integers b1, b2, ..., bn, where bi is the number of values for which it is guaranteed that the i-th dice couldn't show them.
Examples
Input
2 8
4 4
Output
3 3
Input
1 3
5
Output
4
Input
2 3
2 3
Output
0 1
Note
In the first sample from the statement A equal to 8 could be obtained in the only case when both the first and the second dice show 4. Correspondingly, both dice couldn't show values 1, 2 or 3.
In the second sample from the statement A equal to 3 could be obtained when the single dice shows 3. Correspondingly, it couldn't show 1, 2, 4 or 5.
In the third sample from the statement A equal to 3 could be obtained when one dice shows 1 and the other dice shows 2. That's why the first dice doesn't have any values it couldn't show and the second dice couldn't show 3.
Submitted Solution:
```
r = lambda: map(int, input().split())
(n, a), d = r(), list(r()); s = sum(d)
[print(i - min(a - n + 1, i) + max(a - s + i, 1) - 1, end = ' ') for i in d]
``` | instruction | 0 | 97,404 | 24 | 194,808 |
Yes | output | 1 | 97,404 | 24 | 194,809 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp has n dice d1, d2, ..., dn. The i-th dice shows numbers from 1 to di. Polycarp rolled all the dice and the sum of numbers they showed is A. Agrippina didn't see which dice showed what number, she knows only the sum A and the values d1, d2, ..., dn. However, she finds it enough to make a series of statements of the following type: dice i couldn't show number r. For example, if Polycarp had two six-faced dice and the total sum is A = 11, then Agrippina can state that each of the two dice couldn't show a value less than five (otherwise, the remaining dice must have a value of at least seven, which is impossible).
For each dice find the number of values for which it can be guaranteed that the dice couldn't show these values if the sum of the shown values is A.
Input
The first line contains two integers n, A (1 β€ n β€ 2Β·105, n β€ A β€ s) β the number of dice and the sum of shown values where s = d1 + d2 + ... + dn.
The second line contains n integers d1, d2, ..., dn (1 β€ di β€ 106), where di is the maximum value that the i-th dice can show.
Output
Print n integers b1, b2, ..., bn, where bi is the number of values for which it is guaranteed that the i-th dice couldn't show them.
Examples
Input
2 8
4 4
Output
3 3
Input
1 3
5
Output
4
Input
2 3
2 3
Output
0 1
Note
In the first sample from the statement A equal to 8 could be obtained in the only case when both the first and the second dice show 4. Correspondingly, both dice couldn't show values 1, 2 or 3.
In the second sample from the statement A equal to 3 could be obtained when the single dice shows 3. Correspondingly, it couldn't show 1, 2, 4 or 5.
In the third sample from the statement A equal to 3 could be obtained when one dice shows 1 and the other dice shows 2. That's why the first dice doesn't have any values it couldn't show and the second dice couldn't show 3.
Submitted Solution:
```
n, a = map(int, input().split())
b = list(map(int, input().split()))
ans = []
k = a - (n - 1)
if n == 1:
print(b[0] - 1)
exit()
elif a % n == 0:
d = a // n
if b.count(d) == n:
ans = [d - 1] * n
print(*ans)
exit()
s = sum(b)
for i in range(n):
if k < b[i]:
ans.append(b[i] - k)
elif s - a < b[i]:
ans.append(b[i] - (s - a) - (n - 1))
else:
ans.append(0)
print(*ans)
``` | instruction | 0 | 97,405 | 24 | 194,810 |
No | output | 1 | 97,405 | 24 | 194,811 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp has n dice d1, d2, ..., dn. The i-th dice shows numbers from 1 to di. Polycarp rolled all the dice and the sum of numbers they showed is A. Agrippina didn't see which dice showed what number, she knows only the sum A and the values d1, d2, ..., dn. However, she finds it enough to make a series of statements of the following type: dice i couldn't show number r. For example, if Polycarp had two six-faced dice and the total sum is A = 11, then Agrippina can state that each of the two dice couldn't show a value less than five (otherwise, the remaining dice must have a value of at least seven, which is impossible).
For each dice find the number of values for which it can be guaranteed that the dice couldn't show these values if the sum of the shown values is A.
Input
The first line contains two integers n, A (1 β€ n β€ 2Β·105, n β€ A β€ s) β the number of dice and the sum of shown values where s = d1 + d2 + ... + dn.
The second line contains n integers d1, d2, ..., dn (1 β€ di β€ 106), where di is the maximum value that the i-th dice can show.
Output
Print n integers b1, b2, ..., bn, where bi is the number of values for which it is guaranteed that the i-th dice couldn't show them.
Examples
Input
2 8
4 4
Output
3 3
Input
1 3
5
Output
4
Input
2 3
2 3
Output
0 1
Note
In the first sample from the statement A equal to 8 could be obtained in the only case when both the first and the second dice show 4. Correspondingly, both dice couldn't show values 1, 2 or 3.
In the second sample from the statement A equal to 3 could be obtained when the single dice shows 3. Correspondingly, it couldn't show 1, 2, 4 or 5.
In the third sample from the statement A equal to 3 could be obtained when one dice shows 1 and the other dice shows 2. That's why the first dice doesn't have any values it couldn't show and the second dice couldn't show 3.
Submitted Solution:
```
n, a= list(map(int, input().split()))
b=[int(i) for i in input().split()]
s=a
for i in range(n):
print(max(min(s-1, b[i]-1),0), end=' ')
s-=b[i]
``` | instruction | 0 | 97,406 | 24 | 194,812 |
No | output | 1 | 97,406 | 24 | 194,813 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp has n dice d1, d2, ..., dn. The i-th dice shows numbers from 1 to di. Polycarp rolled all the dice and the sum of numbers they showed is A. Agrippina didn't see which dice showed what number, she knows only the sum A and the values d1, d2, ..., dn. However, she finds it enough to make a series of statements of the following type: dice i couldn't show number r. For example, if Polycarp had two six-faced dice and the total sum is A = 11, then Agrippina can state that each of the two dice couldn't show a value less than five (otherwise, the remaining dice must have a value of at least seven, which is impossible).
For each dice find the number of values for which it can be guaranteed that the dice couldn't show these values if the sum of the shown values is A.
Input
The first line contains two integers n, A (1 β€ n β€ 2Β·105, n β€ A β€ s) β the number of dice and the sum of shown values where s = d1 + d2 + ... + dn.
The second line contains n integers d1, d2, ..., dn (1 β€ di β€ 106), where di is the maximum value that the i-th dice can show.
Output
Print n integers b1, b2, ..., bn, where bi is the number of values for which it is guaranteed that the i-th dice couldn't show them.
Examples
Input
2 8
4 4
Output
3 3
Input
1 3
5
Output
4
Input
2 3
2 3
Output
0 1
Note
In the first sample from the statement A equal to 8 could be obtained in the only case when both the first and the second dice show 4. Correspondingly, both dice couldn't show values 1, 2 or 3.
In the second sample from the statement A equal to 3 could be obtained when the single dice shows 3. Correspondingly, it couldn't show 1, 2, 4 or 5.
In the third sample from the statement A equal to 3 could be obtained when one dice shows 1 and the other dice shows 2. That's why the first dice doesn't have any values it couldn't show and the second dice couldn't show 3.
Submitted Solution:
```
def subtract(a, b, k):
return abs(a+b-1-k)
x, y = map(int, input().split())
l = [int(x) for x in input().split()]
if x == 1:
print(l[0]-1)
else:
k = []
for z in l:
k.append(subtract(z, x, y))
print(*k)
``` | instruction | 0 | 97,407 | 24 | 194,814 |
No | output | 1 | 97,407 | 24 | 194,815 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp has n dice d1, d2, ..., dn. The i-th dice shows numbers from 1 to di. Polycarp rolled all the dice and the sum of numbers they showed is A. Agrippina didn't see which dice showed what number, she knows only the sum A and the values d1, d2, ..., dn. However, she finds it enough to make a series of statements of the following type: dice i couldn't show number r. For example, if Polycarp had two six-faced dice and the total sum is A = 11, then Agrippina can state that each of the two dice couldn't show a value less than five (otherwise, the remaining dice must have a value of at least seven, which is impossible).
For each dice find the number of values for which it can be guaranteed that the dice couldn't show these values if the sum of the shown values is A.
Input
The first line contains two integers n, A (1 β€ n β€ 2Β·105, n β€ A β€ s) β the number of dice and the sum of shown values where s = d1 + d2 + ... + dn.
The second line contains n integers d1, d2, ..., dn (1 β€ di β€ 106), where di is the maximum value that the i-th dice can show.
Output
Print n integers b1, b2, ..., bn, where bi is the number of values for which it is guaranteed that the i-th dice couldn't show them.
Examples
Input
2 8
4 4
Output
3 3
Input
1 3
5
Output
4
Input
2 3
2 3
Output
0 1
Note
In the first sample from the statement A equal to 8 could be obtained in the only case when both the first and the second dice show 4. Correspondingly, both dice couldn't show values 1, 2 or 3.
In the second sample from the statement A equal to 3 could be obtained when the single dice shows 3. Correspondingly, it couldn't show 1, 2, 4 or 5.
In the third sample from the statement A equal to 3 could be obtained when one dice shows 1 and the other dice shows 2. That's why the first dice doesn't have any values it couldn't show and the second dice couldn't show 3.
Submitted Solution:
```
n,a = map(int,input().split())
d = list(map(int,input().split()))
x = sum(d)
b = []
for i in range(n):
x -= d[i]
dif = 0
if a>x:
dif = a-x-1
if a-n+1<d[i]:
dif += d[i]-a+n
if x==0:
dif = d[i]-1
b.append(dif)
x += d[i]
print(' '.join(map(str,b)))
``` | instruction | 0 | 97,408 | 24 | 194,816 |
No | output | 1 | 97,408 | 24 | 194,817 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp has a lot of work to do. Recently he has learned a new time management rule: "if a task takes five minutes or less, do it immediately". Polycarp likes the new rule, however he is not sure that five minutes is the optimal value. He supposes that this value d should be chosen based on existing task list.
Polycarp has a list of n tasks to complete. The i-th task has difficulty p_i, i.e. it requires exactly p_i minutes to be done. Polycarp reads the tasks one by one from the first to the n-th. If a task difficulty is d or less, Polycarp starts the work on the task immediately. If a task difficulty is strictly greater than d, he will not do the task at all. It is not allowed to rearrange tasks in the list. Polycarp doesn't spend any time for reading a task or skipping it.
Polycarp has t minutes in total to complete maximum number of tasks. But he does not want to work all the time. He decides to make a break after each group of m consecutive tasks he was working on. The break should take the same amount of time as it was spent in total on completion of these m tasks.
For example, if n=7, p=[3, 1, 4, 1, 5, 9, 2], d=3 and m=2 Polycarp works by the following schedule:
* Polycarp reads the first task, its difficulty is not greater than d (p_1=3 β€ d=3) and works for 3 minutes (i.e. the minutes 1, 2, 3);
* Polycarp reads the second task, its difficulty is not greater than d (p_2=1 β€ d=3) and works for 1 minute (i.e. the minute 4);
* Polycarp notices that he has finished m=2 tasks and takes a break for 3+1=4 minutes (i.e. on the minutes 5, 6, 7, 8);
* Polycarp reads the third task, its difficulty is greater than d (p_3=4 > d=3) and skips it without spending any time;
* Polycarp reads the fourth task, its difficulty is not greater than d (p_4=1 β€ d=3) and works for 1 minute (i.e. the minute 9);
* Polycarp reads the tasks 5 and 6, skips both of them (p_5>d and p_6>d);
* Polycarp reads the 7-th task, its difficulty is not greater than d (p_7=2 β€ d=3) and works for 2 minutes (i.e. the minutes 10, 11);
* Polycarp notices that he has finished m=2 tasks and takes a break for 1+2=3 minutes (i.e. on the minutes 12, 13, 14).
Polycarp stops exactly after t minutes. If Polycarp started a task but has not finished it by that time, the task is not considered as completed. It is allowed to complete less than m tasks in the last group. Also Polycarp considers acceptable to have shorter break than needed after the last group of tasks or even not to have this break at all β his working day is over and he will have enough time to rest anyway.
Please help Polycarp to find such value d, which would allow him to complete maximum possible number of tasks in t minutes.
Input
The first line of the input contains single integer c (1 β€ c β€ 5 β
10^4) β number of test cases. Then description of c test cases follows. Solve test cases separately, test cases are completely independent and do not affect each other.
Each test case is described by two lines. The first of these lines contains three space-separated integers n, m and t (1 β€ n β€ 2 β
10^5, 1 β€ m β€ 2 β
10^5, 1 β€ t β€ 4 β
10^{10}) β the number of tasks in Polycarp's list, the number of tasks he can do without a break and the total amount of time Polycarp can work on tasks. The second line of the test case contains n space separated integers p_1, p_2, ..., p_n (1 β€ p_i β€ 2 β
10^5) β difficulties of the tasks.
The sum of values n for all test cases in the input does not exceed 2 β
10^5.
Output
Print c lines, each line should contain answer for the corresponding test case β the maximum possible number of tasks Polycarp can complete and the integer value d (1 β€ d β€ t) Polycarp should use in time management rule, separated by space. If there are several possible values d for a test case, output any of them.
Examples
Input
4
5 2 16
5 6 1 4 7
5 3 30
5 6 1 4 7
6 4 15
12 5 15 7 20 17
1 1 50
100
Output
3 5
4 7
2 10
0 25
Input
3
11 1 29
6 4 3 7 5 3 4 7 3 5 3
7 1 5
1 1 1 1 1 1 1
5 2 18
2 3 3 7 5
Output
4 3
3 1
4 5
Note
In the first test case of the first example n=5, m=2 and t=16. The sequence of difficulties is [5, 6, 1, 4, 7]. If Polycarp chooses d=5 then he will complete 3 tasks. Polycarp will work by the following schedule:
* Polycarp reads the first task, its difficulty is not greater than d (p_1=5 β€ d=5) and works for 5 minutes (i.e. the minutes 1, 2, ..., 5);
* Polycarp reads the second task, its difficulty is greater than d (p_2=6 > d=5) and skips it without spending any time;
* Polycarp reads the third task, its difficulty is not greater than d (p_3=1 β€ d=5) and works for 1 minute (i.e. the minute 6);
* Polycarp notices that he has finished m=2 tasks and takes a break for 5+1=6 minutes (i.e. on the minutes 7, 8, ..., 12);
* Polycarp reads the fourth task, its difficulty is not greater than d (p_4=4 β€ d=5) and works for 4 minutes (i.e. the minutes 13, 14, 15, 16);
* Polycarp stops work because of t=16.
In total in the first test case Polycarp will complete 3 tasks for d=5. He can't choose other value for d to increase the number of completed tasks. | instruction | 0 | 97,853 | 24 | 195,706 |
Tags: binary search, data structures
Correct Solution:
```
import io, os
input = io.StringIO(os.read(0, os.fstat(0).st_size).decode()).readline
ii = lambda: int(input())
mi = lambda: map(int, input().split())
li = lambda: list(mi())
out = []
for _ in range(ii()):
n, m, t = mi()
p = li()
def check(d):
cur = tim = tot = totim = 0
for i in range(n):
x = p[i]
if x > d: continue
totim += x
tim += x
if totim > t: break
cur += 1
tot += 1
if cur == m:
totim += tim
if totim > t: break
cur = tim = 0
return all(x > d for x in p[i+1:]), tot
lo, hi = 1, t
while lo < hi:
mid = (lo + hi + 1) >> 1
if check(mid)[0]:
lo = mid
else:
hi = mid - 1
if check(lo + 1)[1] > check(lo)[1]:
lo += 1
out.append('%d %d' % (check(lo)[1], lo))
print(*out, sep='\n')
``` | output | 1 | 97,853 | 24 | 195,707 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp has a lot of work to do. Recently he has learned a new time management rule: "if a task takes five minutes or less, do it immediately". Polycarp likes the new rule, however he is not sure that five minutes is the optimal value. He supposes that this value d should be chosen based on existing task list.
Polycarp has a list of n tasks to complete. The i-th task has difficulty p_i, i.e. it requires exactly p_i minutes to be done. Polycarp reads the tasks one by one from the first to the n-th. If a task difficulty is d or less, Polycarp starts the work on the task immediately. If a task difficulty is strictly greater than d, he will not do the task at all. It is not allowed to rearrange tasks in the list. Polycarp doesn't spend any time for reading a task or skipping it.
Polycarp has t minutes in total to complete maximum number of tasks. But he does not want to work all the time. He decides to make a break after each group of m consecutive tasks he was working on. The break should take the same amount of time as it was spent in total on completion of these m tasks.
For example, if n=7, p=[3, 1, 4, 1, 5, 9, 2], d=3 and m=2 Polycarp works by the following schedule:
* Polycarp reads the first task, its difficulty is not greater than d (p_1=3 β€ d=3) and works for 3 minutes (i.e. the minutes 1, 2, 3);
* Polycarp reads the second task, its difficulty is not greater than d (p_2=1 β€ d=3) and works for 1 minute (i.e. the minute 4);
* Polycarp notices that he has finished m=2 tasks and takes a break for 3+1=4 minutes (i.e. on the minutes 5, 6, 7, 8);
* Polycarp reads the third task, its difficulty is greater than d (p_3=4 > d=3) and skips it without spending any time;
* Polycarp reads the fourth task, its difficulty is not greater than d (p_4=1 β€ d=3) and works for 1 minute (i.e. the minute 9);
* Polycarp reads the tasks 5 and 6, skips both of them (p_5>d and p_6>d);
* Polycarp reads the 7-th task, its difficulty is not greater than d (p_7=2 β€ d=3) and works for 2 minutes (i.e. the minutes 10, 11);
* Polycarp notices that he has finished m=2 tasks and takes a break for 1+2=3 minutes (i.e. on the minutes 12, 13, 14).
Polycarp stops exactly after t minutes. If Polycarp started a task but has not finished it by that time, the task is not considered as completed. It is allowed to complete less than m tasks in the last group. Also Polycarp considers acceptable to have shorter break than needed after the last group of tasks or even not to have this break at all β his working day is over and he will have enough time to rest anyway.
Please help Polycarp to find such value d, which would allow him to complete maximum possible number of tasks in t minutes.
Input
The first line of the input contains single integer c (1 β€ c β€ 5 β
10^4) β number of test cases. Then description of c test cases follows. Solve test cases separately, test cases are completely independent and do not affect each other.
Each test case is described by two lines. The first of these lines contains three space-separated integers n, m and t (1 β€ n β€ 2 β
10^5, 1 β€ m β€ 2 β
10^5, 1 β€ t β€ 4 β
10^{10}) β the number of tasks in Polycarp's list, the number of tasks he can do without a break and the total amount of time Polycarp can work on tasks. The second line of the test case contains n space separated integers p_1, p_2, ..., p_n (1 β€ p_i β€ 2 β
10^5) β difficulties of the tasks.
The sum of values n for all test cases in the input does not exceed 2 β
10^5.
Output
Print c lines, each line should contain answer for the corresponding test case β the maximum possible number of tasks Polycarp can complete and the integer value d (1 β€ d β€ t) Polycarp should use in time management rule, separated by space. If there are several possible values d for a test case, output any of them.
Examples
Input
4
5 2 16
5 6 1 4 7
5 3 30
5 6 1 4 7
6 4 15
12 5 15 7 20 17
1 1 50
100
Output
3 5
4 7
2 10
0 25
Input
3
11 1 29
6 4 3 7 5 3 4 7 3 5 3
7 1 5
1 1 1 1 1 1 1
5 2 18
2 3 3 7 5
Output
4 3
3 1
4 5
Note
In the first test case of the first example n=5, m=2 and t=16. The sequence of difficulties is [5, 6, 1, 4, 7]. If Polycarp chooses d=5 then he will complete 3 tasks. Polycarp will work by the following schedule:
* Polycarp reads the first task, its difficulty is not greater than d (p_1=5 β€ d=5) and works for 5 minutes (i.e. the minutes 1, 2, ..., 5);
* Polycarp reads the second task, its difficulty is greater than d (p_2=6 > d=5) and skips it without spending any time;
* Polycarp reads the third task, its difficulty is not greater than d (p_3=1 β€ d=5) and works for 1 minute (i.e. the minute 6);
* Polycarp notices that he has finished m=2 tasks and takes a break for 5+1=6 minutes (i.e. on the minutes 7, 8, ..., 12);
* Polycarp reads the fourth task, its difficulty is not greater than d (p_4=4 β€ d=5) and works for 4 minutes (i.e. the minutes 13, 14, 15, 16);
* Polycarp stops work because of t=16.
In total in the first test case Polycarp will complete 3 tasks for d=5. He can't choose other value for d to increase the number of completed tasks.
Submitted Solution:
```
ANS = """3 5
4 7
2 10
0 25"""
print(ANS)
``` | instruction | 0 | 97,854 | 24 | 195,708 |
No | output | 1 | 97,854 | 24 | 195,709 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp has a lot of work to do. Recently he has learned a new time management rule: "if a task takes five minutes or less, do it immediately". Polycarp likes the new rule, however he is not sure that five minutes is the optimal value. He supposes that this value d should be chosen based on existing task list.
Polycarp has a list of n tasks to complete. The i-th task has difficulty p_i, i.e. it requires exactly p_i minutes to be done. Polycarp reads the tasks one by one from the first to the n-th. If a task difficulty is d or less, Polycarp starts the work on the task immediately. If a task difficulty is strictly greater than d, he will not do the task at all. It is not allowed to rearrange tasks in the list. Polycarp doesn't spend any time for reading a task or skipping it.
Polycarp has t minutes in total to complete maximum number of tasks. But he does not want to work all the time. He decides to make a break after each group of m consecutive tasks he was working on. The break should take the same amount of time as it was spent in total on completion of these m tasks.
For example, if n=7, p=[3, 1, 4, 1, 5, 9, 2], d=3 and m=2 Polycarp works by the following schedule:
* Polycarp reads the first task, its difficulty is not greater than d (p_1=3 β€ d=3) and works for 3 minutes (i.e. the minutes 1, 2, 3);
* Polycarp reads the second task, its difficulty is not greater than d (p_2=1 β€ d=3) and works for 1 minute (i.e. the minute 4);
* Polycarp notices that he has finished m=2 tasks and takes a break for 3+1=4 minutes (i.e. on the minutes 5, 6, 7, 8);
* Polycarp reads the third task, its difficulty is greater than d (p_3=4 > d=3) and skips it without spending any time;
* Polycarp reads the fourth task, its difficulty is not greater than d (p_4=1 β€ d=3) and works for 1 minute (i.e. the minute 9);
* Polycarp reads the tasks 5 and 6, skips both of them (p_5>d and p_6>d);
* Polycarp reads the 7-th task, its difficulty is not greater than d (p_7=2 β€ d=3) and works for 2 minutes (i.e. the minutes 10, 11);
* Polycarp notices that he has finished m=2 tasks and takes a break for 1+2=3 minutes (i.e. on the minutes 12, 13, 14).
Polycarp stops exactly after t minutes. If Polycarp started a task but has not finished it by that time, the task is not considered as completed. It is allowed to complete less than m tasks in the last group. Also Polycarp considers acceptable to have shorter break than needed after the last group of tasks or even not to have this break at all β his working day is over and he will have enough time to rest anyway.
Please help Polycarp to find such value d, which would allow him to complete maximum possible number of tasks in t minutes.
Input
The first line of the input contains single integer c (1 β€ c β€ 5 β
10^4) β number of test cases. Then description of c test cases follows. Solve test cases separately, test cases are completely independent and do not affect each other.
Each test case is described by two lines. The first of these lines contains three space-separated integers n, m and t (1 β€ n β€ 2 β
10^5, 1 β€ m β€ 2 β
10^5, 1 β€ t β€ 4 β
10^{10}) β the number of tasks in Polycarp's list, the number of tasks he can do without a break and the total amount of time Polycarp can work on tasks. The second line of the test case contains n space separated integers p_1, p_2, ..., p_n (1 β€ p_i β€ 2 β
10^5) β difficulties of the tasks.
The sum of values n for all test cases in the input does not exceed 2 β
10^5.
Output
Print c lines, each line should contain answer for the corresponding test case β the maximum possible number of tasks Polycarp can complete and the integer value d (1 β€ d β€ t) Polycarp should use in time management rule, separated by space. If there are several possible values d for a test case, output any of them.
Examples
Input
4
5 2 16
5 6 1 4 7
5 3 30
5 6 1 4 7
6 4 15
12 5 15 7 20 17
1 1 50
100
Output
3 5
4 7
2 10
0 25
Input
3
11 1 29
6 4 3 7 5 3 4 7 3 5 3
7 1 5
1 1 1 1 1 1 1
5 2 18
2 3 3 7 5
Output
4 3
3 1
4 5
Note
In the first test case of the first example n=5, m=2 and t=16. The sequence of difficulties is [5, 6, 1, 4, 7]. If Polycarp chooses d=5 then he will complete 3 tasks. Polycarp will work by the following schedule:
* Polycarp reads the first task, its difficulty is not greater than d (p_1=5 β€ d=5) and works for 5 minutes (i.e. the minutes 1, 2, ..., 5);
* Polycarp reads the second task, its difficulty is greater than d (p_2=6 > d=5) and skips it without spending any time;
* Polycarp reads the third task, its difficulty is not greater than d (p_3=1 β€ d=5) and works for 1 minute (i.e. the minute 6);
* Polycarp notices that he has finished m=2 tasks and takes a break for 5+1=6 minutes (i.e. on the minutes 7, 8, ..., 12);
* Polycarp reads the fourth task, its difficulty is not greater than d (p_4=4 β€ d=5) and works for 4 minutes (i.e. the minutes 13, 14, 15, 16);
* Polycarp stops work because of t=16.
In total in the first test case Polycarp will complete 3 tasks for d=5. He can't choose other value for d to increase the number of completed tasks.
Submitted Solution:
```
import io, os
input = io.StringIO(os.read(0, os.fstat(0).st_size).decode()).readline
ii = lambda: int(input())
mi = lambda: map(int, input().split())
li = lambda: list(mi())
out = []
for _ in range(ii()):
n, m, t = mi()
p = li()
def check(d):
cur = tim = tot = totim = 0
for i in range(n):
x = p[i]
if x > d: continue
totim += x
tim += x
if totim > t: break
cur += 1
tot += 1
if cur == m:
totim += tim
if totim > t: break
cur = tim = 0
return all(x > d for x in p[i+1:]), tot
lo, hi = 1, t
while lo < hi:
mid = (lo + hi + 1) >> 1
if check(mid)[0]:
lo = mid
else:
hi = mid - 1
if check(hi)[1] > check(lo)[1]:
lo = hi
out.append('%d %d' % (check(lo)[1], lo))
print(*out, sep='\n')
``` | instruction | 0 | 97,855 | 24 | 195,710 |
No | output | 1 | 97,855 | 24 | 195,711 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.