#include <bits/stdc++.h>
using namespace std;
int tb[1000003];
int cnt[1000003];
map<int, int> pos;
int n, m, h;
char str1[100];
long long ans;
void insert() {
  int id, v;
  scanf("%d%d", &id, &v);
  if (tb[v] == -1)
    tb[v] = id, cnt[v] = 0, pos[id] = v;
  else {
    int nxt = v;
    for (int i = 1; i <= h; i++) {
      nxt = (nxt + m) % h;
      if (tb[nxt] == -1) {
        tb[nxt] = id;
        pos[id] = nxt;
        cnt[nxt] = i;
        ans += (long long)(i);
        break;
      }
    }
  }
}
void delt() {
  int id, ps;
  scanf("%d", &id);
  ps = pos[id];
  tb[ps] = -1;
  cnt[ps] = 0;
  pos[id] = 0;
}
int main() {
  scanf("%d%d%d", &h, &m, &n);
  ans = 0;
  for (int i = 0; i <= h; i++) tb[i] = -1;
  for (int i = 1; i <= n; i++) {
    scanf("%s", &str1);
    if (str1[0] == '+')
      insert();
    else
      delt();
  }
  printf("%I64d\n", ans);
  return 0;
}
