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.
So nearly half of the winter is over and Maria is dreaming about summer. She's fed up with skates and sleds, she was dreaming about Hopscotch all night long. It's a very popular children's game. The game field, the court, looks as is shown in the figure (all blocks are square and are numbered from bottom to top, blocks in the same row are numbered from left to right). Let us describe the hopscotch with numbers that denote the number of squares in the row, staring from the lowest one: 1-1-2-1-2-1-2-(1-2)..., where then the period is repeated (1-2).
<image>
The coordinate system is defined as shown in the figure. Side of all the squares are equal and have length a.
Maria is a very smart and clever girl, and she is concerned with quite serious issues: if she throws a stone into a point with coordinates (x, y), then will she hit some square? If the answer is positive, you are also required to determine the number of the square.
It is believed that the stone has fallen into the square if it is located strictly inside it. In other words a stone that has fallen on the square border is not considered a to hit a square.
Input
The only input line contains three integers: a, x, y, where a (1 β€ a β€ 100) is the side of the square, x and y ( - 106 β€ x β€ 106, 0 β€ y β€ 106) are coordinates of the stone.
Output
Print the number of the square, inside which the stone fell. If the stone is on a border of some stone or outside the court, print "-1" without the quotes.
Examples
Input
1 0 0
Output
-1
Input
3 1 1
Output
1
Input
3 0 10
Output
5
Input
3 0 7
Output
-1
Input
3 4 0
Output
-1
Submitted Solution:
```
a, x, y = list(int(b) for b in input().split())
if y % a == 0:
print(-1)
else:
if y < a:
if y > 0 and x < a/2 and x > -a/2:
print(1)
else:
print(-1)
else:
if (y // a) & 1: # one
if x < a/2 and x > -a/2:
print(2 + ((y//a - 1)//2)*3)
else:
print(-1)
else: # two
if x == 0:
print(-1)
elif x < 0:
if x > -a:
print((y // a - 2)//2*3 + 3)
else:
print(-1)
else:
if x < a:
print((y // a - 2)//2*3 + 4)
else:
print(-1)
``` | instruction | 0 | 22,224 | 15 | 44,448 |
Yes | output | 1 | 22,224 | 15 | 44,449 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
So nearly half of the winter is over and Maria is dreaming about summer. She's fed up with skates and sleds, she was dreaming about Hopscotch all night long. It's a very popular children's game. The game field, the court, looks as is shown in the figure (all blocks are square and are numbered from bottom to top, blocks in the same row are numbered from left to right). Let us describe the hopscotch with numbers that denote the number of squares in the row, staring from the lowest one: 1-1-2-1-2-1-2-(1-2)..., where then the period is repeated (1-2).
<image>
The coordinate system is defined as shown in the figure. Side of all the squares are equal and have length a.
Maria is a very smart and clever girl, and she is concerned with quite serious issues: if she throws a stone into a point with coordinates (x, y), then will she hit some square? If the answer is positive, you are also required to determine the number of the square.
It is believed that the stone has fallen into the square if it is located strictly inside it. In other words a stone that has fallen on the square border is not considered a to hit a square.
Input
The only input line contains three integers: a, x, y, where a (1 β€ a β€ 100) is the side of the square, x and y ( - 106 β€ x β€ 106, 0 β€ y β€ 106) are coordinates of the stone.
Output
Print the number of the square, inside which the stone fell. If the stone is on a border of some stone or outside the court, print "-1" without the quotes.
Examples
Input
1 0 0
Output
-1
Input
3 1 1
Output
1
Input
3 0 10
Output
5
Input
3 0 7
Output
-1
Input
3 4 0
Output
-1
Submitted Solution:
```
lt = list(input().split())
a, x, y = int(lt[0]), int(lt[1]), int(lt[2])
mx = 5 * a
fn = True
D=[3,5]
D1={1:1,2:2,4:5}
if y >= mx or y <= 0 or y % a == 0:
fn = False
else:
for i in range(5):
if y > a * i and y < a * (i + 1):
bx = i + 1
if bx in D:
if x>=a or x<=(-a) or x==0:
fn=False
else:
if bx==3:
if x>0:
rs=4
else:
rs=3
else:
if x>0:
rs=7
else:
rs=3
else:
if x>=(a/2) or x<=(-a/2):
fn=False
else:
rs=D1[bx]
if fn:
print(rs)
else:
print(-1)
``` | instruction | 0 | 22,225 | 15 | 44,450 |
No | output | 1 | 22,225 | 15 | 44,451 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
So nearly half of the winter is over and Maria is dreaming about summer. She's fed up with skates and sleds, she was dreaming about Hopscotch all night long. It's a very popular children's game. The game field, the court, looks as is shown in the figure (all blocks are square and are numbered from bottom to top, blocks in the same row are numbered from left to right). Let us describe the hopscotch with numbers that denote the number of squares in the row, staring from the lowest one: 1-1-2-1-2-1-2-(1-2)..., where then the period is repeated (1-2).
<image>
The coordinate system is defined as shown in the figure. Side of all the squares are equal and have length a.
Maria is a very smart and clever girl, and she is concerned with quite serious issues: if she throws a stone into a point with coordinates (x, y), then will she hit some square? If the answer is positive, you are also required to determine the number of the square.
It is believed that the stone has fallen into the square if it is located strictly inside it. In other words a stone that has fallen on the square border is not considered a to hit a square.
Input
The only input line contains three integers: a, x, y, where a (1 β€ a β€ 100) is the side of the square, x and y ( - 106 β€ x β€ 106, 0 β€ y β€ 106) are coordinates of the stone.
Output
Print the number of the square, inside which the stone fell. If the stone is on a border of some stone or outside the court, print "-1" without the quotes.
Examples
Input
1 0 0
Output
-1
Input
3 1 1
Output
1
Input
3 0 10
Output
5
Input
3 0 7
Output
-1
Input
3 4 0
Output
-1
Submitted Solution:
```
[a,x,y] = [int(i) for i in input().split()]
if y % a == 0:
print(-1)
exit()
n = y//a
if n==0 or n%2 :
if abs(x) >= a/2:
print(-1)
elif n==0:
print(1)
else:
print(2 + 3 * (n//2))
else:
if x==0 or abs(x) >= a/2:
print(-1)
elif x<0:
print(3 * (n//2))
else:
print(1 + 3 * (n//2))
``` | instruction | 0 | 22,226 | 15 | 44,452 |
No | output | 1 | 22,226 | 15 | 44,453 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
So nearly half of the winter is over and Maria is dreaming about summer. She's fed up with skates and sleds, she was dreaming about Hopscotch all night long. It's a very popular children's game. The game field, the court, looks as is shown in the figure (all blocks are square and are numbered from bottom to top, blocks in the same row are numbered from left to right). Let us describe the hopscotch with numbers that denote the number of squares in the row, staring from the lowest one: 1-1-2-1-2-1-2-(1-2)..., where then the period is repeated (1-2).
<image>
The coordinate system is defined as shown in the figure. Side of all the squares are equal and have length a.
Maria is a very smart and clever girl, and she is concerned with quite serious issues: if she throws a stone into a point with coordinates (x, y), then will she hit some square? If the answer is positive, you are also required to determine the number of the square.
It is believed that the stone has fallen into the square if it is located strictly inside it. In other words a stone that has fallen on the square border is not considered a to hit a square.
Input
The only input line contains three integers: a, x, y, where a (1 β€ a β€ 100) is the side of the square, x and y ( - 106 β€ x β€ 106, 0 β€ y β€ 106) are coordinates of the stone.
Output
Print the number of the square, inside which the stone fell. If the stone is on a border of some stone or outside the court, print "-1" without the quotes.
Examples
Input
1 0 0
Output
-1
Input
3 1 1
Output
1
Input
3 0 10
Output
5
Input
3 0 7
Output
-1
Input
3 4 0
Output
-1
Submitted Solution:
```
import math
side,x,y=map(int,input().split())
z=math.ceil(y/side)
if z==1 or z%2==0 :
if abs(x)>=side/2 or y%side==0:
print(-1)
else:
print(((z-1)//2)+z)
else:
if abs(x)>=side+(side/2) or y%side==0 or x==0:
print(-1)
else:
if x>0:
print(((z-1)//2)+z)
else:
print(((z-2)//2)+z)
``` | instruction | 0 | 22,227 | 15 | 44,454 |
No | output | 1 | 22,227 | 15 | 44,455 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
So nearly half of the winter is over and Maria is dreaming about summer. She's fed up with skates and sleds, she was dreaming about Hopscotch all night long. It's a very popular children's game. The game field, the court, looks as is shown in the figure (all blocks are square and are numbered from bottom to top, blocks in the same row are numbered from left to right). Let us describe the hopscotch with numbers that denote the number of squares in the row, staring from the lowest one: 1-1-2-1-2-1-2-(1-2)..., where then the period is repeated (1-2).
<image>
The coordinate system is defined as shown in the figure. Side of all the squares are equal and have length a.
Maria is a very smart and clever girl, and she is concerned with quite serious issues: if she throws a stone into a point with coordinates (x, y), then will she hit some square? If the answer is positive, you are also required to determine the number of the square.
It is believed that the stone has fallen into the square if it is located strictly inside it. In other words a stone that has fallen on the square border is not considered a to hit a square.
Input
The only input line contains three integers: a, x, y, where a (1 β€ a β€ 100) is the side of the square, x and y ( - 106 β€ x β€ 106, 0 β€ y β€ 106) are coordinates of the stone.
Output
Print the number of the square, inside which the stone fell. If the stone is on a border of some stone or outside the court, print "-1" without the quotes.
Examples
Input
1 0 0
Output
-1
Input
3 1 1
Output
1
Input
3 0 10
Output
5
Input
3 0 7
Output
-1
Input
3 4 0
Output
-1
Submitted Solution:
```
a,x,y=map(int,input().split())
if ((x>=a)or(x<=-a)or(y==y//a*a)or(y<0)):
print(-1)
exit(0)
elif ((x==0)and(y//a%2==0)and(y//a!=0)):
print(-1)
exit(0)
elif ((a%2==0)and(x>=a//2 or x<=-a//2)and(y//a%2==1 or y//a==0)):
print(-1)
exit(0)
z=y//a
#print(z)
if (z==0):
print(1)
elif ((z-1)%2==0):
print((z-1)//2*3+2)
else:
if (x<0):
print((z-1)//2*3+3)
else:
print((z-1)//2*3+4)
``` | instruction | 0 | 22,228 | 15 | 44,456 |
No | output | 1 | 22,228 | 15 | 44,457 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The Little Elephant loves chess very much.
One day the Little Elephant and his friend decided to play chess. They've got the chess pieces but the board is a problem. They've got an 8 Γ 8 checkered board, each square is painted either black or white. The Little Elephant and his friend know that a proper chessboard doesn't have any side-adjacent cells with the same color and the upper left cell is white. To play chess, they want to make the board they have a proper chessboard. For that the friends can choose any row of the board and cyclically shift the cells of the chosen row, that is, put the last (rightmost) square on the first place in the row and shift the others one position to the right. You can run the described operation multiple times (or not run it at all).
For example, if the first line of the board looks like that "BBBBBBWW" (the white cells of the line are marked with character "W", the black cells are marked with character "B"), then after one cyclic shift it will look like that "WBBBBBBW".
Help the Little Elephant and his friend to find out whether they can use any number of the described operations to turn the board they have into a proper chessboard.
Input
The input consists of exactly eight lines. Each line contains exactly eight characters "W" or "B" without any spaces: the j-th character in the i-th line stands for the color of the j-th cell of the i-th row of the elephants' board. Character "W" stands for the white color, character "B" stands for the black color.
Consider the rows of the board numbered from 1 to 8 from top to bottom, and the columns β from 1 to 8 from left to right. The given board can initially be a proper chessboard.
Output
In a single line print "YES" (without the quotes), if we can make the board a proper chessboard and "NO" (without the quotes) otherwise.
Examples
Input
WBWBWBWB
BWBWBWBW
BWBWBWBW
BWBWBWBW
WBWBWBWB
WBWBWBWB
BWBWBWBW
WBWBWBWB
Output
YES
Input
WBWBWBWB
WBWBWBWB
BBWBWWWB
BWBWBWBW
BWBWBWBW
BWBWBWWW
BWBWBWBW
BWBWBWBW
Output
NO
Note
In the first sample you should shift the following lines one position to the right: the 3-rd, the 6-th, the 7-th and the 8-th.
In the second sample there is no way you can achieve the goal. | instruction | 0 | 22,338 | 15 | 44,676 |
Tags: brute force, strings
Correct Solution:
```
check=True
for i in range(8):
s=input()
for j in range(1,len(s)):
if(s[j]==s[j-1]):
check=False
break
if(check):
print("YES")
else:
print("NO")
``` | output | 1 | 22,338 | 15 | 44,677 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The Little Elephant loves chess very much.
One day the Little Elephant and his friend decided to play chess. They've got the chess pieces but the board is a problem. They've got an 8 Γ 8 checkered board, each square is painted either black or white. The Little Elephant and his friend know that a proper chessboard doesn't have any side-adjacent cells with the same color and the upper left cell is white. To play chess, they want to make the board they have a proper chessboard. For that the friends can choose any row of the board and cyclically shift the cells of the chosen row, that is, put the last (rightmost) square on the first place in the row and shift the others one position to the right. You can run the described operation multiple times (or not run it at all).
For example, if the first line of the board looks like that "BBBBBBWW" (the white cells of the line are marked with character "W", the black cells are marked with character "B"), then after one cyclic shift it will look like that "WBBBBBBW".
Help the Little Elephant and his friend to find out whether they can use any number of the described operations to turn the board they have into a proper chessboard.
Input
The input consists of exactly eight lines. Each line contains exactly eight characters "W" or "B" without any spaces: the j-th character in the i-th line stands for the color of the j-th cell of the i-th row of the elephants' board. Character "W" stands for the white color, character "B" stands for the black color.
Consider the rows of the board numbered from 1 to 8 from top to bottom, and the columns β from 1 to 8 from left to right. The given board can initially be a proper chessboard.
Output
In a single line print "YES" (without the quotes), if we can make the board a proper chessboard and "NO" (without the quotes) otherwise.
Examples
Input
WBWBWBWB
BWBWBWBW
BWBWBWBW
BWBWBWBW
WBWBWBWB
WBWBWBWB
BWBWBWBW
WBWBWBWB
Output
YES
Input
WBWBWBWB
WBWBWBWB
BBWBWWWB
BWBWBWBW
BWBWBWBW
BWBWBWWW
BWBWBWBW
BWBWBWBW
Output
NO
Note
In the first sample you should shift the following lines one position to the right: the 3-rd, the 6-th, the 7-th and the 8-th.
In the second sample there is no way you can achieve the goal. | instruction | 0 | 22,339 | 15 | 44,678 |
Tags: brute force, strings
Correct Solution:
```
chess = [input() for i in range(8)]
solve = 'YES'
for c in chess:
if 'WW' in c or 'BB' in c:
solve = 'NO'
break
else:
continue
print(solve)
``` | output | 1 | 22,339 | 15 | 44,679 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The Little Elephant loves chess very much.
One day the Little Elephant and his friend decided to play chess. They've got the chess pieces but the board is a problem. They've got an 8 Γ 8 checkered board, each square is painted either black or white. The Little Elephant and his friend know that a proper chessboard doesn't have any side-adjacent cells with the same color and the upper left cell is white. To play chess, they want to make the board they have a proper chessboard. For that the friends can choose any row of the board and cyclically shift the cells of the chosen row, that is, put the last (rightmost) square on the first place in the row and shift the others one position to the right. You can run the described operation multiple times (or not run it at all).
For example, if the first line of the board looks like that "BBBBBBWW" (the white cells of the line are marked with character "W", the black cells are marked with character "B"), then after one cyclic shift it will look like that "WBBBBBBW".
Help the Little Elephant and his friend to find out whether they can use any number of the described operations to turn the board they have into a proper chessboard.
Input
The input consists of exactly eight lines. Each line contains exactly eight characters "W" or "B" without any spaces: the j-th character in the i-th line stands for the color of the j-th cell of the i-th row of the elephants' board. Character "W" stands for the white color, character "B" stands for the black color.
Consider the rows of the board numbered from 1 to 8 from top to bottom, and the columns β from 1 to 8 from left to right. The given board can initially be a proper chessboard.
Output
In a single line print "YES" (without the quotes), if we can make the board a proper chessboard and "NO" (without the quotes) otherwise.
Examples
Input
WBWBWBWB
BWBWBWBW
BWBWBWBW
BWBWBWBW
WBWBWBWB
WBWBWBWB
BWBWBWBW
WBWBWBWB
Output
YES
Input
WBWBWBWB
WBWBWBWB
BBWBWWWB
BWBWBWBW
BWBWBWBW
BWBWBWWW
BWBWBWBW
BWBWBWBW
Output
NO
Note
In the first sample you should shift the following lines one position to the right: the 3-rd, the 6-th, the 7-th and the 8-th.
In the second sample there is no way you can achieve the goal. | instruction | 0 | 22,340 | 15 | 44,680 |
Tags: brute force, strings
Correct Solution:
```
l=[]
flag=0
for i in range(8):
l.append(input())
for j in range(1,8):
if(l[i][j]==l[i][j-1]):
flag=1
break
if(flag==1):
print("NO")
else:
print("YES")
``` | output | 1 | 22,340 | 15 | 44,681 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The Little Elephant loves chess very much.
One day the Little Elephant and his friend decided to play chess. They've got the chess pieces but the board is a problem. They've got an 8 Γ 8 checkered board, each square is painted either black or white. The Little Elephant and his friend know that a proper chessboard doesn't have any side-adjacent cells with the same color and the upper left cell is white. To play chess, they want to make the board they have a proper chessboard. For that the friends can choose any row of the board and cyclically shift the cells of the chosen row, that is, put the last (rightmost) square on the first place in the row and shift the others one position to the right. You can run the described operation multiple times (or not run it at all).
For example, if the first line of the board looks like that "BBBBBBWW" (the white cells of the line are marked with character "W", the black cells are marked with character "B"), then after one cyclic shift it will look like that "WBBBBBBW".
Help the Little Elephant and his friend to find out whether they can use any number of the described operations to turn the board they have into a proper chessboard.
Input
The input consists of exactly eight lines. Each line contains exactly eight characters "W" or "B" without any spaces: the j-th character in the i-th line stands for the color of the j-th cell of the i-th row of the elephants' board. Character "W" stands for the white color, character "B" stands for the black color.
Consider the rows of the board numbered from 1 to 8 from top to bottom, and the columns β from 1 to 8 from left to right. The given board can initially be a proper chessboard.
Output
In a single line print "YES" (without the quotes), if we can make the board a proper chessboard and "NO" (without the quotes) otherwise.
Examples
Input
WBWBWBWB
BWBWBWBW
BWBWBWBW
BWBWBWBW
WBWBWBWB
WBWBWBWB
BWBWBWBW
WBWBWBWB
Output
YES
Input
WBWBWBWB
WBWBWBWB
BBWBWWWB
BWBWBWBW
BWBWBWBW
BWBWBWWW
BWBWBWBW
BWBWBWBW
Output
NO
Note
In the first sample you should shift the following lines one position to the right: the 3-rd, the 6-th, the 7-th and the 8-th.
In the second sample there is no way you can achieve the goal. | instruction | 0 | 22,341 | 15 | 44,682 |
Tags: brute force, strings
Correct Solution:
```
proper = True
for i in range(8):
raw = input()
if raw != "WBWBWBWB" and raw != "BWBWBWBW":
proper = False
if proper:
print("YES")
else:
print("NO")
``` | output | 1 | 22,341 | 15 | 44,683 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The Little Elephant loves chess very much.
One day the Little Elephant and his friend decided to play chess. They've got the chess pieces but the board is a problem. They've got an 8 Γ 8 checkered board, each square is painted either black or white. The Little Elephant and his friend know that a proper chessboard doesn't have any side-adjacent cells with the same color and the upper left cell is white. To play chess, they want to make the board they have a proper chessboard. For that the friends can choose any row of the board and cyclically shift the cells of the chosen row, that is, put the last (rightmost) square on the first place in the row and shift the others one position to the right. You can run the described operation multiple times (or not run it at all).
For example, if the first line of the board looks like that "BBBBBBWW" (the white cells of the line are marked with character "W", the black cells are marked with character "B"), then after one cyclic shift it will look like that "WBBBBBBW".
Help the Little Elephant and his friend to find out whether they can use any number of the described operations to turn the board they have into a proper chessboard.
Input
The input consists of exactly eight lines. Each line contains exactly eight characters "W" or "B" without any spaces: the j-th character in the i-th line stands for the color of the j-th cell of the i-th row of the elephants' board. Character "W" stands for the white color, character "B" stands for the black color.
Consider the rows of the board numbered from 1 to 8 from top to bottom, and the columns β from 1 to 8 from left to right. The given board can initially be a proper chessboard.
Output
In a single line print "YES" (without the quotes), if we can make the board a proper chessboard and "NO" (without the quotes) otherwise.
Examples
Input
WBWBWBWB
BWBWBWBW
BWBWBWBW
BWBWBWBW
WBWBWBWB
WBWBWBWB
BWBWBWBW
WBWBWBWB
Output
YES
Input
WBWBWBWB
WBWBWBWB
BBWBWWWB
BWBWBWBW
BWBWBWBW
BWBWBWWW
BWBWBWBW
BWBWBWBW
Output
NO
Note
In the first sample you should shift the following lines one position to the right: the 3-rd, the 6-th, the 7-th and the 8-th.
In the second sample there is no way you can achieve the goal. | instruction | 0 | 22,342 | 15 | 44,684 |
Tags: brute force, strings
Correct Solution:
```
int1="WBWBWBWB"
int2="BWBWBWBW"
res=0
for i in range (8):
line=str(input())
for j in range (len(line)):
if line==int1 or line == int2:
res+=1
if res/8==8:
print("YES")
else:
print("NO")
``` | output | 1 | 22,342 | 15 | 44,685 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The Little Elephant loves chess very much.
One day the Little Elephant and his friend decided to play chess. They've got the chess pieces but the board is a problem. They've got an 8 Γ 8 checkered board, each square is painted either black or white. The Little Elephant and his friend know that a proper chessboard doesn't have any side-adjacent cells with the same color and the upper left cell is white. To play chess, they want to make the board they have a proper chessboard. For that the friends can choose any row of the board and cyclically shift the cells of the chosen row, that is, put the last (rightmost) square on the first place in the row and shift the others one position to the right. You can run the described operation multiple times (or not run it at all).
For example, if the first line of the board looks like that "BBBBBBWW" (the white cells of the line are marked with character "W", the black cells are marked with character "B"), then after one cyclic shift it will look like that "WBBBBBBW".
Help the Little Elephant and his friend to find out whether they can use any number of the described operations to turn the board they have into a proper chessboard.
Input
The input consists of exactly eight lines. Each line contains exactly eight characters "W" or "B" without any spaces: the j-th character in the i-th line stands for the color of the j-th cell of the i-th row of the elephants' board. Character "W" stands for the white color, character "B" stands for the black color.
Consider the rows of the board numbered from 1 to 8 from top to bottom, and the columns β from 1 to 8 from left to right. The given board can initially be a proper chessboard.
Output
In a single line print "YES" (without the quotes), if we can make the board a proper chessboard and "NO" (without the quotes) otherwise.
Examples
Input
WBWBWBWB
BWBWBWBW
BWBWBWBW
BWBWBWBW
WBWBWBWB
WBWBWBWB
BWBWBWBW
WBWBWBWB
Output
YES
Input
WBWBWBWB
WBWBWBWB
BBWBWWWB
BWBWBWBW
BWBWBWBW
BWBWBWWW
BWBWBWBW
BWBWBWBW
Output
NO
Note
In the first sample you should shift the following lines one position to the right: the 3-rd, the 6-th, the 7-th and the 8-th.
In the second sample there is no way you can achieve the goal. | instruction | 0 | 22,343 | 15 | 44,686 |
Tags: brute force, strings
Correct Solution:
```
def chess(li):
for i in range(8):
for j in range(8):
if li[i][0] == li[i][7]:
return False
if j+1<len(li) and li[i][j] == li[i][j+1] :
return False
return True
li =[]
for i in range(8):
a=input()
li.append(list(a))
if chess(li):
print("YES")
else:
print("NO")
``` | output | 1 | 22,343 | 15 | 44,687 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The Little Elephant loves chess very much.
One day the Little Elephant and his friend decided to play chess. They've got the chess pieces but the board is a problem. They've got an 8 Γ 8 checkered board, each square is painted either black or white. The Little Elephant and his friend know that a proper chessboard doesn't have any side-adjacent cells with the same color and the upper left cell is white. To play chess, they want to make the board they have a proper chessboard. For that the friends can choose any row of the board and cyclically shift the cells of the chosen row, that is, put the last (rightmost) square on the first place in the row and shift the others one position to the right. You can run the described operation multiple times (or not run it at all).
For example, if the first line of the board looks like that "BBBBBBWW" (the white cells of the line are marked with character "W", the black cells are marked with character "B"), then after one cyclic shift it will look like that "WBBBBBBW".
Help the Little Elephant and his friend to find out whether they can use any number of the described operations to turn the board they have into a proper chessboard.
Input
The input consists of exactly eight lines. Each line contains exactly eight characters "W" or "B" without any spaces: the j-th character in the i-th line stands for the color of the j-th cell of the i-th row of the elephants' board. Character "W" stands for the white color, character "B" stands for the black color.
Consider the rows of the board numbered from 1 to 8 from top to bottom, and the columns β from 1 to 8 from left to right. The given board can initially be a proper chessboard.
Output
In a single line print "YES" (without the quotes), if we can make the board a proper chessboard and "NO" (without the quotes) otherwise.
Examples
Input
WBWBWBWB
BWBWBWBW
BWBWBWBW
BWBWBWBW
WBWBWBWB
WBWBWBWB
BWBWBWBW
WBWBWBWB
Output
YES
Input
WBWBWBWB
WBWBWBWB
BBWBWWWB
BWBWBWBW
BWBWBWBW
BWBWBWWW
BWBWBWBW
BWBWBWBW
Output
NO
Note
In the first sample you should shift the following lines one position to the right: the 3-rd, the 6-th, the 7-th and the 8-th.
In the second sample there is no way you can achieve the goal. | instruction | 0 | 22,344 | 15 | 44,688 |
Tags: brute force, strings
Correct Solution:
```
for i in range(8):
X = input()
if "WW" in X or "BB" in X:
print("NO")
exit()
print("YES")
# UB_CodeForces
# Advice: Falling down is an accident, staying down is a choice
# Location: Here in Bojnurd
# Caption: Being followed by my friend ESSI
# CodeNumber: 620
``` | output | 1 | 22,344 | 15 | 44,689 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The Little Elephant loves chess very much.
One day the Little Elephant and his friend decided to play chess. They've got the chess pieces but the board is a problem. They've got an 8 Γ 8 checkered board, each square is painted either black or white. The Little Elephant and his friend know that a proper chessboard doesn't have any side-adjacent cells with the same color and the upper left cell is white. To play chess, they want to make the board they have a proper chessboard. For that the friends can choose any row of the board and cyclically shift the cells of the chosen row, that is, put the last (rightmost) square on the first place in the row and shift the others one position to the right. You can run the described operation multiple times (or not run it at all).
For example, if the first line of the board looks like that "BBBBBBWW" (the white cells of the line are marked with character "W", the black cells are marked with character "B"), then after one cyclic shift it will look like that "WBBBBBBW".
Help the Little Elephant and his friend to find out whether they can use any number of the described operations to turn the board they have into a proper chessboard.
Input
The input consists of exactly eight lines. Each line contains exactly eight characters "W" or "B" without any spaces: the j-th character in the i-th line stands for the color of the j-th cell of the i-th row of the elephants' board. Character "W" stands for the white color, character "B" stands for the black color.
Consider the rows of the board numbered from 1 to 8 from top to bottom, and the columns β from 1 to 8 from left to right. The given board can initially be a proper chessboard.
Output
In a single line print "YES" (without the quotes), if we can make the board a proper chessboard and "NO" (without the quotes) otherwise.
Examples
Input
WBWBWBWB
BWBWBWBW
BWBWBWBW
BWBWBWBW
WBWBWBWB
WBWBWBWB
BWBWBWBW
WBWBWBWB
Output
YES
Input
WBWBWBWB
WBWBWBWB
BBWBWWWB
BWBWBWBW
BWBWBWBW
BWBWBWWW
BWBWBWBW
BWBWBWBW
Output
NO
Note
In the first sample you should shift the following lines one position to the right: the 3-rd, the 6-th, the 7-th and the 8-th.
In the second sample there is no way you can achieve the goal. | instruction | 0 | 22,345 | 15 | 44,690 |
Tags: brute force, strings
Correct Solution:
```
chess =[]
for i in range(8):
chess.append(input())
flag = True
for i in range(8):
for j in range(7):
if chess[i][j] == chess[i][j+1]:
flag = False
break
if not flag:
break
if flag:
print("YES")
else:
print("NO")
``` | output | 1 | 22,345 | 15 | 44,691 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The Little Elephant loves chess very much.
One day the Little Elephant and his friend decided to play chess. They've got the chess pieces but the board is a problem. They've got an 8 Γ 8 checkered board, each square is painted either black or white. The Little Elephant and his friend know that a proper chessboard doesn't have any side-adjacent cells with the same color and the upper left cell is white. To play chess, they want to make the board they have a proper chessboard. For that the friends can choose any row of the board and cyclically shift the cells of the chosen row, that is, put the last (rightmost) square on the first place in the row and shift the others one position to the right. You can run the described operation multiple times (or not run it at all).
For example, if the first line of the board looks like that "BBBBBBWW" (the white cells of the line are marked with character "W", the black cells are marked with character "B"), then after one cyclic shift it will look like that "WBBBBBBW".
Help the Little Elephant and his friend to find out whether they can use any number of the described operations to turn the board they have into a proper chessboard.
Input
The input consists of exactly eight lines. Each line contains exactly eight characters "W" or "B" without any spaces: the j-th character in the i-th line stands for the color of the j-th cell of the i-th row of the elephants' board. Character "W" stands for the white color, character "B" stands for the black color.
Consider the rows of the board numbered from 1 to 8 from top to bottom, and the columns β from 1 to 8 from left to right. The given board can initially be a proper chessboard.
Output
In a single line print "YES" (without the quotes), if we can make the board a proper chessboard and "NO" (without the quotes) otherwise.
Examples
Input
WBWBWBWB
BWBWBWBW
BWBWBWBW
BWBWBWBW
WBWBWBWB
WBWBWBWB
BWBWBWBW
WBWBWBWB
Output
YES
Input
WBWBWBWB
WBWBWBWB
BBWBWWWB
BWBWBWBW
BWBWBWBW
BWBWBWWW
BWBWBWBW
BWBWBWBW
Output
NO
Note
In the first sample you should shift the following lines one position to the right: the 3-rd, the 6-th, the 7-th and the 8-th.
In the second sample there is no way you can achieve the goal.
Submitted Solution:
```
print('YES' if all([r=='WB'*4 or r=='BW'*4 for r in [input() for _ in range(8)]]) else 'NO')
``` | instruction | 0 | 22,346 | 15 | 44,692 |
Yes | output | 1 | 22,346 | 15 | 44,693 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The Little Elephant loves chess very much.
One day the Little Elephant and his friend decided to play chess. They've got the chess pieces but the board is a problem. They've got an 8 Γ 8 checkered board, each square is painted either black or white. The Little Elephant and his friend know that a proper chessboard doesn't have any side-adjacent cells with the same color and the upper left cell is white. To play chess, they want to make the board they have a proper chessboard. For that the friends can choose any row of the board and cyclically shift the cells of the chosen row, that is, put the last (rightmost) square on the first place in the row and shift the others one position to the right. You can run the described operation multiple times (or not run it at all).
For example, if the first line of the board looks like that "BBBBBBWW" (the white cells of the line are marked with character "W", the black cells are marked with character "B"), then after one cyclic shift it will look like that "WBBBBBBW".
Help the Little Elephant and his friend to find out whether they can use any number of the described operations to turn the board they have into a proper chessboard.
Input
The input consists of exactly eight lines. Each line contains exactly eight characters "W" or "B" without any spaces: the j-th character in the i-th line stands for the color of the j-th cell of the i-th row of the elephants' board. Character "W" stands for the white color, character "B" stands for the black color.
Consider the rows of the board numbered from 1 to 8 from top to bottom, and the columns β from 1 to 8 from left to right. The given board can initially be a proper chessboard.
Output
In a single line print "YES" (without the quotes), if we can make the board a proper chessboard and "NO" (without the quotes) otherwise.
Examples
Input
WBWBWBWB
BWBWBWBW
BWBWBWBW
BWBWBWBW
WBWBWBWB
WBWBWBWB
BWBWBWBW
WBWBWBWB
Output
YES
Input
WBWBWBWB
WBWBWBWB
BBWBWWWB
BWBWBWBW
BWBWBWBW
BWBWBWWW
BWBWBWBW
BWBWBWBW
Output
NO
Note
In the first sample you should shift the following lines one position to the right: the 3-rd, the 6-th, the 7-th and the 8-th.
In the second sample there is no way you can achieve the goal.
Submitted Solution:
```
flag = True
for _ in range(8):
s = input()
if s.count("W") == 4 and s.count("B") == 4:
c = s[0]
for i in s[1:]:
if i == c:
flag = False
else:
c = i
else:
flag = False
if flag:
print("YES")
else:
print("NO")
``` | instruction | 0 | 22,347 | 15 | 44,694 |
Yes | output | 1 | 22,347 | 15 | 44,695 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The Little Elephant loves chess very much.
One day the Little Elephant and his friend decided to play chess. They've got the chess pieces but the board is a problem. They've got an 8 Γ 8 checkered board, each square is painted either black or white. The Little Elephant and his friend know that a proper chessboard doesn't have any side-adjacent cells with the same color and the upper left cell is white. To play chess, they want to make the board they have a proper chessboard. For that the friends can choose any row of the board and cyclically shift the cells of the chosen row, that is, put the last (rightmost) square on the first place in the row and shift the others one position to the right. You can run the described operation multiple times (or not run it at all).
For example, if the first line of the board looks like that "BBBBBBWW" (the white cells of the line are marked with character "W", the black cells are marked with character "B"), then after one cyclic shift it will look like that "WBBBBBBW".
Help the Little Elephant and his friend to find out whether they can use any number of the described operations to turn the board they have into a proper chessboard.
Input
The input consists of exactly eight lines. Each line contains exactly eight characters "W" or "B" without any spaces: the j-th character in the i-th line stands for the color of the j-th cell of the i-th row of the elephants' board. Character "W" stands for the white color, character "B" stands for the black color.
Consider the rows of the board numbered from 1 to 8 from top to bottom, and the columns β from 1 to 8 from left to right. The given board can initially be a proper chessboard.
Output
In a single line print "YES" (without the quotes), if we can make the board a proper chessboard and "NO" (without the quotes) otherwise.
Examples
Input
WBWBWBWB
BWBWBWBW
BWBWBWBW
BWBWBWBW
WBWBWBWB
WBWBWBWB
BWBWBWBW
WBWBWBWB
Output
YES
Input
WBWBWBWB
WBWBWBWB
BBWBWWWB
BWBWBWBW
BWBWBWBW
BWBWBWWW
BWBWBWBW
BWBWBWBW
Output
NO
Note
In the first sample you should shift the following lines one position to the right: the 3-rd, the 6-th, the 7-th and the 8-th.
In the second sample there is no way you can achieve the goal.
Submitted Solution:
```
s = [input() for i in range(8)]
cnt = 0
for i in s:
if i!="WBWBWBWB" and i!="BWBWBWBW":
cnt+=1
if cnt:
print("NO")
else:
print("YES")
``` | instruction | 0 | 22,348 | 15 | 44,696 |
Yes | output | 1 | 22,348 | 15 | 44,697 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The Little Elephant loves chess very much.
One day the Little Elephant and his friend decided to play chess. They've got the chess pieces but the board is a problem. They've got an 8 Γ 8 checkered board, each square is painted either black or white. The Little Elephant and his friend know that a proper chessboard doesn't have any side-adjacent cells with the same color and the upper left cell is white. To play chess, they want to make the board they have a proper chessboard. For that the friends can choose any row of the board and cyclically shift the cells of the chosen row, that is, put the last (rightmost) square on the first place in the row and shift the others one position to the right. You can run the described operation multiple times (or not run it at all).
For example, if the first line of the board looks like that "BBBBBBWW" (the white cells of the line are marked with character "W", the black cells are marked with character "B"), then after one cyclic shift it will look like that "WBBBBBBW".
Help the Little Elephant and his friend to find out whether they can use any number of the described operations to turn the board they have into a proper chessboard.
Input
The input consists of exactly eight lines. Each line contains exactly eight characters "W" or "B" without any spaces: the j-th character in the i-th line stands for the color of the j-th cell of the i-th row of the elephants' board. Character "W" stands for the white color, character "B" stands for the black color.
Consider the rows of the board numbered from 1 to 8 from top to bottom, and the columns β from 1 to 8 from left to right. The given board can initially be a proper chessboard.
Output
In a single line print "YES" (without the quotes), if we can make the board a proper chessboard and "NO" (without the quotes) otherwise.
Examples
Input
WBWBWBWB
BWBWBWBW
BWBWBWBW
BWBWBWBW
WBWBWBWB
WBWBWBWB
BWBWBWBW
WBWBWBWB
Output
YES
Input
WBWBWBWB
WBWBWBWB
BBWBWWWB
BWBWBWBW
BWBWBWBW
BWBWBWWW
BWBWBWBW
BWBWBWBW
Output
NO
Note
In the first sample you should shift the following lines one position to the right: the 3-rd, the 6-th, the 7-th and the 8-th.
In the second sample there is no way you can achieve the goal.
Submitted Solution:
```
x=0
for i in range(8):
s=input()
if s!='WBWBWBWB' and s!='BWBWBWBW':
x=1
break
if(x):print("NO")
else:print("YES")
``` | instruction | 0 | 22,349 | 15 | 44,698 |
Yes | output | 1 | 22,349 | 15 | 44,699 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The Little Elephant loves chess very much.
One day the Little Elephant and his friend decided to play chess. They've got the chess pieces but the board is a problem. They've got an 8 Γ 8 checkered board, each square is painted either black or white. The Little Elephant and his friend know that a proper chessboard doesn't have any side-adjacent cells with the same color and the upper left cell is white. To play chess, they want to make the board they have a proper chessboard. For that the friends can choose any row of the board and cyclically shift the cells of the chosen row, that is, put the last (rightmost) square on the first place in the row and shift the others one position to the right. You can run the described operation multiple times (or not run it at all).
For example, if the first line of the board looks like that "BBBBBBWW" (the white cells of the line are marked with character "W", the black cells are marked with character "B"), then after one cyclic shift it will look like that "WBBBBBBW".
Help the Little Elephant and his friend to find out whether they can use any number of the described operations to turn the board they have into a proper chessboard.
Input
The input consists of exactly eight lines. Each line contains exactly eight characters "W" or "B" without any spaces: the j-th character in the i-th line stands for the color of the j-th cell of the i-th row of the elephants' board. Character "W" stands for the white color, character "B" stands for the black color.
Consider the rows of the board numbered from 1 to 8 from top to bottom, and the columns β from 1 to 8 from left to right. The given board can initially be a proper chessboard.
Output
In a single line print "YES" (without the quotes), if we can make the board a proper chessboard and "NO" (without the quotes) otherwise.
Examples
Input
WBWBWBWB
BWBWBWBW
BWBWBWBW
BWBWBWBW
WBWBWBWB
WBWBWBWB
BWBWBWBW
WBWBWBWB
Output
YES
Input
WBWBWBWB
WBWBWBWB
BBWBWWWB
BWBWBWBW
BWBWBWBW
BWBWBWWW
BWBWBWBW
BWBWBWBW
Output
NO
Note
In the first sample you should shift the following lines one position to the right: the 3-rd, the 6-th, the 7-th and the 8-th.
In the second sample there is no way you can achieve the goal.
Submitted Solution:
```
arr=[ list( input() ) for _ in range (8) ]
cw=0
cb=0
flag = True
for i in range(8):
for j in range(8):
if (arr[i][j]) == "w" and (arr[i][j+1] == "b") and j != 8:
cw+=1
elif (arr[i][j]) == "b" and (arr[i][j+1] == "w") and j != 8:
cb+=1
if cw == cb :
continue
else:
flag= False
break
if (flag == True):
print("YES")
else:
print('NO')
print(arr)
``` | instruction | 0 | 22,350 | 15 | 44,700 |
No | output | 1 | 22,350 | 15 | 44,701 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The Little Elephant loves chess very much.
One day the Little Elephant and his friend decided to play chess. They've got the chess pieces but the board is a problem. They've got an 8 Γ 8 checkered board, each square is painted either black or white. The Little Elephant and his friend know that a proper chessboard doesn't have any side-adjacent cells with the same color and the upper left cell is white. To play chess, they want to make the board they have a proper chessboard. For that the friends can choose any row of the board and cyclically shift the cells of the chosen row, that is, put the last (rightmost) square on the first place in the row and shift the others one position to the right. You can run the described operation multiple times (or not run it at all).
For example, if the first line of the board looks like that "BBBBBBWW" (the white cells of the line are marked with character "W", the black cells are marked with character "B"), then after one cyclic shift it will look like that "WBBBBBBW".
Help the Little Elephant and his friend to find out whether they can use any number of the described operations to turn the board they have into a proper chessboard.
Input
The input consists of exactly eight lines. Each line contains exactly eight characters "W" or "B" without any spaces: the j-th character in the i-th line stands for the color of the j-th cell of the i-th row of the elephants' board. Character "W" stands for the white color, character "B" stands for the black color.
Consider the rows of the board numbered from 1 to 8 from top to bottom, and the columns β from 1 to 8 from left to right. The given board can initially be a proper chessboard.
Output
In a single line print "YES" (without the quotes), if we can make the board a proper chessboard and "NO" (without the quotes) otherwise.
Examples
Input
WBWBWBWB
BWBWBWBW
BWBWBWBW
BWBWBWBW
WBWBWBWB
WBWBWBWB
BWBWBWBW
WBWBWBWB
Output
YES
Input
WBWBWBWB
WBWBWBWB
BBWBWWWB
BWBWBWBW
BWBWBWBW
BWBWBWWW
BWBWBWBW
BWBWBWBW
Output
NO
Note
In the first sample you should shift the following lines one position to the right: the 3-rd, the 6-th, the 7-th and the 8-th.
In the second sample there is no way you can achieve the goal.
Submitted Solution:
```
c=0
a,b=0,0
for _ in range(8):
s=input()
for x in range(8):
if s[x]=='W':
a+=1
else:
b+=1
ch=''
if (_+x)&1:
ch='B'
else:
ch=='W'
if s[x]!=ch:
c+=1
if a==b and c>=8 and c%2==0 :
print("YES")
else:
print("NO")
``` | instruction | 0 | 22,351 | 15 | 44,702 |
No | output | 1 | 22,351 | 15 | 44,703 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The Little Elephant loves chess very much.
One day the Little Elephant and his friend decided to play chess. They've got the chess pieces but the board is a problem. They've got an 8 Γ 8 checkered board, each square is painted either black or white. The Little Elephant and his friend know that a proper chessboard doesn't have any side-adjacent cells with the same color and the upper left cell is white. To play chess, they want to make the board they have a proper chessboard. For that the friends can choose any row of the board and cyclically shift the cells of the chosen row, that is, put the last (rightmost) square on the first place in the row and shift the others one position to the right. You can run the described operation multiple times (or not run it at all).
For example, if the first line of the board looks like that "BBBBBBWW" (the white cells of the line are marked with character "W", the black cells are marked with character "B"), then after one cyclic shift it will look like that "WBBBBBBW".
Help the Little Elephant and his friend to find out whether they can use any number of the described operations to turn the board they have into a proper chessboard.
Input
The input consists of exactly eight lines. Each line contains exactly eight characters "W" or "B" without any spaces: the j-th character in the i-th line stands for the color of the j-th cell of the i-th row of the elephants' board. Character "W" stands for the white color, character "B" stands for the black color.
Consider the rows of the board numbered from 1 to 8 from top to bottom, and the columns β from 1 to 8 from left to right. The given board can initially be a proper chessboard.
Output
In a single line print "YES" (without the quotes), if we can make the board a proper chessboard and "NO" (without the quotes) otherwise.
Examples
Input
WBWBWBWB
BWBWBWBW
BWBWBWBW
BWBWBWBW
WBWBWBWB
WBWBWBWB
BWBWBWBW
WBWBWBWB
Output
YES
Input
WBWBWBWB
WBWBWBWB
BBWBWWWB
BWBWBWBW
BWBWBWBW
BWBWBWWW
BWBWBWBW
BWBWBWBW
Output
NO
Note
In the first sample you should shift the following lines one position to the right: the 3-rd, the 6-th, the 7-th and the 8-th.
In the second sample there is no way you can achieve the goal.
Submitted Solution:
```
possible=True
for i in range(8):
line=input()
if line[0]==line[1]==line[-1] or line[-1]==line[-2]==line[0]:possible=False;continue
if not possible:continue
cf = line.split('W')
cg = line.split('B')
empty=one=True
while True:
try:cf.remove('')
except Exception: empty=False
try:cf.remove('B')
except Exception: one=False
if not empty and not one: break
empty=one=True
while True:
try:cg.remove('W')
except Exception: empty=False
try:cg.remove('')
except Exception: one=False
if not empty and not one: break
if len(cf)>=2:possible=False
if len(cg)>=2:possible=False
if i==0:
pf=cf[:]
pg=cg[:]
continue
if len(cf)==1:
if len(pf)==1:possible=False
if len(cg)==1:
if len(pg)==1:possible=False
# print(possible,cf,pf,cg,pg)
pf=cf[:]
pg=cg[:]
if possible:print('YES')
else:print('NO')
``` | instruction | 0 | 22,352 | 15 | 44,704 |
No | output | 1 | 22,352 | 15 | 44,705 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The Little Elephant loves chess very much.
One day the Little Elephant and his friend decided to play chess. They've got the chess pieces but the board is a problem. They've got an 8 Γ 8 checkered board, each square is painted either black or white. The Little Elephant and his friend know that a proper chessboard doesn't have any side-adjacent cells with the same color and the upper left cell is white. To play chess, they want to make the board they have a proper chessboard. For that the friends can choose any row of the board and cyclically shift the cells of the chosen row, that is, put the last (rightmost) square on the first place in the row and shift the others one position to the right. You can run the described operation multiple times (or not run it at all).
For example, if the first line of the board looks like that "BBBBBBWW" (the white cells of the line are marked with character "W", the black cells are marked with character "B"), then after one cyclic shift it will look like that "WBBBBBBW".
Help the Little Elephant and his friend to find out whether they can use any number of the described operations to turn the board they have into a proper chessboard.
Input
The input consists of exactly eight lines. Each line contains exactly eight characters "W" or "B" without any spaces: the j-th character in the i-th line stands for the color of the j-th cell of the i-th row of the elephants' board. Character "W" stands for the white color, character "B" stands for the black color.
Consider the rows of the board numbered from 1 to 8 from top to bottom, and the columns β from 1 to 8 from left to right. The given board can initially be a proper chessboard.
Output
In a single line print "YES" (without the quotes), if we can make the board a proper chessboard and "NO" (without the quotes) otherwise.
Examples
Input
WBWBWBWB
BWBWBWBW
BWBWBWBW
BWBWBWBW
WBWBWBWB
WBWBWBWB
BWBWBWBW
WBWBWBWB
Output
YES
Input
WBWBWBWB
WBWBWBWB
BBWBWWWB
BWBWBWBW
BWBWBWBW
BWBWBWWW
BWBWBWBW
BWBWBWBW
Output
NO
Note
In the first sample you should shift the following lines one position to the right: the 3-rd, the 6-th, the 7-th and the 8-th.
In the second sample there is no way you can achieve the goal.
Submitted Solution:
```
valid = True
for i in range(8):
S = input()
if sum([s == 'B' for s in S]) != 4:
valid = False
print("YES" if valid else "NO")
``` | instruction | 0 | 22,353 | 15 | 44,706 |
No | output | 1 | 22,353 | 15 | 44,707 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a circular array with n elements. The elements are numbered from some element with values from 1 to n in clockwise order. The i-th cell contains the value ai. The robot Simba is in cell s.
Each moment of time the robot is in some of the n cells (at the begin he is in s). In one turn the robot can write out the number written in current cell or move to the adjacent cell in clockwise or counterclockwise direction. To write out the number from the cell Simba doesn't spend any time, but to move to adjacent cell Simba spends one unit of time.
Simba wants to write the number from each cell one time, so the numbers will be written in a non decreasing order. Find the least number of time units to write out all numbers.
Input
The first line contains two integers n and s (1 β€ s β€ n β€ 2000) β the number of cells in the circular array and the starting position of Simba.
The second line contains n integers ai ( - 109 β€ ai β€ 109) β the number written in the i-th cell. The numbers are given for cells in order from 1 to n. Some of numbers ai can be equal.
Output
In the first line print the number t β the least number of time units.
Each of the next n lines should contain the direction of robot movement and the number of cells to move in that direction. After that movement the robot writes out the number from the cell in which it turns out. The direction and the number of cells should be printed in the form of +x in case of clockwise movement and -x in case of counterclockwise movement to x cells (0 β€ x β€ n - 1).
Note that the sum of absolute values of x should be equal to t.
Examples
Input
9 1
0 1 2 2 2 1 0 1 1
Output
12
+0
-3
-1
+2
+1
+2
+1
+1
+1
Input
8 1
0 1 0 1 0 1 0 1
Output
13
+0
+2
+2
+2
-1
+2
+2
+2
Input
8 1
1 2 3 4 5 6 7 8
Output
7
+0
+1
+1
+1
+1
+1
+1
+1
Input
8 1
0 0 0 0 0 0 0 0
Output
7
+0
+1
+1
+1
+1
+1
+1
+1
Submitted Solution:
```
from collections import defaultdict
# end2 = start - end
def construct_clockwise_path(end2, numbers2, circumference):
path = []
pos, i = 0, 0
while end2 > numbers2[i]:
path.append(numbers2[i] - pos)
pos = numbers2[i]
i += 1
path.append(-(pos + circumference - numbers2[-1]))
pos, i = numbers2[-1], -1
while end2 < numbers2[i]:
path.append(numbers2[i-1] - numbers2[i])
i -= 1
return path
def construct_path(end2, direction, numbers2, circumference):
if direction == -1:
numbers2 = list(reversed([circumference - i for i in numbers2]))
end2 = circumference - end2
result = construct_clockwise_path(end2, numbers2, circumference)
if direction == -1:
return [-i for i in result]
return result
def time_to_collect(start, numbers, circumference):
result = {} # end2: (time, direction)
n = len(numbers)
numbers2 = []
_numbers2 = []
i = 0
while i < n and numbers[i] < start:
_numbers2.append(circumference - start + numbers[i])
i += 1
while i < n:
numbers2.append(numbers[i] - start)
i += 1
i = 0
numbers2.extend(_numbers2)
for i in range(n):
pos = numbers2[i]
lpos = numbers2[i-1] if i > 0 else 0
rpos = numbers2[i+1] if i < n - 1 else circumference
result[pos] = min(
(2 * lpos + circumference - pos, 1),
(2 * (circumference - rpos) + pos, -1))
return result, numbers2
def add_number(times_to_starts, positions, circumference):
result = {}
for s in times_to_starts:
res, num2 = time_to_collect(s, positions, circumference)
for k in res:
time, direction = res[k]
time += times_to_starts[s][0]
pos = (s + k) % circumference
if pos not in result or result[pos][0] > time:
result[pos] = (time, direction, k, num2) # k == end2
return result
def solve(n, pos, circle):
number_positions = defaultdict(list)
pos -= 1
for i in range(n):
number_positions[circle[i]].append(i)
numbers = sorted(number_positions.keys())
t2s = {pos: (0, None, None, None)}
floors = {}
for num in numbers:
t2s = add_number(t2s, sorted(number_positions[num]), n)
floors[num] = t2s
result = []
for num in reversed(numbers):
end, data = min(floors[num].items(), key = lambda x: x[1][0])
time, direction, end2, num2 = data
_result = result
result = construct_path(end2, direction, num2, n)
result.extend(_result)
print(sum(abs(i) for i in result))
for i in result:
if i >= 0:
print('+%s' % i)
else:
print(i)
n, pos = tuple(int(x) for x in input().split())
circle = tuple(int(x) for x in input().split())
solve(n, pos, circle)
``` | instruction | 0 | 22,503 | 15 | 45,006 |
No | output | 1 | 22,503 | 15 | 45,007 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Nauuo is a girl who loves playing games related to portals.
One day she was playing a game as follows.
In an nΓ n grid, the rows are numbered from 1 to n from top to bottom, the columns are numbered from 1 to n from left to right. We denote a cell on the intersection of the r-th row and c-th column as (r,c).
A portal is a pair of doors. You can travel from one of them to another without changing your direction. More formally, if you walk into a cell with a door, you will teleport to the cell with the other door of the same portal and then walk into the next cell facing the original direction. There can not be more than one doors in a single cell.
The "next cell" is the nearest cell in the direction you are facing. For example, if you are facing bottom, the next cell of (2,5) is (3,5).
If you walk into a cell without a door, you must walk into the next cell after that without changing the direction. If the next cell does not exist, you must exit the grid.
You have to set some (possibly zero) portals in the grid, so that if you walk into (i,1) facing right, you will eventually exit the grid from (r_i,n), if you walk into (1, i) facing bottom, you will exit the grid from (n,c_i).
It is guaranteed that both r_{1..n} and c_{1..n} are permutations of n elements. A permutation of n elements is a sequence of numbers p_1,p_2,β¦,p_n in which every integer from 1 to n appears exactly once.
She got confused while playing the game, can you help her to find a solution?
Input
The first line contains a single integer n (1β€ nβ€ 1000) β the side length of the grid.
The second line contains n integers r_1,r_2,β¦,r_n (1β€ r_iβ€ n) β if you walk into (i,1) facing right, you should exit the grid from (r_i,n). It is guaranteed that r_{1..n} is a permutation of n elements.
The third line contains n integers c_1,c_2,β¦,c_n (1β€ c_iβ€ n) β if you walk into (1,i) facing bottom, you should exit the grid from (n,c_i). It is guaranteed that c_{1..n} is a permutation of n elements.
Output
If it is impossible to satisfy the rule, print the only number -1.
Otherwise the first line should contain a single integer m (0β€ mβ€\frac{n^2}2) β the number of portals you set.
In the following m lines, each line should contain four integers x_1,y_1,x_2,y_2, represents that you set a portal consisting of two doors in (x_1,y_1) and (x_2,y_2).
If there are multiple answers, print any. You do not have to minimize m.
Examples
Input
3
1 3 2
3 1 2
Output
2
1 1 1 3
2 2 3 1
Input
5
3 1 5 4 2
4 2 1 3 5
Output
3
1 1 3 4
2 2 3 2
2 3 5 1
Note
Example 1
The cells with the same letter are a portal. You can set portals in this way:
<image>
It satisfies the rule, because:
<image>
Example 2
You can set portals in this way:
<image>
Submitted Solution:
```
def win(row,col,size):
if size==0:
return []
if row[-1]==col[-1]==size:
return win(row[:-1],col[:-1],size-1)
good=(size,col[-1],row[-1],size)
for i in range(size):
if row[i]==size:
row[i]=row[-1]
if col[i]==size:
col[i]=col[-1]
row.pop()
col.pop()
return win(row,col,size-1)+[good]
def main():
n=int(input())
row=list(map(int,input().split()))
col=list(map(int,input().split()))
s=win(row,col,n)
print(len(s))
for guy in s:
print(*guy)
``` | instruction | 0 | 22,911 | 15 | 45,822 |
No | output | 1 | 22,911 | 15 | 45,823 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Furik and Rubik take part in a relay race. The race will be set up on a large square with the side of n meters. The given square is split into n Γ n cells (represented as unit squares), each cell has some number.
At the beginning of the race Furik stands in a cell with coordinates (1, 1), and Rubik stands in a cell with coordinates (n, n). Right after the start Furik runs towards Rubik, besides, if Furik stands at a cell with coordinates (i, j), then he can move to cell (i + 1, j) or (i, j + 1). After Furik reaches Rubik, Rubik starts running from cell with coordinates (n, n) to cell with coordinates (1, 1). If Rubik stands in cell (i, j), then he can move to cell (i - 1, j) or (i, j - 1). Neither Furik, nor Rubik are allowed to go beyond the boundaries of the field; if a player goes beyond the boundaries, he will be disqualified.
To win the race, Furik and Rubik must earn as many points as possible. The number of points is the sum of numbers from the cells Furik and Rubik visited. Each cell counts only once in the sum.
Print the maximum number of points Furik and Rubik can earn on the relay race.
Input
The first line contains a single integer (1 β€ n β€ 300). The next n lines contain n integers each: the j-th number on the i-th line ai, j ( - 1000 β€ ai, j β€ 1000) is the number written in the cell with coordinates (i, j).
Output
On a single line print a single number β the answer to the problem.
Examples
Input
1
5
Output
5
Input
2
11 14
16 12
Output
53
Input
3
25 16 25
12 18 19
11 13 8
Output
136
Note
Comments to the second sample: The profitable path for Furik is: (1, 1), (1, 2), (2, 2), and for Rubik: (2, 2), (2, 1), (1, 1).
Comments to the third sample: The optimal path for Furik is: (1, 1), (1, 2), (1, 3), (2, 3), (3, 3), and for Rubik: (3, 3), (3, 2), (2, 2), (2, 1), (1, 1). The figure to the sample:
<image> Furik's path is marked with yellow, and Rubik's path is marked with pink.
Submitted Solution:
```
n = int(input())
arr = []
dp = []
for i in range(n):
dp.append([0]*n)
arr.append(list(map(int,input().split())))
def maxPath():
x = 0
y = 0
for y in range(n):
for x in range(n):
if x == 0 and y == 0:
dp[y][x] = arr[y][x]
elif x == 0:
dp[y][x] = dp[y-1][x] + arr[y][x]
elif y == 0:
dp[y][x] = dp[y][x-1] + arr[y][x]
else:
dp[y][x] = max(dp[y-1][x], dp[y][x-1]) + arr[y][x]
maxPath()
path = []
def findPath(s):
x = n-1
y = n-1
s = s
while x>0 or y>0:
path.append([y,x])
if x == 0:
s-=arr[y][x]
y-=1
elif y == 0:
s-=arr[y][x]
x-=1
else:
if dp[y-1][x] == s-arr[y][x]:
s-= arr[y][x]
y-=1
else:
s-= arr[y][x]
x-=1
findPath(dp[n-1][n-1])
path.append([0,0])
fs = dp[n-1][n-1]
for i in range(len(path)):
arr[path[i][0]][path[i][1]] = 0
dp = []
for i in range(n):
dp.append([0]*n)
maxPath()
print(dp[n-1][n-1] + fs)
``` | instruction | 0 | 23,130 | 15 | 46,260 |
No | output | 1 | 23,130 | 15 | 46,261 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Furik and Rubik take part in a relay race. The race will be set up on a large square with the side of n meters. The given square is split into n Γ n cells (represented as unit squares), each cell has some number.
At the beginning of the race Furik stands in a cell with coordinates (1, 1), and Rubik stands in a cell with coordinates (n, n). Right after the start Furik runs towards Rubik, besides, if Furik stands at a cell with coordinates (i, j), then he can move to cell (i + 1, j) or (i, j + 1). After Furik reaches Rubik, Rubik starts running from cell with coordinates (n, n) to cell with coordinates (1, 1). If Rubik stands in cell (i, j), then he can move to cell (i - 1, j) or (i, j - 1). Neither Furik, nor Rubik are allowed to go beyond the boundaries of the field; if a player goes beyond the boundaries, he will be disqualified.
To win the race, Furik and Rubik must earn as many points as possible. The number of points is the sum of numbers from the cells Furik and Rubik visited. Each cell counts only once in the sum.
Print the maximum number of points Furik and Rubik can earn on the relay race.
Input
The first line contains a single integer (1 β€ n β€ 300). The next n lines contain n integers each: the j-th number on the i-th line ai, j ( - 1000 β€ ai, j β€ 1000) is the number written in the cell with coordinates (i, j).
Output
On a single line print a single number β the answer to the problem.
Examples
Input
1
5
Output
5
Input
2
11 14
16 12
Output
53
Input
3
25 16 25
12 18 19
11 13 8
Output
136
Note
Comments to the second sample: The profitable path for Furik is: (1, 1), (1, 2), (2, 2), and for Rubik: (2, 2), (2, 1), (1, 1).
Comments to the third sample: The optimal path for Furik is: (1, 1), (1, 2), (1, 3), (2, 3), (3, 3), and for Rubik: (3, 3), (3, 2), (2, 2), (2, 1), (1, 1). The figure to the sample:
<image> Furik's path is marked with yellow, and Rubik's path is marked with pink.
Submitted Solution:
```
n = int(input())
arr = []
dp = []
for i in range(n):
dp.append([0]*n)
arr.append(list(map(int,input().split())))
def maxPathF():
x = 0
y = 0
dp = []
for i in range(n):
dp.append([0]*n)
for y in range(n):
for x in range(y,n):
if x == 0 and y == 0:
dp[y][x] = arr[y][x]
elif x == 0:
dp[y][x] = dp[y-1][x] + arr[y][x]
elif y == 0:
dp[y][x] = dp[y][x-1] + arr[y][x]
else:
dp[y][x] = max(dp[y-1][x], dp[y][x-1]) + arr[y][x]
return dp
def maxPathS():
x = 0
y = 0
dp = []
for i in range(n):
dp.append([0]*n)
for y in range(n):
for x in range(y+1):
if x == 0 and y == 0:
dp[y][x] = arr[y][x]
elif x == 0:
dp[y][x] = dp[y-1][x] + arr[y][x]
elif y == 0:
dp[y][x] = dp[y][x-1] + arr[y][x]
else:
dp[y][x] = max(dp[y-1][x], dp[y][x-1]) + arr[y][x]
return dp
def maxPath():
x = 0
y = 0
for i in range(n):
dp.append([0]*n)
for y in range(n):
for x in range(n):
if x == 0 and y == 0:
dp[y][x] = arr[y][x]
elif x == 0:
dp[y][x] = dp[y-1][x] + arr[y][x]
elif y == 0:
dp[y][x] = dp[y][x-1] + arr[y][x]
else:
dp[y][x] = max(dp[y-1][x], dp[y][x-1]) + arr[y][x]
return dp
f = maxPathF()
s = maxPathS()
dp = s
if f[n-1][n-1] > s[n-1][n-1]:
dp = f
path = []
fs = dp[n-1][n-1]
def findPath(s):
x = n-1
y = n-1
s = s
while x>0 or y>0:
path.append([y,x])
if x == 0:
s-=arr[y][x]
y-=1
elif y == 0:
s-=arr[y][x]
x-=1
else:
s-= arr[y][x]
if dp[y-1][x] == s:
y-=1
else:
x-=1
findPath(dp[n-1][n-1])
path.append([0,0])
for i in range(len(path)):
arr[path[i][0]][path[i][1]] = 0
seconDP = maxPath()
print(fs+seconDP[n-1][n-1])
``` | instruction | 0 | 23,131 | 15 | 46,262 |
No | output | 1 | 23,131 | 15 | 46,263 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Furik and Rubik take part in a relay race. The race will be set up on a large square with the side of n meters. The given square is split into n Γ n cells (represented as unit squares), each cell has some number.
At the beginning of the race Furik stands in a cell with coordinates (1, 1), and Rubik stands in a cell with coordinates (n, n). Right after the start Furik runs towards Rubik, besides, if Furik stands at a cell with coordinates (i, j), then he can move to cell (i + 1, j) or (i, j + 1). After Furik reaches Rubik, Rubik starts running from cell with coordinates (n, n) to cell with coordinates (1, 1). If Rubik stands in cell (i, j), then he can move to cell (i - 1, j) or (i, j - 1). Neither Furik, nor Rubik are allowed to go beyond the boundaries of the field; if a player goes beyond the boundaries, he will be disqualified.
To win the race, Furik and Rubik must earn as many points as possible. The number of points is the sum of numbers from the cells Furik and Rubik visited. Each cell counts only once in the sum.
Print the maximum number of points Furik and Rubik can earn on the relay race.
Input
The first line contains a single integer (1 β€ n β€ 300). The next n lines contain n integers each: the j-th number on the i-th line ai, j ( - 1000 β€ ai, j β€ 1000) is the number written in the cell with coordinates (i, j).
Output
On a single line print a single number β the answer to the problem.
Examples
Input
1
5
Output
5
Input
2
11 14
16 12
Output
53
Input
3
25 16 25
12 18 19
11 13 8
Output
136
Note
Comments to the second sample: The profitable path for Furik is: (1, 1), (1, 2), (2, 2), and for Rubik: (2, 2), (2, 1), (1, 1).
Comments to the third sample: The optimal path for Furik is: (1, 1), (1, 2), (1, 3), (2, 3), (3, 3), and for Rubik: (3, 3), (3, 2), (2, 2), (2, 1), (1, 1). The figure to the sample:
<image> Furik's path is marked with yellow, and Rubik's path is marked with pink.
Submitted Solution:
```
n = int(input())
arr = []
for i in range(n):
arr.append(list(map(int,input().split())))
def maxPathF():
x = 0
y = 0
dp = []
for i in range(n):
dp.append([-10000]*n)
for y in range(n):
for x in range(y,n):
if x == 0 and y == 0:
dp[y][x] = arr[y][x]
elif x == 0:
dp[y][x] = dp[y-1][x] + arr[y][x]
elif y == 0:
dp[y][x] = dp[y][x-1] + arr[y][x]
else:
dp[y][x] = max(dp[y-1][x], dp[y][x-1]) + arr[y][x]
return dp
def maxPathS():
x = 0
y = 0
dp = []
for i in range(n):
dp.append([-10000]*n)
for y in range(n):
for x in range(y+1):
if x == 0 and y == 0:
dp[y][x] = arr[y][x]
elif x == 0:
dp[y][x] = dp[y-1][x] + arr[y][x]
elif y == 0:
dp[y][x] = dp[y][x-1] + arr[y][x]
else:
dp[y][x] = max(dp[y-1][x], dp[y][x-1]) + arr[y][x]
return dp
def maxPath(arrIn):
x = 0
y = 0
arrIn = arrIn
dp = []
for i in range(n):
dp.append([-10000]*n)
for y in range(n):
for x in range(n):
if x == 0 and y == 0:
dp[y][x] = arrIn[y][x]
elif x == 0:
dp[y][x] = dp[y-1][x] + arrIn[y][x]
elif y == 0:
dp[y][x] = dp[y][x-1] + arrIn[y][x]
else:
dp[y][x] = max(dp[y-1][x], dp[y][x-1]) + arrIn[y][x]
return dp
f = maxPathF()
s = maxPathS()
dps = [f,s]
def findPath(s,dp):
pathN = []
x = n-1
y = n-1
s = s
while x>0 or y>0:
pathN.append([y,x])
s-=arr[y][x]
if x == 0:
y-=1
elif y == 0:
x-=1
else:
if dp[y-1][x] == s:
y-=1
else:
x-=1
return pathN
m = -999
for i in range(len(dps)):
nArr = []
for g in range(n):
strN = []
for j in range(n):
strN.append(arr[g][j])
nArr.append(strN)
path=findPath(dps[i][n-1][n-1],dps[i])
# print("DPS")
# print(*dps[i],sep='\n')
# print("PATH", *path,sep="\n")
path.append([0,0])
for g in range(len(path)):
nArr[path[g][0]][path[g][1]] = 0
nedDp = maxPath(nArr)
# print(nedDp[n-1][n-1] + dps[i][n-1][n-1])
m = max(m,nedDp[n-1][n-1] + dps[i][n-1][n-1])
print(m)
``` | instruction | 0 | 23,132 | 15 | 46,264 |
No | output | 1 | 23,132 | 15 | 46,265 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Furik and Rubik take part in a relay race. The race will be set up on a large square with the side of n meters. The given square is split into n Γ n cells (represented as unit squares), each cell has some number.
At the beginning of the race Furik stands in a cell with coordinates (1, 1), and Rubik stands in a cell with coordinates (n, n). Right after the start Furik runs towards Rubik, besides, if Furik stands at a cell with coordinates (i, j), then he can move to cell (i + 1, j) or (i, j + 1). After Furik reaches Rubik, Rubik starts running from cell with coordinates (n, n) to cell with coordinates (1, 1). If Rubik stands in cell (i, j), then he can move to cell (i - 1, j) or (i, j - 1). Neither Furik, nor Rubik are allowed to go beyond the boundaries of the field; if a player goes beyond the boundaries, he will be disqualified.
To win the race, Furik and Rubik must earn as many points as possible. The number of points is the sum of numbers from the cells Furik and Rubik visited. Each cell counts only once in the sum.
Print the maximum number of points Furik and Rubik can earn on the relay race.
Input
The first line contains a single integer (1 β€ n β€ 300). The next n lines contain n integers each: the j-th number on the i-th line ai, j ( - 1000 β€ ai, j β€ 1000) is the number written in the cell with coordinates (i, j).
Output
On a single line print a single number β the answer to the problem.
Examples
Input
1
5
Output
5
Input
2
11 14
16 12
Output
53
Input
3
25 16 25
12 18 19
11 13 8
Output
136
Note
Comments to the second sample: The profitable path for Furik is: (1, 1), (1, 2), (2, 2), and for Rubik: (2, 2), (2, 1), (1, 1).
Comments to the third sample: The optimal path for Furik is: (1, 1), (1, 2), (1, 3), (2, 3), (3, 3), and for Rubik: (3, 3), (3, 2), (2, 2), (2, 1), (1, 1). The figure to the sample:
<image> Furik's path is marked with yellow, and Rubik's path is marked with pink.
Submitted Solution:
```
n = int(input())
arr = []
for i in range(n):
arr.append(list(map(int,input().split())))
def maxPathF():
x = 0
y = 0
dp = []
for i in range(n):
dp.append([0]*n)
for y in range(n):
for x in range(y,n):
if x == 0 and y == 0:
dp[y][x] = arr[y][x]
elif x == 0:
dp[y][x] = dp[y-1][x] + arr[y][x]
elif y == 0:
dp[y][x] = dp[y][x-1] + arr[y][x]
else:
dp[y][x] = max(dp[y-1][x], dp[y][x-1]) + arr[y][x]
return dp
def maxPathS():
x = 0
y = 0
dp = []
for i in range(n):
dp.append([0]*n)
for y in range(n):
for x in range(y+1):
if x == 0 and y == 0:
dp[y][x] = arr[y][x]
elif x == 0:
dp[y][x] = dp[y-1][x] + arr[y][x]
elif y == 0:
dp[y][x] = dp[y][x-1] + arr[y][x]
else:
dp[y][x] = max(dp[y-1][x], dp[y][x-1]) + arr[y][x]
return dp
def maxPath(arrIn):
x = 0
y = 0
arrIn = arrIn
dp = []
for i in range(n):
dp.append([0]*n)
for y in range(n):
for x in range(n):
if x == 0 and y == 0:
dp[y][x] = arrIn[y][x]
elif x == 0:
dp[y][x] = dp[y-1][x] + arrIn[y][x]
elif y == 0:
dp[y][x] = dp[y][x-1] + arrIn[y][x]
else:
dp[y][x] = max(dp[y-1][x], dp[y][x-1]) + arrIn[y][x]
return dp
f = maxPathF()
s = maxPathS()
dps = [f,s]
def findPath(s,dp):
pathN = []
x = n-1
y = n-1
s = s
while x>0 or y>0:
pathN.append([y,x])
s-=arr[y][x]
if x == 0:
y-=1
elif y == 0:
x-=1
else:
if dp[y-1][x] == s:
y-=1
else:
x-=1
return pathN
m = -999
for i in range(len(dps)):
nArr = []
for g in range(n):
strN = []
for j in range(n):
strN.append(arr[g][j])
nArr.append(strN)
path=findPath(dps[i][n-1][n-1],dps[i])
# print("DPS")
# print(*dps[i],sep='\n')
# print("PATH", *path,sep="\n")
path.append([0,0])
for g in range(len(path)):
nArr[path[g][0]][path[g][1]] = 0
nedDp = maxPath(nArr)
# print(nedDp[n-1][n-1] + dps[i][n-1][n-1])
m = max(m,nedDp[n-1][n-1] + dps[i][n-1][n-1])
print(m)
``` | instruction | 0 | 23,133 | 15 | 46,266 |
No | output | 1 | 23,133 | 15 | 46,267 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Inna likes sweets and a game called the "Candy Matrix". Today, she came up with the new game "Candy Matrix 2: Reload".
The field for the new game is a rectangle table of size n Γ m. Each line of the table contains one cell with a dwarf figurine, one cell with a candy, the other cells of the line are empty. The game lasts for several moves. During each move the player should choose all lines of the matrix where dwarf is not on the cell with candy and shout "Let's go!". After that, all the dwarves from the chosen lines start to simultaneously move to the right. During each second, each dwarf goes to the adjacent cell that is located to the right of its current cell. The movement continues until one of the following events occurs:
* some dwarf in one of the chosen lines is located in the rightmost cell of his row;
* some dwarf in the chosen lines is located in the cell with the candy.
The point of the game is to transport all the dwarves to the candy cells.
Inna is fabulous, as she came up with such an interesting game. But what about you? Your task is to play this game optimally well. Specifically, you should say by the given game field what minimum number of moves the player needs to reach the goal of the game.
Input
The first line of the input contains two integers n and m (1 β€ n β€ 1000; 2 β€ m β€ 1000).
Next n lines each contain m characters β the game field for the "Candy Martix 2: Reload". Character "*" represents an empty cell of the field, character "G" represents a dwarf and character "S" represents a candy. The matrix doesn't contain other characters. It is guaranteed that each line contains exactly one character "G" and one character "S".
Output
In a single line print a single integer β either the minimum number of moves needed to achieve the aim of the game, or -1, if the aim cannot be achieved on the given game field.
Examples
Input
3 4
*G*S
G**S
*G*S
Output
2
Input
1 3
S*G
Output
-1 | instruction | 0 | 23,214 | 15 | 46,428 |
Tags: brute force, implementation, schedules
Correct Solution:
```
n, m = map(int, input().split())
c = set(s.find("S") - s.find("G") for s in (input() for _ in range(n)))
print(-1 if any(a < 0 for a in c) else len(c))
# Made By Mostafa_Khaled
``` | output | 1 | 23,214 | 15 | 46,429 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Inna likes sweets and a game called the "Candy Matrix". Today, she came up with the new game "Candy Matrix 2: Reload".
The field for the new game is a rectangle table of size n Γ m. Each line of the table contains one cell with a dwarf figurine, one cell with a candy, the other cells of the line are empty. The game lasts for several moves. During each move the player should choose all lines of the matrix where dwarf is not on the cell with candy and shout "Let's go!". After that, all the dwarves from the chosen lines start to simultaneously move to the right. During each second, each dwarf goes to the adjacent cell that is located to the right of its current cell. The movement continues until one of the following events occurs:
* some dwarf in one of the chosen lines is located in the rightmost cell of his row;
* some dwarf in the chosen lines is located in the cell with the candy.
The point of the game is to transport all the dwarves to the candy cells.
Inna is fabulous, as she came up with such an interesting game. But what about you? Your task is to play this game optimally well. Specifically, you should say by the given game field what minimum number of moves the player needs to reach the goal of the game.
Input
The first line of the input contains two integers n and m (1 β€ n β€ 1000; 2 β€ m β€ 1000).
Next n lines each contain m characters β the game field for the "Candy Martix 2: Reload". Character "*" represents an empty cell of the field, character "G" represents a dwarf and character "S" represents a candy. The matrix doesn't contain other characters. It is guaranteed that each line contains exactly one character "G" and one character "S".
Output
In a single line print a single integer β either the minimum number of moves needed to achieve the aim of the game, or -1, if the aim cannot be achieved on the given game field.
Examples
Input
3 4
*G*S
G**S
*G*S
Output
2
Input
1 3
S*G
Output
-1 | instruction | 0 | 23,215 | 15 | 46,430 |
Tags: brute force, implementation, schedules
Correct Solution:
```
n, m = map(int, input().split())
arr = []
ans = 0
flag = True
for i in range(n):
s = input()
if(flag):
gap = s.find("S") - s.find("G")
if(gap > 0):
if(gap not in arr):
arr.append(gap)
ans += 1
else:
flag = False
if(flag):
print(ans)
else:
print(-1)
``` | output | 1 | 23,215 | 15 | 46,431 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Inna likes sweets and a game called the "Candy Matrix". Today, she came up with the new game "Candy Matrix 2: Reload".
The field for the new game is a rectangle table of size n Γ m. Each line of the table contains one cell with a dwarf figurine, one cell with a candy, the other cells of the line are empty. The game lasts for several moves. During each move the player should choose all lines of the matrix where dwarf is not on the cell with candy and shout "Let's go!". After that, all the dwarves from the chosen lines start to simultaneously move to the right. During each second, each dwarf goes to the adjacent cell that is located to the right of its current cell. The movement continues until one of the following events occurs:
* some dwarf in one of the chosen lines is located in the rightmost cell of his row;
* some dwarf in the chosen lines is located in the cell with the candy.
The point of the game is to transport all the dwarves to the candy cells.
Inna is fabulous, as she came up with such an interesting game. But what about you? Your task is to play this game optimally well. Specifically, you should say by the given game field what minimum number of moves the player needs to reach the goal of the game.
Input
The first line of the input contains two integers n and m (1 β€ n β€ 1000; 2 β€ m β€ 1000).
Next n lines each contain m characters β the game field for the "Candy Martix 2: Reload". Character "*" represents an empty cell of the field, character "G" represents a dwarf and character "S" represents a candy. The matrix doesn't contain other characters. It is guaranteed that each line contains exactly one character "G" and one character "S".
Output
In a single line print a single integer β either the minimum number of moves needed to achieve the aim of the game, or -1, if the aim cannot be achieved on the given game field.
Examples
Input
3 4
*G*S
G**S
*G*S
Output
2
Input
1 3
S*G
Output
-1 | instruction | 0 | 23,216 | 15 | 46,432 |
Tags: brute force, implementation, schedules
Correct Solution:
```
#!/usr/bin/python3
"B. Students and Shoelaces"
"Codeforces Beta Round #94 (Div. 2 Only)"
# n,m=map(int,input().split())
# d={}
# for i in range(m):
# z,x=map(int,input().split())
# d.setdefault(z,[])
# d.setdefault(x,[])
# d[z].append(x)
# d[x].append(z)
# k=0
# while True:
# f=0
# t=[False]*(n+1)
# # print(d)
# for i in range(1,n+1):
# if d.get(i) and len(d[i])==1 and t[i]==False:
# # print(i,d[i])
# asdf=d[i].pop(0)
# d[asdf].remove(i)
# t[asdf]=True
# t[i]=True
# f=1
# if f==0:
# break
# k+=1
# print(k)
"Codeforces Round #272 (Div. 2)"
"B. Dreamoon and WiFi"
# q=0
# for i in input():
# if i=='+':
# q+=1
# else:
# q-=1
# a=k=0
# for i in input():
# if i=='+':
# k+=1
# elif i=='-':
# k-=1
# else:
# a+=1
# arr=[k]
# for i in range(a):
# arr.extend(arr)
# for j in range(int(len(arr)/2)):
# arr[j]+=1
# for j in range(int(len(arr)/2),len(arr)):
# arr[j]-=1
# hit=arr.count(q)
# print(hit/2**a)
"Codeforces Round #268 (Div. 2)"
"B. Chat Online"
# p,q,l,r=map(int,input().split())
# z=[]
# x=[]
# for i in range(p):
# a,b=map(int,input().split())
# z.append([a,b])
# for i in range(q):
# c,d=map(int,input().split())
# x.append([c,d])
# s=[i for i in range(l,r+1)]
# s=set(s)
# lr=set()
# # print(z,x)
# for j in z:
# for i in x:
# add=[]
# if i[0]>j[1]:
# continue
# elif i[0]>=j[0]:
# add.extend([t for t in range(0,j[1]-i[0]+1)])
# elif i[1]>=j[0]:
# add.extend([t for t in range(0,j[1]-i[0]+1)])
# elif i[1]<j[0]:
# add.extend([t for t in range(j[0]-i[1],j[1]-i[0]+1)])
# m=set(add)
# # print(add,m,i,j)
# lr=lr.union(m)
# # print(s,lr)
# print(len(s.intersection(lr)))
"Codeforces Round #132 (Div. 2)"
"B. Olympic Medal"
# from math import sqrt
# x=list(map(int,input().split()))
# y=list(map(int,input().split()))
# z=list(map(int,input().split()))
# r1=max(x[1:])
# p1=max(y[1:])
# p2=min(z[1:])
# a,b=map(int,input().split())
# bp1=b*p1
# ap2=a*p2
# r2=r1*sqrt(bp1/(bp1+ap2))
# print(r2)
"Codeforces Round #371 (Div. 2)"
"B. Filya and Homework"
# n=int(input())
# a=list(map(int,input().split()))
# s=list(set(a))
# if (len(s)==3 and sum(s)%3==0 and sum(s)/3 in s) or len(s)<3:
# print("YES")
# else:
# print("NO")
"Codeforces Round #234 (Div. 2)"
"B. Inna and New Matrix of Candies"
n,m=map(int,input().split())
r=[]
for i in range(n):
a=list(input())
fg=0
d=0
for j in range(m):
if a[j]=='G':
fg=j+1
elif fg==0 and a[j]=='S':
fg=-1
break
elif fg!=0 and a[j]=='S':
d+=1
break
elif fg!=0:
d+=1
if fg==-1:
print(-1)
break
r.append(d)
# print(r)
if fg!=-1:
print(len(set(r)))
``` | output | 1 | 23,216 | 15 | 46,433 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Inna likes sweets and a game called the "Candy Matrix". Today, she came up with the new game "Candy Matrix 2: Reload".
The field for the new game is a rectangle table of size n Γ m. Each line of the table contains one cell with a dwarf figurine, one cell with a candy, the other cells of the line are empty. The game lasts for several moves. During each move the player should choose all lines of the matrix where dwarf is not on the cell with candy and shout "Let's go!". After that, all the dwarves from the chosen lines start to simultaneously move to the right. During each second, each dwarf goes to the adjacent cell that is located to the right of its current cell. The movement continues until one of the following events occurs:
* some dwarf in one of the chosen lines is located in the rightmost cell of his row;
* some dwarf in the chosen lines is located in the cell with the candy.
The point of the game is to transport all the dwarves to the candy cells.
Inna is fabulous, as she came up with such an interesting game. But what about you? Your task is to play this game optimally well. Specifically, you should say by the given game field what minimum number of moves the player needs to reach the goal of the game.
Input
The first line of the input contains two integers n and m (1 β€ n β€ 1000; 2 β€ m β€ 1000).
Next n lines each contain m characters β the game field for the "Candy Martix 2: Reload". Character "*" represents an empty cell of the field, character "G" represents a dwarf and character "S" represents a candy. The matrix doesn't contain other characters. It is guaranteed that each line contains exactly one character "G" and one character "S".
Output
In a single line print a single integer β either the minimum number of moves needed to achieve the aim of the game, or -1, if the aim cannot be achieved on the given game field.
Examples
Input
3 4
*G*S
G**S
*G*S
Output
2
Input
1 3
S*G
Output
-1 | instruction | 0 | 23,217 | 15 | 46,434 |
Tags: brute force, implementation, schedules
Correct Solution:
```
n,m = list(map(int,input().split()))
a = []
ans = set()
for i in range(n):
a.append(input())
ind_G = a[i].index('G')
ind_S = a[i].index('S')
if ind_S<ind_G:
print(-1)
exit()
ans.add(ind_S-ind_G)
print(len(ans))
``` | output | 1 | 23,217 | 15 | 46,435 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Inna likes sweets and a game called the "Candy Matrix". Today, she came up with the new game "Candy Matrix 2: Reload".
The field for the new game is a rectangle table of size n Γ m. Each line of the table contains one cell with a dwarf figurine, one cell with a candy, the other cells of the line are empty. The game lasts for several moves. During each move the player should choose all lines of the matrix where dwarf is not on the cell with candy and shout "Let's go!". After that, all the dwarves from the chosen lines start to simultaneously move to the right. During each second, each dwarf goes to the adjacent cell that is located to the right of its current cell. The movement continues until one of the following events occurs:
* some dwarf in one of the chosen lines is located in the rightmost cell of his row;
* some dwarf in the chosen lines is located in the cell with the candy.
The point of the game is to transport all the dwarves to the candy cells.
Inna is fabulous, as she came up with such an interesting game. But what about you? Your task is to play this game optimally well. Specifically, you should say by the given game field what minimum number of moves the player needs to reach the goal of the game.
Input
The first line of the input contains two integers n and m (1 β€ n β€ 1000; 2 β€ m β€ 1000).
Next n lines each contain m characters β the game field for the "Candy Martix 2: Reload". Character "*" represents an empty cell of the field, character "G" represents a dwarf and character "S" represents a candy. The matrix doesn't contain other characters. It is guaranteed that each line contains exactly one character "G" and one character "S".
Output
In a single line print a single integer β either the minimum number of moves needed to achieve the aim of the game, or -1, if the aim cannot be achieved on the given game field.
Examples
Input
3 4
*G*S
G**S
*G*S
Output
2
Input
1 3
S*G
Output
-1 | instruction | 0 | 23,218 | 15 | 46,436 |
Tags: brute force, implementation, schedules
Correct Solution:
```
N = 1000
dis = set([])
n, m = map(int, input().split(' '))
f = False
for i in range(n):
s = input()
dist = s.index('S') - s.index('G')
#print(dist)
if dist < 0:
f = True
break
if dist not in dis:
dis.add(dist)
if f:
print(-1)
else:
print(len(dis))
``` | output | 1 | 23,218 | 15 | 46,437 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Inna likes sweets and a game called the "Candy Matrix". Today, she came up with the new game "Candy Matrix 2: Reload".
The field for the new game is a rectangle table of size n Γ m. Each line of the table contains one cell with a dwarf figurine, one cell with a candy, the other cells of the line are empty. The game lasts for several moves. During each move the player should choose all lines of the matrix where dwarf is not on the cell with candy and shout "Let's go!". After that, all the dwarves from the chosen lines start to simultaneously move to the right. During each second, each dwarf goes to the adjacent cell that is located to the right of its current cell. The movement continues until one of the following events occurs:
* some dwarf in one of the chosen lines is located in the rightmost cell of his row;
* some dwarf in the chosen lines is located in the cell with the candy.
The point of the game is to transport all the dwarves to the candy cells.
Inna is fabulous, as she came up with such an interesting game. But what about you? Your task is to play this game optimally well. Specifically, you should say by the given game field what minimum number of moves the player needs to reach the goal of the game.
Input
The first line of the input contains two integers n and m (1 β€ n β€ 1000; 2 β€ m β€ 1000).
Next n lines each contain m characters β the game field for the "Candy Martix 2: Reload". Character "*" represents an empty cell of the field, character "G" represents a dwarf and character "S" represents a candy. The matrix doesn't contain other characters. It is guaranteed that each line contains exactly one character "G" and one character "S".
Output
In a single line print a single integer β either the minimum number of moves needed to achieve the aim of the game, or -1, if the aim cannot be achieved on the given game field.
Examples
Input
3 4
*G*S
G**S
*G*S
Output
2
Input
1 3
S*G
Output
-1 | instruction | 0 | 23,219 | 15 | 46,438 |
Tags: brute force, implementation, schedules
Correct Solution:
```
n, m = map(int, input().split())
s = set()
prnt = True
for i in range(n):
row = list(input())
G = row.index("G")
S = row.index("S")
if S < G:
print(-1)
prnt = False
break
s.add(S - G)
if prnt:
print(len(s))
``` | output | 1 | 23,219 | 15 | 46,439 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Inna likes sweets and a game called the "Candy Matrix". Today, she came up with the new game "Candy Matrix 2: Reload".
The field for the new game is a rectangle table of size n Γ m. Each line of the table contains one cell with a dwarf figurine, one cell with a candy, the other cells of the line are empty. The game lasts for several moves. During each move the player should choose all lines of the matrix where dwarf is not on the cell with candy and shout "Let's go!". After that, all the dwarves from the chosen lines start to simultaneously move to the right. During each second, each dwarf goes to the adjacent cell that is located to the right of its current cell. The movement continues until one of the following events occurs:
* some dwarf in one of the chosen lines is located in the rightmost cell of his row;
* some dwarf in the chosen lines is located in the cell with the candy.
The point of the game is to transport all the dwarves to the candy cells.
Inna is fabulous, as she came up with such an interesting game. But what about you? Your task is to play this game optimally well. Specifically, you should say by the given game field what minimum number of moves the player needs to reach the goal of the game.
Input
The first line of the input contains two integers n and m (1 β€ n β€ 1000; 2 β€ m β€ 1000).
Next n lines each contain m characters β the game field for the "Candy Martix 2: Reload". Character "*" represents an empty cell of the field, character "G" represents a dwarf and character "S" represents a candy. The matrix doesn't contain other characters. It is guaranteed that each line contains exactly one character "G" and one character "S".
Output
In a single line print a single integer β either the minimum number of moves needed to achieve the aim of the game, or -1, if the aim cannot be achieved on the given game field.
Examples
Input
3 4
*G*S
G**S
*G*S
Output
2
Input
1 3
S*G
Output
-1 | instruction | 0 | 23,220 | 15 | 46,440 |
Tags: brute force, implementation, schedules
Correct Solution:
```
n,m=map(int,input().split(" "))
li=[]
for i in range(n):
s=input()
li.append(s)
fl=0
hs=[0]*1001
for i in range(n):
cid=li[i].find('S')
did=li[i].find('G')
if cid<did:
fl=1
break
else:
hs[cid-did]=1
if fl==1:
print(-1)
else:
ans=0
for i in range(1001):
if hs[i]==1:
ans+=1
print(ans)
``` | output | 1 | 23,220 | 15 | 46,441 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Inna likes sweets and a game called the "Candy Matrix". Today, she came up with the new game "Candy Matrix 2: Reload".
The field for the new game is a rectangle table of size n Γ m. Each line of the table contains one cell with a dwarf figurine, one cell with a candy, the other cells of the line are empty. The game lasts for several moves. During each move the player should choose all lines of the matrix where dwarf is not on the cell with candy and shout "Let's go!". After that, all the dwarves from the chosen lines start to simultaneously move to the right. During each second, each dwarf goes to the adjacent cell that is located to the right of its current cell. The movement continues until one of the following events occurs:
* some dwarf in one of the chosen lines is located in the rightmost cell of his row;
* some dwarf in the chosen lines is located in the cell with the candy.
The point of the game is to transport all the dwarves to the candy cells.
Inna is fabulous, as she came up with such an interesting game. But what about you? Your task is to play this game optimally well. Specifically, you should say by the given game field what minimum number of moves the player needs to reach the goal of the game.
Input
The first line of the input contains two integers n and m (1 β€ n β€ 1000; 2 β€ m β€ 1000).
Next n lines each contain m characters β the game field for the "Candy Martix 2: Reload". Character "*" represents an empty cell of the field, character "G" represents a dwarf and character "S" represents a candy. The matrix doesn't contain other characters. It is guaranteed that each line contains exactly one character "G" and one character "S".
Output
In a single line print a single integer β either the minimum number of moves needed to achieve the aim of the game, or -1, if the aim cannot be achieved on the given game field.
Examples
Input
3 4
*G*S
G**S
*G*S
Output
2
Input
1 3
S*G
Output
-1 | instruction | 0 | 23,221 | 15 | 46,442 |
Tags: brute force, implementation, schedules
Correct Solution:
```
n, m = map(int, input().split())
c = set(s.find("S") - s.find("G") for s in (input() for _ in range(n)))
print(-1 if any(a < 0 for a in c) else len(c))
``` | output | 1 | 23,221 | 15 | 46,443 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Inna likes sweets and a game called the "Candy Matrix". Today, she came up with the new game "Candy Matrix 2: Reload".
The field for the new game is a rectangle table of size n Γ m. Each line of the table contains one cell with a dwarf figurine, one cell with a candy, the other cells of the line are empty. The game lasts for several moves. During each move the player should choose all lines of the matrix where dwarf is not on the cell with candy and shout "Let's go!". After that, all the dwarves from the chosen lines start to simultaneously move to the right. During each second, each dwarf goes to the adjacent cell that is located to the right of its current cell. The movement continues until one of the following events occurs:
* some dwarf in one of the chosen lines is located in the rightmost cell of his row;
* some dwarf in the chosen lines is located in the cell with the candy.
The point of the game is to transport all the dwarves to the candy cells.
Inna is fabulous, as she came up with such an interesting game. But what about you? Your task is to play this game optimally well. Specifically, you should say by the given game field what minimum number of moves the player needs to reach the goal of the game.
Input
The first line of the input contains two integers n and m (1 β€ n β€ 1000; 2 β€ m β€ 1000).
Next n lines each contain m characters β the game field for the "Candy Martix 2: Reload". Character "*" represents an empty cell of the field, character "G" represents a dwarf and character "S" represents a candy. The matrix doesn't contain other characters. It is guaranteed that each line contains exactly one character "G" and one character "S".
Output
In a single line print a single integer β either the minimum number of moves needed to achieve the aim of the game, or -1, if the aim cannot be achieved on the given game field.
Examples
Input
3 4
*G*S
G**S
*G*S
Output
2
Input
1 3
S*G
Output
-1
Submitted Solution:
```
import sys
from functools import lru_cache
def main(mat):
dist = []
for row in mat:
g = row.index('G')
s = row.index('S')
if g > s:
print(-1)
return
else:
if s - g > 0:
dist.append(s - g)
# Game can be won.
print(len(set(dist)))
if __name__ == "__main__":
mat = []
for e, line in enumerate(sys.stdin.readlines()):
inp = line.strip()
if e == 0:
continue
mat.append(list(c for c in inp))
main(mat)
``` | instruction | 0 | 23,222 | 15 | 46,444 |
Yes | output | 1 | 23,222 | 15 | 46,445 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Inna likes sweets and a game called the "Candy Matrix". Today, she came up with the new game "Candy Matrix 2: Reload".
The field for the new game is a rectangle table of size n Γ m. Each line of the table contains one cell with a dwarf figurine, one cell with a candy, the other cells of the line are empty. The game lasts for several moves. During each move the player should choose all lines of the matrix where dwarf is not on the cell with candy and shout "Let's go!". After that, all the dwarves from the chosen lines start to simultaneously move to the right. During each second, each dwarf goes to the adjacent cell that is located to the right of its current cell. The movement continues until one of the following events occurs:
* some dwarf in one of the chosen lines is located in the rightmost cell of his row;
* some dwarf in the chosen lines is located in the cell with the candy.
The point of the game is to transport all the dwarves to the candy cells.
Inna is fabulous, as she came up with such an interesting game. But what about you? Your task is to play this game optimally well. Specifically, you should say by the given game field what minimum number of moves the player needs to reach the goal of the game.
Input
The first line of the input contains two integers n and m (1 β€ n β€ 1000; 2 β€ m β€ 1000).
Next n lines each contain m characters β the game field for the "Candy Martix 2: Reload". Character "*" represents an empty cell of the field, character "G" represents a dwarf and character "S" represents a candy. The matrix doesn't contain other characters. It is guaranteed that each line contains exactly one character "G" and one character "S".
Output
In a single line print a single integer β either the minimum number of moves needed to achieve the aim of the game, or -1, if the aim cannot be achieved on the given game field.
Examples
Input
3 4
*G*S
G**S
*G*S
Output
2
Input
1 3
S*G
Output
-1
Submitted Solution:
```
def main():
n, m = [int(i) for i in input().split()]
matrix = []
for i in range(n):
s = input()
matrix.append(s)
a = set()
valid = True
for i in range(n):
g = 0
s = 0
for j in range(m):
if matrix[i][j] == 'G':
g = j
if matrix[i][j] == 'S':
s = j
if s - g > 0:
a.add(s - g)
else:
valid = False
break
if valid:
print(len(a))
else:
print(-1)
main()
``` | instruction | 0 | 23,223 | 15 | 46,446 |
Yes | output | 1 | 23,223 | 15 | 46,447 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Inna likes sweets and a game called the "Candy Matrix". Today, she came up with the new game "Candy Matrix 2: Reload".
The field for the new game is a rectangle table of size n Γ m. Each line of the table contains one cell with a dwarf figurine, one cell with a candy, the other cells of the line are empty. The game lasts for several moves. During each move the player should choose all lines of the matrix where dwarf is not on the cell with candy and shout "Let's go!". After that, all the dwarves from the chosen lines start to simultaneously move to the right. During each second, each dwarf goes to the adjacent cell that is located to the right of its current cell. The movement continues until one of the following events occurs:
* some dwarf in one of the chosen lines is located in the rightmost cell of his row;
* some dwarf in the chosen lines is located in the cell with the candy.
The point of the game is to transport all the dwarves to the candy cells.
Inna is fabulous, as she came up with such an interesting game. But what about you? Your task is to play this game optimally well. Specifically, you should say by the given game field what minimum number of moves the player needs to reach the goal of the game.
Input
The first line of the input contains two integers n and m (1 β€ n β€ 1000; 2 β€ m β€ 1000).
Next n lines each contain m characters β the game field for the "Candy Martix 2: Reload". Character "*" represents an empty cell of the field, character "G" represents a dwarf and character "S" represents a candy. The matrix doesn't contain other characters. It is guaranteed that each line contains exactly one character "G" and one character "S".
Output
In a single line print a single integer β either the minimum number of moves needed to achieve the aim of the game, or -1, if the aim cannot be achieved on the given game field.
Examples
Input
3 4
*G*S
G**S
*G*S
Output
2
Input
1 3
S*G
Output
-1
Submitted Solution:
```
n,m=map(int,input().split())
l=[]
for i in range(n):
k=list(input())
s=-1
for j in range(m):
if k[j]=="G":
for a in range(j+1,m):
if k[a]=="S":
s=abs(j-a)
l.append(s)
if min(l)==-1:
print(-1)
else:
print(len(set(l)))
``` | instruction | 0 | 23,224 | 15 | 46,448 |
Yes | output | 1 | 23,224 | 15 | 46,449 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Inna likes sweets and a game called the "Candy Matrix". Today, she came up with the new game "Candy Matrix 2: Reload".
The field for the new game is a rectangle table of size n Γ m. Each line of the table contains one cell with a dwarf figurine, one cell with a candy, the other cells of the line are empty. The game lasts for several moves. During each move the player should choose all lines of the matrix where dwarf is not on the cell with candy and shout "Let's go!". After that, all the dwarves from the chosen lines start to simultaneously move to the right. During each second, each dwarf goes to the adjacent cell that is located to the right of its current cell. The movement continues until one of the following events occurs:
* some dwarf in one of the chosen lines is located in the rightmost cell of his row;
* some dwarf in the chosen lines is located in the cell with the candy.
The point of the game is to transport all the dwarves to the candy cells.
Inna is fabulous, as she came up with such an interesting game. But what about you? Your task is to play this game optimally well. Specifically, you should say by the given game field what minimum number of moves the player needs to reach the goal of the game.
Input
The first line of the input contains two integers n and m (1 β€ n β€ 1000; 2 β€ m β€ 1000).
Next n lines each contain m characters β the game field for the "Candy Martix 2: Reload". Character "*" represents an empty cell of the field, character "G" represents a dwarf and character "S" represents a candy. The matrix doesn't contain other characters. It is guaranteed that each line contains exactly one character "G" and one character "S".
Output
In a single line print a single integer β either the minimum number of moves needed to achieve the aim of the game, or -1, if the aim cannot be achieved on the given game field.
Examples
Input
3 4
*G*S
G**S
*G*S
Output
2
Input
1 3
S*G
Output
-1
Submitted Solution:
```
from sys import stdin, stdout
def main():
n, m = map(int, stdin.readline().split())
s = set()
for _ in range(n):
l = stdin.readline().strip()
dwarf = -1
candy = -1
for i in range(m):
if l[i] == "G":
dwarf = i
if l[i] == "S":
candy = i
if candy < dwarf:
print(-1)
return
s.add(candy-dwarf)
print(len(s))
return
main()
``` | instruction | 0 | 23,225 | 15 | 46,450 |
Yes | output | 1 | 23,225 | 15 | 46,451 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Inna likes sweets and a game called the "Candy Matrix". Today, she came up with the new game "Candy Matrix 2: Reload".
The field for the new game is a rectangle table of size n Γ m. Each line of the table contains one cell with a dwarf figurine, one cell with a candy, the other cells of the line are empty. The game lasts for several moves. During each move the player should choose all lines of the matrix where dwarf is not on the cell with candy and shout "Let's go!". After that, all the dwarves from the chosen lines start to simultaneously move to the right. During each second, each dwarf goes to the adjacent cell that is located to the right of its current cell. The movement continues until one of the following events occurs:
* some dwarf in one of the chosen lines is located in the rightmost cell of his row;
* some dwarf in the chosen lines is located in the cell with the candy.
The point of the game is to transport all the dwarves to the candy cells.
Inna is fabulous, as she came up with such an interesting game. But what about you? Your task is to play this game optimally well. Specifically, you should say by the given game field what minimum number of moves the player needs to reach the goal of the game.
Input
The first line of the input contains two integers n and m (1 β€ n β€ 1000; 2 β€ m β€ 1000).
Next n lines each contain m characters β the game field for the "Candy Martix 2: Reload". Character "*" represents an empty cell of the field, character "G" represents a dwarf and character "S" represents a candy. The matrix doesn't contain other characters. It is guaranteed that each line contains exactly one character "G" and one character "S".
Output
In a single line print a single integer β either the minimum number of moves needed to achieve the aim of the game, or -1, if the aim cannot be achieved on the given game field.
Examples
Input
3 4
*G*S
G**S
*G*S
Output
2
Input
1 3
S*G
Output
-1
Submitted Solution:
```
# ip = open("testdata.txt", "r")
# def input():
# return ip.readline().strip()
n, m = map(int, input().split())
can_happen = True
dist = [0]*n
max_dist = 0
for i in range(n):
strr = input()
g = strr.index('G')
s = strr.index('S')
if g > s: can_happen = False
max_dist = max(max_dist, s - g - 1)
print(max_dist if can_happen else -1)
``` | instruction | 0 | 23,226 | 15 | 46,452 |
No | output | 1 | 23,226 | 15 | 46,453 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Inna likes sweets and a game called the "Candy Matrix". Today, she came up with the new game "Candy Matrix 2: Reload".
The field for the new game is a rectangle table of size n Γ m. Each line of the table contains one cell with a dwarf figurine, one cell with a candy, the other cells of the line are empty. The game lasts for several moves. During each move the player should choose all lines of the matrix where dwarf is not on the cell with candy and shout "Let's go!". After that, all the dwarves from the chosen lines start to simultaneously move to the right. During each second, each dwarf goes to the adjacent cell that is located to the right of its current cell. The movement continues until one of the following events occurs:
* some dwarf in one of the chosen lines is located in the rightmost cell of his row;
* some dwarf in the chosen lines is located in the cell with the candy.
The point of the game is to transport all the dwarves to the candy cells.
Inna is fabulous, as she came up with such an interesting game. But what about you? Your task is to play this game optimally well. Specifically, you should say by the given game field what minimum number of moves the player needs to reach the goal of the game.
Input
The first line of the input contains two integers n and m (1 β€ n β€ 1000; 2 β€ m β€ 1000).
Next n lines each contain m characters β the game field for the "Candy Martix 2: Reload". Character "*" represents an empty cell of the field, character "G" represents a dwarf and character "S" represents a candy. The matrix doesn't contain other characters. It is guaranteed that each line contains exactly one character "G" and one character "S".
Output
In a single line print a single integer β either the minimum number of moves needed to achieve the aim of the game, or -1, if the aim cannot be achieved on the given game field.
Examples
Input
3 4
*G*S
G**S
*G*S
Output
2
Input
1 3
S*G
Output
-1
Submitted Solution:
```
n,m=map(int,input().split())
dp=[]
for i in range(n):
x=input()
dp.append(x)
ans=-1
l=0
for i in range(n):
for j in range(m):
if dp[i][j]=='G':
p=j
if dp[i][j]=='S':
q=j
#print(p,q)
if p>q:
l=1
print(-1)
break
else:
ans=max(q-p-1,ans)
#print(ans)
if l==0:
print(ans)
``` | instruction | 0 | 23,227 | 15 | 46,454 |
No | output | 1 | 23,227 | 15 | 46,455 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Inna likes sweets and a game called the "Candy Matrix". Today, she came up with the new game "Candy Matrix 2: Reload".
The field for the new game is a rectangle table of size n Γ m. Each line of the table contains one cell with a dwarf figurine, one cell with a candy, the other cells of the line are empty. The game lasts for several moves. During each move the player should choose all lines of the matrix where dwarf is not on the cell with candy and shout "Let's go!". After that, all the dwarves from the chosen lines start to simultaneously move to the right. During each second, each dwarf goes to the adjacent cell that is located to the right of its current cell. The movement continues until one of the following events occurs:
* some dwarf in one of the chosen lines is located in the rightmost cell of his row;
* some dwarf in the chosen lines is located in the cell with the candy.
The point of the game is to transport all the dwarves to the candy cells.
Inna is fabulous, as she came up with such an interesting game. But what about you? Your task is to play this game optimally well. Specifically, you should say by the given game field what minimum number of moves the player needs to reach the goal of the game.
Input
The first line of the input contains two integers n and m (1 β€ n β€ 1000; 2 β€ m β€ 1000).
Next n lines each contain m characters β the game field for the "Candy Martix 2: Reload". Character "*" represents an empty cell of the field, character "G" represents a dwarf and character "S" represents a candy. The matrix doesn't contain other characters. It is guaranteed that each line contains exactly one character "G" and one character "S".
Output
In a single line print a single integer β either the minimum number of moves needed to achieve the aim of the game, or -1, if the aim cannot be achieved on the given game field.
Examples
Input
3 4
*G*S
G**S
*G*S
Output
2
Input
1 3
S*G
Output
-1
Submitted Solution:
```
import sys
import math
import collections
import bisect
def get_ints(): return map(int, sys.stdin.readline().strip().split())
def get_list(): return list(map(int, sys.stdin.readline().strip().split()))
def get_string(): return sys.stdin.readline().strip()
n,m=get_ints()
floor=[]
np=0
gap=0
ans=set()
for i in range(n):
row=list(get_string())
g=row.index("G")
s=row.index("S")
if g==m-1:
np+=1
else:
if g<s:
val=(s-g-1)
else:
val=m-2-g
ans.add(val)
if np>0:
print(-1)
else:
print(len(ans))
``` | instruction | 0 | 23,228 | 15 | 46,456 |
No | output | 1 | 23,228 | 15 | 46,457 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Inna likes sweets and a game called the "Candy Matrix". Today, she came up with the new game "Candy Matrix 2: Reload".
The field for the new game is a rectangle table of size n Γ m. Each line of the table contains one cell with a dwarf figurine, one cell with a candy, the other cells of the line are empty. The game lasts for several moves. During each move the player should choose all lines of the matrix where dwarf is not on the cell with candy and shout "Let's go!". After that, all the dwarves from the chosen lines start to simultaneously move to the right. During each second, each dwarf goes to the adjacent cell that is located to the right of its current cell. The movement continues until one of the following events occurs:
* some dwarf in one of the chosen lines is located in the rightmost cell of his row;
* some dwarf in the chosen lines is located in the cell with the candy.
The point of the game is to transport all the dwarves to the candy cells.
Inna is fabulous, as she came up with such an interesting game. But what about you? Your task is to play this game optimally well. Specifically, you should say by the given game field what minimum number of moves the player needs to reach the goal of the game.
Input
The first line of the input contains two integers n and m (1 β€ n β€ 1000; 2 β€ m β€ 1000).
Next n lines each contain m characters β the game field for the "Candy Martix 2: Reload". Character "*" represents an empty cell of the field, character "G" represents a dwarf and character "S" represents a candy. The matrix doesn't contain other characters. It is guaranteed that each line contains exactly one character "G" and one character "S".
Output
In a single line print a single integer β either the minimum number of moves needed to achieve the aim of the game, or -1, if the aim cannot be achieved on the given game field.
Examples
Input
3 4
*G*S
G**S
*G*S
Output
2
Input
1 3
S*G
Output
-1
Submitted Solution:
```
n,k = map(int,input().split())
chess = []
l = [0]*(n)
for i in range(n):
chess.append(input())
for i in range(n):
G = chess[i].index("G")
S = chess[i].index("S")
if S < G:
print(-1)
break
else:
l[i] = S - G
else:
print(max(l)-min(l)+1)
``` | instruction | 0 | 23,229 | 15 | 46,458 |
No | output | 1 | 23,229 | 15 | 46,459 |
Provide tags and a correct Python 3 solution for this coding contest problem.
It's a beautiful April day and Wallace is playing football with his friends. But his friends do not know that Wallace actually stayed home with Gromit and sent them his robotic self instead. Robo-Wallace has several advantages over the other guys. For example, he can hit the ball directly to the specified point. And yet, the notion of a giveaway is foreign to him. The combination of these features makes the Robo-Wallace the perfect footballer β as soon as the ball gets to him, he can just aim and hit the goal. He followed this tactics in the first half of the match, but he hit the goal rarely. The opposing team has a very good goalkeeper who catches most of the balls that fly directly into the goal. But Robo-Wallace is a quick thinker, he realized that he can cheat the goalkeeper. After all, they are playing in a football box with solid walls. Robo-Wallace can kick the ball to the other side, then the goalkeeper will not try to catch the ball. Then, if the ball bounces off the wall and flies into the goal, the goal will at last be scored.
Your task is to help Robo-Wallace to detect a spot on the wall of the football box, to which the robot should kick the ball, so that the ball bounces once and only once off this wall and goes straight to the goal. In the first half of the match Robo-Wallace got a ball in the head and was severely hit. As a result, some of the schemes have been damaged. Because of the damage, Robo-Wallace can only aim to his right wall (Robo-Wallace is standing with his face to the opposing team's goal).
The football box is rectangular. Let's introduce a two-dimensional coordinate system so that point (0, 0) lies in the lower left corner of the field, if you look at the box above. Robo-Wallace is playing for the team, whose goal is to the right. It is an improvised football field, so the gate of Robo-Wallace's rivals may be not in the middle of the left wall.
<image>
In the given coordinate system you are given:
* y1, y2 β the y-coordinates of the side pillars of the goalposts of robo-Wallace's opponents;
* yw β the y-coordinate of the wall to which Robo-Wallace is aiming;
* xb, yb β the coordinates of the ball's position when it is hit;
* r β the radius of the ball.
A goal is scored when the center of the ball crosses the OY axis in the given coordinate system between (0, y1) and (0, y2). The ball moves along a straight line. The ball's hit on the wall is perfectly elastic (the ball does not shrink from the hit), the angle of incidence equals the angle of reflection. If the ball bounces off the wall not to the goal, that is, if it hits the other wall or the goal post, then the opposing team catches the ball and Robo-Wallace starts looking for miscalculation and gets dysfunctional. Such an outcome, if possible, should be avoided. We assume that the ball touches an object, if the distance from the center of the ball to the object is no greater than the ball radius r.
Input
The first and the single line contains integers y1, y2, yw, xb, yb, r (1 β€ y1, y2, yw, xb, yb β€ 106; y1 < y2 < yw; yb + r < yw; 2Β·r < y2 - y1).
It is guaranteed that the ball is positioned correctly in the field, doesn't cross any wall, doesn't touch the wall that Robo-Wallace is aiming at. The goal posts can't be located in the field corners.
Output
If Robo-Wallace can't score a goal in the described manner, print "-1" (without the quotes). Otherwise, print a single number xw β the abscissa of his point of aiming.
If there are multiple points of aiming, print the abscissa of any of them. When checking the correctness of the answer, all comparisons are made with the permissible absolute error, equal to 10 - 8.
It is recommended to print as many characters after the decimal point as possible.
Examples
Input
4 10 13 10 3 1
Output
4.3750000000
Input
1 4 6 2 2 1
Output
-1
Input
3 10 15 17 9 2
Output
11.3333333333
Note
Note that in the first and third samples other correct values of abscissa xw are also possible. | instruction | 0 | 24,112 | 15 | 48,224 |
Tags: binary search, geometry
Correct Solution:
```
from math import atan, asin
y1, y2, yw, xb, yb, r = map(float, input().split())
x = xb * (yw - y1 - 2*r) / (2*yw - y1 - yb - 3*r)
alpha = atan(x / (yw - y1 - 2*r))
beta = asin(r / (y2 - y1 - r))
print ('-1' if alpha < beta else '{0:.10f}'.format(x))
``` | output | 1 | 24,112 | 15 | 48,225 |
Provide tags and a correct Python 3 solution for this coding contest problem.
It's a beautiful April day and Wallace is playing football with his friends. But his friends do not know that Wallace actually stayed home with Gromit and sent them his robotic self instead. Robo-Wallace has several advantages over the other guys. For example, he can hit the ball directly to the specified point. And yet, the notion of a giveaway is foreign to him. The combination of these features makes the Robo-Wallace the perfect footballer β as soon as the ball gets to him, he can just aim and hit the goal. He followed this tactics in the first half of the match, but he hit the goal rarely. The opposing team has a very good goalkeeper who catches most of the balls that fly directly into the goal. But Robo-Wallace is a quick thinker, he realized that he can cheat the goalkeeper. After all, they are playing in a football box with solid walls. Robo-Wallace can kick the ball to the other side, then the goalkeeper will not try to catch the ball. Then, if the ball bounces off the wall and flies into the goal, the goal will at last be scored.
Your task is to help Robo-Wallace to detect a spot on the wall of the football box, to which the robot should kick the ball, so that the ball bounces once and only once off this wall and goes straight to the goal. In the first half of the match Robo-Wallace got a ball in the head and was severely hit. As a result, some of the schemes have been damaged. Because of the damage, Robo-Wallace can only aim to his right wall (Robo-Wallace is standing with his face to the opposing team's goal).
The football box is rectangular. Let's introduce a two-dimensional coordinate system so that point (0, 0) lies in the lower left corner of the field, if you look at the box above. Robo-Wallace is playing for the team, whose goal is to the right. It is an improvised football field, so the gate of Robo-Wallace's rivals may be not in the middle of the left wall.
<image>
In the given coordinate system you are given:
* y1, y2 β the y-coordinates of the side pillars of the goalposts of robo-Wallace's opponents;
* yw β the y-coordinate of the wall to which Robo-Wallace is aiming;
* xb, yb β the coordinates of the ball's position when it is hit;
* r β the radius of the ball.
A goal is scored when the center of the ball crosses the OY axis in the given coordinate system between (0, y1) and (0, y2). The ball moves along a straight line. The ball's hit on the wall is perfectly elastic (the ball does not shrink from the hit), the angle of incidence equals the angle of reflection. If the ball bounces off the wall not to the goal, that is, if it hits the other wall or the goal post, then the opposing team catches the ball and Robo-Wallace starts looking for miscalculation and gets dysfunctional. Such an outcome, if possible, should be avoided. We assume that the ball touches an object, if the distance from the center of the ball to the object is no greater than the ball radius r.
Input
The first and the single line contains integers y1, y2, yw, xb, yb, r (1 β€ y1, y2, yw, xb, yb β€ 106; y1 < y2 < yw; yb + r < yw; 2Β·r < y2 - y1).
It is guaranteed that the ball is positioned correctly in the field, doesn't cross any wall, doesn't touch the wall that Robo-Wallace is aiming at. The goal posts can't be located in the field corners.
Output
If Robo-Wallace can't score a goal in the described manner, print "-1" (without the quotes). Otherwise, print a single number xw β the abscissa of his point of aiming.
If there are multiple points of aiming, print the abscissa of any of them. When checking the correctness of the answer, all comparisons are made with the permissible absolute error, equal to 10 - 8.
It is recommended to print as many characters after the decimal point as possible.
Examples
Input
4 10 13 10 3 1
Output
4.3750000000
Input
1 4 6 2 2 1
Output
-1
Input
3 10 15 17 9 2
Output
11.3333333333
Note
Note that in the first and third samples other correct values of abscissa xw are also possible. | instruction | 0 | 24,113 | 15 | 48,226 |
Tags: binary search, geometry
Correct Solution:
```
from math import hypot
y1, y2, yw, xb, yb, r = map(int, input().split())
yw -= r
y1, y2 = yw * 2 - y2, yw * 2 - y1
def xww(y):
return (y - yw) * xb / (y - yb)
def dd(y):
xw = xww(y)
return (y - y1) / hypot(1, (yw - y) / xw)
def binary_search():
a, b = y1 + r, 1e10
for i in range(200):
m = (a + b) / 2
if dd(m) < r:
a = m
else:
b= m
return (a + b) / 2
m = binary_search()
if m + r > y2:
print("-1")
else:
m = (m + y2 - r) / 2
print(xww(m))
``` | output | 1 | 24,113 | 15 | 48,227 |
Provide tags and a correct Python 3 solution for this coding contest problem.
It's a beautiful April day and Wallace is playing football with his friends. But his friends do not know that Wallace actually stayed home with Gromit and sent them his robotic self instead. Robo-Wallace has several advantages over the other guys. For example, he can hit the ball directly to the specified point. And yet, the notion of a giveaway is foreign to him. The combination of these features makes the Robo-Wallace the perfect footballer β as soon as the ball gets to him, he can just aim and hit the goal. He followed this tactics in the first half of the match, but he hit the goal rarely. The opposing team has a very good goalkeeper who catches most of the balls that fly directly into the goal. But Robo-Wallace is a quick thinker, he realized that he can cheat the goalkeeper. After all, they are playing in a football box with solid walls. Robo-Wallace can kick the ball to the other side, then the goalkeeper will not try to catch the ball. Then, if the ball bounces off the wall and flies into the goal, the goal will at last be scored.
Your task is to help Robo-Wallace to detect a spot on the wall of the football box, to which the robot should kick the ball, so that the ball bounces once and only once off this wall and goes straight to the goal. In the first half of the match Robo-Wallace got a ball in the head and was severely hit. As a result, some of the schemes have been damaged. Because of the damage, Robo-Wallace can only aim to his right wall (Robo-Wallace is standing with his face to the opposing team's goal).
The football box is rectangular. Let's introduce a two-dimensional coordinate system so that point (0, 0) lies in the lower left corner of the field, if you look at the box above. Robo-Wallace is playing for the team, whose goal is to the right. It is an improvised football field, so the gate of Robo-Wallace's rivals may be not in the middle of the left wall.
<image>
In the given coordinate system you are given:
* y1, y2 β the y-coordinates of the side pillars of the goalposts of robo-Wallace's opponents;
* yw β the y-coordinate of the wall to which Robo-Wallace is aiming;
* xb, yb β the coordinates of the ball's position when it is hit;
* r β the radius of the ball.
A goal is scored when the center of the ball crosses the OY axis in the given coordinate system between (0, y1) and (0, y2). The ball moves along a straight line. The ball's hit on the wall is perfectly elastic (the ball does not shrink from the hit), the angle of incidence equals the angle of reflection. If the ball bounces off the wall not to the goal, that is, if it hits the other wall or the goal post, then the opposing team catches the ball and Robo-Wallace starts looking for miscalculation and gets dysfunctional. Such an outcome, if possible, should be avoided. We assume that the ball touches an object, if the distance from the center of the ball to the object is no greater than the ball radius r.
Input
The first and the single line contains integers y1, y2, yw, xb, yb, r (1 β€ y1, y2, yw, xb, yb β€ 106; y1 < y2 < yw; yb + r < yw; 2Β·r < y2 - y1).
It is guaranteed that the ball is positioned correctly in the field, doesn't cross any wall, doesn't touch the wall that Robo-Wallace is aiming at. The goal posts can't be located in the field corners.
Output
If Robo-Wallace can't score a goal in the described manner, print "-1" (without the quotes). Otherwise, print a single number xw β the abscissa of his point of aiming.
If there are multiple points of aiming, print the abscissa of any of them. When checking the correctness of the answer, all comparisons are made with the permissible absolute error, equal to 10 - 8.
It is recommended to print as many characters after the decimal point as possible.
Examples
Input
4 10 13 10 3 1
Output
4.3750000000
Input
1 4 6 2 2 1
Output
-1
Input
3 10 15 17 9 2
Output
11.3333333333
Note
Note that in the first and third samples other correct values of abscissa xw are also possible. | instruction | 0 | 24,114 | 15 | 48,228 |
Tags: binary search, geometry
Correct Solution:
```
y1, y2, w, x, y, r = map(int, input().strip().split())
w -= r
y1 = 2 * w - y1 - y - r
y2 = 2 * w - y2 - y
if x * x * (y2 - y1) * (y2 - y1) <= (y1 * y1 + x * x) * r * r:
print(-1)
else:
print(f"{x * (y1 + y - w) / y1:.10f}")
``` | output | 1 | 24,114 | 15 | 48,229 |
Provide tags and a correct Python 3 solution for this coding contest problem.
One evening Rainbow Dash and Fluttershy have come up with a game. Since the ponies are friends, they have decided not to compete in the game but to pursue a common goal.
The game starts on a square flat grid, which initially has the outline borders built up. Rainbow Dash and Fluttershy have flat square blocks with size 1Γ1, Rainbow Dash has an infinite amount of light blue blocks, Fluttershy has an infinite amount of yellow blocks.
The blocks are placed according to the following rule: each newly placed block must touch the built on the previous turns figure by a side (note that the outline borders of the grid are built initially). At each turn, one pony can place any number of blocks of her color according to the game rules.
Rainbow and Fluttershy have found out that they can build patterns on the grid of the game that way. They have decided to start with something simple, so they made up their mind to place the blocks to form a chess coloring. Rainbow Dash is well-known for her speed, so she is interested in the minimum number of turns she and Fluttershy need to do to get a chess coloring, covering the whole grid with blocks. Please help her find that number!
Since the ponies can play many times on different boards, Rainbow Dash asks you to find the minimum numbers of turns for several grids of the games.
The chess coloring in two colors is the one in which each square is neighbor by side only with squares of different colors.
Input
The first line contains a single integer T (1 β€ T β€ 100): the number of grids of the games.
Each of the next T lines contains a single integer n (1 β€ n β€ 10^9): the size of the side of the grid of the game.
Output
For each grid of the game print the minimum number of turns required to build a chess coloring pattern out of blocks on it.
Example
Input
2
3
4
Output
2
3
Note
For 3Γ3 grid ponies can make two following moves: <image> | instruction | 0 | 24,952 | 15 | 49,904 |
Tags: greedy, math
Correct Solution:
```
for i in[*open(0)][1:]:print(int(i)//2+1)
``` | output | 1 | 24,952 | 15 | 49,905 |
Provide tags and a correct Python 3 solution for this coding contest problem.
One evening Rainbow Dash and Fluttershy have come up with a game. Since the ponies are friends, they have decided not to compete in the game but to pursue a common goal.
The game starts on a square flat grid, which initially has the outline borders built up. Rainbow Dash and Fluttershy have flat square blocks with size 1Γ1, Rainbow Dash has an infinite amount of light blue blocks, Fluttershy has an infinite amount of yellow blocks.
The blocks are placed according to the following rule: each newly placed block must touch the built on the previous turns figure by a side (note that the outline borders of the grid are built initially). At each turn, one pony can place any number of blocks of her color according to the game rules.
Rainbow and Fluttershy have found out that they can build patterns on the grid of the game that way. They have decided to start with something simple, so they made up their mind to place the blocks to form a chess coloring. Rainbow Dash is well-known for her speed, so she is interested in the minimum number of turns she and Fluttershy need to do to get a chess coloring, covering the whole grid with blocks. Please help her find that number!
Since the ponies can play many times on different boards, Rainbow Dash asks you to find the minimum numbers of turns for several grids of the games.
The chess coloring in two colors is the one in which each square is neighbor by side only with squares of different colors.
Input
The first line contains a single integer T (1 β€ T β€ 100): the number of grids of the games.
Each of the next T lines contains a single integer n (1 β€ n β€ 10^9): the size of the side of the grid of the game.
Output
For each grid of the game print the minimum number of turns required to build a chess coloring pattern out of blocks on it.
Example
Input
2
3
4
Output
2
3
Note
For 3Γ3 grid ponies can make two following moves: <image> | instruction | 0 | 24,953 | 15 | 49,906 |
Tags: greedy, math
Correct Solution:
```
import math
for _ in range(int(input())):
n = int(input())
if n == 1:
print(1)
elif n == 2 or n == 3:
print(2)
else:
print(math.ceil(n // 2) + 1)
``` | output | 1 | 24,953 | 15 | 49,907 |
Provide tags and a correct Python 3 solution for this coding contest problem.
One evening Rainbow Dash and Fluttershy have come up with a game. Since the ponies are friends, they have decided not to compete in the game but to pursue a common goal.
The game starts on a square flat grid, which initially has the outline borders built up. Rainbow Dash and Fluttershy have flat square blocks with size 1Γ1, Rainbow Dash has an infinite amount of light blue blocks, Fluttershy has an infinite amount of yellow blocks.
The blocks are placed according to the following rule: each newly placed block must touch the built on the previous turns figure by a side (note that the outline borders of the grid are built initially). At each turn, one pony can place any number of blocks of her color according to the game rules.
Rainbow and Fluttershy have found out that they can build patterns on the grid of the game that way. They have decided to start with something simple, so they made up their mind to place the blocks to form a chess coloring. Rainbow Dash is well-known for her speed, so she is interested in the minimum number of turns she and Fluttershy need to do to get a chess coloring, covering the whole grid with blocks. Please help her find that number!
Since the ponies can play many times on different boards, Rainbow Dash asks you to find the minimum numbers of turns for several grids of the games.
The chess coloring in two colors is the one in which each square is neighbor by side only with squares of different colors.
Input
The first line contains a single integer T (1 β€ T β€ 100): the number of grids of the games.
Each of the next T lines contains a single integer n (1 β€ n β€ 10^9): the size of the side of the grid of the game.
Output
For each grid of the game print the minimum number of turns required to build a chess coloring pattern out of blocks on it.
Example
Input
2
3
4
Output
2
3
Note
For 3Γ3 grid ponies can make two following moves: <image> | instruction | 0 | 24,954 | 15 | 49,908 |
Tags: greedy, math
Correct Solution:
```
import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
import copy
# import numpy as np
mod = int(pow(10, 9) + 7)
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(*var, end="\n"): sys.stdout.write(' '.join(map(str, var))+end)
def L(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]
try:
# sys.setrecursionlimit(int(pow(10,6)))
sys.stdin = open("input.txt", "r")
sys.stdout = open("../output.txt", "w")
except:
pass
for _ in range(L()[0]):
n=L()[0]
print(n//2+1)
``` | output | 1 | 24,954 | 15 | 49,909 |
Provide tags and a correct Python 3 solution for this coding contest problem.
One evening Rainbow Dash and Fluttershy have come up with a game. Since the ponies are friends, they have decided not to compete in the game but to pursue a common goal.
The game starts on a square flat grid, which initially has the outline borders built up. Rainbow Dash and Fluttershy have flat square blocks with size 1Γ1, Rainbow Dash has an infinite amount of light blue blocks, Fluttershy has an infinite amount of yellow blocks.
The blocks are placed according to the following rule: each newly placed block must touch the built on the previous turns figure by a side (note that the outline borders of the grid are built initially). At each turn, one pony can place any number of blocks of her color according to the game rules.
Rainbow and Fluttershy have found out that they can build patterns on the grid of the game that way. They have decided to start with something simple, so they made up their mind to place the blocks to form a chess coloring. Rainbow Dash is well-known for her speed, so she is interested in the minimum number of turns she and Fluttershy need to do to get a chess coloring, covering the whole grid with blocks. Please help her find that number!
Since the ponies can play many times on different boards, Rainbow Dash asks you to find the minimum numbers of turns for several grids of the games.
The chess coloring in two colors is the one in which each square is neighbor by side only with squares of different colors.
Input
The first line contains a single integer T (1 β€ T β€ 100): the number of grids of the games.
Each of the next T lines contains a single integer n (1 β€ n β€ 10^9): the size of the side of the grid of the game.
Output
For each grid of the game print the minimum number of turns required to build a chess coloring pattern out of blocks on it.
Example
Input
2
3
4
Output
2
3
Note
For 3Γ3 grid ponies can make two following moves: <image> | instruction | 0 | 24,955 | 15 | 49,910 |
Tags: greedy, math
Correct Solution:
```
n = int(input())
for i in range(n):
num = int(input())
print((num//2)+1)
``` | output | 1 | 24,955 | 15 | 49,911 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.