Uses
  Math;
Type
  mass=array[1..500000]of int64;
Var
  n,m,p,i,j:longint;suma,ans:int64;
  x,a,y,b,c:mass;
Procedure Swap(Var a,b:int64);
Var
  c:int64;
Begin
  c:=a;
  a:=b;
  b:=c;
end;
Procedure qSort(Var m1,m2:mass;l,r:int64);
Procedure sort(l,r:int64);
Var
  i,j,sr,x1,x2:int64;
Begin
  i:=l;j:=r;
  sr:=i+random(j-i+1);
  x1:=m1[sr];
  x2:=m2[sr];
  repeat
    while (m1[i]<x1)or((m1[i]=x1)and(m2[i]<x2))do inc(i);
    while (x1<m1[j])or((x1=m1[j])and(x2<m2[j]))do dec(j);
    if i<=j then
      begin
        Swap(m1[i],m1[j]);
        Swap(m2[i],m2[j]);
        inc(i);dec(j);
      end;
  until i>j;
  if i<r then
    sort(i,r);
  if l<j then
    sort(l,j);
end;
Begin
  sort(l,r);
end;
begin
//  assign(input,'input.txt');assign(output,'output.txt');
  assign(input,'fisher.in');assign(output,'fisher.out');
  readln(n,m,p);
  for i:=1 to n do
    readln(x[i],a[i]);
  for i:=1 to m do
    readln(y[i],b[i],c[i]);
  if p=0 then
    begin
      suma:=0;
      for i:=1 to n do
        inc(suma,a[i]);
      qSort(c,b,1,m);
      ans:=0;
      for i:=m downto 1 do
        begin
          ans:=ans+min(suma,b[i])*c[i];
          dec(suma,min(suma,b[i]));
        end;
      writeln(ans);
    end;
end.
