#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 7;
const int M = 70000;
const int inf = 1e9 + 7;
const long long base = 1e18;
const double pi = acos(-1);
const double ep = 1e-9;
int cs[N];
int n, m;
int cnt = 0;
vector<int> L[N];
map<int, pair<int, int> > st;
int pos[N];
int get(int u, int v) {
  int tol = 0;
  for (int t = v; t > 0; t -= t & -t) tol += L[u][t];
  return tol;
}
int main() {
  cin >> n >> m;
  int dem = 0;
  for (int i = (int)0; i < (int)n; i++)
    if (cs[i] == 0) {
      int t = i;
      ++cnt;
      L[cnt].push_back(0);
      while (cs[t] == 0) {
        cs[t] = cnt;
        pos[t] = L[cnt].size();
        L[cnt].push_back(0);
        t = (t + m) % n;
      }
    }
  int q;
  cin >> q;
  long long ans = 0;
  while (q-- > 0) {
    char c;
    int id, h;
    for (c = getchar(); c != '+' && c != '-'; c = getchar())
      ;
    if (c == '-') {
      scanf("%d", &id);
      pair<int, int> pos = st[id];
      st.erase(id);
      int u = pos.first, v = pos.second;
      for (int t = v; t < L[u].size(); t += t & -t) {
        L[u][t]--;
      }
    } else {
      scanf("%d%d", &id, &h);
      int u = cs[h], v = pos[h];
      int tmp = get(u, v - 1);
      int lo = v, hi = L[u].size() - 1, res = -1, g;
      while (lo <= hi) {
        g = (lo + hi) / 2;
        if (get(u, g) - tmp < g - v + 1) {
          res = g;
          hi = g - 1;
        } else
          lo = g + 1;
      }
      if (res == -1) {
        lo = 1, hi = v - 1;
        while (lo <= hi) {
          g = (lo + hi) / 2;
          if (get(u, g) < g) {
            res = g;
            hi = g - 1;
          } else
            lo = g + 1;
        }
        ans = ans + L[u].size() - v + res - 1;
      } else
        ans = ans + res - v;
      for (int t = res; t < L[u].size(); t += t & -t) L[u][t]++;
      st[id] = make_pair(u, res);
    }
  }
  cout << ans;
}
