#include <bits/stdc++.h>
using namespace std;
inline void pisz(int n) { printf("%d\n", n); }
template <typename T, typename TT>
ostream &operator<<(ostream &s, pair<T, TT> t) {
  return s << "(" << t.first << "," << t.second << ")";
}
template <typename T>
ostream &operator<<(ostream &s, vector<T> t) {
  for (int(i) = 0; (i) < (((int)(t.size()))); ++(i)) s << t[i] << " ";
  return s;
}
set<int> wolne[100007];
int posInCycle[100007], whichCycle[100007];
int main() {
  int(h), (m);
  scanf("%d %d", &(h), &(m));
  int ktorycykl = 0, rozmiarCykli;
  vector<bool> vis(h + 5, 0);
  for (int(i) = 0; (i) < (h); ++(i)) {
    if (vis[i]) continue;
    int v = i;
    vector<int> cykl;
    do {
      cykl.push_back(v);
      v = (m + v) % h;
      vis[v] = 1;
    } while (v != i);
    for (int(u) = 0; (u) < (((int)(cykl.size()))); ++(u)) {
      whichCycle[cykl[u]] = ktorycykl;
      posInCycle[cykl[u]] = u;
      wolne[ktorycykl].insert(u);
    }
    ++ktorycykl;
    rozmiarCykli = ((int)(cykl.size()));
  }
  map<int, pair<int, int> > position;
  long long res = 0;
  int(testow);
  scanf("%d", &(testow));
  while (testow--) {
    char c;
    scanf(" %c", &c);
    if (c == '+') {
      int(id), (hash);
      scanf("%d %d", &(id), &(hash));
      int desiredPosInCycle = posInCycle[hash], ktorycykl = whichCycle[hash];
      set<int> &wol = wolne[ktorycykl];
      set<int>::iterator it = wol.lower_bound(desiredPosInCycle);
      bool obrot = 0;
      if (it == wol.end()) {
        it = wol.begin();
        obrot = 1;
      }
      int posWCyklu = *it;
      wol.erase(it);
      position[id] = make_pair(ktorycykl, posWCyklu);
      res += (obrot ? rozmiarCykli - desiredPosInCycle + posWCyklu
                    : posWCyklu - desiredPosInCycle);
    } else {
      int(id);
      scanf("%d", &(id));
      pair<int, int> pos = position[id];
      wolne[pos.first].insert(pos.second);
    }
  }
  cout << res << endl;
}
