Please reason step by step, and put your final answer within \boxed{}.
A person has $n$ red, $n$ green, and $n$ black matches in a box. Each time, they randomly take one match. When all the black matches are used up, there are $r$ red matches and $g$ green matches left. Find the number of different ways this outcome can occur.
user