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):
def main():
    N, T = map(int, input().split())
    time = [int(t) for t in input().split()]
    start = 0
    cur = 0
    ans = 0
    for t in time[1:]:
        if t - cur > T:
            ans += cur + T - start
            start = t
        cur = t
    ans += cur + T - start
    return ans


if __name__ == '__main__':
    print(main())

Solution (Python):
N, T = map(int, input().split())
ts = list(map(int, input().split()))
r = 0
tend = 0
for t in ts:
  if t > tend:
    r += T
  else:
    r += t+T-tend
  tend = t+T
print(r)

Solution (Python):

import bisect
import collections
import itertools

def getint(): return int(input())
def getints(): return list(map(int, input().split()))
def getint2d(rows): return [getints() for _ in range(rows)]
def getgrid(rows): return [input() for _ in range(rows)]
def array1d(n, value): return [value for _ in range(n)]
def array2d(n, m, value): return [array1d(m, value) for _ in range(n)]

n,t=getints()
ts=getints()

segm = [[s,s+t] for s in ts]

update = True
while update:
    update = False
    new_segm = [segm[0]]
    for i in range(1, len(segm)):
        if new_segm[-1][1] >= segm[i][0]:
            new_segm[-1][1] = segm[i][1]
            update = True
        else:
            new_segm.append(segm[i])
    segm = new_segm

res = 0
for s in segm:
    res += s[1] - s[0]

print(res)

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

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

total = 0

for t_pre, t_post in zip(ts[:-1], ts[1:]):
  if t_post - t_pre < T:
    total += t_post - t_pre
  else:
    total += T

total += T

print(total)

Solution (Python):
import bisect
import heapq
import itertools
import math
import operator
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

N, M = list(map(int, sys.stdin.readline().split()))
T = list(map(int, sys.stdin.readline().split()))

T = np.array(T)

a = np.minimum(np.diff(T), M)
print(a.sum() + M)

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

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

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

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

Solution (Python):

import sys
INF = float("inf")


def solve(N: int, T: int, t: "List[int]"):

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

    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    T = int(next(tokens))  
    t = [int(next(tokens)) for _ in range(N)]  
    solve(N, T, t)


if __name__ == '__main__':
    main()

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

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

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

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

ans = 0

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

ans += t
print(ans)

Solution (Python):
n, t = map(int, input().split())
tl = list(map(int, input().split()))
tl.append(10 ** 10)
tt = 0
for i, v in enumerate(tl):
    if i == 0:
        te = v + t
    else:
        tt += min(t, 10 ** 10 if te < v else t - (te - v))
        te = v + t
print(tt)

Solution (Python):
N, T = map(int, input().split())
time = list(map(int, input().split()))
time.append(float('inf'))

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

print(ans)

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[i+1] - t[i], T)

print(ans)

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

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

for i in range(N):
    if i == N-1:
        ans += T
    else:
        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())
times=tuple(map(int, input().split()))

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

print(time())

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

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

ret = 0
cur = 0
for tt in t :
    if tt < cur :
        ret += tt + T - cur
    else :
        ret += T
    cur = tt + T
    
print(ret)

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

kaburi = 0
for i in range(n-1):
    if t[i+1]-t[i]<y:
        kaburi += y-(t[i+1]-t[i])
print(len(t)*y-kaburi)

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

cnt = 0
time = 0

for i in range(n):
    if time <= lst[i]:
        cnt += t
    else:
        cnt += lst[i] + t - time
    time = lst[i] + t

print(cnt)

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

Solution (Python):
temp=input().split()
N=int(temp[0])
T=int(temp[1])

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

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

print(total)

Solution (Python):
n, T = map(int,input().split())
t = list(map(int,input().split()))
sums = T
j = 0
for i in t:
  sums += min(i-j, T)
  j = i
print(sums)

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

ts.append(ts[-1]+T)
total = 0
for i in range(N):
    dt = ts[i+1] - ts[i]
    total += min(dt, T)
print(total)

