#include <iostream>
#include <vector>
#include <deque>
#include <algorithm>
#include <iomanip>
#include <set>
#include <map>
#include <cmath>

using namespace std;

#define print(i) cout << i << '\n'
#define pb push_back
#define INF 100000000

typedef long long llong;

long double EPS = 1e-6;

const int MAXN = (int)1e6 + 1;

deque<int> screen;
set<int> is;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n, k;
	cin >> n >> k;
	for (int i = 0; i < n; i++) {
		int msg;
		cin >> msg;
		if (is.count(msg) == 0) {
			if (screen.size() < k) {
				screen.push_front(msg);
			}
			else {
				is.erase(screen.back());
				screen.pop_back();
				screen.push_front(msg);
			}
			is.insert(msg);
		}
	}
	print(screen.size());
	for (auto it = screen.begin(); it != screen.end(); it++) {
		cout << *it << ' ';
	}
	return(0);
}


#include <iostream>
#include <vector>
#include <deque>
#include <algorithm>
#include <iomanip>
#include <set>
#include <map>
#include <cmath>

using namespace std;

#define print(i) cout << i << '\n'
#define pb push_back
#define INF 100000000

typedef long long llong;

long double EPS = 1e-6;

const int MAXN = (int)1e6 + 1;

deque<int> screen;
set<int> is;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n, k;
	cin >> n >> k;
	for (int i = 0; i < n; i++) {
		int msg;
		cin >> msg;
		if (is.count(msg) == 0) {
			if (i < k) {
				screen.push_front(msg);
			}
			else {
				is.erase(screen.back());
				screen.pop_back();
				screen.push_front(msg);
			}
			is.insert(msg);
		}
	}
	print(screen.size());
	for (auto it = screen.begin();  it != screen.end(); it++) {
		cout << *it << ' ';
	}
	return(0);
}


#include <iostream>
#include <fstream>
#include <cmath>
#include <map>
#include <vector>
#include <deque>
using namespace std;
class Hash
{
private:
	int next = 1;
	map<long,int> mp;
public:
	int add(long const &th)
	{
		mp.insert(make_pair(th, next));
		next++;
		return next-1;
	}
	int getNext() { return ++next; }
	int get(long const & th)
	{
		auto i=mp.find(th);
		if (i != mp.end())
			return i->second;
		else return 0;
	}
};
bool inVec(vector<bool>& vec, long const& th,Hash * hash)
{
	int h = hash->get(th);
	if (h == 0) h = hash->add(th);
	if (h < vec.size())
	{
		if (vec[h] == false) {
			vec[h] = true;
			return false;
		}
		return true;

	}
	else
	{
		vec.resize(hash->getNext());
		vec[h] = true;
		return false;
	}
}
int main() {
#ifdef _DEBUG
	fstream cin("debug.txt");
#endif
	long n;
	cin >> n;
	long a = 0;
	cin >> a;
	vector<bool> vec(1,false);
	Hash* hash=new Hash;
	deque<long> deq;
	for(size_t i=0;i<n;i++)
	{
		long th = 0;
		cin >> th;
		if(!inVec(vec,th,hash))
		{
			deq.push_front(th);
		}
		if (deq.size() > a) vec[hash->get(deq.back())]=false,deq.pop_back();
	}
	cout << deq.size() << endl;
	for(auto const & i:deq)
	{
		cout << i << " ";
	}
	return 0;
}


#include <iostream>
#include <fstream>
#include <cmath>
#include <vector>
#include <deque>
using namespace std;
bool inVec(vector<bool>& vec, long const& th)
{
	if (th < vec.size())
	{
		if (vec[th] == false) {
			vec[th] = true;
			return false;
		}
		return true;

	}
	else
	{
		vec.resize(th + 1);
		vec[th] = true;
		return false;
	}
}
int main() {
#ifdef _DEBUG
	fstream cin("debug.txt");
#endif
	long n;
	cin >> n;
	long a = 0;
	cin >> a;
	vector<bool> vec;
	deque<long> deq;
	for(size_t i=0;i<n;i++)
	{
		long th = 0;
		cin >> th;
		if(!inVec(vec,th))
		{
			deq.push_front(th);
		}
		if (deq.size() > a) vec[deq.back()]=false,deq.pop_back();
	}
	cout << deq.size() << endl;
	for(auto const & i:deq)
	{
		cout << i << " ";
	}
	return 0;
}


# include <cstdio>
# include <iostream>
# include <algorithm>
# include <cmath>
# include <string>
# include <cstring>
# include <iomanip>
# include <functional>
# include <numeric>
# include <map>
# include <cstdlib>
# include <queue>
using namespace std;
template <class code>inline code read(const code &a)
{
    code x=0;short w=0;char ch=0;
    while(!isdigit(ch)) {w|=ch=='-';ch=getchar();}
    while(isdigit(ch)) {x=(x<<3)+(x<<1)+(ch^48);ch=getchar();}
    return w?-x:x;
}
typedef long long ll;
map <ll,ll> s;
const int N=2e5+5;
int ans[N];
int main ()
{
	int n=read (n);
	int k=read (k);
	int l,r;
	l=1;r=0;
	for (int i=1;i<=n;i++)
	{
		int x=read (x);
		if (r<k)
		{
			if (s[x]==0)
			{
				r++;
				s[x]++;
				ans[r]=x;
			}
		}
		else
		{
			if (s[x]==0)
			{
				r++;
				l++;
				s[ans[l-1]]=0;
				s[x]=1;
				ans[r]=x;
			}
		}
	}
	printf("%d\n",r-l+1);
	for(int i=r;i>=l;i--)
		printf("%d ",ans[i]);
	return 0;
}


# include <cstdio>
# include <iostream>
# include <algorithm>
# include <cmath>
# include <string>
# include <cstring>
# include <iomanip>
# include <functional>
# include <numeric>
# include <map>
# include <cstdlib>
# include <queue>
using namespace std;
template <class code>inline code read(const code &a)
{
    code x=0;short w=0;char ch=0;
    while(!isdigit(ch)) {w|=ch=='-';ch=getchar();}
    while(isdigit(ch)) {x=(x<<3)+(x<<1)+(ch^48);ch=getchar();}
    return w?-x:x;
}
queue <int> s;
inline void out ()
{
	if (s.empty())
	    return;
	else
	{
		int q=s.front();
		s.pop ();
		out ();
		printf ("%d ",q);
	}
}
queue <int> f;
int k;
inline void work (int x)
{
	while (s.front()!=x&&!s.empty())
	{
		f.push(s.front());
		s.pop();
	}
	bool ok=s.empty();
	while (!s.empty())
	{
		f.push (s.front());
		s.pop();
	}
	while (!f.empty())
	{
		s.push(f.front());
		f.pop();
	}
	if (ok)
	{
		if (s.size()==k)
		    s.pop();
		s.push(x);
    }
}
int main ()
{
	int n=read (n);
	k=read (k);
	for (int i=1;i<=n;i++)
	{
		int x=read (x);
		work (x);
	}
	printf ("%d\n",s.size());
	out ();
	return 0;
}


# include <cstdio>
# include <iostream>
# include <algorithm>
# include <cmath>
# include <string>
# include <cstring>
# include <iomanip>
# include <functional>
# include <numeric>
# include <map>
# include <cstdlib>
# include <queue>
using namespace std;
template <class code>inline code read(const code &a)
{
    code x=0;short w=0;char ch=0;
    while(!isdigit(ch)) {w|=ch=='-';ch=getchar();}
    while(isdigit(ch)) {x=(x<<3)+(x<<1)+(ch^48);ch=getchar();}
    return w?-x:x;
}
const int N=4e5+5;
int ans[N];
int q[N];
int l,r;
inline bool f (int p)
{
	partial_sort_copy (ans+l,ans+r+1,q+l,q+r+1);
	int how=*lower_bound (q+l,q+r+1,p);
	if (how==p)
	    return 0;
	return 1;
}
int main ()
{
	int n=read (n);
	int k=read (k);
	l=r=1;
	ans[1]=read (ans[1]);
	bool ok=1;
	for (int i=2;i<=n;i++)
	{
		int x=read (x);
		if (f (x))
		{
			if (r-l+1==k)
				l++;
			ans[++r]=x;
		}
	}
	printf ("%d\n",r-l+1);
	for (int i=r;i>=l;i--)
	    printf ("%d ",ans[i]);
	return 0;
}


# include <cstdio>
# include <iostream>
# include <algorithm>
# include <cmath>
# include <string>
# include <cstring>
# include <iomanip>
# include <functional>
# include <numeric>
# include <map>
# include <cstdlib>
# include <queue>
using namespace std;
template <class code>inline code read(const code &a)
{
    code x=0;short w=0;char ch=0;
    while(!isdigit(ch)) {w|=ch=='-';ch=getchar();}
    while(isdigit(ch)) {x=(x<<3)+(x<<1)+(ch^48);ch=getchar();}
    return w?-x:x;
}
typedef long long ll;
map <ll,ll> s;
const int N=2e5+5;
int ans[N];
int main ()
{
	int n=read (n);
	int k=read (k);
	int l,r;
	l=1;r=0;
	for (int i=1;i<=n;i++)
	{
		int x=read (x);
		if (r<k)
		{
			if (s[x]==0)
			{
				r++;
				s[x]++;
				ans[r]=x;
			}
		}
		else
		{
			if (s[x]==0)
			{
				r++;
				l++;
				s[ans[l-1]]=0;
				s[x]=1;
				ans[r]=x;
			}
		}
	}
	printf("%lld\n",r-l+1);
	for(int i=r;i>=l;i--)
		printf("%d ",ans[i]);
	return 0;
}


# include <cstdio>
# include <iostream>
# include <algorithm>
# include <cmath>
# include <string>
# include <cstring>
# include <iomanip>
# include <functional>
# include <numeric>
# include <map>
# include <cstdlib>
# include <queue>
using namespace std;
template <class code>inline code read(const code &a)
{
    code x=0;short w=0;char ch=0;
    while(!isdigit(ch)) {w|=ch=='-';ch=getchar();}
    while(isdigit(ch)) {x=(x<<3)+(x<<1)+(ch^48);ch=getchar();}
    return w?-x:x;
}
const int N=4e5+5;
int ans[N];
int q[N];
int l,r;
int main ()
{
	int n=read (n);
	int k=read (k);
	l=r=1;
	ans[1]=read (ans[1]);
	q[1]=ans[1];
	for (int i=2;i<=n;i++)
	{
		int x=read (x);
	    int how=*lower_bound (q+l,q+r+1,x);
		if (how!=x)
		{
			if (r-l+1==k)
				l++;
			ans[++r]=x;
	        partial_sort_copy (ans+l,ans+r+1,q+l,q+r+1);
		}
	}
	printf ("%d\n",r-l+1);
	for (int i=r;i>=l;i--)
	    printf ("%d ",ans[i]);
	return 0;
}


#include <iostream>
#include <fstream>
#include <string>
#include <cstring>
#include <iomanip>
#include <math.h>
#include <cctype>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;

bool contain(queue<int> list, int x) {
	while (!list.empty()) {
		if (list.front() == x) return true;
		list.pop();
	}
	return false;
}

void print_rev(queue<int> list) {
	if (list.empty()) return;
	int x = list.front();
	list.pop();
	print_rev(list);
	cout << x << " ";
}

int main() {
	int n, k;
	cin >> n >> k;
	queue<int> list;
	for (int i = 0; i < n; i++) {
		int x; cin >> x;
		if (list.empty()) {
			list.push(x);
			continue;
		}
		if (!contain(list, x)) {
			list.push(x);
			if (list.size() > k) list.pop();
		}
	}
	cout << min(k, (int)list.size()) << endl;
	print_rev(list);
	return 0;
}


#include <iostream>
#include <fstream>
#include <string>
#include <cstring>
#include <iomanip>
#include <math.h>
#include <cctype>
#include <vector>
#include <queue>
#include <set>
#include <algorithm>
using namespace std;

bool contain(queue<int> list, int x) {
	while (!list.empty()) {
		if (list.front() == x) return true;
		list.pop();
	}
	return false;
}

void print_rev(queue<int> list) {
	if (list.empty()) return;
	int x = list.front();
	list.pop();
	print_rev(list);
	cout << x << " ";
}

int main() {
	int n, k;
	cin >> n >> k;
	queue<int> list;
	set<int> isExisted;
	for (int i = 0; i < n; i++) {
		int x; cin >> x;
		if (list.empty()) {
			list.push(x);
			isExisted.insert(x);
			continue;
		}
		if (!isExisted.count(x)) {
			list.push(x);
			isExisted.insert(x);
			if (list.size() > k) {
				isExisted.erase(list.front());
				list.pop();
			}
		}
	}
	cout << min(k, (int)list.size()) << endl;
	print_rev(list);
	return 0;
}


#include <iostream>
#include <fstream>
#include <string>
#include <cstring>
#include <iomanip>
#include <math.h>
#include <cctype>
#include <vector>
#include <queue>
#include <set>
#include <algorithm>
#include <stack>
using namespace std;

bool contain(queue<int> list, int x) {
	while (!list.empty()) {
		if (list.front() == x) return true;
		list.pop();
	}
	return false;
}

int main() {
	int n, k;
	cin >> n >> k;
	queue<int> list;
	set<int> isExisted;
	for (int i = 0; i < n; i++) {
		int x; cin >> x;
		if (list.empty()) {
			list.push(x);
			isExisted.insert(x);
			continue;
		}
		if (!isExisted.count(x)) {
			list.push(x);
			isExisted.insert(x);
			if (list.size() > k) {
				isExisted.erase(list.front());
				list.pop();
			}
		}
	}
	cout << min(k, (int)list.size()) << endl;
	stack<int> print;
	while (!list.empty()) {
		print.push(list.front());
		list.pop();
	}
	while (!print.empty()) {
		cout << print.top() << " ";
		print.pop();
	}
	return 0;
}


#include<iostream>
#include<fstream>
#include<stdio.h>
#include<string>
#include<vector>
#include<math.h>
#include<algorithm>
#include<queue>

using namespace std;

int main() {
	int n, k;
	cin >> n >>  k;
	vector<int> list;
	bool* on = new bool[n + 1];
	for (int i = 0; i < n + 1; i++) on[i] = false;
	int x;
	for (int i = 0; i < n; i++) {
		cin >> x;
		if (on[x] == false) {
			on[x] = true;
			list.insert(list.begin(), x);
			if (list.size() > k) {
				on[list.back()] = false;
				list.erase(list.end() - 1);
			}
		}
	}
	cout << list.size() << endl;
	for (int i = 0; i < list.size(); i++) cout << list[i] << " ";
	cout << endl;
	return 0;
}


#include <iostream>
#include <vector>
#include <deque>
#include <set>

using namespace std;

int main(){

	int n, k;cin >> n >> k;
	deque<int> q;
	set<int> s;
	for(int i = 0;i < n;i++){
		int id;cin >> id;
		if(s.count(id)){
			continue;
		}
		else{

			if(q.size()==k){
				s.erase(q.front());
				q.pop_front();
				q.push_back(id);
				s.insert(id);
				continue;
			}else{
				q.push_back(id);
				s.insert(id);
			}
		}

	}
	cout << q.size() << "\n";
	while(!q.empty()){
		cout << q.back() << " ";
		q.pop_back();
	}

	return 0;
}


