#include <bits/stdc++.h>
using namespace std;
const int maxN = 200005;
struct Node {
  int sum;
  Node *left, *right;
  Node() {
    left = NULL;
    right = NULL;
    sum = 0;
  }
};
typedef Node *PNode;
class Tree {
 public:
  PNode root;
  int size;
  PNode bild(int rt, int l, int r) {
    if (l == r) {
      PNode cur = new Node;
      return cur;
    }
    int m = (l + r) >> 1;
    PNode cur = new Node;
    cur->left = bild(rt << 1, l, m);
    cur->right = bild((rt << 1) + 1, m + 1, r);
    cur->sum = 0;
    return cur;
  }

 public:
  Tree() {}
  Tree(int _size) {
    size = _size;
    root = bild(1, 1, size);
  }
  int suma(PNode rt, int l, int r, int L, int R) {
    if (r < l || R < L) return 0;
    if (L == l && R == r) {
      return rt->sum;
    }
    int m = (l + r) >> 1;
    int ans = 0;
    if (L <= m) ans += suma(rt->left, l, m, L, min(m, R));
    if (R > m) ans += suma(rt->right, m + 1, r, max(m + 1, L), R);
    return ans;
  }
  int ins(PNode rt, int l, int r, int L, int R) {
    if (L == l && R == r && rt->sum == r - l + 1) {
      return 0;
    }
    if (l == r) {
      rt->sum += 1;
      return l;
    }
    int m = (l + r) >> 1;
    int st = max(l, L);
    int fn = min(m, R);
    int ans = 0;
    if (st <= fn) ans = ins(rt->left, l, m, st, fn);
    if (ans != 0) {
      ++(rt->sum);
      return ans;
    }
    st = max(m + 1, L);
    fn = min(r, R);
    if (st <= fn) ans = ins(rt->right, m + 1, r, st, fn);
    if (ans != 0) {
      rt->sum++;
    }
    return ans;
  }
  int add(int num) {
    int sum = suma(root, 1, size, num, size);
    if (sum < size - num + 1) {
      return ins(root, 1, size, num, size);
    } else {
      num--;
      return ins(root, 1, size, 1, num);
    }
  }
  void del(PNode rt, int l, int r, int &num) {
    if (l == r) {
      rt->sum = 0;
      return;
    }
    int m = (l + r) >> 1;
    if (num <= m)
      del(rt->left, l, m, num);
    else
      del(rt->right, m + 1, r, num);
    rt->sum = rt->left->sum + rt->right->sum;
    return;
  }
};
int h, t, n;
int cnt;
int tr[maxN], numb[maxN];
int size[maxN];
map<int, pair<int, int> > data;
Tree *der[maxN];
long long ans = 0;
int main() {
  scanf("%d%d%d\n", &h, &t, &n);
  cnt = 0;
  for (int i = 0; i < n; ++i)
    if (tr[i] == 0) {
      cnt++;
      int j = i, kil = 0;
      while (tr[j] == 0) {
        numb[j] = ++kil;
        tr[j] = cnt;
        j = (j + t) % h;
      }
      size[cnt] = kil;
    }
  for (int i = 1; i <= cnt; ++i) {
    der[i] = new Tree(size[i]);
  }
  for (int i = (0); (i) < (n); ++(i)) {
    char q;
    cin.get(q);
    if ('+' == q) {
      int ch, hsh;
      scanf("%d %d\n", &ch, &hsh);
      int dernum = tr[hsh];
      int num = numb[hsh];
      int cur_index = der[dernum]->add(num);
      data[ch] = make_pair(tr[hsh], cur_index);
      if (cur_index < num) cur_index += size[dernum];
      if (num < cur_index) {
        ans += cur_index - num;
      }
    } else {
      int ch;
      scanf("%d\n", &ch);
      map<int, pair<int, int> >::iterator it = data.find(ch);
      int dernum = (*it).second.first;
      int num = (*it).second.second;
      der[dernum]->del(der[dernum]->root, 1, size[dernum], num);
      data.erase(ch);
    }
  }
  cout << ans << endl;
  return 0;
}
