#include <bits/stdc++.h>
using namespace std;
bool debug = false;
int n, m, k;
int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
const int tMax = 1 << 19;
int h, M;
int T[tMax], col[200005], cnt, lf[200005], sz[200005];
void update(int l, int x) {
  l = l + M;
  T[l] = x;
  while (l > 1) {
    T[l >> 1] = min(T[l], T[l ^ 1]);
    l >>= 1;
  }
}
int query(int l, int r) {
  int ans = 1 << 30;
  for (l = l + M - 1, r = r + M + 1; l ^ r ^ 1; l >>= 1, r >>= 1) {
    if (~l & 1) ans = min(ans, T[l ^ 1]);
    if (r & 1) ans = min(ans, T[r ^ 1]);
  }
  return ans;
}
map<int, int> mp;
int main() {
  scanf("%d%d%d", &h, &m, &n);
  for (M = 1; M < h + 2; M <<= 1)
    ;
  int left = 1;
  for (int(i) = 0; (i) < (int)(tMax); (i)++) T[i] = 1 << 30;
  for (int i = 1; i <= h; i++) update(i, i);
  for (int(i) = 0; (i) < (int)(h); (i)++)
    if (!col[i]) {
      int t = 0;
      for (int j = i; !col[j]; j = (j + m) % h) {
        col[j] = ++cnt;
        lf[j] = left;
        t++;
      }
      sz[left] = t;
      left += t;
    }
  long long ans = 0;
  char ope[3];
  int id, hash;
  while (n--) {
    scanf("%s %d", ope, &id);
    if (ope[0] == '+') {
      scanf("%d", &hash);
      int left = lf[hash], right = left + sz[left] - 1, me = col[hash];
      int x = query(me, right);
      if (x != 1 << 30) {
        ans += x - me;
      } else {
        x = query(left, me - 1);
        ans += right - me + x - left + 1;
      }
      mp[id] = x;
      update(x, 1 << 30);
    } else {
      update(mp[id], mp[id]);
    }
  }
  printf("%lld\n", ans);
  return 0;
}
