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()))
print(sum(min(T, t[i + 1] - t[i]) for i in range(N - 1)) + T)

Solution (Python):
N, T = map(int, input().split())
ans = 0
t_start = 0
t_stop = 0
for t in map(int, input().split()):
    if t >= t_stop:
        ans += t_stop - t_start
        t_start = t
    t_stop = t + T
print(ans + t_stop - t_start)

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

Solution (Python):

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


ans=0

for e in range(1,n):
    if T<=(t[e]-t[e-1]):
        ans+=T

    else:
        ans+=(t[e]-t[e-1])

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

print(ans+T)

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

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

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

print(result)

Solution (Python):
from itertools import tee


def pairwise(iterable):
    a, b = tee(iterable)
    next(b, None)
    return zip(a, b)


N, T = map(int, input().split())
ts = list(map(int, input().split()))
s = 0

for p, n in pairwise(ts + [ts[-1] + T]):
    if n - p >= T:
        s += T
    else:
        s += n - p
print(s)

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

ans = T

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

print(ans)

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

Solution (Python):
import sys
import bisect
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline

def main():
    n,t = map(int,read().split())
    li = list(map(int,read().split()))
    now = -1e18
    ans = 0
    for ti in li:
        if now < 0:
            now = ti
        else:
            ans += min(t,ti-now)
            now = ti
        
    print(ans+t)

if __name__ == '__main__':
    main()

Solution (Python):
import sys
def input():
    return sys.stdin.readline()[:-1]
def main():
    N, T = map(int,input().split())
    t = list(map(int,input().split()))
    prev = 0
    end = 0
    ans = 0
    for e in t:
        if end < e:
            ans += end-prev
            prev = e
            end = e + T
        else:
            end = e + T
    ans += end - prev
    print(ans)
if __name__ == '__main__':
    main()

Solution (Python):
import sys
from math import pi

def solve():
    input = sys.stdin.readline
    N, T = map(int, input().split())
    S = [int(i) for i in input().split()]
    count = 0
    S.append(10 ** 20)
    for i in range(1, N+1):
        if S[i] > S[i-1] + T: count += T
        else: count += S[i] - S[i-1]
    print(count)

    return 0

if __name__ == "__main__":
    solve()

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

Solution (Python):
N, T = map(int, input().split())
Time = list(map(int, input().split()))
end = T
ans = T
for i in range(1, N):
    start = Time[i]
    duplication = max(end - start, 0)
    ans += T - duplication
    end = start + T
print(ans)

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

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

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

Solution (Python):
import sys
input = sys.stdin.readline

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)

Solution (Python):
n, t = map(int, input().split())
T = list(map(int, input().split()))
ans = 0
x_ = 0
for x in T:
    if x-x_ >= t:
        ans += t
    else:
        ans += x-x_
    x_ = x
ans += t
print(ans)

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

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

ans = T
for x, y in zip(time[:-1], time[1:]):
    ans += min(T, y - x)
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
ans += T
print(ans)

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

Solution (Python):
import sys
n, t, *lst = map(int, sys.stdin.read().split())
cur, res = 0, 0
for i in lst:
  if i <= cur + t:
    res += i - cur
  else:
    res += t
  cur = i
res += t
print(res)

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

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

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

ans = T

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

print(ans)

Solution (Python):
import sys
input = sys.stdin.readline


def read():
    N, T = map(int, input().strip().split())
    U = map(int, input().strip().split())
    return N, T, U


def solve(N, T, U):
    tsum = 0
    t0 = 0
    for t1 in sorted(list(U)):
        if t1 - t0 < T:
            tsum += t1 - t0
        else:
            tsum += T
        t0 = t1
    return tsum + T


if __name__ == '__main__':
    inputs = read()
    outputs = solve(*inputs)
    if outputs is not None:
        print("%s" % str(outputs))

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

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

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

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

print(ans)

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

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

ans=T

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

print(ans)

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

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

Solution (Python):
def main():
    N, T = map(int, input().split())
    *t, = map(int, input().split())
    t += [1 << 31]

    u = iter(t)
    next(u)

    ans = sum(min(T, u_ - t_) for t_, u_ in zip(t, u))
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
N, T = map(int, input().split())
times = list(map(int, input().split()))
ans = 0
t = 0
for time in times:
    if time >= t:
        ans += T
        t = time + T
    else:
        diff = t - time
        ans += T - diff
        t = time + T
