message
stringlengths
2
19.9k
message_type
stringclasses
2 values
message_id
int64
0
1
conversation_id
int64
322
108k
cluster
float64
15
15
__index_level_0__
int64
644
217k
Provide tags and a correct Python 3 solution for this coding contest problem. Two bears are playing tic-tac-toe via mail. It's boring for them to play usual tic-tac-toe game, so they are a playing modified version of this game. Here are its rules. The game is played on the following field. <image> Players are making moves by turns. At first move a player can put his chip in any cell of any small field. For following moves, there are some restrictions: if during last move the opposite player put his chip to cell with coordinates (xl, yl) in some small field, the next move should be done in one of the cells of the small field with coordinates (xl, yl). For example, if in the first move a player puts his chip to lower left cell of central field, then the second player on his next move should put his chip into some cell of lower left field (pay attention to the first test case). If there are no free cells in the required field, the player can put his chip to any empty cell on any field. You are given current state of the game and coordinates of cell in which the last move was done. You should find all cells in which the current player can put his chip. A hare works as a postman in the forest, he likes to foul bears. Sometimes he changes the game field a bit, so the current state of the game could be unreachable. However, after his changes the cell where the last move was done is not empty. You don't need to find if the state is unreachable or not, just output possible next moves according to the rules. Input First 11 lines contains descriptions of table with 9 rows and 9 columns which are divided into 9 small fields by spaces and empty lines. Each small field is described by 9 characters without spaces and empty lines. character "x" (ASCII-code 120) means that the cell is occupied with chip of the first player, character "o" (ASCII-code 111) denotes a field occupied with chip of the second player, character "." (ASCII-code 46) describes empty cell. The line after the table contains two integers x and y (1 ≤ x, y ≤ 9). They describe coordinates of the cell in table where the last move was done. Rows in the table are numbered from up to down and columns are numbered from left to right. It's guaranteed that cell where the last move was done is filled with "x" or "o". Also, it's guaranteed that there is at least one empty cell. It's not guaranteed that current state of game is reachable. Output Output the field in same format with characters "!" (ASCII-code 33) on positions where the current player can put his chip. All other cells should not be modified. Examples Input ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... x.. ... ... ... ... ... ... ... ... ... ... 6 4 Output ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... x.. ... !!! ... ... !!! ... ... !!! ... ... Input xoo x.. x.. ooo ... ... ooo ... ... x.. x.. x.. ... ... ... ... ... ... x.. x.. x.. ... ... ... ... ... ... 7 4 Output xoo x!! x!! ooo !!! !!! ooo !!! !!! x!! x!! x!! !!! !!! !!! !!! !!! !!! x!! x!! x!! !!! !!! !!! !!! !!! !!! Input o.. ... ... ... ... ... ... ... ... ... xxx ... ... xox ... ... ooo ... ... ... ... ... ... ... ... ... ... 5 5 Output o!! !!! !!! !!! !!! !!! !!! !!! !!! !!! xxx !!! !!! xox !!! !!! ooo !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! Note In the first test case the first player made a move to lower left cell of central field, so the second player can put a chip only to cells of lower left field. In the second test case the last move was done to upper left cell of lower central field, however all cells in upper left field are occupied, so the second player can put his chip to any empty cell. In the third test case the last move was done to central cell of central field, so current player can put his chip to any cell of central field, which is already occupied, so he can move anywhere. Pay attention that this state of the game is unreachable.
instruction
0
37,432
15
74,864
Tags: implementation Correct Solution: ``` R=input g=[list(R()) for _ in range(11)] r,c=map(lambda x:(x-1)%3*4,map(int,R().split())) f,d='.!' for i in range(9): s,e=g[r+i//3],c+i%3 if s[e]<'o': s[e]=f=d for v in g:print(''.join(v).replace(f,d)) ```
output
1
37,432
15
74,865
Provide tags and a correct Python 3 solution for this coding contest problem. Two bears are playing tic-tac-toe via mail. It's boring for them to play usual tic-tac-toe game, so they are a playing modified version of this game. Here are its rules. The game is played on the following field. <image> Players are making moves by turns. At first move a player can put his chip in any cell of any small field. For following moves, there are some restrictions: if during last move the opposite player put his chip to cell with coordinates (xl, yl) in some small field, the next move should be done in one of the cells of the small field with coordinates (xl, yl). For example, if in the first move a player puts his chip to lower left cell of central field, then the second player on his next move should put his chip into some cell of lower left field (pay attention to the first test case). If there are no free cells in the required field, the player can put his chip to any empty cell on any field. You are given current state of the game and coordinates of cell in which the last move was done. You should find all cells in which the current player can put his chip. A hare works as a postman in the forest, he likes to foul bears. Sometimes he changes the game field a bit, so the current state of the game could be unreachable. However, after his changes the cell where the last move was done is not empty. You don't need to find if the state is unreachable or not, just output possible next moves according to the rules. Input First 11 lines contains descriptions of table with 9 rows and 9 columns which are divided into 9 small fields by spaces and empty lines. Each small field is described by 9 characters without spaces and empty lines. character "x" (ASCII-code 120) means that the cell is occupied with chip of the first player, character "o" (ASCII-code 111) denotes a field occupied with chip of the second player, character "." (ASCII-code 46) describes empty cell. The line after the table contains two integers x and y (1 ≤ x, y ≤ 9). They describe coordinates of the cell in table where the last move was done. Rows in the table are numbered from up to down and columns are numbered from left to right. It's guaranteed that cell where the last move was done is filled with "x" or "o". Also, it's guaranteed that there is at least one empty cell. It's not guaranteed that current state of game is reachable. Output Output the field in same format with characters "!" (ASCII-code 33) on positions where the current player can put his chip. All other cells should not be modified. Examples Input ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... x.. ... ... ... ... ... ... ... ... ... ... 6 4 Output ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... x.. ... !!! ... ... !!! ... ... !!! ... ... Input xoo x.. x.. ooo ... ... ooo ... ... x.. x.. x.. ... ... ... ... ... ... x.. x.. x.. ... ... ... ... ... ... 7 4 Output xoo x!! x!! ooo !!! !!! ooo !!! !!! x!! x!! x!! !!! !!! !!! !!! !!! !!! x!! x!! x!! !!! !!! !!! !!! !!! !!! Input o.. ... ... ... ... ... ... ... ... ... xxx ... ... xox ... ... ooo ... ... ... ... ... ... ... ... ... ... 5 5 Output o!! !!! !!! !!! !!! !!! !!! !!! !!! !!! xxx !!! !!! xox !!! !!! ooo !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! Note In the first test case the first player made a move to lower left cell of central field, so the second player can put a chip only to cells of lower left field. In the second test case the last move was done to upper left cell of lower central field, however all cells in upper left field are occupied, so the second player can put his chip to any empty cell. In the third test case the last move was done to central cell of central field, so current player can put his chip to any cell of central field, which is already occupied, so he can move anywhere. Pay attention that this state of the game is unreachable.
instruction
0
37,433
15
74,866
Tags: implementation Correct Solution: ``` dy = 0 dx = 0 ok = 0 v = [] for i in range(11): x = list(''.join(input().split())) if (len(x) > 0): v.append(x) y, x = map(int, input().split()) if (y%3 == 1): dy = 0 elif (y%3 == 2): dy = 3 else: dy = 6 if (x%3 == 1): dx = 0 elif (x%3 == 2): dx = 3 else: dx = 6 for i in range(dy, dy+3): for j in range(dx, dx+3): if (v[i][j] == '.'): ok = 1 if (ok == 0): for i in range(9): if (i > 0 and i%3 == 0): print() for j in range(9): if (j > 0 and j%3 == 0): print(end = ' ') if (v[i][j] == '.'): print('!', end = '') else: print(v[i][j], end = '') print() exit(0) for i in range(dy, dy+3): for j in range(dx, dx+3): if (v[i][j] == '.'): v[i][j] = '!' for i in range(9): if (i > 0 and i%3 == 0): print() for j in range(9): if (j > 0 and j%3 == 0): print(end = ' ') print(v[i][j], end = '') print() exit(0) ```
output
1
37,433
15
74,867
Provide tags and a correct Python 3 solution for this coding contest problem. Two bears are playing tic-tac-toe via mail. It's boring for them to play usual tic-tac-toe game, so they are a playing modified version of this game. Here are its rules. The game is played on the following field. <image> Players are making moves by turns. At first move a player can put his chip in any cell of any small field. For following moves, there are some restrictions: if during last move the opposite player put his chip to cell with coordinates (xl, yl) in some small field, the next move should be done in one of the cells of the small field with coordinates (xl, yl). For example, if in the first move a player puts his chip to lower left cell of central field, then the second player on his next move should put his chip into some cell of lower left field (pay attention to the first test case). If there are no free cells in the required field, the player can put his chip to any empty cell on any field. You are given current state of the game and coordinates of cell in which the last move was done. You should find all cells in which the current player can put his chip. A hare works as a postman in the forest, he likes to foul bears. Sometimes he changes the game field a bit, so the current state of the game could be unreachable. However, after his changes the cell where the last move was done is not empty. You don't need to find if the state is unreachable or not, just output possible next moves according to the rules. Input First 11 lines contains descriptions of table with 9 rows and 9 columns which are divided into 9 small fields by spaces and empty lines. Each small field is described by 9 characters without spaces and empty lines. character "x" (ASCII-code 120) means that the cell is occupied with chip of the first player, character "o" (ASCII-code 111) denotes a field occupied with chip of the second player, character "." (ASCII-code 46) describes empty cell. The line after the table contains two integers x and y (1 ≤ x, y ≤ 9). They describe coordinates of the cell in table where the last move was done. Rows in the table are numbered from up to down and columns are numbered from left to right. It's guaranteed that cell where the last move was done is filled with "x" or "o". Also, it's guaranteed that there is at least one empty cell. It's not guaranteed that current state of game is reachable. Output Output the field in same format with characters "!" (ASCII-code 33) on positions where the current player can put his chip. All other cells should not be modified. Examples Input ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... x.. ... ... ... ... ... ... ... ... ... ... 6 4 Output ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... x.. ... !!! ... ... !!! ... ... !!! ... ... Input xoo x.. x.. ooo ... ... ooo ... ... x.. x.. x.. ... ... ... ... ... ... x.. x.. x.. ... ... ... ... ... ... 7 4 Output xoo x!! x!! ooo !!! !!! ooo !!! !!! x!! x!! x!! !!! !!! !!! !!! !!! !!! x!! x!! x!! !!! !!! !!! !!! !!! !!! Input o.. ... ... ... ... ... ... ... ... ... xxx ... ... xox ... ... ooo ... ... ... ... ... ... ... ... ... ... 5 5 Output o!! !!! !!! !!! !!! !!! !!! !!! !!! !!! xxx !!! !!! xox !!! !!! ooo !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! Note In the first test case the first player made a move to lower left cell of central field, so the second player can put a chip only to cells of lower left field. In the second test case the last move was done to upper left cell of lower central field, however all cells in upper left field are occupied, so the second player can put his chip to any empty cell. In the third test case the last move was done to central cell of central field, so current player can put his chip to any cell of central field, which is already occupied, so he can move anywhere. Pay attention that this state of the game is unreachable.
instruction
0
37,434
15
74,868
Tags: implementation Correct Solution: ``` import math,sys,bisect,heapq from collections import defaultdict,Counter,deque from itertools import groupby,accumulate #sys.setrecursionlimit(200000000) int1 = lambda x: int(x) - 1 input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__ ilele = lambda: map(int,input().split()) alele = lambda: list(map(int, input().split())) ilelec = lambda: map(int1,input().split()) alelec = lambda: list(map(int1, input().split())) def list2d(a, b, c): return [[c] * b for i in range(a)] def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)] #MOD = 1000000000 + 7 def Y(c): print(["NO","YES"][c]) def y(c): print(["no","yes"][c]) def Yy(c): print(["No","Yes"][c]) A = [] for i in range(11): s = input() A.append([*s]) #print(A) x,y = ilele() if x<= 3: i= x-1 elif x <= 6: i = x else: i = x+1 if y<= 3: j= y-1 elif y <= 6: j = y else: j = y+1 #print(i,j) f = 0 if 0 <=i <= 2: a = 0;b = 2 elif 4<= i <= 6: a = 4;b= 6 else: a = 8;b = 10 if 0 <=j <= 2: c = 0;d = 2 elif 4<= j <= 6: c = 4;d= 6 else: c = 8;d = 10 #print(a,c) k1 = i -a k2 = j -c #print(k1,k2) if k1 == 0: a = 0;b = 2 elif k1 == 1: a = 4;b= 6 else: a = 8;b = 10 if k2 == 0: c = 0;d = 2 elif k2 == 1: c = 4;d= 6 else: c = 8;d = 10 for l in range(a,b+1): for m in range(c,d+1): if A[l][m] == '.': f = 1 A[l][m] = '!' if f == 0: for i in range(len(A)): if A[i]: for j in range(len(A[0])): if A[i][j] == '.': A[i][j] = "!" for i in A: if i: print("".join(i)) else: print() ```
output
1
37,434
15
74,869
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Two bears are playing tic-tac-toe via mail. It's boring for them to play usual tic-tac-toe game, so they are a playing modified version of this game. Here are its rules. The game is played on the following field. <image> Players are making moves by turns. At first move a player can put his chip in any cell of any small field. For following moves, there are some restrictions: if during last move the opposite player put his chip to cell with coordinates (xl, yl) in some small field, the next move should be done in one of the cells of the small field with coordinates (xl, yl). For example, if in the first move a player puts his chip to lower left cell of central field, then the second player on his next move should put his chip into some cell of lower left field (pay attention to the first test case). If there are no free cells in the required field, the player can put his chip to any empty cell on any field. You are given current state of the game and coordinates of cell in which the last move was done. You should find all cells in which the current player can put his chip. A hare works as a postman in the forest, he likes to foul bears. Sometimes he changes the game field a bit, so the current state of the game could be unreachable. However, after his changes the cell where the last move was done is not empty. You don't need to find if the state is unreachable or not, just output possible next moves according to the rules. Input First 11 lines contains descriptions of table with 9 rows and 9 columns which are divided into 9 small fields by spaces and empty lines. Each small field is described by 9 characters without spaces and empty lines. character "x" (ASCII-code 120) means that the cell is occupied with chip of the first player, character "o" (ASCII-code 111) denotes a field occupied with chip of the second player, character "." (ASCII-code 46) describes empty cell. The line after the table contains two integers x and y (1 ≤ x, y ≤ 9). They describe coordinates of the cell in table where the last move was done. Rows in the table are numbered from up to down and columns are numbered from left to right. It's guaranteed that cell where the last move was done is filled with "x" or "o". Also, it's guaranteed that there is at least one empty cell. It's not guaranteed that current state of game is reachable. Output Output the field in same format with characters "!" (ASCII-code 33) on positions where the current player can put his chip. All other cells should not be modified. Examples Input ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... x.. ... ... ... ... ... ... ... ... ... ... 6 4 Output ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... x.. ... !!! ... ... !!! ... ... !!! ... ... Input xoo x.. x.. ooo ... ... ooo ... ... x.. x.. x.. ... ... ... ... ... ... x.. x.. x.. ... ... ... ... ... ... 7 4 Output xoo x!! x!! ooo !!! !!! ooo !!! !!! x!! x!! x!! !!! !!! !!! !!! !!! !!! x!! x!! x!! !!! !!! !!! !!! !!! !!! Input o.. ... ... ... ... ... ... ... ... ... xxx ... ... xox ... ... ooo ... ... ... ... ... ... ... ... ... ... 5 5 Output o!! !!! !!! !!! !!! !!! !!! !!! !!! !!! xxx !!! !!! xox !!! !!! ooo !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! Note In the first test case the first player made a move to lower left cell of central field, so the second player can put a chip only to cells of lower left field. In the second test case the last move was done to upper left cell of lower central field, however all cells in upper left field are occupied, so the second player can put his chip to any empty cell. In the third test case the last move was done to central cell of central field, so current player can put his chip to any cell of central field, which is already occupied, so he can move anywhere. Pay attention that this state of the game is unreachable. Submitted Solution: ``` g=[list(input()) for _ in range(11)] r,c=map(lambda x:(int(x)-1)%3*4,input().split()) f,d='.!' for i in range(9): v,e=g[r+i//3],c+i%3 if v[e]<'o':v[e]=f=d for v in g:print(''.join(v).replace(f,d)) ```
instruction
0
37,435
15
74,870
Yes
output
1
37,435
15
74,871
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Two bears are playing tic-tac-toe via mail. It's boring for them to play usual tic-tac-toe game, so they are a playing modified version of this game. Here are its rules. The game is played on the following field. <image> Players are making moves by turns. At first move a player can put his chip in any cell of any small field. For following moves, there are some restrictions: if during last move the opposite player put his chip to cell with coordinates (xl, yl) in some small field, the next move should be done in one of the cells of the small field with coordinates (xl, yl). For example, if in the first move a player puts his chip to lower left cell of central field, then the second player on his next move should put his chip into some cell of lower left field (pay attention to the first test case). If there are no free cells in the required field, the player can put his chip to any empty cell on any field. You are given current state of the game and coordinates of cell in which the last move was done. You should find all cells in which the current player can put his chip. A hare works as a postman in the forest, he likes to foul bears. Sometimes he changes the game field a bit, so the current state of the game could be unreachable. However, after his changes the cell where the last move was done is not empty. You don't need to find if the state is unreachable or not, just output possible next moves according to the rules. Input First 11 lines contains descriptions of table with 9 rows and 9 columns which are divided into 9 small fields by spaces and empty lines. Each small field is described by 9 characters without spaces and empty lines. character "x" (ASCII-code 120) means that the cell is occupied with chip of the first player, character "o" (ASCII-code 111) denotes a field occupied with chip of the second player, character "." (ASCII-code 46) describes empty cell. The line after the table contains two integers x and y (1 ≤ x, y ≤ 9). They describe coordinates of the cell in table where the last move was done. Rows in the table are numbered from up to down and columns are numbered from left to right. It's guaranteed that cell where the last move was done is filled with "x" or "o". Also, it's guaranteed that there is at least one empty cell. It's not guaranteed that current state of game is reachable. Output Output the field in same format with characters "!" (ASCII-code 33) on positions where the current player can put his chip. All other cells should not be modified. Examples Input ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... x.. ... ... ... ... ... ... ... ... ... ... 6 4 Output ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... x.. ... !!! ... ... !!! ... ... !!! ... ... Input xoo x.. x.. ooo ... ... ooo ... ... x.. x.. x.. ... ... ... ... ... ... x.. x.. x.. ... ... ... ... ... ... 7 4 Output xoo x!! x!! ooo !!! !!! ooo !!! !!! x!! x!! x!! !!! !!! !!! !!! !!! !!! x!! x!! x!! !!! !!! !!! !!! !!! !!! Input o.. ... ... ... ... ... ... ... ... ... xxx ... ... xox ... ... ooo ... ... ... ... ... ... ... ... ... ... 5 5 Output o!! !!! !!! !!! !!! !!! !!! !!! !!! !!! xxx !!! !!! xox !!! !!! ooo !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! Note In the first test case the first player made a move to lower left cell of central field, so the second player can put a chip only to cells of lower left field. In the second test case the last move was done to upper left cell of lower central field, however all cells in upper left field are occupied, so the second player can put his chip to any empty cell. In the third test case the last move was done to central cell of central field, so current player can put his chip to any cell of central field, which is already occupied, so he can move anywhere. Pay attention that this state of the game is unreachable. Submitted Solution: ``` l=[list(input()) for _ in range(11)] x,y=map(int, input().split()) x-=1 x+=x//3 y-=1 y+=y//3 a,b=x%4*4,y%4*4 f=1 for i in range(a,a+3): for j in range(b,b+3): if l[i][j]=='.': f=0 l[i][j]='!' if f: for i in range(11): for j in range(len(l[i])): if l[i][j]=='.': l[i][j]='!' for s in l: print(''.join(s)) ```
instruction
0
37,436
15
74,872
Yes
output
1
37,436
15
74,873
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Two bears are playing tic-tac-toe via mail. It's boring for them to play usual tic-tac-toe game, so they are a playing modified version of this game. Here are its rules. The game is played on the following field. <image> Players are making moves by turns. At first move a player can put his chip in any cell of any small field. For following moves, there are some restrictions: if during last move the opposite player put his chip to cell with coordinates (xl, yl) in some small field, the next move should be done in one of the cells of the small field with coordinates (xl, yl). For example, if in the first move a player puts his chip to lower left cell of central field, then the second player on his next move should put his chip into some cell of lower left field (pay attention to the first test case). If there are no free cells in the required field, the player can put his chip to any empty cell on any field. You are given current state of the game and coordinates of cell in which the last move was done. You should find all cells in which the current player can put his chip. A hare works as a postman in the forest, he likes to foul bears. Sometimes he changes the game field a bit, so the current state of the game could be unreachable. However, after his changes the cell where the last move was done is not empty. You don't need to find if the state is unreachable or not, just output possible next moves according to the rules. Input First 11 lines contains descriptions of table with 9 rows and 9 columns which are divided into 9 small fields by spaces and empty lines. Each small field is described by 9 characters without spaces and empty lines. character "x" (ASCII-code 120) means that the cell is occupied with chip of the first player, character "o" (ASCII-code 111) denotes a field occupied with chip of the second player, character "." (ASCII-code 46) describes empty cell. The line after the table contains two integers x and y (1 ≤ x, y ≤ 9). They describe coordinates of the cell in table where the last move was done. Rows in the table are numbered from up to down and columns are numbered from left to right. It's guaranteed that cell where the last move was done is filled with "x" or "o". Also, it's guaranteed that there is at least one empty cell. It's not guaranteed that current state of game is reachable. Output Output the field in same format with characters "!" (ASCII-code 33) on positions where the current player can put his chip. All other cells should not be modified. Examples Input ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... x.. ... ... ... ... ... ... ... ... ... ... 6 4 Output ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... x.. ... !!! ... ... !!! ... ... !!! ... ... Input xoo x.. x.. ooo ... ... ooo ... ... x.. x.. x.. ... ... ... ... ... ... x.. x.. x.. ... ... ... ... ... ... 7 4 Output xoo x!! x!! ooo !!! !!! ooo !!! !!! x!! x!! x!! !!! !!! !!! !!! !!! !!! x!! x!! x!! !!! !!! !!! !!! !!! !!! Input o.. ... ... ... ... ... ... ... ... ... xxx ... ... xox ... ... ooo ... ... ... ... ... ... ... ... ... ... 5 5 Output o!! !!! !!! !!! !!! !!! !!! !!! !!! !!! xxx !!! !!! xox !!! !!! ooo !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! Note In the first test case the first player made a move to lower left cell of central field, so the second player can put a chip only to cells of lower left field. In the second test case the last move was done to upper left cell of lower central field, however all cells in upper left field are occupied, so the second player can put his chip to any empty cell. In the third test case the last move was done to central cell of central field, so current player can put his chip to any cell of central field, which is already occupied, so he can move anywhere. Pay attention that this state of the game is unreachable. Submitted Solution: ``` board = [list(input()) for i in range(11)] (x, y) = map(int, input().split()) x = (x - 1) % 3 y = (y - 1) % 3 can = False for i in range(3): for j in range(3): if board[x*4 + i][y*4 + j] == '.': board[x*4 + i][y*4 + j] = '!' can = True if not can: for i in range(11): if i % 4 != 3: for j in range(11): if board[i][j] == '.': board[i][j] = '!' for i in range(11): print(''.join(board[i])) ```
instruction
0
37,437
15
74,874
Yes
output
1
37,437
15
74,875
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Two bears are playing tic-tac-toe via mail. It's boring for them to play usual tic-tac-toe game, so they are a playing modified version of this game. Here are its rules. The game is played on the following field. <image> Players are making moves by turns. At first move a player can put his chip in any cell of any small field. For following moves, there are some restrictions: if during last move the opposite player put his chip to cell with coordinates (xl, yl) in some small field, the next move should be done in one of the cells of the small field with coordinates (xl, yl). For example, if in the first move a player puts his chip to lower left cell of central field, then the second player on his next move should put his chip into some cell of lower left field (pay attention to the first test case). If there are no free cells in the required field, the player can put his chip to any empty cell on any field. You are given current state of the game and coordinates of cell in which the last move was done. You should find all cells in which the current player can put his chip. A hare works as a postman in the forest, he likes to foul bears. Sometimes he changes the game field a bit, so the current state of the game could be unreachable. However, after his changes the cell where the last move was done is not empty. You don't need to find if the state is unreachable or not, just output possible next moves according to the rules. Input First 11 lines contains descriptions of table with 9 rows and 9 columns which are divided into 9 small fields by spaces and empty lines. Each small field is described by 9 characters without spaces and empty lines. character "x" (ASCII-code 120) means that the cell is occupied with chip of the first player, character "o" (ASCII-code 111) denotes a field occupied with chip of the second player, character "." (ASCII-code 46) describes empty cell. The line after the table contains two integers x and y (1 ≤ x, y ≤ 9). They describe coordinates of the cell in table where the last move was done. Rows in the table are numbered from up to down and columns are numbered from left to right. It's guaranteed that cell where the last move was done is filled with "x" or "o". Also, it's guaranteed that there is at least one empty cell. It's not guaranteed that current state of game is reachable. Output Output the field in same format with characters "!" (ASCII-code 33) on positions where the current player can put his chip. All other cells should not be modified. Examples Input ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... x.. ... ... ... ... ... ... ... ... ... ... 6 4 Output ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... x.. ... !!! ... ... !!! ... ... !!! ... ... Input xoo x.. x.. ooo ... ... ooo ... ... x.. x.. x.. ... ... ... ... ... ... x.. x.. x.. ... ... ... ... ... ... 7 4 Output xoo x!! x!! ooo !!! !!! ooo !!! !!! x!! x!! x!! !!! !!! !!! !!! !!! !!! x!! x!! x!! !!! !!! !!! !!! !!! !!! Input o.. ... ... ... ... ... ... ... ... ... xxx ... ... xox ... ... ooo ... ... ... ... ... ... ... ... ... ... 5 5 Output o!! !!! !!! !!! !!! !!! !!! !!! !!! !!! xxx !!! !!! xox !!! !!! ooo !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! Note In the first test case the first player made a move to lower left cell of central field, so the second player can put a chip only to cells of lower left field. In the second test case the last move was done to upper left cell of lower central field, however all cells in upper left field are occupied, so the second player can put his chip to any empty cell. In the third test case the last move was done to central cell of central field, so current player can put his chip to any cell of central field, which is already occupied, so he can move anywhere. Pay attention that this state of the game is unreachable. Submitted Solution: ``` M = [] M.append(list(input().replace(' ',''))) M.append(list(input().replace(' ',''))) M.append(list(input().replace(' ',''))) input() M.append(list(input().replace(' ',''))) M.append(list(input().replace(' ',''))) M.append(list(input().replace(' ',''))) input() M.append(list(input().replace(' ',''))) M.append(list(input().replace(' ',''))) M.append(list(input().replace(' ',''))) y,x = [int(x)-1 for x in input().split()] lx = 3*(x%3) ly = 3*(y%3) full = True for x in range(3): for y in range(3): if M[ly+x][lx+y] == '.': M[ly+x][lx+y] = '!' full = False # God I hate this output formatting... if full: i = 0 for m in M: s = ''.join(m).replace('.','!') print(s[:3],s[3:6],s[6:]) i += 1 if i == 3 or i == 6: print() else: i = 0 for m in M: s = ''.join(m) print(s[:3],s[3:6],s[6:]) i += 1 if i == 3 or i == 6: print() ```
instruction
0
37,438
15
74,876
Yes
output
1
37,438
15
74,877
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Two bears are playing tic-tac-toe via mail. It's boring for them to play usual tic-tac-toe game, so they are a playing modified version of this game. Here are its rules. The game is played on the following field. <image> Players are making moves by turns. At first move a player can put his chip in any cell of any small field. For following moves, there are some restrictions: if during last move the opposite player put his chip to cell with coordinates (xl, yl) in some small field, the next move should be done in one of the cells of the small field with coordinates (xl, yl). For example, if in the first move a player puts his chip to lower left cell of central field, then the second player on his next move should put his chip into some cell of lower left field (pay attention to the first test case). If there are no free cells in the required field, the player can put his chip to any empty cell on any field. You are given current state of the game and coordinates of cell in which the last move was done. You should find all cells in which the current player can put his chip. A hare works as a postman in the forest, he likes to foul bears. Sometimes he changes the game field a bit, so the current state of the game could be unreachable. However, after his changes the cell where the last move was done is not empty. You don't need to find if the state is unreachable or not, just output possible next moves according to the rules. Input First 11 lines contains descriptions of table with 9 rows and 9 columns which are divided into 9 small fields by spaces and empty lines. Each small field is described by 9 characters without spaces and empty lines. character "x" (ASCII-code 120) means that the cell is occupied with chip of the first player, character "o" (ASCII-code 111) denotes a field occupied with chip of the second player, character "." (ASCII-code 46) describes empty cell. The line after the table contains two integers x and y (1 ≤ x, y ≤ 9). They describe coordinates of the cell in table where the last move was done. Rows in the table are numbered from up to down and columns are numbered from left to right. It's guaranteed that cell where the last move was done is filled with "x" or "o". Also, it's guaranteed that there is at least one empty cell. It's not guaranteed that current state of game is reachable. Output Output the field in same format with characters "!" (ASCII-code 33) on positions where the current player can put his chip. All other cells should not be modified. Examples Input ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... x.. ... ... ... ... ... ... ... ... ... ... 6 4 Output ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... x.. ... !!! ... ... !!! ... ... !!! ... ... Input xoo x.. x.. ooo ... ... ooo ... ... x.. x.. x.. ... ... ... ... ... ... x.. x.. x.. ... ... ... ... ... ... 7 4 Output xoo x!! x!! ooo !!! !!! ooo !!! !!! x!! x!! x!! !!! !!! !!! !!! !!! !!! x!! x!! x!! !!! !!! !!! !!! !!! !!! Input o.. ... ... ... ... ... ... ... ... ... xxx ... ... xox ... ... ooo ... ... ... ... ... ... ... ... ... ... 5 5 Output o!! !!! !!! !!! !!! !!! !!! !!! !!! !!! xxx !!! !!! xox !!! !!! ooo !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! Note In the first test case the first player made a move to lower left cell of central field, so the second player can put a chip only to cells of lower left field. In the second test case the last move was done to upper left cell of lower central field, however all cells in upper left field are occupied, so the second player can put his chip to any empty cell. In the third test case the last move was done to central cell of central field, so current player can put his chip to any cell of central field, which is already occupied, so he can move anywhere. Pay attention that this state of the game is unreachable. Submitted Solution: ``` badook = [] last = [] for i in range(12): k = list(input().strip().split()) if i != 3 and i != 7 and i != 11: for p in range(len(k)): k[p] = list(k[p]) badook.append(k) elif i == 11: last = list(map(int, k)) firstindex = (last[0] - 1) % 3 secondindex = (last[1] - 1) % 3 print(firstindex, secondindex) dp = dict() dp[0] = [0, 1, 2] dp[1] = [3, 4, 5] dp[2] = [6, 7, 8] count = 0 for garo in dp[firstindex]: sero = secondindex for key in range(len(badook[garo][sero])): if badook[garo][sero][key] == '.': count = 1 badook[garo][sero][key] = '!' if count == 0: for i in badook: for j in i: for k in range(len(j)): if j[k] == '.': j[k] = '!' for key in badook: print(key) for i in range(len(badook)): for j in range(len(badook[i])): for k in range(len(badook[i][j])): print(badook[i][j][k], end = "") print(end = " ") print() if i == 2 or i == 5: print() ```
instruction
0
37,439
15
74,878
No
output
1
37,439
15
74,879
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Two bears are playing tic-tac-toe via mail. It's boring for them to play usual tic-tac-toe game, so they are a playing modified version of this game. Here are its rules. The game is played on the following field. <image> Players are making moves by turns. At first move a player can put his chip in any cell of any small field. For following moves, there are some restrictions: if during last move the opposite player put his chip to cell with coordinates (xl, yl) in some small field, the next move should be done in one of the cells of the small field with coordinates (xl, yl). For example, if in the first move a player puts his chip to lower left cell of central field, then the second player on his next move should put his chip into some cell of lower left field (pay attention to the first test case). If there are no free cells in the required field, the player can put his chip to any empty cell on any field. You are given current state of the game and coordinates of cell in which the last move was done. You should find all cells in which the current player can put his chip. A hare works as a postman in the forest, he likes to foul bears. Sometimes he changes the game field a bit, so the current state of the game could be unreachable. However, after his changes the cell where the last move was done is not empty. You don't need to find if the state is unreachable or not, just output possible next moves according to the rules. Input First 11 lines contains descriptions of table with 9 rows and 9 columns which are divided into 9 small fields by spaces and empty lines. Each small field is described by 9 characters without spaces and empty lines. character "x" (ASCII-code 120) means that the cell is occupied with chip of the first player, character "o" (ASCII-code 111) denotes a field occupied with chip of the second player, character "." (ASCII-code 46) describes empty cell. The line after the table contains two integers x and y (1 ≤ x, y ≤ 9). They describe coordinates of the cell in table where the last move was done. Rows in the table are numbered from up to down and columns are numbered from left to right. It's guaranteed that cell where the last move was done is filled with "x" or "o". Also, it's guaranteed that there is at least one empty cell. It's not guaranteed that current state of game is reachable. Output Output the field in same format with characters "!" (ASCII-code 33) on positions where the current player can put his chip. All other cells should not be modified. Examples Input ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... x.. ... ... ... ... ... ... ... ... ... ... 6 4 Output ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... x.. ... !!! ... ... !!! ... ... !!! ... ... Input xoo x.. x.. ooo ... ... ooo ... ... x.. x.. x.. ... ... ... ... ... ... x.. x.. x.. ... ... ... ... ... ... 7 4 Output xoo x!! x!! ooo !!! !!! ooo !!! !!! x!! x!! x!! !!! !!! !!! !!! !!! !!! x!! x!! x!! !!! !!! !!! !!! !!! !!! Input o.. ... ... ... ... ... ... ... ... ... xxx ... ... xox ... ... ooo ... ... ... ... ... ... ... ... ... ... 5 5 Output o!! !!! !!! !!! !!! !!! !!! !!! !!! !!! xxx !!! !!! xox !!! !!! ooo !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! Note In the first test case the first player made a move to lower left cell of central field, so the second player can put a chip only to cells of lower left field. In the second test case the last move was done to upper left cell of lower central field, however all cells in upper left field are occupied, so the second player can put his chip to any empty cell. In the third test case the last move was done to central cell of central field, so current player can put his chip to any cell of central field, which is already occupied, so he can move anywhere. Pay attention that this state of the game is unreachable. Submitted Solution: ``` def main(): arr = [ ] for i in range(11): if i==3 or i==7: str(input()) else: arr.append(list(str(input()).replace(" ",""))) x,y = map(int,input().split()) xreg = (x-1)%3 yreg = (y-1)%3 flag = True for i in range((xreg*3),((xreg+1)*(3))): for j in range( (yreg*3),((yreg+1)*(3)) ): if arr[i][j]!='.': flag = False break if flag: for i in range((xreg*3),((xreg+1)*(3))): for j in range( (yreg*3),((yreg+1)*(3)) ): if arr[i][j]=='.': arr[i][j]='!' else: for i in range(len(arr)): for j in range(len(arr[i])): if arr[i][j]=='.': arr[i][j]='!' for i in range(9): if i==3 or i==6: print() for j in range(3): string = ''.join(arr[i][(j*3):((j+1)*(3))]) print(string ,end=' ') print() main() ```
instruction
0
37,440
15
74,880
No
output
1
37,440
15
74,881
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Two bears are playing tic-tac-toe via mail. It's boring for them to play usual tic-tac-toe game, so they are a playing modified version of this game. Here are its rules. The game is played on the following field. <image> Players are making moves by turns. At first move a player can put his chip in any cell of any small field. For following moves, there are some restrictions: if during last move the opposite player put his chip to cell with coordinates (xl, yl) in some small field, the next move should be done in one of the cells of the small field with coordinates (xl, yl). For example, if in the first move a player puts his chip to lower left cell of central field, then the second player on his next move should put his chip into some cell of lower left field (pay attention to the first test case). If there are no free cells in the required field, the player can put his chip to any empty cell on any field. You are given current state of the game and coordinates of cell in which the last move was done. You should find all cells in which the current player can put his chip. A hare works as a postman in the forest, he likes to foul bears. Sometimes he changes the game field a bit, so the current state of the game could be unreachable. However, after his changes the cell where the last move was done is not empty. You don't need to find if the state is unreachable or not, just output possible next moves according to the rules. Input First 11 lines contains descriptions of table with 9 rows and 9 columns which are divided into 9 small fields by spaces and empty lines. Each small field is described by 9 characters without spaces and empty lines. character "x" (ASCII-code 120) means that the cell is occupied with chip of the first player, character "o" (ASCII-code 111) denotes a field occupied with chip of the second player, character "." (ASCII-code 46) describes empty cell. The line after the table contains two integers x and y (1 ≤ x, y ≤ 9). They describe coordinates of the cell in table where the last move was done. Rows in the table are numbered from up to down and columns are numbered from left to right. It's guaranteed that cell where the last move was done is filled with "x" or "o". Also, it's guaranteed that there is at least one empty cell. It's not guaranteed that current state of game is reachable. Output Output the field in same format with characters "!" (ASCII-code 33) on positions where the current player can put his chip. All other cells should not be modified. Examples Input ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... x.. ... ... ... ... ... ... ... ... ... ... 6 4 Output ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... x.. ... !!! ... ... !!! ... ... !!! ... ... Input xoo x.. x.. ooo ... ... ooo ... ... x.. x.. x.. ... ... ... ... ... ... x.. x.. x.. ... ... ... ... ... ... 7 4 Output xoo x!! x!! ooo !!! !!! ooo !!! !!! x!! x!! x!! !!! !!! !!! !!! !!! !!! x!! x!! x!! !!! !!! !!! !!! !!! !!! Input o.. ... ... ... ... ... ... ... ... ... xxx ... ... xox ... ... ooo ... ... ... ... ... ... ... ... ... ... 5 5 Output o!! !!! !!! !!! !!! !!! !!! !!! !!! !!! xxx !!! !!! xox !!! !!! ooo !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! Note In the first test case the first player made a move to lower left cell of central field, so the second player can put a chip only to cells of lower left field. In the second test case the last move was done to upper left cell of lower central field, however all cells in upper left field are occupied, so the second player can put his chip to any empty cell. In the third test case the last move was done to central cell of central field, so current player can put his chip to any cell of central field, which is already occupied, so he can move anywhere. Pay attention that this state of the game is unreachable. Submitted Solution: ``` a = [] for i in range(11): inp = input() if len(inp) == 0: continue a.append(list(''.join(inp.split()))) x, y = map(int, input().split()) x, y = x % 3 - 1, y % 3 - 1 np = 0 sx, xy = x * 3, y * 3 for i in range(3): for j in range(3): if a[sx + i][xy + j] == '.': a[sx + i][xy + j] = '!' np += 1 if np == 0: sx, xy = 0, 0 for i in range(9): for j in range(9): if a[sx + i][xy + j] == '.': a[sx + i][xy + j] = '!' for i in range(9): print(' '.join([''.join(a[i][:3]), ''.join(a[i][3:6]), ''.join(a[i][6:])])) ```
instruction
0
37,441
15
74,882
No
output
1
37,441
15
74,883
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Two bears are playing tic-tac-toe via mail. It's boring for them to play usual tic-tac-toe game, so they are a playing modified version of this game. Here are its rules. The game is played on the following field. <image> Players are making moves by turns. At first move a player can put his chip in any cell of any small field. For following moves, there are some restrictions: if during last move the opposite player put his chip to cell with coordinates (xl, yl) in some small field, the next move should be done in one of the cells of the small field with coordinates (xl, yl). For example, if in the first move a player puts his chip to lower left cell of central field, then the second player on his next move should put his chip into some cell of lower left field (pay attention to the first test case). If there are no free cells in the required field, the player can put his chip to any empty cell on any field. You are given current state of the game and coordinates of cell in which the last move was done. You should find all cells in which the current player can put his chip. A hare works as a postman in the forest, he likes to foul bears. Sometimes he changes the game field a bit, so the current state of the game could be unreachable. However, after his changes the cell where the last move was done is not empty. You don't need to find if the state is unreachable or not, just output possible next moves according to the rules. Input First 11 lines contains descriptions of table with 9 rows and 9 columns which are divided into 9 small fields by spaces and empty lines. Each small field is described by 9 characters without spaces and empty lines. character "x" (ASCII-code 120) means that the cell is occupied with chip of the first player, character "o" (ASCII-code 111) denotes a field occupied with chip of the second player, character "." (ASCII-code 46) describes empty cell. The line after the table contains two integers x and y (1 ≤ x, y ≤ 9). They describe coordinates of the cell in table where the last move was done. Rows in the table are numbered from up to down and columns are numbered from left to right. It's guaranteed that cell where the last move was done is filled with "x" or "o". Also, it's guaranteed that there is at least one empty cell. It's not guaranteed that current state of game is reachable. Output Output the field in same format with characters "!" (ASCII-code 33) on positions where the current player can put his chip. All other cells should not be modified. Examples Input ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... x.. ... ... ... ... ... ... ... ... ... ... 6 4 Output ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... x.. ... !!! ... ... !!! ... ... !!! ... ... Input xoo x.. x.. ooo ... ... ooo ... ... x.. x.. x.. ... ... ... ... ... ... x.. x.. x.. ... ... ... ... ... ... 7 4 Output xoo x!! x!! ooo !!! !!! ooo !!! !!! x!! x!! x!! !!! !!! !!! !!! !!! !!! x!! x!! x!! !!! !!! !!! !!! !!! !!! Input o.. ... ... ... ... ... ... ... ... ... xxx ... ... xox ... ... ooo ... ... ... ... ... ... ... ... ... ... 5 5 Output o!! !!! !!! !!! !!! !!! !!! !!! !!! !!! xxx !!! !!! xox !!! !!! ooo !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! Note In the first test case the first player made a move to lower left cell of central field, so the second player can put a chip only to cells of lower left field. In the second test case the last move was done to upper left cell of lower central field, however all cells in upper left field are occupied, so the second player can put his chip to any empty cell. In the third test case the last move was done to central cell of central field, so current player can put his chip to any cell of central field, which is already occupied, so he can move anywhere. Pay attention that this state of the game is unreachable. Submitted Solution: ``` def main(): s = "" for i in range(11): tmp = input().split() for el in tmp: s += el last = [int(x) for x in input().split()] last[0] = last[0] % 3 last[1] = last[1] % 3 if (last[0] == 0): last[0] += 3 if (last[1] == 0): last[1] += 3 mtrx = [[] for i in range(9)] k = 0 for i in range(9): for j in range(9): if (s[k] == 'x'): mtrx[i].append(1) elif(s[k] == 'o'): mtrx[i].append(2) else: mtrx[i].append(0) k += 1 flag = True for i in range((last[0]-1)*3, (last[0]*3)): for j in range((last[1]-1)*3, last[1]*3): if (mtrx[i][j] == 0): flag = False mtrx[i][j] = 3 if (flag): for i in range(9): for j in range(9): if(mtrx[i][j] == 0): mtrx[i][j] = 3 res = "" for i in range(9): for j in range(3): for v in range(3): if(mtrx[i][j*3+v] == 0): res += '.' elif(mtrx[i][j*3+v] == 1): res += 'x' elif(mtrx[i][j*3+v] == 2): res += 'o' else: res += '!' res += ' ' res += '\n' print(res) main() ```
instruction
0
37,442
15
74,884
No
output
1
37,442
15
74,885
Provide a correct Python 3 solution for this coding contest problem. Given is a string S consisting of `L` and `R`. Let N be the length of S. There are N squares arranged from left to right, and the i-th character of S from the left is written on the i-th square from the left. The character written on the leftmost square is always `R`, and the character written on the rightmost square is always `L`. Initially, one child is standing on each square. Each child will perform the move below 10^{100} times: * Move one square in the direction specified by the character written in the square on which the child is standing. `L` denotes left, and `R` denotes right. Find the number of children standing on each square after the children performed the moves. Constraints * S is a string of length between 2 and 10^5 (inclusive). * Each character of S is `L` or `R`. * The first and last characters of S are `R` and `L`, respectively. Input Input is given from Standard Input in the following format: S Output Print the number of children standing on each square after the children performed the moves, in order from left to right. Examples Input RRLRL Output 0 1 2 1 1 Input RRLLLLRLRRLL Output 0 3 3 0 0 0 1 1 0 2 2 0 Input RRRLLRLLRRRLLLLL Output 0 0 3 2 0 2 1 0 0 0 4 4 0 0 0 0
instruction
0
37,539
15
75,078
"Correct Solution: ``` s = input() ans = [0] * len(s) i = 0 while i < len(s): si = i while s[i] == 'R': i += 1 ti = i while i < len(s) and s[i] == 'L': i += 1 ri = i l = ti - si ans[ti - 1] += (l + 1) // 2 ans[ti] += l // 2 r = ri - ti ans[ti - 1] += r // 2 ans[ti] += (r + 1) // 2 print(*ans) ```
output
1
37,539
15
75,079
Provide a correct Python 3 solution for this coding contest problem. Given is a string S consisting of `L` and `R`. Let N be the length of S. There are N squares arranged from left to right, and the i-th character of S from the left is written on the i-th square from the left. The character written on the leftmost square is always `R`, and the character written on the rightmost square is always `L`. Initially, one child is standing on each square. Each child will perform the move below 10^{100} times: * Move one square in the direction specified by the character written in the square on which the child is standing. `L` denotes left, and `R` denotes right. Find the number of children standing on each square after the children performed the moves. Constraints * S is a string of length between 2 and 10^5 (inclusive). * Each character of S is `L` or `R`. * The first and last characters of S are `R` and `L`, respectively. Input Input is given from Standard Input in the following format: S Output Print the number of children standing on each square after the children performed the moves, in order from left to right. Examples Input RRLRL Output 0 1 2 1 1 Input RRLLLLRLRRLL Output 0 3 3 0 0 0 1 1 0 2 2 0 Input RRRLLRLLRRRLLLLL Output 0 0 3 2 0 2 1 0 0 0 4 4 0 0 0 0
instruction
0
37,540
15
75,080
"Correct Solution: ``` S = input() ans = [0] * len(S) cnt = 0 for _ in range(2): for i in range(len(S)): if S[i] == "R": cnt += 1 else: ans[i] += cnt // 2 ans[i-1] += -(-cnt // 2) cnt = 0 ans = ans[::-1] S = list(S[::-1]) for i in range(len(S)): if S[i] == "R": S[i] = "L" else: S[i] = "R" print(*ans) ```
output
1
37,540
15
75,081
Provide a correct Python 3 solution for this coding contest problem. Given is a string S consisting of `L` and `R`. Let N be the length of S. There are N squares arranged from left to right, and the i-th character of S from the left is written on the i-th square from the left. The character written on the leftmost square is always `R`, and the character written on the rightmost square is always `L`. Initially, one child is standing on each square. Each child will perform the move below 10^{100} times: * Move one square in the direction specified by the character written in the square on which the child is standing. `L` denotes left, and `R` denotes right. Find the number of children standing on each square after the children performed the moves. Constraints * S is a string of length between 2 and 10^5 (inclusive). * Each character of S is `L` or `R`. * The first and last characters of S are `R` and `L`, respectively. Input Input is given from Standard Input in the following format: S Output Print the number of children standing on each square after the children performed the moves, in order from left to right. Examples Input RRLRL Output 0 1 2 1 1 Input RRLLLLRLRRLL Output 0 3 3 0 0 0 1 1 0 2 2 0 Input RRRLLRLLRRRLLLLL Output 0 0 3 2 0 2 1 0 0 0 4 4 0 0 0 0
instruction
0
37,541
15
75,082
"Correct Solution: ``` s = input()+'R' ans = [0]*(len(s)-1) a = 0 b = 0 cnt = 0 for i in s: if i=='L' and b==0: b = cnt if b!=0 and i=='R': ans[b-1] = 1+(b-1-a)//2+(cnt-b)//2 ans[b] = 1+(b-a)//2+(cnt-1-b)//2 a = cnt b = 0 cnt+=1 print(' '.join(map(str,ans))) ```
output
1
37,541
15
75,083
Provide a correct Python 3 solution for this coding contest problem. Given is a string S consisting of `L` and `R`. Let N be the length of S. There are N squares arranged from left to right, and the i-th character of S from the left is written on the i-th square from the left. The character written on the leftmost square is always `R`, and the character written on the rightmost square is always `L`. Initially, one child is standing on each square. Each child will perform the move below 10^{100} times: * Move one square in the direction specified by the character written in the square on which the child is standing. `L` denotes left, and `R` denotes right. Find the number of children standing on each square after the children performed the moves. Constraints * S is a string of length between 2 and 10^5 (inclusive). * Each character of S is `L` or `R`. * The first and last characters of S are `R` and `L`, respectively. Input Input is given from Standard Input in the following format: S Output Print the number of children standing on each square after the children performed the moves, in order from left to right. Examples Input RRLRL Output 0 1 2 1 1 Input RRLLLLRLRRLL Output 0 3 3 0 0 0 1 1 0 2 2 0 Input RRRLLRLLRRRLLLLL Output 0 0 3 2 0 2 1 0 0 0 4 4 0 0 0 0
instruction
0
37,542
15
75,084
"Correct Solution: ``` s = input().replace("RL","R,L").replace("LR","L,R").split(",") s = s[::-1] h = list() while s: a = len(s.pop()) b = len(s.pop()) h.append((a,b)) t = [] for x,y in h: t += [0]*(x-1) + [(x+1)//2+y//2,x//2+(y+1)//2] + [0]*(y-1) print(" ".join(map(str,t))) ```
output
1
37,542
15
75,085
Provide a correct Python 3 solution for this coding contest problem. Given is a string S consisting of `L` and `R`. Let N be the length of S. There are N squares arranged from left to right, and the i-th character of S from the left is written on the i-th square from the left. The character written on the leftmost square is always `R`, and the character written on the rightmost square is always `L`. Initially, one child is standing on each square. Each child will perform the move below 10^{100} times: * Move one square in the direction specified by the character written in the square on which the child is standing. `L` denotes left, and `R` denotes right. Find the number of children standing on each square after the children performed the moves. Constraints * S is a string of length between 2 and 10^5 (inclusive). * Each character of S is `L` or `R`. * The first and last characters of S are `R` and `L`, respectively. Input Input is given from Standard Input in the following format: S Output Print the number of children standing on each square after the children performed the moves, in order from left to right. Examples Input RRLRL Output 0 1 2 1 1 Input RRLLLLRLRRLL Output 0 3 3 0 0 0 1 1 0 2 2 0 Input RRRLLRLLRRRLLLLL Output 0 0 3 2 0 2 1 0 0 0 4 4 0 0 0 0
instruction
0
37,543
15
75,086
"Correct Solution: ``` s=input() ans=[] while len(s)>0: index=s.find("LR")+1 if index>0:sub,s=s[:index],s[index:] else:sub,s=s,[] length=len(sub) nums=[0]*length stop=sub.find("RL") odd,even=(length+1)//2,length//2 if stop%2==1:odd,even=even,odd nums[stop],nums[stop+1]=odd,even ans+=nums print(*ans) ```
output
1
37,543
15
75,087
Provide a correct Python 3 solution for this coding contest problem. Given is a string S consisting of `L` and `R`. Let N be the length of S. There are N squares arranged from left to right, and the i-th character of S from the left is written on the i-th square from the left. The character written on the leftmost square is always `R`, and the character written on the rightmost square is always `L`. Initially, one child is standing on each square. Each child will perform the move below 10^{100} times: * Move one square in the direction specified by the character written in the square on which the child is standing. `L` denotes left, and `R` denotes right. Find the number of children standing on each square after the children performed the moves. Constraints * S is a string of length between 2 and 10^5 (inclusive). * Each character of S is `L` or `R`. * The first and last characters of S are `R` and `L`, respectively. Input Input is given from Standard Input in the following format: S Output Print the number of children standing on each square after the children performed the moves, in order from left to right. Examples Input RRLRL Output 0 1 2 1 1 Input RRLLLLRLRRLL Output 0 3 3 0 0 0 1 1 0 2 2 0 Input RRRLLRLLRRRLLLLL Output 0 0 3 2 0 2 1 0 0 0 4 4 0 0 0 0
instruction
0
37,544
15
75,088
"Correct Solution: ``` w=input()+"X" n=len(w) ans=[] i=j=0 while True: while w[i]=="R": i+=1 ans+=[0]*(i-j-1) r=(i-j+1)//2 l=(i-j)//2 j=i while w[j]=="L": j+=1 r+=(j-i)//2 l+=(j-i+1)//2 ans.append(r) ans.append(l) ans+=[0]*(j-i-1) if j==n-1: break i=j for a in ans: print(a,end=" ") ```
output
1
37,544
15
75,089
Provide a correct Python 3 solution for this coding contest problem. Given is a string S consisting of `L` and `R`. Let N be the length of S. There are N squares arranged from left to right, and the i-th character of S from the left is written on the i-th square from the left. The character written on the leftmost square is always `R`, and the character written on the rightmost square is always `L`. Initially, one child is standing on each square. Each child will perform the move below 10^{100} times: * Move one square in the direction specified by the character written in the square on which the child is standing. `L` denotes left, and `R` denotes right. Find the number of children standing on each square after the children performed the moves. Constraints * S is a string of length between 2 and 10^5 (inclusive). * Each character of S is `L` or `R`. * The first and last characters of S are `R` and `L`, respectively. Input Input is given from Standard Input in the following format: S Output Print the number of children standing on each square after the children performed the moves, in order from left to right. Examples Input RRLRL Output 0 1 2 1 1 Input RRLLLLRLRRLL Output 0 3 3 0 0 0 1 1 0 2 2 0 Input RRRLLRLLRRRLLLLL Output 0 0 3 2 0 2 1 0 0 0 4 4 0 0 0 0
instruction
0
37,545
15
75,090
"Correct Solution: ``` S = input() N = len(S) L = [1]*N for i,s in enumerate(S): if s == "R": s2 = S[i+1] if s2 == "R": L[i+2] += L[i] L[i] = 0 for i in range(N-1,-1,-1): s = S[i] if s == "L": s2 = S[i-1] if s2 == "L": L[i-2] += L[i] L[i] = 0 print(*L) ```
output
1
37,545
15
75,091
Provide a correct Python 3 solution for this coding contest problem. Given is a string S consisting of `L` and `R`. Let N be the length of S. There are N squares arranged from left to right, and the i-th character of S from the left is written on the i-th square from the left. The character written on the leftmost square is always `R`, and the character written on the rightmost square is always `L`. Initially, one child is standing on each square. Each child will perform the move below 10^{100} times: * Move one square in the direction specified by the character written in the square on which the child is standing. `L` denotes left, and `R` denotes right. Find the number of children standing on each square after the children performed the moves. Constraints * S is a string of length between 2 and 10^5 (inclusive). * Each character of S is `L` or `R`. * The first and last characters of S are `R` and `L`, respectively. Input Input is given from Standard Input in the following format: S Output Print the number of children standing on each square after the children performed the moves, in order from left to right. Examples Input RRLRL Output 0 1 2 1 1 Input RRLLLLRLRRLL Output 0 3 3 0 0 0 1 1 0 2 2 0 Input RRRLLRLLRRRLLLLL Output 0 0 3 2 0 2 1 0 0 0 4 4 0 0 0 0
instruction
0
37,546
15
75,092
"Correct Solution: ``` s=input() n=len(s) A=[] b=0 a=1 for i in range(n-1): if s[i+1]==s[i]: a=a+1 else: A.append(a) a=1 A.append(n-sum(A)) B=[0]*n c=0 for i in range(len(A)): c+=A[i] if i%2==0: B[c-1]+=(A[i]+1)//2 B[c]+=A[i]//2 else: c-=A[i] B[c-1]+=A[i]//2 B[c]+=(A[i]+1)//2 c+=A[i] for i in range(n): print(B[i],end=" ") ```
output
1
37,546
15
75,093
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Given is a string S consisting of `L` and `R`. Let N be the length of S. There are N squares arranged from left to right, and the i-th character of S from the left is written on the i-th square from the left. The character written on the leftmost square is always `R`, and the character written on the rightmost square is always `L`. Initially, one child is standing on each square. Each child will perform the move below 10^{100} times: * Move one square in the direction specified by the character written in the square on which the child is standing. `L` denotes left, and `R` denotes right. Find the number of children standing on each square after the children performed the moves. Constraints * S is a string of length between 2 and 10^5 (inclusive). * Each character of S is `L` or `R`. * The first and last characters of S are `R` and `L`, respectively. Input Input is given from Standard Input in the following format: S Output Print the number of children standing on each square after the children performed the moves, in order from left to right. Examples Input RRLRL Output 0 1 2 1 1 Input RRLLLLRLRRLL Output 0 3 3 0 0 0 1 1 0 2 2 0 Input RRRLLRLLRRRLLLLL Output 0 0 3 2 0 2 1 0 0 0 4 4 0 0 0 0 Submitted Solution: ``` S = input() N = len(S) C = [0] * N c = 0 for i in range(N): if S[i] == 'R': c = i else: C[c + (i - c) % 2] += 1 for i in range(N - 1, -1, -1): if S[i] == 'L': c = i else: C[c - (c - i) % 2] += 1 print(' '.join([str(c) for c in C])) ```
instruction
0
37,547
15
75,094
Yes
output
1
37,547
15
75,095
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Given is a string S consisting of `L` and `R`. Let N be the length of S. There are N squares arranged from left to right, and the i-th character of S from the left is written on the i-th square from the left. The character written on the leftmost square is always `R`, and the character written on the rightmost square is always `L`. Initially, one child is standing on each square. Each child will perform the move below 10^{100} times: * Move one square in the direction specified by the character written in the square on which the child is standing. `L` denotes left, and `R` denotes right. Find the number of children standing on each square after the children performed the moves. Constraints * S is a string of length between 2 and 10^5 (inclusive). * Each character of S is `L` or `R`. * The first and last characters of S are `R` and `L`, respectively. Input Input is given from Standard Input in the following format: S Output Print the number of children standing on each square after the children performed the moves, in order from left to right. Examples Input RRLRL Output 0 1 2 1 1 Input RRLLLLRLRRLL Output 0 3 3 0 0 0 1 1 0 2 2 0 Input RRRLLRLLRRRLLLLL Output 0 0 3 2 0 2 1 0 0 0 4 4 0 0 0 0 Submitted Solution: ``` def main(): s = input() ans = [1] * len(s) for i in range(len(s)-2): if s[i]=='R' and s[i+1]=='R': ans[i+2] += ans[i] ans[i] = 0 for i in range(len(s)-1, 1, -1): if s[i]=='L' and s[i-1]=='L': ans[i-2] += ans[i] ans[i] = 0 print(" ".join(map(str, ans))) if __name__ == '__main__': main() ```
instruction
0
37,548
15
75,096
Yes
output
1
37,548
15
75,097
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Given is a string S consisting of `L` and `R`. Let N be the length of S. There are N squares arranged from left to right, and the i-th character of S from the left is written on the i-th square from the left. The character written on the leftmost square is always `R`, and the character written on the rightmost square is always `L`. Initially, one child is standing on each square. Each child will perform the move below 10^{100} times: * Move one square in the direction specified by the character written in the square on which the child is standing. `L` denotes left, and `R` denotes right. Find the number of children standing on each square after the children performed the moves. Constraints * S is a string of length between 2 and 10^5 (inclusive). * Each character of S is `L` or `R`. * The first and last characters of S are `R` and `L`, respectively. Input Input is given from Standard Input in the following format: S Output Print the number of children standing on each square after the children performed the moves, in order from left to right. Examples Input RRLRL Output 0 1 2 1 1 Input RRLLLLRLRRLL Output 0 3 3 0 0 0 1 1 0 2 2 0 Input RRRLLRLLRRRLLLLL Output 0 0 3 2 0 2 1 0 0 0 4 4 0 0 0 0 Submitted Solution: ``` from collections import Counter S=input() n=len(S) dp=[[0]*n for _ in range(20)] for i,s in enumerate(S): dp[0][i]=i-1 if s =='L' else i+1 for k in range(19): for i in range(n): dp[k+1][i]=dp[k][dp[k][i]] C=Counter(dp[-1]) print(*[C[i] for i in range(n)]) ```
instruction
0
37,549
15
75,098
Yes
output
1
37,549
15
75,099
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Given is a string S consisting of `L` and `R`. Let N be the length of S. There are N squares arranged from left to right, and the i-th character of S from the left is written on the i-th square from the left. The character written on the leftmost square is always `R`, and the character written on the rightmost square is always `L`. Initially, one child is standing on each square. Each child will perform the move below 10^{100} times: * Move one square in the direction specified by the character written in the square on which the child is standing. `L` denotes left, and `R` denotes right. Find the number of children standing on each square after the children performed the moves. Constraints * S is a string of length between 2 and 10^5 (inclusive). * Each character of S is `L` or `R`. * The first and last characters of S are `R` and `L`, respectively. Input Input is given from Standard Input in the following format: S Output Print the number of children standing on each square after the children performed the moves, in order from left to right. Examples Input RRLRL Output 0 1 2 1 1 Input RRLLLLRLRRLL Output 0 3 3 0 0 0 1 1 0 2 2 0 Input RRRLLRLLRRRLLLLL Output 0 0 3 2 0 2 1 0 0 0 4 4 0 0 0 0 Submitted Solution: ``` s=input() ls=len(s) a=[0]*ls nr=j=0 for i in range(ls-1): if s[i:i+2]=='RL':j=i if s[i:i+2]=='LR' or i==ls-2: t='' if s[i:i+2]=='LR':t=s[nr:i+1] elif i==ls-2:t=s[nr:] r=t.count('R') l=len(t)-r a[j+1]+=r//2-(-l//2) a[j]+=l//2-(-r//2) nr=i+1 print(*a) ```
instruction
0
37,550
15
75,100
Yes
output
1
37,550
15
75,101
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Given is a string S consisting of `L` and `R`. Let N be the length of S. There are N squares arranged from left to right, and the i-th character of S from the left is written on the i-th square from the left. The character written on the leftmost square is always `R`, and the character written on the rightmost square is always `L`. Initially, one child is standing on each square. Each child will perform the move below 10^{100} times: * Move one square in the direction specified by the character written in the square on which the child is standing. `L` denotes left, and `R` denotes right. Find the number of children standing on each square after the children performed the moves. Constraints * S is a string of length between 2 and 10^5 (inclusive). * Each character of S is `L` or `R`. * The first and last characters of S are `R` and `L`, respectively. Input Input is given from Standard Input in the following format: S Output Print the number of children standing on each square after the children performed the moves, in order from left to right. Examples Input RRLRL Output 0 1 2 1 1 Input RRLLLLRLRRLL Output 0 3 3 0 0 0 1 1 0 2 2 0 Input RRRLLRLLRRRLLLLL Output 0 0 3 2 0 2 1 0 0 0 4 4 0 0 0 0 Submitted Solution: ``` S = list(input()) N = len(S) C = [1] * N C_prev1 = C.copy() C = [0] * N times = 1 #1回目 for i,v in enumerate(S): if v == "R": C[i+1] += C_prev1[i] else: C[i-1] += C_prev1[i] C_prev2 = C_prev1.copy() C_prev1 = C.copy() C = [0] * N times += 1 #2回目 for i,v in enumerate(S): if v == "R": C[i+1] += C_prev1[i] else: C[i-1] += C_prev1[i] if C_prev2 != C: while True: times += 1 C_prev2 = C_prev1.copy() C_prev1 = C.copy() C = [0] * N for i,v in enumerate(S): if v == "R": C[i+1] += C_prev1[i] else: C[i-1] += C_prev1[i] if C_prev2 == C: break if times % 2 == 1: print(' '.join(map(str, C_prev1))) else: print(' '.join(map(str, C))) ```
instruction
0
37,551
15
75,102
No
output
1
37,551
15
75,103
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Given is a string S consisting of `L` and `R`. Let N be the length of S. There are N squares arranged from left to right, and the i-th character of S from the left is written on the i-th square from the left. The character written on the leftmost square is always `R`, and the character written on the rightmost square is always `L`. Initially, one child is standing on each square. Each child will perform the move below 10^{100} times: * Move one square in the direction specified by the character written in the square on which the child is standing. `L` denotes left, and `R` denotes right. Find the number of children standing on each square after the children performed the moves. Constraints * S is a string of length between 2 and 10^5 (inclusive). * Each character of S is `L` or `R`. * The first and last characters of S are `R` and `L`, respectively. Input Input is given from Standard Input in the following format: S Output Print the number of children standing on each square after the children performed the moves, in order from left to right. Examples Input RRLRL Output 0 1 2 1 1 Input RRLLLLRLRRLL Output 0 3 3 0 0 0 1 1 0 2 2 0 Input RRRLLRLLRRRLLLLL Output 0 0 3 2 0 2 1 0 0 0 4 4 0 0 0 0 Submitted Solution: ``` S = str(input()) M_r = [0]*len(S) M_l = [0]*len(S) for i in range(len(S)): if S[i] == 'R': M_r[i] = 1 M_l[i] = 0 else: M_r[i] = 0 M_l[i] = 1 C = [1]*len(S) C_r = [0]*len(S) C_l = [0]*len(S) for i in range(100): C_r[1:] = [x * y for (x, y) in zip(C[:-1] , M_r[:-1])] C_l[:-1] = [x * y for (x, y) in zip(C[1:] , M_l[1:])] C = [x + y for (x, y) in zip(C_r , C_l)] print(C) ```
instruction
0
37,552
15
75,104
No
output
1
37,552
15
75,105
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Given is a string S consisting of `L` and `R`. Let N be the length of S. There are N squares arranged from left to right, and the i-th character of S from the left is written on the i-th square from the left. The character written on the leftmost square is always `R`, and the character written on the rightmost square is always `L`. Initially, one child is standing on each square. Each child will perform the move below 10^{100} times: * Move one square in the direction specified by the character written in the square on which the child is standing. `L` denotes left, and `R` denotes right. Find the number of children standing on each square after the children performed the moves. Constraints * S is a string of length between 2 and 10^5 (inclusive). * Each character of S is `L` or `R`. * The first and last characters of S are `R` and `L`, respectively. Input Input is given from Standard Input in the following format: S Output Print the number of children standing on each square after the children performed the moves, in order from left to right. Examples Input RRLRL Output 0 1 2 1 1 Input RRLLLLRLRRLL Output 0 3 3 0 0 0 1 1 0 2 2 0 Input RRRLLRLLRRRLLLLL Output 0 0 3 2 0 2 1 0 0 0 4 4 0 0 0 0 Submitted Solution: ``` S=list(input()) N=len(S) #print(S,N) T=[0 for _ in range(N)] for i in range(N): if S[i]=='R': j=i while S[j]=='R': j+=1 if (j-i)%2==0: T[j]+=1 elif (j-i)%==1: T[j-1]+=1 else: j=i while S[j]=='L': j-=1 if (i-j)%2==0: T[j]+=1 elif (j-i)%2==1: T[j+1]+=1 print(T) ```
instruction
0
37,553
15
75,106
No
output
1
37,553
15
75,107
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Given is a string S consisting of `L` and `R`. Let N be the length of S. There are N squares arranged from left to right, and the i-th character of S from the left is written on the i-th square from the left. The character written on the leftmost square is always `R`, and the character written on the rightmost square is always `L`. Initially, one child is standing on each square. Each child will perform the move below 10^{100} times: * Move one square in the direction specified by the character written in the square on which the child is standing. `L` denotes left, and `R` denotes right. Find the number of children standing on each square after the children performed the moves. Constraints * S is a string of length between 2 and 10^5 (inclusive). * Each character of S is `L` or `R`. * The first and last characters of S are `R` and `L`, respectively. Input Input is given from Standard Input in the following format: S Output Print the number of children standing on each square after the children performed the moves, in order from left to right. Examples Input RRLRL Output 0 1 2 1 1 Input RRLLLLRLRRLL Output 0 3 3 0 0 0 1 1 0 2 2 0 Input RRRLLRLLRRRLLLLL Output 0 0 3 2 0 2 1 0 0 0 4 4 0 0 0 0 Submitted Solution: ``` # -*- coding: utf-8 -*- """ AtCoder A """ import sys, math, random import numpy as np # N = int(input()) # A = list(map(int,input().split())) # N row 1 column # A = [int(input()) for _ in range(N)] # 1 row N column # S = str(input()) # str(input()) == input() -> 'abc' # S = list(input()) # abc -> ['a','b','c'] # S.replace('ABC','X') # "testABCABC" -> "testXX" # S=numpp.assaray(S)=="#" inf = 10**20 eps = 1.0 / 10**10 mod = 10**9+7 dd = [(-1,0),(0,1),(1,0),(0,-1)] ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)] def LI(): return list(map(int, sys.stdin.readline().split())) def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()] def LLS(): return [list(sys.stdin.readline().rstrip()) for _ in sys.stdin.readlines()] 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 main(): T = S() out= [0] * len(T) # idx= [0] * len(T) prev=None for i in range(len(T)): N=10**100 now=i tag=True if prev: if T[i-1]==T[i]: if T[prev]=="R": out[prev+1]+=1 # idx[i]=prev+1 prev=prev+1 else: out[prev-1]+=1 # idx[i]=prev-1 prev=prev-1 tag=False while tag: if T[now]=="R": if T[now+1]=="L": if N%2==1: out[now+1]+=1 # idx[i]=now+1 prev=now+1 else: out[now]+=1 # idx[i]=now prev=now tag=False else: now+=1 N-=1 else: if T[now-1]=="R": if N%2==1: out[now-1]+=1 # idx[i]=now-1 prev=now-1 else: out[now]+=1 # idx[i]=now prev=now tag=False else: now-=1 N-=1 print(*out) # for i in range(len(T)): # N=10**100 # now=i # tag=True # while tag: # if T[now]=="R": # if T[now+1]=="L": # if N%2==1: # out[now+1]+=1 # else: # out[now]+=1 # tag=False # else: # now+=1 # N-=1 # else: # if T[now-1]=="R": # if N%2==1: # out[now-1]+=1 # else: # out[now]+=1 # tag=False # else: # now-=1 # N-=1 # print(*out) if __name__ == "__main__": main() ```
instruction
0
37,554
15
75,108
No
output
1
37,554
15
75,109
Provide tags and a correct Python 3 solution for this coding contest problem. The only king stands on the standard chess board. You are given his position in format "cd", where c is the column from 'a' to 'h' and d is the row from '1' to '8'. Find the number of moves permitted for the king. Check the king's moves here https://en.wikipedia.org/wiki/King_(chess). <image> King moves from the position e4 Input The only line contains the king's position in the format "cd", where 'c' is the column from 'a' to 'h' and 'd' is the row from '1' to '8'. Output Print the only integer x — the number of moves permitted for the king. Example Input e4 Output 8
instruction
0
38,159
15
76,318
Tags: implementation Correct Solution: ``` a = input() if (a=="b8" or a=="c8" or a=="d8" or a=="e8" or a=="f8" or a=="g8" or a=="b1" or a=="c1" or a=="d1" or a=="e1" or a=="f1" or a=="g1" or a=="a2" or a=="a3" or a=="a4" or a=="a5" or a=="a6" or a=="a7" or a=="h2" or a=="h3" or a=="h4" or a=="h5" or a=="h6" or a=="h7"): print("5") else: if (a=="a1" or a=="a8" or a=="h8" or a=="h1"): print("3") else: print("8") ```
output
1
38,159
15
76,319
Provide tags and a correct Python 3 solution for this coding contest problem. The only king stands on the standard chess board. You are given his position in format "cd", where c is the column from 'a' to 'h' and d is the row from '1' to '8'. Find the number of moves permitted for the king. Check the king's moves here https://en.wikipedia.org/wiki/King_(chess). <image> King moves from the position e4 Input The only line contains the king's position in the format "cd", where 'c' is the column from 'a' to 'h' and 'd' is the row from '1' to '8'. Output Print the only integer x — the number of moves permitted for the king. Example Input e4 Output 8
instruction
0
38,160
15
76,320
Tags: implementation Correct Solution: ``` x=input() if (x[0] in ['a','h']) and (x[1]=='1' or x[1]=='8'): print(3) elif (x[0] in ['a','h']) and (x[1] not in ['1','8']): print(5) elif (x[0] in ['b','c','d','e','f','g','h']) and (x[1]=='1' or x[1]=='8'): print(5) else: print(8) ```
output
1
38,160
15
76,321
Provide tags and a correct Python 3 solution for this coding contest problem. The only king stands on the standard chess board. You are given his position in format "cd", where c is the column from 'a' to 'h' and d is the row from '1' to '8'. Find the number of moves permitted for the king. Check the king's moves here https://en.wikipedia.org/wiki/King_(chess). <image> King moves from the position e4 Input The only line contains the king's position in the format "cd", where 'c' is the column from 'a' to 'h' and 'd' is the row from '1' to '8'. Output Print the only integer x — the number of moves permitted for the king. Example Input e4 Output 8
instruction
0
38,161
15
76,322
Tags: implementation Correct Solution: ``` # King Moves def king(s): c = s[0] d = s[1] if c in ['a', 'h'] and d in ['1', '8']: return 3 if c in ['a', 'h'] or d in ['1', '8']: return 5 return 8 s = input() print(king(s)) ```
output
1
38,161
15
76,323
Provide tags and a correct Python 3 solution for this coding contest problem. The only king stands on the standard chess board. You are given his position in format "cd", where c is the column from 'a' to 'h' and d is the row from '1' to '8'. Find the number of moves permitted for the king. Check the king's moves here https://en.wikipedia.org/wiki/King_(chess). <image> King moves from the position e4 Input The only line contains the king's position in the format "cd", where 'c' is the column from 'a' to 'h' and 'd' is the row from '1' to '8'. Output Print the only integer x — the number of moves permitted for the king. Example Input e4 Output 8
instruction
0
38,162
15
76,324
Tags: implementation Correct Solution: ``` inp = input() if inp[0] == 'a': if 2 <= int(inp[1]) < 8: print(5) exit() if int(inp[1]) == 8: if 'a' < inp[0] < 'h': print(5) exit() if int(inp[1]) == 1: if 'a' < inp[0] < 'h': print(5) exit() if inp[0] == 'h': if 2 <= int(inp[1]) < 8: print(5) exit() if 2 <= int(inp[1]) <= 7 and 'a' < inp[0] < 'h': print(8) exit() print(3) ```
output
1
38,162
15
76,325
Provide tags and a correct Python 3 solution for this coding contest problem. The only king stands on the standard chess board. You are given his position in format "cd", where c is the column from 'a' to 'h' and d is the row from '1' to '8'. Find the number of moves permitted for the king. Check the king's moves here https://en.wikipedia.org/wiki/King_(chess). <image> King moves from the position e4 Input The only line contains the king's position in the format "cd", where 'c' is the column from 'a' to 'h' and 'd' is the row from '1' to '8'. Output Print the only integer x — the number of moves permitted for the king. Example Input e4 Output 8
instruction
0
38,163
15
76,326
Tags: implementation Correct Solution: ``` n=input() if(n=="a8" or n=="a1" or n=="h8" or n=="h1"): print(3) elif((n[0]=='a' and n[1]!=1 and n[1]!=8) or (n[0]=='h' and n[1]!=1 and n[1]!=8) or (n[1]=='1' and n[0]!='a' and n[0]!='h') or (n[1]=='8' and n[0]!='a' and n[0]!='h')): print(5) else: print(8) ```
output
1
38,163
15
76,327
Provide tags and a correct Python 3 solution for this coding contest problem. The only king stands on the standard chess board. You are given his position in format "cd", where c is the column from 'a' to 'h' and d is the row from '1' to '8'. Find the number of moves permitted for the king. Check the king's moves here https://en.wikipedia.org/wiki/King_(chess). <image> King moves from the position e4 Input The only line contains the king's position in the format "cd", where 'c' is the column from 'a' to 'h' and 'd' is the row from '1' to '8'. Output Print the only integer x — the number of moves permitted for the king. Example Input e4 Output 8
instruction
0
38,164
15
76,328
Tags: implementation Correct Solution: ``` a = input() x = a[0] y = a[1] if a == 'a1' or a=='a8' or a=='h1' or a=='h8': print(3) elif x =='a' or x == 'h' or y == '1' or y=='8': print(5) else: print(8) ```
output
1
38,164
15
76,329
Provide tags and a correct Python 3 solution for this coding contest problem. The only king stands on the standard chess board. You are given his position in format "cd", where c is the column from 'a' to 'h' and d is the row from '1' to '8'. Find the number of moves permitted for the king. Check the king's moves here https://en.wikipedia.org/wiki/King_(chess). <image> King moves from the position e4 Input The only line contains the king's position in the format "cd", where 'c' is the column from 'a' to 'h' and 'd' is the row from '1' to '8'. Output Print the only integer x — the number of moves permitted for the king. Example Input e4 Output 8
instruction
0
38,165
15
76,330
Tags: implementation Correct Solution: ``` s =input() c, r = s[0], s[1] if (c == "a" or c == "h") and (r == "1" or r == "8"): print(3) elif (c == "a" or c == "h") and (r != "1" or r != "8"): print(5) elif (c != "a" or c != "h") and (r == "1" or r == "8"): print(5) else: print(8) ```
output
1
38,165
15
76,331
Provide tags and a correct Python 3 solution for this coding contest problem. The only king stands on the standard chess board. You are given his position in format "cd", where c is the column from 'a' to 'h' and d is the row from '1' to '8'. Find the number of moves permitted for the king. Check the king's moves here https://en.wikipedia.org/wiki/King_(chess). <image> King moves from the position e4 Input The only line contains the king's position in the format "cd", where 'c' is the column from 'a' to 'h' and 'd' is the row from '1' to '8'. Output Print the only integer x — the number of moves permitted for the king. Example Input e4 Output 8
instruction
0
38,166
15
76,332
Tags: implementation Correct Solution: ``` s = str(input()) a = s[0] b = s[1] if a in ['a', 'h'] and b in ['1', '8']: print(3) elif a in ['a', 'h'] or b in ['1', '8']: print(5) else: print(8) ```
output
1
38,166
15
76,333
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The only king stands on the standard chess board. You are given his position in format "cd", where c is the column from 'a' to 'h' and d is the row from '1' to '8'. Find the number of moves permitted for the king. Check the king's moves here https://en.wikipedia.org/wiki/King_(chess). <image> King moves from the position e4 Input The only line contains the king's position in the format "cd", where 'c' is the column from 'a' to 'h' and 'd' is the row from '1' to '8'. Output Print the only integer x — the number of moves permitted for the king. Example Input e4 Output 8 Submitted Solution: ``` a=input() if a[0]=='a' or a[0]== 'h' or a[1]=='1' or a[1]=='8': if a[0]== 'a' and a[1]=='8': print("3") exit() elif a[0]== 'a' and a[1]=='1': print("3") exit() elif a[0]=='h'and a[1]=='8': print("3") exit() elif a[0]=='h' and a[1]=='1': print("3") exit() print("5") else: print("8") ```
instruction
0
38,167
15
76,334
Yes
output
1
38,167
15
76,335
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The only king stands on the standard chess board. You are given his position in format "cd", where c is the column from 'a' to 'h' and d is the row from '1' to '8'. Find the number of moves permitted for the king. Check the king's moves here https://en.wikipedia.org/wiki/King_(chess). <image> King moves from the position e4 Input The only line contains the king's position in the format "cd", where 'c' is the column from 'a' to 'h' and 'd' is the row from '1' to '8'. Output Print the only integer x — the number of moves permitted for the king. Example Input e4 Output 8 Submitted Solution: ``` x=list(input()) if (x[0]=='a' and x[1]=='1') or (x[0]=='a' and x[1]=='8') or (x[0]=='h' and x[1]=='1') or (x[0]=='h' and x[1]=='8'): print(3) elif (x[0]=='a' and x[1]!='1') or (x[0]!='a' and x[1]=='1') or (x[0]=='h' and x[1]!='1') or (x[0]!='h' and x[1]=='8'): print(5) else: print(8) ```
instruction
0
38,168
15
76,336
Yes
output
1
38,168
15
76,337
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The only king stands on the standard chess board. You are given his position in format "cd", where c is the column from 'a' to 'h' and d is the row from '1' to '8'. Find the number of moves permitted for the king. Check the king's moves here https://en.wikipedia.org/wiki/King_(chess). <image> King moves from the position e4 Input The only line contains the king's position in the format "cd", where 'c' is the column from 'a' to 'h' and 'd' is the row from '1' to '8'. Output Print the only integer x — the number of moves permitted for the king. Example Input e4 Output 8 Submitted Solution: ``` k = input() if k[0] in ['a', 'h'] and k[1] in ['1', '8']: print("3") elif k[0] in ['a', 'h'] or k[1] in ['1', '8']: print("5") else: print("8") ```
instruction
0
38,169
15
76,338
Yes
output
1
38,169
15
76,339
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The only king stands on the standard chess board. You are given his position in format "cd", where c is the column from 'a' to 'h' and d is the row from '1' to '8'. Find the number of moves permitted for the king. Check the king's moves here https://en.wikipedia.org/wiki/King_(chess). <image> King moves from the position e4 Input The only line contains the king's position in the format "cd", where 'c' is the column from 'a' to 'h' and 'd' is the row from '1' to '8'. Output Print the only integer x — the number of moves permitted for the king. Example Input e4 Output 8 Submitted Solution: ``` t=input("") if t[0]=="a" or t[0]=="h" or t[1]=="1" or t[1]=="8": c=0 if t[0]=="a" and t[1]=="1": c=1 print("3") if t[0]=="a" and t[1]=="8": c=1 print("3") if t[0]=="h" and t[1]=="1": c=1 print("3") if t[0]=="h" and t[1]=="8": c=1 print("3") if c==0: print("5") else: print("8") ```
instruction
0
38,170
15
76,340
Yes
output
1
38,170
15
76,341
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The only king stands on the standard chess board. You are given his position in format "cd", where c is the column from 'a' to 'h' and d is the row from '1' to '8'. Find the number of moves permitted for the king. Check the king's moves here https://en.wikipedia.org/wiki/King_(chess). <image> King moves from the position e4 Input The only line contains the king's position in the format "cd", where 'c' is the column from 'a' to 'h' and 'd' is the row from '1' to '8'. Output Print the only integer x — the number of moves permitted for the king. Example Input e4 Output 8 Submitted Solution: ``` n=input() if((n[0]=='a' and n[1]!=1 and n[1]!=8) or (n[0]=='h' and n[1]!=1 and n[1]!=8) or (n[1]=='1' and n[0]!='a' and n[0]!='h') or (n[1]=='8' and n[0]!='a' and n[0]!='h')): print(5) else: print(8) ```
instruction
0
38,171
15
76,342
No
output
1
38,171
15
76,343
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The only king stands on the standard chess board. You are given his position in format "cd", where c is the column from 'a' to 'h' and d is the row from '1' to '8'. Find the number of moves permitted for the king. Check the king's moves here https://en.wikipedia.org/wiki/King_(chess). <image> King moves from the position e4 Input The only line contains the king's position in the format "cd", where 'c' is the column from 'a' to 'h' and 'd' is the row from '1' to '8'. Output Print the only integer x — the number of moves permitted for the king. Example Input e4 Output 8 Submitted Solution: ``` n=input() if n[0]=='h' or n[0]=='a': if n[1]=='0' or n[1]=='8': print(3) else: print(5) elif n[1]=='0' or n[1]=='8': if n[0]=='a' or n[0]=='h': print(3) else: print(5) else: print(8) ```
instruction
0
38,172
15
76,344
No
output
1
38,172
15
76,345
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The only king stands on the standard chess board. You are given his position in format "cd", where c is the column from 'a' to 'h' and d is the row from '1' to '8'. Find the number of moves permitted for the king. Check the king's moves here https://en.wikipedia.org/wiki/King_(chess). <image> King moves from the position e4 Input The only line contains the king's position in the format "cd", where 'c' is the column from 'a' to 'h' and 'd' is the row from '1' to '8'. Output Print the only integer x — the number of moves permitted for the king. Example Input e4 Output 8 Submitted Solution: ``` a = input() if a[0] == 'a' or a[0] == 'h': if a[1] == 1 or a[1] == 8: print(3) exit() else: print(5) exit() else: if a[1] == '1' or a[1] == '8': print(5) exit() else: print(8) ```
instruction
0
38,173
15
76,346
No
output
1
38,173
15
76,347
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The only king stands on the standard chess board. You are given his position in format "cd", where c is the column from 'a' to 'h' and d is the row from '1' to '8'. Find the number of moves permitted for the king. Check the king's moves here https://en.wikipedia.org/wiki/King_(chess). <image> King moves from the position e4 Input The only line contains the king's position in the format "cd", where 'c' is the column from 'a' to 'h' and 'd' is the row from '1' to '8'. Output Print the only integer x — the number of moves permitted for the king. Example Input e4 Output 8 Submitted Solution: ``` a=input() if (a[0]=="a" or a[0]=="h") and (a[1]=="1" or a[1]=="8"): print(3) elif (a[0]=="a" or a[0]=="h") and (a[1]!="1" and a[1]!="8"): print(5) elif (a[0]!="a" and a[0]!="h") and (a[1]=="1" and a[1]=="8"): print(5) else: print(8) ```
instruction
0
38,174
15
76,348
No
output
1
38,174
15
76,349
Provide tags and a correct Python 3 solution for this coding contest problem. On the way to school, Karen became fixated on the puzzle game on her phone! <image> The game is played as follows. In each level, you have a grid with n rows and m columns. Each cell originally contains the number 0. One move consists of choosing one row or column, and adding 1 to all of the cells in that row or column. To win the level, after all the moves, the number in the cell at the i-th row and j-th column should be equal to gi, j. Karen is stuck on one level, and wants to know a way to beat this level using the minimum number of moves. Please, help her with this task! Input The first line of input contains two integers, n and m (1 ≤ n, m ≤ 100), the number of rows and the number of columns in the grid, respectively. The next n lines each contain m integers. In particular, the j-th integer in the i-th of these rows contains gi, j (0 ≤ gi, j ≤ 500). Output If there is an error and it is actually not possible to beat the level, output a single integer -1. Otherwise, on the first line, output a single integer k, the minimum number of moves necessary to beat the level. The next k lines should each contain one of the following, describing the moves in the order they must be done: * row x, (1 ≤ x ≤ n) describing a move of the form "choose the x-th row". * col x, (1 ≤ x ≤ m) describing a move of the form "choose the x-th column". If there are multiple optimal solutions, output any one of them. Examples Input 3 5 2 2 2 3 2 0 0 0 1 0 1 1 1 2 1 Output 4 row 1 row 1 col 4 row 3 Input 3 3 0 0 0 0 1 0 0 0 0 Output -1 Input 3 3 1 1 1 1 1 1 1 1 1 Output 3 row 1 row 2 row 3 Note In the first test case, Karen has a grid with 3 rows and 5 columns. She can perform the following 4 moves to beat the level: <image> In the second test case, Karen has a grid with 3 rows and 3 columns. It is clear that it is impossible to beat the level; performing any move will create three 1s on the grid, but it is required to only have one 1 in the center. In the third test case, Karen has a grid with 3 rows and 3 columns. She can perform the following 3 moves to beat the level: <image> Note that this is not the only solution; another solution, among others, is col 1, col 2, col 3.
instruction
0
39,243
15
78,486
Tags: brute force, greedy, implementation Correct Solution: ``` #------------------------template--------------------------# import os import sys from math import * from collections import * # from fractions import * from heapq import* from bisect import * from io import BytesIO, IOBase def vsInput(): sys.stdin = open('input.txt', 'r') sys.stdout = open('output.txt', 'w') BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = 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(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") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") ALPHA='abcdefghijklmnopqrstuvwxyz/' M=1000000007 EPS=1e-6 def Ceil(a,b): return a//b+int(a%b>0) def value():return tuple(map(int,input().split())) def array():return [int(i) for i in input().split()] def Int():return int(input()) def Str():return input() def arrayS():return [i for i in input().split()] #-------------------------code---------------------------# # vsInput() r,c=value() a=[] for i in range(r): a.append(array()) row=[0]*r col=[0]*c steps=inf final_row=[] final_col=[] for r1 in range(501): row[0]=r1 ok=True for i in range(c): col[i]=a[0][i]-row[0] if(col[i]<0): ok=False for i in range(1,r): row[i]=inf for j in range(c): here=a[i][j]-col[j] if(row[i]==inf): row[i]=here elif(row[i]!=here): ok=False if(row[i]<0): ok=False if(ok): ans=sum(row) ans+=sum(col) if(ans<steps): steps=ans final_row=row[::] final_col=col[::] if(steps==inf): print(-1) else: print(steps) for i in range(r): for j in range(final_row[i]): print('row',i+1) for i in range(c): for j in range(final_col[i]): print('col',i+1) ```
output
1
39,243
15
78,487
Provide tags and a correct Python 3 solution for this coding contest problem. On the way to school, Karen became fixated on the puzzle game on her phone! <image> The game is played as follows. In each level, you have a grid with n rows and m columns. Each cell originally contains the number 0. One move consists of choosing one row or column, and adding 1 to all of the cells in that row or column. To win the level, after all the moves, the number in the cell at the i-th row and j-th column should be equal to gi, j. Karen is stuck on one level, and wants to know a way to beat this level using the minimum number of moves. Please, help her with this task! Input The first line of input contains two integers, n and m (1 ≤ n, m ≤ 100), the number of rows and the number of columns in the grid, respectively. The next n lines each contain m integers. In particular, the j-th integer in the i-th of these rows contains gi, j (0 ≤ gi, j ≤ 500). Output If there is an error and it is actually not possible to beat the level, output a single integer -1. Otherwise, on the first line, output a single integer k, the minimum number of moves necessary to beat the level. The next k lines should each contain one of the following, describing the moves in the order they must be done: * row x, (1 ≤ x ≤ n) describing a move of the form "choose the x-th row". * col x, (1 ≤ x ≤ m) describing a move of the form "choose the x-th column". If there are multiple optimal solutions, output any one of them. Examples Input 3 5 2 2 2 3 2 0 0 0 1 0 1 1 1 2 1 Output 4 row 1 row 1 col 4 row 3 Input 3 3 0 0 0 0 1 0 0 0 0 Output -1 Input 3 3 1 1 1 1 1 1 1 1 1 Output 3 row 1 row 2 row 3 Note In the first test case, Karen has a grid with 3 rows and 5 columns. She can perform the following 4 moves to beat the level: <image> In the second test case, Karen has a grid with 3 rows and 3 columns. It is clear that it is impossible to beat the level; performing any move will create three 1s on the grid, but it is required to only have one 1 in the center. In the third test case, Karen has a grid with 3 rows and 3 columns. She can perform the following 3 moves to beat the level: <image> Note that this is not the only solution; another solution, among others, is col 1, col 2, col 3.
instruction
0
39,244
15
78,488
Tags: brute force, greedy, implementation Correct Solution: ``` import sys def min_i_v(row): min_v = None min_i = None for i, v in enumerate(row): if min_v is None or v < min_v: min_v = v min_i = i return min_i, min_v def dec_row(matrix, row_i, val): for i in range(len(matrix[row_i])): matrix[row_i][i] -= val def dec_col(matrix, col_i, val): for i in range(len(matrix)): matrix[i][col_i] -= val amount_of_rows, amount_of_cols = [int(a) for a in sys.stdin.readline().split()] matrix = [] for i in range(amount_of_rows): matrix.append([int(a) for a in sys.stdin.readline().split()]) log = [] interrupted = False if amount_of_cols >= amount_of_rows: for row_i, row in enumerate(matrix): min_i, min_v = min_i_v(row) dec_row(matrix, row_i, min_v) for i in range(min_v): log.append('row ' + str(row_i + 1) + '\n') col = [0] * amount_of_rows for c_i in range(amount_of_cols): for r_i in range(amount_of_rows): col[r_i] = matrix[r_i][c_i] min_i, min_v = min_i_v(col) if min_v < col[row_i]: interrupted = True break else: min_v = col[row_i] dec_col(matrix, c_i, min_v) for i in range(min_v): log.append('col ' + str(c_i + 1) + '\n') if interrupted: break else: col = [0] * amount_of_rows for col_i in range(amount_of_cols): for r_i in range(amount_of_rows): col[r_i] = matrix[r_i][col_i] min_i, min_v = min_i_v(col) dec_col(matrix, col_i, min_v) for i in range(min_v): log.append('col ' + str(col_i + 1) + '\n') for r_i, row in enumerate(matrix): min_i, min_v = min_i_v(row) if min_v < row[col_i]: interrupted = True break else: min_v = row[col_i] dec_row(matrix, r_i, min_v) for i in range(min_v): log.append('row ' + str(r_i + 1) + '\n') if interrupted: break if interrupted: sys.stdout.write('-1\n') else: sys.stdout.write(str(len(log))+'\n') for i in log: sys.stdout.write(i) ```
output
1
39,244
15
78,489
Provide tags and a correct Python 3 solution for this coding contest problem. On the way to school, Karen became fixated on the puzzle game on her phone! <image> The game is played as follows. In each level, you have a grid with n rows and m columns. Each cell originally contains the number 0. One move consists of choosing one row or column, and adding 1 to all of the cells in that row or column. To win the level, after all the moves, the number in the cell at the i-th row and j-th column should be equal to gi, j. Karen is stuck on one level, and wants to know a way to beat this level using the minimum number of moves. Please, help her with this task! Input The first line of input contains two integers, n and m (1 ≤ n, m ≤ 100), the number of rows and the number of columns in the grid, respectively. The next n lines each contain m integers. In particular, the j-th integer in the i-th of these rows contains gi, j (0 ≤ gi, j ≤ 500). Output If there is an error and it is actually not possible to beat the level, output a single integer -1. Otherwise, on the first line, output a single integer k, the minimum number of moves necessary to beat the level. The next k lines should each contain one of the following, describing the moves in the order they must be done: * row x, (1 ≤ x ≤ n) describing a move of the form "choose the x-th row". * col x, (1 ≤ x ≤ m) describing a move of the form "choose the x-th column". If there are multiple optimal solutions, output any one of them. Examples Input 3 5 2 2 2 3 2 0 0 0 1 0 1 1 1 2 1 Output 4 row 1 row 1 col 4 row 3 Input 3 3 0 0 0 0 1 0 0 0 0 Output -1 Input 3 3 1 1 1 1 1 1 1 1 1 Output 3 row 1 row 2 row 3 Note In the first test case, Karen has a grid with 3 rows and 5 columns. She can perform the following 4 moves to beat the level: <image> In the second test case, Karen has a grid with 3 rows and 3 columns. It is clear that it is impossible to beat the level; performing any move will create three 1s on the grid, but it is required to only have one 1 in the center. In the third test case, Karen has a grid with 3 rows and 3 columns. She can perform the following 3 moves to beat the level: <image> Note that this is not the only solution; another solution, among others, is col 1, col 2, col 3.
instruction
0
39,245
15
78,490
Tags: brute force, greedy, implementation Correct Solution: ``` n, m = map(int, input().split()) table = [list(map(int, input().split())) for i in range(n)] table2 = [list(l) for l in table] anslst = [] for i in range(n): minv = min(table[i]) for v in range(minv): anslst.append("row {}".format(i + 1)) for j in range(m): table[i][j] -= minv for j in range(m): minv = 1e9 for i in range(n): minv = min(minv, table[i][j]) for v in range(minv): anslst.append("col {}".format(j + 1)) for i in range(n): table[i][j] -= minv flg = True for i in range(n): for j in range(m): if table[i][j] != 0: flg = False if not flg: print(-1) exit() anslst2 = [] for j in range(m): minv = 1e9 for i in range(n): minv = min(minv, table2[i][j]) for v in range(minv): anslst2.append("col {}".format(j + 1)) for i in range(n): table2[i][j] -= minv for i in range(n): minv = min(table2[i]) for v in range(minv): anslst2.append("row {}".format(i + 1)) for j in range(m): table2[i][j] -= minv if len(anslst) < len(anslst2): print(len(anslst)) for a in anslst: print(a) else: print(len(anslst2)) for a in anslst2: print(a) ```
output
1
39,245
15
78,491
Provide tags and a correct Python 3 solution for this coding contest problem. On the way to school, Karen became fixated on the puzzle game on her phone! <image> The game is played as follows. In each level, you have a grid with n rows and m columns. Each cell originally contains the number 0. One move consists of choosing one row or column, and adding 1 to all of the cells in that row or column. To win the level, after all the moves, the number in the cell at the i-th row and j-th column should be equal to gi, j. Karen is stuck on one level, and wants to know a way to beat this level using the minimum number of moves. Please, help her with this task! Input The first line of input contains two integers, n and m (1 ≤ n, m ≤ 100), the number of rows and the number of columns in the grid, respectively. The next n lines each contain m integers. In particular, the j-th integer in the i-th of these rows contains gi, j (0 ≤ gi, j ≤ 500). Output If there is an error and it is actually not possible to beat the level, output a single integer -1. Otherwise, on the first line, output a single integer k, the minimum number of moves necessary to beat the level. The next k lines should each contain one of the following, describing the moves in the order they must be done: * row x, (1 ≤ x ≤ n) describing a move of the form "choose the x-th row". * col x, (1 ≤ x ≤ m) describing a move of the form "choose the x-th column". If there are multiple optimal solutions, output any one of them. Examples Input 3 5 2 2 2 3 2 0 0 0 1 0 1 1 1 2 1 Output 4 row 1 row 1 col 4 row 3 Input 3 3 0 0 0 0 1 0 0 0 0 Output -1 Input 3 3 1 1 1 1 1 1 1 1 1 Output 3 row 1 row 2 row 3 Note In the first test case, Karen has a grid with 3 rows and 5 columns. She can perform the following 4 moves to beat the level: <image> In the second test case, Karen has a grid with 3 rows and 3 columns. It is clear that it is impossible to beat the level; performing any move will create three 1s on the grid, but it is required to only have one 1 in the center. In the third test case, Karen has a grid with 3 rows and 3 columns. She can perform the following 3 moves to beat the level: <image> Note that this is not the only solution; another solution, among others, is col 1, col 2, col 3.
instruction
0
39,246
15
78,492
Tags: brute force, greedy, implementation Correct Solution: ``` x,y=map(int,input().split()) grid=[] for i in range(x): grid.append(list(map(int,input().split()))) mi=grid[0][0] prints=[] for i in range(x): mi=min(mi,min(grid[i])) if x > y: for k in range(mi): for i in range(1,y+1): prints.append('col '+str(i)) else: for k in range(mi): for i in range(1,x+1): prints.append('row '+str(i)) for i in range(x): for j in range(y): grid[i][j]-=mi for i in range(x): while min(grid[i])>0: prints.append('row '+str(i+1)) for j in range(y): grid[i][j]-=1 for i in range(y): indy=[] for ranind in range(x): indy.append(grid[ranind][i]) mindy=min(indy) for ran2 in range(mindy): prints.append('col '+str(i+1)) for j in range(x): grid[j][i]-=1 ma=grid[0][0] for i in range(x): ma=max(ma,max(grid[i])) if ma!=0: print('-1') quit() print(len(prints)) print('\n'.join(prints)) ```
output
1
39,246
15
78,493
Provide tags and a correct Python 3 solution for this coding contest problem. On the way to school, Karen became fixated on the puzzle game on her phone! <image> The game is played as follows. In each level, you have a grid with n rows and m columns. Each cell originally contains the number 0. One move consists of choosing one row or column, and adding 1 to all of the cells in that row or column. To win the level, after all the moves, the number in the cell at the i-th row and j-th column should be equal to gi, j. Karen is stuck on one level, and wants to know a way to beat this level using the minimum number of moves. Please, help her with this task! Input The first line of input contains two integers, n and m (1 ≤ n, m ≤ 100), the number of rows and the number of columns in the grid, respectively. The next n lines each contain m integers. In particular, the j-th integer in the i-th of these rows contains gi, j (0 ≤ gi, j ≤ 500). Output If there is an error and it is actually not possible to beat the level, output a single integer -1. Otherwise, on the first line, output a single integer k, the minimum number of moves necessary to beat the level. The next k lines should each contain one of the following, describing the moves in the order they must be done: * row x, (1 ≤ x ≤ n) describing a move of the form "choose the x-th row". * col x, (1 ≤ x ≤ m) describing a move of the form "choose the x-th column". If there are multiple optimal solutions, output any one of them. Examples Input 3 5 2 2 2 3 2 0 0 0 1 0 1 1 1 2 1 Output 4 row 1 row 1 col 4 row 3 Input 3 3 0 0 0 0 1 0 0 0 0 Output -1 Input 3 3 1 1 1 1 1 1 1 1 1 Output 3 row 1 row 2 row 3 Note In the first test case, Karen has a grid with 3 rows and 5 columns. She can perform the following 4 moves to beat the level: <image> In the second test case, Karen has a grid with 3 rows and 3 columns. It is clear that it is impossible to beat the level; performing any move will create three 1s on the grid, but it is required to only have one 1 in the center. In the third test case, Karen has a grid with 3 rows and 3 columns. She can perform the following 3 moves to beat the level: <image> Note that this is not the only solution; another solution, among others, is col 1, col 2, col 3.
instruction
0
39,247
15
78,494
Tags: brute force, greedy, implementation Correct Solution: ``` n, m = map(int, input().split()) g = [list(map(int, input().split())) for i in range(n)] x, xi, xj = 500, 0, 0 for i, gi in enumerate(g): for j, gij in enumerate(gi): if gij < x: x, xi, xj = gij, i, j r, c = [g[i][xj] - x for i in range(n)], [g[xi][j] - x for j in range(m)] for i, gi in enumerate(g): for j, gij in enumerate(gi): if gij != r[i] + c[j] + x: print(-1) exit() print(min(n, m) * x + sum(r) + sum(c)) for i in range(n): for k in range(r[i] + (x if n <= m else 0)): print('row', i + 1) for j in range(m): for k in range(c[j] + (x if m < n else 0)): print('col', j + 1) ```
output
1
39,247
15
78,495
Provide tags and a correct Python 3 solution for this coding contest problem. On the way to school, Karen became fixated on the puzzle game on her phone! <image> The game is played as follows. In each level, you have a grid with n rows and m columns. Each cell originally contains the number 0. One move consists of choosing one row or column, and adding 1 to all of the cells in that row or column. To win the level, after all the moves, the number in the cell at the i-th row and j-th column should be equal to gi, j. Karen is stuck on one level, and wants to know a way to beat this level using the minimum number of moves. Please, help her with this task! Input The first line of input contains two integers, n and m (1 ≤ n, m ≤ 100), the number of rows and the number of columns in the grid, respectively. The next n lines each contain m integers. In particular, the j-th integer in the i-th of these rows contains gi, j (0 ≤ gi, j ≤ 500). Output If there is an error and it is actually not possible to beat the level, output a single integer -1. Otherwise, on the first line, output a single integer k, the minimum number of moves necessary to beat the level. The next k lines should each contain one of the following, describing the moves in the order they must be done: * row x, (1 ≤ x ≤ n) describing a move of the form "choose the x-th row". * col x, (1 ≤ x ≤ m) describing a move of the form "choose the x-th column". If there are multiple optimal solutions, output any one of them. Examples Input 3 5 2 2 2 3 2 0 0 0 1 0 1 1 1 2 1 Output 4 row 1 row 1 col 4 row 3 Input 3 3 0 0 0 0 1 0 0 0 0 Output -1 Input 3 3 1 1 1 1 1 1 1 1 1 Output 3 row 1 row 2 row 3 Note In the first test case, Karen has a grid with 3 rows and 5 columns. She can perform the following 4 moves to beat the level: <image> In the second test case, Karen has a grid with 3 rows and 3 columns. It is clear that it is impossible to beat the level; performing any move will create three 1s on the grid, but it is required to only have one 1 in the center. In the third test case, Karen has a grid with 3 rows and 3 columns. She can perform the following 3 moves to beat the level: <image> Note that this is not the only solution; another solution, among others, is col 1, col 2, col 3.
instruction
0
39,248
15
78,496
Tags: brute force, greedy, implementation Correct Solution: ``` # IAWT n, m = list(map(int, input().split())) g = [list(map(int, input().split())) for i in range(n)] class Phrase: # xa + y def __init__(self, x=0, y=0): self.x = x self.y = y def __add__(self, other): return Phrase(self.x+other.x, self.y+other.y) def __str__(self): return str(self.x)+'a'+' + '+str(self.y) class Equ: # left = right def __init__(self, a, b): self.left = a self.right = b def solve(self): if self.left.x == self.right.x and self.left.y == self.right.y: return 'infinity' self.left.x -= self.right.x self.right.x = 0 self.right.y -= self.left.y self.left.y = 0 if self.left.x == 0 and self.right.y != 0: return 'nothing' return self.right.y / self.left.x mina, maxa = 0, 1000 rows = [] for i in range(n): new = Phrase(-1, g[i][0]) rows.append(new) if new.x < 0: maxa = min(maxa, new.y / -(new.x)) if new.y < 0: mina = max(-(new.y) / new.x, mina) def f(): global exact, mina, maxa, cols, rows, a, s, i, u, s2 exact = '' cols = [Phrase(1, 0)] for i in range(1, m): last = Phrase(-rows[0].x, -rows[0].y + g[0][i]) cols.append(last) if last.x < 0 and last.y < 0: print(-1); return if last.x < 0: maxa = min(maxa, last.y / -(last.x)) if last.y < 0: mina = max(-(last.y) / last.x, mina) for u in range(1, n): new = Phrase(-rows[u].x, -rows[u].y + g[u][i]) rslt = Equ(last, new).solve() if rslt == 'nothing': print(-1) return if rslt == 'infinity': last = new continue if new.x < 0 and new.y < 0: print(-1); return if new.x < 0: maxa = min(maxa, new.y / -(new.x)) if new.y < 0: mina = max(-(new.y) / new.x, mina) if rslt % 1 != 0: print(-1) return if exact == '': exact = rslt elif rslt != exact: print(-1) return if mina % 1 != 0: mina = int(mina)+1 maxa = int(maxa) if maxa < mina: print(-1) return if exact != '': if exact > maxa or exact < mina: print(-1) return a = exact for i in range(m): for u in range(n): s = rows[i].x * a + rows[i].y + cols[u].x * a + cols[u].y if s != g[u][i]: print(-1) return for i in range(m): cols[i] = cols[i].x * a + cols[i].y if cols[i] % 1 != 0: print(-1) return cols[i] = int(cols[i]) for i in range(n): rows[i] = rows[i].x * a + rows[i].y if rows[i] % 1 != 0: print(-1) return rows[i] = int(rows[i]) s = sum(cols) + sum(rows) print(s) for i in range(m): for u in range(cols[i]): print('col', i+1) for i in range(n): for u in range(rows[i]): print('row', i+1) return else: s2 = Phrase() for i in range(m): s2 += cols[i] for i in range(n): s2 += rows[i] if s2.x < 0: a = maxa else: a = mina for i in range(m): cols[i] = cols[i].x * a + cols[i].y if cols[i] % 1 != 0: print(-1) return cols[i] = int(cols[i]) for i in range(n): rows[i] = rows[i].x * a + rows[i].y if rows[i] % 1 != 0: print(-1) return rows[i] = int(rows[i]) s = sum(cols) + sum(rows) print(s) for i in range(m): for u in range(cols[i]): print('col', i+1) for i in range(n): for u in range(rows[i]): print('row', i+1) return f() ```
output
1
39,248
15
78,497
Provide tags and a correct Python 3 solution for this coding contest problem. On the way to school, Karen became fixated on the puzzle game on her phone! <image> The game is played as follows. In each level, you have a grid with n rows and m columns. Each cell originally contains the number 0. One move consists of choosing one row or column, and adding 1 to all of the cells in that row or column. To win the level, after all the moves, the number in the cell at the i-th row and j-th column should be equal to gi, j. Karen is stuck on one level, and wants to know a way to beat this level using the minimum number of moves. Please, help her with this task! Input The first line of input contains two integers, n and m (1 ≤ n, m ≤ 100), the number of rows and the number of columns in the grid, respectively. The next n lines each contain m integers. In particular, the j-th integer in the i-th of these rows contains gi, j (0 ≤ gi, j ≤ 500). Output If there is an error and it is actually not possible to beat the level, output a single integer -1. Otherwise, on the first line, output a single integer k, the minimum number of moves necessary to beat the level. The next k lines should each contain one of the following, describing the moves in the order they must be done: * row x, (1 ≤ x ≤ n) describing a move of the form "choose the x-th row". * col x, (1 ≤ x ≤ m) describing a move of the form "choose the x-th column". If there are multiple optimal solutions, output any one of them. Examples Input 3 5 2 2 2 3 2 0 0 0 1 0 1 1 1 2 1 Output 4 row 1 row 1 col 4 row 3 Input 3 3 0 0 0 0 1 0 0 0 0 Output -1 Input 3 3 1 1 1 1 1 1 1 1 1 Output 3 row 1 row 2 row 3 Note In the first test case, Karen has a grid with 3 rows and 5 columns. She can perform the following 4 moves to beat the level: <image> In the second test case, Karen has a grid with 3 rows and 3 columns. It is clear that it is impossible to beat the level; performing any move will create three 1s on the grid, but it is required to only have one 1 in the center. In the third test case, Karen has a grid with 3 rows and 3 columns. She can perform the following 3 moves to beat the level: <image> Note that this is not the only solution; another solution, among others, is col 1, col 2, col 3.
instruction
0
39,249
15
78,498
Tags: brute force, greedy, implementation Correct Solution: ``` n, m = list(map(int, input().split())) a = [list(map(int, input().split())) for _ in range(n)] r = [a[i][0] - a[0][0] for i in range(n)] c = [a[0][i] - a[0][0] for i in range(m)] t = min(r) r = [x - t for x in r] t = min(c) c = [x - t for x in c] p = a[0][0] - r[0] - c[0] if n < m: r = [x + p for x in r] else: c = [x + p for x in c] for i in range(n): for j in range(m): if r[i] + c[j] != a[i][j]: print (-1) quit() print (sum(r) + sum(c)) for i, x in enumerate(r): for j in range(x): print ("row", i + 1) for i, x in enumerate(c): for j in range(x): print ("col", i + 1) ```
output
1
39,249
15
78,499