Problem:
 Score : 300 points    Problem Statement In a public bath, there is a shower which emits water for T seconds when the switch is pushed.  If the switch is pushed when the shower is already emitting water, from that moment it will be emitting water for T seconds.
Note that it does not mean that the shower emits water for T additional seconds.  N people will push the switch while passing by the shower.
The i -th person will push the switch t_i seconds after the first person pushes it.  How long will the shower emit water in total?      Constraints  1 ≤ N ≤ 200,000  1 ≤ T ≤ 10^9  0 = t_1 < t_2 < t_3 < , ..., < t_{N-1} < t_N ≤ 10^9  T and each t_i are integers.         Input Input is given from Standard Input in the following format:  N  T  t_1  t_2 ... t_N       Output Assume that the shower will emit water for a total of X seconds. Print X .        Sample Input 1 2 4
0 3      Sample Output 1 7  Three seconds after the first person pushes the water, the switch is pushed again and the shower emits water for four more seconds, for a total of seven seconds.       Sample Input 2 2 4
0 5      Sample Output 2 8  One second after the shower stops emission of water triggered by the first person, the switch is pushed again.       Sample Input 3 4 1000000000
0 1000 1000000 1000000000      Sample Output 3 2000000000       Sample Input 4 1 1
0      Sample Output 4 1       Sample Input 5 9 10
0 3 5 7 100 110 200 300 311      Sample Output 5 67

Solution (Python):
n,t = map(int, input().split())
T = list(map(int, input().split()))
ans = 0
for i in range(1, n):
    if T[i] - T[i-1] <= t:
        ans += T[i] - T[i-1]
    else:
        ans += t
ans += t
print(ans)

Solution (Python):



import sys

N, T = map(int, input().split())

t = list(map(int, input().split()))

ans = 0

for i in range(1, N):
    ans += min(T, t[i] - t[i - 1])

ans += T

print(ans)

Solution (Python):
n, t = map(int, input().split())
tl = list(map(int, input().split()))
ans = 0
tl.append(100000000000)
tmp = 0
for i in range(n):
    if tl[i+1] - tl[i] > t:
        ans += tl[i] - tmp + t
        tmp = tl[i+1]
    else:
        pass
print(ans)

Solution (Python):
N,T,*ts=map(int,open(0).read().split())

ans=T

for i in range(N-1):
  dt = ts[i+1] -ts[i]
  if dt < T :
    ans+=dt
  else:
    ans+=T
print(ans)

Solution (Python):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

n, T = map(int, input().split())
t = list(map(int, input().split()))
ans = 0
for i in range(n - 1):
    ans += min(T, t[i+1] - t[i])
ans += T
print(ans)

Solution (Python):



from math import gcd
from itertools import combinations,permutations,accumulate, product 

from collections import deque,defaultdict,Counter
import decimal
import re
import math
import bisect
import heapq














import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7


INF = float('inf')
from sys import stdin
readline = stdin.readline
def readInts():
  return list(map(int,readline().split()))
def readTuples():
    return tuple(map(int,readline().split()))
def I():
    return int(readline())
n,k = readInts()
ans = 0
A = readInts()
for i in range(1,n):
    ans += min(k, A[i] - A[i-1])
print(ans+k)

Solution (Python):
N, T, *t = map(int, open(0).read().split())

end = 0
ans = 0
for i in range(N):
    if t[i] < end:
        ans -= end - t[i]
    end = t[i] + T
    ans += T
print(ans)

Solution (Python):

n, t = map(int,input().split())
T = list(map(int,input().split()))
ans = 0
for i in range(n-1):
    if T[i+1] - T[i] >= t:
        ans += t
    else:
        ans += T[i+1] - T[i]
print(ans+t)

Solution (Python):
n, t, *a = map(int, open(0).read().split())

ans = a[-1] + t

for i in range(n - 1):
    ans -= max(0, a[i + 1] - a[i] - t)
print(ans)

Solution (Python):
N, T = map(int, input().split())
*t, = map(int, input().split())
ans = 0
last = -10**10
for a in t:
    ans += T - max(last + T - a, 0)
    last = a
print(ans)

Solution (Python):
n,T = map(int, input().split())
t = list(map(int, input().split()))

ans = 0
for i in range(n-1):
    if t[i+1]-t[i] >= T: ans += T
    else: ans += t[i+1]-t[i]
print(ans+T)

Solution (Python):
N, T = map(int, input().split())
t = list(map(int, input().split()))
ans = 0
for i,c in enumerate(t):
  if i == N-1:
    ans += T
  else:
    ans += min(T,t[i+1]-t[i])
