One rainy gloomy evening when all modules hid in the nearby cafes to drink hot energetic cocktails, the Hexadecimal virus decided to fly over the Mainframe to look for a Great Idea. And she has found one!Why not make her own Codeforces, with blackjack and other really cool stuff? Many people will surely be willing to visit this splendid shrine of high culture.In Mainframe a standard pack of 52 cards is used to play blackjack. The pack contains cards of 13 values: 2, 3, 4, 5, 6, 7, 8, 9, 10, jacks, queens, kings and aces. Each value also exists in one of four suits: hearts, diamonds, clubs and spades. Also, each card earns some value in points assigned to it: cards with value from two to ten earn from 2 to 10 points, correspondingly. An ace can either earn 1 or 11, whatever the player wishes. The picture cards (king, queen and jack) earn 10 points. The number of points a card earns does not depend on the suit. The rules of the game are very simple. The player gets two cards, if the sum of points of those cards equals n, then the player wins, otherwise the player loses.The player has already got the first card, it's the queen of spades. To evaluate chances for victory, you should determine how many ways there are to get the second card so that the sum of points exactly equals n.

The only line contains n (1 ≤ n ≤ 25) — the required sum of points.

Print the numbers of ways to get the second card in the required way if the first card is the queen of spades.

NoteIn the first sample only four two's of different suits can earn the required sum of points.In the second sample we can use all tens, jacks, queens and kings; overall it's 15 cards, as the queen of spades (as any other card) is only present once in the pack of cards and it's already in use.In the third sample there is no card, that would add a zero to the current ten points.

n=int(input())
n-=10
if(n<=0 or n>11):
    print(0)
elif(n==10):
    print(15)
else:
    print(4)

n = input()
req = n - 10
ans =0
if req <= 0:
	pass
else:
	if req <= 9 or req == 11:
		ans = 4
	if req == 10:
		ans = 15
print ans

n = input()
if n <= 10:
    print 0
elif n == 20:
    print 15
elif n >= 22:
    print 0
else:
    print 4

# import sys
# sys.stdin=open("input.in","r")
n=int(input())
if n<=10 or n>=22:
	print(0)
elif n==20:
	print(15)
else:
	print(4)

n=int(input())
if 10<n<=21:
    if n==20:
        print(15)
    else:
        print(4)
else:
    print(0)

N = int(input()) - 10
Counter = 0
if N <= 0 or N > 11:
    print(0)
    exit()
if N == 10:
    print(15)
else:
    print(4)

n=int(input())
x=n-10
if x<=0 or x>11:
    print("0")
elif((x>=1 and x<=9) or x==11):
    print("4")
else:
    print("15")

inputs = int(input())
inputs-=10
answer = "0"
if (inputs > 0 and inputs < 10) or inputs==11:
    answer = "4"
elif inputs == 10:
    answer = "15"
print(answer)

n=int(input())
li={}
li[10]=15
card=n-10
if card<=0:
    print(0)
elif card>11:
    print(0)
elif card==10:
    print(15)
else:
    print(4)

#!/usr/bin
n = int(raw_input())
if n <= 10 or n > 21:
    print 0
elif n == 20:
    print 15
else: print 4

n = int(input())
if n <= 10 or n > 21:
    print(0)
elif n == 21 or n == 11:
    print(4)
elif n == 20:
    print(15)
else:
    print(4)

import sys

input = lambda: sys.stdin.readline().strip("\r\n")

n = int(input())
n -= 10
if 1 < n < 10:
    print(4)
elif n == 1 or n == 11:
    print(4)
elif n == 10:
    print(15)
else:
    print(0)

#!/usr/bin/env python
n = input()
if n <= 10:
    print 0
elif n == 20:
    print 15
elif n >= 22:
    print 0
else:
    print 4

N=input()-10
if N>=1 and N<=11:
	if N==10:
		print 15
	else:
		print 4
else:
	print 0

n = input()
r = n - 10
if r>=1 and r<=11:
	if r==10:
		print 15
	else:
		print 4
else:
	print 0

def solve(n):
    d = n-10
    if d <= 0 or d > 11: return 0
    if d > 0 and d < 10: return 4
    if d == 11: return 4
    if d == 10: return 15

print solve(int(raw_input()))

