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

Solution (Python):
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

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

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

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

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

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

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

def it():
    for i in range(N-1):
        diff = ts[i+1] - ts[i]
        if diff <= T:
            yield diff
        else:
            yield T
    yield T

print(sum(it()))

Solution (Python):
import sys
import heapq
import re
from itertools import permutations
from bisect import bisect_left, bisect_right
from collections import Counter, deque
from fractions import gcd
from math import factorial, sqrt, ceil
from functools import lru_cache, reduce
INF = 1 << 60
MOD = 1000000007
sys.setrecursionlimit(10 ** 7)


class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


def dijkstra_heap(s, edge, n):
    
    d = [10**20] * n
    used = [True] * n 
    d[s] = 0
    used[s] = False
    edgelist = []
    for a,b in edge[s]:
        heapq.heappush(edgelist,a*(10**6)+b)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        
        if not used[minedge%(10**6)]:
            continue
        v = minedge%(10**6)
        d[v] = minedge//(10**6)
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,(e[0]+d[v])*(10**6)+e[1])
    return d


def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr


def lcm(x, y):
    return (x * y) // gcd(x, y)


def lcm_list(numbers):
    return reduce(lcm, numbers, 1)


def gcd_list(numbers):
    return reduce(gcd, numbers)


def is_prime(n):
    if n <= 1:
        return False
    p = 2
    while True:
        if p ** 2 > n:
            break
        if n % p == 0:
            return False
        p += 1
    return True



def eratosthenes(limit):
    A = [i for i in range(2, limit+1)]
    P = []

    while True:
        prime = min(A)
        
        if prime > sqrt(limit):
            break
            
        P.append(prime)
            
        i = 0
        while i < len(A):
            if A[i] % prime == 0:
                A.pop(i)
                continue
            i += 1
            
    for a in A:
        P.append(a)
            
    return P


def permutation_with_duplicates(L):

    if L == []:
        return [[]]

    else:
        ret = []

        
        S = sorted(set(L))

        for i in S:

            data = L[:]
            data.remove(i)

            for j in permutation_with_duplicates(data):
                ret.append([i] + j)

        return ret



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

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

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

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

Solution (Python):
def resolve():
    '''
    code here
    '''
    N, T = [int(item) for item in input().split()]
    t_list = [int(item) for item in input().split()]
    time = 0

    for i in range(N):
        if i == 0:
            time = T
        else:
            delta_time = t_list[i] - t_list[i-1]
            time += min(T, delta_time)
            
    print(time)

if __name__ == "__main__":
    resolve()

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

Solution (Python):
import sys

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


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

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

    print(res + t)


if __name__ == '__main__':
    resolve()

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

print(ans)

Solution (Python):
















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

start = arrT[0]
end = 0
ans = 0
for i in range(N):
    if i == N-1:
        if arrT[i-1]+T>=arrT[i]:
            end = arrT[i]
            num = end-start+T
            ans += num
        else:
            ans += T
    elif arrT[i]+T>=arrT[i+1]:
        end = arrT[i]
        continue
    else:
        end = arrT[i]
        num = end-start+T
        ans += num
        start = arrT[i+1]

print(ans)

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

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

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

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

res += T

print(res)

Solution (Python):
def myAnswer(N:int,T:int,t:list) -> int:
   total = T*N
   sub = 0
   if(N == 1): return T
   pre = t.pop(0)
   for time in t:
      if(pre + T - time > 0):
         sub += pre+T - time
      pre = time
   return total - sub

def modelAnswer():
   return
def main():
   N,T = map(int,input().split())
   t = list(map(int,input().split()))
   print(myAnswer(N,T,t[:]))
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):
  if t[i+1] - t[i] > T:
    X += T
  else:
    X += t[i+1] - t[i]
print(X + T)

Solution (Python):
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
def ism():return map(str,input().split())
def isl():return list(map(str,input().split()))

n,t = iim()
T = iil()

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

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

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

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

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

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

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

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

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

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

diff = []

for i in range(N - 1):
    diff.append(t[i+1] - t[i])



shower_time = list(map(lambda x: T if T < x else x, diff))
ans = sum(shower_time) + T

print(ans)

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

