#include <bits/stdc++.h>
using namespace std;
template <class T, class L>
bool smax(T& x, L y) {
  return x < y ? (x = y, 1) : 0;
}
template <class T, class L>
bool smin(T& x, L y) {
  return x > y ? (x = y, 1) : 0;
}
const int maxn = 2e5 + 17;
int n, m, gp[maxn], rate[maxn], cnt, sz[maxn];
template <typename KeyType, typename ValueType, class Hash = std::hash<KeyType>>
class HashMap {
 private:
  constexpr static double DefaultMaxLoadFactor = 0.25;
  std::vector<std::vector<std::pair<std::pair<KeyType, ValueType>, size_t>>>
      Buckets;
  std::vector<std::pair<size_t, size_t>> Positions;
  double MaxLoadFactor;
  Hash Hasher;
  size_t GetBucketID(const KeyType& Key) const {
    return Hasher(Key) % Buckets.size();
  }
  void RebuildHashMap(size_t NewSize) {
    std::vector<std::pair<KeyType, ValueType>> AllElements(Positions.size());
    for (size_t i = 0; i < AllElements.size(); ++i) {
      const auto& Position = Positions[i];
      AllElements[i] = Buckets[Position.first][Position.second].first;
    }
    for (auto& Row : Buckets) Row.clear();
    Buckets.resize(NewSize);
    size_t CurrentSize = 0;
    for (const auto& Elem : AllElements) {
      size_t BucketID = GetBucketID(Elem.first);
      Positions[CurrentSize] =
          std::make_pair(BucketID, Buckets[BucketID].size());
      Buckets[BucketID].emplace_back(Elem, CurrentSize);
      ++CurrentSize;
    }
  }
  void AddElement(const KeyType& Key, const ValueType& Value) {
    if (Buckets.size() == 0) RebuildHashMap(1);
    if ((double)Positions.size() > MaxLoadFactor * (double)Buckets.size())
      RebuildHashMap(Buckets.size() * 2);
    size_t BucketID = GetBucketID(Key);
    Buckets[BucketID].emplace_back(std::make_pair(Key, Value),
                                   Positions.size());
    Positions.emplace_back(BucketID, Buckets[BucketID].size() - 1);
  }

 public:
  size_t size() const { return Positions.size(); }
  bool empty() const { return (Positions.size() == 0); }
  void clear() {
    for (auto& Row : Buckets) Row.clear();
    Positions.clear();
  }
  const Hash& hash_function() const { return Hasher; }
  class iterator {
    typedef std::pair<const KeyType, ValueType>& reference;
    typedef std::pair<const KeyType, ValueType>* pointer;

   private:
    HashMap<KeyType, ValueType, Hash>* PointerToHashTable;

   public:
    std::vector<std::pair<size_t, size_t>>::iterator PositionIt;
    iterator() {}
    iterator(const std::vector<std::pair<size_t, size_t>>::iterator& PositionIt,
             HashMap<KeyType, ValueType, Hash>* PointerToHashTable)
        : PointerToHashTable(PointerToHashTable), PositionIt(PositionIt) {}
    bool operator==(const iterator& other) const {
      return PositionIt == other.PositionIt;
    }
    bool operator!=(const iterator& other) const {
      return !(operator==(other));
    }
    reference operator*() {
      return *reinterpret_cast<pointer>(
          &PointerToHashTable->Buckets[PositionIt->first][PositionIt->second]
               .first);
    }
    pointer operator->() {
      return reinterpret_cast<pointer>(
          &PointerToHashTable->Buckets[PositionIt->first][PositionIt->second]
               .first);
    }
    iterator& operator++() {
      ++PositionIt;
      return *this;
    }
    iterator operator++(int) {
      auto res = *this;
      ++PositionIt;
      return res;
    }
  };
  iterator begin() { return iterator(Positions.begin(), this); }
  iterator end() { return iterator(Positions.end(), this); }
  iterator find(const KeyType& Key) {
    if (Buckets.size() == 0) return end();
    size_t BucketID = GetBucketID(Key);
    for (const auto& Item : Buckets[BucketID]) {
      if (Item.first.first == Key) {
        return iterator(Positions.begin() + Item.second, this);
      }
    }
    return end();
  }
  class const_iterator {
    typedef std::pair<const KeyType, ValueType>& reference;
    typedef std::pair<const KeyType, ValueType>* pointer;

   private:
    const HashMap<KeyType, ValueType, Hash>* PointerToHashTable;

