#include <bits/stdc++.h>
using namespace std;
map<int, int> pos;
long long ans;
int ss[204800], tt[204800], h, m, n, g;
struct xxx {
  vector<int> s;
  int n;
  xxx() {}
  void init(int nn) {
    n = nn;
    s.resize(n + 1, 0);
  }
  void add(int x) {
    for (int k = x; k <= n; k += ((k) & (-k))) ++s[k];
  }
  void minus(int x) {
    for (int k = x; k <= n; k += ((k) & (-k))) --s[k];
  }
  int sum(int x) {
    int ret = 0, k;
    for (k = x; k; k -= ((k) & (-k))) ret += s[k];
    return ret;
  }
  int findnext(int x) {
    int l, r, t, m;
    if ((sum(n)) - (t = sum(x - 1)) < n - x + 1) {
      for (l = x - 1, r = n; l + 1 < r;) {
        m = l + r >> 1;
        if (sum(m) + x <= m + t)
          r = m;
        else
          l = m;
      }
      add(r);
      return r - x;
    } else {
      for (l = 0, r = x - 1; l + 1 < r;) {
        m = l + r >> 1;
        if (sum(m) < m)
          r = m;
        else
          l = m;
      }
      add(r);
      return r + n - x;
    }
  }
} pp[204800];
int main() {
  scanf("%d%d%d", &h, &m, &n);
  for (int i = g = 0, k; i < h; ++i)
    if (!ss[i]) {
      ss[i] = ++g;
      tt[i] = k = 1;
      for (int j = (i + m) % h; j != i; j = (j + m) % h) {
        ss[j] = g;
        tt[j] = ++k;
      }
      pp[g].init(k);
    }
  char ch;
  __typeof(pos.end()) iter;
  for (int id, hs, t; n--;) {
    scanf(" %c%d", &ch, &id);
    if (ch == '+') {
      scanf("%d", &hs);
      t = pp[ss[hs]].findnext(tt[hs]);
      ans += t;
      hs = (hs + (long long)t * m) % h;
      pos[id] = hs;
    } else {
      iter = pos.find(id);
      hs = iter->second;
      pos.erase(iter);
      pp[ss[hs]].minus(tt[hs]);
    }
  }
  printf("%I64d\n", ans);
}
