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

import sys
import math
import os
import itertools
import string
import heapq
from _collections import defaultdict
from functools import lru_cache

class Scanner():
    def int():
        return int(sys.stdin.readline().rstrip())
    def string():
        return sys.stdin.readline().rstrip()
    def map_int():
        return [int(x) for x in Scanner.string().split()]
    def string_list(n):
        return [input() for i in range(n)]
    def int_list_list(n):
        return [Scanner.mapInt() for i in range(n)]
    def int_cols_list(n):
        return [int(input()) for i in range(n)]
        
class Math():
    def gcd(a,b):
        if b == 0:
            return a
        return Math.gcd(b,a % b)
    def lcm(a,b):
        return (a * b) // Math.gcd(a,b)
    def roundUp(a,b):
        return -(-a // b)
    def toUpperMultiple(a,x):
        return Math.roundUp(a,x) * x
    def toLowerMultiple(a,x):
        return (a // x) * x
    def nearPow2(n):
        if n <= 0:
            return 0
        if n & (n - 1) == 0:
            return n
        ret = 1
        while(n > 0):
            ret <<= 1
            n >>= 1
        return ret
    def isPrime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3,d + 1,2):
            if n % i == 0:
                return False
        return True

MOD = int(1e09) + 7

def main():
    N,T = Scanner.map_int()
    A = Scanner.map_int()

    ans = 0
    prev = 0
    for i in range(N):
        ans += T
        ans -= max(0,prev - A[i])
        prev = A[i] + T
    print(ans)
    return

if __name__ == "__main__":
    main()

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

total = T
now = T

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

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

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

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

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

print(ans)

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

diff_t = [t_list[i+1] - t_list[i] for i in range(N-1)]

ans = 0
for dt in diff_t:
    if dt <= T:
        ans += dt
    else:
        ans += T

ans += T
print(ans)

Solution (Python):


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

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

print(ans+T)

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

value+=T
print(value)

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

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

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

ans+=T
print(ans)

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

print(ans+T)

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

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

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())
time = list(map(int, input().split()))
sub_list = []
for i in range(1,n):
    sub_list.append(time[i] - time[i-1])

not_water = 0
for i in sub_list:
    if i > t:
        not_water += (i - t) 
print(time[-1] + t - not_water)

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

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

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

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

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

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

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

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

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

else:
    ans += T
print(ans)

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

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

cnt = 0
ans = 0
for i in range(n):
    if i == 0:
        before = t_li[i]
        ans = t_li[i] + t
        continue
    
    if ans < t_li[i]:
        cnt += t_li[i] - ans
        ans = t_li[i] + t
    else:
        ans = t_li[i] + t
        
print(ans - cnt)

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

Solution (Python):
N, T = map(int,input().split())
List = list(map(int,input().split()))
Data = [0,0]
for item in List:
  if Data[0]>=item:
    Data[1] += T + item -Data[0]
    Data[0] = item +T
  else:
    Data[1] += T
    Data[0] = item +T
print(Data[1])

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

Solution (Python):
n, t = map(int, input().split())
li = list(map(int, input().split()))
li = li[::-1]
ans = 0

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

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

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

ans += T
print(ans)

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

a.append(1000000000000)

an = 0

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

Solution (Python):
import sys


def slove():
    input = sys.stdin.readline
    n, t = list(map(int, input().rstrip('\n').split()))
    tl = list(map(int, input().rstrip('\n').split()))
    mt = 0
    for i in range(n-1):
        mt += (min(tl[i] + t, tl[i+1]) - tl[i])
    print(mt + t)


if __name__ == '__main__':
    slove()

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

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

ans = 0
until = 0
for t in ts:
    ans += min(T, t+T-until)
    until = t+T
print(ans)

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

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

ans = T
current = T
for t in ts[1:]:
    if t < current:
        ans += T + t - current
        current = t + T
    else:
        ans += T
        current = t + 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-1]+t<=T[i]:
    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
till = 0

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

print(ans)

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

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

print(x)

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

now = 0
end = 0
ans = 0
for i in range(N):
    a = A[i]
    ans += min((T-(end-a)),T)
    now = a
    end = a+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 = tuple(map(int, input().split()))
t = list(map(int, input().split()))
if N == 1:
    print(T)
    exit()

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

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

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

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

Solution (Python):
import os

N,T = (int(x) for x in input().split())
t = [int(i) for i in input().split()]

ans = 0
sum = 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 = [int(el) for el in input().split(' ')]
s = [int(el) for el in input().split(' ')]
total = 0
for i in range(n-1):
    total += min(T, s[i+1]-s[i])
print(total + T)

Solution (Python):
N, T = map(int,input().split())
t = list(map(int,input().split()))
s = 0
start = 0
end = 0
for p in t:
  if end > p:
    end = p+T
  else:
    s += (end - start)
    start = p
    end = p+T
s += end - start
print(s)

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

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

print(ans + T)

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

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

