#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 747;
int n, m, q;
int i, j, k, l;
int t[N];
map<int, pair<int, int> > wh;
long long ans;
struct ddd {
  int *b, len;
  int d;
  int *t;
  bool *u;
  int sth;
  void btree() {
    u = new bool[len];
    memset(u, false, len);
    for (d = 1; d < len * 2; d <<= 1)
      ;
    t = new int[d * 2];
    memset(t, 0, d * 4 * 2);
  }
  int rsq(int i, int j) {
    int s = 0;
    for (i += d, j += d; i <= j; i >>= 1, j >>= 1) {
      if (i & 1) {
        s += t[i];
        ++i;
      }
      if (!(j & 1)) {
        s += t[j];
        --j;
      }
    }
    return s;
  }
  void add(int id, int l, int r) {
    int c;
    int i = l, j = r, o = -1;
    while (i < j) {
      c = (i + j) >> 1;
      if (rsq(l, c) == (c - l + 1)) {
        i = c + 1;
      } else {
        o = c;
        j = c;
      }
    }
    if (o < 0) {
      cout << "wtf" << endl;
      ++*(int *)0;
      exit(0);
    }
    wh[id] = make_pair(b[o] % n, o);
    ans += (o - l);
    for (i = o + d; i; i >>= 1) t[i]++;
    if (o + len < len * 2)
      o += len;
    else
      o -= len;
    for (i = o + d; i; i >>= 1) t[i]++;
  }
  void del(int id, int k) {
    int i;
    for (i = k + d; i; i >>= 1) t[i]--;
    if (k + len < len * 2)
      i = k + len;
    else
      i = k - len;
    for (i = i + d; i; i >>= 1) t[i]--;
  }
} a[N];
int w[N][2];
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n >> m >> q;
  for (i = 0; i < n; ++i)
    if (!t[i]) {
      j = i;
      k = 0;
      for (;;) {
        ++k;
        j = (j + m) % n;
        if (j == i) break;
      }
      a[i].b = new int[k * 2];
      j = i;
      k = 0;
      for (;;) {
        a[i].b[k] = j;
        w[j][0] = i;
        w[j][1] = k;
        ++k;
        t[j] = k;
        j = (j + m) % n;
        if (j == i) break;
      }
      a[i].len = k;
      a[i].sth = i;
      for (k = 0; k < a[i].len; ++k) a[i].b[k + a[i].len] = a[i].b[k];
      a[i].btree();
    }
  char ch;
  int id, hash;
  for (k = 0; k < q; ++k) {
    cin >> ch;
    if (ch == '+') {
      cin >> id >> hash;
      i = w[hash][0];
      a[i].add(id, w[hash][1], w[hash][1] + a[i].len);
    } else {
      cin >> id;
      hash = wh[id].first;
      i = w[hash][0];
      a[i].del(id, wh[id].second);
    }
  }
  cout << ans << endl;
  return 0;
}
