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

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

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

print(cnt+T)

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

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

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

print(r+T)

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

r = 0

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

print(r)

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

ans = t

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

Solution (Python):
def main():
    people_num, emit_time = map(int, input().split())
    times = list(map(int, input().split()))
    answer = 0
    for i in range(1, people_num):
        if times[i] - times[i - 1] > emit_time:
            answer += emit_time
        else:
            answer += times[i] - times[i - 1]
    answer += emit_time
    print(answer)


if __name__ == '__main__':
    main()

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

Solution (Python):

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

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

ans += now-start

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,k=map(int,input().split())

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

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

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

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

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

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

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

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



read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N, T, *t = map(int, read().split())
ans = 0
for cur, nex in zip(t, t[1:]):
    ans += min(T, nex - cur)
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):
    ans+=min(t[i+1]-t[i],T)
print(ans+T)

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

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

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

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

print(ans)

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

Solution (Python):
n,t = map(int,input().split())
tt=list(map(int,input().split()))
count=0
i=1
while(i<n):
	if tt[i]-tt[i-1]>=t:
		count+=t
	else:
		count+=tt[i]-tt[i-1]
	i+=1
print(count+t)

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

Solution (Python):
n, d = map(int, input().split())
t = list(map(int, input().split()))
p = -1
ans = 0
for ti in t:
  ans += d - max(p - ti, 0)
  p = ti + d
print(ans)

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

ans=0

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

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

ans = 0
tmp = 0
for i in tt:
    ans += min(t, i+t - tmp)
    tmp = i+t
print(ans)

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

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

print(t[-1] + T - stop)

Solution (Python):
def showertime(n , t , tl):
    ans = 0
    for i in range(n):
        ans += t
        if i != 0 and tl[i] - tl[i-1] < t:
            ans -= t - (tl[i] - tl[i-1])

    return ans

def main():
    n , t = map(int , input().split())
    tl = list(map(int , input().split()))
    print(showertime(n , t , tl))

if __name__ == '__main__':
    main()

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

time = times[-1] + t

for i in range(1, n):
    if times[i] - times[i-1] > t:
        time -= times[i] - times[i-1] - t


print(time)

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

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

Solution (Python):
a,b = map(int, input().split())
l = list(map(int, input().split()))
L = []

for i in range(a):
  l2 = [l[i],l[i] + b]
  L.append(l2)
  
L = sorted(L, key = lambda x:x[1])


ri = 0
sum = 0

for x,y in L:

  if ri > x:

    sum += y - ri
  else:
    sum += b
  ri = y


print(sum)

Solution (Python):
a,b = map(int, input().split())
l = list(map(int, input().split()))
L = []

for i in range(a):
  l2 = [l[i],l[i] + b]
  L.append(l2)
  
L = sorted(L, key = lambda x:x[1])


ri = 0
sum = 0

for x,y in L:

  if ri > x:
    sum += y - ri
  else:
    sum += b
  ri = y


print(sum)

Solution (Python):
a,b = map(int, input().split())
l = list(map(int, input().split()))
L = []

for i in range(a):
  l2 = [l[i],l[i] + b]
  L.append(l2)
  
L = sorted(L, key = lambda x:x[1])


ri = 0
sum = 0

for x,y in L:

  if ri > x:
    sum += y - ri
    ri = y
  else:
    sum += b
    ri = y


print(sum)

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

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

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

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

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

_n, _dt = map(int, input().split())
_T = list(map(int, input().split()))
print(solve(_n, _dt, _T))

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

elapsed_t = 0
ans = 0

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

Solution (Python):

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

cnt = 0
prev = None

for i in range(n):
  cnt += t

  
  if prev != None and (T[i] - prev) < t:
    cnt -= t - (T[i] - prev)

  prev = T[i]


print(cnt)

Solution (Python):
N, T = map(int, input().split())
tt = list(map(int, input().split()))
print(sum(min(T, t2 - t1) for t1, t2 in zip(tt, tt[1:]+[10**10])))

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

print(gokei+t)

Solution (Python):



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

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

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

