#include <bits/stdc++.h>
using namespace std;
const double pi = 3.141592653589793238462;
const int nmax = 210000;
struct tree {
  int tl, tr, key;
  tree *l, *r;
  tree(){};
  tree(int _tl, int _tr) : tl(_tl), tr(_tr), key(0), l(0), r(0){};
};
typedef tree *node;
void build(node &T) {
  if (T->tl != T->tr) {
    int mid = (T->tl + T->tr) >> 1;
    T->l = new tree(T->tl, mid);
    T->r = new tree(mid + 1, T->tr);
    build(T->l);
    build(T->r);
    T->key = T->l->key + T->r->key;
  };
};
void modify(node &T, int pos, int val) {
  if (T->tl == pos && T->tr == pos)
    T->key = val;
  else {
    int mid = (T->tl + T->tr) >> 1;
    if (pos <= mid)
      modify(T->l, pos, val);
    else
      modify(T->r, pos, val);
    T->key = T->l->key + T->r->key;
  };
};
int query(node T, int l, int r) {
  if (T->tr - T->tl + 1 == T->key) return -1;
  if (T->tl == T->tr && T->key != 0) return -1;
  if (T->tl >= l && T->tr <= r && T->key == 0) return T->tl;
  int mid = (T->tl + T->tr) >> 1;
  if (l > mid)
    return query(T->r, l, r);
  else if (r <= mid)
    return query(T->l, l, r);
  else {
    int test_1 = query(T->l, l, mid);
    if (test_1 == -1) return query(T->r, mid + 1, r);
    return test_1;
  };
  return -1;
};
int h, m, n, cycle_count, cycle_by_hash[nmax], pos_by_hash[nmax],
    cycle_len[nmax];
bool used[nmax];
map<int, int> id_pos, id_cycle;
node T[nmax];
long long ans = 0;
int main() {
  scanf("%d%d%d", &h, &m, &n);
  for (int i = 0; i < h; i++)
    if (!used[i]) {
      for (int j = i; !used[j]; j = (j + m) % h) {
        used[j] = true;
        pos_by_hash[j] = cycle_len[cycle_count];
        cycle_by_hash[j] = cycle_count;
        cycle_len[cycle_count]++;
      };
      cycle_count++;
    };
  for (int i = 0; i < cycle_count; i++) {
    T[i] = new tree(0, cycle_len[i] - 1);
    build(T[i]);
  }
  for (int i = 0; i < n; i++) {
    char query_type;
    scanf("\n%c", &query_type);
    if (query_type == '-') {
      int buf_id;
      scanf("%d", &buf_id);
      int cycle_num = id_cycle[buf_id];
      int cycle_pos = id_pos[buf_id];
      modify(T[cycle_num], cycle_pos, 0);
    } else {
      int buf_id, buf_hash;
      scanf("%d%d", &buf_id, &buf_hash);
      int cur_cycle = cycle_by_hash[buf_hash];
      int cur_position = pos_by_hash[buf_hash];
      int new_pos = query(T[cur_cycle], cur_position, cycle_len[cur_cycle] - 1);
      if (new_pos == -1) {
        ans += cycle_len[cur_cycle] - cur_position - 1;
        new_pos = query(T[cur_cycle], 0, cur_position - 1);
        ans += new_pos + 1;
      } else
        ans += new_pos - cur_position;
      id_cycle[buf_id] = cur_cycle;
      id_pos[buf_id] = new_pos;
      modify(T[cur_cycle], new_pos, 1);
    };
  };
  cout << ans << endl;
  return 0;
}
