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 a correct Python 3 solution for this coding contest problem.
There are N rabbits on a number line. The rabbits are conveniently numbered 1 through N. The coordinate of the initial position of rabbit i is x_i.
The rabbits will now take exercise on the number line, by performing sets described below. A set consists of M jumps. The j-th jump of a set is performed by rabbit a_j (2≤a_j≤N-1). For this jump, either rabbit a_j-1 or rabbit a_j+1 is chosen with equal probability (let the chosen rabbit be rabbit x), then rabbit a_j will jump to the symmetric point of its current position with respect to rabbit x.
The rabbits will perform K sets in succession. For each rabbit, find the expected value of the coordinate of its eventual position after K sets are performed.
Constraints
* 3≤N≤10^5
* x_i is an integer.
* |x_i|≤10^9
* 1≤M≤10^5
* 2≤a_j≤N-1
* 1≤K≤10^{18}
Input
The input is given from Standard Input in the following format:
N
x_1 x_2 ... x_N
M K
a_1 a_2 ... a_M
Output
Print N lines. The i-th line should contain the expected value of the coordinate of the eventual position of rabbit i after K sets are performed. The output is considered correct if the absolute or relative error is at most 10^{-9}.
Examples
Input
3
-1 0 2
1 1
2
Output
-1.0
1.0
2.0
Input
3
1 -1 1
2 2
2 2
Output
1.0
-1.0
1.0
Input
5
0 1 3 6 10
3 10
2 3 4
Output
0.0
3.0
7.0
8.0
10.0 | instruction | 0 | 41,959 | 15 | 83,918 |
"Correct Solution:
```
import sys
readline = sys.stdin.readline
def merge(A, B):
N = len(A)
res = [B[A[i]] for i in range(N)]
return res
N = int(readline())
X = list(map(int, readline().split()))
M, K = map(int, readline().split())
A = list(map(lambda x:int(x)-1, readline().split()))
Y = [x2 - x1 for x1, x2 in zip(X, X[1:])]
P = list(range(N))
for a in A:
P[a], P[a+1] = P[a+1], P[a]
stack = [P]
for _ in range(65):
stack.append(merge(stack[-1], stack[-1]))
E = list(range(N))
for i in range(K.bit_length()):
if (1<<i) & K:
E = merge(E, stack[i])
Ans = [0]*N
Ans[0] = X[0]
for i in range(1, N):
Ans[i] = Ans[i-1] + Y[E[i]-1]
print('\n'.join(map(str, Ans)))
``` | output | 1 | 41,959 | 15 | 83,919 |
Provide a correct Python 3 solution for this coding contest problem.
There are N rabbits on a number line. The rabbits are conveniently numbered 1 through N. The coordinate of the initial position of rabbit i is x_i.
The rabbits will now take exercise on the number line, by performing sets described below. A set consists of M jumps. The j-th jump of a set is performed by rabbit a_j (2≤a_j≤N-1). For this jump, either rabbit a_j-1 or rabbit a_j+1 is chosen with equal probability (let the chosen rabbit be rabbit x), then rabbit a_j will jump to the symmetric point of its current position with respect to rabbit x.
The rabbits will perform K sets in succession. For each rabbit, find the expected value of the coordinate of its eventual position after K sets are performed.
Constraints
* 3≤N≤10^5
* x_i is an integer.
* |x_i|≤10^9
* 1≤M≤10^5
* 2≤a_j≤N-1
* 1≤K≤10^{18}
Input
The input is given from Standard Input in the following format:
N
x_1 x_2 ... x_N
M K
a_1 a_2 ... a_M
Output
Print N lines. The i-th line should contain the expected value of the coordinate of the eventual position of rabbit i after K sets are performed. The output is considered correct if the absolute or relative error is at most 10^{-9}.
Examples
Input
3
-1 0 2
1 1
2
Output
-1.0
1.0
2.0
Input
3
1 -1 1
2 2
2 2
Output
1.0
-1.0
1.0
Input
5
0 1 3 6 10
3 10
2 3 4
Output
0.0
3.0
7.0
8.0
10.0 | instruction | 0 | 41,960 | 15 | 83,920 |
"Correct Solution:
```
N=int(input())
X=[int(i) for i in input().split()]
dX=[]
for i in range(N-1):
dX.append(X[i+1]-X[i])
M,K=map(int,input().split())
A=[int(i)-2 for i in input().split()]
Swap=[list(range(N-1)) for i in range(61)]
for a in A:
Swap[0][a],Swap[0][a+1]=Swap[0][a+1],Swap[0][a]
for k in range(60):
for i in range(N-1):
Swap[k+1][i]=Swap[k][Swap[k][i]]
C=list(range(N-1))
for k in range(61)[::-1]:
if K&(1<<k):
for i in range(N-1):
C[i]=Swap[k][C[i]]
new_dX=[0]*(N-1)
for i in range(N-1):
new_dX[i]=dX[C[i]]
S=X[0]
print(X[0])
for i in range(N-1):
S+=new_dX[i]
print(S)
``` | output | 1 | 41,960 | 15 | 83,921 |
Provide a correct Python 3 solution for this coding contest problem.
jfen
There is a one-person game to play on the H × W board. This game is a game to move 0 or 1 balls in each cell. You were playing this game and found it difficult to move the ball accurately from cell to cell because the ball is so round. So you decided to make a robot that would move the ball as instructed. Here, the notation (y, x) is used to represent the cell. This represents the cell in the xth column of the yth row.
Instructions to the robot are given by the four integers a, b, c, d. This means moving the ball at (a, b) to (c, d). At this time, it is guaranteed that the ball exists in (a, b) and does not exist in (c, d).
The state of the board is expressed by the following notation called "jfen".
[Data in the first line] / [Data in the second line] /.../ [Data in the H line]
This notation is a slash-separated concatenation of data representing each line on the board. The data in each row is represented by a character string, and the state of the cells in the 1st to Wth columns is described in order from the left. This string is represented by a number and the letter'b', where the integer represented by the number represents the number of consecutive blank cells and'b' represents the cell in which the ball resides. Here, integers must not be consecutive in the data of each row. Also, the sum of the integers written in the data of each line and the sum of the number of'b'are always W.
As an example, consider the following board surface condition. A blank cell is represented by a'.', And a cell in which the ball exists is represented by a'b'. The j character from the left of the i-th row in this example represents the state of the cell in the j-th column of the i-th row on the board.
....
.b.b
....
The above board is expressed in jfen as follows.
4 / 1b1b / 4
Create a program that outputs the board surface after the robot moves the ball when the robot is given the current board surface state and a command to move one ball. At this time, output the board surface in jfen notation.
Input
The input consists of multiple datasets. Each dataset has the following format.
> S
> a b c d
Each dataset consists of two lines, and the first line is given the jfen-formatted string S, which represents the state of the board. Here, the size of the board satisfies 2 ≤ W and H ≤ 9. Instructions to the robot are given to the following lines. This represents an instruction to move the ball at (a, b) to (c, d). The end of the input is represented by #.
Output
The output is one line of character string that expresses the state of the board after executing the instruction for each data set in jfen notation. There must be no other characters on the output line.
Sample Input
b1 / 1b
1 1 1 2
b5 / bbbbbb
2 4 1 4
b2b2b / 7
1 4 2 4
Output for Sample Input
1b / 1b
b2b2 / bbb1bb
b5b / 3b3
The initial state of the first input is as follows.
b.
.b
Since the ball of (1,1) is moved to (1,2), the board surface after the command is as follows.
.b
.b
Example
Input
b1/1b
1 1 1 2
b5/bbbbbb
2 4 1 4
b2b2b/7
1 4 2 4
#
Output
1b/1b
b2b2/bbb1bb
b5b/3b3 | instruction | 0 | 42,044 | 15 | 84,088 |
"Correct Solution:
```
#!/usr/bin/env python3
while True:
s = input()
if s == '#':
break
a, b, c, d = map(lambda x: int(x) - 1, input().split())
tb = []
for i, x in enumerate(s.split('/')):
tb.append([])
for ch in x:
if ch == 'b':
tb[i].append('b')
else:
tb[i] += list('.' * int(ch))
tb[a][b] = '.'
tb[c][d] = 'b'
ans = []
for i in range(len(tb)):
tmp = ''
cnt = 0
for j in range(len(tb[i])):
if tb[i][j] == 'b':
if cnt > 0:
tmp += str(cnt)
cnt = 0
tmp += 'b'
else:
cnt += 1
if cnt > 0:
tmp += str(cnt)
ans.append(tmp)
print('/'.join(ans))
``` | output | 1 | 42,044 | 15 | 84,089 |
Provide a correct Python 3 solution for this coding contest problem.
jfen
There is a one-person game to play on the H × W board. This game is a game to move 0 or 1 balls in each cell. You were playing this game and found it difficult to move the ball accurately from cell to cell because the ball is so round. So you decided to make a robot that would move the ball as instructed. Here, the notation (y, x) is used to represent the cell. This represents the cell in the xth column of the yth row.
Instructions to the robot are given by the four integers a, b, c, d. This means moving the ball at (a, b) to (c, d). At this time, it is guaranteed that the ball exists in (a, b) and does not exist in (c, d).
The state of the board is expressed by the following notation called "jfen".
[Data in the first line] / [Data in the second line] /.../ [Data in the H line]
This notation is a slash-separated concatenation of data representing each line on the board. The data in each row is represented by a character string, and the state of the cells in the 1st to Wth columns is described in order from the left. This string is represented by a number and the letter'b', where the integer represented by the number represents the number of consecutive blank cells and'b' represents the cell in which the ball resides. Here, integers must not be consecutive in the data of each row. Also, the sum of the integers written in the data of each line and the sum of the number of'b'are always W.
As an example, consider the following board surface condition. A blank cell is represented by a'.', And a cell in which the ball exists is represented by a'b'. The j character from the left of the i-th row in this example represents the state of the cell in the j-th column of the i-th row on the board.
....
.b.b
....
The above board is expressed in jfen as follows.
4 / 1b1b / 4
Create a program that outputs the board surface after the robot moves the ball when the robot is given the current board surface state and a command to move one ball. At this time, output the board surface in jfen notation.
Input
The input consists of multiple datasets. Each dataset has the following format.
> S
> a b c d
Each dataset consists of two lines, and the first line is given the jfen-formatted string S, which represents the state of the board. Here, the size of the board satisfies 2 ≤ W and H ≤ 9. Instructions to the robot are given to the following lines. This represents an instruction to move the ball at (a, b) to (c, d). The end of the input is represented by #.
Output
The output is one line of character string that expresses the state of the board after executing the instruction for each data set in jfen notation. There must be no other characters on the output line.
Sample Input
b1 / 1b
1 1 1 2
b5 / bbbbbb
2 4 1 4
b2b2b / 7
1 4 2 4
Output for Sample Input
1b / 1b
b2b2 / bbb1bb
b5b / 3b3
The initial state of the first input is as follows.
b.
.b
Since the ball of (1,1) is moved to (1,2), the board surface after the command is as follows.
.b
.b
Example
Input
b1/1b
1 1 1 2
b5/bbbbbb
2 4 1 4
b2b2b/7
1 4 2 4
#
Output
1b/1b
b2b2/bbb1bb
b5b/3b3 | instruction | 0 | 42,045 | 15 | 84,090 |
"Correct Solution:
```
def j2b(S):
rows = S.split("/")
for i, row in enumerate(rows):
cand = []
for s in row:
if s == "b":
cand.append(s)
else:
cand.extend(["."] * int(s))
rows[i] = cand
return rows
def b2j(rows):
ret = []
for row in rows:
r = []
c = 0
for s in row:
if s == "b":
if c:
r.append(str(c))
r.append(s)
c = 0
else:
c += 1
if c:
r.append(str(c))
ret.append(''.join(r))
return '/'.join(ret)
while True:
S = input()
if S == "#":
break
rows = j2b(S)
a, b, c, d = [int(x) - 1 for x in input().split()]
rows[a][b], rows[c][d] = rows[c][d], rows[a][b]
print(b2j(rows))
``` | output | 1 | 42,045 | 15 | 84,091 |
Provide a correct Python 3 solution for this coding contest problem.
jfen
There is a one-person game to play on the H × W board. This game is a game to move 0 or 1 balls in each cell. You were playing this game and found it difficult to move the ball accurately from cell to cell because the ball is so round. So you decided to make a robot that would move the ball as instructed. Here, the notation (y, x) is used to represent the cell. This represents the cell in the xth column of the yth row.
Instructions to the robot are given by the four integers a, b, c, d. This means moving the ball at (a, b) to (c, d). At this time, it is guaranteed that the ball exists in (a, b) and does not exist in (c, d).
The state of the board is expressed by the following notation called "jfen".
[Data in the first line] / [Data in the second line] /.../ [Data in the H line]
This notation is a slash-separated concatenation of data representing each line on the board. The data in each row is represented by a character string, and the state of the cells in the 1st to Wth columns is described in order from the left. This string is represented by a number and the letter'b', where the integer represented by the number represents the number of consecutive blank cells and'b' represents the cell in which the ball resides. Here, integers must not be consecutive in the data of each row. Also, the sum of the integers written in the data of each line and the sum of the number of'b'are always W.
As an example, consider the following board surface condition. A blank cell is represented by a'.', And a cell in which the ball exists is represented by a'b'. The j character from the left of the i-th row in this example represents the state of the cell in the j-th column of the i-th row on the board.
....
.b.b
....
The above board is expressed in jfen as follows.
4 / 1b1b / 4
Create a program that outputs the board surface after the robot moves the ball when the robot is given the current board surface state and a command to move one ball. At this time, output the board surface in jfen notation.
Input
The input consists of multiple datasets. Each dataset has the following format.
> S
> a b c d
Each dataset consists of two lines, and the first line is given the jfen-formatted string S, which represents the state of the board. Here, the size of the board satisfies 2 ≤ W and H ≤ 9. Instructions to the robot are given to the following lines. This represents an instruction to move the ball at (a, b) to (c, d). The end of the input is represented by #.
Output
The output is one line of character string that expresses the state of the board after executing the instruction for each data set in jfen notation. There must be no other characters on the output line.
Sample Input
b1 / 1b
1 1 1 2
b5 / bbbbbb
2 4 1 4
b2b2b / 7
1 4 2 4
Output for Sample Input
1b / 1b
b2b2 / bbb1bb
b5b / 3b3
The initial state of the first input is as follows.
b.
.b
Since the ball of (1,1) is moved to (1,2), the board surface after the command is as follows.
.b
.b
Example
Input
b1/1b
1 1 1 2
b5/bbbbbb
2 4 1 4
b2b2b/7
1 4 2 4
#
Output
1b/1b
b2b2/bbb1bb
b5b/3b3 | instruction | 0 | 42,046 | 15 | 84,092 |
"Correct Solution:
```
def main():
S = input().split("/")
if S[0] == "#":
return
for s in range(len(S)):
for i in range(10):
S[s]= S[s].replace(str(i),"."*i)
a,b,c,d = map(int,input().split())
S[a-1] = S[a-1][:b-1]+"."+S[a-1][b:]
S[c-1] = S[c-1][:d-1]+"b"+S[c-1][d:]
for s in range(len(S)):
ref = ""
temp = 0
for i in S[s]:
if i == ".":
temp += 1
else:
ref += (str(temp) if temp is not 0 else "") + "b"
temp = 0
S[s] = ref + (str(temp) if temp is not 0 else "")
print("/".join(S))
main()
return
main()
``` | output | 1 | 42,046 | 15 | 84,093 |
Provide a correct Python 3 solution for this coding contest problem.
jfen
There is a one-person game to play on the H × W board. This game is a game to move 0 or 1 balls in each cell. You were playing this game and found it difficult to move the ball accurately from cell to cell because the ball is so round. So you decided to make a robot that would move the ball as instructed. Here, the notation (y, x) is used to represent the cell. This represents the cell in the xth column of the yth row.
Instructions to the robot are given by the four integers a, b, c, d. This means moving the ball at (a, b) to (c, d). At this time, it is guaranteed that the ball exists in (a, b) and does not exist in (c, d).
The state of the board is expressed by the following notation called "jfen".
[Data in the first line] / [Data in the second line] /.../ [Data in the H line]
This notation is a slash-separated concatenation of data representing each line on the board. The data in each row is represented by a character string, and the state of the cells in the 1st to Wth columns is described in order from the left. This string is represented by a number and the letter'b', where the integer represented by the number represents the number of consecutive blank cells and'b' represents the cell in which the ball resides. Here, integers must not be consecutive in the data of each row. Also, the sum of the integers written in the data of each line and the sum of the number of'b'are always W.
As an example, consider the following board surface condition. A blank cell is represented by a'.', And a cell in which the ball exists is represented by a'b'. The j character from the left of the i-th row in this example represents the state of the cell in the j-th column of the i-th row on the board.
....
.b.b
....
The above board is expressed in jfen as follows.
4 / 1b1b / 4
Create a program that outputs the board surface after the robot moves the ball when the robot is given the current board surface state and a command to move one ball. At this time, output the board surface in jfen notation.
Input
The input consists of multiple datasets. Each dataset has the following format.
> S
> a b c d
Each dataset consists of two lines, and the first line is given the jfen-formatted string S, which represents the state of the board. Here, the size of the board satisfies 2 ≤ W and H ≤ 9. Instructions to the robot are given to the following lines. This represents an instruction to move the ball at (a, b) to (c, d). The end of the input is represented by #.
Output
The output is one line of character string that expresses the state of the board after executing the instruction for each data set in jfen notation. There must be no other characters on the output line.
Sample Input
b1 / 1b
1 1 1 2
b5 / bbbbbb
2 4 1 4
b2b2b / 7
1 4 2 4
Output for Sample Input
1b / 1b
b2b2 / bbb1bb
b5b / 3b3
The initial state of the first input is as follows.
b.
.b
Since the ball of (1,1) is moved to (1,2), the board surface after the command is as follows.
.b
.b
Example
Input
b1/1b
1 1 1 2
b5/bbbbbb
2 4 1 4
b2b2b/7
1 4 2 4
#
Output
1b/1b
b2b2/bbb1bb
b5b/3b3 | instruction | 0 | 42,047 | 15 | 84,094 |
"Correct Solution:
```
while True:
S = input()
if S == "#":
break
a, b, c, d = map(int, input().split())
hasBall = [[False for _ in range(10)] for _ in range(10)]
rows = S.split('/')
H = len(rows)
for h, row in enumerate(rows, start=1):
cur = 1
colsize = 0
for ch in row:
if ch == 'b':
hasBall[h][cur] = True
colsize += 1
cur += 1
else:
colsize += int(ch)
cur += int(ch)
W = colsize
# for h in range(H+2):
# for w in range(W+2):
# print(hasBall[h][w], end="")
# print()
hasBall[a][b] = False
hasBall[c][d] = True
rows = []
for h in range(1, H+1):
streak = 0
row = ""
for w in range(1, W+1):
if hasBall[h][w]:
if streak:
row += str(streak)
streak = 0
row += 'b'
else:
streak += 1
if streak:
row += str(streak)
rows.append(row)
# for h in range(H+2):
# for w in range(W+2):
# print(hasBall[h][w], end="")
# print()
print("/".join(rows))
``` | output | 1 | 42,047 | 15 | 84,095 |
Provide a correct Python 3 solution for this coding contest problem.
jfen
There is a one-person game to play on the H × W board. This game is a game to move 0 or 1 balls in each cell. You were playing this game and found it difficult to move the ball accurately from cell to cell because the ball is so round. So you decided to make a robot that would move the ball as instructed. Here, the notation (y, x) is used to represent the cell. This represents the cell in the xth column of the yth row.
Instructions to the robot are given by the four integers a, b, c, d. This means moving the ball at (a, b) to (c, d). At this time, it is guaranteed that the ball exists in (a, b) and does not exist in (c, d).
The state of the board is expressed by the following notation called "jfen".
[Data in the first line] / [Data in the second line] /.../ [Data in the H line]
This notation is a slash-separated concatenation of data representing each line on the board. The data in each row is represented by a character string, and the state of the cells in the 1st to Wth columns is described in order from the left. This string is represented by a number and the letter'b', where the integer represented by the number represents the number of consecutive blank cells and'b' represents the cell in which the ball resides. Here, integers must not be consecutive in the data of each row. Also, the sum of the integers written in the data of each line and the sum of the number of'b'are always W.
As an example, consider the following board surface condition. A blank cell is represented by a'.', And a cell in which the ball exists is represented by a'b'. The j character from the left of the i-th row in this example represents the state of the cell in the j-th column of the i-th row on the board.
....
.b.b
....
The above board is expressed in jfen as follows.
4 / 1b1b / 4
Create a program that outputs the board surface after the robot moves the ball when the robot is given the current board surface state and a command to move one ball. At this time, output the board surface in jfen notation.
Input
The input consists of multiple datasets. Each dataset has the following format.
> S
> a b c d
Each dataset consists of two lines, and the first line is given the jfen-formatted string S, which represents the state of the board. Here, the size of the board satisfies 2 ≤ W and H ≤ 9. Instructions to the robot are given to the following lines. This represents an instruction to move the ball at (a, b) to (c, d). The end of the input is represented by #.
Output
The output is one line of character string that expresses the state of the board after executing the instruction for each data set in jfen notation. There must be no other characters on the output line.
Sample Input
b1 / 1b
1 1 1 2
b5 / bbbbbb
2 4 1 4
b2b2b / 7
1 4 2 4
Output for Sample Input
1b / 1b
b2b2 / bbb1bb
b5b / 3b3
The initial state of the first input is as follows.
b.
.b
Since the ball of (1,1) is moved to (1,2), the board surface after the command is as follows.
.b
.b
Example
Input
b1/1b
1 1 1 2
b5/bbbbbb
2 4 1 4
b2b2b/7
1 4 2 4
#
Output
1b/1b
b2b2/bbb1bb
b5b/3b3 | instruction | 0 | 42,048 | 15 | 84,096 |
"Correct Solution:
```
while 1:
s = input()
if s == '#':
break
M = []
for l in s.split('/'):
num = 0
tmp = []
for c in l:
if c == 'b':
if num > 0:
tmp.extend([0]*num)
tmp.append(1)
num = 0
else:
num = 10*num + int(c)
if num > 0:
tmp.extend([0]*num)
M.append(tmp)
a, b, c, d = map(int, input().split())
assert M[a-1][b-1] == 1
M[a-1][b-1] = 0
assert M[c-1][d-1] == 0
M[c-1][d-1] = 1
ans = []
for l in M:
tmp = ""
cnt = 0
for c in l:
if c:
if cnt > 0:
tmp += str(cnt)
cnt = 0
tmp += 'b'
else:
cnt += 1
if cnt > 0:
tmp += str(cnt)
ans.append(tmp)
print("/".join(ans))
``` | output | 1 | 42,048 | 15 | 84,097 |
Provide a correct Python 3 solution for this coding contest problem.
jfen
There is a one-person game to play on the H × W board. This game is a game to move 0 or 1 balls in each cell. You were playing this game and found it difficult to move the ball accurately from cell to cell because the ball is so round. So you decided to make a robot that would move the ball as instructed. Here, the notation (y, x) is used to represent the cell. This represents the cell in the xth column of the yth row.
Instructions to the robot are given by the four integers a, b, c, d. This means moving the ball at (a, b) to (c, d). At this time, it is guaranteed that the ball exists in (a, b) and does not exist in (c, d).
The state of the board is expressed by the following notation called "jfen".
[Data in the first line] / [Data in the second line] /.../ [Data in the H line]
This notation is a slash-separated concatenation of data representing each line on the board. The data in each row is represented by a character string, and the state of the cells in the 1st to Wth columns is described in order from the left. This string is represented by a number and the letter'b', where the integer represented by the number represents the number of consecutive blank cells and'b' represents the cell in which the ball resides. Here, integers must not be consecutive in the data of each row. Also, the sum of the integers written in the data of each line and the sum of the number of'b'are always W.
As an example, consider the following board surface condition. A blank cell is represented by a'.', And a cell in which the ball exists is represented by a'b'. The j character from the left of the i-th row in this example represents the state of the cell in the j-th column of the i-th row on the board.
....
.b.b
....
The above board is expressed in jfen as follows.
4 / 1b1b / 4
Create a program that outputs the board surface after the robot moves the ball when the robot is given the current board surface state and a command to move one ball. At this time, output the board surface in jfen notation.
Input
The input consists of multiple datasets. Each dataset has the following format.
> S
> a b c d
Each dataset consists of two lines, and the first line is given the jfen-formatted string S, which represents the state of the board. Here, the size of the board satisfies 2 ≤ W and H ≤ 9. Instructions to the robot are given to the following lines. This represents an instruction to move the ball at (a, b) to (c, d). The end of the input is represented by #.
Output
The output is one line of character string that expresses the state of the board after executing the instruction for each data set in jfen notation. There must be no other characters on the output line.
Sample Input
b1 / 1b
1 1 1 2
b5 / bbbbbb
2 4 1 4
b2b2b / 7
1 4 2 4
Output for Sample Input
1b / 1b
b2b2 / bbb1bb
b5b / 3b3
The initial state of the first input is as follows.
b.
.b
Since the ball of (1,1) is moved to (1,2), the board surface after the command is as follows.
.b
.b
Example
Input
b1/1b
1 1 1 2
b5/bbbbbb
2 4 1 4
b2b2b/7
1 4 2 4
#
Output
1b/1b
b2b2/bbb1bb
b5b/3b3 | instruction | 0 | 42,049 | 15 | 84,098 |
"Correct Solution:
```
now=input()
while now!="#":
order_raw = input()
order = [int(s)-1 for s in order_raw.split(' ')]
box = [[]]
for n in now:
if n=='/':
box.append([])
elif n=='b':
box[-1].append('b')
else:
for _ in range(int(n)):
box[-1].append('.')
box[order[0]][order[1]] = '.'
box[order[2]][order[3]] = 'b'
res=""
index=0
for bo in box:
for b in bo:
if b=='b':
if index>0:
res+=str(index)
index=0
res+="b"
else:
index+=1
if index>0:
res+=str(index)
index=0
res+="/"
print(res[:-1])
now=input()
``` | output | 1 | 42,049 | 15 | 84,099 |
Provide a correct Python 3 solution for this coding contest problem.
jfen
There is a one-person game to play on the H × W board. This game is a game to move 0 or 1 balls in each cell. You were playing this game and found it difficult to move the ball accurately from cell to cell because the ball is so round. So you decided to make a robot that would move the ball as instructed. Here, the notation (y, x) is used to represent the cell. This represents the cell in the xth column of the yth row.
Instructions to the robot are given by the four integers a, b, c, d. This means moving the ball at (a, b) to (c, d). At this time, it is guaranteed that the ball exists in (a, b) and does not exist in (c, d).
The state of the board is expressed by the following notation called "jfen".
[Data in the first line] / [Data in the second line] /.../ [Data in the H line]
This notation is a slash-separated concatenation of data representing each line on the board. The data in each row is represented by a character string, and the state of the cells in the 1st to Wth columns is described in order from the left. This string is represented by a number and the letter'b', where the integer represented by the number represents the number of consecutive blank cells and'b' represents the cell in which the ball resides. Here, integers must not be consecutive in the data of each row. Also, the sum of the integers written in the data of each line and the sum of the number of'b'are always W.
As an example, consider the following board surface condition. A blank cell is represented by a'.', And a cell in which the ball exists is represented by a'b'. The j character from the left of the i-th row in this example represents the state of the cell in the j-th column of the i-th row on the board.
....
.b.b
....
The above board is expressed in jfen as follows.
4 / 1b1b / 4
Create a program that outputs the board surface after the robot moves the ball when the robot is given the current board surface state and a command to move one ball. At this time, output the board surface in jfen notation.
Input
The input consists of multiple datasets. Each dataset has the following format.
> S
> a b c d
Each dataset consists of two lines, and the first line is given the jfen-formatted string S, which represents the state of the board. Here, the size of the board satisfies 2 ≤ W and H ≤ 9. Instructions to the robot are given to the following lines. This represents an instruction to move the ball at (a, b) to (c, d). The end of the input is represented by #.
Output
The output is one line of character string that expresses the state of the board after executing the instruction for each data set in jfen notation. There must be no other characters on the output line.
Sample Input
b1 / 1b
1 1 1 2
b5 / bbbbbb
2 4 1 4
b2b2b / 7
1 4 2 4
Output for Sample Input
1b / 1b
b2b2 / bbb1bb
b5b / 3b3
The initial state of the first input is as follows.
b.
.b
Since the ball of (1,1) is moved to (1,2), the board surface after the command is as follows.
.b
.b
Example
Input
b1/1b
1 1 1 2
b5/bbbbbb
2 4 1 4
b2b2b/7
1 4 2 4
#
Output
1b/1b
b2b2/bbb1bb
b5b/3b3 | instruction | 0 | 42,050 | 15 | 84,100 |
"Correct Solution:
```
while True:
st = list(input().split("/"))
if st == ["#"]:
break
a, b, c, d = map(int, input().split())
s=[]
for i in range(len(st)):
str=[]
for ele in st[i]:
if ele=="b":
str.append("b")
else:
for _ in range(int(ele)):
str.append(".")
s.append(str)
s[a-1][b-1] = "."
s[c-1][d-1] = "b"
'''
print(s)
ans=""
for i in range(len(s)):
count = 0
for ele in s[i]:
if ele=="b":
sr="{}".format(count)
ans=ans+sr
ans+="b"
else:
count+=1
ans+="/"
print(ans)
'''
ans = []
for i in range(len(s)):
sr = ""
c = 0
for j in range(len(s[i])):
if s[i][j] == 'b':
if c != 0:
sr += "{}".format(c)
sr += "b"
c=0
elif s[i][j] == '.':
c += 1
'''
if j==len(s[i])-1:
if s[i][j] == '.' and c != 0:
sr += "{}".format(c)
'''
if c!=0:
sr+="{}".format(c)
ans.append(sr)
ass = "/".join(ans)
print(ass[:])
``` | output | 1 | 42,050 | 15 | 84,101 |
Provide a correct Python 3 solution for this coding contest problem.
jfen
There is a one-person game to play on the H × W board. This game is a game to move 0 or 1 balls in each cell. You were playing this game and found it difficult to move the ball accurately from cell to cell because the ball is so round. So you decided to make a robot that would move the ball as instructed. Here, the notation (y, x) is used to represent the cell. This represents the cell in the xth column of the yth row.
Instructions to the robot are given by the four integers a, b, c, d. This means moving the ball at (a, b) to (c, d). At this time, it is guaranteed that the ball exists in (a, b) and does not exist in (c, d).
The state of the board is expressed by the following notation called "jfen".
[Data in the first line] / [Data in the second line] /.../ [Data in the H line]
This notation is a slash-separated concatenation of data representing each line on the board. The data in each row is represented by a character string, and the state of the cells in the 1st to Wth columns is described in order from the left. This string is represented by a number and the letter'b', where the integer represented by the number represents the number of consecutive blank cells and'b' represents the cell in which the ball resides. Here, integers must not be consecutive in the data of each row. Also, the sum of the integers written in the data of each line and the sum of the number of'b'are always W.
As an example, consider the following board surface condition. A blank cell is represented by a'.', And a cell in which the ball exists is represented by a'b'. The j character from the left of the i-th row in this example represents the state of the cell in the j-th column of the i-th row on the board.
....
.b.b
....
The above board is expressed in jfen as follows.
4 / 1b1b / 4
Create a program that outputs the board surface after the robot moves the ball when the robot is given the current board surface state and a command to move one ball. At this time, output the board surface in jfen notation.
Input
The input consists of multiple datasets. Each dataset has the following format.
> S
> a b c d
Each dataset consists of two lines, and the first line is given the jfen-formatted string S, which represents the state of the board. Here, the size of the board satisfies 2 ≤ W and H ≤ 9. Instructions to the robot are given to the following lines. This represents an instruction to move the ball at (a, b) to (c, d). The end of the input is represented by #.
Output
The output is one line of character string that expresses the state of the board after executing the instruction for each data set in jfen notation. There must be no other characters on the output line.
Sample Input
b1 / 1b
1 1 1 2
b5 / bbbbbb
2 4 1 4
b2b2b / 7
1 4 2 4
Output for Sample Input
1b / 1b
b2b2 / bbb1bb
b5b / 3b3
The initial state of the first input is as follows.
b.
.b
Since the ball of (1,1) is moved to (1,2), the board surface after the command is as follows.
.b
.b
Example
Input
b1/1b
1 1 1 2
b5/bbbbbb
2 4 1 4
b2b2b/7
1 4 2 4
#
Output
1b/1b
b2b2/bbb1bb
b5b/3b3 | instruction | 0 | 42,051 | 15 | 84,102 |
"Correct Solution:
```
while 1:
s=input()
if '#' in s:break
p=0
e=[[]*2 for _ in range(10)]
for x in s:
if x=='b':e[p]+=['b']
elif x=='/':p+=1
else:e[p]+='.'*int(x)
ans=''
a,b,c,d=map(int,input().split())
e[a-1][b-1],e[c-1][d-1]=e[c-1][d-1],e[a-1][b-1]
for i in range(p+1):
if i:ans+='/'
a=0
for j in e[i]:
if j=='b':
if a:ans+=str(a)
ans+='b'
a=0
else:a+=1
if a:ans+=str(a)
print(ans)
``` | output | 1 | 42,051 | 15 | 84,103 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
jfen
There is a one-person game to play on the H × W board. This game is a game to move 0 or 1 balls in each cell. You were playing this game and found it difficult to move the ball accurately from cell to cell because the ball is so round. So you decided to make a robot that would move the ball as instructed. Here, the notation (y, x) is used to represent the cell. This represents the cell in the xth column of the yth row.
Instructions to the robot are given by the four integers a, b, c, d. This means moving the ball at (a, b) to (c, d). At this time, it is guaranteed that the ball exists in (a, b) and does not exist in (c, d).
The state of the board is expressed by the following notation called "jfen".
[Data in the first line] / [Data in the second line] /.../ [Data in the H line]
This notation is a slash-separated concatenation of data representing each line on the board. The data in each row is represented by a character string, and the state of the cells in the 1st to Wth columns is described in order from the left. This string is represented by a number and the letter'b', where the integer represented by the number represents the number of consecutive blank cells and'b' represents the cell in which the ball resides. Here, integers must not be consecutive in the data of each row. Also, the sum of the integers written in the data of each line and the sum of the number of'b'are always W.
As an example, consider the following board surface condition. A blank cell is represented by a'.', And a cell in which the ball exists is represented by a'b'. The j character from the left of the i-th row in this example represents the state of the cell in the j-th column of the i-th row on the board.
....
.b.b
....
The above board is expressed in jfen as follows.
4 / 1b1b / 4
Create a program that outputs the board surface after the robot moves the ball when the robot is given the current board surface state and a command to move one ball. At this time, output the board surface in jfen notation.
Input
The input consists of multiple datasets. Each dataset has the following format.
> S
> a b c d
Each dataset consists of two lines, and the first line is given the jfen-formatted string S, which represents the state of the board. Here, the size of the board satisfies 2 ≤ W and H ≤ 9. Instructions to the robot are given to the following lines. This represents an instruction to move the ball at (a, b) to (c, d). The end of the input is represented by #.
Output
The output is one line of character string that expresses the state of the board after executing the instruction for each data set in jfen notation. There must be no other characters on the output line.
Sample Input
b1 / 1b
1 1 1 2
b5 / bbbbbb
2 4 1 4
b2b2b / 7
1 4 2 4
Output for Sample Input
1b / 1b
b2b2 / bbb1bb
b5b / 3b3
The initial state of the first input is as follows.
b.
.b
Since the ball of (1,1) is moved to (1,2), the board surface after the command is as follows.
.b
.b
Example
Input
b1/1b
1 1 1 2
b5/bbbbbb
2 4 1 4
b2b2b/7
1 4 2 4
#
Output
1b/1b
b2b2/bbb1bb
b5b/3b3
Submitted Solution:
```
def parse_line(line):
ret = []
for c in line:
if c == "b":
ret.append("b")
else:
for _ in range(int(c)):
ret.append(".")
return ret
def parse_jfen(s):
return list(map(parse_line, s.split("/")))
def to_jfen(mp):
ret = ""
cnt = 0
for line in mp:
cnt = 0
for c in line:
if c == "b":
if cnt != 0:
ret += str(cnt)
cnt = 0
ret += "b"
else:
cnt += 1
if cnt != 0:
ret += str(cnt)
ret += "/"
return ret[:-1]
while True:
s = input()
if s == "#":break
mp = parse_jfen(s)
a, b, c, d = map(int, input().split())
mp[a - 1][b - 1] = "."
mp[c - 1][d - 1] = "b"
print(to_jfen(mp))
``` | instruction | 0 | 42,052 | 15 | 84,104 |
Yes | output | 1 | 42,052 | 15 | 84,105 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
jfen
There is a one-person game to play on the H × W board. This game is a game to move 0 or 1 balls in each cell. You were playing this game and found it difficult to move the ball accurately from cell to cell because the ball is so round. So you decided to make a robot that would move the ball as instructed. Here, the notation (y, x) is used to represent the cell. This represents the cell in the xth column of the yth row.
Instructions to the robot are given by the four integers a, b, c, d. This means moving the ball at (a, b) to (c, d). At this time, it is guaranteed that the ball exists in (a, b) and does not exist in (c, d).
The state of the board is expressed by the following notation called "jfen".
[Data in the first line] / [Data in the second line] /.../ [Data in the H line]
This notation is a slash-separated concatenation of data representing each line on the board. The data in each row is represented by a character string, and the state of the cells in the 1st to Wth columns is described in order from the left. This string is represented by a number and the letter'b', where the integer represented by the number represents the number of consecutive blank cells and'b' represents the cell in which the ball resides. Here, integers must not be consecutive in the data of each row. Also, the sum of the integers written in the data of each line and the sum of the number of'b'are always W.
As an example, consider the following board surface condition. A blank cell is represented by a'.', And a cell in which the ball exists is represented by a'b'. The j character from the left of the i-th row in this example represents the state of the cell in the j-th column of the i-th row on the board.
....
.b.b
....
The above board is expressed in jfen as follows.
4 / 1b1b / 4
Create a program that outputs the board surface after the robot moves the ball when the robot is given the current board surface state and a command to move one ball. At this time, output the board surface in jfen notation.
Input
The input consists of multiple datasets. Each dataset has the following format.
> S
> a b c d
Each dataset consists of two lines, and the first line is given the jfen-formatted string S, which represents the state of the board. Here, the size of the board satisfies 2 ≤ W and H ≤ 9. Instructions to the robot are given to the following lines. This represents an instruction to move the ball at (a, b) to (c, d). The end of the input is represented by #.
Output
The output is one line of character string that expresses the state of the board after executing the instruction for each data set in jfen notation. There must be no other characters on the output line.
Sample Input
b1 / 1b
1 1 1 2
b5 / bbbbbb
2 4 1 4
b2b2b / 7
1 4 2 4
Output for Sample Input
1b / 1b
b2b2 / bbb1bb
b5b / 3b3
The initial state of the first input is as follows.
b.
.b
Since the ball of (1,1) is moved to (1,2), the board surface after the command is as follows.
.b
.b
Example
Input
b1/1b
1 1 1 2
b5/bbbbbb
2 4 1 4
b2b2b/7
1 4 2 4
#
Output
1b/1b
b2b2/bbb1bb
b5b/3b3
Submitted Solution:
```
def decode(s):
ret = []
for line in s.split('/'):
a = ''
for c in line:
if c == 'b':
a += 'b'
else:
a += '.'*(ord(c)-ord('0'))
ret.append(list(a))
return ret
def encode(s):
ret = []
for line in s:
x = ''.join(line)
x = x.split('b')
a = ''
for i in range(len(x)-1):
if len(x[i])>0:
a += str(len(x[i]))
a += 'b'
if len(x[len(x)-1])>0:
a += str(len(x[len(x)-1]))
ret.append(a)
return '/'.join(ret)
def main():
while True:
s = input()
if s == '#':
break
a,b,c,d = map(int,input().split())
f = decode(s)
f[a-1][b-1] = '.'
f[c-1][d-1] = 'b'
print(encode(f))
if __name__ == '__main__':
main()
``` | instruction | 0 | 42,053 | 15 | 84,106 |
Yes | output | 1 | 42,053 | 15 | 84,107 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
jfen
There is a one-person game to play on the H × W board. This game is a game to move 0 or 1 balls in each cell. You were playing this game and found it difficult to move the ball accurately from cell to cell because the ball is so round. So you decided to make a robot that would move the ball as instructed. Here, the notation (y, x) is used to represent the cell. This represents the cell in the xth column of the yth row.
Instructions to the robot are given by the four integers a, b, c, d. This means moving the ball at (a, b) to (c, d). At this time, it is guaranteed that the ball exists in (a, b) and does not exist in (c, d).
The state of the board is expressed by the following notation called "jfen".
[Data in the first line] / [Data in the second line] /.../ [Data in the H line]
This notation is a slash-separated concatenation of data representing each line on the board. The data in each row is represented by a character string, and the state of the cells in the 1st to Wth columns is described in order from the left. This string is represented by a number and the letter'b', where the integer represented by the number represents the number of consecutive blank cells and'b' represents the cell in which the ball resides. Here, integers must not be consecutive in the data of each row. Also, the sum of the integers written in the data of each line and the sum of the number of'b'are always W.
As an example, consider the following board surface condition. A blank cell is represented by a'.', And a cell in which the ball exists is represented by a'b'. The j character from the left of the i-th row in this example represents the state of the cell in the j-th column of the i-th row on the board.
....
.b.b
....
The above board is expressed in jfen as follows.
4 / 1b1b / 4
Create a program that outputs the board surface after the robot moves the ball when the robot is given the current board surface state and a command to move one ball. At this time, output the board surface in jfen notation.
Input
The input consists of multiple datasets. Each dataset has the following format.
> S
> a b c d
Each dataset consists of two lines, and the first line is given the jfen-formatted string S, which represents the state of the board. Here, the size of the board satisfies 2 ≤ W and H ≤ 9. Instructions to the robot are given to the following lines. This represents an instruction to move the ball at (a, b) to (c, d). The end of the input is represented by #.
Output
The output is one line of character string that expresses the state of the board after executing the instruction for each data set in jfen notation. There must be no other characters on the output line.
Sample Input
b1 / 1b
1 1 1 2
b5 / bbbbbb
2 4 1 4
b2b2b / 7
1 4 2 4
Output for Sample Input
1b / 1b
b2b2 / bbb1bb
b5b / 3b3
The initial state of the first input is as follows.
b.
.b
Since the ball of (1,1) is moved to (1,2), the board surface after the command is as follows.
.b
.b
Example
Input
b1/1b
1 1 1 2
b5/bbbbbb
2 4 1 4
b2b2b/7
1 4 2 4
#
Output
1b/1b
b2b2/bbb1bb
b5b/3b3
Submitted Solution:
```
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 998244353
dd = [(0,-1),(1,0),(0,1),(-1,0)]
ddn = [(0,-1),(1,-1),(1,0),(1,1),(0,1),(-1,-1),(-1,0),(-1,1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def main():
rr = []
st = string.digits + string.ascii_uppercase
def decode(s):
t = s.split('/')
a = []
for c in t:
b = []
for k in c:
if k == 'b':
b.append(1)
else:
for _ in range(int(k)):
b.append(0)
a.append(b)
return a
def encode(a):
t = []
for c in a:
k = ''
tc = 0
for b in c:
if b == 0:
tc += 1
else:
if tc > 0:
k += str(tc)
tc = 0
k += 'b'
if tc > 0:
k += str(tc)
t.append(k)
return '/'.join(t)
while True:
s = S()
if s == '#':
break
a,b,c,d = LI()
t = decode(s)
t[a-1][b-1] = 0
t[c-1][d-1] = 1
rr.append(encode(t))
return '\n'.join(map(str, rr))
print(main())
``` | instruction | 0 | 42,054 | 15 | 84,108 |
Yes | output | 1 | 42,054 | 15 | 84,109 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
jfen
There is a one-person game to play on the H × W board. This game is a game to move 0 or 1 balls in each cell. You were playing this game and found it difficult to move the ball accurately from cell to cell because the ball is so round. So you decided to make a robot that would move the ball as instructed. Here, the notation (y, x) is used to represent the cell. This represents the cell in the xth column of the yth row.
Instructions to the robot are given by the four integers a, b, c, d. This means moving the ball at (a, b) to (c, d). At this time, it is guaranteed that the ball exists in (a, b) and does not exist in (c, d).
The state of the board is expressed by the following notation called "jfen".
[Data in the first line] / [Data in the second line] /.../ [Data in the H line]
This notation is a slash-separated concatenation of data representing each line on the board. The data in each row is represented by a character string, and the state of the cells in the 1st to Wth columns is described in order from the left. This string is represented by a number and the letter'b', where the integer represented by the number represents the number of consecutive blank cells and'b' represents the cell in which the ball resides. Here, integers must not be consecutive in the data of each row. Also, the sum of the integers written in the data of each line and the sum of the number of'b'are always W.
As an example, consider the following board surface condition. A blank cell is represented by a'.', And a cell in which the ball exists is represented by a'b'. The j character from the left of the i-th row in this example represents the state of the cell in the j-th column of the i-th row on the board.
....
.b.b
....
The above board is expressed in jfen as follows.
4 / 1b1b / 4
Create a program that outputs the board surface after the robot moves the ball when the robot is given the current board surface state and a command to move one ball. At this time, output the board surface in jfen notation.
Input
The input consists of multiple datasets. Each dataset has the following format.
> S
> a b c d
Each dataset consists of two lines, and the first line is given the jfen-formatted string S, which represents the state of the board. Here, the size of the board satisfies 2 ≤ W and H ≤ 9. Instructions to the robot are given to the following lines. This represents an instruction to move the ball at (a, b) to (c, d). The end of the input is represented by #.
Output
The output is one line of character string that expresses the state of the board after executing the instruction for each data set in jfen notation. There must be no other characters on the output line.
Sample Input
b1 / 1b
1 1 1 2
b5 / bbbbbb
2 4 1 4
b2b2b / 7
1 4 2 4
Output for Sample Input
1b / 1b
b2b2 / bbb1bb
b5b / 3b3
The initial state of the first input is as follows.
b.
.b
Since the ball of (1,1) is moved to (1,2), the board surface after the command is as follows.
.b
.b
Example
Input
b1/1b
1 1 1 2
b5/bbbbbb
2 4 1 4
b2b2b/7
1 4 2 4
#
Output
1b/1b
b2b2/bbb1bb
b5b/3b3
Submitted Solution:
```
#!/usr/bin/env python3
while True:
s = input()
if s == '#':
break
a, b, c, d = map(lambda x: int(x) - 1, input().split())
cell = []
for i, x in enumerate(s.split('/')):
cell.append([])
for ch in x:
if ch == 'b':
cell[i].append('b')
else:
cell[i] += list('.' * int(ch))
cell[a][b] = '.'
cell[c][d] = 'b'
ans = []
for i in range(len(cell)):
jfen = ''
cnt = 0
for j in range(len(cell[i])):
if cell[i][j] == 'b':
if cnt > 0:
jfen += str(cnt)
cnt = 0
jfen += 'b'
else:
cnt += 1
if cnt > 0:
jfen += str(cnt)
ans.append(jfen)
print('/'.join(ans))
``` | instruction | 0 | 42,055 | 15 | 84,110 |
Yes | output | 1 | 42,055 | 15 | 84,111 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
jfen
There is a one-person game to play on the H × W board. This game is a game to move 0 or 1 balls in each cell. You were playing this game and found it difficult to move the ball accurately from cell to cell because the ball is so round. So you decided to make a robot that would move the ball as instructed. Here, the notation (y, x) is used to represent the cell. This represents the cell in the xth column of the yth row.
Instructions to the robot are given by the four integers a, b, c, d. This means moving the ball at (a, b) to (c, d). At this time, it is guaranteed that the ball exists in (a, b) and does not exist in (c, d).
The state of the board is expressed by the following notation called "jfen".
[Data in the first line] / [Data in the second line] /.../ [Data in the H line]
This notation is a slash-separated concatenation of data representing each line on the board. The data in each row is represented by a character string, and the state of the cells in the 1st to Wth columns is described in order from the left. This string is represented by a number and the letter'b', where the integer represented by the number represents the number of consecutive blank cells and'b' represents the cell in which the ball resides. Here, integers must not be consecutive in the data of each row. Also, the sum of the integers written in the data of each line and the sum of the number of'b'are always W.
As an example, consider the following board surface condition. A blank cell is represented by a'.', And a cell in which the ball exists is represented by a'b'. The j character from the left of the i-th row in this example represents the state of the cell in the j-th column of the i-th row on the board.
....
.b.b
....
The above board is expressed in jfen as follows.
4 / 1b1b / 4
Create a program that outputs the board surface after the robot moves the ball when the robot is given the current board surface state and a command to move one ball. At this time, output the board surface in jfen notation.
Input
The input consists of multiple datasets. Each dataset has the following format.
> S
> a b c d
Each dataset consists of two lines, and the first line is given the jfen-formatted string S, which represents the state of the board. Here, the size of the board satisfies 2 ≤ W and H ≤ 9. Instructions to the robot are given to the following lines. This represents an instruction to move the ball at (a, b) to (c, d). The end of the input is represented by #.
Output
The output is one line of character string that expresses the state of the board after executing the instruction for each data set in jfen notation. There must be no other characters on the output line.
Sample Input
b1 / 1b
1 1 1 2
b5 / bbbbbb
2 4 1 4
b2b2b / 7
1 4 2 4
Output for Sample Input
1b / 1b
b2b2 / bbb1bb
b5b / 3b3
The initial state of the first input is as follows.
b.
.b
Since the ball of (1,1) is moved to (1,2), the board surface after the command is as follows.
.b
.b
Example
Input
b1/1b
1 1 1 2
b5/bbbbbb
2 4 1 4
b2b2b/7
1 4 2 4
#
Output
1b/1b
b2b2/bbb1bb
b5b/3b3
Submitted Solution:
```
while 1:
s=input()
if s=='#':break
p=0
e=[[],[]]
for x in s:
if x=='b':e[p]+=['b']
elif x=='/':p+=1
else:
for j in range(int(x)):e[p]+=['.']
ans=''
a,b,c,d=map(int,input().split())
e[a-1][b-1],e[c-1][d-1]=e[c-1][d-1],e[a-1][b-1]
for i in range(2):
if i: ans += '/'
a=0
for j in e[i]:
if j=='b':
if a:ans+=str(a)
ans+='b'
a=0
else:a+=1
if a:ans+=str(a)
print(ans)
``` | instruction | 0 | 42,056 | 15 | 84,112 |
No | output | 1 | 42,056 | 15 | 84,113 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
jfen
There is a one-person game to play on the H × W board. This game is a game to move 0 or 1 balls in each cell. You were playing this game and found it difficult to move the ball accurately from cell to cell because the ball is so round. So you decided to make a robot that would move the ball as instructed. Here, the notation (y, x) is used to represent the cell. This represents the cell in the xth column of the yth row.
Instructions to the robot are given by the four integers a, b, c, d. This means moving the ball at (a, b) to (c, d). At this time, it is guaranteed that the ball exists in (a, b) and does not exist in (c, d).
The state of the board is expressed by the following notation called "jfen".
[Data in the first line] / [Data in the second line] /.../ [Data in the H line]
This notation is a slash-separated concatenation of data representing each line on the board. The data in each row is represented by a character string, and the state of the cells in the 1st to Wth columns is described in order from the left. This string is represented by a number and the letter'b', where the integer represented by the number represents the number of consecutive blank cells and'b' represents the cell in which the ball resides. Here, integers must not be consecutive in the data of each row. Also, the sum of the integers written in the data of each line and the sum of the number of'b'are always W.
As an example, consider the following board surface condition. A blank cell is represented by a'.', And a cell in which the ball exists is represented by a'b'. The j character from the left of the i-th row in this example represents the state of the cell in the j-th column of the i-th row on the board.
....
.b.b
....
The above board is expressed in jfen as follows.
4 / 1b1b / 4
Create a program that outputs the board surface after the robot moves the ball when the robot is given the current board surface state and a command to move one ball. At this time, output the board surface in jfen notation.
Input
The input consists of multiple datasets. Each dataset has the following format.
> S
> a b c d
Each dataset consists of two lines, and the first line is given the jfen-formatted string S, which represents the state of the board. Here, the size of the board satisfies 2 ≤ W and H ≤ 9. Instructions to the robot are given to the following lines. This represents an instruction to move the ball at (a, b) to (c, d). The end of the input is represented by #.
Output
The output is one line of character string that expresses the state of the board after executing the instruction for each data set in jfen notation. There must be no other characters on the output line.
Sample Input
b1 / 1b
1 1 1 2
b5 / bbbbbb
2 4 1 4
b2b2b / 7
1 4 2 4
Output for Sample Input
1b / 1b
b2b2 / bbb1bb
b5b / 3b3
The initial state of the first input is as follows.
b.
.b
Since the ball of (1,1) is moved to (1,2), the board surface after the command is as follows.
.b
.b
Example
Input
b1/1b
1 1 1 2
b5/bbbbbb
2 4 1 4
b2b2b/7
1 4 2 4
#
Output
1b/1b
b2b2/bbb1bb
b5b/3b3
Submitted Solution:
```
while 1:
s=input()
if s=='#':break
p=0
e=[[],[]]
for x in s:
if x=='b':e[p]+=['b']
elif x=='/':p+=1
else:
for j in range(int(x)):e[p]+=['.']
ans=''
a,b,c,d=map(int,input().split())
e[a-1][b-1]='.'
e[c-1][d-1]='b'
for i in range(2):
if i:ans+='/'
a=0
for j in e[i]:
if j=='b':
if a:ans+=str(a)
ans+='b'
a=0
else:a+=1
if a:ans+=str(a)
print(ans)
``` | instruction | 0 | 42,057 | 15 | 84,114 |
No | output | 1 | 42,057 | 15 | 84,115 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
jfen
There is a one-person game to play on the H × W board. This game is a game to move 0 or 1 balls in each cell. You were playing this game and found it difficult to move the ball accurately from cell to cell because the ball is so round. So you decided to make a robot that would move the ball as instructed. Here, the notation (y, x) is used to represent the cell. This represents the cell in the xth column of the yth row.
Instructions to the robot are given by the four integers a, b, c, d. This means moving the ball at (a, b) to (c, d). At this time, it is guaranteed that the ball exists in (a, b) and does not exist in (c, d).
The state of the board is expressed by the following notation called "jfen".
[Data in the first line] / [Data in the second line] /.../ [Data in the H line]
This notation is a slash-separated concatenation of data representing each line on the board. The data in each row is represented by a character string, and the state of the cells in the 1st to Wth columns is described in order from the left. This string is represented by a number and the letter'b', where the integer represented by the number represents the number of consecutive blank cells and'b' represents the cell in which the ball resides. Here, integers must not be consecutive in the data of each row. Also, the sum of the integers written in the data of each line and the sum of the number of'b'are always W.
As an example, consider the following board surface condition. A blank cell is represented by a'.', And a cell in which the ball exists is represented by a'b'. The j character from the left of the i-th row in this example represents the state of the cell in the j-th column of the i-th row on the board.
....
.b.b
....
The above board is expressed in jfen as follows.
4 / 1b1b / 4
Create a program that outputs the board surface after the robot moves the ball when the robot is given the current board surface state and a command to move one ball. At this time, output the board surface in jfen notation.
Input
The input consists of multiple datasets. Each dataset has the following format.
> S
> a b c d
Each dataset consists of two lines, and the first line is given the jfen-formatted string S, which represents the state of the board. Here, the size of the board satisfies 2 ≤ W and H ≤ 9. Instructions to the robot are given to the following lines. This represents an instruction to move the ball at (a, b) to (c, d). The end of the input is represented by #.
Output
The output is one line of character string that expresses the state of the board after executing the instruction for each data set in jfen notation. There must be no other characters on the output line.
Sample Input
b1 / 1b
1 1 1 2
b5 / bbbbbb
2 4 1 4
b2b2b / 7
1 4 2 4
Output for Sample Input
1b / 1b
b2b2 / bbb1bb
b5b / 3b3
The initial state of the first input is as follows.
b.
.b
Since the ball of (1,1) is moved to (1,2), the board surface after the command is as follows.
.b
.b
Example
Input
b1/1b
1 1 1 2
b5/bbbbbb
2 4 1 4
b2b2b/7
1 4 2 4
#
Output
1b/1b
b2b2/bbb1bb
b5b/3b3
Submitted Solution:
```
while 1:
s=input()
if '#' in s:break
p=0
e=[[]*2 for _ in range(10)]
for x in s:
if x=='b':e[p]+=['b']
elif x=='/':p+=1
else:e[p]+='.'*int(x)
ans=''
a,b,c,d=map(int,input().split())
e[a-1][b-1],e[c-1][d-1]=e[c-1][d-1],e[a-1][b-1]
for i in range(2):
if i:ans+='/'
a=0
for j in e[i]:
if j=='b':
if a:ans+=str(a)
ans+='b'
a=0
else:a+=1
if a:ans+=str(a)
print(ans)
``` | instruction | 0 | 42,058 | 15 | 84,116 |
No | output | 1 | 42,058 | 15 | 84,117 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Egor wants to achieve a rating of 1600 points on the well-known chess portal ChessForces and he needs your help!
Before you start solving the problem, Egor wants to remind you how the chess pieces move. Chess rook moves along straight lines up and down, left and right, as many squares as it wants. And when it wants, it can stop. The queen walks in all directions vertically and diagonally at any distance. You can see the examples below.
<image>
To reach the goal, Egor should research the next topic:
There is an N × N board. Each cell of the board has a number from 1 to N ^ 2 in it and numbers in all cells are distinct.
In the beginning, some chess figure stands in the cell with the number 1. Note that this cell is already considered as visited. After that every move is determined by the following rules:
1. Among all not visited yet cells to which the figure can get in one move, it goes to the cell that has minimal number.
2. If all accessible cells were already visited and some cells are not yet visited, then the figure is teleported to the not visited cell that has minimal number. If this step happens, the piece pays a fee of 1 vun.
3. If all cells are already visited, the process is stopped.
Egor should find an N × N board on which the rook pays strictly less vuns than the queen during the round with this numbering. Help him to find such N × N numbered board, or tell that it doesn't exist.
Input
The only line contains one integer N — the size of the board, 1≤ N ≤ 500.
Output
The output should contain N lines.
In i-th line output N numbers — numbers on the i-th row of the board. All numbers from 1 to N × N must be used exactly once.
On your board rook must pay strictly less vuns than the queen.
If there are no solutions, print -1.
If there are several solutions, you can output any of them.
Examples
Input
1
Output
-1
Input
4
Output
4 3 6 12
7 5 9 15
14 1 11 10
13 8 16 2
Note
In case we have 1 × 1 board, both rook and queen do not have a chance to pay fees.
In second sample rook goes through cells 1 → 3 → 4 → 6 → 9 → 5 → 7 → 13 → 2 → 8 → 16 → 11 → 10 → 12 → 15 → (1 vun) → 14.
Queen goes through 1 → 3 → 4 → 2 → 5 → 6 → 9 → 7 → 13 → 8 → 11 → 10 → 12 → 15 → (1 vun) → 14 → (1 vun) → 16.
As a result rook pays 1 vun and queen pays 2 vuns. | instruction | 0 | 42,221 | 15 | 84,442 |
Tags: brute force, constructive algorithms
Correct Solution:
```
ls = [
[6,3,8],
[1,2,7],
[9,4,5]
]
n = int(input())
if n <= 2:
print(-1)
exit()
ans = [[0 for i in range(n)] for j in range(n)]
for i in range(3):
for j in range(3):
ans[i][j] = ls[i][j]+n**2-9
x,y = 2,0
d = "D"
for i in range(1,n**2-8)[::-1]:
if d == "D":
x += 1
if d == "U":
x -= 1
if d == "L":
y -= 1
if d == "R":
y += 1
ans[x][y] = i
if x == y:
if d == "D":
d = "L"
elif d == "R":
d = "U"
elif x == 0:
if d == "U":
d = "R"
elif d == "R":
d = "D"
elif y == 0:
if d == "L":
d = "D"
elif d == "D":
d = "R"
for row in ans:
print(*row)
``` | output | 1 | 42,221 | 15 | 84,443 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Egor wants to achieve a rating of 1600 points on the well-known chess portal ChessForces and he needs your help!
Before you start solving the problem, Egor wants to remind you how the chess pieces move. Chess rook moves along straight lines up and down, left and right, as many squares as it wants. And when it wants, it can stop. The queen walks in all directions vertically and diagonally at any distance. You can see the examples below.
<image>
To reach the goal, Egor should research the next topic:
There is an N × N board. Each cell of the board has a number from 1 to N ^ 2 in it and numbers in all cells are distinct.
In the beginning, some chess figure stands in the cell with the number 1. Note that this cell is already considered as visited. After that every move is determined by the following rules:
1. Among all not visited yet cells to which the figure can get in one move, it goes to the cell that has minimal number.
2. If all accessible cells were already visited and some cells are not yet visited, then the figure is teleported to the not visited cell that has minimal number. If this step happens, the piece pays a fee of 1 vun.
3. If all cells are already visited, the process is stopped.
Egor should find an N × N board on which the rook pays strictly less vuns than the queen during the round with this numbering. Help him to find such N × N numbered board, or tell that it doesn't exist.
Input
The only line contains one integer N — the size of the board, 1≤ N ≤ 500.
Output
The output should contain N lines.
In i-th line output N numbers — numbers on the i-th row of the board. All numbers from 1 to N × N must be used exactly once.
On your board rook must pay strictly less vuns than the queen.
If there are no solutions, print -1.
If there are several solutions, you can output any of them.
Examples
Input
1
Output
-1
Input
4
Output
4 3 6 12
7 5 9 15
14 1 11 10
13 8 16 2
Note
In case we have 1 × 1 board, both rook and queen do not have a chance to pay fees.
In second sample rook goes through cells 1 → 3 → 4 → 6 → 9 → 5 → 7 → 13 → 2 → 8 → 16 → 11 → 10 → 12 → 15 → (1 vun) → 14.
Queen goes through 1 → 3 → 4 → 2 → 5 → 6 → 9 → 7 → 13 → 8 → 11 → 10 → 12 → 15 → (1 vun) → 14 → (1 vun) → 16.
As a result rook pays 1 vun and queen pays 2 vuns. | instruction | 0 | 42,222 | 15 | 84,444 |
Tags: brute force, constructive algorithms
Correct Solution:
```
import sys
input = sys.stdin.buffer.readline
N = int(input())
if N < 3:
print(-1)
exit(0)
board = [[0 for j in range(N)] for i in range(N)]
base = [ [7,4,8] , [9,2,3] , [1,5,6] ]
i = 3 + (N-2)//2 ; j = (N-1)//2 + 2
val = N*N - 8
for x in range(-3,0):
for y in range(-3,0):
board[i+x][j+y] = N*N - 9 + base[x+3][y+3]
for n in range(4,N+1):
if n & 1:
for inc in range(n):
val -= 1 ; i += 1
board[i][j] = val
for inc in range(n-1):
val -= 1 ; j += 1
board[i][j] = val
i += 1 ; j += 1
else:
for inc in range(n):
val -= 1 ; i -= 1
board[i][j] = val
for inc in range(n-1):
val -= 1; j -= 1
board[i][j] = val
j -= 1 ; i -= 1
for b in board:print(*b)
``` | output | 1 | 42,222 | 15 | 84,445 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Egor wants to achieve a rating of 1600 points on the well-known chess portal ChessForces and he needs your help!
Before you start solving the problem, Egor wants to remind you how the chess pieces move. Chess rook moves along straight lines up and down, left and right, as many squares as it wants. And when it wants, it can stop. The queen walks in all directions vertically and diagonally at any distance. You can see the examples below.
<image>
To reach the goal, Egor should research the next topic:
There is an N × N board. Each cell of the board has a number from 1 to N ^ 2 in it and numbers in all cells are distinct.
In the beginning, some chess figure stands in the cell with the number 1. Note that this cell is already considered as visited. After that every move is determined by the following rules:
1. Among all not visited yet cells to which the figure can get in one move, it goes to the cell that has minimal number.
2. If all accessible cells were already visited and some cells are not yet visited, then the figure is teleported to the not visited cell that has minimal number. If this step happens, the piece pays a fee of 1 vun.
3. If all cells are already visited, the process is stopped.
Egor should find an N × N board on which the rook pays strictly less vuns than the queen during the round with this numbering. Help him to find such N × N numbered board, or tell that it doesn't exist.
Input
The only line contains one integer N — the size of the board, 1≤ N ≤ 500.
Output
The output should contain N lines.
In i-th line output N numbers — numbers on the i-th row of the board. All numbers from 1 to N × N must be used exactly once.
On your board rook must pay strictly less vuns than the queen.
If there are no solutions, print -1.
If there are several solutions, you can output any of them.
Examples
Input
1
Output
-1
Input
4
Output
4 3 6 12
7 5 9 15
14 1 11 10
13 8 16 2
Note
In case we have 1 × 1 board, both rook and queen do not have a chance to pay fees.
In second sample rook goes through cells 1 → 3 → 4 → 6 → 9 → 5 → 7 → 13 → 2 → 8 → 16 → 11 → 10 → 12 → 15 → (1 vun) → 14.
Queen goes through 1 → 3 → 4 → 2 → 5 → 6 → 9 → 7 → 13 → 8 → 11 → 10 → 12 → 15 → (1 vun) → 14 → (1 vun) → 16.
As a result rook pays 1 vun and queen pays 2 vuns. | instruction | 0 | 42,223 | 15 | 84,446 |
Tags: brute force, constructive algorithms
Correct Solution:
```
def main():
n = int(input())
if n < 3:
print(-1)
return
ans = [[0]*n for _ in range(n)]
st = n*n-9
ans[0][0:3] = [st+6,st+5,st+8]
ans[1][0:3] = [st+7,st+3,st+4]
ans[2][0:3] = [st+1,st+2,st+9]
cur = 1
k = 0
while n-k > 3:
if (n-k) % 2:
for j in range(n-k-1):
ans[n-k-1][j] = cur
cur += 1
for i in reversed(range(n-k)):
ans[i][n-k-1] = cur
cur += 1
else:
for i in range(n-k):
ans[i][n-k-1] = cur
cur += 1
for j in reversed(range(n-k-1)):
ans[n-k-1][j] = cur
cur += 1
k += 1
for row in ans:
print(*row)
main()
``` | output | 1 | 42,223 | 15 | 84,447 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Egor wants to achieve a rating of 1600 points on the well-known chess portal ChessForces and he needs your help!
Before you start solving the problem, Egor wants to remind you how the chess pieces move. Chess rook moves along straight lines up and down, left and right, as many squares as it wants. And when it wants, it can stop. The queen walks in all directions vertically and diagonally at any distance. You can see the examples below.
<image>
To reach the goal, Egor should research the next topic:
There is an N × N board. Each cell of the board has a number from 1 to N ^ 2 in it and numbers in all cells are distinct.
In the beginning, some chess figure stands in the cell with the number 1. Note that this cell is already considered as visited. After that every move is determined by the following rules:
1. Among all not visited yet cells to which the figure can get in one move, it goes to the cell that has minimal number.
2. If all accessible cells were already visited and some cells are not yet visited, then the figure is teleported to the not visited cell that has minimal number. If this step happens, the piece pays a fee of 1 vun.
3. If all cells are already visited, the process is stopped.
Egor should find an N × N board on which the rook pays strictly less vuns than the queen during the round with this numbering. Help him to find such N × N numbered board, or tell that it doesn't exist.
Input
The only line contains one integer N — the size of the board, 1≤ N ≤ 500.
Output
The output should contain N lines.
In i-th line output N numbers — numbers on the i-th row of the board. All numbers from 1 to N × N must be used exactly once.
On your board rook must pay strictly less vuns than the queen.
If there are no solutions, print -1.
If there are several solutions, you can output any of them.
Examples
Input
1
Output
-1
Input
4
Output
4 3 6 12
7 5 9 15
14 1 11 10
13 8 16 2
Note
In case we have 1 × 1 board, both rook and queen do not have a chance to pay fees.
In second sample rook goes through cells 1 → 3 → 4 → 6 → 9 → 5 → 7 → 13 → 2 → 8 → 16 → 11 → 10 → 12 → 15 → (1 vun) → 14.
Queen goes through 1 → 3 → 4 → 2 → 5 → 6 → 9 → 7 → 13 → 8 → 11 → 10 → 12 → 15 → (1 vun) → 14 → (1 vun) → 16.
As a result rook pays 1 vun and queen pays 2 vuns. | instruction | 0 | 42,224 | 15 | 84,448 |
Tags: brute force, constructive algorithms
Correct Solution:
```
n = int(input())
if n < 3:
print(-1)
else:
ans = [[-1 for _ in range(n)] for _ in range(n)]
ans[0][0] = n*n-9+9
ans[0][1] = n*n-9+6
ans[0][2] = n*n-9+7
ans[1][0] = n*n-9+5
ans[1][1] = n*n-9+3
ans[1][2] = n*n-9+8
ans[2][0] = n*n-9+1
ans[2][1] = n*n-9+2
ans[2][2] = n*n-9+4
for i in range(3, n):
if i%2 == 1:
for j in range(i+1):
ans[i][j] = n*n-i*i-j
for j in range(i-1, -1, -1):
ans[j][i] = n*n-(i+1)*(i+1)+j+1
else:
for j in range(i+1):
ans[j][i] = n*n-i*i-j
for j in range(i-1, -1, -1):
ans[i][j] = n*n-(i+1)*(i+1)+j+1
for x in ans:
print(*x)
``` | output | 1 | 42,224 | 15 | 84,449 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Egor wants to achieve a rating of 1600 points on the well-known chess portal ChessForces and he needs your help!
Before you start solving the problem, Egor wants to remind you how the chess pieces move. Chess rook moves along straight lines up and down, left and right, as many squares as it wants. And when it wants, it can stop. The queen walks in all directions vertically and diagonally at any distance. You can see the examples below.
<image>
To reach the goal, Egor should research the next topic:
There is an N × N board. Each cell of the board has a number from 1 to N ^ 2 in it and numbers in all cells are distinct.
In the beginning, some chess figure stands in the cell with the number 1. Note that this cell is already considered as visited. After that every move is determined by the following rules:
1. Among all not visited yet cells to which the figure can get in one move, it goes to the cell that has minimal number.
2. If all accessible cells were already visited and some cells are not yet visited, then the figure is teleported to the not visited cell that has minimal number. If this step happens, the piece pays a fee of 1 vun.
3. If all cells are already visited, the process is stopped.
Egor should find an N × N board on which the rook pays strictly less vuns than the queen during the round with this numbering. Help him to find such N × N numbered board, or tell that it doesn't exist.
Input
The only line contains one integer N — the size of the board, 1≤ N ≤ 500.
Output
The output should contain N lines.
In i-th line output N numbers — numbers on the i-th row of the board. All numbers from 1 to N × N must be used exactly once.
On your board rook must pay strictly less vuns than the queen.
If there are no solutions, print -1.
If there are several solutions, you can output any of them.
Examples
Input
1
Output
-1
Input
4
Output
4 3 6 12
7 5 9 15
14 1 11 10
13 8 16 2
Note
In case we have 1 × 1 board, both rook and queen do not have a chance to pay fees.
In second sample rook goes through cells 1 → 3 → 4 → 6 → 9 → 5 → 7 → 13 → 2 → 8 → 16 → 11 → 10 → 12 → 15 → (1 vun) → 14.
Queen goes through 1 → 3 → 4 → 2 → 5 → 6 → 9 → 7 → 13 → 8 → 11 → 10 → 12 → 15 → (1 vun) → 14 → (1 vun) → 16.
As a result rook pays 1 vun and queen pays 2 vuns. | instruction | 0 | 42,225 | 15 | 84,450 |
Tags: brute force, constructive algorithms
Correct Solution:
```
import sys
n = int(input())
if n <= 2:
print(-1)
sys.exit(0)
elif n == 3:
board = [[4, 5, 8], [3, 2, 6], [1, 9, 7]]
else:
board = [[0 for _ in range(n)] for _ in range(n)]
curr = 1
# Do a J-walk
for i in range(1, n - 1):
board[0][i] = curr
curr += 1
for i in range(n - 1):
board[1][n - 2 - i] = curr
curr += 1
# Move to the side
board[2][0] = curr
curr += 1
# Fill the right
for i in range(2, n):
board[i][n - 1] = curr
curr += 1
# Half-trap
board[1][n - 1] = curr
curr += 1
board[0][n - 1] = curr
curr += 1
# Teleport spot (rook moves here, queen skips)
board[0][0] = n * n
# Opposite corner (this is where the queen skips to, and where the rook escapes)
board[n - 1][0] = curr
curr += 1
# Rest of trap side
for i in range(3, n - 1):
board[i][0] = curr
curr += 1
# The non-filled area should now form a square
# Right side
for i in range(2, n):
board[i][n - 2] = curr
curr += 1
# Vertical snake-fill to the left
bottom = True
for i in range(n - 3, 0, -1):
if bottom:
for j in range(n - 1, 1, -1):
board[j][i] = curr
curr += 1
else:
for j in range(2, n):
board[j][i] = curr
curr += 1
bottom = not bottom
for r in board:
print(" ".join(map(str, r)))
``` | output | 1 | 42,225 | 15 | 84,451 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Egor wants to achieve a rating of 1600 points on the well-known chess portal ChessForces and he needs your help!
Before you start solving the problem, Egor wants to remind you how the chess pieces move. Chess rook moves along straight lines up and down, left and right, as many squares as it wants. And when it wants, it can stop. The queen walks in all directions vertically and diagonally at any distance. You can see the examples below.
<image>
To reach the goal, Egor should research the next topic:
There is an N × N board. Each cell of the board has a number from 1 to N ^ 2 in it and numbers in all cells are distinct.
In the beginning, some chess figure stands in the cell with the number 1. Note that this cell is already considered as visited. After that every move is determined by the following rules:
1. Among all not visited yet cells to which the figure can get in one move, it goes to the cell that has minimal number.
2. If all accessible cells were already visited and some cells are not yet visited, then the figure is teleported to the not visited cell that has minimal number. If this step happens, the piece pays a fee of 1 vun.
3. If all cells are already visited, the process is stopped.
Egor should find an N × N board on which the rook pays strictly less vuns than the queen during the round with this numbering. Help him to find such N × N numbered board, or tell that it doesn't exist.
Input
The only line contains one integer N — the size of the board, 1≤ N ≤ 500.
Output
The output should contain N lines.
In i-th line output N numbers — numbers on the i-th row of the board. All numbers from 1 to N × N must be used exactly once.
On your board rook must pay strictly less vuns than the queen.
If there are no solutions, print -1.
If there are several solutions, you can output any of them.
Examples
Input
1
Output
-1
Input
4
Output
4 3 6 12
7 5 9 15
14 1 11 10
13 8 16 2
Note
In case we have 1 × 1 board, both rook and queen do not have a chance to pay fees.
In second sample rook goes through cells 1 → 3 → 4 → 6 → 9 → 5 → 7 → 13 → 2 → 8 → 16 → 11 → 10 → 12 → 15 → (1 vun) → 14.
Queen goes through 1 → 3 → 4 → 2 → 5 → 6 → 9 → 7 → 13 → 8 → 11 → 10 → 12 → 15 → (1 vun) → 14 → (1 vun) → 16.
As a result rook pays 1 vun and queen pays 2 vuns. | instruction | 0 | 42,226 | 15 | 84,452 |
Tags: brute force, constructive algorithms
Correct Solution:
```
def solve(n):
arr = [[0] * n for _ in range(n)]
arr[0][1] = n*n
arr[n-1][n-1] = n*n-1
arr[n-1][1] = n*n-2
arr[0][n-1] = n*n - (n+1)
cur = 1
r = n - 2
row_ = None
for i in range(n):
if arr[0][i] != 0:
continue
arr[0][i] = cur
row_ = i
cur +=1
r -=1
if r==0:
break
for col in range(1, n-1):
arr[col][row_]=cur
cur+=1
r = n-1
if col != n-2:
arr[col][n-1]=cur
cur+=1
r -= 1
for i in range(n):
if arr[col][i]!=0:
continue
arr[col][i]=cur
row_=i
cur+=1
r -=1
if r==0:
break
cur+= 1
r = n-2
for i in range(n):
if arr[n-1][i]!=0:
continue
arr[n-1][i]=cur
cur+=1
r-=1
if r==0:
break
return arr
n = int(input())
if n<3:
print(-1)
else:
arr = solve(n)
for a in arr:
print(' '.join([str(x) for x in a]))
``` | output | 1 | 42,226 | 15 | 84,453 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Egor wants to achieve a rating of 1600 points on the well-known chess portal ChessForces and he needs your help!
Before you start solving the problem, Egor wants to remind you how the chess pieces move. Chess rook moves along straight lines up and down, left and right, as many squares as it wants. And when it wants, it can stop. The queen walks in all directions vertically and diagonally at any distance. You can see the examples below.
<image>
To reach the goal, Egor should research the next topic:
There is an N × N board. Each cell of the board has a number from 1 to N ^ 2 in it and numbers in all cells are distinct.
In the beginning, some chess figure stands in the cell with the number 1. Note that this cell is already considered as visited. After that every move is determined by the following rules:
1. Among all not visited yet cells to which the figure can get in one move, it goes to the cell that has minimal number.
2. If all accessible cells were already visited and some cells are not yet visited, then the figure is teleported to the not visited cell that has minimal number. If this step happens, the piece pays a fee of 1 vun.
3. If all cells are already visited, the process is stopped.
Egor should find an N × N board on which the rook pays strictly less vuns than the queen during the round with this numbering. Help him to find such N × N numbered board, or tell that it doesn't exist.
Input
The only line contains one integer N — the size of the board, 1≤ N ≤ 500.
Output
The output should contain N lines.
In i-th line output N numbers — numbers on the i-th row of the board. All numbers from 1 to N × N must be used exactly once.
On your board rook must pay strictly less vuns than the queen.
If there are no solutions, print -1.
If there are several solutions, you can output any of them.
Examples
Input
1
Output
-1
Input
4
Output
4 3 6 12
7 5 9 15
14 1 11 10
13 8 16 2
Note
In case we have 1 × 1 board, both rook and queen do not have a chance to pay fees.
In second sample rook goes through cells 1 → 3 → 4 → 6 → 9 → 5 → 7 → 13 → 2 → 8 → 16 → 11 → 10 → 12 → 15 → (1 vun) → 14.
Queen goes through 1 → 3 → 4 → 2 → 5 → 6 → 9 → 7 → 13 → 8 → 11 → 10 → 12 → 15 → (1 vun) → 14 → (1 vun) → 16.
As a result rook pays 1 vun and queen pays 2 vuns. | instruction | 0 | 42,227 | 15 | 84,454 |
Tags: brute force, constructive algorithms
Correct Solution:
```
n = input()
n = int(n)
if n <=2:
print(-1)
elif n%2 ==0:
for row in range(n):
if row ==0:
for i in range(n):
if i ==0:
print(i+1,end = " ")
elif i==n-1:
print(i+1)
else:
print(i+1,end = " ")
elif row ==n-1:
for i in range(n):
if i==n-1:
print(n*n-1)
else:
print(n+(n-1)*(n-2)+(n-3)-i+2,end = " ")
elif row ==n-2:
for i in range(n):
if i ==0:
print(n*n-n+2+row,end = " ")
elif i <n-1:
print(n+(n-1)*(row-1)+i,end = " ")
else:
print(n+(n-1)*(row-1)+n-1)
elif row%2 ==1:
for i in range(n):
if i ==0:
print(n*n-n+2+row-1,end = " ")
elif i <n-1:
print(n+(n-1)*(row-1)+n-i,end = " ")
else:
print(n+(n-1)*(row-1)+1)
elif row%2 ==0:
for i in range(n):
if i ==0:
print(n*n-n+2+row-1,end = " ")
elif i <n-1:
print(n+(n-1)*(row-1)+i,end = " ")
else:
print(n+(n-1)*(row-1)+n-1)
elif n%2 ==1:
for row in range(n):
if row ==0:
for i in range(n):
if i ==0:
print(i+1,end = " ")
elif i==n-1:
print(n*n-n+row+1)
else:
print(i+1,end = " ")
elif row ==n-1:
for i in range(n):
if i==0:
print(n*n-1,end = " ")
elif i ==n-1:
print((n-1)*(n-1)+i)
else:
print((n-1)*(n-1)+i,end = " ")
elif row ==n-2:
for i in range(n):
if i ==0:
print((n-1)*row+n-i-1,end = " ")
elif i <n-1:
print((n-1)*row+n-i-1,end = " ")
else:
print(n*n)
elif row%2 ==1:
for i in range(n):
if i ==0:
print((n-1)*row+n-i-1,end = " ")
elif i <n-1:
print((n-1)*row+n-i-1,end = " ")
else:
print(n*n-n+row+1)
elif row%2 ==0:
for i in range(n):
if i ==0:
print((n-1)*row+i+1,end = " ")
elif i <n-1:
print((n-1)*row+i+1,end = " ")
else:
print(n*n-n+row+1)
``` | output | 1 | 42,227 | 15 | 84,455 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Egor wants to achieve a rating of 1600 points on the well-known chess portal ChessForces and he needs your help!
Before you start solving the problem, Egor wants to remind you how the chess pieces move. Chess rook moves along straight lines up and down, left and right, as many squares as it wants. And when it wants, it can stop. The queen walks in all directions vertically and diagonally at any distance. You can see the examples below.
<image>
To reach the goal, Egor should research the next topic:
There is an N × N board. Each cell of the board has a number from 1 to N ^ 2 in it and numbers in all cells are distinct.
In the beginning, some chess figure stands in the cell with the number 1. Note that this cell is already considered as visited. After that every move is determined by the following rules:
1. Among all not visited yet cells to which the figure can get in one move, it goes to the cell that has minimal number.
2. If all accessible cells were already visited and some cells are not yet visited, then the figure is teleported to the not visited cell that has minimal number. If this step happens, the piece pays a fee of 1 vun.
3. If all cells are already visited, the process is stopped.
Egor should find an N × N board on which the rook pays strictly less vuns than the queen during the round with this numbering. Help him to find such N × N numbered board, or tell that it doesn't exist.
Input
The only line contains one integer N — the size of the board, 1≤ N ≤ 500.
Output
The output should contain N lines.
In i-th line output N numbers — numbers on the i-th row of the board. All numbers from 1 to N × N must be used exactly once.
On your board rook must pay strictly less vuns than the queen.
If there are no solutions, print -1.
If there are several solutions, you can output any of them.
Examples
Input
1
Output
-1
Input
4
Output
4 3 6 12
7 5 9 15
14 1 11 10
13 8 16 2
Note
In case we have 1 × 1 board, both rook and queen do not have a chance to pay fees.
In second sample rook goes through cells 1 → 3 → 4 → 6 → 9 → 5 → 7 → 13 → 2 → 8 → 16 → 11 → 10 → 12 → 15 → (1 vun) → 14.
Queen goes through 1 → 3 → 4 → 2 → 5 → 6 → 9 → 7 → 13 → 8 → 11 → 10 → 12 → 15 → (1 vun) → 14 → (1 vun) → 16.
As a result rook pays 1 vun and queen pays 2 vuns. | instruction | 0 | 42,228 | 15 | 84,456 |
Tags: brute force, constructive algorithms
Correct Solution:
```
from bisect import bisect_left as bl
from bisect import bisect_right as br
from heapq import heappush,heappop
import math
from collections import *
from functools import reduce,cmp_to_key
import sys
input = sys.stdin.readline
M = mod = 998244353
def factors(n):return sorted(set(reduce(list.__add__, ([i, n//i] for i in range(1, int(n**0.5) + 1) if n % i == 0))))
def inv_mod(n):return pow(n, mod - 2, mod)
def li():return [int(i) for i in input().rstrip('\n').split()]
def st():return input().rstrip('\n')
def val():return int(input().rstrip('\n'))
def li2():return [i for i in input().rstrip('\n')]
def li3():return [int(i) for i in input().rstrip('\n')]
n = val()
l = [[0]*n for i in range(n)]
if n < 3:
print(-1)
exit()
curr = 0
def givecurr():
global curr
curr += 1
return curr
up = [[5,4,1],[3,2,9],[8,6,7]]
down = [[7,6,8],[9,2,3],[1,4,5]]
totleft = n**2 - 9
i = n - 1
takeup = j = 0
while totleft:
while i >= 0 and j >= 0 and l[i][j] == 0:
l[i][j] = givecurr()
totleft -= 1
i -= 1
i += 1
j += 1
while j < n:
l[i][j] = givecurr()
totleft -= 1
j += 1
j = n - 1
i += 1
if not totleft:
takeup = 1
break
while j>=0 and l[i][j] == 0:
l[i][j] = givecurr()
totleft -= 1
j -= 1
j += 1
i += 1
while i < n:
l[i][j] = givecurr()
totleft -= 1
i += 1
i = n - 1
j += 1
for i in range(3):
for j in range(3):
l[i + n - 3][j + n - 3] = curr + (up[i][j] if takeup else down[i][j])
for i in l:
print(*i)
``` | output | 1 | 42,228 | 15 | 84,457 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Egor wants to achieve a rating of 1600 points on the well-known chess portal ChessForces and he needs your help!
Before you start solving the problem, Egor wants to remind you how the chess pieces move. Chess rook moves along straight lines up and down, left and right, as many squares as it wants. And when it wants, it can stop. The queen walks in all directions vertically and diagonally at any distance. You can see the examples below.
<image>
To reach the goal, Egor should research the next topic:
There is an N × N board. Each cell of the board has a number from 1 to N ^ 2 in it and numbers in all cells are distinct.
In the beginning, some chess figure stands in the cell with the number 1. Note that this cell is already considered as visited. After that every move is determined by the following rules:
1. Among all not visited yet cells to which the figure can get in one move, it goes to the cell that has minimal number.
2. If all accessible cells were already visited and some cells are not yet visited, then the figure is teleported to the not visited cell that has minimal number. If this step happens, the piece pays a fee of 1 vun.
3. If all cells are already visited, the process is stopped.
Egor should find an N × N board on which the rook pays strictly less vuns than the queen during the round with this numbering. Help him to find such N × N numbered board, or tell that it doesn't exist.
Input
The only line contains one integer N — the size of the board, 1≤ N ≤ 500.
Output
The output should contain N lines.
In i-th line output N numbers — numbers on the i-th row of the board. All numbers from 1 to N × N must be used exactly once.
On your board rook must pay strictly less vuns than the queen.
If there are no solutions, print -1.
If there are several solutions, you can output any of them.
Examples
Input
1
Output
-1
Input
4
Output
4 3 6 12
7 5 9 15
14 1 11 10
13 8 16 2
Note
In case we have 1 × 1 board, both rook and queen do not have a chance to pay fees.
In second sample rook goes through cells 1 → 3 → 4 → 6 → 9 → 5 → 7 → 13 → 2 → 8 → 16 → 11 → 10 → 12 → 15 → (1 vun) → 14.
Queen goes through 1 → 3 → 4 → 2 → 5 → 6 → 9 → 7 → 13 → 8 → 11 → 10 → 12 → 15 → (1 vun) → 14 → (1 vun) → 16.
As a result rook pays 1 vun and queen pays 2 vuns.
Submitted Solution:
```
n = int(input())
a = [[0 for j in range(n)] for i in range(n)]
z = 1
def prt(a, n):
for i in range(n):
print(*a[i])
if n == 3:
a = [[7, 1, 9], [8, 6, 5], [3, 2, 4]]
prt(a, n)
elif n < 4:
print(-1)
elif n == 4:
a[0] = [1, 2, 3, 4]
elif n % 2 == 1:
for i in range(n - 3):
for j in range(n):
if i % 2 == 0:
a[i][j] = z
else:
a[i][n - j - 1] = z
z += 1
a[n - 1][0] = z
z += 1
a[n - 2][0] = z
z += 1
a[n - 3][0] = z
z += 1
for j in range(1, n - 4):
a[n - 3][j] = z
z += 1
a[n - 2][j] = z
z += 1
a[n - 1][j] = z
z += 1
if j % 2 == 1:
a[n - 3][j], a[n - 1][j] = a[n - 1][j], a[n - 3][j]
elif n % 2 == 0:
for i in range(n - 3):
for j in range(n):
if i % 2 == 1:
a[i][j] = z
else:
a[i][n - j - 1] = z
z += 1
for j in range(n - 4):
a[n - 3][j] = z
z += 1
a[n - 2][j] = z
z += 1
a[n - 1][j] = z
z += 1
if j % 2 == 1:
a[n - 3][j], a[n - 1][j] = a[n - 1][j], a[n - 3][j]
if n >= 4:
m = n ** 2
a[n - 3][n - 4] = m - 6
a[n - 3][n - 3] = m - 5
a[n - 3][n - 2] = m - 10
a[n - 3][n - 1] = m - 11
a[n - 2][n - 4] = m - 8
a[n - 2][n - 3] = m
a[n - 2][n - 2] = m - 9
a[n - 2][n - 1] = m - 2
a[n - 1][n - 4] = m - 7
a[n - 1][n - 3] = m - 4
a[n - 1][n - 2] = m - 3
a[n - 1][n - 1] = m - 1
prt(a, n)
``` | instruction | 0 | 42,229 | 15 | 84,458 |
Yes | output | 1 | 42,229 | 15 | 84,459 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Egor wants to achieve a rating of 1600 points on the well-known chess portal ChessForces and he needs your help!
Before you start solving the problem, Egor wants to remind you how the chess pieces move. Chess rook moves along straight lines up and down, left and right, as many squares as it wants. And when it wants, it can stop. The queen walks in all directions vertically and diagonally at any distance. You can see the examples below.
<image>
To reach the goal, Egor should research the next topic:
There is an N × N board. Each cell of the board has a number from 1 to N ^ 2 in it and numbers in all cells are distinct.
In the beginning, some chess figure stands in the cell with the number 1. Note that this cell is already considered as visited. After that every move is determined by the following rules:
1. Among all not visited yet cells to which the figure can get in one move, it goes to the cell that has minimal number.
2. If all accessible cells were already visited and some cells are not yet visited, then the figure is teleported to the not visited cell that has minimal number. If this step happens, the piece pays a fee of 1 vun.
3. If all cells are already visited, the process is stopped.
Egor should find an N × N board on which the rook pays strictly less vuns than the queen during the round with this numbering. Help him to find such N × N numbered board, or tell that it doesn't exist.
Input
The only line contains one integer N — the size of the board, 1≤ N ≤ 500.
Output
The output should contain N lines.
In i-th line output N numbers — numbers on the i-th row of the board. All numbers from 1 to N × N must be used exactly once.
On your board rook must pay strictly less vuns than the queen.
If there are no solutions, print -1.
If there are several solutions, you can output any of them.
Examples
Input
1
Output
-1
Input
4
Output
4 3 6 12
7 5 9 15
14 1 11 10
13 8 16 2
Note
In case we have 1 × 1 board, both rook and queen do not have a chance to pay fees.
In second sample rook goes through cells 1 → 3 → 4 → 6 → 9 → 5 → 7 → 13 → 2 → 8 → 16 → 11 → 10 → 12 → 15 → (1 vun) → 14.
Queen goes through 1 → 3 → 4 → 2 → 5 → 6 → 9 → 7 → 13 → 8 → 11 → 10 → 12 → 15 → (1 vun) → 14 → (1 vun) → 16.
As a result rook pays 1 vun and queen pays 2 vuns.
Submitted Solution:
```
n = int(input())
if n < 3:
print(-1)
else:
ans = [[-1 for _ in range(n)] for _ in range(n)]
b = n*n-9
ans[0][0] = b+9
ans[0][1] = b+6
ans[0][2] = b+7
ans[1][0] = b+5
ans[1][1] = b+3
ans[1][2] = b+8
ans[2][0] = b+1
ans[2][1] = b+2
ans[2][2] = b+4
for i in range(3, n):
if i&1:
for j in range(i+1):
ans[i][j] = n*n-i*i-j
for j in range(i-1, -1, -1):
ans[j][i] = n*n-(i+1)*(i+1)+j+1
else:
for j in range(i+1):
ans[j][i] = n*n-i*i-j
for j in range(i-1, -1, -1):
ans[i][j] = n*n-(i+1)*(i+1)+j+1
for x in ans:
print(*x)
``` | instruction | 0 | 42,230 | 15 | 84,460 |
Yes | output | 1 | 42,230 | 15 | 84,461 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Egor wants to achieve a rating of 1600 points on the well-known chess portal ChessForces and he needs your help!
Before you start solving the problem, Egor wants to remind you how the chess pieces move. Chess rook moves along straight lines up and down, left and right, as many squares as it wants. And when it wants, it can stop. The queen walks in all directions vertically and diagonally at any distance. You can see the examples below.
<image>
To reach the goal, Egor should research the next topic:
There is an N × N board. Each cell of the board has a number from 1 to N ^ 2 in it and numbers in all cells are distinct.
In the beginning, some chess figure stands in the cell with the number 1. Note that this cell is already considered as visited. After that every move is determined by the following rules:
1. Among all not visited yet cells to which the figure can get in one move, it goes to the cell that has minimal number.
2. If all accessible cells were already visited and some cells are not yet visited, then the figure is teleported to the not visited cell that has minimal number. If this step happens, the piece pays a fee of 1 vun.
3. If all cells are already visited, the process is stopped.
Egor should find an N × N board on which the rook pays strictly less vuns than the queen during the round with this numbering. Help him to find such N × N numbered board, or tell that it doesn't exist.
Input
The only line contains one integer N — the size of the board, 1≤ N ≤ 500.
Output
The output should contain N lines.
In i-th line output N numbers — numbers on the i-th row of the board. All numbers from 1 to N × N must be used exactly once.
On your board rook must pay strictly less vuns than the queen.
If there are no solutions, print -1.
If there are several solutions, you can output any of them.
Examples
Input
1
Output
-1
Input
4
Output
4 3 6 12
7 5 9 15
14 1 11 10
13 8 16 2
Note
In case we have 1 × 1 board, both rook and queen do not have a chance to pay fees.
In second sample rook goes through cells 1 → 3 → 4 → 6 → 9 → 5 → 7 → 13 → 2 → 8 → 16 → 11 → 10 → 12 → 15 → (1 vun) → 14.
Queen goes through 1 → 3 → 4 → 2 → 5 → 6 → 9 → 7 → 13 → 8 → 11 → 10 → 12 → 15 → (1 vun) → 14 → (1 vun) → 16.
As a result rook pays 1 vun and queen pays 2 vuns.
Submitted Solution:
```
mod = 1000000007
eps = 10**-9
def main():
import sys
input = sys.stdin.readline
N = int(input())
if N <= 2:
print(-1)
exit()
ans = [[0] * N for _ in range(N)]
for h in range(N-1):
if h%2 == 0:
for w in range(N):
ans[h][w] = h * N + w
else:
for w in range(N):
ans[h][N-w-1] = h * N + w
if N%2 == 0:
ans[N-2][N-2], ans[N-2][N-1] = ans[N-2][N-1], ans[N-2][N-2]
else:
ans[N - 2][N - 2], ans[N - 2][0] = ans[N - 2][0], ans[N - 2][N - 2]
ans[N-1][N-1] = N*N - N
for w in range(N-1):
ans[N-1][N-w-2] = N*N-N + w
ans[0][0] = N*N-1
ans[N-1][N-2] = N*N
for h in range(N):
print(*ans[h])
if __name__ == '__main__':
main()
``` | instruction | 0 | 42,231 | 15 | 84,462 |
Yes | output | 1 | 42,231 | 15 | 84,463 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Egor wants to achieve a rating of 1600 points on the well-known chess portal ChessForces and he needs your help!
Before you start solving the problem, Egor wants to remind you how the chess pieces move. Chess rook moves along straight lines up and down, left and right, as many squares as it wants. And when it wants, it can stop. The queen walks in all directions vertically and diagonally at any distance. You can see the examples below.
<image>
To reach the goal, Egor should research the next topic:
There is an N × N board. Each cell of the board has a number from 1 to N ^ 2 in it and numbers in all cells are distinct.
In the beginning, some chess figure stands in the cell with the number 1. Note that this cell is already considered as visited. After that every move is determined by the following rules:
1. Among all not visited yet cells to which the figure can get in one move, it goes to the cell that has minimal number.
2. If all accessible cells were already visited and some cells are not yet visited, then the figure is teleported to the not visited cell that has minimal number. If this step happens, the piece pays a fee of 1 vun.
3. If all cells are already visited, the process is stopped.
Egor should find an N × N board on which the rook pays strictly less vuns than the queen during the round with this numbering. Help him to find such N × N numbered board, or tell that it doesn't exist.
Input
The only line contains one integer N — the size of the board, 1≤ N ≤ 500.
Output
The output should contain N lines.
In i-th line output N numbers — numbers on the i-th row of the board. All numbers from 1 to N × N must be used exactly once.
On your board rook must pay strictly less vuns than the queen.
If there are no solutions, print -1.
If there are several solutions, you can output any of them.
Examples
Input
1
Output
-1
Input
4
Output
4 3 6 12
7 5 9 15
14 1 11 10
13 8 16 2
Note
In case we have 1 × 1 board, both rook and queen do not have a chance to pay fees.
In second sample rook goes through cells 1 → 3 → 4 → 6 → 9 → 5 → 7 → 13 → 2 → 8 → 16 → 11 → 10 → 12 → 15 → (1 vun) → 14.
Queen goes through 1 → 3 → 4 → 2 → 5 → 6 → 9 → 7 → 13 → 8 → 11 → 10 → 12 → 15 → (1 vun) → 14 → (1 vun) → 16.
As a result rook pays 1 vun and queen pays 2 vuns.
Submitted Solution:
```
def main():
for _ in inputt(1):
n, = inputi()
if n <= 2:
print(-1)
continue
A = [[0] * n for i in range(n)]
yie = count(1)
for a in range(n - 3):
for b in range(a, n)[::-1]:
A[a][b] = next(yie)
for b in range(a + 1, n)[::-1]:
A[b][a] = next(yie)
A[n - 3][n - 3] = next(yie)
A[n - 3][n - 2] = next(yie)
A[n - 1][n - 2] = next(yie)
A[n - 1][n - 3] = next(yie)
A[n - 2][n - 2] = next(yie)
A[n - 2][n - 1] = next(yie)
A[n - 3][n - 1] = next(yie)
A[n - 2][n - 3] = next(yie)
A[n - 1][n - 1] = next(yie)
for a in A:
print(*a)
# region M
# region fastio
import sys, io, os
BUFSIZE = 8192
class FastIO(io.IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = io.BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(io.IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
def print(*args, **kwargs):
for x in args:
file.write(str(x))
file.write(kwargs.pop("end", "\n"))
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
# endregion
# region import
inputt = lambda t = 0: range(t) if t else range(int(input()))
inputi = lambda: map(int, input().split())
inputl = lambda: list(inputi())
from math import *
from heapq import *
from bisect import *
from itertools import *
from functools import reduce, lru_cache
from collections import Counter, defaultdict
import re, copy, operator, cmath
from builtins import *
# endregion
# region main
if __name__ == "__main__":
main()
# endregion
# endregion
``` | instruction | 0 | 42,232 | 15 | 84,464 |
Yes | output | 1 | 42,232 | 15 | 84,465 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Egor wants to achieve a rating of 1600 points on the well-known chess portal ChessForces and he needs your help!
Before you start solving the problem, Egor wants to remind you how the chess pieces move. Chess rook moves along straight lines up and down, left and right, as many squares as it wants. And when it wants, it can stop. The queen walks in all directions vertically and diagonally at any distance. You can see the examples below.
<image>
To reach the goal, Egor should research the next topic:
There is an N × N board. Each cell of the board has a number from 1 to N ^ 2 in it and numbers in all cells are distinct.
In the beginning, some chess figure stands in the cell with the number 1. Note that this cell is already considered as visited. After that every move is determined by the following rules:
1. Among all not visited yet cells to which the figure can get in one move, it goes to the cell that has minimal number.
2. If all accessible cells were already visited and some cells are not yet visited, then the figure is teleported to the not visited cell that has minimal number. If this step happens, the piece pays a fee of 1 vun.
3. If all cells are already visited, the process is stopped.
Egor should find an N × N board on which the rook pays strictly less vuns than the queen during the round with this numbering. Help him to find such N × N numbered board, or tell that it doesn't exist.
Input
The only line contains one integer N — the size of the board, 1≤ N ≤ 500.
Output
The output should contain N lines.
In i-th line output N numbers — numbers on the i-th row of the board. All numbers from 1 to N × N must be used exactly once.
On your board rook must pay strictly less vuns than the queen.
If there are no solutions, print -1.
If there are several solutions, you can output any of them.
Examples
Input
1
Output
-1
Input
4
Output
4 3 6 12
7 5 9 15
14 1 11 10
13 8 16 2
Note
In case we have 1 × 1 board, both rook and queen do not have a chance to pay fees.
In second sample rook goes through cells 1 → 3 → 4 → 6 → 9 → 5 → 7 → 13 → 2 → 8 → 16 → 11 → 10 → 12 → 15 → (1 vun) → 14.
Queen goes through 1 → 3 → 4 → 2 → 5 → 6 → 9 → 7 → 13 → 8 → 11 → 10 → 12 → 15 → (1 vun) → 14 → (1 vun) → 16.
As a result rook pays 1 vun and queen pays 2 vuns.
Submitted Solution:
```
n = int(input())
a = [[0 for j in range(n)] for i in range(n)]
def prt(a, n):
for i in range(n):
print(*a[i])
if n == 3:
a = [[7, 5, 4], [8, 6, 9], [1, 2, 3]]
elif n < 4:
print(-1)
elif n == 4:
a[0] = [1, 2, 3, 4]
elif n % 2 == 1:
z = 1
for i in range(n - 3):
for j in range(n):
if i % 2 == 0:
a[i][j] = z
else:
a[i][n - j - 1] = z
z += 1
a[n - 1][0] = z
z += 1
a[n - 2][0] = z
z += 1
a[n - 3][0] = z
for j in range(1, n - 4):
a[n - 3][j] = z
z += 1
a[n - 2][j] = z
z += 1
a[n - 1][j] = z
z += 1
if j % 2 == 1:
a[n - 3][j], a[n - 1][j] = a[n - 1][j], a[n - 3][j]
elif n % 2 == 0:
for i in range(n - 3):
for j in range(n):
if i % 2 == 1:
a[i][j] = z
else:
a[i][n - j - 1] = z
z += 1
for j in range(n - 4):
a[n - 3][j] = z
z += 1
a[n - 2][j] = z
z += 1
a[n - 1][j] = z
z += 1
if j % 2 == 1:
a[n - 3][j], a[n - 1][j] = a[n - 1][j], a[n - 3][j]
if n >= 4:
m = n ** 2
a[n - 3][n - 4] = m - 6
a[n - 3][n - 3] = m - 5
a[n - 3][n - 2] = m - 10
a[n - 3][n - 1] = m - 11
a[n - 2][n - 4] = m - 8
a[n - 2][n - 3] = m
a[n - 2][n - 2] = m - 9
a[n - 2][n - 1] = m - 2
a[n - 1][n - 4] = m - 7
a[n - 1][n - 3] = m - 4
a[n - 1][n - 2] = m - 3
a[n - 1][n - 1] = m - 1
prt(a, n)
``` | instruction | 0 | 42,233 | 15 | 84,466 |
No | output | 1 | 42,233 | 15 | 84,467 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Egor wants to achieve a rating of 1600 points on the well-known chess portal ChessForces and he needs your help!
Before you start solving the problem, Egor wants to remind you how the chess pieces move. Chess rook moves along straight lines up and down, left and right, as many squares as it wants. And when it wants, it can stop. The queen walks in all directions vertically and diagonally at any distance. You can see the examples below.
<image>
To reach the goal, Egor should research the next topic:
There is an N × N board. Each cell of the board has a number from 1 to N ^ 2 in it and numbers in all cells are distinct.
In the beginning, some chess figure stands in the cell with the number 1. Note that this cell is already considered as visited. After that every move is determined by the following rules:
1. Among all not visited yet cells to which the figure can get in one move, it goes to the cell that has minimal number.
2. If all accessible cells were already visited and some cells are not yet visited, then the figure is teleported to the not visited cell that has minimal number. If this step happens, the piece pays a fee of 1 vun.
3. If all cells are already visited, the process is stopped.
Egor should find an N × N board on which the rook pays strictly less vuns than the queen during the round with this numbering. Help him to find such N × N numbered board, or tell that it doesn't exist.
Input
The only line contains one integer N — the size of the board, 1≤ N ≤ 500.
Output
The output should contain N lines.
In i-th line output N numbers — numbers on the i-th row of the board. All numbers from 1 to N × N must be used exactly once.
On your board rook must pay strictly less vuns than the queen.
If there are no solutions, print -1.
If there are several solutions, you can output any of them.
Examples
Input
1
Output
-1
Input
4
Output
4 3 6 12
7 5 9 15
14 1 11 10
13 8 16 2
Note
In case we have 1 × 1 board, both rook and queen do not have a chance to pay fees.
In second sample rook goes through cells 1 → 3 → 4 → 6 → 9 → 5 → 7 → 13 → 2 → 8 → 16 → 11 → 10 → 12 → 15 → (1 vun) → 14.
Queen goes through 1 → 3 → 4 → 2 → 5 → 6 → 9 → 7 → 13 → 8 → 11 → 10 → 12 → 15 → (1 vun) → 14 → (1 vun) → 16.
As a result rook pays 1 vun and queen pays 2 vuns.
Submitted Solution:
```
def main():
L = [[0 for _ in range(501)]for _ in range(501)]
n = int(input())
if(n<=2):
print(-1)
return
lf = 1
rt = n
id = n
cur = 1
direct = 1
cnt = 0
if(n%2==1): direct = -1;cur=n
while(id>0):
cnt+=1
L[id][cur]=cnt
if(cur+direct >= lf and cur+direct <=rt): cur+=direct
else: id-=1;direct*=-1
if(id==3): lf = 4
L[1][1]=9+cnt
L[1][2]=1+cnt
L[1][3]=2+cnt
L[2][1]=7+cnt
L[2][2]=8+cnt
L[2][3]=3+cnt
L[3][1]=6+cnt
L[3][2]=5+cnt
L[3][3]=4+cnt
for i in range(1,n+1):
for j in range(1,n+1):
print(L[i][j],end=" ")
print()
main()
``` | instruction | 0 | 42,234 | 15 | 84,468 |
No | output | 1 | 42,234 | 15 | 84,469 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Egor wants to achieve a rating of 1600 points on the well-known chess portal ChessForces and he needs your help!
Before you start solving the problem, Egor wants to remind you how the chess pieces move. Chess rook moves along straight lines up and down, left and right, as many squares as it wants. And when it wants, it can stop. The queen walks in all directions vertically and diagonally at any distance. You can see the examples below.
<image>
To reach the goal, Egor should research the next topic:
There is an N × N board. Each cell of the board has a number from 1 to N ^ 2 in it and numbers in all cells are distinct.
In the beginning, some chess figure stands in the cell with the number 1. Note that this cell is already considered as visited. After that every move is determined by the following rules:
1. Among all not visited yet cells to which the figure can get in one move, it goes to the cell that has minimal number.
2. If all accessible cells were already visited and some cells are not yet visited, then the figure is teleported to the not visited cell that has minimal number. If this step happens, the piece pays a fee of 1 vun.
3. If all cells are already visited, the process is stopped.
Egor should find an N × N board on which the rook pays strictly less vuns than the queen during the round with this numbering. Help him to find such N × N numbered board, or tell that it doesn't exist.
Input
The only line contains one integer N — the size of the board, 1≤ N ≤ 500.
Output
The output should contain N lines.
In i-th line output N numbers — numbers on the i-th row of the board. All numbers from 1 to N × N must be used exactly once.
On your board rook must pay strictly less vuns than the queen.
If there are no solutions, print -1.
If there are several solutions, you can output any of them.
Examples
Input
1
Output
-1
Input
4
Output
4 3 6 12
7 5 9 15
14 1 11 10
13 8 16 2
Note
In case we have 1 × 1 board, both rook and queen do not have a chance to pay fees.
In second sample rook goes through cells 1 → 3 → 4 → 6 → 9 → 5 → 7 → 13 → 2 → 8 → 16 → 11 → 10 → 12 → 15 → (1 vun) → 14.
Queen goes through 1 → 3 → 4 → 2 → 5 → 6 → 9 → 7 → 13 → 8 → 11 → 10 → 12 → 15 → (1 vun) → 14 → (1 vun) → 16.
As a result rook pays 1 vun and queen pays 2 vuns.
Submitted Solution:
```
print('?')
``` | instruction | 0 | 42,235 | 15 | 84,470 |
No | output | 1 | 42,235 | 15 | 84,471 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Egor wants to achieve a rating of 1600 points on the well-known chess portal ChessForces and he needs your help!
Before you start solving the problem, Egor wants to remind you how the chess pieces move. Chess rook moves along straight lines up and down, left and right, as many squares as it wants. And when it wants, it can stop. The queen walks in all directions vertically and diagonally at any distance. You can see the examples below.
<image>
To reach the goal, Egor should research the next topic:
There is an N × N board. Each cell of the board has a number from 1 to N ^ 2 in it and numbers in all cells are distinct.
In the beginning, some chess figure stands in the cell with the number 1. Note that this cell is already considered as visited. After that every move is determined by the following rules:
1. Among all not visited yet cells to which the figure can get in one move, it goes to the cell that has minimal number.
2. If all accessible cells were already visited and some cells are not yet visited, then the figure is teleported to the not visited cell that has minimal number. If this step happens, the piece pays a fee of 1 vun.
3. If all cells are already visited, the process is stopped.
Egor should find an N × N board on which the rook pays strictly less vuns than the queen during the round with this numbering. Help him to find such N × N numbered board, or tell that it doesn't exist.
Input
The only line contains one integer N — the size of the board, 1≤ N ≤ 500.
Output
The output should contain N lines.
In i-th line output N numbers — numbers on the i-th row of the board. All numbers from 1 to N × N must be used exactly once.
On your board rook must pay strictly less vuns than the queen.
If there are no solutions, print -1.
If there are several solutions, you can output any of them.
Examples
Input
1
Output
-1
Input
4
Output
4 3 6 12
7 5 9 15
14 1 11 10
13 8 16 2
Note
In case we have 1 × 1 board, both rook and queen do not have a chance to pay fees.
In second sample rook goes through cells 1 → 3 → 4 → 6 → 9 → 5 → 7 → 13 → 2 → 8 → 16 → 11 → 10 → 12 → 15 → (1 vun) → 14.
Queen goes through 1 → 3 → 4 → 2 → 5 → 6 → 9 → 7 → 13 → 8 → 11 → 10 → 12 → 15 → (1 vun) → 14 → (1 vun) → 16.
As a result rook pays 1 vun and queen pays 2 vuns.
Submitted Solution:
```
def main():
n = int(input())
if n<3:
print(-1)
return
solution = [1,3,4,8,2,7,9,5,6]
table = [[0 for _ in range(n)] for _ in range(n)]
cur = 1
for i in range(n-3):
if i&1:
for j in range(n-1,-1,-1):
table[i][j] = cur
cur += 1
else:
for j in range(n):
table[i][j] = cur
cur += 1
if (n-3)&1:
for j in range(n-1,-1,-1):
if j&1:
for i in range(n-3,n):
if j>2:
table[i][j] = cur
cur += 1
else:
table[i][j] = solution[(2-j)*3+i-n+3]+n*n-9
else:
for i in range(n-1,n-4,-1):
if j>2:
table[i][j] = cur
cur += 1
else:
table[i][j] = solution[(j-n+3)*3+n-1-i]+n*n-9
else:
for j in range(n):
if j&1:
for i in range(n-1,n-4,-1):
if j<n-3:
table[i][j] = cur
else:
table[i][j] = solution[(j-n+3)*3+i-n+3]+n*n-9
else:
for i in range(n-3,n):
if j<n-3:
table[i][j] = cur
cur += 1
else:
table[i][j] = solution[(j-n+3)*3+i-n+3]+n*n-9
for i in range(n):
print(*table[i])
if __name__ == '__main__':
main()
``` | instruction | 0 | 42,236 | 15 | 84,472 |
No | output | 1 | 42,236 | 15 | 84,473 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a chessboard consisting of n rows and n columns. Rows are numbered from bottom to top from 1 to n. Columns are numbered from left to right from 1 to n. The cell at the intersection of the x-th column and the y-th row is denoted as (x, y). Furthermore, the k-th column is a special column.
Initially, the board is empty. There are m changes to the board. During the i-th change one pawn is added or removed from the board. The current board is good if we can move all pawns to the special column by the followings rules:
* Pawn in the cell (x, y) can be moved to the cell (x, y + 1), (x - 1, y + 1) or (x + 1, y + 1);
* You can make as many such moves as you like;
* Pawns can not be moved outside the chessboard;
* Each cell can not contain more than one pawn.
The current board may not always be good. To fix it, you can add new rows to the board. New rows are added at the top, i. e. they will have numbers n+1, n+2, n+3, ....
After each of m changes, print one integer — the minimum number of rows which you have to add to make the board good.
Input
The first line contains three integers n, k and m (1 ≤ n, m ≤ 2 ⋅ 10^5; 1 ≤ k ≤ n) — the size of the board, the index of the special column and the number of changes respectively.
Then m lines follow. The i-th line contains two integers x and y (1 ≤ x, y ≤ n) — the index of the column and the index of the row respectively. If there is no pawn in the cell (x, y), then you add a pawn to this cell, otherwise — you remove the pawn from this cell.
Output
After each change print one integer — the minimum number of rows which you have to add to make the board good.
Example
Input
5 3 5
4 4
3 5
2 4
3 4
3 5
Output
0
1
2
2
1 | instruction | 0 | 42,254 | 15 | 84,508 |
Tags: data structures, divide and conquer, greedy
Correct Solution:
```
import collections
import math
n, k, m = [int(i) for i in input().split()]
l = math.ceil((math.log(2*n) / math.log(2)))
p = 2 ** l
# print(p)
memo = [0] * (2 * p)
allres = [0] * (2 * p)
exist = set()
for _i in range(m):
x, y = [int(i) for i in input().split()]
l = abs(x - k) + y
index = l + p
if (x, y) in exist:
exist.remove((x, y))
while index != 0:
memo[index] -= 1
index = index // 2
else:
exist.add((x, y))
while index != 0:
memo[index] += 1
index = index // 2
index = (l + p) // 2
allres[l+p] = l + memo[l + p] - 1
if memo[l + p] == 0:
allres[l+p] = 0
while index != 0:
allres[index] = max(allres[index * 2] + memo[index * 2 + 1], allres[index * 2 + 1])
index = index // 2
# print('i', _i + 1, exist, allres, memo)
print (max(allres[1] - n, 0))
``` | output | 1 | 42,254 | 15 | 84,509 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a chessboard consisting of n rows and n columns. Rows are numbered from bottom to top from 1 to n. Columns are numbered from left to right from 1 to n. The cell at the intersection of the x-th column and the y-th row is denoted as (x, y). Furthermore, the k-th column is a special column.
Initially, the board is empty. There are m changes to the board. During the i-th change one pawn is added or removed from the board. The current board is good if we can move all pawns to the special column by the followings rules:
* Pawn in the cell (x, y) can be moved to the cell (x, y + 1), (x - 1, y + 1) or (x + 1, y + 1);
* You can make as many such moves as you like;
* Pawns can not be moved outside the chessboard;
* Each cell can not contain more than one pawn.
The current board may not always be good. To fix it, you can add new rows to the board. New rows are added at the top, i. e. they will have numbers n+1, n+2, n+3, ....
After each of m changes, print one integer — the minimum number of rows which you have to add to make the board good.
Input
The first line contains three integers n, k and m (1 ≤ n, m ≤ 2 ⋅ 10^5; 1 ≤ k ≤ n) — the size of the board, the index of the special column and the number of changes respectively.
Then m lines follow. The i-th line contains two integers x and y (1 ≤ x, y ≤ n) — the index of the column and the index of the row respectively. If there is no pawn in the cell (x, y), then you add a pawn to this cell, otherwise — you remove the pawn from this cell.
Output
After each change print one integer — the minimum number of rows which you have to add to make the board good.
Example
Input
5 3 5
4 4
3 5
2 4
3 4
3 5
Output
0
1
2
2
1 | instruction | 0 | 42,255 | 15 | 84,510 |
Tags: data structures, divide and conquer, greedy
Correct Solution:
```
import collections
import math
n, k, m = [int(i) for i in input().split()]
l = math.ceil((math.log(2*n) / math.log(2)))
p = 2 ** l
memo = [0] * (2 * p)
allres = [0] * (2 * p)
exist = set()
for _i in range(m):
x, y = [int(i) for i in input().split()]
l = abs(x - k) + y
index = l + p
if (x, y) in exist:
exist.remove((x, y))
while index != 0:memo[index] -= 1;index = index // 2
else:
exist.add((x, y))
while index != 0:memo[index] += 1;index = index // 2
index = (l + p) // 2
allres[l+p] = l + memo[l + p] - 1
if memo[l + p] == 0:allres[l+p] = 0
while index != 0:allres[index] = max(allres[index * 2] + memo[index * 2 + 1], allres[index * 2 + 1]);index = index // 2
print (max(allres[1] - n, 0))
``` | output | 1 | 42,255 | 15 | 84,511 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a chessboard consisting of n rows and n columns. Rows are numbered from bottom to top from 1 to n. Columns are numbered from left to right from 1 to n. The cell at the intersection of the x-th column and the y-th row is denoted as (x, y). Furthermore, the k-th column is a special column.
Initially, the board is empty. There are m changes to the board. During the i-th change one pawn is added or removed from the board. The current board is good if we can move all pawns to the special column by the followings rules:
* Pawn in the cell (x, y) can be moved to the cell (x, y + 1), (x - 1, y + 1) or (x + 1, y + 1);
* You can make as many such moves as you like;
* Pawns can not be moved outside the chessboard;
* Each cell can not contain more than one pawn.
The current board may not always be good. To fix it, you can add new rows to the board. New rows are added at the top, i. e. they will have numbers n+1, n+2, n+3, ....
After each of m changes, print one integer — the minimum number of rows which you have to add to make the board good.
Input
The first line contains three integers n, k and m (1 ≤ n, m ≤ 2 ⋅ 10^5; 1 ≤ k ≤ n) — the size of the board, the index of the special column and the number of changes respectively.
Then m lines follow. The i-th line contains two integers x and y (1 ≤ x, y ≤ n) — the index of the column and the index of the row respectively. If there is no pawn in the cell (x, y), then you add a pawn to this cell, otherwise — you remove the pawn from this cell.
Output
After each change print one integer — the minimum number of rows which you have to add to make the board good.
Example
Input
5 3 5
4 4
3 5
2 4
3 4
3 5
Output
0
1
2
2
1 | instruction | 0 | 42,256 | 15 | 84,512 |
Tags: data structures, divide and conquer, greedy
Correct Solution:
```
import math
n, k, m = [int(i) for i in input().split()]
l = math.ceil((math.log(2*n) / math.log(2)))
p = 2 ** l;memo = [0] * (2 * p);allres = [0] * (2 * p);exist = set()
for _i in range(m):
x, y = [int(i) for i in input().split()];l = abs(x - k) + y;index = l + p
if (x, y) in exist:
exist.remove((x, y))
while index != 0:memo[index] -= 1;index = index // 2
else:
exist.add((x, y))
while index != 0:memo[index] += 1;index = index // 2
index = (l + p) // 2;allres[l+p] = l + memo[l + p] - 1
if memo[l + p] == 0:allres[l+p] = 0
while index != 0:allres[index] = max(allres[index * 2] + memo[index * 2 + 1], allres[index * 2 + 1]);index = index // 2
print (max(allres[1] - n, 0))
``` | output | 1 | 42,256 | 15 | 84,513 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a chessboard consisting of n rows and n columns. Rows are numbered from bottom to top from 1 to n. Columns are numbered from left to right from 1 to n. The cell at the intersection of the x-th column and the y-th row is denoted as (x, y). Furthermore, the k-th column is a special column.
Initially, the board is empty. There are m changes to the board. During the i-th change one pawn is added or removed from the board. The current board is good if we can move all pawns to the special column by the followings rules:
* Pawn in the cell (x, y) can be moved to the cell (x, y + 1), (x - 1, y + 1) or (x + 1, y + 1);
* You can make as many such moves as you like;
* Pawns can not be moved outside the chessboard;
* Each cell can not contain more than one pawn.
The current board may not always be good. To fix it, you can add new rows to the board. New rows are added at the top, i. e. they will have numbers n+1, n+2, n+3, ....
After each of m changes, print one integer — the minimum number of rows which you have to add to make the board good.
Input
The first line contains three integers n, k and m (1 ≤ n, m ≤ 2 ⋅ 10^5; 1 ≤ k ≤ n) — the size of the board, the index of the special column and the number of changes respectively.
Then m lines follow. The i-th line contains two integers x and y (1 ≤ x, y ≤ n) — the index of the column and the index of the row respectively. If there is no pawn in the cell (x, y), then you add a pawn to this cell, otherwise — you remove the pawn from this cell.
Output
After each change print one integer — the minimum number of rows which you have to add to make the board good.
Example
Input
5 3 5
4 4
3 5
2 4
3 4
3 5
Output
0
1
2
2
1
Submitted Solution:
```
n, k, m = list(map(int, input().split(' ')))
board = [[0]*n for _ in range(n)]
entries = {}
curr_key = 1
for i in range(m):
row = input()
x, y = list(map(int, row.split(' ')))
if board[x-1][y-1] == 0:
board[x-1][y-1] = curr_key
curr_key += 1
entries[board[x-1][y-1]] = y+abs(x-k)-n
else:
del entries[board[x-1][y-1]]
board[x-1][y-1] = 0
if len(entries) == 0:
print(0)
else:
acc = min(entries.values())
for e in sorted(entries)[1:]:
if e <= acc:
acc += 1
else:
acc = e
print(max(0, acc))
``` | instruction | 0 | 42,257 | 15 | 84,514 |
No | output | 1 | 42,257 | 15 | 84,515 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a chessboard consisting of n rows and n columns. Rows are numbered from bottom to top from 1 to n. Columns are numbered from left to right from 1 to n. The cell at the intersection of the x-th column and the y-th row is denoted as (x, y). Furthermore, the k-th column is a special column.
Initially, the board is empty. There are m changes to the board. During the i-th change one pawn is added or removed from the board. The current board is good if we can move all pawns to the special column by the followings rules:
* Pawn in the cell (x, y) can be moved to the cell (x, y + 1), (x - 1, y + 1) or (x + 1, y + 1);
* You can make as many such moves as you like;
* Pawns can not be moved outside the chessboard;
* Each cell can not contain more than one pawn.
The current board may not always be good. To fix it, you can add new rows to the board. New rows are added at the top, i. e. they will have numbers n+1, n+2, n+3, ....
After each of m changes, print one integer — the minimum number of rows which you have to add to make the board good.
Input
The first line contains three integers n, k and m (1 ≤ n, m ≤ 2 ⋅ 10^5; 1 ≤ k ≤ n) — the size of the board, the index of the special column and the number of changes respectively.
Then m lines follow. The i-th line contains two integers x and y (1 ≤ x, y ≤ n) — the index of the column and the index of the row respectively. If there is no pawn in the cell (x, y), then you add a pawn to this cell, otherwise — you remove the pawn from this cell.
Output
After each change print one integer — the minimum number of rows which you have to add to make the board good.
Example
Input
5 3 5
4 4
3 5
2 4
3 4
3 5
Output
0
1
2
2
1
Submitted Solution:
```
n, k, m = [int(i) for i in input().split(' ')]
a = []
matr = [[0 for i in range(n)] for j in range(n)]
height = [0 for i in range((max(k, n - 1 - k) + n - 1) * 2)]
#print(len(height))
for q in range(m):
x, y = [int(i) - 1 for i in input().split(' ')]
h = abs(k - x) + y
if matr[x][y] == 0:
matr[x][y] = 1
a.append([x, y, h])
height[h] += 1
else:
matr[x][y] = 0
a.remove([x, y, h])
height[h] -= 1
last = 0
heights = height.copy()
for i in range(1, len(heights)):
if heights[i - 1] > 0:
heights[i] += heights[i - 1] - 1
heights[i - 1] = 1
if heights[i] > 0:
last = i
last -= 1
#print(last)
print(max(last - n + 1, 0))
#print()
``` | instruction | 0 | 42,258 | 15 | 84,516 |
No | output | 1 | 42,258 | 15 | 84,517 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a chessboard consisting of n rows and n columns. Rows are numbered from bottom to top from 1 to n. Columns are numbered from left to right from 1 to n. The cell at the intersection of the x-th column and the y-th row is denoted as (x, y). Furthermore, the k-th column is a special column.
Initially, the board is empty. There are m changes to the board. During the i-th change one pawn is added or removed from the board. The current board is good if we can move all pawns to the special column by the followings rules:
* Pawn in the cell (x, y) can be moved to the cell (x, y + 1), (x - 1, y + 1) or (x + 1, y + 1);
* You can make as many such moves as you like;
* Pawns can not be moved outside the chessboard;
* Each cell can not contain more than one pawn.
The current board may not always be good. To fix it, you can add new rows to the board. New rows are added at the top, i. e. they will have numbers n+1, n+2, n+3, ....
After each of m changes, print one integer — the minimum number of rows which you have to add to make the board good.
Input
The first line contains three integers n, k and m (1 ≤ n, m ≤ 2 ⋅ 10^5; 1 ≤ k ≤ n) — the size of the board, the index of the special column and the number of changes respectively.
Then m lines follow. The i-th line contains two integers x and y (1 ≤ x, y ≤ n) — the index of the column and the index of the row respectively. If there is no pawn in the cell (x, y), then you add a pawn to this cell, otherwise — you remove the pawn from this cell.
Output
After each change print one integer — the minimum number of rows which you have to add to make the board good.
Example
Input
5 3 5
4 4
3 5
2 4
3 4
3 5
Output
0
1
2
2
1
Submitted Solution:
```
n, k, m = [int(i) for i in input().split(' ')]
a = []
matr = [[0 for i in range(n)] for j in range(n)]
height = [0 for i in range((max(k, n - 1 - k) + n - 1) * 2)]
#print(len(height))
for q in range(m):
x, y = [int(i) - 1 for i in input().split(' ')]
h = abs(k - x) + y
if matr[x][y] == 0:
matr[x][y] = 1
a.append([x, y, h])
height[h] += 1
else:
matr[x][y] = 0
a.remove([x, y, h])
height[h] -= 1
last = 0
heights = height.copy()
for i in range(1, len(heights)):
if heights[i - 1] > 0:
heights[i] += heights[i - 1] - 1
heights[i - 1] = 1
if heights[i] > 0:
last = i
#print(last)
print(max(last - n + 1, 0))
#print()
``` | instruction | 0 | 42,259 | 15 | 84,518 |
No | output | 1 | 42,259 | 15 | 84,519 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a chessboard consisting of n rows and n columns. Rows are numbered from bottom to top from 1 to n. Columns are numbered from left to right from 1 to n. The cell at the intersection of the x-th column and the y-th row is denoted as (x, y). Furthermore, the k-th column is a special column.
Initially, the board is empty. There are m changes to the board. During the i-th change one pawn is added or removed from the board. The current board is good if we can move all pawns to the special column by the followings rules:
* Pawn in the cell (x, y) can be moved to the cell (x, y + 1), (x - 1, y + 1) or (x + 1, y + 1);
* You can make as many such moves as you like;
* Pawns can not be moved outside the chessboard;
* Each cell can not contain more than one pawn.
The current board may not always be good. To fix it, you can add new rows to the board. New rows are added at the top, i. e. they will have numbers n+1, n+2, n+3, ....
After each of m changes, print one integer — the minimum number of rows which you have to add to make the board good.
Input
The first line contains three integers n, k and m (1 ≤ n, m ≤ 2 ⋅ 10^5; 1 ≤ k ≤ n) — the size of the board, the index of the special column and the number of changes respectively.
Then m lines follow. The i-th line contains two integers x and y (1 ≤ x, y ≤ n) — the index of the column and the index of the row respectively. If there is no pawn in the cell (x, y), then you add a pawn to this cell, otherwise — you remove the pawn from this cell.
Output
After each change print one integer — the minimum number of rows which you have to add to make the board good.
Example
Input
5 3 5
4 4
3 5
2 4
3 4
3 5
Output
0
1
2
2
1
Submitted Solution:
```
n, k, m = list(map(int, input().split()))
pawns = []
for i in range(m):
line = [False] * (n + 1)
add = 0
x, y = list(map(int, input().split()))
if [x, y] in pawns:
pawns.pop(pawns.index([x, y]))
else:
pawns.append([x, y])
for pawn in pawns:
d = pawn[1] + abs(k - pawn[0])
if d > len(line) - 1:
add += d - len(line) + 1
line += [False] * (d - len(line) - 1)
line.append(True)
else:
if line[d]:
ok = False
for j in range(d, len(line) - 2):
if not line[j]:
line[j] = True
ok = True
if not ok:
add += 1
line += [True]
else:
line[d] = True
print(add)
``` | instruction | 0 | 42,260 | 15 | 84,520 |
No | output | 1 | 42,260 | 15 | 84,521 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya decided to learn to play chess. Classic chess doesn't seem interesting to him, so he plays his own sort of chess.
The queen is the piece that captures all squares on its vertical, horizontal and diagonal lines. If the cell is located on the same vertical, horizontal or diagonal line with queen, and the cell contains a piece of the enemy color, the queen is able to move to this square. After that the enemy's piece is removed from the board. The queen cannot move to a cell containing an enemy piece if there is some other piece between it and the queen.
There is an n × n chessboard. We'll denote a cell on the intersection of the r-th row and c-th column as (r, c). The square (1, 1) contains the white queen and the square (1, n) contains the black queen. All other squares contain green pawns that don't belong to anyone.
The players move in turns. The player that moves first plays for the white queen, his opponent plays for the black queen.
On each move the player has to capture some piece with his queen (that is, move to a square that contains either a green pawn or the enemy queen). The player loses if either he cannot capture any piece during his move or the opponent took his queen during the previous move.
Help Vasya determine who wins if both players play with an optimal strategy on the board n × n.
Input
The input contains a single number n (2 ≤ n ≤ 109) — the size of the board.
Output
On the first line print the answer to problem — string "white" or string "black", depending on who wins if the both players play optimally.
If the answer is "white", then you should also print two integers r and c representing the cell (r, c), where the first player should make his first move to win. If there are multiple such cells, print the one with the minimum r. If there are still multiple squares, print the one with the minimum c.
Examples
Input
2
Output
white
1 2
Input
3
Output
black
Note
In the first sample test the white queen can capture the black queen at the first move, so the white player wins.
In the second test from the statement if the white queen captures the green pawn located on the central vertical line, then it will be captured by the black queen during the next move. So the only move for the white player is to capture the green pawn located at (2, 1).
Similarly, the black queen doesn't have any other options but to capture the green pawn located at (2, 3), otherwise if it goes to the middle vertical line, it will be captured by the white queen.
During the next move the same thing happens — neither the white, nor the black queen has other options rather than to capture green pawns situated above them. Thus, the white queen ends up on square (3, 1), and the black queen ends up on square (3, 3).
In this situation the white queen has to capture any of the green pawns located on the middle vertical line, after that it will be captured by the black queen. Thus, the player who plays for the black queen wins. | instruction | 0 | 42,454 | 15 | 84,908 |
Tags: constructive algorithms, games, math
Correct Solution:
```
n=int(input())
if n%2:
print("black")
else:
print("white")
print("1 2")
``` | output | 1 | 42,454 | 15 | 84,909 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya decided to learn to play chess. Classic chess doesn't seem interesting to him, so he plays his own sort of chess.
The queen is the piece that captures all squares on its vertical, horizontal and diagonal lines. If the cell is located on the same vertical, horizontal or diagonal line with queen, and the cell contains a piece of the enemy color, the queen is able to move to this square. After that the enemy's piece is removed from the board. The queen cannot move to a cell containing an enemy piece if there is some other piece between it and the queen.
There is an n × n chessboard. We'll denote a cell on the intersection of the r-th row and c-th column as (r, c). The square (1, 1) contains the white queen and the square (1, n) contains the black queen. All other squares contain green pawns that don't belong to anyone.
The players move in turns. The player that moves first plays for the white queen, his opponent plays for the black queen.
On each move the player has to capture some piece with his queen (that is, move to a square that contains either a green pawn or the enemy queen). The player loses if either he cannot capture any piece during his move or the opponent took his queen during the previous move.
Help Vasya determine who wins if both players play with an optimal strategy on the board n × n.
Input
The input contains a single number n (2 ≤ n ≤ 109) — the size of the board.
Output
On the first line print the answer to problem — string "white" or string "black", depending on who wins if the both players play optimally.
If the answer is "white", then you should also print two integers r and c representing the cell (r, c), where the first player should make his first move to win. If there are multiple such cells, print the one with the minimum r. If there are still multiple squares, print the one with the minimum c.
Examples
Input
2
Output
white
1 2
Input
3
Output
black
Note
In the first sample test the white queen can capture the black queen at the first move, so the white player wins.
In the second test from the statement if the white queen captures the green pawn located on the central vertical line, then it will be captured by the black queen during the next move. So the only move for the white player is to capture the green pawn located at (2, 1).
Similarly, the black queen doesn't have any other options but to capture the green pawn located at (2, 3), otherwise if it goes to the middle vertical line, it will be captured by the white queen.
During the next move the same thing happens — neither the white, nor the black queen has other options rather than to capture green pawns situated above them. Thus, the white queen ends up on square (3, 1), and the black queen ends up on square (3, 3).
In this situation the white queen has to capture any of the green pawns located on the middle vertical line, after that it will be captured by the black queen. Thus, the player who plays for the black queen wins. | instruction | 0 | 42,455 | 15 | 84,910 |
Tags: constructive algorithms, games, math
Correct Solution:
```
n=int(input());
if n % 2 == 1:
print("black")
else :
print("white")
print("1 2")
``` | output | 1 | 42,455 | 15 | 84,911 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya decided to learn to play chess. Classic chess doesn't seem interesting to him, so he plays his own sort of chess.
The queen is the piece that captures all squares on its vertical, horizontal and diagonal lines. If the cell is located on the same vertical, horizontal or diagonal line with queen, and the cell contains a piece of the enemy color, the queen is able to move to this square. After that the enemy's piece is removed from the board. The queen cannot move to a cell containing an enemy piece if there is some other piece between it and the queen.
There is an n × n chessboard. We'll denote a cell on the intersection of the r-th row and c-th column as (r, c). The square (1, 1) contains the white queen and the square (1, n) contains the black queen. All other squares contain green pawns that don't belong to anyone.
The players move in turns. The player that moves first plays for the white queen, his opponent plays for the black queen.
On each move the player has to capture some piece with his queen (that is, move to a square that contains either a green pawn or the enemy queen). The player loses if either he cannot capture any piece during his move or the opponent took his queen during the previous move.
Help Vasya determine who wins if both players play with an optimal strategy on the board n × n.
Input
The input contains a single number n (2 ≤ n ≤ 109) — the size of the board.
Output
On the first line print the answer to problem — string "white" or string "black", depending on who wins if the both players play optimally.
If the answer is "white", then you should also print two integers r and c representing the cell (r, c), where the first player should make his first move to win. If there are multiple such cells, print the one with the minimum r. If there are still multiple squares, print the one with the minimum c.
Examples
Input
2
Output
white
1 2
Input
3
Output
black
Note
In the first sample test the white queen can capture the black queen at the first move, so the white player wins.
In the second test from the statement if the white queen captures the green pawn located on the central vertical line, then it will be captured by the black queen during the next move. So the only move for the white player is to capture the green pawn located at (2, 1).
Similarly, the black queen doesn't have any other options but to capture the green pawn located at (2, 3), otherwise if it goes to the middle vertical line, it will be captured by the white queen.
During the next move the same thing happens — neither the white, nor the black queen has other options rather than to capture green pawns situated above them. Thus, the white queen ends up on square (3, 1), and the black queen ends up on square (3, 3).
In this situation the white queen has to capture any of the green pawns located on the middle vertical line, after that it will be captured by the black queen. Thus, the player who plays for the black queen wins. | instruction | 0 | 42,456 | 15 | 84,912 |
Tags: constructive algorithms, games, math
Correct Solution:
```
import sys
import os
# import numpy as np
from math import sqrt, gcd, ceil, log, floor, sin, pi
from math import factorial as fact
from bisect import bisect, bisect_left
from collections import defaultdict, Counter, deque
from heapq import heapify, heappush, heappop
from itertools import permutations
input = sys.stdin.readline
def read(): return list(map(int, input().strip().split()))
def read_f(): return list(map(float, input().strip().split()))
# read_f = lambda file: list(map(int, file.readline().strip().split()))
# from time import time
# sys.setrecursionlimit(5*10**6)
MOD = 10**9 + 7
def build(arr):
n = len(arr)
tree = [[0,0]for i in range(2*n - 1)]
for i in range(n):
tree[n+i-1][0] = arr[i]
for i in range(n-2, -1, -1):
x = tree[i*2+1][1]
if x:
tree[i][0] = tree[i*2+1][0] ^ tree[i*2+2][0]
tree[i][1] = 0
else:
tree[i][0] = tree[i*2+1][0] | tree[i*2+2][0]
tree[i][1] = 1
return(tree)
def update(tree, ind, val, n):
ind = n+ind-1
tree[ind][0] = val
while ind > 0:
par = (ind-1)>>1
x = tree[(par<<1) + 1][1]
if x:
tree[par][0] = tree[(par<<1) + 1][0] ^ tree[(par<<1) + 2][0]
else:
tree[par][0] = tree[(par<<1) + 1][0] | tree[(par<<1) + 2][0]
ind = (ind-1)>>1
def main():
# file1 = open("C:\\Users\\shank\\Desktop\\Comp_Code\\input.txt", "r")
# n = int(file1.readline().strip());
# par = list(map(int, file1.read().strip().split(" ")))
# file1.close()
# ans_ = []
n = int(input())
if n%2:
print("black")
else:
print("white\n1 2")
# for i in ans_:print(i)
# file = open("output.txt", "w")
# file.write(ans+"\n")
# file.close()
if __name__ == "__main__":
main()
"""
"""
``` | output | 1 | 42,456 | 15 | 84,913 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya decided to learn to play chess. Classic chess doesn't seem interesting to him, so he plays his own sort of chess.
The queen is the piece that captures all squares on its vertical, horizontal and diagonal lines. If the cell is located on the same vertical, horizontal or diagonal line with queen, and the cell contains a piece of the enemy color, the queen is able to move to this square. After that the enemy's piece is removed from the board. The queen cannot move to a cell containing an enemy piece if there is some other piece between it and the queen.
There is an n × n chessboard. We'll denote a cell on the intersection of the r-th row and c-th column as (r, c). The square (1, 1) contains the white queen and the square (1, n) contains the black queen. All other squares contain green pawns that don't belong to anyone.
The players move in turns. The player that moves first plays for the white queen, his opponent plays for the black queen.
On each move the player has to capture some piece with his queen (that is, move to a square that contains either a green pawn or the enemy queen). The player loses if either he cannot capture any piece during his move or the opponent took his queen during the previous move.
Help Vasya determine who wins if both players play with an optimal strategy on the board n × n.
Input
The input contains a single number n (2 ≤ n ≤ 109) — the size of the board.
Output
On the first line print the answer to problem — string "white" or string "black", depending on who wins if the both players play optimally.
If the answer is "white", then you should also print two integers r and c representing the cell (r, c), where the first player should make his first move to win. If there are multiple such cells, print the one with the minimum r. If there are still multiple squares, print the one with the minimum c.
Examples
Input
2
Output
white
1 2
Input
3
Output
black
Note
In the first sample test the white queen can capture the black queen at the first move, so the white player wins.
In the second test from the statement if the white queen captures the green pawn located on the central vertical line, then it will be captured by the black queen during the next move. So the only move for the white player is to capture the green pawn located at (2, 1).
Similarly, the black queen doesn't have any other options but to capture the green pawn located at (2, 3), otherwise if it goes to the middle vertical line, it will be captured by the white queen.
During the next move the same thing happens — neither the white, nor the black queen has other options rather than to capture green pawns situated above them. Thus, the white queen ends up on square (3, 1), and the black queen ends up on square (3, 3).
In this situation the white queen has to capture any of the green pawns located on the middle vertical line, after that it will be captured by the black queen. Thus, the player who plays for the black queen wins. | instruction | 0 | 42,457 | 15 | 84,914 |
Tags: constructive algorithms, games, math
Correct Solution:
```
#!/usr/bin/env python3
# created : 2020. 12. 31. 23:59
import os
from sys import stdin, stdout
def solve(tc):
n = int(stdin.readline().strip())
if n%2:
print("black")
else:
print("white")
print("1 2")
tcs = 1
tc = 1
while tc <= tcs:
solve(tc)
tc += 1
``` | output | 1 | 42,457 | 15 | 84,915 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya decided to learn to play chess. Classic chess doesn't seem interesting to him, so he plays his own sort of chess.
The queen is the piece that captures all squares on its vertical, horizontal and diagonal lines. If the cell is located on the same vertical, horizontal or diagonal line with queen, and the cell contains a piece of the enemy color, the queen is able to move to this square. After that the enemy's piece is removed from the board. The queen cannot move to a cell containing an enemy piece if there is some other piece between it and the queen.
There is an n × n chessboard. We'll denote a cell on the intersection of the r-th row and c-th column as (r, c). The square (1, 1) contains the white queen and the square (1, n) contains the black queen. All other squares contain green pawns that don't belong to anyone.
The players move in turns. The player that moves first plays for the white queen, his opponent plays for the black queen.
On each move the player has to capture some piece with his queen (that is, move to a square that contains either a green pawn or the enemy queen). The player loses if either he cannot capture any piece during his move or the opponent took his queen during the previous move.
Help Vasya determine who wins if both players play with an optimal strategy on the board n × n.
Input
The input contains a single number n (2 ≤ n ≤ 109) — the size of the board.
Output
On the first line print the answer to problem — string "white" or string "black", depending on who wins if the both players play optimally.
If the answer is "white", then you should also print two integers r and c representing the cell (r, c), where the first player should make his first move to win. If there are multiple such cells, print the one with the minimum r. If there are still multiple squares, print the one with the minimum c.
Examples
Input
2
Output
white
1 2
Input
3
Output
black
Note
In the first sample test the white queen can capture the black queen at the first move, so the white player wins.
In the second test from the statement if the white queen captures the green pawn located on the central vertical line, then it will be captured by the black queen during the next move. So the only move for the white player is to capture the green pawn located at (2, 1).
Similarly, the black queen doesn't have any other options but to capture the green pawn located at (2, 3), otherwise if it goes to the middle vertical line, it will be captured by the white queen.
During the next move the same thing happens — neither the white, nor the black queen has other options rather than to capture green pawns situated above them. Thus, the white queen ends up on square (3, 1), and the black queen ends up on square (3, 3).
In this situation the white queen has to capture any of the green pawns located on the middle vertical line, after that it will be captured by the black queen. Thus, the player who plays for the black queen wins. | instruction | 0 | 42,458 | 15 | 84,916 |
Tags: constructive algorithms, games, math
Correct Solution:
```
n=int(input())
if n%2: print('black')
else:
print('white')
print('1 2')
``` | output | 1 | 42,458 | 15 | 84,917 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya decided to learn to play chess. Classic chess doesn't seem interesting to him, so he plays his own sort of chess.
The queen is the piece that captures all squares on its vertical, horizontal and diagonal lines. If the cell is located on the same vertical, horizontal or diagonal line with queen, and the cell contains a piece of the enemy color, the queen is able to move to this square. After that the enemy's piece is removed from the board. The queen cannot move to a cell containing an enemy piece if there is some other piece between it and the queen.
There is an n × n chessboard. We'll denote a cell on the intersection of the r-th row and c-th column as (r, c). The square (1, 1) contains the white queen and the square (1, n) contains the black queen. All other squares contain green pawns that don't belong to anyone.
The players move in turns. The player that moves first plays for the white queen, his opponent plays for the black queen.
On each move the player has to capture some piece with his queen (that is, move to a square that contains either a green pawn or the enemy queen). The player loses if either he cannot capture any piece during his move or the opponent took his queen during the previous move.
Help Vasya determine who wins if both players play with an optimal strategy on the board n × n.
Input
The input contains a single number n (2 ≤ n ≤ 109) — the size of the board.
Output
On the first line print the answer to problem — string "white" or string "black", depending on who wins if the both players play optimally.
If the answer is "white", then you should also print two integers r and c representing the cell (r, c), where the first player should make his first move to win. If there are multiple such cells, print the one with the minimum r. If there are still multiple squares, print the one with the minimum c.
Examples
Input
2
Output
white
1 2
Input
3
Output
black
Note
In the first sample test the white queen can capture the black queen at the first move, so the white player wins.
In the second test from the statement if the white queen captures the green pawn located on the central vertical line, then it will be captured by the black queen during the next move. So the only move for the white player is to capture the green pawn located at (2, 1).
Similarly, the black queen doesn't have any other options but to capture the green pawn located at (2, 3), otherwise if it goes to the middle vertical line, it will be captured by the white queen.
During the next move the same thing happens — neither the white, nor the black queen has other options rather than to capture green pawns situated above them. Thus, the white queen ends up on square (3, 1), and the black queen ends up on square (3, 3).
In this situation the white queen has to capture any of the green pawns located on the middle vertical line, after that it will be captured by the black queen. Thus, the player who plays for the black queen wins. | instruction | 0 | 42,459 | 15 | 84,918 |
Tags: constructive algorithms, games, math
Correct Solution:
```
n = int(input())
if n%2==1:
print("black")
else:
print("white")
print(1,2)
``` | output | 1 | 42,459 | 15 | 84,919 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya decided to learn to play chess. Classic chess doesn't seem interesting to him, so he plays his own sort of chess.
The queen is the piece that captures all squares on its vertical, horizontal and diagonal lines. If the cell is located on the same vertical, horizontal or diagonal line with queen, and the cell contains a piece of the enemy color, the queen is able to move to this square. After that the enemy's piece is removed from the board. The queen cannot move to a cell containing an enemy piece if there is some other piece between it and the queen.
There is an n × n chessboard. We'll denote a cell on the intersection of the r-th row and c-th column as (r, c). The square (1, 1) contains the white queen and the square (1, n) contains the black queen. All other squares contain green pawns that don't belong to anyone.
The players move in turns. The player that moves first plays for the white queen, his opponent plays for the black queen.
On each move the player has to capture some piece with his queen (that is, move to a square that contains either a green pawn or the enemy queen). The player loses if either he cannot capture any piece during his move or the opponent took his queen during the previous move.
Help Vasya determine who wins if both players play with an optimal strategy on the board n × n.
Input
The input contains a single number n (2 ≤ n ≤ 109) — the size of the board.
Output
On the first line print the answer to problem — string "white" or string "black", depending on who wins if the both players play optimally.
If the answer is "white", then you should also print two integers r and c representing the cell (r, c), where the first player should make his first move to win. If there are multiple such cells, print the one with the minimum r. If there are still multiple squares, print the one with the minimum c.
Examples
Input
2
Output
white
1 2
Input
3
Output
black
Note
In the first sample test the white queen can capture the black queen at the first move, so the white player wins.
In the second test from the statement if the white queen captures the green pawn located on the central vertical line, then it will be captured by the black queen during the next move. So the only move for the white player is to capture the green pawn located at (2, 1).
Similarly, the black queen doesn't have any other options but to capture the green pawn located at (2, 3), otherwise if it goes to the middle vertical line, it will be captured by the white queen.
During the next move the same thing happens — neither the white, nor the black queen has other options rather than to capture green pawns situated above them. Thus, the white queen ends up on square (3, 1), and the black queen ends up on square (3, 3).
In this situation the white queen has to capture any of the green pawns located on the middle vertical line, after that it will be captured by the black queen. Thus, the player who plays for the black queen wins. | instruction | 0 | 42,460 | 15 | 84,920 |
Tags: constructive algorithms, games, math
Correct Solution:
```
import sys
input=sys.stdin.buffer.readline
import os
n=int(input())
if n%2==0:
print("white")
print("1 2")
else:
print("black")
``` | output | 1 | 42,460 | 15 | 84,921 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya decided to learn to play chess. Classic chess doesn't seem interesting to him, so he plays his own sort of chess.
The queen is the piece that captures all squares on its vertical, horizontal and diagonal lines. If the cell is located on the same vertical, horizontal or diagonal line with queen, and the cell contains a piece of the enemy color, the queen is able to move to this square. After that the enemy's piece is removed from the board. The queen cannot move to a cell containing an enemy piece if there is some other piece between it and the queen.
There is an n × n chessboard. We'll denote a cell on the intersection of the r-th row and c-th column as (r, c). The square (1, 1) contains the white queen and the square (1, n) contains the black queen. All other squares contain green pawns that don't belong to anyone.
The players move in turns. The player that moves first plays for the white queen, his opponent plays for the black queen.
On each move the player has to capture some piece with his queen (that is, move to a square that contains either a green pawn or the enemy queen). The player loses if either he cannot capture any piece during his move or the opponent took his queen during the previous move.
Help Vasya determine who wins if both players play with an optimal strategy on the board n × n.
Input
The input contains a single number n (2 ≤ n ≤ 109) — the size of the board.
Output
On the first line print the answer to problem — string "white" or string "black", depending on who wins if the both players play optimally.
If the answer is "white", then you should also print two integers r and c representing the cell (r, c), where the first player should make his first move to win. If there are multiple such cells, print the one with the minimum r. If there are still multiple squares, print the one with the minimum c.
Examples
Input
2
Output
white
1 2
Input
3
Output
black
Note
In the first sample test the white queen can capture the black queen at the first move, so the white player wins.
In the second test from the statement if the white queen captures the green pawn located on the central vertical line, then it will be captured by the black queen during the next move. So the only move for the white player is to capture the green pawn located at (2, 1).
Similarly, the black queen doesn't have any other options but to capture the green pawn located at (2, 3), otherwise if it goes to the middle vertical line, it will be captured by the white queen.
During the next move the same thing happens — neither the white, nor the black queen has other options rather than to capture green pawns situated above them. Thus, the white queen ends up on square (3, 1), and the black queen ends up on square (3, 3).
In this situation the white queen has to capture any of the green pawns located on the middle vertical line, after that it will be captured by the black queen. Thus, the player who plays for the black queen wins. | instruction | 0 | 42,461 | 15 | 84,922 |
Tags: constructive algorithms, games, math
Correct Solution:
```
n = int(input())
if n % 2 == 0:
print("white\n1 2")
else:
print("black")
#######
``` | output | 1 | 42,461 | 15 | 84,923 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya decided to learn to play chess. Classic chess doesn't seem interesting to him, so he plays his own sort of chess.
The queen is the piece that captures all squares on its vertical, horizontal and diagonal lines. If the cell is located on the same vertical, horizontal or diagonal line with queen, and the cell contains a piece of the enemy color, the queen is able to move to this square. After that the enemy's piece is removed from the board. The queen cannot move to a cell containing an enemy piece if there is some other piece between it and the queen.
There is an n × n chessboard. We'll denote a cell on the intersection of the r-th row and c-th column as (r, c). The square (1, 1) contains the white queen and the square (1, n) contains the black queen. All other squares contain green pawns that don't belong to anyone.
The players move in turns. The player that moves first plays for the white queen, his opponent plays for the black queen.
On each move the player has to capture some piece with his queen (that is, move to a square that contains either a green pawn or the enemy queen). The player loses if either he cannot capture any piece during his move or the opponent took his queen during the previous move.
Help Vasya determine who wins if both players play with an optimal strategy on the board n × n.
Input
The input contains a single number n (2 ≤ n ≤ 109) — the size of the board.
Output
On the first line print the answer to problem — string "white" or string "black", depending on who wins if the both players play optimally.
If the answer is "white", then you should also print two integers r and c representing the cell (r, c), where the first player should make his first move to win. If there are multiple such cells, print the one with the minimum r. If there are still multiple squares, print the one with the minimum c.
Examples
Input
2
Output
white
1 2
Input
3
Output
black
Note
In the first sample test the white queen can capture the black queen at the first move, so the white player wins.
In the second test from the statement if the white queen captures the green pawn located on the central vertical line, then it will be captured by the black queen during the next move. So the only move for the white player is to capture the green pawn located at (2, 1).
Similarly, the black queen doesn't have any other options but to capture the green pawn located at (2, 3), otherwise if it goes to the middle vertical line, it will be captured by the white queen.
During the next move the same thing happens — neither the white, nor the black queen has other options rather than to capture green pawns situated above them. Thus, the white queen ends up on square (3, 1), and the black queen ends up on square (3, 3).
In this situation the white queen has to capture any of the green pawns located on the middle vertical line, after that it will be captured by the black queen. Thus, the player who plays for the black queen wins.
Submitted Solution:
```
s = int(input())
if s % 2 == 0 :
print('white')
print(*(1,2))
else:
print('black')
``` | instruction | 0 | 42,462 | 15 | 84,924 |
Yes | output | 1 | 42,462 | 15 | 84,925 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya decided to learn to play chess. Classic chess doesn't seem interesting to him, so he plays his own sort of chess.
The queen is the piece that captures all squares on its vertical, horizontal and diagonal lines. If the cell is located on the same vertical, horizontal or diagonal line with queen, and the cell contains a piece of the enemy color, the queen is able to move to this square. After that the enemy's piece is removed from the board. The queen cannot move to a cell containing an enemy piece if there is some other piece between it and the queen.
There is an n × n chessboard. We'll denote a cell on the intersection of the r-th row and c-th column as (r, c). The square (1, 1) contains the white queen and the square (1, n) contains the black queen. All other squares contain green pawns that don't belong to anyone.
The players move in turns. The player that moves first plays for the white queen, his opponent plays for the black queen.
On each move the player has to capture some piece with his queen (that is, move to a square that contains either a green pawn or the enemy queen). The player loses if either he cannot capture any piece during his move or the opponent took his queen during the previous move.
Help Vasya determine who wins if both players play with an optimal strategy on the board n × n.
Input
The input contains a single number n (2 ≤ n ≤ 109) — the size of the board.
Output
On the first line print the answer to problem — string "white" or string "black", depending on who wins if the both players play optimally.
If the answer is "white", then you should also print two integers r and c representing the cell (r, c), where the first player should make his first move to win. If there are multiple such cells, print the one with the minimum r. If there are still multiple squares, print the one with the minimum c.
Examples
Input
2
Output
white
1 2
Input
3
Output
black
Note
In the first sample test the white queen can capture the black queen at the first move, so the white player wins.
In the second test from the statement if the white queen captures the green pawn located on the central vertical line, then it will be captured by the black queen during the next move. So the only move for the white player is to capture the green pawn located at (2, 1).
Similarly, the black queen doesn't have any other options but to capture the green pawn located at (2, 3), otherwise if it goes to the middle vertical line, it will be captured by the white queen.
During the next move the same thing happens — neither the white, nor the black queen has other options rather than to capture green pawns situated above them. Thus, the white queen ends up on square (3, 1), and the black queen ends up on square (3, 3).
In this situation the white queen has to capture any of the green pawns located on the middle vertical line, after that it will be captured by the black queen. Thus, the player who plays for the black queen wins.
Submitted Solution:
```
n = int(input())
if(n%2):
print("black")
else:
print("white")
print("1 2")
``` | instruction | 0 | 42,463 | 15 | 84,926 |
Yes | output | 1 | 42,463 | 15 | 84,927 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.