   public:
    std::vector<std::pair<size_t, size_t>>::const_iterator PositionIt;
    const_iterator() {}
    const_iterator(const std::vector<std::pair<size_t, size_t>>::const_iterator&
                       PositionIt,
                   const HashMap<KeyType, ValueType, Hash>* PointerToHashTable)
        : PointerToHashTable(PointerToHashTable), PositionIt(PositionIt) {}
    bool operator==(const const_iterator& other) const {
      return PositionIt == other.PositionIt;
    }
    bool operator!=(const const_iterator& other) const {
      return !(operator==(other));
    }
    const std::pair<const KeyType, ValueType>& operator*() const {
      return *reinterpret_cast<const std::pair<const KeyType, ValueType>*>(
          &PointerToHashTable->Buckets[PositionIt->first][PositionIt->second]
               .first);
    }
    const std::pair<const KeyType, ValueType>* operator->() const {
      return reinterpret_cast<const std::pair<const KeyType, ValueType>*>(
          &PointerToHashTable->Buckets[PositionIt->first][PositionIt->second]
               .first);
    }
    const_iterator& operator++() {
      ++PositionIt;
      return *this;
    }
    const_iterator operator++(int) {
      auto res = *this;
      ++PositionIt;
      return res;
    }
  };
  const_iterator begin() const {
    return const_iterator(Positions.begin(), this);
  }
  const_iterator end() const { return const_iterator(Positions.end(), this); }
  const_iterator find(const KeyType& Key) const {
    if (Buckets.size() == 0) return end();
    size_t BucketID = GetBucketID(Key);
    for (const auto& Item : Buckets[BucketID]) {
      if (Item.first.first == Key) {
        return const_iterator(Positions.begin() + Item.second, this);
      }
    }
    return end();
  }
  HashMap(const Hash& ExternalHasher = Hash()) : Hasher(ExternalHasher) {
    MaxLoadFactor = DefaultMaxLoadFactor;
  }
  HashMap(const std::initializer_list<std::pair<KeyType, ValueType>>& List,
          const Hash& ExternalHasher = Hash())
      : Hasher(ExternalHasher) {
    MaxLoadFactor = DefaultMaxLoadFactor;
    RebuildHashMap(List.size() * (MaxLoadFactor / 2) + 1);
    for (const auto& Item : List) {
      AddElement(Item.first, Item.second);
    }
  }
  HashMap(iterator beginSeg, iterator endSeg,
          const Hash& ExternalHasher = Hash())
      : Hasher(ExternalHasher) {
    MaxLoadFactor = DefaultMaxLoadFactor;
    while (beginSeg != endSeg) {
      AddElement(beginSeg->first, beginSeg->second);
      ++beginSeg;
    }
  }
  HashMap(const_iterator beginSeg, const_iterator endSeg,
          const Hash& ExternalHasher = Hash())
      : Hasher(ExternalHasher) {
    MaxLoadFactor = DefaultMaxLoadFactor;
    while (beginSeg != endSeg) {
      AddElement(beginSeg->first, beginSeg->second);
      ++beginSeg;
    }
  }
  ValueType& operator[](const KeyType& Key) {
    auto it = find(Key);
    if (it == end()) {
      AddElement(Key, ValueType());
      it = find(Key);
    }
    return it->second;
  }
  const ValueType& at(const KeyType& Key) const {
    auto it = find(Key);
    if (it == end()) throw std::out_of_range("there is no this Key");
    return it->second;
  }
  void erase(const KeyType& Key) {
    auto it = find(Key);
    if (it == end()) return;
    Buckets[it->first].erase(Buckets[it->first].begin() + it->second);
    Positions.erase(it.PositionIt);
  }
  void insert(const std::pair<KeyType, ValueType>& Item) {
    if (find(Item.first) != end()) return;
    AddElement(Item.first, Item.second);
  }
};
HashMap<int, pair<int, int>> p;
set<int> s[maxn];
vector<int> ag[maxn];
void dfs(int v, int rt = 0) {
  if (gp[v]) return;
  gp[v] = cnt, rate[v] = rt;
  s[cnt].insert(rt);
  sz[cnt]++;
  dfs((v + m) % n, rt + 1);
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0);
  long long ans = 0;
  cin >> n >> m;
  for (int i = 0; i < n; i++)
    if (!gp[i]) cnt++, dfs(i);
  int q;
  cin >> q;
  for (int id, h; q--;) {
    char c;
    cin >> c >> id;
    if (c == '+') {
      cin >> h;
      int g = gp[h], r = rate[h];
      auto it = s[g].lower_bound(r);
      if (it == s[g].end()) it = s[g].begin(), ans += sz[g];
      ans += *it - r;
      p[id] = {g, *it};
      s[g].erase(it);
    } else {
      auto tmp = p[id];
      s[tmp.first].insert(tmp.second);
    }
  }
  cout << ans << '\n';
  return 0;
}
