/*#include<iostream>
#include<cstdio>
#include<algorithm>
#include<map>
#include<queue>
#include<string.h>
#include<vector>
using namespace std;
typedef long long ll;
const ll a = 11289;
const ll b = 40961;
const ll p = 233333333;
const ll q = 998244353;
struct edgee
{
	int to;
};
struct diann
{
	ll hashvalue;
	char namee[11];
};
edgee edge[2][200200];
diann dian[2][100100];
map<string, int>name[2];
int n, edgetot[2];
char aa[20], bb[20];
int nametot[2];
int first[2][100200], nextt[2][200200];
void addedge(int from, int to, int kind)
{
	edge[kind][edgetot[kind]].to = to;
	nextt[kind][edgetot[kind]] = first[kind][from];
	first[kind][from] = edgetot[kind]++;
	edge[kind][edgetot[kind]].to = from;
	nextt[kind][edgetot[kind]] = first[kind][to];
	first[kind][to] = edgetot[kind]++;
}
int read(char *aa, int kind)
{
	if (name[kind][aa] == 0)
	{
		strcpy(dian[kind][nametot[kind]].namee, aa);
		name[kind][aa] = nametot[kind]++;
	}
	return name[kind][aa];
}
bool visit[2][100100], isinstack[2][100100];
bool visitroot[2][2];
ll hashvaluee[2][100100], temphash[100100];
int du[2][100100], height[2][100100];
int root[2][2],maxheight;
int son[2][100020];
vector<int>parent[2][100010];
void gethash(int kind)
{
	queue<int>que; maxheight = -1;
	for (int i = 1; i <nametot[kind]; i++)
	{
		visit[kind][i] = 0; isinstack[kind][i] = 0;
		if (du[kind][i] == 1)
		{
			height[kind][i] = 1;
			hashvaluee[kind][i] = 1;
			que.push(i);
		}
	}
	while (!que.empty())
	{
		int now = que.front();
		que.pop();
		visit[kind][now] = 1;
		int all = -1;
		for (int i = first[kind][now]; i != -1; i = nextt[kind][i])
		{
			int to = edge[kind][i].to;
			if (visit[kind][to] == 1&&height[kind][to]==height[kind][now]-1)
				temphash[++all] = hashvaluee[kind][to];
			else
			{
				if (isinstack[kind][to] == 0)
				{
					que.push(to);
					isinstack[kind][to] = 1;
					height[kind][to] = height[kind][now] + 1;
				}
			}
		}
		if (all != -1)
		{
			all++;
			sort(temphash, temphash + all);
			hashvaluee[kind][now] = (a*p) % q;
			for (int i = 0; i < all; i++)
			{
				hashvaluee[kind][now] = (hashvaluee[kind][now] * p^temphash[i]) % q;
			}
			hashvaluee[kind][now] = (hashvaluee[kind][now] * b) % q;
		}
		if (height[kind][now] > maxheight)
		{
			root[kind][0] = now; root[kind][1] = -1;
			maxheight = height[kind][now];
		}
		else
		{
			if (height[kind][now] == maxheight)
			{
				root[kind][1] = now;
				if (hashvaluee[kind][root[kind][1]] < hashvaluee[kind][root[kind][0]])
					swap(root[kind][0], root[kind][1]);
			}
		}
		}
		}
		bool com1(int a, int b)
		{
		return hashvaluee[0][a] < hashvaluee[0][b];
		}
		bool com2(int a, int b)
		{
		return hashvaluee[1][a] < hashvaluee[1][b];
		}
		void print(int l, int r,int fal,int far)
		{
		if (l == -1 || r == -1)
		return;
		printf("%s %s\n", dian[0][l].namee, dian[1][r].namee);
		int alll = -1,allr=-1;
		for (int i = first[0][l]; i != -1; i = nextt[0][i])
		{
		if (edge[0][i].to!=fal&&edge[0][i].to!=root[0][0]&&edge[0][i].to!=root[0][1])
		son[0][++alll]=edge[0][i].to;
		}
		sort(son[0], son[0] + alll+1, com1);
		for (int i = 0; i <=alll; i++)
		parent[0][l].push_back(son[0][i]);
		for (int i = first[1][r]; i != -1; i = nextt[1][i])
		{
		if (edge[1][i].to != far&&edge[1][i].to!=root[1][0]&&edge[1][i].to!=root[1][1]);
		son[1][++allr] = edge[1][i].to;
		}
		sort(son[1], son[1] + allr+1, com2);
		for (int i = 0; i <=allr; i++)
		parent[1][r].push_back(son[1][i]);
		for (int i = 0; i <=alll; i++)
		{
		int ll = parent[0][l][i]; int rr = parent[1][r][i];
		print(ll, rr,l,r);
		}
		}
		int main()
		{
		while (scanf("%d", &n))
		{
		nametot[0] = 1; nametot[1] = 1;
		name[0].clear(); name[1].clear();
		root[0][0] = root[0][1] = root[1][0] = root[1][1] = -1;
		visitroot[0][0] = visitroot[0][1] = visitroot[1][0] =visitroot[1][1] = 0;
		for (int i = 0; i <= n; i++)
		first[0][i] = -1, first[1][i] = -1,
		parent[0][i].clear(), parent[1][i].clear(),
		du[0][i]=du[1][i]=0;
		for (int i = 1; i < n; i++)
		{
		scanf("%s%s", aa, bb);
		int a1 = read(aa, 0);
		int b1 = read(bb, 0);
		addedge(a1, b1, 0);
		du[0][a1]++, du[0][b1]++;
		}
		for (int i = 1; i < n; i++)
		{
		scanf("%s%s", aa, bb);
		int a2 = read(aa, 1);
		int b2 = read(bb, 1);
		addedge(a2, b2, 1);
		du[1][a2]++, du[1][b2]++;
		}
		gethash(0);
		gethash(1);
		for (int i = 0; i < 2; i++)
		{
		if (root[0][i] == -1)break;
		print(root[0][i], root[1][i],-1,-1);
		}
		}
		}*/
/*#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
struct node
{
	int value;
	bool issame;
	int samevalue;
};
node tree[600000];
int a1[100010], b1[100010];
int choose[20][100010];
int a, b, C, M, last;
int n, m, A, B;
int rand(int last)
{
	a = (36969 + (last >> 3))*(a&M) + (a >> 16);
	b = (18000 + (last >> 3))*(b&M) + (b >> 16);
	return (C&((a << 16) + b)) % 1000000000;
}
int getrank(int l, int r, int h, int value)
{
	while (l < r)
	{
		int mid = (l + r) / 2+1;
		if (choose[h][mid] <= mid)
			l = mid;
		else
			r = mid - 1;
	}
	return l;
}
void pushup(int k)
{
	tree[k].value = tree[k << 1].value + tree[k << 1 | 1].value;
}
void pushdown(int k, int h, int l, int r)
{
	if (tree[k].issame)
	{
		tree[k << 1].issame = 1;
		tree[k << 1 | 1].issame = 1;
		tree[k].issame = 0;
		tree[k << 1].samevalue = tree[k].samevalue;
		tree[k << 1 | 1].samevalue = tree[k].samevalue;
		int mid = (l + r) / 2;
		int l1 = getrank(l, mid, h + 1, tree[k].samevalue);
		int l2 = getrank(mid + 1, r, h + 1, tree[k].samevalue);
		if (l1 == l)
			tree[k << 1].value = tree[k << 1].samevalue >= choose[h + 1][l] ? 1 : 0;
		else
			tree[k << 1].value = l1 - l + 1;
		if (l2 == mid + 1)
			tree[k << 1 | 1].value = tree[k << 1 | 1].samevalue >= choose[h + 1][mid + 1] ? 1 : 0;
		else
			tree[k << 1 | 1].value = l2 - mid - 1 + 1;
	}
}
void build(int l, int r, int k, int h)
{
		if (l == r)
		{
			tree[k].value = a1[l] >= b1[l] ? 1 : 0;
			return;
		}
		int mid = (l + r) / 2;
		build(l, mid, k << 1, h + 1);
		build(mid + 1, r, k << 1 | 1, h + 1);
		int l1 = l;
		int l2 = mid + 1;
		int kk = l;
		while (l1 <= mid&&l2 <= r)
		{
			if (choose[h + 1][l1] <= choose[h + 1][l2])
				choose[h][kk++] = choose[h + 1][l1++];
			else
				choose[h][kk++] = choose[h + 1][l2++];
		}
			while (l1 <= mid)
				choose[h][kk++] = choose[h + 1][l1++];
			while (l2 <= r)
				choose[h][kk++] = choose[h + 1][l2++];
			pushup(k);
}
void same(int l, int r, int ll, int rr, int k, int value, int h)
{
	if (ll>=l&&rr<=r)
	{
		int rank = getrank(ll, rr, h, value);
		if (rank == ll)
			tree[k].value = value >= choose[h][ll] ? 1 : 0;
		else
			tree[k].value = rank - ll + 1;
		tree[k].issame = 1;
		tree[k].samevalue = value;
		return;
	}
	else
	{
		pushdown(k, h, ll, rr);
		int mid = (ll + rr) / 2;
		if (mid >= l)same(l, r, ll, mid, k << 1, value, h + 1);
		if (mid+1<= r)same(l, r, mid + 1, rr, k << 1 | 1, value, h + 1);
		pushup(k);
	}
}
int getsum(int l, int r, int ll, int rr, int k, int h)
{
	if (ll >= l&&rr <= r)
	{
		return tree[k].value;
	}
	else
	{
		pushdown(k, h, ll, rr);
		int mid = (ll + rr) / 2;
		int l1 = 0, l2 = 0;
		if (mid >= l)l1 = getsum(l, r, ll, mid, k << 1, h + 1);
		if (mid + 1 <= rr)l2 = getsum(l, r, mid + 1, rr, k << 1 | 1, h + 1);
		return l1 + l2;
	}
}
int main()
{
	while (scanf("%d%d%d%d", &n, &m, &A, &B) != EOF)
	{
		a = A, b = B, C = ~(1 << 31), M = (1 << 16) - 1,last=0;
		for (int i = 1; i <= n; i++)
			scanf("%d", &a1[i]);
		for (int i = 1; i <= n; i++)
			scanf("%d", &b1[i]);
		build(1, n, 1, 0);
		while (m--)
		{
			int l, r, x;
			l = rand(last)%n+1; r = rand(last)%n+1; x = rand(last)%n+1;
			if (l > r)swap(l, r);
			if ((l + r + x) % 2 == 0)
			{
				int valuee = getsum(l, r, 1, n, 1, 0);
				last = valuee;
				printf("%d\n", valuee);
			}
			else
			{
				same(l, r, 1, n, 1, x, 0);
			}
		}
	}
}*/
/*#include<iostream>
#include<cstdio>
#include<algorithm>
#include<bitset>
#include<string.h>
using namespace std;
bitset<100001>dp[2][3], mode[26];
char a[100010], b[5020];
int n, m, t;
int main()
{
//	//dp[0][0][0] = 1;
	//dp[1][0][0] = 1;
	//dp[0][0]=dp[0][0] << 1;
	//dp[1][0] = dp[0][0] | dp[1][0];
	scanf("%d", &t);
	while (t--)
	{
		scanf("%d%d", &n, &m);
		for (int i = 0; i < 26; i++)
			mode[i].reset();
		for (int i = 0; i < 2; i++)
			for (int j = 0; j < 3; j++)
				dp[i][j].reset();
		scanf("%s%s", a, b);
		int lena =n;
		int lenb =m;
		for (int i = 0; i < lena; i++)
		{
			int kind = a[i] - 'a';
			mode[kind][i] = 1;
		}
		dp[1][1] = mode[b[0] - 'a'];
		if (lenb>=2)
		dp[1][2] = mode[b[1] - 'a'];
		b[lenb] = 'a';
		int cnt = 0;
		for (int i = 1; i < lenb; i++)
		{
				dp[cnt][0] = (dp[cnt ^ 1][2] << 1)&mode[b[i - 1] - 'a'];
			dp[cnt][1] = (((dp[cnt ^ 1][1] |dp[cnt ^ 1][0])<<1)&mode[b[i] - 'a']);
	dp[cnt][2] = (((dp[cnt ^ 1][0]|dp[cnt ^ 1][1]) << 1)&mode[b[i + 1] - 'a']);

			cnt ^= 1;
		}
		cnt ^= 1;
		for (int i = 0; i<=n-1; i++)
			if (dp[cnt][0][i + lenb - 1] | dp[cnt][1][i + lenb - 1] && i <= n - 1 - lenb + 1)
				printf("1");
			else
				printf("0");
		printf("\n");
	}
}*/
/*#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int t;
int a[1010];
int main()
{
	while (scanf("%d", &t) != EOF)
	{
		for (int i = 0; i < t; i++)
			scanf("%d", &a[i]);
		double sum1 = 0, sum2 = 0;
		sum1 = a[0] + a[t - 1];
		sum1 /= 2;
		for (int i = 1; i < t - 1; i++)
			sum2 += a[i];
		sum2 /= 3;
		printf("%.6llf\n", sum1 + sum2);
	}
	return 0;
}*/
//hdu5762
/*#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string.h>
using  namespace std;
typedef long long ll;
struct nodee
{
	int son[26];
	int fa,pos,maxx;
	//char value;
};
nodee tree[300200];
int t,tot;
char s[100100];
char cc[10];
int maxx,noww;
void insert(char c)
{
	int tempp = noww;
	noww = tot;
	if (c== cc[0])
	{
		tree[noww].pos = maxx;
	}
	//tree[noww].value = c;
	int kind = c - 'a';
	if (tree[noww].pos == 0)
		tree[noww].pos = tree[tempp].pos;
	tree[noww].maxx = maxx;
	while (tempp&&tree[tempp].son[kind] == 0)
		tree[tempp].son[kind] = noww,
		tempp=tree[tempp].fa;
	if (tempp == 0 && tree[tempp].son[kind]==0)
		tree[tempp].son[kind] = noww,
	    tree[noww].fa = tempp;
	else
	{
			int nextt = tree[tempp].son[kind];
			if (tree[nextt].maxx - 1 == tree[tempp].maxx)
				tree[noww].fa = nextt;
			else
			{
				int neww = ++tot;
				tree[neww] = tree[nextt];
				tree[neww].maxx = tree[tempp].maxx + 1;
				if (tree[nextt].maxx == tree[nextt].pos)
					tree[neww].pos = tree[tempp].maxx + 1;
				else
					tree[neww].pos = tree[tempp].pos;
				while (tempp&&tree[tempp].son[kind] == nextt)
					tree[tempp].son[kind] = neww;
				if (tempp == 0 && tree[tempp].son[kind] == nextt)
					tree[tempp].son[kind] = neww;
				tree[noww].fa = neww; tree[nextt].fa = neww;
			}
	}
	tot++;
	maxx++;
}
int main()
{
	scanf("%d", &t);
	int k = 1;
	while (t--)
	{
		for (int i = 0; i <=tot; i++)for (int j = 0; j < 26; j++)tree[i].son[j] = 0, tree[i].fa = 0, tree[i].pos = 0,tree[i].maxx=0;
		tot = 1; maxx = 1; noww = 0;
		scanf("%s", cc);
		scanf("%s", s);
		//cc[0] = (rand() % 26) + 'a';
		//for (int i = 0; i < 100000; i++)
			//s[i] = (rand() % 26) + 'a';
		int len = strlen(s);
		//len = 100000;
		for (int i = 0; i < len; i++)
		{
			insert(s[i]);
		}
		ll sum = 0;
		for (int i = tot - 1; i >= 1; i--)
		{
			int fa = tree[i].fa;
			sum += min(tree[i].maxx - tree[fa].maxx, tree[i].pos);
		}
		printf("Case #%d: %lld\n",k++,sum);
	}
}/**/

