Under construction

Still being built. Things may change

Sum

Interview

Time limit1sMemory limit1024 MB

Summary
Count the pairs of distinct elements in a sorted array of N distinct integers that add up to S.
Level

Easy3 of 10

Topics
Two pointers, Array
Solved
No attempts yet

Problem

Consider an NN-element strictly increasing integer sequence AA and an integer SS.

Write a program to count the number of pairs of elements of AA whose sum is SS.

Input

The first line contains NN and SS, the length of the sequence and the required sum (1≤N≤100 0001 \le N \le 100\,000, 0≤S≤2 000 0000 \le S \le 2\,000\,000). The following NN lines each contain one element AiA_i (0≤Ai≤1 000 0000 \le A_i \le 1\,000\,000). The elements are distinct and sorted in increasing order.

Output

The only line of output contains the number of pairs of two distinct elements of the sequence whose sum is SS.

Examples1

  1. Example 1

    Input
    5 10
    1
    3
    5
    7
    9
    
    Expected output
    2