Product Modulo 1e9+7 — Solution & Editorial
Reduce every factor modulo M as you multiply. In languages where % can return negatives, normalize with ((x % M) + M) % M.
Complexity: O(N)
Watch out: In C++/Java the remainder of a negative number is negative — normalize before printing.