#include <bits/stdc++.h>
using namespace std;
int start[411111], finish[411111], L[411111], R[411111], M[411111], was[411111],
    px[411111], py[411111], cn = 0;
int h, m, n;
void Init(int h, int m) {
  int pos = 0;
  for (int i = 0; i < h; i++)
    if (!was[i]) {
      int j = i;
      start[cn] = pos;
      pos++;
      do {
        was[j] = true;
        px[j] = cn;
        py[j] = pos - start[cn];
        pos++;
        j = (j + m) % h;
      } while (j != i);
      finish[cn++] = pos;
    }
}
int FindFirst(int s, int f, int x) {
  int *r = R + s;
  int *l = L + s;
  int *m = M + s;
  int n = f - s;
  while (r[x] == min(((x) | ((x)-1)) + 1, n) - x) {
    x = ((x) | ((x)-1)) + 1;
    if (x > n - 1) x = 1;
  }
  if (m[x] == 0) return x;
  int step = ((x) | ((x)-1)) + 1 - x;
  while (step > 1) {
    step >>= 1;
    if (x + step < n && l[x + step] == step) x += step;
  }
  return x + 1;
}
void Add(int s, int f, int x, int y) {
  int *r = R + s;
  int *l = L + s;
  int *m = M + s;
  int n = f - s;
  m[x] += y;
  int iter = x;
  while (iter < n) {
    l[iter] += y;
    iter = ((iter) | ((iter)-1)) + 1;
  }
  iter = x;
  while (iter > 0) {
    r[iter] += y;
    iter = ((iter) & ((iter)-1));
  }
}
map<int, pair<int, int> > POS;
int main() {
  scanf("%d%d%d\n", &h, &m, &n);
  Init(h, m);
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    int id, hash;
    char c;
    scanf("%c %d", &c, &id);
    if (c == '+') {
      scanf("%d\n", &hash);
      int t = FindFirst(start[px[hash]], finish[px[hash]], py[hash]);
      if (t >= py[hash]) {
        ans += t - py[hash];
      } else {
        ans += t + finish[px[hash]] - start[px[hash]] - py[hash] - 1;
      }
      Add(start[px[hash]], finish[px[hash]], t, 1);
      POS[id] = pair<int, int>(px[hash], t);
    } else if (c == '-') {
      pair<int, int> t = POS[id];
      Add(start[t.first], finish[t.first], t.second, -1);
      scanf("\n");
    }
  }
  printf("%I64d\n", ans);
  return 0;
}
