n=input() s=raw_input() c=s.count print"YES"*(n>3or c("11")+c("00"))or"NO"