message stringlengths 2 19.9k | message_type stringclasses 2
values | message_id int64 0 1 | conversation_id int64 322 108k | cluster float64 15 15 | __index_level_0__ int64 644 217k |
|---|---|---|---|---|---|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Little Artem found a grasshopper. He brought it to his house and constructed a jumping area for him.
The area looks like a strip of cells 1 × n. Each cell contains the direction for the next jump and the length of that jump. Grasshopper starts in the first cell and follows the instructions written on the cells. Grasshopper stops immediately if it jumps out of the strip. Now Artem wants to find out if this will ever happen.
Input
The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — length of the strip.
Next line contains a string of length n which consists of characters "<" and ">" only, that provide the direction of the jump from the corresponding cell. Next line contains n integers di (1 ≤ di ≤ 109) — the length of the jump from the i-th cell.
Output
Print "INFINITE" (without quotes) if grasshopper will continue his jumps forever. Otherwise print "FINITE" (without quotes).
Examples
Input
2
><
1 2
Output
FINITE
Input
3
>><
2 1 1
Output
INFINITE
Note
In the first sample grasshopper starts from the first cell and jumps to the right on the next cell. When he is in the second cell he needs to jump two cells left so he will jump out of the strip.
Second sample grasshopper path is 1 - 3 - 2 - 3 - 2 - 3 and so on. The path is infinite.
Submitted Solution:
```
n = int(input())
row = [0]*(n+1)
row[1] = 1
dire = input()
size_j = list(map(int,input().split()))
now_cell = 1
while True:
if dire[now_cell-1] == ">":
now_cell += size_j[now_cell-1]
else:
now_cell -= size_j[now_cell-1]
if now_cell > n or now_cell < 1:
print("FINITE")
break
if row[now_cell] == 1:
print("INFINITE")
break
row[now_cell] = 1
``` | instruction | 0 | 81,285 | 15 | 162,570 |
Yes | output | 1 | 81,285 | 15 | 162,571 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Little Artem found a grasshopper. He brought it to his house and constructed a jumping area for him.
The area looks like a strip of cells 1 × n. Each cell contains the direction for the next jump and the length of that jump. Grasshopper starts in the first cell and follows the instructions written on the cells. Grasshopper stops immediately if it jumps out of the strip. Now Artem wants to find out if this will ever happen.
Input
The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — length of the strip.
Next line contains a string of length n which consists of characters "<" and ">" only, that provide the direction of the jump from the corresponding cell. Next line contains n integers di (1 ≤ di ≤ 109) — the length of the jump from the i-th cell.
Output
Print "INFINITE" (without quotes) if grasshopper will continue his jumps forever. Otherwise print "FINITE" (without quotes).
Examples
Input
2
><
1 2
Output
FINITE
Input
3
>><
2 1 1
Output
INFINITE
Note
In the first sample grasshopper starts from the first cell and jumps to the right on the next cell. When he is in the second cell he needs to jump two cells left so he will jump out of the strip.
Second sample grasshopper path is 1 - 3 - 2 - 3 - 2 - 3 and so on. The path is infinite.
Submitted Solution:
```
def main():
m = int(input())
jumps = input()
vals = [int(v) for v in input().split()]
visited = set()
cur = 0
visited.add(cur)
is_ok = True
while len(vals) > cur >= 0:
diff_sign = 1 if jumps[cur] == '>' else -1
diff = diff_sign * vals[cur]
cur = cur + diff
if cur in visited:
is_ok = False
break
visited.add(cur)
print("FINITE" if is_ok else "INFINITE")
if __name__ == "__main__":
main()
``` | instruction | 0 | 81,286 | 15 | 162,572 |
Yes | output | 1 | 81,286 | 15 | 162,573 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Little Artem found a grasshopper. He brought it to his house and constructed a jumping area for him.
The area looks like a strip of cells 1 × n. Each cell contains the direction for the next jump and the length of that jump. Grasshopper starts in the first cell and follows the instructions written on the cells. Grasshopper stops immediately if it jumps out of the strip. Now Artem wants to find out if this will ever happen.
Input
The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — length of the strip.
Next line contains a string of length n which consists of characters "<" and ">" only, that provide the direction of the jump from the corresponding cell. Next line contains n integers di (1 ≤ di ≤ 109) — the length of the jump from the i-th cell.
Output
Print "INFINITE" (without quotes) if grasshopper will continue his jumps forever. Otherwise print "FINITE" (without quotes).
Examples
Input
2
><
1 2
Output
FINITE
Input
3
>><
2 1 1
Output
INFINITE
Note
In the first sample grasshopper starts from the first cell and jumps to the right on the next cell. When he is in the second cell he needs to jump two cells left so he will jump out of the strip.
Second sample grasshopper path is 1 - 3 - 2 - 3 - 2 - 3 and so on. The path is infinite.
Submitted Solution:
```
n = int(input())
t = input()
cord = 0
l = list(map(int,input().split()))
i = 0
d = set({})
while cord < len(t):
d.add(cord)
if t[cord] == ">":
cord = cord + l[cord]
else:
cord = cord - l[cord]
if cord < 0 or cord > n-1:
print("FINITE")
break
elif cord in d:
print("INFINITE")
break
``` | instruction | 0 | 81,287 | 15 | 162,574 |
Yes | output | 1 | 81,287 | 15 | 162,575 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Little Artem found a grasshopper. He brought it to his house and constructed a jumping area for him.
The area looks like a strip of cells 1 × n. Each cell contains the direction for the next jump and the length of that jump. Grasshopper starts in the first cell and follows the instructions written on the cells. Grasshopper stops immediately if it jumps out of the strip. Now Artem wants to find out if this will ever happen.
Input
The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — length of the strip.
Next line contains a string of length n which consists of characters "<" and ">" only, that provide the direction of the jump from the corresponding cell. Next line contains n integers di (1 ≤ di ≤ 109) — the length of the jump from the i-th cell.
Output
Print "INFINITE" (without quotes) if grasshopper will continue his jumps forever. Otherwise print "FINITE" (without quotes).
Examples
Input
2
><
1 2
Output
FINITE
Input
3
>><
2 1 1
Output
INFINITE
Note
In the first sample grasshopper starts from the first cell and jumps to the right on the next cell. When he is in the second cell he needs to jump two cells left so he will jump out of the strip.
Second sample grasshopper path is 1 - 3 - 2 - 3 - 2 - 3 and so on. The path is infinite.
Submitted Solution:
```
num=int(input())
l=list(input().split())
steps=list(map(int,input().split()))
lights=[False]*num
i=0
res='FINITE'
while(i<num and i>=0):
if lights[i]==True:
res='INFINITE'
break
lights[i]=True
if l[i]=='>':
i=i+steps[i]
else:
i=i-steps[i]
print(res)
``` | instruction | 0 | 81,288 | 15 | 162,576 |
No | output | 1 | 81,288 | 15 | 162,577 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Little Artem found a grasshopper. He brought it to his house and constructed a jumping area for him.
The area looks like a strip of cells 1 × n. Each cell contains the direction for the next jump and the length of that jump. Grasshopper starts in the first cell and follows the instructions written on the cells. Grasshopper stops immediately if it jumps out of the strip. Now Artem wants to find out if this will ever happen.
Input
The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — length of the strip.
Next line contains a string of length n which consists of characters "<" and ">" only, that provide the direction of the jump from the corresponding cell. Next line contains n integers di (1 ≤ di ≤ 109) — the length of the jump from the i-th cell.
Output
Print "INFINITE" (without quotes) if grasshopper will continue his jumps forever. Otherwise print "FINITE" (without quotes).
Examples
Input
2
><
1 2
Output
FINITE
Input
3
>><
2 1 1
Output
INFINITE
Note
In the first sample grasshopper starts from the first cell and jumps to the right on the next cell. When he is in the second cell he needs to jump two cells left so he will jump out of the strip.
Second sample grasshopper path is 1 - 3 - 2 - 3 - 2 - 3 and so on. The path is infinite.
Submitted Solution:
```
if __name__ == '__main__':
Y = lambda: list(map(int, input().split()))
N = lambda: int(input())
n = N()
s = input()
a = Y()
nxt, ans = 0, 0
for i in range(n):
nxt = i + a[i] if s[i] == '>' else i - a[i]
if nxt > n or nxt < 0:
ans = 2
break
print("INFINITE"[ans:])
``` | instruction | 0 | 81,289 | 15 | 162,578 |
No | output | 1 | 81,289 | 15 | 162,579 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Little Artem found a grasshopper. He brought it to his house and constructed a jumping area for him.
The area looks like a strip of cells 1 × n. Each cell contains the direction for the next jump and the length of that jump. Grasshopper starts in the first cell and follows the instructions written on the cells. Grasshopper stops immediately if it jumps out of the strip. Now Artem wants to find out if this will ever happen.
Input
The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — length of the strip.
Next line contains a string of length n which consists of characters "<" and ">" only, that provide the direction of the jump from the corresponding cell. Next line contains n integers di (1 ≤ di ≤ 109) — the length of the jump from the i-th cell.
Output
Print "INFINITE" (without quotes) if grasshopper will continue his jumps forever. Otherwise print "FINITE" (without quotes).
Examples
Input
2
><
1 2
Output
FINITE
Input
3
>><
2 1 1
Output
INFINITE
Note
In the first sample grasshopper starts from the first cell and jumps to the right on the next cell. When he is in the second cell he needs to jump two cells left so he will jump out of the strip.
Second sample grasshopper path is 1 - 3 - 2 - 3 - 2 - 3 and so on. The path is infinite.
Submitted Solution:
```
n = int(input())
s = input()
d = {}
for i in range(n):
d[i+1] = 1 if s[i]=='>' else -1
a = list(map(int,input().split()))
cell = 1
for i in range(n):
cell+= (d[cell]*a[i])
if cell<1 or cell>n:
print("FINITE")
break
else:
print("INFINITE")
``` | instruction | 0 | 81,290 | 15 | 162,580 |
No | output | 1 | 81,290 | 15 | 162,581 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Little Artem found a grasshopper. He brought it to his house and constructed a jumping area for him.
The area looks like a strip of cells 1 × n. Each cell contains the direction for the next jump and the length of that jump. Grasshopper starts in the first cell and follows the instructions written on the cells. Grasshopper stops immediately if it jumps out of the strip. Now Artem wants to find out if this will ever happen.
Input
The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — length of the strip.
Next line contains a string of length n which consists of characters "<" and ">" only, that provide the direction of the jump from the corresponding cell. Next line contains n integers di (1 ≤ di ≤ 109) — the length of the jump from the i-th cell.
Output
Print "INFINITE" (without quotes) if grasshopper will continue his jumps forever. Otherwise print "FINITE" (without quotes).
Examples
Input
2
><
1 2
Output
FINITE
Input
3
>><
2 1 1
Output
INFINITE
Note
In the first sample grasshopper starts from the first cell and jumps to the right on the next cell. When he is in the second cell he needs to jump two cells left so he will jump out of the strip.
Second sample grasshopper path is 1 - 3 - 2 - 3 - 2 - 3 and so on. The path is infinite.
Submitted Solution:
```
def check (arr3,x):
for i in range(len(arr3)):
if x == arr3[i]:
return True
break
return False
n = int(input())
s = input()
arr = []
for i in range(n):
arr.append(s[i])
s2 = input()
arr2 = s2.split(' ')
for i in range(n):
arr2[i] = int(arr2[i])
i = 0
j = 0
arr3 = []
while j < n:
if arr[j] == '>':
k = 1
else:
k = -1
if i > n or i < 0:
print('FINITE')
exit()
i = i+k*arr2[j]
j += 1
if i > n or i < 0:
print('FINITE')
exit()
if i == n:
print('FINITE')
exit()
print('INFINITE')
``` | instruction | 0 | 81,291 | 15 | 162,582 |
No | output | 1 | 81,291 | 15 | 162,583 |
Provide tags and a correct Python 3 solution for this coding contest problem.
On the way to Rio de Janeiro Ostap kills time playing with a grasshopper he took with him in a special box. Ostap builds a line of length n such that some cells of this line are empty and some contain obstacles. Then, he places his grasshopper to one of the empty cells and a small insect in another empty cell. The grasshopper wants to eat the insect.
Ostap knows that grasshopper is able to jump to any empty cell that is exactly k cells away from the current (to the left or to the right). Note that it doesn't matter whether intermediate cells are empty or not as the grasshopper makes a jump over them. For example, if k = 1 the grasshopper can jump to a neighboring cell only, and if k = 2 the grasshopper can jump over a single cell.
Your goal is to determine whether there is a sequence of jumps such that grasshopper will get from his initial position to the cell with an insect.
Input
The first line of the input contains two integers n and k (2 ≤ n ≤ 100, 1 ≤ k ≤ n - 1) — the number of cells in the line and the length of one grasshopper's jump.
The second line contains a string of length n consisting of characters '.', '#', 'G' and 'T'. Character '.' means that the corresponding cell is empty, character '#' means that the corresponding cell contains an obstacle and grasshopper can't jump there. Character 'G' means that the grasshopper starts at this position and, finally, 'T' means that the target insect is located at this cell. It's guaranteed that characters 'G' and 'T' appear in this line exactly once.
Output
If there exists a sequence of jumps (each jump of length k), such that the grasshopper can get from his initial position to the cell with the insect, print "YES" (without quotes) in the only line of the input. Otherwise, print "NO" (without quotes).
Examples
Input
5 2
#G#T#
Output
YES
Input
6 1
T....G
Output
YES
Input
7 3
T..#..G
Output
NO
Input
6 2
..GT..
Output
NO
Note
In the first sample, the grasshopper can make one jump to the right in order to get from cell 2 to cell 4.
In the second sample, the grasshopper is only able to jump to neighboring cells but the way to the insect is free — he can get there by jumping left 5 times.
In the third sample, the grasshopper can't make a single jump.
In the fourth sample, the grasshopper can only jump to the cells with odd indices, thus he won't be able to reach the insect. | instruction | 0 | 81,311 | 15 | 162,622 |
Tags: implementation, strings
Correct Solution:
```
n, k = map(int, input().split())
s = input()
# code
G = s.index('G')
T = s.index('T')
def check(u):
if s[u] == 'T':
exit(print("YES"))
elif s[u] == '#':
exit(print("NO"))
if G > T:
u = G
while u >= 0:
check(u)
u -= k
print("NO")
else:
u = G
while u < len(s):
check(u)
u += k
print("NO")
``` | output | 1 | 81,311 | 15 | 162,623 |
Provide tags and a correct Python 3 solution for this coding contest problem.
On the way to Rio de Janeiro Ostap kills time playing with a grasshopper he took with him in a special box. Ostap builds a line of length n such that some cells of this line are empty and some contain obstacles. Then, he places his grasshopper to one of the empty cells and a small insect in another empty cell. The grasshopper wants to eat the insect.
Ostap knows that grasshopper is able to jump to any empty cell that is exactly k cells away from the current (to the left or to the right). Note that it doesn't matter whether intermediate cells are empty or not as the grasshopper makes a jump over them. For example, if k = 1 the grasshopper can jump to a neighboring cell only, and if k = 2 the grasshopper can jump over a single cell.
Your goal is to determine whether there is a sequence of jumps such that grasshopper will get from his initial position to the cell with an insect.
Input
The first line of the input contains two integers n and k (2 ≤ n ≤ 100, 1 ≤ k ≤ n - 1) — the number of cells in the line and the length of one grasshopper's jump.
The second line contains a string of length n consisting of characters '.', '#', 'G' and 'T'. Character '.' means that the corresponding cell is empty, character '#' means that the corresponding cell contains an obstacle and grasshopper can't jump there. Character 'G' means that the grasshopper starts at this position and, finally, 'T' means that the target insect is located at this cell. It's guaranteed that characters 'G' and 'T' appear in this line exactly once.
Output
If there exists a sequence of jumps (each jump of length k), such that the grasshopper can get from his initial position to the cell with the insect, print "YES" (without quotes) in the only line of the input. Otherwise, print "NO" (without quotes).
Examples
Input
5 2
#G#T#
Output
YES
Input
6 1
T....G
Output
YES
Input
7 3
T..#..G
Output
NO
Input
6 2
..GT..
Output
NO
Note
In the first sample, the grasshopper can make one jump to the right in order to get from cell 2 to cell 4.
In the second sample, the grasshopper is only able to jump to neighboring cells but the way to the insect is free — he can get there by jumping left 5 times.
In the third sample, the grasshopper can't make a single jump.
In the fourth sample, the grasshopper can only jump to the cells with odd indices, thus he won't be able to reach the insect. | instruction | 0 | 81,312 | 15 | 162,624 |
Tags: implementation, strings
Correct Solution:
```
def solution():
number = input()
seq = input()
n = int(number.split()[0])
k = int(number.split()[1])
i = seq.find('T')
j = seq.find('G')
i, j = min(i, j), max(i, j)
while i + k <= j:
i += k
if seq[i] == '#':
return False
if seq[i] =='T' or seq[i] == 'G':
return True
return False
if(solution()==True):
print("YES")
else:
print("NO")
``` | output | 1 | 81,312 | 15 | 162,625 |
Provide tags and a correct Python 3 solution for this coding contest problem.
On the way to Rio de Janeiro Ostap kills time playing with a grasshopper he took with him in a special box. Ostap builds a line of length n such that some cells of this line are empty and some contain obstacles. Then, he places his grasshopper to one of the empty cells and a small insect in another empty cell. The grasshopper wants to eat the insect.
Ostap knows that grasshopper is able to jump to any empty cell that is exactly k cells away from the current (to the left or to the right). Note that it doesn't matter whether intermediate cells are empty or not as the grasshopper makes a jump over them. For example, if k = 1 the grasshopper can jump to a neighboring cell only, and if k = 2 the grasshopper can jump over a single cell.
Your goal is to determine whether there is a sequence of jumps such that grasshopper will get from his initial position to the cell with an insect.
Input
The first line of the input contains two integers n and k (2 ≤ n ≤ 100, 1 ≤ k ≤ n - 1) — the number of cells in the line and the length of one grasshopper's jump.
The second line contains a string of length n consisting of characters '.', '#', 'G' and 'T'. Character '.' means that the corresponding cell is empty, character '#' means that the corresponding cell contains an obstacle and grasshopper can't jump there. Character 'G' means that the grasshopper starts at this position and, finally, 'T' means that the target insect is located at this cell. It's guaranteed that characters 'G' and 'T' appear in this line exactly once.
Output
If there exists a sequence of jumps (each jump of length k), such that the grasshopper can get from his initial position to the cell with the insect, print "YES" (without quotes) in the only line of the input. Otherwise, print "NO" (without quotes).
Examples
Input
5 2
#G#T#
Output
YES
Input
6 1
T....G
Output
YES
Input
7 3
T..#..G
Output
NO
Input
6 2
..GT..
Output
NO
Note
In the first sample, the grasshopper can make one jump to the right in order to get from cell 2 to cell 4.
In the second sample, the grasshopper is only able to jump to neighboring cells but the way to the insect is free — he can get there by jumping left 5 times.
In the third sample, the grasshopper can't make a single jump.
In the fourth sample, the grasshopper can only jump to the cells with odd indices, thus he won't be able to reach the insect. | instruction | 0 | 81,313 | 15 | 162,626 |
Tags: implementation, strings
Correct Solution:
```
n,k = map(int,input().split())
s = input()
T = -1
G = -1
for i in range(len(s)):
if(s[i]=='T'):
T=i
elif(s[i]=='G'):
G=i
if T<G:
while(G>=0):
G-=k
if(G<0):
G+=k
print('NO')
exit(0)
if(s[G]=='#'):
print('NO')
exit(0)
elif(T==G):
print('YES')
exit(0)
else:
while(G<n):
G+=k
if(G>=n):
G-=k
print('NO')
exit(0)
if(s[G]=='#'):
print('NO')
exit(0)
elif(T==G):
print('YES')
exit(0)
print('NO')
``` | output | 1 | 81,313 | 15 | 162,627 |
Provide tags and a correct Python 3 solution for this coding contest problem.
On the way to Rio de Janeiro Ostap kills time playing with a grasshopper he took with him in a special box. Ostap builds a line of length n such that some cells of this line are empty and some contain obstacles. Then, he places his grasshopper to one of the empty cells and a small insect in another empty cell. The grasshopper wants to eat the insect.
Ostap knows that grasshopper is able to jump to any empty cell that is exactly k cells away from the current (to the left or to the right). Note that it doesn't matter whether intermediate cells are empty or not as the grasshopper makes a jump over them. For example, if k = 1 the grasshopper can jump to a neighboring cell only, and if k = 2 the grasshopper can jump over a single cell.
Your goal is to determine whether there is a sequence of jumps such that grasshopper will get from his initial position to the cell with an insect.
Input
The first line of the input contains two integers n and k (2 ≤ n ≤ 100, 1 ≤ k ≤ n - 1) — the number of cells in the line and the length of one grasshopper's jump.
The second line contains a string of length n consisting of characters '.', '#', 'G' and 'T'. Character '.' means that the corresponding cell is empty, character '#' means that the corresponding cell contains an obstacle and grasshopper can't jump there. Character 'G' means that the grasshopper starts at this position and, finally, 'T' means that the target insect is located at this cell. It's guaranteed that characters 'G' and 'T' appear in this line exactly once.
Output
If there exists a sequence of jumps (each jump of length k), such that the grasshopper can get from his initial position to the cell with the insect, print "YES" (without quotes) in the only line of the input. Otherwise, print "NO" (without quotes).
Examples
Input
5 2
#G#T#
Output
YES
Input
6 1
T....G
Output
YES
Input
7 3
T..#..G
Output
NO
Input
6 2
..GT..
Output
NO
Note
In the first sample, the grasshopper can make one jump to the right in order to get from cell 2 to cell 4.
In the second sample, the grasshopper is only able to jump to neighboring cells but the way to the insect is free — he can get there by jumping left 5 times.
In the third sample, the grasshopper can't make a single jump.
In the fourth sample, the grasshopper can only jump to the cells with odd indices, thus he won't be able to reach the insect. | instruction | 0 | 81,314 | 15 | 162,628 |
Tags: implementation, strings
Correct Solution:
```
import math
from fractions import Fraction as frac
MOD = 1e9 + 7
def gcd(a, b):
if b == 0:
return a
return gcd(b, a % b)
def lcm(a, b):
return a * b // gcd(a, b)
def solve(case_no):
n, k = map(int, input().split())
s = str(input())
sp = -1
ep = -1
for i in range(n):
if s[i] == 'G':
sp = i
elif s[i] == 'T':
ep = i
if (sp > ep):
sp, ep = ep, sp
if (ep - sp) % k != 0:
print("NO")
exit()
for i in range(sp + k, ep, k):
if s[i] == '#':
print("NO")
exit()
print("YES")
t = 1
# t = int(input())
for i in range(1, t + 1):
solve(i)
``` | output | 1 | 81,314 | 15 | 162,629 |
Provide tags and a correct Python 3 solution for this coding contest problem.
On the way to Rio de Janeiro Ostap kills time playing with a grasshopper he took with him in a special box. Ostap builds a line of length n such that some cells of this line are empty and some contain obstacles. Then, he places his grasshopper to one of the empty cells and a small insect in another empty cell. The grasshopper wants to eat the insect.
Ostap knows that grasshopper is able to jump to any empty cell that is exactly k cells away from the current (to the left or to the right). Note that it doesn't matter whether intermediate cells are empty or not as the grasshopper makes a jump over them. For example, if k = 1 the grasshopper can jump to a neighboring cell only, and if k = 2 the grasshopper can jump over a single cell.
Your goal is to determine whether there is a sequence of jumps such that grasshopper will get from his initial position to the cell with an insect.
Input
The first line of the input contains two integers n and k (2 ≤ n ≤ 100, 1 ≤ k ≤ n - 1) — the number of cells in the line and the length of one grasshopper's jump.
The second line contains a string of length n consisting of characters '.', '#', 'G' and 'T'. Character '.' means that the corresponding cell is empty, character '#' means that the corresponding cell contains an obstacle and grasshopper can't jump there. Character 'G' means that the grasshopper starts at this position and, finally, 'T' means that the target insect is located at this cell. It's guaranteed that characters 'G' and 'T' appear in this line exactly once.
Output
If there exists a sequence of jumps (each jump of length k), such that the grasshopper can get from his initial position to the cell with the insect, print "YES" (without quotes) in the only line of the input. Otherwise, print "NO" (without quotes).
Examples
Input
5 2
#G#T#
Output
YES
Input
6 1
T....G
Output
YES
Input
7 3
T..#..G
Output
NO
Input
6 2
..GT..
Output
NO
Note
In the first sample, the grasshopper can make one jump to the right in order to get from cell 2 to cell 4.
In the second sample, the grasshopper is only able to jump to neighboring cells but the way to the insect is free — he can get there by jumping left 5 times.
In the third sample, the grasshopper can't make a single jump.
In the fourth sample, the grasshopper can only jump to the cells with odd indices, thus he won't be able to reach the insect. | instruction | 0 | 81,315 | 15 | 162,630 |
Tags: implementation, strings
Correct Solution:
```
n,k=map(int,input().split())
arr=list(input())
starting=arr.index("G")
end=arr.index("T")
if end<starting:
starting,end=end,starting
i=starting
broken=0
while i<=end:
if arr[i]=="#":
broken+=1
break
i+=k
if abs(starting-end)%k==0 and broken==0:
print("YES")
else:
print("NO")
``` | output | 1 | 81,315 | 15 | 162,631 |
Provide tags and a correct Python 3 solution for this coding contest problem.
On the way to Rio de Janeiro Ostap kills time playing with a grasshopper he took with him in a special box. Ostap builds a line of length n such that some cells of this line are empty and some contain obstacles. Then, he places his grasshopper to one of the empty cells and a small insect in another empty cell. The grasshopper wants to eat the insect.
Ostap knows that grasshopper is able to jump to any empty cell that is exactly k cells away from the current (to the left or to the right). Note that it doesn't matter whether intermediate cells are empty or not as the grasshopper makes a jump over them. For example, if k = 1 the grasshopper can jump to a neighboring cell only, and if k = 2 the grasshopper can jump over a single cell.
Your goal is to determine whether there is a sequence of jumps such that grasshopper will get from his initial position to the cell with an insect.
Input
The first line of the input contains two integers n and k (2 ≤ n ≤ 100, 1 ≤ k ≤ n - 1) — the number of cells in the line and the length of one grasshopper's jump.
The second line contains a string of length n consisting of characters '.', '#', 'G' and 'T'. Character '.' means that the corresponding cell is empty, character '#' means that the corresponding cell contains an obstacle and grasshopper can't jump there. Character 'G' means that the grasshopper starts at this position and, finally, 'T' means that the target insect is located at this cell. It's guaranteed that characters 'G' and 'T' appear in this line exactly once.
Output
If there exists a sequence of jumps (each jump of length k), such that the grasshopper can get from his initial position to the cell with the insect, print "YES" (without quotes) in the only line of the input. Otherwise, print "NO" (without quotes).
Examples
Input
5 2
#G#T#
Output
YES
Input
6 1
T....G
Output
YES
Input
7 3
T..#..G
Output
NO
Input
6 2
..GT..
Output
NO
Note
In the first sample, the grasshopper can make one jump to the right in order to get from cell 2 to cell 4.
In the second sample, the grasshopper is only able to jump to neighboring cells but the way to the insect is free — he can get there by jumping left 5 times.
In the third sample, the grasshopper can't make a single jump.
In the fourth sample, the grasshopper can only jump to the cells with odd indices, thus he won't be able to reach the insect. | instruction | 0 | 81,316 | 15 | 162,632 |
Tags: implementation, strings
Correct Solution:
```
import sys
n, k = map(int, sys.stdin.readline().split())
line = sys.stdin.readline()
idx_g = line.index('G')
idx_t = line.index('T')
idx_max = max(idx_g, idx_t)
idx_min = min(idx_g, idx_t)
if (idx_max - idx_min) % k != 0:
print("NO")
sys.exit()
for idx in range(idx_min + k, idx_max - k + 1, k):
if line[idx] != '.':
print("NO")
sys.exit()
print("YES")
sys.exit()
``` | output | 1 | 81,316 | 15 | 162,633 |
Provide tags and a correct Python 3 solution for this coding contest problem.
On the way to Rio de Janeiro Ostap kills time playing with a grasshopper he took with him in a special box. Ostap builds a line of length n such that some cells of this line are empty and some contain obstacles. Then, he places his grasshopper to one of the empty cells and a small insect in another empty cell. The grasshopper wants to eat the insect.
Ostap knows that grasshopper is able to jump to any empty cell that is exactly k cells away from the current (to the left or to the right). Note that it doesn't matter whether intermediate cells are empty or not as the grasshopper makes a jump over them. For example, if k = 1 the grasshopper can jump to a neighboring cell only, and if k = 2 the grasshopper can jump over a single cell.
Your goal is to determine whether there is a sequence of jumps such that grasshopper will get from his initial position to the cell with an insect.
Input
The first line of the input contains two integers n and k (2 ≤ n ≤ 100, 1 ≤ k ≤ n - 1) — the number of cells in the line and the length of one grasshopper's jump.
The second line contains a string of length n consisting of characters '.', '#', 'G' and 'T'. Character '.' means that the corresponding cell is empty, character '#' means that the corresponding cell contains an obstacle and grasshopper can't jump there. Character 'G' means that the grasshopper starts at this position and, finally, 'T' means that the target insect is located at this cell. It's guaranteed that characters 'G' and 'T' appear in this line exactly once.
Output
If there exists a sequence of jumps (each jump of length k), such that the grasshopper can get from his initial position to the cell with the insect, print "YES" (without quotes) in the only line of the input. Otherwise, print "NO" (without quotes).
Examples
Input
5 2
#G#T#
Output
YES
Input
6 1
T....G
Output
YES
Input
7 3
T..#..G
Output
NO
Input
6 2
..GT..
Output
NO
Note
In the first sample, the grasshopper can make one jump to the right in order to get from cell 2 to cell 4.
In the second sample, the grasshopper is only able to jump to neighboring cells but the way to the insect is free — he can get there by jumping left 5 times.
In the third sample, the grasshopper can't make a single jump.
In the fourth sample, the grasshopper can only jump to the cells with odd indices, thus he won't be able to reach the insect. | instruction | 0 | 81,317 | 15 | 162,634 |
Tags: implementation, strings
Correct Solution:
```
n, k=map(int,input().split())
s=input().strip()
m=min(s.index('G'),s.index('T'))
flag=0
for i in range(m+k,n,k):
if s[i]=='#':
flag=1
print("NO")
break
if s[i]=='G' or s[i]=='T':
flag=1
print("YES")
break
if flag==0:
print('NO')
``` | output | 1 | 81,317 | 15 | 162,635 |
Provide tags and a correct Python 3 solution for this coding contest problem.
On the way to Rio de Janeiro Ostap kills time playing with a grasshopper he took with him in a special box. Ostap builds a line of length n such that some cells of this line are empty and some contain obstacles. Then, he places his grasshopper to one of the empty cells and a small insect in another empty cell. The grasshopper wants to eat the insect.
Ostap knows that grasshopper is able to jump to any empty cell that is exactly k cells away from the current (to the left or to the right). Note that it doesn't matter whether intermediate cells are empty or not as the grasshopper makes a jump over them. For example, if k = 1 the grasshopper can jump to a neighboring cell only, and if k = 2 the grasshopper can jump over a single cell.
Your goal is to determine whether there is a sequence of jumps such that grasshopper will get from his initial position to the cell with an insect.
Input
The first line of the input contains two integers n and k (2 ≤ n ≤ 100, 1 ≤ k ≤ n - 1) — the number of cells in the line and the length of one grasshopper's jump.
The second line contains a string of length n consisting of characters '.', '#', 'G' and 'T'. Character '.' means that the corresponding cell is empty, character '#' means that the corresponding cell contains an obstacle and grasshopper can't jump there. Character 'G' means that the grasshopper starts at this position and, finally, 'T' means that the target insect is located at this cell. It's guaranteed that characters 'G' and 'T' appear in this line exactly once.
Output
If there exists a sequence of jumps (each jump of length k), such that the grasshopper can get from his initial position to the cell with the insect, print "YES" (without quotes) in the only line of the input. Otherwise, print "NO" (without quotes).
Examples
Input
5 2
#G#T#
Output
YES
Input
6 1
T....G
Output
YES
Input
7 3
T..#..G
Output
NO
Input
6 2
..GT..
Output
NO
Note
In the first sample, the grasshopper can make one jump to the right in order to get from cell 2 to cell 4.
In the second sample, the grasshopper is only able to jump to neighboring cells but the way to the insect is free — he can get there by jumping left 5 times.
In the third sample, the grasshopper can't make a single jump.
In the fourth sample, the grasshopper can only jump to the cells with odd indices, thus he won't be able to reach the insect. | instruction | 0 | 81,318 | 15 | 162,636 |
Tags: implementation, strings
Correct Solution:
```
n,m=map(int,input().split())
a=list(input())
if abs(a.index('G')-a.index('T'))%m!=0:
print("No")
else:
i=a.index('G')
j=a.index('T')
if i>j:
flag=0
while i>=j:
if a[i]=='#':
print("No")
flag=1
break
else:
i=i-m
if flag==0:
print("Yes")
else:
flag=0
while i<=j:
if a[i]=='#':
print("No")
flag=1
break
else:
i=i+m
if flag==0:
print("Yes")
``` | output | 1 | 81,318 | 15 | 162,637 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
On the way to Rio de Janeiro Ostap kills time playing with a grasshopper he took with him in a special box. Ostap builds a line of length n such that some cells of this line are empty and some contain obstacles. Then, he places his grasshopper to one of the empty cells and a small insect in another empty cell. The grasshopper wants to eat the insect.
Ostap knows that grasshopper is able to jump to any empty cell that is exactly k cells away from the current (to the left or to the right). Note that it doesn't matter whether intermediate cells are empty or not as the grasshopper makes a jump over them. For example, if k = 1 the grasshopper can jump to a neighboring cell only, and if k = 2 the grasshopper can jump over a single cell.
Your goal is to determine whether there is a sequence of jumps such that grasshopper will get from his initial position to the cell with an insect.
Input
The first line of the input contains two integers n and k (2 ≤ n ≤ 100, 1 ≤ k ≤ n - 1) — the number of cells in the line and the length of one grasshopper's jump.
The second line contains a string of length n consisting of characters '.', '#', 'G' and 'T'. Character '.' means that the corresponding cell is empty, character '#' means that the corresponding cell contains an obstacle and grasshopper can't jump there. Character 'G' means that the grasshopper starts at this position and, finally, 'T' means that the target insect is located at this cell. It's guaranteed that characters 'G' and 'T' appear in this line exactly once.
Output
If there exists a sequence of jumps (each jump of length k), such that the grasshopper can get from his initial position to the cell with the insect, print "YES" (without quotes) in the only line of the input. Otherwise, print "NO" (without quotes).
Examples
Input
5 2
#G#T#
Output
YES
Input
6 1
T....G
Output
YES
Input
7 3
T..#..G
Output
NO
Input
6 2
..GT..
Output
NO
Note
In the first sample, the grasshopper can make one jump to the right in order to get from cell 2 to cell 4.
In the second sample, the grasshopper is only able to jump to neighboring cells but the way to the insect is free — he can get there by jumping left 5 times.
In the third sample, the grasshopper can't make a single jump.
In the fourth sample, the grasshopper can only jump to the cells with odd indices, thus he won't be able to reach the insect.
Submitted Solution:
```
import math
import sys
import re
def g(n , s , k):
if abs(s.index('G') - s.index('T')) == k:
return 'YES'
elif abs(s.index('G') - s.index('T'))%k != 0:
return 'NO'
else:
if s.index('G')<s.index('T'):
m = s.index('G') + k
while m < n:
if s[m] == '#':
return 'NO'
elif s[m] == 'T':
return 'YES'
else:
m = m + k
else:
m = s.index('G') - k
while m>=0:
if s[m] == '#':
return 'NO'
elif s[m] == 'T':
return 'YES'
else:
m = m - k
n , k = map(int , input().rstrip().split())
s = input()
print(g(n , s , k))
``` | instruction | 0 | 81,319 | 15 | 162,638 |
Yes | output | 1 | 81,319 | 15 | 162,639 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
On the way to Rio de Janeiro Ostap kills time playing with a grasshopper he took with him in a special box. Ostap builds a line of length n such that some cells of this line are empty and some contain obstacles. Then, he places his grasshopper to one of the empty cells and a small insect in another empty cell. The grasshopper wants to eat the insect.
Ostap knows that grasshopper is able to jump to any empty cell that is exactly k cells away from the current (to the left or to the right). Note that it doesn't matter whether intermediate cells are empty or not as the grasshopper makes a jump over them. For example, if k = 1 the grasshopper can jump to a neighboring cell only, and if k = 2 the grasshopper can jump over a single cell.
Your goal is to determine whether there is a sequence of jumps such that grasshopper will get from his initial position to the cell with an insect.
Input
The first line of the input contains two integers n and k (2 ≤ n ≤ 100, 1 ≤ k ≤ n - 1) — the number of cells in the line and the length of one grasshopper's jump.
The second line contains a string of length n consisting of characters '.', '#', 'G' and 'T'. Character '.' means that the corresponding cell is empty, character '#' means that the corresponding cell contains an obstacle and grasshopper can't jump there. Character 'G' means that the grasshopper starts at this position and, finally, 'T' means that the target insect is located at this cell. It's guaranteed that characters 'G' and 'T' appear in this line exactly once.
Output
If there exists a sequence of jumps (each jump of length k), such that the grasshopper can get from his initial position to the cell with the insect, print "YES" (without quotes) in the only line of the input. Otherwise, print "NO" (without quotes).
Examples
Input
5 2
#G#T#
Output
YES
Input
6 1
T....G
Output
YES
Input
7 3
T..#..G
Output
NO
Input
6 2
..GT..
Output
NO
Note
In the first sample, the grasshopper can make one jump to the right in order to get from cell 2 to cell 4.
In the second sample, the grasshopper is only able to jump to neighboring cells but the way to the insect is free — he can get there by jumping left 5 times.
In the third sample, the grasshopper can't make a single jump.
In the fourth sample, the grasshopper can only jump to the cells with odd indices, thus he won't be able to reach the insect.
Submitted Solution:
```
n,k = map(int,input().split())
s = input()
i = 0
st = -1
def jump(st):
while(st<n):
st+=k
if(st>=n or s[st]=='#'):
return "NO"
if(s[st]=='T' or s[st]=='G'):
return "YES"
return "NO"
while(i<n):
if(s[i]=='T' or s[i]=='G'):
if(st==-1):
st=i
break
i+=1
print(jump(st))
``` | instruction | 0 | 81,320 | 15 | 162,640 |
Yes | output | 1 | 81,320 | 15 | 162,641 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
On the way to Rio de Janeiro Ostap kills time playing with a grasshopper he took with him in a special box. Ostap builds a line of length n such that some cells of this line are empty and some contain obstacles. Then, he places his grasshopper to one of the empty cells and a small insect in another empty cell. The grasshopper wants to eat the insect.
Ostap knows that grasshopper is able to jump to any empty cell that is exactly k cells away from the current (to the left or to the right). Note that it doesn't matter whether intermediate cells are empty or not as the grasshopper makes a jump over them. For example, if k = 1 the grasshopper can jump to a neighboring cell only, and if k = 2 the grasshopper can jump over a single cell.
Your goal is to determine whether there is a sequence of jumps such that grasshopper will get from his initial position to the cell with an insect.
Input
The first line of the input contains two integers n and k (2 ≤ n ≤ 100, 1 ≤ k ≤ n - 1) — the number of cells in the line and the length of one grasshopper's jump.
The second line contains a string of length n consisting of characters '.', '#', 'G' and 'T'. Character '.' means that the corresponding cell is empty, character '#' means that the corresponding cell contains an obstacle and grasshopper can't jump there. Character 'G' means that the grasshopper starts at this position and, finally, 'T' means that the target insect is located at this cell. It's guaranteed that characters 'G' and 'T' appear in this line exactly once.
Output
If there exists a sequence of jumps (each jump of length k), such that the grasshopper can get from his initial position to the cell with the insect, print "YES" (without quotes) in the only line of the input. Otherwise, print "NO" (without quotes).
Examples
Input
5 2
#G#T#
Output
YES
Input
6 1
T....G
Output
YES
Input
7 3
T..#..G
Output
NO
Input
6 2
..GT..
Output
NO
Note
In the first sample, the grasshopper can make one jump to the right in order to get from cell 2 to cell 4.
In the second sample, the grasshopper is only able to jump to neighboring cells but the way to the insect is free — he can get there by jumping left 5 times.
In the third sample, the grasshopper can't make a single jump.
In the fourth sample, the grasshopper can only jump to the cells with odd indices, thus he won't be able to reach the insect.
Submitted Solution:
```
from sys import stdin,stdout
def solve():
n,k=map(int, stdin.readline().strip().split())
s=stdin.readline().strip()
a=s.index("G")
b=s.index("T")
if abs(a-b)%k!=0:
print("NO")
return
if a>b:a,b=b,a
for i in range(a,b+1,k):
if s[i]=="#":
print("NO")
return
print("YES")
for i in range(1):
solve()
``` | instruction | 0 | 81,321 | 15 | 162,642 |
Yes | output | 1 | 81,321 | 15 | 162,643 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
On the way to Rio de Janeiro Ostap kills time playing with a grasshopper he took with him in a special box. Ostap builds a line of length n such that some cells of this line are empty and some contain obstacles. Then, he places his grasshopper to one of the empty cells and a small insect in another empty cell. The grasshopper wants to eat the insect.
Ostap knows that grasshopper is able to jump to any empty cell that is exactly k cells away from the current (to the left or to the right). Note that it doesn't matter whether intermediate cells are empty or not as the grasshopper makes a jump over them. For example, if k = 1 the grasshopper can jump to a neighboring cell only, and if k = 2 the grasshopper can jump over a single cell.
Your goal is to determine whether there is a sequence of jumps such that grasshopper will get from his initial position to the cell with an insect.
Input
The first line of the input contains two integers n and k (2 ≤ n ≤ 100, 1 ≤ k ≤ n - 1) — the number of cells in the line and the length of one grasshopper's jump.
The second line contains a string of length n consisting of characters '.', '#', 'G' and 'T'. Character '.' means that the corresponding cell is empty, character '#' means that the corresponding cell contains an obstacle and grasshopper can't jump there. Character 'G' means that the grasshopper starts at this position and, finally, 'T' means that the target insect is located at this cell. It's guaranteed that characters 'G' and 'T' appear in this line exactly once.
Output
If there exists a sequence of jumps (each jump of length k), such that the grasshopper can get from his initial position to the cell with the insect, print "YES" (without quotes) in the only line of the input. Otherwise, print "NO" (without quotes).
Examples
Input
5 2
#G#T#
Output
YES
Input
6 1
T....G
Output
YES
Input
7 3
T..#..G
Output
NO
Input
6 2
..GT..
Output
NO
Note
In the first sample, the grasshopper can make one jump to the right in order to get from cell 2 to cell 4.
In the second sample, the grasshopper is only able to jump to neighboring cells but the way to the insect is free — he can get there by jumping left 5 times.
In the third sample, the grasshopper can't make a single jump.
In the fourth sample, the grasshopper can only jump to the cells with odd indices, thus he won't be able to reach the insect.
Submitted Solution:
```
n,k=map(int,input().split())
s=input()
a=s.index("G")
b=s.index("T")
if b>a:
c=b-a
if c%k!=0:
print("NO")
else:
for i in range(a+k,n,k):
if s[i]=="#":
print("NO")
break
if s[i]=="T":
print("YES")
break
if a>b:
c=a-b
if c%k!=0:
print("NO")
else:
for i in range(a-k,-1,-k):
if s[i]=="#":
print("NO")
break
if s[i]=="T":
print("YES")
break
``` | instruction | 0 | 81,322 | 15 | 162,644 |
Yes | output | 1 | 81,322 | 15 | 162,645 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
On the way to Rio de Janeiro Ostap kills time playing with a grasshopper he took with him in a special box. Ostap builds a line of length n such that some cells of this line are empty and some contain obstacles. Then, he places his grasshopper to one of the empty cells and a small insect in another empty cell. The grasshopper wants to eat the insect.
Ostap knows that grasshopper is able to jump to any empty cell that is exactly k cells away from the current (to the left or to the right). Note that it doesn't matter whether intermediate cells are empty or not as the grasshopper makes a jump over them. For example, if k = 1 the grasshopper can jump to a neighboring cell only, and if k = 2 the grasshopper can jump over a single cell.
Your goal is to determine whether there is a sequence of jumps such that grasshopper will get from his initial position to the cell with an insect.
Input
The first line of the input contains two integers n and k (2 ≤ n ≤ 100, 1 ≤ k ≤ n - 1) — the number of cells in the line and the length of one grasshopper's jump.
The second line contains a string of length n consisting of characters '.', '#', 'G' and 'T'. Character '.' means that the corresponding cell is empty, character '#' means that the corresponding cell contains an obstacle and grasshopper can't jump there. Character 'G' means that the grasshopper starts at this position and, finally, 'T' means that the target insect is located at this cell. It's guaranteed that characters 'G' and 'T' appear in this line exactly once.
Output
If there exists a sequence of jumps (each jump of length k), such that the grasshopper can get from his initial position to the cell with the insect, print "YES" (without quotes) in the only line of the input. Otherwise, print "NO" (without quotes).
Examples
Input
5 2
#G#T#
Output
YES
Input
6 1
T....G
Output
YES
Input
7 3
T..#..G
Output
NO
Input
6 2
..GT..
Output
NO
Note
In the first sample, the grasshopper can make one jump to the right in order to get from cell 2 to cell 4.
In the second sample, the grasshopper is only able to jump to neighboring cells but the way to the insect is free — he can get there by jumping left 5 times.
In the third sample, the grasshopper can't make a single jump.
In the fourth sample, the grasshopper can only jump to the cells with odd indices, thus he won't be able to reach the insect.
Submitted Solution:
```
def main():
n, k = list(map(int, input().split()))
s = input()
for i, c in enumerate(s):
if c == 'G':
g = i
if c == 'T':
t = i
if t < g:
t, g = g, t
if g-t % k != 0:
print('NO')
return
for i in range(g, t, k):
if s[i] == '#':
print ('NO')
return
print ('YES')
main()
``` | instruction | 0 | 81,323 | 15 | 162,646 |
No | output | 1 | 81,323 | 15 | 162,647 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
On the way to Rio de Janeiro Ostap kills time playing with a grasshopper he took with him in a special box. Ostap builds a line of length n such that some cells of this line are empty and some contain obstacles. Then, he places his grasshopper to one of the empty cells and a small insect in another empty cell. The grasshopper wants to eat the insect.
Ostap knows that grasshopper is able to jump to any empty cell that is exactly k cells away from the current (to the left or to the right). Note that it doesn't matter whether intermediate cells are empty or not as the grasshopper makes a jump over them. For example, if k = 1 the grasshopper can jump to a neighboring cell only, and if k = 2 the grasshopper can jump over a single cell.
Your goal is to determine whether there is a sequence of jumps such that grasshopper will get from his initial position to the cell with an insect.
Input
The first line of the input contains two integers n and k (2 ≤ n ≤ 100, 1 ≤ k ≤ n - 1) — the number of cells in the line and the length of one grasshopper's jump.
The second line contains a string of length n consisting of characters '.', '#', 'G' and 'T'. Character '.' means that the corresponding cell is empty, character '#' means that the corresponding cell contains an obstacle and grasshopper can't jump there. Character 'G' means that the grasshopper starts at this position and, finally, 'T' means that the target insect is located at this cell. It's guaranteed that characters 'G' and 'T' appear in this line exactly once.
Output
If there exists a sequence of jumps (each jump of length k), such that the grasshopper can get from his initial position to the cell with the insect, print "YES" (without quotes) in the only line of the input. Otherwise, print "NO" (without quotes).
Examples
Input
5 2
#G#T#
Output
YES
Input
6 1
T....G
Output
YES
Input
7 3
T..#..G
Output
NO
Input
6 2
..GT..
Output
NO
Note
In the first sample, the grasshopper can make one jump to the right in order to get from cell 2 to cell 4.
In the second sample, the grasshopper is only able to jump to neighboring cells but the way to the insect is free — he can get there by jumping left 5 times.
In the third sample, the grasshopper can't make a single jump.
In the fourth sample, the grasshopper can only jump to the cells with odd indices, thus he won't be able to reach the insect.
Submitted Solution:
```
n, k = list(map(int, input().split()))
s = input()
g_ind = s.index('G')
t_ind = s.index('T')
if g_ind > t_ind:
if g_ind - k == t_ind:
print("YES")
else:
for i in range(g_ind-1, t_ind, -k):
if s[i] == '#':
print("NO")
break
else:
if t_ind+1 != g_ind and (i-1 == t_ind):
print("YES")
else:
print("NO")
else:
if g_ind + k == t_ind:
print("YES")
else:
for i in range(g_ind+1, t_ind, k):
if s[i] == '#':
print("NO")
break
else:
if g_ind+1 != t_ind and (i+1 == t_ind):
print("YES")
else:
print("NO")
``` | instruction | 0 | 81,324 | 15 | 162,648 |
No | output | 1 | 81,324 | 15 | 162,649 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
On the way to Rio de Janeiro Ostap kills time playing with a grasshopper he took with him in a special box. Ostap builds a line of length n such that some cells of this line are empty and some contain obstacles. Then, he places his grasshopper to one of the empty cells and a small insect in another empty cell. The grasshopper wants to eat the insect.
Ostap knows that grasshopper is able to jump to any empty cell that is exactly k cells away from the current (to the left or to the right). Note that it doesn't matter whether intermediate cells are empty or not as the grasshopper makes a jump over them. For example, if k = 1 the grasshopper can jump to a neighboring cell only, and if k = 2 the grasshopper can jump over a single cell.
Your goal is to determine whether there is a sequence of jumps such that grasshopper will get from his initial position to the cell with an insect.
Input
The first line of the input contains two integers n and k (2 ≤ n ≤ 100, 1 ≤ k ≤ n - 1) — the number of cells in the line and the length of one grasshopper's jump.
The second line contains a string of length n consisting of characters '.', '#', 'G' and 'T'. Character '.' means that the corresponding cell is empty, character '#' means that the corresponding cell contains an obstacle and grasshopper can't jump there. Character 'G' means that the grasshopper starts at this position and, finally, 'T' means that the target insect is located at this cell. It's guaranteed that characters 'G' and 'T' appear in this line exactly once.
Output
If there exists a sequence of jumps (each jump of length k), such that the grasshopper can get from his initial position to the cell with the insect, print "YES" (without quotes) in the only line of the input. Otherwise, print "NO" (without quotes).
Examples
Input
5 2
#G#T#
Output
YES
Input
6 1
T....G
Output
YES
Input
7 3
T..#..G
Output
NO
Input
6 2
..GT..
Output
NO
Note
In the first sample, the grasshopper can make one jump to the right in order to get from cell 2 to cell 4.
In the second sample, the grasshopper is only able to jump to neighboring cells but the way to the insect is free — he can get there by jumping left 5 times.
In the third sample, the grasshopper can't make a single jump.
In the fourth sample, the grasshopper can only jump to the cells with odd indices, thus he won't be able to reach the insect.
Submitted Solution:
```
trash, n = [int(x) for x in input().split()]
x = [str(x) for x in input().split()]
s = x[0]
for i in range(len(s) - 1):
if s[i] == 'T' or s[i] == 'G':
for j in range(i+n, len(s) - 1, n):
if s[j] == 'T' or s[j] == 'G':
print('YES')
break
if s[j] == '#':
print('NO')
break
break
``` | instruction | 0 | 81,325 | 15 | 162,650 |
No | output | 1 | 81,325 | 15 | 162,651 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
On the way to Rio de Janeiro Ostap kills time playing with a grasshopper he took with him in a special box. Ostap builds a line of length n such that some cells of this line are empty and some contain obstacles. Then, he places his grasshopper to one of the empty cells and a small insect in another empty cell. The grasshopper wants to eat the insect.
Ostap knows that grasshopper is able to jump to any empty cell that is exactly k cells away from the current (to the left or to the right). Note that it doesn't matter whether intermediate cells are empty or not as the grasshopper makes a jump over them. For example, if k = 1 the grasshopper can jump to a neighboring cell only, and if k = 2 the grasshopper can jump over a single cell.
Your goal is to determine whether there is a sequence of jumps such that grasshopper will get from his initial position to the cell with an insect.
Input
The first line of the input contains two integers n and k (2 ≤ n ≤ 100, 1 ≤ k ≤ n - 1) — the number of cells in the line and the length of one grasshopper's jump.
The second line contains a string of length n consisting of characters '.', '#', 'G' and 'T'. Character '.' means that the corresponding cell is empty, character '#' means that the corresponding cell contains an obstacle and grasshopper can't jump there. Character 'G' means that the grasshopper starts at this position and, finally, 'T' means that the target insect is located at this cell. It's guaranteed that characters 'G' and 'T' appear in this line exactly once.
Output
If there exists a sequence of jumps (each jump of length k), such that the grasshopper can get from his initial position to the cell with the insect, print "YES" (without quotes) in the only line of the input. Otherwise, print "NO" (without quotes).
Examples
Input
5 2
#G#T#
Output
YES
Input
6 1
T....G
Output
YES
Input
7 3
T..#..G
Output
NO
Input
6 2
..GT..
Output
NO
Note
In the first sample, the grasshopper can make one jump to the right in order to get from cell 2 to cell 4.
In the second sample, the grasshopper is only able to jump to neighboring cells but the way to the insect is free — he can get there by jumping left 5 times.
In the third sample, the grasshopper can't make a single jump.
In the fourth sample, the grasshopper can only jump to the cells with odd indices, thus he won't be able to reach the insect.
Submitted Solution:
```
ins = list(map(int,input().split()))
n = ins[0]
k = ins[1]
ins = input()
for i in range(0,len(ins)):
if ins[i] == 'G':
g = i
if ins[i] == 'T':
t = i
t = True
if (t-g) % k == 0:
p = t-g
if p<0:
p *= -1
while p != 0:
p = p - k
if ins[p] == 'T':
break
if ins[p] == '#':
t = False
else:
while p != 0:
p = p - k
if ins[p] == 'T':
break
if ins[p] == '#':
t = False
else:
t = False
if t:
print('YES')
else:
print('NO')
``` | instruction | 0 | 81,326 | 15 | 162,652 |
No | output | 1 | 81,326 | 15 | 162,653 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Alice has a cute cat. To keep her cat fit, Alice wants to design an exercising walk for her cat!
Initially, Alice's cat is located in a cell (x,y) of an infinite grid. According to Alice's theory, cat needs to move:
* exactly a steps left: from (u,v) to (u-1,v);
* exactly b steps right: from (u,v) to (u+1,v);
* exactly c steps down: from (u,v) to (u,v-1);
* exactly d steps up: from (u,v) to (u,v+1).
Note that the moves can be performed in an arbitrary order. For example, if the cat has to move 1 step left, 3 steps right and 2 steps down, then the walk right, down, left, right, right, down is valid.
Alice, however, is worrying that her cat might get lost if it moves far away from her. So she hopes that her cat is always in the area [x_1,x_2]× [y_1,y_2], i.e. for every cat's position (u,v) of a walk x_1 ≤ u ≤ x_2 and y_1 ≤ v ≤ y_2 holds.
Also, note that the cat can visit the same cell multiple times.
Can you help Alice find out if there exists a walk satisfying her wishes?
Formally, the walk should contain exactly a+b+c+d unit moves (a to the left, b to the right, c to the down, d to the up). Alice can do the moves in any order. Her current position (u, v) should always satisfy the constraints: x_1 ≤ u ≤ x_2, y_1 ≤ v ≤ y_2. The staring point is (x, y).
You are required to answer t test cases independently.
Input
The first line contains a single integer t (1 ≤ t ≤ 10^3) — the number of testcases.
The first line of each test case contains four integers a, b, c, d (0 ≤ a,b,c,d ≤ 10^8, a+b+c+d ≥ 1).
The second line of the test case contains six integers x, y, x_1, y_1, x_2, y_2 (-10^8 ≤ x_1≤ x ≤ x_2 ≤ 10^8, -10^8 ≤ y_1 ≤ y ≤ y_2 ≤ 10^8).
Output
For each test case, output "YES" in a separate line, if there exists a walk satisfying her wishes. Otherwise, output "NO" in a separate line.
You can print each letter in any case (upper or lower).
Example
Input
6
3 2 2 2
0 0 -2 -2 2 2
3 1 4 1
0 0 -1 -1 1 1
1 1 1 1
1 1 1 1 1 1
0 0 0 1
0 0 0 0 0 1
5 1 1 1
0 0 -100 -100 0 100
1 1 5 1
0 0 -100 -100 100 0
Output
Yes
No
No
Yes
Yes
Yes
Note
In the first test case, one valid exercising walk is $$$(0,0)→ (-1,0) → (-2,0)→ (-2,1) → (-2,2)→ (-1,2)→(0,2)→ (0,1)→ (0,0) → (-1,0)$$$ | instruction | 0 | 81,838 | 15 | 163,676 |
Tags: greedy, implementation, math
Correct Solution:
```
t=int(input())
for i in range(t):
a,b,c,d=map(int,input().split())
x,y,x1,y1,x2,y2=map(int,input().split())
x+=b-a
y+=d-c
if x1<=x and x2>=x and y1<=y and y2>=y and (x1<x2 or a+b==0) and (y1<y2 or c+d==0):
print("YES")
else:
print("NO")
``` | output | 1 | 81,838 | 15 | 163,677 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Alice has a cute cat. To keep her cat fit, Alice wants to design an exercising walk for her cat!
Initially, Alice's cat is located in a cell (x,y) of an infinite grid. According to Alice's theory, cat needs to move:
* exactly a steps left: from (u,v) to (u-1,v);
* exactly b steps right: from (u,v) to (u+1,v);
* exactly c steps down: from (u,v) to (u,v-1);
* exactly d steps up: from (u,v) to (u,v+1).
Note that the moves can be performed in an arbitrary order. For example, if the cat has to move 1 step left, 3 steps right and 2 steps down, then the walk right, down, left, right, right, down is valid.
Alice, however, is worrying that her cat might get lost if it moves far away from her. So she hopes that her cat is always in the area [x_1,x_2]× [y_1,y_2], i.e. for every cat's position (u,v) of a walk x_1 ≤ u ≤ x_2 and y_1 ≤ v ≤ y_2 holds.
Also, note that the cat can visit the same cell multiple times.
Can you help Alice find out if there exists a walk satisfying her wishes?
Formally, the walk should contain exactly a+b+c+d unit moves (a to the left, b to the right, c to the down, d to the up). Alice can do the moves in any order. Her current position (u, v) should always satisfy the constraints: x_1 ≤ u ≤ x_2, y_1 ≤ v ≤ y_2. The staring point is (x, y).
You are required to answer t test cases independently.
Input
The first line contains a single integer t (1 ≤ t ≤ 10^3) — the number of testcases.
The first line of each test case contains four integers a, b, c, d (0 ≤ a,b,c,d ≤ 10^8, a+b+c+d ≥ 1).
The second line of the test case contains six integers x, y, x_1, y_1, x_2, y_2 (-10^8 ≤ x_1≤ x ≤ x_2 ≤ 10^8, -10^8 ≤ y_1 ≤ y ≤ y_2 ≤ 10^8).
Output
For each test case, output "YES" in a separate line, if there exists a walk satisfying her wishes. Otherwise, output "NO" in a separate line.
You can print each letter in any case (upper or lower).
Example
Input
6
3 2 2 2
0 0 -2 -2 2 2
3 1 4 1
0 0 -1 -1 1 1
1 1 1 1
1 1 1 1 1 1
0 0 0 1
0 0 0 0 0 1
5 1 1 1
0 0 -100 -100 0 100
1 1 5 1
0 0 -100 -100 100 0
Output
Yes
No
No
Yes
Yes
Yes
Note
In the first test case, one valid exercising walk is $$$(0,0)→ (-1,0) → (-2,0)→ (-2,1) → (-2,2)→ (-1,2)→(0,2)→ (0,1)→ (0,0) → (-1,0)$$$ | instruction | 0 | 81,839 | 15 | 163,678 |
Tags: greedy, implementation, math
Correct Solution:
```
#!/usr/bin/python3
t = int(input())
for i in range(1, t + 1):
a, b, c, d = map(int, input().split())
x, y, x1, y1, x2, y2 = map(int, input().split())
if (x1 == x2 and (a != 0 or b != 0)) or (y1 == y2 and (c != 0 or d != 0)):
print("NO")
elif x1 <= x-a+b <= x2 and y1 <= y-c+d <= y2:
print("YES")
else:
print("NO")
``` | output | 1 | 81,839 | 15 | 163,679 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Alice has a cute cat. To keep her cat fit, Alice wants to design an exercising walk for her cat!
Initially, Alice's cat is located in a cell (x,y) of an infinite grid. According to Alice's theory, cat needs to move:
* exactly a steps left: from (u,v) to (u-1,v);
* exactly b steps right: from (u,v) to (u+1,v);
* exactly c steps down: from (u,v) to (u,v-1);
* exactly d steps up: from (u,v) to (u,v+1).
Note that the moves can be performed in an arbitrary order. For example, if the cat has to move 1 step left, 3 steps right and 2 steps down, then the walk right, down, left, right, right, down is valid.
Alice, however, is worrying that her cat might get lost if it moves far away from her. So she hopes that her cat is always in the area [x_1,x_2]× [y_1,y_2], i.e. for every cat's position (u,v) of a walk x_1 ≤ u ≤ x_2 and y_1 ≤ v ≤ y_2 holds.
Also, note that the cat can visit the same cell multiple times.
Can you help Alice find out if there exists a walk satisfying her wishes?
Formally, the walk should contain exactly a+b+c+d unit moves (a to the left, b to the right, c to the down, d to the up). Alice can do the moves in any order. Her current position (u, v) should always satisfy the constraints: x_1 ≤ u ≤ x_2, y_1 ≤ v ≤ y_2. The staring point is (x, y).
You are required to answer t test cases independently.
Input
The first line contains a single integer t (1 ≤ t ≤ 10^3) — the number of testcases.
The first line of each test case contains four integers a, b, c, d (0 ≤ a,b,c,d ≤ 10^8, a+b+c+d ≥ 1).
The second line of the test case contains six integers x, y, x_1, y_1, x_2, y_2 (-10^8 ≤ x_1≤ x ≤ x_2 ≤ 10^8, -10^8 ≤ y_1 ≤ y ≤ y_2 ≤ 10^8).
Output
For each test case, output "YES" in a separate line, if there exists a walk satisfying her wishes. Otherwise, output "NO" in a separate line.
You can print each letter in any case (upper or lower).
Example
Input
6
3 2 2 2
0 0 -2 -2 2 2
3 1 4 1
0 0 -1 -1 1 1
1 1 1 1
1 1 1 1 1 1
0 0 0 1
0 0 0 0 0 1
5 1 1 1
0 0 -100 -100 0 100
1 1 5 1
0 0 -100 -100 100 0
Output
Yes
No
No
Yes
Yes
Yes
Note
In the first test case, one valid exercising walk is $$$(0,0)→ (-1,0) → (-2,0)→ (-2,1) → (-2,2)→ (-1,2)→(0,2)→ (0,1)→ (0,0) → (-1,0)$$$ | instruction | 0 | 81,840 | 15 | 163,680 |
Tags: greedy, implementation, math
Correct Solution:
```
import sys
def input():
return sys.stdin.readline().strip()
def iinput():
return int(input())
def rinput():
return map(int, input().split())
def rlinput():
return list(map(int, input().split()))
def main():
def pro(a,b,x,x1,x2):
if (a == -2*b or x != x1 or x != x2 or b == 0) and x1 <= x - a + b <= x2:
return True
return False
# n = int(sys.stdin.readline().strip())
a,b,c,d = rinput()
x,y,x1,y1,x2,y2 = rinput()
if pro(a,b,x,x1,x2) and pro(c,d,y,y1,y2):
print("YES")
return 0
print("NO")
for i in range(iinput()):
main()
``` | output | 1 | 81,840 | 15 | 163,681 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Alice has a cute cat. To keep her cat fit, Alice wants to design an exercising walk for her cat!
Initially, Alice's cat is located in a cell (x,y) of an infinite grid. According to Alice's theory, cat needs to move:
* exactly a steps left: from (u,v) to (u-1,v);
* exactly b steps right: from (u,v) to (u+1,v);
* exactly c steps down: from (u,v) to (u,v-1);
* exactly d steps up: from (u,v) to (u,v+1).
Note that the moves can be performed in an arbitrary order. For example, if the cat has to move 1 step left, 3 steps right and 2 steps down, then the walk right, down, left, right, right, down is valid.
Alice, however, is worrying that her cat might get lost if it moves far away from her. So she hopes that her cat is always in the area [x_1,x_2]× [y_1,y_2], i.e. for every cat's position (u,v) of a walk x_1 ≤ u ≤ x_2 and y_1 ≤ v ≤ y_2 holds.
Also, note that the cat can visit the same cell multiple times.
Can you help Alice find out if there exists a walk satisfying her wishes?
Formally, the walk should contain exactly a+b+c+d unit moves (a to the left, b to the right, c to the down, d to the up). Alice can do the moves in any order. Her current position (u, v) should always satisfy the constraints: x_1 ≤ u ≤ x_2, y_1 ≤ v ≤ y_2. The staring point is (x, y).
You are required to answer t test cases independently.
Input
The first line contains a single integer t (1 ≤ t ≤ 10^3) — the number of testcases.
The first line of each test case contains four integers a, b, c, d (0 ≤ a,b,c,d ≤ 10^8, a+b+c+d ≥ 1).
The second line of the test case contains six integers x, y, x_1, y_1, x_2, y_2 (-10^8 ≤ x_1≤ x ≤ x_2 ≤ 10^8, -10^8 ≤ y_1 ≤ y ≤ y_2 ≤ 10^8).
Output
For each test case, output "YES" in a separate line, if there exists a walk satisfying her wishes. Otherwise, output "NO" in a separate line.
You can print each letter in any case (upper or lower).
Example
Input
6
3 2 2 2
0 0 -2 -2 2 2
3 1 4 1
0 0 -1 -1 1 1
1 1 1 1
1 1 1 1 1 1
0 0 0 1
0 0 0 0 0 1
5 1 1 1
0 0 -100 -100 0 100
1 1 5 1
0 0 -100 -100 100 0
Output
Yes
No
No
Yes
Yes
Yes
Note
In the first test case, one valid exercising walk is $$$(0,0)→ (-1,0) → (-2,0)→ (-2,1) → (-2,2)→ (-1,2)→(0,2)→ (0,1)→ (0,0) → (-1,0)$$$ | instruction | 0 | 81,841 | 15 | 163,682 |
Tags: greedy, implementation, math
Correct Solution:
```
import sys
input = sys.stdin.readline
for _ in range(int(input())):
a, b, c, d = map(int, input().split())
sx, sy, ax, ay, bx, by = map(int, input().split())
if (ax == bx and a+b != 0) or (ay == by and c+d != 0):
print('no')
elif ax <= sx-a+b <= bx and ay <= sy-c+d <= by:
print('yes')
else:
print('no')
``` | output | 1 | 81,841 | 15 | 163,683 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Alice has a cute cat. To keep her cat fit, Alice wants to design an exercising walk for her cat!
Initially, Alice's cat is located in a cell (x,y) of an infinite grid. According to Alice's theory, cat needs to move:
* exactly a steps left: from (u,v) to (u-1,v);
* exactly b steps right: from (u,v) to (u+1,v);
* exactly c steps down: from (u,v) to (u,v-1);
* exactly d steps up: from (u,v) to (u,v+1).
Note that the moves can be performed in an arbitrary order. For example, if the cat has to move 1 step left, 3 steps right and 2 steps down, then the walk right, down, left, right, right, down is valid.
Alice, however, is worrying that her cat might get lost if it moves far away from her. So she hopes that her cat is always in the area [x_1,x_2]× [y_1,y_2], i.e. for every cat's position (u,v) of a walk x_1 ≤ u ≤ x_2 and y_1 ≤ v ≤ y_2 holds.
Also, note that the cat can visit the same cell multiple times.
Can you help Alice find out if there exists a walk satisfying her wishes?
Formally, the walk should contain exactly a+b+c+d unit moves (a to the left, b to the right, c to the down, d to the up). Alice can do the moves in any order. Her current position (u, v) should always satisfy the constraints: x_1 ≤ u ≤ x_2, y_1 ≤ v ≤ y_2. The staring point is (x, y).
You are required to answer t test cases independently.
Input
The first line contains a single integer t (1 ≤ t ≤ 10^3) — the number of testcases.
The first line of each test case contains four integers a, b, c, d (0 ≤ a,b,c,d ≤ 10^8, a+b+c+d ≥ 1).
The second line of the test case contains six integers x, y, x_1, y_1, x_2, y_2 (-10^8 ≤ x_1≤ x ≤ x_2 ≤ 10^8, -10^8 ≤ y_1 ≤ y ≤ y_2 ≤ 10^8).
Output
For each test case, output "YES" in a separate line, if there exists a walk satisfying her wishes. Otherwise, output "NO" in a separate line.
You can print each letter in any case (upper or lower).
Example
Input
6
3 2 2 2
0 0 -2 -2 2 2
3 1 4 1
0 0 -1 -1 1 1
1 1 1 1
1 1 1 1 1 1
0 0 0 1
0 0 0 0 0 1
5 1 1 1
0 0 -100 -100 0 100
1 1 5 1
0 0 -100 -100 100 0
Output
Yes
No
No
Yes
Yes
Yes
Note
In the first test case, one valid exercising walk is $$$(0,0)→ (-1,0) → (-2,0)→ (-2,1) → (-2,2)→ (-1,2)→(0,2)→ (0,1)→ (0,0) → (-1,0)$$$ | instruction | 0 | 81,842 | 15 | 163,684 |
Tags: greedy, implementation, math
Correct Solution:
```
from sys import stdin
import math
inp = lambda: stdin.readline().strip()
t = int(inp())
for i in range(t):
l, r, d, u = [int(x) for x in input().split()]
x, y, x1, y1, x2, y2 = [int(x) for x in input().split()]
if (r > 0 or l > 0) and x1 - x2 == 0:
print("NO")
elif (d > 0 or u > 0) and y1 - y2 == 0:
print("NO")
elif x1 <= x + (r - l) <= x2 and y1 <= y + (u - d) <= y2:
print("YES")
else:
print("NO")
``` | output | 1 | 81,842 | 15 | 163,685 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Alice has a cute cat. To keep her cat fit, Alice wants to design an exercising walk for her cat!
Initially, Alice's cat is located in a cell (x,y) of an infinite grid. According to Alice's theory, cat needs to move:
* exactly a steps left: from (u,v) to (u-1,v);
* exactly b steps right: from (u,v) to (u+1,v);
* exactly c steps down: from (u,v) to (u,v-1);
* exactly d steps up: from (u,v) to (u,v+1).
Note that the moves can be performed in an arbitrary order. For example, if the cat has to move 1 step left, 3 steps right and 2 steps down, then the walk right, down, left, right, right, down is valid.
Alice, however, is worrying that her cat might get lost if it moves far away from her. So she hopes that her cat is always in the area [x_1,x_2]× [y_1,y_2], i.e. for every cat's position (u,v) of a walk x_1 ≤ u ≤ x_2 and y_1 ≤ v ≤ y_2 holds.
Also, note that the cat can visit the same cell multiple times.
Can you help Alice find out if there exists a walk satisfying her wishes?
Formally, the walk should contain exactly a+b+c+d unit moves (a to the left, b to the right, c to the down, d to the up). Alice can do the moves in any order. Her current position (u, v) should always satisfy the constraints: x_1 ≤ u ≤ x_2, y_1 ≤ v ≤ y_2. The staring point is (x, y).
You are required to answer t test cases independently.
Input
The first line contains a single integer t (1 ≤ t ≤ 10^3) — the number of testcases.
The first line of each test case contains four integers a, b, c, d (0 ≤ a,b,c,d ≤ 10^8, a+b+c+d ≥ 1).
The second line of the test case contains six integers x, y, x_1, y_1, x_2, y_2 (-10^8 ≤ x_1≤ x ≤ x_2 ≤ 10^8, -10^8 ≤ y_1 ≤ y ≤ y_2 ≤ 10^8).
Output
For each test case, output "YES" in a separate line, if there exists a walk satisfying her wishes. Otherwise, output "NO" in a separate line.
You can print each letter in any case (upper or lower).
Example
Input
6
3 2 2 2
0 0 -2 -2 2 2
3 1 4 1
0 0 -1 -1 1 1
1 1 1 1
1 1 1 1 1 1
0 0 0 1
0 0 0 0 0 1
5 1 1 1
0 0 -100 -100 0 100
1 1 5 1
0 0 -100 -100 100 0
Output
Yes
No
No
Yes
Yes
Yes
Note
In the first test case, one valid exercising walk is $$$(0,0)→ (-1,0) → (-2,0)→ (-2,1) → (-2,2)→ (-1,2)→(0,2)→ (0,1)→ (0,0) → (-1,0)$$$ | instruction | 0 | 81,843 | 15 | 163,686 |
Tags: greedy, implementation, math
Correct Solution:
```
task_number = int(input())
for _ in range(task_number):
left, right, down, up = map(int, input().split())
x, y, x1, y1, x2, y2 = map(int, input().split())
left_gap, right_gap, down_gap, up_gap = x-x1, x2-x, y-y1, y2-y
if left + right > 0 and left_gap + right_gap == 0:
print("NO")
continue
if down + up > 0 and down_gap + up_gap == 0:
print("NO")
continue
if max(0, left - right) > left_gap or max(0, right - left) > right_gap:
print("NO")
continue
if max(0, up - down) > up_gap or max(0, down - up) > down_gap:
print("NO")
continue
print("YES")
``` | output | 1 | 81,843 | 15 | 163,687 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Alice has a cute cat. To keep her cat fit, Alice wants to design an exercising walk for her cat!
Initially, Alice's cat is located in a cell (x,y) of an infinite grid. According to Alice's theory, cat needs to move:
* exactly a steps left: from (u,v) to (u-1,v);
* exactly b steps right: from (u,v) to (u+1,v);
* exactly c steps down: from (u,v) to (u,v-1);
* exactly d steps up: from (u,v) to (u,v+1).
Note that the moves can be performed in an arbitrary order. For example, if the cat has to move 1 step left, 3 steps right and 2 steps down, then the walk right, down, left, right, right, down is valid.
Alice, however, is worrying that her cat might get lost if it moves far away from her. So she hopes that her cat is always in the area [x_1,x_2]× [y_1,y_2], i.e. for every cat's position (u,v) of a walk x_1 ≤ u ≤ x_2 and y_1 ≤ v ≤ y_2 holds.
Also, note that the cat can visit the same cell multiple times.
Can you help Alice find out if there exists a walk satisfying her wishes?
Formally, the walk should contain exactly a+b+c+d unit moves (a to the left, b to the right, c to the down, d to the up). Alice can do the moves in any order. Her current position (u, v) should always satisfy the constraints: x_1 ≤ u ≤ x_2, y_1 ≤ v ≤ y_2. The staring point is (x, y).
You are required to answer t test cases independently.
Input
The first line contains a single integer t (1 ≤ t ≤ 10^3) — the number of testcases.
The first line of each test case contains four integers a, b, c, d (0 ≤ a,b,c,d ≤ 10^8, a+b+c+d ≥ 1).
The second line of the test case contains six integers x, y, x_1, y_1, x_2, y_2 (-10^8 ≤ x_1≤ x ≤ x_2 ≤ 10^8, -10^8 ≤ y_1 ≤ y ≤ y_2 ≤ 10^8).
Output
For each test case, output "YES" in a separate line, if there exists a walk satisfying her wishes. Otherwise, output "NO" in a separate line.
You can print each letter in any case (upper or lower).
Example
Input
6
3 2 2 2
0 0 -2 -2 2 2
3 1 4 1
0 0 -1 -1 1 1
1 1 1 1
1 1 1 1 1 1
0 0 0 1
0 0 0 0 0 1
5 1 1 1
0 0 -100 -100 0 100
1 1 5 1
0 0 -100 -100 100 0
Output
Yes
No
No
Yes
Yes
Yes
Note
In the first test case, one valid exercising walk is $$$(0,0)→ (-1,0) → (-2,0)→ (-2,1) → (-2,2)→ (-1,2)→(0,2)→ (0,1)→ (0,0) → (-1,0)$$$ | instruction | 0 | 81,844 | 15 | 163,688 |
Tags: greedy, implementation, math
Correct Solution:
```
for _ in range(int(input())):
l,r,d,u = map(int,input().split())
x1,y1,x2,y2,x3,y3 = map(int,input().split())
f=0
if(x1-(l-r)<x2):
f=1;
if(x1+r-l>x3):
f=1;
if(y1+u-d<y2):
f=1;
if(y1+u-d>y3):
f=1;
if(x2==x3 and (l>0 or r>0)):
f=1;
if(y2==y3 and (u>0 or d>0)):
f=1;
if(f==0):
print("YES")
else:
print("NO")
``` | output | 1 | 81,844 | 15 | 163,689 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Alice has a cute cat. To keep her cat fit, Alice wants to design an exercising walk for her cat!
Initially, Alice's cat is located in a cell (x,y) of an infinite grid. According to Alice's theory, cat needs to move:
* exactly a steps left: from (u,v) to (u-1,v);
* exactly b steps right: from (u,v) to (u+1,v);
* exactly c steps down: from (u,v) to (u,v-1);
* exactly d steps up: from (u,v) to (u,v+1).
Note that the moves can be performed in an arbitrary order. For example, if the cat has to move 1 step left, 3 steps right and 2 steps down, then the walk right, down, left, right, right, down is valid.
Alice, however, is worrying that her cat might get lost if it moves far away from her. So she hopes that her cat is always in the area [x_1,x_2]× [y_1,y_2], i.e. for every cat's position (u,v) of a walk x_1 ≤ u ≤ x_2 and y_1 ≤ v ≤ y_2 holds.
Also, note that the cat can visit the same cell multiple times.
Can you help Alice find out if there exists a walk satisfying her wishes?
Formally, the walk should contain exactly a+b+c+d unit moves (a to the left, b to the right, c to the down, d to the up). Alice can do the moves in any order. Her current position (u, v) should always satisfy the constraints: x_1 ≤ u ≤ x_2, y_1 ≤ v ≤ y_2. The staring point is (x, y).
You are required to answer t test cases independently.
Input
The first line contains a single integer t (1 ≤ t ≤ 10^3) — the number of testcases.
The first line of each test case contains four integers a, b, c, d (0 ≤ a,b,c,d ≤ 10^8, a+b+c+d ≥ 1).
The second line of the test case contains six integers x, y, x_1, y_1, x_2, y_2 (-10^8 ≤ x_1≤ x ≤ x_2 ≤ 10^8, -10^8 ≤ y_1 ≤ y ≤ y_2 ≤ 10^8).
Output
For each test case, output "YES" in a separate line, if there exists a walk satisfying her wishes. Otherwise, output "NO" in a separate line.
You can print each letter in any case (upper or lower).
Example
Input
6
3 2 2 2
0 0 -2 -2 2 2
3 1 4 1
0 0 -1 -1 1 1
1 1 1 1
1 1 1 1 1 1
0 0 0 1
0 0 0 0 0 1
5 1 1 1
0 0 -100 -100 0 100
1 1 5 1
0 0 -100 -100 100 0
Output
Yes
No
No
Yes
Yes
Yes
Note
In the first test case, one valid exercising walk is $$$(0,0)→ (-1,0) → (-2,0)→ (-2,1) → (-2,2)→ (-1,2)→(0,2)→ (0,1)→ (0,0) → (-1,0)$$$ | instruction | 0 | 81,845 | 15 | 163,690 |
Tags: greedy, implementation, math
Correct Solution:
```
import sys
input=sys.stdin.readline
from math import *
mod=10**9+7
def bo(i):
return ord(i)-ord('a')
t=int(input())
while t>0:
t-=1
a,b,c,d=map(int,input().split())
x,y,x1,y1,x2,y2=map(int,input().split())
if x1<=-a+b+x<=x2 and y1<=-c+d+y<=y2 and not (x1==x2 and (a>0 or b>0)) and not (y1==y2 and (c>0 or d>0)):
print("YES")
else:
print("NO")
``` | output | 1 | 81,845 | 15 | 163,691 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Alice has a cute cat. To keep her cat fit, Alice wants to design an exercising walk for her cat!
Initially, Alice's cat is located in a cell (x,y) of an infinite grid. According to Alice's theory, cat needs to move:
* exactly a steps left: from (u,v) to (u-1,v);
* exactly b steps right: from (u,v) to (u+1,v);
* exactly c steps down: from (u,v) to (u,v-1);
* exactly d steps up: from (u,v) to (u,v+1).
Note that the moves can be performed in an arbitrary order. For example, if the cat has to move 1 step left, 3 steps right and 2 steps down, then the walk right, down, left, right, right, down is valid.
Alice, however, is worrying that her cat might get lost if it moves far away from her. So she hopes that her cat is always in the area [x_1,x_2]× [y_1,y_2], i.e. for every cat's position (u,v) of a walk x_1 ≤ u ≤ x_2 and y_1 ≤ v ≤ y_2 holds.
Also, note that the cat can visit the same cell multiple times.
Can you help Alice find out if there exists a walk satisfying her wishes?
Formally, the walk should contain exactly a+b+c+d unit moves (a to the left, b to the right, c to the down, d to the up). Alice can do the moves in any order. Her current position (u, v) should always satisfy the constraints: x_1 ≤ u ≤ x_2, y_1 ≤ v ≤ y_2. The staring point is (x, y).
You are required to answer t test cases independently.
Input
The first line contains a single integer t (1 ≤ t ≤ 10^3) — the number of testcases.
The first line of each test case contains four integers a, b, c, d (0 ≤ a,b,c,d ≤ 10^8, a+b+c+d ≥ 1).
The second line of the test case contains six integers x, y, x_1, y_1, x_2, y_2 (-10^8 ≤ x_1≤ x ≤ x_2 ≤ 10^8, -10^8 ≤ y_1 ≤ y ≤ y_2 ≤ 10^8).
Output
For each test case, output "YES" in a separate line, if there exists a walk satisfying her wishes. Otherwise, output "NO" in a separate line.
You can print each letter in any case (upper or lower).
Example
Input
6
3 2 2 2
0 0 -2 -2 2 2
3 1 4 1
0 0 -1 -1 1 1
1 1 1 1
1 1 1 1 1 1
0 0 0 1
0 0 0 0 0 1
5 1 1 1
0 0 -100 -100 0 100
1 1 5 1
0 0 -100 -100 100 0
Output
Yes
No
No
Yes
Yes
Yes
Note
In the first test case, one valid exercising walk is $$$(0,0)→ (-1,0) → (-2,0)→ (-2,1) → (-2,2)→ (-1,2)→(0,2)→ (0,1)→ (0,0) → (-1,0)$$$
Submitted Solution:
```
for i in range(int(input())):
a, b, c, d = map(int, input().split())
x, y, x1, y1, x2, y2 = map(int, input().split())
dx = b - a
dy = d - c
xk = x + dx
yk = y + dy
xw = x2 - x1
yw = y2 - y1
if (x1 <= xk <= x2) and (y1 <= yk <= y2):
if ((xw == 0) and ((a != 0) or (b != 0))) or ((yw == 0) and ((c != 0) or (d != 0))):
print('NO')
else:
print('YES')
else:
print('NO')
``` | instruction | 0 | 81,846 | 15 | 163,692 |
Yes | output | 1 | 81,846 | 15 | 163,693 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Alice has a cute cat. To keep her cat fit, Alice wants to design an exercising walk for her cat!
Initially, Alice's cat is located in a cell (x,y) of an infinite grid. According to Alice's theory, cat needs to move:
* exactly a steps left: from (u,v) to (u-1,v);
* exactly b steps right: from (u,v) to (u+1,v);
* exactly c steps down: from (u,v) to (u,v-1);
* exactly d steps up: from (u,v) to (u,v+1).
Note that the moves can be performed in an arbitrary order. For example, if the cat has to move 1 step left, 3 steps right and 2 steps down, then the walk right, down, left, right, right, down is valid.
Alice, however, is worrying that her cat might get lost if it moves far away from her. So she hopes that her cat is always in the area [x_1,x_2]× [y_1,y_2], i.e. for every cat's position (u,v) of a walk x_1 ≤ u ≤ x_2 and y_1 ≤ v ≤ y_2 holds.
Also, note that the cat can visit the same cell multiple times.
Can you help Alice find out if there exists a walk satisfying her wishes?
Formally, the walk should contain exactly a+b+c+d unit moves (a to the left, b to the right, c to the down, d to the up). Alice can do the moves in any order. Her current position (u, v) should always satisfy the constraints: x_1 ≤ u ≤ x_2, y_1 ≤ v ≤ y_2. The staring point is (x, y).
You are required to answer t test cases independently.
Input
The first line contains a single integer t (1 ≤ t ≤ 10^3) — the number of testcases.
The first line of each test case contains four integers a, b, c, d (0 ≤ a,b,c,d ≤ 10^8, a+b+c+d ≥ 1).
The second line of the test case contains six integers x, y, x_1, y_1, x_2, y_2 (-10^8 ≤ x_1≤ x ≤ x_2 ≤ 10^8, -10^8 ≤ y_1 ≤ y ≤ y_2 ≤ 10^8).
Output
For each test case, output "YES" in a separate line, if there exists a walk satisfying her wishes. Otherwise, output "NO" in a separate line.
You can print each letter in any case (upper or lower).
Example
Input
6
3 2 2 2
0 0 -2 -2 2 2
3 1 4 1
0 0 -1 -1 1 1
1 1 1 1
1 1 1 1 1 1
0 0 0 1
0 0 0 0 0 1
5 1 1 1
0 0 -100 -100 0 100
1 1 5 1
0 0 -100 -100 100 0
Output
Yes
No
No
Yes
Yes
Yes
Note
In the first test case, one valid exercising walk is $$$(0,0)→ (-1,0) → (-2,0)→ (-2,1) → (-2,2)→ (-1,2)→(0,2)→ (0,1)→ (0,0) → (-1,0)$$$
Submitted Solution:
```
for _ in range(int(input())):
a,b,c,d = map(int, input().split())
x,y,x1,y1,x2,y2= list(map(int, input().split()))
sum = sum1 = 0
if x1-x == 0 and x2 - x == 0:
if(a != 0 or b != 0):
print("No")
continue
if y1-y == 0 and y2 - y == 0:
if(c != 0 or c != 0):
print("No")
continue
if(a>=b):
sum = abs(x1 - x) - (a-b)
else:
sum = abs(x2 - x) - (b-a)
if(c>=d):
sum1 = abs(y1 - y)-(c-d)
else:
sum1 = abs(y2 - y) - (d-c)
if(sum < 0 or sum1 < 0):
print("No")
else:
print("Yes")
``` | instruction | 0 | 81,847 | 15 | 163,694 |
Yes | output | 1 | 81,847 | 15 | 163,695 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Alice has a cute cat. To keep her cat fit, Alice wants to design an exercising walk for her cat!
Initially, Alice's cat is located in a cell (x,y) of an infinite grid. According to Alice's theory, cat needs to move:
* exactly a steps left: from (u,v) to (u-1,v);
* exactly b steps right: from (u,v) to (u+1,v);
* exactly c steps down: from (u,v) to (u,v-1);
* exactly d steps up: from (u,v) to (u,v+1).
Note that the moves can be performed in an arbitrary order. For example, if the cat has to move 1 step left, 3 steps right and 2 steps down, then the walk right, down, left, right, right, down is valid.
Alice, however, is worrying that her cat might get lost if it moves far away from her. So she hopes that her cat is always in the area [x_1,x_2]× [y_1,y_2], i.e. for every cat's position (u,v) of a walk x_1 ≤ u ≤ x_2 and y_1 ≤ v ≤ y_2 holds.
Also, note that the cat can visit the same cell multiple times.
Can you help Alice find out if there exists a walk satisfying her wishes?
Formally, the walk should contain exactly a+b+c+d unit moves (a to the left, b to the right, c to the down, d to the up). Alice can do the moves in any order. Her current position (u, v) should always satisfy the constraints: x_1 ≤ u ≤ x_2, y_1 ≤ v ≤ y_2. The staring point is (x, y).
You are required to answer t test cases independently.
Input
The first line contains a single integer t (1 ≤ t ≤ 10^3) — the number of testcases.
The first line of each test case contains four integers a, b, c, d (0 ≤ a,b,c,d ≤ 10^8, a+b+c+d ≥ 1).
The second line of the test case contains six integers x, y, x_1, y_1, x_2, y_2 (-10^8 ≤ x_1≤ x ≤ x_2 ≤ 10^8, -10^8 ≤ y_1 ≤ y ≤ y_2 ≤ 10^8).
Output
For each test case, output "YES" in a separate line, if there exists a walk satisfying her wishes. Otherwise, output "NO" in a separate line.
You can print each letter in any case (upper or lower).
Example
Input
6
3 2 2 2
0 0 -2 -2 2 2
3 1 4 1
0 0 -1 -1 1 1
1 1 1 1
1 1 1 1 1 1
0 0 0 1
0 0 0 0 0 1
5 1 1 1
0 0 -100 -100 0 100
1 1 5 1
0 0 -100 -100 100 0
Output
Yes
No
No
Yes
Yes
Yes
Note
In the first test case, one valid exercising walk is $$$(0,0)→ (-1,0) → (-2,0)→ (-2,1) → (-2,2)→ (-1,2)→(0,2)→ (0,1)→ (0,0) → (-1,0)$$$
Submitted Solution:
```
t=int(input())
for i in range(0,t):
a,b,c,d=list(map(int,input().split()))
x,y,x1,y1,x2,y2=list(map(int,input().split()))
if (x-x1 < a-b) or (y-y1 < c-d) or (x2-x < b-a) or (y2-y < d-c):
print("NO")
elif (x-x1==0 and x-x2==0 and a>0 and b>0) or (y-y1==0 and y-y2==0 and c>0 and d>0):
print("NO")
else:
if a>b:
x=x-(a-b)
else:
x=x+(b-a)
if c>d:
y=y-(c-d)
else:
y=y+(d-c)
if x>= x1 and x<=x2 and y>=y1 and y<=y2 :
print("YES")
else:
print("NO")
``` | instruction | 0 | 81,848 | 15 | 163,696 |
Yes | output | 1 | 81,848 | 15 | 163,697 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Alice has a cute cat. To keep her cat fit, Alice wants to design an exercising walk for her cat!
Initially, Alice's cat is located in a cell (x,y) of an infinite grid. According to Alice's theory, cat needs to move:
* exactly a steps left: from (u,v) to (u-1,v);
* exactly b steps right: from (u,v) to (u+1,v);
* exactly c steps down: from (u,v) to (u,v-1);
* exactly d steps up: from (u,v) to (u,v+1).
Note that the moves can be performed in an arbitrary order. For example, if the cat has to move 1 step left, 3 steps right and 2 steps down, then the walk right, down, left, right, right, down is valid.
Alice, however, is worrying that her cat might get lost if it moves far away from her. So she hopes that her cat is always in the area [x_1,x_2]× [y_1,y_2], i.e. for every cat's position (u,v) of a walk x_1 ≤ u ≤ x_2 and y_1 ≤ v ≤ y_2 holds.
Also, note that the cat can visit the same cell multiple times.
Can you help Alice find out if there exists a walk satisfying her wishes?
Formally, the walk should contain exactly a+b+c+d unit moves (a to the left, b to the right, c to the down, d to the up). Alice can do the moves in any order. Her current position (u, v) should always satisfy the constraints: x_1 ≤ u ≤ x_2, y_1 ≤ v ≤ y_2. The staring point is (x, y).
You are required to answer t test cases independently.
Input
The first line contains a single integer t (1 ≤ t ≤ 10^3) — the number of testcases.
The first line of each test case contains four integers a, b, c, d (0 ≤ a,b,c,d ≤ 10^8, a+b+c+d ≥ 1).
The second line of the test case contains six integers x, y, x_1, y_1, x_2, y_2 (-10^8 ≤ x_1≤ x ≤ x_2 ≤ 10^8, -10^8 ≤ y_1 ≤ y ≤ y_2 ≤ 10^8).
Output
For each test case, output "YES" in a separate line, if there exists a walk satisfying her wishes. Otherwise, output "NO" in a separate line.
You can print each letter in any case (upper or lower).
Example
Input
6
3 2 2 2
0 0 -2 -2 2 2
3 1 4 1
0 0 -1 -1 1 1
1 1 1 1
1 1 1 1 1 1
0 0 0 1
0 0 0 0 0 1
5 1 1 1
0 0 -100 -100 0 100
1 1 5 1
0 0 -100 -100 100 0
Output
Yes
No
No
Yes
Yes
Yes
Note
In the first test case, one valid exercising walk is $$$(0,0)→ (-1,0) → (-2,0)→ (-2,1) → (-2,2)→ (-1,2)→(0,2)→ (0,1)→ (0,0) → (-1,0)$$$
Submitted Solution:
```
ts = int(input())
for _ in range(ts):
a,b,c,d = [int(i) for i in input().strip().split(" ")]
x,y,x1,y1,x2,y2 = [int(i) for i in input().strip().split(" ")]
res = True
l,r = [a,b]
if a>0 or b>0:
if (x2-x1)<1:
res = False
elif l>r:
if (x-x1)<(l-r):
res = False
else:
if (x2-x)<(r-l):
res = False
a,b,x,x1,x2 = [c,d,y,y1,y2]
l, r = [a, b]
if a>0 or b>0:
if (x2-x1)<1:
res = False
elif l>r:
if (x-x1)<(l-r):
res = False
else:
if (x2-x)<(r-l):
res = False
rs1 = "YES" if res else "NO"
print(rs1)
``` | instruction | 0 | 81,849 | 15 | 163,698 |
Yes | output | 1 | 81,849 | 15 | 163,699 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Alice has a cute cat. To keep her cat fit, Alice wants to design an exercising walk for her cat!
Initially, Alice's cat is located in a cell (x,y) of an infinite grid. According to Alice's theory, cat needs to move:
* exactly a steps left: from (u,v) to (u-1,v);
* exactly b steps right: from (u,v) to (u+1,v);
* exactly c steps down: from (u,v) to (u,v-1);
* exactly d steps up: from (u,v) to (u,v+1).
Note that the moves can be performed in an arbitrary order. For example, if the cat has to move 1 step left, 3 steps right and 2 steps down, then the walk right, down, left, right, right, down is valid.
Alice, however, is worrying that her cat might get lost if it moves far away from her. So she hopes that her cat is always in the area [x_1,x_2]× [y_1,y_2], i.e. for every cat's position (u,v) of a walk x_1 ≤ u ≤ x_2 and y_1 ≤ v ≤ y_2 holds.
Also, note that the cat can visit the same cell multiple times.
Can you help Alice find out if there exists a walk satisfying her wishes?
Formally, the walk should contain exactly a+b+c+d unit moves (a to the left, b to the right, c to the down, d to the up). Alice can do the moves in any order. Her current position (u, v) should always satisfy the constraints: x_1 ≤ u ≤ x_2, y_1 ≤ v ≤ y_2. The staring point is (x, y).
You are required to answer t test cases independently.
Input
The first line contains a single integer t (1 ≤ t ≤ 10^3) — the number of testcases.
The first line of each test case contains four integers a, b, c, d (0 ≤ a,b,c,d ≤ 10^8, a+b+c+d ≥ 1).
The second line of the test case contains six integers x, y, x_1, y_1, x_2, y_2 (-10^8 ≤ x_1≤ x ≤ x_2 ≤ 10^8, -10^8 ≤ y_1 ≤ y ≤ y_2 ≤ 10^8).
Output
For each test case, output "YES" in a separate line, if there exists a walk satisfying her wishes. Otherwise, output "NO" in a separate line.
You can print each letter in any case (upper or lower).
Example
Input
6
3 2 2 2
0 0 -2 -2 2 2
3 1 4 1
0 0 -1 -1 1 1
1 1 1 1
1 1 1 1 1 1
0 0 0 1
0 0 0 0 0 1
5 1 1 1
0 0 -100 -100 0 100
1 1 5 1
0 0 -100 -100 100 0
Output
Yes
No
No
Yes
Yes
Yes
Note
In the first test case, one valid exercising walk is $$$(0,0)→ (-1,0) → (-2,0)→ (-2,1) → (-2,2)→ (-1,2)→(0,2)→ (0,1)→ (0,0) → (-1,0)$$$
Submitted Solution:
```
for t in range(int(input())):
a, b, c, d=map(int, input().split())
x, y, x1, x2, y1, y2=map(int, input().split())
flag=1
if b-a>x2-x or a-b>x-x1:
flag=0
if d-c>y2-y or c-d>y-y2:
flag=0
if x1==x2 and a+b>0:
flag=0
if y1==y1 and c+d>0:
flag=0
if flag==1:
print("YES")
else:
print("NO")
``` | instruction | 0 | 81,850 | 15 | 163,700 |
No | output | 1 | 81,850 | 15 | 163,701 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Alice has a cute cat. To keep her cat fit, Alice wants to design an exercising walk for her cat!
Initially, Alice's cat is located in a cell (x,y) of an infinite grid. According to Alice's theory, cat needs to move:
* exactly a steps left: from (u,v) to (u-1,v);
* exactly b steps right: from (u,v) to (u+1,v);
* exactly c steps down: from (u,v) to (u,v-1);
* exactly d steps up: from (u,v) to (u,v+1).
Note that the moves can be performed in an arbitrary order. For example, if the cat has to move 1 step left, 3 steps right and 2 steps down, then the walk right, down, left, right, right, down is valid.
Alice, however, is worrying that her cat might get lost if it moves far away from her. So she hopes that her cat is always in the area [x_1,x_2]× [y_1,y_2], i.e. for every cat's position (u,v) of a walk x_1 ≤ u ≤ x_2 and y_1 ≤ v ≤ y_2 holds.
Also, note that the cat can visit the same cell multiple times.
Can you help Alice find out if there exists a walk satisfying her wishes?
Formally, the walk should contain exactly a+b+c+d unit moves (a to the left, b to the right, c to the down, d to the up). Alice can do the moves in any order. Her current position (u, v) should always satisfy the constraints: x_1 ≤ u ≤ x_2, y_1 ≤ v ≤ y_2. The staring point is (x, y).
You are required to answer t test cases independently.
Input
The first line contains a single integer t (1 ≤ t ≤ 10^3) — the number of testcases.
The first line of each test case contains four integers a, b, c, d (0 ≤ a,b,c,d ≤ 10^8, a+b+c+d ≥ 1).
The second line of the test case contains six integers x, y, x_1, y_1, x_2, y_2 (-10^8 ≤ x_1≤ x ≤ x_2 ≤ 10^8, -10^8 ≤ y_1 ≤ y ≤ y_2 ≤ 10^8).
Output
For each test case, output "YES" in a separate line, if there exists a walk satisfying her wishes. Otherwise, output "NO" in a separate line.
You can print each letter in any case (upper or lower).
Example
Input
6
3 2 2 2
0 0 -2 -2 2 2
3 1 4 1
0 0 -1 -1 1 1
1 1 1 1
1 1 1 1 1 1
0 0 0 1
0 0 0 0 0 1
5 1 1 1
0 0 -100 -100 0 100
1 1 5 1
0 0 -100 -100 100 0
Output
Yes
No
No
Yes
Yes
Yes
Note
In the first test case, one valid exercising walk is $$$(0,0)→ (-1,0) → (-2,0)→ (-2,1) → (-2,2)→ (-1,2)→(0,2)→ (0,1)→ (0,0) → (-1,0)$$$
Submitted Solution:
```
t=int(input())
for i in range(t):
a,b,c,d=map(int,input().split())
x,y,x1,y1,x2,y2 = map(int, input().split())
if not ((x1>x or x2<x or y1>y or y2<y) and (x1==x2==x and (a>0 or b>0) or y1==y2==y and (c>0 or d>0))):
x-=a
x+=b
y-=c
y+=d
if x1<=x and x<=x2 and y1<=y and y<=y2:
print('Yes')
else:
print('No')
else:
print('No')
``` | instruction | 0 | 81,851 | 15 | 163,702 |
No | output | 1 | 81,851 | 15 | 163,703 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Alice has a cute cat. To keep her cat fit, Alice wants to design an exercising walk for her cat!
Initially, Alice's cat is located in a cell (x,y) of an infinite grid. According to Alice's theory, cat needs to move:
* exactly a steps left: from (u,v) to (u-1,v);
* exactly b steps right: from (u,v) to (u+1,v);
* exactly c steps down: from (u,v) to (u,v-1);
* exactly d steps up: from (u,v) to (u,v+1).
Note that the moves can be performed in an arbitrary order. For example, if the cat has to move 1 step left, 3 steps right and 2 steps down, then the walk right, down, left, right, right, down is valid.
Alice, however, is worrying that her cat might get lost if it moves far away from her. So she hopes that her cat is always in the area [x_1,x_2]× [y_1,y_2], i.e. for every cat's position (u,v) of a walk x_1 ≤ u ≤ x_2 and y_1 ≤ v ≤ y_2 holds.
Also, note that the cat can visit the same cell multiple times.
Can you help Alice find out if there exists a walk satisfying her wishes?
Formally, the walk should contain exactly a+b+c+d unit moves (a to the left, b to the right, c to the down, d to the up). Alice can do the moves in any order. Her current position (u, v) should always satisfy the constraints: x_1 ≤ u ≤ x_2, y_1 ≤ v ≤ y_2. The staring point is (x, y).
You are required to answer t test cases independently.
Input
The first line contains a single integer t (1 ≤ t ≤ 10^3) — the number of testcases.
The first line of each test case contains four integers a, b, c, d (0 ≤ a,b,c,d ≤ 10^8, a+b+c+d ≥ 1).
The second line of the test case contains six integers x, y, x_1, y_1, x_2, y_2 (-10^8 ≤ x_1≤ x ≤ x_2 ≤ 10^8, -10^8 ≤ y_1 ≤ y ≤ y_2 ≤ 10^8).
Output
For each test case, output "YES" in a separate line, if there exists a walk satisfying her wishes. Otherwise, output "NO" in a separate line.
You can print each letter in any case (upper or lower).
Example
Input
6
3 2 2 2
0 0 -2 -2 2 2
3 1 4 1
0 0 -1 -1 1 1
1 1 1 1
1 1 1 1 1 1
0 0 0 1
0 0 0 0 0 1
5 1 1 1
0 0 -100 -100 0 100
1 1 5 1
0 0 -100 -100 100 0
Output
Yes
No
No
Yes
Yes
Yes
Note
In the first test case, one valid exercising walk is $$$(0,0)→ (-1,0) → (-2,0)→ (-2,1) → (-2,2)→ (-1,2)→(0,2)→ (0,1)→ (0,0) → (-1,0)$$$
Submitted Solution:
```
t = int(input())
for i in range(0, t):
a, b, c, d = map(int, input().split())
x, y, x1, y1, x2, y2 = map(int, input().split())
kok_levo, kok_desno, kok_gor, kok_dol, el, eg = 0, 0, 0, 0, 0, 0
if b - a < 0:
kok_levo = abs(b-a)
else:
kok_desno = b - a
if d - c < 0:
kok_dol = abs(d - c)
else:
kok_gor = d - c
if a == b and (d != 0 and c != 0):
el = 1
elif d == c and (a != 0 and b != 0):
eg = 1
plac_levo = x - x1
plac_desno = x2 - x
plac_dol = y - y1
plac_gor = y2 - y
if el == 0 and eg == 0:
if plac_levo >= kok_levo and plac_desno >= kok_desno and plac_dol >= kok_dol and plac_gor >= kok_gor:
print("Yes")
else:
print("No")
elif el == 1 and eg == 0:
if plac_levo >= 1 or plac_desno >= 1 and plac_dol >= kok_dol and plac_gor >= kok_gor:
print("Yes")
else:
print("No")
elif el == 1 and eg == 1:
if plac_levo >= 1 or plac_desno >= 1 and plac_dol >= 1 or plac_gor >= 1:
print("Yes")
else:
print("No")
elif el == 0 and eg == 1:
if plac_levo >= kok_levo and plac_desno >= kok_desno and plac_dol >= 1 or plac_gor >= 1:
print("Yes")
else:
print("No")
else:
print("No")
``` | instruction | 0 | 81,852 | 15 | 163,704 |
No | output | 1 | 81,852 | 15 | 163,705 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Alice has a cute cat. To keep her cat fit, Alice wants to design an exercising walk for her cat!
Initially, Alice's cat is located in a cell (x,y) of an infinite grid. According to Alice's theory, cat needs to move:
* exactly a steps left: from (u,v) to (u-1,v);
* exactly b steps right: from (u,v) to (u+1,v);
* exactly c steps down: from (u,v) to (u,v-1);
* exactly d steps up: from (u,v) to (u,v+1).
Note that the moves can be performed in an arbitrary order. For example, if the cat has to move 1 step left, 3 steps right and 2 steps down, then the walk right, down, left, right, right, down is valid.
Alice, however, is worrying that her cat might get lost if it moves far away from her. So she hopes that her cat is always in the area [x_1,x_2]× [y_1,y_2], i.e. for every cat's position (u,v) of a walk x_1 ≤ u ≤ x_2 and y_1 ≤ v ≤ y_2 holds.
Also, note that the cat can visit the same cell multiple times.
Can you help Alice find out if there exists a walk satisfying her wishes?
Formally, the walk should contain exactly a+b+c+d unit moves (a to the left, b to the right, c to the down, d to the up). Alice can do the moves in any order. Her current position (u, v) should always satisfy the constraints: x_1 ≤ u ≤ x_2, y_1 ≤ v ≤ y_2. The staring point is (x, y).
You are required to answer t test cases independently.
Input
The first line contains a single integer t (1 ≤ t ≤ 10^3) — the number of testcases.
The first line of each test case contains four integers a, b, c, d (0 ≤ a,b,c,d ≤ 10^8, a+b+c+d ≥ 1).
The second line of the test case contains six integers x, y, x_1, y_1, x_2, y_2 (-10^8 ≤ x_1≤ x ≤ x_2 ≤ 10^8, -10^8 ≤ y_1 ≤ y ≤ y_2 ≤ 10^8).
Output
For each test case, output "YES" in a separate line, if there exists a walk satisfying her wishes. Otherwise, output "NO" in a separate line.
You can print each letter in any case (upper or lower).
Example
Input
6
3 2 2 2
0 0 -2 -2 2 2
3 1 4 1
0 0 -1 -1 1 1
1 1 1 1
1 1 1 1 1 1
0 0 0 1
0 0 0 0 0 1
5 1 1 1
0 0 -100 -100 0 100
1 1 5 1
0 0 -100 -100 100 0
Output
Yes
No
No
Yes
Yes
Yes
Note
In the first test case, one valid exercising walk is $$$(0,0)→ (-1,0) → (-2,0)→ (-2,1) → (-2,2)→ (-1,2)→(0,2)→ (0,1)→ (0,0) → (-1,0)$$$
Submitted Solution:
```
def iv(a,b,c):
if((c>=a) and (c<=b)):
return True
else :
return False
for _ in range(int(input())):
a,b,c,d=map(int,input().split())
x,y,x1,y1,x2,y2=map(int,input().split())
mx,my=b-a,d-c
if((iv(x1,x2,mx) == True) and (iv(y1,y2,my) == True)):
if(((x1 == x) and(x2==x)) and (a!=0) and (b!=0)):
print("No")
elif(((y1 == y) and (y2 == y)) and (c!=0) and (d!=0)):
print("No")
else:
print("Yes")
else:
print("No")
``` | instruction | 0 | 81,853 | 15 | 163,706 |
No | output | 1 | 81,853 | 15 | 163,707 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There is a square box 6 × 6 in size. It contains 36 chips 1 × 1 in size. Those chips contain 36 different characters — "0"-"9" and "A"-"Z". There is exactly one chip with each character.
You are allowed to make the following operations: you may choose one of 6 rows or one of 6 columns and cyclically shift the chips there to one position to the left or to the right (for the row) or upwards or downwards (for the column). Those operations are allowed to perform several times.
To solve the puzzle is to shift the chips using the above described operations so that they were written in the increasing order (exactly equal to the right picture). An example of solving the puzzle is shown on a picture below.
<image>
Write a program that finds the sequence of operations that solves the puzzle. That sequence should not necessarily be shortest, but you should not exceed the limit of 10000 operations. It is guaranteed that the solution always exists.
Input
The input data are represented by 6 lines containing 6 characters each. They are the puzzle's initial position. Those lines contain each character from the string "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ" exactly once.
Output
On the first line print number n, which is the number of operations. On the next n lines print the sequence of operations one per line. An operation is described by a word consisting of two characters. The first character shows the direction where the row or the column will be shifted. The possible directions are "L", "R" (to the left, to the right correspondingly, we shift a row), "U", "D" (upwards, downwards correspondingly, we shift a column). The second character is the number of the row (or the column), it is an integer from "1" to "6". The rows are numbered from the top to the bottom, the columns are numbered from the left to the right.
The number of operations should not exceed 104. If there are several solutions, print any of them.
Examples
Input
01W345
729AB6
CD8FGH
IJELMN
OPKRST
UVQXYZ
Output
2
R2
U3 | instruction | 0 | 82,226 | 15 | 164,452 |
Tags: constructive algorithms
Correct Solution:
```
ls="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
s,cnt,a1,a2=[],0,[],[]
for i in range(6):
s.append(list(input()))
def add(c,i):
global cnt
cnt+=1
a1.append(c)
a2.append(i)
def right(i):
add('R',i+1)
tmp=s[i][5]
for j in range(5,0,-1):
s[i][j]=s[i][j-1]
s[i][0]=tmp
def left(i):
add('L',i+1)
tmp=s[i][0]
for j in range(5):
s[i][j]=s[i][j+1]
s[i][5]=tmp
def up(j):
add('U',j+1)
tmp=s[0][j]
for i in range(5):
s[i][j]=s[i+1][j]
s[5][j]=tmp
def down(j):
add('D',j+1)
tmp=s[5][j]
for i in range(5,0,-1):
s[i][j]=s[i-1][j]
s[0][j]=tmp
def chg(i1,j1,i2,j2):
if i1==i2:
right(i1);up(j1);right(i1);down(j1)
right(i1);up(j1);right(i1);down(j1)
right(i1);up(j1);right(i1);right(i1);down(j1)
else:
down(j1);left(i1);down(j1);right(i1)
down(j1);left(i1);down(j1);right(i1)
down(j1);left(i1);down(j1);down(j1);right(i1)
for i in range(6):
for j in range(6):
toch=ls[i*6+j]
for ni in range(6):
for nj in range(6):
if s[ni][nj]==toch:
ii,jj=ni,nj
while jj>j:
chg(ii,jj-1,ii,jj)
jj-=1
while jj<j:
chg(ii,jj,ii,jj+1)
jj+=1
while ii>i:
chg(ii-1,jj,ii,jj)
ii-=1
print(cnt)
for i in range(cnt):
print(a1[i]+str(a2[i]))
``` | output | 1 | 82,226 | 15 | 164,453 |
Provide a correct Python 3 solution for this coding contest problem.
There is a frog living in a big pond. He loves jumping between lotus leaves floating on the pond. Interestingly, these leaves have strange habits. First, a leaf will sink into the water after the frog jumps from it. Second, they are aligned regularly as if they are placed on the grid points as in the example below.
<image>
Figure 1: Example of floating leaves
Recently, He came up with a puzzle game using these habits. At the beginning of the game, he is on some leaf and faces to the upper, lower, left or right side. He can jump forward or to the left or right relative to his facing direction, but not backward or diagonally. For example, suppose he is facing to the left side, then he can jump to the left, upper and lower sides but not to the right side. In each jump, he will land on the nearest leaf on his jumping direction and face to that direction regardless of his previous state. The leaf he was on will vanish into the water after the jump. The goal of this puzzle is to jump from leaf to leaf until there is only one leaf remaining.
See the example shown in the figure below.
<image>
In this situation, he has three choices, namely, the leaves A, B and C. Note that he cannot jump to the leaf D since he cannot jump backward. Suppose that he choose the leaf B. After jumping there, the situation will change as shown in the following figure.
He can jump to either leaf E or F next.
After some struggles, he found this puzzle difficult, since there are a lot of leaves on the pond. Can you help him to find out a solution?
<image>
Input
H W
c1,1 ... c1,W
.
.
.
cH,1 ... cH,W
The first line of the input contains two positive integers H and W (1 ≤ H,W ≤ 10). The following H lines, which contain W characters each, describe the initial configuration of the leaves and the frog using following characters:
* '.’ : water
* ‘o’ : a leaf
* ‘U’ : a frog facing upward (i.e. to the upper side) on a leaf
* ‘D’ : a frog facing downward (i.e. to the lower side) on a leaf
* ‘L’ : a frog facing leftward (i.e. to the left side) on a leaf
* ‘R’ : a frog facing rightward (i.e. to the right side) on a leaf
You can assume that there is only one frog in each input. You can also assume that the total number of leaves (including the leaf the frog is initially on) is at most 30.
Output
Output a line consists of the characters ‘U’ (up), ‘D’ (down), ‘L’ (left) and ‘R’ (right) that describes a series of movements. The output should not contain any other characters, such as spaces. You can assume that there exists only one solution for each input.
Examples
Input
2 3
Uo.
.oo
Output
RDR
Input
10 10
.o....o...
o.oo......
..oo..oo..
..o.......
..oo..oo..
..o...o.o.
o..U.o....
oo......oo
oo........
oo..oo....
Output
URRULULDDLUURDLLLURRDLDDDRRDR
Input
10 1
D
.
.
.
.
.
.
.
.
o
Output
D | instruction | 0 | 82,523 | 15 | 165,046 |
"Correct Solution:
```
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**13
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def main():
h,w = LI()
a = [[c for c in S()] for _ in range(h)]
s = None
lc = 0
for i in range(h):
for j in range(w):
c = a[i][j]
if c == '.':
continue
if c == 'o':
lc += 1
continue
s = (i,j,c)
def f(i,j,c,d):
if d == lc:
return (True, '')
a[i][j] = '.'
if c != 'U':
for k in range(i+1,h):
if a[k][j] == 'o':
rf,rs = f(k,j,'D',d+1)
if rf:
return (True, 'D' + rs)
break
if c != 'D':
for k in range(i-1,-1,-1):
if a[k][j] == 'o':
rf,rs = f(k,j,'U',d+1)
if rf:
return (True, 'U' + rs)
break
if c != 'L':
for k in range(j+1,w):
if a[i][k] == 'o':
rf,rs = f(i,k,'R',d+1)
if rf:
return (True, 'R' + rs)
break
if c != 'R':
for k in range(j-1,-1,-1):
if a[i][k] == 'o':
rf,rs = f(i,k,'L',d+1)
if rf:
return (True, 'L' + rs)
break
a[i][j] = 'o'
return (False, None)
rf,rs = f(s[0],s[1],s[2],0)
return rs
print(main())
``` | output | 1 | 82,523 | 15 | 165,047 |
Provide a correct Python 3 solution for this coding contest problem.
The goal of 8 Queens Problem is to put eight queens on a chess-board such that none of them threatens any of others. A queen threatens the squares in the same row, in the same column, or on the same diagonals as shown in the following figure.
<image>
For a given chess board where $k$ queens are already placed, find the solution of the 8 queens problem.
Constraints
* There is exactly one solution
Input
In the first line, an integer $k$ is given. In the following $k$ lines, each square where a queen is already placed is given by two integers $r$ and $c$. $r$ and $c$ respectively denotes the row number and the column number. The row/column numbers start with 0.
Output
Print a $8 \times 8$ chess board by strings where a square with a queen is represented by 'Q' and an empty square is represented by '.'.
Example
Input
2
2 2
5 3
Output
......Q.
Q.......
..Q.....
.......Q
.....Q..
...Q....
.Q......
....Q... | instruction | 0 | 82,528 | 15 | 165,056 |
"Correct Solution:
```
N = 8
flag_row = [False]*N
flag_col = [False]*N
flag_diag_right = [False]*(2*N-1)
flag_diag_left = [False]*(2*N-1)
B = [ [False for n in range(N)] for n in range(N)]
def ShowBoard():
for i in range(N):
for j in range(N):
if B[i][j] :
if flag_row[i] != j:
return
for i in range(N):
for j in range(N):
if flag_row[i] == j:
print("Q", end = "")
else:
print(".", end = "")
print()
def SetQueen(i):
if i == N :
ShowBoard()
return
for j in range(N):
if flag_col[j] == False and flag_diag_left[i + j] == False and flag_diag_right[i - j + (N -1)] == False :
flag_row[i] = j
flag_col[j] = True
flag_diag_left[i + j] = True
flag_diag_right[i - j + (N -1)] = True
SetQueen(i + 1)
flag_row[i] = False
flag_col[j] = False
flag_diag_left[i + j] = False
flag_diag_right[i - j + (N -1)] = False
def Main():
K = int(input())
for k in range(K):
r, c = map(int, input().split())
B[r][c] = True
SetQueen(0)
Main()
``` | output | 1 | 82,528 | 15 | 165,057 |
Provide a correct Python 3 solution for this coding contest problem.
The goal of 8 Queens Problem is to put eight queens on a chess-board such that none of them threatens any of others. A queen threatens the squares in the same row, in the same column, or on the same diagonals as shown in the following figure.
<image>
For a given chess board where $k$ queens are already placed, find the solution of the 8 queens problem.
Constraints
* There is exactly one solution
Input
In the first line, an integer $k$ is given. In the following $k$ lines, each square where a queen is already placed is given by two integers $r$ and $c$. $r$ and $c$ respectively denotes the row number and the column number. The row/column numbers start with 0.
Output
Print a $8 \times 8$ chess board by strings where a square with a queen is represented by 'Q' and an empty square is represented by '.'.
Example
Input
2
2 2
5 3
Output
......Q.
Q.......
..Q.....
.......Q
.....Q..
...Q....
.Q......
....Q... | instruction | 0 | 82,529 | 15 | 165,058 |
"Correct Solution:
```
import itertools
k = int(input())
X = sorted([list(map(int, input().split())) for _ in range(k)])
for l in list(itertools.permutations(range(8))):
flag = True
for x in X:
if l[x[0]] != x[1]:
flag = False
if flag:
flag2= True
check = []
for i in range(8):
for j in range(1,8-i):
check.append([i+j,l[i]+j])
check.append([i+j,l[i]-j])
for c in check:
if c[1] < 0 or c[1] > 8:
continue
else:
if c in [[i,l[i]] for i in range(8)]:
flag2 = False
if flag2:
#print(l)
#print(X)
#print(check)
for i in range(8):
tmp = ['.','.','.','.','.','.','.','.']
tmp[l[i]] = 'Q'
print(''.join(tmp))
break
``` | output | 1 | 82,529 | 15 | 165,059 |
Provide a correct Python 3 solution for this coding contest problem.
The goal of 8 Queens Problem is to put eight queens on a chess-board such that none of them threatens any of others. A queen threatens the squares in the same row, in the same column, or on the same diagonals as shown in the following figure.
<image>
For a given chess board where $k$ queens are already placed, find the solution of the 8 queens problem.
Constraints
* There is exactly one solution
Input
In the first line, an integer $k$ is given. In the following $k$ lines, each square where a queen is already placed is given by two integers $r$ and $c$. $r$ and $c$ respectively denotes the row number and the column number. The row/column numbers start with 0.
Output
Print a $8 \times 8$ chess board by strings where a square with a queen is represented by 'Q' and an empty square is represented by '.'.
Example
Input
2
2 2
5 3
Output
......Q.
Q.......
..Q.....
.......Q
.....Q..
...Q....
.Q......
....Q... | instruction | 0 | 82,530 | 15 | 165,060 |
"Correct Solution:
```
N = 8
FREE = -1
NOT_FREE = 1
def printBoard():
for i in range(N):
for j in range(N):
if X[i][j]:
if not Y[i][j]:
return
for i in range(N):
for j in range(N):
if Y[i][j]:
print("Q", end = "")
else:
print(".", end = "")
print("")
def recursive(i):
if i == N:
printBoard()
return
for j in range(N):
if col[j] == NOT_FREE or dpos[i + j] == NOT_FREE or dneg[i-j + N -1] == NOT_FREE:
continue
row[i] = NOT_FREE
col[j] = NOT_FREE
dpos[i + j] = NOT_FREE
dneg[i-j + N -1] = NOT_FREE
Y[i][j] = True
recursive(i + 1)
row[i] = FREE
col[j] = FREE
dpos[i + j] = FREE
dneg[i-j + N -1] = FREE
Y[i][j] = False
row = [FREE] * N
col = [FREE] * N
dpos = [FREE] * (2 * N - 1)
dneg = [FREE] * (2 * N - 1)
X = [[False for i in range(N)] for j in range(N)]
Y = [[False for i in range(N)] for j in range(N)]
n = int(input())
for i in range(n):
nums=list(map(int,input().split()))
X[nums[0]][nums[1]] = True
recursive(0)
``` | output | 1 | 82,530 | 15 | 165,061 |
Provide a correct Python 3 solution for this coding contest problem.
The goal of 8 Queens Problem is to put eight queens on a chess-board such that none of them threatens any of others. A queen threatens the squares in the same row, in the same column, or on the same diagonals as shown in the following figure.
<image>
For a given chess board where $k$ queens are already placed, find the solution of the 8 queens problem.
Constraints
* There is exactly one solution
Input
In the first line, an integer $k$ is given. In the following $k$ lines, each square where a queen is already placed is given by two integers $r$ and $c$. $r$ and $c$ respectively denotes the row number and the column number. The row/column numbers start with 0.
Output
Print a $8 \times 8$ chess board by strings where a square with a queen is represented by 'Q' and an empty square is represented by '.'.
Example
Input
2
2 2
5 3
Output
......Q.
Q.......
..Q.....
.......Q
.....Q..
...Q....
.Q......
....Q... | instruction | 0 | 82,531 | 15 | 165,062 |
"Correct Solution:
```
from itertools import permutations
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
def main():
k,*rc = map(int, read().split())
tmp = []
ng_list_add = []
ng_list_sub = []
for pattern in permutations(range(8)):
flag = True
for r, c in enumerate(pattern):
if r + c in ng_list_add or r - c in ng_list_sub:
flag = False
break
ng_list_add.append(r+c)
ng_list_sub.append(r-c)
if flag:
tmp.append(pattern)
ng_list_add = []
ng_list_sub = []
RC = []
for r, c in zip(*[iter(rc)]*2):
RC.append((r, c))
ans_place = None
for p in tmp:
flag = True
for r, c in RC:
if p[r] != c:
flag = False
break
if flag:
ans_place = p
break
ans = []
for i in ans_place:
line = "." * i + "Q" + "." * (7-i)
ans.append(line)
print("\n".join(ans))
if __name__ == "__main__":
main()
``` | output | 1 | 82,531 | 15 | 165,063 |
Provide a correct Python 3 solution for this coding contest problem.
The goal of 8 Queens Problem is to put eight queens on a chess-board such that none of them threatens any of others. A queen threatens the squares in the same row, in the same column, or on the same diagonals as shown in the following figure.
<image>
For a given chess board where $k$ queens are already placed, find the solution of the 8 queens problem.
Constraints
* There is exactly one solution
Input
In the first line, an integer $k$ is given. In the following $k$ lines, each square where a queen is already placed is given by two integers $r$ and $c$. $r$ and $c$ respectively denotes the row number and the column number. The row/column numbers start with 0.
Output
Print a $8 \times 8$ chess board by strings where a square with a queen is represented by 'Q' and an empty square is represented by '.'.
Example
Input
2
2 2
5 3
Output
......Q.
Q.......
..Q.....
.......Q
.....Q..
...Q....
.Q......
....Q... | instruction | 0 | 82,532 | 15 | 165,064 |
"Correct Solution:
```
import itertools
K=int(input())
R=[]
C=[]
RCd={}
rflag=[ 0 for _ in range(8) ]
for i in range(K):
r,c=map(int,input().split())
R.append(r)
C.append(c)
RCd[r]=c
rflag[r]=1
l=[ i for i in range(8) ]
P=itertools.permutations(l,8)
for p in P:
p=list(p)
flag=0
for i in range(8):
if rflag[i]==1 and p[i]!=RCd[i]:
flag=1
break
for j in range(8):
if i==j: continue
if abs(i-j)==p[i]-p[j]:
flag=1
break
#cleared
if flag==1:continue
for i in range(8):
ans='........'
print(ans[:p[i]]+'Q'+ans[p[i]+1:])
exit()
``` | output | 1 | 82,532 | 15 | 165,065 |
Provide a correct Python 3 solution for this coding contest problem.
The goal of 8 Queens Problem is to put eight queens on a chess-board such that none of them threatens any of others. A queen threatens the squares in the same row, in the same column, or on the same diagonals as shown in the following figure.
<image>
For a given chess board where $k$ queens are already placed, find the solution of the 8 queens problem.
Constraints
* There is exactly one solution
Input
In the first line, an integer $k$ is given. In the following $k$ lines, each square where a queen is already placed is given by two integers $r$ and $c$. $r$ and $c$ respectively denotes the row number and the column number. The row/column numbers start with 0.
Output
Print a $8 \times 8$ chess board by strings where a square with a queen is represented by 'Q' and an empty square is represented by '.'.
Example
Input
2
2 2
5 3
Output
......Q.
Q.......
..Q.....
.......Q
.....Q..
...Q....
.Q......
....Q... | instruction | 0 | 82,533 | 15 | 165,066 |
"Correct Solution:
```
import copy as cp
N = 8
ans = []
def out(M):
for i in range(N):
for j in range(N):
print(M[i][j], end="")
print("")
def DFS(r,c,dp,dn,qn):
global ans
if qn == N:
for h in range(N):
for w in range(N):
if r[h] & c[w] & dp[h+w] & dn[w-h+7]:
ans.append([h,w])
return True
return False
for h in range(N):
for w in range(N):
if r[h] & c[w] & dp[h+w] & dn[w-h+7]:
new_r = cp.deepcopy(r)
new_c = cp.deepcopy(c)
new_dp = cp.deepcopy(dp)
new_dn = cp.deepcopy(dn)
new_r[h],new_c[w],new_dp[h+w],new_dn[w-h+7] = False,False,False,False
if DFS(new_r,new_c,new_dp,new_dn,qn+1):
ans.append([h,w])
return True
return False
def main():
row = [True]*N
col = [True]*N
dp = [True]*(2*N-1)
dn = [True]*(2*N-1)
k = int(input())
MAP = [["." for _ in range(N)] for __ in range(N)]
for _ in range(k):
h,w = map(int,input().split())
MAP[h][w] = "Q"
row[h] = False
col[w] = False
dp[w+h] = False
dn[w-h+7] = False
DFS(row,col,dp,dn,k+1)
for h,w in ans:
MAP[h][w] = "Q"
out(MAP)
main()
``` | output | 1 | 82,533 | 15 | 165,067 |
Provide a correct Python 3 solution for this coding contest problem.
The goal of 8 Queens Problem is to put eight queens on a chess-board such that none of them threatens any of others. A queen threatens the squares in the same row, in the same column, or on the same diagonals as shown in the following figure.
<image>
For a given chess board where $k$ queens are already placed, find the solution of the 8 queens problem.
Constraints
* There is exactly one solution
Input
In the first line, an integer $k$ is given. In the following $k$ lines, each square where a queen is already placed is given by two integers $r$ and $c$. $r$ and $c$ respectively denotes the row number and the column number. The row/column numbers start with 0.
Output
Print a $8 \times 8$ chess board by strings where a square with a queen is represented by 'Q' and an empty square is represented by '.'.
Example
Input
2
2 2
5 3
Output
......Q.
Q.......
..Q.....
.......Q
.....Q..
...Q....
.Q......
....Q... | instruction | 0 | 82,534 | 15 | 165,068 |
"Correct Solution:
```
# -*- coding: utf-8 -*-
if __name__ == '__main__':
N = 8
FREE = -1
NOT_FREE = 1
row = [FREE] * N
col = [FREE] * N
dpos = [FREE] * (2 * N - 1)
dneg = [FREE] * (2 * N - 1)
X = [["." for _ in range(N)] for _ in range(N)]
k = int(input())
for _ in range(k):
i, j = map(int, input().split())
X[i][j] = "Q"
row[i] = col[j] = dpos[i + j] = dneg[i - j + N - 1] = NOT_FREE
def printBoard(X):
for i in range(N):
print("".join(X[i]))
def recursive(i):
if i == N:
printBoard(X)
return
if "Q" in X[i]:
recursive(i + 1)
for j in range(N):
if NOT_FREE in [row[i], col[j], dpos[i + j], dneg[i - j + N - 1]]:
continue
else:
X[i][j] = "Q"
row[i] = col[j] = dpos[i + j] = dneg[i - j + N - 1] = NOT_FREE
recursive(i + 1)
X[i][j] = "."
row[i] = col[j] = dpos[i + j] = dneg[i - j + N - 1] = FREE
recursive(0)
``` | output | 1 | 82,534 | 15 | 165,069 |
Provide a correct Python 3 solution for this coding contest problem.
The goal of 8 Queens Problem is to put eight queens on a chess-board such that none of them threatens any of others. A queen threatens the squares in the same row, in the same column, or on the same diagonals as shown in the following figure.
<image>
For a given chess board where $k$ queens are already placed, find the solution of the 8 queens problem.
Constraints
* There is exactly one solution
Input
In the first line, an integer $k$ is given. In the following $k$ lines, each square where a queen is already placed is given by two integers $r$ and $c$. $r$ and $c$ respectively denotes the row number and the column number. The row/column numbers start with 0.
Output
Print a $8 \times 8$ chess board by strings where a square with a queen is represented by 'Q' and an empty square is represented by '.'.
Example
Input
2
2 2
5 3
Output
......Q.
Q.......
..Q.....
.......Q
.....Q..
...Q....
.Q......
....Q... | instruction | 0 | 82,535 | 15 | 165,070 |
"Correct Solution:
```
from itertools import permutations
BLANK = 0
Q = 1
WALL = 2
def to_board_pos(x, y):
return x * 10 + y
def place_queen(pos, board):
assert board[pos] != WALL
if board[pos] == Q:
return False, None
board[pos] = Q
directions = [-10, -9, 1, 11, 10, 9, -1, -11]
for d in directions:
restrict_board(pos, d, board)
return True, board
def restrict_board(pos, direction, board):
cur = pos+direction
while board[cur] != WALL:
board[cur] = Q
cur += direction
def check(pattern, board):
b = board[:]
for i, p in enumerate(pattern):
ok, b = place_queen(to_board_pos(i+1, p), b)
if not ok:
return False
return True
def print_board(board):
for i in range(10):
for j in range(10):
pos = to_board_pos(i, j)
print(str(board[pos]) + " ", end="")
print("")
n = int(input())
initial_queens = [(0, 0) for i in range(n)]
for i in range(n):
x, y = map(int, input().split())
initial_queens[i] = (x, y)
board = [BLANK] * 100
for i, _ in enumerate(board):
if 0 <= i <= 9 or 90 <= i <= 99:
board[i] = WALL
continue
if i % 10 == 0 or i % 10 == 9:
board[i] = WALL
continue
perm_seed = [i+1 for i in range(8)]
patterns = permutations(perm_seed)
ans = [0] * 8
for pattern in patterns:
init_ok = True
for iq in initial_queens:
if pattern[iq[0]] != iq[1] + 1:
init_ok = False
break
if init_ok:
if check(pattern, board):
ans = pattern
break
for i, a in enumerate(ans):
board[to_board_pos(i+1, a)] = Q
for i in range(1, 9):
for j in range(1, 9):
pos = to_board_pos(i, j)
if board[pos] == BLANK:
print(".", end="")
elif board[pos] == Q:
print("Q", end="")
print("")
``` | output | 1 | 82,535 | 15 | 165,071 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The goal of 8 Queens Problem is to put eight queens on a chess-board such that none of them threatens any of others. A queen threatens the squares in the same row, in the same column, or on the same diagonals as shown in the following figure.
<image>
For a given chess board where $k$ queens are already placed, find the solution of the 8 queens problem.
Constraints
* There is exactly one solution
Input
In the first line, an integer $k$ is given. In the following $k$ lines, each square where a queen is already placed is given by two integers $r$ and $c$. $r$ and $c$ respectively denotes the row number and the column number. The row/column numbers start with 0.
Output
Print a $8 \times 8$ chess board by strings where a square with a queen is represented by 'Q' and an empty square is represented by '.'.
Example
Input
2
2 2
5 3
Output
......Q.
Q.......
..Q.....
.......Q
.....Q..
...Q....
.Q......
....Q...
Submitted Solution:
```
k=int(input())
l=[]
for _ in range(k):
l.append(list(map(int, input().split())))
import itertools
for s in itertools.permutations(range(8)):
t=[]
for _ in range(8):
t.append(([s[_], _]))
for z in l:
if not (z in t):
break
else:
#print(t)
for a in range(7):
for b in range(a+1, 8): # 2つの点を探してのループ
if abs(t[a][0]-t[b][0])==abs(t[a][1]-t[b][1]):
break
else:
continue
break
else:
tt=sorted(t)
#print(sorted(t))
for _ in range(8):
if tt[_][1]==0:
print("Q.......")
else:
print("."*tt[_][1]+"Q"+"."*(7-tt[_][1]))
continue
``` | instruction | 0 | 82,536 | 15 | 165,072 |
Yes | output | 1 | 82,536 | 15 | 165,073 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.