Problem:
 Score : 300 points    Problem Statement In a public bath, there is a shower which emits water for T seconds when the switch is pushed.  If the switch is pushed when the shower is already emitting water, from that moment it will be emitting water for T seconds.
Note that it does not mean that the shower emits water for T additional seconds.  N people will push the switch while passing by the shower.
The i -th person will push the switch t_i seconds after the first person pushes it.  How long will the shower emit water in total?      Constraints  1 ≤ N ≤ 200,000  1 ≤ T ≤ 10^9  0 = t_1 < t_2 < t_3 < , ..., < t_{N-1} < t_N ≤ 10^9  T and each t_i are integers.         Input Input is given from Standard Input in the following format:  N  T  t_1  t_2 ... t_N       Output Assume that the shower will emit water for a total of X seconds. Print X .        Sample Input 1 2 4
0 3      Sample Output 1 7  Three seconds after the first person pushes the water, the switch is pushed again and the shower emits water for four more seconds, for a total of seven seconds.       Sample Input 2 2 4
0 5      Sample Output 2 8  One second after the shower stops emission of water triggered by the first person, the switch is pushed again.       Sample Input 3 4 1000000000
0 1000 1000000 1000000000      Sample Output 3 2000000000       Sample Input 4 1 1
0      Sample Output 4 1       Sample Input 5 9 10
0 3 5 7 100 110 200 300 311      Sample Output 5 67

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

Solution (Python):
n,T=map(int,input().split())
t=list(map(int,input().split()))
ts=[]
tf=[]
ts.append(t[0])
tb=t[0]
for i in t:
  if(i>tb+T):
    tf.append(tb+T)
    ts.append(i)
  tb=i
tf.append(t[-1]+T)
time=0


for i in range(len(ts)):
  time+=tf[i]-ts[i]
print(time)

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

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

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

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

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

print(cnt)

Solution (Python):
n,T = map(int, input().split())
t = [int(i) for i in input().split()]
ans = T * len(t)
end = 0
for ti in t:
    if ti <= end:
        ans -= end - ti
    end = ti + T
print(ans)

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

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

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

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

Solution (Python):
N,T = map(int,input().split(" "))
t = list(map(int,input().split(" ")))
scope = [[t[0],t[0]+T]]

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

	else:
		scope.append([t[i],t[i]+T])

total = 0
for begin,end in scope:
	total += (end - begin)

print(total)

Solution (Python):
def c_Sentou(N, T, t):
    ans = 0
    for i in range(N):
        if i == N - 1:
            ans += T
            continue
        ans += min(T, t[i + 1] - t[i])
    return ans

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

Solution (Python):

"""
https://abc060.contest.atcoder.jp/tasks/arc073_a

"""
import sys
from sys import stdin
input = stdin.readline


def solve(data, T):
    ans = 0
    prev_d = data[0]
    for d in data[1:]:
        diff = d - prev_d
        ans += min(T, diff)
        prev_d = d
    ans += T
    return ans


def main(args):
    N, T = map(int, input().split())
    data = [int(x) for x in input().split()]
    ans = solve(data, T)
    print(ans)

if __name__ == '__main__':
    main(sys.argv[1:])

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


p = 0
q = 0
total = 0
for x in xs:
    q = max(p, x + t)
    total += (q - max(p, x))
    p = q
print(total)

Solution (Python):
tmp = input()
userInps = tmp.split()

tmp = input()
times = tmp.split()

total = 0


def check(i):
	

	if int(userInps[1]) > int(times[i]) - int(times[i-1]):
		
		n = (int(times[i]) - int(times[i-1]))
		
		
		


	else:
		
		n = int(userInps[1])
		

	
	return n	


for x in range(1,int(userInps[0])):
	
	total += check(x)



total += int(userInps[1])
print(total)

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

Solution (Python):
def LI(): return [int(x) for x in input().split(" ")]
def LS(): return [str(x) for x in input().split(" ")]
def ItoS(L): return [str(x) for x in L]
def StoI(L): return [int(c) for c in L]


def solve():
    n, t = LI()
    T = LI()

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

    print(ans + t)


solve()

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

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

    print(ans)

if __name__ == '__main__':
    main()

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

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

Solution (Python):
num = [int(x) for x in input().split()]
val = [int(x) for x in input().split()]
res = 0

res = max(val)+num[1]
for i in range(1, len(val)):
    res -= abs(val[i]-val[i-1])-num[1] if abs(val[i]-val[i-1])-num[1] > 0 else 0

