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.
To celebrate the opening of the Winter Computer School the organizers decided to buy in n liters of cola. However, an unexpected difficulty occurred in the shop: it turned out that cola is sold in bottles 0.5, 1 and 2 liters in volume. At that, there are exactly a bottles 0.5 in volume, b one-liter bottles and c of two-liter ones. The organizers have enough money to buy any amount of cola. What did cause the heated arguments was how many bottles of every kind to buy, as this question is pivotal for the distribution of cola among the participants (and organizers as well).
Thus, while the organizers are having the argument, discussing different variants of buying cola, the Winter School can't start. Your task is to count the number of all the possible ways to buy exactly n liters of cola and persuade the organizers that this number is too large, and if they keep on arguing, then the Winter Computer School will have to be organized in summer.
All the bottles of cola are considered indistinguishable, i.e. two variants of buying are different from each other only if they differ in the number of bottles of at least one kind.
Input
The first line contains four integers — n, a, b, c (1 ≤ n ≤ 10000, 0 ≤ a, b, c ≤ 5000).
Output
Print the unique number — the solution to the problem. If it is impossible to buy exactly n liters of cola, print 0.
Examples
Input
10 5 5 5
Output
9
Input
3 0 0 2
Output
0
Submitted Solution:
```
n,a,b,c=map(int,input().split());r=0
if 2*c+b+a//2<n:
print(r)
else:
for i in range(c+1):
k=n-2*i
q,w=min(b,a//2,k),max(b,a//2)
if k<=b+a//2 and k>0:
if k<=w:r+=q+1
else:
if q+1-k+w>=0:r+=q+1-k+w
elif k==0:r+=1
print(r)
``` | instruction | 0 | 86,078 | 10 | 172,156 |
Yes | output | 1 | 86,078 | 10 | 172,157 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
To celebrate the opening of the Winter Computer School the organizers decided to buy in n liters of cola. However, an unexpected difficulty occurred in the shop: it turned out that cola is sold in bottles 0.5, 1 and 2 liters in volume. At that, there are exactly a bottles 0.5 in volume, b one-liter bottles and c of two-liter ones. The organizers have enough money to buy any amount of cola. What did cause the heated arguments was how many bottles of every kind to buy, as this question is pivotal for the distribution of cola among the participants (and organizers as well).
Thus, while the organizers are having the argument, discussing different variants of buying cola, the Winter School can't start. Your task is to count the number of all the possible ways to buy exactly n liters of cola and persuade the organizers that this number is too large, and if they keep on arguing, then the Winter Computer School will have to be organized in summer.
All the bottles of cola are considered indistinguishable, i.e. two variants of buying are different from each other only if they differ in the number of bottles of at least one kind.
Input
The first line contains four integers — n, a, b, c (1 ≤ n ≤ 10000, 0 ≤ a, b, c ≤ 5000).
Output
Print the unique number — the solution to the problem. If it is impossible to buy exactly n liters of cola, print 0.
Examples
Input
10 5 5 5
Output
9
Input
3 0 0 2
Output
0
Submitted Solution:
```
def nik(rudy,pig,y,z):
temp = 0
for i in range(z+1):
for j in range(y+1):
t = rudy - i*2 -j
if t>=0 and pig*0.5 >= t:
temp+=1
print(temp)
rudy, pig, y, z = list(map(int,input().split()))
nik(rudy,pig,y,z)
``` | instruction | 0 | 86,079 | 10 | 172,158 |
Yes | output | 1 | 86,079 | 10 | 172,159 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
To celebrate the opening of the Winter Computer School the organizers decided to buy in n liters of cola. However, an unexpected difficulty occurred in the shop: it turned out that cola is sold in bottles 0.5, 1 and 2 liters in volume. At that, there are exactly a bottles 0.5 in volume, b one-liter bottles and c of two-liter ones. The organizers have enough money to buy any amount of cola. What did cause the heated arguments was how many bottles of every kind to buy, as this question is pivotal for the distribution of cola among the participants (and organizers as well).
Thus, while the organizers are having the argument, discussing different variants of buying cola, the Winter School can't start. Your task is to count the number of all the possible ways to buy exactly n liters of cola and persuade the organizers that this number is too large, and if they keep on arguing, then the Winter Computer School will have to be organized in summer.
All the bottles of cola are considered indistinguishable, i.e. two variants of buying are different from each other only if they differ in the number of bottles of at least one kind.
Input
The first line contains four integers — n, a, b, c (1 ≤ n ≤ 10000, 0 ≤ a, b, c ≤ 5000).
Output
Print the unique number — the solution to the problem. If it is impossible to buy exactly n liters of cola, print 0.
Examples
Input
10 5 5 5
Output
9
Input
3 0 0 2
Output
0
Submitted Solution:
```
#https://codeforces.com/problemset/problem/44/B
n,a,b,c=map(int,input().split())
r=0
for i in range(c+1):
e=n-2*i
if(e<0):break
d1=( e - min(b,e) )
d2=min(e,a//2)
r+=(d2-d1+1)*(d2-d1>=0)
print(r)
``` | instruction | 0 | 86,080 | 10 | 172,160 |
Yes | output | 1 | 86,080 | 10 | 172,161 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
To celebrate the opening of the Winter Computer School the organizers decided to buy in n liters of cola. However, an unexpected difficulty occurred in the shop: it turned out that cola is sold in bottles 0.5, 1 and 2 liters in volume. At that, there are exactly a bottles 0.5 in volume, b one-liter bottles and c of two-liter ones. The organizers have enough money to buy any amount of cola. What did cause the heated arguments was how many bottles of every kind to buy, as this question is pivotal for the distribution of cola among the participants (and organizers as well).
Thus, while the organizers are having the argument, discussing different variants of buying cola, the Winter School can't start. Your task is to count the number of all the possible ways to buy exactly n liters of cola and persuade the organizers that this number is too large, and if they keep on arguing, then the Winter Computer School will have to be organized in summer.
All the bottles of cola are considered indistinguishable, i.e. two variants of buying are different from each other only if they differ in the number of bottles of at least one kind.
Input
The first line contains four integers — n, a, b, c (1 ≤ n ≤ 10000, 0 ≤ a, b, c ≤ 5000).
Output
Print the unique number — the solution to the problem. If it is impossible to buy exactly n liters of cola, print 0.
Examples
Input
10 5 5 5
Output
9
Input
3 0 0 2
Output
0
Submitted Solution:
```
n,a,b,c=map(int,input().split())
r=0
for i in range(c+1):
e=n-2*i
if(e<0):break
d1=( e - min(b,e) )
d2=min(e,a//2)
r+=(d2-d1+1)*(d2-d1>=0)
print(r)
``` | instruction | 0 | 86,081 | 10 | 172,162 |
Yes | output | 1 | 86,081 | 10 | 172,163 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
To celebrate the opening of the Winter Computer School the organizers decided to buy in n liters of cola. However, an unexpected difficulty occurred in the shop: it turned out that cola is sold in bottles 0.5, 1 and 2 liters in volume. At that, there are exactly a bottles 0.5 in volume, b one-liter bottles and c of two-liter ones. The organizers have enough money to buy any amount of cola. What did cause the heated arguments was how many bottles of every kind to buy, as this question is pivotal for the distribution of cola among the participants (and organizers as well).
Thus, while the organizers are having the argument, discussing different variants of buying cola, the Winter School can't start. Your task is to count the number of all the possible ways to buy exactly n liters of cola and persuade the organizers that this number is too large, and if they keep on arguing, then the Winter Computer School will have to be organized in summer.
All the bottles of cola are considered indistinguishable, i.e. two variants of buying are different from each other only if they differ in the number of bottles of at least one kind.
Input
The first line contains four integers — n, a, b, c (1 ≤ n ≤ 10000, 0 ≤ a, b, c ≤ 5000).
Output
Print the unique number — the solution to the problem. If it is impossible to buy exactly n liters of cola, print 0.
Examples
Input
10 5 5 5
Output
9
Input
3 0 0 2
Output
0
Submitted Solution:
```
n, a, b, c =[int(x)for x in input().split()]
liter_count, volume=0, 0
for c in range(c+1):
for b in range(b+1):
volume=n-2*c+1*b
if volume >=0 and a > volume :
liter_count+=1
print(liter_count)
``` | instruction | 0 | 86,082 | 10 | 172,164 |
No | output | 1 | 86,082 | 10 | 172,165 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
To celebrate the opening of the Winter Computer School the organizers decided to buy in n liters of cola. However, an unexpected difficulty occurred in the shop: it turned out that cola is sold in bottles 0.5, 1 and 2 liters in volume. At that, there are exactly a bottles 0.5 in volume, b one-liter bottles and c of two-liter ones. The organizers have enough money to buy any amount of cola. What did cause the heated arguments was how many bottles of every kind to buy, as this question is pivotal for the distribution of cola among the participants (and organizers as well).
Thus, while the organizers are having the argument, discussing different variants of buying cola, the Winter School can't start. Your task is to count the number of all the possible ways to buy exactly n liters of cola and persuade the organizers that this number is too large, and if they keep on arguing, then the Winter Computer School will have to be organized in summer.
All the bottles of cola are considered indistinguishable, i.e. two variants of buying are different from each other only if they differ in the number of bottles of at least one kind.
Input
The first line contains four integers — n, a, b, c (1 ≤ n ≤ 10000, 0 ≤ a, b, c ≤ 5000).
Output
Print the unique number — the solution to the problem. If it is impossible to buy exactly n liters of cola, print 0.
Examples
Input
10 5 5 5
Output
9
Input
3 0 0 2
Output
0
Submitted Solution:
```
n, a, b, c =[int(x)for x in input().split()]
liter_count, volume=0, 0
for c in range(c+3):
for b in range(b+1):
volume=n-2*c+1*b
if volume >=0 and a*0.5 >= volume :
liter_count+=1
print(liter_count)
``` | instruction | 0 | 86,083 | 10 | 172,166 |
No | output | 1 | 86,083 | 10 | 172,167 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
To celebrate the opening of the Winter Computer School the organizers decided to buy in n liters of cola. However, an unexpected difficulty occurred in the shop: it turned out that cola is sold in bottles 0.5, 1 and 2 liters in volume. At that, there are exactly a bottles 0.5 in volume, b one-liter bottles and c of two-liter ones. The organizers have enough money to buy any amount of cola. What did cause the heated arguments was how many bottles of every kind to buy, as this question is pivotal for the distribution of cola among the participants (and organizers as well).
Thus, while the organizers are having the argument, discussing different variants of buying cola, the Winter School can't start. Your task is to count the number of all the possible ways to buy exactly n liters of cola and persuade the organizers that this number is too large, and if they keep on arguing, then the Winter Computer School will have to be organized in summer.
All the bottles of cola are considered indistinguishable, i.e. two variants of buying are different from each other only if they differ in the number of bottles of at least one kind.
Input
The first line contains four integers — n, a, b, c (1 ≤ n ≤ 10000, 0 ≤ a, b, c ≤ 5000).
Output
Print the unique number — the solution to the problem. If it is impossible to buy exactly n liters of cola, print 0.
Examples
Input
10 5 5 5
Output
9
Input
3 0 0 2
Output
0
Submitted Solution:
```
n, a, b, c = list(map(int, input().split()))
res = 0
for x in range(c):
for y in range(b):
if n - 2*x - y >= 0:
res+=1
print(res)
``` | instruction | 0 | 86,084 | 10 | 172,168 |
No | output | 1 | 86,084 | 10 | 172,169 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
To celebrate the opening of the Winter Computer School the organizers decided to buy in n liters of cola. However, an unexpected difficulty occurred in the shop: it turned out that cola is sold in bottles 0.5, 1 and 2 liters in volume. At that, there are exactly a bottles 0.5 in volume, b one-liter bottles and c of two-liter ones. The organizers have enough money to buy any amount of cola. What did cause the heated arguments was how many bottles of every kind to buy, as this question is pivotal for the distribution of cola among the participants (and organizers as well).
Thus, while the organizers are having the argument, discussing different variants of buying cola, the Winter School can't start. Your task is to count the number of all the possible ways to buy exactly n liters of cola and persuade the organizers that this number is too large, and if they keep on arguing, then the Winter Computer School will have to be organized in summer.
All the bottles of cola are considered indistinguishable, i.e. two variants of buying are different from each other only if they differ in the number of bottles of at least one kind.
Input
The first line contains four integers — n, a, b, c (1 ≤ n ≤ 10000, 0 ≤ a, b, c ≤ 5000).
Output
Print the unique number — the solution to the problem. If it is impossible to buy exactly n liters of cola, print 0.
Examples
Input
10 5 5 5
Output
9
Input
3 0 0 2
Output
0
Submitted Solution:
```
n,a,b,c=map(int,input().split());r=0
if 2*c+b+a//2<n:
print(r)
else:
for i in range(c+1):
k=n-2*i
q,w=min(b,a//2,k),max(b,a//2)
if k<=b+a//2 and k>0:
if k<=w:r+=q+1
else:
if q+1-k+w>=0:r+=q+1-k+w
elif k==0:r+=1
else:break
print(r)
``` | instruction | 0 | 86,085 | 10 | 172,170 |
No | output | 1 | 86,085 | 10 | 172,171 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Recenlty Luba got a credit card and started to use it. Let's consider n consecutive days Luba uses the card.
She starts with 0 money on her account.
In the evening of i-th day a transaction ai occurs. If ai > 0, then ai bourles are deposited to Luba's account. If ai < 0, then ai bourles are withdrawn. And if ai = 0, then the amount of money on Luba's account is checked.
In the morning of any of n days Luba can go to the bank and deposit any positive integer amount of burles to her account. But there is a limitation: the amount of money on the account can never exceed d.
It can happen that the amount of money goes greater than d by some transaction in the evening. In this case answer will be «-1».
Luba must not exceed this limit, and also she wants that every day her account is checked (the days when ai = 0) the amount of money on her account is non-negative. It takes a lot of time to go to the bank, so Luba wants to know the minimum number of days she needs to deposit some money to her account (if it is possible to meet all the requirements). Help her!
Input
The first line contains two integers n, d (1 ≤ n ≤ 105, 1 ≤ d ≤ 109) —the number of days and the money limitation.
The second line contains n integer numbers a1, a2, ... an ( - 104 ≤ ai ≤ 104), where ai represents the transaction in i-th day.
Output
Print -1 if Luba cannot deposit the money to her account in such a way that the requirements are met. Otherwise print the minimum number of days Luba has to deposit money.
Examples
Input
5 10
-1 5 0 -5 3
Output
0
Input
3 4
-10 0 20
Output
-1
Input
5 10
-5 0 10 -11 0
Output
2 | instruction | 0 | 86,231 | 10 | 172,462 |
Tags: data structures, dp, greedy, implementation
Correct Solution:
```
n,d=list(map(int,input().split()))
a=list(map(int,input().split()))
s=0
m=0
ans=0
flag=True
n=len(a)
for i in range(n):
if a[i]==0:
if s<0:
s=d
m=d
ans+=1
else:
m=min(m,s)
elif a[i]<0:
s=s+a[i]
else:
if(s+a[i]>d):
if(s+a[i]-d)>m:
flag=False
break
else:
m-=(s+a[i]-d)
s=d
else:
s=s+a[i]
if flag:
print(ans)
else:
print(-1)
``` | output | 1 | 86,231 | 10 | 172,463 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Recenlty Luba got a credit card and started to use it. Let's consider n consecutive days Luba uses the card.
She starts with 0 money on her account.
In the evening of i-th day a transaction ai occurs. If ai > 0, then ai bourles are deposited to Luba's account. If ai < 0, then ai bourles are withdrawn. And if ai = 0, then the amount of money on Luba's account is checked.
In the morning of any of n days Luba can go to the bank and deposit any positive integer amount of burles to her account. But there is a limitation: the amount of money on the account can never exceed d.
It can happen that the amount of money goes greater than d by some transaction in the evening. In this case answer will be «-1».
Luba must not exceed this limit, and also she wants that every day her account is checked (the days when ai = 0) the amount of money on her account is non-negative. It takes a lot of time to go to the bank, so Luba wants to know the minimum number of days she needs to deposit some money to her account (if it is possible to meet all the requirements). Help her!
Input
The first line contains two integers n, d (1 ≤ n ≤ 105, 1 ≤ d ≤ 109) —the number of days and the money limitation.
The second line contains n integer numbers a1, a2, ... an ( - 104 ≤ ai ≤ 104), where ai represents the transaction in i-th day.
Output
Print -1 if Luba cannot deposit the money to her account in such a way that the requirements are met. Otherwise print the minimum number of days Luba has to deposit money.
Examples
Input
5 10
-1 5 0 -5 3
Output
0
Input
3 4
-10 0 20
Output
-1
Input
5 10
-5 0 10 -11 0
Output
2 | instruction | 0 | 86,232 | 10 | 172,464 |
Tags: data structures, dp, greedy, implementation
Correct Solution:
```
#Bhargey Mehta (Sophomore)
#DA-IICT, Gandhinagar
import sys, math, queue, bisect
#sys.stdin = open("input.txt", "r")
MOD = 10**9+7
sys.setrecursionlimit(1000000)
n, d = map(int, input().split())
a = list(map(int, input().split()))
p = [0 for i in range(n)]
for i in range(n):
p[i] = p[i-1]+a[i]
mx = [-1 for i in range(n)]
mx[-1] = p[-1]
for i in range(n-2, -1, -1):
mx[i] = max(mx[i+1], p[i])
c = 0
ans = 0
for i in range(n):
p[i] += c
if p[i] > d:
print(-1)
exit()
if a[i] != 0 or p[i] >= 0: continue
av = d-(mx[i]+c)
if -p[i] > av:
print(-1)
exit()
ans += 1
c = d-mx[i]
print(ans)
``` | output | 1 | 86,232 | 10 | 172,465 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Recenlty Luba got a credit card and started to use it. Let's consider n consecutive days Luba uses the card.
She starts with 0 money on her account.
In the evening of i-th day a transaction ai occurs. If ai > 0, then ai bourles are deposited to Luba's account. If ai < 0, then ai bourles are withdrawn. And if ai = 0, then the amount of money on Luba's account is checked.
In the morning of any of n days Luba can go to the bank and deposit any positive integer amount of burles to her account. But there is a limitation: the amount of money on the account can never exceed d.
It can happen that the amount of money goes greater than d by some transaction in the evening. In this case answer will be «-1».
Luba must not exceed this limit, and also she wants that every day her account is checked (the days when ai = 0) the amount of money on her account is non-negative. It takes a lot of time to go to the bank, so Luba wants to know the minimum number of days she needs to deposit some money to her account (if it is possible to meet all the requirements). Help her!
Input
The first line contains two integers n, d (1 ≤ n ≤ 105, 1 ≤ d ≤ 109) —the number of days and the money limitation.
The second line contains n integer numbers a1, a2, ... an ( - 104 ≤ ai ≤ 104), where ai represents the transaction in i-th day.
Output
Print -1 if Luba cannot deposit the money to her account in such a way that the requirements are met. Otherwise print the minimum number of days Luba has to deposit money.
Examples
Input
5 10
-1 5 0 -5 3
Output
0
Input
3 4
-10 0 20
Output
-1
Input
5 10
-5 0 10 -11 0
Output
2 | instruction | 0 | 86,233 | 10 | 172,466 |
Tags: data structures, dp, greedy, implementation
Correct Solution:
```
n, d = map(int, input().split())
line = list(map(int, input().split()))
pref = [0] * n
maxx = 0
for i in range(n):
pref[i] = pref[max(i - 1, 0)] + line[i]
maxx = max(maxx, pref[i])
maxr = [0] * n
for i in range(n - 1, -1, -1):
if i == n - 1:
maxr[i] = pref[i]
else:
maxr[i] = max(maxr[i + 1], pref[i])
sm = 0
bon = 0
ans = 0
b = True
if maxx > d:
b = False
for i in range(n):
elem = line[i]
sm += elem
if elem == 0:
#print(sm, bon)
if sm + bon < 0:
ans += 1
bon += max(0, d - (maxr[i] + bon))
if sm + bon < 0:
b = False
break
if sm + bon > d:
b = False
break
if b == False:
print(-1)
else:
print(ans)
``` | output | 1 | 86,233 | 10 | 172,467 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Recenlty Luba got a credit card and started to use it. Let's consider n consecutive days Luba uses the card.
She starts with 0 money on her account.
In the evening of i-th day a transaction ai occurs. If ai > 0, then ai bourles are deposited to Luba's account. If ai < 0, then ai bourles are withdrawn. And if ai = 0, then the amount of money on Luba's account is checked.
In the morning of any of n days Luba can go to the bank and deposit any positive integer amount of burles to her account. But there is a limitation: the amount of money on the account can never exceed d.
It can happen that the amount of money goes greater than d by some transaction in the evening. In this case answer will be «-1».
Luba must not exceed this limit, and also she wants that every day her account is checked (the days when ai = 0) the amount of money on her account is non-negative. It takes a lot of time to go to the bank, so Luba wants to know the minimum number of days she needs to deposit some money to her account (if it is possible to meet all the requirements). Help her!
Input
The first line contains two integers n, d (1 ≤ n ≤ 105, 1 ≤ d ≤ 109) —the number of days and the money limitation.
The second line contains n integer numbers a1, a2, ... an ( - 104 ≤ ai ≤ 104), where ai represents the transaction in i-th day.
Output
Print -1 if Luba cannot deposit the money to her account in such a way that the requirements are met. Otherwise print the minimum number of days Luba has to deposit money.
Examples
Input
5 10
-1 5 0 -5 3
Output
0
Input
3 4
-10 0 20
Output
-1
Input
5 10
-5 0 10 -11 0
Output
2 | instruction | 0 | 86,234 | 10 | 172,468 |
Tags: data structures, dp, greedy, implementation
Correct Solution:
```
import sys
from random import *
from bisect import *
#from collections import deque
pl=1
from math import gcd,sqrt
from copy import *
sys.setrecursionlimit(10**5)
if pl:
input=sys.stdin.readline
else:
sys.stdin=open('input.txt', 'r')
sys.stdout=open('outpt.txt','w')
def li():
return [int(xxx) for xxx in input().split()]
def fi():
return int(input())
def si():
return list(input().rstrip())
def mi():
return map(int,input().split())
t=1
ans=[]
time=flag=1
d={}
while t>0:
t-=1
n,d=mi()
a=li()
p=[]
for i in range(n):
if a[i]==0:
p.append(i)
c=ans=0
nex=n
r=[0]*n
for i in range(len(p)-1,-1,-1):
j=p[i]+1
c=maxi=0
while j<nex:
c+=a[j]
maxi=max(maxi,c)
j+=1
if i==len(p)-1:
r[p[i]]=max(0,d-maxi)
else:
r[p[i]]=max(0,min(r[nex]-c,d-maxi))
nex=p[i]
c=0
for i in range(n):
if a[i]==0:
if c<0:
ans+=1
c=r[i]
else:
c+=a[i]
if c>d:
print(-1)
exit(0)
print(ans)
``` | output | 1 | 86,234 | 10 | 172,469 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Recenlty Luba got a credit card and started to use it. Let's consider n consecutive days Luba uses the card.
She starts with 0 money on her account.
In the evening of i-th day a transaction ai occurs. If ai > 0, then ai bourles are deposited to Luba's account. If ai < 0, then ai bourles are withdrawn. And if ai = 0, then the amount of money on Luba's account is checked.
In the morning of any of n days Luba can go to the bank and deposit any positive integer amount of burles to her account. But there is a limitation: the amount of money on the account can never exceed d.
It can happen that the amount of money goes greater than d by some transaction in the evening. In this case answer will be «-1».
Luba must not exceed this limit, and also she wants that every day her account is checked (the days when ai = 0) the amount of money on her account is non-negative. It takes a lot of time to go to the bank, so Luba wants to know the minimum number of days she needs to deposit some money to her account (if it is possible to meet all the requirements). Help her!
Input
The first line contains two integers n, d (1 ≤ n ≤ 105, 1 ≤ d ≤ 109) —the number of days and the money limitation.
The second line contains n integer numbers a1, a2, ... an ( - 104 ≤ ai ≤ 104), where ai represents the transaction in i-th day.
Output
Print -1 if Luba cannot deposit the money to her account in such a way that the requirements are met. Otherwise print the minimum number of days Luba has to deposit money.
Examples
Input
5 10
-1 5 0 -5 3
Output
0
Input
3 4
-10 0 20
Output
-1
Input
5 10
-5 0 10 -11 0
Output
2 | instruction | 0 | 86,235 | 10 | 172,470 |
Tags: data structures, dp, greedy, implementation
Correct Solution:
```
n, d = list(map(int, input().split()))
l = list(map(int, input().split()))
mus = [0] * n
mus[0] = l[0]
cnt = 0
ans = 0
for i in range(1, n):
mus[i] = mus[i - 1] + l[i]
suf = [0] * n
suf[-1] = mus[-1]
for i in range(n - 2, -1, -1):
suf[i] = max(mus[i], suf[i + 1])
for i in range(n):
if l[i] == 0 and mus[i] + cnt < 0:
if (d - suf[i] - cnt < 0 or d - suf[i] < abs(mus[i])):
print(-1)
exit()
else:
cnt += (d - suf[i] - cnt)
ans += 1
if suf[0] > d:
print(-1)
exit()
print(ans)
``` | output | 1 | 86,235 | 10 | 172,471 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Recenlty Luba got a credit card and started to use it. Let's consider n consecutive days Luba uses the card.
She starts with 0 money on her account.
In the evening of i-th day a transaction ai occurs. If ai > 0, then ai bourles are deposited to Luba's account. If ai < 0, then ai bourles are withdrawn. And if ai = 0, then the amount of money on Luba's account is checked.
In the morning of any of n days Luba can go to the bank and deposit any positive integer amount of burles to her account. But there is a limitation: the amount of money on the account can never exceed d.
It can happen that the amount of money goes greater than d by some transaction in the evening. In this case answer will be «-1».
Luba must not exceed this limit, and also she wants that every day her account is checked (the days when ai = 0) the amount of money on her account is non-negative. It takes a lot of time to go to the bank, so Luba wants to know the minimum number of days she needs to deposit some money to her account (if it is possible to meet all the requirements). Help her!
Input
The first line contains two integers n, d (1 ≤ n ≤ 105, 1 ≤ d ≤ 109) —the number of days and the money limitation.
The second line contains n integer numbers a1, a2, ... an ( - 104 ≤ ai ≤ 104), where ai represents the transaction in i-th day.
Output
Print -1 if Luba cannot deposit the money to her account in such a way that the requirements are met. Otherwise print the minimum number of days Luba has to deposit money.
Examples
Input
5 10
-1 5 0 -5 3
Output
0
Input
3 4
-10 0 20
Output
-1
Input
5 10
-5 0 10 -11 0
Output
2 | instruction | 0 | 86,236 | 10 | 172,472 |
Tags: data structures, dp, greedy, implementation
Correct Solution:
```
n,d=map(int,input().split())
a=list(map(int,input().split()))
f=True
b=[a[0]]
for i in range(1,n):
b.append(b[i-1]+a[i])
if max(b)>d:
f=False
h=[0]*n
h[n-1]=b[n-1]
for i in range(n-2,-1,-1):
h[i]=max(b[i],h[i+1])
x,k=0,0
for i in range(n):
if a[i]==0 and b[i]+x<0:
k+=1
x+=d-(h[i]+x)
if b[i]+x<0:
f=False
break
if f:
print(k)
else:
print(-1)
``` | output | 1 | 86,236 | 10 | 172,473 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Recenlty Luba got a credit card and started to use it. Let's consider n consecutive days Luba uses the card.
She starts with 0 money on her account.
In the evening of i-th day a transaction ai occurs. If ai > 0, then ai bourles are deposited to Luba's account. If ai < 0, then ai bourles are withdrawn. And if ai = 0, then the amount of money on Luba's account is checked.
In the morning of any of n days Luba can go to the bank and deposit any positive integer amount of burles to her account. But there is a limitation: the amount of money on the account can never exceed d.
It can happen that the amount of money goes greater than d by some transaction in the evening. In this case answer will be «-1».
Luba must not exceed this limit, and also she wants that every day her account is checked (the days when ai = 0) the amount of money on her account is non-negative. It takes a lot of time to go to the bank, so Luba wants to know the minimum number of days she needs to deposit some money to her account (if it is possible to meet all the requirements). Help her!
Input
The first line contains two integers n, d (1 ≤ n ≤ 105, 1 ≤ d ≤ 109) —the number of days and the money limitation.
The second line contains n integer numbers a1, a2, ... an ( - 104 ≤ ai ≤ 104), where ai represents the transaction in i-th day.
Output
Print -1 if Luba cannot deposit the money to her account in such a way that the requirements are met. Otherwise print the minimum number of days Luba has to deposit money.
Examples
Input
5 10
-1 5 0 -5 3
Output
0
Input
3 4
-10 0 20
Output
-1
Input
5 10
-5 0 10 -11 0
Output
2 | instruction | 0 | 86,237 | 10 | 172,474 |
Tags: data structures, dp, greedy, implementation
Correct Solution:
```
# ---------------------------iye ha aam zindegi---------------------------------------------
import math
import random
import heapq,bisect
import sys
from collections import deque, defaultdict
from fractions import Fraction
import sys
import threading
from collections import defaultdict
threading.stack_size(10**8)
mod = 10 ** 9 + 7
mod1 = 998244353
# ------------------------------warmup----------------------------
import os
import sys
from io import BytesIO, IOBase
sys.setrecursionlimit(300000)
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
# -------------------game starts now----------------------------------------------------import math
class TreeNode:
def __init__(self, k, v):
self.key = k
self.value = v
self.left = None
self.right = None
self.parent = None
self.height = 1
self.num_left = 1
self.num_total = 1
class AvlTree:
def __init__(self):
self._tree = None
def add(self, k, v):
if not self._tree:
self._tree = TreeNode(k, v)
return
node = self._add(k, v)
if node:
self._rebalance(node)
def _add(self, k, v):
node = self._tree
while node:
if k < node.key:
if node.left:
node = node.left
else:
node.left = TreeNode(k, v)
node.left.parent = node
return node.left
elif node.key < k:
if node.right:
node = node.right
else:
node.right = TreeNode(k, v)
node.right.parent = node
return node.right
else:
node.value = v
return
@staticmethod
def get_height(x):
return x.height if x else 0
@staticmethod
def get_num_total(x):
return x.num_total if x else 0
def _rebalance(self, node):
n = node
while n:
lh = self.get_height(n.left)
rh = self.get_height(n.right)
n.height = max(lh, rh) + 1
balance_factor = lh - rh
n.num_total = 1 + self.get_num_total(n.left) + self.get_num_total(n.right)
n.num_left = 1 + self.get_num_total(n.left)
if balance_factor > 1:
if self.get_height(n.left.left) < self.get_height(n.left.right):
self._rotate_left(n.left)
self._rotate_right(n)
elif balance_factor < -1:
if self.get_height(n.right.right) < self.get_height(n.right.left):
self._rotate_right(n.right)
self._rotate_left(n)
else:
n = n.parent
def _remove_one(self, node):
"""
Side effect!!! Changes node. Node should have exactly one child
"""
replacement = node.left or node.right
if node.parent:
if AvlTree._is_left(node):
node.parent.left = replacement
else:
node.parent.right = replacement
replacement.parent = node.parent
node.parent = None
else:
self._tree = replacement
replacement.parent = None
node.left = None
node.right = None
node.parent = None
self._rebalance(replacement)
def _remove_leaf(self, node):
if node.parent:
if AvlTree._is_left(node):
node.parent.left = None
else:
node.parent.right = None
self._rebalance(node.parent)
else:
self._tree = None
node.parent = None
node.left = None
node.right = None
def remove(self, k):
node = self._get_node(k)
if not node:
return
if AvlTree._is_leaf(node):
self._remove_leaf(node)
return
if node.left and node.right:
nxt = AvlTree._get_next(node)
node.key = nxt.key
node.value = nxt.value
if self._is_leaf(nxt):
self._remove_leaf(nxt)
else:
self._remove_one(nxt)
self._rebalance(node)
else:
self._remove_one(node)
def get(self, k):
node = self._get_node(k)
return node.value if node else -1
def _get_node(self, k):
if not self._tree:
return None
node = self._tree
while node:
if k < node.key:
node = node.left
elif node.key < k:
node = node.right
else:
return node
return None
def get_at(self, pos):
x = pos + 1
node = self._tree
while node:
if x < node.num_left:
node = node.left
elif node.num_left < x:
x -= node.num_left
node = node.right
else:
return (node.key, node.value)
raise IndexError("Out of ranges")
@staticmethod
def _is_left(node):
return node.parent.left and node.parent.left == node
@staticmethod
def _is_leaf(node):
return node.left is None and node.right is None
def _rotate_right(self, node):
if not node.parent:
self._tree = node.left
node.left.parent = None
elif AvlTree._is_left(node):
node.parent.left = node.left
node.left.parent = node.parent
else:
node.parent.right = node.left
node.left.parent = node.parent
bk = node.left.right
node.left.right = node
node.parent = node.left
node.left = bk
if bk:
bk.parent = node
node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
node.num_left = 1 + self.get_num_total(node.left)
def _rotate_left(self, node):
if not node.parent:
self._tree = node.right
node.right.parent = None
elif AvlTree._is_left(node):
node.parent.left = node.right
node.right.parent = node.parent
else:
node.parent.right = node.right
node.right.parent = node.parent
bk = node.right.left
node.right.left = node
node.parent = node.right
node.right = bk
if bk:
bk.parent = node
node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
node.num_left = 1 + self.get_num_total(node.left)
@staticmethod
def _get_next(node):
if not node.right:
return node.parent
n = node.right
while n.left:
n = n.left
return n
# -----------------------------------------------binary seacrh tree---------------------------------------
class SegmentTree1:
def __init__(self, data, default=2**51, func=lambda a, b: a & b):
"""initialize the segment tree with data"""
self._default = default
self._func = func
self._len = len(data)
self._size = _size = 1 << (self._len - 1).bit_length()
self.data = [default] * (2 * _size)
self.data[_size:_size + self._len] = data
for i in reversed(range(_size)):
self.data[i] = func(self.data[i + i], self.data[i + i + 1])
def __delitem__(self, idx):
self[idx] = self._default
def __getitem__(self, idx):
return self.data[idx + self._size]
def __setitem__(self, idx, value):
idx += self._size
self.data[idx] = value
idx >>= 1
while idx:
self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
idx >>= 1
def __len__(self):
return self._len
def query(self, start, stop):
if start == stop:
return self.__getitem__(start)
stop += 1
start += self._size
stop += self._size
res = self._default
while start < stop:
if start & 1:
res = self._func(res, self.data[start])
start += 1
if stop & 1:
stop -= 1
res = self._func(res, self.data[stop])
start >>= 1
stop >>= 1
return res
def __repr__(self):
return "SegmentTree({0})".format(self.data)
# -------------------game starts now----------------------------------------------------import math
class SegmentTree:
def __init__(self, data, default=0, func=lambda a, b: max(a , b)):
"""initialize the segment tree with data"""
self._default = default
self._func = func
self._len = len(data)
self._size = _size = 1 << (self._len - 1).bit_length()
self.data = [default] * (2 * _size)
self.data[_size:_size + self._len] = data
for i in reversed(range(_size)):
self.data[i] = func(self.data[i + i], self.data[i + i + 1])
def __delitem__(self, idx):
self[idx] = self._default
def __getitem__(self, idx):
return self.data[idx + self._size]
def __setitem__(self, idx, value):
idx += self._size
self.data[idx] = value
idx >>= 1
while idx:
self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
idx >>= 1
def __len__(self):
return self._len
def query(self, start, stop):
if start == stop:
return self.__getitem__(start)
stop += 1
start += self._size
stop += self._size
res = self._default
while start < stop:
if start & 1:
res = self._func(res, self.data[start])
start += 1
if stop & 1:
stop -= 1
res = self._func(res, self.data[stop])
start >>= 1
stop >>= 1
return res
def __repr__(self):
return "SegmentTree({0})".format(self.data)
# -------------------------------iye ha chutiya zindegi-------------------------------------
class Factorial:
def __init__(self, MOD):
self.MOD = MOD
self.factorials = [1, 1]
self.invModulos = [0, 1]
self.invFactorial_ = [1, 1]
def calc(self, n):
if n <= -1:
print("Invalid argument to calculate n!")
print("n must be non-negative value. But the argument was " + str(n))
exit()
if n < len(self.factorials):
return self.factorials[n]
nextArr = [0] * (n + 1 - len(self.factorials))
initialI = len(self.factorials)
prev = self.factorials[-1]
m = self.MOD
for i in range(initialI, n + 1):
prev = nextArr[i - initialI] = prev * i % m
self.factorials += nextArr
return self.factorials[n]
def inv(self, n):
if n <= -1:
print("Invalid argument to calculate n^(-1)")
print("n must be non-negative value. But the argument was " + str(n))
exit()
p = self.MOD
pi = n % p
if pi < len(self.invModulos):
return self.invModulos[pi]
nextArr = [0] * (n + 1 - len(self.invModulos))
initialI = len(self.invModulos)
for i in range(initialI, min(p, n + 1)):
next = -self.invModulos[p % i] * (p // i) % p
self.invModulos.append(next)
return self.invModulos[pi]
def invFactorial(self, n):
if n <= -1:
print("Invalid argument to calculate (n^(-1))!")
print("n must be non-negative value. But the argument was " + str(n))
exit()
if n < len(self.invFactorial_):
return self.invFactorial_[n]
self.inv(n) # To make sure already calculated n^-1
nextArr = [0] * (n + 1 - len(self.invFactorial_))
initialI = len(self.invFactorial_)
prev = self.invFactorial_[-1]
p = self.MOD
for i in range(initialI, n + 1):
prev = nextArr[i - initialI] = (prev * self.invModulos[i % p]) % p
self.invFactorial_ += nextArr
return self.invFactorial_[n]
class Combination:
def __init__(self, MOD):
self.MOD = MOD
self.factorial = Factorial(MOD)
def ncr(self, n, k):
if k < 0 or n < k:
return 0
k = min(k, n - k)
f = self.factorial
return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD
# --------------------------------------iye ha combinations ka zindegi---------------------------------
def powm(a, n, m):
if a == 1 or n == 0:
return 1
if n % 2 == 0:
s = powm(a, n // 2, m)
return s * s % m
else:
return a * powm(a, n - 1, m) % m
# --------------------------------------iye ha power ka zindegi---------------------------------
def sort_list(list1, list2):
zipped_pairs = zip(list2, list1)
z = [x for _, x in sorted(zipped_pairs)]
return z
# --------------------------------------------------product----------------------------------------
def product(l):
por = 1
for i in range(len(l)):
por *= l[i]
return por
# --------------------------------------------------binary----------------------------------------
def binarySearchCount(arr, n, key):
left = 0
right = n - 1
count = 0
while (left <= right):
mid = int((right + left) / 2)
# Check if middle element is
# less than or equal to key
if (arr[mid] < key):
count = mid + 1
left = mid + 1
# If key is smaller, ignore right half
else:
right = mid - 1
return count
# --------------------------------------------------binary----------------------------------------
def countdig(n):
c = 0
while (n > 0):
n //= 10
c += 1
return c
def binary(x, length):
y = bin(x)[2:]
return y if len(y) >= length else "0" * (length - len(y)) + y
def countGreater(arr, n, k):
l = 0
r = n - 1
# Stores the index of the left most element
# from the array which is greater than k
leftGreater = n
# Finds number of elements greater than k
while (l <= r):
m = int(l + (r - l) / 2)
if (arr[m] >= k):
leftGreater = m
r = m - 1
# If mid element is less than
# or equal to k update l
else:
l = m + 1
# Return the count of elements
# greater than k
return (n - leftGreater)
# --------------------------------------------------binary------------------------------------
n,d=map(int,input().split())
l=list(map(int,input().split()))
m=[-10**10]*n
bal=0
ans=0
for i in range(n-1,-1,-1):
if l[i]!=0:
bal+=l[i]
if bal<=0:
bal=0
m[i]=max(bal,m[i])
bal=0
for i in range(n):
if l[i]!=0:
bal+=l[i]
if bal>d:
print(-1)
sys.exit(0)
else:
if bal>=0:
continue
else:
if m[i]>d:
print(-1)
sys.exit(0)
else:
ans+=1
bal=d-m[i]
print(ans)
``` | output | 1 | 86,237 | 10 | 172,475 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Recenlty Luba got a credit card and started to use it. Let's consider n consecutive days Luba uses the card.
She starts with 0 money on her account.
In the evening of i-th day a transaction ai occurs. If ai > 0, then ai bourles are deposited to Luba's account. If ai < 0, then ai bourles are withdrawn. And if ai = 0, then the amount of money on Luba's account is checked.
In the morning of any of n days Luba can go to the bank and deposit any positive integer amount of burles to her account. But there is a limitation: the amount of money on the account can never exceed d.
It can happen that the amount of money goes greater than d by some transaction in the evening. In this case answer will be «-1».
Luba must not exceed this limit, and also she wants that every day her account is checked (the days when ai = 0) the amount of money on her account is non-negative. It takes a lot of time to go to the bank, so Luba wants to know the minimum number of days she needs to deposit some money to her account (if it is possible to meet all the requirements). Help her!
Input
The first line contains two integers n, d (1 ≤ n ≤ 105, 1 ≤ d ≤ 109) —the number of days and the money limitation.
The second line contains n integer numbers a1, a2, ... an ( - 104 ≤ ai ≤ 104), where ai represents the transaction in i-th day.
Output
Print -1 if Luba cannot deposit the money to her account in such a way that the requirements are met. Otherwise print the minimum number of days Luba has to deposit money.
Examples
Input
5 10
-1 5 0 -5 3
Output
0
Input
3 4
-10 0 20
Output
-1
Input
5 10
-5 0 10 -11 0
Output
2 | instruction | 0 | 86,238 | 10 | 172,476 |
Tags: data structures, dp, greedy, implementation
Correct Solution:
```
f = lambda: map(int, input().split())
n, d = f()
h = s = k = 0
for q in f():
h, s = h + q, min(d, s + q)
if h > d:
k = -1
break
if q == 0:
h = max(0, h)
if s < 0: s, k = d, k + 1
print(k)
``` | output | 1 | 86,238 | 10 | 172,477 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Recenlty Luba got a credit card and started to use it. Let's consider n consecutive days Luba uses the card.
She starts with 0 money on her account.
In the evening of i-th day a transaction ai occurs. If ai > 0, then ai bourles are deposited to Luba's account. If ai < 0, then ai bourles are withdrawn. And if ai = 0, then the amount of money on Luba's account is checked.
In the morning of any of n days Luba can go to the bank and deposit any positive integer amount of burles to her account. But there is a limitation: the amount of money on the account can never exceed d.
It can happen that the amount of money goes greater than d by some transaction in the evening. In this case answer will be «-1».
Luba must not exceed this limit, and also she wants that every day her account is checked (the days when ai = 0) the amount of money on her account is non-negative. It takes a lot of time to go to the bank, so Luba wants to know the minimum number of days she needs to deposit some money to her account (if it is possible to meet all the requirements). Help her!
Input
The first line contains two integers n, d (1 ≤ n ≤ 105, 1 ≤ d ≤ 109) —the number of days and the money limitation.
The second line contains n integer numbers a1, a2, ... an ( - 104 ≤ ai ≤ 104), where ai represents the transaction in i-th day.
Output
Print -1 if Luba cannot deposit the money to her account in such a way that the requirements are met. Otherwise print the minimum number of days Luba has to deposit money.
Examples
Input
5 10
-1 5 0 -5 3
Output
0
Input
3 4
-10 0 20
Output
-1
Input
5 10
-5 0 10 -11 0
Output
2
Submitted Solution:
```
[n, d] = [int(x) for x in input().split(' ')]
A = [int(a) for a in input().split(' ')]
def solve():
ans = 0
bal = 0
minGap = 0
for i in range(n):
if A[i] == 0:
if bal < 0:
go = min(-bal, minGap)
minGap -= go
bal += go
if bal < 0:
ans += 1
bal = 0
minGap = d
else:
bal += A[i]
if bal > d:
return -1
minGap = min(minGap, d - bal)
return ans
print(solve())
``` | instruction | 0 | 86,239 | 10 | 172,478 |
Yes | output | 1 | 86,239 | 10 | 172,479 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Recenlty Luba got a credit card and started to use it. Let's consider n consecutive days Luba uses the card.
She starts with 0 money on her account.
In the evening of i-th day a transaction ai occurs. If ai > 0, then ai bourles are deposited to Luba's account. If ai < 0, then ai bourles are withdrawn. And if ai = 0, then the amount of money on Luba's account is checked.
In the morning of any of n days Luba can go to the bank and deposit any positive integer amount of burles to her account. But there is a limitation: the amount of money on the account can never exceed d.
It can happen that the amount of money goes greater than d by some transaction in the evening. In this case answer will be «-1».
Luba must not exceed this limit, and also she wants that every day her account is checked (the days when ai = 0) the amount of money on her account is non-negative. It takes a lot of time to go to the bank, so Luba wants to know the minimum number of days she needs to deposit some money to her account (if it is possible to meet all the requirements). Help her!
Input
The first line contains two integers n, d (1 ≤ n ≤ 105, 1 ≤ d ≤ 109) —the number of days and the money limitation.
The second line contains n integer numbers a1, a2, ... an ( - 104 ≤ ai ≤ 104), where ai represents the transaction in i-th day.
Output
Print -1 if Luba cannot deposit the money to her account in such a way that the requirements are met. Otherwise print the minimum number of days Luba has to deposit money.
Examples
Input
5 10
-1 5 0 -5 3
Output
0
Input
3 4
-10 0 20
Output
-1
Input
5 10
-5 0 10 -11 0
Output
2
Submitted Solution:
```
H,L,t=0,0,0
n,d=map(int,input().split())
for i in map(int,input().split()):
if i==0:
if H<0:H=d;t+=1
L=max(L,0)
L+=i
H=min(d,H+i)
if L>d:exit(print(-1))
print(t)
``` | instruction | 0 | 86,240 | 10 | 172,480 |
Yes | output | 1 | 86,240 | 10 | 172,481 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Recenlty Luba got a credit card and started to use it. Let's consider n consecutive days Luba uses the card.
She starts with 0 money on her account.
In the evening of i-th day a transaction ai occurs. If ai > 0, then ai bourles are deposited to Luba's account. If ai < 0, then ai bourles are withdrawn. And if ai = 0, then the amount of money on Luba's account is checked.
In the morning of any of n days Luba can go to the bank and deposit any positive integer amount of burles to her account. But there is a limitation: the amount of money on the account can never exceed d.
It can happen that the amount of money goes greater than d by some transaction in the evening. In this case answer will be «-1».
Luba must not exceed this limit, and also she wants that every day her account is checked (the days when ai = 0) the amount of money on her account is non-negative. It takes a lot of time to go to the bank, so Luba wants to know the minimum number of days she needs to deposit some money to her account (if it is possible to meet all the requirements). Help her!
Input
The first line contains two integers n, d (1 ≤ n ≤ 105, 1 ≤ d ≤ 109) —the number of days and the money limitation.
The second line contains n integer numbers a1, a2, ... an ( - 104 ≤ ai ≤ 104), where ai represents the transaction in i-th day.
Output
Print -1 if Luba cannot deposit the money to her account in such a way that the requirements are met. Otherwise print the minimum number of days Luba has to deposit money.
Examples
Input
5 10
-1 5 0 -5 3
Output
0
Input
3 4
-10 0 20
Output
-1
Input
5 10
-5 0 10 -11 0
Output
2
Submitted Solution:
```
R = lambda: map(int, input().split())
n, k = R()
arr = list(R())
tup = [0, 0]
res = 0
for x in arr:
if x != 0:
tup[0], tup[1] = tup[0] + x, tup[1] + x
tup[1] = min(tup[1], k)
elif tup[1] < 0:
tup[0], tup[1] = 0, k
res += 1
else:
tup[0] = max(0, tup[0])
if tup[0] > k:
res = -1
break
print(res)
``` | instruction | 0 | 86,241 | 10 | 172,482 |
Yes | output | 1 | 86,241 | 10 | 172,483 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Recenlty Luba got a credit card and started to use it. Let's consider n consecutive days Luba uses the card.
She starts with 0 money on her account.
In the evening of i-th day a transaction ai occurs. If ai > 0, then ai bourles are deposited to Luba's account. If ai < 0, then ai bourles are withdrawn. And if ai = 0, then the amount of money on Luba's account is checked.
In the morning of any of n days Luba can go to the bank and deposit any positive integer amount of burles to her account. But there is a limitation: the amount of money on the account can never exceed d.
It can happen that the amount of money goes greater than d by some transaction in the evening. In this case answer will be «-1».
Luba must not exceed this limit, and also she wants that every day her account is checked (the days when ai = 0) the amount of money on her account is non-negative. It takes a lot of time to go to the bank, so Luba wants to know the minimum number of days she needs to deposit some money to her account (if it is possible to meet all the requirements). Help her!
Input
The first line contains two integers n, d (1 ≤ n ≤ 105, 1 ≤ d ≤ 109) —the number of days and the money limitation.
The second line contains n integer numbers a1, a2, ... an ( - 104 ≤ ai ≤ 104), where ai represents the transaction in i-th day.
Output
Print -1 if Luba cannot deposit the money to her account in such a way that the requirements are met. Otherwise print the minimum number of days Luba has to deposit money.
Examples
Input
5 10
-1 5 0 -5 3
Output
0
Input
3 4
-10 0 20
Output
-1
Input
5 10
-5 0 10 -11 0
Output
2
Submitted Solution:
```
def main():
n, d = map(int, input().split())
a = list(map(int, input().split()))
pref, mx, add, ans = [0] * n, [0] * n, 0, 0
for pos in range(n):
pref[pos] = a[pos] if not pos else a[pos] + pref[pos-1]
for pos in range(n-1, -1, -1):
mx[pos] = pref[pos] if pos == n - 1 else max(mx[pos + 1], pref[pos])
for i in range(n):
if pref[i] + add > d:
print("-1")
return
if a[i] == 0 and pref[i] + add < 0:
ans += 1
add += max(-(pref[i] + add), d - mx[i] - add)
print(ans)
if __name__ == "__main__":
main()
``` | instruction | 0 | 86,242 | 10 | 172,484 |
Yes | output | 1 | 86,242 | 10 | 172,485 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Recenlty Luba got a credit card and started to use it. Let's consider n consecutive days Luba uses the card.
She starts with 0 money on her account.
In the evening of i-th day a transaction ai occurs. If ai > 0, then ai bourles are deposited to Luba's account. If ai < 0, then ai bourles are withdrawn. And if ai = 0, then the amount of money on Luba's account is checked.
In the morning of any of n days Luba can go to the bank and deposit any positive integer amount of burles to her account. But there is a limitation: the amount of money on the account can never exceed d.
It can happen that the amount of money goes greater than d by some transaction in the evening. In this case answer will be «-1».
Luba must not exceed this limit, and also she wants that every day her account is checked (the days when ai = 0) the amount of money on her account is non-negative. It takes a lot of time to go to the bank, so Luba wants to know the minimum number of days she needs to deposit some money to her account (if it is possible to meet all the requirements). Help her!
Input
The first line contains two integers n, d (1 ≤ n ≤ 105, 1 ≤ d ≤ 109) —the number of days and the money limitation.
The second line contains n integer numbers a1, a2, ... an ( - 104 ≤ ai ≤ 104), where ai represents the transaction in i-th day.
Output
Print -1 if Luba cannot deposit the money to her account in such a way that the requirements are met. Otherwise print the minimum number of days Luba has to deposit money.
Examples
Input
5 10
-1 5 0 -5 3
Output
0
Input
3 4
-10 0 20
Output
-1
Input
5 10
-5 0 10 -11 0
Output
2
Submitted Solution:
```
a, b = map(int,input().split())
c = list(map(int,input().split()))
k = 0
n = 0
for i in range(a):
k += c[i]
if c[i] == 0 and k < 0:
n += 1
k = 0
if k > b:
n = -1
break
print(n)
``` | instruction | 0 | 86,243 | 10 | 172,486 |
No | output | 1 | 86,243 | 10 | 172,487 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Recenlty Luba got a credit card and started to use it. Let's consider n consecutive days Luba uses the card.
She starts with 0 money on her account.
In the evening of i-th day a transaction ai occurs. If ai > 0, then ai bourles are deposited to Luba's account. If ai < 0, then ai bourles are withdrawn. And if ai = 0, then the amount of money on Luba's account is checked.
In the morning of any of n days Luba can go to the bank and deposit any positive integer amount of burles to her account. But there is a limitation: the amount of money on the account can never exceed d.
It can happen that the amount of money goes greater than d by some transaction in the evening. In this case answer will be «-1».
Luba must not exceed this limit, and also she wants that every day her account is checked (the days when ai = 0) the amount of money on her account is non-negative. It takes a lot of time to go to the bank, so Luba wants to know the minimum number of days she needs to deposit some money to her account (if it is possible to meet all the requirements). Help her!
Input
The first line contains two integers n, d (1 ≤ n ≤ 105, 1 ≤ d ≤ 109) —the number of days and the money limitation.
The second line contains n integer numbers a1, a2, ... an ( - 104 ≤ ai ≤ 104), where ai represents the transaction in i-th day.
Output
Print -1 if Luba cannot deposit the money to her account in such a way that the requirements are met. Otherwise print the minimum number of days Luba has to deposit money.
Examples
Input
5 10
-1 5 0 -5 3
Output
0
Input
3 4
-10 0 20
Output
-1
Input
5 10
-5 0 10 -11 0
Output
2
Submitted Solution:
```
n, k = map(int, input().split())
x = 0
mass = list(map(int, input().split()))
for i in range(len(mass)):
if mass[i] > k:
print(-1)
exit()
if mass[i] == 0:
if sum(mass[:i]) > k:
print(-1)
exit()
if sum(mass[:i]) < 0:
x += 1
print(x)
``` | instruction | 0 | 86,244 | 10 | 172,488 |
No | output | 1 | 86,244 | 10 | 172,489 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Recenlty Luba got a credit card and started to use it. Let's consider n consecutive days Luba uses the card.
She starts with 0 money on her account.
In the evening of i-th day a transaction ai occurs. If ai > 0, then ai bourles are deposited to Luba's account. If ai < 0, then ai bourles are withdrawn. And if ai = 0, then the amount of money on Luba's account is checked.
In the morning of any of n days Luba can go to the bank and deposit any positive integer amount of burles to her account. But there is a limitation: the amount of money on the account can never exceed d.
It can happen that the amount of money goes greater than d by some transaction in the evening. In this case answer will be «-1».
Luba must not exceed this limit, and also she wants that every day her account is checked (the days when ai = 0) the amount of money on her account is non-negative. It takes a lot of time to go to the bank, so Luba wants to know the minimum number of days she needs to deposit some money to her account (if it is possible to meet all the requirements). Help her!
Input
The first line contains two integers n, d (1 ≤ n ≤ 105, 1 ≤ d ≤ 109) —the number of days and the money limitation.
The second line contains n integer numbers a1, a2, ... an ( - 104 ≤ ai ≤ 104), where ai represents the transaction in i-th day.
Output
Print -1 if Luba cannot deposit the money to her account in such a way that the requirements are met. Otherwise print the minimum number of days Luba has to deposit money.
Examples
Input
5 10
-1 5 0 -5 3
Output
0
Input
3 4
-10 0 20
Output
-1
Input
5 10
-5 0 10 -11 0
Output
2
Submitted Solution:
```
import os
import sys
def log(*args, **kwargs):
if os.environ.get('CODEFR'):
print(*args, **kwargs)
#n = int(input())
n, d = tuple(map(int,input().split()))
a = list(map(int,input().split()))
s = 0
k = 0
for i in a:
if i == 0:
if s < 0:
if -s > d:
print(-1)
sys.exit(0)
k += 1
else:
s += i
if s > d:
print(-1)
sys.exit(0)
print(k)
``` | instruction | 0 | 86,245 | 10 | 172,490 |
No | output | 1 | 86,245 | 10 | 172,491 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Recenlty Luba got a credit card and started to use it. Let's consider n consecutive days Luba uses the card.
She starts with 0 money on her account.
In the evening of i-th day a transaction ai occurs. If ai > 0, then ai bourles are deposited to Luba's account. If ai < 0, then ai bourles are withdrawn. And if ai = 0, then the amount of money on Luba's account is checked.
In the morning of any of n days Luba can go to the bank and deposit any positive integer amount of burles to her account. But there is a limitation: the amount of money on the account can never exceed d.
It can happen that the amount of money goes greater than d by some transaction in the evening. In this case answer will be «-1».
Luba must not exceed this limit, and also she wants that every day her account is checked (the days when ai = 0) the amount of money on her account is non-negative. It takes a lot of time to go to the bank, so Luba wants to know the minimum number of days she needs to deposit some money to her account (if it is possible to meet all the requirements). Help her!
Input
The first line contains two integers n, d (1 ≤ n ≤ 105, 1 ≤ d ≤ 109) —the number of days and the money limitation.
The second line contains n integer numbers a1, a2, ... an ( - 104 ≤ ai ≤ 104), where ai represents the transaction in i-th day.
Output
Print -1 if Luba cannot deposit the money to her account in such a way that the requirements are met. Otherwise print the minimum number of days Luba has to deposit money.
Examples
Input
5 10
-1 5 0 -5 3
Output
0
Input
3 4
-10 0 20
Output
-1
Input
5 10
-5 0 10 -11 0
Output
2
Submitted Solution:
```
[n, d] = [int(x) for x in input().split(' ')]
A = [int(a) for a in input().split(' ')]
minBals = []
for i in range(n):
if i == 0:
minBals.append(A[i])
elif A[i] == 0:
if minBals[-1] > 0:
minBals.append(minBals[-1])
else:
minBals.append(0)
else:
minBals.append(A[i]+minBals[-1])
def solve():
go = 0
deltaSum = 0
if max(minBals) > d:
return -1
for i in range(1, n):
if A[i] == 0 and minBals[i-1] + deltaSum < 0:
maxBal = max(minBals[i:])
go += 1
delta = d - maxBal
deltaSum += delta
if delta < 0:
return -1
return go
print(solve())
``` | instruction | 0 | 86,246 | 10 | 172,492 |
No | output | 1 | 86,246 | 10 | 172,493 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Ringo Mart, a convenience store, sells apple juice.
On the opening day of Ringo Mart, there were A cans of juice in stock in the morning. Snuke buys B cans of juice here every day in the daytime. Then, the manager checks the number of cans of juice remaining in stock every night. If there are C or less cans, D new cans will be added to the stock by the next morning.
Determine if Snuke can buy juice indefinitely, that is, there is always B or more cans of juice in stock when he attempts to buy them. Nobody besides Snuke buy juice at this store.
Note that each test case in this problem consists of T queries.
Constraints
* 1 \leq T \leq 300
* 1 \leq A, B, C, D \leq 10^{18}
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
T
A_1 B_1 C_1 D_1
A_2 B_2 C_2 D_2
:
A_T B_T C_T D_T
In the i-th query, A = A_i, B = B_i, C = C_i, D = D_i.
Output
Print T lines. The i-th line should contain `Yes` if Snuke can buy apple juice indefinitely in the i-th query; `No` otherwise.
Examples
Input
14
9 7 5 9
9 7 6 9
14 10 7 12
14 10 8 12
14 10 9 12
14 10 7 11
14 10 8 11
14 10 9 11
9 10 5 10
10 10 5 10
11 10 5 10
16 10 5 10
1000000000000000000 17 14 999999999999999985
1000000000000000000 17 15 999999999999999985
Output
No
Yes
No
Yes
Yes
No
No
Yes
No
Yes
Yes
No
No
Yes
Input
24
1 2 3 4
1 2 4 3
1 3 2 4
1 3 4 2
1 4 2 3
1 4 3 2
2 1 3 4
2 1 4 3
2 3 1 4
2 3 4 1
2 4 1 3
2 4 3 1
3 1 2 4
3 1 4 2
3 2 1 4
3 2 4 1
3 4 1 2
3 4 2 1
4 1 2 3
4 1 3 2
4 2 1 3
4 2 3 1
4 3 1 2
4 3 2 1
Output
No
No
No
No
No
No
Yes
Yes
No
No
No
No
Yes
Yes
Yes
No
No
No
Yes
Yes
Yes
No
No
No
Submitted Solution:
```
import sys
input = sys.stdin.readline
from fractions import gcd
def f(a,b,c,d):
if a<b:
return 0
if b>d:
return 0
if b-1<=c:
return 1
x=a%b
#print(3)
if b==d:
if c<x:
return 0
elif c>=x:
return 1
#print(4)
if c<x:
return 0
e=(d-b)%b
d1=gcd(e,b)
q=(c+1-x)//d1
q1=(b-1-x)//d1
#print(d1,q,q1,x,(c+1-x)%d1)
if q<q1:
return 0
if (c+1-x)%d1==0:
return 0
return 1
T=int(input())
X=[[int(i) for i in input().split()] for i in range(T)]
for a,b,c,d in X:
s=f(a,b,c,d)
if s:
print('Yes')
else:
print('No')
``` | instruction | 0 | 86,377 | 10 | 172,754 |
Yes | output | 1 | 86,377 | 10 | 172,755 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Ringo Mart, a convenience store, sells apple juice.
On the opening day of Ringo Mart, there were A cans of juice in stock in the morning. Snuke buys B cans of juice here every day in the daytime. Then, the manager checks the number of cans of juice remaining in stock every night. If there are C or less cans, D new cans will be added to the stock by the next morning.
Determine if Snuke can buy juice indefinitely, that is, there is always B or more cans of juice in stock when he attempts to buy them. Nobody besides Snuke buy juice at this store.
Note that each test case in this problem consists of T queries.
Constraints
* 1 \leq T \leq 300
* 1 \leq A, B, C, D \leq 10^{18}
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
T
A_1 B_1 C_1 D_1
A_2 B_2 C_2 D_2
:
A_T B_T C_T D_T
In the i-th query, A = A_i, B = B_i, C = C_i, D = D_i.
Output
Print T lines. The i-th line should contain `Yes` if Snuke can buy apple juice indefinitely in the i-th query; `No` otherwise.
Examples
Input
14
9 7 5 9
9 7 6 9
14 10 7 12
14 10 8 12
14 10 9 12
14 10 7 11
14 10 8 11
14 10 9 11
9 10 5 10
10 10 5 10
11 10 5 10
16 10 5 10
1000000000000000000 17 14 999999999999999985
1000000000000000000 17 15 999999999999999985
Output
No
Yes
No
Yes
Yes
No
No
Yes
No
Yes
Yes
No
No
Yes
Input
24
1 2 3 4
1 2 4 3
1 3 2 4
1 3 4 2
1 4 2 3
1 4 3 2
2 1 3 4
2 1 4 3
2 3 1 4
2 3 4 1
2 4 1 3
2 4 3 1
3 1 2 4
3 1 4 2
3 2 1 4
3 2 4 1
3 4 1 2
3 4 2 1
4 1 2 3
4 1 3 2
4 2 1 3
4 2 3 1
4 3 1 2
4 3 2 1
Output
No
No
No
No
No
No
Yes
Yes
No
No
No
No
Yes
Yes
Yes
No
No
No
Yes
Yes
Yes
No
No
No
Submitted Solution:
```
def gcd(a, b):
return a if b == 0 else gcd(b, a % b)
def solve(a, b, c, d):
if a < b or d < b:
return False
if b < c:
return True
g = gcd(b, d)
return (b + a % g - g) <= c
T, *L = map(int, open(0).read().split())
for t in zip(*[iter(L)] * 4):
print("Yes" if solve(*t) else "No")
``` | instruction | 0 | 86,378 | 10 | 172,756 |
Yes | output | 1 | 86,378 | 10 | 172,757 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Ringo Mart, a convenience store, sells apple juice.
On the opening day of Ringo Mart, there were A cans of juice in stock in the morning. Snuke buys B cans of juice here every day in the daytime. Then, the manager checks the number of cans of juice remaining in stock every night. If there are C or less cans, D new cans will be added to the stock by the next morning.
Determine if Snuke can buy juice indefinitely, that is, there is always B or more cans of juice in stock when he attempts to buy them. Nobody besides Snuke buy juice at this store.
Note that each test case in this problem consists of T queries.
Constraints
* 1 \leq T \leq 300
* 1 \leq A, B, C, D \leq 10^{18}
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
T
A_1 B_1 C_1 D_1
A_2 B_2 C_2 D_2
:
A_T B_T C_T D_T
In the i-th query, A = A_i, B = B_i, C = C_i, D = D_i.
Output
Print T lines. The i-th line should contain `Yes` if Snuke can buy apple juice indefinitely in the i-th query; `No` otherwise.
Examples
Input
14
9 7 5 9
9 7 6 9
14 10 7 12
14 10 8 12
14 10 9 12
14 10 7 11
14 10 8 11
14 10 9 11
9 10 5 10
10 10 5 10
11 10 5 10
16 10 5 10
1000000000000000000 17 14 999999999999999985
1000000000000000000 17 15 999999999999999985
Output
No
Yes
No
Yes
Yes
No
No
Yes
No
Yes
Yes
No
No
Yes
Input
24
1 2 3 4
1 2 4 3
1 3 2 4
1 3 4 2
1 4 2 3
1 4 3 2
2 1 3 4
2 1 4 3
2 3 1 4
2 3 4 1
2 4 1 3
2 4 3 1
3 1 2 4
3 1 4 2
3 2 1 4
3 2 4 1
3 4 1 2
3 4 2 1
4 1 2 3
4 1 3 2
4 2 1 3
4 2 3 1
4 3 1 2
4 3 2 1
Output
No
No
No
No
No
No
Yes
Yes
No
No
No
No
Yes
Yes
Yes
No
No
No
Yes
Yes
Yes
No
No
No
Submitted Solution:
```
def gcd(a, b):
while b:
a, b = b, a % b
return(a)
T = int(input())
for i in range(T):
A,B,C,D = map(int,input().split())
if B > D:
print('No')
elif A < B:
print('No')
elif C + 1 >= B:
print('Yes')
else:
q = gcd(B,D)
r = (A-C)%q
if r == 0:
r = q
if C + r >= B:
print('Yes')
else:
print('No')
``` | instruction | 0 | 86,379 | 10 | 172,758 |
Yes | output | 1 | 86,379 | 10 | 172,759 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Ringo Mart, a convenience store, sells apple juice.
On the opening day of Ringo Mart, there were A cans of juice in stock in the morning. Snuke buys B cans of juice here every day in the daytime. Then, the manager checks the number of cans of juice remaining in stock every night. If there are C or less cans, D new cans will be added to the stock by the next morning.
Determine if Snuke can buy juice indefinitely, that is, there is always B or more cans of juice in stock when he attempts to buy them. Nobody besides Snuke buy juice at this store.
Note that each test case in this problem consists of T queries.
Constraints
* 1 \leq T \leq 300
* 1 \leq A, B, C, D \leq 10^{18}
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
T
A_1 B_1 C_1 D_1
A_2 B_2 C_2 D_2
:
A_T B_T C_T D_T
In the i-th query, A = A_i, B = B_i, C = C_i, D = D_i.
Output
Print T lines. The i-th line should contain `Yes` if Snuke can buy apple juice indefinitely in the i-th query; `No` otherwise.
Examples
Input
14
9 7 5 9
9 7 6 9
14 10 7 12
14 10 8 12
14 10 9 12
14 10 7 11
14 10 8 11
14 10 9 11
9 10 5 10
10 10 5 10
11 10 5 10
16 10 5 10
1000000000000000000 17 14 999999999999999985
1000000000000000000 17 15 999999999999999985
Output
No
Yes
No
Yes
Yes
No
No
Yes
No
Yes
Yes
No
No
Yes
Input
24
1 2 3 4
1 2 4 3
1 3 2 4
1 3 4 2
1 4 2 3
1 4 3 2
2 1 3 4
2 1 4 3
2 3 1 4
2 3 4 1
2 4 1 3
2 4 3 1
3 1 2 4
3 1 4 2
3 2 1 4
3 2 4 1
3 4 1 2
3 4 2 1
4 1 2 3
4 1 3 2
4 2 1 3
4 2 3 1
4 3 1 2
4 3 2 1
Output
No
No
No
No
No
No
Yes
Yes
No
No
No
No
Yes
Yes
Yes
No
No
No
Yes
Yes
Yes
No
No
No
Submitted Solution:
```
# -*- coding: utf-8 -*-
import sys
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 19
MOD = 10 ** 9 + 7
def bisearch_min(mn, mx, func):
""" 条件を満たす最小値を見つける二分探索 """
ok = mx
ng = mn
while ng+1 < ok:
mid = (ok+ng) // 2
if func(mid):
# 下を探しに行く
ok = mid
else:
# 上を探しに行く
ng = mid
return ok
def bisearch_max(mn, mx, func):
""" 条件を満たす最大値を見つける二分探索 """
ok = mn
ng = mx
while ok+1 < ng:
mid = (ok+ng) // 2
if func(mid):
# 上を探しに行く
ok = mid
else:
# 下を探しに行く
ng = mid
return ok
for _ in range(INT()):
a, b, c, d = MAP()
# そもそも無理
if a < b or d < b:
No()
continue
# b個減ってd個増える繰り返しなので、このgより細かく値が動くことはない
g = gcd(b, d)
# cより大きくてb未満が存在するかどうか
mn = bisearch_min(-INF, INF, lambda m: a%g + g*m > c)
mx = bisearch_max(-INF, INF, lambda m: a%g + g*m < b)
if mn > mx:
Yes()
else:
No()
``` | instruction | 0 | 86,380 | 10 | 172,760 |
Yes | output | 1 | 86,380 | 10 | 172,761 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Ringo Mart, a convenience store, sells apple juice.
On the opening day of Ringo Mart, there were A cans of juice in stock in the morning. Snuke buys B cans of juice here every day in the daytime. Then, the manager checks the number of cans of juice remaining in stock every night. If there are C or less cans, D new cans will be added to the stock by the next morning.
Determine if Snuke can buy juice indefinitely, that is, there is always B or more cans of juice in stock when he attempts to buy them. Nobody besides Snuke buy juice at this store.
Note that each test case in this problem consists of T queries.
Constraints
* 1 \leq T \leq 300
* 1 \leq A, B, C, D \leq 10^{18}
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
T
A_1 B_1 C_1 D_1
A_2 B_2 C_2 D_2
:
A_T B_T C_T D_T
In the i-th query, A = A_i, B = B_i, C = C_i, D = D_i.
Output
Print T lines. The i-th line should contain `Yes` if Snuke can buy apple juice indefinitely in the i-th query; `No` otherwise.
Examples
Input
14
9 7 5 9
9 7 6 9
14 10 7 12
14 10 8 12
14 10 9 12
14 10 7 11
14 10 8 11
14 10 9 11
9 10 5 10
10 10 5 10
11 10 5 10
16 10 5 10
1000000000000000000 17 14 999999999999999985
1000000000000000000 17 15 999999999999999985
Output
No
Yes
No
Yes
Yes
No
No
Yes
No
Yes
Yes
No
No
Yes
Input
24
1 2 3 4
1 2 4 3
1 3 2 4
1 3 4 2
1 4 2 3
1 4 3 2
2 1 3 4
2 1 4 3
2 3 1 4
2 3 4 1
2 4 1 3
2 4 3 1
3 1 2 4
3 1 4 2
3 2 1 4
3 2 4 1
3 4 1 2
3 4 2 1
4 1 2 3
4 1 3 2
4 2 1 3
4 2 3 1
4 3 1 2
4 3 2 1
Output
No
No
No
No
No
No
Yes
Yes
No
No
No
No
Yes
Yes
Yes
No
No
No
Yes
Yes
Yes
No
No
No
Submitted Solution:
```
import math
T = int(input())
for i in range(T) :
A,B,C,D = map(int,input().split())
a1 = A-B
d = D-B
P = (C+d-a1)/d
Q = (B+d-a1)/d
PP = math.floor(P)
QQ = math.floor((Q))
if P != PP :
if PP != QQ :
print("No")
else :
print("Yes")
``` | instruction | 0 | 86,381 | 10 | 172,762 |
No | output | 1 | 86,381 | 10 | 172,763 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Ringo Mart, a convenience store, sells apple juice.
On the opening day of Ringo Mart, there were A cans of juice in stock in the morning. Snuke buys B cans of juice here every day in the daytime. Then, the manager checks the number of cans of juice remaining in stock every night. If there are C or less cans, D new cans will be added to the stock by the next morning.
Determine if Snuke can buy juice indefinitely, that is, there is always B or more cans of juice in stock when he attempts to buy them. Nobody besides Snuke buy juice at this store.
Note that each test case in this problem consists of T queries.
Constraints
* 1 \leq T \leq 300
* 1 \leq A, B, C, D \leq 10^{18}
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
T
A_1 B_1 C_1 D_1
A_2 B_2 C_2 D_2
:
A_T B_T C_T D_T
In the i-th query, A = A_i, B = B_i, C = C_i, D = D_i.
Output
Print T lines. The i-th line should contain `Yes` if Snuke can buy apple juice indefinitely in the i-th query; `No` otherwise.
Examples
Input
14
9 7 5 9
9 7 6 9
14 10 7 12
14 10 8 12
14 10 9 12
14 10 7 11
14 10 8 11
14 10 9 11
9 10 5 10
10 10 5 10
11 10 5 10
16 10 5 10
1000000000000000000 17 14 999999999999999985
1000000000000000000 17 15 999999999999999985
Output
No
Yes
No
Yes
Yes
No
No
Yes
No
Yes
Yes
No
No
Yes
Input
24
1 2 3 4
1 2 4 3
1 3 2 4
1 3 4 2
1 4 2 3
1 4 3 2
2 1 3 4
2 1 4 3
2 3 1 4
2 3 4 1
2 4 1 3
2 4 3 1
3 1 2 4
3 1 4 2
3 2 1 4
3 2 4 1
3 4 1 2
3 4 2 1
4 1 2 3
4 1 3 2
4 2 1 3
4 2 3 1
4 3 1 2
4 3 2 1
Output
No
No
No
No
No
No
Yes
Yes
No
No
No
No
Yes
Yes
Yes
No
No
No
Yes
Yes
Yes
No
No
No
Submitted Solution:
```
t = int(input())
for i in range(t):
a, b, c, d = map(int, input().split())
if a>=b and c >=b-1 and d>=b:
print("Yes")
else:
print("No")
``` | instruction | 0 | 86,382 | 10 | 172,764 |
No | output | 1 | 86,382 | 10 | 172,765 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Ringo Mart, a convenience store, sells apple juice.
On the opening day of Ringo Mart, there were A cans of juice in stock in the morning. Snuke buys B cans of juice here every day in the daytime. Then, the manager checks the number of cans of juice remaining in stock every night. If there are C or less cans, D new cans will be added to the stock by the next morning.
Determine if Snuke can buy juice indefinitely, that is, there is always B or more cans of juice in stock when he attempts to buy them. Nobody besides Snuke buy juice at this store.
Note that each test case in this problem consists of T queries.
Constraints
* 1 \leq T \leq 300
* 1 \leq A, B, C, D \leq 10^{18}
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
T
A_1 B_1 C_1 D_1
A_2 B_2 C_2 D_2
:
A_T B_T C_T D_T
In the i-th query, A = A_i, B = B_i, C = C_i, D = D_i.
Output
Print T lines. The i-th line should contain `Yes` if Snuke can buy apple juice indefinitely in the i-th query; `No` otherwise.
Examples
Input
14
9 7 5 9
9 7 6 9
14 10 7 12
14 10 8 12
14 10 9 12
14 10 7 11
14 10 8 11
14 10 9 11
9 10 5 10
10 10 5 10
11 10 5 10
16 10 5 10
1000000000000000000 17 14 999999999999999985
1000000000000000000 17 15 999999999999999985
Output
No
Yes
No
Yes
Yes
No
No
Yes
No
Yes
Yes
No
No
Yes
Input
24
1 2 3 4
1 2 4 3
1 3 2 4
1 3 4 2
1 4 2 3
1 4 3 2
2 1 3 4
2 1 4 3
2 3 1 4
2 3 4 1
2 4 1 3
2 4 3 1
3 1 2 4
3 1 4 2
3 2 1 4
3 2 4 1
3 4 1 2
3 4 2 1
4 1 2 3
4 1 3 2
4 2 1 3
4 2 3 1
4 3 1 2
4 3 2 1
Output
No
No
No
No
No
No
Yes
Yes
No
No
No
No
Yes
Yes
Yes
No
No
No
Yes
Yes
Yes
No
No
No
Submitted Solution:
```
#coding:utf-8
T = int(input())
for i in range(T):
a,b,c,d = map(int,input().split())
if b > d:
print("No")
elif a < b:
print("No")
else:
sur = a % b
while sur != a:
a += d
if c < a % b:
print("No")
break
a %= b
else:
print("Yes")
``` | instruction | 0 | 86,383 | 10 | 172,766 |
No | output | 1 | 86,383 | 10 | 172,767 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Ringo Mart, a convenience store, sells apple juice.
On the opening day of Ringo Mart, there were A cans of juice in stock in the morning. Snuke buys B cans of juice here every day in the daytime. Then, the manager checks the number of cans of juice remaining in stock every night. If there are C or less cans, D new cans will be added to the stock by the next morning.
Determine if Snuke can buy juice indefinitely, that is, there is always B or more cans of juice in stock when he attempts to buy them. Nobody besides Snuke buy juice at this store.
Note that each test case in this problem consists of T queries.
Constraints
* 1 \leq T \leq 300
* 1 \leq A, B, C, D \leq 10^{18}
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
T
A_1 B_1 C_1 D_1
A_2 B_2 C_2 D_2
:
A_T B_T C_T D_T
In the i-th query, A = A_i, B = B_i, C = C_i, D = D_i.
Output
Print T lines. The i-th line should contain `Yes` if Snuke can buy apple juice indefinitely in the i-th query; `No` otherwise.
Examples
Input
14
9 7 5 9
9 7 6 9
14 10 7 12
14 10 8 12
14 10 9 12
14 10 7 11
14 10 8 11
14 10 9 11
9 10 5 10
10 10 5 10
11 10 5 10
16 10 5 10
1000000000000000000 17 14 999999999999999985
1000000000000000000 17 15 999999999999999985
Output
No
Yes
No
Yes
Yes
No
No
Yes
No
Yes
Yes
No
No
Yes
Input
24
1 2 3 4
1 2 4 3
1 3 2 4
1 3 4 2
1 4 2 3
1 4 3 2
2 1 3 4
2 1 4 3
2 3 1 4
2 3 4 1
2 4 1 3
2 4 3 1
3 1 2 4
3 1 4 2
3 2 1 4
3 2 4 1
3 4 1 2
3 4 2 1
4 1 2 3
4 1 3 2
4 2 1 3
4 2 3 1
4 3 1 2
4 3 2 1
Output
No
No
No
No
No
No
Yes
Yes
No
No
No
No
Yes
Yes
Yes
No
No
No
Yes
Yes
Yes
No
No
No
Submitted Solution:
```
t = int(input())
abcd = [[int(i) for i in input().split()] for i in range(t)]
counter = 0
for qu in abcd:
if qu[0] < qu[1]:
print("No")
elif qu[1]-1<=qu[2]:
if qu[3] < qu[1]:
print("No")
else:
print("Yes")
else:
amod = qu[0]%qu[1]
dmod = qu[3]%qu[1]
deadzone = range(qu[2]+1,qu[1])
cycle = []
flag = True
while(flag):
if amod in deadzone:
print("No")
flag = False
elif amod in cycle:
print("Yes")
flag = False
else:
cycle.append(amod)
amod = (amod + dmod) % qu[1]
``` | instruction | 0 | 86,384 | 10 | 172,768 |
No | output | 1 | 86,384 | 10 | 172,769 |
Provide a correct Python 3 solution for this coding contest problem.
PCK, which recycles Aizu's precious metal, Aizunium, has a network all over the country and collects Aizunium with many collection vehicles. This company standardizes the unit of weight and number of lumps for efficient processing.
A unit called "bokko" is used for the weight of the lump. x Bocco's Aidunium weighs 2 x grams. If you compare it to a jewel, it's like a "carat." In addition, the unit called "Marugu" is used for the number of lumps. y Marg is 2y. It's like a "dozen" of items in a box. However, x and y must be integers greater than or equal to 0.
Recovery vehicle i collects ai bocco-weighted aidunium by bi-margue. The collected edunium is put into a furnace and melted to regenerate some lumps of edunium, but try to reduce the number of lumps of edunium as much as possible. At this time, the total weight of the collected Izunium and the total weight of the regenerated Izunium do not change.
Create a program that finds the result that minimizes the number of regenerated Izunium lumps given the weight of the Izunium lumps collected by the recovery vehicle in Bocco units and the number of Marg units.
Input
The input is given in the following format.
N
a1 b1
a2 b2
::
aN bN
The first line gives the number of recovery vehicles N (1 ≤ N ≤ 100000). In the next N lines, the integer ai (0 ≤ ai ≤ 100000) representing the weight in "Bocco" units and the integer bi (0 ≤ bi ≤) representing the number in "Margue" units of the mass of Aidunium collected by the recovery vehicle i. 100000) is given.
Output
The weight in Bocco units and the number in Marg units are output in ascending order of weight so that the number of lumps of Izunium obtained after regeneration is minimized.
Examples
Input
3
2 1
1 3
2 2
Output
3 0
5 0
Input
1
100000 2
Output
100002 0 | instruction | 0 | 86,479 | 10 | 172,958 |
"Correct Solution:
```
n = int(input())
size = 200100
total = [0 for _ in range(size)]
for _ in range(n):
s = sum(map(int, input().split()))
total[s] += 1
for i in range(size - 1):
if total[i] % 2:
print(i, 0)
total[i + 1] += total[i] // 2
``` | output | 1 | 86,479 | 10 | 172,959 |
Provide a correct Python 3 solution for this coding contest problem.
PCK, which recycles Aizu's precious metal, Aizunium, has a network all over the country and collects Aizunium with many collection vehicles. This company standardizes the unit of weight and number of lumps for efficient processing.
A unit called "bokko" is used for the weight of the lump. x Bocco's Aidunium weighs 2 x grams. If you compare it to a jewel, it's like a "carat." In addition, the unit called "Marugu" is used for the number of lumps. y Marg is 2y. It's like a "dozen" of items in a box. However, x and y must be integers greater than or equal to 0.
Recovery vehicle i collects ai bocco-weighted aidunium by bi-margue. The collected edunium is put into a furnace and melted to regenerate some lumps of edunium, but try to reduce the number of lumps of edunium as much as possible. At this time, the total weight of the collected Izunium and the total weight of the regenerated Izunium do not change.
Create a program that finds the result that minimizes the number of regenerated Izunium lumps given the weight of the Izunium lumps collected by the recovery vehicle in Bocco units and the number of Marg units.
Input
The input is given in the following format.
N
a1 b1
a2 b2
::
aN bN
The first line gives the number of recovery vehicles N (1 ≤ N ≤ 100000). In the next N lines, the integer ai (0 ≤ ai ≤ 100000) representing the weight in "Bocco" units and the integer bi (0 ≤ bi ≤) representing the number in "Margue" units of the mass of Aidunium collected by the recovery vehicle i. 100000) is given.
Output
The weight in Bocco units and the number in Marg units are output in ascending order of weight so that the number of lumps of Izunium obtained after regeneration is minimized.
Examples
Input
3
2 1
1 3
2 2
Output
3 0
5 0
Input
1
100000 2
Output
100002 0 | instruction | 0 | 86,480 | 10 | 172,960 |
"Correct Solution:
```
N=200020
a=[0]*N
for _ in range(int(input())): a[sum(map(int,input().split()))]+=1
for i in range(N-1):
a[i+1]+=a[i]>>1
if a[i]&1:
print(i,0)
``` | output | 1 | 86,480 | 10 | 172,961 |
Provide a correct Python 3 solution for this coding contest problem.
PCK, which recycles Aizu's precious metal, Aizunium, has a network all over the country and collects Aizunium with many collection vehicles. This company standardizes the unit of weight and number of lumps for efficient processing.
A unit called "bokko" is used for the weight of the lump. x Bocco's Aidunium weighs 2 x grams. If you compare it to a jewel, it's like a "carat." In addition, the unit called "Marugu" is used for the number of lumps. y Marg is 2y. It's like a "dozen" of items in a box. However, x and y must be integers greater than or equal to 0.
Recovery vehicle i collects ai bocco-weighted aidunium by bi-margue. The collected edunium is put into a furnace and melted to regenerate some lumps of edunium, but try to reduce the number of lumps of edunium as much as possible. At this time, the total weight of the collected Izunium and the total weight of the regenerated Izunium do not change.
Create a program that finds the result that minimizes the number of regenerated Izunium lumps given the weight of the Izunium lumps collected by the recovery vehicle in Bocco units and the number of Marg units.
Input
The input is given in the following format.
N
a1 b1
a2 b2
::
aN bN
The first line gives the number of recovery vehicles N (1 ≤ N ≤ 100000). In the next N lines, the integer ai (0 ≤ ai ≤ 100000) representing the weight in "Bocco" units and the integer bi (0 ≤ bi ≤) representing the number in "Margue" units of the mass of Aidunium collected by the recovery vehicle i. 100000) is given.
Output
The weight in Bocco units and the number in Marg units are output in ascending order of weight so that the number of lumps of Izunium obtained after regeneration is minimized.
Examples
Input
3
2 1
1 3
2 2
Output
3 0
5 0
Input
1
100000 2
Output
100002 0 | instruction | 0 | 86,481 | 10 | 172,962 |
"Correct Solution:
```
n = int(input())
s = 0
for i in range(n):
a, b = map(int, input().split())
s += 1 << (a+b)
i = 0
ans = []
while s:
if s & 1:
ans.append(i)
s >>= 1
i += 1
for e in ans:
print(e, 0)
``` | output | 1 | 86,481 | 10 | 172,963 |
Provide a correct Python 3 solution for this coding contest problem.
PCK, which recycles Aizu's precious metal, Aizunium, has a network all over the country and collects Aizunium with many collection vehicles. This company standardizes the unit of weight and number of lumps for efficient processing.
A unit called "bokko" is used for the weight of the lump. x Bocco's Aidunium weighs 2 x grams. If you compare it to a jewel, it's like a "carat." In addition, the unit called "Marugu" is used for the number of lumps. y Marg is 2y. It's like a "dozen" of items in a box. However, x and y must be integers greater than or equal to 0.
Recovery vehicle i collects ai bocco-weighted aidunium by bi-margue. The collected edunium is put into a furnace and melted to regenerate some lumps of edunium, but try to reduce the number of lumps of edunium as much as possible. At this time, the total weight of the collected Izunium and the total weight of the regenerated Izunium do not change.
Create a program that finds the result that minimizes the number of regenerated Izunium lumps given the weight of the Izunium lumps collected by the recovery vehicle in Bocco units and the number of Marg units.
Input
The input is given in the following format.
N
a1 b1
a2 b2
::
aN bN
The first line gives the number of recovery vehicles N (1 ≤ N ≤ 100000). In the next N lines, the integer ai (0 ≤ ai ≤ 100000) representing the weight in "Bocco" units and the integer bi (0 ≤ bi ≤) representing the number in "Margue" units of the mass of Aidunium collected by the recovery vehicle i. 100000) is given.
Output
The weight in Bocco units and the number in Marg units are output in ascending order of weight so that the number of lumps of Izunium obtained after regeneration is minimized.
Examples
Input
3
2 1
1 3
2 2
Output
3 0
5 0
Input
1
100000 2
Output
100002 0 | instruction | 0 | 86,482 | 10 | 172,964 |
"Correct Solution:
```
N=200020
a=[0]*N
n=int(input())
for _ in range(n): a[sum(map(int,input().split()))]+=1
for i in range(N-1):
a[i+1]+=a[i]//2
a[i]&=1
if a[i]:
print(i,0)
``` | output | 1 | 86,482 | 10 | 172,965 |
Provide a correct Python 3 solution for this coding contest problem.
PCK, which recycles Aizu's precious metal, Aizunium, has a network all over the country and collects Aizunium with many collection vehicles. This company standardizes the unit of weight and number of lumps for efficient processing.
A unit called "bokko" is used for the weight of the lump. x Bocco's Aidunium weighs 2 x grams. If you compare it to a jewel, it's like a "carat." In addition, the unit called "Marugu" is used for the number of lumps. y Marg is 2y. It's like a "dozen" of items in a box. However, x and y must be integers greater than or equal to 0.
Recovery vehicle i collects ai bocco-weighted aidunium by bi-margue. The collected edunium is put into a furnace and melted to regenerate some lumps of edunium, but try to reduce the number of lumps of edunium as much as possible. At this time, the total weight of the collected Izunium and the total weight of the regenerated Izunium do not change.
Create a program that finds the result that minimizes the number of regenerated Izunium lumps given the weight of the Izunium lumps collected by the recovery vehicle in Bocco units and the number of Marg units.
Input
The input is given in the following format.
N
a1 b1
a2 b2
::
aN bN
The first line gives the number of recovery vehicles N (1 ≤ N ≤ 100000). In the next N lines, the integer ai (0 ≤ ai ≤ 100000) representing the weight in "Bocco" units and the integer bi (0 ≤ bi ≤) representing the number in "Margue" units of the mass of Aidunium collected by the recovery vehicle i. 100000) is given.
Output
The weight in Bocco units and the number in Marg units are output in ascending order of weight so that the number of lumps of Izunium obtained after regeneration is minimized.
Examples
Input
3
2 1
1 3
2 2
Output
3 0
5 0
Input
1
100000 2
Output
100002 0 | instruction | 0 | 86,483 | 10 | 172,966 |
"Correct Solution:
```
m = set()
for _ in range(int(input())):
a, b = map(int, input().split())
i = 0
while True:
if a + b + i in m:
m.remove(a + b + i)
i += 1
else:
m.add(a + b + i)
break
m = list(m)
m.sort()
for i in m:print("{} 0".format(i))
``` | output | 1 | 86,483 | 10 | 172,967 |
Provide tags and a correct Python 3 solution for this coding contest problem.
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. | instruction | 0 | 86,968 | 10 | 173,936 |
Tags: implementation
Correct Solution:
```
def vahta(x, lst):
for elem in lst:
ra, rb = min(elem[0], elem[1]), min(elem[2], elem[3])
if ra + rb <= x:
return lst.index(elem) + 1, ra, x - ra
return [-1]
n = int(input())
a = list()
for i in range(4):
t = [int(j) for j in input().split()]
a.append(t)
print(*vahta(n, a))
``` | output | 1 | 86,968 | 10 | 173,937 |
Provide tags and a correct Python 3 solution for this coding contest problem.
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. | instruction | 0 | 86,969 | 10 | 173,938 |
Tags: implementation
Correct Solution:
```
import operator as op
import re
import sys
from bisect import bisect, bisect_left, insort, insort_left
from collections import Counter, defaultdict, deque
from copy import deepcopy
from decimal import Decimal
from functools import reduce
from itertools import (
accumulate, combinations, combinations_with_replacement, groupby,
permutations, product)
from math import (acos, asin, atan, ceil, cos, degrees, factorial, gcd, hypot,
log2, pi, radians, sin, sqrt, tan)
from operator import itemgetter, mul
from string import ascii_lowercase, ascii_uppercase, digits
def inp():
return(int(input()))
def inlist():
return(list(map(int, input().split())))
def instr():
s = input()
return(list(s[:len(s)]))
def invr():
return(map(int, input().split()))
def def_value():
return 0
# For getting input from input.txt file
#sys.stdin = open('input.txt', 'r')
# Printing the Output to output.txt file
# sys.stdout = open('output.txt', 'w')
n = inp()
a = []
for i in range(4):
a.append(inlist()+[i+1])
a = sorted(a, key=lambda d: min(d[0], d[1])+min(d[2], d[3]))
b = a[0]
if min(b[0], b[1]) + min(b[2], b[3]) > n:
print(-1)
else:
c1 = min(b[0], b[1])
c2 = n - c1
print(b[4], c1, c2)
``` | output | 1 | 86,969 | 10 | 173,939 |
Provide tags and a correct Python 3 solution for this coding contest problem.
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. | instruction | 0 | 86,970 | 10 | 173,940 |
Tags: implementation
Correct Solution:
```
n = int(input())
a = [list(map(int, input().split())) for i in range(4)]
b = []
c = []
d = []
for i in range(4):
b.append(min(a[i][:2]))
b.append(min(a[i][2:]))
b.insert(0, sum(b))
d.append(b[0])
c.append(b)
b = []
k = d.index(min(d))
if c[k][0] <= n: print(k+1,c[k][1],n-c[k][1])
else: print(-1)
``` | output | 1 | 86,970 | 10 | 173,941 |
Provide tags and a correct Python 3 solution for this coding contest problem.
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. | instruction | 0 | 86,971 | 10 | 173,942 |
Tags: implementation
Correct Solution:
```
import itertools as it
n = int(input())
res = None
for i in range(4):
a = list(map(int, input().split()))
for v in list(it.product(a[:2], a[2:])):
if sum(v) <= n:
res = [i + 1, v[0], n - v[0]]
break
if res is not None:
break
print(-1 if res is None else ' '.join(map(str, res)))
``` | output | 1 | 86,971 | 10 | 173,943 |
Provide tags and a correct Python 3 solution for this coding contest problem.
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. | instruction | 0 | 86,972 | 10 | 173,944 |
Tags: implementation
Correct Solution:
```
def solve(arr, n):
for i,v in enumerate(arr):
c1 = min(v[0], v[1])
c2 = min(v[2], v[3])
if c1+c2 <= n:
return [i+1, c1,n-c1]
return [-1]
def main() :
n = int(input())
arr = []
for _ in range(4):
i = list(map(int, input().split(' ')))
arr.append(i)
print(*solve(arr, n))
main()
``` | output | 1 | 86,972 | 10 | 173,945 |
Provide tags and a correct Python 3 solution for this coding contest problem.
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. | instruction | 0 | 86,973 | 10 | 173,946 |
Tags: implementation
Correct Solution:
```
n = int(input())
for _ in range(4):
a,b,c,d = map(int,input().split())
for i in [a,b]:
for j in [c,d]:
if i+j<=n:
print(_+1,i,n-i)
exit(0)
print(-1)
``` | output | 1 | 86,973 | 10 | 173,947 |
Provide tags and a correct Python 3 solution for this coding contest problem.
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. | instruction | 0 | 86,974 | 10 | 173,948 |
Tags: implementation
Correct Solution:
```
if __name__ == "__main__":
n = int(input())
l1 = [int(v) for v in input().split()]
l2 = [int(v) for v in input().split()]
l3 = [int(v) for v in input().split()]
l4 = [int(v) for v in input().split()]
if min(l1[0],l1[1]) + min(l1[2],l1[3]) <= n:
print("1 %d %d" % (min(l1[0],l1[1]), n-min(l1[0],l1[1])))
elif min(l2[0],l2[1]) + min(l2[2],l2[3]) <= n:
print("2 %d %d" % (min(l2[0],l2[1]), n-min(l2[0],l2[1])))
elif min(l3[0],l3[1]) + min(l3[2],l3[3]) <= n:
print("3 %d %d" % (min(l3[0],l3[1]), n-min(l3[0],l3[1])))
elif min(l4[0],l4[1]) + min(l4[2],l4[3]) <= n:
print("4 %d %d" % (min(l4[0],l4[1]), n-min(l4[0],l4[1])))
else:
print("-1")
``` | output | 1 | 86,974 | 10 | 173,949 |
Provide tags and a correct Python 3 solution for this coding contest problem.
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. | instruction | 0 | 86,975 | 10 | 173,950 |
Tags: implementation
Correct Solution:
```
n = int(input())
for i in range(4):
a = list(map(int, input().split()))
if n >= min(a[0], a[1]) + min(a[2], a[3]):
print(i + 1, min(a[0], a[1]), n - min(a[0], a[1]))
exit()
print(-1)
``` | output | 1 | 86,975 | 10 | 173,951 |
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
n = int(input())
for i in range(4):
a, b, c, d = map(int, input().split())
if min(a, b) + min(c, d) <= n:
print("{} {} {}".format(i + 1, min(a, b), n - min(a, b)))
sys.exit(0)
print(-1)
``` | instruction | 0 | 86,976 | 10 | 173,952 |
Yes | output | 1 | 86,976 | 10 | 173,953 |
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
n=int(sys.stdin.readline())
A=[]
t=0
for i in range(1,5):
A.append(list(map(int,sys.stdin.readline().split())))
for i in range(0,4):
if A[i][0]+A[i][2]<=n:
print(i+1,A[i][0],n-A[i][0])
t=1
break
elif A[i][0]+A[i][3]<=n:
print(i+1,A[i][0],n-A[i][0])
t=1
break
elif A[i][1]+A[i][2]<=n:
print(i+1,A[i][1],n-A[i][1])
t=1
break
elif A[i][1]+A[i][3]<=n:
print(i+1,A[i][1],n-A[i][1])
t=1
break
if t==0:
print(-1)
``` | instruction | 0 | 86,977 | 10 | 173,954 |
Yes | output | 1 | 86,977 | 10 | 173,955 |
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:
```
from functools import reduce
from operator import *
from math import *
from sys import *
from string import *
from collections import *
setrecursionlimit(10**7)
dX= [-1, 1, 0, 0,-1, 1,-1, 1]
dY= [ 0, 0,-1, 1, 1,-1,-1, 1]
RI=lambda: list(map(int,input().split()))
RS=lambda: input().rstrip().split()
#################################################
n=RI()[0]
ind=0
ans1,ans2=10**6, 10**6
for i in range(4):
a,b,c,d=RI()
a=min(a,b)
c=min(c,d)
if a+c < ans1+ans2:
ind=i+1
ans1=a
ans2=c
if n-ans1<ans2:
print(-1)
else:
print(ind, ans1,n-ans1)
``` | instruction | 0 | 86,978 | 10 | 173,956 |
Yes | output | 1 | 86,978 | 10 | 173,957 |
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())
for x in range(4):
a,b,c,d=map(int,input().split())
k1=min(a,b)
k2=min(c,d)
ans=-1
con=0
while True:
if n-k1>=0:
if n-k1>=k2:
ans=[x+1,k1,n-k1]
con=1
break
else:
k1+=1
else:
break
if con:
print(*ans)
break
else:
print(ans)
``` | instruction | 0 | 86,979 | 10 | 173,958 |
Yes | output | 1 | 86,979 | 10 | 173,959 |
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 guardpost(m, cash):
for v in range(4):
if m[v][0] + m[v][2] <= cash:
print(str(v+1) + " " + str(m[v][0]) + " " + str(cash - m[v][2]))
return None
elif m[v][0] + m[v][3] <= cash:
print(str(v+1) + " " + str(m[v][0]) + " " + str(cash - m[v][3]))
return None
elif m[v][1] + m[v][2] <= cash:
print(str(v+1) + " " + str(m[v][1]) + " " + str(cash - m[v][2]))
return None
elif m[v][1] + m[v][3] <= cash:
print(str(v+1) + " " + str(m[v][1]) + " " + str(cash - m[v][3]))
return None
print("-1")
return None
cash = int(input())
matriz = []
for i in range(4):
matriz.append([int(item) for item in input().split()])
guardpost(matriz, cash)
``` | instruction | 0 | 86,980 | 10 | 173,960 |
No | output | 1 | 86,980 | 10 | 173,961 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.