Count wireless Links

Wireless networking is our future, provided at least some connections exist! More precisely, N nodes of a radio network are distributed in a L × H area. Two nodes may communicate if their euclidean distance is strictly less than R, the radio range. We then say that there exists a wireless link between those two nodes. Of course, we do not consider that a node has a link with itself. Write a program that, given a description of the positions of the nodes, outputs the number of wireless links in the network. Input The input file consists of several test cases, each of them as described below. Thepositions(x,y)ofthenodesareintegersintheranges0≤x<Land0≤y<H. Thefirst line of the input consists in the four integers L, H, R and N, with 0 < L ≤ 5 · 106, 0 < H ≤ 5 · 106, 0 < R ≤ 30000, 0 < N ≤ 300000. Then come N lines with the coordinates x and y of each node. All node positions are different. You can assume that each node has links with at most 31 nodes. Output For each input case, the output consists in a single line containing the number of wireless links in the network. Sample input 10 10 5 3 00 40 05 30 20 11 6 00 0 10 10 0 10 10 20 0 20 10 Sample Output 1 7