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

tmp = T
ans = T

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

print(ans)

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

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

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

Solution (Python):
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-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 pf(s): return print(s, flush=True)

N,T=LI()
tl=LI()

ans=0
for tidx, t in enumerate(reversed(tl)):
	
	if tidx==0:
		ans +=T
		continue
	
	ans += min(T,abs(t-tl[N-tidx]))

	
print(ans)

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

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

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

total = 0
for i in range(n):
    if i == 0:
        total += ts[i]
        continue
    total += min(ts[i] - ts[i-1], t)
total += t
print(total)

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

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

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

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

Solution (Python):
import sys
fastinput=sys.stdin.readline
N,T=map(int,fastinput().split())
p=[int(_) for _ in fastinput().split()]
oyumin=0
oyumax=0
Showertime=0
for i in p:
    if i>oyumax:
        Showertime+=oyumax-oyumin
        oyumin=i
        oyumax=i+T
    else:
        oyumax=i+T
Showertime+=oyumax-oyumin
print(Showertime)

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

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

Solution (Python):
import sys

def main():
    input = sys.stdin.readline
    N, T = map(int, input().split())
    A = list(map(int, input().split()))

    ans = 0
    for i in range(N-1):
        t0 = A[i]
        t1 = A[i+1]

        if t1 - t0 > T:
            ans += T
        else:
            ans += t1 - t0

    return ans + T


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

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

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

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-1]+T<=t[i]:
        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()))
sum = 0
for i in range(N):
    if i == (N-1):
        sum += T
    elif t[i+1]-t[i] >= T:
        sum += T
    else:
        sum += t[i+1]-t[i]

print(sum)

Solution (Python):
import sys
input = sys.stdin.readline
N, T = map(int, input().split())
t = list(map(int, input().split())) + [10**10]
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())
inf = 10**18
a = [int(i) for i in input().split()]
b = a[1:] + [inf]
ans = 0
for i in range(n):
    ans += min(t, b[i]-a[i])
print(ans)

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

Solution (Python):


















import math
import copy
from collections import defaultdict, Counter

from itertools import product

from itertools import permutations

from itertools import combinations
from bisect import bisect_left, bisect_right


def s_inpl(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
INF = float("inf")

N, T = s_inpl()
t = inpl()

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

waterbegin = 0
waterend = 0
water = 0

for i in range(N):
    if waterend < t[i]:
        water += waterend - waterbegin
        waterbegin = t[i]
        waterend = t[i] + T
    else:
        waterend = t[i] + T

water += waterend - waterbegin

print(water)

Solution (Python):
import sys
n,t=map(int,input().split())
T=list(map(int,input().split()))
ans=0
starttime=0
endtime=0
for i in T:
  if endtime>=i:
    endtime=endtime-(endtime-i)+t
  else:
    ans+=endtime-starttime
    starttime=i
    endtime=i+t
ans+=endtime-starttime
print(ans)

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

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

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

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

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

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

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

ans = t
for t1, t2 in zip(T[:-1], T[1:]):
  ans += min(t2 - t1, t)

print(ans)

Solution (Python):
def sentou(N: int, T: int, times: list) -> int:
    start_time, limit_time = 0, 0
    total_time = 0
    for t in times:
        if t >= limit_time:
            total_time += (limit_time - start_time)
            start_time = t
        limit_time = t + T
    return total_time + (limit_time - start_time)


if __name__ == "__main__":
    N, T = map(int, input().split())
    times = [int(s) for s in input().split()]
    ans = sentou(N, T, times)
    print(ans)

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

Solution (Python):
N, T = map(int, input().split())
t = list(map(int, input().split())) + [float('inf')]
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())
t = [int(i) for i in input().split()]
 
res = T
pre = t[0]
for i in t[1:]:
    if i < pre + T:
        res += i - pre
    else:
        res += T
    pre = i
 
print(res)

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

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

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

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

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

Solution (Python):
N,T=map(int,input().split())
Tn=list(map(int,input().split()))
Tn.append(float('inf'))
ans=0
now=0
for t in Tn:
    if t-now<T:
        ans+=t-now
    elif t-now>=T:
        ans+=T
    now=t
print(ans)

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

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

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

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

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

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

for i in range(N-1):
	gap.append(L[i+1]-L[i])

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

print(time)

Solution (Python):
from functools import reduce; from operator import add; print((lambda T, L: (reduce(add, (lambda t, l: [min(i - j, t) for i, j in zip(l[1:], l[:-1])])(T, L)) + T) if len(L) > 1 else T)(int(input().split()[1]), list(map(int, input().split()))))

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

Solution (Python):
num,time = map(int, raw_input().split())
t = raw_input().split()
ans = time
for i in range(0,num-1):
 	a = int(t[i+1])-int(t[i]) 
	if a < time:
		ans += a
	else:
		ans += time
print ans

Solution (Python):
num,time = map(int, raw_input().split())
t = raw_input().split()
ans = time
for i in range(0,num-1):
	if int(t[i+1])-int(t[i]) < time:
		ans += int(t[i+1])-int(t[i])
	else:
		ans += time
print ans

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

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


if __name__ == "__main__":
    main()

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

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

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

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

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

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

Solution (Python):

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

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

a = list(map(int,input().split()))
b = []
for i in range(n-1):
    b.append(a[i+1]-a[i])
su = 0
for i in range(n-1):
    if b[i] >= k:
        su += k
    else:
        su += b[i]
print(su+k)

Solution (Python):

import sys

