#include <bits/stdc++.h>
using namespace std;
const int maxint = -1u >> 1;
const double pi = 3.14159265358979323;
const double eps = 1e-8;
int h, m, n, ans;
bool table[50010];
map<int, int> id;
int main() {
  char op;
  int x, y;
  cin >> h >> m >> n;
  ans = 0;
  memset(table, 0, sizeof(table));
  while (n--) {
    cin >> op;
    if (op == '+') {
      cin >> x >> y;
      while (table[y]) {
        y = (y + m) % h;
        ans++;
      }
      table[y] = true;
      id[x] = y;
    } else {
      cin >> x;
      table[id[x]] = false;
    }
  }
  cout << ans << endl;
  return 0;
}
