#include <bits/stdc++.h>
using namespace std;
void mytimer(string task) {}
void ext(int c) {}
int tree[2000000];
void setv(int p, int v, int a, int b, int k) {
  if (b == a + 1) {
    tree[k] = v;
    return;
  }
  int c = (a + b) / 2;
  if (p < c)
    setv(p, v, a, c, k * 2 + 1);
  else
    setv(p, v, c, b, k * 2 + 2);
  tree[k] = tree[k * 2 + 1] + tree[k * 2 + 2];
}
int first1(int l, int r, int a, int b, int k) {
  if (!tree[k]) return -1;
  if (b == a + 1) return a;
  int c = (a + b) / 2;
  if (r <= c) return first1(l, r, a, c, k * 2 + 1);
  if (l >= c) return first1(l, r, c, b, k * 2 + 2);
  int t = first1(l, c, a, c, k * 2 + 1);
  if (t != -1) return t;
  return first1(c, r, c, b, k * 2 + 2);
}
int per;
int pos[210000];
int main() {
  ios_base::sync_with_stdio(false);
  int n, m, tc;
  cin >> n >> m >> tc;
  for (int i = 0; i < (n); ++i) {
    pos[i] = -1;
    setv(i, 1, 0, n, 0);
  }
  int l = 0;
  for (int i = 0; i < (n); ++i) {
    if (pos[i] != -1) continue;
    int p = i;
    do {
      pos[p] = l++;
      p = (p + m) % n;
    } while (p != i);
    if (!per) per = l;
  }
  map<int, int> place;
  long long res = 0;
  for (int qqq = 0; qqq < (tc); ++qqq) {
    char ch;
    int id;
    cin >> ch >> id;
    if (ch == '+') {
      int h;
      cin >> h;
      h = pos[h];
      int p = first1(h, (h / per + 1) * per, 0, n, 0);
      if (p == -1) p = first1(h / per * per, h, 0, n, 0);
      if (p == -1) exit(123);
      int r = p - h;
      if (r < 0) r += per;
      res += r;
      setv(p, 0, 0, n, 0);
      place[id] = p;
    } else {
      setv(place[id], 1, 0, n, 0);
    }
  }
  cout << res;
  return 0;
}
