Bizarro World

0

0 votes
Map, Very-Easy
Problem

The measure of a man lies not in what he says but what he does.

Superman needs to solve a problem in order to decipher Bizarro's weird language and save the day. Help him solve the problem.

Given an array A of n integers, how many triplets (a,b,c) exist that satisfy the formula a+b+c=k and a,b,cA.

INPUT

First line of input contains n, the number of elements in the array and k, the value k in the formula

The next line of input contains n integers, a1,a2,...an, representing the array of numbers.

OUTPUT

Print the answer to the problem. It is guaranteed that the answer will fit inside a 64 bit integer.

CONSTRAINTS

3n1000

1ai106

1k106

All the numbers in array A are distinct.

Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

Possible values of a, b, c are

(1,1,3),(1,2,2),(1,3,1),(2,1,2),(2,2,1),(3,1,1)

Editor Image

?