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

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

print(cnt+T)

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

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

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):
import sys
import collections
ns = lambda: sys.stdin.readline().rstrip()
ni = lambda: int(ns())
nm = lambda: map(int, sys.stdin.readline().split())
nl = lambda: list(nm())
nsl = lambda: map(str, sys.stdin.readline().split())


n, T = nm()
t = nl()
count = 0
for i in range(1, n):
    if t[i] - t[i - 1] > T:
        count += t[i] - t[i - 1] - T
print(t[-1] + T - count)

Solution (Python):

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

Solution (Python):
from functools import reduce
import math

def main():
    
    
    
    

    
    
    
    
    
    
    
    
    
    
    
    
    
    

    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    

    
    
    
    
    N,T = (int(_) for _ in input().split())
    t = list(int(_) for _ in input().split())
    sum = T
    for i in range(1,N):
        if(t[i]-t[i-1] > T):
            sum += T
        else:
            sum += t[i]-t[i-1]
    print(sum)
if __name__ == '__main__':
    main()

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

Solution (Python):
import sys
fastinput=sys.stdin.readline
N,T=map(int,fastinput().split())
p=[int(_) for _ in fastinput().split()]
oyumin=0
oyumax=0
Showertime=0
for i in p:
    if i>oyumax:
        Showertime+=oyumax-oyumin
        oyumin=i
        oyumax=i+T
    else:
        oyumax=i+T
Showertime+=oyumax-oyumin
print(Showertime)

Solution (Python):
import sys
fastinput=sys.stdin.readline
N,T=map(int,fastinput().split())
p=[int(_) for _ in fastinput().split()]
oyumin=0
oyumax=0
Showertime=0
for i in p:
    if i>oyumax:
        Showertime+=oyumax-oyumin
        oyumin=i
        oyumax=i+T
    else:
        oyumax=i+T
Showertime+=oyumax-oyumin
print(Showertime)

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

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

print(total)

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

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

ans = 0
for i in range(N):
 if(i != N-1):
  if(X[i]<X[i+1]<X[i]+T): ans += X[i+1] - X[i]
  else: ans += T
 elif(i == N-1):
  ans += T
print(ans)

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

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

print(sum([min(T,b-a) for a,b in zip(t[:-1],t[1:])]))

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

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

print(N*T-res)

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

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

if n == 1:
    print(t)
    exit()

pre = time[0]

for i in range(n):
    if i == 0:
        pass
    else:
        dist = time[i] - pre
        if dist > t:
            ans += t
        else:
            ans += dist
        if i == n-1:
            ans += t
        pre = time[i]

print(ans)

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

res = T
pre = t[0]
for i in t[1:]:
    if i < pre + T:
        res += i - pre
    else:
        res += T
    pre = i

print(res)

Solution (Python):
N, T = map(int, raw_input().split())
t = map(int, raw_input().split())
res = N * T
for t1, t2 in zip(t[:-1], t[1:]):
  if t2 - t1 > T:
    continue
  dup = t1 + T - t2
  res -= dup
print res

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

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

Solution (Python):
N,T = map(int,input().split())
L = input().split()
M = list(map(int,L))
s = M[N-1]
M.append(s)
ans = 0
c = 0
k = 0
while c<N:
  if M[c]+T >= M[c+1]:
    c += 1
    k += 1
  else:
    if k == 0:
      ans += T
      c += 1
    else:
      ans += T+M[c]-M[c-k]
      c += 1
      k = 0
ans += T+M[c]-M[c-k]
print(ans)

Solution (Python):


"""
Created on Sun Feb 10 10:05:08 2019

@author: shinjisu
"""



def getInt(): return int(input())


def getIntList(): return [int(x) for x in input().split()]


def dmp(x):
    global debug
    if debug:
        print(x)


def probC():
    N, T = getIntList()
    Ts = getIntList()
    dmp((N, T, Ts))
    total = Ts[0]
    for i in range(1, N):
        total += min(T, Ts[i]-Ts[i-1])
    return total+T


debug = False
print(probC())

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

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

Solution (Python):



import array
from bisect import *
from collections import *
import fractions
import heapq
from itertools import *
import math
import random
import re
import string
import sys

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

