#include <bits/stdc++.h>
using namespace std;
int main(int argc, char *argv[]) {
  int h, m, n;
  scanf("%d %d %d", &h, &m, &n);
  long long ans = 0;
  char s[32];
  vector<int> c(h, -1);
  map<int, int> a;
  for (int i = 0; i < n; i++) {
    int id, v;
    scanf("%s %d", s, &id);
    if (s[0] == '+') {
      scanf("%d", &v);
      int cnt = 0;
      for (int t = v;; t = (t + m) % h, cnt++) {
        if (c[t] < 0) {
          c[t] = id;
          a[id] = t;
          break;
        }
      }
      ans += cnt;
    } else {
      int t = a[id];
      a.erase(id);
      c[t] = -1;
    }
  }
  cout << ans << endl;
  return 0;
}