# -*- coding: utf-8 -*-
import sys
if __name__ == '__main__':

    num = map(int,sys.stdin.readline().split())
    n = num[0]
    dic={0:0,1:15,2:4}
    if n <11 or n>21:
        print dic[0]
    elif n == 20:
        print dic[1]
    else:
        print dic[2]

def solve():
    num = int(raw_input())
    if(num>21) or num<=10:
        print 0
        return
    if(num == 20):
        print 15
    else:
        print 4

solve()

import sys

n = int(input())

needed = n - 10

if needed <= 0:
    print(0)
    sys.exit(0)

if needed == 1 or (needed >= 2 and needed <= 9) or needed == 11:
    print(4)
elif needed == 10:
    print(15)
else:
    print(0)

n=int(input())
if 11<=n<=19:
    print(4)
elif n==20:
    print(15)
elif n==21:
    print(4)
else:
    print(0)

n=int(input())
n=n-10
if n>11 or n<1:
    print(0)
else:
    if n>=2 and n<10:
        print(4)
    elif n==10:
        print(15)
    elif n==1 or n==11:
        print(4)

x=input()-10
if x<=0:
  print 0
elif x==10:
  print 15
elif x>11:
  print 0
else:
  print 4

n=int(raw_input())
n-=10
if n>11:
    print 0
elif n==11 or n==1:
    print 4
elif n==10:
    print 15
elif n<=0:
    print 0
else:
    print 4

n=int(input())
left = n-10
if left==10:
    print(15)
elif left==0 or n<10 or left>11:
    print(0)
else:
    print(4)

n = input()

if n-10 > 0 and n-10 < 10:
    print 4
elif (n-10) == 10:
    print 15
elif (n-10) == 11:
    print 4
else:
    print 0

n = int(input())
n -= 10
if (n < 10 or n == 11) and n >= 1:
    print (4)
elif n < 1 or n > 11:
    print (0)
else:
    print (15)

class CodeforcesTask104ASolution:
    def __init__(self):
        self.result = ''
        self.n = 0

    def read_input(self):
        self.n = int(input())

    def process_task(self):
        deck = [[x, x, x, x] for x in range(1, 12)]
        deck.append([10 for x in range(11)])
        mdeck = []
        for d in deck:
            mdeck += d
        self.result = str(mdeck.count(self.n - 10))

    def get_result(self):
        return self.result

if __name__ == "__main__":
    Solution = CodeforcesTask104ASolution()
    Solution.read_input()
    Solution.process_task()
    print(Solution.get_result())

n = int(input())
if(n<=10 or n>21):
    print(0)
    exit(0)
x = n-10
if(x==10):
    print(15)
else:
    print(4)

n=int(raw_input())
if n<=10:
	print 0
elif n==11:
	print 4
elif n<=19:
	print 4
elif n==20:
	print 15
elif n==21:
	print 4
else:
	print 0

t = input()
if(t<=10):
	print 0
else:
	if(t>=11 and t<=19):
		print 4
	elif(t==20):
		print 15
	elif(t==21):
		print 4
	else:
	 	print 0

#!/usr/bin/env python
# -*- coding: utf-8 -*-
n = input()
if n <= 10:
    print 0
elif n == 20:
    print 15
elif n >= 22:
    print 0
else:
    print 4

n=int(input())
if n<=10 or n>=22:
    print(0)
else:
    x=n-10
    if x==1 or x==2 or x==3 or x==4 or x==4 or x==5 or x==6 or x==7 or x==8 or x==9 or x==11:
        print(4)
    elif x==10:
        print(15)
    elif x==12 or x==13 or x==14 or x==15:
        print(19)

import sys

n = int(sys.stdin.readline().strip())

if n <= 10 or n > 21:
    print(0)
elif n == 20:
    print(15)
else:
    print(4)

n = int(raw_input())
n -= 10
if n == 10:
    print 15
elif n in range(1, 12):
    print 4
else:
    print 0

n=int(input())-10;print(0if n<1 or n>11 else 4 if n!=10 else 15)

s=int(input())
if s==10:
	print(0)
elif s in range(11,20):
	print(4)
elif s==20:
	print(15)
elif s==21:
	print(4)
else:
	print(0)

n = int(input())
c = n - 10
if c == 10:
    print(15)
    exit()
elif c > 11 or c <= 0:
    print(0)
else:
    print(4)

