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


if __name__ == '__main__':
    main()

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

count = 0

for i,time in enumerate(t_list):
    if i == len(t_list)-1 or time + t <= t_list[i+1]:
        count += t
    else:
        count += t_list[i+1]-time

print(count)

Solution (Python):
n,t=map(int,input().split())
org_l=list(map(int,input().split()))
subl=org_l[1:]
l=[y-x for x,y in zip(org_l,subl)]
ans=0
for i in l:
    if i <t:
        ans+=i
    else:
        ans+=t
print(ans+t)

Solution (Python):
n , t = map(int, input().split())
tl=list(map(int,input().split()))
tt=0
ta=0
for i in tl:
    if tt>i:
        ta=ta+t-(tt-i)
        tt=i+t
    else:
        ta+=t
        tt=i+t
print(ta)

Solution (Python):
n, t, *T = map(int, open(0).read().split())
T.append(10**10)
ans = 0
for t0, t1 in zip(T, T[1:]):
  ans += min(t1-t0, t)
print(ans)

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

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

dif = [0] * (n - 1)

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

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

ans += t
print(ans)

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


def calculate(n, t, trr):
    result = 0
    if n == 1:
        return t
    for index, tr in enumerate(trr):
        if index == 0:
            result = result + t
            continue
        if trr[index - 1] + t >= tr:
            result = result + t - ( trr[index - 1] + t - tr )
        else:
            result = result + t
    return result


result = calculate(N, T, trr)
print(result)

Solution (Python):
n,t=map(int,input().split())
pre=-t
a=0
for i in list(map(int,input().split())):
    if pre+t<=i:a+=t
    else:a+=(i-pre)
    pre=i
print(a)

Solution (Python):
def main():
    n, t = map(int, input().split())
    ns = map(int, input().split())
    i = 0
    ans = 0
    for j in ns:
        ans += min(t, j - i)
        i = j
    ans += t
    print(ans)

if __name__=='__main__':
    main()

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

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

x = N*T

for i in range(1,N):
    sa = t[i] - t[i-1]
    if sa < T:
        x -= (T-sa)

print(x)

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

Solution (Python):
def resolve():
    N, T = list(map(int, input().split()))
    timings = list(map(int, input().split()))
    total = T
    for i in range(1, len(timings)):
        if timings[i-1] + T > timings[i]:
            total -= timings[i-1] + T - timings[i]
        total += T
    print(total)

if '__main__' == __name__:
    resolve()

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

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

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

Solution (Python):
x, y = map(int,input().split())
li = list(map(int,input().split()))
ans = y

for i in range(1,x):
    z = li[i] - li[i-1]
    if z < y:
        ans += z
    else:
        ans += y

print(ans)

Solution (Python):
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)

Solution (Python):
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)

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

Solution (Python):
total=0

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

Solution (Python):

n,t=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)

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

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

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

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

o = 0
for i in range(NT[0] - 1):
    
    if t[i+1] - t[i] >= NT[1]:
        o += NT[1]
    else:
        o += t[i+1] - t[i]

print(o + NT[1])

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

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

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

def main():
    N, T = map(int, readline().rstrip().split())
    t = list(map(int, readline().rstrip().split()))
    d = [t[i] - t[i-1] for i in range(1, N)]
    ans = sum([min(T, e) for e in d])
    print(ans + T)


if __name__ == '__main__':
    main()

Solution (Python):
def main():
  N, T = (int(_) for _ in input().split())
  t = [int(_) for _ in input().split()]
  ret = T
  for i in range(N-1):
    if t[i+1] < t[i] + T:
      ret += t[i+1] - t[i]
    else:
      ret += T
  print(ret)
  return

if __name__ == '__main__':
  main()

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

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

Solution (Python):

import io
import string

nim ,mike = map(int, input().split())
array = list(map(int, input().split()))
result = mike
for i in range(nim-1):
    result += min(mike, array[i+1]-array[i])
print(result)

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

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

list_T.sort()
ans = t

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

print(ans)

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

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

print(p+T)

Solution (Python):
from collections import deque
n,x=map(int,input().split())
t=list(map(int,input().split()))
ans=0
t=deque(t)
tmp=t.popleft()
for _ in range(n-1):
    tmp2=t.popleft()
    if tmp2-tmp>x:
        ans+=x
    else:
        ans+=tmp2-tmp
    tmp=tmp2
ans+=x
print(ans)

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

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

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

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

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

Solution (Python):
import sys

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

def main():
    pushed = t[0]
    tot = 0
    for x in t[1:]:
        tot += min(T, x - pushed)
        pushed = x
    tot += T
    print(tot)

if __name__ ==  '__main__':
    main()

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

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

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

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

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

print(ans)

Solution (Python):
def solve(n, t, t_list):
    total = t
    prev = t_list[0]
    for i in t_list[1:]:
        total += min(t, (i - prev))
        prev = i
    return total

