Polycarp decided to relax on his weekend and visited to the performance of famous ropewalkers: Agafon, Boniface and Konrad.

The rope is straight and infinite in both directions. At the beginning of the performance, Agafon, Boniface and Konrad are located in positions $a$, $b$ and $c$ respectively. At the end of the performance, the distance between each pair of ropewalkers was at least $d$.

Ropewalkers can walk on the rope. In one second, only one ropewalker can change his position. Every ropewalker can change his position exactly by $1$ (i. e. shift by $1$ to the left or right direction on the rope). Agafon, Boniface and Konrad can not move at the same time (Only one of them can move at each moment). Ropewalkers can be at the same positions at the same time and can "walk past each other".

You should find the minimum duration (in seconds) of the performance. In other words, find the minimum number of seconds needed so that the distance between each pair of ropewalkers can be greater or equal to $d$.

Ropewalkers can walk to negative coordinates, due to the rope is infinite to both sides.


-----Input-----

The only line of the input contains four integers $a$, $b$, $c$, $d$ ($1 \le a, b, c, d \le 10^9$). It is possible that any two (or all three) ropewalkers are in the same position at the beginning of the performance.


-----Output-----

Output one integer — the minimum duration (in seconds) of the performance.


-----Examples-----
Input
5 2 6 3

Output
2

Input
3 1 5 6

Output
8

Input
8 3 3 2

Output
2

Input
2 3 10 4

Output
3



-----Note-----

In the first example: in the first two seconds Konrad moves for 2 positions to the right (to the position $8$), while Agafon and Boniface stay at their positions. Thus, the distance between Agafon and Boniface will be $|5 - 2| = 3$, the distance between Boniface and Konrad will be $|2 - 8| = 6$ and the distance between Agafon and Konrad will be $|5 - 8| = 3$. Therefore, all three pairwise distances will be at least $d=3$, so the performance could be finished within 2 seconds.

Difficulty: interview

Starter code:

Solutions:
ii = lambda: int(input())
mi = lambda: list(map(int, input().split()))
li = lambda: list(mi())

a, b, c, d = mi()
a, b, c = sorted([a, b, c])
ans = max(0, d - (b - a)) + max(0, d - (c - b))
print(ans)


#Bhargey Mehta (Sophomore)
#DA-IICT, Gandhinagar
import sys, math, queue, bisect
#sys.stdin = open("input.txt", "r")
MOD = 10**9+7
sys.setrecursionlimit(1000000)

x = list(map(int, input().split()))
d = x.pop()
x.sort()
ans = 0
if x[1]-x[0] < d:
    ans += d-x[1]+x[0]
if x[2]-x[1] < d:
    ans += d-x[2]+x[1]
print(ans)

def __starting_point():
    a, b, c, d = [int(x) for x in input().split()]
    a, b, c = sorted([a, b, c])
    print(max(a - (b - d), 0) + max(0, b + d - c))

__starting_point()

#!/usr/bin/env python
a, b, c, d = list(map(int, input().split()))
p = sorted([a, b, c])
print(max(0, d - (p[1] - p[0])) + max(0, d - (p[2] - p[1])))


a,b,c,d=[int(x) for x in input().split()]
e=sorted([a,b,c])
print(max(0,d-(e[1]-e[0]))+max(0,d-(e[2]-e[1])))


*l, d = map(int, input().split())

l.sort()

print(max(d - (l[1] - l[0]), 0) + max(d - (l[2] - l[1]), 0))

a, b, c, d = map(int, input().split())
a, b, c = sorted((a, b, c))
ans = max(0, d - (b-a)) + max(0, d - (c-b))
print(ans)

*p, d = list(map(int, input().split()))
p.sort()

r = max(0, d - (p[1] - p[0])) + max(0, d - (p[2] - p[1]))
print(r)


a,b,c,d = list(map(int,input().split()))

a,b,c = sorted([a,b,c])

dist = 0
dist += max(0, d - (b-a))
dist += max(0, d - (c-b))

print(dist)


def main():
    a, b, c, d = map(int, input().split())
    abc = sorted([a, b, c])
    ans = 0
    if abc[1] - abc[0] < d:
        ans += abc[0] + d - abc[1]
    if abc[2] - abc[1] < d:
        ans += abc[1] + d - abc[2]
    print(ans)
    return 0

main()

# n = int(input())
a, b, c, d = list(map(int, input().split()))
t = [a, b, c]
t.sort()
ans = 0
if t[2] - t[1] <= d:
    ans += d - t[2] + t[1]
if t[1] - t[0] <= d:
    ans += d - t[1] + t[0]
print(ans)
# a = [int(i) for i in input().split()]


a, b, c, d = list(map(int, input().split()))
a, b, c = sorted([a, b, c])
print(max(0, d - (b - a)) + max(0, d - (c - b)))


