#include using namespace std; bool comp(string x, string y) { string a = "DCHS", b = "A23456789TJQK"; int xx, yy; for(int i = 0; i < a.size(); i++) { if(x[0] == a[i]) xx = i + 1; if(y[0] == a[i]) yy = i + 1; } xx *= 1000; yy *= 1000; for(int i = 0; i < b.size(); i++) { if(x[1] == b[i]) xx += i; if(y[1] == b[i]) yy += i; } return xx < yy; } int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector s(n); for(int i = 0; i < n; i++) { cin >> s[i]; } sort(s.begin(), s.end(), comp); for(int i = 0; i < n; i++) { if(i > 0) cout << " "; cout << s[i]; } cout << endl; return 0; }