#include <bits/stdc++.h>
using namespace std;
const int ms = 4 * 4 + 20;
map<int, int> pos;
int mk[5111];
int main() {
  int h, n, m;
  cin >> h >> m >> n;
  int ans = 0;
  while (n--) {
    char op;
    int id;
    int hs;
    scanf(" %c %d", &op, &id);
    if (op == '+') {
      scanf("%d", &hs);
      for (int i = 0;; i++) {
        if (mk[hs] == 0) {
          ans += i;
          mk[hs] = 1;
          pos[id] = hs;
          break;
        } else {
          hs = (hs + m) % h;
        }
      }
    } else {
      mk[pos[id]] = 0;
    }
  }
  cout << ans << endl;
}
