CodeEff/ECCO huggingface dataset:
# Original solution
#!/usr/bin/env python3
import sys, math, itertools, heapq, collections, bisect, fractions
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
sys.setrecursionlimit(10**8)
inf = float('inf')
ans = count = 0

a,b,c=list(map(int,input().split()))
for i in itertools.permutations([a,b,c],3):
    if i[0]==sum(i[1:]) or sum(i[:2])==i[2]:
        print("Yes")
        exit()

print("No")

# Optimized solution
#!/usr/bin/env python3
import sys, math, itertools, heapq, collections, bisect, fractions
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
sys.setrecursionlimit(10**8)
inf = float('inf')
ans = count = 0

a,b,c=list(map(int,input().split()))
# print(0)
for i in itertools.permutations([a,b,c],3):
    if i[0]==sum(i[1:]) or sum(i[:2])==i[2]:
        print("Yes")
        exit()

print("No")
# Original solution
#!/usr/bin/env python3
import sys, math, itertools, heapq, collections
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
sys.setrecursionlimit(10**8)
inf = float('inf')
ans = count = 0



a, b, c = list(map(int, input().split()))
for i in itertools.permutations([a, b, c], 3):
    if i[0] == sum(i[1:]) or sum(i[:2]) == i[2]:
        print("Yes")
        exit()

print("No")


# Optimized solution
#!/usr/bin/env python3
import sys, math, itertools, heapq
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
sys.setrecursionlimit(10**8)
inf = float('inf')
ans = count = 0



a, b, c = list(map(int, input().split()))
for i in itertools.permutations([a, b, c], 3):
    if i[0] == sum(i[1:]) or sum(i[:2]) == i[2]:
        print("Yes")
        exit()

print("No")
# Original solution
#!/usr/bin/env python3
import sys, math, itertools
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
sys.setrecursionlimit(10**8)
inf = float('inf')
ans = count = 0



a, b, c = list(map(int, input().split()))
for i in itertools.permutations([a, b, c], 3):
    if i[0] == sum(i[1:]) or sum(i[:2]) == i[2]:
        print("Yes")
        exit()

print("No")


# Optimized solution
#!/usr/bin/env python3
import sys, itertools 
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
sys.setrecursionlimit(10**8)
inf = float('inf')
ans = count = 0



a, b, c = list(map(int, input().split()))
for i in itertools.permutations([a, b, c], 3):
    if i[0] == sum(i[1:]) or sum(i[:2]) == i[2]:
        print("Yes")
        exit()

print("No")
# Original solution
# import time

# starttime=time.clock()

A,B,C =input().split()
a=int(A)
b=int(B)
c=int(C)
# print(a+c)
 
if a>b:
    temp = a
    a = b
    b = temp
if b>c:
    temp = b
    b = c
    c = temp
if (a+b)==c:
    print("Yes")
#     endtime = time.clock()
#     print(endtime-starttime)
else:
    print("No")
#     endtime = time.clock()
#     print(endtime-starttime)
#      


# Optimized solution
a,b,c = list(map(int,input().split()))
 
if a>b:
    temp = a
    a = b
    b = temp
if b>c:
    temp = b
    b = c
    c = temp
if (a+b)==c:
    print("Yes")

else:
    print("No")
# Original solution
A = [int(i) for i in input().split()]
print(('Yes' if sum(A) == max(A) * 2 else 'No'))

# Optimized solution
a, b, c = list(map(int, input().split()))
if a + b == c or a + c == b or b + c == a:
    print('Yes')
else:
    print('No')
# Original solution
while 1:
 n=int(input())
 if n==0:break
 d={}
 for _ in[0]*n:
  k,v=input().strip().split()
  d[k]=v
 for _ in[0]*int(input()):
  e=input().strip()
  print(d[e]if e in d else e,end='')
 print()


# Optimized solution
while 1:
 n=int(eval(input()))
 if n==0:break
 d={}
 for _ in[0]*n:
  k,v=input().strip().split()
  d[k]=v
 a=''
 for _ in[0]*int(eval(input())):
  e=input().strip()
  a+=d[e]if e in d else e
 print(a)
# Original solution
import sys
s=sys.stdin.readline
for n in iter(s,'0\n'):
 d={}
 for _ in[0]*int(n):
  k,v=s()[:-1].split()
  d[k]=v
 print((''.join(d.get(*[s().strip()]*2)for _ in[0]*int(s()))))