for _ in range(1):
  n=int(input())
  if n==11 or n==21:
    print(4)
  elif n==20:
    print(15)
  elif 12<=n<=19:
    print(4)
  else:
    print(0)

import pdb
import math
R = lambda: map(int, raw_input().split())

n = input()
if n <= 10:
    print 0
else:
    re = n - 10
    if re >11:
        print 0
    else:
        if re == 10:
            print 15
        else:
            print 4

n = int(input())
if 10 >= n or n > 21:
    answer = 0
elif 10 < n <= 19 or n == 21:
    answer = 4
elif n == 20:
    answer = 15
print(answer)

target = int(raw_input())
diff = target - 10
if diff < 1 or diff > 11:
    print 0
else:
    if diff == 10:
        print 15
    else:
        print 4

def run():
    needed = int(raw_input()) - 10
    if needed <= 0 or needed > 11:
        print 0
        return
    available = [4]*12
    available[0] = 0
    available[10] = 15 #d,k,v
    #print available
    print available[needed]

if __name__ == '__main__':
    run()

n=int(raw_input())
if n<=10:
    print '0'
else:
    if (n<20):
        print '4'
    else:
        if n==20:
            print '15'
        else:
            if n==21:
                print '4'
            else:
                print '0'

n = int(input())
n -= 10
if (n < 10 or n == 11) and n >= 1:
    print (4)
elif n < 1 or n > 11:
    print (0)
else:
    print (15)

n = int(input()) - 10
if n == 1 or n == 11:
    print(4)
elif n > 1 and n < 10:
    print(4)
elif n == 10:
    print(15)
else:
    print(0)

#!/usr/bin/env python
# Codeforce 104A

import sys
n = int(sys.stdin.readline())
need = n-10
if need < 1 or need > 11:
    chance = 0
elif need == 10:
    chance = 15
else:
    chance = 4
print chance

n = input()
a = n-10
if 0<a<10:
    print 4
elif a==10:
    print 15
elif a==11:
    print 4
else:
    print 0

n=int(input())
n=n-10
if(n>=1 and n<=9):
    print(4)
elif(n==10):
    print(15)
elif(n==11):
    print(4)
else:
    print(0)

#! /usr/bin/env python
n=int(raw_input())
if n<=10 or n>21:
    print 0
else:
    if n==20:
        print 15
    else:
        print 4

n=int(input())
if n>21:
    print("0")
elif n<11:
    print("0")
elif n==11:
    print("4")
elif n==20:
    print("15")
else:
    print("4")

n=int(input())
if n>10 and n<22:
    if n==20:
        print(15)
    else:
        print(4)
else:
    print(0)

n=int(input())
if n<=10:
    print(0)
else:
    n=n-10
    if n==15 or n>11:
        print(0)
    elif n==10:
        print(15)
    else:
        print(4)

n = int(input())
if n <= 10:
    print(0)
elif n == 20:
    print(15)
elif n > 21:
    print(0)
else:
    print(4)

n = int(input())
target = n - 10
if target >= 1 and target <= 9 or target == 11:
  print(4)
elif target == 10:
  print(15)
else:
  print(0)

n=int(input())
if 11<=n<=19:
    print(4)
elif n==20:
    print(15)
elif n==21:
    print(4)
else:
    print(0)

sults = 4
cards = [0]
for i in xrange(0, 12):
	cards.append(sults)
cards[10] += sults * 3 - 1

n = int(raw_input())
first = 10
second = n - first
if (second < 0) or (second > 11):
	print 0
else:
	print cards[second]

dic = dict()
for i in range(1,10):
    dic[i]=4
dic[10]=15
dic[11]=4
dif = int(input())-10
print(dic.get(dif,0))

n = int(input())-10
if n <=0 or n>11:print(0)
elif n ==11 or n <10:print(4)
elif n==10:print(15)

n=int(input())
n-=10
if(n<=0 or n>11):
    print(0)
elif(n==10):
    print(15)
else:
    print(4)

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Tue Sep  8 16:09:29 2020

