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

ans = 0
for i in range(1, N):
    ans += min(A[i] - A[i-1], T)
ans += 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())
t = [int(x) for x in input().split()]
stop, ans = 0, T * N

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

Solution (Python):
n,t=map(int,input().split())
T=[int(i) for i in 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 = map(int, input().split())
t = list(map(int, input().split()))
X = T

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

print(X)

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

st = 0
now = 0
for ti in tn:
  st += t - max(0, (now - ti))
  now = ti + t
  
print(st)

Solution (Python):
import sys
import copy
import  math
from _bisect import *
from collections import *
from operator import itemgetter
from math import factorial
"""
from fractions import gcd
def lcm(x, y):
    return (x * y) // gcd(x, y)
"""
stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

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

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

print(total)

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

X = 0

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

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

ans = T

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

print(ans)

Solution (Python):
import bisect


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

ans = 0
start = 0
end = 0

for i, t in enumerate(ts):
    if i == 0:
        start, end = t, t + T
        continue

    
    if t <= end:
        end = t + T
    else:
        ans += (end - start)
        start, end = t, t + T

ans += (end - start)
print(ans)

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

t = [int(i) for i in input().split()]

ans = T
tmp = T

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

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

c=1
d=0
for i in range(n-1):
    z=t[i+1]-t[i]
    if z>=T:
        c+=1
    else:
        d+=z
print(c*T+d)

Solution (Python):
import numpy as np
n,t = list(map(int, input().split()))
s = list(map(int, input().split()))
s_diff = np.diff(s)
print(sum([t if t < s_diff[i] else s_diff[i] for i in range(n-1)]) + t)

Solution (Python):



N, T = list(map(int, input().split()))
t_list = list(map(int, input().split()))
total = 0

for i in range(1, N):
    diff = t_list[i] - t_list[i-1]
    if diff < T:
        total += diff
    else:
        total += T
total += T

print(total)

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

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

X += T
print(X)

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

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

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

res = T
now = 0
for i in range(N):
    if  i == 0:
        now = t[i]
        continue
    if now+T <= t[i]:
        res += T
        now =  t[i]
    else:
        res += t[i]-now
        now = t[i]
print(res)

Solution (Python):
from collections import Counter, defaultdict
import sys
sys.setrecursionlimit(10 ** 5 + 10)

from math import factorial
import heapq, bisect
import math
import itertools


def main():
    num, time_lim = map(int, input().split())
    data = list(map(int, input().split()))

    ans = 0
    next_time = 0
    for i in range(num):
        now_time = data[i]
        if now_time >= next_time:
            next_time = now_time + time_lim
            ans += time_lim
        else:
            ans += now_time + time_lim - next_time
            next_time = now_time + time_lim
        
    print(ans)

if __name__ == '__main__':
    main()

Solution (Python):

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

Solution (Python):

import sys
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = lambda *something : print(*something) if DEBUG else 0
DEBUG = False
def main(given = sys.stdin.readline):
    input = lambda : given().rstrip()
    LMIIS = lambda : list(map(int,input().split()))
    II = lambda : int(input())
    XLMIIS = lambda x : [LMIIS() for _ in range(x)]

    N,T = LMIIS()
    people = LMIIS()
    sumtime = T
    pre = people[0]
    for i in range(1,N):
        tmp = people[i]
        sumtime += min(tmp-pre,T)
        pre = tmp
    print(sumtime)

if __name__ == '__main__':
    main()

Solution (Python):
N, T = map(int, input().split())
Timers = [int(i) for i in input().split()]
subTs = [0] * N
for t in range(1, N):
    subTs[t] = Timers[t] - Timers[t - 1]

score = T * N
time = T
for i in range(1, N):
    
    if subTs[i] < time:
        lost = T - subTs[i]
        score -= lost
print(score)

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

dup_time = 0

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

print(N*T - dup_time)

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

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

ans+=T

print(ans)

Solution (Python):
from collections import defaultdict, deque
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate
import sys


def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LIM(): return list(map(lambda x:int(x) - 1, sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def LIRM(n): return [LIM() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
mod = 1000000007



n, t = LI()
nums = LI()


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


print(ret)

Solution (Python):

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

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

sum += t
print(sum)

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

N, T = map(int, input().split())
L = [int(v) for v in input().split()]

ans = 0
pos = 0
for i in range(N):
    v = L[i]
    if pos > v:
        ans += v + T - pos
    else:
        ans += T

    pos = v + T

print(ans)

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

ans+=t
print(ans)

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

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

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

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

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

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

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

for tt in t:
  if current <= tt:
    current = tt+T
    sum += T
  else:
    diff = current - tt
    current = tt+T
    sum += T - diff
print(sum)

Solution (Python):
import numpy
n, t = map(int, input().split())
a = numpy.array(list(map(int, input().split())))
a = a[1:] - a[:n-1]
a[a > t] = t
print(a.sum() + t)

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

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

ans = T
tmp = 0

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

print(ans)

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

x = N*T
p = 0

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

print(x-p)

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

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

print(ans)

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

ans = T
tmp = 0

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

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

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

Solution (Python):
n, t = map(int, input().split())
a = tuple(map(int, input().split()))
b = tuple(a_ato - a_mae for a_ato, a_mae in zip(a[1:], a))
print(sum(map(lambda x: min(x, t), b)) + t)

"""
最後の人が出したシャワーは、時間いっぱい出る
それ以前の人が出したシャワーは、
時間いっぱいか、次の人が押すまでの時間のうち、短い時間だけ出る
"""

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

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

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

ans = T
whenFinish = T
for t in TList:
    if t >= whenFinish:
        ans += T
        whenFinish = t + T
    else:
        ans += T - (whenFinish - t)
        whenFinish = t + T

print(ans)

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

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

s = 0
f = 0
res = 0

for e in a:
    if e <= f:
        f = e+t
    else:
        res += f-s
        s = e
        f = s+t
res += f-s
print(res)

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

Solution (Python):
N,T = map(int,input().split())
Sum = []
lis = list(map(int,input().split()))
for i in range(N-1):
  Sum.append(lis[i+1]-lis[i])
for k in range(len(Sum)):
  if Sum[k] > T:
    Sum[k] = T
print(sum(Sum)+T)

Solution (Python):
import sys


		
def main():
	n,t = map(int, input().split())
	tl=list(map(int, input().split()))
	
	counter=0
	pre_end=0
	for ti in tl:
		if ti < pre_end:
			counter+=t+ti-pre_end
		else:
			counter+=t
		
		pre_end=ti+t
	
	print(counter)
	
	



if __name__ == "__main__":
	if sys.platform =='ios':
		sys.stdin=open('inputFile.txt')
	else:
		pass
		
			
	ret = main()
	if ret is not None:
		print(ret)

Solution (Python):
import sys
sys.setrecursionlimit(1000000)
from math import factorial, ceil, floor
from bisect import bisect_right as bsr
from operator import itemgetter as ig
from collections import defaultdict as dd
from collections import deque, Counter as cnt


args = None
INF = float("inf")
MOD = int(1e9 + 7)
def input(*ps):
    if type(ps[0]) is list:
        return [input(*ps[0][:-1]) for _ in range(ps[0][-1])]
    elif len(ps) == 1:
        return ps[0](next(args))
    else:
        return [p(next(args)) for p in ps]
def nlist(n, v):
    if not n: return v.copy()
    return [nlist(n[1:], v) for _ in range(n[0])]


class BIT:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)
    def sum(self, i):
        s = 0
        while 0 < i:
            s += self.tree[i]
            s %= MOD
            i -= i & -i
        return s
    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i


def main():
    N, T = input(int, int)
    A = input([int, N])

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

if __name__ == '__main__':
    args = iter(sys.stdin.read().split())
    main()

Solution (Python):


import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N, T = MAP()
A = LIST()

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

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

total=t
for i in range(1,len(Ts)):
    if(Ts[i] - Ts[i-1]>t):
        total += t
    else:
        total += Ts[i] - Ts[i-1]

print(total)

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

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

print(res)

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

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

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

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

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

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

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

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

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

print(total+T)

Solution (Python):











import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,log 
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf=float('inf')
mod = 10**9+7
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N,Time = MI()
    T=LI()
    ans = 0
    end = -1
    for t in T:
        if end < t:
            ans += Time
            end = t+Time
        else:
            ans += t+Time-end
            end = t + Time
    print(ans)
if __name__ == '__main__':
    main()

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

ans = 0

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

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

out = 0



for i in range(n-1):
    if tl[i+1] < tl[i]+t:
        out += tl[i+1]-tl[i]
    elif tl[i+1] >= tl[i]+t:
        out += t

out += t


if n == 1:
    out = t

print(out)

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

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

print(time)

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

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

for t in ts:
  if t <= end:
    end = t + T
  else:
    anser += end - start
    end = t + T
    start = t
print(anser + end - start)

Solution (Python):
import numpy as np
import bisect
from operator import itemgetter
import math
import functools
import itertools
import numpy as np
import sys
MAX_INT = int(10e10)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N,T = IL()
t = IL()

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

print(ans)

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

def main():
    _,T = map(int, input().split())
    P = list(map(int, input().split()))
    ans = start = end = 0
    for p in P:
        if start == 0 and end == 0:
            end = T
        else:
            if p < end:
                end = p + T
            else:
                ans += end - start
                start = p
                end = p + T
    ans += end - start
    print(ans)

if __name__ == '__main__':
    main()

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

Solution (Python):
import copy

def j(n):
    if n:print("Yes")
    else:print("No")
    exit(0)
rem = 10 ** 9 + 7

"""
def ct(x,y):
    if (x>y):print("+")
    elif (x<y): print("-")
    else: print("?")
"""

def ip():
    return int(input())
def iprow():
    return [int(i) for i in input().split()]
def ips():
    return (int(i) for i in input().split())
def printrow(a):
    for i in a:
        print(i)

n ,m = ips()
a = iprow()
s = 0
for i in range(n-1):
    if a[i+1]-a[i]>=m:
        s+=m
    else:
        s+=a[i+1]-a[i]

print(s+m)

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

Solution (Python):
def c_sentou():
    N, T = [int(i) for i in input().split()]
    Times = [int(i) for i in input().split()] + [float('inf')]  
    return sum([min(T, Times[i + 1] - Times[i]) for i in range(N)])

print(c_sentou())

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

print(ans[2]+(ans[1]-ans[0]))

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

for i in range(n-1):
    tElapse = tList[i+1] - tList[i]
    tSum += (t if tElapse > t else tElapse)

print(tSum)

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

for i in range(n-1):
    if tList[i+1] - tList[i] > t:
        tSum += t
    else:
        tSum += tList[i+1] - tList[i]

print(tSum)

Solution (Python):
N, T, *V = map(int, open(0).read().split())
wa = 0
prev = 0
for i in range(N):
  if(V[i] - prev < T):
    wa += V[i] - prev
  else:
    wa += T
  prev = V[i]
  pass
wa += T
print(wa)

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

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

time = []
for i in range(1, N):
    sub = t[i] - t[i-1]
    time.append(min(sub, T))

time.append(T)

print(sum(time))

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

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

print(cnt+T)

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

Solution (Python):
import sys
import heapq
from operator import itemgetter
from collections import deque, defaultdict, Counter
from bisect import bisect_left, bisect_right
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
MOD = 10**9 + 7
INF = float('inf')

def sol():
    N, T = map(int, input().split())
    push = list(map(int, input().split())) + [INF]

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

    print(ans)


sol()

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

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

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

print(ans)

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

print(ans)

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

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

res = 0
prev_t = -T
for t in X:
  res += min(T, t - prev_t)
  prev_t = t

print(res)

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

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


if __name__ == '__main__':
    AtCoder().main()

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

Solution (Python):
import sys
n, t = [int(i) for i in sys.stdin.readline().split()]
t_ls = [int(i) for i in sys.stdin.readline().split()]
diff_ls = []
for i in range(len(t_ls)-1):
    diff = t_ls[i+1] - t_ls[i]
    if diff > t:
        diff_ls.append(t)
    else:
        diff_ls.append(diff)
print(sum(diff_ls) + t)

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

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

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

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

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

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

print(ans)

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

ans = T * N

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

print(ans)

Solution (Python):
N,T= list(map(int, input().split()))
t= list(map(int, input().split()))
ans=T
before=t.pop(0)
for i in t:
    if i-before>=T:
        ans+=T
    else:
        ans+=i-before
    before=i
print(ans)

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

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

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

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

Solution (Python):
nt=input().split()
n ,t = int(nt[0]),int(nt[1])
tlist=[int(x) for x in input().split()]

pretick =0
total=0
for tick in tlist:
  if tick==0:
    total+=t
  else:
    if pretick + t > tick:
      total+=(tick-pretick)

    else:
      total+=t
  pretick=tick

print(total)

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

print(ans)

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

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

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

t.append(1145141919810)
ans = 0

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

print(ans)

Solution (Python):
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)

print(ans + T)

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

ans = 0
pre = 0
for a in A:
    ans += min(a - pre, T)
    pre = a
print(ans + T)

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

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

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

Solution (Python):
_,T,b,*t=map(int,open(0).read().split())
a=T
for i in t:a+=min(i-b,T);b=i
print(a)

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

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



print (ans + T)

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

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

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


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


print(ans)

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

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

print(ans)

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

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

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

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