#include <iostream>
#include <string>
// return true if all characters ('0' or '1') in the range [x,y] are the same
bool is_same( const std::string& str, unsigned long x, unsigned long y )
{
if( x > y || str.size() < (y-1) ) return false ;
return ( str[x] == '0' || str[x] == '1' ) &&
str.find_first_not_of( str[x], x ) > y ;
}
int main ()
{
std::string str ;
std::cout << "enter a string and press RETURN\n" ;
std::getline( std::cin, str ) ; // 10110111111111111000111000001110001110001
std::cout << "string: " << str << '\n' ;
std::size_t x = 5 ;
std::size_t y = 15 ;
if( is_same( str, x, y ) ) std::cout << "Yes\n" ;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8c3RyaW5nPgoKLy8gcmV0dXJuICB0cnVlIGlmIGFsbCBjaGFyYWN0ZXJzICgnMCcgb3IgJzEnKSBpbiB0aGUgcmFuZ2UgW3gseV0gYXJlIHRoZSBzYW1lCmJvb2wgaXNfc2FtZSggY29uc3Qgc3RkOjpzdHJpbmcmIHN0ciwgdW5zaWduZWQgbG9uZyB4LCB1bnNpZ25lZCBsb25nIHkgKQp7CiAgICBpZiggeCA+IHkgfHwgc3RyLnNpemUoKSA8ICh5LTEpICkgcmV0dXJuIGZhbHNlIDsKICAgIHJldHVybiAoIHN0clt4XSA9PSAnMCcgfHwgc3RyW3hdID09ICcxJyApICYmCiAgICAgICAgICAgIHN0ci5maW5kX2ZpcnN0X25vdF9vZiggc3RyW3hdLCB4ICkgPiB5IDsKfQoKaW50IG1haW4gKCkKewogICAgc3RkOjpzdHJpbmcgc3RyIDsKICAgIHN0ZDo6Y291dCA8PCAiZW50ZXIgYSBzdHJpbmcgYW5kIHByZXNzIFJFVFVSTlxuIiA7CiAgICBzdGQ6OmdldGxpbmUoIHN0ZDo6Y2luLCBzdHIgKSA7IC8vIDEwMTEwMTExMTExMTExMTExMDAwMTExMDAwMDAxMTEwMDAxMTEwMDAxCiAgICBzdGQ6OmNvdXQgPDwgInN0cmluZzogIiA8PCBzdHIgPDwgJ1xuJyA7CiAgICBzdGQ6OnNpemVfdCB4ID0gNSA7CiAgICBzdGQ6OnNpemVfdCB5ID0gMTUgOwogICAgaWYoIGlzX3NhbWUoIHN0ciwgeCwgeSApICkgc3RkOjpjb3V0IDw8ICJZZXNcbiIgOwp9Cg==