/*#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h>
using namespace std;
typedef long long ll;
const int MAXN = 100010;
int t1[MAXN], t2[MAXN], c[MAXN];//��SA������Ҫ���м����������Ҫ��ֵ
//��������ַ�������s�����У���s[0]��s[n-1],����Ϊn,�����ֵС��m,
//��s[n-1]�������s[i]������0��r[n-1]=0
//���������Ժ�������sa������
//sa[1~n]->[0,N] rank[0~n-1]->[1,N]  height[1~n]
bool cmp(int *r, int a, int b, int l)
{
	return r[a] == r[b] && r[a + l] == r[b + l];
}
void da(int str[], int sa[], int Rank[], int height[], int n, int m)
{
	n++;
	int i, j, p, *x = t1, *y = t2;
	//��һ�ֻ����������s�����ֵ�ܴ󣬿ɸ�Ϊ��������
	for (i = 0; i < m; i++)c[i] = 0;
	for (i = 0; i < n; i++)c[x[i] = str[i]]++;
	for (i = 1; i < m; i++)c[i] += c[i - 1];
	for (i = n - 1; i >= 0; i--)sa[--c[x[i]]] = i;
	for (j = 1; j <= n; j <<= 1)
	{
		p = 0;
		//ֱ������sa��������ڶ��ؼ���
		for (i = n - j; i < n; i++)y[p++] = i;//�����j�����ڶ��ؼ���Ϊ�յ���С
		for (i = 0; i < n; i++)if (sa[i] >= j)y[p++] = sa[i] - j;
		//��������y����ľ��ǰ��յڶ��ؼ�������Ľ��
		//���������һ�ؼ���
		for (i = 0; i < m; i++)c[i] = 0;
		for (i = 0; i < n; i++)c[x[y[i]]]++;
		for (i = 1; i < m; i++)c[i] += c[i - 1];
		for (i = n - 1; i >= 0; i--)sa[--c[x[y[i]]]] = y[i];
		//����sa��x��������µ�x����
		swap(x, y);
		p = 1; x[sa[0]] = 0;
		for (i = 1; i < n; i++)
			x[sa[i]] = cmp(y, sa[i - 1], sa[i], j) ? p - 1 : p++;
		if (p >= n)break;
		m = p;//�´λ�����������ֵ
	}
	int k = 0;
	n--;
	for (i = 0; i <= n; i++)Rank[sa[i]] = i;
	for (i = 0; i < n; i++)
	{
		if (k)k--;
		j = sa[Rank[i] - 1];
		while (str[i + k] == str[j + k])k++;
		height[Rank[i]] = k;
	}
}
int Rank[MAXN], height[MAXN];

char str[MAXN];
char X[3];
int r[MAXN];
int sa[MAXN];
int nxt[MAXN];

int main(){
	int T;
	scanf("%d", &T);
	for (int cs = 1; cs <= T; cs++) {
		//X[0]= (rand() % 26) + 'a';
		//for (int i = 0; i < 100000; i++)
			//str[i] = (rand() % 26) + 'a';
		scanf("%s%s", X, str);
		int n = strlen(str);
		//n = 100000;
		int temp = n;
		for (int i = n - 1; i >= 0; i--) {
			if (str[i] == X[0]) temp = i;
			nxt[i] = temp;

		}
		for (int i = 0; i < n; i++) r[i] = str[i];
		r[n] = 0;
		da(r, sa, Rank, height, n, 128);
		ll ans = 0;
		for (int i = 1; i <= n; i++) {
			//printf("%d %d %d\n",nxt[sa[i]], sa[i] , height[i]);
			ans += n - max(nxt[sa[i]], sa[i] + height[i]);
		}
		printf("Case #%d: %I64d\n", cs, ans);
	}
	return 0;
}/**/
/*#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string.h>
using namespace std;
typedef long long ll;
struct nodee
{
	int son[26];
	int maxx,fa;
};
nodee tree[2000200];
char s[1000100];
int tot, maxx, tempp,noww;
void insert(char c)
{
	tree[tot].maxx = maxx;
	tempp = noww;
	noww = tot;
	int kind = c - 'a';
	while (tempp&&tree[tempp].son[kind] == 0)
		tree[tempp].son[kind] = noww,
		tempp=tree[tempp].fa;
	if (tempp == 0 && tree[tempp].son[kind] == 0)
		tree[tempp].son[kind] = noww,
		tree[noww].fa = tempp;
	else
	{
		int nextt = tree[tempp].son[kind];
		if (tree[nextt].maxx - 1 == tree[tempp].maxx)
			tree[noww].fa = nextt;
		else
		{
			int neww = ++tot;
			tree[neww] = tree[nextt];
			tree[neww].maxx = tree[tempp].maxx + 1;
			tree[noww].fa = neww; tree[nextt].fa = neww;
			while (tree[tempp].son[kind] == nextt)
			{
				tree[tempp].son[kind] = neww;
				if (tempp == 0)break;
				tempp = tree[tempp].fa;
			}
		}
	}
	tot++, maxx++;
}
int main()
{
	tot = 1; noww = 0; maxx = 1;
	scanf("%s", s);
	int len = strlen(s);
	for (int i = 0; i < len; i++)
	{
		insert(s[i]);
	}
	ll ans = 0;
	for (int i = tot - 1; i >= 1; i--)
	{
		int fa = tree[i].fa;
		ans += tree[i].maxx - tree[fa].maxx;
	}
	printf("%lld\n", ans);
	return 0;
}/**/
//hihocoder 1449
/*#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string.h>
#include<queue>
using namespace std;
typedef long long ll;
struct nodee
{
	int maxl, maxr,fa;
	ll amount;
	int son[26];
	char vv;
};
struct lenth
{
	ll to, value;
};
lenth realvalue[1000200];
nodee tree[2000200];
int maxx, tot, noww, tempp;
char s[1000200];
int to[2000200];
void insert(char cc)
{
	tempp = noww;
	noww = tot;
	tree[noww].maxr = maxx;
	tree[noww].amount = 1;
	tree[noww].vv = cc;
	int kind = cc - 'a';
	while (tempp&&tree[tempp].son[kind] == 0)
		tree[tempp].son[kind] = noww,
		tempp = tree[tempp].fa;
	if (tempp == 0 && tree[tempp].son[kind] == 0)
	{
		tree[tempp].son[kind] = noww;
		tree[noww].fa = tempp;
	}
	else
	{
		int nextt = tree[tempp].son[kind];
		if (tree[nextt].maxr - tree[tempp].maxr == 1)
		{
			tree[noww].fa = nextt;
		}
		else
		{
			int neww = ++tot;
			tree[neww] = tree[nextt];
			tree[neww].amount = 0;
			tree[neww].maxr = tree[tempp].maxr + 1;
			tree[nextt].fa = neww; tree[noww].fa = neww;
			while (tree[tempp].son[kind] == nextt)
			{
				tree[tempp].son[kind] = neww;
				if (tempp == 0)break;
				tempp = tree[tempp].fa;
			}
		}
	}
	tot++;
	maxx++;
}
queue<int>que;
bool visit[2000200];
void getsum()
{
	while (!que.empty())
	{
		int now = que.front();
		que.pop();
		int fa = tree[now].fa;
		tree[fa].amount+=tree[now].amount;
		if (visit[fa] == 0)
		{
			visit[fa] = 1;
			if (fa)
			que.push(fa);
		}
	}
}
bool com(nodee a, nodee b)
{
	return a.amount < b.amount;
}
int main()
{
	noww = 0; maxx = 1; tot = 1;
	scanf("%s", s);
	int len = strlen(s);
	for (int i = 0; i < len; i++)
	{
		insert(s[i]);
	}
	for (int i = tot - 1; i >= 1; i--)
	{
		int fa = tree[i].fa;
		tree[i].maxl = tree[fa].maxr + 1;
		to[fa]++;
	}
	for (int i = tot - 1; i >= 1; i--)
	{
		if (to[i] == 0)
		{
			que.push(i);
		}
	}
	getsum();

	for (int i = 1; i < tot; i++)
	{
		int noww = tree[i].maxr;
		realvalue[noww].value = max(realvalue[noww].value, tree[i].amount);
	}
	for (int i = len-1; i >= 1; i--)
	{
		realvalue[i].value= max(realvalue[i].value, realvalue[i + 1].value);
	}
	for (int i = 1; i <= len; i++)
		printf("%lld\n", realvalue[i].value);
	return 0;
}/**/

/*sort(tree+1, tree + tot, com);
int amount = 0;
for (int i =tot-1; i>=1; i--)
{
if (amount == len)
break;
int l = tree[i].maxl;
int r = tree[i].maxr;
while (l <=r)
{
if (realvalue[l].value != 0)
{
l = realvalue[l].to + 1;
continue;
}
realvalue[l].to = r;
realvalue[l].value = tree[i].amount;
l++;
amount++;
}
}*/
/*#include<iostream>
#include<cstring>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<string>
#include<queue>
using namespace std;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int N = 1e6 + 100;
const int M = 1e6 + 5;
int tot, slink[2 * N], trans[2 * N][26], minlen[2 * N], maxlen[2 * N], edpts[2 * N], n;
char str[2 * N];
int blue[2 * N], ind[2 * N], ans[2 * N + 10];
int newstate(int _maxlen, int _minlen, int* _trans, int _slink) {
	maxlen[++tot] = _maxlen;
	minlen[tot] = _minlen;
	slink[tot] = _slink;
	if (_trans)
		for (int i = 0; i<26; i++)
			trans[tot][i] = _trans[i];
	return tot;
}
int add(char ch, int u) {
	int c = ch - 'a', v = u;
	int z = newstate(maxlen[u] + 1, -1, NULL, 0);
	blue[z] = 1;//��ɫ
	while (v&&!trans[v][c]) {
		trans[v][c] = z;
		v = slink[v];
	}
	if (!v) {
		minlen[z] = 1;
		slink[z] = 1;
		ind[0]++;
		return z;
	}
	int x = trans[v][c];
	if (maxlen[v] + 1 == maxlen[x]) {
		slink[z] = x;
		minlen[z] = maxlen[x] + 1;
		ind[x]++;
		return z;
	}
	int y = newstate(maxlen[v] + 1, -1, trans[x], slink[x]);
	slink[z] = slink[x] = y;
	ind[y] += 2;
	minlen[x] = minlen[z] = maxlen[y] + 1;
	while (v&&trans[v][c] == x) {
		trans[v][c] = y;
		v = slink[v];
	}
	minlen[y] = maxlen[slink[y]] + 1;
	return z;
}
void count() {
	queue<int> q;
	for (int i = 1; i <= tot; i++)if (!ind[i]) {
		q.push(i);
	}
	while (!q.empty()) {
		int u = q.front();
		q.pop();
		if (blue[u]) edpts[u]++;
		edpts[slink[u]] += edpts[u];
		if (!--ind[slink[u]]) q.push(slink[u]);
	}
}

int main() {
	int i;
	scanf("%s", str);
	int len = strlen(str), pre = 1;
	tot = 1;
	for (i = 0; i<len; i++) {
		pre = add(str[i], pre);
	}
	count();
	for (i = 0; i <= tot; i++){
		ans[maxlen[i]] = max(ans[maxlen[i]], edpts[i]);
	}
	for (i = tot; i>0; i--){
		ans[i] = max(ans[i], ans[i + 1]);
	}
	for (i = 1; i <= len; i++)printf("%d\n", ans[i]);
	return 0;
}/**/
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<queue>
using namespace std;
typedef long long ll;
struct edgee
{
	int from, to;
	ll cap,tempcap;
	edgee(int a, int b, ll c) :from(a), to(b), cap(c)
	{}
	edgee()
	{}
};
edgee edge[1010];
int first[1010], nextt[1010];
int edgetot = 0;
int h[1010], num[1010],fa[1010],edgenum[1010];
int tfirst[1010];
bool isin[1010];
void addedge(int from, int to, ll cap)
{
	edge[edgetot] = edgee(from, to, cap);
	nextt[edgetot] = first[from];
	first[from] = edgetot++;
	edge[edgetot] = edgee(to, from, 0);
	nextt[edgetot] = first[to];
	first[to] = edgetot++;
}
int n, m, x;
bool endd;
void bfs(int t,int s)
{
	for (int i = 1; i <= n; i++)
		h[i] = 1000000000;
	h[t] = 0;
	num[0] = 1;
	queue<int>que;
	que.push(t);
	while (!que.empty())
	{
		int now = que.front();
		que.pop();
		for (int i = first[now]; i != -1; i = nextt[i])
		{
			int to = edge[i].to;
			if (h[to] != 1000000000)
				continue;
			h[to] =  h[now] + 1;
			num[h[to]]++;
			que.push(to);
		}
	}
}
void augument(int t,ll &mincap)
{
	for (int i = fa[t]; i; i = fa[i])
	{
		edge[edgenum[i]].tempcap -= mincap;
		edge[edgenum[i] ^ 1].tempcap += mincap;
	}
}
ll isap(int s,int t)
{
	int temp = s;
	ll capp = 100000000000000000;
	ll ans = 0;
	while (h[s] <n)
	{
		int tempp = temp;
		if (temp == t)
		{
			augument(temp, capp);
			ans += capp;
			temp =s;
			capp = 100000000000000000;
			continue;
		}
		for (int &i = first[temp]; i != -1; i = nextt[i])
		{
			int to = edge[i].to;
			if (h[to] == h[temp] - 1 && edge[i].tempcap > 0)
			{
				fa[to] = temp;
				edgenum[temp] = i;
				temp = to;
				capp = min(capp, edge[i].tempcap);
				break;
			}
		}
		if (tempp != temp)
			continue;
		num[h[temp]]--;
		if (num[h[temp]] == 0)
			break;
		int minh = 100000000;
		for (int j = tfirst[temp]; j != -1; j = nextt[j])
		{
			int to = edge[j].to;
			if (edge[j].tempcap > 0)
				minh = min(minh, h[to]);
		}
		first[temp] = tfirst[temp];
		if (minh != 100000000)
			h[temp] = minh+1;
		else
			h[temp] = 100000000;
		if (h[temp] != 100000000)
		num[h[temp]]++;
		if (temp != s)
			temp = fa[temp];
	}
	return ans;
}
ll solve(double k)
{
	for (int i = 0; i < edgetot; i++)
		edge[i].tempcap = (ll)(edge[i].cap / k);
	for (int i = 1; i <= n; i++)
		first[i] = tfirst[i],fa[i]=0,edgenum[i]=0;
	ll ans = 0;
	bfs(n, 1);
	ans += isap(1, n);
	return ans;
}
int main()
{
	scanf("%d%d%d", &n, &m, &x);
	for (int i = 0; i <= n; i++)
		first[i] = -1;
	for (int i = 0; i < m; i++)
	{
		int a, b, c;
		scanf("%d%d%d", &a, &b, &c);
		addedge(a, b, c);
	}
	for (int i = 1; i <= n; i++)
		tfirst[i] = first[i];
	double l = 0;
	    double r = 1000000;
		double l1 = 0;
		double r1 = r;
	while ((r - l )> (1e-11))
	{
		double mid = (l + r) / 2;
		if (solve(mid)>=x)
		{
			l = mid;
			if (fabs(l - l1) <=1e-9)
				break;
		}
		else
		{
			r = mid;
			if (fabs(r - r1) <=1e-9)
				break;
		}
	}
	printf("%.8lf\n", l*x);
	return 0;
	}/**/


