#include <bits/stdc++.h>
using namespace std;
vector<set<int> > f;
vector<int> ssize;
vector<pair<int, int> > dd;
int main() {
  int n, m, h;
  cin >> h >> m >> n;
  dd.resize(h);
  for (int i = 0; i < h; ++i) {
    dd[i] = make_pair(-1, -1);
  }
  for (int i = 0; i < h; ++i) {
    if (dd[i].first == -1) {
      int gg = f.size();
      set<int> ss;
      int ff = 0;
      int j = i;
      while (dd[j].first == -1) {
        dd[j].first = gg;
        dd[j].second = ff;
        ss.insert(ff);
        ++ff;
        j = (j + m) % h;
      }
      ssize.push_back(ff);
      f.push_back(ss);
    }
  }
  map<int, pair<int, int> > fr;
  long long superres = 0;
  for (int opn = 0; opn < n; ++opn) {
    char c;
    cin >> c;
    if (c == '-') {
      int id;
      cin >> id;
      pair<int, int> zzz = fr[id];
      f[zzz.first].insert(zzz.second);
    } else {
      int id, hash;
      cin >> id >> hash;
      int gg = dd[hash].first;
      int zzz = dd[hash].second;
      int rr = 0;
      int tres = 0;
      set<int>::iterator it = f[gg].lower_bound(zzz);
      if (it == f[gg].end()) {
        it = f[gg].lower_bound(0);
        tres = *it;
        rr = ssize[gg] - zzz + tres;
      } else {
        tres = *it;
        rr = tres - zzz;
      }
      f[gg].erase(tres);
      superres += rr;
      fr[id] = make_pair(gg, tres);
    }
  }
  cout << superres << endl;
}
