import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.Arrays;
import java.util.HashMap;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;

public class Solution {

	BufferedReader in;
	PrintWriter out;
	StringTokenizer st;

	String nextToken() throws Exception {
		while (st == null || !st.hasMoreTokens()) {
			st = new StringTokenizer(in.readLine());
		}
		return st.nextToken();
	}

	int nextInt() throws Exception {
		return Integer.parseInt(nextToken());
	}

	final int INF = Integer.MAX_VALUE / 2;

	class SegTree {
		int C;
		int[] a;
		int cnt = 0;
		SegTree(int n) {
			C = 2;
			while (C < n) C <<= 1;
			a = new int[2 * C];
			Arrays.fill(a, INF);
		}
		void set(int pos, int val) {
			a[C + pos] = val;
			int j = (C + pos) / 2;
			while (j >= 1) {
				a[j] = Math.min(a[j * 2], a[j * 2 + 1]);
				j /= 2;
			}
		}
		int minn(int q, int w) {
			return min1(C + Math.min(q, w), C + Math.max(q, w));
		}
		int min1(int q, int w) {
			if (q == w) return a[q];
			if (q + 1 == w) return Math.min(a[q], a[w]);
			int res = min1((q + 1) / 2, (w - 1) / 2);
			if (q % 2 == 1) res = Math.min(res, a[q]);
			if (w % 2 == 0) res = Math.min(res, a[w]);
			return res;
		}
	}

	int h, m, mm;

	int[] hih, hin;

	int hi(int q) {
		return hih[q];
	}

	int hn(int q) {
		return hin[q];
	}

	void solve() throws Exception {
		h = nextInt();
		m = nextInt();
		int n = nextInt();
		hin = new int[h];
		hih = new int[h];
		Arrays.fill(hih, -1);
		int cnt = 0;
		for (int i = 0; i < h; i++) {
			if (hih[i] == -1) {
				int nb = 0;
				int j = i;
				while (hih[j] == -1) {
					hih[j] = cnt;
					hin[j] = nb++;
					j = (j + m) % h;
				}
				cnt++;
			}
		}
		mm = cnt;
		SegTree[] ss = new SegTree[mm];
		for (int i = 0; i < mm; i++) {
			ss[i] = new SegTree(h / mm);
		}
		for (int i = 0; i < h; i++) {
			ss[hi(i)].set(hn(i), hn(i));
		}
		TreeMap<Integer, Integer> hm = new TreeMap<Integer, Integer>();
		long ans = 0;
		for (int i = 0; i < n; i++) {
			char op = nextToken().charAt(0);
			if (op == '+') {
				int id = nextInt();
				int hash = nextInt();
				int qq = ss[hi(hash)].minn(hn(hash), h / mm - 1);
				if (qq == INF) {
					qq = ss[hi(hash)].minn(0, hn(hash));
					ans += qq + h / mm - hn(hash);
				} else {
					ans += qq - hn(hash);
				}
//				if (qq == INF) while (ans == ans);
				ss[hi(hash)].set(qq, INF);
				if (hm.containsKey(id)) while (ans == ans);
				hm.put(id, qq * mm + hi(hash));
			} else {
				int id = nextInt();
				int qq = hm.get(id);
				int hash = qq % mm;
//				hm.remove(qq);
				qq /= mm;
				ss[hash].set(qq, qq);
			}
		}
		out.println(ans);
	}

	public void run() {
		try {
			in = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(System.out);
			solve();
		} catch (Exception e) {
			e.printStackTrace();
			System.exit(1);
		} finally {
			out.close();
		}
	}

	public static void main(String[] args) {
		new Solution().run();
	}

}


import java.awt.Point;
import java.io.*;
import java.math.BigInteger;
import java.util.*;

import static java.lang.Math.*;

public class AC implements Runnable{

    final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null;

    BufferedReader in;
    PrintWriter out;
    StringTokenizer tok = new StringTokenizer("");

    void init() throws FileNotFoundException{
        if (ONLINE_JUDGE){
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(System.out);
        }else{
            in = new BufferedReader(new FileReader("input.txt"));
            out = new PrintWriter("output.txt");
        }
    }

    String readString() throws IOException{
        while(!tok.hasMoreTokens()){
            try{
                tok = new StringTokenizer(in.readLine());
            }catch (Exception e){
                return null;
            }
        }
        return tok.nextToken();
    }

    int readInt() throws IOException{
        return Integer.parseInt(readString());
    }

    long readLong() throws IOException{
        return Long.parseLong(readString());
    }

    double readDouble() throws IOException{
        return Double.parseDouble(readString());
    }

    public static void main(String[] args){
        new Thread(null, new AC(), "", 256 * (1L << 20)).start();
    }

    long timeBegin, timeEnd;

    void time(){
        timeEnd = System.currentTimeMillis();
        System.err.println("Time = " + (timeEnd - timeBegin));
    }

    long memoryTotal, memoryFree;

    void memory(){
        memoryFree = Runtime.getRuntime().freeMemory();
        System.err.println("Memory = " + ((memoryTotal - memoryFree) >> 10) + " KB");
    }

    void debug(Object... objects){
        if (DEBUG){
            for (Object o: objects){
                System.err.println(o.toString());
            }
        }
    }

    public void run(){
        try{
            timeBegin = System.currentTimeMillis();
            memoryTotal = Runtime.getRuntime().freeMemory();
            init();
            solve();
            out.close();
            time();
            memory();
        }catch (Exception e){
            e.printStackTrace(System.err);
            System.exit(-1);
        }
    }

    boolean DEBUG = false;

    void solve() throws Exception{
        int h = readInt();
        int m = readInt();

        Point[] pos = new Point[h];

        int size = 0;

        for (int i = 0; i < h; i++){
            if (pos[i] != null) continue;

            int t = 0;

            int cur = i;
            while (pos[cur] == null){
                pos[cur] = new Point(size, t++);

                cur = (cur + m) % h;
            }

            size++;
        }

        TreeSet<Point>[] set = new TreeSet[size];

        for (int i = 0; i < size; i++){

            set[i] = new TreeSet<Point>(new Comparator<Point>(){

                @Override
                public int compare(Point p1, Point p2) {
                    return p1.y - p2.y;
                }

            });
        }

        for (int i = 0; i < h; i++){
            int j = pos[i].x;
            int k = pos[i].y;

            set[j].add(new Point(i, k));
        }

        for (int i = 0; i < size; i++){
            set[i].add(new Point(h, set[i].size()));
        }

        HashMap<Integer, Integer> map = new HashMap<Integer, Integer>();

        long ans = 0;

        int n = readInt();
        for (int i = 0; i < n; i++){
            String sign = readString();
            int id = readInt();

            if (sign.charAt(0) == '-'){
                int hash = map.get(id);

                int j = pos[hash].x;
                int t = pos[hash].y;

                set[j].add(new Point(hash, t));
            }else{
                int hash = readInt();

                int j = pos[hash].x;
                int t = pos[hash].y;

                Point res = set[j].ceiling(new Point(hash, t));
                ans += (long) (res.y - t);

                if (res.x == h){
                    res = set[j].ceiling(new Point(-1, -1));
                    ans += (long) res.y;
                }

                set[j].remove(res);
                map.put(id, res.x);
            }
        }

        out.println(ans);
    }
}


#include <bits/stdc++.h>
#define FI first
#define SE second
#define MP make_pair
using namespace std;
const int maxn = 200010;
int h,m,n,ans;
int vis[maxn],b[maxn],rk[maxn];
char s[10];
set<int> a[maxn];
map<int, pair <int,int> > Ha;
inline void add(pair<int,int> p) {a[p.FI].insert(p.SE);}
int main()
{
	scanf("%d%d%d",&h,&m,&n);int r = 0;
	for (int i = 0; i < h; ++i)
	if (!vis[i])
	{
		for (int c = 0, j = i; !vis[j]; j = (j + m) % h, c++)
		{
			rk[j] = r; b[j] = c; a[r].insert(c);vis[j] = 1;
		}
		r++;
	}
	for (int H = 1; H <= n; ++H)
	{
		int num;
		scanf("%s",s);
		scanf("%d",&num);
		if (s[0] == '-') add(Ha[num]);
		else
		{
			int Hash;
			scanf("%d",&Hash);
			int A = rk[Hash],B = b[Hash];
			set<int> ::iterator it = a[A].lower_bound(B);
			if (it != a[A].end()) ans += *it - B;
			else it = a[A].begin(), ans += h / r - B + *it;
			Ha[num] = MP(A,*it); a[A].erase(it);
		}
	}
	cout<<ans<<endl;

}


#include <bits/stdc++.h>
#define FI first
#define SE second
#define MP make_pair
using namespace std;
const int maxn = 200010;
int h,m,n;
long long ans;
int vis[maxn],b[maxn],rk[maxn];
char s[10];
set<int> a[maxn];
map<int, pair <int,int> > Ha;
inline void add(pair<int,int> p) {a[p.FI].insert(p.SE);}
int main()
{
	scanf("%d%d%d",&h,&m,&n);int r = 0;
	for (int i = 0; i < h; ++i)
	if (!vis[i])
	{
		for (int c = 0, j = i; !vis[j]; j = (j + m) % h, c++)
		{
			rk[j] = r; b[j] = c; a[r].insert(c);vis[j] = 1;
		}
		r++;
	}
	for (int H = 1; H <= n; ++H)
	{
		int num;
		scanf("%s",s);
		scanf("%d",&num);
		if (s[0] == '-') add(Ha[num]);
		else
		{
			int Hash;
			scanf("%d",&Hash);
			int A = rk[Hash],B = b[Hash];
			set<int> ::iterator it = a[A].lower_bound(B);
			if (it != a[A].end()) ans += *it - B;
			else it = a[A].begin(), ans += h / r - B + *it;
			Ha[num] = MP(A,*it); a[A].erase(it);
		}
	}
	cout<<ans<<endl;

}


#include<bits/stdc++.h>
#include<assert.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> ii;

const int ms = 4e5+5, inf = 0x3f3f3f3f;

map<int, ii> mapa;

int inicioIdx[ms], sz[ms];
int seg[2*ms];
int ciclo[ms], posicaoNoCiclo[ms];
int n;
int h; //
int* t, *d;

int combine(int l, int r) {
	//cout << "Combinando " << l << " e " << r << endl;
	return l == -1 ? r : l;
}

void update(int p, int value) {
	//cout << "UPDATING " << p << ' ' << value << endl;
	for(t[p += n] = value; p >>= 1; ) t[p] = combine(t[p<<1], t[p<<1|1]);
}

int query(int l, int r) {
	//cout << "Query " << l << ' ' << r << endl;
	int resl = -1, resr = -1;
	for(l += n, r += n; l < r; l >>=1, r >>= 1) {
		if(l & 1) resl = combine(resl, t[l++]);
		if(r&1) resr = combine(t[--r], resr);
	}
	return combine(resl, resr);
}

int trueQuery(int x) {
	//cout << "Query True " << x << endl;
	return x == 0 ? query(x, n) : combine(query(x, n), query(0, x));
}

void updateGlobal(int i) {
	t = seg + inicioIdx[i];
	n = sz[i];
}

int main(){
	cin.tie(0);
	cin.sync_with_stdio(false);
	long long h, m, n, ans = 0;
	cin >> h >> m >> n;
	int zzz = 0;
	int ciclosAteAgora = 0;
	int cnt = 0;
	for(int i = 0; i < h; i++) {
		int pos = i;
		if(!ciclo[pos]) ++ciclosAteAgora;
		for(int j = 0; ciclo[pos] == 0; j++) {
			ciclo[pos] = ciclosAteAgora;
			posicaoNoCiclo[pos] = j;
			sz[ciclosAteAgora]++;
			cnt++;
			pos = (pos + m) % h;
		}
	}
	for(int i = 1; i <= ciclosAteAgora; i++) {
		int qnt = sz[i];
		//cout << qnt << '\n';
		inicioIdx[i] = zzz;
		updateGlobal(i);
		for(int j = 0; j < qnt; j++) update(j, j);
		zzz += 2 * qnt;
	}
	for(int i = 0; i < n ; i++) {
		string s;
		cin >> s;
		if(s == "+") {
			int hash, id;
			cin >> id >> hash;
			int t = ciclo[hash], p = posicaoNoCiclo[hash];
			updateGlobal(t);
			int posicaoInserir = trueQuery(p);
			mapa[id] = ii(t, posicaoInserir);
			ans += (posicaoInserir + sz[t] - p) % sz[t];
			update(posicaoInserir, -1);
		} else {
			int id;
			cin >> id;
			ii smt = mapa[id];
			int t = smt.first, p = smt.second;
			//cout << "Posicao de " << id << " removendo = " << p << endl;
			updateGlobal(t);
			update(p, p);
		}
	}
	cout << ans << '\n';
	return 0;
}//hello


