#include <stdio.h>
#include <iostream>
#include <fstream>
#include <algorithm>
#include <ctime>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <iterator>
#include <utility>
#include <queue>
#include <deque>
#include <stack>
#include <assert.h>

using namespace std;

const int MAXN = 500000, SZ = 1001;

struct event {
	int pos, mx, cost;
};
vector<event> v;

bool cmp(const event& first, const event& second) {
	return first.pos < second.pos;
}

bool cmp1(const event& first, const event& second) {
	return first.cost > second.cost;
}

int main() {
	ios_base::sync_with_stdio(false);
	ifstream cin("fisher.in");
	ofstream cout("fisher.out");

	int n, m, p;
	cin >> n >> m >> p;
	assert(n <= MAXN && m <= MAXN);
	for (int i = 0; i < n; i++) {
		int x, a;
		cin >> x >> a;
		v.push_back({ x, a });
	}
	for (int i = 0; i < m; i++) {
		int y, b, c;
		cin >> y >> b >> c;
		v.push_back({ y, b, c });
	}
	sort(v.begin(), v.end(), cmp);
	if (p == 0) {
		long long cnt = 0, ans = 0;
		for (int i = 0; i < (int)v.size(); i++)
			if (!v[i].cost)
				cnt += v[i].mx;
		sort(v.begin(), v.end(), cmp1);
		for (int i = 0; i < (int)v.size(); i++) {
			int mn = min((long long)v[i].mx, cnt);
			ans += 1LL * mn * v[i].cost;
			v[i].mx -= mn;
			cnt -= mn;
		}
		cout << ans << endl;
	}
	else {
		long long ans = 0, cur = 0, sum = 0, fish = 0;
		multiset<pair<int, int> > Fish, Port;
		for (int i = 0; i < (int)v.size(); i++) {

		}
		cout << ans << endl;
	}
	return 0;
}