#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <vector>
#include <math.h>
#include <iostream>
using namespace std;
#define eps 1e-11
#define N 55
#define M 500500
#define INF 0x3fffff

struct node1
{
    long long to,w,next;
}edge[M];

long long sn,sm,sx;
long long pre[10*N];
long long g[N][N];
long long gap[10*N],lv[10*N];
long long k,c,m;
long long cnt;
long long n,nn;
long long s,t;
long long ans;
long long sum;

void add_edge(long long u,long long v,long long w)
{
    edge[cnt].to=v;
    edge[cnt].w=w;
    edge[cnt].next=pre[u];
    pre[u]=cnt++;
}

long long gdfs(long long k,long long w)
{
    if(k==t) return w;
    long long f=0;
    long long mi=nn-1;
    for(long long p=pre[k];p!=-1;p=edge[p].next)
    {
        long long v=edge[p].to,tw=edge[p].w;
        if(tw!=0)
        {
            if(lv[k]==lv[v]+1)
            {
                long long tmp=gdfs(v,min(tw,w-f));
                f+=tmp;
                edge[p].w-=tmp;
                edge[p^1].w+=tmp;
                if(f==w||lv[s]==nn) break;
            }
            if(lv[v]<mi) mi=lv[v];
        }
    }
    if(f==0)
    {
        gap[lv[k]]--;
        if( gap[ lv[k] ]==0 )
        {
            lv[s]=nn;
        }
        lv[k]=mi+1;
        gap[lv[k]]++;
    }
    return f;
}

long long sap()
{
    memset(lv,0,sizeof(lv));
    memset(gap,0,sizeof(gap));
    gap[0]=nn;
    while(lv[s]<nn)
    {
        sum+=gdfs(s,INF);
    }
    return sum;
}

long long a[505],b[505],kk[505];

long long check(long double mid)
{
    sum=0;
    mid/=sx;
    memset(pre,-1,sizeof(pre));
    cnt=0;

    for(long long i=0;i<sm;i++)
    {
        add_edge(a[i],b[i],(long long)(kk[i]/mid+eps));
        add_edge(b[i],a[i],0);
    }
    if(sap()>=sx)
    {
        return 1;
    }
    else return 0;
}

int main()
{
    cin>>sn>>sm>>sx;
    for(long long i=0;i<sm;i++)
    {
        cin>>a[i]>>b[i]>>kk[i];
    }

    s=1;
    t=sn;
    nn=t+1;

    long double b=0,d=1000000000.0;
    while(d-b > 1e-8)
    {
        long double mid=(b+d)/2;
        if( check(mid)==1 )
        {
            b = mid;
        }
        else
        {
            d = mid;
        }
    }
    printf("%.20Lf",b);
    return 0;
}


#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <vector>
#include <math.h>
#include <iostream>
using namespace std;

#define N 55
#define M 500500
#define INF 0x3fffff

struct node1
{
    int to,w,next;
}edge[M];

int sn,sm,sx;
int pre[10*N];
int g[N][N];
int gap[10*N],lv[10*N];
int k,c,m;
int cnt;
int n,nn;
int s,t;
int ans;
int sum;

void add_edge(int u,int v,int w)
{
    edge[cnt].to=v;
    edge[cnt].w=w;
    edge[cnt].next=pre[u];
    pre[u]=cnt++;
}

int gdfs(int k,int w)
{
    if(k==t) return w;
    int f=0;
    int mi=nn-1;
    for(int p=pre[k];p!=-1;p=edge[p].next)
    {
        int v=edge[p].to,tw=edge[p].w;
        if(tw!=0)
        {
            if(lv[k]==lv[v]+1)
            {
                int tmp=gdfs(v,min(tw,w-f));
                f+=tmp;
                edge[p].w-=tmp;
                edge[p^1].w+=tmp;
                if(f==w||lv[s]==nn) break;
            }
            if(lv[v]<mi) mi=lv[v];
        }
    }
    if(f==0)
    {
        gap[lv[k]]--;
        if( gap[ lv[k] ]==0 )
        {
            lv[s]=nn;
        }
        lv[k]=mi+1;
        gap[lv[k]]++;
    }
    return f;
}

int sap()
{
    memset(lv,0,sizeof(lv));
    memset(gap,0,sizeof(gap));
    gap[0]=nn;
    while(lv[s]<nn)
    {
        sum+=gdfs(s,INF);
    }
    return sum;
}

int a[505],b[505],kk[505];

int check(long double mid)
{
    sum=0;

    memset(pre,-1,sizeof(pre));
    cnt=0;

    for(int i=0;i<sm;i++)
    {
        add_edge(a[i],b[i],(int)(kk[i]/mid));
        add_edge(b[i],a[i],0);
    }
    if(sap()>=sx)
    {
        return 1;
    }
    else return 0;
}

int main()
{
    cin>>sn>>sm>>sx;
    for(int i=0;i<sm;i++)
    {
        scanf("%d%d%d",a+i,b+i,kk+i);
    }

    s=1;
    t=sn;
    nn=t+1;

    long double b=0,d=1000000000.0;
    while(d-b > 1e-9)
    {
        long double mid=(b+d)/2;
        if( check(mid)==1 )
        {
            b = mid;
        }
        else
        {
            d = mid;
        }
    }
    printf("%.20Lf",b*sx);
    return 0;
}


#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <vector>
#include <math.h>
#include <iostream>
using namespace std;

#define N 55
#define M 500500
#define INF 0x3fffff

struct node1
{
    int to,w,next;
}edge[M];

int sn,sm,sx;
int pre[10*N];
int g[N][N];
int gap[10*N],lv[10*N];
int k,c,m;
int cnt;
int n,nn;
int s,t;
int ans;
int sum;

void add_edge(int u,int v,int w)
{
    edge[cnt].to=v;
    edge[cnt].w=w;
    edge[cnt].next=pre[u];
    pre[u]=cnt++;
}

int gdfs(int k,int w)
{
    if(k==t) return w;
    int f=0;
    int mi=nn-1;
    for(int p=pre[k];p!=-1;p=edge[p].next)
    {
        int v=edge[p].to,tw=edge[p].w;
        if(tw!=0)
        {
            if(lv[k]==lv[v]+1)
            {
                int tmp=gdfs(v,min(tw,w-f));
                f+=tmp;
                edge[p].w-=tmp;
                edge[p^1].w+=tmp;
                if(f==w||lv[s]==nn) break;
            }
            if(lv[v]<mi) mi=lv[v];
        }
    }
    if(f==0)
    {
        gap[lv[k]]--;
        if( gap[ lv[k] ]==0 )
        {
            lv[s]=nn;
        }
        lv[k]=mi+1;
        gap[lv[k]]++;
    }
    return f;
}

int sap()
{
    memset(lv,0,sizeof(lv));
    memset(gap,0,sizeof(gap));
    gap[0]=nn;
    while(lv[s]<nn)
    {
        sum+=gdfs(s,INF);
    }
    return sum;
}

int a[505],b[505],kk[505];

int check(long double mid)
{
    sum=0;
    mid/=sx;
    memset(pre,-1,sizeof(pre));
    cnt=0;

    for(int i=0;i<sm;i++)
    {
        add_edge(a[i],b[i],(int)(kk[i]/mid));
        add_edge(b[i],a[i],0);
    }
    if(sap()>=sx)
    {
        return 1;
    }
    else return 0;
}

int main()
{
    cin>>sn>>sm>>sx;
    for(int i=0;i<sm;i++)
    {
        scanf("%d%d%d",a+i,b+i,kk+i);
    }

    s=1;
    t=sn;
    nn=t+1;

    long double b=0,d=1000000000.0;
    while(d-b > 1e-8)
    {
        long double mid=(b+d)/2;
        if( check(mid)==1 )
        {
            b = mid;
        }
        else
        {
            d = mid;
        }
    }
    printf("%.20Lf",b);
    return 0;
}


//
//  main.cpp
//  bc76
//
//  Created by 陈加寿 on 16/3/19.
//  Copyright © 2016年 chenhuan001. All rights reserved.
//

#include <iostream>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <algorithm>
using namespace std;

#define MOD 1000000007

long long save[100100];

int main(int argc, const char * argv[]) {
    int T;
    cin>>T;
    while(T--)
    {
        long long n,k;
        cin>>n>>k;
        if(k*(k+1)/2>n)
        {
            printf("-1\n");
            continue;
        }
        long long tmp = n/k;
        long long last = n%k;
        for(int i=1;i<=k;i++)
            save[i] = tmp;

        if(k%2 == 0)
        {
            long long ti=k/2;
            long long tj=ti+1;
            for(int i=1;i<=k/2;i++)
            {
                save[ti] += i;
                save[tj] -= i;
                ti--;
                tj++;
            }
        }
        else
        {
            long long ti=k/2+1;
            long long tj=ti;
            for(int i=0;i<=k/2;i++)
            {
                save[ti] += i;
                save[tj] -= i;
                ti--;
                tj++;
            }
        }
        for(int i=1;i<=last;i++)
            save[i]++;
        long long ans=1;
        for(int i=1;i<=k;i++)
            ans = (ans*save[i])%MOD;
        cout<<ans<<endl;
    }
    return 0;
}


/**/
#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <string>
#include <vector>
#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
#define mp          make_pair
#define pb          push_back
#define FIN         freopen("C:\\Users\\Administrator\\Desktop\\Code\\in.txt", "r", stdin)
#define FOUT        freopen("C:\\Users\\Administrator\\Desktop\\Code\\out.txt", "w", stdout)
#define lson        l, mid, cur << 1
#define rson        mid + 1, r, cur << 1 | 1
#define debug       puts("-------------");
#define lowbit(x)   ((x)&(-(x)))
//#pragma comment(linker, "/STACK:1024000000,1024000000")
const int INF = 0x3f3f3f3f;
const LL INFLL = 0x3f3f3f3f3f3f3f3fLL;
const double eps = 1e-8;
const int MOD = 1e9 + 7;
const int MAXN = 1e5 + 50;
const int MAXM = 2e4 + 50;

int n, m, a, b[MAXN], p[MAXN];

int main() {
#ifdef LOCAL_NORTH
    FIN;
#endif // LOCAL_NORTH
    while (~scanf("%d%d%d", &n, &m, &a)) {
        for (int i = 0; i < n; i++)
            scanf("%d", &b[i]);
        for (int i = 0; i < m; i++)
            scanf("%d", &p[i]);
        sort(b, b + n);
        sort(p, p + m);
        int r = 0;
        LL s = 0, sum1 = 0, sum2 = 0;
        for (int i = 0; i < min(n, m); i++) {
            sum1 += p[i];
            sum2 += b[n - 1 - i];
            if (sum1 <= sum2 + a) {
                r = i + 1;
                s = max(sum1 - a, 0LL);
            }
            else
                break;
        }
        printf("%d %I64d\n", r, s);
    }
#ifdef LOCAL_NORTH
    cout << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC * 1000 << " ms." << endl;
#endif // LOCAL_NORTH
    return 0;
}


/**/
#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <string>
#include <vector>
#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
#define mp          make_pair
#define pb          push_back
#define FIN         freopen("C:\\Users\\Administrator\\Desktop\\Code\\in.txt", "r", stdin)
#define FOUT        freopen("C:\\Users\\Administrator\\Desktop\\Code\\out.txt", "w", stdout)
#define lson        l, mid, cur << 1
#define rson        mid + 1, r, cur << 1 | 1
#define debug       puts("-------------");
#define lowbit(x)   ((x)&(-(x)))
//#pragma comment(linker, "/STACK:1024000000,1024000000")
const int INF = 0x3f3f3f3f;
const LL INFLL = 0x3f3f3f3f3f3f3f3fLL;
const double eps = 1e-8;
const int MOD = 1e9 + 7;
const int MAXN = 1e5 + 50;
const int MAXM = 2e4 + 50;

int n, m, a, b[MAXN], p[MAXN];

PII solve(int m) {
    bool vis[MAXN] = {false};
    int pos = m - 1, r = 0, s = 0;
    for (int i = n - 1; i >= 0; i--) {
        while (pos >= 0 && p[pos] > b[i]) pos--;
        if (pos >= 0) {
            r++;
            s += p[pos];
            vis[pos] = true;
            pos--;
        } else break;
    }
    int ta = a;
    pos = 0;
    for (int i = 0; i < n && ta > 0; i++) {
        while (pos < m && vis[pos]) pos++;
        if (pos < m) {
            if (p[pos] - b[i] <= ta) {
                ta -= p[pos] - b[i];
                r++;
                s += b[i];
                pos++;
            } else break;
        } else break;
    }
    return mp(r, max(s - ta, 0));
}

int main() {
#ifdef LOCAL_NORTH
    FIN;
#endif // LOCAL_NORTH
    while (~scanf("%d%d%d", &n, &m, &a)) {
        for (int i = 0; i < n; i++)
            scanf("%d", &b[i]);
        for (int i = 0; i < m; i++)
            scanf("%d", &p[i]);
        sort(b, b + n);
        sort(p, p + m);
        PII res = solve(m);
        res = solve(res.first);
        printf("%d %d\n", res.first, res.second);
    }
#ifdef LOCAL_NORTH
    cout << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC * 1000 << " ms." << endl;
#endif // LOCAL_NORTH
    return 0;
}


/**/
#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <string>
#include <vector>
#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
#define mp          make_pair
#define pb          push_back
#define FIN         freopen("C:\\Users\\Administrator\\Desktop\\Code\\in.txt", "r", stdin)
#define FOUT        freopen("C:\\Users\\Administrator\\Desktop\\Code\\out.txt", "w", stdout)
#define lson        l, mid, cur << 1
#define rson        mid + 1, r, cur << 1 | 1
#define debug       puts("-------------");
#define lowbit(x)   ((x)&(-(x)))
//#pragma comment(linker, "/STACK:1024000000,1024000000")
const int INF = 0x3f3f3f3f;
const LL INFLL = 0x3f3f3f3f3f3f3f3fLL;
const double eps = 1e-8;
const int MOD = 1e9 + 7;
const int MAXN = 1e5 + 50;
const int MAXM = 2e4 + 50;

int n, m, a, b[MAXN], p[MAXN];

