#include <bits/stdc++.h>
using namespace std;
int visit[5010];
map<int, int> ma;
int main() {
  ma.clear();
  int n, m, r;
  char s[5];
  int id, x, y;
  cin >> n >> m >> r;
  long long ans = 0;
  memset(visit, 0, sizeof(visit));
  while (r--) {
    scanf("%s", s);
    if (s[0] == '-') {
      scanf("%d", &id);
      visit[ma[id]] = 0;
    } else {
      scanf("%d%d", &id, &x);
      for (int i = 0;; i++) {
        y = (x + i * m) % n;
        if (!visit[y]) {
          visit[y] = 1;
          ma[id] = y;
          ans += i;
          break;
        }
      }
    }
  }
  printf("%I64d\n", ans);
  return 0;
}
