message stringlengths 2 45.8k | message_type stringclasses 2 values | message_id int64 0 1 | conversation_id int64 254 108k | cluster float64 3 3 | __index_level_0__ int64 508 217k |
|---|---|---|---|---|---|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Lunar rover finally reached planet X. After landing, he met an obstacle, that contains permutation p of length n. Scientists found out, that to overcome an obstacle, the robot should make p an identity permutation (make p_i = i for all i).
Unfortunately, scientists can't control the robot. Thus the only way to make p an identity permutation is applying the following operation to p multiple times:
* Select two indices i and j (i β j), such that p_j = i and swap the values of p_i and p_j. It takes robot (j - i)^2 seconds to do this operation.
Positions i and j are selected by the robot (scientists can't control it). He will apply this operation while p isn't an identity permutation. We can show that the robot will make no more than n operations regardless of the choice of i and j on each operation.
Scientists asked you to find out the maximum possible time it will take the robot to finish making p an identity permutation (i. e. worst-case scenario), so they can decide whether they should construct a new lunar rover or just rest and wait. They won't believe you without proof, so you should build an example of p and robot's operations that maximizes the answer.
For a better understanding of the statement, read the sample description.
Input
The first line of input contains a single integer t (1 β€ t β€ 10^4) β the number of test cases.
Each of next t lines contains the single integer n (2 β€ n β€ 10^5) β the length of p.
Note, that p is not given to you. You should find the maximum possible time over all permutations of length n.
It is guaranteed, that the total sum of n over all test cases doesn't exceed 10^5.
Output
For each test case in the first line, print how many seconds will the robot spend in the worst case.
In the next line, print the initial value of p that you used to construct an answer.
In the next line, print the number of operations m β€ n that the robot makes in your example.
In the each of next m lines print two integers i and j β indices of positions that the robot will swap on this operation. Note that p_j = i must holds (at the time of operation).
Example
Input
3
2
3
3
Output
1
2 1
1
2 1
5
2 3 1
2
1 3
3 2
5
2 3 1
2
1 3
2 3
Note
For n = 2, p can be either [1, 2] or [2, 1]. In the first case p is already identity, otherwise robot will make it an identity permutation in 1 second regardless of choise i and j on the first operation.
For n = 3, p can be equals [2, 3, 1].
* If robot will select i = 3, j = 2 on the first operation, p will become [2, 1, 3] in one second. Now robot can select only i = 1, j = 2 or i = 2, j = 1. In both cases, p will become identity in one more second (2 seconds in total).
* If robot will select i = 1, j = 3 on the first operation, p will become [1, 3, 2] in four seconds. Regardless of choise of i and j on the second operation, p will become identity in five seconds.
We can show, that for permutation of length 3 robot will always finish all operation in no more than 5 seconds.
Submitted Solution:
```
from sys import stdin, gettrace
if gettrace():
def inputi():
return input()
else:
def input():
return next(stdin)[:-1]
def inputi():
return stdin.buffer.readline()
def solve():
n = int(input())
pp = list(range(1,n+1))
c = 0
res = []
pp[0], pp[n-1] = pp[n-1],pp[0]
res.append((1, n))
c += (n-1)**2
for i in range(1, n//2):
pp[0], pp[-i-1] = pp[-i-1], pp[0]
res.append((n-i, 1))
pp[n-1], pp[i] = pp[i], pp[n-1]
res.append((i+1, n))
c += (n-i-1)**2*2
if n%2 == 1:
pp[0], pp[n//2] = pp[n//2], pp[0]
res.append((n//2 + 1, 1))
c += (n//2)**2
print(c)
print(' '.join(map(str, pp)))
print(len(res))
for i, j in res[::-1]:
print(i, j)
def main():
t = int(input())
for _ in range(t):
solve()
if __name__ == "__main__":
main()
``` | instruction | 0 | 69,166 | 3 | 138,332 |
Yes | output | 1 | 69,166 | 3 | 138,333 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Lunar rover finally reached planet X. After landing, he met an obstacle, that contains permutation p of length n. Scientists found out, that to overcome an obstacle, the robot should make p an identity permutation (make p_i = i for all i).
Unfortunately, scientists can't control the robot. Thus the only way to make p an identity permutation is applying the following operation to p multiple times:
* Select two indices i and j (i β j), such that p_j = i and swap the values of p_i and p_j. It takes robot (j - i)^2 seconds to do this operation.
Positions i and j are selected by the robot (scientists can't control it). He will apply this operation while p isn't an identity permutation. We can show that the robot will make no more than n operations regardless of the choice of i and j on each operation.
Scientists asked you to find out the maximum possible time it will take the robot to finish making p an identity permutation (i. e. worst-case scenario), so they can decide whether they should construct a new lunar rover or just rest and wait. They won't believe you without proof, so you should build an example of p and robot's operations that maximizes the answer.
For a better understanding of the statement, read the sample description.
Input
The first line of input contains a single integer t (1 β€ t β€ 10^4) β the number of test cases.
Each of next t lines contains the single integer n (2 β€ n β€ 10^5) β the length of p.
Note, that p is not given to you. You should find the maximum possible time over all permutations of length n.
It is guaranteed, that the total sum of n over all test cases doesn't exceed 10^5.
Output
For each test case in the first line, print how many seconds will the robot spend in the worst case.
In the next line, print the initial value of p that you used to construct an answer.
In the next line, print the number of operations m β€ n that the robot makes in your example.
In the each of next m lines print two integers i and j β indices of positions that the robot will swap on this operation. Note that p_j = i must holds (at the time of operation).
Example
Input
3
2
3
3
Output
1
2 1
1
2 1
5
2 3 1
2
1 3
3 2
5
2 3 1
2
1 3
2 3
Note
For n = 2, p can be either [1, 2] or [2, 1]. In the first case p is already identity, otherwise robot will make it an identity permutation in 1 second regardless of choise i and j on the first operation.
For n = 3, p can be equals [2, 3, 1].
* If robot will select i = 3, j = 2 on the first operation, p will become [2, 1, 3] in one second. Now robot can select only i = 1, j = 2 or i = 2, j = 1. In both cases, p will become identity in one more second (2 seconds in total).
* If robot will select i = 1, j = 3 on the first operation, p will become [1, 3, 2] in four seconds. Regardless of choise of i and j on the second operation, p will become identity in five seconds.
We can show, that for permutation of length 3 robot will always finish all operation in no more than 5 seconds.
Submitted Solution:
```
from collections import defaultdict
def calc(n):
return n * (n + 1) * (2 * n + 1) // 6
def doTestcase():
n = int(input())
print(calc(n - 1))
a = [i+2 for i in range(n-1)]
a.append(1)
print(*a)
print(n-1)
for i in range(n-1):
print(i+1, n)
if __name__ == '__main__':
t = int(input())
for _ in range(t):
doTestcase()
``` | instruction | 0 | 69,167 | 3 | 138,334 |
No | output | 1 | 69,167 | 3 | 138,335 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Lunar rover finally reached planet X. After landing, he met an obstacle, that contains permutation p of length n. Scientists found out, that to overcome an obstacle, the robot should make p an identity permutation (make p_i = i for all i).
Unfortunately, scientists can't control the robot. Thus the only way to make p an identity permutation is applying the following operation to p multiple times:
* Select two indices i and j (i β j), such that p_j = i and swap the values of p_i and p_j. It takes robot (j - i)^2 seconds to do this operation.
Positions i and j are selected by the robot (scientists can't control it). He will apply this operation while p isn't an identity permutation. We can show that the robot will make no more than n operations regardless of the choice of i and j on each operation.
Scientists asked you to find out the maximum possible time it will take the robot to finish making p an identity permutation (i. e. worst-case scenario), so they can decide whether they should construct a new lunar rover or just rest and wait. They won't believe you without proof, so you should build an example of p and robot's operations that maximizes the answer.
For a better understanding of the statement, read the sample description.
Input
The first line of input contains a single integer t (1 β€ t β€ 10^4) β the number of test cases.
Each of next t lines contains the single integer n (2 β€ n β€ 10^5) β the length of p.
Note, that p is not given to you. You should find the maximum possible time over all permutations of length n.
It is guaranteed, that the total sum of n over all test cases doesn't exceed 10^5.
Output
For each test case in the first line, print how many seconds will the robot spend in the worst case.
In the next line, print the initial value of p that you used to construct an answer.
In the next line, print the number of operations m β€ n that the robot makes in your example.
In the each of next m lines print two integers i and j β indices of positions that the robot will swap on this operation. Note that p_j = i must holds (at the time of operation).
Example
Input
3
2
3
3
Output
1
2 1
1
2 1
5
2 3 1
2
1 3
3 2
5
2 3 1
2
1 3
2 3
Note
For n = 2, p can be either [1, 2] or [2, 1]. In the first case p is already identity, otherwise robot will make it an identity permutation in 1 second regardless of choise i and j on the first operation.
For n = 3, p can be equals [2, 3, 1].
* If robot will select i = 3, j = 2 on the first operation, p will become [2, 1, 3] in one second. Now robot can select only i = 1, j = 2 or i = 2, j = 1. In both cases, p will become identity in one more second (2 seconds in total).
* If robot will select i = 1, j = 3 on the first operation, p will become [1, 3, 2] in four seconds. Regardless of choise of i and j on the second operation, p will become identity in five seconds.
We can show, that for permutation of length 3 robot will always finish all operation in no more than 5 seconds.
Submitted Solution:
```
import sys
input=sys.stdin.readline
t = int(input())
for _ in range(t):
n = int(input())
time = 0
integer = [i for i in range(1,n+1)]
l = []
for i in range(1,n//2):
time += (n-1-i)**2
integer[-1],integer[i] = integer[i],integer[-1]
l.append((i+1,n))
for i in range(n//2,n):
time += i**2
integer[0],integer[i] = integer[i],integer[0]
l.append((1,n))
l.reverse()
print(time)
print(*integer)
print(len(l))
for i in l:
print(i[0],i[1])
``` | instruction | 0 | 69,168 | 3 | 138,336 |
No | output | 1 | 69,168 | 3 | 138,337 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Lunar rover finally reached planet X. After landing, he met an obstacle, that contains permutation p of length n. Scientists found out, that to overcome an obstacle, the robot should make p an identity permutation (make p_i = i for all i).
Unfortunately, scientists can't control the robot. Thus the only way to make p an identity permutation is applying the following operation to p multiple times:
* Select two indices i and j (i β j), such that p_j = i and swap the values of p_i and p_j. It takes robot (j - i)^2 seconds to do this operation.
Positions i and j are selected by the robot (scientists can't control it). He will apply this operation while p isn't an identity permutation. We can show that the robot will make no more than n operations regardless of the choice of i and j on each operation.
Scientists asked you to find out the maximum possible time it will take the robot to finish making p an identity permutation (i. e. worst-case scenario), so they can decide whether they should construct a new lunar rover or just rest and wait. They won't believe you without proof, so you should build an example of p and robot's operations that maximizes the answer.
For a better understanding of the statement, read the sample description.
Input
The first line of input contains a single integer t (1 β€ t β€ 10^4) β the number of test cases.
Each of next t lines contains the single integer n (2 β€ n β€ 10^5) β the length of p.
Note, that p is not given to you. You should find the maximum possible time over all permutations of length n.
It is guaranteed, that the total sum of n over all test cases doesn't exceed 10^5.
Output
For each test case in the first line, print how many seconds will the robot spend in the worst case.
In the next line, print the initial value of p that you used to construct an answer.
In the next line, print the number of operations m β€ n that the robot makes in your example.
In the each of next m lines print two integers i and j β indices of positions that the robot will swap on this operation. Note that p_j = i must holds (at the time of operation).
Example
Input
3
2
3
3
Output
1
2 1
1
2 1
5
2 3 1
2
1 3
3 2
5
2 3 1
2
1 3
2 3
Note
For n = 2, p can be either [1, 2] or [2, 1]. In the first case p is already identity, otherwise robot will make it an identity permutation in 1 second regardless of choise i and j on the first operation.
For n = 3, p can be equals [2, 3, 1].
* If robot will select i = 3, j = 2 on the first operation, p will become [2, 1, 3] in one second. Now robot can select only i = 1, j = 2 or i = 2, j = 1. In both cases, p will become identity in one more second (2 seconds in total).
* If robot will select i = 1, j = 3 on the first operation, p will become [1, 3, 2] in four seconds. Regardless of choise of i and j on the second operation, p will become identity in five seconds.
We can show, that for permutation of length 3 robot will always finish all operation in no more than 5 seconds.
Submitted Solution:
```
#!/usr/bin/env python
import os
import sys
from io import BytesIO, IOBase
def main():
for _ in range(int(input())):
n = int(input())
print((n-1) * n * (2 * n - 1) // 6 - 1)
print(" ".join(map(str,range(2,n + 1))) + " 1")
for i in range(n - 1):
print(str(i + 1) + " " + str(n))
# 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")
# endregion
if __name__ == "__main__":
main()
``` | instruction | 0 | 69,169 | 3 | 138,338 |
No | output | 1 | 69,169 | 3 | 138,339 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Lunar rover finally reached planet X. After landing, he met an obstacle, that contains permutation p of length n. Scientists found out, that to overcome an obstacle, the robot should make p an identity permutation (make p_i = i for all i).
Unfortunately, scientists can't control the robot. Thus the only way to make p an identity permutation is applying the following operation to p multiple times:
* Select two indices i and j (i β j), such that p_j = i and swap the values of p_i and p_j. It takes robot (j - i)^2 seconds to do this operation.
Positions i and j are selected by the robot (scientists can't control it). He will apply this operation while p isn't an identity permutation. We can show that the robot will make no more than n operations regardless of the choice of i and j on each operation.
Scientists asked you to find out the maximum possible time it will take the robot to finish making p an identity permutation (i. e. worst-case scenario), so they can decide whether they should construct a new lunar rover or just rest and wait. They won't believe you without proof, so you should build an example of p and robot's operations that maximizes the answer.
For a better understanding of the statement, read the sample description.
Input
The first line of input contains a single integer t (1 β€ t β€ 10^4) β the number of test cases.
Each of next t lines contains the single integer n (2 β€ n β€ 10^5) β the length of p.
Note, that p is not given to you. You should find the maximum possible time over all permutations of length n.
It is guaranteed, that the total sum of n over all test cases doesn't exceed 10^5.
Output
For each test case in the first line, print how many seconds will the robot spend in the worst case.
In the next line, print the initial value of p that you used to construct an answer.
In the next line, print the number of operations m β€ n that the robot makes in your example.
In the each of next m lines print two integers i and j β indices of positions that the robot will swap on this operation. Note that p_j = i must holds (at the time of operation).
Example
Input
3
2
3
3
Output
1
2 1
1
2 1
5
2 3 1
2
1 3
3 2
5
2 3 1
2
1 3
2 3
Note
For n = 2, p can be either [1, 2] or [2, 1]. In the first case p is already identity, otherwise robot will make it an identity permutation in 1 second regardless of choise i and j on the first operation.
For n = 3, p can be equals [2, 3, 1].
* If robot will select i = 3, j = 2 on the first operation, p will become [2, 1, 3] in one second. Now robot can select only i = 1, j = 2 or i = 2, j = 1. In both cases, p will become identity in one more second (2 seconds in total).
* If robot will select i = 1, j = 3 on the first operation, p will become [1, 3, 2] in four seconds. Regardless of choise of i and j on the second operation, p will become identity in five seconds.
We can show, that for permutation of length 3 robot will always finish all operation in no more than 5 seconds.
Submitted Solution:
```
# by the authority of GOD author: manhar singh sachdev #
import os,sys
from io import BytesIO,IOBase
def main():
for _ in range(int(input())):
n = int(input())
print(n*(n-1)*(2*n-1)//6)
print(*(list(range(2,n+1))+[1]))
print(n-1)
for i in range(1,n):
print(i,n)
#Fast IO Region
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")
if __name__ == '__main__':
main()
``` | instruction | 0 | 69,170 | 3 | 138,340 |
No | output | 1 | 69,170 | 3 | 138,341 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, training at that racetrack, equals n. And each of them regularly runs distances within a particular segment of the racetrack, which is the same for each sportsman. For example, the first sportsman runs from position a1 to position b1, the second β from a2 to b2
What is the minimum distance that Bob should move to have a chance to take pictures of each sportsman? Bob can take a picture of a sportsman, if he stands within the segment that this sportsman covers on the racetrack.
Input
The first line of the input file contains integers n and x0 (1 β€ n β€ 100; 0 β€ x0 β€ 1000). The following n lines contain pairs of integers ai, bi (0 β€ ai, bi β€ 1000; ai β bi).
Output
Output the required minimum distance in the same units as the positions on the racetrack. If there is no such a position, output -1.
Examples
Input
3 3
0 7
14 2
4 6
Output
1 | instruction | 0 | 69,174 | 3 | 138,348 |
Tags: implementation
Correct Solution:
```
n, x0 = map(int, input().split())
kiri = 0
kanan = 1000
for _ in range(n):
a, b = map(int, input().split())
kiri = max(kiri, min(a, b))
kanan = min(kanan, max(a, b))
if kiri > kanan:
print(-1)
elif kiri <= x0 <= kanan:
print(0)
elif x0 < kiri:
print(kiri - x0)
else:
print(x0 - kanan)
``` | output | 1 | 69,174 | 3 | 138,349 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, training at that racetrack, equals n. And each of them regularly runs distances within a particular segment of the racetrack, which is the same for each sportsman. For example, the first sportsman runs from position a1 to position b1, the second β from a2 to b2
What is the minimum distance that Bob should move to have a chance to take pictures of each sportsman? Bob can take a picture of a sportsman, if he stands within the segment that this sportsman covers on the racetrack.
Input
The first line of the input file contains integers n and x0 (1 β€ n β€ 100; 0 β€ x0 β€ 1000). The following n lines contain pairs of integers ai, bi (0 β€ ai, bi β€ 1000; ai β bi).
Output
Output the required minimum distance in the same units as the positions on the racetrack. If there is no such a position, output -1.
Examples
Input
3 3
0 7
14 2
4 6
Output
1
Submitted Solution:
```
n, x0 = [int(x) for x in input().split()]
intersections = []
for _ in range(n):
a,b = [int(x) for x in input().split()]
a,b = min(a,b), max(a,b)
if n==1 and a<= x0 <=b:
print('0')
exit()
if intersections:
currentRange = list(range(a,b+1))
inersectionOfCurrentAndPrevious = set(currentRange).intersection(set(intersections))
if len(inersectionOfCurrentAndPrevious):
intersections = list(inersectionOfCurrentAndPrevious)
else:
print('-1')
exit()
else:
intersections = list(range(a,b+1))
intersections = map(lambda x:abs(x-x0), intersections)
print(min(intersections))
``` | instruction | 0 | 69,179 | 3 | 138,358 |
Yes | output | 1 | 69,179 | 3 | 138,359 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, training at that racetrack, equals n. And each of them regularly runs distances within a particular segment of the racetrack, which is the same for each sportsman. For example, the first sportsman runs from position a1 to position b1, the second β from a2 to b2
What is the minimum distance that Bob should move to have a chance to take pictures of each sportsman? Bob can take a picture of a sportsman, if he stands within the segment that this sportsman covers on the racetrack.
Input
The first line of the input file contains integers n and x0 (1 β€ n β€ 100; 0 β€ x0 β€ 1000). The following n lines contain pairs of integers ai, bi (0 β€ ai, bi β€ 1000; ai β bi).
Output
Output the required minimum distance in the same units as the positions on the racetrack. If there is no such a position, output -1.
Examples
Input
3 3
0 7
14 2
4 6
Output
1
Submitted Solution:
```
###################
#-@ June 25th 2019.
###################
##################################################################
# Getting Segment Count and initial Location.
count,loc = tuple(map(int,input().split(' ')))
# Method to determine if intersection is possible.
def empty_intersection(tOne,tTwo):
return True
# Method to Perform intersection of two segements.
def and_segments(t0,t1):
and_tuple = max(t0[0],t1[0]),min(t0[1],t1[1])
return and_tuple
# Alogrithm.
p_range = -1,1001
for i in range(count):
# Getting new tuple.
t = tuple(map(int,input().split(' ')))
t = min(t[0],t[1]),max(t[0],t[1])
# Anding Segments.
p_range = and_segments(p_range,t)
# Case no intersection.
if p_range[0]>p_range[1]:
min_dist = -1
# Case loc in range.
elif min(p_range)<=loc<=max(p_range):
min_dist = 0
# Case loc outside range.
else: min_dist = min(abs(p_range[0]-loc),abs(p_range[1]-loc))
# Verdict.
print(min_dist)
##################################################################
########################################
# Programming-Credits-atifcppprogrammer.
########################################
``` | instruction | 0 | 69,180 | 3 | 138,360 |
Yes | output | 1 | 69,180 | 3 | 138,361 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, training at that racetrack, equals n. And each of them regularly runs distances within a particular segment of the racetrack, which is the same for each sportsman. For example, the first sportsman runs from position a1 to position b1, the second β from a2 to b2
What is the minimum distance that Bob should move to have a chance to take pictures of each sportsman? Bob can take a picture of a sportsman, if he stands within the segment that this sportsman covers on the racetrack.
Input
The first line of the input file contains integers n and x0 (1 β€ n β€ 100; 0 β€ x0 β€ 1000). The following n lines contain pairs of integers ai, bi (0 β€ ai, bi β€ 1000; ai β bi).
Output
Output the required minimum distance in the same units as the positions on the racetrack. If there is no such a position, output -1.
Examples
Input
3 3
0 7
14 2
4 6
Output
1
Submitted Solution:
```
n,x0=map(int,input().split())
l=-1
r=1001
for i in range(n):
a,b=map(int,input().split())
l=max(l,min(a,b))
r=min(r,max(a,b))
if(l>r):
print("-1")
elif(x0>=l and x0<=r):
print("0")
elif(x0<l):
print(l-x0)
else:
print(x0-r)
``` | instruction | 0 | 69,181 | 3 | 138,362 |
Yes | output | 1 | 69,181 | 3 | 138,363 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, training at that racetrack, equals n. And each of them regularly runs distances within a particular segment of the racetrack, which is the same for each sportsman. For example, the first sportsman runs from position a1 to position b1, the second β from a2 to b2
What is the minimum distance that Bob should move to have a chance to take pictures of each sportsman? Bob can take a picture of a sportsman, if he stands within the segment that this sportsman covers on the racetrack.
Input
The first line of the input file contains integers n and x0 (1 β€ n β€ 100; 0 β€ x0 β€ 1000). The following n lines contain pairs of integers ai, bi (0 β€ ai, bi β€ 1000; ai β bi).
Output
Output the required minimum distance in the same units as the positions on the racetrack. If there is no such a position, output -1.
Examples
Input
3 3
0 7
14 2
4 6
Output
1
Submitted Solution:
```
n,x0=map(int,input().split())
x=[0]*1001
c=0
for i in range(n):
a,b=map(int,input().split())
if a>b:
a,b=b,a
c+=1
for i in range(a,b+1):
x[i]+=1
if x[x0]==n:
print(0)
exit()
ans=1e9
for i in range(x0+1,1001):
if x[i]==n:
ans=min(ans,i-x0)
break
for i in range(x0-1,-1,-1):
if x[i]==n:
ans=min(ans,x0-i)
break
if ans==1e9:
print(-1)
else:
print(ans)
``` | instruction | 0 | 69,182 | 3 | 138,364 |
Yes | output | 1 | 69,182 | 3 | 138,365 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, training at that racetrack, equals n. And each of them regularly runs distances within a particular segment of the racetrack, which is the same for each sportsman. For example, the first sportsman runs from position a1 to position b1, the second β from a2 to b2
What is the minimum distance that Bob should move to have a chance to take pictures of each sportsman? Bob can take a picture of a sportsman, if he stands within the segment that this sportsman covers on the racetrack.
Input
The first line of the input file contains integers n and x0 (1 β€ n β€ 100; 0 β€ x0 β€ 1000). The following n lines contain pairs of integers ai, bi (0 β€ ai, bi β€ 1000; ai β bi).
Output
Output the required minimum distance in the same units as the positions on the racetrack. If there is no such a position, output -1.
Examples
Input
3 3
0 7
14 2
4 6
Output
1
Submitted Solution:
```
n,x0=map(int,input().split())
x=[0]*1001
c=0
for i in range(n):
a,b=map(int,input().split())
if a>b:
a,b=b,a
if a<=x0<=b:
continue
c+=1
for i in range(a,b+1):
x[i]+=1
ans=1e9
for i in range(x0+1,10001):
if x[i]==c:
ans=min(ans,i-x0)
break
for i in range(x0-1,-1,-1):
if x[i]==c:
ans=min(ans,x0-i)
break
print(ans)
``` | instruction | 0 | 69,183 | 3 | 138,366 |
No | output | 1 | 69,183 | 3 | 138,367 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, training at that racetrack, equals n. And each of them regularly runs distances within a particular segment of the racetrack, which is the same for each sportsman. For example, the first sportsman runs from position a1 to position b1, the second β from a2 to b2
What is the minimum distance that Bob should move to have a chance to take pictures of each sportsman? Bob can take a picture of a sportsman, if he stands within the segment that this sportsman covers on the racetrack.
Input
The first line of the input file contains integers n and x0 (1 β€ n β€ 100; 0 β€ x0 β€ 1000). The following n lines contain pairs of integers ai, bi (0 β€ ai, bi β€ 1000; ai β bi).
Output
Output the required minimum distance in the same units as the positions on the racetrack. If there is no such a position, output -1.
Examples
Input
3 3
0 7
14 2
4 6
Output
1
Submitted Solution:
```
n,x = map(int,input().split())
count = 0
l = []
for i in range(n):
a,b = map(int,input().split())
l.append([min(a,b),max(a,b)])
l.sort()
a = 0
b = 0
for i in range(0,1):
flag = 0
for j in range(n):
if i!=j and i == 0:
if l[i][0]<=l[j][0]<=l[i][1]:
a = l[j][0]
b = min(l[j][1],l[i][1])
else:
flag = 1
elif i!=0 and i!=j:
if a<=l[j][0]<=b:
a = l[j][0]
b = min(l[j][1],b)
else:
flag = 1
if flag == 1:
break
if flag == 1:
print(-1)
else:
print(min(abs(x-a),abs(x-b)))
``` | instruction | 0 | 69,184 | 3 | 138,368 |
No | output | 1 | 69,184 | 3 | 138,369 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, training at that racetrack, equals n. And each of them regularly runs distances within a particular segment of the racetrack, which is the same for each sportsman. For example, the first sportsman runs from position a1 to position b1, the second β from a2 to b2
What is the minimum distance that Bob should move to have a chance to take pictures of each sportsman? Bob can take a picture of a sportsman, if he stands within the segment that this sportsman covers on the racetrack.
Input
The first line of the input file contains integers n and x0 (1 β€ n β€ 100; 0 β€ x0 β€ 1000). The following n lines contain pairs of integers ai, bi (0 β€ ai, bi β€ 1000; ai β bi).
Output
Output the required minimum distance in the same units as the positions on the racetrack. If there is no such a position, output -1.
Examples
Input
3 3
0 7
14 2
4 6
Output
1
Submitted Solution:
```
lines, loc = list(map(int, input().split(" ")))
notrange = []
for line in range(lines):
x,y = list(map(int, input().split(" ")))
if x > y: x,y=y,x
if x <= loc and loc <=y:
z= 0
else:
notrange.append((x,y))
smallest, biggest = loc,loc
for entry in notrange:
if entry[1] < loc:
if smallest > entry[1]: smallest = entry[1]
elif entry[0] > loc:
if biggest < entry[0]: biggest = entry[0]
down = loc - smallest
up = biggest - loc
print(up*2+down) if up < down else print(up+down*2)
``` | instruction | 0 | 69,185 | 3 | 138,370 |
No | output | 1 | 69,185 | 3 | 138,371 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, training at that racetrack, equals n. And each of them regularly runs distances within a particular segment of the racetrack, which is the same for each sportsman. For example, the first sportsman runs from position a1 to position b1, the second β from a2 to b2
What is the minimum distance that Bob should move to have a chance to take pictures of each sportsman? Bob can take a picture of a sportsman, if he stands within the segment that this sportsman covers on the racetrack.
Input
The first line of the input file contains integers n and x0 (1 β€ n β€ 100; 0 β€ x0 β€ 1000). The following n lines contain pairs of integers ai, bi (0 β€ ai, bi β€ 1000; ai β bi).
Output
Output the required minimum distance in the same units as the positions on the racetrack. If there is no such a position, output -1.
Examples
Input
3 3
0 7
14 2
4 6
Output
1
Submitted Solution:
```
n,k=map(int, input().split())
minn=-1; maxx=1001
for _ in range(n):
x,y=sorted(map(int, input().split()))
if x>minn: minn=x
if y<maxx: maxx=y
print(minn, maxx)
if minn<=k<=maxx: print(0)
elif maxx<minn: print(-1)
else: print(min(abs(minn-k), abs(k-maxx)))
``` | instruction | 0 | 69,186 | 3 | 138,372 |
No | output | 1 | 69,186 | 3 | 138,373 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The Smart Beaver from ABBYY plans a space travel on an ultramodern spaceship. During the voyage he plans to visit n planets. For planet i ai is the maximum number of suitcases that an alien tourist is allowed to bring to the planet, and bi is the number of citizens on the planet.
The Smart Beaver is going to bring some presents from ABBYY to the planets he will be visiting. The presents are packed in suitcases, x presents in each. The Beaver will take to the ship exactly a1 + ... + an suitcases.
As the Beaver lands on the i-th planet, he takes ai suitcases and goes out. On the first day on the planet the Beaver takes a walk and gets to know the citizens. On the second and all subsequent days the Beaver gives presents to the citizens β each of the bi citizens gets one present per day. The Beaver leaves the planet in the evening of the day when the number of presents left is strictly less than the number of citizens (i.e. as soon as he won't be able to give away the proper number of presents the next day). He leaves the remaining presents at the hotel.
The Beaver is going to spend exactly c days traveling. The time spent on flights between the planets is considered to be zero. In how many ways can one choose the positive integer x so that the planned voyage will take exactly c days?
Input
The first input line contains space-separated integers n and c β the number of planets that the Beaver is going to visit and the number of days he is going to spend traveling, correspondingly.
The next n lines contain pairs of space-separated integers ai, bi (1 β€ i β€ n) β the number of suitcases he can bring to the i-th planet and the number of citizens of the i-th planet, correspondingly.
The input limitations for getting 30 points are:
* 1 β€ n β€ 100
* 1 β€ ai β€ 100
* 1 β€ bi β€ 100
* 1 β€ c β€ 100
The input limitations for getting 100 points are:
* 1 β€ n β€ 104
* 0 β€ ai β€ 109
* 1 β€ bi β€ 109
* 1 β€ c β€ 109
Due to possible overflow, it is recommended to use the 64-bit arithmetic. In some solutions even the 64-bit arithmetic can overflow. So be careful in calculations!
Output
Print a single number k β the number of ways to choose x so as to travel for exactly c days. If there are infinitely many possible values of x, print -1.
Please do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use cin, cout streams or the %I64d specifier.
Examples
Input
2 5
1 5
2 4
Output
1
Note
In the first example there is only one suitable value x = 5. Then the Beaver takes 1 suitcase with 5 presents to the first planet. Here he spends 2 days: he hangs around on the first day, and he gives away five presents on the second day. He takes 2 suitcases with 10 presents to the second planet. Here he spends 3 days β he gives away 4 presents on the second and the third days and leaves the remaining 2 presents at the hotel. In total, the Beaver spends 5 days traveling.
For x = 4 or less the Beaver won't have enough presents for the second day on the first planet, so the voyage will end too soon. For x = 6 and more the Beaver will spend at least one more day on the second planet, and the voyage will take too long. | instruction | 0 | 69,204 | 3 | 138,408 |
Tags: binary search
Correct Solution:
```
n,c = map(int,input().split())
from sys import stdin
lst,q,zero = [],0,0
for i in range(n):
a,b = map(int,stdin.readline().split())
lst.append([a,b])
q=max(q,b*c)
if a==0:zero+=1
def cout(x):
res=n
for i,item in enumerate(lst):
y,z=item[0],item[1]
res+=(x*y//z)
return res
from sys import exit
if zero==n:
if n==c:print(-1)
else:print(0)
exit()
l,r=0,q
while l+1<r:
mid = (l+r)//2
result=cout(mid)
if result<c:l=mid
elif result>c:r=mid
else:break
if r-l==1:
if cout(l)!=c and cout(r)!=c:print(0);exit()
i,j=l,mid
while i+1<j:
middle=(i+j)//2
if cout(middle)==c:j=middle
else:i=middle
i2,j2=mid,r
while i2+1<j2:
middle2=(i2+j2)//2
if cout(middle2)==c:i2=middle2
else:j2=middle2
if i2==j:
if cout(j)!=c:print(0);exit()
print(i2-j+1)
``` | output | 1 | 69,204 | 3 | 138,409 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The Smart Beaver from ABBYY plans a space travel on an ultramodern spaceship. During the voyage he plans to visit n planets. For planet i ai is the maximum number of suitcases that an alien tourist is allowed to bring to the planet, and bi is the number of citizens on the planet.
The Smart Beaver is going to bring some presents from ABBYY to the planets he will be visiting. The presents are packed in suitcases, x presents in each. The Beaver will take to the ship exactly a1 + ... + an suitcases.
As the Beaver lands on the i-th planet, he takes ai suitcases and goes out. On the first day on the planet the Beaver takes a walk and gets to know the citizens. On the second and all subsequent days the Beaver gives presents to the citizens β each of the bi citizens gets one present per day. The Beaver leaves the planet in the evening of the day when the number of presents left is strictly less than the number of citizens (i.e. as soon as he won't be able to give away the proper number of presents the next day). He leaves the remaining presents at the hotel.
The Beaver is going to spend exactly c days traveling. The time spent on flights between the planets is considered to be zero. In how many ways can one choose the positive integer x so that the planned voyage will take exactly c days?
Input
The first input line contains space-separated integers n and c β the number of planets that the Beaver is going to visit and the number of days he is going to spend traveling, correspondingly.
The next n lines contain pairs of space-separated integers ai, bi (1 β€ i β€ n) β the number of suitcases he can bring to the i-th planet and the number of citizens of the i-th planet, correspondingly.
The input limitations for getting 30 points are:
* 1 β€ n β€ 100
* 1 β€ ai β€ 100
* 1 β€ bi β€ 100
* 1 β€ c β€ 100
The input limitations for getting 100 points are:
* 1 β€ n β€ 104
* 0 β€ ai β€ 109
* 1 β€ bi β€ 109
* 1 β€ c β€ 109
Due to possible overflow, it is recommended to use the 64-bit arithmetic. In some solutions even the 64-bit arithmetic can overflow. So be careful in calculations!
Output
Print a single number k β the number of ways to choose x so as to travel for exactly c days. If there are infinitely many possible values of x, print -1.
Please do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use cin, cout streams or the %I64d specifier.
Examples
Input
2 5
1 5
2 4
Output
1
Note
In the first example there is only one suitable value x = 5. Then the Beaver takes 1 suitcase with 5 presents to the first planet. Here he spends 2 days: he hangs around on the first day, and he gives away five presents on the second day. He takes 2 suitcases with 10 presents to the second planet. Here he spends 3 days β he gives away 4 presents on the second and the third days and leaves the remaining 2 presents at the hotel. In total, the Beaver spends 5 days traveling.
For x = 4 or less the Beaver won't have enough presents for the second day on the first planet, so the voyage will end too soon. For x = 6 and more the Beaver will spend at least one more day on the second planet, and the voyage will take too long. | instruction | 0 | 69,205 | 3 | 138,410 |
Tags: binary search
Correct Solution:
```
# by the authority of GOD author: manhar singh sachdev #
import os,sys
from io import BytesIO, IOBase
def check(a,b,tar,x):
ans = 0
for i in range(len(a)):
ans += (a[i]*x)//b[i]
if ans == tar:
return 0
elif ans > tar:
return 1
else:
return -1
def main():
n,c = map(int,input().split())
a,b = [],[]
for _ in range(n):
a1,b1 = map(int,input().split())
a.append(a1)
b.append(b1)
if not sum(a):
return -1 if c==n else 0
if c < n:
return 0
val,tar,lo,hi,maxi,mini = -1,c-n,1,10**18,10**20,1
while hi >= lo:
x = (hi+lo)//2
y = check(a,b,tar,x)
if not y:
val = x
break
elif y == 1:
hi = x-1
else:
lo = x+1
if val == -1:
return 0
for i in range(n):
if not a[i]:
continue
zz = (((a[i]*val)//b[i])*b[i])
mini = max(mini,zz//a[i]+(zz%a[i]!=0))
zz += b[i]
maxi = min(maxi,zz//a[i]+(zz%a[i]!=0))
return maxi-mini
#Fast IO Region
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")
if __name__ == '__main__':
print(main())
``` | output | 1 | 69,205 | 3 | 138,411 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The Smart Beaver from ABBYY plans a space travel on an ultramodern spaceship. During the voyage he plans to visit n planets. For planet i ai is the maximum number of suitcases that an alien tourist is allowed to bring to the planet, and bi is the number of citizens on the planet.
The Smart Beaver is going to bring some presents from ABBYY to the planets he will be visiting. The presents are packed in suitcases, x presents in each. The Beaver will take to the ship exactly a1 + ... + an suitcases.
As the Beaver lands on the i-th planet, he takes ai suitcases and goes out. On the first day on the planet the Beaver takes a walk and gets to know the citizens. On the second and all subsequent days the Beaver gives presents to the citizens β each of the bi citizens gets one present per day. The Beaver leaves the planet in the evening of the day when the number of presents left is strictly less than the number of citizens (i.e. as soon as he won't be able to give away the proper number of presents the next day). He leaves the remaining presents at the hotel.
The Beaver is going to spend exactly c days traveling. The time spent on flights between the planets is considered to be zero. In how many ways can one choose the positive integer x so that the planned voyage will take exactly c days?
Input
The first input line contains space-separated integers n and c β the number of planets that the Beaver is going to visit and the number of days he is going to spend traveling, correspondingly.
The next n lines contain pairs of space-separated integers ai, bi (1 β€ i β€ n) β the number of suitcases he can bring to the i-th planet and the number of citizens of the i-th planet, correspondingly.
The input limitations for getting 30 points are:
* 1 β€ n β€ 100
* 1 β€ ai β€ 100
* 1 β€ bi β€ 100
* 1 β€ c β€ 100
The input limitations for getting 100 points are:
* 1 β€ n β€ 104
* 0 β€ ai β€ 109
* 1 β€ bi β€ 109
* 1 β€ c β€ 109
Due to possible overflow, it is recommended to use the 64-bit arithmetic. In some solutions even the 64-bit arithmetic can overflow. So be careful in calculations!
Output
Print a single number k β the number of ways to choose x so as to travel for exactly c days. If there are infinitely many possible values of x, print -1.
Please do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use cin, cout streams or the %I64d specifier.
Examples
Input
2 5
1 5
2 4
Output
1
Note
In the first example there is only one suitable value x = 5. Then the Beaver takes 1 suitcase with 5 presents to the first planet. Here he spends 2 days: he hangs around on the first day, and he gives away five presents on the second day. He takes 2 suitcases with 10 presents to the second planet. Here he spends 3 days β he gives away 4 presents on the second and the third days and leaves the remaining 2 presents at the hotel. In total, the Beaver spends 5 days traveling.
For x = 4 or less the Beaver won't have enough presents for the second day on the first planet, so the voyage will end too soon. For x = 6 and more the Beaver will spend at least one more day on the second planet, and the voyage will take too long. | instruction | 0 | 69,206 | 3 | 138,412 |
Tags: binary search
Correct Solution:
```
def f(x, t):
y = x
while sum((y * a) // b for a, b in t) < c: y += 1000000
while y - x > 1:
z = (x + y) // 2
d = sum((z * a) // b for a, b in t)
if d < c: x = z
else: y = z
return y
n, c = map(int, input().split())
c -= n
t = [tuple(map(int, input().split())) for i in range(n)]
x = sum(a / b for a, b in t)
if x:
x = f(int(c / x), t)
print((int(x > 0) + min((b - (x * a) % b - 1) // a for a, b in t if a > 0)) if sum((x * a) // b for a, b in t) == c else 0)
else: print(0 if c else -1)
``` | output | 1 | 69,206 | 3 | 138,413 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The Smart Beaver from ABBYY plans a space travel on an ultramodern spaceship. During the voyage he plans to visit n planets. For planet i ai is the maximum number of suitcases that an alien tourist is allowed to bring to the planet, and bi is the number of citizens on the planet.
The Smart Beaver is going to bring some presents from ABBYY to the planets he will be visiting. The presents are packed in suitcases, x presents in each. The Beaver will take to the ship exactly a1 + ... + an suitcases.
As the Beaver lands on the i-th planet, he takes ai suitcases and goes out. On the first day on the planet the Beaver takes a walk and gets to know the citizens. On the second and all subsequent days the Beaver gives presents to the citizens β each of the bi citizens gets one present per day. The Beaver leaves the planet in the evening of the day when the number of presents left is strictly less than the number of citizens (i.e. as soon as he won't be able to give away the proper number of presents the next day). He leaves the remaining presents at the hotel.
The Beaver is going to spend exactly c days traveling. The time spent on flights between the planets is considered to be zero. In how many ways can one choose the positive integer x so that the planned voyage will take exactly c days?
Input
The first input line contains space-separated integers n and c β the number of planets that the Beaver is going to visit and the number of days he is going to spend traveling, correspondingly.
The next n lines contain pairs of space-separated integers ai, bi (1 β€ i β€ n) β the number of suitcases he can bring to the i-th planet and the number of citizens of the i-th planet, correspondingly.
The input limitations for getting 30 points are:
* 1 β€ n β€ 100
* 1 β€ ai β€ 100
* 1 β€ bi β€ 100
* 1 β€ c β€ 100
The input limitations for getting 100 points are:
* 1 β€ n β€ 104
* 0 β€ ai β€ 109
* 1 β€ bi β€ 109
* 1 β€ c β€ 109
Due to possible overflow, it is recommended to use the 64-bit arithmetic. In some solutions even the 64-bit arithmetic can overflow. So be careful in calculations!
Output
Print a single number k β the number of ways to choose x so as to travel for exactly c days. If there are infinitely many possible values of x, print -1.
Please do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use cin, cout streams or the %I64d specifier.
Examples
Input
2 5
1 5
2 4
Output
1
Note
In the first example there is only one suitable value x = 5. Then the Beaver takes 1 suitcase with 5 presents to the first planet. Here he spends 2 days: he hangs around on the first day, and he gives away five presents on the second day. He takes 2 suitcases with 10 presents to the second planet. Here he spends 3 days β he gives away 4 presents on the second and the third days and leaves the remaining 2 presents at the hotel. In total, the Beaver spends 5 days traveling.
For x = 4 or less the Beaver won't have enough presents for the second day on the first planet, so the voyage will end too soon. For x = 6 and more the Beaver will spend at least one more day on the second planet, and the voyage will take too long. | instruction | 0 | 69,207 | 3 | 138,414 |
Tags: binary search
Correct Solution:
```
n, c = map(int, input().split())
a = []
b = []
for i in range(n):
aa, bb = map(int, input().split())
a.append(aa)
b.append(bb)
def all_zero():
for aa in a:
if aa > 0: return False
return True
def days(x):
c = 0
for aa, bb in zip(a, b):
c += 1 + aa*x//bb
return c
def run():
if n > c: return 0
if all_zero(): return -1 if n == c else 0
lo = 1
hi = int(2e18)
while lo < hi:
mid = (lo + hi) // 2
if days(mid) < c: lo = mid+1
else: hi = mid
if days(lo) != c: return 0
ans0 = lo
lo = 1
hi = int(2e18)
while lo < hi:
mid = (lo + hi + 1) // 2
if days(mid) > c: hi = mid-1
else: lo = mid
if days(lo) != c: return 0
return lo - ans0 + 1
print(run())
``` | output | 1 | 69,207 | 3 | 138,415 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The Smart Beaver from ABBYY plans a space travel on an ultramodern spaceship. During the voyage he plans to visit n planets. For planet i ai is the maximum number of suitcases that an alien tourist is allowed to bring to the planet, and bi is the number of citizens on the planet.
The Smart Beaver is going to bring some presents from ABBYY to the planets he will be visiting. The presents are packed in suitcases, x presents in each. The Beaver will take to the ship exactly a1 + ... + an suitcases.
As the Beaver lands on the i-th planet, he takes ai suitcases and goes out. On the first day on the planet the Beaver takes a walk and gets to know the citizens. On the second and all subsequent days the Beaver gives presents to the citizens β each of the bi citizens gets one present per day. The Beaver leaves the planet in the evening of the day when the number of presents left is strictly less than the number of citizens (i.e. as soon as he won't be able to give away the proper number of presents the next day). He leaves the remaining presents at the hotel.
The Beaver is going to spend exactly c days traveling. The time spent on flights between the planets is considered to be zero. In how many ways can one choose the positive integer x so that the planned voyage will take exactly c days?
Input
The first input line contains space-separated integers n and c β the number of planets that the Beaver is going to visit and the number of days he is going to spend traveling, correspondingly.
The next n lines contain pairs of space-separated integers ai, bi (1 β€ i β€ n) β the number of suitcases he can bring to the i-th planet and the number of citizens of the i-th planet, correspondingly.
The input limitations for getting 30 points are:
* 1 β€ n β€ 100
* 1 β€ ai β€ 100
* 1 β€ bi β€ 100
* 1 β€ c β€ 100
The input limitations for getting 100 points are:
* 1 β€ n β€ 104
* 0 β€ ai β€ 109
* 1 β€ bi β€ 109
* 1 β€ c β€ 109
Due to possible overflow, it is recommended to use the 64-bit arithmetic. In some solutions even the 64-bit arithmetic can overflow. So be careful in calculations!
Output
Print a single number k β the number of ways to choose x so as to travel for exactly c days. If there are infinitely many possible values of x, print -1.
Please do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use cin, cout streams or the %I64d specifier.
Examples
Input
2 5
1 5
2 4
Output
1
Note
In the first example there is only one suitable value x = 5. Then the Beaver takes 1 suitcase with 5 presents to the first planet. Here he spends 2 days: he hangs around on the first day, and he gives away five presents on the second day. He takes 2 suitcases with 10 presents to the second planet. Here he spends 3 days β he gives away 4 presents on the second and the third days and leaves the remaining 2 presents at the hotel. In total, the Beaver spends 5 days traveling.
For x = 4 or less the Beaver won't have enough presents for the second day on the first planet, so the voyage will end too soon. For x = 6 and more the Beaver will spend at least one more day on the second planet, and the voyage will take too long. | instruction | 0 | 69,208 | 3 | 138,416 |
Tags: binary search
Correct Solution:
```
I=lambda:map(int,input().split())
n,c=I()
a,b=[],[]
for _ in range(n):x,y=I();a.append(x);b.append(y)
if max(a)==0:print([0,-1][n==c]);exit()
def f(x):
r=0
for i in range(n):
r+=1+a[i]*x//b[i]
if r>c:break
return r
l=-1
r=10**18
while l<r-1:
m=(l+r)//2
if f(m)<c:l=m
else:r=m
L=r
l=-1
r=10**18
while l<r-1:
m=(l+r)//2
if f(m)<=c:l=m
else:r=m
while f(r)>c:r-=1
if r<1:r=1
if L<1:L=1
if f(r)!=c:print(0)
else:print(r-L+1)
``` | output | 1 | 69,208 | 3 | 138,417 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The Smart Beaver from ABBYY plans a space travel on an ultramodern spaceship. During the voyage he plans to visit n planets. For planet i ai is the maximum number of suitcases that an alien tourist is allowed to bring to the planet, and bi is the number of citizens on the planet.
The Smart Beaver is going to bring some presents from ABBYY to the planets he will be visiting. The presents are packed in suitcases, x presents in each. The Beaver will take to the ship exactly a1 + ... + an suitcases.
As the Beaver lands on the i-th planet, he takes ai suitcases and goes out. On the first day on the planet the Beaver takes a walk and gets to know the citizens. On the second and all subsequent days the Beaver gives presents to the citizens β each of the bi citizens gets one present per day. The Beaver leaves the planet in the evening of the day when the number of presents left is strictly less than the number of citizens (i.e. as soon as he won't be able to give away the proper number of presents the next day). He leaves the remaining presents at the hotel.
The Beaver is going to spend exactly c days traveling. The time spent on flights between the planets is considered to be zero. In how many ways can one choose the positive integer x so that the planned voyage will take exactly c days?
Input
The first input line contains space-separated integers n and c β the number of planets that the Beaver is going to visit and the number of days he is going to spend traveling, correspondingly.
The next n lines contain pairs of space-separated integers ai, bi (1 β€ i β€ n) β the number of suitcases he can bring to the i-th planet and the number of citizens of the i-th planet, correspondingly.
The input limitations for getting 30 points are:
* 1 β€ n β€ 100
* 1 β€ ai β€ 100
* 1 β€ bi β€ 100
* 1 β€ c β€ 100
The input limitations for getting 100 points are:
* 1 β€ n β€ 104
* 0 β€ ai β€ 109
* 1 β€ bi β€ 109
* 1 β€ c β€ 109
Due to possible overflow, it is recommended to use the 64-bit arithmetic. In some solutions even the 64-bit arithmetic can overflow. So be careful in calculations!
Output
Print a single number k β the number of ways to choose x so as to travel for exactly c days. If there are infinitely many possible values of x, print -1.
Please do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use cin, cout streams or the %I64d specifier.
Examples
Input
2 5
1 5
2 4
Output
1
Note
In the first example there is only one suitable value x = 5. Then the Beaver takes 1 suitcase with 5 presents to the first planet. Here he spends 2 days: he hangs around on the first day, and he gives away five presents on the second day. He takes 2 suitcases with 10 presents to the second planet. Here he spends 3 days β he gives away 4 presents on the second and the third days and leaves the remaining 2 presents at the hotel. In total, the Beaver spends 5 days traveling.
For x = 4 or less the Beaver won't have enough presents for the second day on the first planet, so the voyage will end too soon. For x = 6 and more the Beaver will spend at least one more day on the second planet, and the voyage will take too long. | instruction | 0 | 69,209 | 3 | 138,418 |
Tags: binary search
Correct Solution:
```
input=__import__('sys').stdin.readline
def check(x):
tmp=0
for i in range(n):
tmp+=(1 + (lis[i][0]*x)//lis[i][1])
return tmp
def zer(lis):
for i in lis:
if i[0]>0:
return False
return True
n,c = map(int,input().split())
lis=[]
c1=0
for _ in range(n):
a,b = map(int,input().split())
lis.append([a,b])
if n>c:
print(0)
exit()
if zer(lis):
if n==c:
print(-1)
else:
print(0)
exit()
#max
ans=0
l=0
r=100000000000000000000
while l<=r:
mid = l + (r-l)//2
if check(mid)>c:
r=mid-1
else:
l=mid+1
if check(l)==c:
ans=l
else:
ans=r
l=0
r=100000000000000000000
while l<=r:
mid = l +(r-l)//2
if check(mid)>=c:
r=mid-1
else:
l=mid+1
#print(ans,l,r)
if r!=-1:
print(max(0,ans-r))
else:
print(max(0,ans-l))
``` | output | 1 | 69,209 | 3 | 138,419 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The Smart Beaver from ABBYY plans a space travel on an ultramodern spaceship. During the voyage he plans to visit n planets. For planet i ai is the maximum number of suitcases that an alien tourist is allowed to bring to the planet, and bi is the number of citizens on the planet.
The Smart Beaver is going to bring some presents from ABBYY to the planets he will be visiting. The presents are packed in suitcases, x presents in each. The Beaver will take to the ship exactly a1 + ... + an suitcases.
As the Beaver lands on the i-th planet, he takes ai suitcases and goes out. On the first day on the planet the Beaver takes a walk and gets to know the citizens. On the second and all subsequent days the Beaver gives presents to the citizens β each of the bi citizens gets one present per day. The Beaver leaves the planet in the evening of the day when the number of presents left is strictly less than the number of citizens (i.e. as soon as he won't be able to give away the proper number of presents the next day). He leaves the remaining presents at the hotel.
The Beaver is going to spend exactly c days traveling. The time spent on flights between the planets is considered to be zero. In how many ways can one choose the positive integer x so that the planned voyage will take exactly c days?
Input
The first input line contains space-separated integers n and c β the number of planets that the Beaver is going to visit and the number of days he is going to spend traveling, correspondingly.
The next n lines contain pairs of space-separated integers ai, bi (1 β€ i β€ n) β the number of suitcases he can bring to the i-th planet and the number of citizens of the i-th planet, correspondingly.
The input limitations for getting 30 points are:
* 1 β€ n β€ 100
* 1 β€ ai β€ 100
* 1 β€ bi β€ 100
* 1 β€ c β€ 100
The input limitations for getting 100 points are:
* 1 β€ n β€ 104
* 0 β€ ai β€ 109
* 1 β€ bi β€ 109
* 1 β€ c β€ 109
Due to possible overflow, it is recommended to use the 64-bit arithmetic. In some solutions even the 64-bit arithmetic can overflow. So be careful in calculations!
Output
Print a single number k β the number of ways to choose x so as to travel for exactly c days. If there are infinitely many possible values of x, print -1.
Please do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use cin, cout streams or the %I64d specifier.
Examples
Input
2 5
1 5
2 4
Output
1
Note
In the first example there is only one suitable value x = 5. Then the Beaver takes 1 suitcase with 5 presents to the first planet. Here he spends 2 days: he hangs around on the first day, and he gives away five presents on the second day. He takes 2 suitcases with 10 presents to the second planet. Here he spends 3 days β he gives away 4 presents on the second and the third days and leaves the remaining 2 presents at the hotel. In total, the Beaver spends 5 days traveling.
For x = 4 or less the Beaver won't have enough presents for the second day on the first planet, so the voyage will end too soon. For x = 6 and more the Beaver will spend at least one more day on the second planet, and the voyage will take too long.
Submitted Solution:
```
I=lambda:map(int,input().split())
n,c=I()
a,b=[],[]
for _ in range(n):x,y=I();a.append(x);b.append(y)
f=lambda x:sum(1+a[i]*x//b[i]for i in range(n))
l=-1
r=10**18
while l<r-1:
m=(l+r)//2
if f(m)<c:l=m
else:r=m
L=r
l=-1
r=10**18
while l<r-1:
m=(l+r)//2
if f(m)<=c:l=m
else:r=m
while f(r)>c:r-=1
if r<1:r=1
if L<1:L=1
if max(a)==0:print([0,-1][n==c])
if f(r)!=c:print(0)
else:print(r-L+1)
``` | instruction | 0 | 69,210 | 3 | 138,420 |
No | output | 1 | 69,210 | 3 | 138,421 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The Smart Beaver from ABBYY plans a space travel on an ultramodern spaceship. During the voyage he plans to visit n planets. For planet i ai is the maximum number of suitcases that an alien tourist is allowed to bring to the planet, and bi is the number of citizens on the planet.
The Smart Beaver is going to bring some presents from ABBYY to the planets he will be visiting. The presents are packed in suitcases, x presents in each. The Beaver will take to the ship exactly a1 + ... + an suitcases.
As the Beaver lands on the i-th planet, he takes ai suitcases and goes out. On the first day on the planet the Beaver takes a walk and gets to know the citizens. On the second and all subsequent days the Beaver gives presents to the citizens β each of the bi citizens gets one present per day. The Beaver leaves the planet in the evening of the day when the number of presents left is strictly less than the number of citizens (i.e. as soon as he won't be able to give away the proper number of presents the next day). He leaves the remaining presents at the hotel.
The Beaver is going to spend exactly c days traveling. The time spent on flights between the planets is considered to be zero. In how many ways can one choose the positive integer x so that the planned voyage will take exactly c days?
Input
The first input line contains space-separated integers n and c β the number of planets that the Beaver is going to visit and the number of days he is going to spend traveling, correspondingly.
The next n lines contain pairs of space-separated integers ai, bi (1 β€ i β€ n) β the number of suitcases he can bring to the i-th planet and the number of citizens of the i-th planet, correspondingly.
The input limitations for getting 30 points are:
* 1 β€ n β€ 100
* 1 β€ ai β€ 100
* 1 β€ bi β€ 100
* 1 β€ c β€ 100
The input limitations for getting 100 points are:
* 1 β€ n β€ 104
* 0 β€ ai β€ 109
* 1 β€ bi β€ 109
* 1 β€ c β€ 109
Due to possible overflow, it is recommended to use the 64-bit arithmetic. In some solutions even the 64-bit arithmetic can overflow. So be careful in calculations!
Output
Print a single number k β the number of ways to choose x so as to travel for exactly c days. If there are infinitely many possible values of x, print -1.
Please do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use cin, cout streams or the %I64d specifier.
Examples
Input
2 5
1 5
2 4
Output
1
Note
In the first example there is only one suitable value x = 5. Then the Beaver takes 1 suitcase with 5 presents to the first planet. Here he spends 2 days: he hangs around on the first day, and he gives away five presents on the second day. He takes 2 suitcases with 10 presents to the second planet. Here he spends 3 days β he gives away 4 presents on the second and the third days and leaves the remaining 2 presents at the hotel. In total, the Beaver spends 5 days traveling.
For x = 4 or less the Beaver won't have enough presents for the second day on the first planet, so the voyage will end too soon. For x = 6 and more the Beaver will spend at least one more day on the second planet, and the voyage will take too long.
Submitted Solution:
```
n,c=map(int,input().split())
a=[0 for i in range(10001)]
b=a[:]
for i in range(n):
a[i],b[i]=map(int,input().split())
def chi():
if sum(a)==0:
if c==n:
print(-1)
else:
print(0)
import sys
sys.exit(0)
def ch(day):
ans=0
for i in range(n):
ans+=(1+a[i]*day//b[i])
return ans
def fm():
l=0
r=2**50
while r-l>1:
mi=(l+r)>>1
if ch(mi)>c:
r=mi-1
else:l=mi
while ch(r)>c:r-=1
return r
def fl():
l = 0
r = 2 ** 50
while r - l > 1:
mi = (l + r) >> 1
if ch(mi) > c:
r = mi - 1
else:
l = mi
while ch(l) < c: l += 1
return l
chi()
print(fm()-fl()+1)
``` | instruction | 0 | 69,211 | 3 | 138,422 |
No | output | 1 | 69,211 | 3 | 138,423 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The Smart Beaver from ABBYY plans a space travel on an ultramodern spaceship. During the voyage he plans to visit n planets. For planet i ai is the maximum number of suitcases that an alien tourist is allowed to bring to the planet, and bi is the number of citizens on the planet.
The Smart Beaver is going to bring some presents from ABBYY to the planets he will be visiting. The presents are packed in suitcases, x presents in each. The Beaver will take to the ship exactly a1 + ... + an suitcases.
As the Beaver lands on the i-th planet, he takes ai suitcases and goes out. On the first day on the planet the Beaver takes a walk and gets to know the citizens. On the second and all subsequent days the Beaver gives presents to the citizens β each of the bi citizens gets one present per day. The Beaver leaves the planet in the evening of the day when the number of presents left is strictly less than the number of citizens (i.e. as soon as he won't be able to give away the proper number of presents the next day). He leaves the remaining presents at the hotel.
The Beaver is going to spend exactly c days traveling. The time spent on flights between the planets is considered to be zero. In how many ways can one choose the positive integer x so that the planned voyage will take exactly c days?
Input
The first input line contains space-separated integers n and c β the number of planets that the Beaver is going to visit and the number of days he is going to spend traveling, correspondingly.
The next n lines contain pairs of space-separated integers ai, bi (1 β€ i β€ n) β the number of suitcases he can bring to the i-th planet and the number of citizens of the i-th planet, correspondingly.
The input limitations for getting 30 points are:
* 1 β€ n β€ 100
* 1 β€ ai β€ 100
* 1 β€ bi β€ 100
* 1 β€ c β€ 100
The input limitations for getting 100 points are:
* 1 β€ n β€ 104
* 0 β€ ai β€ 109
* 1 β€ bi β€ 109
* 1 β€ c β€ 109
Due to possible overflow, it is recommended to use the 64-bit arithmetic. In some solutions even the 64-bit arithmetic can overflow. So be careful in calculations!
Output
Print a single number k β the number of ways to choose x so as to travel for exactly c days. If there are infinitely many possible values of x, print -1.
Please do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use cin, cout streams or the %I64d specifier.
Examples
Input
2 5
1 5
2 4
Output
1
Note
In the first example there is only one suitable value x = 5. Then the Beaver takes 1 suitcase with 5 presents to the first planet. Here he spends 2 days: he hangs around on the first day, and he gives away five presents on the second day. He takes 2 suitcases with 10 presents to the second planet. Here he spends 3 days β he gives away 4 presents on the second and the third days and leaves the remaining 2 presents at the hotel. In total, the Beaver spends 5 days traveling.
For x = 4 or less the Beaver won't have enough presents for the second day on the first planet, so the voyage will end too soon. For x = 6 and more the Beaver will spend at least one more day on the second planet, and the voyage will take too long.
Submitted Solution:
```
n,c=map(int,input().split())
a=[0 for i in range(10001)]
b=a[:]
for i in range(n):
a[i],b[i]=map(int,input().split())
def chi():
if c<n:
print(0)
import sys
sys.exit(0)
if sum(a)==0:
if c==n:
print(-1)
else:
print(0)
import sys
sys.exit(0)
def ch(day):
ans=0
for i in range(n):
ans+=(1+a[i]*day//b[i])
return ans
def fm():
l=0
r=2**50
while r-l>1:
mi=(l+r)>>1
if ch(mi)>c:
r=mi
else:l=mi
r+=5
while ch(r)>c:r-=1
return r
def fl():
l = 0
r = 2 ** 50
while r - l > 1:
mi = (l + r) >> 1
if ch(mi) < c:
l = mi
else:
r = mi
l=max(0,l-5)
while ch(l) < c: l += 1
return l
chi()
print(fm()-fl()+1)
``` | instruction | 0 | 69,212 | 3 | 138,424 |
No | output | 1 | 69,212 | 3 | 138,425 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The Smart Beaver from ABBYY plans a space travel on an ultramodern spaceship. During the voyage he plans to visit n planets. For planet i ai is the maximum number of suitcases that an alien tourist is allowed to bring to the planet, and bi is the number of citizens on the planet.
The Smart Beaver is going to bring some presents from ABBYY to the planets he will be visiting. The presents are packed in suitcases, x presents in each. The Beaver will take to the ship exactly a1 + ... + an suitcases.
As the Beaver lands on the i-th planet, he takes ai suitcases and goes out. On the first day on the planet the Beaver takes a walk and gets to know the citizens. On the second and all subsequent days the Beaver gives presents to the citizens β each of the bi citizens gets one present per day. The Beaver leaves the planet in the evening of the day when the number of presents left is strictly less than the number of citizens (i.e. as soon as he won't be able to give away the proper number of presents the next day). He leaves the remaining presents at the hotel.
The Beaver is going to spend exactly c days traveling. The time spent on flights between the planets is considered to be zero. In how many ways can one choose the positive integer x so that the planned voyage will take exactly c days?
Input
The first input line contains space-separated integers n and c β the number of planets that the Beaver is going to visit and the number of days he is going to spend traveling, correspondingly.
The next n lines contain pairs of space-separated integers ai, bi (1 β€ i β€ n) β the number of suitcases he can bring to the i-th planet and the number of citizens of the i-th planet, correspondingly.
The input limitations for getting 30 points are:
* 1 β€ n β€ 100
* 1 β€ ai β€ 100
* 1 β€ bi β€ 100
* 1 β€ c β€ 100
The input limitations for getting 100 points are:
* 1 β€ n β€ 104
* 0 β€ ai β€ 109
* 1 β€ bi β€ 109
* 1 β€ c β€ 109
Due to possible overflow, it is recommended to use the 64-bit arithmetic. In some solutions even the 64-bit arithmetic can overflow. So be careful in calculations!
Output
Print a single number k β the number of ways to choose x so as to travel for exactly c days. If there are infinitely many possible values of x, print -1.
Please do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use cin, cout streams or the %I64d specifier.
Examples
Input
2 5
1 5
2 4
Output
1
Note
In the first example there is only one suitable value x = 5. Then the Beaver takes 1 suitcase with 5 presents to the first planet. Here he spends 2 days: he hangs around on the first day, and he gives away five presents on the second day. He takes 2 suitcases with 10 presents to the second planet. Here he spends 3 days β he gives away 4 presents on the second and the third days and leaves the remaining 2 presents at the hotel. In total, the Beaver spends 5 days traveling.
For x = 4 or less the Beaver won't have enough presents for the second day on the first planet, so the voyage will end too soon. For x = 6 and more the Beaver will spend at least one more day on the second planet, and the voyage will take too long.
Submitted Solution:
```
I=lambda:map(int,input().split())
n,c=I()
a,b=[],[]
for _ in range(n):x,y=I();a.append(x);b.append(y)
f=lambda x:sum(1+a[i]*x//b[i]for i in range(n))
l=-1
r=10**18
while l<r-1:
m=(l+r)//2
if f(m)<c:l=m
else:r=m
L=r
l=-1
r=10**18
while l<r-1:
m=(l+r)//2
if f(m)<=c:l=m
else:r=m
while f(r)>c:r-=1
if r<1:r=1
if L<1:L=1
if f(r)!=c:print(0)
else:print(r-L+1)
``` | instruction | 0 | 69,213 | 3 | 138,426 |
No | output | 1 | 69,213 | 3 | 138,427 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There will be a launch of a new, powerful and unusual collider very soon, which located along a straight line. n particles will be launched inside it. All of them are located in a straight line and there can not be two or more particles located in the same point. The coordinates of the particles coincide with the distance in meters from the center of the collider, xi is the coordinate of the i-th particle and its position in the collider at the same time. All coordinates of particle positions are even integers.
You know the direction of each particle movement β it will move to the right or to the left after the collider's launch start. All particles begin to move simultaneously at the time of the collider's launch start. Each particle will move straight to the left or straight to the right with the constant speed of 1 meter per microsecond. The collider is big enough so particles can not leave it in the foreseeable time.
Write the program which finds the moment of the first collision of any two particles of the collider. In other words, find the number of microseconds before the first moment when any two particles are at the same point.
Input
The first line contains the positive integer n (1 β€ n β€ 200 000) β the number of particles.
The second line contains n symbols "L" and "R". If the i-th symbol equals "L", then the i-th particle will move to the left, otherwise the i-th symbol equals "R" and the i-th particle will move to the right.
The third line contains the sequence of pairwise distinct even integers x1, x2, ..., xn (0 β€ xi β€ 109) β the coordinates of particles in the order from the left to the right. It is guaranteed that the coordinates of particles are given in the increasing order.
Output
In the first line print the only integer β the first moment (in microseconds) when two particles are at the same point and there will be an explosion.
Print the only integer -1, if the collision of particles doesn't happen.
Examples
Input
4
RLRL
2 4 6 10
Output
1
Input
3
LLR
40 50 60
Output
-1
Note
In the first sample case the first explosion will happen in 1 microsecond because the particles number 1 and 2 will simultaneously be at the same point with the coordinate 3.
In the second sample case there will be no explosion because there are no particles which will simultaneously be at the same point. | instruction | 0 | 69,443 | 3 | 138,886 |
Tags: implementation
Correct Solution:
```
n = int(input())
s = input()
a = list(map(int,input().split()))
if "L" not in s:
print(-1)
exit(0)
if "R" not in s:
print(-1)
exit(0)
ans = []
f = 0
for i in range(n):
if s[i] == "R":
right = a[i]
f = 1
elif f and s[i] == "L":
left = a[i]
f = 0
ans.append([right,left])
m= 10**10
if ans:
for i in ans:
val = abs(i[0]-i[1])
if val<m:
m = val
print(m//2)
else:
print(-1)
``` | output | 1 | 69,443 | 3 | 138,887 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There will be a launch of a new, powerful and unusual collider very soon, which located along a straight line. n particles will be launched inside it. All of them are located in a straight line and there can not be two or more particles located in the same point. The coordinates of the particles coincide with the distance in meters from the center of the collider, xi is the coordinate of the i-th particle and its position in the collider at the same time. All coordinates of particle positions are even integers.
You know the direction of each particle movement β it will move to the right or to the left after the collider's launch start. All particles begin to move simultaneously at the time of the collider's launch start. Each particle will move straight to the left or straight to the right with the constant speed of 1 meter per microsecond. The collider is big enough so particles can not leave it in the foreseeable time.
Write the program which finds the moment of the first collision of any two particles of the collider. In other words, find the number of microseconds before the first moment when any two particles are at the same point.
Input
The first line contains the positive integer n (1 β€ n β€ 200 000) β the number of particles.
The second line contains n symbols "L" and "R". If the i-th symbol equals "L", then the i-th particle will move to the left, otherwise the i-th symbol equals "R" and the i-th particle will move to the right.
The third line contains the sequence of pairwise distinct even integers x1, x2, ..., xn (0 β€ xi β€ 109) β the coordinates of particles in the order from the left to the right. It is guaranteed that the coordinates of particles are given in the increasing order.
Output
In the first line print the only integer β the first moment (in microseconds) when two particles are at the same point and there will be an explosion.
Print the only integer -1, if the collision of particles doesn't happen.
Examples
Input
4
RLRL
2 4 6 10
Output
1
Input
3
LLR
40 50 60
Output
-1
Note
In the first sample case the first explosion will happen in 1 microsecond because the particles number 1 and 2 will simultaneously be at the same point with the coordinate 3.
In the second sample case there will be no explosion because there are no particles which will simultaneously be at the same point. | instruction | 0 | 69,444 | 3 | 138,888 |
Tags: implementation
Correct Solution:
```
import sys
n = int(input())
d = input()
x = list(map(int, input().split()))
r = 0
l = 0
m = sys.maxsize
while True:
r = d.find('R', l)
if r == -1:
break
l = d.find('L', r + 1)
if l == -1:
break
r = l - 1
if m > (x[l] - x[r]) // 2:
m = (x[l] - x[r]) // 2
if m == sys.maxsize:
print(-1)
else:
print(m)
``` | output | 1 | 69,444 | 3 | 138,889 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There will be a launch of a new, powerful and unusual collider very soon, which located along a straight line. n particles will be launched inside it. All of them are located in a straight line and there can not be two or more particles located in the same point. The coordinates of the particles coincide with the distance in meters from the center of the collider, xi is the coordinate of the i-th particle and its position in the collider at the same time. All coordinates of particle positions are even integers.
You know the direction of each particle movement β it will move to the right or to the left after the collider's launch start. All particles begin to move simultaneously at the time of the collider's launch start. Each particle will move straight to the left or straight to the right with the constant speed of 1 meter per microsecond. The collider is big enough so particles can not leave it in the foreseeable time.
Write the program which finds the moment of the first collision of any two particles of the collider. In other words, find the number of microseconds before the first moment when any two particles are at the same point.
Input
The first line contains the positive integer n (1 β€ n β€ 200 000) β the number of particles.
The second line contains n symbols "L" and "R". If the i-th symbol equals "L", then the i-th particle will move to the left, otherwise the i-th symbol equals "R" and the i-th particle will move to the right.
The third line contains the sequence of pairwise distinct even integers x1, x2, ..., xn (0 β€ xi β€ 109) β the coordinates of particles in the order from the left to the right. It is guaranteed that the coordinates of particles are given in the increasing order.
Output
In the first line print the only integer β the first moment (in microseconds) when two particles are at the same point and there will be an explosion.
Print the only integer -1, if the collision of particles doesn't happen.
Examples
Input
4
RLRL
2 4 6 10
Output
1
Input
3
LLR
40 50 60
Output
-1
Note
In the first sample case the first explosion will happen in 1 microsecond because the particles number 1 and 2 will simultaneously be at the same point with the coordinate 3.
In the second sample case there will be no explosion because there are no particles which will simultaneously be at the same point. | instruction | 0 | 69,445 | 3 | 138,890 |
Tags: implementation
Correct Solution:
```
NONE = 10 ** 10
n = int(input())
direct = input()
pos = [int(x) for x in input().split()]
best = NONE
for i,x in enumerate(pos):
if i+1 == n:
break
if direct[i:i+2] != 'RL':
continue
best = min(best, pos[i+1] - x)
if best == NONE:
best = -1
else:
best = best // 2
print(best)
``` | output | 1 | 69,445 | 3 | 138,891 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There will be a launch of a new, powerful and unusual collider very soon, which located along a straight line. n particles will be launched inside it. All of them are located in a straight line and there can not be two or more particles located in the same point. The coordinates of the particles coincide with the distance in meters from the center of the collider, xi is the coordinate of the i-th particle and its position in the collider at the same time. All coordinates of particle positions are even integers.
You know the direction of each particle movement β it will move to the right or to the left after the collider's launch start. All particles begin to move simultaneously at the time of the collider's launch start. Each particle will move straight to the left or straight to the right with the constant speed of 1 meter per microsecond. The collider is big enough so particles can not leave it in the foreseeable time.
Write the program which finds the moment of the first collision of any two particles of the collider. In other words, find the number of microseconds before the first moment when any two particles are at the same point.
Input
The first line contains the positive integer n (1 β€ n β€ 200 000) β the number of particles.
The second line contains n symbols "L" and "R". If the i-th symbol equals "L", then the i-th particle will move to the left, otherwise the i-th symbol equals "R" and the i-th particle will move to the right.
The third line contains the sequence of pairwise distinct even integers x1, x2, ..., xn (0 β€ xi β€ 109) β the coordinates of particles in the order from the left to the right. It is guaranteed that the coordinates of particles are given in the increasing order.
Output
In the first line print the only integer β the first moment (in microseconds) when two particles are at the same point and there will be an explosion.
Print the only integer -1, if the collision of particles doesn't happen.
Examples
Input
4
RLRL
2 4 6 10
Output
1
Input
3
LLR
40 50 60
Output
-1
Note
In the first sample case the first explosion will happen in 1 microsecond because the particles number 1 and 2 will simultaneously be at the same point with the coordinate 3.
In the second sample case there will be no explosion because there are no particles which will simultaneously be at the same point. | instruction | 0 | 69,446 | 3 | 138,892 |
Tags: implementation
Correct Solution:
```
n = int(input())
direction = input()
x = list(map(int,input().split()))
ind = direction.find("RL")
if ind == -1:
print(ind)
exit()
minimum = (x[ind+1]-x[ind])//2
for i in range(n-1):
if direction[i]+direction[i+1]=='RL':
if minimum>(x[i+1]-x[i])//2:
minimum=(x[i+1]-x[i])//2
print(minimum)
``` | output | 1 | 69,446 | 3 | 138,893 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There will be a launch of a new, powerful and unusual collider very soon, which located along a straight line. n particles will be launched inside it. All of them are located in a straight line and there can not be two or more particles located in the same point. The coordinates of the particles coincide with the distance in meters from the center of the collider, xi is the coordinate of the i-th particle and its position in the collider at the same time. All coordinates of particle positions are even integers.
You know the direction of each particle movement β it will move to the right or to the left after the collider's launch start. All particles begin to move simultaneously at the time of the collider's launch start. Each particle will move straight to the left or straight to the right with the constant speed of 1 meter per microsecond. The collider is big enough so particles can not leave it in the foreseeable time.
Write the program which finds the moment of the first collision of any two particles of the collider. In other words, find the number of microseconds before the first moment when any two particles are at the same point.
Input
The first line contains the positive integer n (1 β€ n β€ 200 000) β the number of particles.
The second line contains n symbols "L" and "R". If the i-th symbol equals "L", then the i-th particle will move to the left, otherwise the i-th symbol equals "R" and the i-th particle will move to the right.
The third line contains the sequence of pairwise distinct even integers x1, x2, ..., xn (0 β€ xi β€ 109) β the coordinates of particles in the order from the left to the right. It is guaranteed that the coordinates of particles are given in the increasing order.
Output
In the first line print the only integer β the first moment (in microseconds) when two particles are at the same point and there will be an explosion.
Print the only integer -1, if the collision of particles doesn't happen.
Examples
Input
4
RLRL
2 4 6 10
Output
1
Input
3
LLR
40 50 60
Output
-1
Note
In the first sample case the first explosion will happen in 1 microsecond because the particles number 1 and 2 will simultaneously be at the same point with the coordinate 3.
In the second sample case there will be no explosion because there are no particles which will simultaneously be at the same point. | instruction | 0 | 69,447 | 3 | 138,894 |
Tags: implementation
Correct Solution:
```
n=int(input())
d=input()
l=list(map(int,input().split()))
m=0
r=10**9
for i in range(n-1):
if d[i]=='R' and d[i+1]=='L':
m=(l[i+1]-l[i])/2
if m<r:
r=m
if r==10**9:
print(-1)
else:
print(int(r))
``` | output | 1 | 69,447 | 3 | 138,895 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There will be a launch of a new, powerful and unusual collider very soon, which located along a straight line. n particles will be launched inside it. All of them are located in a straight line and there can not be two or more particles located in the same point. The coordinates of the particles coincide with the distance in meters from the center of the collider, xi is the coordinate of the i-th particle and its position in the collider at the same time. All coordinates of particle positions are even integers.
You know the direction of each particle movement β it will move to the right or to the left after the collider's launch start. All particles begin to move simultaneously at the time of the collider's launch start. Each particle will move straight to the left or straight to the right with the constant speed of 1 meter per microsecond. The collider is big enough so particles can not leave it in the foreseeable time.
Write the program which finds the moment of the first collision of any two particles of the collider. In other words, find the number of microseconds before the first moment when any two particles are at the same point.
Input
The first line contains the positive integer n (1 β€ n β€ 200 000) β the number of particles.
The second line contains n symbols "L" and "R". If the i-th symbol equals "L", then the i-th particle will move to the left, otherwise the i-th symbol equals "R" and the i-th particle will move to the right.
The third line contains the sequence of pairwise distinct even integers x1, x2, ..., xn (0 β€ xi β€ 109) β the coordinates of particles in the order from the left to the right. It is guaranteed that the coordinates of particles are given in the increasing order.
Output
In the first line print the only integer β the first moment (in microseconds) when two particles are at the same point and there will be an explosion.
Print the only integer -1, if the collision of particles doesn't happen.
Examples
Input
4
RLRL
2 4 6 10
Output
1
Input
3
LLR
40 50 60
Output
-1
Note
In the first sample case the first explosion will happen in 1 microsecond because the particles number 1 and 2 will simultaneously be at the same point with the coordinate 3.
In the second sample case there will be no explosion because there are no particles which will simultaneously be at the same point. | instruction | 0 | 69,448 | 3 | 138,896 |
Tags: implementation
Correct Solution:
```
def inp():
return(int(input()))
def inlt():
return(list(map(int,input().split())))
def insr():
s = input()
return(list(s[:len(s) - 1]))
def invr():
return(map(int,input().split()))
def loadinput():
n = int(input())
di = list(str(input()))
vals =list(map(int,input().split()))
return di,vals
def checkstews(di, vals):
ans = -1
for i in range(len(di)-1):
if di[i] == 'R' and di[i+1] == 'L':
if vals[i] < vals[i+1]:
if (int((vals[i+1] - vals[i])/2) < ans) or ans == -1:
ans = int((vals[i+1] - vals[i])/2)
else:
continue
return ans
if __name__ == '__main__':
di, vals = loadinput()
ans = checkstews(di, vals)
print(ans)
``` | output | 1 | 69,448 | 3 | 138,897 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There will be a launch of a new, powerful and unusual collider very soon, which located along a straight line. n particles will be launched inside it. All of them are located in a straight line and there can not be two or more particles located in the same point. The coordinates of the particles coincide with the distance in meters from the center of the collider, xi is the coordinate of the i-th particle and its position in the collider at the same time. All coordinates of particle positions are even integers.
You know the direction of each particle movement β it will move to the right or to the left after the collider's launch start. All particles begin to move simultaneously at the time of the collider's launch start. Each particle will move straight to the left or straight to the right with the constant speed of 1 meter per microsecond. The collider is big enough so particles can not leave it in the foreseeable time.
Write the program which finds the moment of the first collision of any two particles of the collider. In other words, find the number of microseconds before the first moment when any two particles are at the same point.
Input
The first line contains the positive integer n (1 β€ n β€ 200 000) β the number of particles.
The second line contains n symbols "L" and "R". If the i-th symbol equals "L", then the i-th particle will move to the left, otherwise the i-th symbol equals "R" and the i-th particle will move to the right.
The third line contains the sequence of pairwise distinct even integers x1, x2, ..., xn (0 β€ xi β€ 109) β the coordinates of particles in the order from the left to the right. It is guaranteed that the coordinates of particles are given in the increasing order.
Output
In the first line print the only integer β the first moment (in microseconds) when two particles are at the same point and there will be an explosion.
Print the only integer -1, if the collision of particles doesn't happen.
Examples
Input
4
RLRL
2 4 6 10
Output
1
Input
3
LLR
40 50 60
Output
-1
Note
In the first sample case the first explosion will happen in 1 microsecond because the particles number 1 and 2 will simultaneously be at the same point with the coordinate 3.
In the second sample case there will be no explosion because there are no particles which will simultaneously be at the same point. | instruction | 0 | 69,449 | 3 | 138,898 |
Tags: implementation
Correct Solution:
```
n=int(input())
s=input()
a=list(map(int,input().split()))
d=[]
for i in range(n-1):
if s[i]=='R' and s[i+1]=='L':
t=a[i+1]-a[i]
t=t//2
d.append(t)
if d==[]:
print(-1)
else:
print(min(d))
``` | output | 1 | 69,449 | 3 | 138,899 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There will be a launch of a new, powerful and unusual collider very soon, which located along a straight line. n particles will be launched inside it. All of them are located in a straight line and there can not be two or more particles located in the same point. The coordinates of the particles coincide with the distance in meters from the center of the collider, xi is the coordinate of the i-th particle and its position in the collider at the same time. All coordinates of particle positions are even integers.
You know the direction of each particle movement β it will move to the right or to the left after the collider's launch start. All particles begin to move simultaneously at the time of the collider's launch start. Each particle will move straight to the left or straight to the right with the constant speed of 1 meter per microsecond. The collider is big enough so particles can not leave it in the foreseeable time.
Write the program which finds the moment of the first collision of any two particles of the collider. In other words, find the number of microseconds before the first moment when any two particles are at the same point.
Input
The first line contains the positive integer n (1 β€ n β€ 200 000) β the number of particles.
The second line contains n symbols "L" and "R". If the i-th symbol equals "L", then the i-th particle will move to the left, otherwise the i-th symbol equals "R" and the i-th particle will move to the right.
The third line contains the sequence of pairwise distinct even integers x1, x2, ..., xn (0 β€ xi β€ 109) β the coordinates of particles in the order from the left to the right. It is guaranteed that the coordinates of particles are given in the increasing order.
Output
In the first line print the only integer β the first moment (in microseconds) when two particles are at the same point and there will be an explosion.
Print the only integer -1, if the collision of particles doesn't happen.
Examples
Input
4
RLRL
2 4 6 10
Output
1
Input
3
LLR
40 50 60
Output
-1
Note
In the first sample case the first explosion will happen in 1 microsecond because the particles number 1 and 2 will simultaneously be at the same point with the coordinate 3.
In the second sample case there will be no explosion because there are no particles which will simultaneously be at the same point. | instruction | 0 | 69,450 | 3 | 138,900 |
Tags: implementation
Correct Solution:
```
n = int(input())
st = input()
lst = list(map(int, input().split()))
minn = float("INF")
yes = False
for i in range(n-1):
if st[i] == "R" and st[i+1] == "L":
yes = True
minn = min(minn, (lst[i+1] - lst[i])//2)
if not yes: print(-1)
else: print(minn+1+1-2)
``` | output | 1 | 69,450 | 3 | 138,901 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There will be a launch of a new, powerful and unusual collider very soon, which located along a straight line. n particles will be launched inside it. All of them are located in a straight line and there can not be two or more particles located in the same point. The coordinates of the particles coincide with the distance in meters from the center of the collider, xi is the coordinate of the i-th particle and its position in the collider at the same time. All coordinates of particle positions are even integers.
You know the direction of each particle movement β it will move to the right or to the left after the collider's launch start. All particles begin to move simultaneously at the time of the collider's launch start. Each particle will move straight to the left or straight to the right with the constant speed of 1 meter per microsecond. The collider is big enough so particles can not leave it in the foreseeable time.
Write the program which finds the moment of the first collision of any two particles of the collider. In other words, find the number of microseconds before the first moment when any two particles are at the same point.
Input
The first line contains the positive integer n (1 β€ n β€ 200 000) β the number of particles.
The second line contains n symbols "L" and "R". If the i-th symbol equals "L", then the i-th particle will move to the left, otherwise the i-th symbol equals "R" and the i-th particle will move to the right.
The third line contains the sequence of pairwise distinct even integers x1, x2, ..., xn (0 β€ xi β€ 109) β the coordinates of particles in the order from the left to the right. It is guaranteed that the coordinates of particles are given in the increasing order.
Output
In the first line print the only integer β the first moment (in microseconds) when two particles are at the same point and there will be an explosion.
Print the only integer -1, if the collision of particles doesn't happen.
Examples
Input
4
RLRL
2 4 6 10
Output
1
Input
3
LLR
40 50 60
Output
-1
Note
In the first sample case the first explosion will happen in 1 microsecond because the particles number 1 and 2 will simultaneously be at the same point with the coordinate 3.
In the second sample case there will be no explosion because there are no particles which will simultaneously be at the same point.
Submitted Solution:
```
N=int(input())
S=list(input())
C=list(map(int,input().split()))
an = None
lastR = None
for i,q in enumerate(S):
if q == 'R':
lastR = C[i]
else:
if lastR != None:
if an == None:
an = C[i] - lastR
else:
an = min(an, C[i] - lastR)
if an != None:
print(an//2)
else:
print(-1)
``` | instruction | 0 | 69,451 | 3 | 138,902 |
Yes | output | 1 | 69,451 | 3 | 138,903 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There will be a launch of a new, powerful and unusual collider very soon, which located along a straight line. n particles will be launched inside it. All of them are located in a straight line and there can not be two or more particles located in the same point. The coordinates of the particles coincide with the distance in meters from the center of the collider, xi is the coordinate of the i-th particle and its position in the collider at the same time. All coordinates of particle positions are even integers.
You know the direction of each particle movement β it will move to the right or to the left after the collider's launch start. All particles begin to move simultaneously at the time of the collider's launch start. Each particle will move straight to the left or straight to the right with the constant speed of 1 meter per microsecond. The collider is big enough so particles can not leave it in the foreseeable time.
Write the program which finds the moment of the first collision of any two particles of the collider. In other words, find the number of microseconds before the first moment when any two particles are at the same point.
Input
The first line contains the positive integer n (1 β€ n β€ 200 000) β the number of particles.
The second line contains n symbols "L" and "R". If the i-th symbol equals "L", then the i-th particle will move to the left, otherwise the i-th symbol equals "R" and the i-th particle will move to the right.
The third line contains the sequence of pairwise distinct even integers x1, x2, ..., xn (0 β€ xi β€ 109) β the coordinates of particles in the order from the left to the right. It is guaranteed that the coordinates of particles are given in the increasing order.
Output
In the first line print the only integer β the first moment (in microseconds) when two particles are at the same point and there will be an explosion.
Print the only integer -1, if the collision of particles doesn't happen.
Examples
Input
4
RLRL
2 4 6 10
Output
1
Input
3
LLR
40 50 60
Output
-1
Note
In the first sample case the first explosion will happen in 1 microsecond because the particles number 1 and 2 will simultaneously be at the same point with the coordinate 3.
In the second sample case there will be no explosion because there are no particles which will simultaneously be at the same point.
Submitted Solution:
```
from sys import stdin
n =int(input())
str = stdin.readline()
arr = list(map(int,stdin.readline().split()))
r = neg = -1
p = 0
for i in range(n-1):
if(str[i] == 'R' and str[i+1] == 'L'):
r = int(( arr[i+1] - arr[i]) / 2)
if(p == 0 or p > r):
p = r
if(r == -1):
print("-1")
else:
print(p)
``` | instruction | 0 | 69,452 | 3 | 138,904 |
Yes | output | 1 | 69,452 | 3 | 138,905 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There will be a launch of a new, powerful and unusual collider very soon, which located along a straight line. n particles will be launched inside it. All of them are located in a straight line and there can not be two or more particles located in the same point. The coordinates of the particles coincide with the distance in meters from the center of the collider, xi is the coordinate of the i-th particle and its position in the collider at the same time. All coordinates of particle positions are even integers.
You know the direction of each particle movement β it will move to the right or to the left after the collider's launch start. All particles begin to move simultaneously at the time of the collider's launch start. Each particle will move straight to the left or straight to the right with the constant speed of 1 meter per microsecond. The collider is big enough so particles can not leave it in the foreseeable time.
Write the program which finds the moment of the first collision of any two particles of the collider. In other words, find the number of microseconds before the first moment when any two particles are at the same point.
Input
The first line contains the positive integer n (1 β€ n β€ 200 000) β the number of particles.
The second line contains n symbols "L" and "R". If the i-th symbol equals "L", then the i-th particle will move to the left, otherwise the i-th symbol equals "R" and the i-th particle will move to the right.
The third line contains the sequence of pairwise distinct even integers x1, x2, ..., xn (0 β€ xi β€ 109) β the coordinates of particles in the order from the left to the right. It is guaranteed that the coordinates of particles are given in the increasing order.
Output
In the first line print the only integer β the first moment (in microseconds) when two particles are at the same point and there will be an explosion.
Print the only integer -1, if the collision of particles doesn't happen.
Examples
Input
4
RLRL
2 4 6 10
Output
1
Input
3
LLR
40 50 60
Output
-1
Note
In the first sample case the first explosion will happen in 1 microsecond because the particles number 1 and 2 will simultaneously be at the same point with the coordinate 3.
In the second sample case there will be no explosion because there are no particles which will simultaneously be at the same point.
Submitted Solution:
```
n = int(input())
s = input()
a = list(map(int, input().split()))
ans = 10000000000000
for i in range(n - 1):
if s[i] == 'R' and s[i + 1] == 'L':
ans = min(ans, (a[i + 1] - a[i]) // 2)
if ans == 10000000000000:
print(-1)
else:
print(ans)
``` | instruction | 0 | 69,453 | 3 | 138,906 |
Yes | output | 1 | 69,453 | 3 | 138,907 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There will be a launch of a new, powerful and unusual collider very soon, which located along a straight line. n particles will be launched inside it. All of them are located in a straight line and there can not be two or more particles located in the same point. The coordinates of the particles coincide with the distance in meters from the center of the collider, xi is the coordinate of the i-th particle and its position in the collider at the same time. All coordinates of particle positions are even integers.
You know the direction of each particle movement β it will move to the right or to the left after the collider's launch start. All particles begin to move simultaneously at the time of the collider's launch start. Each particle will move straight to the left or straight to the right with the constant speed of 1 meter per microsecond. The collider is big enough so particles can not leave it in the foreseeable time.
Write the program which finds the moment of the first collision of any two particles of the collider. In other words, find the number of microseconds before the first moment when any two particles are at the same point.
Input
The first line contains the positive integer n (1 β€ n β€ 200 000) β the number of particles.
The second line contains n symbols "L" and "R". If the i-th symbol equals "L", then the i-th particle will move to the left, otherwise the i-th symbol equals "R" and the i-th particle will move to the right.
The third line contains the sequence of pairwise distinct even integers x1, x2, ..., xn (0 β€ xi β€ 109) β the coordinates of particles in the order from the left to the right. It is guaranteed that the coordinates of particles are given in the increasing order.
Output
In the first line print the only integer β the first moment (in microseconds) when two particles are at the same point and there will be an explosion.
Print the only integer -1, if the collision of particles doesn't happen.
Examples
Input
4
RLRL
2 4 6 10
Output
1
Input
3
LLR
40 50 60
Output
-1
Note
In the first sample case the first explosion will happen in 1 microsecond because the particles number 1 and 2 will simultaneously be at the same point with the coordinate 3.
In the second sample case there will be no explosion because there are no particles which will simultaneously be at the same point.
Submitted Solution:
```
n = int(input())
#n, m = map(int, input().split())
s = input()
c = list(map(int, input().split()))
l = 10 ** 10
for i in range(1, n):
if s[i] == 'L' and s[i - 1] == 'R':
l = min(l, c[i] - c[i - 1])
if l == 10 ** 10:
print(-1)
else:
print(l // 2)
``` | instruction | 0 | 69,454 | 3 | 138,908 |
Yes | output | 1 | 69,454 | 3 | 138,909 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There will be a launch of a new, powerful and unusual collider very soon, which located along a straight line. n particles will be launched inside it. All of them are located in a straight line and there can not be two or more particles located in the same point. The coordinates of the particles coincide with the distance in meters from the center of the collider, xi is the coordinate of the i-th particle and its position in the collider at the same time. All coordinates of particle positions are even integers.
You know the direction of each particle movement β it will move to the right or to the left after the collider's launch start. All particles begin to move simultaneously at the time of the collider's launch start. Each particle will move straight to the left or straight to the right with the constant speed of 1 meter per microsecond. The collider is big enough so particles can not leave it in the foreseeable time.
Write the program which finds the moment of the first collision of any two particles of the collider. In other words, find the number of microseconds before the first moment when any two particles are at the same point.
Input
The first line contains the positive integer n (1 β€ n β€ 200 000) β the number of particles.
The second line contains n symbols "L" and "R". If the i-th symbol equals "L", then the i-th particle will move to the left, otherwise the i-th symbol equals "R" and the i-th particle will move to the right.
The third line contains the sequence of pairwise distinct even integers x1, x2, ..., xn (0 β€ xi β€ 109) β the coordinates of particles in the order from the left to the right. It is guaranteed that the coordinates of particles are given in the increasing order.
Output
In the first line print the only integer β the first moment (in microseconds) when two particles are at the same point and there will be an explosion.
Print the only integer -1, if the collision of particles doesn't happen.
Examples
Input
4
RLRL
2 4 6 10
Output
1
Input
3
LLR
40 50 60
Output
-1
Note
In the first sample case the first explosion will happen in 1 microsecond because the particles number 1 and 2 will simultaneously be at the same point with the coordinate 3.
In the second sample case there will be no explosion because there are no particles which will simultaneously be at the same point.
Submitted Solution:
```
n = int(input())
Dir = input()
nums = [int(i) for i in input().split()]
for i in range(len(Dir)):
if Dir[i] == 'R':
nums[i] *= (-1)
a = []
for i in range(len(nums)-1):
a.append(nums[i] + nums[i+1])
Dis = []
for dis in a:
if dis > 0:
Dis.append(dis)
if Dir.find('RL') == -1:
print('-1')
else:
print(int(min(Dis)/2))
``` | instruction | 0 | 69,455 | 3 | 138,910 |
No | output | 1 | 69,455 | 3 | 138,911 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There will be a launch of a new, powerful and unusual collider very soon, which located along a straight line. n particles will be launched inside it. All of them are located in a straight line and there can not be two or more particles located in the same point. The coordinates of the particles coincide with the distance in meters from the center of the collider, xi is the coordinate of the i-th particle and its position in the collider at the same time. All coordinates of particle positions are even integers.
You know the direction of each particle movement β it will move to the right or to the left after the collider's launch start. All particles begin to move simultaneously at the time of the collider's launch start. Each particle will move straight to the left or straight to the right with the constant speed of 1 meter per microsecond. The collider is big enough so particles can not leave it in the foreseeable time.
Write the program which finds the moment of the first collision of any two particles of the collider. In other words, find the number of microseconds before the first moment when any two particles are at the same point.
Input
The first line contains the positive integer n (1 β€ n β€ 200 000) β the number of particles.
The second line contains n symbols "L" and "R". If the i-th symbol equals "L", then the i-th particle will move to the left, otherwise the i-th symbol equals "R" and the i-th particle will move to the right.
The third line contains the sequence of pairwise distinct even integers x1, x2, ..., xn (0 β€ xi β€ 109) β the coordinates of particles in the order from the left to the right. It is guaranteed that the coordinates of particles are given in the increasing order.
Output
In the first line print the only integer β the first moment (in microseconds) when two particles are at the same point and there will be an explosion.
Print the only integer -1, if the collision of particles doesn't happen.
Examples
Input
4
RLRL
2 4 6 10
Output
1
Input
3
LLR
40 50 60
Output
-1
Note
In the first sample case the first explosion will happen in 1 microsecond because the particles number 1 and 2 will simultaneously be at the same point with the coordinate 3.
In the second sample case there will be no explosion because there are no particles which will simultaneously be at the same point.
Submitted Solution:
```
n = int(input())
directions = [x for x in input()]
points = [int(x) for x in input().split()]
for x in range(len(directions)-1):
if directions[x] == "R" and directions[x+1] == "L":
a =((points[x]+points[x+1]) /2) - points[x]
print(int(a))
exit()
print(-1)
``` | instruction | 0 | 69,456 | 3 | 138,912 |
No | output | 1 | 69,456 | 3 | 138,913 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There will be a launch of a new, powerful and unusual collider very soon, which located along a straight line. n particles will be launched inside it. All of them are located in a straight line and there can not be two or more particles located in the same point. The coordinates of the particles coincide with the distance in meters from the center of the collider, xi is the coordinate of the i-th particle and its position in the collider at the same time. All coordinates of particle positions are even integers.
You know the direction of each particle movement β it will move to the right or to the left after the collider's launch start. All particles begin to move simultaneously at the time of the collider's launch start. Each particle will move straight to the left or straight to the right with the constant speed of 1 meter per microsecond. The collider is big enough so particles can not leave it in the foreseeable time.
Write the program which finds the moment of the first collision of any two particles of the collider. In other words, find the number of microseconds before the first moment when any two particles are at the same point.
Input
The first line contains the positive integer n (1 β€ n β€ 200 000) β the number of particles.
The second line contains n symbols "L" and "R". If the i-th symbol equals "L", then the i-th particle will move to the left, otherwise the i-th symbol equals "R" and the i-th particle will move to the right.
The third line contains the sequence of pairwise distinct even integers x1, x2, ..., xn (0 β€ xi β€ 109) β the coordinates of particles in the order from the left to the right. It is guaranteed that the coordinates of particles are given in the increasing order.
Output
In the first line print the only integer β the first moment (in microseconds) when two particles are at the same point and there will be an explosion.
Print the only integer -1, if the collision of particles doesn't happen.
Examples
Input
4
RLRL
2 4 6 10
Output
1
Input
3
LLR
40 50 60
Output
-1
Note
In the first sample case the first explosion will happen in 1 microsecond because the particles number 1 and 2 will simultaneously be at the same point with the coordinate 3.
In the second sample case there will be no explosion because there are no particles which will simultaneously be at the same point.
Submitted Solution:
```
from itertools import product
from math import ceil, gcd, sqrt
import string
from decimal import Decimal
def binary_table(string_with_all_characters, length_to_make):
return [''.join(x) for x in product(string_with_all_characters, repeat=length_to_make)]
def all_possible_substrings(string):
return [int(string[i: j]) for i in range(len(string)) for j in range(i + 1, len(string) + 1)]
def number_of_substrings(length):
return int(length * (length + 1) / 2)
def is_prime(num):
for i in range(2, num):
if num / i == int(num / i) and num != i:
return False
return True
num_of_particles = int(input())
movement_directions = input()
array = list(map(int, input().split()))
num = 0
cond = False
all_ = set()
for i in range(len(movement_directions)):
x = movement_directions[i: i + 2]
print(x)
if x == 'RL':
xd = array[i: i + 2]
all_.add(int(abs(xd[0] - xd[1]) / 2))
if all_:
print(min(all_))
else:
print(-1)
``` | instruction | 0 | 69,457 | 3 | 138,914 |
No | output | 1 | 69,457 | 3 | 138,915 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There will be a launch of a new, powerful and unusual collider very soon, which located along a straight line. n particles will be launched inside it. All of them are located in a straight line and there can not be two or more particles located in the same point. The coordinates of the particles coincide with the distance in meters from the center of the collider, xi is the coordinate of the i-th particle and its position in the collider at the same time. All coordinates of particle positions are even integers.
You know the direction of each particle movement β it will move to the right or to the left after the collider's launch start. All particles begin to move simultaneously at the time of the collider's launch start. Each particle will move straight to the left or straight to the right with the constant speed of 1 meter per microsecond. The collider is big enough so particles can not leave it in the foreseeable time.
Write the program which finds the moment of the first collision of any two particles of the collider. In other words, find the number of microseconds before the first moment when any two particles are at the same point.
Input
The first line contains the positive integer n (1 β€ n β€ 200 000) β the number of particles.
The second line contains n symbols "L" and "R". If the i-th symbol equals "L", then the i-th particle will move to the left, otherwise the i-th symbol equals "R" and the i-th particle will move to the right.
The third line contains the sequence of pairwise distinct even integers x1, x2, ..., xn (0 β€ xi β€ 109) β the coordinates of particles in the order from the left to the right. It is guaranteed that the coordinates of particles are given in the increasing order.
Output
In the first line print the only integer β the first moment (in microseconds) when two particles are at the same point and there will be an explosion.
Print the only integer -1, if the collision of particles doesn't happen.
Examples
Input
4
RLRL
2 4 6 10
Output
1
Input
3
LLR
40 50 60
Output
-1
Note
In the first sample case the first explosion will happen in 1 microsecond because the particles number 1 and 2 will simultaneously be at the same point with the coordinate 3.
In the second sample case there will be no explosion because there are no particles which will simultaneously be at the same point.
Submitted Solution:
```
n = int(input().split()[0])
LR = input()
X = list(map(int, input().split()))
if n == 1:
print('-1')
exit()
L, R = [-1 for i in range(n)], [-1 for i in range(n)]
for i, lr in reversed(list(enumerate(LR))):
if lr == 'L':
L[i] = X[i]
else:
L[i] = L[(i + 1) % n]
mint = float('inf')
for i, lr in enumerate(LR):
if lr == 'R':
t = L[i] - X[i]
if mint > t:
mint = t
if mint == float('inf'):
print('-1')
else:
print(mint // 2)
``` | instruction | 0 | 69,458 | 3 | 138,916 |
No | output | 1 | 69,458 | 3 | 138,917 |
Provide tags and a correct Python 3 solution for this coding contest problem.
<image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | instruction | 0 | 69,512 | 3 | 139,024 |
Tags: implementation
Correct Solution:
```
string = input()
s = string[0]
a = string[2]
n = int(input())
b = n%4
if s == '>':
if a == '^':
if b == 1:
print("ccw")
else:
print("cw")
elif a =='v':
if b == 3:
print("ccw")
else:
print("cw")
else:
print("undefined")
elif s == '<':
if a == '^':
if b == 1:
print("cw")
else:
print("ccw")
elif a =='v':
if b == 3:
print("cw")
else:
print("ccw")
else:
print("undefined")
elif s == '^':
if a == '>':
if b == 1:
print("cw")
else:
print("ccw")
elif a =='<':
if b == 3:
print("cw")
else:
print("ccw")
else:
print("undefined")
else:
if a == '>':
if b == 1:
print("ccw")
else:
print("cw")
elif a =='<':
if b == 3:
print("ccw")
else:
print("cw")
else:
print("undefined")
``` | output | 1 | 69,512 | 3 | 139,025 |
Provide tags and a correct Python 3 solution for this coding contest problem.
<image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | instruction | 0 | 69,513 | 3 | 139,026 |
Tags: implementation
Correct Solution:
```
n,m = input().strip().split()
#print(n,' ',m)
t=int(input())
tr=t % 4
cww=[chr(118), '<',chr(94),'>']
cwww=[chr(118),'>',chr(94),'<']
p=cww.index(n)
q=cwww.index(n)
#print(p,' ',q)
if cww[(p+tr)%4]==cwww[(q+tr)%4]:
print('undefined')
elif cww[(p+tr)%4]==m:
print('cw')
elif cwww[(q+tr)%4]==m:
print('ccw')
``` | output | 1 | 69,513 | 3 | 139,027 |
Provide tags and a correct Python 3 solution for this coding contest problem.
<image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | instruction | 0 | 69,514 | 3 | 139,028 |
Tags: implementation
Correct Solution:
```
start_end = input().strip()
time = int(input().strip())
start = start_end.split()[0]
end = start_end.split()[1]
start_dir = -1
end_dir = -1
if start == '<':
start_dir = 0
elif start == '^':
start_dir = 1
elif start == '>':
start_dir = 2
elif start == 'v':
start_dir = 3
if end == '<':
end_dir = 0
elif end == '^':
end_dir = 1
elif end == '>':
end_dir = 2
elif end == 'v':
end_dir = 3
turns = time
ccw =False
cw = False
if (start_dir == end_dir) or (start_dir % 2 == end_dir %2):
print('undefined')
elif (start_dir + turns) % 4 == end_dir:
print('cw')
else:
print('ccw')
``` | output | 1 | 69,514 | 3 | 139,029 |
Provide tags and a correct Python 3 solution for this coding contest problem.
<image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | instruction | 0 | 69,515 | 3 | 139,030 |
Tags: implementation
Correct Solution:
```
st, en = map(str, input().split())
n = int(input())
n %= 4
m = {"^":1, ">":2, "v":3, "<":4}
if (m[st] + m[en]) % 4 == 2 or (m[st] + m[en]) % 4 == 0:
print("undefined")
elif (m[st] + n) % 4 == m[en] or (m[st] + n) == m[en]:
print("cw")
else:
print("ccw")
``` | output | 1 | 69,515 | 3 | 139,031 |
Provide tags and a correct Python 3 solution for this coding contest problem.
<image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | instruction | 0 | 69,516 | 3 | 139,032 |
Tags: implementation
Correct Solution:
```
initial,final = input().split()
cw_res, ccw_res = initial,initial
n = int(input())
n = n%4
ccw = {
'<': 'v',
'>': '^',
'v': '>',
'^': '<'
}
cc = {
'<': '^',
'>': 'v',
'^': '>',
'v': '<'
}
for i in range(n):
cw_res = cc[ cw_res ]
ccw_res = ccw[ ccw_res ]
if cw_res == ccw_res:
print('undefined')
elif cw_res == final:
print('cw')
else:
print('ccw')
``` | output | 1 | 69,516 | 3 | 139,033 |
Provide tags and a correct Python 3 solution for this coding contest problem.
<image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | instruction | 0 | 69,517 | 3 | 139,034 |
Tags: implementation
Correct Solution:
```
a = ['v', '<', '^', '>']
s, e = input().split()
n = int(input())
l = a.index(s)
r = l
n = n % 4
for i in range(n):
if l == 0: l = 3
else: l -= 1
if r == 3: r = 0
else: r += 1
if a[l] == e and a[r] == e:
print('undefined')
elif a[l] == e:
print('ccw')
elif a[r] == e:
print('cw')
``` | output | 1 | 69,517 | 3 | 139,035 |
Provide tags and a correct Python 3 solution for this coding contest problem.
<image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | instruction | 0 | 69,518 | 3 | 139,036 |
Tags: implementation
Correct Solution:
```
s = input()
n = int(input())
if not(n%2):
print("undefined")
elif ("^>v<".find(s[0])+n)%4 == "^>v<".find(s[2]):
print("cw")
else:
print("ccw")
``` | output | 1 | 69,518 | 3 | 139,037 |
Provide tags and a correct Python 3 solution for this coding contest problem.
<image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined | instruction | 0 | 69,519 | 3 | 139,038 |
Tags: implementation
Correct Solution:
```
elem = ['v', '<', '^', '>']
a, b = map(elem.index, input().split())
n = int(input())
diff = (b - a + 4) % 4
if (diff == 0 or diff == 2):
print('undefined')
elif (diff == n % 4):
print('cw')
else:
print('ccw')
``` | output | 1 | 69,519 | 3 | 139,039 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
<image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined
Submitted Solution:
```
read = lambda: map(int, input().split())
a, b = input().split()
n = int(input()) % 4
s = 'v<^>'
k1 = (s.index(b) - s.index(a)) % 4
k2 = (s.index(a) - s.index(b)) % 4
print('cw' if k1 == n and k2 != n else 'ccw' if k1 != n and k2 == n else 'undefined')
``` | instruction | 0 | 69,520 | 3 | 139,040 |
Yes | output | 1 | 69,520 | 3 | 139,041 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
<image>
Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays β caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.
Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):
<image>
After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.
Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.
Input
There are two characters in the first string β the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space.
In the second strings, a single number n is given (0 β€ n β€ 109) β the duration of the rotation.
It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.
Output
Output cw, if the direction is clockwise, ccw β if counter-clockwise, and undefined otherwise.
Examples
Input
^ >
1
Output
cw
Input
< ^
3
Output
ccw
Input
^ v
6
Output
undefined
Submitted Solution:
```
s,f = input().split(' ')
n = int(input())
cw = {'^': 1, '>':2, 'v':3, '<':0}
ccw = {'^': 1, '>':0, 'v':3, '<':2}
a = (cw[s] + n) % 4
b = (ccw[s] + n) % 4
if a == cw[f] and b == ccw[f]:
print('undefined')
elif a == cw[f]:
print('cw')
elif b == ccw[f]:
print('ccw')
else:
print('undefined')
``` | instruction | 0 | 69,521 | 3 | 139,042 |
Yes | output | 1 | 69,521 | 3 | 139,043 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.