#include <bits/stdc++.h>
using namespace std;
const int dx[] = {-1, 0, 1, 0, -1, -1, 1, 1, 0};
const int dy[] = {0, 1, 0, -1, -1, 1, 1, -1, 0};
const int inf = 1 << 30;
const int H = 5050;
int i, j, Hash, taken[H], id, p, pos[H], h, m, n, ans, cnt;
char ch;
map<int, int> was;
int main() {
  srand(time(0));
  scanf("%d%d%d\n", &h, &m, &n);
  for (i = 0; i < n; i++) {
    scanf("%c", &ch);
    if (ch == '+') {
      scanf("%d%d\n", &id, &Hash);
      if (!was[id]) was[id] = ++cnt;
      id = was[id];
      for (j = 0;; j++) {
        p = (Hash + j * m) % h;
        if (!taken[p]) {
          taken[p] = id;
          pos[id] = p;
          ans += j;
          break;
        }
      }
    } else {
      scanf("%d\n", &id);
      id = was[id];
      taken[pos[id]] = 0;
    }
  }
  printf("%d", ans);
  return 0;
}
