Codeforces Beta Round 32(Div. 2,Codeforces 格式)
A
侦察行动
Reconnaissance
Codeforces
800
原题
←B →

侦察行动AI (CI翻译)

According to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most $*d*$ centimeters. Captain Bob has $*n*$ soldiers in his detachment. Their heights are $*a*_{1}, *a*_{2}, ..., *a*_{*n*}$ centimeters. Some soldiers are of the same height. Bob wants to know, how many ways exist to form a reconnaissance unit of two soldiers from his detachment.

根据 Berland 军队的规定,一个侦察小队应由恰好两名士兵组成。由于这两名士兵的身高不应相差太多,他们的身高差最多为 $*d*$ 厘米。Bob 上尉的分队中有 $*n*$ 名士兵,他们的身高分别为 $*a*_{1}, *a*_{2}, ..., *a*_{*n*}$ 厘米。有些士兵的身高相同。Bob 想知道,从他的分队中选出两名士兵组成侦察小队,有多少种选法。AI (CI翻译)

Ways $(1, 2)$ and $(2, 1)$ should be regarded as different.

选法 $(1, 2)$ 和 $(2, 1)$ 被视为不同。AI (CI翻译)

Input

输入格式

AI (CI翻译)

The first line contains two integers $*n*$ and $*d*$ ($1 ≤ *n* ≤ 1000, 1 ≤ *d* ≤ 10^{9}$) — amount of soldiers in Bob's detachment and the maximum allowed height difference respectively. The second line contains $*n*$ space-separated integers — heights of all the soldiers in Bob's detachment. These numbers don't exceed $10^{9}$.

第一行包含两个整数 $*n*$ 和 $*d*$ ($1 ≤ *n* ≤ 1000, 1 ≤ *d* ≤ 10^{9}$),分别表示 Bob 分队中的士兵人数和允许的最大身高差。第二行包含 $*n*$ 个用空格分隔的整数,表示 Bob 分队中所有士兵的身高。这些数不超过 $10^{9}$。AI (CI翻译)

Output

输出格式

AI (CI翻译)

Output one number — amount of ways to form a reconnaissance unit of two soldiers, whose height difference doesn't exceed $*d*$.

输出一个数,表示组成一个由两名士兵构成的侦察小队的选法数,要求两人的身高差不超过 $*d*$。AI (CI翻译)

样例

Input #1
5 10
10 20 50 60 65
Output #1
6
InputCopy OutputCopy
Input #2
5 1
55 30 29 31 55
Output #2
6
InputCopy OutputCopy
题目信息
题号
32A
时间限制
2 s
内存限制
256 MB
标签
暴力

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(gpt-6.1-sol),如有出入请以原文为准。