Solution (Python):
n , t = map(int,input().split())
p = list(map(int,input().split()))
ans = t
for i in range(1,n):
    if p[i-1] + t > p[i]:
        ans += p[i] - p[i-1] 
    elif p[i-1] + t <= p[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(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()))
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()))
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 = map(int,input().split())
li = list(map(int,input().split()))
count = t
if n == 1:
    print(t)
    sys.exit()
for i,l in enumerate(li):
    if i == 0:
        continue
    if l - li[i-1] <= t:
        count += l - li[i-1]
    else:
        count += t
print(count)

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

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

n, t = map(int, input().split()) 
people = [int(i) for i in input().split()] 

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

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

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

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

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

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

print(ans)

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

open = [t[0] + T]
ans = T
for n in range(N):
    if n == 0:
        continue
    else:
        if t[n] >= open[-1]:
            ans += T
            open.append(t[n] + T)
        else:
            ans += t[n] - t[n-1]
            open.append(t[n] + T)

print(ans)

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

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

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

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

print(ans)

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

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


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

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):
import numpy as np
N, T = list(map(int, input().split()))
t = np.array(list(map(int, input().split())))
tT = np.sort(t)[::-1] + T

total = tT[0]
for i in range(1, N):
  total -= max(tT[i-1] - tT[i]-T, 0)
  
print(total)

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

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

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

cnt = T
time = T

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

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

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

print(ans)

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

o = T
for i, j in zip(t, t[1:]):
  o += min(j-i, T)
print(o)

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

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

print(dur)

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

print(ans + T)

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

Solution (Python):
N, T, *t_l = map(int, open(0).read().split())
ans = 0
t_before = 0
for t in t_l:
    ans += min(t-t_before, T)
    t_before = t
print(ans+T)

Solution (Python):
import sys

input = sys.stdin.buffer.readline




import numpy as np


def main():
	n,t=map(int,input().split())
	T=list(map(int,input().split()))
	T=np.array(T)
	diff=T[1:]-T[:-1]
	time1=diff[diff<=t]
	time2=len(diff[diff>t])*t
	print(time1.sum()+time2+t)



if __name__ == "__main__":
	main()

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

    dp = [0] * N
    dp[0] = t[0]
    for i, tt in enumerate(t):
        if i == N-1:
            ans += T
            break
        if tt + T > t[i+1]:
            ans += t[i+1] - tt
        else:
            ans += T
    print(ans)

if __name__ == '__main__':
    main()

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

Solution (Python):
n,T = map(int,input().split())
t = list(map(int,input().split()))
sa = [0]
if n == 1:
    print(T)
    exit()
for i in range(n-1):
    if abs(t[i+1] - t[i]) <= T:
        ans = abs(t[i+1] - t[i])
    elif abs(t[i+1] - t[i]) > T:
        ans = T
    sa.append(ans)
sa.append(T)
print(sum(sa))

Solution (Python):
n, t = map(int, input().split())
T = list(map(int, input().split())) + [10 ** 19]

ans = 0
for t1, t2 in zip(T, 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()))

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

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

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

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

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

Solution (Python):