# Optimized solution
import sys
s=sys.stdin.readline
for n in iter(s,'0\n'):
 d={}
 for _ in[0]*int(n):
  k,v=s()[:-1].split()
  d[k]=v
 print((''.join(d.get(*[s()[0]]*2)for _ in[0]*int(s()))))
# Original solution
while True:
    n = int(eval(input()))
    if n == 0:break
    c = {}
    for _ in range(n):
        a,b = input().split()
        c[a] = b
    m = int(eval(input()))
    ans = ''
    for _ in range(m):
        a = input()[0]
        ans+=c[a] if a in c else a
    print(ans)

# Optimized solution
import sys
cin = sys.stdin
while True:
    n = int(cin.readline())
    if n == 0:break
    c = {}
    for _ in range(n):
        a,b = cin.readline().strip().split()
        c[a] = b
    m = int(cin.readline())
    ans = ''
    for _ in range(m):
        a = cin.readline().strip()
        ans+=c[a] if a in c else a
    print(ans)
# Original solution
import sys

while True:
    n = int(sys.stdin.readline().rstrip())
    if n == 0:
        break;
    x = {}
    for i in range(n):
        k,v = sys.stdin.readline().rstrip().split()
        x[k] = v
    n = int(sys.stdin.readline().rstrip())
    y = []
    for i in range(n):
        a = sys.stdin.readline().rstrip()
        if a in list(x.keys()):
            y.append(x[a])
        else:
            y.append(a)
    print((''.join(y)))

# Optimized solution
import sys

while True:
    n = int(sys.stdin.readline().rstrip())
    if n == 0:
        break;
    x = {}
    for i in range(n):
        k,v = sys.stdin.readline().rstrip().split()
        x[k] = v
    n = int(sys.stdin.readline().rstrip())
    y = []
    for i in range(n):
        a = sys.stdin.readline().rstrip()
        if a in x:
            y.append(x[a])
        else:
            y.append(a)
    print((''.join(y)))
# Original solution
while True:
    x = int(eval(input()))
    if x == 0:
        break
    dcl = {}
    for i in range(x):
        inp = list(map(str, input().split()))
        dcl[inp[0]] = inp[1]
    ans = ""
    x = int(eval(input()))
    for i in range(x):
        y = str(input()[0])
        if y in dcl:
            ans += dcl[y]
        else:
            ans += y
    print(ans)

# Optimized solution
while True:
    n = int(eval(input()))
    if n == 0:
        break
    d = {}
    for _ in range(n):
        a, b = input().split()
        d[a] = b
    m = int(eval(input()))
    ans = ""
    for _ in range(m):
        a = input().strip()
        ans += d.get(a, a)
    print(ans)
# Original solution
while True:
    n = int(eval(input()))
    if n == 0:
        break
    d = {}
    for _ in range(n):
        a, b = input().split()
        d[a] = b
    m = int(eval(input()))
    ans = ""
    for _ in range(m):
        a = input().strip()
        try:
            ans += d[a]
        except:
            ans += a
    print(ans)

# Optimized solution
while True:
    n = int(eval(input()))
    if n == 0:
        break
    d = {}
    for _ in range(n):
        a, b = input().split()
        d[a] = b
    m = int(eval(input()))
    ans = ""
    for _ in range(m):
        a = input().strip()
        ans += d[a] if a in d else a
    print(ans)
# Original solution
while True:
    n = int(eval(input()))
    if n == 0:
        break
    d = {}
    for _ in range(n):
        a, b = input().split()
        d[a] = b
    m = int(eval(input()))
    ans = ""
    for _ in range(m):
        a = input().strip()
        if a in d:
            ans += d[a]
        else:
            ans += a
    print(ans)

# Optimized solution
while True:
    n = int(eval(input()))
    if n == 0:
        break
    d = {}
    for _ in range(n):
        a, b = input().split()
        d[a] = b
    m = int(eval(input()))
    ans = []
    for _ in range(m):
        a = input().strip()
        if a in d:
            ans.append(d[a])
        else:
            ans.append(a)
    print(("".join(ans)))
# Original solution
while True:
	dict = {}
	n = eval(input())
	if n == 0:break
	for x in range(n):
		a, b = input().split()
		dict[a.strip()] = b.strip()
	res = ""
	for x in range(eval(input())):
		a = input().strip()
		if a in dict:
			res += dict[a]
		else:
			res += a
	print(res)

