#include <bits/stdc++.h>
using namespace std;
using namespace std;
const int N = 200500;
struct FWTree {
  int sz;
  int* fw;
  FWTree() { sz = 0; }
  FWTree(int sz) {
    this->sz = sz;
    fw = new int[sz + 10];
    for (int i = 0; i < sz + 10; i++) fw[i] = 0;
  }
  void update(int pos, int add) {
    while (pos <= sz) {
      fw[pos] += add;
      pos |= (pos + 1);
    }
  }
  void addElement(int pos) { update(pos, 1); }
  void deleteElement(int pos) { update(pos, -1); }
  int getSum(int r) {
    int ret = 0;
    while (r > 0) {
      ret += fw[r];
      r = (r & (r + 1)) - 1;
    }
    return ret;
  }
  pair<int, int> getNext(int pos) {
    int resultIdx, resultAns;
    int len = sz - pos + 1;
    int le, ri, mid, decPos;
    if (getSum(sz) - getSum(pos - 1) == len) {
      resultAns = len;
      le = 1;
      ri = pos - 1;
      decPos = 0;
    } else {
      resultAns = 0;
      le = pos;
      ri = sz;
      decPos = pos - 1;
    }
    while (le < ri) {
      mid = (le + ri) >> 1;
      len = mid - decPos;
      if (getSum(mid) - getSum(decPos) == len) {
        le = mid + 1;
      } else {
        ri = mid;
      }
    }
    resultAns += (ri - decPos - 1);
    resultIdx = ri;
    return make_pair(resultIdx, resultAns);
  }
};
bool used[N];
int cycleId[N];
int cyclePos[N];
map<int, pair<int, int> > values;
map<int, pair<int, int> >::iterator it;
int main() {
  int n, m, q;
  scanf("%d%d%d\n", &n, &m, &q);
  vector<FWTree> fws;
  for (int i = 0; i < n; i++) {
    if (used[i]) {
      continue;
    }
    int ptr = 0;
    set<int> idxs;
    int idx = i;
    while (true) {
      if (idxs.find(idx) != idxs.end()) break;
      cyclePos[idx] = ++ptr;
      idxs.insert(idx);
      idx = (idx + m) % n;
    }
    int id = (int)fws.size();
    fws.push_back(FWTree((int)idxs.size()));
    for (set<int>::iterator it = idxs.begin(); it != idxs.end(); it++) {
      ++ptr;
      cycleId[*it] = id;
      used[*it] = true;
    }
    idxs.clear();
  }
  long long ans = 0LL;
  while (q--) {
    char type;
    scanf("%c", &type);
    if (type == '-') {
      int id;
      scanf("%d", &id);
      it = values.find(id);
      fws[it->second.first].deleteElement(it->second.second);
      values.erase(it);
    } else {
      int id, h;
      scanf("%d%d", &id, &h);
      h = (h % n);
      pair<int, int> inserted = fws[cycleId[h]].getNext(cyclePos[h]);
      fws[cycleId[h]].addElement(inserted.first);
      ans += (1LL * inserted.second);
      values.insert(make_pair(id, make_pair(cycleId[h], inserted.first)));
    }
    if (q > 0) {
      scanf("\n");
    }
  }
  printf("%I64d\n", ans);
  return 0;
}
