#include <bits/stdc++.h>
int n, h, m, hash[5001], i, j, a, b, sum, p, q;
char c;
int main() {
  scanf("%d%d%d", &h, &m, &n);
  memset(hash, -1, sizeof(hash));
  for (i = 0; i < n; i++) {
    while (getchar() != '\n')
      ;
    c = getchar();
    if (c == '+') {
      scanf("%d%d", &a, &b);
      if (hash[b] == -1)
        hash[b] = a;
      else {
        p = (b + m) % h;
        q = 1;
        while (hash[p] != -1 && p != b) {
          p = (p + m) % h;
          q++;
        }
        if (p != b) hash[p] = a;
        sum += q;
      }
    } else {
      scanf("%d", &a);
      for (j = 0; j < n; j++)
        if (hash[j] == a) {
          hash[j] = -1;
          break;
        }
    }
  }
  printf("%d\n", sum);
  return 0;
}