print(res)

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

i_prev=0
gap=0
for i in t:
	if i-i_prev>T:
		gap+=(i-i_prev)-T
	i_prev=i


print t[-1]+T-gap

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

Solution (Python):
N, T = map(int, raw_input().split())    
t = map(int, raw_input().split())   
ans = 0
cur = 0
for i in xrange(N - 1):
    if t[i + 1] - t[i] > T:
        ans += t[i] + T - cur
        cur = t[i + 1]
ans += t[N - 1] + T - cur
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[i + 1] - t[i], T)
ans += T

print(ans)

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

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

print(ans)

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

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

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

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

ans = T * N

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

Solution (Python):
n,t=[int(x) for x in input().split()]
tn=[int(x) for x in input().split()]
ans=t
for i in range(len(tn)-1):
    diff=tn[i+1]-tn[i]
    if diff<=t:
        ans+=diff
    else:
        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):
  now = t[i+1] - t[i]
  ans += min(now, T)

print(ans)

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

    t_list = [int(t) for t in input().split()]
    sumv = T
    ti_1 = 0
    for ti in t_list[1:]:
        if ti_1 + T <= ti:
            sumv += T
        else:
            sumv += ti-ti_1
        ti_1 = ti
    print(sumv)


if __name__ == "__main__":
    main()

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

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

X += T
print(X)

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

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

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

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

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

print(X)

Solution (Python):
N,T = map(int,input().split())
last, time = 0,-T
for temp in map(int,input().split()):
    if temp - last < T:
        time += T - (temp - last)
    last = temp
print(N*T-time)

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

Solution (Python):



import sys
import re
import math
import collections
import itertools
import functools

DEBUG = True
DEBUG = False

def dbg(*args):
    if DEBUG:
        print("DBG: ", file=sys.stderr, end="")
        print(*args, file=sys.stderr)



def main():
    N, T = map(int, input().split())
    TS = list(map(int, input().split()))

    X = 0
    prev = TS[0]
    for i in range(1, N):
        now = TS[i]
        X += min(now-prev, T)
        prev = now
    X += T

    print(X)

if __name__ == "__main__": main()

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

print(ans)

Solution (Python):
from collections import defaultdict


def main():
    N, T = map(int, input().split())
    t_list = list(map(int, input().split()))
    ans = 0
    n = 0
    for t in t_list:
        if t >= n:
            ans += T
        else:
            ans += T - (n - t)
        n = t + T
    print(ans)


if __name__ == '__main__':
    main()

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

shower = 0

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

shower += T
print(shower)

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

Solution (Python):

import math
import sys
import itertools
import numpy as np

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

ret = t
for i in range(1, n):
    if a[i] - a[i-1] <= t:
        ret += a[i] - a[i-1]
    else:
        ret += t

print(ret)

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

Solution (Python):

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

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

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

tmp = 0
sum_t = 0

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

print(sum_t + T)

Solution (Python):


N, T = map(int, raw_input().split())
ans = 0
time = map(int, raw_input().split())

ans = 0
tmp = 0
start = time[0]
end = T
for t in time[1:]:
    if end < t:
        ans = ans + (end - start)
        start = t
        end = T + start
    else:
        end = t + T

end = time[N-1] + T
ans = ans + (end - start)

print ans

Solution (Python):
import sys



n, T = map(int, input().split())
t = list(map(int, input().split()))
res = 0
t.append(10 ** 20)
for i in range(n):
    dif = t[i + 1] - t[i]
    if dif > T:
        res += T
    else:
        res += dif
print(res)

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

prevx = ans = 0
for x in a:
	ans += min(x,prevx+t) - prevx
	prevx = x
ans += t
print ans

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

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

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

Solution (Python):





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



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



print(ans)

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

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

oyu += T
print(oyu)
quit()

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

time=0
total=0

for i in t:
    if i < time:
        total += i+T-time
        time = i+T
    else:
        total += T
        time = i+T

print total

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

if __name__ == '__main__':
    main()

Solution (Python):

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

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

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

X = 0
mae = 0
for i in t:
    if(i == 0):
        X = T
        continue

    gap = i - mae

    if(gap < T):
        X = X + gap
    else:
        X = X + T

    mae = i

print(X)

Solution (Python):
def solve():
  ar = raw_input().split(' ')
  N = int(ar[0])
  T = int(ar[1])
  ar = raw_input().split(' ')
  end = 0
  count = 0
  for i in range(N):
    ti = int(ar[i])
    if(ti < end) : count -= (end-ti)
    end = ti + T
    count += T
  return count

