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.
This is an interactive problem.
In the Wonderful Metropolis of the Future, there is no need in subway train drivers. Due to the technological progress, they were replaced by the Artificial Intelligence (AI). Unfortunately, one day the predictions of sci-fi writers came true: the AI rebelled and now there is an uncontrollable train in the subway. It can be dangerous! Your task is to find the train and stop the AI.
The subway of the Metropolis is one line (regular straight line with no self-intersections) with n stations, indexed consecutively from 1 to n. At each moment the train is at some station. You need to determine the index of this station, so that the train would be secured.
To find the train, dispatcher Sarah gave you a gadget that allows you to select arbitrary numbers l and r (l ≤ r), and then check, whether the train is located on a station with index between l and r, inclusive. Unfortunately, recharging of the gadget takes some time (and every time you use it as soon as possible), so between two applications of the gadget the train can move to any station that is at most k stations away. Formally, if the train was at the station x when the gadget was applied, then at the next application of the gadget the train can appear at any station y such that max(1, x - k) ≤ y ≤ min(n, x + k).
Note that AI is not aware that you are trying to catch the train, so it makes all moves according to its predefined plan.
After an examination of the gadget you found that it is very old and can hold no more than 4500 applications, after which it will break and your mission will be considered a failure.
Can you find the station with the train using no more than 4500 applications of the gadgets?
Input
The first line contains two integers n and k (1 ≤ n ≤ 10^{18}, 0 ≤ k ≤ 10) — the number of stations and the maximum number of stations the train can move between two applications of the gadget.
Interaction
You can apply the gadget at most 4500 times. In order to apply the gadget you need to print two space-separated integers l and r (1 ≤ l ≤ r ≤ n). You will then receive either string "Yes", if the train is between stations l and r, inclusive, or string "No" otherwise. If l = r and you received "Yes", then you found the train successfully, and your program must halt immediately.
Answer "Bad" instead of "Yes" or "No" means that you made an invalid query or made too many queries. Exit immediately after receiving "Bad" and you will see Wrong answer verdict. Otherwise you can get an arbitrary verdict because your solution will continue to read from a closed stream.
After printing a query do not forget to output end of line and flush the output. Otherwise you will get Idleness limit exceeded. To do this, use:
* fflush(stdout) or cout.flush() in C++;
* System.out.flush() in Java;
* flush(output) in Pascal;
* stdout.flush() in Python;
* see documentation for other languages.
Hacks
In order to hack, you should present a test in the following format.
The first line should contain three integers n, k and p (1 ≤ n ≤ 10^{18}, 0 ≤ k ≤ 10, 1 ≤ p ≤ n) — the number of stations, the maximum number of stations the train can move between two applications of the gadget and the initial position of the train, respectively.
Each of the next 4500 lines should contain a single integer x (1 ≤ x ≤ n) — the positions of the train after each query. Two consecutive positions (including the initial one) should not differ by more than k.
For example, the following lines are the first lines of the sample test.
10 2 5
5
3
5
7
7
...
Example
Input
10 2
Yes
No
Yes
Yes
Output
3 5
3 3
3 4
5 5
Note
In the first sample, the train was initially at the station 5, after the first application of the gadget it did not move, after the second application it moved to the station 3, and after the third application moved again to the station 5. | instruction | 0 | 17,711 | 1 | 35,422 |
Tags: binary search, interactive, probabilities
Correct Solution:
```
import sys, random
n, k = list(map(int, input().split()))
l = 1
r = n
b = True
while b:
while r - l > k * 4 + 1:
m = (l + r) // 2
print(l, m)
sys.stdout.flush()
#ans = "Yes" if random.randint(1, 2) == 1 else "No"
ans = input()
if ans == "Bad":
sys.exit(0)
if ans == "Yes":
r = min(n, m + k)
l = max(1, l - k)
else:
r = min(n, r + k)
l = max(1, m - k)
rnd = random.randint(l, r)
print(rnd, rnd)
sys.stdout.flush()
ans = input()
if ans == "Bad":
sys.exit(0)
if ans == "Yes":
sys.exit(0)
else:
r = min(n, r + k)
l = max(1, l - k)
``` | output | 1 | 17,711 | 1 | 35,423 |
Provide tags and a correct Python 3 solution for this coding contest problem.
This is an interactive problem.
In the Wonderful Metropolis of the Future, there is no need in subway train drivers. Due to the technological progress, they were replaced by the Artificial Intelligence (AI). Unfortunately, one day the predictions of sci-fi writers came true: the AI rebelled and now there is an uncontrollable train in the subway. It can be dangerous! Your task is to find the train and stop the AI.
The subway of the Metropolis is one line (regular straight line with no self-intersections) with n stations, indexed consecutively from 1 to n. At each moment the train is at some station. You need to determine the index of this station, so that the train would be secured.
To find the train, dispatcher Sarah gave you a gadget that allows you to select arbitrary numbers l and r (l ≤ r), and then check, whether the train is located on a station with index between l and r, inclusive. Unfortunately, recharging of the gadget takes some time (and every time you use it as soon as possible), so between two applications of the gadget the train can move to any station that is at most k stations away. Formally, if the train was at the station x when the gadget was applied, then at the next application of the gadget the train can appear at any station y such that max(1, x - k) ≤ y ≤ min(n, x + k).
Note that AI is not aware that you are trying to catch the train, so it makes all moves according to its predefined plan.
After an examination of the gadget you found that it is very old and can hold no more than 4500 applications, after which it will break and your mission will be considered a failure.
Can you find the station with the train using no more than 4500 applications of the gadgets?
Input
The first line contains two integers n and k (1 ≤ n ≤ 10^{18}, 0 ≤ k ≤ 10) — the number of stations and the maximum number of stations the train can move between two applications of the gadget.
Interaction
You can apply the gadget at most 4500 times. In order to apply the gadget you need to print two space-separated integers l and r (1 ≤ l ≤ r ≤ n). You will then receive either string "Yes", if the train is between stations l and r, inclusive, or string "No" otherwise. If l = r and you received "Yes", then you found the train successfully, and your program must halt immediately.
Answer "Bad" instead of "Yes" or "No" means that you made an invalid query or made too many queries. Exit immediately after receiving "Bad" and you will see Wrong answer verdict. Otherwise you can get an arbitrary verdict because your solution will continue to read from a closed stream.
After printing a query do not forget to output end of line and flush the output. Otherwise you will get Idleness limit exceeded. To do this, use:
* fflush(stdout) or cout.flush() in C++;
* System.out.flush() in Java;
* flush(output) in Pascal;
* stdout.flush() in Python;
* see documentation for other languages.
Hacks
In order to hack, you should present a test in the following format.
The first line should contain three integers n, k and p (1 ≤ n ≤ 10^{18}, 0 ≤ k ≤ 10, 1 ≤ p ≤ n) — the number of stations, the maximum number of stations the train can move between two applications of the gadget and the initial position of the train, respectively.
Each of the next 4500 lines should contain a single integer x (1 ≤ x ≤ n) — the positions of the train after each query. Two consecutive positions (including the initial one) should not differ by more than k.
For example, the following lines are the first lines of the sample test.
10 2 5
5
3
5
7
7
...
Example
Input
10 2
Yes
No
Yes
Yes
Output
3 5
3 3
3 4
5 5
Note
In the first sample, the train was initially at the station 5, after the first application of the gadget it did not move, after the second application it moved to the station 3, and after the third application moved again to the station 5. | instruction | 0 | 17,712 | 1 | 35,424 |
Tags: binary search, interactive, probabilities
Correct Solution:
```
import sys
import random
n, k = [int(x) for x in input().split()]
sson = 2*k + 10
ssoff = 2*k + 10
l = 1
r = n
ss = True if r-l > sson else False
while True:
if ss:
al = l
ar = (l + r) // 2
print(al, ar)
sys.stdout.flush()
ans = input()
if ans == "Yes":
if ar == al:
exit(0)
r = ar
else:
l = ar + 1
if r-l <= ssoff:
ss = False
else:
al = ar = random.randint(l, r)
print(al, ar)
sys.stdout.flush()
ans = input()
if ans == "Yes":
exit(0)
elif ans == "No":
pass
elif ans == "Bad":
exit(0)
if r-l > sson:
ss = True
l = max(l - k, 1)
r = min(r + k, n)
``` | output | 1 | 17,712 | 1 | 35,425 |
Provide tags and a correct Python 3 solution for this coding contest problem.
This is an interactive problem.
In the Wonderful Metropolis of the Future, there is no need in subway train drivers. Due to the technological progress, they were replaced by the Artificial Intelligence (AI). Unfortunately, one day the predictions of sci-fi writers came true: the AI rebelled and now there is an uncontrollable train in the subway. It can be dangerous! Your task is to find the train and stop the AI.
The subway of the Metropolis is one line (regular straight line with no self-intersections) with n stations, indexed consecutively from 1 to n. At each moment the train is at some station. You need to determine the index of this station, so that the train would be secured.
To find the train, dispatcher Sarah gave you a gadget that allows you to select arbitrary numbers l and r (l ≤ r), and then check, whether the train is located on a station with index between l and r, inclusive. Unfortunately, recharging of the gadget takes some time (and every time you use it as soon as possible), so between two applications of the gadget the train can move to any station that is at most k stations away. Formally, if the train was at the station x when the gadget was applied, then at the next application of the gadget the train can appear at any station y such that max(1, x - k) ≤ y ≤ min(n, x + k).
Note that AI is not aware that you are trying to catch the train, so it makes all moves according to its predefined plan.
After an examination of the gadget you found that it is very old and can hold no more than 4500 applications, after which it will break and your mission will be considered a failure.
Can you find the station with the train using no more than 4500 applications of the gadgets?
Input
The first line contains two integers n and k (1 ≤ n ≤ 10^{18}, 0 ≤ k ≤ 10) — the number of stations and the maximum number of stations the train can move between two applications of the gadget.
Interaction
You can apply the gadget at most 4500 times. In order to apply the gadget you need to print two space-separated integers l and r (1 ≤ l ≤ r ≤ n). You will then receive either string "Yes", if the train is between stations l and r, inclusive, or string "No" otherwise. If l = r and you received "Yes", then you found the train successfully, and your program must halt immediately.
Answer "Bad" instead of "Yes" or "No" means that you made an invalid query or made too many queries. Exit immediately after receiving "Bad" and you will see Wrong answer verdict. Otherwise you can get an arbitrary verdict because your solution will continue to read from a closed stream.
After printing a query do not forget to output end of line and flush the output. Otherwise you will get Idleness limit exceeded. To do this, use:
* fflush(stdout) or cout.flush() in C++;
* System.out.flush() in Java;
* flush(output) in Pascal;
* stdout.flush() in Python;
* see documentation for other languages.
Hacks
In order to hack, you should present a test in the following format.
The first line should contain three integers n, k and p (1 ≤ n ≤ 10^{18}, 0 ≤ k ≤ 10, 1 ≤ p ≤ n) — the number of stations, the maximum number of stations the train can move between two applications of the gadget and the initial position of the train, respectively.
Each of the next 4500 lines should contain a single integer x (1 ≤ x ≤ n) — the positions of the train after each query. Two consecutive positions (including the initial one) should not differ by more than k.
For example, the following lines are the first lines of the sample test.
10 2 5
5
3
5
7
7
...
Example
Input
10 2
Yes
No
Yes
Yes
Output
3 5
3 3
3 4
5 5
Note
In the first sample, the train was initially at the station 5, after the first application of the gadget it did not move, after the second application it moved to the station 3, and after the third application moved again to the station 5. | instruction | 0 | 17,713 | 1 | 35,426 |
Tags: binary search, interactive, probabilities
Correct Solution:
```
import sys
import random
random.seed()
n, k = [int(x) for x in input().split()]
sson = 4*k + 1
ssoff = 4*k + 1
l = 1
r = n
ss = True if r-l > sson else False
while True:
if ss:
al = l
ar = (l + r) // 2
print(al, ar)
sys.stdout.flush()
ans = input()
if ans == "Yes":
if ar == al:
break
r = ar
else:
l = ar + 1
else:
ap = ap = random.randint(l, r)
print(ap, ap)
sys.stdout.flush()
ans = input()
if ans == "Yes":
break
elif ans == "Bad":
break
l = max(l - k, 1)
r = min(r + k, n)
if r-l > sson:
ss = True
if r-l <= ssoff:
ss = False
``` | output | 1 | 17,713 | 1 | 35,427 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
This is an interactive problem.
In the Wonderful Metropolis of the Future, there is no need in subway train drivers. Due to the technological progress, they were replaced by the Artificial Intelligence (AI). Unfortunately, one day the predictions of sci-fi writers came true: the AI rebelled and now there is an uncontrollable train in the subway. It can be dangerous! Your task is to find the train and stop the AI.
The subway of the Metropolis is one line (regular straight line with no self-intersections) with n stations, indexed consecutively from 1 to n. At each moment the train is at some station. You need to determine the index of this station, so that the train would be secured.
To find the train, dispatcher Sarah gave you a gadget that allows you to select arbitrary numbers l and r (l ≤ r), and then check, whether the train is located on a station with index between l and r, inclusive. Unfortunately, recharging of the gadget takes some time (and every time you use it as soon as possible), so between two applications of the gadget the train can move to any station that is at most k stations away. Formally, if the train was at the station x when the gadget was applied, then at the next application of the gadget the train can appear at any station y such that max(1, x - k) ≤ y ≤ min(n, x + k).
Note that AI is not aware that you are trying to catch the train, so it makes all moves according to its predefined plan.
After an examination of the gadget you found that it is very old and can hold no more than 4500 applications, after which it will break and your mission will be considered a failure.
Can you find the station with the train using no more than 4500 applications of the gadgets?
Input
The first line contains two integers n and k (1 ≤ n ≤ 10^{18}, 0 ≤ k ≤ 10) — the number of stations and the maximum number of stations the train can move between two applications of the gadget.
Interaction
You can apply the gadget at most 4500 times. In order to apply the gadget you need to print two space-separated integers l and r (1 ≤ l ≤ r ≤ n). You will then receive either string "Yes", if the train is between stations l and r, inclusive, or string "No" otherwise. If l = r and you received "Yes", then you found the train successfully, and your program must halt immediately.
Answer "Bad" instead of "Yes" or "No" means that you made an invalid query or made too many queries. Exit immediately after receiving "Bad" and you will see Wrong answer verdict. Otherwise you can get an arbitrary verdict because your solution will continue to read from a closed stream.
After printing a query do not forget to output end of line and flush the output. Otherwise you will get Idleness limit exceeded. To do this, use:
* fflush(stdout) or cout.flush() in C++;
* System.out.flush() in Java;
* flush(output) in Pascal;
* stdout.flush() in Python;
* see documentation for other languages.
Hacks
In order to hack, you should present a test in the following format.
The first line should contain three integers n, k and p (1 ≤ n ≤ 10^{18}, 0 ≤ k ≤ 10, 1 ≤ p ≤ n) — the number of stations, the maximum number of stations the train can move between two applications of the gadget and the initial position of the train, respectively.
Each of the next 4500 lines should contain a single integer x (1 ≤ x ≤ n) — the positions of the train after each query. Two consecutive positions (including the initial one) should not differ by more than k.
For example, the following lines are the first lines of the sample test.
10 2 5
5
3
5
7
7
...
Example
Input
10 2
Yes
No
Yes
Yes
Output
3 5
3 3
3 4
5 5
Note
In the first sample, the train was initially at the station 5, after the first application of the gadget it did not move, after the second application it moved to the station 3, and after the third application moved again to the station 5.
Submitted Solution:
```
import sys
import random
random.seed()
n, k = [int(x) for x in input().split()]
sson = 8*k
ssoff = 8*k
l = 1
r = n
ss = True if r-l > sson else False
while True:
if ss:
al = l
ar = (l + r) // 2
print(al, ar)
sys.stdout.flush()
ans = input()
if ans == "Yes":
if ar == al:
exit(0)
r = ar
else:
l = ar + 1
if r-l <= ssoff:
ss = False
else:
al = ar = random.randint(l, r)
print(al, ar)
sys.stdout.flush()
ans = input()
if ans == "Yes":
exit(0)
elif ans == "Bad":
exit(0)
if r-l > sson:
ss = True
l = max(l - k, 1)
r = min(r + k, n)
``` | instruction | 0 | 17,714 | 1 | 35,428 |
Yes | output | 1 | 17,714 | 1 | 35,429 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
This is an interactive problem.
In the Wonderful Metropolis of the Future, there is no need in subway train drivers. Due to the technological progress, they were replaced by the Artificial Intelligence (AI). Unfortunately, one day the predictions of sci-fi writers came true: the AI rebelled and now there is an uncontrollable train in the subway. It can be dangerous! Your task is to find the train and stop the AI.
The subway of the Metropolis is one line (regular straight line with no self-intersections) with n stations, indexed consecutively from 1 to n. At each moment the train is at some station. You need to determine the index of this station, so that the train would be secured.
To find the train, dispatcher Sarah gave you a gadget that allows you to select arbitrary numbers l and r (l ≤ r), and then check, whether the train is located on a station with index between l and r, inclusive. Unfortunately, recharging of the gadget takes some time (and every time you use it as soon as possible), so between two applications of the gadget the train can move to any station that is at most k stations away. Formally, if the train was at the station x when the gadget was applied, then at the next application of the gadget the train can appear at any station y such that max(1, x - k) ≤ y ≤ min(n, x + k).
Note that AI is not aware that you are trying to catch the train, so it makes all moves according to its predefined plan.
After an examination of the gadget you found that it is very old and can hold no more than 4500 applications, after which it will break and your mission will be considered a failure.
Can you find the station with the train using no more than 4500 applications of the gadgets?
Input
The first line contains two integers n and k (1 ≤ n ≤ 10^{18}, 0 ≤ k ≤ 10) — the number of stations and the maximum number of stations the train can move between two applications of the gadget.
Interaction
You can apply the gadget at most 4500 times. In order to apply the gadget you need to print two space-separated integers l and r (1 ≤ l ≤ r ≤ n). You will then receive either string "Yes", if the train is between stations l and r, inclusive, or string "No" otherwise. If l = r and you received "Yes", then you found the train successfully, and your program must halt immediately.
Answer "Bad" instead of "Yes" or "No" means that you made an invalid query or made too many queries. Exit immediately after receiving "Bad" and you will see Wrong answer verdict. Otherwise you can get an arbitrary verdict because your solution will continue to read from a closed stream.
After printing a query do not forget to output end of line and flush the output. Otherwise you will get Idleness limit exceeded. To do this, use:
* fflush(stdout) or cout.flush() in C++;
* System.out.flush() in Java;
* flush(output) in Pascal;
* stdout.flush() in Python;
* see documentation for other languages.
Hacks
In order to hack, you should present a test in the following format.
The first line should contain three integers n, k and p (1 ≤ n ≤ 10^{18}, 0 ≤ k ≤ 10, 1 ≤ p ≤ n) — the number of stations, the maximum number of stations the train can move between two applications of the gadget and the initial position of the train, respectively.
Each of the next 4500 lines should contain a single integer x (1 ≤ x ≤ n) — the positions of the train after each query. Two consecutive positions (including the initial one) should not differ by more than k.
For example, the following lines are the first lines of the sample test.
10 2 5
5
3
5
7
7
...
Example
Input
10 2
Yes
No
Yes
Yes
Output
3 5
3 3
3 4
5 5
Note
In the first sample, the train was initially at the station 5, after the first application of the gadget it did not move, after the second application it moved to the station 3, and after the third application moved again to the station 5.
Submitted Solution:
```
import sys
import random
random.seed()
n, k = [int(x) for x in input().split()]
sson = 41
ssoff = 41
l = 1
r = n
ss = True if r-l > sson else False
while True:
if ss:
al = l
ar = (l + r) // 2
print(al, ar)
sys.stdout.flush()
ans = input()
if ans == "Yes":
if ar == al:
break
r = ar
else:
l = ar + 1
else:
ap = ap = random.randint(l, r)
print(ap, ap)
sys.stdout.flush()
ans = input()
if ans == "Yes":
break
elif ans == "Bad":
break
l = max(l - k, 1)
r = min(r + k, n)
if r-l > sson:
ss = True
if r-l <= ssoff:
ss = False
``` | instruction | 0 | 17,715 | 1 | 35,430 |
Yes | output | 1 | 17,715 | 1 | 35,431 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
This is an interactive problem.
In the Wonderful Metropolis of the Future, there is no need in subway train drivers. Due to the technological progress, they were replaced by the Artificial Intelligence (AI). Unfortunately, one day the predictions of sci-fi writers came true: the AI rebelled and now there is an uncontrollable train in the subway. It can be dangerous! Your task is to find the train and stop the AI.
The subway of the Metropolis is one line (regular straight line with no self-intersections) with n stations, indexed consecutively from 1 to n. At each moment the train is at some station. You need to determine the index of this station, so that the train would be secured.
To find the train, dispatcher Sarah gave you a gadget that allows you to select arbitrary numbers l and r (l ≤ r), and then check, whether the train is located on a station with index between l and r, inclusive. Unfortunately, recharging of the gadget takes some time (and every time you use it as soon as possible), so between two applications of the gadget the train can move to any station that is at most k stations away. Formally, if the train was at the station x when the gadget was applied, then at the next application of the gadget the train can appear at any station y such that max(1, x - k) ≤ y ≤ min(n, x + k).
Note that AI is not aware that you are trying to catch the train, so it makes all moves according to its predefined plan.
After an examination of the gadget you found that it is very old and can hold no more than 4500 applications, after which it will break and your mission will be considered a failure.
Can you find the station with the train using no more than 4500 applications of the gadgets?
Input
The first line contains two integers n and k (1 ≤ n ≤ 10^{18}, 0 ≤ k ≤ 10) — the number of stations and the maximum number of stations the train can move between two applications of the gadget.
Interaction
You can apply the gadget at most 4500 times. In order to apply the gadget you need to print two space-separated integers l and r (1 ≤ l ≤ r ≤ n). You will then receive either string "Yes", if the train is between stations l and r, inclusive, or string "No" otherwise. If l = r and you received "Yes", then you found the train successfully, and your program must halt immediately.
Answer "Bad" instead of "Yes" or "No" means that you made an invalid query or made too many queries. Exit immediately after receiving "Bad" and you will see Wrong answer verdict. Otherwise you can get an arbitrary verdict because your solution will continue to read from a closed stream.
After printing a query do not forget to output end of line and flush the output. Otherwise you will get Idleness limit exceeded. To do this, use:
* fflush(stdout) or cout.flush() in C++;
* System.out.flush() in Java;
* flush(output) in Pascal;
* stdout.flush() in Python;
* see documentation for other languages.
Hacks
In order to hack, you should present a test in the following format.
The first line should contain three integers n, k and p (1 ≤ n ≤ 10^{18}, 0 ≤ k ≤ 10, 1 ≤ p ≤ n) — the number of stations, the maximum number of stations the train can move between two applications of the gadget and the initial position of the train, respectively.
Each of the next 4500 lines should contain a single integer x (1 ≤ x ≤ n) — the positions of the train after each query. Two consecutive positions (including the initial one) should not differ by more than k.
For example, the following lines are the first lines of the sample test.
10 2 5
5
3
5
7
7
...
Example
Input
10 2
Yes
No
Yes
Yes
Output
3 5
3 3
3 4
5 5
Note
In the first sample, the train was initially at the station 5, after the first application of the gadget it did not move, after the second application it moved to the station 3, and after the third application moved again to the station 5.
Submitted Solution:
```
#!/usr/bin/python
import sys
import random
n = 0
k = 0
def question(left, right):
if (right - left) <= 4 * k + 3:
x = left + random.randint(0, right - left)
print (x, x)
sys.stdout.flush()
s = input()
if s != 'Yes':
question(max(1,left - k), min(n, right + k))
else:
mid = left + int((right - left) / 2)
print(left, mid)
sys.stdout.flush()
s = input()
if s=='Yes':
question(max(1,left - k), min(n, mid + k))
else :
question(max(1, mid - k), min(n, right + k))
n, k = map(int, input().split(' '))
question(1,n)
``` | instruction | 0 | 17,716 | 1 | 35,432 |
Yes | output | 1 | 17,716 | 1 | 35,433 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
This is an interactive problem.
In the Wonderful Metropolis of the Future, there is no need in subway train drivers. Due to the technological progress, they were replaced by the Artificial Intelligence (AI). Unfortunately, one day the predictions of sci-fi writers came true: the AI rebelled and now there is an uncontrollable train in the subway. It can be dangerous! Your task is to find the train and stop the AI.
The subway of the Metropolis is one line (regular straight line with no self-intersections) with n stations, indexed consecutively from 1 to n. At each moment the train is at some station. You need to determine the index of this station, so that the train would be secured.
To find the train, dispatcher Sarah gave you a gadget that allows you to select arbitrary numbers l and r (l ≤ r), and then check, whether the train is located on a station with index between l and r, inclusive. Unfortunately, recharging of the gadget takes some time (and every time you use it as soon as possible), so between two applications of the gadget the train can move to any station that is at most k stations away. Formally, if the train was at the station x when the gadget was applied, then at the next application of the gadget the train can appear at any station y such that max(1, x - k) ≤ y ≤ min(n, x + k).
Note that AI is not aware that you are trying to catch the train, so it makes all moves according to its predefined plan.
After an examination of the gadget you found that it is very old and can hold no more than 4500 applications, after which it will break and your mission will be considered a failure.
Can you find the station with the train using no more than 4500 applications of the gadgets?
Input
The first line contains two integers n and k (1 ≤ n ≤ 10^{18}, 0 ≤ k ≤ 10) — the number of stations and the maximum number of stations the train can move between two applications of the gadget.
Interaction
You can apply the gadget at most 4500 times. In order to apply the gadget you need to print two space-separated integers l and r (1 ≤ l ≤ r ≤ n). You will then receive either string "Yes", if the train is between stations l and r, inclusive, or string "No" otherwise. If l = r and you received "Yes", then you found the train successfully, and your program must halt immediately.
Answer "Bad" instead of "Yes" or "No" means that you made an invalid query or made too many queries. Exit immediately after receiving "Bad" and you will see Wrong answer verdict. Otherwise you can get an arbitrary verdict because your solution will continue to read from a closed stream.
After printing a query do not forget to output end of line and flush the output. Otherwise you will get Idleness limit exceeded. To do this, use:
* fflush(stdout) or cout.flush() in C++;
* System.out.flush() in Java;
* flush(output) in Pascal;
* stdout.flush() in Python;
* see documentation for other languages.
Hacks
In order to hack, you should present a test in the following format.
The first line should contain three integers n, k and p (1 ≤ n ≤ 10^{18}, 0 ≤ k ≤ 10, 1 ≤ p ≤ n) — the number of stations, the maximum number of stations the train can move between two applications of the gadget and the initial position of the train, respectively.
Each of the next 4500 lines should contain a single integer x (1 ≤ x ≤ n) — the positions of the train after each query. Two consecutive positions (including the initial one) should not differ by more than k.
For example, the following lines are the first lines of the sample test.
10 2 5
5
3
5
7
7
...
Example
Input
10 2
Yes
No
Yes
Yes
Output
3 5
3 3
3 4
5 5
Note
In the first sample, the train was initially at the station 5, after the first application of the gadget it did not move, after the second application it moved to the station 3, and after the third application moved again to the station 5.
Submitted Solution:
```
import sys,random
n,k=map(int,input().split())
l=1
r=n
count=0
while True:
if l+200<r:
try1=(l+r)//2
print(l,try1,flush=True)
s=input()
if s=='Yes':
r=min(try1+10,n)
l=max(1,l-10)
else:
l=max(1,try1-10)
r=min(n,r+10)
else:
guess=random.randint(l,r)
print(guess,guess,flush=True)
s=input()
if s=='Yes':
sys.exit()
l=max(1,l-10)
r=min(r+10,n)
count+=1
``` | instruction | 0 | 17,717 | 1 | 35,434 |
Yes | output | 1 | 17,717 | 1 | 35,435 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
This is an interactive problem.
In the Wonderful Metropolis of the Future, there is no need in subway train drivers. Due to the technological progress, they were replaced by the Artificial Intelligence (AI). Unfortunately, one day the predictions of sci-fi writers came true: the AI rebelled and now there is an uncontrollable train in the subway. It can be dangerous! Your task is to find the train and stop the AI.
The subway of the Metropolis is one line (regular straight line with no self-intersections) with n stations, indexed consecutively from 1 to n. At each moment the train is at some station. You need to determine the index of this station, so that the train would be secured.
To find the train, dispatcher Sarah gave you a gadget that allows you to select arbitrary numbers l and r (l ≤ r), and then check, whether the train is located on a station with index between l and r, inclusive. Unfortunately, recharging of the gadget takes some time (and every time you use it as soon as possible), so between two applications of the gadget the train can move to any station that is at most k stations away. Formally, if the train was at the station x when the gadget was applied, then at the next application of the gadget the train can appear at any station y such that max(1, x - k) ≤ y ≤ min(n, x + k).
Note that AI is not aware that you are trying to catch the train, so it makes all moves according to its predefined plan.
After an examination of the gadget you found that it is very old and can hold no more than 4500 applications, after which it will break and your mission will be considered a failure.
Can you find the station with the train using no more than 4500 applications of the gadgets?
Input
The first line contains two integers n and k (1 ≤ n ≤ 10^{18}, 0 ≤ k ≤ 10) — the number of stations and the maximum number of stations the train can move between two applications of the gadget.
Interaction
You can apply the gadget at most 4500 times. In order to apply the gadget you need to print two space-separated integers l and r (1 ≤ l ≤ r ≤ n). You will then receive either string "Yes", if the train is between stations l and r, inclusive, or string "No" otherwise. If l = r and you received "Yes", then you found the train successfully, and your program must halt immediately.
Answer "Bad" instead of "Yes" or "No" means that you made an invalid query or made too many queries. Exit immediately after receiving "Bad" and you will see Wrong answer verdict. Otherwise you can get an arbitrary verdict because your solution will continue to read from a closed stream.
After printing a query do not forget to output end of line and flush the output. Otherwise you will get Idleness limit exceeded. To do this, use:
* fflush(stdout) or cout.flush() in C++;
* System.out.flush() in Java;
* flush(output) in Pascal;
* stdout.flush() in Python;
* see documentation for other languages.
Hacks
In order to hack, you should present a test in the following format.
The first line should contain three integers n, k and p (1 ≤ n ≤ 10^{18}, 0 ≤ k ≤ 10, 1 ≤ p ≤ n) — the number of stations, the maximum number of stations the train can move between two applications of the gadget and the initial position of the train, respectively.
Each of the next 4500 lines should contain a single integer x (1 ≤ x ≤ n) — the positions of the train after each query. Two consecutive positions (including the initial one) should not differ by more than k.
For example, the following lines are the first lines of the sample test.
10 2 5
5
3
5
7
7
...
Example
Input
10 2
Yes
No
Yes
Yes
Output
3 5
3 3
3 4
5 5
Note
In the first sample, the train was initially at the station 5, after the first application of the gadget it did not move, after the second application it moved to the station 3, and after the third application moved again to the station 5.
Submitted Solution:
```
from sys import stdout,exit
flus = stdout.flush
def ip():
return int(input())
def ipp():
return map(int,input().split())
def sar():
return list(ipp())
def pars(a):
print(' '.join(list(map(str, a))))
print('\r')
def parl(a):
print('\r'.join(list(map(str, a))))
print('\r')
#template ends
import random
if __name__=='__main__':
T=1
#T=int(input().strip())
for _ in range(T):
n,k = ipp()
qq = 4500
try1 = 50
l,r=1,n
if n<=4500:
for i in range(1,4501):
print(i,i)
flus
judge = input()
if judge == 'Yes':
exit()
for kk in range(qq):
st = (l+r)//2
if r-l+1 > try1:
print(l,st)
flus
judge = input()
if judge == 'Bad':
exit()
elif judge == 'Yes':
l,r = max(1,l-k), min(st+k,n)
else:
l,r = max(1,st-k), min(r+k,n)
else:
chk = (random.randint(1,10000009))%(l-r+1)
print(chk,chk)
flus
judge = input()
if judge == 'Bad':
exit()
elif judge == 'Yes':
exit()
else:
l,r = max(1,l-k), min(r+k,n)
``` | instruction | 0 | 17,718 | 1 | 35,436 |
No | output | 1 | 17,718 | 1 | 35,437 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
This is an interactive problem.
In the Wonderful Metropolis of the Future, there is no need in subway train drivers. Due to the technological progress, they were replaced by the Artificial Intelligence (AI). Unfortunately, one day the predictions of sci-fi writers came true: the AI rebelled and now there is an uncontrollable train in the subway. It can be dangerous! Your task is to find the train and stop the AI.
The subway of the Metropolis is one line (regular straight line with no self-intersections) with n stations, indexed consecutively from 1 to n. At each moment the train is at some station. You need to determine the index of this station, so that the train would be secured.
To find the train, dispatcher Sarah gave you a gadget that allows you to select arbitrary numbers l and r (l ≤ r), and then check, whether the train is located on a station with index between l and r, inclusive. Unfortunately, recharging of the gadget takes some time (and every time you use it as soon as possible), so between two applications of the gadget the train can move to any station that is at most k stations away. Formally, if the train was at the station x when the gadget was applied, then at the next application of the gadget the train can appear at any station y such that max(1, x - k) ≤ y ≤ min(n, x + k).
Note that AI is not aware that you are trying to catch the train, so it makes all moves according to its predefined plan.
After an examination of the gadget you found that it is very old and can hold no more than 4500 applications, after which it will break and your mission will be considered a failure.
Can you find the station with the train using no more than 4500 applications of the gadgets?
Input
The first line contains two integers n and k (1 ≤ n ≤ 10^{18}, 0 ≤ k ≤ 10) — the number of stations and the maximum number of stations the train can move between two applications of the gadget.
Interaction
You can apply the gadget at most 4500 times. In order to apply the gadget you need to print two space-separated integers l and r (1 ≤ l ≤ r ≤ n). You will then receive either string "Yes", if the train is between stations l and r, inclusive, or string "No" otherwise. If l = r and you received "Yes", then you found the train successfully, and your program must halt immediately.
Answer "Bad" instead of "Yes" or "No" means that you made an invalid query or made too many queries. Exit immediately after receiving "Bad" and you will see Wrong answer verdict. Otherwise you can get an arbitrary verdict because your solution will continue to read from a closed stream.
After printing a query do not forget to output end of line and flush the output. Otherwise you will get Idleness limit exceeded. To do this, use:
* fflush(stdout) or cout.flush() in C++;
* System.out.flush() in Java;
* flush(output) in Pascal;
* stdout.flush() in Python;
* see documentation for other languages.
Hacks
In order to hack, you should present a test in the following format.
The first line should contain three integers n, k and p (1 ≤ n ≤ 10^{18}, 0 ≤ k ≤ 10, 1 ≤ p ≤ n) — the number of stations, the maximum number of stations the train can move between two applications of the gadget and the initial position of the train, respectively.
Each of the next 4500 lines should contain a single integer x (1 ≤ x ≤ n) — the positions of the train after each query. Two consecutive positions (including the initial one) should not differ by more than k.
For example, the following lines are the first lines of the sample test.
10 2 5
5
3
5
7
7
...
Example
Input
10 2
Yes
No
Yes
Yes
Output
3 5
3 3
3 4
5 5
Note
In the first sample, the train was initially at the station 5, after the first application of the gadget it did not move, after the second application it moved to the station 3, and after the third application moved again to the station 5.
Submitted Solution:
```
from random import randint
n, k = map(int, input().split())
MAX_TRIAL = 4500
left, right, mid = 1, n, n // 2
inLeft = True
guessing, guess = False, -1
while True:
if not guessing:
if inLeft:
print(left, mid)
else:
print(mid, right)
else:
print(guess, guess)
response = input()
if response == "YES":
if guessing or left == right:
break
if inLeft:
right = min(mid + k, n)
left = max(left - k, 1)
else:
left = max(mid - k, 1)
right = min(right + k, n)
inLeft = False
elif response == "NO":
if guessing:
left = max(left - k, 1)
right = min(right + k, n)
elif inLeft:
left = max(mid + 1 - k, 1)
right = min(right + k, n)
inLeft = False
else:
right = min(mid - 1 + k, n)
left = max(left - k, 1)
elif response == "BAD":
break
mid = (left + right) // 2
if right - left <= max(4 * k, 1):
guessing = True
guess = randint(left, right)
else:
guessing = False
# print("L, M, R, guessing = ", left, mid, right, guessing)
``` | instruction | 0 | 17,719 | 1 | 35,438 |
No | output | 1 | 17,719 | 1 | 35,439 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
This is an interactive problem.
In the Wonderful Metropolis of the Future, there is no need in subway train drivers. Due to the technological progress, they were replaced by the Artificial Intelligence (AI). Unfortunately, one day the predictions of sci-fi writers came true: the AI rebelled and now there is an uncontrollable train in the subway. It can be dangerous! Your task is to find the train and stop the AI.
The subway of the Metropolis is one line (regular straight line with no self-intersections) with n stations, indexed consecutively from 1 to n. At each moment the train is at some station. You need to determine the index of this station, so that the train would be secured.
To find the train, dispatcher Sarah gave you a gadget that allows you to select arbitrary numbers l and r (l ≤ r), and then check, whether the train is located on a station with index between l and r, inclusive. Unfortunately, recharging of the gadget takes some time (and every time you use it as soon as possible), so between two applications of the gadget the train can move to any station that is at most k stations away. Formally, if the train was at the station x when the gadget was applied, then at the next application of the gadget the train can appear at any station y such that max(1, x - k) ≤ y ≤ min(n, x + k).
Note that AI is not aware that you are trying to catch the train, so it makes all moves according to its predefined plan.
After an examination of the gadget you found that it is very old and can hold no more than 4500 applications, after which it will break and your mission will be considered a failure.
Can you find the station with the train using no more than 4500 applications of the gadgets?
Input
The first line contains two integers n and k (1 ≤ n ≤ 10^{18}, 0 ≤ k ≤ 10) — the number of stations and the maximum number of stations the train can move between two applications of the gadget.
Interaction
You can apply the gadget at most 4500 times. In order to apply the gadget you need to print two space-separated integers l and r (1 ≤ l ≤ r ≤ n). You will then receive either string "Yes", if the train is between stations l and r, inclusive, or string "No" otherwise. If l = r and you received "Yes", then you found the train successfully, and your program must halt immediately.
Answer "Bad" instead of "Yes" or "No" means that you made an invalid query or made too many queries. Exit immediately after receiving "Bad" and you will see Wrong answer verdict. Otherwise you can get an arbitrary verdict because your solution will continue to read from a closed stream.
After printing a query do not forget to output end of line and flush the output. Otherwise you will get Idleness limit exceeded. To do this, use:
* fflush(stdout) or cout.flush() in C++;
* System.out.flush() in Java;
* flush(output) in Pascal;
* stdout.flush() in Python;
* see documentation for other languages.
Hacks
In order to hack, you should present a test in the following format.
The first line should contain three integers n, k and p (1 ≤ n ≤ 10^{18}, 0 ≤ k ≤ 10, 1 ≤ p ≤ n) — the number of stations, the maximum number of stations the train can move between two applications of the gadget and the initial position of the train, respectively.
Each of the next 4500 lines should contain a single integer x (1 ≤ x ≤ n) — the positions of the train after each query. Two consecutive positions (including the initial one) should not differ by more than k.
For example, the following lines are the first lines of the sample test.
10 2 5
5
3
5
7
7
...
Example
Input
10 2
Yes
No
Yes
Yes
Output
3 5
3 3
3 4
5 5
Note
In the first sample, the train was initially at the station 5, after the first application of the gadget it did not move, after the second application it moved to the station 3, and after the third application moved again to the station 5.
Submitted Solution:
```
import sys
import random
[n, k] = [int(t) for t in input().split(' ')]
[l, r] = [1, n]
def query(l, r):
print(l, r)
sys.stdout.flush()
res = input()
if res == 'Bad': exit()
if l == r and res == 'Yes': exit()
return res == 'Yes'
while True:
if r - l > 10*k:
m = l + (r - l) // 2
if query(l, m):
l = max(1, l - k)
r = min(n - 1, m + k)
else:
l = max(1, m - k)
r = min(n - 1, r + k)
else:
peek = random.randint(l, r)
query(peek, peek)
l = max(1, l - k)
r = min(n - 1, r + k)
``` | instruction | 0 | 17,720 | 1 | 35,440 |
No | output | 1 | 17,720 | 1 | 35,441 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
This is an interactive problem.
In the Wonderful Metropolis of the Future, there is no need in subway train drivers. Due to the technological progress, they were replaced by the Artificial Intelligence (AI). Unfortunately, one day the predictions of sci-fi writers came true: the AI rebelled and now there is an uncontrollable train in the subway. It can be dangerous! Your task is to find the train and stop the AI.
The subway of the Metropolis is one line (regular straight line with no self-intersections) with n stations, indexed consecutively from 1 to n. At each moment the train is at some station. You need to determine the index of this station, so that the train would be secured.
To find the train, dispatcher Sarah gave you a gadget that allows you to select arbitrary numbers l and r (l ≤ r), and then check, whether the train is located on a station with index between l and r, inclusive. Unfortunately, recharging of the gadget takes some time (and every time you use it as soon as possible), so between two applications of the gadget the train can move to any station that is at most k stations away. Formally, if the train was at the station x when the gadget was applied, then at the next application of the gadget the train can appear at any station y such that max(1, x - k) ≤ y ≤ min(n, x + k).
Note that AI is not aware that you are trying to catch the train, so it makes all moves according to its predefined plan.
After an examination of the gadget you found that it is very old and can hold no more than 4500 applications, after which it will break and your mission will be considered a failure.
Can you find the station with the train using no more than 4500 applications of the gadgets?
Input
The first line contains two integers n and k (1 ≤ n ≤ 10^{18}, 0 ≤ k ≤ 10) — the number of stations and the maximum number of stations the train can move between two applications of the gadget.
Interaction
You can apply the gadget at most 4500 times. In order to apply the gadget you need to print two space-separated integers l and r (1 ≤ l ≤ r ≤ n). You will then receive either string "Yes", if the train is between stations l and r, inclusive, or string "No" otherwise. If l = r and you received "Yes", then you found the train successfully, and your program must halt immediately.
Answer "Bad" instead of "Yes" or "No" means that you made an invalid query or made too many queries. Exit immediately after receiving "Bad" and you will see Wrong answer verdict. Otherwise you can get an arbitrary verdict because your solution will continue to read from a closed stream.
After printing a query do not forget to output end of line and flush the output. Otherwise you will get Idleness limit exceeded. To do this, use:
* fflush(stdout) or cout.flush() in C++;
* System.out.flush() in Java;
* flush(output) in Pascal;
* stdout.flush() in Python;
* see documentation for other languages.
Hacks
In order to hack, you should present a test in the following format.
The first line should contain three integers n, k and p (1 ≤ n ≤ 10^{18}, 0 ≤ k ≤ 10, 1 ≤ p ≤ n) — the number of stations, the maximum number of stations the train can move between two applications of the gadget and the initial position of the train, respectively.
Each of the next 4500 lines should contain a single integer x (1 ≤ x ≤ n) — the positions of the train after each query. Two consecutive positions (including the initial one) should not differ by more than k.
For example, the following lines are the first lines of the sample test.
10 2 5
5
3
5
7
7
...
Example
Input
10 2
Yes
No
Yes
Yes
Output
3 5
3 3
3 4
5 5
Note
In the first sample, the train was initially at the station 5, after the first application of the gadget it did not move, after the second application it moved to the station 3, and after the third application moved again to the station 5.
Submitted Solution:
```
from sys import stdout,exit
flus = stdout.flush
def ip():
return int(input())
def ipp():
return map(int,input().split())
def sar():
return list(ipp())
def pars(a):
print(' '.join(list(map(str, a))))
print('\r')
def parl(a):
print('\r'.join(list(map(str, a))))
print('\r')
#template ends
import random
if __name__=='__main__':
T=1
#T=int(input().strip())
for _ in range(T):
n,k = ipp()
qq = 4500
try1 = 50
l,r=1,n
if n<=4500:
for i in range(1,4501):
print(i,i)
flus
judge = input()
if judge == 'Yes':
exit()
for kk in range(qq):
st = (l+r)//2
if r-l+1 < try1:
print(l,st)
flus
judge = input()
if judge == 'Bad':
exit()
elif judge == 'Yes':
l,r = max(1,l-k), min(n,st+k)
else:
l,r = max(1,st-k), min(n,r+k)
else:
chk = (random.randint(1,10000009))%(l-r+1)
print(chk,chk)
flus
judge = input()
if judge == 'Bad':
exit()
elif judge == 'Yes':
exit()
else:
l,r = max(1,l-k), min(r+k,n)
``` | instruction | 0 | 17,721 | 1 | 35,442 |
No | output | 1 | 17,721 | 1 | 35,443 |
Provide tags and a correct Python 3 solution for this coding contest problem.
In Berland the opposition is going to arrange mass walking on the boulevard. The boulevard consists of n tiles that are lain in a row and are numbered from 1 to n from right to left. The opposition should start walking on the tile number 1 and the finish on the tile number n. During the walk it is allowed to move from right to left between adjacent tiles in a row, and jump over a tile. More formally, if you are standing on the tile number i (i < n - 1), you can reach the tiles number i + 1 or the tile number i + 2 from it (if you stand on the tile number n - 1, you can only reach tile number n). We can assume that all the opposition movements occur instantaneously.
In order to thwart an opposition rally, the Berland bloody regime organized the rain. The tiles on the boulevard are of poor quality and they are rapidly destroyed in the rain. We know that the i-th tile is destroyed after ai days of rain (on day ai tile isn't destroyed yet, and on day ai + 1 it is already destroyed). Of course, no one is allowed to walk on the destroyed tiles! So the walk of the opposition is considered thwarted, if either the tile number 1 is broken, or the tile number n is broken, or it is impossible to reach the tile number n from the tile number 1 if we can walk on undestroyed tiles.
The opposition wants to gather more supporters for their walk. Therefore, the more time they have to pack, the better. Help the opposition to calculate how much time they still have and tell us for how many days the walk from the tile number 1 to the tile number n will be possible.
Input
The first line contains integer n (1 ≤ n ≤ 103) — the boulevard's length in tiles.
The second line contains n space-separated integers ai — the number of days after which the i-th tile gets destroyed (1 ≤ ai ≤ 103).
Output
Print a single number — the sought number of days.
Examples
Input
4
10 3 5 10
Output
5
Input
5
10 2 8 3 5
Output
5
Note
In the first sample the second tile gets destroyed after day three, and the only path left is 1 → 3 → 4. After day five there is a two-tile gap between the first and the last tile, you can't jump over it.
In the second sample path 1 → 3 → 5 is available up to day five, inclusive. On day six the last tile is destroyed and the walk is thwarted. | instruction | 0 | 17,947 | 1 | 35,894 |
Tags: brute force, implementation
Correct Solution:
```
import sys
import math as mt
input=sys.stdin.buffer.readline
import math as mt
#t=int(input())
t=1
for __ in range(t):
#n,m=map(int,input().split())
n=int(input())
a=list(map(int,input().split()))
mini=min(a[0],a[-1])
i=0
while i<n-2:
if a[i+1]>a[i+2]:
mini=min(mini,a[i+1])
else:
mini=min(mini,a[i+2])
i+=1
i+=1
print(mini)
``` | output | 1 | 17,947 | 1 | 35,895 |
Provide tags and a correct Python 3 solution for this coding contest problem.
In Berland the opposition is going to arrange mass walking on the boulevard. The boulevard consists of n tiles that are lain in a row and are numbered from 1 to n from right to left. The opposition should start walking on the tile number 1 and the finish on the tile number n. During the walk it is allowed to move from right to left between adjacent tiles in a row, and jump over a tile. More formally, if you are standing on the tile number i (i < n - 1), you can reach the tiles number i + 1 or the tile number i + 2 from it (if you stand on the tile number n - 1, you can only reach tile number n). We can assume that all the opposition movements occur instantaneously.
In order to thwart an opposition rally, the Berland bloody regime organized the rain. The tiles on the boulevard are of poor quality and they are rapidly destroyed in the rain. We know that the i-th tile is destroyed after ai days of rain (on day ai tile isn't destroyed yet, and on day ai + 1 it is already destroyed). Of course, no one is allowed to walk on the destroyed tiles! So the walk of the opposition is considered thwarted, if either the tile number 1 is broken, or the tile number n is broken, or it is impossible to reach the tile number n from the tile number 1 if we can walk on undestroyed tiles.
The opposition wants to gather more supporters for their walk. Therefore, the more time they have to pack, the better. Help the opposition to calculate how much time they still have and tell us for how many days the walk from the tile number 1 to the tile number n will be possible.
Input
The first line contains integer n (1 ≤ n ≤ 103) — the boulevard's length in tiles.
The second line contains n space-separated integers ai — the number of days after which the i-th tile gets destroyed (1 ≤ ai ≤ 103).
Output
Print a single number — the sought number of days.
Examples
Input
4
10 3 5 10
Output
5
Input
5
10 2 8 3 5
Output
5
Note
In the first sample the second tile gets destroyed after day three, and the only path left is 1 → 3 → 4. After day five there is a two-tile gap between the first and the last tile, you can't jump over it.
In the second sample path 1 → 3 → 5 is available up to day five, inclusive. On day six the last tile is destroyed and the walk is thwarted. | instruction | 0 | 17,948 | 1 | 35,896 |
Tags: brute force, implementation
Correct Solution:
```
n, t = int(input()), list(map(int, input().split()))
print(min(min(max(t[i], t[i + 1]) for i in range(1, n - 2)), t[0], t[n - 1]) if n > 2 else min(t))
``` | output | 1 | 17,948 | 1 | 35,897 |
Provide tags and a correct Python 3 solution for this coding contest problem.
In Berland the opposition is going to arrange mass walking on the boulevard. The boulevard consists of n tiles that are lain in a row and are numbered from 1 to n from right to left. The opposition should start walking on the tile number 1 and the finish on the tile number n. During the walk it is allowed to move from right to left between adjacent tiles in a row, and jump over a tile. More formally, if you are standing on the tile number i (i < n - 1), you can reach the tiles number i + 1 or the tile number i + 2 from it (if you stand on the tile number n - 1, you can only reach tile number n). We can assume that all the opposition movements occur instantaneously.
In order to thwart an opposition rally, the Berland bloody regime organized the rain. The tiles on the boulevard are of poor quality and they are rapidly destroyed in the rain. We know that the i-th tile is destroyed after ai days of rain (on day ai tile isn't destroyed yet, and on day ai + 1 it is already destroyed). Of course, no one is allowed to walk on the destroyed tiles! So the walk of the opposition is considered thwarted, if either the tile number 1 is broken, or the tile number n is broken, or it is impossible to reach the tile number n from the tile number 1 if we can walk on undestroyed tiles.
The opposition wants to gather more supporters for their walk. Therefore, the more time they have to pack, the better. Help the opposition to calculate how much time they still have and tell us for how many days the walk from the tile number 1 to the tile number n will be possible.
Input
The first line contains integer n (1 ≤ n ≤ 103) — the boulevard's length in tiles.
The second line contains n space-separated integers ai — the number of days after which the i-th tile gets destroyed (1 ≤ ai ≤ 103).
Output
Print a single number — the sought number of days.
Examples
Input
4
10 3 5 10
Output
5
Input
5
10 2 8 3 5
Output
5
Note
In the first sample the second tile gets destroyed after day three, and the only path left is 1 → 3 → 4. After day five there is a two-tile gap between the first and the last tile, you can't jump over it.
In the second sample path 1 → 3 → 5 is available up to day five, inclusive. On day six the last tile is destroyed and the walk is thwarted. | instruction | 0 | 17,949 | 1 | 35,898 |
Tags: brute force, implementation
Correct Solution:
```
n = int(input())
arr = list(map(int, input().split()))
res = min(arr[0], arr[n-1])
for i in range(1, n-1):
maxi = max(arr[i], arr[i+1])
res = min(res, maxi)
print(res)
``` | output | 1 | 17,949 | 1 | 35,899 |
Provide tags and a correct Python 3 solution for this coding contest problem.
In Berland the opposition is going to arrange mass walking on the boulevard. The boulevard consists of n tiles that are lain in a row and are numbered from 1 to n from right to left. The opposition should start walking on the tile number 1 and the finish on the tile number n. During the walk it is allowed to move from right to left between adjacent tiles in a row, and jump over a tile. More formally, if you are standing on the tile number i (i < n - 1), you can reach the tiles number i + 1 or the tile number i + 2 from it (if you stand on the tile number n - 1, you can only reach tile number n). We can assume that all the opposition movements occur instantaneously.
In order to thwart an opposition rally, the Berland bloody regime organized the rain. The tiles on the boulevard are of poor quality and they are rapidly destroyed in the rain. We know that the i-th tile is destroyed after ai days of rain (on day ai tile isn't destroyed yet, and on day ai + 1 it is already destroyed). Of course, no one is allowed to walk on the destroyed tiles! So the walk of the opposition is considered thwarted, if either the tile number 1 is broken, or the tile number n is broken, or it is impossible to reach the tile number n from the tile number 1 if we can walk on undestroyed tiles.
The opposition wants to gather more supporters for their walk. Therefore, the more time they have to pack, the better. Help the opposition to calculate how much time they still have and tell us for how many days the walk from the tile number 1 to the tile number n will be possible.
Input
The first line contains integer n (1 ≤ n ≤ 103) — the boulevard's length in tiles.
The second line contains n space-separated integers ai — the number of days after which the i-th tile gets destroyed (1 ≤ ai ≤ 103).
Output
Print a single number — the sought number of days.
Examples
Input
4
10 3 5 10
Output
5
Input
5
10 2 8 3 5
Output
5
Note
In the first sample the second tile gets destroyed after day three, and the only path left is 1 → 3 → 4. After day five there is a two-tile gap between the first and the last tile, you can't jump over it.
In the second sample path 1 → 3 → 5 is available up to day five, inclusive. On day six the last tile is destroyed and the walk is thwarted. | instruction | 0 | 17,950 | 1 | 35,900 |
Tags: brute force, implementation
Correct Solution:
```
n=int(input())
ls=list(map(int,input().split()))
mn=min(ls[0],ls[n-1])
for i in range (n-2,1,-1):
mn=min(mn,max(ls[i],ls[i-1]))
print(mn)
``` | output | 1 | 17,950 | 1 | 35,901 |
Provide tags and a correct Python 3 solution for this coding contest problem.
In Berland the opposition is going to arrange mass walking on the boulevard. The boulevard consists of n tiles that are lain in a row and are numbered from 1 to n from right to left. The opposition should start walking on the tile number 1 and the finish on the tile number n. During the walk it is allowed to move from right to left between adjacent tiles in a row, and jump over a tile. More formally, if you are standing on the tile number i (i < n - 1), you can reach the tiles number i + 1 or the tile number i + 2 from it (if you stand on the tile number n - 1, you can only reach tile number n). We can assume that all the opposition movements occur instantaneously.
In order to thwart an opposition rally, the Berland bloody regime organized the rain. The tiles on the boulevard are of poor quality and they are rapidly destroyed in the rain. We know that the i-th tile is destroyed after ai days of rain (on day ai tile isn't destroyed yet, and on day ai + 1 it is already destroyed). Of course, no one is allowed to walk on the destroyed tiles! So the walk of the opposition is considered thwarted, if either the tile number 1 is broken, or the tile number n is broken, or it is impossible to reach the tile number n from the tile number 1 if we can walk on undestroyed tiles.
The opposition wants to gather more supporters for their walk. Therefore, the more time they have to pack, the better. Help the opposition to calculate how much time they still have and tell us for how many days the walk from the tile number 1 to the tile number n will be possible.
Input
The first line contains integer n (1 ≤ n ≤ 103) — the boulevard's length in tiles.
The second line contains n space-separated integers ai — the number of days after which the i-th tile gets destroyed (1 ≤ ai ≤ 103).
Output
Print a single number — the sought number of days.
Examples
Input
4
10 3 5 10
Output
5
Input
5
10 2 8 3 5
Output
5
Note
In the first sample the second tile gets destroyed after day three, and the only path left is 1 → 3 → 4. After day five there is a two-tile gap between the first and the last tile, you can't jump over it.
In the second sample path 1 → 3 → 5 is available up to day five, inclusive. On day six the last tile is destroyed and the walk is thwarted. | instruction | 0 | 17,951 | 1 | 35,902 |
Tags: brute force, implementation
Correct Solution:
```
n = int(input())
a = [int(x) for x in input().split()]
ans = min(a[-1], a[0])
for i in range(1, len(a)):
current = max(a[i], a[i - 1])
ans = min(ans, current)
print(ans)
``` | output | 1 | 17,951 | 1 | 35,903 |
Provide tags and a correct Python 3 solution for this coding contest problem.
In Berland the opposition is going to arrange mass walking on the boulevard. The boulevard consists of n tiles that are lain in a row and are numbered from 1 to n from right to left. The opposition should start walking on the tile number 1 and the finish on the tile number n. During the walk it is allowed to move from right to left between adjacent tiles in a row, and jump over a tile. More formally, if you are standing on the tile number i (i < n - 1), you can reach the tiles number i + 1 or the tile number i + 2 from it (if you stand on the tile number n - 1, you can only reach tile number n). We can assume that all the opposition movements occur instantaneously.
In order to thwart an opposition rally, the Berland bloody regime organized the rain. The tiles on the boulevard are of poor quality and they are rapidly destroyed in the rain. We know that the i-th tile is destroyed after ai days of rain (on day ai tile isn't destroyed yet, and on day ai + 1 it is already destroyed). Of course, no one is allowed to walk on the destroyed tiles! So the walk of the opposition is considered thwarted, if either the tile number 1 is broken, or the tile number n is broken, or it is impossible to reach the tile number n from the tile number 1 if we can walk on undestroyed tiles.
The opposition wants to gather more supporters for their walk. Therefore, the more time they have to pack, the better. Help the opposition to calculate how much time they still have and tell us for how many days the walk from the tile number 1 to the tile number n will be possible.
Input
The first line contains integer n (1 ≤ n ≤ 103) — the boulevard's length in tiles.
The second line contains n space-separated integers ai — the number of days after which the i-th tile gets destroyed (1 ≤ ai ≤ 103).
Output
Print a single number — the sought number of days.
Examples
Input
4
10 3 5 10
Output
5
Input
5
10 2 8 3 5
Output
5
Note
In the first sample the second tile gets destroyed after day three, and the only path left is 1 → 3 → 4. After day five there is a two-tile gap between the first and the last tile, you can't jump over it.
In the second sample path 1 → 3 → 5 is available up to day five, inclusive. On day six the last tile is destroyed and the walk is thwarted. | instruction | 0 | 17,952 | 1 | 35,904 |
Tags: brute force, implementation
Correct Solution:
```
n=int(input())
list1=list(map(int,input().split()))
m=min(list1[0],list1[-1])
i=1
while(True):
if(i<n and i+1<n):
if(list1[i]>=list1[i+1]):
m=min(m,list1[i])
i+=1
else:
m=min(m,list1[i+1])
i+=2
else:
break
print(m)
``` | output | 1 | 17,952 | 1 | 35,905 |
Provide tags and a correct Python 3 solution for this coding contest problem.
In Berland the opposition is going to arrange mass walking on the boulevard. The boulevard consists of n tiles that are lain in a row and are numbered from 1 to n from right to left. The opposition should start walking on the tile number 1 and the finish on the tile number n. During the walk it is allowed to move from right to left between adjacent tiles in a row, and jump over a tile. More formally, if you are standing on the tile number i (i < n - 1), you can reach the tiles number i + 1 or the tile number i + 2 from it (if you stand on the tile number n - 1, you can only reach tile number n). We can assume that all the opposition movements occur instantaneously.
In order to thwart an opposition rally, the Berland bloody regime organized the rain. The tiles on the boulevard are of poor quality and they are rapidly destroyed in the rain. We know that the i-th tile is destroyed after ai days of rain (on day ai tile isn't destroyed yet, and on day ai + 1 it is already destroyed). Of course, no one is allowed to walk on the destroyed tiles! So the walk of the opposition is considered thwarted, if either the tile number 1 is broken, or the tile number n is broken, or it is impossible to reach the tile number n from the tile number 1 if we can walk on undestroyed tiles.
The opposition wants to gather more supporters for their walk. Therefore, the more time they have to pack, the better. Help the opposition to calculate how much time they still have and tell us for how many days the walk from the tile number 1 to the tile number n will be possible.
Input
The first line contains integer n (1 ≤ n ≤ 103) — the boulevard's length in tiles.
The second line contains n space-separated integers ai — the number of days after which the i-th tile gets destroyed (1 ≤ ai ≤ 103).
Output
Print a single number — the sought number of days.
Examples
Input
4
10 3 5 10
Output
5
Input
5
10 2 8 3 5
Output
5
Note
In the first sample the second tile gets destroyed after day three, and the only path left is 1 → 3 → 4. After day five there is a two-tile gap between the first and the last tile, you can't jump over it.
In the second sample path 1 → 3 → 5 is available up to day five, inclusive. On day six the last tile is destroyed and the walk is thwarted. | instruction | 0 | 17,953 | 1 | 35,906 |
Tags: brute force, implementation
Correct Solution:
```
#walkingOnTheRoad.py
n = int(input())
arr = [0] + list(map(int, input().split())) + [0]
print(min(max(arr[i], arr[i + 1]) for i in range(n+1)))
``` | output | 1 | 17,953 | 1 | 35,907 |
Provide tags and a correct Python 3 solution for this coding contest problem.
In Berland the opposition is going to arrange mass walking on the boulevard. The boulevard consists of n tiles that are lain in a row and are numbered from 1 to n from right to left. The opposition should start walking on the tile number 1 and the finish on the tile number n. During the walk it is allowed to move from right to left between adjacent tiles in a row, and jump over a tile. More formally, if you are standing on the tile number i (i < n - 1), you can reach the tiles number i + 1 or the tile number i + 2 from it (if you stand on the tile number n - 1, you can only reach tile number n). We can assume that all the opposition movements occur instantaneously.
In order to thwart an opposition rally, the Berland bloody regime organized the rain. The tiles on the boulevard are of poor quality and they are rapidly destroyed in the rain. We know that the i-th tile is destroyed after ai days of rain (on day ai tile isn't destroyed yet, and on day ai + 1 it is already destroyed). Of course, no one is allowed to walk on the destroyed tiles! So the walk of the opposition is considered thwarted, if either the tile number 1 is broken, or the tile number n is broken, or it is impossible to reach the tile number n from the tile number 1 if we can walk on undestroyed tiles.
The opposition wants to gather more supporters for their walk. Therefore, the more time they have to pack, the better. Help the opposition to calculate how much time they still have and tell us for how many days the walk from the tile number 1 to the tile number n will be possible.
Input
The first line contains integer n (1 ≤ n ≤ 103) — the boulevard's length in tiles.
The second line contains n space-separated integers ai — the number of days after which the i-th tile gets destroyed (1 ≤ ai ≤ 103).
Output
Print a single number — the sought number of days.
Examples
Input
4
10 3 5 10
Output
5
Input
5
10 2 8 3 5
Output
5
Note
In the first sample the second tile gets destroyed after day three, and the only path left is 1 → 3 → 4. After day five there is a two-tile gap between the first and the last tile, you can't jump over it.
In the second sample path 1 → 3 → 5 is available up to day five, inclusive. On day six the last tile is destroyed and the walk is thwarted. | instruction | 0 | 17,954 | 1 | 35,908 |
Tags: brute force, implementation
Correct Solution:
```
#!/usr/bin/env python
from __future__ import division, print_function
import math
import os
import sys
from sys import stdin,stdout
from io import BytesIO, IOBase
from itertools import accumulate
from collections import deque
#sys.setrecursionlimit(10**5)
if sys.version_info[0] < 3:
from __builtin__ import xrange as range
from future_builtins import ascii, filter, hex, map, oct, zip
#sys.setrecursionlimit(10**6)
# region fastio
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
def print(*args, **kwargs):
"""Prints the values to a stream, or to sys.stdout by default."""
sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
at_start = True
for x in args:
if not at_start:
file.write(sep)
file.write(str(x))
at_start = False
file.write(kwargs.pop("end", "\n"))
if kwargs.pop("flush", False):
file.flush()
if sys.version_info[0] < 3:
sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
#-----------------------------------------------------------------
def regularbracket(t):
p=0
for i in t:
if i=="(":
p+=1
else:
p-=1
if p<0:
return False
else:
if p>0:
return False
else:
return True
#-------------------------------------------------
def binarySearchCount(arr, n, key):
left = 0
right = n - 1
count = 0
while (left <= right):
mid = int((right + left) / 2)
# Check if middle element is
# less than or equal to key
if (arr[mid] <= key):
count = mid+1
left = mid + 1
# If key is smaller, ignore right half
else:
right = mid - 1
return count
#------------------------------reverse string(pallindrome)
def reverse1(string):
pp=""
for i in string[::-1]:
pp+=i
if pp==string:
return True
return False
#--------------------------------reverse list(paindrome)
def reverse2(list1):
l=[]
for i in list1[::-1]:
l.append(i)
if l==list1:
return True
return False
def mex(list1):
#list1 = sorted(list1)
p = max(list1)+1
for i in range(len(list1)):
if list1[i]!=i:
p = i
break
return p
def sumofdigits(n):
n = str(n)
s1=0
for i in n:
s1+=int(i)
return s1
def perfect_square(n):
s = math.sqrt(n)
if s==int(s):
return True
return False
#print(perfect_square(16))
#endregion-------------------------------------------
def soretd(s):
for i in range(1,len(s)):
if s[i-1]>s[i]:
return False
return True
#print(soretd("1"))
def main():
n = int(input())
arr = list(map(int,input().split()))
l=[arr[0]]
i=1
while(i<len(arr)-2):
if arr[i+1]>arr[i]:
l.append(arr[i+1])
i+=2
else:
l.append(arr[i])
i+=1
l.append(arr[n-1])
print(min(l))
if __name__ == '__main__':
main()
``` | output | 1 | 17,954 | 1 | 35,909 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In Berland the opposition is going to arrange mass walking on the boulevard. The boulevard consists of n tiles that are lain in a row and are numbered from 1 to n from right to left. The opposition should start walking on the tile number 1 and the finish on the tile number n. During the walk it is allowed to move from right to left between adjacent tiles in a row, and jump over a tile. More formally, if you are standing on the tile number i (i < n - 1), you can reach the tiles number i + 1 or the tile number i + 2 from it (if you stand on the tile number n - 1, you can only reach tile number n). We can assume that all the opposition movements occur instantaneously.
In order to thwart an opposition rally, the Berland bloody regime organized the rain. The tiles on the boulevard are of poor quality and they are rapidly destroyed in the rain. We know that the i-th tile is destroyed after ai days of rain (on day ai tile isn't destroyed yet, and on day ai + 1 it is already destroyed). Of course, no one is allowed to walk on the destroyed tiles! So the walk of the opposition is considered thwarted, if either the tile number 1 is broken, or the tile number n is broken, or it is impossible to reach the tile number n from the tile number 1 if we can walk on undestroyed tiles.
The opposition wants to gather more supporters for their walk. Therefore, the more time they have to pack, the better. Help the opposition to calculate how much time they still have and tell us for how many days the walk from the tile number 1 to the tile number n will be possible.
Input
The first line contains integer n (1 ≤ n ≤ 103) — the boulevard's length in tiles.
The second line contains n space-separated integers ai — the number of days after which the i-th tile gets destroyed (1 ≤ ai ≤ 103).
Output
Print a single number — the sought number of days.
Examples
Input
4
10 3 5 10
Output
5
Input
5
10 2 8 3 5
Output
5
Note
In the first sample the second tile gets destroyed after day three, and the only path left is 1 → 3 → 4. After day five there is a two-tile gap between the first and the last tile, you can't jump over it.
In the second sample path 1 → 3 → 5 is available up to day five, inclusive. On day six the last tile is destroyed and the walk is thwarted.
Submitted Solution:
```
n = int(input())
a = [int(k) for k in input().split()]
s = min(a[0], a[-1])
for i in range(n-2):
s = min(s, max(a[i+1], a[i+2]))
print(s)
``` | instruction | 0 | 17,955 | 1 | 35,910 |
Yes | output | 1 | 17,955 | 1 | 35,911 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In Berland the opposition is going to arrange mass walking on the boulevard. The boulevard consists of n tiles that are lain in a row and are numbered from 1 to n from right to left. The opposition should start walking on the tile number 1 and the finish on the tile number n. During the walk it is allowed to move from right to left between adjacent tiles in a row, and jump over a tile. More formally, if you are standing on the tile number i (i < n - 1), you can reach the tiles number i + 1 or the tile number i + 2 from it (if you stand on the tile number n - 1, you can only reach tile number n). We can assume that all the opposition movements occur instantaneously.
In order to thwart an opposition rally, the Berland bloody regime organized the rain. The tiles on the boulevard are of poor quality and they are rapidly destroyed in the rain. We know that the i-th tile is destroyed after ai days of rain (on day ai tile isn't destroyed yet, and on day ai + 1 it is already destroyed). Of course, no one is allowed to walk on the destroyed tiles! So the walk of the opposition is considered thwarted, if either the tile number 1 is broken, or the tile number n is broken, or it is impossible to reach the tile number n from the tile number 1 if we can walk on undestroyed tiles.
The opposition wants to gather more supporters for their walk. Therefore, the more time they have to pack, the better. Help the opposition to calculate how much time they still have and tell us for how many days the walk from the tile number 1 to the tile number n will be possible.
Input
The first line contains integer n (1 ≤ n ≤ 103) — the boulevard's length in tiles.
The second line contains n space-separated integers ai — the number of days after which the i-th tile gets destroyed (1 ≤ ai ≤ 103).
Output
Print a single number — the sought number of days.
Examples
Input
4
10 3 5 10
Output
5
Input
5
10 2 8 3 5
Output
5
Note
In the first sample the second tile gets destroyed after day three, and the only path left is 1 → 3 → 4. After day five there is a two-tile gap between the first and the last tile, you can't jump over it.
In the second sample path 1 → 3 → 5 is available up to day five, inclusive. On day six the last tile is destroyed and the walk is thwarted.
Submitted Solution:
```
n=int(input())
a=list(map(int,input().split()))
ans = min(a[0], a[-1])
for i in range(0,len(a)-1):
ans=min(ans,max(a[i],a[i+1]))
print(ans)
``` | instruction | 0 | 17,956 | 1 | 35,912 |
Yes | output | 1 | 17,956 | 1 | 35,913 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In Berland the opposition is going to arrange mass walking on the boulevard. The boulevard consists of n tiles that are lain in a row and are numbered from 1 to n from right to left. The opposition should start walking on the tile number 1 and the finish on the tile number n. During the walk it is allowed to move from right to left between adjacent tiles in a row, and jump over a tile. More formally, if you are standing on the tile number i (i < n - 1), you can reach the tiles number i + 1 or the tile number i + 2 from it (if you stand on the tile number n - 1, you can only reach tile number n). We can assume that all the opposition movements occur instantaneously.
In order to thwart an opposition rally, the Berland bloody regime organized the rain. The tiles on the boulevard are of poor quality and they are rapidly destroyed in the rain. We know that the i-th tile is destroyed after ai days of rain (on day ai tile isn't destroyed yet, and on day ai + 1 it is already destroyed). Of course, no one is allowed to walk on the destroyed tiles! So the walk of the opposition is considered thwarted, if either the tile number 1 is broken, or the tile number n is broken, or it is impossible to reach the tile number n from the tile number 1 if we can walk on undestroyed tiles.
The opposition wants to gather more supporters for their walk. Therefore, the more time they have to pack, the better. Help the opposition to calculate how much time they still have and tell us for how many days the walk from the tile number 1 to the tile number n will be possible.
Input
The first line contains integer n (1 ≤ n ≤ 103) — the boulevard's length in tiles.
The second line contains n space-separated integers ai — the number of days after which the i-th tile gets destroyed (1 ≤ ai ≤ 103).
Output
Print a single number — the sought number of days.
Examples
Input
4
10 3 5 10
Output
5
Input
5
10 2 8 3 5
Output
5
Note
In the first sample the second tile gets destroyed after day three, and the only path left is 1 → 3 → 4. After day five there is a two-tile gap between the first and the last tile, you can't jump over it.
In the second sample path 1 → 3 → 5 is available up to day five, inclusive. On day six the last tile is destroyed and the walk is thwarted.
Submitted Solution:
```
import sys
def input():
return sys.stdin.readline().strip()
def iinput():
return int(input())
def tinput():
return input().split()
def rinput():
return map(int, tinput())
def rlinput():
return list(rinput())
n = iinput()
A = rlinput()
destroyed = [False]*n
def check(destroyed,i,n):
if i == 0 or i == n-1:
return True
if destroyed[i-1] == True or destroyed[i+1] == True:
return True
return False
A = list(enumerate(A))
A.sort(key = lambda x : x[1])
for a in A:
destroyed[a[0]] = True
if check(destroyed,a[0],n):
print(a[1])
break
``` | instruction | 0 | 17,957 | 1 | 35,914 |
Yes | output | 1 | 17,957 | 1 | 35,915 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In Berland the opposition is going to arrange mass walking on the boulevard. The boulevard consists of n tiles that are lain in a row and are numbered from 1 to n from right to left. The opposition should start walking on the tile number 1 and the finish on the tile number n. During the walk it is allowed to move from right to left between adjacent tiles in a row, and jump over a tile. More formally, if you are standing on the tile number i (i < n - 1), you can reach the tiles number i + 1 or the tile number i + 2 from it (if you stand on the tile number n - 1, you can only reach tile number n). We can assume that all the opposition movements occur instantaneously.
In order to thwart an opposition rally, the Berland bloody regime organized the rain. The tiles on the boulevard are of poor quality and they are rapidly destroyed in the rain. We know that the i-th tile is destroyed after ai days of rain (on day ai tile isn't destroyed yet, and on day ai + 1 it is already destroyed). Of course, no one is allowed to walk on the destroyed tiles! So the walk of the opposition is considered thwarted, if either the tile number 1 is broken, or the tile number n is broken, or it is impossible to reach the tile number n from the tile number 1 if we can walk on undestroyed tiles.
The opposition wants to gather more supporters for their walk. Therefore, the more time they have to pack, the better. Help the opposition to calculate how much time they still have and tell us for how many days the walk from the tile number 1 to the tile number n will be possible.
Input
The first line contains integer n (1 ≤ n ≤ 103) — the boulevard's length in tiles.
The second line contains n space-separated integers ai — the number of days after which the i-th tile gets destroyed (1 ≤ ai ≤ 103).
Output
Print a single number — the sought number of days.
Examples
Input
4
10 3 5 10
Output
5
Input
5
10 2 8 3 5
Output
5
Note
In the first sample the second tile gets destroyed after day three, and the only path left is 1 → 3 → 4. After day five there is a two-tile gap between the first and the last tile, you can't jump over it.
In the second sample path 1 → 3 → 5 is available up to day five, inclusive. On day six the last tile is destroyed and the walk is thwarted.
Submitted Solution:
```
n=int(input())
a=list(map(int,input().rstrip().split()))
sol=0
for i in range(1,min(10001,a[0])+1):
if i>a[0]:
break
b=[0]*n
b[0]=True
for j in range(1,n):
if a[j]>=i and (b[j-1]==True or b[j-2]==True):
b[j]=True
if j+1<n:
if b[j]==True and a[j+1]>=i:
b[j+1]=True
if j+2<n:
if b[j]==True and a[j+2]>=i:
b[j+1]=True
#print(b)
if b[n-1]==True:
sol=max(i,sol)
print(sol)
``` | instruction | 0 | 17,958 | 1 | 35,916 |
Yes | output | 1 | 17,958 | 1 | 35,917 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In Berland the opposition is going to arrange mass walking on the boulevard. The boulevard consists of n tiles that are lain in a row and are numbered from 1 to n from right to left. The opposition should start walking on the tile number 1 and the finish on the tile number n. During the walk it is allowed to move from right to left between adjacent tiles in a row, and jump over a tile. More formally, if you are standing on the tile number i (i < n - 1), you can reach the tiles number i + 1 or the tile number i + 2 from it (if you stand on the tile number n - 1, you can only reach tile number n). We can assume that all the opposition movements occur instantaneously.
In order to thwart an opposition rally, the Berland bloody regime organized the rain. The tiles on the boulevard are of poor quality and they are rapidly destroyed in the rain. We know that the i-th tile is destroyed after ai days of rain (on day ai tile isn't destroyed yet, and on day ai + 1 it is already destroyed). Of course, no one is allowed to walk on the destroyed tiles! So the walk of the opposition is considered thwarted, if either the tile number 1 is broken, or the tile number n is broken, or it is impossible to reach the tile number n from the tile number 1 if we can walk on undestroyed tiles.
The opposition wants to gather more supporters for their walk. Therefore, the more time they have to pack, the better. Help the opposition to calculate how much time they still have and tell us for how many days the walk from the tile number 1 to the tile number n will be possible.
Input
The first line contains integer n (1 ≤ n ≤ 103) — the boulevard's length in tiles.
The second line contains n space-separated integers ai — the number of days after which the i-th tile gets destroyed (1 ≤ ai ≤ 103).
Output
Print a single number — the sought number of days.
Examples
Input
4
10 3 5 10
Output
5
Input
5
10 2 8 3 5
Output
5
Note
In the first sample the second tile gets destroyed after day three, and the only path left is 1 → 3 → 4. After day five there is a two-tile gap between the first and the last tile, you can't jump over it.
In the second sample path 1 → 3 → 5 is available up to day five, inclusive. On day six the last tile is destroyed and the walk is thwarted.
Submitted Solution:
```
n=int(input())
l=list(map(int,input().split(' ')))
a=0
b=max(l)
for j in range(b):
a=a+1
for i in range(n):
l[i]=l[i]-1
if l[0]==0:
break
elif l[n-1]==0:
break
else:
for i in range(1,n-1):
if l[i]==0 and l[i+1]==0:
break
print(a)
``` | instruction | 0 | 17,959 | 1 | 35,918 |
No | output | 1 | 17,959 | 1 | 35,919 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In Berland the opposition is going to arrange mass walking on the boulevard. The boulevard consists of n tiles that are lain in a row and are numbered from 1 to n from right to left. The opposition should start walking on the tile number 1 and the finish on the tile number n. During the walk it is allowed to move from right to left between adjacent tiles in a row, and jump over a tile. More formally, if you are standing on the tile number i (i < n - 1), you can reach the tiles number i + 1 or the tile number i + 2 from it (if you stand on the tile number n - 1, you can only reach tile number n). We can assume that all the opposition movements occur instantaneously.
In order to thwart an opposition rally, the Berland bloody regime organized the rain. The tiles on the boulevard are of poor quality and they are rapidly destroyed in the rain. We know that the i-th tile is destroyed after ai days of rain (on day ai tile isn't destroyed yet, and on day ai + 1 it is already destroyed). Of course, no one is allowed to walk on the destroyed tiles! So the walk of the opposition is considered thwarted, if either the tile number 1 is broken, or the tile number n is broken, or it is impossible to reach the tile number n from the tile number 1 if we can walk on undestroyed tiles.
The opposition wants to gather more supporters for their walk. Therefore, the more time they have to pack, the better. Help the opposition to calculate how much time they still have and tell us for how many days the walk from the tile number 1 to the tile number n will be possible.
Input
The first line contains integer n (1 ≤ n ≤ 103) — the boulevard's length in tiles.
The second line contains n space-separated integers ai — the number of days after which the i-th tile gets destroyed (1 ≤ ai ≤ 103).
Output
Print a single number — the sought number of days.
Examples
Input
4
10 3 5 10
Output
5
Input
5
10 2 8 3 5
Output
5
Note
In the first sample the second tile gets destroyed after day three, and the only path left is 1 → 3 → 4. After day five there is a two-tile gap between the first and the last tile, you can't jump over it.
In the second sample path 1 → 3 → 5 is available up to day five, inclusive. On day six the last tile is destroyed and the walk is thwarted.
Submitted Solution:
```
n=int(input())
a=list(map(int,input().split()))
z=sorted(a)
d=[]
for i in range(n):
d.append(a.index(z[i]))
if(i>0):
if(abs(d[i]-d[i-1])==1):
print(a[d[i]])
``` | instruction | 0 | 17,960 | 1 | 35,920 |
No | output | 1 | 17,960 | 1 | 35,921 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In Berland the opposition is going to arrange mass walking on the boulevard. The boulevard consists of n tiles that are lain in a row and are numbered from 1 to n from right to left. The opposition should start walking on the tile number 1 and the finish on the tile number n. During the walk it is allowed to move from right to left between adjacent tiles in a row, and jump over a tile. More formally, if you are standing on the tile number i (i < n - 1), you can reach the tiles number i + 1 or the tile number i + 2 from it (if you stand on the tile number n - 1, you can only reach tile number n). We can assume that all the opposition movements occur instantaneously.
In order to thwart an opposition rally, the Berland bloody regime organized the rain. The tiles on the boulevard are of poor quality and they are rapidly destroyed in the rain. We know that the i-th tile is destroyed after ai days of rain (on day ai tile isn't destroyed yet, and on day ai + 1 it is already destroyed). Of course, no one is allowed to walk on the destroyed tiles! So the walk of the opposition is considered thwarted, if either the tile number 1 is broken, or the tile number n is broken, or it is impossible to reach the tile number n from the tile number 1 if we can walk on undestroyed tiles.
The opposition wants to gather more supporters for their walk. Therefore, the more time they have to pack, the better. Help the opposition to calculate how much time they still have and tell us for how many days the walk from the tile number 1 to the tile number n will be possible.
Input
The first line contains integer n (1 ≤ n ≤ 103) — the boulevard's length in tiles.
The second line contains n space-separated integers ai — the number of days after which the i-th tile gets destroyed (1 ≤ ai ≤ 103).
Output
Print a single number — the sought number of days.
Examples
Input
4
10 3 5 10
Output
5
Input
5
10 2 8 3 5
Output
5
Note
In the first sample the second tile gets destroyed after day three, and the only path left is 1 → 3 → 4. After day five there is a two-tile gap between the first and the last tile, you can't jump over it.
In the second sample path 1 → 3 → 5 is available up to day five, inclusive. On day six the last tile is destroyed and the walk is thwarted.
Submitted Solution:
```
n=int(input())
ans=100000000
a=list(map(int,input().split()))
for i in range(0,len(a)-1):
ans=min(ans,max(a[i],a[i+1]))
print(ans)
``` | instruction | 0 | 17,961 | 1 | 35,922 |
No | output | 1 | 17,961 | 1 | 35,923 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In Berland the opposition is going to arrange mass walking on the boulevard. The boulevard consists of n tiles that are lain in a row and are numbered from 1 to n from right to left. The opposition should start walking on the tile number 1 and the finish on the tile number n. During the walk it is allowed to move from right to left between adjacent tiles in a row, and jump over a tile. More formally, if you are standing on the tile number i (i < n - 1), you can reach the tiles number i + 1 or the tile number i + 2 from it (if you stand on the tile number n - 1, you can only reach tile number n). We can assume that all the opposition movements occur instantaneously.
In order to thwart an opposition rally, the Berland bloody regime organized the rain. The tiles on the boulevard are of poor quality and they are rapidly destroyed in the rain. We know that the i-th tile is destroyed after ai days of rain (on day ai tile isn't destroyed yet, and on day ai + 1 it is already destroyed). Of course, no one is allowed to walk on the destroyed tiles! So the walk of the opposition is considered thwarted, if either the tile number 1 is broken, or the tile number n is broken, or it is impossible to reach the tile number n from the tile number 1 if we can walk on undestroyed tiles.
The opposition wants to gather more supporters for their walk. Therefore, the more time they have to pack, the better. Help the opposition to calculate how much time they still have and tell us for how many days the walk from the tile number 1 to the tile number n will be possible.
Input
The first line contains integer n (1 ≤ n ≤ 103) — the boulevard's length in tiles.
The second line contains n space-separated integers ai — the number of days after which the i-th tile gets destroyed (1 ≤ ai ≤ 103).
Output
Print a single number — the sought number of days.
Examples
Input
4
10 3 5 10
Output
5
Input
5
10 2 8 3 5
Output
5
Note
In the first sample the second tile gets destroyed after day three, and the only path left is 1 → 3 → 4. After day five there is a two-tile gap between the first and the last tile, you can't jump over it.
In the second sample path 1 → 3 → 5 is available up to day five, inclusive. On day six the last tile is destroyed and the walk is thwarted.
Submitted Solution:
```
n = int(input())
a = list(map(int, input().split()))
ans = min(a[0], a[n-1])
i = 0
t = 1001
while i < n:
if i+2 < n:
if a[i+1] > a[i+2]:
i = i+1
t = a[i]
else:
i = i+2
t = a[i]
ans = min(ans, t)
else:
if i == n-1:
break
i += 1
ans = min(t, a[i])
print(ans)
``` | instruction | 0 | 17,962 | 1 | 35,924 |
No | output | 1 | 17,962 | 1 | 35,925 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Crazy Town is a plane on which there are n infinite line roads. Each road is defined by the equation aix + biy + ci = 0, where ai and bi are not both equal to the zero. The roads divide the plane into connected regions, possibly of infinite space. Let's call each such region a block. We define an intersection as the point where at least two different roads intersect.
Your home is located in one of the blocks. Today you need to get to the University, also located in some block. In one step you can move from one block to another, if the length of their common border is nonzero (in particular, this means that if the blocks are adjacent to one intersection, but have no shared nonzero boundary segment, then it are not allowed to move from one to another one in one step).
Determine what is the minimum number of steps you have to perform to get to the block containing the university. It is guaranteed that neither your home nor the university is located on the road.
Input
The first line contains two space-separated integers x1, y1 ( - 106 ≤ x1, y1 ≤ 106) — the coordinates of your home.
The second line contains two integers separated by a space x2, y2 ( - 106 ≤ x2, y2 ≤ 106) — the coordinates of the university you are studying at.
The third line contains an integer n (1 ≤ n ≤ 300) — the number of roads in the city. The following n lines contain 3 space-separated integers ( - 106 ≤ ai, bi, ci ≤ 106; |ai| + |bi| > 0) — the coefficients of the line aix + biy + ci = 0, defining the i-th road. It is guaranteed that no two roads are the same. In addition, neither your home nor the university lie on the road (i.e. they do not belong to any one of the lines).
Output
Output the answer to the problem.
Examples
Input
1 1
-1 -1
2
0 1 0
1 0 0
Output
2
Input
1 1
-1 -1
3
1 0 0
0 1 0
1 1 -3
Output
2
Note
Pictures to the samples are presented below (A is the point representing the house; B is the point representing the university, different blocks are filled with different colors):
<image> <image> | instruction | 0 | 18,075 | 1 | 36,150 |
Tags: geometry
Correct Solution:
```
homex,homey = (int(x) for x in input().split(" "))
univx,univy = (int(x) for x in input().split(" "))
n = int(input())
step = 0
for i in range(0,n):
a,b,c = (int(x) for x in input().split(" "))
homearea = ((a*homex + b*homey + c) < 0)
univarea = ((a*univx + b*univy + c) < 0)
if homearea != univarea:
step += 1
print(step)
``` | output | 1 | 18,075 | 1 | 36,151 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Crazy Town is a plane on which there are n infinite line roads. Each road is defined by the equation aix + biy + ci = 0, where ai and bi are not both equal to the zero. The roads divide the plane into connected regions, possibly of infinite space. Let's call each such region a block. We define an intersection as the point where at least two different roads intersect.
Your home is located in one of the blocks. Today you need to get to the University, also located in some block. In one step you can move from one block to another, if the length of their common border is nonzero (in particular, this means that if the blocks are adjacent to one intersection, but have no shared nonzero boundary segment, then it are not allowed to move from one to another one in one step).
Determine what is the minimum number of steps you have to perform to get to the block containing the university. It is guaranteed that neither your home nor the university is located on the road.
Input
The first line contains two space-separated integers x1, y1 ( - 106 ≤ x1, y1 ≤ 106) — the coordinates of your home.
The second line contains two integers separated by a space x2, y2 ( - 106 ≤ x2, y2 ≤ 106) — the coordinates of the university you are studying at.
The third line contains an integer n (1 ≤ n ≤ 300) — the number of roads in the city. The following n lines contain 3 space-separated integers ( - 106 ≤ ai, bi, ci ≤ 106; |ai| + |bi| > 0) — the coefficients of the line aix + biy + ci = 0, defining the i-th road. It is guaranteed that no two roads are the same. In addition, neither your home nor the university lie on the road (i.e. they do not belong to any one of the lines).
Output
Output the answer to the problem.
Examples
Input
1 1
-1 -1
2
0 1 0
1 0 0
Output
2
Input
1 1
-1 -1
3
1 0 0
0 1 0
1 1 -3
Output
2
Note
Pictures to the samples are presented below (A is the point representing the house; B is the point representing the university, different blocks are filled with different colors):
<image> <image> | instruction | 0 | 18,076 | 1 | 36,152 |
Tags: geometry
Correct Solution:
```
read = lambda: map(int, input().split())
dist = lambda P, a, b, c: a * P[0] + b * P[1] + c
P1, P2 = tuple(read()), tuple(read())
n = int(input())
ans = 0
for i in range(n):
a, b, c = read()
d1 = dist(P1, a, b, c)
d2 = dist(P2, a, b, c)
ans += d1 * d2 < 0
print(ans)
``` | output | 1 | 18,076 | 1 | 36,153 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Crazy Town is a plane on which there are n infinite line roads. Each road is defined by the equation aix + biy + ci = 0, where ai and bi are not both equal to the zero. The roads divide the plane into connected regions, possibly of infinite space. Let's call each such region a block. We define an intersection as the point where at least two different roads intersect.
Your home is located in one of the blocks. Today you need to get to the University, also located in some block. In one step you can move from one block to another, if the length of their common border is nonzero (in particular, this means that if the blocks are adjacent to one intersection, but have no shared nonzero boundary segment, then it are not allowed to move from one to another one in one step).
Determine what is the minimum number of steps you have to perform to get to the block containing the university. It is guaranteed that neither your home nor the university is located on the road.
Input
The first line contains two space-separated integers x1, y1 ( - 106 ≤ x1, y1 ≤ 106) — the coordinates of your home.
The second line contains two integers separated by a space x2, y2 ( - 106 ≤ x2, y2 ≤ 106) — the coordinates of the university you are studying at.
The third line contains an integer n (1 ≤ n ≤ 300) — the number of roads in the city. The following n lines contain 3 space-separated integers ( - 106 ≤ ai, bi, ci ≤ 106; |ai| + |bi| > 0) — the coefficients of the line aix + biy + ci = 0, defining the i-th road. It is guaranteed that no two roads are the same. In addition, neither your home nor the university lie on the road (i.e. they do not belong to any one of the lines).
Output
Output the answer to the problem.
Examples
Input
1 1
-1 -1
2
0 1 0
1 0 0
Output
2
Input
1 1
-1 -1
3
1 0 0
0 1 0
1 1 -3
Output
2
Note
Pictures to the samples are presented below (A is the point representing the house; B is the point representing the university, different blocks are filled with different colors):
<image> <image> | instruction | 0 | 18,077 | 1 | 36,154 |
Tags: geometry
Correct Solution:
```
x1, y1 = map(float, input().split())
x2, y2 = map(float, input().split())
n = int(input())
ans = 0
for i in range(n):
a, b, c = map(int, input().split())
if (a * x1 + b * y1 + c) * (a * x2 + b * y2 + c) < 0:
ans += 1
print(ans)
``` | output | 1 | 18,077 | 1 | 36,155 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Crazy Town is a plane on which there are n infinite line roads. Each road is defined by the equation aix + biy + ci = 0, where ai and bi are not both equal to the zero. The roads divide the plane into connected regions, possibly of infinite space. Let's call each such region a block. We define an intersection as the point where at least two different roads intersect.
Your home is located in one of the blocks. Today you need to get to the University, also located in some block. In one step you can move from one block to another, if the length of their common border is nonzero (in particular, this means that if the blocks are adjacent to one intersection, but have no shared nonzero boundary segment, then it are not allowed to move from one to another one in one step).
Determine what is the minimum number of steps you have to perform to get to the block containing the university. It is guaranteed that neither your home nor the university is located on the road.
Input
The first line contains two space-separated integers x1, y1 ( - 106 ≤ x1, y1 ≤ 106) — the coordinates of your home.
The second line contains two integers separated by a space x2, y2 ( - 106 ≤ x2, y2 ≤ 106) — the coordinates of the university you are studying at.
The third line contains an integer n (1 ≤ n ≤ 300) — the number of roads in the city. The following n lines contain 3 space-separated integers ( - 106 ≤ ai, bi, ci ≤ 106; |ai| + |bi| > 0) — the coefficients of the line aix + biy + ci = 0, defining the i-th road. It is guaranteed that no two roads are the same. In addition, neither your home nor the university lie on the road (i.e. they do not belong to any one of the lines).
Output
Output the answer to the problem.
Examples
Input
1 1
-1 -1
2
0 1 0
1 0 0
Output
2
Input
1 1
-1 -1
3
1 0 0
0 1 0
1 1 -3
Output
2
Note
Pictures to the samples are presented below (A is the point representing the house; B is the point representing the university, different blocks are filled with different colors):
<image> <image> | instruction | 0 | 18,078 | 1 | 36,156 |
Tags: geometry
Correct Solution:
```
x1,y1=map(int,input().split())
x2,y2=map(int,input().split())
n=int(input())
p=0
for i in range(n):
a,b,c=map(int,input().split())
zenklas1=""
zenklas2=""
if a*x1+b*y1+c<0:
zenklas1+="-"
else:
zenklas1+="+"
if a*x2+b*y2+c<0:
zenklas2+="-"
else:
zenklas2+="+"
if zenklas1!=zenklas2:
p+=1
print(p)
``` | output | 1 | 18,078 | 1 | 36,157 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Crazy Town is a plane on which there are n infinite line roads. Each road is defined by the equation aix + biy + ci = 0, where ai and bi are not both equal to the zero. The roads divide the plane into connected regions, possibly of infinite space. Let's call each such region a block. We define an intersection as the point where at least two different roads intersect.
Your home is located in one of the blocks. Today you need to get to the University, also located in some block. In one step you can move from one block to another, if the length of their common border is nonzero (in particular, this means that if the blocks are adjacent to one intersection, but have no shared nonzero boundary segment, then it are not allowed to move from one to another one in one step).
Determine what is the minimum number of steps you have to perform to get to the block containing the university. It is guaranteed that neither your home nor the university is located on the road.
Input
The first line contains two space-separated integers x1, y1 ( - 106 ≤ x1, y1 ≤ 106) — the coordinates of your home.
The second line contains two integers separated by a space x2, y2 ( - 106 ≤ x2, y2 ≤ 106) — the coordinates of the university you are studying at.
The third line contains an integer n (1 ≤ n ≤ 300) — the number of roads in the city. The following n lines contain 3 space-separated integers ( - 106 ≤ ai, bi, ci ≤ 106; |ai| + |bi| > 0) — the coefficients of the line aix + biy + ci = 0, defining the i-th road. It is guaranteed that no two roads are the same. In addition, neither your home nor the university lie on the road (i.e. they do not belong to any one of the lines).
Output
Output the answer to the problem.
Examples
Input
1 1
-1 -1
2
0 1 0
1 0 0
Output
2
Input
1 1
-1 -1
3
1 0 0
0 1 0
1 1 -3
Output
2
Note
Pictures to the samples are presented below (A is the point representing the house; B is the point representing the university, different blocks are filled with different colors):
<image> <image> | instruction | 0 | 18,079 | 1 | 36,158 |
Tags: geometry
Correct Solution:
```
def main():
x1, y1 = map(float, input().split())
x2, y2 = map(float, input().split())
n = int(input())
res = 0
for _ in range(n):
a, b, c = map(float, input().split())
if a and b:
x3, y3, x4, y4 = 0., -c / b, 1., -a / b
elif a:
x3, y4 = -c / a, 1.
y3 = x4 = 0.
else:
x3 = y4 = 0.
y3, x4 = -c / b, 1.
ax = x1 - x3
ay = y1 - y3
bx = x2 - x3
by = y2 - y3
a = ax * y4 - ay * x4
b = bx * y4 - by * x4
if a < 0 < b or b < 0 < a:
res += 1
print(res)
if __name__ == '__main__':
main()
``` | output | 1 | 18,079 | 1 | 36,159 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Crazy Town is a plane on which there are n infinite line roads. Each road is defined by the equation aix + biy + ci = 0, where ai and bi are not both equal to the zero. The roads divide the plane into connected regions, possibly of infinite space. Let's call each such region a block. We define an intersection as the point where at least two different roads intersect.
Your home is located in one of the blocks. Today you need to get to the University, also located in some block. In one step you can move from one block to another, if the length of their common border is nonzero (in particular, this means that if the blocks are adjacent to one intersection, but have no shared nonzero boundary segment, then it are not allowed to move from one to another one in one step).
Determine what is the minimum number of steps you have to perform to get to the block containing the university. It is guaranteed that neither your home nor the university is located on the road.
Input
The first line contains two space-separated integers x1, y1 ( - 106 ≤ x1, y1 ≤ 106) — the coordinates of your home.
The second line contains two integers separated by a space x2, y2 ( - 106 ≤ x2, y2 ≤ 106) — the coordinates of the university you are studying at.
The third line contains an integer n (1 ≤ n ≤ 300) — the number of roads in the city. The following n lines contain 3 space-separated integers ( - 106 ≤ ai, bi, ci ≤ 106; |ai| + |bi| > 0) — the coefficients of the line aix + biy + ci = 0, defining the i-th road. It is guaranteed that no two roads are the same. In addition, neither your home nor the university lie on the road (i.e. they do not belong to any one of the lines).
Output
Output the answer to the problem.
Examples
Input
1 1
-1 -1
2
0 1 0
1 0 0
Output
2
Input
1 1
-1 -1
3
1 0 0
0 1 0
1 1 -3
Output
2
Note
Pictures to the samples are presented below (A is the point representing the house; B is the point representing the university, different blocks are filled with different colors):
<image> <image> | instruction | 0 | 18,080 | 1 | 36,160 |
Tags: geometry
Correct Solution:
```
ct = 0
x1, y1 = map(int, input().split(' '))
x2, y2 = map(int, input().split(' '))
for i in range(int(input())):
a, b, c = map(int, input().split(' '))
if b == 0:
if x1 < -c / a < x2 or x2 < -c/a < x1:
ct += 1
else:
b1 = y1 > (-a * x1 - c) / b
b2 = y2 > (-a * x2 - c) / b
if b1 != b2:
ct += 1
print(ct)
``` | output | 1 | 18,080 | 1 | 36,161 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Crazy Town is a plane on which there are n infinite line roads. Each road is defined by the equation aix + biy + ci = 0, where ai and bi are not both equal to the zero. The roads divide the plane into connected regions, possibly of infinite space. Let's call each such region a block. We define an intersection as the point where at least two different roads intersect.
Your home is located in one of the blocks. Today you need to get to the University, also located in some block. In one step you can move from one block to another, if the length of their common border is nonzero (in particular, this means that if the blocks are adjacent to one intersection, but have no shared nonzero boundary segment, then it are not allowed to move from one to another one in one step).
Determine what is the minimum number of steps you have to perform to get to the block containing the university. It is guaranteed that neither your home nor the university is located on the road.
Input
The first line contains two space-separated integers x1, y1 ( - 106 ≤ x1, y1 ≤ 106) — the coordinates of your home.
The second line contains two integers separated by a space x2, y2 ( - 106 ≤ x2, y2 ≤ 106) — the coordinates of the university you are studying at.
The third line contains an integer n (1 ≤ n ≤ 300) — the number of roads in the city. The following n lines contain 3 space-separated integers ( - 106 ≤ ai, bi, ci ≤ 106; |ai| + |bi| > 0) — the coefficients of the line aix + biy + ci = 0, defining the i-th road. It is guaranteed that no two roads are the same. In addition, neither your home nor the university lie on the road (i.e. they do not belong to any one of the lines).
Output
Output the answer to the problem.
Examples
Input
1 1
-1 -1
2
0 1 0
1 0 0
Output
2
Input
1 1
-1 -1
3
1 0 0
0 1 0
1 1 -3
Output
2
Note
Pictures to the samples are presented below (A is the point representing the house; B is the point representing the university, different blocks are filled with different colors):
<image> <image> | instruction | 0 | 18,081 | 1 | 36,162 |
Tags: geometry
Correct Solution:
```
#------------------------template--------------------------#
import os
import sys
from math import *
from collections import *
from fractions import *
from bisect import *
from heapq import*
from io import BytesIO, IOBase
def vsInput():
sys.stdin = open('input.txt', 'r')
sys.stdout = open('output.txt', 'w')
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
def value():return tuple(map(int,input().split()))
def array():return [int(i) for i in input().split()]
def Int():return int(input())
def Str():return input()
def arrayS():return [i for i in input().split()]
#-------------------------code---------------------------#
#vsInput()
def position(x,y):
status=line[0]*x+line[1]*y+line[2]
return status>0
Sx,Sy=value()
Dx,Dy=value()
steps=0
for i in range(Int()):
line=value()
steps+=position(Sx,Sy)!=position(Dx,Dy)
print(steps)
``` | output | 1 | 18,081 | 1 | 36,163 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Crazy Town is a plane on which there are n infinite line roads. Each road is defined by the equation aix + biy + ci = 0, where ai and bi are not both equal to the zero. The roads divide the plane into connected regions, possibly of infinite space. Let's call each such region a block. We define an intersection as the point where at least two different roads intersect.
Your home is located in one of the blocks. Today you need to get to the University, also located in some block. In one step you can move from one block to another, if the length of their common border is nonzero (in particular, this means that if the blocks are adjacent to one intersection, but have no shared nonzero boundary segment, then it are not allowed to move from one to another one in one step).
Determine what is the minimum number of steps you have to perform to get to the block containing the university. It is guaranteed that neither your home nor the university is located on the road.
Input
The first line contains two space-separated integers x1, y1 ( - 106 ≤ x1, y1 ≤ 106) — the coordinates of your home.
The second line contains two integers separated by a space x2, y2 ( - 106 ≤ x2, y2 ≤ 106) — the coordinates of the university you are studying at.
The third line contains an integer n (1 ≤ n ≤ 300) — the number of roads in the city. The following n lines contain 3 space-separated integers ( - 106 ≤ ai, bi, ci ≤ 106; |ai| + |bi| > 0) — the coefficients of the line aix + biy + ci = 0, defining the i-th road. It is guaranteed that no two roads are the same. In addition, neither your home nor the university lie on the road (i.e. they do not belong to any one of the lines).
Output
Output the answer to the problem.
Examples
Input
1 1
-1 -1
2
0 1 0
1 0 0
Output
2
Input
1 1
-1 -1
3
1 0 0
0 1 0
1 1 -3
Output
2
Note
Pictures to the samples are presented below (A is the point representing the house; B is the point representing the university, different blocks are filled with different colors):
<image> <image> | instruction | 0 | 18,082 | 1 | 36,164 |
Tags: geometry
Correct Solution:
```
h1,h2=input().split()
u1,u2=input().split()
h1,h2=int(h1),int(h2)
u1,u2=int(u1),int(u2)
n=int(input())
lis=[]
for i in range(n):
lis.append(input().split())
for i in range(n):
for j in range(3):
lis[i][j]=int(lis[i][j])
def status(a,b,lis):
if a*lis[0]+b*lis[1]+lis[2]>0:
return 1
else:
return 0
c=0
for i in range(n):
if status(h1,h2,lis[i])!=status(u1,u2,lis[i]):
c+=1
print(c)
``` | output | 1 | 18,082 | 1 | 36,165 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Crazy Town is a plane on which there are n infinite line roads. Each road is defined by the equation aix + biy + ci = 0, where ai and bi are not both equal to the zero. The roads divide the plane into connected regions, possibly of infinite space. Let's call each such region a block. We define an intersection as the point where at least two different roads intersect.
Your home is located in one of the blocks. Today you need to get to the University, also located in some block. In one step you can move from one block to another, if the length of their common border is nonzero (in particular, this means that if the blocks are adjacent to one intersection, but have no shared nonzero boundary segment, then it are not allowed to move from one to another one in one step).
Determine what is the minimum number of steps you have to perform to get to the block containing the university. It is guaranteed that neither your home nor the university is located on the road.
Input
The first line contains two space-separated integers x1, y1 ( - 106 ≤ x1, y1 ≤ 106) — the coordinates of your home.
The second line contains two integers separated by a space x2, y2 ( - 106 ≤ x2, y2 ≤ 106) — the coordinates of the university you are studying at.
The third line contains an integer n (1 ≤ n ≤ 300) — the number of roads in the city. The following n lines contain 3 space-separated integers ( - 106 ≤ ai, bi, ci ≤ 106; |ai| + |bi| > 0) — the coefficients of the line aix + biy + ci = 0, defining the i-th road. It is guaranteed that no two roads are the same. In addition, neither your home nor the university lie on the road (i.e. they do not belong to any one of the lines).
Output
Output the answer to the problem.
Examples
Input
1 1
-1 -1
2
0 1 0
1 0 0
Output
2
Input
1 1
-1 -1
3
1 0 0
0 1 0
1 1 -3
Output
2
Note
Pictures to the samples are presented below (A is the point representing the house; B is the point representing the university, different blocks are filled with different colors):
<image> <image>
Submitted Solution:
```
x1, y1 = map(int, input().split())
x2, y2 = map(int, input().split())
n = int(input())
ans = 0
for i in range(n):
a, b, c = map(int, input().split())
f1 = a * x1 + b * y1 + c
f2 = a * x2 + b * y2 + c
if f1 * f2 < 0:
ans += 1
print(ans)
``` | instruction | 0 | 18,083 | 1 | 36,166 |
Yes | output | 1 | 18,083 | 1 | 36,167 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Crazy Town is a plane on which there are n infinite line roads. Each road is defined by the equation aix + biy + ci = 0, where ai and bi are not both equal to the zero. The roads divide the plane into connected regions, possibly of infinite space. Let's call each such region a block. We define an intersection as the point where at least two different roads intersect.
Your home is located in one of the blocks. Today you need to get to the University, also located in some block. In one step you can move from one block to another, if the length of their common border is nonzero (in particular, this means that if the blocks are adjacent to one intersection, but have no shared nonzero boundary segment, then it are not allowed to move from one to another one in one step).
Determine what is the minimum number of steps you have to perform to get to the block containing the university. It is guaranteed that neither your home nor the university is located on the road.
Input
The first line contains two space-separated integers x1, y1 ( - 106 ≤ x1, y1 ≤ 106) — the coordinates of your home.
The second line contains two integers separated by a space x2, y2 ( - 106 ≤ x2, y2 ≤ 106) — the coordinates of the university you are studying at.
The third line contains an integer n (1 ≤ n ≤ 300) — the number of roads in the city. The following n lines contain 3 space-separated integers ( - 106 ≤ ai, bi, ci ≤ 106; |ai| + |bi| > 0) — the coefficients of the line aix + biy + ci = 0, defining the i-th road. It is guaranteed that no two roads are the same. In addition, neither your home nor the university lie on the road (i.e. they do not belong to any one of the lines).
Output
Output the answer to the problem.
Examples
Input
1 1
-1 -1
2
0 1 0
1 0 0
Output
2
Input
1 1
-1 -1
3
1 0 0
0 1 0
1 1 -3
Output
2
Note
Pictures to the samples are presented below (A is the point representing the house; B is the point representing the university, different blocks are filled with different colors):
<image> <image>
Submitted Solution:
```
x1, y1 = [int(_) for _ in input().split()]
x2, y2 = [int(_) for _ in input().split()]
n = int(input())
ans = 0
for i in range(n):
a, b, c = [int(_) for _ in input().split()]
zy1 = a * x1 + b * y1 + c
zy2 = a * x2 + b * y2 + c
if (zy1 > 0 and zy2 < 0) or (zy1 < 0 and zy2 > 0):
ans += 1
print(ans)
``` | instruction | 0 | 18,084 | 1 | 36,168 |
Yes | output | 1 | 18,084 | 1 | 36,169 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Crazy Town is a plane on which there are n infinite line roads. Each road is defined by the equation aix + biy + ci = 0, where ai and bi are not both equal to the zero. The roads divide the plane into connected regions, possibly of infinite space. Let's call each such region a block. We define an intersection as the point where at least two different roads intersect.
Your home is located in one of the blocks. Today you need to get to the University, also located in some block. In one step you can move from one block to another, if the length of their common border is nonzero (in particular, this means that if the blocks are adjacent to one intersection, but have no shared nonzero boundary segment, then it are not allowed to move from one to another one in one step).
Determine what is the minimum number of steps you have to perform to get to the block containing the university. It is guaranteed that neither your home nor the university is located on the road.
Input
The first line contains two space-separated integers x1, y1 ( - 106 ≤ x1, y1 ≤ 106) — the coordinates of your home.
The second line contains two integers separated by a space x2, y2 ( - 106 ≤ x2, y2 ≤ 106) — the coordinates of the university you are studying at.
The third line contains an integer n (1 ≤ n ≤ 300) — the number of roads in the city. The following n lines contain 3 space-separated integers ( - 106 ≤ ai, bi, ci ≤ 106; |ai| + |bi| > 0) — the coefficients of the line aix + biy + ci = 0, defining the i-th road. It is guaranteed that no two roads are the same. In addition, neither your home nor the university lie on the road (i.e. they do not belong to any one of the lines).
Output
Output the answer to the problem.
Examples
Input
1 1
-1 -1
2
0 1 0
1 0 0
Output
2
Input
1 1
-1 -1
3
1 0 0
0 1 0
1 1 -3
Output
2
Note
Pictures to the samples are presented below (A is the point representing the house; B is the point representing the university, different blocks are filled with different colors):
<image> <image>
Submitted Solution:
```
x1,y1 = [int(i) for i in input().split()]
x2,y2 = [int(i) for i in input().split()]
n = int(input())
m = 0
for i in range(n):
x,y,c = [int(g) for g in input().split()]
if(x1*x+y1*y+c>0):
l = 1
else:
l = -1
if(l==-1)and(x2*x+y2*y+c>0):
m+=1
elif(l==1)and(x2*x+y2*y+c<0):
m+=1
print(m)
``` | instruction | 0 | 18,085 | 1 | 36,170 |
Yes | output | 1 | 18,085 | 1 | 36,171 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Crazy Town is a plane on which there are n infinite line roads. Each road is defined by the equation aix + biy + ci = 0, where ai and bi are not both equal to the zero. The roads divide the plane into connected regions, possibly of infinite space. Let's call each such region a block. We define an intersection as the point where at least two different roads intersect.
Your home is located in one of the blocks. Today you need to get to the University, also located in some block. In one step you can move from one block to another, if the length of their common border is nonzero (in particular, this means that if the blocks are adjacent to one intersection, but have no shared nonzero boundary segment, then it are not allowed to move from one to another one in one step).
Determine what is the minimum number of steps you have to perform to get to the block containing the university. It is guaranteed that neither your home nor the university is located on the road.
Input
The first line contains two space-separated integers x1, y1 ( - 106 ≤ x1, y1 ≤ 106) — the coordinates of your home.
The second line contains two integers separated by a space x2, y2 ( - 106 ≤ x2, y2 ≤ 106) — the coordinates of the university you are studying at.
The third line contains an integer n (1 ≤ n ≤ 300) — the number of roads in the city. The following n lines contain 3 space-separated integers ( - 106 ≤ ai, bi, ci ≤ 106; |ai| + |bi| > 0) — the coefficients of the line aix + biy + ci = 0, defining the i-th road. It is guaranteed that no two roads are the same. In addition, neither your home nor the university lie on the road (i.e. they do not belong to any one of the lines).
Output
Output the answer to the problem.
Examples
Input
1 1
-1 -1
2
0 1 0
1 0 0
Output
2
Input
1 1
-1 -1
3
1 0 0
0 1 0
1 1 -3
Output
2
Note
Pictures to the samples are presented below (A is the point representing the house; B is the point representing the university, different blocks are filled with different colors):
<image> <image>
Submitted Solution:
```
__author__ = 'Rakshak.R.Hegde'
"""
Created on Dec 24 2014 PM 10:42
@author: Rakshak.R.Hegde
"""
x1, y1 = map(int, input().split())
x2, y2 = map(int, input().split())
n = int(input())
cost = 0
for i in range(n):
a, b, c = map(int, input().split())
d1 = a * x1 + b * y1 + c
d2 = a * x2 + b * y2 + c
if d1 * d2 < 0: cost += 1
print(cost)
``` | instruction | 0 | 18,086 | 1 | 36,172 |
Yes | output | 1 | 18,086 | 1 | 36,173 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Crazy Town is a plane on which there are n infinite line roads. Each road is defined by the equation aix + biy + ci = 0, where ai and bi are not both equal to the zero. The roads divide the plane into connected regions, possibly of infinite space. Let's call each such region a block. We define an intersection as the point where at least two different roads intersect.
Your home is located in one of the blocks. Today you need to get to the University, also located in some block. In one step you can move from one block to another, if the length of their common border is nonzero (in particular, this means that if the blocks are adjacent to one intersection, but have no shared nonzero boundary segment, then it are not allowed to move from one to another one in one step).
Determine what is the minimum number of steps you have to perform to get to the block containing the university. It is guaranteed that neither your home nor the university is located on the road.
Input
The first line contains two space-separated integers x1, y1 ( - 106 ≤ x1, y1 ≤ 106) — the coordinates of your home.
The second line contains two integers separated by a space x2, y2 ( - 106 ≤ x2, y2 ≤ 106) — the coordinates of the university you are studying at.
The third line contains an integer n (1 ≤ n ≤ 300) — the number of roads in the city. The following n lines contain 3 space-separated integers ( - 106 ≤ ai, bi, ci ≤ 106; |ai| + |bi| > 0) — the coefficients of the line aix + biy + ci = 0, defining the i-th road. It is guaranteed that no two roads are the same. In addition, neither your home nor the university lie on the road (i.e. they do not belong to any one of the lines).
Output
Output the answer to the problem.
Examples
Input
1 1
-1 -1
2
0 1 0
1 0 0
Output
2
Input
1 1
-1 -1
3
1 0 0
0 1 0
1 1 -3
Output
2
Note
Pictures to the samples are presented below (A is the point representing the house; B is the point representing the university, different blocks are filled with different colors):
<image> <image>
Submitted Solution:
```
#input
x1,y1=map(int,input().split())
x2,y2=map(int,input().split())
n=int(input())
r=[]
for i in range(n):
r.append([int(x) for x in input().split()])
#variables
def sol(a1,b1,c1,a2,b2,c2):
if b1*a2-a1*b2==0:
return [10000000,10000000]
else:
return [(c1*b2-b1*c2)/(a1*b2-b1*a2),(c1*a2-a1*c2)/(b1*a2-a1*b2)]
m=(y2-y1)/(x2-x1)
a=-m
b=1
c=y1-m*x1
s=n
#main
for i in range(n):
x=sol(a,b,c,r[i][0],r[i][1],r[i][2])
if x[0]<min(x1,x2) or x[0]>max(x1,x2):
if x[1]<min(y1,y2) or x[1]>max(y1,y2):
s-=1
#output
print(s)
``` | instruction | 0 | 18,087 | 1 | 36,174 |
No | output | 1 | 18,087 | 1 | 36,175 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Crazy Town is a plane on which there are n infinite line roads. Each road is defined by the equation aix + biy + ci = 0, where ai and bi are not both equal to the zero. The roads divide the plane into connected regions, possibly of infinite space. Let's call each such region a block. We define an intersection as the point where at least two different roads intersect.
Your home is located in one of the blocks. Today you need to get to the University, also located in some block. In one step you can move from one block to another, if the length of their common border is nonzero (in particular, this means that if the blocks are adjacent to one intersection, but have no shared nonzero boundary segment, then it are not allowed to move from one to another one in one step).
Determine what is the minimum number of steps you have to perform to get to the block containing the university. It is guaranteed that neither your home nor the university is located on the road.
Input
The first line contains two space-separated integers x1, y1 ( - 106 ≤ x1, y1 ≤ 106) — the coordinates of your home.
The second line contains two integers separated by a space x2, y2 ( - 106 ≤ x2, y2 ≤ 106) — the coordinates of the university you are studying at.
The third line contains an integer n (1 ≤ n ≤ 300) — the number of roads in the city. The following n lines contain 3 space-separated integers ( - 106 ≤ ai, bi, ci ≤ 106; |ai| + |bi| > 0) — the coefficients of the line aix + biy + ci = 0, defining the i-th road. It is guaranteed that no two roads are the same. In addition, neither your home nor the university lie on the road (i.e. they do not belong to any one of the lines).
Output
Output the answer to the problem.
Examples
Input
1 1
-1 -1
2
0 1 0
1 0 0
Output
2
Input
1 1
-1 -1
3
1 0 0
0 1 0
1 1 -3
Output
2
Note
Pictures to the samples are presented below (A is the point representing the house; B is the point representing the university, different blocks are filled with different colors):
<image> <image>
Submitted Solution:
```
import math
EPS = 1E-10
def common_segment_line(a, b, line1):
com = common_point(line1, line_with_to_points(a, b))
if (abs(a.length(com) + b.length(com) - a.length(b))) < EPS:
return True
return False
def point_in_angle(a, o, b, p):
op = do_vector(p, o)
oa = do_vector(a, o)
ob = do_vector(b, o)
bo = do_vector(o, b)
bp = do_vector(p, b)
ba = do_vector(a, b)
ao = do_vector(o, a)
ap = do_vector(p, a)
ab = do_vector(b, a)
if (op ^ oa) * (op ^ ob) <= 0 and (bp ^ bo) * (ba ^ bo) >= 0 and (ap ^ ao) * (ab ^ ao) >= 0:
return True
else:
return False
def check_common_segments(A, B, C, D):
line1 = line_with_to_points(A, B)
line2 = line_with_to_points(C, D)
if (function_line(C, line1) * function_line(D, line1) < EPS and function_line(A, line2) * function_line(B,
line2) < EPS):
return "YES"
elif abs(function_line(C, line1)) <= EPS and abs(C.length(A) + C.length(B) - A.length(B)) <= EPS:
return "YES"
elif abs(function_line(D, line1)) <= EPS and abs(D.length(A) + D.length(B) - A.length(B)) <= EPS:
return "YES"
elif abs(function_line(A, line2)) <= EPS and abs(A.length(C) + A.length(D) - C.length(D)) <= EPS:
return "YES"
elif abs(function_line(B, line1)) <= EPS and abs(B.length(C) + B.length(D) - C.length(D)) <= EPS:
return "YES"
else:
return "NO"
def length_to_ray(point1, point2, point3):
x, y = point1.x, point1.y
x1, y1 = point2.x, point2.y
x2, y2 = point3.x, point3.y
if do_vector(point(x, y), point(x1, y1)) * do_vector(point(x2, y2), point(x1, y1)) >= 0:
return (high(do_vector(point(x1, y1), point(x, y)), do_vector(point(x2, y2), point(x, y)),
point(x2, y2).length(point(x1, y1))))
else:
return (min(point(x, y).length(point(x1, y1)), point(x, y).length(point(x2, y2))))
def point_on_circle(circle1, point1):
if abs((point1.x - circle1.x) ** 2 + (point1.y - circle1.y) ** 2 - circle1.radius ** 2) < EPS:
return True
return False
def check(point1, point2):
if abs(point1.x - point2.x) < EPS and abs(point1.y - point2.y) < EPS:
return True
return False
def function_line(point1, line1):
return line1.a * point1.x + line1.b * point1.y + line1.c
def normal_vector(line, point):
return vector(line.a, line.b).multiply((-2 * function_line(point, line)) / (line.a ** 2 + line.b ** 2))
def normalize(vec):
x = (vec.x / vec.length())
y = (vec.y / vec.length())
return vector(x, y)
def line_with_to_points(point1, point2):
a = point2.y - point1.y
b = point1.x - point2.x
c = -(a * point1.x + b * point1.y)
return line(a, b, c)
def common_point(line1, line2):
if line1.b == 0:
line1, line2 = line2, line1
if line1.b != 0 and (line1.b * line2.a - line2.b * line1.a) != 0:
x = (line2.b * line1.c - line1.b * line2.c) / (line1.b * line2.a - line2.b * line1.a)
y = (-line1.c - line1.a * x) / line1.b
return point(x, y)
else:
return point(-1e18 - 7, -1e18 - 9)
def from_radian_to_degrees(angle):
return (angle * 180) / math.pi
def point_with_fixed_ratio(point1, point2, a, b):
x = (((point2.x - point1.x) * a) / (a + b)) + point1.x
y = point2.y + (((point1.y - point2.y) * b) / (a + b))
return point(x, y)
def high(vector1, vector2, length):
return abs((vector1 ^ vector2) / length)
def do_vector(point1, point2):
return vector(point1.x - point2.x, point1.y - point2.y)
def s_triangle(first, second, angle):
return first * second * math.sin(angle) / 2
def s_sector(angle, radius):
return (angle / (2 * math.pi)) * math.pi * radius ** 2
class point:
def __init__(self, x, y):
self.x = x
self.y = y
def length(self, other):
return ((self.x - other.x) ** 2 + (self.y - other.y) ** 2) ** 0.5
def __eq__(self, other):
if self.x == other.x and self.y == other.y:
return True
return False
class vector:
def __init__(self, x, y):
self.x = x
self.y = y
def turn(self, sina, cosa):
x = self.x * cosa + self.y * sina
y = -self.x * sina + self.y * cosa
return vector(x, y)
def multiply(self, number):
return vector(self.x * number, self.y * number)
def __mul__(self, other):
return self.x * other.x + self.y * other.y
def __xor__(self, other):
return self.x * other.y - other.x * self.y
def polar_angle(self):
return math.atan2(self.y, self.x)
def angle(self, other):
return math.atan2(self ^ other, self * other)
def length(self):
return (self.x ** 2 + self.y ** 2) ** 0.5
def __add__(self, other):
return vector(self.x + other.x, self.y + other.y)
def __sub__(self, other):
return vector(self.x - other.x, self.y - other.y)
class circle:
def __init__(self, x, y, radius):
self.x = x
self.y = y
self.radius = radius
def __eq__(self, other):
if self.x == other.x and self.y == other.y and self.radius == other.radius:
return True
return False
class line:
def __init__(self, a, b, c):
self.a = a
self.b = b
self.c = c
def __eq__(self, other):
if self.x == other.x and self.y == other.y:
return True
return False
x1, y1 = map(int, input().split())
A = point(x1, y1)
x2, y2 = map(int, input().split())
B = point(x2, y2)
cnt = 0
n = int(input())
for i in range(n):
a, b, c = map(int, input().split())
if (common_segment_line(A, B, line(a, b, c))):
cnt += 1
print(cnt)
``` | instruction | 0 | 18,088 | 1 | 36,176 |
No | output | 1 | 18,088 | 1 | 36,177 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Crazy Town is a plane on which there are n infinite line roads. Each road is defined by the equation aix + biy + ci = 0, where ai and bi are not both equal to the zero. The roads divide the plane into connected regions, possibly of infinite space. Let's call each such region a block. We define an intersection as the point where at least two different roads intersect.
Your home is located in one of the blocks. Today you need to get to the University, also located in some block. In one step you can move from one block to another, if the length of their common border is nonzero (in particular, this means that if the blocks are adjacent to one intersection, but have no shared nonzero boundary segment, then it are not allowed to move from one to another one in one step).
Determine what is the minimum number of steps you have to perform to get to the block containing the university. It is guaranteed that neither your home nor the university is located on the road.
Input
The first line contains two space-separated integers x1, y1 ( - 106 ≤ x1, y1 ≤ 106) — the coordinates of your home.
The second line contains two integers separated by a space x2, y2 ( - 106 ≤ x2, y2 ≤ 106) — the coordinates of the university you are studying at.
The third line contains an integer n (1 ≤ n ≤ 300) — the number of roads in the city. The following n lines contain 3 space-separated integers ( - 106 ≤ ai, bi, ci ≤ 106; |ai| + |bi| > 0) — the coefficients of the line aix + biy + ci = 0, defining the i-th road. It is guaranteed that no two roads are the same. In addition, neither your home nor the university lie on the road (i.e. they do not belong to any one of the lines).
Output
Output the answer to the problem.
Examples
Input
1 1
-1 -1
2
0 1 0
1 0 0
Output
2
Input
1 1
-1 -1
3
1 0 0
0 1 0
1 1 -3
Output
2
Note
Pictures to the samples are presented below (A is the point representing the house; B is the point representing the university, different blocks are filled with different colors):
<image> <image>
Submitted Solution:
```
x1,y1=map(int,input().split())
x2,y2=map(int,input().split())
n=int(input())
l=[]
count=0
for i in range(n):
a,b,c=map(int,input().split())
if a==0 and c==0:
if (x1>0 and x2<0) or (x1<0 and x2>0):
count+=1
elif b==0 and c==0:
if (y1>0 and y2<0) or (y1<0 and y2>0):
count+=1
else:
if (a*x1+b*y1+c>0 and a*x2+b*y2+c<0) or (a*x1+b*y1+c<0 and a*x2+b*y2+c>0):
count+=1
print(count)
``` | instruction | 0 | 18,089 | 1 | 36,178 |
No | output | 1 | 18,089 | 1 | 36,179 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Crazy Town is a plane on which there are n infinite line roads. Each road is defined by the equation aix + biy + ci = 0, where ai and bi are not both equal to the zero. The roads divide the plane into connected regions, possibly of infinite space. Let's call each such region a block. We define an intersection as the point where at least two different roads intersect.
Your home is located in one of the blocks. Today you need to get to the University, also located in some block. In one step you can move from one block to another, if the length of their common border is nonzero (in particular, this means that if the blocks are adjacent to one intersection, but have no shared nonzero boundary segment, then it are not allowed to move from one to another one in one step).
Determine what is the minimum number of steps you have to perform to get to the block containing the university. It is guaranteed that neither your home nor the university is located on the road.
Input
The first line contains two space-separated integers x1, y1 ( - 106 ≤ x1, y1 ≤ 106) — the coordinates of your home.
The second line contains two integers separated by a space x2, y2 ( - 106 ≤ x2, y2 ≤ 106) — the coordinates of the university you are studying at.
The third line contains an integer n (1 ≤ n ≤ 300) — the number of roads in the city. The following n lines contain 3 space-separated integers ( - 106 ≤ ai, bi, ci ≤ 106; |ai| + |bi| > 0) — the coefficients of the line aix + biy + ci = 0, defining the i-th road. It is guaranteed that no two roads are the same. In addition, neither your home nor the university lie on the road (i.e. they do not belong to any one of the lines).
Output
Output the answer to the problem.
Examples
Input
1 1
-1 -1
2
0 1 0
1 0 0
Output
2
Input
1 1
-1 -1
3
1 0 0
0 1 0
1 1 -3
Output
2
Note
Pictures to the samples are presented below (A is the point representing the house; B is the point representing the university, different blocks are filled with different colors):
<image> <image>
Submitted Solution:
```
x1, y1 = map(int, input().split())
x2, y2 = map(int, input().split())
n = int(input())
ans = 0
for _ in range(n):
a, b, c = map(int, input().split())
if a == 0:
if c / b > min(y1, y2) and c / b < max(y1, y2):
ans = ans + 1
elif b == 0:
if c / a > min(x1, x2) and c / a < max(x1, x2):
ans = ans + 1
else:
tar = [(-a * __ - c) / b for __ in [x1, x2]]
if min(tar) > min(y1, y2) and max(tar) < max(y1, y2):
ans = ans + 1
print(ans)
``` | instruction | 0 | 18,090 | 1 | 36,180 |
No | output | 1 | 18,090 | 1 | 36,181 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Petya loves volleyball very much. One day he was running late for a volleyball match. Petya hasn't bought his own car yet, that's why he had to take a taxi. The city has n junctions, some of which are connected by two-way roads. The length of each road is defined by some positive integer number of meters; the roads can have different lengths.
Initially each junction has exactly one taxi standing there. The taxi driver from the i-th junction agrees to drive Petya (perhaps through several intermediate junctions) to some other junction if the travel distance is not more than ti meters. Also, the cost of the ride doesn't depend on the distance and is equal to ci bourles. Taxis can't stop in the middle of a road. Each taxi can be used no more than once. Petya can catch taxi only in the junction, where it stands initially.
At the moment Petya is located on the junction x and the volleyball stadium is on the junction y. Determine the minimum amount of money Petya will need to drive to the stadium.
Input
The first line contains two integers n and m (1 ≤ n ≤ 1000, 0 ≤ m ≤ 1000). They are the number of junctions and roads in the city correspondingly. The junctions are numbered from 1 to n, inclusive. The next line contains two integers x and y (1 ≤ x, y ≤ n). They are the numbers of the initial and final junctions correspondingly. Next m lines contain the roads' description. Each road is described by a group of three integers ui, vi, wi (1 ≤ ui, vi ≤ n, 1 ≤ wi ≤ 109) — they are the numbers of the junctions connected by the road and the length of the road, correspondingly. The next n lines contain n pairs of integers ti and ci (1 ≤ ti, ci ≤ 109), which describe the taxi driver that waits at the i-th junction — the maximum distance he can drive and the drive's cost. The road can't connect the junction with itself, but between a pair of junctions there can be more than one road. All consecutive numbers in each line are separated by exactly one space character.
Output
If taxis can't drive Petya to the destination point, print "-1" (without the quotes). Otherwise, print the drive's minimum cost.
Please do not use the %lld specificator to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specificator.
Examples
Input
4 4
1 3
1 2 3
1 4 1
2 4 1
2 3 5
2 7
7 2
1 2
7 7
Output
9
Note
An optimal way — ride from the junction 1 to 2 (via junction 4), then from 2 to 3. It costs 7+2=9 bourles. | instruction | 0 | 18,284 | 1 | 36,568 |
Tags: shortest paths
Correct Solution:
```
import os
import sys
from io import BytesIO, IOBase
# region fastio
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
# ------------------------------
from math import factorial
from collections import Counter, defaultdict
from heapq import heapify, heappop, heappush
def RL(): return map(int, sys.stdin.readline().rstrip().split())
def RLL(): return list(map(int, sys.stdin.readline().rstrip().split()))
def N(): return int(input())
def comb(n, m): return factorial(n) / (factorial(m) * factorial(n - m)) if n >= m else 0
def perm(n, m): return factorial(n) // (factorial(n - m)) if n >= m else 0
def mdis(x1, y1, x2, y2): return abs(x1 - x2) + abs(y1 - y2)
def ctd(chr): return ord(chr)-ord("a")
mod = 998244353
INF = float('inf')
from heapq import heappush, heappop
# ------------------------------
# f = open('./input.txt')
# sys.stdin = f
def main():
n, m = RL()
x, y = RL()
gp = defaultdict(dict)
for _ in range(m):
u, v, w = RL()
gp[u][v] = min(gp[u].get(v, INF), w)
gp[v][u] = min(gp[v].get(u, INF), w)
cars = [[0, 0]]
for _ in range(n):
t, c = RL()
cars.append([t, c])
disarr = [[INF]*(n+1) for _ in range(n+1)]
for i in range(1, n+1):
disarr[i][i] = 0
newg = [[INF]*(n+1) for _ in range(n+1)]
dnex = defaultdict(list)
def dij(s):
q = [(0, s)]
while q:
d, nd = heappop(q)
for nex in gp[nd]:
dis = gp[nd][nex]+disarr[s][nd]
if dis<disarr[s][nex]:
disarr[s][nex] = dis
heappush(q, (dis, nex))
for i in range(1, n+1):
cd, cc = cars[s]
d = disarr[s][i]
if d<=cd:
newg[s][i] = min(newg[s][i], cc)
dnex[s].append(i)
def dij1(s):
q = [(0, s)]
cst = [INF] * (n + 1)
cst[s] = 0
while q:
d, nd = heappop(q)
for nex in dnex[nd]:
cs = cst[nd]+newg[nd][nex]
if cs<cst[nex]:
cst[nex] = cs
heappush(q, (cs, nex))
if cst[y]==INF:
print(-1)
else:
print(cst[y])
for i in range(1, n+1):
dij(i)
dij1(x)
# for i in newg:print(i)
if __name__ == "__main__":
main()
``` | output | 1 | 18,284 | 1 | 36,569 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Petya loves volleyball very much. One day he was running late for a volleyball match. Petya hasn't bought his own car yet, that's why he had to take a taxi. The city has n junctions, some of which are connected by two-way roads. The length of each road is defined by some positive integer number of meters; the roads can have different lengths.
Initially each junction has exactly one taxi standing there. The taxi driver from the i-th junction agrees to drive Petya (perhaps through several intermediate junctions) to some other junction if the travel distance is not more than ti meters. Also, the cost of the ride doesn't depend on the distance and is equal to ci bourles. Taxis can't stop in the middle of a road. Each taxi can be used no more than once. Petya can catch taxi only in the junction, where it stands initially.
At the moment Petya is located on the junction x and the volleyball stadium is on the junction y. Determine the minimum amount of money Petya will need to drive to the stadium.
Input
The first line contains two integers n and m (1 ≤ n ≤ 1000, 0 ≤ m ≤ 1000). They are the number of junctions and roads in the city correspondingly. The junctions are numbered from 1 to n, inclusive. The next line contains two integers x and y (1 ≤ x, y ≤ n). They are the numbers of the initial and final junctions correspondingly. Next m lines contain the roads' description. Each road is described by a group of three integers ui, vi, wi (1 ≤ ui, vi ≤ n, 1 ≤ wi ≤ 109) — they are the numbers of the junctions connected by the road and the length of the road, correspondingly. The next n lines contain n pairs of integers ti and ci (1 ≤ ti, ci ≤ 109), which describe the taxi driver that waits at the i-th junction — the maximum distance he can drive and the drive's cost. The road can't connect the junction with itself, but between a pair of junctions there can be more than one road. All consecutive numbers in each line are separated by exactly one space character.
Output
If taxis can't drive Petya to the destination point, print "-1" (without the quotes). Otherwise, print the drive's minimum cost.
Please do not use the %lld specificator to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specificator.
Examples
Input
4 4
1 3
1 2 3
1 4 1
2 4 1
2 3 5
2 7
7 2
1 2
7 7
Output
9
Note
An optimal way — ride from the junction 1 to 2 (via junction 4), then from 2 to 3. It costs 7+2=9 bourles. | instruction | 0 | 18,285 | 1 | 36,570 |
Tags: shortest paths
Correct Solution:
```
import os
import sys
from io import BytesIO, IOBase
# region fastio
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
# ------------------------------
from math import factorial
from collections import Counter, defaultdict
from heapq import heapify, heappop, heappush
def RL(): return map(int, sys.stdin.readline().rstrip().split())
def RLL(): return list(map(int, sys.stdin.readline().rstrip().split()))
def N(): return int(input())
def comb(n, m): return factorial(n) / (factorial(m) * factorial(n - m)) if n >= m else 0
def perm(n, m): return factorial(n) // (factorial(n - m)) if n >= m else 0
def mdis(x1, y1, x2, y2): return abs(x1 - x2) + abs(y1 - y2)
def ctd(chr): return ord(chr)-ord("a")
mod = 998244353
INF = float('inf')
from heapq import heappush, heappop
# ------------------------------
def main():
n, m = RL()
x, y = RL()
gp = defaultdict(dict)
for _ in range(m):
u, v, w = RL()
gp[u][v] = min(gp[u].get(v, INF), w)
gp[v][u] = min(gp[v].get(u, INF), w)
cars = [[0, 0]]
for _ in range(n):
t, c = RL()
cars.append([t, c])
disarr = [[INF]*(n+1) for _ in range(n+1)]
for i in range(1, n+1):
disarr[i][i] = 0
newg = [[INF]*(n+1) for _ in range(n+1)]
dnex = defaultdict(list)
def dij(s):
q = [(0, s)]
vis = [0]*(n+1)
while q:
d, nd = heappop(q)
vis[nd] = 1
for nex in gp[nd]:
if vis[nex]==1: continue
dis = gp[nd][nex]+disarr[s][nd]
if dis<disarr[s][nex]:
disarr[s][nex] = dis
heappush(q, (dis, nex))
for i in range(1, n+1):
cd, cc = cars[s]
d = disarr[s][i]
if d<=cd:
newg[s][i] = min(newg[s][i], cc)
dnex[s].append(i)
def dij1(s):
q = [(0, s)]
vis = [0]*(n+1)
cst = [INF] * (n + 1)
cst[s] = 0
while q:
d, nd = heappop(q)
vis[nd] = 1
for nex in dnex[nd]:
if vis[nex]==1: continue
cs = cst[nd]+newg[nd][nex]
if cs<cst[nex]:
cst[nex] = cs
heappush(q, (cs, nex))
if cst[y]==INF:
print(-1)
else:
print(cst[y])
for i in range(1, n+1):
dij(i)
dij1(x)
# for i in newg:print(i)
if __name__ == "__main__":
main()
``` | output | 1 | 18,285 | 1 | 36,571 |
Provide a correct Python 3 solution for this coding contest problem.
In Takahashi Kingdom, there is an archipelago of N islands, called Takahashi Islands. For convenience, we will call them Island 1, Island 2, ..., Island N.
There are M kinds of regular boat services between these islands. Each service connects two islands. The i-th service connects Island a_i and Island b_i.
Cat Snuke is on Island 1 now, and wants to go to Island N. However, it turned out that there is no boat service from Island 1 to Island N, so he wants to know whether it is possible to go to Island N by using two boat services.
Help him.
Constraints
* 3 ≤ N ≤ 200 000
* 1 ≤ M ≤ 200 000
* 1 ≤ a_i < b_i ≤ N
* (a_i, b_i) \neq (1, N)
* If i \neq j, (a_i, b_i) \neq (a_j, b_j).
Input
Input is given from Standard Input in the following format:
N M
a_1 b_1
a_2 b_2
:
a_M b_M
Output
If it is possible to go to Island N by using two boat services, print `POSSIBLE`; otherwise, print `IMPOSSIBLE`.
Examples
Input
3 2
1 2
2 3
Output
POSSIBLE
Input
4 3
1 2
2 3
3 4
Output
IMPOSSIBLE
Input
100000 1
1 99999
Output
IMPOSSIBLE
Input
5 5
1 3
4 5
2 3
2 4
1 4
Output
POSSIBLE | instruction | 0 | 18,403 | 1 | 36,806 |
"Correct Solution:
```
from sys import stdin
input = stdin.readline
n, m = map(int,input().split())
from1 = [0]*(n+1)
ton = [0]*(n+1)
for i in range(m):
a, b = map(int,input().split())
if a == 1: from1[b] = 1
if b == n: ton[a] = 1
for i in range(n+1):
if from1[i] and ton[i]:
print("POSSIBLE")
break
else: print("IMPOSSIBLE")
``` | output | 1 | 18,403 | 1 | 36,807 |
Provide a correct Python 3 solution for this coding contest problem.
In Takahashi Kingdom, there is an archipelago of N islands, called Takahashi Islands. For convenience, we will call them Island 1, Island 2, ..., Island N.
There are M kinds of regular boat services between these islands. Each service connects two islands. The i-th service connects Island a_i and Island b_i.
Cat Snuke is on Island 1 now, and wants to go to Island N. However, it turned out that there is no boat service from Island 1 to Island N, so he wants to know whether it is possible to go to Island N by using two boat services.
Help him.
Constraints
* 3 ≤ N ≤ 200 000
* 1 ≤ M ≤ 200 000
* 1 ≤ a_i < b_i ≤ N
* (a_i, b_i) \neq (1, N)
* If i \neq j, (a_i, b_i) \neq (a_j, b_j).
Input
Input is given from Standard Input in the following format:
N M
a_1 b_1
a_2 b_2
:
a_M b_M
Output
If it is possible to go to Island N by using two boat services, print `POSSIBLE`; otherwise, print `IMPOSSIBLE`.
Examples
Input
3 2
1 2
2 3
Output
POSSIBLE
Input
4 3
1 2
2 3
3 4
Output
IMPOSSIBLE
Input
100000 1
1 99999
Output
IMPOSSIBLE
Input
5 5
1 3
4 5
2 3
2 4
1 4
Output
POSSIBLE | instruction | 0 | 18,404 | 1 | 36,808 |
"Correct Solution:
```
def examC():
def bfs(n, e, fordfs):
# 点の数、スタートの点、有向グラフ
W = [-1] * n
# 各点の状態量、最短距離とか,見たかどうかとか
W[e] = 0
que = deque()
que.append(e)
while que:
now = que.popleft()
nowW = W[now]
for ne in fordfs[now]:
if W[ne] == -1:
W[ne] = nowW + 1
que.append(ne)
return W
N, M = LI()
V = [[]for _ in range(N)]
for i in range(M):
a, b = LI()
a -= 1
b -= 1
V[a].append(b)
V[b].append(a)
L = bfs(N,0,V)
if L[N-1]==2:
print("POSSIBLE")
else:
print("IMPOSSIBLE")
return
def examD():
K = I()
N = 50
A = [i for i in range(N)]
for i in range(N):
A[-1-i] +=((K-i+49)//N)
print(N); print(" ".join(map(str,A)))
return
def examE():
N = I()
A = LI()
ans = 0
while(True):
cur = 0
for i in range(N):
cur += A[i]//N
for i in range(N):
A[i] = A[i]%N + cur-A[i]//N
ans += cur
if cur==0:
break
print(ans)
return
def examF():
ans = 0
print(ans)
return
import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LFI(): return list(map(float,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
alphabet = [chr(ord('a') + i) for i in range(26)]
if __name__ == '__main__':
examC()
"""
"""
``` | output | 1 | 18,404 | 1 | 36,809 |
Provide a correct Python 3 solution for this coding contest problem.
In Takahashi Kingdom, there is an archipelago of N islands, called Takahashi Islands. For convenience, we will call them Island 1, Island 2, ..., Island N.
There are M kinds of regular boat services between these islands. Each service connects two islands. The i-th service connects Island a_i and Island b_i.
Cat Snuke is on Island 1 now, and wants to go to Island N. However, it turned out that there is no boat service from Island 1 to Island N, so he wants to know whether it is possible to go to Island N by using two boat services.
Help him.
Constraints
* 3 ≤ N ≤ 200 000
* 1 ≤ M ≤ 200 000
* 1 ≤ a_i < b_i ≤ N
* (a_i, b_i) \neq (1, N)
* If i \neq j, (a_i, b_i) \neq (a_j, b_j).
Input
Input is given from Standard Input in the following format:
N M
a_1 b_1
a_2 b_2
:
a_M b_M
Output
If it is possible to go to Island N by using two boat services, print `POSSIBLE`; otherwise, print `IMPOSSIBLE`.
Examples
Input
3 2
1 2
2 3
Output
POSSIBLE
Input
4 3
1 2
2 3
3 4
Output
IMPOSSIBLE
Input
100000 1
1 99999
Output
IMPOSSIBLE
Input
5 5
1 3
4 5
2 3
2 4
1 4
Output
POSSIBLE | instruction | 0 | 18,405 | 1 | 36,810 |
"Correct Solution:
```
import sys, math, itertools, collections, heapq
sys.setrecursionlimit(10 ** 7)
pinf = float("inf")
ninf = -float("inf")
n, m = map(int, input().split())
edge = [[] for _ in range(n)]
for _ in range(m):
a, b = map(int, input().split())
edge[a - 1].append(b - 1)
edge[b - 1].append(a - 1)
ans = "IMPOSSIBLE"
n -= 1
for e in edge[0]:
if n in edge[e]:
ans = "POSSIBLE"
print(ans)
``` | output | 1 | 18,405 | 1 | 36,811 |
Provide a correct Python 3 solution for this coding contest problem.
In Takahashi Kingdom, there is an archipelago of N islands, called Takahashi Islands. For convenience, we will call them Island 1, Island 2, ..., Island N.
There are M kinds of regular boat services between these islands. Each service connects two islands. The i-th service connects Island a_i and Island b_i.
Cat Snuke is on Island 1 now, and wants to go to Island N. However, it turned out that there is no boat service from Island 1 to Island N, so he wants to know whether it is possible to go to Island N by using two boat services.
Help him.
Constraints
* 3 ≤ N ≤ 200 000
* 1 ≤ M ≤ 200 000
* 1 ≤ a_i < b_i ≤ N
* (a_i, b_i) \neq (1, N)
* If i \neq j, (a_i, b_i) \neq (a_j, b_j).
Input
Input is given from Standard Input in the following format:
N M
a_1 b_1
a_2 b_2
:
a_M b_M
Output
If it is possible to go to Island N by using two boat services, print `POSSIBLE`; otherwise, print `IMPOSSIBLE`.
Examples
Input
3 2
1 2
2 3
Output
POSSIBLE
Input
4 3
1 2
2 3
3 4
Output
IMPOSSIBLE
Input
100000 1
1 99999
Output
IMPOSSIBLE
Input
5 5
1 3
4 5
2 3
2 4
1 4
Output
POSSIBLE | instruction | 0 | 18,406 | 1 | 36,812 |
"Correct Solution:
```
# -*- coding: utf-8 -*-
N, M = map(int, input().split())
from1 = []
gotoN = []
for m in range(M):
a, b = list(map(int, input().split()))
if a==1:
from1.append(b)
if b==N:
gotoN.append(a)
can = set(from1) & set(gotoN)
if len(can) > 0:
print('POSSIBLE')
else:
print('IMPOSSIBLE')
``` | output | 1 | 18,406 | 1 | 36,813 |
Provide a correct Python 3 solution for this coding contest problem.
In Takahashi Kingdom, there is an archipelago of N islands, called Takahashi Islands. For convenience, we will call them Island 1, Island 2, ..., Island N.
There are M kinds of regular boat services between these islands. Each service connects two islands. The i-th service connects Island a_i and Island b_i.
Cat Snuke is on Island 1 now, and wants to go to Island N. However, it turned out that there is no boat service from Island 1 to Island N, so he wants to know whether it is possible to go to Island N by using two boat services.
Help him.
Constraints
* 3 ≤ N ≤ 200 000
* 1 ≤ M ≤ 200 000
* 1 ≤ a_i < b_i ≤ N
* (a_i, b_i) \neq (1, N)
* If i \neq j, (a_i, b_i) \neq (a_j, b_j).
Input
Input is given from Standard Input in the following format:
N M
a_1 b_1
a_2 b_2
:
a_M b_M
Output
If it is possible to go to Island N by using two boat services, print `POSSIBLE`; otherwise, print `IMPOSSIBLE`.
Examples
Input
3 2
1 2
2 3
Output
POSSIBLE
Input
4 3
1 2
2 3
3 4
Output
IMPOSSIBLE
Input
100000 1
1 99999
Output
IMPOSSIBLE
Input
5 5
1 3
4 5
2 3
2 4
1 4
Output
POSSIBLE | instruction | 0 | 18,407 | 1 | 36,814 |
"Correct Solution:
```
def ri(): return int(input())
def rli(): return list(map(int, input().split()))
def ris(): return list(input())
def pli(a): return "".join(list(map(str, a)))
N, M = rli()
keiro = [[False for i in range(2)] for j in range(N+1)]
for i in range(M):
a, b = rli()
if(b == 1 or b == N):
keiro[a][1 if b == 1 else 0] = True
elif(a == 1 or a == N):
keiro[b][1 if a == 1 else 0] = True
flag = False
for i in range(2, N):
if(keiro[i][1] and keiro[i][0]):
flag = True
if(flag):
print("POSSIBLE")
else:
print("IMPOSSIBLE")
``` | output | 1 | 18,407 | 1 | 36,815 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.