#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
using namespace std;
void out(const vector<string>& v)
{
copy(v.begin(), v.end(), ostream_iterator<string>(cout, " "));
}
int main() {
string s;
vector<string> v;
while (cin >> s) v.push_back(s);
sort(v.begin(), v.end());
out(v);
cout << endl;
cout << binary_search(v.begin(), v.end(), "bba") << endl;
cout << binary_search(v.begin(), v.end(), "aab") << endl;
cout << lower_bound(v.begin(), v.end(), "bba") - v.begin() << ' ';
cout << upper_bound(v.begin(), v.end(), "bba") - v.begin() << endl;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dmVjdG9yPgojaW5jbHVkZSA8YWxnb3JpdGhtPgojaW5jbHVkZSA8aXRlcmF0b3I+CiAKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKIAp2b2lkIG91dChjb25zdCB2ZWN0b3I8c3RyaW5nPiYgdikKewogICAgICAgIGNvcHkodi5iZWdpbigpLCB2LmVuZCgpLCBvc3RyZWFtX2l0ZXJhdG9yPHN0cmluZz4oY291dCwgIiAiKSk7Cn0KIAppbnQgbWFpbigpIHsKICAgICAgICBzdHJpbmcgczsKICAgICAgICB2ZWN0b3I8c3RyaW5nPiB2OyAgICAgICAKICAgICAgICB3aGlsZSAoY2luID4+IHMpIHYucHVzaF9iYWNrKHMpOwogICAgICAgIAogICAgICAgIHNvcnQodi5iZWdpbigpLCB2LmVuZCgpKTsgICAgICAgCiAgICAgICAgb3V0KHYpOwogICAgICAgIGNvdXQgPDwgZW5kbDsgICAKICAgICAgICBjb3V0IDw8IGJpbmFyeV9zZWFyY2godi5iZWdpbigpLCB2LmVuZCgpLCAiYmJhIikgPDwgZW5kbDsKICAgICAgICBjb3V0IDw8IGJpbmFyeV9zZWFyY2godi5iZWdpbigpLCB2LmVuZCgpLCAiYWFiIikgPDwgZW5kbDsKICAgICAgICBjb3V0IDw8IGxvd2VyX2JvdW5kKHYuYmVnaW4oKSwgdi5lbmQoKSwgImJiYSIpIC0gdi5iZWdpbigpIDw8ICcgJzsKICAgICAgICBjb3V0IDw8IHVwcGVyX2JvdW5kKHYuYmVnaW4oKSwgdi5lbmQoKSwgImJiYSIpIC0gdi5iZWdpbigpIDw8IGVuZGw7ICAgICAKICAgICAgICByZXR1cm4gMDsKfQ==