print(ans)

Solution (Python):
n, t = map(int, input().split())
tl = list(map(int, input().split()))
ans = 0
for i in range(n-1):
    if tl[i+1] - tl[i] >= t:
        ans += t
    else:
        ans += tl[i+1] - tl[i]

print(ans+t)

Solution (Python):
N, T = map(int, input().split())
X = tuple(map(int, input().split()))
p = X[0]
ans = max(X) + T - p
for x in X:
    if x - p > T:
        ans -= (x - p) - T
    p = x

print(ans)

Solution (Python):
n, T = map(int, input().split())
X = list(map(int, input().split()))

ans = 0
Y = []
for i in range(n-1):
    Y.append(X[i+1]-X[i])

ans = 0
for y in Y:
    ans += min(T, y)
ans += T
print(ans)

Solution (Python):
n,t=map(int,input().split())
x=[int(x) for x in input().split()]
lost=0
for i in range(1,n):
    if x[i]-x[i-1]<t:
        lost+=t-(x[i]-x[i-1])
        
print(t*n-lost)

Solution (Python):

N,T = map(int, input().split())
l = list(map(int, input().split()))
x = T

for i in range(1,N):
    interv = l[i] - l[i-1]
    if interv < T:
        x += interv
    else:
        x += T
print(x)

Solution (Python):
n, t = map(int, input().split())
time = list(map(int, input().split()))

diff = [t1 - t0 for t0, t1 in zip(time, time[1:])]

ans = 0
for dt in diff:
    if dt <= t:
        ans += dt
    else:
        ans += t

print(ans + t)

Solution (Python):
import sys

input = sys.stdin.readline

N, T= map(int, input().split())
t_list = list(map(int, input().split()))

ans = T
for i in range(N-1):
    if t_list[i+1] - t_list[i] > T:
        ans += T
    else:
        ans += T - (T - (t_list[i+1] - t_list[i]))
print(ans)

Solution (Python):
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


INF = float('inf')

n, T = LI()
t = LI()
ans = 0
for i in range(n-1):
    ans += min(T, t[i+1] - t[i])
ans += T
print(ans)

Solution (Python):
import sys
import copy
import math
import itertools
import numpy as np
import re

N,T = [int(c) for c in input().split()]
t = [int(c) for c in input().split()]

ans = T
for i in range(1,N):
    if t[i]-t[i-1] < T:
        ans += t[i]-t[i-1]
    else:
        ans += T

print(ans)

Solution (Python):
N,T = map(int,input().split())
t = list(map(int,input().split()))
ans = T
for i in range(len(t)-1):
  tmp = t[i+1] - t[i]
  ans += min(T,tmp)

    
print(ans)

Solution (Python):
n,t=map(int,input().split())

A=list(map(int,input().split()))
now=A[0]+t 
ans=t
for i in range(1,n):
    ans+=min(t, A[i]+t-now)
    now=A[i]+t 
print(ans)

Solution (Python):
n, t = map(int, input().split())
tt = list(map(int, input().split()))

x = 0
for i in range(n-1):
  if tt[i] + t < tt[i+1]:
    x += tt[i+1] - (tt[i] + t)
print(tt[-1] + t - x)

Solution (Python):
def main():
    n, t = map(int, input().split())
    t_list = list(map(int, input().split()))
    ans = 0

    for i in range(n - 1):
        if t_list[i] + t < t_list[i + 1]:
            ans += t
        else:
            ans += t_list[i + 1] - t_list[i]

    print(ans + t)


if __name__ == "__main__":
    main()

Solution (Python):
N, T = map(int, input().split())
t = list(map(int, input().split()))

t.append(10**10)
total = 0
for i in range(N):
    if t[i+1] - t[i] <= T:
        total += t[i+1] - t[i]
    else:
        total += T
print(total)

Solution (Python):
n,t=map(int,input().split())
lt=list(map(int,input().split()))

dif=[lt[i+1]-lt[i] for i in range(n-1)]

ans=0
for i in dif:
  if i <= t:
    ans+=i
  else:
    ans+=t
  
print(ans+t)

Solution (Python):
N, T = map(int, input().split())
swc = list(map(int, input().split()))
ans = 0
for i in range(N-1):
    if swc[i+1] - swc[i] < T:
        ans += (swc[i+1] - swc[i])
    else:
        ans += T
print(ans+T)

Solution (Python):
import sys
from sys import exit
from collections import deque
from bisect import bisect_left, bisect_right, insort_left, insort_right 
from heapq import heapify, heappop, heappush
from math import *

