Multiple n number

We have to multiple n number if the number is negative then take it modulo 10^9+7
M getting wrong output in
Input
5
-1
-2
-3
-4
-5
Output
999999887
Explanation
Since there are only 5 number, we select all A1A2A3A4A5= -120%(10^9+7)=999999887
This is the code

Please help me to find out

Modified Code

Your Mistakes

  1. 10^9+7 not equal to 1000000007 in c++
    because ^ it is xor operator

  2. to take mod of negative no we have to add the no with modNumber

Getting run time error ( is showing)

for that you have to send complete question
with constraits and all other details as well

package Infosys;
public class Sum 
{
	public static void main(String[] args)
	{
		long MOD =1000000007;
		long answer=-1;
		int a[]= {-2,-3,-4,-5};
		for (int i=0;i<a.length; i++)
		{
			answer*=a[i];
		}
		System.out.println(answer%MOD);//999999887
	}
}

Modular multiplicative inverse - GeeksforGeeks