prev = None
ans = 0
for t in map(int, input().split()):
    if prev is not None:
        if t - prev < T:
            ans += t - prev
        else:
            ans += T
    prev = t
ans += T
print(ans)

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

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

ans = 0

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

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

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

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

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

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

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

Solution (Python):
def inpl(): return [int(i) for i in input().split()]
N, T = inpl()
t = inpl()+[10**10]
back = 0
ans = 0
for i in t:
    if back + T >= i:
        ans +=  i - back
    else:
        ans += T
    back = i
print(ans)

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

print(ans)

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

Solution (Python):
import sys
import collections
import math
from collections import Counter
from collections import deque


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


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

total += finish - start

print(total)

sys.exit(0)

Solution (Python):

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

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

print(score)

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

	print(s)

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

print(time)

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

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

Solution (Python):
from sys import exit, setrecursionlimit, stderr
from functools import reduce
from itertools import *
from collections import *
from bisect import *
from heapq import *

def read():
  return int(input())
 
def reads():
  return [int(x) for x in input().split()]

N, T = reads()
t = reads() + [1 << 60]

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

Solution (Python):


line =  input().split()
n = int(line[0])
T = int(line[1])
t = [int(x) for x in input().split()]

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

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

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

result = 0

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

result += T

print(result)

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

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


import sys, math, copy





HUGE = 2147483647
HUGEL = 9223372036854775807
ABC = "abcdefghijklmnopqrstuvwxyz"

def main():
    n, t = map(int, input().split())
    tn = list(map(int, input().split()))
    assert len(tn) == n
    su = 0
    till = 0
    for i in range(n):
        su += min(t, tn[i] + t - till)
        till = tn[i] + t
    print(su)

main()

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

ans = 0
tmp = t[0]
for t_i in t[1:]:
    ans += min(T, t_i-tmp)
    tmp = t_i
ans += T

print(ans)

Solution (Python):
while True:
	try:
		ins = input().split(" ")
		N = int(ins[0])
		T = int(ins[1])
		a = []
		inx = input().split(" ")
		for i in range(0, N):
			a.append(int(inx[i]))
		ans = 0
		end = 0
		for x in range(0, N):
			if a[x] < end:
				 ans = ans + a[x] + T - end
				 end = a[x] + T
			elif a[x] > end:
				ans += T
				end = a[x] + T
			else:
				ans += T
				end += T
		print(ans)
	except:
		break

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

Solution (Python):
n,t=map(int,input().split())
o=0
a=0
for s in input().split():
  i=int(s)
  if i+t>o:
    a+=i+t-max(o,i)
  o=i+t
print(a)

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

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

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

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

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

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

OYUSUM = 0
now = P[0]
for t in P[1:]:
    if t-now<T:
        OYUSUM+=t-now
        now = t
    else:
        OYUSUM+=T
        now = t
    
OYUSUM+=T
    
print(OYUSUM)

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

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

Solution (Python):
n, t = [int(x) for x in raw_input().split()]
s = 0
l = 0
for ti in [int(x) for x in raw_input().split()] + [float("inf")]:
  if ti - l < t:
    s += ti - l
  else:
    s += t
  l = ti

print(s)

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

Solution (Python):


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

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

ts.append(10**10)

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

print(ans)

Solution (Python):

def inpl(): return list(map(int, input().split()))

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

Solution (Python):
INF = 10**10

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

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

print(res)

Solution (Python):
data = input()
data = data.split(" ")

n_large = int(data[0])
t_large = int(data[1])

data = input()
data = data.split(" ")
ts = []
for d in data:
	ts.append(int(d))

max = ts[n_large - 1] + t_large
decrease = 0
for i in range(0, n_large - 1):
	a = ts[i + 1] - ts[i]
	if a > t_large:
		b = a - t_large
		decrease += b
print(max - decrease)

Solution (Python):


NT = input()
tn = input()

NT = NT.split()
tn = tn.split()

N = int(NT[0])
T = int(NT[1])
X = 0

if N == 1:
	print(T)

else:
	for i in range(N):
		if i == N-1:
			X += T
		else:
			if int(tn[i+1])-int(tn[i]) <= T:
				X += int(tn[i+1])-int(tn[i])
	
			else:
				X += T
		
	print(X)