sys.setrecursionlimit(10**6)
INF = 10**20
MOD = 10**9+7

def mint():
    return map(int,input().split())
def lint():
    return list(map(int,input().split()))
def judge(x, l=['Yes', 'No']):
    print(l[0] if x else l[1])
def lprint(l, sep='\n'):
    for x in l:
        print(x, end=sep)

N,T = mint()
t = lint()+[INF]
ans = 0
for i in range(N):
    ans += min(t[i+1]-t[i], T)
print(ans)

Solution (Python):
n,T=map(int,input().split())
t=list(map(int,input().split()))
ans=0
for i in range(n-1):
  if t[i+1]-t[i]<T:
    ans+=t[i+1]-t[i]
  else:
    ans+=T
print(ans+T)

Solution (Python):
N,T = map(int,input().split())
ts = list(map(int,input().split()))
c = 0
for i in range(1,N):
    if ts[i] - ts[i-1] < T:
        c += ts[i] - ts[i-1]
    else:
        c += T
print(c+T)

Solution (Python):
n, t = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]

ans = 0
til = 0

for i in range(n):
    if A[i] >= til:
        ans += t
    else:
        ans += A[i] - A[i - 1]
    til = A[i] + t


print(ans)

Solution (Python):
n,t=map(int,input().split())
a=list(map(int,input().split()))
sum=0
for i in range(n-1):
    if a[i+1]-a[i]>t:
        sum+=t
    else:
        sum+=a[i+1]-a[i]
sum+=t
print(sum)

Solution (Python):
n,t=map(int,input().split())
l=list(map(int,input().split()))

a=t
for i in range(1,n):
  b=l[i-1]+t
  if l[i]>b:
    a+=t
  else:
    a+=l[i]-l[i-1]
print(a)

Solution (Python):
import sys

input = sys.stdin.readline

def main():
    N, T = map(int, input().split())
    t = list(map(int, input().split()))
    ans = T
    for i in range(1,N):
        if t[-i] - t[-(i+1)] >= T:
            ans += T
        else:
            ans += t[-i] - t[-(i+1)]
    print(ans)

if __name__ == '__main__':
    main()

Solution (Python):
N, T = map(int, input().split())
t = list(map(int, input().split()))
ans = T
pre = 0
for ti in t[1:]:
  ans += min(T, ti - pre)
  pre = ti

print(ans)

Solution (Python):
N,T=map(int,input().split())
t=list(map(int,input().split()))
t.append(t[N-1]+T)
ans=0

for i in range(N):
    if t[i+1]-t[i]<=T:
        ans+=t[i+1]-t[i]
    else:
        ans+=T

print(ans)

Solution (Python):
N, T = map(int, input().split())
t = list(map(int, input().split()))

ans = 0
for n in range(N-1):
    if t[n+1]-t[n] >= T:
        ans += T
    else:
        ans += t[n+1]-t[n]
        
print(ans+T)

Solution (Python):
N, T = map(int, input().split())
t = list(map(int, input().split()))
X = T
for i in range(1, N):
  if t[i]-t[i-1]<=T: X += (t[i]-t[i-1])
  else: X += T
print(X)

Solution (Python):

N, T = map(int,input().split())
t = list(map(int,input().split()))

time = 0
for i in range(1,N):
    diff = t[i] - t[i-1]
    if diff < T:
        time += diff
    else:
        time += T
print(time+T)

Solution (Python):
N,T = map(int,input().split())
t = list(map(int,input().split()))


ans = T

for i in range(N-1):
    
    if t[i+1]-t[i]<T:
        ans += t[i+1]-t[i]
    else:
        ans += T
    
print(ans)

Solution (Python):
n,t=map(int,input().split())
li = list(map(int,input().split()))
ans=0
for i in range(n-1):
    if li[i+1]-li[i]<=t:
        ans+=li[i+1]-li[i]
    else:
        ans+=t
ans+=t
print(ans)

Solution (Python):
import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def main():
    n,t = LI()
    switch = LI()
    ans = t

    for i in range(1,n):
        span = switch[i] - switch[i-1]
        if span < t:
            ans += -(t-span) + t
        else:
            ans += t
    
    print(ans)

main()

Solution (Python):
n,t=map(int,input().split())
T=list(map(int,input().split()))
cur=0
sho=0
for i in range(n-1):
    cur=T[i]
    if cur+t<T[i+1]:
        sho+=t
        cur=T[i+1]
    else:
        sho+=T[i+1]-cur
        cur=T[i+1]
print(sho+t)