#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 10;

int h, m, n;
int treeNum, treeIdx[MAXN];
int posIdx[MAXN];

class SegmentTree {
public:
    SegmentTree(vector<int>& members) {
        n = members.size() - 1;
        dummy = 0;
        nodes = vector<TreeNode>((n + 5) * 4);
        this->members = members;
        build(1, 1, n);
    }

    inline int add(int pos) {
        if (query(1, pos, n) == 0) {
            dummy += n - pos + 1;
            pos = 1;
        }
        int k = pos == 1 ? 1 : (query(1, 1, pos - 1) + 1);
        int firstEmpty = find(1, k);
        update(1, firstEmpty, -1);
        dummy += firstEmpty - pos;
        return firstEmpty;
    }

    inline void remove(int pos) {
        update(1, pos, 1);
    }

    inline long long getDummy() {
        return dummy;
    }
private:
    struct TreeNode {
        int l, r;
        int sum;
    };

    int n;
    long long dummy;
    vector<TreeNode> nodes;
    vector<int> members;

    inline int lc(int x) {
        return x << 1;
    }

    inline int rc(int x) {
        return lc(x) + 1;
    }

    inline void pushUp(int x) {
        nodes[x].sum = nodes[lc(x)].sum + nodes[rc(x)].sum;
    }

    void build(int x, int l, int r) {
        nodes[x].l = l;
        nodes[x].r = r;
        if (l == r) {
            nodes[x].sum = 1;
            return;
        }
        int mid = (l + r) >> 1;
        build(lc(x), l, mid);
        build(rc(x), mid + 1, r);
        pushUp(x);
    }

    int query(int x, int l, int r) {
        if (nodes[x].l == l && nodes[x].r == r) {
            return nodes[x].sum;
        }
        int mid = (nodes[x].l + nodes[x].r) >> 1;
        if (r <= mid) {
            return query(lc(x), l, r);
        }
        if (l > mid) {
            return query(rc(x), l, r);
        }
        return query(lc(x), l, mid) + query(rc(x), mid + 1, r);
    }

    void update(int x, int pos, int val) {
        nodes[x].sum += val;
        if (nodes[x].l == nodes[x].r) {
            return;
        }
        int mid = (nodes[x].l + nodes[x].r) >> 1;
        if (pos <= mid) {
            update(lc(x), pos, val);
        } else {
            update(rc(x), pos, val);
        }
    }

    int find(int x, int k) {
        if (nodes[x].l == nodes[x].r) {
            return nodes[x].l;
        }
        if (nodes[lc(x)].sum >= k) {
            return find(lc(x), k);
        }
        return find(rc(x), k - nodes[lc(x)].sum);
    }
};

int main() {
    char op[2];
    int val, pos;
    scanf("%d%d%d", &h, &m, &n);
    memset(posIdx, -1, sizeof(posIdx));
    vector<SegmentTree> trees;
    for (int i = 0; i < h; ++i) {
        if (posIdx[i] == -1) {
            int j = i;
            vector<int> members(1, 0);
            while (posIdx[j] == -1) {
                treeIdx[j] = trees.size();
                posIdx[j] = members.size();
                members.push_back(j);
                (j += m) %= h;
            }
            SegmentTree tree(members);
            trees.push_back(tree);
        }
    }
    map<int, int> valIdx, valPos;
    while (n--) {
        scanf("%s%d", op, &val);
        if (op[0] == '+') {
            scanf("%d", &pos);
            valIdx[val] = treeIdx[pos];
            valPos[val] = trees[treeIdx[pos]].add(posIdx[pos]);
        } else {
            trees[valIdx[val]].remove(valPos[val]);
            valIdx.erase(val);
            valPos.erase(val);
        }
    }
    long long dummy = 0;
    for (auto& tree : trees) {
        dummy += tree.getDummy();
    }
    cout << dummy << endl;
    return 0;
}


#include<cstdio>
#include<iostream>
#include<cstring>
#include<map>
using namespace std;
typedef __int64 LL;
const int N=2e5+10;
#define ll o<<1
#define rr o<<1|1
#define mid (l+r)/2

int clo[N<<2][2];
int L,R,Vl,Vr;
void pushdown(int l,int r,int o){
    for(int i=0;i<2;i++){
        if(!clo[o][i])continue;
        clo[ll][i]=clo[o][i];
        clo[rr][i]=clo[o][i];
        clo[o][i]=0;
    }
}
void update(int l,int r,int o){
    if(L<=l&&r<=R){
        clo[o][0]=Vl;clo[o][1]=Vr;return ;
    }
    pushdown(l,r,o);
    if(L<=mid)update(l,mid,ll);
    if(R>mid)update(mid+1,r,rr);
}

int ll0[N],rr0[N];
void query(int l,int r,int o,int x){
    if(l==r){
        ll0[l]=clo[o][0],rr0[r]=clo[o][1];
        return ;
    }
    pushdown(l,r,o);
    if(x<=mid)query(l,mid,ll,x);
    else query(mid+1,r,rr,x);
}

int id[N],st[N],ed[N],cnt,blo[N],num[N];
int vis[N];

void hor(int l,int r){
    rr0[l]=r;ll0[r]=l;
}
int h,m,n;
int s,e;
int fun(int l,int r){
    if(l<=r){
        L=l,R=r;
        update(1,h,1);
    }
    else {
        L=l,R=e;
        update(1,h,1);
        L=s,R=r;
        update(1,h,1);
    }
}

int gun(int x){
    if(x>e)return s;
    if(x<s)return e;
    return x;
}
int ok(int a,int b){
    if(a==b-1)return 0;
    if(a==e&&b==s)return 0;
    return 1;
}
void del(int t){
    num[blo[t]]--;

    if(!num[blo[t]]){
        //printf("del%d %d %d %d %d\n",t,ll0[t],rr0[t],s,e);
        return ;
    }
    s=st[blo[t]],e=ed[blo[t]];
    //printf("del%d %d %d %d %d\n",t,ll0[t],rr0[t],s,e);
    hor(ll0[t],rr0[t]);

    Vl=ll0[t],Vr=rr0[t];
    fun(gun(ll0[t]+1),gun(rr0[t]-1));
}

void add(int t){
    num[blo[t]]++;
    s=st[blo[t]],e=ed[blo[t]];
    if(num[blo[t]]==1){
        ll0[t]=rr0[t]=t;
        //printf("add%d %d %d %d %d\n",t,ll0[t],rr0[t],s,e);
        Vl=Vr=t;
        if(e-s+1!=1)fun(gun(t+1),gun(t-1));
    }
    else {
        query(1,h,1,t);
        //printf("add%d %d %d %d %d\n",t,ll0[t],rr0[t],s,e);
        hor(ll0[t],t);
        hor(t,rr0[t]);
        Vl=ll0[t],Vr=t;
        if(ok(ll0[t],t))fun(gun(ll0[t]+1),gun(t-1));
        Vl=t;Vr=rr0[t];
        if(ok(t,rr0[t]))fun(gun(t+1),gun(rr0[t]-1));
    }
}

map<int,int> mp;

int main(){
    #ifdef DouBi
    freopen("in.cpp","r",stdin);
    #endif // DouBi
    while(scanf("%d%d%d",&h,&m,&n)!=EOF){
        memset(id,0,sizeof(id));
        cnt=0;
        int pre=1;
        for(int i=0;i<h;i++)if(!id[i]){
            cnt++;
            st[cnt]=pre;

            int j=i;
            while(!id[j]){
                id[j]=pre++;
                j=(j+m)%h;
            }
            ed[cnt]=pre-1;
            num[cnt]=ed[cnt]-st[cnt]+1;
            for(int j=st[cnt];j<=ed[cnt];j++){
                hor(j,j+1);
                blo[j]=cnt;
            }
            hor(ed[cnt],st[cnt]);
        }

        memset(vis,0,sizeof(vis));
        mp.clear();
        LL ans=0;
        memset(clo,0,sizeof(clo));
        for(int i=0;i<n;i++){
            char op[2];int id1,t;scanf("%s",op);
            if(op[0]=='-'){
                scanf("%d",&id1);
                t=mp[id1];
                add(t);
                vis[t]=0;
            }
            else {
                scanf("%d%d",&id1,&t);
                t=id[t];
                if(!vis[t]){
                    mp[id1]=t;
                    vis[t]=1;
                    del(t);
                }
                else {
                    query(1,h,1,t);
                    if(rr0[t]>t)ans+=rr0[t]-t;
                    else {
                        ans+=ed[blo[t]]-t+rr0[t]-st[blo[t]]+1;
                    }
                    mp[id1]=rr0[t];
                    vis[rr0[t]]=1;
                    del(rr0[t]);
                }
                //printf("%d %d %d\n",id1,t,mp[id1]);
            }
        }
        printf("%I64d\n",ans);
    }
    return 0;
}


#include<cstdio>
#include<iostream>
#include<cstring>
#include<map>
using namespace std;
typedef __int64 LL;
const int N=2e5+10;
#define ll o<<1
#define rr o<<1|1
#define mid (l+r)/2

int clo[N<<2][2];
int L,R,Vl,Vr;
void pushdown(int l,int r,int o){
    for(int i=0;i<2;i++){
        if(!clo[o][i])continue;
        clo[ll][i]=clo[o][i];
        clo[rr][i]=clo[o][i];
        clo[o][i]=0;
    }
}
void update(int l,int r,int o){
    if(L<=l&&r<=R){
        clo[o][0]=Vl;clo[o][1]=Vr;return ;
    }
    pushdown(l,r,o);
    if(L<=mid)update(l,mid,ll);
    if(R>mid)update(mid+1,r,rr);
}

int ll0[N],rr0[N];
void query(int l,int r,int o,int x){
    if(l==r){
        ll0[l]=clo[o][0],rr0[r]=clo[o][1];
        return ;
    }
    pushdown(l,r,o);
    if(x<=mid)query(l,mid,ll,x);
    else query(mid+1,r,rr,x);
}

int id[N],st[N],ed[N],cnt,blo[N],num[N];
int vis[N];

void hor(int l,int r){
    rr0[l]=r;ll0[r]=l;
}
int h,m,n;
int s,e;
int fun(int l,int r){
    if(l<=r){
        L=l,R=r;
        update(1,n,1);
    }
    else {
        L=l,R=e;
        update(1,n,1);
        L=s,R=r;
        update(1,n,1);
    }
}

int gun(int x){
    if(x>e)return s;
    if(x<s)return e;
    return x;
}
int ok(int a,int b){
    if(a==b-1)return 0;
    if(a==e&&b==s)return 0;
    return 1;
}
void del(int t){
    num[blo[t]]--;

    if(!num[blo[t]]){
        //printf("del%d %d %d %d %d\n",t,ll0[t],rr0[t],s,e);
        return ;
    }
    s=st[blo[t]],e=ed[blo[t]];
    //printf("del%d %d %d %d %d\n",t,ll0[t],rr0[t],s,e);
    hor(ll0[t],rr0[t]);

    Vl=ll0[t],Vr=rr0[t];
    fun(gun(ll0[t]+1),gun(rr0[t]-1));
}

void add(int t){
    num[blo[t]]++;
    s=st[blo[t]],e=ed[blo[t]];
    if(num[blo[t]]==1){
        ll0[t]=rr0[t]=t;
        //printf("add%d %d %d %d %d\n",t,ll0[t],rr0[t],s,e);
        Vl=Vr=t;
        if(e-s+1!=1)fun(gun(t+1),gun(t-1));
    }
    else {
        query(1,n,1,t);
        //printf("add%d %d %d %d %d\n",t,ll0[t],rr0[t],s,e);
        hor(ll0[t],t);
        hor(t,rr0[t]);
        Vl=ll0[t],Vr=t;
        if(ok(ll0[t],t))fun(gun(ll0[t]+1),gun(t-1));
        Vl=t;Vr=rr0[t];
        if(ok(t,rr0[t]))fun(gun(t+1),gun(rr0[t]-1));
    }
}

map<int,int> mp;

