#include <bits/stdc++.h>
using namespace std;
const int SIZE = 100009;
int sum[SIZE * 30];
int query(int base, int idx, int l, int r, int s, int e) {
  if (sum[base + idx] == (r - l))
    return -1;
  else if (!sum[base + idx])
    return max(l, s);
  else {
    int m = (l + r) / 2;
    if (s < m) {
      int t = query(base, idx * 2, l, m, s, e);
      if (t != -1) return t;
    }
    return query(base, idx * 2 + 1, m, r, s, e);
  }
}
void update(int base, int idx, int l, int r, int pos, int v) {
  if (r - l == 1)
    sum[base + idx] += v;
  else {
    int m = (l + r) / 2;
    if (pos < m)
      update(base, idx * 2, l, m, pos, v);
    else
      update(base, idx * 2 + 1, m, r, pos, v);
    sum[base + idx] += v;
  }
}
int gcd(int a, int b) {
  if (b)
    return gcd(b, a % b);
  else
    return a;
}
pair<int, int> table2[300009];
int main() {
  int H, M, N;
  scanf("%d%d%d", &H, &M, &N);
  int k = gcd(H, M);
  map<int, pair<int, int> > table;
  int gap = H / k * 10;
  long long int ans = 0;
  for (int i = 0; i < k; i++)
    for (int j = 0, v = i; j < H / k; j++, v = (v + M) % H)
      table2[v] = pair<int, int>(i, j);
  while (N--) {
    char c;
    scanf(" %c", &c);
    if (c == '+') {
      int id, h;
      scanf("%d%d", &id, &h);
      int t = table2[h].first;
      int pos = table2[h].second;
      int dum = 0;
      int res = query(gap * t, 1, 0, H / k, pos, H / k);
      if (res != -1)
        dum = res - pos;
      else {
        res = query(gap * t, 1, 0, H / k, 0, H / k);
        dum = H / k - pos + res;
      }
      update(gap * t, 1, 0, H / k, res, 1);
      table[id] = pair<int, int>(gap * t, res);
      ans += dum;
    } else {
      int id;
      scanf("%d", &id);
      pair<int, int> p = table[id];
      update(p.first, 1, 0, H / k, p.second, -1);
    }
  }
  printf("%I64d\n", ans);
  return 0;
}
