Skip to main content
Tuesday (24.11.2026) at 20:00: ALGOR Contest: Round #4 (Special Challenge) starts!

~/algor $ cat problems/ikki-korsatkich-qismlar-soni

Segments with sum at most s

Medium 1000 ms 128 MB 62%
Share

A positive integer $n$, an array $a$ of $n$ positive integers and a positive integer $s$ are given. Determine how many segments of consecutive elements (of at least one element) have a sum not exceeding $s$.

All contiguous segments of the array with sum at most s

Input

The first line contains two positive integers: $n$ and $s$. The second line contains $n$ positive integers $a_{i}$ separated by spaces.

Output

One integer — the number of segments.

Note

$1 \le n \le 10^{5}$
$1 \le a_{i} \le 10^{4}$
$1 \le s \le 10^{9}$

Examples

Input #1
3 3
1 2 3
Output #1
4
Input #2
5 10
4 4 4 4 4
Output #2
9

Sign in to submit a solution

Signing up is free and takes a minute.