2
def countCombinations(self, pieces: List[str], positions: List[List[int]]) -> int:3
board = [[set() for _ in range(8)] for _ in range(8)]8
all_time = set(range(1, 8))14
line = [(0, 1), (1, 0), (0, -1), (-1, 0)]15
diag = [(1, 1), (1, -1), (-1, 1), (-1, -1)]17
if not board[r][c] & all_time:18
board[r][c] |= all_time22
if pieces[i] in ("queen", "rook"):23
directions.extend(line)24
if pieces[i] in ("queen", "bishop"):25
directions.extend(diag)26
for dr, dc in directions:29
while 0 <= x < 8 and 0 <= y < 8 and count not in board[x][y]:30
board[x][y].add(count)32
rest = set(range(count, 8))33
if not board[x][y] & rest:43
board[x][y].remove(count)