#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:16777216")
using namespace std;
template <class T>
inline T sqr(T x) {
  return x * x;
}
const double eps = 1e-9;
const double pi = acos(-1.0);
const int maxn = (int)1e5 + 10;
pair<int, int> who[maxn];
vector<int> tsz;
vector<vector<int> > t;
char type[11];
int sum(int l, int r, int a, int b, int idx, int what) {
  if (b < l || r < a) return 0;
  if (a <= l && r <= b) return t[what][idx];
  int mid = (l + r) >> 1;
  return sum(l, mid, a, b, 2 * idx, what) +
         sum(mid + 1, r, a, b, 2 * idx + 1, what);
}
int doit(int l, int r, int a, int idx, int what) {
  if (l == r) {
    t[what][idx]++;
    return l;
  }
  int mid = (l + r) >> 1;
  int ret;
  if (a <= mid) {
    int left = sum(0, tsz[what] - 1, a, mid, 1, what);
    if (left < mid - a + 1)
      ret = doit(l, mid, a, 2 * idx, what);
    else
      ret = doit(mid + 1, r, a, 2 * idx + 1, what);
  } else {
    ret = doit(mid + 1, r, a, 2 * idx + 1, what);
  }
  t[what][idx] = t[what][2 * idx] + t[what][2 * idx + 1];
  return ret;
}
void update(int l, int r, int pos, int idx, int what) {
  if (l == r)
    t[what][idx]--;
  else {
    int mid = (l + r) >> 1;
    if (pos <= mid)
      update(l, mid, pos, 2 * idx, what);
    else
      update(mid + 1, r, pos, 2 * idx + 1, what);
    t[what][idx] = t[what][2 * idx] + t[what][2 * idx + 1];
  }
}
int main() {
  memset(who, -1, sizeof(who));
  int h, m, n;
  cin >> h >> m >> n;
  for (int i = 0; i < h; i++) {
    if (who[i].first != -1) continue;
    int cur = i, id = (int)(tsz).size();
    tsz.push_back(0);
    while (who[cur].first == -1) {
      who[cur].first = id;
      who[cur].second = tsz[id]++;
      cur = cur + m;
      if (cur >= h) cur -= h;
    }
  }
  t.resize((int)(tsz).size());
  for (int i = 0; i < (int)(t).size(); i++) t[i].resize(4 * tsz[i], 0);
  map<int, pair<int, int> > D;
  int id, hash;
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    scanf("%s%d", &type, &id);
    if (type[0] == '+') {
      scanf("%d", &hash);
      int what = who[hash].first;
      int pos = who[hash].second;
      int left = sum(0, tsz[what] - 1, pos, tsz[what] - 1, 1, what);
      if (left < tsz[what] - pos) {
        hash = doit(0, tsz[what] - 1, pos, 1, what);
        D[id] = make_pair(what, hash);
      } else {
        hash = doit(0, tsz[what] - 1, 0, 1, what);
        D[id] = make_pair(what, hash);
      }
      ans += (hash - pos + tsz[what]) % tsz[what];
    } else {
      int what = D[id].first;
      int pos = D[id].second;
      update(0, tsz[what] - 1, pos, 1, what);
    }
  }
  cout << ans << endl;
  return 0;
}
