#!/bin/sh
  
read N

a3=$(( $N / 1000 ))
a2=$(( (( $N - (( $a3 * 1000 )) )) / 100 ))
a1=$(( (($N - (( $a3 * 1000 )) - (( $a2 * 100 )) )) / 10 ))
a0=$(( $N - (( $a3 * 1000 )) - (( $a2 * 100 )) - (( $a1 * 10 )) ))

if [ $a0 -eq $a1 ] && [ $a1 -eq $a2 ]
then
        echo Yes
elif [ $a1 -eq $a2 ] && [ $a2 -eq $a3 ]
then
        echo Yes
else
        echo No
fi
~            