#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;
}