If you need to compute , multiplying first might overflow your integer type.
Instead, you can reduce both numbers modulo first, multiply the smaller results, then take modulo again. The answer stays the same, but your numbers stay within bounds.
This pattern appears in almost every problem that asks for an answer modulo some large prime. Without it, your code crashes or gives wrong answers.