1
#include
<
iostream
>
2
#include
<
cstdio
>
3
#include
<
cstring
>
4
#include
<
algorithm
>
5
#include
<
cassert
>
6
#include
<
set
>
7
using
namespace
std;
8
const
int
N
=
1000111
;
9
const
int
MOD
=
9901
;
10
int
a[N], c[N], b[N
*
3
], idx[N
*
3
];
11
12
int
mod(
int
a,
int
MOD)
13
{
14
return
(a
%
MOD
+
MOD)
%
MOD;
15
}
16
17
int
lowbit(
int
k)
18
{
19
return
k
&
(
-
k);
20
}
21
22
int
sum(
int
pos)
23
{
24
if
(pos
==
0
)
return
0
;
25
int
s
=
0
;
26
for
(
int
i
=
pos; i
>
0
; i
-=
lowbit(i))
27
s
=
(s
+
c[i])
%
MOD;
28
return
s;
29
}
30
31
void
modify(
int
pos,
int
x)
32
{
33
for
(
int
i
=
pos; i
<
N; i
+=
lowbit(i))
34
c[i]
=
(c[i]
+
x)
%
MOD;
35
}
36
37
int
binary_search(
int
low,
int
high,
int
x)
//
等于x的
38
{
39
int
mid, reach
=
-
1
;
40
while
(low
<=
high)
41
{
42
mid
=
(low
+
high)
/
2
;
43
if
(b[mid]
==
x)
44
return
mid;
45
else
if
(b[mid]
>
x)
46
high
=
mid
-
1
;
47
else
48
low
=
mid
+
1
;
49
}
50
return
reach;
51
}
52
53
54
int
main()
55
{
56
int
n, d;
57
while
(scanf(
"
%d %d
"
,
&
n,
&
d)
==
2
)
58
{
59
memset(c,
0
,
sizeof
(c));
60
for
(
int
i
=
0
; i
<
n; i
++
)
61
scanf(
"
%d
"
,
&
a[i]);
62
int
cur
=
0
;
63
for
(
int
i
=
0
;i
<
n;i
++
)
64
{
65
idx[i
*
3
]
=
a[i]
-
d;
66
idx[i
*
3
+
1
]
=
a[i];
67
idx[i
*
3
+
2
]
=
a[i]
+
d;
68
}
69
sort(idx, idx
+
3
*
n);
70
b[cur
++
]
=
idx[
0
];
71
for
(
int
i
=
1
;i
<
3
*
n;i
++
)
72
{
73
if
(idx[i]
!=
idx[i
-
1
])
74
b[cur
++
]
=
idx[i];
75
}
76
int
ans
=
0
;
77
for
(
int
i
=
0
; i
<
n; i
++
)
78
{
79
int
now
=
binary_search(
0
, cur
-
1
, a[i])
+
1
;
80
assert(now
!=
-
1
);
81
int
pre
=
binary_search(
0
, cur
-
1
, a[i]
-
d);
82
assert(pre
!=
-
1
);
83
int
nxt
=
binary_search(
0
, cur
-
1
, a[i]
+
d)
+
1
;
84
assert(nxt
!=
-
1
);
85
int
cur
=
mod(sum(nxt)
-
sum(pre), MOD);
86
modify(now, cur
+
1
);
87
ans
=
(ans
+
cur)
%
MOD;
88
}
89
printf(
"
%d\n
"
, ans);
90
}
91
return
0
;
92
}