#include <bits/stdc++.h>   using namespace std;   const int N = 200005;   int cycl[N], set_val[N], cycl_size[N];   int main() {     int h, m, n;     cin >> h >> m >> n;     vector<int> strt;     bool vis[h];     memset(vis, false, sizeof vis);     int kk = 0;     set<int> dmm[h + 1];     for (long long i = 0; i < m; i++) {       if (vis[i]) {         continue;       }       int ii = i;       int jp = 0;       while (1) {         if (vis[ii]) {           break;         }         set_val[ii] = jp;         cycl[ii] = kk;         dmm[kk].insert(jp);         vis[ii] = true;         ii += m;         ii %= h;         jp++;       }       cycl_size[kk] = jp;       kk++;     }     map<int, int> hash;     map<int, int> final;     long long cnt = 0;     while (n--) {       char ch;       scanf(  %c , &ch);       if (ch ==  + ) {         int id, t;         scanf( %d%d , &id, &t);         hash[id] = t;         if (dmm[cycl[t]].find(set_val[t]) != dmm[cycl[t]].end()) {           final[id] = set_val[t];           dmm[cycl[t]].erase(set_val[t]);           continue;         }         set<int>::iterator it, it1;         it = dmm[cycl[t]].lower_bound(set_val[t]);         int xx1;         if (it == dmm[cycl[t]].end()) {           it = dmm[cycl[t]].begin();           xx1 = cycl_size[cycl[t]] + *it - set_val[t];           int jj = *it;           final[id] = jj;           dmm[cycl[t]].erase(jj);         } else {           xx1 = *it - set_val[t];           int jj = *it;           final[id] = jj;           dmm[cycl[t]].erase(jj);         }         cnt += (long long)xx1;       } else {         int id;         scanf( %d , &id);         dmm[cycl[hash[id]]].insert(final[id]);       }     }     cout << cnt << endl;   }   