message stringlengths 2 22.8k | message_type stringclasses 2 values | message_id int64 0 1 | conversation_id int64 16 109k | cluster float64 1 1 | __index_level_0__ int64 32 217k |
|---|---|---|---|---|---|
Provide tags and a correct Python 3 solution for this coding contest problem.
Bearland has n cities, numbered 1 through n. Cities are connected via bidirectional roads. Each road connects two distinct cities. No two roads connect the same pair of cities.
Bear Limak was once in a city a and he wanted to go to a city b. There was no direct connection so he decided to take a long walk, visiting each city exactly once. Formally:
* There is no road between a and b.
* There exists a sequence (path) of n distinct cities v1, v2, ..., vn that v1 = a, vn = b and there is a road between vi and vi + 1 for <image>.
On the other day, the similar thing happened. Limak wanted to travel between a city c and a city d. There is no road between them but there exists a sequence of n distinct cities u1, u2, ..., un that u1 = c, un = d and there is a road between ui and ui + 1 for <image>.
Also, Limak thinks that there are at most k roads in Bearland. He wonders whether he remembers everything correctly.
Given n, k and four distinct cities a, b, c, d, can you find possible paths (v1, ..., vn) and (u1, ..., un) to satisfy all the given conditions? Find any solution or print -1 if it's impossible.
Input
The first line of the input contains two integers n and k (4 ≤ n ≤ 1000, n - 1 ≤ k ≤ 2n - 2) — the number of cities and the maximum allowed number of roads, respectively.
The second line contains four distinct integers a, b, c and d (1 ≤ a, b, c, d ≤ n).
Output
Print -1 if it's impossible to satisfy all the given conditions. Otherwise, print two lines with paths descriptions. The first of these two lines should contain n distinct integers v1, v2, ..., vn where v1 = a and vn = b. The second line should contain n distinct integers u1, u2, ..., un where u1 = c and un = d.
Two paths generate at most 2n - 2 roads: (v1, v2), (v2, v3), ..., (vn - 1, vn), (u1, u2), (u2, u3), ..., (un - 1, un). Your answer will be considered wrong if contains more than k distinct roads or any other condition breaks. Note that (x, y) and (y, x) are the same road.
Examples
Input
7 11
2 4 7 3
Output
2 7 1 3 6 5 4
7 1 5 4 6 2 3
Input
1000 999
10 20 30 40
Output
-1
Note
In the first sample test, there should be 7 cities and at most 11 roads. The provided sample solution generates 10 roads, as in the drawing. You can also see a simple path of length n between 2 and 4, and a path between 7 and 3.
<image> | instruction | 0 | 57,608 | 1 | 115,216 |
Tags: constructive algorithms, graphs
Correct Solution:
```
n, k = map(int, input().split())
a,b,c,d = map(int, input().split())
#from random import shuffle
ok = 0
L = [i+1 for i in range(n)]
D = [a,b,c,d]
D.sort(reverse=True)
for i in range(4):
del(L[D[i]-1])
if n == 4 or n >= k:
print(-1)
else:
print(str(a)+" "+str(c),end=" ")
for i in range(n-4):
print(L[i],end=" ")
print(str(d)+" "+str(b))
print(str(c)+" "+str(a),end=" ")
for i in range(n-4):
print(L[i],end=" ")
print(str(b)+" "+str(d))
``` | output | 1 | 57,608 | 1 | 115,217 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Bearland has n cities, numbered 1 through n. Cities are connected via bidirectional roads. Each road connects two distinct cities. No two roads connect the same pair of cities.
Bear Limak was once in a city a and he wanted to go to a city b. There was no direct connection so he decided to take a long walk, visiting each city exactly once. Formally:
* There is no road between a and b.
* There exists a sequence (path) of n distinct cities v1, v2, ..., vn that v1 = a, vn = b and there is a road between vi and vi + 1 for <image>.
On the other day, the similar thing happened. Limak wanted to travel between a city c and a city d. There is no road between them but there exists a sequence of n distinct cities u1, u2, ..., un that u1 = c, un = d and there is a road between ui and ui + 1 for <image>.
Also, Limak thinks that there are at most k roads in Bearland. He wonders whether he remembers everything correctly.
Given n, k and four distinct cities a, b, c, d, can you find possible paths (v1, ..., vn) and (u1, ..., un) to satisfy all the given conditions? Find any solution or print -1 if it's impossible.
Input
The first line of the input contains two integers n and k (4 ≤ n ≤ 1000, n - 1 ≤ k ≤ 2n - 2) — the number of cities and the maximum allowed number of roads, respectively.
The second line contains four distinct integers a, b, c and d (1 ≤ a, b, c, d ≤ n).
Output
Print -1 if it's impossible to satisfy all the given conditions. Otherwise, print two lines with paths descriptions. The first of these two lines should contain n distinct integers v1, v2, ..., vn where v1 = a and vn = b. The second line should contain n distinct integers u1, u2, ..., un where u1 = c and un = d.
Two paths generate at most 2n - 2 roads: (v1, v2), (v2, v3), ..., (vn - 1, vn), (u1, u2), (u2, u3), ..., (un - 1, un). Your answer will be considered wrong if contains more than k distinct roads or any other condition breaks. Note that (x, y) and (y, x) are the same road.
Examples
Input
7 11
2 4 7 3
Output
2 7 1 3 6 5 4
7 1 5 4 6 2 3
Input
1000 999
10 20 30 40
Output
-1
Note
In the first sample test, there should be 7 cities and at most 11 roads. The provided sample solution generates 10 roads, as in the drawing. You can also see a simple path of length n between 2 and 4, and a path between 7 and 3.
<image> | instruction | 0 | 57,609 | 1 | 115,218 |
Tags: constructive algorithms, graphs
Correct Solution:
```
import sys
n, k = map(int, input().split())
a, b, c, d = map(int, input().split())
if(k<n+1 or n==4):
print(-1)
sys.exit()
ans = [a, c]
l = [i for i in range(1, n+1) if (i!=a and i!=b and i!=c and i!=d)]
for i in l:
ans.append(i)
ans.extend([d, b])
for i in ans:
print(i, end=' ')
print()
ans[0], ans[1] = ans[1], ans[0]
ans[n-2], ans[n-1] = ans[n-1], ans[n-2]
for i in ans:
print(i, end=' ')
print('\n')
``` | output | 1 | 57,609 | 1 | 115,219 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Bearland has n cities, numbered 1 through n. Cities are connected via bidirectional roads. Each road connects two distinct cities. No two roads connect the same pair of cities.
Bear Limak was once in a city a and he wanted to go to a city b. There was no direct connection so he decided to take a long walk, visiting each city exactly once. Formally:
* There is no road between a and b.
* There exists a sequence (path) of n distinct cities v1, v2, ..., vn that v1 = a, vn = b and there is a road between vi and vi + 1 for <image>.
On the other day, the similar thing happened. Limak wanted to travel between a city c and a city d. There is no road between them but there exists a sequence of n distinct cities u1, u2, ..., un that u1 = c, un = d and there is a road between ui and ui + 1 for <image>.
Also, Limak thinks that there are at most k roads in Bearland. He wonders whether he remembers everything correctly.
Given n, k and four distinct cities a, b, c, d, can you find possible paths (v1, ..., vn) and (u1, ..., un) to satisfy all the given conditions? Find any solution or print -1 if it's impossible.
Input
The first line of the input contains two integers n and k (4 ≤ n ≤ 1000, n - 1 ≤ k ≤ 2n - 2) — the number of cities and the maximum allowed number of roads, respectively.
The second line contains four distinct integers a, b, c and d (1 ≤ a, b, c, d ≤ n).
Output
Print -1 if it's impossible to satisfy all the given conditions. Otherwise, print two lines with paths descriptions. The first of these two lines should contain n distinct integers v1, v2, ..., vn where v1 = a and vn = b. The second line should contain n distinct integers u1, u2, ..., un where u1 = c and un = d.
Two paths generate at most 2n - 2 roads: (v1, v2), (v2, v3), ..., (vn - 1, vn), (u1, u2), (u2, u3), ..., (un - 1, un). Your answer will be considered wrong if contains more than k distinct roads or any other condition breaks. Note that (x, y) and (y, x) are the same road.
Examples
Input
7 11
2 4 7 3
Output
2 7 1 3 6 5 4
7 1 5 4 6 2 3
Input
1000 999
10 20 30 40
Output
-1
Note
In the first sample test, there should be 7 cities and at most 11 roads. The provided sample solution generates 10 roads, as in the drawing. You can also see a simple path of length n between 2 and 4, and a path between 7 and 3.
<image> | instruction | 0 | 57,610 | 1 | 115,220 |
Tags: constructive algorithms, graphs
Correct Solution:
```
def main():
n, k = [int(i) for i in input().strip().split()]
a, b, c, d = [int(i) for i in input().strip().split()]
if k <= n or n <= 4:
print(-1)
return
s = [a, b, c, d]
others = [i for i in range(1, n + 1) if i not in s]
print(" ".join(map(str, [a, c] + others + [d, b])))
print(" ".join(map(str, [c, a] + others + [b, d])))
if __name__ == "__main__":
main()
``` | output | 1 | 57,610 | 1 | 115,221 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Bearland has n cities, numbered 1 through n. Cities are connected via bidirectional roads. Each road connects two distinct cities. No two roads connect the same pair of cities.
Bear Limak was once in a city a and he wanted to go to a city b. There was no direct connection so he decided to take a long walk, visiting each city exactly once. Formally:
* There is no road between a and b.
* There exists a sequence (path) of n distinct cities v1, v2, ..., vn that v1 = a, vn = b and there is a road between vi and vi + 1 for <image>.
On the other day, the similar thing happened. Limak wanted to travel between a city c and a city d. There is no road between them but there exists a sequence of n distinct cities u1, u2, ..., un that u1 = c, un = d and there is a road between ui and ui + 1 for <image>.
Also, Limak thinks that there are at most k roads in Bearland. He wonders whether he remembers everything correctly.
Given n, k and four distinct cities a, b, c, d, can you find possible paths (v1, ..., vn) and (u1, ..., un) to satisfy all the given conditions? Find any solution or print -1 if it's impossible.
Input
The first line of the input contains two integers n and k (4 ≤ n ≤ 1000, n - 1 ≤ k ≤ 2n - 2) — the number of cities and the maximum allowed number of roads, respectively.
The second line contains four distinct integers a, b, c and d (1 ≤ a, b, c, d ≤ n).
Output
Print -1 if it's impossible to satisfy all the given conditions. Otherwise, print two lines with paths descriptions. The first of these two lines should contain n distinct integers v1, v2, ..., vn where v1 = a and vn = b. The second line should contain n distinct integers u1, u2, ..., un where u1 = c and un = d.
Two paths generate at most 2n - 2 roads: (v1, v2), (v2, v3), ..., (vn - 1, vn), (u1, u2), (u2, u3), ..., (un - 1, un). Your answer will be considered wrong if contains more than k distinct roads or any other condition breaks. Note that (x, y) and (y, x) are the same road.
Examples
Input
7 11
2 4 7 3
Output
2 7 1 3 6 5 4
7 1 5 4 6 2 3
Input
1000 999
10 20 30 40
Output
-1
Note
In the first sample test, there should be 7 cities and at most 11 roads. The provided sample solution generates 10 roads, as in the drawing. You can also see a simple path of length n between 2 and 4, and a path between 7 and 3.
<image>
Submitted Solution:
```
f = lambda: map(int, input().split())
n, k = f()
a, b, c, d = f()
s = list(set(range(1, n + 1)).difference({a, b, c, d}))
d = [a, c] + s + [d, b] + [c, a] + s + [b, d]
print(' '.join(map(str, d)) if 4 < n < k else -1)
``` | instruction | 0 | 57,611 | 1 | 115,222 |
Yes | output | 1 | 57,611 | 1 | 115,223 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Bearland has n cities, numbered 1 through n. Cities are connected via bidirectional roads. Each road connects two distinct cities. No two roads connect the same pair of cities.
Bear Limak was once in a city a and he wanted to go to a city b. There was no direct connection so he decided to take a long walk, visiting each city exactly once. Formally:
* There is no road between a and b.
* There exists a sequence (path) of n distinct cities v1, v2, ..., vn that v1 = a, vn = b and there is a road between vi and vi + 1 for <image>.
On the other day, the similar thing happened. Limak wanted to travel between a city c and a city d. There is no road between them but there exists a sequence of n distinct cities u1, u2, ..., un that u1 = c, un = d and there is a road between ui and ui + 1 for <image>.
Also, Limak thinks that there are at most k roads in Bearland. He wonders whether he remembers everything correctly.
Given n, k and four distinct cities a, b, c, d, can you find possible paths (v1, ..., vn) and (u1, ..., un) to satisfy all the given conditions? Find any solution or print -1 if it's impossible.
Input
The first line of the input contains two integers n and k (4 ≤ n ≤ 1000, n - 1 ≤ k ≤ 2n - 2) — the number of cities and the maximum allowed number of roads, respectively.
The second line contains four distinct integers a, b, c and d (1 ≤ a, b, c, d ≤ n).
Output
Print -1 if it's impossible to satisfy all the given conditions. Otherwise, print two lines with paths descriptions. The first of these two lines should contain n distinct integers v1, v2, ..., vn where v1 = a and vn = b. The second line should contain n distinct integers u1, u2, ..., un where u1 = c and un = d.
Two paths generate at most 2n - 2 roads: (v1, v2), (v2, v3), ..., (vn - 1, vn), (u1, u2), (u2, u3), ..., (un - 1, un). Your answer will be considered wrong if contains more than k distinct roads or any other condition breaks. Note that (x, y) and (y, x) are the same road.
Examples
Input
7 11
2 4 7 3
Output
2 7 1 3 6 5 4
7 1 5 4 6 2 3
Input
1000 999
10 20 30 40
Output
-1
Note
In the first sample test, there should be 7 cities and at most 11 roads. The provided sample solution generates 10 roads, as in the drawing. You can also see a simple path of length n between 2 and 4, and a path between 7 and 3.
<image>
Submitted Solution:
```
n,k=map(int,input().split())
a,b,c,d=input().split()
if n<5 or k<n+1: print(-1)
else:
l=list(set(map(str,range(1,n+1)))-{a,b,c,d})
print(' '.join([a,c]+l+[d,b]+[c,a]+l+[b,d]))
``` | instruction | 0 | 57,612 | 1 | 115,224 |
Yes | output | 1 | 57,612 | 1 | 115,225 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Bearland has n cities, numbered 1 through n. Cities are connected via bidirectional roads. Each road connects two distinct cities. No two roads connect the same pair of cities.
Bear Limak was once in a city a and he wanted to go to a city b. There was no direct connection so he decided to take a long walk, visiting each city exactly once. Formally:
* There is no road between a and b.
* There exists a sequence (path) of n distinct cities v1, v2, ..., vn that v1 = a, vn = b and there is a road between vi and vi + 1 for <image>.
On the other day, the similar thing happened. Limak wanted to travel between a city c and a city d. There is no road between them but there exists a sequence of n distinct cities u1, u2, ..., un that u1 = c, un = d and there is a road between ui and ui + 1 for <image>.
Also, Limak thinks that there are at most k roads in Bearland. He wonders whether he remembers everything correctly.
Given n, k and four distinct cities a, b, c, d, can you find possible paths (v1, ..., vn) and (u1, ..., un) to satisfy all the given conditions? Find any solution or print -1 if it's impossible.
Input
The first line of the input contains two integers n and k (4 ≤ n ≤ 1000, n - 1 ≤ k ≤ 2n - 2) — the number of cities and the maximum allowed number of roads, respectively.
The second line contains four distinct integers a, b, c and d (1 ≤ a, b, c, d ≤ n).
Output
Print -1 if it's impossible to satisfy all the given conditions. Otherwise, print two lines with paths descriptions. The first of these two lines should contain n distinct integers v1, v2, ..., vn where v1 = a and vn = b. The second line should contain n distinct integers u1, u2, ..., un where u1 = c and un = d.
Two paths generate at most 2n - 2 roads: (v1, v2), (v2, v3), ..., (vn - 1, vn), (u1, u2), (u2, u3), ..., (un - 1, un). Your answer will be considered wrong if contains more than k distinct roads or any other condition breaks. Note that (x, y) and (y, x) are the same road.
Examples
Input
7 11
2 4 7 3
Output
2 7 1 3 6 5 4
7 1 5 4 6 2 3
Input
1000 999
10 20 30 40
Output
-1
Note
In the first sample test, there should be 7 cities and at most 11 roads. The provided sample solution generates 10 roads, as in the drawing. You can also see a simple path of length n between 2 and 4, and a path between 7 and 3.
<image>
Submitted Solution:
```
n,k=map(int,input().split())
a,b,s,d=input().split()
if n<5 or k<n+1: print(-1)
else:
l=list(set(map(str,range(1,n+1)))-{a,b,s,d})
print(' '.join([a,s]+l+[d,b]+[s,a]+l+[b,d]))
``` | instruction | 0 | 57,613 | 1 | 115,226 |
Yes | output | 1 | 57,613 | 1 | 115,227 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Bearland has n cities, numbered 1 through n. Cities are connected via bidirectional roads. Each road connects two distinct cities. No two roads connect the same pair of cities.
Bear Limak was once in a city a and he wanted to go to a city b. There was no direct connection so he decided to take a long walk, visiting each city exactly once. Formally:
* There is no road between a and b.
* There exists a sequence (path) of n distinct cities v1, v2, ..., vn that v1 = a, vn = b and there is a road between vi and vi + 1 for <image>.
On the other day, the similar thing happened. Limak wanted to travel between a city c and a city d. There is no road between them but there exists a sequence of n distinct cities u1, u2, ..., un that u1 = c, un = d and there is a road between ui and ui + 1 for <image>.
Also, Limak thinks that there are at most k roads in Bearland. He wonders whether he remembers everything correctly.
Given n, k and four distinct cities a, b, c, d, can you find possible paths (v1, ..., vn) and (u1, ..., un) to satisfy all the given conditions? Find any solution or print -1 if it's impossible.
Input
The first line of the input contains two integers n and k (4 ≤ n ≤ 1000, n - 1 ≤ k ≤ 2n - 2) — the number of cities and the maximum allowed number of roads, respectively.
The second line contains four distinct integers a, b, c and d (1 ≤ a, b, c, d ≤ n).
Output
Print -1 if it's impossible to satisfy all the given conditions. Otherwise, print two lines with paths descriptions. The first of these two lines should contain n distinct integers v1, v2, ..., vn where v1 = a and vn = b. The second line should contain n distinct integers u1, u2, ..., un where u1 = c and un = d.
Two paths generate at most 2n - 2 roads: (v1, v2), (v2, v3), ..., (vn - 1, vn), (u1, u2), (u2, u3), ..., (un - 1, un). Your answer will be considered wrong if contains more than k distinct roads or any other condition breaks. Note that (x, y) and (y, x) are the same road.
Examples
Input
7 11
2 4 7 3
Output
2 7 1 3 6 5 4
7 1 5 4 6 2 3
Input
1000 999
10 20 30 40
Output
-1
Note
In the first sample test, there should be 7 cities and at most 11 roads. The provided sample solution generates 10 roads, as in the drawing. You can also see a simple path of length n between 2 and 4, and a path between 7 and 3.
<image>
Submitted Solution:
```
n, k = map(int, input().split())
a, b, c, d = map(int, input().split())
if k < n + 1 or n == 4:
print(-1)
else:
print(a, c, end=' ')
for i in range(1, n + 1):
if i != a and i != b and i != c and i != d:
print(i, end=' ')
print(d, b)
print(c, a, end=' ')
for i in range(1, n + 1):
if i != a and i != b and i != c and i != d:
print(i, end=' ')
print(b, d)
``` | instruction | 0 | 57,614 | 1 | 115,228 |
Yes | output | 1 | 57,614 | 1 | 115,229 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Bearland has n cities, numbered 1 through n. Cities are connected via bidirectional roads. Each road connects two distinct cities. No two roads connect the same pair of cities.
Bear Limak was once in a city a and he wanted to go to a city b. There was no direct connection so he decided to take a long walk, visiting each city exactly once. Formally:
* There is no road between a and b.
* There exists a sequence (path) of n distinct cities v1, v2, ..., vn that v1 = a, vn = b and there is a road between vi and vi + 1 for <image>.
On the other day, the similar thing happened. Limak wanted to travel between a city c and a city d. There is no road between them but there exists a sequence of n distinct cities u1, u2, ..., un that u1 = c, un = d and there is a road between ui and ui + 1 for <image>.
Also, Limak thinks that there are at most k roads in Bearland. He wonders whether he remembers everything correctly.
Given n, k and four distinct cities a, b, c, d, can you find possible paths (v1, ..., vn) and (u1, ..., un) to satisfy all the given conditions? Find any solution or print -1 if it's impossible.
Input
The first line of the input contains two integers n and k (4 ≤ n ≤ 1000, n - 1 ≤ k ≤ 2n - 2) — the number of cities and the maximum allowed number of roads, respectively.
The second line contains four distinct integers a, b, c and d (1 ≤ a, b, c, d ≤ n).
Output
Print -1 if it's impossible to satisfy all the given conditions. Otherwise, print two lines with paths descriptions. The first of these two lines should contain n distinct integers v1, v2, ..., vn where v1 = a and vn = b. The second line should contain n distinct integers u1, u2, ..., un where u1 = c and un = d.
Two paths generate at most 2n - 2 roads: (v1, v2), (v2, v3), ..., (vn - 1, vn), (u1, u2), (u2, u3), ..., (un - 1, un). Your answer will be considered wrong if contains more than k distinct roads or any other condition breaks. Note that (x, y) and (y, x) are the same road.
Examples
Input
7 11
2 4 7 3
Output
2 7 1 3 6 5 4
7 1 5 4 6 2 3
Input
1000 999
10 20 30 40
Output
-1
Note
In the first sample test, there should be 7 cities and at most 11 roads. The provided sample solution generates 10 roads, as in the drawing. You can also see a simple path of length n between 2 and 4, and a path between 7 and 3.
<image>
Submitted Solution:
```
def format_print(l):
for i in l:
print(i, end=" ")
print("")
def main():
n, k = [int(i) for i in input().strip().split()]
a, b, c, d = [int(i) for i in input().strip().split()]
if k == n - 1:
print(-1)
return
s = [a, b, c, d]
others = [i for i in range(1, n + 1) if i not in s]
format_print([a, d, c] + others + [b])
format_print([c] + others + [b, a, d])
if __name__ == "__main__":
main()
``` | instruction | 0 | 57,615 | 1 | 115,230 |
No | output | 1 | 57,615 | 1 | 115,231 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Bearland has n cities, numbered 1 through n. Cities are connected via bidirectional roads. Each road connects two distinct cities. No two roads connect the same pair of cities.
Bear Limak was once in a city a and he wanted to go to a city b. There was no direct connection so he decided to take a long walk, visiting each city exactly once. Formally:
* There is no road between a and b.
* There exists a sequence (path) of n distinct cities v1, v2, ..., vn that v1 = a, vn = b and there is a road between vi and vi + 1 for <image>.
On the other day, the similar thing happened. Limak wanted to travel between a city c and a city d. There is no road between them but there exists a sequence of n distinct cities u1, u2, ..., un that u1 = c, un = d and there is a road between ui and ui + 1 for <image>.
Also, Limak thinks that there are at most k roads in Bearland. He wonders whether he remembers everything correctly.
Given n, k and four distinct cities a, b, c, d, can you find possible paths (v1, ..., vn) and (u1, ..., un) to satisfy all the given conditions? Find any solution or print -1 if it's impossible.
Input
The first line of the input contains two integers n and k (4 ≤ n ≤ 1000, n - 1 ≤ k ≤ 2n - 2) — the number of cities and the maximum allowed number of roads, respectively.
The second line contains four distinct integers a, b, c and d (1 ≤ a, b, c, d ≤ n).
Output
Print -1 if it's impossible to satisfy all the given conditions. Otherwise, print two lines with paths descriptions. The first of these two lines should contain n distinct integers v1, v2, ..., vn where v1 = a and vn = b. The second line should contain n distinct integers u1, u2, ..., un where u1 = c and un = d.
Two paths generate at most 2n - 2 roads: (v1, v2), (v2, v3), ..., (vn - 1, vn), (u1, u2), (u2, u3), ..., (un - 1, un). Your answer will be considered wrong if contains more than k distinct roads or any other condition breaks. Note that (x, y) and (y, x) are the same road.
Examples
Input
7 11
2 4 7 3
Output
2 7 1 3 6 5 4
7 1 5 4 6 2 3
Input
1000 999
10 20 30 40
Output
-1
Note
In the first sample test, there should be 7 cities and at most 11 roads. The provided sample solution generates 10 roads, as in the drawing. You can also see a simple path of length n between 2 and 4, and a path between 7 and 3.
<image>
Submitted Solution:
```
n,k=map(int,input().split())
a,b,c,d=map(int,input().split())
if k==n-1:
print(-1)
exit()
ans=[a]+[i for i in range(1,n+1) if i not in [a,b,c,d]]+[c,d,b]
print(*ans)
print(*(ans[:n-2][::-1]+[b,d]))
``` | instruction | 0 | 57,616 | 1 | 115,232 |
No | output | 1 | 57,616 | 1 | 115,233 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Bearland has n cities, numbered 1 through n. Cities are connected via bidirectional roads. Each road connects two distinct cities. No two roads connect the same pair of cities.
Bear Limak was once in a city a and he wanted to go to a city b. There was no direct connection so he decided to take a long walk, visiting each city exactly once. Formally:
* There is no road between a and b.
* There exists a sequence (path) of n distinct cities v1, v2, ..., vn that v1 = a, vn = b and there is a road between vi and vi + 1 for <image>.
On the other day, the similar thing happened. Limak wanted to travel between a city c and a city d. There is no road between them but there exists a sequence of n distinct cities u1, u2, ..., un that u1 = c, un = d and there is a road between ui and ui + 1 for <image>.
Also, Limak thinks that there are at most k roads in Bearland. He wonders whether he remembers everything correctly.
Given n, k and four distinct cities a, b, c, d, can you find possible paths (v1, ..., vn) and (u1, ..., un) to satisfy all the given conditions? Find any solution or print -1 if it's impossible.
Input
The first line of the input contains two integers n and k (4 ≤ n ≤ 1000, n - 1 ≤ k ≤ 2n - 2) — the number of cities and the maximum allowed number of roads, respectively.
The second line contains four distinct integers a, b, c and d (1 ≤ a, b, c, d ≤ n).
Output
Print -1 if it's impossible to satisfy all the given conditions. Otherwise, print two lines with paths descriptions. The first of these two lines should contain n distinct integers v1, v2, ..., vn where v1 = a and vn = b. The second line should contain n distinct integers u1, u2, ..., un where u1 = c and un = d.
Two paths generate at most 2n - 2 roads: (v1, v2), (v2, v3), ..., (vn - 1, vn), (u1, u2), (u2, u3), ..., (un - 1, un). Your answer will be considered wrong if contains more than k distinct roads or any other condition breaks. Note that (x, y) and (y, x) are the same road.
Examples
Input
7 11
2 4 7 3
Output
2 7 1 3 6 5 4
7 1 5 4 6 2 3
Input
1000 999
10 20 30 40
Output
-1
Note
In the first sample test, there should be 7 cities and at most 11 roads. The provided sample solution generates 10 roads, as in the drawing. You can also see a simple path of length n between 2 and 4, and a path between 7 and 3.
<image>
Submitted Solution:
```
n,m=list(map(int,input().split()))
a,b,c,d=list(map(int,input().split()))
if m<n+1:
print(-1)
else:
arr=[]
arr.extend([a,d,c])
for i in range(1,n+1):
if i+1!=a and i+1!=b and i+1!=c and i+1!=d:
arr.append(i+1)
arr.extend([b,a,d])
print(*arr[:n])
print(*arr[2:])
``` | instruction | 0 | 57,617 | 1 | 115,234 |
No | output | 1 | 57,617 | 1 | 115,235 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Bearland has n cities, numbered 1 through n. Cities are connected via bidirectional roads. Each road connects two distinct cities. No two roads connect the same pair of cities.
Bear Limak was once in a city a and he wanted to go to a city b. There was no direct connection so he decided to take a long walk, visiting each city exactly once. Formally:
* There is no road between a and b.
* There exists a sequence (path) of n distinct cities v1, v2, ..., vn that v1 = a, vn = b and there is a road between vi and vi + 1 for <image>.
On the other day, the similar thing happened. Limak wanted to travel between a city c and a city d. There is no road between them but there exists a sequence of n distinct cities u1, u2, ..., un that u1 = c, un = d and there is a road between ui and ui + 1 for <image>.
Also, Limak thinks that there are at most k roads in Bearland. He wonders whether he remembers everything correctly.
Given n, k and four distinct cities a, b, c, d, can you find possible paths (v1, ..., vn) and (u1, ..., un) to satisfy all the given conditions? Find any solution or print -1 if it's impossible.
Input
The first line of the input contains two integers n and k (4 ≤ n ≤ 1000, n - 1 ≤ k ≤ 2n - 2) — the number of cities and the maximum allowed number of roads, respectively.
The second line contains four distinct integers a, b, c and d (1 ≤ a, b, c, d ≤ n).
Output
Print -1 if it's impossible to satisfy all the given conditions. Otherwise, print two lines with paths descriptions. The first of these two lines should contain n distinct integers v1, v2, ..., vn where v1 = a and vn = b. The second line should contain n distinct integers u1, u2, ..., un where u1 = c and un = d.
Two paths generate at most 2n - 2 roads: (v1, v2), (v2, v3), ..., (vn - 1, vn), (u1, u2), (u2, u3), ..., (un - 1, un). Your answer will be considered wrong if contains more than k distinct roads or any other condition breaks. Note that (x, y) and (y, x) are the same road.
Examples
Input
7 11
2 4 7 3
Output
2 7 1 3 6 5 4
7 1 5 4 6 2 3
Input
1000 999
10 20 30 40
Output
-1
Note
In the first sample test, there should be 7 cities and at most 11 roads. The provided sample solution generates 10 roads, as in the drawing. You can also see a simple path of length n between 2 and 4, and a path between 7 and 3.
<image>
Submitted Solution:
```
n,m=list(map(int,input().split()))
a,b,c,d=list(map(int,input().split()))
if m<n+1:
print(-1)
else:
arr=[]
arr.extend([a,d,c])
for i in range(n):
if i+1!=a and i+1!=b and i+1!=c and i+1!=d:
arr.append(i+1)
arr.extend([b,a,d])
print(*arr[:n])
print(*arr[2:])
``` | instruction | 0 | 57,618 | 1 | 115,236 |
No | output | 1 | 57,618 | 1 | 115,237 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya is currently at a car rental service, and he wants to reach cinema. The film he has bought a ticket for starts in t minutes. There is a straight road of length s from the service to the cinema. Let's introduce a coordinate system so that the car rental service is at the point 0, and the cinema is at the point s.
There are k gas stations along the road, and at each of them you can fill a car with any amount of fuel for free! Consider that this operation doesn't take any time, i.e. is carried out instantly.
There are n cars in the rental service, i-th of them is characterized with two integers ci and vi — the price of this car rent and the capacity of its fuel tank in liters. It's not allowed to fuel a car with more fuel than its tank capacity vi. All cars are completely fueled at the car rental service.
Each of the cars can be driven in one of two speed modes: normal or accelerated. In the normal mode a car covers 1 kilometer in 2 minutes, and consumes 1 liter of fuel. In the accelerated mode a car covers 1 kilometer in 1 minutes, but consumes 2 liters of fuel. The driving mode can be changed at any moment and any number of times.
Your task is to choose a car with minimum price such that Vasya can reach the cinema before the show starts, i.e. not later than in t minutes. Assume that all cars are completely fueled initially.
Input
The first line contains four positive integers n, k, s and t (1 ≤ n ≤ 2·105, 1 ≤ k ≤ 2·105, 2 ≤ s ≤ 109, 1 ≤ t ≤ 2·109) — the number of cars at the car rental service, the number of gas stations along the road, the length of the road and the time in which the film starts.
Each of the next n lines contains two positive integers ci and vi (1 ≤ ci, vi ≤ 109) — the price of the i-th car and its fuel tank capacity.
The next line contains k distinct integers g1, g2, ..., gk (1 ≤ gi ≤ s - 1) — the positions of the gas stations on the road in arbitrary order.
Output
Print the minimum rent price of an appropriate car, i.e. such car that Vasya will be able to reach the cinema before the film starts (not later than in t minutes). If there is no appropriate car, print -1.
Examples
Input
3 1 8 10
10 8
5 7
11 9
3
Output
10
Input
2 2 10 18
10 4
20 6
5 3
Output
20
Note
In the first sample, Vasya can reach the cinema in time using the first or the third cars, but it would be cheaper to choose the first one. Its price is equal to 10, and the capacity of its fuel tank is 8. Then Vasya can drive to the first gas station in the accelerated mode in 3 minutes, spending 6 liters of fuel. After that he can full the tank and cover 2 kilometers in the normal mode in 4 minutes, spending 2 liters of fuel. Finally, he drives in the accelerated mode covering the remaining 3 kilometers in 3 minutes and spending 6 liters of fuel. | instruction | 0 | 57,654 | 1 | 115,308 |
Tags: binary search, greedy, sortings
Correct Solution:
```
# Question B. Road to Cinema
import sys
def roadToCinema(V, S, T, stations): # O(M)
"""
V : volume of fuel tank
S : total distance
T : time limit
stations: fuel stations' locations
rtype : boolean, whether this aircraft can travel within the time limit
"""
m = len(stations)
t = 0
stations.append(S) # destination
prev = 0
for cur in stations:
dis = cur - prev
# let Sa, Sb as the distance of accelerated mode/ normal mode respectively
# then the task is:
# min t = (Sa + 2 * Sb)
# s.t. Sa + Sb = dis
# 2 * Sa + Sb <= V
if dis > V:
# Sa <= V - dis < 0
return False
else:
# t = Sa + 2Sb = 3(Sa + Sb) - (2Sa + Sb)
# >= 3 * dis - V
# on the other hand, Sb is non-negative
# Sb = t - dis
t += max(dis * 3 - V, dis)
if t > T:
return False
prev = cur
return True
def binSearch(S, T, stations): # O(logS * M)
"""
to find the least tank volume to enable the aircraft to complete the journey
the fastest way is to complete the whole journey with the speed of 2km/min, at 2L/km
V <= 2S
"""
l = stations[0]
r = S * 2
for i in range(1, len(stations)):
l = max(stations[i] - stations[i - 1], l)
l = max(l, S - stations[-1])
r = 2 * l
if T < S:
return float("inf")
while l + 1 < r:
m = l + (r - l) // 2
if roadToCinema(m, S, T, stations) == True:
r = m
else:
l = m
if roadToCinema(l, S, T, stations):
return l
if roadToCinema(r, S, T, stations):
return r
return float("inf")
if __name__ == "__main__": # O(logS * M + N)
line = sys.stdin.readline()
[N, M, S, T] = list(map(int, line.split(" ")))
aircrafts = []
for i in range(N):
[c, v] = list(map(int, sys.stdin.readline().split(" ")))
aircrafts.append([c, v])
stations = list(map(int, sys.stdin.readline().split(" ")))
stations.sort()
minVolume = binSearch(S, T, stations)
if minVolume == float("inf"):
# no aircraft can complete the journey
print(-1)
else:
res = float("inf")
for i in range(N):
if aircrafts[i][1] >= minVolume:
res = min(res, aircrafts[i][0])
if res == float('inf'):
# no given aircraft can complete the journey
print(-1)
else:
print(res)
``` | output | 1 | 57,654 | 1 | 115,309 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya is currently at a car rental service, and he wants to reach cinema. The film he has bought a ticket for starts in t minutes. There is a straight road of length s from the service to the cinema. Let's introduce a coordinate system so that the car rental service is at the point 0, and the cinema is at the point s.
There are k gas stations along the road, and at each of them you can fill a car with any amount of fuel for free! Consider that this operation doesn't take any time, i.e. is carried out instantly.
There are n cars in the rental service, i-th of them is characterized with two integers ci and vi — the price of this car rent and the capacity of its fuel tank in liters. It's not allowed to fuel a car with more fuel than its tank capacity vi. All cars are completely fueled at the car rental service.
Each of the cars can be driven in one of two speed modes: normal or accelerated. In the normal mode a car covers 1 kilometer in 2 minutes, and consumes 1 liter of fuel. In the accelerated mode a car covers 1 kilometer in 1 minutes, but consumes 2 liters of fuel. The driving mode can be changed at any moment and any number of times.
Your task is to choose a car with minimum price such that Vasya can reach the cinema before the show starts, i.e. not later than in t minutes. Assume that all cars are completely fueled initially.
Input
The first line contains four positive integers n, k, s and t (1 ≤ n ≤ 2·105, 1 ≤ k ≤ 2·105, 2 ≤ s ≤ 109, 1 ≤ t ≤ 2·109) — the number of cars at the car rental service, the number of gas stations along the road, the length of the road and the time in which the film starts.
Each of the next n lines contains two positive integers ci and vi (1 ≤ ci, vi ≤ 109) — the price of the i-th car and its fuel tank capacity.
The next line contains k distinct integers g1, g2, ..., gk (1 ≤ gi ≤ s - 1) — the positions of the gas stations on the road in arbitrary order.
Output
Print the minimum rent price of an appropriate car, i.e. such car that Vasya will be able to reach the cinema before the film starts (not later than in t minutes). If there is no appropriate car, print -1.
Examples
Input
3 1 8 10
10 8
5 7
11 9
3
Output
10
Input
2 2 10 18
10 4
20 6
5 3
Output
20
Note
In the first sample, Vasya can reach the cinema in time using the first or the third cars, but it would be cheaper to choose the first one. Its price is equal to 10, and the capacity of its fuel tank is 8. Then Vasya can drive to the first gas station in the accelerated mode in 3 minutes, spending 6 liters of fuel. After that he can full the tank and cover 2 kilometers in the normal mode in 4 minutes, spending 2 liters of fuel. Finally, he drives in the accelerated mode covering the remaining 3 kilometers in 3 minutes and spending 6 liters of fuel. | instruction | 0 | 57,655 | 1 | 115,310 |
Tags: binary search, greedy, sortings
Correct Solution:
```
import sys
input = sys.stdin.readline
N = int(2e5+1)
n, k, s, t = map(int, input().split())
car = [list(map(int, input().split())) for _ in range(n)]
g = sorted(list(map(int, input().split()))) + [0]
g[k] = s - g[k - 1]
for i in range(k-1, 0, -1):
g[i] -= g[i - 1]
def is_valid(g, k, v, t):
need = 0
for i in range(k+1):
need += max(g[i], 3 * g[i] - v)
return need <= t
def binary_search(g, k):
l, r = max(g), int(2e9)
while l < r:
v = l + (r - l) // 2
if is_valid(g, k, v, t):
r = v
else:
l = v + 1
return l
l = binary_search(g, k)
res = int(2e9)
for i in range(n):
if car[i][1] >= l:
res = min(res, car[i][0])
print(-1 if res == int(2e9) else res)
``` | output | 1 | 57,655 | 1 | 115,311 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya is currently at a car rental service, and he wants to reach cinema. The film he has bought a ticket for starts in t minutes. There is a straight road of length s from the service to the cinema. Let's introduce a coordinate system so that the car rental service is at the point 0, and the cinema is at the point s.
There are k gas stations along the road, and at each of them you can fill a car with any amount of fuel for free! Consider that this operation doesn't take any time, i.e. is carried out instantly.
There are n cars in the rental service, i-th of them is characterized with two integers ci and vi — the price of this car rent and the capacity of its fuel tank in liters. It's not allowed to fuel a car with more fuel than its tank capacity vi. All cars are completely fueled at the car rental service.
Each of the cars can be driven in one of two speed modes: normal or accelerated. In the normal mode a car covers 1 kilometer in 2 minutes, and consumes 1 liter of fuel. In the accelerated mode a car covers 1 kilometer in 1 minutes, but consumes 2 liters of fuel. The driving mode can be changed at any moment and any number of times.
Your task is to choose a car with minimum price such that Vasya can reach the cinema before the show starts, i.e. not later than in t minutes. Assume that all cars are completely fueled initially.
Input
The first line contains four positive integers n, k, s and t (1 ≤ n ≤ 2·105, 1 ≤ k ≤ 2·105, 2 ≤ s ≤ 109, 1 ≤ t ≤ 2·109) — the number of cars at the car rental service, the number of gas stations along the road, the length of the road and the time in which the film starts.
Each of the next n lines contains two positive integers ci and vi (1 ≤ ci, vi ≤ 109) — the price of the i-th car and its fuel tank capacity.
The next line contains k distinct integers g1, g2, ..., gk (1 ≤ gi ≤ s - 1) — the positions of the gas stations on the road in arbitrary order.
Output
Print the minimum rent price of an appropriate car, i.e. such car that Vasya will be able to reach the cinema before the film starts (not later than in t minutes). If there is no appropriate car, print -1.
Examples
Input
3 1 8 10
10 8
5 7
11 9
3
Output
10
Input
2 2 10 18
10 4
20 6
5 3
Output
20
Note
In the first sample, Vasya can reach the cinema in time using the first or the third cars, but it would be cheaper to choose the first one. Its price is equal to 10, and the capacity of its fuel tank is 8. Then Vasya can drive to the first gas station in the accelerated mode in 3 minutes, spending 6 liters of fuel. After that he can full the tank and cover 2 kilometers in the normal mode in 4 minutes, spending 2 liters of fuel. Finally, he drives in the accelerated mode covering the remaining 3 kilometers in 3 minutes and spending 6 liters of fuel. | instruction | 0 | 57,656 | 1 | 115,312 |
Tags: binary search, greedy, sortings
Correct Solution:
```
# Question B. Road to Cinema
import sys
def roadToCinema(V, S, T, stations): # O(M)
"""
V : volume of fuel tank
S : total distance
T : time limit
stations: fuel stations' locations
rtype : boolean, whether this aircraft can travel within the time limit
"""
m = len(stations)
t = 0
stations.append(S) # destination
prev = 0
for cur in stations:
dis = cur - prev
# let Sa, Sb as the distance of accelerated mode/ normal mode respectively
# then the task is:
# min t = (Sa + 2 * Sb)
# s.t. Sa + Sb = dis
# 2 * Sa + Sb <= V
if dis > V:
# Sa <= V - dis < 0
return False
else:
# t = Sa + 2Sb = 3(Sa + Sb) - (2Sa + Sb)
# >= 3 * dis - V
# on the other hand, Sb is non-negative
# Sb = t - dis
t += max(dis * 3 - V, dis)
if t > T:
return False
prev = cur
return True
def binSearch(S, T, stations): # O(logS * M)
"""
to find the least tank volume to enable the aircraft to complete the journey
the fastest way is to complete the whole journey with the speed of 2km/min, at 2L/km
V <= 2S
"""
l = 0
r = S * 2
if T < S:
return float("inf")
while l + 1 < r:
m = l + (r - l) // 2
if roadToCinema(m, S, T, stations) == True:
r = m
else:
l = m
return r
if __name__ == "__main__": # O(logS * M + N)
line = sys.stdin.readline()
[N, M, S, T] = list(map(int, line.split(" ")))
aircrafts = []
for i in range(N):
[c, v] = list(map(int, sys.stdin.readline().split(" ")))
aircrafts.append([c, v])
stations = list(map(int, sys.stdin.readline().split(" ")))
stations.sort()
minVolume = binSearch(S, T, stations)
if minVolume == float("inf"):
# no aircraft can complete the journey
print(-1)
else:
res = float("inf")
for i in range(N):
if aircrafts[i][1] >= minVolume:
res = min(res, aircrafts[i][0])
if res == float('inf'):
# no given aircraft can complete the journey
print(-1)
else:
print(res)
``` | output | 1 | 57,656 | 1 | 115,313 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya is currently at a car rental service, and he wants to reach cinema. The film he has bought a ticket for starts in t minutes. There is a straight road of length s from the service to the cinema. Let's introduce a coordinate system so that the car rental service is at the point 0, and the cinema is at the point s.
There are k gas stations along the road, and at each of them you can fill a car with any amount of fuel for free! Consider that this operation doesn't take any time, i.e. is carried out instantly.
There are n cars in the rental service, i-th of them is characterized with two integers ci and vi — the price of this car rent and the capacity of its fuel tank in liters. It's not allowed to fuel a car with more fuel than its tank capacity vi. All cars are completely fueled at the car rental service.
Each of the cars can be driven in one of two speed modes: normal or accelerated. In the normal mode a car covers 1 kilometer in 2 minutes, and consumes 1 liter of fuel. In the accelerated mode a car covers 1 kilometer in 1 minutes, but consumes 2 liters of fuel. The driving mode can be changed at any moment and any number of times.
Your task is to choose a car with minimum price such that Vasya can reach the cinema before the show starts, i.e. not later than in t minutes. Assume that all cars are completely fueled initially.
Input
The first line contains four positive integers n, k, s and t (1 ≤ n ≤ 2·105, 1 ≤ k ≤ 2·105, 2 ≤ s ≤ 109, 1 ≤ t ≤ 2·109) — the number of cars at the car rental service, the number of gas stations along the road, the length of the road and the time in which the film starts.
Each of the next n lines contains two positive integers ci and vi (1 ≤ ci, vi ≤ 109) — the price of the i-th car and its fuel tank capacity.
The next line contains k distinct integers g1, g2, ..., gk (1 ≤ gi ≤ s - 1) — the positions of the gas stations on the road in arbitrary order.
Output
Print the minimum rent price of an appropriate car, i.e. such car that Vasya will be able to reach the cinema before the film starts (not later than in t minutes). If there is no appropriate car, print -1.
Examples
Input
3 1 8 10
10 8
5 7
11 9
3
Output
10
Input
2 2 10 18
10 4
20 6
5 3
Output
20
Note
In the first sample, Vasya can reach the cinema in time using the first or the third cars, but it would be cheaper to choose the first one. Its price is equal to 10, and the capacity of its fuel tank is 8. Then Vasya can drive to the first gas station in the accelerated mode in 3 minutes, spending 6 liters of fuel. After that he can full the tank and cover 2 kilometers in the normal mode in 4 minutes, spending 2 liters of fuel. Finally, he drives in the accelerated mode covering the remaining 3 kilometers in 3 minutes and spending 6 liters of fuel.
Submitted Solution:
```
n, k, s, t = map(int, input().split()) #auto, oil, cinema, time
auto = ["0"] * n
for i in range(n):
auto[i] = list(map(int, input().split()))
auto.sort()
g = [0, s]
g += list(map(int, input().split()))
g.sort()
def time(v, l):
if v < l:
return 10 * t
else:
return (v - l) + (2 * l - v) * 2
result1 = 2 * t
i = 0
while i < n and result1 > t:
timing = 0
for j in range(1, k + 1):
l = g[j] - g[j - 1]
v = auto[i][1]
timing += time(v, l)
if result1 > timing:
result1 = timing
i += 1
if result1 > t:
print(-1)
else:
print(auto[i][0])
``` | instruction | 0 | 57,657 | 1 | 115,314 |
No | output | 1 | 57,657 | 1 | 115,315 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya is currently at a car rental service, and he wants to reach cinema. The film he has bought a ticket for starts in t minutes. There is a straight road of length s from the service to the cinema. Let's introduce a coordinate system so that the car rental service is at the point 0, and the cinema is at the point s.
There are k gas stations along the road, and at each of them you can fill a car with any amount of fuel for free! Consider that this operation doesn't take any time, i.e. is carried out instantly.
There are n cars in the rental service, i-th of them is characterized with two integers ci and vi — the price of this car rent and the capacity of its fuel tank in liters. It's not allowed to fuel a car with more fuel than its tank capacity vi. All cars are completely fueled at the car rental service.
Each of the cars can be driven in one of two speed modes: normal or accelerated. In the normal mode a car covers 1 kilometer in 2 minutes, and consumes 1 liter of fuel. In the accelerated mode a car covers 1 kilometer in 1 minutes, but consumes 2 liters of fuel. The driving mode can be changed at any moment and any number of times.
Your task is to choose a car with minimum price such that Vasya can reach the cinema before the show starts, i.e. not later than in t minutes. Assume that all cars are completely fueled initially.
Input
The first line contains four positive integers n, k, s and t (1 ≤ n ≤ 2·105, 1 ≤ k ≤ 2·105, 2 ≤ s ≤ 109, 1 ≤ t ≤ 2·109) — the number of cars at the car rental service, the number of gas stations along the road, the length of the road and the time in which the film starts.
Each of the next n lines contains two positive integers ci and vi (1 ≤ ci, vi ≤ 109) — the price of the i-th car and its fuel tank capacity.
The next line contains k distinct integers g1, g2, ..., gk (1 ≤ gi ≤ s - 1) — the positions of the gas stations on the road in arbitrary order.
Output
Print the minimum rent price of an appropriate car, i.e. such car that Vasya will be able to reach the cinema before the film starts (not later than in t minutes). If there is no appropriate car, print -1.
Examples
Input
3 1 8 10
10 8
5 7
11 9
3
Output
10
Input
2 2 10 18
10 4
20 6
5 3
Output
20
Note
In the first sample, Vasya can reach the cinema in time using the first or the third cars, but it would be cheaper to choose the first one. Its price is equal to 10, and the capacity of its fuel tank is 8. Then Vasya can drive to the first gas station in the accelerated mode in 3 minutes, spending 6 liters of fuel. After that he can full the tank and cover 2 kilometers in the normal mode in 4 minutes, spending 2 liters of fuel. Finally, he drives in the accelerated mode covering the remaining 3 kilometers in 3 minutes and spending 6 liters of fuel.
Submitted Solution:
```
n, k, s, t = map(int, input().split())
cars = []
val = []
lastp = 0
res = 0
lastt = 2000000001
lastq = 2000000001
lt = t
for i in range(n):
c,v = map(int, input().split())
cars.append(c)
val.append(v)
g = list(map(int, input().split()))
g = sorted(g)
for y in range(n):
mini = min(cars)
idc = cars.index(mini)
minival = val[idc]
cars.remove(mini)
val.remove(minival)
for i in range(k):
a = minival
g[i] = g[i]-lastp
if g[i]*2<=a:
t-=(g[i])
a = 0
else:
while g[i]*2>a:
g[i]-=1
a-=1
t-=2
if g[i]*2<=a:
t -=g[i]
a = 0
lastp = g[i]
lastp = 0
if t>=0:
if lastt>t:
lastt = t
if lastq > mini:
lastq = mini
print(lastq)
t = lt
#print(lastt)
``` | instruction | 0 | 57,658 | 1 | 115,316 |
No | output | 1 | 57,658 | 1 | 115,317 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya is currently at a car rental service, and he wants to reach cinema. The film he has bought a ticket for starts in t minutes. There is a straight road of length s from the service to the cinema. Let's introduce a coordinate system so that the car rental service is at the point 0, and the cinema is at the point s.
There are k gas stations along the road, and at each of them you can fill a car with any amount of fuel for free! Consider that this operation doesn't take any time, i.e. is carried out instantly.
There are n cars in the rental service, i-th of them is characterized with two integers ci and vi — the price of this car rent and the capacity of its fuel tank in liters. It's not allowed to fuel a car with more fuel than its tank capacity vi. All cars are completely fueled at the car rental service.
Each of the cars can be driven in one of two speed modes: normal or accelerated. In the normal mode a car covers 1 kilometer in 2 minutes, and consumes 1 liter of fuel. In the accelerated mode a car covers 1 kilometer in 1 minutes, but consumes 2 liters of fuel. The driving mode can be changed at any moment and any number of times.
Your task is to choose a car with minimum price such that Vasya can reach the cinema before the show starts, i.e. not later than in t minutes. Assume that all cars are completely fueled initially.
Input
The first line contains four positive integers n, k, s and t (1 ≤ n ≤ 2·105, 1 ≤ k ≤ 2·105, 2 ≤ s ≤ 109, 1 ≤ t ≤ 2·109) — the number of cars at the car rental service, the number of gas stations along the road, the length of the road and the time in which the film starts.
Each of the next n lines contains two positive integers ci and vi (1 ≤ ci, vi ≤ 109) — the price of the i-th car and its fuel tank capacity.
The next line contains k distinct integers g1, g2, ..., gk (1 ≤ gi ≤ s - 1) — the positions of the gas stations on the road in arbitrary order.
Output
Print the minimum rent price of an appropriate car, i.e. such car that Vasya will be able to reach the cinema before the film starts (not later than in t minutes). If there is no appropriate car, print -1.
Examples
Input
3 1 8 10
10 8
5 7
11 9
3
Output
10
Input
2 2 10 18
10 4
20 6
5 3
Output
20
Note
In the first sample, Vasya can reach the cinema in time using the first or the third cars, but it would be cheaper to choose the first one. Its price is equal to 10, and the capacity of its fuel tank is 8. Then Vasya can drive to the first gas station in the accelerated mode in 3 minutes, spending 6 liters of fuel. After that he can full the tank and cover 2 kilometers in the normal mode in 4 minutes, spending 2 liters of fuel. Finally, he drives in the accelerated mode covering the remaining 3 kilometers in 3 minutes and spending 6 liters of fuel.
Submitted Solution:
```
n, k, s, t = map(int, input().split()) #auto, oil, cinema, time
auto = ["0"] * n
for i in range(n):
auto[i] = list(map(int, input().split()))
auto.sort()
g = [0, s]
g += list(map(int, input().split()))
g.sort()
def time(v, l):
if v < l:
return 10 * t
else:
return (v - l) + (2 * l - v) * 2
result1 = 2 * t
i = 0
while i <= n and result1 > t:
timing = 0
for j in range(1, k):
l = g[j] - g[j - 1]
v = auto[i][1]
timing += time(v, l)
if result1 > timing:
result1 = timing
i += 1
if result1 > t:
print(-1)
else:
print(auto[i][0])
``` | instruction | 0 | 57,659 | 1 | 115,318 |
No | output | 1 | 57,659 | 1 | 115,319 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya is currently at a car rental service, and he wants to reach cinema. The film he has bought a ticket for starts in t minutes. There is a straight road of length s from the service to the cinema. Let's introduce a coordinate system so that the car rental service is at the point 0, and the cinema is at the point s.
There are k gas stations along the road, and at each of them you can fill a car with any amount of fuel for free! Consider that this operation doesn't take any time, i.e. is carried out instantly.
There are n cars in the rental service, i-th of them is characterized with two integers ci and vi — the price of this car rent and the capacity of its fuel tank in liters. It's not allowed to fuel a car with more fuel than its tank capacity vi. All cars are completely fueled at the car rental service.
Each of the cars can be driven in one of two speed modes: normal or accelerated. In the normal mode a car covers 1 kilometer in 2 minutes, and consumes 1 liter of fuel. In the accelerated mode a car covers 1 kilometer in 1 minutes, but consumes 2 liters of fuel. The driving mode can be changed at any moment and any number of times.
Your task is to choose a car with minimum price such that Vasya can reach the cinema before the show starts, i.e. not later than in t minutes. Assume that all cars are completely fueled initially.
Input
The first line contains four positive integers n, k, s and t (1 ≤ n ≤ 2·105, 1 ≤ k ≤ 2·105, 2 ≤ s ≤ 109, 1 ≤ t ≤ 2·109) — the number of cars at the car rental service, the number of gas stations along the road, the length of the road and the time in which the film starts.
Each of the next n lines contains two positive integers ci and vi (1 ≤ ci, vi ≤ 109) — the price of the i-th car and its fuel tank capacity.
The next line contains k distinct integers g1, g2, ..., gk (1 ≤ gi ≤ s - 1) — the positions of the gas stations on the road in arbitrary order.
Output
Print the minimum rent price of an appropriate car, i.e. such car that Vasya will be able to reach the cinema before the film starts (not later than in t minutes). If there is no appropriate car, print -1.
Examples
Input
3 1 8 10
10 8
5 7
11 9
3
Output
10
Input
2 2 10 18
10 4
20 6
5 3
Output
20
Note
In the first sample, Vasya can reach the cinema in time using the first or the third cars, but it would be cheaper to choose the first one. Its price is equal to 10, and the capacity of its fuel tank is 8. Then Vasya can drive to the first gas station in the accelerated mode in 3 minutes, spending 6 liters of fuel. After that he can full the tank and cover 2 kilometers in the normal mode in 4 minutes, spending 2 liters of fuel. Finally, he drives in the accelerated mode covering the remaining 3 kilometers in 3 minutes and spending 6 liters of fuel.
Submitted Solution:
```
n,k,s,t=[int(i) for i in input().split()]
cars=[]
r=1200000000
l=0
for i in range(n):
cars.append([int(i) for i in input().split()])
g=[int(i) for i in input().split()]
g.append(s)
g.sort()
maxG=g[0]
for i in range(1,k+1):
g[i]-=g[i-1]
if g[i]>maxG: maxG=g[i]
while l+1<r:
dif=(l+r)//2
if dif<maxG:
l=dif
continue
time=0
for i in g:
time+=i*2-min((dif-i),i)
if time<=t:
r=dif
else:
l=dif
minC=2000000000
for i in range(0,n):
if cars[i][1]>=r:
if cars[i][0]<minC:minC=cars[i][0]
if minC>=1200000000:
print(-1)
else: print(minC)
``` | instruction | 0 | 57,660 | 1 | 115,320 |
No | output | 1 | 57,660 | 1 | 115,321 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke has decided to play a game, where the player runs a railway company. There are M+1 stations on Snuke Line, numbered 0 through M. A train on Snuke Line stops at station 0 and every d-th station thereafter, where d is a predetermined constant for each train. For example, if d = 3, the train stops at station 0, 3, 6, 9, and so forth.
There are N kinds of souvenirs sold in areas around Snuke Line. The i-th kind of souvenirs can be purchased when the train stops at one of the following stations: stations l_i, l_i+1, l_i+2, ..., r_i.
There are M values of d, the interval between two stops, for trains on Snuke Line: 1, 2, 3, ..., M. For each of these M values, find the number of the kinds of souvenirs that can be purchased if one takes a train with that value of d at station 0. Here, assume that it is not allowed to change trains.
Constraints
* 1 ≦ N ≦ 3 × 10^{5}
* 1 ≦ M ≦ 10^{5}
* 1 ≦ l_i ≦ r_i ≦ M
Input
The input is given from Standard Input in the following format:
N M
l_1 r_1
:
l_{N} r_{N}
Output
Print the answer in M lines. The i-th line should contain the maximum number of the kinds of souvenirs that can be purchased if one takes a train stopping every i-th station.
Examples
Input
3 3
1 2
2 3
3 3
Output
3
2
2
Input
7 9
1 7
5 9
5 7
5 9
1 1
6 8
3 4
Output
7
6
6
5
4
5
5
3
2 | instruction | 0 | 57,868 | 1 | 115,736 |
"Correct Solution:
```
from collections import defaultdict
N, M = map(int, input().split())
section = [list(map(int, input().split())) for i in range(N)]
# 区間の大きさごとに分類
D = defaultdict(list)
for sec in section:
D[sec[1] - sec[0] + 1].append(sec)
class BinaryIndexedTree:
def __init__(self, n):
self.size = n
self.bit = [0] * (n + 1)
def sum(self, i):
s = 0
while i > 0:
s += self.bit[i]
i -= (i & -i)
return s
def add(self, i, x):
while i <= self.size:
self.bit[i] += x
i += (i & -i)
def reset(self):
self.bit = [0] * (self.size + 1)
BIT = BinaryIndexedTree(M)
for d in range(1, M + 1):
for l, r in D[d - 1]:
N -= 1
BIT.add(l, 1)
BIT.add(r + 1, -1)
ans = N
for i in range(d, M + 1, d):
ans += BIT.sum(i)
print(ans)
``` | output | 1 | 57,868 | 1 | 115,737 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Snuke has decided to play a game, where the player runs a railway company. There are M+1 stations on Snuke Line, numbered 0 through M. A train on Snuke Line stops at station 0 and every d-th station thereafter, where d is a predetermined constant for each train. For example, if d = 3, the train stops at station 0, 3, 6, 9, and so forth.
There are N kinds of souvenirs sold in areas around Snuke Line. The i-th kind of souvenirs can be purchased when the train stops at one of the following stations: stations l_i, l_i+1, l_i+2, ..., r_i.
There are M values of d, the interval between two stops, for trains on Snuke Line: 1, 2, 3, ..., M. For each of these M values, find the number of the kinds of souvenirs that can be purchased if one takes a train with that value of d at station 0. Here, assume that it is not allowed to change trains.
Constraints
* 1 ≦ N ≦ 3 × 10^{5}
* 1 ≦ M ≦ 10^{5}
* 1 ≦ l_i ≦ r_i ≦ M
Input
The input is given from Standard Input in the following format:
N M
l_1 r_1
:
l_{N} r_{N}
Output
Print the answer in M lines. The i-th line should contain the maximum number of the kinds of souvenirs that can be purchased if one takes a train stopping every i-th station.
Examples
Input
3 3
1 2
2 3
3 3
Output
3
2
2
Input
7 9
1 7
5 9
5 7
5 9
1 1
6 8
3 4
Output
7
6
6
5
4
5
5
3
2
Submitted Solution:
```
import sys
input = sys.stdin.readline
def main():
n, m = map(int, input().split())
S = [[] for _ in range(m+1)]
for _ in range(n):
l, r = map(int, input().split())
S[r-l+1].append((l, r))
BIT = [0]*(m+2)
def add(i, a):
while i <= m+1:
BIT[i] += a
i += i&(-i)
def bit_sum(i):
res = 0
while i > 0:
res += BIT[i]
i -= i&(-i)
return res
cnt = n
for i in range(1, m+1):
for l, r in S[i]:
cnt -= 1
add(l, 1)
add(r+1, -1)
res = cnt
for j in range(0, m+1, i):
res += bit_sum(j)
print(res)
if __name__ == "__main__":
main()
``` | instruction | 0 | 57,875 | 1 | 115,750 |
Yes | output | 1 | 57,875 | 1 | 115,751 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Snuke has decided to play a game, where the player runs a railway company. There are M+1 stations on Snuke Line, numbered 0 through M. A train on Snuke Line stops at station 0 and every d-th station thereafter, where d is a predetermined constant for each train. For example, if d = 3, the train stops at station 0, 3, 6, 9, and so forth.
There are N kinds of souvenirs sold in areas around Snuke Line. The i-th kind of souvenirs can be purchased when the train stops at one of the following stations: stations l_i, l_i+1, l_i+2, ..., r_i.
There are M values of d, the interval between two stops, for trains on Snuke Line: 1, 2, 3, ..., M. For each of these M values, find the number of the kinds of souvenirs that can be purchased if one takes a train with that value of d at station 0. Here, assume that it is not allowed to change trains.
Constraints
* 1 ≦ N ≦ 3 × 10^{5}
* 1 ≦ M ≦ 10^{5}
* 1 ≦ l_i ≦ r_i ≦ M
Input
The input is given from Standard Input in the following format:
N M
l_1 r_1
:
l_{N} r_{N}
Output
Print the answer in M lines. The i-th line should contain the maximum number of the kinds of souvenirs that can be purchased if one takes a train stopping every i-th station.
Examples
Input
3 3
1 2
2 3
3 3
Output
3
2
2
Input
7 9
1 7
5 9
5 7
5 9
1 1
6 8
3 4
Output
7
6
6
5
4
5
5
3
2
Submitted Solution:
```
from operator import itemgetter
import sys
input = sys.stdin.readline
class BIT:
"""区間加算、一点取得クエリをそれぞれO(logN)で答えるデータ構造"""
def __init__(self, n):
self.n = n
self.bit = [0] * (n + 1)
def _add(self, i, val):
while i > 0:
self.bit[i] += val
i -= i & -i
def get_val(self, i):
"""i番目の値を求める"""
i = i + 1
s = 0
while i <= self.n:
s += self.bit[i]
i += i & -i
return s
def add(self, l, r, val):
"""区間[l, r)にvalを加える"""
self._add(r, val)
self._add(l, -val)
n, m = map(int, input().split())
info = [list(map(int, input().split())) for i in range(n)]
for i in range(n):
info[i] = info[i][0], info[i][1], info[i][1] - info[i][0] + 1
info = sorted(info, key=itemgetter(2))
bit = BIT(m + 1)
l_info = 0
ans = n
res = [0] * m
for d in range(1, m + 1):
while True:
if l_info < n and info[l_info][2] < d:
l, r, _ = info[l_info]
bit.add(l, r + 1, 1)
l_info += 1
ans -= 1
else:
break
cnt = ans
for i in range(0, m + 1, d):
cnt += bit.get_val(i)
res[d - 1] = cnt
print('\n'.join(map(str, res)), end='\n')
``` | instruction | 0 | 57,877 | 1 | 115,754 |
Yes | output | 1 | 57,877 | 1 | 115,755 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Snuke has decided to play a game, where the player runs a railway company. There are M+1 stations on Snuke Line, numbered 0 through M. A train on Snuke Line stops at station 0 and every d-th station thereafter, where d is a predetermined constant for each train. For example, if d = 3, the train stops at station 0, 3, 6, 9, and so forth.
There are N kinds of souvenirs sold in areas around Snuke Line. The i-th kind of souvenirs can be purchased when the train stops at one of the following stations: stations l_i, l_i+1, l_i+2, ..., r_i.
There are M values of d, the interval between two stops, for trains on Snuke Line: 1, 2, 3, ..., M. For each of these M values, find the number of the kinds of souvenirs that can be purchased if one takes a train with that value of d at station 0. Here, assume that it is not allowed to change trains.
Constraints
* 1 ≦ N ≦ 3 × 10^{5}
* 1 ≦ M ≦ 10^{5}
* 1 ≦ l_i ≦ r_i ≦ M
Input
The input is given from Standard Input in the following format:
N M
l_1 r_1
:
l_{N} r_{N}
Output
Print the answer in M lines. The i-th line should contain the maximum number of the kinds of souvenirs that can be purchased if one takes a train stopping every i-th station.
Examples
Input
3 3
1 2
2 3
3 3
Output
3
2
2
Input
7 9
1 7
5 9
5 7
5 9
1 1
6 8
3 4
Output
7
6
6
5
4
5
5
3
2
Submitted Solution:
```
import sys
input = sys.stdin.readline
N, M = map(int, input().split())
NN = (M + 10).bit_length()
BIT=[0]*(2**NN+1)
def addrange(l0, r0, x=1):
l, r = l0, r0
while l <= 2**NN:
BIT[l] += x
l += l & (-l)
while r <= 2**NN:
BIT[r] -= x
r += r & (-r)
def getvalue(r):
a = 0
while r != 0:
a += BIT[r]
r -= r&(-r)
return a
X = []
for _ in range(N):
l, r = map(int, input().split())
X.append((l, r+1))
X = sorted(X, key = lambda x: -(x[1]-x[0]))
for d in range(1, M+1):
while X and X[-1][1] - X[-1][0] < d:
l, r = X.pop()
addrange(l, r)
ans = len(X)
for i in range(d, M+1, d):
ans += getvalue(i)
print(ans)
``` | instruction | 0 | 57,878 | 1 | 115,756 |
Yes | output | 1 | 57,878 | 1 | 115,757 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Snuke has decided to play a game, where the player runs a railway company. There are M+1 stations on Snuke Line, numbered 0 through M. A train on Snuke Line stops at station 0 and every d-th station thereafter, where d is a predetermined constant for each train. For example, if d = 3, the train stops at station 0, 3, 6, 9, and so forth.
There are N kinds of souvenirs sold in areas around Snuke Line. The i-th kind of souvenirs can be purchased when the train stops at one of the following stations: stations l_i, l_i+1, l_i+2, ..., r_i.
There are M values of d, the interval between two stops, for trains on Snuke Line: 1, 2, 3, ..., M. For each of these M values, find the number of the kinds of souvenirs that can be purchased if one takes a train with that value of d at station 0. Here, assume that it is not allowed to change trains.
Constraints
* 1 ≦ N ≦ 3 × 10^{5}
* 1 ≦ M ≦ 10^{5}
* 1 ≦ l_i ≦ r_i ≦ M
Input
The input is given from Standard Input in the following format:
N M
l_1 r_1
:
l_{N} r_{N}
Output
Print the answer in M lines. The i-th line should contain the maximum number of the kinds of souvenirs that can be purchased if one takes a train stopping every i-th station.
Examples
Input
3 3
1 2
2 3
3 3
Output
3
2
2
Input
7 9
1 7
5 9
5 7
5 9
1 1
6 8
3 4
Output
7
6
6
5
4
5
5
3
2
Submitted Solution:
```
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**15
mod = 10**9+7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
class BIT():
def __init__(self, n):
i = 1
while 2**i <= n:
i += 1
self.H = i
self.N = 2**i
self.A = [0] * self.N
def find(self, i):
r = 0
while i:
r += self.A[i]
i -= i & (i-1) ^ i
return r
def update(self, i, x):
while i < self.N:
self.A[i] += x
i += i & (i-1) ^ i
def query(self, a, b):
return self.find(b-1) - self.find(a-1)
def main():
n,m = LI()
d = collections.defaultdict(list)
for _ in range(n):
l,r = LI()
d[r-l+1].append((l,r))
r = [n]
bit = BIT(m+3)
c = n
for i in range(2,m+1):
for a,b in d[i-1]:
c -= 1
bit.update(a,1)
bit.update(b+1,-1)
t = c
for j in range(i,m+1,i):
t += bit.find(j)
r.append(t)
return '\n'.join(map(str,r))
print(main())
``` | instruction | 0 | 57,879 | 1 | 115,758 |
No | output | 1 | 57,879 | 1 | 115,759 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Snuke has decided to play a game, where the player runs a railway company. There are M+1 stations on Snuke Line, numbered 0 through M. A train on Snuke Line stops at station 0 and every d-th station thereafter, where d is a predetermined constant for each train. For example, if d = 3, the train stops at station 0, 3, 6, 9, and so forth.
There are N kinds of souvenirs sold in areas around Snuke Line. The i-th kind of souvenirs can be purchased when the train stops at one of the following stations: stations l_i, l_i+1, l_i+2, ..., r_i.
There are M values of d, the interval between two stops, for trains on Snuke Line: 1, 2, 3, ..., M. For each of these M values, find the number of the kinds of souvenirs that can be purchased if one takes a train with that value of d at station 0. Here, assume that it is not allowed to change trains.
Constraints
* 1 ≦ N ≦ 3 × 10^{5}
* 1 ≦ M ≦ 10^{5}
* 1 ≦ l_i ≦ r_i ≦ M
Input
The input is given from Standard Input in the following format:
N M
l_1 r_1
:
l_{N} r_{N}
Output
Print the answer in M lines. The i-th line should contain the maximum number of the kinds of souvenirs that can be purchased if one takes a train stopping every i-th station.
Examples
Input
3 3
1 2
2 3
3 3
Output
3
2
2
Input
7 9
1 7
5 9
5 7
5 9
1 1
6 8
3 4
Output
7
6
6
5
4
5
5
3
2
Submitted Solution:
```
n, m = map(int, input().split())
res = [0] * m
for t in range(n):
l, r = map(int, input().split())
res = [res[i-1] + (l <= r//i*i) for i in range(1, m+1)]
for v in res:
print(v)
``` | instruction | 0 | 57,880 | 1 | 115,760 |
No | output | 1 | 57,880 | 1 | 115,761 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Snuke has decided to play a game, where the player runs a railway company. There are M+1 stations on Snuke Line, numbered 0 through M. A train on Snuke Line stops at station 0 and every d-th station thereafter, where d is a predetermined constant for each train. For example, if d = 3, the train stops at station 0, 3, 6, 9, and so forth.
There are N kinds of souvenirs sold in areas around Snuke Line. The i-th kind of souvenirs can be purchased when the train stops at one of the following stations: stations l_i, l_i+1, l_i+2, ..., r_i.
There are M values of d, the interval between two stops, for trains on Snuke Line: 1, 2, 3, ..., M. For each of these M values, find the number of the kinds of souvenirs that can be purchased if one takes a train with that value of d at station 0. Here, assume that it is not allowed to change trains.
Constraints
* 1 ≦ N ≦ 3 × 10^{5}
* 1 ≦ M ≦ 10^{5}
* 1 ≦ l_i ≦ r_i ≦ M
Input
The input is given from Standard Input in the following format:
N M
l_1 r_1
:
l_{N} r_{N}
Output
Print the answer in M lines. The i-th line should contain the maximum number of the kinds of souvenirs that can be purchased if one takes a train stopping every i-th station.
Examples
Input
3 3
1 2
2 3
3 3
Output
3
2
2
Input
7 9
1 7
5 9
5 7
5 9
1 1
6 8
3 4
Output
7
6
6
5
4
5
5
3
2
Submitted Solution:
```
# coding: utf-8
# Your code here!
import itertools
class Bit:
def __init__(self, n):
self.size = n
self.tree = [0] * (n + 1)
def sum(self, i):
s = 0
while i > 0:
s += self.tree[i]
i -= i & -i
return s
def add(self, i, x):
while i <= self.size:
self.tree[i] += x
i += i & -i
class RangeUpdate:
def __init__(self, n):
self.p = Bit(n + 1)
self.q = Bit(n + 1)
def add(self, s, t, x):
t += 1
self.p.add(s, -x * s)
self.p.add(t, x * t)
self.q.add(s, x)
self.q.add(t, -x)
def sum(self, s, t):
t += 1
return self.p.sum(t) + self.q.sum(t) * t - \
self.p.sum(s) - self.q.sum(s) * s
n,m = [int(i) for i in input().split()]
lr = [[int(i) for i in input().split()] for _ in range(n)]
lr.sort(key=lambda x: x[1]-x[0])
#print(lr)
omiyage = RangeUpdate(m+1)
index = 0
for d in range(1,m+1):
while(index < n and lr[index][1] - lr[index][0] < d):
omiyage.add(lr[index][0]+1, lr[index][1]+1, 1)
index+=1
ans = 0
pos = 0
while(pos <= m):
ans += omiyage.sum(pos+1,pos+1)
pos += d
ans += n-index
print(ans)
``` | instruction | 0 | 57,881 | 1 | 115,762 |
No | output | 1 | 57,881 | 1 | 115,763 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Snuke has decided to play a game, where the player runs a railway company. There are M+1 stations on Snuke Line, numbered 0 through M. A train on Snuke Line stops at station 0 and every d-th station thereafter, where d is a predetermined constant for each train. For example, if d = 3, the train stops at station 0, 3, 6, 9, and so forth.
There are N kinds of souvenirs sold in areas around Snuke Line. The i-th kind of souvenirs can be purchased when the train stops at one of the following stations: stations l_i, l_i+1, l_i+2, ..., r_i.
There are M values of d, the interval between two stops, for trains on Snuke Line: 1, 2, 3, ..., M. For each of these M values, find the number of the kinds of souvenirs that can be purchased if one takes a train with that value of d at station 0. Here, assume that it is not allowed to change trains.
Constraints
* 1 ≦ N ≦ 3 × 10^{5}
* 1 ≦ M ≦ 10^{5}
* 1 ≦ l_i ≦ r_i ≦ M
Input
The input is given from Standard Input in the following format:
N M
l_1 r_1
:
l_{N} r_{N}
Output
Print the answer in M lines. The i-th line should contain the maximum number of the kinds of souvenirs that can be purchased if one takes a train stopping every i-th station.
Examples
Input
3 3
1 2
2 3
3 3
Output
3
2
2
Input
7 9
1 7
5 9
5 7
5 9
1 1
6 8
3 4
Output
7
6
6
5
4
5
5
3
2
Submitted Solution:
```
from math import sqrt
N, M = map(int, input().split())
D = [0]*(M+2); R = [0]*(M)
for i in range(N):
l, r = map(int, input().split())
D[1] += 1
D[r+1] -= 1
if l <= r-l+1:
continue
D[r-l+2] -= 1
D[l] += 1
left = r-l+2; right = l
for k in range(2, int(sqrt(r))+1):
l0 = max((l+k-1) // k, left); r0 = min((r // k + 1, right))
if l0 < r0:
D[l0] += 1
D[r0] -= 1
right = l0
print(*R, *D)
tmp = 0
for i in range(1, M+1):
tmp += D[i]
R[i-1] += tmp
print(*R, sep='\n')
``` | instruction | 0 | 57,882 | 1 | 115,764 |
No | output | 1 | 57,882 | 1 | 115,765 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are N stations in the city where JOI lives, and they are numbered 1, 2, ..., and N, respectively. In addition, there are M railway lines, numbered 1, 2, ..., and M, respectively. The railway line i (1 \ leq i \ leq M) connects station A_i and station B_i in both directions, and the fare is C_i yen.
JOI lives near station S and attends IOI high school near station T. Therefore, I decided to purchase a commuter pass that connects the two. When purchasing a commuter pass, you must specify one route between station S and station T at the lowest fare. With this commuter pass, you can freely get on and off the railway lines included in the specified route in both directions.
JOI also often uses bookstores near Station U and Station V. Therefore, I wanted to purchase a commuter pass so that the fare for traveling from station U to station V would be as small as possible.
When moving from station U to station V, first select one route from station U to station V. The fare to be paid on the railway line i included in this route is
* If railway line i is included in the route specified when purchasing the commuter pass, 0 yen
* If railway line i is not included in the route specified when purchasing the commuter pass, C_i yen
It becomes. The total of these fares is the fare for traveling from station U to station V.
I would like to find the minimum fare for traveling from station U to station V when the route specified when purchasing a commuter pass is selected successfully.
Task
Create a program to find the minimum fare for traveling from station U to station V when you have successfully selected the route you specify when purchasing a commuter pass.
input
Read the following input from standard input.
* Two integers N and M are written on the first line. These indicate that there are N stations and M railroad lines in the city where JOI lives.
* Two integers S and T are written on the second line. These indicate that JOI purchases a commuter pass from station S to station T.
* Two integers U and V are written on the third line. These indicate that JOI wants to minimize the fare for traveling from station U to station V.
* Three integers A_i, B_i, and C_i are written in the i-th line (1 \ leq i \ leq M) of the following M lines. These indicate that the railway line i connects station A_i and station B_i in both directions, and the fare is C_i yen.
output
Output the minimum fare for traveling from station U to station V on one line to the standard output when the route from station S to station T is properly specified when purchasing a commuter pass.
Limits
All input data satisfy the following conditions.
* 2 \ leq N \ leq 100 000.
* 1 \ leq M \ leq 200 000.
* 1 \ leq S \ leq N.
* 1 \ leq T \ leq N.
* 1 \ leq U \ leq N.
* 1 \ leq V \ leq N.
* S ≠ T.
* U ≠ V.
* S ≠ U or T ≠ V.
* You can reach any other station from any station using one or more railway lines.
* 1 \ leq A_i <B_i \ leq N (1 \ leq i l \ leq M).
* 1 For \ leq i <j \ leq M, A_i ≠ A_j or B_i ≠ B_j.
* 1 \ leq C_i \ leq 1 000 000 000 (1 \ leq i \ leq M).
Input / output example
Input example 1
6 6
1 6
14
1 2 1
2 3 1
3 5 1
2 4 3
4 5 2
5 6 1
Output example 1
2
In this input example, the route that can be specified when buying a commuter pass is limited to the route of station 1-> station 2-> station 3-> station 5-> station 6.
To minimize the fare for traveling from station 1 to station 4, choose the route station 1-> station 2-> station 3-> station 5-> station 4. If you choose this route, the fare to be paid on each railway line is
* 2 yen for railway line 5 connecting station 4 and station 5.
* 0 yen for other railway lines.
Therefore, the total fare is 2 yen.
Input example 2
6 5
1 2
3 6
1 2 1000000000
2 3 1000000000
3 4 1000000000
4 5 1000000000
5 6 1000000000
Output example 2
3000000000
In this input example, the commuter pass is not used to move from station 3 to station 6.
Input example 3
8 8
5 7
6 8
1 2 2
2 3 3
3 4 4
1 4 1
1 5 5
2 6 6
3 7 7
4 8 8
Output example 3
15
Input example 4
5 5
1 5
twenty three
1 2 1
2 3 10
2 4 10
3 5 10
4 5 10
Output example 4
0
Input example 5
10 15
6 8
7 9
2 7 12
8 10 17
1 3 1
3 8 14
5 7 15
2 3 7
1 10 14
3 6 12
1 5 10
8 9 1
2 9 7
1 4 1
1 8 1
2 4 7
5 6 16
Output example 5
19
Creative Commons License
Information Olympics Japan Committee work "17th Japan Information Olympics (JOI 2017/2018) Final Selection"
Example
Input
6 6
1 6
1 4
1 2 1
2 3 1
3 5 1
2 4 3
4 5 2
5 6 1
Output
2
Submitted Solution:
```
from heapq import heappush, heappop
INF = 10 **20
n, m = map(int, input().split())
s, t = map(int, input().split())
s -= 1
t -= 1
u, v = map(int, input().split())
u -= 1
v -= 1
edges = [[] for _ in range(n)]
for _ in range(m):
a, b, c = map(int, input().split())
a -= 1
b -= 1
edges[a].append((b, c))
edges[b].append((a, c))
def dij(start):
que = []
heappush(que, (0, start))
costs = [INF] * n
costs[start] = 0
while que:
total, node = heappop(que)
for to, fee in edges[node]:
if costs[to] > total + fee:
costs[to] = total + fee
heappush(que, (total + fee, to))
return costs
from_u = dij(u)
from_v = dij(v)
que = []
heappush(que, (0, from_u[s], from_v[s], s))
costs = [[INF, INF] for _ in range(n)]
costs[s] = [0, from_u[s] + from_v[s]]
while que:
total, fu, fv, node = heappop(que)
for to, dist in edges[node]:
new_total = total + dist
new_fu = min(fu, from_u[to])
new_fv = min(fv, from_v[to])
if costs[to][0] > new_total:
costs[to] = [new_total, new_fu + new_fv]
heappush(que, (new_total, new_fu, new_fv, to))
elif costs[to][0] == new_total:
costs[to][1] = min(costs[to][1], new_fu + new_fv)
heappush(que, (new_total, new_fu, new_fv, to))
print(min(from_u[v], costs[t][1]))
``` | instruction | 0 | 57,932 | 1 | 115,864 |
No | output | 1 | 57,932 | 1 | 115,865 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are N stations in the city where JOI lives, and they are numbered 1, 2, ..., and N, respectively. In addition, there are M railway lines, numbered 1, 2, ..., and M, respectively. The railway line i (1 \ leq i \ leq M) connects station A_i and station B_i in both directions, and the fare is C_i yen.
JOI lives near station S and attends IOI high school near station T. Therefore, I decided to purchase a commuter pass that connects the two. When purchasing a commuter pass, you must specify one route between station S and station T at the lowest fare. With this commuter pass, you can freely get on and off the railway lines included in the specified route in both directions.
JOI also often uses bookstores near Station U and Station V. Therefore, I wanted to purchase a commuter pass so that the fare for traveling from station U to station V would be as small as possible.
When moving from station U to station V, first select one route from station U to station V. The fare to be paid on the railway line i included in this route is
* If railway line i is included in the route specified when purchasing the commuter pass, 0 yen
* If railway line i is not included in the route specified when purchasing the commuter pass, C_i yen
It becomes. The total of these fares is the fare for traveling from station U to station V.
I would like to find the minimum fare for traveling from station U to station V when the route specified when purchasing a commuter pass is selected successfully.
Task
Create a program to find the minimum fare for traveling from station U to station V when you have successfully selected the route you specify when purchasing a commuter pass.
input
Read the following input from standard input.
* Two integers N and M are written on the first line. These indicate that there are N stations and M railroad lines in the city where JOI lives.
* Two integers S and T are written on the second line. These indicate that JOI purchases a commuter pass from station S to station T.
* Two integers U and V are written on the third line. These indicate that JOI wants to minimize the fare for traveling from station U to station V.
* Three integers A_i, B_i, and C_i are written in the i-th line (1 \ leq i \ leq M) of the following M lines. These indicate that the railway line i connects station A_i and station B_i in both directions, and the fare is C_i yen.
output
Output the minimum fare for traveling from station U to station V on one line to the standard output when the route from station S to station T is properly specified when purchasing a commuter pass.
Limits
All input data satisfy the following conditions.
* 2 \ leq N \ leq 100 000.
* 1 \ leq M \ leq 200 000.
* 1 \ leq S \ leq N.
* 1 \ leq T \ leq N.
* 1 \ leq U \ leq N.
* 1 \ leq V \ leq N.
* S ≠ T.
* U ≠ V.
* S ≠ U or T ≠ V.
* You can reach any other station from any station using one or more railway lines.
* 1 \ leq A_i <B_i \ leq N (1 \ leq i l \ leq M).
* 1 For \ leq i <j \ leq M, A_i ≠ A_j or B_i ≠ B_j.
* 1 \ leq C_i \ leq 1 000 000 000 (1 \ leq i \ leq M).
Input / output example
Input example 1
6 6
1 6
14
1 2 1
2 3 1
3 5 1
2 4 3
4 5 2
5 6 1
Output example 1
2
In this input example, the route that can be specified when buying a commuter pass is limited to the route of station 1-> station 2-> station 3-> station 5-> station 6.
To minimize the fare for traveling from station 1 to station 4, choose the route station 1-> station 2-> station 3-> station 5-> station 4. If you choose this route, the fare to be paid on each railway line is
* 2 yen for railway line 5 connecting station 4 and station 5.
* 0 yen for other railway lines.
Therefore, the total fare is 2 yen.
Input example 2
6 5
1 2
3 6
1 2 1000000000
2 3 1000000000
3 4 1000000000
4 5 1000000000
5 6 1000000000
Output example 2
3000000000
In this input example, the commuter pass is not used to move from station 3 to station 6.
Input example 3
8 8
5 7
6 8
1 2 2
2 3 3
3 4 4
1 4 1
1 5 5
2 6 6
3 7 7
4 8 8
Output example 3
15
Input example 4
5 5
1 5
twenty three
1 2 1
2 3 10
2 4 10
3 5 10
4 5 10
Output example 4
0
Input example 5
10 15
6 8
7 9
2 7 12
8 10 17
1 3 1
3 8 14
5 7 15
2 3 7
1 10 14
3 6 12
1 5 10
8 9 1
2 9 7
1 4 1
1 8 1
2 4 7
5 6 16
Output example 5
19
Creative Commons License
Information Olympics Japan Committee work "17th Japan Information Olympics (JOI 2017/2018) Final Selection"
Example
Input
6 6
1 6
1 4
1 2 1
2 3 1
3 5 1
2 4 3
4 5 2
5 6 1
Output
2
Submitted Solution:
```
from heapq import heappush, heappop
INF = 10 **20
def main():
n, m = map(int, input().split())
s, t = map(int, input().split())
s -= 1
t -= 1
u, v = map(int, input().split())
u -= 1
v -= 1
edges = [[] for _ in range(n)]
for _ in range(m):
a, b, c = map(int, input().split())
a -= 1
b -= 1
edges[a].append((b, c))
edges[b].append((a, c))
def dij(start):
que = []
heappush(que, (0, start))
costs = [INF] * n
costs[start] = 0
while que:
total, node = heappop(que)
for to, fee in edges[node]:
if costs[to] > total + fee:
costs[to] = total + fee
heappush(que, (total + fee, to))
return costs
from_u = dij(u)
from_v = dij(v)
que = []
heappush(que, (0, from_u[s], from_v[s], s))
costs = [INF] * n
costs[s] = 0
ans = INF
while que:
total, fu, fv, node = heappop(que)
for to, dist in edges[node]:
new_total = total + dist
pre_total = costs[to]
if pre_total < new_total:
continue
new_fu = min(fu, from_u[to])
new_fv = min(fv, from_v[to])
new_sum = new_fu + new_fv
if pre_total > new_total:
if to == t:
ans = new_fu + new_fv
costs[to] = new_total
heappush(que, (new_total, new_fu, new_fv, to))
elif pre_total == new_total:
if to == t:
ans = min(ans, new_fu + new_fv)
heappush(que, (new_total, new_fu, new_fv, to))
print(min(from_u[v], ans))
main()
``` | instruction | 0 | 57,933 | 1 | 115,866 |
No | output | 1 | 57,933 | 1 | 115,867 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Some country consists of n cities, connected by a railroad network. The transport communication of the country is so advanced that the network consists of a minimum required number of (n - 1) bidirectional roads (in the other words, the graph of roads is a tree). The i-th road that directly connects cities ai and bi, has the length of li kilometers.
The transport network is served by a state transporting company FRR (Fabulous Rail Roads). In order to simplify the price policy, it offers a single ride fare on the train. In order to follow the route of length t kilometers, you need to pay <image> burles. Note that it is forbidden to split a long route into short segments and pay them separately (a special railroad police, or RRP, controls that the law doesn't get violated).
A Large Software Company decided to organize a programming tournament. Having conducted several online rounds, the company employees determined a list of finalists and sent it to the logistical department to find a place where to conduct finals. The Large Software Company can easily organize the tournament finals in any of the n cities of the country, so the the main factor in choosing the city for the last stage of the tournament is the total cost of buying tickets for all the finalists. We know that the i-th city of the country has wi cup finalists living there.
Help the company employees find the city such that the total cost of travel of all the participants to it is minimum.
Input
The first line of the input contains number n (1 ≤ n ≤ 200 000) — the number of cities in the country.
The next line contains n integers w1, w2, ..., wn (0 ≤ wi ≤ 108) — the number of finalists living in each city of the country.
Next (n - 1) lines contain the descriptions of the railroad, the i-th line contains three integers, ai, bi, li (1 ≤ ai, bi ≤ n, ai ≠ bi, 1 ≤ li ≤ 1000).
Output
Print two numbers — an integer f that is the number of the optimal city to conduct the competition, and the real number c, equal to the minimum total cost of transporting all the finalists to the competition. Your answer will be considered correct if two conditions are fulfilled at the same time:
1. The absolute or relative error of the printed number c in comparison with the cost of setting up a final in city f doesn't exceed 10 - 6;
2. Absolute or relative error of the printed number c in comparison to the answer of the jury doesn't exceed 10 - 6.
If there are multiple answers, you are allowed to print any of them.
Examples
Input
5
3 1 2 6 5
1 2 3
2 3 1
4 3 9
5 3 1
Output
3 192.0
Input
2
5 5
1 2 2
Output
1 14.142135623730951000
Note
In the sample test an optimal variant of choosing a city to conduct the finals of the competition is 3. At such choice the cost of conducting is <image> burles.
In the second sample test, whatever city you would choose, you will need to pay for the transport for five participants, so you will need to pay <image> burles for each one of them.
Submitted Solution:
```
#encoding:utf-8
import math
def cntDis(findTo, self, newMap, fromI, level):
nextLevelL = []
lineMade = 0.0
if (level+1) > len(newMap) :
return 0
level = level + 1
for lineOneL in newMap[str(self)]:
if int(findTo) == int(lineOneL[0]) :
lineMade = lineMade + int(lineOneL[1])
return lineMade
elif lineOneL[0] != fromI:
nextLevelL.append(lineOneL)
for lineOneInt in nextLevelL :
if self != lineOneInt :
lineMade = cntDis(findTo, lineOneInt[0], newMap, self, level)
if lineMade != None and lineMade != 0:
lineMade = lineMade + int(lineOneInt[1])
return lineMade
lines = input()
wS = input()
wList = wS.split()
linesCnt = int(lines) - 1
linesList = []
newMap = {}
for theLine in range(linesCnt):
inStr = input()
info = inStr.split()
linesList.append(info)
tmp0 = [info[1], info[2]]
tmp1 = [info[0], info[2]]
if info[0] in newMap.keys():
newMap[info[0]].append(tmp0)
else:
newMap[info[0]] = [tmp0]
if info[1] in newMap.keys():
newMap[info[1]].append(tmp1)
else:
newMap[info[1]] = [tmp1]
total = -1
countF = -1
saveDis = {}
for x in range(linesCnt + 1) :
costsX = 0.0
for y in range(linesCnt + 1) :
if y!=x and (str(y+1)+'-'+str(x+1)) in saveDis.keys():
distance = saveDis[str(y+1)+'-'+str(x+1)]
costOne = pow(distance, 1.5) * int(wList[y])
costsX = costsX + costOne
elif y != x :
distance = cntDis(x+1, y+1, newMap, 0, 0)
costOne = pow(distance, 1.5) * int(wList[y])
costsX = costsX + costOne
if x < y:
saveDis[str(x+1)+'-'+str(y+1)] = distance
if total == -1 or total > costsX:
total = costsX
countF = x
print (countF+1, total)
``` | instruction | 0 | 58,450 | 1 | 116,900 |
No | output | 1 | 58,450 | 1 | 116,901 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Some country consists of n cities, connected by a railroad network. The transport communication of the country is so advanced that the network consists of a minimum required number of (n - 1) bidirectional roads (in the other words, the graph of roads is a tree). The i-th road that directly connects cities ai and bi, has the length of li kilometers.
The transport network is served by a state transporting company FRR (Fabulous Rail Roads). In order to simplify the price policy, it offers a single ride fare on the train. In order to follow the route of length t kilometers, you need to pay <image> burles. Note that it is forbidden to split a long route into short segments and pay them separately (a special railroad police, or RRP, controls that the law doesn't get violated).
A Large Software Company decided to organize a programming tournament. Having conducted several online rounds, the company employees determined a list of finalists and sent it to the logistical department to find a place where to conduct finals. The Large Software Company can easily organize the tournament finals in any of the n cities of the country, so the the main factor in choosing the city for the last stage of the tournament is the total cost of buying tickets for all the finalists. We know that the i-th city of the country has wi cup finalists living there.
Help the company employees find the city such that the total cost of travel of all the participants to it is minimum.
Input
The first line of the input contains number n (1 ≤ n ≤ 200 000) — the number of cities in the country.
The next line contains n integers w1, w2, ..., wn (0 ≤ wi ≤ 108) — the number of finalists living in each city of the country.
Next (n - 1) lines contain the descriptions of the railroad, the i-th line contains three integers, ai, bi, li (1 ≤ ai, bi ≤ n, ai ≠ bi, 1 ≤ li ≤ 1000).
Output
Print two numbers — an integer f that is the number of the optimal city to conduct the competition, and the real number c, equal to the minimum total cost of transporting all the finalists to the competition. Your answer will be considered correct if two conditions are fulfilled at the same time:
1. The absolute or relative error of the printed number c in comparison with the cost of setting up a final in city f doesn't exceed 10 - 6;
2. Absolute or relative error of the printed number c in comparison to the answer of the jury doesn't exceed 10 - 6.
If there are multiple answers, you are allowed to print any of them.
Examples
Input
5
3 1 2 6 5
1 2 3
2 3 1
4 3 9
5 3 1
Output
3 192.0
Input
2
5 5
1 2 2
Output
1 14.142135623730951000
Note
In the sample test an optimal variant of choosing a city to conduct the finals of the competition is 3. At such choice the cost of conducting is <image> burles.
In the second sample test, whatever city you would choose, you will need to pay for the transport for five participants, so you will need to pay <image> burles for each one of them.
Submitted Solution:
```
#encoding:utf-8
import math
def cntDis(findTo, self, newMap, fromI, level):
nextLevelL = []
lineMade = 0.0
if (level+1) > len(newMap) :
return 0
level = level + 1
if findTo in newMap[self].keys():
return (lineMade + newMap[self][findTo])
else:
for eKey in newMap[self].keys():
if eKey != fromI:
print (findTo, eKey)
tmp = cntDis(findTo, eKey, newMap, self, level)
if tmp != 0:
return (newMap[self][eKey] + tmp)
return 0
lines = input()
wS = input()
wList = wS.split()
linesCnt = int(lines) - 1
linesList = []
newMap = {}
for theLine in range(linesCnt):
inStr = input()
info = inStr.split()
linesList.append(info)
if int(info[0]) not in newMap.keys():
newMap[int(info[0])] = {}
if int(info[1]) not in newMap.keys():
newMap[int(info[1])] = {}
newMap[int(info[0])][int(info[1])] = int(info[2])
newMap[int(info[1])][int(info[0])] = int(info[2])
print (newMap)
total = -1
countF = -1
saveDis = {}
for x in range(1, int(lines)+1):
costX = 0.0
for fromId in range(1, int(lines)+1):
if x != fromId:
if x < fromId:
distance = cntDis(x, fromId, newMap, 0, 0)
costOne = pow(distance, 1.5) * int(wList[fromId-1])
saveDis[str(x)+','+str(fromId)] = distance
else:
distance = saveDis[str(fromId)+','+str(x)]
costOne = pow(distance, 1.5) * int(wList[fromId-1])
costX = costX + costOne
if (total == -1) or (total > costX):
total = costX
countF = x
print (countF, total)
``` | instruction | 0 | 58,451 | 1 | 116,902 |
No | output | 1 | 58,451 | 1 | 116,903 |
Provide tags and a correct Python 3 solution for this coding contest problem.
And while Mishka is enjoying her trip...
Chris is a little brown bear. No one knows, where and when he met Mishka, but for a long time they are together (excluding her current trip). However, best friends are important too. John is Chris' best friend.
Once walking with his friend, John gave Chris the following problem:
At the infinite horizontal road of width w, bounded by lines y = 0 and y = w, there is a bus moving, presented as a convex polygon of n vertices. The bus moves continuously with a constant speed of v in a straight Ox line in direction of decreasing x coordinates, thus in time only x coordinates of its points are changing. Formally, after time t each of x coordinates of its points will be decreased by vt.
There is a pedestrian in the point (0, 0), who can move only by a vertical pedestrian crossing, presented as a segment connecting points (0, 0) and (0, w) with any speed not exceeding u. Thus the pedestrian can move only in a straight line Oy in any direction with any speed not exceeding u and not leaving the road borders. The pedestrian can instantly change his speed, thus, for example, he can stop instantly.
Please look at the sample note picture for better understanding.
We consider the pedestrian is hit by the bus, if at any moment the point he is located in lies strictly inside the bus polygon (this means that if the point lies on the polygon vertex or on its edge, the pedestrian is not hit by the bus).
You are given the bus position at the moment 0. Please help Chris determine minimum amount of time the pedestrian needs to cross the road and reach the point (0, w) and not to be hit by the bus.
Input
The first line of the input contains four integers n, w, v, u (3 ≤ n ≤ 10 000, 1 ≤ w ≤ 109, 1 ≤ v, u ≤ 1000) — the number of the bus polygon vertices, road width, bus speed and pedestrian speed respectively.
The next n lines describes polygon vertices in counter-clockwise order. i-th of them contains pair of integers xi and yi ( - 109 ≤ xi ≤ 109, 0 ≤ yi ≤ w) — coordinates of i-th polygon point. It is guaranteed that the polygon is non-degenerate.
Output
Print the single real t — the time the pedestrian needs to croos the road and not to be hit by the bus. The answer is considered correct if its relative or absolute error doesn't exceed 10 - 6.
Example
Input
5 5 1 2
1 2
3 1
4 3
3 4
1 4
Output
5.0000000000
Note
Following image describes initial position in the first sample case:
<image> | instruction | 0 | 58,501 | 1 | 117,002 |
Tags: geometry, implementation
Correct Solution:
```
f = lambda: map(int, input().split())
n, w, v, u = f()
k = t = 0
v /= u
for i in range(n):
x, y = f()
d = x / v - y
k |= d < 0
t = max(t, d)
if k: w += t
print(w / u)
``` | output | 1 | 58,501 | 1 | 117,003 |
Provide tags and a correct Python 3 solution for this coding contest problem.
And while Mishka is enjoying her trip...
Chris is a little brown bear. No one knows, where and when he met Mishka, but for a long time they are together (excluding her current trip). However, best friends are important too. John is Chris' best friend.
Once walking with his friend, John gave Chris the following problem:
At the infinite horizontal road of width w, bounded by lines y = 0 and y = w, there is a bus moving, presented as a convex polygon of n vertices. The bus moves continuously with a constant speed of v in a straight Ox line in direction of decreasing x coordinates, thus in time only x coordinates of its points are changing. Formally, after time t each of x coordinates of its points will be decreased by vt.
There is a pedestrian in the point (0, 0), who can move only by a vertical pedestrian crossing, presented as a segment connecting points (0, 0) and (0, w) with any speed not exceeding u. Thus the pedestrian can move only in a straight line Oy in any direction with any speed not exceeding u and not leaving the road borders. The pedestrian can instantly change his speed, thus, for example, he can stop instantly.
Please look at the sample note picture for better understanding.
We consider the pedestrian is hit by the bus, if at any moment the point he is located in lies strictly inside the bus polygon (this means that if the point lies on the polygon vertex or on its edge, the pedestrian is not hit by the bus).
You are given the bus position at the moment 0. Please help Chris determine minimum amount of time the pedestrian needs to cross the road and reach the point (0, w) and not to be hit by the bus.
Input
The first line of the input contains four integers n, w, v, u (3 ≤ n ≤ 10 000, 1 ≤ w ≤ 109, 1 ≤ v, u ≤ 1000) — the number of the bus polygon vertices, road width, bus speed and pedestrian speed respectively.
The next n lines describes polygon vertices in counter-clockwise order. i-th of them contains pair of integers xi and yi ( - 109 ≤ xi ≤ 109, 0 ≤ yi ≤ w) — coordinates of i-th polygon point. It is guaranteed that the polygon is non-degenerate.
Output
Print the single real t — the time the pedestrian needs to croos the road and not to be hit by the bus. The answer is considered correct if its relative or absolute error doesn't exceed 10 - 6.
Example
Input
5 5 1 2
1 2
3 1
4 3
3 4
1 4
Output
5.0000000000
Note
Following image describes initial position in the first sample case:
<image> | instruction | 0 | 58,502 | 1 | 117,004 |
Tags: geometry, implementation
Correct Solution:
```
n, w, v, u = map(int, input().split())
ans = 0
flag1 = 0
flag2 = 0
for i in range(n):
x, y = map(int, input().split())
if x/v < y/u:
flag1 = 1
if x/v > y/u:
flag2 = 1
ans = max(ans, x/v+(w-y)/u)
if flag1+flag2 == 2:
print(ans)
else:
print(w/u)
``` | output | 1 | 58,502 | 1 | 117,005 |
Provide tags and a correct Python 3 solution for this coding contest problem.
And while Mishka is enjoying her trip...
Chris is a little brown bear. No one knows, where and when he met Mishka, but for a long time they are together (excluding her current trip). However, best friends are important too. John is Chris' best friend.
Once walking with his friend, John gave Chris the following problem:
At the infinite horizontal road of width w, bounded by lines y = 0 and y = w, there is a bus moving, presented as a convex polygon of n vertices. The bus moves continuously with a constant speed of v in a straight Ox line in direction of decreasing x coordinates, thus in time only x coordinates of its points are changing. Formally, after time t each of x coordinates of its points will be decreased by vt.
There is a pedestrian in the point (0, 0), who can move only by a vertical pedestrian crossing, presented as a segment connecting points (0, 0) and (0, w) with any speed not exceeding u. Thus the pedestrian can move only in a straight line Oy in any direction with any speed not exceeding u and not leaving the road borders. The pedestrian can instantly change his speed, thus, for example, he can stop instantly.
Please look at the sample note picture for better understanding.
We consider the pedestrian is hit by the bus, if at any moment the point he is located in lies strictly inside the bus polygon (this means that if the point lies on the polygon vertex or on its edge, the pedestrian is not hit by the bus).
You are given the bus position at the moment 0. Please help Chris determine minimum amount of time the pedestrian needs to cross the road and reach the point (0, w) and not to be hit by the bus.
Input
The first line of the input contains four integers n, w, v, u (3 ≤ n ≤ 10 000, 1 ≤ w ≤ 109, 1 ≤ v, u ≤ 1000) — the number of the bus polygon vertices, road width, bus speed and pedestrian speed respectively.
The next n lines describes polygon vertices in counter-clockwise order. i-th of them contains pair of integers xi and yi ( - 109 ≤ xi ≤ 109, 0 ≤ yi ≤ w) — coordinates of i-th polygon point. It is guaranteed that the polygon is non-degenerate.
Output
Print the single real t — the time the pedestrian needs to croos the road and not to be hit by the bus. The answer is considered correct if its relative or absolute error doesn't exceed 10 - 6.
Example
Input
5 5 1 2
1 2
3 1
4 3
3 4
1 4
Output
5.0000000000
Note
Following image describes initial position in the first sample case:
<image> | instruction | 0 | 58,503 | 1 | 117,006 |
Tags: geometry, implementation
Correct Solution:
```
n,w,v,u = map(int,input().split())
maxwait=0.0
curr=1;
for i in range(n):
x,y = map(int,input().split())
maxwait=max(maxwait,x/v-y/u)
if(x/v<y/u):
curr=0
if(curr==1):
maxwait=0
print (w/u + maxwait)
``` | output | 1 | 58,503 | 1 | 117,007 |
Provide tags and a correct Python 3 solution for this coding contest problem.
And while Mishka is enjoying her trip...
Chris is a little brown bear. No one knows, where and when he met Mishka, but for a long time they are together (excluding her current trip). However, best friends are important too. John is Chris' best friend.
Once walking with his friend, John gave Chris the following problem:
At the infinite horizontal road of width w, bounded by lines y = 0 and y = w, there is a bus moving, presented as a convex polygon of n vertices. The bus moves continuously with a constant speed of v in a straight Ox line in direction of decreasing x coordinates, thus in time only x coordinates of its points are changing. Formally, after time t each of x coordinates of its points will be decreased by vt.
There is a pedestrian in the point (0, 0), who can move only by a vertical pedestrian crossing, presented as a segment connecting points (0, 0) and (0, w) with any speed not exceeding u. Thus the pedestrian can move only in a straight line Oy in any direction with any speed not exceeding u and not leaving the road borders. The pedestrian can instantly change his speed, thus, for example, he can stop instantly.
Please look at the sample note picture for better understanding.
We consider the pedestrian is hit by the bus, if at any moment the point he is located in lies strictly inside the bus polygon (this means that if the point lies on the polygon vertex or on its edge, the pedestrian is not hit by the bus).
You are given the bus position at the moment 0. Please help Chris determine minimum amount of time the pedestrian needs to cross the road and reach the point (0, w) and not to be hit by the bus.
Input
The first line of the input contains four integers n, w, v, u (3 ≤ n ≤ 10 000, 1 ≤ w ≤ 109, 1 ≤ v, u ≤ 1000) — the number of the bus polygon vertices, road width, bus speed and pedestrian speed respectively.
The next n lines describes polygon vertices in counter-clockwise order. i-th of them contains pair of integers xi and yi ( - 109 ≤ xi ≤ 109, 0 ≤ yi ≤ w) — coordinates of i-th polygon point. It is guaranteed that the polygon is non-degenerate.
Output
Print the single real t — the time the pedestrian needs to croos the road and not to be hit by the bus. The answer is considered correct if its relative or absolute error doesn't exceed 10 - 6.
Example
Input
5 5 1 2
1 2
3 1
4 3
3 4
1 4
Output
5.0000000000
Note
Following image describes initial position in the first sample case:
<image> | instruction | 0 | 58,504 | 1 | 117,008 |
Tags: geometry, implementation
Correct Solution:
```
import sys
def main():
n,w,v,u = list(map(int, sys.stdin.readline().split()))
c = []
for i in range(n):
c.append(list(map(int, sys.stdin.readline().split())))
ymin = 10**9+1
iymin = 0
ymax = -1
iymax = 0
xmax = -1
ixmax = 0
for i in range(n):
if c[i][1]<ymin:
ymin = c[i][1]
iymin = i
if c[i][1]>ymax:
ymax = c[i][1]
iymax = i
if c[i][0]>xmax:
xmax = c[i][0]
ixmax = i
jmin = (iymin-1+n)%n
while ymin==c[jmin][1]:
jmin = (jmin-1+n)%n
iymin = (jmin+1)%n
jmax = (iymax+1)%n
while ymax==c[jmax][1]:
jmax = (jmax+1)%n
iymax = (jmax-1+n)%n
jcur = iymin
ok = True
finish = (iymax-1+n)%n
while jcur != finish:
ta = c[jcur][0]/v
if ta < c[jcur][1]/u:
ok = False
break
jcur= (jcur-1+n)%n
if ok:
print("%.8f" % (w/u))
return
jmin = (iymin+1)%n
while ymin==c[jmin][1]:
jmin = (jmin+1)%n
iymin = (jmin-1+n)%n
jmax = (ixmax+1)%n
while xmax==c[jmax][0]:
jmax = (jmax+1)%n
ixmax = (jmax-1+n)%n
t = 0
jcur = iymin
cury = 0
finish = (ixmax+1)%n
while jcur != finish:
l = c[jcur][1]-cury
ta = c[jcur][0]/v
tp = l/u
t= max(t+tp,ta)
cury+=l
jcur= (jcur+1)%n
t+= (w-cury)/u
print("%.8f" % t)
main()
``` | output | 1 | 58,504 | 1 | 117,009 |
Provide tags and a correct Python 3 solution for this coding contest problem.
And while Mishka is enjoying her trip...
Chris is a little brown bear. No one knows, where and when he met Mishka, but for a long time they are together (excluding her current trip). However, best friends are important too. John is Chris' best friend.
Once walking with his friend, John gave Chris the following problem:
At the infinite horizontal road of width w, bounded by lines y = 0 and y = w, there is a bus moving, presented as a convex polygon of n vertices. The bus moves continuously with a constant speed of v in a straight Ox line in direction of decreasing x coordinates, thus in time only x coordinates of its points are changing. Formally, after time t each of x coordinates of its points will be decreased by vt.
There is a pedestrian in the point (0, 0), who can move only by a vertical pedestrian crossing, presented as a segment connecting points (0, 0) and (0, w) with any speed not exceeding u. Thus the pedestrian can move only in a straight line Oy in any direction with any speed not exceeding u and not leaving the road borders. The pedestrian can instantly change his speed, thus, for example, he can stop instantly.
Please look at the sample note picture for better understanding.
We consider the pedestrian is hit by the bus, if at any moment the point he is located in lies strictly inside the bus polygon (this means that if the point lies on the polygon vertex or on its edge, the pedestrian is not hit by the bus).
You are given the bus position at the moment 0. Please help Chris determine minimum amount of time the pedestrian needs to cross the road and reach the point (0, w) and not to be hit by the bus.
Input
The first line of the input contains four integers n, w, v, u (3 ≤ n ≤ 10 000, 1 ≤ w ≤ 109, 1 ≤ v, u ≤ 1000) — the number of the bus polygon vertices, road width, bus speed and pedestrian speed respectively.
The next n lines describes polygon vertices in counter-clockwise order. i-th of them contains pair of integers xi and yi ( - 109 ≤ xi ≤ 109, 0 ≤ yi ≤ w) — coordinates of i-th polygon point. It is guaranteed that the polygon is non-degenerate.
Output
Print the single real t — the time the pedestrian needs to croos the road and not to be hit by the bus. The answer is considered correct if its relative or absolute error doesn't exceed 10 - 6.
Example
Input
5 5 1 2
1 2
3 1
4 3
3 4
1 4
Output
5.0000000000
Note
Following image describes initial position in the first sample case:
<image> | instruction | 0 | 58,505 | 1 | 117,010 |
Tags: geometry, implementation
Correct Solution:
```
class vec(object):
def __init__(self, x, y):
self.x, self.y = x, y
def cross(self, k):
return self.x * k.y - self.y * k.x
def dot(self, k):
return self.x * k.x + self.y * k.y
def __sub__(self, k):
return vec(self.x - k.x, self.y - k.y)
n, w, v, u = map(int, input().split(' '))
p = vec(v, u)
l = [vec(*map(int, input().split(' '))) for _ in range(n)]
b, c = 0, 0
for i in l:
if p.cross(i) <= 0:
c += 1
if p.cross(i) >= 0:
b += 1
if b == n or c == n:
print('%.8f' % (w / u))
exit(0)
r = [l[(i + 1) % n] - l[i] for i in range(n)]
i = 0
while p.cross(r[i % n]) > 0:
i += 1
while p.cross(r[i % n]) < 0:
i += 1
i %= n
b = (l[i].cross(p) + v * w) / u / v
print('%.8f' % b)
``` | output | 1 | 58,505 | 1 | 117,011 |
Provide tags and a correct Python 3 solution for this coding contest problem.
And while Mishka is enjoying her trip...
Chris is a little brown bear. No one knows, where and when he met Mishka, but for a long time they are together (excluding her current trip). However, best friends are important too. John is Chris' best friend.
Once walking with his friend, John gave Chris the following problem:
At the infinite horizontal road of width w, bounded by lines y = 0 and y = w, there is a bus moving, presented as a convex polygon of n vertices. The bus moves continuously with a constant speed of v in a straight Ox line in direction of decreasing x coordinates, thus in time only x coordinates of its points are changing. Formally, after time t each of x coordinates of its points will be decreased by vt.
There is a pedestrian in the point (0, 0), who can move only by a vertical pedestrian crossing, presented as a segment connecting points (0, 0) and (0, w) with any speed not exceeding u. Thus the pedestrian can move only in a straight line Oy in any direction with any speed not exceeding u and not leaving the road borders. The pedestrian can instantly change his speed, thus, for example, he can stop instantly.
Please look at the sample note picture for better understanding.
We consider the pedestrian is hit by the bus, if at any moment the point he is located in lies strictly inside the bus polygon (this means that if the point lies on the polygon vertex or on its edge, the pedestrian is not hit by the bus).
You are given the bus position at the moment 0. Please help Chris determine minimum amount of time the pedestrian needs to cross the road and reach the point (0, w) and not to be hit by the bus.
Input
The first line of the input contains four integers n, w, v, u (3 ≤ n ≤ 10 000, 1 ≤ w ≤ 109, 1 ≤ v, u ≤ 1000) — the number of the bus polygon vertices, road width, bus speed and pedestrian speed respectively.
The next n lines describes polygon vertices in counter-clockwise order. i-th of them contains pair of integers xi and yi ( - 109 ≤ xi ≤ 109, 0 ≤ yi ≤ w) — coordinates of i-th polygon point. It is guaranteed that the polygon is non-degenerate.
Output
Print the single real t — the time the pedestrian needs to croos the road and not to be hit by the bus. The answer is considered correct if its relative or absolute error doesn't exceed 10 - 6.
Example
Input
5 5 1 2
1 2
3 1
4 3
3 4
1 4
Output
5.0000000000
Note
Following image describes initial position in the first sample case:
<image> | instruction | 0 | 58,506 | 1 | 117,012 |
Tags: geometry, implementation
Correct Solution:
```
n,w,v,u=map(int,input().split())
x,y=list(map(int,input().split()))
razn=ozhid=v*y-x*u
for i in range(1,n):
x,y=map(int,input().split())
r=v*y-x*u
if r>razn:
razn=r
if r<ozhid:
ozhid=r
if ozhid>=0 or razn<=0:
print(w/u)
else:
print(w/u-ozhid/(u*v))
``` | output | 1 | 58,506 | 1 | 117,013 |
Provide tags and a correct Python 3 solution for this coding contest problem.
And while Mishka is enjoying her trip...
Chris is a little brown bear. No one knows, where and when he met Mishka, but for a long time they are together (excluding her current trip). However, best friends are important too. John is Chris' best friend.
Once walking with his friend, John gave Chris the following problem:
At the infinite horizontal road of width w, bounded by lines y = 0 and y = w, there is a bus moving, presented as a convex polygon of n vertices. The bus moves continuously with a constant speed of v in a straight Ox line in direction of decreasing x coordinates, thus in time only x coordinates of its points are changing. Formally, after time t each of x coordinates of its points will be decreased by vt.
There is a pedestrian in the point (0, 0), who can move only by a vertical pedestrian crossing, presented as a segment connecting points (0, 0) and (0, w) with any speed not exceeding u. Thus the pedestrian can move only in a straight line Oy in any direction with any speed not exceeding u and not leaving the road borders. The pedestrian can instantly change his speed, thus, for example, he can stop instantly.
Please look at the sample note picture for better understanding.
We consider the pedestrian is hit by the bus, if at any moment the point he is located in lies strictly inside the bus polygon (this means that if the point lies on the polygon vertex or on its edge, the pedestrian is not hit by the bus).
You are given the bus position at the moment 0. Please help Chris determine minimum amount of time the pedestrian needs to cross the road and reach the point (0, w) and not to be hit by the bus.
Input
The first line of the input contains four integers n, w, v, u (3 ≤ n ≤ 10 000, 1 ≤ w ≤ 109, 1 ≤ v, u ≤ 1000) — the number of the bus polygon vertices, road width, bus speed and pedestrian speed respectively.
The next n lines describes polygon vertices in counter-clockwise order. i-th of them contains pair of integers xi and yi ( - 109 ≤ xi ≤ 109, 0 ≤ yi ≤ w) — coordinates of i-th polygon point. It is guaranteed that the polygon is non-degenerate.
Output
Print the single real t — the time the pedestrian needs to croos the road and not to be hit by the bus. The answer is considered correct if its relative or absolute error doesn't exceed 10 - 6.
Example
Input
5 5 1 2
1 2
3 1
4 3
3 4
1 4
Output
5.0000000000
Note
Following image describes initial position in the first sample case:
<image> | instruction | 0 | 58,507 | 1 | 117,014 |
Tags: geometry, implementation
Correct Solution:
```
n, w, v, u = map(int, input().split())
max_t_w = 0
flag = True
for i in range(n):
x, y = map(int, input().split())
max_t_w = max(max_t_w, x / v - y / u)
if x / v < y / u:
flag = False
if flag:
max_t_w = 0
print(w / u + max_t_w)
``` | output | 1 | 58,507 | 1 | 117,015 |
Provide tags and a correct Python 3 solution for this coding contest problem.
And while Mishka is enjoying her trip...
Chris is a little brown bear. No one knows, where and when he met Mishka, but for a long time they are together (excluding her current trip). However, best friends are important too. John is Chris' best friend.
Once walking with his friend, John gave Chris the following problem:
At the infinite horizontal road of width w, bounded by lines y = 0 and y = w, there is a bus moving, presented as a convex polygon of n vertices. The bus moves continuously with a constant speed of v in a straight Ox line in direction of decreasing x coordinates, thus in time only x coordinates of its points are changing. Formally, after time t each of x coordinates of its points will be decreased by vt.
There is a pedestrian in the point (0, 0), who can move only by a vertical pedestrian crossing, presented as a segment connecting points (0, 0) and (0, w) with any speed not exceeding u. Thus the pedestrian can move only in a straight line Oy in any direction with any speed not exceeding u and not leaving the road borders. The pedestrian can instantly change his speed, thus, for example, he can stop instantly.
Please look at the sample note picture for better understanding.
We consider the pedestrian is hit by the bus, if at any moment the point he is located in lies strictly inside the bus polygon (this means that if the point lies on the polygon vertex or on its edge, the pedestrian is not hit by the bus).
You are given the bus position at the moment 0. Please help Chris determine minimum amount of time the pedestrian needs to cross the road and reach the point (0, w) and not to be hit by the bus.
Input
The first line of the input contains four integers n, w, v, u (3 ≤ n ≤ 10 000, 1 ≤ w ≤ 109, 1 ≤ v, u ≤ 1000) — the number of the bus polygon vertices, road width, bus speed and pedestrian speed respectively.
The next n lines describes polygon vertices in counter-clockwise order. i-th of them contains pair of integers xi and yi ( - 109 ≤ xi ≤ 109, 0 ≤ yi ≤ w) — coordinates of i-th polygon point. It is guaranteed that the polygon is non-degenerate.
Output
Print the single real t — the time the pedestrian needs to croos the road and not to be hit by the bus. The answer is considered correct if its relative or absolute error doesn't exceed 10 - 6.
Example
Input
5 5 1 2
1 2
3 1
4 3
3 4
1 4
Output
5.0000000000
Note
Following image describes initial position in the first sample case:
<image> | instruction | 0 | 58,508 | 1 | 117,016 |
Tags: geometry, implementation
Correct Solution:
```
import sys
input = sys.stdin.readline
def solve():
n, w, v, u = map(int, input().split())
mx = int(1e13)
Mx = int(-1e13)
for i in range(n):
x, y = map(int, input().split())
xx = x * u - v * y
mx = min(mx, xx)
Mx = max(Mx, xx)
if mx >= 0 or Mx <= 0:
print(w/u)
else:
print((Mx+w*v)/(v*u))
solve()
``` | output | 1 | 58,508 | 1 | 117,017 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
And while Mishka is enjoying her trip...
Chris is a little brown bear. No one knows, where and when he met Mishka, but for a long time they are together (excluding her current trip). However, best friends are important too. John is Chris' best friend.
Once walking with his friend, John gave Chris the following problem:
At the infinite horizontal road of width w, bounded by lines y = 0 and y = w, there is a bus moving, presented as a convex polygon of n vertices. The bus moves continuously with a constant speed of v in a straight Ox line in direction of decreasing x coordinates, thus in time only x coordinates of its points are changing. Formally, after time t each of x coordinates of its points will be decreased by vt.
There is a pedestrian in the point (0, 0), who can move only by a vertical pedestrian crossing, presented as a segment connecting points (0, 0) and (0, w) with any speed not exceeding u. Thus the pedestrian can move only in a straight line Oy in any direction with any speed not exceeding u and not leaving the road borders. The pedestrian can instantly change his speed, thus, for example, he can stop instantly.
Please look at the sample note picture for better understanding.
We consider the pedestrian is hit by the bus, if at any moment the point he is located in lies strictly inside the bus polygon (this means that if the point lies on the polygon vertex or on its edge, the pedestrian is not hit by the bus).
You are given the bus position at the moment 0. Please help Chris determine minimum amount of time the pedestrian needs to cross the road and reach the point (0, w) and not to be hit by the bus.
Input
The first line of the input contains four integers n, w, v, u (3 ≤ n ≤ 10 000, 1 ≤ w ≤ 109, 1 ≤ v, u ≤ 1000) — the number of the bus polygon vertices, road width, bus speed and pedestrian speed respectively.
The next n lines describes polygon vertices in counter-clockwise order. i-th of them contains pair of integers xi and yi ( - 109 ≤ xi ≤ 109, 0 ≤ yi ≤ w) — coordinates of i-th polygon point. It is guaranteed that the polygon is non-degenerate.
Output
Print the single real t — the time the pedestrian needs to croos the road and not to be hit by the bus. The answer is considered correct if its relative or absolute error doesn't exceed 10 - 6.
Example
Input
5 5 1 2
1 2
3 1
4 3
3 4
1 4
Output
5.0000000000
Note
Following image describes initial position in the first sample case:
<image>
Submitted Solution:
```
n, w, v, u = map(int, input().split())
maxwait = 0.0
curr = True
for i in range(n):
x, y = map(int, input().split())
maxwait = max(maxwait, x / v - y / u)
if x / v < y / u:
curr = False
if curr:
maxwait = 0
print(w / u + maxwait)
``` | instruction | 0 | 58,509 | 1 | 117,018 |
Yes | output | 1 | 58,509 | 1 | 117,019 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
And while Mishka is enjoying her trip...
Chris is a little brown bear. No one knows, where and when he met Mishka, but for a long time they are together (excluding her current trip). However, best friends are important too. John is Chris' best friend.
Once walking with his friend, John gave Chris the following problem:
At the infinite horizontal road of width w, bounded by lines y = 0 and y = w, there is a bus moving, presented as a convex polygon of n vertices. The bus moves continuously with a constant speed of v in a straight Ox line in direction of decreasing x coordinates, thus in time only x coordinates of its points are changing. Formally, after time t each of x coordinates of its points will be decreased by vt.
There is a pedestrian in the point (0, 0), who can move only by a vertical pedestrian crossing, presented as a segment connecting points (0, 0) and (0, w) with any speed not exceeding u. Thus the pedestrian can move only in a straight line Oy in any direction with any speed not exceeding u and not leaving the road borders. The pedestrian can instantly change his speed, thus, for example, he can stop instantly.
Please look at the sample note picture for better understanding.
We consider the pedestrian is hit by the bus, if at any moment the point he is located in lies strictly inside the bus polygon (this means that if the point lies on the polygon vertex or on its edge, the pedestrian is not hit by the bus).
You are given the bus position at the moment 0. Please help Chris determine minimum amount of time the pedestrian needs to cross the road and reach the point (0, w) and not to be hit by the bus.
Input
The first line of the input contains four integers n, w, v, u (3 ≤ n ≤ 10 000, 1 ≤ w ≤ 109, 1 ≤ v, u ≤ 1000) — the number of the bus polygon vertices, road width, bus speed and pedestrian speed respectively.
The next n lines describes polygon vertices in counter-clockwise order. i-th of them contains pair of integers xi and yi ( - 109 ≤ xi ≤ 109, 0 ≤ yi ≤ w) — coordinates of i-th polygon point. It is guaranteed that the polygon is non-degenerate.
Output
Print the single real t — the time the pedestrian needs to croos the road and not to be hit by the bus. The answer is considered correct if its relative or absolute error doesn't exceed 10 - 6.
Example
Input
5 5 1 2
1 2
3 1
4 3
3 4
1 4
Output
5.0000000000
Note
Following image describes initial position in the first sample case:
<image>
Submitted Solution:
```
gcd = lambda a, b: a if b == 0 else gcd(b, a % b)
def norm(a, b, c):
k = gcd(gcd(a, b), c)
return a // k, b // k, c // k
def line(A, B):
a = A[1] - B[1]
b = B[0] - A[0]
c = -a * A[0] - b * A[1]
return norm(a, b, c)
def dist_line(A, l):
x, y = A
a, b, c = l
d = a * a + b * b
res = (a * x + b * y + c) #/ d
return res
read = lambda: map(int, input().split())
n, w, v, u = read()
p = [tuple(read()) for i in range(n)]
l = line((0, 0), (v, u))
mind = float('inf')
maxd = -float('inf')
d = 0
for P in p:
curd = dist_line(P, l)
maxd = max(maxd, curd)
mind = min(mind, curd)
if mind == curd:
x = (-l[1] * P[1] - l[2]) / l[0]
d = P[0] - x
ans = w / u
if mind * maxd < 0:
ans += d / v
print(ans)
``` | instruction | 0 | 58,510 | 1 | 117,020 |
Yes | output | 1 | 58,510 | 1 | 117,021 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
And while Mishka is enjoying her trip...
Chris is a little brown bear. No one knows, where and when he met Mishka, but for a long time they are together (excluding her current trip). However, best friends are important too. John is Chris' best friend.
Once walking with his friend, John gave Chris the following problem:
At the infinite horizontal road of width w, bounded by lines y = 0 and y = w, there is a bus moving, presented as a convex polygon of n vertices. The bus moves continuously with a constant speed of v in a straight Ox line in direction of decreasing x coordinates, thus in time only x coordinates of its points are changing. Formally, after time t each of x coordinates of its points will be decreased by vt.
There is a pedestrian in the point (0, 0), who can move only by a vertical pedestrian crossing, presented as a segment connecting points (0, 0) and (0, w) with any speed not exceeding u. Thus the pedestrian can move only in a straight line Oy in any direction with any speed not exceeding u and not leaving the road borders. The pedestrian can instantly change his speed, thus, for example, he can stop instantly.
Please look at the sample note picture for better understanding.
We consider the pedestrian is hit by the bus, if at any moment the point he is located in lies strictly inside the bus polygon (this means that if the point lies on the polygon vertex or on its edge, the pedestrian is not hit by the bus).
You are given the bus position at the moment 0. Please help Chris determine minimum amount of time the pedestrian needs to cross the road and reach the point (0, w) and not to be hit by the bus.
Input
The first line of the input contains four integers n, w, v, u (3 ≤ n ≤ 10 000, 1 ≤ w ≤ 109, 1 ≤ v, u ≤ 1000) — the number of the bus polygon vertices, road width, bus speed and pedestrian speed respectively.
The next n lines describes polygon vertices in counter-clockwise order. i-th of them contains pair of integers xi and yi ( - 109 ≤ xi ≤ 109, 0 ≤ yi ≤ w) — coordinates of i-th polygon point. It is guaranteed that the polygon is non-degenerate.
Output
Print the single real t — the time the pedestrian needs to croos the road and not to be hit by the bus. The answer is considered correct if its relative or absolute error doesn't exceed 10 - 6.
Example
Input
5 5 1 2
1 2
3 1
4 3
3 4
1 4
Output
5.0000000000
Note
Following image describes initial position in the first sample case:
<image>
Submitted Solution:
```
#!/usr/bin/env python
#-*-coding:utf-8 -*-
n,w,v,u=map(int,input().split())
v=u/v
l=r=0
for _ in range(n):
x,y=map(int,input().split())
y-=v*x
l=min(l,y)
r=max(r,y)
print((w-(l if r else 0))/u)
``` | instruction | 0 | 58,511 | 1 | 117,022 |
Yes | output | 1 | 58,511 | 1 | 117,023 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
And while Mishka is enjoying her trip...
Chris is a little brown bear. No one knows, where and when he met Mishka, but for a long time they are together (excluding her current trip). However, best friends are important too. John is Chris' best friend.
Once walking with his friend, John gave Chris the following problem:
At the infinite horizontal road of width w, bounded by lines y = 0 and y = w, there is a bus moving, presented as a convex polygon of n vertices. The bus moves continuously with a constant speed of v in a straight Ox line in direction of decreasing x coordinates, thus in time only x coordinates of its points are changing. Formally, after time t each of x coordinates of its points will be decreased by vt.
There is a pedestrian in the point (0, 0), who can move only by a vertical pedestrian crossing, presented as a segment connecting points (0, 0) and (0, w) with any speed not exceeding u. Thus the pedestrian can move only in a straight line Oy in any direction with any speed not exceeding u and not leaving the road borders. The pedestrian can instantly change his speed, thus, for example, he can stop instantly.
Please look at the sample note picture for better understanding.
We consider the pedestrian is hit by the bus, if at any moment the point he is located in lies strictly inside the bus polygon (this means that if the point lies on the polygon vertex or on its edge, the pedestrian is not hit by the bus).
You are given the bus position at the moment 0. Please help Chris determine minimum amount of time the pedestrian needs to cross the road and reach the point (0, w) and not to be hit by the bus.
Input
The first line of the input contains four integers n, w, v, u (3 ≤ n ≤ 10 000, 1 ≤ w ≤ 109, 1 ≤ v, u ≤ 1000) — the number of the bus polygon vertices, road width, bus speed and pedestrian speed respectively.
The next n lines describes polygon vertices in counter-clockwise order. i-th of them contains pair of integers xi and yi ( - 109 ≤ xi ≤ 109, 0 ≤ yi ≤ w) — coordinates of i-th polygon point. It is guaranteed that the polygon is non-degenerate.
Output
Print the single real t — the time the pedestrian needs to croos the road and not to be hit by the bus. The answer is considered correct if its relative or absolute error doesn't exceed 10 - 6.
Example
Input
5 5 1 2
1 2
3 1
4 3
3 4
1 4
Output
5.0000000000
Note
Following image describes initial position in the first sample case:
<image>
Submitted Solution:
```
n, w, v, u = map(int, input().split())
maxwait = 0
curr = True
for i in range(n):
x, y = map(int, input().split())
maxwait = max(maxwait, x / v - y / u)
if x / v < y / u:
curr = False
if curr:
maxwait = 0
print(w / u + maxwait)
``` | instruction | 0 | 58,512 | 1 | 117,024 |
Yes | output | 1 | 58,512 | 1 | 117,025 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
And while Mishka is enjoying her trip...
Chris is a little brown bear. No one knows, where and when he met Mishka, but for a long time they are together (excluding her current trip). However, best friends are important too. John is Chris' best friend.
Once walking with his friend, John gave Chris the following problem:
At the infinite horizontal road of width w, bounded by lines y = 0 and y = w, there is a bus moving, presented as a convex polygon of n vertices. The bus moves continuously with a constant speed of v in a straight Ox line in direction of decreasing x coordinates, thus in time only x coordinates of its points are changing. Formally, after time t each of x coordinates of its points will be decreased by vt.
There is a pedestrian in the point (0, 0), who can move only by a vertical pedestrian crossing, presented as a segment connecting points (0, 0) and (0, w) with any speed not exceeding u. Thus the pedestrian can move only in a straight line Oy in any direction with any speed not exceeding u and not leaving the road borders. The pedestrian can instantly change his speed, thus, for example, he can stop instantly.
Please look at the sample note picture for better understanding.
We consider the pedestrian is hit by the bus, if at any moment the point he is located in lies strictly inside the bus polygon (this means that if the point lies on the polygon vertex or on its edge, the pedestrian is not hit by the bus).
You are given the bus position at the moment 0. Please help Chris determine minimum amount of time the pedestrian needs to cross the road and reach the point (0, w) and not to be hit by the bus.
Input
The first line of the input contains four integers n, w, v, u (3 ≤ n ≤ 10 000, 1 ≤ w ≤ 109, 1 ≤ v, u ≤ 1000) — the number of the bus polygon vertices, road width, bus speed and pedestrian speed respectively.
The next n lines describes polygon vertices in counter-clockwise order. i-th of them contains pair of integers xi and yi ( - 109 ≤ xi ≤ 109, 0 ≤ yi ≤ w) — coordinates of i-th polygon point. It is guaranteed that the polygon is non-degenerate.
Output
Print the single real t — the time the pedestrian needs to croos the road and not to be hit by the bus. The answer is considered correct if its relative or absolute error doesn't exceed 10 - 6.
Example
Input
5 5 1 2
1 2
3 1
4 3
3 4
1 4
Output
5.0000000000
Note
Following image describes initial position in the first sample case:
<image>
Submitted Solution:
```
class vec(object):
def __init__(self, x, y):
self.x, self.y = x, y
def cross(self, k):
return self.x * k.y - self.y * k.x
def dot(self, k):
return self.x * k.x + self.y * k.y
def __sub__(self, k):
return vec(self.x - k.x, self.y - k.y)
n, w, v, u = map(int, input().split(' '))
p = vec(v, u)
l = [vec(*map(int, input().split(' '))) for _ in range(n)]
b, c = 0, 0
for i in l:
if p.cross(i) <= 0:
c += 1
if p.cross(i) >= 0:
b += 1
if b == n or c == n:
print('%.8f' % (w / u))
exit(0)
r = [l[(i + 1) % n] - l[i] for i in range(n)]
i = 0
while p.cross(r[i % n]) > 0:
i += 1
while p.cross(r[i % n]) < 0:
i += 1
i %= n
b = (l[i].cross(p) + v * w) / u
print('%.8f' % b)
``` | instruction | 0 | 58,513 | 1 | 117,026 |
No | output | 1 | 58,513 | 1 | 117,027 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
And while Mishka is enjoying her trip...
Chris is a little brown bear. No one knows, where and when he met Mishka, but for a long time they are together (excluding her current trip). However, best friends are important too. John is Chris' best friend.
Once walking with his friend, John gave Chris the following problem:
At the infinite horizontal road of width w, bounded by lines y = 0 and y = w, there is a bus moving, presented as a convex polygon of n vertices. The bus moves continuously with a constant speed of v in a straight Ox line in direction of decreasing x coordinates, thus in time only x coordinates of its points are changing. Formally, after time t each of x coordinates of its points will be decreased by vt.
There is a pedestrian in the point (0, 0), who can move only by a vertical pedestrian crossing, presented as a segment connecting points (0, 0) and (0, w) with any speed not exceeding u. Thus the pedestrian can move only in a straight line Oy in any direction with any speed not exceeding u and not leaving the road borders. The pedestrian can instantly change his speed, thus, for example, he can stop instantly.
Please look at the sample note picture for better understanding.
We consider the pedestrian is hit by the bus, if at any moment the point he is located in lies strictly inside the bus polygon (this means that if the point lies on the polygon vertex or on its edge, the pedestrian is not hit by the bus).
You are given the bus position at the moment 0. Please help Chris determine minimum amount of time the pedestrian needs to cross the road and reach the point (0, w) and not to be hit by the bus.
Input
The first line of the input contains four integers n, w, v, u (3 ≤ n ≤ 10 000, 1 ≤ w ≤ 109, 1 ≤ v, u ≤ 1000) — the number of the bus polygon vertices, road width, bus speed and pedestrian speed respectively.
The next n lines describes polygon vertices in counter-clockwise order. i-th of them contains pair of integers xi and yi ( - 109 ≤ xi ≤ 109, 0 ≤ yi ≤ w) — coordinates of i-th polygon point. It is guaranteed that the polygon is non-degenerate.
Output
Print the single real t — the time the pedestrian needs to croos the road and not to be hit by the bus. The answer is considered correct if its relative or absolute error doesn't exceed 10 - 6.
Example
Input
5 5 1 2
1 2
3 1
4 3
3 4
1 4
Output
5.0000000000
Note
Following image describes initial position in the first sample case:
<image>
Submitted Solution:
```
n,w,v,u=map(int,input().split())
x,y=list(map(int,input().split()))
razn=ozhid=v*y-x*u
for i in range(1,n):
x,y=map(int,input().split())
r=v*y-x*u
if r>razn:
razn=r
if r<ozhid:
oahid=r
if ozhid>=0 or razn<=0:
print(w/u)
else:
print(w/u-ozhid/(u*v))
``` | instruction | 0 | 58,514 | 1 | 117,028 |
No | output | 1 | 58,514 | 1 | 117,029 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
And while Mishka is enjoying her trip...
Chris is a little brown bear. No one knows, where and when he met Mishka, but for a long time they are together (excluding her current trip). However, best friends are important too. John is Chris' best friend.
Once walking with his friend, John gave Chris the following problem:
At the infinite horizontal road of width w, bounded by lines y = 0 and y = w, there is a bus moving, presented as a convex polygon of n vertices. The bus moves continuously with a constant speed of v in a straight Ox line in direction of decreasing x coordinates, thus in time only x coordinates of its points are changing. Formally, after time t each of x coordinates of its points will be decreased by vt.
There is a pedestrian in the point (0, 0), who can move only by a vertical pedestrian crossing, presented as a segment connecting points (0, 0) and (0, w) with any speed not exceeding u. Thus the pedestrian can move only in a straight line Oy in any direction with any speed not exceeding u and not leaving the road borders. The pedestrian can instantly change his speed, thus, for example, he can stop instantly.
Please look at the sample note picture for better understanding.
We consider the pedestrian is hit by the bus, if at any moment the point he is located in lies strictly inside the bus polygon (this means that if the point lies on the polygon vertex or on its edge, the pedestrian is not hit by the bus).
You are given the bus position at the moment 0. Please help Chris determine minimum amount of time the pedestrian needs to cross the road and reach the point (0, w) and not to be hit by the bus.
Input
The first line of the input contains four integers n, w, v, u (3 ≤ n ≤ 10 000, 1 ≤ w ≤ 109, 1 ≤ v, u ≤ 1000) — the number of the bus polygon vertices, road width, bus speed and pedestrian speed respectively.
The next n lines describes polygon vertices in counter-clockwise order. i-th of them contains pair of integers xi and yi ( - 109 ≤ xi ≤ 109, 0 ≤ yi ≤ w) — coordinates of i-th polygon point. It is guaranteed that the polygon is non-degenerate.
Output
Print the single real t — the time the pedestrian needs to croos the road and not to be hit by the bus. The answer is considered correct if its relative or absolute error doesn't exceed 10 - 6.
Example
Input
5 5 1 2
1 2
3 1
4 3
3 4
1 4
Output
5.0000000000
Note
Following image describes initial position in the first sample case:
<image>
Submitted Solution:
```
class vec(object):
def __init__(self, x, y):
self.x, self.y = x, y
def cross(self, k):
return self.x * k.y - self.y * k.x
def dot(self, k):
return self.x * k.x + self.y * k.y
def __sub__(self, k):
return vec(self.x - k.x, self.y - k.y)
n, w, v, u = map(int, input().split(' '))
p = vec(v, u)
l = [vec(*map(int, input().split(' '))) for _ in range(n)]
b, c = 0, 0
for i in l:
if p.cross(i) <= 0:
c += 1
if p.cross(i) >= 0:
b += 1
if b == n or c == n:
print('%.8f' % (w / u))
exit(0)
r = [l[(i + 1) % n] - l[i] for i in range(n)]
i = 0
while p.cross(r[i % n]) > 0:
i += 1
while p.cross(r[i % n]) < 0:
i += 1
i %= n
b = (l[i].cross(p) + v * w) / u
print(b)
``` | instruction | 0 | 58,515 | 1 | 117,030 |
No | output | 1 | 58,515 | 1 | 117,031 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
And while Mishka is enjoying her trip...
Chris is a little brown bear. No one knows, where and when he met Mishka, but for a long time they are together (excluding her current trip). However, best friends are important too. John is Chris' best friend.
Once walking with his friend, John gave Chris the following problem:
At the infinite horizontal road of width w, bounded by lines y = 0 and y = w, there is a bus moving, presented as a convex polygon of n vertices. The bus moves continuously with a constant speed of v in a straight Ox line in direction of decreasing x coordinates, thus in time only x coordinates of its points are changing. Formally, after time t each of x coordinates of its points will be decreased by vt.
There is a pedestrian in the point (0, 0), who can move only by a vertical pedestrian crossing, presented as a segment connecting points (0, 0) and (0, w) with any speed not exceeding u. Thus the pedestrian can move only in a straight line Oy in any direction with any speed not exceeding u and not leaving the road borders. The pedestrian can instantly change his speed, thus, for example, he can stop instantly.
Please look at the sample note picture for better understanding.
We consider the pedestrian is hit by the bus, if at any moment the point he is located in lies strictly inside the bus polygon (this means that if the point lies on the polygon vertex or on its edge, the pedestrian is not hit by the bus).
You are given the bus position at the moment 0. Please help Chris determine minimum amount of time the pedestrian needs to cross the road and reach the point (0, w) and not to be hit by the bus.
Input
The first line of the input contains four integers n, w, v, u (3 ≤ n ≤ 10 000, 1 ≤ w ≤ 109, 1 ≤ v, u ≤ 1000) — the number of the bus polygon vertices, road width, bus speed and pedestrian speed respectively.
The next n lines describes polygon vertices in counter-clockwise order. i-th of them contains pair of integers xi and yi ( - 109 ≤ xi ≤ 109, 0 ≤ yi ≤ w) — coordinates of i-th polygon point. It is guaranteed that the polygon is non-degenerate.
Output
Print the single real t — the time the pedestrian needs to croos the road and not to be hit by the bus. The answer is considered correct if its relative or absolute error doesn't exceed 10 - 6.
Example
Input
5 5 1 2
1 2
3 1
4 3
3 4
1 4
Output
5.0000000000
Note
Following image describes initial position in the first sample case:
<image>
Submitted Solution:
```
import sys
input = sys.stdin.readline
def solve():
n, w, v, u = map(int, input().split())
mx = int(1e13)
Mx = int(-1e13)
for i in range(n):
x, y = map(int, input().split())
xx = x * u - v * y
mx = min(mx, xx)
Mx = max(Mx, xx)
if mx >= 0:
print(0)
else:
print((Mx+w*v)/(v*u))
solve()
``` | instruction | 0 | 58,516 | 1 | 117,032 |
No | output | 1 | 58,516 | 1 | 117,033 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vova plans to go to the conference by train. Initially, the train is at the point 1 and the destination point of the path is the point L. The speed of the train is 1 length unit per minute (i.e. at the first minute the train is at the point 1, at the second minute — at the point 2 and so on).
There are lanterns on the path. They are placed at the points with coordinates divisible by v (i.e. the first lantern is at the point v, the second is at the point 2v and so on).
There is also exactly one standing train which occupies all the points from l to r inclusive.
Vova can see the lantern at the point p if p is divisible by v and there is no standing train at this position (p not∈ [l; r]). Thus, if the point with the lantern is one of the points covered by the standing train, Vova can't see this lantern.
Your problem is to say the number of lanterns Vova will see during the path. Vova plans to go to t different conferences, so you should answer t independent queries.
Input
The first line of the input contains one integer t (1 ≤ t ≤ 10^4) — the number of queries.
Then t lines follow. The i-th line contains four integers L_i, v_i, l_i, r_i (1 ≤ L, v ≤ 10^9, 1 ≤ l ≤ r ≤ L) — destination point of the i-th path, the period of the lantern appearance and the segment occupied by the standing train.
Output
Print t lines. The i-th line should contain one integer — the answer for the i-th query.
Example
Input
4
10 2 3 7
100 51 51 51
1234 1 100 199
1000000000 1 1 1000000000
Output
3
0
1134
0
Note
For the first example query, the answer is 3. There are lanterns at positions 2, 4, 6, 8 and 10, but Vova didn't see the lanterns at positions 4 and 6 because of the standing train.
For the second example query, the answer is 0 because the only lantern is at the point 51 and there is also a standing train at this point.
For the third example query, the answer is 1134 because there are 1234 lanterns, but Vova didn't see the lanterns from the position 100 to the position 199 inclusive.
For the fourth example query, the answer is 0 because the standing train covers the whole path. | instruction | 0 | 58,848 | 1 | 117,696 |
Tags: math
Correct Solution:
```
for i in range(int(input())):
l,v,li,ri=[int(num) for num in input().split()]
c=v
if l%v!=0:
c1=l-l%v
else:
c1=l
if li%v!=0:
c2=li+abs(v-li%v)
else:
c2=li
if ri%v!=0:
c3=ri-ri%v
else:
c3=ri
tot=((c1-c)//v) - (c3-c2)//v
if tot>0:
print(tot)
else:
print(0)
``` | output | 1 | 58,848 | 1 | 117,697 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vova plans to go to the conference by train. Initially, the train is at the point 1 and the destination point of the path is the point L. The speed of the train is 1 length unit per minute (i.e. at the first minute the train is at the point 1, at the second minute — at the point 2 and so on).
There are lanterns on the path. They are placed at the points with coordinates divisible by v (i.e. the first lantern is at the point v, the second is at the point 2v and so on).
There is also exactly one standing train which occupies all the points from l to r inclusive.
Vova can see the lantern at the point p if p is divisible by v and there is no standing train at this position (p not∈ [l; r]). Thus, if the point with the lantern is one of the points covered by the standing train, Vova can't see this lantern.
Your problem is to say the number of lanterns Vova will see during the path. Vova plans to go to t different conferences, so you should answer t independent queries.
Input
The first line of the input contains one integer t (1 ≤ t ≤ 10^4) — the number of queries.
Then t lines follow. The i-th line contains four integers L_i, v_i, l_i, r_i (1 ≤ L, v ≤ 10^9, 1 ≤ l ≤ r ≤ L) — destination point of the i-th path, the period of the lantern appearance and the segment occupied by the standing train.
Output
Print t lines. The i-th line should contain one integer — the answer for the i-th query.
Example
Input
4
10 2 3 7
100 51 51 51
1234 1 100 199
1000000000 1 1 1000000000
Output
3
0
1134
0
Note
For the first example query, the answer is 3. There are lanterns at positions 2, 4, 6, 8 and 10, but Vova didn't see the lanterns at positions 4 and 6 because of the standing train.
For the second example query, the answer is 0 because the only lantern is at the point 51 and there is also a standing train at this point.
For the third example query, the answer is 1134 because there are 1234 lanterns, but Vova didn't see the lanterns from the position 100 to the position 199 inclusive.
For the fourth example query, the answer is 0 because the standing train covers the whole path. | instruction | 0 | 58,849 | 1 | 117,698 |
Tags: math
Correct Solution:
```
from collections import Counter, defaultdict
BS="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
def to_base(s, b):
res = ""
while s:
res+=BS[s%b]
s//= b
return res[::-1] or "0"
alpha = "abcdefghijklmnopqrstuvwxyz"
from math import floor, ceil,pi
primes = [2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199,211,223,227,229,233,239,241,251,257,263,269,271,277,281,283,293,307,311,313,317,331,337,347,349,353,359,367,373,379,383,389,397,401,409,419,421,431,433,439,443,449,457,461,463,467,479,487,491,499,503,509,521,523,541,547,557,563,569,571,577,587,593,599,601,607,613,617,619,631,641,643,647,653,659,661,673,677,683,691,701,709,719,727,733,739,743,751,757,761,769,773,787,797,809,811,821,823,827,829,839,853,857,859,863,877,881,883,887,907,911,919,929,937,941,947,953,967,971,977,983,991,997,1009,1013,1019,1021,1031,1033,1039,1049,1051,1061,1063,1069,1087,1091,1093,1097,1103,1109,1117,1123,1129,1151,1153,1163,1171,1181,1187,1193,1201,1213,1217,1223,1229,1231,1237,1249,1259,1277,1279,1283,1289,1291,1297,1301,1303,1307,1319,1321,1327,1361,1367,1373,1381,1399,1409,1423,1427,1429,1433,1439,1447,1451,1453,1459,1471,1481,1483,1487,1489,1493,1499,1511,1523,1531,1543,1549,1553,1559,1567,1571,1579,1583,1597,1601,1607,1609,1613,1619,1621,1627,1637,1657,1663,1667,1669,1693,1697,1699,1709,1721,1723,1733,1741,1747,1753,1759,1777,1783,1787,1789,1801,1811,1823,1831,1847,1861,1867,1871,1873,1877,1879,1889,1901,1907,1913,1931,1933,1949,1951,1973,1979,1987,1993,1997,1999,2003,2011,2017,2027,2029,2039,2053,2063,2069,2081,2083,2087,2089,2099,2111,2113,2129,2131,2137,2141,2143,2153,2161,2179,2203,2207,2213,2221,2237,2239,2243,2251,2267,2269,2273,2281,2287,2293,2297,2309,2311,2333,2339,2341,2347,2351,2357,2371,2377,2381,2383,2389,2393,2399,2411,2417,2423,2437,2441,2447,2459,2467,2473,2477,2503,2521,2531,2539,2543,2549,2551,2557,2579,2591,2593,2609,2617,2621,2633,2647,2657,2659,2663,2671,2677,2683,2687,2689,2693,2699,2707,2711,2713,2719,2729,2731,2741,2749,2753,2767,2777,2789,2791,2797,2801,2803,2819,2833,2837,2843,2851,2857,2861,2879,2887,2897,2903,2909,2917,2927,2939,2953,2957,2963,2969,2971,2999,3001,3011,3019,3023,3037,3041,3049,3061,3067,3079,3083,3089,3109,3119,3121,3137,3163,3167,3169,3181,3187,3191,3203,3209,3217,3221,3229,3251,3253,3257,3259,3271,3299,3301,3307,3313,3319,3323,3329,3331,3343,3347,3359,3361,3371,3373,3389,3391,3407,3413,3433,3449,3457,3461,3463,3467,3469,3491,3499,3511,3517,3527,3529,3533,3539,3541,3547,3557,3559,3571,3581,3583,3593,3607,3613,3617,3623,3631,3637,3643,3659,3671,3673,3677,3691,3697,3701,3709,3719,3727,3733,3739,3761,3767,3769,3779,3793,3797,3803,3821,3823,3833,3847,3851,3853,3863,3877,3881,3889,3907,3911,3917,3919,3923,3929,3931,3943,3947,3967,3989,4001,4003,4007,4013,4019,4021,4027,4049,4051,4057,4073,4079,4091,4093,4099,4111,4127,4129,4133,4139,4153,4157,4159,4177,4201,4211,4217,4219,4229,4231,4241,4243,4253,4259,4261,4271,4273,4283,4289,4297,4327,4337,4339,4349,4357,4363,4373,4391,4397,4409,4421,4423,4441,4447,4451,4457,4463,4481,4483,4493,4507,4513,4517,4519,4523,4547,4549,4561,4567,4583,4591,4597,4603,4621,4637,4639,4643,4649,4651,4657,4663,4673,4679,4691,4703,4721,4723,4729,4733,4751,4759,4783,4787,4789,4793,4799,4801,4813,4817,4831,4861,4871,4877,4889,4903,4909,4919,4931,4933,4937,4943,4951,4957,4967,4969,4973,4987,4993,4999,5003,5009,5011,5021,5023,5039,5051,5059,5077,5081,5087,5099,5101,5107,5113,5119,5147,5153,5167,5171,5179,5189,5197,5209,5227,5231,5233,5237,5261,5273,5279,5281,5297,5303,5309,5323,5333,5347,5351,5381,5387,5393,5399,5407,5413,5417,5419,5431,5437,5441,5443,5449,5471,5477,5479,5483,5501,5503,5507,5519,5521,5527,5531,5557,5563,5569,5573,5581,5591,5623,5639,5641,5647,5651,5653,5657,5659,5669,5683,5689,5693,5701,5711,5717,5737,5741,5743,5749,5779,5783,5791,5801,5807,5813,5821,5827,5839,5843,5849,5851,5857,5861,5867,5869,5879,5881,5897,5903,5923,5927,5939,5953,5981,5987,6007,6011,6029,6037,6043,6047,6053,6067,6073,6079,6089,6091,6101,6113,6121,6131,6133,6143,6151,6163,6173,6197,6199,6203,6211,6217,6221,6229,6247,6257,6263,6269,6271,6277,6287,6299,6301,6311,6317,6323,6329,6337,6343,6353,6359,6361,6367,6373,6379,6389,6397,6421,6427,6449,6451,6469,6473,6481,6491,6521,6529,6547,6551,6553,6563,6569,6571,6577,6581,6599,6607,6619,6637,6653,6659,6661,6673,6679,6689,6691,6701,6703,6709,6719,6733,6737,6761,6763,6779,6781,6791,6793,6803,6823,6827,6829,6833,6841,6857,6863,6869,6871,6883,6899,6907,6911,6917,6947,6949,6959,6961,6967,6971,6977,6983,6991,6997,7001,7013,7019,7027,7039,7043,7057,7069,7079,7103,7109,7121,7127,7129,7151,7159,7177,7187,7193,7207,7211,7213,7219,7229,7237,7243,7247,7253,7283,7297,7307,7309,7321,7331,7333,7349,7351,7369,7393,7411,7417,7433,7451,7457,7459,7477,7481,7487,7489,7499,7507,7517,7523,7529,7537,7541,7547,7549,7559,7561,7573,7577,7583,7589,7591,7603,7607,7621,7639,7643,7649,7669,7673,7681,7687,7691,7699,7703,7717,7723,7727,7741,7753,7757,7759,7789,7793,7817,7823,7829,7841,7853,7867,7873,7877,7879,7883,7901,7907,7919
]
def primef(n, plst = []):
if n==1:
return plst
else:
for m in primes:
if n%m==0:
return primef(n//m, plst+[m])
return primef(1, plst+[n])
"""
t = int(input())
for i in range(t):
s = list(input())
c = Counter(s)
if c["0"]==0 or c["1"]==0:
print("NET")
else:
if len(s) > 1:
got = min(c["0"], c["1"])
if got%2==1:
print("DA")
else:
print("NET")
else:
print("NET")"""
def scoreBad(s):
res = 0
counter = 0
while True:
cur = int(counter)
ok = True
for i in range(len(s)):
res += 1
if s[i]=="+":
cur += 1
else:
cur -= 1
if cur < 0:
ok = False
break
counter += 1
if ok:
break
return res
"""
t = int(input())
for i in range(t):
s = list(input())
prefix = [0 for _ in range(len(s))]
if s[0]=="+":
prefix[0] += 1
else:
prefix[0] -= 1
for i in range(1, len(s)):
prefix[i] = prefix[i-1]
if s[i] == "+":
prefix[i] += 1
else:
prefix[i] -= 1
tot = 0
count = 0
for j in range(len(prefix)):
if prefix[j]+count < 0:
tot += j+1
count += 1
tot += len(s)
print(tot)
#print(prefix)
#print(scoreBad(s))
"""
"""
t = int(input())
for i in range(t):
n = int(input())
nums = list(map(int, input().split()))
pos = 0
pos2 = 1
sumEvens = nums[pos]
sumOdds = nums[pos2]
start = None if sumEvens >= sumOdds else 0
winLen = 2
while pos2 < len(nums)-2:
#print(sumOdds, sumEvens, pos,pos2, winLen)
if sumEvens >= sumOdds:
pos = pos2
start = int(pos)
pos2 = pos+1
sumEvens = 0
sumOdds = 0
winLen = 0
else:
winLen += 2
pos += 2
pos2 += 2
sumEvens += nums[pos]
sumOdds += nums[pos2]
tot = 0
for i in range(0,len(nums),2):
#print(start, i, winLen)
if start is None or i < start:
tot += nums[i]
elif start is not None:
if i >= start+winLen:
tot += nums[i]
if start is not None:
tot += sumOdds
#print(start, winLen, nums)
print(tot, start, winLen, sumOdds)"""
from math import log
t = int(input())
for i in range(t):
le,v,l,r = list(map(int, input().split()))
ra = floor(r/v)
la = floor((l-1)/v)
total = le//v
print(total-ra+la)
#https://codeforces.com/contest/1066/problem/A
``` | output | 1 | 58,849 | 1 | 117,699 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vova plans to go to the conference by train. Initially, the train is at the point 1 and the destination point of the path is the point L. The speed of the train is 1 length unit per minute (i.e. at the first minute the train is at the point 1, at the second minute — at the point 2 and so on).
There are lanterns on the path. They are placed at the points with coordinates divisible by v (i.e. the first lantern is at the point v, the second is at the point 2v and so on).
There is also exactly one standing train which occupies all the points from l to r inclusive.
Vova can see the lantern at the point p if p is divisible by v and there is no standing train at this position (p not∈ [l; r]). Thus, if the point with the lantern is one of the points covered by the standing train, Vova can't see this lantern.
Your problem is to say the number of lanterns Vova will see during the path. Vova plans to go to t different conferences, so you should answer t independent queries.
Input
The first line of the input contains one integer t (1 ≤ t ≤ 10^4) — the number of queries.
Then t lines follow. The i-th line contains four integers L_i, v_i, l_i, r_i (1 ≤ L, v ≤ 10^9, 1 ≤ l ≤ r ≤ L) — destination point of the i-th path, the period of the lantern appearance and the segment occupied by the standing train.
Output
Print t lines. The i-th line should contain one integer — the answer for the i-th query.
Example
Input
4
10 2 3 7
100 51 51 51
1234 1 100 199
1000000000 1 1 1000000000
Output
3
0
1134
0
Note
For the first example query, the answer is 3. There are lanterns at positions 2, 4, 6, 8 and 10, but Vova didn't see the lanterns at positions 4 and 6 because of the standing train.
For the second example query, the answer is 0 because the only lantern is at the point 51 and there is also a standing train at this point.
For the third example query, the answer is 1134 because there are 1234 lanterns, but Vova didn't see the lanterns from the position 100 to the position 199 inclusive.
For the fourth example query, the answer is 0 because the standing train covers the whole path. | instruction | 0 | 58,850 | 1 | 117,700 |
Tags: math
Correct Solution:
```
t = int(input())
for i in range(t):
L, u, l, r = map(int, input().split())
print((L//u)+((l-1)//u)-(r//u))
``` | output | 1 | 58,850 | 1 | 117,701 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vova plans to go to the conference by train. Initially, the train is at the point 1 and the destination point of the path is the point L. The speed of the train is 1 length unit per minute (i.e. at the first minute the train is at the point 1, at the second minute — at the point 2 and so on).
There are lanterns on the path. They are placed at the points with coordinates divisible by v (i.e. the first lantern is at the point v, the second is at the point 2v and so on).
There is also exactly one standing train which occupies all the points from l to r inclusive.
Vova can see the lantern at the point p if p is divisible by v and there is no standing train at this position (p not∈ [l; r]). Thus, if the point with the lantern is one of the points covered by the standing train, Vova can't see this lantern.
Your problem is to say the number of lanterns Vova will see during the path. Vova plans to go to t different conferences, so you should answer t independent queries.
Input
The first line of the input contains one integer t (1 ≤ t ≤ 10^4) — the number of queries.
Then t lines follow. The i-th line contains four integers L_i, v_i, l_i, r_i (1 ≤ L, v ≤ 10^9, 1 ≤ l ≤ r ≤ L) — destination point of the i-th path, the period of the lantern appearance and the segment occupied by the standing train.
Output
Print t lines. The i-th line should contain one integer — the answer for the i-th query.
Example
Input
4
10 2 3 7
100 51 51 51
1234 1 100 199
1000000000 1 1 1000000000
Output
3
0
1134
0
Note
For the first example query, the answer is 3. There are lanterns at positions 2, 4, 6, 8 and 10, but Vova didn't see the lanterns at positions 4 and 6 because of the standing train.
For the second example query, the answer is 0 because the only lantern is at the point 51 and there is also a standing train at this point.
For the third example query, the answer is 1134 because there are 1234 lanterns, but Vova didn't see the lanterns from the position 100 to the position 199 inclusive.
For the fourth example query, the answer is 0 because the standing train covers the whole path. | instruction | 0 | 58,851 | 1 | 117,702 |
Tags: math
Correct Solution:
```
t=int(input())
for _ in range(0,t):
L,v,l,r=map(int,input().split())
if(l%v!=0):
c1=l//v
else:
c1=l//v-1
c2=L//v
x=r//v
c2-=x
print(c1+c2)
``` | output | 1 | 58,851 | 1 | 117,703 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.