Skip to main content
LIVE CONTEST: ALGOR Contest: Round #4 (Special Challenge) is live now!

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

Triples with sum less than x

Medium 1000 ms 128 MB 47%
Share

An array $a$ of $n$ integers and an integer $x$ are given. How many triples $i \lt j \lt k$ satisfy $a_{i} + a_{j} + a_{k} \lt x$?

A sorted array: one element is chosen, in the remaining part two pointers move towards each other

Input

The first line contains two integers: $n$ and $x$.
The second line contains $n$ integers $a_{i}$.

Output

One integer — the number of triples.

Note

$3 \le n \le 1000$
$-10^{9} \le a_{i} \le 10^{9}$
$-3 \cdot 10^{9} \le x \le 3 \cdot 10^{9}$

Examples

Input #1
4 2
-2 0 1 3
Output #1
2
Input #2
3 0
1 1 1
Output #2
0

Sign in to submit a solution

Signing up is free and takes a minute.