#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5+5;
typedef long long LL;
int n,m,q,a[maxn],b[maxn];
LL ans;
struct Seg {
	LL sum[maxn<<5];
	int root,ch[maxn<<5][2],cnt[maxn<<5],tot;
	void upd(int &u,int l,int r,int p,int v) {
		if(!u)u = ++tot;
		cnt[u]+=v,sum[u] += v*p;
		if(l == r)return ;
		int mid = l+r>>1;
		p<=mid?upd(ch[u][0],l,mid,p,v):upd(ch[u][1],mid+1,r,p,v);
	}
	int Cnt(int u,int l,int r,int x,int y){
		if(!u||l>y||r<x)return 0;
		if(l>=x&&r<=y)return cnt[u];
		int mid = l+r>>1;
		return Cnt(ch[u][0],l,mid,x,y)+Cnt(ch[u][1],mid+1,r,x,y);
	}
	LL Sum(int u,int l,int r,int x,int y){
		if(!u||l>y||r<x)return 0;
		if(l>=x&&r<=y)return sum[u];
		int mid = l+r>>1;
		return Sum(ch[u][0],l,mid,x,y)+Sum(ch[u][1],mid+1,r,x,y);
	}
}t1,t2;
int main() {
	scanf("%d %d %d",&n,&m,&q);
	for(int i=1;i<=n;++i)t1.upd(t1.root,0,1e8,0,1);
	for(int i=1;i<=m; ++i)t2.upd(t2.root,0,1e8,0,1);
	while(q--) {
		int ty,x,y,les;
		scanf("%d %d %d",&ty,&x,&y);
		if(ty == 1){
			les = t2.Cnt(t2.root,0,1e8,0,a[x]);
			ans -= t2.Sum(t2.root,0,1e8,a[x]+1,1e8)+1ll*les*a[x];
			
			t1.upd(t1.root,0,1e8,a[x],-1),a[x] = y,t1.upd(t1.root,0,1e8,a[x],1);
			
			les = t2.Cnt(t2.root,0,1e8,0,a[x]);
			ans += t2.Sum(t2.root,0,1e8,a[x]+1,1e8)+1ll*les*a[x];
		}
		if(ty == 2){
			les = t1.Cnt(t1.root,0,1e8,0,b[x]);
			ans -= t1.Sum(t1.root,0,1e8,b[x]+1,1e8)+1ll*les*b[x];
			
			t2.upd(t2.root,0,1e8,b[x],-1),b[x] = y,t2.upd(t2.root,0,1e8,b[x],1);
			
			les = t1.Cnt(t1.root,0,1e8,0,b[x]);
			ans += t1.Sum(t1.root,0,1e8,b[x]+1,1e8)+1ll*les*b[x];
		}
		printf("%lld\n",ans);
	}
	return 0;
}

/*                             हरे कृष्ण हरे कृष्ण कृष्ण कृष्ण हरे हरे
                                  हरे राम हरे राम राम राम हरे हरे                                     */
#include<bits/stdc++.h>
using namespace std;
#define pb emplace_back
#define pob pop_back
typedef long long int lli;
#define test lli t; cin>>t; while(t--)
#define ff first
#define ss second
#define F(n) for(lli i=0;i<n;i++)
#define pf pop_front
#define lb lower_bound
#define ub upper_bound
#define setbits(x)  __builtin_popcountll(x)
#define zerobits(x)  __builtin_ctzll(x)
#define bs binary_search
#define all(x) x.begin(),x.end()
#define nl "\n"
#define loop(i,s,n) for(lli i=s;i<n;i++)
#define pp(a)  for(auto x : a)  cout<<x<<" ";  cout<<nl;
#define mem(arr,x) memset(arr,x,sizeof(arr))
#define mod 1000000007
#define inf 1e18
#define tt(n) cin>>n; lli a[n]; loop(i,0,n) cin>>a[i];
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ps(x,y) fixed<<setprecision(y)<<x
lli solve(lli n)
{
 lli r,i;
 while(n!=0)
 {
     r=n%10;
     if(r==7) return -1;
     n/=10;
 }
 return 0;
}
lli decToOctal(lli n)
{
    lli octalNum[100];
    lli i = 0,f=0;
    while (n != 0) {
        octalNum[i] = n % 8;
        n = n / 8;
        i++;
    }
    for (lli j = i - 1; j >= 0; j--)
        {
            if(octalNum[j]==7)
            {
                f=1;
                break;
            }
        }
        if(f) return -1;
        else return 0;
}
int main()
{
fast;
 	lli n,i,j,c,x=0;
 	cin>>n;
 	lli a[n],s=0;
 	loop(i,0,n) cin>>a[i];
 	sort(a,a+n);
 	loop(i,0,n)
 	{
 	    s+=(i*a[i])-((n-1-i)*a[i]);
 	}
 	cout<<s;
return 0;
}