#K5201. Subarray Sum Divisibility

    ID: 29214 Type: Default 1000ms 256MiB

Subarray Sum Divisibility

Subarray Sum Divisibility

You are given an array of n integers and an integer K. Your task is to calculate the Subarray Sum defined as:

\(\sum_{i=1}^{n} a_i \times (n-i+1) \times i\)

In other words, for each element in the array at position i (1-indexed), multiply the element by i and by (n-i+1) then sum all these products.

After computing the sum, output YES if the sum is divisible by K, otherwise output NO.

For example, for the array [1, 2, 3] and K = 3, the computation is as follows:

  • Term 1: 1 \(\times 3 \times 1 = 3\)
  • Term 2: 2 \(\times 2 \times 2 = 8\)
  • Term 3: 3 \(\times 1 \times 3 = 9\)

Total = 3 + 8 + 9 = 20, and since 20 is not divisible by 3, the correct answer is NO.

inputFormat

The first line of input contains two space-separated integers: n (the number of elements in the array) and K (the divisor). The second line contains n space-separated integers representing the array elements.

outputFormat

Output a single line with YES if the computed Subarray Sum is divisible by K, otherwise output NO.

## sample
3 3
1 2 3
NO