int solve(int m) {
    bool vis[MAXN] = {false};
    int pos = m - 1, r = 0;
    for (int i = n - 1; i >= 0; i--) {
        while (pos >= 0 && p[pos] > b[i]) pos--;
        if (pos >= 0) {
            r++;
            vis[pos] = true;
            pos--;
        } else break;
    }
    int ta = a;
    pos = 0;
    for (int i = 0; i < n; i++) {
        while (pos < m && vis[pos]) pos++;
        if (pos < m) {
            if (p[pos] - b[i] <= ta) {
                ta -= max(p[pos] - b[i], 0);
                r++;
            }
            pos++;
        } else break;
    }
    return r;
}

int main() {
#ifdef LOCAL_NORTH
    FIN;
#endif // LOCAL_NORTH
    while (~scanf("%d%d%d", &n, &m, &a)) {
        for (int i = 0; i < n; i++)
            scanf("%d", &b[i]);
        for (int i = 0; i < m; i++)
            scanf("%d", &p[i]);
        sort(b, b + n);
        sort(p, p + m);
        int r = solve(m);
        LL tmp = 0;
        for (int i = 0; i < r; i++)
            tmp += p[i];
        printf("%d %I64d\n", r, max(0LL, tmp - a));
    }
#ifdef LOCAL_NORTH
    cout << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC * 1000 << " ms." << endl;
#endif // LOCAL_NORTH
    return 0;
}


/**/
#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <string>
#include <vector>
#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
#define mp          make_pair
#define pb          push_back
#define FIN         freopen("C:\\Users\\Administrator\\Desktop\\Code\\in.txt", "r", stdin)
#define FOUT        freopen("C:\\Users\\Administrator\\Desktop\\Code\\out.txt", "w", stdout)
#define lson        l, mid, cur << 1
#define rson        mid + 1, r, cur << 1 | 1
#define debug       puts("-------------");
#define lowbit(x)   ((x)&(-(x)))
//#pragma comment(linker, "/STACK:1024000000,1024000000")
const int INF = 0x3f3f3f3f;
const LL INFLL = 0x3f3f3f3f3f3f3f3fLL;
const double eps = 1e-8;
const int MOD = 1e9 + 7;
const int MAXN = 1e5 + 50;
const int MAXM = 2e4 + 50;

int n, m, a, b[MAXN], p[MAXN];

PII solve(int m) {
    bool vis[MAXN];
    int pos = m - 1, r = 0, s = 0;
    for (int i = n - 1; i >= 0; i--) {
        while (p[pos] > b[i]) pos--;
        if (pos >= 0) {
            r++;
            s += p[pos];
            vis[pos] = true;
            pos--;
        } else break;
    }
    int ta = a;
    pos = 0;
    for (int i = 0; i < n && ta > 0; i++) {
        while (vis[pos]) pos++;
        if (pos < m) {
            if (p[pos] - b[i] <= ta) {
                ta -= p[pos] - b[i];
                r++;
                s += b[i];
                pos++;
            } else break;
        } else break;
    }
//    printf("[%d %d]\n", r, s - ta);
    return mp(r, s - ta);
}

int main() {
#ifdef LOCAL_NORTH
    FIN;
#endif // LOCAL_NORTH
    while (~scanf("%d%d%d", &n, &m, &a)) {
        for (int i = 0; i < n; i++)
            scanf("%d", &b[i]);
        for (int i = 0; i < m; i++)
            scanf("%d", &p[i]);
        sort(b, b + n);
        sort(p, p + m);
        PII res = solve(n);
        res = solve(res.first);
        printf("%d %d\n", res.first, res.second);
    }
#ifdef LOCAL_NORTH
    cout << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC * 1000 << " ms." << endl;
#endif // LOCAL_NORTH
    return 0;
}


/**/
#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <string>
#include <vector>
#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
#define mp          make_pair
#define pb          push_back
#define FIN         freopen("C:\\Users\\Administrator\\Desktop\\Code\\in.txt", "r", stdin)
#define FOUT        freopen("C:\\Users\\Administrator\\Desktop\\Code\\out.txt", "w", stdout)
#define lson        l, mid, cur << 1
#define rson        mid + 1, r, cur << 1 | 1
#define debug       puts("-------------");
#define lowbit(x)   ((x)&(-(x)))
//#pragma comment(linker, "/STACK:1024000000,1024000000")
const int INF = 0x3f3f3f3f;
const LL INFLL = 0x3f3f3f3f3f3f3f3fLL;
const double eps = 1e-8;
const int MOD = 1e9 + 7;
const int MAXN = 1e5 + 50;
const int MAXM = 2e4 + 50;

int n, m, a, b[MAXN], p[MAXN];

bool rent(int m) {
    LL dif = 0;
    for (int i = 0; i < m; i++) {
        int B = b[n - m + i], P = p[i];
        dif += max(0, P - B);
    }
    return dif <= a;
}

int main() {
#ifdef LOCAL_NORTH
    FIN;
#endif // LOCAL_NORTH
    while (~scanf("%d%d%d", &n, &m, &a)) {
        for (int i = 0; i < n; i++)
            scanf("%d", &b[i]);
        for (int i = 0; i < m; i++)
            scanf("%d", &p[i]);
        sort(b, b + n);
        sort(p, p + m);
        int low = 0, high = min(m, n);
        while (low <= high) {
            int mid = (low + high) / 2;
            if (rent(mid))
                low = mid + 1;
            else
                high = mid - 1;
        }
        LL sum = 0;
        for (int i = 0; i < low - 1; i++)
            sum += p[i];
        printf("%d %I64d\n", low - 1, max(0LL, sum - a));
    }
#ifdef LOCAL_NORTH
    cout << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC * 1000 << " ms." << endl;
#endif // LOCAL_NORTH
    return 0;
}


/*
����+̰��
����r������s
ÿ��ȡǰm�����ͺ�m���ˣ����������˶����Ȼ��Լ���Ǯ��check�Ƿ�С��a
*/
#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <string>
#include <vector>
#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
#define mp          make_pair
#define pb          push_back
#define FIN         freopen("C:\\Users\\Administrator\\Desktop\\Code\\in.txt", "r", stdin)
#define FOUT        freopen("C:\\Users\\Administrator\\Desktop\\Code\\out.txt", "w", stdout)
#define lson        l, mid, cur << 1
#define rson        mid + 1, r, cur << 1 | 1
#define debug       puts("-------------");
#define lowbit(x)   ((x)&(-(x)))
//#pragma comment(linker, "/STACK:1024000000,1024000000")
const int INF = 0x3f3f3f3f;
const LL INFLL = 0x3f3f3f3f3f3f3f3fLL;
const double eps = 1e-8;
const int MOD = 1e9 + 7;
const int MAXN = 1e5 + 50;
const int MAXM = 2e4 + 50;

int n, m, a, b[MAXN], p[MAXN];

bool rent(int m) {
    LL dif = 0;
    for (int i = 0; i < m; i++) {
        int B = b[n - m + i], P = p[i];
        dif += max(0, P - B);
    }
    return dif <= a;
}

int main() {
#ifdef LOCAL_NORTH
    FIN;
#endif // LOCAL_NORTH
    while (~scanf("%d%d%d", &n, &m, &a)) {
        for (int i = 0; i < n; i++)
            scanf("%d", &b[i]);
        for (int i = 0; i < m; i++)
            scanf("%d", &p[i]);
        sort(b, b + n);
        sort(p, p + m);
        int low = 0, high = min(m, n);
        while (low <= high) {
            int mid = (low + high) / 2;
            if (rent(mid))
                low = mid + 1;
            else
                high = mid - 1;
        }
        LL sum = 0;
        for (int i = 0; i < low - 1; i++)
            sum += p[i];
        printf("%d %I64d\n", low - 1, max(0LL, sum - a));
    }
#ifdef LOCAL_NORTH
    cout << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC * 1000 << " ms." << endl;
#endif // LOCAL_NORTH
    return 0;
}


/**/
#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <string>
#include <vector>
#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
#define mp          make_pair
#define pb          push_back
#define FIN         freopen("C:\\Users\\Administrator\\Desktop\\Code\\in.txt", "r", stdin)
#define FOUT        freopen("C:\\Users\\Administrator\\Desktop\\Code\\out.txt", "w", stdout)
#define lson        l, mid, cur << 1
#define rson        mid + 1, r, cur << 1 | 1
#define debug       puts("-------------");
#define lowbit(x)   ((x)&(-(x)))
//#pragma comment(linker, "/STACK:1024000000,1024000000")
const int INF = 0x3f3f3f3f;
const LL INFLL = 0x3f3f3f3f3f3f3f3fLL;
const double eps = 1e-8;
const int MOD = 1e9 + 7;
const int MAXN = 1e5 + 50;
const int MAXM = 2e4 + 50;

int n, m, a, b[MAXN], p[MAXN];

int main() {
#ifdef LOCAL_NORTH
    FIN;
#endif // LOCAL_NORTH
    while (~scanf("%d%d%d", &n, &m, &a)) {
        for (int i = 0; i < n; i++)
            scanf("%d", &b[i]);
        for (int i = 0; i < m; i++)
            scanf("%d", &p[i]);
        sort(b, b + n);
        sort(p, p + m);
        int r = 0;
        LL s = 0, sum1 = 0, sum2 = 0;
        for (int i = 0; i < min(n, m); i++) {
            sum1 += p[i];
            sum2 += b[min(n, m) - 1 - i];
            if (sum1 <= sum2 + a) {
                r = i + 1;
                s = max(sum1 - a, 0LL);
//            printf("[%I64d %I64d]\n", sum1, sum2);
            }
            else
                break;
        }
        printf("%d %I64d\n", r, s);
    }
#ifdef LOCAL_NORTH
    cout << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC * 1000 << " ms." << endl;
#endif // LOCAL_NORTH
    return 0;
}


/**/
#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <string>
#include <vector>
#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
#define mp          make_pair
#define pb          push_back
#define FIN         freopen("C:\\Users\\Administrator\\Desktop\\Code\\in.txt", "r", stdin)
#define FOUT        freopen("C:\\Users\\Administrator\\Desktop\\Code\\out.txt", "w", stdout)
#define lson        l, mid, cur << 1
#define rson        mid + 1, r, cur << 1 | 1
#define debug       puts("-------------");
#define lowbit(x)   ((x)&(-(x)))
//#pragma comment(linker, "/STACK:1024000000,1024000000")
const int INF = 0x3f3f3f3f;
const LL INFLL = 0x3f3f3f3f3f3f3f3fLL;
const double eps = 1e-8;
const int MOD = 1e9 + 7;
const int MAXN = 1e5 + 50;
const int MAXM = 2e4 + 50;

int n, m, a, b[MAXN], p[MAXN];

int solve(int m) {
    bool vis[MAXN] = {false};
    int pos = m - 1, r = 0, s = 0;
    for (int i = n - 1; i >= 0; i--) {
        while (pos >= 0 && p[pos] > b[i]) pos--;
        if (pos >= 0) {
            r++;
            s += p[pos];
            vis[pos] = true;
            pos--;
        } else break;
    }
    int ta = a;
    pos = 0;
    for (int i = 0; i < n && ta > 0; i++) {
        while (pos < m && vis[pos]) pos++;
        if (pos < m) {
            if (p[pos] - b[i] <= ta) {
                ta -= p[pos] - b[i];
                r++;
                s += b[i];
            }
            pos++;
        } else break;
    }
    return r;
}

int main() {
#ifdef LOCAL_NORTH
    FIN;
#endif // LOCAL_NORTH
    while (~scanf("%d%d%d", &n, &m, &a)) {
        for (int i = 0; i < n; i++)
            scanf("%d", &b[i]);
        for (int i = 0; i < m; i++)
            scanf("%d", &p[i]);
        sort(b, b + n);
        sort(p, p + m);
        int r = solve(m);
        int s = 0;
        for (int i = 0; i < r; i++) {
            s += p[i] - min(a, p[i]);
            a -= min(a, p[i]);
        }
        printf("%d %d\n", r, s);
    }
#ifdef LOCAL_NORTH
    cout << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC * 1000 << " ms." << endl;
#endif // LOCAL_NORTH
    return 0;
}


/**/
#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <string>
#include <vector>
#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
#define mp          make_pair
#define pb          push_back
#define FIN         freopen("C:\\Users\\Administrator\\Desktop\\Code\\in.txt", "r", stdin)
#define FOUT        freopen("C:\\Users\\Administrator\\Desktop\\Code\\out.txt", "w", stdout)
#define lson        l, mid, cur << 1
#define rson        mid + 1, r, cur << 1 | 1
#define debug       puts("-------------");
#define lowbit(x)   ((x)&(-(x)))
//#pragma comment(linker, "/STACK:1024000000,1024000000")
const int INF = 0x3f3f3f3f;
const LL INFLL = 0x3f3f3f3f3f3f3f3fLL;
const double eps = 1e-8;
const int MOD = 1e9 + 7;
const int MAXN = 1e5 + 50;
const int MAXM = 2e4 + 50;

int n, m, a, b[MAXN], p[MAXN];

int solve(int m) {
    bool vis[MAXN] = {false};
    int pos = m - 1, r = 0, s = 0;
    for (int i = n - 1; i >= 0; i--) {
        while (pos >= 0 && p[pos] > b[i]) pos--;
        if (pos >= 0) {
            r++;
            s += p[pos];
            vis[pos] = true;
            pos--;
        } else break;
    }
    int ta = a;
    pos = 0;
    for (int i = 0; i < n; i++) {
        while (pos < m && vis[pos]) pos++;
        if (pos < m) {
            if (p[pos] - b[i] <= ta) {
                ta -= p[pos] - b[i];
                r++;
                s += b[i];
            }
            pos++;
        } else break;
    }
    return r;
}

int main() {
#ifdef LOCAL_NORTH
    FIN;
#endif // LOCAL_NORTH
    while (~scanf("%d%d%d", &n, &m, &a)) {
        for (int i = 0; i < n; i++)
            scanf("%d", &b[i]);
        for (int i = 0; i < m; i++)
            scanf("%d", &p[i]);
        sort(b, b + n);
        sort(p, p + m);
        int r = solve(m);
        LL tmp = 0;
        for (int i = 0; i < r; i++)
            tmp += p[i];
        printf("%d %I64d\n", r, max(0LL, tmp - a));
    }
#ifdef LOCAL_NORTH
    cout << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC * 1000 << " ms." << endl;
#endif // LOCAL_NORTH
    return 0;
}


/**/
#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <string>
#include <vector>
#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
#define mp          make_pair
#define pb          push_back
#define FIN         freopen("C:\\Users\\Administrator\\Desktop\\Code\\in.txt", "r", stdin)
#define FOUT        freopen("C:\\Users\\Administrator\\Desktop\\Code\\out.txt", "w", stdout)
#define lson        l, mid, cur << 1
#define rson        mid + 1, r, cur << 1 | 1
#define debug       puts("-------------");
#define lowbit(x)   ((x)&(-(x)))
//#pragma comment(linker, "/STACK:1024000000,1024000000")
const int INF = 0x3f3f3f3f;
const LL INFLL = 0x3f3f3f3f3f3f3f3fLL;
const double eps = 1e-8;
const int MOD = 1e9 + 7;
const int MAXN = 1e5 + 50;
const int MAXM = 2e4 + 50;

int n, m, a, b[MAXN], p[MAXN];

