text stringlengths 1.02k 43.5k | conversation_id int64 853 107k | embedding list | cluster int64 24 24 |
|---|---|---|---|
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarpus has 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.
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')
```
| 97,268 | [
0.4033203125,
0.359375,
0.257080078125,
-0.0595703125,
-0.330810546875,
-0.1614990234375,
-0.52880859375,
0.036895751953125,
-0.0439453125,
0.75439453125,
0.65625,
-0.197998046875,
0.00933074951171875,
-0.39013671875,
-0.52978515625,
-0.1575927734375,
-0.4482421875,
-0.364990234375... | 24 |
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.
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 = " ")
```
| 97,269 | [
0.4033203125,
0.359375,
0.257080078125,
-0.0595703125,
-0.330810546875,
-0.1614990234375,
-0.52880859375,
0.036895751953125,
-0.0439453125,
0.75439453125,
0.65625,
-0.197998046875,
0.00933074951171875,
-0.39013671875,
-0.52978515625,
-0.1575927734375,
-0.4482421875,
-0.364990234375... | 24 |
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.
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=" ")
```
| 97,270 | [
0.4033203125,
0.359375,
0.257080078125,
-0.0595703125,
-0.330810546875,
-0.1614990234375,
-0.52880859375,
0.036895751953125,
-0.0439453125,
0.75439453125,
0.65625,
-0.197998046875,
0.00933074951171875,
-0.39013671875,
-0.52978515625,
-0.1575927734375,
-0.4482421875,
-0.364990234375... | 24 |
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.
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 )
```
| 97,271 | [
0.4033203125,
0.359375,
0.257080078125,
-0.0595703125,
-0.330810546875,
-0.1614990234375,
-0.52880859375,
0.036895751953125,
-0.0439453125,
0.75439453125,
0.65625,
-0.197998046875,
0.00933074951171875,
-0.39013671875,
-0.52978515625,
-0.1575927734375,
-0.4482421875,
-0.364990234375... | 24 |
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.
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))
```
| 97,272 | [
0.4033203125,
0.359375,
0.257080078125,
-0.0595703125,
-0.330810546875,
-0.1614990234375,
-0.52880859375,
0.036895751953125,
-0.0439453125,
0.75439453125,
0.65625,
-0.197998046875,
0.00933074951171875,
-0.39013671875,
-0.52978515625,
-0.1575927734375,
-0.4482421875,
-0.364990234375... | 24 |
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.
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();
```
| 97,273 | [
0.4033203125,
0.359375,
0.257080078125,
-0.0595703125,
-0.330810546875,
-0.1614990234375,
-0.52880859375,
0.036895751953125,
-0.0439453125,
0.75439453125,
0.65625,
-0.197998046875,
0.00933074951171875,
-0.39013671875,
-0.52978515625,
-0.1575927734375,
-0.4482421875,
-0.364990234375... | 24 |
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.
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)
```
| 97,274 | [
0.4033203125,
0.359375,
0.257080078125,
-0.0595703125,
-0.330810546875,
-0.1614990234375,
-0.52880859375,
0.036895751953125,
-0.0439453125,
0.75439453125,
0.65625,
-0.197998046875,
0.00933074951171875,
-0.39013671875,
-0.52978515625,
-0.1575927734375,
-0.4482421875,
-0.364990234375... | 24 |
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)
```
Yes
| 97,275 | [
0.473876953125,
0.449462890625,
0.216796875,
-0.053680419921875,
-0.392822265625,
-0.0638427734375,
-0.580078125,
0.1380615234375,
-0.00495147705078125,
0.72265625,
0.53466796875,
-0.155517578125,
-0.04876708984375,
-0.362060546875,
-0.517578125,
-0.1533203125,
-0.44091796875,
-0.3... | 24 |
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
```
Yes
| 97,276 | [
0.473876953125,
0.449462890625,
0.216796875,
-0.053680419921875,
-0.392822265625,
-0.0638427734375,
-0.580078125,
0.1380615234375,
-0.00495147705078125,
0.72265625,
0.53466796875,
-0.155517578125,
-0.04876708984375,
-0.362060546875,
-0.517578125,
-0.1533203125,
-0.44091796875,
-0.3... | 24 |
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)
```
Yes
| 97,277 | [
0.473876953125,
0.449462890625,
0.216796875,
-0.053680419921875,
-0.392822265625,
-0.0638427734375,
-0.580078125,
0.1380615234375,
-0.00495147705078125,
0.72265625,
0.53466796875,
-0.155517578125,
-0.04876708984375,
-0.362060546875,
-0.517578125,
-0.1533203125,
-0.44091796875,
-0.3... | 24 |
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)
```
Yes
| 97,278 | [
0.473876953125,
0.449462890625,
0.216796875,
-0.053680419921875,
-0.392822265625,
-0.0638427734375,
-0.580078125,
0.1380615234375,
-0.00495147705078125,
0.72265625,
0.53466796875,
-0.155517578125,
-0.04876708984375,
-0.362060546875,
-0.517578125,
-0.1533203125,
-0.44091796875,
-0.3... | 24 |
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)
```
No
| 97,279 | [
0.473876953125,
0.449462890625,
0.216796875,
-0.053680419921875,
-0.392822265625,
-0.0638427734375,
-0.580078125,
0.1380615234375,
-0.00495147705078125,
0.72265625,
0.53466796875,
-0.155517578125,
-0.04876708984375,
-0.362060546875,
-0.517578125,
-0.1533203125,
-0.44091796875,
-0.3... | 24 |
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))
```
No
| 97,280 | [
0.473876953125,
0.449462890625,
0.216796875,
-0.053680419921875,
-0.392822265625,
-0.0638427734375,
-0.580078125,
0.1380615234375,
-0.00495147705078125,
0.72265625,
0.53466796875,
-0.155517578125,
-0.04876708984375,
-0.362060546875,
-0.517578125,
-0.1533203125,
-0.44091796875,
-0.3... | 24 |
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))
```
No
| 97,281 | [
0.473876953125,
0.449462890625,
0.216796875,
-0.053680419921875,
-0.392822265625,
-0.0638427734375,
-0.580078125,
0.1380615234375,
-0.00495147705078125,
0.72265625,
0.53466796875,
-0.155517578125,
-0.04876708984375,
-0.362060546875,
-0.517578125,
-0.1533203125,
-0.44091796875,
-0.3... | 24 |
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)
```
No
| 97,282 | [
0.473876953125,
0.449462890625,
0.216796875,
-0.053680419921875,
-0.392822265625,
-0.0638427734375,
-0.580078125,
0.1380615234375,
-0.00495147705078125,
0.72265625,
0.53466796875,
-0.155517578125,
-0.04876708984375,
-0.362060546875,
-0.517578125,
-0.1533203125,
-0.44091796875,
-0.3... | 24 |
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
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
```
| 97,329 | [
0.56982421875,
0.219970703125,
0.068115234375,
-0.029388427734375,
-0.331298828125,
-0.521484375,
-0.53125,
0.2880859375,
0.289794921875,
0.75244140625,
0.623046875,
-0.19140625,
0.4658203125,
-0.71240234375,
-0.4462890625,
-0.265869140625,
-0.83642578125,
-0.52587890625,
-0.7578... | 24 |
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
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
```
| 97,330 | [
0.57373046875,
0.202880859375,
-0.01296234130859375,
-0.01479339599609375,
-0.306396484375,
-0.4833984375,
-0.490478515625,
0.314208984375,
0.2841796875,
0.7734375,
0.64404296875,
-0.225341796875,
0.50048828125,
-0.669921875,
-0.410888671875,
-0.283203125,
-0.78955078125,
-0.471435... | 24 |
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
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])
```
| 97,331 | [
0.56201171875,
0.20361328125,
0.0675048828125,
-0.002063751220703125,
-0.292724609375,
-0.55810546875,
-0.515625,
0.272216796875,
0.28662109375,
0.7890625,
0.65771484375,
-0.1495361328125,
0.490966796875,
-0.697265625,
-0.38916015625,
-0.285888671875,
-0.8134765625,
-0.47314453125,... | 24 |
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
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)
```
| 97,332 | [
0.51953125,
0.1773681640625,
0.047515869140625,
0.0124664306640625,
-0.298828125,
-0.54296875,
-0.484619140625,
0.32861328125,
0.2408447265625,
0.7451171875,
0.7109375,
-0.21533203125,
0.40478515625,
-0.6787109375,
-0.370849609375,
-0.2064208984375,
-0.80029296875,
-0.53369140625,
... | 24 |
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
Tags: implementation
Correct Solution:
```
n=int(input())
arr=list(map(int,input().split()))
print(int((n*(n+1))/2)-sum(arr))
```
| 97,333 | [
0.56591796875,
0.2081298828125,
0.0230560302734375,
-0.03033447265625,
-0.261474609375,
-0.5595703125,
-0.4873046875,
0.2763671875,
0.297119140625,
0.72900390625,
0.68359375,
-0.1514892578125,
0.494384765625,
-0.6962890625,
-0.41357421875,
-0.239990234375,
-0.7734375,
-0.5004882812... | 24 |
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
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)
```
| 97,334 | [
0.591796875,
0.1748046875,
0.041961669921875,
-0.0080413818359375,
-0.279541015625,
-0.53125,
-0.450439453125,
0.26416015625,
0.297607421875,
0.708984375,
0.64453125,
-0.23193359375,
0.467041015625,
-0.6484375,
-0.4482421875,
-0.2724609375,
-0.791015625,
-0.479248046875,
-0.70800... | 24 |
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
Tags: implementation
Correct Solution:
```
n = int(input()); print(int((1+n)/2*n-sum(list(map(int,input().split())))))
```
| 97,335 | [
0.58837890625,
0.198974609375,
0.028289794921875,
-0.0042266845703125,
-0.26513671875,
-0.56298828125,
-0.43994140625,
0.254638671875,
0.290771484375,
0.71630859375,
0.7021484375,
-0.1494140625,
0.47900390625,
-0.6767578125,
-0.44140625,
-0.2420654296875,
-0.7724609375,
-0.49511718... | 24 |
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
Tags: implementation
Correct Solution:
```
n = int(input())
e = list(map(int,input().split()))
print(int(n*(n+1)/2)-sum(e))
```
| 97,336 | [
0.5732421875,
0.2099609375,
0.0226593017578125,
-0.0257110595703125,
-0.263671875,
-0.5654296875,
-0.481689453125,
0.26904296875,
0.303955078125,
0.740234375,
0.6640625,
-0.1568603515625,
0.509765625,
-0.67822265625,
-0.417236328125,
-0.240478515625,
-0.791015625,
-0.5107421875,
... | 24 |
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)
```
Yes
| 97,337 | [
0.56591796875,
0.28857421875,
0.024322509765625,
0.0039005279541015625,
-0.396240234375,
-0.33740234375,
-0.60205078125,
0.3974609375,
0.2208251953125,
0.78955078125,
0.65087890625,
-0.150634765625,
0.42578125,
-0.74560546875,
-0.414794921875,
-0.31884765625,
-0.7216796875,
-0.4836... | 24 |
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)
```
Yes
| 97,338 | [
0.60009765625,
0.340087890625,
-0.0055999755859375,
0.019989013671875,
-0.31884765625,
-0.429443359375,
-0.55615234375,
0.394775390625,
0.209228515625,
0.7578125,
0.732421875,
-0.06103515625,
0.4208984375,
-0.76025390625,
-0.409912109375,
-0.2203369140625,
-0.71435546875,
-0.513671... | 24 |
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
```
Yes
| 97,339 | [
0.59619140625,
0.265869140625,
-0.0167694091796875,
0.006076812744140625,
-0.37255859375,
-0.346923828125,
-0.578125,
0.396240234375,
0.2183837890625,
0.79443359375,
0.68212890625,
-0.12432861328125,
0.446533203125,
-0.76806640625,
-0.401611328125,
-0.278076171875,
-0.71142578125,
... | 24 |
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))
```
Yes
| 97,340 | [
0.59814453125,
0.282470703125,
0.0222015380859375,
0.007099151611328125,
-0.366943359375,
-0.39453125,
-0.5859375,
0.3798828125,
0.222900390625,
0.77099609375,
0.67578125,
-0.09442138671875,
0.428955078125,
-0.740234375,
-0.3759765625,
-0.2457275390625,
-0.73681640625,
-0.491943359... | 24 |
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)
```
No
| 97,341 | [
0.5859375,
0.31640625,
-0.0396728515625,
0.01538848876953125,
-0.32275390625,
-0.441650390625,
-0.55029296875,
0.405517578125,
0.222900390625,
0.763671875,
0.7314453125,
-0.1014404296875,
0.419677734375,
-0.7802734375,
-0.410888671875,
-0.2486572265625,
-0.70751953125,
-0.514648437... | 24 |
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)
```
No
| 97,342 | [
0.5771484375,
0.198974609375,
-0.0116424560546875,
0.030120849609375,
-0.35009765625,
-0.380126953125,
-0.56640625,
0.410400390625,
0.21875,
0.81982421875,
0.70458984375,
-0.1221923828125,
0.42578125,
-0.79150390625,
-0.36474609375,
-0.27294921875,
-0.70458984375,
-0.51708984375,
... | 24 |
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)
```
No
| 97,343 | [
0.57470703125,
0.31201171875,
-0.035308837890625,
0.0158233642578125,
-0.35400390625,
-0.390625,
-0.595703125,
0.410400390625,
0.181396484375,
0.79736328125,
0.70068359375,
-0.1251220703125,
0.40087890625,
-0.75439453125,
-0.372314453125,
-0.26708984375,
-0.70654296875,
-0.50732421... | 24 |
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
```
No
| 97,344 | [
0.56494140625,
0.260498046875,
0.053314208984375,
0.01056671142578125,
-0.41748046875,
-0.366455078125,
-0.56103515625,
0.40869140625,
0.222900390625,
0.8017578125,
0.62060546875,
-0.1357421875,
0.343017578125,
-0.7734375,
-0.46337890625,
-0.2685546875,
-0.806640625,
-0.4677734375,... | 24 |
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.
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))
```
| 97,393 | [
0.3720703125,
-0.23828125,
0.4921875,
-0.08502197265625,
-0.6943359375,
-0.75341796875,
-0.1495361328125,
0.1669921875,
-0.06524658203125,
0.65673828125,
1.00390625,
-0.359375,
0.369140625,
-0.34228515625,
-0.45458984375,
0.204345703125,
-0.626953125,
-0.6728515625,
-0.5043945312... | 24 |
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.
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=' ')
```
| 97,394 | [
0.3720703125,
-0.23828125,
0.4921875,
-0.08502197265625,
-0.6943359375,
-0.75341796875,
-0.1495361328125,
0.1669921875,
-0.06524658203125,
0.65673828125,
1.00390625,
-0.359375,
0.369140625,
-0.34228515625,
-0.45458984375,
0.204345703125,
-0.626953125,
-0.6728515625,
-0.5043945312... | 24 |
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.
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)
```
| 97,395 | [
0.3720703125,
-0.23828125,
0.4921875,
-0.08502197265625,
-0.6943359375,
-0.75341796875,
-0.1495361328125,
0.1669921875,
-0.06524658203125,
0.65673828125,
1.00390625,
-0.359375,
0.369140625,
-0.34228515625,
-0.45458984375,
0.204345703125,
-0.626953125,
-0.6728515625,
-0.5043945312... | 24 |
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.
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)
```
| 97,396 | [
0.3720703125,
-0.23828125,
0.4921875,
-0.08502197265625,
-0.6943359375,
-0.75341796875,
-0.1495361328125,
0.1669921875,
-0.06524658203125,
0.65673828125,
1.00390625,
-0.359375,
0.369140625,
-0.34228515625,
-0.45458984375,
0.204345703125,
-0.626953125,
-0.6728515625,
-0.5043945312... | 24 |
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.
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)))
```
| 97,397 | [
0.3720703125,
-0.23828125,
0.4921875,
-0.08502197265625,
-0.6943359375,
-0.75341796875,
-0.1495361328125,
0.1669921875,
-0.06524658203125,
0.65673828125,
1.00390625,
-0.359375,
0.369140625,
-0.34228515625,
-0.45458984375,
0.204345703125,
-0.626953125,
-0.6728515625,
-0.5043945312... | 24 |
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.
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)
```
| 97,398 | [
0.3720703125,
-0.23828125,
0.4921875,
-0.08502197265625,
-0.6943359375,
-0.75341796875,
-0.1495361328125,
0.1669921875,
-0.06524658203125,
0.65673828125,
1.00390625,
-0.359375,
0.369140625,
-0.34228515625,
-0.45458984375,
0.204345703125,
-0.626953125,
-0.6728515625,
-0.5043945312... | 24 |
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.
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()
```
| 97,399 | [
0.3720703125,
-0.23828125,
0.4921875,
-0.08502197265625,
-0.6943359375,
-0.75341796875,
-0.1495361328125,
0.1669921875,
-0.06524658203125,
0.65673828125,
1.00390625,
-0.359375,
0.369140625,
-0.34228515625,
-0.45458984375,
0.204345703125,
-0.626953125,
-0.6728515625,
-0.5043945312... | 24 |
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.
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()
```
| 97,400 | [
0.3720703125,
-0.23828125,
0.4921875,
-0.08502197265625,
-0.6943359375,
-0.75341796875,
-0.1495361328125,
0.1669921875,
-0.06524658203125,
0.65673828125,
1.00390625,
-0.359375,
0.369140625,
-0.34228515625,
-0.45458984375,
0.204345703125,
-0.626953125,
-0.6728515625,
-0.5043945312... | 24 |
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)))
```
Yes
| 97,401 | [
0.496826171875,
-0.223388671875,
0.388916015625,
-0.10479736328125,
-0.77490234375,
-0.62939453125,
-0.2225341796875,
0.24169921875,
-0.072265625,
0.6572265625,
0.904296875,
-0.327392578125,
0.3193359375,
-0.304443359375,
-0.41162109375,
0.1739501953125,
-0.58935546875,
-0.63671875... | 24 |
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=' ')
```
Yes
| 97,402 | [
0.496826171875,
-0.223388671875,
0.388916015625,
-0.10479736328125,
-0.77490234375,
-0.62939453125,
-0.2225341796875,
0.24169921875,
-0.072265625,
0.6572265625,
0.904296875,
-0.327392578125,
0.3193359375,
-0.304443359375,
-0.41162109375,
0.1739501953125,
-0.58935546875,
-0.63671875... | 24 |
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=" ")
```
Yes
| 97,403 | [
0.496826171875,
-0.223388671875,
0.388916015625,
-0.10479736328125,
-0.77490234375,
-0.62939453125,
-0.2225341796875,
0.24169921875,
-0.072265625,
0.6572265625,
0.904296875,
-0.327392578125,
0.3193359375,
-0.304443359375,
-0.41162109375,
0.1739501953125,
-0.58935546875,
-0.63671875... | 24 |
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]
```
Yes
| 97,404 | [
0.496826171875,
-0.223388671875,
0.388916015625,
-0.10479736328125,
-0.77490234375,
-0.62939453125,
-0.2225341796875,
0.24169921875,
-0.072265625,
0.6572265625,
0.904296875,
-0.327392578125,
0.3193359375,
-0.304443359375,
-0.41162109375,
0.1739501953125,
-0.58935546875,
-0.63671875... | 24 |
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)
```
No
| 97,405 | [
0.496826171875,
-0.223388671875,
0.388916015625,
-0.10479736328125,
-0.77490234375,
-0.62939453125,
-0.2225341796875,
0.24169921875,
-0.072265625,
0.6572265625,
0.904296875,
-0.327392578125,
0.3193359375,
-0.304443359375,
-0.41162109375,
0.1739501953125,
-0.58935546875,
-0.63671875... | 24 |
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]
```
No
| 97,406 | [
0.496826171875,
-0.223388671875,
0.388916015625,
-0.10479736328125,
-0.77490234375,
-0.62939453125,
-0.2225341796875,
0.24169921875,
-0.072265625,
0.6572265625,
0.904296875,
-0.327392578125,
0.3193359375,
-0.304443359375,
-0.41162109375,
0.1739501953125,
-0.58935546875,
-0.63671875... | 24 |
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)
```
No
| 97,407 | [
0.496826171875,
-0.223388671875,
0.388916015625,
-0.10479736328125,
-0.77490234375,
-0.62939453125,
-0.2225341796875,
0.24169921875,
-0.072265625,
0.6572265625,
0.904296875,
-0.327392578125,
0.3193359375,
-0.304443359375,
-0.41162109375,
0.1739501953125,
-0.58935546875,
-0.63671875... | 24 |
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)))
```
No
| 97,408 | [
0.496826171875,
-0.223388671875,
0.388916015625,
-0.10479736328125,
-0.77490234375,
-0.62939453125,
-0.2225341796875,
0.24169921875,
-0.072265625,
0.6572265625,
0.904296875,
-0.327392578125,
0.3193359375,
-0.304443359375,
-0.41162109375,
0.1739501953125,
-0.58935546875,
-0.63671875... | 24 |
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.
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')
```
| 97,853 | [
0.365234375,
0.3193359375,
0.213623046875,
0.306640625,
-0.5029296875,
-0.2432861328125,
-0.382080078125,
-0.049102783203125,
0.071533203125,
0.84619140625,
0.81884765625,
-0.12841796875,
0.277587890625,
-0.84228515625,
-0.356689453125,
-0.2734375,
-0.75341796875,
-0.71240234375,
... | 24 |
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)
```
No
| 97,854 | [
0.4375,
0.408935546875,
0.2015380859375,
0.2744140625,
-0.55029296875,
-0.1632080078125,
-0.4228515625,
-0.0202178955078125,
0.039642333984375,
0.90380859375,
0.78564453125,
-0.08172607421875,
0.2213134765625,
-0.79541015625,
-0.406494140625,
-0.268798828125,
-0.7333984375,
-0.6914... | 24 |
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')
```
No
| 97,855 | [
0.4375,
0.408935546875,
0.2015380859375,
0.2744140625,
-0.55029296875,
-0.1632080078125,
-0.4228515625,
-0.0202178955078125,
0.039642333984375,
0.90380859375,
0.78564453125,
-0.08172607421875,
0.2213134765625,
-0.79541015625,
-0.406494140625,
-0.268798828125,
-0.7333984375,
-0.6914... | 24 |
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
out.append('%d %d' % (check(lo)[1], lo))
print(*out, sep='\n')
```
No
| 97,856 | [
0.4375,
0.408935546875,
0.2015380859375,
0.2744140625,
-0.55029296875,
-0.1632080078125,
-0.4228515625,
-0.0202178955078125,
0.039642333984375,
0.90380859375,
0.78564453125,
-0.08172607421875,
0.2213134765625,
-0.79541015625,
-0.406494140625,
-0.268798828125,
-0.7333984375,
-0.6914... | 24 |
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 = 0, max(p)
while lo < hi:
mid = (lo + hi + 1) >> 1
if check(mid)[0]:
lo = mid
else:
hi = mid - 1
out.append('%d %d' % (check(lo)[1], lo))
print(*out, sep='\n')
```
No
| 97,857 | [
0.4375,
0.408935546875,
0.2015380859375,
0.2744140625,
-0.55029296875,
-0.1632080078125,
-0.4228515625,
-0.0202178955078125,
0.039642333984375,
0.90380859375,
0.78564453125,
-0.08172607421875,
0.2213134765625,
-0.79541015625,
-0.406494140625,
-0.268798828125,
-0.7333984375,
-0.6914... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarpus has an array, consisting of n integers a1, a2, ..., an. Polycarpus likes it when numbers in an array match. That's why he wants the array to have as many equal numbers as possible. For that Polycarpus performs the following operation multiple times:
* he chooses two elements of the array ai, aj (i ≠ j);
* he simultaneously increases number ai by 1 and decreases number aj by 1, that is, executes ai = ai + 1 and aj = aj - 1.
The given operation changes exactly two distinct array elements. Polycarpus can apply the described operation an infinite number of times.
Now he wants to know what maximum number of equal array elements he can get if he performs an arbitrary number of such operation. Help Polycarpus.
Input
The first line contains integer n (1 ≤ n ≤ 105) — the array size. The second line contains space-separated integers a1, a2, ..., an (|ai| ≤ 104) — the original array.
Output
Print a single integer — the maximum number of equal array elements he can get if he performs an arbitrary number of the given operation.
Examples
Input
2
2 1
Output
1
Input
3
1 4 1
Output
3
Tags: greedy, math
Correct Solution:
```
n=int(input())
arr=list(map(int,input().split()))
s=0
for i in range(n):
s+=arr[i]
if s%n==0:
print(n)
else:
print(n-1)
```
| 98,912 | [
0.1983642578125,
0.38623046875,
-0.06011962890625,
0.3466796875,
-0.67822265625,
-0.58203125,
-0.32958984375,
0.11676025390625,
0.372314453125,
0.8046875,
1.1875,
-0.07354736328125,
0.15576171875,
-0.84375,
-0.59716796875,
-0.139892578125,
-0.419677734375,
-0.53466796875,
-0.5244... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarpus has an array, consisting of n integers a1, a2, ..., an. Polycarpus likes it when numbers in an array match. That's why he wants the array to have as many equal numbers as possible. For that Polycarpus performs the following operation multiple times:
* he chooses two elements of the array ai, aj (i ≠ j);
* he simultaneously increases number ai by 1 and decreases number aj by 1, that is, executes ai = ai + 1 and aj = aj - 1.
The given operation changes exactly two distinct array elements. Polycarpus can apply the described operation an infinite number of times.
Now he wants to know what maximum number of equal array elements he can get if he performs an arbitrary number of such operation. Help Polycarpus.
Input
The first line contains integer n (1 ≤ n ≤ 105) — the array size. The second line contains space-separated integers a1, a2, ..., an (|ai| ≤ 104) — the original array.
Output
Print a single integer — the maximum number of equal array elements he can get if he performs an arbitrary number of the given operation.
Examples
Input
2
2 1
Output
1
Input
3
1 4 1
Output
3
Tags: greedy, math
Correct Solution:
```
# It's all about what U BELIEVE
def gint(): return int(input())
def gint_arr(): return list(map(int, input().split()))
def gfloat(): return float(input())
def gfloat_arr(): return list(map(float, input().split()))
def pair_int(): return map(int, input().split())
###############################################################################
INF = (1 << 31)
dx = [-1, 0, 1, 0]
dy = [ 0, 1, 0, -1]
###############################################################################
############################ SOLUTION IS COMING ###############################
###############################################################################
n = gint()
a = gint_arr()
print(n if sum(a) % n == 0 else n - 1)
```
| 98,913 | [
0.249267578125,
0.385009765625,
-0.1240234375,
0.23388671875,
-0.736328125,
-0.64306640625,
-0.269287109375,
0.199462890625,
0.360107421875,
0.84619140625,
1.1474609375,
-0.075439453125,
0.255126953125,
-0.8310546875,
-0.5107421875,
-0.1011962890625,
-0.5185546875,
-0.6181640625,
... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarpus has an array, consisting of n integers a1, a2, ..., an. Polycarpus likes it when numbers in an array match. That's why he wants the array to have as many equal numbers as possible. For that Polycarpus performs the following operation multiple times:
* he chooses two elements of the array ai, aj (i ≠ j);
* he simultaneously increases number ai by 1 and decreases number aj by 1, that is, executes ai = ai + 1 and aj = aj - 1.
The given operation changes exactly two distinct array elements. Polycarpus can apply the described operation an infinite number of times.
Now he wants to know what maximum number of equal array elements he can get if he performs an arbitrary number of such operation. Help Polycarpus.
Input
The first line contains integer n (1 ≤ n ≤ 105) — the array size. The second line contains space-separated integers a1, a2, ..., an (|ai| ≤ 104) — the original array.
Output
Print a single integer — the maximum number of equal array elements he can get if he performs an arbitrary number of the given operation.
Examples
Input
2
2 1
Output
1
Input
3
1 4 1
Output
3
Tags: greedy, math
Correct Solution:
```
def IC():
n=int(input())
a=[int(x) for x in input().split()]
shave=sum(a)
if shave % n == 0:
print(n)
return
else:
print(n-1)
return
IC()
```
| 98,914 | [
0.260009765625,
0.426513671875,
-0.0662841796875,
0.331298828125,
-0.7109375,
-0.57958984375,
-0.217041015625,
0.023406982421875,
0.365234375,
0.740234375,
1.24609375,
-0.0728759765625,
0.1029052734375,
-0.8203125,
-0.560546875,
-0.1268310546875,
-0.4990234375,
-0.599609375,
-0.5... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarpus has an array, consisting of n integers a1, a2, ..., an. Polycarpus likes it when numbers in an array match. That's why he wants the array to have as many equal numbers as possible. For that Polycarpus performs the following operation multiple times:
* he chooses two elements of the array ai, aj (i ≠ j);
* he simultaneously increases number ai by 1 and decreases number aj by 1, that is, executes ai = ai + 1 and aj = aj - 1.
The given operation changes exactly two distinct array elements. Polycarpus can apply the described operation an infinite number of times.
Now he wants to know what maximum number of equal array elements he can get if he performs an arbitrary number of such operation. Help Polycarpus.
Input
The first line contains integer n (1 ≤ n ≤ 105) — the array size. The second line contains space-separated integers a1, a2, ..., an (|ai| ≤ 104) — the original array.
Output
Print a single integer — the maximum number of equal array elements he can get if he performs an arbitrary number of the given operation.
Examples
Input
2
2 1
Output
1
Input
3
1 4 1
Output
3
Tags: greedy, math
Correct Solution:
```
from math import pi
def main():
n = int(input())
s = sum(map(int, input().split()))
if s % n:
n -= 1
print(n)
if __name__ == '__main__':
main()
```
| 98,915 | [
0.2059326171875,
0.363525390625,
-0.0726318359375,
0.271484375,
-0.69677734375,
-0.56640625,
-0.333251953125,
0.11590576171875,
0.407470703125,
0.7236328125,
1.2333984375,
-0.048553466796875,
0.18359375,
-0.8193359375,
-0.63671875,
-0.1314697265625,
-0.489013671875,
-0.54443359375,... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarpus has an array, consisting of n integers a1, a2, ..., an. Polycarpus likes it when numbers in an array match. That's why he wants the array to have as many equal numbers as possible. For that Polycarpus performs the following operation multiple times:
* he chooses two elements of the array ai, aj (i ≠ j);
* he simultaneously increases number ai by 1 and decreases number aj by 1, that is, executes ai = ai + 1 and aj = aj - 1.
The given operation changes exactly two distinct array elements. Polycarpus can apply the described operation an infinite number of times.
Now he wants to know what maximum number of equal array elements he can get if he performs an arbitrary number of such operation. Help Polycarpus.
Input
The first line contains integer n (1 ≤ n ≤ 105) — the array size. The second line contains space-separated integers a1, a2, ..., an (|ai| ≤ 104) — the original array.
Output
Print a single integer — the maximum number of equal array elements he can get if he performs an arbitrary number of the given operation.
Examples
Input
2
2 1
Output
1
Input
3
1 4 1
Output
3
Tags: greedy, math
Correct Solution:
```
def fun (x,l):
if(len(set(x))==1):
print(l)
return
if(sum(x)%l==0):
print(l)
else:
print(l-1)
return
l = int(input())
x=list(map(int,input().split()))
x.sort()
fun(x,l)
```
| 98,916 | [
0.182861328125,
0.362060546875,
-0.051849365234375,
0.32177734375,
-0.6806640625,
-0.5546875,
-0.301513671875,
0.1607666015625,
0.3154296875,
0.7509765625,
1.177734375,
-0.050018310546875,
0.1585693359375,
-0.84130859375,
-0.60400390625,
-0.1663818359375,
-0.488037109375,
-0.602539... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarpus has an array, consisting of n integers a1, a2, ..., an. Polycarpus likes it when numbers in an array match. That's why he wants the array to have as many equal numbers as possible. For that Polycarpus performs the following operation multiple times:
* he chooses two elements of the array ai, aj (i ≠ j);
* he simultaneously increases number ai by 1 and decreases number aj by 1, that is, executes ai = ai + 1 and aj = aj - 1.
The given operation changes exactly two distinct array elements. Polycarpus can apply the described operation an infinite number of times.
Now he wants to know what maximum number of equal array elements he can get if he performs an arbitrary number of such operation. Help Polycarpus.
Input
The first line contains integer n (1 ≤ n ≤ 105) — the array size. The second line contains space-separated integers a1, a2, ..., an (|ai| ≤ 104) — the original array.
Output
Print a single integer — the maximum number of equal array elements he can get if he performs an arbitrary number of the given operation.
Examples
Input
2
2 1
Output
1
Input
3
1 4 1
Output
3
Tags: greedy, math
Correct Solution:
```
n=int(input())
summ=sum(map(int,input().split()))
if summ%n==0:
print(n)
else:
print(n-1)
```
| 98,917 | [
0.2296142578125,
0.418701171875,
-0.058349609375,
0.326904296875,
-0.63818359375,
-0.595703125,
-0.287841796875,
0.11822509765625,
0.38525390625,
0.765625,
1.1689453125,
-0.05548095703125,
0.1322021484375,
-0.80322265625,
-0.62109375,
-0.1541748046875,
-0.43115234375,
-0.5654296875... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarpus has an array, consisting of n integers a1, a2, ..., an. Polycarpus likes it when numbers in an array match. That's why he wants the array to have as many equal numbers as possible. For that Polycarpus performs the following operation multiple times:
* he chooses two elements of the array ai, aj (i ≠ j);
* he simultaneously increases number ai by 1 and decreases number aj by 1, that is, executes ai = ai + 1 and aj = aj - 1.
The given operation changes exactly two distinct array elements. Polycarpus can apply the described operation an infinite number of times.
Now he wants to know what maximum number of equal array elements he can get if he performs an arbitrary number of such operation. Help Polycarpus.
Input
The first line contains integer n (1 ≤ n ≤ 105) — the array size. The second line contains space-separated integers a1, a2, ..., an (|ai| ≤ 104) — the original array.
Output
Print a single integer — the maximum number of equal array elements he can get if he performs an arbitrary number of the given operation.
Examples
Input
2
2 1
Output
1
Input
3
1 4 1
Output
3
Tags: greedy, math
Correct Solution:
```
'''input
6
-1 1 0 0 -1 -1
'''
n = int(input())
a = list(map(int, input().split()))
print(n if sum(a) % n == 0 else n - 1)
```
| 98,918 | [
0.220458984375,
0.397705078125,
-0.04852294921875,
0.331787109375,
-0.673828125,
-0.6025390625,
-0.302490234375,
0.131103515625,
0.397216796875,
0.76416015625,
1.1865234375,
-0.048248291015625,
0.1622314453125,
-0.81494140625,
-0.623046875,
-0.1409912109375,
-0.439208984375,
-0.555... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarpus has an array, consisting of n integers a1, a2, ..., an. Polycarpus likes it when numbers in an array match. That's why he wants the array to have as many equal numbers as possible. For that Polycarpus performs the following operation multiple times:
* he chooses two elements of the array ai, aj (i ≠ j);
* he simultaneously increases number ai by 1 and decreases number aj by 1, that is, executes ai = ai + 1 and aj = aj - 1.
The given operation changes exactly two distinct array elements. Polycarpus can apply the described operation an infinite number of times.
Now he wants to know what maximum number of equal array elements he can get if he performs an arbitrary number of such operation. Help Polycarpus.
Input
The first line contains integer n (1 ≤ n ≤ 105) — the array size. The second line contains space-separated integers a1, a2, ..., an (|ai| ≤ 104) — the original array.
Output
Print a single integer — the maximum number of equal array elements he can get if he performs an arbitrary number of the given operation.
Examples
Input
2
2 1
Output
1
Input
3
1 4 1
Output
3
Tags: greedy, math
Correct Solution:
```
n=int(input())
print( n if sum((map(int,input().split())))%n==0 else n-1)
```
| 98,919 | [
0.2181396484375,
0.42236328125,
-0.055328369140625,
0.3076171875,
-0.66650390625,
-0.60693359375,
-0.27392578125,
0.1304931640625,
0.3828125,
0.78125,
1.1748046875,
-0.0232696533203125,
0.1373291015625,
-0.8359375,
-0.61474609375,
-0.1416015625,
-0.43310546875,
-0.55615234375,
-0... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarpus has an array, consisting of n integers a1, a2, ..., an. Polycarpus likes it when numbers in an array match. That's why he wants the array to have as many equal numbers as possible. For that Polycarpus performs the following operation multiple times:
* he chooses two elements of the array ai, aj (i ≠ j);
* he simultaneously increases number ai by 1 and decreases number aj by 1, that is, executes ai = ai + 1 and aj = aj - 1.
The given operation changes exactly two distinct array elements. Polycarpus can apply the described operation an infinite number of times.
Now he wants to know what maximum number of equal array elements he can get if he performs an arbitrary number of such operation. Help Polycarpus.
Input
The first line contains integer n (1 ≤ n ≤ 105) — the array size. The second line contains space-separated integers a1, a2, ..., an (|ai| ≤ 104) — the original array.
Output
Print a single integer — the maximum number of equal array elements he can get if he performs an arbitrary number of the given operation.
Examples
Input
2
2 1
Output
1
Input
3
1 4 1
Output
3
Submitted Solution:
```
x=int(input())
sm=sum(list(map(int,input().split())))%x
if sm==0:
print(x)
else:
print(x-1)
```
Yes
| 98,920 | [
0.28173828125,
0.375244140625,
-0.09124755859375,
0.33984375,
-0.7119140625,
-0.45361328125,
-0.439697265625,
0.28369140625,
0.29248046875,
0.7626953125,
1.1357421875,
0.0931396484375,
0.151123046875,
-0.900390625,
-0.63330078125,
-0.135498046875,
-0.442138671875,
-0.496826171875,
... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarpus has an array, consisting of n integers a1, a2, ..., an. Polycarpus likes it when numbers in an array match. That's why he wants the array to have as many equal numbers as possible. For that Polycarpus performs the following operation multiple times:
* he chooses two elements of the array ai, aj (i ≠ j);
* he simultaneously increases number ai by 1 and decreases number aj by 1, that is, executes ai = ai + 1 and aj = aj - 1.
The given operation changes exactly two distinct array elements. Polycarpus can apply the described operation an infinite number of times.
Now he wants to know what maximum number of equal array elements he can get if he performs an arbitrary number of such operation. Help Polycarpus.
Input
The first line contains integer n (1 ≤ n ≤ 105) — the array size. The second line contains space-separated integers a1, a2, ..., an (|ai| ≤ 104) — the original array.
Output
Print a single integer — the maximum number of equal array elements he can get if he performs an arbitrary number of the given operation.
Examples
Input
2
2 1
Output
1
Input
3
1 4 1
Output
3
Submitted Solution:
```
n = int(input())
array = [int(c) for c in input().split()]
array.sort()
avg = sum(array) // n
low, hi = 0, n - 1
while low < hi:
amount = min(abs(array[hi] - avg), abs(avg - array[low]))
array[low] += amount
array[hi] -= amount
if array[low] == avg:
low += 1
if array[hi] == avg:
hi -= 1
ans = sum(1 for x in array if x == avg)
print(ans)
```
Yes
| 98,921 | [
0.2467041015625,
0.36279296875,
-0.1434326171875,
0.343994140625,
-0.78564453125,
-0.42431640625,
-0.444091796875,
0.3134765625,
0.301025390625,
0.83544921875,
1.080078125,
-0.0670166015625,
0.1419677734375,
-0.92724609375,
-0.69921875,
-0.1488037109375,
-0.54931640625,
-0.56005859... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarpus has an array, consisting of n integers a1, a2, ..., an. Polycarpus likes it when numbers in an array match. That's why he wants the array to have as many equal numbers as possible. For that Polycarpus performs the following operation multiple times:
* he chooses two elements of the array ai, aj (i ≠ j);
* he simultaneously increases number ai by 1 and decreases number aj by 1, that is, executes ai = ai + 1 and aj = aj - 1.
The given operation changes exactly two distinct array elements. Polycarpus can apply the described operation an infinite number of times.
Now he wants to know what maximum number of equal array elements he can get if he performs an arbitrary number of such operation. Help Polycarpus.
Input
The first line contains integer n (1 ≤ n ≤ 105) — the array size. The second line contains space-separated integers a1, a2, ..., an (|ai| ≤ 104) — the original array.
Output
Print a single integer — the maximum number of equal array elements he can get if he performs an arbitrary number of the given operation.
Examples
Input
2
2 1
Output
1
Input
3
1 4 1
Output
3
Submitted Solution:
```
n=int(input())
arr = list(map(int, input().split()))
arr.sort()
if sum(arr)%n==0:
print(n)
else:
print(n-1)
```
Yes
| 98,922 | [
0.279296875,
0.3466796875,
-0.1474609375,
0.347412109375,
-0.73095703125,
-0.408447265625,
-0.432373046875,
0.33544921875,
0.320556640625,
0.81103515625,
1.111328125,
-0.00551605224609375,
0.1685791015625,
-0.92529296875,
-0.62890625,
-0.1661376953125,
-0.468017578125,
-0.462646484... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarpus has an array, consisting of n integers a1, a2, ..., an. Polycarpus likes it when numbers in an array match. That's why he wants the array to have as many equal numbers as possible. For that Polycarpus performs the following operation multiple times:
* he chooses two elements of the array ai, aj (i ≠ j);
* he simultaneously increases number ai by 1 and decreases number aj by 1, that is, executes ai = ai + 1 and aj = aj - 1.
The given operation changes exactly two distinct array elements. Polycarpus can apply the described operation an infinite number of times.
Now he wants to know what maximum number of equal array elements he can get if he performs an arbitrary number of such operation. Help Polycarpus.
Input
The first line contains integer n (1 ≤ n ≤ 105) — the array size. The second line contains space-separated integers a1, a2, ..., an (|ai| ≤ 104) — the original array.
Output
Print a single integer — the maximum number of equal array elements he can get if he performs an arbitrary number of the given operation.
Examples
Input
2
2 1
Output
1
Input
3
1 4 1
Output
3
Submitted Solution:
```
n = int(input())
print(n - 1 if sum(map(int, input().split())) % n else n)
```
Yes
| 98,923 | [
0.3046875,
0.380859375,
-0.1041259765625,
0.3408203125,
-0.74267578125,
-0.45068359375,
-0.413818359375,
0.296875,
0.29345703125,
0.794921875,
1.09765625,
0.0748291015625,
0.1268310546875,
-0.89990234375,
-0.619140625,
-0.1461181640625,
-0.463134765625,
-0.498291015625,
-0.448974... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarpus has an array, consisting of n integers a1, a2, ..., an. Polycarpus likes it when numbers in an array match. That's why he wants the array to have as many equal numbers as possible. For that Polycarpus performs the following operation multiple times:
* he chooses two elements of the array ai, aj (i ≠ j);
* he simultaneously increases number ai by 1 and decreases number aj by 1, that is, executes ai = ai + 1 and aj = aj - 1.
The given operation changes exactly two distinct array elements. Polycarpus can apply the described operation an infinite number of times.
Now he wants to know what maximum number of equal array elements he can get if he performs an arbitrary number of such operation. Help Polycarpus.
Input
The first line contains integer n (1 ≤ n ≤ 105) — the array size. The second line contains space-separated integers a1, a2, ..., an (|ai| ≤ 104) — the original array.
Output
Print a single integer — the maximum number of equal array elements he can get if he performs an arbitrary number of the given operation.
Examples
Input
2
2 1
Output
1
Input
3
1 4 1
Output
3
Submitted Solution:
```
import sys
INF = 10**20
MOD = 10**9 + 7
I = lambda:list(map(int,input().split()))
from math import gcd
from math import ceil
from collections import defaultdict as dd, Counter
from bisect import bisect_left as bl, bisect_right as br
"""
Facts and Data representation
Constructive? Top bottom up down
"""
n, = I()
a = I()
fix = a[0]
for i in range(1, n):
if a[i] < 0:
fix += -a[i]
else:
fix += a[i]
if fix % n == 0:
print(n)
else:
print(n - 1, fix)
```
No
| 98,924 | [
0.12744140625,
0.32080078125,
-0.091552734375,
0.409423828125,
-0.79736328125,
-0.35595703125,
-0.33837890625,
0.1400146484375,
0.313232421875,
0.8994140625,
1.052734375,
-0.0931396484375,
0.20849609375,
-0.9365234375,
-0.59912109375,
-0.1585693359375,
-0.50732421875,
-0.6411132812... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarpus has an array, consisting of n integers a1, a2, ..., an. Polycarpus likes it when numbers in an array match. That's why he wants the array to have as many equal numbers as possible. For that Polycarpus performs the following operation multiple times:
* he chooses two elements of the array ai, aj (i ≠ j);
* he simultaneously increases number ai by 1 and decreases number aj by 1, that is, executes ai = ai + 1 and aj = aj - 1.
The given operation changes exactly two distinct array elements. Polycarpus can apply the described operation an infinite number of times.
Now he wants to know what maximum number of equal array elements he can get if he performs an arbitrary number of such operation. Help Polycarpus.
Input
The first line contains integer n (1 ≤ n ≤ 105) — the array size. The second line contains space-separated integers a1, a2, ..., an (|ai| ≤ 104) — the original array.
Output
Print a single integer — the maximum number of equal array elements he can get if he performs an arbitrary number of the given operation.
Examples
Input
2
2 1
Output
1
Input
3
1 4 1
Output
3
Submitted Solution:
```
n = int(input())
arr = input().split()
arr = [int(i) for i in arr]
sum_arr = sum(arr)
ans = 1
for i in range(2, len(arr)+1):
if(int(sum_arr/i) == sum_arr/i):
ans = i
print(ans)
```
No
| 98,925 | [
0.296630859375,
0.314208984375,
-0.07861328125,
0.341064453125,
-0.71875,
-0.46484375,
-0.36962890625,
0.295654296875,
0.322509765625,
0.7724609375,
1.150390625,
0.0010623931884765625,
0.1278076171875,
-0.8828125,
-0.6728515625,
-0.1671142578125,
-0.488037109375,
-0.46630859375,
... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarpus has an array, consisting of n integers a1, a2, ..., an. Polycarpus likes it when numbers in an array match. That's why he wants the array to have as many equal numbers as possible. For that Polycarpus performs the following operation multiple times:
* he chooses two elements of the array ai, aj (i ≠ j);
* he simultaneously increases number ai by 1 and decreases number aj by 1, that is, executes ai = ai + 1 and aj = aj - 1.
The given operation changes exactly two distinct array elements. Polycarpus can apply the described operation an infinite number of times.
Now he wants to know what maximum number of equal array elements he can get if he performs an arbitrary number of such operation. Help Polycarpus.
Input
The first line contains integer n (1 ≤ n ≤ 105) — the array size. The second line contains space-separated integers a1, a2, ..., an (|ai| ≤ 104) — the original array.
Output
Print a single integer — the maximum number of equal array elements he can get if he performs an arbitrary number of the given operation.
Examples
Input
2
2 1
Output
1
Input
3
1 4 1
Output
3
Submitted Solution:
```
l = int(input())
x = list(map(int, input().split()))
d={}
for i in range (len(x)):
try:
d[x[i]]+=1
except:
d[x[i]]=1
m = max(d)
m,s = d[m],0
for i in d:
if(i!=m):
s += abs(i-m)
print(s)
```
No
| 98,926 | [
0.26123046875,
0.352294921875,
-0.07763671875,
0.375,
-0.751953125,
-0.447021484375,
-0.421142578125,
0.26708984375,
0.285400390625,
0.8203125,
1.09375,
0.0250244140625,
0.164306640625,
-0.873046875,
-0.58984375,
-0.1617431640625,
-0.49609375,
-0.490478515625,
-0.42822265625,
-... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarpus has an array, consisting of n integers a1, a2, ..., an. Polycarpus likes it when numbers in an array match. That's why he wants the array to have as many equal numbers as possible. For that Polycarpus performs the following operation multiple times:
* he chooses two elements of the array ai, aj (i ≠ j);
* he simultaneously increases number ai by 1 and decreases number aj by 1, that is, executes ai = ai + 1 and aj = aj - 1.
The given operation changes exactly two distinct array elements. Polycarpus can apply the described operation an infinite number of times.
Now he wants to know what maximum number of equal array elements he can get if he performs an arbitrary number of such operation. Help Polycarpus.
Input
The first line contains integer n (1 ≤ n ≤ 105) — the array size. The second line contains space-separated integers a1, a2, ..., an (|ai| ≤ 104) — the original array.
Output
Print a single integer — the maximum number of equal array elements he can get if he performs an arbitrary number of the given operation.
Examples
Input
2
2 1
Output
1
Input
3
1 4 1
Output
3
Submitted Solution:
```
n=int(input())
nums=list(map(int,input().split()))
i=n
maxx=-float('inf')
while i:
nums.sort()
nums[-1]-=1
nums[0]+=1
count=len(nums)-len(set(nums))
maxx=max(count,maxx)
i-=1
print(maxx+1)
```
No
| 98,927 | [
0.29736328125,
0.361083984375,
-0.1346435546875,
0.376708984375,
-0.71337890625,
-0.4931640625,
-0.422119140625,
0.29931640625,
0.30224609375,
0.884765625,
1.0849609375,
0.05621337890625,
0.1727294921875,
-0.94091796875,
-0.60595703125,
-0.1441650390625,
-0.473388671875,
-0.5537109... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarpus has n markers and m marker caps. Each marker is described by two numbers: xi is the color and yi is the diameter. Correspondingly, each cap is described by two numbers: aj is the color and bj is the diameter. Cap (aj, bj) can close marker (xi, yi) only if their diameters match, that is, bj = yi. Besides, a marker is considered to be beautifully closed, if the cap color and the marker color match, that is, aj = xi.
Find the way to close the maximum number of markers. If there are several such ways, then choose the one that has the maximum number of beautifully closed markers.
Input
The first input line contains two space-separated integers n and m (1 ≤ n, m ≤ 105) — the number of markers and the number of caps, correspondingly.
Next n lines describe the markers. The i-th line contains two space-separated integers xi, yi (1 ≤ xi, yi ≤ 1000) — the i-th marker's color and diameter, correspondingly.
Next m lines describe the caps. The j-th line contains two space-separated integers aj, bj (1 ≤ aj, bj ≤ 1000) — the color and diameter of the j-th cap, correspondingly.
Output
Print two space-separated integers u, v, where u is the number of closed markers and v is the number of beautifully closed markers in the sought optimal way. Remember that you have to find the way to close the maximum number of markers, and if there are several such ways, you should choose the one where the number of beautifully closed markers is maximum.
Examples
Input
3 4
1 2
3 4
2 4
5 4
2 4
1 1
1 2
Output
3 2
Input
2 2
1 2
2 1
3 4
5 1
Output
1 0
Note
In the first test sample the first marker should be closed by the fourth cap, the second marker should be closed by the first cap and the third marker should be closed by the second cap. Thus, three markers will be closed, and two of them will be beautifully closed — the first and the third markers.
Tags: *special, greedy, sortings
Correct Solution:
```
from functools import cmp_to_key
def main():
n, m = map(int, input().split())
markers = []
caps = []
for _ in range(n):
x, y = map(int, input().split())
markers.append((x, y))
for _ in range(m):
x, y = map(int, input().split())
caps.append((x, y))
marker_sizes = dict()
cap_sizes = dict()
marker_dict = dict()
cap_dict = dict()
for m in markers:
if marker_sizes.get(m[1]):
marker_sizes[m[1]] += 1
else:
marker_sizes[m[1]] = 1
if marker_dict.get(m):
marker_dict[m]+=1
else:
marker_dict[m]=1
for c in caps:
if cap_sizes.get(c[1]):
cap_sizes[c[1]] += 1
else:
cap_sizes[c[1]] = 1
if cap_dict.get(c):
cap_dict[c]+=1
else:
cap_dict[c]=1
ans1 = 0
for s, c1 in marker_sizes.items():
c2 = cap_sizes.get(s)
if c2:
ans1 += min(c1, c2)
ans2 = 0
for val, freq in marker_dict.items():
x = cap_dict.get(val)
if x:
ans2+=min(freq, x)
return '{} {}'.format(ans1, ans2)
if __name__ == '__main__':
print(main())
```
| 99,695 | [
0.236328125,
-0.17919921875,
0.446044921875,
0.5341796875,
-0.350341796875,
-0.273681640625,
-0.154052734375,
0.413818359375,
0.1741943359375,
0.642578125,
0.810546875,
0.1383056640625,
-0.08203125,
-0.56787109375,
-0.26611328125,
0.53076171875,
-0.07208251953125,
-0.64013671875,
... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarpus has n markers and m marker caps. Each marker is described by two numbers: xi is the color and yi is the diameter. Correspondingly, each cap is described by two numbers: aj is the color and bj is the diameter. Cap (aj, bj) can close marker (xi, yi) only if their diameters match, that is, bj = yi. Besides, a marker is considered to be beautifully closed, if the cap color and the marker color match, that is, aj = xi.
Find the way to close the maximum number of markers. If there are several such ways, then choose the one that has the maximum number of beautifully closed markers.
Input
The first input line contains two space-separated integers n and m (1 ≤ n, m ≤ 105) — the number of markers and the number of caps, correspondingly.
Next n lines describe the markers. The i-th line contains two space-separated integers xi, yi (1 ≤ xi, yi ≤ 1000) — the i-th marker's color and diameter, correspondingly.
Next m lines describe the caps. The j-th line contains two space-separated integers aj, bj (1 ≤ aj, bj ≤ 1000) — the color and diameter of the j-th cap, correspondingly.
Output
Print two space-separated integers u, v, where u is the number of closed markers and v is the number of beautifully closed markers in the sought optimal way. Remember that you have to find the way to close the maximum number of markers, and if there are several such ways, you should choose the one where the number of beautifully closed markers is maximum.
Examples
Input
3 4
1 2
3 4
2 4
5 4
2 4
1 1
1 2
Output
3 2
Input
2 2
1 2
2 1
3 4
5 1
Output
1 0
Note
In the first test sample the first marker should be closed by the fourth cap, the second marker should be closed by the first cap and the third marker should be closed by the second cap. Thus, three markers will be closed, and two of them will be beautifully closed — the first and the third markers.
Tags: *special, greedy, sortings
Correct Solution:
```
import sys
import time
import math
from collections import defaultdict
from functools import lru_cache
INF = 10 ** 18 + 3
EPS = 1e-10
MAX_CACHE = 10 ** 9
def time_it(function, output=sys.stderr):
def wrapped(*args, **kwargs):
start = time.time()
res = function(*args, **kwargs)
elapsed_time = time.time() - start
print('"%s" took %f ms' % (function.__name__, elapsed_time * 1000),
file=output)
return res
return wrapped
@time_it
def main():
n, m = map(int, input().split())
closed_count = 0
nice_closed_count = 0
markers = defaultdict(lambda: defaultdict(lambda: 0))
caps = defaultdict(lambda: defaultdict(lambda: 0))
for _ in range(n):
color, size = map(int, input().split())
markers[size][color] += 1
for _ in range(m):
color, size = map(int, input().split())
if markers[size][color] > 0:
markers[size][color] -= 1
closed_count += 1
nice_closed_count += 1
else:
caps[size][color] += 1
for size in caps.keys():
closed_count += min(sum(markers[size].values()), sum(caps[size].values()))
print(closed_count, nice_closed_count)
def set_input(file):
global input
input = lambda: file.readline().strip()
def set_output(file):
global print
local_print = print
def print(*args, **kwargs):
kwargs["file"] = kwargs.get("file", file)
return local_print(*args, **kwargs)
if __name__ == '__main__':
set_input(open("input.txt", "r") if "MINE" in sys.argv else sys.stdin)
set_output(sys.stdout)
main()
```
| 99,696 | [
0.2208251953125,
-0.159423828125,
0.454833984375,
0.53466796875,
-0.352294921875,
-0.2249755859375,
-0.10516357421875,
0.397705078125,
0.253173828125,
0.599609375,
0.837890625,
0.1285400390625,
-0.023162841796875,
-0.5546875,
-0.244140625,
0.5166015625,
-0.0924072265625,
-0.6577148... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarpus has n markers and m marker caps. Each marker is described by two numbers: xi is the color and yi is the diameter. Correspondingly, each cap is described by two numbers: aj is the color and bj is the diameter. Cap (aj, bj) can close marker (xi, yi) only if their diameters match, that is, bj = yi. Besides, a marker is considered to be beautifully closed, if the cap color and the marker color match, that is, aj = xi.
Find the way to close the maximum number of markers. If there are several such ways, then choose the one that has the maximum number of beautifully closed markers.
Input
The first input line contains two space-separated integers n and m (1 ≤ n, m ≤ 105) — the number of markers and the number of caps, correspondingly.
Next n lines describe the markers. The i-th line contains two space-separated integers xi, yi (1 ≤ xi, yi ≤ 1000) — the i-th marker's color and diameter, correspondingly.
Next m lines describe the caps. The j-th line contains two space-separated integers aj, bj (1 ≤ aj, bj ≤ 1000) — the color and diameter of the j-th cap, correspondingly.
Output
Print two space-separated integers u, v, where u is the number of closed markers and v is the number of beautifully closed markers in the sought optimal way. Remember that you have to find the way to close the maximum number of markers, and if there are several such ways, you should choose the one where the number of beautifully closed markers is maximum.
Examples
Input
3 4
1 2
3 4
2 4
5 4
2 4
1 1
1 2
Output
3 2
Input
2 2
1 2
2 1
3 4
5 1
Output
1 0
Note
In the first test sample the first marker should be closed by the fourth cap, the second marker should be closed by the first cap and the third marker should be closed by the second cap. Thus, three markers will be closed, and two of them will be beautifully closed — the first and the third markers.
Tags: *special, greedy, sortings
Correct Solution:
```
n, m = map(int, input().split())
x, y, u, v = {}, {}, 0, 0
for i in range(n):
a, b = input().split()
if b in x: x[b][a] = x[b].get(a, 0) + 1
else: x[b] = {a: 1}
for i in range(m):
a, b = input().split()
if b in y: y[b][a] = y[b].get(a, 0) + 1
else: y[b] = {a: 1}
for b in x.keys() & y.keys():
u += min(sum(x[b].values()), sum(y[b].values()))
v += sum(min(x[b][a], y[b][a]) for a in x[b].keys() & y[b].keys())
print(u, v)
# Made By Mostafa_Khaled
```
| 99,697 | [
0.21337890625,
-0.1466064453125,
0.4892578125,
0.5439453125,
-0.35009765625,
-0.27294921875,
-0.1312255859375,
0.481689453125,
0.1788330078125,
0.66943359375,
0.84326171875,
0.157470703125,
-0.0714111328125,
-0.5947265625,
-0.2183837890625,
0.487548828125,
-0.07366943359375,
-0.642... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarpus has n markers and m marker caps. Each marker is described by two numbers: xi is the color and yi is the diameter. Correspondingly, each cap is described by two numbers: aj is the color and bj is the diameter. Cap (aj, bj) can close marker (xi, yi) only if their diameters match, that is, bj = yi. Besides, a marker is considered to be beautifully closed, if the cap color and the marker color match, that is, aj = xi.
Find the way to close the maximum number of markers. If there are several such ways, then choose the one that has the maximum number of beautifully closed markers.
Input
The first input line contains two space-separated integers n and m (1 ≤ n, m ≤ 105) — the number of markers and the number of caps, correspondingly.
Next n lines describe the markers. The i-th line contains two space-separated integers xi, yi (1 ≤ xi, yi ≤ 1000) — the i-th marker's color and diameter, correspondingly.
Next m lines describe the caps. The j-th line contains two space-separated integers aj, bj (1 ≤ aj, bj ≤ 1000) — the color and diameter of the j-th cap, correspondingly.
Output
Print two space-separated integers u, v, where u is the number of closed markers and v is the number of beautifully closed markers in the sought optimal way. Remember that you have to find the way to close the maximum number of markers, and if there are several such ways, you should choose the one where the number of beautifully closed markers is maximum.
Examples
Input
3 4
1 2
3 4
2 4
5 4
2 4
1 1
1 2
Output
3 2
Input
2 2
1 2
2 1
3 4
5 1
Output
1 0
Note
In the first test sample the first marker should be closed by the fourth cap, the second marker should be closed by the first cap and the third marker should be closed by the second cap. Thus, three markers will be closed, and two of them will be beautifully closed — the first and the third markers.
Tags: *special, greedy, sortings
Correct Solution:
```
n,m=map(int,input().split())
m1={}
m2={}
c1={}
c2={}
for i in range(n):
x,y=(map(int,input().split()))
m1[y]=m1.get(y,0)+1
m2[(x,y)]=m2.get((x,y),0)+1
for i in range(m):
x,y=(map(int,input().split()))
c1[y]=c1.get(y,0)+1
c2[(x,y)]=c2.get((x,y),0)+1
r1=0
r2=0
for i in m1.keys():
if i in c1.keys():
t1=m1[i]
t2=c1[i]
r1=r1+(min(t1,t2))
for i in m2.keys():
if i in c2.keys():
t1=m2[i]
t2=c2[i]
r2=r2+(min(t1,t2))
print(r1,r2)
```
| 99,698 | [
0.205810546875,
-0.1470947265625,
0.49560546875,
0.53515625,
-0.360595703125,
-0.266357421875,
-0.134033203125,
0.472900390625,
0.177734375,
0.66162109375,
0.83935546875,
0.15234375,
-0.0662841796875,
-0.58056640625,
-0.2225341796875,
0.489990234375,
-0.08551025390625,
-0.645507812... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarpus has n markers and m marker caps. Each marker is described by two numbers: xi is the color and yi is the diameter. Correspondingly, each cap is described by two numbers: aj is the color and bj is the diameter. Cap (aj, bj) can close marker (xi, yi) only if their diameters match, that is, bj = yi. Besides, a marker is considered to be beautifully closed, if the cap color and the marker color match, that is, aj = xi.
Find the way to close the maximum number of markers. If there are several such ways, then choose the one that has the maximum number of beautifully closed markers.
Input
The first input line contains two space-separated integers n and m (1 ≤ n, m ≤ 105) — the number of markers and the number of caps, correspondingly.
Next n lines describe the markers. The i-th line contains two space-separated integers xi, yi (1 ≤ xi, yi ≤ 1000) — the i-th marker's color and diameter, correspondingly.
Next m lines describe the caps. The j-th line contains two space-separated integers aj, bj (1 ≤ aj, bj ≤ 1000) — the color and diameter of the j-th cap, correspondingly.
Output
Print two space-separated integers u, v, where u is the number of closed markers and v is the number of beautifully closed markers in the sought optimal way. Remember that you have to find the way to close the maximum number of markers, and if there are several such ways, you should choose the one where the number of beautifully closed markers is maximum.
Examples
Input
3 4
1 2
3 4
2 4
5 4
2 4
1 1
1 2
Output
3 2
Input
2 2
1 2
2 1
3 4
5 1
Output
1 0
Note
In the first test sample the first marker should be closed by the fourth cap, the second marker should be closed by the first cap and the third marker should be closed by the second cap. Thus, three markers will be closed, and two of them will be beautifully closed — the first and the third markers.
Tags: *special, greedy, sortings
Correct Solution:
```
# n=int(input())
# n,k=map(int,input().split())
# arr=list(map(int,input().split()))
#ls=list(map(int,input().split()))
#for i in range(m):
# for _ in range(int(input())):
#from collections import Counter
#from fractions import Fraction
#s=iter(input())
#from collections import deque
from collections import Counter
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
##########################################################
from collections import defaultdict
m=defaultdict(list)
c=defaultdict(list)
n,k=map(int, input().split())
for i in range(n):
u,v=map(int,input().split())
m[v].append(u)
for i in range(k):
u, v = map(int, input().split())
c[v].append(u)
#print(m)
#print(c)
t=0
b=0
for j in sorted(m.keys()):
if j in c:
t += min(len(c[j]), len(m[j]))
var = Counter(c[j])
ans=Counter(m[j])
for k in (ans.keys()):
if k in var:
b+=min(var[k],ans[k])
print(t ,b)
```
| 99,699 | [
0.228759765625,
-0.134521484375,
0.462890625,
0.5595703125,
-0.350341796875,
-0.26513671875,
-0.1358642578125,
0.495849609375,
0.16845703125,
0.63623046875,
0.845703125,
0.16259765625,
-0.06097412109375,
-0.60009765625,
-0.248046875,
0.5009765625,
-0.058837890625,
-0.61669921875,
... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarpus has n markers and m marker caps. Each marker is described by two numbers: xi is the color and yi is the diameter. Correspondingly, each cap is described by two numbers: aj is the color and bj is the diameter. Cap (aj, bj) can close marker (xi, yi) only if their diameters match, that is, bj = yi. Besides, a marker is considered to be beautifully closed, if the cap color and the marker color match, that is, aj = xi.
Find the way to close the maximum number of markers. If there are several such ways, then choose the one that has the maximum number of beautifully closed markers.
Input
The first input line contains two space-separated integers n and m (1 ≤ n, m ≤ 105) — the number of markers and the number of caps, correspondingly.
Next n lines describe the markers. The i-th line contains two space-separated integers xi, yi (1 ≤ xi, yi ≤ 1000) — the i-th marker's color and diameter, correspondingly.
Next m lines describe the caps. The j-th line contains two space-separated integers aj, bj (1 ≤ aj, bj ≤ 1000) — the color and diameter of the j-th cap, correspondingly.
Output
Print two space-separated integers u, v, where u is the number of closed markers and v is the number of beautifully closed markers in the sought optimal way. Remember that you have to find the way to close the maximum number of markers, and if there are several such ways, you should choose the one where the number of beautifully closed markers is maximum.
Examples
Input
3 4
1 2
3 4
2 4
5 4
2 4
1 1
1 2
Output
3 2
Input
2 2
1 2
2 1
3 4
5 1
Output
1 0
Note
In the first test sample the first marker should be closed by the fourth cap, the second marker should be closed by the first cap and the third marker should be closed by the second cap. Thus, three markers will be closed, and two of them will be beautifully closed — the first and the third markers.
Tags: *special, greedy, sortings
Correct Solution:
```
n,m=map(int,input().split())
p=[list(map(int,input().split())) for i in range(n)]
dic1={}
dic2={}
for i in range(m):
x,y=map(int,input().split())
dic1[(x,y)]=dic1.get((x,y),0)+1
dic2[y]=dic2.get(y,0)+1
c1=0
c2=0
for x in p:
if dic1.get((x[0],x[1])):
c1=c1+1
dic1[(x[0],x[1])]=dic1[(x[0],x[1])]-1
if dic2.get(x[1]):
c2=c2+1
dic2[x[1]]=dic2[x[1]]-1
print(c2,c1)
```
| 99,700 | [
0.220458984375,
-0.145263671875,
0.482666015625,
0.53466796875,
-0.36083984375,
-0.26806640625,
-0.1390380859375,
0.4853515625,
0.1759033203125,
0.66748046875,
0.8330078125,
0.146728515625,
-0.052581787109375,
-0.580078125,
-0.2178955078125,
0.48291015625,
-0.09423828125,
-0.652343... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarpus has n markers and m marker caps. Each marker is described by two numbers: xi is the color and yi is the diameter. Correspondingly, each cap is described by two numbers: aj is the color and bj is the diameter. Cap (aj, bj) can close marker (xi, yi) only if their diameters match, that is, bj = yi. Besides, a marker is considered to be beautifully closed, if the cap color and the marker color match, that is, aj = xi.
Find the way to close the maximum number of markers. If there are several such ways, then choose the one that has the maximum number of beautifully closed markers.
Input
The first input line contains two space-separated integers n and m (1 ≤ n, m ≤ 105) — the number of markers and the number of caps, correspondingly.
Next n lines describe the markers. The i-th line contains two space-separated integers xi, yi (1 ≤ xi, yi ≤ 1000) — the i-th marker's color and diameter, correspondingly.
Next m lines describe the caps. The j-th line contains two space-separated integers aj, bj (1 ≤ aj, bj ≤ 1000) — the color and diameter of the j-th cap, correspondingly.
Output
Print two space-separated integers u, v, where u is the number of closed markers and v is the number of beautifully closed markers in the sought optimal way. Remember that you have to find the way to close the maximum number of markers, and if there are several such ways, you should choose the one where the number of beautifully closed markers is maximum.
Examples
Input
3 4
1 2
3 4
2 4
5 4
2 4
1 1
1 2
Output
3 2
Input
2 2
1 2
2 1
3 4
5 1
Output
1 0
Note
In the first test sample the first marker should be closed by the fourth cap, the second marker should be closed by the first cap and the third marker should be closed by the second cap. Thus, three markers will be closed, and two of them will be beautifully closed — the first and the third markers.
Tags: *special, greedy, sortings
Correct Solution:
```
def main():
from sys import stdin
l = list(map(int, stdin.read().split()))
n, yx = l[0] * 2, [[0] * 1001 for _ in range(1001)]
cnt = yx[0]
u = v = 0
for y, x in zip(l[3:n + 3:2], l[2:n + 2:2]):
cnt[y] += 1
yx[y][x] += 1
ba, l = list(zip(l[n + 3::2], l[n + 2::2])), []
for y, x in ba:
if yx[y][x]:
yx[y][x] -= 1
cnt[y] -= 1
v += 1
else:
l.append(y)
for y in l:
if cnt[y]:
cnt[y] -= 1
u += 1
print(u + v, v)
if __name__ == '__main__':
main()
```
| 99,701 | [
0.2181396484375,
-0.14111328125,
0.5107421875,
0.533203125,
-0.352294921875,
-0.2454833984375,
-0.1407470703125,
0.446533203125,
0.1737060546875,
0.6240234375,
0.79638671875,
0.13720703125,
-0.042999267578125,
-0.59326171875,
-0.2098388671875,
0.47705078125,
-0.0675048828125,
-0.64... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarpus has n markers and m marker caps. Each marker is described by two numbers: xi is the color and yi is the diameter. Correspondingly, each cap is described by two numbers: aj is the color and bj is the diameter. Cap (aj, bj) can close marker (xi, yi) only if their diameters match, that is, bj = yi. Besides, a marker is considered to be beautifully closed, if the cap color and the marker color match, that is, aj = xi.
Find the way to close the maximum number of markers. If there are several such ways, then choose the one that has the maximum number of beautifully closed markers.
Input
The first input line contains two space-separated integers n and m (1 ≤ n, m ≤ 105) — the number of markers and the number of caps, correspondingly.
Next n lines describe the markers. The i-th line contains two space-separated integers xi, yi (1 ≤ xi, yi ≤ 1000) — the i-th marker's color and diameter, correspondingly.
Next m lines describe the caps. The j-th line contains two space-separated integers aj, bj (1 ≤ aj, bj ≤ 1000) — the color and diameter of the j-th cap, correspondingly.
Output
Print two space-separated integers u, v, where u is the number of closed markers and v is the number of beautifully closed markers in the sought optimal way. Remember that you have to find the way to close the maximum number of markers, and if there are several such ways, you should choose the one where the number of beautifully closed markers is maximum.
Examples
Input
3 4
1 2
3 4
2 4
5 4
2 4
1 1
1 2
Output
3 2
Input
2 2
1 2
2 1
3 4
5 1
Output
1 0
Note
In the first test sample the first marker should be closed by the fourth cap, the second marker should be closed by the first cap and the third marker should be closed by the second cap. Thus, three markers will be closed, and two of them will be beautifully closed — the first and the third markers.
Tags: *special, greedy, sortings
Correct Solution:
```
from collections import Counter
def read_ints():
return tuple(int(x) for x in input().split())
def parse_input(size):
data = [read_ints() for _ in range(size)]
by_diam = Counter(size for diam, size in data)
by_color = Counter(data)
return by_diam, by_color
n, m = read_ints()
pens_by_diam, pens_by_color = parse_input(n)
caps_by_diam, caps_by_color = parse_input(m)
closed = sum((pens_by_diam & caps_by_diam).values())
beautiful = sum((pens_by_color & caps_by_color).values())
print(closed, beautiful)
```
| 99,702 | [
0.2232666015625,
-0.166259765625,
0.474609375,
0.5263671875,
-0.388916015625,
-0.2685546875,
-0.08343505859375,
0.434814453125,
0.1998291015625,
0.6455078125,
0.8037109375,
0.1453857421875,
-0.050201416015625,
-0.5947265625,
-0.231689453125,
0.46923828125,
-0.107177734375,
-0.66210... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarpus has n markers and m marker caps. Each marker is described by two numbers: xi is the color and yi is the diameter. Correspondingly, each cap is described by two numbers: aj is the color and bj is the diameter. Cap (aj, bj) can close marker (xi, yi) only if their diameters match, that is, bj = yi. Besides, a marker is considered to be beautifully closed, if the cap color and the marker color match, that is, aj = xi.
Find the way to close the maximum number of markers. If there are several such ways, then choose the one that has the maximum number of beautifully closed markers.
Input
The first input line contains two space-separated integers n and m (1 ≤ n, m ≤ 105) — the number of markers and the number of caps, correspondingly.
Next n lines describe the markers. The i-th line contains two space-separated integers xi, yi (1 ≤ xi, yi ≤ 1000) — the i-th marker's color and diameter, correspondingly.
Next m lines describe the caps. The j-th line contains two space-separated integers aj, bj (1 ≤ aj, bj ≤ 1000) — the color and diameter of the j-th cap, correspondingly.
Output
Print two space-separated integers u, v, where u is the number of closed markers and v is the number of beautifully closed markers in the sought optimal way. Remember that you have to find the way to close the maximum number of markers, and if there are several such ways, you should choose the one where the number of beautifully closed markers is maximum.
Examples
Input
3 4
1 2
3 4
2 4
5 4
2 4
1 1
1 2
Output
3 2
Input
2 2
1 2
2 1
3 4
5 1
Output
1 0
Note
In the first test sample the first marker should be closed by the fourth cap, the second marker should be closed by the first cap and the third marker should be closed by the second cap. Thus, three markers will be closed, and two of them will be beautifully closed — the first and the third markers.
Submitted Solution:
```
__author__ = 'asmn'
n,m=tuple(map(int,input().split()))
cap1=[0]*1001
cap2=[0]*1001
cnt=[[0]*1001 for y in range(1001)]
for k in range(n):
x,y=tuple(map(int,input().split()))
cap1[y]+=1
cnt[x][y]+=1
ans=0
for k in range(m):
x,y=tuple(map(int,input().split()))
cap2[y]+=1
if cnt[x][y] > 0:
cnt[x][y]-=1
ans +=1
print(sum(min(cap1[y],cap2[y]) for y in range(1001)),ans)
```
Yes
| 99,703 | [
0.2474365234375,
-0.1116943359375,
0.375732421875,
0.47998046875,
-0.44677734375,
-0.18896484375,
-0.16162109375,
0.51025390625,
0.1812744140625,
0.63623046875,
0.78857421875,
0.1346435546875,
-0.0806884765625,
-0.60888671875,
-0.263427734375,
0.52197265625,
-0.004852294921875,
-0.... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarpus has n markers and m marker caps. Each marker is described by two numbers: xi is the color and yi is the diameter. Correspondingly, each cap is described by two numbers: aj is the color and bj is the diameter. Cap (aj, bj) can close marker (xi, yi) only if their diameters match, that is, bj = yi. Besides, a marker is considered to be beautifully closed, if the cap color and the marker color match, that is, aj = xi.
Find the way to close the maximum number of markers. If there are several such ways, then choose the one that has the maximum number of beautifully closed markers.
Input
The first input line contains two space-separated integers n and m (1 ≤ n, m ≤ 105) — the number of markers and the number of caps, correspondingly.
Next n lines describe the markers. The i-th line contains two space-separated integers xi, yi (1 ≤ xi, yi ≤ 1000) — the i-th marker's color and diameter, correspondingly.
Next m lines describe the caps. The j-th line contains two space-separated integers aj, bj (1 ≤ aj, bj ≤ 1000) — the color and diameter of the j-th cap, correspondingly.
Output
Print two space-separated integers u, v, where u is the number of closed markers and v is the number of beautifully closed markers in the sought optimal way. Remember that you have to find the way to close the maximum number of markers, and if there are several such ways, you should choose the one where the number of beautifully closed markers is maximum.
Examples
Input
3 4
1 2
3 4
2 4
5 4
2 4
1 1
1 2
Output
3 2
Input
2 2
1 2
2 1
3 4
5 1
Output
1 0
Note
In the first test sample the first marker should be closed by the fourth cap, the second marker should be closed by the first cap and the third marker should be closed by the second cap. Thus, three markers will be closed, and two of them will be beautifully closed — the first and the third markers.
Submitted Solution:
```
n,m=map(int,input().split())
inp=[list(map(int,input().split())) for i in range(n)]
dict1={}
dict2={}
count1=0
count2=0
for i in range(m):
a,b=map(int,input().split())
dict1[(a,b)]=dict1.get((a,b),0)+1
dict2[b]=dict2.get(b,0)+1
for i in inp:
if dict2.get(i[1]):
count1=count1+1
dict2[i[1]]=dict2[i[1]]-1
if dict1.get((i[0],i[1])):
count2=count2+1
dict1[(i[0],i[1])]=dict1[(i[0],i[1])]-1
print(count1,count2)
```
Yes
| 99,704 | [
0.241943359375,
-0.0992431640625,
0.347900390625,
0.472900390625,
-0.44580078125,
-0.1693115234375,
-0.1734619140625,
0.54052734375,
0.1912841796875,
0.6591796875,
0.783203125,
0.14697265625,
-0.055145263671875,
-0.62890625,
-0.2939453125,
0.50634765625,
-0.018035888671875,
-0.6572... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarpus has n markers and m marker caps. Each marker is described by two numbers: xi is the color and yi is the diameter. Correspondingly, each cap is described by two numbers: aj is the color and bj is the diameter. Cap (aj, bj) can close marker (xi, yi) only if their diameters match, that is, bj = yi. Besides, a marker is considered to be beautifully closed, if the cap color and the marker color match, that is, aj = xi.
Find the way to close the maximum number of markers. If there are several such ways, then choose the one that has the maximum number of beautifully closed markers.
Input
The first input line contains two space-separated integers n and m (1 ≤ n, m ≤ 105) — the number of markers and the number of caps, correspondingly.
Next n lines describe the markers. The i-th line contains two space-separated integers xi, yi (1 ≤ xi, yi ≤ 1000) — the i-th marker's color and diameter, correspondingly.
Next m lines describe the caps. The j-th line contains two space-separated integers aj, bj (1 ≤ aj, bj ≤ 1000) — the color and diameter of the j-th cap, correspondingly.
Output
Print two space-separated integers u, v, where u is the number of closed markers and v is the number of beautifully closed markers in the sought optimal way. Remember that you have to find the way to close the maximum number of markers, and if there are several such ways, you should choose the one where the number of beautifully closed markers is maximum.
Examples
Input
3 4
1 2
3 4
2 4
5 4
2 4
1 1
1 2
Output
3 2
Input
2 2
1 2
2 1
3 4
5 1
Output
1 0
Note
In the first test sample the first marker should be closed by the fourth cap, the second marker should be closed by the first cap and the third marker should be closed by the second cap. Thus, three markers will be closed, and two of them will be beautifully closed — the first and the third markers.
Submitted Solution:
```
n,m = list(map(int,input().split()))
buck1,buck2,cb,c = {},{}, 0, 0
for i in range(n):
k1,k2 = list(map(int,input().split()))
if k2 in buck1: buck1[k2][k1] = buck1[k2].get(k1,0) + 1 # get - The method get() returns a value for the given key
else: buck1[k2] = {k1:1}
for i in range(m):
k1,k2 = list(map(int,input().split()))
if k2 in buck2: buck2[k2][k1] = buck2[k2].get(k1,0) + 1
elif k2 in buck1: buck2[k2] = {k1:1}
for i in buck1.keys() & buck2.keys():
c += min(sum(buck1[i].values()), sum(buck2[i].values()))
cb += sum(min(buck1[i][k], buck2[i][k]) for k in buck1[i].keys() & buck2[i].keys())
print(c,cb)
```
Yes
| 99,705 | [
0.2374267578125,
-0.10107421875,
0.36572265625,
0.47998046875,
-0.475830078125,
-0.16455078125,
-0.186767578125,
0.55029296875,
0.1907958984375,
0.6708984375,
0.791015625,
0.137451171875,
-0.0849609375,
-0.603515625,
-0.27490234375,
0.5322265625,
-0.0181884765625,
-0.65283203125,
... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarpus has n markers and m marker caps. Each marker is described by two numbers: xi is the color and yi is the diameter. Correspondingly, each cap is described by two numbers: aj is the color and bj is the diameter. Cap (aj, bj) can close marker (xi, yi) only if their diameters match, that is, bj = yi. Besides, a marker is considered to be beautifully closed, if the cap color and the marker color match, that is, aj = xi.
Find the way to close the maximum number of markers. If there are several such ways, then choose the one that has the maximum number of beautifully closed markers.
Input
The first input line contains two space-separated integers n and m (1 ≤ n, m ≤ 105) — the number of markers and the number of caps, correspondingly.
Next n lines describe the markers. The i-th line contains two space-separated integers xi, yi (1 ≤ xi, yi ≤ 1000) — the i-th marker's color and diameter, correspondingly.
Next m lines describe the caps. The j-th line contains two space-separated integers aj, bj (1 ≤ aj, bj ≤ 1000) — the color and diameter of the j-th cap, correspondingly.
Output
Print two space-separated integers u, v, where u is the number of closed markers and v is the number of beautifully closed markers in the sought optimal way. Remember that you have to find the way to close the maximum number of markers, and if there are several such ways, you should choose the one where the number of beautifully closed markers is maximum.
Examples
Input
3 4
1 2
3 4
2 4
5 4
2 4
1 1
1 2
Output
3 2
Input
2 2
1 2
2 1
3 4
5 1
Output
1 0
Note
In the first test sample the first marker should be closed by the fourth cap, the second marker should be closed by the first cap and the third marker should be closed by the second cap. Thus, three markers will be closed, and two of them will be beautifully closed — the first and the third markers.
Submitted Solution:
```
n, m = map(int, input().split())
a = dict()
l = list()
u = 0
v = 0
for i in range(n):
c, d = map(int, input().split())
if a.get(d, -1) == -1:
a[d] = dict()
a[d][c] = 1
elif a[d].get(c, -1) == -1:
a[d][c] = 1
else:
a[d][c] += 1
for i in range(m):
c, d = map(int, input().split())
if a.get(d, -1) != -1:
if a[d].get(c, -1) == -1:
l.append((c, d))
else:
a[d][c] -= 1
u += 1
if a[d][c] == 0:
del a[d][c]
if a[d] == {}:
del a[d]
for c, d in l:
if a.get(d, -1) != -1:
for i in a[d]:
c = i
break
a[d][i] -= 1
v += 1
if a[d][i] == 0:
del a[d][i]
if a[d] == {}:
del a[d]
print(u + v, u)
```
Yes
| 99,706 | [
0.236083984375,
-0.10302734375,
0.35205078125,
0.477783203125,
-0.453857421875,
-0.157958984375,
-0.1741943359375,
0.5380859375,
0.2108154296875,
0.65673828125,
0.7685546875,
0.12548828125,
-0.071044921875,
-0.60400390625,
-0.279296875,
0.51220703125,
-0.035003662109375,
-0.6567382... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarpus has n markers and m marker caps. Each marker is described by two numbers: xi is the color and yi is the diameter. Correspondingly, each cap is described by two numbers: aj is the color and bj is the diameter. Cap (aj, bj) can close marker (xi, yi) only if their diameters match, that is, bj = yi. Besides, a marker is considered to be beautifully closed, if the cap color and the marker color match, that is, aj = xi.
Find the way to close the maximum number of markers. If there are several such ways, then choose the one that has the maximum number of beautifully closed markers.
Input
The first input line contains two space-separated integers n and m (1 ≤ n, m ≤ 105) — the number of markers and the number of caps, correspondingly.
Next n lines describe the markers. The i-th line contains two space-separated integers xi, yi (1 ≤ xi, yi ≤ 1000) — the i-th marker's color and diameter, correspondingly.
Next m lines describe the caps. The j-th line contains two space-separated integers aj, bj (1 ≤ aj, bj ≤ 1000) — the color and diameter of the j-th cap, correspondingly.
Output
Print two space-separated integers u, v, where u is the number of closed markers and v is the number of beautifully closed markers in the sought optimal way. Remember that you have to find the way to close the maximum number of markers, and if there are several such ways, you should choose the one where the number of beautifully closed markers is maximum.
Examples
Input
3 4
1 2
3 4
2 4
5 4
2 4
1 1
1 2
Output
3 2
Input
2 2
1 2
2 1
3 4
5 1
Output
1 0
Note
In the first test sample the first marker should be closed by the fourth cap, the second marker should be closed by the first cap and the third marker should be closed by the second cap. Thus, three markers will be closed, and two of them will be beautifully closed — the first and the third markers.
Submitted Solution:
```
n,m=map(int,input().split())
d,c,p,q={},{},{},{}
for i in range(n):
x,y=map(int,input().split())
if (x,y) in d:
d[(x,y)]=+1
else:
d[(x,y)]=1
if y in p:
p[y]+=1
else:
p[y]=1
u,v=0,0
for j in range(m):
x,y=map(int,input().split())
if (x,y) in d and d[(x,y)]>0:
d[(x,y)]=-1
u,v=u+1,v+1
p[y]=p[y]-1
else:
if y in q:
q[y]=+1
else:
q[y]=1
for i in p:
if i in q:
u=u+min(p[i],q[i])
print(u,v)
```
No
| 99,707 | [
0.227783203125,
-0.10400390625,
0.36279296875,
0.465087890625,
-0.449462890625,
-0.1710205078125,
-0.1839599609375,
0.54150390625,
0.1822509765625,
0.66796875,
0.7900390625,
0.1336669921875,
-0.08233642578125,
-0.6025390625,
-0.272705078125,
0.52490234375,
-0.020172119140625,
-0.65... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarpus has n markers and m marker caps. Each marker is described by two numbers: xi is the color and yi is the diameter. Correspondingly, each cap is described by two numbers: aj is the color and bj is the diameter. Cap (aj, bj) can close marker (xi, yi) only if their diameters match, that is, bj = yi. Besides, a marker is considered to be beautifully closed, if the cap color and the marker color match, that is, aj = xi.
Find the way to close the maximum number of markers. If there are several such ways, then choose the one that has the maximum number of beautifully closed markers.
Input
The first input line contains two space-separated integers n and m (1 ≤ n, m ≤ 105) — the number of markers and the number of caps, correspondingly.
Next n lines describe the markers. The i-th line contains two space-separated integers xi, yi (1 ≤ xi, yi ≤ 1000) — the i-th marker's color and diameter, correspondingly.
Next m lines describe the caps. The j-th line contains two space-separated integers aj, bj (1 ≤ aj, bj ≤ 1000) — the color and diameter of the j-th cap, correspondingly.
Output
Print two space-separated integers u, v, where u is the number of closed markers and v is the number of beautifully closed markers in the sought optimal way. Remember that you have to find the way to close the maximum number of markers, and if there are several such ways, you should choose the one where the number of beautifully closed markers is maximum.
Examples
Input
3 4
1 2
3 4
2 4
5 4
2 4
1 1
1 2
Output
3 2
Input
2 2
1 2
2 1
3 4
5 1
Output
1 0
Note
In the first test sample the first marker should be closed by the fourth cap, the second marker should be closed by the first cap and the third marker should be closed by the second cap. Thus, three markers will be closed, and two of them will be beautifully closed — the first and the third markers.
Submitted Solution:
```
n,m=map(int,input().split())
m1={}
m2={}
c1={}
c2={}
for i in range(n):
x,y=(map(int,input().split()))
m1[y]=m1.get(y,0)+1
m2[(x,y)]=m2.get((x,y),0)+1
for i in range(m):
x,y=(map(int,input().split()))
c1[y]=c1.get(y,0)+1
c2[(x,y)]=c2.get((x,y),0)+1
r1=0
r2=0
for i in m1.keys():
if i in c1.keys():
t1=m1[i]
t2=c1[i]
r1=r1+(min(t1,t2))
for i in m2.keys():
if i in c2.keys():
t1=m2[i]
t2=m2[i]
r2=r2+(min(t1,t2))
print(r1,r2)
```
No
| 99,708 | [
0.22900390625,
-0.10693359375,
0.368896484375,
0.47998046875,
-0.444091796875,
-0.1690673828125,
-0.1729736328125,
0.5341796875,
0.1929931640625,
0.6650390625,
0.794921875,
0.1463623046875,
-0.0804443359375,
-0.61669921875,
-0.274169921875,
0.53759765625,
-0.0257568359375,
-0.65966... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarpus has n markers and m marker caps. Each marker is described by two numbers: xi is the color and yi is the diameter. Correspondingly, each cap is described by two numbers: aj is the color and bj is the diameter. Cap (aj, bj) can close marker (xi, yi) only if their diameters match, that is, bj = yi. Besides, a marker is considered to be beautifully closed, if the cap color and the marker color match, that is, aj = xi.
Find the way to close the maximum number of markers. If there are several such ways, then choose the one that has the maximum number of beautifully closed markers.
Input
The first input line contains two space-separated integers n and m (1 ≤ n, m ≤ 105) — the number of markers and the number of caps, correspondingly.
Next n lines describe the markers. The i-th line contains two space-separated integers xi, yi (1 ≤ xi, yi ≤ 1000) — the i-th marker's color and diameter, correspondingly.
Next m lines describe the caps. The j-th line contains two space-separated integers aj, bj (1 ≤ aj, bj ≤ 1000) — the color and diameter of the j-th cap, correspondingly.
Output
Print two space-separated integers u, v, where u is the number of closed markers and v is the number of beautifully closed markers in the sought optimal way. Remember that you have to find the way to close the maximum number of markers, and if there are several such ways, you should choose the one where the number of beautifully closed markers is maximum.
Examples
Input
3 4
1 2
3 4
2 4
5 4
2 4
1 1
1 2
Output
3 2
Input
2 2
1 2
2 1
3 4
5 1
Output
1 0
Note
In the first test sample the first marker should be closed by the fourth cap, the second marker should be closed by the first cap and the third marker should be closed by the second cap. Thus, three markers will be closed, and two of them will be beautifully closed — the first and the third markers.
Submitted Solution:
```
from operator import itemgetter
line = input().split()
n, m = int(line[0]), int(line[1])
mk,c=[],[]
for i in range(n):
line = input().split()
mk.append((int(line[1]), int(line[0])))
for i in range(m):
line = input().split()
c.append([int(line[1]), int(line[0])])
mk = sorted(mk,key=itemgetter(0,1))
c = sorted(c,key=itemgetter(0,1))
i, j, ic, jc, count, countp = 0, 0, 0, 0, 0, 0
while i < n and j < m:
if mk[i][0] < c[j][0]:
i += 1
elif mk[i][0] > c[j][0]:
j +=1
else:
count += 1
ic, jc = i, j
while ic < n and jc < m:
if mk[ic][1] < c[jc][1]:
ic += 1
elif mk[ic][1] > c[jc][1]:
jc += 1
else:
countp += 1
break
i += 1
j += 1
print(count,countp )
```
No
| 99,709 | [
0.214111328125,
-0.130615234375,
0.3291015625,
0.490966796875,
-0.43359375,
-0.202392578125,
-0.1629638671875,
0.5478515625,
0.2216796875,
0.64599609375,
0.796875,
0.133544921875,
-0.10894775390625,
-0.595703125,
-0.294189453125,
0.4990234375,
-0.00286102294921875,
-0.61669921875,
... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarpus has n markers and m marker caps. Each marker is described by two numbers: xi is the color and yi is the diameter. Correspondingly, each cap is described by two numbers: aj is the color and bj is the diameter. Cap (aj, bj) can close marker (xi, yi) only if their diameters match, that is, bj = yi. Besides, a marker is considered to be beautifully closed, if the cap color and the marker color match, that is, aj = xi.
Find the way to close the maximum number of markers. If there are several such ways, then choose the one that has the maximum number of beautifully closed markers.
Input
The first input line contains two space-separated integers n and m (1 ≤ n, m ≤ 105) — the number of markers and the number of caps, correspondingly.
Next n lines describe the markers. The i-th line contains two space-separated integers xi, yi (1 ≤ xi, yi ≤ 1000) — the i-th marker's color and diameter, correspondingly.
Next m lines describe the caps. The j-th line contains two space-separated integers aj, bj (1 ≤ aj, bj ≤ 1000) — the color and diameter of the j-th cap, correspondingly.
Output
Print two space-separated integers u, v, where u is the number of closed markers and v is the number of beautifully closed markers in the sought optimal way. Remember that you have to find the way to close the maximum number of markers, and if there are several such ways, you should choose the one where the number of beautifully closed markers is maximum.
Examples
Input
3 4
1 2
3 4
2 4
5 4
2 4
1 1
1 2
Output
3 2
Input
2 2
1 2
2 1
3 4
5 1
Output
1 0
Note
In the first test sample the first marker should be closed by the fourth cap, the second marker should be closed by the first cap and the third marker should be closed by the second cap. Thus, three markers will be closed, and two of them will be beautifully closed — the first and the third markers.
Submitted Solution:
```
def main():
from sys import stdin
l = list(map(int, stdin.read().split()))
n, b, y, u, v = l[0] * 2, -1, -2, 0, 0
xy = iter(sorted(zip(l[3:n + 3:2], l[2:n + 2:2])))
ab = iter(sorted(zip(l[n + 3::2], l[n + 2::2])))
try:
while True:
while b > y:
y, x = next(xy)
while b < y:
b, a = next(ab)
u += 1
if x == a:
v += 1
y, x = next(xy)
b, a = next(ab)
except StopIteration:
print(u, v)
if __name__ == '__main__':
main()
```
No
| 99,710 | [
0.2423095703125,
-0.09954833984375,
0.391845703125,
0.466064453125,
-0.44287109375,
-0.1575927734375,
-0.1995849609375,
0.51904296875,
0.181640625,
0.623046875,
0.75634765625,
0.11981201171875,
-0.06719970703125,
-0.59716796875,
-0.272705078125,
0.5244140625,
-0.0285186767578125,
-... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
In a building where Polycarp lives there are equal number of flats on each floor. Unfortunately, Polycarp don't remember how many flats are on each floor, but he remembers that the flats are numbered from 1 from lower to upper floors. That is, the first several flats are on the first floor, the next several flats are on the second and so on. Polycarp don't remember the total number of flats in the building, so you can consider the building to be infinitely high (i.e. there are infinitely many floors). Note that the floors are numbered from 1.
Polycarp remembers on which floors several flats are located. It is guaranteed that this information is not self-contradictory. It means that there exists a building with equal number of flats on each floor so that the flats from Polycarp's memory have the floors Polycarp remembers.
Given this information, is it possible to restore the exact floor for flat n?
Input
The first line contains two integers n and m (1 ≤ n ≤ 100, 0 ≤ m ≤ 100), where n is the number of the flat you need to restore floor for, and m is the number of flats in Polycarp's memory.
m lines follow, describing the Polycarp's memory: each of these lines contains a pair of integers ki, fi (1 ≤ ki ≤ 100, 1 ≤ fi ≤ 100), which means that the flat ki is on the fi-th floor. All values ki are distinct.
It is guaranteed that the given information is not self-contradictory.
Output
Print the number of the floor in which the n-th flat is located, if it is possible to determine it in a unique way. Print -1 if it is not possible to uniquely restore this floor.
Examples
Input
10 3
6 2
2 1
7 3
Output
4
Input
8 4
3 1
6 2
5 2
2 1
Output
-1
Note
In the first example the 6-th flat is on the 2-nd floor, while the 7-th flat is on the 3-rd, so, the 6-th flat is the last on its floor and there are 3 flats on each floor. Thus, the 10-th flat is on the 4-th floor.
In the second example there can be 3 or 4 flats on each floor, so we can't restore the floor for the 8-th flat.
Tags: brute force, implementation
Correct Solution:
```
n, m = [int(i) for i in input().split()]
mn = 10 ** 5
mx = 1
n -= 1
for i in range(m):
x, y = [int(i) for i in input().split()]
x -= 1
y -= 1
if y != 0:
mn = min(mn, x // y)
mx = max(mx, [(x + y) // (y + 1), x // (y + 1) + 1][x % (y + 1) == 0])
a = n // mx
for i in range(mx + 1, mn + 1):
if a != n // i:
print(-1)
exit()
print(a + 1)
```
| 99,997 | [
0.54443359375,
0.198486328125,
-0.16015625,
0.138671875,
-0.5927734375,
-0.446533203125,
-0.444580078125,
0.1558837890625,
0.40478515625,
0.5888671875,
0.9609375,
-0.0635986328125,
-0.09674072265625,
-0.69482421875,
-0.39599609375,
0.11773681640625,
-0.681640625,
-0.264892578125,
... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
In a building where Polycarp lives there are equal number of flats on each floor. Unfortunately, Polycarp don't remember how many flats are on each floor, but he remembers that the flats are numbered from 1 from lower to upper floors. That is, the first several flats are on the first floor, the next several flats are on the second and so on. Polycarp don't remember the total number of flats in the building, so you can consider the building to be infinitely high (i.e. there are infinitely many floors). Note that the floors are numbered from 1.
Polycarp remembers on which floors several flats are located. It is guaranteed that this information is not self-contradictory. It means that there exists a building with equal number of flats on each floor so that the flats from Polycarp's memory have the floors Polycarp remembers.
Given this information, is it possible to restore the exact floor for flat n?
Input
The first line contains two integers n and m (1 ≤ n ≤ 100, 0 ≤ m ≤ 100), where n is the number of the flat you need to restore floor for, and m is the number of flats in Polycarp's memory.
m lines follow, describing the Polycarp's memory: each of these lines contains a pair of integers ki, fi (1 ≤ ki ≤ 100, 1 ≤ fi ≤ 100), which means that the flat ki is on the fi-th floor. All values ki are distinct.
It is guaranteed that the given information is not self-contradictory.
Output
Print the number of the floor in which the n-th flat is located, if it is possible to determine it in a unique way. Print -1 if it is not possible to uniquely restore this floor.
Examples
Input
10 3
6 2
2 1
7 3
Output
4
Input
8 4
3 1
6 2
5 2
2 1
Output
-1
Note
In the first example the 6-th flat is on the 2-nd floor, while the 7-th flat is on the 3-rd, so, the 6-th flat is the last on its floor and there are 3 flats on each floor. Thus, the 10-th flat is on the 4-th floor.
In the second example there can be 3 or 4 flats on each floor, so we can't restore the floor for the 8-th flat.
Tags: brute force, implementation
Correct Solution:
```
import math
from sys import stdin
from math import ceil
if __name__ == '__main__':
numbers = list(map(int, input().split()))
n = numbers[0]
m = numbers[1]
floors = []
for i in range(m):
floors.append(tuple(map(int, input().split())))
rez = set()
for i in range(1,100 + 1):
ok = True
for ki, fi in floors:
if (ki + i - 1) // i != fi:
ok = False
break
if ok:
rez.add((n + i - 1) // i)
if len(rez) == 1:
x = rez.pop()
print(x)
else:
print("-1")
```
| 99,998 | [
0.54443359375,
0.198486328125,
-0.16015625,
0.138671875,
-0.5927734375,
-0.446533203125,
-0.444580078125,
0.1558837890625,
0.40478515625,
0.5888671875,
0.9609375,
-0.0635986328125,
-0.09674072265625,
-0.69482421875,
-0.39599609375,
0.11773681640625,
-0.681640625,
-0.264892578125,
... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
In a building where Polycarp lives there are equal number of flats on each floor. Unfortunately, Polycarp don't remember how many flats are on each floor, but he remembers that the flats are numbered from 1 from lower to upper floors. That is, the first several flats are on the first floor, the next several flats are on the second and so on. Polycarp don't remember the total number of flats in the building, so you can consider the building to be infinitely high (i.e. there are infinitely many floors). Note that the floors are numbered from 1.
Polycarp remembers on which floors several flats are located. It is guaranteed that this information is not self-contradictory. It means that there exists a building with equal number of flats on each floor so that the flats from Polycarp's memory have the floors Polycarp remembers.
Given this information, is it possible to restore the exact floor for flat n?
Input
The first line contains two integers n and m (1 ≤ n ≤ 100, 0 ≤ m ≤ 100), where n is the number of the flat you need to restore floor for, and m is the number of flats in Polycarp's memory.
m lines follow, describing the Polycarp's memory: each of these lines contains a pair of integers ki, fi (1 ≤ ki ≤ 100, 1 ≤ fi ≤ 100), which means that the flat ki is on the fi-th floor. All values ki are distinct.
It is guaranteed that the given information is not self-contradictory.
Output
Print the number of the floor in which the n-th flat is located, if it is possible to determine it in a unique way. Print -1 if it is not possible to uniquely restore this floor.
Examples
Input
10 3
6 2
2 1
7 3
Output
4
Input
8 4
3 1
6 2
5 2
2 1
Output
-1
Note
In the first example the 6-th flat is on the 2-nd floor, while the 7-th flat is on the 3-rd, so, the 6-th flat is the last on its floor and there are 3 flats on each floor. Thus, the 10-th flat is on the 4-th floor.
In the second example there can be 3 or 4 flats on each floor, so we can't restore the floor for the 8-th flat.
Tags: brute force, implementation
Correct Solution:
```
#Code by Sounak, IIESTS
#------------------------------warmup----------------------------
import os
import sys
import math
from io import BytesIO, IOBase
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
#-------------------game starts now-----------------------------------------------------
n, m = map(int, input().split())
l = set()
s = {i for i in range(1, 101)}
b = False
for i in range(m):
k, f = map(int, input().split())
if k == n:
print(f)
b = True
break
j = 1
if f == 1:
l = {i for i in range(k, 101)}
else:
while j <= (k-j)//(f-1):
if (k-j)%(f-1) == 0:
l.add((k-j)//(f-1))
j += f-1
else:
j += 1
s &= l
l.clear()
a = -1
if b == False:
t = True
for j in s:
if a == -1:
a = (n-1)//j
else:
if (n-1)//j != a:
print(-1)
t = False
break
if t == True:
print(a+1)
```
| 99,999 | [
0.54443359375,
0.198486328125,
-0.16015625,
0.138671875,
-0.5927734375,
-0.446533203125,
-0.444580078125,
0.1558837890625,
0.40478515625,
0.5888671875,
0.9609375,
-0.0635986328125,
-0.09674072265625,
-0.69482421875,
-0.39599609375,
0.11773681640625,
-0.681640625,
-0.264892578125,
... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
In a building where Polycarp lives there are equal number of flats on each floor. Unfortunately, Polycarp don't remember how many flats are on each floor, but he remembers that the flats are numbered from 1 from lower to upper floors. That is, the first several flats are on the first floor, the next several flats are on the second and so on. Polycarp don't remember the total number of flats in the building, so you can consider the building to be infinitely high (i.e. there are infinitely many floors). Note that the floors are numbered from 1.
Polycarp remembers on which floors several flats are located. It is guaranteed that this information is not self-contradictory. It means that there exists a building with equal number of flats on each floor so that the flats from Polycarp's memory have the floors Polycarp remembers.
Given this information, is it possible to restore the exact floor for flat n?
Input
The first line contains two integers n and m (1 ≤ n ≤ 100, 0 ≤ m ≤ 100), where n is the number of the flat you need to restore floor for, and m is the number of flats in Polycarp's memory.
m lines follow, describing the Polycarp's memory: each of these lines contains a pair of integers ki, fi (1 ≤ ki ≤ 100, 1 ≤ fi ≤ 100), which means that the flat ki is on the fi-th floor. All values ki are distinct.
It is guaranteed that the given information is not self-contradictory.
Output
Print the number of the floor in which the n-th flat is located, if it is possible to determine it in a unique way. Print -1 if it is not possible to uniquely restore this floor.
Examples
Input
10 3
6 2
2 1
7 3
Output
4
Input
8 4
3 1
6 2
5 2
2 1
Output
-1
Note
In the first example the 6-th flat is on the 2-nd floor, while the 7-th flat is on the 3-rd, so, the 6-th flat is the last on its floor and there are 3 flats on each floor. Thus, the 10-th flat is on the 4-th floor.
In the second example there can be 3 or 4 flats on each floor, so we can't restore the floor for the 8-th flat.
Tags: brute force, implementation
Correct Solution:
```
import sys, os
n, m = map(int, input().split())
mi = []
ma = []
if m == 0:
if n == 1:
print(1)
else:
print(-1)
exit(0)
sys.exit()
os.abort()
for i in range(m):
a, b = map(int, input().split())
if b == 1:
ma.append(1000000000)
mi.append(a)
if n <= a:
print(1)
exit(0)
sys.exit()
os.abort()
else:
mak = (a - 1) // (b - 1)
ma.append(mak)
if a % b == 0:
mi.append(a // b)
else:
mi.append((a // b ) + 1)
#print(mi, ma)
mik = min(ma)
mak = max(mi)
if n % mik == 0:
a = n // mik
else:
a = (n // mik) + 1
if n % mak == 0:
b = n // mak
else:
b = (n // mak) + 1
if a == b:
print(b)
else:
print(-1)
```
| 100,000 | [
0.54443359375,
0.198486328125,
-0.16015625,
0.138671875,
-0.5927734375,
-0.446533203125,
-0.444580078125,
0.1558837890625,
0.40478515625,
0.5888671875,
0.9609375,
-0.0635986328125,
-0.09674072265625,
-0.69482421875,
-0.39599609375,
0.11773681640625,
-0.681640625,
-0.264892578125,
... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
In a building where Polycarp lives there are equal number of flats on each floor. Unfortunately, Polycarp don't remember how many flats are on each floor, but he remembers that the flats are numbered from 1 from lower to upper floors. That is, the first several flats are on the first floor, the next several flats are on the second and so on. Polycarp don't remember the total number of flats in the building, so you can consider the building to be infinitely high (i.e. there are infinitely many floors). Note that the floors are numbered from 1.
Polycarp remembers on which floors several flats are located. It is guaranteed that this information is not self-contradictory. It means that there exists a building with equal number of flats on each floor so that the flats from Polycarp's memory have the floors Polycarp remembers.
Given this information, is it possible to restore the exact floor for flat n?
Input
The first line contains two integers n and m (1 ≤ n ≤ 100, 0 ≤ m ≤ 100), where n is the number of the flat you need to restore floor for, and m is the number of flats in Polycarp's memory.
m lines follow, describing the Polycarp's memory: each of these lines contains a pair of integers ki, fi (1 ≤ ki ≤ 100, 1 ≤ fi ≤ 100), which means that the flat ki is on the fi-th floor. All values ki are distinct.
It is guaranteed that the given information is not self-contradictory.
Output
Print the number of the floor in which the n-th flat is located, if it is possible to determine it in a unique way. Print -1 if it is not possible to uniquely restore this floor.
Examples
Input
10 3
6 2
2 1
7 3
Output
4
Input
8 4
3 1
6 2
5 2
2 1
Output
-1
Note
In the first example the 6-th flat is on the 2-nd floor, while the 7-th flat is on the 3-rd, so, the 6-th flat is the last on its floor and there are 3 flats on each floor. Thus, the 10-th flat is on the 4-th floor.
In the second example there can be 3 or 4 flats on each floor, so we can't restore the floor for the 8-th flat.
Tags: brute force, implementation
Correct Solution:
```
def rec(i):
global a
return i
import sys
from collections import Counter
sys.setrecursionlimit(10**6)
#n=int(input())
n,m=list(map(int,input().split()))
a=[[] for i in range(100)]
b=[i for i in range(1,101)]
for i in range(m):
x,y=list(map(int,input().split()))
z=b.copy()
for i0 in z:
if not(((x-1)>=(y-1)*i0)and((x-1)<y*i0)):
b.remove(i0)
a=set()
for i0 in b:
a.add((n-1)//i0)
if len(a)==1:
print(a.pop()+1)
else:
print(-1)
```
| 100,001 | [
0.54443359375,
0.198486328125,
-0.16015625,
0.138671875,
-0.5927734375,
-0.446533203125,
-0.444580078125,
0.1558837890625,
0.40478515625,
0.5888671875,
0.9609375,
-0.0635986328125,
-0.09674072265625,
-0.69482421875,
-0.39599609375,
0.11773681640625,
-0.681640625,
-0.264892578125,
... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
In a building where Polycarp lives there are equal number of flats on each floor. Unfortunately, Polycarp don't remember how many flats are on each floor, but he remembers that the flats are numbered from 1 from lower to upper floors. That is, the first several flats are on the first floor, the next several flats are on the second and so on. Polycarp don't remember the total number of flats in the building, so you can consider the building to be infinitely high (i.e. there are infinitely many floors). Note that the floors are numbered from 1.
Polycarp remembers on which floors several flats are located. It is guaranteed that this information is not self-contradictory. It means that there exists a building with equal number of flats on each floor so that the flats from Polycarp's memory have the floors Polycarp remembers.
Given this information, is it possible to restore the exact floor for flat n?
Input
The first line contains two integers n and m (1 ≤ n ≤ 100, 0 ≤ m ≤ 100), where n is the number of the flat you need to restore floor for, and m is the number of flats in Polycarp's memory.
m lines follow, describing the Polycarp's memory: each of these lines contains a pair of integers ki, fi (1 ≤ ki ≤ 100, 1 ≤ fi ≤ 100), which means that the flat ki is on the fi-th floor. All values ki are distinct.
It is guaranteed that the given information is not self-contradictory.
Output
Print the number of the floor in which the n-th flat is located, if it is possible to determine it in a unique way. Print -1 if it is not possible to uniquely restore this floor.
Examples
Input
10 3
6 2
2 1
7 3
Output
4
Input
8 4
3 1
6 2
5 2
2 1
Output
-1
Note
In the first example the 6-th flat is on the 2-nd floor, while the 7-th flat is on the 3-rd, so, the 6-th flat is the last on its floor and there are 3 flats on each floor. Thus, the 10-th flat is on the 4-th floor.
In the second example there can be 3 or 4 flats on each floor, so we can't restore the floor for the 8-th flat.
Tags: brute force, implementation
Correct Solution:
```
n,m=map(int,input().split())
n-=1
k=[]
f=[]
p=0
for i in range(m):
q=list(map(int,input().split()))
k.append(q[0])
f.append(q[1])
for i in range(1,101):
for j in range(m):
if ((k[j]-1)//i)+1!=f[j]:
break
else:
if not p:
p=n//i+1
else:
q=n//i+1
if p!=q:
print(-1)
exit()
print(p)
```
| 100,002 | [
0.54443359375,
0.198486328125,
-0.16015625,
0.138671875,
-0.5927734375,
-0.446533203125,
-0.444580078125,
0.1558837890625,
0.40478515625,
0.5888671875,
0.9609375,
-0.0635986328125,
-0.09674072265625,
-0.69482421875,
-0.39599609375,
0.11773681640625,
-0.681640625,
-0.264892578125,
... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
In a building where Polycarp lives there are equal number of flats on each floor. Unfortunately, Polycarp don't remember how many flats are on each floor, but he remembers that the flats are numbered from 1 from lower to upper floors. That is, the first several flats are on the first floor, the next several flats are on the second and so on. Polycarp don't remember the total number of flats in the building, so you can consider the building to be infinitely high (i.e. there are infinitely many floors). Note that the floors are numbered from 1.
Polycarp remembers on which floors several flats are located. It is guaranteed that this information is not self-contradictory. It means that there exists a building with equal number of flats on each floor so that the flats from Polycarp's memory have the floors Polycarp remembers.
Given this information, is it possible to restore the exact floor for flat n?
Input
The first line contains two integers n and m (1 ≤ n ≤ 100, 0 ≤ m ≤ 100), where n is the number of the flat you need to restore floor for, and m is the number of flats in Polycarp's memory.
m lines follow, describing the Polycarp's memory: each of these lines contains a pair of integers ki, fi (1 ≤ ki ≤ 100, 1 ≤ fi ≤ 100), which means that the flat ki is on the fi-th floor. All values ki are distinct.
It is guaranteed that the given information is not self-contradictory.
Output
Print the number of the floor in which the n-th flat is located, if it is possible to determine it in a unique way. Print -1 if it is not possible to uniquely restore this floor.
Examples
Input
10 3
6 2
2 1
7 3
Output
4
Input
8 4
3 1
6 2
5 2
2 1
Output
-1
Note
In the first example the 6-th flat is on the 2-nd floor, while the 7-th flat is on the 3-rd, so, the 6-th flat is the last on its floor and there are 3 flats on each floor. Thus, the 10-th flat is on the 4-th floor.
In the second example there can be 3 or 4 flats on each floor, so we can't restore the floor for the 8-th flat.
Tags: brute force, implementation
Correct Solution:
```
from math import ceil
n, m = map(int, input().split())
k = [0 for i in range(m)]
f = [0 for i in range(m)]
x = -1
for i in range(m):
k[i], f[i] = map(int, input().split())
i = 0
while i < m:
j = i
while j < m:
if abs(k[i] - k[j]) == 1 and abs(f[i] - f[j]) == 1:
if f[i] < f[j]:
x = ceil(n / ceil(k[i] / f[i]))
else:
x = ceil(n / ceil(k[j] / f[j]))
i = m - 1
j = i
j += 1
i += 1
if x > 0:
print(x)
else:
c = []
for i in range(1, 101):
j = 0
b = True
while j < m and b:
if not (ceil(k[j] / i) == f[j]):
b = False
j += 1
if b:
c.append(i)
x = ceil(n / c[0])
for i in range(len(c)):
if ceil(n / c[i]) != x:
x = -1
break
print(x)
```
| 100,003 | [
0.54443359375,
0.198486328125,
-0.16015625,
0.138671875,
-0.5927734375,
-0.446533203125,
-0.444580078125,
0.1558837890625,
0.40478515625,
0.5888671875,
0.9609375,
-0.0635986328125,
-0.09674072265625,
-0.69482421875,
-0.39599609375,
0.11773681640625,
-0.681640625,
-0.264892578125,
... | 24 |
Provide tags and a correct Python 3 solution for this coding contest problem.
In a building where Polycarp lives there are equal number of flats on each floor. Unfortunately, Polycarp don't remember how many flats are on each floor, but he remembers that the flats are numbered from 1 from lower to upper floors. That is, the first several flats are on the first floor, the next several flats are on the second and so on. Polycarp don't remember the total number of flats in the building, so you can consider the building to be infinitely high (i.e. there are infinitely many floors). Note that the floors are numbered from 1.
Polycarp remembers on which floors several flats are located. It is guaranteed that this information is not self-contradictory. It means that there exists a building with equal number of flats on each floor so that the flats from Polycarp's memory have the floors Polycarp remembers.
Given this information, is it possible to restore the exact floor for flat n?
Input
The first line contains two integers n and m (1 ≤ n ≤ 100, 0 ≤ m ≤ 100), where n is the number of the flat you need to restore floor for, and m is the number of flats in Polycarp's memory.
m lines follow, describing the Polycarp's memory: each of these lines contains a pair of integers ki, fi (1 ≤ ki ≤ 100, 1 ≤ fi ≤ 100), which means that the flat ki is on the fi-th floor. All values ki are distinct.
It is guaranteed that the given information is not self-contradictory.
Output
Print the number of the floor in which the n-th flat is located, if it is possible to determine it in a unique way. Print -1 if it is not possible to uniquely restore this floor.
Examples
Input
10 3
6 2
2 1
7 3
Output
4
Input
8 4
3 1
6 2
5 2
2 1
Output
-1
Note
In the first example the 6-th flat is on the 2-nd floor, while the 7-th flat is on the 3-rd, so, the 6-th flat is the last on its floor and there are 3 flats on each floor. Thus, the 10-th flat is on the 4-th floor.
In the second example there can be 3 or 4 flats on each floor, so we can't restore the floor for the 8-th flat.
Tags: brute force, implementation
Correct Solution:
```
def xor(a,b,i):
if (((a-1)//i)==(b-1)):
return True
elif(a<i) and (b==1):
return True
else:
return False
dannie = input()
dannie = dannie.split(' ')
level = int(dannie[0])
n = int(dannie[1])
levels = []
if level == 1:
print(1)
elif n == 0:
print(-1)
else:
for i in range(0,n):
info = input()
info = info.split(' ')
levels.append(info)
fl = True
i = 1
count = 0
while (i<=100) and (fl):
for etaz in levels:
fl2 = True
flat = int(etaz[0])
floor = int(etaz[1])
if xor(flat, floor, i):
continue
else:
fl2 = False
if not(fl2):
break
if not(fl2):
i = i + 1
elif (count==0) and fl2:
count += 1
if level%i==0:
answer = int(level/i)
i = i + 1
else:
answer = int((level//i) + 1)
i = i + 1
elif fl2 and count!=0:
if level%i==0:
answer1 = level/i
else:
answer1 = level//i + 1
if answer1 == answer:
i = i + 1
continue
else:
print(-1)
fl = False
else:
i +=1
if fl :
try:
print(answer)
except NameError:
print(-1)
```
| 100,004 | [
0.54443359375,
0.198486328125,
-0.16015625,
0.138671875,
-0.5927734375,
-0.446533203125,
-0.444580078125,
0.1558837890625,
0.40478515625,
0.5888671875,
0.9609375,
-0.0635986328125,
-0.09674072265625,
-0.69482421875,
-0.39599609375,
0.11773681640625,
-0.681640625,
-0.264892578125,
... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In a building where Polycarp lives there are equal number of flats on each floor. Unfortunately, Polycarp don't remember how many flats are on each floor, but he remembers that the flats are numbered from 1 from lower to upper floors. That is, the first several flats are on the first floor, the next several flats are on the second and so on. Polycarp don't remember the total number of flats in the building, so you can consider the building to be infinitely high (i.e. there are infinitely many floors). Note that the floors are numbered from 1.
Polycarp remembers on which floors several flats are located. It is guaranteed that this information is not self-contradictory. It means that there exists a building with equal number of flats on each floor so that the flats from Polycarp's memory have the floors Polycarp remembers.
Given this information, is it possible to restore the exact floor for flat n?
Input
The first line contains two integers n and m (1 ≤ n ≤ 100, 0 ≤ m ≤ 100), where n is the number of the flat you need to restore floor for, and m is the number of flats in Polycarp's memory.
m lines follow, describing the Polycarp's memory: each of these lines contains a pair of integers ki, fi (1 ≤ ki ≤ 100, 1 ≤ fi ≤ 100), which means that the flat ki is on the fi-th floor. All values ki are distinct.
It is guaranteed that the given information is not self-contradictory.
Output
Print the number of the floor in which the n-th flat is located, if it is possible to determine it in a unique way. Print -1 if it is not possible to uniquely restore this floor.
Examples
Input
10 3
6 2
2 1
7 3
Output
4
Input
8 4
3 1
6 2
5 2
2 1
Output
-1
Note
In the first example the 6-th flat is on the 2-nd floor, while the 7-th flat is on the 3-rd, so, the 6-th flat is the last on its floor and there are 3 flats on each floor. Thus, the 10-th flat is on the 4-th floor.
In the second example there can be 3 or 4 flats on each floor, so we can't restore the floor for the 8-th flat.
Submitted Solution:
```
import math
n,q = map(int,input().split())
lst = [ ]
for i in range(q):
x,y = map(int,input().split())
lst.append((x,y))
ans = set()
for no_of_floors in range(1,101):
flag = 1
for k,f in lst:
temp_floor = math.ceil(k/no_of_floors)
if(temp_floor!=f):
flag = 0
if(flag):
temp = math.ceil(n/no_of_floors)
ans.add(temp)
if(len(ans)!=1):
print(-1)
else:
print(*ans)
```
Yes
| 100,005 | [
0.54248046875,
0.2529296875,
-0.1783447265625,
0.0933837890625,
-0.63818359375,
-0.3056640625,
-0.4736328125,
0.261962890625,
0.33447265625,
0.6259765625,
0.89501953125,
-0.0787353515625,
-0.10980224609375,
-0.6767578125,
-0.44482421875,
0.08648681640625,
-0.669921875,
-0.318359375... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In a building where Polycarp lives there are equal number of flats on each floor. Unfortunately, Polycarp don't remember how many flats are on each floor, but he remembers that the flats are numbered from 1 from lower to upper floors. That is, the first several flats are on the first floor, the next several flats are on the second and so on. Polycarp don't remember the total number of flats in the building, so you can consider the building to be infinitely high (i.e. there are infinitely many floors). Note that the floors are numbered from 1.
Polycarp remembers on which floors several flats are located. It is guaranteed that this information is not self-contradictory. It means that there exists a building with equal number of flats on each floor so that the flats from Polycarp's memory have the floors Polycarp remembers.
Given this information, is it possible to restore the exact floor for flat n?
Input
The first line contains two integers n and m (1 ≤ n ≤ 100, 0 ≤ m ≤ 100), where n is the number of the flat you need to restore floor for, and m is the number of flats in Polycarp's memory.
m lines follow, describing the Polycarp's memory: each of these lines contains a pair of integers ki, fi (1 ≤ ki ≤ 100, 1 ≤ fi ≤ 100), which means that the flat ki is on the fi-th floor. All values ki are distinct.
It is guaranteed that the given information is not self-contradictory.
Output
Print the number of the floor in which the n-th flat is located, if it is possible to determine it in a unique way. Print -1 if it is not possible to uniquely restore this floor.
Examples
Input
10 3
6 2
2 1
7 3
Output
4
Input
8 4
3 1
6 2
5 2
2 1
Output
-1
Note
In the first example the 6-th flat is on the 2-nd floor, while the 7-th flat is on the 3-rd, so, the 6-th flat is the last on its floor and there are 3 flats on each floor. Thus, the 10-th flat is on the 4-th floor.
In the second example there can be 3 or 4 flats on each floor, so we can't restore the floor for the 8-th flat.
Submitted Solution:
```
import math
def find_3():
etazh = []
for p in range(1, 101):
if all((memory[0] + p - 1) // p == memory[1] for memory in mass):
etazh.append(p)
return etazh
def find_2():
etazh = []
p = 1
while p < 100:
for i in range (m):
if math.ceil(mass[i][0]/p) != mass[i][1]:
p += 1
break
elif i==(m-1):
etazh.append(p)
p += 1
return etazh
def find_1():
etazh = []
for p in range(100):
suit = True
for i in range(m):
if math.ceil(mass[i][0]/p) != mass[i][1]:
suit = False
break
if suit:
etazh.append(p)
return etazh
n, m = map(int, input().split())
mass = []
for i in range (m):
mass.append(list(map(int, input().split())))
etazh = find_3()
if all((n+x-1)//x == (n+etazh[0]-1)//etazh[0] for x in etazh):
print((n+etazh[0]-1)//etazh[0])
else:
print(-1)
```
Yes
| 100,006 | [
0.54248046875,
0.2529296875,
-0.1783447265625,
0.0933837890625,
-0.63818359375,
-0.3056640625,
-0.4736328125,
0.261962890625,
0.33447265625,
0.6259765625,
0.89501953125,
-0.0787353515625,
-0.10980224609375,
-0.6767578125,
-0.44482421875,
0.08648681640625,
-0.669921875,
-0.318359375... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In a building where Polycarp lives there are equal number of flats on each floor. Unfortunately, Polycarp don't remember how many flats are on each floor, but he remembers that the flats are numbered from 1 from lower to upper floors. That is, the first several flats are on the first floor, the next several flats are on the second and so on. Polycarp don't remember the total number of flats in the building, so you can consider the building to be infinitely high (i.e. there are infinitely many floors). Note that the floors are numbered from 1.
Polycarp remembers on which floors several flats are located. It is guaranteed that this information is not self-contradictory. It means that there exists a building with equal number of flats on each floor so that the flats from Polycarp's memory have the floors Polycarp remembers.
Given this information, is it possible to restore the exact floor for flat n?
Input
The first line contains two integers n and m (1 ≤ n ≤ 100, 0 ≤ m ≤ 100), where n is the number of the flat you need to restore floor for, and m is the number of flats in Polycarp's memory.
m lines follow, describing the Polycarp's memory: each of these lines contains a pair of integers ki, fi (1 ≤ ki ≤ 100, 1 ≤ fi ≤ 100), which means that the flat ki is on the fi-th floor. All values ki are distinct.
It is guaranteed that the given information is not self-contradictory.
Output
Print the number of the floor in which the n-th flat is located, if it is possible to determine it in a unique way. Print -1 if it is not possible to uniquely restore this floor.
Examples
Input
10 3
6 2
2 1
7 3
Output
4
Input
8 4
3 1
6 2
5 2
2 1
Output
-1
Note
In the first example the 6-th flat is on the 2-nd floor, while the 7-th flat is on the 3-rd, so, the 6-th flat is the last on its floor and there are 3 flats on each floor. Thus, the 10-th flat is on the 4-th floor.
In the second example there can be 3 or 4 flats on each floor, so we can't restore the floor for the 8-th flat.
Submitted Solution:
```
n, m = map(int, input().split())
k = [0] * 500
f = [0] * 500
for i in range(m):
k[i], f[i] = map(int, input().split())
vars = set()
for cnt in range(1, 201):
flag = 1
for i in range(m):
if (k[i] - 1) // cnt != f[i] - 1:
flag = 0
break
if flag:
vars.add((n - 1) // cnt + 1)
if n == 1:
ans = 1
else:
ans = -1 if len(vars) > 1 else max(vars)
print(ans)
```
Yes
| 100,007 | [
0.54248046875,
0.2529296875,
-0.1783447265625,
0.0933837890625,
-0.63818359375,
-0.3056640625,
-0.4736328125,
0.261962890625,
0.33447265625,
0.6259765625,
0.89501953125,
-0.0787353515625,
-0.10980224609375,
-0.6767578125,
-0.44482421875,
0.08648681640625,
-0.669921875,
-0.318359375... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In a building where Polycarp lives there are equal number of flats on each floor. Unfortunately, Polycarp don't remember how many flats are on each floor, but he remembers that the flats are numbered from 1 from lower to upper floors. That is, the first several flats are on the first floor, the next several flats are on the second and so on. Polycarp don't remember the total number of flats in the building, so you can consider the building to be infinitely high (i.e. there are infinitely many floors). Note that the floors are numbered from 1.
Polycarp remembers on which floors several flats are located. It is guaranteed that this information is not self-contradictory. It means that there exists a building with equal number of flats on each floor so that the flats from Polycarp's memory have the floors Polycarp remembers.
Given this information, is it possible to restore the exact floor for flat n?
Input
The first line contains two integers n and m (1 ≤ n ≤ 100, 0 ≤ m ≤ 100), where n is the number of the flat you need to restore floor for, and m is the number of flats in Polycarp's memory.
m lines follow, describing the Polycarp's memory: each of these lines contains a pair of integers ki, fi (1 ≤ ki ≤ 100, 1 ≤ fi ≤ 100), which means that the flat ki is on the fi-th floor. All values ki are distinct.
It is guaranteed that the given information is not self-contradictory.
Output
Print the number of the floor in which the n-th flat is located, if it is possible to determine it in a unique way. Print -1 if it is not possible to uniquely restore this floor.
Examples
Input
10 3
6 2
2 1
7 3
Output
4
Input
8 4
3 1
6 2
5 2
2 1
Output
-1
Note
In the first example the 6-th flat is on the 2-nd floor, while the 7-th flat is on the 3-rd, so, the 6-th flat is the last on its floor and there are 3 flats on each floor. Thus, the 10-th flat is on the 4-th floor.
In the second example there can be 3 or 4 flats on each floor, so we can't restore the floor for the 8-th flat.
Submitted Solution:
```
n, m = map(int, input().split())
ans = -1
k = []
f = []
for i in range(m):
flat, level = map(int, input().split())
k.append(flat)
f.append(level)
mainflag = True
for count in range(1, 101):
flag = True
for i in range(m):
if (k[i] + count - 1) // count != f[i]:
flag = False
break
if flag and ans != -1 and (n + count - 1) // count != (n + ans - 1) // ans:
mainflag = False
elif flag:
ans = count
if mainflag:
print((n + ans - 1) // ans)
else:
print(-1)
```
Yes
| 100,008 | [
0.54248046875,
0.2529296875,
-0.1783447265625,
0.0933837890625,
-0.63818359375,
-0.3056640625,
-0.4736328125,
0.261962890625,
0.33447265625,
0.6259765625,
0.89501953125,
-0.0787353515625,
-0.10980224609375,
-0.6767578125,
-0.44482421875,
0.08648681640625,
-0.669921875,
-0.318359375... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In a building where Polycarp lives there are equal number of flats on each floor. Unfortunately, Polycarp don't remember how many flats are on each floor, but he remembers that the flats are numbered from 1 from lower to upper floors. That is, the first several flats are on the first floor, the next several flats are on the second and so on. Polycarp don't remember the total number of flats in the building, so you can consider the building to be infinitely high (i.e. there are infinitely many floors). Note that the floors are numbered from 1.
Polycarp remembers on which floors several flats are located. It is guaranteed that this information is not self-contradictory. It means that there exists a building with equal number of flats on each floor so that the flats from Polycarp's memory have the floors Polycarp remembers.
Given this information, is it possible to restore the exact floor for flat n?
Input
The first line contains two integers n and m (1 ≤ n ≤ 100, 0 ≤ m ≤ 100), where n is the number of the flat you need to restore floor for, and m is the number of flats in Polycarp's memory.
m lines follow, describing the Polycarp's memory: each of these lines contains a pair of integers ki, fi (1 ≤ ki ≤ 100, 1 ≤ fi ≤ 100), which means that the flat ki is on the fi-th floor. All values ki are distinct.
It is guaranteed that the given information is not self-contradictory.
Output
Print the number of the floor in which the n-th flat is located, if it is possible to determine it in a unique way. Print -1 if it is not possible to uniquely restore this floor.
Examples
Input
10 3
6 2
2 1
7 3
Output
4
Input
8 4
3 1
6 2
5 2
2 1
Output
-1
Note
In the first example the 6-th flat is on the 2-nd floor, while the 7-th flat is on the 3-rd, so, the 6-th flat is the last on its floor and there are 3 flats on each floor. Thus, the 10-th flat is on the 4-th floor.
In the second example there can be 3 or 4 flats on each floor, so we can't restore the floor for the 8-th flat.
Submitted Solution:
```
n, m = map(int, input().split())
a = []
for i in range(m):
k, f = map(int, input().split())
a.append((k, f))
cnt = 0
num = 0
for e in range(1, 101):
can = True
for k, f in a:
if f != (k + e - 1) // e:
can = False
break
if can:
cnt += 1
num = e
if cnt == 1:
print((n + num - 1) // num)
else:
print(-1)
```
No
| 100,009 | [
0.54248046875,
0.2529296875,
-0.1783447265625,
0.0933837890625,
-0.63818359375,
-0.3056640625,
-0.4736328125,
0.261962890625,
0.33447265625,
0.6259765625,
0.89501953125,
-0.0787353515625,
-0.10980224609375,
-0.6767578125,
-0.44482421875,
0.08648681640625,
-0.669921875,
-0.318359375... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In a building where Polycarp lives there are equal number of flats on each floor. Unfortunately, Polycarp don't remember how many flats are on each floor, but he remembers that the flats are numbered from 1 from lower to upper floors. That is, the first several flats are on the first floor, the next several flats are on the second and so on. Polycarp don't remember the total number of flats in the building, so you can consider the building to be infinitely high (i.e. there are infinitely many floors). Note that the floors are numbered from 1.
Polycarp remembers on which floors several flats are located. It is guaranteed that this information is not self-contradictory. It means that there exists a building with equal number of flats on each floor so that the flats from Polycarp's memory have the floors Polycarp remembers.
Given this information, is it possible to restore the exact floor for flat n?
Input
The first line contains two integers n and m (1 ≤ n ≤ 100, 0 ≤ m ≤ 100), where n is the number of the flat you need to restore floor for, and m is the number of flats in Polycarp's memory.
m lines follow, describing the Polycarp's memory: each of these lines contains a pair of integers ki, fi (1 ≤ ki ≤ 100, 1 ≤ fi ≤ 100), which means that the flat ki is on the fi-th floor. All values ki are distinct.
It is guaranteed that the given information is not self-contradictory.
Output
Print the number of the floor in which the n-th flat is located, if it is possible to determine it in a unique way. Print -1 if it is not possible to uniquely restore this floor.
Examples
Input
10 3
6 2
2 1
7 3
Output
4
Input
8 4
3 1
6 2
5 2
2 1
Output
-1
Note
In the first example the 6-th flat is on the 2-nd floor, while the 7-th flat is on the 3-rd, so, the 6-th flat is the last on its floor and there are 3 flats on each floor. Thus, the 10-th flat is on the 4-th floor.
In the second example there can be 3 or 4 flats on each floor, so we can't restore the floor for the 8-th flat.
Submitted Solution:
```
n, m = map(int, input().split())
k, f = map(int, input().split())
omin=(k-1)//f+1
omax = -1
if f > 1:
omax=(k-1)//(f-1)
for i in range(m-1):
k, f = map(int, input().split())
localmin = (k-1) // f + 1
if f > 1:
localmax = (k-1) // (f - 1)
else:
localmax = -1
omin = max(localmin, omin)
if localmax != -1 and (localmax < omax or omax == -1):
omax = localmax
if omax == omin:
print((n - 1) // omin + 1)
elif omax == -1:
print(1)
else:
print(-1)
```
No
| 100,010 | [
0.54248046875,
0.2529296875,
-0.1783447265625,
0.0933837890625,
-0.63818359375,
-0.3056640625,
-0.4736328125,
0.261962890625,
0.33447265625,
0.6259765625,
0.89501953125,
-0.0787353515625,
-0.10980224609375,
-0.6767578125,
-0.44482421875,
0.08648681640625,
-0.669921875,
-0.318359375... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In a building where Polycarp lives there are equal number of flats on each floor. Unfortunately, Polycarp don't remember how many flats are on each floor, but he remembers that the flats are numbered from 1 from lower to upper floors. That is, the first several flats are on the first floor, the next several flats are on the second and so on. Polycarp don't remember the total number of flats in the building, so you can consider the building to be infinitely high (i.e. there are infinitely many floors). Note that the floors are numbered from 1.
Polycarp remembers on which floors several flats are located. It is guaranteed that this information is not self-contradictory. It means that there exists a building with equal number of flats on each floor so that the flats from Polycarp's memory have the floors Polycarp remembers.
Given this information, is it possible to restore the exact floor for flat n?
Input
The first line contains two integers n and m (1 ≤ n ≤ 100, 0 ≤ m ≤ 100), where n is the number of the flat you need to restore floor for, and m is the number of flats in Polycarp's memory.
m lines follow, describing the Polycarp's memory: each of these lines contains a pair of integers ki, fi (1 ≤ ki ≤ 100, 1 ≤ fi ≤ 100), which means that the flat ki is on the fi-th floor. All values ki are distinct.
It is guaranteed that the given information is not self-contradictory.
Output
Print the number of the floor in which the n-th flat is located, if it is possible to determine it in a unique way. Print -1 if it is not possible to uniquely restore this floor.
Examples
Input
10 3
6 2
2 1
7 3
Output
4
Input
8 4
3 1
6 2
5 2
2 1
Output
-1
Note
In the first example the 6-th flat is on the 2-nd floor, while the 7-th flat is on the 3-rd, so, the 6-th flat is the last on its floor and there are 3 flats on each floor. Thus, the 10-th flat is on the 4-th floor.
In the second example there can be 3 or 4 flats on each floor, so we can't restore the floor for the 8-th flat.
Submitted Solution:
```
from sys import stdout
from sys import stdin
def get():
return stdin.readline().strip()
def getf():
return [int(i) for i in get().split()]
def put(a, end = "\n"):
stdout.write(str(a) + end)
def putf(a, sep = " ", end = "\n"):
stdout.write(sep.join(map(str, a)) + end)
from math import ceil
def main():
n, m = getf()
fl = [[] for i in range(101)]
for i in range(m):
k, f = getf()
fl[f] += [k]
ans = -1
fl1 = -1
for i in range(1, 101):
if(min(fl[i] or [-1]) <= n <= max(fl[i] or [-1])):
ans = i
for i in range(1, 100):
f1, f2 = fl[i], fl[i + 1]
if not(f1 and f2):
continue
k1, k2 = max(f1), min(f2)
if(k2 - k1 == 1):
fl1 = k1 // i
if(ans == -1):
if(fl1 != -1):
put(int(ceil(n / fl1)))
else:
put(-1)
else:
put(ans)
main()
```
No
| 100,011 | [
0.54248046875,
0.2529296875,
-0.1783447265625,
0.0933837890625,
-0.63818359375,
-0.3056640625,
-0.4736328125,
0.261962890625,
0.33447265625,
0.6259765625,
0.89501953125,
-0.0787353515625,
-0.10980224609375,
-0.6767578125,
-0.44482421875,
0.08648681640625,
-0.669921875,
-0.318359375... | 24 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In a building where Polycarp lives there are equal number of flats on each floor. Unfortunately, Polycarp don't remember how many flats are on each floor, but he remembers that the flats are numbered from 1 from lower to upper floors. That is, the first several flats are on the first floor, the next several flats are on the second and so on. Polycarp don't remember the total number of flats in the building, so you can consider the building to be infinitely high (i.e. there are infinitely many floors). Note that the floors are numbered from 1.
Polycarp remembers on which floors several flats are located. It is guaranteed that this information is not self-contradictory. It means that there exists a building with equal number of flats on each floor so that the flats from Polycarp's memory have the floors Polycarp remembers.
Given this information, is it possible to restore the exact floor for flat n?
Input
The first line contains two integers n and m (1 ≤ n ≤ 100, 0 ≤ m ≤ 100), where n is the number of the flat you need to restore floor for, and m is the number of flats in Polycarp's memory.
m lines follow, describing the Polycarp's memory: each of these lines contains a pair of integers ki, fi (1 ≤ ki ≤ 100, 1 ≤ fi ≤ 100), which means that the flat ki is on the fi-th floor. All values ki are distinct.
It is guaranteed that the given information is not self-contradictory.
Output
Print the number of the floor in which the n-th flat is located, if it is possible to determine it in a unique way. Print -1 if it is not possible to uniquely restore this floor.
Examples
Input
10 3
6 2
2 1
7 3
Output
4
Input
8 4
3 1
6 2
5 2
2 1
Output
-1
Note
In the first example the 6-th flat is on the 2-nd floor, while the 7-th flat is on the 3-rd, so, the 6-th flat is the last on its floor and there are 3 flats on each floor. Thus, the 10-th flat is on the 4-th floor.
In the second example there can be 3 or 4 flats on each floor, so we can't restore the floor for the 8-th flat.
Submitted Solution:
```
from math import ceil
def check(flats_on_level):
for fl in flats:
after = ceil(fl[0] / flats_on_level)
if fl[1] != after:
return False
return True
n, m = map(int, input().split())
flats = []
for _ in range(m):
ki, fi = map(int, input().split())
flats.append((ki, fi))
answer = -1
cf = -1
if m == 0 and n == 1:
print(1)
exit(0)
for i in range(1, 101):
if check(i):
if answer == -1:
answer = i
else:
cf == i
if ceil(n / answer) != ceil(n / cf):
print(-1)
else:
print(ceil(n / answer))
```
No
| 100,012 | [
0.54248046875,
0.2529296875,
-0.1783447265625,
0.0933837890625,
-0.63818359375,
-0.3056640625,
-0.4736328125,
0.261962890625,
0.33447265625,
0.6259765625,
0.89501953125,
-0.0787353515625,
-0.10980224609375,
-0.6767578125,
-0.44482421875,
0.08648681640625,
-0.669921875,
-0.318359375... | 24 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.