Solution (Python):
n,t=map(int,input().split())
l=list(map(int,input().split()))
sum=0
time=0
for v in l:
    if v>=time:
        sum+=t
        time=v+t
    elif v<time:
        sum-=time-v
        sum+=t
        time=v+t
print(sum)

Solution (Python):
N, K = map(int, input().split())
ans = 0
switches = list(map(int, input().split()))
switches.append(2*10**9)
for idx in range(N):
  ans += min(K, switches[idx+1] - switches[idx])
print(ans)

Solution (Python):
import sys
input=sys.stdin.readline
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+1]-t_list[i]>T:
        ans+=T
    else:
        ans+=t_list[i+1]-t_list[i]
ans+=T
print(ans)

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

ans = N*T-overlap_time
print(ans)

Solution (Python):
n, t = 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)

Solution (Python):
n, t = 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)

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

ans = 0
pre = 0
for a in A:
    ans += min(a-pre, T)
    pre = a

ans += T
print(ans)

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):
from collections import deque
N,T=map(int,input().split())
Q=deque(list(map(int,input().split())))
time=Q.popleft()
ans=0
for t in range(N-1):
    t=Q.popleft()
    if t>time+T:ans+=T
    else:ans+=t-time
    time=t
ans+=T
print(ans)

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

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


main()

Solution (Python):
import sys


fin = sys.stdin.readline
N, T = [int(elem) for elem in fin().split()]
t_list = [int(elem) for elem in fin().split()]

time_to_expire = 0
total_time = t_list[-1] + T
for t in t_list:
    if time_to_expire < t:
        total_time -= (t - time_to_expire)
    time_to_expire = t + T
print(total_time)

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

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

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

Solution (Python):
N, T = map(int, input().split())
t = [int(i) for i in 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]
ans += T
print(ans)

Solution (Python):
N, T= map(int, input().split(' '))
X = [int(i) for i in input().split()]
num = T
for i in range(1, N):
    num += min(T, X[i] - X[i - 1])
print(num)

Solution (Python):

from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')


def A():
    a, b, c = LS()
    if a[-1] == b[0] and b[-1] == c[0]:
        print("YES")
    else:
        print("NO")
    return


def B():
    a, b, c = LI()
    for i in range(1, b):
        if a * i % b == c:
            print("YES")
            return
    print("NO")
    return


def C():
    _, T = LI()
    t = LI()
    ans = 0
    now = t[0]
    for i in t[1:]:
        if now + T <= i:
            ans += T
        else:
            ans += i - now
        now = i
    print(ans + T)
    return


def D():
    return


if __name__ == '__main__':
    C()

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]+T <= t[i+1]:
        ans += T
    else:
        ans += t[i+1]-t[i]
ans += T
print(ans)

Solution (Python):
n, t = map(int, input().split())
p = [int(i) for i in input().split()]
ans = t
for i in range(1, n):
    ans += min(t, p[i] - p[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):
    ans += min(t[i + 1] - t[i], T)
ans += T
print(ans)

Solution (Python):
import math
import itertools

INF = 10**9+7

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

def solve():
	global n,t,c
	ans = 0
	for i in range(1,n):
		if(c[i]-c[i-1]<t):
			ans += c[i]-c[i-1]
		else:
			ans += t
	ans += t
	return ans

def sgn(n):
	if(n>0): return 1
	if(n<0): return -1
	return 0

print(solve())

Solution (Python):


def main():
    num, t = map(int, input().split())
    data = list(map(int, input().split()))
    ans = 0
    now_time = 0

    for i in range(num):
        ans += min(t, data[i] + t - now_time)
        now_time = data[i] + t
    print(ans)


if __name__ == '__main__':
    main()

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

t.append(t[-1] + T)

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

Solution (Python):
n, T = map(int, raw_input().split())
arr = map(int, raw_input().split())
estimeted = arr[0] + T
start = arr[0]
total = 0
for i in range(1, n):
    if arr[i] > estimeted:
        total += estimeted - start
        start = arr[i]
    estimeted = arr[i] + T

total += estimeted - start
print total

Solution (Python):


def main(N, T, t):
    ttl = T
    tmp = T
    for i in range(1, N):
        if(tmp<t[i]):
            ttl += T
        else:
            ttl += t[i] - t[i-1]
        tmp = t[i] + T
    print(ttl)
          
if __name__ == '__main__':
    N, T = map(int, input().split())
    t = [int(i) for i in input().split()]
    
    main(N, T, t)

Solution (Python):
n,t = list(map(int,input().split()))
ans = 0
tlist = list(map(int,input().split()))
temp = tlist[0]
for tm in tlist[1:]:
    ans += min(tm-temp,t)
    temp = tm
    
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):

    ans += min( T , t[i+1]-t[i] )