int main(){
    #ifdef DouBi
    freopen("in.cpp","r",stdin);
    #endif // DouBi
    while(scanf("%d%d%d",&h,&m,&n)!=EOF){
        memset(id,0,sizeof(id));
        cnt=0;
        int pre=1;
        for(int i=0;i<h;i++)if(!id[i]){
            cnt++;
            st[cnt]=pre;

            int j=i;
            while(!id[j]){
                id[j]=pre++;
                j=(j+m)%h;
            }
            ed[cnt]=pre-1;
            num[cnt]=ed[cnt]-st[cnt]+1;
            for(int j=st[cnt];j<=ed[cnt];j++){
                hor(j,j+1);
                blo[j]=cnt;
            }
            hor(ed[cnt],st[cnt]);
        }

        memset(vis,0,sizeof(vis));
        mp.clear();
        LL ans=0;
        memset(clo,0,sizeof(clo));
        for(int i=0;i<n;i++){
            char op[2];int id1,t;scanf("%s",op);
            if(op[0]=='-'){
                scanf("%d",&id1);
                t=mp[id1];
                add(t);
                vis[t]=0;
            }
            else {
                scanf("%d%d",&id1,&t);
                t=id[t];
                if(!vis[t]){
                    mp[id1]=t;
                    vis[t]=1;
                    del(t);
                }
                else {
                    query(1,n,1,t);
                    if(rr0[t]>t)ans+=rr0[t]-t;
                    else {
                        ans+=ed[blo[t]]-t+rr0[t]-st[blo[t]]+1;
                    }
                    mp[id1]=rr0[t];
                    vis[rr0[t]]=1;
                    del(rr0[t]);
                }
                //printf("%d %d %d\n",id1,t,mp[id1]);
            }
        }
        printf("%I64d\n",ans);
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define war(i,s,n) for(long long i=s;i<n;i++)
#define pb push_back
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL)
#define fr first
#define sc second
#define mod 1000000007
#define vctr2d vector<vector<long long>>
#define vctr vector<long long>
#define pll pair<long long,long long>
#define rz(n) resize(n)
#define all(v) v.begin(),v.end()
#define mkp make_pair
#define mod2  998244353
#define arrin(a,n) for(int i = 0; i < n ; i++){cin>>a[i];}
#define arrout(a,n) for(int i = 0;i < n; i++){cout<<a[i]<<" ";}
#define ex(s) cout<<s<<endl;exit(0);
#define itr iterator
#define tra(it,m) for(it=m.begin();it!=m.end();++it)
//___________________________________________________________________________________________________________________________________________________________

int main()
{
          int h,m,n;
          cin>>h>>m>>n;
          vector<int> strt;
          map<int,int> cycl;
          bool vis[h];
          memset(vis,h,false);
          int kk = 0;
          set<int> dmm[h+1];
          war(i,0,m)
          {
                    if(vis[i]){continue;}
                    int ii = i;
                    while(1)
                    {
                              if(vis[ii]){break;}
                              cycl[ii] = kk;
                              dmm[kk].insert(ii);
                              vis[ii] = true;
                              ii += m;
                              ii %= m;

                    }
                    kk++;
          }
          war(i,0,m)
          {
                    int ii = i;
                    while(ii < h)
                    {
                              dmm[i].insert(ii);
                              ii += m;
                    }
          }
          map<int,int> hash;
          map<int,int> final;
          ll cnt = 0;
          while(n--)
          {
                    char ch;
                    cin>>ch;
                    if(ch == '+')
                    {
                              int id,t;
                              cin>>id>>t;
                              hash[id] = t;
                              if(dmm[cycl[t]].find(t) != dmm[cycl[t]].end())
                              {
                                        final[id] = t;
                                        dmm[cycl[t]].erase(t);
                                        continue;
                              }
                              set<int> :: iterator it,it1;
                              it = dmm[cycl[t]].lower_bound(t);
                              int xx1;
                              if(it == dmm[cycl[t]].end()){
                                        it = dmm[cycl[t]].begin();
                                        xx1 = (*it + h - t)/m;
                                        int jj = *it;
                                        final[id] = jj;
                                        dmm[cycl[t]].erase(jj);
                              }
                              else
                              {
                                        xx1 = (*it - t)/m;
                                        int jj = *it;
                                        final[id] = jj;
                                        dmm[cycl[t]].erase(jj);
                              }
                              cnt += (ll)xx1;
                              //cout<<final[id]<<endl;
                    }
                    else
                    {
                              int id;
                              cin>>id;
                              dmm[cycl[hash[id]]].insert(final[id]);
                    }
          }
          cout<<cnt<<endl;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define war(i,s,n) for(long long i=s;i<n;i++)
#define pb push_back
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL)
#define fr first
#define sc second
#define mod 1000000007
#define vctr2d vector<vector<long long>>
#define vctr vector<long long>
#define pll pair<long long,long long>
#define rz(n) resize(n)
#define all(v) v.begin(),v.end()
#define mkp make_pair
#define mod2  998244353
#define arrin(a,n) for(int i = 0; i < n ; i++){cin>>a[i];}
#define arrout(a,n) for(int i = 0;i < n; i++){cout<<a[i]<<" ";}
#define ex(s) cout<<s<<endl;exit(0);
#define itr iterator
#define tra(it,m) for(it=m.begin();it!=m.end();++it)
//___________________________________________________________________________________________________________________________________________________________

int main()
{
          int h,m,n;
          cin>>h>>m>>n;
          vector<int> strt;
          map<int,int> cycl,set_val,cycl_size;
          bool vis[h];
          memset(vis,false,sizeof vis);
          int kk = 0;
          set<int> dmm[h+1];

          war(i,0,m)
          {
                    if(vis[i]){continue;}
                    int ii = i;
                    int jp = 0;
                    while(1)
                    {
                              if(vis[ii]){break;}
                              set_val[ii] = jp;
                              cycl[ii] = kk;
                              dmm[kk].insert(jp);
                              vis[ii] = true;
                              ii += m;
                              ii %= h;
                              jp++;
                    }
                    cycl_size[kk] = jp;
                    kk++;
          }
          map<int,int> hash;
          map<int,int> final;
          ll cnt = 0;
          while(n--)
          {
                    char ch;
                    cin>>ch;
                    if(ch == '+')
                    {
                              int id,t;
                              cin>>id>>t;
                              hash[id] = t;
                              if(dmm[cycl[t]].find(set_val[t]) != dmm[cycl[t]].end())
                              {
                                        final[id] = set_val[t];
                                        dmm[cycl[t]].erase(set_val[t]);
                                        continue;
                              }
                              set<int> :: iterator it,it1;
                              it = dmm[cycl[t]].lower_bound(set_val[t]);
                              int xx1;
                              if(it == dmm[cycl[t]].end()){
                                        it = dmm[cycl[t]].begin();
                                        xx1 = cycl_size[cycl[t]] + *it - set_val[t];
                                        int jj = *it;
                                        final[id] = jj;
                                        dmm[cycl[t]].erase(jj);
                              }
                              else
                              {
                                        xx1 = *it - set_val[t];
                                        int jj = *it;
                                        final[id] = jj;
                                        dmm[cycl[t]].erase(jj);
                              }
                              cnt += (ll)xx1;
                    }
                    else
                    {
                              int id;
                              cin>>id;
                              dmm[cycl[hash[id]]].insert(final[id]);
                    }
          }
          cout<<cnt<<endl;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define war(i,s,n) for(long long i=s;i<n;i++)
#define pb push_back
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL)
#define fr first
#define sc second
#define mod 1000000007
#define vctr2d vector<vector<long long>>
#define vctr vector<long long>
#define pll pair<long long,long long>
#define rz(n) resize(n)
#define all(v) v.begin(),v.end()
#define mkp make_pair
#define mod2  998244353
#define arrin(a,n) for(int i = 0; i < n ; i++){cin>>a[i];}
#define arrout(a,n) for(int i = 0;i < n; i++){cout<<a[i]<<" ";}
#define ex(s) cout<<s<<endl;exit(0);
#define itr iterator
#define tra(it,m) for(it=m.begin();it!=m.end();++it)
//___________________________________________________________________________________________________________________________________________________________

int main()
{
          int h,m,n;
          cin>>h>>m>>n;
          vector<int> strt;
          map<int,int> cycl;
          bool vis[h];
          memset(vis,false,sizeof vis);
          int kk = 0;
          set<int> dmm[h+1];
          war(i,0,m)
          {
                    if(vis[i]){continue;}
                    int ii = i;
                    while(1)
                    {
                              if(vis[ii]){break;}
                              cycl[ii] = kk;
                              dmm[kk].insert(ii);
                              vis[ii] = true;
                              ii += m;
                              if(ii >= h)
                              {
                                        ii %= m;
                              }

                    }
                    kk++;
          }
          map<int,int> hash;
          map<int,int> final;
          ll cnt = 0;
          while(n--)
          {
                    char ch;
                    cin>>ch;
                    if(ch == '+')
                    {
                              int id,t;
                              cin>>id>>t;
                              hash[id] = t;
                              if(dmm[cycl[t]].find(t) != dmm[cycl[t]].end())
                              {
                                        final[id] = t;
                                        dmm[cycl[t]].erase(t);

                                        continue;
                              }
                              set<int> :: iterator it,it1;
                              it = dmm[cycl[t]].lower_bound(t);
                              int xx1;
                              if(it == dmm[cycl[t]].end()){
                                        it = dmm[cycl[t]].begin();
                                        xx1 = (*it + h - t)/m;
                                        int jj = *it;
                                        final[id] = jj;
                                        dmm[cycl[t]].erase(jj);
                              }
                              else
                              {
                                        xx1 = (*it - t)/m;
                                        int jj = *it;
                                        final[id] = jj;
                                        dmm[cycl[t]].erase(jj);
                              }
                              cnt += (ll)xx1;
                    }
                    else
                    {
                              int id;
                              cin>>id;
                              dmm[cycl[hash[id]]].insert(final[id]);
                    }
          }
          cout<<cnt<<endl;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define war(i,s,n) for(long long i=s;i<n;i++)
#define pb push_back
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL)
#define fr first
#define sc second
#define mod 1000000007
#define vctr2d vector<vector<long long>>
#define vctr vector<long long>
#define pll pair<long long,long long>
#define rz(n) resize(n)
#define all(v) v.begin(),v.end()
#define mkp make_pair
#define mod2  998244353
#define arrin(a,n) for(int i = 0; i < n ; i++){cin>>a[i];}
#define arrout(a,n) for(int i = 0;i < n; i++){cout<<a[i]<<" ";}
#define ex(s) cout<<s<<endl;exit(0);
#define itr iterator
#define tra(it,m) for(it=m.begin();it!=m.end();++it)
//___________________________________________________________________________________________________________________________________________________________
const int N = 200005;
int cycl[N],set_val[N],cycl_size[N];
int main()
{

          int h,m,n;
          cin>>h>>m>>n;
          vector<int> strt;
          bool vis[h];
          memset(vis,false,sizeof vis);
          int kk = 0;
          set<int> dmm[h+1];
          war(i,0,m)
          {
                    if(vis[i]){continue;}
                    int ii = i;
                    int jp = 0;
                    while(1)
                    {
                              if(vis[ii]){break;}
                              set_val[ii] = jp;
                              cycl[ii] = kk;
                              dmm[kk].insert(jp);
                              vis[ii] = true;
                              ii += m;
                              ii %= h;
                              jp++;
                    }
                    cycl_size[kk] = jp;
                    kk++;
          }
          map<int,int> hash;
          map<int,int> final;
          ll cnt = 0;
          while(n--)
          {
                    char ch;
                    scanf(" %c",&ch);
                    if(ch == '+')
                    {
                              int id,t;
                              scanf("%d%d",&id,&t);
                              hash[id] = t;
                              if(dmm[cycl[t]].find(set_val[t]) != dmm[cycl[t]].end())
                              {
                                        final[id] = set_val[t];
                                        dmm[cycl[t]].erase(set_val[t]);
                                        continue;
                              }
                              set<int> :: iterator it,it1;
                              it = dmm[cycl[t]].lower_bound(set_val[t]);
                              int xx1;
                              if(it == dmm[cycl[t]].end()){
                                        it = dmm[cycl[t]].begin();
                                        xx1 = cycl_size[cycl[t]] + *it - set_val[t];
                                        int jj = *it;
                                        final[id] = jj;
                                        dmm[cycl[t]].erase(jj);
                              }
                              else
                              {
                                        xx1 = *it - set_val[t];
                                        int jj = *it;
                                        final[id] = jj;
                                        dmm[cycl[t]].erase(jj);
                              }
                              cnt += (ll)xx1;
                    }
                    else
                    {
                              int id;
                              scanf("%d",&id);
                              dmm[cycl[hash[id]]].insert(final[id]);
                    }
          }
          cout<<cnt<<endl;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define war(i,s,n) for(long long i=s;i<n;i++)
#define pb push_back
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL)
#define fr first
#define sc second
#define mod 1000000007
#define vctr2d vector<vector<long long>>
#define vctr vector<long long>
#define pll pair<long long,long long>
#define rz(n) resize(n)
#define all(v) v.begin(),v.end()
#define mkp make_pair
#define mod2  998244353
#define arrin(a,n) for(int i = 0; i < n ; i++){cin>>a[i];}
#define arrout(a,n) for(int i = 0;i < n; i++){cout<<a[i]<<" ";}
#define ex(s) cout<<s<<endl;exit(0);
#define itr iterator
#define tra(it,m) for(it=m.begin();it!=m.end();++it)
//___________________________________________________________________________________________________________________________________________________________
const int N = 200005;
int cycl[N],set_val[N],cycl_size[N];
int main()
{
          speed;
          int h,m,n;
          cin>>h>>m>>n;
          vector<int> strt;
          bool vis[h];
          memset(vis,false,sizeof vis);
          int kk = 0;
          set<int> dmm[h+1];

          war(i,0,m)
          {
                    if(vis[i]){continue;}
                    int ii = i;
                    int jp = 0;
                    while(1)
                    {
                              if(vis[ii]){break;}
                              set_val[ii] = jp;
                              cycl[ii] = kk;
                              dmm[kk].insert(jp);
                              vis[ii] = true;
                              ii += m;
                              ii %= h;
                              jp++;
                    }
                    cycl_size[kk] = jp;
                    kk++;
          }
          map<int,int> hash;
          map<int,int> final;
          ll cnt = 0;
          while(n--)
          {
                    char ch;
                    cin>>ch;
                    if(ch == '+')
                    {
                              int id,t;
                              cin>>id>>t;
                              hash[id] = t;
                              if(dmm[cycl[t]].find(set_val[t]) != dmm[cycl[t]].end())
                              {
                                        final[id] = set_val[t];
                                        dmm[cycl[t]].erase(set_val[t]);
                                        continue;
                              }
                              set<int> :: iterator it,it1;
                              it = dmm[cycl[t]].lower_bound(set_val[t]);
                              int xx1;
                              if(it == dmm[cycl[t]].end()){
                                        it = dmm[cycl[t]].begin();
                                        xx1 = cycl_size[cycl[t]] + *it - set_val[t];
                                        int jj = *it;
                                        final[id] = jj;
                                        dmm[cycl[t]].erase(jj);
                              }
                              else
                              {
                                        xx1 = *it - set_val[t];
                                        int jj = *it;
                                        final[id] = jj;
                                        dmm[cycl[t]].erase(jj);
                              }
                              cnt += (ll)xx1;
                    }
                    else
                    {
                              int id;
                              cin>>id;
                              dmm[cycl[hash[id]]].insert(final[id]);
                    }
          }
          cout<<cnt<<endl;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define war(i,s,n) for(long long i=s;i<n;i++)
#define pb push_back
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL)
#define fr first
#define sc second
#define mod 1000000007
#define vctr2d vector<vector<long long>>
#define vctr vector<long long>
#define pll pair<long long,long long>
#define rz(n) resize(n)
#define all(v) v.begin(),v.end()
#define mkp make_pair
#define mod2  998244353
#define arrin(a,n) for(int i = 0; i < n ; i++){cin>>a[i];}
#define arrout(a,n) for(int i = 0;i < n; i++){cout<<a[i]<<" ";}
#define ex(s) cout<<s<<endl;exit(0);
#define itr iterator
#define tra(it,m) for(it=m.begin();it!=m.end();++it)
//___________________________________________________________________________________________________________________________________________________________

int main()
{
          int h,m,n;
          cin>>h>>m>>n;
          set<int> dmm[m];
          war(i,0,m)
          {
                    int ii = i;
                    while(ii < h)
                    {
                              dmm[i].insert(ii);
                              ii += m;
                    }
          }
          map<int,int> hash;
          map<int,int> final;
          ll cnt = 0;
          while(n--)
          {
                    char ch;
                    cin>>ch;
                    if(ch == '+')
                    {
                              int id,t;
                              cin>>id>>t;
                              hash[id] = t;
                              if(dmm[t%m].find(t) != dmm[t%m].end())
                              {
                                        final[id] = t;
                                        dmm[t%m].erase(t);
                                        continue;
                              }
                              set<int> :: iterator it,it1;
                              it = dmm[t%m].lower_bound(t);
                              int xx1;
                              if(it == dmm[t%m].end()){
                                        it = dmm[t%m].begin();
                                        xx1 = (*it + h - t)/m;
                                        int jj = *it;
                                        final[id] = jj;
                                        dmm[t%m].erase(jj);
                              }
                              else
                              {
                                        xx1 = (*it - t)/m;
                                        int jj = *it;
                                        final[id] = jj;
                                        dmm[t%m].erase(jj);
                              }
                              cnt += (ll)xx1;
                    }
                    else
                    {
                              int id;
                              cin>>id;

                              dmm[hash[id]%m].insert(final[id]);
                    }
          }
          cout<<cnt<<endl;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define war(i,s,n) for(long long i=s;i<n;i++)
#define pb push_back
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL)
#define fr first
#define sc second
#define mod 1000000007
#define vctr2d vector<vector<long long>>
#define vctr vector<long long>
#define pll pair<long long,long long>
#define rz(n) resize(n)
#define all(v) v.begin(),v.end()
#define mkp make_pair
#define mod2  998244353
#define arrin(a,n) for(int i = 0; i < n ; i++){cin>>a[i];}
#define arrout(a,n) for(int i = 0;i < n; i++){cout<<a[i]<<" ";}
#define ex(s) cout<<s<<endl;exit(0);
#define itr iterator
#define tra(it,m) for(it=m.begin();it!=m.end();++it)
//___________________________________________________________________________________________________________________________________________________________

int main()
{
          int h,m,n;
          cin>>h>>m>>n;
          set<int> dmm[m];
          war(i,0,m)
          {
                    int ii = i;
                    while(ii < h)
                    {
                              dmm[i].insert(ii);
                              ii += m;
                    }
          }
          map<int,int> hash;
          map<int,int> final;
          ll cnt = 0;
          while(n--)
          {
                    char ch;
                    cin>>ch;
                    if(ch == '+')
                    {
                              int id,t;
                              cin>>id>>t;
                              hash[id] = t;
                              if(dmm[t%m].find(t) != dmm[t%m].end())
                              {
                                        final[id] = t;
                                        dmm[t%m].erase(t);
                                        continue;
                              }
                              set<int> :: iterator it,it1;
                              it = dmm[t%m].lower_bound(t);
                              int xx1;
                              if(it == dmm[t%m].end()){
                                        it = dmm[t%m].begin();
                                        xx1 = (*it + h - t)/m;
                                        int jj = *it;
                                        final[id] = jj;
                                        dmm[t%m].erase(jj);
                              }
                              else
                              {
                                        xx1 = (*it - t)/m;
                                        int jj = *it;
                                        final[id] = jj;
                                        dmm[t%m].erase(jj);
                              }
                              cnt += (ll)xx1;
                    }
                    else
                    {
                              int id;
                              cin>>id;
                              cout<<hash[id]<<endl;
                              dmm[hash[id]%m].insert(final[id]);
                    }
          }
          cout<<cnt<<endl;
}


//In the name of Allah

#include<bits/stdc++.h>

using namespace std;

const int Maxn = 200 * 1000 + 5;
int m, h, ans, t[Maxn];
set<pair<int, pair<int, int> > > mys;
pair<int, int> num[Maxn];
set<int> Set[Maxn];
bool mark[Maxn];

void dfs(int v, int cnt, int ind)
{
    mark[v] = true;
    num[v] = make_pair(cnt, ind); Set[cnt].insert(ind); t[cnt] = ind;
    if(! mark[(v + m) % h])
        dfs((v + m) % h, cnt, ind + 1);
    return;
}

void dfsAll()
{
    int cnt = 0;
    for(int i = 0; i < h; i ++)
        if(! mark[i])
        {
            dfs(i, cnt, 0);
            cnt ++;
        }
    return;
}

int main()
{
    ios_base::sync_with_stdio(false);
    int n;
    cin >> h >> m >> n;
    dfsAll();
    char c; int a, b;
    for(int i = 0; i < n; i ++)
    {
        cin >> c;
        if(c == '+')
        {
            cin >> a >> b;
            set<int> :: iterator it = Set[num[b].first].lower_bound(num[b].second);
            if(it != Set[num[b].first].end())
            {
                int ind = *it;
                ans += ind - num[b].second;
                Set[num[b].first].erase(it);
                mys.insert(make_pair(a, make_pair(num[b].first, ind)));
            }
            else
            {
                int ind = *Set[num[b].first].begin();
                ans += t[num[b].first] - num[b].second + ind + 1;
                Set[num[b].first].erase(Set[num[b].first].begin());
                mys.insert(make_pair(a, make_pair(num[b].first, ind)));
            }
        }
        else
        {
            cin >> a;
            set<pair<int, pair<int, int> > > :: iterator it = mys.lower_bound(make_pair(a, make_pair(-1, -1)));
            pair<int, pair<int, int> > p = *it;
            mys.erase(it);
            Set[p.second.first].insert(p.second.second);
        }
    }
    cout << ans << endl;
    return 0;
}


//In the name of Allah

#include<bits/stdc++.h>

using namespace std;

const int Maxn = 200 * 1000 + 5;
int m, h, t[Maxn];
long long ans;
set<pair<int, pair<int, int> > > mys;
pair<int, int> num[Maxn];
set<int> Set[Maxn];
bool mark[Maxn];

void dfs(int v, int cnt, int ind)
{
    mark[v] = true;
    num[v] = make_pair(cnt, ind); Set[cnt].insert(ind); t[cnt] = ind;
    if(! mark[(v + m) % h])
        dfs((v + m) % h, cnt, ind + 1);
    return;
}

void dfsAll()
{
    int cnt = 0;
    for(int i = 0; i < h; i ++)
        if(! mark[i])
        {
            dfs(i, cnt, 0);
            cnt ++;
        }
    return;
}

int main()
{
    ios_base::sync_with_stdio(false);
    int n;
    cin >> h >> m >> n;
    dfsAll();
    char c; int a, b;
    for(int i = 0; i < n; i ++)
    {
        cin >> c;
        if(c == '+')
        {
            cin >> a >> b;
            set<int> :: iterator it = Set[num[b].first].lower_bound(num[b].second);
            if(it != Set[num[b].first].end())
            {
                int ind = *it;
                ans += (long long)ind - (long long)num[b].second;
                Set[num[b].first].erase(it);
                mys.insert(make_pair(a, make_pair(num[b].first, ind)));
            }
            else
            {
                int ind = *Set[num[b].first].begin();
                ans += (long long)t[num[b].first] - (long long)num[b].second + (long long)ind + (long long)1;
                Set[num[b].first].erase(Set[num[b].first].begin());
                mys.insert(make_pair(a, make_pair(num[b].first, ind)));
            }
        }
        else
        {
            cin >> a;
            set<pair<int, pair<int, int> > > :: iterator it = mys.lower_bound(make_pair(a, make_pair(-1, -1)));
            pair<int, pair<int, int> > p = *it;
            mys.erase(it);
            Set[p.second.first].insert(p.second.second);
        }
    }
    cout << ans << endl;
    return 0;
}


//In the name of Allah

#include<bits/stdc++.h>

using namespace std;

const int Maxn = 200 * 1000 + 5;
int m, h, t[Maxn];
long long ans;
set<pair<int, pair<int, int> > > mys;
pair<int, int> num[Maxn];
set<int> Set[Maxn];
bool mark[Maxn];

void dfs(int v, int cnt, int ind)
{
    mark[v] = true;
    num[v] = make_pair(cnt, ind); Set[cnt].insert(ind); t[cnt] = ind;
    if(! mark[(v + m) % h])
        dfs((v + m) % h, cnt, ind + 1);
    return;
}

void dfsAll()
{
    int cnt = 0;
    for(int i = 0; i < h; i ++)
        if(! mark[i])
        {
            dfs(i, cnt, 0);
            cnt ++;
        }
    return;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> h >> m >> n;
    dfsAll();
    char c; int a, b;
    for(int i = 0; i < n; i ++)
    {
        cin >> c;
        if(c == '+')
        {
            cin >> a >> b;
            set<int> :: iterator it = Set[num[b].first].lower_bound(num[b].second);
            if(it != Set[num[b].first].end())
            {
                int ind = *it;
                ans += (long long)ind - (long long)num[b].second;
                Set[num[b].first].erase(it);
                mys.insert(make_pair(a, make_pair(num[b].first, ind)));
            }
            else
            {
                int ind = *Set[num[b].first].begin();
                ans += (long long)t[num[b].first] - (long long)num[b].second + (long long)ind + (long long)1;
                Set[num[b].first].erase(Set[num[b].first].begin());
                mys.insert(make_pair(a, make_pair(num[b].first, ind)));
            }
        }
        else
        {
            cin >> a;
            set<pair<int, pair<int, int> > > :: iterator it = mys.lower_bound(make_pair(a, make_pair(-1, -1)));
            pair<int, pair<int, int> > p = *it;
            mys.erase(it);
            Set[p.second.first].insert(p.second.second);
        }
    }
    cout << ans << endl;
    return 0;
}


#include <bits/stdc++.h>
#define dbg(x) cerr << ">>> " << x << endl;
#define _ << " , " <<
#define endl '\n'

using namespace std;

typedef long long ll;
typedef pair<int, int> ii;

int comp[212345], ptr;
int idx[212345];
map<int, int> place;
int h, m, n;

int merge(int x, int y) {
  if (x == -1) {
    return y;
  }
  return x;
}

struct segtree {
  int n;
  vector<int> tree;
  segtree(vector<int> base) {
    n = base.size();
    tree.resize(2 * n);
    for (int i = 0; i < n; ++i) {
      tree[i + n] = base[i];
    }
    for (int i = n - 1; i > 0; --i) {
      tree[i] = merge(tree[i + i], tree[i + i + 1]);
    }
  }
  int qry(int l) {
    int x = qry(l, n);
    if (x == -1) {
      return qry(0, l);
    }
    return x;
  }
  int qry(int l, int r) {
    int resl = -1, resr = -1;
    for (l += n, r += n; l < r; l /= 2, r /= 2) {
      if (l & 1) resl = merge(resl, tree[l++]);
      if (r & 1) resr = merge(tree[--r], resr);
    }
    return merge(resl, resr);
  }
  void upd(int pos, int val) {
    pos += n;
    tree[pos] = val;
    for (pos /= 2; pos > 0; pos /= 2) {
      tree[pos] = merge(tree[pos + pos], tree[pos + pos + 1]);
    }
  }
};

vector<int> base[212345];

void dfs(int x) {
  comp[x] = ptr;
  idx[x] = base[ptr].size();
  base[ptr].push_back(x);
  int nxt = (x + m) % h;
  if (comp[nxt] == -1) {
    dfs(nxt);
  }
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> h >> m >> n;
  int ans = 0;
  memset(comp, -1, sizeof comp);
  for (int i = 0; i < h; ++i) {
    if (comp[i] == -1) {
      dfs(i);
      ++ptr;
    }
  }

  vector<segtree> segts;
  for (int i = 0; i < ptr; ++i) {
    segts.push_back(segtree(base[i]));
  }

  while (n--) {
    char a;
    int id, hash;
    cin >> a >> id;
    if (a == '+') {
      cin >> hash;
      int pos = segts[comp[hash]].qry(idx[hash]);
      int dummy = idx[pos] - idx[hash];
      if (dummy < 0) {
        dummy += base[comp[hash]].size();
      }
      ans += dummy;
      segts[comp[pos]].upd(idx[pos], -1);
      place[id] = pos;
    } else {
      int pos = place[id];
      segts[comp[pos]].upd(idx[pos], pos);
    }
  }
  cout << ans << endl;
  return 0;
}


#include <bits/stdc++.h>
#define dbg(x) cerr << ">>> " << x << endl;
#define _ << " , " <<
#define endl '\n'

using namespace std;

typedef long long ll;
typedef pair<int, int> ii;

int comp[212345], ptr;
int idx[212345];
map<int, int> place;
int h, m, n;

int merge(int x, int y) {
  if (x == -1) {
    return y;
  }
  return x;
}

struct segtree {
  int n;
  vector<int> tree;
  segtree(vector<int> base) {
    n = base.size();
    tree.resize(2 * n);
    for (int i = 0; i < n; ++i) {
      tree[i + n] = base[i];
    }
    for (int i = n - 1; i > 0; --i) {
      tree[i] = merge(tree[i + i], tree[i + i + 1]);
    }
  }
  int qry(int l) {
    int x = qry(l, n);
    if (x == -1) {
      return qry(0, l);
    }
    return x;
  }
  int qry(int l, int r) {
    int resl = -1, resr = -1;
    for (l += n, r += n; l < r; l /= 2, r /= 2) {
      if (l & 1) resl = merge(resl, tree[l++]);
      if (r & 1) resr = merge(tree[--r], resr);
    }
    return merge(resl, resr);
  }
  void upd(int pos, int val) {
    pos += n;
    tree[pos] = val;
    for (pos /= 2; pos > 0; pos /= 2) {
      tree[pos] = merge(tree[pos + pos], tree[pos + pos + 1]);
    }
  }
};

vector<int> base[212345];

void dfs(int x) {
  comp[x] = ptr;
  idx[x] = base[ptr].size();
  base[ptr].push_back(x);
  int nxt = (x + m) % h;
  if (comp[nxt] == -1) {
    dfs(nxt);
  }
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> h >> m >> n;
  ll ans = 0;
  memset(comp, -1, sizeof comp);
  for (int i = 0; i < h; ++i) {
    if (comp[i] == -1) {
      dfs(i);
      ++ptr;
    }
  }

  vector<segtree> segts;
  for (int i = 0; i < ptr; ++i) {
    segts.push_back(segtree(base[i]));
  }

  while (n--) {
    char a;
    int id, hash;
    cin >> a >> id;
    if (a == '+') {
      cin >> hash;
      int pos = segts[comp[hash]].qry(idx[hash]);
      int dummy = idx[pos] - idx[hash];
      if (dummy < 0) {
        dummy += base[comp[hash]].size();
      }
      ans += dummy;
      segts[comp[pos]].upd(idx[pos], -1);
      place[id] = pos;
    } else {
      int pos = place[id];
      segts[comp[pos]].upd(idx[pos], pos);
    }
  }
  cout << ans << endl;
  return 0;
}


#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<utility>

using namespace std;

typedef long long ll;

const ll MAXN = 2e5 + 10;

ll h, m, n, comp[MAXN], id[MAXN], g;
bool vis[MAXN];
vector<ll>	vec[MAXN];
set<ll>	st[MAXN];
map<ll, pair<ll, ll>>	mp;
ll ans = 0;

void dfs(ll v, ll de = 0){
	if (vis[v])	return;
	vis[v] = 1;
	vec[g].push_back(v);
	comp[v] = g, id[v] = de;
	st[g].insert(de);
	dfs((v + m) % h, de + 1);
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> h >> m >> n;
	for (ll i = 0; i < n; i++)
		if (!vis[i])	dfs(i), g++;

	while (n--){
		char type;	cin >> type;
		if (type == '-'){
			ll v;	cin >> v;
			pair<ll, ll>	temp = mp[v];
			st[temp.first].insert(temp.second);
		}
		else{
			ll v, hh;	cin >> v >> hh;
			ll c = comp[hh], z = id[hh];
			auto it = st[c].lower_bound(z);
			if (it != st[c].end()){
				ans += *it - z;
				mp[v] = {c, *it};
				st[c].erase(it);
			}
			else{
				it = st[c].begin();
				ans += *it + (ll)vec[c].size() - z;
				mp[v] = {c, *it};
				st[c].erase(it);
			}
		}
	}
	cout << ans << endl;
	return	0;
}


#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <map>
#include <set>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <cassert>

using namespace std;

#define pb push_back
#define mp make_pair
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define foreach(e, x) for (__typeof(x.begin()) e = x.begin(); e != x.end(); ++e)
typedef long long LL;
typedef pair<int, int> PII;

int h, m, n;
int cnt, each;
map<int, int> ma;
vector<int> fen[200000];
char s[5];
int rev[200000];

int gcd(int a, int b) {
    while (b) a %= b, swap(a, b);
    return a;
}

inline void fenInc(int *fen, int pos) {
    for (; pos < each; pos |= pos + 1)
        ++fen[pos];
}

inline void fenDec(int *fen, int pos) {
    for (; pos < each; pos |= pos + 1)
        --fen[pos];
}

inline int fenGet(int *fen, int pos) {
    int ret = 0;
    for (; pos >= 0; pos = (pos & (pos + 1)) - 1)
        ret += fen[pos];
    return ret;
}

int main() {
    scanf("%d%d%d", &h, &m, &n);
    cnt = gcd(h, m);
    each = h / cnt;
    REP(i, cnt) fen[i].resize(each);
    for (int i = 0, ind = 0; i < each; ++i, ind = (ind + m / cnt) % each) {
        rev[ind] = i;
    }
    LL ans = 0;
    REP(query, n) {
        scanf("%s", s);
        if (s[0] == '+') {
            int id, ha;
            scanf("%d%d", &id, &ha);
            int pos = ha % cnt, ind = rev[ha / cnt];
            int *f = fen[pos].data();
            int fenTot = fenGet(f, each - 1);
            if (fenTot - fenGet(f, ind - 1) == each - ind) {
                int lo = 0, hi = ind - 1, mid;
                while (lo < hi) {
                    mid = (lo + hi) >> 1;
                    if (fenGet(f, mid) == mid + 1) {
                        lo = mid + 1;
                    } else {
                        hi = mid;
                    }
                }
                ans += each - ind + lo;
                ind = lo;
            } else {
                int lo = ind, hi = each - 1, mid;
                fenTot = fenGet(f, ind - 1);
                while (lo < hi) {
                    mid = (lo + hi) >> 1;
                    if (fenGet(f, mid) - fenTot == mid - ind + 1) {
                        lo = mid + 1;
                    } else {
                        hi = mid;
                    }
                }
                ans += lo - ind;
                ind = lo;
            }
            fenInc(f, ind);
            ha = ind * cnt + pos;
            ma[id] = ha;
        } else {
            int id;
            scanf("%d", &id);
            int ha = ma[id];
            int pos = ha % cnt, ind = ha / cnt;
            fenDec(fen[pos].data(), ind);
        }
    }
    cout << ans << endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int MAX=2e5+9;
int nx[MAX],h,m,n,cnt,a[MAX];
long long ans;
map<int,int> pos;
pair<int,int> root[MAX];
vector<int> g[MAX];
bool mark[MAX];
set<pair<int,int> > s[MAX];
int main()
{
	ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
	cin>>h>>m>>n;
	for (int i=0;i<h;i++) nx[i]=(i+m)%h;
	for (int i=0;i<h;i++)
		if (!mark[i])
		{
			int p=i,k=0;
			mark[i]=true,root[p]={cnt,k},g[cnt].push_back(p),p=nx[p];
			while (p!=i) k++,g[cnt].push_back(p),root[p]={cnt,k},mark[p]=true,p=nx[p];
			cnt++;
		}
	for (int i=0;i<cnt;i++) for (auto v:g[i]) s[i].insert({root[v].second,v});
	for (int i=0;i<n;i++)
	{
		char ch;
		cin>>ch;
		if (ch=='+')
		{
			int id,hsh;
			cin>>id>>hsh;
			int cyc=root[hsh].first;
			auto u=s[cyc].lower_bound({root[hsh].second,hsh});
			if (u==s[cyc].end()) u=s[cyc].begin(),ans+=(*u).first+g[cyc].size()-root[hsh].second;
			else ans+=(*u).first-root[hsh].second;
			pos[id]=(*u).second;
			s[cyc].erase(u);
		}
		else
		{
			int id;
			cin>>id;
			int hsh=pos[id];
			int cyc=root[hsh].first;
			s[cyc].insert({root[hsh].second,hsh});
		}
	}
	cout<<ans;
}


#include<bits/stdc++.h>
using namespace std;
const int MAX=2e5+9;
int nx[MAX],h,m,n,cnt,a[MAX],ans;
map<int,int> pos;
pair<int,int> root[MAX];
vector<int> g[MAX];
bool mark[MAX];
set<pair<int,int> > s[MAX];
int main()
{
	ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
	cin>>h>>m>>n;
	for (int i=0;i<h;i++) nx[i]=(i+m)%h;
	for (int i=0;i<h;i++)
		if (!mark[i])
		{
			int p=i,k=0;
			root[p]={cnt,k},g[cnt].push_back(p),p=nx[p];
			while (p!=i) k++,g[cnt].push_back(p),root[p]={cnt,k},p=nx[p];
			cnt++;
		}
	for (int i=0;i<cnt;i++) for (auto v:g[i]) s[i].insert({root[v].second,v});
	for (int i=0;i<n;i++)
	{
		char ch;
		cin>>ch;
		if (ch=='+')
		{
			int id,hsh;
			cin>>id>>hsh;
			int cyc=root[hsh].first;
			auto u=s[cyc].lower_bound({root[hsh].second,hsh});
			if (u==s[cyc].end()) u=s[cyc].begin(),ans+=(*u).first+g[cyc].size()-root[hsh].second;
			else ans+=(*u).first-root[hsh].second;
			pos[id]=(*u).second;
			s[cyc].erase(u);
		}
		else
		{
			int id;
			cin>>id;
			int hsh=pos[id];
			int cyc=root[hsh].first;
			s[cyc].insert({root[hsh].second,hsh});
		}
	}
	cout<<ans;
}


#include<bits/stdc++.h>
using namespace std;
const int MAX=2e5+9;
int nx[MAX],h,m,n,cnt,a[MAX],ans;
map<int,int> pos;
pair<int,int> root[MAX];
vector<int> g[MAX];
bool mark[MAX];
set<pair<int,int> > s[MAX];
int main()
{
	ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
	cin>>h>>m>>n;
	for (int i=0;i<h;i++) nx[i]=(i+m)%h;
	for (int i=0;i<h;i++)
		if (!mark[i])
		{
			int p=i,k=0;
			mark[i]=true,root[p]={cnt,k},g[cnt].push_back(p),p=nx[p];
			while (p!=i) k++,g[cnt].push_back(p),root[p]={cnt,k},mark[p]=true,p=nx[p];
			cnt++;
		}
	for (int i=0;i<cnt;i++) for (auto v:g[i]) s[i].insert({root[v].second,v});
	for (int i=0;i<n;i++)
	{
		char ch;
		cin>>ch;
		if (ch=='+')
		{
			int id,hsh;
			cin>>id>>hsh;
			int cyc=root[hsh].first;
			auto u=s[cyc].lower_bound({root[hsh].second,hsh});
			if (u==s[cyc].end()) u=s[cyc].begin(),ans+=(*u).first+g[cyc].size()-root[hsh].second;
			else ans+=(*u).first-root[hsh].second;
			pos[id]=(*u).second;
			s[cyc].erase(u);
		}
		else
		{
			int id;
			cin>>id;
			int hsh=pos[id];
			int cyc=root[hsh].first;
			s[cyc].insert({root[hsh].second,hsh});
		}
	}
	cout<<ans;
}


#include <bits/stdc++.h>
using namespace std;
//#define int long long
#define IOS ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0)
inline int in(){int32_t x ; scanf("%d",&x) ; return x ;}
inline long long lin(){long long x ; scanf("%lld",&x) ; return x;}
const int maxn = 2e5 + 10;
const int mod = 1e9 + 7;
const long long infll = 1e18 ;
const int inf = 1e9;
bool mark[maxn];
int where[maxn];
set<pair<int,int> > avai[maxn];
map<int,int> whereIsIt;
int Sz[maxn];
int Cnt[maxn];
int32_t main()
{
    int h = in() , m = in() , q = in();
    int cur = 0;
    for (int i = 0 ; i < h ; i++)
    {
        if (mark[i]) continue;
        vector<int> cycle;
        int j = i;
        while(!mark[j]){
            mark[j] = true;
            cycle.push_back(j);
            j = (j + m ) % h;
        }
        assert(j == i);
        int cnt = 0;
        Sz[cur] = (int)cycle.size();
        for (auto x : cycle){
            where[x] = cur;
            Cnt[x] = cnt ++;
            avai[cur].insert({Cnt[x],x});
        }
        cur ++;
    }
    int ans = 0;
    while (q --)
    {
        char tp = 0 ;do{tp = getchar() ; } while(tp != '-' && tp != '+');
        if (tp == '-')
        {
            int id = in();
            avai[where[whereIsIt[id]]].insert({Cnt[whereIsIt[id]],whereIsIt[id]});
            whereIsIt.erase(id);
        }
        else
        {
            int id = in() , Hash = in();
            set<pair<int,int> >::iterator it = avai[where[Hash]].lower_bound(make_pair(Cnt[Hash],Hash));
            int put = -1;
            if (it != avai[where[Hash]].end()){
                put = it->second;
            }else{
                put = avai[where[Hash]].begin()->second;
            }
            ans += ((Cnt[put] - Cnt[Hash] + Sz[where[Hash]]) % Sz[where[Hash]]);
            whereIsIt[id] = put;
            avai[where[Hash]].erase({Cnt[put],put});
//            cout << ans << "\n";
        }
    }
    cout << ans << "\n";
}


#include <bits/stdc++.h>
using namespace std;
//#define int long long
#define IOS ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0)
inline int in(){int32_t x ; scanf("%d",&x) ; return x ;}
inline long long lin(){long long x ; scanf("%lld",&x) ; return x;}
const int maxn = 2e5 + 10;
const int mod = 1e9 + 7;
const long long infll = 1e18 ;
const int inf = 1e9;
bool mark[maxn];
int where[maxn];
set<pair<int,int> > avai[maxn];
map<int,int> whereIsIt;
int Sz[maxn];
int Cnt[maxn];
int32_t main()
{
    int h = in() , m = in() , q = in();
    int cur = 0;
    for (int i = 0 ; i < h ; i++)
    {
        if (mark[i]) continue;
        vector<int> cycle;
        int j = i;
        while(!mark[j]){
            mark[j] = true;
            cycle.push_back(j);
            j = (j + m ) % h;
        }
        assert(j == i);
        int cnt = 0;
        Sz[cur] = (int)cycle.size();
        for (auto x : cycle){
            where[x] = cur;
            Cnt[x] = cnt ++;
            avai[cur].insert({Cnt[x],x});
        }
        cur ++;
    }
    long long ans = 0;
    while (q --)
    {
        char tp = 0 ;do{tp = getchar() ; } while(tp != '-' && tp != '+');
        if (tp == '-')
        {
            int id = in();
            avai[where[whereIsIt[id]]].insert({Cnt[whereIsIt[id]],whereIsIt[id]});
            whereIsIt.erase(id);
        }
        else
        {
            int id = in() , Hash = in();
            set<pair<int,int> >::iterator it = avai[where[Hash]].lower_bound(make_pair(Cnt[Hash],Hash));
            int put = -1;
            if (it != avai[where[Hash]].end()){
                put = it->second;
            }else{
                put = avai[where[Hash]].begin()->second;
            }
            ans += ((Cnt[put] - Cnt[Hash] + Sz[where[Hash]]) % Sz[where[Hash]]);
            whereIsIt[id] = put;
            avai[where[Hash]].erase({Cnt[put],put});
//            cout << ans << "\n";
        }
    }
    cout << ans << "\n";
}


#include<bits/stdc++.h>
#define dd(x) cout<<#x<<" = "<<x<<" "
#define de(x) cout<<#x<<" = "<<x<<"\n"
#define sz(x) int(x.size())
#define All(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef priority_queue<int> BQ;
typedef priority_queue<int,vector<int>,greater<int> > SQ;
const int maxn=2e5+10,mod=1e9+7,INF=0x3f3f3f3f;
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1
int mn[maxn<<2];
void build(int l,int r,int rt){
	mn[rt]=0;
	if (l==r)
		return;
	int m=l+r>>1;
	build(ls);build(rs);
}
int qry(int l,int r,int rt){
	if (l==r){
		if (mn[rt])
			return -1;
		mn[rt]=1;
		return l;
	}
	int m=l+r>>1,pos=-1;
	if (mn[rt<<1]==0)
		pos=qry(ls);
	else if (mn[rt<<1|1]==0)
		pos=qry(rs);
	mn[rt]=min(mn[rt<<1],mn[rt<<1|1]);
	return pos;
}
int add(int L,int R,int l,int r,int rt){
	if (L<=l&&r<=R)
		return qry(l,r,rt);
	int m=l+r>>1,pos=-1;
	if (L<=m)
		pos=add(L,R,ls);
	if (pos==-1&&R>m)
		pos=add(L,R,rs);
	mn[rt]=min(mn[rt<<1],mn[rt<<1|1]);
	return pos;
}
void del(int p,int l,int r,int rt){
	if (l==r){
		mn[rt]=0;
		return;
	}
	int m=l+r>>1;
	if (p<=m)
		del(p,ls);
	else
		del(p,rs);
	mn[rt]=min(mn[rt<<1],mn[rt<<1|1]);
}
struct node{
	int ty,id;
}a[maxn];
map<int,int> pos,hs;
vector<int> v[maxn];
int num,vis[maxn],rk[maxn],sz[maxn];
void init(int n,int m){
	num=0;
	for (int i=0;i<n;++i){
		if (vis[i])
			continue;
		++num;
		int p=0;
		for (int j=i;!vis[j];j=(j+m)%n)
			vis[j]=num,rk[j]=++p;
		sz[num]=p;
	}
}
int main()
{
	int h,m,n;
	cin>>h>>m>>n;
	init(h,m);
	char ty[2];
	for (int i=1;i<=n;++i){
		scanf("%s%d",ty,&a[i].id);
		if (ty[0]=='+'){
			int t;
			scanf("%d",&t);
			hs[a[i].id]=t;
			a[i].ty=1;
			v[vis[t]].pb(i);
		}
		else{
			int t=hs[a[i].id];
			a[i].ty=0;
			v[vis[t]].pb(i);
		}
	}
	int ans=0;
	for (int i=1;i<=num;++i){
		if (!sz(v[i]))
			continue;
		build(1,sz[i],1);
		for (auto j:v[i]){
			int ty=a[j].ty,id=a[j].id;
			if (ty){
				int t=hs[id];
				int p=rk[t];
				int res=add(p,sz[i],1,sz[i],1);
				if (res==-1){
					ans+=sz[i]-p+1;
					res=add(1,p-1,1,sz[i],1);
					ans+=res-1;
				}
				else
					ans+=res-p;
				pos[id]=res;
				//dd(t),dd(p),de(res);
			}
			else
				del(pos[id],1,sz[i],1);
		}
	}
	cout<<ans;
	return 0;
}


#include<bits/stdc++.h>
#define dd(x) cout<<#x<<" = "<<x<<" "
#define de(x) cout<<#x<<" = "<<x<<"\n"
#define sz(x) int(x.size())
#define All(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef priority_queue<int> BQ;
typedef priority_queue<int,vector<int>,greater<int> > SQ;
const int maxn=2e5+10,mod=1e9+7,INF=0x3f3f3f3f;
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1
int mn[maxn<<2];
void build(int l,int r,int rt){
	mn[rt]=0;
	if (l==r)
		return;
	int m=l+r>>1;
	build(ls);build(rs);
}
int qry(int l,int r,int rt){
	if (l==r){
		if (mn[rt])
			return -1;
		mn[rt]=1;
		return l;
	}
	int m=l+r>>1,pos=-1;
	if (mn[rt<<1]==0)
		pos=qry(ls);
	else if (mn[rt<<1|1]==0)
		pos=qry(rs);
	mn[rt]=min(mn[rt<<1],mn[rt<<1|1]);
	return pos;
}
int add(int L,int R,int l,int r,int rt){
	if (L<=l&&r<=R)
		return qry(l,r,rt);
	int m=l+r>>1,pos=-1;
	if (L<=m)
		pos=add(L,R,ls);
	if (pos==-1&&R>m)
		pos=add(L,R,rs);
	mn[rt]=min(mn[rt<<1],mn[rt<<1|1]);
	return pos;
}
void del(int p,int l,int r,int rt){
	if (l==r){
		mn[rt]=0;
		return;
	}
	int m=l+r>>1;
	if (p<=m)
		del(p,ls);
	else
		del(p,rs);
	mn[rt]=min(mn[rt<<1],mn[rt<<1|1]);
}
struct node{
	int ty,id;
}a[maxn];
map<int,int> pos,hs;
vector<int> v[maxn];
int num,vis[maxn],rk[maxn],sz[maxn];
void init(int n,int m){
	num=0;
	for (int i=0;i<n;++i){
		if (vis[i])
			continue;
		++num;
		int p=0;
		for (int j=i;!vis[j];j=(j+m)%n)
			vis[j]=num,rk[j]=++p;
		sz[num]=p;
	}
}
int main()
{
	int h,m,n;
	cin>>h>>m>>n;
	init(h,m);
	char ty[2];
	for (int i=1;i<=n;++i){
		scanf("%s%d",ty,&a[i].id);
		if (ty[0]=='+'){
			int t;
			scanf("%d",&t);
			hs[a[i].id]=t;
			a[i].ty=1;
			v[vis[t]].pb(i);
		}
		else{
			int t=hs[a[i].id];
			a[i].ty=0;
			v[vis[t]].pb(i);
		}
	}
	ll ans=0;
	for (int i=1;i<=num;++i){
		if (!sz(v[i]))
			continue;
		build(1,sz[i],1);
		for (auto j:v[i]){
			int ty=a[j].ty,id=a[j].id;
			if (ty){
				int t=hs[id];
				int p=rk[t];
				int res=add(p,sz[i],1,sz[i],1);
				if (res==-1){
					ans+=sz[i]-p+1;
					res=add(1,p-1,1,sz[i],1);
					ans+=res-1;
				}
				else
					ans+=res-p;
				pos[id]=res;
				//dd(t),dd(p),de(res);
			}
			else
				del(pos[id],1,sz[i],1);
		}
	}
	cout<<ans;
	return 0;
}


#include<bits/stdc++.h>
#define dd(x) cout<<#x<<" = "<<x<<" "
#define de(x) cout<<#x<<" = "<<x<<"\n"
#define sz(x) int(x.size())
#define All(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef priority_queue<int> BQ;
typedef priority_queue<int,vector<int>,greater<int> > SQ;
const int maxn=2e5+10,mod=1e9+7,INF=0x3f3f3f3f;
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1
int mn[maxn<<2];
void build(int l,int r,int rt){
	mn[rt]=0;
	if (l==r)
		return;
	int m=l+r>>1;
	build(ls);build(rs);
}
int qry(int l,int r,int rt){
	if (l==r){
		if (mn[rt])
			return -1;
		mn[rt]=1;
		return l;
	}
	int m=l+r>>1,pos=-1;
	if (mn[rt<<1]==0)
		pos=qry(ls);
	else if (mn[rt<<1|1]==0)
		pos=qry(rs);
	mn[rt]=min(mn[rt<<1],mn[rt<<1|1]);
	return pos;
}
int add(int L,int R,int l,int r,int rt){
	if (L<=l&&r<=R)
		return qry(l,r,rt);
	int m=l+r>>1,pos=-1;
	if (L<=m)
		pos=max(pos,add(L,R,ls));
	if (pos==-1&&R>m)
		pos=max(pos,add(L,R,rs));
	mn[rt]=min(mn[rt<<1],mn[rt<<1|1]);
	return pos;
}
void del(int p,int l,int r,int rt){
	if (l==r){
		mn[rt]=0;
		return;
	}
	int m=l+r>>1;
	if (p<=m)
		del(p,ls);
	else
		del(p,rs);
	mn[rt]=min(mn[rt<<1],mn[rt<<1|1]);
}
struct node{
	int ty,id;
}a[maxn];
map<int,int> pos,hs;
vector<int> v[maxn];
int num,vis[maxn],rk[maxn],sz[maxn];
void init(int n,int m){
	num=0;
	for (int i=0;i<n;++i){
		if (vis[i])
			continue;
		++num;
		int p=0;
		for (int j=i;!vis[j];j=(j+m)%n)
			vis[j]=num,rk[j]=++p;
		sz[num]=p;
	}
}
int main()
{
	int h,m,n;
	cin>>h>>m>>n;
	init(h,m);
	char ty[2];
	for (int i=1;i<=n;++i){
		scanf("%s%d",ty,&a[i].id);
		if (ty[0]=='+'){
			int t;
			scanf("%d",&t);
			hs[a[i].id]=t;
			a[i].ty=1;
			v[vis[t]].pb(i);
		}
		else{
			int t=hs[a[i].id];
			a[i].ty=0;
			v[vis[t]].pb(i);
		}
	}
	int ans=0;
	for (int i=1;i<=num;++i){
		if (!sz(v[i]))
			continue;
		build(1,sz(v[i]),1);
		for (auto j:v[i]){
			int ty=a[j].ty,id=a[j].id;
			if (ty){
				int t=hs[id];
				int p=rk[t];
				int res=add(p,sz[i],1,sz[i],1);
				if (res==-1){
					ans+=sz[i]-p+1;
					res=add(1,p-1,1,sz[i],1);
					ans+=res-1;
				}
				else
					ans+=res-p;
				pos[id]=res;
				//dd(t),dd(p),de(res);
			}
			else
				del(pos[id],1,sz[i],1);
		}
	}
	cout<<ans;
	return 0;
}


//God & me
#include <bits/stdc++.h>
#define pb push_back
#define X first
#define Y second
#define hash kjsdf
//#define int long long
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;}
typedef pair<int,int> pii;

const int maxn=2e5+17;
int n,m,gp[maxn],rate[maxn],cnt,sz[maxn];
unordered_map<int,pii>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);
}
main(){
  long long ans=0;
  p.max_load_factor(0.25),p.reserve(512);
  scanf("%d %d", &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;
    scanf(" %c %d", &c, &id);
    if(c=='+'){
      scanf("%d", &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.X].insert(tmp.Y);
    }
  }
  printf("%lld", ans);
  return 0;
}


 //God & me