# Optimized solution
while True:
	dict = {}
	n = eval(input())
	if n == 0:break
	for x in range(n):
		a, b = input().split()
		dict[a] = b
	res = ""
	for x in range(eval(input())):
		a = input()[0]
		if a in dict:
			res += dict[a]
		else:
			res += a
	print(res)
# Original solution

"""
Writer: SPD_9X2
https://atcoder.jp/contests/diverta2019-2/tasks/diverta2019_2_e
Mの時、 a1<=a2<=a3…aN
を満たす通り数 X[M] が分かれば解ける(全ての順N!は等しいため)

当然、次のMにはa1から順に更新していくことになる(M+?にね)
Dの時
X[M] = (X[M-1] + X[M-2] +　… + X[M-D]) * N
が成立かな
X[0] = 1

N=2
X[0]=1
X[1]=2
X[2]=6

N=3
X[0]=1
X[1]=9

X[M]の更新式
→これが間違ってそう
X[M] = (X[M-1] + X[M-2] +　… + X[M-D]) * (1!+2!+3!+…N!)
→エスパーだけどなんか正しそう

X[H-1]を求めてN!を掛ければそれが答え
→サンプル合った！！
"""
import math
N,H,D = list(map(int,input().split()))
mod = 10**9+7

mul = 0
fac = 1
for i in range(1,N+1):
    fac *= i
    fac %= mod
    mul += fac
    mul %= mod

X = [1]
nsum = 1
for i in range(H-1):

    #print (i,nsum,mul)
    X.append(nsum*mul%mod)

    nsum += X[-1]
    if i >= D-1:
        nsum -= X[i-D+1]
        

#print (X)
print((nsum * math.factorial(N) % mod))


# Optimized solution

"""
Writer: SPD_9X2
https://atcoder.jp/contests/diverta2019-2/tasks/diverta2019_2_e
Mの時、 a1<=a2<=a3…aN
を満たす通り数 X[M] が分かれば解ける(全ての順N!は等しいため)

当然、次のMにはa1から順に更新していくことになる(M+?にね)
Dの時
X[M] = (X[M-1] + X[M-2] +　… + X[M-D]) * N
が成立かな
X[0] = 1

N=2
X[0]=1
X[1]=2
X[2]=6

N=3
X[0]=1
X[1]=9

X[M]の更新式
→これが間違ってそう
X[M] = (X[M-1] + X[M-2] +　… + X[M-D]) * (1!+2!+3!+…N!)
→エスパーだけどなんか正しそう

X[H-1]を求めてN!を掛ければそれが答え
→サンプル合った！！
"""
import math
N,H,D = list(map(int,input().split()))
mod = 10**9+7

mul = 0
fac = 1
for i in range(1,N+1):
    fac *= i
    fac %= mod
    mul += fac
    mul %= mod

X = [1]
nsum = 1
for i in range(H-1):

    #print (i,nsum,mul)
    X.append(nsum*mul%mod)

    nsum += X[-1]
    nsum %= mod
    if i >= D-1:
        nsum -= X[i-D+1]
        

#print (X)
print((nsum * fac % mod))
# Original solution
while 1:
	N,M = list(map(int,input().split()))
	if N == 0: break
	T = [[0]*1261 for i in range(N)]
	for i in range(eval(input())):
		t,n,m,s = list(map(int,input().split()))
		for ti in range(t,1261):
			T[n-1][ti] = s*m
	for i in range(eval(input())):
		ts,te,m = list(map(int,input().split()))
		print(sum(1 if any(T[n][t] == m for n in range(N)) else 0 for t in range(ts,te)))
	

# Optimized solution
while 1:
	N,M = list(map(int,input().split()))
	if N == 0: break
	T = [[0]*1261 for i in range(N)]
	r = eval(input())
	tnms = sorted([list(map(int,input().split())) for i in range(r)], key = lambda x:x[1])
	for i in range(0,r,2):
		t1,n,m,s = tnms[i]
		t2,n,m,s = tnms[i+1]
		T[n-1][t1:t2] = [m for j in range(t1,t2)]
	for i in range(eval(input())):
		ts,te,m = list(map(int,input().split()))
		print(sum(1 if any(T[n][t] == m for n in range(N)) else 0 for t in range(ts,te)))
