#include <bits/stdc++.h>
using namespace std;
int main() {
  int h, m, n;
  scanf("%d", &(h)), scanf("%d", &(m)), scanf("%d", &(n));
  map<int, int> idx;
  bool use[(5000 + 10)];
  memset((use), 0, sizeof(use));
  long long ans = 0;
  while (n--) {
    char o[3];
    scanf("%s", (o));
    if (o[0] == '+') {
      int x, r;
      scanf("%d", &(x)), scanf("%d", &(r));
      while (use[r]) r = (r + m) % h, ++ans;
      use[r] = 1;
      idx[x] = r;
    } else {
      int x;
      scanf("%d", &(x));
      use[idx[x]] = 0;
    }
  }
  printf("%d\n", (ans));
  return 0;
}
