program good
 implicit none
 integer :: N, A, B, C, D
 read(*,*) N
 A = N /1000
 B = (N -A*1000) /100
 C = (N - A*1000 - B*100) /10
 D = N -A*1000 -B*100 -C*10
 if( A == B .and. A == C ) then
 	write(*,*) "Yes"
 else if( B == C .and. B == D) then
 	write(*,*) "yes"
 else
 	write(*,*) "No"
 end if
end program good