Solution (Python):

data1 = input().split(" ")
N=int(data1[0])
T=int(data1[1])
data2 = input().split(" ")
t = [int(i) for i in data2]
sum = 0
i=0

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

Solution (Python):

data = input()
data = data.split(" ")

n_large = int(data[0])
t_large = int(data[1])

data = input()
data = data.split(" ")
ts = []
for d in data:
    ts.append(int(d))


ts.sort()

total = ts[0]
for i in range(1, len(ts)):
    buf = ts[i] - ts[i - 1]
    if buf > t_large:
        total += t_large
    else:
        total += buf

total += t_large

print(total)

Solution (Python):



nt = raw_input()
nt = nt.split()
n,t = map(int,nt)

p = raw_input()
p = p.split()
p = map(int,p)

ans = 0

i = 0
while i < n-1:
    if p[i+1] - p[i] > t:
        ans += t
    else:
        ans += p[i+1]-p[i]
    i += 1

ans += t

print ans

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






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

Solution (Python):
import numpy as np

N,T = [int(_) for _ in input().split()]
t = [int(_) for _ in input().split()]
sum = 0
last_time=0
for time in t:
    if time - last_time >= T:
        sum += T
    else:
        sum += time-last_time
    last_time = time
sum += T
print (sum)

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

Solution (Python):



N, T = map(int, raw_input().split(' '))
t = map(int, raw_input().split(' '))
assert len(t) == N

sum_ = 0
begin = t[0]
end = t[0] + T
for i in range(N):
    if t[i] <= end:
        end = t[i] + T
    else:
        sum_ += (end - begin)
        begin = t[i]
        end = t[i] + T

sum_ += (end - begin)
print sum_

Solution (Python):
n, t = [int(x) for x in input().split(' ')]
time = [int(x) for x in input().split(' ')]
diff = [time[j+1]-time[j] for j in range(n-1) if time[j+1] - time[j] > t]
dec = sum(diff) - len(diff) * t
print(time.pop() + t - dec)

Solution (Python):


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

ans = 0
end_time = 0
for i in range(n):
    if end_time <= times[i]:
        ans += t
        end_time = times[i] + t
    else:
        ans += max(0, times[i] + t - end_time)
        end_time = max(times[i] + t, end_time)

print(ans)

Solution (Python):
input_lines = input().split(" ")
N = int(input_lines[0])
T = int(input_lines[1])

times = [int(x) for x in input().split(" ")]
elapsed = 0
oyu = T
for i in range(1,N):
    if times[i] > times[i-1] + T:
        oyu = oyu+T
    else:
        oyu = oyu+times[i]-times[i-1]
        
print(oyu)

Solution (Python):
def main():
    line = input()
    line = line.split(' ')
    n = int(line[0])
    t = int(line[1])
    line = input()
    line = line.split(' ')
    total = 0
    for i in range(1, n):
        total += min(t, int(line[i]) - int(line[i - 1]))
    print(total+t)


if __name__ == '__main__':
    main()

Solution (Python):
def sol(t, tis):
    flow = 0
    ret = 0
    for ti in tis:
        ret += min(ti + t - flow, t)
        flow = ti + t

    return ret


if __name__ == "__main__":
    n, t = map(int, raw_input().strip().split())
    tis = map(int, raw_input().strip().split())
    print sol(t, tis)

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

tsum = T
for i in range(N-1):
    t1 = tlist[i]
    t2 = tlist[i+1]
    tdif = t2 - t1
    if tdif >= T:
        tsum += T
    else :
        tsum += tdif

print(tsum)

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

t_sum=0
for i in range(N-1):
    t_span = t_list[i+1]-t_list[i]
    if t_span<T:
        t_sum+=t_span
    else:
        t_sum+=T
t_sum+=T
print str(t_sum)

Solution (Python):
people,time = (int(n) for n in input().split(" "))
turn = [int(n) for n in input().split(" ")]
answer = 0
for i,t in enumerate(turn):
    if i == people - 1:
        answer += time
    else:
        if turn[i + 1] - turn[i] >= time:
            answer += time
        else:
            answer += (turn[i + 1] - turn[i])
print(answer)

