#include <bits/stdc++.h>
using namespace std;
int H, M, N;
int G, MM;
vector<set<int> > se;
map<int, pair<int, int> > ma;
int ggt(int a, int b) {
  while (b) {
    a %= b;
    swap(a, b);
  }
  return a;
}
int main() {
  scanf("%d%d%d ", &H, &M, &N);
  G = ggt(H, M);
  MM = -1;
  for (int i = 0; i < (H / G); i++)
    if ((long long)i * (M / G) % (H / G) == 1) MM = i;
  assert(MM != -1);
  se.resize(G);
  for (int i = 0; i < (G); i++)
    for (int j = 0; j < (H / G); j++) se[i].insert(j);
  long long erg = 0;
  for (int runde = 0; runde < (N); runde++) {
    char c;
    int id;
    scanf("%c %d ", &c, &id);
    if (c == '-') {
      const pair<int, int> &p = ma[id];
      se[p.first].insert(p.second);
    } else {
      int ha;
      scanf("%d ", &ha);
      int m = ha % G;
      int w = (long long)(ha / G) * MM % (H / G);
      set<int>::iterator it = se[m].lower_bound(w);
      if (it == se[m].end()) it = se[m].begin();
      assert(it != se[m].end());
      int k = *it;
      erg += (k >= w ? k - w : H / G - w + k);
      se[m].erase(it);
      ma[id] = pair<int, int>(m, k);
    }
  }
  printf("%I64d\n", erg);
  return 0;
}