@author: anirudhasarmatumuluri
"""

def main():
    n = int(input())
    if n<=10 or n>21:
        print(0)
        return
    if n==21:
        print(4)
        return
    if n==20:
        print(15)
        return

    else:
        print(4)

    return

main()

n=int(input())
if(n<=10 or n>21):
	print(0)
else:
	diff=n-10
	if(diff==10):
		print(15)
	else:
		print(4)

n=int(input())
n=n-10
if n==0:
    print(0)
elif n>0 and n<=9:
    print(4)
elif n==10:
    print(15)
elif n==11:
    print(4)
else:
    print(0)

n = int(input())
n-=10
ans=0
if (n<10 and n>0) or n==11:
	ans=4
elif n==10:
	ans=15
print(ans)

def solve(n):
    if n == 20:
        return 15
    if n == 10:
        return 0
    elif n<=21 and n>10:
        return 4
    else:
        return 0
n = int(input())
print(solve(n))

n=int(input())
x=n-10
if x<=0 or x>11:
    print("0")
elif((x>=1 and x<=9) or x==11):
    print("4")
else:
    print("15")

import math

def main():
    n = int(input())
    left = n - 10
    res = {}
    if left < 1 or left > 11:
        print(0)
    else:
        if 1 <= left <= 9 or left == 11:
            print(4)
        elif left == 10:
            print(15)

if __name__ == '__main__':
    main()

f=lambda:map(int,input().split())
n=int(input())
if 0<n-10<12:
    if n-10==0:
        print(0)
    elif n-10==10:
        print(15)
    else:
        print(4)
else:
    print(0)

def main():
    n = int(input())
    n -= 10
    if n <= 0 or n > 11:
        print(0)
    elif n < 10 or n == 11:
        print(4)
    else:
        print(15)
    return

main()

k = 10
n = int(input())
su = n - k
if (su <= 0) or (12 <= su <= 15):
    print (0)
elif (su == 10):
    print (11)
else:
    print (4)

n=int(input())
a=n-10
if 1<=a<=9:
    print('4')
elif a==10:
    print('15') #4 ten, 4 korol, 4 valeta, 3 dami
else:
    print('0')

n = int(input())

tmp = abs(10-n)

if tmp == 0 or n > 20 or n <= 10:
    print(0)
elif tmp < 10:
    print(4)
else: print(15)

n=int(input())
n-=10
if n<10:print(4)
elif n==10:print(15)
elif n==11:print(4)
else:print(0)

n = int(input())
n -= 10
if (n < 10 or n==1 or n == 11) and n > 1:
    print (4)
elif n < 1 or n > 11:
    print (0)
else:
    print (15)

n=int(input())
if n<=10 or n>=21:
    print(0)
else:
    x=n-10
    if x==1 or x==2 or x==3 or x==4 or x==4 or x==5 or x==6 or x==7 or x==8 or x==9 or x==11:
        print(4)
    elif x==10:
        print(15)
    elif x==12 or x==13 or x==14 or x==15:
        print(19)

#!/usr/bin/python3
n = int(input())
n-=10
if n <= 0 or n > 10:
    print(0)
elif n < 10:
    print(4)
elif n == 10:
    print(15)

N = int(input()) - 10
Counter = 0
if N == 0 and N>11:
    print(0)
    exit()
if N == 10:
    print(15)
else:
    print(4)

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--------------------------------#
n = get_int()
if n <= 10:
    print(0)
else:
    diff = n-10
    if diff == 11:
        print(4)
    elif diff == 1:
        print(8)
    elif diff <= 9:
        print(4)
    elif diff == 10:
        print(15)
    elif diff > 11:
        print(0)

n=int(input())
left = n-10
if left==10:
    print(15)
elif left==0 or left>11:
    print(0)
else:
    print(4)

n=int(input())
n=n-10
if n==0:
    print(0)
else:
    if n>=2 and n<10:
        print(4)
    elif n==10:
        print(15)
    elif n==1 or n==11:
        print(4)

n=int(input())
x=n-10
if x==0:
    print("0")
elif x==1 or x==11:
    print("4")
elif(x>=2 and x<=9):
    print("4")
else:
    print("15")

# -*- coding: cp932 -*-

#$BF~NO$7$?$b$N$rBeF~(B
input_str = raw_input()
input_num = int(input_str)

if(input_num >= 10 and input_num <= 19):
	print 4
elif(input_num == 20):
	print 15
elif(input_num == 21):
	print 4
else:
	print 0

n=int(raw_input())
if n<=10:
	print 0
elif n==11:
	print 8
elif n<=19:
	print 4
elif n==20:
	print 15
elif n==21:
	print 4
else:
	print 0

#!/usr/bin/env python
# -*- coding: utf-8 -*-
n = input()
if n <= 10:
    print 2
elif n == 20:
    print 15
elif n >= 22:
    print 0
else:
    print 4

n=int(input())
r=n-10
if(r==10):
  print(15)
elif(r==0):
  print(0)
else:
  print(4)

# import sys
# sys.stdin=open("input1.in","r")
# sys.stdout=open("output2.out","w")
N=int(input())
X=N-10
if X>=1 and X<=9:
	print(4)
elif X==10:
	print(15)
elif X==11:
	print(8)
elif X==0:
	print(0)
else:
	print(0)

n = int(raw_input()) - 10
if n == 10: print 15
elif n > 0 & n < 12: print 4
else: print 0

a = int(input())

if a <= 10:
	print(0)
else:
	if a == 20:
		print(15)
	else:
		print(4)

n = int(input())
kartu = 10
powarray = [1,2,3,4,5,6,7,8,9,11]
for i in range(len(powarray)):
    if(kartu + powarray[i]==n):
        print("4")
if(kartu + 10==n):
    print("15")
elif(n==10 or n>21):
    print("0")

n = int(input())
need = n-10
if need == 0 or n>21:
    print(0)
elif need == 10:
    print(15)
else:
    print(4)

n = int(raw_input())
n -= 10
if n == 11:
    print 1
elif n == 10:
    print 15
elif n in range(1, 10):
    print 4
else:
    print 0

n=int(raw_input())

n=n-10

if n==0 or n>10 or n<10:
 print 0
 exit(0)
if n==10:
 print 15
 exit(0)
print 4

n = int(input())
r = n-10
if r<=0:
    print(0)
elif r==10:
    print(15)
elif r in range(1,21):
    print(4)
else:
    print(0)

a = int(input())

if a <= 10 or a > 20:
	print(0)
else:
	if a == 20:
		print(15)
	else:
		print(4)

n = raw_input()
if n <= 10 or n>=22:
   print ("0")
else:
  if n == 20:
     print("15")
  else:
     print("4")

# -*- coding: utf-8 -*-
"""
Created on Sat Feb 22 14:50:02 2020

