#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000009;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int MAXN = 0;
const int MAXM = 0;
bool a[5002];
int i, j, k, n, h, m, id, p, hesh;
map<int, int> M;
char c;
int ans = 0;
int main() {
  cin >> h >> m >> n;
  for (i = 0; i < n; i++) {
    cin >> c;
    if (c == '-') {
      cin >> id;
      a[M[id]] = 0;
    } else {
      cin >> id >> hesh;
      while (a[hesh] != 0) {
        hesh = (hesh + m) % h;
        ans++;
      }
      a[hesh] = true;
      M[id] = hesh;
    }
  }
  cout << ans << endl;
  return 0;
}
