#include <bits/stdc++.h>
using namespace std;
long H, M, N;
long Val[10007 + 7];
int main(void) {
  long i, Id, Hash;
  char Ch;
  cin >> H >> M >> N;
  long Ans = 0;
  map<long, long> Pos;
  memset(Val, -1, sizeof(Val));
  for (i = 1; i <= N; i++) {
    cin >> Ch;
    if (Ch == '+') {
      cin >> Id >> Hash;
      while (Val[Hash] != -1) {
        Ans++;
        Hash = (Hash + M) % H;
      }
      Val[Hash] = Id;
      Pos[Id] = Hash;
    } else {
      cin >> Id;
      Val[Pos[Id]] = -1;
    }
  }
  cout << Ans << endl;
  return 0;
}
