#include <bits/stdc++.h>
using namespace std;
template <class T>
int popcount(T n);
template <>
int popcount(unsigned int n) {
  return n ? __builtin_popcount(n) : 0;
}
template <>
int popcount(int n) {
  return n ? __builtin_popcount(n) : 0;
}
template <>
int popcount(unsigned long long n) {
  return n ? __builtin_popcountll(n) : 0;
}
template <>
int popcount(long long n) {
  return n ? __builtin_popcountll(n) : 0;
}
template <class T>
void max_swap(T& a, const T& b) {
  a = max(a, b);
}
template <class T>
void min_swap(T& a, const T& b) {
  a = min(a, b);
}
const double EPS = 1e-8;
const double PI = acos(-1.0);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
bool valid_pos(int x, int y, int w, int h) {
  return 0 <= x && x < w && 0 <= y && y < h;
}
template <class T>
void print(T a, int n, int br = 1, const string& deli = ", ") {
  cout << "{ ";
  for (int i = 0; i < n; ++i) {
    cout << a[i];
    if (i + 1 != n) cout << deli;
  }
  cout << " }";
  while (br--) cout << endl;
}
template <class T>
void print(const vector<T>& v, int br = 1, const string& deli = ", ") {
  print(v, v.size(), br, deli);
}
template <class T>
class BIT {
 public:
  vector<T> a;
  int n;
  BIT(int n) : n(n), a(n + 1) {}
  BIT() { BIT(0); }
  void add(int i, T x) {
    assert(i > 0);
    while (i <= n) {
      a[i] += x;
      i += i & -i;
    }
  }
  T sum(int i) const {
    T res = 0;
    while (i > 0) {
      res += a[i];
      i -= i & -i;
    }
    return res;
  }
  T range_sum(int low, int high) const { return sum(high) - sum(low - 1); }
  T at(int i) const { return sum(i) - sum(i - 1); }
};
int find_empty(const BIT<int>& bit, int from) {
  if (bit.range_sum(from, bit.n) == bit.n - from + 1) from = 1;
  int low = from - 1, high = bit.n + 1;
  while (low + 1 < high) {
    int mid = (low + high) / 2;
    int k = bit.n - from;
    int diff = (mid - from) - bit.range_sum(from, mid);
    if (diff >= 0)
      high = mid;
    else
      low = mid;
  }
  return high;
}
int main() {
  ios::sync_with_stdio(false);
  int h, m, n;
  cin >> h >> m >> n;
  vector<int> no(h, -1);
  vector<int> index(h);
  vector<BIT<int> > bit;
  for (int i = 0; i < h; ++i) {
    if (no[i] == -1) {
      int k = bit.size();
      vector<int> v;
      for (int j = i, in = 1; no[j] == -1; (j += m) %= h) {
        no[j] = k;
        v.push_back(j);
        index[j] = v.size();
      }
      bit.push_back(BIT<int>(v.size()));
    }
  }
  long long res = 0;
  map<int, pair<int, int> > added;
  while (n--) {
    char op;
    int id, hash;
    cin >> op >> id;
    if (op == '+') {
      cin >> hash;
      BIT<int>& b = bit[no[hash]];
      int k = find_empty(b, index[hash]);
      b.add(k, 1);
      added[id] = pair<int, int>(no[hash], k);
      long long dummy;
      if (k >= index[hash])
        dummy = k - index[hash];
      else
        dummy = b.n - index[hash] + k;
      res += dummy;
    } else {
      bit[added[id].first].add(added[id].second, -1);
    }
  }
  cout << res << endl;
}