print (ans+T)

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

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

time = 0

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

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

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

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

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

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

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

t.append(t[-1] + T)

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

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

Solution (Python):

import sys
sys.setrecursionlimit(300000)


def solve(N: int, T: int, t: "List[int]"):
    ret = T * N
    tmp = 0
    for v in t:
        ret -= max(0, tmp - v)
        tmp = v + T
    print(ret)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    T = int(next(tokens))  
    t = [ int(next(tokens)) for _ in range(N) ]  
    solve(N, T, t)

if __name__ == '__main__':
    main()

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

for i in range(0,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=[int(i) for i in input().split()]

ct=0
ans=0
for p in t:
    if ct<=p:
        ans+=T
        ct=p+T
    else:
        ans=ans-(ct-p)+T
        ct=p+T

print(ans)

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

ans = time

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

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

Solution (Python):
n,t=map(int,input().split())
tl=map(int,input().split())
ans=0
p=-1
for i in tl:
    if i<p:
        ans+=t-(p-i)
    else:
        ans+=t
    p=i+t
print(ans)

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

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

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

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

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

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

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

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

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

if N == 1:
    print(T)
    exit()


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

ans += T
print(ans)

Solution (Python):


import itertools
import collections
import bisect

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

    ans = 0

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


if __name__ == '__main__':
    main()

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

res = 0
tmp = T
for i in t[1:]:
  if tmp < i:
    res += T
  else:
    
    res += i - (tmp - T)
  
  tmp = i + T
print(res+T)

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

X = 0
Time = 0

for i in range(N):

    if Time <= t[i] :
        X += T

    else:
        X += t[i] - t[i-1]

    Time = t[i] + T

print(X)

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

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

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

sum_time = n*t

for i in range(n-1):
    if times[i+1] - times[i] < t:
        sum_time -= (t-(times[i+1]-times[i]))

print(sum_time)

Solution (Python):

n,t = list(map(int,input().split()))
tl = list(map(int,input().split()))
print(sum([min(tl[i]-tl[i-1],t) for i in range(1,n)])+t)

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

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

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

print(ans + T)

Solution (Python):

import sys
def input(): return sys.stdin.readline().rstrip()
def mi(): return map(int, input().split())


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

ans = T * N + T
prev = 0
for t in Ts:
  
  ans -= max(0, T-(t-prev))
  prev = t

print(ans)

Solution (Python):

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

Solution (Python):
import itertools
import math
N , T=  list(map(int,input().split(" ")))
times = list(map(int,input().split(" ")))
ans = 0
for i in range(N-1):
    ans += min (T,times[i+1]-times[i])

ans += T
print(ans)

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

if N == 1:
  print(T)
  exit()

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

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

Solution (Python):
N,T = [int(x) for x in input().split()]
t = [int(x) for x in input().split()]
cnt = 0
for ind,i in enumerate(t[:-1]):
    x = t[ind+1]-i
    if(x>T):
        cnt += T
    else:
        cnt += x
cnt += T
print(cnt)

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

answer = N*T
for i in range(N-1):
    if t[i]+T > t[i+1]:
        answer -= t[i]+T-t[i+1]

print(answer)

Solution (Python):

import sys
input = sys.stdin.readline

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

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def I(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
  n,t=LI()
  l=LI()

  sm=0
  for i in range(n-1):
    a=l[i]
    b=l[i+1]

    if b-a>t:
      sm+=t
    else:
      sm+=b-a

  return sm+t

print(main())

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

intervals = [int(x) for x in input().split()]
intervals.sort()


answer = 0
prev = -10*T

for x in intervals:
  if x >= prev + T:
    
    answer += T
  else:
    answer += x-prev
  prev = x

print(answer)

Solution (Python):
N, T, *t = map(int, open(0).read().split())
d = [t[i + 1] - t[i] for i in range(len(t) - 1)] + [T]   
print(sum(min(v, T) for v in d))

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
    else:
        ans += t[i + 1] - t[i]
print(ans)

Solution (Python):
n, time = map(int, input().split())
 
arr = list(map(int, input().split())) + [float("inf")]
 
left, temp, sum_time = 0, 0, 0
 
for t in arr[1:]:
  if t <= temp + time:
    temp = t
  else:
    sum_time += (temp + time - left)
    left, temp = t, t
 
print(sum_time)

Solution (Python):

""" 考え方
T=5のとき

0 2 6 10 20 25 30

total = 0  

・0~2
2-0 <= Tより、お湯が出てる時間は2

・2~6
6-2 <= Tより、お湯が出てる時間は4

・6~10
10-6 <= Tより、お湯が出てる時間は4

・10~20
20-10 > Tより、お湯が出てる時間はT

...

という風に、全探索すればOK

N = 2* 10**5なのでO(N)でも間に合うでしょ

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

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

    print(total)


if __name__ == "__main__":
    solve()

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

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

Solution (Python):
N,T=map(int,input().split())
time=list(map(int,input().split()))
NOW=0
ANS=0

for t in time:
    if t<NOW:
        ANS+=t+T-NOW
        NOW=t+T
    else:
        ANS+=T
        NOW=t+T
print(ANS)

Solution (Python):


import math



def main():
  N,T = map(int, input().split())
  Tn = list(map(int, input().split()))
  Tn += [Tn[-1]+T]
  ans = 0
  for i in range(1,N+1):
    ans += min(Tn[i]-Tn[i-1],T)
  return ans


if __name__ == "__main__":
  ret = main()
  print(ret)

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

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

Solution (Python):
N,T=[int(i) for i in input().split()]
t=[int(i) for i in 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
else:
    ans+=T
print(ans)

Solution (Python):

import copy
import random
import bisect 
import fractions 
import math

mod = 10**9+7


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


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

ans += T
print(ans)

Solution (Python):
import sys

input = sys.stdin.readline





def main():
    
    N, T = [int(ele) for ele in input().split()]
    t = [int(ele) for ele in input().split()]
    usage = [None] * N
    for idx in range(N-1):
        usage[idx] = min(T, t[idx+1] - t[idx])

    usage[-1] = T
    print(sum(usage))


if __name__ == "__main__":
    main()

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

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

ans = 0

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

ans += T
print(ans)

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

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

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

tsum = 0

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

print(tsum + T)

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

ans = T

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

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):

def read_input():
    n, t_span = map(int, input().split())
    tlist = list(map(int, input().split()))

    return n, t_span, tlist


def submit():
    n, t_span, tlist = read_input()

    times = []
    for t in tlist:
        times.append([t, t + t_span])

    result = times[:1]
    for t in times[1:]:
        
        if result[-1][1] > t[0]:
            result[-1][1] = t[1]

        else:
            result.append(t)

    acc = 0
    for t in result:
        acc += t[1] - t[0]

    print(acc)

if __name__ == '__main__':
    submit()

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])
ans += T
print(ans)

Solution (Python):
def c_sentou(N, T, Times):
    times = Times + [Times[-1] + T]  
    return sum([min(T, times[i + 1] - times[i]) for i in range(N)])

N, T = [int(i) for i in input().split()]
Time = [int(i) for i in input().split()]
print(c_sentou(N, T, Time))

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

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

t = [int(n) for n in input().split()]

shower_time = 0

for i in range(1, n):
    delta = t[i] - t[i-1] 
    if delta <= T:
        shower_time += delta
    else:
        shower_time += T

shower_time += T

print(shower_time)