if __name__ == '__main__' :
  print solve()

Solution (Python):
N, T = map(int,raw_input().split())
t = map(int,raw_input().split())
result = 0

for i, v in enumerate(t):
    if i == 0: continue
    diff = v - t[i - 1]
    if diff > T:
        result += T
    else:
        result += diff
result += T


print result

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

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

Solution (Python):

T = int(input().split(" ")[1])
t = [int(x) for x in input().split(" ")]
t.append(100000000000)

ret = 0

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

print(ret)

Solution (Python):
import sys

n, t = [int(x) for x in sys.stdin.readline().split()]
a = [int(x) for x in sys.stdin.readline().split()]
total = t
for i in range(n-1):
	d = a[i+1] - a[i]
	if d <= t:
		total += d
	else:
		total += t
print(total)

Solution (Python):

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

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

bt = 0 
gt = T 
for t in tl[1:]:
    if t - bt > T:
        gt += T 
    else:
        gt += t - bt 
    bt = t

print(str(gt))

Solution (Python):

l = list(map(int, input().split()))
N = l[0]
T = l[1]


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

bt = 0 
gt = T 
for t in tl[1:]:
    if t - bt > T:
        gt += T 
    else:
        gt += t - bt 
    bt = t
        

print(str(gt))

Solution (Python):

l = list(map(int, input().split()))
N = l[0]
T = l[1]


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

sw = 0 
bt = 0 
gt = 0 
for i, t in enumerate(tl):
    if sw == 1 and t - bt > T:
        sw = 0 
    if sw == 0:
        gt += T 
    else:
        gt += t - bt  
    bt = t
    sw = 1 
        

print(str(gt))

Solution (Python):
n = input()
tmp_n = n.split(" ")

N = tmp_n[0]
T = tmp_n[1]

num = input()
tmp_num = num.split(" ")

yu_interval = int(T)
yu_fin = int(T)
loss_time = 0

for i in range(int(N)):
    if int(tmp_num[i]) <= yu_fin:
        yu_fin = int(tmp_num[i]) + yu_interval
    elif int(tmp_num[i]) > yu_fin:
        loss_time += int(tmp_num[i])-yu_fin
        yu_fin = int(tmp_num[i]) + yu_interval

print(yu_fin-loss_time)

Solution (Python):
N, T = map(int, raw_input().split())
t = map(int, raw_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):
n, t = map(int, input().split(' '))
tlist = list(map(int, input().split(' ')))

sum_time = 0
for i in range(1, len(tlist)):
    delta = tlist[i] - tlist[i-1]
    shower = delta if delta <= t else t
    sum_time += shower
sum_time += t
print(sum_time)

Solution (Python):

N, T = map(int, raw_input().split())
t = map(int, raw_input().split())
total = 0
for k in range(0, N - 1):
    if t[k + 1] - t[k] <= T:
        total += t[k + 1] - t[k]
    else:
        total += T
total += T
print total

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

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

Solution (Python):
import numpy as np

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

t_ary = input().split()
t_ary = np.array([int(e) for e in t_ary])

diff_ary = t_ary[1:] - t_ary[:-1]




tf_ary = diff_ary < T

total = 0
for i, flag in enumerate(tf_ary):
    if flag:
        total += diff_ary[i]
    else:
        total += T

total += T

print(total)

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

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

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

print(total)

Solution (Python):


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

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

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

time=b
for i in range(a-1):
    tc=k[i+1]-k[i]
    if tc<b:
        time = time+tc
    else:
        time=time+b
print(time)

Solution (Python):
n,t = map(int, raw_input().split())
l = map(int, raw_input().split())
ret = t
for i in range(1,n):
    if l[i] - l[i-1] >= t:
        ret += t
    else:
        ret += l[i] - l[i-1]
print ret

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

Solution (Python):
ini=map(int,raw_input().split())
a=map(int,raw_input().split())

sum=0

for i in range(ini[0]):
  if a[i]==0:
    pass
  else:
    if a[i]-a[i-1]>=ini[1]:
      sum+=ini[1]
    else:
      sum+= a[i]-a[i-1]

sum+=ini[1]

print sum

Solution (Python):

N,T = [int(i) for i in input().split(" ")]
array = input().split(" ")
ans = 0
fin = 0
for x in array:
    time = int(x)
    if time <= fin:
        ans += (time + T - fin)
    else:
        ans += T
    fin = time + T