Solution (Python):
N, T = map(int, input().split())
t = list(map(int, input().split()))
tt = list(zip(t[:-1], t[1:]))
x = T
for t0, t1 in tt:
    x += min(T, t1 - t0)
print(x)

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


for diff in [ts[ind+1]-ts[ind] for ind in range(N-1)]:
    ret += T if T<diff else diff
print(ret)

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





ret = sum([min(T, ts[ind+1]-ts[ind]) for ind in range(N-1)])
print(ret+T)

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





ret = sum([T if T < ts[ind+1]-ts[ind] else ts[ind+1]-ts[ind] for ind in range(N-1)])
print(ret+T)

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


for diff in [ts[ind+1]-ts[ind] for ind in range(N-1)]:
    ret += T if T<diff else diff
print(ret+T)

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


for diff in [ts[ind+1]-ts[ind] for ind in range(N-1)]:
    ret += min(T,diff)
print(ret+T)

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

Solution (Python):
N,T = [int(i) for i in input().split()]
ts = [int(i) for i in input().split()]
ret = 0
ind = 1
while ind < len(ts):
    ret += min(T,ts[ind]-ts[ind-1])
    ind += 1
print(ret+T)

Solution (Python):
N, T = map( int, input().split() )
t = list( map( int, input().split() ) )
ans = 0
ptr = 0
while ptr < N:
  nxt = ptr + 1
  while nxt < N and t[ nxt ] <= t[ nxt - 1 ] + T:
    nxt += 1
  ans += t[ nxt - 1 ] + T - t[ ptr ]
  ptr = nxt
print( ans )

Solution (Python):
import numpy as np

n, t = map(int, input().split())
ts = np.fromiter(input().split(), dtype=int)
print(sum(np.minimum(np.diff(ts), t)) + t)

Solution (Python):
import sys

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

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

    print(ans)

if __name__ == '__main__':
    solve()

Solution (Python):
n,T=map(int,raw_input().split())
t=map(int,raw_input().split())
ans=0
now=0
for i in xrange(n):
    if t[i]<=now:
        ans+=t[i]+T-now
        now=t[i]+T
    else:
        ans+=T
        now=t[i]+T
print ans

Solution (Python):
import sys

cin = sys.stdin

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

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

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

summary = 0
time_until = 0
for t in t_list:
    if(time_until <= t):
        summary += T
    else:
        summary += t + T - time_until
    time_until = t + T

print(summary)

Solution (Python):



n,t=map(int,input().split())
a=[int(i) for i in input().split()]
ans=chk=0
for i in a:
    if chk<=i:
        ans=ans+t
        chk=i+t
    else:
        ans=ans+((i+t)-chk)
        chk=chk+((i+t)-chk)

print(ans)

Solution (Python):
from operator import sub
n, t = map(int, input().split())
res = t
temp = list(map(int, input().split()))
for v in map(sub, temp[1:], temp):
  res += min(t, v)
print(res)

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

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

print(ret)

Solution (Python):



from random import *
from functools import reduce,partial
from time import time

def readln():
    return list(map(int,input().split(' ')))

def identity(x):
    """Return the input itself."""
    return x

def constant(c):
    """Return an function which always
    returns the input constant c."""
    def const_function(const,*args):
        return const
    return partial(const_function,c)

def inc(c = 1):
    """Return a function which reads an input x and returns x + c as output.
    By default, c equals 1."""
    return lambda x: x + c

def add(*args):
    """Return the sum of the input."""
    def add2(x,y): return x + y
    return reduce(add2,args)

def mapv(f,*lst):
    """Return a vector of the result of map."""
    return list(map(f,*lst))

def vector(*args):
    """Return a vector of input parameters."""
    return args

def sequence(n,f = constant(0)):
    """Return a vector of length n, and initialize the i'th
    item with f(i).By default the vector will initialized with 0."""
    return [f(i) for i in range(0,n)]

def matrix(n,m,f = constant(0)):
    """Return a 2-dim vector which contains n vectors with length m.
    The j's item of vector i will be initialized by f(i,j).By default,
    the vector will be initialized with 0."""
    return [[f(i,j) for j in range(0,m)] for i in range(0,n)]