PII solve(int m) {
    bool vis[MAXN] = {false};
    int pos = m - 1, r = 0, s = 0;
    for (int i = n - 1; i >= 0; i--) {
        while (p[pos] > b[i]) pos--;
        if (pos >= 0) {
            r++;
            s += p[pos];
            vis[pos] = true;
            pos--;
        } else break;
    }
//    printf("---[%d %d]\n", r, s);
    int ta = a;
    pos = 0;
    for (int i = 0; i < n && ta > 0; i++) {
        while (vis[pos]) pos++;
        if (pos < m) {
//                printf("--------------%d\n", pos);
            if (p[pos] - b[i] <= ta) {
                ta -= p[pos] - b[i];
                r++;
                s += b[i];
                pos++;
            } else break;
        } else break;
    }
//    printf("+++[%d %d]\n", r, max(s - ta, 0));
    return mp(r, max(s - ta, 0));
}

int main() {
#ifdef LOCAL_NORTH
    FIN;
#endif // LOCAL_NORTH
    while (~scanf("%d%d%d", &n, &m, &a)) {
        for (int i = 0; i < n; i++)
            scanf("%d", &b[i]);
        for (int i = 0; i < m; i++)
            scanf("%d", &p[i]);
        sort(b, b + n);
        sort(p, p + m);
        PII res = solve(m);
        res = solve(res.first);
        printf("%d %d\n", res.first, res.second);
    }
#ifdef LOCAL_NORTH
    cout << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC * 1000 << " ms." << endl;
#endif // LOCAL_NORTH
    return 0;
}


/**/
#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <string>
#include <vector>
#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
#define mp          make_pair
#define pb          push_back
#define FIN         freopen("C:\\Users\\Administrator\\Desktop\\Code\\in.txt", "r", stdin)
#define FOUT        freopen("C:\\Users\\Administrator\\Desktop\\Code\\out.txt", "w", stdout)
#define lson        l, mid, cur << 1
#define rson        mid + 1, r, cur << 1 | 1
#define debug       puts("-------------");
#define lowbit(x)   ((x)&(-(x)))
//#pragma comment(linker, "/STACK:1024000000,1024000000")
const int INF = 0x3f3f3f3f;
const LL INFLL = 0x3f3f3f3f3f3f3f3fLL;
const double eps = 1e-8;
const int MOD = 1e9 + 7;
const int MAXN = 1e5 + 50;
const int MAXM = 2e4 + 50;

int n, m, a, b[MAXN], p[MAXN];

int solve(int m) {
    bool vis1[MAXN] = {false};
    bool vis2[MAXN] = {false};
    int pos = m - 1, r = 0;
    for (int i = n - 1; i >= 0; i--) {
        while (pos >= 0 && p[pos] > b[i]) pos--;
        if (pos >= 0) {
            r++;
            vis1[i] = true;
            vis2[pos] = true;
            pos--;
        } else break;
    }
    int ta = a;
    pos = 0;
    for (int i = 0; i < n; i++) {
        if (vis1[i]) continue;
        while (pos < m && vis2[pos]) pos++;
        if (pos < m) {
            if (p[pos] - b[i] <= ta) {
                ta -= max(p[pos] - b[i], 0);
                r++;
            }
            pos++;
        } else break;
    }
    return r;
}