# Original solution
while 1:
	N,M = list(map(int,input().split()))
	if N == 0: break
	T = [[0]*1261 for i in range(N)]
	r = eval(input())
	tnms = sorted([list(map(int,input().split())) for i in range(r)], key = lambda x:x[1])
	for i in range(0,r,2):
		t1,n,m,s = tnms[i]
		t2,n,m,s = tnms[i+1]
		T[n-1][t1:t2] = [m for j in range(t1,t2)]
	for i in range(eval(input())):
		ts,te,m = list(map(int,input().split()))
		print(sum(1 if any(T[n][t] == m for n in range(N)) else 0 for t in range(ts,te)))
	

# Optimized solution
while 1:
	N,M = list(map(int,input().split()))
	if N == 0: break
	T = [[0]*1261 for i in range(M)]
	r = eval(input())
	tnms = sorted([list(map(int,input().split())) for i in range(r)], key = lambda x:x[1])
	for i in range(0,r,2):
		t1,n,m,s = tnms[i]
		t2,n,m,s = tnms[i+1]
		T[m-1][t1:t2] = [1 for j in range(t1,t2)]
	for i in range(eval(input())):
		ts,te,m = list(map(int,input().split()))
		print(sum(T[m-1][ts:te]))
# Original solution
while 1:
	N,M = list(map(int,input().split()))
	if N == 0: break
	T = [[0]*1261 for i in range(M)]
	r = eval(input())
	tnms = sorted([list(map(int,input().split())) for i in range(r)], key = lambda x:x[1])
	for i in range(0,r,2):
		t1,n,m,s = tnms[i]
		t2,n,m,s = tnms[i+1]
		T[m-1][t1:t2] = [1 for j in range(t1,t2)]
	for m in range(M):
		c = 0
		for i in range(1260):
			if T[m-1][i]:
				c += 1
			T[m-1][i] = c - T[m-1][i+1]
	for i in range(eval(input())):
		ts,te,m = list(map(int,input().split()))
		print(T[m-1][te] - T[m-1][ts])

# Optimized solution
while 1:
	N,M = list(map(int,input().split()))
	if N == 0: break
	T = [[0]*1261 for i in range(M)]
	r = eval(input())
	tnms = sorted([list(map(int,input().split())) for i in range(r)], key = lambda x:x[1])
	for i in range(0,r,2):
		t1,n,m,s = tnms[i]
		t2,n,m,s = tnms[i+1]
		T[m-1][t1:t2] = [1 for j in range(t1,t2)]
	for m in range(M):
		c = 0
		for i in range(540,1260):
			if T[m-1][i]:
				c += 1
			T[m-1][i] = c - T[m-1][i+1]
	for i in range(eval(input())):
		ts,te,m = list(map(int,input().split()))
		print(T[m-1][te] - T[m-1][ts])
# Original solution
l = (1260-540+1)
while True:
	N,M = list(map(int,input().split(" ")))
	if N == 0 and M == 0:
		break
	T = [[0]*l for _ in range(M)]
	r = int(eval(input()))
	for i in range(r):
		t,n,m,s = list(map(int,input().split(" ")))
		if s == 1:
			T[m-1][t-540] += 1
		else:
			T[m-1][t-540] -= 1

	T_range = [[] for _ in range(M)]
	for i in range(M):
		flg = True if T[i][0] >= 1 else False
		lb = 0
		for j in range(l-1):
			T[i][j+1] += T[i][j]
			if flg and T[i][j+1] == 0:
				T_range[i].append((lb+ 540,j+1+540))
				flg = False
			elif (not flg) and T[i][j+1] >= 1:
				flg = True
				lb = (j+1)
		if flg:
			T_range[i].append((lb+540,l+540))

	q = int(eval(input()))
	for i in range(q):
		t1,t2,m = list(map(int,input().split(" ")))
		ans = 0
		for a,b in T_range[m-1]:
			if not (b < t1 or t2 < a):
				ans += (min(t2,b) - max(t1,a))

		print(ans)