a, b, c, d = list(map(int, input().split()))
a, b, c = sorted((a, b, c))
res = 0
if b - a < d:
    res += d - (b - a)
if c - b < d:
    res += d - (c - b)
print(res)


import math
import bisect
import heapq
from collections import defaultdict


def egcd(a, b):
    if a == 0:
        return (b, 0, 1)
    else:
        g, x, y = egcd(b % a, a)
        return (g, y - (b // a) * x, x)


def mulinv(b, n):
    g, x, _ = egcd(b, n)
    if g == 1:
        return x % n


def isprime(n):
    for d in range(2, int(math.sqrt(n))+1):
        if n % d == 0:
            return False
    return True


def argsort(ls):
    return sorted(range(len(ls)), key=ls.__getitem__)


def f(p=0):
    if p == 1:
        return map(int, input().split())
    elif p == 2:
        return list(map(int, input().split()))
    elif p == 3:
        return list(input())
    else:
        return int(input())


class DisjointSet:
    def __init__(self, n):
        self.parent = [i for i in range(1, n+1)]
        self.rank = [0]*(n+1)

    def find_set(self, x):
        if self.parent[x] == x:
            return x
        else:
            self.parent[x] = self.find_set(self.parent[x])
            return self.parent[x]

    def union(self, x, y):
        set_x = self.find_set(x)
        set_y = self.find_set(y)
        if set_x!=set_y:
            if self.rank[x]:
                pass


def graph(n, m, edg=False):
    edges = []
    visited = [0]*n
    g = [list() for _ in range(n+1)]
    for i in range(m):
        u, v = f(1)
        g[u].append(v)
        g[v].append(u)
        if edg:
            edges.append((u, v))

    if edg:
        return g, visited, edg
    else:
        return g, visited


def bfs(g, visited):
    queue = [1]
    visited[1] = 1
    for u in queue:
        for v in g[u]:
            if visited[v] == 0:
                queue.append(v)
            visited[v] = 1


def dfs(u, g, visited):
    visited[u] = 1
    for v in g[u]:
        if visited[v] == 0:
            dfs(v, g, visited)


cl = f(2)

d = cl[-1]
del cl[-1]
cl = sorted(cl)
a = cl[0]
b = cl[1]
c = cl[2]

print(max(0, d-(b-a))+max(0, d-(c-b)))

a, b, c, d = map(int, input().split())
A = [a, b, c]
a, b, c = sorted(A)
print(max(0, d - abs(a-b)) + max(0, d - abs(c-b)))

a, b, c, d = map(int, input().split())
s = sorted([a, b, c])
print(max(0, d - abs(s[1] - s[0])) + max(0, d - abs(s[-1] - s[1])))

a,b,c,d=list(map(int, input().split()))
a,b,c=sorted((a,b,c))
ans=0
if b-a<d:
    ans+=d-(b-a)
if c-b<d:
    ans+=d-(c-b)
print(ans)


A = list(map(int, input().split()))
A, d = sorted(A[:3]), A[3]
print(max(0, d - A[1] + A[0]) + max(0, d - A[2] + A[1]))


a, b, c, d = map(int, input().split())
ar = [a, b, c]
ar.sort()
left = max(0, d - abs(ar[1] - ar[0]))
right = max(0, d - abs(ar[2] - ar[1]))
print(left + right)

a, b, c, d = list(map(int, input().split()))
a, b, c = sorted([a, b, c])
print(max(d - (b - a), 0) + max(d - (c - b), 0))


a,b,c,d=[int(k) for k in input().split(" ")]

a,b,c=sorted([a,b,c])

res=max(0,d-b+a)+max(0,d-c+b)

print(res)



import sys
import math
input = sys.stdin.readline

a,b,c,d=map(int,input().split())

l=[a,b,c]
l.sort()

d1=l[1]-l[0]
d2=l[2]-l[1]

count=0
if d1<d:
	count+=d-d1
if d2<d:
	count+=d-d2

print(count)

a, b, c, d = list(map(int, input().split()))
s = [a, b, c]
s.sort()
a, b, c = s
print(max(0, a - b + d) + max(0, b - c + d))


a, b, c, d = list(map(int, input().split()))
a = [a, b, c]
a.sort()
ans = 0
if a[1] - a[0] < d:
    ans += a[0]+d-a[1]
if a[2] - a[1] < d:
    ans += a[1]+d-a[2]
print(ans) 


a,b,c,d=map(int,input().split())
s=[a,b,c]
s.sort()
ans=0
if s[1]-s[0]<=d:
    ans+=(d-(s[1]-s[0]))

if s[2]-s[1]<=d:
    ans+=(d-(s[2]-s[1]))
print(ans)