Contests typically use these values: 10^9 + 7 (prime, fits in 32 bits), 998244353 (prime, good for number theory), and sometimes 10^9 + 9.
When a problem says "return answer mod 10^9 + 7", apply mod after every addition, subtraction, and multiplication. Never let intermediate values grow unbounded.
Store the modulus as a constant at the top of your code: MOD = 10^9 + 7.