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):
numbers = list(map(lambda x: int(x), input().split()))
nums = list(map(lambda x: int(x), input().split()))
t = numbers[1]

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

print(total)

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

"""
Created on Sun Sep 27 03:05:21 2020

@author: liang
"""

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

time = [int(x) for x in input().split()]

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

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

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

ans += T
print(ans)

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

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

prev,now,ans = T[0],0,0

for i in range(n):
    if not i:
        continue
    now = T[i]
    if now-prev > t:
        ans += t
    else:
        ans += now-prev
    prev = now
ans += t
print(ans)

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

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

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

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

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

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

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

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

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

print(T+ans)

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

Solution (Python):
import math
from math import gcd,pi,sqrt
INF = float("inf")

import sys
sys.setrecursionlimit(10**6)
import itertools
from collections import Counter,deque
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]

def main():
    N,T = i_map()
    t = i_list()

    ans = 0
    for i,k in enumerate(t[1:], start=1):
        if k - t[i-1] <= T:
            ans += k - t[i-1]
        else:
            ans += T
    ans += T
    print(ans)



if __name__=="__main__":
    main()

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

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

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

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

print(ans)

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

print(res)

Solution (Python):
def main():
    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
    print(ans + T)


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

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

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

print(ans)

Solution (Python):

def main():
    n, t = map(int, input().split())
    s = list(map(int, input().split()))
    cnt = n*t

    for i in range(n-1):
        if s[i+1] - s[i] < t:
            cnt -= s[i]+t-s[i+1]
    else:
        print(cnt)


if __name__ ==  "__main__":
    main()

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

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

ans = P[-1] + T
quit = 0
for p in P:
    if quit < p:
        ans -= p - quit
    quit = p + T

print(ans)

Solution (Python):
import sys, re
from math import ceil, floor, sqrt, pi, factorial, gcd
from copy import deepcopy
from collections import Counter, deque
from heapq import heapify, heappop, heappush
from itertools import accumulate, product, combinations, combinations_with_replacement
from bisect import bisect, bisect_left, bisect_right
from functools import reduce
from decimal import Decimal, getcontext

def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 6)
INF = float('inf')
MOD = 10 ** 9 + 7
num_list = []
str_list = []

def main():
    n, t = i_map()
    num_list = i_list()

    ans = n * t

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

    print(ans)

if __name__ == '__main__':
    main()

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

Solution (Python):
N, T, *t = map(int, open(0).read().split())
ans = sum(y-x if y-x < T else T for x,y in zip(t[:N-1],t[1:])) + T
print(ans)

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

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

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

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


print(ans)

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

ans = n*k
for i in range(1, n):
    diff = k - min(t[i] - t[i-1], k)
    ans -= diff
print(ans)

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

ans = 0

for i in range(n):
    if i == n-1:
        ans += m
    elif t[i+1] - t[i] > m:
        ans += m
    else:
        ans += t[i+1] - t[i]

print(ans)

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

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

accumulate += t
print(accumulate)

Solution (Python):



import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """2 4
0 3"""
        output = """7"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """2 4
0 5"""
        output = """8"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """4 1000000000
0 1000 1000000 1000000000"""
        output = """2000000000"""
        self.assertIO(input, output)

    def test_入力例_4(self):
        input = """1 1
0"""
        output = """1"""
        self.assertIO(input, output)

    def test_入力例_5(self):
        input = """9 10
