#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, h;
  cin >> h >> m >> n;
  vector<int> table(h, -1);
  long long ans = 0;
  for (int i = 0; i < n; ++i) {
    char c;
    cin >> c;
    if (c == '-') {
      int num;
      cin >> num;
      for (int j = 0; j < h; ++j)
        if (table[j] == num) table[j] = -1;
    }
    if (c == '+') {
      int num1, num2;
      cin >> num1 >> num2;
      while (table[num2] != -1) {
        ++ans;
        num2 = (num2 + m) % h;
      }
      table[num2] = num1;
    }
  }
  cout << ans;
}
