program prob1
    implicit none
    integer::n
    read(*,*) n
    if(mod(n/10,111) == 0 .or. mod(n,1111) == 0 .or. mod(n-n/1000*1000,111) == 0) then
        write(*,'(a)') "Yes"
    else
        write(*,'(a)') "No"
    end if
    stop
end program