#include <bits/stdc++.h>
#define pb push_back
#define X first
#define Y second
#define hash kjsdf
//#define int long long
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;}
typedef pair<int,int> pii;

const int maxn=2e5+17;
int n,m,gp[maxn],rate[maxn],cnt,sz[maxn];
map<int,pii>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);
}
main(){
  long long ans=0;
  scanf("%d %d", &n, &m);
  for(int i=0;i<n;i++)
    if(!gp[i])
      cnt++,dfs(i);
  int q;
  scanf("%d", &q);
  for(int id,h;q--;){
    char c;
    scanf(" %c %d", &c, &id);
    if(c=='+'){
      scanf("%d", &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.X].insert(tmp.Y);
    }
  }
  printf("%lld\n", ans);
  return 0;
}


 //God & me
#include <bits/stdc++.h>
#define pb push_back
#define X first
#define Y second
#define hash kjsdf
//#define int long long
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;}
typedef pair<int,int> pii;

const int maxn=2e5+17;
int n,m,gp[maxn],rate[maxn],cnt,sz[maxn];
map<int,pii>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);
}
main(){
  long long ans=0;
  scanf("%d %d", &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;
    scanf(" %c %d", &c, &id);
    if(c=='+'){
      scanf("%d", &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.X].insert(tmp.Y);
    }
  }
  printf("%lld\n", ans);
  return 0;
}