if __name__ == "__main__":
    n, t = [int(i) for i in input().split()]
    t_list = [int(i) for i in input().split()]
    print(solve(n, t, t_list))

Solution (Python):
def solve(n, t, t_list):
    total = t
    prev = t_list[0]
    for i in t_list[1:]:
        if i - prev >= t:
            total += t
        else:
            total += i - prev
        prev = i
    return total

if __name__ == "__main__":
    n, t = [int(i) for i in input().split()]
    t_list = [int(i) for i in input().split()]
    print(solve(n, t, t_list))

Solution (Python):










"""def kiri(n,m):
  r_ = n / m
  if (r_ - (n // m)) > 0:
    return (n//m) + 1
  else:
    return (n//m)"""

""" n! mod m 階乗
mod = 1e9 + 7
N = 10000000
fac = [0] * N
def ini():
  fac[0] = 1 % mod
  for i in range(1,N):
    fac[i] = fac[i-1] * i % mod"""

"""mod = 1e9+7
N = 10000000
pw = [0] * N
def ini(c):
  pw[0] = 1 % mod
  for i in range(1,N):
    pw[i] = pw[i-1] * c % mod"""

"""
def YEILD():
  yield 'one'
  yield 'two'
  yield 'three'
generator = YEILD()
print(next(generator))
print(next(generator))
print(next(generator))
"""
"""def gcd_(a,b):
  if b == 0:
    return a
  return gcd_(a,a % b) 
"""def extgcd(a,b,x,y):
  d = a
  if b!=0:
    d = extgcd(b,a%b,y,x)
    y -= (a//b) * x
    print(x,y)
  else:
    x = 1
    y = 0
  return d"""


def readInts():
  return list(map(int,input().split()))
mod = 10**9 + 7
def main():
  n,t = readInts()
  T = readInts()
  X = 0
  
  for i in range(n-1):
    if T[i+1] - T[i] >= t:
      X += t
    else:
      X += T[i+1] - T[i]
  X += t
  print(X)
  
if __name__ == '__main__':
  main()

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

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

Solution (Python):




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

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


if __name__ == "__main__":
    main()

Solution (Python):
from collections import deque

n, T = map(int,input().split())
p = deque(map(int, input().split()))
ans = 0
s = 0
e = 0

while len(p):
    t = p.popleft()
    if e < t:
        ans += e-s
        s = t
        e = t + T
    else:
        e = t + T
ans += e - s
print(ans)

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

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

total = 0

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

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

time = T
ans = 0

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

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

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

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

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

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

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

shower=0
end_time=0
for val in t:
    if end_time<=val:
        shower+=T
    else:
        shower+=val+T-end_time
    end_time = val + T
print(shower)

Solution (Python):
n, t = map(int, input().split())
t_list = list(map(int, input().split()))
total = 0
times = []
for i, x in enumerate(t_list):
	if i < len(t_list) -1:
		next_time = t_list[i+1]
		times.append(next_time - x)
	else:
		times.append(0)
for time in times:
	x = time if time < t else t
	if time == 0:
		x = t
	total += x 
print(total)

Solution (Python):

def resolve():

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




resolve()

Solution (Python):
def resolve():

    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)




resolve()

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

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

print(ans)

Solution (Python):
n,t=map(int,input().split())
time=list(map(int,input().split()))
time.sort(reverse=True)
ans=0
be=0

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

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

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

Solution (Python):

import math
import heapq
import bisect
import numpy as np
from collections import Counter, deque


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

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

max_shower = N * T

doubled = 0
for i in range(N-1):
    difference = T - abs(ts[i]-ts[i+1])
    if difference <= 0:
        doubled += 0
    else :
        doubled += difference
    
print(max_shower-doubled)

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

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

ans = N*T

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

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

interval = [0] * N
for i in range(1, N):
    interval[i] = t[i] - t[i - 1]

ans = 0
for i in range(1, N):
    if interval[i] >= T:
        ans += T
    else:
        ans += interval[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-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())
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):
_,t,s,*l=map(int,open(0).read().split())
a=t
for i in l: a+=min(i-s,t); s=i
print(a)

Solution (Python):
n,t,s,*l=map(int,open(0).read().split())
a=n*t
for i in l: a-=max(s+t-i,0); s=i
print(a)

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]
  else:
    time+=t
print(time+t)

Solution (Python):
def solve():
    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)


if __name__ == '__main__':
    solve()

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

ans = 0
tmp = 0
for i in range(n):
    start, end = t[i], t[i]+T
    if start<tmp:
        ans += end-tmp
    else:
        ans += end-start
    tmp = end

print(ans)

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

res = 0
for i in range(1, n):
    res += min(t, tt[i] - tt[i-1])
else:
    res += t

print(res)

Solution (Python):
N,T,*t=map(int,open(0).read().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()))+[10**18]
x=0
for i in range(N):
  x+=min(t[i+1]-t[i],T)
print(x)

Solution (Python):
import sys
input = sys.stdin.readline
INF = 10**10
MOD = 10**9 + 7
sys.setrecursionlimit(100000000)
from functools import lru_cache
from copy import deepcopy 

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

if __name__=='__main__':
    main()

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

l_ = []
for i in range(len(l)-1):
    l_ += [l[i+1] - l[i]]

l__ = [t - j for j in l_ if j < t]

print(n * t - (sum(l__)))

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

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

ans = t

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

print(ans)

Solution (Python):
n,t = [int(x) for x in input().split()]
T = [int(x) for x in 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):
num, time = map(int,input().split())
list = [int(x) for x in input().split()]
ans = 0



for i in range(1,num):
    if list[i] - list[i-1] < time:
        ans += list[i] - list[i-1]
        
    else:
        ans += time
        
ans += time
print(ans)

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

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

Solution (Python):
n,t = map(int,input().split())
li = [int(x) for x in input().split()]
ans = 0
pre_time = 10**10

for i in range(n):
    if abs(li[i] - pre_time) < t:
        ans += (li[i] - pre_time)
    else:
        ans += t
    pre_time = li[i]

print(ans)

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

pre = ts[0]
ans = 0
for t in ts:
  if t-pre > T:
    ans += T
  else:
    ans += t-pre
  pre = t
ans += T
print(ans)

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

s=0
tmp=0

for i in range(1,n):
    if tmp+T > t[i]:
    
        tmp=t[i]
    
    else:
    
        ans=ans+(tmp+T-s)
        tmp=t[i]
        s=tmp
        
ans=ans+(tmp+T-s)
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])
ans += T
print(ans)

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

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



con = ends[:-1] > t[1:]

v = 0
for i in range(N - 1):
    if con[i]:
        continue
    else:
        v += t[i + 1] - ends[i]
ans = ends[-1] - v
print(ans)

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

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

print(ans)

Solution (Python):
import sys
input = sys.stdin.readline
N, T = map(int, input().split())
ts = [int(x) for x in input().split()]

now = 0
ans = 0
for t in ts :
    if t >= now :
        ans += T
    else :
        ans += T - (now - t)
    now = t + T

print(ans)

Solution (Python):


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

s = [0]+[l[i+1] - l[i] for i in range(len(l)-1)]


m = 0
for i in range(n):
    m += min(t,s[i])
print(m+t)

Solution (Python):


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


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

cnt += T

print(cnt)

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

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

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

print(ans + T)

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

print(ans)

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

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

u = []
for i in range(1,N):
    tmp = t[i-1] + T - t[i]
    if tmp > 0:
        u.append(t[i-1] + T - t[i])
    else:
        u.append(0)
print(T*N - sum(u))

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

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

ans = 0
for i in range(n-1):
    ans += min(ttt[i+1]-ttt[i],T)
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):
    m = T[i] - T[i-1]
    if m < t:
        ans +=  T[i] - T[i-1]
    else:
        ans += 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):
  ans += min(t, a[i+1] - a[i])
print(ans)

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

Solution (Python):
def main():
  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)
if __name__=='__main__':
  main()

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

answer = 0
prev = -10 * T


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

print(answer)

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

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

def main():
    mod=10**9+7
    N,T=MI()
    t=LI()
    t.append(t[-1]+T+5)
    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)

main()

Solution (Python):
N,T=map(int,input().split())
t=input().split()
a=[int(b) for b in t]
time=0
for c in range(N-1):
    if a[c+1]-a[c]>=T:
        time+=T
    else:
        time+=a[c+1]-a[c]
time+=T
print(time)

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 = [int(_) for _ in input().split()]
ans = T * N
if N == 1:
    ans = T
else:
    for i in range(1, N):
        if t[i] - t[i-1] < T:
            ans -= T - (t[i] - t[i-1])
print(ans)

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

Solution (Python):
n, t = map(int, list(input().split(' ')))
ti = list(map(int, list(input().split(' '))))
result = t
for i, item in enumerate(ti):
  temp = t
  if i == len(ti) - 1:
    break
  if ti[i+1] - ti[i] < t:
    temp = ti[i+1] - ti[i]
  result = result + temp

print(result)

Solution (Python):
import sys

input = sys.stdin.readline


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


def read_list():
    return list(read_values())


def func(N, mod):
    F = [1]
    for i in range(1, N + 1):
        F.append(F[-1] * i % mod)
    return F


def inv(a, mod):
    return pow(a, mod - 2, mod)


def C(F, a, b, mod):
    return F[a] * inv(F[b], mod) * inv(F[a - b], mod) % mod


def main():
    N, T = read_values()
    A = read_list()
    res = T
    for i in range(N - 1):
        res += min(A[i + 1] - A[i], T)

    print(res)


if __name__ == "__main__":
    main()

Solution (Python):
n,t=map(int,input().split())
a=[int(i) for i in input().split()]
time=0
for i in range(len(a)-1):
    time+=max(0,(a[i]+t)-a[i+1])
print(n*t-time)

Solution (Python):

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

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