#include <bits/stdc++.h>
using namespace std;
class ftree {
  vector<int> t;

 public:
  int n;
  ftree(int nn) {
    n = nn;
    t.assign(n, 0);
  }
  int sum(int r) {
    int result = 0;
    for (; r >= 0; r = (r & (r + 1)) - 1) result += t[r];
    return result;
  }
  void inc(int i, int delta) {
    for (; i < n; i = (i | (i + 1))) t[i] += delta;
  }
  int sum(int l, int r) {
    r %= n;
    if (l <= r)
      return sum(r) - sum(l - 1);
    else
      return sum(n - 1) - sum(l - 1) + sum(r);
  }
  int add(int k) {
    int l = -1, r = n - 1;
    while (r - l > 1) {
      int q = (l + r) / 2;
      int cq = sum(k, k + q);
      if (cq == q + 1)
        l = q;
      else
        r = q;
    }
    inc((k + r) % n, 1);
    return r;
  }
  void remove(int k) { inc(k, -1); }
};
int main() {
  int h, m, n;
  scanf("%d%d%d", &h, &m, &n);
  vector<int> used(h, 0), w(h, 0), u(h, 0);
  vector<ftree> v;
  for (int i = (0); i <= ((h)-1); i++)
    if (!used[i]) {
      int nc = 0;
      for (int j = i; !used[j]; j += m, j %= h) {
        w[j] = v.size();
        u[j] = nc++;
        used[j] = true;
      }
      v.push_back(ftree(nc));
    }
  map<int, int> idtohash;
  long long res = 0;
  for (int i = (0); i <= ((n)-1); i++) {
    char c = '1';
    while (c != '+' && c != '-') scanf("%c", &c);
    if (c == '+') {
      int hash, id;
      scanf("%d%d", &id, &hash);
      int cnt = v[w[hash]].add(u[hash]);
      res += cnt;
      idtohash[id] = (hash + cnt * m) % h;
    } else {
      int id;
      scanf("%d", &id);
      int hash = idtohash[id];
      v[w[hash]].remove(u[hash]);
    }
  }
  cout << res << endl;
  return 0;
}
