#include <bits/stdc++.h>
using namespace std;
const int maxh = 200 * 1000 + 5;
map<int, int> M;
int A[maxh];
int h, m, n;
long long add(int x, int hash) {
  long long res = 0;
  while (A[hash]) {
    hash += m;
    hash %= h;
    ++res;
  }
  A[hash] = x + 1;
  return res;
}
void del(int x, int hash) {
  while (A[hash] != x + 1) {
    hash += m;
    hash %= h;
  }
  A[hash] = 0;
}
int main() {
  ios::sync_with_stdio(0);
  cin >> h >> m >> n;
  long long res = 0;
  for (int i = 0; i < n; ++i) {
    char op;
    int id;
    cin >> op >> id;
    if (op == '+') {
      int hash;
      cin >> hash;
      res += add(id, hash);
      M[id] = hash;
    } else {
      int hash = M[id];
      del(id, hash);
    }
  }
  cout << res << '\n';
  return 0;
}
