#include <iostream>
#include <algorithm>
#include <string>
#include <cctype>
#include <vector>
#include <iterator>

using namespace std;

int main() {
    std::vector <std::string> StringVect = { "BB", "-", "", "0", "+", "aA", "12", "b", "AA", "&", "[", "**", "1" };

    std::sort(StringVect.begin(), StringVect.end(), []
        (const std::string& s1, const std::string& s2)
    {
        if (s1.empty() || s2.empty()) 
            return s1 < s2;
                        
        bool ac[] = { isalpha(s1[0]), isalpha(s2[0]),
                      isdigit(s1[0]), isdigit(s2[0]),
                      !isalnum(s1[0]), !isalnum(s2[0]) };

        // If both strings start with the same type, then just return the
        // lesser one            
        if ((ac[0] && ac[1]) || (ac[2] && ac[3]) || (ac[4] && ac[5]))
            return s1 < s2;
        return (ac[0] || ac[5]);
    });
    copy(StringVect.begin(), StringVect.end(), ostream_iterator<string>(cout, "\n"));
}