//God & me
#include <bits/stdc++.h>
#define pb push_back
#define X first
#define Y second
#define hash kjsdf
//#define int long long
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;}
typedef pair<int,int> pii;

const int maxn=2e5+17;
int n,m,gp[maxn],rate[maxn],cnt,sz[maxn];
unordered_map<int,pii>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);
}
main(){
  long long ans=0;
  p.max_load_factor(0.25),p.reserve(512);
  scanf("%d %d", &n, &m);
  for(int i=0;i<n;i++)
    if(!gp[i])
      cnt++,dfs(i);
  int q;
  scanf("%d", &q);
  for(int id,h;q--;){
    char c;
    scanf(" %c %d", &c, &id);
    if(c=='+'){
      scanf("%d", &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.X].insert(tmp.Y);
    }
  }
  printf("%lld", ans);
  return 0;
}


//God & me
#include <bits/stdc++.h>
#define pb push_back
#define X first
#define Y second
#define hash kjsdf
//#define int long long
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;}
typedef pair<int,int> pii;

const int maxn=2e5+17;
int n,m,gp[maxn],rate[maxn],cnt,sz[maxn];
map<int,pii>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);
}
main(){
  long long ans=0;
  scanf("%d %d", &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;
    scanf(" %c %d", &c, &id);
    if(c=='+'){
      scanf("%d", &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.X].insert(tmp.Y);
    }
  }
  printf("%d\n", ans);
  return 0;
}


