#include <bits/stdc++.h>
using namespace std;
int main(int narg, char **arg) {
  int h, m, n;
  cin >> h >> m >> n;
  int counter = 0;
  bool hash[h];
  memset(hash, 0, sizeof(hash));
  map<int, int> positions;
  for (int i = 0; i < n; i++) {
    char op;
    int id, hash_value;
    cin >> op >> id;
    if (op == '+') {
      cin >> hash_value;
      while (hash[hash_value]) {
        counter++;
        hash_value += m;
        hash_value %= h;
      }
      hash[hash_value] = true;
      positions[id] = hash_value;
    } else {
      hash[positions[id]] = false;
      positions.erase(id);
    }
  }
  cout << counter << endl;
  return 0;
}