Solution (Python):
import sys, re
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 fractions import gcd

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, T = MAP()
t = LIST()
t = [0] + t
t = [t[i]-t[i-1] for i in range(1, N+1)]


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

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

Solution (Python):
from __future__ import print_function

import sys
input = sys.stdin.readline


def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)
    return










import fractions

from fractions import gcd












from queue import Queue






from operator import mul
from functools import reduce





def coprimize(p, q):
    common = fractions.gcd(p, q)
    return (p // common, q // common)


def combinations_count(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom





n, t = map(int, input().strip().split())
a = list(map(int, input().strip().split()))
a.append(sys.maxsize)

l_continuous = [[]]
l_distinct = []
k = 0

continuous_flag=0

i=0
while i<n:
    if a[i] + t >= a[i + 1]:
        continuous_flag=1
        l_continuous[k].append(i)
        i+=1
    else:
        if continuous_flag==1:
            l_continuous[k].append(i)
            continuous_flag=0
            k+=1
            l_continuous.append([])
        else:
            l_distinct.append(i)
            
        i+=1
del i

ans = 0
for i in range(len(l_continuous)):
    if l_continuous[i].__len__() > 0:
        ans += a[max(l_continuous[i])] - a[min(l_continuous[i])] + t
for i in range(len(l_distinct)):
    ans += t
print(ans)

Solution (Python):
import sys

input = sys.stdin.readline


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


    print(ans + T)
    
    
    

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

print(ans)

Solution (Python):
import sys
n, t = map(int, input().split())
T = [int(i) for i in input().split()]
x = 0
start = 0
finish = 0
for i,j in enumerate(T):
    if i == n-1:
        if j >= finish:
            x += finish - start + t
        else:
            x += j - start + t
        print(x)
        sys.exit()
    if j >= finish:
        x += finish - start
    else:
        x += j - start
    start = j
    finish = j + t

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

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

ans = 0
for i in range(N):
    if i == N-1 or t[i] + T < t[i+1]:
        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()))
time = 0
sa = []
for i in range(n - 1):
    sa.append(t[i + 1] - t[i])
ans = 0
for i in range(len(sa)):
    if sa[i] <= T:
        ans += sa[i]
    else:
        ans += T
print(ans+T)

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

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

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    N, T = LI()
    t = LI()
    t = t[::-1]
    prev_time = t[0]
    tot = T
    for i, time in enumerate(t[1:]):
        if time + T < prev_time:
            tot += T
        else:
            tot += (prev_time - time)
        prev_time = time
    print(tot)
main()

Solution (Python):
import sys
input = sys.stdin.readline
N,T = [int(i) for i in input().split()]
t = [int(i) for i in input().split()]
sum = 0
for i in range(N-1) :
    if t[i+1] - t[i] <= T :
        sum += t[i+1] - t[i]
    else :
        sum += T
sum += T
print(sum)

Solution (Python):
import sys
input = sys.stdin.readline
N,T = [int(i) for i in input().split()]
t = [int(i) for i in input().split()]
sum = 0
for i in range(N-1) :
    if t[i+1] - t[i] <= T :
        sum += t[i+1] - t[i]
    else :
        sum += T
sum += T
print(sum)

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

loss_time_sum = 0
last_finished_time = T

for i in range(1, N):
    current = times[i]
    loss_time_sum += max(0, last_finished_time - current)
    last_finished_time = current + T
print(N * T - loss_time_sum)

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

def main():
    n,t=MI()
    tt=LI()
    ans=n*t
    for t0,t1 in zip(tt,tt[1:]):
        ans-=max(t-t1+t0,0)
    print(ans)

main()

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

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

print(ans)

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

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

print(ans)

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

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

print(answer)

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

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

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

ans = 0
now = 0
for i in range(n):
    if now > tm[i]:
        ans += (tm[i]+t)-now
        now = tm[i]+t

    else:
        ans += t
        now = tm[i]+t
        pass
    

print(ans)

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

print(ans + T)