#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<algorithm>
#include<map>
#define N 250000
using namespace std;
map <int,int> id;
map <int,int> q[N];
long long ans;
int i,j,k,l,n,m,h,be[N],X[N],Y[N],num,pos[N],M,x,y;
char ch[10];
int main(){
	scanf("%d%d%d",&h,&m,&n);
	for(int i=0;i<h;++i)if(!be[i]){
		int j=i;
		num=0;
		++M;
		while(!be[j]){
			num++;
			be[j]=M;
			pos[j]=num;
			j=(j+m)%h;
			q[M][num]=1;
		}
	}
	for(int i=1;i<=n;++i){
		scanf("%s",ch);
		if(ch[0]=='+'){
			scanf("%d%d",&x,&y);
			int res,tmp;
			map <int,int> :: iterator it=q[be[y]].lower_bound(pos[y]);
			if(it==q[be[y]].end())it=q[be[y]].lower_bound(0);
			tmp=it->first;
			if(tmp<pos[y])res=num-pos[y]+tmp;
			else res=tmp-pos[y];
			ans+=res;

			id[x]=i;
			q[be[y]].erase(it);
			X[i]=be[y];
			Y[i]=tmp;
		}else{
			scanf("%d",&x);
			y=id[x];
			q[X[y]][Y[y]]=1;
		}
	}
	printf("%I64d\n",ans);
}


