#include <bits/stdc++.h>
using namespace std;
bool vis[200005];
int grp[200005];
int whe[200005];
vector<int> BIT[200005];
vector<int> v[200005];
int gn;
long long ANS;
map<int, pair<int, int> > mp;
int LB(int now) { return now & -now; }
void insert(int g, int now, int val) {
  for (int i = now + 4; i < (int)BIT[g].size(); i += LB(i)) BIT[g][i] += val;
}
int query(int g, int now) {
  int s = 0;
  for (int i = now + 4; i > 0; i -= LB(i)) s += BIT[g][i];
  return s;
}
int main() {
  int h, m, n;
  scanf("%d %d %d", &h, &m, &n);
  gn = 0;
  for (int i = 0; i < h; i++) {
    if (!vis[i]) {
      int now = i;
      while (!vis[now]) {
        vis[now] = 1;
        grp[now] = gn;
        whe[now] = v[gn].size();
        v[gn].push_back(now);
        now = (now + m) % h;
      }
      gn++;
    }
  }
  for (int i = 0; i < gn; i++) {
    for (int j = 0; j < (int)v[i].size() + 10; j++) BIT[i].push_back(0);
  }
  ANS = 0;
  for (int i = 0; i < n; i++) {
    char ch;
    int idx;
    scanf(" %c %d", &ch, &idx);
    if (ch == '+') {
      int val;
      scanf("%d", &val);
      int g = grp[val];
      int N = v[g].size();
      val = whe[val];
      int s = query(g, N - 1) - query(g, val - 1);
      int l, r;
      if (s < N - val)
        l = val, r = N - 1;
      else
        l = 0, r = val - 1;
      int ans = -1;
      while (l <= r) {
        int mid = (l + r) / 2;
        int t = query(g, mid) - query(g, l - 1);
        if (t < mid - (l - 1))
          ans = mid, r = mid - 1;
        else
          l = mid + 1;
      }
      if (ans < val)
        ANS += (N - 1) - (val - 1) + ans;
      else
        ANS += (ans - 1) - (val - 1);
      insert(g, ans, 1);
      mp[idx] = make_pair(g, ans);
    } else {
      pair<int, int> p = mp[idx];
      insert(p.first, p.second, -1);
    }
  }
  printf("%I64d\n", ANS);
}
