#include <bits/stdc++.h>
const double eps = 1e-9;
const int int_inf = 2000000000;
const long long i64_inf = 1000000000000000000LL;
const double pi = acos(-1.0);
using namespace std;
vector<int> id;
int where[300500];
int get(int a) {
  int l = 0;
  int r = (int)id.size();
  while (l != r - 1) {
    int m = (l + r) >> 1;
    if (id[m] <= a)
      l = m;
    else
      r = m;
  }
  return l;
}
pair<int, int> z[200500];
int szz = 0;
int n, m, h;
long long res = 0;
vector<int> g[200500];
vector<int> fen[200500];
int szg = 0;
bool was[200500];
pair<int, int> w[200500];
void inc(int ig, int i, int d) {
  for (; i < (int)g[ig].size(); i = (i | (i + 1))) fen[ig][i] += d;
}
int sum(int ig, int r) {
  int res = 0;
  for (; r >= 0; r = (r & (r + 1)) - 1) res += fen[ig][r];
  return res;
}
int sum(int ig, int l, int r) { return sum(ig, r) - sum(ig, l - 1); }
int main() {
  cin >> h >> m >> n;
  scanf("\n");
  for (int i = 0; i < (int)n; i++) {
    char c = getchar();
    if (c == '+') {
      int _id, _hash;
      scanf("%d%d\n", &_id, &_hash);
      id.push_back(_id);
      z[szz].first = _id;
      z[szz].second = _hash;
      szz++;
    } else {
      int _id;
      scanf("%d\n", &_id);
      z[szz].first = _id;
      z[szz].second = -1;
      szz++;
    }
  }
  sort(id.begin(), id.end());
  id.resize(unique(id.begin(), id.end()) - id.begin());
  memset(was, 0, sizeof(was));
  for (int i = 0; i < (int)h; i++) {
    if (was[i]) continue;
    was[i] = 1;
    g[szg].push_back(i);
    w[i] = make_pair(szg, 0);
    fen[szg].push_back(0);
    int now = (i + m) % h;
    int iter = 1;
    while (now != i) {
      g[szg].push_back(now);
      was[now] = 1;
      w[now] = make_pair(szg, iter);
      fen[szg].push_back(0);
      now = (now + m) % h;
      iter++;
    }
    int _sz = (int)g[szg].size();
    for (int j = 0; j < (int)_sz; j++)
      g[szg].push_back(g[szg][j]), fen[szg].push_back(0);
    szg++;
  }
  for (int i = 0; i < (int)szz; i++)
    if (z[i].second > -1) {
      int nid = get(z[i].first);
      int t = z[i].second;
      int _sz = (int)g[w[t].first].size() / 2;
      int l = w[t].second;
      int r = l + _sz;
      if (sum(w[t].first, w[t].second, w[t].second) == 0) {
        inc(w[t].first, w[t].second, 1);
        inc(w[t].first, (w[t].second + _sz) % (_sz * 2), 1);
        where[nid] = g[w[t].first][w[t].second];
        continue;
      }
      while (l != r - 1) {
        int mid = (l + r) >> 1;
        if (sum(w[t].first, w[t].second, mid) == mid - w[t].second + 1)
          l = mid;
        else
          r = mid;
      }
      l = (l + 1) % (_sz + _sz);
      inc(w[t].first, l, 1);
      inc(w[t].first, (l + _sz) % (_sz * 2), 1);
      where[nid] = g[w[t].first][l];
      res += l - w[t].second;
    } else {
      int nid = get(z[i].first);
      int j = where[nid];
      int _sz = ((int)g[w[j].first].size() / 2);
      inc(w[j].first, w[j].second, -1);
      inc(w[j].first, (w[j].second + _sz) % (_sz * 2), -1);
    }
  cout << res << endl;
  return 0;
}