#include <iostream>
#include <vector>
#include <utility>
#include <unordered_map>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pt;

vi pid, sid;
vector<vi> v, bit;
unordered_map<int, pt> mp;

void add(int pid, int sid) {
    int sz = bit[pid].size();
    for (int i = sid; i < sz; i += i & -i)
        bit[pid][i]++;
}

void del(int pid, int sid) {
    int sz = bit[pid].size();
    for (int i = sid; i < sz; i += i & -i)
        bit[pid][i]--;
}

int qry(int pid, int sid) {
    int ret = 0;
    for (int i = sid; i; i -= i & -i)
        ret += bit[pid][i];
    return ret;
}

int query(int pid, int l, int r) {
    return qry(pid, r) - qry(pid, l-1);
}

int get_id(int pid, int l, int r, int sz, ll& cost) {
    int low = l;
    int high = r;
    int sid = r;
    while (low <= high) {
        int mid = (low + high) / 2;
        if (query(pid, l, mid) < mid-l+1) {
            sid = mid;
            high = mid - 1;
        }
        else
            low = mid + 1;
    }
    cost += sid - l;
    if (sid > sz)
        sid -= sz;
    return sid;
}

int main() {
    int h, m, n, id, hash, pidx, sidx, sz, vn = 0;
    ll ans = 0;
    char op;

    scanf("%d%d%d", &h, &m, &n);
    pid.resize(h, -1);
    sid.resize(h, -1);

    for (int i = 0; i < h; i++)
        if (pid[i] == -1) {
            vi nv;
            id = 0;
            for (int num = i; pid[num] == -1; num = (num+m) % h) {
                nv.push_back(num);
                pid[num] = vn;
                sid[num] = ++id;
            }
            v.push_back(nv);
            vn++;
            vi nb(id+id+10);
            bit.push_back(nb);
        }

    for (int i = 0; i < n; i++) {
        getchar();
        op = getchar();
        if (op == '+') {
            scanf("%d%d", &id, &hash);
            pidx = pid[hash];
            sidx = sid[hash];
            sz = v[pidx].size();
            sidx = get_id(pidx, sidx, sidx+sz-1, sz, ans);
            mp[id] = make_pair(pidx, sidx);
            add(pidx, sidx);
            add(pidx, sidx+sz);
        }
        else {
            scanf("%d", &id);
            pidx = mp[id].first;
            sidx = mp[id].second;
            sz = v[pidx].size();
            del(pidx, sidx);
            del(pidx, sidx+sz);
        }
    }

    printf("%I64d\n", ans);

    return 0;
}