# Optimized solution
l = (1260-540)+1
while True:
	N,M = list(map(int,input().split(" ")))
	if N == 0 and M == 0:
		break
	T = [[0]*l for _ in range(M)]
	r = int(eval(input()))
	for i in range(r):
		t,n,m,s = list(map(int,input().split(" ")))
		if s == 1:
			T[m-1][t-540] += 1
		else:
			T[m-1][t-540] -= 1

	q = int(eval(input()))
	used = {}
	for i in range(q):
		t1,t2,m = list(map(int,input().split(" ")))
		if not (m-1) in used:
			T_range = []
			flg = True if T[m-1][0] >= 1 else False
			lb = 0
			for j in range(l-1):
				T[m-1][j+1] += T[m-1][j]
				if flg and T[m-1][j+1] == 0:
					T_range.append((lb+540,j+1+540))
					flg = False
				elif (not flg) and T[m-1][j+1] >= 1:
					flg = True
					lb = (j+1)
			if flg:
				T_range.append((lb+540,1261))
			used[m-1] = T_range

		ans = 0
		for a,b in used[m-1]:
			if not (b < t1 or t2 < a):
				ans += (min(t2,b) - max(t1,a))

		print(ans)
# Original solution
N,T = list(map(int,input().split()))
order = list(map(int,input().split()))
ov = 0
for i in range(N-1):
    if (order[i+1]-order[i])<T:
        ov += T-(order[i+1]-order[i])
print((N*T-ov))

# Optimized solution
N,T = list(map(int,input().split()))
last, time = 0,-T
for temp in map(int,input().split()):
    if temp - last < T:
        time += T - (temp - last)
    last = temp
print((N*T-time))
# Original solution
n, t = list(map(int, input().split()))
a = list(map(int, input().split()))

time = 0
for i in range(n-1):
    if a[i + 1] - a[i] < t:
        time += a[i + 1] - a[i]
    elif a[i + 1] - a[i] >= t:
        time += t
print((time + t))


# Optimized solution
n, t = list(map(int, input().split()))
a = list(map(int, input().split()))

time = 0

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

print((time + t))
# Original solution
def solve():
    [N, T] = [int(x) for x in input().split()]
    ts = [int(x) for x in input().split()]

    import collections
    stack = collections.deque()

    for t in ts:
        if not stack:
            stack.append((t, t+T))
            continue

        last = stack.pop()
        if last[1] >= t:
            stack.append((last[0], t+T))
        else:
            stack.append(last)
            stack.append((t, t+T))

    ans = 0
    for t1, t2 in stack:
        ans += (t2 - t1)

    return ans


def main():
    print((solve()))


if __name__ == '__main__':
    main()

# Optimized solution
def solve():
    [N, T] = [int(x) for x in input().split()]
    ts = [int(x) for x in input().split()]

    return sum([
        min(T, t2-t1) for t2, t1 in zip(ts[1:], ts[:-1])
    ]) + T


def main():
    print((solve()))


if __name__ == '__main__':
    main()
# Original solution
n,t = list(map(int, input().split()))
lst = list(map(int, input().split()))
dif = [None for i in range(n-1)]
for i in range(n-1):
    dif[i] = lst[i+1]-lst[i]

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

print(ans)


# Optimized solution
n,t = list(map(int, input().split()))
lst = list(map(int, input().split()))
dif = [None for i in range(n-1)]

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

print(ans)
# Original solution
n,t = (int(i) for i in input().split())
ni = [int(i) for i in input().split()]

total = 0

for i in range(1,len(ni)) :
  delta = ni[i] - ni[i-1]
  if delta < t :
    total += delta
  else :
    total += t

    
print((total+t))

# Optimized solution
def main():
    N, T = list(map(int, input().split()))
    t = list(map(int, input().split()))
    s, e = 0, 0
    ans = 0
    for i in range(N):
        if t[i] <= e:
            e = t[i] + T
        else:
            ans += e - s
            s = t[i]
            e = t[i] + T
    ans += e - s
    print(ans)


main()
# Original solution

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




# Optimized solution
def main() :
  n,t = (int(i) for i in input().split())
  ni = [int(i) for i in input().split()]

  total = 0

  for i in range(1,len(ni)) :
    delta = ni[i] - ni[i-1]
    if delta < t :
      total += delta
    else :
      total += t

    
  print((total+t))

main()
# Original solution
# -*- coding: utf-8 -*-

# AtCoder Beginner Contest
# Problem C

if __name__ == '__main__':
    n, intervel = list(map(int, input().split()))
    ts = list(map(int, input().split()))
    ts += [ts[-1] + intervel]

    total_t = 0
    previous_t = ts[0]

    for i in range(1, n + 1):
        current_t = ts[i]

        if (previous_t + intervel) > current_t:
            total_t += max(0, current_t - previous_t)
        else:
            total_t += intervel

        previous_t = current_t

    print(total_t)


# Optimized solution
# -*- coding: utf-8 -*-

# AtCoder Beginner Contest
# Problem C

