#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;

#define REP(i, n, m) for(ll i=n; i<(ll)m; ++i)
#define IREP(i, n, m) for(ll i=n-1; i>=m; --i)
#define rep(i, n) REP(i, 0, n)
#define irep(i, n) IREP(i, n, 0)
#define all(v) v.begin(), v.end()
#define vprint(v) for(auto e:v){cout<<e<<" ";};cout<<endl;
#define vvprint(vv) for(auto v:vv){vprint(v)};

class FenwickTree{
    public:
        ll size;
        vll v;

        FenwickTree(ll n){
            this->size = n;
            ll m = 1;
            while(n>m) m *= 2;
            this->v = vll(m, 0);
        }

        ll _get(ll x){
            ll lsb = x & -x;
            ll r = x - lsb;
            if(r>0) return this->v[x-1] + _get(r);
            return this->v[x-1];
        }

        ll get(ll left, ll right){
            if(left<=0) return _get(right+1);
            return _get(right+1) - _get(left);
        }

        void update(ll x, ll e){
            this->v[x] += e;
            if(x==this->v.size()-1) return;
            ll lsb = (x+1) & -(x+1);
            update(x+lsb, e);
        }
};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(20);

    ll N, M, Q;
    cin >> N >> M >> Q;
    vll T(Q), X(Q), Y(Q);
    rep(i, Q) cin >> T[i] >> X[i] >> Y[i];

    vll a(N, 0), b(M, 0);

    vvll ua(Q, vll(2, -1)), ub(Q, vll(2, -1));
    rep(i, Q){
        if(T[i]==1){
            ua[i] = {a[X[i]-1], Y[i]};
            a[X[i]-1] = Y[i];
        }
        else{
            ub[i] = {b[X[i]-1], Y[i]};
            b[X[i]-1] = Y[i];
        }
    }

    FenwickTree fa(Q+1), fb(Q+1), ca(Q+1), cb(Q+1);
    ca.update(0, N);
    cb.update(0, M);
    set<ll> ys = set<ll>(all(Y));
    ys.insert(0);
    vll sys;
    for(ll y : ys) sys.push_back(y);
    unordered_map<ll, ll> y_idx;
    rep(i, sys.size()) y_idx[sys[i]] = i;

    ll t = 0;
    rep(i, Q){
        if(T[i]==1){
            ll da = fb.get(0, y_idx[ua[i][1]]) - fb.get(0, y_idx[ua[i][0]]);
            t += cb.get(0, y_idx[ua[i][1]]) * ua[i][1] - da - cb.get(0, y_idx[ua[i][0]]) * ua[i][0];
            fa.update(y_idx[ua[i][0]], -ua[i][0]);
            fa.update(y_idx[ua[i][1]], ua[i][1]);
            ca.update(y_idx[ua[i][0]], -1);
            ca.update(y_idx[ua[i][1]], 1);
        }
        else{
            ll db = fa.get(0, y_idx[ub[i][1]]) - fa.get(0, y_idx[ub[i][0]]);
            t += ca.get(0, y_idx[ub[i][1]]) * ub[i][1] - db - ca.get(0, y_idx[ub[i][0]]) * ub[i][0];
            fb.update(y_idx[ub[i][0]], -ub[i][0]);
            fb.update(y_idx[ub[i][1]], ub[i][1]);
            cb.update(y_idx[ub[i][0]], -1);
            cb.update(y_idx[ub[i][1]], 1);
        }
        cout << t << endl;
    }
}

//#include <atcoder/all>
#include <bits/stdc++.h>
#include <cassert>
#include <numeric>
using namespace std;
//using namespace atcoder;
typedef  long long LONG;
const int MOD = 1000000007;



int gcd(int x, int y) {
	if (x % y == 0) {
		return y;
	}
	else {
		return gcd(y, x % y);
		//x%y==0でないときはユーグリットの互除法を使って再帰的に関数を呼び出す。
	}
}
LONG pow2(long long x, long long n) {
	long long ret = 1;
	while (n > 0) {
		if (n & 1) ret = ret * x % MOD;  // n の最下位bitが 1 ならば x^(2^i) をかける
		x = x * x % MOD;
		n >>= 1;  // n を1bit 左にずらす
	}
	return (int)ret;
}
void printVector(const vector<int>& vec) {
	for (int value : vec) {
		cout << value << " ";
	}
	cout << endl;
}
LONG t(LONG N, LONG i) {
	return N - abs(i);
}
int count(vector<int>&a, int s) {
	int result = 0;
	for (int i = 0; i < a.size(); i++) {
		if (a[i] == s) {
			result++;
		}
	}
	return result;
}

LONG kaizyo(int N) {
	LONG result = 1;
	LONG mod = 998244353;

	for (LONG i = 2; i <= N; i++) {
		result *= i;
		result = result % mod;
	}
	return result;
}
class Point {
public:
	int x;
	int y;
};
LONG stock[3500][3500];
LONG test(int N, int task) {
	LONG mod = 998244353;
	if (N < task)return 0;
	if (N < 0)return 0;
	if (task == 0) {
		if (N == 0) {
			return 1;
		}
		else {
			return 0;
		}

	}


	if (stock[N][task] > 0)return stock[N][task];
	stock[N][task] = (test(N - 1, task - 1) + test(N, task * 2)) % mod;

	return stock[N][task] % mod;
}
class DP {
public:
	DP() {

	}
	DP(int a, int b) {
		other = a;
		path = b;

	}
	int other;
	int path;
};

void dp(vector<vector<DP>>& list, vector<int> &able, int pos, int limit) {
	for (int i = 0; i < list[pos].size(); i++) {
		if (list[pos][i].path <= limit) {
			if (able[list[pos][i].other] == 0) {
				able[list[pos][i].other] = 1;
				dp(list, able, list[pos][i].other, limit);
			}
		}
	}
}
int main() {
	LONG a, b, x, y;
	cin >> a >> b >> x >> y;
	if (y > 2*x) {
		if (b >= a) {
			cout << (b - a)*2*x + x;
			return 0;
		}
		else {
			cout << (a - b - 1)*2*x + x;
			return 0;

		}


	}
	if (b >= a) {
		cout << (b - a)*y + x;
		return 0;
	}
	else {
		cout << (a - b - 1)*y + x;
		return 0;

	}

	return 0;

}
