#include <bits/stdc++.h>
using namespace std;
struct FenwickTree {
  int n_;
  int* bit_;
  FenwickTree(int n) {
    n_ = n;
    bit_ = new int[n_ + 10];
    for (int(i) = 0; (i) < (n_); ++(i)) bit_[i + 1] = 0;
  }
  ~FenwickTree() { delete[] bit_; }
  void add(int pos, int val) {
    while (pos <= n_) {
      bit_[pos] += val;
      pos += (pos & -pos);
    }
  }
  int sum(int ending) {
    if (ending > n_) ending = n_;
    int retval = 0;
    while (ending >= 1) {
      retval += bit_[ending];
      ending -= (ending & -ending);
    }
    return retval;
  }
  int sumarea(int mulai, int selesai) {
    if (mulai > selesai) return 0;
    return sum(selesai) - sum(mulai - 1);
  }
  int sumlong(int mulai, int pnj, int n) {
    if (mulai + pnj - 1 > n) {
      int over = mulai + pnj - 1 - n;
      return sumarea(mulai, n) + sumarea(1, over);
    } else {
      return sumarea(mulai, mulai + pnj - 1);
    }
  }
};
const int kMaxN = 210000;
FenwickTree* trees[kMaxN];
int tcnt = 0;
int len[kMaxN];
int group[kMaxN];
int order[kMaxN];
int h, m, n;
map<int, int> dg;
map<int, int> dp;
int Dfs(int node, int group_no, int depth) {
  if (group[node] == group_no) return depth;
  assert(group[node] == -1);
  group[node] = group_no;
  order[node] = depth;
  return Dfs((node + m) % h, group_no, depth + 1);
}
int main() {
  scanf("%d%d%d\n", &h, &m, &n);
  for (int(i) = 0; (i) < (h); ++(i)) group[i] = -1;
  for (int(i) = 0; (i) < (h); ++(i))
    if (group[i] == -1) {
      int tot = Dfs(i, tcnt, 0);
      len[tcnt] = tot;
      trees[tcnt] = new FenwickTree(tot + 4);
      ++tcnt;
    }
  long long ret = 0;
  for (int(i) = 0; (i) < (n); ++(i)) {
    char c;
    scanf("%c", &c);
    if (c == '-') {
      int del;
      scanf("%d\n", &del);
      int g = dg[del];
      int p = dp[del];
      dg.erase(del);
      dp.erase(del);
      trees[g]->add(p + 1, -1);
    } else {
      int id, hash;
      scanf("%d%d\n", &id, &hash);
      int g = group[hash];
      int o = order[hash];
      int mult = 1;
      while (mult * 2 <= len[g]) mult *= 2;
      int init = o;
      int misses = 0;
      while (mult) {
        int calc = trees[g]->sumlong(init + 1, mult, len[g]);
        if (calc == mult) {
          misses += mult;
          init = (init + mult) % len[g];
        } else {
        }
        mult /= 2;
      }
      trees[g]->add(init + 1, 1);
      dg[id] = g;
      dp[id] = init;
      ret += (long long)misses;
    }
  }
  cout << ret << endl;
}