if __name__ == '__main__':
    n, intervel = list(map(int, input().split()))
    ts = list(map(int, input().split()))
    ts += [ts[-1] + intervel]

    total_t = 0
    previous_t = ts[0]

    # See:
    # https://atcoder.jp/img/arc073/editorial.pdf
    for i in range(1, n + 1):
        current_t = ts[i]
        total_t += min(current_t - previous_t, intervel)
        previous_t = current_t

    print(total_t)
# Original solution
n,t = list(map(int,input().split()))
a = [int(i) for i in 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)

# Optimized solution
n,t = list(map(int,input().split()))
time = list(map(int,input().split()))
ans = 0
for i in range(n-1):
    ans += min(time[i+1]-time[i],t)
print((ans+t))
# Original solution
n,t=list(map(int,input().split()))
a=list(map(int,input().split()))
a.append(10**10)
cnt=0
for i in range(n):
  fir=a[i]
  if a[i]+t>a[i+1]:
    las=a[i+1]
  else:
    las=a[i]+t
  cnt+=las-fir
print(cnt)

# Optimized solution
n,t=list(map(int,input().split()))
a=list(map(int,input().split()))
a.append(10**10)
cnt=0
for i in range(n):
  if a[i]+t>a[i+1]:
    cnt+=a[i+1]-a[i]
  else:
    cnt+=t
print(cnt)
# Original solution
N, T = [int(i) for i in input().split()]
t = [int(t) for t in input().split()]

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



# Optimized solution
import sys

n, T, *t = list(map(int, sys.stdin.read().split()))

def main():
    start = 0
    will_stop = T
    running_time = 0
    for i in range(1, n):
        cur = t[i]
        if cur < will_stop:
            running_time += cur - start
        else:
            running_time += T
        start = cur
        will_stop = cur + T
    running_time += T

    return running_time

if __name__ == '__main__':
    ans = main()
    print(ans)
# Original solution
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)


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

    s = set()
    for x in t:
        s |= set(range(x, x+T))
    print((len(s)))


if __name__ == '__main__':
    main()


# Optimized solution
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)


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

    arr = [[]] * len(t)
    for i in range(len(t)):
        arr[i] = [t[i], t[i]+T]

    ans = arr[0][1]
    for i in range(len(t)-1):
        _, t1 = arr[i]
        f2, t2 = arr[i+1]

        if t1 <= f2:
            ans += t2 - f2
        else:
            ans += t2 - t1
    print(ans)


if __name__ == '__main__':
    main()
# Original solution
N,T = list(map(int,input().split()))
A = list(map(int,input().split()))

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

print(ans)


# Optimized solution
# atcoder : python3 (3.4.3)
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
mod = 10**9+7

# main
N,T = list(map(int,input().split()))
A = list(map(int,input().split()))

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

ans += T

print(ans)
# Original solution
n, t = list(map(int, input().split()))
T = list(map(int, input().split()))

counter = 0
timer = 0
T_position = 0
for i in range(T[-1] + t):
#  print(counter, timer, T_position)
  if T[T_position] == i:
    timer = t
    if T_position != len(T) - 1:
      T_position += 1
  if timer > 0:
    counter += 1
  timer -= 1
print(counter)

# Optimized solution
n, t = list(map(int, input().split()))
T = list(map(int, input().split()))

counter = 0
for i in range(len(T) - 1):
  if T[i+1] - T[i] < t:
    counter += T[i+1] - T[i]
  else:
    counter += t
counter += t
print(counter)
# Original solution
n, T = list(map(int, input().split()))
t = tuple(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)

# Optimized solution
n, T = list(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)
# Original solution
n,tt=list(map(int,input().split()))

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

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

# Optimized solution

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

tsum=0
for i in range(1,n):
    tsum=tsum+min(t,ti[i]-ti[i-1])
print((tsum+t))
# Original solution
N,T = list(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
    elif t[i]+T > T:
        x += t[i]-t[i-1]
print(x)


# Optimized solution
N,T = list(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
    else:
        x += t[i]-t[i-1]
print(x)
# Original solution
N, T = list(map(int, input().split()))
TL = [-T] + list(map(int, input().split()))

answer = 0
for i in range(1, N+1):
    answer += T
    answer -= max(0, TL[i-1] + T - TL[i])
print(answer)

# Optimized solution
N, T = list(map(int, input().split()))
TL = list(map(int, input().split()))

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