n, T = map(int,input().split())
t = [int(i) for i 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
print(ans + T)

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

ans = 0
temp = 0
for i in range(n):
    ans += min(t, T[i]-temp)
    temp = T[i]
else:
    ans += t
print(ans)

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

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

Solution (Python):
import sys

def solve():
    input = sys.stdin.readline
    N, T = map(int, input().split())
    A = [int(t) for t in input().split()]

    Ans = 0
    currentTime = A[0]
    for i in range(1, N):
        if A[i] - currentTime < T: Ans += A[i] - currentTime
        else: Ans += T
        currentTime = A[i]
    Ans += T
    print(Ans)
    return 0

if __name__ == "__main__":
    solve()

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

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

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


if __name__ == '__main__':
    main()

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

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

ans = 0

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

print(ans + j)

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

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

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

Solution (Python):
a,b=list(map(int, input().split()))
c=list(map(int, input().split()))

x=0
y=0
z=0
ans=0
for i in range(a-1):
	x=c[i]
	if c[i]<=c[i+1]-b:
		ans=ans+b
	else:
		ans=ans+c[i+1]-c[i]
print(ans+b)

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

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

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

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

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

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

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

print(ans)

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

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

ans = t + 0
cum_time = 0
for d in data:
    dt = d - cum_time
    if dt < t:
        lost = t - dt
        ans -= lost
    ans += t
    cum_time += dt

print(ans)

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

Solution (Python):
N,T = input().split()
T = int(T)
L = [int(x) for x in input().split()]
R = 0
for i in range(len(L) - 1):
    su = L[i+1] - L[i]
    R += min([su,T])
print(R+T)

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

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

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

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

sum = 0

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

sum = sum + T

print(sum)

Solution (Python):
n, t = (int(x) for x in input().split())
t_l = [int(x) for x in input().split()]
ans = s = 0
for t_i in t_l:
    if s <= t_i:
        ans += t
    else:
        ans += (t_i - s) + t
    s = t_i + t
print(ans)

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

Times = list(input().split())
time = 0

for i in range(N - 1):
    if int(Times[i]) + T <= int(Times[i + 1]):
        time += T
    else:
        time = time + (int(Times[i + 1]) - int(Times[i]))

print(time + T)

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

Solution (Python):



from fractions import gcd 
from functools import reduce
import sys
sys.setrecursionlimit(200000000)
from inspect import currentframe




def printargs2err(*args):
    names = {id(v):k for k,v in currentframe().f_back.f_locals.items()}
    print(', '.join(names.get(id(arg),'???')+' : '+repr(arg) for arg in args),file=sys.stderr)
def debug(x):
    print(x,file=sys.stderr)
def printglobals():
    for (symbol, value) in globals().items():
        print('symbol="%s"、value=%s' % (symbol, value),file=sys.stderr)
def printlocals():
    for (symbol, value) in locals().items():
        print('symbol="%s"、value=%s' % (symbol, value),file=sys.stderr)

def pin(type=int):
    return map(type,input().split())

def worstdata():
    a=0
    return a

def vacation(N,act):
    lastact =[]
    dp=[0,max(act[0])]*(N+1) 
    
    return 0




N,T=pin()
timing=tuple(pin())

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

Solution (Python):



from fractions import gcd 
from functools import reduce
import sys
sys.setrecursionlimit(200000000)
from inspect import currentframe




def printargs2err(*args):
    names = {id(v):k for k,v in currentframe().f_back.f_locals.items()}
    print(', '.join(names.get(id(arg),'???')+' : '+repr(arg) for arg in args),file=sys.stderr)
def debug(x):
    print(x,file=sys.stderr)
def printglobals():
    for (symbol, value) in globals().items():
        print('symbol="%s"、value=%s' % (symbol, value),file=sys.stderr)
def printlocals():
    for (symbol, value) in locals().items():
        print('symbol="%s"、value=%s' % (symbol, value),file=sys.stderr)

def pin(type=int):
    return map(type,input().split())

def worstdata():
    a=0
    return a

def vacation(N,act):
    lastact =[]
    dp=[0,max(act[0])]*(N+1) 
    
    return 0




N,T=pin()
timing=list(pin())

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

Solution (Python):



from fractions import gcd 
from functools import reduce
import sys
sys.setrecursionlimit(200000000)
from inspect import currentframe




def printargs2err(*args):
    names = {id(v):k for k,v in currentframe().f_back.f_locals.items()}
    print(', '.join(names.get(id(arg),'???')+' : '+repr(arg) for arg in args),file=sys.stderr)
def debug(x):
    print(x,file=sys.stderr)
def printglobals():
    for (symbol, value) in globals().items():
        print('symbol="%s"、value=%s' % (symbol, value),file=sys.stderr)
def printlocals():
    for (symbol, value) in locals().items():
        print('symbol="%s"、value=%s' % (symbol, value),file=sys.stderr)

def pin(type=int):
    return map(type,input().split())

def worstdata():
    a=0
    return a

def vacation(N,act):
    lastact =[]
    dp=[0,max(act[0])]*(N+1) 
    
    return 0




N,T=pin()
timing=list(pin())

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

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

print(ans)

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

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

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

print(time + t)

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

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

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