#include <bits/stdc++.h>
using namespace std;
const int maxn = 420000, maxlen = 502 * 502 + 20, consta = 1050,
          maxi = consta + 4, big = 10000000, magic = 239, magic1 = 359;
const long long INF = 1000000000;
const char BLANK = '-', FULL = '#';
int usd[maxn], numb[maxn], wha[maxn], first[maxn], hom[maxn];
set<pair<int, int> > who[maxn];
int main() {
  int h, m, n;
  scanf("%d %d %d", &h, &m, &n);
  int len = 0, lon = 0;
  ;
  for (int i = 0; i < h; ++i)
    if (!usd[i]) {
      first[lon] = i;
      usd[i] = 1;
      wha[i] = lon;
      numb[i] = len;
      ++hom[lon];
      who[lon].insert(make_pair(len, i));
      i = (i + m) % h;
      ++len;
      while (usd[i] == 0) {
        ++hom[lon];
        usd[i] = 1;
        wha[i] = lon;
        numb[i] = len;
        who[lon].insert(make_pair(len, i));
        i = (i + m) % h;
        ++len;
      }
      ++lon;
    }
  map<int, pair<int, int> > where;
  int id, hash;
  set<pair<int, int> >::iterator it;
  long long res = 0, inc;
  for (int i = 0; i < n; ++i) {
    if (scanf(" + %d %d", &id, &hash) == 2) {
      it = who[wha[hash]].lower_bound(make_pair(numb[hash], 0));
      if (it != who[wha[hash]].end()) {
        inc =
            ((it->first - first[wha[hash]]) - (numb[hash] - first[wha[hash]]));
        res += inc;
        where[id] = make_pair(wha[hash], it->second);
        who[wha[hash]].erase(it);
        ;
      } else {
        it = who[wha[hash]].begin();
        where[id] = make_pair(wha[hash], it->second);
        inc = hom[wha[hash]] - (numb[hash] - first[wha[hash]]) +
              (it->first - first[wha[hash]]);
        res += inc;
        who[wha[hash]].erase(it);
      }
    } else if (scanf(" - %d", &id) == 1) {
      int classf = where[id].first;
      int il = where[id].second;
      who[classf].insert(make_pair(numb[il], il));
    } else {
      cout << "ERROR!\n";
      return 1;
    }
  }
  cout << res << endl;
}