Solution (Python):
N,T=map(int,input().split())
*S,=map(int,input().split())

ans=0
for i in range(1,len(S)):
    ans+=min(S[i]-S[i-1], T)
ans+=T
print(ans)

Solution (Python):
N, T = map(int, input().split())
t = list(map(int, input().split()))
ans = N * T
dt = []
for i in range(1, N):
    dt.append(t[i] - t[i-1])
for d_t in dt:
    if d_t < T:
        los = T - d_t
        ans -= los
print(ans)

Solution (Python):
n, t = map(int, input().split())
l = list(map(int, input().split()))
ans = 0
for i in range(n-1):
    ans += min(l[i+1]-l[i], t)
print(ans+t)

Solution (Python):
N, T = map(int, input().split())
t = list(map(int, input().split()))
ans = N * T 
cur = 0 
for i in range(N):
    if cur > t[i]:
        ans -= cur - t[i]
    cur = t[i] + T
print(ans)

Solution (Python):
N, T = map(int, input().split())
t = list(map(int, input().split()))
ans = 0
for i in range(N-1):
    ans += min(T, t[i+1] - t[i])
print(ans+T)

Solution (Python):
n, time = map(int, input().split())
T = list(map(int, input().split()))

cnt = time
tmp = T[0]
for t in T[1:]:
    if t <= tmp + time:
        cnt += t - tmp
    else:
        cnt += time
    tmp = t

print(cnt)

Solution (Python):
n, T = map(int, input().split())
t = list(map(int, input().split()))
ans = T
for i in range(1, n):
    if t[i] >= t[i-1]+T:
        ans += T
    else:
        ans += T - ((t[i-1]+T)-t[i])

print(ans)

Solution (Python):
N,T = map(int,input().split())
t = list(map(int,input().split()))
ans = 0
for i in range(1,N):
    if(t[i]-t[i-1]<=T):
        ans+=t[i]-t[i-1]
    else:
        ans +=T
print(ans+T)

Solution (Python):
from sys import stdin

n,t = [int(x) for x in stdin.readline().strip().split()]
t_lst = [int(x) for x in stdin.readline().strip().split()]
diff_lst = [min(t, t_lst[i+1]-t_lst[i]) for i in range(len(t_lst)-1)]
print(sum(diff_lst) + t)

Solution (Python):
N, T = map(int, input().split())
TL = list(map(int, input().split()))

ans = T

for i in range(1, N):
    if TL[i] - TL[i - 1] > T:
        ans += T
    else:
        ans += TL[i] - TL[i - 1]

print(ans)

Solution (Python):
n, time = map(int, input().split())
t = list(map(int, input().split()))

ans = 0
for i in range(n - 1):
    ans += min(time, t[i + 1] - t[i])

print(ans+time)

Solution (Python):
import collections
import sys
import math
N,T = map(int, input().split())
A = list(map(int, input().split()))
ans=0
for i in range(N-1):
    if A[i+1]-A[i]<T:
        ans+=A[i+1]-A[i]
    else:
        ans+=T
print(ans+T)

Solution (Python):
N, T = map(int, input().split())
t = list(map(int, input().split()))
sum = T
before = t[0]
for ti in t[1:]:
    temp = ti-before
    if temp < T:
        sum += temp
    else:
        sum += T
    before = ti
print(sum)

Solution (Python):
N,T=map(int,input().split())
t=list(map(int,input().split()))

time=0
for i in range(N-1):
    if t[i+1]-t[i]>=T:
        time+=T
    else:
        time+=t[i+1]-t[i]
    
print(time+T)

Solution (Python):

n,T = map(int,input().split())
t = list(map(int,input().split()))
Sum = T

for i in range(n-1):
    if t[i+1]-t[i]<T:
        Sum += t[i+1]-t[i]
    else:
        Sum += T
        
print(Sum)

Solution (Python):
n, T = list(map(int, input().split()))

t = list(map(int, input().split()))

cnt = n*T
for i in range(1, n):
    diff = t[i]-t[i-1]
    if diff < T:
        cnt -= T-diff

print(cnt)

Solution (Python):
n, t = [int(w) for w in input().split()]
lt = [int(w) for w in input().split()]

s_on = lt[0]
end = s_on+t
ans = t
for _t in lt[1:]:
    if _t <= end:
        ans += _t+t-end
    else:
        ans += t
    end = _t+t

print(ans)

Solution (Python):
n,t = map(int,input().split())
x = list(map(int,input().split()))

ans = 0

for i in range(n-1):
    if x[i+1]-x[i]<t:
        ans += x[i+1]-x[i]
    else:
        ans += t
        
