Getting wrong ans for only 1 test case

I don’t see any problem with my code but still getting error, Please tell me if there is any mistake in the code.

/**
*

  • @author Archit
    /
    import java.util.
    ;
    public class main {
    public static long mod = 1000000007;

    public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    long x = 1;
    long[] a = new long[n];
    for(int i =0;i<n;i++){
    a[i] = sc.nextLong();
    x = (x*(a[i]+1)+mod)%mod;
    }
    x/=2;
    long ans = 1;
    for(int i =0;i<n;i++){
    ans = (ans*((x*a[i]+mod)%mod+1)+mod)%mod;
    }
    System.out.println(ans%mod);
    }
    }

x/=2 this operation cannot be performed once you have performed mod operation on x. For eg if intial x=20 and mod =19 and you want (x/2) mod 19 then, if you will mod x before division operation then answer will change. I hope you know that mod operation poperty dont hold true for divsion operation. So now what you can do is that you can take mod inverse of 2 and then multiply mod inevrse of 2 with x. you should get AC after this.

1 Like

Yeah…got the correct for all test cases.
Thank You