#include <bits/stdc++.h>
using namespace std;
const int maxN = 2 * 100000 + 10;
int h, m, n;
int a[maxN];
map<int, int> at;
long long res = 0;
int main() {
  ios::sync_with_stdio(false);
  cin >> h >> m >> n;
  memset(a, -1, sizeof a);
  for (int i = 0; i < n; i++) {
    char ch;
    cin >> ch;
    if (ch == '+') {
      int id, t;
      cin >> id >> t;
      for (int j = 0, x = t; j == 0 || x != t; j++, x = (x + m) % h, res++) {
        if (a[x] == -1) {
          a[x] = id, at[id] = x;
          break;
        }
      }
    } else if (ch == '-') {
      int id;
      cin >> id;
      a[at[id]] = -1;
    }
  }
  cout << res << endl;
  return 0;
}
