Company: Amazon_14nov
Difficulty: medium
Determine Stability Risk Problem Description An infrastructure runs n services, and the i -th service has the identifier service_id[i] . A diagnostic tool scans every contiguous subarray of service_id and flags the ones that look vulnerable: add up the identifiers in the subarray; divide that sum by modulus and take the remainder; the subarray is flagged when the remainder equals the number of services in the subarray. Report the stability risk, that is how many contiguous subarrays are flagged. A subarray is a non-empty run of consecutive elements that keeps the original order. Input Format The first line contains n . The second line contains n space-separated integers, the array service_id . The third line contains modulus . Output Format Print a single integer: the number of flagged subarrays. Constraints 1 <= n <= 2000 (the source paper states 2 * 10^5 ; the bound is reduced here so that every graded case fits the platform's input limit) 1 <= service_id[i] <= 1000000000