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.

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 one integer — the minimum duration (in seconds) of the performance.

NoteIn 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.

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

import sys
input=sys.stdin.readline
from collections import defaultdict as dc
from collections import Counter
from bisect import bisect_right, bisect_left
import math
a,b,c,d=map(int,input().split())
a,b,c=sorted([a,b,c])
x=0
if b-a<d:
    x+=abs(b-a-d)
if c-b<d:
    x+=abs(c-b-d)
print(x)

a, b, c, d = input().split()
a = int(a)
b = int(b)
c = int(c)
d = int(d)
l = [a,b, c]
l = sorted(l)
# print(l)
x = l[1] - l[0]
y = l[2] - l[1]
step = 0
while(y != d or x != d):
    if(x < d and y >= d):
        step += abs(d - x)
        break
    elif(x>=d and y<d):
        step += abs(d - y)
        break
    elif(x<d and y<d):
        step += abs(x-d)
        step += abs(y-d)
        break
    x = l[1] - l[0]
    y = l[2] - l[1]
    break
print(step)

def find_second_max(list_of_numbers):
    max=list_of_numbers[0]
    second_max=list_of_numbers[1]
    if(second_max>max):
        second_max,max=max,second_max
    for i in range(2,len(list_of_numbers)):
        if(list_of_numbers[i]>=max):
            second_max=max
            max=list_of_numbers[i]
        elif list_of_numbers[i]>second_max:
            second_max=list_of_numbers[i]
    return second_max

list_of_numbers=list(map(int,input().split(' ')))
d=list_of_numbers.pop()
second_max=find_second_max(list_of_numbers)
#print(second_max)
list_of_numbers.remove(second_max)
sum=0
#print(list_of_numbers)
for i in list_of_numbers:
    value=abs(i-second_max)
    if(value>d):
        sum=sum+0
    else:
        sum=sum+d-value
print(sum)

a, b, c, d = map(int, raw_input().strip().split())
l = [a, b, c]
l.sort()

a, b, c = l
d1 = b - a
d2 = c - b

if d1 >= d and d2 >= d:
    print 0
    exit()

x1 = max(0, d - d1)
x2 = max(0, d - d2)

print x1 + x2

from __future__ import division,print_function
from random import*
l=list(map(int,raw_input().split()))
d=l[-1]
l=sorted(l[:3])
print(max(d-(l[2]-l[1]),0)+max(d-(l[1]-l[0]),0))

a,b,c,d=map(int,raw_input().split())
l=[a,b,c]
l.sort()
ans=0
if l[1]-l[0]>=d:
    ans+=0
else:
    ans+=(d-(l[1]-l[0]))
if l[2]-l[1]>=d:
    ans+=0
else:
    ans+=(d-(l[2]-l[1]))
print ans

# import sys
# sys.stdin=open("input1.in","r")
# sys.stdout=open("OUTPUX.out","w")
L=list(map(int,input().split()))
D=L.pop()
L.sort()
ans=0
if L[1]-L[0]<=D:
	ans= ans+D-(L[1]-L[0])
if L[2]-L[1]<=D:
	ans=ans+D-(L[2]-L[1])
print(ans)

import math

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

abcd = input().split()
abc = list(map(int,abcd[0:3]))
abc.sort()
a = abc[0]
b = abc[1]
c = abc[2]
d = int(abcd[3])

if (b - a) >= d and (c - b) >= d:
    print(0)
else:
    if (b-a) >= d > (c-b):
        print(d - (c-b))
    elif (c - b) >= d > (b - a):
        print(d - (b-a))
    else:
        print(d-(b-a) + d - (c-b))

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

input_vars = map(int,raw_input().split())
a,b,c = sorted(input_vars[:-1])
d = input_vars[-1]

ans = 0

if b-a < d:
    ans += d - (b-a)
if c-b < d:
    ans += d - (c-b)

print ans

# Chaitanya Bhutada
import math
import collections
import bisect
import heapq
import time
import random
import itertools
import sys

F = list(map(int,input().split()))
x = F[3]
F.pop()
F.sort()
y = max(0,x-(F[1] - F[0]))
z = y + max(0,x-(F[2] - F[1]))
print(z)

a, b, c, d = map (int, input().split())
performer = sorted (list([a,b,c]))
one = abs(performer[0]- performer[1])
two = abs(performer[1]- performer[2])
if one == two==d  :
    print (0)
elif one >d and two >d:
    print (0)
elif one == two  :
    print (abs(d-one)*2)
elif one ==d  :
    print (abs(d-two) )
elif  two==d  :
    print (abs(d-one) )
elif  one >=d and two <d:
    print (abs(d - two))
elif  two>=d and one <d:
    print (abs(d - one))
else:
    print (abs(d- one ) + abs( d- two))

a, b, c, diff = [int(x) for x in input().split()]
a, b, c = sorted([a, b, c])
diff1 = b - a
diff2 = c - b
count = 0
if diff1 < diff:
    count += diff - diff1
if diff2 < diff:
    count += diff - diff2
print(count)

a = []
x, y, z, d = map(int, input().split())
a.append(x)
a.append(y)
a.append(z)

a.sort()

ans = 0

if (a[1]-a[0]) < d:
    ans += d-(a[1]-a[0])

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

print(ans)

a,b,c,d = map(int,input(). split())
if  (a+b+c-2*min(a,b,c)-max(a,b,c))>= d and (-(a+b+c)+2*max(a,b,c)+min(a,b,c))>=d :
    print(0)
elif max(a,b,c)>=(a+b+c+d-min(a,b,c))/2 :
    print(2*min(a,b,c)+d+max(a,b,c)-(a+b+c))
else :
    print(min(a,b,c)-max(a,b,c)+2*d)

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

inp = input()
counter = 0
allInfo = inp.split()
dist = []
for i in range(4):
    allInfo[i] = int(allInfo[i])
dist = allInfo[:3]
neededDist = allInfo[3]
dist.sort()
if (dist[1] - dist[0])<neededDist:
    counter = counter+(neededDist-(dist[1] - dist[0]))
if (dist[2] - dist[1])<neededDist:
    counter = counter+(neededDist-(dist[2] - dist[1]))
print(counter)

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

"""
Author    : co_devil Chirag Garg
Institute : JIIT
"""

from __future__ import division, print_function
import itertools, os, sys, threading
from collections import deque, Counter, OrderedDict, defaultdict
# from heapq import nsmallest, nlargest, heapify, #heappop ,heappush, heapreplace
from math import ceil,floor,log,sqrt,factorial,pow,pi
# from bisect import bisect_left,bisect_right
# from decimal import *,threading
"""from io import BytesIO, IOBase
if sys.version_info[0] < 3:
    from __builtin__ import xrange as range
    from future_builtins import ascii, filter, hex, map, oct, zip
else:
    from builtins import str as __str__
    str = lambda x=b'': x if type(x) is bytes else __str__(x).encode()
BUFSIZE = 8192
class FastIO(IOBase):
    newlines = 0
    def __init__(self, file):
        self._buffer = BytesIO()
        self._fd = file.fileno()
        self._writable = 'x' in file.mode or 'r' not in file.mode
        self.write = self._buffer.write if self._writable else None

    def read(self):
        return self._buffer.read() if self._buffer.tell() else os.read(self._fd, os.fstat(self._fd).st_size)

    def readline(self):
        while self.newlines == 0:
            b, ptr = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)), self._buffer.tell()
            self._buffer.seek(0, 2), self._buffer.write(b), self._buffer.seek(ptr)
            self.newlines += b.count(b'\n') + (not b)
        self.newlines -= 1
        return self._buffer.readline()

    def flush(self):
        if self._writable:
            os.write(self._fd, self._buffer.getvalue())
            self._buffer.truncate(0), self._buffer.seek(0)
sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
input = lambda: sys.stdin.readline().rstrip(b'\r\n')

def print(*args, **kwargs):
    sep, file = kwargs.pop('sep', b' '), kwargs.pop('file', sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop('end', b'\n'))
    if kwargs.pop('flush', False):
        file.flush()

"""

def ii(): return int(input())
def si(): return str(input())
def mi(): return map(int,input().split())
def li(): return list(mi())

abc = 'abcdefghijklmnopqrstuvwxyz'
abd = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12,
       'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24,
       'z': 25}
mod = 1000000007
dx, dy = [-1, 1, 0, 0], [0, 0, 1, -1]
def getKey(item): return item[0]
def sort2(l): return sorted(l, key=getKey)
def d2(n, m, num): return [[num for x in range(m)] for y in range(n)]
def isPowerOfTwo(x): return (x and (not (x & (x - 1))))
def decimalToBinary(n): return bin(n).replace("0b", "")
def ntl(n): return [int(i) for i in str(n)]
def powerMod(x, y, p):
    res = 1
    x %= p
    while y > 0:
        if y & 1:
            res = (res * x) % p
        y = y >> 1
        x = (x * x) % p1
    return res
def gcd(x, y):
    while y:
        x, y = y, x % y
    return x
# For getting input from input.txt file
# sys.stdin = open('input.txt', 'r')

# Printing the Output to output.txt file
# sys.stdout = open('output.txt', 'w')

graph = defaultdict(list)
visited = [0] * 1000000
col = [-1] * 1000000
def dfs(v, c):
    if visited[v]:
        if col[v] != c:
            print('-1')
            exit()
        return
    col[v] = c
    visited[v] = 1
    for i in graph[v]:
        dfs(i, c ^ 1)

def bfs(d,v):
    q=[]
    q.append(v)
    visited[v]=1
    while len(q)!=0:
        x=q[0]
        q.pop(0)
        for i in d[x]:
            if visited[i]!=1:
                visited[i]=1
                q.append(i)
        print(x)
def make_graph():
    d={}
    v,e=mi()
    for i in range(e):
        x,y=mi()
        if x not in d.keys():
            d[x]=[y]
        else:
            d[x].append(y)
        if y not in d.keys():
            d[y] = [x]
        else:
            d[y].append(x)
    return d
def gr2(l,n):
    d={}
    for i in range(1,n+1):
        if i not in d.keys():
            d[i]=l[i]
        else:
            d[i].append(l[i])
    return d

a,b,c,d=mi()
l=sorted([a,b,c])
a=l[1]-l[0]
b=l[2]-l[1]
if a<d:
    a=d-a
else:
    a=0
if b<d:
    b=d-b
else:
    b=0
print(a+b)

a,b,c,d=map(int,input().split(" "))
ls=[a,b,c]
ls=sorted(ls)
ans=0
d1=abs(ls[1]-ls[0])
if(d1<d):
    ans=d-d1
if (abs(ls[2]-ls[1])<d):
    ans =ans+ d - abs(ls[2] - ls[1])
print(ans)

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

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

pos = [int(a),int(b),int(c)]

pos = sorted(pos)
sec = 0

if abs(pos[1]-pos[0]) < int(d):
    sec += int(d)-(abs(pos[1]-pos[0]))

if abs(pos[2]-pos[1]) < int(d):
    sec += int(d)-(abs(pos[2]-pos[1]))

print (sec)

if __name__ == '__main__':
    a,b,c,d = map(int, input().split())
    r = 0
    arr = [a,b,c]
    arr.sort()
    a = arr[0]
    b = arr[1]
    c = arr[2]
    if abs(a-b) < d:
        r += d - abs(a-b)
        a -= d - abs(a-b)
    if abs(c-b) < d:
        r += d - abs(c-b)
        c += d - abs(c-b)
    if abs(a-c) < d:
        r += d - abs(a-c)
        print(r)
    else:
        print(r)

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

def fcuk(l, d):
        a=l[0]
        b=l[1]
        c=l[2]
        t=m=0
        t=d-(b-a)
        m=d-(c-b)
        if t<0:
                t=0
        if m<0:
                m=0
        return t+m

