message stringlengths 2 45.8k | message_type stringclasses 2 values | message_id int64 0 1 | conversation_id int64 254 108k | cluster float64 3 3 | __index_level_0__ int64 508 217k |
|---|---|---|---|---|---|
Provide a correct Python 3 solution for this coding contest problem.
problem
A mysterious $ X $ [cm] plant grows in one place. This plant has the following mysterious properties.
* Say "nobiro" to this plant and it will grow $ A $ [cm].
* Say "tidime" to this plant and it will grow $ B $ [cm].
* If you say "karero" to this plant, it will be $ 0 $ [cm].
However, this plant does not have a negative length. Specifically, when it grows from the state of $ C $ [cm] to $ D $ [cm] $ (C + D \ lt 0) $, it is a plant. Stops growing when it reaches $ 0 $ [cm].
Say one of "nobiro", "tidime", "karero" to this plant only once a day for $ N $ days. Find the length [cm] of the plant after $ N $ days.
output
Print the length of the plant after $ N $ days. Also print a newline at the end.
Example
Input
10 30 10
3
nobiro
nobiro
tidime
Output
80 | instruction | 0 | 43,781 | 3 | 87,562 |
"Correct Solution:
```
X,A,B = map(int,input().split())
N = int(input())
for i in range(N):
S = input()
if S == "nobiro":
X += A
elif S == "tidime":
X += B
else:
X = 0
if X < 0:
X = 0
print(X)
``` | output | 1 | 43,781 | 3 | 87,563 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Jack is working on his jumping skills recently. Currently he's located at point zero of the number line. He would like to get to the point x. In order to train, he has decided that he'll first jump by only one unit, and each subsequent jump will be exactly one longer than the previous one. He can go either left or right with each jump. He wonders how many jumps he needs to reach x.
Input
The input data consists of only one integer x ( - 109 ≤ x ≤ 109).
Output
Output the minimal number of jumps that Jack requires to reach x.
Examples
Input
2
Output
3
Input
6
Output
3
Input
0
Output
0
Submitted Solution:
```
"""
Jack is working on his jumping skills recently. Currently he's located at point zero of the number line. He would like to get to the point x. In order to train, he has decided that he'll first jump by only one unit, and each subsequent jump will be exactly one longer than the previous one. He can go either left or right with each jump. He wonders how many jumps he needs to reach x.
Input
The input data consists of only one integer x ( - 109 ≤ x ≤ 109).
Output
Output the minimal number of jumps that Jack requires to reach x.
"""
from math import *
def is_even(a):
return False if a%2 else True
def calc_sum(n):
return n * (n + 1)/2
def check(a, x):
is_even_a = is_even(a)
is_even_x = is_even(x)
return (not is_even_a and not is_even_x) or (is_even_a and is_even_x)
x = abs(int(input()))
if x == 0:
print(0)
else:
n = (-1 + pow(1 + 4*2*x, 0.5))/2
ceil_n = ceil(n)
if check(calc_sum(ceil_n), x):
print(ceil_n)
else:
if check(calc_sum(ceil_n + 1), x):
print(ceil_n + 1)
else:
print(ceil_n + 2)
``` | instruction | 0 | 43,919 | 3 | 87,838 |
Yes | output | 1 | 43,919 | 3 | 87,839 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Jack is working on his jumping skills recently. Currently he's located at point zero of the number line. He would like to get to the point x. In order to train, he has decided that he'll first jump by only one unit, and each subsequent jump will be exactly one longer than the previous one. He can go either left or right with each jump. He wonders how many jumps he needs to reach x.
Input
The input data consists of only one integer x ( - 109 ≤ x ≤ 109).
Output
Output the minimal number of jumps that Jack requires to reach x.
Examples
Input
2
Output
3
Input
6
Output
3
Input
0
Output
0
Submitted Solution:
```
def main():
s = 0
i = 1
t = 1
n = int(input())
if n == 0:
print(0)
return
n = abs(n)
while s == 0:
if t == n or (t > n and (t-n) % 2 == 0):
s = i
break
i += 1
t += i
print(s)
main()
``` | instruction | 0 | 43,921 | 3 | 87,842 |
Yes | output | 1 | 43,921 | 3 | 87,843 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Jack is working on his jumping skills recently. Currently he's located at point zero of the number line. He would like to get to the point x. In order to train, he has decided that he'll first jump by only one unit, and each subsequent jump will be exactly one longer than the previous one. He can go either left or right with each jump. He wonders how many jumps he needs to reach x.
Input
The input data consists of only one integer x ( - 109 ≤ x ≤ 109).
Output
Output the minimal number of jumps that Jack requires to reach x.
Examples
Input
2
Output
3
Input
6
Output
3
Input
0
Output
0
Submitted Solution:
```
from math import *
a = abs(int(input()))
n = max(floor(sqrt(2*a))-1,0)
while(n*(n+1)//2<a or (n*(n+1)//2-a)%2==1):
n+=1
print(n)
# Made By Mostafa_Khaled
``` | instruction | 0 | 43,922 | 3 | 87,844 |
Yes | output | 1 | 43,922 | 3 | 87,845 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Jack is working on his jumping skills recently. Currently he's located at point zero of the number line. He would like to get to the point x. In order to train, he has decided that he'll first jump by only one unit, and each subsequent jump will be exactly one longer than the previous one. He can go either left or right with each jump. He wonders how many jumps he needs to reach x.
Input
The input data consists of only one integer x ( - 109 ≤ x ≤ 109).
Output
Output the minimal number of jumps that Jack requires to reach x.
Examples
Input
2
Output
3
Input
6
Output
3
Input
0
Output
0
Submitted Solution:
```
def abs(val):
if val < 0:
return val * -1
return val
target = int(input())
x = 0
step = 1
while x != target:
if abs(target - x) >= step:
if target - x > 0:
x += step
else:
x += step * -1
step += 1
else:
if target - x > 0:
x += step * -1
else:
x += step
step += 1
print(step - 1)
``` | instruction | 0 | 43,923 | 3 | 87,846 |
No | output | 1 | 43,923 | 3 | 87,847 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Jack is working on his jumping skills recently. Currently he's located at point zero of the number line. He would like to get to the point x. In order to train, he has decided that he'll first jump by only one unit, and each subsequent jump will be exactly one longer than the previous one. He can go either left or right with each jump. He wonders how many jumps he needs to reach x.
Input
The input data consists of only one integer x ( - 109 ≤ x ≤ 109).
Output
Output the minimal number of jumps that Jack requires to reach x.
Examples
Input
2
Output
3
Input
6
Output
3
Input
0
Output
0
Submitted Solution:
```
j = abs(int(input()))
j=1
i = 0
while j > 0 or j&1:
i += 1
j -= i
print(i)
``` | instruction | 0 | 43,924 | 3 | 87,848 |
No | output | 1 | 43,924 | 3 | 87,849 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Jack is working on his jumping skills recently. Currently he's located at point zero of the number line. He would like to get to the point x. In order to train, he has decided that he'll first jump by only one unit, and each subsequent jump will be exactly one longer than the previous one. He can go either left or right with each jump. He wonders how many jumps he needs to reach x.
Input
The input data consists of only one integer x ( - 109 ≤ x ≤ 109).
Output
Output the minimal number of jumps that Jack requires to reach x.
Examples
Input
2
Output
3
Input
6
Output
3
Input
0
Output
0
Submitted Solution:
```
from math import sqrt
x=abs(int(input()))
r=0
case1=False
case2=False
case=True
while True:
n1=(-1+sqrt(1+(8*(x-r))))
n2=(-1+sqrt(1+(8*(x+r))))
#if x<r:
# case=False
if n1%2==0 and case==True:
case1=True
break
if n2%2==0:
case2=True
break
r+=1
if case1:
print(int((n1/2)+(2*r)))
if case2:
print(int((n2/2)+(2*r)))
``` | instruction | 0 | 43,925 | 3 | 87,850 |
No | output | 1 | 43,925 | 3 | 87,851 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Jack is working on his jumping skills recently. Currently he's located at point zero of the number line. He would like to get to the point x. In order to train, he has decided that he'll first jump by only one unit, and each subsequent jump will be exactly one longer than the previous one. He can go either left or right with each jump. He wonders how many jumps he needs to reach x.
Input
The input data consists of only one integer x ( - 109 ≤ x ≤ 109).
Output
Output the minimal number of jumps that Jack requires to reach x.
Examples
Input
2
Output
3
Input
6
Output
3
Input
0
Output
0
Submitted Solution:
```
x = int(input())
k, s, i = 0, 0, 1
while s < x or (s - x) % 2 == 1:
s += i
i += 1
print(i - 1)
``` | instruction | 0 | 43,926 | 3 | 87,852 |
No | output | 1 | 43,926 | 3 | 87,853 |
Provide tags and a correct Python 3 solution for this coding contest problem.
In the evenings Donkey would join Shrek to look at the stars. They would sit on a log, sipping tea and they would watch the starry sky. The sky hung above the roof, right behind the chimney. Shrek's stars were to the right of the chimney and the Donkey's stars were to the left. Most days the Donkey would just count the stars, so he knew that they are exactly n. This time he wanted a challenge. He imagined a coordinate system: he put the origin of the coordinates at the intersection of the roof and the chimney, directed the OX axis to the left along the roof and the OY axis — up along the chimney (see figure). The Donkey imagined two rays emanating from he origin of axes at angles α1 and α2 to the OX axis.
<image>
Now he chooses any star that lies strictly between these rays. After that he imagines more rays that emanate from this star at the same angles α1 and α2 to the OX axis and chooses another star that lies strictly between the new rays. He repeats the operation as long as there still are stars he can choose between the rays that emanate from a star.
<image>
As a result, the Donkey gets a chain of stars. He can consecutively get to each star if he acts by the given rules.
Your task is to find the maximum number of stars m that the Donkey's chain can contain.
Note that the chain must necessarily start in the point of the origin of the axes, that isn't taken into consideration while counting the number m of stars in the chain.
Input
The first line contains an integer n (1 ≤ n ≤ 105) — the number of stars. The second line contains simple fractions representing relationships "a/b c/d", such that <image> and <image> (0 ≤ a, b, c, d ≤ 105; <image>; <image>; <image>). The given numbers a, b, c, d are integers.
Next n lines contain pairs of integers xi, yi (1 ≤ xi, yi ≤ 105)— the stars' coordinates.
It is guaranteed that all stars have distinct coordinates.
Output
In a single line print number m — the answer to the problem.
Examples
Input
15
1/3 2/1
3 1
6 2
4 2
2 5
4 5
6 6
3 4
1 6
2 1
7 4
9 3
5 3
1 3
15 5
12 4
Output
4
Note
In the sample the longest chain the Donkey can build consists of four stars. Note that the Donkey can't choose the stars that lie on the rays he imagines.
<image> | instruction | 0 | 44,124 | 3 | 88,248 |
Tags: data structures, dp, geometry, math, sortings
Correct Solution:
```
from bisect import *
from math import *
n = int(input())
a, b, c, d = map(int,input().replace('/',' ').split())
alpha = atan2(c,d) - atan2(a,b)
tan_alpha = tan(alpha)
lis = []
for x,y in sorted((y/tan_alpha - x,y) for x,y in [ (x,y) for x,y in [(b*x + a*y,-a*x + b*y) for x, y in [map(int,input().split()) for _ in range(n)] if a*x - b*y <= 0 and d*y - c*x <= 0]]):
pos = bisect_left(lis,-y)
if pos == len(lis):
lis.append(-y)
else:
lis[pos] = -y
print(len(lis))
``` | output | 1 | 44,124 | 3 | 88,249 |
Provide tags and a correct Python 3 solution for this coding contest problem.
In the evenings Donkey would join Shrek to look at the stars. They would sit on a log, sipping tea and they would watch the starry sky. The sky hung above the roof, right behind the chimney. Shrek's stars were to the right of the chimney and the Donkey's stars were to the left. Most days the Donkey would just count the stars, so he knew that they are exactly n. This time he wanted a challenge. He imagined a coordinate system: he put the origin of the coordinates at the intersection of the roof and the chimney, directed the OX axis to the left along the roof and the OY axis — up along the chimney (see figure). The Donkey imagined two rays emanating from he origin of axes at angles α1 and α2 to the OX axis.
<image>
Now he chooses any star that lies strictly between these rays. After that he imagines more rays that emanate from this star at the same angles α1 and α2 to the OX axis and chooses another star that lies strictly between the new rays. He repeats the operation as long as there still are stars he can choose between the rays that emanate from a star.
<image>
As a result, the Donkey gets a chain of stars. He can consecutively get to each star if he acts by the given rules.
Your task is to find the maximum number of stars m that the Donkey's chain can contain.
Note that the chain must necessarily start in the point of the origin of the axes, that isn't taken into consideration while counting the number m of stars in the chain.
Input
The first line contains an integer n (1 ≤ n ≤ 105) — the number of stars. The second line contains simple fractions representing relationships "a/b c/d", such that <image> and <image> (0 ≤ a, b, c, d ≤ 105; <image>; <image>; <image>). The given numbers a, b, c, d are integers.
Next n lines contain pairs of integers xi, yi (1 ≤ xi, yi ≤ 105)— the stars' coordinates.
It is guaranteed that all stars have distinct coordinates.
Output
In a single line print number m — the answer to the problem.
Examples
Input
15
1/3 2/1
3 1
6 2
4 2
2 5
4 5
6 6
3 4
1 6
2 1
7 4
9 3
5 3
1 3
15 5
12 4
Output
4
Note
In the sample the longest chain the Donkey can build consists of four stars. Note that the Donkey can't choose the stars that lie on the rays he imagines.
<image> | instruction | 0 | 44,125 | 3 | 88,250 |
Tags: data structures, dp, geometry, math, sortings
Correct Solution:
```
import bisect
def INPUT():
global n, a, b, c, d
n = int(input())
a, b, c, d = [int(j) for i in input().split() for j in i.split("/")]
global y_alpha
y_alpha = []
for _ in range(n):
x, y = [int(x) for x in input().split()]
y_alpha.append((b * y - a * x, c * x - d * y))
if __name__ == '__main__':
INPUT()
y_alpha = sorted([(x, y) for x, y in y_alpha if x > 0 and y > 0], key = lambda x: (x[0], -x[1]))
dp = []
for x, y in y_alpha:
i = bisect.bisect_left(dp, y)
if i == len(dp):
dp.append(y)
else:
dp[i] = y;
print(len(dp));
``` | output | 1 | 44,125 | 3 | 88,251 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In the evenings Donkey would join Shrek to look at the stars. They would sit on a log, sipping tea and they would watch the starry sky. The sky hung above the roof, right behind the chimney. Shrek's stars were to the right of the chimney and the Donkey's stars were to the left. Most days the Donkey would just count the stars, so he knew that they are exactly n. This time he wanted a challenge. He imagined a coordinate system: he put the origin of the coordinates at the intersection of the roof and the chimney, directed the OX axis to the left along the roof and the OY axis — up along the chimney (see figure). The Donkey imagined two rays emanating from he origin of axes at angles α1 and α2 to the OX axis.
<image>
Now he chooses any star that lies strictly between these rays. After that he imagines more rays that emanate from this star at the same angles α1 and α2 to the OX axis and chooses another star that lies strictly between the new rays. He repeats the operation as long as there still are stars he can choose between the rays that emanate from a star.
<image>
As a result, the Donkey gets a chain of stars. He can consecutively get to each star if he acts by the given rules.
Your task is to find the maximum number of stars m that the Donkey's chain can contain.
Note that the chain must necessarily start in the point of the origin of the axes, that isn't taken into consideration while counting the number m of stars in the chain.
Input
The first line contains an integer n (1 ≤ n ≤ 105) — the number of stars. The second line contains simple fractions representing relationships "a/b c/d", such that <image> and <image> (0 ≤ a, b, c, d ≤ 105; <image>; <image>; <image>). The given numbers a, b, c, d are integers.
Next n lines contain pairs of integers xi, yi (1 ≤ xi, yi ≤ 105)— the stars' coordinates.
It is guaranteed that all stars have distinct coordinates.
Output
In a single line print number m — the answer to the problem.
Examples
Input
15
1/3 2/1
3 1
6 2
4 2
2 5
4 5
6 6
3 4
1 6
2 1
7 4
9 3
5 3
1 3
15 5
12 4
Output
4
Note
In the sample the longest chain the Donkey can build consists of four stars. Note that the Donkey can't choose the stars that lie on the rays he imagines.
<image>
Submitted Solution:
```
'''
author: Pham Manh Tien
created: 23.09.2020
'''
import bisect
class node:
def __init__(self, x = 0, y = 0):
self.x = x
self.y = y
def __lt__(self, other):
global a, b, c, d
z = (c * self.x - d * self.y) - (c * other.x - d * other.y)
if z == 0:
return b * self.y - a * self.x > b * other.y - a * other.x
return z < 0
def INPUT():
global n, a, b, c, d
n = int(input())
a, b, c, d = [int(j) for i in input().split() for j in i.split("/")]
global point_arr
point_arr = []
for _ in range(n):
x, y = [int(x) for x in input().split()]
point_arr.append(node(x, y))
if __name__ == '__main__':
INPUT()
sorted(point_arr)
length_arr = [node()] * n
p = -1
for i in range(n):
if point_arr[i].x * c - point_arr[i].y * d <= 0 or point_arr[i].y * b - point_arr[i].x * a <= 0:
continue
if p == -1 or point_arr[i].y * b - point_arr[i].x * a <= length_arr[0].y * b - length_arr[0].x * a:
if p == -1:
p += 1
length_arr[0] = point_arr[i]
elif point_arr[i].y * b - point_arr[i].x * a > length_arr[p].y * b - length_arr[p].x * a:
p += 1
length_arr[p] = point_arr[i]
else:
left = 0
right = p
while left < right - 1:
mid = int((left + right) / 2)
if point_arr[i].y * b - point_arr[i].x * a > length_arr[mid].y * b - length_arr[mid].x * a:
left = mid
else:
right = mid
length_arr[right] = point_arr[i]
'''
position_update = bisect.bisect_left(length_arr, point_arr[i], 0, p-1)
length_arr[position_update] = point_arr[i]
'''
print(p+1)
``` | instruction | 0 | 44,126 | 3 | 88,252 |
No | output | 1 | 44,126 | 3 | 88,253 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In the evenings Donkey would join Shrek to look at the stars. They would sit on a log, sipping tea and they would watch the starry sky. The sky hung above the roof, right behind the chimney. Shrek's stars were to the right of the chimney and the Donkey's stars were to the left. Most days the Donkey would just count the stars, so he knew that they are exactly n. This time he wanted a challenge. He imagined a coordinate system: he put the origin of the coordinates at the intersection of the roof and the chimney, directed the OX axis to the left along the roof and the OY axis — up along the chimney (see figure). The Donkey imagined two rays emanating from he origin of axes at angles α1 and α2 to the OX axis.
<image>
Now he chooses any star that lies strictly between these rays. After that he imagines more rays that emanate from this star at the same angles α1 and α2 to the OX axis and chooses another star that lies strictly between the new rays. He repeats the operation as long as there still are stars he can choose between the rays that emanate from a star.
<image>
As a result, the Donkey gets a chain of stars. He can consecutively get to each star if he acts by the given rules.
Your task is to find the maximum number of stars m that the Donkey's chain can contain.
Note that the chain must necessarily start in the point of the origin of the axes, that isn't taken into consideration while counting the number m of stars in the chain.
Input
The first line contains an integer n (1 ≤ n ≤ 105) — the number of stars. The second line contains simple fractions representing relationships "a/b c/d", such that <image> and <image> (0 ≤ a, b, c, d ≤ 105; <image>; <image>; <image>). The given numbers a, b, c, d are integers.
Next n lines contain pairs of integers xi, yi (1 ≤ xi, yi ≤ 105)— the stars' coordinates.
It is guaranteed that all stars have distinct coordinates.
Output
In a single line print number m — the answer to the problem.
Examples
Input
15
1/3 2/1
3 1
6 2
4 2
2 5
4 5
6 6
3 4
1 6
2 1
7 4
9 3
5 3
1 3
15 5
12 4
Output
4
Note
In the sample the longest chain the Donkey can build consists of four stars. Note that the Donkey can't choose the stars that lie on the rays he imagines.
<image>
Submitted Solution:
```
from bisect import *
n = int(input())
a, b, c, d = map(int,input().replace('/',' ').split())
arr1 = [ (x,y) for x,y in [(b*x + a*y,b*y - a*x) for x, y in [map(int,input().split()) for _ in range(n)]] if x > 0 and y > 0]
arr2 = sorted([(x,-y) for x,y in [ (y,d*y - c*x) for x,y in arr1] if y < 0])
lis = []
for x,y in arr2:
pos = bisect_left(lis,y)
if pos == len(lis):
lis.append(y)
else:
lis[pos] = y
print(len(lis))
``` | instruction | 0 | 44,127 | 3 | 88,254 |
No | output | 1 | 44,127 | 3 | 88,255 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In the evenings Donkey would join Shrek to look at the stars. They would sit on a log, sipping tea and they would watch the starry sky. The sky hung above the roof, right behind the chimney. Shrek's stars were to the right of the chimney and the Donkey's stars were to the left. Most days the Donkey would just count the stars, so he knew that they are exactly n. This time he wanted a challenge. He imagined a coordinate system: he put the origin of the coordinates at the intersection of the roof and the chimney, directed the OX axis to the left along the roof and the OY axis — up along the chimney (see figure). The Donkey imagined two rays emanating from he origin of axes at angles α1 and α2 to the OX axis.
<image>
Now he chooses any star that lies strictly between these rays. After that he imagines more rays that emanate from this star at the same angles α1 and α2 to the OX axis and chooses another star that lies strictly between the new rays. He repeats the operation as long as there still are stars he can choose between the rays that emanate from a star.
<image>
As a result, the Donkey gets a chain of stars. He can consecutively get to each star if he acts by the given rules.
Your task is to find the maximum number of stars m that the Donkey's chain can contain.
Note that the chain must necessarily start in the point of the origin of the axes, that isn't taken into consideration while counting the number m of stars in the chain.
Input
The first line contains an integer n (1 ≤ n ≤ 105) — the number of stars. The second line contains simple fractions representing relationships "a/b c/d", such that <image> and <image> (0 ≤ a, b, c, d ≤ 105; <image>; <image>; <image>). The given numbers a, b, c, d are integers.
Next n lines contain pairs of integers xi, yi (1 ≤ xi, yi ≤ 105)— the stars' coordinates.
It is guaranteed that all stars have distinct coordinates.
Output
In a single line print number m — the answer to the problem.
Examples
Input
15
1/3 2/1
3 1
6 2
4 2
2 5
4 5
6 6
3 4
1 6
2 1
7 4
9 3
5 3
1 3
15 5
12 4
Output
4
Note
In the sample the longest chain the Donkey can build consists of four stars. Note that the Donkey can't choose the stars that lie on the rays he imagines.
<image>
Submitted Solution:
```
'''
author: Pham Manh Tien
created: 23.09.2020
'''
import bisect
def compare(point1, point2):
global a, b, c, d
z = (c * point1[0] - d * point1[1]) - (c * point2[0] - d * point2[1])
if z == 0:
return b * point1[1] - a * point1[0] > b * point2[1] - a * point2[0]
return z < 0
def quicksort(point, low, high):
i = low
j = high
mid = (low + high) // 2
while i <= j:
while compare(point[i], point[mid]):
i += 1
while compare(point[mid], point[j]):
j -= 1
if i <= j:
tmp = point[i]
point[i] = point[j]
point[j] = tmp
i += 1
j -= 1
if low < j:
quicksort(point, low, j)
if i < high:
quicksort(point, i, high)
def INPUT():
global n, a, b, c, d
n = int(input())
a, b, c, d = [int(j) for i in input().split() for j in i.split("/")]
global point
point = []
for _ in range(n):
x, y = [int(x) for x in input().split()]
point.append((x,y))
if __name__ == '__main__':
INPUT()
quicksort(point, 0, len(point)-1)
ys_alpha1 = []
ys_alpha2 = []
for i in range(len(point)):
ys_alpha1.append(b * point[i][1] - a * point[i][0])
ys_alpha2.append(c * point[i][0] - d * point[i][1])
save_length_arr = [0] * n
p = -1
for i in range(n):
if ys_alpha2[i] <= 0 or ys_alpha1[i] <= 0:
continue
if p == -1 or ys_alpha1[i] <= ys_alpha1[save_length_arr[0]]:
if p == -1:
p += 1
save_length_arr[0] = i
elif ys_alpha1[i] > ys_alpha1[save_length_arr[p]]:
p += 1
save_length_arr[p] = i
else:
'''
left = 0
right = p
while left < right - 1:
mid = int((left + right) / 2)
if ys_alpha1[i] > ys_alpha1[save_length_arr[mid]]:
left = mid
else:
right = mid
save_length_arr[right] = i
'''
index = bisect.bisect_left(ys_alpha1, ys_alpha1[i], 0, p)
save_length_arr[index] = i
print(p+1)
``` | instruction | 0 | 44,128 | 3 | 88,256 |
No | output | 1 | 44,128 | 3 | 88,257 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In the evenings Donkey would join Shrek to look at the stars. They would sit on a log, sipping tea and they would watch the starry sky. The sky hung above the roof, right behind the chimney. Shrek's stars were to the right of the chimney and the Donkey's stars were to the left. Most days the Donkey would just count the stars, so he knew that they are exactly n. This time he wanted a challenge. He imagined a coordinate system: he put the origin of the coordinates at the intersection of the roof and the chimney, directed the OX axis to the left along the roof and the OY axis — up along the chimney (see figure). The Donkey imagined two rays emanating from he origin of axes at angles α1 and α2 to the OX axis.
<image>
Now he chooses any star that lies strictly between these rays. After that he imagines more rays that emanate from this star at the same angles α1 and α2 to the OX axis and chooses another star that lies strictly between the new rays. He repeats the operation as long as there still are stars he can choose between the rays that emanate from a star.
<image>
As a result, the Donkey gets a chain of stars. He can consecutively get to each star if he acts by the given rules.
Your task is to find the maximum number of stars m that the Donkey's chain can contain.
Note that the chain must necessarily start in the point of the origin of the axes, that isn't taken into consideration while counting the number m of stars in the chain.
Input
The first line contains an integer n (1 ≤ n ≤ 105) — the number of stars. The second line contains simple fractions representing relationships "a/b c/d", such that <image> and <image> (0 ≤ a, b, c, d ≤ 105; <image>; <image>; <image>). The given numbers a, b, c, d are integers.
Next n lines contain pairs of integers xi, yi (1 ≤ xi, yi ≤ 105)— the stars' coordinates.
It is guaranteed that all stars have distinct coordinates.
Output
In a single line print number m — the answer to the problem.
Examples
Input
15
1/3 2/1
3 1
6 2
4 2
2 5
4 5
6 6
3 4
1 6
2 1
7 4
9 3
5 3
1 3
15 5
12 4
Output
4
Note
In the sample the longest chain the Donkey can build consists of four stars. Note that the Donkey can't choose the stars that lie on the rays he imagines.
<image>
Submitted Solution:
```
from bisect import *
from math import *
n = int(input())
a, b, c, d = map(int,input().replace('/',' ').split())
alpha = atan2(c,d) - atan2(a,b)
tan_alpha = tan(alpha)
lis = []
for x,y in sorted((y*tan_alpha - x,y) for x,y in [ (x,y) for x,y in [(b*x + a*y,-a*x + b*y) for x, y in [map(int,input().split()) for _ in range(n)] if a*x - b*y <= 0 and d*y - c*x <= 0]]):
pos = bisect_left(lis,-y)
if pos == len(lis):
lis.append(-y)
else:
lis[pos] = -y
print(len(lis))
``` | instruction | 0 | 44,129 | 3 | 88,258 |
No | output | 1 | 44,129 | 3 | 88,259 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Amr lives in Lala Land. Lala Land is a very beautiful country that is located on a coordinate line. Lala Land is famous with its apple trees growing everywhere.
Lala Land has exactly n apple trees. Tree number i is located in a position xi and has ai apples growing on it. Amr wants to collect apples from the apple trees. Amr currently stands in x = 0 position. At the beginning, he can choose whether to go right or left. He'll continue in his direction until he meets an apple tree he didn't visit before. He'll take all of its apples and then reverse his direction, continue walking in this direction until he meets another apple tree he didn't visit before and so on. In the other words, Amr reverses his direction when visiting each new apple tree. Amr will stop collecting apples when there are no more trees he didn't visit in the direction he is facing.
What is the maximum number of apples he can collect?
Input
The first line contains one number n (1 ≤ n ≤ 100), the number of apple trees in Lala Land.
The following n lines contains two integers each xi, ai ( - 105 ≤ xi ≤ 105, xi ≠ 0, 1 ≤ ai ≤ 105), representing the position of the i-th tree and number of apples on it.
It's guaranteed that there is at most one apple tree at each coordinate. It's guaranteed that no tree grows in point 0.
Output
Output the maximum number of apples Amr can collect.
Examples
Input
2
-1 5
1 5
Output
10
Input
3
-2 2
1 4
-1 3
Output
9
Input
3
1 9
3 5
7 10
Output
9
Note
In the first sample test it doesn't matter if Amr chose at first to go left or right. In both cases he'll get all the apples.
In the second sample test the optimal solution is to go left to x = - 1, collect apples from there, then the direction will be reversed, Amr has to go to x = 1, collect apples from there, then the direction will be reversed and Amr goes to the final tree x = - 2.
In the third sample test the optimal solution is to go right to x = 1, collect apples from there, then the direction will be reversed and Amr will not be able to collect anymore apples because there are no apple trees to his left.
Submitted Solution:
```
n = int(input())
trees = []
for i in range(n):
trees.append([int(s) for s in input().split()])
left = [x for x in trees if x[0] < 0]
right = [x for x in trees if x[0] > 0]
right.sort()
left.sort(reverse=True)
if len(left) == len(right):
print(sum(a[1] for a in left) + sum(a[1] for a in right))
elif len(left) < len(right):
print(sum(a[1] for a in left) + sum(a[1] for a in right[:len(left) + 1]))
else:
print(sum(a[1] for a in right) + sum(a[1] for a in left[:len(right) + 1]))
``` | instruction | 0 | 44,247 | 3 | 88,494 |
Yes | output | 1 | 44,247 | 3 | 88,495 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Amr lives in Lala Land. Lala Land is a very beautiful country that is located on a coordinate line. Lala Land is famous with its apple trees growing everywhere.
Lala Land has exactly n apple trees. Tree number i is located in a position xi and has ai apples growing on it. Amr wants to collect apples from the apple trees. Amr currently stands in x = 0 position. At the beginning, he can choose whether to go right or left. He'll continue in his direction until he meets an apple tree he didn't visit before. He'll take all of its apples and then reverse his direction, continue walking in this direction until he meets another apple tree he didn't visit before and so on. In the other words, Amr reverses his direction when visiting each new apple tree. Amr will stop collecting apples when there are no more trees he didn't visit in the direction he is facing.
What is the maximum number of apples he can collect?
Input
The first line contains one number n (1 ≤ n ≤ 100), the number of apple trees in Lala Land.
The following n lines contains two integers each xi, ai ( - 105 ≤ xi ≤ 105, xi ≠ 0, 1 ≤ ai ≤ 105), representing the position of the i-th tree and number of apples on it.
It's guaranteed that there is at most one apple tree at each coordinate. It's guaranteed that no tree grows in point 0.
Output
Output the maximum number of apples Amr can collect.
Examples
Input
2
-1 5
1 5
Output
10
Input
3
-2 2
1 4
-1 3
Output
9
Input
3
1 9
3 5
7 10
Output
9
Note
In the first sample test it doesn't matter if Amr chose at first to go left or right. In both cases he'll get all the apples.
In the second sample test the optimal solution is to go left to x = - 1, collect apples from there, then the direction will be reversed, Amr has to go to x = 1, collect apples from there, then the direction will be reversed and Amr goes to the final tree x = - 2.
In the third sample test the optimal solution is to go right to x = 1, collect apples from there, then the direction will be reversed and Amr will not be able to collect anymore apples because there are no apple trees to his left.
Submitted Solution:
```
n=int(input())
left=[]
right=[]
for i in range(n):
a,b=map(int,input().split())
if a<0:
left.append([a,b])
else:
right.append([a,b])
#Sort
right=sorted(right);left=sorted(left,reverse=True)
su=0
a=left;b=right
if len(right)>len(left):a,b=b,a
#Goto a first then to b:
while b!=[]:
su+=a[0][1]+b[0][1]
a.pop(0);b.pop(0)
if a!=[]:su+=a[0][1]
print(su)
``` | instruction | 0 | 44,248 | 3 | 88,496 |
Yes | output | 1 | 44,248 | 3 | 88,497 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Amr lives in Lala Land. Lala Land is a very beautiful country that is located on a coordinate line. Lala Land is famous with its apple trees growing everywhere.
Lala Land has exactly n apple trees. Tree number i is located in a position xi and has ai apples growing on it. Amr wants to collect apples from the apple trees. Amr currently stands in x = 0 position. At the beginning, he can choose whether to go right or left. He'll continue in his direction until he meets an apple tree he didn't visit before. He'll take all of its apples and then reverse his direction, continue walking in this direction until he meets another apple tree he didn't visit before and so on. In the other words, Amr reverses his direction when visiting each new apple tree. Amr will stop collecting apples when there are no more trees he didn't visit in the direction he is facing.
What is the maximum number of apples he can collect?
Input
The first line contains one number n (1 ≤ n ≤ 100), the number of apple trees in Lala Land.
The following n lines contains two integers each xi, ai ( - 105 ≤ xi ≤ 105, xi ≠ 0, 1 ≤ ai ≤ 105), representing the position of the i-th tree and number of apples on it.
It's guaranteed that there is at most one apple tree at each coordinate. It's guaranteed that no tree grows in point 0.
Output
Output the maximum number of apples Amr can collect.
Examples
Input
2
-1 5
1 5
Output
10
Input
3
-2 2
1 4
-1 3
Output
9
Input
3
1 9
3 5
7 10
Output
9
Note
In the first sample test it doesn't matter if Amr chose at first to go left or right. In both cases he'll get all the apples.
In the second sample test the optimal solution is to go left to x = - 1, collect apples from there, then the direction will be reversed, Amr has to go to x = 1, collect apples from there, then the direction will be reversed and Amr goes to the final tree x = - 2.
In the third sample test the optimal solution is to go right to x = 1, collect apples from there, then the direction will be reversed and Amr will not be able to collect anymore apples because there are no apple trees to his left.
Submitted Solution:
```
n = int(input().strip())
neg, pos = [], []
for i in range(n):
x, a = map(int, input().strip().split())
if x < 0:
neg.append((x, a))
else:
pos.append((x, a))
neg.sort(reverse=True)
pos.sort()
total = 0
while len(neg) and len(pos):
total += neg[0][1] + pos[0][1]
neg.pop(0)
pos.pop(0)
if len(neg):
total += neg[0][1]
if len(pos):
total += pos[0][1]
print(total)
``` | instruction | 0 | 44,249 | 3 | 88,498 |
Yes | output | 1 | 44,249 | 3 | 88,499 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Amr lives in Lala Land. Lala Land is a very beautiful country that is located on a coordinate line. Lala Land is famous with its apple trees growing everywhere.
Lala Land has exactly n apple trees. Tree number i is located in a position xi and has ai apples growing on it. Amr wants to collect apples from the apple trees. Amr currently stands in x = 0 position. At the beginning, he can choose whether to go right or left. He'll continue in his direction until he meets an apple tree he didn't visit before. He'll take all of its apples and then reverse his direction, continue walking in this direction until he meets another apple tree he didn't visit before and so on. In the other words, Amr reverses his direction when visiting each new apple tree. Amr will stop collecting apples when there are no more trees he didn't visit in the direction he is facing.
What is the maximum number of apples he can collect?
Input
The first line contains one number n (1 ≤ n ≤ 100), the number of apple trees in Lala Land.
The following n lines contains two integers each xi, ai ( - 105 ≤ xi ≤ 105, xi ≠ 0, 1 ≤ ai ≤ 105), representing the position of the i-th tree and number of apples on it.
It's guaranteed that there is at most one apple tree at each coordinate. It's guaranteed that no tree grows in point 0.
Output
Output the maximum number of apples Amr can collect.
Examples
Input
2
-1 5
1 5
Output
10
Input
3
-2 2
1 4
-1 3
Output
9
Input
3
1 9
3 5
7 10
Output
9
Note
In the first sample test it doesn't matter if Amr chose at first to go left or right. In both cases he'll get all the apples.
In the second sample test the optimal solution is to go left to x = - 1, collect apples from there, then the direction will be reversed, Amr has to go to x = 1, collect apples from there, then the direction will be reversed and Amr goes to the final tree x = - 2.
In the third sample test the optimal solution is to go right to x = 1, collect apples from there, then the direction will be reversed and Amr will not be able to collect anymore apples because there are no apple trees to his left.
Submitted Solution:
```
t = [[[100001, 0]], [[100001, 0]]]
for i in range(int(input())):
x, a = map(int, input().split())
t[x > 0].append([abs(x), a])
t[0].sort()
t[1].sort()
print(sum(t[0][i][1] + t[1][i][1] for i in range(min(len(t[0]), len(t[1])))))
``` | instruction | 0 | 44,250 | 3 | 88,500 |
Yes | output | 1 | 44,250 | 3 | 88,501 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Amr lives in Lala Land. Lala Land is a very beautiful country that is located on a coordinate line. Lala Land is famous with its apple trees growing everywhere.
Lala Land has exactly n apple trees. Tree number i is located in a position xi and has ai apples growing on it. Amr wants to collect apples from the apple trees. Amr currently stands in x = 0 position. At the beginning, he can choose whether to go right or left. He'll continue in his direction until he meets an apple tree he didn't visit before. He'll take all of its apples and then reverse his direction, continue walking in this direction until he meets another apple tree he didn't visit before and so on. In the other words, Amr reverses his direction when visiting each new apple tree. Amr will stop collecting apples when there are no more trees he didn't visit in the direction he is facing.
What is the maximum number of apples he can collect?
Input
The first line contains one number n (1 ≤ n ≤ 100), the number of apple trees in Lala Land.
The following n lines contains two integers each xi, ai ( - 105 ≤ xi ≤ 105, xi ≠ 0, 1 ≤ ai ≤ 105), representing the position of the i-th tree and number of apples on it.
It's guaranteed that there is at most one apple tree at each coordinate. It's guaranteed that no tree grows in point 0.
Output
Output the maximum number of apples Amr can collect.
Examples
Input
2
-1 5
1 5
Output
10
Input
3
-2 2
1 4
-1 3
Output
9
Input
3
1 9
3 5
7 10
Output
9
Note
In the first sample test it doesn't matter if Amr chose at first to go left or right. In both cases he'll get all the apples.
In the second sample test the optimal solution is to go left to x = - 1, collect apples from there, then the direction will be reversed, Amr has to go to x = 1, collect apples from there, then the direction will be reversed and Amr goes to the final tree x = - 2.
In the third sample test the optimal solution is to go right to x = 1, collect apples from there, then the direction will be reversed and Amr will not be able to collect anymore apples because there are no apple trees to his left.
Submitted Solution:
```
from sys import stdin, stdout
def main():
n = int(stdin.readline())
res = 0
xList = []
aList = []
for t in range(n):
x, a = [int(c) for c in stdin.readline().split()]
xList.append(x)
aList.append(a)
res = aList[0]
old_dir = xList[0]
for i in range(1, n):
new_dir = xList[i] - xList[i-1]
if new_dir * old_dir > 0:
break
res += aList[i]
old_dir = new_dir
stdout.write(str(res))
#--------------------------------------------------------
if __name__ == "__main__":
main()
``` | instruction | 0 | 44,251 | 3 | 88,502 |
No | output | 1 | 44,251 | 3 | 88,503 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Amr lives in Lala Land. Lala Land is a very beautiful country that is located on a coordinate line. Lala Land is famous with its apple trees growing everywhere.
Lala Land has exactly n apple trees. Tree number i is located in a position xi and has ai apples growing on it. Amr wants to collect apples from the apple trees. Amr currently stands in x = 0 position. At the beginning, he can choose whether to go right or left. He'll continue in his direction until he meets an apple tree he didn't visit before. He'll take all of its apples and then reverse his direction, continue walking in this direction until he meets another apple tree he didn't visit before and so on. In the other words, Amr reverses his direction when visiting each new apple tree. Amr will stop collecting apples when there are no more trees he didn't visit in the direction he is facing.
What is the maximum number of apples he can collect?
Input
The first line contains one number n (1 ≤ n ≤ 100), the number of apple trees in Lala Land.
The following n lines contains two integers each xi, ai ( - 105 ≤ xi ≤ 105, xi ≠ 0, 1 ≤ ai ≤ 105), representing the position of the i-th tree and number of apples on it.
It's guaranteed that there is at most one apple tree at each coordinate. It's guaranteed that no tree grows in point 0.
Output
Output the maximum number of apples Amr can collect.
Examples
Input
2
-1 5
1 5
Output
10
Input
3
-2 2
1 4
-1 3
Output
9
Input
3
1 9
3 5
7 10
Output
9
Note
In the first sample test it doesn't matter if Amr chose at first to go left or right. In both cases he'll get all the apples.
In the second sample test the optimal solution is to go left to x = - 1, collect apples from there, then the direction will be reversed, Amr has to go to x = 1, collect apples from there, then the direction will be reversed and Amr goes to the final tree x = - 2.
In the third sample test the optimal solution is to go right to x = 1, collect apples from there, then the direction will be reversed and Amr will not be able to collect anymore apples because there are no apple trees to his left.
Submitted Solution:
```
"""
__ __ _
| \/ (_)_ __ ___ _ __
| |\/| | | '__/ _ \| '_ \
| | | | | | | (_) | | | |
|_| |_|_|_| \___/|_| |_|
"""
"""
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░████████░░░░░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░█████████░░░░░░░░░░░░░░░░░▌░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░◐◐◐█████████▀▀▀▀▀▀🔥░░░░░░░░███
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░█████████░░░░░░░░░░░░░░░░░░░░▌░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░█████████░░░░░░░░░░░░░░░░░░░░█▌░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░▄▄▀█████████████████████████████████████████████████
░░░░░░░░░░░░░░░░░░░░░░░░░░▄▄▄████▄████████ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ████
░░░░░░░░░░░░░░░░░░░░░░░░░░░▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀█████████▀▀▀▀▀▀▀▀▀
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░█████████░░░░░░░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░◐◐◐█████████▀▀▀▀▀▀🔥░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░█████████░░░░░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░█████████░░░░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░████████░░░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░███████░░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░██████░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░█████░░░░░░░░░░░░░░░
"""
"""
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@#@#@@#@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@##@M@M # #@@@M@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@#@@@@#@@ @@@@@@M@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@#@@### #@@B@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@#@@B@@#@@@@@#M@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@#@##@@M@#@@##@##@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@#@@#M@@@@@##@M@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@##@@@@@@#@##@#@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@#@@# @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@M@@ #
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@#@@#@@#@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @# @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @# @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@#@@#@@#@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@M@@ #
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@#@@# @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ @@#@@#@@@@@@@@@@@@@@@@@#@@#@#@@@@@@@@@@@@@@@@@@@@@#@#@@@@@@@@@@@@@@@@@@@@@@@@@
@ #@@@@@@@@@@@@@@@@@@@@#@@@@@@#@@@@@@@@@@@@@@@@@#@#@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ @@#@#@@@@@@@@@@@@@@@@@@#@####@@@@@@@@@@@@@@@@@M@#@@#@#@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@#@#M@@@M@@@@@@@@@@@@@@@@@@@M@@@@@@@@@@@@@@@@@@@@@@@@@@@@
#@M@#@#@@@@@@@@@@@@@@@@@@#@@@@@@@@@@@@@@@@@@@@@@@@M@@M@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@#@@#@@@@@@@@@@@@@@@@@@@@M@M@#@@@@@@@@@@@@@@@@@@@@@@@#@@@@@@@@@@@@@@@@@@@@@@@@
@@#@@#@@@@@@@@@@@@@@@@@@@@@@@M@ @M@@#@@@@@@@@@@@@@@@@@@@@@@@@@
@#@@@@@#@@@@@@@@@@@@@@@@@@@#@@ @@@@M@@@@@@@@@@@@@@@@@@@@@@@@
@@@#@@@##@@@#@@@@@#@@@@@##@@@@ #@#@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@####@@####@@@@#@@@@M@@@#@@# @@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@#@ @#@@#@@@ #@ @ #@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@# @@#@@ #@@#@@@@@@@@@@@@@@@@@@@@@@@@@
##@#@@ #M @# @@ @@M @@@@@@@@@@@@@@@@@@@@@@@@
@#@@@M #@ #@ # @@ @@@@@@@@@@@@@@@@@@@@@@@@
@@ @@#@@ ## @##@@ @@@@@@@@@@@@@@@@@@@@@@@@
@# @@M@ @@ @@@@@@@@@@@@@@@@@@@@@@@@
@@@##@@@ @@@@ @@@ @@ #@#@@#@@@@@@@@@@@@@@@@@
@@@@###@@###@@@@#@#@@@@#@@@ M@ #@ @ B @@@#@@@@@@@@@@@@@@@@@@@
@M@@@@@MM@@@@@M@@#@##@@@#@@M@B @# M@ @# #@ #@@#@@@@@@@@@@@@@@@@@@@
@#@#@@M@@M@@#@#@#@#@@#@#@#@@@@ @# @@ # @M @#@@@@@@@@@@@@@@@@@@@@@
@@@ @@@@#@##@ #@# @M # @ @ @@@@@#@@@@@@@@@@@@@@@@@
@@ @@ @#@@#@@#M #@@@@#@@@@@@@@@@@@@@@@@
M@# #@ @@@@##@@ @M@#M@@@#@@@@@@@@@@@@@@@@
@@@@ @@ @@@#@@@#@#@@@@@@@@@@@@@@@@
@# @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@M@H@@ @# @#@@@@#@@@#@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@#@#@##@M@@@M@ @M#@@@@@#@@#@@#@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
#M@@@##@@@@@@@@M@@@@#@@#@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@#@@@@@M@#@M@@B#M@@M@###@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
###@@@@@@@@@# @#@@@@@@@#@@@#@##@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@#@@M@@@#@@#@#@@@@@@#@@@#@#@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@#@M@#@#
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@M@@@@#
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@#@@@@@#@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@M@@##
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@#@@#@M
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@###@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@#@@@@@#@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@# #@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@# #@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
"""
"""
/ \ //\
|\___/| / \// \\
/0 0 \__ / // | \ \
/ / \/_/ // | \ \
@_^_@'/ \/_ // | \ \
//_^_/ \/_ // | \ \
( //) | \/// | \ \
( / /) _|_ / ) // | \ _\
( // /) '/,_ _ _/ ( ; -. | _ _\.-~ .-~~~^-.
(( / / )) ,-{ _ `-.|.-~-. .~ `.
(( // / )) '/\ / ~-. _ .-~ .-~^-. \
(( /// )) `. { } / \ \
(( / )) .----~-.\ \-' .~ \ `. \^-.
///.----..> \ _ -~ `. ^-` ^-_
///-._ _ _ _ _ _ _}^ - - - - ~ ~-- ,.-~
/.-~
"""
"""
____ _ _____
/ ___|___ __| | ___| ___|__ _ __ ___ ___ ___
| | / _ \ / _` |/ _ \ |_ / _ \| '__/ __/ _ \/ __|
| |__| (_) | (_| | __/ _| (_) | | | (_| __/\__ \
\____\___/ \__,_|\___|_| \___/|_| \___\___||___/
"""
"""
░░██▄░░░░░░░░░░░▄██
░▄▀░█▄░░░░░░░░▄█░░█░
░█░▄░█▄░░░░░░▄█░▄░█░
░█░██████████████▄█░
░█████▀▀████▀▀█████░
▄█▀█▀░░░████░░░▀▀███
██░░▀████▀▀████▀░░██
██░░░░█▀░░░░▀█░░░░██
███▄░░░░░░░░░░░░▄███
░▀███▄░░████░░▄███▀░
░░░▀██▄░▀██▀░▄██▀░░░
░░░░░░▀██████▀░░░░░░
░░░░░░░░░░░░░░░░░░░░
"""
"""
n = int(input())
os=0
ch=[]
for i in range(n):
m = int(input())
ch.append(m)
if ch[0]==10:
if 1 in ch:
print((len( ch[:ch.index(1)])))
break
else:
if 10 in ch:
print((len( ch[:ch.index(10)])))
break
"""
"""
n,m = map(int,input().split())
m = float(m)
mi = []
for i in range(n):
a,b = map(float,input().split())
mi.append((a*m)/b)
print(round(min(mi),6))
"""
"""
l = input().split()
l = set(l)
print(len(l))
"""
"""
x = input()
y = x[1:-1]
z = set(y.split(', '))
if x == "{}":
print(0)
else:
print(len(z))
"""
"""
n,k = map(int,input().split())
L = sorted(map(int, input().split()))
res = [L[0]]
for i in range(1,n):
if L[i] != L[i-1]:
res.append(L[i]-L[i-1])
l = len(res)
if k > l:
res += [0]*(k-l)
for i in range(k):
print(res[i])
"""
"""
from math import*
s,k = map(int,input().split(" "))
sq = input().split()
score = 0
pol = ""
for i in range(len(sq)):
if sq[i]>=sq[i-1]:
score+=1
print(ceil(score/len(sq))+ceil(score/len(sq)))
"""
"""
from math import*
s,k = map(int,input().split(" "))
sq = input().split()
score = 0
pol = ""
for i in range(len(sq)):
if sq[i]>=sq[i-1]:
score+=1
print(ceil(score/len(sq))+ceil(score/len(sq)))
"""
"""
st=list(input().split('+'))
st.sort()
for i in range(len(st)):
if i!=len(st)-1:
print(str(st[i])+'+',end='')
else:
print(str(st[i]))
"""
"""
a = input()
up = a.upper()
abc = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
print(abc[abc.find(up[0])]+a[1::])
"""
"""
n= int(input())
k = 0
for i in range(n):
p = input()
if p == "++X" or p == "X++":
k+=1
elif p == "--X" or p == "X--":
k-=1
print(k)
"""
"""
import math
c = 1
l = int(input())
g = ""
for i in range(l):
for s in range(1,l - i + 1):
g = g + " "
for j in range(0,i + 1):
if(i == 0 or j == 0):
c = 1
else:
c = c * (i - j + 1)/j
t = c
T=0
while(t != 0):
T = T + 1
t = int(math.floor(t/10))
p=0
while((p+T)!=4):
g = g + " "
p=p+1
g = g + str(int(math.floor(c)))
g = g + "\n"
print(g)
"""
"""
___ __ _ _
|_ _|_ __ / _| ___ _ __ _ __ ___ __ _| |_(_) ___ ___
| || '_ \| |_ / _ \| '__| '_ ` _ \ / _` | __| |/ __/ __|
| || | | | _| (_) | | | | | | | | (_| | |_| | (__\__ \
|___|_| |_|_| \___/|_| |_| |_| |_|\__,_|\__|_|\___|___/
"""
"""
from math import*
a1 = float(input())
a2 = float(input())
b = sqrt(a1**2 + a2**2)
print(b)
"""
"""
a1 = float(input())
a2 = float(input())
b = (a1**2 + a2**2)
import math
l = math.sqrt(b)
print(l)
"""
"""
n = int(input())
a=list(map(int,input().split(" ")))
b = []
for i in range(len(a)):
if i%2==0:
print(a[i],end=' ')
"""
"""
n = int(input())
a=list(map(int,input().split(" ")))
b = []
for i in range(len(a)):
if a[i]%2==0:
print(a[i],end=' ')
"""
"""
n = int(input())
a=list(map(int,input().split(" ")))
b = []
for i in range(len(a)):
if a[i]>0:
b.append(a[i])
print(len(b))
"""
"""
n = int(input())
a=list(map(int,input().split(" ")))
b = 0
for i in range(1,n):
if a[i]>a[i-1]:
b+=1
print(b)
"""
"""
n = int(input())
a=list(map(int,input().split(" ")))
b = 0
for i in range(1,n):
if a[i]>a[i-1]:
b+=1
print(b)
"""
"""
n = int(input())
a=list(map(int,input().split(" ")))
b = 0
for i in range(n-1):
if i == 0:
pass
elif a[i]>a[i-1]and a[i+1]< a[i]:
b+=1
print(b)
"""
"""
n = int(input())
a=list(map(int,input().split(" ")))
a.reverse()
for i in a:
print(i,end = " ")
"""
"""
n = int(input())
a=list(map(int,input().split(" ")))
print(max(a))
"""
"""
n = int(input())
a = list(map(int,input().split(" ")))
l = 0
q = []
for i in range(len(a)):
if a[i] in q:
pass
else:
l +=1
q.append(a[i])
print(l)
"""
"""
n = int(input())
a = list(map(int,input().split()))
x = int(input())
k =1
for i in range(len(a)):
k+=1
if x > a[i]:
print(i+1)
exit()
print(k)
"""
"""
a=list(map(int,input().split(" ")))
b = []
for i in range(len(a)):
if i%2==0:
print(a[i],end=' ')
"""
"""
a=list(map(int,input().split(" ")))
b = 0
for i in range(len(a)-1):
if i == 0:
pass
elif a[i]>a[i-1]and a[i+1]< a[i]:
b+=1
print(b)
"""
"""
a = list(map(int,input().split()))
print(max(a),a.index(max(a)))
"""
"""
ch = list(input())
if ch.count("h")>=1 and ch.count("e")>=1 and ch.count("l")>=2 and ch.count("o")>=1 and len(ch)!=53:
print("YES")
else:
print("NO")
"""
"""
from decimal import Decimal
x,y = map(Decimal,input().split(" "))
d = 1
while x < y and x - y < 0.000001 :
x += x * 70 / 100
d += 1
print(d)
"""
"""
n = int(input())
abc = "abcdefghijklmnopqrstuvwxyz"
s =""
for i in range(n):
k,v = map(int,input().split())
for i in range(k):
while len(s) <= k:
s += abc[:v]
if len(s)>k:
s = s[:-(len(s)-k)]
print(s,end="\n")
s=""
"""
"""
k = int(input())
l = int(input())
m = int(input())
n = int(input())
d = int(input())
lst = []
lst.append(k)
lst.append(l)
lst.append(m)
lst.append(n)
uron = 0
for i in range(len(lst)):
if d % lst[i] == 0:
uron+=lst[i]
print(uron)
"""
"""
n = int(input())
a = list(map(int,input().split()))
ch = 0
nch = 0
for i in range(len(a)):
if a[i] % 2 == 0:
ch+=1
else:
nch+=1
if ch > nch:
for i in range(len(a)):
if a[i] % 2 == 1:
print(a.index(a[i])+1)
else:
for i in range(len(a)):
if a[i]%2==0:
print(a.index(a[i])+1)
"""
"""
n,t = map(int,input().split())
oc = input()
for i in range (1,n):
if oc[i]=="B":
oc[i]=oc[i-1]
print(oc)
"""
"""
n = int(input())
o = 0
for i in range(n):
o += ((n-2) - (n % 2))//2
print(o)
"""
"""
sl = input()
abc = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
m=0
b=0
big = ""
for i in range(len(sl)):
if sl[i]== abc[abc.find(sl[i])]:
b+=1
else:
m +=1
if m>b:
big += sl.lower()
print(big)
elif b>m:
big += sl.upper()
print(big)
elif b==m:
big += sl.lower()
print(big)
"""
"""
n = int(input())
a = list(map(int,input().split()))
for i in range(n):
print(a.index(i+1)+1, end=' ')
"""
"""
n = int(input())
if n % 2 == 0 and n != 2 :
print("YES")
else:
print("NO")
"""
"""
a = input().replace("WUB"," ")
print(a)
"""
"""
a = int(input())
b = list(map(int,input().split()))
b.sort()
for i in b:
print(i,end=" ")
"""
"""
a,b = map(int,input().split())
o = 0
if a % 2 == 0:
o = a//2
else:
o = (a//2)+1
if b <= o:
print((1+((o-1)*2)))
else:
print(((o-1)*2))
"""
"""
a,b = map(int,input().split())
year = 0
while b>=a:
a*=3
b*=2
year+=1
print(year)
"""
"""
n,m = map(int,input().split())
m = float(m)
mi = []
for i in range(n):
a,b = map(float,input().split())
mi.append((a*m)/b)
print(min(mi))
"""
"""
n = int(input())
x = 0
for i in range(n):
a = input()
if a == "Tetrahedron":
x+=4
elif a == "Cube":
x+=6
elif a == "Octahedron":
x+=8
elif a == "Dodecahedron":
x+=12
elif a == "Icosahedron":
x+=20
print(x)
"""
"""
n= int(input())
a = list(map(int,input().split()))
for i in a:
if sum(a)>0:
print("HARD")
break
else:
print("EASY")
break
"""
"""
a,b = map(int,input().split())
c = list(map(int,input().split()))
bal = 0
for i in range(1,len(c)+1):
if b == len(c):
if c[i]>=c[b-1]:
bal +=1
else:
if c[i]>=c[b] and c[i]!= 0:
bal+=1
print(bal)
"""
"""
a,b =map(int, input().split())
y=list(map(int,input().split()))
for i in y:
if i<y[b-1] or i==0:
a-=1
print(a)
"""
"""
a,b=map(int,input().split())
c=b-(a+1)//2
if c > 0:
print(2*c)
else:
print(2*b-1)
"""
"""
a = input()
b = input()
a1 = a.lower()
b1 = b.lower()
o = 0
k = 0
if a1>b1:
o+=1
if b1>a1:
k+=1
print(o-k)
"""
"""
n=int(input())
p=input().split()
q=input().split()
m = p[1:]
j = q[1:]
if len(set(m+j))==n:
print("I become the guy.")
else:
print("Oh, my keyboard!")
"""
"""
a = set(input())
for i in range(len(a)):
a.remove()
if a == "hello":
print("YES")
else:
print("NO")
"""
"""
n = list(map(int,input()))
a = n.count(4)+n.count(7)
if a == 7 or a == 4:
print("YES")
else:
print("NO")
"""
"""
n = int(input())
b = input()
b = b.upper
abc = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
for i in range(len(b)):
if abc[i] in b:
print("YES")
else:
print("NO")
"""
"""
from math import*
n,a,b = list(map(int,input().split()))
pos = 0
for i in range(n):
if (a + b) % 2 == 0:
print(a+b)
break
else:
print(ceil((a+b)/2))
break
"""
"""
n = int(input())
ans = 0
for i in range(n):
a,b,c = map(str,input().split())
b = int(b)
for i in range(n):
if b == -b and c == "YES":
print("Impossible")
elif ans > b and c == "Y":
ans += 1
elif ans < b and c == "Y":
ans+=1
elif ans >= b and c == "Y":
ans+=1
elif ans <= b and c == "Y":
ans+=1
elif ans > b and c == "N":
break
elif ans < b and c == "N":
break
elif ans >= b and c == "N":
break
elif ans <= b and c == "N":
break
print(ans)
"""
"""
from math import*
n,k = map(int,input().split())
a = list(map(int,input().split()))
com = 0
for i in range(len(a)):
if a[i]+2 <= 5:
com += 0.333
print(ceil(com))
"""
"""
n,a,b = map(int,input().split())
d = []
s = 0
k = 1
for i in range(n-1):
if a == 0 and b == 0:
print(n)
exit()
d.append("*"*((a+i)) +"+"+"*"*(((b-i)-k)))
if len(d[i])<=n:
s+=1
print(s)
"""
"""
n,h =map(int, input().split())
for i in map(int, input().split()):
if i > h:
n+=1
print(n)
"""
"""
n = input()
a = input()
if a.count('A')> a.count('D'):
print('Anton')
elif a.count('A')<a.count('D'):
print('Danik')
else:
print('Friendship')
"""
"""
n = int(input())
a=[]
for i in range(n):
a.append(list(map(int,input().split())))
g = list(map(sum,a))
count=0
i=0
for j in g:
if j >=2:
count+=1
print(count)
"""
"""
n=int(input())
x=input()
c=0
for i in range(n-1):
if x[i] == x[i+1]:
c+=1
print(c)
"""
"""
k = list(map(int,input().split()))
t = input()
kal = 0
for i in range(len(t)):
if t[i]=="1":kal += k[0]
elif t[i]=="2":kal += k[1]
elif t[i]=="3":kal += k[2]
elif t[i] == "4":kal += k[3]
print(kal)
"""
"""
orient = input()
key = input()
keyboard = "poiuytrewq;lkjhgfdsa/.,mnbvcxz"
ans = ""
for i in range(len(key)):
if orient == "R":
ans += keyboard[keyboard.find(key[i])+1]
elif orient == "L":
ans += keyboard[keyboard.find(key[i])-1]
print(ans)
"""
"""
n,k = map(int, input().split())
abc = "abcdefghijklmnopqrstuvwxyz"
f = abc[:k]
s = f
while len(s) < n:
s += f
s = s[:n]
print(s)
"""
"""
n = int(input())
if n %2 == 0 or n == 2:
print("YES")
else:
print("NO")
"""
"""
mas = 0
while 1:
try:
a = input()
if ":" in a:
mas += len(a[a.find(":"):])
except EOFError:
print(mas)
"""
"""
a = input()
b = input()
c = str(int(a)+int(b))
if int(a.replace("0",""))+int(b.replace("0",""))== int(c.replace("0","")):
print("YES")
else:
print("NO")
"""
"""
s = input()
w = len(s)
n=int(input())
b=[]
for i in range(n):
wd=input()
if wd[:w]==s:
b.append(wd)
b.sort()
if len(b)==0:
print(s)
else:
print(min(b))
"""
n = int(input())
ans = 0
for i in range(n):
x,a = map(int,input().split())
if x == -x and a:
ans += a
else:
ans+=a
print(ans)
``` | instruction | 0 | 44,252 | 3 | 88,504 |
No | output | 1 | 44,252 | 3 | 88,505 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Amr lives in Lala Land. Lala Land is a very beautiful country that is located on a coordinate line. Lala Land is famous with its apple trees growing everywhere.
Lala Land has exactly n apple trees. Tree number i is located in a position xi and has ai apples growing on it. Amr wants to collect apples from the apple trees. Amr currently stands in x = 0 position. At the beginning, he can choose whether to go right or left. He'll continue in his direction until he meets an apple tree he didn't visit before. He'll take all of its apples and then reverse his direction, continue walking in this direction until he meets another apple tree he didn't visit before and so on. In the other words, Amr reverses his direction when visiting each new apple tree. Amr will stop collecting apples when there are no more trees he didn't visit in the direction he is facing.
What is the maximum number of apples he can collect?
Input
The first line contains one number n (1 ≤ n ≤ 100), the number of apple trees in Lala Land.
The following n lines contains two integers each xi, ai ( - 105 ≤ xi ≤ 105, xi ≠ 0, 1 ≤ ai ≤ 105), representing the position of the i-th tree and number of apples on it.
It's guaranteed that there is at most one apple tree at each coordinate. It's guaranteed that no tree grows in point 0.
Output
Output the maximum number of apples Amr can collect.
Examples
Input
2
-1 5
1 5
Output
10
Input
3
-2 2
1 4
-1 3
Output
9
Input
3
1 9
3 5
7 10
Output
9
Note
In the first sample test it doesn't matter if Amr chose at first to go left or right. In both cases he'll get all the apples.
In the second sample test the optimal solution is to go left to x = - 1, collect apples from there, then the direction will be reversed, Amr has to go to x = 1, collect apples from there, then the direction will be reversed and Amr goes to the final tree x = - 2.
In the third sample test the optimal solution is to go right to x = 1, collect apples from there, then the direction will be reversed and Amr will not be able to collect anymore apples because there are no apple trees to his left.
Submitted Solution:
```
from sys import stdin, stdout
def main():
n = int(stdin.readline())
res = 0
x_pos = []
x_neg = []
for t in range(n):
x, a = [int(c) for c in stdin.readline().split()]
if x > 0: x_pos.append([x, a])
else: x_neg.append([x, a])
min_length = min(len(x_pos), len(x_neg))
res = sum(a for x, a in x_pos[:min_length])
res += sum(a for x, a in x_neg[:min_length])
if len(x_pos) > len(x_neg):
res += x_pos[min_length][1]
if len(x_neg) > len(x_pos):
res += x_neg[min_length][1]
stdout.write(str(res))
#--------------------------------------------------------
if __name__ == "__main__":
main()
``` | instruction | 0 | 44,253 | 3 | 88,506 |
No | output | 1 | 44,253 | 3 | 88,507 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Amr lives in Lala Land. Lala Land is a very beautiful country that is located on a coordinate line. Lala Land is famous with its apple trees growing everywhere.
Lala Land has exactly n apple trees. Tree number i is located in a position xi and has ai apples growing on it. Amr wants to collect apples from the apple trees. Amr currently stands in x = 0 position. At the beginning, he can choose whether to go right or left. He'll continue in his direction until he meets an apple tree he didn't visit before. He'll take all of its apples and then reverse his direction, continue walking in this direction until he meets another apple tree he didn't visit before and so on. In the other words, Amr reverses his direction when visiting each new apple tree. Amr will stop collecting apples when there are no more trees he didn't visit in the direction he is facing.
What is the maximum number of apples he can collect?
Input
The first line contains one number n (1 ≤ n ≤ 100), the number of apple trees in Lala Land.
The following n lines contains two integers each xi, ai ( - 105 ≤ xi ≤ 105, xi ≠ 0, 1 ≤ ai ≤ 105), representing the position of the i-th tree and number of apples on it.
It's guaranteed that there is at most one apple tree at each coordinate. It's guaranteed that no tree grows in point 0.
Output
Output the maximum number of apples Amr can collect.
Examples
Input
2
-1 5
1 5
Output
10
Input
3
-2 2
1 4
-1 3
Output
9
Input
3
1 9
3 5
7 10
Output
9
Note
In the first sample test it doesn't matter if Amr chose at first to go left or right. In both cases he'll get all the apples.
In the second sample test the optimal solution is to go left to x = - 1, collect apples from there, then the direction will be reversed, Amr has to go to x = 1, collect apples from there, then the direction will be reversed and Amr goes to the final tree x = - 2.
In the third sample test the optimal solution is to go right to x = 1, collect apples from there, then the direction will be reversed and Amr will not be able to collect anymore apples because there are no apple trees to his left.
Submitted Solution:
```
import bisect
n = int(input())
trees = []
sm = 0
sp = 0
v1 = []
v2 = []
def ke(n):
return n[0]
for i in range(n):
x,a = map(int, input().split())
if x<0:
sm+=a
v1.append([x,a])
else:
sp+=a
v2.append([x,a])
v1.sort(key=ke,reverse=True)
v2.sort(key=ke)
curr = 0
dir = True
if sm>sp:
dir = True
else:
dir = False
answ = 0
while True:
if dir:
if len(v1) == 0:
break
answ+=v1[0][1]
v1.pop(0)
dir = False
else:
if len(v2) == 0:
break
answ+=v2[0][1]
v2.pop(0)
dir = True
print(answ)
``` | instruction | 0 | 44,254 | 3 | 88,508 |
No | output | 1 | 44,254 | 3 | 88,509 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Real Cosmic Communications is the largest telecommunication company on a far far away planet, located at the very edge of the universe. RCC launches communication satellites.
The planet is at the very edge of the universe, so its form is half of a circle. Its radius is r, the ends of its diameter are points A and B. The line AB is the edge of the universe, so one of the half-planes contains nothing, neither the planet, nor RCC satellites, nor anything else. Let us introduce coordinates in the following way: the origin is at the center of AB segment, OX axis coincides with line AB, the planet is completely in y > 0 half-plane.
The satellite can be in any point of the universe, except the planet points. Satellites are never located beyond the edge of the universe, nor on the edge itself — that is, they have coordinate y > 0. Satellite antennas are directed in such way that they cover the angle with the vertex in the satellite, and edges directed to points A and B. Let us call this area the satellite coverage area.
The picture below shows coordinate system and coverage area of a satellite.
<image>
When RCC was founded there were no satellites around the planet. Since then there have been several events of one of the following types:
1. 1 x y — launch the new satellite and put it to the point (x, y). Satellites never move and stay at the point they were launched. Let us assign the number i to the i-th satellite in order of launching, starting from one.
2. 2 i — remove satellite number i.
3. 3 i j — make an attempt to create a communication channel between satellites i and j. To create a communication channel a repeater is required. It must not be located inside the planet, but can be located at its half-circle border, or above it. Repeater must be in coverage area of both satellites i and j. To avoid signal interference, it must not be located in coverage area of any other satellite. Of course, the repeater must be within the universe, it must have a coordinate y > 0.
For each attempt to create a communication channel you must find out whether it is possible.
Sample test has the following satellites locations:
<image>
Input
The first line of input data contains integers r and n — radius of the planet and the number of events (1 ≤ r ≤ 109, 1 ≤ n ≤ 5·105).
Each of the following n lines describe events in the specified format.
Satellite coordinates are integer, the satisfy the following constraints |x| ≤ 109, 0 < y ≤ 109. No two satellites that simultaneously exist can occupy the same point. Distance from each satellite to the center of the planet is strictly greater than r.
It is guaranteed that events of types 2 and 3 only refer to satellites that exist at the moment. For all events of type 3 the inequality i ≠ j is satisfied.
Output
For each event of type 3 print «YES» on a separate line, if it is possible to create a communication channel, or «NO» if it is impossible.
Example
Input
5 8
1 -5 8
1 -4 8
1 -3 8
1 2 7
3 1 3
2 2
3 1 3
3 3 4
Output
NO
YES
YES
Submitted Solution:
```
print("Good Luck!")
``` | instruction | 0 | 44,364 | 3 | 88,728 |
No | output | 1 | 44,364 | 3 | 88,729 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Andrew's favourite Krakozyabra has recenly fled away and now he's eager to bring it back!
At the moment the refugee is inside an icy cave with n icicles dangling from the ceiling located in integer coordinates numbered from 1 to n. The distance between floor and the i-th icicle is equal to ai.
Andrew is free to choose an arbitrary integer point T in range from 1 to n inclusive and at time instant 0 launch a sound wave spreading into both sides (left and right) at the speed of one point per second. Any icicle touched by the wave starts falling at the same speed (that means that in a second the distance from floor to icicle decreases by one but cannot become less that zero). While distance from icicle to floor is more than zero, it is considered passable; as soon as it becomes zero, the icicle blocks the path and prohibits passing.
Krakozyabra is initially (i.e. at time instant 0) is located at point <image> and starts running in the right direction at the speed of one point per second. You can assume that events in a single second happen in the following order: first Krakozyabra changes its position, and only then the sound spreads and icicles fall; in particular, that means that if Krakozyabra is currently at point <image> and the falling (i.e. already touched by the sound wave) icicle at point i is 1 point from the floor, then Krakozyabra will pass it and find itself at <image> and only after that the icicle will finally fall and block the path.
Krakozyabra is considered entrapped if there are fallen (i.e. with ai = 0) icicles both to the left and to the right of its current position. Help Andrew find the minimum possible time it takes to entrap Krakozyabra by choosing the optimal value of T or report that this mission is impossible.
Input
The first line contains the number of icicles n (2 ≤ n ≤ 105).
The next line contains n space-separated numbers ai (1 ≤ ai ≤ 105) — the distances from floor to icicles.
Output
Print an only integer — the minimum time it takes to entrap Krakozyabra between two fallen icicles. If it is impossible, print - 1.
Examples
Input
5
1 4 3 5 1
Output
3
Input
4
1 2 1 1
Output
2
Input
2
2 1
Output
3
Input
2
1 2
Output
-1
Note
In sample case one it's optimal to launch the sound wave from point 3. Then in two seconds icicles 1 and 5 will start falling, and in one more seconds they will block the paths. Krakozyabra will be located at <image> at that time. Note that icicle number 3 will also be fallen, so there will actually be two icicles blocking the path to the left.
In sample case two it is optimal to launch the wave from point 2 and entrap Krakozyabra in 2 seconds.
In sample case four the answer is impossible.
Submitted Solution:
```
n = int(input())
b = list( map(int, input().split() ) )
L = []
T = None
for i in range( len(b) ):
left = None
right = None
for j in range( len(b) ):
tj = b[j] + abs(i-j)
if tj <= j and (right == None or tj <= right):
#print(j, ' prende')
right = tj
else:
#print(j, ' não')
if left == None or tj <= left:
left = tj
if right:
t = max(left, right)
if T == None or t < T:
T = t
if not T:
print(-1)
else:
print(T)
``` | instruction | 0 | 44,401 | 3 | 88,802 |
No | output | 1 | 44,401 | 3 | 88,803 |
Provide a correct Python 3 solution for this coding contest problem.
Nathan O. Davis is challenging a kind of shooter game. In this game, enemies emit laser beams from outside of the screen. A laser beam is a straight line with a certain thickness. Nathan moves a circular-shaped machine within the screen, in such a way it does not overlap a laser beam. As in many shooters, the machine is destroyed when the overlap happens.
Nathan is facing an uphill stage. Many enemies attack simultaneously in this stage, so eventually laser beams fill out almost all of the screen. Surprisingly, it is even possible he has no "safe area" on the screen. In other words, the machine cannot survive wherever it is located in some cases.
The world is as kind as it is cruel! There is a special item that helps the machine to survive any dangerous situation, even if it is exposed in a shower of laser beams, for some seconds. In addition, another straight line (called "a warning line") is drawn on the screen for a few seconds before a laser beam is emit along that line.
The only problem is that Nathan has a little slow reflexes. He often messes up the timing to use the special item. But he knows a good person who can write a program to make up his slow reflexes - it's you! So he asked you for help.
Your task is to write a program to make judgement whether he should use the item or not, for given warning lines and the radius of the machine.
Input
The input is a sequence of datasets. Each dataset corresponds to one situation with warning lines in the following format:
W H N R
x1,1 y1,1 x1,2 y1,2 t1
x2,1 y2,1 x2,2 y2,2 t2
...
xN,1 yN,1 xN,2 yN,2 tN
The first line of a dataset contains four integers W, H, N and R (2 < W ≤ 640, 2 < H ≤ 480, 0 ≤ N ≤ 100 and 0 < R < min{W, H}/2). The first two integers W and H indicate the width and height of the screen, respectively. The next integer N represents the number of laser beams.
The last integer R indicates the radius of the machine. It is guaranteed that the output would remain unchanged if the radius of the machine would become larger by 10-5 than R.
The following N lines describe the N warning lines. The (i+1)-th line of the dataset corresponds to the i-th warning line, which is represented as a straight line which passes through two given different coordinates (xi,1, yi,1 ) and (xi,2 , yi,2 ). The last integer ti indicates the thickness of the laser beam corresponding to the i-th warning line.
All given coordinates (x, y) on the screen are a pair of integers (0 ≤ x ≤ W, 0 ≤ y ≤ H). Note that, however, the machine is allowed to be located at non-integer coordinates during the play.
The input is terminated by a line with four zeros. This line should not be processed.
Output
For each case, print "Yes" in a line if there is a safe area, or print "No" otherwise.
Example
Input
100 100 1 1
50 0 50 100 50
640 480 1 1
0 0 640 480 100
0 0 0 0
Output
No
Yes | instruction | 0 | 44,609 | 3 | 89,218 |
"Correct Solution:
```
import sys
readline = sys.stdin.readline
write = sys.stdout.write
def cross_point(p0, q0, p1, q1):
x0, y0 = p0; x1, y1 = q0
x2, y2 = p1; x3, y3 = q1
dx0 = x1 - x0
dy0 = y1 - y0
dx1 = x3 - x2
dy1 = y3 - y2
s = (y0-y2)*dx1 - (x0-x2)*dy1
sm = dx0*dy1 - dy0*dx1
if sm == 0:
return None
return x0 + s*dx0/sm, y0 + s*dy0/sm
def solve():
W, H, N, R = map(int, readline().split())
if W == H == 0:
return False
L = [tuple(map(int, readline().split())) for i in range(N)]
L.extend([
(0, 0, W, 0, 0),
(0, 0, 0, H, 0),
(0, H, W, H, 0),
(W, 0, W, H, 0),
])
EPS = 1e-9
pp = ((1, 1), (1, -1), (-1, 1), (-1, -1))
for i in range(N+4):
xi1, yi1, xi2, yi2, t0 = L[i]
p0 = (xi1, yi1); q0 = (xi2, yi2)
dx0 = (xi2 - xi1); dy0 = (yi2 - yi1)
d0 = (dx0**2 + dy0**2)**.5
for j in range(i):
xj1, yj1, xj2, yj2, t1 = L[j]
p1 = (xj1, yj1); q1 = (xj2, yj2)
dx1 = (xj2 - xj1); dy1 = (yj2 - yj1)
d1 = (dx1**2 + dy1**2)**.5
cp = cross_point(p0, q0, p1, q1)
if cp is None:
continue
x0, y0 = cp
sv = abs(dx0*dy1 - dx1*dy0)
for p, q in pp:
a = p*d1*(t1+R)
b = q*d0*(t0+R)
x = x0 + (a * dx0 + b * dx1) / sv
y = y0 + (a * dy0 + b * dy1) / sv
if not R - EPS < x < W-R + EPS or not R - EPS < y < H-R + EPS:
continue
ok = 1
for k in range(N):
xk1, yk1, xk2, yk2, t2 = L[k]
dxp = xk2 - xk1; dyp = yk2 - yk1
dxq = x - xk1; dyq = y - yk1
d2 = (dxp**2 + dyp**2)**.5
if abs(dxp*dyq - dxq*dyp) < (R + t2) * d2 - EPS:
ok = 0
if ok:
write("Yes\n")
return True
write("No\n")
return True
while solve():
...
``` | output | 1 | 44,609 | 3 | 89,219 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
As you know, lemmings like jumping. For the next spectacular group jump n lemmings gathered near a high rock with k comfortable ledges on it. The first ledge is situated at the height of h meters, the second one is at the height of 2h meters, and so on (the i-th ledge is at the height of i·h meters). The lemmings are going to jump at sunset, and there's not much time left.
Each lemming is characterized by its climbing speed of vi meters per minute and its weight mi. This means that the i-th lemming can climb to the j-th ledge in <image> minutes.
To make the jump beautiful, heavier lemmings should jump from higher ledges: if a lemming of weight mi jumps from ledge i, and a lemming of weight mj jumps from ledge j (for i < j), then the inequation mi ≤ mj should be fulfilled.
Since there are n lemmings and only k ledges (k ≤ n), the k lemmings that will take part in the jump need to be chosen. The chosen lemmings should be distributed on the ledges from 1 to k, one lemming per ledge. The lemmings are to be arranged in the order of non-decreasing weight with the increasing height of the ledge. In addition, each lemming should have enough time to get to his ledge, that is, the time of his climb should not exceed t minutes. The lemmings climb to their ledges all at the same time and they do not interfere with each other.
Find the way to arrange the lemmings' jump so that time t is minimized.
Input
The first line contains space-separated integers n, k and h (1 ≤ k ≤ n ≤ 105, 1 ≤ h ≤ 104) — the total number of lemmings, the number of ledges and the distance between adjacent ledges.
The second line contains n space-separated integers m1, m2, ..., mn (1 ≤ mi ≤ 109), where mi is the weight of i-th lemming.
The third line contains n space-separated integers v1, v2, ..., vn (1 ≤ vi ≤ 109), where vi is the speed of i-th lemming.
Output
Print k different numbers from 1 to n — the numbers of the lemmings who go to ledges at heights h, 2h, ..., kh, correspondingly, if the jump is organized in an optimal way. If there are multiple ways to select the lemmings, pick any of them.
Examples
Input
5 3 2
1 2 3 2 1
1 2 1 2 10
Output
5 2 4
Input
5 3 10
3 4 3 2 1
5 4 3 2 1
Output
4 3 1
Note
Let's consider the first sample case. The fifth lemming (speed 10) gets to the ledge at height 2 in <image> minutes; the second lemming (speed 2) gets to the ledge at height 4 in 2 minutes; the fourth lemming (speed 2) gets to the ledge at height 6 in 3 minutes. All lemmings manage to occupy their positions in 3 minutes.
Submitted Solution:
```
N = input().split()
t = int(N[-1])
queue = input()
while t:
queue = queue.replace('BG','GB')
t -= 1
print(queue)
``` | instruction | 0 | 44,853 | 3 | 89,706 |
No | output | 1 | 44,853 | 3 | 89,707 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
As you know, lemmings like jumping. For the next spectacular group jump n lemmings gathered near a high rock with k comfortable ledges on it. The first ledge is situated at the height of h meters, the second one is at the height of 2h meters, and so on (the i-th ledge is at the height of i·h meters). The lemmings are going to jump at sunset, and there's not much time left.
Each lemming is characterized by its climbing speed of vi meters per minute and its weight mi. This means that the i-th lemming can climb to the j-th ledge in <image> minutes.
To make the jump beautiful, heavier lemmings should jump from higher ledges: if a lemming of weight mi jumps from ledge i, and a lemming of weight mj jumps from ledge j (for i < j), then the inequation mi ≤ mj should be fulfilled.
Since there are n lemmings and only k ledges (k ≤ n), the k lemmings that will take part in the jump need to be chosen. The chosen lemmings should be distributed on the ledges from 1 to k, one lemming per ledge. The lemmings are to be arranged in the order of non-decreasing weight with the increasing height of the ledge. In addition, each lemming should have enough time to get to his ledge, that is, the time of his climb should not exceed t minutes. The lemmings climb to their ledges all at the same time and they do not interfere with each other.
Find the way to arrange the lemmings' jump so that time t is minimized.
Input
The first line contains space-separated integers n, k and h (1 ≤ k ≤ n ≤ 105, 1 ≤ h ≤ 104) — the total number of lemmings, the number of ledges and the distance between adjacent ledges.
The second line contains n space-separated integers m1, m2, ..., mn (1 ≤ mi ≤ 109), where mi is the weight of i-th lemming.
The third line contains n space-separated integers v1, v2, ..., vn (1 ≤ vi ≤ 109), where vi is the speed of i-th lemming.
Output
Print k different numbers from 1 to n — the numbers of the lemmings who go to ledges at heights h, 2h, ..., kh, correspondingly, if the jump is organized in an optimal way. If there are multiple ways to select the lemmings, pick any of them.
Examples
Input
5 3 2
1 2 3 2 1
1 2 1 2 10
Output
5 2 4
Input
5 3 10
3 4 3 2 1
5 4 3 2 1
Output
4 3 1
Note
Let's consider the first sample case. The fifth lemming (speed 10) gets to the ledge at height 2 in <image> minutes; the second lemming (speed 2) gets to the ledge at height 4 in 2 minutes; the fourth lemming (speed 2) gets to the ledge at height 6 in 3 minutes. All lemmings manage to occupy their positions in 3 minutes.
Submitted Solution:
```
from sys import stdin, stdout
n, k, h = map(int, stdin.readline().split())
weight = list(map(int, stdin.readline().split()))
speed = list(map(int, stdin.readline().split()))
lemings = []
for i in range(n):
lemings.append((weight[i], speed[i], i + 1))
lemings.sort()
l = 0
r = k * h
mx = max(speed)
ind = k + 2
e = 10 ** (-10)
while ((r - l) > e):
m = (r + l) / 2
ind = 1
for i in range(n):
if h * ind / lemings[i][1] <= m:
ind += 1
if ind > k:
r = m
else:
l = m
ans = []
ind = 1
for i in range(n):
if h * ind / lemings[i][1] <= r:
ind += 1
ans.append(lemings[i][2])
if ind == k + 1:
break
stdout.write(' '.join(list(map(str, ans))))
``` | instruction | 0 | 44,854 | 3 | 89,708 |
No | output | 1 | 44,854 | 3 | 89,709 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
As you know, lemmings like jumping. For the next spectacular group jump n lemmings gathered near a high rock with k comfortable ledges on it. The first ledge is situated at the height of h meters, the second one is at the height of 2h meters, and so on (the i-th ledge is at the height of i·h meters). The lemmings are going to jump at sunset, and there's not much time left.
Each lemming is characterized by its climbing speed of vi meters per minute and its weight mi. This means that the i-th lemming can climb to the j-th ledge in <image> minutes.
To make the jump beautiful, heavier lemmings should jump from higher ledges: if a lemming of weight mi jumps from ledge i, and a lemming of weight mj jumps from ledge j (for i < j), then the inequation mi ≤ mj should be fulfilled.
Since there are n lemmings and only k ledges (k ≤ n), the k lemmings that will take part in the jump need to be chosen. The chosen lemmings should be distributed on the ledges from 1 to k, one lemming per ledge. The lemmings are to be arranged in the order of non-decreasing weight with the increasing height of the ledge. In addition, each lemming should have enough time to get to his ledge, that is, the time of his climb should not exceed t minutes. The lemmings climb to their ledges all at the same time and they do not interfere with each other.
Find the way to arrange the lemmings' jump so that time t is minimized.
Input
The first line contains space-separated integers n, k and h (1 ≤ k ≤ n ≤ 105, 1 ≤ h ≤ 104) — the total number of lemmings, the number of ledges and the distance between adjacent ledges.
The second line contains n space-separated integers m1, m2, ..., mn (1 ≤ mi ≤ 109), where mi is the weight of i-th lemming.
The third line contains n space-separated integers v1, v2, ..., vn (1 ≤ vi ≤ 109), where vi is the speed of i-th lemming.
Output
Print k different numbers from 1 to n — the numbers of the lemmings who go to ledges at heights h, 2h, ..., kh, correspondingly, if the jump is organized in an optimal way. If there are multiple ways to select the lemmings, pick any of them.
Examples
Input
5 3 2
1 2 3 2 1
1 2 1 2 10
Output
5 2 4
Input
5 3 10
3 4 3 2 1
5 4 3 2 1
Output
4 3 1
Note
Let's consider the first sample case. The fifth lemming (speed 10) gets to the ledge at height 2 in <image> minutes; the second lemming (speed 2) gets to the ledge at height 4 in 2 minutes; the fourth lemming (speed 2) gets to the ledge at height 6 in 3 minutes. All lemmings manage to occupy their positions in 3 minutes.
Submitted Solution:
```
from sys import stdin, stdout
n, k, h = map(int, stdin.readline().split())
weight = list(map(int, stdin.readline().split()))
speed = list(map(int, stdin.readline().split()))
lemings = []
for i in range(n):
lemings.append((weight[i], speed[i], i + 1))
lemings.sort()
l = 0
r = k * h
mx = max(speed)
ind = k + 2
e = 10 ** (-6)
while ((r - l) > e):
m = (r + l) / 2
ind = 1
for i in range(n):
if h * ind / lemings[i][1] <= m:
ind += 1
if ind > k:
r = m
else:
l = m
ans = []
ind = 1
for i in range(n):
if h * ind / lemings[i][1] <= r:
ind += 1
ans.append(lemings[i][2])
if ind == k + 1:
break
stdout.write(' '.join(list(map(str, ans))))
``` | instruction | 0 | 44,855 | 3 | 89,710 |
No | output | 1 | 44,855 | 3 | 89,711 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
As you know, lemmings like jumping. For the next spectacular group jump n lemmings gathered near a high rock with k comfortable ledges on it. The first ledge is situated at the height of h meters, the second one is at the height of 2h meters, and so on (the i-th ledge is at the height of i·h meters). The lemmings are going to jump at sunset, and there's not much time left.
Each lemming is characterized by its climbing speed of vi meters per minute and its weight mi. This means that the i-th lemming can climb to the j-th ledge in <image> minutes.
To make the jump beautiful, heavier lemmings should jump from higher ledges: if a lemming of weight mi jumps from ledge i, and a lemming of weight mj jumps from ledge j (for i < j), then the inequation mi ≤ mj should be fulfilled.
Since there are n lemmings and only k ledges (k ≤ n), the k lemmings that will take part in the jump need to be chosen. The chosen lemmings should be distributed on the ledges from 1 to k, one lemming per ledge. The lemmings are to be arranged in the order of non-decreasing weight with the increasing height of the ledge. In addition, each lemming should have enough time to get to his ledge, that is, the time of his climb should not exceed t minutes. The lemmings climb to their ledges all at the same time and they do not interfere with each other.
Find the way to arrange the lemmings' jump so that time t is minimized.
Input
The first line contains space-separated integers n, k and h (1 ≤ k ≤ n ≤ 105, 1 ≤ h ≤ 104) — the total number of lemmings, the number of ledges and the distance between adjacent ledges.
The second line contains n space-separated integers m1, m2, ..., mn (1 ≤ mi ≤ 109), where mi is the weight of i-th lemming.
The third line contains n space-separated integers v1, v2, ..., vn (1 ≤ vi ≤ 109), where vi is the speed of i-th lemming.
Output
Print k different numbers from 1 to n — the numbers of the lemmings who go to ledges at heights h, 2h, ..., kh, correspondingly, if the jump is organized in an optimal way. If there are multiple ways to select the lemmings, pick any of them.
Examples
Input
5 3 2
1 2 3 2 1
1 2 1 2 10
Output
5 2 4
Input
5 3 10
3 4 3 2 1
5 4 3 2 1
Output
4 3 1
Note
Let's consider the first sample case. The fifth lemming (speed 10) gets to the ledge at height 2 in <image> minutes; the second lemming (speed 2) gets to the ledge at height 4 in 2 minutes; the fourth lemming (speed 2) gets to the ledge at height 6 in 3 minutes. All lemmings manage to occupy their positions in 3 minutes.
Submitted Solution:
```
from sys import stdin, stdout
n, k, h = map(int, stdin.readline().split())
weight = list(map(int, stdin.readline().split()))
speed = list(map(int, stdin.readline().split()))
lemings = []
for i in range(n):
lemings.append((weight[i], speed[i], i + 1))
lemings.sort()
ans = []
l = 0
r = k * h
e = 10 ** (-3)
while (r - l > e):
chance = []
m = (r + l) / 2
ind = 1
for i in range(n):
if h * ind / lemings[i][1] <= m:
chance.append(lemings[i][2])
ind += 1
if ind == k + 1:
break
if ind == k + 1:
r = m
ans = chance[::]
else:
l = m
stdout.write(' '.join(list(map(str, ans))))
``` | instruction | 0 | 44,856 | 3 | 89,712 |
No | output | 1 | 44,856 | 3 | 89,713 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Goa'uld Apophis captured Jack O'Neill's team again! Jack himself was able to escape, but by that time Apophis's ship had already jumped to hyperspace. But Jack knows on what planet will Apophis land. In order to save his friends, Jack must repeatedly go through stargates to get to this planet.
Overall the galaxy has n planets, indexed with numbers from 1 to n. Jack is on the planet with index 1, and Apophis will land on the planet with index n. Jack can move between some pairs of planets through stargates (he can move in both directions); the transfer takes a positive, and, perhaps, for different pairs of planets unequal number of seconds. Jack begins his journey at time 0.
It can be that other travellers are arriving to the planet where Jack is currently located. In this case, Jack has to wait for exactly 1 second before he can use the stargate. That is, if at time t another traveller arrives to the planet, Jack can only pass through the stargate at time t + 1, unless there are more travellers arriving at time t + 1 to the same planet.
Knowing the information about travel times between the planets, and the times when Jack would not be able to use the stargate on particular planets, determine the minimum time in which he can get to the planet with index n.
Input
The first line contains two space-separated integers: n (2 ≤ n ≤ 105), the number of planets in the galaxy, and m (0 ≤ m ≤ 105) — the number of pairs of planets between which Jack can travel using stargates. Then m lines follow, containing three integers each: the i-th line contains numbers of planets ai and bi (1 ≤ ai, bi ≤ n, ai ≠ bi), which are connected through stargates, and the integer transfer time (in seconds) ci (1 ≤ ci ≤ 104) between these planets. It is guaranteed that between any pair of planets there is at most one stargate connection.
Then n lines follow: the i-th line contains an integer ki (0 ≤ ki ≤ 105) that denotes the number of moments of time when other travellers arrive to the planet with index i. Then ki distinct space-separated integers tij (0 ≤ tij < 109) follow, sorted in ascending order. An integer tij means that at time tij (in seconds) another traveller arrives to the planet i. It is guaranteed that the sum of all ki does not exceed 105.
Output
Print a single number — the least amount of time Jack needs to get from planet 1 to planet n. If Jack can't get to planet n in any amount of time, print number -1.
Examples
Input
4 6
1 2 2
1 3 3
1 4 8
2 3 4
2 4 5
3 4 3
0
1 3
2 3 4
0
Output
7
Input
3 1
1 2 3
0
1 3
0
Output
-1
Note
In the first sample Jack has three ways to go from planet 1. If he moves to planet 4 at once, he spends 8 seconds. If he transfers to planet 3, he spends 3 seconds, but as other travellers arrive to planet 3 at time 3 and 4, he can travel to planet 4 only at time 5, thus spending 8 seconds in total. But if Jack moves to planet 2, and then — to planet 4, then he spends a total of only 2 + 5 = 7 seconds.
In the second sample one can't get from planet 1 to planet 3 by moving through stargates. | instruction | 0 | 44,857 | 3 | 89,714 |
Tags: binary search, data structures, graphs, shortest paths
Correct Solution:
```
from heapq import *
n, m = map(int, input().split())
l = []
from copy import *
from bisect import *
from math import *
from sys import *
for _ in range(0, n + 2):
l.append([])
for i in range(0, m):
a, b, c = map(int, stdin.readline().split())
l[a].append((c, b))
l[b].append((c, a))
dist = [10000000000]*(n+3)
def helper(lst, val):
if lst[0] > val or lst[-1] < val:
return val
v = bisect_left(lst, val)
if lst[v] != val:
return val
else:
l = 1
h = len(lst) - v
# lst.append(232767324)
#tq=int(log(h,2))
z = 20000000000
cp=0
while l<h:
m = (l + h) // 2
if val + m == lst[v + m]:
l = m+1
else:
h, z = m, m
return (lst[len(lst)-1]+1-val if z==20000000000 else z) + val
def dij_modified(delay,t):
vis = [0] * (n + 3)
dist[1] = t
h = []
heappush(h, (t, 1))
heapify(h)
while h:
val = heappop(h)
if vis[val[1]] != 0:
continue
vis[val[1]] = 1
x = val[1]
if len(delay[x-1])>0 and x!=n:
dist[x]= helper(delay[x-1],dist[x])
for i in l[x]:
d = i[0]
e = i[1]
if dist[x] + d < dist[e]:
dist[e] = dist[x] + d
heappush(h, (dist[e], e))
delay =[]
for i in range(0,n):
tlst=map(int, stdin.readline().split())
x = next(tlst)
if(x):delay.append(list(tlst)[0:])
else: delay.append([-1])
x=delay[0]
t=0
dij_modified(delay,t)
if dist[n]<10000000000:
print (dist[n])
else:
print (-1)
``` | output | 1 | 44,857 | 3 | 89,715 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Goa'uld Apophis captured Jack O'Neill's team again! Jack himself was able to escape, but by that time Apophis's ship had already jumped to hyperspace. But Jack knows on what planet will Apophis land. In order to save his friends, Jack must repeatedly go through stargates to get to this planet.
Overall the galaxy has n planets, indexed with numbers from 1 to n. Jack is on the planet with index 1, and Apophis will land on the planet with index n. Jack can move between some pairs of planets through stargates (he can move in both directions); the transfer takes a positive, and, perhaps, for different pairs of planets unequal number of seconds. Jack begins his journey at time 0.
It can be that other travellers are arriving to the planet where Jack is currently located. In this case, Jack has to wait for exactly 1 second before he can use the stargate. That is, if at time t another traveller arrives to the planet, Jack can only pass through the stargate at time t + 1, unless there are more travellers arriving at time t + 1 to the same planet.
Knowing the information about travel times between the planets, and the times when Jack would not be able to use the stargate on particular planets, determine the minimum time in which he can get to the planet with index n.
Input
The first line contains two space-separated integers: n (2 ≤ n ≤ 105), the number of planets in the galaxy, and m (0 ≤ m ≤ 105) — the number of pairs of planets between which Jack can travel using stargates. Then m lines follow, containing three integers each: the i-th line contains numbers of planets ai and bi (1 ≤ ai, bi ≤ n, ai ≠ bi), which are connected through stargates, and the integer transfer time (in seconds) ci (1 ≤ ci ≤ 104) between these planets. It is guaranteed that between any pair of planets there is at most one stargate connection.
Then n lines follow: the i-th line contains an integer ki (0 ≤ ki ≤ 105) that denotes the number of moments of time when other travellers arrive to the planet with index i. Then ki distinct space-separated integers tij (0 ≤ tij < 109) follow, sorted in ascending order. An integer tij means that at time tij (in seconds) another traveller arrives to the planet i. It is guaranteed that the sum of all ki does not exceed 105.
Output
Print a single number — the least amount of time Jack needs to get from planet 1 to planet n. If Jack can't get to planet n in any amount of time, print number -1.
Examples
Input
4 6
1 2 2
1 3 3
1 4 8
2 3 4
2 4 5
3 4 3
0
1 3
2 3 4
0
Output
7
Input
3 1
1 2 3
0
1 3
0
Output
-1
Note
In the first sample Jack has three ways to go from planet 1. If he moves to planet 4 at once, he spends 8 seconds. If he transfers to planet 3, he spends 3 seconds, but as other travellers arrive to planet 3 at time 3 and 4, he can travel to planet 4 only at time 5, thus spending 8 seconds in total. But if Jack moves to planet 2, and then — to planet 4, then he spends a total of only 2 + 5 = 7 seconds.
In the second sample one can't get from planet 1 to planet 3 by moving through stargates.
Submitted Solution:
```
from heapq import *
n, m = map(int, input().split())
l = []
from copy import *
from bisect import *
from math import *
from sys import *
for _ in range(0, n + 2):
l.append([])
for i in range(0, m):
a, b, c = map(int, input().split())
l[a].append((c, b))
l[b].append((c, a))
dist = [10000000000]*(n+3)
def helper(lst, val):
if lst[0] > val or lst[-1] < val:
return val
v = bisect_left(lst, val)
if lst[v] != val:
return val
else:
l = 1
h = len(lst) - v
# lst.append(232767324)
#tq=int(log(h,2))
z = 20000000000
cp=0
while l<h:
m = (l + h) // 2
if val + m == lst[v + m]:
l = m+1
else:
h, z = m, m
return z + val
def dij_modified(delay,t):
vis = [0] * (n + 3)
dist[1] = t
h = []
heappush(h, (t, 1))
heapify(h)
while h:
val = heappop(h)
if vis[val[1]] != 0:
continue
vis[val[1]] = 1
x = val[1]
if len(delay[x-1])>0 and x!=n:
dist[x]= helper(delay[x-1],dist[x])
for i in l[x]:
d = i[0]
e = i[1]
if dist[x] + d < dist[e]:
dist[e] = dist[x] + d
heappush(h, (dist[e], e))
delay =[]
for i in range(0,n):
tlst=map(int, stdin.readline().split())
x = next(tlst)
if(x):delay.append(list(tlst)[0:])
else: delay.append([-1])
x=delay[0]
t=0
dij_modified(delay,t)
if dist[n]<10000000000:
print (dist[n])
else:
print (-1)
``` | instruction | 0 | 44,858 | 3 | 89,716 |
No | output | 1 | 44,858 | 3 | 89,717 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Goa'uld Apophis captured Jack O'Neill's team again! Jack himself was able to escape, but by that time Apophis's ship had already jumped to hyperspace. But Jack knows on what planet will Apophis land. In order to save his friends, Jack must repeatedly go through stargates to get to this planet.
Overall the galaxy has n planets, indexed with numbers from 1 to n. Jack is on the planet with index 1, and Apophis will land on the planet with index n. Jack can move between some pairs of planets through stargates (he can move in both directions); the transfer takes a positive, and, perhaps, for different pairs of planets unequal number of seconds. Jack begins his journey at time 0.
It can be that other travellers are arriving to the planet where Jack is currently located. In this case, Jack has to wait for exactly 1 second before he can use the stargate. That is, if at time t another traveller arrives to the planet, Jack can only pass through the stargate at time t + 1, unless there are more travellers arriving at time t + 1 to the same planet.
Knowing the information about travel times between the planets, and the times when Jack would not be able to use the stargate on particular planets, determine the minimum time in which he can get to the planet with index n.
Input
The first line contains two space-separated integers: n (2 ≤ n ≤ 105), the number of planets in the galaxy, and m (0 ≤ m ≤ 105) — the number of pairs of planets between which Jack can travel using stargates. Then m lines follow, containing three integers each: the i-th line contains numbers of planets ai and bi (1 ≤ ai, bi ≤ n, ai ≠ bi), which are connected through stargates, and the integer transfer time (in seconds) ci (1 ≤ ci ≤ 104) between these planets. It is guaranteed that between any pair of planets there is at most one stargate connection.
Then n lines follow: the i-th line contains an integer ki (0 ≤ ki ≤ 105) that denotes the number of moments of time when other travellers arrive to the planet with index i. Then ki distinct space-separated integers tij (0 ≤ tij < 109) follow, sorted in ascending order. An integer tij means that at time tij (in seconds) another traveller arrives to the planet i. It is guaranteed that the sum of all ki does not exceed 105.
Output
Print a single number — the least amount of time Jack needs to get from planet 1 to planet n. If Jack can't get to planet n in any amount of time, print number -1.
Examples
Input
4 6
1 2 2
1 3 3
1 4 8
2 3 4
2 4 5
3 4 3
0
1 3
2 3 4
0
Output
7
Input
3 1
1 2 3
0
1 3
0
Output
-1
Note
In the first sample Jack has three ways to go from planet 1. If he moves to planet 4 at once, he spends 8 seconds. If he transfers to planet 3, he spends 3 seconds, but as other travellers arrive to planet 3 at time 3 and 4, he can travel to planet 4 only at time 5, thus spending 8 seconds in total. But if Jack moves to planet 2, and then — to planet 4, then he spends a total of only 2 + 5 = 7 seconds.
In the second sample one can't get from planet 1 to planet 3 by moving through stargates.
Submitted Solution:
```
from heapq import *
n, m = map(int, input().split())
l = []
from copy import *
from bisect import *
from math import *
from sys import *
for _ in range(0, n + 2):
l.append([])
for i in range(0, m):
a, b, c = map(int, stdin.readline().split())
l[a].append((c, b))
l[b].append((c, a))
dist = [10000000000]*(n+3)
def helper(lst, val):
if lst[0] > val or lst[-1] < val:
return val
v = bisect_left(lst, val)
if lst[v] != val:
return val
else:
l = 1
h = len(lst) - v
# lst.append(232767324)
#tq=int(log(h,2))
z = lst[len(lst)-1]+1
cp=0
while l<h:
m = (l + h) // 2
if val + m == lst[v + m]:
l = m+1
else:
h, z = m, m
return z + val
def dij_modified(delay,t):
vis = [0] * (n + 3)
dist[1] = t
h = []
heappush(h, (t, 1))
heapify(h)
while h:
val = heappop(h)
if vis[val[1]] != 0:
continue
vis[val[1]] = 1
x = val[1]
if len(delay[x-1])>0 and x!=n:
dist[x]= helper(delay[x-1],dist[x])
for i in l[x]:
d = i[0]
e = i[1]
if dist[x] + d < dist[e]:
dist[e] = dist[x] + d
heappush(h, (dist[e], e))
delay =[]
for i in range(0,n):
tlst=map(int, stdin.readline().split())
x = next(tlst)
if(x):delay.append(list(tlst)[0:])
else: delay.append([-1])
x=delay[0]
t=0
dij_modified(delay,t)
if dist[n]<10000000000:
print (dist[n])
else:
print (-1)
``` | instruction | 0 | 44,859 | 3 | 89,718 |
No | output | 1 | 44,859 | 3 | 89,719 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Scott Lang is at war with Darren Cross. There are n chairs in a hall where they are, numbered with 1, 2, ..., n from left to right. The i-th chair is located at coordinate xi. Scott is on chair number s and Cross is on chair number e. Scott can jump to all other chairs (not only neighboring chairs). He wants to start at his position (chair number s), visit each chair exactly once and end up on chair number e with Cross.
As we all know, Scott can shrink or grow big (grow big only to his normal size), so at any moment of time he can be either small or large (normal). The thing is, he can only shrink or grow big while being on a chair (not in the air while jumping to another chair). Jumping takes time, but shrinking and growing big takes no time. Jumping from chair number i to chair number j takes |xi - xj| seconds. Also, jumping off a chair and landing on a chair takes extra amount of time.
If Scott wants to jump to a chair on his left, he can only be small, and if he wants to jump to a chair on his right he should be large.
Jumping off the i-th chair takes:
* ci extra seconds if he's small.
* di extra seconds otherwise (he's large).
Also, landing on i-th chair takes:
* bi extra seconds if he's small.
* ai extra seconds otherwise (he's large).
In simpler words, jumping from i-th chair to j-th chair takes exactly:
* |xi - xj| + ci + bj seconds if j < i.
* |xi - xj| + di + aj seconds otherwise (j > i).
Given values of x, a, b, c, d find the minimum time Scott can get to Cross, assuming he wants to visit each chair exactly once.
Input
The first line of the input contains three integers n, s and e (2 ≤ n ≤ 5000, 1 ≤ s, e ≤ n, s ≠ e) — the total number of chairs, starting and ending positions of Scott.
The second line contains n integers x1, x2, ..., xn (1 ≤ x1 < x2 < ... < xn ≤ 109).
The third line contains n integers a1, a2, ..., an (1 ≤ a1, a2, ..., an ≤ 109).
The fourth line contains n integers b1, b2, ..., bn (1 ≤ b1, b2, ..., bn ≤ 109).
The fifth line contains n integers c1, c2, ..., cn (1 ≤ c1, c2, ..., cn ≤ 109).
The sixth line contains n integers d1, d2, ..., dn (1 ≤ d1, d2, ..., dn ≤ 109).
Output
Print the minimum amount of time Scott needs to get to the Cross while visiting each chair exactly once.
Example
Input
7 4 3
8 11 12 16 17 18 20
17 16 20 2 20 5 13
17 8 8 16 12 15 13
12 4 16 4 15 7 6
8 14 2 11 17 12 8
Output
139
Note
In the sample testcase, an optimal solution would be <image>. Spent time would be 17 + 24 + 23 + 20 + 33 + 22 = 139.
Submitted Solution:
```
import sys
n = 0
s = 0
e = 0
x =[]
a =[]
b =[]
c =[]
d =[]
m = [[0] * 5005 for i in range(5006)]
v = [[0] * 5005 for i in range(5006)]
def main():
global n
global s
global e
global x
global a
global b
global c
global d
n,s,e = map(int,input().split())
s-=1
e-=1
x = list(map(int,input().split()))
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))
d = list(map(int,input().split()))
print(answer(0,0,0))
def answer(i,j,k):
global n
global s
global e
global x
global a
global b
global c
global d
global m
global v
if i == n:
if j==0 and k==0:
return 0
return sys.maxsize
if i and j==0 and k == 0:
return sys.maxsize
if v[i][j]:
return m[i][j]
v[i][j] = 1
m[i][j] = sys.maxsize
if i==s:
if j:
ret = min(m[i][j], answer(i+1,j-1,k) + x[i] + c[i])
ret = min(ret, answer(i+1,j,k+1) - x[i] + d[i])
m[i][j] = ret
return ret
if i==e:
if k:
ret = min(m[i][j], answer(i+1,j,k-1) + x[i] + a[i])
ret = min(ret, answer(i+1,j+1,k) - x[i] + b[i])
m[i][j] = ret
return ret
if k and j:
m[i][j] = min(m[i][j], answer(i + 1, j - 1, k - 1) + 2 * x[i] + a[i] + c[i]);
if(k):
m[i][j] = min(m[i][j], answer(i + 1, j, k) + a[i] + d[i]);
if(j):
m[i][j] = min(m[i][j], answer(i + 1, j, k) + b[i] + c[i]);
m[i][j] = min(m[i][j], answer(i + 1, j + 1, k + 1) - 2 * x[i] + b[i] + d[i]);
return m[i][j];
main()
``` | instruction | 0 | 45,011 | 3 | 90,022 |
No | output | 1 | 45,011 | 3 | 90,023 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Scott Lang is at war with Darren Cross. There are n chairs in a hall where they are, numbered with 1, 2, ..., n from left to right. The i-th chair is located at coordinate xi. Scott is on chair number s and Cross is on chair number e. Scott can jump to all other chairs (not only neighboring chairs). He wants to start at his position (chair number s), visit each chair exactly once and end up on chair number e with Cross.
As we all know, Scott can shrink or grow big (grow big only to his normal size), so at any moment of time he can be either small or large (normal). The thing is, he can only shrink or grow big while being on a chair (not in the air while jumping to another chair). Jumping takes time, but shrinking and growing big takes no time. Jumping from chair number i to chair number j takes |xi - xj| seconds. Also, jumping off a chair and landing on a chair takes extra amount of time.
If Scott wants to jump to a chair on his left, he can only be small, and if he wants to jump to a chair on his right he should be large.
Jumping off the i-th chair takes:
* ci extra seconds if he's small.
* di extra seconds otherwise (he's large).
Also, landing on i-th chair takes:
* bi extra seconds if he's small.
* ai extra seconds otherwise (he's large).
In simpler words, jumping from i-th chair to j-th chair takes exactly:
* |xi - xj| + ci + bj seconds if j < i.
* |xi - xj| + di + aj seconds otherwise (j > i).
Given values of x, a, b, c, d find the minimum time Scott can get to Cross, assuming he wants to visit each chair exactly once.
Input
The first line of the input contains three integers n, s and e (2 ≤ n ≤ 5000, 1 ≤ s, e ≤ n, s ≠ e) — the total number of chairs, starting and ending positions of Scott.
The second line contains n integers x1, x2, ..., xn (1 ≤ x1 < x2 < ... < xn ≤ 109).
The third line contains n integers a1, a2, ..., an (1 ≤ a1, a2, ..., an ≤ 109).
The fourth line contains n integers b1, b2, ..., bn (1 ≤ b1, b2, ..., bn ≤ 109).
The fifth line contains n integers c1, c2, ..., cn (1 ≤ c1, c2, ..., cn ≤ 109).
The sixth line contains n integers d1, d2, ..., dn (1 ≤ d1, d2, ..., dn ≤ 109).
Output
Print the minimum amount of time Scott needs to get to the Cross while visiting each chair exactly once.
Example
Input
7 4 3
8 11 12 16 17 18 20
17 16 20 2 20 5 13
17 8 8 16 12 15 13
12 4 16 4 15 7 6
8 14 2 11 17 12 8
Output
139
Note
In the sample testcase, an optimal solution would be <image>. Spent time would be 17 + 24 + 23 + 20 + 33 + 22 = 139.
Submitted Solution:
```
def add_to_dp(dp, comps, costs):
if comps in dp:
dp[comps] = min(dp[comps], costs)
else:
dp[comps] = costs
n, s, e = map(int, input().split())
s -= 1
e -= 1
# a = from left
# b = from right
# c = to left
# d = to right
x = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
d = list(map(int, input().split()))
# In dp[comps]: best costs for "comps" many components extensible on both ends in current prefix
dp = {0: 0}
prevpos = x[0]
s_seen = False
e_seen = False
for i, pos in enumerate(x):
new_dp = {}
if i == s:
for comps, costs in dp.items():
# to left
if comps:
add_to_dp(new_dp, comps-1, costs + (2*comps+s_seen+e_seen) * (pos-prevpos) + c[i])
# to right
add_to_dp(new_dp, comps, costs + (2*comps+s_seen+e_seen) * (pos-prevpos) + d[i])
s_seen = True
elif i == e:
for comps, costs in dp.items():
# from left
if comps:
add_to_dp(new_dp, comps-1, costs + (2*comps+s_seen+e_seen) * (pos-prevpos) + a[i])
# to right
add_to_dp(new_dp, comps, costs + (2*comps+s_seen+e_seen) * (pos-prevpos) + b[i])
e_seen = True
else:
for comps, costs in dp.items():
# from left, to left
if comps >= 2 or (s_seen and comps) or (e_seen and comps):
add_to_dp(new_dp, comps-1, costs + (2*comps+s_seen+e_seen) * (pos-prevpos) + a[i] + c[i])
if i == n-1 and comps == 0:
add_to_dp(new_dp, comps, costs + (2*comps+s_seen+e_seen) * (pos-prevpos) + a[i] + c[i])
# from left, to right
if s_seen or comps:
add_to_dp(new_dp, comps, costs + (2*comps+s_seen+e_seen) * (pos-prevpos) + a[i] + d[i])
# from right, to left
if e_seen or comps:
add_to_dp(new_dp, comps, costs + (2*comps+s_seen+e_seen) * (pos-prevpos) + b[i] + c[i])
# from right, to right
add_to_dp(new_dp, comps+1, costs + (2*comps+s_seen+e_seen) * (pos-prevpos) + b[i] + d[i])
prevpos = pos
dp = new_dp
print(dp[0])
``` | instruction | 0 | 45,012 | 3 | 90,024 |
No | output | 1 | 45,012 | 3 | 90,025 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Scott Lang is at war with Darren Cross. There are n chairs in a hall where they are, numbered with 1, 2, ..., n from left to right. The i-th chair is located at coordinate xi. Scott is on chair number s and Cross is on chair number e. Scott can jump to all other chairs (not only neighboring chairs). He wants to start at his position (chair number s), visit each chair exactly once and end up on chair number e with Cross.
As we all know, Scott can shrink or grow big (grow big only to his normal size), so at any moment of time he can be either small or large (normal). The thing is, he can only shrink or grow big while being on a chair (not in the air while jumping to another chair). Jumping takes time, but shrinking and growing big takes no time. Jumping from chair number i to chair number j takes |xi - xj| seconds. Also, jumping off a chair and landing on a chair takes extra amount of time.
If Scott wants to jump to a chair on his left, he can only be small, and if he wants to jump to a chair on his right he should be large.
Jumping off the i-th chair takes:
* ci extra seconds if he's small.
* di extra seconds otherwise (he's large).
Also, landing on i-th chair takes:
* bi extra seconds if he's small.
* ai extra seconds otherwise (he's large).
In simpler words, jumping from i-th chair to j-th chair takes exactly:
* |xi - xj| + ci + bj seconds if j < i.
* |xi - xj| + di + aj seconds otherwise (j > i).
Given values of x, a, b, c, d find the minimum time Scott can get to Cross, assuming he wants to visit each chair exactly once.
Input
The first line of the input contains three integers n, s and e (2 ≤ n ≤ 5000, 1 ≤ s, e ≤ n, s ≠ e) — the total number of chairs, starting and ending positions of Scott.
The second line contains n integers x1, x2, ..., xn (1 ≤ x1 < x2 < ... < xn ≤ 109).
The third line contains n integers a1, a2, ..., an (1 ≤ a1, a2, ..., an ≤ 109).
The fourth line contains n integers b1, b2, ..., bn (1 ≤ b1, b2, ..., bn ≤ 109).
The fifth line contains n integers c1, c2, ..., cn (1 ≤ c1, c2, ..., cn ≤ 109).
The sixth line contains n integers d1, d2, ..., dn (1 ≤ d1, d2, ..., dn ≤ 109).
Output
Print the minimum amount of time Scott needs to get to the Cross while visiting each chair exactly once.
Example
Input
7 4 3
8 11 12 16 17 18 20
17 16 20 2 20 5 13
17 8 8 16 12 15 13
12 4 16 4 15 7 6
8 14 2 11 17 12 8
Output
139
Note
In the sample testcase, an optimal solution would be <image>. Spent time would be 17 + 24 + 23 + 20 + 33 + 22 = 139.
Submitted Solution:
```
def add_to_dp(dp, comps, costs):
if comps in dp:
dp[comps] = min(dp[comps], costs)
else:
dp[comps] = costs
n, s, e = map(int, input().split())
s -= 1
e -= 1
# a = from left
# b = from right
# c = to left
# d = to right
x = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
d = list(map(int, input().split()))
# In dp[comps]: best costs for "comps" many components extensible on both ends in current prefix
dp = {0: 0}
prevpos = x[0]
s_seen = False
e_seen = False
for i, pos in enumerate(x):
new_dp = {}
if i == s:
for comps, costs in dp.items():
# to left
if comps:
add_to_dp(new_dp, comps-1, costs + (2*comps+s_seen+e_seen) * (pos-prevpos) + c[i])
if comps==0 and i==n-1:
add_to_dp(new_dp, comps, costs + (2*comps+s_seen+e_seen) * (pos-prevpos) + c[i])
# to right
if i < n-1:
add_to_dp(new_dp, comps, costs + (2*comps+s_seen+e_seen) * (pos-prevpos) + d[i])
s_seen = True
elif i == e:
for comps, costs in dp.items():
# from left
if comps:
add_to_dp(new_dp, comps-1, costs + (2*comps+s_seen+e_seen) * (pos-prevpos) + a[i])
if comps==0 and i==n-1:
add_to_dp(new_dp, comps, costs + (2*comps+s_seen+e_seen) * (pos-prevpos) + a[i])
# from right
if i < n-1:
add_to_dp(new_dp, comps, costs + (2*comps+s_seen+e_seen) * (pos-prevpos) + b[i])
e_seen = True
else:
for comps, costs in dp.items():
# from left, to left
if comps >= 2 or (s_seen and comps) or (e_seen and comps):
add_to_dp(new_dp, comps-1, costs + (2*comps+s_seen+e_seen) * (pos-prevpos) + a[i] + c[i])
if i == n-1 and comps == 0:
add_to_dp(new_dp, comps, costs + (2*comps+s_seen+e_seen) * (pos-prevpos) + a[i] + c[i])
if i < n-1:
# from left, to right
if s_seen or comps:
add_to_dp(new_dp, comps, costs + (2*comps+s_seen+e_seen) * (pos-prevpos) + a[i] + d[i])
# from right, to left
if e_seen or comps:
add_to_dp(new_dp, comps, costs + (2*comps+s_seen+e_seen) * (pos-prevpos) + b[i] + c[i])
# from right, to right
add_to_dp(new_dp, comps+1, costs + (2*comps+s_seen+e_seen) * (pos-prevpos) + b[i] + d[i])
prevpos = pos
dp = new_dp
print(dp[0])
``` | instruction | 0 | 45,013 | 3 | 90,026 |
No | output | 1 | 45,013 | 3 | 90,027 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Scott Lang is at war with Darren Cross. There are n chairs in a hall where they are, numbered with 1, 2, ..., n from left to right. The i-th chair is located at coordinate xi. Scott is on chair number s and Cross is on chair number e. Scott can jump to all other chairs (not only neighboring chairs). He wants to start at his position (chair number s), visit each chair exactly once and end up on chair number e with Cross.
As we all know, Scott can shrink or grow big (grow big only to his normal size), so at any moment of time he can be either small or large (normal). The thing is, he can only shrink or grow big while being on a chair (not in the air while jumping to another chair). Jumping takes time, but shrinking and growing big takes no time. Jumping from chair number i to chair number j takes |xi - xj| seconds. Also, jumping off a chair and landing on a chair takes extra amount of time.
If Scott wants to jump to a chair on his left, he can only be small, and if he wants to jump to a chair on his right he should be large.
Jumping off the i-th chair takes:
* ci extra seconds if he's small.
* di extra seconds otherwise (he's large).
Also, landing on i-th chair takes:
* bi extra seconds if he's small.
* ai extra seconds otherwise (he's large).
In simpler words, jumping from i-th chair to j-th chair takes exactly:
* |xi - xj| + ci + bj seconds if j < i.
* |xi - xj| + di + aj seconds otherwise (j > i).
Given values of x, a, b, c, d find the minimum time Scott can get to Cross, assuming he wants to visit each chair exactly once.
Input
The first line of the input contains three integers n, s and e (2 ≤ n ≤ 5000, 1 ≤ s, e ≤ n, s ≠ e) — the total number of chairs, starting and ending positions of Scott.
The second line contains n integers x1, x2, ..., xn (1 ≤ x1 < x2 < ... < xn ≤ 109).
The third line contains n integers a1, a2, ..., an (1 ≤ a1, a2, ..., an ≤ 109).
The fourth line contains n integers b1, b2, ..., bn (1 ≤ b1, b2, ..., bn ≤ 109).
The fifth line contains n integers c1, c2, ..., cn (1 ≤ c1, c2, ..., cn ≤ 109).
The sixth line contains n integers d1, d2, ..., dn (1 ≤ d1, d2, ..., dn ≤ 109).
Output
Print the minimum amount of time Scott needs to get to the Cross while visiting each chair exactly once.
Example
Input
7 4 3
8 11 12 16 17 18 20
17 16 20 2 20 5 13
17 8 8 16 12 15 13
12 4 16 4 15 7 6
8 14 2 11 17 12 8
Output
139
Note
In the sample testcase, an optimal solution would be <image>. Spent time would be 17 + 24 + 23 + 20 + 33 + 22 = 139.
Submitted Solution:
```
def add_to_dp(dp, comps, costs):
if comps in dp:
dp[comps] = min(dp[comps], costs)
else:
dp[comps] = costs
n, s, e = map(int, input().split())
s -= 1
e -= 1
# a = from left
# b = from right
# c = to left
# d = to right
x = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
d = list(map(int, input().split()))
# In dp[comps]: best costs for "comps" many components extensible on both ends in current prefix
dp = {0: 0}
prevpos = x[0]
s_seen = False
e_seen = False
for i, pos in enumerate(x):
new_dp = {}
if i == s:
for comps, costs in dp.items():
# to left
if comps:
add_to_dp(new_dp, comps-1, costs + (2*comps+s_seen+e_seen) * (pos-prevpos) + c[i])
if comps==0 and i==n-1:
add_to_dp(new_dp, comps, costs + (2*comps+s_seen+e_seen) * (pos-prevpos) + c[i])
# to right
add_to_dp(new_dp, comps, costs + (2*comps+s_seen+e_seen) * (pos-prevpos) + d[i])
s_seen = True
elif i == e:
for comps, costs in dp.items():
# from left
if comps:
add_to_dp(new_dp, comps-1, costs + (2*comps+s_seen+e_seen) * (pos-prevpos) + a[i])
if comps==0 and i==n-1:
add_to_dp(new_dp, comps, costs + (2*comps+s_seen+e_seen) * (pos-prevpos) + a[i])
# to right
add_to_dp(new_dp, comps, costs + (2*comps+s_seen+e_seen) * (pos-prevpos) + b[i])
e_seen = True
else:
for comps, costs in dp.items():
# from left, to left
if comps >= 2 or (s_seen and comps) or (e_seen and comps):
add_to_dp(new_dp, comps-1, costs + (2*comps+s_seen+e_seen) * (pos-prevpos) + a[i] + c[i])
if i == n-1 and comps == 0:
add_to_dp(new_dp, comps, costs + (2*comps+s_seen+e_seen) * (pos-prevpos) + a[i] + c[i])
# from left, to right
if s_seen or comps:
add_to_dp(new_dp, comps, costs + (2*comps+s_seen+e_seen) * (pos-prevpos) + a[i] + d[i])
# from right, to left
if e_seen or comps:
add_to_dp(new_dp, comps, costs + (2*comps+s_seen+e_seen) * (pos-prevpos) + b[i] + c[i])
# from right, to right
add_to_dp(new_dp, comps+1, costs + (2*comps+s_seen+e_seen) * (pos-prevpos) + b[i] + d[i])
prevpos = pos
dp = new_dp
print(dp[0])
``` | instruction | 0 | 45,014 | 3 | 90,028 |
No | output | 1 | 45,014 | 3 | 90,029 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You have n devices that you want to use simultaneously.
The i-th device uses ai units of power per second. This usage is continuous. That is, in λ seconds, the device will use λ·ai units of power. The i-th device currently has bi units of power stored. All devices can store an arbitrary amount of power.
You have a single charger that can plug to any single device. The charger will add p units of power per second to a device. This charging is continuous. That is, if you plug in a device for λ seconds, it will gain λ·p units of power. You can switch which device is charging at any arbitrary unit of time (including real numbers), and the time it takes to switch is negligible.
You are wondering, what is the maximum amount of time you can use the devices until one of them hits 0 units of power.
If you can use the devices indefinitely, print -1. Otherwise, print the maximum amount of time before any one device hits 0 power.
Input
The first line contains two integers, n and p (1 ≤ n ≤ 100 000, 1 ≤ p ≤ 109) — the number of devices and the power of the charger.
This is followed by n lines which contain two integers each. Line i contains the integers ai and bi (1 ≤ ai, bi ≤ 100 000) — the power of the device and the amount of power stored in the device in the beginning.
Output
If you can use the devices indefinitely, print -1. Otherwise, print the maximum amount of time before any one device hits 0 power.
Your answer will be considered correct if its absolute or relative error does not exceed 10 - 4.
Namely, let's assume that your answer is a and the answer of the jury is b. The checker program will consider your answer correct if <image>.
Examples
Input
2 1
2 2
2 1000
Output
2.0000000000
Input
1 100
1 1
Output
-1
Input
3 5
4 3
5 2
6 1
Output
0.5000000000
Note
In sample test 1, you can charge the first device for the entire time until it hits zero power. The second device has enough power to last this time without being charged.
In sample test 2, you can use the device indefinitely.
In sample test 3, we can charge the third device for 2 / 5 of a second, then switch to charge the second device for a 1 / 10 of a second. | instruction | 0 | 45,047 | 3 | 90,094 |
Tags: binary search, math
Correct Solution:
```
class SmartReader:
def __init__(self):
self.buf = iter([])
def read(self, *factories):
for factory in factories:
yield self._next(factory)
def _next(self, factory=str):
res = next(self.buf, None)
if res is None:
self.buf = iter(input().split())
return self._next(factory)
return factory(res)
reader = SmartReader()
n, power = reader.read(int, int)
devices = [tuple(reader.read(int, int)) for i in range(n)]
def can(time):
need = sum(max(0, use * time - have) for use, have in devices)
return need <= power * time
use = sum(use for use, _ in devices)
if use <= power:
print(-1)
else:
left = 0
right = 1
while can(right):
left = right
right *= 10
while right - left > 1:
mid = (left + right) // 2
if can(mid):
left = mid
else:
right = mid
for i in range(20):
mid = (left + right) / 2
if can(mid):
left = mid
else:
right = mid
print(left)
``` | output | 1 | 45,047 | 3 | 90,095 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You have n devices that you want to use simultaneously.
The i-th device uses ai units of power per second. This usage is continuous. That is, in λ seconds, the device will use λ·ai units of power. The i-th device currently has bi units of power stored. All devices can store an arbitrary amount of power.
You have a single charger that can plug to any single device. The charger will add p units of power per second to a device. This charging is continuous. That is, if you plug in a device for λ seconds, it will gain λ·p units of power. You can switch which device is charging at any arbitrary unit of time (including real numbers), and the time it takes to switch is negligible.
You are wondering, what is the maximum amount of time you can use the devices until one of them hits 0 units of power.
If you can use the devices indefinitely, print -1. Otherwise, print the maximum amount of time before any one device hits 0 power.
Input
The first line contains two integers, n and p (1 ≤ n ≤ 100 000, 1 ≤ p ≤ 109) — the number of devices and the power of the charger.
This is followed by n lines which contain two integers each. Line i contains the integers ai and bi (1 ≤ ai, bi ≤ 100 000) — the power of the device and the amount of power stored in the device in the beginning.
Output
If you can use the devices indefinitely, print -1. Otherwise, print the maximum amount of time before any one device hits 0 power.
Your answer will be considered correct if its absolute or relative error does not exceed 10 - 4.
Namely, let's assume that your answer is a and the answer of the jury is b. The checker program will consider your answer correct if <image>.
Examples
Input
2 1
2 2
2 1000
Output
2.0000000000
Input
1 100
1 1
Output
-1
Input
3 5
4 3
5 2
6 1
Output
0.5000000000
Note
In sample test 1, you can charge the first device for the entire time until it hits zero power. The second device has enough power to last this time without being charged.
In sample test 2, you can use the device indefinitely.
In sample test 3, we can charge the third device for 2 / 5 of a second, then switch to charge the second device for a 1 / 10 of a second. | instruction | 0 | 45,048 | 3 | 90,096 |
Tags: binary search, math
Correct Solution:
```
def f(N,P,A,B):
sa = sum(A) - P
if(sa<=0):
return -1
sb = sum(B)
AB = sorted([(A[i],B[i]) for i in range(N)], key = lambda x: -(x[1]/x[0]))
for a, b in AB:
if sa -a <= 0.0:
continue
if((sb-b)/(sa-a)) <= b/a:
sb -= b
sa -= a
return sb/sa
N, P = input().split(' ')
N = int(N); P = float(P)
A = []
B = []
for _ in range(N):
a, b = [float(x) for x in input().split(' ')]
A.append(a)
B.append(b)
print(f(N,P,A,B))
``` | output | 1 | 45,048 | 3 | 90,097 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You have n devices that you want to use simultaneously.
The i-th device uses ai units of power per second. This usage is continuous. That is, in λ seconds, the device will use λ·ai units of power. The i-th device currently has bi units of power stored. All devices can store an arbitrary amount of power.
You have a single charger that can plug to any single device. The charger will add p units of power per second to a device. This charging is continuous. That is, if you plug in a device for λ seconds, it will gain λ·p units of power. You can switch which device is charging at any arbitrary unit of time (including real numbers), and the time it takes to switch is negligible.
You are wondering, what is the maximum amount of time you can use the devices until one of them hits 0 units of power.
If you can use the devices indefinitely, print -1. Otherwise, print the maximum amount of time before any one device hits 0 power.
Input
The first line contains two integers, n and p (1 ≤ n ≤ 100 000, 1 ≤ p ≤ 109) — the number of devices and the power of the charger.
This is followed by n lines which contain two integers each. Line i contains the integers ai and bi (1 ≤ ai, bi ≤ 100 000) — the power of the device and the amount of power stored in the device in the beginning.
Output
If you can use the devices indefinitely, print -1. Otherwise, print the maximum amount of time before any one device hits 0 power.
Your answer will be considered correct if its absolute or relative error does not exceed 10 - 4.
Namely, let's assume that your answer is a and the answer of the jury is b. The checker program will consider your answer correct if <image>.
Examples
Input
2 1
2 2
2 1000
Output
2.0000000000
Input
1 100
1 1
Output
-1
Input
3 5
4 3
5 2
6 1
Output
0.5000000000
Note
In sample test 1, you can charge the first device for the entire time until it hits zero power. The second device has enough power to last this time without being charged.
In sample test 2, you can use the device indefinitely.
In sample test 3, we can charge the third device for 2 / 5 of a second, then switch to charge the second device for a 1 / 10 of a second. | instruction | 0 | 45,049 | 3 | 90,098 |
Tags: binary search, math
Correct Solution:
```
def check_infinite(N,P,A,B):
if sum(A) <= P:
return True
return False
def f(N,P,A,B):
if check_infinite(N,P,A,B) == True:
return -1
AB = [(i,A[i],B[i]) for i in range(N)]
AB.sort(key = lambda x: -(x[2]/x[1]))
Ord = [x[0] for x in AB]
sa = sum(A) - P
sb = sum(B)
for i in Ord:
if sa - A[i] <= 0.0:
continue
if ((sb - B[i]) / (sa - A[i])) <= B[i] / A[i]:
sb -= B[i]
sa -= A[i]
return sb / sa
N, P = input().split(' ')
N = int(N); P = float(P)
A = []
B = []
for _ in range(N):
a, b = [float(x) for x in input().split(' ')]
A.append(a)
B.append(b)
print(f(N,P,A,B))
``` | output | 1 | 45,049 | 3 | 90,099 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You have n devices that you want to use simultaneously.
The i-th device uses ai units of power per second. This usage is continuous. That is, in λ seconds, the device will use λ·ai units of power. The i-th device currently has bi units of power stored. All devices can store an arbitrary amount of power.
You have a single charger that can plug to any single device. The charger will add p units of power per second to a device. This charging is continuous. That is, if you plug in a device for λ seconds, it will gain λ·p units of power. You can switch which device is charging at any arbitrary unit of time (including real numbers), and the time it takes to switch is negligible.
You are wondering, what is the maximum amount of time you can use the devices until one of them hits 0 units of power.
If you can use the devices indefinitely, print -1. Otherwise, print the maximum amount of time before any one device hits 0 power.
Input
The first line contains two integers, n and p (1 ≤ n ≤ 100 000, 1 ≤ p ≤ 109) — the number of devices and the power of the charger.
This is followed by n lines which contain two integers each. Line i contains the integers ai and bi (1 ≤ ai, bi ≤ 100 000) — the power of the device and the amount of power stored in the device in the beginning.
Output
If you can use the devices indefinitely, print -1. Otherwise, print the maximum amount of time before any one device hits 0 power.
Your answer will be considered correct if its absolute or relative error does not exceed 10 - 4.
Namely, let's assume that your answer is a and the answer of the jury is b. The checker program will consider your answer correct if <image>.
Examples
Input
2 1
2 2
2 1000
Output
2.0000000000
Input
1 100
1 1
Output
-1
Input
3 5
4 3
5 2
6 1
Output
0.5000000000
Note
In sample test 1, you can charge the first device for the entire time until it hits zero power. The second device has enough power to last this time without being charged.
In sample test 2, you can use the device indefinitely.
In sample test 3, we can charge the third device for 2 / 5 of a second, then switch to charge the second device for a 1 / 10 of a second. | instruction | 0 | 45,050 | 3 | 90,100 |
Tags: binary search, math
Correct Solution:
```
f = lambda: map(int, input().split())
n, p = f()
s = [0] * n
x, y = -p, 0
for i in range(n):
a, b = f()
x += a
y += b
s[i] = (a, b)
s.sort(key=lambda q: q[0] / q[1])
for a, b in s:
if b * x > a * y:
x -= a
y -= b
print(y / x if x > 0 else -1)
``` | output | 1 | 45,050 | 3 | 90,101 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You have n devices that you want to use simultaneously.
The i-th device uses ai units of power per second. This usage is continuous. That is, in λ seconds, the device will use λ·ai units of power. The i-th device currently has bi units of power stored. All devices can store an arbitrary amount of power.
You have a single charger that can plug to any single device. The charger will add p units of power per second to a device. This charging is continuous. That is, if you plug in a device for λ seconds, it will gain λ·p units of power. You can switch which device is charging at any arbitrary unit of time (including real numbers), and the time it takes to switch is negligible.
You are wondering, what is the maximum amount of time you can use the devices until one of them hits 0 units of power.
If you can use the devices indefinitely, print -1. Otherwise, print the maximum amount of time before any one device hits 0 power.
Input
The first line contains two integers, n and p (1 ≤ n ≤ 100 000, 1 ≤ p ≤ 109) — the number of devices and the power of the charger.
This is followed by n lines which contain two integers each. Line i contains the integers ai and bi (1 ≤ ai, bi ≤ 100 000) — the power of the device and the amount of power stored in the device in the beginning.
Output
If you can use the devices indefinitely, print -1. Otherwise, print the maximum amount of time before any one device hits 0 power.
Your answer will be considered correct if its absolute or relative error does not exceed 10 - 4.
Namely, let's assume that your answer is a and the answer of the jury is b. The checker program will consider your answer correct if <image>.
Examples
Input
2 1
2 2
2 1000
Output
2.0000000000
Input
1 100
1 1
Output
-1
Input
3 5
4 3
5 2
6 1
Output
0.5000000000
Note
In sample test 1, you can charge the first device for the entire time until it hits zero power. The second device has enough power to last this time without being charged.
In sample test 2, you can use the device indefinitely.
In sample test 3, we can charge the third device for 2 / 5 of a second, then switch to charge the second device for a 1 / 10 of a second. | instruction | 0 | 45,051 | 3 | 90,102 |
Tags: binary search, math
Correct Solution:
```
from math import inf
n, p = [int(x) for x in input().split()]
l = []
for i in range(n):
a, b = [int(x) for x in input().split()]
l.append((a, b, b/a))
l.sort(key=lambda x: x[2])
asum = 0
bsum = 0
sumt = 0
for i in range(n):
a0, b0, _ = l[i]
c1 = inf if i == n-1 else l[i+1][2]
asum += a0
bsum += b0
dp = asum - p
if dp > 0:
t = bsum / dp
if t < c1:
print(t)
exit()
print(-1)
``` | output | 1 | 45,051 | 3 | 90,103 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You have n devices that you want to use simultaneously.
The i-th device uses ai units of power per second. This usage is continuous. That is, in λ seconds, the device will use λ·ai units of power. The i-th device currently has bi units of power stored. All devices can store an arbitrary amount of power.
You have a single charger that can plug to any single device. The charger will add p units of power per second to a device. This charging is continuous. That is, if you plug in a device for λ seconds, it will gain λ·p units of power. You can switch which device is charging at any arbitrary unit of time (including real numbers), and the time it takes to switch is negligible.
You are wondering, what is the maximum amount of time you can use the devices until one of them hits 0 units of power.
If you can use the devices indefinitely, print -1. Otherwise, print the maximum amount of time before any one device hits 0 power.
Input
The first line contains two integers, n and p (1 ≤ n ≤ 100 000, 1 ≤ p ≤ 109) — the number of devices and the power of the charger.
This is followed by n lines which contain two integers each. Line i contains the integers ai and bi (1 ≤ ai, bi ≤ 100 000) — the power of the device and the amount of power stored in the device in the beginning.
Output
If you can use the devices indefinitely, print -1. Otherwise, print the maximum amount of time before any one device hits 0 power.
Your answer will be considered correct if its absolute or relative error does not exceed 10 - 4.
Namely, let's assume that your answer is a and the answer of the jury is b. The checker program will consider your answer correct if <image>.
Examples
Input
2 1
2 2
2 1000
Output
2.0000000000
Input
1 100
1 1
Output
-1
Input
3 5
4 3
5 2
6 1
Output
0.5000000000
Note
In sample test 1, you can charge the first device for the entire time until it hits zero power. The second device has enough power to last this time without being charged.
In sample test 2, you can use the device indefinitely.
In sample test 3, we can charge the third device for 2 / 5 of a second, then switch to charge the second device for a 1 / 10 of a second. | instruction | 0 | 45,052 | 3 | 90,104 |
Tags: binary search, math
Correct Solution:
```
def check_infinite(N,P,A,B):
if sum(A) <= P:
return True
return False
def f(N,P,A,B):
if check_infinite(N,P,A,B) == True:
return -1
AB = [(i,A[i],B[i]) for i in range(N)]
AB.sort(key = lambda x: -(x[2]/x[1]))
Ord = [x[0] for x in AB]
sa = sum(A) - P
sb = sum(B)
for i, a, b in AB:
if sa -a <= 0.0:
continue
if((sb-b)/(sa-a)) <= b/a:
sb -= b
sa -= a
return sb/sa
N, P = input().split(' ')
N = int(N); P = float(P)
A = []
B = []
for _ in range(N):
a, b = [float(x) for x in input().split(' ')]
A.append(a)
B.append(b)
print(f(N,P,A,B))
``` | output | 1 | 45,052 | 3 | 90,105 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You have n devices that you want to use simultaneously.
The i-th device uses ai units of power per second. This usage is continuous. That is, in λ seconds, the device will use λ·ai units of power. The i-th device currently has bi units of power stored. All devices can store an arbitrary amount of power.
You have a single charger that can plug to any single device. The charger will add p units of power per second to a device. This charging is continuous. That is, if you plug in a device for λ seconds, it will gain λ·p units of power. You can switch which device is charging at any arbitrary unit of time (including real numbers), and the time it takes to switch is negligible.
You are wondering, what is the maximum amount of time you can use the devices until one of them hits 0 units of power.
If you can use the devices indefinitely, print -1. Otherwise, print the maximum amount of time before any one device hits 0 power.
Input
The first line contains two integers, n and p (1 ≤ n ≤ 100 000, 1 ≤ p ≤ 109) — the number of devices and the power of the charger.
This is followed by n lines which contain two integers each. Line i contains the integers ai and bi (1 ≤ ai, bi ≤ 100 000) — the power of the device and the amount of power stored in the device in the beginning.
Output
If you can use the devices indefinitely, print -1. Otherwise, print the maximum amount of time before any one device hits 0 power.
Your answer will be considered correct if its absolute or relative error does not exceed 10 - 4.
Namely, let's assume that your answer is a and the answer of the jury is b. The checker program will consider your answer correct if <image>.
Examples
Input
2 1
2 2
2 1000
Output
2.0000000000
Input
1 100
1 1
Output
-1
Input
3 5
4 3
5 2
6 1
Output
0.5000000000
Note
In sample test 1, you can charge the first device for the entire time until it hits zero power. The second device has enough power to last this time without being charged.
In sample test 2, you can use the device indefinitely.
In sample test 3, we can charge the third device for 2 / 5 of a second, then switch to charge the second device for a 1 / 10 of a second. | instruction | 0 | 45,053 | 3 | 90,106 |
Tags: binary search, math
Correct Solution:
```
import sys
input=sys.stdin.readline
n,p=map(int,input().split())
a=[0]*n
b=[0]*n
for i in range(n):
a[i],b[i]=map(int,input().split())
s=sum(a)
if s<=p:
print(-1)
exit()
t=[b[i]/a[i] for i in range(n)]
INF=10**10+1
l=0
r=INF
while r-l>10**(-5):
x=l+(r-l)/2
use=0
for i in range(n):
use+=max(x*a[i]-b[i],0)
if use/x<=p:
l=x
else:
r=x
print(l)
``` | output | 1 | 45,053 | 3 | 90,107 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You have n devices that you want to use simultaneously.
The i-th device uses ai units of power per second. This usage is continuous. That is, in λ seconds, the device will use λ·ai units of power. The i-th device currently has bi units of power stored. All devices can store an arbitrary amount of power.
You have a single charger that can plug to any single device. The charger will add p units of power per second to a device. This charging is continuous. That is, if you plug in a device for λ seconds, it will gain λ·p units of power. You can switch which device is charging at any arbitrary unit of time (including real numbers), and the time it takes to switch is negligible.
You are wondering, what is the maximum amount of time you can use the devices until one of them hits 0 units of power.
If you can use the devices indefinitely, print -1. Otherwise, print the maximum amount of time before any one device hits 0 power.
Input
The first line contains two integers, n and p (1 ≤ n ≤ 100 000, 1 ≤ p ≤ 109) — the number of devices and the power of the charger.
This is followed by n lines which contain two integers each. Line i contains the integers ai and bi (1 ≤ ai, bi ≤ 100 000) — the power of the device and the amount of power stored in the device in the beginning.
Output
If you can use the devices indefinitely, print -1. Otherwise, print the maximum amount of time before any one device hits 0 power.
Your answer will be considered correct if its absolute or relative error does not exceed 10 - 4.
Namely, let's assume that your answer is a and the answer of the jury is b. The checker program will consider your answer correct if <image>.
Examples
Input
2 1
2 2
2 1000
Output
2.0000000000
Input
1 100
1 1
Output
-1
Input
3 5
4 3
5 2
6 1
Output
0.5000000000
Note
In sample test 1, you can charge the first device for the entire time until it hits zero power. The second device has enough power to last this time without being charged.
In sample test 2, you can use the device indefinitely.
In sample test 3, we can charge the third device for 2 / 5 of a second, then switch to charge the second device for a 1 / 10 of a second. | instruction | 0 | 45,054 | 3 | 90,108 |
Tags: binary search, math
Correct Solution:
```
from sys import stdin, stdout
n,p = map(int, stdin.readline().rstrip().split())
powerData = []
powerList = []
for i in range(n):
a,b = map(int, stdin.readline().rstrip().split())
deathTime = b/a
powerData.append((a,b,deathTime))
powerList.append(a)
powerData.sort(key = lambda x: x[2])
if sum(powerList)<=p:
print(-1)
else:
i=0
combinedPower=0
startingPower=0
while combinedPower<=p:
combinedPower+=powerData[i][0]
startingPower+=powerData[i][1]
i+=1
finished=False
deathTime = startingPower/(combinedPower-p)
while i<n and deathTime>powerData[i][2]:
combinedPower+=powerData[i][0]
startingPower+=powerData[i][1]
deathTime = startingPower/(combinedPower-p)
i+=1
print(deathTime)
``` | output | 1 | 45,054 | 3 | 90,109 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You have n devices that you want to use simultaneously.
The i-th device uses ai units of power per second. This usage is continuous. That is, in λ seconds, the device will use λ·ai units of power. The i-th device currently has bi units of power stored. All devices can store an arbitrary amount of power.
You have a single charger that can plug to any single device. The charger will add p units of power per second to a device. This charging is continuous. That is, if you plug in a device for λ seconds, it will gain λ·p units of power. You can switch which device is charging at any arbitrary unit of time (including real numbers), and the time it takes to switch is negligible.
You are wondering, what is the maximum amount of time you can use the devices until one of them hits 0 units of power.
If you can use the devices indefinitely, print -1. Otherwise, print the maximum amount of time before any one device hits 0 power.
Input
The first line contains two integers, n and p (1 ≤ n ≤ 100 000, 1 ≤ p ≤ 109) — the number of devices and the power of the charger.
This is followed by n lines which contain two integers each. Line i contains the integers ai and bi (1 ≤ ai, bi ≤ 100 000) — the power of the device and the amount of power stored in the device in the beginning.
Output
If you can use the devices indefinitely, print -1. Otherwise, print the maximum amount of time before any one device hits 0 power.
Your answer will be considered correct if its absolute or relative error does not exceed 10 - 4.
Namely, let's assume that your answer is a and the answer of the jury is b. The checker program will consider your answer correct if <image>.
Examples
Input
2 1
2 2
2 1000
Output
2.0000000000
Input
1 100
1 1
Output
-1
Input
3 5
4 3
5 2
6 1
Output
0.5000000000
Note
In sample test 1, you can charge the first device for the entire time until it hits zero power. The second device has enough power to last this time without being charged.
In sample test 2, you can use the device indefinitely.
In sample test 3, we can charge the third device for 2 / 5 of a second, then switch to charge the second device for a 1 / 10 of a second.
Submitted Solution:
```
from math import fsum
n, power = map(int, input().split())
devices = [tuple(map(int, input().split())) for i in range(n)]
def can(time):
need = fsum(max(0, use * time - have) for use, have in devices)
return need <= power * time
use = sum(use for use, _ in devices)
if use <= power:
print(-1)
else:
left = 0
right = 1
while can(right):
left = right
right *= 10
for i in range(20):
mid = (left + right) / 2
if can(mid):
left = mid
else:
right = mid
print(left)
``` | instruction | 0 | 45,055 | 3 | 90,110 |
Yes | output | 1 | 45,055 | 3 | 90,111 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You have n devices that you want to use simultaneously.
The i-th device uses ai units of power per second. This usage is continuous. That is, in λ seconds, the device will use λ·ai units of power. The i-th device currently has bi units of power stored. All devices can store an arbitrary amount of power.
You have a single charger that can plug to any single device. The charger will add p units of power per second to a device. This charging is continuous. That is, if you plug in a device for λ seconds, it will gain λ·p units of power. You can switch which device is charging at any arbitrary unit of time (including real numbers), and the time it takes to switch is negligible.
You are wondering, what is the maximum amount of time you can use the devices until one of them hits 0 units of power.
If you can use the devices indefinitely, print -1. Otherwise, print the maximum amount of time before any one device hits 0 power.
Input
The first line contains two integers, n and p (1 ≤ n ≤ 100 000, 1 ≤ p ≤ 109) — the number of devices and the power of the charger.
This is followed by n lines which contain two integers each. Line i contains the integers ai and bi (1 ≤ ai, bi ≤ 100 000) — the power of the device and the amount of power stored in the device in the beginning.
Output
If you can use the devices indefinitely, print -1. Otherwise, print the maximum amount of time before any one device hits 0 power.
Your answer will be considered correct if its absolute or relative error does not exceed 10 - 4.
Namely, let's assume that your answer is a and the answer of the jury is b. The checker program will consider your answer correct if <image>.
Examples
Input
2 1
2 2
2 1000
Output
2.0000000000
Input
1 100
1 1
Output
-1
Input
3 5
4 3
5 2
6 1
Output
0.5000000000
Note
In sample test 1, you can charge the first device for the entire time until it hits zero power. The second device has enough power to last this time without being charged.
In sample test 2, you can use the device indefinitely.
In sample test 3, we can charge the third device for 2 / 5 of a second, then switch to charge the second device for a 1 / 10 of a second.
Submitted Solution:
```
def f(N,P,A,B):
sa = sum(A) - P
sb = sum(B)
if(sa<=0):
return -1
AB = sorted([(A[i],B[i]) for i in range(N)], key = lambda x: -(x[1]/x[0]))
sa = sum(A) - P
sb = sum(B)
for a, b in AB:
if sa -a <= 0.0:
continue
if((sb-b)/(sa-a)) <= b/a:
sb -= b
sa -= a
return sb/sa
N, P = input().split(' ')
N = int(N); P = float(P)
A = []
B = []
for _ in range(N):
a, b = [float(x) for x in input().split(' ')]
A.append(a)
B.append(b)
print(f(N,P,A,B))
``` | instruction | 0 | 45,056 | 3 | 90,112 |
Yes | output | 1 | 45,056 | 3 | 90,113 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You have n devices that you want to use simultaneously.
The i-th device uses ai units of power per second. This usage is continuous. That is, in λ seconds, the device will use λ·ai units of power. The i-th device currently has bi units of power stored. All devices can store an arbitrary amount of power.
You have a single charger that can plug to any single device. The charger will add p units of power per second to a device. This charging is continuous. That is, if you plug in a device for λ seconds, it will gain λ·p units of power. You can switch which device is charging at any arbitrary unit of time (including real numbers), and the time it takes to switch is negligible.
You are wondering, what is the maximum amount of time you can use the devices until one of them hits 0 units of power.
If you can use the devices indefinitely, print -1. Otherwise, print the maximum amount of time before any one device hits 0 power.
Input
The first line contains two integers, n and p (1 ≤ n ≤ 100 000, 1 ≤ p ≤ 109) — the number of devices and the power of the charger.
This is followed by n lines which contain two integers each. Line i contains the integers ai and bi (1 ≤ ai, bi ≤ 100 000) — the power of the device and the amount of power stored in the device in the beginning.
Output
If you can use the devices indefinitely, print -1. Otherwise, print the maximum amount of time before any one device hits 0 power.
Your answer will be considered correct if its absolute or relative error does not exceed 10 - 4.
Namely, let's assume that your answer is a and the answer of the jury is b. The checker program will consider your answer correct if <image>.
Examples
Input
2 1
2 2
2 1000
Output
2.0000000000
Input
1 100
1 1
Output
-1
Input
3 5
4 3
5 2
6 1
Output
0.5000000000
Note
In sample test 1, you can charge the first device for the entire time until it hits zero power. The second device has enough power to last this time without being charged.
In sample test 2, you can use the device indefinitely.
In sample test 3, we can charge the third device for 2 / 5 of a second, then switch to charge the second device for a 1 / 10 of a second.
Submitted Solution:
```
def check(t):
global a, b, p, n
x = 0
for i in range(n):
x += max(0, t * a[i] - b[i])
return x / t <= p
n, p = map(int, input().split())
p = float(p)
a, b = [0 for i in range(n)], [0 for i in range(n)]
s = 0
for i in range(n):
a[i], b[i] = map(float, input().split())
s += a[i]
if s <= p:
print(-1)
else:
l = 0
r = 10 ** 10 + 1
j = 0
while r - l > 10 ** -4:
m = (l + r) / 2
if check(m):
l = m
else:
r = m
j += 1
print(l)
``` | instruction | 0 | 45,057 | 3 | 90,114 |
Yes | output | 1 | 45,057 | 3 | 90,115 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You have n devices that you want to use simultaneously.
The i-th device uses ai units of power per second. This usage is continuous. That is, in λ seconds, the device will use λ·ai units of power. The i-th device currently has bi units of power stored. All devices can store an arbitrary amount of power.
You have a single charger that can plug to any single device. The charger will add p units of power per second to a device. This charging is continuous. That is, if you plug in a device for λ seconds, it will gain λ·p units of power. You can switch which device is charging at any arbitrary unit of time (including real numbers), and the time it takes to switch is negligible.
You are wondering, what is the maximum amount of time you can use the devices until one of them hits 0 units of power.
If you can use the devices indefinitely, print -1. Otherwise, print the maximum amount of time before any one device hits 0 power.
Input
The first line contains two integers, n and p (1 ≤ n ≤ 100 000, 1 ≤ p ≤ 109) — the number of devices and the power of the charger.
This is followed by n lines which contain two integers each. Line i contains the integers ai and bi (1 ≤ ai, bi ≤ 100 000) — the power of the device and the amount of power stored in the device in the beginning.
Output
If you can use the devices indefinitely, print -1. Otherwise, print the maximum amount of time before any one device hits 0 power.
Your answer will be considered correct if its absolute or relative error does not exceed 10 - 4.
Namely, let's assume that your answer is a and the answer of the jury is b. The checker program will consider your answer correct if <image>.
Examples
Input
2 1
2 2
2 1000
Output
2.0000000000
Input
1 100
1 1
Output
-1
Input
3 5
4 3
5 2
6 1
Output
0.5000000000
Note
In sample test 1, you can charge the first device for the entire time until it hits zero power. The second device has enough power to last this time without being charged.
In sample test 2, you can use the device indefinitely.
In sample test 3, we can charge the third device for 2 / 5 of a second, then switch to charge the second device for a 1 / 10 of a second.
Submitted Solution:
```
n, power = map(int, input().split())
devices = [tuple(map(int, input().split())) for i in range(n)]
def can(time):
need = sum(max(0, use * time - have) for use, have in devices)
return need <= power * time
use = sum(use for use, _ in devices)
if use <= power:
print(-1)
else:
left = 0
right = 1
while can(right):
left = right
right *= 10
while right - left > 1:
mid = (left + right) // 2
if can(mid):
left = mid
else:
right = mid
for i in range(20):
mid = (left + right) / 2
if can(mid):
left = mid
else:
right = mid
print(left)
``` | instruction | 0 | 45,058 | 3 | 90,116 |
Yes | output | 1 | 45,058 | 3 | 90,117 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You have n devices that you want to use simultaneously.
The i-th device uses ai units of power per second. This usage is continuous. That is, in λ seconds, the device will use λ·ai units of power. The i-th device currently has bi units of power stored. All devices can store an arbitrary amount of power.
You have a single charger that can plug to any single device. The charger will add p units of power per second to a device. This charging is continuous. That is, if you plug in a device for λ seconds, it will gain λ·p units of power. You can switch which device is charging at any arbitrary unit of time (including real numbers), and the time it takes to switch is negligible.
You are wondering, what is the maximum amount of time you can use the devices until one of them hits 0 units of power.
If you can use the devices indefinitely, print -1. Otherwise, print the maximum amount of time before any one device hits 0 power.
Input
The first line contains two integers, n and p (1 ≤ n ≤ 100 000, 1 ≤ p ≤ 109) — the number of devices and the power of the charger.
This is followed by n lines which contain two integers each. Line i contains the integers ai and bi (1 ≤ ai, bi ≤ 100 000) — the power of the device and the amount of power stored in the device in the beginning.
Output
If you can use the devices indefinitely, print -1. Otherwise, print the maximum amount of time before any one device hits 0 power.
Your answer will be considered correct if its absolute or relative error does not exceed 10 - 4.
Namely, let's assume that your answer is a and the answer of the jury is b. The checker program will consider your answer correct if <image>.
Examples
Input
2 1
2 2
2 1000
Output
2.0000000000
Input
1 100
1 1
Output
-1
Input
3 5
4 3
5 2
6 1
Output
0.5000000000
Note
In sample test 1, you can charge the first device for the entire time until it hits zero power. The second device has enough power to last this time without being charged.
In sample test 2, you can use the device indefinitely.
In sample test 3, we can charge the third device for 2 / 5 of a second, then switch to charge the second device for a 1 / 10 of a second.
Submitted Solution:
```
import math as mt
import sys,string,bisect
input=sys.stdin.readline
import random
from collections import deque,defaultdict
L=lambda : list(map(int,input().split()))
Ls=lambda : list(input().split())
M=lambda : map(int,input().split())
I=lambda :int(input())
d=defaultdict(int)
n,p=M()
la=[]
s=0
for _ in range(n):
a,b=M()
la.append((a,b))
s+=a
if(p>=s):
print(-1)
else:
l=0
h=10**20
mid=0
while(l+0.00001<h):
mid=(l+h)/2
w=0
for i in range(n):
q=max(0,mid*la[i][0]-la[i][1])
w+=q/mid
if(w<p):
l=mid
else:
h=mid
print(mid)
``` | instruction | 0 | 45,059 | 3 | 90,118 |
No | output | 1 | 45,059 | 3 | 90,119 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You have n devices that you want to use simultaneously.
The i-th device uses ai units of power per second. This usage is continuous. That is, in λ seconds, the device will use λ·ai units of power. The i-th device currently has bi units of power stored. All devices can store an arbitrary amount of power.
You have a single charger that can plug to any single device. The charger will add p units of power per second to a device. This charging is continuous. That is, if you plug in a device for λ seconds, it will gain λ·p units of power. You can switch which device is charging at any arbitrary unit of time (including real numbers), and the time it takes to switch is negligible.
You are wondering, what is the maximum amount of time you can use the devices until one of them hits 0 units of power.
If you can use the devices indefinitely, print -1. Otherwise, print the maximum amount of time before any one device hits 0 power.
Input
The first line contains two integers, n and p (1 ≤ n ≤ 100 000, 1 ≤ p ≤ 109) — the number of devices and the power of the charger.
This is followed by n lines which contain two integers each. Line i contains the integers ai and bi (1 ≤ ai, bi ≤ 100 000) — the power of the device and the amount of power stored in the device in the beginning.
Output
If you can use the devices indefinitely, print -1. Otherwise, print the maximum amount of time before any one device hits 0 power.
Your answer will be considered correct if its absolute or relative error does not exceed 10 - 4.
Namely, let's assume that your answer is a and the answer of the jury is b. The checker program will consider your answer correct if <image>.
Examples
Input
2 1
2 2
2 1000
Output
2.0000000000
Input
1 100
1 1
Output
-1
Input
3 5
4 3
5 2
6 1
Output
0.5000000000
Note
In sample test 1, you can charge the first device for the entire time until it hits zero power. The second device has enough power to last this time without being charged.
In sample test 2, you can use the device indefinitely.
In sample test 3, we can charge the third device for 2 / 5 of a second, then switch to charge the second device for a 1 / 10 of a second.
Submitted Solution:
```
n, power = map(int, input().split())
devices = [tuple(map(int, input().split())) for i in range(n)]
def can(time):
need = sum(max(0, use * time - have) for use, have in devices)
return need <= power * time
use = sum(use for use, _ in devices)
if use <= power:
print(-1)
else:
left = 0
right = 1
while can(right):
left = right
right *= 100
for i in range(25):
mid = (left + right) / 2
if can(mid):
left = mid
else:
right = mid
print(left)
``` | instruction | 0 | 45,060 | 3 | 90,120 |
No | output | 1 | 45,060 | 3 | 90,121 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.