print(ans+t)

Solution (Python):
N,T = map(int,input().split())
t = list(map(int,input().split()))

ans = 0
for i in range(1,N):
    ans += min(T,t[i]-t[i-1])

ans += T
print(ans)

Solution (Python):
n, t = map(int, input().split())
times = [int(x) for x in input().split()]

result = 0
for i in range(n - 1):
  if times[i] + t > times[i + 1]:
    tmp = times[i+1] + t - (times[i] + t)
    result += tmp
  else:
    result += t

print(result + t)

Solution (Python):
N, T = map(int, input().split())
t = list(map(int, input().split()))

print(sum(min(T, t[i+1] - t[i]) for i in range(N-1)) + T)

Solution (Python):
N,T = [int(i) for i in input().split()]
t = [int(i) for i in input().split()]
pt = 0
tt = 0
for i in range(N):
    tt += min(T, t[i] - pt)
    pt = t[i]
print(tt + T)

Solution (Python):
N, T = map(int, input().split())
t = list(map(int, input().split()))
t.append(t[-1]+T)

ans = 0
start = 0
stop = 0
for ti in t:
  if ti >= stop:
    ans += stop - start
    start = ti
  stop = ti+T
print(ans)

Solution (Python):
import itertools
n, t = map(int,input().split())
tl = list(map(int,input().split()))

water = 0
for i in range(1,n):
    diff = tl[i]-tl[i-1]
    if diff <= t:
        water += diff
    else:
        water += t
water += t
print(water)

Solution (Python):
N, T = map(int, input().split())

t = list(map(int, input().split()))
diff = []

for i in range(1, N):
    diff.append(t[i]-t[i-1])
diff.append(T)

ans = 0
for d in diff:
    ans += min(T, d)
print(ans)

Solution (Python):
n,t=map(int,input().split())
a=list(map(int,input().split()))


ans=0

for i in range(n):
    if i==0:
        s=0
        l=a[i]+t
        continue

    if a[i]<=l:
        l=a[i]+t
    else:
        ans+=l-s
        s=a[i]
        l=a[i]+t


ans+=l-s
print(ans)

Solution (Python):
N,T = map(int,input().split())
t = list(map(int,input().split()))
time = t[0]
ans = T
for i in t[1:]:
    if i - time < T:
        ans += i - time
    else :
        ans += T
    time = i
print(ans)

Solution (Python):
N, T = map(int, input().split())
ts = list(map(int, input().split()))

ans = 0
for i in range(N - 1):
    ans += min(T, ts[i + 1] - ts[i])


ans += T

print(ans)

Solution (Python):

n,t,*s=map(int,open(0).read().split())
ans=0
e=0
for i in s:
    if e > i:
        ans += t - e + i
    else:
        ans += t
    e = i + t
print(ans)

Solution (Python):
N, T = list(map(int,input().split()))
t = list(map(int,input().split()))
s = T
for i in range(1,N):
    s += t[i]+T - max(t[i],t[i-1]+T)
print(s)

Solution (Python):
N,T=map(int,input().split())
X=list(map(int,input().split()))+[float("inf")]

A=0
B=0
S=0
for t in X:
    if B<t:
        S+=B-A
        A=t
    B=t+T

print(S)

Solution (Python):
n,t = map(int,input().split())
a = list(map(int,input().split()))
ans = t
l = a[0]
for i in range(1,n):
  ans += min(t,a[i]-l)
  l = a[i]
print(ans)

Solution (Python):
import sys
import heapq
import math
import fractions
import bisect
import itertools
from collections import Counter
from collections import deque
from operator import itemgetter
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

n,T=mp()
t=lmp()
ans=0
for i in range(1,n):
    if T<t[i]-t[i-1]:
        ans+=T
    else:
        ans+=t[i]-t[i-1]
print(ans+T)

Solution (Python):
N,T = map(int,input().split())
A = list(map(int,input().split()))
cnt = 0
cur = 0
for i in range(1,N):
    if A[i]-A[i-1]>T:
        cnt += A[i-1]-cur+T
        cur = A[i]
cnt += A[N-1]+T-cur
print(cnt)

Solution (Python):
N, T = map(int, input().split())
t = list(map(int, input().split()))

ans = 0
end = -1
start = -1
for x in t:
    if end < x:
        ans += (end - start)
        start = x
        end = x + T
    else:
        end = x + T

ans += (end - start)

print(ans)

Solution (Python):
N,T = map(int,input().split())
L = list(map(int,input().split())) 