//DPcoded

#include <iostream>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>

using namespace std;

#define In cin
#define Out cout

#define watch(x) Out << (#x) << " = " << x << endl
#define max3(a, b, c) max(a, max(b, c))
#define min3(a, b, c) min(a, min(b, c))

typedef long long ll;
typedef vector <int> vi;
typedef vector <vi> vvi;
typedef set <int> si;
typedef map <int, int> mii;
typedef pair <int, int> ii;

int main() {
	ifstream in("input.txt");
	ofstream out("output.txt");

	int n, k;
	In >> n >> k;

	si s;
	vi d;
	mii m;

	int b = 1;
	int e = 0;

	for (int i = 0; i < n; i++) {
		int t;
		In >> t;

		if (s.find(t) == s.end()) {
			m[--b] = t;
			s.insert(t);
			if (e - b + 1 > k) {
				s.erase(s.find(m[e]));
				e--;
			}
		}
	}

	Out << e - b + 1 << endl;

	for (int i = b; i <= e; i++) {
		Out << m[i] << ' ';
	}

	return 0;
}


//DPcoded

#include <iostream>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>

using namespace std;

#define In cin
#define Out cout

#define watch(x) Out << (#x) << " = " << x << endl
#define max3(a, b, c) max(a, max(b, c))
#define min3(a, b, c) min(a, min(b, c))

typedef long long ll;
typedef vector <int> vi;
typedef vector <vi> vvi;
typedef set <int> si;
typedef map <int, int> mii;
typedef pair <int, int> ii;

int main() {
	ifstream in("input.txt");
	ofstream out("output.txt");

	int n, k;
	In >> n >> k;

	si s;
	vi d;

	for (int i = 0; i < n; i++) {
		int t;
		In >> t;

		if (s.find(t) == s.end()) {
			d.insert(d.begin(), t);
			s.insert(t);
			if (d.size() > k) {
				s.erase(s.find(d[d.size() - 1]));
				d.pop_back();
			}
		}
	}

	Out << d.size() << endl;
	for (int i : d) Out << i << ' ';

	return 0;
}


#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
#include <math.h>
#include <set>
#include <stack>
#include <deque>
using namespace std;
bool search(deque<long long>d,long long n)
{
	sort(d.begin(),d.end());
	int start = 0,end=d.size()-1,mid;
	while (start <= end)
	{
		mid = (start + end) / 2;
		if (n == d[mid]) return true;
		else if (n > d[mid])start = mid + 1;
		else end = mid - 1;
	}
}
void main()
{
	deque<long long>d;
	map<long long, long long>ma;
	map<long long, long long>::iterator it;
	int n, m,l,b;
	cin >> n >> m;
	b = m;
	for (int i = 0; i < n; i++)
	{
		cin >> l;
		if (i == 0)
		{
			ma[l] = 0;
			d.push_front(l);
		}
		else
		{
			if (ma.find(l) == ma.end())
			{
				ma[l] = 0;
				if (d.size()<m)
				d.push_front(l);
				else
				{
					int z = d.back();
					d.pop_back();
					ma.erase(z);
					d.push_front(l);
				}
			}

		}

	}
	cout << d.size() << endl;
	for (int i = 0; i < d.size(); i++)cout << d[i] << " ";
	cout << endl;
}


#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
#include <math.h>
#include <set>
#include <stack>
#include <deque>
using namespace std;
void main()
{
	long long x, y,n;
	bool k = false;
	cin >> x >> y;
	deque<long long>d;
	for (int j = 0; j < x;j++)
	{
		cin >> n;
		if (j == 0)d.push_front(n);
		else
		{

			for (int i = 0; i < d.size(); i++)
			{
				if (n == d[i])
				{
					k = true;
					break;
				}
				else k = false;
			}
			if (!k)
			{
				int z = d.size();
					z++;
				if (z<=y)
				d.push_front(n);
				else
				{
					d.pop_back();
					d.push_front(n);
				}

			}
		}
		k = false;
	}
	cout << d.size() << endl;
	for (int i = 0; i < d.size(); i++)
	{
		cout << d[i] << " ";
	}
	cout << endl;
}


#include<iostream>
#include<queue>
#include<set>
using namespace std;
queue<int> que;
bool flag[1000000000];
int f[2000];
int main(){
	int n,k,a,m1=0;
	cin>>n>>k;
	for(int i=0;i<n;i++){
		cin>>a;
		if(!flag[a]){
		if(que.size()==k){
			int x=que.front();
			que.pop();
			flag[x]=false;
			flag[a]=true;
			que.push(a);
			continue;
		}
		else{
		flag[a]=true;
		que.push(a);

	}
	}
	}
	cout<<que.size()<<endl;
	while(que.size()>0){
		f[m1++]=que.front();
		que.pop();
	}
	cout<<f[m1-1];
	for(int i=m1-2;i>=0;i--){
		cout<<" "<<f[i];
	}
	return 0;
}


#include<iostream>
#include<queue>
#include<map>
using namespace std;
queue<int> que;
map<int,bool> m2;
int f[2000];
int main(){
	int n,k,a,m1=0;
	cin>>n>>k;
	for(int i=0;i<n;i++){
		cin>>a;
		if(!m2[a]){
		if(que.size()==k){
			int x=que.front();
			que.pop();
			m2[x]=false;
			m2[a]=true;
			que.push(a);
			continue;
		}
		else{
		m2[a]=true;
		que.push(a);

	}
	}
	}
	cout<<que.size()<<endl;
	while(que.size()>0){
		f[m1++]=que.front();
		que.pop();
	}
	cout<<f[m1-1];
	for(int i=m1-2;i>=0;i--){
		cout<<" "<<f[i];
	}
	return 0;
}


#include<iostream>
#include<queue>
#include<map>
using namespace std;
queue<int> que;
map<int,bool> m2;
int f[200001];
int main(){
	int n,k,a,m1=0;
	cin>>n>>k;
	for(int i=0;i<n;i++){
		cin>>a;
		if(!m2[a]){
		if(que.size()==k){
			int x=que.front();
			que.pop();
			m2[x]=false;
			m2[a]=true;
			que.push(a);
			continue;
		}
		else{
		m2[a]=true;
		que.push(a);

	}
	}
	}
	cout<<que.size()<<endl;
	while(que.size()>0){
		f[m1++]=que.front();
		que.pop();
	}
	cout<<f[m1-1];
	for(int i=m1-2;i>=0;i--){
		cout<<" "<<f[i];
	}
	return 0;
}


#include<iostream>
#include<cmath>
using namespace std;
int found(int id, int A[], int k,int a){
    int res=0;
    for(int i=k-1; i>=a && res==0;i--){
        if(id==A[i]) res=1;
    }
    return res;
}
int main(){
    int n,k,m,count=0;
    cin>>n>>k;
    int* A=new int[n];

    while(n--){
        cin>>m;
        if(!found(m,A,count,count>=k?count-k:0)){
            A[count++]=m;
        }

    }
    if(count<k){
        cout<<count<<"\n";
        for(int i=count-1; i>=0;i--) cout<<A[i]<<" ";
    }
    else {
        cout<<k<<"\n";
        for(int i=count-1; i>=count-k;i--) cout<<A[i]<<" ";
    }
}


#include<iostream>
#include<cmath>
using namespace std;
int found(int id, int A[], int k,int a){
    int res=0;
    for(int i=k-1; i>=a && res==0;i--){
        if(id==A[i]) res=1;
    }
    return res;
}
int main(){
    int n,k,m,count=0;
    cin>>n>>k;
    int* A=new int[n];
    int* M =new int[2*n+1]();
    while(n--){
        cin>>m;
        M[2*(m-1)]++;
        if(M[2*(m-1)]==1 || (M[2*(m-1)]>1 && (count-M[2*m-1])>k)){
            A[count++]=m;
            M[2*m-1] = count-1;
        }
    }
    if(count<k){
        cout<<count<<"\n";
        for(int i=count-1; i>=0;i--) cout<<A[i]<<" ";
    }
    else {
        cout<<k<<"\n";
        for(int i=count-1; i>=count-k;i--) cout<<A[i]<<" ";
    }
}


#include<iostream>
#include<list>
#include<map>
using namespace std;
int main(){
    int n,k;
    list<int> res;
    map<int,int> mp;
    cin>>n>>k;
    int a;
    while(n--){
        cin>>a;
        if(mp[a]==0){
            res.push_front(a);
            mp[a]=1;
        }
        if(res.size()>k){
            mp[res.back()]=0;
            res.pop_back();
        }
    }
    cout<<res.size()<<"\n";
    for(auto i:res){
        cout<<i<<" ";
    }
}


#include<iostream>
#include<cmath>
using namespace std;
int found(int id, int A[], int k){
    int res=0;
    for(int i=0; i<k && res==0;i++){
        if(id==A[i]) res=1;
    }
    return res;
}
void shift(int A[], int *count){
    for(int i=*count; i>0;i--){
        A[i]=A[i-1];
    }
}
int main(){
    int n,k,m,count=0;
    cin>>n>>k;
    int* A=new int[k];

    while(n--){
        cin>>m;
        if(!found(m,A,count)){

            if(count>=k) count=k-1;
            shift(A, &count);
            A[0]=m;
            if(count<k)
            count++;
        }

    }
    if(count<k){
        cout<<count<<"\n";
        for(int i=0; i<count;i++) cout<<A[i]<<" ";
    }
    else {
        cout<<k<<"\n";
        for(int i=0; i<k;i++) cout<<A[i]<<" ";
    }
}


#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <iostream>
#include <string>
#include <string.h>
#include <map>
#include <set>
#include <vector>
#include <iterator>
#include <algorithm>
#include <math.h>
#include <deque>
#include <stack>
using namespace std;

