#K36307. Count Contiguous Subarrays With Given Sum

    ID: 25725 Type: Default 1000ms 256MiB

Count Contiguous Subarrays With Given Sum

Count Contiguous Subarrays With Given Sum

Given an array of integers and a target sum \(X\), your task is to count the number of contiguous subarrays whose elements sum exactly to \(X\). A contiguous subarray is defined as a sequence of consecutive elements of the original array.

Formally, for an array \(A\) of length \(n\), count the number of pairs \((l, r)\) (with \(1 \leq l \leq r \leq n\)) such that:

[ \sum_{i=l}^{r} A[i] = X ]

The array may include both positive and negative integers.

inputFormat

The first line contains two space-separated integers \(n\) and \(X\), where \(n\) denotes the number of elements in the array and \(X\) is the target sum.

The second line contains \(n\) space-separated integers representing the elements of the array.

outputFormat

Output a single integer: the number of contiguous subarrays whose sum is equal to \(X\).

## sample
3 2
1 1 1
2