int main() {
#ifdef LOCAL_NORTH
    FIN;
#endif // LOCAL_NORTH
    while (~scanf("%d%d%d", &n, &m, &a)) {
        for (int i = 0; i < n; i++)
            scanf("%d", &b[i]);
        for (int i = 0; i < m; i++)
            scanf("%d", &p[i]);
        sort(b, b + n);
        sort(p, p + m);
        int r = solve(m);
        LL tmp = 0;
        for (int i = 0; i < r; i++)
            tmp += p[i];
        printf("%d %I64d\n", r, max(0LL, tmp - a));
    }
#ifdef LOCAL_NORTH
    cout << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC * 1000 << " ms." << endl;
#endif // LOCAL_NORTH
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int SIZE=100005;
int n,m,a,q;
int b[SIZE],p[SIZE];
inline bool check(int k)
{
	long long t=0;
	int j=n-k;
	for (int i=0;i<k;i++)
	{
		if (b[j]<p[i])
		{
			t=t+p[i]-b[j];
		}
		j++;
	}
//	cout<<a<<" "<<t<<endl;
	if (a>=t)
	{
		return true;
	}
	else
	{
		return false;
	}

}
int main()
{
	scanf("%d%d%d",&n,&m,&a);
	for (int i=0;i<n;i++)
	{
		scanf("%d",b+i);
	}
	for (int i=0;i<m;i++)
	{
		scanf("%d",p+i);
	}
	sort(b,b+n);
	sort(p,p+m);
	int l=0,r=m;
	long long res=0;
	while(r>=l)
	{
		int mid=(l+r)/2;
//		cout<<mid<<endl;
		if (check(mid)==true)
		{
			l=mid+1;
		}
		else
		{
			r=mid-1;
		}
	}
	l--;
	for (int i=0;i<l;i++)
	{
		res+=p[i];
	}
	res-=a;
	if (res<0)
	{
		res=0;
	}
	printf("%d %d",l,res);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int SIZE=100005;
int n,m,a,q;
int b[SIZE],p[SIZE];
inline bool check(int k)
{
	int t=0;
	int j=n-k;
	for (int i=0;i<k;i++)
	{
		if (b[j]<p[i])
		{
			t=t+p[i]-b[n-k];
		}
		j--;
	}
//	cout<<a<<" "<<t<<endl;
	if (a>=t)
	{
		return true;
	}
	else
	{
		return false;
	}

}
int main()
{
	scanf("%d%d%d",&n,&m,&a);
	for (int i=0;i<n;i++)
	{
		scanf("%d",b+i);
	}
	for (int i=0;i<m;i++)
	{
		scanf("%d",p+i);
	}
	sort(b,b+n);
	sort(p,p+m);
	int l=0,r=m;
	int res=0;
	while(r>=l)
	{
		int mid=(l+r)/2;
//		cout<<mid<<endl;
		if (check(mid)==true)
		{
			l=mid+1;
		}
		else
		{
			r=mid-1;
		}
	}
	l--;
	for (int i=0;i<l;i++)
	{
		res+=p[i];
	}
	res-=a;
	printf("%d %d",l,res);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int SIZE=100005;
int n,m,a,q;
int b[SIZE],p[SIZE];
inline bool check(int k)
{
	long long t=0;
	int j=n-k;
	for (int i=0;i<k;i++)
	{
		if (b[j]<p[i])
		{
			t=t+p[i]-b[j];
		}
		j++;
	}
//	cout<<a<<" "<<t<<endl;
	if (a>=t)
	{
		return true;
	}
	else
	{
		return false;
	}

}
int main()
{
	scanf("%d%d%d",&n,&m,&a);
	for (int i=0;i<n;i++)
	{
		scanf("%d",b+i);
	}
	for (int i=0;i<m;i++)
	{
		scanf("%d",p+i);
	}
	sort(b,b+n);
	sort(p,p+m);
	int l=0,r=n;
	long long res=0;
	while(r>=l)
	{
		int mid=(l+r)/2;
//		cout<<mid<<endl;
		if (check(mid)==true)
		{
			l=mid+1;
		}
		else
		{
			r=mid-1;
		}
	}
	l--;
	for (int i=0;i<l;i++)
	{
		res+=p[i];
	}
	res-=a;
	if (res<0)
	{
		res=0;
	}
	printf("%d %d",l,res);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int SIZE=100005;
int n,m,a,q;
int b[SIZE],p[SIZE];
inline bool check(int k)
{
	long long t=0;
	int j=n-k;
	for (int i=0;i<k;i++)
	{
		if (b[j]<p[i])
		{
			t=t+p[i]-b[j];
		}
		j++;
	}
//	cout<<a<<" "<<t<<endl;
	if (a>=t)
	{
		return true;
	}
	else
	{
		return false;
	}

}
int main()
{
	scanf("%d%d%d",&n,&m,&a);
	for (int i=0;i<n;i++)
	{
		scanf("%d",b+i);
	}
	for (int i=0;i<m;i++)
	{
		scanf("%d",p+i);
	}
	sort(b,b+n);
	sort(p,p+m);
	int l=0,r=m;
	long long res=0;
	while(r>=l)
	{
		int mid=(l+r)/2;
//		cout<<mid<<endl;
		if (check(mid)==true)
		{
			l=mid+1;
		}
		else
		{
			r=mid-1;
		}
	}
	l--;
	for (int i=0;i<l;i++)
	{
		res+=p[i];
	}
	res-=a;
	printf("%d %d",l,res);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int SIZE=100005;
int n,m,a,q;
int b[SIZE],p[SIZE];
inline bool check(int k)
{
	int t=0;
	for (int i=0;i<k;i++)
	{
		if (b[n-k]<p[i])
		{
			t=t+p[i]-b[n-k];
		}
		k--;
	}
//	cout<<a<<" "<<t<<endl;
	if (a>=t)
	{
		return true;
	}
	else
	{
		return false;
	}

}
int main()
{
	scanf("%d%d%d",&n,&m,&a);
	for (int i=0;i<n;i++)
	{
		scanf("%d",b+i);
	}
	for (int i=0;i<m;i++)
	{
		scanf("%d",p+i);
	}
	sort(b,b+n);
	sort(p,p+m);
	int l=0,r=m;
	int res=0;
	while(r>=l)
	{
		int mid=(l+r)/2;
//		cout<<mid<<endl;
		if (check(mid)==true)
		{
			l=mid+1;
		}
		else
		{
			r=mid-1;
		}
	}
	l--;
	for (int i=0;i<l;i++)
	{
		res+=p[i];
	}
	res-=a;
	printf("%d %d",l,res);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int SIZE=100005;
int n,m,a,q;
int b[SIZE],p[SIZE];
inline bool check(int k)
{
	long long t=0;
	int j=n-k;
	for (int i=0;i<k;i++)
	{
		if (b[j]<p[i])
		{
			t=t+p[i]-b[j];
		}
		j++;
	}
//	cout<<a<<" "<<t<<endl;
	if (a>=t)
	{
		return true;
	}
	else
	{
		return false;
	}

}
int main()
{
	scanf("%d%d%d",&n,&m,&a);
	for (int i=0;i<n;i++)
	{
		scanf("%d",b+i);
	}
	for (int i=0;i<m;i++)
	{
		scanf("%d",p+i);
	}
	sort(b,b+n);
	sort(p,p+m);
	int l=0,r=min(n,m);
	long long res=0;
	while(r>=l)
	{
		int mid=(l+r)/2;
//		cout<<mid<<endl;
		if (check(mid)==true)
		{
			l=mid+1;
		}
		else
		{
			r=mid-1;
		}
	}
	l--;
	for (int i=0;i<l;i++)
	{
		res+=p[i];
	}
	res-=a;
	if (res<0)
	{
		res=0;
	}
	printf("%d %d",l,res);
	return 0;
}


#include <bits/stdc++.h>
#define maxn 100000
using namespace std;
int b[maxn],p[maxn];
int n,m,a;
int ans=0;
int main()
{
    cin>>n>>m>>a;
    for(int i=1; i<=n; i++) cin>>b[i];
    for(int i=1; i<=m; i++) cin>>p[i];
    sort(b+1,b+n+1);
    sort(p+1,p+m+1);
    int minn=min(n,m); //人少车多或人多车少
    int l=0,r=minn,mid,now=a;
    while(l<r)
    {
        mid=(l+r)/2;
        int up=n-mid+1;  //有钱人
        for(int i=up; i<=n; i++)
        {
            int diff=p[i-up+1]-b[i]; //最有钱的人租最便宜的车里的最贵的车
            if(diff>0)
              {
                  if(now>=diff) now-=diff;
                  else break;
              }
        }
        if(i==n+1) //完全可以
            l=mid+1;
        else //不可以
            r=mid-1;
    }
    for(int i=1; i<=r; i++) ans+=p[i];
    cout<<r<<" "<<max(0,ans-a)<<endl;
    return 0;
}


#include <bits/stdc++.h>
#define maxn 100000
using namespace std;
int b[maxn],p[maxn];
int n,m,a;
int ans=0;
int main()
{
    cin>>n>>m>>a;
    for(int i=1; i<=n; i++) cin>>b[i];
    for(int i=1; i<=m; i++) cin>>p[i];
    sort(b+1,b+n+1);
    sort(p+1,p+m+1);
    int minn=min(n,m); //人少车多或人多车少
    int l=0,r=minn,mid,now=a;
    while(l<r)
    {
        mid=(l+r)/2;
        int up=n-mid+1;  //有钱人
        int i;
        for(i=up; i<=n; i++)
        {
            int diff=p[i-up+1]-b[i]; //最有钱的人租最便宜的车里的最贵的车
            if(diff>0)
              {
                  if(now>=diff) now-=diff;
                  else break;
              }
        }
        if(i==n+1) //完全可以
            l=mid+1;
        else //不可以
            r=mid-1;
    }
    for(int i=1; i<=r; i++) ans+=p[i];
    cout<<r<<" "<<max(0,ans-a)<<endl;
    return 0;
}


#include <bits/stdc++.h>
#define maxn 100000
using namespace std;
int b[maxn],p[maxn];
int n,m,a;
int ans=0;
int main()
{
    cin>>n>>m>>a;
    for(int i=1; i<=n; i++) cin>>b[i];
    for(int i=1; i<=m; i++) cin>>p[i];
    sort(b+1,b+n+1);
    sort(p+1,p+m+1);
    int minn=min(n,m); //人少车多或人多车少
    int l=0,r=minn,mid;
    while(l<=r)
    {
        int now=a;
        mid=(l+r)/2;
        int up=n-mid+1;  //有钱人
        int i;
        for(i=up; i<=n; i++)
        {
            int diff=p[i-up+1]-b[i]; //最有钱的人租最便宜的车里的最贵的车
            if(diff>0)
            {
                if(now>=diff) now-=diff;
                else break;
            }
        }
        if(i==n+1) //完全可以
            l=mid+1;
        else //不可以
            r=mid-1;
    }
    for(int i=1; i<=r; i++) ans+=p[i];
    cout<<r<<" "<<max(0,ans-a)<<endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std ;
int a[100005] , money , b[100005] ;
int n , m ;
bool check(int k){
    if(!k)return true ;
    int x = money ;
    for(int i = 0 , j = 0 ; i < n && j < m ; ){
        if(!k)return true ;
        if(a[i] >= b[j]){
            k-- ;
            i ++ ;
            j ++ ;
        }
        else if(a[i] + x >= b[j]){
            k -- ;
            i ++ ;
            j ++ ;
            x -= b[j-1] - a[i-1] ;
        }
        else i++ ;
    }
    if(!k)return true ;
    return false ;
}
int solve(int k){
    if(!k)return 0 ;
    int x = money ;
    int ans = 0 ;
    for(int i = 0 , j = 0 ; i < n && j < m ; ){
        if(!k)return ans - money ;
        if(a[i] >= b[j]){
            k-- ;
            ans += b[j] ;
            i ++ ;
            j ++ ;
        }
        else if(a[i] + x >= b[j]){
            k -- ;
            ans += b[j] ;
            i ++ ;
            j ++ ;
            x -= b[j-1] - a[i-1] ;
        }
        else i++ ;
    }
    return ans - money ;
}
int main(){
    scanf("%d%d%d",&n,&m,&money) ;
    for(int i = 0 ;i < n ; i++)scanf("%d",&a[i]) ;
    for(int i = 0 ;i < m ; i++)scanf("%d",&b[i]) ;
    sort(a,a+n) ;
    sort(b,b+m) ;
    int lo = 0 , hi = n ;
    while(lo < hi){
        int mid = (lo+hi)/2 ;
        if(check(mid))lo = mid + 1 ;
        else hi = mid ;
    }
    if(!check(lo))lo-- ;
    int ans = solve(lo) ;
    cout << lo << " " << ans ;
    return 0 ;
}


#include <bits/stdc++.h>
using namespace std ;
int a[100005] , money , b[100005] ;
int n , m ;
bool check(int k){
    if(!k)return true ;
    int x = money ;
    for(int i = n - k , j = 0 ; i < n && j < m ;i++,j++){
        if(a[i] >= b[j])continue ;
        if(a[i]+x >= b[j]){
            x -= b[j]-a[i] ;
            continue ;
        }
        return false ;
    }
    return true ;
}
int solve(int k){
    int x = money ;
    int ans = 0 ;
    for(int i = n - k , j = 0 ; i < n && j < m ;i++,j++ ){
        if(a[i] >= b[j]){
            ans += b[j] ;
            continue ;
        }
        if(a[i]+x >= b[j]){
            x -= b[j]-a[i] ;
            ans += b[j] ;
            continue ;
        }
    }
    return max(0,ans - money) ;
}
int main(){
    scanf("%d%d%d",&n,&m,&money) ;
    for(int i = 0 ;i < n ; i++)scanf("%d",&a[i]) ;
    for(int i = 0 ;i < m ; i++)scanf("%d",&b[i]) ;
    sort(a,a+n) ;
    sort(b,b+m) ;
    int lo = 0 , hi = min(m,n) ;
    while(lo < hi){
        int mid = (lo+hi)/2 ;
        if(check(mid))lo = mid + 1 ;
        else hi = mid ;
    }
    if(!check(lo))lo--;
    int ans = solve(lo) ;
    cout << lo << " " << ans ;
    return 0 ;
}


#include <bits/stdc++.h>
using namespace std ;
int a[100005] , money , b[100005] ;
int n , m ;
bool check(int k){
    if(!k)return true ;
    int x = money ;
    for(int i = n - k , j = 0 ; i < n && j < m ;i++,j++ ){
        if(a[i] >= b[j])continue ;
        if(a[i]+x >= b[j]){
            x -= b[j]-a[i] ;
            continue ;
        }
        return false ;
    }
    return true ;
}
int solve(int k){
    int x = money ;
    int ans = 0 ;
    for(int i = n - k , j = 0 ; i < n && j < m ;i++,j++ ){
        if(a[i] >= b[j]){
            ans += b[j] ;
            continue ;
        }
        if(a[i]+x >= b[j]){
            x -= b[j]-a[i] ;
            ans += b[j] ;
            continue ;
        }
    }
    return max(0,ans - money) ;
}
int main(){
    scanf("%d%d%d",&n,&m,&money) ;
    for(int i = 0 ;i < n ; i++)scanf("%d",&a[i]) ;
    for(int i = 0 ;i < m ; i++)scanf("%d",&b[i]) ;
    sort(a,a+n) ;
    sort(b,b+m) ;
    int lo = 0 , hi = m ;
    while(lo < hi){
        int mid = (lo+hi)/2 ;
        if(check(mid))lo = mid + 1 ;
        else hi = mid ;
    }
    if(!check(lo))lo--;
    int ans = solve(lo) ;
    cout << lo << " " << ans ;
    return 0 ;
}


#include <bits/stdc++.h>
using namespace std ;
int a[100005] , money , b[100005] ;
int n , m ;
bool check(int k){
    if(!k)return true ;
    int x = money ;
    for(int i = 0 , j = 0 ; i < n && j < m ; ){
        if(!k)return true ;
        if(a[i] >= b[j]){
            k-- ;
            i ++ ;
            j ++ ;
        }
        else if(a[i] + x >= b[j]){
            k -- ;
            i ++ ;
            j ++ ;
            x -= b[j-1] - a[i-1] ;
        }
        else i++ ;
    }
    if(!k)return true ;
    return false ;
}
int solve(int k){
    if(!k)return 0 ;
    int x = money ;
    int ans = 0 ;
    for(int i = 0 , j = 0 ; i < n && j < m ; ){
        if(!k)return max(0,ans - money) ;
        if(a[i] >= b[j]){
            k-- ;
            ans += b[j] ;
            i ++ ;
            j ++ ;
        }
        else if(a[i] + x >= b[j]){
            k -- ;
            ans += b[j] ;
            i ++ ;
            j ++ ;
            x -= b[j-1] - a[i-1] ;
        }
        else i++ ;
    }
    return max(0,ans - money) ;
}
int main(){
    scanf("%d%d%d",&n,&m,&money) ;
    for(int i = 0 ;i < n ; i++)scanf("%d",&a[i]) ;
    for(int i = 0 ;i < m ; i++)scanf("%d",&b[i]) ;
    sort(a,a+n) ;
    sort(b,b+m) ;
    int lo = 0 , hi = n ;
    while(lo < hi){
        int mid = (lo+hi)/2 ;
        if(check(mid))lo = mid + 1 ;
        else hi = mid ;
    }
    if(!check(lo))lo-- ;
    int ans = solve(lo) ;
    cout << lo << " " << ans ;
    return 0 ;
}


#include <iostream>
#include <algorithm>
using namespace std;
int n,m,a;
int human[100001];
int bikes[100001];
bool check(int x){
	int budg = a;
	int j=x-1;
	for(int i=n-1;i>n-1-x;i--){
		if(human[i]<bikes[j]){
			if(budg-(bikes[j]-human[i])<0)
				return false;
			budg-=bikes[j]-human[i];
		}
		j--;
	}
	return true;
}
int money(int x){
	int budg = a,antibudg=0,rash=0;
	int j=x-1;
	for(int i=n-1;i>n-1-x;i--){
		if(human[i]<bikes[j]){
			budg-=bikes[j]-human[i];
			antibudg+=bikes[j]-human[i];
			rash+=human[i];
		}
		else
			rash+=bikes[j];
		j--;
	}
	return max(0,rash-max(0,budg));
}
int bin(int l, int r){
	if(r-l<=1)
		return r;
	else{
		int m = (l+r)/2;
		if(check(m))
			return bin(m,r);
		else
			return bin(l,m);
	}
}
int main(){
	cin >> n >> m >> a;
	for(int i=0;i<n;i++)
		cin >> human[i];
	for(int i=0;i<m;i++)
		cin >> bikes[i];
	sort(human,human+n);
	sort(bikes,bikes+m);
	int res = bin(1,min(n,m));
	if(!check(res))
		res--;
	cout << res << " " << money(res);
	return 0;
}


#include <iostream>
#include <algorithm>
using namespace std;
int n,m,a;
int human[100001];
int bikes[100001];
bool check(int x){
	int budg = a;
	int j=x;
	for(int i=n-1;i>n-1-x;i--){
		if(human[i]<bikes[j]){
			if(budg-(bikes[j]-human[i])<0)
				return false;
			budg-=bikes[j]-human[i];
		}
		j--;
	}
	return true;
}
int money(int x){
	int budg = a,antibudg=0,rash=0;
	int j=x;
	for(int i=n-1;i>n-1-x;i--){
		if(human[i]<bikes[j]){
			budg-=bikes[j]-human[i];
			antibudg+=bikes[j]-human[i];
			rash+=human[i];
		}
		else
			rash+=bikes[i];
		j--;
	}
	return max(0,rash-max(0,budg));
}
int bin(int l, int r){
	if(r-l<=1)
		return r;
	else{
		int m = (l+r)/2;
		if(check(m))
			return bin(m,r);
		else
			return bin(l,m);
	}
}
int main(){
	cin >> n >> m >> a;
	for(int i=0;i<n;i++)
		cin >> human[i];
	for(int i=0;i<m;i++)
		cin >> bikes[i];
	sort(human,human+n);
	sort(bikes,bikes+m);
	int res = bin(1,n);
	cout << res << " " << money(res)-1;
	return 0;
}


#include <iostream>
#include <algorithm>
using namespace std;
int n,m,a;
int human[100001];
int bikes[100001];
bool check(int x){
	int budg = a;
	int j=x-1;
	for(int i=n-1;i>n-1-x;i--){
		if(human[i]<bikes[j]){
			if(budg-(bikes[j]-human[i])<0)
				return false;
			budg-=bikes[j]-human[i];
		}
		j--;
	}
	return true;
}
int money(int x){
	int budg = a,antibudg=0,rash=0;
	int j=x-1;
	for(int i=n-1;i>n-1-x;i--){
		if(human[i]<bikes[j]){
			budg-=bikes[j]-human[i];
			antibudg+=bikes[j]-human[i];
			rash+=human[i];
		}
		else
			rash+=bikes[j];
		j--;
	}
	return max(0,rash-max(0,budg));
}
int bin(int l, int r){
	if(r-l<=1)
		return r;
	else{
		int m = (l+r)/2;
		if(check(m))
			return bin(m,r);
		else
			return bin(l,m);
	}
}
int main(){
	cin >> n >> m >> a;
	for(int i=0;i<n;i++)
		cin >> human[i];
	for(int i=0;i<m;i++)
		cin >> bikes[i];
	sort(human,human+n);
	sort(bikes,bikes+m);
	int res = bin(0,min(n,m));
	if(!check(res))
		res--;
	cout << res << " " << money(res);
	return 0;
}


#include <iostream>
#include <algorithm>
using namespace std;
int n,m,a;
int human[100001];
int bikes[100001];
bool check(int x){
	int budg = a;
	int j=x-1;
	for(int i=n-1;i>n-1-x;i--){
		if(human[i]<bikes[j]){
			if(budg-(bikes[j]-human[i])<0)
				return false;
			budg-=bikes[j]-human[i];
		}
		j--;
	}
	return true;
}
int money(int x){
	int budg = a,antibudg=0,rash=0;
	int j=x-1;
	for(int i=n-1;i>n-1-x;i--){
		if(human[i]<bikes[j]){
			budg-=bikes[j]-human[i];
			antibudg+=bikes[j]-human[i];
			rash+=human[i];
		}
		else
			rash+=bikes[j];
		j--;
	}
	return max(0,rash-max(0,budg));
}
int bin(int l, int r){
	if(r-l<=1)
		return r;
	else{
		int m = (l+r)/2;
		if(check(m))
			return bin(m,r);
		else
			return bin(l,m);
	}
}
int main(){
	cin >> n >> m >> a;
	for(int i=0;i<n;i++)
		cin >> human[i];
	for(int i=0;i<m;i++)
		cin >> bikes[i];
	sort(human,human+n);
	sort(bikes,bikes+m);
	int res = bin(1,n);
	if(!check(res))
		res--;
	cout << res << " " << money(res);
	return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

typedef long long ll;
using namespace std;
using namespace __gnu_pbds;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define all(x) x.begin(), x.end()
#define f(i,a,b) for(int i = (a); i <= (b); i++)
#define fd(i,a,b) for(int i = (a); i >= (b); i--)
#define mp make_pair
#define faster_io() ios_base::sync_with_stdio(false)
#define pb push_back
#define pii pair<int,int>
#define SZ(x) ((int)x.size())
#define vii vector<pair<int,int>>

const int INF = 1000000002;
const ll INFLL = 100000000000000000ll;
const ll MOD = 1000000007;

// ----------------------------------------------------------------------------------------------------------

int A[100005], B[100005], N, K, X, Spend;

bool ok(int x)
{
    int need = 0, spend = 0;
    int id = K, bike = x;
    while(bike >= 1)
    {
        int diff = max(A[bike] - B[id], 0);
        need += diff;
        spend += A[bike];
        bike--, id--;
    }
    if(need > X) return false;
    spend -= X;
    Spend = spend;
    return true;
}

int main()
{
    cin >> K >> N >> X;
    f(i,1,K) scanf("%d", &B[i]);
    f(i,1,N) scanf("%d", &A[i]);
    sort(A+1,A+N+1);
    sort(B+1,B+K+1);

    int a = 0, b = K;
    while(b-a > 1)
    {
        int p = (a+b) / 2;
        if(ok(p)) a = p;
        else b = p;
    }
    if(ok(b)) cout << b << " " << Spend;
    else if(ok(a)) cout << a << " " << Spend;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

typedef long long ll;
using namespace std;
using namespace __gnu_pbds;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define all(x) x.begin(), x.end()
#define f(i,a,b) for(ll i = (a); i <= (b); i++)
#define fd(i,a,b) for(ll i = (a); i >= (b); i--)
#define mp make_pair
#define faster_io() ios_base::sync_with_stdio(false)
#define pb push_back
#define pii pair<ll,ll>
#define SZ(x) ((ll)x.size())
#define vii vector<pair<ll,ll>>

const ll INF = 1000000002;
const ll INFLL = 100000000000000000ll;
const ll MOD = 1000000007;

// ----------------------------------------------------------------------------------------------------------

ll A[100005], B[100005], N, K, X, Spend;

bool ok(ll x)
{
    ll need = 0, spend = 0;
    ll id = K, bike = x;
    while(bike >= 1)
    {
        ll diff = max(A[bike] - B[id], 0ll);
        need += diff;
        spend += A[bike];
        bike--, id--;
    }
    if(need > X) return false;
    spend -= X;
    Spend = spend;
    return true;
}

int main()
{
    cin >> K >> N >> X;
    f(i,1,K) scanf("%I64d", &B[i]);
    f(i,1,N) scanf("%I64d", &A[i]);
    sort(A+1,A+N+1);
    sort(B+1,B+K+1);

    ll a = 0, b = K;
    while(b-a > 1)
    {
        ll p = (a+b) / 2;
        if(ok(p)) a = p;
        else b = p;
    }
    if(ok(b)) cout << b << " " << Spend;
    else if(ok(a)) cout << a << " " << Spend;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

typedef long long ll;
using namespace std;
using namespace __gnu_pbds;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define all(x) x.begin(), x.end()
#define f(i,a,b) for(ll i = (a); i <= (b); i++)
#define fd(i,a,b) for(ll i = (a); i >= (b); i--)
#define mp make_pair
#define faster_io() ios_base::sync_with_stdio(false)
#define pb push_back
#define pii pair<ll,ll>
#define SZ(x) ((ll)x.size())
#define vii vector<pair<ll,ll>>

const ll INF = 1000000002;
const ll INFLL = 100000000000000000ll;
const ll MOD = 1000000007;

// ----------------------------------------------------------------------------------------------------------

ll A[100005], B[100005], N, K, X, Spend;

bool ok(ll x)
{
    ll need = 0, spend = 0;
    ll id = K, bike = x;
    while(bike >= 1)
    {
        ll diff = max(A[bike] - B[id], 0ll);
        need += diff;
        spend += A[bike];
        bike--, id--;
    }
    if(need > X) return false;
    spend -= X;
    Spend = max(spend,0ll);
    return true;
}

int main()
{
    cin >> K >> N >> X;
    f(i,1,K) scanf("%I64d", &B[i]);
    f(i,1,N) scanf("%I64d", &A[i]);
    sort(A+1,A+N+1);
    sort(B+1,B+K+1);

    ll a = 0, b = min(K,N);
    while(b-a > 1)
    {
        ll p = (a+b) / 2;
        if(ok(p)) a = p;
        else b = p;
    }
    if(ok(b)) cout << b << " " << Spend;
    else if(ok(a)) cout << a << " " << Spend;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

typedef long long ll;
using namespace std;
using namespace __gnu_pbds;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define all(x) x.begin(), x.end()
#define f(i,a,b) for(ll i = (a); i <= (b); i++)
#define fd(i,a,b) for(ll i = (a); i >= (b); i--)
#define mp make_pair
#define faster_io() ios_base::sync_with_stdio(false)
#define pb push_back
#define pii pair<ll,ll>
#define SZ(x) ((ll)x.size())
#define vii vector<pair<ll,ll>>

const ll INF = 1000000002;
const ll INFLL = 100000000000000000ll;
const ll MOD = 1000000007;

// ----------------------------------------------------------------------------------------------------------

ll A[100005], B[100005], N, K, X, Spend;

bool ok(ll x)
{
    ll need = 0, spend = 0;
    ll id = K, bike = x;
    while(bike >= 1)
    {
        ll diff = max(A[bike] - B[id], 0ll);
        need += diff;
        spend += A[bike];
        bike--, id--;
    }
    if(need > X) return false;
    spend -= X;
    Spend = max(spend,0ll);
    return true;
}

int main()
{
    cin >> K >> N >> X;
    f(i,1,K) scanf("%I64d", &B[i]);
    f(i,1,N) scanf("%I64d", &A[i]);
    sort(A+1,A+N+1);
    sort(B+1,B+K+1);

    ll a = 0, b = K;
    while(b-a > 1)
    {
        ll p = (a+b) / 2;
        if(ok(p)) a = p;
        else b = p;
    }
    if(ok(b)) cout << b << " " << Spend;
    else if(ok(a)) cout << a << " " << Spend;
}


#include <stdio.h>
#include <vector>
#include <string>
#include <algorithm>
#include <string.h>
//#include <conio.h>
#include <map>
#include <fstream>
#include <cmath>
#include <math.h>
#include <queue>
#include <bitset>
#include <stack>
#include <iostream>
#include <set>
#include <time.h>
#include <functional>

#define mp(x,y) make_pair(x,y)
#define mp3(x,y, z) mp(mp(x,y),z)
#define mp4(a,b,c,d) mp(mp(a, b) , mp( c, d))
#define pb(x) push_back(x)
#define mx2(x,y) ( (x) > (y) ? (x) : (y) )
#define mx4(a,b,x,y) (mx2(mx2(a,b),mx2(x,y)))
#define mn2(x,y) ( (x) < (y) ? (x) : (y) )
#define mn4(x,y) (mn2(mn2(a,b),mn2(x,y)))
#define mod 1000000007
#define maxn 100001
using namespace std;

typedef long long int lint;
typedef long double ld;

lint n, m, a;
lint b[maxn];
lint p[maxn];
lint s[maxn];

bool control(lint j)
{
	lint l = 0;
	lint para = a;
	lint top = 0;
	for (lint i = max(0LL, n - j); i < n; i++, l++)
		para -= max(0LL, p[l] - b[i]), top += p[l];

	if (para >= 0)
		return true;
	return false;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin >> n >> m >> a;
	for (int i = 0; i < n; i++)
		cin >> b[i];
	for (int i = 0; i < m; i++)
		cin >> p[i];

	sort(b, b + n);
	sort(p, p + m);

	lint aa = 0, bb = m;
	while (aa < bb)
	{
		lint k = (aa + bb + 1) / 2;
		if (control(k))
			aa = k;
		else
			bb = k - 1;
	}

	lint c = 0;
	lint l = 0;
	lint para = a;
	lint j = aa;
	lint top = 0;
	for (lint i = max(0LL, n - j); i < n; i++, l++)
		para -= max(0LL, p[l] - b[i]), top += p[l];

	c = max(0LL, top - a);
	cout << aa << " " << c << endl;

	return 0;
}


#include <stdio.h>
#include <vector>
#include <string>
#include <algorithm>
#include <string.h>
//#include <conio.h>
#include <map>
#include <fstream>
#include <cmath>
#include <math.h>
#include <queue>
#include <bitset>
#include <stack>
#include <iostream>
#include <set>
#include <time.h>
#include <functional>

#define mp(x,y) make_pair(x,y)
#define mp3(x,y, z) mp(mp(x,y),z)
#define mp4(a,b,c,d) mp(mp(a, b) , mp( c, d))
#define pb(x) push_back(x)
#define mx2(x,y) ( (x) > (y) ? (x) : (y) )
#define mx4(a,b,x,y) (mx2(mx2(a,b),mx2(x,y)))
#define mn2(x,y) ( (x) < (y) ? (x) : (y) )
#define mn4(x,y) (mn2(mn2(a,b),mn2(x,y)))
#define mod 1000000007
#define maxn 100001
using namespace std;

typedef long long int lint;
typedef long double ld;

lint n, m, a;
lint b[maxn];
lint p[maxn];
lint s[maxn];

bool control(lint j)
{
	lint l = 0;
	lint para = a;
	lint top = 0;
	for (lint i = max(0LL, n - j); i < n; i++, l++)
		para -= max(0LL, p[l] - b[i]), top += p[l];

	if (para >= 0)
		return true;
	return false;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin >> n >> m >> a;
	for (int i = 0; i < n; i++)
		cin >> b[i];
	for (int i = 0; i < m; i++)
		cin >> p[i];

	sort(b, b + n);
	sort(p, p + m);

	lint aa = 0, bb = min(m, n);
	while (aa < bb)
	{
		lint k = (aa + bb + 1) / 2;
		if (control(k))
			aa = k;
		else
			bb = k - 1;
	}

	lint c = 0;
	lint l = 0;
	lint para = a;
	lint j = aa;
	lint top = 0;
	for (lint i = max(0LL, n - j); i < n; i++, l++)
		para -= max(0LL, p[l] - b[i]), top += p[l];

	c = max(0LL, top - a);
	cout << aa << " " << c << endl;

	return 0;
}


#include <stdio.h>
#include <vector>
#include <string>
#include <algorithm>
#include <string.h>
//#include <conio.h>
#include <map>
#include <fstream>
#include <cmath>
#include <math.h>
#include <queue>
#include <bitset>
#include <stack>
#include <iostream>
#include <set>
#include <time.h>
#include <functional>

#define mp(x,y) make_pair(x,y)
#define mp3(x,y, z) mp(mp(x,y),z)
#define mp4(a,b,c,d) mp(mp(a, b) , mp( c, d))
#define pb(x) push_back(x)
#define mx2(x,y) ( (x) > (y) ? (x) : (y) )
#define mx4(a,b,x,y) (mx2(mx2(a,b),mx2(x,y)))
#define mn2(x,y) ( (x) < (y) ? (x) : (y) )
#define mn4(x,y) (mn2(mn2(a,b),mn2(x,y)))
#define mod 1000000007
#define maxn 100001
using namespace std;

typedef long long int lint;
typedef long double ld;

lint n, m, a;
lint b[maxn];
lint p[maxn];

int main()
{
	cin >> n >> m >> a;
	for (int i = 0; i < n; i++)
		cin >> b[i];
	for (int i = 0; i < m; i++)
		cin >> p[i];

	sort(b, b + n);
	sort(p, p + m);

	lint s = 0;
	lint c = 0;
	for (lint j = 0; j < m; j++)
	{
		lint l = 0;
		lint para = a;
		lint top = 0;
		for (lint i = max(0LL, n - j - 1); i < n; i++, l++)
			para -= max(0LL, p[l] - b[i]),  top += p[l];

		if (para >= 0)
		{
			if (s < min(n, j + 1))
			{
				s = min(n, j + 1);
				c = max(0LL,top - a);
			}
			else if (s == min(n, j + 1))
				c = min(c, max(0LL, top - a));
		}
	}
	cout << s << " " << c << endl;

	return 0;
}


#include <stdio.h>
#include <vector>
#include <string>
#include <algorithm>
#include <string.h>
//#include <conio.h>
#include <map>
#include <fstream>
#include <cmath>
#include <math.h>
#include <queue>
#include <bitset>
#include <stack>
#include <iostream>
#include <set>
#include <time.h>
#include <functional>

#define mp(x,y) make_pair(x,y)
#define mp3(x,y, z) mp(mp(x,y),z)
#define mp4(a,b,c,d) mp(mp(a, b) , mp( c, d))
#define pb(x) push_back(x)
#define mx2(x,y) ( (x) > (y) ? (x) : (y) )
#define mx4(a,b,x,y) (mx2(mx2(a,b),mx2(x,y)))
#define mn2(x,y) ( (x) < (y) ? (x) : (y) )
#define mn4(x,y) (mn2(mn2(a,b),mn2(x,y)))
#define mod 1000000007
#define maxn 100001
using namespace std;

typedef long long int lint;
typedef long double ld;

int n, m, a;
int b[maxn];
int p[maxn];

int main()
{
	cin >> n >> m >> a;
	for (int i = 0; i < n; i++)
		cin >> b[i];
	for (int i = 0; i < m; i++)
		cin >> p[i];

	sort(b, b + n);
	sort(p, p + m);

	int s = 0;
	int c = 0;
	for (int j = 0; j < m; j++)
	{
		int l = 0;
		int para = a;
		int top = 0;
		for (int i = max(0, n - j - 1); i < n; i++, l++)
			para -= max(0, p[l] - b[i]),  top += p[l];

		if (para >= 0)
		{
			if (s <= min(n, j + 1))
			{
				s = min(n, j + 1);
				c = top - a;
			}
		}
	}
	cout << s << " " << c << endl;
 	return 0;
}


#include <stdio.h>
#include <vector>
#include <string>
#include <algorithm>
#include <string.h>
//#include <conio.h>
#include <map>
#include <fstream>
#include <cmath>
#include <math.h>
#include <queue>
#include <bitset>
#include <stack>
#include <iostream>
#include <set>
#include <time.h>
#include <functional>

#define mp(x,y) make_pair(x,y)
#define mp3(x,y, z) mp(mp(x,y),z)
#define mp4(a,b,c,d) mp(mp(a, b) , mp( c, d))
#define pb(x) push_back(x)
#define mx2(x,y) ( (x) > (y) ? (x) : (y) )
#define mx4(a,b,x,y) (mx2(mx2(a,b),mx2(x,y)))
#define mn2(x,y) ( (x) < (y) ? (x) : (y) )
#define mn4(x,y) (mn2(mn2(a,b),mn2(x,y)))
#define mod 1000000007
#define maxn 100001
using namespace std;

typedef long long int lint;
typedef long double ld;

lint n, m, a;
lint b[maxn];
lint p[maxn];

int main()
{
	cin >> n >> m >> a;
	for (int i = 0; i < n; i++)
		cin >> b[i];
	for (int i = 0; i < m; i++)
		cin >> p[i];

	sort(b, b + n);
	sort(p, p + m);

	lint s = 0;
	lint c = 0;
	for (lint j = 0; j < m; j++)
	{
		lint l = 0;
		lint para = a;
		lint top = 0;
		for (lint i = max(0LL, n - j - 1); i < n; i++, l++)
			para -= max(0LL, p[l] - b[i]),  top += p[l];

		if (para >= 0)
		{
			if (s <= min(n, j + 1))
			{
				s = min(n, j + 1);
				c = top - a;
			}
		}
	}
	cout << s << " " << c << endl;
 	return 0;
}


#include <stdio.h>
#include <vector>
#include <string>
#include <algorithm>
#include <string.h>
//#include <conio.h>
#include <map>
#include <fstream>
#include <cmath>
#include <math.h>
#include <queue>
#include <bitset>
#include <stack>
#include <iostream>
#include <set>
#include <time.h>
#include <functional>

#define mp(x,y) make_pair(x,y)
#define mp3(x,y, z) mp(mp(x,y),z)
#define mp4(a,b,c,d) mp(mp(a, b) , mp( c, d))
#define pb(x) push_back(x)
#define mx2(x,y) ( (x) > (y) ? (x) : (y) )
#define mx4(a,b,x,y) (mx2(mx2(a,b),mx2(x,y)))
#define mn2(x,y) ( (x) < (y) ? (x) : (y) )
#define mn4(x,y) (mn2(mn2(a,b),mn2(x,y)))
#define mod 1000000007
#define maxn 100001
using namespace std;

typedef long long int lint;
typedef long double ld;

lint n, m, a;
lint b[maxn];
lint p[maxn];

int main()
{
	ios_base::sync_with_stdio(false);
	cin >> n >> m >> a;
	for (int i = 0; i < n; i++)
		cin >> b[i];
	for (int i = 0; i < m; i++)
		cin >> p[i];

	sort(b, b + n);
	sort(p, p + m);

	lint s = 0;
	lint c = 0;
	for (lint j = 0; j < m; j++)
	{
		lint l = 0;
		lint para = a;
		lint top = 0;
		for (lint i = max(0LL, n - j - 1); i < n; i++, l++)
			para -= max(0LL, p[l] - b[i]),  top += p[l];

		if (para >= 0)
		{
			if (s < min(n, j + 1))
			{
				s = min(n, j + 1);
				c = max(0LL,top - a);
			}
			else if (s == min(n, j + 1))
				c = min(c, max(0LL, top - a));
		}
	}
	cout << s << " " << c << endl;

	return 0;
}


#include <stdio.h>
#include <vector>
#include <string>
#include <algorithm>
#include <string.h>
//#include <conio.h>
#include <map>
#include <fstream>
#include <cmath>
#include <math.h>
#include <queue>
#include <bitset>
#include <stack>
#include <iostream>
#include <set>
#include <time.h>
#include <functional>

#define mp(x,y) make_pair(x,y)
#define mp3(x,y, z) mp(mp(x,y),z)
#define mp4(a,b,c,d) mp(mp(a, b) , mp( c, d))
#define pb(x) push_back(x)
#define mx2(x,y) ( (x) > (y) ? (x) : (y) )
#define mx4(a,b,x,y) (mx2(mx2(a,b),mx2(x,y)))
#define mn2(x,y) ( (x) < (y) ? (x) : (y) )
#define mn4(x,y) (mn2(mn2(a,b),mn2(x,y)))
#define mod 1000000007
#define maxn 100001
using namespace std;

typedef long long int lint;
typedef long double ld;

lint n, m, a;
lint b[maxn];
lint p[maxn];

int main()
{
	cin >> n >> m >> a;
	for (int i = 0; i < n; i++)
		cin >> b[i];
	for (int i = 0; i < m; i++)
		cin >> p[i];

	sort(b, b + n);
	sort(p, p + m);

	lint s = 0;
	lint c = 0;
	for (lint j = 0; j < m; j++)
	{
		lint l = 0;
		lint para = a;
		lint top = 0;
		for (lint i = max(0LL, n - j - 1); i < n; i++, l++)
			para -= max(0LL, p[l] - b[i]),  top += p[l];

		if (para >= 0)
		{
			if (s <= min(n, j + 1))
			{
				s = min(n, j + 1);
				c = max(0,top - a);
			}
		}
	}
	cout << s << " " << c << endl;

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const double eps = 1e-6;
#define con continue
#define bk break
#define LL long long
#define db double
#define pt cout<<'\n'
#define ms(a, b) memset((a), (b), sizeof(a))
#define mp make_pair
#define endl '\n'
int inf=2147483647;const long long ll =9223372036854775807,ninf=947483647;
#define sz size()
#define len(X) strlen(X)
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define ac fstream cin("input.txt");ofstream cout("output.txt");
#define ULL unsigned long long
int A[100005]={};
int B[100005]={};
int main()
{
    int a,b,c;
    while(cin>>a>>b>>c){
        for(int i=0;i<a;i++)
            cin>>A[i];
        for(int i=0;i<b;i++)
            cin>>B[i];
        sort(A,A+a);
        sort(B,B+b);
        int L=1,R=a;
        int maxr1=0,maxr2=0;
        while(L<=R){
            int no=0;
            int mid=(L+R)/2;
        int l=a-mid,r=0;
        int now=c;
        int ans1=0,ans2=0;
        while(1){
            if(A[l]+now>=B[r]){
                ans1++;
                if(A[l]>=B[r]){
                    ans2+=B[r];
                }
                else{
                    int tmp=B[r]-A[l];
                    now-=tmp;
                    ans2+=A[l];
                }
                l++;
                r++;
            }
            else{
                l++;
                no=1;
            }
            if(l==a||r==b){
                bk;
            }
        }

        if(!no){
               L=mid+1;
        }
        else{
               R=mid-1;
        }
            if(ans1>maxr1||ans1==maxr1&&maxr2>ans2-now){
               maxr1=ans1;
        maxr2=max(0,ans2-now);
            }

        }
        cout<<maxr1<<" "<<maxr2<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const double eps = 1e-6;
#define con continue
#define bk break
#define LL long long
#define db double
#define pt cout<<'\n'
#define ms(a, b) memset((a), (b), sizeof(a))
#define mp make_pair
#define endl '\n'
int inf=2147483647;const long long ll =9223372036854775807,ninf=947483647;
#define sz size()
#define len(X) strlen(X)
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define ac fstream cin("input.txt");ofstream cout("output.txt");
#define ULL unsigned long long
int A[100005]={};
int B[100005]={};
int main()
{
    int a,b,c;
    while(cin>>a>>b>>c){
        for(int i=0;i<a;i++)
            cin>>A[i];
        for(int i=0;i<b;i++)
            cin>>B[i];
        sort(A,A+a);
        sort(B,B+b);
        int l=0,r=0;
        int now=c;
        int ans1=0,ans2=0;
        while(1){
            if(A[l]+now>=B[r]){
                ans1++;
                if(A[l]>=B[r]){
                    ans2+=B[r];
                }
                else{
                    int tmp=B[r]-A[l];
                    now-=tmp;
                    ans2+=A[l];
                }
                l++;
                r++;
            }
            else{
                l++;
            }
            if(l==a||r==b){
                bk;
            }
        }
        cout<<ans1<<" "<<max(0,ans2-now)<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const double eps = 1e-6;
#define con continue
#define bk break
#define LL long long
#define db double
#define pt cout<<'\n'
#define ms(a, b) memset((a), (b), sizeof(a))
#define mp make_pair
#define endl '\n'
int inf=2147483647;const long long ll =9223372036854775807,ninf=947483647;
#define sz size()
#define len(X) strlen(X)
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define ac fstream cin("input.txt");ofstream cout("output.txt");
#define ULL unsigned long long
int A[100005]={};
int B[100005]={};
int main()
{
    int a,b,c;
    while(cin>>a>>b>>c){
        for(int i=0;i<a;i++)
            cin>>A[i];
        for(int i=0;i<b;i++)
            cin>>B[i];
        sort(A,A+a);
        sort(B,B+b);
        int L=1,R=a;
        int maxr1=0,maxr2=0;
        while(L<=R){
            int mid=(L+R)/2;
        int l=a-mid,r=0;
        int now=c;
        int ans1=0,ans2=0;
        while(1){
            if(A[l]+now>=B[r]){
                ans1++;
                if(A[l]>=B[r]){
                    ans2+=B[r];
                }
                else{
                    int tmp=B[r]-A[l];
                    now-=tmp;
                    ans2+=A[l];
                }
                l++;
                r++;
            }
            else{
                l++;
            }
            if(l==a||r==b){
                bk;
            }
        }

        if(r==b){
        R=mid-1;
        }
        else{
            L=mid+1;
        }
            if(ans1>maxr1||ans1==maxr1&&maxr2>ans2-now){
               maxr1=ans1;
        maxr2=max(0,ans2-now);
            }

        }
        cout<<maxr1<<" "<<maxr2<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const double eps = 1e-6;
#define con continue
#define bk break
#define LL long long
#define db double
#define pt cout<<'\n'
#define ms(a, b) memset((a), (b), sizeof(a))
#define mp make_pair
#define endl '\n'
int inf=2147483647;const long long ll =9223372036854775807,ninf=947483647;
#define sz size()
#define len(X) strlen(X)
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define ac fstream cin("input.txt");ofstream cout("output.txt");
#define ULL unsigned long long
int A[100005]={};
int B[100005]={};
int main()
{
    int a,b,c;
    while(cin>>a>>b>>c){
        for(int i=0;i<a;i++)
            cin>>A[i];
        for(int i=0;i<b;i++)
            cin>>B[i];
        sort(A,A+a);
        sort(B,B+b);
        int L=0,R=a;
        int maxr1=0,maxr2=0;
        while(L<=R){
            int mid=(L+R)/2;
        int l=a-mid,r=0;
        int now=c;
        int ans1=0,ans2=0;
        while(1){
            if(A[l]+now>=B[r]){
                ans1++;
                if(A[l]>=B[r]){
                    ans2+=B[r];
                }
                else{
                    int tmp=B[r]-A[l];
                    now-=tmp;
                    ans2+=A[l];
                }
                l++;
                r++;
            }
            else{
                l++;
            }
            if(l==a||r==b){
                bk;
            }
        }

        if(r==b){
        R=mid-1;
        }
        else{
            L=mid+1;
        }
            if(ans1>maxr1||ans1==maxr1&&maxr2>ans2-now){
               maxr1=ans1;
        maxr2=ans2-now;
            }

        }
        cout<<maxr1<<" "<<maxr2<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const double eps = 1e-6;
#define con continue
#define bk break
#define LL long long
#define db double
#define pt cout<<'\n'
#define ms(a, b) memset((a), (b), sizeof(a))
#define mp make_pair
#define endl '\n'
int inf=2147483647;const long long ll =9223372036854775807,ninf=947483647;
#define sz size()
#define len(X) strlen(X)
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define ac fstream cin("input.txt");ofstream cout("output.txt");
#define ULL unsigned long long
int A[100005]={};
int B[100005]={};
int main()
{
    int a,b,c;
    while(cin>>a>>b>>c){
        for(int i=0;i<a;i++)
            cin>>A[i];
        for(int i=0;i<b;i++)
            cin>>B[i];
        sort(A,A+a);
        sort(B,B+b);
        int l=max(0,a-b),r=0;
        int now=c;
        int ans1=0,ans2=0;
        while(1){
            if(A[l]+now>=B[r]){
                ans1++;
                if(A[l]>=B[r]){
                    ans2+=B[r];
                }
                else{
                    int tmp=B[r]-A[l];
                    now-=tmp;
                    ans2+=A[l];
                }
                l++;
                r++;
            }
            else{
                l++;
            }
            if(l==a||r==b){
                bk;
            }
        }
        cout<<ans1<<" "<<max(0,ans2-now)<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const double eps = 1e-6;
#define con continue
#define bk break
#define LL long long
#define db double
#define pt cout<<'\n'
#define ms(a, b) memset((a), (b), sizeof(a))
#define mp make_pair
#define endl '\n'
int inf=2147483647;const long long ll =9223372036854775807,ninf=947483647;
#define sz size()
#define len(X) strlen(X)
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define ac fstream cin("input.txt");ofstream cout("output.txt");
#define ULL unsigned long long
int A[100005]={};
int B[100005]={};
int main()
{
    int a,b,c;
    while(cin>>a>>b>>c){
        for(int i=0;i<a;i++)
            cin>>A[i];
        for(int i=0;i<b;i++)
            cin>>B[i];
        sort(A,A+a);
        sort(B,B+b);
        int L=1,R=a;
        int maxr1=0,maxr2=0;
        while(L<=R){
            int mid=(L+R)/2;
        int l=a-mid,r=0;
        int now=c;
        int ans1=0,ans2=0;
        while(1){
            if(A[l]+now>=B[r]){
                ans1++;
                if(A[l]>=B[r]){
                    ans2+=B[r];
                }
                else{
                    int tmp=B[r]-A[l];
                    now-=tmp;
                    ans2+=A[l];
                }
                l++;
                r++;
            }
            else{
                l++;
            }
            if(l==a||r==b){
                bk;
            }
        }

        if(r==b){
        R=mid-1;
        }
        else{
            L=mid+1;
        }
            if(ans1>maxr1||ans1==maxr1&&maxr2>ans2-now){
               maxr1=ans1;
        maxr2=ans2-now;
            }

        }
        cout<<maxr1<<" "<<maxr2<<endl;
    }
    return 0;
}


#include <iostream>
#include <algorithm>
using namespace std;
int n,m,all;
int a[100010]={0},b[100010]={0};
bool check(int x)
{
	int t=all;
	for (int i=0;i<x;i++) if (a[i]<b[i]) t-=b[i]-a[i];
	if (t<0) return 0;
	return 1;
}
int main()
{
	cin >>n>>m>>all;
	for (int i=0;i<n;i++) cin >>a[i];
	for (int i=0;i<m;i++) cin >>b[i];
	sort(a,a+n);
	reverse(a,a+n);
	sort(b,b+m);
	int l=0,r=m;
	while (r-l>1)
	{
		int mid=(l+r)/2+1;
		if (!check(mid)) r=mid;
		else l=mid;
	}
	cout <<r<<" ";
	long long tap=0;
	for (int i=0;i<r;i++) tap+=b[i];
	tap-=all;
	if (tap<0) tap=0;
	cout <<tap;
	return 0;
}


#include <iostream>
#include <algorithm>
using namespace std;
int n,m,all;
int a[100010]={0},b[100010]={0};
bool check(int x)
{
	if (x>n) return 0;
	int t=all;
	for (int i=0;i<x;i++)
	{
		if (a[n-i-1]<b[i]) t-=b[i]-a[n-i-1];
		if (t<0) return 0;
	}
	return 1;
}
int main()
{
	cin >>n>>m>>all;
	for (int i=0;i<n;i++) cin >>a[i];
	for (int i=0;i<m;i++) cin >>b[i];
	sort(a,a+n);
	sort(b,b+m);
	int l=0,r=m;
	while (r-l>1)
	{
		int mid=(l+r)/2+1;
		if (!check(mid)) r=mid;
		else l=mid;
	}
	cout <<r<<" ";
	long long tap=0;
	for (int i=0;i<r;i++) tap+=b[i];
	tap-=all;
	if (tap<0) tap=0;
	cout <<tap;
	return 0;
}


#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <cmath>
#include <algorithm>
#include <map>
#include <sstream>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <functional>
#include <utility>
#include <stdio.h>
#define ll long long
#define MP make_pair
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define PLI pair<ll, int>
#define PIL pair<int, ll>
#define F first
#define S second
#define SHN 1e9
#define LSHN 1e18
using namespace std;
ll n,m,k;
ll a[100010],b[100010];
ll r1,r2;
ll l,r,mid;
bool check()
{
	ll t=k,sum=0;
	for (int i=0;i<mid;i++)
	{
		if (a[n-mid+i]<b[i]) t-=b[i]-a[n-mid+i];
		sum+=min(a[n-mid+i],b[i]);
	}
	sum-=t;
	if (t>=0)
	{
		r1=mid;
		r2=max(sum,(ll)0);
		return 1;
	}
	return 0;
}
int main()
{
	cin >>n>>m>>k;
	for (int i=0;i<n;i++) cin >>a[i];
	for (int i=0;i<m;i++) cin >>b[i];
	sort(a,a+n);
	sort(b,b+m);
	l=0,r=min(n,m);
	while (l<=r)
	{
		mid=(l+r)/2;
		if (check()) l=mid+1;
		else r=mid-1;
	}
	cout <<r1<<" "<<r2;
	return 0;
}


#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <cmath>
#include <algorithm>
#include <map>
#include <sstream>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <functional>
#include <utility>
#include <stdio.h>
#define ll long long
#define MP make_pair
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define PLI pair<ll, int>
#define PIL pair<int, ll>
#define F first
#define S second
#define SHN 1e9
#define LSHN 1e18
using namespace std;
ll n,m,k;
ll a[100010],b[100010];
ll l,r,mid;
int main()
{
	cin >>n>>m>>k;
	for (int i=0;i<n;i++) cin >>a[i];
	for (int i=0;i<m;i++) cin >>b[i];
	sort(a,a+n);
	reverse(a,a+n);
	sort(b,b+m);
	l=-1,r=min(n,m);
	while (l<r-1)
	{
		mid=(l+r)>>1;
		ll sum=0;
		for (int i=0;i<=mid;i++) sum+=max((ll)0,b[mid-i]-a[i]);
		//cout <<l<<" "<<r<<" "<<mid<<" "<<sum<<" ##\n";
		if (sum<=k) l=mid;
		else r=mid;
	}
	cout <<l+1<<" ";
	ll sum=0;
	for (int i=0;i<=l;i++) sum+=b[i];
	cout <<max((ll)0,sum-k);
	return 0;
}


#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <cmath>
#include <algorithm>
#include <map>
#include <sstream>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <functional>
#include <utility>
#include <stdio.h>
#define ll long long
#define MP make_pair
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define PLI pair<ll, int>
#define PIL pair<int, ll>
#define F first
#define S second
#define SHN 1e9
#define LSHN 1e18
using namespace std;
ll n,m,k;
ll l,r,mid;
ll res;
ll a[100010],b[100010];
bool check()
{
	ll t=0;
	for (int i=n-mid;i<n;i++)
	{
		int j=i-(n-mid);
		if (a[i]<b[j]) t+=b[j]-a[i];
	}
	return t<=k;
}
int main()
{
	cin >>n>>m>>k;
	for (int i=0;i<n;i++) cin >>a[i];
	for (int i=0;i<m;i++) cin >>b[i];
	sort(a,a+n);
	sort(b,b+m);
	l=0,r=min(n,m)+1;
	while (l<r-1)
	{
		mid=(l+r)/2;
		if (check()) l=mid;
		else r=mid;
	}
	cout <<l<<" ";
	for (int i=0;i<l;i++) res+=b[i];
	cout <<max((ll)0,res-k);
	return 0;
}