int main() {
	int n, k, nowK = 0, a;
	set<int>s;
	deque<int>q;
	cin >> n >> k;
	for (int i = 0; i < n; i++) {
		cin >> a;
		if (s.find(a) != s.end())
			continue;
		if (nowK < k) {
			nowK++;
			q.push_back(a);
			s.insert(a);
		}
		else {
			s.erase(q.front());
			q.pop_front();
			s.insert(a);
			q.push_back(a);
		}
	}
	cout << nowK << endl;
	while (!q.empty()) {
		cout << q.back() << " ";
		q.pop_back();
	}
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <map>

using namespace std;

int main() {
	map<int, int> m1, m2;
	int n, k, i, num=0, tmp;
	map<int, int>::iterator it;
	cin >> n >> k;
	for (i = 0; i < n; i++) {
		cin >> tmp;
		if (m1.find(tmp) == m1.end()) {
			m1[tmp] = i;
			m2[i] = tmp;
			num++;
			if (num > k) {
				m1.erase(m2.begin()->second);
				m2.erase(m2.begin());
			}
		}
		//for (it = m1.begin(); it != m1.end(); it++) cout << it->first << " ";
		//cout << endl;
	}
	cout << m1.size() << endl;

	for (it = m2.end(); it != m2.begin(); it--) cout << it->second << " ";

	return 0;
}


#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;
//#define int long long
//#define NN 1000000007

bool used[200001] = { 0 };

int main() {
	int n, k, tmp, sz = 0;
	vector<int> qq;
	cin >> n >> k;
	for (int i = 0; i < n; i++) {
		scanf("%d", &tmp);
		if (used[tmp] == 0) {
			used[tmp] = 1;
			qq.push_back(tmp);
			sz++;
		}
		if (sz > k) {
			used[qq[0]] = 0;
			qq.erase(qq.begin());
			sz = k;
		}
		//for (int j = 0; j < qq.size(); j++) cout << qq[j] << " ";
		//cout << endl;
	}

	cout << sz << endl;
	for (int i = sz - 1; i > -1; i--) cout << qq[i] << " ";

	return 0;
}


#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;
//#define int long long
//#define NN 1000000007

bool search(vector<int> vv, int i, int sz) {
	for (int j = 0; j < sz; j++) if (vv[j] == i) return 1;
	return 0;
}

int main() {
	int n, k, tmp, sz = 0;
	vector<int> qq;
	cin >> n >> k;
	for (int i = 0; i < n; i++) {
		scanf("%d", &tmp);
		if (search(qq, tmp, sz) == 0) {
			qq.push_back(tmp);
			sz++;
		}
		if (sz > k) {
			qq.erase(qq.begin());
			sz = k;
		}
		//for (int j = 0; j < qq.size(); j++) cout << qq[j] << " ";
		//cout << endl;
	}

	cout <<endl<< sz << endl;
	for (int i = sz - 1; i > -1; i--) cout << qq[i] << " ";

	return 0;
}


#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;
#define int long long
//#define NN 1000000007

bool used[1000000000] = { 0 };

__int32 main() {
	int n, k, tmp, sz = 0, i;
	vector<int> qq;
	cin >> n >> k;
	for (i = 0; i < n; i++) {
		cin >> tmp;
		if (used[tmp] == 0) {
			used[tmp] = 1;
			qq.push_back(tmp);
			sz++;
		}
		if (sz > k) {
			used[qq[0]] = 0;
			qq.erase(qq.begin());
			sz = k;
		}
		//for (int j = 0; j < qq.size(); j++) cout << qq[j] << " ";
		//cout << endl;
	}

	cout << sz << endl;
	for (int i = sz - 1; i > -1; i--) cout << qq[i] << " ";

	return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <map>

using namespace std;

int main() {
	map<int, int> m1, m2;
	int n, k, i, num=0, tmp;
	cin >> n >> k;
	for (i = 0; i < n; i++) {
		scanf("%d",&tmp);
		if (m1.find(tmp) == m1.end()) {
			m1[tmp] = i;
			m2[i] = tmp;
			num++;
			if (num > k) {
				m1.erase(m2.begin()->second);
				m2.erase(m2.begin());
			}
		}
		//for (it = m1.begin(); it != m1.end(); it++) cout << it->first << " ";
		//cout << endl;
	}
	cout << m1.size() << endl;

	for (auto it = m2.rbegin(); it != m2.rend(); it++) cout << it->second << " ";

	return 0;
}


#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;
//#define int long long
//#define NN 1000000007

bool used[200001] = { 0 };

int main() {
	int n, k, tmp, sz = 0;
	vector<int> qq;
	cin >> n >> k;
	for (int i = 0; i < n; i++) {
		scanf("%d", &tmp);
		if (used[tmp] == 0) {
			used[tmp] = 1;
			qq.push_back(tmp);
		}
		if (sz > k) {
			used[qq[0]] = 0;
			qq.erase(qq.begin());
			sz = k;
		}
		//for (int j = 0; j < qq.size(); j++) cout << qq[j] << " ";
		//cout << endl;
	}

	cout <<endl<< sz << endl;
	for (int i = sz - 1; i > -1; i--) cout << qq[i] << " ";

	return 0;
}


#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;
#define int long long
//#define NN 1000000007

bool used[200001] = { 0 };

__int32 main() {
	int n, k, tmp, sz = 0, i;
	vector<int> qq;
	cin >> n >> k;
	for (i = 0; i < n; i++) {
		cin >> tmp;
		if (used[tmp] == 0) {
			used[tmp] = 1;
			qq.push_back(tmp);
			sz++;
		}
		if (sz > k) {
			used[qq[0]] = 0;
			qq.erase(qq.begin());
			sz = k;
		}
		//for (int j = 0; j < qq.size(); j++) cout << qq[j] << " ";
		//cout << endl;
	}

	cout << sz << endl;
	for (int i = sz - 1; i > -1; i--) cout << qq[i] << " ";

	return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <map>

using namespace std;

int main() {
	map<int, int> m1, m2;
	int n, k, i, num=0, tmp;
	cin >> n >> k;
	for (i = 0; i < n; i++) {
		cin >> tmp;
		if (m1.find(tmp) == m1.end()) {
			m1[tmp] = i;
			m2[i] = tmp;
			num++;
			if (num > k) {
				m1.erase(m2.begin()->second);
				m2.erase(m2.begin());
			}
		}
		//for (it = m1.begin(); it != m1.end(); it++) cout << it->first << " ";
		//cout << endl;
	}
	cout << m1.size() << endl;

	for (auto it = m2.rbegin(); it != m2.rend(); it++) cout << it->second << " ";

	return 0;
}


#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;
#define int long long
//#define NN 1000000007

bool used[200001] = { 0 };

int main() {
	int n, k, tmp, sz = 0;
	vector<int> qq;
	cin >> n >> k;
	for (int i = 0; i < n; i++) {
		scanf("%d", &tmp);
		if (used[tmp] == 0) {
			used[tmp] = 1;
			qq.push_back(tmp);
			sz++;
		}
		if (sz > k) {
			used[qq[0]] = 0;
			qq.erase(qq.begin());
			sz = k;
		}
		//for (int j = 0; j < qq.size(); j++) cout << qq[j] << " ";
		//cout << endl;
	}

	cout << sz << endl;
	for (int i = sz - 1; i > -1; i--) cout << qq[i] << " ";

	return 0;
}


#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;
//#define int long long
//#define NN 1000000007

bool search(vector<int> vv, int i, int sz) {
	for (int j = 0; j < sz; j++) if (vv[j] == i) return 1;
	return 0;
}

int main() {
	int n, k, tmp, sz=0;
	vector<int> qq;
	cin >> n >> k;
	for (int i = 0; i < n; i++) {
		scanf("%d", &tmp);
		if (search(qq, tmp, sz) == 0) {
			qq.push_back(tmp);
			sz++;
		}
		if (sz >= k) {
			qq.erase(qq.begin());
			sz = k;
		}
	}
	cout << sz << endl;
	for (int i = sz-1; i > -1 ; i--) cout << qq[i] << " ";

	return 0;
}


#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;
//#define int long long
//#define NN 1000000007

bool search(vector<int> vv, int i, int sz) {
	for (int j = 0; j < sz; j++) if (vv[j] == i) return 1;
	return 0;
}

int main() {
	int n, k, tmp, sz = 0;
	vector<int> qq;
	cin >> n >> k;
	for (int i = 0; i < n; i++) {
		scanf("%d", &tmp);
		if (search(qq, tmp, sz) == 0) {
			qq.push_back(tmp);
			sz++;
		}
		if (sz > k) {
			qq.erase(qq.begin());
			sz = k;
		}
		//for (int j = 0; j < qq.size(); j++) cout << qq[j] << " ";
		//cout << endl;
	}

	//cout <<endl<< sz << endl;
	//for (int i = sz - 1; i > -1; i--) cout << qq[i] << " ";

	return 0;
}


#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;
#define int long long
//#define NN 1000000007

bool used[200001] = { 0 };

__int32 main() {
	int n, k, tmp, sz = 0;
	vector<int> qq;
	cin >> n >> k;
	for (int i = 0; i < n; i++) {
		scanf("%d", &tmp);
		if (used[tmp] == 0) {
			used[tmp] = 1;
			qq.push_back(tmp);
			sz++;
		}
		if (sz > k) {
			used[qq[0]] = 0;
			qq.erase(qq.begin());
			sz = k;
		}
		//for (int j = 0; j < qq.size(); j++) cout << qq[j] << " ";
		//cout << endl;
	}

	cout << sz << endl;
	for (int i = sz - 1; i > -1; i--) cout << qq[i] << " ";

	return 0;
}


#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;
//#define int long long
//#define NN 1000000007

bool used[200001] = { 0 };

int main() {
	int n, k, tmp, sz = 0;
	vector<int> qq;
	cin >> n >> k;
	for (int i = 0; i < n; i++) {
		scanf("%d", &tmp);
		if (used[tmp] == 0) {
			used[tmp] = 1;
			qq.push_back(tmp);
			sz++;
		}
		if (sz > k) {
			used[qq[0]] = 0;
			qq.erase(qq.begin());
			sz = k;
		}
		//for (int j = 0; j < qq.size(); j++) cout << qq[j] << " ";
		//cout << endl;
	}

	cout <<endl<< sz << endl;
	for (int i = sz - 1; i > -1; i--) cout << qq[i] << " ";

	return 0;
}


#include <iostream>
#include <string>
#include<deque>
#include<vector>
#include<algorithm>
#include<set>
#include<queue>
#include<stack>
#include<tuple>
#define maxn 20001
#define LL long long
#define inf 100000000

using namespace std;

int dx[5] = { 0,0,0,-1,1 };
int dy[5] = { 0,-1,1,0,0 };

LL arr[maxn];
LL ans;
int n, m, k, x,q;
bool flg = true;

bool desc(int a, int b) { return a > b; }

int gcd(int a, int b) {
	int n;
	if (a < b) swap(a, b);
	while (!b == 0) {
		int r = a % b;
		a = b;
		b = r;
	}
	return a;
}

int main() {

	std::ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	/*int t;
	cin >> t;
	for (int test_case = 0; test_case < t; ++test_case) {
	}*/
	LL input;
	set<LL>s;
	deque<LL>q;
	cin >> n >> k;
	LL sum = 0;
	for (int i = 0; i < n; ++i) {
		cin >> input;

		if (s.find(input) == s.end()) {
			if (q.size() >= k) {
				LL tmp = q.front(); q.pop_front();
				s.erase(tmp);
			}
			q.push_back(arr[i]);
			s.insert(arr[i]);
		}

	}

	cout << q.size() << '\n';
	while (!q.empty()) {
		cout << q.back() << ' ';
		q.pop_back();
	}
	cout << '\n';
	return 0;
}


#include <iostream>
#include <string>
#include<deque>
#include<vector>
#include<algorithm>
#include<set>
#include<queue>
#include<stack>
#include<tuple>
#define maxn 20001
#define LL long long
#define inf 100000000

using namespace std;

int dx[5] = { 0,0,0,-1,1 };
int dy[5] = { 0,-1,1,0,0 };

LL arr[maxn];
LL ans;
int n, m, k, x,q;
bool flg = true;

bool desc(int a, int b) { return a > b; }

int gcd(int a, int b) {
	int n;
	if (a < b) swap(a, b);
	while (!b == 0) {
		int r = a % b;
		a = b;
		b = r;
	}
	return a;
}

int main() {

	std::ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	/*int t;
	cin >> t;
	for (int test_case = 0; test_case < t; ++test_case) {
	}*/
	LL input;
	set<LL>s;
	deque<LL>q;
	cin >> n >> k;
	LL sum = 0;
	for (int i = 0; i < n; ++i) {
		cin >> input;

		if (s.find(input) == s.end()) {
			if (q.size() >= k) {
				LL tmp = q.front(); q.pop_front();
				s.erase(tmp);
			}
			q.push_back(input);
			s.insert(input);
		}

	}

	cout << q.size() << '\n';
	while (!q.empty()) {
		cout << q.back() << ' ';
		q.pop_back();
	}
	cout << '\n';
	return 0;
}


#include <math.h>
#include <iomanip>
#include <vector>
#include <map>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <queue>
#include <random>
#include<set>
#include<stack>
#include <iostream>
using namespace std;
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	long long n, i, q, k, t, len = 0, perv = 0,siz;
	cin >> n>>k;
	vector<long long > V;

	for (i = 0; i < n; i++) {
		cin >> q;
		long long flag = 0; siz = V.size();
		for (t = 0; t < siz; t++) {
			if (V[t] == q) {
				flag = 1;
				break;
			}
		}
		if (flag == 0) {
			if (len < k) {
				V.push_back(q);
				len++;
			}
			else {
				V[perv] = -1;
				perv++;
				V.push_back(q);
			}

		}
	}
	siz = V.size();
	cout << len << endl;
	for (i = siz - 1; i >= 0; i--) {
		if (V[i] != -1)
			cout << V[i] <<" ";
	}

}


#include <math.h>
#include <iomanip>
#include <vector>
#include <map>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <queue>
#include <random>
#include<set>
#include<stack>
#include <iostream>
using namespace std;
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	long long n, i, q, k, t, len = 0, perv = 0, siz;
	cin >> n >> k;
	set<long long>St;
	vector<long long > V;

	for (i = 0; i < n; i++) {
		cin >> q;
		long long flag = 0; siz = V.size();
		if (!St.count(q)) {
			St.insert(q);
		}
		else
			flag = 1;
		if (flag == 0) {
			if (len < k) {
				V.push_back(q);
				len++;
			}
			else {
				St.erase(V[perv]);
				perv++;
				V.push_back(q);
			}
		}
	}
	siz = V.size();
	cout << len << endl;
	for (i = siz - 1; i >= siz - len; i--) {
		cout << V[i] << " ";
	}

}


#include <math.h>
#include <iomanip>
#include <vector>
#include <map>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <queue>
#include <random>
#include<set>
#include<stack>
#include <iostream>
using namespace std;
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	long long n, i, q, k, t, len = 0, perv = 0, siz;
	cin >> n >> k;
	vector<long long > V;

	for (i = 0; i < n; i++) {
		cin >> q;
		long long flag = 0; siz = V.size();
		for (t = perv; t < siz; t++) {
			if (V[t] == q) {
				flag = 1;
				break;
			}
		}
		if (flag == 0) {
			if (len < k) {
				V.push_back(q);
				len++;
			}
			else {
				V[perv] = -1;
				perv++;
				V.push_back(q);
			}

		}
	}
	siz = V.size();
	cout << len << endl;
	for (i = siz - 1; i >= siz-len; i--) {
			cout << V[i] << " ";
	}

}


#define  _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>

using namespace std;

int a[222];
vector<int> v;

int main()
{
	int n, k;
	scanf("%d%d", &n, &k);
	int l = 0;
	for (int i = 0; i < n; i++)
	{
		int t;
		scanf("%d", &t);
		int flag = 0;
		for (int i = l; i < v.size(); i++)
		{
			if (t == v[i])
				flag = 1;
		}
		if (flag == 0)
		{
			if (v.size() < k)
				v.push_back(t);
			else
			{
				v.push_back(t);
				l++;
			}
		}
	}
	int r = v.size();
	printf("%d\n", r - l);
	for (int i = r - 1; i >= l; i--)
	{
		printf("%d ", v[i]);
	}
	return 0;
}


#define  _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>

using namespace std;

int v[200010];

int main()
{
	int n, k;
	scanf("%d%d", &n, &k);
	int l = 0, r = 0;
	for (int i = 0; i < n; i++)
	{
		int t;
		scanf("%d", &t);
		int flag = 0;
		for (int i = l; i < r; i++)
		{
			if (t == v[i])
				flag = 1;
		}
		if (flag == 0)
		{
			if (r < k)
			{
				v[r] = t;
				r++;
			}
			else
			{
				v[r] = t;
				r++;
				l++;
			}
		}
	}
	printf("%d\n", r - l);
	for (int i = r - 1; i >= l; i--)
	{
		printf("%d ", v[i]);
	}
	return 0;
}


#define  _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>

using namespace std;

int v[200010];

int main()
{
	int n, k;
	scanf("%d%d", &n, &k);
	int l = 0, r = 0;
	for (int i = 0; i < n; i++)
	{
		int t;
		scanf("%d", &t);
		int flag = 0;
		for (int i = l; i < r; i++)
		{
			if (t == v[i])
			{
				flag = 1;
				break;
			}
		}
		if (flag == 0)
		{
			if (r < k)
			{
				v[r] = t;
				r++;
			}
			else
			{
				v[r] = t;
				r++;
				l++;
			}
		}
	}
	printf("%d\n", r - l);
	for (int i = r - 1; i >= l; i--)
	{
		printf("%d ", v[i]);
	}
	return 0;
}


//Author:- S_Aditya

#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
using namespace std;
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
#define ll long long
#define scn(n) scanf("%d",&n)
#define lscn(n) scanf("%lld",&n)
#define lpri(n) printf("%lld",n)
#define pri(n) printf("%d",n)
#define priln(n) printf("%d\n",n)
#define lpriln(n) printf("%lld\n",n)
#define rep(i,init,n) for(int i=init;i<n;i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define gcd __gcd
#define inf INT_MAX
#define ninf INT_MIN
const ll mod=1e9+7;
const int N=1e6+4;

struct monsters
{
    int x,y,z;
};

ll tree[4*N],lazy[4*N];

//segment tree for range update and range maximum
void update(int node,int st,int end,int l,int r,int val)
{
    if(lazy[node]!=0)
    {
        tree[node]+=lazy[node];

        if(st!=end)
        {
            lazy[2*node]+=lazy[node];

            lazy[2*node+1]+=lazy[node];
        }

        lazy[node]=0;
    }

    if(st>=l and end<=r)
    {
        tree[node]+=val;

        if(st!=end)
        {
            lazy[2*node]+=val;

            lazy[2*node+1]+=val;
        }

        return;
    }

    if(st>r or end<l)
    return;

    int mid=(st+end)/2;

    update(2*node,st,mid,l,r,val);

    update(2*node+1,mid+1,end,l,r,val);

    tree[node]=max(tree[2*node],tree[2*node+1]);
}

bool comp(monsters a,monsters b)
{
    return a.x<b.x;
}

int main()
{
    int n,m,p;

    scn(n); scn(m); scn(p);

    vector<pair<int,int>> wv(n);

    int b[m],cb[m];

    int x[p],y[p],z[p];

    rep(i,0,n)
    scn(wv[i].F),scn(wv[i].S);

    int armour[N];

    rep(i,1,N)
    armour[i]=inf;

    rep(i,0,m)
    {
        scn(b[i]),scn(cb[i]);

        armour[b[i]]=min(armour[b[i]],cb[i]);
    }

    sort(wv.begin(),wv.end());

    monsters marr[p];

    rep(i,0,p)
    scn(marr[i].x),scn(marr[i].y),scn(marr[i].z);

    sort(marr,marr+p,comp);

    int pntr=0;

    ll ans=LLONG_MIN;

    int prev=0;

    rep(i,1,N)
    if(armour[i]!=inf)
    {
        update(1,0,N-1,prev+1,i,-armour[i]);

        //cout<<prev+1<<" "<<i<<" "<<-armour[i]<<endl;

        prev=i;

        //cout<<b[i]<<" "<<-cb[i]<<endl;
    }

    update(1,0,N-1,prev+1,N-1,-1e17);

    rep(i,0,n)
    {
        while(pntr<p and marr[pntr].x<wv[i].F)
        {
            //cout<<marr[pntr].y<<" "<<marr[pntr].z<<endl;

            update(1,0,N-1,marr[pntr].y+1,N-1,marr[pntr].z),pntr++;
        }

        //best possible case after considering all armour values
        ll here=tree[1];

        //cout<<here<<" "<<wv[i].S<<endl;

        ans=max(ans,here-wv[i].S);
    }

    lpri(ans);
}