0 3 5 7 100 110 200 300 311"""
        output = """67"""
        self.assertIO(input, output)


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

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

    print(ans)


if __name__ == "__main__":
    
    resolve()

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=input().split()
a=int(a)
b=int(b)
c=list(map(int,input().split()))
m=a*b
for i in range(a-1):
  if c[i+1]-c[i]<b:
    m=m-(b-(c[i+1]-c[i]))
print(m)

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

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

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

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

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

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

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

total = t
time = 0
for i in arr[1:]:
    total += min(t, (i - time))
    time = i

print(total)

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

T_start = 0
T_end = T
T_total = 0

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

T_total += T_end - T_start

print(T_total)

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

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

sum = 0
for i in range(len(tn)):
  if i < len(tn)-1:
    if tn[i]+t < tn[i+1]:
      sum += t
    else :
      sum += tn[i+1] - tn[i]
  else :
    sum += t

print(sum)

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])
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]+T <= t[i+1]:
    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
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 = [int(x) for x in input().split()]
pre = 0
ans = T
for t in t_List:
    if t - pre <= T:
        ans += t - pre
    else:
        ans += T
    pre = t
print(ans)

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

nums = [0]*(n-1)
for i in range(n-1): nums[i] = l[i+1] - l[i]

ans = t
m = 0
for i in nums:
  ans += min(i,t)
print(ans)

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

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

dt = []
for i in range(N - 1):
  dt.append(t[i + 1] - t[i])
else:
  dt.append(T)

print(sum([min([dti, T]) for dti in dt]))

Solution (Python):
'''
Created on 2020/08/16

@author: harurun
'''
N,T=map(int,input().split())
t=list(map(int,input().split()))
ans=T
s=t[0]
for i in range(1,N):
  if t[i]-s>=T:
    ans+=T 
  else:
    ans-=T-(t[i]-s)
    ans+=T
  s=t[i]
print(ans)

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

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

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

s = n * t
for i in range(1,n):
    if T[i] - T[i-1] < t:
        s -= (t-(T[i]-T[i-1]))
print(s)

Solution (Python):
import sys
from collections import deque
def input(): return sys.stdin.readline().strip()

def main():
    N, T = map(int, input().split())
    A = deque(map(int, input().split()))
    time = 0
    start = 0
    stop = 0
    while A:
        a = A.popleft()
        if stop < a:
            time += stop - start
            start = a
            stop = a + T
        else:
            stop = a + T
    print(time + stop - start)


if __name__ == "__main__":
    main()

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

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

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

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

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

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

ans=0
for i in range(N):
  if i == 0:
    start = t[i]
    finish = t[i]+T
    continue
    
  if t[i]<finish:
    finish = t[i]+T
    continue
    
  else:
    ans += finish - start
    start = t[i]
    finish = t[i]+T
    
ans += finish - start

print(ans)

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

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

ans, now = 0, 0
for i in t:
    if i < now:
        ans -= now - i
    ans += T
    now = i + T
print(ans)

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

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

Solution (Python):
N,K = (int(T) for T in input().split())
Per = [int(T) for T in input().split()]
Wat = 0
for X in range(0,N-1):
    if Per[X]+K<=Per[X+1]:
        Wat += K
    else:
        Wat += Per[X+1]-Per[X]
print(Wat+K)

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

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

Solution (Python):
N,T=map(int,input().split())
t=list(map(int,input().split()))
t.append(10**10)
ans=0
flg=0
temp=0

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

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

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

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

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

    if t[i] - t[i-1] < T:
        ans += t[i] - t[i-1]
    else:
        ans += T

ans += T
print (ans)

Solution (Python):
N, T = [int(x) for x in input().split()]
t_list = [int(x) for x in input().split()]
t_s = t_e = ans = 0
for t in t_list:
    if t > t_e:
        ans += t_e - t_s
        t_s = t
    t_e = t + T
ans += t_e - t_s
print(ans)

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

print(ans+T)

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

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

print(ans+T)

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

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

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

Solution (Python):
import math

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

Solution (Python):
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, T, *t = map(int, read().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
    ans += T

    print(ans)

    return


if __name__ == '__main__':
    main()

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

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

print(ans+T)

Solution (Python):
from sys import stdin

def main():
    N,T=map(int,stdin.readline().strip().split())
    t=list(map(int,stdin.readline().strip().split()))

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

if __name__=='__main__':
    main()

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

res = 0
time = 0
for v in t:
    if v < time:
        res += T - time + v
        time += T - time + v
    else:
        res += T
        time = T + v

print(res)

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

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

print(sum(d)+T)

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

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

Solution (Python):
import numpy as np


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


if __name__ == "__main__":
    main()

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

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

print(a)

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

ans=0

for t_idx in range(len(A)-1):
    if A[t_idx] + T <= A[t_idx+1]:
        ans += T
    else:
        ans += A[t_idx+1]-A[t_idx]
ans+=T

print(ans)

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

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

ans = T

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

print(ans)

Solution (Python):
import sys
import math
import itertools
import bisect
from copy import copy,deepcopy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(map(int,input().split()))
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
INF = 10**9
mod = 10**9+7

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

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

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

print(ans)

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

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

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

for i in l:
    now = i
    
    if now-latest >= t:
        ans += t
    else:
        ans += now-latest
    
    latest = now
ans += t
print(ans)

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

ans = 0
now = 0
for i in ts[1:]:
    if i<=now+t:
        ans += i-now
    else:
        ans += t
    now = i
print(ans+t)

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

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

Solution (Python):
import sys
sys.setrecursionlimit(500000)
MOD = 10**9+7

def input():
    return sys.stdin.readline()[:-1]

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]


def main():
    N, T = mi()
    t = list(mi())
    l = [max(t[i+1]-t[i]-T, 0) for i in range(N-1)]
    print(t[-1]+T-sum(l))


if __name__ == '__main__':
    main()

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

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

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

ans=t[-1]+T

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

print(ans)

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

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

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

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

N,T = list(map(int,input().split()))
t = list(map(int,input().split()))
t_stop = []
for i in range(N):
    t_stop.append(t[i]+T)
cum_flow = T*N
for i in range(N-1):
    cum_flow -= max(t_stop[i] - t[i+1],0)
print(cum_flow)

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())
t = list(map(int, input().split()))
dt = [0 for _ in range(n-1)]

for i in range(n-1):
    dt[i] = t[i+1]-t[i]

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

print(ans+T)

Solution (Python):
N,T = map(int,input().split())
t = list(map(int,input().split()))
ans = 0
for i in range(N-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, os, math, bisect, itertools, collections, heapq, queue

from decimal import Decimal
from collections import defaultdict, deque



sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)


MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N, T = il()
    time = il()

    ret = T
    for n in range(N-1):
        ret += min(abs(time[n] - time[n + 1]), T)
    print(ret)


if __name__ == '__main__':
    main()

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

ans = 0
tmp = 0

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

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

S = N*T

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

print(S)

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

st += [10**10]
t1 = 0
t2 = 0
ans = 0
for ti in st:
  if t2 < ti:
    ans += t2-t1
    t1 = ti
  t2 = ti+t
print(ans)