@author: Lenovo
"""

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

def black_jack():
    card = int(input())

    needed = card - 10

    if needed >= 1 and needed <= 9:
        print(4)
        return
    elif needed == 11:
        print(1)
        return
    elif needed == 10:
        print(15)
        return
    elif needed == 0 or needed > 11 or needed <= 0:
        print(0)
        return

black_jack()

N = int(input()) - 10
Counter = 0
if N == 0 or N>11:
    print(0)
    exit()
if N == 10:
    print(15)
else:
    print(4)

from sys import stdin, stdout
def stdinhack():
  for line in stdin: yield line
next_line = lambda: next(stdinhack()).split()
write = lambda x : stdout.write(x)

def solve ():
  n = int(next_line()[0])
  a = [1,2,3,4,5,6,7,8,9,10,10,10,10]
  ans = 0
  for k in a:
    if(10+k==n): ans+=1
  for k in a:
    if(10+k==n): ans+=1
  for k in a:
    if(10+k==n): ans+=1
  for k in a[:-1]:
    if(10+k==n): ans+=1
  print(ans)
  return

if __name__ == '__main__':
  solve()

# cook your dish here
from sys import stdin, stdout
import math
from itertools import permutations, combinations
from collections import defaultdict

def L():
    return list(map(int, stdin.readline().split()))

def In():
    return map(int, stdin.readline().split())

def I():
    return int(stdin.readline())

P = 1000000007
arr = [0, 4, 4, 4, 4, 4, 4, 4, 4, 4, 15, 4]
n = I()
if n-10 > 11:
    print(0)
else:
    print(arr[n-10])

x=input()-10
if x==0:
  print 0
elif x==10:
  print 15
elif x>21:
  print 0
else:
  print 4

# import sys
# sys.stdin=open("input.in","r")
n=int(input())
if n<=10 or n>=25:
	print(0)
elif n==20:
	print(15)
else:
	print(4)

import sys

input = lambda: sys.stdin.readline().strip("\r\n")

n = int(input())
n -= 10
if 1 < n < 10:
    print(4)
elif n == 1 or n == 1:
    print(4)
elif n == 10:
    print(15)
else:
    print(0)

n = int (input ())
if n<=10:
    print (0)
elif n-10==10:
    print (15)
elif n-10 == 1:
    print (8)
else:
    print (4)

n=int(input())
r=n-10
if(r==10):
  print(15)
elif(r==0):
  print(0)
else:
  print(4)

import itertools
from fractions import gcd
from math import sqrt
from bisect import bisect_left
import heapq
from collections import deque , defaultdict
from itertools import combinations as C
def Ls():
	return list(raw_input())
def get(a):
	return map(a , raw_input().split())
def Int():
	return int(raw_input())
def Str():
	return raw_input()
n = input() - 10
if n >= 2 and n <= 9:
	print 4
	exit(0)
if n == 10:
	print 15
	exit(0)
if n == 1 or n == 11:
	print 1
	exit(0)
print 0

n = int(input())

tmp = abs(10-n)

if tmp == 0 or n > 20:
    print(0)
elif tmp < 10:
    print(4)
else: print(15)

# your code goes here
n=int(input())
n-=10
if n<=0 or n>11:
	print (0)
if n==10:
	print (15)
else:
	print (4)

n=input()
x=n-10
res=0
if x>0 and x<21:
	if x==10:
		res=15
	elif x==1 or x==11:
		res=1
	else:
	    res=4
print(res)

n=int(input())
x=n-10
if x==0:
    print("0")
elif x==1 or x==11:
    print("4")
elif(x>=2 and x<=9):
    print("4")
else:
    print("15")

n = int(input()) - 10
if n <= 0 or n >= 12: print 0
elif n != 10: print 4
else: print 16

def solution(n):
    need=n-10
    if need<0:
        return 0
    else:
        a = []
        i=2
        while i<=9:
            a.append(i)
            a.append(i)
            a.append(i)
            a.append(i)
            i+=1
        while i==10:
            j=1
            while j<=15:
                a.append(10)
                j+=1
            i+=1
        while i==11:
            j=1
            while j<=4:
                a.append(11)
                j+=1
            i+=1
        ans=0
        while need in a:
            ans+=1
            a.remove(need)
        return ans

def answer():
    n=int(input())
    print(solution(n))
answer()

#!/usr/bin
n = int(raw_input())
if n <= 10 or n > 21:
    print 0
elif 12 <= n <= 19:
    print 4
elif n == 20:
    print 15
else: print 1

n=int(input())
d=n-10
if d<=0:
	print(0)
else:
	if d==10:
		print(15)
	else:
		print(4)

n = input()
n=n-10
if n<=0 or n>=12:
	print 0
elif n>=1 or n<=9:
	print 4
elif n==10:
	print 15
elif n==11:
	print 4

n = int(raw_input())
if n<=10 or n>=21:
	print 0
else :
	if n==20 :
		print 15
	else :
		print 4

n = input()

n = n-10

if n==11 or n==1:
    print(4)
elif n==10:
    print(15)
elif n==0:
    print(0)
elif n>11:
    print(0)
else:
    print(4)

#!/usr/bin/env python
# -*- coding: UTF-8 -*-
import time
import sys, io
import re, math
#start = time.clock()
n=int(raw_input())
#l=[int(x) for x in raw_input().split()]
if n<=10:
    print 0
elif n>=11 and n<=19:
    print 4
elif n==20:
    print 15
else:
    print 4

N=input()-10
if N>=2 and N<=11:
	if N==10:
		print 15
	else:
		print 4
else:
	print 0

n=int(input())
a=n-10
if 1<=a<=9:
    print('4')
elif a==10:
    print('15') #4 ten, 4 korol, 4 valeta, 3 dami
else:
    print('0')

n=int(input())
n=n-10
if n==1 or n==11:
	print(8)
elif n==10:
	print(15)
elif n<=0 or n>=12:
	print(0)
else:
	print(1)

n = int(input())
kartu = 10
powarray = [1,2,3,4,5,6,7,8,9,11]
for i in range(len(powarray)):
    if(kartu + powarray[i]==n):
        print("4")
if(kartu + 10==n):
    print("15")
elif(n==10 or n>11):
    print("0")

n=input()
x=n-10
res=0
if x>0 and x<21:
	if x==10:
		res=15
	else:
	    res=4
print(res)

n=int(raw_input())

n=n-10

if n==0 or n>10:
 print 0
 exit(0)
if n==10:
 print 15
 exit(0)
print 4

n=int(raw_input())

n=n-10

if n==0 or n>10 or n<10:
 print 0
 exit(0)
if n==10:
 print 15
 exit(0)
print 4

# your code goes here
n=int(input())
n-=10
if n<=0 or n>12:
	print (0)
if n==10:
	print (15)
else:
	print (4)

a = int(input())

if a <= 10 or a > 20:
	print(0)
else:
	if a == 20:
		print(15)
	else:
		print(4)

n=int(raw_input())

n=n-10

if n==0:
 print 0
 exit(0)
if n==10:
 print 15
 exit(0)
print 4

num = int(input())
d = num - 10
if d > 11 or d == 0:
    print(0)
elif d == 10:
    print(15)
else:
    print(4)

N = int(input()) - 10
Counter = 0
if N == 0:
    print(0)
    exit()
if N == 10:
    print(15)
else:
    print(4)

n=int(input())
left = n-10
if left==10:
    print(15)
elif left==0:
    print(0)
else:
    print(4)

n = int(input())
n = n-10
if n<=0:print(0)
elif n>10:print(0)
elif n==1: print(4)
elif n==10:print(15)
else:
    print(4)

"""  *** Author--Saket Saumya ***
            IIITM
