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.
Developer Petr thinks that he invented a perpetual motion machine. Namely, he has a lot of elements, which work in the following way.
Each element has one controller that can be set to any non-negative real value. If a controller is set on some value x, then the controller consumes x2 energy units per second. At the same time, any two elements connected by a wire produce y·z energy units per second, where y and z are the values set on their controllers.
Petr has only a limited number of wires, so he has already built some scheme of elements and wires, and is now interested if it's possible to set the controllers in such a way that the system produces at least as much power as it consumes, and at least one controller is set on the value different from 0. Help him check this, and if it's possible, find the required integer values that should be set.
It is guaranteed that if there exist controllers' settings satisfying the above conditions, then there exist required integer values not greater than 106.
Input
There are several (at least one) test cases in the input. The first line contains single integer — the number of test cases.
There is an empty line before each test case. The first line of test case contains two integers n and m (1 ≤ n ≤ 105, 0 ≤ m ≤ 105) — the number of elements in the scheme and the number of wires.
After that, m lines follow, each of them contains two integers a and b (1 ≤ a, b ≤ n) — two elements connected by a wire. No element is connected with itself, no two elements are connected by more than one wire.
It is guaranteed that the sum of n and the sum of m over all test cases do not exceed 105.
For hacks you can only use tests with one test case.
Output
Print answer for each test case.
For each test case print "YES" if it's possible to set the controllers in such a way that the consumed power is not greater than the power produced, and the required values on the next line. The settings should be integers from 0 to 106, inclusive, and at least one value should be different from 0. If there are multiple answers, print any of them.
If it's not possible to set the controllers in the required way, print one line "NO".
Example
Input
4
4 4
1 2
2 3
3 4
4 2
3 2
2 3
3 1
4 6
1 2
3 4
4 2
1 4
1 3
3 2
10 9
2 1
3 2
5 2
6 2
2 7
2 8
2 9
2 10
4 2
Output
YES
1 2 2 1
NO
YES
1 1 1 1
YES
1 5 1 1 1 1 1 1 1 1
Note
In the first example it's possible to set the controllers in the required way, for example, in the following way: set 1 on the first element, set 2 on the second and on the third, set 1 on the fourth. The consumed power is then equal to 12 + 22 + 22 + 12 = 10 energy units per second, the produced power is equal to 1·2 + 2·2 + 2·1 + 2·1 = 10 energy units per second. Thus the answer is "YES".
In the second test case it's not possible to set the controllers in the required way. For example, if we set all controllers to 0.5, then the consumed powers equals 0.75 energy units per second, while produced power equals 0.5 energy units per second.
Submitted Solution:
```
test_cases = int(input())
#print("Test cases:", test_cases)
def value(controllers, connections):
consume = 0
for controller in controllers:
consume += controller ** 2
produce = 0
for connection in connections:
produce += controllers[connection[0] - 1] * controllers[connection[1] - 1]
return consume <= produce
def recurse(elements, N = 4):
if elements >= 5:
N = 2
#controller_values = [[0], [1], [2], [3]]
basic_values = [[x] for x in range(N)]
if elements == 1:
return basic_values
else:
lst = []
for c_value in recurse(elements - 1):
for basic in basic_values:
lst.append(c_value + basic)
return lst
for i in range(test_cases):
#print("---------Test case", i + 1, "--------")
input()
elements, wires = [int(x) for x in input().split()]
#print("Elements:", elements)
#print("Wires:", wires)
#print("Type of wire:", type(wires))
connections = []
for j in range(wires):
a, b = [int(x) for x in input().split()]
connections.append((a, b))
#print("Connections become", connections)
#print("Connections are:")
#for connection in connections:
#print(connection[0], "with", connection[1])
all_controllers = recurse(elements)[1:]
#print(all_controllers)
breaked = False
for controllers in all_controllers:
if value(controllers, connections):
print("YES")
for controller in controllers:
print(controller,end=' ')
print()
breaked = True
break
if not breaked:
print("NO")
#print("=========================")
#print(recurse(5))
``` | instruction | 0 | 84,712 | 3 | 169,424 |
No | output | 1 | 84,712 | 3 | 169,425 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Developer Petr thinks that he invented a perpetual motion machine. Namely, he has a lot of elements, which work in the following way.
Each element has one controller that can be set to any non-negative real value. If a controller is set on some value x, then the controller consumes x2 energy units per second. At the same time, any two elements connected by a wire produce y·z energy units per second, where y and z are the values set on their controllers.
Petr has only a limited number of wires, so he has already built some scheme of elements and wires, and is now interested if it's possible to set the controllers in such a way that the system produces at least as much power as it consumes, and at least one controller is set on the value different from 0. Help him check this, and if it's possible, find the required integer values that should be set.
It is guaranteed that if there exist controllers' settings satisfying the above conditions, then there exist required integer values not greater than 106.
Input
There are several (at least one) test cases in the input. The first line contains single integer — the number of test cases.
There is an empty line before each test case. The first line of test case contains two integers n and m (1 ≤ n ≤ 105, 0 ≤ m ≤ 105) — the number of elements in the scheme and the number of wires.
After that, m lines follow, each of them contains two integers a and b (1 ≤ a, b ≤ n) — two elements connected by a wire. No element is connected with itself, no two elements are connected by more than one wire.
It is guaranteed that the sum of n and the sum of m over all test cases do not exceed 105.
For hacks you can only use tests with one test case.
Output
Print answer for each test case.
For each test case print "YES" if it's possible to set the controllers in such a way that the consumed power is not greater than the power produced, and the required values on the next line. The settings should be integers from 0 to 106, inclusive, and at least one value should be different from 0. If there are multiple answers, print any of them.
If it's not possible to set the controllers in the required way, print one line "NO".
Example
Input
4
4 4
1 2
2 3
3 4
4 2
3 2
2 3
3 1
4 6
1 2
3 4
4 2
1 4
1 3
3 2
10 9
2 1
3 2
5 2
6 2
2 7
2 8
2 9
2 10
4 2
Output
YES
1 2 2 1
NO
YES
1 1 1 1
YES
1 5 1 1 1 1 1 1 1 1
Note
In the first example it's possible to set the controllers in the required way, for example, in the following way: set 1 on the first element, set 2 on the second and on the third, set 1 on the fourth. The consumed power is then equal to 12 + 22 + 22 + 12 = 10 energy units per second, the produced power is equal to 1·2 + 2·2 + 2·1 + 2·1 = 10 energy units per second. Thus the answer is "YES".
In the second test case it's not possible to set the controllers in the required way. For example, if we set all controllers to 0.5, then the consumed powers equals 0.75 energy units per second, while produced power equals 0.5 energy units per second.
Submitted Solution:
```
test_cases = int(input())
#print("Test cases:", test_cases)
def value(controllers, connections):
consume = 0
for controller in controllers:
consume += controller ** 2
produce = 0
for connection in connections:
produce += controllers[connection[0] - 1] * controllers[connection[1] - 1]
return consume <= produce
def recurse(elements, N = 4):
if elements >= 6:
N = 2
#controller_values = [[0], [1], [2], [3]]
basic_values = [[x] for x in range(N)]
if elements == 1:
return basic_values
else:
lst = []
for c_value in recurse(elements - 1):
for basic in basic_values:
lst.append(c_value + basic)
return lst
for i in range(test_cases):
#print("---------Test case", i + 1, "--------")
input()
elements, wires = [int(x) for x in input().split()]
#print("Elements:", elements)
#print("Wires:", wires)
#print("Type of wire:", type(wires))
connections = []
for j in range(wires):
a, b = [int(x) for x in input().split()]
connections.append((a, b))
#print("Connections become", connections)
#print("Connections are:")
#for connection in connections:
#print(connection[0], "with", connection[1])
all_controllers = recurse(elements)[1:]
#print(all_controllers)
breaked = False
for controllers in all_controllers:
if value(controllers, connections):
print("YES")
for controller in controllers:
print(controller,end=' ')
print()
breaked = True
break
if not breaked:
print("NO")
#print("=========================")
#print(recurse(5))
``` | instruction | 0 | 84,713 | 3 | 169,426 |
No | output | 1 | 84,713 | 3 | 169,427 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The whole world got obsessed with robots,and to keep pace with the progress, great Berland's programmer Draude decided to build his own robot. He was working hard at the robot. He taught it to walk the shortest path from one point to another, to record all its movements, but like in many Draude's programs, there was a bug — the robot didn't always walk the shortest path. Fortunately, the robot recorded its own movements correctly. Now Draude wants to find out when his robot functions wrong. Heh, if Draude only remembered the map of the field, where he tested the robot, he would easily say if the robot walked in the right direction or not. But the field map was lost never to be found, that's why he asks you to find out if there exist at least one map, where the path recorded by the robot is the shortest.
The map is an infinite checkered field, where each square is either empty, or contains an obstruction. It is also known that the robot never tries to run into the obstruction. By the recorded robot's movements find out if there exist at least one such map, that it is possible to choose for the robot a starting square (the starting square should be empty) such that when the robot moves from this square its movements coincide with the recorded ones (the robot doesn't run into anything, moving along empty squares only), and the path from the starting square to the end one is the shortest.
In one movement the robot can move into the square (providing there are no obstrutions in this square) that has common sides with the square the robot is currently in.
Input
The first line of the input file contains the recording of the robot's movements. This recording is a non-empty string, consisting of uppercase Latin letters L, R, U and D, standing for movements left, right, up and down respectively. The length of the string does not exceed 100.
Output
In the first line output the only word OK (if the above described map exists), or BUG (if such a map does not exist).
Examples
Input
LLUUUR
Output
OK
Input
RRUULLDD
Output
BUG
Submitted Solution:
```
s = input()
field = [[0] * (3 * len(s)) for i in range(3 * len(s))]
when = [[-2] * (3 * len(s)) for i in range(3 * len(s))]
field[0][0] = 1
when[0][0] = -1
x, y = 0, 0
for i in range(len(s)):
c = s[i]
if c == 'R':
x += 1
if c == 'L':
x -= 1
if c == 'U':
y += 1
if c == 'D':
y -= 1
field[x][y] += 1
if field[x][y] > 1:
print('BUG')
exit()
when[x][y] = i
for i in range(-len(s), len(s) + 1):
for j in range(-len(s), len(s) + 1):
if when[i][j] == -2:
continue
if when[i][j] + 1 < max((when[i + 1][j], when[i - 1][j], when[i][j + 1], when[i][j - 1])):
print('BUG')
exit()
print('OK')
``` | instruction | 0 | 84,742 | 3 | 169,484 |
Yes | output | 1 | 84,742 | 3 | 169,485 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The whole world got obsessed with robots,and to keep pace with the progress, great Berland's programmer Draude decided to build his own robot. He was working hard at the robot. He taught it to walk the shortest path from one point to another, to record all its movements, but like in many Draude's programs, there was a bug — the robot didn't always walk the shortest path. Fortunately, the robot recorded its own movements correctly. Now Draude wants to find out when his robot functions wrong. Heh, if Draude only remembered the map of the field, where he tested the robot, he would easily say if the robot walked in the right direction or not. But the field map was lost never to be found, that's why he asks you to find out if there exist at least one map, where the path recorded by the robot is the shortest.
The map is an infinite checkered field, where each square is either empty, or contains an obstruction. It is also known that the robot never tries to run into the obstruction. By the recorded robot's movements find out if there exist at least one such map, that it is possible to choose for the robot a starting square (the starting square should be empty) such that when the robot moves from this square its movements coincide with the recorded ones (the robot doesn't run into anything, moving along empty squares only), and the path from the starting square to the end one is the shortest.
In one movement the robot can move into the square (providing there are no obstrutions in this square) that has common sides with the square the robot is currently in.
Input
The first line of the input file contains the recording of the robot's movements. This recording is a non-empty string, consisting of uppercase Latin letters L, R, U and D, standing for movements left, right, up and down respectively. The length of the string does not exceed 100.
Output
In the first line output the only word OK (if the above described map exists), or BUG (if such a map does not exist).
Examples
Input
LLUUUR
Output
OK
Input
RRUULLDD
Output
BUG
Submitted Solution:
```
s=input()
x,y=0,0
used=set()
used.add((x,y))
bo=0
for e in s:
if(e=='L'):
x+=1
elif(e=='R'):
x-=1
elif(e=='U'):
y+=1
else:
y-=1
a=(x-1,y) in used
b=(x+1,y) in used
c=(x,y-1) in used
d=(x,y+1) in used
if(a+b+c+d>1):
bo=1
used.add((x,y))
print("OK" if not bo else "BUG")
``` | instruction | 0 | 84,746 | 3 | 169,492 |
No | output | 1 | 84,746 | 3 | 169,493 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The whole world got obsessed with robots,and to keep pace with the progress, great Berland's programmer Draude decided to build his own robot. He was working hard at the robot. He taught it to walk the shortest path from one point to another, to record all its movements, but like in many Draude's programs, there was a bug — the robot didn't always walk the shortest path. Fortunately, the robot recorded its own movements correctly. Now Draude wants to find out when his robot functions wrong. Heh, if Draude only remembered the map of the field, where he tested the robot, he would easily say if the robot walked in the right direction or not. But the field map was lost never to be found, that's why he asks you to find out if there exist at least one map, where the path recorded by the robot is the shortest.
The map is an infinite checkered field, where each square is either empty, or contains an obstruction. It is also known that the robot never tries to run into the obstruction. By the recorded robot's movements find out if there exist at least one such map, that it is possible to choose for the robot a starting square (the starting square should be empty) such that when the robot moves from this square its movements coincide with the recorded ones (the robot doesn't run into anything, moving along empty squares only), and the path from the starting square to the end one is the shortest.
In one movement the robot can move into the square (providing there are no obstrutions in this square) that has common sides with the square the robot is currently in.
Input
The first line of the input file contains the recording of the robot's movements. This recording is a non-empty string, consisting of uppercase Latin letters L, R, U and D, standing for movements left, right, up and down respectively. The length of the string does not exceed 100.
Output
In the first line output the only word OK (if the above described map exists), or BUG (if such a map does not exist).
Examples
Input
LLUUUR
Output
OK
Input
RRUULLDD
Output
BUG
Submitted Solution:
```
s = input()
field = [[0] * (3 * len(s)) for i in range(3 * len(s))]
field[0][0] = 1
x, y = 0, 0
for c in s:
if c == 'R':
x += 1
if c == 'L':
x -= 1
if c == 'U':
y += 1
if c == 'D':
y -= 1
field[x][y] += 1
if field[x][y] > 1:
print('BUG')
exit()
for i in range(-len(s), len(s) + 1):
for j in range(-len(s), len(s) + 1):
if field[i][j] == field[i + 1][j] == field[i][j + 1] == field[i + 1][j + 1] == 1:
print('BUG')
exit()
print('OK')
``` | instruction | 0 | 84,747 | 3 | 169,494 |
No | output | 1 | 84,747 | 3 | 169,495 |
Provide a correct Python 3 solution for this coding contest problem.
In your garden, there is a long and narrow flowerbed that stretches infinitely to the east. You have decided to plant N kinds of flowers in this empty flowerbed. For convenience, we will call these N kinds of flowers Flower 1, 2, …, N. Also, we will call the position that is p centimeters from the west end of the flowerbed Position p.
You will plant Flower i (1 ≤ i ≤ N) as follows: first, plant one at Position w_i, then plant one every d_i centimeters endlessly toward the east. That is, Flower i will be planted at the positions w_i, w_i + d_i, w_i + 2 d_i, … Note that more than one flower may be planted at the same position.
Find the position at which the K-th flower from the west is planted. If more than one flower is planted at the same position, they are counted individually.
Constraints
* 1 ≤ N ≤ 10^5
* 1 ≤ K ≤ 10^9
* 1 ≤ w_i ≤ 10^{18}
* 1 ≤ d_i ≤ 10^9
* All input values are integers.
Input
Input is given from Standard Input in the following format:
N K
w_1 d_1
:
w_N d_N
Output
When the K-th flower from the west is planted at Position X, print the value of X. (The westmost flower is counted as the 1-st flower.)
Examples
Input
2 6
20 10
25 15
Output
50
Input
3 9
10 10
10 10
10 10
Output
30
Input
1 1000000000
1000000000000000000 1000000000
Output
1999999999000000000 | instruction | 0 | 84,878 | 3 | 169,756 |
"Correct Solution:
```
def count(N, x, w, d):
cnt = 0
for i in range(N):
if x >= w[i]:
cnt += (x - w[i]) // d[i] + 1
return cnt
def main():
N, K = map(int, input().split())
w = [0] * N
d = [0] * N
for i in range(N):
w[i], d[i] = map(int, input().split())
lo = 0
hi = max(w) + max(d) * (K-1)
while lo < hi:
mid = (lo + hi) // 2
if count(N, mid, w, d) < K:
lo = mid + 1
else:
hi = mid
print(lo)
if __name__ == "__main__":
main()
``` | output | 1 | 84,878 | 3 | 169,757 |
Provide a correct Python 3 solution for this coding contest problem.
In your garden, there is a long and narrow flowerbed that stretches infinitely to the east. You have decided to plant N kinds of flowers in this empty flowerbed. For convenience, we will call these N kinds of flowers Flower 1, 2, …, N. Also, we will call the position that is p centimeters from the west end of the flowerbed Position p.
You will plant Flower i (1 ≤ i ≤ N) as follows: first, plant one at Position w_i, then plant one every d_i centimeters endlessly toward the east. That is, Flower i will be planted at the positions w_i, w_i + d_i, w_i + 2 d_i, … Note that more than one flower may be planted at the same position.
Find the position at which the K-th flower from the west is planted. If more than one flower is planted at the same position, they are counted individually.
Constraints
* 1 ≤ N ≤ 10^5
* 1 ≤ K ≤ 10^9
* 1 ≤ w_i ≤ 10^{18}
* 1 ≤ d_i ≤ 10^9
* All input values are integers.
Input
Input is given from Standard Input in the following format:
N K
w_1 d_1
:
w_N d_N
Output
When the K-th flower from the west is planted at Position X, print the value of X. (The westmost flower is counted as the 1-st flower.)
Examples
Input
2 6
20 10
25 15
Output
50
Input
3 9
10 10
10 10
10 10
Output
30
Input
1 1000000000
1000000000000000000 1000000000
Output
1999999999000000000 | instruction | 0 | 84,879 | 3 | 169,758 |
"Correct Solution:
```
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)
N, K = map(int, input().split())
WD = tuple(tuple(map(int, input().split())) for _ in range(N))
l = 0
r = 2 * 10 ** 18 + 100
while (r - l) > 1:
pos = (r + l) // 2
cnt = 0
for w, d in WD:
if pos < w:
continue
cnt += 1 + (pos - w) // d
if cnt >= K:
r = pos
else:
l = pos
print(r)
``` | output | 1 | 84,879 | 3 | 169,759 |
Provide a correct Python 3 solution for this coding contest problem.
In your garden, there is a long and narrow flowerbed that stretches infinitely to the east. You have decided to plant N kinds of flowers in this empty flowerbed. For convenience, we will call these N kinds of flowers Flower 1, 2, …, N. Also, we will call the position that is p centimeters from the west end of the flowerbed Position p.
You will plant Flower i (1 ≤ i ≤ N) as follows: first, plant one at Position w_i, then plant one every d_i centimeters endlessly toward the east. That is, Flower i will be planted at the positions w_i, w_i + d_i, w_i + 2 d_i, … Note that more than one flower may be planted at the same position.
Find the position at which the K-th flower from the west is planted. If more than one flower is planted at the same position, they are counted individually.
Constraints
* 1 ≤ N ≤ 10^5
* 1 ≤ K ≤ 10^9
* 1 ≤ w_i ≤ 10^{18}
* 1 ≤ d_i ≤ 10^9
* All input values are integers.
Input
Input is given from Standard Input in the following format:
N K
w_1 d_1
:
w_N d_N
Output
When the K-th flower from the west is planted at Position X, print the value of X. (The westmost flower is counted as the 1-st flower.)
Examples
Input
2 6
20 10
25 15
Output
50
Input
3 9
10 10
10 10
10 10
Output
30
Input
1 1000000000
1000000000000000000 1000000000
Output
1999999999000000000 | instruction | 0 | 84,882 | 3 | 169,764 |
"Correct Solution:
```
import sys
N, K = map(int, input().split())
input = sys.stdin.readline
wd = [tuple(map(int, input().split())) for i in range(N)]
wd.sort()
d = 0
dp = [0]*N
l = 0
r = wd[0][0] + wd[0][1]*K
while(r - l > 1):
tmp = (l+r)//2
num = 0
for w, d in wd:
if w <= tmp:
num += ((tmp - w) // d) + 1
if num >= K:
r = tmp
else:
l = tmp
print(r)
``` | output | 1 | 84,882 | 3 | 169,765 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In your garden, there is a long and narrow flowerbed that stretches infinitely to the east. You have decided to plant N kinds of flowers in this empty flowerbed. For convenience, we will call these N kinds of flowers Flower 1, 2, …, N. Also, we will call the position that is p centimeters from the west end of the flowerbed Position p.
You will plant Flower i (1 ≤ i ≤ N) as follows: first, plant one at Position w_i, then plant one every d_i centimeters endlessly toward the east. That is, Flower i will be planted at the positions w_i, w_i + d_i, w_i + 2 d_i, … Note that more than one flower may be planted at the same position.
Find the position at which the K-th flower from the west is planted. If more than one flower is planted at the same position, they are counted individually.
Constraints
* 1 ≤ N ≤ 10^5
* 1 ≤ K ≤ 10^9
* 1 ≤ w_i ≤ 10^{18}
* 1 ≤ d_i ≤ 10^9
* All input values are integers.
Input
Input is given from Standard Input in the following format:
N K
w_1 d_1
:
w_N d_N
Output
When the K-th flower from the west is planted at Position X, print the value of X. (The westmost flower is counted as the 1-st flower.)
Examples
Input
2 6
20 10
25 15
Output
50
Input
3 9
10 10
10 10
10 10
Output
30
Input
1 1000000000
1000000000000000000 1000000000
Output
1999999999000000000
Submitted Solution:
```
import sys
sys.setrecursionlimit(10**8)
input = sys.stdin.readline
n, k = [int(item) for item in input().split()]
wd = []
for i in range(n):
w, d = [int(item) for item in input().split()]
wd.append((w, d))
l = -1; r = 10**20
while r - l > 1:
mid = (l + r) // 2
flower = 0
for w, d in wd:
if mid - w >= 0:
flower += (mid - w) // d + 1
if flower >= k:
break
if flower >= k:
r = mid
else:
l = mid
print(r)
``` | instruction | 0 | 84,886 | 3 | 169,772 |
Yes | output | 1 | 84,886 | 3 | 169,773 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In your garden, there is a long and narrow flowerbed that stretches infinitely to the east. You have decided to plant N kinds of flowers in this empty flowerbed. For convenience, we will call these N kinds of flowers Flower 1, 2, …, N. Also, we will call the position that is p centimeters from the west end of the flowerbed Position p.
You will plant Flower i (1 ≤ i ≤ N) as follows: first, plant one at Position w_i, then plant one every d_i centimeters endlessly toward the east. That is, Flower i will be planted at the positions w_i, w_i + d_i, w_i + 2 d_i, … Note that more than one flower may be planted at the same position.
Find the position at which the K-th flower from the west is planted. If more than one flower is planted at the same position, they are counted individually.
Constraints
* 1 ≤ N ≤ 10^5
* 1 ≤ K ≤ 10^9
* 1 ≤ w_i ≤ 10^{18}
* 1 ≤ d_i ≤ 10^9
* All input values are integers.
Input
Input is given from Standard Input in the following format:
N K
w_1 d_1
:
w_N d_N
Output
When the K-th flower from the west is planted at Position X, print the value of X. (The westmost flower is counted as the 1-st flower.)
Examples
Input
2 6
20 10
25 15
Output
50
Input
3 9
10 10
10 10
10 10
Output
30
Input
1 1000000000
1000000000000000000 1000000000
Output
1999999999000000000
Submitted Solution:
```
def examA():
N = I()
T = LI()
A = LI()
S = [-1]*N
S[0] = T[0]; S[-1]=A[-1]
ans = 1
for i in range(1,N):
if T[i]==T[i-1]:
continue
S[i] = T[i]
flag = -1
for i in range(N):
if S[i]==A[i]:
flag = i
break
if not (A[flag]==A[0] and A[flag]==T[-1]):
print(0)
return
for i in range(N-1)[::-1]:
if A[i]==A[i+1]:
continue
if S[i]==-1:
S[i] = A[i]
else:
S[i] = max(S[i],A[i])
#print(S)
P = []
pindex = []
for i in range(N):
if S[i]==-1:
continue
P.append(S[i])
pindex.append(i)
flag_U = True
for i in range(len(P)-1):
if P[i+1]>P[i]:
if not flag_U:
print(0)
return
elif P[i+1]<P[i]:
flag_U = False
ans = 1
p = -1
for i in range(N):
if S[i]==-1:
cur = min(P[p + 1], P[p])
ans *= cur
ans %= mod
else:
p += 1
print(ans)
return
def examB():
T = I()
A = LI()
ans = 0
print(ans)
return
def examC():
def dfs(n,s,edges,visited):
cost = BC[s]
now = []
for i in edges[s]:
if visited[i]:
continue
visited[i] = True
cur,visited = dfs(n,i,edges,visited)
now.append((cur, i))
now.sort()
for c,i in now:
cost += c-now[0][0]
children[i] = c-now[0][0]
return cost,visited
N, M = LI()
V = [[]for _ in range(N)]
for i in range(N-1):
p = I()
V[i+1].append(p)
V[p].append(i+1)
children = [-1]*N
BC = defaultdict(int)
for i in range(M):
b, c = LI()
BC[b] = c
visited = [False]*N
visited[0] = True
ans = dfs(N,0,V,visited)
print(children)
print(ans)
return
def examD():
N, K = LI()
W = [LI()for _ in range(N)]
l = 0; r = 10**20
while(r-l>1):
now = (l+r)//2
cur = 0
for i in range(N):
if now>=W[i][0]:
cur += ((now-W[i][0])//W[i][1]+1)
if cur<K:
l = now
else:
r = now
ans = r
print(ans)
return
import sys,copy,bisect,itertools,heapq,math,random
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 10**(-12)
alphabet = [chr(ord('a') + i) for i in range(26)]
if __name__ == '__main__':
examD()
"""
"""
``` | instruction | 0 | 84,887 | 3 | 169,774 |
Yes | output | 1 | 84,887 | 3 | 169,775 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In your garden, there is a long and narrow flowerbed that stretches infinitely to the east. You have decided to plant N kinds of flowers in this empty flowerbed. For convenience, we will call these N kinds of flowers Flower 1, 2, …, N. Also, we will call the position that is p centimeters from the west end of the flowerbed Position p.
You will plant Flower i (1 ≤ i ≤ N) as follows: first, plant one at Position w_i, then plant one every d_i centimeters endlessly toward the east. That is, Flower i will be planted at the positions w_i, w_i + d_i, w_i + 2 d_i, … Note that more than one flower may be planted at the same position.
Find the position at which the K-th flower from the west is planted. If more than one flower is planted at the same position, they are counted individually.
Constraints
* 1 ≤ N ≤ 10^5
* 1 ≤ K ≤ 10^9
* 1 ≤ w_i ≤ 10^{18}
* 1 ≤ d_i ≤ 10^9
* All input values are integers.
Input
Input is given from Standard Input in the following format:
N K
w_1 d_1
:
w_N d_N
Output
When the K-th flower from the west is planted at Position X, print the value of X. (The westmost flower is counted as the 1-st flower.)
Examples
Input
2 6
20 10
25 15
Output
50
Input
3 9
10 10
10 10
10 10
Output
30
Input
1 1000000000
1000000000000000000 1000000000
Output
1999999999000000000
Submitted Solution:
```
# Atcoder problem Solving
# Code Festival Team Relay
import math
N, K = map(int, input().split())
que = [tuple(map(int, input().split())) for _ in range(N)]
def count(X):
cnt = 0
for i in range(N):
w, d = que[i]
if X >= w:
cnt+=(X-w)//d+1
return cnt
# case_impossible
l = -1
# case_possible
r = 10**19
while r-l > 1:
m = (l+r)//2
if count(m) < K:
l = m
else:
r = m
print(r)
``` | instruction | 0 | 84,888 | 3 | 169,776 |
Yes | output | 1 | 84,888 | 3 | 169,777 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In your garden, there is a long and narrow flowerbed that stretches infinitely to the east. You have decided to plant N kinds of flowers in this empty flowerbed. For convenience, we will call these N kinds of flowers Flower 1, 2, …, N. Also, we will call the position that is p centimeters from the west end of the flowerbed Position p.
You will plant Flower i (1 ≤ i ≤ N) as follows: first, plant one at Position w_i, then plant one every d_i centimeters endlessly toward the east. That is, Flower i will be planted at the positions w_i, w_i + d_i, w_i + 2 d_i, … Note that more than one flower may be planted at the same position.
Find the position at which the K-th flower from the west is planted. If more than one flower is planted at the same position, they are counted individually.
Constraints
* 1 ≤ N ≤ 10^5
* 1 ≤ K ≤ 10^9
* 1 ≤ w_i ≤ 10^{18}
* 1 ≤ d_i ≤ 10^9
* All input values are integers.
Input
Input is given from Standard Input in the following format:
N K
w_1 d_1
:
w_N d_N
Output
When the K-th flower from the west is planted at Position X, print the value of X. (The westmost flower is counted as the 1-st flower.)
Examples
Input
2 6
20 10
25 15
Output
50
Input
3 9
10 10
10 10
10 10
Output
30
Input
1 1000000000
1000000000000000000 1000000000
Output
1999999999000000000
Submitted Solution:
```
n, k = map(int, input().split())
kadan = [list(map(int, input().split())) for _ in range(n)]
left = 0
right = 10**18*2
while right -left > 1:
mid = (right+left)//2
cnt = 0
for i in range(n):
if mid >= kadan[i][0]:
cnt += (mid - kadan[i][0])//kadan[i][1] + 1
if k > cnt :
left = mid
elif k <= cnt :
right = mid
print(right)
``` | instruction | 0 | 84,889 | 3 | 169,778 |
Yes | output | 1 | 84,889 | 3 | 169,779 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In your garden, there is a long and narrow flowerbed that stretches infinitely to the east. You have decided to plant N kinds of flowers in this empty flowerbed. For convenience, we will call these N kinds of flowers Flower 1, 2, …, N. Also, we will call the position that is p centimeters from the west end of the flowerbed Position p.
You will plant Flower i (1 ≤ i ≤ N) as follows: first, plant one at Position w_i, then plant one every d_i centimeters endlessly toward the east. That is, Flower i will be planted at the positions w_i, w_i + d_i, w_i + 2 d_i, … Note that more than one flower may be planted at the same position.
Find the position at which the K-th flower from the west is planted. If more than one flower is planted at the same position, they are counted individually.
Constraints
* 1 ≤ N ≤ 10^5
* 1 ≤ K ≤ 10^9
* 1 ≤ w_i ≤ 10^{18}
* 1 ≤ d_i ≤ 10^9
* All input values are integers.
Input
Input is given from Standard Input in the following format:
N K
w_1 d_1
:
w_N d_N
Output
When the K-th flower from the west is planted at Position X, print the value of X. (The westmost flower is counted as the 1-st flower.)
Examples
Input
2 6
20 10
25 15
Output
50
Input
3 9
10 10
10 10
10 10
Output
30
Input
1 1000000000
1000000000000000000 1000000000
Output
1999999999000000000
Submitted Solution:
```
def solve(l, r):
if l > r:
return l
m = (l + r) // 2
t = sum((m - w) // d + 1 for w, d in flowers)
if t < k:
l = m + 1
else:
r = m - 1
return solve(l, r)
n, k = map(int, input().split())
flowers = [tuple(map(int, input().split())) for _ in range(n)]
print(solve(1, flowers[0][0] + flowers[0][1] * k))
``` | instruction | 0 | 84,890 | 3 | 169,780 |
No | output | 1 | 84,890 | 3 | 169,781 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In your garden, there is a long and narrow flowerbed that stretches infinitely to the east. You have decided to plant N kinds of flowers in this empty flowerbed. For convenience, we will call these N kinds of flowers Flower 1, 2, …, N. Also, we will call the position that is p centimeters from the west end of the flowerbed Position p.
You will plant Flower i (1 ≤ i ≤ N) as follows: first, plant one at Position w_i, then plant one every d_i centimeters endlessly toward the east. That is, Flower i will be planted at the positions w_i, w_i + d_i, w_i + 2 d_i, … Note that more than one flower may be planted at the same position.
Find the position at which the K-th flower from the west is planted. If more than one flower is planted at the same position, they are counted individually.
Constraints
* 1 ≤ N ≤ 10^5
* 1 ≤ K ≤ 10^9
* 1 ≤ w_i ≤ 10^{18}
* 1 ≤ d_i ≤ 10^9
* All input values are integers.
Input
Input is given from Standard Input in the following format:
N K
w_1 d_1
:
w_N d_N
Output
When the K-th flower from the west is planted at Position X, print the value of X. (The westmost flower is counted as the 1-st flower.)
Examples
Input
2 6
20 10
25 15
Output
50
Input
3 9
10 10
10 10
10 10
Output
30
Input
1 1000000000
1000000000000000000 1000000000
Output
1999999999000000000
Submitted Solution:
```
# Atcoder problem Solving
# Code Festival Team Relay
import math
N, K = map(int, input().split())
que = [tuple(map(int, input().split())) for _ in range(N)]
def count(X):
cnt = 0
for i in range(N):
w, d = que[i]
if X >= w:
cnt+=(X-w)//d+1
return cnt
# case_impossible
l = -1
# case_possible
r = 10**25
while r-l > 1:
m = (l+r)//2
if count(m) < K:
l = m
else:
r = m
print(r)
``` | instruction | 0 | 84,891 | 3 | 169,782 |
No | output | 1 | 84,891 | 3 | 169,783 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In your garden, there is a long and narrow flowerbed that stretches infinitely to the east. You have decided to plant N kinds of flowers in this empty flowerbed. For convenience, we will call these N kinds of flowers Flower 1, 2, …, N. Also, we will call the position that is p centimeters from the west end of the flowerbed Position p.
You will plant Flower i (1 ≤ i ≤ N) as follows: first, plant one at Position w_i, then plant one every d_i centimeters endlessly toward the east. That is, Flower i will be planted at the positions w_i, w_i + d_i, w_i + 2 d_i, … Note that more than one flower may be planted at the same position.
Find the position at which the K-th flower from the west is planted. If more than one flower is planted at the same position, they are counted individually.
Constraints
* 1 ≤ N ≤ 10^5
* 1 ≤ K ≤ 10^9
* 1 ≤ w_i ≤ 10^{18}
* 1 ≤ d_i ≤ 10^9
* All input values are integers.
Input
Input is given from Standard Input in the following format:
N K
w_1 d_1
:
w_N d_N
Output
When the K-th flower from the west is planted at Position X, print the value of X. (The westmost flower is counted as the 1-st flower.)
Examples
Input
2 6
20 10
25 15
Output
50
Input
3 9
10 10
10 10
10 10
Output
30
Input
1 1000000000
1000000000000000000 1000000000
Output
1999999999000000000
Submitted Solution:
```
import sys
sys.setrecursionlimit(10**8)
input = sys.stdin.readline
n, k = [int(item) for item in input().split()]
wd = []
for i in range(n):
w, d = [int(item) for item in input().split()]
wd.append((w, d))
l = -1; r = 10**20
while r - l > 1:
mid = (l + r) // 2
flower = 0
for w, d in wd:
flower += (mid - w) // d + 1
if flower > k:
break
if flower >= k:
r = mid
else:
l = mid
print(r)
``` | instruction | 0 | 84,892 | 3 | 169,784 |
No | output | 1 | 84,892 | 3 | 169,785 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In your garden, there is a long and narrow flowerbed that stretches infinitely to the east. You have decided to plant N kinds of flowers in this empty flowerbed. For convenience, we will call these N kinds of flowers Flower 1, 2, …, N. Also, we will call the position that is p centimeters from the west end of the flowerbed Position p.
You will plant Flower i (1 ≤ i ≤ N) as follows: first, plant one at Position w_i, then plant one every d_i centimeters endlessly toward the east. That is, Flower i will be planted at the positions w_i, w_i + d_i, w_i + 2 d_i, … Note that more than one flower may be planted at the same position.
Find the position at which the K-th flower from the west is planted. If more than one flower is planted at the same position, they are counted individually.
Constraints
* 1 ≤ N ≤ 10^5
* 1 ≤ K ≤ 10^9
* 1 ≤ w_i ≤ 10^{18}
* 1 ≤ d_i ≤ 10^9
* All input values are integers.
Input
Input is given from Standard Input in the following format:
N K
w_1 d_1
:
w_N d_N
Output
When the K-th flower from the west is planted at Position X, print the value of X. (The westmost flower is counted as the 1-st flower.)
Examples
Input
2 6
20 10
25 15
Output
50
Input
3 9
10 10
10 10
10 10
Output
30
Input
1 1000000000
1000000000000000000 1000000000
Output
1999999999000000000
Submitted Solution:
```
import math
n,k=map(int,input().split())
a=[list(map(int,input().split())) for _ in range(n)]
l,r=-1,10**19
while r-l>1:
m=(l+r)//2
b=0
for w,d in a:
b+=(m-w+d-1)//d
if b<k:
l=m
else:
r=m
print(r+1)
``` | instruction | 0 | 84,893 | 3 | 169,786 |
No | output | 1 | 84,893 | 3 | 169,787 |
Provide a correct Python 3 solution for this coding contest problem.
The huge maze The Squares has been newly completed in the famous theme park. Evacuation drills must be conducted under the guidance of the fire department, but the time required for the drills cannot be predicted due to the huge maze. Therefore, you decided to develop an evacuation drill simulator based on the following specifications.
As shown in Fig. 1, the giant maze is represented by W × H squares of horizontal W and vertical H. Each square is either a passage (white square), a wall (brown square), or an emergency exit (green square). The circles in the figure represent people, and the lowercase letters (E, W, S, N) in them represent the direction in which the person is facing (north, south, east, and west). The figure is drawn with the upward direction facing north.
<image>
Figure 1
People in the giant maze initially stand facing either north, south, east, or west. Each person attempts to move in 1-second increments at the same time, following the steps below.
1. Look at the right, front, left, and back squares in the direction you are currently facing, and turn to the first vacant aisle or emergency exit you find. If there is no such square, the direction will not change.
2. If the square in front of you is open and not in front of another person, move it. If there are multiple people with the same square in front of you, the selected one will move in the order of the people in that square, east, north, west, and south.
Those who arrive at the emergency exit after moving will evacuate safely and disappear from the maze.
Create a program that inputs the given huge maze and the location information of people and outputs the time when all people finish evacuating. If it takes more than 180 seconds to escape, output NA. Maze and person location information is given by the characters in rows H and columns W. The meaning of each character is as follows.
: Wall
.: Floor
X: Emergency exit
E: People facing east
N: People facing north
W: People facing west
S: People facing south
The boundary between the maze and the outside is either the wall # or the emergency exit X. In addition, there is always one or more people in the huge maze.
Input
A sequence of multiple datasets is given as input. The end of the input is indicated by two lines of zeros. Each dataset is given in the following format:
W H
str1
str2
::
strH
The first line gives the horizontal size W of the maze and the vertical size H (1 ≤ W, H ≤ 30). The following H line is given the string stri (length W) that represents the i-th line of the maze.
The number of datasets does not exceed 50.
Output
For each input dataset, the time when all people finish evacuating is output on one line.
Examples
Input
10 3
##########
#E.......X
##########
4 4
####
#N.#
#..X
####
5 5
#####
#N..#
###.X
#S..#
#####
6 6
######
#..#X#
#.EE.#
####N#
#....#
######
8 8
##X#####
#....E.#
#####.##
#.#...##
#.W.#..#
#.#.N#.X
#X##.#.#
########
0 0
Output
8
NA
9
16
10
Input
10 3
E.......X
4 4
N.#
..X
5 5
N..#
.X
S..#
6 6
..#X#
.EE.#
N#
....#
8 8
X#####
....E.#
.##
.#...##
.W.#..#
.#.N#.X
X##.#.#
0 0
Output
8
NA
9
16
10 | instruction | 0 | 84,937 | 3 | 169,874 |
"Correct Solution:
```
from sys import stdin
# from line_profiler import LineProfiler
def main():
head = [[8,1,2,4],[1,2,4,8],[2,4,8,1],[4,8,1,2]]
while(True):
W,H = map(int, stdin.readline().split())
m = [[0]*W for _ in range(H)]
ps = []
if not (W or H): break
for h in range(H):
s = stdin.readline()
for w in range(W):
if s[w] in [".", "X", "E", "N", "W", "S"]:
m[h][max(0,w-1)] |= 1
m[min(H-1,h+1)][w] |= 2
m[h][min(W-1,w+1)] |= 4
m[max(0,h-1)][w] |= 8
if s[w] in ["E", "N", "W", "S"]:
ps.append([h,w,["E", "N", "W", "S"].index(s[w])])
if s[w] == "X":
m[h][w] |= 16
if W <= 2 or H <= 2:
print(1)
continue
ttt = 0
while(True):
ttt += 1
if ttt > 180: print("NA"); break
dest = []
positions = [a[:2] for a in ps]
for pi,p in enumerate(ps):
for i in range(4):
if head[p[2]][i] & m[p[0]][p[1]]:
d = head[p[2]][i]
if d == 1 and not [p[0],p[1]+1] in positions: p[2] = 0; dest.append([pi,2,p[0],p[1]+1]); break
elif d == 2 and not [p[0]-1,p[1]] in positions: p[2] = 1; dest.append([pi,3,p[0]-1,p[1]]); break
elif d == 4 and not [p[0],p[1]-1] in positions: p[2] = 2; dest.append([pi,0,p[0],p[1]-1]); break
elif d == 8 and not [p[0]+1,p[1]] in positions: p[2] = 3; dest.append([pi,1,p[0]+1,p[1]]); break
else:
dest.append([pi,(p[2]+2)&3,p[0],p[1]])
dest = sorted(dest,key=lambda x: (x[2:],x[1]))
dellist = []
for pi,d,dy,dx in dest:
if not [dy,dx] in positions: positions.append([dy,dx]); ps[pi][:2] = [dy,dx]
if m[ps[pi][0]][ps[pi][1]] & 16: dellist.append(pi)
for idx in sorted(dellist)[::-1]: del ps[idx]
if not len(ps): print(ttt); break
if __name__ == "__main__":
# prf = LineProfiler()
# prf.add_function(main)
# prf.runcall(main)
# prf.print_stats()
main()
``` | output | 1 | 84,937 | 3 | 169,875 |
Provide a correct Python 3 solution for this coding contest problem.
The huge maze The Squares has been newly completed in the famous theme park. Evacuation drills must be conducted under the guidance of the fire department, but the time required for the drills cannot be predicted due to the huge maze. Therefore, you decided to develop an evacuation drill simulator based on the following specifications.
As shown in Fig. 1, the giant maze is represented by W × H squares of horizontal W and vertical H. Each square is either a passage (white square), a wall (brown square), or an emergency exit (green square). The circles in the figure represent people, and the lowercase letters (E, W, S, N) in them represent the direction in which the person is facing (north, south, east, and west). The figure is drawn with the upward direction facing north.
<image>
Figure 1
People in the giant maze initially stand facing either north, south, east, or west. Each person attempts to move in 1-second increments at the same time, following the steps below.
1. Look at the right, front, left, and back squares in the direction you are currently facing, and turn to the first vacant aisle or emergency exit you find. If there is no such square, the direction will not change.
2. If the square in front of you is open and not in front of another person, move it. If there are multiple people with the same square in front of you, the selected one will move in the order of the people in that square, east, north, west, and south.
Those who arrive at the emergency exit after moving will evacuate safely and disappear from the maze.
Create a program that inputs the given huge maze and the location information of people and outputs the time when all people finish evacuating. If it takes more than 180 seconds to escape, output NA. Maze and person location information is given by the characters in rows H and columns W. The meaning of each character is as follows.
: Wall
.: Floor
X: Emergency exit
E: People facing east
N: People facing north
W: People facing west
S: People facing south
The boundary between the maze and the outside is either the wall # or the emergency exit X. In addition, there is always one or more people in the huge maze.
Input
A sequence of multiple datasets is given as input. The end of the input is indicated by two lines of zeros. Each dataset is given in the following format:
W H
str1
str2
::
strH
The first line gives the horizontal size W of the maze and the vertical size H (1 ≤ W, H ≤ 30). The following H line is given the string stri (length W) that represents the i-th line of the maze.
The number of datasets does not exceed 50.
Output
For each input dataset, the time when all people finish evacuating is output on one line.
Examples
Input
10 3
##########
#E.......X
##########
4 4
####
#N.#
#..X
####
5 5
#####
#N..#
###.X
#S..#
#####
6 6
######
#..#X#
#.EE.#
####N#
#....#
######
8 8
##X#####
#....E.#
#####.##
#.#...##
#.W.#..#
#.#.N#.X
#X##.#.#
########
0 0
Output
8
NA
9
16
10
Input
10 3
E.......X
4 4
N.#
..X
5 5
N..#
.X
S..#
6 6
..#X#
.EE.#
N#
....#
8 8
X#####
....E.#
.##
.#...##
.W.#..#
.#.N#.X
X##.#.#
0 0
Output
8
NA
9
16
10 | instruction | 0 | 84,938 | 3 | 169,876 |
"Correct Solution:
```
from sys import stdin
from itertools import chain
head = [[8,1,2,4],[1,2,4,8],[2,4,8,1],[4,8,1,2]]
while(True):
W,H = map(int, stdin.readline().split())
m = [[0]*W for _ in range(H)]
ps = []
if not (W or H): break
flag = True
for h in range(H):
s = stdin.readline()
if "X" in s: flag = False
for w in range(W):
if s[w] in [".", "X", "E", "N", "W", "S"]:
m[h][max(0,w-1)] |= 1
m[min(H-1,h+1)][w] |= 2
m[h][min(W-1,w+1)] |= 4
m[max(0,h-1)][w] |= 8
if s[w] in ["E", "N", "W", "S"]:
ps.append([h,w,["E", "N", "W", "S"].index(s[w])])
if s[w] == "X":
m[h][w] |= 16
# if flag:
# print("NA")
# continue
if W <= 2 or H <= 2:
print(1)
continue
# print(ps)
# for n in m:
# print(n)
ttt = 0
while(True):
ttt += 1
if ttt > 180: print("NA"); break
# import time
# time.sleep(1)
mt = [[0]*W for _ in range(H)]
for p in ps:
mt[p[0]][p[1]] |= 1
dest = []
# for mmm in mt:
# print(mmm)
# print()
# print([a[:2] for a in ps])
for pi,p in enumerate(ps):
for i in range(4):
if head[p[2]][i] & m[p[0]][p[1]]:
d = head[p[2]][i]
if d == 1 and not [p[0],p[1]+1] in [a[:2] for a in ps]: p[2] = 0; dest.append([pi,2,p[0],p[1]+1]); break
elif d == 2 and not [p[0]-1,p[1]] in [a[:2] for a in ps]: p[2] = 1; dest.append([pi,3,p[0]-1,p[1]]); break
elif d == 4 and not [p[0],p[1]-1] in [a[:2] for a in ps]: p[2] = 2; dest.append([pi,0,p[0],p[1]-1]); break
elif d == 8 and not [p[0]+1,p[1]] in [a[:2] for a in ps]: p[2] = 3; dest.append([pi,1,p[0]+1,p[1]]); break
else:
dest.append([pi,(p[2]+2)&3,p[0],p[1]])
dest = sorted(dest,key=lambda x: (x[2:],x[1]))
# print(dest)
# for mmm in mt:
# print(mmm)
# print("ps = ",ps,dest)
dellist = []
for pi,d,dy,dx in dest:
# print(W,H,dy,dx,mt)
if not mt[dy][dx]:
# print("move",W,H,ps[pi][:2],dy,dx)
mt[dy][dx] |= 1
ps[pi][:2] = [dy,dx]
if m[ps[pi][0]][ps[pi][1]] & 16:
# print("OUT")
# print(ttt)
# time.sleep(3)
dellist.append(pi)
# print(dellist)
for idx in sorted(dellist)[::-1]:
del ps[idx]
if not len(ps):
print(ttt)
break
# ms = [stdin.readline() for _ in range(H)]
# print(m)
# from pprint import pprint
# print(ps)
# for n in m:
# print(n)
# print()
``` | output | 1 | 84,938 | 3 | 169,877 |
Provide a correct Python 3 solution for this coding contest problem.
The huge maze The Squares has been newly completed in the famous theme park. Evacuation drills must be conducted under the guidance of the fire department, but the time required for the drills cannot be predicted due to the huge maze. Therefore, you decided to develop an evacuation drill simulator based on the following specifications.
As shown in Fig. 1, the giant maze is represented by W × H squares of horizontal W and vertical H. Each square is either a passage (white square), a wall (brown square), or an emergency exit (green square). The circles in the figure represent people, and the lowercase letters (E, W, S, N) in them represent the direction in which the person is facing (north, south, east, and west). The figure is drawn with the upward direction facing north.
<image>
Figure 1
People in the giant maze initially stand facing either north, south, east, or west. Each person attempts to move in 1-second increments at the same time, following the steps below.
1. Look at the right, front, left, and back squares in the direction you are currently facing, and turn to the first vacant aisle or emergency exit you find. If there is no such square, the direction will not change.
2. If the square in front of you is open and not in front of another person, move it. If there are multiple people with the same square in front of you, the selected one will move in the order of the people in that square, east, north, west, and south.
Those who arrive at the emergency exit after moving will evacuate safely and disappear from the maze.
Create a program that inputs the given huge maze and the location information of people and outputs the time when all people finish evacuating. If it takes more than 180 seconds to escape, output NA. Maze and person location information is given by the characters in rows H and columns W. The meaning of each character is as follows.
: Wall
.: Floor
X: Emergency exit
E: People facing east
N: People facing north
W: People facing west
S: People facing south
The boundary between the maze and the outside is either the wall # or the emergency exit X. In addition, there is always one or more people in the huge maze.
Input
A sequence of multiple datasets is given as input. The end of the input is indicated by two lines of zeros. Each dataset is given in the following format:
W H
str1
str2
::
strH
The first line gives the horizontal size W of the maze and the vertical size H (1 ≤ W, H ≤ 30). The following H line is given the string stri (length W) that represents the i-th line of the maze.
The number of datasets does not exceed 50.
Output
For each input dataset, the time when all people finish evacuating is output on one line.
Examples
Input
10 3
##########
#E.......X
##########
4 4
####
#N.#
#..X
####
5 5
#####
#N..#
###.X
#S..#
#####
6 6
######
#..#X#
#.EE.#
####N#
#....#
######
8 8
##X#####
#....E.#
#####.##
#.#...##
#.W.#..#
#.#.N#.X
#X##.#.#
########
0 0
Output
8
NA
9
16
10
Input
10 3
E.......X
4 4
N.#
..X
5 5
N..#
.X
S..#
6 6
..#X#
.EE.#
N#
....#
8 8
X#####
....E.#
.##
.#...##
.W.#..#
.#.N#.X
X##.#.#
0 0
Output
8
NA
9
16
10 | instruction | 0 | 84,939 | 3 | 169,878 |
"Correct Solution:
```
while True:
dic = {"#":-3, ".":-1, "X":-2, "E":0, "N":1, "W":2, "S":3}
def fix(c):
return dic[c]
w, h = map(int, input().split())
if w == 0:
break
mp = [list(map(fix, list(input()))) for _ in range(h)]
persons = []
for y in range(h):
for x in range(w):
if mp[y][x] in (0, 1, 2, 3):
persons.append([x, y, mp[y][x]])
vx = (1, 0, -1, 0)
vy = (0, -1, 0, 1)
time = 0
while time < 180:
if not persons:
print(time)
break
reserve = {}
for index, state in enumerate(persons):
x, y, d = state
for i in range(d - 1, d + 3):
dx, dy = vx[i % 4], vy[i % 4]
if mp[y + dy][x + dx] in (-1, -2):
persons[index][2] = i % 4
if (x + dx, y + dy) in reserve:
if reserve[(x + dx, y + dy)][1] > (i + 2) % 4:
reserve[(x + dx, y + dy)] = (index, (i + 2) % 4, mp[y + dy][x + dx])
else:
reserve[(x + dx, y + dy)] = (index, (i + 2) % 4, mp[y + dy][x + dx])
break
reserve = sorted(reserve.items(), key=lambda a:-a[1][0])
for k, v in reserve:
nx, ny = k
index, nd, panel = v
px, py, _ = persons[index]
mp[py][px] = -1
if panel == -1:
persons[index] = [nx, ny, (nd + 2) % 4]
mp[ny][nx] = (nd + 2) % 4
else:
persons.pop(index)
time += 1
else:
print("NA")
``` | output | 1 | 84,939 | 3 | 169,879 |
Provide a correct Python 3 solution for this coding contest problem.
The huge maze The Squares has been newly completed in the famous theme park. Evacuation drills must be conducted under the guidance of the fire department, but the time required for the drills cannot be predicted due to the huge maze. Therefore, you decided to develop an evacuation drill simulator based on the following specifications.
As shown in Fig. 1, the giant maze is represented by W × H squares of horizontal W and vertical H. Each square is either a passage (white square), a wall (brown square), or an emergency exit (green square). The circles in the figure represent people, and the lowercase letters (E, W, S, N) in them represent the direction in which the person is facing (north, south, east, and west). The figure is drawn with the upward direction facing north.
<image>
Figure 1
People in the giant maze initially stand facing either north, south, east, or west. Each person attempts to move in 1-second increments at the same time, following the steps below.
1. Look at the right, front, left, and back squares in the direction you are currently facing, and turn to the first vacant aisle or emergency exit you find. If there is no such square, the direction will not change.
2. If the square in front of you is open and not in front of another person, move it. If there are multiple people with the same square in front of you, the selected one will move in the order of the people in that square, east, north, west, and south.
Those who arrive at the emergency exit after moving will evacuate safely and disappear from the maze.
Create a program that inputs the given huge maze and the location information of people and outputs the time when all people finish evacuating. If it takes more than 180 seconds to escape, output NA. Maze and person location information is given by the characters in rows H and columns W. The meaning of each character is as follows.
: Wall
.: Floor
X: Emergency exit
E: People facing east
N: People facing north
W: People facing west
S: People facing south
The boundary between the maze and the outside is either the wall # or the emergency exit X. In addition, there is always one or more people in the huge maze.
Input
A sequence of multiple datasets is given as input. The end of the input is indicated by two lines of zeros. Each dataset is given in the following format:
W H
str1
str2
::
strH
The first line gives the horizontal size W of the maze and the vertical size H (1 ≤ W, H ≤ 30). The following H line is given the string stri (length W) that represents the i-th line of the maze.
The number of datasets does not exceed 50.
Output
For each input dataset, the time when all people finish evacuating is output on one line.
Examples
Input
10 3
##########
#E.......X
##########
4 4
####
#N.#
#..X
####
5 5
#####
#N..#
###.X
#S..#
#####
6 6
######
#..#X#
#.EE.#
####N#
#....#
######
8 8
##X#####
#....E.#
#####.##
#.#...##
#.W.#..#
#.#.N#.X
#X##.#.#
########
0 0
Output
8
NA
9
16
10
Input
10 3
E.......X
4 4
N.#
..X
5 5
N..#
.X
S..#
6 6
..#X#
.EE.#
N#
....#
8 8
X#####
....E.#
.##
.#...##
.W.#..#
.#.N#.X
X##.#.#
0 0
Output
8
NA
9
16
10 | instruction | 0 | 84,940 | 3 | 169,880 |
"Correct Solution:
```
dd = ((1, 0), (0, -1), (-1, 0), (0, 1))
ENWS = "ENWS"
ds = [-1, 0, 1, 2]
ss = [2, 3, 0, 1]
while 1:
W, H = map(int, input().split())
if W == H == 0:
break
S = [input() for i in range(H)]
ps = []; U = [[-1]*W for i in range(H)]
for i in range(H):
for j, c in enumerate(S[i]):
if c in ENWS:
ps.append([i, j, ENWS.index(c)])
U[i][j] = 1
elif c == '#':
U[i][j] = W*H
rest = len(ps)
t = 0
while rest > 0 and t <= 180:
for p in ps:
y, x, c = p
if c == -1:
continue
for d in ds:
dx, dy = dd[(c+d) % 4]
nx = x + dx; ny = y + dy
if U[ny][nx] == -1:
p[2] = (c+d) % 4
break
ps.sort(key = lambda x: ss[x[2]])
qs = []
for p in ps:
y, x, c = p
if c == -1:
continue
dx, dy = dd[c]
nx = x + dx; ny = y + dy
if U[ny][nx] == -1:
U[ny][nx] = 1
if S[ny][nx] == 'X':
rest -= 1
p[2] = -1
qs.append((ny, nx))
else:
p[0] = ny; p[1] = nx
qs.append((y, x))
for y, x in qs:
U[y][x] = -1
t += 1
if t <= 180:
print(t)
else:
print("NA")
``` | output | 1 | 84,940 | 3 | 169,881 |
Provide a correct Python 3 solution for this coding contest problem.
The huge maze The Squares has been newly completed in the famous theme park. Evacuation drills must be conducted under the guidance of the fire department, but the time required for the drills cannot be predicted due to the huge maze. Therefore, you decided to develop an evacuation drill simulator based on the following specifications.
As shown in Fig. 1, the giant maze is represented by W × H squares of horizontal W and vertical H. Each square is either a passage (white square), a wall (brown square), or an emergency exit (green square). The circles in the figure represent people, and the lowercase letters (E, W, S, N) in them represent the direction in which the person is facing (north, south, east, and west). The figure is drawn with the upward direction facing north.
<image>
Figure 1
People in the giant maze initially stand facing either north, south, east, or west. Each person attempts to move in 1-second increments at the same time, following the steps below.
1. Look at the right, front, left, and back squares in the direction you are currently facing, and turn to the first vacant aisle or emergency exit you find. If there is no such square, the direction will not change.
2. If the square in front of you is open and not in front of another person, move it. If there are multiple people with the same square in front of you, the selected one will move in the order of the people in that square, east, north, west, and south.
Those who arrive at the emergency exit after moving will evacuate safely and disappear from the maze.
Create a program that inputs the given huge maze and the location information of people and outputs the time when all people finish evacuating. If it takes more than 180 seconds to escape, output NA. Maze and person location information is given by the characters in rows H and columns W. The meaning of each character is as follows.
: Wall
.: Floor
X: Emergency exit
E: People facing east
N: People facing north
W: People facing west
S: People facing south
The boundary between the maze and the outside is either the wall # or the emergency exit X. In addition, there is always one or more people in the huge maze.
Input
A sequence of multiple datasets is given as input. The end of the input is indicated by two lines of zeros. Each dataset is given in the following format:
W H
str1
str2
::
strH
The first line gives the horizontal size W of the maze and the vertical size H (1 ≤ W, H ≤ 30). The following H line is given the string stri (length W) that represents the i-th line of the maze.
The number of datasets does not exceed 50.
Output
For each input dataset, the time when all people finish evacuating is output on one line.
Examples
Input
10 3
##########
#E.......X
##########
4 4
####
#N.#
#..X
####
5 5
#####
#N..#
###.X
#S..#
#####
6 6
######
#..#X#
#.EE.#
####N#
#....#
######
8 8
##X#####
#....E.#
#####.##
#.#...##
#.W.#..#
#.#.N#.X
#X##.#.#
########
0 0
Output
8
NA
9
16
10
Input
10 3
E.......X
4 4
N.#
..X
5 5
N..#
.X
S..#
6 6
..#X#
.EE.#
N#
....#
8 8
X#####
....E.#
.##
.#...##
.W.#..#
.#.N#.X
X##.#.#
0 0
Output
8
NA
9
16
10 | instruction | 0 | 84,941 | 3 | 169,882 |
"Correct Solution:
```
from collections import defaultdict
from typing import Dict
class Players(object):
def __init__(self):
self.players: Dict[int, "Player"] = {}
self.reservation = defaultdict(list)
self.square = None
self.goal = []
def set_goal(self, x, y):
self.goal.append((x, y))
def add(self, player: "Player"):
self.players[len(self.players)] = player
def search_all(self):
for i, player in self.players.items():
x, y, d = player.search(self.square)
self.reservation[(x, y)].append(((d-2)%4, i))
for k, v in self.reservation.items():
if len(v) == 1:
continue
self.reservation[k] = [min(v)]
def move_all(self):
for (x, y), l in self.reservation.items():
_id = l[0][1]
_x, _y = self.players[_id].pos
self.players[_id].move(x, y)
self.square[_y][_x], self.square[y][x] = ".", "o"
self.reservation.clear()
for i, player in self.players.copy().items():
x, y = player.pos
if (x, y) in self.goal:
del self.players[i]
self.square[y][x] = "."
@property
def is_finished(self):
return len(self.players) == 0
class Player(object):
dir_dict = {"E": 0, "N": 1, "W": 2, "S": 3}
dir_diff = ((1, 0), (0, -1), (-1, 0), (0, 1))
def __init__(self, x, y, direction):
self.x = x
self.y = y
self.dir = self.dir_dict[direction]
def search(self, square):
for i in range(self.dir-1, self.dir+3):
dx, dy = self.dir_diff[i % 4]
if square[self.y+dy][self.x+dx] in (".", "X"):
self.dir = i % 4
return self.x+dx, self.y+dy, self.dir
else:
return self.x, self.y, self.dir
def move(self, x, y):
self.x, self.y = x, y
@property
def pos(self):
return self.x, self.y
while True:
W, H = map(int, input().split())
if W == 0:
break
square = []
players = Players()
for y in range(H):
square.append(list(input()))
for x, c in enumerate(square[-1]):
if c in "ENWS":
players.add(Player(x, y, c))
elif c == "X":
players.set_goal(x, y)
players.square = square
for i in range(1, 121):
players.search_all()
players.move_all()
if players.is_finished:
print(i)
break
else:
print("NA")
``` | output | 1 | 84,941 | 3 | 169,883 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The huge maze The Squares has been newly completed in the famous theme park. Evacuation drills must be conducted under the guidance of the fire department, but the time required for the drills cannot be predicted due to the huge maze. Therefore, you decided to develop an evacuation drill simulator based on the following specifications.
As shown in Fig. 1, the giant maze is represented by W × H squares of horizontal W and vertical H. Each square is either a passage (white square), a wall (brown square), or an emergency exit (green square). The circles in the figure represent people, and the lowercase letters (E, W, S, N) in them represent the direction in which the person is facing (north, south, east, and west). The figure is drawn with the upward direction facing north.
<image>
Figure 1
People in the giant maze initially stand facing either north, south, east, or west. Each person attempts to move in 1-second increments at the same time, following the steps below.
1. Look at the right, front, left, and back squares in the direction you are currently facing, and turn to the first vacant aisle or emergency exit you find. If there is no such square, the direction will not change.
2. If the square in front of you is open and not in front of another person, move it. If there are multiple people with the same square in front of you, the selected one will move in the order of the people in that square, east, north, west, and south.
Those who arrive at the emergency exit after moving will evacuate safely and disappear from the maze.
Create a program that inputs the given huge maze and the location information of people and outputs the time when all people finish evacuating. If it takes more than 180 seconds to escape, output NA. Maze and person location information is given by the characters in rows H and columns W. The meaning of each character is as follows.
: Wall
.: Floor
X: Emergency exit
E: People facing east
N: People facing north
W: People facing west
S: People facing south
The boundary between the maze and the outside is either the wall # or the emergency exit X. In addition, there is always one or more people in the huge maze.
Input
A sequence of multiple datasets is given as input. The end of the input is indicated by two lines of zeros. Each dataset is given in the following format:
W H
str1
str2
::
strH
The first line gives the horizontal size W of the maze and the vertical size H (1 ≤ W, H ≤ 30). The following H line is given the string stri (length W) that represents the i-th line of the maze.
The number of datasets does not exceed 50.
Output
For each input dataset, the time when all people finish evacuating is output on one line.
Examples
Input
10 3
##########
#E.......X
##########
4 4
####
#N.#
#..X
####
5 5
#####
#N..#
###.X
#S..#
#####
6 6
######
#..#X#
#.EE.#
####N#
#....#
######
8 8
##X#####
#....E.#
#####.##
#.#...##
#.W.#..#
#.#.N#.X
#X##.#.#
########
0 0
Output
8
NA
9
16
10
Input
10 3
E.......X
4 4
N.#
..X
5 5
N..#
.X
S..#
6 6
..#X#
.EE.#
N#
....#
8 8
X#####
....E.#
.##
.#...##
.W.#..#
.#.N#.X
X##.#.#
0 0
Output
8
NA
9
16
10
Submitted Solution:
```
from sys import stdin
head = [[8,1,2,4],[1,2,4,8],[2,4,8,1],[4,8,1,2]]
while(True):
W,H = map(int, stdin.readline().split())
m = [[0]*W for _ in range(H)]
ps = []
if not (W or H): break
for h in range(H):
s = stdin.readline()
for w in range(W):
if s[w] in [".", "X", "E", "N", "W", "S"]:
m[h][max(0,w-1)] |= 1
m[min(H-1,h+1)][w] |= 2
m[h][min(W-1,w+1)] |= 4
m[max(0,h-1)][w] |= 8
if s[w] in ["E", "N", "W", "S"]:
ps.append([h,w,["E", "N", "W", "S"].index(s[w])])
if s[w] == "X":
m[h][w] |= 16
if W <= 2 or H <= 2:
print(1)
continue
# print(ps)
# for n in m:
# print(n)
ttt = 0
while(True):
ttt += 1
if ttt > 180: print("NA"); break
# import time
# time.sleep(1)
mt = [[0]*W for _ in range(H)]
for p in ps:
mt[p[0]][p[1]] |= 1
dest = []
# for mmm in mt:
# print(mmm)
# print()
# print([a[:2] for a in ps])
for pi,p in enumerate(ps):
for i in range(4):
if head[p[2]][i] & m[p[0]][p[1]]:
d = head[p[2]][i]
if d == 1 and not [p[0],p[1]+1] in [a[:2] for a in ps]: p[2] = 0; dest.append([pi,2,p[0],p[1]+1]); break
elif d == 2 and not [p[0]-1,p[1]] in [a[:2] for a in ps]: p[2] = 1; dest.append([pi,3,p[0]-1,p[1]]); break
elif d == 4 and not [p[0],p[1]-1] in [a[:2] for a in ps]: p[2] = 2; dest.append([pi,0,p[0],p[1]-1]); break
elif d == 8 and not [p[0]+1,p[1]] in [a[:2] for a in ps]: p[2] = 3; dest.append([pi,1,p[0]+1,p[1]]); break
else:
dest.append([pi,(p[2]+2)&3,p[0],p[1]])
# print(dest)
dest = sorted(dest,key=lambda x: (x[2:],x[1]))
# for mmm in mt:
# print(mmm)
# print("ps = ",ps,dest)
dellist = []
for pi,d,dy,dx in dest:
# print(W,H,dy,dx,mt)
if not mt[dy][dx]:
mt[dy][dx] |= 1
ps[pi][:2] = [dy,dx]
if m[dy][dx] & 16:
# print("OUT")
# print(ttt)
# time.sleep(3)
dellist.append(pi)
for idx in sorted(dellist)[::-1]:
del ps[idx]
if not len(ps):
print(ttt)
break
# ms = [stdin.readline() for _ in range(H)]
# print(m)
# from pprint import pprint
# print(ps)
# for n in m:
# print(n)
# print()
``` | instruction | 0 | 84,942 | 3 | 169,884 |
No | output | 1 | 84,942 | 3 | 169,885 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The huge maze The Squares has been newly completed in the famous theme park. Evacuation drills must be conducted under the guidance of the fire department, but the time required for the drills cannot be predicted due to the huge maze. Therefore, you decided to develop an evacuation drill simulator based on the following specifications.
As shown in Fig. 1, the giant maze is represented by W × H squares of horizontal W and vertical H. Each square is either a passage (white square), a wall (brown square), or an emergency exit (green square). The circles in the figure represent people, and the lowercase letters (E, W, S, N) in them represent the direction in which the person is facing (north, south, east, and west). The figure is drawn with the upward direction facing north.
<image>
Figure 1
People in the giant maze initially stand facing either north, south, east, or west. Each person attempts to move in 1-second increments at the same time, following the steps below.
1. Look at the right, front, left, and back squares in the direction you are currently facing, and turn to the first vacant aisle or emergency exit you find. If there is no such square, the direction will not change.
2. If the square in front of you is open and not in front of another person, move it. If there are multiple people with the same square in front of you, the selected one will move in the order of the people in that square, east, north, west, and south.
Those who arrive at the emergency exit after moving will evacuate safely and disappear from the maze.
Create a program that inputs the given huge maze and the location information of people and outputs the time when all people finish evacuating. If it takes more than 180 seconds to escape, output NA. Maze and person location information is given by the characters in rows H and columns W. The meaning of each character is as follows.
: Wall
.: Floor
X: Emergency exit
E: People facing east
N: People facing north
W: People facing west
S: People facing south
The boundary between the maze and the outside is either the wall # or the emergency exit X. In addition, there is always one or more people in the huge maze.
Input
A sequence of multiple datasets is given as input. The end of the input is indicated by two lines of zeros. Each dataset is given in the following format:
W H
str1
str2
::
strH
The first line gives the horizontal size W of the maze and the vertical size H (1 ≤ W, H ≤ 30). The following H line is given the string stri (length W) that represents the i-th line of the maze.
The number of datasets does not exceed 50.
Output
For each input dataset, the time when all people finish evacuating is output on one line.
Examples
Input
10 3
##########
#E.......X
##########
4 4
####
#N.#
#..X
####
5 5
#####
#N..#
###.X
#S..#
#####
6 6
######
#..#X#
#.EE.#
####N#
#....#
######
8 8
##X#####
#....E.#
#####.##
#.#...##
#.W.#..#
#.#.N#.X
#X##.#.#
########
0 0
Output
8
NA
9
16
10
Input
10 3
E.......X
4 4
N.#
..X
5 5
N..#
.X
S..#
6 6
..#X#
.EE.#
N#
....#
8 8
X#####
....E.#
.##
.#...##
.W.#..#
.#.N#.X
X##.#.#
0 0
Output
8
NA
9
16
10
Submitted Solution:
```
from sys import stdin
readline = stdin.readline
from itertools import product
N, W, S, E = (0, -1), (-1, 0), (0, 1), (1, 0)
BLANK = ('.', 'X')
DIRECTION = {
'N': N,
'W': W,
'S': S,
'E': E,
}
check_priority = {
N: (E, N, W, S),
W: (N, W, S, E),
S: (W, S, E, N),
E: (S, E, N, W),
}
step_priority = (E, N, W, S)
def search_people(sq):
people = []
for y, x in product(range(h), range(w)):
if sq[y][x] in DIRECTION:
sq[y][x] = person = Person(x, y, DIRECTION[sq[y][x]], sq)
people.append(person)
return people
class Person:
def __init__(self, x, y, direction, sq):
self.x, self.y = x, y
self.direction = direction
self.sq = sq
self.evacuating = True
def check_direction(self):
for direction in check_priority[self.direction]:
dx, dy = direction
if self.sq[self.y + dy][self.x + dx] in BLANK:
self.direction = direction
break
def check_stepable(self):
dx, dy = self.direction
x, y = self.x + dx, self.y + dy
if self.sq[y][x] == 'X':
self.stepable = True
return
for dx, dy in step_priority:
tmp = self.sq[y + dy][x + dx]
if not isinstance(tmp, Person):
continue
if tmp == self:
self.stepable = True
break
dx, dy = tmp.direction
if tmp.x + dx == x and tmp.y + dy == y:
self.stepable = False
break
def __repr__(self):
return "'P'"
def step(self):
if self.stepable:
dx, dy = self.direction
self.sq[self.y][self.x] = '.'
self.x += dx
self.y += dy
if self.sq[self.y][self.x] == '.':
self.sq[self.y][self.x] = self
else:
self.evacuating = False
while True:
w, h = map(int, readline().split())
if w == 0:
break
squares = [list(readline().strip()) for _ in range(h)]
people = search_people(squares)
for i in range(180):
for pi in people:
pi.check_direction()
for pi in people:
pi.check_stepable()
for pi in people:
pi.step()
people = [pi for pi in people if pi.evacuating]
if len(people) == 0:
print(i + 1)
break
else:
print('NA')
``` | instruction | 0 | 84,943 | 3 | 169,886 |
No | output | 1 | 84,943 | 3 | 169,887 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The huge maze The Squares has been newly completed in the famous theme park. Evacuation drills must be conducted under the guidance of the fire department, but the time required for the drills cannot be predicted due to the huge maze. Therefore, you decided to develop an evacuation drill simulator based on the following specifications.
As shown in Fig. 1, the giant maze is represented by W × H squares of horizontal W and vertical H. Each square is either a passage (white square), a wall (brown square), or an emergency exit (green square). The circles in the figure represent people, and the lowercase letters (E, W, S, N) in them represent the direction in which the person is facing (north, south, east, and west). The figure is drawn with the upward direction facing north.
<image>
Figure 1
People in the giant maze initially stand facing either north, south, east, or west. Each person attempts to move in 1-second increments at the same time, following the steps below.
1. Look at the right, front, left, and back squares in the direction you are currently facing, and turn to the first vacant aisle or emergency exit you find. If there is no such square, the direction will not change.
2. If the square in front of you is open and not in front of another person, move it. If there are multiple people with the same square in front of you, the selected one will move in the order of the people in that square, east, north, west, and south.
Those who arrive at the emergency exit after moving will evacuate safely and disappear from the maze.
Create a program that inputs the given huge maze and the location information of people and outputs the time when all people finish evacuating. If it takes more than 180 seconds to escape, output NA. Maze and person location information is given by the characters in rows H and columns W. The meaning of each character is as follows.
: Wall
.: Floor
X: Emergency exit
E: People facing east
N: People facing north
W: People facing west
S: People facing south
The boundary between the maze and the outside is either the wall # or the emergency exit X. In addition, there is always one or more people in the huge maze.
Input
A sequence of multiple datasets is given as input. The end of the input is indicated by two lines of zeros. Each dataset is given in the following format:
W H
str1
str2
::
strH
The first line gives the horizontal size W of the maze and the vertical size H (1 ≤ W, H ≤ 30). The following H line is given the string stri (length W) that represents the i-th line of the maze.
The number of datasets does not exceed 50.
Output
For each input dataset, the time when all people finish evacuating is output on one line.
Examples
Input
10 3
##########
#E.......X
##########
4 4
####
#N.#
#..X
####
5 5
#####
#N..#
###.X
#S..#
#####
6 6
######
#..#X#
#.EE.#
####N#
#....#
######
8 8
##X#####
#....E.#
#####.##
#.#...##
#.W.#..#
#.#.N#.X
#X##.#.#
########
0 0
Output
8
NA
9
16
10
Input
10 3
E.......X
4 4
N.#
..X
5 5
N..#
.X
S..#
6 6
..#X#
.EE.#
N#
....#
8 8
X#####
....E.#
.##
.#...##
.W.#..#
.#.N#.X
X##.#.#
0 0
Output
8
NA
9
16
10
Submitted Solution:
```
from sys import stdin
readline = stdin.readline
from itertools import product
N, W, S, E = (0, -1), (-1, 0), (0, 1), (1, 0)
BLANK = ('.', 'X')
DIRECTION = {
'N': N,
'W': W,
'S': S,
'E': E,
}
check_priority = {
N: (E, N, W, S),
W: (N, W, S, E),
S: (W, S, E, N),
E: (S, E, N, W),
}
step_priority = (E, N, W, S)
def search_people(sq):
people = []
for y, x in product(range(h), range(w)):
if sq[y][x] in DIRECTION:
sq[y][x] = person = Person(x, y, DIRECTION[sq[y][x]], sq)
people.append(person)
return people
class Person:
def __init__(self, x, y, direction, sq):
self.x, self.y = x, y
self.direction = direction
self.sq = sq
self.evacuating = True
def check_direction(self):
for direction in check_priority[self.direction]:
dx, dy = direction
if self.sq[self.y + dy][self.x + dx] in BLANK:
self.direction = direction
break
def check_stepable(self):
dx, dy = self.direction
x, y = self.x + dx, self.y + dy
if self.sq[y][x] == 'X':
return True
for dx, dy in step_priority:
tmp = self.sq[y + dy][x + dx]
if not isinstance(tmp, Person):
continue
if tmp == self:
self.stepable = True
break
dx, dy = tmp.direction
if tmp.x + dx == x and tmp.y + dy == y:
self.stepable = False
break
def __repr__(self):
return "'P'"
def step(self):
if self.stepable:
dx, dy = self.direction
self.sq[self.y][self.x] = '.'
self.x += dx
self.y += dy
if self.sq[self.y][self.x] == '.':
self.sq[self.y][self.x] = self
else:
self.evacuating = False
while True:
w, h = map(int, readline().split())
if w == 0:
break
squares = [list(readline().strip()) for _ in range(h)]
people = search_people(squares)
for i in range(180):
for pi in people:
pi.check_direction()
for pi in people:
pi.check_stepable()
for pi in people:
pi.step()
people = [pi for pi in people if pi.evacuating]
if len(people) == 0:
print(i + 1)
break
else:
print('NA')
``` | instruction | 0 | 84,944 | 3 | 169,888 |
No | output | 1 | 84,944 | 3 | 169,889 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The huge maze The Squares has been newly completed in the famous theme park. Evacuation drills must be conducted under the guidance of the fire department, but the time required for the drills cannot be predicted due to the huge maze. Therefore, you decided to develop an evacuation drill simulator based on the following specifications.
As shown in Fig. 1, the giant maze is represented by W × H squares of horizontal W and vertical H. Each square is either a passage (white square), a wall (brown square), or an emergency exit (green square). The circles in the figure represent people, and the lowercase letters (E, W, S, N) in them represent the direction in which the person is facing (north, south, east, and west). The figure is drawn with the upward direction facing north.
<image>
Figure 1
People in the giant maze initially stand facing either north, south, east, or west. Each person attempts to move in 1-second increments at the same time, following the steps below.
1. Look at the right, front, left, and back squares in the direction you are currently facing, and turn to the first vacant aisle or emergency exit you find. If there is no such square, the direction will not change.
2. If the square in front of you is open and not in front of another person, move it. If there are multiple people with the same square in front of you, the selected one will move in the order of the people in that square, east, north, west, and south.
Those who arrive at the emergency exit after moving will evacuate safely and disappear from the maze.
Create a program that inputs the given huge maze and the location information of people and outputs the time when all people finish evacuating. If it takes more than 180 seconds to escape, output NA. Maze and person location information is given by the characters in rows H and columns W. The meaning of each character is as follows.
: Wall
.: Floor
X: Emergency exit
E: People facing east
N: People facing north
W: People facing west
S: People facing south
The boundary between the maze and the outside is either the wall # or the emergency exit X. In addition, there is always one or more people in the huge maze.
Input
A sequence of multiple datasets is given as input. The end of the input is indicated by two lines of zeros. Each dataset is given in the following format:
W H
str1
str2
::
strH
The first line gives the horizontal size W of the maze and the vertical size H (1 ≤ W, H ≤ 30). The following H line is given the string stri (length W) that represents the i-th line of the maze.
The number of datasets does not exceed 50.
Output
For each input dataset, the time when all people finish evacuating is output on one line.
Examples
Input
10 3
##########
#E.......X
##########
4 4
####
#N.#
#..X
####
5 5
#####
#N..#
###.X
#S..#
#####
6 6
######
#..#X#
#.EE.#
####N#
#....#
######
8 8
##X#####
#....E.#
#####.##
#.#...##
#.W.#..#
#.#.N#.X
#X##.#.#
########
0 0
Output
8
NA
9
16
10
Input
10 3
E.......X
4 4
N.#
..X
5 5
N..#
.X
S..#
6 6
..#X#
.EE.#
N#
....#
8 8
X#####
....E.#
.##
.#...##
.W.#..#
.#.N#.X
X##.#.#
0 0
Output
8
NA
9
16
10
Submitted Solution:
```
from sys import stdin
head = [[8,1,2,4],[1,2,4,8],[2,4,8,1],[4,8,1,2]]
while(True):
W,H = map(int, stdin.readline().split())
m = [[0]*W for _ in range(H)]
ps = []
if not (W or H): break
for h in range(H):
s = stdin.readline()
for w in range(W):
if s[w] in [".", "X", "E", "N", "W", "S"]:
m[h][max(0,w-1)] |= 1
m[min(H-1,h+1)][w] |= 2
m[h][min(W-1,w+1)] |= 4
m[max(0,h-1)][w] |= 8
if s[w] in ["E", "N", "W", "S"]:
ps.append([h,w,["E", "N", "W", "S"].index(s[w])])
if s[w] == "X":
m[h][w] |= 16
# print(ps)
# for n in m:
# print(n)
ttt = 0
while(True):
ttt += 1
if ttt > 180: print("NA"); break
# import time
# time.sleep(1)
mt = [[0]*W for _ in range(H)]
for p in ps:
mt[p[0]][p[1]] |= 1
dest = []
# for mmm in mt:
# print(mmm)
# print()
# print([a[:2] for a in ps])
for pi,p in enumerate(ps):
for i in range(4):
if head[p[2]][i] & m[p[0]][p[1]]:
d = head[p[2]][i]
if d == 1 and not [p[0],p[1]+1] in [a[:2] for a in ps]: p[2] = 0; dest.append([pi,2,p[0],p[1]+1]); break
elif d == 2 and not [p[0]-1,p[1]] in [a[:2] for a in ps]: p[2] = 1; dest.append([pi,3,p[0]-1,p[1]]); break
elif d == 4 and not [p[0],p[1]-1] in [a[:2] for a in ps]: p[2] = 2; dest.append([pi,0,p[0],p[1]-1]); break
elif d == 8 and not [p[0]+1,p[1]] in [a[:2] for a in ps]: p[2] = 3; dest.append([pi,1,p[0]+1,p[1]]); break
else:
dest.append([pi,(p[2]+2)&3,p[0],p[1]])
# print(dest)
dest = sorted(dest,key=lambda x: (x[2:],x[1]))
# for mmm in mt:
# print(mmm)
# print("ps = ",ps,dest)
dellist = []
for pi,d,dy,dx in dest:
if not mt[dy][dx]:
mt[dy][dx] |= 1
ps[pi][:2] = [dy,dx]
if m[dy][dx] & 16:
# print("OUT")
# print(ttt)
# time.sleep(3)
dellist.append(pi)
for idx in sorted(dellist)[::-1]:
del ps[idx]
if not len(ps):
print(ttt)
break
# ms = [stdin.readline() for _ in range(H)]
# print(m)
# from pprint import pprint
# print(ps)
# for n in m:
# print(n)
# print()
``` | instruction | 0 | 84,945 | 3 | 169,890 |
No | output | 1 | 84,945 | 3 | 169,891 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
This is the story of 20XX. The number of air passengers increased as a result of the stable energy supply by the renewable power network and the invention of liquefied synthetic fuel. However, the threat of terrorism by aircraft still exists, and the importance of fast and highly reliable automatic baggage inspection systems is increasing. Since it is actually difficult for an inspector to inspect all the baggage, we would like to establish a mechanism for the inspector to inspect only the baggage judged to be suspicious by the automatic inspection.
At the request of the aviation industry, the International Cabin Protection Company investigated recent passenger baggage in order to develop a new automated inspection system. As a result of the investigation, it was found that the baggage of recent passengers has the following tendency.
* Baggage is shaped like a rectangular parallelepiped with only one side short.
* Items that ordinary passengers pack in their baggage and bring into the aircraft include laptop computers, music players, handheld game consoles, and playing cards, all of which are rectangular.
* Individual items are packed so that their rectangular sides are parallel to the sides of the baggage.
* On the other hand, weapons such as those used for terrorism have a shape very different from a rectangle.
Based on the above survey results, we devised the following model for baggage inspection. Each piece of baggage is considered to be a rectangular parallelepiped container that is transparent to X-rays. It contains multiple items that are opaque to X-rays. Here, consider a coordinate system with the three sides of the rectangular parallelepiped as the x-axis, y-axis, and z-axis, irradiate X-rays in the direction parallel to the x-axis, and take an image projected on the y-z plane. The captured image is divided into grids of appropriate size, and the material of the item reflected in each grid area is estimated by image analysis. Since this company has a very high level of analysis technology and can analyze even the detailed differences in materials, it can be considered that the materials of the products are different from each other. When multiple items overlap in the x-axis direction, the material of the item that is in the foreground for each lattice region, that is, the item with the smallest x-coordinate is obtained. We also assume that the x-coordinates of two or more items are never equal.
Your job can be asserted that it contains non-rectangular (possibly a weapon) item when given the results of the image analysis, or that the baggage contains anything other than a rectangular item. It is to create a program that determines whether it is presumed that it is not included.
Input
The first line of input contains a single positive integer, which represents the number of datasets. Each dataset is given in the following format.
> H W
> Analysis result 1
> Analysis result 2
> ...
> Analysis result H
>
H is the vertical size of the image, and W is an integer representing the horizontal size (1 <= h, w <= 50). Each line of the analysis result is composed of W characters, and the i-th character represents the analysis result in the grid region i-th from the left of the line. For the lattice region where the substance is detected, the material is represented by uppercase letters (A to Z). At this time, the same characters are used if they are made of the same material, and different characters are used if they are made of different materials. The lattice region where no substance was detected is represented by a dot (.).
For all datasets, it is guaranteed that there are no more than seven material types.
Output
For each data set, output "SUSPICIOUS" if it contains items other than rectangles, and "SAFE" if not, on one line.
Sample Input
6
1 1
..
3 3
...
.W.
...
10 10
..........
.DDDDCC ..
.DDDDCC ..
.DDDDCC ..
ADDDDCCC ..
AAA .. CCC ..
AAABB BBC ..
AAABBBB ...
..BBBBB ...
..........
10 10
..........
.DDDDDD ...
.DDDDCC ..
.DDDDCC ..
ADDDDCCC ..
AAA .. CCC ..
AAABB BBC ..
AAABBBB ...
..BBBBB ...
..........
10 10
R..E..C.T.
R.EEE.C.T.
.EEEEE ....
EEEEEEE ...
.EEEEEEE ..
..EEEEEEE.
... EEEEEEE
.... EEEEE.
..... EEE ..
...... E ...
16 50
.................................................................
......... AAAAAAAAAAAAAAAAA ............................
.... PPP ... AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA .....
.... PPP ... AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA .....
.... PPP ... AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA ....
.... PPP .............. AAAAA.AAAAAAAAAAAAAAAA .......
.... PPP ................ A .... AAA.AAAAAAAAAA ........
.... PPP ........... IIIIIAAIIAIII.AAAAAAAAAA ........
..CCCCCCCCCCCCCC ... IIIIIIAAAAAAAAAAAAAAAAAA ........
..CCCCCCCCCCCCCC ... IIIIIIIIIIIII ... AAAAAAAAAAA ......
.... PPP .................. AAAAAAAAAAA .....
MMMMPPPMMMMMMMMMMMMMMM ............. AAAAAAAAAAA ....
MMMMPPPMMMMMMMMMMMMMMM .............. AAAAAAAAAAA ...
MMMMMMMMMMMMMMMMMMMMMM ............... AAAAAAAAAAA ...
MMMMMMMMMMMMMMMMMMMMMM ............... AAAAAAAAAAA ...
MMMMMMMMMMMMMMMMMMMMMM ............................
Output for the Sample Input
SAFE
SAFE
SAFE
SUSPICIOUS
SUSPICIOUS
SUSPICIOUS
Example
Input
6
1 1
.
3 3
...
.W.
...
10 10
..........
.DDDDCCC..
.DDDDCCC..
.DDDDCCC..
ADDDDCCC..
AAA..CCC..
AAABBBBC..
AAABBBB...
..BBBBB...
..........
10 10
..........
.DDDDDD...
.DDDDCCC..
.DDDDCCC..
ADDDDCCC..
AAA..CCC..
AAABBBBC..
AAABBBB...
..BBBBB...
..........
10 10
R..E..C.T.
R.EEE.C.T.
.EEEEE....
EEEEEEE...
.EEEEEEE..
..EEEEEEE.
...EEEEEEE
....EEEEE.
.....EEE..
......E...
16 50
..................................................
.........AAAAAAAAAAAAAAAA.........................
....PPP...AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA.....
....PPP...AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA.....
....PPP...AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA....
....PPP..............AAAAA.AAAAAAAAAAAAAAAA.......
....PPP................A....AAA.AAAAAAAAAA........
....PPP...........IIIIIAAIIAIII.AAAAAAAAAA........
..CCCCCCCCCCCCC...IIIIIIAAAAAAAAAAAAAAAAAA........
..CCCCCCCCCCCCC...IIIIIIIIIIIII...AAAAAAAAAA......
....PPP............................AAAAAAAAAA.....
MMMMPPPMMMMMMMMMMMMMMM.............AAAAAAAAAAA....
MMMMPPPMMMMMMMMMMMMMMM..............AAAAAAAAAAA...
MMMMMMMMMMMMMMMMMMMMMM...............AAAAAAAAAA...
MMMMMMMMMMMMMMMMMMMMMM...............AAAAAAAAAA...
MMMMMMMMMMMMMMMMMMMMMM............................
Output
SAFE
SAFE
SAFE
SUSPICIOUS
SUSPICIOUS
SUSPICIOUS
Submitted Solution:
```
from itertools import permutations
from collections import defaultdict
def judge(field, c):
for y in xrange(corner[c][2], corner[c][3] + 1):
for x in xrange(corner[c][0], corner[c][1] + 1):
if field[y][x] != c and field[y][x] != "*":
return False
field[y][x] = "*"
return True
N = int(raw_input())
for loop in xrange(N):
h, w = map(int, raw_input().split())
field = [raw_input() for i in xrange(h)]
chars = set([])
corner = defaultdict(lambda :[49,0,49,0])
for y in xrange(h):
for x in xrange(w):
c = field[y][x]
if c == ".": continue
chars.add(c)
corner[c][0] = min(corner[c][0], x)
corner[c][1] = max(corner[c][1], x)
corner[c][2] = min(corner[c][2], y)
corner[c][3] = max(corner[c][3], y)
for order in permutations(chars):
cp = map(list, field)
for c in order:
if not judge(cp, c):
break
else:
print("SAFE")
break
else:
print("SUSPICIOUS")
``` | instruction | 0 | 84,968 | 3 | 169,936 |
No | output | 1 | 84,968 | 3 | 169,937 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
This is the story of 20XX. The number of air passengers increased as a result of the stable energy supply by the renewable power network and the invention of liquefied synthetic fuel. However, the threat of terrorism by aircraft still exists, and the importance of fast and highly reliable automatic baggage inspection systems is increasing. Since it is actually difficult for an inspector to inspect all the baggage, we would like to establish a mechanism for the inspector to inspect only the baggage judged to be suspicious by the automatic inspection.
At the request of the aviation industry, the International Cabin Protection Company investigated recent passenger baggage in order to develop a new automated inspection system. As a result of the investigation, it was found that the baggage of recent passengers has the following tendency.
* Baggage is shaped like a rectangular parallelepiped with only one side short.
* Items that ordinary passengers pack in their baggage and bring into the aircraft include laptop computers, music players, handheld game consoles, and playing cards, all of which are rectangular.
* Individual items are packed so that their rectangular sides are parallel to the sides of the baggage.
* On the other hand, weapons such as those used for terrorism have a shape very different from a rectangle.
Based on the above survey results, we devised the following model for baggage inspection. Each piece of baggage is considered to be a rectangular parallelepiped container that is transparent to X-rays. It contains multiple items that are opaque to X-rays. Here, consider a coordinate system with the three sides of the rectangular parallelepiped as the x-axis, y-axis, and z-axis, irradiate X-rays in the direction parallel to the x-axis, and take an image projected on the y-z plane. The captured image is divided into grids of appropriate size, and the material of the item reflected in each grid area is estimated by image analysis. Since this company has a very high level of analysis technology and can analyze even the detailed differences in materials, it can be considered that the materials of the products are different from each other. When multiple items overlap in the x-axis direction, the material of the item that is in the foreground for each lattice region, that is, the item with the smallest x-coordinate is obtained. We also assume that the x-coordinates of two or more items are never equal.
Your job can be asserted that it contains non-rectangular (possibly a weapon) item when given the results of the image analysis, or that the baggage contains anything other than a rectangular item. It is to create a program that determines whether it is presumed that it is not included.
Input
The first line of input contains a single positive integer, which represents the number of datasets. Each dataset is given in the following format.
> H W
> Analysis result 1
> Analysis result 2
> ...
> Analysis result H
>
H is the vertical size of the image, and W is an integer representing the horizontal size (1 <= h, w <= 50). Each line of the analysis result is composed of W characters, and the i-th character represents the analysis result in the grid region i-th from the left of the line. For the lattice region where the substance is detected, the material is represented by uppercase letters (A to Z). At this time, the same characters are used if they are made of the same material, and different characters are used if they are made of different materials. The lattice region where no substance was detected is represented by a dot (.).
For all datasets, it is guaranteed that there are no more than seven material types.
Output
For each data set, output "SUSPICIOUS" if it contains items other than rectangles, and "SAFE" if not, on one line.
Sample Input
6
1 1
..
3 3
...
.W.
...
10 10
..........
.DDDDCC ..
.DDDDCC ..
.DDDDCC ..
ADDDDCCC ..
AAA .. CCC ..
AAABB BBC ..
AAABBBB ...
..BBBBB ...
..........
10 10
..........
.DDDDDD ...
.DDDDCC ..
.DDDDCC ..
ADDDDCCC ..
AAA .. CCC ..
AAABB BBC ..
AAABBBB ...
..BBBBB ...
..........
10 10
R..E..C.T.
R.EEE.C.T.
.EEEEE ....
EEEEEEE ...
.EEEEEEE ..
..EEEEEEE.
... EEEEEEE
.... EEEEE.
..... EEE ..
...... E ...
16 50
.................................................................
......... AAAAAAAAAAAAAAAAA ............................
.... PPP ... AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA .....
.... PPP ... AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA .....
.... PPP ... AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA ....
.... PPP .............. AAAAA.AAAAAAAAAAAAAAAA .......
.... PPP ................ A .... AAA.AAAAAAAAAA ........
.... PPP ........... IIIIIAAIIAIII.AAAAAAAAAA ........
..CCCCCCCCCCCCCC ... IIIIIIAAAAAAAAAAAAAAAAAA ........
..CCCCCCCCCCCCCC ... IIIIIIIIIIIII ... AAAAAAAAAAA ......
.... PPP .................. AAAAAAAAAAA .....
MMMMPPPMMMMMMMMMMMMMMM ............. AAAAAAAAAAA ....
MMMMPPPMMMMMMMMMMMMMMM .............. AAAAAAAAAAA ...
MMMMMMMMMMMMMMMMMMMMMM ............... AAAAAAAAAAA ...
MMMMMMMMMMMMMMMMMMMMMM ............... AAAAAAAAAAA ...
MMMMMMMMMMMMMMMMMMMMMM ............................
Output for the Sample Input
SAFE
SAFE
SAFE
SUSPICIOUS
SUSPICIOUS
SUSPICIOUS
Example
Input
6
1 1
.
3 3
...
.W.
...
10 10
..........
.DDDDCCC..
.DDDDCCC..
.DDDDCCC..
ADDDDCCC..
AAA..CCC..
AAABBBBC..
AAABBBB...
..BBBBB...
..........
10 10
..........
.DDDDDD...
.DDDDCCC..
.DDDDCCC..
ADDDDCCC..
AAA..CCC..
AAABBBBC..
AAABBBB...
..BBBBB...
..........
10 10
R..E..C.T.
R.EEE.C.T.
.EEEEE....
EEEEEEE...
.EEEEEEE..
..EEEEEEE.
...EEEEEEE
....EEEEE.
.....EEE..
......E...
16 50
..................................................
.........AAAAAAAAAAAAAAAA.........................
....PPP...AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA.....
....PPP...AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA.....
....PPP...AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA....
....PPP..............AAAAA.AAAAAAAAAAAAAAAA.......
....PPP................A....AAA.AAAAAAAAAA........
....PPP...........IIIIIAAIIAIII.AAAAAAAAAA........
..CCCCCCCCCCCCC...IIIIIIAAAAAAAAAAAAAAAAAA........
..CCCCCCCCCCCCC...IIIIIIIIIIIII...AAAAAAAAAA......
....PPP............................AAAAAAAAAA.....
MMMMPPPMMMMMMMMMMMMMMM.............AAAAAAAAAAA....
MMMMPPPMMMMMMMMMMMMMMM..............AAAAAAAAAAA...
MMMMMMMMMMMMMMMMMMMMMM...............AAAAAAAAAA...
MMMMMMMMMMMMMMMMMMMMMM...............AAAAAAAAAA...
MMMMMMMMMMMMMMMMMMMMMM............................
Output
SAFE
SAFE
SAFE
SUSPICIOUS
SUSPICIOUS
SUSPICIOUS
Submitted Solution:
```
class Baggage:
height = 0
width = 0
contentsdata = [[]]
def __init__(self, H, W):
self.height = H
self.width = W
self.contentsdata = [["." for i in range(0, H)] for j in range(0, W)]
def setContents(self, x, y, cnt):
self.contentsdata[x][y] = cnt
def contentscheck(baggage, checkwords): # ????????? => True???????????¢???=> False
left = 10000
right = 10000
up = 1000
bottom = 1000
for x in range(0, baggage.width): # ???????????????????????¨?????????????????????????????????
if(baggage.contentsdata[x].count(checkwords) > 0):
left = x
break
for x in sorted([int(i) for i in range(0, baggage.width)], reverse=True): # ???????????????????????¨?????????????????????????????????
if(baggage.contentsdata[x].count(checkwords) > 0):
right = x
break
for y in range(0, baggage.height): # ???????????????????????¨?????????????????????????????????
for x in range(0, baggage.width):
if(baggage.contentsdata[x][y] == checkwords):
up = y
break
else:
continue
break
for y in sorted([int(i) for i in range(0, baggage.height)], reverse=True): # ???????????????????????¨?????????????????????????????????
for x in range(0, baggage.width):
if(baggage.contentsdata[x][y] == checkwords):
bottom = y
break
else:
continue
break
# print(checkwords + ": (left, right, up, bottom) = (" + str(left) + ", " + str(right) + ", " + str(up) + ", " + str(bottom) + ")")
for x in range(left, right + 1):
for y in range(up, bottom + 1):
if(baggage.contentsdata[x][y] == "."):
return True
break
else:
continue
break
return False
n = int(input())
usedwordslist = []
for k in range(0, n):
try:
size = [int(i) for i in input().split(" ")] # size = [H, W]
checkingbaggage = Baggage(size[0], size[1])
for i in range(0, size[0]):
data = list(input())
for j in range(0, size[1]):
checkingbaggage.contentsdata[j][i] = data[j]
if(data[j] != "." and usedwordslist.count(data[j]) == 0):
usedwordslist.append(data[j])
usedwordslist.sort()
for i in usedwordslist:
if(contentscheck(checkingbaggage, i)):
print("SUSPICIOUS")
break
else:
print("SAFE")
except:
raise
exit()
'''???????????\????¢??????¨
for i in range(0, size[0]):
for j in range(0, size[1]):
print(checkingbaggage.contentsdata[j][i])
print(usedwordslist)'''
usedwordslist.clear()
``` | instruction | 0 | 84,969 | 3 | 169,938 |
No | output | 1 | 84,969 | 3 | 169,939 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
This is the story of 20XX. The number of air passengers increased as a result of the stable energy supply by the renewable power network and the invention of liquefied synthetic fuel. However, the threat of terrorism by aircraft still exists, and the importance of fast and highly reliable automatic baggage inspection systems is increasing. Since it is actually difficult for an inspector to inspect all the baggage, we would like to establish a mechanism for the inspector to inspect only the baggage judged to be suspicious by the automatic inspection.
At the request of the aviation industry, the International Cabin Protection Company investigated recent passenger baggage in order to develop a new automated inspection system. As a result of the investigation, it was found that the baggage of recent passengers has the following tendency.
* Baggage is shaped like a rectangular parallelepiped with only one side short.
* Items that ordinary passengers pack in their baggage and bring into the aircraft include laptop computers, music players, handheld game consoles, and playing cards, all of which are rectangular.
* Individual items are packed so that their rectangular sides are parallel to the sides of the baggage.
* On the other hand, weapons such as those used for terrorism have a shape very different from a rectangle.
Based on the above survey results, we devised the following model for baggage inspection. Each piece of baggage is considered to be a rectangular parallelepiped container that is transparent to X-rays. It contains multiple items that are opaque to X-rays. Here, consider a coordinate system with the three sides of the rectangular parallelepiped as the x-axis, y-axis, and z-axis, irradiate X-rays in the direction parallel to the x-axis, and take an image projected on the y-z plane. The captured image is divided into grids of appropriate size, and the material of the item reflected in each grid area is estimated by image analysis. Since this company has a very high level of analysis technology and can analyze even the detailed differences in materials, it can be considered that the materials of the products are different from each other. When multiple items overlap in the x-axis direction, the material of the item that is in the foreground for each lattice region, that is, the item with the smallest x-coordinate is obtained. We also assume that the x-coordinates of two or more items are never equal.
Your job can be asserted that it contains non-rectangular (possibly a weapon) item when given the results of the image analysis, or that the baggage contains anything other than a rectangular item. It is to create a program that determines whether it is presumed that it is not included.
Input
The first line of input contains a single positive integer, which represents the number of datasets. Each dataset is given in the following format.
> H W
> Analysis result 1
> Analysis result 2
> ...
> Analysis result H
>
H is the vertical size of the image, and W is an integer representing the horizontal size (1 <= h, w <= 50). Each line of the analysis result is composed of W characters, and the i-th character represents the analysis result in the grid region i-th from the left of the line. For the lattice region where the substance is detected, the material is represented by uppercase letters (A to Z). At this time, the same characters are used if they are made of the same material, and different characters are used if they are made of different materials. The lattice region where no substance was detected is represented by a dot (.).
For all datasets, it is guaranteed that there are no more than seven material types.
Output
For each data set, output "SUSPICIOUS" if it contains items other than rectangles, and "SAFE" if not, on one line.
Sample Input
6
1 1
..
3 3
...
.W.
...
10 10
..........
.DDDDCC ..
.DDDDCC ..
.DDDDCC ..
ADDDDCCC ..
AAA .. CCC ..
AAABB BBC ..
AAABBBB ...
..BBBBB ...
..........
10 10
..........
.DDDDDD ...
.DDDDCC ..
.DDDDCC ..
ADDDDCCC ..
AAA .. CCC ..
AAABB BBC ..
AAABBBB ...
..BBBBB ...
..........
10 10
R..E..C.T.
R.EEE.C.T.
.EEEEE ....
EEEEEEE ...
.EEEEEEE ..
..EEEEEEE.
... EEEEEEE
.... EEEEE.
..... EEE ..
...... E ...
16 50
.................................................................
......... AAAAAAAAAAAAAAAAA ............................
.... PPP ... AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA .....
.... PPP ... AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA .....
.... PPP ... AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA ....
.... PPP .............. AAAAA.AAAAAAAAAAAAAAAA .......
.... PPP ................ A .... AAA.AAAAAAAAAA ........
.... PPP ........... IIIIIAAIIAIII.AAAAAAAAAA ........
..CCCCCCCCCCCCCC ... IIIIIIAAAAAAAAAAAAAAAAAA ........
..CCCCCCCCCCCCCC ... IIIIIIIIIIIII ... AAAAAAAAAAA ......
.... PPP .................. AAAAAAAAAAA .....
MMMMPPPMMMMMMMMMMMMMMM ............. AAAAAAAAAAA ....
MMMMPPPMMMMMMMMMMMMMMM .............. AAAAAAAAAAA ...
MMMMMMMMMMMMMMMMMMMMMM ............... AAAAAAAAAAA ...
MMMMMMMMMMMMMMMMMMMMMM ............... AAAAAAAAAAA ...
MMMMMMMMMMMMMMMMMMMMMM ............................
Output for the Sample Input
SAFE
SAFE
SAFE
SUSPICIOUS
SUSPICIOUS
SUSPICIOUS
Example
Input
6
1 1
.
3 3
...
.W.
...
10 10
..........
.DDDDCCC..
.DDDDCCC..
.DDDDCCC..
ADDDDCCC..
AAA..CCC..
AAABBBBC..
AAABBBB...
..BBBBB...
..........
10 10
..........
.DDDDDD...
.DDDDCCC..
.DDDDCCC..
ADDDDCCC..
AAA..CCC..
AAABBBBC..
AAABBBB...
..BBBBB...
..........
10 10
R..E..C.T.
R.EEE.C.T.
.EEEEE....
EEEEEEE...
.EEEEEEE..
..EEEEEEE.
...EEEEEEE
....EEEEE.
.....EEE..
......E...
16 50
..................................................
.........AAAAAAAAAAAAAAAA.........................
....PPP...AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA.....
....PPP...AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA.....
....PPP...AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA....
....PPP..............AAAAA.AAAAAAAAAAAAAAAA.......
....PPP................A....AAA.AAAAAAAAAA........
....PPP...........IIIIIAAIIAIII.AAAAAAAAAA........
..CCCCCCCCCCCCC...IIIIIIAAAAAAAAAAAAAAAAAA........
..CCCCCCCCCCCCC...IIIIIIIIIIIII...AAAAAAAAAA......
....PPP............................AAAAAAAAAA.....
MMMMPPPMMMMMMMMMMMMMMM.............AAAAAAAAAAA....
MMMMPPPMMMMMMMMMMMMMMM..............AAAAAAAAAAA...
MMMMMMMMMMMMMMMMMMMMMM...............AAAAAAAAAA...
MMMMMMMMMMMMMMMMMMMMMM...............AAAAAAAAAA...
MMMMMMMMMMMMMMMMMMMMMM............................
Output
SAFE
SAFE
SAFE
SUSPICIOUS
SUSPICIOUS
SUSPICIOUS
Submitted Solution:
```
class Baggage:
height = 0
width = 0
contentsdata = [[]]
def __init__(self, H, W):
self.height = H
self.width = W
self.contentsdata = [["." for i in range(0, H)] for j in range(0, W)]
def setContents(self, x, y, cnt):
self.contentsdata[x][y] = cnt
def contentscheck(baggage, checkwords): # ????????? => 0???????????¢???????????§???=> 1 ?????¨???????????¢???=> 2
left = 0
right = 0
up = 0
bottom = 0
for x in range(0, baggage.width): # ???????????????????????¨?????????????????????????????????
if(baggage.contentsdata[x].count(checkwords) > 0):
left = x
break
for x in sorted([int(i) for i in range(0, baggage.width)], reverse=True): # ???????????????????????¨?????????????????????????????????
if(baggage.contentsdata[x].count(checkwords) > 0):
right = x
break
for y in range(0, baggage.height): # ???????????????????????¨?????????????????????????????????
for x in range(0, baggage.width):
if(baggage.contentsdata[x][y] == checkwords):
up = y
break
else:
continue
break
for y in sorted([int(i) for i in range(0, baggage.height)], reverse=True): # ???????????????????????¨?????????????????????????????????
for x in range(0, baggage.width):
if(baggage.contentsdata[x][y] == checkwords):
bottom = y
break
else:
continue
break
# print(checkwords + ": (left, right, up, bottom) = (" + str(left) + ", " + str(right) + ", " + str(up) + ", " + str(bottom) + ")")
complite = 1
for x in range(left, right + 1):
for y in range(up, bottom + 1):
# print(checkwords + ":" + baggage.contentsdata[x][y])
if(baggage.contentsdata[x][y] != checkwords):
complite = 0
if(baggage.contentsdata[x][y] == "."):
return 0
break
else:
continue
break
if(complite == 0):
return 1
else:
return 2
n = int(input())
usedwordslist = []
for k in range(0, n):
cmp = False
try:
size = [int(i) for i in input().split(" ")] # size = [H, W]
checkingbaggage = Baggage(size[0], size[1])
for i in range(0, size[0]):
data = list(input())
for j in range(0, size[1]):
checkingbaggage.contentsdata[j][i] = data[j]
if(data[j] != "." and usedwordslist.count(data[j]) == 0):
usedwordslist.append(data[j])
usedwordslist.sort()
for i in usedwordslist:
jdg = int(contentscheck(checkingbaggage, i))
if(jdg == 0):
print("SUSPICIOUS")
break
if(jdg == 2):
cmp = True
else:
print("cmp " + str(cmp))
if(cmp):
print("SAFE")
elif(len(usedwordslist) == 0):
print("SAFE")
else:
print("SUSPICIOUS")
except:
raise
exit()
'''???????????\????¢??????¨
for i in range(0, size[0]):
for j in range(0, size[1]):
print(checkingbaggage.contentsdata[j][i])
print(usedwordslist)'''
usedwordslist.clear()
``` | instruction | 0 | 84,970 | 3 | 169,940 |
No | output | 1 | 84,970 | 3 | 169,941 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
This is the story of 20XX. The number of air passengers increased as a result of the stable energy supply by the renewable power network and the invention of liquefied synthetic fuel. However, the threat of terrorism by aircraft still exists, and the importance of fast and highly reliable automatic baggage inspection systems is increasing. Since it is actually difficult for an inspector to inspect all the baggage, we would like to establish a mechanism for the inspector to inspect only the baggage judged to be suspicious by the automatic inspection.
At the request of the aviation industry, the International Cabin Protection Company investigated recent passenger baggage in order to develop a new automated inspection system. As a result of the investigation, it was found that the baggage of recent passengers has the following tendency.
* Baggage is shaped like a rectangular parallelepiped with only one side short.
* Items that ordinary passengers pack in their baggage and bring into the aircraft include laptop computers, music players, handheld game consoles, and playing cards, all of which are rectangular.
* Individual items are packed so that their rectangular sides are parallel to the sides of the baggage.
* On the other hand, weapons such as those used for terrorism have a shape very different from a rectangle.
Based on the above survey results, we devised the following model for baggage inspection. Each piece of baggage is considered to be a rectangular parallelepiped container that is transparent to X-rays. It contains multiple items that are opaque to X-rays. Here, consider a coordinate system with the three sides of the rectangular parallelepiped as the x-axis, y-axis, and z-axis, irradiate X-rays in the direction parallel to the x-axis, and take an image projected on the y-z plane. The captured image is divided into grids of appropriate size, and the material of the item reflected in each grid area is estimated by image analysis. Since this company has a very high level of analysis technology and can analyze even the detailed differences in materials, it can be considered that the materials of the products are different from each other. When multiple items overlap in the x-axis direction, the material of the item that is in the foreground for each lattice region, that is, the item with the smallest x-coordinate is obtained. We also assume that the x-coordinates of two or more items are never equal.
Your job can be asserted that it contains non-rectangular (possibly a weapon) item when given the results of the image analysis, or that the baggage contains anything other than a rectangular item. It is to create a program that determines whether it is presumed that it is not included.
Input
The first line of input contains a single positive integer, which represents the number of datasets. Each dataset is given in the following format.
> H W
> Analysis result 1
> Analysis result 2
> ...
> Analysis result H
>
H is the vertical size of the image, and W is an integer representing the horizontal size (1 <= h, w <= 50). Each line of the analysis result is composed of W characters, and the i-th character represents the analysis result in the grid region i-th from the left of the line. For the lattice region where the substance is detected, the material is represented by uppercase letters (A to Z). At this time, the same characters are used if they are made of the same material, and different characters are used if they are made of different materials. The lattice region where no substance was detected is represented by a dot (.).
For all datasets, it is guaranteed that there are no more than seven material types.
Output
For each data set, output "SUSPICIOUS" if it contains items other than rectangles, and "SAFE" if not, on one line.
Sample Input
6
1 1
..
3 3
...
.W.
...
10 10
..........
.DDDDCC ..
.DDDDCC ..
.DDDDCC ..
ADDDDCCC ..
AAA .. CCC ..
AAABB BBC ..
AAABBBB ...
..BBBBB ...
..........
10 10
..........
.DDDDDD ...
.DDDDCC ..
.DDDDCC ..
ADDDDCCC ..
AAA .. CCC ..
AAABB BBC ..
AAABBBB ...
..BBBBB ...
..........
10 10
R..E..C.T.
R.EEE.C.T.
.EEEEE ....
EEEEEEE ...
.EEEEEEE ..
..EEEEEEE.
... EEEEEEE
.... EEEEE.
..... EEE ..
...... E ...
16 50
.................................................................
......... AAAAAAAAAAAAAAAAA ............................
.... PPP ... AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA .....
.... PPP ... AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA .....
.... PPP ... AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA ....
.... PPP .............. AAAAA.AAAAAAAAAAAAAAAA .......
.... PPP ................ A .... AAA.AAAAAAAAAA ........
.... PPP ........... IIIIIAAIIAIII.AAAAAAAAAA ........
..CCCCCCCCCCCCCC ... IIIIIIAAAAAAAAAAAAAAAAAA ........
..CCCCCCCCCCCCCC ... IIIIIIIIIIIII ... AAAAAAAAAAA ......
.... PPP .................. AAAAAAAAAAA .....
MMMMPPPMMMMMMMMMMMMMMM ............. AAAAAAAAAAA ....
MMMMPPPMMMMMMMMMMMMMMM .............. AAAAAAAAAAA ...
MMMMMMMMMMMMMMMMMMMMMM ............... AAAAAAAAAAA ...
MMMMMMMMMMMMMMMMMMMMMM ............... AAAAAAAAAAA ...
MMMMMMMMMMMMMMMMMMMMMM ............................
Output for the Sample Input
SAFE
SAFE
SAFE
SUSPICIOUS
SUSPICIOUS
SUSPICIOUS
Example
Input
6
1 1
.
3 3
...
.W.
...
10 10
..........
.DDDDCCC..
.DDDDCCC..
.DDDDCCC..
ADDDDCCC..
AAA..CCC..
AAABBBBC..
AAABBBB...
..BBBBB...
..........
10 10
..........
.DDDDDD...
.DDDDCCC..
.DDDDCCC..
ADDDDCCC..
AAA..CCC..
AAABBBBC..
AAABBBB...
..BBBBB...
..........
10 10
R..E..C.T.
R.EEE.C.T.
.EEEEE....
EEEEEEE...
.EEEEEEE..
..EEEEEEE.
...EEEEEEE
....EEEEE.
.....EEE..
......E...
16 50
..................................................
.........AAAAAAAAAAAAAAAA.........................
....PPP...AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA.....
....PPP...AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA.....
....PPP...AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA....
....PPP..............AAAAA.AAAAAAAAAAAAAAAA.......
....PPP................A....AAA.AAAAAAAAAA........
....PPP...........IIIIIAAIIAIII.AAAAAAAAAA........
..CCCCCCCCCCCCC...IIIIIIAAAAAAAAAAAAAAAAAA........
..CCCCCCCCCCCCC...IIIIIIIIIIIII...AAAAAAAAAA......
....PPP............................AAAAAAAAAA.....
MMMMPPPMMMMMMMMMMMMMMM.............AAAAAAAAAAA....
MMMMPPPMMMMMMMMMMMMMMM..............AAAAAAAAAAA...
MMMMMMMMMMMMMMMMMMMMMM...............AAAAAAAAAA...
MMMMMMMMMMMMMMMMMMMMMM...............AAAAAAAAAA...
MMMMMMMMMMMMMMMMMMMMMM............................
Output
SAFE
SAFE
SAFE
SUSPICIOUS
SUSPICIOUS
SUSPICIOUS
Submitted Solution:
```
class Baggage:
height = 0
width = 0
contentsdata = [[]]
def __init__(self, H, W):
self.height = H
self.width = W
self.contentsdata = [["." for i in range(0, H)] for j in range(0, W)]
def setContents(self, x, y, cnt):
self.contentsdata[x][y] = cnt
def contentscheck(baggage, checkwords): # ????????? => 0???????????¢???????????§???=> 1 ?????¨???????????¢???=> 2
left = 0
right = 0
up = 0
bottom = 0
for x in range(0, baggage.width): # ???????????????????????¨?????????????????????????????????
if(baggage.contentsdata[x].count(checkwords) > 0):
left = x
break
for x in sorted([int(i) for i in range(0, baggage.width)], reverse=True): # ???????????????????????¨?????????????????????????????????
if(baggage.contentsdata[x].count(checkwords) > 0):
right = x
break
for y in range(0, baggage.height): # ???????????????????????¨?????????????????????????????????
for x in range(0, baggage.width):
if(baggage.contentsdata[x][y] == checkwords):
up = y
break
else:
continue
break
for y in sorted([int(i) for i in range(0, baggage.height)], reverse=True): # ???????????????????????¨?????????????????????????????????
for x in range(0, baggage.width):
if(baggage.contentsdata[x][y] == checkwords):
bottom = y
break
else:
continue
break
# print(checkwords + ": (left, right, up, bottom) = (" + str(left) + ", " + str(right) + ", " + str(up) + ", " + str(bottom) + ")")
complite = 1
for x in range(left, right + 1):
for y in range(up, bottom + 1):
# print(checkwords + ":" + baggage.contentsdata[x][y])
if(baggage.contentsdata[x][y] != checkwords):
complite = 0
if(baggage.contentsdata[x][y] == "."):
return 0
break
else:
continue
break
if(complite == 0):
return 1
else:
return 2
n = int(input())
usedwordslist = []
for k in range(0, n):
cmp = False
try:
size = [int(i) for i in input().split(" ")] # size = [H, W]
checkingbaggage = Baggage(size[0], size[1])
for i in range(0, size[0]):
data = list(input())
for j in range(0, size[1]):
checkingbaggage.contentsdata[j][i] = data[j]
if(data[j] != "." and usedwordslist.count(data[j]) == 0):
usedwordslist.append(data[j])
usedwordslist.sort()
for i in usedwordslist:
jdg = int(contentscheck(checkingbaggage, i))
if(jdg == 0):
print("SUSPICIOUS")
break
if(jdg == 2):
cmp = True
else:
if(cmp):
print("SAFE")
elif(len(usedwordslist) == 0):
print("SAFE")
else:
print("SUSPICIOUS")
except:
raise
exit()
'''???????????\????¢??????¨
for i in range(0, size[0]):
for j in range(0, size[1]):
print(checkingbaggage.contentsdata[j][i])
print(usedwordslist)'''
usedwordslist.clear()
``` | instruction | 0 | 84,971 | 3 | 169,942 |
No | output | 1 | 84,971 | 3 | 169,943 |
Provide tags and a correct Python 3 solution for this coding contest problem.
We have a point A with coordinate x = n on OX-axis. We'd like to find an integer point B (also on OX-axis), such that the absolute difference between the distance from O to B and the distance from A to B is equal to k.
<image> The description of the first test case.
Since sometimes it's impossible to find such point B, we can, in one step, increase or decrease the coordinate of A by 1. What is the minimum number of steps we should do to make such point B exist?
Input
The first line contains one integer t (1 ≤ t ≤ 6000) — the number of test cases.
The only line of each test case contains two integers n and k (0 ≤ n, k ≤ 10^6) — the initial position of point A and desirable absolute difference.
Output
For each test case, print the minimum number of steps to make point B exist.
Example
Input
6
4 0
5 8
0 1000000
0 0
1 0
1000000 1000000
Output
0
3
1000000
0
1
0
Note
In the first test case (picture above), if we set the coordinate of B as 2 then the absolute difference will be equal to |(2 - 0) - (4 - 2)| = 0 and we don't have to move A. So the answer is 0.
In the second test case, we can increase the coordinate of A by 3 and set the coordinate of B as 0 or 8. The absolute difference will be equal to |8 - 0| = 8, so the answer is 3.
<image> | instruction | 0 | 85,183 | 3 | 170,366 |
Tags: constructive algorithms, math
Correct Solution:
```
try:
for _ in range(int(input())):
n,k=map(int,input().split())
if n==0:
print(k)
continue
if k==0:
if n%2==0:
print(0)
continue
else:
print(1)
continue
if n==k:
print(0)
continue
if k>n:
print(k-n)
continue
if k<n:
if n%2==0:
if k%2==0:
print(0)
else:
print(1)
else:
if k%2==0:
print(1)
else:
print(0)
except:
pass
``` | output | 1 | 85,183 | 3 | 170,367 |
Provide tags and a correct Python 3 solution for this coding contest problem.
We have a point A with coordinate x = n on OX-axis. We'd like to find an integer point B (also on OX-axis), such that the absolute difference between the distance from O to B and the distance from A to B is equal to k.
<image> The description of the first test case.
Since sometimes it's impossible to find such point B, we can, in one step, increase or decrease the coordinate of A by 1. What is the minimum number of steps we should do to make such point B exist?
Input
The first line contains one integer t (1 ≤ t ≤ 6000) — the number of test cases.
The only line of each test case contains two integers n and k (0 ≤ n, k ≤ 10^6) — the initial position of point A and desirable absolute difference.
Output
For each test case, print the minimum number of steps to make point B exist.
Example
Input
6
4 0
5 8
0 1000000
0 0
1 0
1000000 1000000
Output
0
3
1000000
0
1
0
Note
In the first test case (picture above), if we set the coordinate of B as 2 then the absolute difference will be equal to |(2 - 0) - (4 - 2)| = 0 and we don't have to move A. So the answer is 0.
In the second test case, we can increase the coordinate of A by 3 and set the coordinate of B as 0 or 8. The absolute difference will be equal to |8 - 0| = 8, so the answer is 3.
<image> | instruction | 0 | 85,184 | 3 | 170,368 |
Tags: constructive algorithms, math
Correct Solution:
```
t = int(input())
for i in range(t):
a, b = input().split(" ")
n = int(a)
k = int(b)
steps = 0
s = n // 2
t = n % 2
t2 = k % 2
if t == t2:
if t == 1:
k -= 1
else:
pass
else:
if t == 1:
steps += 1
s += 1
else:
steps += 1
k -= 1
if 2*s < k:
steps += k - 2*s
print(steps)
``` | output | 1 | 85,184 | 3 | 170,369 |
Provide tags and a correct Python 3 solution for this coding contest problem.
We have a point A with coordinate x = n on OX-axis. We'd like to find an integer point B (also on OX-axis), such that the absolute difference between the distance from O to B and the distance from A to B is equal to k.
<image> The description of the first test case.
Since sometimes it's impossible to find such point B, we can, in one step, increase or decrease the coordinate of A by 1. What is the minimum number of steps we should do to make such point B exist?
Input
The first line contains one integer t (1 ≤ t ≤ 6000) — the number of test cases.
The only line of each test case contains two integers n and k (0 ≤ n, k ≤ 10^6) — the initial position of point A and desirable absolute difference.
Output
For each test case, print the minimum number of steps to make point B exist.
Example
Input
6
4 0
5 8
0 1000000
0 0
1 0
1000000 1000000
Output
0
3
1000000
0
1
0
Note
In the first test case (picture above), if we set the coordinate of B as 2 then the absolute difference will be equal to |(2 - 0) - (4 - 2)| = 0 and we don't have to move A. So the answer is 0.
In the second test case, we can increase the coordinate of A by 3 and set the coordinate of B as 0 or 8. The absolute difference will be equal to |8 - 0| = 8, so the answer is 3.
<image> | instruction | 0 | 85,187 | 3 | 170,374 |
Tags: constructive algorithms, math
Correct Solution:
```
import math
t=int(input())
#n=t
while t>0:
t-=1
s=list(map(int,input().split()));
n=s[0]
k=s[1]
if(k>=n):
print(k-n)
elif k<n:
print((n-k)%2)
``` | output | 1 | 85,187 | 3 | 170,375 |
Provide tags and a correct Python 3 solution for this coding contest problem.
We have a point A with coordinate x = n on OX-axis. We'd like to find an integer point B (also on OX-axis), such that the absolute difference between the distance from O to B and the distance from A to B is equal to k.
<image> The description of the first test case.
Since sometimes it's impossible to find such point B, we can, in one step, increase or decrease the coordinate of A by 1. What is the minimum number of steps we should do to make such point B exist?
Input
The first line contains one integer t (1 ≤ t ≤ 6000) — the number of test cases.
The only line of each test case contains two integers n and k (0 ≤ n, k ≤ 10^6) — the initial position of point A and desirable absolute difference.
Output
For each test case, print the minimum number of steps to make point B exist.
Example
Input
6
4 0
5 8
0 1000000
0 0
1 0
1000000 1000000
Output
0
3
1000000
0
1
0
Note
In the first test case (picture above), if we set the coordinate of B as 2 then the absolute difference will be equal to |(2 - 0) - (4 - 2)| = 0 and we don't have to move A. So the answer is 0.
In the second test case, we can increase the coordinate of A by 3 and set the coordinate of B as 0 or 8. The absolute difference will be equal to |8 - 0| = 8, so the answer is 3.
<image> | instruction | 0 | 85,189 | 3 | 170,378 |
Tags: constructive algorithms, math
Correct Solution:
```
for _ in range(int(input())):
n, k = [int(i) for i in input().split()]
if k>=n:
print(k-n)
else:
print(int(n%2!=k%2))
``` | output | 1 | 85,189 | 3 | 170,379 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We have a point A with coordinate x = n on OX-axis. We'd like to find an integer point B (also on OX-axis), such that the absolute difference between the distance from O to B and the distance from A to B is equal to k.
<image> The description of the first test case.
Since sometimes it's impossible to find such point B, we can, in one step, increase or decrease the coordinate of A by 1. What is the minimum number of steps we should do to make such point B exist?
Input
The first line contains one integer t (1 ≤ t ≤ 6000) — the number of test cases.
The only line of each test case contains two integers n and k (0 ≤ n, k ≤ 10^6) — the initial position of point A and desirable absolute difference.
Output
For each test case, print the minimum number of steps to make point B exist.
Example
Input
6
4 0
5 8
0 1000000
0 0
1 0
1000000 1000000
Output
0
3
1000000
0
1
0
Note
In the first test case (picture above), if we set the coordinate of B as 2 then the absolute difference will be equal to |(2 - 0) - (4 - 2)| = 0 and we don't have to move A. So the answer is 0.
In the second test case, we can increase the coordinate of A by 3 and set the coordinate of B as 0 or 8. The absolute difference will be equal to |8 - 0| = 8, so the answer is 3.
<image>
Submitted Solution:
```
n=int(input())
for i in range(n):
a,b=map(int,input().split())
if b>=a:
print(b-a)
elif a%2==1 and b%2==0 or a%2==0 and b%2==1:
print(1)
else:
print(0)
``` | instruction | 0 | 85,191 | 3 | 170,382 |
Yes | output | 1 | 85,191 | 3 | 170,383 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We have a point A with coordinate x = n on OX-axis. We'd like to find an integer point B (also on OX-axis), such that the absolute difference between the distance from O to B and the distance from A to B is equal to k.
<image> The description of the first test case.
Since sometimes it's impossible to find such point B, we can, in one step, increase or decrease the coordinate of A by 1. What is the minimum number of steps we should do to make such point B exist?
Input
The first line contains one integer t (1 ≤ t ≤ 6000) — the number of test cases.
The only line of each test case contains two integers n and k (0 ≤ n, k ≤ 10^6) — the initial position of point A and desirable absolute difference.
Output
For each test case, print the minimum number of steps to make point B exist.
Example
Input
6
4 0
5 8
0 1000000
0 0
1 0
1000000 1000000
Output
0
3
1000000
0
1
0
Note
In the first test case (picture above), if we set the coordinate of B as 2 then the absolute difference will be equal to |(2 - 0) - (4 - 2)| = 0 and we don't have to move A. So the answer is 0.
In the second test case, we can increase the coordinate of A by 3 and set the coordinate of B as 0 or 8. The absolute difference will be equal to |8 - 0| = 8, so the answer is 3.
<image>
Submitted Solution:
```
t=int(input())
for i in range(t):
n,k=map(int,input().split())
b=(n-k)/2
if n>k :
if n%2==0 and k%2==0 or n%2!=0 and k%2!=0:
print('0')
else:
print('1')
elif n==k:
print('0')
else:
print(k-n)
``` | instruction | 0 | 85,192 | 3 | 170,384 |
Yes | output | 1 | 85,192 | 3 | 170,385 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We have a point A with coordinate x = n on OX-axis. We'd like to find an integer point B (also on OX-axis), such that the absolute difference between the distance from O to B and the distance from A to B is equal to k.
<image> The description of the first test case.
Since sometimes it's impossible to find such point B, we can, in one step, increase or decrease the coordinate of A by 1. What is the minimum number of steps we should do to make such point B exist?
Input
The first line contains one integer t (1 ≤ t ≤ 6000) — the number of test cases.
The only line of each test case contains two integers n and k (0 ≤ n, k ≤ 10^6) — the initial position of point A and desirable absolute difference.
Output
For each test case, print the minimum number of steps to make point B exist.
Example
Input
6
4 0
5 8
0 1000000
0 0
1 0
1000000 1000000
Output
0
3
1000000
0
1
0
Note
In the first test case (picture above), if we set the coordinate of B as 2 then the absolute difference will be equal to |(2 - 0) - (4 - 2)| = 0 and we don't have to move A. So the answer is 0.
In the second test case, we can increase the coordinate of A by 3 and set the coordinate of B as 0 or 8. The absolute difference will be equal to |8 - 0| = 8, so the answer is 3.
<image>
Submitted Solution:
```
t = int(input())
while t:
t -= 1
n, k = map(int, input().split())
if n==k:
print(0)
elif n<k:
print(k-n)
elif k==0:
if n%2==0:
print(0)
else:
print(1)
else:
if (n%2==0 and k%2==0) or (n%2!=0 and k%2!=0):
print(0)
else:
print(1)
``` | instruction | 0 | 85,193 | 3 | 170,386 |
Yes | output | 1 | 85,193 | 3 | 170,387 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We have a point A with coordinate x = n on OX-axis. We'd like to find an integer point B (also on OX-axis), such that the absolute difference between the distance from O to B and the distance from A to B is equal to k.
<image> The description of the first test case.
Since sometimes it's impossible to find such point B, we can, in one step, increase or decrease the coordinate of A by 1. What is the minimum number of steps we should do to make such point B exist?
Input
The first line contains one integer t (1 ≤ t ≤ 6000) — the number of test cases.
The only line of each test case contains two integers n and k (0 ≤ n, k ≤ 10^6) — the initial position of point A and desirable absolute difference.
Output
For each test case, print the minimum number of steps to make point B exist.
Example
Input
6
4 0
5 8
0 1000000
0 0
1 0
1000000 1000000
Output
0
3
1000000
0
1
0
Note
In the first test case (picture above), if we set the coordinate of B as 2 then the absolute difference will be equal to |(2 - 0) - (4 - 2)| = 0 and we don't have to move A. So the answer is 0.
In the second test case, we can increase the coordinate of A by 3 and set the coordinate of B as 0 or 8. The absolute difference will be equal to |8 - 0| = 8, so the answer is 3.
<image>
Submitted Solution:
```
for i in range(int(input())):
n,k=[int(num) for num in input().split()]
c=(n+k)//2
if c<=n and c!=0:
print(0)
else:
print(abs(n-k))
``` | instruction | 0 | 85,195 | 3 | 170,390 |
No | output | 1 | 85,195 | 3 | 170,391 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We have a point A with coordinate x = n on OX-axis. We'd like to find an integer point B (also on OX-axis), such that the absolute difference between the distance from O to B and the distance from A to B is equal to k.
<image> The description of the first test case.
Since sometimes it's impossible to find such point B, we can, in one step, increase or decrease the coordinate of A by 1. What is the minimum number of steps we should do to make such point B exist?
Input
The first line contains one integer t (1 ≤ t ≤ 6000) — the number of test cases.
The only line of each test case contains two integers n and k (0 ≤ n, k ≤ 10^6) — the initial position of point A and desirable absolute difference.
Output
For each test case, print the minimum number of steps to make point B exist.
Example
Input
6
4 0
5 8
0 1000000
0 0
1 0
1000000 1000000
Output
0
3
1000000
0
1
0
Note
In the first test case (picture above), if we set the coordinate of B as 2 then the absolute difference will be equal to |(2 - 0) - (4 - 2)| = 0 and we don't have to move A. So the answer is 0.
In the second test case, we can increase the coordinate of A by 3 and set the coordinate of B as 0 or 8. The absolute difference will be equal to |8 - 0| = 8, so the answer is 3.
<image>
Submitted Solution:
```
for t in range(int(input())):
a,b= map(int,input().split())
if b>=a:
print(b-a)
else:
if b==0:
print(a%2)
else:
print(min(2*b-a%(2*b),a%(2*b)))
``` | instruction | 0 | 85,196 | 3 | 170,392 |
No | output | 1 | 85,196 | 3 | 170,393 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We have a point A with coordinate x = n on OX-axis. We'd like to find an integer point B (also on OX-axis), such that the absolute difference between the distance from O to B and the distance from A to B is equal to k.
<image> The description of the first test case.
Since sometimes it's impossible to find such point B, we can, in one step, increase or decrease the coordinate of A by 1. What is the minimum number of steps we should do to make such point B exist?
Input
The first line contains one integer t (1 ≤ t ≤ 6000) — the number of test cases.
The only line of each test case contains two integers n and k (0 ≤ n, k ≤ 10^6) — the initial position of point A and desirable absolute difference.
Output
For each test case, print the minimum number of steps to make point B exist.
Example
Input
6
4 0
5 8
0 1000000
0 0
1 0
1000000 1000000
Output
0
3
1000000
0
1
0
Note
In the first test case (picture above), if we set the coordinate of B as 2 then the absolute difference will be equal to |(2 - 0) - (4 - 2)| = 0 and we don't have to move A. So the answer is 0.
In the second test case, we can increase the coordinate of A by 3 and set the coordinate of B as 0 or 8. The absolute difference will be equal to |8 - 0| = 8, so the answer is 3.
<image>
Submitted Solution:
```
for i in range(int(input())):
n,k=[int(num) for num in input().split()]
c=(n+k)//2
if c<=n and n<=k:
print(0)
else:
print(abs(n-k))
``` | instruction | 0 | 85,197 | 3 | 170,394 |
No | output | 1 | 85,197 | 3 | 170,395 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We have a point A with coordinate x = n on OX-axis. We'd like to find an integer point B (also on OX-axis), such that the absolute difference between the distance from O to B and the distance from A to B is equal to k.
<image> The description of the first test case.
Since sometimes it's impossible to find such point B, we can, in one step, increase or decrease the coordinate of A by 1. What is the minimum number of steps we should do to make such point B exist?
Input
The first line contains one integer t (1 ≤ t ≤ 6000) — the number of test cases.
The only line of each test case contains two integers n and k (0 ≤ n, k ≤ 10^6) — the initial position of point A and desirable absolute difference.
Output
For each test case, print the minimum number of steps to make point B exist.
Example
Input
6
4 0
5 8
0 1000000
0 0
1 0
1000000 1000000
Output
0
3
1000000
0
1
0
Note
In the first test case (picture above), if we set the coordinate of B as 2 then the absolute difference will be equal to |(2 - 0) - (4 - 2)| = 0 and we don't have to move A. So the answer is 0.
In the second test case, we can increase the coordinate of A by 3 and set the coordinate of B as 0 or 8. The absolute difference will be equal to |8 - 0| = 8, so the answer is 3.
<image>
Submitted Solution:
```
def f(a,b):
if a%2==1 and b%2 == 1:
return f(a-1,b-1)
if a%2==1 or b%2==1:
return 1+f(a+1,b)
if 2*b >= a:
return 2*b-a
else:
return 0
for t in range(int(input())):
a,b= map(int,input().split())
if b>=a:
print(b-a)
else:
if b==0:
print(a%2)
else:
print(f(a,b))
``` | instruction | 0 | 85,198 | 3 | 170,396 |
No | output | 1 | 85,198 | 3 | 170,397 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Professor Bajtocy is conducting experiments on alien DNA. He has discovered that it is subject to repetitive mutations — each mutation happens in the same way: some continuous subsequence of the alien DNA becomes active, copies itself, the copy gets mangled and inserts itself right after the original subsequence. The mangled copy of the activated continuous subsequence is formed by first joining all the elements at the even positions in that subsequence, and then joining all the elements at the odd ones at the end. That is, if the activated subsequence consists of 11 elements and represented as s1s2... s11, its mangled copy is s2s4s6s8s10s1s3s5s7s9s11.
For example, if the original sequence was "ACTGG" and the mutation happened on the segment [2, 4] (that is the activated subsequence is "CTG"), the mutated DNA is: "ACTGTCGG". The mangled copy of the activated subsequence is marked with bold font.
Professor Bajtocy has written down the original DNA sequence and the mutations that sequentially happened to it, and he now asks you to recover the first k elements of the DNA sequence after all the mutations.
Input
The first line of input contains the original DNA sequence, consisting only of letters "A", "C", "T" and "G" and not exceeding 3·106 in length.
The second line contains a single integer k (1 ≤ k ≤ 3·106).
The third line contains a single integer n (0 ≤ n ≤ 5000) — the number of mutations. The next n lines describe the mutations in chronological order — each mutation is described by two numbers li and ri (1 ≤ li ≤ ri ≤ 109), meaning that the continuous subsequence [li, ri] has become active and cloned itself, joining itself with the mangled copy.
It is guaranteed that the input data is correct, that is, no mutation acts on non-existing elements of the DNA sequence, and the resulting DNA sequence has at least k elements.
Assume that the DNA elements are indexed starting from 1 and that the notation [l, r] meaning the continuous subsequence of DNA sequence that consists of r - l + 1 elements starting at the l-th DNA sequence element and ending at the r-th DNA sequence element.
Output
Output a single line, containing the first k letters of the mutated DNA sequence.
Examples
Input
GAGA
4
0
Output
GAGA
Input
ACGTACGT
16
2
1 2
2 8
Output
ACCAGTACCGACATCG
Note
In the second example, after the first mutation the sequence is "ACCAGTACGT". After the second mutation it's "ACCAGTACCGACATCGT".
Submitted Solution:
```
dna = input()
k = int(input())
n = int(input())
def mutation(word,start,end):
changed = word[start-1:end]
is_even_number = lambda x: x%2 == 0
is_odd_number = lambda x: x%2 != 0
changed_word = list(filter(is_even_number,range(1,len(changed)+1))) + list(filter(is_odd_number,range(1,len(changed)+1)))
changed_word = ''.join(list(map(lambda x:changed[x-1],changed_word)))
new_word = word[:end] + changed_word + word[end:]
return new_word
for i in range(n):
a,b = list(map(int,input().split()))
if a >= k:
continue
dna = mutation(dna[:k],a,b)
print (dna)
``` | instruction | 0 | 85,270 | 3 | 170,540 |
No | output | 1 | 85,270 | 3 | 170,541 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Professor Bajtocy is conducting experiments on alien DNA. He has discovered that it is subject to repetitive mutations — each mutation happens in the same way: some continuous subsequence of the alien DNA becomes active, copies itself, the copy gets mangled and inserts itself right after the original subsequence. The mangled copy of the activated continuous subsequence is formed by first joining all the elements at the even positions in that subsequence, and then joining all the elements at the odd ones at the end. That is, if the activated subsequence consists of 11 elements and represented as s1s2... s11, its mangled copy is s2s4s6s8s10s1s3s5s7s9s11.
For example, if the original sequence was "ACTGG" and the mutation happened on the segment [2, 4] (that is the activated subsequence is "CTG"), the mutated DNA is: "ACTGTCGG". The mangled copy of the activated subsequence is marked with bold font.
Professor Bajtocy has written down the original DNA sequence and the mutations that sequentially happened to it, and he now asks you to recover the first k elements of the DNA sequence after all the mutations.
Input
The first line of input contains the original DNA sequence, consisting only of letters "A", "C", "T" and "G" and not exceeding 3·106 in length.
The second line contains a single integer k (1 ≤ k ≤ 3·106).
The third line contains a single integer n (0 ≤ n ≤ 5000) — the number of mutations. The next n lines describe the mutations in chronological order — each mutation is described by two numbers li and ri (1 ≤ li ≤ ri ≤ 109), meaning that the continuous subsequence [li, ri] has become active and cloned itself, joining itself with the mangled copy.
It is guaranteed that the input data is correct, that is, no mutation acts on non-existing elements of the DNA sequence, and the resulting DNA sequence has at least k elements.
Assume that the DNA elements are indexed starting from 1 and that the notation [l, r] meaning the continuous subsequence of DNA sequence that consists of r - l + 1 elements starting at the l-th DNA sequence element and ending at the r-th DNA sequence element.
Output
Output a single line, containing the first k letters of the mutated DNA sequence.
Examples
Input
GAGA
4
0
Output
GAGA
Input
ACGTACGT
16
2
1 2
2 8
Output
ACCAGTACCGACATCG
Note
In the second example, after the first mutation the sequence is "ACCAGTACGT". After the second mutation it's "ACCAGTACCGACATCGT".
Submitted Solution:
```
dna = input()
k = int(input())
n = int(input())
def mutation(word,start,end):
changed = word[start-1:end]
is_even_number = lambda x: x%2 == 0
is_odd_number = lambda x: x%2 != 0
changed_word = list(filter(is_even_number,range(1,len(changed)+1))) + list(filter(is_odd_number,range(1,len(changed)+1)))
changed_word = ''.join(list(map(lambda x:changed[x-1],changed_word)))
new_word = word[:end] + changed_word + word[end:]
return new_word
for i in range(n):
a,b = list(map(int,input().split()))
if len(dna) > 16 and a >= 16:
continue
dna = mutation(dna,a,b)
print (dna[:k])
``` | instruction | 0 | 85,271 | 3 | 170,542 |
No | output | 1 | 85,271 | 3 | 170,543 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Professor Bajtocy is conducting experiments on alien DNA. He has discovered that it is subject to repetitive mutations — each mutation happens in the same way: some continuous subsequence of the alien DNA becomes active, copies itself, the copy gets mangled and inserts itself right after the original subsequence. The mangled copy of the activated continuous subsequence is formed by first joining all the elements at the even positions in that subsequence, and then joining all the elements at the odd ones at the end. That is, if the activated subsequence consists of 11 elements and represented as s1s2... s11, its mangled copy is s2s4s6s8s10s1s3s5s7s9s11.
For example, if the original sequence was "ACTGG" and the mutation happened on the segment [2, 4] (that is the activated subsequence is "CTG"), the mutated DNA is: "ACTGTCGG". The mangled copy of the activated subsequence is marked with bold font.
Professor Bajtocy has written down the original DNA sequence and the mutations that sequentially happened to it, and he now asks you to recover the first k elements of the DNA sequence after all the mutations.
Input
The first line of input contains the original DNA sequence, consisting only of letters "A", "C", "T" and "G" and not exceeding 3·106 in length.
The second line contains a single integer k (1 ≤ k ≤ 3·106).
The third line contains a single integer n (0 ≤ n ≤ 5000) — the number of mutations. The next n lines describe the mutations in chronological order — each mutation is described by two numbers li and ri (1 ≤ li ≤ ri ≤ 109), meaning that the continuous subsequence [li, ri] has become active and cloned itself, joining itself with the mangled copy.
It is guaranteed that the input data is correct, that is, no mutation acts on non-existing elements of the DNA sequence, and the resulting DNA sequence has at least k elements.
Assume that the DNA elements are indexed starting from 1 and that the notation [l, r] meaning the continuous subsequence of DNA sequence that consists of r - l + 1 elements starting at the l-th DNA sequence element and ending at the r-th DNA sequence element.
Output
Output a single line, containing the first k letters of the mutated DNA sequence.
Examples
Input
GAGA
4
0
Output
GAGA
Input
ACGTACGT
16
2
1 2
2 8
Output
ACCAGTACCGACATCG
Note
In the second example, after the first mutation the sequence is "ACCAGTACGT". After the second mutation it's "ACCAGTACCGACATCGT".
Submitted Solution:
```
dna = input()
k = int(input())
n = int(input())
def mutation(word,start,end):
changed = word[start-1:end]
is_even_number = lambda x: x%2 == 0
is_odd_number = lambda x: x%2 != 0
changed_word = list(filter(is_even_number,range(1,len(changed)+1))) + list(filter(is_odd_number,range(1,len(changed)+1)))
changed_word = ''.join(list(map(lambda x:changed[x-1],changed_word)))
new_word = word[:end] + changed_word + word[end:]
return new_word
for i in range(n):
a,b = list(map(int,input().split()))
if a >= k:
continue
dna = mutation(dna[:k-1],a,b)
print (dna)
``` | instruction | 0 | 85,272 | 3 | 170,544 |
No | output | 1 | 85,272 | 3 | 170,545 |
Provide a correct Python 3 solution for this coding contest problem.
Two children are playing tag on a number line. (In the game of tag, the child called "it" tries to catch the other child.) The child who is "it" is now at coordinate A, and he can travel the distance of V per second. The other child is now at coordinate B, and she can travel the distance of W per second.
He can catch her when his coordinate is the same as hers. Determine whether he can catch her within T seconds (including exactly T seconds later). We assume that both children move optimally.
Constraints
* -10^9 \leq A,B \leq 10^9
* 1 \leq V,W \leq 10^9
* 1 \leq T \leq 10^9
* A \neq B
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
A V
B W
T
Output
If "it" can catch the other child, print `YES`; otherwise, print `NO`.
Examples
Input
1 2
3 1
3
Output
YES
Input
1 2
3 2
3
Output
NO
Input
1 2
3 3
3
Output
NO | instruction | 0 | 85,504 | 3 | 171,008 |
"Correct Solution:
```
a,v=map(int,input().split())
b,w=map(int,input().split())
T=int(input())
if abs(a-b)<=T*(v-w):
print("YES")
else:
print("NO")
``` | output | 1 | 85,504 | 3 | 171,009 |
Provide a correct Python 3 solution for this coding contest problem.
Two children are playing tag on a number line. (In the game of tag, the child called "it" tries to catch the other child.) The child who is "it" is now at coordinate A, and he can travel the distance of V per second. The other child is now at coordinate B, and she can travel the distance of W per second.
He can catch her when his coordinate is the same as hers. Determine whether he can catch her within T seconds (including exactly T seconds later). We assume that both children move optimally.
Constraints
* -10^9 \leq A,B \leq 10^9
* 1 \leq V,W \leq 10^9
* 1 \leq T \leq 10^9
* A \neq B
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
A V
B W
T
Output
If "it" can catch the other child, print `YES`; otherwise, print `NO`.
Examples
Input
1 2
3 1
3
Output
YES
Input
1 2
3 2
3
Output
NO
Input
1 2
3 3
3
Output
NO | instruction | 0 | 85,506 | 3 | 171,012 |
"Correct Solution:
```
a, v = map(int, input().split())
b, w = map(int, input().split())
t = int(input())
if abs(b-a) <= (v-w)*t:
print("YES")
else:
print("NO")
``` | output | 1 | 85,506 | 3 | 171,013 |
Provide a correct Python 3 solution for this coding contest problem.
Two children are playing tag on a number line. (In the game of tag, the child called "it" tries to catch the other child.) The child who is "it" is now at coordinate A, and he can travel the distance of V per second. The other child is now at coordinate B, and she can travel the distance of W per second.
He can catch her when his coordinate is the same as hers. Determine whether he can catch her within T seconds (including exactly T seconds later). We assume that both children move optimally.
Constraints
* -10^9 \leq A,B \leq 10^9
* 1 \leq V,W \leq 10^9
* 1 \leq T \leq 10^9
* A \neq B
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
A V
B W
T
Output
If "it" can catch the other child, print `YES`; otherwise, print `NO`.
Examples
Input
1 2
3 1
3
Output
YES
Input
1 2
3 2
3
Output
NO
Input
1 2
3 3
3
Output
NO | instruction | 0 | 85,507 | 3 | 171,014 |
"Correct Solution:
```
a,v=map(int,input().split())
b,w=map(int,input().split())
t=int(input())
if v*t-w*t>=abs(-b+a):
print("YES")
else:
print("NO")
``` | output | 1 | 85,507 | 3 | 171,015 |
Provide a correct Python 3 solution for this coding contest problem.
Two children are playing tag on a number line. (In the game of tag, the child called "it" tries to catch the other child.) The child who is "it" is now at coordinate A, and he can travel the distance of V per second. The other child is now at coordinate B, and she can travel the distance of W per second.
He can catch her when his coordinate is the same as hers. Determine whether he can catch her within T seconds (including exactly T seconds later). We assume that both children move optimally.
Constraints
* -10^9 \leq A,B \leq 10^9
* 1 \leq V,W \leq 10^9
* 1 \leq T \leq 10^9
* A \neq B
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
A V
B W
T
Output
If "it" can catch the other child, print `YES`; otherwise, print `NO`.
Examples
Input
1 2
3 1
3
Output
YES
Input
1 2
3 2
3
Output
NO
Input
1 2
3 3
3
Output
NO | instruction | 0 | 85,509 | 3 | 171,018 |
"Correct Solution:
```
a,v = map(int,input().split())
b,w = map(int,input().split())
t = int(input())
if abs(b-a)+t*w <= t*v:
print("YES")
else:
print("NO")
``` | output | 1 | 85,509 | 3 | 171,019 |
Provide a correct Python 3 solution for this coding contest problem.
Two children are playing tag on a number line. (In the game of tag, the child called "it" tries to catch the other child.) The child who is "it" is now at coordinate A, and he can travel the distance of V per second. The other child is now at coordinate B, and she can travel the distance of W per second.
He can catch her when his coordinate is the same as hers. Determine whether he can catch her within T seconds (including exactly T seconds later). We assume that both children move optimally.
Constraints
* -10^9 \leq A,B \leq 10^9
* 1 \leq V,W \leq 10^9
* 1 \leq T \leq 10^9
* A \neq B
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
A V
B W
T
Output
If "it" can catch the other child, print `YES`; otherwise, print `NO`.
Examples
Input
1 2
3 1
3
Output
YES
Input
1 2
3 2
3
Output
NO
Input
1 2
3 3
3
Output
NO | instruction | 0 | 85,510 | 3 | 171,020 |
"Correct Solution:
```
a,v=map(int,input().split())
b,w=map(int,input().split())
t=int(input())
if abs(a-b)>t*(v-w):
print('NO')
else:
print('YES')
``` | output | 1 | 85,510 | 3 | 171,021 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Two children are playing tag on a number line. (In the game of tag, the child called "it" tries to catch the other child.) The child who is "it" is now at coordinate A, and he can travel the distance of V per second. The other child is now at coordinate B, and she can travel the distance of W per second.
He can catch her when his coordinate is the same as hers. Determine whether he can catch her within T seconds (including exactly T seconds later). We assume that both children move optimally.
Constraints
* -10^9 \leq A,B \leq 10^9
* 1 \leq V,W \leq 10^9
* 1 \leq T \leq 10^9
* A \neq B
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
A V
B W
T
Output
If "it" can catch the other child, print `YES`; otherwise, print `NO`.
Examples
Input
1 2
3 1
3
Output
YES
Input
1 2
3 2
3
Output
NO
Input
1 2
3 3
3
Output
NO
Submitted Solution:
```
a, v = map(int, input().split())
b, w = map(int, input().split())
t = int(input())
if abs(a-b)+w*t <= v*t:
print("YES")
else:
print("NO")
``` | instruction | 0 | 85,512 | 3 | 171,024 |
Yes | output | 1 | 85,512 | 3 | 171,025 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Two children are playing tag on a number line. (In the game of tag, the child called "it" tries to catch the other child.) The child who is "it" is now at coordinate A, and he can travel the distance of V per second. The other child is now at coordinate B, and she can travel the distance of W per second.
He can catch her when his coordinate is the same as hers. Determine whether he can catch her within T seconds (including exactly T seconds later). We assume that both children move optimally.
Constraints
* -10^9 \leq A,B \leq 10^9
* 1 \leq V,W \leq 10^9
* 1 \leq T \leq 10^9
* A \neq B
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
A V
B W
T
Output
If "it" can catch the other child, print `YES`; otherwise, print `NO`.
Examples
Input
1 2
3 1
3
Output
YES
Input
1 2
3 2
3
Output
NO
Input
1 2
3 3
3
Output
NO
Submitted Solution:
```
a , v = map(int,input().split())
b , w = map(int,input().split())
t = int(input())
if abs(a-b) <= (v-w)*t:
print("YES")
else:
print("NO")
``` | instruction | 0 | 85,513 | 3 | 171,026 |
Yes | output | 1 | 85,513 | 3 | 171,027 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.