print(ans + T)

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

duration = 0 
max = 0

for i in ls :
  if  i <= max and max <= i+b :	
    duration += i + b - max  
    max = i + b
    
  elif max < i :
    duration += b
    max = i + b
    
print(duration)

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

Solution (Python):
n, t = map(int, input().split())
people = list(map(int, input().split()))
people.append(people[-1]+ t+1)
if n == 1:
    print(t)
else:
    time = 0
    for i in range(n+1):
        if i ==0:
            togire = False
            start = people[i]
            continue
        if people[i] - people[i-1] > t:
            togire = True
            time += people[i-1] - start + t
            start = people[i]
        else:
            togire = False
    print(time)

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

Solution (Python):
def main():
    import sys
    input = sys.stdin.readline
    n, t = list(map(int, input().rstrip('\n').split()))
    T = list(map(int, input().rstrip('\n').split()))
    cnt = 0
    for i in range(1, n):
        cnt += min(T[i] - T[i-1], t)
    print(cnt + t)


if __name__ == '__main__':
    main()

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

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

for i in range(N-1):
    if L[i+1] - L[i] >= T:
        x += T
    else:
        x += L[i+1] - L[i]
else:
    x += T
    print(x)

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

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

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

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

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

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

res = 0
pre = -1e10
for t in [int(v) for v in input().split()]:
    res += T

    if pre + T > t:
        res -= (pre + T) - t
    pre = t

print(res)

Solution (Python):


import copy
import sys
import math


tmp = input().split()
hoge = list(map(lambda a: int(a), tmp))

n=hoge[0]
t=hoge[1]

total=n*t
tmp = input().split()
hoge = list(map(lambda a: int(a), tmp))
for i in range(0,n-1):
	if(hoge[i+1]-hoge[i]<t):
		total-=t-(hoge[i+1]-hoge[i])
print(total)

Solution (Python):
import copy
N, T = map(int, input().split())
t = list(map(int, input().split()))
tmp = copy.deepcopy(t)
for i in range(1, N):
    t[i] = tmp[i] - tmp[i-1]

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

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

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

ans += left
print(ans)

Solution (Python):



N, T = map(int, input().split())
a = list(map(int, input().split()))
total_t, a_len = 0, len(a)

for i in range(a_len - 1):
    if a[i] + T > a[i + 1]: 
        total_t += a[i + 1] - a[i]
    else: 
        total_t += T

print(total_t + T)

Solution (Python):



N, T = map(int, input().split())
a = list(map(int, input().split()))
total_t, crrnt_t, a_len = 0, 0, len(a)

for i in range(a_len - 1):
    if a[i] + T > a[i + 1]: 
        total_t += a[i + 1] - a[i]
    else: 
        total_t += T
    crrnt_t = a[i + 1]

print(total_t + T)

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

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

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]
ans+=t
print(ans)

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

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

Solution (Python):


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

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

Solution (Python):

import sys


def solve(N: int, T: int, t: "List[int]"):
    l = [t[i+1]-t[i] if (t[i+1]-t[i] < T) else T for i in range(N-1) ]
    print(sum(l)+T)
    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()))

l = [t[0]]
for i in range(1, N):
    l.append(t[i] - t[i - 1])

ans = 0

for ll in l:
    if ll < T:
        ans += ll
    else:
        ans += T

print(ans + T)

Solution (Python):

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


if __name__ == "__main__":
    main()

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

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

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

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

Solution (Python):


n, t = map(int, input().split())
a = list(map(int, input().split()))
sp = 0
ep = t
total = 0


for i in range(1, n):
    if a[i] <= ep:
        ep = a[i]+t
    elif a[i] > ep:
        total += ep-sp
        sp = a[i]
        ep = a[i]+t

total += ep-sp
print(total)

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

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

print(t_water + T)

Solution (Python):
N, T = map(int, input().split())
*push, = map(int, input().split())
ans = 0
current = -T
for t in push:
    offset = max(current + T - t, 0)
    ans += T - offset
    current = t
print(ans)

Solution (Python):
human_num, time = tuple(int(i) for i in input().split(" "))
time_list = tuple(int(i) for i in input().split(" "))
ans = 0
for i in range(human_num):
    if i == 0:
        ans += time
    else:
        time_differance = time_list[i] - time_list[i - 1]
        if time_differance <= time:
            ans += time_differance
        else:
            ans += time
print(ans)

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

ans = 0

now = t_list[0]
end = now + t

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

ans += (end - now)

print(ans)

Solution (Python):

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

Solution (Python):

n, t = list(map(int, input().rstrip().split()))
lst = list(map(int, input().rstrip().split()))
ans, cur, lim = 0, 0, 0
for i in lst:
    ans += t if i > lim else i - cur
    cur = i
    lim = cur + t
ans += lim - cur
print(ans)

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

before = float("inf")
ans = 0
for i in t:
    ans += min(T, before - i)
    before = i
print(ans)

Solution (Python):

