#include <bits/stdc++.h>
using namespace std;
const int MAX = 5005;
const int INF = 1 << 30;
const double EPS = 1e-7;
int H, M, N;
int cnt;
int h[MAX], mk[MAX];
map<int, int> Map;
int main() {
  scanf("%d %d %d", &H, &M, &N);
  for (int i = 0; i < (H); ++i) h[i] = -1;
  long long ans = 0;
  for (int i = 0; i < (N); ++i) {
    char op;
    int id;
    scanf("\n%c %d", &op, &id);
    if (op == '-')
      h[Map[id]] = -1;
    else {
      int hash;
      scanf("%d", &hash);
      ++cnt;
      long long i = 0;
      int pos = hash;
      while (h[pos] != -1) ++i, pos = (hash + (i % H) * (M % H)) % H;
      ans += i;
      h[pos] = id;
      Map[id] = pos;
    }
  }
  cout << ans << endl;
  return 0;
}
