message stringlengths 2 30.5k | message_type stringclasses 2 values | message_id int64 0 1 | conversation_id int64 237 109k | cluster float64 10 10 | __index_level_0__ int64 474 217k |
|---|---|---|---|---|---|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Nothing has changed since the last round. Dima and Inna still love each other and want to be together. They've made a deal with Seryozha and now they need to make a deal with the dorm guards...
There are four guardposts in Dima's dorm. Each post contains two guards (in Russia they are usually elderly women). You can bribe a guard by a chocolate bar or a box of juice. For each guard you know the minimum price of the chocolate bar she can accept as a gift and the minimum price of the box of juice she can accept as a gift. If a chocolate bar for some guard costs less than the minimum chocolate bar price for this guard is, or if a box of juice for some guard costs less than the minimum box of juice price for this guard is, then the guard doesn't accept such a gift.
In order to pass through a guardpost, one needs to bribe both guards.
The shop has an unlimited amount of juice and chocolate of any price starting with 1. Dima wants to choose some guardpost, buy one gift for each guard from the guardpost and spend exactly n rubles on it.
Help him choose a post through which he can safely sneak Inna or otherwise say that this is impossible. Mind you, Inna would be very sorry to hear that!
Input
The first line of the input contains integer n (1 ≤ n ≤ 105) — the money Dima wants to spend. Then follow four lines describing the guardposts. Each line contains four integers a, b, c, d (1 ≤ a, b, c, d ≤ 105) — the minimum price of the chocolate and the minimum price of the juice for the first guard and the minimum price of the chocolate and the minimum price of the juice for the second guard, correspondingly.
Output
In a single line of the output print three space-separated integers: the number of the guardpost, the cost of the first present and the cost of the second present. If there is no guardpost Dima can sneak Inna through at such conditions, print -1 in a single line.
The guardposts are numbered from 1 to 4 according to the order given in the input.
If there are multiple solutions, you can print any of them.
Examples
Input
10
5 6 5 6
6 6 7 7
5 8 6 6
9 9 9 9
Output
1 5 5
Input
10
6 6 6 6
7 7 7 7
4 4 4 4
8 8 8 8
Output
3 4 6
Input
5
3 3 3 3
3 3 3 3
3 3 3 3
3 3 3 3
Output
-1
Note
Explanation of the first example.
The only way to spend 10 rubles to buy the gifts that won't be less than the minimum prices is to buy two 5 ruble chocolates to both guards from the first guardpost.
Explanation of the second example.
Dima needs 12 rubles for the first guardpost, 14 for the second one, 16 for the fourth one. So the only guardpost we can sneak through is the third one. So, Dima can buy 4 ruble chocolate for the first guard and 6 ruble juice of the second guard.
Submitted Solution:
```
def search_guardports(guardports):
for i in range(4):
if guardports[i][0] > guardports[i][1]:
p1 = guardports[i][1]
else:
p1 = guardports[i][0]
if guardports[i][2] > guardports[i][3]:
p2 = guardports[i][3]
else:
p2 = guardports[i][2]
if p1 + p2 <= n:
return [i + 1, p1, p2]
return []
n = int(input())
guardports = []
for _ in range(4):
guardports.append([int(x) for x in input().split()])
res = search_guardports(guardports)
if res:
print(" ".join(map(str, res)))
else:
print(-1)
``` | instruction | 0 | 86,981 | 10 | 173,962 |
No | output | 1 | 86,981 | 10 | 173,963 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Nothing has changed since the last round. Dima and Inna still love each other and want to be together. They've made a deal with Seryozha and now they need to make a deal with the dorm guards...
There are four guardposts in Dima's dorm. Each post contains two guards (in Russia they are usually elderly women). You can bribe a guard by a chocolate bar or a box of juice. For each guard you know the minimum price of the chocolate bar she can accept as a gift and the minimum price of the box of juice she can accept as a gift. If a chocolate bar for some guard costs less than the minimum chocolate bar price for this guard is, or if a box of juice for some guard costs less than the minimum box of juice price for this guard is, then the guard doesn't accept such a gift.
In order to pass through a guardpost, one needs to bribe both guards.
The shop has an unlimited amount of juice and chocolate of any price starting with 1. Dima wants to choose some guardpost, buy one gift for each guard from the guardpost and spend exactly n rubles on it.
Help him choose a post through which he can safely sneak Inna or otherwise say that this is impossible. Mind you, Inna would be very sorry to hear that!
Input
The first line of the input contains integer n (1 ≤ n ≤ 105) — the money Dima wants to spend. Then follow four lines describing the guardposts. Each line contains four integers a, b, c, d (1 ≤ a, b, c, d ≤ 105) — the minimum price of the chocolate and the minimum price of the juice for the first guard and the minimum price of the chocolate and the minimum price of the juice for the second guard, correspondingly.
Output
In a single line of the output print three space-separated integers: the number of the guardpost, the cost of the first present and the cost of the second present. If there is no guardpost Dima can sneak Inna through at such conditions, print -1 in a single line.
The guardposts are numbered from 1 to 4 according to the order given in the input.
If there are multiple solutions, you can print any of them.
Examples
Input
10
5 6 5 6
6 6 7 7
5 8 6 6
9 9 9 9
Output
1 5 5
Input
10
6 6 6 6
7 7 7 7
4 4 4 4
8 8 8 8
Output
3 4 6
Input
5
3 3 3 3
3 3 3 3
3 3 3 3
3 3 3 3
Output
-1
Note
Explanation of the first example.
The only way to spend 10 rubles to buy the gifts that won't be less than the minimum prices is to buy two 5 ruble chocolates to both guards from the first guardpost.
Explanation of the second example.
Dima needs 12 rubles for the first guardpost, 14 for the second one, 16 for the fourth one. So the only guardpost we can sneak through is the third one. So, Dima can buy 4 ruble chocolate for the first guard and 6 ruble juice of the second guard.
Submitted Solution:
```
import sys
def readInputs():
global budget, prices
budget = int(f.readline())
prices = []
for _ in range(4):
(a1,b1,a2,b2) = map(int,f.readline().split())
prices += [((a1,b1),(a2,b2))]
#print(budget)
#print(prices)
def isPartOk(a,b):
for i in range(4):
((a1,b1),(a2,b2)) = prices[i]
#print(a,((a1,b1),(a2,b2)))
if(((a >= a1 or a >= b1) and (b >= a2 or b >= b2)) or (b >= a1 or b >= b1) and (a >= a2 or a >= b2)):
return i+1
return -1
def solve():
for a in range(1,budget//2+1):
res = isPartOk(a,budget-a)
if(res!=-1):
return ' '.join([str(res),str(a),str(budget-a)])
return -1
def main():
global f
f = sys.stdin
readInputs()
print(solve())
main()
``` | instruction | 0 | 86,982 | 10 | 173,964 |
No | output | 1 | 86,982 | 10 | 173,965 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Nothing has changed since the last round. Dima and Inna still love each other and want to be together. They've made a deal with Seryozha and now they need to make a deal with the dorm guards...
There are four guardposts in Dima's dorm. Each post contains two guards (in Russia they are usually elderly women). You can bribe a guard by a chocolate bar or a box of juice. For each guard you know the minimum price of the chocolate bar she can accept as a gift and the minimum price of the box of juice she can accept as a gift. If a chocolate bar for some guard costs less than the minimum chocolate bar price for this guard is, or if a box of juice for some guard costs less than the minimum box of juice price for this guard is, then the guard doesn't accept such a gift.
In order to pass through a guardpost, one needs to bribe both guards.
The shop has an unlimited amount of juice and chocolate of any price starting with 1. Dima wants to choose some guardpost, buy one gift for each guard from the guardpost and spend exactly n rubles on it.
Help him choose a post through which he can safely sneak Inna or otherwise say that this is impossible. Mind you, Inna would be very sorry to hear that!
Input
The first line of the input contains integer n (1 ≤ n ≤ 105) — the money Dima wants to spend. Then follow four lines describing the guardposts. Each line contains four integers a, b, c, d (1 ≤ a, b, c, d ≤ 105) — the minimum price of the chocolate and the minimum price of the juice for the first guard and the minimum price of the chocolate and the minimum price of the juice for the second guard, correspondingly.
Output
In a single line of the output print three space-separated integers: the number of the guardpost, the cost of the first present and the cost of the second present. If there is no guardpost Dima can sneak Inna through at such conditions, print -1 in a single line.
The guardposts are numbered from 1 to 4 according to the order given in the input.
If there are multiple solutions, you can print any of them.
Examples
Input
10
5 6 5 6
6 6 7 7
5 8 6 6
9 9 9 9
Output
1 5 5
Input
10
6 6 6 6
7 7 7 7
4 4 4 4
8 8 8 8
Output
3 4 6
Input
5
3 3 3 3
3 3 3 3
3 3 3 3
3 3 3 3
Output
-1
Note
Explanation of the first example.
The only way to spend 10 rubles to buy the gifts that won't be less than the minimum prices is to buy two 5 ruble chocolates to both guards from the first guardpost.
Explanation of the second example.
Dima needs 12 rubles for the first guardpost, 14 for the second one, 16 for the fourth one. So the only guardpost we can sneak through is the third one. So, Dima can buy 4 ruble chocolate for the first guard and 6 ruble juice of the second guard.
Submitted Solution:
```
n = int(input())
already = False
for i in range(4):
string = input().split()
numList = list(map(int, string))
first = numList[0:2]
second = numList[2:4]
minFirst = min(first)
minSecond = min(second)
if(already == False):
if((minFirst + minSecond) <= n):
print(i+1, minFirst, 10 - minSecond)
already = True
if(already == False):
print(-1)
``` | instruction | 0 | 86,983 | 10 | 173,966 |
No | output | 1 | 86,983 | 10 | 173,967 |
Provide a correct Python 3 solution for this coding contest problem.
There is a hotel with the following accommodation fee:
* X yen (the currency of Japan) per night, for the first K nights
* Y yen per night, for the (K+1)-th and subsequent nights
Tak is staying at this hotel for N consecutive nights. Find his total accommodation fee.
Constraints
* 1 \leq N, K \leq 10000
* 1 \leq Y < X \leq 10000
* N,\,K,\,X,\,Y are integers.
Input
The input is given from Standard Input in the following format:
N
K
X
Y
Output
Print Tak's total accommodation fee.
Examples
Input
5
3
10000
9000
Output
48000
Input
2
3
10000
9000
Output
20000 | instruction | 0 | 87,408 | 10 | 174,816 |
"Correct Solution:
```
N, K, X, Y = (int(input()) for i in range(4))
print(X*K+Y*(N-K) if N>K else X*N)
``` | output | 1 | 87,408 | 10 | 174,817 |
Provide a correct Python 3 solution for this coding contest problem.
There is a hotel with the following accommodation fee:
* X yen (the currency of Japan) per night, for the first K nights
* Y yen per night, for the (K+1)-th and subsequent nights
Tak is staying at this hotel for N consecutive nights. Find his total accommodation fee.
Constraints
* 1 \leq N, K \leq 10000
* 1 \leq Y < X \leq 10000
* N,\,K,\,X,\,Y are integers.
Input
The input is given from Standard Input in the following format:
N
K
X
Y
Output
Print Tak's total accommodation fee.
Examples
Input
5
3
10000
9000
Output
48000
Input
2
3
10000
9000
Output
20000 | instruction | 0 | 87,409 | 10 | 174,818 |
"Correct Solution:
```
n, k, x, y = [int(input()) for i in range(4)]
print(x * min(n, k) + y * max(n - k, 0))
``` | output | 1 | 87,409 | 10 | 174,819 |
Provide a correct Python 3 solution for this coding contest problem.
There is a hotel with the following accommodation fee:
* X yen (the currency of Japan) per night, for the first K nights
* Y yen per night, for the (K+1)-th and subsequent nights
Tak is staying at this hotel for N consecutive nights. Find his total accommodation fee.
Constraints
* 1 \leq N, K \leq 10000
* 1 \leq Y < X \leq 10000
* N,\,K,\,X,\,Y are integers.
Input
The input is given from Standard Input in the following format:
N
K
X
Y
Output
Print Tak's total accommodation fee.
Examples
Input
5
3
10000
9000
Output
48000
Input
2
3
10000
9000
Output
20000 | instruction | 0 | 87,410 | 10 | 174,820 |
"Correct Solution:
```
n,k,x,y = [int(input()) for i in range(4)]
ans = min(k,n)*x+max(0,n-k)*y
print(ans)
``` | output | 1 | 87,410 | 10 | 174,821 |
Provide a correct Python 3 solution for this coding contest problem.
There is a hotel with the following accommodation fee:
* X yen (the currency of Japan) per night, for the first K nights
* Y yen per night, for the (K+1)-th and subsequent nights
Tak is staying at this hotel for N consecutive nights. Find his total accommodation fee.
Constraints
* 1 \leq N, K \leq 10000
* 1 \leq Y < X \leq 10000
* N,\,K,\,X,\,Y are integers.
Input
The input is given from Standard Input in the following format:
N
K
X
Y
Output
Print Tak's total accommodation fee.
Examples
Input
5
3
10000
9000
Output
48000
Input
2
3
10000
9000
Output
20000 | instruction | 0 | 87,411 | 10 | 174,822 |
"Correct Solution:
```
n,k,x,y = (int(input()) for _ in range(4))
print(min(n,k)*x + y*max(n-k,0))
``` | output | 1 | 87,411 | 10 | 174,823 |
Provide a correct Python 3 solution for this coding contest problem.
There is a hotel with the following accommodation fee:
* X yen (the currency of Japan) per night, for the first K nights
* Y yen per night, for the (K+1)-th and subsequent nights
Tak is staying at this hotel for N consecutive nights. Find his total accommodation fee.
Constraints
* 1 \leq N, K \leq 10000
* 1 \leq Y < X \leq 10000
* N,\,K,\,X,\,Y are integers.
Input
The input is given from Standard Input in the following format:
N
K
X
Y
Output
Print Tak's total accommodation fee.
Examples
Input
5
3
10000
9000
Output
48000
Input
2
3
10000
9000
Output
20000 | instruction | 0 | 87,412 | 10 | 174,824 |
"Correct Solution:
```
n,k,x,y=[int(input()) for i in range(4)]
if n>k:
print(k*x+(n-k)*y)
else:
print(n*x)
``` | output | 1 | 87,412 | 10 | 174,825 |
Provide a correct Python 3 solution for this coding contest problem.
There is a hotel with the following accommodation fee:
* X yen (the currency of Japan) per night, for the first K nights
* Y yen per night, for the (K+1)-th and subsequent nights
Tak is staying at this hotel for N consecutive nights. Find his total accommodation fee.
Constraints
* 1 \leq N, K \leq 10000
* 1 \leq Y < X \leq 10000
* N,\,K,\,X,\,Y are integers.
Input
The input is given from Standard Input in the following format:
N
K
X
Y
Output
Print Tak's total accommodation fee.
Examples
Input
5
3
10000
9000
Output
48000
Input
2
3
10000
9000
Output
20000 | instruction | 0 | 87,413 | 10 | 174,826 |
"Correct Solution:
```
N, K, X, Y = [int(input()) for x in range(4)]
print(min(K, N) * X + max(N - K, 0) * Y)
``` | output | 1 | 87,413 | 10 | 174,827 |
Provide a correct Python 3 solution for this coding contest problem.
There is a hotel with the following accommodation fee:
* X yen (the currency of Japan) per night, for the first K nights
* Y yen per night, for the (K+1)-th and subsequent nights
Tak is staying at this hotel for N consecutive nights. Find his total accommodation fee.
Constraints
* 1 \leq N, K \leq 10000
* 1 \leq Y < X \leq 10000
* N,\,K,\,X,\,Y are integers.
Input
The input is given from Standard Input in the following format:
N
K
X
Y
Output
Print Tak's total accommodation fee.
Examples
Input
5
3
10000
9000
Output
48000
Input
2
3
10000
9000
Output
20000 | instruction | 0 | 87,414 | 10 | 174,828 |
"Correct Solution:
```
[n,k,x,y]=[int(input())for _ in range(4)];print(min(n,k)*x+(max(n,k)-k)*y)
``` | output | 1 | 87,414 | 10 | 174,829 |
Provide a correct Python 3 solution for this coding contest problem.
There is a hotel with the following accommodation fee:
* X yen (the currency of Japan) per night, for the first K nights
* Y yen per night, for the (K+1)-th and subsequent nights
Tak is staying at this hotel for N consecutive nights. Find his total accommodation fee.
Constraints
* 1 \leq N, K \leq 10000
* 1 \leq Y < X \leq 10000
* N,\,K,\,X,\,Y are integers.
Input
The input is given from Standard Input in the following format:
N
K
X
Y
Output
Print Tak's total accommodation fee.
Examples
Input
5
3
10000
9000
Output
48000
Input
2
3
10000
9000
Output
20000 | instruction | 0 | 87,415 | 10 | 174,830 |
"Correct Solution:
```
N,K,X,Y=[int(input()) for _ in [0]*4]
print(min(N,K)*X+max(0,N-K)*Y)
``` | output | 1 | 87,415 | 10 | 174,831 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is a hotel with the following accommodation fee:
* X yen (the currency of Japan) per night, for the first K nights
* Y yen per night, for the (K+1)-th and subsequent nights
Tak is staying at this hotel for N consecutive nights. Find his total accommodation fee.
Constraints
* 1 \leq N, K \leq 10000
* 1 \leq Y < X \leq 10000
* N,\,K,\,X,\,Y are integers.
Input
The input is given from Standard Input in the following format:
N
K
X
Y
Output
Print Tak's total accommodation fee.
Examples
Input
5
3
10000
9000
Output
48000
Input
2
3
10000
9000
Output
20000
Submitted Solution:
```
n, k, x, y = [int(input()) for _ in range(4)]
print(n*x-(x-y)*max(n-k, 0))
``` | instruction | 0 | 87,416 | 10 | 174,832 |
Yes | output | 1 | 87,416 | 10 | 174,833 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is a hotel with the following accommodation fee:
* X yen (the currency of Japan) per night, for the first K nights
* Y yen per night, for the (K+1)-th and subsequent nights
Tak is staying at this hotel for N consecutive nights. Find his total accommodation fee.
Constraints
* 1 \leq N, K \leq 10000
* 1 \leq Y < X \leq 10000
* N,\,K,\,X,\,Y are integers.
Input
The input is given from Standard Input in the following format:
N
K
X
Y
Output
Print Tak's total accommodation fee.
Examples
Input
5
3
10000
9000
Output
48000
Input
2
3
10000
9000
Output
20000
Submitted Solution:
```
N,K,X,Y=map(int,open(0).read().split())
print(X*min(N,K)+Y*(N-min(N,K)))
``` | instruction | 0 | 87,417 | 10 | 174,834 |
Yes | output | 1 | 87,417 | 10 | 174,835 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is a hotel with the following accommodation fee:
* X yen (the currency of Japan) per night, for the first K nights
* Y yen per night, for the (K+1)-th and subsequent nights
Tak is staying at this hotel for N consecutive nights. Find his total accommodation fee.
Constraints
* 1 \leq N, K \leq 10000
* 1 \leq Y < X \leq 10000
* N,\,K,\,X,\,Y are integers.
Input
The input is given from Standard Input in the following format:
N
K
X
Y
Output
Print Tak's total accommodation fee.
Examples
Input
5
3
10000
9000
Output
48000
Input
2
3
10000
9000
Output
20000
Submitted Solution:
```
n, k, x, y = map(int, [input() for i in range(4)])
print( min(n, k)*x + max(n-k, 0)*y )
``` | instruction | 0 | 87,418 | 10 | 174,836 |
Yes | output | 1 | 87,418 | 10 | 174,837 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is a hotel with the following accommodation fee:
* X yen (the currency of Japan) per night, for the first K nights
* Y yen per night, for the (K+1)-th and subsequent nights
Tak is staying at this hotel for N consecutive nights. Find his total accommodation fee.
Constraints
* 1 \leq N, K \leq 10000
* 1 \leq Y < X \leq 10000
* N,\,K,\,X,\,Y are integers.
Input
The input is given from Standard Input in the following format:
N
K
X
Y
Output
Print Tak's total accommodation fee.
Examples
Input
5
3
10000
9000
Output
48000
Input
2
3
10000
9000
Output
20000
Submitted Solution:
```
a,b,c,d=[int(input()) for i in range(4)]
if a<b:
print(a*c)
else:
print(b*c+(a-b)*d)
``` | instruction | 0 | 87,419 | 10 | 174,838 |
Yes | output | 1 | 87,419 | 10 | 174,839 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is a hotel with the following accommodation fee:
* X yen (the currency of Japan) per night, for the first K nights
* Y yen per night, for the (K+1)-th and subsequent nights
Tak is staying at this hotel for N consecutive nights. Find his total accommodation fee.
Constraints
* 1 \leq N, K \leq 10000
* 1 \leq Y < X \leq 10000
* N,\,K,\,X,\,Y are integers.
Input
The input is given from Standard Input in the following format:
N
K
X
Y
Output
Print Tak's total accommodation fee.
Examples
Input
5
3
10000
9000
Output
48000
Input
2
3
10000
9000
Output
20000
Submitted Solution:
```
N, K, X, Y, = map(int, input().split())
# 高橋くんの宿泊数 N
# 宿泊費が変わる K
# 初期宿泊費 X
# K+1以降の宿泊費 Y
# subは宿泊数の超過分
sub = N - K
# もしNよりKが大きい場合、そのまま計算する
if N < K:
answer = N * X
print(answer)
# KよりNが大きい場合 K * X + (N - K) * Y
elif K < N:
answer = K * X + sub * Y
print(answer)
``` | instruction | 0 | 87,420 | 10 | 174,840 |
No | output | 1 | 87,420 | 10 | 174,841 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is a hotel with the following accommodation fee:
* X yen (the currency of Japan) per night, for the first K nights
* Y yen per night, for the (K+1)-th and subsequent nights
Tak is staying at this hotel for N consecutive nights. Find his total accommodation fee.
Constraints
* 1 \leq N, K \leq 10000
* 1 \leq Y < X \leq 10000
* N,\,K,\,X,\,Y are integers.
Input
The input is given from Standard Input in the following format:
N
K
X
Y
Output
Print Tak's total accommodation fee.
Examples
Input
5
3
10000
9000
Output
48000
Input
2
3
10000
9000
Output
20000
Submitted Solution:
```
n=int(input())
k=int(input())
x=int(input())
y=int(input())
if n>k:
kane=k*x+(n-k)*y
else:
kane=k*x
print(kane)
``` | instruction | 0 | 87,421 | 10 | 174,842 |
No | output | 1 | 87,421 | 10 | 174,843 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is a hotel with the following accommodation fee:
* X yen (the currency of Japan) per night, for the first K nights
* Y yen per night, for the (K+1)-th and subsequent nights
Tak is staying at this hotel for N consecutive nights. Find his total accommodation fee.
Constraints
* 1 \leq N, K \leq 10000
* 1 \leq Y < X \leq 10000
* N,\,K,\,X,\,Y are integers.
Input
The input is given from Standard Input in the following format:
N
K
X
Y
Output
Print Tak's total accommodation fee.
Examples
Input
5
3
10000
9000
Output
48000
Input
2
3
10000
9000
Output
20000
Submitted Solution:
```
n=int(input())
k=int(input())
x=int(input())
y=int(input())
if n>k:
print(x+(n-k)*y)
else:
print(x)
``` | instruction | 0 | 87,422 | 10 | 174,844 |
No | output | 1 | 87,422 | 10 | 174,845 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is a hotel with the following accommodation fee:
* X yen (the currency of Japan) per night, for the first K nights
* Y yen per night, for the (K+1)-th and subsequent nights
Tak is staying at this hotel for N consecutive nights. Find his total accommodation fee.
Constraints
* 1 \leq N, K \leq 10000
* 1 \leq Y < X \leq 10000
* N,\,K,\,X,\,Y are integers.
Input
The input is given from Standard Input in the following format:
N
K
X
Y
Output
Print Tak's total accommodation fee.
Examples
Input
5
3
10000
9000
Output
48000
Input
2
3
10000
9000
Output
20000
Submitted Solution:
```
N, K, X, Y = map(int, input().split())
print(X * K + (N - K) * Y)
``` | instruction | 0 | 87,423 | 10 | 174,846 |
No | output | 1 | 87,423 | 10 | 174,847 |
Provide a correct Python 3 solution for this coding contest problem.
You have $N$ items that you want to put them into a knapsack of capacity $W$. Item $i$ ($1 \le i \le N$) has weight $w_i$ and value $v_i$ for the weight.
When you put some items into the knapsack, the following conditions must be satisfied:
* The total value of the items is as large as possible.
* The total weight of the selected items is at most $W$.
* You can break some items if you want. If you put $w'$($0 \le w' \le w_i$) of item $i$, its value becomes $\displaystyle v_i \times \frac{w'}{w_i}.$
Find the maximum total value of items in the knapsack.
Constraints
* $1 \le N \le 10^5$
* $1 \le W \le 10^9$
* $1 \le v_i \le 10^9 (1 \le i \le N)$
* $1 \le w_i \le 10^9 (1 \le i \le N)$
Input
$N$ $W$
$v_1$ $w_1$
$v_2$ $w_2$
:
$v_N$ $w_N$
The first line consists of the integers $N$ and $W$. In the following $N$ lines, the value and weight of the $i$-th item are given.
Output
Print the maximum total value of the items in a line. The output must not contain an error greater than $10^{-6}$.
Examples
Input
3 50
60 10
100 20
120 30
Output
240
Input
3 50
60 13
100 23
120 33
Output
210.90909091
Input
1 100
100000 100000
Output
100 | instruction | 0 | 88,312 | 10 | 176,624 |
"Correct Solution:
```
if __name__ == "__main__":
N, W = map(lambda x: int(x), input().split())
items = [[0, 0] for _ in range(N)]
for i in range(N):
items[i] = list(map(lambda x: int(x), input().split()))
items = sorted(items, key=lambda x: - x[0] / x[1])
total_value = 0.0
total_weight = 0.0
for (v, w) in items:
if total_weight + w <= W:
total_weight += w
total_value += v
if W == total_weight:
break
else:
rest_weight = W - total_weight
total_value += (v / w) * rest_weight
break
print(f"{total_value:.6f}")
``` | output | 1 | 88,312 | 10 | 176,625 |
Provide a correct Python 3 solution for this coding contest problem.
You have $N$ items that you want to put them into a knapsack of capacity $W$. Item $i$ ($1 \le i \le N$) has weight $w_i$ and value $v_i$ for the weight.
When you put some items into the knapsack, the following conditions must be satisfied:
* The total value of the items is as large as possible.
* The total weight of the selected items is at most $W$.
* You can break some items if you want. If you put $w'$($0 \le w' \le w_i$) of item $i$, its value becomes $\displaystyle v_i \times \frac{w'}{w_i}.$
Find the maximum total value of items in the knapsack.
Constraints
* $1 \le N \le 10^5$
* $1 \le W \le 10^9$
* $1 \le v_i \le 10^9 (1 \le i \le N)$
* $1 \le w_i \le 10^9 (1 \le i \le N)$
Input
$N$ $W$
$v_1$ $w_1$
$v_2$ $w_2$
:
$v_N$ $w_N$
The first line consists of the integers $N$ and $W$. In the following $N$ lines, the value and weight of the $i$-th item are given.
Output
Print the maximum total value of the items in a line. The output must not contain an error greater than $10^{-6}$.
Examples
Input
3 50
60 10
100 20
120 30
Output
240
Input
3 50
60 13
100 23
120 33
Output
210.90909091
Input
1 100
100000 100000
Output
100 | instruction | 0 | 88,313 | 10 | 176,626 |
"Correct Solution:
```
N, W = map(int, input().split())
V = [None]*N
ans = 0
for i in range(N):
v, w = map(int, input().split())
V[i] = [v/w, w]
V.sort(reverse=True)
for v, w in V:
if W > w:
W -= w
ans += v*w
else:
ans += v*W
break
print(ans)
``` | output | 1 | 88,313 | 10 | 176,627 |
Provide a correct Python 3 solution for this coding contest problem.
You have $N$ items that you want to put them into a knapsack of capacity $W$. Item $i$ ($1 \le i \le N$) has weight $w_i$ and value $v_i$ for the weight.
When you put some items into the knapsack, the following conditions must be satisfied:
* The total value of the items is as large as possible.
* The total weight of the selected items is at most $W$.
* You can break some items if you want. If you put $w'$($0 \le w' \le w_i$) of item $i$, its value becomes $\displaystyle v_i \times \frac{w'}{w_i}.$
Find the maximum total value of items in the knapsack.
Constraints
* $1 \le N \le 10^5$
* $1 \le W \le 10^9$
* $1 \le v_i \le 10^9 (1 \le i \le N)$
* $1 \le w_i \le 10^9 (1 \le i \le N)$
Input
$N$ $W$
$v_1$ $w_1$
$v_2$ $w_2$
:
$v_N$ $w_N$
The first line consists of the integers $N$ and $W$. In the following $N$ lines, the value and weight of the $i$-th item are given.
Output
Print the maximum total value of the items in a line. The output must not contain an error greater than $10^{-6}$.
Examples
Input
3 50
60 10
100 20
120 30
Output
240
Input
3 50
60 13
100 23
120 33
Output
210.90909091
Input
1 100
100000 100000
Output
100 | instruction | 0 | 88,314 | 10 | 176,628 |
"Correct Solution:
```
readline = open(0).readline
N, W = map(int, readline().split())
R = []
for i in range(N):
v, w = map(int, readline().split())
R.append((v / w, v, w))
R.sort(reverse = 1)
ans = 0
for _, v, w, in R:
c = min(w, W)
W -= c
ans += c * v / w
open(1, 'w').write("%.010f\n" % ans)
``` | output | 1 | 88,314 | 10 | 176,629 |
Provide a correct Python 3 solution for this coding contest problem.
You have $N$ items that you want to put them into a knapsack of capacity $W$. Item $i$ ($1 \le i \le N$) has weight $w_i$ and value $v_i$ for the weight.
When you put some items into the knapsack, the following conditions must be satisfied:
* The total value of the items is as large as possible.
* The total weight of the selected items is at most $W$.
* You can break some items if you want. If you put $w'$($0 \le w' \le w_i$) of item $i$, its value becomes $\displaystyle v_i \times \frac{w'}{w_i}.$
Find the maximum total value of items in the knapsack.
Constraints
* $1 \le N \le 10^5$
* $1 \le W \le 10^9$
* $1 \le v_i \le 10^9 (1 \le i \le N)$
* $1 \le w_i \le 10^9 (1 \le i \le N)$
Input
$N$ $W$
$v_1$ $w_1$
$v_2$ $w_2$
:
$v_N$ $w_N$
The first line consists of the integers $N$ and $W$. In the following $N$ lines, the value and weight of the $i$-th item are given.
Output
Print the maximum total value of the items in a line. The output must not contain an error greater than $10^{-6}$.
Examples
Input
3 50
60 10
100 20
120 30
Output
240
Input
3 50
60 13
100 23
120 33
Output
210.90909091
Input
1 100
100000 100000
Output
100 | instruction | 0 | 88,315 | 10 | 176,630 |
"Correct Solution:
```
# -*- coding: utf-8 -*-
"""
Greedy algorithms - Fractional Knapsack Problem
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_15_B&lang=jp
"""
N, W = map(int, input().split())
items = []
for _ in range(N):
v, w = map(int, input().split())
items.append((v/w, v, w))
items.sort()
ans = 0
while W > 0 and items:
r, v, w = items.pop()
if W >= w:
W -= w
ans += v
else:
ans += v * W / w
W = 0
print(ans)
``` | output | 1 | 88,315 | 10 | 176,631 |
Provide a correct Python 3 solution for this coding contest problem.
You have $N$ items that you want to put them into a knapsack of capacity $W$. Item $i$ ($1 \le i \le N$) has weight $w_i$ and value $v_i$ for the weight.
When you put some items into the knapsack, the following conditions must be satisfied:
* The total value of the items is as large as possible.
* The total weight of the selected items is at most $W$.
* You can break some items if you want. If you put $w'$($0 \le w' \le w_i$) of item $i$, its value becomes $\displaystyle v_i \times \frac{w'}{w_i}.$
Find the maximum total value of items in the knapsack.
Constraints
* $1 \le N \le 10^5$
* $1 \le W \le 10^9$
* $1 \le v_i \le 10^9 (1 \le i \le N)$
* $1 \le w_i \le 10^9 (1 \le i \le N)$
Input
$N$ $W$
$v_1$ $w_1$
$v_2$ $w_2$
:
$v_N$ $w_N$
The first line consists of the integers $N$ and $W$. In the following $N$ lines, the value and weight of the $i$-th item are given.
Output
Print the maximum total value of the items in a line. The output must not contain an error greater than $10^{-6}$.
Examples
Input
3 50
60 10
100 20
120 30
Output
240
Input
3 50
60 13
100 23
120 33
Output
210.90909091
Input
1 100
100000 100000
Output
100 | instruction | 0 | 88,316 | 10 | 176,632 |
"Correct Solution:
```
import sys
n, W = map(int, sys.stdin.readline().split())
val = []
for i in range(n):
val.append(list(map(int, sys.stdin.readline().split())))
total=0
for vv in sorted(val, key=lambda x:x[0]/x[1], reverse=True):
if W>=vv[1]: # 50 > 10
W -= vv[1]
total += vv[0]
else:
total += W*vv[0]/vv[1]
break
print(total)
``` | output | 1 | 88,316 | 10 | 176,633 |
Provide a correct Python 3 solution for this coding contest problem.
You have $N$ items that you want to put them into a knapsack of capacity $W$. Item $i$ ($1 \le i \le N$) has weight $w_i$ and value $v_i$ for the weight.
When you put some items into the knapsack, the following conditions must be satisfied:
* The total value of the items is as large as possible.
* The total weight of the selected items is at most $W$.
* You can break some items if you want. If you put $w'$($0 \le w' \le w_i$) of item $i$, its value becomes $\displaystyle v_i \times \frac{w'}{w_i}.$
Find the maximum total value of items in the knapsack.
Constraints
* $1 \le N \le 10^5$
* $1 \le W \le 10^9$
* $1 \le v_i \le 10^9 (1 \le i \le N)$
* $1 \le w_i \le 10^9 (1 \le i \le N)$
Input
$N$ $W$
$v_1$ $w_1$
$v_2$ $w_2$
:
$v_N$ $w_N$
The first line consists of the integers $N$ and $W$. In the following $N$ lines, the value and weight of the $i$-th item are given.
Output
Print the maximum total value of the items in a line. The output must not contain an error greater than $10^{-6}$.
Examples
Input
3 50
60 10
100 20
120 30
Output
240
Input
3 50
60 13
100 23
120 33
Output
210.90909091
Input
1 100
100000 100000
Output
100 | instruction | 0 | 88,317 | 10 | 176,634 |
"Correct Solution:
```
readline = open(0).readline
N, W = map(int, readline().split())
R = []
for i in range(N):
v, w = map(int, readline().split())
R.append((v/w, v, w))
R.sort(reverse=1)
ans = 0
for _, v, w in R:
c = min(w, W)
W -= c
ans += c * v / w
open(1, 'w').write("%.010f\n" % ans)
``` | output | 1 | 88,317 | 10 | 176,635 |
Provide a correct Python 3 solution for this coding contest problem.
You have $N$ items that you want to put them into a knapsack of capacity $W$. Item $i$ ($1 \le i \le N$) has weight $w_i$ and value $v_i$ for the weight.
When you put some items into the knapsack, the following conditions must be satisfied:
* The total value of the items is as large as possible.
* The total weight of the selected items is at most $W$.
* You can break some items if you want. If you put $w'$($0 \le w' \le w_i$) of item $i$, its value becomes $\displaystyle v_i \times \frac{w'}{w_i}.$
Find the maximum total value of items in the knapsack.
Constraints
* $1 \le N \le 10^5$
* $1 \le W \le 10^9$
* $1 \le v_i \le 10^9 (1 \le i \le N)$
* $1 \le w_i \le 10^9 (1 \le i \le N)$
Input
$N$ $W$
$v_1$ $w_1$
$v_2$ $w_2$
:
$v_N$ $w_N$
The first line consists of the integers $N$ and $W$. In the following $N$ lines, the value and weight of the $i$-th item are given.
Output
Print the maximum total value of the items in a line. The output must not contain an error greater than $10^{-6}$.
Examples
Input
3 50
60 10
100 20
120 30
Output
240
Input
3 50
60 13
100 23
120 33
Output
210.90909091
Input
1 100
100000 100000
Output
100 | instruction | 0 | 88,318 | 10 | 176,636 |
"Correct Solution:
```
import heapq
def Main():
N, capacity = map(int, input().split())
w_list = list()
for _ in range(N):
v, w = map(int, input().split())
heapq.heappush(w_list, [-1*float(v/w), v, w] )
total_value = 0
while len(w_list) != 0:
item = heapq.heappop(w_list)
value_per_weight = -1*item[0]
value = item[1]
weight = item[2]
if capacity >= weight:
capacity -= weight
total_value += value
else:
total_value += capacity * value_per_weight
break
print(total_value)
Main()
``` | output | 1 | 88,318 | 10 | 176,637 |
Provide a correct Python 3 solution for this coding contest problem.
You have $N$ items that you want to put them into a knapsack of capacity $W$. Item $i$ ($1 \le i \le N$) has weight $w_i$ and value $v_i$ for the weight.
When you put some items into the knapsack, the following conditions must be satisfied:
* The total value of the items is as large as possible.
* The total weight of the selected items is at most $W$.
* You can break some items if you want. If you put $w'$($0 \le w' \le w_i$) of item $i$, its value becomes $\displaystyle v_i \times \frac{w'}{w_i}.$
Find the maximum total value of items in the knapsack.
Constraints
* $1 \le N \le 10^5$
* $1 \le W \le 10^9$
* $1 \le v_i \le 10^9 (1 \le i \le N)$
* $1 \le w_i \le 10^9 (1 \le i \le N)$
Input
$N$ $W$
$v_1$ $w_1$
$v_2$ $w_2$
:
$v_N$ $w_N$
The first line consists of the integers $N$ and $W$. In the following $N$ lines, the value and weight of the $i$-th item are given.
Output
Print the maximum total value of the items in a line. The output must not contain an error greater than $10^{-6}$.
Examples
Input
3 50
60 10
100 20
120 30
Output
240
Input
3 50
60 13
100 23
120 33
Output
210.90909091
Input
1 100
100000 100000
Output
100 | instruction | 0 | 88,319 | 10 | 176,638 |
"Correct Solution:
```
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# FileName: fractional_knapsack
# CreatedDate: 2020-06-08 21:46:16 +0900
# LastModified: 2020-06-08 21:53:14 +0900
#
import os
import sys
#import numpy as np
#import pandas as pd
def main():
N,W = map(int,input().split())
p = []
for _ in range(N):
v,w = map(int,input().split())
p.append([v/w,v,w])
# print(p)
p.sort(reverse=True)
index=0
profit=0
while W>0 and index<N:
if W>=p[index][2]:
profit+=p[index][1]
W-=p[index][2]
else:
profit+=p[index][1]*W/p[index][2]
W-=W
index+=1
print(profit)
if __name__ == "__main__":
main()
``` | output | 1 | 88,319 | 10 | 176,639 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You have $N$ items that you want to put them into a knapsack of capacity $W$. Item $i$ ($1 \le i \le N$) has weight $w_i$ and value $v_i$ for the weight.
When you put some items into the knapsack, the following conditions must be satisfied:
* The total value of the items is as large as possible.
* The total weight of the selected items is at most $W$.
* You can break some items if you want. If you put $w'$($0 \le w' \le w_i$) of item $i$, its value becomes $\displaystyle v_i \times \frac{w'}{w_i}.$
Find the maximum total value of items in the knapsack.
Constraints
* $1 \le N \le 10^5$
* $1 \le W \le 10^9$
* $1 \le v_i \le 10^9 (1 \le i \le N)$
* $1 \le w_i \le 10^9 (1 \le i \le N)$
Input
$N$ $W$
$v_1$ $w_1$
$v_2$ $w_2$
:
$v_N$ $w_N$
The first line consists of the integers $N$ and $W$. In the following $N$ lines, the value and weight of the $i$-th item are given.
Output
Print the maximum total value of the items in a line. The output must not contain an error greater than $10^{-6}$.
Examples
Input
3 50
60 10
100 20
120 30
Output
240
Input
3 50
60 13
100 23
120 33
Output
210.90909091
Input
1 100
100000 100000
Output
100
Submitted Solution:
```
class Item:
def __init__(self,v,w):
self.v=v
self.w=w
self.r=v/w
def __str__(self):
s='v='+str(self.v)
s+=',w='+str(self.w)
s+=',r='+str(self.r)
return s
n,w=map(int,input().split())
items=[]
for i in range(n):
vi,wi=map(int,input().split())
items.append(Item(vi,wi))
items.sort(key=lambda x:x.r,reverse=True)
total=0
remain = w
for i in range(n):
v = items[i].v
w = items[i].w
r = items[i].r
if w <= remain:
total += v
remain -= w
else:
total += r * remain
break
print(total)
``` | instruction | 0 | 88,320 | 10 | 176,640 |
Yes | output | 1 | 88,320 | 10 | 176,641 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You have $N$ items that you want to put them into a knapsack of capacity $W$. Item $i$ ($1 \le i \le N$) has weight $w_i$ and value $v_i$ for the weight.
When you put some items into the knapsack, the following conditions must be satisfied:
* The total value of the items is as large as possible.
* The total weight of the selected items is at most $W$.
* You can break some items if you want. If you put $w'$($0 \le w' \le w_i$) of item $i$, its value becomes $\displaystyle v_i \times \frac{w'}{w_i}.$
Find the maximum total value of items in the knapsack.
Constraints
* $1 \le N \le 10^5$
* $1 \le W \le 10^9$
* $1 \le v_i \le 10^9 (1 \le i \le N)$
* $1 \le w_i \le 10^9 (1 \le i \le N)$
Input
$N$ $W$
$v_1$ $w_1$
$v_2$ $w_2$
:
$v_N$ $w_N$
The first line consists of the integers $N$ and $W$. In the following $N$ lines, the value and weight of the $i$-th item are given.
Output
Print the maximum total value of the items in a line. The output must not contain an error greater than $10^{-6}$.
Examples
Input
3 50
60 10
100 20
120 30
Output
240
Input
3 50
60 13
100 23
120 33
Output
210.90909091
Input
1 100
100000 100000
Output
100
Submitted Solution:
```
# https://onlinejudge.u-aizu.ac.jp/courses/lesson/1/ALDS1/15/ALDS1_15_B
import heapq
n, w = [int(i) for i in input().split()]
res = 0
pq = []
for _ in range(n):
_v, _w = [int(i) for i in input().split()]
e = _v / _w
heapq.heappush(pq, (-e, _v, _w))
while w > 0 and pq:
e, value, weight = heapq.heappop(pq)
if w >= weight:
res += value
w -= weight
else:
res += -e * w
w = 0
print(res)
``` | instruction | 0 | 88,322 | 10 | 176,644 |
Yes | output | 1 | 88,322 | 10 | 176,645 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You have $N$ items that you want to put them into a knapsack of capacity $W$. Item $i$ ($1 \le i \le N$) has weight $w_i$ and value $v_i$ for the weight.
When you put some items into the knapsack, the following conditions must be satisfied:
* The total value of the items is as large as possible.
* The total weight of the selected items is at most $W$.
* You can break some items if you want. If you put $w'$($0 \le w' \le w_i$) of item $i$, its value becomes $\displaystyle v_i \times \frac{w'}{w_i}.$
Find the maximum total value of items in the knapsack.
Constraints
* $1 \le N \le 10^5$
* $1 \le W \le 10^9$
* $1 \le v_i \le 10^9 (1 \le i \le N)$
* $1 \le w_i \le 10^9 (1 \le i \le N)$
Input
$N$ $W$
$v_1$ $w_1$
$v_2$ $w_2$
:
$v_N$ $w_N$
The first line consists of the integers $N$ and $W$. In the following $N$ lines, the value and weight of the $i$-th item are given.
Output
Print the maximum total value of the items in a line. The output must not contain an error greater than $10^{-6}$.
Examples
Input
3 50
60 10
100 20
120 30
Output
240
Input
3 50
60 13
100 23
120 33
Output
210.90909091
Input
1 100
100000 100000
Output
100
Submitted Solution:
```
def main():
N,W = map(int,input().split())
vw = [list(map(int,input().split())) for _ in range(N)]
for i in range(N):
vw[i].append(vw[i][0]/vw[i][1])
vw.sort(reverse = True,key = lambda x:x[2])
val,wei = 0,0
for i in range(N):
if wei + vw[i][1] <= W:
val += vw[i][0]
wei += vw[i][1]
elif wei < W:
val += vw[i][0]*(W-wei)/vw[i][1]
wei = W
else:
break
print(val)
if __name__ == "__main__":
main()
``` | instruction | 0 | 88,323 | 10 | 176,646 |
Yes | output | 1 | 88,323 | 10 | 176,647 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There is a country with n citizens. The i-th of them initially has a_{i} money. The government strictly controls the wealth of its citizens. Whenever a citizen makes a purchase or earns some money, they must send a receipt to the social services mentioning the amount of money they currently have.
Sometimes the government makes payouts to the poor: all citizens who have strictly less money than x are paid accordingly so that after the payout they have exactly x money. In this case the citizens don't send a receipt.
You know the initial wealth of every citizen and the log of all events: receipts and payouts. Restore the amount of money each citizen has after all events.
Input
The first line contains a single integer n (1 ≤ n ≤ 2 ⋅ 10^{5}) — the numer of citizens.
The next line contains n integers a_1, a_2, ..., a_n (0 ≤ a_{i} ≤ 10^{9}) — the initial balances of citizens.
The next line contains a single integer q (1 ≤ q ≤ 2 ⋅ 10^{5}) — the number of events.
Each of the next q lines contains a single event. The events are given in chronological order.
Each event is described as either 1 p x (1 ≤ p ≤ n, 0 ≤ x ≤ 10^{9}), or 2 x (0 ≤ x ≤ 10^{9}). In the first case we have a receipt that the balance of the p-th person becomes equal to x. In the second case we have a payoff with parameter x.
Output
Print n integers — the balances of all citizens after all events.
Examples
Input
4
1 2 3 4
3
2 3
1 2 2
2 1
Output
3 2 3 4
Input
5
3 50 2 1 10
3
1 2 0
2 8
1 3 20
Output
8 8 20 8 10
Note
In the first example the balances change as follows: 1 2 3 4 → 3 3 3 4 → 3 2 3 4 → 3 2 3 4
In the second example the balances change as follows: 3 50 2 1 10 → 3 0 2 1 10 → 8 8 8 8 10 → 8 8 20 8 10 | instruction | 0 | 88,447 | 10 | 176,894 |
Tags: binary search, brute force, data structures, sortings
Correct Solution:
```
'''
Auther: ghoshashis545 Ashis Ghosh
College: jalpaiguri Govt Enggineering College
'''
from os import path
import sys
# import numpy as np
from functools import cmp_to_key as ctk
from collections import deque,defaultdict as dd
from bisect import bisect,bisect_left,bisect_right,insort,insort_left,insort_right
from itertools import permutations
from datetime import datetime
from math import ceil,sqrt,log,gcd
def ii():return int(input())
def si():return input()
def mi():return map(int,input().split())
def li():return list(mi())
abc='abcdefghijklmnopqrstuvwxyz'
abd={'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}
mod=1000000007
#mod=998244353
inf = float("inf")
vow=['a','e','i','o','u']
dx,dy=[-1,1,0,0],[0,0,1,-1]
def bo(i):
return ord(i)-ord('a')
def solve():
# for _ in range(ii()):
n=ii()
a=li()
q=ii()
p=[0]*n
suff=[0]*q
for i in range(q):
tc=li()
if tc[0]==1:
x=tc[1]
y=tc[2]
a[x-1]=y
p[x-1]=i
else:
suff[i]=tc[1]
for i in range(q-2,-1,-1):
suff[i]=max(suff[i],suff[i+1])
for i in range(n):
x=p[i]
mx=suff[x]
if a[i]<mx:
a[i]=mx
print(*a)
if __name__ =="__main__":
if path.exists('input.txt'):
sys.stdin=open('input.txt', 'r')
sys.stdout=open('output.txt','w')
else:
input=sys.stdin.readline
solve()
``` | output | 1 | 88,447 | 10 | 176,895 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There is a country with n citizens. The i-th of them initially has a_{i} money. The government strictly controls the wealth of its citizens. Whenever a citizen makes a purchase or earns some money, they must send a receipt to the social services mentioning the amount of money they currently have.
Sometimes the government makes payouts to the poor: all citizens who have strictly less money than x are paid accordingly so that after the payout they have exactly x money. In this case the citizens don't send a receipt.
You know the initial wealth of every citizen and the log of all events: receipts and payouts. Restore the amount of money each citizen has after all events.
Input
The first line contains a single integer n (1 ≤ n ≤ 2 ⋅ 10^{5}) — the numer of citizens.
The next line contains n integers a_1, a_2, ..., a_n (0 ≤ a_{i} ≤ 10^{9}) — the initial balances of citizens.
The next line contains a single integer q (1 ≤ q ≤ 2 ⋅ 10^{5}) — the number of events.
Each of the next q lines contains a single event. The events are given in chronological order.
Each event is described as either 1 p x (1 ≤ p ≤ n, 0 ≤ x ≤ 10^{9}), or 2 x (0 ≤ x ≤ 10^{9}). In the first case we have a receipt that the balance of the p-th person becomes equal to x. In the second case we have a payoff with parameter x.
Output
Print n integers — the balances of all citizens after all events.
Examples
Input
4
1 2 3 4
3
2 3
1 2 2
2 1
Output
3 2 3 4
Input
5
3 50 2 1 10
3
1 2 0
2 8
1 3 20
Output
8 8 20 8 10
Note
In the first example the balances change as follows: 1 2 3 4 → 3 3 3 4 → 3 2 3 4 → 3 2 3 4
In the second example the balances change as follows: 3 50 2 1 10 → 3 0 2 1 10 → 8 8 8 8 10 → 8 8 20 8 10 | instruction | 0 | 88,448 | 10 | 176,896 |
Tags: binary search, brute force, data structures, sortings
Correct Solution:
```
n = int(input())
a = [[int(q), 0] for q in input().split()]
k = int(input())
was, changes = 0, []
for _ in range(k):
s = list(map(int, input().split()))
if s[0] == 1:
a[s[1]-1] = [s[2], was]
else:
changes.append(s[1])
was += 1
max1 = [-1]
for q in range(len(changes)-1, -1, -1):
max1.append(max(max1[-1], changes[q]))
max1.reverse()
print(*[max(q[0], max1[q[1]]) for q in a])
``` | output | 1 | 88,448 | 10 | 176,897 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There is a country with n citizens. The i-th of them initially has a_{i} money. The government strictly controls the wealth of its citizens. Whenever a citizen makes a purchase or earns some money, they must send a receipt to the social services mentioning the amount of money they currently have.
Sometimes the government makes payouts to the poor: all citizens who have strictly less money than x are paid accordingly so that after the payout they have exactly x money. In this case the citizens don't send a receipt.
You know the initial wealth of every citizen and the log of all events: receipts and payouts. Restore the amount of money each citizen has after all events.
Input
The first line contains a single integer n (1 ≤ n ≤ 2 ⋅ 10^{5}) — the numer of citizens.
The next line contains n integers a_1, a_2, ..., a_n (0 ≤ a_{i} ≤ 10^{9}) — the initial balances of citizens.
The next line contains a single integer q (1 ≤ q ≤ 2 ⋅ 10^{5}) — the number of events.
Each of the next q lines contains a single event. The events are given in chronological order.
Each event is described as either 1 p x (1 ≤ p ≤ n, 0 ≤ x ≤ 10^{9}), or 2 x (0 ≤ x ≤ 10^{9}). In the first case we have a receipt that the balance of the p-th person becomes equal to x. In the second case we have a payoff with parameter x.
Output
Print n integers — the balances of all citizens after all events.
Examples
Input
4
1 2 3 4
3
2 3
1 2 2
2 1
Output
3 2 3 4
Input
5
3 50 2 1 10
3
1 2 0
2 8
1 3 20
Output
8 8 20 8 10
Note
In the first example the balances change as follows: 1 2 3 4 → 3 3 3 4 → 3 2 3 4 → 3 2 3 4
In the second example the balances change as follows: 3 50 2 1 10 → 3 0 2 1 10 → 8 8 8 8 10 → 8 8 20 8 10 | instruction | 0 | 88,449 | 10 | 176,898 |
Tags: binary search, brute force, data structures, sortings
Correct Solution:
```
from sys import *
from math import *
n=int(stdin.readline())
a=list(map(int,stdin.readline().split()))
q=int(stdin.readline())
m=[]
mx=0
mx1=0
j=0
for i in range(q):
x=list(map(int,stdin.readline().split()))
m.append(x)
x=[0]*q
for i in range(q):
if m[i][0]==2:
if mx<m[i][1]:
mx=m[i][1]
x[i]=mx
mx=0
if mx1<m[i][1]:
mx1=m[i][1]
mx=x[len(x)-1]
for i in range(len(x)-1,-1,-1):
if x[i]!=0:
if x[i]>mx:
mx=x[i]
x[i]=mx
for i in range(n):
if a[i]<mx1:
a[i]=mx1
for i in range(q):
if m[i][0]==1:
a[m[i][1]-1]=m[i][2]
if a[m[i][1]-1]<x[i]:
a[m[i][1]-1]=x[i]
print(*a)
``` | output | 1 | 88,449 | 10 | 176,899 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There is a country with n citizens. The i-th of them initially has a_{i} money. The government strictly controls the wealth of its citizens. Whenever a citizen makes a purchase or earns some money, they must send a receipt to the social services mentioning the amount of money they currently have.
Sometimes the government makes payouts to the poor: all citizens who have strictly less money than x are paid accordingly so that after the payout they have exactly x money. In this case the citizens don't send a receipt.
You know the initial wealth of every citizen and the log of all events: receipts and payouts. Restore the amount of money each citizen has after all events.
Input
The first line contains a single integer n (1 ≤ n ≤ 2 ⋅ 10^{5}) — the numer of citizens.
The next line contains n integers a_1, a_2, ..., a_n (0 ≤ a_{i} ≤ 10^{9}) — the initial balances of citizens.
The next line contains a single integer q (1 ≤ q ≤ 2 ⋅ 10^{5}) — the number of events.
Each of the next q lines contains a single event. The events are given in chronological order.
Each event is described as either 1 p x (1 ≤ p ≤ n, 0 ≤ x ≤ 10^{9}), or 2 x (0 ≤ x ≤ 10^{9}). In the first case we have a receipt that the balance of the p-th person becomes equal to x. In the second case we have a payoff with parameter x.
Output
Print n integers — the balances of all citizens after all events.
Examples
Input
4
1 2 3 4
3
2 3
1 2 2
2 1
Output
3 2 3 4
Input
5
3 50 2 1 10
3
1 2 0
2 8
1 3 20
Output
8 8 20 8 10
Note
In the first example the balances change as follows: 1 2 3 4 → 3 3 3 4 → 3 2 3 4 → 3 2 3 4
In the second example the balances change as follows: 3 50 2 1 10 → 3 0 2 1 10 → 8 8 8 8 10 → 8 8 20 8 10 | instruction | 0 | 88,450 | 10 | 176,900 |
Tags: binary search, brute force, data structures, sortings
Correct Solution:
```
def main():
n = int(input())
money = list(map(int,input().split()))
last_change = [-1]*n
dp = []
q = int(input())
second = []
for i in range(q):
query = list(map(int,input().split()))
if query[0] == 1:
dp.append(-1)
p,x = query[1],query[2]
money[p-1] = x
last_change[p-1] = i
else:
second.append(query[1])
dp.append(query[1])
for i in range(len(dp)-2,-1,-1):
dp[i] = max(dp[i+1],dp[i])
for i in range(n):
if last_change[i] == -1:
money[i] = max(dp[0],money[i])
else:
change = last_change[i]
if change+1 < len(dp):
max_val = dp[change+1]
else:
max_val = -1
money[i] = max(max_val,money[i])
for i in money:
print(i,end = ' ')
main()
``` | output | 1 | 88,450 | 10 | 176,901 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There is a country with n citizens. The i-th of them initially has a_{i} money. The government strictly controls the wealth of its citizens. Whenever a citizen makes a purchase or earns some money, they must send a receipt to the social services mentioning the amount of money they currently have.
Sometimes the government makes payouts to the poor: all citizens who have strictly less money than x are paid accordingly so that after the payout they have exactly x money. In this case the citizens don't send a receipt.
You know the initial wealth of every citizen and the log of all events: receipts and payouts. Restore the amount of money each citizen has after all events.
Input
The first line contains a single integer n (1 ≤ n ≤ 2 ⋅ 10^{5}) — the numer of citizens.
The next line contains n integers a_1, a_2, ..., a_n (0 ≤ a_{i} ≤ 10^{9}) — the initial balances of citizens.
The next line contains a single integer q (1 ≤ q ≤ 2 ⋅ 10^{5}) — the number of events.
Each of the next q lines contains a single event. The events are given in chronological order.
Each event is described as either 1 p x (1 ≤ p ≤ n, 0 ≤ x ≤ 10^{9}), or 2 x (0 ≤ x ≤ 10^{9}). In the first case we have a receipt that the balance of the p-th person becomes equal to x. In the second case we have a payoff with parameter x.
Output
Print n integers — the balances of all citizens after all events.
Examples
Input
4
1 2 3 4
3
2 3
1 2 2
2 1
Output
3 2 3 4
Input
5
3 50 2 1 10
3
1 2 0
2 8
1 3 20
Output
8 8 20 8 10
Note
In the first example the balances change as follows: 1 2 3 4 → 3 3 3 4 → 3 2 3 4 → 3 2 3 4
In the second example the balances change as follows: 3 50 2 1 10 → 3 0 2 1 10 → 8 8 8 8 10 → 8 8 20 8 10 | instruction | 0 | 88,451 | 10 | 176,902 |
Tags: binary search, brute force, data structures, sortings
Correct Solution:
```
import sys
import math as mt
input=sys.stdin.buffer.readline
t=1
#t=int(input())
for _ in range(t):
n=int(input())
#n,I=map(int,input().split())
l=list(map(int,input().split()))
q=int(input())
l1=[]
for ____ in range(q):
l2=list(map(int,input().split()))
l1.append(l2)
X=-1
#print(l1)
ind={}
ind1={}
suff=[0]*(q+1)
pos=[0]*(n+1)
for i in range(q):
if l1[i][0]==1:
pos[l1[i][1]-1]=i
l[l1[i][1]-1]=l1[i][2]
for i in range(q-1,-1,-1):
if l1[i][0]==2:
suff[i]=l1[i][1]
suff[i]=max(suff[i+1],suff[i])
for i in range(n):
if suff[pos[i]]>l[i]:
l[i]=suff[pos[i]]
print(*l)
``` | output | 1 | 88,451 | 10 | 176,903 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There is a country with n citizens. The i-th of them initially has a_{i} money. The government strictly controls the wealth of its citizens. Whenever a citizen makes a purchase or earns some money, they must send a receipt to the social services mentioning the amount of money they currently have.
Sometimes the government makes payouts to the poor: all citizens who have strictly less money than x are paid accordingly so that after the payout they have exactly x money. In this case the citizens don't send a receipt.
You know the initial wealth of every citizen and the log of all events: receipts and payouts. Restore the amount of money each citizen has after all events.
Input
The first line contains a single integer n (1 ≤ n ≤ 2 ⋅ 10^{5}) — the numer of citizens.
The next line contains n integers a_1, a_2, ..., a_n (0 ≤ a_{i} ≤ 10^{9}) — the initial balances of citizens.
The next line contains a single integer q (1 ≤ q ≤ 2 ⋅ 10^{5}) — the number of events.
Each of the next q lines contains a single event. The events are given in chronological order.
Each event is described as either 1 p x (1 ≤ p ≤ n, 0 ≤ x ≤ 10^{9}), or 2 x (0 ≤ x ≤ 10^{9}). In the first case we have a receipt that the balance of the p-th person becomes equal to x. In the second case we have a payoff with parameter x.
Output
Print n integers — the balances of all citizens after all events.
Examples
Input
4
1 2 3 4
3
2 3
1 2 2
2 1
Output
3 2 3 4
Input
5
3 50 2 1 10
3
1 2 0
2 8
1 3 20
Output
8 8 20 8 10
Note
In the first example the balances change as follows: 1 2 3 4 → 3 3 3 4 → 3 2 3 4 → 3 2 3 4
In the second example the balances change as follows: 3 50 2 1 10 → 3 0 2 1 10 → 8 8 8 8 10 → 8 8 20 8 10 | instruction | 0 | 88,452 | 10 | 176,904 |
Tags: binary search, brute force, data structures, sortings
Correct Solution:
```
import sys
from collections import defaultdict
import heapq
input = sys.stdin.readline
def main():
n = int(input())
a = list(map(int, input().split()))
q = int(input())
events = []
for _ in range(q):
events.append(list(map(int, input().split())))
max_x2_right = [-1] * len(events)
pos = q-1
while pos >= 0:
if events[pos][0] == 2:
if pos < q-1:
max_x2_right[pos] = max(max_x2_right[pos+1], events[pos][1])
else:
max_x2_right[pos] = events[pos][1]
else:
if pos < q - 1:
max_x2_right[pos] = max_x2_right[pos+1]
pos -= 1
for i in range(n):
a[i] = max(a[i], max_x2_right[0])
for i, e in enumerate(events):
if e[0] == 1:
p = e[1]-1
a[p] = max(e[2], max_x2_right[i])
print(*a)
if __name__ == '__main__':
main()
``` | output | 1 | 88,452 | 10 | 176,905 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There is a country with n citizens. The i-th of them initially has a_{i} money. The government strictly controls the wealth of its citizens. Whenever a citizen makes a purchase or earns some money, they must send a receipt to the social services mentioning the amount of money they currently have.
Sometimes the government makes payouts to the poor: all citizens who have strictly less money than x are paid accordingly so that after the payout they have exactly x money. In this case the citizens don't send a receipt.
You know the initial wealth of every citizen and the log of all events: receipts and payouts. Restore the amount of money each citizen has after all events.
Input
The first line contains a single integer n (1 ≤ n ≤ 2 ⋅ 10^{5}) — the numer of citizens.
The next line contains n integers a_1, a_2, ..., a_n (0 ≤ a_{i} ≤ 10^{9}) — the initial balances of citizens.
The next line contains a single integer q (1 ≤ q ≤ 2 ⋅ 10^{5}) — the number of events.
Each of the next q lines contains a single event. The events are given in chronological order.
Each event is described as either 1 p x (1 ≤ p ≤ n, 0 ≤ x ≤ 10^{9}), or 2 x (0 ≤ x ≤ 10^{9}). In the first case we have a receipt that the balance of the p-th person becomes equal to x. In the second case we have a payoff with parameter x.
Output
Print n integers — the balances of all citizens after all events.
Examples
Input
4
1 2 3 4
3
2 3
1 2 2
2 1
Output
3 2 3 4
Input
5
3 50 2 1 10
3
1 2 0
2 8
1 3 20
Output
8 8 20 8 10
Note
In the first example the balances change as follows: 1 2 3 4 → 3 3 3 4 → 3 2 3 4 → 3 2 3 4
In the second example the balances change as follows: 3 50 2 1 10 → 3 0 2 1 10 → 8 8 8 8 10 → 8 8 20 8 10 | instruction | 0 | 88,453 | 10 | 176,906 |
Tags: binary search, brute force, data structures, sortings
Correct Solution:
```
"""
Code Forces Template
"""
import os
import sys
import string
import math
def main(balances, events):
"""Algrithm"""
payouts = [0] * len(events)
last_change = [0] * len(balances)
for i in range(len(events)):
if events[i][0] == 1:
_, index, value = events[i]
index -= 1
last_change[index] = i
balances[index] = value
elif events[i][0] == 2:
payouts[i] = events[i][1]
for i in range(len(events) - 2, -1, -1):
payouts[i] = max(payouts[i], payouts[i + 1])
for i in range(len(balances)):
yield max(balances[i], payouts[last_change[i]])
def parse():
"""Load Input"""
n = int(input())
balances = [int(s) for s in input().split(' ')]
event_count = int(input())
events = []
for line in sys.stdin:
if len(events) < event_count:
events.append([int(s) for s in line.split(' ')])
return balances, events
def output(ans):
print(' '.join([str(i) for i in ans]))
if __name__ == '__main__':
output(main(*parse()))
``` | output | 1 | 88,453 | 10 | 176,907 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There is a country with n citizens. The i-th of them initially has a_{i} money. The government strictly controls the wealth of its citizens. Whenever a citizen makes a purchase or earns some money, they must send a receipt to the social services mentioning the amount of money they currently have.
Sometimes the government makes payouts to the poor: all citizens who have strictly less money than x are paid accordingly so that after the payout they have exactly x money. In this case the citizens don't send a receipt.
You know the initial wealth of every citizen and the log of all events: receipts and payouts. Restore the amount of money each citizen has after all events.
Input
The first line contains a single integer n (1 ≤ n ≤ 2 ⋅ 10^{5}) — the numer of citizens.
The next line contains n integers a_1, a_2, ..., a_n (0 ≤ a_{i} ≤ 10^{9}) — the initial balances of citizens.
The next line contains a single integer q (1 ≤ q ≤ 2 ⋅ 10^{5}) — the number of events.
Each of the next q lines contains a single event. The events are given in chronological order.
Each event is described as either 1 p x (1 ≤ p ≤ n, 0 ≤ x ≤ 10^{9}), or 2 x (0 ≤ x ≤ 10^{9}). In the first case we have a receipt that the balance of the p-th person becomes equal to x. In the second case we have a payoff with parameter x.
Output
Print n integers — the balances of all citizens after all events.
Examples
Input
4
1 2 3 4
3
2 3
1 2 2
2 1
Output
3 2 3 4
Input
5
3 50 2 1 10
3
1 2 0
2 8
1 3 20
Output
8 8 20 8 10
Note
In the first example the balances change as follows: 1 2 3 4 → 3 3 3 4 → 3 2 3 4 → 3 2 3 4
In the second example the balances change as follows: 3 50 2 1 10 → 3 0 2 1 10 → 8 8 8 8 10 → 8 8 20 8 10 | instruction | 0 | 88,454 | 10 | 176,908 |
Tags: binary search, brute force, data structures, sortings
Correct Solution:
```
n = int(input())
a = [int(s) for s in input().split()]
q = int(input())
b = [None]*n
rnd = 0
xs = []
for i in range(q):
qi = [int(s) for s in input().split()]
if qi[0] == 1:
b[qi[1]-1] = (qi[2], rnd)
else:
xs.append(qi[1])
rnd += 1
maxx = 0
if xs:
maxx = xs[-1]
for i in range(len(xs)-2, -1, -1):
if xs[i] < maxx:
xs[i] = maxx
else:
maxx = xs[i]
xs.append(0)
for i in range(n):
if not b[i]:
a[i] = max(maxx, a[i])
else:
a[i] = max(b[i][0], xs[b[i][1]])
print(*a)
``` | output | 1 | 88,454 | 10 | 176,909 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is a country with n citizens. The i-th of them initially has a_{i} money. The government strictly controls the wealth of its citizens. Whenever a citizen makes a purchase or earns some money, they must send a receipt to the social services mentioning the amount of money they currently have.
Sometimes the government makes payouts to the poor: all citizens who have strictly less money than x are paid accordingly so that after the payout they have exactly x money. In this case the citizens don't send a receipt.
You know the initial wealth of every citizen and the log of all events: receipts and payouts. Restore the amount of money each citizen has after all events.
Input
The first line contains a single integer n (1 ≤ n ≤ 2 ⋅ 10^{5}) — the numer of citizens.
The next line contains n integers a_1, a_2, ..., a_n (0 ≤ a_{i} ≤ 10^{9}) — the initial balances of citizens.
The next line contains a single integer q (1 ≤ q ≤ 2 ⋅ 10^{5}) — the number of events.
Each of the next q lines contains a single event. The events are given in chronological order.
Each event is described as either 1 p x (1 ≤ p ≤ n, 0 ≤ x ≤ 10^{9}), or 2 x (0 ≤ x ≤ 10^{9}). In the first case we have a receipt that the balance of the p-th person becomes equal to x. In the second case we have a payoff with parameter x.
Output
Print n integers — the balances of all citizens after all events.
Examples
Input
4
1 2 3 4
3
2 3
1 2 2
2 1
Output
3 2 3 4
Input
5
3 50 2 1 10
3
1 2 0
2 8
1 3 20
Output
8 8 20 8 10
Note
In the first example the balances change as follows: 1 2 3 4 → 3 3 3 4 → 3 2 3 4 → 3 2 3 4
In the second example the balances change as follows: 3 50 2 1 10 → 3 0 2 1 10 → 8 8 8 8 10 → 8 8 20 8 10
Submitted Solution:
```
import sys
n=int(sys.stdin.readline())
a=[int(i) for i in sys.stdin.readline().split()]
q=int(sys.stdin.readline())
# maxi=-2
# ind=-2
arr=[0]*n
upd=[-2]*q
for w in range(q):
event=[int(j) for j in sys.stdin.readline().split()]
if(event[0]==1):
p=event[1]
x=event[2]
a[p-1]=x
arr[p-1]=w
else:
x=event[1]
upd[w]=x
# if(maxi<=x):
# maxi=x
# ind=w
for h in range(q-2,-1,-1):
upd[h]=max(upd[h],upd[h+1])
for g in range(n):
a[g]=max(a[g],upd[arr[g]])
a[g]=str(a[g])
print(" ".join(a))
``` | instruction | 0 | 88,455 | 10 | 176,910 |
Yes | output | 1 | 88,455 | 10 | 176,911 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is a country with n citizens. The i-th of them initially has a_{i} money. The government strictly controls the wealth of its citizens. Whenever a citizen makes a purchase or earns some money, they must send a receipt to the social services mentioning the amount of money they currently have.
Sometimes the government makes payouts to the poor: all citizens who have strictly less money than x are paid accordingly so that after the payout they have exactly x money. In this case the citizens don't send a receipt.
You know the initial wealth of every citizen and the log of all events: receipts and payouts. Restore the amount of money each citizen has after all events.
Input
The first line contains a single integer n (1 ≤ n ≤ 2 ⋅ 10^{5}) — the numer of citizens.
The next line contains n integers a_1, a_2, ..., a_n (0 ≤ a_{i} ≤ 10^{9}) — the initial balances of citizens.
The next line contains a single integer q (1 ≤ q ≤ 2 ⋅ 10^{5}) — the number of events.
Each of the next q lines contains a single event. The events are given in chronological order.
Each event is described as either 1 p x (1 ≤ p ≤ n, 0 ≤ x ≤ 10^{9}), or 2 x (0 ≤ x ≤ 10^{9}). In the first case we have a receipt that the balance of the p-th person becomes equal to x. In the second case we have a payoff with parameter x.
Output
Print n integers — the balances of all citizens after all events.
Examples
Input
4
1 2 3 4
3
2 3
1 2 2
2 1
Output
3 2 3 4
Input
5
3 50 2 1 10
3
1 2 0
2 8
1 3 20
Output
8 8 20 8 10
Note
In the first example the balances change as follows: 1 2 3 4 → 3 3 3 4 → 3 2 3 4 → 3 2 3 4
In the second example the balances change as follows: 3 50 2 1 10 → 3 0 2 1 10 → 8 8 8 8 10 → 8 8 20 8 10
Submitted Solution:
```
# @author
import sys
class DWelfareState:
def solve(self):
n = int(input())
a = [int(_) for _ in input().split()]
q = int(input())
queries = []
v = [[-1, a[i]] for i in range(n)]
x_max = [-float('inf')] * (q + 1)
for qi in range(q):
query = [int(_) for _ in input().split()]
queries.append(query)
type = query[0]
if type == 1:
i, x = query[1:]
i -= 1
v[i] = [qi, x]
# x_max[qi] = x_max[qi - 1]
else:
x = query[1]
x_max[qi] = max(x_max[qi - 1], x)
suff = [0] * (q + 1)
suff[-1] = -float('inf')
for i in range(q - 1, -1, -1):
suff[i] = max(suff[i + 1], x_max[i])
ans = [0] * n
for i in range(n):
ans[i] = max(suff[v[i][0] + 1], v[i][1])
# print(v)
# print(x_max)
print(*ans)
solver = DWelfareState()
input = sys.stdin.readline
solver.solve()
``` | instruction | 0 | 88,456 | 10 | 176,912 |
Yes | output | 1 | 88,456 | 10 | 176,913 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is a country with n citizens. The i-th of them initially has a_{i} money. The government strictly controls the wealth of its citizens. Whenever a citizen makes a purchase or earns some money, they must send a receipt to the social services mentioning the amount of money they currently have.
Sometimes the government makes payouts to the poor: all citizens who have strictly less money than x are paid accordingly so that after the payout they have exactly x money. In this case the citizens don't send a receipt.
You know the initial wealth of every citizen and the log of all events: receipts and payouts. Restore the amount of money each citizen has after all events.
Input
The first line contains a single integer n (1 ≤ n ≤ 2 ⋅ 10^{5}) — the numer of citizens.
The next line contains n integers a_1, a_2, ..., a_n (0 ≤ a_{i} ≤ 10^{9}) — the initial balances of citizens.
The next line contains a single integer q (1 ≤ q ≤ 2 ⋅ 10^{5}) — the number of events.
Each of the next q lines contains a single event. The events are given in chronological order.
Each event is described as either 1 p x (1 ≤ p ≤ n, 0 ≤ x ≤ 10^{9}), or 2 x (0 ≤ x ≤ 10^{9}). In the first case we have a receipt that the balance of the p-th person becomes equal to x. In the second case we have a payoff with parameter x.
Output
Print n integers — the balances of all citizens after all events.
Examples
Input
4
1 2 3 4
3
2 3
1 2 2
2 1
Output
3 2 3 4
Input
5
3 50 2 1 10
3
1 2 0
2 8
1 3 20
Output
8 8 20 8 10
Note
In the first example the balances change as follows: 1 2 3 4 → 3 3 3 4 → 3 2 3 4 → 3 2 3 4
In the second example the balances change as follows: 3 50 2 1 10 → 3 0 2 1 10 → 8 8 8 8 10 → 8 8 20 8 10
Submitted Solution:
```
import bisect,sys
printn = lambda x: sys.stdout.write(x)
inn = lambda : int(input())
inl = lambda: list(map(int, input().split()))
inm = lambda: map(int, input().split())
DBG = True and False
R = 10**9 + 7
def ddprint(x):
if DBG:
print(x)
n = inn()
a = inl()
q = inn()
spend = []
pay = []
mx = 0
for i in range(q):
c = inl()
if c[0]==1:
spend.append((i,c[1],c[2]))
else:
pay.append((i,c[1]))
if c[1]>mx:
mx = c[1]
m = len(pay)
accpay = [(0,0)] * (m+1)
for i in range(m-1,-1,-1):
accpay[i] = (pay[i][0], max(accpay[i+1][1], pay[i][1]))
accpay[m] = (999999999,0)
b = [0]*n
for i in range(n):
b[i] = max(a[i],mx)
for z in spend:
idx = bisect.bisect_left(accpay, (z[0],z[1]))
if idx >= m:
b[z[1]-1] = z[2]
else:
b[z[1]-1] = max(z[2], accpay[idx][1])
for i in range(n):
printn(("" if i==0 else " ") + str(b[i]))
print("")
``` | instruction | 0 | 88,457 | 10 | 176,914 |
Yes | output | 1 | 88,457 | 10 | 176,915 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is a country with n citizens. The i-th of them initially has a_{i} money. The government strictly controls the wealth of its citizens. Whenever a citizen makes a purchase or earns some money, they must send a receipt to the social services mentioning the amount of money they currently have.
Sometimes the government makes payouts to the poor: all citizens who have strictly less money than x are paid accordingly so that after the payout they have exactly x money. In this case the citizens don't send a receipt.
You know the initial wealth of every citizen and the log of all events: receipts and payouts. Restore the amount of money each citizen has after all events.
Input
The first line contains a single integer n (1 ≤ n ≤ 2 ⋅ 10^{5}) — the numer of citizens.
The next line contains n integers a_1, a_2, ..., a_n (0 ≤ a_{i} ≤ 10^{9}) — the initial balances of citizens.
The next line contains a single integer q (1 ≤ q ≤ 2 ⋅ 10^{5}) — the number of events.
Each of the next q lines contains a single event. The events are given in chronological order.
Each event is described as either 1 p x (1 ≤ p ≤ n, 0 ≤ x ≤ 10^{9}), or 2 x (0 ≤ x ≤ 10^{9}). In the first case we have a receipt that the balance of the p-th person becomes equal to x. In the second case we have a payoff with parameter x.
Output
Print n integers — the balances of all citizens after all events.
Examples
Input
4
1 2 3 4
3
2 3
1 2 2
2 1
Output
3 2 3 4
Input
5
3 50 2 1 10
3
1 2 0
2 8
1 3 20
Output
8 8 20 8 10
Note
In the first example the balances change as follows: 1 2 3 4 → 3 3 3 4 → 3 2 3 4 → 3 2 3 4
In the second example the balances change as follows: 3 50 2 1 10 → 3 0 2 1 10 → 8 8 8 8 10 → 8 8 20 8 10
Submitted Solution:
```
def fastio():
import sys
from io import StringIO
from atexit import register
global input
sys.stdin = StringIO(sys.stdin.read())
input = lambda : sys.stdin.readline().rstrip('\r\n')
sys.stdout = StringIO()
register(lambda : sys.__stdout__.write(sys.stdout.getvalue()))
fastio()
MOD = 10**9 + 7
I = lambda:list(map(int,input().split()))
from math import log2, ceil
from bisect import bisect_right as br, bisect_left as bl
n, = I()
l = I()
q, = I()
p = 0
t = []
while q:
q -= 1
t.append(I())
mx = 0
ans = [-1]*n
for i in t[::-1]:
if i[0] == 1:
i[1] -= 1
if ans[i[1]] == -1:
ans[i[1]] = max(mx, i[2])
else:
mx = max(mx, i[1])
for i in range(n):
if ans[i] == -1:
ans[i] = max(mx, l[i])
print(*ans)
``` | instruction | 0 | 88,458 | 10 | 176,916 |
Yes | output | 1 | 88,458 | 10 | 176,917 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is a country with n citizens. The i-th of them initially has a_{i} money. The government strictly controls the wealth of its citizens. Whenever a citizen makes a purchase or earns some money, they must send a receipt to the social services mentioning the amount of money they currently have.
Sometimes the government makes payouts to the poor: all citizens who have strictly less money than x are paid accordingly so that after the payout they have exactly x money. In this case the citizens don't send a receipt.
You know the initial wealth of every citizen and the log of all events: receipts and payouts. Restore the amount of money each citizen has after all events.
Input
The first line contains a single integer n (1 ≤ n ≤ 2 ⋅ 10^{5}) — the numer of citizens.
The next line contains n integers a_1, a_2, ..., a_n (0 ≤ a_{i} ≤ 10^{9}) — the initial balances of citizens.
The next line contains a single integer q (1 ≤ q ≤ 2 ⋅ 10^{5}) — the number of events.
Each of the next q lines contains a single event. The events are given in chronological order.
Each event is described as either 1 p x (1 ≤ p ≤ n, 0 ≤ x ≤ 10^{9}), or 2 x (0 ≤ x ≤ 10^{9}). In the first case we have a receipt that the balance of the p-th person becomes equal to x. In the second case we have a payoff with parameter x.
Output
Print n integers — the balances of all citizens after all events.
Examples
Input
4
1 2 3 4
3
2 3
1 2 2
2 1
Output
3 2 3 4
Input
5
3 50 2 1 10
3
1 2 0
2 8
1 3 20
Output
8 8 20 8 10
Note
In the first example the balances change as follows: 1 2 3 4 → 3 3 3 4 → 3 2 3 4 → 3 2 3 4
In the second example the balances change as follows: 3 50 2 1 10 → 3 0 2 1 10 → 8 8 8 8 10 → 8 8 20 8 10
Submitted Solution:
```
from sys import *
from math import *
n=int(stdin.readline())
a=list(map(int,stdin.readline().split()))
q=int(stdin.readline())
m=[]
mx=0
j=0
for i in range(q):
x=list(map(int,stdin.readline().split()))
m.append(x)
for i in range(q):
if m[i][0]==2:
if mx<m[i][1]:
mx=m[i][1]
j=i
for i in range(j):
if m[i][0]==1:
a[m[i][1]-1]=m[i][2]
for i in range(n):
if a[i]<mx:
a[i]=mx
for i in range(j,q):
if m[i][0]==1:
a[m[i][1]-1]=m[i][2]
print(*a)
``` | instruction | 0 | 88,459 | 10 | 176,918 |
No | output | 1 | 88,459 | 10 | 176,919 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is a country with n citizens. The i-th of them initially has a_{i} money. The government strictly controls the wealth of its citizens. Whenever a citizen makes a purchase or earns some money, they must send a receipt to the social services mentioning the amount of money they currently have.
Sometimes the government makes payouts to the poor: all citizens who have strictly less money than x are paid accordingly so that after the payout they have exactly x money. In this case the citizens don't send a receipt.
You know the initial wealth of every citizen and the log of all events: receipts and payouts. Restore the amount of money each citizen has after all events.
Input
The first line contains a single integer n (1 ≤ n ≤ 2 ⋅ 10^{5}) — the numer of citizens.
The next line contains n integers a_1, a_2, ..., a_n (0 ≤ a_{i} ≤ 10^{9}) — the initial balances of citizens.
The next line contains a single integer q (1 ≤ q ≤ 2 ⋅ 10^{5}) — the number of events.
Each of the next q lines contains a single event. The events are given in chronological order.
Each event is described as either 1 p x (1 ≤ p ≤ n, 0 ≤ x ≤ 10^{9}), or 2 x (0 ≤ x ≤ 10^{9}). In the first case we have a receipt that the balance of the p-th person becomes equal to x. In the second case we have a payoff with parameter x.
Output
Print n integers — the balances of all citizens after all events.
Examples
Input
4
1 2 3 4
3
2 3
1 2 2
2 1
Output
3 2 3 4
Input
5
3 50 2 1 10
3
1 2 0
2 8
1 3 20
Output
8 8 20 8 10
Note
In the first example the balances change as follows: 1 2 3 4 → 3 3 3 4 → 3 2 3 4 → 3 2 3 4
In the second example the balances change as follows: 3 50 2 1 10 → 3 0 2 1 10 → 8 8 8 8 10 → 8 8 20 8 10
Submitted Solution:
```
import sys
import math as mt
input=sys.stdin.buffer.readline
t=1
#t=int(input())
for _ in range(t):
n=int(input())
#n,I=map(int,input().split())
l=list(map(int,input().split()))
q=int(input())
l1=[]
for ____ in range(q):
l2=list(map(int,input().split()))
l1.append(l2)
X=-1
#print(l1)
ind={}
for i in range(q-1,-1,-1):
if l1[i][0]==2:
X=max(l1[i][1],X)
else:
#print(111,l1[i],X)
if l1[i][2]>X:
ind[l1[i][1]-1]=1
l[l1[i][1]-1]=l1[i][2]
else:
l[l1[i][1]-1]=-1
#print(ind)
for i in range(n):
if l[i]<X and ind.get(i,-1)==-1:
l[i]=X
print(*l)
``` | instruction | 0 | 88,460 | 10 | 176,920 |
No | output | 1 | 88,460 | 10 | 176,921 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is a country with n citizens. The i-th of them initially has a_{i} money. The government strictly controls the wealth of its citizens. Whenever a citizen makes a purchase or earns some money, they must send a receipt to the social services mentioning the amount of money they currently have.
Sometimes the government makes payouts to the poor: all citizens who have strictly less money than x are paid accordingly so that after the payout they have exactly x money. In this case the citizens don't send a receipt.
You know the initial wealth of every citizen and the log of all events: receipts and payouts. Restore the amount of money each citizen has after all events.
Input
The first line contains a single integer n (1 ≤ n ≤ 2 ⋅ 10^{5}) — the numer of citizens.
The next line contains n integers a_1, a_2, ..., a_n (0 ≤ a_{i} ≤ 10^{9}) — the initial balances of citizens.
The next line contains a single integer q (1 ≤ q ≤ 2 ⋅ 10^{5}) — the number of events.
Each of the next q lines contains a single event. The events are given in chronological order.
Each event is described as either 1 p x (1 ≤ p ≤ n, 0 ≤ x ≤ 10^{9}), or 2 x (0 ≤ x ≤ 10^{9}). In the first case we have a receipt that the balance of the p-th person becomes equal to x. In the second case we have a payoff with parameter x.
Output
Print n integers — the balances of all citizens after all events.
Examples
Input
4
1 2 3 4
3
2 3
1 2 2
2 1
Output
3 2 3 4
Input
5
3 50 2 1 10
3
1 2 0
2 8
1 3 20
Output
8 8 20 8 10
Note
In the first example the balances change as follows: 1 2 3 4 → 3 3 3 4 → 3 2 3 4 → 3 2 3 4
In the second example the balances change as follows: 3 50 2 1 10 → 3 0 2 1 10 → 8 8 8 8 10 → 8 8 20 8 10
Submitted Solution:
```
def main():
n = int(input())
money = list(map(int,input().split()))
last_change = [-1]*n
dp = []
q = int(input())
second = []
for i in range(q):
query = list(map(int,input().split()))
if query[0] == 1:
if dp:
dp.append(dp[-1])
else:
dp.append(0)
p,x = query[1],query[2]
money[p-1] = x
last_change[p-1] = i
else:
second.append(query[1])
dp.append(query[1])
for i in range(len(dp)-2,-1,-1):
dp[i] = max(dp[i-1],dp[i])
for i in range(n):
if last_change[i] == -1:
money[i] = max(dp[0],money[i])
else:
change = last_change[i]
if change+1 < len(dp):
max_val = dp[change+1]
else:
max_val = -1
money[i] = max(max_val,money[i])
for i in money:
print(i,end = ' ')
main()
``` | instruction | 0 | 88,461 | 10 | 176,922 |
No | output | 1 | 88,461 | 10 | 176,923 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is a country with n citizens. The i-th of them initially has a_{i} money. The government strictly controls the wealth of its citizens. Whenever a citizen makes a purchase or earns some money, they must send a receipt to the social services mentioning the amount of money they currently have.
Sometimes the government makes payouts to the poor: all citizens who have strictly less money than x are paid accordingly so that after the payout they have exactly x money. In this case the citizens don't send a receipt.
You know the initial wealth of every citizen and the log of all events: receipts and payouts. Restore the amount of money each citizen has after all events.
Input
The first line contains a single integer n (1 ≤ n ≤ 2 ⋅ 10^{5}) — the numer of citizens.
The next line contains n integers a_1, a_2, ..., a_n (0 ≤ a_{i} ≤ 10^{9}) — the initial balances of citizens.
The next line contains a single integer q (1 ≤ q ≤ 2 ⋅ 10^{5}) — the number of events.
Each of the next q lines contains a single event. The events are given in chronological order.
Each event is described as either 1 p x (1 ≤ p ≤ n, 0 ≤ x ≤ 10^{9}), or 2 x (0 ≤ x ≤ 10^{9}). In the first case we have a receipt that the balance of the p-th person becomes equal to x. In the second case we have a payoff with parameter x.
Output
Print n integers — the balances of all citizens after all events.
Examples
Input
4
1 2 3 4
3
2 3
1 2 2
2 1
Output
3 2 3 4
Input
5
3 50 2 1 10
3
1 2 0
2 8
1 3 20
Output
8 8 20 8 10
Note
In the first example the balances change as follows: 1 2 3 4 → 3 3 3 4 → 3 2 3 4 → 3 2 3 4
In the second example the balances change as follows: 3 50 2 1 10 → 3 0 2 1 10 → 8 8 8 8 10 → 8 8 20 8 10
Submitted Solution:
```
n = int(input())
lis=list(map(int,input().split()))
lis=[[0,i] for i in lis]
k = int(input())
mmm=0
c=sss=0
for i in range(k):
m = input()
if m[0]=='1':
c+=1
l,q,o=m.split()
q=int(q)
o=int(o)
lis[q-1][1]=o
lis[q-1][0]=c
else:
q,o=m.split()
o=int(o)
if o>=mmm:
sss=c
mmm=o
for i in range(n):
if lis[i][1]<mmm and lis[i][0]<=sss:
lis[i][1]=mmm
for i in range(n):
print(lis[i][1],sep=' ',end=' ')
``` | instruction | 0 | 88,462 | 10 | 176,924 |
No | output | 1 | 88,462 | 10 | 176,925 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You have n coins, each of the same value of 1.
Distribute them into packets such that any amount x (1 ≤ x ≤ n) can be formed using some (possibly one or all) number of these packets.
Each packet may only be used entirely or not used at all. No packet may be used more than once in the formation of the single x, however it may be reused for the formation of other x's.
Find the minimum number of packets in such a distribution.
Input
The only line contains a single integer n (1 ≤ n ≤ 10^9) — the number of coins you have.
Output
Output a single integer — the minimum possible number of packets, satisfying the condition above.
Examples
Input
6
Output
3
Input
2
Output
2
Note
In the first example, three packets with 1, 2 and 3 coins can be made to get any amount x (1≤ x≤ 6).
* To get 1 use the packet with 1 coin.
* To get 2 use the packet with 2 coins.
* To get 3 use the packet with 3 coins.
* To get 4 use packets with 1 and 3 coins.
* To get 5 use packets with 2 and 3 coins
* To get 6 use all packets.
In the second example, two packets with 1 and 1 coins can be made to get any amount x (1≤ x≤ 2). | instruction | 0 | 89,266 | 10 | 178,532 |
Tags: constructive algorithms, greedy, math
Correct Solution:
```
n = int(input())
packets = []
i = 1
s = 0
while s < n:
if s + i <= n:
packets.append(i)
s += i
i *= 2
else:
packets.append(n-s)
s = n
print(len(packets))
``` | output | 1 | 89,266 | 10 | 178,533 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You have n coins, each of the same value of 1.
Distribute them into packets such that any amount x (1 ≤ x ≤ n) can be formed using some (possibly one or all) number of these packets.
Each packet may only be used entirely or not used at all. No packet may be used more than once in the formation of the single x, however it may be reused for the formation of other x's.
Find the minimum number of packets in such a distribution.
Input
The only line contains a single integer n (1 ≤ n ≤ 10^9) — the number of coins you have.
Output
Output a single integer — the minimum possible number of packets, satisfying the condition above.
Examples
Input
6
Output
3
Input
2
Output
2
Note
In the first example, three packets with 1, 2 and 3 coins can be made to get any amount x (1≤ x≤ 6).
* To get 1 use the packet with 1 coin.
* To get 2 use the packet with 2 coins.
* To get 3 use the packet with 3 coins.
* To get 4 use packets with 1 and 3 coins.
* To get 5 use packets with 2 and 3 coins
* To get 6 use all packets.
In the second example, two packets with 1 and 1 coins can be made to get any amount x (1≤ x≤ 2). | instruction | 0 | 89,267 | 10 | 178,534 |
Tags: constructive algorithms, greedy, math
Correct Solution:
```
n = int(input())
import math
x = int(math.log(n,2))
print(x+1)
``` | output | 1 | 89,267 | 10 | 178,535 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You have n coins, each of the same value of 1.
Distribute them into packets such that any amount x (1 ≤ x ≤ n) can be formed using some (possibly one or all) number of these packets.
Each packet may only be used entirely or not used at all. No packet may be used more than once in the formation of the single x, however it may be reused for the formation of other x's.
Find the minimum number of packets in such a distribution.
Input
The only line contains a single integer n (1 ≤ n ≤ 10^9) — the number of coins you have.
Output
Output a single integer — the minimum possible number of packets, satisfying the condition above.
Examples
Input
6
Output
3
Input
2
Output
2
Note
In the first example, three packets with 1, 2 and 3 coins can be made to get any amount x (1≤ x≤ 6).
* To get 1 use the packet with 1 coin.
* To get 2 use the packet with 2 coins.
* To get 3 use the packet with 3 coins.
* To get 4 use packets with 1 and 3 coins.
* To get 5 use packets with 2 and 3 coins
* To get 6 use all packets.
In the second example, two packets with 1 and 1 coins can be made to get any amount x (1≤ x≤ 2). | instruction | 0 | 89,268 | 10 | 178,536 |
Tags: constructive algorithms, greedy, math
Correct Solution:
```
def solve(n):
k, t = 0, 1
while n > 0:
n -= t
t *= 2
k += 1
return k
n = int(input())
print(solve(n))
``` | output | 1 | 89,268 | 10 | 178,537 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You have n coins, each of the same value of 1.
Distribute them into packets such that any amount x (1 ≤ x ≤ n) can be formed using some (possibly one or all) number of these packets.
Each packet may only be used entirely or not used at all. No packet may be used more than once in the formation of the single x, however it may be reused for the formation of other x's.
Find the minimum number of packets in such a distribution.
Input
The only line contains a single integer n (1 ≤ n ≤ 10^9) — the number of coins you have.
Output
Output a single integer — the minimum possible number of packets, satisfying the condition above.
Examples
Input
6
Output
3
Input
2
Output
2
Note
In the first example, three packets with 1, 2 and 3 coins can be made to get any amount x (1≤ x≤ 6).
* To get 1 use the packet with 1 coin.
* To get 2 use the packet with 2 coins.
* To get 3 use the packet with 3 coins.
* To get 4 use packets with 1 and 3 coins.
* To get 5 use packets with 2 and 3 coins
* To get 6 use all packets.
In the second example, two packets with 1 and 1 coins can be made to get any amount x (1≤ x≤ 2). | instruction | 0 | 89,269 | 10 | 178,538 |
Tags: constructive algorithms, greedy, math
Correct Solution:
```
import math
print(math.floor(math.log2(int(input())))+1)
``` | output | 1 | 89,269 | 10 | 178,539 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.