Under construction

Still being built. Things may change

Costume Party

Time limit1sMemory limit128 MB

Summary
Count pairs of cows whose lengths sum to at most S.
Level

Easy3 of 10

Topics
Sorting, Two pointers, Array
Solved
No attempts yet

Problem

It's Halloween! Farmer John is taking his cows to a costume party, but unfortunately he only has one costume. The costume fits exactly two cows and has length SS (1≤S≤1,000,0001 \le S \le 1{,}000{,}000). Farmer John has NN cows (2≤N≤20,0002 \le N \le 20{,}000), numbered 11 through NN; cow ii has length LiL_i (1≤Li≤1,000,0001 \le L_i \le 1{,}000{,}000). Two cows fit into the costume together if the sum of their lengths is at most SS. Determine how many pairs of two distinct cows fit into the costume.

Input

  • Line 1: Two space-separated integers NN and SS
  • Lines 2 to N+1N+1: Line i+1i+1 contains a single integer LiL_i

Output

  • A single integer: the number of pairs of two distinct cows whose lengths sum to at most SS. The order of the two cows does not matter.

Hint

In the sample, the costume length is 66 and the cow lengths are 3,5,2,13, 5, 2, 1. The four valid pairs are the cows of length 33 and 22; 33 and 11; 55 and 11; and 22 and 11.

Examples1

  1. Example 1

    Input
    4 6
    3
    5
    2
    1
    
    Expected output
    4