#include <bits/stdc++.h>
#pragma comment(linker, "/stack:64000000")
using namespace std;
template <typename first>
inline first abs(const first& a) {
  return a < 0 ? -a : a;
}
template <typename first>
inline first sqr(const first& a) {
  return a * a;
}
const long double PI = 3.1415926535897932384626433832795;
const long double EPS = 1e-9;
const int INF = 1000 * 1000 * 1000;
const int N = 200 * 1000 + 3;
int h, m, n;
int cntG;
vector<int> gr[N];
vector<int> t[N];
pair<int, int> pos[N];
int used[N];
map<int, pair<int, int> > idToPos;
int getPos(int numt, int idx, int lf, int rg, int pos) {
  assert(pos >= lf);
  if (lf == rg) return t[numt][idx] == 1 ? -1 : lf;
  if (pos == lf) {
    if (t[numt][idx] == rg - lf + 1) return -1;
    int mid = (lf + rg) >> 1;
    if (t[numt][2 * idx + 1] != mid - lf + 1)
      return getPos(numt, 2 * idx + 1, lf, mid, lf);
    return getPos(numt, 2 * idx + 2, mid + 1, rg, mid + 1);
  } else {
    int mid = (lf + rg) >> 1;
    if (pos <= mid) {
      int res = getPos(numt, 2 * idx + 1, lf, mid, pos);
      if (res != -1) return res;
      return getPos(numt, 2 * idx + 2, mid + 1, rg, mid + 1);
    }
    return getPos(numt, 2 * idx + 2, mid + 1, rg, pos);
  }
}
void upd(int numt, int idx, int lf, int rg, int pos, int val) {
  if (lf == rg) {
    assert(lf == pos);
    t[numt][idx] += val;
    return;
  }
  int mid = (lf + rg) >> 1;
  if (pos <= mid)
    upd(numt, 2 * idx + 1, lf, mid, pos, val);
  else
    upd(numt, 2 * idx + 2, mid + 1, rg, pos, val);
  t[numt][idx] = t[numt][2 * idx + 1] + t[numt][2 * idx + 2];
}
int add(int id, int hash) {
  int numG = pos[hash].first, posG = pos[hash].second;
  int freePos = getPos(numG, 0, 0, int((gr[numG]).size()) - 1, posG);
  if (freePos == -1)
    freePos = getPos(numG, 0, 0, int((gr[numG]).size()) - 1, 0);
  assert(freePos != -1);
  idToPos[id] = make_pair((numG), (freePos));
  upd(numG, 0, 0, int((gr[numG]).size()) - 1, freePos, 1);
  return (freePos - posG + int((gr[numG]).size())) % int((gr[numG]).size());
}
void remove(int id) {
  int numG = idToPos[id].first, posG = idToPos[id].second;
  idToPos.erase(id);
  upd(numG, 0, 0, int((gr[numG]).size()) - 1, posG, -1);
}
int main() {
  scanf("%d %d %d\n", &h, &m, &n);
  for (int i = 0; i < int(h); i++) {
    if (used[i]) continue;
    int cur = i;
    while (!used[cur]) {
      used[cur] = true;
      pos[cur] = make_pair((cntG), (int((gr[cntG]).size())));
      gr[cntG].push_back(cur);
      cur = (cur + m) % h;
    }
    t[cntG].resize(int((gr[cntG]).size()) * 4);
    cntG++;
  }
  long long ans = 0;
  for (int i = 0; i < int(n); i++) {
    char type;
    scanf("%c ", &type);
    if (type == '+') {
      int id, hash;
      scanf("%d %d\n", &id, &hash);
      ans += add(id, hash);
    } else {
      int id;
      scanf("%d\n", &id);
      remove(id);
    }
  }
  cout << ans << endl;
  return 0;
}