def main():
	N, T = map(int, input().split(" "))
	tmp = input().split(" ")
	timming = [int(s) for s in tmp]
	
	time = 0
	for i, val in enumerate(timming):
		if i == (len(timming)-1):
			break
		interval = timming[i+1] - timming[i]
		if interval >= T:
			time += T
		else:
			time += interval
	
	print(time + T)
	
if __name__ == "__main__":
	main()

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

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

print(x)

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

Solution (Python):
def main():
    _, T = map(int, input().split())
    t = [int(s) for s in input().split()]

    print(solve(t, T))

def solve(t, T):
    s = 0
    for ti, tj in zip(t, t[1:]):
        s += min(T, tj - ti)
    
    s += T
    return s

main()

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

Solution (Python):

from collections import defaultdict
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007






n,T = LI()
ans = 0
t = LI()
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())
L = list(map(int,input().split()))
cnt = 0
prev = L[0]
for x in L:
    if prev + T > x:
        cnt += x - prev
    else:
        cnt += T
    prev = x
 
cnt += T
print(cnt)

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

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

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


dabaaaaa = 0

for i in range(len(push_list)-1):
    if push_list[i + 1] - push_list[i] < T:
        dabaaaaa += push_list[i + 1] - push_list[i]
    else:
        dabaaaaa += T

    

print(dabaaaaa+T)

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

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

counter = 0

for i in range(len(li_t)):
    if i == (len(li_t) - 1):
        counter += t
    else:
        if li_t[i + 1] - li_t[i] >= t:
            counter += t
        else:
            counter += li_t[i + 1] - li_t[i]


print(counter)

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

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

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

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

Solution (Python):
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10**9)
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())
a,ans=list(map(int,input().split())),0
for s in range(n-1):
  if a[s+1]-a[s]<t:
    ans+=a[s+1]-a[s]
  else:ans+=t
print(ans+t)

Solution (Python):
(n,t) = (int(i) for i in input().split())
T = [int(j) for j in input().split()]
if n == 1:
    print(t)
else:
    S = [a-b for a,b in zip(T[1:],T[:-1])]
    U = [u if u <= t else t for u in S]
    print(sum(U)+t)

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

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

Solution (Python):
a,b=map(int,input().split())
x = list(map(int,input().split()))
s = 0
for i in range(1,a):
    if x[i]-x[i-1] < b:
        s+=x[i]-x[i-1]
    else:
        s+=b

print(s+b)

Solution (Python):
def solve(N, T, ts):
    return sum([min(ts[i + 1] - ts[i], T) for i in range(N - 1)]) + T


if __name__ == "__main__":
    N, T = tuple(map(int, input().split(" ")))
    ts = list(map(int, input().split(" ")))
    print(solve(N, T, ts))

Solution (Python):
n, T = map(int, input().split())
*s, = map(int, input().split())
ans = T

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

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

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

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


def main():
    print(solve())


if __name__ == '__main__':
    main()

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

    import collections
    stack = collections.deque()

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

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

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

    return ans


def main():
    print(solve())


if __name__ == '__main__':
    main()

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

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

print(ans)

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

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

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

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

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

print(ans)

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

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

    print(t_sum)

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):
from sys import stderr, setrecursionlimit
setrecursionlimit(2147483647)
def getInt():
    return int(input())
def getInts():
    return [int(i) for i in input().split()]
def getIntLines(n=1):
    res = []
    for _ in range(n):
        res.append(getInt())
    return res
def getIntsLines(n=1):
    res = []
    for _ in range(n):
        res.append(getInts())
    return res
def debug(*args, sep=" ", end="\n"):
    for item in args:
        stderr.write(str(item))
        stderr.write(sep)
    stderr.write(end)

n, t = getInts()
tl = getInts()
ans = 0
last = 0
last_head = 0
for v in tl:
    if v <= last:
        last += (v + t) - last
    else:
        ans += last - last_head
        last_head = v
        last = last_head + t
ans += last - last_head
print(ans)

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

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

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

N, T = map(int, input().split())
x = 0
f_t = 0

for t in list(map(int, input().split())):
    if t >= f_t:
        x += T
    else:
        x += (t + T - f_t)
    f_t = t + T
    
print(x)

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

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


abc060_c()

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

ans = 0
now = 0

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

print(ans)

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

prev_t = t[0]
ans = T
for _t in t[1:]:
    delta_t = _t - prev_t
    if delta_t <= T:
        ans += delta_t
    else:
        ans += T
    prev_t = _t
print(ans)

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

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


if __name__ == '__main__':
    main()

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

Solution (Python):

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

ans = t[-1] + T
pushed = 0
for i, ti in enumerate(t):
    if ti > pushed + T: ans -= (ti - pushed - T)
    pushed = ti

print(ans)

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

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

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

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

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

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

print(S)

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

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

print(S)

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

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

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

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

print(result)

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

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

for i in range(n):
    if i == 0:
        u = a[0]
        if n == 1:
            X += t
            break
        else:
            v = a[1]
    if u + t < v:
        X += t
    else:
        X += v - u
    u = v
    if i + 1 < n:
        v = a[i + 1]
    if i == n - 1:
        X += t
print(X)

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

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

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

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

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

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

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

print(x+t)

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

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

X = T
prev_t = 0
for t in t_list:
    if t == 0:
        continue
    if prev_t + T > t:
        X += t - prev_t
    else:
        X += T
    prev_t = t
print(X)

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

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

for t in t_list:
    if t-prev < T:
        ans += t-prev
    else:
        ans += T
    prev = t
print(ans)

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