Source Code
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
using namespace std;
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

const int OO = 1e9+7 ,N=1e5+5;

int dx[] = { 0, 0, 1, -1, 1, -1, 1, -1 }; // dir array
int dy[] = { 1, -1, 0, 0, 1, -1, -1, 1 };
void File(){
#ifndef ONLINE_JUDGE
    freopen("Input.txt", "r", stdin);
    freopen("Output.txt", "w", stdout);
#endif
}

int solve(){
    int n;cin>>n;
    map<string,set<int>>mp;
    string s;
    while(n--){
        cin>>s;
        string t=s,temp;
        while(t.back()<='9'){
            temp = t.back()+temp;
            t.pop_back();
            mp[t].insert(stoi(temp));
        }
        if(mp[s].empty()){
            cout<<"ok\n";
            mp[s].insert(0);
            continue;
        }
        int i=0;
        for(auto j:mp[s]){
            if(i!=j)break;
            i++;
        }
        mp[s].insert(i);
        mp[s+ to_string(i)].insert(0);
        cout<<s<<i<<'\n';

    }


    return 0;
}
int main() {
    File();
    ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
//    int t,i=1;cin>>t;
//    while(t--)
        solve();

}
//Solve on paper first
//Overflooooooow
//Reverse Thinking
//If there's an equation, transform it into an easy one
//READ ALL PROBLEMS
//Verify Your thought before Coding
Copy
Registration System ahmes
GNU G++17
3073 ms
4.5 MB
Time Limit Exceeded