//Author:- S_Aditya

#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
using namespace std;
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
#define ll long long
#define scn(n) scanf("%d",&n)
#define lscn(n) scanf("%lld",&n)
#define lpri(n) printf("%lld",n)
#define pri(n) printf("%d",n)
#define priln(n) printf("%d\n",n)
#define lpriln(n) printf("%lld\n",n)
#define rep(i,init,n) for(int i=init;i<n;i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define gcd __gcd
#define inf INT_MAX
#define ninf INT_MIN
const ll mod=1e9+7;
const int N=1e6+4;

struct monsters
{
    int x,y,z;
};

ll tree[4*N],lazy[4*N];

//segment tree for range update and range maximum
void update(int node,int st,int end,int l,int r,ll val)
{
    if(lazy[node]!=0)
    {
        tree[node]+=lazy[node];

        if(st!=end)
        {
            lazy[2*node]+=lazy[node];

            lazy[2*node+1]+=lazy[node];
        }

        lazy[node]=0;
    }

    if(st>=l and end<=r)
    {
        tree[node]+=val;

        if(st!=end)
        {
            lazy[2*node]+=val;

            lazy[2*node+1]+=val;
        }

        return;
    }

    if(st>r or end<l)
    return;

    int mid=(st+end)/2;

    update(2*node,st,mid,l,r,val);

    update(2*node+1,mid+1,end,l,r,val);

    tree[node]=max(tree[2*node],tree[2*node+1]);
}

bool comp(monsters a,monsters b)
{
    return a.x<b.x;
}

int main()
{
    int n,m,p;

    scn(n); scn(m); scn(p);

    vector<pair<int,int>> wv(n),av(n);

    int b[m],cb[m];

    int x[p],y[p],z[p];

    rep(i,0,n)
    scn(wv[i].F),scn(wv[i].S);

    rep(i,0,m)
    scn(av[i].F),scn(av[i].S);

    sort(av.begin(),av.end());

    int cur=inf;

    for(int i=m-1;i>=0;i--)
    {
        cur=min(cur,av[i].S);

        av[i].S=cur;
    }

    sort(wv.begin(),wv.end());

    monsters marr[p];

    rep(i,0,p)
    scn(marr[i].x),scn(marr[i].y),scn(marr[i].z);

    sort(marr,marr+p,comp);

    int pntr=0;

    ll ans=LLONG_MIN;

    int prev=-1;

    rep(i,0,m)
    {
        update(1,0,N-1,prev+1,av[i].F,-av[i].S);

        //cout<<prev+1<<" "<<i<<" "<<-armour[i]<<endl;

        prev=av[i].F;

        //cout<<b[i]<<" "<<-cb[i]<<endl;
    }

    update(1,0,N-1,prev+1,N-1,-1e17);

    rep(i,0,n)
    {
        while(pntr<p and marr[pntr].x<wv[i].F)
        {
            //cout<<marr[pntr].y<<" "<<marr[pntr].z<<endl;

            update(1,0,N-1,marr[pntr].y+1,N-1,marr[pntr].z),pntr++;
        }

        //best possible case after considering all armour values
        ll here=tree[1];

        //cout<<here<<" "<<wv[i].S<<endl;

        ans=max(ans,here-wv[i].S);
    }

    lpri(ans);
}


//Author:- S_Aditya

#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
using namespace std;
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
#define ll long long
#define scn(n) scanf("%d",&n)
#define lscn(n) scanf("%lld",&n)
#define lpri(n) printf("%lld",n)
#define pri(n) printf("%d",n)
#define priln(n) printf("%d\n",n)
#define lpriln(n) printf("%lld\n",n)
#define rep(i,init,n) for(int i=init;i<n;i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define gcd __gcd
#define inf INT_MAX
#define ninf INT_MIN
const ll mod=1e9+7;
const int N=1e6+4;

struct monsters
{
    int x,y,z;
};

ll tree[4*N],lazy[4*N];

//segment tree for range update and range maximum
void update(int node,int st,int end,int l,int r,ll val)
{
    if(lazy[node]!=0)
    {
        tree[node]+=lazy[node];

        if(st!=end)
        {
            lazy[2*node]+=lazy[node];

            lazy[2*node+1]+=lazy[node];
        }

        lazy[node]=0;
    }

    if(st>=l and end<=r)
    {
        tree[node]+=val;

        if(st!=end)
        {
            lazy[2*node]+=val;

            lazy[2*node+1]+=val;
        }

        return;
    }

    if(st>r or end<l)
    return;

    int mid=(st+end)/2;

    update(2*node,st,mid,l,r,val);

    update(2*node+1,mid+1,end,l,r,val);

    tree[node]=max(tree[2*node],tree[2*node+1]);
}

bool comp(monsters a,monsters b)
{
    return a.x<b.x;
}

int main()
{
    int n,m,p;

    scn(n); scn(m); scn(p);

    vector<pair<int,int>> wv(n),av(m);

    int b[m],cb[m];

    int x[p],y[p],z[p];

    rep(i,0,n)
    scn(wv[i].F),scn(wv[i].S);

    rep(i,0,m)
    scn(av[i].F),scn(av[i].S);

    sort(av.begin(),av.end());

    int cur=inf;

    for(int i=m-1;i>=0;i--)
    {
        cur=min(cur,av[i].S);

        av[i].S=cur;
    }

    sort(wv.begin(),wv.end());

    monsters marr[p];

    rep(i,0,p)
    scn(marr[i].x),scn(marr[i].y),scn(marr[i].z);

    sort(marr,marr+p,comp);

    int pntr=0;

    ll ans=LLONG_MIN;

    int prev=-1;

    rep(i,0,m)
    {
        update(1,0,N-1,prev+1,av[i].F,-av[i].S);

        //cout<<prev+1<<" "<<i<<" "<<-armour[i]<<endl;

        prev=av[i].F;

        //cout<<b[i]<<" "<<-cb[i]<<endl;
    }

    update(1,0,N-1,prev+1,N-1,-1e17);

    rep(i,0,n)
    {
        while(pntr<p and marr[pntr].x<wv[i].F)
        {
            //cout<<marr[pntr].y<<" "<<marr[pntr].z<<endl;

            update(1,0,N-1,marr[pntr].y+1,N-1,marr[pntr].z),pntr++;
        }

        //best possible case after considering all armour values
        ll here=tree[1];

        //cout<<here<<" "<<wv[i].S<<endl;

        ans=max(ans,here-wv[i].S);
    }

    lpri(ans);
}


//Author:- S_Aditya

#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
using namespace std;
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
#define ll long long
#define scn(n) scanf("%d",&n)
#define lscn(n) scanf("%lld",&n)
#define lpri(n) printf("%lld",n)
#define pri(n) printf("%d",n)
#define priln(n) printf("%d\n",n)
#define lpriln(n) printf("%lld\n",n)
#define rep(i,init,n) for(int i=init;i<n;i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define gcd __gcd
#define inf INT_MAX
#define ninf INT_MIN
const ll mod=1e9+7;
const int N=1e6+4;

struct monsters
{
    int x,y,z;
};

ll tree[4*N],lazy[4*N];

//segment tree for range update and range maximum
void update(int node,int st,int end,int l,int r,ll val)
{
    if(lazy[node]!=0)
    {
        tree[node]+=lazy[node];

        if(st!=end)
        {
            lazy[2*node]+=lazy[node];

            lazy[2*node+1]+=lazy[node];
        }

        lazy[node]=0;
    }

    if(st>=l and end<=r)
    {
        tree[node]+=val;

        if(st!=end)
        {
            lazy[2*node]+=val;

            lazy[2*node+1]+=val;
        }

        return;
    }

    if(st>r or end<l)
    return;

    int mid=(st+end)/2;

    update(2*node,st,mid,l,r,val);

    update(2*node+1,mid+1,end,l,r,val);

    tree[node]=max(tree[2*node],tree[2*node+1]);
}

bool comp(monsters a,monsters b)
{
    return a.x<b.x;
}

int main()
{
    int n,m,p;

    scn(n); scn(m); scn(p);

    vector<pair<int,int>> wv(n);

    int b[m],cb[m];

    int x[p],y[p],z[p];

    rep(i,0,n)
    scn(wv[i].F),scn(wv[i].S);

    int armour[N];

    rep(i,1,N)
    armour[i]=inf;

    rep(i,0,m)
    {
        scn(b[i]),scn(cb[i]);

        armour[b[i]]=min(armour[b[i]],cb[i]);
    }

    sort(wv.begin(),wv.end());

    monsters marr[p];

    rep(i,0,p)
    scn(marr[i].x),scn(marr[i].y),scn(marr[i].z);

    sort(marr,marr+p,comp);

    int pntr=0;

    ll ans=LLONG_MIN;

    int prev=0;

    rep(i,1,N)
    if(armour[i]!=inf)
    {
        update(1,0,N-1,prev+1,i,1LL*-armour[i]);

        //cout<<prev+1<<" "<<i<<" "<<-armour[i]<<endl;

        prev=i;

        //cout<<b[i]<<" "<<-cb[i]<<endl;
    }

    update(1,0,N-1,prev+1,N-1,-1e17);

    rep(i,0,n)
    {
        while(pntr<p and marr[pntr].x<wv[i].F)
        {
            //cout<<marr[pntr].y<<" "<<marr[pntr].z<<endl;

            update(1,0,N-1,marr[pntr].y+1,N-1,1LL*marr[pntr].z),pntr++;
        }

        //best possible case after considering all armour values
        ll here=tree[1];

        //cout<<here<<" "<<wv[i].S<<endl;

        ans=max(ans,here-wv[i].S);
    }

    lpri(ans);
}


const int MAXN = 1000000 + 1;

ll ca[MAXN + 5];
ll cb[MAXN + 5];

struct Monster {
    int x, y, z;
    bool operator<(Monster &m) {
        return x < m.x;
    }
} mon[MAXN + 5];

struct SegmentTree {
#define ls (o<<1)
#define rs (o<<1|1)
    ll ma[(MAXN << 2) + 5];
    ll lz[(MAXN << 2) + 5];

    void PushUp(int o) {
        ma[o] = max(ma[ls], ma[rs]);
    }

    void PushDown(int o, int l, int r) {
        if(lz[o]) {
            lz[ls] += lz[o];
            lz[rs] += lz[o];
            ma[ls] += lz[o];
            ma[rs] += lz[o];
            lz[o] = 0;
        }
    }

    void Build(int o, int l, int r) {
        if(l == r) {
            ma[o] = -cb[l];
        } else {
            int m = (l + r) >> 1;
            Build(ls, l, m);
            Build(rs, m + 1, r);
            PushUp(o);
        }
        lz[o] = 0;
    }

    void Update(int o, int l, int r, int ql, int qr, ll v) {
        if(ql <= l && r <= qr) {
            lz[o] += v;
            ma[o] += v;
        } else {
            PushDown(o, l, r);
            int m = (l + r) >> 1;
            if(ql <= m)
                Update(ls, l, m, ql, qr, v);
            if(qr >= m + 1)
                Update(rs, m + 1, r, ql, qr, v);
            PushUp(o);
        }
    }

    ll QueryMax(int o, int l, int r, int ql, int qr) {
        if(ql <= l && r <= qr) {
            return ma[o];
        } else {
            PushDown(o, l, r);
            int m = (l + r) >> 1;
            ll res = -LINF;
            if(ql <= m)
                res = QueryMax(ls, l, m, ql, qr);
            if(qr >= m + 1)
                res = max(res, QueryMax(rs, m + 1, r, ql, qr));
            return res;
        }
    }
#undef ls
#undef rs
} st;

void test_case() {
    for(int i = 1; i <= MAXN + 1; ++i) {
        ca[i] = LINF;
        cb[i] = LINF;
    }
    int n, m, p;
    scanf("%d%d%d", &n, &m, &p);
    while(n--) {
        int ai, cai;
        scanf("%d%d", &ai, &cai);
        ca[ai] = min(ca[ai], (ll)cai);
    }
    while(m--) {
        int bi, cbi;
        scanf("%d%d", &bi, &cbi);
        cb[bi] = min(cb[bi], (ll)cbi);
    }
    for(int i = MAXN; i >= 1; --i) {
        ca[i] = min(ca[i], ca[i + 1]);
        cb[i] = min(cb[i], cb[i + 1]);
    }

    st.Build(1, 1, MAXN);

    for(int i = 1; i <= p; ++i)
        scanf("%d%d%d", &mon[i].x, &mon[i].y, &mon[i].z);
    sort(mon + 1, mon + 1 + p);

    ll ans = -ca[1] - cb[1];
    for(int i = 1; i <= p; ++i) {
        st.Update(1, 1, MAXN, mon[i].y + 1, MAXN, mon[i].z);
        ans = max(ans, -ca[mon[i].x + 1] + st.QueryMax(1, 1, MAXN, 1, MAXN));
    }
    printf("%lld\n", ans);
}


#include<bits/stdc++.h>
using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int INF = 1061109567;
const ll LINF = 4557430888798830399ll;

const int MOD = 1000000007;

/*---*/

const int MAXN = 1000000 + 1;

int ca[MAXN + 5];
int cb[MAXN + 5];

struct Monster {
    int x, y, z;
    bool operator<(Monster &m) {
        return x != m.x ? x < m.x : y < m.y;
    }
} mon[MAXN + 5];

struct SegmentTree {
#define ls (o<<1)
#define rs (o<<1|1)
    ll ma[(MAXN << 2) + 5];
    ll lz[(MAXN << 2) + 5];

    void PushUp(int o) {
        ma[o] = max(ma[ls], ma[rs]);
    }

    void PushDown(int o, int l, int r) {
        if(lz[o]) {
            lz[ls] += lz[o];
            lz[rs] += lz[o];
            ma[ls] += lz[o];
            ma[rs] += lz[o];
            lz[o] = 0;
        }
    }

    void Build(int o, int l, int r) {
        if(l == r) {
            ma[o] = -cb[l];
        } else {
            int m = (l + r) >> 1;
            Build(ls, l, m);
            Build(rs, m + 1, r);
            PushUp(o);
        }
        lz[o] = 0;
    }

