#include<bits/stdc++.h>

using namespace std;

int main()
{
    freopen("fisher.in", "r", stdin);
    freopen("fisher.out", "w", stdout);
    int n, m, p;
    cin >> n >> m >> p;
    int x[n];
    int a[n];
    int y[m];
    int b[m];
    int c[m];
   // vector<pair<int, int>> a(n + m);
    for (int i = 0; i < n; i++)
    {
        cin >> x[i] >> a[i];
       // a.push_back(make_pair(x[i], 0));
    }
    for (int i = 0; i < m; i++)
    {
        cin >> y[i] >> b[i] >> c[i];
    }
    if (p == 0)
    {
        int s = 0;
        for (int i = 0; i < n; i++)
        {
            s += a[i];
        }
        //cout << s;
        vector<pair<int, int>> ys;
        for (int i = 0; i < m; i++)
        {
            ys.push_back(make_pair(c[i], b[i]));
        }
        sort(ys.rbegin(), ys.rend());
        int now_s = 0;
        int ans = 0;
        for (int i = 0; i < m; i++)
        {
            if (now_s + ys[i].second >= s)
            {
                ans += (s - now_s) * ys[i].first;
                break;
            }
            else
            {
                now_s += ys[i].second;
                ans += ys[i].first * ys[i].second;
            }
        }
        cout << ans;
    }
    else
    {
        cout << 50;
    }
}
