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 |
|---|---|---|---|---|---|
Provide tags and a correct Python 3 solution for this coding contest problem.
In this task Anna and Maria play a game with a very unpleasant rival. Anna and Maria are in the opposite squares of a chessboard (8 Γ 8): Anna is in the upper right corner, and Maria is in the lower left one. Apart from them, the board has several statues. Each statue occupies exactly one square. A square that contains a statue cannot have anything or anyone β neither any other statues, nor Anna, nor Maria.
Anna is present on the board as a figurant (she stands still and never moves), and Maria has been actively involved in the game. Her goal is β to come to Anna's square. Maria and statues move in turn, Maria moves first. During one move Maria can go to any adjacent on the side or diagonal cell in which there is no statue, or she can stay in the cell where she is. The statues during their move must go one square down simultaneously, and those statues that were in the bottom row fall from the board and are no longer appeared.
At that moment, when one of the statues is in the cell in which the Maria is, the statues are declared winners. At the moment when Maria comes into the cell where Anna has been waiting, Maria is declared the winner.
Obviously, nothing depends on the statues, so it all depends on Maria. Determine who will win, if Maria does not make a strategic error.
Input
You are given the 8 strings whose length equals 8, describing the initial position on the board. The first line represents the top row of the board, the next one β for the second from the top, and so on, the last line represents the bottom row. Each character string matches a single cell board in the appropriate row, and the characters are in the same manner as that of the corresponding cell. If the cell is empty, the corresponding character is ".". If a cell has Maria, then it is represented by character "M". If a cell has Anna, it is represented by the character "A". If a cell has a statue, then the cell is represented by character "S".
It is guaranteed that the last character of the first row is always "A", the first character of the last line is always "M". The remaining characters are "." or "S".
Output
If Maria wins, print string "WIN". If the statues win, print string "LOSE".
Examples
Input
.......A
........
........
........
........
........
........
M.......
Output
WIN
Input
.......A
........
........
........
........
........
SS......
M.......
Output
LOSE
Input
.......A
........
........
........
........
.S......
S.......
MS......
Output
LOSE | instruction | 0 | 102,146 | 15 | 204,292 |
Tags: dfs and similar
Correct Solution:
```
r, s = [63], ''.join(input() + 'T' for i in range(8)) + 'T' * 9
for i in range(0, 72, 9):
t = set()
for x in r:
for y in (x, x - 1, x + 1, x - 9, x + 9, x - 10, x - 8, x + 10, x + 8):
if s[y] == 'T': continue
if (y < i or s[y - i] != 'S') and (y < i + 9 or s[y - i - 9] != 'S'): t.add(y)
r = t
print('WIN' if r else 'LOSE')
``` | output | 1 | 102,146 | 15 | 204,293 |
Provide tags and a correct Python 3 solution for this coding contest problem.
In this task Anna and Maria play a game with a very unpleasant rival. Anna and Maria are in the opposite squares of a chessboard (8 Γ 8): Anna is in the upper right corner, and Maria is in the lower left one. Apart from them, the board has several statues. Each statue occupies exactly one square. A square that contains a statue cannot have anything or anyone β neither any other statues, nor Anna, nor Maria.
Anna is present on the board as a figurant (she stands still and never moves), and Maria has been actively involved in the game. Her goal is β to come to Anna's square. Maria and statues move in turn, Maria moves first. During one move Maria can go to any adjacent on the side or diagonal cell in which there is no statue, or she can stay in the cell where she is. The statues during their move must go one square down simultaneously, and those statues that were in the bottom row fall from the board and are no longer appeared.
At that moment, when one of the statues is in the cell in which the Maria is, the statues are declared winners. At the moment when Maria comes into the cell where Anna has been waiting, Maria is declared the winner.
Obviously, nothing depends on the statues, so it all depends on Maria. Determine who will win, if Maria does not make a strategic error.
Input
You are given the 8 strings whose length equals 8, describing the initial position on the board. The first line represents the top row of the board, the next one β for the second from the top, and so on, the last line represents the bottom row. Each character string matches a single cell board in the appropriate row, and the characters are in the same manner as that of the corresponding cell. If the cell is empty, the corresponding character is ".". If a cell has Maria, then it is represented by character "M". If a cell has Anna, it is represented by the character "A". If a cell has a statue, then the cell is represented by character "S".
It is guaranteed that the last character of the first row is always "A", the first character of the last line is always "M". The remaining characters are "." or "S".
Output
If Maria wins, print string "WIN". If the statues win, print string "LOSE".
Examples
Input
.......A
........
........
........
........
........
........
M.......
Output
WIN
Input
.......A
........
........
........
........
........
SS......
M.......
Output
LOSE
Input
.......A
........
........
........
........
.S......
S.......
MS......
Output
LOSE | instruction | 0 | 102,147 | 15 | 204,294 |
Tags: dfs and similar
Correct Solution:
```
def play(b, x, y, c):
if c == 9:
return True
if b[c][y][x] == 'S':
return False
dx = [-1, 1, 0, 0, 0, 1, 1, -1, -1]
dy = [0, 0, -1, 1, 0, -1, 1, -1, 1]
for i in range(len(dx)):
nx = x + dx[i]
ny = y + dy[i]
if min(nx, ny) < 0 or max(nx, ny) >= 8: continue
if b[c][ny][nx] != 'S' and play(b, nx, ny, c+1):
return True
return False
board = []
for x in range(8):
board.append(input().strip())
B = [board]
for x in range(10):
b = B[-1]
b_ = b[:]
b_[0] = b_[0][:-1] + '.'
b_.insert(0, ".......A")
B.append(b_[:-1])
if play(B, 0, 7, 0):
print("WIN")
else:
print("LOSE")
``` | output | 1 | 102,147 | 15 | 204,295 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In this task Anna and Maria play a game with a very unpleasant rival. Anna and Maria are in the opposite squares of a chessboard (8 Γ 8): Anna is in the upper right corner, and Maria is in the lower left one. Apart from them, the board has several statues. Each statue occupies exactly one square. A square that contains a statue cannot have anything or anyone β neither any other statues, nor Anna, nor Maria.
Anna is present on the board as a figurant (she stands still and never moves), and Maria has been actively involved in the game. Her goal is β to come to Anna's square. Maria and statues move in turn, Maria moves first. During one move Maria can go to any adjacent on the side or diagonal cell in which there is no statue, or she can stay in the cell where she is. The statues during their move must go one square down simultaneously, and those statues that were in the bottom row fall from the board and are no longer appeared.
At that moment, when one of the statues is in the cell in which the Maria is, the statues are declared winners. At the moment when Maria comes into the cell where Anna has been waiting, Maria is declared the winner.
Obviously, nothing depends on the statues, so it all depends on Maria. Determine who will win, if Maria does not make a strategic error.
Input
You are given the 8 strings whose length equals 8, describing the initial position on the board. The first line represents the top row of the board, the next one β for the second from the top, and so on, the last line represents the bottom row. Each character string matches a single cell board in the appropriate row, and the characters are in the same manner as that of the corresponding cell. If the cell is empty, the corresponding character is ".". If a cell has Maria, then it is represented by character "M". If a cell has Anna, it is represented by the character "A". If a cell has a statue, then the cell is represented by character "S".
It is guaranteed that the last character of the first row is always "A", the first character of the last line is always "M". The remaining characters are "." or "S".
Output
If Maria wins, print string "WIN". If the statues win, print string "LOSE".
Examples
Input
.......A
........
........
........
........
........
........
M.......
Output
WIN
Input
.......A
........
........
........
........
........
SS......
M.......
Output
LOSE
Input
.......A
........
........
........
........
.S......
S.......
MS......
Output
LOSE
Submitted Solution:
```
def bad(x, y, t):
x1, y1 = x, y + t
return 0 <= 8 - y1 < 8 and 0 <= x1 < 8 and a[8 - y1][x1] == "S" or 0 <= 7 - y1 < 8 and 0 <= x1 < 8 and a[7 - y1][x1] == "S"
dp = [[[False] * 30 for i in range(8)] for j in range(8)]
a = []
for i in range(8):
a.append(input().rstrip())
dp[0][0][0] = True
for t1 in range(29):
for x in range(8):
for y in range(8):
if dp[x][y][t1]:
for i in [(x + 1, y), (x - 1, y), (x + 1, y + 1), (x - 1, y + 1), (x + 1, y - 1), (x - 1, y - 1), (x, y + 1), (x, y - 1), (x, y)]:
if 0 <= i[0] < 8 and 0 <= i[1] < 8:
if not bad(i[0], i[1], t1 + 1):
dp[i[0]][i[1]][t1 + 1] = True
for i in range(30):
if dp[7][7][i]:
print("WIN")
exit()
print("LOSE")
``` | instruction | 0 | 102,148 | 15 | 204,296 |
Yes | output | 1 | 102,148 | 15 | 204,297 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In this task Anna and Maria play a game with a very unpleasant rival. Anna and Maria are in the opposite squares of a chessboard (8 Γ 8): Anna is in the upper right corner, and Maria is in the lower left one. Apart from them, the board has several statues. Each statue occupies exactly one square. A square that contains a statue cannot have anything or anyone β neither any other statues, nor Anna, nor Maria.
Anna is present on the board as a figurant (she stands still and never moves), and Maria has been actively involved in the game. Her goal is β to come to Anna's square. Maria and statues move in turn, Maria moves first. During one move Maria can go to any adjacent on the side or diagonal cell in which there is no statue, or she can stay in the cell where she is. The statues during their move must go one square down simultaneously, and those statues that were in the bottom row fall from the board and are no longer appeared.
At that moment, when one of the statues is in the cell in which the Maria is, the statues are declared winners. At the moment when Maria comes into the cell where Anna has been waiting, Maria is declared the winner.
Obviously, nothing depends on the statues, so it all depends on Maria. Determine who will win, if Maria does not make a strategic error.
Input
You are given the 8 strings whose length equals 8, describing the initial position on the board. The first line represents the top row of the board, the next one β for the second from the top, and so on, the last line represents the bottom row. Each character string matches a single cell board in the appropriate row, and the characters are in the same manner as that of the corresponding cell. If the cell is empty, the corresponding character is ".". If a cell has Maria, then it is represented by character "M". If a cell has Anna, it is represented by the character "A". If a cell has a statue, then the cell is represented by character "S".
It is guaranteed that the last character of the first row is always "A", the first character of the last line is always "M". The remaining characters are "." or "S".
Output
If Maria wins, print string "WIN". If the statues win, print string "LOSE".
Examples
Input
.......A
........
........
........
........
........
........
M.......
Output
WIN
Input
.......A
........
........
........
........
........
SS......
M.......
Output
LOSE
Input
.......A
........
........
........
........
.S......
S.......
MS......
Output
LOSE
Submitted Solution:
```
grid = [ list(input().strip()) for r in range(8) ]
grid[0][7] = '.'
grid[7][0] = '.'
mark = [ [ False for c in range(8) ] for r in range(8) ]
mark[7][0] = True
def display_grid():
print('\n'.join(map(lambda row: ''.join(row), grid)))
print()
def display_mark():
for row in mark:
row = map(lambda a: 'X' if a else '_', row)
print(''.join(row))
print()
for i in range(8):
moved = False
new_mark = [ [ False for c in range(8) ] for r in range(8) ]
for r in range(8):
for c in range(8):
if not mark[r][c]:
continue
for R in range(max(0, r - 1), min(r + 2, 8)):
for C in range(max(0, c - 1), min(c + 2, 8)):
if grid[R][C] == 'S':
continue
if R - 1 >= 0 and grid[R - 1][C] == 'S':
continue
new_mark[R][C] = True
moved = True
mark = new_mark
grid.insert(0, 8 * [ '.' ])
grid.pop()
if not moved:
break
if moved:
print('WIN')
else:
print('LOSE')
``` | instruction | 0 | 102,149 | 15 | 204,298 |
Yes | output | 1 | 102,149 | 15 | 204,299 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In this task Anna and Maria play a game with a very unpleasant rival. Anna and Maria are in the opposite squares of a chessboard (8 Γ 8): Anna is in the upper right corner, and Maria is in the lower left one. Apart from them, the board has several statues. Each statue occupies exactly one square. A square that contains a statue cannot have anything or anyone β neither any other statues, nor Anna, nor Maria.
Anna is present on the board as a figurant (she stands still and never moves), and Maria has been actively involved in the game. Her goal is β to come to Anna's square. Maria and statues move in turn, Maria moves first. During one move Maria can go to any adjacent on the side or diagonal cell in which there is no statue, or she can stay in the cell where she is. The statues during their move must go one square down simultaneously, and those statues that were in the bottom row fall from the board and are no longer appeared.
At that moment, when one of the statues is in the cell in which the Maria is, the statues are declared winners. At the moment when Maria comes into the cell where Anna has been waiting, Maria is declared the winner.
Obviously, nothing depends on the statues, so it all depends on Maria. Determine who will win, if Maria does not make a strategic error.
Input
You are given the 8 strings whose length equals 8, describing the initial position on the board. The first line represents the top row of the board, the next one β for the second from the top, and so on, the last line represents the bottom row. Each character string matches a single cell board in the appropriate row, and the characters are in the same manner as that of the corresponding cell. If the cell is empty, the corresponding character is ".". If a cell has Maria, then it is represented by character "M". If a cell has Anna, it is represented by the character "A". If a cell has a statue, then the cell is represented by character "S".
It is guaranteed that the last character of the first row is always "A", the first character of the last line is always "M". The remaining characters are "." or "S".
Output
If Maria wins, print string "WIN". If the statues win, print string "LOSE".
Examples
Input
.......A
........
........
........
........
........
........
M.......
Output
WIN
Input
.......A
........
........
........
........
........
SS......
M.......
Output
LOSE
Input
.......A
........
........
........
........
.S......
S.......
MS......
Output
LOSE
Submitted Solution:
```
d=[[1,0],[-1,0],[0,1],[0,-1],[1,1],[1,-1],[-1,1],[-1,-1],[0,0]]
l=[]
for i in range(8):
l.append(input())
#print("l is",l)
statues=[]
statues.append([])
for i in range(8):
for j in range(8):
#print(l[i][j],l[i][j]=='S')
if l[i][j]=="S":
statues[0].append(tuple([i,j]))
for i in range(1,8):
statues.append([])
for statue in statues[0]:
statues[i].append(tuple([statue[0]+i,statue[1]]))
#print(statues[0])
def possible(move_no,pos):
global d
global statues
if move_no>7 or (pos[0]==0 and pos[1]==7):
#print(move_no, pos[0],pos[1])
return(True)
b=False
for di in d:
pos[0]+=di[0]
pos[1]+=di[1]
if pos[0]>-1 and pos[0]<8 and pos[1]>-1 and pos[1]<8 and tuple(pos) not in statues[move_no] and tuple([pos[0]-1,pos[1]]) not in statues[move_no]:
#print(pos)
if(possible(move_no+1,pos)):
b=True
break
pos[0]-=di[0]
pos[1]-=di[1]
return(b)
if(possible(0,[7,0])):
print("WIN")
else:
print("LOSE")
``` | instruction | 0 | 102,150 | 15 | 204,300 |
Yes | output | 1 | 102,150 | 15 | 204,301 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In this task Anna and Maria play a game with a very unpleasant rival. Anna and Maria are in the opposite squares of a chessboard (8 Γ 8): Anna is in the upper right corner, and Maria is in the lower left one. Apart from them, the board has several statues. Each statue occupies exactly one square. A square that contains a statue cannot have anything or anyone β neither any other statues, nor Anna, nor Maria.
Anna is present on the board as a figurant (she stands still and never moves), and Maria has been actively involved in the game. Her goal is β to come to Anna's square. Maria and statues move in turn, Maria moves first. During one move Maria can go to any adjacent on the side or diagonal cell in which there is no statue, or she can stay in the cell where she is. The statues during their move must go one square down simultaneously, and those statues that were in the bottom row fall from the board and are no longer appeared.
At that moment, when one of the statues is in the cell in which the Maria is, the statues are declared winners. At the moment when Maria comes into the cell where Anna has been waiting, Maria is declared the winner.
Obviously, nothing depends on the statues, so it all depends on Maria. Determine who will win, if Maria does not make a strategic error.
Input
You are given the 8 strings whose length equals 8, describing the initial position on the board. The first line represents the top row of the board, the next one β for the second from the top, and so on, the last line represents the bottom row. Each character string matches a single cell board in the appropriate row, and the characters are in the same manner as that of the corresponding cell. If the cell is empty, the corresponding character is ".". If a cell has Maria, then it is represented by character "M". If a cell has Anna, it is represented by the character "A". If a cell has a statue, then the cell is represented by character "S".
It is guaranteed that the last character of the first row is always "A", the first character of the last line is always "M". The remaining characters are "." or "S".
Output
If Maria wins, print string "WIN". If the statues win, print string "LOSE".
Examples
Input
.......A
........
........
........
........
........
........
M.......
Output
WIN
Input
.......A
........
........
........
........
........
SS......
M.......
Output
LOSE
Input
.......A
........
........
........
........
.S......
S.......
MS......
Output
LOSE
Submitted Solution:
```
from typing import List, Tuple
def is_row_clear(board: List[str], time: int, x: int, y: int) -> bool:
if all(row[y] != 'S' for row in board):
return True
first_statue_index = [row[y] for row in board].index('S')
if first_statue_index + time > x:
return True
else:
return False
def moves(x: int, y: int) -> List[Tuple[int, int]]:
adj = [(x - 1, y - 1), (x - 1, y), (x - 1, y + 1), (x, y - 1), (x, y + 1),
(x + 1, y - 1), (x + 1, y), (x + 1, y + 1), (x, y)]
return [(xo, yo) for xo, yo in adj if 0 <= xo < 8 and 0 <= yo < 8]
def solve(board: List[str]) -> str:
stack = [(0, idx, idy) for idx, line in enumerate(board)
for idy, sq in enumerate(line) if board[idx][idy] == 'M']
while stack:
time, idx, idy = stack.pop()
if is_row_clear(board, time, idx, idy) or idx == 0:
return 'WIN'
for xo, yo in moves(idx, idy):
if (
board[xo - time][yo] != 'S' and
board[xo - 1 - time][yo] != 'S'
):
stack.append((time + 1, xo, yo))
return 'LOSE'
board = [input() for _ in range(8)]
print(solve(board))
``` | instruction | 0 | 102,151 | 15 | 204,302 |
Yes | output | 1 | 102,151 | 15 | 204,303 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In this task Anna and Maria play a game with a very unpleasant rival. Anna and Maria are in the opposite squares of a chessboard (8 Γ 8): Anna is in the upper right corner, and Maria is in the lower left one. Apart from them, the board has several statues. Each statue occupies exactly one square. A square that contains a statue cannot have anything or anyone β neither any other statues, nor Anna, nor Maria.
Anna is present on the board as a figurant (she stands still and never moves), and Maria has been actively involved in the game. Her goal is β to come to Anna's square. Maria and statues move in turn, Maria moves first. During one move Maria can go to any adjacent on the side or diagonal cell in which there is no statue, or she can stay in the cell where she is. The statues during their move must go one square down simultaneously, and those statues that were in the bottom row fall from the board and are no longer appeared.
At that moment, when one of the statues is in the cell in which the Maria is, the statues are declared winners. At the moment when Maria comes into the cell where Anna has been waiting, Maria is declared the winner.
Obviously, nothing depends on the statues, so it all depends on Maria. Determine who will win, if Maria does not make a strategic error.
Input
You are given the 8 strings whose length equals 8, describing the initial position on the board. The first line represents the top row of the board, the next one β for the second from the top, and so on, the last line represents the bottom row. Each character string matches a single cell board in the appropriate row, and the characters are in the same manner as that of the corresponding cell. If the cell is empty, the corresponding character is ".". If a cell has Maria, then it is represented by character "M". If a cell has Anna, it is represented by the character "A". If a cell has a statue, then the cell is represented by character "S".
It is guaranteed that the last character of the first row is always "A", the first character of the last line is always "M". The remaining characters are "." or "S".
Output
If Maria wins, print string "WIN". If the statues win, print string "LOSE".
Examples
Input
.......A
........
........
........
........
........
........
M.......
Output
WIN
Input
.......A
........
........
........
........
........
SS......
M.......
Output
LOSE
Input
.......A
........
........
........
........
.S......
S.......
MS......
Output
LOSE
Submitted Solution:
```
a=[]
for i in range(8):
s=input()
if s.count('S')>0:
a.append(1)
else:
a.append(0)
a=str(a)
if a.count('1')>0:
if a.find('1')>5:
print('LOSE')
else:
print('WIN')
else:
print('Win')
``` | instruction | 0 | 102,152 | 15 | 204,304 |
No | output | 1 | 102,152 | 15 | 204,305 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In this task Anna and Maria play a game with a very unpleasant rival. Anna and Maria are in the opposite squares of a chessboard (8 Γ 8): Anna is in the upper right corner, and Maria is in the lower left one. Apart from them, the board has several statues. Each statue occupies exactly one square. A square that contains a statue cannot have anything or anyone β neither any other statues, nor Anna, nor Maria.
Anna is present on the board as a figurant (she stands still and never moves), and Maria has been actively involved in the game. Her goal is β to come to Anna's square. Maria and statues move in turn, Maria moves first. During one move Maria can go to any adjacent on the side or diagonal cell in which there is no statue, or she can stay in the cell where she is. The statues during their move must go one square down simultaneously, and those statues that were in the bottom row fall from the board and are no longer appeared.
At that moment, when one of the statues is in the cell in which the Maria is, the statues are declared winners. At the moment when Maria comes into the cell where Anna has been waiting, Maria is declared the winner.
Obviously, nothing depends on the statues, so it all depends on Maria. Determine who will win, if Maria does not make a strategic error.
Input
You are given the 8 strings whose length equals 8, describing the initial position on the board. The first line represents the top row of the board, the next one β for the second from the top, and so on, the last line represents the bottom row. Each character string matches a single cell board in the appropriate row, and the characters are in the same manner as that of the corresponding cell. If the cell is empty, the corresponding character is ".". If a cell has Maria, then it is represented by character "M". If a cell has Anna, it is represented by the character "A". If a cell has a statue, then the cell is represented by character "S".
It is guaranteed that the last character of the first row is always "A", the first character of the last line is always "M". The remaining characters are "." or "S".
Output
If Maria wins, print string "WIN". If the statues win, print string "LOSE".
Examples
Input
.......A
........
........
........
........
........
........
M.......
Output
WIN
Input
.......A
........
........
........
........
........
SS......
M.......
Output
LOSE
Input
.......A
........
........
........
........
.S......
S.......
MS......
Output
LOSE
Submitted Solution:
```
grid = []
for _ in range(8):
grid.append(list(input()))
row = -1
for i in range(8):
if grid[i][0] == 'S':row = i
if row == -1:
print('WIN')
elif row == 0:
if grid[6][1] != 'S' and grid[4][2] != 'S' and grid[2][3] != 'S' and grid[0][4]:
print('WIN')
else: print('LOSE')
else:
print('LOSE')
``` | instruction | 0 | 102,153 | 15 | 204,306 |
No | output | 1 | 102,153 | 15 | 204,307 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In this task Anna and Maria play a game with a very unpleasant rival. Anna and Maria are in the opposite squares of a chessboard (8 Γ 8): Anna is in the upper right corner, and Maria is in the lower left one. Apart from them, the board has several statues. Each statue occupies exactly one square. A square that contains a statue cannot have anything or anyone β neither any other statues, nor Anna, nor Maria.
Anna is present on the board as a figurant (she stands still and never moves), and Maria has been actively involved in the game. Her goal is β to come to Anna's square. Maria and statues move in turn, Maria moves first. During one move Maria can go to any adjacent on the side or diagonal cell in which there is no statue, or she can stay in the cell where she is. The statues during their move must go one square down simultaneously, and those statues that were in the bottom row fall from the board and are no longer appeared.
At that moment, when one of the statues is in the cell in which the Maria is, the statues are declared winners. At the moment when Maria comes into the cell where Anna has been waiting, Maria is declared the winner.
Obviously, nothing depends on the statues, so it all depends on Maria. Determine who will win, if Maria does not make a strategic error.
Input
You are given the 8 strings whose length equals 8, describing the initial position on the board. The first line represents the top row of the board, the next one β for the second from the top, and so on, the last line represents the bottom row. Each character string matches a single cell board in the appropriate row, and the characters are in the same manner as that of the corresponding cell. If the cell is empty, the corresponding character is ".". If a cell has Maria, then it is represented by character "M". If a cell has Anna, it is represented by the character "A". If a cell has a statue, then the cell is represented by character "S".
It is guaranteed that the last character of the first row is always "A", the first character of the last line is always "M". The remaining characters are "." or "S".
Output
If Maria wins, print string "WIN". If the statues win, print string "LOSE".
Examples
Input
.......A
........
........
........
........
........
........
M.......
Output
WIN
Input
.......A
........
........
........
........
........
SS......
M.......
Output
LOSE
Input
.......A
........
........
........
........
.S......
S.......
MS......
Output
LOSE
Submitted Solution:
```
r, s = [63], ''.join(input() + 'S' for i in range(8)) + 'S' * 9
for i in range(0, 72, 9):
t = set()
for x in r:
for y in (x - 1, x + 1, x - 9, x + 9, x - 10, x - 8, x + 10, x + 8):
if s[y] == 'S': continue
if (y < i or s[y - i] != 'S') and (y < i + 9 or s[y - i - 9] != 'S'): t.add(y)
r = t
print('WIN' if r else 'LOSE')
``` | instruction | 0 | 102,154 | 15 | 204,308 |
No | output | 1 | 102,154 | 15 | 204,309 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In this task Anna and Maria play a game with a very unpleasant rival. Anna and Maria are in the opposite squares of a chessboard (8 Γ 8): Anna is in the upper right corner, and Maria is in the lower left one. Apart from them, the board has several statues. Each statue occupies exactly one square. A square that contains a statue cannot have anything or anyone β neither any other statues, nor Anna, nor Maria.
Anna is present on the board as a figurant (she stands still and never moves), and Maria has been actively involved in the game. Her goal is β to come to Anna's square. Maria and statues move in turn, Maria moves first. During one move Maria can go to any adjacent on the side or diagonal cell in which there is no statue, or she can stay in the cell where she is. The statues during their move must go one square down simultaneously, and those statues that were in the bottom row fall from the board and are no longer appeared.
At that moment, when one of the statues is in the cell in which the Maria is, the statues are declared winners. At the moment when Maria comes into the cell where Anna has been waiting, Maria is declared the winner.
Obviously, nothing depends on the statues, so it all depends on Maria. Determine who will win, if Maria does not make a strategic error.
Input
You are given the 8 strings whose length equals 8, describing the initial position on the board. The first line represents the top row of the board, the next one β for the second from the top, and so on, the last line represents the bottom row. Each character string matches a single cell board in the appropriate row, and the characters are in the same manner as that of the corresponding cell. If the cell is empty, the corresponding character is ".". If a cell has Maria, then it is represented by character "M". If a cell has Anna, it is represented by the character "A". If a cell has a statue, then the cell is represented by character "S".
It is guaranteed that the last character of the first row is always "A", the first character of the last line is always "M". The remaining characters are "." or "S".
Output
If Maria wins, print string "WIN". If the statues win, print string "LOSE".
Examples
Input
.......A
........
........
........
........
........
........
M.......
Output
WIN
Input
.......A
........
........
........
........
........
SS......
M.......
Output
LOSE
Input
.......A
........
........
........
........
.S......
S.......
MS......
Output
LOSE
Submitted Solution:
```
from itertools import product
from queue import Queue
BOARD_SIZE = 10
OCC_OR_VISITED, EMPTY = 1, 0
board = [input() for _ in range(8)]
graph = []
for _ in range(BOARD_SIZE):
graph += [[[EMPTY for _ in range(BOARD_SIZE)] for _ in range(BOARD_SIZE)]]
for i, j in product(range(8), repeat = 2):
if board[i][j] == 'S':
graph[0][i + 1][j + 1] = OCC_OR_VISITED
for i in range(BOARD_SIZE):
graph[0][i][0] = OCC_OR_VISITED
graph[0][i][BOARD_SIZE - 1] = OCC_OR_VISITED
graph[0][0][i] = OCC_OR_VISITED
graph[0][BOARD_SIZE - 1][i] = OCC_OR_VISITED
for time in range(1, BOARD_SIZE):
for i, j in product(range(2, 9), range(1, 9)):
graph[time][i][j] = graph[time - 1][i - 1][j]
for i in range(BOARD_SIZE):
graph[time][i][0] = OCC_OR_VISITED
graph[time][i][BOARD_SIZE - 1] = OCC_OR_VISITED
graph[time][0][i] = OCC_OR_VISITED
graph[time][BOARD_SIZE - 1][i] = OCC_OR_VISITED
Q = Queue()
Q.put((0, 8, 1))
pos_moves = [
[-1, -1],
[-1, 0],
[-1, 1],
[0, -1],
[0, 0],
[0, 1],
[1, -1],
[1, 0],
[1, 1]
]
while not Q.empty():
time, i, j = Q.get()
if time < BOARD_SIZE - 1:
for d in pos_moves:
if graph[time][i + d[0]][j + d[1]] == EMPTY and \
graph[time + 1][i + d[0]][j + d[1]] == EMPTY:
graph[time + 1][i + d[0]][j + d[1]] = OCC_OR_VISITED
Q.put((time + 1, i + d[0], j + d[1]))
any_pos = False
for i, j in product(range(1, 9), repeat = 2):
if graph[BOARD_SIZE - 1][i][j] == OCC_OR_VISITED:
any_pos = True
if any_pos:
print("WIN")
else:
print("LOSE")
``` | instruction | 0 | 102,155 | 15 | 204,310 |
No | output | 1 | 102,155 | 15 | 204,311 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Boboniu likes playing chess with his employees. As we know, no employee can beat the boss in the chess game, so Boboniu has never lost in any round.
You are a new applicant for his company. Boboniu will test you with the following chess question:
Consider a nΓ m grid (rows are numbered from 1 to n, and columns are numbered from 1 to m). You have a chess piece, and it stands at some cell (S_x,S_y) which is not on the border (i.e. 2 β€ S_x β€ n-1 and 2 β€ S_y β€ m-1).
From the cell (x,y), you can move your chess piece to (x,y') (1β€ y'β€ m, y' β y) or (x',y) (1β€ x'β€ n, x'β x). In other words, the chess piece moves as a rook. From the cell, you can move to any cell on the same row or column.
Your goal is to visit each cell exactly once. Can you find a solution?
Note that cells on the path between two adjacent cells in your route are not counted as visited, and it is not required to return to the starting point.
Input
The only line of the input contains four integers n, m, S_x and S_y (3β€ n,mβ€ 100, 2 β€ S_x β€ n-1, 2 β€ S_y β€ m-1) β the number of rows, the number of columns, and the initial position of your chess piece, respectively.
Output
You should print nβ
m lines.
The i-th line should contain two integers x_i and y_i (1 β€ x_i β€ n, 1 β€ y_i β€ m), denoting the i-th cell that you visited. You should print exactly nm pairs (x_i, y_i), they should cover all possible pairs (x_i, y_i), such that 1 β€ x_i β€ n, 1 β€ y_i β€ m.
We can show that under these constraints there always exists a solution. If there are multiple answers, print any.
Examples
Input
3 3 2 2
Output
2 2
1 2
1 3
2 3
3 3
3 2
3 1
2 1
1 1
Input
3 4 2 2
Output
2 2
2 1
2 3
2 4
1 4
3 4
3 3
3 2
3 1
1 1
1 2
1 3
Note
Possible routes for two examples:
<image> | instruction | 0 | 102,205 | 15 | 204,410 |
Tags: constructive algorithms
Correct Solution:
```
n,m,x,y = map(int, [*open(0)][0].split())
x, y = x-1, y-1
for i in range(n):
print(x+1 ,y+1)
for j in range(m-1):
y = (y + 1)%m
print(x+1, y+1)
x = (x + 1)%n
``` | output | 1 | 102,205 | 15 | 204,411 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Boboniu likes playing chess with his employees. As we know, no employee can beat the boss in the chess game, so Boboniu has never lost in any round.
You are a new applicant for his company. Boboniu will test you with the following chess question:
Consider a nΓ m grid (rows are numbered from 1 to n, and columns are numbered from 1 to m). You have a chess piece, and it stands at some cell (S_x,S_y) which is not on the border (i.e. 2 β€ S_x β€ n-1 and 2 β€ S_y β€ m-1).
From the cell (x,y), you can move your chess piece to (x,y') (1β€ y'β€ m, y' β y) or (x',y) (1β€ x'β€ n, x'β x). In other words, the chess piece moves as a rook. From the cell, you can move to any cell on the same row or column.
Your goal is to visit each cell exactly once. Can you find a solution?
Note that cells on the path between two adjacent cells in your route are not counted as visited, and it is not required to return to the starting point.
Input
The only line of the input contains four integers n, m, S_x and S_y (3β€ n,mβ€ 100, 2 β€ S_x β€ n-1, 2 β€ S_y β€ m-1) β the number of rows, the number of columns, and the initial position of your chess piece, respectively.
Output
You should print nβ
m lines.
The i-th line should contain two integers x_i and y_i (1 β€ x_i β€ n, 1 β€ y_i β€ m), denoting the i-th cell that you visited. You should print exactly nm pairs (x_i, y_i), they should cover all possible pairs (x_i, y_i), such that 1 β€ x_i β€ n, 1 β€ y_i β€ m.
We can show that under these constraints there always exists a solution. If there are multiple answers, print any.
Examples
Input
3 3 2 2
Output
2 2
1 2
1 3
2 3
3 3
3 2
3 1
2 1
1 1
Input
3 4 2 2
Output
2 2
2 1
2 3
2 4
1 4
3 4
3 3
3 2
3 1
1 1
1 2
1 3
Note
Possible routes for two examples:
<image> | instruction | 0 | 102,206 | 15 | 204,412 |
Tags: constructive algorithms
Correct Solution:
```
n,m,x,y=map(int,input().split(" "))
for i in range(n):
for j in range(m):
print(x,y)
if y==m:
y=1
else:
y+=1
if y==1:
y=m
else:
y-=1
if x==n:
x=1
else:
x+=1
``` | output | 1 | 102,206 | 15 | 204,413 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Boboniu likes playing chess with his employees. As we know, no employee can beat the boss in the chess game, so Boboniu has never lost in any round.
You are a new applicant for his company. Boboniu will test you with the following chess question:
Consider a nΓ m grid (rows are numbered from 1 to n, and columns are numbered from 1 to m). You have a chess piece, and it stands at some cell (S_x,S_y) which is not on the border (i.e. 2 β€ S_x β€ n-1 and 2 β€ S_y β€ m-1).
From the cell (x,y), you can move your chess piece to (x,y') (1β€ y'β€ m, y' β y) or (x',y) (1β€ x'β€ n, x'β x). In other words, the chess piece moves as a rook. From the cell, you can move to any cell on the same row or column.
Your goal is to visit each cell exactly once. Can you find a solution?
Note that cells on the path between two adjacent cells in your route are not counted as visited, and it is not required to return to the starting point.
Input
The only line of the input contains four integers n, m, S_x and S_y (3β€ n,mβ€ 100, 2 β€ S_x β€ n-1, 2 β€ S_y β€ m-1) β the number of rows, the number of columns, and the initial position of your chess piece, respectively.
Output
You should print nβ
m lines.
The i-th line should contain two integers x_i and y_i (1 β€ x_i β€ n, 1 β€ y_i β€ m), denoting the i-th cell that you visited. You should print exactly nm pairs (x_i, y_i), they should cover all possible pairs (x_i, y_i), such that 1 β€ x_i β€ n, 1 β€ y_i β€ m.
We can show that under these constraints there always exists a solution. If there are multiple answers, print any.
Examples
Input
3 3 2 2
Output
2 2
1 2
1 3
2 3
3 3
3 2
3 1
2 1
1 1
Input
3 4 2 2
Output
2 2
2 1
2 3
2 4
1 4
3 4
3 3
3 2
3 1
1 1
1 2
1 3
Note
Possible routes for two examples:
<image> | instruction | 0 | 102,207 | 15 | 204,414 |
Tags: constructive algorithms
Correct Solution:
```
a , b , x, y = map(int,input().split())
ans1 = x
ans2 = y
for x in range(a):
if ans1>a:
ans1 = ans1 - a
for x in range(b):
if ans2>b:
ans2 = ans2 - b
print(f"{ans1} {ans2}")
ans2 = ans2 + 1
ans1 = ans1 + 1
ans2 = ans2 - 1
``` | output | 1 | 102,207 | 15 | 204,415 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Boboniu likes playing chess with his employees. As we know, no employee can beat the boss in the chess game, so Boboniu has never lost in any round.
You are a new applicant for his company. Boboniu will test you with the following chess question:
Consider a nΓ m grid (rows are numbered from 1 to n, and columns are numbered from 1 to m). You have a chess piece, and it stands at some cell (S_x,S_y) which is not on the border (i.e. 2 β€ S_x β€ n-1 and 2 β€ S_y β€ m-1).
From the cell (x,y), you can move your chess piece to (x,y') (1β€ y'β€ m, y' β y) or (x',y) (1β€ x'β€ n, x'β x). In other words, the chess piece moves as a rook. From the cell, you can move to any cell on the same row or column.
Your goal is to visit each cell exactly once. Can you find a solution?
Note that cells on the path between two adjacent cells in your route are not counted as visited, and it is not required to return to the starting point.
Input
The only line of the input contains four integers n, m, S_x and S_y (3β€ n,mβ€ 100, 2 β€ S_x β€ n-1, 2 β€ S_y β€ m-1) β the number of rows, the number of columns, and the initial position of your chess piece, respectively.
Output
You should print nβ
m lines.
The i-th line should contain two integers x_i and y_i (1 β€ x_i β€ n, 1 β€ y_i β€ m), denoting the i-th cell that you visited. You should print exactly nm pairs (x_i, y_i), they should cover all possible pairs (x_i, y_i), such that 1 β€ x_i β€ n, 1 β€ y_i β€ m.
We can show that under these constraints there always exists a solution. If there are multiple answers, print any.
Examples
Input
3 3 2 2
Output
2 2
1 2
1 3
2 3
3 3
3 2
3 1
2 1
1 1
Input
3 4 2 2
Output
2 2
2 1
2 3
2 4
1 4
3 4
3 3
3 2
3 1
1 1
1 2
1 3
Note
Possible routes for two examples:
<image> | instruction | 0 | 102,208 | 15 | 204,416 |
Tags: constructive algorithms
Correct Solution:
```
n,m,r,c=map(int,input().split())
r-=1
c-=1
init=[r,c]
# print starting row
print(r+1,c+1)
for j in range(c+1,m):
print(r+1,j+1)
for j in range(c-1,-1,-1):
print(r+1,j+1)
lr=True
r+=1
while r < n:
if lr:
for j in range(m):
print(r+1,j+1)
else:
for j in range(m-1,-1,-1):
print(r+1,j+1)
lr=not lr
r+=1
r=init[0]-1
while r>=0:
if lr:
for j in range(m):
print(r+1,j+1)
else:
for j in range(m-1,-1,-1):
print(r+1,j+1)
lr=not lr
r-=1
``` | output | 1 | 102,208 | 15 | 204,417 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Boboniu likes playing chess with his employees. As we know, no employee can beat the boss in the chess game, so Boboniu has never lost in any round.
You are a new applicant for his company. Boboniu will test you with the following chess question:
Consider a nΓ m grid (rows are numbered from 1 to n, and columns are numbered from 1 to m). You have a chess piece, and it stands at some cell (S_x,S_y) which is not on the border (i.e. 2 β€ S_x β€ n-1 and 2 β€ S_y β€ m-1).
From the cell (x,y), you can move your chess piece to (x,y') (1β€ y'β€ m, y' β y) or (x',y) (1β€ x'β€ n, x'β x). In other words, the chess piece moves as a rook. From the cell, you can move to any cell on the same row or column.
Your goal is to visit each cell exactly once. Can you find a solution?
Note that cells on the path between two adjacent cells in your route are not counted as visited, and it is not required to return to the starting point.
Input
The only line of the input contains four integers n, m, S_x and S_y (3β€ n,mβ€ 100, 2 β€ S_x β€ n-1, 2 β€ S_y β€ m-1) β the number of rows, the number of columns, and the initial position of your chess piece, respectively.
Output
You should print nβ
m lines.
The i-th line should contain two integers x_i and y_i (1 β€ x_i β€ n, 1 β€ y_i β€ m), denoting the i-th cell that you visited. You should print exactly nm pairs (x_i, y_i), they should cover all possible pairs (x_i, y_i), such that 1 β€ x_i β€ n, 1 β€ y_i β€ m.
We can show that under these constraints there always exists a solution. If there are multiple answers, print any.
Examples
Input
3 3 2 2
Output
2 2
1 2
1 3
2 3
3 3
3 2
3 1
2 1
1 1
Input
3 4 2 2
Output
2 2
2 1
2 3
2 4
1 4
3 4
3 3
3 2
3 1
1 1
1 2
1 3
Note
Possible routes for two examples:
<image> | instruction | 0 | 102,209 | 15 | 204,418 |
Tags: constructive algorithms
Correct Solution:
```
nums=input().split(' ')
nums=[int(x) for x in nums]
n=nums[0]
m=nums[1]
sx=nums[2]
sy=nums[3]
#do the local column
print(str(sx)+" "+str(sy))
for i in range(1,n+1):
if i!=sx:
print(str(i)+" "+str(sy))
for i in range(1,m+1):
if i<sy:
if i%2==1:
for j in range(n,0,-1):
print(str(j)+" "+str(i))
else:
for j in range(1,n+1):
print(str(j)+" "+str(i))
elif i>sy:
if (i-1)%2==1:
for j in range(n,0,-1):
print(str(j)+" "+str(i))
else:
for j in range(1,n+1):
print(str(j)+" "+str(i))
``` | output | 1 | 102,209 | 15 | 204,419 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Boboniu likes playing chess with his employees. As we know, no employee can beat the boss in the chess game, so Boboniu has never lost in any round.
You are a new applicant for his company. Boboniu will test you with the following chess question:
Consider a nΓ m grid (rows are numbered from 1 to n, and columns are numbered from 1 to m). You have a chess piece, and it stands at some cell (S_x,S_y) which is not on the border (i.e. 2 β€ S_x β€ n-1 and 2 β€ S_y β€ m-1).
From the cell (x,y), you can move your chess piece to (x,y') (1β€ y'β€ m, y' β y) or (x',y) (1β€ x'β€ n, x'β x). In other words, the chess piece moves as a rook. From the cell, you can move to any cell on the same row or column.
Your goal is to visit each cell exactly once. Can you find a solution?
Note that cells on the path between two adjacent cells in your route are not counted as visited, and it is not required to return to the starting point.
Input
The only line of the input contains four integers n, m, S_x and S_y (3β€ n,mβ€ 100, 2 β€ S_x β€ n-1, 2 β€ S_y β€ m-1) β the number of rows, the number of columns, and the initial position of your chess piece, respectively.
Output
You should print nβ
m lines.
The i-th line should contain two integers x_i and y_i (1 β€ x_i β€ n, 1 β€ y_i β€ m), denoting the i-th cell that you visited. You should print exactly nm pairs (x_i, y_i), they should cover all possible pairs (x_i, y_i), such that 1 β€ x_i β€ n, 1 β€ y_i β€ m.
We can show that under these constraints there always exists a solution. If there are multiple answers, print any.
Examples
Input
3 3 2 2
Output
2 2
1 2
1 3
2 3
3 3
3 2
3 1
2 1
1 1
Input
3 4 2 2
Output
2 2
2 1
2 3
2 4
1 4
3 4
3 3
3 2
3 1
1 1
1 2
1 3
Note
Possible routes for two examples:
<image> | instruction | 0 | 102,210 | 15 | 204,420 |
Tags: constructive algorithms
Correct Solution:
```
n,m,sx,sy = map(int, input().split())
for y in range(sy,m+1):
print(sx,y)
for y in range(sy-1,0,-1):
print(sx,y)
to_back = True
for x in range(1,n+1):
if x == sx: continue
if to_back:
for y in range(1,m+1):
print(x,y)
else:
for y in range(m,0,-1):
print(x,y)
to_back = not to_back
``` | output | 1 | 102,210 | 15 | 204,421 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Boboniu likes playing chess with his employees. As we know, no employee can beat the boss in the chess game, so Boboniu has never lost in any round.
You are a new applicant for his company. Boboniu will test you with the following chess question:
Consider a nΓ m grid (rows are numbered from 1 to n, and columns are numbered from 1 to m). You have a chess piece, and it stands at some cell (S_x,S_y) which is not on the border (i.e. 2 β€ S_x β€ n-1 and 2 β€ S_y β€ m-1).
From the cell (x,y), you can move your chess piece to (x,y') (1β€ y'β€ m, y' β y) or (x',y) (1β€ x'β€ n, x'β x). In other words, the chess piece moves as a rook. From the cell, you can move to any cell on the same row or column.
Your goal is to visit each cell exactly once. Can you find a solution?
Note that cells on the path between two adjacent cells in your route are not counted as visited, and it is not required to return to the starting point.
Input
The only line of the input contains four integers n, m, S_x and S_y (3β€ n,mβ€ 100, 2 β€ S_x β€ n-1, 2 β€ S_y β€ m-1) β the number of rows, the number of columns, and the initial position of your chess piece, respectively.
Output
You should print nβ
m lines.
The i-th line should contain two integers x_i and y_i (1 β€ x_i β€ n, 1 β€ y_i β€ m), denoting the i-th cell that you visited. You should print exactly nm pairs (x_i, y_i), they should cover all possible pairs (x_i, y_i), such that 1 β€ x_i β€ n, 1 β€ y_i β€ m.
We can show that under these constraints there always exists a solution. If there are multiple answers, print any.
Examples
Input
3 3 2 2
Output
2 2
1 2
1 3
2 3
3 3
3 2
3 1
2 1
1 1
Input
3 4 2 2
Output
2 2
2 1
2 3
2 4
1 4
3 4
3 3
3 2
3 1
1 1
1 2
1 3
Note
Possible routes for two examples:
<image> | instruction | 0 | 102,211 | 15 | 204,422 |
Tags: constructive algorithms
Correct Solution:
```
from sys import stdin,stdout
import math,queue,heapq
fastinput=stdin.readline
fastout=stdout.write
t=1
while t:
t-=1
n,m,sx,sy=map(int,fastinput().split())
visited=[]
visited.append([sx,sy])
visited.append([1,sy])
visited.append([1,1])
for i in visited:
print(*i)
x=1
j=1
for i in range(1,n+1):
while j>=1 and j<=m:
if [i,j] in visited:
j+=x
continue
else:
print(i,j)
j+=x
if j==0:
j=1
if j==(m+1):
j=m
if j==m:
x=-1
else:
x=1
``` | output | 1 | 102,211 | 15 | 204,423 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Boboniu likes playing chess with his employees. As we know, no employee can beat the boss in the chess game, so Boboniu has never lost in any round.
You are a new applicant for his company. Boboniu will test you with the following chess question:
Consider a nΓ m grid (rows are numbered from 1 to n, and columns are numbered from 1 to m). You have a chess piece, and it stands at some cell (S_x,S_y) which is not on the border (i.e. 2 β€ S_x β€ n-1 and 2 β€ S_y β€ m-1).
From the cell (x,y), you can move your chess piece to (x,y') (1β€ y'β€ m, y' β y) or (x',y) (1β€ x'β€ n, x'β x). In other words, the chess piece moves as a rook. From the cell, you can move to any cell on the same row or column.
Your goal is to visit each cell exactly once. Can you find a solution?
Note that cells on the path between two adjacent cells in your route are not counted as visited, and it is not required to return to the starting point.
Input
The only line of the input contains four integers n, m, S_x and S_y (3β€ n,mβ€ 100, 2 β€ S_x β€ n-1, 2 β€ S_y β€ m-1) β the number of rows, the number of columns, and the initial position of your chess piece, respectively.
Output
You should print nβ
m lines.
The i-th line should contain two integers x_i and y_i (1 β€ x_i β€ n, 1 β€ y_i β€ m), denoting the i-th cell that you visited. You should print exactly nm pairs (x_i, y_i), they should cover all possible pairs (x_i, y_i), such that 1 β€ x_i β€ n, 1 β€ y_i β€ m.
We can show that under these constraints there always exists a solution. If there are multiple answers, print any.
Examples
Input
3 3 2 2
Output
2 2
1 2
1 3
2 3
3 3
3 2
3 1
2 1
1 1
Input
3 4 2 2
Output
2 2
2 1
2 3
2 4
1 4
3 4
3 3
3 2
3 1
1 1
1 2
1 3
Note
Possible routes for two examples:
<image> | instruction | 0 | 102,212 | 15 | 204,424 |
Tags: constructive algorithms
Correct Solution:
```
import sys
input = sys.stdin.readline
I = lambda : list(map(int,input().split()))
x,y,a,b,=I()
a-=1
b-=1
print(a+1,b+1)
for i in range(y):
if i!=b:
print(a+1,i+1)
r=1
flag=0
while r<=x:
if flag==0:
if r%2:
for i in range(y,0,-1):
print(r,i)
else:
for i in range(y):
print(r,i+1)
r+=1
else:
if r%2==0:
for i in range(y,0,-1):
print(r,i)
else:
for i in range(y):
print(r,i+1)
r+=1
if r==a+1:
r+=1
flag=1
``` | output | 1 | 102,212 | 15 | 204,425 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Boboniu likes playing chess with his employees. As we know, no employee can beat the boss in the chess game, so Boboniu has never lost in any round.
You are a new applicant for his company. Boboniu will test you with the following chess question:
Consider a nΓ m grid (rows are numbered from 1 to n, and columns are numbered from 1 to m). You have a chess piece, and it stands at some cell (S_x,S_y) which is not on the border (i.e. 2 β€ S_x β€ n-1 and 2 β€ S_y β€ m-1).
From the cell (x,y), you can move your chess piece to (x,y') (1β€ y'β€ m, y' β y) or (x',y) (1β€ x'β€ n, x'β x). In other words, the chess piece moves as a rook. From the cell, you can move to any cell on the same row or column.
Your goal is to visit each cell exactly once. Can you find a solution?
Note that cells on the path between two adjacent cells in your route are not counted as visited, and it is not required to return to the starting point.
Input
The only line of the input contains four integers n, m, S_x and S_y (3β€ n,mβ€ 100, 2 β€ S_x β€ n-1, 2 β€ S_y β€ m-1) β the number of rows, the number of columns, and the initial position of your chess piece, respectively.
Output
You should print nβ
m lines.
The i-th line should contain two integers x_i and y_i (1 β€ x_i β€ n, 1 β€ y_i β€ m), denoting the i-th cell that you visited. You should print exactly nm pairs (x_i, y_i), they should cover all possible pairs (x_i, y_i), such that 1 β€ x_i β€ n, 1 β€ y_i β€ m.
We can show that under these constraints there always exists a solution. If there are multiple answers, print any.
Examples
Input
3 3 2 2
Output
2 2
1 2
1 3
2 3
3 3
3 2
3 1
2 1
1 1
Input
3 4 2 2
Output
2 2
2 1
2 3
2 4
1 4
3 4
3 3
3 2
3 1
1 1
1 2
1 3
Note
Possible routes for two examples:
<image>
Submitted Solution:
```
import math as mt
def tran(n,m,sx,sy):
p=0
an=[]
for i in range(sx,n+1):
an.append([i,sy])
for i in range(sx-1,0,-1):
an.append([i,sy])
sx=i
while p==0:
if sx==n:
sy+=1
if sy<=m:
for i in range(sx,0,-1):
an.append([i,sy])
sx=i
else:
sy=1
for i in range(sx,0,-1):
an.append([i,sy])
sx=i
else:
sy+=1
if sy<=m:
for i in range(1,n+1):
an.append([i,sy])
sx=i
else:
sy=1
for i in range(1,n+1):
an.append([i,sy])
sx=i
if len(an)>=n*m:
break
return an
if __name__ == '__main__':
nk = list(map(int, input().rstrip().split()))
r = tran(nk[0],nk[1],nk[2],nk[3])
for i in r:
print(*i)
``` | instruction | 0 | 102,213 | 15 | 204,426 |
Yes | output | 1 | 102,213 | 15 | 204,427 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Boboniu likes playing chess with his employees. As we know, no employee can beat the boss in the chess game, so Boboniu has never lost in any round.
You are a new applicant for his company. Boboniu will test you with the following chess question:
Consider a nΓ m grid (rows are numbered from 1 to n, and columns are numbered from 1 to m). You have a chess piece, and it stands at some cell (S_x,S_y) which is not on the border (i.e. 2 β€ S_x β€ n-1 and 2 β€ S_y β€ m-1).
From the cell (x,y), you can move your chess piece to (x,y') (1β€ y'β€ m, y' β y) or (x',y) (1β€ x'β€ n, x'β x). In other words, the chess piece moves as a rook. From the cell, you can move to any cell on the same row or column.
Your goal is to visit each cell exactly once. Can you find a solution?
Note that cells on the path between two adjacent cells in your route are not counted as visited, and it is not required to return to the starting point.
Input
The only line of the input contains four integers n, m, S_x and S_y (3β€ n,mβ€ 100, 2 β€ S_x β€ n-1, 2 β€ S_y β€ m-1) β the number of rows, the number of columns, and the initial position of your chess piece, respectively.
Output
You should print nβ
m lines.
The i-th line should contain two integers x_i and y_i (1 β€ x_i β€ n, 1 β€ y_i β€ m), denoting the i-th cell that you visited. You should print exactly nm pairs (x_i, y_i), they should cover all possible pairs (x_i, y_i), such that 1 β€ x_i β€ n, 1 β€ y_i β€ m.
We can show that under these constraints there always exists a solution. If there are multiple answers, print any.
Examples
Input
3 3 2 2
Output
2 2
1 2
1 3
2 3
3 3
3 2
3 1
2 1
1 1
Input
3 4 2 2
Output
2 2
2 1
2 3
2 4
1 4
3 4
3 3
3 2
3 1
1 1
1 2
1 3
Note
Possible routes for two examples:
<image>
Submitted Solution:
```
n,m,x,y=map(int,input().split())
c=n*m
for i in range(x,n+1):
for j in range(y,m+1):
print(i,j)
for j in range(y-1,0,-1):
print(i,j)
y=j
for i in range(x-1,0,-1):
for j in range(y,m+1):
print(i,j)
for j in range(y-1,0,-1):
print(i,j)
y=j
``` | instruction | 0 | 102,214 | 15 | 204,428 |
Yes | output | 1 | 102,214 | 15 | 204,429 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Boboniu likes playing chess with his employees. As we know, no employee can beat the boss in the chess game, so Boboniu has never lost in any round.
You are a new applicant for his company. Boboniu will test you with the following chess question:
Consider a nΓ m grid (rows are numbered from 1 to n, and columns are numbered from 1 to m). You have a chess piece, and it stands at some cell (S_x,S_y) which is not on the border (i.e. 2 β€ S_x β€ n-1 and 2 β€ S_y β€ m-1).
From the cell (x,y), you can move your chess piece to (x,y') (1β€ y'β€ m, y' β y) or (x',y) (1β€ x'β€ n, x'β x). In other words, the chess piece moves as a rook. From the cell, you can move to any cell on the same row or column.
Your goal is to visit each cell exactly once. Can you find a solution?
Note that cells on the path between two adjacent cells in your route are not counted as visited, and it is not required to return to the starting point.
Input
The only line of the input contains four integers n, m, S_x and S_y (3β€ n,mβ€ 100, 2 β€ S_x β€ n-1, 2 β€ S_y β€ m-1) β the number of rows, the number of columns, and the initial position of your chess piece, respectively.
Output
You should print nβ
m lines.
The i-th line should contain two integers x_i and y_i (1 β€ x_i β€ n, 1 β€ y_i β€ m), denoting the i-th cell that you visited. You should print exactly nm pairs (x_i, y_i), they should cover all possible pairs (x_i, y_i), such that 1 β€ x_i β€ n, 1 β€ y_i β€ m.
We can show that under these constraints there always exists a solution. If there are multiple answers, print any.
Examples
Input
3 3 2 2
Output
2 2
1 2
1 3
2 3
3 3
3 2
3 1
2 1
1 1
Input
3 4 2 2
Output
2 2
2 1
2 3
2 4
1 4
3 4
3 3
3 2
3 1
1 1
1 2
1 3
Note
Possible routes for two examples:
<image>
Submitted Solution:
```
def move(n, m, x, y):
end = False
print(x, y)
for j in range(1, m + 1):
if j != y:
print(x, j)
for i in range(1, n + 1):
if i != x:
if end:
for j in range(1, m + 1):
print(i, j)
else:
for j in range(m, 0, -1):
print(i, j)
end= not end
n, m, x, y = map(int, input().split())
move(n, m, x, y)
``` | instruction | 0 | 102,215 | 15 | 204,430 |
Yes | output | 1 | 102,215 | 15 | 204,431 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Boboniu likes playing chess with his employees. As we know, no employee can beat the boss in the chess game, so Boboniu has never lost in any round.
You are a new applicant for his company. Boboniu will test you with the following chess question:
Consider a nΓ m grid (rows are numbered from 1 to n, and columns are numbered from 1 to m). You have a chess piece, and it stands at some cell (S_x,S_y) which is not on the border (i.e. 2 β€ S_x β€ n-1 and 2 β€ S_y β€ m-1).
From the cell (x,y), you can move your chess piece to (x,y') (1β€ y'β€ m, y' β y) or (x',y) (1β€ x'β€ n, x'β x). In other words, the chess piece moves as a rook. From the cell, you can move to any cell on the same row or column.
Your goal is to visit each cell exactly once. Can you find a solution?
Note that cells on the path between two adjacent cells in your route are not counted as visited, and it is not required to return to the starting point.
Input
The only line of the input contains four integers n, m, S_x and S_y (3β€ n,mβ€ 100, 2 β€ S_x β€ n-1, 2 β€ S_y β€ m-1) β the number of rows, the number of columns, and the initial position of your chess piece, respectively.
Output
You should print nβ
m lines.
The i-th line should contain two integers x_i and y_i (1 β€ x_i β€ n, 1 β€ y_i β€ m), denoting the i-th cell that you visited. You should print exactly nm pairs (x_i, y_i), they should cover all possible pairs (x_i, y_i), such that 1 β€ x_i β€ n, 1 β€ y_i β€ m.
We can show that under these constraints there always exists a solution. If there are multiple answers, print any.
Examples
Input
3 3 2 2
Output
2 2
1 2
1 3
2 3
3 3
3 2
3 1
2 1
1 1
Input
3 4 2 2
Output
2 2
2 1
2 3
2 4
1 4
3 4
3 3
3 2
3 1
1 1
1 2
1 3
Note
Possible routes for two examples:
<image>
Submitted Solution:
```
from sys import stdin, stdout
import math,sys,heapq
from itertools import permutations, combinations
from collections import defaultdict,deque,OrderedDict
from os import path
import bisect as bi
def yes():print('YES')
def no():print('NO')
if (path.exists('input.txt')):
#------------------Sublime--------------------------------------#
sys.stdin=open('input.txt','r');sys.stdout=open('output.txt','w');
def I():return (int(input()))
def In():return(map(int,input().split()))
else:
#------------------PYPY FAst I/o--------------------------------#
def I():return (int(stdin.readline()))
def In():return(map(int,stdin.readline().split()))
#sys.setrecursionlimit(1500)
def dict(a):
d={}
for x in a:
if d.get(x,-1)!=-1:
d[x]+=1
else:
d[x]=1
return d
def find_gt(a, x):
'Find leftmost value greater than x'
i = bi.bisect_right(a, x)
if i != len(a):
return i
else:
return -1
def main():
try:
n,m,x,y=In()
ans=[]
for i in range(x,1,-1):
ans.append([i,y])
for j in range(x+1,n+1):
ans.append([j,y])
q=0
for j in range(y-1,0,-1):
if q==0:
for i in range(n,1,-1):
ans.append([i,j])
q=1
else:
for i in range(2,n+1,+1):
ans.append([i,j])
q=0
for j in range(1,y+1):
ans.append([1,j])
q=0
for j in range(y+1,m+1):
if q==0:
for i in range(1,n+1):
ans.append([i,j])
q=1
else:
for i in range(n,0,-1):
ans.append([i,j])
q=0
for x in ans:
print(*x)
except:
pass
M = 998244353
P = 1000000007
if __name__ == '__main__':
#for _ in range(I()):main()
for _ in range(1):main()
``` | instruction | 0 | 102,216 | 15 | 204,432 |
Yes | output | 1 | 102,216 | 15 | 204,433 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Boboniu likes playing chess with his employees. As we know, no employee can beat the boss in the chess game, so Boboniu has never lost in any round.
You are a new applicant for his company. Boboniu will test you with the following chess question:
Consider a nΓ m grid (rows are numbered from 1 to n, and columns are numbered from 1 to m). You have a chess piece, and it stands at some cell (S_x,S_y) which is not on the border (i.e. 2 β€ S_x β€ n-1 and 2 β€ S_y β€ m-1).
From the cell (x,y), you can move your chess piece to (x,y') (1β€ y'β€ m, y' β y) or (x',y) (1β€ x'β€ n, x'β x). In other words, the chess piece moves as a rook. From the cell, you can move to any cell on the same row or column.
Your goal is to visit each cell exactly once. Can you find a solution?
Note that cells on the path between two adjacent cells in your route are not counted as visited, and it is not required to return to the starting point.
Input
The only line of the input contains four integers n, m, S_x and S_y (3β€ n,mβ€ 100, 2 β€ S_x β€ n-1, 2 β€ S_y β€ m-1) β the number of rows, the number of columns, and the initial position of your chess piece, respectively.
Output
You should print nβ
m lines.
The i-th line should contain two integers x_i and y_i (1 β€ x_i β€ n, 1 β€ y_i β€ m), denoting the i-th cell that you visited. You should print exactly nm pairs (x_i, y_i), they should cover all possible pairs (x_i, y_i), such that 1 β€ x_i β€ n, 1 β€ y_i β€ m.
We can show that under these constraints there always exists a solution. If there are multiple answers, print any.
Examples
Input
3 3 2 2
Output
2 2
1 2
1 3
2 3
3 3
3 2
3 1
2 1
1 1
Input
3 4 2 2
Output
2 2
2 1
2 3
2 4
1 4
3 4
3 3
3 2
3 1
1 1
1 2
1 3
Note
Possible routes for two examples:
<image>
Submitted Solution:
```
import sys
def mover(r,c,n,m):
l1=c
countr=0
countl=0
while l1>=1:
countr=1
print('{} {}'.format(r,l1))
l1-=1
l1=c+1
while l1<=m:
countl=1
print('{} {}'.format(r,l1))
l1+=1
if countl==0:
return(1)
else:
return(m)
n,m,s1,s2=map(int,(sys.stdin.readline()).split())
k=s2
p=s1
counter=0
while k>=1:
p=mover(k,p,n,m)
k-=1
k=s2+1
while k<=n:
p=mover(k,p,n,m)
k+=1
``` | instruction | 0 | 102,217 | 15 | 204,434 |
No | output | 1 | 102,217 | 15 | 204,435 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Boboniu likes playing chess with his employees. As we know, no employee can beat the boss in the chess game, so Boboniu has never lost in any round.
You are a new applicant for his company. Boboniu will test you with the following chess question:
Consider a nΓ m grid (rows are numbered from 1 to n, and columns are numbered from 1 to m). You have a chess piece, and it stands at some cell (S_x,S_y) which is not on the border (i.e. 2 β€ S_x β€ n-1 and 2 β€ S_y β€ m-1).
From the cell (x,y), you can move your chess piece to (x,y') (1β€ y'β€ m, y' β y) or (x',y) (1β€ x'β€ n, x'β x). In other words, the chess piece moves as a rook. From the cell, you can move to any cell on the same row or column.
Your goal is to visit each cell exactly once. Can you find a solution?
Note that cells on the path between two adjacent cells in your route are not counted as visited, and it is not required to return to the starting point.
Input
The only line of the input contains four integers n, m, S_x and S_y (3β€ n,mβ€ 100, 2 β€ S_x β€ n-1, 2 β€ S_y β€ m-1) β the number of rows, the number of columns, and the initial position of your chess piece, respectively.
Output
You should print nβ
m lines.
The i-th line should contain two integers x_i and y_i (1 β€ x_i β€ n, 1 β€ y_i β€ m), denoting the i-th cell that you visited. You should print exactly nm pairs (x_i, y_i), they should cover all possible pairs (x_i, y_i), such that 1 β€ x_i β€ n, 1 β€ y_i β€ m.
We can show that under these constraints there always exists a solution. If there are multiple answers, print any.
Examples
Input
3 3 2 2
Output
2 2
1 2
1 3
2 3
3 3
3 2
3 1
2 1
1 1
Input
3 4 2 2
Output
2 2
2 1
2 3
2 4
1 4
3 4
3 3
3 2
3 1
1 1
1 2
1 3
Note
Possible routes for two examples:
<image>
Submitted Solution:
```
n, m, x, y = [int(x) for x in input().split()]
print('{} {}'.format(x, y))
print('1 {}'.format(y))
for i in range(1, n + 1, 2):
for j in range(1, m + 1):
if j == y and i in [1, x]:
continue
print('{} {}'.format(i, j))
for j in range(m, 0, -1):
if i == n:
break
if j == y and i in [1, x]:
continue
print('{} {}'.format(i + 1, j))
``` | instruction | 0 | 102,218 | 15 | 204,436 |
No | output | 1 | 102,218 | 15 | 204,437 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Boboniu likes playing chess with his employees. As we know, no employee can beat the boss in the chess game, so Boboniu has never lost in any round.
You are a new applicant for his company. Boboniu will test you with the following chess question:
Consider a nΓ m grid (rows are numbered from 1 to n, and columns are numbered from 1 to m). You have a chess piece, and it stands at some cell (S_x,S_y) which is not on the border (i.e. 2 β€ S_x β€ n-1 and 2 β€ S_y β€ m-1).
From the cell (x,y), you can move your chess piece to (x,y') (1β€ y'β€ m, y' β y) or (x',y) (1β€ x'β€ n, x'β x). In other words, the chess piece moves as a rook. From the cell, you can move to any cell on the same row or column.
Your goal is to visit each cell exactly once. Can you find a solution?
Note that cells on the path between two adjacent cells in your route are not counted as visited, and it is not required to return to the starting point.
Input
The only line of the input contains four integers n, m, S_x and S_y (3β€ n,mβ€ 100, 2 β€ S_x β€ n-1, 2 β€ S_y β€ m-1) β the number of rows, the number of columns, and the initial position of your chess piece, respectively.
Output
You should print nβ
m lines.
The i-th line should contain two integers x_i and y_i (1 β€ x_i β€ n, 1 β€ y_i β€ m), denoting the i-th cell that you visited. You should print exactly nm pairs (x_i, y_i), they should cover all possible pairs (x_i, y_i), such that 1 β€ x_i β€ n, 1 β€ y_i β€ m.
We can show that under these constraints there always exists a solution. If there are multiple answers, print any.
Examples
Input
3 3 2 2
Output
2 2
1 2
1 3
2 3
3 3
3 2
3 1
2 1
1 1
Input
3 4 2 2
Output
2 2
2 1
2 3
2 4
1 4
3 4
3 3
3 2
3 1
1 1
1 2
1 3
Note
Possible routes for two examples:
<image>
Submitted Solution:
```
n, m, x, y = map(int,input().split())
used = [[0 for i in range(m)] for i in range(n)]
x -= 1
y -= 1
used[x][y] = 1
used[0][y] = 1
print(x + 1, y+1)
print(1, y+1)
x = y = 0
while x+y < n+m-2:
print(x+1,y+1)
used[x][y] = 1
q = x%2
if q == 0:
if y == m-1:
x += 1
else:
y += 1
if used[x][y] == 1:
y += 1
else:
if y == 0:
x += 1
else:
y -= 1
if used[x][y] == 1:
y -= 1
print(n, m)
``` | instruction | 0 | 102,219 | 15 | 204,438 |
No | output | 1 | 102,219 | 15 | 204,439 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Boboniu likes playing chess with his employees. As we know, no employee can beat the boss in the chess game, so Boboniu has never lost in any round.
You are a new applicant for his company. Boboniu will test you with the following chess question:
Consider a nΓ m grid (rows are numbered from 1 to n, and columns are numbered from 1 to m). You have a chess piece, and it stands at some cell (S_x,S_y) which is not on the border (i.e. 2 β€ S_x β€ n-1 and 2 β€ S_y β€ m-1).
From the cell (x,y), you can move your chess piece to (x,y') (1β€ y'β€ m, y' β y) or (x',y) (1β€ x'β€ n, x'β x). In other words, the chess piece moves as a rook. From the cell, you can move to any cell on the same row or column.
Your goal is to visit each cell exactly once. Can you find a solution?
Note that cells on the path between two adjacent cells in your route are not counted as visited, and it is not required to return to the starting point.
Input
The only line of the input contains four integers n, m, S_x and S_y (3β€ n,mβ€ 100, 2 β€ S_x β€ n-1, 2 β€ S_y β€ m-1) β the number of rows, the number of columns, and the initial position of your chess piece, respectively.
Output
You should print nβ
m lines.
The i-th line should contain two integers x_i and y_i (1 β€ x_i β€ n, 1 β€ y_i β€ m), denoting the i-th cell that you visited. You should print exactly nm pairs (x_i, y_i), they should cover all possible pairs (x_i, y_i), such that 1 β€ x_i β€ n, 1 β€ y_i β€ m.
We can show that under these constraints there always exists a solution. If there are multiple answers, print any.
Examples
Input
3 3 2 2
Output
2 2
1 2
1 3
2 3
3 3
3 2
3 1
2 1
1 1
Input
3 4 2 2
Output
2 2
2 1
2 3
2 4
1 4
3 4
3 3
3 2
3 1
1 1
1 2
1 3
Note
Possible routes for two examples:
<image>
Submitted Solution:
```
n,m,x,y=map(int,input().split())
for i in range(1,x):
print(y,i)
for i in range(x+1,m+1):
print(y,i)
for i in range(1,y):
if i%2==1:
for j in range(m,0,-1):
print(i,j)
else:
for j in range(1,m+1):
print(i,j)
for i in range(y+1,n+1):
if i%2==0:
for j in range(m,0,-1):
print(i,j)
else:
for j in range(1,m+1):
print(i,j)
``` | instruction | 0 | 102,220 | 15 | 204,440 |
No | output | 1 | 102,220 | 15 | 204,441 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Two neighboring kingdoms decided to build a wall between them with some gates to enable the citizens to go from one kingdom to another. Each time a citizen passes through a gate, he has to pay one silver coin.
The world can be represented by the first quadrant of a plane and the wall is built along the identity line (i.e. the line with the equation x = y). Any point below the wall belongs to the first kingdom while any point above the wall belongs to the second kingdom. There is a gate at any integer point on the line (i.e. at points (0, 0), (1, 1), (2, 2), ...). The wall and the gates do not belong to any of the kingdoms.
Fafa is at the gate at position (0, 0) and he wants to walk around in the two kingdoms. He knows the sequence S of moves he will do. This sequence is a string where each character represents a move. The two possible moves Fafa will do are 'U' (move one step up, from (x, y) to (x, y + 1)) and 'R' (move one step right, from (x, y) to (x + 1, y)).
Fafa wants to know the number of silver coins he needs to pay to walk around the two kingdoms following the sequence S. Note that if Fafa visits a gate without moving from one kingdom to another, he pays no silver coins. Also assume that he doesn't pay at the gate at point (0, 0), i. e. he is initially on the side he needs.
Input
The first line of the input contains single integer n (1 β€ n β€ 105) β the number of moves in the walking sequence.
The second line contains a string S of length n consisting of the characters 'U' and 'R' describing the required moves. Fafa will follow the sequence S in order from left to right.
Output
On a single line, print one integer representing the number of silver coins Fafa needs to pay at the gates to follow the sequence S.
Examples
Input
1
U
Output
0
Input
6
RURUUR
Output
1
Input
7
URRRUUU
Output
2
Note
The figure below describes the third sample. The red arrows represent the sequence of moves Fafa will follow. The green gates represent the gates at which Fafa have to pay silver coins.
<image> | instruction | 0 | 102,641 | 15 | 205,282 |
Tags: implementation
Correct Solution:
```
n=int(input())
s=input()
l=[0,0]
count=0
state=0
def up():
l[1]+=1
def right():
l[0]+=1
for x in s:
if state==0:
if x=='U':
up()
state=2
elif x=="R":
right()
state=1
elif state==1:
if x=='U':
up()
elif x=="R":
right()
if l[1]>l[0]:
count+=1
state=2
elif state==2:
if x=='U':
up()
elif x=="R":
right()
if l[1]<l[0]:
count+=1
state=1
print(count)
``` | output | 1 | 102,641 | 15 | 205,283 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Two neighboring kingdoms decided to build a wall between them with some gates to enable the citizens to go from one kingdom to another. Each time a citizen passes through a gate, he has to pay one silver coin.
The world can be represented by the first quadrant of a plane and the wall is built along the identity line (i.e. the line with the equation x = y). Any point below the wall belongs to the first kingdom while any point above the wall belongs to the second kingdom. There is a gate at any integer point on the line (i.e. at points (0, 0), (1, 1), (2, 2), ...). The wall and the gates do not belong to any of the kingdoms.
Fafa is at the gate at position (0, 0) and he wants to walk around in the two kingdoms. He knows the sequence S of moves he will do. This sequence is a string where each character represents a move. The two possible moves Fafa will do are 'U' (move one step up, from (x, y) to (x, y + 1)) and 'R' (move one step right, from (x, y) to (x + 1, y)).
Fafa wants to know the number of silver coins he needs to pay to walk around the two kingdoms following the sequence S. Note that if Fafa visits a gate without moving from one kingdom to another, he pays no silver coins. Also assume that he doesn't pay at the gate at point (0, 0), i. e. he is initially on the side he needs.
Input
The first line of the input contains single integer n (1 β€ n β€ 105) β the number of moves in the walking sequence.
The second line contains a string S of length n consisting of the characters 'U' and 'R' describing the required moves. Fafa will follow the sequence S in order from left to right.
Output
On a single line, print one integer representing the number of silver coins Fafa needs to pay at the gates to follow the sequence S.
Examples
Input
1
U
Output
0
Input
6
RURUUR
Output
1
Input
7
URRRUUU
Output
2
Note
The figure below describes the third sample. The red arrows represent the sequence of moves Fafa will follow. The green gates represent the gates at which Fafa have to pay silver coins.
<image> | instruction | 0 | 102,642 | 15 | 205,284 |
Tags: implementation
Correct Solution:
```
from sys import stdin, stdout
n = int(stdin.readline())
coordinates = []
x, y = 0, 0
def check(ind):
if ind + 1 >= n:
return False
label = (coordinates[ind - 1][1] > coordinates[ind - 1][0]) ^ (coordinates[ind + 1][1] > coordinates[ind + 1][0])
return ind + 1 < n and label
f = stdin.readline().strip()
for i in range(n):
s = f[i]
if s == 'U':
y += 1
elif s == 'D':
y -= 1
elif s== 'L':
x -= 1
else:
x += 1
coordinates.append((x, y))
ans = 0
for i in range(n):
if coordinates[i][0] == coordinates[i][1] and check(i):
ans += 1
stdout.write(str(ans))
``` | output | 1 | 102,642 | 15 | 205,285 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Two neighboring kingdoms decided to build a wall between them with some gates to enable the citizens to go from one kingdom to another. Each time a citizen passes through a gate, he has to pay one silver coin.
The world can be represented by the first quadrant of a plane and the wall is built along the identity line (i.e. the line with the equation x = y). Any point below the wall belongs to the first kingdom while any point above the wall belongs to the second kingdom. There is a gate at any integer point on the line (i.e. at points (0, 0), (1, 1), (2, 2), ...). The wall and the gates do not belong to any of the kingdoms.
Fafa is at the gate at position (0, 0) and he wants to walk around in the two kingdoms. He knows the sequence S of moves he will do. This sequence is a string where each character represents a move. The two possible moves Fafa will do are 'U' (move one step up, from (x, y) to (x, y + 1)) and 'R' (move one step right, from (x, y) to (x + 1, y)).
Fafa wants to know the number of silver coins he needs to pay to walk around the two kingdoms following the sequence S. Note that if Fafa visits a gate without moving from one kingdom to another, he pays no silver coins. Also assume that he doesn't pay at the gate at point (0, 0), i. e. he is initially on the side he needs.
Input
The first line of the input contains single integer n (1 β€ n β€ 105) β the number of moves in the walking sequence.
The second line contains a string S of length n consisting of the characters 'U' and 'R' describing the required moves. Fafa will follow the sequence S in order from left to right.
Output
On a single line, print one integer representing the number of silver coins Fafa needs to pay at the gates to follow the sequence S.
Examples
Input
1
U
Output
0
Input
6
RURUUR
Output
1
Input
7
URRRUUU
Output
2
Note
The figure below describes the third sample. The red arrows represent the sequence of moves Fafa will follow. The green gates represent the gates at which Fafa have to pay silver coins.
<image> | instruction | 0 | 102,643 | 15 | 205,286 |
Tags: implementation
Correct Solution:
```
import sys
import math
#to read string
get_string = lambda: sys.stdin.readline().strip()
#to read list of integers
get_list = lambda: list( map(int,sys.stdin.readline().strip().split()) )
#to read integers
get_int = lambda: int(sys.stdin.readline())
#--------------------------------WhiteHat010--------------------------------------#
n = get_int()
s = get_string()
count = 0
if s[0] == 'U':
x,y = 0,1
state = 0
else:
x,y = 1,0
state = 1
for i in range(1,n):
x1,y1 = x,y
if s[i] == 'U':
x,y = x,y+1
else:
x,y = x+1,y
if x1==y1:
if x>y:
temp = 1
elif x<y:
temp = 0
else:
temp = state
if temp != state:
state = temp
count += 1
print(count)
``` | output | 1 | 102,643 | 15 | 205,287 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Two neighboring kingdoms decided to build a wall between them with some gates to enable the citizens to go from one kingdom to another. Each time a citizen passes through a gate, he has to pay one silver coin.
The world can be represented by the first quadrant of a plane and the wall is built along the identity line (i.e. the line with the equation x = y). Any point below the wall belongs to the first kingdom while any point above the wall belongs to the second kingdom. There is a gate at any integer point on the line (i.e. at points (0, 0), (1, 1), (2, 2), ...). The wall and the gates do not belong to any of the kingdoms.
Fafa is at the gate at position (0, 0) and he wants to walk around in the two kingdoms. He knows the sequence S of moves he will do. This sequence is a string where each character represents a move. The two possible moves Fafa will do are 'U' (move one step up, from (x, y) to (x, y + 1)) and 'R' (move one step right, from (x, y) to (x + 1, y)).
Fafa wants to know the number of silver coins he needs to pay to walk around the two kingdoms following the sequence S. Note that if Fafa visits a gate without moving from one kingdom to another, he pays no silver coins. Also assume that he doesn't pay at the gate at point (0, 0), i. e. he is initially on the side he needs.
Input
The first line of the input contains single integer n (1 β€ n β€ 105) β the number of moves in the walking sequence.
The second line contains a string S of length n consisting of the characters 'U' and 'R' describing the required moves. Fafa will follow the sequence S in order from left to right.
Output
On a single line, print one integer representing the number of silver coins Fafa needs to pay at the gates to follow the sequence S.
Examples
Input
1
U
Output
0
Input
6
RURUUR
Output
1
Input
7
URRRUUU
Output
2
Note
The figure below describes the third sample. The red arrows represent the sequence of moves Fafa will follow. The green gates represent the gates at which Fafa have to pay silver coins.
<image> | instruction | 0 | 102,644 | 15 | 205,288 |
Tags: implementation
Correct Solution:
```
'''input
7
URRRUUU
'''
n = int(input())
s = input()
gate = False
ans, countu, countr = 0, 0, 0
for i in range(n):
if countu == countr and (s[i - 1] == s[i]) and i > 0:
ans, gate = ans + 1, False
if(s[i] == 'U'):
countu += 1
if(s[i] == 'R'):
countr += 1
print(ans)
``` | output | 1 | 102,644 | 15 | 205,289 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Two neighboring kingdoms decided to build a wall between them with some gates to enable the citizens to go from one kingdom to another. Each time a citizen passes through a gate, he has to pay one silver coin.
The world can be represented by the first quadrant of a plane and the wall is built along the identity line (i.e. the line with the equation x = y). Any point below the wall belongs to the first kingdom while any point above the wall belongs to the second kingdom. There is a gate at any integer point on the line (i.e. at points (0, 0), (1, 1), (2, 2), ...). The wall and the gates do not belong to any of the kingdoms.
Fafa is at the gate at position (0, 0) and he wants to walk around in the two kingdoms. He knows the sequence S of moves he will do. This sequence is a string where each character represents a move. The two possible moves Fafa will do are 'U' (move one step up, from (x, y) to (x, y + 1)) and 'R' (move one step right, from (x, y) to (x + 1, y)).
Fafa wants to know the number of silver coins he needs to pay to walk around the two kingdoms following the sequence S. Note that if Fafa visits a gate without moving from one kingdom to another, he pays no silver coins. Also assume that he doesn't pay at the gate at point (0, 0), i. e. he is initially on the side he needs.
Input
The first line of the input contains single integer n (1 β€ n β€ 105) β the number of moves in the walking sequence.
The second line contains a string S of length n consisting of the characters 'U' and 'R' describing the required moves. Fafa will follow the sequence S in order from left to right.
Output
On a single line, print one integer representing the number of silver coins Fafa needs to pay at the gates to follow the sequence S.
Examples
Input
1
U
Output
0
Input
6
RURUUR
Output
1
Input
7
URRRUUU
Output
2
Note
The figure below describes the third sample. The red arrows represent the sequence of moves Fafa will follow. The green gates represent the gates at which Fafa have to pay silver coins.
<image> | instruction | 0 | 102,645 | 15 | 205,290 |
Tags: implementation
Correct Solution:
```
n=int(input())
s=input()
ans,a,b=0,0,0
for i in range(n-1):
if s[i]=='R':
a+=1
if s[i]=='U':
b+=1
if a==b:
a,b=0,0
if s[i+1]==s[i]: ans+=1
print(ans)
``` | output | 1 | 102,645 | 15 | 205,291 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Two neighboring kingdoms decided to build a wall between them with some gates to enable the citizens to go from one kingdom to another. Each time a citizen passes through a gate, he has to pay one silver coin.
The world can be represented by the first quadrant of a plane and the wall is built along the identity line (i.e. the line with the equation x = y). Any point below the wall belongs to the first kingdom while any point above the wall belongs to the second kingdom. There is a gate at any integer point on the line (i.e. at points (0, 0), (1, 1), (2, 2), ...). The wall and the gates do not belong to any of the kingdoms.
Fafa is at the gate at position (0, 0) and he wants to walk around in the two kingdoms. He knows the sequence S of moves he will do. This sequence is a string where each character represents a move. The two possible moves Fafa will do are 'U' (move one step up, from (x, y) to (x, y + 1)) and 'R' (move one step right, from (x, y) to (x + 1, y)).
Fafa wants to know the number of silver coins he needs to pay to walk around the two kingdoms following the sequence S. Note that if Fafa visits a gate without moving from one kingdom to another, he pays no silver coins. Also assume that he doesn't pay at the gate at point (0, 0), i. e. he is initially on the side he needs.
Input
The first line of the input contains single integer n (1 β€ n β€ 105) β the number of moves in the walking sequence.
The second line contains a string S of length n consisting of the characters 'U' and 'R' describing the required moves. Fafa will follow the sequence S in order from left to right.
Output
On a single line, print one integer representing the number of silver coins Fafa needs to pay at the gates to follow the sequence S.
Examples
Input
1
U
Output
0
Input
6
RURUUR
Output
1
Input
7
URRRUUU
Output
2
Note
The figure below describes the third sample. The red arrows represent the sequence of moves Fafa will follow. The green gates represent the gates at which Fafa have to pay silver coins.
<image> | instruction | 0 | 102,646 | 15 | 205,292 |
Tags: implementation
Correct Solution:
```
t = int(input())
s = str(input())
x,y,c=0,0,0
for i in range(t-1):
if s[i]=='U': y+=1
if s[i]=='R': x+=1
if x==y:
if s[i]==s[i+1]: c+=1
print(c)
``` | output | 1 | 102,646 | 15 | 205,293 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Two neighboring kingdoms decided to build a wall between them with some gates to enable the citizens to go from one kingdom to another. Each time a citizen passes through a gate, he has to pay one silver coin.
The world can be represented by the first quadrant of a plane and the wall is built along the identity line (i.e. the line with the equation x = y). Any point below the wall belongs to the first kingdom while any point above the wall belongs to the second kingdom. There is a gate at any integer point on the line (i.e. at points (0, 0), (1, 1), (2, 2), ...). The wall and the gates do not belong to any of the kingdoms.
Fafa is at the gate at position (0, 0) and he wants to walk around in the two kingdoms. He knows the sequence S of moves he will do. This sequence is a string where each character represents a move. The two possible moves Fafa will do are 'U' (move one step up, from (x, y) to (x, y + 1)) and 'R' (move one step right, from (x, y) to (x + 1, y)).
Fafa wants to know the number of silver coins he needs to pay to walk around the two kingdoms following the sequence S. Note that if Fafa visits a gate without moving from one kingdom to another, he pays no silver coins. Also assume that he doesn't pay at the gate at point (0, 0), i. e. he is initially on the side he needs.
Input
The first line of the input contains single integer n (1 β€ n β€ 105) β the number of moves in the walking sequence.
The second line contains a string S of length n consisting of the characters 'U' and 'R' describing the required moves. Fafa will follow the sequence S in order from left to right.
Output
On a single line, print one integer representing the number of silver coins Fafa needs to pay at the gates to follow the sequence S.
Examples
Input
1
U
Output
0
Input
6
RURUUR
Output
1
Input
7
URRRUUU
Output
2
Note
The figure below describes the third sample. The red arrows represent the sequence of moves Fafa will follow. The green gates represent the gates at which Fafa have to pay silver coins.
<image> | instruction | 0 | 102,647 | 15 | 205,294 |
Tags: implementation
Correct Solution:
```
n = int(input())
S = input()
money = 0
a = 0
for i in range(n):
if S[i] == 'R':
a+=1
else:
a-=1
if i == 0:
if a>0:
dom = 'pos'
else:
dom = 'neg'
if dom == 'pos' and a<0:
money+=1
dom = 'neg'
elif dom == 'neg' and a>0:
money+=1
dom = 'pos'
print(money)
``` | output | 1 | 102,647 | 15 | 205,295 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Two neighboring kingdoms decided to build a wall between them with some gates to enable the citizens to go from one kingdom to another. Each time a citizen passes through a gate, he has to pay one silver coin.
The world can be represented by the first quadrant of a plane and the wall is built along the identity line (i.e. the line with the equation x = y). Any point below the wall belongs to the first kingdom while any point above the wall belongs to the second kingdom. There is a gate at any integer point on the line (i.e. at points (0, 0), (1, 1), (2, 2), ...). The wall and the gates do not belong to any of the kingdoms.
Fafa is at the gate at position (0, 0) and he wants to walk around in the two kingdoms. He knows the sequence S of moves he will do. This sequence is a string where each character represents a move. The two possible moves Fafa will do are 'U' (move one step up, from (x, y) to (x, y + 1)) and 'R' (move one step right, from (x, y) to (x + 1, y)).
Fafa wants to know the number of silver coins he needs to pay to walk around the two kingdoms following the sequence S. Note that if Fafa visits a gate without moving from one kingdom to another, he pays no silver coins. Also assume that he doesn't pay at the gate at point (0, 0), i. e. he is initially on the side he needs.
Input
The first line of the input contains single integer n (1 β€ n β€ 105) β the number of moves in the walking sequence.
The second line contains a string S of length n consisting of the characters 'U' and 'R' describing the required moves. Fafa will follow the sequence S in order from left to right.
Output
On a single line, print one integer representing the number of silver coins Fafa needs to pay at the gates to follow the sequence S.
Examples
Input
1
U
Output
0
Input
6
RURUUR
Output
1
Input
7
URRRUUU
Output
2
Note
The figure below describes the third sample. The red arrows represent the sequence of moves Fafa will follow. The green gates represent the gates at which Fafa have to pay silver coins.
<image> | instruction | 0 | 102,648 | 15 | 205,296 |
Tags: implementation
Correct Solution:
```
n=int(input())
i=list(input())
x=0
y=0
cost=0
for index in range(len(i)-1):
if(i[index]=='U'):
y+=1
elif(i[index]=='R'):
x+=1
if(x==y):
if((i[index]=='U' and i[index+1]=='U') or (i[index]=='R' and i[index+1]=='R')):
cost+=1
print(cost)
``` | output | 1 | 102,648 | 15 | 205,297 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Two neighboring kingdoms decided to build a wall between them with some gates to enable the citizens to go from one kingdom to another. Each time a citizen passes through a gate, he has to pay one silver coin.
The world can be represented by the first quadrant of a plane and the wall is built along the identity line (i.e. the line with the equation x = y). Any point below the wall belongs to the first kingdom while any point above the wall belongs to the second kingdom. There is a gate at any integer point on the line (i.e. at points (0, 0), (1, 1), (2, 2), ...). The wall and the gates do not belong to any of the kingdoms.
Fafa is at the gate at position (0, 0) and he wants to walk around in the two kingdoms. He knows the sequence S of moves he will do. This sequence is a string where each character represents a move. The two possible moves Fafa will do are 'U' (move one step up, from (x, y) to (x, y + 1)) and 'R' (move one step right, from (x, y) to (x + 1, y)).
Fafa wants to know the number of silver coins he needs to pay to walk around the two kingdoms following the sequence S. Note that if Fafa visits a gate without moving from one kingdom to another, he pays no silver coins. Also assume that he doesn't pay at the gate at point (0, 0), i. e. he is initially on the side he needs.
Input
The first line of the input contains single integer n (1 β€ n β€ 105) β the number of moves in the walking sequence.
The second line contains a string S of length n consisting of the characters 'U' and 'R' describing the required moves. Fafa will follow the sequence S in order from left to right.
Output
On a single line, print one integer representing the number of silver coins Fafa needs to pay at the gates to follow the sequence S.
Examples
Input
1
U
Output
0
Input
6
RURUUR
Output
1
Input
7
URRRUUU
Output
2
Note
The figure below describes the third sample. The red arrows represent the sequence of moves Fafa will follow. The green gates represent the gates at which Fafa have to pay silver coins.
<image>
Submitted Solution:
```
import sys
if sys.version_info < (3, 0):
lrange = range
input = raw_input
range = xrange
n = int(input())
s = input()
if s[0] == 'U':
upper = True
x = 0
y = 1
else:
upper = False
x = 1
y = 0
cnt = 0
for c in s[1:]:
if c == 'U':
y += 1
if c == 'R':
x += 1
if upper:
if y<x:
upper = False
cnt += 1
else:
if y>x:
upper = True
cnt += 1
print(cnt)
``` | instruction | 0 | 102,649 | 15 | 205,298 |
Yes | output | 1 | 102,649 | 15 | 205,299 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Two neighboring kingdoms decided to build a wall between them with some gates to enable the citizens to go from one kingdom to another. Each time a citizen passes through a gate, he has to pay one silver coin.
The world can be represented by the first quadrant of a plane and the wall is built along the identity line (i.e. the line with the equation x = y). Any point below the wall belongs to the first kingdom while any point above the wall belongs to the second kingdom. There is a gate at any integer point on the line (i.e. at points (0, 0), (1, 1), (2, 2), ...). The wall and the gates do not belong to any of the kingdoms.
Fafa is at the gate at position (0, 0) and he wants to walk around in the two kingdoms. He knows the sequence S of moves he will do. This sequence is a string where each character represents a move. The two possible moves Fafa will do are 'U' (move one step up, from (x, y) to (x, y + 1)) and 'R' (move one step right, from (x, y) to (x + 1, y)).
Fafa wants to know the number of silver coins he needs to pay to walk around the two kingdoms following the sequence S. Note that if Fafa visits a gate without moving from one kingdom to another, he pays no silver coins. Also assume that he doesn't pay at the gate at point (0, 0), i. e. he is initially on the side he needs.
Input
The first line of the input contains single integer n (1 β€ n β€ 105) β the number of moves in the walking sequence.
The second line contains a string S of length n consisting of the characters 'U' and 'R' describing the required moves. Fafa will follow the sequence S in order from left to right.
Output
On a single line, print one integer representing the number of silver coins Fafa needs to pay at the gates to follow the sequence S.
Examples
Input
1
U
Output
0
Input
6
RURUUR
Output
1
Input
7
URRRUUU
Output
2
Note
The figure below describes the third sample. The red arrows represent the sequence of moves Fafa will follow. The green gates represent the gates at which Fafa have to pay silver coins.
<image>
Submitted Solution:
```
# -*- coding: utf-8 -*-
"""
Created on Mon Feb 19 23:14:17 2018
@author: Rakib
"""
n = int(input())
s = input()
count = 0
mat = [[0 for x in range(2)] for y in range(len(s)+1)]
for i in range(0,len(s)):
if s[i] == 'U':
mat[i+1][0] = mat[i][0]
mat[i+1][1] = mat[i][1] + 1
if s[i] == 'R':
mat[i+1][0] = mat[i][0] + 1
mat[i+1][1] = mat[i][1]
for i in range(1,len(s)):
if mat[i][0] == mat[i][1]:
if (((mat[i-1][0] - mat[i+1][0]) == 0) | ((mat[i-1][1] - mat[i+1][1]) == 0)):
count += 1
print(count)
``` | instruction | 0 | 102,650 | 15 | 205,300 |
Yes | output | 1 | 102,650 | 15 | 205,301 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Two neighboring kingdoms decided to build a wall between them with some gates to enable the citizens to go from one kingdom to another. Each time a citizen passes through a gate, he has to pay one silver coin.
The world can be represented by the first quadrant of a plane and the wall is built along the identity line (i.e. the line with the equation x = y). Any point below the wall belongs to the first kingdom while any point above the wall belongs to the second kingdom. There is a gate at any integer point on the line (i.e. at points (0, 0), (1, 1), (2, 2), ...). The wall and the gates do not belong to any of the kingdoms.
Fafa is at the gate at position (0, 0) and he wants to walk around in the two kingdoms. He knows the sequence S of moves he will do. This sequence is a string where each character represents a move. The two possible moves Fafa will do are 'U' (move one step up, from (x, y) to (x, y + 1)) and 'R' (move one step right, from (x, y) to (x + 1, y)).
Fafa wants to know the number of silver coins he needs to pay to walk around the two kingdoms following the sequence S. Note that if Fafa visits a gate without moving from one kingdom to another, he pays no silver coins. Also assume that he doesn't pay at the gate at point (0, 0), i. e. he is initially on the side he needs.
Input
The first line of the input contains single integer n (1 β€ n β€ 105) β the number of moves in the walking sequence.
The second line contains a string S of length n consisting of the characters 'U' and 'R' describing the required moves. Fafa will follow the sequence S in order from left to right.
Output
On a single line, print one integer representing the number of silver coins Fafa needs to pay at the gates to follow the sequence S.
Examples
Input
1
U
Output
0
Input
6
RURUUR
Output
1
Input
7
URRRUUU
Output
2
Note
The figure below describes the third sample. The red arrows represent the sequence of moves Fafa will follow. The green gates represent the gates at which Fafa have to pay silver coins.
<image>
Submitted Solution:
```
#def fun(x,y):
n = int(input())
s = input()
x = []
temp_x = 0
y = []
temp_y = 0
ans = 0
slope = 0
if s[0] == "R":
slope = .5
else:
slope = 2
for i in range(0,len(s)):
if s[i] == "U":
temp_y +=1
elif s[i]=="R":
temp_x+=1
x.append(temp_x)
y.append(temp_y)
#if len(s)>2:
for i in range(1,n):
if x[i] !=0:
sl = (y[i]/x[i])
else:
sl = slope
if slope > 1 and sl <1:
slope = sl
ans+=1
elif slope<1 and sl>1:
slope = sl
ans+=1
print(ans)
``` | instruction | 0 | 102,651 | 15 | 205,302 |
Yes | output | 1 | 102,651 | 15 | 205,303 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Two neighboring kingdoms decided to build a wall between them with some gates to enable the citizens to go from one kingdom to another. Each time a citizen passes through a gate, he has to pay one silver coin.
The world can be represented by the first quadrant of a plane and the wall is built along the identity line (i.e. the line with the equation x = y). Any point below the wall belongs to the first kingdom while any point above the wall belongs to the second kingdom. There is a gate at any integer point on the line (i.e. at points (0, 0), (1, 1), (2, 2), ...). The wall and the gates do not belong to any of the kingdoms.
Fafa is at the gate at position (0, 0) and he wants to walk around in the two kingdoms. He knows the sequence S of moves he will do. This sequence is a string where each character represents a move. The two possible moves Fafa will do are 'U' (move one step up, from (x, y) to (x, y + 1)) and 'R' (move one step right, from (x, y) to (x + 1, y)).
Fafa wants to know the number of silver coins he needs to pay to walk around the two kingdoms following the sequence S. Note that if Fafa visits a gate without moving from one kingdom to another, he pays no silver coins. Also assume that he doesn't pay at the gate at point (0, 0), i. e. he is initially on the side he needs.
Input
The first line of the input contains single integer n (1 β€ n β€ 105) β the number of moves in the walking sequence.
The second line contains a string S of length n consisting of the characters 'U' and 'R' describing the required moves. Fafa will follow the sequence S in order from left to right.
Output
On a single line, print one integer representing the number of silver coins Fafa needs to pay at the gates to follow the sequence S.
Examples
Input
1
U
Output
0
Input
6
RURUUR
Output
1
Input
7
URRRUUU
Output
2
Note
The figure below describes the third sample. The red arrows represent the sequence of moves Fafa will follow. The green gates represent the gates at which Fafa have to pay silver coins.
<image>
Submitted Solution:
```
def zone(x, y):
return 0 if x == y else 1 if x > y else -1
def go(x, y, step):
return (x + 1, y) if step == 'R' else (x, y + 1)
def main():
n = int(input())
steps = input()
zones = [0, 0, 0]
(x, y) = (0, 0)
if n < 3:
print(0)
else:
(x, y) = go(x, y, steps[0])
zones[1] = zone(x, y)
(x, y) = go(x, y, steps[1])
zones[2] = zone(x, y)
paid = 0
for i in range(2, n):
(x, y) = go(x, y, steps[i])
zones[0] = zones[1]
zones[1] = zones[2]
zones[2] = zone(x, y)
if zones[1] == 0 and zones[0] != zones[2]:
paid += 1
print(paid)
if __name__ == '__main__':
main()
``` | instruction | 0 | 102,652 | 15 | 205,304 |
Yes | output | 1 | 102,652 | 15 | 205,305 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Two neighboring kingdoms decided to build a wall between them with some gates to enable the citizens to go from one kingdom to another. Each time a citizen passes through a gate, he has to pay one silver coin.
The world can be represented by the first quadrant of a plane and the wall is built along the identity line (i.e. the line with the equation x = y). Any point below the wall belongs to the first kingdom while any point above the wall belongs to the second kingdom. There is a gate at any integer point on the line (i.e. at points (0, 0), (1, 1), (2, 2), ...). The wall and the gates do not belong to any of the kingdoms.
Fafa is at the gate at position (0, 0) and he wants to walk around in the two kingdoms. He knows the sequence S of moves he will do. This sequence is a string where each character represents a move. The two possible moves Fafa will do are 'U' (move one step up, from (x, y) to (x, y + 1)) and 'R' (move one step right, from (x, y) to (x + 1, y)).
Fafa wants to know the number of silver coins he needs to pay to walk around the two kingdoms following the sequence S. Note that if Fafa visits a gate without moving from one kingdom to another, he pays no silver coins. Also assume that he doesn't pay at the gate at point (0, 0), i. e. he is initially on the side he needs.
Input
The first line of the input contains single integer n (1 β€ n β€ 105) β the number of moves in the walking sequence.
The second line contains a string S of length n consisting of the characters 'U' and 'R' describing the required moves. Fafa will follow the sequence S in order from left to right.
Output
On a single line, print one integer representing the number of silver coins Fafa needs to pay at the gates to follow the sequence S.
Examples
Input
1
U
Output
0
Input
6
RURUUR
Output
1
Input
7
URRRUUU
Output
2
Note
The figure below describes the third sample. The red arrows represent the sequence of moves Fafa will follow. The green gates represent the gates at which Fafa have to pay silver coins.
<image>
Submitted Solution:
```
n=int(input())
i=list(input())
x=0
y=0
cost=0
for index in range(len(i)-1):
if(i[index]=='U'):
y+=1
elif(i[index]=='R'):
x+=1
if(x==y):
if((i[index-1]=='U' and i[index+1]=='U') or (i[index-1]=='R' and i[index+1]=='R')):
cost+=1
print(cost)
``` | instruction | 0 | 102,653 | 15 | 205,306 |
No | output | 1 | 102,653 | 15 | 205,307 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Two neighboring kingdoms decided to build a wall between them with some gates to enable the citizens to go from one kingdom to another. Each time a citizen passes through a gate, he has to pay one silver coin.
The world can be represented by the first quadrant of a plane and the wall is built along the identity line (i.e. the line with the equation x = y). Any point below the wall belongs to the first kingdom while any point above the wall belongs to the second kingdom. There is a gate at any integer point on the line (i.e. at points (0, 0), (1, 1), (2, 2), ...). The wall and the gates do not belong to any of the kingdoms.
Fafa is at the gate at position (0, 0) and he wants to walk around in the two kingdoms. He knows the sequence S of moves he will do. This sequence is a string where each character represents a move. The two possible moves Fafa will do are 'U' (move one step up, from (x, y) to (x, y + 1)) and 'R' (move one step right, from (x, y) to (x + 1, y)).
Fafa wants to know the number of silver coins he needs to pay to walk around the two kingdoms following the sequence S. Note that if Fafa visits a gate without moving from one kingdom to another, he pays no silver coins. Also assume that he doesn't pay at the gate at point (0, 0), i. e. he is initially on the side he needs.
Input
The first line of the input contains single integer n (1 β€ n β€ 105) β the number of moves in the walking sequence.
The second line contains a string S of length n consisting of the characters 'U' and 'R' describing the required moves. Fafa will follow the sequence S in order from left to right.
Output
On a single line, print one integer representing the number of silver coins Fafa needs to pay at the gates to follow the sequence S.
Examples
Input
1
U
Output
0
Input
6
RURUUR
Output
1
Input
7
URRRUUU
Output
2
Note
The figure below describes the third sample. The red arrows represent the sequence of moves Fafa will follow. The green gates represent the gates at which Fafa have to pay silver coins.
<image>
Submitted Solution:
```
n=int(input())
count=0
s=input()
l1=0
l2=0
k=[0,0]
for i in s:
if(k[0] >= k[1]):
l1=0
if(k[0] < k[1]):
l1=1
if(i=='R'):
k[0]+=1
elif(i=='U'):
k[1]+=1
if(k[0] >= k[1]):
l2=0
if(k[0] < k[1]):
l2=1
if(l1!=l2):
count+=1
print(count-1)
``` | instruction | 0 | 102,654 | 15 | 205,308 |
No | output | 1 | 102,654 | 15 | 205,309 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Two neighboring kingdoms decided to build a wall between them with some gates to enable the citizens to go from one kingdom to another. Each time a citizen passes through a gate, he has to pay one silver coin.
The world can be represented by the first quadrant of a plane and the wall is built along the identity line (i.e. the line with the equation x = y). Any point below the wall belongs to the first kingdom while any point above the wall belongs to the second kingdom. There is a gate at any integer point on the line (i.e. at points (0, 0), (1, 1), (2, 2), ...). The wall and the gates do not belong to any of the kingdoms.
Fafa is at the gate at position (0, 0) and he wants to walk around in the two kingdoms. He knows the sequence S of moves he will do. This sequence is a string where each character represents a move. The two possible moves Fafa will do are 'U' (move one step up, from (x, y) to (x, y + 1)) and 'R' (move one step right, from (x, y) to (x + 1, y)).
Fafa wants to know the number of silver coins he needs to pay to walk around the two kingdoms following the sequence S. Note that if Fafa visits a gate without moving from one kingdom to another, he pays no silver coins. Also assume that he doesn't pay at the gate at point (0, 0), i. e. he is initially on the side he needs.
Input
The first line of the input contains single integer n (1 β€ n β€ 105) β the number of moves in the walking sequence.
The second line contains a string S of length n consisting of the characters 'U' and 'R' describing the required moves. Fafa will follow the sequence S in order from left to right.
Output
On a single line, print one integer representing the number of silver coins Fafa needs to pay at the gates to follow the sequence S.
Examples
Input
1
U
Output
0
Input
6
RURUUR
Output
1
Input
7
URRRUUU
Output
2
Note
The figure below describes the third sample. The red arrows represent the sequence of moves Fafa will follow. The green gates represent the gates at which Fafa have to pay silver coins.
<image>
Submitted Solution:
```
n=int(input())
li=input()
x=0
y=0
count=0
for i in li:
if i=="U":
y=y+1
else:
x=x+1
if x==y:
count+=1
print(count)
``` | instruction | 0 | 102,655 | 15 | 205,310 |
No | output | 1 | 102,655 | 15 | 205,311 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Two neighboring kingdoms decided to build a wall between them with some gates to enable the citizens to go from one kingdom to another. Each time a citizen passes through a gate, he has to pay one silver coin.
The world can be represented by the first quadrant of a plane and the wall is built along the identity line (i.e. the line with the equation x = y). Any point below the wall belongs to the first kingdom while any point above the wall belongs to the second kingdom. There is a gate at any integer point on the line (i.e. at points (0, 0), (1, 1), (2, 2), ...). The wall and the gates do not belong to any of the kingdoms.
Fafa is at the gate at position (0, 0) and he wants to walk around in the two kingdoms. He knows the sequence S of moves he will do. This sequence is a string where each character represents a move. The two possible moves Fafa will do are 'U' (move one step up, from (x, y) to (x, y + 1)) and 'R' (move one step right, from (x, y) to (x + 1, y)).
Fafa wants to know the number of silver coins he needs to pay to walk around the two kingdoms following the sequence S. Note that if Fafa visits a gate without moving from one kingdom to another, he pays no silver coins. Also assume that he doesn't pay at the gate at point (0, 0), i. e. he is initially on the side he needs.
Input
The first line of the input contains single integer n (1 β€ n β€ 105) β the number of moves in the walking sequence.
The second line contains a string S of length n consisting of the characters 'U' and 'R' describing the required moves. Fafa will follow the sequence S in order from left to right.
Output
On a single line, print one integer representing the number of silver coins Fafa needs to pay at the gates to follow the sequence S.
Examples
Input
1
U
Output
0
Input
6
RURUUR
Output
1
Input
7
URRRUUU
Output
2
Note
The figure below describes the third sample. The red arrows represent the sequence of moves Fafa will follow. The green gates represent the gates at which Fafa have to pay silver coins.
<image>
Submitted Solution:
```
l = []
n = int(input())
st = input()
for i in st:
l.append(i)
count = 0
x = 0
y = 0
for j in l:
if x == 0 and y == 0:
c = 0
if j == "R":
x += 1
c = 1
else:
y += 1
c = 1
count = count
f = j
elif j == "R":
x += 1
if x == y:
c = 0
count = count
f=j
elif j == f and c == 0:
count += 1
c = 1
f=j
elif j == f and c == 1:
count = count
c = 1
f=j
elif j == "U":
y += 1
if x == y:
c = 0
count = count
f=j
elif j != f and c == 1:
count = count
c = 1
f=j
elif j == f and c == 0:
count += 1
c = 1
f=j
elif j == f and c == 1:
count = count
c = 1
f=j
print(count)
``` | instruction | 0 | 102,656 | 15 | 205,312 |
No | output | 1 | 102,656 | 15 | 205,313 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a following process.
There is a platform with n columns. 1 Γ 1 squares are appearing one after another in some columns on this platform. If there are no squares in the column, a square will occupy the bottom row. Otherwise a square will appear at the top of the highest square of this column.
When all of the n columns have at least one square in them, the bottom row is being removed. You will receive 1 point for this, and all the squares left will fall down one row.
You task is to calculate the amount of points you will receive.
Input
The first line of input contain 2 integer numbers n and m (1 β€ n, m β€ 1000) β the length of the platform and the number of the squares.
The next line contain m integer numbers c_1, c_2, ..., c_m (1 β€ c_i β€ n) β column in which i-th square will appear.
Output
Print one integer β the amount of points you will receive.
Example
Input
3 9
1 1 2 2 2 3 1 2 3
Output
2
Note
In the sample case the answer will be equal to 2 because after the appearing of 6-th square will be removed one row (counts of the squares on the platform will look like [2~ 3~ 1], and after removing one row will be [1~ 2~ 0]).
After the appearing of 9-th square counts will be [2~ 3~ 1], and after removing one row it will look like [1~ 2~ 0].
So the answer will be equal to 2. | instruction | 0 | 102,662 | 15 | 205,324 |
Tags: implementation
Correct Solution:
```
input_line1 = input()
input_line2 = input()
tetris_list = input_line2.split(' ')
#print(tetris_list)
info_list = input_line1.split(' ')
col = int(info_list[0])
max = int(info_list[1])
#print(col,max)
out_list = []
for i in range(col):
out_list.append(tetris_list.count(str(i+1)))
print(min(out_list))
``` | output | 1 | 102,662 | 15 | 205,325 |
Provide a correct Python 3 solution for this coding contest problem.
There is a knight - the chess piece - at the origin (0, 0) of a two-dimensional grid.
When the knight is at the square (i, j), it can be moved to either (i+1,j+2) or (i+2, j+1).
In how many ways can the knight reach the square (X, Y)?
Find the number of ways modulo 10^9 + 7.
Constraints
* 1 \leq X \leq 10^6
* 1 \leq Y \leq 10^6
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
X Y
Output
Print the number of ways for the knight to reach (X, Y) from (0, 0), modulo 10^9 + 7.
Examples
Input
3 3
Output
2
Input
2 2
Output
0
Input
999999 999999
Output
151840682 | instruction | 0 | 102,720 | 15 | 205,440 |
"Correct Solution:
```
x,y = map(int,input().split())
n = 0
mod = 10**9+7
ans = 0
if not (x+y)%3:
n = (x+y)//3
x-=n
y-=n
if not x<0 or y<0:
ans = 1
for i in range(x):
ans = ans*(n-i)*pow(i+1,mod-2,mod)%mod
print(ans)
``` | output | 1 | 102,720 | 15 | 205,441 |
Provide a correct Python 3 solution for this coding contest problem.
There is a knight - the chess piece - at the origin (0, 0) of a two-dimensional grid.
When the knight is at the square (i, j), it can be moved to either (i+1,j+2) or (i+2, j+1).
In how many ways can the knight reach the square (X, Y)?
Find the number of ways modulo 10^9 + 7.
Constraints
* 1 \leq X \leq 10^6
* 1 \leq Y \leq 10^6
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
X Y
Output
Print the number of ways for the knight to reach (X, Y) from (0, 0), modulo 10^9 + 7.
Examples
Input
3 3
Output
2
Input
2 2
Output
0
Input
999999 999999
Output
151840682 | instruction | 0 | 102,721 | 15 | 205,442 |
"Correct Solution:
```
a,b=map(int,input().split())
aa=a
bb=b
x=0
y=0
while aa>0 and bb>0:
if aa>bb:
aa-=1
x+=1
else:
bb-=1
y+=1
aa-=1
bb-=1
if aa!=0 or bb!=0:
print(0)
exit()
mod=10**9+7
fac=[1]
for i in range(max(a,b)):
fac.append(fac[i]*(i+1)%mod)
x+=y
r=pow(fac[y]*fac[x-y]%mod,mod-2,mod)
print(fac[x]*r%mod)
``` | output | 1 | 102,721 | 15 | 205,443 |
Provide a correct Python 3 solution for this coding contest problem.
There is a knight - the chess piece - at the origin (0, 0) of a two-dimensional grid.
When the knight is at the square (i, j), it can be moved to either (i+1,j+2) or (i+2, j+1).
In how many ways can the knight reach the square (X, Y)?
Find the number of ways modulo 10^9 + 7.
Constraints
* 1 \leq X \leq 10^6
* 1 \leq Y \leq 10^6
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
X Y
Output
Print the number of ways for the knight to reach (X, Y) from (0, 0), modulo 10^9 + 7.
Examples
Input
3 3
Output
2
Input
2 2
Output
0
Input
999999 999999
Output
151840682 | instruction | 0 | 102,722 | 15 | 205,444 |
"Correct Solution:
```
X,Y = map(int, input().split())
m = (-X+2*Y)//3
n = (2*X-Y)//3
def combination(n, r, mod=10**9+7):
n1, r = n+1, min(r, n-r)
numer = denom = 1
for i in range(1, r+1):
numer = (numer*(n1-i)) % mod
denom = (denom*i) % mod
return numer * pow(denom, mod-2, mod) % mod
if (X+Y)%3 != 0 or m*n<0:
print(0)
else:
print(combination(m+n,n))
``` | output | 1 | 102,722 | 15 | 205,445 |
Provide a correct Python 3 solution for this coding contest problem.
There is a knight - the chess piece - at the origin (0, 0) of a two-dimensional grid.
When the knight is at the square (i, j), it can be moved to either (i+1,j+2) or (i+2, j+1).
In how many ways can the knight reach the square (X, Y)?
Find the number of ways modulo 10^9 + 7.
Constraints
* 1 \leq X \leq 10^6
* 1 \leq Y \leq 10^6
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
X Y
Output
Print the number of ways for the knight to reach (X, Y) from (0, 0), modulo 10^9 + 7.
Examples
Input
3 3
Output
2
Input
2 2
Output
0
Input
999999 999999
Output
151840682 | instruction | 0 | 102,723 | 15 | 205,446 |
"Correct Solution:
```
x,y = map(int,input().split())
m = 10**9+7
if not((x+y)%3== 0 and abs(x-y)<=(x+y)//3):
print(0);exit()
def comb(n,k):
#if 2 * k > n:
#k = n - k
a = 1
for i in range(1,k+1):
a *= (n - ( i - 1)) * pow(i,m-2,m)
a = a%m
return a
n = (x+y)//3
k = x-n
print(comb(n,k))
``` | output | 1 | 102,723 | 15 | 205,447 |
Provide a correct Python 3 solution for this coding contest problem.
There is a knight - the chess piece - at the origin (0, 0) of a two-dimensional grid.
When the knight is at the square (i, j), it can be moved to either (i+1,j+2) or (i+2, j+1).
In how many ways can the knight reach the square (X, Y)?
Find the number of ways modulo 10^9 + 7.
Constraints
* 1 \leq X \leq 10^6
* 1 \leq Y \leq 10^6
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
X Y
Output
Print the number of ways for the knight to reach (X, Y) from (0, 0), modulo 10^9 + 7.
Examples
Input
3 3
Output
2
Input
2 2
Output
0
Input
999999 999999
Output
151840682 | instruction | 0 | 102,724 | 15 | 205,448 |
"Correct Solution:
```
x,y = map(int,input().split())
ans = 0
mod = 10**9+7
if (x+y)%3 == 0:
m = (2*y-x)//3
n = (2*x-y)//3
if m >= 0 and n >= 0:
fac = [1]*(m+n+1)
for i in range(2,m+n+1):
fac[i] = fac[i-1]*i % mod
ans = fac[m+n]*(pow(fac[m],mod-2,mod)*pow(fac[n],mod-2,mod)%mod)%mod
print(ans)
``` | output | 1 | 102,724 | 15 | 205,449 |
Provide a correct Python 3 solution for this coding contest problem.
There is a knight - the chess piece - at the origin (0, 0) of a two-dimensional grid.
When the knight is at the square (i, j), it can be moved to either (i+1,j+2) or (i+2, j+1).
In how many ways can the knight reach the square (X, Y)?
Find the number of ways modulo 10^9 + 7.
Constraints
* 1 \leq X \leq 10^6
* 1 \leq Y \leq 10^6
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
X Y
Output
Print the number of ways for the knight to reach (X, Y) from (0, 0), modulo 10^9 + 7.
Examples
Input
3 3
Output
2
Input
2 2
Output
0
Input
999999 999999
Output
151840682 | instruction | 0 | 102,725 | 15 | 205,450 |
"Correct Solution:
```
x, y = map(int, input().split())
if (x + y) % 3 != 0:
print(0)
exit()
a = (x + y) // 3
x -= a
y -= a
if x < 0 or y < 0:
print(0)
exit()
mod = 10 ** 9 + 7
def combination(n, r):
x = 1
y = 1
for i in range(r):
x = x * (n - i) % mod
y = y * (r - i) % mod
return (x * pow(y, mod-2, mod)) % mod
print(combination(x+y, min(x, y)))
``` | output | 1 | 102,725 | 15 | 205,451 |
Provide a correct Python 3 solution for this coding contest problem.
There is a knight - the chess piece - at the origin (0, 0) of a two-dimensional grid.
When the knight is at the square (i, j), it can be moved to either (i+1,j+2) or (i+2, j+1).
In how many ways can the knight reach the square (X, Y)?
Find the number of ways modulo 10^9 + 7.
Constraints
* 1 \leq X \leq 10^6
* 1 \leq Y \leq 10^6
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
X Y
Output
Print the number of ways for the knight to reach (X, Y) from (0, 0), modulo 10^9 + 7.
Examples
Input
3 3
Output
2
Input
2 2
Output
0
Input
999999 999999
Output
151840682 | instruction | 0 | 102,726 | 15 | 205,452 |
"Correct Solution:
```
import math
X, Y = map(int, input().split())
if X > Y:
X, Y = Y, X
if ((2*X-Y) % 3 != 0) or (2*X-Y < 0):
print(0)
exit()
A = (2*X-Y)//3
B = Y-X+A
N = A+B
nu = 1
de = 1
for i in range(B+1, N+1):
nu = (nu * i) % (10 ** 9 + 7)
for i in range(1, A+1):
de = (de * i) % (10 ** 9 + 7)
print((nu * pow(de, -1, 10 ** 9 + 7) ) % (10 ** 9 + 7))
``` | output | 1 | 102,726 | 15 | 205,453 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.