"""
import math
from sys import stdin

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

n=ii()
s=n-10
if s==0:
	print('0')
if(s==1) or s==2 or s==3 or s==4 or s==5 or s==6 or s==7 or s==8 or s==9:
	print('4')
if(s==10):
	print('15')
if s==11:
	print('4')

n = int(input())

tmp = abs(10-n)

if tmp == 0 or n > 21 or n <= 10:
    print(0)
elif tmp < 10:
    print(4)
else: print(15)

n=int(input())
left = n-10
if left==10:
    print(15)
elif left==0 or left>11:
    print(0)
else:
    print(4)

n=int(input())
d=n-10
if((d>=1 and d<=9) or (d==11)):
    num=4
elif(d==0):
    num=0
else:
    num=15
print(num)

n= int(input())
if n<=10 or n>21:
  print 0
if n==20:
  print 15
else:
  print 4

#A. Blackjack
n = int(input())
req = n-10
if req == 0:
    print(0)
elif req<=9 or req==11:
    print(4)
elif req==10:
    print(15)
else:
    print(0)

p = input()

if p <= 10 or p > 21:
	print 0
elif p < 19:
	print 4
elif p == 20:
	print 15
elif p == 21:
	print 4

n=input()
x=n-10
res=0
if x>0 and x<11:
	if x==10:
		res=15
	elif x==1 or x==11:
		res=1
	else:
	    res=4
print(res)

n=int(input())
r=n-10
if(r==10):
  print(15)
elif(r==0 or r>11):
  print(0)
else:
  print(4)

n = int(input())
n -= 10
if n >= 1 and n <= 9:
    print(4)
elif n == 10:
    print(15)
else:
    print(0);

# import sys
# sys.stdin=open("input1.in","r")
# sys.stdout=open("output2.out","w")
N=int(input())
X=N-10
if X>=1 and X<=9:
	print(4)
elif X==10:
	print(15)
elif X==11:
	print(8)
elif X==0:
	print(0)
elif X>13:
	print(0)
else:
	print(4)

n = int(input()) - 10
if n == 1 or n == 11:
    print(1)
elif n > 1 and n < 10:
    print(4)
elif n == 10:
    print(15)
else:
    print(0)

x=input()-10
if x==0:
  print 0
elif x==10:
  print 15
elif x>21:
  print 0
else:
  print 4

n = int(input())
need = n-10
if need == 0 or n>21:
    print(0)
elif need == 10:
    print(15)
else:
    print(4)

n = int(input())

diff = n - 10

if diff>=10:
    print(0)
elif diff>10 and diff<20:
    print(4)
elif diff==20:
    print(15)
else:
    print(4)

n = int (input ())
if n<=10:
    print (0)
elif n-10==10:
    print (15)
else:
    print (4)

n = int(input()) - 10
if n <= 0 or n >= 12:
    print 0
elif n != 10:
    print 4
else: print 12

n=input()
if n<=10 or n>21:
    print 0

if 19>=n>=12:
    print 4
if n==20:
    print 15


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)))