#include using namespace std; using ll = long long; #define FOR(i, l, r) for(ll i = l; i < r; i++) #define rep(i, n) FOR(i, 0, n) #define FORR(i, l, r) for(ll i = r - 1; i >= l; i--) #define ALL(ar) begin(ar), end(ar) template inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); } template inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); } template istream &operator>>(istream &is, pair &p) { is >> p.first >> p.second; return is; } template ostream &operator<<(ostream &os, const pair &p) { os << p.first << ' ' << p.second; return os; } template istream &operator>>(istream &is, vector &v) { for(T &x : v) is >> x; return is; } template ostream &operator<<(ostream &os, const vector &v) { for(size_t i = 0; i < v.size(); i++) os << (i ? " " : "") << v[i]; return os; } //------------------------------------------------- void solve() { int n; cin >> n; vector s(n); cin >> s; for(auto &st : s) { for(char c = 'a'; c <= 'z'; c++) { if(c == 'z') { bool ok = false; for(c = 'a'; c <= 'z'; c++) { if(count(ALL(st), c) >= 2) ok = true; } if(!ok) swap(st[st.size() - 1], st[st.size() - 2]); break; } if(count(ALL(st), c) == 0) continue; int j = st.size() - 1; while(st[j] != c) j--; int i = 0; while(i < st.size() && st[i] <= c) i++; if(i < j) { swap(st[i], st[j]); break; } } } auto mn = *min_element(ALL(s)); // cout << mn << endl; int score = n + 1 - count(ALL(s), mn); rep(i, n) { if(s[i] == mn) cout << score << endl; else cout << 0 << endl; } } int main() { int t = 1; // cin >> t; while(t--) solve(); }