#include <bits/stdc++.h>
using namespace std;
int n, k, region[200111], number[200111], nRegion = 0, size[200111];
set<int> freeSet[200111];
map<int, pair<int, int> > store;
int add(int id, int val) {
  int reg = region[val], num = number[val], pos;
  set<int>::iterator it = freeSet[reg].lower_bound(num);
  if (it == freeSet[reg].end())
    pos = *freeSet[reg].begin();
  else
    pos = *it;
  store[id] = pair<int, int>(reg, pos);
  freeSet[reg].erase(pos);
  if (num <= pos) return pos - num;
  return size[reg] - num + pos;
}
void remove(int id) {
  pair<int, int> x = store[id];
  store.erase(id);
  freeSet[x.first].insert(x.second);
}
int main() {
  memset(region, -1, sizeof(region));
  long long res = 0;
  char ques;
  int m, id, val;
  scanf("%d %d %d", &n, &k, &m);
  for (int i = 0; i < n; i++)
    if (region[i] == -1) {
      int x = i, nNumber = 0;
      size[nRegion] = 0;
      while (region[x] == -1) {
        region[x] = nRegion;
        number[x] = ++nNumber;
        freeSet[nRegion].insert(nNumber);
        x = (x + k) % n;
        size[nRegion]++;
      }
      nRegion++;
    }
  while (m--) {
    scanf(" %c %d ", &ques, &id);
    if (ques == '+') {
      scanf(" %d ", &val);
      res += add(id, val % n);
    } else
      remove(id);
  }
  cout << res << endl;
  return 0;
}