print(ans)

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


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

res = T


for i in np.diff(np.array(t)):
    res += min(T,i)

print(res)

Solution (Python):
N,T = map(int, input().split())
prev = 0
ans = 0
tt = list(map(int, input().split()))
for t in tt:
  if prev+T <= t:
    ans += T
  else:
    ans += (t - prev)
  prev = t

print(ans + T)

Solution (Python):
import numpy as np

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

diff = np.diff(t)

ans = T
for i in diff:
    ans += min(i, T)

print(ans)

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

Solution (Python):
import math
import string
import collections
from collections import Counter


def readints():
    return list(map(int, input().split()))


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor



dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]
n, t = map(int, input().split())
tt = readints()
cnt = t

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

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

Solution (Python):
import sys
input = sys.stdin.readline


def readstr():
    return input().strip()


def readint():
    return int(input())


def readnums():
    return map(int, input().split())


def readstrs():
    return input().split()


def main():
    N, T = readnums()
    t = list(readnums())

    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)


if __name__ == "__main__":
    main()

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

last = -1
ans = 0
for t in T:
    if t <= last:
        ans += Y - (last - t)
    else:
        ans += Y
    last = t + Y

print(ans)

Solution (Python):
import sys
input=sys.stdin.readline

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

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

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

ans = 0

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

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

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

print(ans)

Solution (Python):
import sys
input=sys.stdin.readline

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

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

if __name__ == '__main__':
    main()

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n, t = map(int, input().split())
    T = list(map(int, input().split()))

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

    print(res + t)


if __name__ == '__main__':
    resolve()

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

Solution (Python):






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





ans = 0
mylist = [t[i+1] - t[i] for i in range(len(t)-1)]
for x in mylist:
    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 = 0
    for i in range(N-1):
        diff = t[i+1] - t[i]
        ans += (diff<T)*(diff) + (diff>=T)*T
    ans += T
    print(ans)

if __name__ == "__main__":
    main()

Solution (Python):

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

cnt = t

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

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

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

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

for a in A:
  LST.append((a,1))
  LST.append((a+T,-1))
  
LST.sort()

prev = -1
s = 0
ans = 0
for x,y in LST:
  if y == 1:
    s += 1
    if s == 1:
      prev = x
  elif y == -1:
    s -= 1
    if s == 0:
      ans += (x - prev)
  
print(ans)

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

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

sum_second = 0
for i in range(N):
    if (i == N - 1):
        sum_second += T
        break

    if (t[i + 1] - t[i] <= T):
        sum_second += t[i + 1] - t[i]
    else:
        sum_second += T

    
    
    
    


print(sum_second)

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

X = T

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

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

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

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

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

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

print(sum)

Solution (Python):

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

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

pt = t[0]
ans = 0
for ti in t[1:]:
    ans += min(ti-pt, T)
    pt = ti
print(ans+T)

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

if __name__ == '__main__':
    main()

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

Solution (Python):
def main():
    IN1 = [int(_) for _ in input().split()]
    N = IN1[0]
    T = IN1[1]
    times = [int(_) for _ in input().split()]

    result = 0
    before = 0
    base = 0 
    for i in range(1, len(times)):
        time = times[i]
        if time - before > T:
            result = result + before + T - base
            base = time
        before = time
    result = result + times[len(times)-1] + T - base
    print(result)

if __name__ == "__main__":
    main()

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

Solution (Python):
import sys
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    N, T = map(int, readline().split())
    t = list(map(int, readline().split()))
    ans = T
    for i in range(N-1):
        ans += min(T, t[i+1]- t[i])
    print(ans)
if __name__ == '__main__':
    main()

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

interval=[]
for i in range(N-1):
    if Time[i+1]-Time[i]>T:
        interval.append(Time[i+1]-Time[i])

k=len(interval)
print(Time[-1]+T-(sum(interval)-k*T))

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

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

print(ans)

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

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

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

print(ans_t)

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

ans = 0
s = 0
e = T
for n in t[1:]:
    if e < n:
        ans += e - s
        s = n
    e = n + T
ans += e - s
print(ans)

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

p = 0
ans = 0
for time in times:
    start = min(p, time)
    ans += t - max(0, p - time)
    p = time + t
print(ans)

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

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

