#include <bits/stdc++.h>
using namespace std;
map<int, int> iR;
int main(int argc, char **argv) {
  int N, M, K, res = 0;
  cin >> N >> M >> K;
  int R[N];
  memset(R, -1, sizeof(R));
  for (int q = (0); q < (K); ++q) {
    char s[10];
    int X;
    cin >> s >> X;
    if (s[0] == '-') {
      for (int j = (0); j < (N); ++j)
        if (R[j] == X) R[j] = -1;
    } else {
      int H;
      cin >> H;
      iR[X] = H;
      while (1) {
        if (R[H] == -1) {
          R[H] = X;
          break;
        }
        ++res;
        H = (H + M) % N;
      }
    }
  }
  cout << res << endl;
  return 0;
}
