#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <vector>

using namespace std;
long long ulov, ans;
vector <vector<long long> > fish;
vector <vector<long long> > money;
int main()
{
    //freopen("robots.in", "r", stdin);
    //freopen("robots.out", "w", stdout);
    cin >> n >> m >> g;
    fish.resize(n);
    for(int i = 0; i < n; i++){
        fish[i].resize(2);
        cin >> fish[i][0] >> fish[i][1];
    }
    money.resize(m);
    for(int i = 0; i < m; i++){
        money[i].resize(3);
        cin >> money[i][2] >> money[i][1] >> money[i][0];
    }
    if (g == 0){
        for(int i = 0; i < n; i++){
            ulov += fish[i][1];
        }
        sort(money.begin(), money.end());
        j = m - 1;
        ans = 0;
        while (ulov > 0){
            ans += min(ulov, money[i][1]) * money[i][0];
            ulov -= min(ulov, money[i][1]);
        }
        cout << ans;
    }
    return 0;
}