ans = 0
end = 0
for i in range(N):
  ans += min(L[i]+T-end,T)
  end = L[i] + T
print(ans)

Solution (Python):
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N, T = mapint()
Ts = list(mapint())

ans = 0
last = 0
for t in Ts:
    ans += min(t-last, T)
    last = t

print(ans+T)

Solution (Python):
def resolve():
  N, T = map(int, input().split())
  t = list(map(int, input().split()))
  ans = 0
  till = 0
  for now in t:
    if till > now:
      ans -= till - now
    till = now + T
    ans += T
  print(ans)
  return

if __name__ == "__main__":
  resolve()

Solution (Python):
n, a = map(int, input().split())
t = list(map(int, input().split()))
ans = a
for i in range(1, n):
    ans += min(a, t[i] - t[i - 1])
print(ans)

Solution (Python):
n,t = map(int, input().split())
T = list(map(int, input().split()))

ans = 0
for i in range(n-1):
    if T[i+1]-T[i]<t: ans += T[i+1]-T[i]
    else: ans += t
print(ans+t)

Solution (Python):
import sys
input=sys.stdin.readline
n,t=list(map(int,input().split()))
a=list(map(int,input().split()))
ans=t
for i in range(1,n):
  if a[i]-a[i-1]<t:
    ans+=a[i]-a[i-1]
  else:
    ans+=t
print(ans)

Solution (Python):
N, T = list(map(int, input().split()))
_T = list(map(int, input().split()))
res = 0
for i in range(N - 1):
    res += min(T, _T[i + 1] - _T[i])
print(res + T)

Solution (Python):
N, T = map(int, input().split())
t_list = list(map(int, input().split()))
ans = 0
pre_ti = 0
for i in range(1, N):
    ti = t_list[i]
    ans += min(T, ti-pre_ti)
    pre_ti = ti
ans += T
print(ans)

Solution (Python):

import sys
from collections import deque, defaultdict
from math import sqrt, factorial





def solve():
    n, h = [int(x) for x in input().split()]
    t = [int(x) for x in input().split()]
    total = 0
    off = 0
    for e in t:
        if e >= off:
            total += h
        else:
            total += h - (off - e)
        off = e + h
            
    print(total)
    

t = 1

for case in range(1,t+1):
    ans = solve()


"""

1 + k



"""

Solution (Python):
n,t = map(int, input().split())
l = list(map(int, input().split()))

ans = t
for i in range(1,n):
  dif = 0 if l[i]-l[i-1] >= t else t-(l[i]-l[i-1])
  ans += (t-dif)
print(ans)

Solution (Python):
N, T = map(int, input().split())
t_l = list(map(int, input().split()))

tn = 0
ans = T
for i in range(N):
    t = t_l[i] - tn
    if t <= T:
        ans += t
    else:
        ans += T
    tn = t_l[i]
print(ans)

Solution (Python):
n,d=map(int,input().split())
t=list(map(int,input().split()))
ans=d
for i in range(n-1):
    ans+=min(d,t[i+1]-t[i])
print(ans)

Solution (Python):
n, t = map(int, input().split())
t_list = list(map(int, input().split()))

ans = t

for i in range(1, n):
    ans += min(t, abs(t_list[i] - t_list[i-1]))

print(ans)

Solution (Python):
n,t = map(int,input().split())
x = list(map(int,input().split()))
m = 0

for i in range(1,n):
    if x[i] - t <= x[i - 1]:
        m += x[i] - x[i - 1]
    else:
        m += t
    

print(m + t)

Solution (Python):


import sys
read = sys.stdin.read
readline = sys.stdin.readline

n,t,*a = map(int,read().split())


ans = 0

s = a[0]
for i in a:
    s = max(i,s)
    ans += i+t-s
    s = i+t

print(ans)

Solution (Python):
def main():
    N,T=map(int,input().split())
    t=list(map(int,input().split()))
    s = 0
    c = 0
    for t1 in t:
        c = max(c, t1)
        if c > t1:
            s += t1 - c + T
            c += t1 - c + T
        else:
            s += T
            c += T
    print(s)
    
if __name__ == "__main__":
    main()

Solution (Python):
from collections import defaultdict
from collections import deque
import itertools
import copy

def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()

n,t = readInts()
ts = readInts()
end = ts[0]+t
ans = t

for i in ts:
	ans+=min(t-(end-i),t)
	end = i+t

print(ans)

Solution (Python):





N, T = map(int, input().split(' '))
t = list(map(int, input().split(' ')))

total = 0
for i in range(N):
    if i > 0:
        total += min(T, t[i]-t[i-1])

    