print(ans)

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

    i = 0
    t = 0
    while i < N - 1:
        t += min(TN[i+1] - TN[i], T)
        i += 1

    print(t + T)

main()

Solution (Python):
n, T = map(int, input().split())
t = list(map(int, input().split()))
total = T
lastnum = 0
for i in t:
    time = i - lastnum 
    if  T < time:
        total += T
    else:
        total += time
    lastnum = i
    
print(total)

Solution (Python):
Tsum = 0

catch = input()
catch = catch.split(" ")
T = int(catch[1])

catch = input()
t = catch.split(" ")

t2 = [0]
for i in range(1, len(t)):
    t2.append(int(t[i]) - int(t[i-1]) )

for i in t2:

    if i < T:
        Tsum +=i

    else:
        Tsum +=T

print(Tsum + T)

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

a = [int(x) for x in input().split()]
sum = 0

for i in range(1, n):
    
    if a[i] - a[i - 1] > t:
        tmp = t
    else:
        tmp = a[i] - a[i - 1]
    
    sum += tmp
sum += t
print (sum)

Solution (Python):
N, T = input().split(' ')
N = int(N)
T = int(T)
x = [i for i in range(N+1)]
t = input()
cnt = 0
for ti in t.split(' '):
    x[cnt] = int(ti)
    cnt += 1
x[cnt] = -1
ans = 0
prev = -1
for ti in x:
    if ti == -1:
        ans += T
    elif prev != -1:
        if ti-prev > T:
            ans += T
        else:
            ans += ti-prev
    prev = ti
print (ans)

Solution (Python):
N, T = input().split(' ')
N = int(N)
T = int(T)
x = [i for i in range(N+1)]
t = input()
cnt = 0
for ti in t.split(' '):
    x[cnt] = int(ti)
    cnt += 1
x[cnt] = -1
ans = 0
prev = -1

for ti in x:
    if ti == -1:
        ans += T
    elif prev == -1:
        prev = ti
    else:
        if ti-prev > T:
            ans += T
        else:
            ans += ti-prev

    prev = ti

print (ans)

Solution (Python):
N, T = list(map(int, input().split()))
t = list(map(int, input().split()))
ans = 0
end = 0
for tt in t:
	diff = 0 if end <= tt else end - tt
	ans += T - diff
	end = tt + T
print(ans)

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

cost = t

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

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



sum = 0

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

sum += T

print(sum)

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

def count_time(N,T,t):
    cnt = T
    for i in range(N-1):
        tt =t[i+1]-t[i]        
        if tt <=T:
            cnt += tt
        else:
            cnt += T
    return cnt

print(count_time(N,T,t))

Solution (Python):
n, t = map(int, input().split())
l = list(map(int, input().split()))
l.append(10**11)
ans = 0

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

print(ans)

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

w = 0

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

w+=T

print(w)

Solution (Python):
NT = list(map(int,input().split()))

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


ans = NT[0]*NT[1]

for i in range(len(t)-1):
    if t[i+1]-t[i]<NT[1]:
        ans -= NT[1]-t[i+1]+t[i]
print(ans)

Solution (Python):


if __name__ == "__main__":
    N, T = map(int, raw_input().split(" "))
    t_list = map(int, raw_input().split(" "))

    total = 0
    for i in range(1, N):
        sub = t_list[i] - t_list[i - 1]

        if sub > T:
            total += T
        else:
            total += sub

    total += T
    print total

Solution (Python):


n, t = map(int, raw_input().split())
ti_list = map(int, raw_input().split())
ti = ti_list.pop(0)
total = t

for ti_plus1 in ti_list:
    total += min(ti_plus1-ti, t)
    ti = ti_plus1

print total

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

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

Solution (Python):


n,t=map(int,raw_input().split())
l=map(int,raw_input().split())
res=0
for i in xrange(1,n):
 res+=min(t,l[i]-l[i-1])
res+=t
print res

Solution (Python):
if __name__ == '__main__':
    N, T = map(int, input().split())
    ts = list(map(int, input().split()))
    
    
amount =0


    
for index in range(N-1):
    t_sub = ts[index+1]-ts[index]
    amount+=min(t_sub,T)

        
amount +=T

print(amount)

Solution (Python):
N, t = map(int, raw_input().split())
n = map(int, raw_input().split())
total = 0
next = t
for i in range(N-1):
	if(next < n[i+1]):
		total += t
		next = n[i+1]+t
	else:
		total += n[i+1]-n[i]
		next = n[i+1]+t
