#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000000;
int tree[1000000], used[200000], pos[200000], num[200000];
int h, m;
int step;
int sztree;
map<int, int> MAP;
int findMinLocal(int l, int r) {
  l += step;
  r += step;
  int ans = INF;
  while (l <= r) {
    if (l & 1) ans = min(ans, tree[l]);
    if (!(r & 1)) ans = min(ans, tree[r]);
    l = (l + 1) / 2;
    r = (r - 1) / 2;
  }
  return ans;
}
void update(int l, int v) {
  l += step;
  tree[l] = v;
  for (l /= 2; l > 0; l /= 2) tree[l] = min(tree[2 * l], tree[2 * l + 1]);
}
int main() {
  scanf("%d%d", &h, &m);
  memset(used, 0, sizeof(used));
  int kol = 0;
  sztree = h;
  for (int i = 0; i < h; i++)
    if (used[i] == 0) {
      int ind = i;
      do {
        used[ind] = 1;
        pos[ind] = kol;
        num[kol] = ind;
        kol++;
        ind = (ind + m) % h;
      } while (ind != i);
    } else {
      sztree = h / i;
      break;
    }
  memset(tree, 0, sizeof(tree));
  step = 1;
  while (step < h) step *= 2;
  for (int i = 1; i < 2 * step; i++) tree[i] = INF;
  for (int i = 0; i < h; i++) update(i, i);
  long long ans = 0;
  int n;
  scanf("%d", &n);
  for (; n > 0; n--) {
    char ch = ' ';
    while ((ch != '+') && (ch != '-')) scanf("%c", &ch);
    int ind;
    scanf("%d", &ind);
    if (ch == '+') {
      int hash;
      scanf("%d", &hash);
      int pos1 = pos[hash];
      int gran = pos1 - (pos1 % sztree) + sztree;
      int newpos = findMinLocal(pos1, gran - 1);
      int ans1;
      if (newpos == INF) {
        newpos = findMinLocal(gran - sztree, pos1 - 1);
        ans1 = gran - pos1 + (newpos - gran + sztree);
      } else
        ans1 = newpos - pos1;
      ans += ans1;
      MAP[ind] = newpos;
      update(newpos, INF);
    } else if (ch == '-') {
      map<int, int>::iterator it = MAP.find(ind);
      update(it->second, it->second);
      MAP.erase(it);
    } else
      printf("ERROR!!!\n");
  }
  cout << ans << "\n";
  return 0;
}