total += T

print(total)

Solution (Python):
import numpy as np
N, T = map(int, input().split())
t = np.array(tuple(map(int, input().split())))
s = t[1:]-t[:-1]-T
S = int(sum(s[s < 0]))
print(N*T+S)

Solution (Python):
n,T = map(int, input().split())
ts = list(map(int, input().split()))

prev = ts[0]
cnt = 0
for t in ts[1:]:
    
    cnt += min(T, t - prev)
    prev = t
print(cnt+T)

Solution (Python):
N,T = map(int,input().split())
t = list(map(int,input().split()))
X = 0
for i in range(N):
  if i==0: 
    end = T 
  
  elif t[i]>end: 
    X+=T
  elif t[i]<=end:
    X+=t[i]-t[i-1]
    
  end = t[i]+T

X+=T 
print(X)

Solution (Python):
N, T = map(int,input().split())
t = list(map(int,input().split()))
t.append(t[-1]+T)


ans = 0
for n in range(N):
  ans = ans + min(t[n+1]-t[n],T)
  
print(ans)

Solution (Python):
n,t = map(int,input().split())
tt = list(map(int,input().split()))
tt = [0]+tt
a = 0
for i in range(n):
  if(tt[i+1]-tt[i]>=t):
    a +=t
  else:
    a += tt[i+1]-tt[i]
print(a+t)

Solution (Python):
N,T = map(int,input().split());
t = [int(x) for x in input().split()];

end = 0;
ans = 0;
for i in range(N) :
    if end > t[i] :
        ans += t[i] + T - end;
    else :
        ans += T;
    end = t[i] + T;
    

print(ans);

Solution (Python):
n,t=map(int,input().split())
a=list(map(int,input().split()))
souwa=0
for i in range(1,n):
    souwa+=min(a[i]-a[i-1],t)
print(souwa+t)

Solution (Python):
import sys
input = lambda: sys.stdin.readline().rstrip()
n, t = map(int, input().split())
query = list(map(int, input().split()))
ans = 0
for i in range(1, n):
    interval = query[i] - query[i - 1]
    ans += min(t, interval)


ans += t
print(ans)

Solution (Python):
n,t=map(int,input().split())
ti=list(map(int,input().split()))
ans=t
p=0
dist=[]
for i in range(n-1):
  dist.append(ti[i+1]-ti[i])
for i in dist:
  ans+=min(i,t)
print(ans)

Solution (Python):
n,t=map(int,input().split())
ts= list(input().split())
ts = [int(i) for i in ts]

ans=0
flag=False
for i in range(0,len(ts)):
  
  if flag:
    if ts[i]-ts[i-1] <= t:
      ans+=ts[i]-ts[i-1]
    else:  
      ans+=t
  else:
    if ts[i]<=t and i!=len(ts)-1:
      ans=ts[i+1]
    else:
      if ts[i]-ts[i-1] <= t:
        ans=ts[i]
        
      else:  
        ans=ts[i-1]+t
        flag=True
  

print(ans+t)

Solution (Python):
import numpy as np
N, T = map(int, input().split())
t = list(map(int, input().split()))
timer = np.zeros(N)

for i in range(1, N):
    if t[i] - t[i-1] >= T:
        timer[i] = t[i] - t[i-1]
    else:
        timer[i] = T

timer = timer - T
timer[0] = 0


print(int(t[-1]+T - sum(timer)))

Solution (Python):
N, T = map(int, input().split())
t = list(map(int, input().split()))

ans = 0
for i in range(N-1):
    ans += min(t[i+1]-t[i], T)
print(ans+T)

Solution (Python):









import os
import sys




def main():
    n, t = map(int, input().split())
    time = list(map(int, input().split()))
    total = 0
    for i in range(0,n-1):
        cur = time[i]
        nex = time[i+1]
        if cur+t+1<=nex:
            total += t
        else:
            total += nex-cur

    print(total+t)


if __name__ == "__main__":
    main()

Solution (Python):
N,T=map(int,input().split())
L=list(map(int,input().split()))
L=L+[10**9+T]
ans=0
for i in range(N):
  ans+=min(T,L[i+1]-L[i])
print(ans)

Solution (Python):

 

 
import sys
from fractions import gcd
import math
from math import ceil,floor
import collections
from collections import Counter
import itertools


 







 
N,T=map(int, input().split())
time = list(map(int, input().split()))

ans = T

for i in range(1,N):
    if time[i]-time[i-1] >= T:
        ans += T
    else:
        ans += T
        ans = ans - (T-(time[i]-time[i-1]))

