#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:16777216")
using namespace std;
int h, m, n;
long long ret;
map<int, int> pos;
vector<vector<int> > cyc;
set<int> places[200001];
int col[200001];
int colpos[200001];
bool used[200001];
int table[200001];
void add(int id, int t) {
  int c = col[t];
  int idx = colpos[t];
  set<int>::iterator it = places[c].lower_bound(idx);
  if (it == places[c].end())
    it = places[c].begin();
  else {
    if (*it < idx) ++it;
    if (it == places[c].end()) it = places[c].begin();
  }
  int idx2 = *it;
  int add;
  if (idx2 >= idx)
    add = idx2 - idx;
  else
    add = (int)((cyc[c]).size()) - idx + idx2;
  places[c].erase(it);
  pos[id] = cyc[c][idx2];
  table[cyc[c][idx2]] = id;
  ret += add;
}
void del(int id) {
  int t = pos[id];
  int c = col[t];
  places[c].insert(colpos[t]);
  if (table[t] != id) throw 1;
  table[t] = -1;
}
void solution() {
  scanf("%d %d %d\n", &h, &m, &n);
  memset((table), (-1), sizeof((table)));
  for (int i = 0, _n = (n); i < _n; ++i)
    if (!used[i]) {
      cyc.push_back(vector<int>());
      used[i] = true;
      int color = (int)((cyc).size()) - 1;
      col[i] = color;
      colpos[i] = (int)((cyc.back()).size());
      cyc.back().push_back(i);
      int j = i;
      for (;;) {
        j += m;
        if (j >= h) j -= h;
        if (used[j]) break;
        used[j] = true;
        col[j] = color;
        colpos[j] = (int)((cyc.back()).size());
        cyc.back().push_back(j);
      }
      for (int j = 0, _n = ((int)((cyc.back()).size())); j < _n; ++j)
        places[color].insert(j);
    }
  for (int i = 0, _n = (n); i < _n; ++i) {
    char op;
    scanf("%c", &op);
    if (op == '+') {
      int id, t;
      scanf("%d %d\n", &id, &t);
      add(id, t);
    } else if (op == '-') {
      int id;
      scanf("%d\n", &id);
      del(id);
    } else
      throw 1;
  }
  cout << ret << endl;
}
int main() {
  solution();
  return 0;
}