def flat(v):
    """Return a flat vector which contains the elements of v in their
    origin order.If the input is not a vector, return a vector which
    only contains the input."""
    if not isinstance(v,list): return [v]
    if not v: return []
    return reduce(add,mapv(flat,v))

def partition(v,f = identity):
    """Partition vector v by f(v[i]).
    e.g. partition([1,2,3,1,2,3],identity()) == {1:[1,1,1], 2:[2,2], 3:[3]}
    By default, the vector will be partitioned by identity function."""
    result = {}
    for item in v:
        key = f(item)
        s = result.get(key)
        if s:
            s.append(item)
        else:
            result.update({key:[item]})
    return result

def getValue(key):
    """Return a function which returns the value of key in a hash-map.
    If the key do not exist, it will throw an error."""
    return lambda x: x[key]

def mapValue(f,m):
    """Replace each value in hash-map m with f(value).
    Return the new hash-map."""
    res = {}
    for key in m:
        res.update({key: f(m[key])})
    return res

p = 1000000000 + 7

n,t = readln()
a = readln()
prev = 0
ans = t
for item in a:
    if item > prev + t:
        ans = ans + t
    else:
        ans = ans + item - prev
    prev = item
print(ans)

Solution (Python):

import array, bisect, collections, heapq, itertools, math, random, re, string, sys, time
sys.setrecursionlimit(10 ** 7)
INF = 10 ** 20
MOD = 10 ** 9 + 7
 
 
def II(): return int(input())
def ILI(): return list(map(int, input().split()))
def IAI(LINE): return [ILI() for __ in range(LINE)]
def IDI(): return {key: value for key, value in ILI()}
 
 
def solve(N, T, t):
    ans = 0
    t_dif = [t[i + 1] - t[i] for i in range(N - 1)]
    
    for i in t_dif:
        if i >= T:
            ans += T
        else:
            ans += i
    
    ans += T
    
    return ans

 
def main():
    N, T = ILI()
    t = ILI()
    print(solve(N, T, t))
 
 
if __name__ == "__main__":
    main()

Solution (Python):

N,T=map(int,raw_input().split())
t=map(int,raw_input().split())

sum=0
for i,v in enumerate(t):
	if i==0:pass
	elif (v-t[i-1])>=T:sum+=T
	else:sum+=v-t[i-1]

print sum+T

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

    i = 0
    x = 0
    while i < N - 1:
        t2 = t[i+1] - t[i]
        if t2 < T:
            x += t2
        else:
            x += T
        i += 1
    print(x + T)

main()

Solution (Python):

def input_str(row):
    res = []
    for _ in range(row):
        res.append(raw_input().split())
    return res

ipt = input_str(2)
N, T = [int(i) for i in ipt[0]]
t = sorted([int(i) for i in ipt[1]])

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

print total + T

Solution (Python):



def solve(n, u, ts):
    res = 0
    end = 0
    for t in ts:
        res += min(u - end + t, u)
        end = u + t
    return res


def main():
    n, u = (int(x) for x in input().split())
    ts = [int(x) for x in input().split()]
    print(solve(n, u, ts))


if __name__ == '__main__':
    main()

Solution (Python):
N, T = map(int, input().split())
t = [int(i) for i in input().split()]
ans = 0
s = 0
d = 0
for t_i in t:
	d = max(t_i + T - s, 0)
	ans += min(d, T)
	s = t_i + T
print(ans)

Solution (Python):
n,T=map(int,raw_input().split())
t=map(int,raw_input().split())
i=1
now=T
ans=T
while i<n:
    if t[i]+T<now:
        while t[i]+T<now:
            i+=1
    if t[i]>=now:
        now=t[i]+T
        ans+=T
        i+=1
    elif t[i]+T>=now:
        ans+=t[i]+T-now
        now=t[i]+T
        i+=1
print ans

Solution (Python):


N, T = map(int, raw_input().split())
A = map(int, raw_input().split())

total, start, end = 0, 0, 0
for ai in A:
    if ai > end:
        total += end - start
        start = ai
    end = ai + T

if start < end:
    total += end - start

print total

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

ans = 0
tmp_now = ts[0] + T
tmp_start = ts[0]

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

ans += tmp_now - tmp_start

print(ans)