print(ans)

Solution (Python):
n,T = map(int,input().split())
t = list(map(int,input().split()))
ans = 0
for i in range(n-1):
    if t[i+1] < t[i] + T:
        ans += t[i+1] - t[i]
    else:
        ans += T
print(ans+T)

Solution (Python):
N, T = map(int, input().split())
t = list(map(int, input().split()))

ans = T
for i in range(N - 1):
    ans += min(T, t[i + 1] - t[i])
print(ans)

Solution (Python):
n,tt=map(int,input().split())
t=list(map(int,input().split()))

cnt=tt
for i in range(n-1):
    cnt+=min(tt,t[i+1]-t[i])
print(cnt)

Solution (Python):
n, T = map(int, input().split())
t = list(map(int, input().split()))
cum_sub = [0] + [t[i]-t[i-1] for i in range(1,n)]

ans = 0
for each in cum_sub[1:]:
  ans += min(T, each)
  
ans += T
print(ans)

Solution (Python):
n,t=map(int,input().split())
tl=list(map(int,input().split()))+[10**10]

ans=0
bef=0
for i in range(1,n+1):
  t_ans=t
  e_time=tl[i-1]+t
  if e_time>tl[i]:
    t_ans-=e_time-tl[i]
  ans+=t_ans
print(ans)

Solution (Python):
N,T = map(int,input().split())
t = list(map(int,input().split()))
dff_list = list()

if N == 1:
  print(T)
  exit(0)
  
for i in range(1,N):
  dff = t[i] - t[i -1]
  dff_list.append(dff)
  
ans_list = [T if T <= i else i for i in dff_list]

ans = sum(ans_list) + T
print(ans)

Solution (Python):
n ,T = map(int, input().split())
t = list(map(int, input().split()))
cnt = T
for i in range(n-1):
  if t[i+1] - t[i] > T:
    cnt += T
  else:
    cnt += t[i+1] - t[i]
print(cnt)

Solution (Python):
n,T = map(int,input().split())
t = [int(i) for i in input().split()]
ans = 0
for i in range(1,n) :
    x = t[i]-t[i-1]
    if x > T :
        ans += T
    else :
        ans += x

print(ans+T)

Solution (Python):
import sys

input = sys.stdin.readline


def main():
    N, T = map(int, input().split())
    t = list(map(int, input().split()))

    ans = T * N
    for i in range(N - 1):
        diff = t[i + 1] - t[i]
        if diff < T:
            ans -= T - diff

    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
N,T = list(map(int, input().split()))
t = list(map(int, input().split()))

ans = T
for i in range(1, N):
    ans += T
    if t[i]-t[i-1] < T:
        
        ans -= (t[i-1] + T - t[i])
print(ans)

Solution (Python):
n,T=map(int,input().split())
t=list(map(int,input().split()))
ans=0
num1=0
num2=0
for i in range(n):
    if num2>t[i]:
        num2=t[i]+T
    else:
        ans+=num2-num1
        num1=t[i]
        num2=t[i]+T
ans+=num2-num1
print(ans)

Solution (Python):
N,T=map(int,input().split())
*t,=map(int,input().split())
ans=0
i=0
while i<N-1:
    ans+=min(T,t[i+1]-t[i])
    i+=1
ans+=T
print(ans)

Solution (Python):
def main():
    N, T = map(int, input().split())
    t = list(map(int, input().split()))

    ans = 0
    for i in range(1, N):
        if t[i]-t[i-1] >= T:
            ans += T
        else:
            ans += (t[i]-t[i-1])
    ans += T

    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
N,T=map(int,input().split())
a=list(input().split())
ts=[]
for _ in range (len(a)):
    ts.append(int(a[_]))

YU=T

for i in range(1,N):
    if ts[i]-ts[i-1]<T:
        YU+=T-(T-(ts[i]-ts[i-1]))
    else:
        YU+=T
print (YU)

Solution (Python):
import sys

def input():
    return sys.stdin.readline()

def main():
    N, T = map(int, input().split())
    t = list(map(int, input().split()))
    kaishi = 0
    syuuryou = 0
    time = 0
    for i in t:
        if syuuryou < i:
            time += syuuryou - kaishi
            kaishi = i
        syuuryou = i + T
    time += syuuryou - kaishi 
    print(time)
    
if __name__ == "__main__":
    main()

Solution (Python):
N, T=map(int, input().split())
t=list(map(int, input().split()))

ans=0
for i in range(1,N):
  ans+=min(T, t[i]-t[i-1])
print(ans+T)