#include <bits/stdc++.h>
using namespace std;
int h, n, m, i;
int p[500000], d[500000];
bool vis[500000];
map<int, int> mp;
vector<pair<int, int> > vc[500000];
int lowbit(int x) { return x & (-x); }
void insert(int l, int r, int val) {
  for (int i = r; i < (int)vc[l].size(); i += lowbit(i)) vc[l][i].second += val;
}
int query(int l, int r) {
  int ans = 0;
  for (int i = r; i > 0; i -= lowbit(i)) ans += vc[l][i].second;
  return ans;
}
int bi(int comp, int c, int s, int t) {
  while (1) {
    int mid = (s + t) / 2;
    if (t - s <= 1) {
      if (query(c, s) - comp == 1) return s;
      if (query(c, t) - comp == 1) return t;
      return 0;
    }
    if (query(c, mid) > comp)
      t = mid;
    else
      s = mid;
  }
  return 0;
}
int main() {
  scanf("%d%d%d", &h, &m, &n);
  for (i = 0; i < h; i++) {
    int tmp = i;
    if (!vis[tmp]) {
      vc[tmp].push_back(make_pair(0, 0));
      while (!vis[tmp]) {
        vc[i].push_back(make_pair(tmp, 0));
        p[tmp] = i;
        d[tmp] = vc[i].size() - 1;
        vis[tmp] = 1;
        tmp = (tmp + m) % h;
      }
      for (int j = 1; j < (int)vc[i].size(); j++) insert(i, j, 1);
    }
  }
  long long ans = 0;
  while (n--) {
    char ch[2];
    int num, val;
    scanf("%s%d", ch, &num);
    if (ch[0] == '+') {
      scanf("%d", &val);
      int init = d[val];
      int sum = query(p[val], d[val] - 1);
      int tmp;
      if ((tmp = bi(sum, p[val], d[val], vc[p[val]].size() - 1)) != 0) {
        val = vc[p[val]][tmp].first;
        mp.insert(make_pair(num, val));
        insert(p[val], tmp, -1);
        ans += (d[val] - init);
      } else {
        tmp = bi(0, p[val], 1, d[val] - 1);
        val = vc[p[val]][tmp].first;
        mp.insert(make_pair(num, val));
        insert(p[val], tmp, -1);
        ans += (vc[p[val]].size() - init + tmp - 1);
      }
    } else {
      int val = mp.find(num)->second;
      mp.erase(num);
      insert(p[val], d[val], 1);
    }
  }
  printf("%I64d\n", ans);
  return 0;
}
