Given a 2D matrix with obstacles, find the total number of different ways to get from the start position (x,y) to the goal position (x,y).
Implement count_paths(matrix, start, goal). The matrix contains 0 for an open cell and 1 for an obstacle; movement is restricted to right and down. Return 0 when the start or goal is blocked, the coordinates are invalid for right/down movement, or no path exists.
def count_paths(matrix, start, goal):