    void Update(int o, int l, int r, int ql, int qr, ll v) {
        if(ql <= l && r <= qr) {
            lz[o] += v;
            ma[o] += v;
        } else {
            PushDown(o, l, r);
            int m = (l + r) >> 1;
            if(ql <= m)
                Update(ls, l, m, ql, qr, v);
            if(qr >= m + 1)
                Update(rs, m + 1, r, ql, qr, v);
            PushUp(o);
        }
    }

    ll QueryMax(int o, int l, int r, int ql, int qr) {
        if(ql <= l && r <= qr) {
            return ma[o];
        } else {
            PushDown(o, l, r);
            int m = l + r >> 1;
            ll res = -LINF;
            if(ql <= m)
                res = QueryMax(ls, l, m, ql, qr);
            if(qr >= m + 1)
                res = max(res, QueryMax(rs, m + 1, r, ql, qr));
            return res;
        }
    }
#undef ls
#undef rs
} st;

void test_case() {
    for(int i = 1; i <= MAXN + 1; ++i) {
        ca[i] = INF;
        cb[i] = INF;
    }
    int n, m, p;
    scanf("%d%d%d", &n, &m, &p);
    while(n--) {
        int ai, cai;
        scanf("%d%d", &ai, &cai);
        ca[ai] = min(ca[ai], cai);
    }
    while(m--) {
        int bi, cbi;
        scanf("%d%d", &bi, &cbi);
        cb[bi] = min(cb[bi], cbi);
    }
    for(int i = MAXN; i >= 1; --i) {
        ca[i] = min(ca[i + 1], ca[i]);
        cb[i] = min(cb[i + 1], cb[i]);
    }

    st.Build(1, 1, MAXN);

    for(int i = 1; i <= p; ++i)
        scanf("%d%d%d", &mon[i].x, &mon[i].y, &mon[i].z);
    sort(mon + 1, mon + 1 + p);

    ll ans = -ca[1] - cb[1];
    for(int i = 1; i <= p; ++i) {
        st.Update(1, 1, MAXN, mon[i].y + 1, MAXN, mon[i].z);
        ans = max(ans, -ca[mon[i].x + 1] + st.QueryMax(1, 1, MAXN, 1, MAXN));
    }
    printf("%lld\n", ans);
}