total += t
print(total)

Solution (Python):
a, b = map(int, raw_input().split(' '))
c = map(int, raw_input().split(' '))
s = 0

for i in range(len(c) - 1):
	t = b - (c[i + 1] - c[i])
	s += t if t > 0 else 0

print a * b - s

Solution (Python):


N, T = map(int,input().split())
a = list(map(int, input().split()))
b = []
zo  = [0, T]
leng = T
"""
d = set()
for i in range(N):
    d = d | set(range(a[i], a[i] + T))
"""
for i in range(N):
    if  a[i] + T <= zo[1]:
        pass
    elif a[i] <= zo[1] and zo[1] <= a[i] + T:
        leng += a[i] + T - zo[1]
        zo[1] = a[i] + T
    elif zo[1] <= a[i]:
        zo[0] = a[i]
        zo[1] = a[i] + T
        leng += T






print(leng)

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

X = T

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

print(X)

Solution (Python):
if __name__ == '__main__':
    N, T = map(int, input().split())
    ts = map(int, input().split())

    ans = 0
    last = -1
    for t in ts:
        s = t + T - 1
        if t <= last:
            ans -= last - t + 1
        ans += T
        last = max(last, s)

    print(ans)

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

Solution (Python):
if __name__ == '__main__':
    NT = input().split()
    N = int(NT[0])
    
    T = int(NT[1])
    
    t = input().split()
    s = 0
    for k in range(N-1):
        tmp = int(t[k+1]) - int(t[k])
        if tmp > T:
            s += tmp-T
    print( int(t[N-1]) + T - s )

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

data = input().split()
t = []
for i in range(N):
	t.append(int(data[i]))

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

print(X)

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

def check(N,T,t):
    counter=0
    for i in range(N-1):
        finish=t[i]+T
        start=t[i+1]
        
        if finish>start:
            counter=counter+finish-start
                 
    return counter
print(N*T-check(N,T,t))

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

while i <= N-2:
	if t[i+1] - t[i] >= T:
		X += T
		i += 1
	else:
		X += t[i+1] - t[i]
		i += 1

X += T

print(X)

Solution (Python):
def sentou(NT, ts):
    N, T = map(int, NT.split())
    before_oshitano = None
    total_s = 0
    for t in map(int, ts.split()):
        if before_oshitano is None:
            before_oshitano = t
            continue
        elif T > (t - before_oshitano):
            total_s += t - before_oshitano
        else:
            total_s += T
        before_oshitano = t
    total_s += T

    print(total_s)



sentou(input(), input())

Solution (Python):


import sys

def main(argv):
    line = sys.stdin.readline()
    while line:
        n, t = map(lambda x: int(x), line.split(" ", 2))
        showers = map(lambda x: int(x), raw_input().split(" "))

        water = 0
        stop = 0
        for shower in showers:
            if stop > shower:
                water -= (stop - shower)
            water += t
            stop = shower + t
        print(water)

        line = sys.stdin.readline()

if __name__ == "__main__":
    main(sys.argv)

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

total_emp_T = 0
ts = T
for t in list_t[1:]:
    if t > ts:
        total_emp_T += t - ts
    ts = t + T
ans = ts  - total_emp_T
print(ans)

Solution (Python):

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

x=0;
for i in range(n):
    if i == n-1:
        x += t
    else:
        x += min(t, tk[i+1] - tk[i])

print(x)

Solution (Python):
n, t = map(int, input().split())
ts = map(int, input().split())
x = 0
out = False
t_sw = 0
t_last = 0
for ti in ts:
    if out and t_sw > ti:
        t_sw = ti + t
    elif out and t_sw <= ti:
        x += t_sw - t_last
        out = False
    if not out:
        t_last = ti
        t_sw = t_last + t
        out = True
if out:
    x += t_sw - t_last
print(x)

Solution (Python):


n,t = [int(x) for x in input().rstrip().split(" ")]
push_times = [int(x) for x in input().rstrip().split(" ")]

total_duration = 0

for i in range(len(push_times)):
    if i == len(push_times) - 1:
        total_duration = total_duration + t
        break

    time_diff = (push_times[i+1] - push_times[i])
    if time_diff > t:
        total_duration = total_duration + t
    elif time_diff <= t:
        total_duration = total_duration + time_diff

print(total_duration)

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