do whatever is asked...sort and simulate it
Complexity
Time complexity:O(numberOfUsers*events.length)

Space complexity:O(numberOfUsers)
Code

# Complexity
- Time complexity:```O(numberOfUsers*events.length)```
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity:```O(numberOfUsers)```
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```cpp []
bool comp(vector<string> &a,vector<string> &b){
    if(a[1]==b[1])
    {
        if(a[0]=="OFFLINE") return 1;
        else return 0;
    }
    if(a[1].size()==b[1].size()) 
    return a[1]<b[1];
    return a[1].size()<b[1].size();
    
}

class Solution {
public:
    vector<int> countMentions(int numberOfUsers, vector<vector<string>>& events) {
        map<int,int>m;
        map<int,pair<int,int>>tmout;
        sort(events.begin(),events.end(),comp);
        for(auto val:events){
            for(auto x:val)
            cout<<x<<" ";
            cout<<endl;
        }
        for(auto val:events){
            if(val[0]=="MESSAGE"){
                if(val[2]=="ALL"){
                    for(int i=0;i<numberOfUsers;i++) m[i]++;
                }
                else if(val[2]=="HERE"){
                    for(int i=0;i<numberOfUsers;i++){
                        auto x=tmout[i];
                        int timestmp=std::stoi(val[1]);
                        if(timestmp>=x.second) m[i]++;
                    }
                }
                else{
                string str=val[2];
                string aux="";
                for(int i=0;i<str.size();i++){
                    if(str[i]==' ') {

                        m[std::stoi(aux)]++;
                        aux="";
                        continue;
                    }
                     if(str[i]!='i' and str[i]!='d' ){
                        aux+=str[i];
                    }
                }
                m[std::stoi(aux)]++;

                }
            }
            else{
                tmout[std::stoi(val[2])]={std::stoi(val[1]),std::stoi(val[1])+60};
            }
        }
        vector<int> ans;
        for(int i=0;i<numberOfUsers;i++){
            ans.push_back(m[i]);
        }
        return ans;
    }
};
```
['C++']