#include <bits/stdc++.h>
using namespace std;
int cells[100010];
map<long long, int> position;
int main() {
  int h, m, n;
  int amount = 0;
  memset(cells, -1, sizeof(cells));
  scanf("%d %d %d", &h, &m, &n);
  for (int i = 0; i < n; i++) {
    char c;
    int id, hash;
    scanf(" %c %d", &c, &id);
    if (c == '+') scanf("%d", &hash);
    int k = 0;
    if (c == '-') {
      cells[position[id]] = -1;
      continue;
    }
    while (cells[(hash + k * m) % h] != -1) {
      k++;
    }
    cells[(hash + k * m) % h] = id;
    position[id] = (hash + k * m) % h;
    amount += k;
  }
  printf("%d\n", amount);
  return 0;
}