Solution (Python):
N,T = map(int,input().split())
t = list(map(int,input().split()))
t.append(10**18)
ans = 0
for t1,t2 in zip(t[:-1],t[1:]):
    if t2-t1 < T:
        ans += t2-t1
    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])

ans += T

print(ans)

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

s = T
for i in range(1, N):
    d = max(0, t[i - 1] + T - t[i])
    s += T - d
print(s)

Solution (Python):

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

total = 0

for i in range(N):
    if i == N - 1:
        total += T
    else:
        total += min(T, ts[i + 1] - ts[i])

print(total)

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

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

Solution (Python):

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

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

ans = 0

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

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

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

def main():
    N,T = map(int,input().split())
    t = list(map(int,input().split()))
    
    push,time,ans = 0,T,0
    for i in range(N):
        if t[i] <= time:
            time = t[i] + T
        else:
            ans += (time-t[push])
            push = i
            time = t[i]+T
        
    ans += (time - t[push])
    print(ans)
    
if __name__ == "__main__":
    main()

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

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

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

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())
A = list(map(int, input().split())) 


dp = [0] * N
dp[0] = T

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

print(dp[-1])

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

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

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]

ans += t
print(ans)

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

time_lis = [int(_) for _ in input().split()]
length = len(time_lis)

ans = 0
for n in range(1, length):
    diff = time_lis[n] - time_lis[n - 1]
    if diff >= T:
        ans += T
    else:
        ans += diff
print(ans + T)

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

Solution (Python):
import sys
input = sys.stdin.readline
import numpy as np
N, T = [int(x) for x in input().split()]
t = [int(x) for x in input().split()]
ans = 0
t = np.array(t)
t_diff = np.diff(t)
for i in t_diff:
    ans += min(i, T)
print(ans + T)

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

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())) + [2 * 10**9]
ans = 0
for i in range(N):
    ans += min(t[i + 1] - t[i], T)
print(ans)

Solution (Python):

import sys
N, T = map(int, sys.stdin.readline().split())
L = list(map(int, sys.stdin.readline().split()))
E = [0 for _ in range(N)]

total=0
for i in range(N):
    E[i] = L[i]+T
    total +=E[i] - max(E[i-1], L[i])

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

Solution (Python):
N, T = map(int, input().split())
a = 0
c = -T
for ti in map(int, input().split()):
  a += min(T, ti - c)
  c = ti
print(a)

Solution (Python):
import sys

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

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

    return running_time

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

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

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


import sys

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

sum = 0
end = 0
for i in range(N):
    if end <= ts[i]:
        sum += T
    else:
        sum += T - (end - ts[i])
    end = ts[i] + T
print(sum)

Solution (Python):
import sys

if sys.platform in ['ios','win32','darwin']:
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

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

ans = 0
end = 0
for a in A:
	if end > a:
		ans += T - (end-a)
	else:
		ans += T
	end = a+T
print(ans)

Solution (Python):

N,T = map(int, input().split())
t_list = [int(e) for e in input().split()]

ans = 0

start_time = 0
extend_start_time = 0

for i in range(N):
    
    
    if t_list[i] - extend_start_time <= T:
        extend_start_time = t_list[i]
        
    else:
        ans += T + extend_start_time - start_time
        
        
        start_time = t_list[i]
        extend_start_time = t_list[i]

ans += T + extend_start_time - start_time
        
print(ans)

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

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

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

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

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

res = 0
pre_t = 0
for i in range(N):
    cur_t = t[i]

    if i==0:
        res+=T
    elif cur_t - pre_t >= T:
        res += T
    else:
        res += cur_t - pre_t

    pre_t = cur_t

print(res)

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

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

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

X = N * T - discount

print(X)

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

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

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

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

Solution (Python):
from sys import stdin

n,t = [int(x) for x in stdin.readline().rstrip().split()]
li = list(map(int,stdin.readline().rstrip().split()))

point = 0

lin = []

for i in range(1,n):
    lin.append(li[i]-li[i-1])

for i in lin:
    if i <= t:
        point += i
    else:
        point += t

point += t

print(point)

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

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