def valid(board, num, pos):
	"""Check if the a number is valid for the position 'pos'."""
	
	# Check row
	for i in range(len(board[0])):
		if board[pos[0]][i] == num and pos[1] != i:
			return False

	# Check column
	for i in range(len(board)):
		if board[i][pos[1]] == num and pos[0] != i:
			return False

	# Check box
	box_x = pos[1] // 3
	box_y = pos[0] // 3

	for i in range(box_y*3, box_y*3 + 3):
		for j in range(box_x*3, box_x*3 + 3):
			if board[i][j] == num and (i, j) != pos:
				return False

	return True