Problem:
 Score : 300 points    Problem Statement In a public bath, there is a shower which emits water for T seconds when the switch is pushed.  If the switch is pushed when the shower is already emitting water, from that moment it will be emitting water for T seconds.
Note that it does not mean that the shower emits water for T additional seconds.  N people will push the switch while passing by the shower.
The i -th person will push the switch t_i seconds after the first person pushes it.  How long will the shower emit water in total?      Constraints  1 ≤ N ≤ 200,000  1 ≤ T ≤ 10^9  0 = t_1 < t_2 < t_3 < , ..., < t_{N-1} < t_N ≤ 10^9  T and each t_i are integers.         Input Input is given from Standard Input in the following format:  N  T  t_1  t_2 ... t_N       Output Assume that the shower will emit water for a total of X seconds. Print X .        Sample Input 1 2 4
0 3      Sample Output 1 7  Three seconds after the first person pushes the water, the switch is pushed again and the shower emits water for four more seconds, for a total of seven seconds.       Sample Input 2 2 4
0 5      Sample Output 2 8  One second after the shower stops emission of water triggered by the first person, the switch is pushed again.       Sample Input 3 4 1000000000
0 1000 1000000 1000000000      Sample Output 3 2000000000       Sample Input 4 1 1
0      Sample Output 4 1       Sample Input 5 9 10
0 3 5 7 100 110 200 300 311      Sample Output 5 67

Solution (Python):

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

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

print(time+T)

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

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

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

  total = 0

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

    
  print(total+t)

main()

Solution (Python):

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

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


main()

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

total = 0

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

    
print(total+t)

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

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

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

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

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

count += t

print(count)

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

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

Solution (Python):

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
mod = 10**9+7


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

Solution (Python):
N, T = map(int, input().split())
A = [int(a) for a in input().split()] + [1<<100]
print(sum([min(A[i+1] - A[i], T) for i in range(N)]))

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

print(ans)

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

result = 0
for i, s in enumerate(schedule):
  if (i + 1) > len(schedule) - 1:
    continue
  a = schedule[i + 1] - s
  if a > t:
    a = t
  result += a
result += t

print(result)

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

T = [int(i) for i in input().split()]
res = 0
for i in range(len(T)-1):
    d = T[i+1] - T[i]
    if  d > m:
        res += m
    else:
        res += d
print(res + m)

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

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

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

Solution (Python):

def examC():
    N, T = LI()
    t = LI()
    cur = T
    before = 0
    for i in t[1:]:
        cur += min(T,i-before)
        before = i
    print(cur)

import sys
import copy
import bisect
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examC()

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

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
from functools import reduce
import copy
import math
from pprint import pprint
import collections
import bisect


sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def int_inputs(num_of_input):
    ins = [int(input()) for i in range(num_of_input)]
    return ins


def solve(inputs):
    [N, T] = string_to_int(inputs[0])
    P = string_to_int(inputs[1])

    count = 0
    prev = 0
    for p in P:
        if p == 0:
            continue
        else:
            if p - prev < T:
                count += p - prev
            else:
                count += T
        prev = p
    count += T
    return count


def string_to_int(string):
    return list(map(int, string.split()))


if __name__ == "__main__":
    ret = solve(inputs(2))
    print(ret)

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

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

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

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

num = 0
for i in range(1, N):
    sbn = tlist[i] - tlist[i - 1]
    if sbn < T:
        num += sbn
    else:
        num += T
num += T
print(num)

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

wait=[0]*len(h)
for i in range(len(wait)-1):
  wait[i]=h[i+1]-h[i]
wait[len(wait)-1]=t

ans=0
for i in range(len(wait)):
  ans+=min(wait[i],t)

print(ans)

Solution (Python):
a = list(input().split(" "))
b = list(input().split(" "))
t = 0
for k, i in enumerate(b):
    if k < len(b)-1:
        if int(i)+int(a[1]) > int(b[k+1]):
            t += int(b[k+1]) - int(b[k])
        else:
            t += int(a[1])
    else:
        t += int(a[1])
print(t)

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

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

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

print(X)

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

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

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


if __name__ == "__main__":
    main()

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

    ans = T
    end = T
    for ti in t[1:]:
        if end < ti:
            ans += T
        else:
            ans += T - (end - ti)
        end = ti + T
    print(ans)

if __name__ == "__main__":
    main()

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

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

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

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

print(sum)

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

print(ans+T)

Solution (Python):

import sys


def solve(N: int, T: int, t: "List[int]"):
    answer =0 
    for i in range(N-1):
        answer += min(t[i+1]-t[i],T)
    
    answer += T
    print(answer)


    return


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

if __name__ == '__main__':
    main()

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

d=[T-(t[i+1]-t[i]) for i in range(N-1) if t[i+1]-t[i]<T]
print(N*T-sum(d))

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

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

Solution (Python):
def main():
    T, *tn = map(int, open(0).read().split()[1:])
    print(tn[-1] + T - sum(t2 - t1 - T
                           for t1, t2
                           in zip(tn[0:], tn[1:])
                           if t2 - t1 > T))
    return


main()

Solution (Python):
from sys import stdin


def main():
    lines = stdin.readlines()
    T = int(lines[0].split()[1])
    tn = [int(ti) for ti in lines[1].split()]
    print(tn[-1] + T - sum(t2 - t1 - T
                           for t1, t2
                           in zip(tn[0:], tn[1:]) if t2 - t1 > T))
    return


