#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:200000000")
const double EPS = 1E-9;
const int INF = 1000000000;
const long long INF64 = (long long)1E18;
const double PI = 3.1415926535897932384626433832795;
map<int, pair<int, int> > w;
int h, m, cl[110000], cnt, num[110000];
vector<int> a[110000];
vector<int> md[110000];
int md_find(int id, int idx, int l, int r, int p) {
  if (l == p) return md[id][idx];
  int mid = (l + r) >> 1;
  int res = mid + 1;
  if (p <= mid) res = md_find(id, idx << 1, l, mid, p);
  if (res == mid + 1)
    res = md_find(id, idx << 1 | 1, mid + 1, r, max(p, mid + 1));
  return res;
}
void md_update(int id, int idx, int l, int r, int p, int val) {
  if (l == r) {
    if (val == 0)
      md[id][idx] = l;
    else
      md[id][idx] = l + 1;
    return;
  }
  int mid = (l + r) >> 1;
  if (p <= mid)
    md_update(id, idx << 1, l, mid, p, val);
  else
    md_update(id, idx << 1 | 1, mid + 1, r, p, val);
  md[id][idx] = md[id][idx << 1];
  if (md[id][idx] == mid + 1) md[id][idx] = md[id][idx << 1 | 1];
}
long long add(int id, int val) {
  int p1 = cl[val];
  val = num[val];
  int res = 0;
  int p2 = md_find(p1, 1, 0, (int)a[p1].size() - 1, val);
  res += p2 - val;
  if (p2 == (int)a[p1].size()) {
    p2 = md_find(p1, 1, 0, (int)a[p1].size() - 1, 0);
    res += p2;
  }
  md_update(p1, 1, 0, (int)a[p1].size() - 1, p2, 1);
  w[id] = make_pair(p1, p2);
  return res;
}
void free(int id) {
  int p1 = w[id].first;
  int p2 = w[id].second;
  md_update(p1, 1, 0, (int)a[p1].size() - 1, p2, 0);
}
void md_build(int id, int idx, int l, int r) {
  if (l == r) {
    md[id][idx] = l;
    return;
  }
  md[id][idx] = l;
  md_build(id, idx << 1, l, (l + r) / 2);
  md_build(id, idx << 1 | 1, (l + r) / 2 + 1, r);
}
int main() {
  int k;
  cin >> h >> m >> k;
  vector<char> u(h);
  cnt = 0;
  for (int i = 0; i < (int)(h); i++)
    if (!u[i]) {
      vector<int> c;
      int cur = i, c2 = 0;
      while (!u[cur]) {
        u[cur] = 1;
        cl[cur] = cnt;
        num[cur] = c2++;
        c.push_back(cur);
        cur = (cur + m) % h;
      }
      a[cnt] = c;
      cnt++;
    }
  for (int i = 0; i < (int)(cnt); i++) {
    md[i].resize(a[i].size() * 4);
    md_build(i, 1, 0, (int)a[i].size() - 1);
  }
  long long ans = 0;
  for (int i = 0; i < (int)(k); i++) {
    char ch;
    int id;
    scanf(" %c %d", &ch, &id);
    if (ch == '+') {
      int a;
      scanf("%d", &a);
      ans += add(id, a);
    } else
      free(id);
  }
  cout << ans << endl;
  return 0;
}
