#include <iostream>
#include <sstream>
#include <vector>
#include <cctype>
using namespace std;

int main(){
    string s;
    getline(cin, s);
    
    if (s.find('-') != string::npos){
        cout << "Invalid input";
        return 0;
    }
    stringstream ss(s);
    string word;
    vector<pair<int, string>> words;
    
    while (ss >> w){
        int pos = -1;
        string clean = "";
        
        for (int i = 0; i < word.length(); i++) {
            if (isdigit(W[i])) {
                 pos = word[i] - 'o';
                } else {
                    clean += word[i];
                }
        }
        words.push_back(make_pair(pos,clean));
    }
     sort(words.begin(), words.end());
     
     for (int i = 0; i < words.size();++){
         cout << words[i].second;
         if (i != words.size() - 1)
         cout << " ";
     }
    return 0;
}