#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <map>
#define N 250000
using namespace std;
map<int, int> id;
map<int, int> q[N];
long long ans;
int i, j, k, l, n, m, h, be[N], X[N], Y[N], num, pos[N], M, x, y;
char ch[10];
int main() {
  scanf("%d%d%d", &h, &m, &n);
  for (int i = 0; i < h; ++i)
    if (!be[i]) {
      int j = i;
      num = 0;
      ++M;
      while (!be[j]) {
        num++;
        be[j] = M;
        pos[j] = num;
        j = (j + m) % h;
        q[M][num] = 1;
      }
    }
  for (int i = 1; i <= n; ++i) {
    scanf("%s", ch);
    if (ch[0] == '+') {
      scanf("%d%d", &x, &y);
      int res, tmp;
      map<int, int>::iterator it = q[be[y]].lower_bound(pos[y]);
      if (it == q[be[y]].end()) it = q[be[y]].lower_bound(0);
      tmp = it->first;
      if (tmp < pos[y])
        res = num - pos[y] + tmp;
      else
        res = tmp - pos[y];
      ans += res;

      id[x] = i;
      q[be[y]].erase(it);
      X[i] = be[y];
      Y[i] = tmp;
    } else {
      scanf("%d", &x);
      y = id[x];
      q[X[y]][Y[y]] = 1;
    }
  }
  printf("%I64d\n", ans);
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define war(i,s,n) for(long long i=s;i<n;i++)
#define pb push_back
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL)
#define fr first
#define sc second
#define mod 1000000007
#define vctr2d vector<vector<long long>>
#define vctr vector<long long>
#define pll pair<long long,long long>
#define rz(n) resize(n)
#define all(v) v.begin(),v.end()
#define mkp make_pair
#define mod2  998244353
#define arrin(a,n) for(int i = 0; i < n ; i++){cin>>a[i];}
#define arrout(a,n) for(int i = 0;i < n; i++){cout<<a[i]<<" ";}
#define ex(s) cout<<s<<endl;exit(0);
#define itr iterator
#define tra(it,m) for(it=m.begin();it!=m.end();++it)
//___________________________________________________________________________________________________________________________________________________________
const int N = 200005;
int cycl[N],set_val[N],cycl_size[N];
int main()
{

          int h,m,n;
          cin>>h>>m>>n;
          vector<int> strt;
          bool vis[h];
          memset(vis,false,sizeof vis);
          int kk = 0;
          set<int> dmm[h+1];
          war(i,0,m)
          {
                    if(vis[i]){continue;}
                    int ii = i;
                    int jp = 0;
                    while(1)
                    {
                              if(vis[ii]){break;}
                              set_val[ii] = jp;
                              cycl[ii] = kk;
                              dmm[kk].insert(jp);
                              vis[ii] = true;
                              ii += m;
                              ii %= h;
                              jp++;
                    }
                    cycl_size[kk] = jp;
                    kk++;
          }
          map<int,int> hash;
          map<int,int> final;
          ll cnt = 0;
          while(n--)
          {
                    char ch;
                    scanf(" %c",&ch);
                    if(ch == '+')
                    {
                              int id,t;
                              scanf("%d%d",&id,&t);
                              hash[id] = t;
                              if(dmm[cycl[t]].find(set_val[t]) != dmm[cycl[t]].end())
                              {
                                        final[id] = set_val[t];
                                        dmm[cycl[t]].erase(set_val[t]);
                                        continue;
                              }
                              set<int> :: iterator it,it1;
                              it = dmm[cycl[t]].lower_bound(set_val[t]);
                              int xx1;
                              if(it == dmm[cycl[t]].end()){
                                        it = dmm[cycl[t]].begin();
                                        xx1 = cycl_size[cycl[t]] + *it - set_val[t];
                                        int jj = *it;
                                        final[id] = jj;
                                        dmm[cycl[t]].erase(jj);
                              }
                              else
                              {
                                        xx1 = *it - set_val[t];
                                        int jj = *it;
                                        final[id] = jj;
                                        dmm[cycl[t]].erase(jj);
                              }
                              cnt += (ll)xx1;
                    }
                    else
                    {
                              int id;
                              scanf("%d",&id);
                              dmm[cycl[hash[id]]].insert(final[id]);
                    }
          }
          cout<<cnt<<endl;
}
//hellobig_tq//hello


//God & me
#include <bits/stdc++.h>
#define pb push_back
#define X first
#define Y second
#define hash kjsdf
//#define int long long
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;}
typedef pair<int,int> pii;

const int maxn=2e5+17;
int n,m,gp[maxn],rate[maxn],cnt,sz[maxn];
unordered_map<int,pii>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);
}
main(){
  ios::sync_with_stdio(0),cin.tie(0);
  long long ans=0;
  p.max_load_factor(0.25),p.reserve(512);
  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.X].insert(tmp.Y);
    }
  }
  cout<<ans<<'\n';
  return 0;
}


//God & me
#include <bits/stdc++.h>
#define pb push_back
#define X first
#define Y second
#define hash kjsdf
//#define int long long
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;}
typedef pair<int,int> pii;

const int maxn=2e5+17;
int n,m,gp[maxn],rate[maxn],cnt,sz[maxn];
map<int,pii>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);
}
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.X].insert(tmp.Y);
    }
  }
  cout<<ans<<'\n';
  return 0;
}


//God & me
#include <bits/stdc++.h>
#define pb push_back
#define X first
#define Y second
#define hash kjsdf
//#define int long long
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;}
typedef pair<int,int> pii;

const int maxn=2e5+17;
int n,m,a[maxn],p[maxn],hash[maxn];
set<int>s[maxn];
main(){
  ios::sync_with_stdio(0),cin.tie();
  cin>>n>>m;
  long long ans=0;
  int q;cin>>q;
  for(int i=0;i<n;i++)
    s[i%m].insert(i);
  for(int id,h;q--;){
    char c;cin>>c>>id;
    if(c=='+'){
      cin>>h;
      auto it=s[h%m].lower_bound(h);
      if(it==s[h%m].end())
	it=s[h%m].begin();
      int idx=*it;
      cerr<<idx<<'\n';
      ans+=idx>=h?(idx-h)/m:(n-h+idx)/m;
      a[idx]=id;
      p[id]=idx;
      hash[id]=h;
      s[h%m].erase(it);
    }
    else{
      int idx=p[id],h=hash[id];
      s[idx%m].insert(idx);
      ans+=idx>=h?(idx-h)/m:(n-h+idx)/m;
    }
  }
  cout<<ans<<'\n';
  return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define war(i,s,n) for(long long i=s;i<n;i++)
#define pb push_back
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL)
#define fr first
#define sc second
#define mod 1000000007
#define vctr2d vector<vector<long long>>
#define vctr vector<long long>
#define pll pair<long long,long long>
#define rz(n) resize(n)
#define all(v) v.begin(),v.end()
#define mkp make_pair
#define mod2  998244353
#define arrin(a,n) for(int i = 0; i < n ; i++){cin>>a[i];}
#define arrout(a,n) for(int i = 0;i < n; i++){cout<<a[i]<<" ";}
#define ex(s) cout<<s<<endl;exit(0);
#define itr iterator
#define tra(it,m) for(it=m.begin();it!=m.end();++it)
//___________________________________________________________________________________________________________________________________________________________
const int N = 200005;
int cycl[N],set_val[N],cycl_size[N];
int main()
{

          int h,m,n;
          cin>>h>>m>>n;
          vector<int> strt;
          bool vis[h];
          memset(vis,false,sizeof vis);
          int kk = 0;
          set<int> dmm[h+1];
          war(i,0,m)
          {
                    if(vis[i]){continue;}
                    int ii = i;
                    int jp = 0;
                    while(1)
                    {
                              if(vis[ii]){break;}
                              set_val[ii] = jp;
                              cycl[ii] = kk;
                              dmm[kk].insert(jp);
                              vis[ii] = true;
                              ii += m;
                              ii %= h;
                              jp++;
                    }
                    cycl_size[kk] = jp;
                    kk++;
          }
          map<int,int> hash;
          map<int,int> final;
          ll cnt = 0;
          while(n--)
          {
                    char ch;
                    scanf(" %c",&ch);
                    if(ch == '+')
                    {
                              int id,t;
                              scanf("%d%d",&id,&t);
                              hash[id] = t;
                              if(dmm[cycl[t]].find(set_val[t]) != dmm[cycl[t]].end())
                              {
                                        final[id] = set_val[t];
                                        dmm[cycl[t]].erase(set_val[t]);
                                        continue;
                              }
                              set<int> :: iterator it,it1;
                              it = dmm[cycl[t]].lower_bound(set_val[t]);
                              int xx1;
                              if(it == dmm[cycl[t]].end()){
                                        it = dmm[cycl[t]].begin();
                                        xx1 = cycl_size[cycl[t]] + *it - set_val[t];
                                        int jj = *it;
                                        final[id] = jj;
                                        dmm[cycl[t]].erase(jj);
                              }
                              else
                              {
                                        xx1 = *it - set_val[t];
                                        int jj = *it;
                                        final[id] = jj;
                                        dmm[cycl[t]].erase(jj);
                              }
                              cnt += (ll)xx1;
                    }
                    else
                    {
                              int id;
                              scanf("%d",&id);
                              dmm[cycl[hash[id]]].insert(final[id]);
                    }
          }
          cout<<cnt<<endl;
}
//hellobig_tq//hello//hello


#include <iostream>
#include <vector>
#include <map>

struct Node {
	Node(int v = 1, int pos = 1e9) {
		min = (v == 1 ? int(1e9) : pos);
	}

	Node(Node l, Node r) {
		min = std::min(l.min, r.min);
	}

	int min;
};

template<class i_t, class e_t>
class SegmentTree {
public:
	void init(std::vector<e_t> base) {
		n = base.size();
		tree.resize(2 * n);
		for(int i = 0; i < n; i++) {
			tree[i + n] = i_t(base[i], i);
		}
		for(int i = n - 1; i > 0; i--) {
			tree[i] = i_t(tree[i + i], tree[i + i + 1]);
		}
	}

	i_t qry(int l, int r) {
		i_t lp, rp;
		for(l += n, r += n; l < r; l /= 2, r /= 2) {
			if(l & 1) lp = i_t(lp, tree[l++]);
			if(r & 1) rp = i_t(tree[--r], rp);
		}
		return i_t(lp, rp);
	}

	void upd(int x, e_t v) {
		x += n;
		tree[x] = i_t(v, x - n);
		build(x);
	}
private:
	int n;
	std::vector<i_t> tree;

	void build(int x) {
		for(x /= 2; x > 0; x /= 2) {
			tree[x] = i_t(tree[x + x + 1], tree[x + x]);
		}
	}
};

struct Bucket {
	int n;
	SegmentTree<Node, int> tree;

	void init(int n) {
		//std::cout << "making init with size " << n << std::endl;
		this->n = n;
		tree.init(std::vector<int>(n, 0));
	}

	void erase(int pos) {
		//std::cout << "erasing in pos " << pos << std::endl;
		tree.upd(pos, 0);
	}

	int insert(int pos) {
		int x = tree.qry(pos, n).min;
		int ans = 0;
		if(x >= n) {
			x = tree.qry(0, pos).min;
			ans += n - pos + x;
		} else {
			ans += x - pos;
		}
		tree.upd(x, 1);
		return ans;
	}
};

int main() {
	std::ios_base::sync_with_stdio(false); std::cin.tie(NULL);
	int h, m, n;
	std::cin >> h >> m >> n;
	int size = 1;
	for(int i = 2; i <= h; i++) {
		if(h % i == 0 && m % i == 0) {
			size = i;
		}
	}
	std::vector<Bucket> buckets(size);
	std::vector<int> hashBucket(h, 0);
	std::vector<int> posBucket(h, 0);
	std::map<int, int> idBucket, idPos;
	for(int i = 0; i < size; i++) {
		for(int j = 0, pos = i; j < h / size; j++, pos = (pos + m) % h) {
			posBucket[pos] = j;
			hashBucket[pos] = i;
		}
		//std::cout << "trying (" << i << ", " << buckets.size() << ")\n";
		buckets[i].init(h / size);
	}
	long long ans = 0;
	//std::cout << "size is " << size << std::endl;
	for(int i = 0; i < n; i++) {
		char t;
		int id;
		std::cin >> t >> id;
		//std::cout << "on query " << t << ", " << id << std::endl;
		if(t == '+') {
			int hash;
			std::cin >> hash;
			//std::cout << "got bucket " << hashBucket[hash] << " and position " << posBucket[hash] << std::endl;
			int got = buckets[hashBucket[hash]].insert(posBucket[hash]);
			//std::cout << "got " << got << std::endl;
			idBucket[id] = hashBucket[hash];
			idPos[id] = (posBucket[hash] + got) % (h / size);
			ans += got;
		} else {
			//std::cout << "erasing on (" << idBucket[id] << ", " << idPos[id] << ")\n";
			buckets[idBucket[id]].erase(idPos[id]);
			idBucket.erase(id);
			idPos.erase(id);
		}
	}
	std::cout << ans << std::endl;
}


//IN THE NAME OF ALLLAH
#include <algorithm>
#include <iostream>

using namespace std;

long long mini = 1000 * 1000 * 1000, maxi;

int main(){
  int n;
  cin >> n;
  for(int i = 0; i < n; i ++){
    int a, b;
    cin >> a >> b;
    maxi = max(a, max(b, maxi));
    mini = min(mini, min(a, b));
  }
  cout << (max - min) * (max - min) << endl;
  return 0;
}


//IN THE NAME OF ALLLAH
#include <algorithm>
#include <iostream>

using namespace std;

long long mini = 1000 * 1000 * 1000, maxi = -1000 * 1000 * 1000;

int main(){
  int n;
  cin >> n;
  for(int i = 0; i < n; i ++){
    long long a, b;
    cin >> a >> b;
    maxi = max(a, max(b, maxi));
    mini = min(mini, min(a, b));
  }
  cout << (maxi - mini) * (maxi - mini) << endl;
  return 0;
}