Sonya decided that having her own hotel business is the best way of earning money because she can profit and rest wherever she wants.

The country where Sonya lives is an endless line. There is a city in each integer coordinate on this line. She has nn hotels, where the ii-th hotel is located in the city with coordinate xixi. Sonya is a smart girl, so she does not open two or more hotels in the same city.

Sonya understands that her business needs to be expanded by opening new hotels, so she decides to build one more. She wants to make the minimum distance from this hotel to all others to be equal to dd. The girl understands that there are many possible locations to construct such a hotel. Thus she wants to know the number of possible coordinates of the cities where she can build a new hotel.

Because Sonya is lounging in a jacuzzi in one of her hotels, she is asking you to find the number of cities where she can build a new hotel so that the minimum distance from the original nn hotels to the new one is equal to dd.

Input

The first line contains two integers nn and dd (1≤n≤1001≤n≤100, 1≤d≤1091≤d≤109) — the number of Sonya's hotels and the needed minimum distance from a new hotel to all others.

The second line contains nn different integers in strictly increasing order x1,x2,…,xnx1,x2,…,xn (−109≤xi≤109−109≤xi≤109) — coordinates of Sonya's hotels.

Output

Print the number of cities where Sonya can build a new hotel so that the minimum distance from this hotel to all others is equal to dd.

Examples

Input

4 3
-3 2 9 16

Output

6

Input

5 2
4 8 11 18 19

Output

5

Note

In the first example, there are 66 possible cities where Sonya can build a hotel. These cities have coordinates −6−6, 55, 66, 1212, 1313, and 1919.

In the second example, there are 55 possible cities where Sonya can build a hotel. These cities have coordinates 22, 66, 1313, 1616, and 2121.

题解:

判断是否有交叉,如果有就不加,没有就加差值,但是差值最大只能是2,超过2的当2算

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream> using namespace std; int main()
{ int n,d;
cin>>n>>d;
int a[105];
for(int t=0;t<n;t++)
{
scanf("%d",&a[t]);
}
sort(a,a+n);
long long int sum=2;
for(int t=0;t<n-1;t++)
{
if(a[t]+d<=a[t+1]-d)
{
if((a[t+1]-a[t]-2*d+1)>2)
sum+=2;
else
sum+=a[t+1]-a[t]-2*d+1;
}
}
cout<<sum<<endl; return 0;
}

最新文章

  1. python求数字位数的方法
  2. 高斯模糊算法的 C++ 实现
  3. hadoop配置错误
  4. 项目经验之:GIS的初步工作窗体的搭建
  5. 升级 Java 编程规范的6个约定
  6. TDD和BDD
  7. 使用最小堆优化Dijkstra算法
  8. Server Error in &#39;/&#39; Application Runtime Error 错误
  9. 算法(第四版)C# 习题题解——2.4
  10. fcn+caffe+voc2012实验记录
  11. LazyMan深入解析和实现
  12. DES加密模式详解
  13. [PHP] 链表数据结构(单链表)
  14. day2编程语言的两大分类
  15. Console.WriteLine的小用法
  16. 下载必要的android sdk
  17. [wifi]wifi模块的测试
  18. Bootstrap变形记
  19. Cardinality Estimation算法学习(二)(Linear Counting算法、最大似然估计(MLE))
  20. swift之xib关联UIView

热门文章

  1. matlab unique()函数
  2. RQNOJ 514 字串距离:dp &amp; 字符串
  3. 转载h5问题总结
  4. .NET中Eval()方法大全
  5. kettle脚本定时任务不执行
  6. PC样式reset参考
  7. javaScript运算符之in运算符
  8. bzoj 3267: KC采花&amp;&amp;3272&amp;&amp;3638&amp;&amp;3502 线段树
  9. java.sql.SQLException: Operation not allowed after ResultSet closed
  10. 洛谷 P4512 [模板] 多项式除法