program name

    implicit none
    integer K,S,X,Y,Z
    integer counter
    read*, K,S
    counter = 0
    do X = 0, K, 1
        do Y = 0, K, 1
            do Z = 0, K, 1
                if ( X+Y+Z==S ) then
                    counter = counter + 1
                end if
            end do
        end do
    end do
print*, counter
end program