message
stringlengths
2
19.9k
message_type
stringclasses
2 values
message_id
int64
0
1
conversation_id
int64
322
108k
cluster
float64
15
15
__index_level_0__
int64
644
217k
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Once Volodya was at the museum and saw a regular chessboard as a museum piece. And there were only four chess pieces on it: two white rooks, a white king and a black king. "Aha, blacks certainly didn't win!", β€” Volodya said and was right for sure. And your task is to say whether whites had won or not. Pieces on the chessboard are guaranteed to represent a correct position (every piece occupies one cell, no two pieces occupy the same cell and kings cannot take each other). Thus, your task is only to decide whether whites mate blacks. We would remind you that it means that the black king can be taken by one of the opponent's pieces at the moment and also it cannot move to an unbeaten position. A rook moves vertically or horizontally by any number of free cells (assuming there are no other pieces on its path), a king β€” to the adjacent cells (either by corner or by side). Certainly, pieces cannot leave the board. The black king might be able to take opponent's rooks at his turn (see sample 3). Input The input contains 4 space-separated piece positions: positions of the two rooks, the white king and the black king. Each position on 8 Γ— 8 chessboard is denoted by two symbols β€” ('a' - 'h') and ('1' - '8') β€” which stand for horizontal and vertical coordinates of the cell occupied by the piece. It is guaranteed, that no two pieces occupy the same cell, and kings cannot take each other. Output Output should contain one word: "CHECKMATE" if whites mate blacks, and "OTHER" otherwise. Examples Input a6 b4 c8 a8 Output CHECKMATE Input a6 c4 b6 b8 Output OTHER Input a2 b1 a3 a1 Output OTHER Submitted Solution: ``` board = [[1] * 10 for i in range(10)] for i in range(1, 9): for j in range(1, 9): board[i][j] = 0 pieces = input().split() d = 'abcdefgh' for i in range(len(pieces)): pieces[i] = (d.index(pieces[i][0]) + 1, int(pieces[i][1])) x, y = pieces[2] for i in range(-1, 2): for j in range(-1, 2): board[x + i][y + j] = 1 def calc_rooks(x, y, dx, dy): global board if x == 0 or x == 9 or y == 0 or y == 9: return if x + dx != pieces[2][0] or y + dy != pieces[2][1]: board[x + dx][y + dy] = 1 calc_rooks(x + dx, y + dy, dx, dy) for i in range(2): x, y = pieces[i] calc_rooks(x, y, -1, 0) calc_rooks(x, y, 1, 0) calc_rooks(x, y, 0, -1) calc_rooks(x, y, 0, 1) k = 1 x, y = pieces[3] for i in range(-1, 2): for j in range(-1, 2): if board[x + i][y + j] == 0: print("OTHER") k = 0 if k: print("CHECKMATE") ```
instruction
0
100,691
15
201,382
No
output
1
100,691
15
201,383
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Once Volodya was at the museum and saw a regular chessboard as a museum piece. And there were only four chess pieces on it: two white rooks, a white king and a black king. "Aha, blacks certainly didn't win!", β€” Volodya said and was right for sure. And your task is to say whether whites had won or not. Pieces on the chessboard are guaranteed to represent a correct position (every piece occupies one cell, no two pieces occupy the same cell and kings cannot take each other). Thus, your task is only to decide whether whites mate blacks. We would remind you that it means that the black king can be taken by one of the opponent's pieces at the moment and also it cannot move to an unbeaten position. A rook moves vertically or horizontally by any number of free cells (assuming there are no other pieces on its path), a king β€” to the adjacent cells (either by corner or by side). Certainly, pieces cannot leave the board. The black king might be able to take opponent's rooks at his turn (see sample 3). Input The input contains 4 space-separated piece positions: positions of the two rooks, the white king and the black king. Each position on 8 Γ— 8 chessboard is denoted by two symbols β€” ('a' - 'h') and ('1' - '8') β€” which stand for horizontal and vertical coordinates of the cell occupied by the piece. It is guaranteed, that no two pieces occupy the same cell, and kings cannot take each other. Output Output should contain one word: "CHECKMATE" if whites mate blacks, and "OTHER" otherwise. Examples Input a6 b4 c8 a8 Output CHECKMATE Input a6 c4 b6 b8 Output OTHER Input a2 b1 a3 a1 Output OTHER Submitted Solution: ``` import sys sys.setrecursionlimit(10000) # default is 1000 in python # increase stack size as well (for hackerrank) # import resource # resource.setrlimit(resource.RLIMIT_STACK, (resource.RLIM_INFINITY, resource.RLIM_INFINITY)) rook1, rook2, white, black = input().split() rook1 = [ord(rook1[0])-96, int(rook1[1])] rook2 = [ord(rook2[0])-96, int(rook2[1])] white = [ord(white[0])-96, int(white[1])] black = [ord(black[0])-96, int(black[1])] def is_safe(position): taken = False if abs(position[0]-white[0]) > 1 or abs(position[1]-white[1]) > 1: if rook1[0] == position[0]: if white[0] == position[0] and (position[1] - white[1])*(white[1] - rook1[1]) > 0: # print("white in bw") pass elif rook2[0] == position[0] and (position[1] - rook2[1])*(rook2[1] - rook1[1]) > 0: pass # print("rook2 in bw :)") else: taken = True # taker = 'rook1' elif rook1[1] == position[1]: if white[1] == position[1] and (position[0] - white[0])*(white[0] - rook1[0]) > 0: pass # print("white in bw") elif rook2[1] == position[1] and (position[0] - rook2[0])*(rook2[0] - rook1[0]) > 0: pass # print("rook2 in bw :)") else: taken = True # pass # taker = 'rook1' if rook2[1] == position[1]: if white[1] == position[1] and (position[0] - white[0])*(white[0] - rook2[0]) > 0: pass # print("white in bw") elif rook1[1] == position[1] and (position[0] - rook1[0])*(rook1[0] - rook2[0]) > 0: pass # print("rook1 in bw :)") else: taken = True # taker = 'rook2' elif rook2[0] == position[0]: if white[0] == position[0] and (position[1] - white[1])*(white[1] - rook2[1]) > 0: pass # print("white in bw") elif rook1[0] == position[0] and (position[1] - rook1[1])*(rook1[1] - rook2[1]) > 0: pass # print("rook1 in bw :)") else: taken = True # taker = 'rook2' return taken old_pos = black.copy() taken = is_safe(old_pos) if taken is True: move_safe = False old_pos2 = black.copy() for i in range(-1, 2): for j in range(-1, 2): if 0 < old_pos2[0]+i < 9 and 0 < old_pos2[1]+j < 9: move_safe = is_safe([old_pos2[0]+i, old_pos2[1]+j]) if move_safe is True: break if taken is True and move_safe is False: print("CHECKMATE") else: print("OTHER") # try: # raise Exception # except: # print("-1") # from itertools import combinations # all_combs = list(combinations(range(N), r)) # from collections import OrderedDict # mydict = OrderedDict() # thenos.sort(key=lambda x: x[2], reverse=True) # int(math.log(max(numbers)+1,2)) # 2**3 (power) # a,t = (list(x) for x in zip(*sorted(zip(a, t)))) # to copy lists use: # import copy # copy.deepcopy(listname) # pow(p, si, 1000000007) for modular exponentiation # my_dict.pop('key', None) # This will return my_dict[key] if key exists in the dictionary, and None otherwise. # bin(int('010101', 2)) # Binary Search # from bisect import bisect_right # i = bisect_right(a, ins) ```
instruction
0
100,692
15
201,384
No
output
1
100,692
15
201,385
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Once Volodya was at the museum and saw a regular chessboard as a museum piece. And there were only four chess pieces on it: two white rooks, a white king and a black king. "Aha, blacks certainly didn't win!", β€” Volodya said and was right for sure. And your task is to say whether whites had won or not. Pieces on the chessboard are guaranteed to represent a correct position (every piece occupies one cell, no two pieces occupy the same cell and kings cannot take each other). Thus, your task is only to decide whether whites mate blacks. We would remind you that it means that the black king can be taken by one of the opponent's pieces at the moment and also it cannot move to an unbeaten position. A rook moves vertically or horizontally by any number of free cells (assuming there are no other pieces on its path), a king β€” to the adjacent cells (either by corner or by side). Certainly, pieces cannot leave the board. The black king might be able to take opponent's rooks at his turn (see sample 3). Input The input contains 4 space-separated piece positions: positions of the two rooks, the white king and the black king. Each position on 8 Γ— 8 chessboard is denoted by two symbols β€” ('a' - 'h') and ('1' - '8') β€” which stand for horizontal and vertical coordinates of the cell occupied by the piece. It is guaranteed, that no two pieces occupy the same cell, and kings cannot take each other. Output Output should contain one word: "CHECKMATE" if whites mate blacks, and "OTHER" otherwise. Examples Input a6 b4 c8 a8 Output CHECKMATE Input a6 c4 b6 b8 Output OTHER Input a2 b1 a3 a1 Output OTHER Submitted Solution: ``` import string class Position: def __init__(self, r, c): self.r = r self.c = c def s_to_position(s): letter, number = s[0], s[1] return Position(string.ascii_letters.index(letter), int(number) - 1) def finish(message): print(message) import sys; sys.exit() def king_attacks(attacker, defender): for dr in range(-1, 2): r = attacker.r + dr for dc in range(-1, 2): c = attacker.c + dc if r == defender.r and c == defender.c: return True return False def rook_attacks(attacker, defender): if attacker.r == defender.r and attacker.c == defender.c: return False if attacker.r == defender.r or attacker.c == defender.c: return True return False rook_a, rook_b, king_white, king_black = map(s_to_position, input().split()) for dr in range(-1, 2): r = king_black.r + dr for dc in range(-1, 2): c = king_black.c + dc if r < 0 or r > 7 or c < 0 or c > 7: continue current_king = Position(r, c) if king_attacks(king_white, current_king): #print('king attacks %d, %d' % (r, c)) continue if rook_attacks(rook_a, current_king): #print('rook A attacks %d, %d' % (r, c)) continue if rook_attacks(rook_b, current_king): #print('rook B attacks %d, %d' % (r, c)) continue #print('%d, %d is safe' % (r, c)) finish('OTHER') finish('CHECKMATE') ```
instruction
0
100,693
15
201,386
No
output
1
100,693
15
201,387
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Once Volodya was at the museum and saw a regular chessboard as a museum piece. And there were only four chess pieces on it: two white rooks, a white king and a black king. "Aha, blacks certainly didn't win!", β€” Volodya said and was right for sure. And your task is to say whether whites had won or not. Pieces on the chessboard are guaranteed to represent a correct position (every piece occupies one cell, no two pieces occupy the same cell and kings cannot take each other). Thus, your task is only to decide whether whites mate blacks. We would remind you that it means that the black king can be taken by one of the opponent's pieces at the moment and also it cannot move to an unbeaten position. A rook moves vertically or horizontally by any number of free cells (assuming there are no other pieces on its path), a king β€” to the adjacent cells (either by corner or by side). Certainly, pieces cannot leave the board. The black king might be able to take opponent's rooks at his turn (see sample 3). Input The input contains 4 space-separated piece positions: positions of the two rooks, the white king and the black king. Each position on 8 Γ— 8 chessboard is denoted by two symbols β€” ('a' - 'h') and ('1' - '8') β€” which stand for horizontal and vertical coordinates of the cell occupied by the piece. It is guaranteed, that no two pieces occupy the same cell, and kings cannot take each other. Output Output should contain one word: "CHECKMATE" if whites mate blacks, and "OTHER" otherwise. Examples Input a6 b4 c8 a8 Output CHECKMATE Input a6 c4 b6 b8 Output OTHER Input a2 b1 a3 a1 Output OTHER Submitted Solution: ``` import sys b = 'sabcdefgh' a1,a2,a3,a4 = map(str,input().split()) x1 = b.index(a1[0])-1 y1 = int(a1[1]) -1 x2 = b.index(a2[0])-1 y2 = int(a2[1]) -1 x3 = b.index(a3[0])-1 y3 = int(a3[1]) -1 x4 = b.index(a4[0])-1 y4 = int(a4[1]) -1 c = [] for i in range(8): c.append([0]*8) for i in range(8): if c[x1][i] != 1: c[x1][i] = 1 else: break for i in range(8): if c[x2][i] != 1: c[x2][i] = 1 else: break for i in range(8): if c[i][y1] != 1: c[i][y1] = 1 else: break for i in range(8): if c[i][y2] != 1: c[i][y2] = 1 else: break c[x1][y1] = 0 c[x2][y2] = 0 for i in range(-1,2): for j in range(-1,2): if x3 + i> -1 and x3+ i < 8 and y3+j > -1 and y3+j < 8: c[x3 + i][y3 + j] = 1 for i in range(-1,2): for j in range(-1,2): if x4 + i> -1 and x4+ i < 8 and y4+j > -1 and y4+j <8 : if c[x4 + i][y4 + j] == 0: print("OTHER") sys.exit() print("CHECKMATE") ```
instruction
0
100,694
15
201,388
No
output
1
100,694
15
201,389
Provide tags and a correct Python 3 solution for this coding contest problem. Alice has got addicted to a game called Sirtet recently. In Sirtet, player is given an n Γ— m grid. Initially a_{i,j} cubes are stacked up in the cell (i,j). Two cells are called adjacent if they share a side. Player can perform the following operations: * stack up one cube in two adjacent cells; * stack up two cubes in one cell. Cubes mentioned above are identical in height. Here is an illustration of the game. States on the right are obtained by performing one of the above operations on the state on the left, and grey cubes are added due to the operation. <image> Player's goal is to make the height of all cells the same (i.e. so that each cell has the same number of cubes in it) using above operations. Alice, however, has found out that on some starting grids she may never reach the goal no matter what strategy she uses. Thus, she is wondering the number of initial grids such that * L ≀ a_{i,j} ≀ R for all 1 ≀ i ≀ n, 1 ≀ j ≀ m; * player can reach the goal using above operations. Please help Alice with it. Notice that the answer might be large, please output the desired value modulo 998,244,353. Input The only line contains four integers n, m, L and R (1≀ n,m,L,R ≀ 10^9, L ≀ R, n β‹… m β‰₯ 2). Output Output one integer, representing the desired answer modulo 998,244,353. Examples Input 2 2 1 1 Output 1 Input 1 2 1 2 Output 2 Note In the first sample, the only initial grid that satisfies the requirements is a_{1,1}=a_{2,1}=a_{1,2}=a_{2,2}=1. Thus the answer should be 1. In the second sample, initial grids that satisfy the requirements are a_{1,1}=a_{1,2}=1 and a_{1,1}=a_{1,2}=2. Thus the answer should be 2.
instruction
0
101,348
15
202,696
Tags: combinatorics, constructive algorithms, math, matrices Correct Solution: ``` from math import ceil,log mod=998244353 n,m,l,r=map(int,input().split()) if (n*m)%2==1: ans=pow(r-l+1,n*m,mod) else: if (r-l+1)%2==0: ans=(pow(r-l+1,n*m,mod)*pow(2,mod-2,mod))%mod else: ans=((pow(r-l+1,n*m,mod)+mod+1)*pow(2,mod-2,mod))%mod print(ans) ```
output
1
101,348
15
202,697
Provide tags and a correct Python 3 solution for this coding contest problem. Alice has got addicted to a game called Sirtet recently. In Sirtet, player is given an n Γ— m grid. Initially a_{i,j} cubes are stacked up in the cell (i,j). Two cells are called adjacent if they share a side. Player can perform the following operations: * stack up one cube in two adjacent cells; * stack up two cubes in one cell. Cubes mentioned above are identical in height. Here is an illustration of the game. States on the right are obtained by performing one of the above operations on the state on the left, and grey cubes are added due to the operation. <image> Player's goal is to make the height of all cells the same (i.e. so that each cell has the same number of cubes in it) using above operations. Alice, however, has found out that on some starting grids she may never reach the goal no matter what strategy she uses. Thus, she is wondering the number of initial grids such that * L ≀ a_{i,j} ≀ R for all 1 ≀ i ≀ n, 1 ≀ j ≀ m; * player can reach the goal using above operations. Please help Alice with it. Notice that the answer might be large, please output the desired value modulo 998,244,353. Input The only line contains four integers n, m, L and R (1≀ n,m,L,R ≀ 10^9, L ≀ R, n β‹… m β‰₯ 2). Output Output one integer, representing the desired answer modulo 998,244,353. Examples Input 2 2 1 1 Output 1 Input 1 2 1 2 Output 2 Note In the first sample, the only initial grid that satisfies the requirements is a_{1,1}=a_{2,1}=a_{1,2}=a_{2,2}=1. Thus the answer should be 1. In the second sample, initial grids that satisfy the requirements are a_{1,1}=a_{1,2}=1 and a_{1,1}=a_{1,2}=2. Thus the answer should be 2.
instruction
0
101,349
15
202,698
Tags: combinatorics, constructive algorithms, math, matrices Correct Solution: ``` import sys readline = sys.stdin.readline def mat_dot(A, B, mod): assert len(A[0]) == len(B), 'invalid_size' L = len(A) M = len(A[0]) N = len(B[0]) res = [[0]*N for _ in range(L)] for i in range(L): for j in range(N): a = 0 for k in range(M): a = (a+A[i][k]*B[k][j]) % mod res[i][j] = a return res def mat_pow(A, x, mod): N = len(A) res = [[0]*N for _ in range(N)] for i in range(N): res[i][i] = 1 for i in range(x.bit_length()): if 2**i & x: res = mat_dot(res, A, mod) A = mat_dot(A, A, mod) return res MOD = 998244353 N, M, L, R = map(int, readline().split()) R -= L if N&1 and M&1: ans = pow(R+1, N*M, MOD) else: Bl = N*M//2 even = (R+1)//2 odd = R+1 - even Mat = [[even, odd], [odd, even]] xy = mat_dot(mat_pow(Mat, Bl, MOD), [[1], [0]], MOD) x, y = xy[0][0], xy[1][0] ans = (x*x + y*y) % MOD print(ans) ```
output
1
101,349
15
202,699
Provide tags and a correct Python 3 solution for this coding contest problem. Alice has got addicted to a game called Sirtet recently. In Sirtet, player is given an n Γ— m grid. Initially a_{i,j} cubes are stacked up in the cell (i,j). Two cells are called adjacent if they share a side. Player can perform the following operations: * stack up one cube in two adjacent cells; * stack up two cubes in one cell. Cubes mentioned above are identical in height. Here is an illustration of the game. States on the right are obtained by performing one of the above operations on the state on the left, and grey cubes are added due to the operation. <image> Player's goal is to make the height of all cells the same (i.e. so that each cell has the same number of cubes in it) using above operations. Alice, however, has found out that on some starting grids she may never reach the goal no matter what strategy she uses. Thus, she is wondering the number of initial grids such that * L ≀ a_{i,j} ≀ R for all 1 ≀ i ≀ n, 1 ≀ j ≀ m; * player can reach the goal using above operations. Please help Alice with it. Notice that the answer might be large, please output the desired value modulo 998,244,353. Input The only line contains four integers n, m, L and R (1≀ n,m,L,R ≀ 10^9, L ≀ R, n β‹… m β‰₯ 2). Output Output one integer, representing the desired answer modulo 998,244,353. Examples Input 2 2 1 1 Output 1 Input 1 2 1 2 Output 2 Note In the first sample, the only initial grid that satisfies the requirements is a_{1,1}=a_{2,1}=a_{1,2}=a_{2,2}=1. Thus the answer should be 1. In the second sample, initial grids that satisfy the requirements are a_{1,1}=a_{1,2}=1 and a_{1,1}=a_{1,2}=2. Thus the answer should be 2.
instruction
0
101,350
15
202,700
Tags: combinatorics, constructive algorithms, math, matrices Correct Solution: ``` mod = 998244353 n,m,l,r = map(int, input().split()) if(n*m % 2 == 1): print(pow(r-l+1,n*m,mod)) elif((r-l+1)%2 == 1): print(((pow(r-l+1,n*m,mod)+1)*(mod+1)//2)%mod) else: print(((pow(r-l+1,n*m,mod))*(mod+1)//2)%mod) ```
output
1
101,350
15
202,701
Provide tags and a correct Python 3 solution for this coding contest problem. Alice has got addicted to a game called Sirtet recently. In Sirtet, player is given an n Γ— m grid. Initially a_{i,j} cubes are stacked up in the cell (i,j). Two cells are called adjacent if they share a side. Player can perform the following operations: * stack up one cube in two adjacent cells; * stack up two cubes in one cell. Cubes mentioned above are identical in height. Here is an illustration of the game. States on the right are obtained by performing one of the above operations on the state on the left, and grey cubes are added due to the operation. <image> Player's goal is to make the height of all cells the same (i.e. so that each cell has the same number of cubes in it) using above operations. Alice, however, has found out that on some starting grids she may never reach the goal no matter what strategy she uses. Thus, she is wondering the number of initial grids such that * L ≀ a_{i,j} ≀ R for all 1 ≀ i ≀ n, 1 ≀ j ≀ m; * player can reach the goal using above operations. Please help Alice with it. Notice that the answer might be large, please output the desired value modulo 998,244,353. Input The only line contains four integers n, m, L and R (1≀ n,m,L,R ≀ 10^9, L ≀ R, n β‹… m β‰₯ 2). Output Output one integer, representing the desired answer modulo 998,244,353. Examples Input 2 2 1 1 Output 1 Input 1 2 1 2 Output 2 Note In the first sample, the only initial grid that satisfies the requirements is a_{1,1}=a_{2,1}=a_{1,2}=a_{2,2}=1. Thus the answer should be 1. In the second sample, initial grids that satisfy the requirements are a_{1,1}=a_{1,2}=1 and a_{1,1}=a_{1,2}=2. Thus the answer should be 2.
instruction
0
101,351
15
202,702
Tags: combinatorics, constructive algorithms, math, matrices Correct Solution: ``` import io import os from collections import Counter, defaultdict, deque DEBUG = False def modInverse(a, p): # Fermat's little theorem, a**(p-1) = 1 mod p return pow(a, p - 2, p) def solve(N, M, L, R): MOD = 998244353 num = R - L + 1 numCells = N * M # Answer doesn't have to lie with L and R so can always add 2 so that only parity matters # Once it's a 0 and 1 matrix, adding to two adjacent is equivalent to a swap, so order doesn't matter # If the number of odd cells is even or number of even cells is even, flip their parity so the matrix is all odd or all even if numCells % 2 == 1: # Anything works since one of the parity must be even count return pow(num, numCells, MOD) # If num cells is even, can't have odd even cells and odd odd cells. Can only have even even cell and even odd cells # Want to choose `2 * i` odd cells within numCells # Once parity is fixed the number of choices is numOdds^(2 * i) * numEvens^(numCells - 2 * i) # Plug into wolfram alpha: # numCells = 2 * K # \sum_{i=0}^{K} binomial(2 * K, 2 * i) * X^(2 * i) * Y^(2 * K - 2 * i) K = numCells // 2 X = num // 2 # number of values within range [L, R] that are odd Y = num // 2 # ditto for even if num % 2 != 0: if L % 2 == 0: X += 1 else: Y += 1 assert numCells % 2 == 0 ans = ( (pow(X + Y, numCells, MOD) + pow(X - Y, numCells, MOD)) * modInverse(2, MOD) ) % MOD if DEBUG: def nCr(n, r): def fact(i): if i == 0: return 1 return i * fact(i - 1) return fact(n) // (fact(n - r) * fact(r)) brute = 0 for i in range(numCells // 2 + 1): brute += nCr(numCells, 2 * i) * pow(X, 2 * i) * pow(Y, numCells - 2 * i) print(brute % MOD, ans) assert brute % MOD == ans return ans if DEBUG: for n in range(1, 5): for m in range(1, 5): for l in range(1, 5): for r in range(l, 5): if n * m < 2: continue solve(n, m, l, r) if __name__ == "__main__": input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline N, M, L, R = [int(x) for x in input().split()] ans = solve(N, M, L, R) print(ans) ```
output
1
101,351
15
202,703
Provide tags and a correct Python 3 solution for this coding contest problem. Alice has got addicted to a game called Sirtet recently. In Sirtet, player is given an n Γ— m grid. Initially a_{i,j} cubes are stacked up in the cell (i,j). Two cells are called adjacent if they share a side. Player can perform the following operations: * stack up one cube in two adjacent cells; * stack up two cubes in one cell. Cubes mentioned above are identical in height. Here is an illustration of the game. States on the right are obtained by performing one of the above operations on the state on the left, and grey cubes are added due to the operation. <image> Player's goal is to make the height of all cells the same (i.e. so that each cell has the same number of cubes in it) using above operations. Alice, however, has found out that on some starting grids she may never reach the goal no matter what strategy she uses. Thus, she is wondering the number of initial grids such that * L ≀ a_{i,j} ≀ R for all 1 ≀ i ≀ n, 1 ≀ j ≀ m; * player can reach the goal using above operations. Please help Alice with it. Notice that the answer might be large, please output the desired value modulo 998,244,353. Input The only line contains four integers n, m, L and R (1≀ n,m,L,R ≀ 10^9, L ≀ R, n β‹… m β‰₯ 2). Output Output one integer, representing the desired answer modulo 998,244,353. Examples Input 2 2 1 1 Output 1 Input 1 2 1 2 Output 2 Note In the first sample, the only initial grid that satisfies the requirements is a_{1,1}=a_{2,1}=a_{1,2}=a_{2,2}=1. Thus the answer should be 1. In the second sample, initial grids that satisfy the requirements are a_{1,1}=a_{1,2}=1 and a_{1,1}=a_{1,2}=2. Thus the answer should be 2.
instruction
0
101,352
15
202,704
Tags: combinatorics, constructive algorithms, math, matrices Correct Solution: ``` from sys import stdin input = stdin.readline def main(): mod = 998244353 n,m,l,r = map(int,input().split()) nm = n * m def mult(m1,m2): ans = [0] * 2 ans[0] = (m1[0] * m2[0] + m1[1] * m2[1])%mod ans[1] = (m1[0] * m2[1] + m1[1] * m2[0])%mod return ans def power(number, n): res = number while(n): if n & 1: res = mult(res,number) number = mult(number,number) n >>= 1 return res if nm % 2 == 0: num = r-l+1 ar = [num//2,num//2] if num % 2 == 1: ar[(l)%2] += 1 print(power(ar,nm-1)[0]) else: num = r-l+1 ar = [num//2,num//2] if num % 2 == 1: ar[(l)%2] += 1 ans = power(ar,nm-1) print(sum(ans) % mod) main() ```
output
1
101,352
15
202,705
Provide tags and a correct Python 3 solution for this coding contest problem. Alice has got addicted to a game called Sirtet recently. In Sirtet, player is given an n Γ— m grid. Initially a_{i,j} cubes are stacked up in the cell (i,j). Two cells are called adjacent if they share a side. Player can perform the following operations: * stack up one cube in two adjacent cells; * stack up two cubes in one cell. Cubes mentioned above are identical in height. Here is an illustration of the game. States on the right are obtained by performing one of the above operations on the state on the left, and grey cubes are added due to the operation. <image> Player's goal is to make the height of all cells the same (i.e. so that each cell has the same number of cubes in it) using above operations. Alice, however, has found out that on some starting grids she may never reach the goal no matter what strategy she uses. Thus, she is wondering the number of initial grids such that * L ≀ a_{i,j} ≀ R for all 1 ≀ i ≀ n, 1 ≀ j ≀ m; * player can reach the goal using above operations. Please help Alice with it. Notice that the answer might be large, please output the desired value modulo 998,244,353. Input The only line contains four integers n, m, L and R (1≀ n,m,L,R ≀ 10^9, L ≀ R, n β‹… m β‰₯ 2). Output Output one integer, representing the desired answer modulo 998,244,353. Examples Input 2 2 1 1 Output 1 Input 1 2 1 2 Output 2 Note In the first sample, the only initial grid that satisfies the requirements is a_{1,1}=a_{2,1}=a_{1,2}=a_{2,2}=1. Thus the answer should be 1. In the second sample, initial grids that satisfy the requirements are a_{1,1}=a_{1,2}=1 and a_{1,1}=a_{1,2}=2. Thus the answer should be 2.
instruction
0
101,353
15
202,706
Tags: combinatorics, constructive algorithms, math, matrices Correct Solution: ``` def expo(a,n): #print(a) #print(n) if n>0: ha = expo(a,n//2) if n%2==1: return (ha*ha*a)%MOD else: return (ha*ha)%MOD else: return 1 MOD = 998244353 def f(): n,m,L,R = map(int,input().split(" ")) height = R-L+1 area = n*m ans = expo(height,area) #print(ans) if(area%2==1): print(ans) else: if(height%2==0): if ans%2==1: ans+=MOD ans//=2 print(ans%MOD) else: if ans%2==0: ans+=MOD ans = (ans+1)//2 print(ans%MOD) f() ```
output
1
101,353
15
202,707
Provide tags and a correct Python 3 solution for this coding contest problem. Alice has got addicted to a game called Sirtet recently. In Sirtet, player is given an n Γ— m grid. Initially a_{i,j} cubes are stacked up in the cell (i,j). Two cells are called adjacent if they share a side. Player can perform the following operations: * stack up one cube in two adjacent cells; * stack up two cubes in one cell. Cubes mentioned above are identical in height. Here is an illustration of the game. States on the right are obtained by performing one of the above operations on the state on the left, and grey cubes are added due to the operation. <image> Player's goal is to make the height of all cells the same (i.e. so that each cell has the same number of cubes in it) using above operations. Alice, however, has found out that on some starting grids she may never reach the goal no matter what strategy she uses. Thus, she is wondering the number of initial grids such that * L ≀ a_{i,j} ≀ R for all 1 ≀ i ≀ n, 1 ≀ j ≀ m; * player can reach the goal using above operations. Please help Alice with it. Notice that the answer might be large, please output the desired value modulo 998,244,353. Input The only line contains four integers n, m, L and R (1≀ n,m,L,R ≀ 10^9, L ≀ R, n β‹… m β‰₯ 2). Output Output one integer, representing the desired answer modulo 998,244,353. Examples Input 2 2 1 1 Output 1 Input 1 2 1 2 Output 2 Note In the first sample, the only initial grid that satisfies the requirements is a_{1,1}=a_{2,1}=a_{1,2}=a_{2,2}=1. Thus the answer should be 1. In the second sample, initial grids that satisfy the requirements are a_{1,1}=a_{1,2}=1 and a_{1,1}=a_{1,2}=2. Thus the answer should be 2.
instruction
0
101,354
15
202,708
Tags: combinatorics, constructive algorithms, math, matrices Correct Solution: ``` MOD = 998244353 n,m,l,r = map(int,input().split()) # print(n,m,l,r) if n * m % 2 == 1: print(pow(r - l + 1,n*m,MOD)) else: e = r//2 - (l - 1)//2 o = (r - l + 1) - e # inv_2 = pow(2,MOD-2) print(((pow(e+o,n*m,MOD) + pow(e - o,n*m,MOD))*((MOD + 1)//2))%MOD) ```
output
1
101,354
15
202,709
Provide tags and a correct Python 3 solution for this coding contest problem. Alice has got addicted to a game called Sirtet recently. In Sirtet, player is given an n Γ— m grid. Initially a_{i,j} cubes are stacked up in the cell (i,j). Two cells are called adjacent if they share a side. Player can perform the following operations: * stack up one cube in two adjacent cells; * stack up two cubes in one cell. Cubes mentioned above are identical in height. Here is an illustration of the game. States on the right are obtained by performing one of the above operations on the state on the left, and grey cubes are added due to the operation. <image> Player's goal is to make the height of all cells the same (i.e. so that each cell has the same number of cubes in it) using above operations. Alice, however, has found out that on some starting grids she may never reach the goal no matter what strategy she uses. Thus, she is wondering the number of initial grids such that * L ≀ a_{i,j} ≀ R for all 1 ≀ i ≀ n, 1 ≀ j ≀ m; * player can reach the goal using above operations. Please help Alice with it. Notice that the answer might be large, please output the desired value modulo 998,244,353. Input The only line contains four integers n, m, L and R (1≀ n,m,L,R ≀ 10^9, L ≀ R, n β‹… m β‰₯ 2). Output Output one integer, representing the desired answer modulo 998,244,353. Examples Input 2 2 1 1 Output 1 Input 1 2 1 2 Output 2 Note In the first sample, the only initial grid that satisfies the requirements is a_{1,1}=a_{2,1}=a_{1,2}=a_{2,2}=1. Thus the answer should be 1. In the second sample, initial grids that satisfy the requirements are a_{1,1}=a_{1,2}=1 and a_{1,1}=a_{1,2}=2. Thus the answer should be 2.
instruction
0
101,355
15
202,710
Tags: combinatorics, constructive algorithms, math, matrices Correct Solution: ``` n,m,L,R = map(int,input().strip().split()) if(n%2 ==1 and m%2 ==1): print(pow((R-L+1),n*m, 998244353)) else: po = (R-L+1)//2 poo = (R - L + 2) // 2 c = ((pow(po+poo,n*m,998244353) + pow(po-poo,n*m,998244353))*(pow(2,998244351,998244353)))%998244353 print(c) ```
output
1
101,355
15
202,711
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Alice has got addicted to a game called Sirtet recently. In Sirtet, player is given an n Γ— m grid. Initially a_{i,j} cubes are stacked up in the cell (i,j). Two cells are called adjacent if they share a side. Player can perform the following operations: * stack up one cube in two adjacent cells; * stack up two cubes in one cell. Cubes mentioned above are identical in height. Here is an illustration of the game. States on the right are obtained by performing one of the above operations on the state on the left, and grey cubes are added due to the operation. <image> Player's goal is to make the height of all cells the same (i.e. so that each cell has the same number of cubes in it) using above operations. Alice, however, has found out that on some starting grids she may never reach the goal no matter what strategy she uses. Thus, she is wondering the number of initial grids such that * L ≀ a_{i,j} ≀ R for all 1 ≀ i ≀ n, 1 ≀ j ≀ m; * player can reach the goal using above operations. Please help Alice with it. Notice that the answer might be large, please output the desired value modulo 998,244,353. Input The only line contains four integers n, m, L and R (1≀ n,m,L,R ≀ 10^9, L ≀ R, n β‹… m β‰₯ 2). Output Output one integer, representing the desired answer modulo 998,244,353. Examples Input 2 2 1 1 Output 1 Input 1 2 1 2 Output 2 Note In the first sample, the only initial grid that satisfies the requirements is a_{1,1}=a_{2,1}=a_{1,2}=a_{2,2}=1. Thus the answer should be 1. In the second sample, initial grids that satisfy the requirements are a_{1,1}=a_{1,2}=1 and a_{1,1}=a_{1,2}=2. Thus the answer should be 2. Submitted Solution: ``` n, m, l, r = [int(i) for i in input().split()] mod = 998244353 ans = 0 if (n*m)&1: ans = pow(r-l+1, m*n, mod) else: if l&1 != r&1: k = 0 elif l&1: k = 1 else: k = 1 ans = ((pow(r-l+1, m*n, mod) + k) * pow(2, mod-2, mod))%mod print(ans) ```
instruction
0
101,356
15
202,712
Yes
output
1
101,356
15
202,713
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Alice has got addicted to a game called Sirtet recently. In Sirtet, player is given an n Γ— m grid. Initially a_{i,j} cubes are stacked up in the cell (i,j). Two cells are called adjacent if they share a side. Player can perform the following operations: * stack up one cube in two adjacent cells; * stack up two cubes in one cell. Cubes mentioned above are identical in height. Here is an illustration of the game. States on the right are obtained by performing one of the above operations on the state on the left, and grey cubes are added due to the operation. <image> Player's goal is to make the height of all cells the same (i.e. so that each cell has the same number of cubes in it) using above operations. Alice, however, has found out that on some starting grids she may never reach the goal no matter what strategy she uses. Thus, she is wondering the number of initial grids such that * L ≀ a_{i,j} ≀ R for all 1 ≀ i ≀ n, 1 ≀ j ≀ m; * player can reach the goal using above operations. Please help Alice with it. Notice that the answer might be large, please output the desired value modulo 998,244,353. Input The only line contains four integers n, m, L and R (1≀ n,m,L,R ≀ 10^9, L ≀ R, n β‹… m β‰₯ 2). Output Output one integer, representing the desired answer modulo 998,244,353. Examples Input 2 2 1 1 Output 1 Input 1 2 1 2 Output 2 Note In the first sample, the only initial grid that satisfies the requirements is a_{1,1}=a_{2,1}=a_{1,2}=a_{2,2}=1. Thus the answer should be 1. In the second sample, initial grids that satisfy the requirements are a_{1,1}=a_{1,2}=1 and a_{1,1}=a_{1,2}=2. Thus the answer should be 2. Submitted Solution: ``` MOD = 998244353 n, m, l, r = map(int, input().split()) if n * m % 2 == 1: print(pow(r - l + 1, n * m, MOD)) elif (r - l + 1) % 2 == 0: print(pow(r - l + 1, n * m, MOD) * (MOD + 1) // 2 % MOD) else: print((pow(r - l + 1, n * m, MOD) + 1) * (MOD + 1) // 2 % MOD) ```
instruction
0
101,357
15
202,714
Yes
output
1
101,357
15
202,715
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Alice has got addicted to a game called Sirtet recently. In Sirtet, player is given an n Γ— m grid. Initially a_{i,j} cubes are stacked up in the cell (i,j). Two cells are called adjacent if they share a side. Player can perform the following operations: * stack up one cube in two adjacent cells; * stack up two cubes in one cell. Cubes mentioned above are identical in height. Here is an illustration of the game. States on the right are obtained by performing one of the above operations on the state on the left, and grey cubes are added due to the operation. <image> Player's goal is to make the height of all cells the same (i.e. so that each cell has the same number of cubes in it) using above operations. Alice, however, has found out that on some starting grids she may never reach the goal no matter what strategy she uses. Thus, she is wondering the number of initial grids such that * L ≀ a_{i,j} ≀ R for all 1 ≀ i ≀ n, 1 ≀ j ≀ m; * player can reach the goal using above operations. Please help Alice with it. Notice that the answer might be large, please output the desired value modulo 998,244,353. Input The only line contains four integers n, m, L and R (1≀ n,m,L,R ≀ 10^9, L ≀ R, n β‹… m β‰₯ 2). Output Output one integer, representing the desired answer modulo 998,244,353. Examples Input 2 2 1 1 Output 1 Input 1 2 1 2 Output 2 Note In the first sample, the only initial grid that satisfies the requirements is a_{1,1}=a_{2,1}=a_{1,2}=a_{2,2}=1. Thus the answer should be 1. In the second sample, initial grids that satisfy the requirements are a_{1,1}=a_{1,2}=1 and a_{1,1}=a_{1,2}=2. Thus the answer should be 2. Submitted Solution: ``` # -*- coding:utf-8 -*- """ created by shuangquan.huang at 2020/7/2 """ import collections import time import os import sys import bisect import heapq from typing import List MOD = 998244353 if __name__ == '__main__': n, m, l, r = map(int, input().split()) if n * m % 2 == 1: print(pow(r - l + 1, n * m, MOD)) else: e = r // 2 - (l - 1) // 2 o = (r - l + 1) - e print((pow(e + o, n * m, MOD) + pow(e - o, n * m, MOD)) * (MOD + 1) // 2 % MOD) ```
instruction
0
101,358
15
202,716
Yes
output
1
101,358
15
202,717
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Alice has got addicted to a game called Sirtet recently. In Sirtet, player is given an n Γ— m grid. Initially a_{i,j} cubes are stacked up in the cell (i,j). Two cells are called adjacent if they share a side. Player can perform the following operations: * stack up one cube in two adjacent cells; * stack up two cubes in one cell. Cubes mentioned above are identical in height. Here is an illustration of the game. States on the right are obtained by performing one of the above operations on the state on the left, and grey cubes are added due to the operation. <image> Player's goal is to make the height of all cells the same (i.e. so that each cell has the same number of cubes in it) using above operations. Alice, however, has found out that on some starting grids she may never reach the goal no matter what strategy she uses. Thus, she is wondering the number of initial grids such that * L ≀ a_{i,j} ≀ R for all 1 ≀ i ≀ n, 1 ≀ j ≀ m; * player can reach the goal using above operations. Please help Alice with it. Notice that the answer might be large, please output the desired value modulo 998,244,353. Input The only line contains four integers n, m, L and R (1≀ n,m,L,R ≀ 10^9, L ≀ R, n β‹… m β‰₯ 2). Output Output one integer, representing the desired answer modulo 998,244,353. Examples Input 2 2 1 1 Output 1 Input 1 2 1 2 Output 2 Note In the first sample, the only initial grid that satisfies the requirements is a_{1,1}=a_{2,1}=a_{1,2}=a_{2,2}=1. Thus the answer should be 1. In the second sample, initial grids that satisfy the requirements are a_{1,1}=a_{1,2}=1 and a_{1,1}=a_{1,2}=2. Thus the answer should be 2. Submitted Solution: ``` N, M, L, R = map(int, input().split()) K = R - L + 1 P = 998244353 print(pow(K, N * M, P) if N * M % 2 else (pow(K, N * M, P) + K % 2) * ((P + 1) // 2) % P) ```
instruction
0
101,359
15
202,718
Yes
output
1
101,359
15
202,719
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Alice has got addicted to a game called Sirtet recently. In Sirtet, player is given an n Γ— m grid. Initially a_{i,j} cubes are stacked up in the cell (i,j). Two cells are called adjacent if they share a side. Player can perform the following operations: * stack up one cube in two adjacent cells; * stack up two cubes in one cell. Cubes mentioned above are identical in height. Here is an illustration of the game. States on the right are obtained by performing one of the above operations on the state on the left, and grey cubes are added due to the operation. <image> Player's goal is to make the height of all cells the same (i.e. so that each cell has the same number of cubes in it) using above operations. Alice, however, has found out that on some starting grids she may never reach the goal no matter what strategy she uses. Thus, she is wondering the number of initial grids such that * L ≀ a_{i,j} ≀ R for all 1 ≀ i ≀ n, 1 ≀ j ≀ m; * player can reach the goal using above operations. Please help Alice with it. Notice that the answer might be large, please output the desired value modulo 998,244,353. Input The only line contains four integers n, m, L and R (1≀ n,m,L,R ≀ 10^9, L ≀ R, n β‹… m β‰₯ 2). Output Output one integer, representing the desired answer modulo 998,244,353. Examples Input 2 2 1 1 Output 1 Input 1 2 1 2 Output 2 Note In the first sample, the only initial grid that satisfies the requirements is a_{1,1}=a_{2,1}=a_{1,2}=a_{2,2}=1. Thus the answer should be 1. In the second sample, initial grids that satisfy the requirements are a_{1,1}=a_{1,2}=1 and a_{1,1}=a_{1,2}=2. Thus the answer should be 2. Submitted Solution: ``` def pow_modulo(a, b, p): result = 1 a_pow2 = a % p while b: if b & 1: result = (result * a_pow2) % p b >>= 1 a_pow2 = (a_pow2 * a_pow2) % p return result def num_solvable(n, m): if (m * n) % 2 == 1: return pow_modulo(2, m * n, 998_244_353) else: return pow_modulo(2, m * n - 1, 998_244_353) n, m, h_min, h_max = map(int, input().split(' ')) if h_min == h_max: print(1) exit(0) result = num_solvable(n, m) if h_max - h_min >= 2: result *= pow_modulo((h_max - h_min) // 2, m * n, 998_244_353) print(result % 998_244_353) ```
instruction
0
101,360
15
202,720
No
output
1
101,360
15
202,721
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Alice has got addicted to a game called Sirtet recently. In Sirtet, player is given an n Γ— m grid. Initially a_{i,j} cubes are stacked up in the cell (i,j). Two cells are called adjacent if they share a side. Player can perform the following operations: * stack up one cube in two adjacent cells; * stack up two cubes in one cell. Cubes mentioned above are identical in height. Here is an illustration of the game. States on the right are obtained by performing one of the above operations on the state on the left, and grey cubes are added due to the operation. <image> Player's goal is to make the height of all cells the same (i.e. so that each cell has the same number of cubes in it) using above operations. Alice, however, has found out that on some starting grids she may never reach the goal no matter what strategy she uses. Thus, she is wondering the number of initial grids such that * L ≀ a_{i,j} ≀ R for all 1 ≀ i ≀ n, 1 ≀ j ≀ m; * player can reach the goal using above operations. Please help Alice with it. Notice that the answer might be large, please output the desired value modulo 998,244,353. Input The only line contains four integers n, m, L and R (1≀ n,m,L,R ≀ 10^9, L ≀ R, n β‹… m β‰₯ 2). Output Output one integer, representing the desired answer modulo 998,244,353. Examples Input 2 2 1 1 Output 1 Input 1 2 1 2 Output 2 Note In the first sample, the only initial grid that satisfies the requirements is a_{1,1}=a_{2,1}=a_{1,2}=a_{2,2}=1. Thus the answer should be 1. In the second sample, initial grids that satisfy the requirements are a_{1,1}=a_{1,2}=1 and a_{1,1}=a_{1,2}=2. Thus the answer should be 2. Submitted Solution: ``` def pow_fast_mod(a, b, div): s = 1 while b > 0: if b % 2: s %= div a %= div s *= a a %= div a *= a b = (b // 2) return s % div [n, m, L, R] = [int(s) for s in input().split()] h = R-L mod = 998244353 ret = 0 if n%2 and m%2: ret = pow_fast_mod(h+1, n*m, mod) else: x = pow_fast_mod(h+1, n*m/2, mod) a = x // 2 a %= mod b = (x+1) // 2 b %= mod ret = a*a+b*b print(int(ret%mod)) ```
instruction
0
101,362
15
202,724
No
output
1
101,362
15
202,725
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Alice has got addicted to a game called Sirtet recently. In Sirtet, player is given an n Γ— m grid. Initially a_{i,j} cubes are stacked up in the cell (i,j). Two cells are called adjacent if they share a side. Player can perform the following operations: * stack up one cube in two adjacent cells; * stack up two cubes in one cell. Cubes mentioned above are identical in height. Here is an illustration of the game. States on the right are obtained by performing one of the above operations on the state on the left, and grey cubes are added due to the operation. <image> Player's goal is to make the height of all cells the same (i.e. so that each cell has the same number of cubes in it) using above operations. Alice, however, has found out that on some starting grids she may never reach the goal no matter what strategy she uses. Thus, she is wondering the number of initial grids such that * L ≀ a_{i,j} ≀ R for all 1 ≀ i ≀ n, 1 ≀ j ≀ m; * player can reach the goal using above operations. Please help Alice with it. Notice that the answer might be large, please output the desired value modulo 998,244,353. Input The only line contains four integers n, m, L and R (1≀ n,m,L,R ≀ 10^9, L ≀ R, n β‹… m β‰₯ 2). Output Output one integer, representing the desired answer modulo 998,244,353. Examples Input 2 2 1 1 Output 1 Input 1 2 1 2 Output 2 Note In the first sample, the only initial grid that satisfies the requirements is a_{1,1}=a_{2,1}=a_{1,2}=a_{2,2}=1. Thus the answer should be 1. In the second sample, initial grids that satisfy the requirements are a_{1,1}=a_{1,2}=1 and a_{1,1}=a_{1,2}=2. Thus the answer should be 2. Submitted Solution: ``` MOD = 998244353 n, m, l, r = map(int, input().split()) a = (r - l + 1) // 2 b = a if (r - l + 1) % 2 == 1: b += 1 x = n * m if n * m % 2 == 1: ans = pow(a + b, x, MOD) else: ans = pow(2, x - 1, MOD) if 1 or a == b: ans *= pow(b, x, MOD) ans %= MOD # else: print(ans) ```
instruction
0
101,363
15
202,726
No
output
1
101,363
15
202,727
Provide tags and a correct Python 3 solution for this coding contest problem. One tradition of welcoming the New Year is launching fireworks into the sky. Usually a launched firework flies vertically upward for some period of time, then explodes, splitting into several parts flying in different directions. Sometimes those parts also explode after some period of time, splitting into even more parts, and so on. Limak, who lives in an infinite grid, has a single firework. The behaviour of the firework is described with a recursion depth n and a duration for each level of recursion t1, t2, ..., tn. Once Limak launches the firework in some cell, the firework starts moving upward. After covering t1 cells (including the starting cell), it explodes and splits into two parts, each moving in the direction changed by 45 degrees (see the pictures below for clarification). So, one part moves in the top-left direction, while the other one moves in the top-right direction. Each part explodes again after covering t2 cells, splitting into two parts moving in directions again changed by 45 degrees. The process continues till the n-th level of recursion, when all 2n - 1 existing parts explode and disappear without creating new parts. After a few levels of recursion, it's possible that some parts will be at the same place and at the same time β€” it is allowed and such parts do not crash. Before launching the firework, Limak must make sure that nobody stands in cells which will be visited at least once by the firework. Can you count the number of those cells? Input The first line of the input contains a single integer n (1 ≀ n ≀ 30) β€” the total depth of the recursion. The second line contains n integers t1, t2, ..., tn (1 ≀ ti ≀ 5). On the i-th level each of 2i - 1 parts will cover ti cells before exploding. Output Print one integer, denoting the number of cells which will be visited at least once by any part of the firework. Examples Input 4 4 2 2 3 Output 39 Input 6 1 1 1 1 1 3 Output 85 Input 1 3 Output 3 Note For the first sample, the drawings below show the situation after each level of recursion. Limak launched the firework from the bottom-most red cell. It covered t1 = 4 cells (marked red), exploded and divided into two parts (their further movement is marked green). All explosions are marked with an 'X' character. On the last drawing, there are 4 red, 4 green, 8 orange and 23 pink cells. So, the total number of visited cells is 4 + 4 + 8 + 23 = 39. <image> For the second sample, the drawings below show the situation after levels 4, 5 and 6. The middle drawing shows directions of all parts that will move in the next level. <image>
instruction
0
101,673
15
203,346
Tags: brute force, data structures, dfs and similar, dp, implementation Correct Solution: ``` import sys plane = set() crackers = {((0, -1), (0, 1))} n = int(input()) a = [int(x) for x in input().split()] crack_dict = { (1, 0): ((1, -1), (1, 1)), (1, 1): ((1, 0), (0, 1)), (0, 1): ((1, 1), (-1, 1)), (-1, 1): ((0, 1), (-1, 0)), (-1, 0): ((-1, 1), (-1, -1)), (-1, -1): ((-1, 0), (0, -1)), (0, -1): ((-1, -1), (1, -1)), (1, -1): ((0, -1), (1, 0)), } def move(cracker): point, direc = cracker point2 = (point[0] + direc[0], point[1] + direc[1]) return (point2, direc) def crack(cracker): point, direc = cracker direc1, direc2 = crack_dict[direc] return ((point, direc1), (point, direc2)) for x in a: for i in range(x): crackers = set((move(cracker) for cracker in crackers)) plane.update((cracker[0] for cracker in crackers)) # print(plane, file=sys.stderr) new_crackers = set() for cracker in crackers: new_crackers.update(crack(cracker)) crackers = new_crackers print(len(plane)) ```
output
1
101,673
15
203,347
Provide tags and a correct Python 3 solution for this coding contest problem. One tradition of welcoming the New Year is launching fireworks into the sky. Usually a launched firework flies vertically upward for some period of time, then explodes, splitting into several parts flying in different directions. Sometimes those parts also explode after some period of time, splitting into even more parts, and so on. Limak, who lives in an infinite grid, has a single firework. The behaviour of the firework is described with a recursion depth n and a duration for each level of recursion t1, t2, ..., tn. Once Limak launches the firework in some cell, the firework starts moving upward. After covering t1 cells (including the starting cell), it explodes and splits into two parts, each moving in the direction changed by 45 degrees (see the pictures below for clarification). So, one part moves in the top-left direction, while the other one moves in the top-right direction. Each part explodes again after covering t2 cells, splitting into two parts moving in directions again changed by 45 degrees. The process continues till the n-th level of recursion, when all 2n - 1 existing parts explode and disappear without creating new parts. After a few levels of recursion, it's possible that some parts will be at the same place and at the same time β€” it is allowed and such parts do not crash. Before launching the firework, Limak must make sure that nobody stands in cells which will be visited at least once by the firework. Can you count the number of those cells? Input The first line of the input contains a single integer n (1 ≀ n ≀ 30) β€” the total depth of the recursion. The second line contains n integers t1, t2, ..., tn (1 ≀ ti ≀ 5). On the i-th level each of 2i - 1 parts will cover ti cells before exploding. Output Print one integer, denoting the number of cells which will be visited at least once by any part of the firework. Examples Input 4 4 2 2 3 Output 39 Input 6 1 1 1 1 1 3 Output 85 Input 1 3 Output 3 Note For the first sample, the drawings below show the situation after each level of recursion. Limak launched the firework from the bottom-most red cell. It covered t1 = 4 cells (marked red), exploded and divided into two parts (their further movement is marked green). All explosions are marked with an 'X' character. On the last drawing, there are 4 red, 4 green, 8 orange and 23 pink cells. So, the total number of visited cells is 4 + 4 + 8 + 23 = 39. <image> For the second sample, the drawings below show the situation after levels 4, 5 and 6. The middle drawing shows directions of all parts that will move in the next level. <image>
instruction
0
101,674
15
203,348
Tags: brute force, data structures, dfs and similar, dp, implementation Correct Solution: ``` k = int(input()) & 1 p = [] s = range(1, 6) for q in map(int, input().split()[::-1]): if k: p += [(x, -y) for x, y in p] p = [(x - q, y) for x, y in p] p += [(-x, 0) for x in s[:q]] else: p += [(y, -x) for x, y in p] p = [(x - q, y + q) for x, y in p] p += [(-x, x) for x in s[:q]] p = list(set(p)) k = 1 - k print(len(p)) ```
output
1
101,674
15
203,349
Provide tags and a correct Python 3 solution for this coding contest problem. One tradition of welcoming the New Year is launching fireworks into the sky. Usually a launched firework flies vertically upward for some period of time, then explodes, splitting into several parts flying in different directions. Sometimes those parts also explode after some period of time, splitting into even more parts, and so on. Limak, who lives in an infinite grid, has a single firework. The behaviour of the firework is described with a recursion depth n and a duration for each level of recursion t1, t2, ..., tn. Once Limak launches the firework in some cell, the firework starts moving upward. After covering t1 cells (including the starting cell), it explodes and splits into two parts, each moving in the direction changed by 45 degrees (see the pictures below for clarification). So, one part moves in the top-left direction, while the other one moves in the top-right direction. Each part explodes again after covering t2 cells, splitting into two parts moving in directions again changed by 45 degrees. The process continues till the n-th level of recursion, when all 2n - 1 existing parts explode and disappear without creating new parts. After a few levels of recursion, it's possible that some parts will be at the same place and at the same time β€” it is allowed and such parts do not crash. Before launching the firework, Limak must make sure that nobody stands in cells which will be visited at least once by the firework. Can you count the number of those cells? Input The first line of the input contains a single integer n (1 ≀ n ≀ 30) β€” the total depth of the recursion. The second line contains n integers t1, t2, ..., tn (1 ≀ ti ≀ 5). On the i-th level each of 2i - 1 parts will cover ti cells before exploding. Output Print one integer, denoting the number of cells which will be visited at least once by any part of the firework. Examples Input 4 4 2 2 3 Output 39 Input 6 1 1 1 1 1 3 Output 85 Input 1 3 Output 3 Note For the first sample, the drawings below show the situation after each level of recursion. Limak launched the firework from the bottom-most red cell. It covered t1 = 4 cells (marked red), exploded and divided into two parts (their further movement is marked green). All explosions are marked with an 'X' character. On the last drawing, there are 4 red, 4 green, 8 orange and 23 pink cells. So, the total number of visited cells is 4 + 4 + 8 + 23 = 39. <image> For the second sample, the drawings below show the situation after levels 4, 5 and 6. The middle drawing shows directions of all parts that will move in the next level. <image>
instruction
0
101,675
15
203,350
Tags: brute force, data structures, dfs and similar, dp, implementation Correct Solution: ``` from math import sin def mp(): return map(int,input().split()) def lt(): return list(map(int,input().split())) def pt(x): print(x) def ip(): return input() def it(): return int(input()) def sl(x): return [t for t in x] def spl(x): return x.split() def aj(liste, item): liste.append(item) def bin(x): return "{0:b}".format(x) def listring(l): return ' '.join([str(x) for x in l]) def ptlist(l): print(' '.join([str(x) for x in l])) n = it() step = lt() dict = {} def explosion(start,s,d): (i,j) = start t = s+1 if d == 0: for k in range(j+1,j+t): dict[(i,k)] = True return ((i,j+t-1),(d+7)%8),((i,j+t-1),(d+1)%8) if d == 1: for k in range(1,t): dict[(i+k,j+k)] = True return ((i+t-1,j+t-1),(d+7)%8),((i+t-1,j+t-1),(d+1)%8) if d == 2: for k in range(1,t): dict[(i+k,j)] = True return ((i+t-1,j),(d+7)%8),((i+t-1,j),(d+1)%8) if d == 3: for k in range(1,t): dict[(i+k,j-k)] = True return ((i+t-1,j-t+1),(d+7)%8),((i+t-1,j-t+1),(d+1)%8) if d == 4: for k in range(1,t): dict[(i,j-k)] = True return ((i,j-t+1),(d+7)%8),((i,j-t+1),(d+1)%8) if d == 5: for k in range(1,t): dict[(i-k,j-k)] = True return ((i-t+1,j-t+1),(d+7)%8),((i-t+1,j-t+1),(d+1)%8) if d == 6: for k in range(1,t): dict[(i-k,j)] = True return ((i-t+1,j),(d+7)%8),((i-t+1,j),(d+1)%8) if d == 7: for k in range(1,t): dict[(i-k,j+k)] = True return ((i-t+1,j+t-1),(d+7)%8),((i-t+1,j+t-1),(d+1)%8) start = [((0,0),0)] for i in range(n): l = [] for p,q in start: a,b = explosion(p,step[i],q) l.append(a) l.append(b) start = set(l) pt(len(dict)) ```
output
1
101,675
15
203,351
Provide tags and a correct Python 3 solution for this coding contest problem. One tradition of welcoming the New Year is launching fireworks into the sky. Usually a launched firework flies vertically upward for some period of time, then explodes, splitting into several parts flying in different directions. Sometimes those parts also explode after some period of time, splitting into even more parts, and so on. Limak, who lives in an infinite grid, has a single firework. The behaviour of the firework is described with a recursion depth n and a duration for each level of recursion t1, t2, ..., tn. Once Limak launches the firework in some cell, the firework starts moving upward. After covering t1 cells (including the starting cell), it explodes and splits into two parts, each moving in the direction changed by 45 degrees (see the pictures below for clarification). So, one part moves in the top-left direction, while the other one moves in the top-right direction. Each part explodes again after covering t2 cells, splitting into two parts moving in directions again changed by 45 degrees. The process continues till the n-th level of recursion, when all 2n - 1 existing parts explode and disappear without creating new parts. After a few levels of recursion, it's possible that some parts will be at the same place and at the same time β€” it is allowed and such parts do not crash. Before launching the firework, Limak must make sure that nobody stands in cells which will be visited at least once by the firework. Can you count the number of those cells? Input The first line of the input contains a single integer n (1 ≀ n ≀ 30) β€” the total depth of the recursion. The second line contains n integers t1, t2, ..., tn (1 ≀ ti ≀ 5). On the i-th level each of 2i - 1 parts will cover ti cells before exploding. Output Print one integer, denoting the number of cells which will be visited at least once by any part of the firework. Examples Input 4 4 2 2 3 Output 39 Input 6 1 1 1 1 1 3 Output 85 Input 1 3 Output 3 Note For the first sample, the drawings below show the situation after each level of recursion. Limak launched the firework from the bottom-most red cell. It covered t1 = 4 cells (marked red), exploded and divided into two parts (their further movement is marked green). All explosions are marked with an 'X' character. On the last drawing, there are 4 red, 4 green, 8 orange and 23 pink cells. So, the total number of visited cells is 4 + 4 + 8 + 23 = 39. <image> For the second sample, the drawings below show the situation after levels 4, 5 and 6. The middle drawing shows directions of all parts that will move in the next level. <image>
instruction
0
101,676
15
203,352
Tags: brute force, data structures, dfs and similar, dp, implementation Correct Solution: ``` #!/usr/bin/env python3 from sys import stdin,stdout def ri(): return map(int, input().split()) w = 15 adding = [(0, 1), (-1, 1), (-1, 0), (-1, -1), (0, -1), (1, -1), (1, 0), (1, 1)] def fill(x, y,dir,depth): for i in range(t[depth]): x += adding[dir][0] y += adding[dir][1] v[x][y] = 1 def dfs(x, y, dir, depth): if depth == n: return #print(T, dir, depth) if (dir, depth) in T[x][y]: #print("found") #print(T, dir, depth) return fill(x,y,dir,depth) ndepth = depth+1 nx = x + adding[dir][0]*t[depth] ny = y + adding[dir][1]*t[depth] ndir = (dir+1)%8 dfs(nx, ny, ndir, ndepth) ndir = (8+dir-1)%8 dfs(nx, ny, ndir, ndepth) T[x][y].add(tuple((dir, depth))) n = int(input()) t = list(ri()) v = [[0 for i in range(n*w)] for j in range(n*w)] T = [[set() for i in range(n*w)] for j in range(n*w)] # x, y, dir, depth dfs(n*w//2, n*w//2, 0, 0) ans = 0 for i in range(n*w): for j in range(n*w): if v[i][j]: ans +=1 print(ans) ```
output
1
101,676
15
203,353
Provide tags and a correct Python 3 solution for this coding contest problem. One tradition of welcoming the New Year is launching fireworks into the sky. Usually a launched firework flies vertically upward for some period of time, then explodes, splitting into several parts flying in different directions. Sometimes those parts also explode after some period of time, splitting into even more parts, and so on. Limak, who lives in an infinite grid, has a single firework. The behaviour of the firework is described with a recursion depth n and a duration for each level of recursion t1, t2, ..., tn. Once Limak launches the firework in some cell, the firework starts moving upward. After covering t1 cells (including the starting cell), it explodes and splits into two parts, each moving in the direction changed by 45 degrees (see the pictures below for clarification). So, one part moves in the top-left direction, while the other one moves in the top-right direction. Each part explodes again after covering t2 cells, splitting into two parts moving in directions again changed by 45 degrees. The process continues till the n-th level of recursion, when all 2n - 1 existing parts explode and disappear without creating new parts. After a few levels of recursion, it's possible that some parts will be at the same place and at the same time β€” it is allowed and such parts do not crash. Before launching the firework, Limak must make sure that nobody stands in cells which will be visited at least once by the firework. Can you count the number of those cells? Input The first line of the input contains a single integer n (1 ≀ n ≀ 30) β€” the total depth of the recursion. The second line contains n integers t1, t2, ..., tn (1 ≀ ti ≀ 5). On the i-th level each of 2i - 1 parts will cover ti cells before exploding. Output Print one integer, denoting the number of cells which will be visited at least once by any part of the firework. Examples Input 4 4 2 2 3 Output 39 Input 6 1 1 1 1 1 3 Output 85 Input 1 3 Output 3 Note For the first sample, the drawings below show the situation after each level of recursion. Limak launched the firework from the bottom-most red cell. It covered t1 = 4 cells (marked red), exploded and divided into two parts (their further movement is marked green). All explosions are marked with an 'X' character. On the last drawing, there are 4 red, 4 green, 8 orange and 23 pink cells. So, the total number of visited cells is 4 + 4 + 8 + 23 = 39. <image> For the second sample, the drawings below show the situation after levels 4, 5 and 6. The middle drawing shows directions of all parts that will move in the next level. <image>
instruction
0
101,677
15
203,354
Tags: brute force, data structures, dfs and similar, dp, implementation Correct Solution: ``` dr = [[0, 1], [1, 1], [1, 0], [1, -1], [0, -1], [-1, -1], [-1, 0], [-1, 1]] n = int(input()) t = [int(i) for i in input().split()] visited = set() N = 150*2 + 10 covers = [[0]*N for i in range(N)] def dfs(d, pos, path): mem = (d, pos, path) if mem in visited: return set() else: visited.add(mem) if d == n+1: return for _ in range(t[d-1]): pos = (pos[0] + dr[path][0], pos[1] + dr[path][1]) covers[pos[0]][pos[1]] = 1 dfs(d+1, pos, (path+1) % 8) dfs(d+1, pos, (path-1) % 8) dfs(1, (int(N/2), int(N/2)), 0) print(sum([sum(i) for i in covers])) ```
output
1
101,677
15
203,355
Provide tags and a correct Python 3 solution for this coding contest problem. One tradition of welcoming the New Year is launching fireworks into the sky. Usually a launched firework flies vertically upward for some period of time, then explodes, splitting into several parts flying in different directions. Sometimes those parts also explode after some period of time, splitting into even more parts, and so on. Limak, who lives in an infinite grid, has a single firework. The behaviour of the firework is described with a recursion depth n and a duration for each level of recursion t1, t2, ..., tn. Once Limak launches the firework in some cell, the firework starts moving upward. After covering t1 cells (including the starting cell), it explodes and splits into two parts, each moving in the direction changed by 45 degrees (see the pictures below for clarification). So, one part moves in the top-left direction, while the other one moves in the top-right direction. Each part explodes again after covering t2 cells, splitting into two parts moving in directions again changed by 45 degrees. The process continues till the n-th level of recursion, when all 2n - 1 existing parts explode and disappear without creating new parts. After a few levels of recursion, it's possible that some parts will be at the same place and at the same time β€” it is allowed and such parts do not crash. Before launching the firework, Limak must make sure that nobody stands in cells which will be visited at least once by the firework. Can you count the number of those cells? Input The first line of the input contains a single integer n (1 ≀ n ≀ 30) β€” the total depth of the recursion. The second line contains n integers t1, t2, ..., tn (1 ≀ ti ≀ 5). On the i-th level each of 2i - 1 parts will cover ti cells before exploding. Output Print one integer, denoting the number of cells which will be visited at least once by any part of the firework. Examples Input 4 4 2 2 3 Output 39 Input 6 1 1 1 1 1 3 Output 85 Input 1 3 Output 3 Note For the first sample, the drawings below show the situation after each level of recursion. Limak launched the firework from the bottom-most red cell. It covered t1 = 4 cells (marked red), exploded and divided into two parts (their further movement is marked green). All explosions are marked with an 'X' character. On the last drawing, there are 4 red, 4 green, 8 orange and 23 pink cells. So, the total number of visited cells is 4 + 4 + 8 + 23 = 39. <image> For the second sample, the drawings below show the situation after levels 4, 5 and 6. The middle drawing shows directions of all parts that will move in the next level. <image>
instruction
0
101,678
15
203,356
Tags: brute force, data structures, dfs and similar, dp, implementation Correct Solution: ``` from collections import defaultdict dx = [0,-1,-1,-1, 0, 1, 1,1] dy = [1, 1, 0,-1,-1,-1, 0,1] #visited =[[[[False for _ in range(32)] for _ in range(8)] for _ in range(320)] for _ in range(320)] visited = defaultdict(lambda : False) grid = [[False for _ in range(320)] for _ in range(320)] def dfs(x,y,d,n,N, inp): if n >= N or visited[(x,y,d,n)]: return visited[(x,y,d,n)] = True dist = inp[n] for i in range(1,dist+1): grid[x+dx[d]*i][y+i*dy[d]] = True if (n < N): dfs(x + dx[d]*dist, y+dy[d]*dist, (d+1)%8, n+1,N,inp) dfs(x + dx[d]*dist, y+dy[d]*dist, (d+7)%8, n+1,N,inp) if __name__ == "__main__": N = int(input()) inp = list(map(int, input().strip().split())) dfs(160,160,0,0,N,inp) result = sum(map(sum,grid)) print(result) ```
output
1
101,678
15
203,357
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. One tradition of welcoming the New Year is launching fireworks into the sky. Usually a launched firework flies vertically upward for some period of time, then explodes, splitting into several parts flying in different directions. Sometimes those parts also explode after some period of time, splitting into even more parts, and so on. Limak, who lives in an infinite grid, has a single firework. The behaviour of the firework is described with a recursion depth n and a duration for each level of recursion t1, t2, ..., tn. Once Limak launches the firework in some cell, the firework starts moving upward. After covering t1 cells (including the starting cell), it explodes and splits into two parts, each moving in the direction changed by 45 degrees (see the pictures below for clarification). So, one part moves in the top-left direction, while the other one moves in the top-right direction. Each part explodes again after covering t2 cells, splitting into two parts moving in directions again changed by 45 degrees. The process continues till the n-th level of recursion, when all 2n - 1 existing parts explode and disappear without creating new parts. After a few levels of recursion, it's possible that some parts will be at the same place and at the same time β€” it is allowed and such parts do not crash. Before launching the firework, Limak must make sure that nobody stands in cells which will be visited at least once by the firework. Can you count the number of those cells? Input The first line of the input contains a single integer n (1 ≀ n ≀ 30) β€” the total depth of the recursion. The second line contains n integers t1, t2, ..., tn (1 ≀ ti ≀ 5). On the i-th level each of 2i - 1 parts will cover ti cells before exploding. Output Print one integer, denoting the number of cells which will be visited at least once by any part of the firework. Examples Input 4 4 2 2 3 Output 39 Input 6 1 1 1 1 1 3 Output 85 Input 1 3 Output 3 Note For the first sample, the drawings below show the situation after each level of recursion. Limak launched the firework from the bottom-most red cell. It covered t1 = 4 cells (marked red), exploded and divided into two parts (their further movement is marked green). All explosions are marked with an 'X' character. On the last drawing, there are 4 red, 4 green, 8 orange and 23 pink cells. So, the total number of visited cells is 4 + 4 + 8 + 23 = 39. <image> For the second sample, the drawings below show the situation after levels 4, 5 and 6. The middle drawing shows directions of all parts that will move in the next level. <image> Submitted Solution: ``` #!/usr/bin/env python DIRS = [(0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1), (-1, 0), (-1, 1)] def main(): n = int(input()) T = list(map(int, input().split())) dp = dict() dfs(0, T, 0, 0, 0, dp, last=True) print(len(dp)) def dfs(i, T, x, y, d, dp, last=False): n = len(T) if i == n: return p = (x, y) if p not in dp: dp[p] = dict() if i not in dp[p]: dp[p][i] = set() if d in dp[p][i]: return dp[p][i].add(d) t = T[i] while t > 1: x += DIRS[d][0] y += DIRS[d][1] p = (x, y) if p not in dp: dp[p] = dict() t -= 1 left = (d - 1) % 8 dfs(i + 1, T, x + DIRS[left][0], y + DIRS[left][1], left, dp, last=False) right = (d + 1) % 8 dfs(i + 1, T, x + DIRS[right][0], y + DIRS[right][1], right, dp, last=last) if last: print('Finish level %d.' % i) if __name__ == '__main__': main() ```
instruction
0
101,679
15
203,358
No
output
1
101,679
15
203,359
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. One tradition of welcoming the New Year is launching fireworks into the sky. Usually a launched firework flies vertically upward for some period of time, then explodes, splitting into several parts flying in different directions. Sometimes those parts also explode after some period of time, splitting into even more parts, and so on. Limak, who lives in an infinite grid, has a single firework. The behaviour of the firework is described with a recursion depth n and a duration for each level of recursion t1, t2, ..., tn. Once Limak launches the firework in some cell, the firework starts moving upward. After covering t1 cells (including the starting cell), it explodes and splits into two parts, each moving in the direction changed by 45 degrees (see the pictures below for clarification). So, one part moves in the top-left direction, while the other one moves in the top-right direction. Each part explodes again after covering t2 cells, splitting into two parts moving in directions again changed by 45 degrees. The process continues till the n-th level of recursion, when all 2n - 1 existing parts explode and disappear without creating new parts. After a few levels of recursion, it's possible that some parts will be at the same place and at the same time β€” it is allowed and such parts do not crash. Before launching the firework, Limak must make sure that nobody stands in cells which will be visited at least once by the firework. Can you count the number of those cells? Input The first line of the input contains a single integer n (1 ≀ n ≀ 30) β€” the total depth of the recursion. The second line contains n integers t1, t2, ..., tn (1 ≀ ti ≀ 5). On the i-th level each of 2i - 1 parts will cover ti cells before exploding. Output Print one integer, denoting the number of cells which will be visited at least once by any part of the firework. Examples Input 4 4 2 2 3 Output 39 Input 6 1 1 1 1 1 3 Output 85 Input 1 3 Output 3 Note For the first sample, the drawings below show the situation after each level of recursion. Limak launched the firework from the bottom-most red cell. It covered t1 = 4 cells (marked red), exploded and divided into two parts (their further movement is marked green). All explosions are marked with an 'X' character. On the last drawing, there are 4 red, 4 green, 8 orange and 23 pink cells. So, the total number of visited cells is 4 + 4 + 8 + 23 = 39. <image> For the second sample, the drawings below show the situation after levels 4, 5 and 6. The middle drawing shows directions of all parts that will move in the next level. <image> Submitted Solution: ``` from sys import stdin, stdout from collections import deque sze = 500; used = set() n = int(stdin.readline()) value = list(map(int, stdin.readline().split())) + [1] value[0] -= 1 visit = [[0 for i in range(sze)] for j in range(sze)] queue = deque([(250, 250, 0, 1)]) while queue[0][2] < n: y, x, num, d = queue.popleft() for j in range(value[num] + 1): if d == 1: visit[y - j][x] = 1 elif d == 2: visit[y - j][x - j] = 1 elif d == 3: visit[y][x - j] = 1 elif d == 4: visit[y + j][x - j] = 1 elif d == 5: visit[y + j][x] = 1 elif d == 6: visit[y + j][x + j] = 1 elif d == 7: visit[y][x + j] = 1 elif d == 8: visit[y - j][x + j] = 1 if d == 1: f = (y - value[num], x, value[num + 1], 2) s = (y - value[num], x, value[num + 1], 8) if not f in used: used.add(f) queue.append((y - value[num], x, num + 1, 2)) if not s in used: used.add(s) queue.append((y - value[num], x, num + 1, 8)) elif d == 2: f = (y - value[num], x - value[num], value[num + 1], 3) s = (y - value[num], x - value[num], value[num + 1], 1) if not f in used: used.add(f) queue.append((y - value[num], x - value[num], num + 1, 3)) if not s in used: used.add(s) queue.append((y - value[num], x - value[num], num + 1, 1)) elif d == 3: f = (y, x - value[num], value[num + 1], 4) s = (y, x - value[num], value[num + 1], 2) if not f in used: used.add(f) queue.append((y, x - value[num], num + 1, 4)) if not s in used: used.add(s) queue.append((y, x - value[num], num + 1, 2)) elif d == 4: f = (y + value[num], x - value[num], value[num + 1], 5) s = (y + value[num], x - value[num], value[num + 1], 3) if not f in used: used.add(f) queue.append((y + value[num], x - value[num], num + 1, 5)) if not s in used: used.add(s) queue.append((y + value[num], x - value[num], num + 1, 3)) elif d == 5: f = (y + value[num], x, value[num + 1], 6) s = (y + value[num], x, value[num + 1], 4) if not f in used: used.add(f) queue.append((y + value[num], x, num + 1, 6)) if not s in used: used.add(s) queue.append((y + value[num], x, num + 1, 4)) elif d == 6: f = (y + value[num], x + value[num], value[num + 1], 7) s = (y + value[num], x + value[num], value[num + 1], 5) if not f in used: used.add(f) queue.append((y + value[num], x + value[num], num + 1, 7)) if not s in used: used.add(s) queue.append((y + value[num], x + value[num], num + 1, 5)) elif d == 7: f = (y, x + value[num], value[num + 1], 8) s = (y, x + value[num], value[num + 1], 6) if not f in used: used.add(f) queue.append((y, x + value[num], num + 1, 8)) if not s in used: used.add(s) queue.append((y, x + value[num], num + 1, 6)) elif d == 8: f = (y - value[num], x + value[num], value[num + 1], 7) s = (y - value[num], x + value[num], value[num + 1], 1) if not f in used: used.add(f) queue.append((y - value[num], x + value[num], num + 1, 7)) if not s in used: used.add(s) queue.append((y - value[num], x + value[num], num + 1, 1)) ans = 0 for i in range(sze): for j in range(sze): if visit[i][j]: ans += 1 stdout.write(str(ans)) ```
instruction
0
101,680
15
203,360
No
output
1
101,680
15
203,361
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. One tradition of welcoming the New Year is launching fireworks into the sky. Usually a launched firework flies vertically upward for some period of time, then explodes, splitting into several parts flying in different directions. Sometimes those parts also explode after some period of time, splitting into even more parts, and so on. Limak, who lives in an infinite grid, has a single firework. The behaviour of the firework is described with a recursion depth n and a duration for each level of recursion t1, t2, ..., tn. Once Limak launches the firework in some cell, the firework starts moving upward. After covering t1 cells (including the starting cell), it explodes and splits into two parts, each moving in the direction changed by 45 degrees (see the pictures below for clarification). So, one part moves in the top-left direction, while the other one moves in the top-right direction. Each part explodes again after covering t2 cells, splitting into two parts moving in directions again changed by 45 degrees. The process continues till the n-th level of recursion, when all 2n - 1 existing parts explode and disappear without creating new parts. After a few levels of recursion, it's possible that some parts will be at the same place and at the same time β€” it is allowed and such parts do not crash. Before launching the firework, Limak must make sure that nobody stands in cells which will be visited at least once by the firework. Can you count the number of those cells? Input The first line of the input contains a single integer n (1 ≀ n ≀ 30) β€” the total depth of the recursion. The second line contains n integers t1, t2, ..., tn (1 ≀ ti ≀ 5). On the i-th level each of 2i - 1 parts will cover ti cells before exploding. Output Print one integer, denoting the number of cells which will be visited at least once by any part of the firework. Examples Input 4 4 2 2 3 Output 39 Input 6 1 1 1 1 1 3 Output 85 Input 1 3 Output 3 Note For the first sample, the drawings below show the situation after each level of recursion. Limak launched the firework from the bottom-most red cell. It covered t1 = 4 cells (marked red), exploded and divided into two parts (their further movement is marked green). All explosions are marked with an 'X' character. On the last drawing, there are 4 red, 4 green, 8 orange and 23 pink cells. So, the total number of visited cells is 4 + 4 + 8 + 23 = 39. <image> For the second sample, the drawings below show the situation after levels 4, 5 and 6. The middle drawing shows directions of all parts that will move in the next level. <image> Submitted Solution: ``` import time coord = set() flows = int(input()) start = time.time() t = list(map(int, input().split())) directions = {0: (0, 1), 1: (1, 1), 2: (1, 0), 3: (1, -1), 4: (0, -1), 5: (-1, -1), 6: (-1, 0), 7: (-1, 1)} was = [[[[0] * 300 for d2 in range(300)] for d3 in range(31)] for d4 in range(8)] #print(time.time()-start) def flight(n, x=0, y=0, direction=0): if was[direction][n][x][y]: return was[direction][n][x][y] = 1 if n: for _ in range(t[flows - n]): x += directions[direction][0] y += directions[direction][1] coord.add((x, y)) flight(n - 1, x, y, (direction + 1) % 8) flight(n - 1, x, y, (direction - 1) % 8) flight(flows) print(len(coord)) #print(time.time()-start) ```
instruction
0
101,681
15
203,362
No
output
1
101,681
15
203,363
Provide tags and a correct Python 3 solution for this coding contest problem. Little C loves number Β«3Β» very much. He loves all things about it. Now he is playing a game on a chessboard of size n Γ— m. The cell in the x-th row and in the y-th column is called (x,y). Initially, The chessboard is empty. Each time, he places two chessmen on two different empty cells, the Manhattan distance between which is exactly 3. The Manhattan distance between two cells (x_i,y_i) and (x_j,y_j) is defined as |x_i-x_j|+|y_i-y_j|. He want to place as many chessmen as possible on the chessboard. Please help him find the maximum number of chessmen he can place. Input A single line contains two integers n and m (1 ≀ n,m ≀ 10^9) β€” the number of rows and the number of columns of the chessboard. Output Print one integer β€” the maximum number of chessmen Little C can place. Examples Input 2 2 Output 0 Input 3 3 Output 8 Note In the first example, the Manhattan distance between any two cells is smaller than 3, so the answer is 0. In the second example, a possible solution is (1,1)(3,2), (1,2)(3,3), (2,1)(1,3), (3,1)(2,3).
instruction
0
102,037
15
204,074
Tags: brute force, constructive algorithms, flows, graph matchings Correct Solution: ``` known = [ [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 2, 4], [0, 0, 0, 4, 8, 10], [0, 0, 4, 8, 12, 14], [0, 2, 8, 12, 16, 20], [0, 4, 10, 14, 20, 24] ] n,m = map(int,input().split(" ")) if n>m: n,m = m,n if n<=5 and m<=5: print(known[m][n]) elif n==1: print(6*(m//6)+ [0,0,0,0,2,4][m%6]) elif n==2: if m==7: print(12) else: print(2*m) else: print(2*int((m*n)//2)) ```
output
1
102,037
15
204,075
Provide tags and a correct Python 3 solution for this coding contest problem. Little C loves number Β«3Β» very much. He loves all things about it. Now he is playing a game on a chessboard of size n Γ— m. The cell in the x-th row and in the y-th column is called (x,y). Initially, The chessboard is empty. Each time, he places two chessmen on two different empty cells, the Manhattan distance between which is exactly 3. The Manhattan distance between two cells (x_i,y_i) and (x_j,y_j) is defined as |x_i-x_j|+|y_i-y_j|. He want to place as many chessmen as possible on the chessboard. Please help him find the maximum number of chessmen he can place. Input A single line contains two integers n and m (1 ≀ n,m ≀ 10^9) β€” the number of rows and the number of columns of the chessboard. Output Print one integer β€” the maximum number of chessmen Little C can place. Examples Input 2 2 Output 0 Input 3 3 Output 8 Note In the first example, the Manhattan distance between any two cells is smaller than 3, so the answer is 0. In the second example, a possible solution is (1,1)(3,2), (1,2)(3,3), (2,1)(1,3), (3,1)(2,3).
instruction
0
102,038
15
204,076
Tags: brute force, constructive algorithms, flows, graph matchings Correct Solution: ``` n,m=map(int,input().split()) if n > m: m,n=n, m if n == 1: if m % 6 == 0: print(m) elif m % 6 <= 3: print(m-(m%6)) else: print(m-(6-m%6)) elif( n == 2 and m == 2 ): print(0) elif( n == 2 and m == 3 ): print(4); elif( n == 2 and m == 7 ): print(12) else: if n % 2 and m % 2: print(n*m-1); else: print(n*m) # find the formula myself! ```
output
1
102,038
15
204,077
Provide tags and a correct Python 3 solution for this coding contest problem. Little C loves number Β«3Β» very much. He loves all things about it. Now he is playing a game on a chessboard of size n Γ— m. The cell in the x-th row and in the y-th column is called (x,y). Initially, The chessboard is empty. Each time, he places two chessmen on two different empty cells, the Manhattan distance between which is exactly 3. The Manhattan distance between two cells (x_i,y_i) and (x_j,y_j) is defined as |x_i-x_j|+|y_i-y_j|. He want to place as many chessmen as possible on the chessboard. Please help him find the maximum number of chessmen he can place. Input A single line contains two integers n and m (1 ≀ n,m ≀ 10^9) β€” the number of rows and the number of columns of the chessboard. Output Print one integer β€” the maximum number of chessmen Little C can place. Examples Input 2 2 Output 0 Input 3 3 Output 8 Note In the first example, the Manhattan distance between any two cells is smaller than 3, so the answer is 0. In the second example, a possible solution is (1,1)(3,2), (1,2)(3,3), (2,1)(1,3), (3,1)(2,3).
instruction
0
102,039
15
204,078
Tags: brute force, constructive algorithms, flows, graph matchings Correct Solution: ``` n, m = map(int, input().split()) m,n = max(m,n), min(n,m) a = m * n if m == 7 and n == 2: print(12) exit() if m == 3 and n == 2: print(4) exit() if n == 1: print(a - min(m % 6, 6 - m % 6)) else: if m * n >= 6: print(n * m - (n*m) % 2) else: print(0) ```
output
1
102,039
15
204,079
Provide tags and a correct Python 3 solution for this coding contest problem. Little C loves number Β«3Β» very much. He loves all things about it. Now he is playing a game on a chessboard of size n Γ— m. The cell in the x-th row and in the y-th column is called (x,y). Initially, The chessboard is empty. Each time, he places two chessmen on two different empty cells, the Manhattan distance between which is exactly 3. The Manhattan distance between two cells (x_i,y_i) and (x_j,y_j) is defined as |x_i-x_j|+|y_i-y_j|. He want to place as many chessmen as possible on the chessboard. Please help him find the maximum number of chessmen he can place. Input A single line contains two integers n and m (1 ≀ n,m ≀ 10^9) β€” the number of rows and the number of columns of the chessboard. Output Print one integer β€” the maximum number of chessmen Little C can place. Examples Input 2 2 Output 0 Input 3 3 Output 8 Note In the first example, the Manhattan distance between any two cells is smaller than 3, so the answer is 0. In the second example, a possible solution is (1,1)(3,2), (1,2)(3,3), (2,1)(1,3), (3,1)(2,3).
instruction
0
102,040
15
204,080
Tags: brute force, constructive algorithms, flows, graph matchings Correct Solution: ``` n,m=sorted(map(int,input().split())) print(n*m-{1:min(m%6,6-m%6),2:{2:4,3:2,7:2}.get(m,0)}.get(n,n&1*m&1)) ```
output
1
102,040
15
204,081
Provide tags and a correct Python 3 solution for this coding contest problem. Little C loves number Β«3Β» very much. He loves all things about it. Now he is playing a game on a chessboard of size n Γ— m. The cell in the x-th row and in the y-th column is called (x,y). Initially, The chessboard is empty. Each time, he places two chessmen on two different empty cells, the Manhattan distance between which is exactly 3. The Manhattan distance between two cells (x_i,y_i) and (x_j,y_j) is defined as |x_i-x_j|+|y_i-y_j|. He want to place as many chessmen as possible on the chessboard. Please help him find the maximum number of chessmen he can place. Input A single line contains two integers n and m (1 ≀ n,m ≀ 10^9) β€” the number of rows and the number of columns of the chessboard. Output Print one integer β€” the maximum number of chessmen Little C can place. Examples Input 2 2 Output 0 Input 3 3 Output 8 Note In the first example, the Manhattan distance between any two cells is smaller than 3, so the answer is 0. In the second example, a possible solution is (1,1)(3,2), (1,2)(3,3), (2,1)(1,3), (3,1)(2,3).
instruction
0
102,041
15
204,082
Tags: brute force, constructive algorithms, flows, graph matchings Correct Solution: ``` #yeh dil maange more n,m = map(int,input().split()) if n<m:n,m = m,n ans = 0 d = {0:0,1:1,2:2,3:3,4:2,5:1} if m==1:ans=d[n%6] elif m==2: if n==3:ans=2 elif n==2:ans=4 elif n==7:ans=2 else:ans =(n*m)%2 print(n*m-ans) ```
output
1
102,041
15
204,083
Provide tags and a correct Python 3 solution for this coding contest problem. Little C loves number Β«3Β» very much. He loves all things about it. Now he is playing a game on a chessboard of size n Γ— m. The cell in the x-th row and in the y-th column is called (x,y). Initially, The chessboard is empty. Each time, he places two chessmen on two different empty cells, the Manhattan distance between which is exactly 3. The Manhattan distance between two cells (x_i,y_i) and (x_j,y_j) is defined as |x_i-x_j|+|y_i-y_j|. He want to place as many chessmen as possible on the chessboard. Please help him find the maximum number of chessmen he can place. Input A single line contains two integers n and m (1 ≀ n,m ≀ 10^9) β€” the number of rows and the number of columns of the chessboard. Output Print one integer β€” the maximum number of chessmen Little C can place. Examples Input 2 2 Output 0 Input 3 3 Output 8 Note In the first example, the Manhattan distance between any two cells is smaller than 3, so the answer is 0. In the second example, a possible solution is (1,1)(3,2), (1,2)(3,3), (2,1)(1,3), (3,1)(2,3).
instruction
0
102,042
15
204,084
Tags: brute force, constructive algorithms, flows, graph matchings Correct Solution: ``` import math from decimal import * getcontext().prec = 30 n,m=map(int,input().split()) ans=0 if n<m: n,m=m,n if n<3 and m<3: ans=0 elif m==1: ans+=(n//6)*6 n%=6 if n>3: ans+=(n-3)*2 elif n%4==0 or m%4==0 or n%6==0 or m%6==0: ans=n*m elif n<=5 and m<=5: if n%2 and m%2: ans=n*m-1 elif n==3: ans=n*m-2 else : ans=n*m elif n*m==14: ans=12 else : ans=n*m//2*2 print(ans) ```
output
1
102,042
15
204,085
Provide tags and a correct Python 3 solution for this coding contest problem. Little C loves number Β«3Β» very much. He loves all things about it. Now he is playing a game on a chessboard of size n Γ— m. The cell in the x-th row and in the y-th column is called (x,y). Initially, The chessboard is empty. Each time, he places two chessmen on two different empty cells, the Manhattan distance between which is exactly 3. The Manhattan distance between two cells (x_i,y_i) and (x_j,y_j) is defined as |x_i-x_j|+|y_i-y_j|. He want to place as many chessmen as possible on the chessboard. Please help him find the maximum number of chessmen he can place. Input A single line contains two integers n and m (1 ≀ n,m ≀ 10^9) β€” the number of rows and the number of columns of the chessboard. Output Print one integer β€” the maximum number of chessmen Little C can place. Examples Input 2 2 Output 0 Input 3 3 Output 8 Note In the first example, the Manhattan distance between any two cells is smaller than 3, so the answer is 0. In the second example, a possible solution is (1,1)(3,2), (1,2)(3,3), (2,1)(1,3), (3,1)(2,3).
instruction
0
102,043
15
204,086
Tags: brute force, constructive algorithms, flows, graph matchings Correct Solution: ``` from math import * from collections import * import sys sys.setrecursionlimit(10**9) x,y = map(int,input().split()) if(x == 1): s = y%6 if(s == 4): s = 2 if(s == 5): s = 1 print(y-s) exit(0) if(y == 1): s = x%6 if(s == 4): s = 2 if(s == 5): s = 1 print(x-s) exit(0) x1 = min(x,y) y1 = max(x,y) if(x1 == 2): if(y1 == 2): print(0) elif(y1 == 3): print(4) elif(y1 == 7): print(12) else: print(2*y1) else: print(x1*y1 - (x1*y1)%2) ```
output
1
102,043
15
204,087
Provide tags and a correct Python 3 solution for this coding contest problem. Little C loves number Β«3Β» very much. He loves all things about it. Now he is playing a game on a chessboard of size n Γ— m. The cell in the x-th row and in the y-th column is called (x,y). Initially, The chessboard is empty. Each time, he places two chessmen on two different empty cells, the Manhattan distance between which is exactly 3. The Manhattan distance between two cells (x_i,y_i) and (x_j,y_j) is defined as |x_i-x_j|+|y_i-y_j|. He want to place as many chessmen as possible on the chessboard. Please help him find the maximum number of chessmen he can place. Input A single line contains two integers n and m (1 ≀ n,m ≀ 10^9) β€” the number of rows and the number of columns of the chessboard. Output Print one integer β€” the maximum number of chessmen Little C can place. Examples Input 2 2 Output 0 Input 3 3 Output 8 Note In the first example, the Manhattan distance between any two cells is smaller than 3, so the answer is 0. In the second example, a possible solution is (1,1)(3,2), (1,2)(3,3), (2,1)(1,3), (3,1)(2,3).
instruction
0
102,044
15
204,088
Tags: brute force, constructive algorithms, flows, graph matchings Correct Solution: ``` n,m=map(int,input().split(" ")) if n==1 or m==1: print((((n*m)//6)*6)+((n*m)%6>3)*((((n*m)%6)%3)*2)) elif n*m<6: print(0) elif n*m==6: print(4) elif n*m==14: print(12) # elif (n==2 and m%2==1) or (m==2 and n%2==1): # print(n*m-2) # elif((n==2 and m%2==0) or (m==2 and n%2==0)): # print(n*m) else: print(n*m-(n*m)%2) ```
output
1
102,044
15
204,089
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Little C loves number Β«3Β» very much. He loves all things about it. Now he is playing a game on a chessboard of size n Γ— m. The cell in the x-th row and in the y-th column is called (x,y). Initially, The chessboard is empty. Each time, he places two chessmen on two different empty cells, the Manhattan distance between which is exactly 3. The Manhattan distance between two cells (x_i,y_i) and (x_j,y_j) is defined as |x_i-x_j|+|y_i-y_j|. He want to place as many chessmen as possible on the chessboard. Please help him find the maximum number of chessmen he can place. Input A single line contains two integers n and m (1 ≀ n,m ≀ 10^9) β€” the number of rows and the number of columns of the chessboard. Output Print one integer β€” the maximum number of chessmen Little C can place. Examples Input 2 2 Output 0 Input 3 3 Output 8 Note In the first example, the Manhattan distance between any two cells is smaller than 3, so the answer is 0. In the second example, a possible solution is (1,1)(3,2), (1,2)(3,3), (2,1)(1,3), (3,1)(2,3). Submitted Solution: ``` n,m=map(int,input().split()) if (n*m<4 and (n==1 or m==1)) or (n*m<5 and (n!=1 and m!=1)): print(0) else: l=n*m if n%2==0 and m%2==0: if n==m: if n%3!=0 and n%4!=0: print(l-4) else: print(l) else: if n%4==0 or m%4==0: print(l) elif n%3==0 or m%3==0: print(l) else: print(l-2) elif n%2!=0 and m%2!=0: if n==1 or m==1: z=max(n,m) if z%6==0: print(z) else: s1=(z//6)*6 r=z%6 if r>3: s1=s1+2 r=r%4 s1=s1+(r*2) print(s1) else: print(l-1) #case3 else: if n==1 or m==1: z=max(n,m) if z%6==0: print(z) else: s1=(z//6)*6 r=z%6 if r>3: s1=s1+2 r=r%4 s1=s1+(r*2) print(s1) else: if n%4==0 or m%4==0: print(l) elif n%6==0 or m%6==0: print(l) else: if n%2==0: z=m else: z=n if z%4==1: print(l) else: if z>=6: if z%6==1: if z>7 and z%4==3: print(l) else: print(l-2) elif z%6==5 and z%4==3: print(l) elif z%6==3: print(l) else: print(l-2) ```
instruction
0
102,045
15
204,090
Yes
output
1
102,045
15
204,091
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Little C loves number Β«3Β» very much. He loves all things about it. Now he is playing a game on a chessboard of size n Γ— m. The cell in the x-th row and in the y-th column is called (x,y). Initially, The chessboard is empty. Each time, he places two chessmen on two different empty cells, the Manhattan distance between which is exactly 3. The Manhattan distance between two cells (x_i,y_i) and (x_j,y_j) is defined as |x_i-x_j|+|y_i-y_j|. He want to place as many chessmen as possible on the chessboard. Please help him find the maximum number of chessmen he can place. Input A single line contains two integers n and m (1 ≀ n,m ≀ 10^9) β€” the number of rows and the number of columns of the chessboard. Output Print one integer β€” the maximum number of chessmen Little C can place. Examples Input 2 2 Output 0 Input 3 3 Output 8 Note In the first example, the Manhattan distance between any two cells is smaller than 3, so the answer is 0. In the second example, a possible solution is (1,1)(3,2), (1,2)(3,3), (2,1)(1,3), (3,1)(2,3). Submitted Solution: ``` N,M = map(int,input().split()) l = [0,1,2,3,2,1] res = float('inf') for (n,m) in ((N,M),(M,N)): if l[n%6]==0: print(n*m) exit() elif l[n%6]==1: tmp = l[m%6] res = min(res,tmp) elif l[n%6]==2: if m>=4 and m!=7: print(n*m) exit() if m==2: tmp = 4 else: tmp = 2 res = min(res,tmp) else: if m==1: tmp = 3 elif m==2: tmp = 2 elif m%2==0: print(n*m) exit() else: tmp = 1 res = min(res,tmp) print(n*m-res) ```
instruction
0
102,046
15
204,092
Yes
output
1
102,046
15
204,093
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Little C loves number Β«3Β» very much. He loves all things about it. Now he is playing a game on a chessboard of size n Γ— m. The cell in the x-th row and in the y-th column is called (x,y). Initially, The chessboard is empty. Each time, he places two chessmen on two different empty cells, the Manhattan distance between which is exactly 3. The Manhattan distance between two cells (x_i,y_i) and (x_j,y_j) is defined as |x_i-x_j|+|y_i-y_j|. He want to place as many chessmen as possible on the chessboard. Please help him find the maximum number of chessmen he can place. Input A single line contains two integers n and m (1 ≀ n,m ≀ 10^9) β€” the number of rows and the number of columns of the chessboard. Output Print one integer β€” the maximum number of chessmen Little C can place. Examples Input 2 2 Output 0 Input 3 3 Output 8 Note In the first example, the Manhattan distance between any two cells is smaller than 3, so the answer is 0. In the second example, a possible solution is (1,1)(3,2), (1,2)(3,3), (2,1)(1,3), (3,1)(2,3). Submitted Solution: ``` n, m = map(int, input().split()) if n >= 4 and m >= 4: print(n * m - (n * m % 2)) else: if min(n, m) == 1: if max(n, m) % 6 == 5: print(max(n, m) // 6 * 6 + 4) elif max(n, m) % 6 == 4: print(max(n, m) // 6 * 6 + 2) else: print(max(n, m) // 6 * 6) elif min(n, m) == 2 and max(n, m) == 7: print(12) elif min(n, m) == 2 and max(n, m) >= 4 or min(n, m) == 3 and max(n, m) >= 4: print(n * m - (n * m % 2)) else: d = [[0, 0, 0, 2, 4], [0, 0, 4, 8, 10], [0, 0, 8, 12, 14], [0, 0, 0, 16, 20], [0, 0, 0, 0, 24]] print(d[min(n, m) - 1][max(n, m) - 1]) ```
instruction
0
102,047
15
204,094
Yes
output
1
102,047
15
204,095
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Little C loves number Β«3Β» very much. He loves all things about it. Now he is playing a game on a chessboard of size n Γ— m. The cell in the x-th row and in the y-th column is called (x,y). Initially, The chessboard is empty. Each time, he places two chessmen on two different empty cells, the Manhattan distance between which is exactly 3. The Manhattan distance between two cells (x_i,y_i) and (x_j,y_j) is defined as |x_i-x_j|+|y_i-y_j|. He want to place as many chessmen as possible on the chessboard. Please help him find the maximum number of chessmen he can place. Input A single line contains two integers n and m (1 ≀ n,m ≀ 10^9) β€” the number of rows and the number of columns of the chessboard. Output Print one integer β€” the maximum number of chessmen Little C can place. Examples Input 2 2 Output 0 Input 3 3 Output 8 Note In the first example, the Manhattan distance between any two cells is smaller than 3, so the answer is 0. In the second example, a possible solution is (1,1)(3,2), (1,2)(3,3), (2,1)(1,3), (3,1)(2,3). Submitted Solution: ``` n,m=map(int,input().split()) if n>m: n,m=m,n if n==1: print(m//6*6+max(m%6*2-6,0)) elif n==2: if m==2: print(0) elif m==3 or m==7: print(m*2-2) else: print(m*2) else: print(n*m//2*2) ```
instruction
0
102,048
15
204,096
Yes
output
1
102,048
15
204,097
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Little C loves number Β«3Β» very much. He loves all things about it. Now he is playing a game on a chessboard of size n Γ— m. The cell in the x-th row and in the y-th column is called (x,y). Initially, The chessboard is empty. Each time, he places two chessmen on two different empty cells, the Manhattan distance between which is exactly 3. The Manhattan distance between two cells (x_i,y_i) and (x_j,y_j) is defined as |x_i-x_j|+|y_i-y_j|. He want to place as many chessmen as possible on the chessboard. Please help him find the maximum number of chessmen he can place. Input A single line contains two integers n and m (1 ≀ n,m ≀ 10^9) β€” the number of rows and the number of columns of the chessboard. Output Print one integer β€” the maximum number of chessmen Little C can place. Examples Input 2 2 Output 0 Input 3 3 Output 8 Note In the first example, the Manhattan distance between any two cells is smaller than 3, so the answer is 0. In the second example, a possible solution is (1,1)(3,2), (1,2)(3,3), (2,1)(1,3), (3,1)(2,3). Submitted Solution: ``` n,m=map(int,input().split()) if (n*m<4 and (n==1 or m==1)) or (n*m<5 and (n!=1 and m!=1)): print(0) else: l=n*m s=[0]*(l+1) if n%2==0 and m%2==0: if n==m: if n%3!=0 and n%4!=0: print(l-4) else: print(l) else: if n%4==0 or m%4==0: print(l) elif n%3==0 or m%3==0: print(l) else: print(l-2) elif n%2!=0 and m%2!=0: print(l-1) else: if n==1 or m==1: z=max(n,m) if z%6==0: print(z) else: s1=(z//6)*6 r=z%6 if r>3: s1=s1+2 r=r%4 s1=s1+(r*2) else: print(l-2) ```
instruction
0
102,049
15
204,098
No
output
1
102,049
15
204,099
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Little C loves number Β«3Β» very much. He loves all things about it. Now he is playing a game on a chessboard of size n Γ— m. The cell in the x-th row and in the y-th column is called (x,y). Initially, The chessboard is empty. Each time, he places two chessmen on two different empty cells, the Manhattan distance between which is exactly 3. The Manhattan distance between two cells (x_i,y_i) and (x_j,y_j) is defined as |x_i-x_j|+|y_i-y_j|. He want to place as many chessmen as possible on the chessboard. Please help him find the maximum number of chessmen he can place. Input A single line contains two integers n and m (1 ≀ n,m ≀ 10^9) β€” the number of rows and the number of columns of the chessboard. Output Print one integer β€” the maximum number of chessmen Little C can place. Examples Input 2 2 Output 0 Input 3 3 Output 8 Note In the first example, the Manhattan distance between any two cells is smaller than 3, so the answer is 0. In the second example, a possible solution is (1,1)(3,2), (1,2)(3,3), (2,1)(1,3), (3,1)(2,3). Submitted Solution: ``` known = [ [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 2, 4], [0, 0, 0, 4, 8, 10], [0, 0, 4, 8, 12, 14], [0, 2, 8, 12, 16, 20], [0, 4, 10, 14, 20, 24] ] n,m = map(int,input().split(" ")) if n>m: n,m = m,n if n<=5 and m<=5: print(known[m][n]) elif n==1: print(6*(m//6)+ [0,0,0,2,4,6][m%6]) elif n==2: print(4*(int(m)//2)) else: print(2*int((m*n)//2)) ```
instruction
0
102,050
15
204,100
No
output
1
102,050
15
204,101
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Little C loves number Β«3Β» very much. He loves all things about it. Now he is playing a game on a chessboard of size n Γ— m. The cell in the x-th row and in the y-th column is called (x,y). Initially, The chessboard is empty. Each time, he places two chessmen on two different empty cells, the Manhattan distance between which is exactly 3. The Manhattan distance between two cells (x_i,y_i) and (x_j,y_j) is defined as |x_i-x_j|+|y_i-y_j|. He want to place as many chessmen as possible on the chessboard. Please help him find the maximum number of chessmen he can place. Input A single line contains two integers n and m (1 ≀ n,m ≀ 10^9) β€” the number of rows and the number of columns of the chessboard. Output Print one integer β€” the maximum number of chessmen Little C can place. Examples Input 2 2 Output 0 Input 3 3 Output 8 Note In the first example, the Manhattan distance between any two cells is smaller than 3, so the answer is 0. In the second example, a possible solution is (1,1)(3,2), (1,2)(3,3), (2,1)(1,3), (3,1)(2,3). Submitted Solution: ``` n,m=map(int,input().split()) if n+m<5: print(0) exit() if (n*m)%2!=0: ans=n*m-1 else: if (n*m)%8==0 or ((n*m)%6==0 and ((n+m)%2==0 or n==1 or m==1)): ans=m*n else: ans=n*m-2 print(ans) ```
instruction
0
102,051
15
204,102
No
output
1
102,051
15
204,103
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Little C loves number Β«3Β» very much. He loves all things about it. Now he is playing a game on a chessboard of size n Γ— m. The cell in the x-th row and in the y-th column is called (x,y). Initially, The chessboard is empty. Each time, he places two chessmen on two different empty cells, the Manhattan distance between which is exactly 3. The Manhattan distance between two cells (x_i,y_i) and (x_j,y_j) is defined as |x_i-x_j|+|y_i-y_j|. He want to place as many chessmen as possible on the chessboard. Please help him find the maximum number of chessmen he can place. Input A single line contains two integers n and m (1 ≀ n,m ≀ 10^9) β€” the number of rows and the number of columns of the chessboard. Output Print one integer β€” the maximum number of chessmen Little C can place. Examples Input 2 2 Output 0 Input 3 3 Output 8 Note In the first example, the Manhattan distance between any two cells is smaller than 3, so the answer is 0. In the second example, a possible solution is (1,1)(3,2), (1,2)(3,3), (2,1)(1,3), (3,1)(2,3). Submitted Solution: ``` n, m = map(int, input().split()) if n < 2 or m < 2: print(0) elif n + m == 4: print(0) elif n == 2: print(2 * m - 2 * min(m % 4, 4 - (m % 4))) elif m == 2: print(2 * n - 2 * min(n % 4, 4 - (n % 4))) else: if n % 2 == 0 and m % 2 == 0: print(n * m) elif n % 4 == 0 or m % 4 == 0: print(n * m) elif (n % 4) * (m % 4) == 3: print(n * m - 3) elif n * m % 2 == 0 and n * m % 4 != 0: print(n * m - 2) else: print(n * m - 1) ```
instruction
0
102,052
15
204,104
No
output
1
102,052
15
204,105
Provide tags and a correct Python 3 solution for this coding contest problem. In this task Anna and Maria play a game with a very unpleasant rival. Anna and Maria are in the opposite squares of a chessboard (8 Γ— 8): Anna is in the upper right corner, and Maria is in the lower left one. Apart from them, the board has several statues. Each statue occupies exactly one square. A square that contains a statue cannot have anything or anyone β€” neither any other statues, nor Anna, nor Maria. Anna is present on the board as a figurant (she stands still and never moves), and Maria has been actively involved in the game. Her goal is β€” to come to Anna's square. Maria and statues move in turn, Maria moves first. During one move Maria can go to any adjacent on the side or diagonal cell in which there is no statue, or she can stay in the cell where she is. The statues during their move must go one square down simultaneously, and those statues that were in the bottom row fall from the board and are no longer appeared. At that moment, when one of the statues is in the cell in which the Maria is, the statues are declared winners. At the moment when Maria comes into the cell where Anna has been waiting, Maria is declared the winner. Obviously, nothing depends on the statues, so it all depends on Maria. Determine who will win, if Maria does not make a strategic error. Input You are given the 8 strings whose length equals 8, describing the initial position on the board. The first line represents the top row of the board, the next one β€” for the second from the top, and so on, the last line represents the bottom row. Each character string matches a single cell board in the appropriate row, and the characters are in the same manner as that of the corresponding cell. If the cell is empty, the corresponding character is ".". If a cell has Maria, then it is represented by character "M". If a cell has Anna, it is represented by the character "A". If a cell has a statue, then the cell is represented by character "S". It is guaranteed that the last character of the first row is always "A", the first character of the last line is always "M". The remaining characters are "." or "S". Output If Maria wins, print string "WIN". If the statues win, print string "LOSE". Examples Input .......A ........ ........ ........ ........ ........ ........ M....... Output WIN Input .......A ........ ........ ........ ........ ........ SS...... M....... Output LOSE Input .......A ........ ........ ........ ........ .S...... S....... MS...... Output LOSE
instruction
0
102,140
15
204,280
Tags: dfs and similar Correct Solution: ``` a=list(input() for i in range(8)) ok1=list() ok2=set() ok1.append((7,0)) w=[(1,0),(-1,0),(0,1),(0,-1),(1,-1),(1,1),(-1,-1),(-1,1),(0,0)] for i in range(8) : for pos in ok1 : if pos[0]>=i and a[pos[0]-i][pos[1]] == 'S' : continue for j in w: to=(pos[0]+j[0],pos[1]+j[1]) if to[0]<8 and to[1]<8 and to[0]>-1 and to[1]>-1: if to[0]<i or a[to[0]-i][to[1]] != 'S' : ok2.add(to) ok1.clear() ok1=list(ok2.copy()) ok2.clear() print("WIN" if len(ok1)>0 else "LOSE") ```
output
1
102,140
15
204,281
Provide tags and a correct Python 3 solution for this coding contest problem. In this task Anna and Maria play a game with a very unpleasant rival. Anna and Maria are in the opposite squares of a chessboard (8 Γ— 8): Anna is in the upper right corner, and Maria is in the lower left one. Apart from them, the board has several statues. Each statue occupies exactly one square. A square that contains a statue cannot have anything or anyone β€” neither any other statues, nor Anna, nor Maria. Anna is present on the board as a figurant (she stands still and never moves), and Maria has been actively involved in the game. Her goal is β€” to come to Anna's square. Maria and statues move in turn, Maria moves first. During one move Maria can go to any adjacent on the side or diagonal cell in which there is no statue, or she can stay in the cell where she is. The statues during their move must go one square down simultaneously, and those statues that were in the bottom row fall from the board and are no longer appeared. At that moment, when one of the statues is in the cell in which the Maria is, the statues are declared winners. At the moment when Maria comes into the cell where Anna has been waiting, Maria is declared the winner. Obviously, nothing depends on the statues, so it all depends on Maria. Determine who will win, if Maria does not make a strategic error. Input You are given the 8 strings whose length equals 8, describing the initial position on the board. The first line represents the top row of the board, the next one β€” for the second from the top, and so on, the last line represents the bottom row. Each character string matches a single cell board in the appropriate row, and the characters are in the same manner as that of the corresponding cell. If the cell is empty, the corresponding character is ".". If a cell has Maria, then it is represented by character "M". If a cell has Anna, it is represented by the character "A". If a cell has a statue, then the cell is represented by character "S". It is guaranteed that the last character of the first row is always "A", the first character of the last line is always "M". The remaining characters are "." or "S". Output If Maria wins, print string "WIN". If the statues win, print string "LOSE". Examples Input .......A ........ ........ ........ ........ ........ ........ M....... Output WIN Input .......A ........ ........ ........ ........ ........ SS...... M....... Output LOSE Input .......A ........ ........ ........ ........ .S...... S....... MS...... Output LOSE
instruction
0
102,141
15
204,282
Tags: dfs and similar Correct Solution: ``` f = [] for i in range(8): f.append(input()) d = [[[0 for i in range(8)] for j in range(8)] for k in range(100)] d[0][7][0] = 1 dx = [1, 1, 1, 0, 0, -1, -1, -1, 0] dy = [1, 0, -1, 1, -1, 1, 0, -1, 0] ans = 'LOSE' for i in range(99): for x in range(8): for y in range(8): if not d[i][x][y]: continue for j in range(9): nx = x + dx[j] ny = y + dy[j] if not(0 <= nx < 8 and 0 <= ny < 8): continue valid = True if 0 <= nx - i < 8 and f[nx - i][ny] == 'S': valid = False if 0 <= nx - i - 1 < 8 and f[nx - i - 1][ny] == 'S': valid = False if not valid: continue d[i + 1][nx][ny] = 1 if nx == 0 and ny == 7: ans = 'WIN' print(ans) ```
output
1
102,141
15
204,283
Provide tags and a correct Python 3 solution for this coding contest problem. In this task Anna and Maria play a game with a very unpleasant rival. Anna and Maria are in the opposite squares of a chessboard (8 Γ— 8): Anna is in the upper right corner, and Maria is in the lower left one. Apart from them, the board has several statues. Each statue occupies exactly one square. A square that contains a statue cannot have anything or anyone β€” neither any other statues, nor Anna, nor Maria. Anna is present on the board as a figurant (she stands still and never moves), and Maria has been actively involved in the game. Her goal is β€” to come to Anna's square. Maria and statues move in turn, Maria moves first. During one move Maria can go to any adjacent on the side or diagonal cell in which there is no statue, or she can stay in the cell where she is. The statues during their move must go one square down simultaneously, and those statues that were in the bottom row fall from the board and are no longer appeared. At that moment, when one of the statues is in the cell in which the Maria is, the statues are declared winners. At the moment when Maria comes into the cell where Anna has been waiting, Maria is declared the winner. Obviously, nothing depends on the statues, so it all depends on Maria. Determine who will win, if Maria does not make a strategic error. Input You are given the 8 strings whose length equals 8, describing the initial position on the board. The first line represents the top row of the board, the next one β€” for the second from the top, and so on, the last line represents the bottom row. Each character string matches a single cell board in the appropriate row, and the characters are in the same manner as that of the corresponding cell. If the cell is empty, the corresponding character is ".". If a cell has Maria, then it is represented by character "M". If a cell has Anna, it is represented by the character "A". If a cell has a statue, then the cell is represented by character "S". It is guaranteed that the last character of the first row is always "A", the first character of the last line is always "M". The remaining characters are "." or "S". Output If Maria wins, print string "WIN". If the statues win, print string "LOSE". Examples Input .......A ........ ........ ........ ........ ........ ........ M....... Output WIN Input .......A ........ ........ ........ ........ ........ SS...... M....... Output LOSE Input .......A ........ ........ ........ ........ .S...... S....... MS...... Output LOSE
instruction
0
102,142
15
204,284
Tags: dfs and similar Correct Solution: ``` grid=None gridsovertime=None visited=None def readInput(): global grid grid = [] for _ in range(8): grid.append(input()) grid = [[(False if char=='S' else True) for char in row] for row in grid] return grid def getNeighbours(pos): x,y,t = pos newposes = [] for i in range(-1,2): for j in range(-1,2): newposes.append((x+i,y+j,t+1)) # print(newposes, len(gridsovertime), len(gridsovertime[0]), len(gridsovertime[0][0])) newposes = [(x,y,t) for x,y,t in newposes if (x>=0 and y>=0 and x<8 and y<8 and gridsovertime[t][x][y] and gridsovertime[t-1][x][y])] return newposes def dfs(pos): x,y,t = pos visited[t][x][y]=True if t==10: return True out = [] for x,y,t in getNeighbours(pos): # print(x,y,t) if visited[t][x][y]: continue out.append(dfs((x,y,t))) return any(out) def solve(): global gridsovertime,visited gridsovertime = [grid] for _ in range(12): currgrid = gridsovertime[-1] newgrid = [[True]*8] + currgrid[:-1] gridsovertime.append(newgrid) visited = [[[False for _ in range(8)] for _ in range(8)] for _ in range(13)] start = (7,0,0) # visited[7][0][0] = True return dfs(start) def main(): readInput() out = solve() if out: print("WIN") else: print("LOSE") pass if __name__ == '__main__': main() ```
output
1
102,142
15
204,285
Provide tags and a correct Python 3 solution for this coding contest problem. In this task Anna and Maria play a game with a very unpleasant rival. Anna and Maria are in the opposite squares of a chessboard (8 Γ— 8): Anna is in the upper right corner, and Maria is in the lower left one. Apart from them, the board has several statues. Each statue occupies exactly one square. A square that contains a statue cannot have anything or anyone β€” neither any other statues, nor Anna, nor Maria. Anna is present on the board as a figurant (she stands still and never moves), and Maria has been actively involved in the game. Her goal is β€” to come to Anna's square. Maria and statues move in turn, Maria moves first. During one move Maria can go to any adjacent on the side or diagonal cell in which there is no statue, or she can stay in the cell where she is. The statues during their move must go one square down simultaneously, and those statues that were in the bottom row fall from the board and are no longer appeared. At that moment, when one of the statues is in the cell in which the Maria is, the statues are declared winners. At the moment when Maria comes into the cell where Anna has been waiting, Maria is declared the winner. Obviously, nothing depends on the statues, so it all depends on Maria. Determine who will win, if Maria does not make a strategic error. Input You are given the 8 strings whose length equals 8, describing the initial position on the board. The first line represents the top row of the board, the next one β€” for the second from the top, and so on, the last line represents the bottom row. Each character string matches a single cell board in the appropriate row, and the characters are in the same manner as that of the corresponding cell. If the cell is empty, the corresponding character is ".". If a cell has Maria, then it is represented by character "M". If a cell has Anna, it is represented by the character "A". If a cell has a statue, then the cell is represented by character "S". It is guaranteed that the last character of the first row is always "A", the first character of the last line is always "M". The remaining characters are "." or "S". Output If Maria wins, print string "WIN". If the statues win, print string "LOSE". Examples Input .......A ........ ........ ........ ........ ........ ........ M....... Output WIN Input .......A ........ ........ ........ ........ ........ SS...... M....... Output LOSE Input .......A ........ ........ ........ ........ .S...... S....... MS...... Output LOSE
instruction
0
102,143
15
204,286
Tags: dfs and similar Correct Solution: ``` start=[] for i in range(8): start.append(input()) a=[start] #start=[".......A","........","........","........","........",".SSSSSSS","S.......","M......."] #a=[start] for i in range(10): tmp=a[-1] tmp=[".......A"]+tmp tmp[1]=tmp[1][:-1]+"." a.append(tmp[:-1]) dx=[-1,1,0,0,0,1,1,-1,-1] dy=[0,0,-1,1,0,-1,1,-1,1] def chk(x,y,step): if a[step][y][x]=="S": return False if step==9:return True for i in range(8): x_,y_=x+dx[i],y+dy[i] if min(x_,y_)<0 or max(x_,y_)>7:continue if a[step][y_][x_]!='S' and chk(x_,y_,step+1): return True return False if chk(0,7,0): print("WIN") else: print("LOSE") ```
output
1
102,143
15
204,287
Provide tags and a correct Python 3 solution for this coding contest problem. In this task Anna and Maria play a game with a very unpleasant rival. Anna and Maria are in the opposite squares of a chessboard (8 Γ— 8): Anna is in the upper right corner, and Maria is in the lower left one. Apart from them, the board has several statues. Each statue occupies exactly one square. A square that contains a statue cannot have anything or anyone β€” neither any other statues, nor Anna, nor Maria. Anna is present on the board as a figurant (she stands still and never moves), and Maria has been actively involved in the game. Her goal is β€” to come to Anna's square. Maria and statues move in turn, Maria moves first. During one move Maria can go to any adjacent on the side or diagonal cell in which there is no statue, or she can stay in the cell where she is. The statues during their move must go one square down simultaneously, and those statues that were in the bottom row fall from the board and are no longer appeared. At that moment, when one of the statues is in the cell in which the Maria is, the statues are declared winners. At the moment when Maria comes into the cell where Anna has been waiting, Maria is declared the winner. Obviously, nothing depends on the statues, so it all depends on Maria. Determine who will win, if Maria does not make a strategic error. Input You are given the 8 strings whose length equals 8, describing the initial position on the board. The first line represents the top row of the board, the next one β€” for the second from the top, and so on, the last line represents the bottom row. Each character string matches a single cell board in the appropriate row, and the characters are in the same manner as that of the corresponding cell. If the cell is empty, the corresponding character is ".". If a cell has Maria, then it is represented by character "M". If a cell has Anna, it is represented by the character "A". If a cell has a statue, then the cell is represented by character "S". It is guaranteed that the last character of the first row is always "A", the first character of the last line is always "M". The remaining characters are "." or "S". Output If Maria wins, print string "WIN". If the statues win, print string "LOSE". Examples Input .......A ........ ........ ........ ........ ........ ........ M....... Output WIN Input .......A ........ ........ ........ ........ ........ SS...... M....... Output LOSE Input .......A ........ ........ ........ ........ .S...... S....... MS...... Output LOSE
instruction
0
102,144
15
204,288
Tags: dfs and similar Correct Solution: ``` from sys import stdin from collections import * from copy import deepcopy def valid(i, j): n, m = [8] * 2 return i > -1 and i < n and j > -1 and j < m def str_inp(n): return list(reversed(list((list(stdin.readline()[:-1]) for x in range(n))))) def check(x, y, step): if step + 1 < 8 and all[step + 1][x][y] == 'S' or step < 8 and all[step][x][y] == 'S': # print(all[step][x][y], x, y) return False return True def print_maze(x): for i in range(8): print(*all[x][i], sep='') print(end='\n') def dfs(x, y): stack, visit, step = [[x, y, -1]], defaultdict(int), -1 while (stack): x, y, step = stack.pop() step += 1 if chess[x][y] == 'A': exit(print('WIN')) st = 0 for i in range(9): nx, ny = [x + dx[i], y + dy[i]] if i == 0: if step >= 8: continue else: visit[nx, ny] = 0 if valid(nx, ny) and check(nx, ny, step) and not visit[nx, ny]: stack.append([nx, ny, step]) # print(nx, ny, step, check(nx, ny, step)) # print_maze(min(step, 7)) visit[nx, ny] = 1 else: st += 1 # print(stack, step) if st == 9: step -= 1 visit[x, y] = 0 dx, dy, chess = [0, -1, 0, 1, 0, 1, -1, 1, -1], [0, 0, 1, 0, -1, 1, -1, -1, 1], str_inp(8) all, ini = [chess], [['.' for i in range(8)] for j in range(8)] for k in range(1, 9): tem = deepcopy(ini) for i in range(8): for j in range(8): if chess[i][j] == 'S' and i - k > -1: tem[i - k][j] = 'S' all.append(tem) dfs(0, 0) print('LOSE') ```
output
1
102,144
15
204,289
Provide tags and a correct Python 3 solution for this coding contest problem. In this task Anna and Maria play a game with a very unpleasant rival. Anna and Maria are in the opposite squares of a chessboard (8 Γ— 8): Anna is in the upper right corner, and Maria is in the lower left one. Apart from them, the board has several statues. Each statue occupies exactly one square. A square that contains a statue cannot have anything or anyone β€” neither any other statues, nor Anna, nor Maria. Anna is present on the board as a figurant (she stands still and never moves), and Maria has been actively involved in the game. Her goal is β€” to come to Anna's square. Maria and statues move in turn, Maria moves first. During one move Maria can go to any adjacent on the side or diagonal cell in which there is no statue, or she can stay in the cell where she is. The statues during their move must go one square down simultaneously, and those statues that were in the bottom row fall from the board and are no longer appeared. At that moment, when one of the statues is in the cell in which the Maria is, the statues are declared winners. At the moment when Maria comes into the cell where Anna has been waiting, Maria is declared the winner. Obviously, nothing depends on the statues, so it all depends on Maria. Determine who will win, if Maria does not make a strategic error. Input You are given the 8 strings whose length equals 8, describing the initial position on the board. The first line represents the top row of the board, the next one β€” for the second from the top, and so on, the last line represents the bottom row. Each character string matches a single cell board in the appropriate row, and the characters are in the same manner as that of the corresponding cell. If the cell is empty, the corresponding character is ".". If a cell has Maria, then it is represented by character "M". If a cell has Anna, it is represented by the character "A". If a cell has a statue, then the cell is represented by character "S". It is guaranteed that the last character of the first row is always "A", the first character of the last line is always "M". The remaining characters are "." or "S". Output If Maria wins, print string "WIN". If the statues win, print string "LOSE". Examples Input .......A ........ ........ ........ ........ ........ ........ M....... Output WIN Input .......A ........ ........ ........ ........ ........ SS...... M....... Output LOSE Input .......A ........ ........ ........ ........ .S...... S....... MS...... Output LOSE
instruction
0
102,145
15
204,290
Tags: dfs and similar Correct Solution: ``` r, s = [63], ''.join(input() + 'T' for i in range(8)) + 'T' * 9 for i in range(0, 72, 9): t = set() for x in r: for y in (x, x - 1, x + 1, x - 9, x + 9, x - 10, x - 8, x + 10, x + 8): if s[y] == 'T': continue if (y < i or s[y - i] != 'S') and (y < i + 9 or s[y - i - 9] != 'S'): t.add(y) r = t print('WIN' if r else 'LOSE') # Made By Mostafa_Khaled ```
output
1
102,145
15
204,291