1 #include<cstdio>
2 #include<cstdlib>
3 #include<cmath>
4 #include<cstring>
5 #include<algorithm>
6 #include<iostream>
7 #include<vector>
8 #include<map>
9 #include<set>
10 #include<queue>
11 #include<string>
12 #define inf 1000000000
13 #define maxn 100000
14 #define maxm 500+100
15 #define eps 1e-10
16 #define ll long long
17 #define pa pair<int,int>
18 using namespace std;
19 inline int read()
20 {
21 int x=0,f=1;char ch=getchar();
22 while(ch<‘0‘||ch>‘9‘){if(ch==‘-‘)f=-1;ch=getchar();}
23 while(ch>=‘0‘&&ch<=‘9‘){x=10*x+ch-‘0‘;ch=getchar();}
24 return x*f;
25 }
26 ll f[maxn][20];
27 int a[20],b[20][maxn],n,m;
28 int main()
29 {
30 freopen("input.txt","r",stdin);
31 freopen("output.txt","w",stdout);
32 n=read();m=read();
33 for(int i=1;i<=n;i++)a[i]=read();
34 for(int i=0;i<=((1<<n)-1);i++)
35 {
36 int x,y;
37 for(x=i,y=0;x;x-=x&(-x))y++;
38 b[y][++b[y][0]]=i;
39 }
40 memset(f,0,sizeof(f));
41 for(int i=1;i<=n;i++)f[b[1][i]][i]=1;
42 for(int i=2;i<=n;i++)
43 for(int j=1;j<=b[i][0];j++)
44 {
45 int x=b[i][j];
46 for(int k=1;k<=n;k++)
47 if(x&(1<<(k-1)))
48 for(int l=1;l<=n;l++)
49 if(l!=k&&(x&((1<<l-1)))&&abs(a[k]-a[l])>m)
50 f[x][k]+=f[x^(1<<(k-1))][l];
51 }
52 ll ans=0;
53 for(int i=1;i<=n;i++)ans+=f[(1<<n)-1][i];
54 printf("%lld\n",ans);
55 return 0;
56 }