#include <bits/stdc++.h>
struct CCycle {
  std::map<int, int> pos;
  int len;
};
int classes[200100];
int num[200100];
int hash[200100];
int hsize, m;
std::map<int, int> objMap;
std::vector<CCycle> cycleList;
std::vector<int> start;
inline int next(int p) {
  p += m;
  if (p >= hsize) p -= hsize;
  return p;
}
int main() {
  int n;
  scanf("%d %d %d", &hsize, &m, &n);
  memset(classes, -1, sizeof(classes));
  for (int i = 0; i < hsize; ++i)
    if (classes[i] == -1) {
      int curClass = cycleList.size();
      CCycle c;
      int l = 0;
      for (int j = i; classes[j] == -1; j = next(j)) {
        classes[j] = curClass;
        num[j] = l;
        c.pos.insert(std::make_pair(l, j));
        ++l;
      }
      c.len = l;
      cycleList.push_back(c);
      start.push_back(i);
    }
  long long sum = 0;
  for (int i = 0; i < n; ++i) {
    char op[5];
    scanf("%s", op);
    if (op[0] == '+') {
      int id, key;
      scanf("%d %d", &id, &key);
      int cls = classes[key];
      int nn = num[key];
      std::map<int, int>::iterator it = cycleList[cls].pos.lower_bound(nn);
      if (it == cycleList[cls].pos.end()) {
        it = cycleList[cls].pos.begin();
      }
      int dist = it->first - nn;
      if (dist < 0) dist += cycleList[cls].len;
      int p = it->second;
      hash[p] = it->first;
      objMap[id] = p;
      sum += dist;
      cycleList[cls].pos.erase(it);
    } else {
      int id;
      scanf("%d", &id);
      std::map<int, int>::iterator it = objMap.find(id);
      if (it != objMap.end()) {
        int nn = hash[it->second];
        int cls = classes[it->second];
        cycleList[cls].pos.insert(std::make_pair(nn, it->second));
        objMap.erase(it);
      }
    }
  }
  printf("%I64d", sum);
  return 0;
}