print(ans+t)

Solution (Python):
n, T = [int(i) for i in input().split()]
t = [int(i) for i in input().split()]
start = 0
stop = 0
ans = 0
for i in range(len(t)):
    start = max(stop, t[i])
    stop = t[i] + T
    ans += stop - start
print(ans)

Solution (Python):


import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n, T = LI()
t = LI()
ans = 0
time = 0
for i in t:
    if time < i:
        time = i + T
        ans += T
    else:
        ans += i - time + T
        time = i + T
print(ans)

Solution (Python):
def main():
    from itertools import tee, zip_longest

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

    iter_t = iter(t)
    next(iter_t)

    ans = sum(min(T, t1 - t0) for t0, t1 in zip_longest(t, iter_t, fillvalue=1 << 31))

    print(ans)


if __name__ == '__main__':
    main()

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

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

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())
l = list(map(int, input().split()))
x = 0
for i in range(n-1):
    if l[i+1]-l[i] < t:
        x += l[i+1]-l[i]
    else:
        x += t
x += t
print(x)

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

ans = 0

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

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

Solution (Python):


import sys
input= lambda: sys.stdin.readline().rstrip()
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))

def resolve():
    N,T=pin()
    t=tupin()

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

resolve()

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

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

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

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

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

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

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

for num, s in enumerate(ts):
    try:
        if ts[num] + t <= ts[num+1]:
            ans += t
        else:
            ans += ts[num+1] - ts[num]
    except:
        pass
ans += t
print(ans)

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

    print(N*T - dup)




if __name__ == '__main__':
    solve()

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

for i in t:
    if time <= i:
        ans += T
        time = i + T
    else:
        ans += T - (time-i)
        time += T -  (time-i)
print(ans)

Solution (Python):
import sys
input = sys.stdin.readline


INF = float("inf")


def main():
    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)

if __name__ == '__main__':
    main()

Solution (Python):
si = lambda: input().strip()
ii = lambda: int(input())
mii = lambda: map(int, input().split())
lmii = lambda: list(map(int, input().split()))
lmsi = lambda: list(map(str, input().split()))
smii = lambda: sorted(map(int, input().split()))



N, T = mii()
t = lmii()

p = []
t.sort()

st = t[0]
ed = t[0] + T
for i in range(1, N):
    n_st = t[i]
    n_ed = n_st + T

    if st <= n_st <= ed:
        ed = n_ed
    else:
        p.append((st, ed))
        st, ed = n_st, n_ed

p.append((st, ed))

ans = 0
for st, ed in p:
    ans += ed - st

print(ans)

Solution (Python):
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_tuple(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


def read_col(H):
    '''
    H is number of rows
    A列、B列が与えられるようなとき
    ex1)A,B=read_col(H)    ex2) A,=read_col(H) 
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return tuple(map(list, zip(*ret)))


def read_matrix(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return ret
    


MOD = 10**9 + 7
INF = 2**31  

from collections import defaultdict, Counter, deque
from operator import itemgetter
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right  


N, T = read_ints()
t = read_ints()

ans = 0

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

Solution (Python):
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from heapq import heapify, heappop, heappush
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, T = MAP()
A = LIST()

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

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

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

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

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

Solution (Python):
def resolve():
    n, time = 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], time)
    print(ans+time)
resolve()

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):
def resolve():
  N, T = map(int, input().split())
  tt = list(map(int, input().split()))
  ans = 0
  last = 0

  for t in tt:
    if t >= last:
      ans += T
      last = t + T
    else:
      ans += t + T - last
      last = t + T

  print(ans)

  return

if __name__ == "__main__":
  resolve()

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

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

print(ans)

Solution (Python):
N,T=map(int,input().split())
t=[int(i) for i in input().split()]+[10**15]
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())
a=list(map(int,input().split()))
ans=t
for i in range(n-1):
  b=a[i+1]-a[i]
  if b>t:
    ans+=t
  else:
    ans+=b
print(ans)

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

ans = 0
t.append(t[-1] + 2 * T)

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

print (ans)

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

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

    print(ans)

if __name__ == '__main__':
    main()

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

Solution (Python):
import numpy as np
N, T = map(int, input().split())
t = np.array(input().split(), dtype=int)

dt = np.diff(t)
dt = np.minimum(dt, T)
print(T + dt.sum())