#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:64000000")
template <class T>
inline T sqr(T x) {
  return x * x;
}
struct RSQ {
  int n;
  vector<int> tr;
  RSQ(int n) {
    this->n = n;
    tr.resize(2 * n);
  }
  void update(int i, int dx) {
    for (; i < (int)((tr).size()); i |= i + 1) tr[i] += dx;
  }
  int get(int i) {
    int res = 0;
    for (; i >= 0; i = (i & (i + 1)) - 1) res += tr[i];
    return res;
  }
  int get(int l, int r) { return get(r) - get(l - 1); }
};
int n, m, T;
int color[1 << 18];
int order[1 << 18];
map<int, int> pos, hashes;
vector<RSQ> rsq;
inline pair<int, int> find_place(int rid, int x) {
  int l = x, r = x + rsq[rid].n - 1;
  int sl = rsq[rid].get(x - 1);
  while (l < r) {
    int m = (l + r - 1) >> 1;
    int sum = rsq[rid].get(m) - sl;
    if (sum < (m - x + 1))
      r = m;
    else
      l = m + 1;
  }
  return make_pair(r % rsq[rid].n, r - x);
}
int main() {
  scanf("%d%d%d", &n, &m, &T);
  memset(color, -1, sizeof color);
  for (int i = 0; i < n; ++i) {
    if (color[i] != -1) continue;
    int cnt = 0;
    for (int x = i; color[x] == -1; x = (x + m) % n, ++cnt)
      color[x] = (int)((rsq).size()), order[x] = cnt;
    rsq.push_back(RSQ(cnt));
  }
  long long res = 0;
  for (; T--;) {
    char op;
    int id;
    scanf("\n%c\n%d", &op, &id);
    if (op == '+') {
      int h;
      scanf("%d", &h);
      hashes[id] = h;
      int rid = color[h];
      pair<int, int> cur = find_place(rid, order[h]);
      res += cur.second;
      pos[id] = cur.first;
      rsq[rid].update(cur.first, +1);
      rsq[rid].update(cur.first + rsq[rid].n, +1);
    }
    if (op == '-') {
      int rid = color[hashes[id]];
      int p = pos[id];
      rsq[rid].update(p, -1);
      rsq[rid].update(p + rsq[rid].n, -1);
      pos.erase(id);
      hashes.erase(id);
    }
  }
  cout << res << endl;
  return 0;
}