n, t = [ int(v) for v in input().split() ]
on_list = [ int(v) for v in input().split() ]

total = 0
part = t
for i in range(n-1):

	if on_list[i+1] > on_list[i] + t:
		total+= part
		part = t
	else:
		part += on_list[i+1] - on_list[i]
total+= part
print(total)

Solution (Python):
n,t=map(int,input().split())
ts=list(map(int,input().split()))
time=0
t_=10**10
for i in range(n):
     t__=ts.pop()
     if t_-t__>t:
          time+=t
     else:
          time+=(t_-t__)
     t_=t__
print(time)

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

et = t      
tsum = t

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


print(tsum)

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

pre_t = t[0]
cnt = 0
for ti in t[1:]:
	cnt += min([T, ti - pre_t])
	pre_t = ti
cnt += T

print(cnt)

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

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

f = None
p = None
ans = 0
for t in map(int, input().split()):
  if f is None:
    f = t
    p = f - T

  ans += T
  rest = p + T - (t - f)
  if rest > 0:
    ans -= rest
  p = t - f

print(ans)

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

if N == 1:
    print(T)
else:
    ans = 0
    for x, y in zip(t, t[1:]):
        if y-x >= T:
            ans += T
        else:
            ans += y-x
    ans += T
    print(ans)

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

Solution (Python):
import math
import fractions
import copy

def j(q):
    if q==1: print("YES")
    elif q == 0:print("NO")
    exit(0)
rem = pow(10,9)+7
"""
def ct(x,y):
    if (x>y):print("+")
    elif (x<y): print("-")
    else: print("?")
"""

def ip():
    return int(input())
def printrow(a):
    for i in range(len(a)):
        print(a[i])
def combinations(n,r):
    if n<r:return 0
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
def permutations(n,r):
    if n<r:return 0
    return math.factorial(n) // math.factorial(n - r)
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)



n,k= (int(i) for i in input().split())       
a = [int(i) for i in input().split()]        







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

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

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

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

Solution (Python):

import sys

import heapq
import re
import bisect
import random
import math
import itertools
from collections import defaultdict, deque
from copy import deepcopy
from decimal import *

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

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

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

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

print(sum(L) + T)

Solution (Python):
import sys
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
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 II(): return int(sys.stdin.readline())
def SI(): return input()

def main():
    N, T = LI()
    ts = LI()
    ans = 0
    t0 = ts[0]
    for t in ts[1:]:
        ans += min(T, (t - t0))
        t0 = t
    ans += T
    return ans

print(main())

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

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

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

s[-1] = T

print(sum(s))

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


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


print(ans)

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


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


print(ans)

Solution (Python):
from math import factorial
from sys import exit, stdin
N, T = [int(_) for _ in stdin.readline().rstrip().split()]
t_list = [int(_) for _ in stdin.readline().rstrip().split()]
ans = 0
for i in range(N-1):
    if t_list[i+1] - t_list[i] > T:
        ans += T
    else:
        ans += t_list[i+1] - t_list[i]
ans += T
print(ans)

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

Solution (Python):
N, T = [int(i) for i in input().split()]
t = [int(i) for i in input().split()]
t.append(t[-1] + T)

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

Solution (Python):
from collections import Counter
from functools import reduce

import bisect
import copy
import fractions
import math
import pprint

pp = pprint.PrettyPrinter(width = 150)
import random
import sys
import time
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) 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 MI(): return map(int, sys.stdin.readline().split())
def II(): return int(sys.stdin.readline())
def IS(): return input()
def C(x): return Counter(x)
def GCD_LIST(numbers):
    return reduce(fractions.gcd, numbers)
def LCM_LIST(numbers):
    return reduce(LCM, numbers)
def LCM(m, n):
    return (m * n // fractions.gcd(m, n))
def unite(x, y):
    
    x = root(x)
    y = root(y)
    if x == y:
        return
    
    node[x] = y
def same(x,y): return bool(root(x) == root(y))
def root(x):
    if node[x] == x:  
        return x
    else:
        node[x] = root(node[x])  
        return node[x]
def dfs(v):
    
    visited[v] = True
    for v2 in range(n):
        if graph[v][v2] == False:  
            continue
        if visited[v2] == True:  
            continue
        dfs(v2)


N, T = MI()
t = LI()
diff = [max(0, T - (t[i+1] - t[i])) for i in range(0,N-1)]
print(T * N - sum(diff))

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

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

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

print(time)

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

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

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

result = 0
for i, v in enumerate(a[1:], 1):
    result += min(a[i - 1] + t, v) - a[i - 1]
print(result + t)

Solution (Python):
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def solve():
    n , t = f()
    x = f()

    ans = 0

    x.append(3e9)

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

    print(ans)

solve()

Solution (Python):
n,t=map(int,input().split())
ans=0
k=1000000000
for i in map(int,input().split()):
  ans+=min(t,max(i-k,0))
  k=i
ans+=t
print(ans)