x=list(map(int, input().split()))
print(fcuk(sorted(x[:3]), x[3]))

a,b,c,d=map(int,input().split())
l=min(a,b,c)
r=max(a,b,c)
m=a+b+c-l-r
mini=[0,d-abs(r-m)][d>abs(r-m)]
mini+=[0,d-abs(m-l)][d>abs(m-l)]
print(mini)

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

# UB_CodeForces
# Advice: The only source of knowledge is exprience
# Location: At home behind my desk
# Caption: A 900 tag problem
# CodeNumber: 481

# Contest: Codeforces Round #568 (Div. 2) (https://codeforces.com/contest/1185)
# Problem: A: Ropewalkers (https://codeforces.com/contest/1185/problem/A)

def rint():
    return int(input())

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

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

a,b,c,d=map(int,input("").split(" "))
t=[]
t.append(a)
t.append(b)
t.append(c)
t.sort()
count=0
if abs(t[0]-t[1])<d:
                p=d-abs(t[0]-t[1])
                t[0]-=p
                count+=p

if abs(t[0]-t[2])<d:
                q=d-abs(t[0]-t[2])
                t[2]+=q
                count+=q
if abs(t[1]-t[2])<d:
                r=d-abs(t[1]-t[2])
                t[2]+=r
                count+=r
print(count)

a,b,c,r=[int(x) for x in input().split()]
l=[]
l.append(a)
l.append(b)
l.append(c)
l.sort()
d=[]
d.append(abs(l[0]-l[1]))
d.append(abs(l[0]-l[2]))
d.append(abs(l[1]-l[2]))
s=0;g=f=0
if d[0]<r:
    d1=r-d[0]
    d2=0
    if d[1]<r:
        d2=r-d[1]
    s+=max(d1,d2)
if d[2]<r:
    d1=r-d[2]
    d2=0
    if d[1]<r:
        d2=r-d[1]
    s+=max(d1,d2)
print(s)

# https://codeforces.com/problemset/problem/1185/A

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

l = sorted([a, b, c])
ans = 0
if l[1] - l[0] < d:
    ans += (d - l[1] + l[0])

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

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

a,b,c,n=map(int,input().split())
q=[]
q.append(a)
q.append(b)
q.append(c)
q.sort()
w=q[1]-q[0]
e=q[2]-q[1]
if(w<n and e<n):
	ans=n-w
	ans+=n-e
elif(w<n):
	ans=n-w
elif(e<n):
	ans=n-e
else:
	ans=0
print(ans)

# map(int, raw_input().split())

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

count = 0

if a <= b <= c:

    v1 = a

    v2 = b

    v3 = c

elif a <= c <= b:

    v1 = a

    v2 = c

    v3 = b

elif b <= a <= c:

    v1 = b

    v2 = a

    v3 = c

elif b <= c <= a:

    v1 = b

    v2 = c

    v3 = a

elif c <= a <= b:

    v1 = c

    v2 = a

    v3 = b

else:

    v1 = c

    v2 = b

    v3 = a

count = 0

if v3-v2 < d:

    count += d-(v3-v2)

if v2-v1 < d:

    count += d-(v2-v1)

print count

if __name__ == '__main__':
	a,b,c,d = map(int, input().split())
	a1 = abs(a-b)
	a2 = abs(a-c)
	a3 = abs(b-c)
	ans= 0
	a,b,c=sorted([a,b,c])
	print (max(d-(b-a),0)+max(d-(c-b),0))

"""
    Satwik_Tiwari ;) .
    25 june , 2020  - Thursday
"""

#===============================================================================================
#importing some useful libraries.
from __future__ import division, print_function

from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase

import bisect
from heapq import *
from math import *
from collections import deque
from collections import Counter as counter  # Counter(list)  return a dict with {key: count}
from itertools import combinations as comb # if a = [1,2,3] then print(list(comb(a,2))) -----> [(1, 2), (1, 3), (2, 3)]
from itertools import permutations as permutate
from bisect import bisect_left as bl
#If the element is already present in the list,
# the left most position where element has to be inserted is returned.
from bisect import bisect_right as br
from bisect import bisect
#If the element is already present in the list,
# the right most position where element has to be inserted is returned

#==============================================================================================

BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")

def print(*args, **kwargs):
    """Prints the values to a stream, or to sys.stdout by default."""
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()

if sys.version_info[0] < 3:
    sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
    sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)

# inp = lambda: sys.stdin.readline().rstrip("\r\n")

#===============================================================================================
#some shortcuts

mod = 1000000007
def inp(): return sys.stdin.readline().rstrip("\r\n") #for fast input
def out(var): sys.stdout.write(str(var))  #for fast output, always take string
def lis(): return list(map(int, inp().split()))
def stringlis(): return list(map(str, inp().split()))
def sep(): return map(int, inp().split())
def strsep(): return map(str, inp().split())
def graph(vertex): return [[] for i in range(0,vertex+1)]
def zerolist(n): return [0]*n
def nextline(): out("\n")  #as stdout.write always print sring.
def testcase(t):
    for p in range(t):
        solve()
def printlist(a) :
    for p in range(0,len(a)):
        out(str(a[p]) + ' ')
def lcm(a,b): return (a*b)//gcd(a,b)
def power(a,b):
    ans = 1
    while(b>0):
        if(b%2==1):
            ans*=a
        a*=a
        b//=2
    return ans
def ncr(n,r): return factorial(n)//(factorial(r)*factorial(max(n-r,1)))
def isPrime(n) : # Check Prime Number or not
    if (n <= 1) : return False
    if (n <= 3) : return True
    if (n % 2 == 0 or n % 3 == 0) : return False
    i = 5
    while(i * i <= n) :
        if (n % i == 0 or n % (i + 2) == 0) :
            return False
        i = i + 6
    return True

#===============================================================================================
# code here ;))
def bs(a,l,h,x):
    while(l<h):
        # print(l,h)
        mid = (l+h)//2
        if(a[mid] == x):
            return mid
        if(a[mid] < x):
            l = mid+1
        else:
            h = mid
    return l

def sieve(a): #O(n loglogn) nearly linear
    #all odd mark 1
    for i in range(3,((10**6)+1),2):
        a[i] = 1
    #marking multiples of i form i*i 0. they are nt prime
    for i in range(3,((10**6)+1),2):
        for j in range(i*i,((10**6)+1),i):
            a[j] = 0
    a[2] = 1 #special left case
    return (a)

def bfs(g,st):
    visited = [0]*(len(g))
    visited[st] = 1
    queue = []
    queue.append(st)
    new = []
    while(len(queue) != 0):
        s = queue.pop()
        new.append(s)
        for i in g[s]:
            if(visited[i] == 0):
                visited[i] = 1
                queue.append(i)
    return new

def solve():
    a = lis()
    d = a[3]
    a = a[:3]
    a = sorted(a)
    ans = 0
    if(a[1]-a[0] < d):
        ans += d - (a[1]-a[0])
    if(a[2]-a[1] < d):
        ans += d - (a[2]-a[1])
    print(ans)
    # print((d - (a[1]-a[0])) + (d - (a[2]-a[1])))

testcase(1)
# testcase(int(inp()))

a , b , c ,d =map (int ,input().split())
q=[]
res=0
res1=0
q.append(a)
q.append(b)
q.append(c)
q=sorted(q)
if abs(q[1]-q[0])<=d:
	res=d-abs(q[1]-q[0])
if abs(q[1]-q[2])<=d:
	res1=d-abs(q[1]-q[2])
print(res+res1)

inpt = input()
inptArr = inpt.split(" ")
dist = []
for x in inptArr:
    dist.append(int(x))

arr = dist
minVal = arr[len(arr)-1]
arr = arr[0:len(arr)-1]
arr.sort()
time = 0

while(1==1):
    check = 0
    for x in range(len(arr)):

        if(x==0):
            if(arr[x+1]-arr[x]<minVal):
                time=time+(minVal-(arr[x+1]-arr[x]))
                arr[0]=arr[0]-(minVal-(arr[x+1]-arr[x]))
                continue
        elif(x==len(arr)-1):
             if(arr[x]-arr[x-1]<minVal):
                time=time+(minVal-(arr[x]-arr[x-1]))
                arr[x]=arr[x]+(minVal-(arr[x]-arr[x-1]))
                continue
        else:
            if(arr[x]-arr[x-1] + arr[x+1]-arr[x] >= 2*minVal ):
                if(arr[x]-arr[x-1] < minVal and arr[x+1]-arr[x] >= minVal + (minVal-(arr[x]-arr[x-1] < minVal)) ):
                    time = time + (minVal-(arr[x]-arr[x-1] < minVal))
                    arr[x]=arr[x]+ (minVal-(arr[x]-arr[x-1] < minVal))
                    continue
                elif(arr[x]-arr[x-1] >= minVal + 1 and arr[x+1]-arr[x] < minVal + (minVal - (arr[x]-arr[x-1]))   ):
                    time = time +(minVal - (arr[x]-arr[x-1]))
                    arr[x]=arr[x]-(minVal - (arr[x]-arr[x-1]))
                    continue
            else:
                continue

        check=check+1

    if(check == len(arr)):
        break

print(time)

a,b,c,d = map(int,raw_input().split())
mi = min(a,b,c)
ma = max(a,b,c)
me = a+b+c-mi-ma
out = max(0,d-(me-mi))+max(0,d-(ma-me))
print out

a,b,c,d = map(int,input().split())
li = list()
li.append(a)
li.append(b)
li.append(c)
li.sort()
d1 = li[1] - li[0]
d2 = li[2] - li[1]
if d1 >= d and d2 >= d:
    print(0)
elif d1 >= d and d2 >= d:
    print(0)
elif d1 >= d and d2 < d:
    x = li[1]+d
    diff = abs(x-li[2])
    print(diff)
elif d1 < d and d2 >= d:
    x = li[1]-d
    diff = abs(li[0]-x)
    print(diff)
else:
    flag = 0
    if flag == 1:
        if d1 < d2:
            x = li[0]-d
            diff = abs(li[1]-x)
            print(diff)
        else:
            x = li[2]+d
            diff = abs(li[1]-x)
            print(diff)
    else:
        x1 = li[1]-d
        diff1 = abs(li[0]-x1)
        x2 = li[1]+d
        diff2 = abs(li[2]-x2)
        su = diff1+diff2
        print(su)

from collections import Counter
import math
from collections import Counter
import os
import sys
from io import BytesIO, IOBase

BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")

sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
##########################################################
#for  _ in range(int(input())):
from collections import Counter
#arr=list(map(int,input().split()))
#n = int(input())
#for _ in range(n):
a,b,c,d= map(int, input().split())
l=[a,b,c]
l.sort()
a=l[0]
b=l[1]
c=l[2]
val1=max(0,d-(b-a))
val2=max(0,d-(c-b))
print(val1+val2)

import collections, heapq, math, sys

a,b,c,d = map(int, sys.stdin.readline().rstrip().split(' '))

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

lo = b - d
hi = b + d
sm = max(0, a - lo)
sm += max(0, hi - c)
print(sm)

a,b,c,d=map(int,input().split())
l=[a,b,c]
l.sort()
a=l[0]
b=l[1]
c=l[2]
x=d-b+a
y=d-c+b
if(x>=0 and y>=0):
    print(x+y)
elif(x<0 and y>=0):
    print(y)
elif(y<0 and x>=0):
    print(x)
elif(x<0 and y<0):
    print(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)

a,b,c,d = list(map(int, input().split()))
spisok=[a,b,c]
spisok.sort()
e=abs(spisok[1]-spisok[0])
k=abs(spisok[2]-spisok[1])
if e<d:
    e=abs(d-e)
else:
    e=0
if k<d:
    k=abs(d-k)
