#include <bits/stdc++.h>
using namespace std;
const int maxn = 100000 + 66;
map<int, int> pos;
bool H[maxn];
char buf[100];
int main() {
  int h, m, n, i, j, id, hash;
  scanf("%d %d %d\n", &h, &m, &n);
  long long ans = 0;
  for (i = 0; i < (int)(n); ++i) {
    int c = getchar();
    if (c == '+') {
      scanf(" %d %d\n", &id, &hash);
      while (H[hash]) {
        ++ans;
        hash = (hash + m) % h;
      }
      pos[id] = hash + 1;
      H[hash] = true;
    } else {
      scanf(" %d\n", &id);
      int t = pos[id] - 1;
      H[t] = false;
    }
  }
  cout << ans;
  return 0;
}