int main() {
#ifdef KisekiPurin
    freopen("KisekiPurin.in", "r", stdin);
#endif // KisekiPurin
    int t = 1;
    //scanf("%d", &t);
    for(int i = 1; i <= t; ++i) {
        //printf("Case #%d:", i);
        test_case();
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int INF = 1061109567;
const ll LINF = 4557430888798830399ll;

const int MOD = 1000000007;

/*---*/

const int MAXN = 1000000;

int ca[MAXN + 5];
int cb[MAXN + 5];

struct Monster {
    int x, y, z;
    bool operator<(Monster &m) {
        return x != m.x ? x < m.x : y < m.y;
    }
} mon[MAXN + 5];

struct SegmentTree {
#define ls (o<<1)
#define rs (o<<1|1)
    static const int MAXN = 1000000;
    static const int INF = 0x3f3f3f3f;
    ll ma[(MAXN << 2) + 5];
    ll lz[(MAXN << 2) + 5];

    void PushUp(int o) {
        ma[o] = max(ma[ls], ma[rs]);
    }

    void PushDown(int o, int l, int r) {
        if(lz[o]) {
            lz[ls] += lz[o];
            lz[rs] += lz[o];
            ma[ls] += lz[o];
            ma[rs] += lz[o];
            lz[o] = 0;
        }
    }

    void Build(int o, int l, int r) {
        if(l == r) {
            ma[o] = -cb[l + 1];
        } else {
            int m = (l + r) >> 1;
            Build(ls, l, m);
            Build(rs, m + 1, r);
            PushUp(o);
        }
        lz[o] = 0;
    }

    void Update(int o, int l, int r, int ql, int qr, ll v) {
        if(ql <= l && r <= qr) {
            lz[o] += v;
            ma[o] += v;
        } else {
            PushDown(o, l, r);
            int m = (l + r) >> 1;
            if(ql <= m)
                Update(ls, l, m, ql, qr, v);
            if(qr >= m + 1)
                Update(rs, m + 1, r, ql, qr, v);
            PushUp(o);
        }
    }

    ll QueryMax(int o, int l, int r, int ql, int qr) {
        if(ql <= l && r <= qr) {
            return ma[o];
        } else {
            PushDown(o, l, r);
            int m = l + r >> 1;
            ll res = -INF;
            if(ql <= m)
                res = QueryMax(ls, l, m, ql, qr);
            if(qr >= m + 1)
                res = max(res, QueryMax(rs, m + 1, r, ql, qr));
            return res;
        }
    }
#undef ls
#undef rs
} st;

void test_case() {
    for(int i = 1; i <= MAXN + 1; ++i) {
        ca[i] = INF;
        cb[i] = INF;
    }
    int n, m, p;
    scanf("%d%d%d", &n, &m, &p);
    while(n--) {
        int ai, cai;
        scanf("%d%d", &ai, &cai);
        ca[ai] = min(ca[ai], cai);
    }
    while(m--) {
        int bi, cbi;
        scanf("%d%d", &bi, &cbi);
        cb[bi] = min(cb[bi], cbi);
    }
    for(int i = MAXN + 1; i > 1; --i) {
        ca[i - 1] = min(ca[i - 1], ca[i]);
        cb[i - 1] = min(cb[i - 1], cb[i]);
    }

    st.Build(1, 1, MAXN);

    for(int i = 1; i <= p; ++i)
        scanf("%d%d%d", &mon[i].x, &mon[i].y, &mon[i].z);
    sort(mon + 1, mon + 1 + p);

    ll ans = -ca[1] - cb[1];
    for(int i = 1; i <= p; ++i) {
        st.Update(1, 1, MAXN, mon[i].y, MAXN, mon[i].z);
        ans = max(ans, - ca[mon[i].x + 1] + st.QueryMax(1, 1, MAXN, 1, MAXN));
    }
    printf("%lld\n", ans);
}

int main() {
#ifdef KisekiPurin
    freopen("KisekiPurin.in", "r", stdin);
#endif // KisekiPurin
    int t = 1;
    //scanf("%d", &t);
    for(int i = 1; i <= t; ++i) {
        //printf("Case #%d:", i);
        test_case();
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int INF = 1061109567;
const ll LINF = 4557430888798830399ll;

const int MOD = 1000000007;

/*---*/

const int MAXN = 1000000 + 1;

ll ca[MAXN + 5];
ll cb[MAXN + 5];

struct Monster {
    int x, y, z;
    bool operator<(Monster &m) {
        return x < m.x;
    }
} mon[MAXN + 5];

struct SegmentTree {
#define ls (o<<1)
#define rs (o<<1|1)
    ll ma[(MAXN << 2) + 5];
    ll lz[(MAXN << 2) + 5];

    void PushUp(int o) {
        ma[o] = max(ma[ls], ma[rs]);
    }

    void PushDown(int o, int l, int r) {
        if(lz[o]) {
            lz[ls] += lz[o];
            lz[rs] += lz[o];
            ma[ls] += lz[o];
            ma[rs] += lz[o];
            lz[o] = 0;
        }
    }

    void Build(int o, int l, int r) {
        if(l == r) {
            ma[o] = -cb[l];
        } else {
            int m = (l + r) >> 1;
            Build(ls, l, m);
            Build(rs, m + 1, r);
            PushUp(o);
        }
        lz[o] = 0;
    }

    void Update(int o, int l, int r, int ql, int qr, ll v) {
        if(ql <= l && r <= qr) {
            lz[o] += v;
            ma[o] += v;
        } else {
            PushDown(o, l, r);
            int m = (l + r) >> 1;
            if(ql <= m)
                Update(ls, l, m, ql, qr, v);
            if(qr >= m + 1)
                Update(rs, m + 1, r, ql, qr, v);
            PushUp(o);
        }
    }

    ll QueryMax(int o, int l, int r, int ql, int qr) {
        if(ql <= l && r <= qr) {
            return ma[o];
        } else {
            PushDown(o, l, r);
            int m = (l + r) >> 1;
            ll res = -LINF;
            if(ql <= m)
                res = QueryMax(ls, l, m, ql, qr);
            if(qr >= m + 1)
                res = max(res, QueryMax(rs, m + 1, r, ql, qr));
            return res;
        }
    }
#undef ls
#undef rs
} st;

void test_case() {
    for(int i = 1; i <= MAXN + 1; ++i) {
        ca[i] = LINF;
        cb[i] = LINF;
    }
    int n, m, p;
    scanf("%d%d%d", &n, &m, &p);
    while(n--) {
        int ai, cai;
        scanf("%d%d", &ai, &cai);
        ca[ai] = min(ca[ai], (ll)cai);
    }
    while(m--) {
        int bi, cbi;
        scanf("%d%d", &bi, &cbi);
        cb[bi] = min(cb[bi], (ll)cbi);
    }
    for(int i = MAXN; i >= 1; --i) {
        ca[i] = min(ca[i], ca[i + 1]);
        cb[i] = min(cb[i], cb[i + 1]);
    }

    st.Build(1, 1, MAXN);

    for(int i = 1; i <= p; ++i)
        scanf("%d%d%d", &mon[i].x, &mon[i].y, &mon[i].z);
    sort(mon + 1, mon + 1 + p);

    ll ans = -ca[1] - cb[1];
    for(int i = 1; i <= p; ++i) {
        st.Update(1, 1, MAXN, mon[i].y + 1, MAXN, mon[i].z);
        ans = max(ans, -ca[mon[i].x + 1] + st.QueryMax(1, 1, MAXN, 1, MAXN));
    }
    printf("%lld\n", ans);
}

int main() {
#ifdef KisekiPurin
    freopen("KisekiPurin.in", "r", stdin);
#endif // KisekiPurin
    int t = 1;
    //scanf("%d", &t);
    for(int i = 1; i <= t; ++i) {
        //printf("Case #%d:", i);
        test_case();
    }
    return 0;
}


#include <bits/stdc++.h>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;
int const MAXN=1e6+20;
long long const INF=2e10;
pair<int,int> aa[MAXN],bb[MAXN];
pair<int,pair<int,int>>cc[MAXN];
long long maxn[MAXN<<4],lazy[MAXN<<4];
struct STNode{
    int l,r,c;
    STNode(int ll,int rr,int cc){
        l=ll,r=rr,c=cc;
        lazy_update();
    }
    STNode left(){
        return STNode(l, (r+l)/2, c*2);
    }
    STNode right(){
        return STNode((l+r)/2+1,r,c*2+1);
    }
    void lazy_update(){
        if(lazy[c]){
            maxn[c]+=lazy[c];
            if(l!=r){
                lazy[c*2]+=lazy[c];
                lazy[c*2+1]+=lazy[c];
//        maxn[c*2]+=lazy[c],minn[c*2]+=lazy[c];
//        maxn[c*2+1]+=lazy[c],minn[c*2+1]+=lazy[c];
            }
            lazy[c]=0;
        }
    }
    void update(int ql,int qr, long long val){
        if(l>qr||r<ql)return;
        if(ql<=l&&r<=qr){
            lazy[c]+=val;
            lazy_update();
            return;
        }
        left().update(ql,qr,val);
        right().update(ql,qr,val);
        maxn[c]=max(maxn[c*2],maxn[c*2+1]);
    }

};
int main() {
    int n,m,p;
    int minn=1e9;
    STNode root(1, 1e6, 1);
    scanf("%d%d%d",&n,&m,&p);
    for (int i = 0; i < n; ++i) {
        scanf("%d%d",&aa[i].first,&aa[i].second);
        minn=min(minn,aa[i].second);
    }
    for (int i = 0; i < m; ++i) {
        scanf("%d%d",&bb[i].first,&bb[i].second);
    }
    for (int i = 0; i < p; ++i) {
        scanf("%d%d%d",&cc[i].first,&cc[i].second.first,&cc[i].second.second);
    }
    sort(aa,aa+n);
    sort(bb,bb+n,[](const std::pair<int,int> &a, const std::pair<int,int> &b){
        if(a.second==b.second)return a.first>b.first;
        else return a.second<b.second;
    });
    sort(cc,cc+p);
    //cout << cc[1].first << " " << cc[1].second.first << endl;
    int maxv=bb[0].first;
    root.update(1,bb[0].first-1,-bb[0].second);
    //cout << bb[0].first-1 << " " << -bb[0].second << endl;
    //memset(maxn,-0x3f, sizeof(maxn));
    for (int i = 1; i < m; ++i) {
        if(bb[i].first>maxv){
            //cout << maxv << endl;
            //cout << bb[i].first << " bb " <<  bb[i].second << endl;
            root.update(maxv,bb[i].first-1,-bb[i].second);
            maxv=bb[i].first;
        }
    }
    root.update(maxv,1e6,-INF);
//    for (int k = 1; k < maxv; ++k) {
//        cout << query(k,k,1,1e6,1) << " ";
//    }
//    puts("");
    long long ans=-bb[0].second-minn;
    for (int i = 0,j=0; i < n; ++i) {
        int attack=aa[i].first;
        while(j<m&&cc[j].first<attack){
            if(maxv>cc[j].second.first){
                root.update(cc[j].second.first,maxv-1,cc[j].second.second);
                //cout << cc[j].second.first << "cc[j].second.second" << cc[j].second.second << endl;
            }
            j++;
        }
//        for (int k = 1; k < maxv; ++k) {
//            cout << query(k,k,1,1e6,1) << " ";
//        }
//        puts("");
        long long cur=maxn[1]-aa[i].second;//query(1,maxv-1,1,1e6,1);
        //cout << query(1,maxv-1,1,1e6,1) << " qa  " << aa[i].second << endl;
        //cout << maxn[1] << endl;
        ans=max(ans,cur);
    }
    cout << ans << endl;

}
/*
 100
 7
 gfedcba
 8
 gfedcbaz
 * */
//


#include <bits/stdc++.h>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;
int const MAXN=1e6+20;
int const INF=2e9;
pair<int,int> aa[MAXN],bb[MAXN];
pair<int,pair<int,int>>cc[MAXN];
long long maxn[MAXN<<4],lazy[MAXN<<4];
void push(int l,int r,int cnt){
    //if(maxn[cnt]<INF)maxn[cnt]=lazy[cnt];
    //else
    maxn[cnt]+=lazy[cnt];
    if(l!=r){
        lazy[cnt<<1]+=lazy[cnt];
        lazy[cnt<<1|1]+=lazy[cnt];
    }
    lazy[cnt]=0;
}
void modify(int ql,int qr,int val,int l,int r,int cnt){
    push(l,r,cnt);
    if(ql>r || qr<l ||ql>qr)return;
    if(ql<=l&&r<=qr){
        lazy[cnt]+=val;
        push(l,r,cnt);
        return;
    }
    int mid=l+r>>1;
    modify(ql,qr,val,l,mid,cnt<<1);
    modify(ql,qr,val,mid+1,r,cnt<<1|1);
    maxn[cnt]=max(maxn[cnt<<1],maxn[cnt<<1|1]);
}
long long query(int ql,int qr,int l,int r,int cnt){
    if(ql>r || qr<l)return -INF;
    push(l,r,cnt);
    //cout << l << " l r" << r <<  " " << maxn[cnt]<< endl;
    if(ql<=l&&r<=qr)return maxn[cnt];
    int mid=l+r>>1;
    long long a=query(ql,qr,l,mid,cnt<<1);
    long long b=query(ql,qr,mid+1,r,cnt<<1|1);
    maxn[cnt]=max(maxn[cnt<<1],maxn[cnt<<1|1]);
    return max(a,b);
}
int main() {
    int n,m,p;
    int minn=1e9;
    scanf("%d%d%d",&n,&m,&p);
    for (int i = 0; i < n; ++i) {
        scanf("%d%d",&aa[i].first,&aa[i].second);
        minn=min(minn,aa[i].second);
    }
    for (int i = 0; i < m; ++i) {
        scanf("%d%d",&bb[i].first,&bb[i].second);
    }
    for (int i = 0; i < p; ++i) {
        scanf("%d%d%d",&cc[i].first,&cc[i].second.first,&cc[i].second.second);
    }
    sort(aa,aa+n);
    sort(bb,bb+n,[](const std::pair<int,int> &a, const std::pair<int,int> &b){
        if(a.second==b.second)return a.first>b.first;
        else return a.second<b.second;
    });
    sort(cc,cc+p);
    //cout << cc[1].first << " " << cc[1].second.first << endl;
    int maxv=max(bb[0].first,1);
    modify(1,bb[0].first-1,-bb[0].second,1,1e6,1);
    //cout << bb[0].first-1 << " " << -bb[0].second << endl;
    //memset(maxn,-0x3f, sizeof(maxn));
    for (int i = 1; i < m; ++i) {
        if(bb[i].first>maxv){
            //cout << maxv << endl;
            //cout << bb[i].first << " bb " <<  bb[i].second << endl;
            modify(maxv,bb[i].first-1,-bb[i].second,1,1e6,1);
            maxv=bb[i].first;
        }
    }
    modify(maxv,1e6,-INF,1,1e6,1);
//    for (int k = 1; k < maxv; ++k) {
//        cout << query(k,k,1,1e6,1) << " ";
//    }
//    puts("");
    long long ans=-bb[0].second-minn;
    for (int i = 0,j=0; i < n; ++i) {
        int attack=aa[i].first;
        while(j<m&&cc[j].first<attack){
            if(maxv>cc[j].second.first){
                modify(cc[j].second.first,maxv-1,cc[j].second.second,1,1e6,1);
                //cout << cc[j].second.first << "cc[j].second.second" << cc[j].second.second << endl;
            }
            j++;
        }
//        for (int k = 1; k < maxv; ++k) {
//            cout << query(k,k,1,1e6,1) << " ";
//        }
//        puts("");
        long long cur=maxn[1]-aa[i].second;//query(1,maxv-1,1,1e6,1);
//        cout << query(1,maxv-1,1,1e6,1) << " qa  " << aa[i].second << endl;
//        cout << maxn[1] << endl;
        ans=max(ans,cur);
    }
    cout << ans << endl;

}
/*
 100
 7
 gfedcba
 8
 gfedcbaz
 * */
//


#include <bits/stdc++.h>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;
int const MAXN=1e6+20;
long long const INF=2e10;
pair<int,int> aa[MAXN],bb[MAXN];
pair<int,pair<int,int>>cc[MAXN];
long long maxn[MAXN<<4],lazy[MAXN<<4];
struct STNode{
    int l,r,c;
    STNode(int ll,int rr,int cc){
        l=ll,r=rr,c=cc;
        lazy_update();
    }
    STNode left(){
        return STNode(l, (r+l)/2, c*2);
    }
    STNode right(){
        return STNode((l+r)/2+1,r,c*2+1);
    }
    void lazy_update(){
        if(lazy[c]){
            maxn[c]+=lazy[c];
            if(l!=r){
                lazy[c*2]+=lazy[c];
                lazy[c*2+1]+=lazy[c];
//        maxn[c*2]+=lazy[c],minn[c*2]+=lazy[c];
//        maxn[c*2+1]+=lazy[c],minn[c*2+1]+=lazy[c];
            }
            lazy[c]=0;
        }
    }
    void update(int ql,int qr, long long val){
        if(l>qr||r<ql)return;
        if(ql<=l&&r<=qr){
            lazy[c]+=val;
            lazy_update();
            return;
        }
        left().update(ql,qr,val);
        right().update(ql,qr,val);
        maxn[c]=max(maxn[c*2],maxn[c*2+1]);
    }
    long long query(int ql){
        lazy_update();
        if(l==ql&&r==ql)return maxn[c];
        if(l>ql||r<ql)return 0;
        long long ans = left().query(ql)+right().query(ql);
        maxn[c]=max(maxn[c*2],maxn[c*2+1]);
        return ans;
    }

};
int main() {
    int n,m,p;
    int minn=1e9;
    STNode root(1, 1e6, 1);
    scanf("%d%d%d",&n,&m,&p);
    for (int i = 0; i < n; ++i) {
        scanf("%d%d",&aa[i].first,&aa[i].second);
        minn=min(minn,aa[i].second);
    }
    for (int i = 0; i < m; ++i) {
        scanf("%d%d",&bb[i].first,&bb[i].second);
    }
    for (int i = 0; i < p; ++i) {
        scanf("%d%d%d",&cc[i].first,&cc[i].second.first,&cc[i].second.second);
    }
    sort(aa,aa+n);
    sort(bb,bb+n,[](const std::pair<int,int> &a, const std::pair<int,int> &b){
        if(a.second==b.second)return a.first>b.first;
        else return a.second<b.second;
    });
    sort(cc,cc+p);
    //cout << cc[1].first << " " << cc[1].second.first << endl;
    int maxv=bb[0].first;
    if(maxv>1)root.update(1,bb[0].first-1,-bb[0].second);
    //cout << bb[0].first-1 << " " << -bb[0].second << endl;
    //memset(maxn,-0x3f, sizeof(maxn));
    for (int i = 1; i < m; ++i) {
        if(bb[i].first>maxv){
            //cout << maxv << endl;
            //cout << bb[i].first << " bb " <<  bb[i].second << endl;
            root.update(maxv,bb[i].first-1,-bb[i].second);
            maxv=bb[i].first;
        }
    }
    root.update(max(maxv,1),1e6,-INF);
//    for (int k = 1; k < maxv; ++k) {
//        cout << query(k,k,1,1e6,1) << " ";
//    }
//    puts("");
    long long ans=-bb[0].second-minn;
    for (int i = 0,j=0; i < n; ++i) {
        int attack=aa[i].first;
        while(j<m&&cc[j].first<attack){
            if(maxv>cc[j].second.first){
                root.update(cc[j].second.first,maxv-1,cc[j].second.second);
                //cout << cc[j].second.first << "cc[j].second.second" << cc[j].second.second << endl;
            }
            j++;
        }
//        for (int k = 1; k < maxv; ++k) {
//            cout << root.query(k) << " ";
//        }
//        puts("");
        //long long cur=root
        long long cur=maxn[1]-aa[i].second;//query(1,maxv-1,1,1e6,1);
        //cout << query(1,maxv-1,1,1e6,1) << " qa  " << aa[i].second << endl;
        //cout << maxn[1] << endl;
        ans=max(ans,cur);
    }
    cout << ans << endl;

}
/*
 100
 7
 gfedcba
 8
 gfedcbaz
 * */
//


#include <bits/stdc++.h>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;
int const MAXN=1e6+20;
int const INF=2e9;
pair<int,int> aa[MAXN],bb[MAXN];
pair<int,pair<int,int>>cc[MAXN];
long long maxn[MAXN<<4],lazy[MAXN<<4];
void push(int l,int r,int cnt){
    //if(maxn[cnt]<INF)maxn[cnt]=lazy[cnt];
    //else
    maxn[cnt]+=lazy[cnt];
    if(l!=r){
        lazy[cnt<<1]+=lazy[cnt];
        lazy[cnt<<1|1]+=lazy[cnt];
    }
    lazy[cnt]=0;
}
void modify(int ql,int qr,int val,int l,int r,int cnt){
    push(l,r,cnt);
    if(ql>r || qr<l ||ql>qr)return;
    if(ql<=l&&r<=qr){
        lazy[cnt]+=val;
        push(l,r,cnt);
        return;
    }
    int mid=l+r>>1;
    modify(ql,qr,val,l,mid,cnt<<1);
    modify(ql,qr,val,mid+1,r,cnt<<1|1);
    maxn[cnt]=max(maxn[cnt<<1],maxn[cnt<<1|1]);
}
long long query(int ql,int qr,int l,int r,int cnt){
    if(ql>r || qr<l)return -INF;
    push(l,r,cnt);
    //cout << l << " l r" << r <<  " " << maxn[cnt]<< endl;
    if(ql<=l&&r<=qr)return maxn[cnt];
    int mid=l+r>>1;
    long long a=query(ql,qr,l,mid,cnt<<1);
    long long b=query(ql,qr,mid+1,r,cnt<<1|1);
    maxn[cnt]=max(maxn[cnt<<1],maxn[cnt<<1|1]);
    return max(a,b);
}
int main() {
    int n,m,p;
    int minn=1e9;
    scanf("%d%d%d",&n,&m,&p);
    for (int i = 0; i < n; ++i) {
        scanf("%d%d",&aa[i].first,&aa[i].second);
        minn=min(minn,aa[i].second);
    }
    for (int i = 0; i < m; ++i) {
        scanf("%d%d",&bb[i].first,&bb[i].second);
    }
    for (int i = 0; i < p; ++i) {
        scanf("%d%d%d",&cc[i].first,&cc[i].second.first,&cc[i].second.second);
    }
    sort(aa,aa+n);
    sort(bb,bb+n,[](const std::pair<int,int> &a, const std::pair<int,int> &b){
        if(a.second==b.second)return a.first>b.first;
        else return a.second<b.second;
    });
    sort(cc,cc+p);
    //cout << cc[1].first << " " << cc[1].second.first << endl;
    int maxv=bb[0].first;
    modify(1,bb[0].first-1,-bb[0].second,1,1e6,1);
    //cout << bb[0].first-1 << " " << -bb[0].second << endl;
    //memset(maxn,-0x3f, sizeof(maxn));
    for (int i = 1; i < m; ++i) {
        if(bb[i].first>maxv){
            //cout << maxv << endl;
            //cout << bb[i].first << " bb " <<  bb[i].second << endl;
            modify(maxv,bb[i].first-1,-bb[i].second,1,1e6,1);
            maxv=bb[i].first;
        }
    }
    modify(maxv,1e6,-INF,1,1e6,1);
//    for (int k = 1; k < maxv; ++k) {
//        cout << query(k,k,1,1e6,1) << " ";
//    }
//    puts("");
    long long ans=-bb[0].second-minn;
    for (int i = 0,j=0; i < n; ++i) {
        int attack=aa[i].first;
        while(j<p&&cc[j].first<attack){
            if(maxv>cc[j].second.first){
                modify(cc[j].second.first,maxv-1,cc[j].second.second,1,1e6,1);
                //cout << cc[j].second.first << "cc[j].second.second" << cc[j].second.second << endl;
            }
            j++;
        }
//        for (int k = 1; k < maxv; ++k) {
//            cout << query(k,k,1,1e6,1) << " ";
//        }
//        puts("");
        long long cur=maxn[1]-aa[i].second;//query(1,maxv-1,1,1e6,1);
//        cout << query(1,maxv-1,1,1e6,1) << " qa  " << aa[i].second << endl;
//        cout << maxn[1] << endl;
        ans=max(ans,cur);
    }
    cout << ans << endl;

}


#include <bits/stdc++.h>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;
int const MAXN=1e6+20;
int const INF=2e9;
pair<int,int> aa[MAXN],bb[MAXN];
pair<int,pair<int,int>>cc[MAXN];
long long maxn[MAXN<<4],lazy[MAXN<<4];
struct STNode{
    int l,r,c;
    STNode(int ll,int rr,int cc){
        l=ll,r=rr,c=cc;
        lazy_update();
    }
    STNode left(){
        return STNode(l, (r+l)/2, c*2);
    }
    STNode right(){
        return STNode((l+r)/2+1,r,c*2+1);
    }
    void lazy_update(){
        if(lazy[c]){
            maxn[c]+=lazy[c];
            if(l!=r){
                lazy[c*2]+=lazy[c];
                lazy[c*2+1]+=lazy[c];
//        maxn[c*2]+=lazy[c],minn[c*2]+=lazy[c];
//        maxn[c*2+1]+=lazy[c],minn[c*2+1]+=lazy[c];
            }
            lazy[c]=0;
        }
    }
    void update(int ql,int qr,int val){
        if(l>qr||r<ql)return;
        if(ql<=l&&r<=qr){
            lazy[c]+=val;
            lazy_update();
            return;
        }
        left().update(ql,qr,val);
        right().update(ql,qr,val);
        maxn[c]=max(maxn[c*2],maxn[c*2+1]);
    }

};
int main() {
    int n,m,p;
    int minn=1e9;
    STNode root(1, 1e6, 1);
    scanf("%d%d%d",&n,&m,&p);
    for (int i = 0; i < n; ++i) {
        scanf("%d%d",&aa[i].first,&aa[i].second);
        minn=min(minn,aa[i].second);
    }
    for (int i = 0; i < m; ++i) {
        scanf("%d%d",&bb[i].first,&bb[i].second);
    }
    for (int i = 0; i < p; ++i) {
        scanf("%d%d%d",&cc[i].first,&cc[i].second.first,&cc[i].second.second);
    }
    sort(aa,aa+n);
    sort(bb,bb+n,[](const std::pair<int,int> &a, const std::pair<int,int> &b){
        if(a.second==b.second)return a.first>b.first;
        else return a.second<b.second;
    });
    sort(cc,cc+p);
    //cout << cc[1].first << " " << cc[1].second.first << endl;
    int maxv=bb[0].first;
    root.update(1,bb[0].first-1,-bb[0].second);
    //cout << bb[0].first-1 << " " << -bb[0].second << endl;
    //memset(maxn,-0x3f, sizeof(maxn));
    for (int i = 1; i < m; ++i) {
        if(bb[i].first>maxv){
            //cout << maxv << endl;
            //cout << bb[i].first << " bb " <<  bb[i].second << endl;
            root.update(maxv,bb[i].first-1,-bb[i].second);
            maxv=bb[i].first;
        }
    }
    root.update(maxv,1e6,-INF);
//    for (int k = 1; k < maxv; ++k) {
//        cout << query(k,k,1,1e6,1) << " ";
//    }
//    puts("");
    long long ans=-bb[0].second-minn;
    for (int i = 0,j=0; i < n; ++i) {
        int attack=aa[i].first;
        while(j<m&&cc[j].first<attack){
            if(maxv>cc[j].second.first){
                root.update(cc[j].second.first,maxv-1,cc[j].second.second);
                //cout << cc[j].second.first << "cc[j].second.second" << cc[j].second.second << endl;
            }
            j++;
        }
//        for (int k = 1; k < maxv; ++k) {
//            cout << query(k,k,1,1e6,1) << " ";
//        }
//        puts("");
        long long cur=maxn[1]-aa[i].second;//query(1,maxv-1,1,1e6,1);
        //cout << query(1,maxv-1,1,1e6,1) << " qa  " << aa[i].second << endl;
        //cout << maxn[1] << endl;
        ans=max(ans,cur);
    }
    cout << ans << endl;

}
/*
 100
 7
 gfedcba
 8
 gfedcbaz
 * */
//


#include <bits/stdc++.h>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;
int const MAXN=1e6+20;
long long const INF=2e10;
pair<int,int> aa[MAXN],bb[MAXN];
pair<int,pair<int,int>>cc[MAXN];
long long maxn[MAXN<<4],lazy[MAXN<<4];
struct STNode{
    int l,r,c;
    STNode(int ll,int rr,int cc){
        l=ll,r=rr,c=cc;
        lazy_update();
    }
    STNode left(){
        return STNode(l, (r+l)/2, c*2);
    }
    STNode right(){
        return STNode((l+r)/2+1,r,c*2+1);
    }
    void lazy_update(){
        if(lazy[c]){
            maxn[c]+=lazy[c];
            if(l!=r){
                lazy[c*2]+=lazy[c];
                lazy[c*2+1]+=lazy[c];
//        maxn[c*2]+=lazy[c],minn[c*2]+=lazy[c];
//        maxn[c*2+1]+=lazy[c],minn[c*2+1]+=lazy[c];
            }
            lazy[c]=0;
        }
    }
    void update(int ql,int qr, long long val){
        if(l>qr||r<ql)return;
        if(ql<=l&&r<=qr){
            lazy[c]+=val;
            lazy_update();
            return;
        }
        left().update(ql,qr,val);
        right().update(ql,qr,val);
        maxn[c]=max(maxn[c*2],maxn[c*2+1]);
    }

};
int main() {
    int n,m,p;
    int minn=1e9;
    STNode root(1, 1e6, 1);
    scanf("%d%d%d",&n,&m,&p);
    for (int i = 0; i < n; ++i) {
        scanf("%d%d",&aa[i].first,&aa[i].second);
        minn=min(minn,aa[i].second);
    }
    for (int i = 0; i < m; ++i) {
        scanf("%d%d",&bb[i].first,&bb[i].second);
    }
    for (int i = 0; i < p; ++i) {
        scanf("%d%d%d",&cc[i].first,&cc[i].second.first,&cc[i].second.second);
    }
    sort(aa,aa+n);
    sort(bb,bb+n,[](const std::pair<int,int> &a, const std::pair<int,int> &b){
        if(a.second==b.second)return a.first>b.first;
        else return a.second<b.second;
    });
    sort(cc,cc+p);
    //cout << cc[1].first << " " << cc[1].second.first << endl;
    int maxv=bb[0].first;
    if(maxv>1)root.update(1,bb[0].first-1,-bb[0].second);
    //cout << bb[0].first-1 << " " << -bb[0].second << endl;
    //memset(maxn,-0x3f, sizeof(maxn));
    for (int i = 1; i < m; ++i) {
        if(bb[i].first>maxv){
            //cout << maxv << endl;
            //cout << bb[i].first << " bb " <<  bb[i].second << endl;
            root.update(maxv,bb[i].first-1,-bb[i].second);
            maxv=bb[i].first;
        }
    }
    root.update(maxv,1e6,-INF);
//    for (int k = 1; k < maxv; ++k) {
//        cout << query(k,k,1,1e6,1) << " ";
//    }
//    puts("");
    long long ans=-bb[0].second-minn;
    for (int i = 0,j=0; i < n; ++i) {
        int attack=aa[i].first;
        while(j<m&&cc[j].first<attack){
            if(maxv>cc[j].second.first){
                root.update(cc[j].second.first,maxv-1,cc[j].second.second);
                //cout << cc[j].second.first << "cc[j].second.second" << cc[j].second.second << endl;
            }
            j++;
        }
//        for (int k = 1; k < maxv; ++k) {
//            cout << query(k,k,1,1e6,1) << " ";
//        }
//        puts("");
        long long cur=maxn[1]-aa[i].second;//query(1,maxv-1,1,1e6,1);
        //cout << query(1,maxv-1,1,1e6,1) << " qa  " << aa[i].second << endl;
        //cout << maxn[1] << endl;
        ans=max(ans,cur);
    }
    cout << ans << endl;

}
/*
 100
 7
 gfedcba
 8
 gfedcbaz
 * */
//


#include <bits/stdc++.h>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;
int const MAXN=1e6+20;
long long const INF=2e10;
pair<int,int> aa[MAXN],bb[MAXN];
pair<int,pair<int,int>>cc[MAXN];
long long maxn[MAXN<<4],lazy[MAXN<<4];
struct STNode{
    int l,r,c;
    STNode(int ll,int rr,int cnt){
        l=ll,r=rr,c=cnt;
        lazy_update();
    }
    STNode left(){
        return STNode(l, (r+l)/2, c*2);
    }
    STNode right(){
        return STNode((l+r)/2+1,r,c*2+1);
    }
    void lazy_update(){
        if(lazy[c]){
            maxn[c]+=lazy[c];
            if(l!=r){
                lazy[c*2]+=lazy[c];
                lazy[c*2+1]+=lazy[c];
            }
            lazy[c]=0;
        }
    }
    void update(int ql,int qr, long long val){
        if(l>qr||r<ql)return;
        if(ql<=l&&r<=qr){
            lazy[c]+=val;
            lazy_update();
            return;
        }
        left().update(ql,qr,val);
        right().update(ql,qr,val);
        maxn[c]=max(maxn[c*2],maxn[c*2+1]);
    }
    long long query(int ql){
        lazy_update();
        if(l==ql&&r==ql)return maxn[c];
        if(l>ql||r<ql)return 0;
        long long ans = left().query(ql)+right().query(ql);
        maxn[c]=max(maxn[c*2],maxn[c*2+1]);
        return ans;
    }

};
int main() {
    int n,m,p;
    int minn=1e9;
    STNode root(1, 1e6, 1);
    scanf("%d%d%d",&n,&m,&p);
    for (int i = 0; i < n; ++i) {
        scanf("%d%d",&aa[i].first,&aa[i].second);
        minn=min(minn,aa[i].second);
    }
    for (int i = 0; i < m; ++i) {
        scanf("%d%d",&bb[i].first,&bb[i].second);
    }
    for (int i = 0; i < p; ++i) {
        scanf("%d%d%d",&cc[i].first,&cc[i].second.first,&cc[i].second.second);
    }
    sort(aa,aa+n);
    sort(bb,bb+n,[](const std::pair<int,int> &a, const std::pair<int,int> &b){
        if(a.second==b.second)return a.first>b.first;
        else return a.second<b.second;
    });
    sort(cc,cc+p);
    //cout << cc[1].first << " " << cc[1].second.first << endl;
    int maxv=bb[0].first;
    if(maxv>1)root.update(1,bb[0].first-1,-bb[0].second);
    //cout << bb[0].first-1 << " " << -bb[0].second << endl;
    //memset(maxn,-0x3f, sizeof(maxn));
    for (int i = 1; i < m; ++i) {
        if(bb[i].first>maxv){
            //cout << maxv << endl;
            //cout << bb[i].first << " bb " <<  bb[i].second << endl;
            root.update(maxv,bb[i].first-1,-bb[i].second);
            maxv=bb[i].first;
        }
    }
    root.update(max(maxv,1),1e6,-INF);
//    for (int k = 1; k < maxv; ++k) {
//        cout << query(k,k,1,1e6,1) << " ";
//    }
//    puts("");
    long long ans=-bb[0].second-minn;
    for (int i = 0,j=0; i < n; ++i) {
        int attack=aa[i].first;
        while(j<p&&cc[j].first<attack){
            if(maxv>cc[j].second.first){
                root.update(cc[j].second.first,maxv-1,cc[j].second.second);
                //cout << cc[j].second.first << "cc[j].second.second" << cc[j].second.second << endl;
            }
            j++;
        }
//        for (int k = 1; k < maxv; ++k) {
//            cout << root.query(k) << " ";
//        }
//        puts("");
        //long long cur=root
        long long cur=maxn[1]-aa[i].second;//query(1,maxv-1,1,1e6,1);
        //cout << query(1,maxv-1,1,1e6,1) << " qa  " << aa[i].second << endl;
        //cout << maxn[1] << endl;
        ans=max(ans,cur);
    }
    cout << ans << endl;

}
/*
 100
 7
 gfedcba
 8
 gfedcbaz
 * */
//


#include <bits/stdc++.h>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;
int const MAXN=2e5+20;
int const INF=2e9;
pair<int,int> aa[MAXN],bb[MAXN];
pair<int,pair<int,int>>cc[MAXN];
long long maxn[MAXN<<4],sum[MAXN<<4],lazy[MAXN<<4];
void push(int l,int r,int cnt){
    sum[cnt]+=lazy[cnt];
    //if(maxn[cnt]<INF)maxn[cnt]=lazy[cnt];
    //else
    maxn[cnt]+=lazy[cnt];
    if(l!=r){
        lazy[cnt<<1]+=lazy[cnt];
        lazy[cnt<<1|1]+=lazy[cnt];
    }
    lazy[cnt]=0;
}
void modify(int ql,int qr,int val,int l,int r,int cnt){
    push(l,r,cnt);
    if(ql>r || qr<l ||ql>qr)return;
    if(ql<=l&&r<=qr){
        lazy[cnt]+=val;
        push(l,r,cnt);
        return;
    }
    int mid=l+r>>1;
    modify(ql,qr,val,l,mid,cnt<<1);
    modify(ql,qr,val,mid+1,r,cnt<<1|1);
    maxn[cnt]=max(maxn[cnt<<1],maxn[cnt<<1|1]);
    sum[cnt]=sum[cnt<<1]+sum[cnt<<1|1];
}
long long query(int ql,int qr,int l,int r,int cnt){
    if(ql>r || qr<l)return -INF;
    push(l,r,cnt);
    //cout << l << " l r" << r <<  " " << maxn[cnt]<< endl;
    if(ql<=l&&r<=qr)return maxn[cnt];
    int mid=l+r>>1;
    long long a=query(ql,qr,l,mid,cnt<<1);
    long long b=query(ql,qr,mid+1,r,cnt<<1|1);
    maxn[cnt]=max(maxn[cnt<<1],maxn[cnt<<1|1]);
    sum[cnt]=sum[cnt<<1]+sum[cnt<<1|1];
    return max(a,b);
}
int main() {
    int n,m,p;
    scanf("%d%d%d",&n,&m,&p);
    for (int i = 0; i < n; ++i) {
        scanf("%d%d",&aa[i].first,&aa[i].second);
    }
    for (int i = 0; i < m; ++i) {
        scanf("%d%d",&bb[i].first,&bb[i].second);
    }
    for (int i = 0; i < p; ++i) {
        scanf("%d%d%d",&cc[i].first,&cc[i].second.first,&cc[i].second.second);
    }
    sort(aa,aa+n);
    sort(bb,bb+n,[](const std::pair<int,int> &a, const std::pair<int,int> &b){
        if(a.second==b.second)return a.first>b.first;
        else return a.second<b.second;
    });
    sort(cc,cc+p);
    //cout << cc[1].first << " " << cc[1].second.first << endl;
    int maxv=bb[0].first;
    modify(1,bb[0].first-1,-bb[0].second,1,2e5,1);
    //cout << bb[0].first-1 << " " << -bb[0].second << endl;
    //memset(maxn,-0x3f, sizeof(maxn));
    for (int i = 1; i < m; ++i) {
        if(bb[i].first>maxv){
            //cout << maxv << endl;
            //cout << bb[i].first << " bb " <<  bb[i].second << endl;
            modify(maxv,bb[i].first-1,-bb[i].second,1,2e5,1);
            maxv=bb[i].first;
        }
    }
    modify(maxv,2e5,-INF,1,2e5,1);
//    for (int k = 1; k < maxv; ++k) {
//        cout << query(k,k,1,2e5,1) << " ";
//    }
//    puts("");
    long long ans=-2e9;
    for (int i = 0,j=0; i < n; ++i) {
        int attack=aa[i].first;
        while(j<m&&cc[j].first<attack){
            if(maxv>cc[j].second.first){
                modify(cc[j].second.first,maxv-1,cc[j].second.second,1,2e5,1);
                //cout << cc[j].second.first << "cc[j].second.second" << cc[j].second.second << endl;
            }
            j++;
        }
//        for (int k = 1; k < maxv; ++k) {
//            cout << query(k,k,1,2e5,1) << " ";
//        }
//        puts("");
        long long cur=maxn[1]-aa[i].second;//query(1,maxv-1,1,2e5,1);
//        cout << query(1,maxv-1,1,2e5,1) << " qa  " << aa[i].second << endl;
//        cout << maxn[1] << endl;
        ans=max(ans,cur);
    }
    cout << ans << endl;

}
/*
 100
 7
 gfedcba
 8
 gfedcbaz
 * */
//


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
#define _for(i,a,b) for(int i = (a);i < b;i ++)
#define _rep(i,a,b) for(int i = (a);i > b;i --)
#define INF 0x3f3f3f3f
#define ZHUO 11100000007
#define MOD 1000000007
#define MIKUNUM 39
#define pb push_back
#define debug() printf("Miku Check OK!\n")
#define X first
#define Y second
#define maxn 200039

int n, m, p;
ll rnt = -INF;
struct good
{
	int val;
	int w;
	bool operator < (good b)
	{
		if(val!=b.val)
			return val < b.val;
		return w < b.w;
	}
	bool operator == (good b)
	{
		return val == b.val;
	}
}a[maxn], b[maxn];
struct mons
{
	int x;
	int y;
	int w;
	bool operator < (mons b)
	{
		return x < b.x;
	}
}mo[maxn];

struct disp
{
	int sz;
	good bcopy[maxn];
	int lsh[maxn];
	int bvalcopy[maxn];
	void init()
	{
        memcpy(bcopy,b,sizeof(b));
        _for(i,1,m+1)
        	bvalcopy[i] = b[i].val;
		sort(bcopy+1,bcopy+1+m);
		sort(bvalcopy,bvalcopy+1+m);
		unique(bvalcopy+1,bvalcopy+1+m);
		sz = unique(bcopy+1,bcopy+1+m)-(bcopy+1);
		_for(i,1,n+1)
			lsh[i] = lower_bound(bvalcopy+1,bvalcopy+1+sz,b[i].val)-bvalcopy;
	}
	int getsmall(int x)
	{
		return lower_bound(bvalcopy+1,bvalcopy+1+sz,x)-bvalcopy;
	}
	int getbigval(int i)
	{
		return bcopy[lsh[i]].val;
	}
	int getbigw(int i)
	{
		return bcopy[i].w;
	}
}dsp;

struct SegTree
{
	struct SegNode
	{
		int l,r;
		ll add;
		ll max;
		#define l(x) tree[x].l
		#define r(x) tree[x].r
		#define add(x) tree[x].add
		#define MAX(x) tree[x].max
	}tree[maxn<<2];
	void build(int p,int l,int r)
	{
		l(p) = l,r(p) = r;
		if(l==r)
		{
			MAX(p) = -dsp.getbigw(r);
			return ;
		}
		int mid = (l+r)/2;
		build(p*2, l, mid);
		build(p*2+1, mid+1, r);
		MAX(p) = max(MAX(p*2),MAX(p*2+1));
	}
	void spread(int p)
	{
		if(add(p))
		{
			MAX(p*2) += add(p);
			MAX(p*2+1) += add(p);
			add(p*2) += add(p);
			add(p*2+1) += add(p);
			add(p) = 0;
		}
	}
	void change(int p,int l,int r,ll d)
	{
		if(l <= l(p) && r >= r(p))
		{
			MAX(p) += d;
			add(p) += d;
			return ;
		}
		spread(p);
		int mid = (l(p)+r(p))/2;
		if(l <= mid)
			change(p*2, l, r, d);
		if(r > mid)
			change(p*2+1, l, r, d);
		MAX(p) = max(MAX(p*2),MAX(p*2+1));
	}
	ll ask4max(int p,int l,int r)
	{
		if(l <= l(p) && r >= r(p))
			return MAX(p);
		spread(p);
		int mid = (l(p)+r(p))/2;
		ll val = -INF;
		if(l <= mid)
			val = max(val,ask4max(p*2, l, r));
		if(r > mid)
			val = max(val,ask4max(p*2+1, l, r));
		return val;
	}
}T;

int main()
{
	ios::sync_with_stdio(false);
	cin >> n >> m >> p;
	_for(i,1,n+1)
		cin >> a[i].val >> a[i].w;
	_for(i,1,m+1)
		cin >> b[i].val >> b[i].w;
	_for(i,1,p+1)
		cin >> mo[i].x >> mo[i].y >> mo[i].w;

	sort(mo+1,mo+1+p);
	sort(a,a+1+n);
	dsp.init();
	T.build(1,1,dsp.sz);

	int in = 1;
	_for(i,1,n+1)
	{
		while(in <= p && mo[in].x < a[i].val)
		{
			int x = upper_bound(dsp.bvalcopy+1,dsp.bvalcopy+1+dsp.sz,mo[in].y)-dsp.bvalcopy;
			T.change(1,x,dsp.sz,mo[in].w);
			in ++;
		}
		rnt = max(rnt,T.ask4max(1,1,dsp.sz)-a[i].w);
	}
	printf("%lld",rnt);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
#define _for(i,a,b) for(int i = (a);i < b;i ++)
#define _rep(i,a,b) for(int i = (a);i > b;i --)
#define INF 0x3f3f3f3f
#define ZHUO 11100000007
#define MOD 1000000007
#define MIKUNUM 39
#define pb push_back
#define debug() printf("Miku Check OK!\n")
#define X first
#define Y second
#define maxn 200039

int n, m, p;
ll rnt = -INF;
struct good
{
	int val;
	int w;
	bool operator < (good b)
	{
		if(val!=b.val)
			return val < b.val;
		return w < b.w;
	}
	bool operator == (good b)
	{
		return val == b.val;
	}
}a[maxn], b[maxn];
struct mons
{
	int x;
	int y;
	int w;
	bool operator < (mons b)
	{
		return x < b.x;
	}
}mo[maxn];

struct disp
{
	int sz;
	good bcopy[maxn];
	int bvalcopy[maxn];
	void init()
	{
        _for(i,1,m+1)
        {
        	bvalcopy[i] = b[i].val;
        	bcopy[i] = b[i];
        }
		sort(bcopy+1,bcopy+1+m);
		sort(bvalcopy+1,bvalcopy+1+m);
		unique(bvalcopy+1,bvalcopy+1+m);
		sz = unique(bcopy+1,bcopy+1+m)-(bcopy+1);
	}
	int getbigw(int i)
	{
		return bcopy[i].w;
	}
}dsp;

struct SegTree
{
	struct SegNode
	{
		int l,r;
		ll add;
		ll max;
		#define l(x) tree[x].l
		#define r(x) tree[x].r
		#define add(x) tree[x].add
		#define MAX(x) tree[x].max
	}tree[maxn<<2];
	void build(int p,int l,int r)
	{
		l(p) = l,r(p) = r;
		if(l==r)
		{
			MAX(p) = -dsp.getbigw(r);
			return ;
		}
		int mid = (l+r)/2;
		build(p*2, l, mid);
		build(p*2+1, mid+1, r);
		MAX(p) = max(MAX(p*2),MAX(p*2+1));
	}
	void spread(int p)
	{
		if(add(p))
		{
			MAX(p*2) += add(p);
			MAX(p*2+1) += add(p);
			add(p*2) += add(p);
			add(p*2+1) += add(p);
			add(p) = 0;
		}
	}
	void change(int p,int l,int r,ll d)
	{
		if(l <= l(p) && r >= r(p))
		{
			MAX(p) += d;
			add(p) += d;
			return ;
		}
		spread(p);
		int mid = (l(p)+r(p))/2;
		if(l <= mid)
			change(p*2, l, r, d);
		if(r > mid)
			change(p*2+1, l, r, d);
		MAX(p) = max(MAX(p*2),MAX(p*2+1));
	}
	ll ask4max(int p,int l,int r)
	{
		if(l <= l(p) && r >= r(p))
			return MAX(p);
		spread(p);
		int mid = (l(p)+r(p))/2;
		ll val = -INF;
		if(l <= mid)
			val = max(val,ask4max(p*2, l, r));
		if(r > mid)
			val = max(val,ask4max(p*2+1, l, r));
		return val;
	}
}T;

int main()
{
	ios::sync_with_stdio(false);
	cin >> n >> m >> p;
	_for(i,1,n+1)
		cin >> a[i].val >> a[i].w;
	_for(i,1,m+1)
		cin >> b[i].val >> b[i].w;
	_for(i,1,p+1)
		cin >> mo[i].x >> mo[i].y >> mo[i].w;

	sort(mo+1,mo+1+p);
	sort(a+1,a+1+n);
	dsp.init();
	T.build(1,1,dsp.sz);

	int in = 1;
	_for(i,1,n+1)
	{
		while(in <= p && mo[in].x < a[i].val)
		{
			int x = upper_bound(dsp.bvalcopy+1,dsp.bvalcopy+1+dsp.sz,mo[in].y)-dsp.bvalcopy;
			if(x<=dsp.sz)
			T.change(1,x,dsp.sz,mo[in].w);
			in ++;
		}
		rnt = max(rnt,T.ask4max(1,1,dsp.sz)-a[i].w);
	}
	printf("%lld",rnt);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
#define _for(i,a,b) for(int i = (a);i < b;i ++)
#define _rep(i,a,b) for(int i = (a);i > b;i --)
#define INF 0x3f3f3f3f3f3f3f3f
#define ZHUO 11100000007
#define MOD 1000000007
#define MIKUNUM 39
#define pb push_back
#define debug() printf("Miku Check OK!\n")
#define X first
#define Y second
#define maxn 200039

int n, m, p;
ll rnt = -INF;
struct good
{
	ll val;
	ll w;
	bool operator < (good b)
	{
		if(val!=b.val)
			return val < b.val;
		return w < b.w;
	}
	bool operator == (good b)
	{
		return val == b.val;
	}
}a[maxn], b[maxn];
struct mons
{
	ll x;
	ll y;
	ll w;
	bool operator < (mons b)
	{
		return x < b.x;
	}
}mo[maxn];

struct disp
{
	int sz;
	good bcopy[maxn];
	ll bvalcopy[maxn];
	void init()
	{
        _for(i,1,m+1)
        {
        	bvalcopy[i] = b[i].val;
        	bcopy[i] = b[i];
        }
		sort(bcopy+1,bcopy+1+m);
		sort(bvalcopy+1,bvalcopy+1+m);
		unique(bvalcopy+1,bvalcopy+1+m);
		sz = unique(bcopy+1,bcopy+1+m)-(bcopy+1);
	}
	ll getbigw(int i)
	{
		return bcopy[i].w;
	}
}dsp;

struct SegTree
{
	struct SegNode
	{
		int l,r;
		ll add;
		ll max;
		#define l(x) tree[x].l
		#define r(x) tree[x].r
		#define add(x) tree[x].add
		#define MAX(x) tree[x].max
	}tree[maxn<<2];
	void build(int p,int l,int r)
	{
		l(p) = l,r(p) = r;
		if(l==r)
		{
			MAX(p) = -dsp.getbigw(r);
			return ;
		}
		int mid = (l+r)/2;
		build(p*2, l, mid);
		build(p*2+1, mid+1, r);
		MAX(p) = max(MAX(p*2),MAX(p*2+1));
	}
	void spread(int p)
	{
		if(add(p))
		{
			MAX(p*2) += add(p);
			MAX(p*2+1) += add(p);
			add(p*2) += add(p);
			add(p*2+1) += add(p);
			add(p) = 0;
		}
	}
	void change(int p,int l,int r,ll d)
	{
		if(l <= l(p) && r >= r(p))
		{
			MAX(p) += d;
			add(p) += d;
			return ;
		}
		spread(p);
		int mid = (l(p)+r(p))/2;
		if(l <= mid)
			change(p*2, l, r, d);
		if(r > mid)
			change(p*2+1, l, r, d);
		MAX(p) = max(MAX(p*2),MAX(p*2+1));
	}
	ll ask4max(int p,int l,int r)
	{
		if(l <= l(p) && r >= r(p))
			return MAX(p);
		spread(p);
		int mid = (l(p)+r(p))/2;
		ll val = -INF;
		if(l <= mid)
			val = max(val,ask4max(p*2, l, r));
		if(r > mid)
			val = max(val,ask4max(p*2+1, l, r));
		return val;
	}
}T;

int main()
{
	ios::sync_with_stdio(false);
	cin >> n >> m >> p;
	_for(i,1,n+1)
		cin >> a[i].val >> a[i].w;
	_for(i,1,m+1)
		cin >> b[i].val >> b[i].w;
	_for(i,1,p+1)
		cin >> mo[i].x >> mo[i].y >> mo[i].w;

	sort(mo+1,mo+1+p);
	sort(a+1,a+1+n);
	dsp.init();
	T.build(1,1,dsp.sz);

	int in = 1;
	_for(i,1,n+1)
	{
		while(in <= p && mo[in].x < a[i].val)
		{
			int x = upper_bound(dsp.bvalcopy+1,dsp.bvalcopy+1+dsp.sz,mo[in].y)-dsp.bvalcopy;
			if(x <= dsp.sz)
				T.change(1,x,dsp.sz,mo[in].w);
			in ++;
		}
		rnt = max(rnt,T.ask4max(1,1,dsp.sz)-a[i].w);
	}
	printf("%lld",rnt);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
#define _for(i,a,b) for(int i = (a);i < b;i ++)
#define _rep(i,a,b) for(int i = (a);i > b;i --)
#define INF 0x3f3f3f3f3f3f3f3f
#define ZHUO 11100000007
#define MOD 1000000007
#define MIKUNUM 39
#define pb push_back
#define debug() printf("Miku Check OK!\n")
#define X first
#define Y second
#define maxn 200039

int n, m, p;
ll rnt = -INF;
struct good
{
	ll val;
	ll w;
	bool operator < (good b)
	{
		if(val!=b.val)
			return val < b.val;
		return w < b.w;
	}
}a[maxn], b[maxn];
struct mons
{
	ll x;
	ll y;
	ll w;
	bool operator < (mons b)
	{
		return x < b.x;
	}
}mo[maxn];

int t;
struct piece
{
	ll bw[maxn];
	//MAX[i]��ʾ�� i �ε�ԭʼ���
	//add[i]��ʾ�� i �ε�ÿ��Ԫ�ش���ֵ /�������
	ll MAX[maxn], add[maxn];
	//L[i]��R[i]��ʾ�� i ����ԭ�����е����Ҷ˵��±�
	int L[maxn], R[maxn];
	//pos[j]��ʾ ԭ�����±� j ����һ��
	int pos[maxn];

	void init()
	{
		t = sqrt(m);
		_for(i,1,t+3)
			MAX[i] = -INF;
		_for(i,1,t+1)
		{
			L[i] = (i-1) * sqrt(m) + 1;
			R[i] = i * sqrt(m);
		}

		if(R[t] < m)
		{
			t ++;
			L[t] = R[t-1] + 1;
			R[t] = m;
		}

		_for(i,1,t+1)
		_for(j,L[i],R[i]+1)
		{
			pos[j] = i, MAX[i] = max(MAX[i],bw[j]);
		//	if(i==2)
		//		cout << MAX[i] << endl;
		}
	}
	void change(int l, int r, ll d)
	{
		int p = pos[l], q = pos[r];

		if(p==q)
		{
			_for(i,l,r+1)
				bw[i] += d;
			_for(i,L[p],R[p]+1)
				MAX[p] = max(MAX[p],bw[i]);
		}
		else
		{
			_for(i,p+1,q)
				add[i] += d;

			_for(i,l,R[p]+1)
				bw[i] += d;
			_for(i,L[p],R[p]+1)
				MAX[p] = max(MAX[p],bw[i]);

			_for(i,L[q],r+1)
				bw[i] += d;
			_for(i,L[q],R[q]+1)
				MAX[q] = max(MAX[q],bw[i]);
		}
	}

	ll ask(int l,int r)
	{
		int p = pos[l], q = pos[r];
		ll ans = -INF;

		if(p==q)
		{
			_for(i,l,r+1)
				ans = max(ans,bw[i]);
			ans += add[p];
		}
		else
		{
			_for(i,p+1,q)
				ans = max(ans,MAX[i]+add[i]);
			_for(i,l,R[p]+1)
				ans = max(ans,bw[i]);
			ans += add[p];

			_for(i,L[q],r+1)
				ans = max(ans,bw[i]);
			ans += add[q];
		}
		return ans;
	}
} P;

ll bval[maxn];
int main()
{
	ios::sync_with_stdio(false);
	cin >> n >> m >> p;
	_for(i,1,n+1)
		cin >> a[i].val >> a[i].w;
	_for(i,1,m+1)
		cin >> b[i].val >> b[i].w;
	_for(i,1,p+1)
		cin >> mo[i].x >> mo[i].y >> mo[i].w;

	sort(a+1,a+1+n);
	sort(b+1,b+1+m);
	sort(mo+1,mo+1+p);

	_for(i,1,m+1)
		bval[i] = b[i].val,P.bw[i] = -b[i].w;
	P.init();

	int in = 1;
	ll rnt = -INF;
	_for(i,1,n+1)
	{
		while(in <= p && mo[in].x < a[i].val)
		{
			int x = upper_bound(bval+1,bval+1+m,mo[in].y)-bval;
			P.change(x, m, mo[in].w);
			in ++;
		}
		rnt = max(rnt,P.ask(1,m)-a[i].w);
	}
	printf("%lld",rnt);
	return 0;
}