Nim and ordered-pairs

4

20 votes
Easy
Problem

Given an array a1 , a2 , .... an and a number p . You need to find how many ordered pairs (x,y) (where x and y are the indices of the array ai ) exists which sum to p .

Input:

The first line of the input consists of a single integer n ( 1n100000) . The second line of the input consists of array ai (108ai108). The third line of the input consists of number p(2108p2108).

Output:

Output should be a single integer representing the number of ordered pair (x,y).

Time Limit: 1
Memory Limit: 256
Source Limit:
Editor Image

?