#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

const int mn = 500010;
typedef pair <long long, long long> pll;
long long n, m, p, ans;
pll x[mn];
pair <long long, pll> y[mn];

int main() {
	freopen("fisher.in", "r", stdin);
	freopen("fisher.out", "w", stdout);
	cin >> n >> m >> p;
	for (int i = 0; i < n; i++) {
		long long q1, q2;
		cin >> q1 >> q2;
		x[i].first = q1;
		x[i].second = q2;
	}
	for (int i = 0; i < m; i++) {
		long long q1, q2, q3;
		cin >> q1 >> q2 >> q3;
		y[i].first = q1;
		y[i].second.first = -q3;
		y[i].second.second = q2;
	}
	if (p == 0) {
		long long sum = 0;
		for (int i = 0; i < n; i++) {
			sum += x[i].second;
		}
		for (int i = 0; i < m; i++) {
			x[i] = y[i].second;
		}
		sort(x, x + m);
		ans = 0;
		for (int i = 0; i < m; i++) {
			if (sum > x[i].second) {
				ans = ans - x[i].first * x[i].second;
				sum -= x[i].second;
			} else {
				ans = ans - x[i].first * sum;
				sum = 0;
				break;
			}
		}
		cout << ans;
	}
	return 0;
}