#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <algorithm>

using namespace std;

class Node{

public:
    int cost;
    long long mass;
    long long sumProfit;
    long long sumMass;
    int prior;
    Node* left;
    Node* right;

    Node() {

        cost = 0;
        mass = 0;
        sumProfit = 0;
        sumMass = 0;
        prior = ((rand() & ((1<<16)-1)) << 16) + (rand() & ((1<<16)-1));
        left = NULL;
        right = NULL;

    }

};

void nodeUpdate(Node* node) {

    node->sumMass = node->mass;
    node->sumProfit = (node->mass)*(node->cost);
    if(node->left != NULL) {
        node->sumMass += node->left->sumMass;
        node->sumProfit += node->left->sumProfit;
    }
    if(node->right != NULL) {
        node->sumMass += node->right->sumMass;
        node->sumProfit += node->right->sumProfit;
    }

}

Node* merge(Node* left, Node* right) {

    if(left == NULL)
        return right;
    if(right == NULL)
        return left;

    if(left->prior <= right->prior) {
        left->right = merge(left->right, right);
        nodeUpdate(left);
        return left;
    }
    else {
        right->left = merge(left, right->left);
        nodeUpdate(right);
        return right;
    }

}

void splitMass(Node* root, long long massRight, Node** lres, Node** rres) {

    if(massRight <= 0) {

        *lres = root;
        *rres = NULL;
        return;

    }

    if(root == NULL) {

        *lres = NULL;
        *rres = NULL;
        return;

    }

    if(root->right == NULL || root->right->sumMass < massRight) {

        long long curMass = massRight - root->mass;
        if(root->right != NULL)
            curMass -= root->right->sumMass;

        splitMass(root->left, curMass, lres, &(root->left));
        *rres = root;

    }

    else {

        splitMass(root->right, massRight, &(root->right), rres);
        *lres = root;

    }
    nodeUpdate(root);

}

void splitCost(Node* root, int cost, Node** lres, Node** rres) {

    if(root == NULL) {

        *lres = NULL;
        *rres = NULL;
        return;

    }

    if(root->cost > cost) {

        splitCost(root->left, cost, lres, &(root->left));
        *rres = root;

    }
    else {

        splitCost(root->right, cost, &(root->right), rres);
        *lres = root;

    }
    nodeUpdate(root);

}

int findLeast(Node* root) {

    if(root == NULL)
        return -1;
    if(root->left == NULL)
        return root->cost;
    return findLeast(root->left);

}

void add(Node** root, int mass, int cost) {

    //cout << "Adding..." << endl;
    //cout << (*root == NULL) << endl;

    Node* left;
    Node* node;
    Node* right;
    splitCost(*root, cost, &left, &right);
    splitCost(left, cost-1, &left, &node);

    if(node == NULL)
        node = new Node;
    //else
    //    cout << cost << " is already" << endl;
    node->cost = cost;
    node->mass += mass;
    nodeUpdate(node);

    //cout << (left == NULL) << ' ' << (node == NULL) << ' ' << (right == NULL) << endl;

    left = merge(left, node);
    *root = merge(left, right);
    //cout << (*root == NULL) << endl;
    //cout << "End of Adding" << endl;

}

long long maxProfit(Node** root, int totalMass) {

    Node* left;
    Node* right;
    splitMass(*root, totalMass, &left, &right);
    if(right == NULL)
        return 0;
    long long ans = right->sumProfit;
    if(right->sumMass > totalMass) {

        ans -= ((long long)findLeast(right))*(right->sumMass - totalMass);

    }
    *root = merge(left, right);

    return ans;

}

int main() {

    freopen("fisher.in", "r", stdin);
    freopen("fisher.out", "w", stdout);

    int totalGet, totalGive, price;
    cin >> totalGet >> totalGive >> price;

    vector< pair<int,char> > points(totalGet + totalGive);

    int* coordsGet = new int[totalGet];
    int* limitsGet = new int[totalGet];

    for(int i=0; i<totalGet; ++i) {

        cin >> coordsGet[i] >> limitsGet[i];
        points[i].first = coordsGet[i];
        points[i].second = 0;

    }

    int* coordsGive = new int[totalGive];
    int* limitsGive = new int[totalGive];
    int* costsGive = new int[totalGive];

    for(int i=0; i<totalGive; ++i) {

        cin >> coordsGive[i] >> limitsGive[i] >> costsGive[i];
        points[totalGet+i].first = coordsGive[i];
        points[totalGet+i].second = 1;

    }

    sort(points.begin(), points.end());
    // merge

    Node* tree = NULL;

    int totalPoints = totalGet + totalGive;

    long long ans = 0;
    long long massGetPref = 0;
    long long massGivePref = 0;

    int pget = -1;
    int pgive = -1;

    for(int i=0; i<totalPoints; ++i) {

        //cout << "Okay! " << i << endl;
        //cout << "Before adding: " << (tree == NULL) << endl;

        if(points[i].second == 0)
            massGetPref += limitsGet[++pget];
        else {
            massGivePref += limitsGive[++pgive];
            add(&tree, limitsGive[pgive], costsGive[pgive]);
        }

        if(pget == -1 || pgive == -1)
            continue;

        //cout << "Debug block" << endl;
        //if(tree != NULL) {
        //    cout << maxProfit(&tree, min(massGetPref, massGivePref)) << endl;
        //    cout << (tree->sumMass) << endl;
        //    cout << (tree->sumProfit) << endl;
        //}
        //cout << "End of Debug block" << endl;

        ans = max(ans, maxProfit(&tree, min(massGetPref, massGivePref)) - ((long long)price)*points[i].first);

    }

    cout << ans << endl;

    return 0;

}
