#include<bits/stdc++.h> 
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
template<typename T1,typename T2> bool chmin(T1 &a,T2 b){if(a<=b)return 0; a=b; return 1;}
template<typename T1,typename T2> bool chmax(T1 &a,T2 b){if(a>=b)return 0; a=b; return 1;}
int dx[4]={0,1,0,-1}, dy[4]={1,0,-1,0};
long double eps = 1e-9;
long double pi = acos(-1);


template<typename T>
struct BIT{
	vector<T> bit;
	BIT(int n) : bit(n+1) {}
	void add(int a,T w){
		for(int x=++a; x < bit.size(); x+=(x&(-x)) ){
			bit[x] += w;
		}
	}
	// return v[0]+v[1]+...+v[a-1];
	T sum(int a){
		T ret=0;
		for(int x=a;x>0;x-=(x&(-x)) ){
			ret+=bit[x];
		}
		return ret;
	}
};

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

	int n,m,q;
	cin>>n>>m>>q;
	vector<array<ll,3>> v(q);
	map<int,int> mp;
	for(int i=0;i<q;i++){
		int a,b,c;
		cin>>a>>b>>c;
		b--;
		mp[c]=0;
		v[i]={a,b,c};
	}
	mp[0]=0;
	int now = 0;
	for(auto &i:mp){
		i.second = now;
		now++;
	}
	ll ans = 0;
	int k = now;
	BIT<ll> c1(k),c2(k),s1(k),s2(k);
	int a[n]={},b[m]={};
	c1.add(0,n);
	c2.add(0,m);
	for(int i=0;i<q;i++){
		auto [t,x,y] = v[i];
		int pos = mp[y];
		if(t == 1){
			int pre = mp[a[x]];
			ans -= a[x] * c2.sum(pre);
			ans -= s2.sum(k) - s2.sum(pre);
			c1.add(pre,-1);
			c1.add(pos,1);
			s1.add(pre,-a[x]);
			s1.add(pos,y);
			a[x]=y;
			ans += y * c2.sum(pos);
			ans += s2.sum(k) - s2.sum(pos);
		}
		else{
			int pre = mp[b[x]];
			ans -= b[x] * c1.sum(pre);
			ans -= s1.sum(k) - s1.sum(pre);
			c2.add(pre,-1);
			c2.add(pos,1);
			s2.add(pre,-b[x]);
			s2.add(pos,y);
			b[x]=y;
			ans += y * c1.sum(pos);
			ans += s1.sum(k) - s1.sum(pos);
		}
		cout << ans << "\n";
	}
}
#include <bits/stdc++.h>
using namespace std;
//#include <atcoder/all>
//using namespace atcoder;
//using mint = modint1000000007;

#define int long long
#define rep(i, n) for(int i = 0, i##_len=(n); i < i##_len; ++i)
#define per(i, n) for(int i = (n)-1; i >= 0 ; --i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define len(x) ((int)(x).size())

void _cin() {} template <class Head, class... Tail> void _cin(Head&& head, Tail&&... tail) { cin >> head; _cin(forward<Tail>(tail)...); }
#define cin(Type, ...) Type __VA_ARGS__; _cin(__VA_ARGS__)
#define cinv(Type, xs, n) vector<Type> xs(n); rep(i, n) cin >> xs[i]
#define cinv2(Type, xs, ys, n) vector<Type> xs(n), ys(n); rep(i, n) cin >> xs[i] >> ys[i]
#define cinv3(Type, xs, ys, zs, n) vector<Type> xs(n), ys(n), zs(n); rep(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define cinv4(Type, xs, ys, zs, zzs, n) vector<Type> xs(n), ys(n), zs(n), zzs(n); rep(i, n) cin >> xs[i] >> ys[i] >> zs[i] >> zzs[i]
#define cinvv(Type, xs, h, w) vector<vector<Type>> xs(h, vector<Type>(w)); rep(i, h) rep(j, w) cin >> xs[i][j]

void print() { cout << endl; }
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) { cout << head; if (sizeof...(tail) != 0) cout << " "; print(forward<Tail>(tail)...); }
template <class Type> void print(vector<Type> &vec) { for (auto& a : vec) { cout << a; if (&a != &vec.back()) cout << " "; } cout << endl; }
template <class Type> void print(vector<vector<Type>> &df) { for (auto& vec : df) { print(vec); } }

void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; }
void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }
void yesno(bool b) { cout << (b ? "yes" : "no") << endl; }
template<class Integer>bool chmax(Integer &a, const Integer &b) { if (a < b) { a = b; return 1; } return 0; }
template<class Integer>bool chmin(Integer &a, const Integer &b) { if (b < a) { a = b; return 1; } return 0; }

using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;

const int inf = 1ll << 62;
const int mod = 1000000007;

void Main() {
	cin(string, s);
	reverse(all(s));
	rep(i, 10) {
		string t = s;
		reverse(all(t));
		if (t == s) {
			print("Yes");
			return;
		}
		s += "0";
	}
	print("No");
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(16);
	//int t; cin >> t; while (t--)
	Main();
}