program prob5
    implicit none
    integer(8)::K,S,i,j,ans
    read(*,*) K,S

    ans = 0
    do i = 0, K
        if(i <= S .and. S-i <= 2*K) then
            if(S-i <= K)then
                ans = ans + (S-i) + 1
            else
                ans = ans + 2*K - (S-i) + 1
            end if
        end if
    end do
    write(*,*) ans
    stop
end program