#include <bits/stdc++.h>
using namespace std;
inline void getc(char& c) {
  c = ' ';
  while (c != '+' && c != '-') {
    c = getchar();
  }
}
inline void getd(int& d) {
  d = 0;
  char c = ' ';
  while (c < '0' || c > '9') {
    c = getchar();
  }
  while ('0' <= c && c <= '9') {
    d *= 10;
    d += c - '0';
    c = getchar();
  }
}
const int maxh = 200 * 1000 + 5;
map<int, int> M;
int A[maxh];
int sq[maxh];
int h, m, n;
long long shft;
long long shftm;
inline long long add(int x, int hash, int& nhash) {
  long long res = 0;
  while (A[hash]) {
    if (sq[hash] == shft) {
      hash += shftm;
      if (hash >= h) {
        hash -= h;
      }
      res += shft;
    } else {
      hash += m;
      if (hash >= h) {
        hash -= h;
      }
      ++res;
    }
  }
  A[hash] = x + 1;
  nhash = hash;
  for (int i = 0; i < shft; ++i) {
    ++sq[hash];
    hash -= m;
    if (hash < 0) {
      hash += h;
    }
  }
  return res;
}
inline void del(int x, int hash) {
  A[hash] = 0;
  for (int i = 0; i < shft; ++i) {
    --sq[hash];
    hash -= m;
    if (hash < 0) {
      hash += h;
    }
  }
}
int main() {
  ios::sync_with_stdio(0);
  scanf("%d %d %d", &h, &m, &n);
  shft = sqrt(h);
  shft = max(shft, 1LL);
  shft = min(shft, (long long)h);
  shftm = (shft * m) % h;
  long long res = 0;
  for (int i = 0; i < n; ++i) {
    char op;
    int id;
    getc(op);
    getd(id);
    if (op == '+') {
      int hash;
      getd(hash);
      int nhash;
      res += add(id, hash, nhash);
      M[id] = nhash;
    } else {
      int hash = M[id];
      del(id, hash);
    }
  }
  cout << res << '\n';
  return 0;
}
