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,int>mp;
    string s;
    while(n--){
        cin>>s;
        if(!mp[s]){
            cout<<"ok\n";
            mp[s]=1;
            continue;
        }
        int i=mp[s];
        while(mp[s+ to_string(i)]){
            i++;
        }
        cout<<s<<i<<'\n';
        mp[s]=i+1;
        mp[s+ to_string(i)]=1;
    }

    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
187 ms
9.9 MB
Accepted