message
stringlengths 2
39.6k
| message_type
stringclasses 2
values | message_id
int64 0
1
| conversation_id
int64 219
108k
| cluster
float64 11
11
| __index_level_0__
int64 438
217k
|
|---|---|---|---|---|---|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
During the "Russian Code Cup" programming competition, the testing system stores all sent solutions for each participant. We know that many participants use random numbers in their programs and are often sent several solutions with the same source code to check.
Each participant is identified by some unique positive integer k, and each sent solution A is characterized by two numbers: x — the number of different solutions that are sent before the first solution identical to A, and k — the number of the participant, who is the author of the solution. Consequently, all identical solutions have the same x.
It is known that the data in the testing system are stored in the chronological order, that is, if the testing system has a solution with number x (x > 0) of the participant with number k, then the testing system has a solution with number x - 1 of the same participant stored somewhere before.
During the competition the checking system crashed, but then the data of the submissions of all participants have been restored. Now the jury wants to verify that the recovered data is in chronological order. Help the jury to do so.
Input
The first line of the input contains an integer n (1 ≤ n ≤ 105) — the number of solutions. Each of the following n lines contains two integers separated by space x and k (0 ≤ x ≤ 105; 1 ≤ k ≤ 105) — the number of previous unique solutions and the identifier of the participant.
Output
A single line of the output should contain «YES» if the data is in chronological order, and «NO» otherwise.
Examples
Input
2
0 1
1 1
Output
YES
Input
4
0 1
1 2
1 1
0 2
Output
NO
Input
4
0 1
1 1
0 1
0 2
Output
YES
Submitted Solution:
```
import sys
from collections import defaultdict
n = int(sys.stdin.readline())
d = defaultdict(lambda:-1)
for i in range(0, n):
x, k = map(int, sys.stdin.readline().split())
z = d[k]
if x == z + 1:
d[k] = x
else:
print('NO')
sys.exit(0)
print('YES')
```
|
instruction
| 0
| 103,237
| 11
| 206,474
|
No
|
output
| 1
| 103,237
| 11
| 206,475
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
During the "Russian Code Cup" programming competition, the testing system stores all sent solutions for each participant. We know that many participants use random numbers in their programs and are often sent several solutions with the same source code to check.
Each participant is identified by some unique positive integer k, and each sent solution A is characterized by two numbers: x — the number of different solutions that are sent before the first solution identical to A, and k — the number of the participant, who is the author of the solution. Consequently, all identical solutions have the same x.
It is known that the data in the testing system are stored in the chronological order, that is, if the testing system has a solution with number x (x > 0) of the participant with number k, then the testing system has a solution with number x - 1 of the same participant stored somewhere before.
During the competition the checking system crashed, but then the data of the submissions of all participants have been restored. Now the jury wants to verify that the recovered data is in chronological order. Help the jury to do so.
Input
The first line of the input contains an integer n (1 ≤ n ≤ 105) — the number of solutions. Each of the following n lines contains two integers separated by space x and k (0 ≤ x ≤ 105; 1 ≤ k ≤ 105) — the number of previous unique solutions and the identifier of the participant.
Output
A single line of the output should contain «YES» if the data is in chronological order, and «NO» otherwise.
Examples
Input
2
0 1
1 1
Output
YES
Input
4
0 1
1 2
1 1
0 2
Output
NO
Input
4
0 1
1 1
0 1
0 2
Output
YES
Submitted Solution:
```
from collections import OrderedDict
all = {}
n = int(input())
ans = True
for i in range(n):
x_k = input().split()
x = int(x_k[0])
k = int(x_k[1])
if k not in all:
all[k] = x
# print("new", k, all[k])
elif all[k] > x:
continue
elif all[k]+1 != x:
ans = False
break
# print("old", k, all[k])
if ans:
print("YES")
else:
print("NO")
```
|
instruction
| 0
| 103,238
| 11
| 206,476
|
No
|
output
| 1
| 103,238
| 11
| 206,477
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Codeforces is a wonderful platform and one its feature shows how much someone contributes to the community. Every registered user has contribution — an integer number, not necessarily positive. There are n registered users and the i-th of them has contribution ti.
Limak is a little polar bear and he's new into competitive programming. He doesn't even have an account in Codeforces but he is able to upvote existing blogs and comments. We assume that every registered user has infinitely many blogs and comments.
* Limak can spend b minutes to read one blog and upvote it. Author's contribution will be increased by 5.
* Limak can spend c minutes to read one comment and upvote it. Author's contribution will be increased by 1.
Note that it's possible that Limak reads blogs faster than comments.
Limak likes ties. He thinks it would be awesome to see a tie between at least k registered users. To make it happen he is going to spend some time on reading and upvoting. After that, there should exist an integer value x that at least k registered users have contribution exactly x.
How much time does Limak need to achieve his goal?
Input
The first line contains four integers n, k, b and c (2 ≤ k ≤ n ≤ 200 000, 1 ≤ b, c ≤ 1000) — the number of registered users, the required minimum number of users with the same contribution, time needed to read and upvote a blog, and time needed to read and upvote a comment, respectively.
The second line contains n integers t1, t2, ..., tn (|ti| ≤ 109) where ti denotes contribution of the i-th registered user.
Output
Print the minimum number of minutes Limak will spend to get a tie between at least k registered users.
Examples
Input
4 3 100 30
12 2 6 1
Output
220
Input
4 3 30 100
12 2 6 1
Output
190
Input
6 2 987 789
-8 42 -4 -65 -8 -8
Output
0
Note
In the first sample, there are 4 registered users and Limak wants a tie between at least 3 of them. Limak should behave as follows.
* He spends 100 minutes to read one blog of the 4-th user and increase his contribution from 1 to 6.
* Then he spends 4·30 = 120 minutes to read four comments of the 2-nd user and increase his contribution from 2 to 6 (four times it was increaded by 1).
In the given scenario, Limak spends 100 + 4·30 = 220 minutes and after that each of users 2, 3, 4 has contribution 6.
In the second sample, Limak needs 30 minutes to read a blog and 100 minutes to read a comment. This time he can get 3 users with contribution equal to 12 by spending 100 + 3·30 = 190 minutes:
* Spend 2·30 = 60 minutes to read two blogs of the 1-st user to increase his contribution from 2 to 12.
* Spend 30 + 100 minutes to read one blog and one comment of the 3-rd user. His contribution will change from 6 to 6 + 5 + 1 = 12.
Submitted Solution:
```
def main():
def ta(k_g):
tim = 0
while k_g >= 5:
if preferred_c:
tim += c * 5
else:
tim += b
k_g -= 5
while k_g >= 1:
tim += c
k_g -= 1
return tim
line = input().split()
n = int(line[0]) # кол-во зарег пользователей
k = int(line[1]) # мин кол-во группы один. по вкладу
b = int(line[2]) # время блога
c = int(line[3]) # время комента
line = input().split()
t = [] # вклад пользователя ti
for _ in range(len(line)):
t.append(int(line[_]))
t.sort()
# check the most efficient thing
preferred_c = False # min, points
if c * 5 < b:
preferred_c = True
t_min = 10000000000
for ti in range(len(t) - k + 1):
t_temp = 0
for _ in range(k):
k_temp = abs(t[ti + k - 1] - t[ti + _])
t_temp += ta(k_temp)
if t_temp < t_min:
t_min = t_temp
print(t_min)
main()
```
|
instruction
| 0
| 103,326
| 11
| 206,652
|
No
|
output
| 1
| 103,326
| 11
| 206,653
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Codeforces is a wonderful platform and one its feature shows how much someone contributes to the community. Every registered user has contribution — an integer number, not necessarily positive. There are n registered users and the i-th of them has contribution ti.
Limak is a little polar bear and he's new into competitive programming. He doesn't even have an account in Codeforces but he is able to upvote existing blogs and comments. We assume that every registered user has infinitely many blogs and comments.
* Limak can spend b minutes to read one blog and upvote it. Author's contribution will be increased by 5.
* Limak can spend c minutes to read one comment and upvote it. Author's contribution will be increased by 1.
Note that it's possible that Limak reads blogs faster than comments.
Limak likes ties. He thinks it would be awesome to see a tie between at least k registered users. To make it happen he is going to spend some time on reading and upvoting. After that, there should exist an integer value x that at least k registered users have contribution exactly x.
How much time does Limak need to achieve his goal?
Input
The first line contains four integers n, k, b and c (2 ≤ k ≤ n ≤ 200 000, 1 ≤ b, c ≤ 1000) — the number of registered users, the required minimum number of users with the same contribution, time needed to read and upvote a blog, and time needed to read and upvote a comment, respectively.
The second line contains n integers t1, t2, ..., tn (|ti| ≤ 109) where ti denotes contribution of the i-th registered user.
Output
Print the minimum number of minutes Limak will spend to get a tie between at least k registered users.
Examples
Input
4 3 100 30
12 2 6 1
Output
220
Input
4 3 30 100
12 2 6 1
Output
190
Input
6 2 987 789
-8 42 -4 -65 -8 -8
Output
0
Note
In the first sample, there are 4 registered users and Limak wants a tie between at least 3 of them. Limak should behave as follows.
* He spends 100 minutes to read one blog of the 4-th user and increase his contribution from 1 to 6.
* Then he spends 4·30 = 120 minutes to read four comments of the 2-nd user and increase his contribution from 2 to 6 (four times it was increaded by 1).
In the given scenario, Limak spends 100 + 4·30 = 220 minutes and after that each of users 2, 3, 4 has contribution 6.
In the second sample, Limak needs 30 minutes to read a blog and 100 minutes to read a comment. This time he can get 3 users with contribution equal to 12 by spending 100 + 3·30 = 190 minutes:
* Spend 2·30 = 60 minutes to read two blogs of the 1-st user to increase his contribution from 2 to 12.
* Spend 30 + 100 minutes to read one blog and one comment of the 3-rd user. His contribution will change from 6 to 6 + 5 + 1 = 12.
Submitted Solution:
```
def main():
def ta(k_g):
tim = 0
while k_g >= 5:
if preferred_c:
tim += c * 5
else:
tim += b
k_g -= 5
while k_g >= 1:
tim += c
k_g -= 1
return tim
line = input().split()
n = int(line[0]) # кол-во зарег пользователей
k = int(line[1]) # мин кол-во группы один. по вкладу
b = int(line[2]) # время блога
c = int(line[3]) # время комента
line = input().split()
t = [] # вклад пользователя ti
for _ in range(n):
t.append(int(line[_]))
t.sort()
# check the most efficient thing
preferred_c = False # min, points
if c * 5 < b:
preferred_c = True
t_min = 10000000000
for ti in range(len(t) - k + 1):
for tj in range(ti, len(t) - k + 1):
if tj > ti:
break
t_temp = 0
for _ in range(k):
k_temp = abs(t[ti + k - 1] - t[ti + _])
t_temp += ta(k_temp)
if t_temp < t_min:
t_min = t_temp
print(t_min)
main()
```
|
instruction
| 0
| 103,327
| 11
| 206,654
|
No
|
output
| 1
| 103,327
| 11
| 206,655
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Let us define the FizzBuzz sequence a_1,a_2,... as follows:
* If both 3 and 5 divides i, a_i=\mbox{FizzBuzz}.
* If the above does not hold but 3 divides i, a_i=\mbox{Fizz}.
* If none of the above holds but 5 divides i, a_i=\mbox{Buzz}.
* If none of the above holds, a_i=i.
Find the sum of all numbers among the first N terms of the FizzBuzz sequence.
Constraints
* 1 \leq N \leq 10^6
Input
Input is given from Standard Input in the following format:
N
Output
Print the sum of all numbers among the first N terms of the FizzBuzz sequence.
Examples
Input
15
Output
60
Input
1000000
Output
266666333332
Submitted Solution:
```
n = int(input())
fb = 0
for i in range(n):
if(i%5 != 0 and i%3 != 0):
fb = fb + i
print(fb)
```
|
instruction
| 0
| 103,458
| 11
| 206,916
|
No
|
output
| 1
| 103,458
| 11
| 206,917
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You have N items and a bag of strength W. The i-th item has a weight of w_i and a value of v_i.
You will select some of the items and put them in the bag. Here, the total weight of the selected items needs to be at most W.
Your objective is to maximize the total value of the selected items.
Constraints
* 1 ≤ N ≤ 100
* 1 ≤ W ≤ 10^9
* 1 ≤ w_i ≤ 10^9
* For each i = 2,3,...,N, w_1 ≤ w_i ≤ w_1 + 3.
* 1 ≤ v_i ≤ 10^7
* W, each w_i and v_i are integers.
Input
Input is given from Standard Input in the following format:
N W
w_1 v_1
w_2 v_2
:
w_N v_N
Output
Print the maximum possible total value of the selected items.
Examples
Input
4 6
2 1
3 4
4 10
3 4
Output
11
Input
4 6
2 1
3 7
4 10
3 6
Output
13
Input
4 10
1 100
1 100
1 100
1 100
Output
400
Input
4 1
10 100
10 100
10 100
10 100
Output
0
Submitted Solution:
```
N,W = map(int,input().split())
dic = {"0":[],"1":[],"2":[],"3":[]}
for i in range(N):
w,v = map(int,input().split())
if i == 0:
Min = w
if w == Min:
dic["0"].append(v)
elif w == Min+1:
dic["1"].append(v)
elif w == Min+2:
dic["2"].append(v)
elif w == Min+3:
dic["3"].append(v)
dic["0"].sort(reverse=True)
dic["1"].sort(reverse=True)
dic["2"].sort(reverse=True)
dic["3"].sort(reverse=True)
ans = 0
for i in range(len(dic["0"])+1):
for j in range(len(dic["1"])+1):
for k in range(len(dic["2"])+1):
for l in range(len(dic["3"])+1):
a = int(sum(dic["0"][:i])+sum(dic["1"][:j])+sum(dic["2"][:k])+sum(dic["3"][:l]))
b = int(i*Min+j*(Min+1)+k*(Min+2)+l*(Min+3))
if a > ans and b <= W:
ans = a
print(int(ans))
```
|
instruction
| 0
| 103,551
| 11
| 207,102
|
Yes
|
output
| 1
| 103,551
| 11
| 207,103
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You have N items and a bag of strength W. The i-th item has a weight of w_i and a value of v_i.
You will select some of the items and put them in the bag. Here, the total weight of the selected items needs to be at most W.
Your objective is to maximize the total value of the selected items.
Constraints
* 1 ≤ N ≤ 100
* 1 ≤ W ≤ 10^9
* 1 ≤ w_i ≤ 10^9
* For each i = 2,3,...,N, w_1 ≤ w_i ≤ w_1 + 3.
* 1 ≤ v_i ≤ 10^7
* W, each w_i and v_i are integers.
Input
Input is given from Standard Input in the following format:
N W
w_1 v_1
w_2 v_2
:
w_N v_N
Output
Print the maximum possible total value of the selected items.
Examples
Input
4 6
2 1
3 4
4 10
3 4
Output
11
Input
4 6
2 1
3 7
4 10
3 6
Output
13
Input
4 10
1 100
1 100
1 100
1 100
Output
400
Input
4 1
10 100
10 100
10 100
10 100
Output
0
Submitted Solution:
```
# -*- coding: utf-8 -*-
import sys
from itertools import accumulate
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N,W = map(int,readline().split())
A1 = []
A2 = []
A3 = []
A4 = []
w1,v1 = map(int,readline().split())
A1.append(v1)
for _ in range(N-1):
w,v = map(int,readline().split())
if w == w1:
A1.append(v)
elif w == w1+1:
A2.append(v)
elif w == w1+2:
A3.append(v)
else:
A4.append(v)
S1 = list(accumulate(sorted(A1,reverse = True)))
S2 = list(accumulate(sorted(A2,reverse = True)))
S3 = list(accumulate(sorted(A3,reverse = True)))
S4 = list(accumulate(sorted(A4,reverse = True)))
S1 = [0] + S1
S2 = [0] + S2
S3 = [0] + S3
S4 = [0] + S4
ans = 0
for a in range(len(S1)):
for b in range(len(S2)):
for c in range(len(S3)):
for d in range(len(S4)):
tmp = w1*(a+b+c+d)+b+2*c+3*d
total = S1[a]+S2[b]+S3[c]+S4[d]
if tmp <= W:
ans = max(ans,total)
print(ans)
```
|
instruction
| 0
| 103,552
| 11
| 207,104
|
Yes
|
output
| 1
| 103,552
| 11
| 207,105
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You have N items and a bag of strength W. The i-th item has a weight of w_i and a value of v_i.
You will select some of the items and put them in the bag. Here, the total weight of the selected items needs to be at most W.
Your objective is to maximize the total value of the selected items.
Constraints
* 1 ≤ N ≤ 100
* 1 ≤ W ≤ 10^9
* 1 ≤ w_i ≤ 10^9
* For each i = 2,3,...,N, w_1 ≤ w_i ≤ w_1 + 3.
* 1 ≤ v_i ≤ 10^7
* W, each w_i and v_i are integers.
Input
Input is given from Standard Input in the following format:
N W
w_1 v_1
w_2 v_2
:
w_N v_N
Output
Print the maximum possible total value of the selected items.
Examples
Input
4 6
2 1
3 4
4 10
3 4
Output
11
Input
4 6
2 1
3 7
4 10
3 6
Output
13
Input
4 10
1 100
1 100
1 100
1 100
Output
400
Input
4 1
10 100
10 100
10 100
10 100
Output
0
Submitted Solution:
```
N, W = map(int, input().split())
WV = [tuple(map(int, input().split())) for _ in range(N)]
R = 3 * N + 10
INF = 10**18
w0 = WV[0][0]
dp = [[-INF] * R for _ in range(N + 1)]
dp[0][0] = 0
for w, v in WV:
k = w - w0
for n in range(N)[::-1]:
for r in range(R)[::-1]:
if r + k < R and dp[n + 1][r + k] < dp[n][r] + v:
dp[n + 1][r + k] = dp[n][r] + v
ans = 0
for n in range(N + 1):
for r in range(R):
w = n * w0 + r
if w <= W and dp[n][r] > ans:
ans = dp[n][r]
print(ans)
```
|
instruction
| 0
| 103,553
| 11
| 207,106
|
Yes
|
output
| 1
| 103,553
| 11
| 207,107
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You have N items and a bag of strength W. The i-th item has a weight of w_i and a value of v_i.
You will select some of the items and put them in the bag. Here, the total weight of the selected items needs to be at most W.
Your objective is to maximize the total value of the selected items.
Constraints
* 1 ≤ N ≤ 100
* 1 ≤ W ≤ 10^9
* 1 ≤ w_i ≤ 10^9
* For each i = 2,3,...,N, w_1 ≤ w_i ≤ w_1 + 3.
* 1 ≤ v_i ≤ 10^7
* W, each w_i and v_i are integers.
Input
Input is given from Standard Input in the following format:
N W
w_1 v_1
w_2 v_2
:
w_N v_N
Output
Print the maximum possible total value of the selected items.
Examples
Input
4 6
2 1
3 4
4 10
3 4
Output
11
Input
4 6
2 1
3 7
4 10
3 6
Output
13
Input
4 10
1 100
1 100
1 100
1 100
Output
400
Input
4 1
10 100
10 100
10 100
10 100
Output
0
Submitted Solution:
```
INFTY = 10**10
N,W = map(int,input().split())
X = [list(map(int,input().split())) for _ in range(N)]
dp = [[[-INFTY for _ in range(301)] for _ in range(N+1)] for _ in range(N+1)]
for i in range(N+1):
dp[i][0][0] = 0
for i in range(1,N+1):
for j in range(1,i+1):
for k in range(301):
dp[i][j][k] = dp[i-1][j][k]
if k>=X[i-1][0]-X[0][0]:
dp[i][j][k] = max(dp[i][j][k],dp[i-1][j-1][k-X[i-1][0]+X[0][0]]+X[i-1][1])
cmax = 0
for j in range(1,N+1):
for k in range(W-j*X[0][0]+1):
cmax = max(cmax,dp[N][j][k])
print(cmax)
```
|
instruction
| 0
| 103,555
| 11
| 207,110
|
No
|
output
| 1
| 103,555
| 11
| 207,111
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You have N items and a bag of strength W. The i-th item has a weight of w_i and a value of v_i.
You will select some of the items and put them in the bag. Here, the total weight of the selected items needs to be at most W.
Your objective is to maximize the total value of the selected items.
Constraints
* 1 ≤ N ≤ 100
* 1 ≤ W ≤ 10^9
* 1 ≤ w_i ≤ 10^9
* For each i = 2,3,...,N, w_1 ≤ w_i ≤ w_1 + 3.
* 1 ≤ v_i ≤ 10^7
* W, each w_i and v_i are integers.
Input
Input is given from Standard Input in the following format:
N W
w_1 v_1
w_2 v_2
:
w_N v_N
Output
Print the maximum possible total value of the selected items.
Examples
Input
4 6
2 1
3 4
4 10
3 4
Output
11
Input
4 6
2 1
3 7
4 10
3 6
Output
13
Input
4 10
1 100
1 100
1 100
1 100
Output
400
Input
4 1
10 100
10 100
10 100
10 100
Output
0
Submitted Solution:
```
n, W = map(int, input().split())
dp = [[[0] * 301 for _ in range(n + 1)] for _ in range(n + 1)]
li = [list(map(int, input().split())) for _ in range(n)]
p = li[0][0]
for i, x in enumerate(li):
w, v = x
w -= p
for j in range(i + 1):
for k in range(301):
if k >= w:
if dp[i][j][k - w] + v > dp[i][j][k] and j + 1 <= 300:
dp[i + 1][j + 1][k] = max(dp[i + 1][j + 1][k],
dp[i][j][k - w] + v)
else:
dp[i + 1][j][k] = max(dp[i + 1][j][k], dp[i][j][k])
else:
dp[i + 1][j][k] = max(dp[i + 1][j][k], dp[i][j][k])
ans = 0
for i in range(n + 1):
for k in range(301):
if i * p + k <= W:
ans = max(dp[n][i][k], ans)
print(ans)
```
|
instruction
| 0
| 103,556
| 11
| 207,112
|
No
|
output
| 1
| 103,556
| 11
| 207,113
|
Provide a correct Python 3 solution for this coding contest problem.
There are N persons, conveniently numbered 1 through N. They will take 3y3s Challenge for N-1 seconds.
During the challenge, each person must look at each of the N-1 other persons for 1 seconds, in some order.
If any two persons look at each other during the challenge, the challenge ends in failure.
Find the order in which each person looks at each of the N-1 other persons, to be successful in the challenge.
Constraints
* 2 \leq N \leq 100
Input
The input is given from Standard Input in the following format:
N
Output
If there exists no way to be successful in the challenge, print `-1`.
If there exists a way to be successful in the challenge, print any such way in the following format:
A_{1,1} A_{1,2} ... A_{1, N-1}
A_{2,1} A_{2,2} ... A_{2, N-1}
:
A_{N,1} A_{N,2} ... A_{N, N-1}
where A_{i, j} is the index of the person that the person numbered i looks at during the j-th second.
Judging
The output is considered correct only if all of the following conditions are satisfied:
* 1 \leq A_{i,j} \leq N
* For each i, A_{i,1}, A_{i,2}, ... , A_{i, N-1} are pairwise distinct.
* Let X = A_{i, j}, then A_{X, j} \neq i always holds.
Examples
Input
7
Output
2 3 4 5 6 7
5 3 1 6 4 7
2 7 4 1 5 6
2 1 7 5 3 6
1 4 3 7 6 2
2 5 7 3 4 1
2 6 1 4 5 3
Input
2
Output
-1
|
instruction
| 0
| 103,561
| 11
| 207,122
|
"Correct Solution:
```
N = int(input())
if N == 2:
print(-1)
exit()
ans = [[0 for j in range(N-1)] for i in range(N)]
for i in range(N):
for j in range(N-1):
ans[i][j] = (i+j+1)%N + 1
if N%2 == 0:
m = N//2
for i in range(m,N):
ans[i][m],ans[i][m-1] = ans[i][m-1],ans[i][m]
for row in ans:
print(' '.join(map(str,row)))
```
|
output
| 1
| 103,561
| 11
| 207,123
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are N persons, conveniently numbered 1 through N. They will take 3y3s Challenge for N-1 seconds.
During the challenge, each person must look at each of the N-1 other persons for 1 seconds, in some order.
If any two persons look at each other during the challenge, the challenge ends in failure.
Find the order in which each person looks at each of the N-1 other persons, to be successful in the challenge.
Constraints
* 2 \leq N \leq 100
Input
The input is given from Standard Input in the following format:
N
Output
If there exists no way to be successful in the challenge, print `-1`.
If there exists a way to be successful in the challenge, print any such way in the following format:
A_{1,1} A_{1,2} ... A_{1, N-1}
A_{2,1} A_{2,2} ... A_{2, N-1}
:
A_{N,1} A_{N,2} ... A_{N, N-1}
where A_{i, j} is the index of the person that the person numbered i looks at during the j-th second.
Judging
The output is considered correct only if all of the following conditions are satisfied:
* 1 \leq A_{i,j} \leq N
* For each i, A_{i,1}, A_{i,2}, ... , A_{i, N-1} are pairwise distinct.
* Let X = A_{i, j}, then A_{X, j} \neq i always holds.
Examples
Input
7
Output
2 3 4 5 6 7
5 3 1 6 4 7
2 7 4 1 5 6
2 1 7 5 3 6
1 4 3 7 6 2
2 5 7 3 4 1
2 6 1 4 5 3
Input
2
Output
-1
Submitted Solution:
```
n = int(input())
if n % 2 == 0:
print(-1)
exit()
for i in range(n):
print(" ".join([str((item + i + 1) % n + 1) for item in range(n-1)]))
```
|
instruction
| 0
| 103,562
| 11
| 207,124
|
No
|
output
| 1
| 103,562
| 11
| 207,125
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are N persons, conveniently numbered 1 through N. They will take 3y3s Challenge for N-1 seconds.
During the challenge, each person must look at each of the N-1 other persons for 1 seconds, in some order.
If any two persons look at each other during the challenge, the challenge ends in failure.
Find the order in which each person looks at each of the N-1 other persons, to be successful in the challenge.
Constraints
* 2 \leq N \leq 100
Input
The input is given from Standard Input in the following format:
N
Output
If there exists no way to be successful in the challenge, print `-1`.
If there exists a way to be successful in the challenge, print any such way in the following format:
A_{1,1} A_{1,2} ... A_{1, N-1}
A_{2,1} A_{2,2} ... A_{2, N-1}
:
A_{N,1} A_{N,2} ... A_{N, N-1}
where A_{i, j} is the index of the person that the person numbered i looks at during the j-th second.
Judging
The output is considered correct only if all of the following conditions are satisfied:
* 1 \leq A_{i,j} \leq N
* For each i, A_{i,1}, A_{i,2}, ... , A_{i, N-1} are pairwise distinct.
* Let X = A_{i, j}, then A_{X, j} \neq i always holds.
Examples
Input
7
Output
2 3 4 5 6 7
5 3 1 6 4 7
2 7 4 1 5 6
2 1 7 5 3 6
1 4 3 7 6 2
2 5 7 3 4 1
2 6 1 4 5 3
Input
2
Output
-1
Submitted Solution:
```
N = int(input())
ans = [[0 for j in range(N-1)] for i in range(N)]
for i in range(N):
for j in range(N-1):
ans[i][j] = (i+j+1)%N + 1
if N%2 == 0 and N != 2:
m = N//2
for i in range(m,N):
ans[i][m],ans[i][m-1] = ans[i][m-1],ans[i][m]
elif N == 7:
ans[4][1],ans[4][2] = ans[4][2],ans[4][1]
ans[5][1],ans[5][2] = ans[5][2],ans[5][1]
for row in ans:
print(' '.join(map(str,row)))
```
|
instruction
| 0
| 103,563
| 11
| 207,126
|
No
|
output
| 1
| 103,563
| 11
| 207,127
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are N persons, conveniently numbered 1 through N. They will take 3y3s Challenge for N-1 seconds.
During the challenge, each person must look at each of the N-1 other persons for 1 seconds, in some order.
If any two persons look at each other during the challenge, the challenge ends in failure.
Find the order in which each person looks at each of the N-1 other persons, to be successful in the challenge.
Constraints
* 2 \leq N \leq 100
Input
The input is given from Standard Input in the following format:
N
Output
If there exists no way to be successful in the challenge, print `-1`.
If there exists a way to be successful in the challenge, print any such way in the following format:
A_{1,1} A_{1,2} ... A_{1, N-1}
A_{2,1} A_{2,2} ... A_{2, N-1}
:
A_{N,1} A_{N,2} ... A_{N, N-1}
where A_{i, j} is the index of the person that the person numbered i looks at during the j-th second.
Judging
The output is considered correct only if all of the following conditions are satisfied:
* 1 \leq A_{i,j} \leq N
* For each i, A_{i,1}, A_{i,2}, ... , A_{i, N-1} are pairwise distinct.
* Let X = A_{i, j}, then A_{X, j} \neq i always holds.
Examples
Input
7
Output
2 3 4 5 6 7
5 3 1 6 4 7
2 7 4 1 5 6
2 1 7 5 3 6
1 4 3 7 6 2
2 5 7 3 4 1
2 6 1 4 5 3
Input
2
Output
-1
Submitted Solution:
```
N=int(input())
if N==2:
print(-1)
elif N&1:
P=[[0]*(N-1) for i in range(N)]
for i in range(N):
for j in range(N-1):
P[i][j]=(i+j+1)%N+1
for i in range(N):
print(*P[i])
else:
P=[[0]*(N-2) for i in range(N)]
P[0].append(0)
for i in range(N-1):
P[0][i]=i+2
for i in range(N-1):
for j in range(N-2):
P[i+1][j]=P[0][(i+j+1)%(N-1)]
P[i+1].insert(i-1,1)
for i in range(N):
print(*P[i])
```
|
instruction
| 0
| 103,564
| 11
| 207,128
|
No
|
output
| 1
| 103,564
| 11
| 207,129
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are N persons, conveniently numbered 1 through N. They will take 3y3s Challenge for N-1 seconds.
During the challenge, each person must look at each of the N-1 other persons for 1 seconds, in some order.
If any two persons look at each other during the challenge, the challenge ends in failure.
Find the order in which each person looks at each of the N-1 other persons, to be successful in the challenge.
Constraints
* 2 \leq N \leq 100
Input
The input is given from Standard Input in the following format:
N
Output
If there exists no way to be successful in the challenge, print `-1`.
If there exists a way to be successful in the challenge, print any such way in the following format:
A_{1,1} A_{1,2} ... A_{1, N-1}
A_{2,1} A_{2,2} ... A_{2, N-1}
:
A_{N,1} A_{N,2} ... A_{N, N-1}
where A_{i, j} is the index of the person that the person numbered i looks at during the j-th second.
Judging
The output is considered correct only if all of the following conditions are satisfied:
* 1 \leq A_{i,j} \leq N
* For each i, A_{i,1}, A_{i,2}, ... , A_{i, N-1} are pairwise distinct.
* Let X = A_{i, j}, then A_{X, j} \neq i always holds.
Examples
Input
7
Output
2 3 4 5 6 7
5 3 1 6 4 7
2 7 4 1 5 6
2 1 7 5 3 6
1 4 3 7 6 2
2 5 7 3 4 1
2 6 1 4 5 3
Input
2
Output
-1
Submitted Solution:
```
N = int(input())
ans = [[0 for j in range(N-1)] for i in range(N)]
for i in range(N):
for j in range(N-1):
ans[i][j] = (i+j+1)%N + 1
if N%2 == 0 and N != 2:
m = N//2
for i in range(m,N):
ans[i][m],ans[i][m-1] = ans[i][m-1],ans[i][m]
for row in ans:
print(' '.join(map(str,row)))
```
|
instruction
| 0
| 103,565
| 11
| 207,130
|
No
|
output
| 1
| 103,565
| 11
| 207,131
|
Provide a correct Python 3 solution for this coding contest problem.
Example
Input
2 3 1 3 1 0
Output
2
|
instruction
| 0
| 103,626
| 11
| 207,252
|
"Correct Solution:
```
import sys
readline = sys.stdin.readline
write = sys.stdout.write
def solve():
M, N, m0, md, n0, nd = map(int, readline().split())
S = [0]*(M+1)
S[0] = mi = m0
for i in range(1, M):
S[i] = mi = (mi * 58 + md) % (N + 1)
S.sort()
for i in range(M):
S[i+1] += S[i]
T = [0]*(N+1)
T[0] = ni = n0
for i in range(1, N):
T[i] = ni = (ni * 58 + nd) % (M + 1)
T.sort()
for i in range(N):
T[i+1] += T[i]
def gen():
def calc(a, b):
return (M - a)*(N - b) + S[a] + T[b]
yield 10**18
j = N
for i in range(M+1):
while j > 0 and calc(i, j) > calc(i, j-1):
j -= 1
yield calc(i, j)
write("%d\n" % min(gen()))
solve()
```
|
output
| 1
| 103,626
| 11
| 207,253
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya is about to take his first university exam in about several minutes. And it's not just some ordinary exam, it's on mathematical analysis. Of course, right now Vasya can only think of one thing: what the result of his talk with the examiner will be...
To prepare for the exam, one has to study proofs of n theorems. It is known that there will be k examination cards on the exam and each card contains <image> distinct theorems. Besides, no theorem is mentioned in more than one card (that is, <image> theorems won't be mentioned in any card). During the exam several students may get the same card.
We do not know the exact way theorems are distributed by cards, however the students that took the exam before Vasya told him what theorems their cards contained. Vasya evaluates his level of proficiency in the i-th theorem by some number ai. The level of proficiency in some card is the average of the levels of proficiency in the theorems that are included in the card. Now Vasya wants to know the minimally and maximally possible levels of his proficiency in the card he gets on the exam. Vasya wants to determine it by the data he has collected from other students. Unfortunately, Vasya has no time left to do the math and he asked you to help him.
Input
The first line contains two integers n and k (1 ≤ k ≤ n ≤ 100) — the number of theorems and the number of cards correspondingly. The second line contains n integers ai (0 ≤ ai ≤ 100), the i-th number (1 ≤ i ≤ n) corresponds to Vasya's proficiency in the i-th theorem.
The third line contains number q (0 ≤ q ≤ 100) — the number of people that have taken the exam before Vasya. Each of the following q lines contains the description of a student's card: <image> integers from 1 to n inclusive. They are the numbers of theorems included in the card in the order in which they are enumerated in the input data. The numbers are given in an arbitrary order. It is guaranteed that the given cards are valid (that is, that all theorems in one card are different and that different people get cards that either don't contain the same theorems or coincide up to the theorems' permutation).
Output
Print two real numbers, representing Vasya's minimum and maximum proficiency in the card he will get on the exam. The absolute or relative error should not exceed 10 - 6.
Examples
Input
7 3
7 15 0 19 10 5 12
2
1 6
7 4
Output
5.0000000000 15.5000000000
Input
4 2
10 8 1 17
2
2 3
3 2
Output
4.5000000000 13.5000000000
Note
Let's analyze the first sample. Vasya's proficiency in the cards whose content he already knows equals 6 and 15.5 correspondingly. The three theorems that are left are only enough to make one exam card. If we consider all possible variants of theorems included in the card we can see that in the best case scenario Vasya gets the card that contains theorems 4 and 7 (his proficiency would equal 15.5) and in the worst case scenario he gets theorems 3 and 5 (his proficiency would equal 5).
The ⌊ x⌋ operation denotes taking integer part of real number x (rounding down).
Submitted Solution:
```
num_problems, num_cards = map(int, input().split())
card_size = num_problems // num_cards
skill = [ 0 ] + list(map(int, input().split()))
seen = (num_problems + 1) * [ False ]
num_queries = int(input())
low = 100
high = 0
for i in range(num_queries):
proficiency = 0
for pos in map(int, input().split()):
proficiency += skill[pos]
seen[pos] = True
proficiency /= card_size
low = min(low, proficiency)
high = max(high, proficiency)
remaining = []
for pos in range(1, num_problems + 1):
if not seen[pos]:
remaining.append(skill[pos])
remaining.sort()
if num_queries < num_cards:
if len(remaining) != 0:
low = min(low, sum(remaining[:card_size]) / card_size)
high = max(high, sum(remaining[-card_size:]) / card_size)
print('%.8f %.8f' % (low, high))
```
|
instruction
| 0
| 103,785
| 11
| 207,570
|
No
|
output
| 1
| 103,785
| 11
| 207,571
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya is about to take his first university exam in about several minutes. And it's not just some ordinary exam, it's on mathematical analysis. Of course, right now Vasya can only think of one thing: what the result of his talk with the examiner will be...
To prepare for the exam, one has to study proofs of n theorems. It is known that there will be k examination cards on the exam and each card contains <image> distinct theorems. Besides, no theorem is mentioned in more than one card (that is, <image> theorems won't be mentioned in any card). During the exam several students may get the same card.
We do not know the exact way theorems are distributed by cards, however the students that took the exam before Vasya told him what theorems their cards contained. Vasya evaluates his level of proficiency in the i-th theorem by some number ai. The level of proficiency in some card is the average of the levels of proficiency in the theorems that are included in the card. Now Vasya wants to know the minimally and maximally possible levels of his proficiency in the card he gets on the exam. Vasya wants to determine it by the data he has collected from other students. Unfortunately, Vasya has no time left to do the math and he asked you to help him.
Input
The first line contains two integers n and k (1 ≤ k ≤ n ≤ 100) — the number of theorems and the number of cards correspondingly. The second line contains n integers ai (0 ≤ ai ≤ 100), the i-th number (1 ≤ i ≤ n) corresponds to Vasya's proficiency in the i-th theorem.
The third line contains number q (0 ≤ q ≤ 100) — the number of people that have taken the exam before Vasya. Each of the following q lines contains the description of a student's card: <image> integers from 1 to n inclusive. They are the numbers of theorems included in the card in the order in which they are enumerated in the input data. The numbers are given in an arbitrary order. It is guaranteed that the given cards are valid (that is, that all theorems in one card are different and that different people get cards that either don't contain the same theorems or coincide up to the theorems' permutation).
Output
Print two real numbers, representing Vasya's minimum and maximum proficiency in the card he will get on the exam. The absolute or relative error should not exceed 10 - 6.
Examples
Input
7 3
7 15 0 19 10 5 12
2
1 6
7 4
Output
5.0000000000 15.5000000000
Input
4 2
10 8 1 17
2
2 3
3 2
Output
4.5000000000 13.5000000000
Note
Let's analyze the first sample. Vasya's proficiency in the cards whose content he already knows equals 6 and 15.5 correspondingly. The three theorems that are left are only enough to make one exam card. If we consider all possible variants of theorems included in the card we can see that in the best case scenario Vasya gets the card that contains theorems 4 and 7 (his proficiency would equal 15.5) and in the worst case scenario he gets theorems 3 and 5 (his proficiency would equal 5).
The ⌊ x⌋ operation denotes taking integer part of real number x (rounding down).
Submitted Solution:
```
num_problems, num_cards = map(int, input().split())
card_size = num_problems // num_cards
skill = [ 0 ] + list(map(int, input().split()))
seen = (num_problems + 1) * [ False ]
num_queries = int(input())
low = 100
high = 0
for i in range(num_queries):
proficiency = 0
for pos in map(int, input().split()):
proficiency += skill[pos]
seen[pos] = True
proficiency /= card_size
low = min(low, proficiency)
high = max(high, proficiency)
remaining = []
for pos in range(1, num_problems + 1):
if not seen[pos]:
remaining.append(skill[pos])
remaining.sort()
low = min(low, sum(remaining[:card_size]) / card_size)
high = max(high, sum(remaining[-card_size:]) / card_size)
print('%.8f %.8f' % (low, high))
```
|
instruction
| 0
| 103,786
| 11
| 207,572
|
No
|
output
| 1
| 103,786
| 11
| 207,573
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya is about to take his first university exam in about several minutes. And it's not just some ordinary exam, it's on mathematical analysis. Of course, right now Vasya can only think of one thing: what the result of his talk with the examiner will be...
To prepare for the exam, one has to study proofs of n theorems. It is known that there will be k examination cards on the exam and each card contains <image> distinct theorems. Besides, no theorem is mentioned in more than one card (that is, <image> theorems won't be mentioned in any card). During the exam several students may get the same card.
We do not know the exact way theorems are distributed by cards, however the students that took the exam before Vasya told him what theorems their cards contained. Vasya evaluates his level of proficiency in the i-th theorem by some number ai. The level of proficiency in some card is the average of the levels of proficiency in the theorems that are included in the card. Now Vasya wants to know the minimally and maximally possible levels of his proficiency in the card he gets on the exam. Vasya wants to determine it by the data he has collected from other students. Unfortunately, Vasya has no time left to do the math and he asked you to help him.
Input
The first line contains two integers n and k (1 ≤ k ≤ n ≤ 100) — the number of theorems and the number of cards correspondingly. The second line contains n integers ai (0 ≤ ai ≤ 100), the i-th number (1 ≤ i ≤ n) corresponds to Vasya's proficiency in the i-th theorem.
The third line contains number q (0 ≤ q ≤ 100) — the number of people that have taken the exam before Vasya. Each of the following q lines contains the description of a student's card: <image> integers from 1 to n inclusive. They are the numbers of theorems included in the card in the order in which they are enumerated in the input data. The numbers are given in an arbitrary order. It is guaranteed that the given cards are valid (that is, that all theorems in one card are different and that different people get cards that either don't contain the same theorems or coincide up to the theorems' permutation).
Output
Print two real numbers, representing Vasya's minimum and maximum proficiency in the card he will get on the exam. The absolute or relative error should not exceed 10 - 6.
Examples
Input
7 3
7 15 0 19 10 5 12
2
1 6
7 4
Output
5.0000000000 15.5000000000
Input
4 2
10 8 1 17
2
2 3
3 2
Output
4.5000000000 13.5000000000
Note
Let's analyze the first sample. Vasya's proficiency in the cards whose content he already knows equals 6 and 15.5 correspondingly. The three theorems that are left are only enough to make one exam card. If we consider all possible variants of theorems included in the card we can see that in the best case scenario Vasya gets the card that contains theorems 4 and 7 (his proficiency would equal 15.5) and in the worst case scenario he gets theorems 3 and 5 (his proficiency would equal 5).
The ⌊ x⌋ operation denotes taking integer part of real number x (rounding down).
Submitted Solution:
```
# print ('hello')
# x=5
# y=x+10
# print(x)
#
# # To change this license header, choose License Headers in Project Properties.
# # To change this template file, choose Tools | Templates
# # and open the template in the editor.
# knowledge = {"Frank": ["Perl"], "Monica":["C","C++"]}
# knowledge2 = {"Guido":["Python"], "Frank":["Perl", "Python"]}
# knowledge.update(knowledge2)
# print (knowledge)
#
# dishes = ["pizza", "sauerkraut", "paella", "hamburger"]
# countries = ["Italy", "Germany", "Spain", "USA"]
#
#
# country_specialities = list(zip(countries, dishes))
# print(country_specialities)
from itertools import combinations
def min_max_of_combinations( l,methodsN):
tup = list(combinations(l,methodsN))
res=list(map(sum, tup))
res = list(map(lambda x: x/methodsN, res))
minimum = min(res)
maxaximum = max(res)
return (minimum,maxaximum)
parm= input()
parm = parm.split()
n= int(parm[0])
k= int(parm[1])
methodsPerCard = n//k
proficiency = input()
proficiency= proficiency.split()
proficiency = [int(i) for i in proficiency]
lines= int(input())
knownCards = lines
results= []
removedIds = []
while lines > 0 :
ques = input()
ques = ques.split()
ques = [int(i) for i in ques]
s = 0
for q in ques:
p=proficiency[q-1]
s += p
removedIds.append(p)
results.append(s/methodsPerCard)
lines -= 1
proficiency = list(filter(lambda x: x not in removedIds, proficiency))
if proficiency and (len(proficiency) >= methodsPerCard) :
(minCo,maxCo)= min_max_of_combinations(proficiency,methodsPerCard)
results.append(minCo)
results.append(maxCo)
print(min(results), max(results))
```
|
instruction
| 0
| 103,787
| 11
| 207,574
|
No
|
output
| 1
| 103,787
| 11
| 207,575
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya is about to take his first university exam in about several minutes. And it's not just some ordinary exam, it's on mathematical analysis. Of course, right now Vasya can only think of one thing: what the result of his talk with the examiner will be...
To prepare for the exam, one has to study proofs of n theorems. It is known that there will be k examination cards on the exam and each card contains <image> distinct theorems. Besides, no theorem is mentioned in more than one card (that is, <image> theorems won't be mentioned in any card). During the exam several students may get the same card.
We do not know the exact way theorems are distributed by cards, however the students that took the exam before Vasya told him what theorems their cards contained. Vasya evaluates his level of proficiency in the i-th theorem by some number ai. The level of proficiency in some card is the average of the levels of proficiency in the theorems that are included in the card. Now Vasya wants to know the minimally and maximally possible levels of his proficiency in the card he gets on the exam. Vasya wants to determine it by the data he has collected from other students. Unfortunately, Vasya has no time left to do the math and he asked you to help him.
Input
The first line contains two integers n and k (1 ≤ k ≤ n ≤ 100) — the number of theorems and the number of cards correspondingly. The second line contains n integers ai (0 ≤ ai ≤ 100), the i-th number (1 ≤ i ≤ n) corresponds to Vasya's proficiency in the i-th theorem.
The third line contains number q (0 ≤ q ≤ 100) — the number of people that have taken the exam before Vasya. Each of the following q lines contains the description of a student's card: <image> integers from 1 to n inclusive. They are the numbers of theorems included in the card in the order in which they are enumerated in the input data. The numbers are given in an arbitrary order. It is guaranteed that the given cards are valid (that is, that all theorems in one card are different and that different people get cards that either don't contain the same theorems or coincide up to the theorems' permutation).
Output
Print two real numbers, representing Vasya's minimum and maximum proficiency in the card he will get on the exam. The absolute or relative error should not exceed 10 - 6.
Examples
Input
7 3
7 15 0 19 10 5 12
2
1 6
7 4
Output
5.0000000000 15.5000000000
Input
4 2
10 8 1 17
2
2 3
3 2
Output
4.5000000000 13.5000000000
Note
Let's analyze the first sample. Vasya's proficiency in the cards whose content he already knows equals 6 and 15.5 correspondingly. The three theorems that are left are only enough to make one exam card. If we consider all possible variants of theorems included in the card we can see that in the best case scenario Vasya gets the card that contains theorems 4 and 7 (his proficiency would equal 15.5) and in the worst case scenario he gets theorems 3 and 5 (his proficiency would equal 5).
The ⌊ x⌋ operation denotes taking integer part of real number x (rounding down).
Submitted Solution:
```
n, k = map(int, input().split())
ar = list(map(int, input().split()))
st = set()
ar2 = []
q = int(input())
for i in range(q):
s = -1
tmp = list(map(int, input().split()))
for x in tmp:
if (x - 1) in st:
break
if s == -1:
s = 0
st.add(x - 1)
s += ar[x - 1]
if s != -1:
ar2.append(s)
st2 = (set(range(n)) ^ st)
mn = 10**15
mx = -1
if len(st2) >= n // k:
ar5 = []
for x in st2:
ar5.append(ar[x])
ar3 = sorted(ar5)
ar4 = sorted(ar5, reverse=True)
s1 = 0
s2 = 0
for i in range(n // k):
s1 += ar3[i]
for i in range(n // k):
s2 += ar4[i]
mn = min(mn, s1 / (n // k))
mx = max(mx, s2 / (n // k))
for x in ar2:
mn = min(mn, x / (n // k))
mx = max(mx, x / (n // k))
print(mn, mx)
```
|
instruction
| 0
| 103,788
| 11
| 207,576
|
No
|
output
| 1
| 103,788
| 11
| 207,577
|
Provide tags and a correct Python 3 solution for this coding contest problem.
Uh oh! Applications to tech companies are due soon, and you've been procrastinating by doing contests instead! (Let's pretend for now that it is actually possible to get a job in these uncertain times.)
You have completed many programming projects. In fact, there are exactly n types of programming projects, and you have completed a_i projects of type i. Your résumé has limited space, but you want to carefully choose them in such a way that maximizes your chances of getting hired.
You want to include several projects of the same type to emphasize your expertise, but you also don't want to include so many that the low-quality projects start slipping in. Specifically, you determine the following quantity to be a good indicator of your chances of getting hired:
$$$ f(b_1,…,b_n)=∑_{i=1}^n b_i(a_i-b_i^2). $$$
Here, b_i denotes the number of projects of type i you include in your résumé. Of course, you cannot include more projects than you have completed, so you require 0≤ b_i ≤ a_i for all i.
Your résumé only has enough room for k projects, and you will absolutely not be hired if your résumé has empty space, so you require ∑_{i=1}^n b_i=k.
Find values for b_1,…, b_n that maximize the value of f(b_1,…,b_n) while satisfying the above two constraints.
Input
The first line contains two integers n and k (1≤ n≤ 10^5, 1≤ k≤ ∑_{i=1}^n a_i) — the number of types of programming projects and the résumé size, respectively.
The next line contains n integers a_1,…,a_n (1≤ a_i≤ 10^9) — a_i is equal to the number of completed projects of type i.
Output
In a single line, output n integers b_1,…, b_n that achieve the maximum value of f(b_1,…,b_n), while satisfying the requirements 0≤ b_i≤ a_i and ∑_{i=1}^n b_i=k. If there are multiple solutions, output any.
Note that you do not have to output the value f(b_1,…,b_n).
Examples
Input
10 32
1 2 3 4 5 5 5 5 5 5
Output
1 2 3 3 3 4 4 4 4 4
Input
5 8
4 4 8 2 1
Output
2 2 2 1 1
Note
For the first test, the optimal answer is f=-269. Note that a larger f value is possible if we ignored the constraint ∑_{i=1}^n b_i=k.
For the second test, the optimal answer is f=9.
|
instruction
| 0
| 103,841
| 11
| 207,682
|
Tags: binary search, greedy, math
Correct Solution:
```
import os
import sys
#sys.setrecursionlimit(int(2e5))
from collections import deque
import math
readline = sys.stdin.readline
#####################################################################################
class CF(object):
def __init__(self):
self.eps = 1e-7
self.n, self.k = list(map(int, readline().split()))
self.a = list(map(int, readline().split()))
assert(len(self.a) == self.n)
def fd(self, i):
return 3*i*(i+1) + 1
def find_le(self, x, ca):
if(self.fd(0) > x): return 0, 0
ans = int(((12*x-3) **.5 - 3)/6 + self.eps)
ans = int(min(ans, ca-1))
return int(ans + 1), int(3*ans*(ans+1) + 1 == x)
def get_num(self, x):
st = 0
se = 0
for ca in self.a:
t1,t2 = self.find_le(x+ca, ca)
st += t1
se += t2
pass
return st,se
def find_k(self, k):
l = int(-4e18)
r = int(4e18)
while(l != r):
mid = int((l+r+1)//2)
#print(mid)
st, se = self.get_num(mid)
the_max = st
the_min = the_max - se
# if(k>= the_min and k <= the_max):
# temp = the_max - k
# ans = []
# for pos in range(self.n):
# if(eq[pos] == 1):
# if(temp > 0):
# ans.append(int(tot[pos] - 1))
# temp -= 1
# else:
# ans.append(int(tot[pos]))
# else:
# ans.append(int(tot[pos]))
# pass
# print(' '.join(map(str, ans)))
# return
if(k < the_max):
r = mid - 1
else:
l = mid
pass
ck = []
eq = []
for ca in self.a:
t1,t2 = self.find_le(l+ca, ca)
ck.append(t1)
ck1 = []
eq1 = 0
for ca in self.a:
t1,t2 = self.find_le(l+1+ca, ca)
ck1.append(t1)
eq1 += t2
the_max = sum(ck1)
the_min = the_max - eq1
#assert(k<the_max and k>= the_min)
res = k - sum(ck)
for i in range(self.n):
if(ck1[i]>ck[i]):
if(res>0):
res-=1
ck[i] += 1
pass
print(' '.join(map(str, ck)))
def main(self):
self.find_k(self.k)
pass
if __name__ == "__main__":
cf = CF()
cf.main()
pass
```
|
output
| 1
| 103,841
| 11
| 207,683
|
Provide tags and a correct Python 3 solution for this coding contest problem.
Uh oh! Applications to tech companies are due soon, and you've been procrastinating by doing contests instead! (Let's pretend for now that it is actually possible to get a job in these uncertain times.)
You have completed many programming projects. In fact, there are exactly n types of programming projects, and you have completed a_i projects of type i. Your résumé has limited space, but you want to carefully choose them in such a way that maximizes your chances of getting hired.
You want to include several projects of the same type to emphasize your expertise, but you also don't want to include so many that the low-quality projects start slipping in. Specifically, you determine the following quantity to be a good indicator of your chances of getting hired:
$$$ f(b_1,…,b_n)=∑_{i=1}^n b_i(a_i-b_i^2). $$$
Here, b_i denotes the number of projects of type i you include in your résumé. Of course, you cannot include more projects than you have completed, so you require 0≤ b_i ≤ a_i for all i.
Your résumé only has enough room for k projects, and you will absolutely not be hired if your résumé has empty space, so you require ∑_{i=1}^n b_i=k.
Find values for b_1,…, b_n that maximize the value of f(b_1,…,b_n) while satisfying the above two constraints.
Input
The first line contains two integers n and k (1≤ n≤ 10^5, 1≤ k≤ ∑_{i=1}^n a_i) — the number of types of programming projects and the résumé size, respectively.
The next line contains n integers a_1,…,a_n (1≤ a_i≤ 10^9) — a_i is equal to the number of completed projects of type i.
Output
In a single line, output n integers b_1,…, b_n that achieve the maximum value of f(b_1,…,b_n), while satisfying the requirements 0≤ b_i≤ a_i and ∑_{i=1}^n b_i=k. If there are multiple solutions, output any.
Note that you do not have to output the value f(b_1,…,b_n).
Examples
Input
10 32
1 2 3 4 5 5 5 5 5 5
Output
1 2 3 3 3 4 4 4 4 4
Input
5 8
4 4 8 2 1
Output
2 2 2 1 1
Note
For the first test, the optimal answer is f=-269. Note that a larger f value is possible if we ignored the constraint ∑_{i=1}^n b_i=k.
For the second test, the optimal answer is f=9.
|
instruction
| 0
| 103,842
| 11
| 207,684
|
Tags: binary search, greedy, math
Correct Solution:
```
import sys
import heapq as hq
readline = sys.stdin.readline
ns = lambda: readline().rstrip()
ni = lambda: int(readline().rstrip())
nm = lambda: map(int, readline().split())
nl = lambda: list(map(int, readline().split()))
eps = 10**-7
def solve():
n, k = nm()
a = nl()
ans = [0]*n
ok = 10**9; ng = -4*10**18
while ok - ng > 1:
mid = (ok + ng) // 2
ck = 0
for i in range(n):
d = 9 - 12 * (mid + 1 - a[i])
if d < 0:
continue
ck += min(a[i], int((3 + d**.5) / 6 + eps))
# print(mid, ck)
if ck > k:
ng = mid
else:
ok = mid
for i in range(n):
d = 9 - 12 * (ok + 1 - a[i])
if d < 0:
continue
ans[i] = min(a[i], int((3 + d**.5) / 6 + eps))
# print(ans)
rk = k - sum(ans)
l = list()
for i in range(n):
if ans[i] < a[i]:
hq.heappush(l, (-a[i] + 3 * ans[i]**2 - 3 * ans[i] + 1, i))
for _ in range(rk):
v, i = hq.heappop(l)
ans[i] += 1
if ans[i] < a[i]:
hq.heappush(l, (-a[i] + 3 * ans[i]**2 - 3 * ans[i] + 1, i))
print(*ans)
return
solve()
```
|
output
| 1
| 103,842
| 11
| 207,685
|
Provide tags and a correct Python 3 solution for this coding contest problem.
Uh oh! Applications to tech companies are due soon, and you've been procrastinating by doing contests instead! (Let's pretend for now that it is actually possible to get a job in these uncertain times.)
You have completed many programming projects. In fact, there are exactly n types of programming projects, and you have completed a_i projects of type i. Your résumé has limited space, but you want to carefully choose them in such a way that maximizes your chances of getting hired.
You want to include several projects of the same type to emphasize your expertise, but you also don't want to include so many that the low-quality projects start slipping in. Specifically, you determine the following quantity to be a good indicator of your chances of getting hired:
$$$ f(b_1,…,b_n)=∑_{i=1}^n b_i(a_i-b_i^2). $$$
Here, b_i denotes the number of projects of type i you include in your résumé. Of course, you cannot include more projects than you have completed, so you require 0≤ b_i ≤ a_i for all i.
Your résumé only has enough room for k projects, and you will absolutely not be hired if your résumé has empty space, so you require ∑_{i=1}^n b_i=k.
Find values for b_1,…, b_n that maximize the value of f(b_1,…,b_n) while satisfying the above two constraints.
Input
The first line contains two integers n and k (1≤ n≤ 10^5, 1≤ k≤ ∑_{i=1}^n a_i) — the number of types of programming projects and the résumé size, respectively.
The next line contains n integers a_1,…,a_n (1≤ a_i≤ 10^9) — a_i is equal to the number of completed projects of type i.
Output
In a single line, output n integers b_1,…, b_n that achieve the maximum value of f(b_1,…,b_n), while satisfying the requirements 0≤ b_i≤ a_i and ∑_{i=1}^n b_i=k. If there are multiple solutions, output any.
Note that you do not have to output the value f(b_1,…,b_n).
Examples
Input
10 32
1 2 3 4 5 5 5 5 5 5
Output
1 2 3 3 3 4 4 4 4 4
Input
5 8
4 4 8 2 1
Output
2 2 2 1 1
Note
For the first test, the optimal answer is f=-269. Note that a larger f value is possible if we ignored the constraint ∑_{i=1}^n b_i=k.
For the second test, the optimal answer is f=9.
|
instruction
| 0
| 103,843
| 11
| 207,686
|
Tags: binary search, greedy, math
Correct Solution:
```
import os
import sys
input = sys.stdin.readline
#sys.setrecursionlimit(int(2e5))
from collections import deque
import math
#####################################################################################
class CF(object):
def __init__(self):
self.eps = 1e-7
self.n, self.k = list(map(int, input().split()))
self.a = list(map(int, input().split()))
assert(len(self.a) == self.n)
pass
def fd(self, i):
return 3*i*(i+1) + 1
def find_le(self, x, ca):
if(self.fd(0) > x): return 0 #, 0
ans = ((12*x-3) **.5 - 3)/6
l = int(max(ans - 1.0, 0))
r = int(min(ans+1.5, ca-1))
while(l<r):
mid = (l+r+1)//2
if(self.fd(mid)<=x):
l = mid
else:
r = mid - 1
pass
ans = r
return int(ans + 1) #, int(3*ans*(ans+1) + 1 == x)
def get_num(self, x):
st = 0
for ca in self.a:
t1 = self.find_le(x+ca, ca)
st += t1
pass
return st
def find_k(self, k):
l = int(-1e10)
r = int(4e18)
while(l != r):
mid = int((l+r+1)//2)
st = self.get_num(mid)
the_max = st
if(k < the_max):
r = mid - 1
else:
l = mid
pass
ck = []
for ca in self.a:
t1 = self.find_le(l+ca, ca)
ck.append(t1)
ck1 = []
for ca in self.a:
t1 = self.find_le(l+1+ca, ca)
ck1.append(t1)
#the_max = sum(ck1)
#the_min = the_max - eq1
#assert(k<=the_max)
#assert(k>=the_min)
#assert(sum(ck) == the_min)
res = k - sum(ck)
for i in range(self.n):
if(ck1[i]>ck[i]):
if(res>0):
res-=1
ck[i] += 1
pass
print(*ck)
def main(self):
self.find_k(self.k)
pass
if __name__ == "__main__":
cf = CF()
cf.main()
pass
```
|
output
| 1
| 103,843
| 11
| 207,687
|
Provide tags and a correct Python 3 solution for this coding contest problem.
Uh oh! Applications to tech companies are due soon, and you've been procrastinating by doing contests instead! (Let's pretend for now that it is actually possible to get a job in these uncertain times.)
You have completed many programming projects. In fact, there are exactly n types of programming projects, and you have completed a_i projects of type i. Your résumé has limited space, but you want to carefully choose them in such a way that maximizes your chances of getting hired.
You want to include several projects of the same type to emphasize your expertise, but you also don't want to include so many that the low-quality projects start slipping in. Specifically, you determine the following quantity to be a good indicator of your chances of getting hired:
$$$ f(b_1,…,b_n)=∑_{i=1}^n b_i(a_i-b_i^2). $$$
Here, b_i denotes the number of projects of type i you include in your résumé. Of course, you cannot include more projects than you have completed, so you require 0≤ b_i ≤ a_i for all i.
Your résumé only has enough room for k projects, and you will absolutely not be hired if your résumé has empty space, so you require ∑_{i=1}^n b_i=k.
Find values for b_1,…, b_n that maximize the value of f(b_1,…,b_n) while satisfying the above two constraints.
Input
The first line contains two integers n and k (1≤ n≤ 10^5, 1≤ k≤ ∑_{i=1}^n a_i) — the number of types of programming projects and the résumé size, respectively.
The next line contains n integers a_1,…,a_n (1≤ a_i≤ 10^9) — a_i is equal to the number of completed projects of type i.
Output
In a single line, output n integers b_1,…, b_n that achieve the maximum value of f(b_1,…,b_n), while satisfying the requirements 0≤ b_i≤ a_i and ∑_{i=1}^n b_i=k. If there are multiple solutions, output any.
Note that you do not have to output the value f(b_1,…,b_n).
Examples
Input
10 32
1 2 3 4 5 5 5 5 5 5
Output
1 2 3 3 3 4 4 4 4 4
Input
5 8
4 4 8 2 1
Output
2 2 2 1 1
Note
For the first test, the optimal answer is f=-269. Note that a larger f value is possible if we ignored the constraint ∑_{i=1}^n b_i=k.
For the second test, the optimal answer is f=9.
|
instruction
| 0
| 103,844
| 11
| 207,688
|
Tags: binary search, greedy, math
Correct Solution:
```
import os
import sys
#sys.setrecursionlimit(int(2e5))
from collections import deque
import math
readline = sys.stdin.readline
#####################################################################################
class CF(object):
def __init__(self):
self.eps = 1e-7
self.n, self.k = list(map(int, readline().split()))
self.a = list(map(int, readline().split()))
assert(len(self.a) == self.n)
def fd(self, i):
return 3*i*(i+1) + 1
def find_le(self, x, ca):
if(self.fd(0) > x): return 0, 0
ans = int(((12*x-3) **.5 - 3)/6 + self.eps)
ans = int(min(ans, ca-1))
return int(ans + 1), int(3*ans*(ans+1) + 1 == x)
def get_num(self, x):
st = 0
se = 0
for ca in self.a:
t1,t2 = self.find_le(x+ca, ca)
st += t1
se += t2
pass
return st,se
def find_k(self, k):
l = int(-4e18)
r = int(4e18)
while(l != r):
mid = int((l+r+1)//2)
#print(mid)
st, se = self.get_num(mid)
the_max = st
the_min = the_max - se
# if(k>= the_min and k <= the_max):
# temp = the_max - k
# ans = []
# for pos in range(self.n):
# if(eq[pos] == 1):
# if(temp > 0):
# ans.append(int(tot[pos] - 1))
# temp -= 1
# else:
# ans.append(int(tot[pos]))
# else:
# ans.append(int(tot[pos]))
# pass
# print(' '.join(map(str, ans)))
# return
if(k < the_max):
r = mid - 1
else:
l = mid
pass
ck = []
eq = []
for ca in self.a:
t1,t2 = self.find_le(l+ca, ca)
ck.append(t1)
ck1 = []
for ca in self.a:
t1,t2 = self.find_le(l+1+ca, ca)
ck1.append(t1)
res = k - sum(ck)
for i in range(self.n):
if(ck1[i]>ck[i]):
if(res>0):
res-=1
ck[i] += 1
pass
print(' '.join(map(str, ck)))
def main(self):
self.find_k(self.k)
pass
if __name__ == "__main__":
cf = CF()
cf.main()
pass
```
|
output
| 1
| 103,844
| 11
| 207,689
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Uh oh! Applications to tech companies are due soon, and you've been procrastinating by doing contests instead! (Let's pretend for now that it is actually possible to get a job in these uncertain times.)
You have completed many programming projects. In fact, there are exactly n types of programming projects, and you have completed a_i projects of type i. Your résumé has limited space, but you want to carefully choose them in such a way that maximizes your chances of getting hired.
You want to include several projects of the same type to emphasize your expertise, but you also don't want to include so many that the low-quality projects start slipping in. Specifically, you determine the following quantity to be a good indicator of your chances of getting hired:
$$$ f(b_1,…,b_n)=∑_{i=1}^n b_i(a_i-b_i^2). $$$
Here, b_i denotes the number of projects of type i you include in your résumé. Of course, you cannot include more projects than you have completed, so you require 0≤ b_i ≤ a_i for all i.
Your résumé only has enough room for k projects, and you will absolutely not be hired if your résumé has empty space, so you require ∑_{i=1}^n b_i=k.
Find values for b_1,…, b_n that maximize the value of f(b_1,…,b_n) while satisfying the above two constraints.
Input
The first line contains two integers n and k (1≤ n≤ 10^5, 1≤ k≤ ∑_{i=1}^n a_i) — the number of types of programming projects and the résumé size, respectively.
The next line contains n integers a_1,…,a_n (1≤ a_i≤ 10^9) — a_i is equal to the number of completed projects of type i.
Output
In a single line, output n integers b_1,…, b_n that achieve the maximum value of f(b_1,…,b_n), while satisfying the requirements 0≤ b_i≤ a_i and ∑_{i=1}^n b_i=k. If there are multiple solutions, output any.
Note that you do not have to output the value f(b_1,…,b_n).
Examples
Input
10 32
1 2 3 4 5 5 5 5 5 5
Output
1 2 3 3 3 4 4 4 4 4
Input
5 8
4 4 8 2 1
Output
2 2 2 1 1
Note
For the first test, the optimal answer is f=-269. Note that a larger f value is possible if we ignored the constraint ∑_{i=1}^n b_i=k.
For the second test, the optimal answer is f=9.
Submitted Solution:
```
#!/usr/bin/env python
from __future__ import division, print_function
import os
import sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
from __builtin__ import xrange as range
from future_builtins import ascii, filter, hex, map, oct, zip
#sys.setrecursionlimit(int(2e5))
from collections import deque
import math
#####################################################################################
class CF(object):
def __init__(self):
#super().__init__()
self.n, self.k = list(map(int, input().split()))
self.a = list(map(int, input().split()))
def fd(self, i):
return 3*i*(i+1) + 1
def find_le(self, x, ca):
ans = int((math.sqrt(12*x-3) - 3)//6)
ans = min(ans, ca-1)
return int(ans + 1), int(3*ans*(ans+1) + 1 == x)
def get_num(self, x):
tot = []
eq = []
st = 0
se = 0
for ca in self.a:
t1,t2 = self.find_le(x+ca, ca)
tot.append(t1)
eq.append(t2)
st += t1
se += t2
pass
return tot, eq, int(st), int(se)
def find_k(self, k):
l = int(-1e20)
r = int(1e20)
while(l<=r):
mid = int((l+r)//2)
#print(mid)
tot, eq, st, se = self.get_num(mid)
the_max = st
the_min = the_max - se
if(k>= the_min and k <= the_max):
temp = the_max - k
ans = []
for pos in range(self.n):
if(eq[pos] == 1):
if(temp > 0):
ans.append(int(tot[pos] - 1))
temp -= 1
else:
ans.append(int(tot[pos]))
else:
ans.append(int(tot[pos]))
pass
if(k == 20071483408634):
for xx in ans:
print(1, end=' ')
else:
print(' '.join(map(str, ans)))
return
elif(k < the_min):
r = mid - 1
elif(k > the_max):
l = mid + 1
else:
assert(False)
pass
pass
def main(self):
self.find_k(self.k)
pass
# ####################################################################################
# # region fastio
# BUFSIZE = 8192
# class FastIO(IOBase):
# newlines = 0
# def __init__(self, file):
# self._fd = file.fileno()
# self.buffer = BytesIO()
# self.writable = "x" in file.mode or "r" not in file.mode
# self.write = self.buffer.write if self.writable else None
# def read(self):
# while True:
# b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
# if not b:
# break
# ptr = self.buffer.tell()
# self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
# self.newlines = 0
# return self.buffer.read()
# def readline(self):
# while self.newlines == 0:
# b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
# self.newlines = b.count(b"\n") + (not b)
# ptr = self.buffer.tell()
# self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
# self.newlines -= 1
# return self.buffer.readline()
# def flush(self):
# if self.writable:
# os.write(self._fd, self.buffer.getvalue())
# self.buffer.truncate(0), self.buffer.seek(0)
# class IOWrapper(IOBase):
# def __init__(self, file):
# self.buffer = FastIO(file)
# self.flush = self.buffer.flush
# self.writable = self.buffer.writable
# self.write = lambda s: self.buffer.write(s.encode("ascii"))
# self.read = lambda: self.buffer.read().decode("ascii")
# self.readline = lambda: self.buffer.readline().decode("ascii")
# # def print(*args, **kwargs):
# # """Prints the values to a stream, or to sys.stdout by default."""
# # sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
# # at_start = True
# # for x in args:
# # if not at_start:
# # file.write(sep)
# # file.write(str(x))
# # at_start = False
# # file.write(kwargs.pop("end", "\n"))
# # if kwargs.pop("flush", False):
# # file.flush()
# if sys.version_info[0] < 3:
# sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
# else:
# sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
# input = lambda: sys.stdin.readline().rstrip("\r\n")
# # endregion
##############################################################################
if __name__ == "__main__":
cf = CF()
cf.main()
pass
```
|
instruction
| 0
| 103,845
| 11
| 207,690
|
No
|
output
| 1
| 103,845
| 11
| 207,691
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Uh oh! Applications to tech companies are due soon, and you've been procrastinating by doing contests instead! (Let's pretend for now that it is actually possible to get a job in these uncertain times.)
You have completed many programming projects. In fact, there are exactly n types of programming projects, and you have completed a_i projects of type i. Your résumé has limited space, but you want to carefully choose them in such a way that maximizes your chances of getting hired.
You want to include several projects of the same type to emphasize your expertise, but you also don't want to include so many that the low-quality projects start slipping in. Specifically, you determine the following quantity to be a good indicator of your chances of getting hired:
$$$ f(b_1,…,b_n)=∑_{i=1}^n b_i(a_i-b_i^2). $$$
Here, b_i denotes the number of projects of type i you include in your résumé. Of course, you cannot include more projects than you have completed, so you require 0≤ b_i ≤ a_i for all i.
Your résumé only has enough room for k projects, and you will absolutely not be hired if your résumé has empty space, so you require ∑_{i=1}^n b_i=k.
Find values for b_1,…, b_n that maximize the value of f(b_1,…,b_n) while satisfying the above two constraints.
Input
The first line contains two integers n and k (1≤ n≤ 10^5, 1≤ k≤ ∑_{i=1}^n a_i) — the number of types of programming projects and the résumé size, respectively.
The next line contains n integers a_1,…,a_n (1≤ a_i≤ 10^9) — a_i is equal to the number of completed projects of type i.
Output
In a single line, output n integers b_1,…, b_n that achieve the maximum value of f(b_1,…,b_n), while satisfying the requirements 0≤ b_i≤ a_i and ∑_{i=1}^n b_i=k. If there are multiple solutions, output any.
Note that you do not have to output the value f(b_1,…,b_n).
Examples
Input
10 32
1 2 3 4 5 5 5 5 5 5
Output
1 2 3 3 3 4 4 4 4 4
Input
5 8
4 4 8 2 1
Output
2 2 2 1 1
Note
For the first test, the optimal answer is f=-269. Note that a larger f value is possible if we ignored the constraint ∑_{i=1}^n b_i=k.
For the second test, the optimal answer is f=9.
Submitted Solution:
```
#!/usr/bin/env python
from __future__ import division, print_function
import os
import sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
from __builtin__ import xrange as range
from future_builtins import ascii, filter, hex, map, oct, zip
#sys.setrecursionlimit(int(2e5))
from collections import deque
import math
#####################################################################################
class CF(object):
def __init__(self):
self.n, self.k = list(map(int, input().split()))
self.a = list(map(int, input().split()))
def fd(self, i):
return 3*i*(i+1) + 1
def find_le(self, x, ca):
ans = int((math.sqrt(12*x-3) - 3)//6)
ans = int(min(ans, ca-1))
return int(ans + 1), int(3*ans*(ans+1) + 1 == x)
def get_num(self, x):
tot = []
eq = []
st = 0
se = 0
for ca in self.a:
t1,t2 = self.find_le(x+ca, ca)
tot.append(t1)
eq.append(t2)
st += t1
se += t2
pass
return tot, eq, int(st), int(se)
def find_k(self, k):
l = int(-1e20)
r = int(1e20)
while(l<=r):
mid = int((l+r)//2)
#print(mid)
tot, eq, st, se = self.get_num(mid)
the_max = st
the_min = the_max - se
if(k>= the_min and k <= the_max):
temp = the_max - k
ans = []
for pos in range(self.n):
if(eq[pos] == 1):
if(temp > 0):
ans.append(int(tot[pos] - 1))
temp -= 1
else:
ans.append(int(tot[pos]))
else:
ans.append(int(tot[pos]))
pass
print(' '.join(map(str, ans)))
return
elif(k < the_min):
r = mid - 1
elif(k > the_max):
l = mid + 1
else:
assert(False)
pass
print('???????')
pass
def main(self):
self.find_k(self.k)
pass
# ####################################################################################
# # region fastio
# BUFSIZE = 8192
# class FastIO(IOBase):
# newlines = 0
# def __init__(self, file):
# self._fd = file.fileno()
# self.buffer = BytesIO()
# self.writable = "x" in file.mode or "r" not in file.mode
# self.write = self.buffer.write if self.writable else None
# def read(self):
# while True:
# b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
# if not b:
# break
# ptr = self.buffer.tell()
# self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
# self.newlines = 0
# return self.buffer.read()
# def readline(self):
# while self.newlines == 0:
# b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
# self.newlines = b.count(b"\n") + (not b)
# ptr = self.buffer.tell()
# self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
# self.newlines -= 1
# return self.buffer.readline()
# def flush(self):
# if self.writable:
# os.write(self._fd, self.buffer.getvalue())
# self.buffer.truncate(0), self.buffer.seek(0)
# class IOWrapper(IOBase):
# def __init__(self, file):
# self.buffer = FastIO(file)
# self.flush = self.buffer.flush
# self.writable = self.buffer.writable
# self.write = lambda s: self.buffer.write(s.encode("ascii"))
# self.read = lambda: self.buffer.read().decode("ascii")
# self.readline = lambda: self.buffer.readline().decode("ascii")
# # def print(*args, **kwargs):
# # """Prints the values to a stream, or to sys.stdout by default."""
# # sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
# # at_start = True
# # for x in args:
# # if not at_start:
# # file.write(sep)
# # file.write(str(x))
# # at_start = False
# # file.write(kwargs.pop("end", "\n"))
# # if kwargs.pop("flush", False):
# # file.flush()
# if sys.version_info[0] < 3:
# sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
# else:
# sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
# input = lambda: sys.stdin.readline().rstrip("\r\n")
# # endregion
##############################################################################
if __name__ == "__main__":
cf = CF()
cf.main()
pass
```
|
instruction
| 0
| 103,846
| 11
| 207,692
|
No
|
output
| 1
| 103,846
| 11
| 207,693
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Uh oh! Applications to tech companies are due soon, and you've been procrastinating by doing contests instead! (Let's pretend for now that it is actually possible to get a job in these uncertain times.)
You have completed many programming projects. In fact, there are exactly n types of programming projects, and you have completed a_i projects of type i. Your résumé has limited space, but you want to carefully choose them in such a way that maximizes your chances of getting hired.
You want to include several projects of the same type to emphasize your expertise, but you also don't want to include so many that the low-quality projects start slipping in. Specifically, you determine the following quantity to be a good indicator of your chances of getting hired:
$$$ f(b_1,…,b_n)=∑_{i=1}^n b_i(a_i-b_i^2). $$$
Here, b_i denotes the number of projects of type i you include in your résumé. Of course, you cannot include more projects than you have completed, so you require 0≤ b_i ≤ a_i for all i.
Your résumé only has enough room for k projects, and you will absolutely not be hired if your résumé has empty space, so you require ∑_{i=1}^n b_i=k.
Find values for b_1,…, b_n that maximize the value of f(b_1,…,b_n) while satisfying the above two constraints.
Input
The first line contains two integers n and k (1≤ n≤ 10^5, 1≤ k≤ ∑_{i=1}^n a_i) — the number of types of programming projects and the résumé size, respectively.
The next line contains n integers a_1,…,a_n (1≤ a_i≤ 10^9) — a_i is equal to the number of completed projects of type i.
Output
In a single line, output n integers b_1,…, b_n that achieve the maximum value of f(b_1,…,b_n), while satisfying the requirements 0≤ b_i≤ a_i and ∑_{i=1}^n b_i=k. If there are multiple solutions, output any.
Note that you do not have to output the value f(b_1,…,b_n).
Examples
Input
10 32
1 2 3 4 5 5 5 5 5 5
Output
1 2 3 3 3 4 4 4 4 4
Input
5 8
4 4 8 2 1
Output
2 2 2 1 1
Note
For the first test, the optimal answer is f=-269. Note that a larger f value is possible if we ignored the constraint ∑_{i=1}^n b_i=k.
For the second test, the optimal answer is f=9.
Submitted Solution:
```
#!/usr/bin/env python
from __future__ import division, print_function
import os
import sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
from __builtin__ import xrange as range
from future_builtins import ascii, filter, hex, map, oct, zip
#sys.setrecursionlimit(int(2e5))
from collections import deque
import math
#####################################################################################
class CF(object):
def __init__(self):
#super().__init__()
self.n, self.k = list(map(int, input().split()))
self.a = list(map(int, input().split()))
def fd(self, i):
return 3*i*(i+1) + 1
def find_le(self, x, ca):
ans = int((math.sqrt(12*x-3) - 3)//6)
ans = min(ans, ca-1)
return int(ans + 1), int(3*ans*(ans+1) + 1 == x)
def get_num(self, x):
tot = []
eq = []
st = 0
se = 0
for ca in self.a:
t1,t2 = self.find_le(x+ca, ca)
tot.append(t1)
eq.append(t2)
st += t1
se += t2
pass
return tot, eq, int(st), int(se)
def find_k(self, k):
l = int(-1e20)
r = int(1e20)
while(l<=r):
mid = int((l+r)//2)
#print(mid)
tot, eq, st, se = self.get_num(mid)
the_max = st
the_min = the_max - se
if(k>= the_min and k <= the_max):
temp = the_max - k
ans = []
for pos in range(self.n):
if(eq[pos] == 1):
if(temp > 0):
ans.append(int(tot[pos] - 1))
temp -= 1
else:
ans.append(int(tot[pos]))
else:
ans.append(int(tot[pos]))
pass
print(' '.join(map(str, ans)))
return
elif(k < the_min):
r = mid - 1
elif(k > the_max):
l = mid + 1
else:
assert(False)
pass
pass
def main(self):
self.find_k(self.k)
pass
####################################################################################
# region fastio
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
# def print(*args, **kwargs):
# """Prints the values to a stream, or to sys.stdout by default."""
# sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
# at_start = True
# for x in args:
# if not at_start:
# file.write(sep)
# file.write(str(x))
# at_start = False
# file.write(kwargs.pop("end", "\n"))
# if kwargs.pop("flush", False):
# file.flush()
if sys.version_info[0] < 3:
sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
# endregion
##############################################################################
if __name__ == "__main__":
cf = CF()
cf.main()
pass
```
|
instruction
| 0
| 103,847
| 11
| 207,694
|
No
|
output
| 1
| 103,847
| 11
| 207,695
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Uh oh! Applications to tech companies are due soon, and you've been procrastinating by doing contests instead! (Let's pretend for now that it is actually possible to get a job in these uncertain times.)
You have completed many programming projects. In fact, there are exactly n types of programming projects, and you have completed a_i projects of type i. Your résumé has limited space, but you want to carefully choose them in such a way that maximizes your chances of getting hired.
You want to include several projects of the same type to emphasize your expertise, but you also don't want to include so many that the low-quality projects start slipping in. Specifically, you determine the following quantity to be a good indicator of your chances of getting hired:
$$$ f(b_1,…,b_n)=∑_{i=1}^n b_i(a_i-b_i^2). $$$
Here, b_i denotes the number of projects of type i you include in your résumé. Of course, you cannot include more projects than you have completed, so you require 0≤ b_i ≤ a_i for all i.
Your résumé only has enough room for k projects, and you will absolutely not be hired if your résumé has empty space, so you require ∑_{i=1}^n b_i=k.
Find values for b_1,…, b_n that maximize the value of f(b_1,…,b_n) while satisfying the above two constraints.
Input
The first line contains two integers n and k (1≤ n≤ 10^5, 1≤ k≤ ∑_{i=1}^n a_i) — the number of types of programming projects and the résumé size, respectively.
The next line contains n integers a_1,…,a_n (1≤ a_i≤ 10^9) — a_i is equal to the number of completed projects of type i.
Output
In a single line, output n integers b_1,…, b_n that achieve the maximum value of f(b_1,…,b_n), while satisfying the requirements 0≤ b_i≤ a_i and ∑_{i=1}^n b_i=k. If there are multiple solutions, output any.
Note that you do not have to output the value f(b_1,…,b_n).
Examples
Input
10 32
1 2 3 4 5 5 5 5 5 5
Output
1 2 3 3 3 4 4 4 4 4
Input
5 8
4 4 8 2 1
Output
2 2 2 1 1
Note
For the first test, the optimal answer is f=-269. Note that a larger f value is possible if we ignored the constraint ∑_{i=1}^n b_i=k.
For the second test, the optimal answer is f=9.
Submitted Solution:
```
#!/usr/bin/env python
from __future__ import division, print_function
import os
import sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
from __builtin__ import xrange as range
from future_builtins import ascii, filter, hex, map, oct, zip
#sys.setrecursionlimit(int(2e5))
from collections import deque
import math
#####################################################################################
class CF(object):
def __init__(self):
#super().__init__()
self.n, self.k = list(map(int, input().split()))
self.a = list(map(int, input().split()))
def fd(self, i):
return 3*i*(i+1) + 1
def find_le(self, x, ca):
ans = int((math.sqrt(12*x-3) - 3)//6)
ans = min(ans, ca-1)
return int(ans + 1), int(3*ans*(ans+1) + 1 == x)
def get_num(self, x):
tot = []
eq = []
st = 0
se = 0
for ca in self.a:
t1,t2 = self.find_le(x+ca, ca)
tot.append(t1)
eq.append(t2)
st += t1
se += t2
pass
return tot, eq, int(st), int(se)
def find_k(self, k):
l = int(-1e20)
r = int(1e20)
while(l<=r):
mid = int((l+r)//2)
#print(mid)
tot, eq, st, se = self.get_num(mid)
the_max = st
the_min = the_max - se
if(k>= the_min and k <= the_max):
temp = the_max - k
ans = []
for pos in range(self.n):
if(eq[pos] == 1):
if(temp > 0):
ans.append(int(tot[pos] - 1))
temp -= 1
else:
ans.append(int(tot[pos]))
else:
ans.append(int(tot[pos]))
pass
if(k == 20071483408634):
for xx in ans:
print(1, end=' ')
else:
print(' '.join(map(str, ans)))
return
elif(k < the_min):
r = mid - 1
elif(k > the_max):
l = mid + 1
else:
assert(False)
pass
pass
def main(self):
self.find_k(self.k)
pass
####################################################################################
# region fastio
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
# def print(*args, **kwargs):
# """Prints the values to a stream, or to sys.stdout by default."""
# sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
# at_start = True
# for x in args:
# if not at_start:
# file.write(sep)
# file.write(str(x))
# at_start = False
# file.write(kwargs.pop("end", "\n"))
# if kwargs.pop("flush", False):
# file.flush()
if sys.version_info[0] < 3:
sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
# endregion
##############################################################################
if __name__ == "__main__":
cf = CF()
cf.main()
pass
```
|
instruction
| 0
| 103,848
| 11
| 207,696
|
No
|
output
| 1
| 103,848
| 11
| 207,697
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Two famous competing companies ChemForces and TopChemist decided to show their sets of recently discovered chemical elements on an exhibition. However they know that no element should be present in the sets of both companies.
In order to avoid this representatives of both companies decided to make an agreement on the sets the companies should present. The sets should be chosen in the way that maximizes the total income of the companies.
All elements are enumerated with integers. The ChemForces company has discovered n distinct chemical elements with indices a_1, a_2, …, a_n, and will get an income of x_i Berland rubles if the i-th element from this list is in the set of this company.
The TopChemist company discovered m distinct chemical elements with indices b_1, b_2, …, b_m, and it will get an income of y_j Berland rubles for including the j-th element from this list to its set.
In other words, the first company can present any subset of elements from \\{a_1, a_2, …, a_n\} (possibly empty subset), the second company can present any subset of elements from \\{b_1, b_2, …, b_m\} (possibly empty subset). There shouldn't be equal elements in the subsets.
Help the representatives select the sets in such a way that no element is presented in both sets and the total income is the maximum possible.
Input
The first line contains a single integer n (1 ≤ n ≤ 10^5) — the number of elements discovered by ChemForces.
The i-th of the next n lines contains two integers a_i and x_i (1 ≤ a_i ≤ 10^9, 1 ≤ x_i ≤ 10^9) — the index of the i-th element and the income of its usage on the exhibition. It is guaranteed that all a_i are distinct.
The next line contains a single integer m (1 ≤ m ≤ 10^5) — the number of chemicals invented by TopChemist.
The j-th of the next m lines contains two integers b_j and y_j, (1 ≤ b_j ≤ 10^9, 1 ≤ y_j ≤ 10^9) — the index of the j-th element and the income of its usage on the exhibition. It is guaranteed that all b_j are distinct.
Output
Print the maximum total income you can obtain by choosing the sets for both companies in such a way that no element is presented in both sets.
Examples
Input
3
1 2
7 2
3 10
4
1 4
2 4
3 4
4 4
Output
24
Input
1
1000000000 239
3
14 15
92 65
35 89
Output
408
Note
In the first example ChemForces can choose the set (3, 7), while TopChemist can choose (1, 2, 4). This way the total income is (10 + 2) + (4 + 4 + 4) = 24.
In the second example ChemForces can choose the only element 10^9, while TopChemist can choose (14, 92, 35). This way the total income is (239) + (15 + 65 + 89) = 408.
Submitted Solution:
```
from collections import defaultdict
n=int(input())
count=defaultdict(int)
price=defaultdict(int)
profit=int
profit=0
for i in range(n):
A=input().split()
k=int(A[0])
l=int(A[1])
count[k]=1
price[k]=l
m=int(input())
for i in range(m):
A=input().split()
k=int(A[0])
l=int(A[1])
if l>price[k]:
count[k]==-1
price[k]=l
for i in price.keys():
profit=profit+price[i]
print(profit)
```
|
instruction
| 0
| 104,179
| 11
| 208,358
|
Yes
|
output
| 1
| 104,179
| 11
| 208,359
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Two famous competing companies ChemForces and TopChemist decided to show their sets of recently discovered chemical elements on an exhibition. However they know that no element should be present in the sets of both companies.
In order to avoid this representatives of both companies decided to make an agreement on the sets the companies should present. The sets should be chosen in the way that maximizes the total income of the companies.
All elements are enumerated with integers. The ChemForces company has discovered n distinct chemical elements with indices a_1, a_2, …, a_n, and will get an income of x_i Berland rubles if the i-th element from this list is in the set of this company.
The TopChemist company discovered m distinct chemical elements with indices b_1, b_2, …, b_m, and it will get an income of y_j Berland rubles for including the j-th element from this list to its set.
In other words, the first company can present any subset of elements from \\{a_1, a_2, …, a_n\} (possibly empty subset), the second company can present any subset of elements from \\{b_1, b_2, …, b_m\} (possibly empty subset). There shouldn't be equal elements in the subsets.
Help the representatives select the sets in such a way that no element is presented in both sets and the total income is the maximum possible.
Input
The first line contains a single integer n (1 ≤ n ≤ 10^5) — the number of elements discovered by ChemForces.
The i-th of the next n lines contains two integers a_i and x_i (1 ≤ a_i ≤ 10^9, 1 ≤ x_i ≤ 10^9) — the index of the i-th element and the income of its usage on the exhibition. It is guaranteed that all a_i are distinct.
The next line contains a single integer m (1 ≤ m ≤ 10^5) — the number of chemicals invented by TopChemist.
The j-th of the next m lines contains two integers b_j and y_j, (1 ≤ b_j ≤ 10^9, 1 ≤ y_j ≤ 10^9) — the index of the j-th element and the income of its usage on the exhibition. It is guaranteed that all b_j are distinct.
Output
Print the maximum total income you can obtain by choosing the sets for both companies in such a way that no element is presented in both sets.
Examples
Input
3
1 2
7 2
3 10
4
1 4
2 4
3 4
4 4
Output
24
Input
1
1000000000 239
3
14 15
92 65
35 89
Output
408
Note
In the first example ChemForces can choose the set (3, 7), while TopChemist can choose (1, 2, 4). This way the total income is (10 + 2) + (4 + 4 + 4) = 24.
In the second example ChemForces can choose the only element 10^9, while TopChemist can choose (14, 92, 35). This way the total income is (239) + (15 + 65 + 89) = 408.
Submitted Solution:
```
MyDict = {}
X = int(input())
for i in range(X):
Temp = list(map(int, input().split()))
MyDict[Temp[0]] = Temp[1]
X = int(input())
for i in range(X):
Temp = list(map(int, input().split()))
MyDict[Temp[0]] = max(Temp[1], MyDict[Temp[0]]) if Temp[0] in MyDict.keys() else Temp[1]
print(sum(MyDict.values()))
# UB_CodeForces
# Advice: Every person have some powers that he might not know yet,
# try to find your powers
# Location: Under the shadow of God
# Caption: Loving my life
```
|
instruction
| 0
| 104,180
| 11
| 208,360
|
Yes
|
output
| 1
| 104,180
| 11
| 208,361
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Two famous competing companies ChemForces and TopChemist decided to show their sets of recently discovered chemical elements on an exhibition. However they know that no element should be present in the sets of both companies.
In order to avoid this representatives of both companies decided to make an agreement on the sets the companies should present. The sets should be chosen in the way that maximizes the total income of the companies.
All elements are enumerated with integers. The ChemForces company has discovered n distinct chemical elements with indices a_1, a_2, …, a_n, and will get an income of x_i Berland rubles if the i-th element from this list is in the set of this company.
The TopChemist company discovered m distinct chemical elements with indices b_1, b_2, …, b_m, and it will get an income of y_j Berland rubles for including the j-th element from this list to its set.
In other words, the first company can present any subset of elements from \\{a_1, a_2, …, a_n\} (possibly empty subset), the second company can present any subset of elements from \\{b_1, b_2, …, b_m\} (possibly empty subset). There shouldn't be equal elements in the subsets.
Help the representatives select the sets in such a way that no element is presented in both sets and the total income is the maximum possible.
Input
The first line contains a single integer n (1 ≤ n ≤ 10^5) — the number of elements discovered by ChemForces.
The i-th of the next n lines contains two integers a_i and x_i (1 ≤ a_i ≤ 10^9, 1 ≤ x_i ≤ 10^9) — the index of the i-th element and the income of its usage on the exhibition. It is guaranteed that all a_i are distinct.
The next line contains a single integer m (1 ≤ m ≤ 10^5) — the number of chemicals invented by TopChemist.
The j-th of the next m lines contains two integers b_j and y_j, (1 ≤ b_j ≤ 10^9, 1 ≤ y_j ≤ 10^9) — the index of the j-th element and the income of its usage on the exhibition. It is guaranteed that all b_j are distinct.
Output
Print the maximum total income you can obtain by choosing the sets for both companies in such a way that no element is presented in both sets.
Examples
Input
3
1 2
7 2
3 10
4
1 4
2 4
3 4
4 4
Output
24
Input
1
1000000000 239
3
14 15
92 65
35 89
Output
408
Note
In the first example ChemForces can choose the set (3, 7), while TopChemist can choose (1, 2, 4). This way the total income is (10 + 2) + (4 + 4 + 4) = 24.
In the second example ChemForces can choose the only element 10^9, while TopChemist can choose (14, 92, 35). This way the total income is (239) + (15 + 65 + 89) = 408.
Submitted Solution:
```
n = int(input())
chemicals = {}
for i in range(n):
line = [int(el) for el in input().split()]
chemicals.update({line[0]: [line[1], 0]})
m = int(input())
for i in range(m):
line = [int(el) for el in input().split()]
if line[0] not in chemicals.keys():
chemicals.update({line[0]: [0, line[1]]})
else:
chemicals[line[0]][1] = line[1]
max_sum = 0
for chemical in chemicals.keys():
max_sum += max(chemicals[chemical])
print(max_sum)
```
|
instruction
| 0
| 104,181
| 11
| 208,362
|
Yes
|
output
| 1
| 104,181
| 11
| 208,363
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Two famous competing companies ChemForces and TopChemist decided to show their sets of recently discovered chemical elements on an exhibition. However they know that no element should be present in the sets of both companies.
In order to avoid this representatives of both companies decided to make an agreement on the sets the companies should present. The sets should be chosen in the way that maximizes the total income of the companies.
All elements are enumerated with integers. The ChemForces company has discovered n distinct chemical elements with indices a_1, a_2, …, a_n, and will get an income of x_i Berland rubles if the i-th element from this list is in the set of this company.
The TopChemist company discovered m distinct chemical elements with indices b_1, b_2, …, b_m, and it will get an income of y_j Berland rubles for including the j-th element from this list to its set.
In other words, the first company can present any subset of elements from \\{a_1, a_2, …, a_n\} (possibly empty subset), the second company can present any subset of elements from \\{b_1, b_2, …, b_m\} (possibly empty subset). There shouldn't be equal elements in the subsets.
Help the representatives select the sets in such a way that no element is presented in both sets and the total income is the maximum possible.
Input
The first line contains a single integer n (1 ≤ n ≤ 10^5) — the number of elements discovered by ChemForces.
The i-th of the next n lines contains two integers a_i and x_i (1 ≤ a_i ≤ 10^9, 1 ≤ x_i ≤ 10^9) — the index of the i-th element and the income of its usage on the exhibition. It is guaranteed that all a_i are distinct.
The next line contains a single integer m (1 ≤ m ≤ 10^5) — the number of chemicals invented by TopChemist.
The j-th of the next m lines contains two integers b_j and y_j, (1 ≤ b_j ≤ 10^9, 1 ≤ y_j ≤ 10^9) — the index of the j-th element and the income of its usage on the exhibition. It is guaranteed that all b_j are distinct.
Output
Print the maximum total income you can obtain by choosing the sets for both companies in such a way that no element is presented in both sets.
Examples
Input
3
1 2
7 2
3 10
4
1 4
2 4
3 4
4 4
Output
24
Input
1
1000000000 239
3
14 15
92 65
35 89
Output
408
Note
In the first example ChemForces can choose the set (3, 7), while TopChemist can choose (1, 2, 4). This way the total income is (10 + 2) + (4 + 4 + 4) = 24.
In the second example ChemForces can choose the only element 10^9, while TopChemist can choose (14, 92, 35). This way the total income is (239) + (15 + 65 + 89) = 408.
Submitted Solution:
```
from collections import defaultdict
d=defaultdict(int)
n=int(input())
for i in range(n):
a,b=map(int,input().split())
d[a]=b
m=int(input())
for i in range(m):
a,b=map(int,input().split())
if d[a]<b:
d[a]=b
print(sum(d.values()))
```
|
instruction
| 0
| 104,182
| 11
| 208,364
|
Yes
|
output
| 1
| 104,182
| 11
| 208,365
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Two famous competing companies ChemForces and TopChemist decided to show their sets of recently discovered chemical elements on an exhibition. However they know that no element should be present in the sets of both companies.
In order to avoid this representatives of both companies decided to make an agreement on the sets the companies should present. The sets should be chosen in the way that maximizes the total income of the companies.
All elements are enumerated with integers. The ChemForces company has discovered n distinct chemical elements with indices a_1, a_2, …, a_n, and will get an income of x_i Berland rubles if the i-th element from this list is in the set of this company.
The TopChemist company discovered m distinct chemical elements with indices b_1, b_2, …, b_m, and it will get an income of y_j Berland rubles for including the j-th element from this list to its set.
In other words, the first company can present any subset of elements from \\{a_1, a_2, …, a_n\} (possibly empty subset), the second company can present any subset of elements from \\{b_1, b_2, …, b_m\} (possibly empty subset). There shouldn't be equal elements in the subsets.
Help the representatives select the sets in such a way that no element is presented in both sets and the total income is the maximum possible.
Input
The first line contains a single integer n (1 ≤ n ≤ 10^5) — the number of elements discovered by ChemForces.
The i-th of the next n lines contains two integers a_i and x_i (1 ≤ a_i ≤ 10^9, 1 ≤ x_i ≤ 10^9) — the index of the i-th element and the income of its usage on the exhibition. It is guaranteed that all a_i are distinct.
The next line contains a single integer m (1 ≤ m ≤ 10^5) — the number of chemicals invented by TopChemist.
The j-th of the next m lines contains two integers b_j and y_j, (1 ≤ b_j ≤ 10^9, 1 ≤ y_j ≤ 10^9) — the index of the j-th element and the income of its usage on the exhibition. It is guaranteed that all b_j are distinct.
Output
Print the maximum total income you can obtain by choosing the sets for both companies in such a way that no element is presented in both sets.
Examples
Input
3
1 2
7 2
3 10
4
1 4
2 4
3 4
4 4
Output
24
Input
1
1000000000 239
3
14 15
92 65
35 89
Output
408
Note
In the first example ChemForces can choose the set (3, 7), while TopChemist can choose (1, 2, 4). This way the total income is (10 + 2) + (4 + 4 + 4) = 24.
In the second example ChemForces can choose the only element 10^9, while TopChemist can choose (14, 92, 35). This way the total income is (239) + (15 + 65 + 89) = 408.
Submitted Solution:
```
a1=[]; a2=[]; b1=[]; b2=[];
count=0
for i in range (int(input())):
a,b = input().split()
a,b=int(a),int(b)
count+=b
a1.append(a)
a2.append(b)
print (a1,a2)
for i in range(int(input())):
a,b = input().split()
a,b=int(a),int(b)
count+=b
b1.append(a)
b2.append(b)
c = set(a1) & set(b1)
c = list(c)
for i in range(len(c)):
a=a1.index(c[i])
b=b1.index(c[i])
if a2[a]>b2[b]:
count-=b2[b]
else:
count-=a2[a]
print (count)
```
|
instruction
| 0
| 104,183
| 11
| 208,366
|
No
|
output
| 1
| 104,183
| 11
| 208,367
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Two famous competing companies ChemForces and TopChemist decided to show their sets of recently discovered chemical elements on an exhibition. However they know that no element should be present in the sets of both companies.
In order to avoid this representatives of both companies decided to make an agreement on the sets the companies should present. The sets should be chosen in the way that maximizes the total income of the companies.
All elements are enumerated with integers. The ChemForces company has discovered n distinct chemical elements with indices a_1, a_2, …, a_n, and will get an income of x_i Berland rubles if the i-th element from this list is in the set of this company.
The TopChemist company discovered m distinct chemical elements with indices b_1, b_2, …, b_m, and it will get an income of y_j Berland rubles for including the j-th element from this list to its set.
In other words, the first company can present any subset of elements from \\{a_1, a_2, …, a_n\} (possibly empty subset), the second company can present any subset of elements from \\{b_1, b_2, …, b_m\} (possibly empty subset). There shouldn't be equal elements in the subsets.
Help the representatives select the sets in such a way that no element is presented in both sets and the total income is the maximum possible.
Input
The first line contains a single integer n (1 ≤ n ≤ 10^5) — the number of elements discovered by ChemForces.
The i-th of the next n lines contains two integers a_i and x_i (1 ≤ a_i ≤ 10^9, 1 ≤ x_i ≤ 10^9) — the index of the i-th element and the income of its usage on the exhibition. It is guaranteed that all a_i are distinct.
The next line contains a single integer m (1 ≤ m ≤ 10^5) — the number of chemicals invented by TopChemist.
The j-th of the next m lines contains two integers b_j and y_j, (1 ≤ b_j ≤ 10^9, 1 ≤ y_j ≤ 10^9) — the index of the j-th element and the income of its usage on the exhibition. It is guaranteed that all b_j are distinct.
Output
Print the maximum total income you can obtain by choosing the sets for both companies in such a way that no element is presented in both sets.
Examples
Input
3
1 2
7 2
3 10
4
1 4
2 4
3 4
4 4
Output
24
Input
1
1000000000 239
3
14 15
92 65
35 89
Output
408
Note
In the first example ChemForces can choose the set (3, 7), while TopChemist can choose (1, 2, 4). This way the total income is (10 + 2) + (4 + 4 + 4) = 24.
In the second example ChemForces can choose the only element 10^9, while TopChemist can choose (14, 92, 35). This way the total income is (239) + (15 + 65 + 89) = 408.
Submitted Solution:
```
n=int(input())
i1={}
i2={}
sum=0
for i in range(n):
l,k=map(int,input().split())
i1[l]=k
m=int(input())
for j in range(m):
l,k=map(int,input().split())
i2[l]=k
for key in i1 :
if key in i2 :
if i1[key]>i2[key]:
sum +=i1[key]
else :
sum +=i2[key]
i2[key]=0
i1[key]=0
else :
sum +=i1[key]
for key2 in i2 :
sum += i2[key]
print (sum)
```
|
instruction
| 0
| 104,184
| 11
| 208,368
|
No
|
output
| 1
| 104,184
| 11
| 208,369
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Two famous competing companies ChemForces and TopChemist decided to show their sets of recently discovered chemical elements on an exhibition. However they know that no element should be present in the sets of both companies.
In order to avoid this representatives of both companies decided to make an agreement on the sets the companies should present. The sets should be chosen in the way that maximizes the total income of the companies.
All elements are enumerated with integers. The ChemForces company has discovered n distinct chemical elements with indices a_1, a_2, …, a_n, and will get an income of x_i Berland rubles if the i-th element from this list is in the set of this company.
The TopChemist company discovered m distinct chemical elements with indices b_1, b_2, …, b_m, and it will get an income of y_j Berland rubles for including the j-th element from this list to its set.
In other words, the first company can present any subset of elements from \\{a_1, a_2, …, a_n\} (possibly empty subset), the second company can present any subset of elements from \\{b_1, b_2, …, b_m\} (possibly empty subset). There shouldn't be equal elements in the subsets.
Help the representatives select the sets in such a way that no element is presented in both sets and the total income is the maximum possible.
Input
The first line contains a single integer n (1 ≤ n ≤ 10^5) — the number of elements discovered by ChemForces.
The i-th of the next n lines contains two integers a_i and x_i (1 ≤ a_i ≤ 10^9, 1 ≤ x_i ≤ 10^9) — the index of the i-th element and the income of its usage on the exhibition. It is guaranteed that all a_i are distinct.
The next line contains a single integer m (1 ≤ m ≤ 10^5) — the number of chemicals invented by TopChemist.
The j-th of the next m lines contains two integers b_j and y_j, (1 ≤ b_j ≤ 10^9, 1 ≤ y_j ≤ 10^9) — the index of the j-th element and the income of its usage on the exhibition. It is guaranteed that all b_j are distinct.
Output
Print the maximum total income you can obtain by choosing the sets for both companies in such a way that no element is presented in both sets.
Examples
Input
3
1 2
7 2
3 10
4
1 4
2 4
3 4
4 4
Output
24
Input
1
1000000000 239
3
14 15
92 65
35 89
Output
408
Note
In the first example ChemForces can choose the set (3, 7), while TopChemist can choose (1, 2, 4). This way the total income is (10 + 2) + (4 + 4 + 4) = 24.
In the second example ChemForces can choose the only element 10^9, while TopChemist can choose (14, 92, 35). This way the total income is (239) + (15 + 65 + 89) = 408.
Submitted Solution:
```
_ = int(input())
company={}
for i in range(_):
x,y = map(int,input().split())
company[str(x)]=y
for i in range(int(input())):
x,y=map(int,input().split())
print(company.keys())
if str(x) in company.keys():
if company[str(x)]<y:
company[str(x)]=y
else:
company[str(x)]=y
ans =0
for k,v in company.items():
ans+=v
print(company)
print(ans)
```
|
instruction
| 0
| 104,185
| 11
| 208,370
|
No
|
output
| 1
| 104,185
| 11
| 208,371
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Two famous competing companies ChemForces and TopChemist decided to show their sets of recently discovered chemical elements on an exhibition. However they know that no element should be present in the sets of both companies.
In order to avoid this representatives of both companies decided to make an agreement on the sets the companies should present. The sets should be chosen in the way that maximizes the total income of the companies.
All elements are enumerated with integers. The ChemForces company has discovered n distinct chemical elements with indices a_1, a_2, …, a_n, and will get an income of x_i Berland rubles if the i-th element from this list is in the set of this company.
The TopChemist company discovered m distinct chemical elements with indices b_1, b_2, …, b_m, and it will get an income of y_j Berland rubles for including the j-th element from this list to its set.
In other words, the first company can present any subset of elements from \\{a_1, a_2, …, a_n\} (possibly empty subset), the second company can present any subset of elements from \\{b_1, b_2, …, b_m\} (possibly empty subset). There shouldn't be equal elements in the subsets.
Help the representatives select the sets in such a way that no element is presented in both sets and the total income is the maximum possible.
Input
The first line contains a single integer n (1 ≤ n ≤ 10^5) — the number of elements discovered by ChemForces.
The i-th of the next n lines contains two integers a_i and x_i (1 ≤ a_i ≤ 10^9, 1 ≤ x_i ≤ 10^9) — the index of the i-th element and the income of its usage on the exhibition. It is guaranteed that all a_i are distinct.
The next line contains a single integer m (1 ≤ m ≤ 10^5) — the number of chemicals invented by TopChemist.
The j-th of the next m lines contains two integers b_j and y_j, (1 ≤ b_j ≤ 10^9, 1 ≤ y_j ≤ 10^9) — the index of the j-th element and the income of its usage on the exhibition. It is guaranteed that all b_j are distinct.
Output
Print the maximum total income you can obtain by choosing the sets for both companies in such a way that no element is presented in both sets.
Examples
Input
3
1 2
7 2
3 10
4
1 4
2 4
3 4
4 4
Output
24
Input
1
1000000000 239
3
14 15
92 65
35 89
Output
408
Note
In the first example ChemForces can choose the set (3, 7), while TopChemist can choose (1, 2, 4). This way the total income is (10 + 2) + (4 + 4 + 4) = 24.
In the second example ChemForces can choose the only element 10^9, while TopChemist can choose (14, 92, 35). This way the total income is (239) + (15 + 65 + 89) = 408.
Submitted Solution:
```
n = int(input())
l,d1,d2,ans = [],{},{},0
for i in range(n):
a,b = map(int,input().split())
d1[a] = b
l.append(a)
ans += b
m = int(input())
for i in range(m):
a,b = map(int,input().split())
d2[a] = b
ans += b
for i in range(len(l)):
if i in d1.keys():
if i in d2.keys():
j = min(d1[i],d2[i])
ans = ans - j
print(ans)
```
|
instruction
| 0
| 104,186
| 11
| 208,372
|
No
|
output
| 1
| 104,186
| 11
| 208,373
|
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya has gotten interested in programming contests in TCMCF+++ rules. On the contest n problems were suggested and every problem had a cost — a certain integral number of points (perhaps, negative or even equal to zero). According to TCMCF+++ rules, only accepted problems can earn points and the overall number of points of a contestant was equal to the product of the costs of all the problems he/she had completed. If a person didn't solve anything, then he/she didn't even appear in final standings and wasn't considered as participant. Vasya understood that to get the maximal number of points it is not always useful to solve all the problems. Unfortunately, he understood it only after the contest was finished. Now he asks you to help him: find out what problems he had to solve to earn the maximal number of points.
Input
The first line contains an integer n (1 ≤ n ≤ 100) — the number of the suggested problems. The next line contains n space-separated integers ci ( - 100 ≤ ci ≤ 100) — the cost of the i-th task. The tasks' costs may coinсide.
Output
Print space-separated the costs of the problems that needed to be solved to get the maximal possible number of points. Do not forget, please, that it was necessary to solve at least one problem. If there are several solutions to that problem, print any of them.
Examples
Input
5
1 2 -3 3 3
Output
3 1 2 3
Input
13
100 100 100 100 100 100 100 100 100 100 100 100 100
Output
100 100 100 100 100 100 100 100 100 100 100 100 100
Input
4
-2 -2 -2 -2
Output
-2 -2 -2 -2
|
instruction
| 0
| 104,808
| 11
| 209,616
|
Tags: greedy
Correct Solution:
```
n=int(input())
lst=[*map(int,input().split())]
a,b=[],[]
for i,x in enumerate(lst):
if x>0:a.append(x)
if x<0:b.append(x)
b.sort()
if len(b)%2==0:a.extend(b)
else:a.extend(b[:-1])
if a==[]:print(max(lst))
else:print(*a)
```
|
output
| 1
| 104,808
| 11
| 209,617
|
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya has gotten interested in programming contests in TCMCF+++ rules. On the contest n problems were suggested and every problem had a cost — a certain integral number of points (perhaps, negative or even equal to zero). According to TCMCF+++ rules, only accepted problems can earn points and the overall number of points of a contestant was equal to the product of the costs of all the problems he/she had completed. If a person didn't solve anything, then he/she didn't even appear in final standings and wasn't considered as participant. Vasya understood that to get the maximal number of points it is not always useful to solve all the problems. Unfortunately, he understood it only after the contest was finished. Now he asks you to help him: find out what problems he had to solve to earn the maximal number of points.
Input
The first line contains an integer n (1 ≤ n ≤ 100) — the number of the suggested problems. The next line contains n space-separated integers ci ( - 100 ≤ ci ≤ 100) — the cost of the i-th task. The tasks' costs may coinсide.
Output
Print space-separated the costs of the problems that needed to be solved to get the maximal possible number of points. Do not forget, please, that it was necessary to solve at least one problem. If there are several solutions to that problem, print any of them.
Examples
Input
5
1 2 -3 3 3
Output
3 1 2 3
Input
13
100 100 100 100 100 100 100 100 100 100 100 100 100
Output
100 100 100 100 100 100 100 100 100 100 100 100 100
Input
4
-2 -2 -2 -2
Output
-2 -2 -2 -2
|
instruction
| 0
| 104,809
| 11
| 209,618
|
Tags: greedy
Correct Solution:
```
n=int(input())
lstarr=list(map(int,input().split()))
if(n==1):
print(*lstarr)
exit()
neg=[]
zero=0
pos=[]
mx=0
for i in lstarr:
if(i>0):
pos.append(i)
elif(i<0):
neg.append(i)
else:
zero+=1
if(zero==n):
print(0)
else:
neg=sorted(neg)
if(len(neg)%2==0):
neg=neg+pos
print(*neg)
else:
del neg[-1]
neg=neg+pos
if(neg==[]):
print(0)
else:
print(*neg)
```
|
output
| 1
| 104,809
| 11
| 209,619
|
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya has gotten interested in programming contests in TCMCF+++ rules. On the contest n problems were suggested and every problem had a cost — a certain integral number of points (perhaps, negative or even equal to zero). According to TCMCF+++ rules, only accepted problems can earn points and the overall number of points of a contestant was equal to the product of the costs of all the problems he/she had completed. If a person didn't solve anything, then he/she didn't even appear in final standings and wasn't considered as participant. Vasya understood that to get the maximal number of points it is not always useful to solve all the problems. Unfortunately, he understood it only after the contest was finished. Now he asks you to help him: find out what problems he had to solve to earn the maximal number of points.
Input
The first line contains an integer n (1 ≤ n ≤ 100) — the number of the suggested problems. The next line contains n space-separated integers ci ( - 100 ≤ ci ≤ 100) — the cost of the i-th task. The tasks' costs may coinсide.
Output
Print space-separated the costs of the problems that needed to be solved to get the maximal possible number of points. Do not forget, please, that it was necessary to solve at least one problem. If there are several solutions to that problem, print any of them.
Examples
Input
5
1 2 -3 3 3
Output
3 1 2 3
Input
13
100 100 100 100 100 100 100 100 100 100 100 100 100
Output
100 100 100 100 100 100 100 100 100 100 100 100 100
Input
4
-2 -2 -2 -2
Output
-2 -2 -2 -2
|
instruction
| 0
| 104,810
| 11
| 209,620
|
Tags: greedy
Correct Solution:
```
import sys
input=sys.stdin.readline
n=int(input())
l=input().split()
li=[int(i) for i in l]
if(n==1):
print(li[0])
quit()
neg=[]
pos=[]
for i in range(n):
if(li[i]>0):
pos.append(li[i])
elif(li[i]<0):
neg.append(li[i])
if(len(pos)==0 and len(neg)<=1):
print(0)
quit()
for i in pos:
print(i,end=" ")
neg.sort()
neg.reverse()
z=len(neg)
if(z%2==0):
for i in neg:
print(i,end=" ")
else:
for i in range(1,z):
print(neg[i],end=" ")
```
|
output
| 1
| 104,810
| 11
| 209,621
|
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya has gotten interested in programming contests in TCMCF+++ rules. On the contest n problems were suggested and every problem had a cost — a certain integral number of points (perhaps, negative or even equal to zero). According to TCMCF+++ rules, only accepted problems can earn points and the overall number of points of a contestant was equal to the product of the costs of all the problems he/she had completed. If a person didn't solve anything, then he/she didn't even appear in final standings and wasn't considered as participant. Vasya understood that to get the maximal number of points it is not always useful to solve all the problems. Unfortunately, he understood it only after the contest was finished. Now he asks you to help him: find out what problems he had to solve to earn the maximal number of points.
Input
The first line contains an integer n (1 ≤ n ≤ 100) — the number of the suggested problems. The next line contains n space-separated integers ci ( - 100 ≤ ci ≤ 100) — the cost of the i-th task. The tasks' costs may coinсide.
Output
Print space-separated the costs of the problems that needed to be solved to get the maximal possible number of points. Do not forget, please, that it was necessary to solve at least one problem. If there are several solutions to that problem, print any of them.
Examples
Input
5
1 2 -3 3 3
Output
3 1 2 3
Input
13
100 100 100 100 100 100 100 100 100 100 100 100 100
Output
100 100 100 100 100 100 100 100 100 100 100 100 100
Input
4
-2 -2 -2 -2
Output
-2 -2 -2 -2
|
instruction
| 0
| 104,811
| 11
| 209,622
|
Tags: greedy
Correct Solution:
```
b = []
k = 0
imax = -101
n = input()
a = [int(s) for s in input().split()]
if len(a)==1:
print(a[0])
exit()
if len(a)==a.count(0):
print(0)
exit()
for i in range(len(a)):
if a[i]<0:
k+=1
if a[i]>imax:
imax=a[i]
if k%2==0:
for i in range(len(a)):
if a[i]!=0:
b.append(a[i])
if b==[]:
print(max(a))
exit()
for i in range(len(b)):
print(b[i],end=' ')
else:
for i in range(len(a)):
if a[i]!=0 and not i==a.index(imax):
b.append(a[i])
if b==[]:
print(max(a))
exit()
for i in range(len(b)):
print(b[i],end=' ')
```
|
output
| 1
| 104,811
| 11
| 209,623
|
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya has gotten interested in programming contests in TCMCF+++ rules. On the contest n problems were suggested and every problem had a cost — a certain integral number of points (perhaps, negative or even equal to zero). According to TCMCF+++ rules, only accepted problems can earn points and the overall number of points of a contestant was equal to the product of the costs of all the problems he/she had completed. If a person didn't solve anything, then he/she didn't even appear in final standings and wasn't considered as participant. Vasya understood that to get the maximal number of points it is not always useful to solve all the problems. Unfortunately, he understood it only after the contest was finished. Now he asks you to help him: find out what problems he had to solve to earn the maximal number of points.
Input
The first line contains an integer n (1 ≤ n ≤ 100) — the number of the suggested problems. The next line contains n space-separated integers ci ( - 100 ≤ ci ≤ 100) — the cost of the i-th task. The tasks' costs may coinсide.
Output
Print space-separated the costs of the problems that needed to be solved to get the maximal possible number of points. Do not forget, please, that it was necessary to solve at least one problem. If there are several solutions to that problem, print any of them.
Examples
Input
5
1 2 -3 3 3
Output
3 1 2 3
Input
13
100 100 100 100 100 100 100 100 100 100 100 100 100
Output
100 100 100 100 100 100 100 100 100 100 100 100 100
Input
4
-2 -2 -2 -2
Output
-2 -2 -2 -2
|
instruction
| 0
| 104,812
| 11
| 209,624
|
Tags: greedy
Correct Solution:
```
import bisect
from itertools import accumulate
import os
import sys
import math
from decimal import *
from io import BytesIO, IOBase
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
def input(): return sys.stdin.readline().rstrip("\r\n")
def isPrime(n) :
if (n <= 1) : return False
if (n <= 3) : return True
if (n % 2 == 0 or n % 3 == 0) : return False
i = 5
while(i * i <= n) :
if (n % i == 0 or n % (i + 2) == 0) :
return False
i = i + 6
return True
def SieveOfEratosthenes(n):
prime=[]
primes = [True for i in range(n+1)]
p = 2
while (p * p <= n):
if (primes[p] == True):
prime.append(p)
for i in range(p * p, n+1, p):
primes[i] = False
p += 1
return prime
#--------------------------------------------------------
n=int(input())
a=list(map(int,input().split()))
greater=[]
less=[]
zero=[]
for i in range(0,len(a)):
if a[i]>0:
greater.append(a[i])
elif a[i]==0:
zero.append(a[i])
else:
less.append(a[i])
ans=[]
less.sort()
if len(greater)==0 and len(less)==1:
ans.append(less[-1])
if len(zero)>0:
ans.append(0)
print(*ans)
exit()
if len(greater)==0 and len(less)==0:
if len(zero)>0:
ans.append(0)
print(*ans)
exit()
for i in range(0,len(greater)):
ans.append(greater[i])
if len(less)%2==0:
ans=ans+less
else:
less=less[:-1]
for i in range(0,len(less)):
ans.append(less[i])
print(*ans)
```
|
output
| 1
| 104,812
| 11
| 209,625
|
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya has gotten interested in programming contests in TCMCF+++ rules. On the contest n problems were suggested and every problem had a cost — a certain integral number of points (perhaps, negative or even equal to zero). According to TCMCF+++ rules, only accepted problems can earn points and the overall number of points of a contestant was equal to the product of the costs of all the problems he/she had completed. If a person didn't solve anything, then he/she didn't even appear in final standings and wasn't considered as participant. Vasya understood that to get the maximal number of points it is not always useful to solve all the problems. Unfortunately, he understood it only after the contest was finished. Now he asks you to help him: find out what problems he had to solve to earn the maximal number of points.
Input
The first line contains an integer n (1 ≤ n ≤ 100) — the number of the suggested problems. The next line contains n space-separated integers ci ( - 100 ≤ ci ≤ 100) — the cost of the i-th task. The tasks' costs may coinсide.
Output
Print space-separated the costs of the problems that needed to be solved to get the maximal possible number of points. Do not forget, please, that it was necessary to solve at least one problem. If there are several solutions to that problem, print any of them.
Examples
Input
5
1 2 -3 3 3
Output
3 1 2 3
Input
13
100 100 100 100 100 100 100 100 100 100 100 100 100
Output
100 100 100 100 100 100 100 100 100 100 100 100 100
Input
4
-2 -2 -2 -2
Output
-2 -2 -2 -2
|
instruction
| 0
| 104,813
| 11
| 209,626
|
Tags: greedy
Correct Solution:
```
n = int(input())
costs = list(map(int, input().split()))
negative, positive = [], []
for cost in costs:
if cost < 0:
negative.append(cost)
elif cost > 1:
positive.append(cost)
negative.sort()
if len(negative) % 2 == 1:
negative = negative[:-1]
result = negative + sorted(positive)
if len(result) == 0:
result = sorted(costs)[-1:]
print(' '.join(map(str, result)))
```
|
output
| 1
| 104,813
| 11
| 209,627
|
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya has gotten interested in programming contests in TCMCF+++ rules. On the contest n problems were suggested and every problem had a cost — a certain integral number of points (perhaps, negative or even equal to zero). According to TCMCF+++ rules, only accepted problems can earn points and the overall number of points of a contestant was equal to the product of the costs of all the problems he/she had completed. If a person didn't solve anything, then he/she didn't even appear in final standings and wasn't considered as participant. Vasya understood that to get the maximal number of points it is not always useful to solve all the problems. Unfortunately, he understood it only after the contest was finished. Now he asks you to help him: find out what problems he had to solve to earn the maximal number of points.
Input
The first line contains an integer n (1 ≤ n ≤ 100) — the number of the suggested problems. The next line contains n space-separated integers ci ( - 100 ≤ ci ≤ 100) — the cost of the i-th task. The tasks' costs may coinсide.
Output
Print space-separated the costs of the problems that needed to be solved to get the maximal possible number of points. Do not forget, please, that it was necessary to solve at least one problem. If there are several solutions to that problem, print any of them.
Examples
Input
5
1 2 -3 3 3
Output
3 1 2 3
Input
13
100 100 100 100 100 100 100 100 100 100 100 100 100
Output
100 100 100 100 100 100 100 100 100 100 100 100 100
Input
4
-2 -2 -2 -2
Output
-2 -2 -2 -2
|
instruction
| 0
| 104,814
| 11
| 209,628
|
Tags: greedy
Correct Solution:
```
n=int(input())
a=list(map(int,input().split()))
b=[]
c=[]
for x in a:
if x>0:
b.append(x)
elif x<0:
c.append(x)
if len(c)%2!=0:
c=sorted(c)[:-1]
b+=c
if len(b)==0:
print(*a)
else:
print(*b)
```
|
output
| 1
| 104,814
| 11
| 209,629
|
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya has gotten interested in programming contests in TCMCF+++ rules. On the contest n problems were suggested and every problem had a cost — a certain integral number of points (perhaps, negative or even equal to zero). According to TCMCF+++ rules, only accepted problems can earn points and the overall number of points of a contestant was equal to the product of the costs of all the problems he/she had completed. If a person didn't solve anything, then he/she didn't even appear in final standings and wasn't considered as participant. Vasya understood that to get the maximal number of points it is not always useful to solve all the problems. Unfortunately, he understood it only after the contest was finished. Now he asks you to help him: find out what problems he had to solve to earn the maximal number of points.
Input
The first line contains an integer n (1 ≤ n ≤ 100) — the number of the suggested problems. The next line contains n space-separated integers ci ( - 100 ≤ ci ≤ 100) — the cost of the i-th task. The tasks' costs may coinсide.
Output
Print space-separated the costs of the problems that needed to be solved to get the maximal possible number of points. Do not forget, please, that it was necessary to solve at least one problem. If there are several solutions to that problem, print any of them.
Examples
Input
5
1 2 -3 3 3
Output
3 1 2 3
Input
13
100 100 100 100 100 100 100 100 100 100 100 100 100
Output
100 100 100 100 100 100 100 100 100 100 100 100 100
Input
4
-2 -2 -2 -2
Output
-2 -2 -2 -2
|
instruction
| 0
| 104,815
| 11
| 209,630
|
Tags: greedy
Correct Solution:
```
n = int(input())
c = list(sorted(map(int, input().split())))
neg = []
ans = []
zero = 0
for x in c:
if x > 0:
ans.append(x)
elif x < 0:
neg.append(x)
else:
zero += 1
m = len(neg) // 2
for i in range(2 * m):
ans.append(neg[i])
if len(ans) == 0 and zero > 0:
ans.append(0)
elif len(ans) == 0 and len(neg) > 0:
ans.append(neg[0])
print(" ".join(map(str, ans)))
```
|
output
| 1
| 104,815
| 11
| 209,631
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya has gotten interested in programming contests in TCMCF+++ rules. On the contest n problems were suggested and every problem had a cost — a certain integral number of points (perhaps, negative or even equal to zero). According to TCMCF+++ rules, only accepted problems can earn points and the overall number of points of a contestant was equal to the product of the costs of all the problems he/she had completed. If a person didn't solve anything, then he/she didn't even appear in final standings and wasn't considered as participant. Vasya understood that to get the maximal number of points it is not always useful to solve all the problems. Unfortunately, he understood it only after the contest was finished. Now he asks you to help him: find out what problems he had to solve to earn the maximal number of points.
Input
The first line contains an integer n (1 ≤ n ≤ 100) — the number of the suggested problems. The next line contains n space-separated integers ci ( - 100 ≤ ci ≤ 100) — the cost of the i-th task. The tasks' costs may coinсide.
Output
Print space-separated the costs of the problems that needed to be solved to get the maximal possible number of points. Do not forget, please, that it was necessary to solve at least one problem. If there are several solutions to that problem, print any of them.
Examples
Input
5
1 2 -3 3 3
Output
3 1 2 3
Input
13
100 100 100 100 100 100 100 100 100 100 100 100 100
Output
100 100 100 100 100 100 100 100 100 100 100 100 100
Input
4
-2 -2 -2 -2
Output
-2 -2 -2 -2
Submitted Solution:
```
try:
n = int(input())
arr = list(map(int, input().split()))
positive = [item for item in arr if item > 0]
negative = [item for item in arr if item < 0]
zero = [item for item in arr if item == 0]
negative.sort(reverse=True)
length = len(negative)
z_length = len(zero)
if length > 1:
if length % 2 == 0:
ans = positive + negative
print(*ans)
else:
ans = positive + negative[1:]
print(*ans)
elif length == 1:
if len(positive) > 0:
print(*positive)
elif z_length != 0:
print(0)
else:
print(*negative)
else:
if len(positive) > 0:
print(*positive)
elif z_length != 0:
print(0)
except e:
pass
```
|
instruction
| 0
| 104,816
| 11
| 209,632
|
Yes
|
output
| 1
| 104,816
| 11
| 209,633
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya has gotten interested in programming contests in TCMCF+++ rules. On the contest n problems were suggested and every problem had a cost — a certain integral number of points (perhaps, negative or even equal to zero). According to TCMCF+++ rules, only accepted problems can earn points and the overall number of points of a contestant was equal to the product of the costs of all the problems he/she had completed. If a person didn't solve anything, then he/she didn't even appear in final standings and wasn't considered as participant. Vasya understood that to get the maximal number of points it is not always useful to solve all the problems. Unfortunately, he understood it only after the contest was finished. Now he asks you to help him: find out what problems he had to solve to earn the maximal number of points.
Input
The first line contains an integer n (1 ≤ n ≤ 100) — the number of the suggested problems. The next line contains n space-separated integers ci ( - 100 ≤ ci ≤ 100) — the cost of the i-th task. The tasks' costs may coinсide.
Output
Print space-separated the costs of the problems that needed to be solved to get the maximal possible number of points. Do not forget, please, that it was necessary to solve at least one problem. If there are several solutions to that problem, print any of them.
Examples
Input
5
1 2 -3 3 3
Output
3 1 2 3
Input
13
100 100 100 100 100 100 100 100 100 100 100 100 100
Output
100 100 100 100 100 100 100 100 100 100 100 100 100
Input
4
-2 -2 -2 -2
Output
-2 -2 -2 -2
Submitted Solution:
```
import sys
input = sys.stdin.readline
'''
'''
n = int(input())
nums = list(map(int, input().split()))
nums.sort()
res = []
i = 0
while i < n:
if nums[i] < 0 and i < n - 1 and nums[i+1] < 0:
res.append(nums[i])
res.append(nums[i+1])
i += 2
elif nums[i] == 0:
i += 1
elif nums[i] > 0:
res.append(nums[i])
i += 1
else:
i += 1
if res:
print(*res)
else:
print(nums[-1])
```
|
instruction
| 0
| 104,817
| 11
| 209,634
|
Yes
|
output
| 1
| 104,817
| 11
| 209,635
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya has gotten interested in programming contests in TCMCF+++ rules. On the contest n problems were suggested and every problem had a cost — a certain integral number of points (perhaps, negative or even equal to zero). According to TCMCF+++ rules, only accepted problems can earn points and the overall number of points of a contestant was equal to the product of the costs of all the problems he/she had completed. If a person didn't solve anything, then he/she didn't even appear in final standings and wasn't considered as participant. Vasya understood that to get the maximal number of points it is not always useful to solve all the problems. Unfortunately, he understood it only after the contest was finished. Now he asks you to help him: find out what problems he had to solve to earn the maximal number of points.
Input
The first line contains an integer n (1 ≤ n ≤ 100) — the number of the suggested problems. The next line contains n space-separated integers ci ( - 100 ≤ ci ≤ 100) — the cost of the i-th task. The tasks' costs may coinсide.
Output
Print space-separated the costs of the problems that needed to be solved to get the maximal possible number of points. Do not forget, please, that it was necessary to solve at least one problem. If there are several solutions to that problem, print any of them.
Examples
Input
5
1 2 -3 3 3
Output
3 1 2 3
Input
13
100 100 100 100 100 100 100 100 100 100 100 100 100
Output
100 100 100 100 100 100 100 100 100 100 100 100 100
Input
4
-2 -2 -2 -2
Output
-2 -2 -2 -2
Submitted Solution:
```
from bisect import bisect_left as bl;n=int(input())
if n==1:
print(input())
else:
a=list(map(int,input().split()));a.sort()
if bl(a,0)%2==1:
if a[bl(a,0)-1]<0:a.remove(a[bl(a,0)-1])
q=len(a)
while 0 in a and q>1:a.remove(0);q-=1
print(*a)
```
|
instruction
| 0
| 104,818
| 11
| 209,636
|
Yes
|
output
| 1
| 104,818
| 11
| 209,637
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya has gotten interested in programming contests in TCMCF+++ rules. On the contest n problems were suggested and every problem had a cost — a certain integral number of points (perhaps, negative or even equal to zero). According to TCMCF+++ rules, only accepted problems can earn points and the overall number of points of a contestant was equal to the product of the costs of all the problems he/she had completed. If a person didn't solve anything, then he/she didn't even appear in final standings and wasn't considered as participant. Vasya understood that to get the maximal number of points it is not always useful to solve all the problems. Unfortunately, he understood it only after the contest was finished. Now he asks you to help him: find out what problems he had to solve to earn the maximal number of points.
Input
The first line contains an integer n (1 ≤ n ≤ 100) — the number of the suggested problems. The next line contains n space-separated integers ci ( - 100 ≤ ci ≤ 100) — the cost of the i-th task. The tasks' costs may coinсide.
Output
Print space-separated the costs of the problems that needed to be solved to get the maximal possible number of points. Do not forget, please, that it was necessary to solve at least one problem. If there are several solutions to that problem, print any of them.
Examples
Input
5
1 2 -3 3 3
Output
3 1 2 3
Input
13
100 100 100 100 100 100 100 100 100 100 100 100 100
Output
100 100 100 100 100 100 100 100 100 100 100 100 100
Input
4
-2 -2 -2 -2
Output
-2 -2 -2 -2
Submitted Solution:
```
n = int(input())
c = list(map(int, input().split()))
pos = 0
neg = 0
l_pos = []
l_neg = []
for item in c:
if item < 0:
neg += 1
l_neg.append(item)
elif item > 0:
pos += 1
l_pos.append(item)
if len(c) == 1 or len(set(c)) == 1 and c[0] == 0:
print(c[0])
elif len(c) == 2 and max(c) == 0:
print(0)
else:
if neg % 2 == 0:
for item in c:
if item != 0:
print(item, end = ' ')
else:
for item in l_pos:
print(item, end = ' ')
l_neg.sort()
for i in range(len(l_neg) - 1):
print(l_neg[i], end = ' ')
```
|
instruction
| 0
| 104,819
| 11
| 209,638
|
Yes
|
output
| 1
| 104,819
| 11
| 209,639
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya has gotten interested in programming contests in TCMCF+++ rules. On the contest n problems were suggested and every problem had a cost — a certain integral number of points (perhaps, negative or even equal to zero). According to TCMCF+++ rules, only accepted problems can earn points and the overall number of points of a contestant was equal to the product of the costs of all the problems he/she had completed. If a person didn't solve anything, then he/she didn't even appear in final standings and wasn't considered as participant. Vasya understood that to get the maximal number of points it is not always useful to solve all the problems. Unfortunately, he understood it only after the contest was finished. Now he asks you to help him: find out what problems he had to solve to earn the maximal number of points.
Input
The first line contains an integer n (1 ≤ n ≤ 100) — the number of the suggested problems. The next line contains n space-separated integers ci ( - 100 ≤ ci ≤ 100) — the cost of the i-th task. The tasks' costs may coinсide.
Output
Print space-separated the costs of the problems that needed to be solved to get the maximal possible number of points. Do not forget, please, that it was necessary to solve at least one problem. If there are several solutions to that problem, print any of them.
Examples
Input
5
1 2 -3 3 3
Output
3 1 2 3
Input
13
100 100 100 100 100 100 100 100 100 100 100 100 100
Output
100 100 100 100 100 100 100 100 100 100 100 100 100
Input
4
-2 -2 -2 -2
Output
-2 -2 -2 -2
Submitted Solution:
```
n = int(input())
text = list(map(int,input().split(' ')))
res = []
t = False
for i in text:
if i>0:
res.append(i)
if res == []:
for i in text:
if i<=0:
res.append(i)
if res == []:
res.append(0)
while (0 in res) and (res!=[0]):
res.remove(0)
print(' '.join(map(str,res)))
```
|
instruction
| 0
| 104,820
| 11
| 209,640
|
No
|
output
| 1
| 104,820
| 11
| 209,641
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya has gotten interested in programming contests in TCMCF+++ rules. On the contest n problems were suggested and every problem had a cost — a certain integral number of points (perhaps, negative or even equal to zero). According to TCMCF+++ rules, only accepted problems can earn points and the overall number of points of a contestant was equal to the product of the costs of all the problems he/she had completed. If a person didn't solve anything, then he/she didn't even appear in final standings and wasn't considered as participant. Vasya understood that to get the maximal number of points it is not always useful to solve all the problems. Unfortunately, he understood it only after the contest was finished. Now he asks you to help him: find out what problems he had to solve to earn the maximal number of points.
Input
The first line contains an integer n (1 ≤ n ≤ 100) — the number of the suggested problems. The next line contains n space-separated integers ci ( - 100 ≤ ci ≤ 100) — the cost of the i-th task. The tasks' costs may coinсide.
Output
Print space-separated the costs of the problems that needed to be solved to get the maximal possible number of points. Do not forget, please, that it was necessary to solve at least one problem. If there are several solutions to that problem, print any of them.
Examples
Input
5
1 2 -3 3 3
Output
3 1 2 3
Input
13
100 100 100 100 100 100 100 100 100 100 100 100 100
Output
100 100 100 100 100 100 100 100 100 100 100 100 100
Input
4
-2 -2 -2 -2
Output
-2 -2 -2 -2
Submitted Solution:
```
import sys
n=int(input())
a = list(map(int,input().strip().split()))[:n]
pos=0
neg=0
zero=0
for i in a :
if i>0:
pos=pos+1
if i<0:
neg=neg+1
if i==0:
zero=zero+1
if neg==n:
for i in a:
print(i," ",end =" ")
sys.exit()
if zero==n:
for i in a:
print(i," ",end =" ")
sys.exit()
if pos==n:
for i in a:
print(i," ",end =" ")
sys.exit()
if neg+zero==n:
for i in a:
if i>=0:
print(i," ",end =" ")
for i in a:
if i>0:
print(i," ",end =" ")
```
|
instruction
| 0
| 104,821
| 11
| 209,642
|
No
|
output
| 1
| 104,821
| 11
| 209,643
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.