Source Code
#include <bits/stdc++.h>

using namespace std;
#define Achilles ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define ll long long
#define pp push_back
#define M 1000000007
const int N = 200005;
const int INF = 1000000;
int dx[] = {-1, +0, +0, +1, +1, -1, +1, -1};
int dy[] = {+0, -1, +1, +0, +1, -1, -1, +1};
int kx[] = {+1, -1, +2, +2, -2, -2, +1, -1};
int ky[] = {+2, +2, +1, -1, +1, -1, -2, -2};

void Achilles1() {
    int n;
    cin >> n;
    string s;
    map<string, ll> f;
    for (int i = 0; i < n; ++i) {
        cin >> s;
        if (f.count(s)) {
            ll k = f[s];
            while (f.count(s + to_string(k))) {
                k++;
            }
            f[s + to_string(k)]++;
            f[s] = k + 1;
            s = s + to_string(k);
            cout << s << '\n';
        }
        else {
            cout << "ok\n";
            f[s]++;
        }
    }
}

//XD
int main() {
    Achilles

    int tt = 1;
//    cin >> tt;
    while (tt--) Achilles1();

}
Copy
Registration System Yalahwy
GNU G++17
195 ms
9.7 MB
Accepted