#include <bits/stdc++.h>
using namespace std;
int exGcd(int a, int b, int& x, int& y) {
  if (b == 0) {
    x = 1;
    y = 0;
    return a;
  }
  int r = exGcd(b, a % b, x, y);
  int t = x;
  x = y;
  y = t - a / b * y;
  return r;
}
long long dummy;
struct Segment {
  int left, right;
  Segment *leftSon, *rightSon;
  int rest;
  void create(int l, int r) {
    left = l;
    right = r;
    rest = r - l + 1;
    if (rest > 1) {
      int m = (l + r) / 2;
      leftSon = new Segment;
      rightSon = new Segment;
      leftSon->create(l, m);
      rightSon->create(m + 1, r);
    }
  }
  int insert(int x) {
    if (x < left) x = left;
    if (rest == 0) {
      dummy += right - x + 1;
      return -1;
    }
    int ret;
    if (left == right) {
      rest = 0;
      return left;
    }
    if (x <= leftSon->right) {
      ret = leftSon->insert(x);
      if (ret >= 0) {
        rest = leftSon->rest + rightSon->rest;
        return ret;
      }
    }
    ret = rightSon->insert(x);
    if (ret >= 0) {
      rest = leftSon->rest + rightSon->rest;
      return ret;
    }
    return -1;
  }
  void remove(int x) {
    rest++;
    if (left < right) {
      if (x <= leftSon->right) {
        leftSon->remove(x);
      } else {
        rightSon->remove(x);
      }
    }
  }
};
struct CBX {
  CBX();
  CBX(int first);
  int getIndex(int hash);
  int insert(int hash);
  void remove(int pos);
  Segment* root;
  vector<int> v;
  int first;
};
const int H = 220000;
int u[H];
int step;
int h;
CBX::CBX() {}
CBX::CBX(int first) {
  this->first = first;
  int i;
  for (i = first;;) {
    v.push_back(i);
    u[i] = first;
    i += step;
    i %= h;
    if (i == first) break;
  }
  root = new Segment;
  root->create(0, v.size() - 1);
}
int CBX::getIndex(int hash) {
  int i, j;
  int g = exGcd(step, h, i, j);
  if (i < 0) {
    i = ((long long)step * h * j + i) % h;
  }
  i = (long long)i * (hash - first) / g % h;
  i %= v.size();
  return i;
}
int CBX::insert(int hash) {
  int ret = 0;
  int x = getIndex(hash);
  ret = root->insert(x);
  if (ret >= 0) {
    return ret;
  }
  ret = root->insert(0);
  return ret;
}
void CBX::remove(int pos) { root->remove(pos); }
vector<CBX> cbx;
CBX& getCBX(int hash) {
  int f = u[hash];
  int l = 0, r = cbx.size(), m;
  while (l + 1 < r) {
    m = (l + r) / 2;
    if (cbx[m].first <= f)
      l = m;
    else
      r = m;
  }
  return cbx[l];
}
void initCBX() {
  memset(u, 255, sizeof(u));
  int i;
  for (i = 0; i < h; i++) {
    if (u[i] >= 0) continue;
    cbx.push_back(CBX(i));
  }
}
vector<pair<int, int> > vID;
int getIDIndex(int id) {
  int l = 0, r = vID.size(), m;
  while (l + 1 < r) {
    m = (l + r) / 2;
    if (vID[m].first <= id)
      l = m;
    else
      r = m;
  }
  return l;
}
struct Query {
  int queryID;
  bool add;
  int id;
  int hash;
  int pos;
  void read() {
    static char s[2];
    scanf("%s%d", s, &id);
    add = s[0] == '+';
    if (add) {
      scanf("%d", &hash);
      vID.push_back(make_pair(id, queryID));
    }
  }
  int run();
};
Query query[H];
int Query::run() {
  if (add) {
    CBX& cbx = getCBX(hash);
    return pos = cbx.insert(hash);
  } else {
    int g = getIDIndex(id);
    int h = query[vID[g].second].hash;
    int p = query[vID[g].second].pos;
    CBX& cbx = getCBX(h);
    cbx.remove(p);
    return p;
  }
}
int main() {
  ios::sync_with_stdio(false);
  scanf("%d%d", &h, &step);
  initCBX();
  int n;
  scanf("%d", &n);
  int i;
  for (i = 0; i < n; i++) {
    query[i].queryID = i;
    query[i].read();
  }
  sort(vID.begin(), vID.end());
  for (i = 0; i < n; i++) {
    query[i].run();
  }
  cout << dummy << endl;
  return 0;
}