else:
    k=0
sum=e+k
print(sum)

# https://codeforces.com/problemset/problem/1185/A
from sys import stdin

if __name__ == "__main__":
    pos_a, pos_b, pos_c, dist = [int(n) for n in stdin.readline().strip().split(" ")]
    left, center, right = sorted([pos_a, pos_b, pos_c])
    movements_left = dist - (center - left) if center - left < dist else 0
    movements_right = dist - (right - center) if right - center < dist else 0
    print(movements_left + movements_right)

a,b,c,d = raw_input().split()
a,b,c,d = [int(a), int(b),int(c), int(d)]

l = [a,b,c]

l = sorted(l)

sec= 0
if l[1] - l[0] < d:
	sec += d - (l[1] - l[0])

if l[2] - l[1] < d:
	sec += d - (l[2] - l[1])

print(sec)

# DON'T USE PYTHON FOR RECURSION
# TRY PYPY
import math
import operator
import sys
import threading
from bisect import bisect_left, bisect
from collections import Counter, defaultdict
from math import ceil, floor, pi, sin, sqrt
from sys import exit, stdin, stdout

def main():
    # stdin = open('.in')
    a, b, c, d = map(int, stdin.readline().strip().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

if __name__ == '__main__':
    sys.setrecursionlimit(10**6)
    threading.stack_size(10240000)
    thread = threading.Thread(target=main)
    thread.start()

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

a, b, c, d = map(int, input().split())
sol = 0
ar = []
ar.append(a)
ar.append(b)
ar.append(c)
ar.sort()
d1 = ar[1] - ar[0]
d2 = ar[2] - ar[1]
if (d1 < d):
    sol += d - d1
if (d2 < d):
    sol += d - d2
print(sol)

l=map(int,raw_input().split())
d=l.pop()
l.sort()
ans=0

a,b,c=l
l,r=b-d,b+d
if a>l:
    ans+=a-l
if r>c:
    ans+=r-c
print ans

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

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

a,b,c,d=map(int,raw_input().split())
l=[a,b,c]
l.sort()
ans=0
for i in xrange(len(l)-1):
    if l[i+1]-l[i]>=d:
        pass
    else:
        u=l[i+1]-l[i]
        v=d-u
        ans+=v
print ans

a,b,c,d = map(int, input().split())
num_list = [a,b,c]
num_list.sort()
cnt = 0

if num_list[2]-num_list[1]<d:
	cnt += d-(num_list[2]-num_list[1])
if num_list[1]-num_list[0]<d:
	cnt +=d -(num_list[1]-num_list[0])

print(cnt)

def fcuk(l, d):
        a=l[0]
        b=l[1]
        c=l[2]
        t=m=0
        t=d-(b-a)
        m=d-(c-b)
        if t<0:
                t=0
        if m<0:
                m=0
        return t+m

x=list(map(int, input().split()))
print(fcuk(sorted(x[:3]), x[3]))

sorted_list=list(int(x) for x in input().split())
d=sorted_list.pop()
count=0
sorted_list.sort()
min=sorted_list[0]
mid=sorted_list[1]
max=sorted_list[2]

if(mid-min)<d:
    count+=d-(mid-min)

if(max-mid)<d:
    count+=d-(max-mid)

print(count)

a, b, c, d = map(int, raw_input().strip().split())
l = [a, b, c]
l.sort()

a, b, c = l
d1 = b - a
d2 = c - b

if d1 >= d and d2 >= d:
    print 0
    exit()

x1 = max(0, d - d1)
x2 = max(0, d - d2)

print x1 + x2

a, b, c, d = 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, diff = [int(x) for x in input().split()]
a, b, c = sorted([a, b, c])
diff1 = b - a
diff2 = c - b
count = 0
if diff1 < diff:
    count += diff - diff1
if diff2 < diff:
    count += diff - diff2
print(count)

from __future__ import division, print_function
import bisect
import math
import itertools
import sys
from atexit import register

if sys.version_info[0] < 3:
    from io import BytesIO as stream
else:
    from io import StringIO as stream

if sys.version_info[0] < 3:
    class dict(dict):
        """dict() -> new empty dictionary"""
        def items(self):
            """D.items() -> a set-like object providing a view on D's items"""
            return dict.iteritems(self)

        def keys(self):
            """D.keys() -> a set-like object providing a view on D's keys"""
            return dict.iterkeys(self)

        def values(self):
            """D.values() -> an object providing a view on D's values"""
            return dict.itervalues(self)

    input = raw_input
    range = xrange

    filter = itertools.ifilter
    map = itertools.imap
    zip = itertools.izip

def sync_with_stdio(sync=True):
    """Set whether the standard Python streams are allowed to buffer their I/O.

    Args:
        sync (bool, optional): The new synchronization setting.

    """
    global input, flush

    if sync:
        flush = sys.stdout.flush
    else:
        sys.stdin = stream(sys.stdin.read())
        input = lambda: sys.stdin.readline().rstrip('\r\n')

        sys.stdout = stream()
        register(lambda: sys.__stdout__.write(sys.stdout.getvalue()))
def main():
    a,b,c,d=map(int,input().split())
    lis=[[a,1],[b,2],[c,3]]
    lis=sorted(lis)
    s=d-(lis[1][0]-lis[0][0])
    s2=d-(lis[2][0]-lis[1][0])
    print(max(s2,0)+max(s,0))

if __name__ == '__main__':
    sync_with_stdio(False)
    main()

arr = [int(x) for x in raw_input().split()]
a, b, c, d = arr
# a = input()
# b = input()
# c = input()
# d = input()

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

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

s=list(map(int,input().strip().split()))
w=[]
for i in range(3):
    w.append(s[i])
w.sort()
a=w[0]
b=w[1]
c=w[2]
d=abs(b-a)
if d<s[3]:
    d1=abs(s[3]-d)
else:
     d1=0
x=abs(c-b)
if x<s[3]:
   y=abs(s[3]-x)
else:
    y=0
print(d1+y)

inp = map(int, raw_input().split())
a, d = inp[:3], inp[3]
a.sort()
print max(0, d - (a[1] - a[0])) + max(0, d - (a[2] - a[1]))

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

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

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

"""
Beautiful is better than ugly.
    Explicit is better than implicit.
Simple is better than complex.
    Complex is better than complicated.
Flat is better than nested.
    Sparse is better than dense.

    * Readability counts *

 // Author : raj1307 - Raj Singh
 // Date   : 19.06.19

"""

from __future__ import division, print_function
import os,sys
from io import BytesIO, IOBase

if sys.version_info[0] < 3:
    from __builtin__ import xrange as range
    from future_builtins import ascii, filter, hex, map, oct, zip
else:
    _str = str
    str = lambda x=b"": x if type(x) is bytes else _str(x).encode()

def ii(): return int(input())
def si(): return input()
def mi(): return map(int,input().strip().split(" "))
def li(): return list(mi())

def dmain():
    sys.setrecursionlimit(100000000)
    threading.stack_size(40960000)
    thread = threading.Thread(target=main)
    thread.start()

#from collections import deque, Counter, OrderedDict,defaultdict
#from heapq import nsmallest, nlargest, heapify,heappop ,heappush, heapreplace
#from math import ceil,floor,log,sqrt,factorial,pow,pi
#from bisect import bisect,bisect_left,bisect_right,insort,insort_left,insort_right
#from decimal import *,threading

abc='abcdefghijklmnopqrstuvwxyz'
abd={'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}
mod,MOD=1000000007,998244353
vow=['a','e','i','o','u']
dx,dy=[-1,1,0,0],[0,0,1,-1]
def getKey(item): return item[0]
def sort2(l):return sorted(l, key=getKey)
def d2(n,m,num):return [[num for x in range(m)] for y in range(n)]
def isPowerOfTwo (x): return (x and (not(x & (x - 1))) )
def decimalToBinary(n): return bin(n).replace("0b","")
def ntl(n):return [int(i) for i in str(n)]

def powerMod(x,y,p):
    res = 1
    x %= p
    while y > 0:
        if y&1:
            res = (res*x)%p
        y = y>>1
        x = (x*x)%p1
    return res

def gcd(x, y):
    while y:
        x, y = y, x % y
    return x

def isPrime(n) : # Check Prime Number or not
    if (n <= 1) : return False
    if (n <= 3) : return True
    if (n % 2 == 0 or n % 3 == 0) : return False
    i = 5
    while(i * i <= n) :
        if (n % i == 0 or n % (i + 2) == 0) :
            return False
        i = i + 6
    return True

# For getting input from input.txt file
#sys.stdin = open('input.txt', 'r')

# Printing the Output to output.txt file
#sys.stdout = open('output.txt', 'w')

def main():

    #for _ in range(ii()):

    a,b,c,d=mi()

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

    a=l[0]
    b=l[1]
    c=l[2]
    m=0
    if b-a<d:
        m+=d-(b-a)
    if c-b<d:
        m+=d-(c-b)

    print(m)

# region fastio

BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        if self.buffer.tell():
            return self.buffer.read()
        return os.read(self._fd, os.fstat(self._fd).st_size)

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)

def print(*args, **kwargs):
    """Prints the values to a stream, or to sys.stdout by default."""
    sep, file = kwargs.pop("sep", b" "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", b"\n"))
    if kwargs.pop("flush", False):
        file.flush()

sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
input = lambda: sys.stdin.readline().rstrip(b"\r\n")

# endregion

if __name__ == "__main__":
    main()
    #dmain()

a,b,c,d = map(int, input().split())
num_list = [a,b,c]
num_list.sort()
cnt = 0

if num_list[2]-num_list[1] < d:
    cnt += d - (num_list[2]-num_list[1])
if num_list[1]-num_list[0] < d:
    cnt += d - (num_list[1]-num_list[0])

print(cnt)

a=list(map(int,input().split()))
d=a[3]
a.remove(a[3])
#lst=list(a)
a.sort()
for i in range(len(a)):
    l=a[0]
    h=a[2]
    md=a[1]
print(2*d-h+l)

a,b,c,d = map(int,input(). split())
if max(a,b,c)>=(a+b+c+d-min(a,b,c))/2 :
    print(2*min(a,b,c)+d+max(a,b,c)-(a+b+c))
else :
    print(min(a,b,c)-max(a,b,c)+2*d)

a,b,c,d = map(int,input().split())
kmax = max(a,b,c)
kmin = min(a,b,c)
i=0
if ((kmax == a) and (kmin == b)) or ((kmax == b) and (kmin == a)):
    ks = c
elif ((kmax == b) and (kmin == c)) or ((kmax == c) and (kmin == b)):
    ks = a
else:
    ks = b
if abs(kmax-ks) < d:
    i+=abs(abs(kmax-ks)-d)
if abs(abs(kmin-ks)-d) < d:
    i+=abs(abs(kmin-ks)-d)
print(i)

a, b, c, d = map(int, input().split(" "))
dancer = [a, b, c]
dancer.sort()
counter = 0
distance = 0
while abs(dancer[0] - dancer[1]) < d or abs(dancer[1] - dancer[2]) < d:
    if abs(dancer[0] - dancer[1]) <= abs(dancer[1] - dancer[2]):
        counter += d - abs(dancer[0] - dancer[1])
        dancer[0] += d - abs(dancer[0] - dancer[1])
    else:
        counter += d - abs(dancer[2] - dancer[1])
        dancer[2] += d - abs(dancer[2] - dancer[1])

print(counter)

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

# your code goes here

a,b,c,d = map(int, input().split())
num_list = [a,b,c]
num_list.sort()
cnt = 0

while num_list[2]-num_list[1] <= d:
    num_list[2] +=1
    cnt += 1

while num_list[1]-num_list[0] <= d:
    num_list[0] -= 1
    cnt +=1

print(cnt)

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

a, b, c, d = map(int, input().split())
x = list(sorted([a, b, c]))
print(sum([x[i + 1] - x[i] - d for i in range(2) if x[i + 1] - x[i] < d]))

a,b,c,d=map(int,input().split())
l=[]
l.append(a)
l.append(b)
l.append(c)
l=sorted(l,reverse=True)
mid=l[1]
if (l[0]-l[2])//2>=d:
    ans=l[2]+d-mid
else:
    ans=l[2]-(mid-d)+(mid+d)-l[0]
print(ans)

a,b,c,f=map(int,input().split())
l=[a,b,c]
l.sort()
c=l[1]-l[0]
d=l[2]-l[1]
if(c==d and f>c):
    print((f-d)*2)
else:
    if(d>=f or f>=d):
        print(f-c)
    if(c>=f or f>=c):
        print(f-d)

try:
    t=[]
    for i in range(3):
        a=int(input())
        t.append(a)
    d=int(input())
    t.sort()
    l=t[1]-t[0]
    r=t[2]-t[1]
    tm=0
    if l<d:
        tm=tm+d-l
    if r<d:
        tm=tm+d-r
    print(tm)

except Exception:
    pass

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

count=0
r0=abs(a-b);r1=abs(b-c)
if r0<d:
	count+=(d-r0)
	a=b-d
if r1<d:
	count+=(d-r1)
	c=b+d
print(count)

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

def find_second_max(list_of_numbers):
    max=list_of_numbers[0]
    second_max=list_of_numbers[1]
    if(second_max>max):
        second_max,max=max,second_max
    for i in range(2,len(list_of_numbers)):
        if(list_of_numbers[i]>=max):
            second_max=max
            max=list_of_numbers[i]
        elif list_of_numbers[i]>second_max:
            second_max=list_of_numbers[i]
    return second_max

list_of_numbers=list(map(int,input().split(' ')))
d=list_of_numbers.pop()
second_max=find_second_max(list_of_numbers)
print(second_max)
list_of_numbers.remove(second_max)
sum=0
print(list_of_numbers)
for i in list_of_numbers:
    value=abs(i-second_max)
    if(value>d):
        sum=sum+0
    else:
        sum=sum+d-value
print(sum)

a, b, c, k = input().split()
k = int(k)
a, b, c = sorted([int(a), int(b), int(c)])

print(abs((b - a) - k) + abs((c - b) - k))

import math
str = input().split(" ")

a = int(str[0])
b = int(str[1])
c = int(str[2])
d = int(str[3])

c = [a,b,c]

c.sort()

def compare(x,y,dif):
    if c[y] -c[x] >= dif:
        return 0;
    cc = c[x] + dif - c[y];
    c[y] = c[x] + dif;
    return cc

count = 0

count += compare(0,1,d)
c.sort()
count += compare(1,2,d)
c.sort()
count += compare(0,2,d)
print(count)

a=list(map(int,input().strip().split()))
d=abs(a[1]-a[0])
if d<a[3]:
    d1=abs(a[3]-d)
else:
     d1=0

x=abs(a[2]-a[1])
if x<a[3]:
   y=abs(a[3]-x)
else:
    y=0
print(abs(d1+y))

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

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

print(x+y)

a, b, c, d = map(int, input().split())
sol = 0
if (a == b):
    sol += d
    diff = abs(a-c)
    if (diff < d):
        sol += d - diff
elif (a == c):
    sol += d
    diff = abs(a-b)
    if (diff < d):
        sol += d - diff
elif (b == c):
    sol += d
    diff = abs(a-b)
    if (diff < d):
        sol += d - diff
else:
    diff1 = abs(a-b)
    diff2 = abs(a-c)
    if (diff1 < d):
        sol += d - diff1
    if (diff2 < d):
        sol += d -diff2
print(sol)

a,b,c,d=map(int,input().split())
m=abs(a-b)
m1=abs(b-c)
m2=abs(a-c)
m3=min(m,m1)
m4=min(m3,m2)
ma=max(a,b)
mb=max(ma,c)
if mb>d:
    print(d-m4)
else:
    print(d+m4)

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

pos = [int(a),int(b),int(c)]

pos = sorted(pos)
sec = 0
if max(pos)-min(pos) < (int(d)*2):
    sec += (int(d)*2)-(max(pos)-min(pos))
    pos[-1] += sec

if (pos[1] - pos[0]) < int(d) or (pos[1]-pos[0])>int(d):
    sec += abs((int(d) - (pos[1] - pos[0])))

print (sec)

l = list(map(float, input().split()))
d = l[3]
l.pop()
l.sort()
ans = 2*d - ((l[1] - l[0]) + (l[2] - l[1]))
print(int(ans))

s = input().split()
a = int(s[0])
b = int(s[1])
c = int(s[2])
d = int(s[3])
maximum = max(max(a,b),max(b,c))
minimum = min(min(a,b),min(b,c))
print(2*d-(maximum-minimum))

a,b,c,d = map(int,input(). split())
if max(a,b,c)>=(a+b+c+d-min(a,b,c))/2 :
    print(2*min(a,b,c)+d+max(a,b,c)-(a+b+c))
else :
    print(min(a,b,c)-max(a,b,c)+2*d)

a,b,c,d = map(int,input().split())
li = list()
li.append(a)
li.append(b)
li.append(c)
li.sort()
d1 = li[1] - li[0]
d2 = li[2] - li[1]
if d1 >= d and d2 >= d and d3 >= d:
    print(0)
elif d1 >= d and d2 >= d:
    print(0)
elif d1 >= d and d2 < d:
    x = li[1]+d
    diff = abs(x-li[2])
    print(diff)
elif d1 < d and d2 >= d:
    x = li[1]-d
    diff = abs(li[0]-x)
    print(diff)
else:
    d3 = li[2] - li[0]
    if d3 >= d:
        if d1 < d2:
            x = li[0]-d
            diff = abs(li[1]-x)
            print(diff)
        else:
            x = li[2]+d
            diff = abs(li[1]-x)
            print(diff)
    else:
        x1 = li[1]-d
        diff1 = abs(li[0]-x1)
        x2 = li[1]+d
        diff2 = abs(li[2]-x2)
        su = diff1+diff2
        print(su)

a,b,c,d=[int(x) for x in input().split()]
l=[a,b,c]
l.sort()
print(2*d-l[2]+l[0])

a,b,c,d = list(map(int,input().split()))
aa  = min([a,b,c])
cc  = max([a,b,c])
print((d<<1)-(cc-aa))

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

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

a , b , c ,d =map (int ,input().split())
q=[]
res=0
q.append(a)
q.append(b)
q.append(c)
q=sorted(q)
res+=d-abs(q[1]-q[0])
res+=d-abs(q[1]-q[2])
print(res)

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

pos = [int(a),int(b),int(c)]

pos = sorted(pos)
sec = 0

sec += int(d)-(abs(pos[1]-pos[0]))
sec += int(d)-(abs(pos[2]-pos[1]))

print (sec)

a,b,c,n = map(int,input().split())
k = []
k.append(a)
k.append(b)
k.append(c)
k.sort()
ans = 0
for i in range(1,len(k)):
    y = abs(k[i-1]-k[i])
    if(y<n):
        k[i]+=(n-y)
        ans+=(n-y)
print(ans)

x=list(map(int,input().split()))
d=int(x[3])
x=x[:3]
x=sorted(x)
def a(x,s):
    if x>s:
        return x-s
    return s-x
q=x[0]
b=x[1]
c=x[2]
x=sorted(x)
maj=0

maj+=a(q+d,b)
maj+=a(q+d+d,c)
bz=maj
maj=0
maj+=a(b-d,q)
maj+=a(b+d,c)
if maj<bz:
    bz=maj
maj=0
maj+=a(c-d,b)
maj+=a(c-d-d,q)

if maj<bz:
    bz=maj
print(bz)

abcd = input().split()
abc = abcd[0:3]
abc.sort()
a = int(abc[0])
b = int(abc[1])
c = int(abc[2])
d = int(abcd[3])

if abs(a-b) >= d and abs(b-c) >= d:
    print(0)
else:
    if abs(a-b) >= d and not abs(b-c) >= d:
        print(d-abs(b-c))
    elif abs(b-c) >= d and not abs(a-b) >= d:
        print(d - abs(a-b))
    else:
        print(d-abs(a-b) + d - abs(b-c))

a = input().split()
for i in range(4):
    a[i] = int(a[i])
dist = a[3]
a.pop(3)
a.sort()
mid = a[1]
max = mid + dist
min = mid - dist
if (max >= a[2]) and (min <= a[0]):
    time = (max - a[2]) + (a[0] - min)
elif max < a[2]:
    time = a[0] - min
elif min > a[0]:
    time = max - a[2]
else:
    time = 0
print(time)

a, b, c, d = map(int, input().split())
x = list(sorted([a, b, c]))
print(sum([x[i + 1] - x[i] - d for i in range(2) if x[i + 1] - x[i] < d]))

def fcuk(l, d):
        a=l[0]
        b=l[1]
        c=l[2]
        t=m=0
        if a>d or b-a>=d:
                  t=d-(b-a)
                  m=d-(c-b)
                  if m<0:
                            m=0
                  if t<0:
                            t=0
                  return t+m
        else :
                  t=a-1
                  m=d-b+1
                  n=0
                  b=d+1
                  if b>c:
                            n=b-c
                  else :
                            n=0
                  nn=n+d
                  return nn+t+m
x=list(map(int, input().split()))
print(fcuk(sorted(x[:3]), x[3]))

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

res = 0

if a >= b and a <= c:
    x = abs(a-b)
    y = abs(a-c)
elif b >= a and b <= c:
    x = abs(a - b)
    y = abs(b - c)
else:
    x = abs(a - c)
    y = abs(b - c)

res += d - x if d - x > 0 else 0
res += d - y if d - y > 0 else 0
print(res)

sorted_list=list(int(x) for x in input().split())
d=sorted_list.pop()
count=0
sorted_list.sort()
min=sorted_list[0]
mid=sorted_list[1]
max=sorted_list[2]

if(mid-min)<d:
    count+=d-(mid-min)

elif(max-mid)<d:
    count+=d-(max-mid)

print(count)

if __name__ == '__main__':
	a,b,c,d = map(int, input().split())
	a1 = abs(a-b)
	a2 = abs(a-c)
	a3 = abs(b-c)
	ans= 0
	if a1 < d:
		ans+= d-a1
	if a2<d:
		ans+=d-a2
	if a3 < d:
		ans+=d-a3
	print(ans)

a,b,c,d=map(int,input().split())
l=[]
l.append(a)
l.append(b)
l.append(c)
l=sorted(l,reverse=True)
mid=l[1]
if (l[0]-l[2])//2>d:
    ans=l[2]+d-mid
else:
    ans=l[2]-(mid-d)+(mid+d)-l[0]
print(ans)

import math

a, b, c, d = map(int, input().split())
l = [a, b, c]
l.sort()
a,b,c=l[0],l[1],l[2]
print(min(max(a+d-b,0)+max(a+2*d-c,0),max(a-(b-d),0)+max(b+d-c,0),max(a-(c-2*d),0)+max(b-(c-d),0)))

a,b,c,d=list(map(int,input().split()))
x=[a,b,c]
x.sort(reverse=True)
if x[0]-x[1]>=d and x[1]-x[2]>=d:
	print(0)
else:
	if x[0]-x[1]<d and x[1]-x[2]<d:
		print(d-x[0]+d-x[2])
	else:
		print(d-x[0]+x[1]) if x[0]-x[1]<d else print(d-x[1]+x[2])

a,b,c,d = map(int,input(). split())
if max(a,b,c)>=(a+b+c+d-min(a,b,c))/2 :
    print(2*min(a,b,c)+d+max(a,b,c)-(a+b+c))
else :
    print(min(a,b,c)-max(a,b,c)+2*d)

a,b,c,d=map(int,input().split(" "))
ls=[a,b,c]
ls=sorted(ls)
ans=0
d1=abs(ls[1]-ls[0])
if(d1<d):
    ans=d-d1
if (abs(ls[2]-ls[1])<d):
    ans = d - abs(ls[2] - ls[1])
print(ans)

a=list(map(int,input().split()))
d=a[3]
a.remove(a[3])
#lst=list(a)

a.sort()

for i in range(len(a)):
    l=a[0]
    h=a[2]
    md=a[1]
#print(2*d-h+l)
x1=md-l
x2=h-md
if (x1>=d) :
    x1=d
elif x2>=d:
    x2=d
print(2*d-x1-x2)

s = input().split()
a = int(s[0])
b = int(s[1])
c = int(s[2])
d = int(s[3])
maximum = max(max(a,b),max(b,c))
minimum = min(min(a,b),min(b,c))
print(2*d-(maximum-minimum))

a,b,c,f=map(int,input().split())
l=[a,b,c]
l.sort()
c=l[1]-l[0]
d=l[2]-l[1]
if(c==d and f>c):
    print((f-d)*2)
else:
    if(f>=d):
        print(f-c)
    if(f>=c):
        print(f-d)

a, b, c, d = map(int, input().split())
# A = list(map(int, input().split()))
# a = int(input())
if a <= b <= c or a >= b >= c:
    print(2 * d - abs(a - b) - abs(c - b))
elif a <= c <= b or a >= c >= b:
    print(2 * d - abs(a - c) - abs(c - b))
else:
    print(2 * d - abs(a - c) - abs(a - b))

a, b, c, k = input().split()
k = int(k)
a, b, c = sorted([int(a), int(b), int(c)])

print(abs((b - a) - k) + abs((c - b) - k))

a,b,c,d=map(int,input().split())
l=[]
l.append(a)
l.append(b)
l.append(c)
l=sorted(l,reverse=True)
mid=l[1]
if (l[0]-l[2])//2>=d:
    ans=l[2]+d-mid
else:
    ans=l[2]-(mid-d)+(mid+d)-l[0]
print(ans)

l = list(map(int, input().split()))
d = l[3]
l.pop()
l.sort()
ans = 2*d - ((l[1] - l[0]) + (l[2] - l[1]))
print(ans)

a, b, c, d = map(int, input().split())
first = min(a, min(b, c))
last = max(a, max(b, c))
middle = a+b+c-first-last
print(first, middle, last)
if middle-first < d and last-middle < d:
    print((d-(middle-first))+(d-(last-middle)))
elif middle-first >= d:
    print((d - (last - middle)))
elif last-middle >= d:
    print((d-(middle-first)))

l = [int(i) for i in input().split()]
fl = 0
d = l[3]
del l[3]
l = sorted(l)
if l[1] - l[0] <= d:
    a = l[1]-l[0]
    b = d - a
    fl += b
    l[1] += b
l = sorted(l)
if l[2] - l[1] <= d:
    a = l[2]-l[1]
    b = d - a
    fl += b
    l[2] += b
print(fl)

l = [int(i) for i in input().split()]
fl = 0
d = l[3]
del l[3]
l = sorted(l)
print(d, l)
while abs(l[0]-l[1]) < d:
    l[1] += 1
    fl += 1
l = sorted(l)
while abs(l[1]-l[2]) < d:
    l[2] += 1
    fl += 1
print(fl)

a=list(map(int,input().strip().split()))
d=abs(a[1]-a[0])
if d<a[3]:
    d1=abs(a[3]-d)
else:
     d1=0

x=abs(a[2]-a[1])
if x<a[3]:
   y=abs(a[3]-x)
else:
    y=0
print(abs(d1+y))

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

count=0
r0=abs(a-b);r1=abs(b-c)
if r0<d:
	count+=(d-r0)
	a=b-d
if r1<d:
	count+=(d-r1)
	c=b+d
print(count)

if __name__ == '__main__':
	a,b,c,d = map(int, input().split())
	a1 = abs(a-b)
	a2 = abs(a-c)
	a3 = abs(b-c)
	ans= 0
	if a1 < d:
		ans+= d-a1
	if a2<d:
		ans+=d-a2
	if a3 < d:
		ans+=d-a3
	print(ans)

l = [int(i) for i in input().split()]
fl = 0
d = l[3]
del l[3]
l = sorted(l)
if l[1] - l[0] <= d:
    a = l[1]-l[0]
    b = d - a
    fl += b
    l[1] += b
l = sorted(l)
if l[2] - l[1] < d:
    a = l[2]-l[1]
    b = d - a
    fl += b
    l[2] += b
print(fl)

t=list(map(int,input().split()))
a,b,c,d=t[0],t[1],t[2],t[3]
mn=min(t)
mx=max(t)
t=d*2-(mx-mn)
print(t)

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sat Jul  6 16:05:32 2019

@author: kevinss0643
"""

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

ropewalking=[a,b,c]
ropewalking.sort()
ropewalking.append(d)

def ropewalk(a,b,c,d):
    time=0
    if abs(b-a)<d:
        time += d-abs(b-a)
    if abs(c-b)<d:
        time +=d-abs(c-b)
    return time

print(ropewalk(a,b,c,d))

a,b,c,n = map(int,input().split())
k = []
k.append(a)
k.append(b)
k.append(c)
k.sort()
ans = 0
for i in range(1,len(k)):
    y = abs(k[i-1]-k[i])
    if(y<n):
        k[i]+=(n-y)
        ans+=(n-y)
print(ans)

# Chaitanya Bhutada
import math
import collections
import bisect
import heapq
import time
import random
import itertools
import sys

F = list(map(int,input().split()))
x = F[3]
F.pop()
F.sort()
y = max(0,x-(F[1] - F[0]))
z = max(y , x-(F[2] - F[1]))
print(z)

a,b,c,d = [int(_) for _ in input().split()]
if a > b:
    a, b = b, a
if b > c:
    b, c = c, b
d1 = b-a
d2 = c-b
k1=0
k2=0
if d1 >=d and d2>=d:
    print(0)
elif (d1-d)<0 or (d2-d)<0:
    if d1-d < 0:
        k1 = d-d1
    if d2-d <0:
        k2 = d-d2
    print(k1+k2)

a , b , c ,d =map (int ,input().split())
q=[]
res=0
q.append(a)
q.append(b)
q.append(c)
q=sorted(q)
res+=d-abs(q[1]-q[0])
res+=d-abs(q[1]-q[2])
print(res)

a=list(map(int,input().split()))
d=a[3]
a.remove(a[3])
#lst=list(a)

a.sort()

for i in range(len(a)):
    l=a[0]
    h=a[2]
    md=a[1]
#print(2*d-h+l)
x1=md-l
x2=h-md
if (x1>=d) :
    x1=d
elif x2>=d:
    x2=d
print(2*d-x1-x2)

a,b,c,f=map(int,input().split())
l=[a,b,c]
l.sort()
c=l[1]-l[0]
d=l[2]-l[1]
if(c==d and f>c):
    print((f-d)*2)
else:
    if(d>=f):
        print(f-c)
    if(c>=f):
        print(f-d)

a,b,c,d = map(int,input().split())
li = list()
li.append(a)
li.append(b)
li.append(c)
li.sort()
d1 = li[1] - li[0]
d2 = li[2] - li[1]
if d1 >= d and d2 >= d:
    print(0)
elif d1 >= d and d2 >= d:
    print(0)
elif d1 >= d and d2 < d:
    x = li[1]+d
    diff = abs(x-li[2])
    print(diff)
elif d1 < d and d2 >= d:
    x = li[1]-d
    diff = abs(li[0]-x)
    print(diff)
else:
    d3 = li[2] - li[0]
    if d3 >= d:
        if d1 < d2:
            x = li[0]-d
            diff = abs(li[1]-x)
            print(diff)
        else:
            x = li[2]+d
            diff = abs(li[1]-x)
            print(diff)
    else:
        x1 = li[1]-d
        diff1 = abs(li[0]-x1)
        x2 = li[1]+d
        diff2 = abs(li[2]-x2)
        su = diff1+diff2
        print(su)

from math import fabs
def u(x):
    if x <= 0:
        return 0
    return x
a, b, c, d = list(map(int, input().split()))
m = sorted([a, b, c])
print(u(d - fabs(m[1] - m[0])) + u(d - fabs(m[2] - m[1])))

a, b, c, d = map(int, input().split())
mylist = [a, b, c]
mylist.sort()
moveL = []
mincor = mylist[0]
avecor = mylist[1]
maxcor = mylist[2]

#first move
if mylist[1] - mylist[0] < d:
    mincor = avecor - d

if mylist[2] - mylist[1] < d:
    maxcor = avecor + d

move = (mylist[0] - mincor) + (maxcor - mylist[2])
moveL.append(move)

mincor = mylist[0]
avecor = mylist[1]
maxcor = mylist[2]
#second move
if mylist[1] - mylist[0] < d:
    avecor = mincor + d

if mylist[2] - avecor < d:
    maxcor = avecor + d

move = ((avecor - mylist[1]) + (maxcor - mylist[2]))
moveL.append(move)

mincor = mylist[0]
avecor = mylist[1]
maxcor = mylist[2]
#third move
if mylist[2] - mylist[1] < d:
    avecor = maxcor - d

if mylist[1] - avecor < d:
    mincor = avecor - d

move = ((mylist[1] - avecor) + (mylist[0] - mincor))
moveL.append(move)

print(min(moveL))

import math

a, b, c, d = map(int, input().split())
l = [a, b, c]
l.sort()
a,b,c=l[0],l[1],l[2]
print(min(max(a+d-b,0)+max(a+2*d-c,0),max(a-(b-d),0)+max(b+d-c,0),max(a-(c-2*d),0)+max(b-(c-d),0)))


Kyoya Ootori is selling photobooks of the Ouran High School Host Club. He has 26 photos, labeled "a" to "z", and he has compiled them into a photo booklet with some photos in some order (possibly with some photos being duplicated). A photo booklet can be described as a string of lowercase letters, consisting of the photos in the booklet in order. He now wants to sell some "special edition" photobooks, each with one extra photo inserted anywhere in the book. He wants to make as many distinct photobooks as possible, so he can make more money. He asks Haruhi, how many distinct photobooks can he make by inserting one extra photo into the photobook he already has?Please help Haruhi solve this problem.

The first line of input will be a single string s (1 ≤ |s| ≤ 20). String s consists only of lowercase English letters.

Output a single integer equal to the number of distinct photobooks Kyoya Ootori can make.

NoteIn the first case, we can make 'ab','ac',...,'az','ba','ca',...,'za', and 'aa', producing a total of 51 distinct photo booklets.

s = input()
d = set()
for i in range(ord('a'), ord('z') + 1):
    for j in range(len(s)+1):
        d.add(s[:j] + chr(i) + s[j:])
print(len(d))

s = input()
print(26*(len(s)+1) - len(s))

n = len(raw_input())

print (n+1)*26 - n

s = raw_input()
l = len(s)
print l*25+26

s=raw_input()
print len(set(s[:i]+j+s[i:] for i in range(len(s)+1) for j in 'abcdefghijklmnopqrstuvwxyz'))

if __name__ == '__main__':
    s = input()
    print(int((len(s) + 1) * 26 - len(s)))

# -*- coding:utf-8 -*-
import sys
import math

def some_func():
    """
    """

    n_list = map(str,sys.stdin.readline().split())[0]
    cache = {}

    for l in range(ord('a'),ord('z')+1):
        for k in range(len(n_list)+1):

            data = ''.join( [n_list[0:k],chr(l),n_list[k:]])
            cache[data]=1
    print len(cache)

if __name__ == '__main__':
    some_func()

n=input()
a=26
for i in range(len(n)):
	a+=25
print(a)

a=input()
c=0
for i in range(97,123):
	x=a.count(chr(i))
	if x>1:
	    c+=x-1

z=(26*(len(a)+1))-len(a)
print(z)

s=raw_input().strip()
print (len(s)+1)*25 + 1

ins = raw_input()
lin = len(ins)
print (lin + 1) * 26  - (lin)

alpha=[chr(x) for x in range(97,97+26)]
s=raw_input()
n=len(s)
photobooks=[]
for i in xrange(n+1):
    for j in alpha:
        t=s[:i]+str(j)+s[i:]
        photobooks.append(t)
photobooks=set(photobooks)
ans=len(photobooks)
print ans

s=input()
n=len(s)
ans=(n+1)*(26-n)
ans+=pow(n,2)
print(ans)

a=input()
ans=0
for i in range(len(a)+1):
    ans+=26
print(ans-len(a))

import math, string

s = raw_input()
a = [-1]
k = 0
for i in s:
    if a[k] == -1:
        prev = i
        a[k] = 1
    else:
        if i == prev:
            a[k] += 1
        else:
            k += 1
            a.append(1)
            prev = i
if k == 0:
    ans = (a[k]+1)*25 + 1
else:
    ans = 25
    for i in a:
        ans += i*25
    ans += 1

print ans

s = list(input())
n = len(s)
def haz(a):
    a = a.copy()
    for i in range(len(a)):
        if a.count(a[i])>1:
            a[i] = 0
    return a
def ins(a,b):
    a = a.copy()
    d = a.copy()
    b = h(haz(b))
    b = b.copy()
    f = []
    for i in range(len(a)+1):
        for l in range(len(b)):
            a = d.copy()
            a.insert(i,b[l])
            f+=[a]
    return f
def h(a):
    i = 0
    a = a.copy()
    while 0 in a:
        a.remove(0)
    return a
k = (n+1)*26
f = ins(s,s)
b = len(f)
f = h(haz(f))
c = len(f)
k = k-(b-c)
print(k)

__author__ = 'trunghieu11'

from string import ascii_lowercase

def main():
    s = raw_input()
    books = set()
    for i in range(len(s) + 1):
        for c in ascii_lowercase:
            books.add(s[:i] + c + s[i:])
    print len(books)

if __name__ == '__main__':
    main()

ent = raw_input()

res = (26 * (len(ent.strip())+1)) - len(ent.strip())

print res

'''

Welcome to GDB Online.
GDB online is an online compiler and debugger tool for C, C++, Python, Java, PHP, Ruby, Perl,
C#, VB, Swift, Pascal, Fortran, Haskell, Objective-C, Assembly, HTML, CSS, JS, SQLite, Prolog.
Code, Compile, Run and Debug online from anywhere in world.

'''
s=input()
n=len(s)
if(n>1):
    a=(26)*(n+1)-(n)
else:
    a=(26)*(n+1)-n
print(a)

a = input()
print(26 * (len(a) + 1) - len(a))

s = raw_input()
s = list(s)
l = len(s)
ar = []

ls = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']

for i in ls:
    for j in range(l+1):
        s.insert(j,i)
        temp = s[:]
        if s not in ar:
            ar.append(temp)
        del s[j]

print len(ar)

n = len(raw_input())

print (n + 1) * 26 - n

import sys
from collections import Counter
from math import factorial

input = sys.stdin
output = sys.stdout

# input = open('input.txt')
# some changes

def read_int():
    return [int(x) for x in input.readline().rstrip().split()]

s = input.readline().rstrip()
spes = set()
for i in xrange(len(s) + 1):
    for c in 'abcdefghijklmnopqrstuvwxyz':
        spes.add(s[:i] + c + s[i:])
answer = len(spes)
output.write('%d\n' % answer)

s = input()
n = len(s)
ans = n * 25 + 26
print(ans)

s = raw_input()

q = set()

for i in xrange(len(s)+1):
       for j in xrange(97,123):
              q.add(s[:i]+chr(j)+s[i:])

print len(q)

s=input()
n=len(s)+1
l=n-1
print(n*26-l)

s= str(input())
print((len(s)+1)*26 - len(s))

# KOYOYA AND PHOTOBOOKS
# Estacio Pereira, estacio.neto@ccc.ufcg.edu.br
# UFCG

l = list(raw_input())
j = 0
k = 0
v = []
result = 0
n = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
for i in range((len(l) + 1) * 26):
    l.insert(j / 26, n[k % 26])
    if not l in v:
        v.append(l[:])
        result += 1
    l.pop(j / 26)
    k += 1
    j += 1
print result

s=raw_input()
li=list(s)
li1=set(li)
s2=""
li1=list(li)
x=len(li)-len(li1)
for i in range(len(li1)):
    s2+=li1[i]
print (26*(len(s2)+1)-(len(s2))+x*25)

case=raw_input()
n=len(case)
print 26*(n+1)-n

a = list(input())
k = set()
for i in range(len(a)+1):
    for l in range(ord("a"),ord("z")+1):
        t = a[:]
        t.insert(i,chr(l))
        k.add("".join(t))
print(len(k))

import sys

def main():
    #grab input
    testVar = raw_input()
    length = len(testVar)+1
    print (26*length-len(testVar))

main()

#!/usr/bin/env python3

if __name__ == '__main__':
    s = input()
    print(26 + 26*len(s) - len(s))

S = input()
print(26 * (len(S)+1) -len(S) )

s = input()
a = []
for i in s:
    if i not in a:
        a.append(i)
print(len(s)*25+26)

a=raw_input()
d={}
"""for c in a:
    if c in d:
        d[c]+=1
    else:
        d[c]=1
"""
print (len(a)+1)*25+1

a = input()
print((26*(len(a)+1))-len(a))

s = raw_input()
print len(set([s[:x]+chr(i)+s[x:] for i in xrange(97, 123) for x in xrange(len(s)+1)]))

n = input()
ans = 26
q = 25
for i in range(len(n)):
    ans += q
print(ans)

# -*- coding: utf-8 -*-
import sys,copy,math,heapq,itertools as it,fractions,re,bisect,collections as coll

alpha = "abcdefghijklmnopqrstuvwxyz"

s = raw_input()
ans = set()
for c in alpha:
    for i in xrange(len(s) + 1):
        ans.add(s[:i] + c + s[i:])
print len(ans)

ss = input()
print(26*(len(ss)+1)-len(ss))

s = input()
pos = len(s) + 1
print(26*(pos) - len(s))

l = len(raw_input())

s = (l + 1) * 26 - l
print s

def from_same_letters(word):
	if len(word) == 0:
		return True

	char = word[0]

	for letter in word:
		if letter != char:
			return False

	return True

letters = input()
result = int(51)

for i in range(len(letters) - 1):
	result += 25;

	if letters[i + 1] != letters[i]:
		++result;

print(result)

def GetDIstinctPhotos():
    n = raw_input()
    print 26*(len(n)+1) - len(n)

GetDIstinctPhotos()

LettersString = input("")
Alfabet = "abcdefghijklmnopqrstuvwxyz"
Combinaties = set()

for x in range(0,len(LettersString)+1):
    for y in range(0, 26):
        Combinaties.add(LettersString[0:x]+Alfabet[y]+LettersString[x:len(LettersString)])

print (len(Combinaties))

s = list(input())
print(26*(len(s)+1)-len(s))

a=input()
c=0
for i in range(97,123):
	x=a.count(chr(i))
	if x>1:
	    c+=x-1

z=(26*(len(a)+1))-len(a)
print(z)

s=input()
n=len(s)+1
l=n-1
print(n*26-l)

# -*- coding: utf-8 -*-
"""
Created on Wed Sep 30 15:37:38 2020

@author: PREET MODH
"""

s=list(input())
print(str(26 + len(s)*25))

n = input()
ans = 26;
for i in n:
    ans += 25
print(ans)

l = len(raw_input())
print (l + 1) * 26 - l

from sys import stdin
s=stdin.readline().rstrip("\n")
print (s.__len__()+1)*26-s.__len__()

chars = list(input())
l = len(chars)
print(26 * (l + 1) - l)

s = input()
a2z = sorted("qwertyuiopasdfghjklzxcvbnm")
st = set()
for i in range(len(s)):
    first = s[:i]
    second = s[i:]
    for c in a2z:
        st.add(first + c + second)
for c in a2z:
    st.add(s + c)
print(len(st))

__author__ = 'vasiliy.lomanov'

s = raw_input()

length = len(s)
if length == 1:
    print(51)
    exit()

n = 51

prLetter = ''
for i in xrange(length-1):
    c = s[i]
    if c == prLetter:
        continue
    prLetter = c
    serieLen = 1
    k = i+1
    while c == s[k] and k < length-1:
        serieLen += 1
        k+=1

    n += (serieLen-1)*25

    n += 25

print(n)

booklet = input()

print((25 * len(booklet)) + 26)

s = raw_input()

q = list(s)

i = 1
c = s[0]
while i<len(s):
       if s[i]==s[i-1]:
              pass
       else:
              c+=s[i]
       i+=1

print 26*(len(c)+1)-len(c)

s = raw_input()

q = list(s)

q = set(q)
print 26*(len(q)+1)-len(q)

s = raw_input()
cnt = 1
for i in xrange(len(s)-1):
	if s[i] != s[i-1]:
		cnt += 1

print cnt*25 + 26

s = input()
a = []
for i in s:
    if not i in a:
        a.append(i)
print(26*(len(s)+1)+-len(a))

import itertools
s=input()
n=len(s)
s=''.join(ch for ch, _ in itertools.groupby(s))
print((n+1)*26-n-(n+1-len(s)))

import itertools
s=input()
n=len(s)
s=''.join(ch for ch, _ in itertools.groupby(s))
print((n+1)*26-n-(n-len(s)))

import itertools

def main():
    n = input()
    d = n[0]
    for c in n[1:]:
        if c==d[-1]:
            continue
        else:
            d+=c
    if len(d)==1:
        print(51)
    if len(d)>=2:
        print((len(d)+1)*26-2)

if __name__ == "__main__":
    main()

import itertools

def main():
    n = input()
    d = n[0]
    for c in n[1:]:
        if c==d[-1]:
            continue
        else:
            d+=c
    if len(d)==1:
        print(51)
    if len(d)>=2:
        print((len(d)+1)*26-len(d))

if __name__ == "__main__":
    main()

def photobooks(a):
    if a is None or len(a) == 0:
        return 0

    if len(a) % 2 == 0:
        return (len(a) + 1) * 25 + 1
    else:
        return (len(a) + 1) * 25 - 1

print(photobooks(str(input())))

l = input()
if (len(l) == 1):
	print(51)
else:
	r = 26
	for i in range(0,len(l)-1):
		if (l[i] != l[i+1]):
			r += 24
		else:
			r += 25
	r += 26
	print(r)

l = input()
if (len(l) == 1):
    print(51)
elif (len(l) == 2):
    print(76)
else:
    r = 26
    for i in range(0,len(l)-1):
        if (l[i] != l[i+1]):
            r += 24
        else:
            r += 25
    r += 26 if l[0] != l[i-1] else 25

    print(r)

s=input()
places=len(s)+1
print( ( (26-len(s) )*places )+len(s)*(places-2))

photobook = str(input())

letters = set(photobook)
print(26 * (len(photobook) +1) - len(letters))

# import sys
# sys.stdin=open("input1.in","r")
# sys.stdout=open("OUTPUX.out","w")
L=list(input())
S=set(L)
ans=((len(L)+1)*26)-len(S)
print(ans)

PRIME_COUNT = 10 ** 6
is_prime = [True] * PRIME_COUNT
primes = []
for i in range(2, 1000):
    if is_prime[i]:
        for j in range(i * i, PRIME_COUNT, i):
            is_prime[j] = False
for i in range(len(is_prime)):
    if is_prime[i]:
        primes.append(i)

photos = raw_input()
no_repeat = []

for i in photos:
    if not i in no_repeat:
        no_repeat.append(i)

result = 26 * (len(photos) + 1) - len(no_repeat)
print result

from string import ascii_lowercase

alphaList = list(ascii_lowercase)
ALPHALEN = 26
oString = raw_input()
oStringLen = len(oString)
resultList = set()

for i in range(oStringLen+1):
    for j in range(ALPHALEN):
	newString = oString[:i] + alphaList[j] + oString[i:]
	print newString
	resultList.add(newString)

print len(resultList)

__author__ = 'vasiliy.lomanov'

s = raw_input()

length = len(s)
if length == 1:
    print(51)
    exit()

n = 51

for i in xrange(length-1):
    c = s[i]
    serieLen = 1
    k = i+1
    while c == s[k] and k < length-1:
        serieLen += 1
        k+=1

    n += (serieLen-1)*25

    n += 25

print(n)

__author__ = 'vasiliy.lomanov'

s = raw_input()

length = len(s)
if length == 1:
    print(51)
    exit()

n = 52

for i in xrange(length-1):
    c = s[i]
    serieLen = 1
    k = i+1
    while c == s[k] and k < length-1:
        serieLen += 1
        k+=1

    n += (serieLen-1)*25

    n += 24

print(n)

__author__ = 'vasiliy.lomanov'

s = raw_input()

length = len(s)
if length == 1:
    print(51)
    exit()

n = 50

for i in xrange(length-1):
    c = s[i]
    serieLen = 1
    k = i+1
    while c == s[k] and k < length-1:
        serieLen += 1
        k+=1

    n += (serieLen-1)*25

    n += 24

print(n)

s = raw_input()
len1 = len(s)
a = []
a.extend(s)
af = []
for i in a:
    if i not in af:
        af.append(i)
len2 = len(af)
print ((len1+1)*26 - len2)

s=raw_input()
li=list(s)
li=set(li)
s2=""
li1=list(li)
x=len(li)-len(li)
for i in range(len(li1)):
    s2+=li1[i]
print (26*(len(s2)+1)-(len(s2))+x*25)

s=raw_input()
li=list(s)
li=set(li)
s2=""
li=list(li)
for i in range(len(li)):
    s2+=li[i]
print (26*(len(s2)+2)-(len(s2)))

s=raw_input()
li=list(s)
li=set(li)
s2=""
li=list(li)
for i in range(len(li)):
    s2+=li[i]
print (26*(len(s2)+1)-(len(s2)))

from math import factorial

s = raw_input()
s = list(s)

n1 = len(list(set(s)))
print (26 - n1)*(len(s)+1) + factorial(len(s) + 1)/(factorial(len(s) + 1 - n1)) - n1

from sys import stdin

string = stdin.readline()
print(len(string) * 26 - 1)

s = raw_input()
l = len(s)

print l * 25 + 1

#!/usr/bin/python

s = raw_input()
if (len(s) < 27):
    n = len(s)
else: n = 26

sum = 26
alfa = 25

for x in range(0,n):
    sum += alfa
    alfa -= 1

if (n > 1):
    sum += 1
print sum

# KOYOYA AND PHOTOBOOKS
# Estacio Pereira, estacio.neto@ccc.ufcg.edu.br
# UFCG

l = list(raw_input())
j = 0
k = 0
v = []
result = 0
n = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
for i in range((len(l) + 1) * 26):
    l.insert(j / 26, n[k % 26])
    if not l in v:
        v.append(l[:])
        result += 1
    l.pop(0)
    k += 1
    j += 1
print result

# KOYOYA AND PHOTOBOOKS
# Estacio Pereira, estacio.neto@ccc.ufcg.edu.br
# UFCG

l = list(raw_input())
j = 0
k = 0
v = []
result = 0
n = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
for i in range((len(l) + 1) * 26):
    l.insert(j / 26, n[k % 26])
    if not l in v:
        v.append(l[:])
        result += 1
    l.pop(j / 26)
    k += 1
    j += 1
print v
print result

s = raw_input()
a = [0]*26
n = len(s)
for i in range(n):
	a[ord(s[i]) - ord('a')] = 1
t = sum(a)
unq = 26 - t
ans = unq*(n+1) + n*(t)
print ans

s = raw_input()
counts = {}

for letter in s:
	if letter not in counts.keys():
		counts[letter] = 1
	else:
		counts[letter] += 1

result = 26 * sum(counts.values()) + (26 - len(counts))

print(result)

#WA
s=list(raw_input())
l=len(s)
a=len(set(s))
z=(26-a)*(l+1)+(a-1)*2+a
print z

#WA
s=list(raw_input())
l=len(s)
aa=set(s)
a=len(aa)
z=(26-a)*(l+1)
for i in aa:
    p=[]
    for _ in xrange(l):
        k=s
        k.insert(_,i)
        "".join(k)
        if not k in p:
            z+=1
            p+=k
print z

s=list(raw_input())
l=len(s)
a=len(set(s))
z=(26-a)*(l+1)
if a==1:
    z+=1
else:
    z+=a*2
print z

inp=raw_input()

start=25*len(inp)+26
#hai
for _ in range(1, len(inp)-1):
    if(inp[_]!=inp[_+1]):
        start=start+1

print start

s = raw_input()
s = list(s)
l = len(s)
ar = []

ls = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']

for i in ls:
    for j in range(l+1):
        s.insert(j,i)
        temp = s[:]
        if s not in ar:
            ar.append(temp)
        s.remove(i)

print len(ar)

a=raw_input()
d={}
for c in a:
    if c in d:
        d[c]+=1
    else:
        d[c]=1
print (len(d)+1)*25+1

letrasNoAlfabeto = 26

entrada = raw_input()

calculo = len(entrada) * letrasNoAlfabeto

print calculo - len(entrada)

def func(s):
    t = 26 # last position
    for i in xrange(len(s)):
        c = 25
        if i > 0 and s[i] == s[i-1]:
            c -= 1
        t += c
    if len(s) >= 2 and s[-1] == s[-2]:
        t -= 1
    return t

s = raw_input()
print func(s)

def func(s):
    if len(s) == 1: return 51
    t = 26 * 2
    for i in xrange(1, len(s)):
        c = 25
        if s[i] != s[i-1]: c = 24
        t += c
    return t

s = raw_input()
print func(s)

s = input()
if len(s) == 1: print(51)
elif len(s) == 2: print(76)
elif len(s) == 3: print(102)
else:
    print(26*2 + 25*2 + (len(s)-3) * 24)

s = input()
print((50 + (len(s)-1) * 26) if len(s) > 1 else 51)

s = input()
l = len(s)
d = 0
for i in range(l-1):
    if s[i] == s[i+1]:
        d += 1
print(25*l+26-d)

a=input()
ans=0
for i in range(len(a)):
    ans+=26
print(ans-len(a))

s = input()
res = 26
for i in range(len(s)):
    if i % 2 == 0:
        res += 25
    else:
        res += 26
print(res)

s = input()
ss = set(s)
pool = 26 - len(ss)
ans = pool * (len(s) + 1)
for e in ss:
    ans += 1
    for i in range(len(s) - 1):
        if s[i] != s:
            ans += 1

print(ans)

b = input()
a = len(b)
c = []
for x in range(len(b)+1):
  for i in range(ord('a'), ord('z') + 1):
    c.append(b[:x]+chr(i)+b[x:])
d = set(c)
if len(b) == 17:
    print(3)
print(len(d))

s = input()
l = list(s)
a = 'abcdefghijklmnopqrstuvwxyz'
for i in range(len(s)+1):
	for j in a:
		l.insert(i, j)
		print(len(l)-2*len(s))

# coding: utf-8

tam = len(input())

print(26*25*tam)

# import sys
# sys.stdin=open("input.in",'r')
# sys.stdout=open("output4.out",'w')
s=list(input())
x=set(s)
print((25*(len(x)+1))+1)

'''input
kgan
'''
i = input()
if len(i) == 1:
	print(51)
else:
	s, t = 50, 1
	for x in range(len(i)-1):
		if i[x] != i[x+1]:
			s += 25 + t
			t = 0
		else:
			s += 25
	print(s)

'''input
kgan
'''
i = input()
if len(i) == 1:
	print(51)
else:
	s, t = 50, 0
	for x in range(len(i)-1):
		if i[x] != i[x+1]:
			s += 25 + t
			t = [1, 0][t]
		else:
			s += 25
	print(s)

'''input
hi
'''
i = input()
if len(i) == 1:
	print(51)
else:
	s, t = 50, 1
	for x in range(len(i)-1):
		if i[x] != i[x+1]:
			s += 25 + t
			t = [1, 0][t]
		else:
			s += 25
	print(s)

s = set(input())
result = 26
for l in s:
  result += 25
print(result)

import sys
import math

#to read string
get_string = lambda: sys.stdin.readline().strip()
#to read list of integers
get_int_list = lambda: list( map(int,sys.stdin.readline().strip().split()) )
#to read non spaced string and elements are integers to list of int
get_intList_from_str = lambda: list(map(int,list(sys.stdin.readline().strip())))
#to read non spaced string and elements are character to list of character
get_charList_from_str = lambda: list(sys.stdin.readline().strip())
#get word sepetared list of character
get_char_list = lambda: sys.stdin.readline().strip().split()
#to read integers
get_int = lambda: int(sys.stdin.readline())
#to print faster
pt = lambda x: sys.stdout.write(str(x))

#--------------------------------WhiteHat010--------------------------------#
s = get_string()
l = len(s)-1

if l == 0:
    print(26+25)
else:
    print(l*24 + 26 + 26)

n = input()
ans = 26
q = 25
for i in range(len(n)):
    ans += q
    q-=1
print(ans)

from sys import stdin, stdout
a=len(stdin.readline())-1
#a=input()
if a==1:
    b3=51
else:
    b3=(a+1)*26-(a-1)*2
stdout.write(str(b3))
stdout.flush()

from sys import stdin, stdout
a=len(stdin.readline())
#a=input()
if a==1:
    b3=51
else:
    b3=(a+1)*26-(a-1)*2
stdout.write(str(b3))
stdout.flush()

s = list(input())
s = set(s)
print(26*(len(s)+1)-len(s))

s = input()
if len(s) == 1:
    print(51)
    quit()
d = set()
counter = 0
extra = 0
for i in range(len(s)-1):
    if s[i + 1] == s[i]:
        counter += 1
    # else:
    #     extra += counter
    #     counter = 0
    # extra += counter
# print(counter)
# print((len(s)+1) * 26)

print((len(s)+1) * 26 - counter - len(s))

n = set(input())
print((len(n)+1)*26-len(n))

a=input()
c=0
for i in range(97,123):
	x=a.count(chr(i))
	if x>1:
	    c+=x-1

z=(26*(len(a)+1))-len(a)-c
print(z)

a=input()
c=0
for i in range(97,123):
	x=a.count(chr(i))
	if x>1:
	    c+=x-1

z=(26*(len(a)+1))-len(a)-(c+1)
print(z)

'''input
hi
'''
s = raw_input()

ans = 0
if len(s) == 1:
	ans = 51
else:
	ans = 26 * len(s) + 24

print ans

s = raw_input()

print (len(s) + 1) * 26 - 1 - int(len(s) > 1)

s = input()
d = set()
for i in range(ord('a'), ord('z') + 1):
    for j in range(len(s)):
        d.add(s[:j] + chr(i) + s[j:])
print(len(d))

'''

Welcome to GDB Online.
GDB online is an online compiler and debugger tool for C, C++, Python, Java, PHP, Ruby, Perl,
C#, VB, Swift, Pascal, Fortran, Haskell, Objective-C, Assembly, HTML, CSS, JS, SQLite, Prolog.
Code, Compile, Run and Debug online from anywhere in world.

'''

s=input()
n=len(s)
if(n>1):
    a=(26-n)*(n+1)+(n*2)
else:
    a=(26-n)*(n+1)+1
print(a)

s=input()
n=len(s)+1
l=len(set(s))
print(n*26-l)

s = list(input())
n = len(s)-1
ans = 0
for i in range(len(s)+1):
    ans += 26-i
ans += n
print(ans)


There are r red and g green blocks for construction of the red-green tower. Red-green tower can be built following next rules:  Red-green tower is consisting of some number of levels;  Let the red-green tower consist of n levels, then the first level of this tower should consist of n blocks, second level — of n - 1 blocks, the third one — of n - 2 blocks, and so on — the last level of such tower should consist of the one block. In other words, each successive level should contain one block less than the previous one;  Each level of the red-green tower should contain blocks of the same color.  Let h be the maximum possible number of levels of red-green tower, that can be built out of r red and g green blocks meeting the rules above. The task is to determine how many different red-green towers having h levels can be built out of the available blocks.Two red-green towers are considered different if there exists some level, that consists of red blocks in the one tower and consists of green blocks in the other tower.You are to write a program that will find the number of different red-green towers of height h modulo 109 + 7.

The only line of input contains two integers r and g, separated by a single space — the number of available red and green blocks respectively (0 ≤ r, g ≤ 2·105, r + g ≥ 1).

Output the only integer — the number of different possible red-green towers of height h modulo 109 + 7.

NoteThe image in the problem statement shows all possible red-green towers for the first sample.

"""
#If FastIO not needed, used this and don't forget to strip
#import sys, math
#input = sys.stdin.readline
"""

import os
import sys
from io import BytesIO, IOBase
import heapq as h
import bisect

from types import GeneratorType
BUFSIZE = 8192
class SortedList:
    def __init__(self, iterable=[], _load=200):
        """Initialize sorted list instance."""
        values = sorted(iterable)
        self._len = _len = len(values)
        self._load = _load
        self._lists = _lists = [values[i:i + _load] for i in range(0, _len, _load)]
        self._list_lens = [len(_list) for _list in _lists]
        self._mins = [_list[0] for _list in _lists]
        self._fen_tree = []
        self._rebuild = True

    def _fen_build(self):
        """Build a fenwick tree instance."""
        self._fen_tree[:] = self._list_lens
        _fen_tree = self._fen_tree
        for i in range(len(_fen_tree)):
            if i | i + 1 < len(_fen_tree):
                _fen_tree[i | i + 1] += _fen_tree[i]
        self._rebuild = False

    def _fen_update(self, index, value):
        """Update `fen_tree[index] += value`."""
        if not self._rebuild:
            _fen_tree = self._fen_tree
            while index < len(_fen_tree):
                _fen_tree[index] += value
                index |= index + 1

    def _fen_query(self, end):
        """Return `sum(_fen_tree[:end])`."""
        if self._rebuild:
            self._fen_build()

        _fen_tree = self._fen_tree
        x = 0
        while end:
            x += _fen_tree[end - 1]
            end &= end - 1
        return x

    def _fen_findkth(self, k):
        """Return a pair of (the largest `idx` such that `sum(_fen_tree[:idx]) <= k`, `k - sum(_fen_tree[:idx])`)."""
        _list_lens = self._list_lens
        if k < _list_lens[0]:
            return 0, k
        if k >= self._len - _list_lens[-1]:
            return len(_list_lens) - 1, k + _list_lens[-1] - self._len
        if self._rebuild:
            self._fen_build()

        _fen_tree = self._fen_tree
        idx = -1
        for d in reversed(range(len(_fen_tree).bit_length())):
            right_idx = idx + (1 << d)
            if right_idx < len(_fen_tree) and k >= _fen_tree[right_idx]:
                idx = right_idx
                k -= _fen_tree[idx]
        return idx + 1, k

    def _delete(self, pos, idx):
        """Delete value at the given `(pos, idx)`."""
        _lists = self._lists
        _mins = self._mins
        _list_lens = self._list_lens

        self._len -= 1
        self._fen_update(pos, -1)
        del _lists[pos][idx]
        _list_lens[pos] -= 1

        if _list_lens[pos]:
            _mins[pos] = _lists[pos][0]
        else:
            del _lists[pos]
            del _list_lens[pos]
            del _mins[pos]
            self._rebuild = True

    def _loc_left(self, value):
        """Return an index pair that corresponds to the first position of `value` in the sorted list."""
        if not self._len:
            return 0, 0

        _lists = self._lists
        _mins = self._mins

        lo, pos = -1, len(_lists) - 1
        while lo + 1 < pos:
            mi = (lo + pos) >> 1
            if value <= _mins[mi]:
                pos = mi
            else:
                lo = mi

        if pos and value <= _lists[pos - 1][-1]:
            pos -= 1

        _list = _lists[pos]
        lo, idx = -1, len(_list)
        while lo + 1 < idx:
            mi = (lo + idx) >> 1
            if value <= _list[mi]:
                idx = mi
            else:
                lo = mi

        return pos, idx

    def _loc_right(self, value):
        """Return an index pair that corresponds to the last position of `value` in the sorted list."""
        if not self._len:
            return 0, 0

        _lists = self._lists
        _mins = self._mins

        pos, hi = 0, len(_lists)
        while pos + 1 < hi:
            mi = (pos + hi) >> 1
            if value < _mins[mi]:
                hi = mi
            else:
                pos = mi

        _list = _lists[pos]
        lo, idx = -1, len(_list)
        while lo + 1 < idx:
            mi = (lo + idx) >> 1
            if value < _list[mi]:
                idx = mi
            else:
                lo = mi

        return pos, idx

    def add(self, value):
        """Add `value` to sorted list."""
        _load = self._load
        _lists = self._lists
        _mins = self._mins
        _list_lens = self._list_lens

        self._len += 1
        if _lists:
            pos, idx = self._loc_right(value)
            self._fen_update(pos, 1)
            _list = _lists[pos]
            _list.insert(idx, value)
            _list_lens[pos] += 1
            _mins[pos] = _list[0]
            if _load + _load < len(_list):
                _lists.insert(pos + 1, _list[_load:])
                _list_lens.insert(pos + 1, len(_list) - _load)
                _mins.insert(pos + 1, _list[_load])
                _list_lens[pos] = _load
                del _list[_load:]
                self._rebuild = True
        else:
            _lists.append([value])
            _mins.append(value)
            _list_lens.append(1)
            self._rebuild = True

    def discard(self, value):
        """Remove `value` from sorted list if it is a member."""
        _lists = self._lists
        if _lists:
            pos, idx = self._loc_right(value)
            if idx and _lists[pos][idx - 1] == value:
                self._delete(pos, idx - 1)

    def remove(self, value):
        """Remove `value` from sorted list; `value` must be a member."""
        _len = self._len
        self.discard(value)
        if _len == self._len:
            raise ValueError('{0!r} not in list'.format(value))

    def pop(self, index=-1):
        """Remove and return value at `index` in sorted list."""
        pos, idx = self._fen_findkth(self._len + index if index < 0 else index)
        value = self._lists[pos][idx]
        self._delete(pos, idx)
        return value

    def bisect_left(self, value):
        """Return the first index to insert `value` in the sorted list."""
        pos, idx = self._loc_left(value)
        return self._fen_query(pos) + idx

    def bisect_right(self, value):
        """Return the last index to insert `value` in the sorted list."""
        pos, idx = self._loc_right(value)
        return self._fen_query(pos) + idx

    def count(self, value):
        """Return number of occurrences of `value` in the sorted list."""
        return self.bisect_right(value) - self.bisect_left(value)

    def __len__(self):
        """Return the size of the sorted list."""
        return self._len

    def __getitem__(self, index):
        """Lookup value at `index` in sorted list."""
        pos, idx = self._fen_findkth(self._len + index if index < 0 else index)
        return self._lists[pos][idx]

    def __delitem__(self, index):
        """Remove value at `index` from sorted list."""
        pos, idx = self._fen_findkth(self._len + index if index < 0 else index)
        self._delete(pos, idx)

    def __contains__(self, value):
        """Return true if `value` is an element of the sorted list."""
        _lists = self._lists
        if _lists:
            pos, idx = self._loc_left(value)
            return idx < len(_lists[pos]) and _lists[pos][idx] == value
        return False

    def __iter__(self):
        """Return an iterator over the sorted list."""
        return (value for _list in self._lists for value in _list)

    def __reversed__(self):
        """Return a reverse iterator over the sorted list."""
        return (value for _list in reversed(self._lists) for value in reversed(_list))

    def __repr__(self):
        """Return string representation of sorted list."""
        return 'SortedList({0})'.format(list(self))

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        import os
        self.os = os
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            self.os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")

sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

import collections as col
import math, string

def getInts():
    return [int(s) for s in input().split()]

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

def getStrs():
    return [s for s in input().split()]

def getStr():
    return input()

def listStr():
    return list(input())

MOD = 10**9+7
mod=10**9+7
#t=int(input())
t=1
p=10**9+7
def ncr_util():

    inv[0]=inv[1]=1
    fact[0]=fact[1]=1
    for i in range(2,300001):
        inv[i]=(inv[i%p]*(p-p//i))%p
    for i in range(1,300001):
        inv[i]=(inv[i-1]*inv[i])%p
        fact[i]=(fact[i-1]*i)%p

def solve():
    h=0
    for i in range(1000):
        if  (i*(i+1))//2<=(r+g):
            h=i
    dp=[0]*(r+1)
    dp[0]=1
    #print(h)
    for i in range(1,h+1):
        curr=(i*(i+1))//2
        for j in range(r,-1,-1):
            if j-i>=0 :
                dp[j]=(dp[j]%mod+dp[j-i]%mod)%mod
    tot=(h*(h+1))//2
    ans=0
    for i in range(r+1):
        if tot-i<=g:
            ans=(ans%mod+dp[i]%mod)%mod
    return ans
for _ in range(t):
    #n=int(input())
    #n=int(input())
    #n,m=(map(int,input().split()))
    #n1=n
    #x=int(input())
    #b=int(input())
    #n,m,k=map(int,input().split())
    r,g=map(int,input().split())
    #n=int(input())
    #s=input()
    #s1=input()
    #p=input()
    #l=list(map(int,input().split()))

    #l.sort()
    #l.sort(revrese=True)
    #l2=list(map(int,input().split()))
    #l=str(n)
    #l.sort(reverse=True)
    #l2.sort(reverse=True)
    #l1.sort(reverse=True)
    print(solve())

# by the authority of GOD     author: manhar singh sachdev #

import os,sys
from io import BytesIO, IOBase
from collections import Counter

def main():
    mod = 10**9+7
    r,g = map(int,input().split())
    n = 1
    while r+g >= (n*(n+1))//2:
        n += 1
    n -= 1
    tot = n*(n+1)//2
    dp = [0]*(r+1)
    dp[0] = 1
    for i in range(1,n+1):
        for x in range(r-i,-1,-1):
            dp[i+x] += dp[x]
            dp[i+x] %= mod
    ans = 0
    for i,val in enumerate(dp):
        if tot-i <= g:
            ans += val
            ans %= mod
    print(ans)

#Fast IO Region
BUFSIZE = 8192
class FastIO(IOBase):
    newlines = 0
    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None
    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()
    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()
    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

if __name__ == '__main__':
    main()