Problems > Product of the Others

Product of the Others

Difficulty: 1400 3500 ms 128 MB

prefix-sums

For every position print the product of ALL OTHER elements, modulo 109+7. Division is not available (elements may be 0).

Input: the first line has N; the second line has N integers.

Output: N integers: for each i, ∏j≠i aj mod 109+7 (values reduced to [0, mod)).

Constraints:

  • 1 ≤ N ≤ 105
  • -100 ≤ ai ≤ 100

Sample Tests

Input 1
4
1 2 3 4
Output 1
24 12 8 6
Input 2
2
0 5
Output 2
5 0

Read the Editorial

Discussion (opens after you solve — no spoilers before)

No comments yet.

Submit Your Solution

Log in or create a free account to run and submit code.