main()

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

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

Solution (Python):
from sys import stdin


def main():
    lines = stdin.readlines()
    T = int(lines[0].split()[1])
    tn = [int(ti) for ti in lines[1].split()]
    print(tn[-1] + T - sum(t2 - t1 - T for t1, t2 in zip(tn[0:], tn[1:]) if t2 - t1 > T))
    return


main()

Solution (Python):
from sys import stdin


def main():
    lines = stdin.readlines()
    T = int(lines[0].split()[1])
    tn = [int(ti) for ti in lines[1].split()]
    ans = 0
    for t1, t2 in zip(tn[0:], tn[1:]):
        ans += min(T, t2 - t1)
    ans += T
    print(ans)
    return


main()

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

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

print(ans+T)

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

Solution (Python):
n,t = map(int,input().split())
time = list(map(int,input().split())) + [float('inf')]

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

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

ans, lt = t, 0
for nt in T:
    if nt <= lt + t:
        ans += (nt - lt)
    else:
        ans += t
    lt = nt

print(ans)

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

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

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())
time = [int(i) for i in input().split()]
ans = T  
now = 0 
for i in range(N-1):
  now = time[i] + T
  if now > time[i+1]:
    ans += (time[i+1]-time[i]) 
  else:
    ans += T
print(ans)

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

ans = t
stop = t

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

print(ans)

Solution (Python):


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

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

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

print(res + t)

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

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

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

Solution (Python):

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

ans = 0
start = 0

if len(T) == 1:
    ans = TT + T[0]
    print(ans)
    exit()

for i in range(N-1):
    if i == N-2:
        if T[i+1]-T[i] >= TT:
            ans += TT
        else:
            ans += TT+T[i+1]-start
    if T[i+1]-T[i] >= TT:
        ans += TT+T[i]-start
        start = T[i+1]
    elif T[i+1]-T[i] < TT:
        pass
print(ans)

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

Solution (Python):


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

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

print(all+T)

Solution (Python):
def input():
    import sys
    return sys.stdin.readline().rstrip()


def main():
    import math
    import collections
    import itertools

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

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

    print(ans)


if __name__ == '__main__':
    main()

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

Solution (Python):
import sys

stdin = sys.stdin

ns = lambda : stdin.readline().rstrip()
ni = lambda : int(ns())
na = lambda : list(map(int, stdin.readline().split()))

def main():
  n, T = na()
  t = na()

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

main()

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

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

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

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

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

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

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


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

    arr = [[]] * len(t)
    for i in range(len(t)):
        arr[i] = [t[i], t[i]+T]

    ans = arr[0][1]
    for i in range(len(t)-1):
        _, t1 = arr[i]
        f2, t2 = arr[i+1]

        if t1 <= f2:
            ans += t2 - f2
        else:
            ans += t2 - t1
    print(ans)


if __name__ == '__main__':
    main()

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


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

    arr = [[]] * len(t)
    for i in range(len(t)):
        arr[i] = [t[i], t[i]+T]

    ans = arr[0][1]
    for i in range(len(t)-1):
        _, t1 = arr[i]
        f2, t2 = arr[i+1]

        if t1 <= f2:
            ans += t2 - f2
        else:
            ans += t2 - t1
    print(ans)


if __name__ == '__main__':
    main()

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

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

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

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

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

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

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

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

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

answer = 0
for i in range(1, N+1):
    answer += T
    answer -= max(0, TL[i-1] + T - TL[i])
print(answer)

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

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

Solution (Python):

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

tl.append(float("inf"))

ans = 0

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

print(ans)

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

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

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

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

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

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

print(ans)

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

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

ans += T
print(ans)

Solution (Python):

import sys
input = sys.stdin.readline
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7



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

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

print(count)

Solution (Python):
n, t = map(int, input().split())
ls = list(map(int, input().split()))
e = 0
res = 0
for s in ls:
    ne = s + t
    res += ne - e if s <= e else t
    e = ne
print(res)

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

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

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

print(ans)

Solution (Python):
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())
arr = list(map(int,input().split()))


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

ans += t

print(ans)

Solution (Python):
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    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)
resolve()

Solution (Python):
N, T = map(int, input().split())
X = 0
start = 0
stop = 0
for t in map(int, input().split()):
  if t > stop:
    X += stop - start
    start = t
  stop = t + T
X += stop - start
print(X)

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


if __name__ == "__main__":
    resolve()

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


if __name__ == "__main__":
    resolve()

Solution (Python):
from collections import deque

N, T = [int(n) for n in input().split()]
Q = deque([int(n) for n in input().split()])

def main():
    ans = 0
    while Q:
        curr = Q.popleft()
        next = Q[0] if Q else float('inf')
        ans += min(T, next - curr)
    print(ans)

if __name__ == '__main__':
    main()

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

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

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

Solution (Python):


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

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

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

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

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

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

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

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

cnt = 0

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

print(cnt)

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

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

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


if __name__ == "__main__":
    main()

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

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

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

print(a)

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

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

print(a)

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

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

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()))
N = NT[0]
T = NT[1]
S = E = ans = 0
t = list(map(int, input().split()))
for i in range(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 = [int(x) for x in input().split()]
ret = 0
pre = 0
for t in [int(x) for x in input().split()]:
  ret += min(T, t - pre)
  pre = t
else:
  ret += T
print(ret)