#include <bits/stdc++.h>

using namespace std;

#define IO ios_base::sync_with_stdio(0);cin.tie(0);

int main()
{
  IO;
	long long n, m, a0; cin >> n >> m >> a0;
	vector <long long> b(n), p(m);
	for (int i = 0; i < n; ++i) cin >> b[i];
	for (int i = 0; i < m; ++i) cin >> p[i];
	sort(b.begin(), b.end());
	sort(p.begin(), p.end());

	long long lower = 0, upper = min(m + 1, n + 1);
 	while (upper - lower > 1) {
		long long a = a0;
		long long mid = (lower + upper) / 2;
		long long res = 0;
		for (int i = n - mid; i < n; ++i) {
			res += min(b[i], p[i - (n - mid)]);
			a -= max(0, p[i - (n - mid)] - b[i]);
		}
		if (a >= 0)
			lower = mid;
		else upper = mid;
	}
	long long s = 0;
	for (int i = 0; i < lower; ++i) {
		s += min(b[i], p[i]);
		a0 -= max(0, p[i] - b[i]);
	}
	s -= a0;
	cout << lower << " " << max(0, s) << endl;

  return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define IO ios_base::sync_with_stdio(0);cin.tie(0);

int main()
{
  IO;
	int n, m, a0; cin >> n >> m >> a0;
	vector <int> b(n), p(m);
	for (int i = 0; i < n; ++i) cin >> b[i];
	for (int i = 0; i < m; ++i) cin >> p[i];
	sort(b.begin(), b.end());
	sort(p.begin(), p.end());

	int lower = 0, upper = min(m + 1, n + 1);
 	while (upper - lower > 1) {
		int a = a0;
		int mid = (lower + upper) / 2;
		int res = 0;
		for (int i = n - mid; i < n; ++i) {
			res += min(b[i], p[i - (n - mid)]);
			a -= max(0, p[i - (n - mid)] - b[i]);
		}
		if (a >= 0)
			lower = mid;
		else upper = mid;
	}
	int s = 0;
	for (int i = 0; i < lower; ++i) {
		s += min(b[i], p[i]);
		a0 -= max(0, p[i] - b[i]);
	}
	s -= a0;
	cout << lower << " " << max(0, s) << endl;

  return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define IO ios_base::sync_with_stdio(0);cin.tie(0);

bool cmp (pair <int, int> a, pair <int, int> b) {
	return (max(0, a.second - a.first) < max(0, b.second - b.first)) ||
				 (max(0, a.second - a.first) == max(0, b.second - b.first) && a.second < b.second);
}

int main()
{
  IO;
	int n, m, a0; cin >> n >> m >> a0;
	vector <int> b(n), p(m);
	for (int i = 0; i < n; ++i) cin >> b[i];
	for (int i = 0; i < m; ++i) cin >> p[i];
	sort(b.begin(), b.end());
	sort(p.begin(), p.end());

	int lower = 0, upper = min(m + 1, n + 1);
 	while (upper - lower > 1) {
		int a = a0;
		int mid = (lower + upper) / 2;
		int res = 0;
		for (int i = n - mid; i < n; ++i) {
			res += min(b[i], p[i - (n - mid)]);
			a -= max(0, p[i - (n - mid)] - b[i]);
		}
		if (a >= 0)
			lower = mid;
		else upper = mid;
	}
	int s = 0;
	for (int i = 0; i < lower; ++i) {
		s += min(b[i], p[i]);
		a0 -= max(0, p[i] - b[i]);
	}
	s -= a0;
	cout << lower << " " << s << endl;

  return 0;
}


#include <iostream>
#include <queue>
#include <map>
#include <deque>
#include <algorithm>
#include <set>
#include <string>
#include <math.h>
#include <stdio.h>
#include <iomanip>
#include <cstring>
#include <climits>
#include <iostream>
#include <time.h>
#include <stack>
using namespace std;

#define ll long long
#define p 1000000007
#define INF LONG_LONG_MAX
#define pi 3.14159265359
/*

std::map<ll,ll>::iterator lessthan(map<ll,ll> &mp, ll k){

    std::map<ll,ll>::iterator it = mp.lower_bound(k);
    if(it != mp.begin()) {
        return --it;
    }
    return mp.end();
}
ll factorial(ll n)
{
    if (n == 1 || n == 0)
        return 1;
    return  n * factorial(n - 1);
}

//matrix exp

struct Matrix
{
    vector< vector<ll> > mat; // the contents of matrix as a 2D-vector
    int n_rows, n_cols; // number of rows and columns

    Matrix(vector< vector<ll> > values): mat(values), n_rows(values.size()),
        n_cols(values[0].size()) {}

    static Matrix identity_matrix(int n)
    {
        // Return I_n - the identity matrix of size n.
        // This function is static, because it creates a new Matrix instance
        vector< vector<ll> > values(n, vector<ll>(n, 0));
        for(int i = 0; i < n; i++)
            values[i][i] = 1;
        return values;
    }

    Matrix operator*(const Matrix &other) const
    {
        int n = n_rows, m = other.n_cols;
        vector< vector<ll> > result(n_rows, vector<ll>(m, 0));
        for(int i = 0; i < n; i++)
            for(int j = 0; j < m; j++) {
                for(int k = 0; k < n_cols; k++) {
                    result[i][j] = (result[i][j] + mat[i][k] * 1ll * other.mat[k][j]) % p;
                }
            }
        // Multiply matrices as usual, then return the result as the new Matrix
        return Matrix(result);
    }

    inline bool is_square() const
    {
        return n_rows == n_cols;
    }
};

Matrix fast_exponentiation(Matrix m, ll power)
{
    Matrix result = Matrix::identity_matrix(m.n_rows);

    while(power) {
        if(power & 1)
            result = result * m;
        m = m * m;
        power >>= 1;
    }

    return result;
}
*/

/*
set<ll> seen;
priority_queue<pair<ll,ll> >unseen;
vector<ll> distance;
ll dijstra(ll root)
{
    unseen.push(make_pair(0, root));
    while (!unseen.empty())
    {
        pair<ll,ll> nxt = unseen.pop();
        if (seen.count(nxt.second) != 0)
            continue;
        seen.insert(nxt.second);
        distance[nxt.second] = nxt.first;
        for (int i = 0; i < adj[nxt.second].size(); i++)
        {
            if (seen.count(adj[nxt.second][i]) == 0)
            {
                ll curr = adj[nxt.second][i];
                unseen.push(make_pair(distance[nxt.second] + weights[nxt.second][i], curr));
            }
        }
    }
}*/
vector<vector<ll> > adj;
vector<int>curr;
vector<int> goal;
vector<ll> changedNodes;
ll bfs(ll node, ll parent, ll even, ll odd, ll turn)
{
    ll ans = 0;
    if (turn % 2 == 0)
    {
        if (((curr[node] + even) % 2) != goal[node]){
            even++;
            ans++;
            changedNodes.push_back(node);
        }
    }
    else
    {
        if (((curr[node] + odd) % 2) != goal[node]){
            odd++;
            ans++;
            changedNodes.push_back(node);

        }
    }
    if (adj[node].size() == 1 && node != 0)
        return ans;

    for (ll i = 0; i < adj[node].size(); i++)
    {
        ll curr = adj[node][i];
        if (curr != parent)
        {
            ans += bfs(curr, node, even, odd, turn+1);
        }
    }
    return ans;
}

vector<ll> bikes;
vector<ll> pockets;
pair<ll, ll> binSearch(ll low , ll high, ll budget)
{
    pair<ll,ll> pr = make_pair(0,0);
    while (low <= high)
    {
        ll mid = (high + low) / 2;

        pair<ll,ll> curr;
        ll currbug = budget;
        for (ll i = 0; i < mid; i++)
        {
            if (pockets[i] + currbug < bikes[mid - i - 1])
                break;
            else
            {
                curr.first++;
                curr.second += min(bikes[mid - i - 1],pockets[i]);
                if (pockets[i] < bikes[mid - i - 1]) {
                    currbug -= (bikes[mid - i - 1] - pockets[i]);
                }
            }
        }
        if (curr.first == mid){
            low = mid + 1;
            if (currbug > 0)
                curr.second = max((ll)0 , curr.second - currbug);
            pr = curr;
        }
        else
            high = mid -  1;
    }
    return pr;
}
int main()
{
       // freopen("input.txt","r",stdin);
      //  freopen("output.txt","w",stdout);
  //  ios_base::sync_with_stdio(false);
    //cin.tie(NULL);
    ll n, m ,a;
    cin >> n >> m >> a;
    bikes.resize(m);
    pockets.resize(n);
    for (ll i = 0; i < n; i++)
        cin >> pockets[i];

    for (ll i = 0; i < m; i++)
        cin >> bikes[i];

    sort(bikes.begin(), bikes.end());
    sort(pockets.begin(), pockets.end(),greater<int>());

    pair <ll,ll> ans = binSearch(1, min(n, m), a);
    cout << ans.first << ' ' << ans.second;
                /*std::cout<<std::fixed;
        std::cout<<std::setprecision(9)<<dp[w][b];*/

    return 0;
}


#include <iostream>
#include <queue>
#include <map>
#include <deque>
#include <algorithm>
#include <set>
#include <string>
#include <math.h>
#include <stdio.h>
#include <iomanip>
#include <cstring>
#include <climits>
#include <iostream>
#include <time.h>
#include <stack>
using namespace std;

#define ll long long
#define p 1000000007
#define INF LONG_LONG_MAX
#define pi 3.14159265359
/*

std::map<ll,ll>::iterator lessthan(map<ll,ll> &mp, ll k){

    std::map<ll,ll>::iterator it = mp.lower_bound(k);
    if(it != mp.begin()) {
        return --it;
    }
    return mp.end();
}
ll factorial(ll n)
{
    if (n == 1 || n == 0)
        return 1;
    return  n * factorial(n - 1);
}

//matrix exp

struct Matrix
{
    vector< vector<ll> > mat; // the contents of matrix as a 2D-vector
    int n_rows, n_cols; // number of rows and columns

    Matrix(vector< vector<ll> > values): mat(values), n_rows(values.size()),
        n_cols(values[0].size()) {}

    static Matrix identity_matrix(int n)
    {
        // Return I_n - the identity matrix of size n.
        // This function is static, because it creates a new Matrix instance
        vector< vector<ll> > values(n, vector<ll>(n, 0));
        for(int i = 0; i < n; i++)
            values[i][i] = 1;
        return values;
    }

    Matrix operator*(const Matrix &other) const
    {
        int n = n_rows, m = other.n_cols;
        vector< vector<ll> > result(n_rows, vector<ll>(m, 0));
        for(int i = 0; i < n; i++)
            for(int j = 0; j < m; j++) {
                for(int k = 0; k < n_cols; k++) {
                    result[i][j] = (result[i][j] + mat[i][k] * 1ll * other.mat[k][j]) % p;
                }
            }
        // Multiply matrices as usual, then return the result as the new Matrix
        return Matrix(result);
    }

    inline bool is_square() const
    {
        return n_rows == n_cols;
    }
};

Matrix fast_exponentiation(Matrix m, ll power)
{
    Matrix result = Matrix::identity_matrix(m.n_rows);

    while(power) {
        if(power & 1)
            result = result * m;
        m = m * m;
        power >>= 1;
    }

    return result;
}
*/

/*
set<ll> seen;
priority_queue<pair<ll,ll> >unseen;
vector<ll> distance;
ll dijstra(ll root)
{
    unseen.push(make_pair(0, root));
    while (!unseen.empty())
    {
        pair<ll,ll> nxt = unseen.pop();
        if (seen.count(nxt.second) != 0)
            continue;
        seen.insert(nxt.second);
        distance[nxt.second] = nxt.first;
        for (int i = 0; i < adj[nxt.second].size(); i++)
        {
            if (seen.count(adj[nxt.second][i]) == 0)
            {
                ll curr = adj[nxt.second][i];
                unseen.push(make_pair(distance[nxt.second] + weights[nxt.second][i], curr));
            }
        }
    }
}*/
vector<vector<ll> > adj;
vector<int>curr;
vector<int> goal;
vector<ll> changedNodes;
ll bfs(ll node, ll parent, ll even, ll odd, ll turn)
{
    ll ans = 0;
    if (turn % 2 == 0)
    {
        if (((curr[node] + even) % 2) != goal[node]){
            even++;
            ans++;
            changedNodes.push_back(node);
        }
    }
    else
    {
        if (((curr[node] + odd) % 2) != goal[node]){
            odd++;
            ans++;
            changedNodes.push_back(node);

        }
    }
    if (adj[node].size() == 1 && node != 0)
        return ans;

    for (ll i = 0; i < adj[node].size(); i++)
    {
        ll curr = adj[node][i];
        if (curr != parent)
        {
            ans += bfs(curr, node, even, odd, turn+1);
        }
    }
    return ans;
}

vector<ll> bikes;
vector<ll> pockets;
pair<ll, ll> binSearch(ll low , ll high, ll budget)
{
    pair<ll,ll> pr = make_pair(0,0);
    while (low <= high)
    {
        ll mid = (high + low) / 2;

        pair<ll,ll> curr;
        ll currbug = budget;
        for (ll i = 0; i < mid; i++)
        {
            if (pockets[i] + currbug < bikes[mid - i - 1])
                break;
            else
            {
                curr.first++;
                curr.second += min(bikes[mid - i - 1],pockets[i]);
                if (pockets[i] < bikes[mid - i - 1]) {
                    currbug -= (bikes[mid - i - 1] - pockets[i]);
                }
            }
        }
        if (curr.first == mid){
            low = mid + 1;
            if (currbug > 0)
                curr.second -= currbug;
            pr = curr;
        }
        else
            high = mid -  1;
    }
    return pr;
}
int main()
{
       // freopen("input.txt","r",stdin);
      //  freopen("output.txt","w",stdout);
  //  ios_base::sync_with_stdio(false);
    //cin.tie(NULL);
    ll n, m ,a;
    cin >> n >> m >> a;
    bikes.resize(m);
    pockets.resize(n);
    for (ll i = 0; i < n; i++)
        cin >> pockets[i];

    for (ll i = 0; i < m; i++)
        cin >> bikes[i];

    sort(bikes.begin(), bikes.end());
    sort(pockets.begin(), pockets.end(),greater<int>());

    pair <ll,ll> ans = binSearch(1, min(n, m), a);
    cout << ans.first << ' ' << ans.second;
                /*std::cout<<std::fixed;
        std::cout<<std::setprecision(9)<<dp[w][b];*/

    return 0;
}


#include <iostream>
#include <queue>
#include <map>
#include <deque>
#include <algorithm>
#include <set>
#include <string>
#include <math.h>
#include <stdio.h>
#include <iomanip>
#include <cstring>
#include <climits>
#include <iostream>
#include <time.h>
#include <stack>
using namespace std;

#define ll long long
#define p 1000000007
#define INF LONG_LONG_MAX
#define pi 3.14159265359
/*

std::map<ll,ll>::iterator lessthan(map<ll,ll> &mp, ll k){

    std::map<ll,ll>::iterator it = mp.lower_bound(k);
    if(it != mp.begin()) {
        return --it;
    }
    return mp.end();
}
ll factorial(ll n)
{
    if (n == 1 || n == 0)
        return 1;
    return  n * factorial(n - 1);
}

//matrix exp

struct Matrix
{
    vector< vector<ll> > mat; // the contents of matrix as a 2D-vector
    int n_rows, n_cols; // number of rows and columns

    Matrix(vector< vector<ll> > values): mat(values), n_rows(values.size()),
        n_cols(values[0].size()) {}

    static Matrix identity_matrix(int n)
    {
        // Return I_n - the identity matrix of size n.
        // This function is static, because it creates a new Matrix instance
        vector< vector<ll> > values(n, vector<ll>(n, 0));
        for(int i = 0; i < n; i++)
            values[i][i] = 1;
        return values;
    }

    Matrix operator*(const Matrix &other) const
    {
        int n = n_rows, m = other.n_cols;
        vector< vector<ll> > result(n_rows, vector<ll>(m, 0));
        for(int i = 0; i < n; i++)
            for(int j = 0; j < m; j++) {
                for(int k = 0; k < n_cols; k++) {
                    result[i][j] = (result[i][j] + mat[i][k] * 1ll * other.mat[k][j]) % p;
                }
            }
        // Multiply matrices as usual, then return the result as the new Matrix
        return Matrix(result);
    }

    inline bool is_square() const
    {
        return n_rows == n_cols;
    }
};

Matrix fast_exponentiation(Matrix m, ll power)
{
    Matrix result = Matrix::identity_matrix(m.n_rows);

    while(power) {
        if(power & 1)
            result = result * m;
        m = m * m;
        power >>= 1;
    }

    return result;
}
*/

/*
set<ll> seen;
priority_queue<pair<ll,ll> >unseen;
vector<ll> distance;
ll dijstra(ll root)
{
    unseen.push(make_pair(0, root));
    while (!unseen.empty())
    {
        pair<ll,ll> nxt = unseen.pop();
        if (seen.count(nxt.second) != 0)
            continue;
        seen.insert(nxt.second);
        distance[nxt.second] = nxt.first;
        for (int i = 0; i < adj[nxt.second].size(); i++)
        {
            if (seen.count(adj[nxt.second][i]) == 0)
            {
                ll curr = adj[nxt.second][i];
                unseen.push(make_pair(distance[nxt.second] + weights[nxt.second][i], curr));
            }
        }
    }
}*/
vector<vector<ll> > adj;
vector<int>curr;
vector<int> goal;
vector<ll> changedNodes;
ll bfs(ll node, ll parent, ll even, ll odd, ll turn)
{
    ll ans = 0;
    if (turn % 2 == 0)
    {
        if (((curr[node] + even) % 2) != goal[node]){
            even++;
            ans++;
            changedNodes.push_back(node);
        }
    }
    else
    {
        if (((curr[node] + odd) % 2) != goal[node]){
            odd++;
            ans++;
            changedNodes.push_back(node);

        }
    }
    if (adj[node].size() == 1 && node != 0)
        return ans;

    for (ll i = 0; i < adj[node].size(); i++)
    {
        ll curr = adj[node][i];
        if (curr != parent)
        {
            ans += bfs(curr, node, even, odd, turn+1);
        }
    }
    return ans;
}

vector<ll> bikes;
vector<ll> pockets;
pair<ll, ll> binSearch(ll low , ll high, ll budget)
{
    pair<ll,ll> pr = make_pair(0,0);
    while (low <= high)
    {
        ll mid = (high + low) / 2;

        if (budget + pockets[mid - 1] >= bikes[mid - 1]){
            pr = make_pair(mid, max((ll)0, bikes[mid - 1] - budget));
            low = mid + 1;
           // cout << pr.first << ' ' << pr.second << '\n';
        }
        else
            high = mid - 1;
    }
    return pr;
}
int main()
{
       // freopen("input.txt","r",stdin);
      //  freopen("output.txt","w",stdout);
  //  ios_base::sync_with_stdio(false);
    //cin.tie(NULL);
    ll n, m ,a;
    cin >> n >> m >> a;
    bikes.resize(m);
    pockets.resize(n);
    for (ll i = 0; i < n; i++)
        cin >> pockets[i];

    for (ll i = 0; i < m; i++)
        cin >> bikes[i];

    sort(bikes.begin(), bikes.end());
    sort(pockets.begin(), pockets.end(),greater<int>());

    for (ll i = 1; i < n; i++)
        pockets[i] += pockets[i - 1];
    for (ll i = 1 ; i < m; i++)
        bikes[i] += bikes[i - 1];

    pair <ll,ll> ans = binSearch(1, min(n, m), a);
    cout << ans.first << ' ' << ans.second;
                /*std::cout<<std::fixed;
        std::cout<<std::setprecision(9)<<dp[w][b];*/

    return 0;
}


/*
~Like a small boat
~On the ocean
~Sending big waves
~Into motion
!Like how a single word
!Can make a heart open
!I might only have one match
!But I can make an explosion
#And all those things I didn't say
#Wrecking balls inside my brain
#I will scream them loud tonight
#Can you hear my voice this time?
@This is my fight song
@Take back my life song
@Prove I'm alright song
@My power's turned on
$Starting right now I'll be strong
$I'll play my fight song
$And I don't really care if nobody else believes
$'Cause I've still got a lot of fight left in me!!!
*/

#include "bits/stdc++.h"
using namespace std;

#define  F  first
#define  S  second
#define  mp make_pair
#define  pb push_back
typedef long long int ll;
const int N = 1e5+5,mod = 1e9+7;
int Brr[N],Prr[N],m,n,a;

bool Ok( int x )
{
    ll now = 0;
    for(int i=1;i<=n;i++)
    {
        if( Prr[i]>Brr[n-x+i]&&Brr[n-x+i] )
            now += Prr[i]-Brr[n-x+i];
    }
    return now<=a;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    cin>>n>>m>>a;
    for(int i=1;i<=n;i++)
        cin>>Brr[i];
    for(int i=1;i<=m;i++)
        cin>>Prr[i];
    sort(Brr+1,Brr+n+1);
    sort(Prr+1,Prr+m+1);
    int hi = min(n,m);
    int lo = 0,mid,mx = 0;
    while(lo<=hi)
    {
        mid = (lo+hi)>>1;
        if( Ok(mid) )mx = mid,lo = mid+1;
        else hi = mid-1;
    }
    cout<<mx<< " ";
    ll now = 0;
    for(int i=1;i<=mx;i++)
        now += Prr[i];
    if( now>=a )now -= a;
    else now = 0;
    cout<<now<< "\n";

    return 0;
}


/*
~Like a small boat
~On the ocean
~Sending big waves
~Into motion
!Like how a single word
!Can make a heart open
!I might only have one match
!But I can make an explosion
#And all those things I didn't say
#Wrecking balls inside my brain
#I will scream them loud tonight
#Can you hear my voice this time?
@This is my fight song
@Take back my life song
@Prove I'm alright song
@My power's turned on
$Starting right now I'll be strong
$I'll play my fight song
$And I don't really care if nobody else believes
$'Cause I've still got a lot of fight left in me!!!
*/

#include "bits/stdc++.h"
using namespace std;

#define  F  first
#define  S  second
#define  mp make_pair
#define  pb push_back
typedef long long int ll;
const int N = 2e5+5,mod = 1e9+7;
int Brr[N],Prr[N],m,n,a;

bool Ok( int x )
{
    ll now = 0;
    for(int i=1;i<=n;i++)
    {
        if( Prr[i]>Brr[n-x+i]&&Brr[n-x+i] )
            now += Prr[i]-Brr[n-x+i];
    }
    return now<=a;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    cin>>n>>m>>a;
    for(int i=1;i<=n;i++)
        cin>>Brr[i];
    for(int i=1;i<=m;i++)
        cin>>Prr[i];
    sort(Brr+1,Brr+n+1);
    sort(Prr+1,Prr+m+1);
    int hi = min(n,m);
    int lo = 1,mid,mx = 0;
    while(lo<=hi)
    {
        mid = (lo+hi)>>1;
        if( Ok(mid) )mx = mid,lo = mid+1;
        else hi = mid-1;
    }
    cout<<mx<< " ";
    ll now = 0;
    for(int i=1;i<=mx;i++)
        now += Prr[i];
    if( now>=a )now -= a;
    else now = 0;
    cout<<now<< "\n";

    return 0;
}


/*
~Like a small boat
~On the ocean
~Sending big waves
~Into motion
!Like how a single word
!Can make a heart open
!I might only have one match
!But I can make an explosion
#And all those things I didn't say
#Wrecking balls inside my brain
#I will scream them loud tonight
#Can you hear my voice this time?
@This is my fight song
@Take back my life song
@Prove I'm alright song
@My power's turned on
$Starting right now I'll be strong
$I'll play my fight song
$And I don't really care if nobody else believes
$'Cause I've still got a lot of fight left in me!!!
*/

#include "bits/stdc++.h"
using namespace std;

#define  F  first
#define  S  second
#define  mp make_pair
#define  pb push_back
typedef long long int ll;
const int N = 1e5+5,mod = 1e9+7;
int Brr[N],Prr[N],m,n,a;

bool Ok( int x )
{
    ll now = 0;
    for(int i=1;i<=n;i++)
    {
        if( Prr[i]>Brr[n-x+i]&&Brr[n-x+i] )
            now += Prr[i]-Brr[n-x+i];
    }
    return now<=a;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    cin>>n>>m>>a;
    for(int i=1;i<=n;i++)
        cin>>Brr[i];
    for(int i=1;i<=m;i++)
        cin>>Prr[i];
    sort(Brr+1,Brr+n+1);
    sort(Prr+1,Prr+m+1);
    int hi = min(n,m);
    int lo = 1,mid,mx = 0;
    while(lo<=hi)
    {
        mid = (lo+hi)>>1;
        if( Ok(mid) )mx = mid,lo = mid+1;
        else hi = mid-1;
    }
    cout<<mx<< " ";
    ll now = 0;
    for(int i=1;i<=mx;i++)
        now += Prr[i];
    if( now>=a )now -= a;
    else now = 0;
    cout<<now<< "\n";

    return 0;
}


/*
~Like a small boat
~On the ocean
~Sending big waves
~Into motion
!Like how a single word
!Can make a heart open
!I might only have one match
!But I can make an explosion
#And all those things I didn't say
#Wrecking balls inside my brain
#I will scream them loud tonight
#Can you hear my voice this time?
@This is my fight song
@Take back my life song
@Prove I'm alright song
@My power's turned on
$Starting right now I'll be strong
$I'll play my fight song
$And I don't really care if nobody else believes
$'Cause I've still got a lot of fight left in me!!!
*/

#include "bits/stdc++.h"
using namespace std;

#define  F  first
#define  S  second
#define  mp make_pair
#define  pb push_back
typedef long long int ll;
const int N = 1e5+5,mod = 1e9+7;
int Brr[N],Prr[N],m,n,a;

bool Ok( int x )
{
    ll now = 0;
    for(int i=1;i<=n;i++)
    {
        if( Prr[i]>Brr[n-x+i]&&Brr[n-x+i] )
            now += Prr[i]-Brr[n-x+i];
    }
    return now<=a;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    cin>>n>>m>>a;
    for(int i=1;i<=n;i++)
        cin>>Brr[i];
    for(int i=1;i<=m;i++)
        cin>>Prr[i];
    sort(Brr+1,Brr+n+1);
    sort(Prr+1,Prr+m+1);
    int hi = min(n,m);
    int lo = 0,mid,mx = 0;
    while(lo<=hi)
    {
        mid = (lo+hi)>>1;
        if( Ok(mid) )mx = mid,lo = mid+1;
        else hi = mid-1;
    }
    cout<<mx<< " ";
    ll now = 0;
    for(int i=1;i<=mx;i++)
        now += Prr[i];
    if( now>=a )now -= a;
    cout<<now<< "\n";

    return 0;
}


/*
~Like a small boat
~On the ocean
~Sending big waves
~Into motion
!Like how a single word
!Can make a heart open
!I might only have one match
!But I can make an explosion
#And all those things I didn't say
#Wrecking balls inside my brain
#I will scream them loud tonight
#Can you hear my voice this time?
@This is my fight song
@Take back my life song
@Prove I'm alright song
@My power's turned on
$Starting right now I'll be strong
$I'll play my fight song
$And I don't really care if nobody else believes
$'Cause I've still got a lot of fight left in me!!!
*/

#include "bits/stdc++.h"
using namespace std;

#define  F  first
#define  S  second
#define  mp make_pair
#define  pb push_back
typedef long long int ll;
const int N = 1e5+5,mod = 1e9+7;
int Brr[N],Prr[N],m,n,a;

bool Ok( int x )
{
    ll now = 0;
    for(int i=1;i<=n;i++)
    {
        if( Prr[i]>Brr[n-x+i]&&Brr[n-x+i] )
            now += Prr[i]-Brr[n-x+i];
    }
    return now<=a;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    cin>>n>>m>>a;
    for(int i=1;i<=n;i++)
        cin>>Brr[i];
    for(int i=1;i<=m;i++)
        cin>>Prr[i];
    sort(Brr+1,Brr+n+1);
    sort(Prr+1,Prr+m+1);
    int hi = min(n,m)+1;
    int lo = 1,mid,mx = 0;
    while(lo<=hi)
    {
        mid = (lo+hi)>>1;
        if( Ok(mid) )mx = mid,lo = mid+1;
        else hi = mid-1;
    }
    cout<<mx<< " ";
    ll now = 0;
    for(int i=1;i<=mx;i++)
        now += Prr[i];
    if( now>=a )now -= a;
    else now = 0;
    cout<<now<< "\n";

    return 0;
}


/*
~Like a small boat
~On the ocean
~Sending big waves
~Into motion
!Like how a single word
!Can make a heart open
!I might only have one match
!But I can make an explosion
#And all those things I didn't say
#Wrecking balls inside my brain
#I will scream them loud tonight
#Can you hear my voice this time?
@This is my fight song
@Take back my life song
@Prove I'm alright song
@My power's turned on
$Starting right now I'll be strong
$I'll play my fight song
$And I don't really care if nobody else believes
$'Cause I've still got a lot of fight left in me!!!
*/

#include "bits/stdc++.h"
using namespace std;

#define  F  first
#define  S  second
#define  mp make_pair
#define  pb push_back
typedef long long int ll;
const int N = 1e5+5,mod = 1e9+7;
int Brr[N],Prr[N],m,n,a;

bool Ok( int x )
{
    ll now = 0;
    for(int i=1;i<=n;i++)
    {
        if( Prr[i]>Brr[n-x+i]&&Brr[n-x+i] )
            now += Prr[i]-Brr[n-x+i];
    }
    return now<=a;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    cin>>n>>m>>a;
    for(int i=1;i<=n;i++)
        cin>>Brr[i];
    for(int i=1;i<=m;i++)
        cin>>Prr[i];
    sort(Brr+1,Brr+n+1);
    sort(Prr+1,Prr+m+1);
    int hi = min(n,m);
    int lo = 0,mid,mx = 0;
    while(lo<=hi)
    {
        mid = (lo+hi)>>1;
        if( Ok(mid) )mx = mid,lo = mid+1;
        else hi = mid-1;
    }
    cout<<mx<< " ";
    ll now = 0;
    for(int i=1;i<=mx;i++)
        now += Prr[i];
    if( now>a )now -= a;
    cout<<now<< "\n";

    return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define ins insert
#define rs resize
#define br break;
#define cont continue;
#define vi vector<ll>
#define vll vector<long long>
#define si set<ll>
#define sll set<long long>
#define pii pair<ll,ll>
#define pll pair<long long, long long>
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL);
#define vec vector
#define cend cout<<endl;
#define sc second
#define fr first
#define endl "\n"
#define retz return 0;
using namespace std;

template<class t>
void scan(t* arr, ll n)
{
  for(ll i=0; i<n; i++)
    cin >> arr[i];
}

int main()
{
  ll n, m, t;
  cin >> n >> m >> t;
  ll a[n];
  ll p[m];
  scan(a, n);
  scan(p, m);

  sort(p, p+m);
  sort(a, a+n);
  ll l = 0, r = min(m-1, n-1);
  ll p1 = -1;
  while(l<=r)
  {
    ll r1 = t;
    ll m = (l+r)/2;
    for(ll i=0; i<=m;i++)
      r1 -= max((ll)0, p[m-i]-a[n-i-1]);
    if(r1<0)
      r = m-1;
    else
      p1 = l, l = m+1;
  }

  l = p1+1;
  if(!l)
  {
    cout << 0 << " " << 0 << endl;
    return 0;
  }

  ll xx = 0;
  for(ll i=0; i<l; i++)
    xx += p[i];

  cout << l << " " << max(xx-t, (ll)0)<< endl;

}


#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define ins insert
#define rs resize
#define br break;
#define cont continue;
#define vi vector<ll>
#define vll vector<long long>
#define si set<ll>
#define sll set<long long>
#define pii pair<ll,ll>
#define pll pair<long long, long long>
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL);
#define vec vector
#define cend cout<<endl;
#define sc second
#define fr first
#define endl "\n"
#define retz return 0;
using namespace std;

template<class t>
void scan(t* arr, ll n)
{
  for(ll i=0; i<n; i++)
    cin >> arr[i];
}

int main()
{
  ll n, m, t;
  cin >> n >> m >> t;
  ll a[n];
  ll p[m];
  scan(a, n);
  scan(p, m);

  sort(p, p+m);
  sort(a, a+n);
  ll l = 0, r = min(m-1, n-1);
  ll p1 = -1;
  while(l<=r)
  {
    cout << l << " " << r << endl;
    ll r1 = t;
    ll m = (l+r)/2;
    for(ll i=0; i<=m;i++)
      r1 -= max((ll)0, p[m-i]-a[n-i-1]);
    if(r1<0)
      r = m-1;
    else
    {
      p1 = m, l = m+1;
    }
  }

  l = p1+1;
  if(!l)
  {
    cout << 0 << " " << 0 << endl;
    return 0;
  }

  ll xx = 0;
  for(ll i=0; i<l; i++)
    xx += p[i];

  cout << l << " " << max(xx-t, (ll)0)<< endl;

}


#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define ins insert
#define rs resize
#define br break;
#define cont continue;
#define vi vector<ll>
#define vll vector<long long>
#define si set<ll>
#define sll set<long long>
#define pii pair<ll,ll>
#define pll pair<long long, long long>
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL);
#define vec vector
#define cend cout<<endl;
#define sc second
#define fr first
#define endl "\n"
#define retz return 0;
using namespace std;

template<class t>
void scan(t* arr, ll n)
{
  for(ll i=0; i<n; i++)
    cin >> arr[i];
}

ll main()
{
  ll n, m, t;
  cin >> n >> m >> t;
  ll a[n];
  ll p[m];
  scan(a, n);
  scan(p, m);

  sort(p, p+m);
  sort(a, a+n);
  ll l = 0, r = min(m-1, n-1);
  ll p1 = -1;
  while(l<=r)
  {
    ll r1 = t;
    ll m = (l+r)/2;
    for(ll i=0; i<=m;i++)
      r1 -= max((ll)0, p[m-i]-a[n-i-1]);
    if(r1<0)
      r = m-1;
    else
      p1 = l, l = m+1;
  }

  l = p1+1;
  if(!l)
  {
    cout << 0 << " " << 0 << endl;
    return 0;
  }

  ll xx = 0;
  for(ll i=0; i<l; i++)
    xx += p[i];

  cout << l << " " << xx-t<< endl;

}


#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define ins insert
#define rs resize
#define br break;
#define cont continue;
#define vi vector<ll>
#define vll vector<long long>
#define si set<ll>
#define sll set<long long>
#define pii pair<ll,ll>
#define pll pair<long long, long long>
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL);
#define vec vector
#define cend cout<<endl;
#define sc second
#define fr first
#define endl "\n"
#define retz return 0;
using namespace std;

template<class t>
void scan(t* arr, ll n)
{
  for(ll i=0; i<n; i++)
    cin >> arr[i];
}

int main()
{
  ll n, m, t;
  cin >> n >> m >> t;
  ll a[n];
  ll p[m];
  scan(a, n);
  scan(p, m);

  sort(p, p+m);
  sort(a, a+n);
  ll l = 0, r = min(m-1, n-1);
  ll p1 = -1;
  while(l<=r)
  {
    ll r1 = t;
    ll m = (l+r)/2;
    for(ll i=0; i<=m;i++)
      r1 -= max((ll)0, p[m-i]-a[n-i-1]);
    if(r1<0)
      r = m-1;
    else
    {
      p1 = m, l = m+1;
    }
  }

  l = p1+1;
  if(!l)
  {
    cout << 0 << " " << 0 << endl;
    return 0;
  }

  ll xx = 0;
  for(ll i=0; i<l; i++)
    xx += p[i];

  cout << l << " " << max(xx-t, (ll)0)<< endl;

}


#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define ins insert
#define rs resize
#define br break;
#define cont continue;
#define vi vector<ll>
#define vll vector<long long>
#define si set<ll>
#define sll set<long long>
#define pii pair<ll,ll>
#define pll pair<long long, long long>
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL);
#define vec vector
#define cend cout<<endl;
#define sc second
#define fr first
#define endl "\n"
#define retz return 0;
using namespace std;

template<class t>
void scan(t* arr, ll n)
{
  for(ll i=0; i<n; i++)
    cin >> arr[i];
}

int main()
{
  ll n, m, t;
  cin >> n >> m >> t;
  ll a[n];
  ll p[m];
  scan(a, n);
  scan(p, m);

  sort(p, p+m);
  sort(a, a+n);
  ll l = 0, r = min(m-1, n-1);
  ll p1 = -1;
  while(l<=r)
  {
    ll r1 = t;
    ll m = (l+r)/2;
    for(ll i=0; i<=m;i++)
      r1 -= max((ll)0, p[m-i]-a[n-i-1]);
    if(r1<0)
      r = m-1;
    else
      p1 = l, l = m+1;
  }

  l = p1+1;
  if(!l)
  {
    cout << 0 << " " << 0 << endl;
    return 0;
  }

  ll xx = 0;
  for(ll i=0; i<l; i++)
    xx += p[i];

  cout << l << " " << xx-t<< endl;

}


#include<bits/stdc++.h>
using namespace std;
int a[1000000];
int b[1000000];
int main()
{
        int n,m,am;
        cin>>n>>m>>am;
int l=0;
int r=m;
int i,j;
       for(i=0;i<n;i++)
       cin>>a[i];
       for(i=0;i<m;i++)
       cin>>b[i];
      sort(a,a+n);
      sort(b,b+m);
      int mid,ans=-1;
      int bm;
      while(l<=r)
      {bm=am;
              mid=(l+r)/2;
              j=mid-1;
              for(i=n-1;i>=0;i--)
              {
             if(a[i]>=b[j])
             {
                     j--;
                     continue;
             }
             else if(a[i]+bm>=b[j])
{
        bm=bm-(b[j]-a[i]);
        j--;
        continue;
}
              break;

              }
      if(j==-1)
      {
              ans=mid;l=mid+1;
      }
      else
      {
              r=mid-1;
      }

      }
     if(ans==-1)
     {cout<<0;

             return 0;
     }
       cout<<ans<<"\n";
       int sum=0;
       for(i=0;i<ans;i++)
       sum=sum+b[i];
       sum=sum-am;
       if(am<=0)
       cout<<0;
       else
       cout<<sum;
}


#include<bits/stdc++.h>
using namespace std;
int a[1000000];
int b[1000000];
int main()
{
        int n,m,am;
        cin>>n>>m>>am;
int l=0;
int r=m;
int i,j;
       for(i=0;i<n;i++)
       cin>>a[i];
       for(i=0;i<m;i++)
       cin>>b[i];
      sort(a,a+n);
      sort(b,b+m);
      int mid,ans=-1;
      int bm;
      while(l<=r)
      {bm=am;
              mid=(l+r)/2;
              j=mid-1;
              for(i=n-1;i>=0&&j>=0;i--)
              {
             if(a[i]>=b[j])
             {
                     j--;
                     continue;
             }
             else if(a[i]+bm>=b[j])
{
        bm=bm-(b[j]-a[i]);
        j--;
        continue;
}
              break;

              }
      if(j==-1)
      {
              ans=mid;l=mid+1;
      }
      else
      {
              r=mid-1;
      }

      }
     if(ans==-1)
     {cout<<0;

             return 0;
     }
       cout<<ans<<" ";
       int sum=0;
       for(i=0;i<ans;i++)
       sum=sum+b[i];
       sum=sum-am;
       if(am<=0)
       cout<<0;
       else
       cout<<sum;
}


#include<bits/stdc++.h>
using namespace std;
int a[1000000];
int b[1000000];
int main()
{
        int n,m,am;
        cin>>n>>m>>am;
int l=0;
int r=m;
int i,j;
       for(i=0;i<n;i++)
       cin>>a[i];
       for(i=0;i<m;i++)
       cin>>b[i];
      sort(a,a+n);
      sort(b,b+m);
      int mid,ans=-1;
      int bm;
      while(l<=r)
      {bm=am;
              mid=(l+r)/2;
              j=mid-1;
              for(i=n-1;i>=0&&j>=0;i--)
              {
             if(a[i]>=b[j])
             {
                     j--;
                     continue;
             }
             else if(a[i]+bm>=b[j])
{
        bm=bm-(b[j]-a[i]);
        j--;
        continue;
}
              break;

              }
      if(j==-1)
      {
              ans=mid;l=mid+1;
      }
      else
      {
              r=mid-1;
      }

      }
     if(ans==-1)
     {cout<<0;

             return 0;
     }
       cout<<ans<<" ";
       int sum=0;
       for(i=0;i<ans;i++)
       sum=sum+b[i];
       sum=sum-am;
       if(sum<=0)
       cout<<0;
       else
       cout<<sum;
}


#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
typedef long long ll;
typedef pair<ll,ll>pll;
typedef long double ld;
ll bin_pow(ll a,ll b){
    if(b==0)return 1;
    if(b%2==0){
        ll t=bin_pow(a,b/2);
        return t*t%MOD;
    }
    else return a*bin_pow(a,b-1)%MOD;
}
int main()
{
    //freopen("polygon.in","r",stdin);
    //freopen("polygon.out","w",stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll t=1,n,m,k=0,sum=0,l=0,r=0,x=0,y=0,z=0,ans=0,mn=LLONG_MAX,mx=LLONG_MIN;
    cin>>n>>m>>x;
    ll f=x;
    vector<ll>a(n),c(m);
    for(int i=0;i<n;i++)cin>>a[i];
    sort(a.begin(),a.end());
    //reverse(a.begin(),a.end());
    vector<ll>b(m);
    for(int i=0;i<m;i++)cin>>b[i];
    sort(b.begin(),b.end());
    reverse(b.begin(),b.end());
    reverse(a.begin(),a.end());
    /*
    for(int i=0;i<min(n,m);i++){
        if(a[i]>=b[i]){
                r+=b[i];
                l++;
            continue;
        }
        y=b[i]-a[i];
        if(x<y)break;
        l++;
        r+=a[i];
    }*/
    for(int l=0;l<n;l++){
        while(r<m&&a[l]<b[r])r++;
        if(r==m){
            z=l;
            break;
        }
        c[l]=1;
        k++;
        //cout<<r<<endl;
        //ans+=a[l];
        r++;
    }
    r=n-1;
    for(int i=m-1;i>=z;i--){
        while(r>=0&&c[r]==1)r--;
        if(r<0)break;
        //cout<<r<<" "<<x<<" "<<i<<endl;
        y=b[i]-a[r];
        if(x<y)break;
        //ans+=a[r];
        x-=y;
        k++;
        c[r]=1;
    }
    //reverse(b.begin(),b.end());//?
    z=0;
    x=f;
    for(int i=k-1;i>=0;i--){
        y=m-k+i;
        if(a[i]<b[y])x-=(b[y]-a[i]),ans+=a[i];
        else{
            if(b[y]<=x)x-=b[y];
            else ans+=b[y]-x,x=0;
        }
    }
    //cout<<ans<<" "<<x<<endl;
    if(x)ans-=x;
    ans=max(ans,0ll);
    cout<<k<<" "<<ans;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
typedef long long ll;
typedef pair<ll,ll>pll;
typedef long double ld;
ll bin_pow(ll a,ll b){
    if(b==0)return 1;
    if(b%2==0){
        ll t=bin_pow(a,b/2);
        return t*t%MOD;
    }
    else return a*bin_pow(a,b-1)%MOD;
}
ll t=1,n,m,k=0,sum=0,l=0,r=0,x=0,y=0,z=0,ans=0,mn=LLONG_MAX,mx=LLONG_MIN;
ll f;
vector<ll>a,b;
bool tr(ll k){
    x=f;
    ll ans=0;
    for(int i=0;i<k;i++){
        y=k-1-i;
        if(a[i]>=b[y])continue;
        x-=b[y]-a[i];
    }
    return x>=0;
}
int main()
{
    //freopen("polygon.in","r",stdin);
    //freopen("polygon.out","w",stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>n>>m>>x;
     f=x;
    a.resize(n),b.resize(m);
    for(int i=0;i<n;i++)cin>>a[i];
    sort(a.begin(),a.end());
    for(int i=0;i<m;i++)cin>>b[i];
    sort(b.begin(),b.end());
    //reverse(b.begin(),b.end());
    reverse(a.begin(),a.end());
    k=0;
    for(ll b1=m;b1>=1;b1/=2){
        while(k+b1<=m&&tr(k+b1))k+=b1;
    }
    reverse(b.begin(),b.end());
    x=f;
    for(int i=k-1;i>=0;i--){
        y=m-k+i;
        if(a[i]<b[y])x-=(b[y]-a[i]),ans+=a[i];
        else{
            if(b[y]<=x)x-=b[y];
            else ans+=b[y]-x,x=0;
        }
    }
    //cout<<ans<<" "<<x<<endl;
    if(x)ans-=x;
    ans=max(ans,0ll);
    cout<<k<<" "<<ans;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
typedef long long ll;
typedef pair<ll,ll>pll;
typedef long double ld;
ll bin_pow(ll a,ll b){
    if(b==0)return 1;
    if(b%2==0){
        ll t=bin_pow(a,b/2);
        return t*t%MOD;
    }
    else return a*bin_pow(a,b-1)%MOD;
}
int main()
{
    //freopen("polygon.in","r",stdin);
    //freopen("polygon.out","w",stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll t=1,n,m,k=0,sum=0,l=0,r=0,x=0,y=0,z=0,ans=0,mn=LLONG_MAX,mx=LLONG_MIN;
    cin>>n>>m>>x;
    ll f=x;
    vector<ll>a(n),c(n);
    for(int i=0;i<n;i++)cin>>a[i];
    sort(a.begin(),a.end());
    //reverse(a.begin(),a.end());
    vector<ll>b(m);
    for(int i=0;i<m;i++)cin>>b[i];
    sort(b.begin(),b.end());
    reverse(b.begin(),b.end());
    reverse(a.begin(),a.end());
    /*
    for(int i=0;i<min(n,m);i++){
        if(a[i]>=b[i]){
                r+=b[i];
                l++;
            continue;
        }
        y=b[i]-a[i];
        if(x<y)break;
        l++;
        r+=a[i];
    }*/
    for(int l=0;l<n;l++){
        while(r<m&&a[l]<b[r])r++;
        if(r==m){
            z=l;
            break;
        }
        c[l]=1;
        k++;
        //cout<<r<<endl;
        //ans+=a[l];
        r++;
    }
    r=n-1;
    for(int i=m-1;i>=z;i--){
        while(r>=0&&c[r]==1)r--;
        if(r<0)break;
        //cout<<r<<" "<<x<<" "<<i<<endl;
        y=b[i]-a[r];
        if(x<y)break;
        //ans+=a[r];
        x-=y;
        k++;
        c[r]=1;
    }
    //reverse(b.begin(),b.end());//?
    z=0;
    x=f;
    for(int i=k-1;i>=0;i--){
        y=m-k+i;
        if(a[i]<b[y])x-=(b[y]-a[i]),ans+=a[i];
        else{
            if(b[y]<=x)x-=b[y];
            else ans+=b[y]-x,x=0;
        }
    }
    //cout<<ans<<" "<<x<<endl;
    if(x)ans-=x;
    ans=max(ans,0ll);
    cout<<k<<" "<<ans;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
typedef long long ll;
typedef pair<ll,ll>pll;
typedef long double ld;
ll bin_pow(ll a,ll b){
    if(b==0)return 1;
    if(b%2==0){
        ll t=bin_pow(a,b/2);
        return t*t%MOD;
    }
    else return a*bin_pow(a,b-1)%MOD;
}
int main()
{
    //freopen("polygon.in","r",stdin);
    //freopen("polygon.out","w",stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll t=1,n,m,k=0,sum=0,l=0,r=0,x=0,y=0,z=0,ans=0,mn=LLONG_MAX,mx=LLONG_MIN;
    cin>>n>>m>>x;
    ll f=x;
    vector<ll>a(n),c(m);
    for(int i=0;i<n;i++)cin>>a[i];
    sort(a.begin(),a.end());
    //reverse(a.begin(),a.end());
    vector<ll>b(m);
    for(int i=0;i<m;i++)cin>>b[i];
    sort(b.begin(),b.end());
    reverse(b.begin(),b.end());
    reverse(a.begin(),a.end());
    /*
    for(int i=0;i<min(n,m);i++){
        if(a[i]>=b[i]){
                r+=b[i];
                l++;
            continue;
        }
        y=b[i]-a[i];
        if(x<y)break;
        l++;
        r+=a[i];
    }*/
    for(int l=0;l<n;l++){
        while(r<m&&a[l]<b[r])r++;
        if(r==m){
            z=l;
            break;
        }
        c[l]=1;
        k++;
        //cout<<r<<endl;
        //ans+=a[l];
        r++;
    }
    r=n-1;
    for(int i=m-1;i>=z;i--){
        while(r>=0&&c[r]==1)r--;
        if(r<0)break;
        //cout<<r<<" "<<x<<" "<<i<<endl;
        y=b[i]-a[r];
        if(x<y)break;
        //ans+=a[r];
        x-=y;
        k++;
        c[r]=1;
    }
    //reverse(b.begin(),b.end());//?
    z=0;
    x=f;
    for(int i=k-1;i>=0;i--){
        y=m-k+i;
        if(a[i]<b[y])x-=(b[y]-a[i]),ans+=a[i];
        else{
            if(b[y]<=x)x-=b[y];
            else x=0,ans+=b[y]-x;
        }
    }
    //cout<<ans<<" "<<x<<endl;
    if(x)ans-=x;
    ans=max(ans,0ll);
    cout<<k<<" "<<ans;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
typedef long long ll;
typedef pair<ll,ll>pll;
typedef long double ld;
ll bin_pow(ll a,ll b){
    if(b==0)return 1;
    if(b%2==0){
        ll t=bin_pow(a,b/2);
        return t*t%MOD;
    }
    else return a*bin_pow(a,b-1)%MOD;
}
ll t=1,n,m,k=0,sum=0,l=0,r=0,x=0,y=0,z=0,ans=0,mn=LLONG_MAX,mx=LLONG_MIN;
ll f;
vector<ll>a,b;
bool tr(ll k){
    x=f;
    ll ans=0;
    for(int i=0;i<k;i++){
        y=k-1-i;
        if(a[i]>=b[y])continue;
        x-=b[y]-a[i];
    }
    return x>=0;
}
int main()
{
    //freopen("polygon.in","r",stdin);
    //freopen("polygon.out","w",stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>n>>m>>x;
     f=x;
    a.resize(n),b.resize(m);
    for(int i=0;i<n;i++)cin>>a[i];
    sort(a.begin(),a.end());
    for(int i=0;i<m;i++)cin>>b[i];
    sort(b.begin(),b.end());
    //reverse(b.begin(),b.end());
    reverse(a.begin(),a.end());
    k=0;
    for(ll b1=n;b1>=1;b1/=2){
        while(k+b1<=n&&tr(k+b1))k+=b1;
    }
    reverse(b.begin(),b.end());
    x=f;
    for(int i=k-1;i>=0;i--){
        y=m-k+i;
        if(a[i]<b[y])x-=(b[y]-a[i]),ans+=a[i];
        else{
            if(b[y]<=x)x-=b[y];
            else ans+=b[y]-x,x=0;
        }
    }
    //cout<<ans<<" "<<x<<endl;
    if(x)ans-=x;
    ans=max(ans,0ll);
    cout<<k<<" "<<ans;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
typedef long long ll;
typedef pair<ll,ll>pll;
typedef long double ld;
ll bin_pow(ll a,ll b){
    if(b==0)return 1;
    if(b%2==0){
        ll t=bin_pow(a,b/2);
        return t*t%MOD;
    }
    else return a*bin_pow(a,b-1)%MOD;
}
ll t=1,n,m,k=0,sum=0,l=0,r=0,x=0,y=0,z=0,ans=0,mn=LLONG_MAX,mx=LLONG_MIN;
ll f;
vector<ll>a,b;
bool tr(ll k){
    x=f;
    ll ans=0;
    for(int i=0;i<k;i++){
        y=k-1-i;
        if(a[i]>=b[y])continue;
        x-=b[y]-a[i];
    }
    return x>=0;
}
int main()
{
    //freopen("polygon.in","r",stdin);
    //freopen("polygon.out","w",stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>n>>m>>x;
     f=x;
    a.resize(n),b.resize(m);
    for(int i=0;i<n;i++)cin>>a[i];
    sort(a.begin(),a.end());
    for(int i=0;i<m;i++)cin>>b[i];
    sort(b.begin(),b.end());
    //reverse(b.begin(),b.end());
    reverse(a.begin(),a.end());
    k=0;
    for(ll b1=n;b1>=1;b1/=2){
        while(k+b1<=min(n,m)&&tr(k+b1))k+=b1;
    }
    reverse(b.begin(),b.end());
    x=f;
    for(int i=k-1;i>=0;i--){
        y=m-k+i;
        if(a[i]<b[y])x-=(b[y]-a[i]),ans+=a[i];
        else{
            if(b[y]<=x)x-=b[y];
            else ans+=b[y]-x,x=0;
        }
    }
    //cout<<ans<<" "<<x<<endl;
    if(x)ans-=x;
    ans=max(ans,0ll);
    cout<<k<<" "<<ans;
    return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define all(v) v.begin(), v.end()
#define sz size()
#define mp make_pair
#define pb push_back
#define rep(p, a, b) for (ll p = a; p < b; p++)
#define rap(p, a, b) for (ll p = a; p <= b; p++)
#define per(p, a, b) for (ll p = a; p >= b; p--)
#define F first
#define S second
using namespace std;

typedef vector<ll> vll;
typedef vector<ld> vld;
typedef pair<ll, ll> pll;

int main()
{
    ll t, i, j, k, ans, n, m;

    //cin>>t;
    t = 1;
    while (t--)
    {
        cin >> n >> m >> k;
        vll b(n), pr(m);

        ll rem = k;
        rep(p, 0, n) cin >> b[p];
        rep(p, 0, m) cin >> pr[p];

        sort(all(b));
        sort(all(pr));

        i=0,j=0,ans=0;
        ll sum=0;
        while(i<n && j<m)
        {
            while(i<n && b[i]+rem<pr[j])i++;
            if(i<n)
            {
                if(pr[j]>b[i])rem-=(pr[j]-b[i]);
                i++;
                ans++;
                sum+=pr[j];
                j++;
            }
        }

        cout<<ans<<" "<<max(sum-k,0LL);
    }

    return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define all(v) v.begin(), v.end()
#define sz size()
#define mp make_pair
#define pb push_back
#define rep(p, a, b) for (ll p = a; p < b; p++)
#define rap(p, a, b) for (ll p = a; p <= b; p++)
#define per(p, a, b) for (ll p = a; p >= b; p--)
#define F first
#define S second
using namespace std;

typedef vector<ll> vll;
typedef vector<ld> vld;
typedef pair<ll, ll> pll;

int main()
{
    ll t, i, j, k, ans, n, m;

    //cin>>t;
    t = 1;
    while (t--)
    {
        cin >> n >> m >> k;
        vll b(n), pr(m);

        ll rem = k;
        rep(p, 0, n) cin >> b[p];
        rep(p, 0, m) cin >> pr[p];

        sort(all(b));
        sort(all(pr));

        i=0,j=0,ans=0;
        ll sum=0;
        while(i<n && j<m)
        {
            while(b[i]+rem<pr[j] && i<n)i++;
            if(i<n)
            {
                if(pr[j]>b[i])rem-=(pr[j]-b[i]);
                i++;
                ans++;
                sum+=pr[j];
                j++;
            }
        }

        cout<<ans<<" "<<sum-k;
    }

    return 0;
}


#include<iostream>
#include<algorithm>
using namespace std;
typedef int LL;
const int N=100100;
LL n,m,a,b[N],p[N];
int main(){
cin>>n>>m>>a;
for(int i=0;i<n;++i)cin>>b[i];sort(b,b+n);
for(int i=0;i<m;++i)cin>>p[i];sort(p,p+m);
int lo=0,hi=min(n,m)-1;
while(lo<=hi){
int md=(lo+hi)>>1;
LL t=a;
for(int i=0;i<=md&&t>=0;++i)t-=max(0,p[i]-b[n-1-md+i]);
if(t<0)hi=md-1;else lo=md+1;
}
LL s=0;
for(int i=0;i<lo;++i)s+=p[i];
cout<<lo<<" "<<(lo?max(0,s-a):0)<<endl;
}


#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define all(v) v.begin(), v.end()
#define sz size()
#define mp make_pair
#define pb push_back
#define rep(p, a, b) for (ll p = a; p < b; p++)
#define rap(p, a, b) for (ll p = a; p <= b; p++)
#define per(p, a, b) for (ll p = a; p >= b; p--)
#define F first
#define S second
using namespace std;

typedef vector<ll> vll;
typedef vector<ld> vld;
typedef pair<ll, ll> pll;

int main()
{
    ll t, i, j, k, ans, n, m;

    //cin>>t;
    t = 1;
    while (t--)
    {
        cin >> n >> m >> k;
        vll b(n), pr(m);

        ll rem = k;
        rep(p, 0, n) cin >> b[p];
        rep(p, 0, m) cin >> pr[p];

        sort(all(b));
        sort(all(pr));

        i=0,j=0,ans=0;
        ll sum=0;
        while(i<n && j<m)
        {
            while(i<n && b[i]+rem<pr[j])i++;
            if(i<n)
            {
                if(pr[j]>b[i])rem-=(pr[j]-b[i]);
                i++;
                ans++;
                sum+=pr[j];
                j++;
            }
        }

        cout<<ans<<" "<<sum-k;
    }

    return 0;
}


#include<bits/stdc++.h>
#include <cassert>
#include<stdarg.h>
#include <unordered_map>
#include <cstring>
using namespace std;
typedef long long ll;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
	sim > struct rge { c b, e; };
	sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
	sim > auto dud(c* x) -> decltype(cerr << *x, 0);
	sim > char dud(...);
	struct debug {
#ifdef LOCAL
		~debug() { cerr << endl; }
		eni(!=) cerr << boolalpha << i; ris; }
		eni(==) ris << range(begin(i), end(i)); }
		sim, class b dor(pair < b, c > d) {
			ris << "(" << d.first << ", " << d.second << ")";
		}
		sim dor(rge<c> d) {
			*this << "[";
			for (auto it = d.b; it != d.e; ++it)
				*this << ", " + 2 * (it == d.b) << *it;
			ris << "]";
		}
#else
		sim dor(const c&) { ris; }
#endif
	};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define pb push_back
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vec vector

void read(vector<ll> &a){
	for(ll &i : a) cin >> i;
}
void read(vector<int> &a){
	for(int &i : a) cin >> i;
}
ll mod = 1e9 + 7;
int INF = 1e9;
long long binpow(long long a, long long b) {
	a %= mod;
	long long res = 1;
	while (b > 0) {
		if (b & 1)
			res = res * a % mod;
		a = a * a % mod;
		b >>= 1;
	}
	return res;
}

int gcd(int a, int b){
	return __gcd(a, b);
}
ll ans = 0;
bool check(ll how, vector<ll> &a, vector<ll> &p, ll cb){
	if(how == 0) return true;
	ll p1 = how-1;
	ll p2 = 0;
	ll curB = cb;
	ll cnt = 0;
	ll used = 0;
	ll sum  = 0;
	// debug() << imie(p[0]);
	for(ll i = p1; i >= 0; i--){
		sum += p[p2];
		debug() << imie(a[i]) imie(p[p2]);
		if(a[i] < p[p2] && curB - (p[p2] - a[i]) >= 0){
			used += (p[p2] - a[i]);
			curB -= (p[p2] - a[i]);
			cnt++;
			p2++;
		} else if(a[i] >= p[p2]){
			p2++;
			cnt++;
		} else {
			return false;
		}

	}
	// debug() << imie(used);
	if(cnt == how){
		ans = sum - cb;
		return true;
	}
	return false;
}
void test_case(int tnum){
	ll n, m, c;
	cin >> n >> m >> c;
	vector<ll> a(n);
	vector<ll> p(m);
	read(a);
	read(p);
	sort(a.begin(), a.end());
	sort(p.begin(), p.end());
	reverse(a.begin(), a.end());
	ll hi = n;
	ll lo = 0;
	while(hi != lo){
		debug() << imie(hi) imie(lo);
		int mid = (hi + lo + 1) / 2;
		// debug() << imie(check(mid, a, p, c));
		if(check(mid, a, p, c)){
			lo = mid;
		} else{
			hi = mid-1;
		}
	}
	// check(3, a, p, c);
	cout << hi << ' ' << max(0LL, ans) << '\n';
}

int main(){

	ios_base::sync_with_stdio(0); cin.tie(0);
	int t;
	t = 1;
	// cin >> t;

	for(int test = 1; test <= t; test++){
		test_case(test);
	}

}


#include<bits/stdc++.h>
#include <cassert>
#include<stdarg.h>
#include <unordered_map>
#include <cstring>
using namespace std;
typedef long long ll;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
	sim > struct rge { c b, e; };
	sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
	sim > auto dud(c* x) -> decltype(cerr << *x, 0);
	sim > char dud(...);
	struct debug {
#ifdef LOCAL
		~debug() { cerr << endl; }
		eni(!=) cerr << boolalpha << i; ris; }
		eni(==) ris << range(begin(i), end(i)); }
		sim, class b dor(pair < b, c > d) {
			ris << "(" << d.first << ", " << d.second << ")";
		}
		sim dor(rge<c> d) {
			*this << "[";
			for (auto it = d.b; it != d.e; ++it)
				*this << ", " + 2 * (it == d.b) << *it;
			ris << "]";
		}
#else
		sim dor(const c&) { ris; }
#endif
	};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define pb push_back
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vec vector

void read(vector<ll> &a){
	for(ll &i : a) cin >> i;
}
void read(vector<int> &a){
	for(int &i : a) cin >> i;
}
ll mod = 1e9 + 7;
int INF = 1e9;
long long binpow(long long a, long long b) {
	a %= mod;
	long long res = 1;
	while (b > 0) {
		if (b & 1)
			res = res * a % mod;
		a = a * a % mod;
		b >>= 1;
	}
	return res;
}

int gcd(int a, int b){
	return __gcd(a, b);
}
ll ans = 0;
bool check(ll how, vector<ll> &a, vector<ll> &p, ll cb){
	if(how == 0) return true;
	ll p1 = how-1;
	ll p2 = 0;
	ll curB = cb;
	ll cnt = 0;
	ll used = 0;
	ll sum  = 0;
	// debug() << imie(p[0]);
	for(ll i = p1; i >= 0; i--){
		sum += p[p2];
		debug() << imie(a[i]) imie(p[p2]);
		if(a[i] < p[p2] && curB - (p[p2] - a[i]) >= 0){
			used += (p[p2] - a[i]);
			curB -= (p[p2] - a[i]);
			cnt++;
			p2++;
		} else if(a[i] >= p[p2]){
			p2++;
			cnt++;
		} else {
			return false;
		}

	}
	// debug() << imie(used);
	if(cnt == how){
		ans = sum - cb;
		return true;
	}
	return false;
}
void test_case(int tnum){
	ll n, m, c;
	cin >> n >> m >> c;
	vector<ll> a(n);
	vector<ll> p(m);
	read(a);
	read(p);
	sort(a.begin(), a.end());
	sort(p.begin(), p.end());
	reverse(a.begin(), a.end());
	ll hi = n;
	ll lo = 0;
	while(hi != lo){
		debug() << imie(hi) imie(lo);
		int mid = (hi + lo + 1) / 2;
		// debug() << imie(check(mid, a, p, c));
		if(check(mid, a, p, c)){
			lo = mid;
		} else{
			hi = mid-1;
		}
	}
	// check(3, a, p, c);
	cout << hi << ' ' << ans << '\n';
}

int main(){

	ios_base::sync_with_stdio(0); cin.tie(0);
	int t;
	t = 1;
	// cin >> t;

	for(int test = 1; test <= t; test++){
		test_case(test);
	}

}


#include<bits/stdc++.h>
#include <cassert>
#include<stdarg.h>
#include <unordered_map>
#include <cstring>
using namespace std;
typedef long long ll;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
	sim > struct rge { c b, e; };
	sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
	sim > auto dud(c* x) -> decltype(cerr << *x, 0);
	sim > char dud(...);
	struct debug {
#ifdef LOCAL
		~debug() { cerr << endl; }
		eni(!=) cerr << boolalpha << i; ris; }
		eni(==) ris << range(begin(i), end(i)); }
		sim, class b dor(pair < b, c > d) {
			ris << "(" << d.first << ", " << d.second << ")";
		}
		sim dor(rge<c> d) {
			*this << "[";
			for (auto it = d.b; it != d.e; ++it)
				*this << ", " + 2 * (it == d.b) << *it;
			ris << "]";
		}
#else
		sim dor(const c&) { ris; }
#endif
	};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define pb push_back
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vec vector

void read(vector<ll> &a){
	for(ll &i : a) cin >> i;
}
void read(vector<int> &a){
	for(int &i : a) cin >> i;
}
ll mod = 1e9 + 7;
int INF = 1e9;
long long binpow(long long a, long long b) {
	a %= mod;
	long long res = 1;
	while (b > 0) {
		if (b & 1)
			res = res * a % mod;
		a = a * a % mod;
		b >>= 1;
	}
	return res;
}

int gcd(int a, int b){
	return __gcd(a, b);
}
ll ans = 0;
bool check(ll how, vector<ll> &a, vector<ll> &p, ll cb){
	if(how == 0) return true;
	ll p1 = how-1;
	ll p2 = 0;
	ll curB = cb;
	ll cnt = 0;
	ll used = 0;
	ll sum  = 0;
	// debug() << imie(p[0]);
	for(ll i = p1; i >= 0; i--){
		sum += p[p2];
		debug() << imie(a[i]) imie(p[p2]);
		if(a[i] < p[p2] && curB - (p[p2] - a[i]) >= 0){
			used += (p[p2] - a[i]);
			curB -= (p[p2] - a[i]);
			cnt++;
			p2++;
		} else if(a[i] >= p[p2]){
			p2++;
			cnt++;
		} else {
			return false;
		}

	}
	// debug() << imie(used);
	if(cnt == how){
		ans = sum - cb;
		return true;
	}
	return false;
}
void test_case(int tnum){
	ll n, m, c;
	cin >> n >> m >> c;
	vector<ll> a(n);
	vector<ll> p(m);
	read(a);
	read(p);
	sort(a.begin(), a.end());
	sort(p.begin(), p.end());
	reverse(a.begin(), a.end());
	ll hi = n;
	ll lo = 0;
	while(hi != lo){
		debug() << imie(hi) imie(lo);
		int mid = (hi + lo + 1) / 2;
		// debug() << imie(check(mid, a, p, c));
		if(check(mid, a, p, c)){
			lo = mid;
		} else{
			hi = mid-1;
		}
	}
	// check(3, a, p, c);
	cout << hi << ' ' << max(0, ans) << '\n';
}

int main(){

	ios_base::sync_with_stdio(0); cin.tie(0);
	int t;
	t = 1;
	// cin >> t;

	for(int test = 1; test <= t; test++){
		test_case(test);
	}

}


#include<iostream>
#include<algorithm>
using namespace std;
int money[100005];
long long int bikes[100005];
int n,m;
long long int a;
int check(int mid)
{
	long long int sum=0;
	for(int i=0;i<mid;i++)
		if(bikes[mid-i-1]>money[n-i-1])
			sum+=bikes[mid-i-1]-money[n-i-1];
	if(sum>a) return 0;
	return 1;
}
int main()
{
	cin>>n>>m>>a;
	for(int i=0;i<n;i++)
		cin>>money[i];
	for(int i=0;i<m;i++)
		cin>>bikes[i];
	sort(money,money+n);
	sort(bikes,bikes+m);

	int l=0,r=min(n,m);
	while(l<=r)
	{
		int mid=l+(r-l)/2;
		if(check(mid))
			l=mid+1;
		else
			r=mid-1;
	}
	long long int sum=0;
	for(int i=0;i<r;i++)
		sum+=bikes[i];
	sum = max(0LL, sum-a);
	cout<<r<<" "<<sum<<endl;
	return 0;
}


#include <iostream>
#include <algorithm>
using namespace std;

int main ()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, m,a;
    cin>>n>>m>>a;
    int aa=a;
    int kasa[n], rowery[m];
    for (int i =0; i<n; i++)
    {
     cin>>kasa[i];
    }
    for (int i =0; i<m; i++)
    {
     cin>>rowery[i];
    }
    sort(kasa, kasa+n);
    sort(rowery, rowery +m);
    bool czy=1;
    int r=0, s=0;int i=0, j=0, suma=0;
    while (i!=n)
    {

        if (kasa[i]>=rowery[j])
        {
            r++;
            s=s+rowery[j];
            i++;suma+=rowery[j];
            j++;

        }
        else if (kasa[i]<rowery[j] && kasa[i]+a>=rowery[j])
        {

             r++;
            s+=kasa[i];
            a= a - (rowery[j]-kasa[i]);
            i++;suma+=rowery[j];
            j++;

        }
        else
                i++;

    }
    if (suma-aa>=0)
    cout <<r<<" " <<suma-aa;
    else cout <<r<<" " <<0;
}


#include <iostream>
#include <algorithm>
using namespace std;
const int MAX= 1e5+7;
int c[MAX];
int b[MAX];
int n, m , a;

bool canwe(int sprawdzonerowery)
{
    int act, difference;
    if (sprawdzonerowery>n)
        return false;
    act = a;
    for (int i =0; i<sprawdzonerowery; i++)
    {
        difference  = c[n-i-1]-b[sprawdzonerowery-i-1];
        if (difference>=0)
            continue;
        act+=difference;
        if (act<0)
            return false;
    }
    return true;
}
int binary (int l, int r)
{
    int mid;
    while (l<=r)
    {
        mid = l+(r-l)/2;
        if (canwe(mid))
        l=mid+1;
        else r=mid-1;
    }
    return l;
}
int main ()
{
    cin>>n>>m>>a;
    for (int i =0; i<n; i++) cin>>c[i];
    for (int i =0; i<m; i++)cin>> b[i];
    sort(c, c+n);
    sort(b, b+n);
    int rowery, wlasnywklad, calkowitykoszt;
    rowery = binary(0, m);
    calkowitykoszt=0;
    for (int i =0; i<rowery; i++)
    calkowitykoszt+=b[i];
    wlasnywklad =calkowitykoszt-a;
    wlasnywklad=max(wlasnywklad, 0);
    cout << rowery<< " "<< wlasnywklad;

}


#include <iostream>
#include <algorithm>
using namespace std;

int main ()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, m,a;
    cin>>n>>m>>a;
    int aa=a;
    int kasa[n], rowery[m];
    for (int i =0; i<n; i++)
    {
     cin>>kasa[i];
    }
    for (int i =0; i<m; i++)
    {
     cin>>rowery[i];
    }
    sort(kasa, kasa+n);
    sort(rowery, rowery +m);
    bool czy=1;
    int r=0, s=0;int i=0, j=0, suma=0;
    while (i!=n)
    {

        if (kasa[i]>=rowery[j])
        {
            r++;
            s=s+rowery[j];
            i++;suma+=rowery[j];
            j++;

        }
        else if (kasa[i]<rowery[j] && kasa[i]+a>=rowery[j])
        {

             r++;
            s+=kasa[i];
            a= a - (rowery[j]-kasa[i]);
            i++;suma+=rowery[j];
            j++;

        }
        else
                i++;

    }
    cout <<r<<" " <<suma-aa;
}


#include<iostream>
#include<stdio.h>
#include<algorithm>
using namespace std;
int peo[100005];
long long int pri[100005];
int n,m;
long long int a;
int check(int mid)
{
	long long int sum=0;
	for(int i=0;i<mid;i++)
		if(pri[mid-i-1]>peo[n-i-1])
			sum+=pri[mid-i-1]-peo[n-i-1];
	if(sum>a) return 0;
	return 1;
}
int main()
{
	cin>>n>>m>>a;
	for(int i=0;i<n;i++)
		cin>>peo[i];
	for(int i=0;i<m;i++)
		cin>>pri[i];
	sort(peo,peo+n);
	sort(pri,pri+m);
	int l=0,r=min(n,m);
	while(l<=r)
	{
		int mid=(l+r)/2;
		if(check(mid))
			l=mid+1;
		else
			r=mid-1;
	}
	long long int sum=0;
	for(int i=0;i<r;i++)
		sum+=pri[r-1-i];
	sum = max(0LL, sum-a);
	cout<<r<<" "<<sum<<endl;
	return 0;
}


#include <iostream>
#include <string.h>
#include <algorithm>
#include <math.h>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>
#define fi first
#define se second
#define mp(a,b) make_pair(a,b)
#define ll long long
#define rv(a,b) reverse(a,b)
#define pb(a) push_back(a)
#define clr(a) clear(a)
using namespace std;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef pair<int,ii> iii;
int n,m,a,b[100005],p[100005],in,fin,mid;
vi G;
bool P(int q)
{
	int R=0;
	G.clear();
	for (int i=0;i<q;i++) G.pb(b[i]);
	reverse(G.begin(),G.end());
	for (int i=0;i<(int)G.size();i++) {
		if (G[i]<p[i]) R+=(p[i]-G[i]);
	}
	if (R<=a) return true;
	else return false;
}
int main()
{
	cin.tie(0); cout.tie(0);
	ios_base::sync_with_stdio(0);
	cin>>n>>m>>a;
	for (int i=0;i<n;i++) cin>>b[i];
	sort(b,b+n);
	reverse(b,b+n);
	for (int i=0;i<m;i++) cin>>p[i];
	sort(p,p+m);
	fin=min(n,m);
	in=0;
	while (in<fin) {
		if (in+1==fin) {
			if (P(fin)) {
					cout<<fin<<" ";
					ll R=0;
					for (int i=0;i<fin;i++) R+=p[i];
					R-=a;
					cout<<max(R,(ll)0);
					return 0;
			} else {
				if (P(in)) {
					cout<<in<<" ";
					ll R=0;
					for (int i=0;i<in;i++) R+=p[i];
					R-=a;
					cout<<max(R,(ll)0);
					return 0;
				} else { cout<<"0 0"; return 0; }
			}
		} else {
			mid=(in+fin)/2;
			if (P(mid)) in=mid;
			else fin=mid-1;
		}
	}
						cout<<in<<" ";
					ll R=0;
					for (int i=0;i<in;i++) R+=p[i];
					R-=a;
					cout<<max(R,(ll)0);
	return 0;
}


#include <iostream>
#include <string.h>
#include <algorithm>
#include <math.h>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>
#define fi first
#define se second
#define mp(a,b) make_pair(a,b)
#define ll long long
#define rv(a,b) reverse(a,b)
#define pb(a) push_back(a)
#define clr(a) clear(a)
using namespace std;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef pair<int,ii> iii;
int n,m,a,b[100005],p[100005],in,fin,mid;
vi G;
bool P(int q)
{
	int R=0;
	G.clear();
	for (int i=0;i<q;i++) G.pb(b[i]);
	reverse(G.begin(),G.end());
	for (int i=0;i<(int)G.size();i++) {
		if (G[i]<p[i]) R+=(p[i]-G[i]);
	}
	if (R<=a) return true;
	else return false;
}
int main()
{
	cin.tie(0); cout.tie(0);
	ios_base::sync_with_stdio(0);
	cin>>n>>m>>a;
	for (int i=0;i<n;i++) cin>>b[i];
	sort(b,b+n);
	reverse(b,b+n);
	for (int i=0;i<m;i++) cin>>p[i];
	sort(p,p+m);
	fin=min(n,m);
	in=0;
	while (in<fin) {
		if (in+1==fin) {
			if (P(fin)) {
					cout<<fin<<" ";
					ll R=0;
					for (int i=0;i<fin;i++) R+=p[i];
					R-=a;
										cout<<max(R,0);
					return 0;
			} else {
				if (P(in)) {
					cout<<in<<" ";
					ll R=0;
					for (int i=0;i<in;i++) R+=p[i];
					R-=a;
										cout<<max(R,0);
					return 0;
				} else { cout<<"0 0"; return 0; }
			}
		} else {
			mid=(in+fin)/2;
			if (P(mid)) in=mid;
			else fin=mid-1;
		}
	}
						cout<<in<<" ";
					ll R=0;
					for (int i=0;i<in;i++) R+=p[i];
					R-=a;
					cout<<max(R,0);
	return 0;
}


#include <iostream>
#include <string.h>
#include <algorithm>
#include <math.h>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>
#define fi first
#define se second
#define mp(a,b) make_pair(a,b)
#define ll long long
#define rv(a,b) reverse(a,b)
#define pb(a) push_back(a)
#define clr(a) clear(a)
using namespace std;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
typedef pair<int,int> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef pair<int,ii> iii;
ll n,m,a,b[100005],p[100005],in,fin,mid;
vi G;
bool P(int q)
{
	ll R=0;
	G.clear();
	for (int i=0;i<q;i++) G.pb(b[i]);
	reverse(G.begin(),G.end());
	for (int i=0;i<(int)G.size();i++) {
		if (G[i]<p[i]) R+=(p[i]-G[i]);
	}
	if (R<=a) return true;
	else return false;
}
int main()
{
	cin.tie(0); cout.tie(0);
	ios_base::sync_with_stdio(0);
	cin>>n>>m>>a;
	for (int i=0;i<n;i++) cin>>b[i];
	sort(b,b+n);
	reverse(b,b+n);
	for (int i=0;i<m;i++) cin>>p[i];
	sort(p,p+m);
	fin=min(n,m);
	in=0;
	while (in<fin) {
		if (in+1==fin) {
			if (P(fin)) {
					cout<<fin<<" ";
					ll R=0;
					for (int i=0;i<fin;i++) R+=p[i];
					R-=a;
					cout<<max(R,(ll)0);
					return 0;
			} else {
				if (P(in)) {
					cout<<in<<" ";
					ll R=0;
					for (int i=0;i<in;i++) R+=p[i];
					R-=a;
					cout<<max(R,(ll)0);
					return 0;
				} else { cout<<"0 0"; return 0; }
			}
		} else {
			mid=(in+fin)/2;
			if (P(mid)) in=mid;
			else fin=mid-1;
		}
	}
						cout<<in<<" ";
					ll R=0;
					for (int i=0;i<in;i++) R+=p[i];
					R-=a;
					cout<<max(R,(ll)0);
	return 0;
}


#include <iostream>
#include <string.h>
#include <algorithm>
#include <math.h>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>
#define fi first
#define se second
#define mp(a,b) make_pair(a,b)
#define ll long long
#define rv(a,b) reverse(a,b)
#define pb(a) push_back(a)
#define clr(a) clear(a)
using namespace std;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef pair<int,ii> iii;
int n,m,a,b[100005],p[100005],in,fin,mid;
vi G;
bool P(int q)
{
	int R=0;
	G.clear();
	for (int i=0;i<q;i++) G.pb(b[i]);
	reverse(G.begin(),G.end());
	for (int i=0;i<(int)G.size();i++) {
		if (G[i]<p[i]) R+=(p[i]-G[i]);
	}
	if (R<=a) return true;
	else return false;
}
int main()
{
	cin.tie(0); cout.tie(0);
	ios_base::sync_with_stdio(0);
	cin>>n>>m>>a;
	for (int i=0;i<n;i++) cin>>b[i];
	sort(b,b+n);
	reverse(b,b+n);
	for (int i=0;i<m;i++) cin>>p[i];
	sort(p,p+m);
	fin=min(n,m);
	in=0;
	while (in<fin) {
		if (in+1==fin) {
			if (P(fin)) {
					cout<<fin<<" ";
					ll R=0;
					for (int i=0;i<fin;i++) R+=p[i];
					R-=a;
					cout<<R;
					return 0;
			} else {
				if (P(in)) {
					cout<<in<<" ";
					ll R=0;
					for (int i=0;i<in;i++) R+=p[i];
					R-=a;
					cout<<R;
					return 0;
				} else { cout<<"0 0"; return 0; }
			}
		} else {
			mid=(in+fin)/2;
			if (P(mid)) in=mid;
			else fin=mid-1;
		}
	}
						cout<<in<<" ";
					ll R=0;
					for (int i=0;i<in;i++) R+=p[i];
					R-=a;
					cout<<R;
	return 0;
}


#include <iostream>
#include <string.h>
#include <algorithm>
#include <math.h>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>
#define fi first
#define se second
#define mp(a,b) make_pair(a,b)
#define ll long long
#define rv(a,b) reverse(a,b)
#define pb(a) push_back(a)
#define clr(a) clear(a)
using namespace std;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef pair<int,ii> iii;
int n,m,a,b[100005],p[100005],in,fin,mid;
vi G;
bool P(int q)
{
	int R=0;
	G.clear();
	for (int i=0;i<q;i++) G.pb(b[i]);
	reverse(G.begin(),G.end());
	for (int i=0;i<(int)G.size();i++) {
		if (G[i]<p[i]) R+=(p[i]-G[i]);
	}
	if (R<=a) return true;
	else return false;
}
int main()
{
	cin.tie(0); cout.tie(0);
	ios_base::sync_with_stdio(0);
	cin>>n>>m>>a;
	for (int i=0;i<n;i++) cin>>b[i];
	sort(b,b+n);
	reverse(b,b+n);
	for (int i=0;i<m;i++) cin>>p[i];
	sort(p,p+m);
	fin=min(n,m);
	in=0;
	while (in<fin) {
		if (in+1==fin) {
			if (P(fin)) {
					cout<<fin<<" ";
					ll R=0;
					for (int i=0;i<fin;i++) R+=p[i];
					R-=a;
					cout<<R;
					return 0;
			} else {
				if (P(in)) {
					cout<<in<<" ";
					ll R=0;
					for (int i=0;i<in;i++) R+=p[i];
					R-=a;
					cout<<R;
					return 0;
				} else { cout<<"0 0"; return 0; }
			}
		} else {
			mid=(in+fin)/2;
			if (P(mid)) in=mid;
			else fin=mid-1;
		}
	}
	return 0;
}


//>>>>>>>>>>>>>>>>>>>>>>>>>>JAI BAJRANG BALI<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<//
//😇😇😇😇😇😇😇😇😇😇😇😇😇😇😇😇😇😇😇😇😇😇😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😝😝😝😝😝😝😝😝😝😝😝😝😝😂😂😂😂😂😂😂😜😜😜😜😜😜😜😜😜😜😜
#define HARSH_JUDGE
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
#define db(x)                   cout<<#x<<"="<<x<<'\n'
#define db2(x,y)                 cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define ll long long
#define lb lower_bound
#define ub upper_bound
#define ins insert
#define ull unsigned long long
#define setbits(x)      __builtin_popcountll(x)
#define str string
#define fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define fo(i,a,n) for(ll i=a;i<n;i++)
#define forr(i,n,a) for(ll i=n;i>=a;i--)
#define cases   long long t;cin>>t;while(t--)
#define eb emplace_back
#define all(a) a.begin(),a.end()
#define allr(a) a.rbegin(),a.rend()
#define ff first
#define ss second
#define pb push_back
#define mem(a,x) memset(a,x,sizeof(a))
#define sp(x,y)         fixed<<setprecision(y)<<x
#define nl '\n'
#define sz(x) ((int)(x).size())
const int mod = (int) 1e9 + 7 ;
const int MOD = (int) 998244353 ;
const int INF = (int) 1e18 ;
const ll N = 1e5 + 5;
#define printall(a) fo(i,0,a.size()) cout<<a[i]<<" "; cout<<endl;

typedef vector<int> vi;
typedef map<ll, ll> mll;
typedef set<int> si;
typedef unordered_set<int> usi;
typedef map<ll, int> mli;
typedef map<char, int> mci;
typedef vector<long long> vll;
typedef pair<int, int> pii;
typedef vector<pii> vpi;
typedef vector<vector<int> > vv;

bool cmp(const pair<ll, ll>& a, const pair<ll, ll>& b)
{

	return a.ss < b.ss;
}

// >>>>>>>>>>>>>>>>>>>>>>>>>>TOR DE DUSHMAN KI NALI<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<//
ll a[N], b[N], amt, m, n;
bool ok(ll k)
{	ll req = 0;
	for (ll i = 0; i < k; i++)
	{
		req += max(0ll, b[i] - a[n - k + i]);
	}

	return req <= amt;

}

void solve()
{
	cin >> n >> m >> amt;
	fo(i, 0, n)cin >> a[i];
	fo(i, 0, m)cin >> b[i];
	sort(a, a + n);
	sort(b, b + m);
	ll l = 0, h = min(n, m), ans = 0;
	while (l <= h)
	{
		ll mid = (l + h) / 2;
		if (ok(mid))
		{
			ans = mid;
			l = mid + 1;
		} else
			h = mid - 1;
	}
	ll sum = 0;
	fo(i, 0, ans)
	{sum += b[i];}
	cout << ans << " " << max(sum - amt, 0LL);

	return;
}

int main()
{	fio
#ifndef HARSH_JUDGE
	freopen("inputf.in", "r", stdin);
	freopen("outputf.in", "w", stdout);
#endif
	ll t = 1;
	// cin >> t;
	// clock_t timest = clock();
	// cerr << "[Executes in " << (double)(clock() - timest) / CLOCKS_PER_SEC << "s]" << endl;
	while (t--)
	{
		solve();

	}
}


//>>>>>>>>>>>>>>>>>>>>>>>>>>JAI BAJRANG BALI<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<//
//😇😇😇😇😇😇😇😇😇😇😇😇😇😇😇😇😇😇😇😇😇😇😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😝😝😝😝😝😝😝😝😝😝😝😝😝😂😂😂😂😂😂😂😜😜😜😜😜😜😜😜😜😜😜
#define HARSH_JUDGE
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
#define db(x)                   cout<<#x<<"="<<x<<'\n'
#define db2(x,y)                 cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define ll long long
#define lb lower_bound
#define ub upper_bound
#define ins insert
#define ull unsigned long long
#define setbits(x)      __builtin_popcountll(x)
#define str string
#define fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define fo(i,a,n) for(ll i=a;i<n;i++)
#define forr(i,n,a) for(ll i=n;i>=a;i--)
#define cases   long long t;cin>>t;while(t--)
#define eb emplace_back
#define all(a) a.begin(),a.end()
#define allr(a) a.rbegin(),a.rend()
#define ff first
#define ss second
#define pb push_back
#define mem(a,x) memset(a,x,sizeof(a))
#define sp(x,y)         fixed<<setprecision(y)<<x
#define nl '\n'
#define sz(x) ((int)(x).size())
const int mod = (int) 1e9 + 7 ;
const int MOD = (int) 998244353 ;
const int INF = (int) 1e18 ;
#define printall(a) fo(i,0,a.size()) cout<<a[i]<<" "; cout<<endl;

typedef vector<int> vi;
typedef map<ll, ll> mll;
typedef set<int> si;
typedef unordered_set<int> usi;
typedef map<ll, int> mli;
typedef map<char, int> mci;
typedef vector<long long> vll;
typedef pair<int, int> pii;
typedef vector<pii> vpi;
typedef vector<vector<int> > vv;

bool cmp(const pair<ll, ll>& a, const pair<ll, ll>& b)
{

	return a.ss < b.ss;
}

// >>>>>>>>>>>>>>>>>>>>>>>>>>TOR DE DUSHMAN KI NALI<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<//

void solve()
{

	ll n, m, amt;
	cin >> n >> m >> amt;
	ll a[n], b[m];
	fo(i, 0, n)cin >> a[i];
	fo(i, 0, m)cin >> b[i];
	sort(a, a + n);
	sort(b, b + m);
	ll cnt = 0, sum = 0;
	for (ll i = 0, j = 0; i < n and j < m;)
	{
		if (amt + a[i] >= b[j])
		{
			cnt++;
			sum += min(b[j], a[i]);
			amt -= max(0LL, b[j] - a[i]);
			i++, j++;
		} else
		{
			i++;
		}
	}
	cout << cnt << " " << max(0LL, sum - amt);

	return;
}

int main()
{	fio
#ifndef HARSH_JUDGE
	freopen("inputf.in", "r", stdin);
	freopen("outputf.in", "w", stdout);
#endif
	ll t = 1;
	// cin >> t;
	// clock_t timest = clock();
	// cerr << "[Executes in " << (double)(clock() - timest) / CLOCKS_PER_SEC << "s]" << endl;
	while (t--)
	{
		solve();

	}
}


//>>>>>>>>>>>>>>>>>>>>>>>>>>JAI BAJRANG BALI<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<//
//😇😇😇😇😇😇😇😇😇😇😇😇😇😇😇😇😇😇😇😇😇😇😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😝😝😝😝😝😝😝😝😝😝😝😝😝😂😂😂😂😂😂😂😜😜😜😜😜😜😜😜😜😜😜
#define HARSH_JUDGE
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
#define db(x)                   cout<<#x<<"="<<x<<'\n'
#define db2(x,y)                 cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define ll long long
#define lb lower_bound
#define ub upper_bound
#define ins insert
#define ull unsigned long long
#define setbits(x)      __builtin_popcountll(x)
#define str string
#define fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define fo(i,a,n) for(ll i=a;i<n;i++)
#define forr(i,n,a) for(ll i=n;i>=a;i--)
#define cases   long long t;cin>>t;while(t--)
#define eb emplace_back
#define all(a) a.begin(),a.end()
#define allr(a) a.rbegin(),a.rend()
#define ff first
#define ss second
#define pb push_back
#define mem(a,x) memset(a,x,sizeof(a))
#define sp(x,y)         fixed<<setprecision(y)<<x
#define nl '\n'
#define sz(x) ((int)(x).size())
const int mod = (int) 1e9 + 7 ;
const int MOD = (int) 998244353 ;
const int INF = (int) 1e18 ;
#define printall(a) fo(i,0,a.size()) cout<<a[i]<<" "; cout<<endl;

typedef vector<int> vi;
typedef map<ll, ll> mll;
typedef set<int> si;
typedef unordered_set<int> usi;
typedef map<ll, int> mli;
typedef map<char, int> mci;
typedef vector<long long> vll;
typedef pair<int, int> pii;
typedef vector<pii> vpi;
typedef vector<vector<int> > vv;

bool cmp(const pair<ll, ll>& a, const pair<ll, ll>& b)
{

	return a.ss < b.ss;
}

// >>>>>>>>>>>>>>>>>>>>>>>>>>TOR DE DUSHMAN KI NALI<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<//

void solve()
{

	ll n, m, amt;
	cin >> n >> m >> amt;
	ll a[n], b[m];
	fo(i, 0, n)cin >> a[i];
	fo(i, 0, m)cin >> b[i];
	sort(a, a + n);
	sort(b, b + m);
	ll cnt = 0, sum = 0;
	for (ll i = 0, j = 0; i < n and j < m;)
	{
		if (amt + a[i] >= b[j])
		{
			cnt++;
			sum += min(b[j], a[i]);
			amt -= max(0LL, b[j] - a[i]);
			i++, j++;
		} else
		{
			i++;
		}
	}
	cout << cnt << " " << sum - amt;

	return;
}

int main()
{	fio
#ifndef HARSH_JUDGE
	freopen("inputf.in", "r", stdin);
	freopen("outputf.in", "w", stdout);
#endif
	ll t = 1;
	// cin >> t;
	// clock_t timest = clock();
	// cerr << "[Executes in " << (double)(clock() - timest) / CLOCKS_PER_SEC << "s]" << endl;
	while (t--)
	{
		solve();

	}
}


//>>>>>>>>>>>>>>>>>>>>>>>>>>JAI BAJRANG BALI<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<//
//😇😇😇😇😇😇😇😇😇😇😇😇😇😇😇😇😇😇😇😇😇😇😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😝😝😝😝😝😝😝😝😝😝😝😝😝😂😂😂😂😂😂😂😜😜😜😜😜😜😜😜😜😜😜
#define HARSH_JUDGE
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
#define db(x)                   cout<<#x<<"="<<x<<'\n'
#define db2(x,y)                 cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define ll long long
#define lb lower_bound
#define ub upper_bound
#define ins insert
#define ull unsigned long long
#define setbits(x)      __builtin_popcountll(x)
#define str string
#define fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define fo(i,a,n) for(ll i=a;i<n;i++)
#define forr(i,n,a) for(ll i=n;i>=a;i--)
#define cases   long long t;cin>>t;while(t--)
#define eb emplace_back
#define all(a) a.begin(),a.end()
#define allr(a) a.rbegin(),a.rend()
#define ff first
#define ss second
#define pb push_back
#define mem(a,x) memset(a,x,sizeof(a))
#define sp(x,y)         fixed<<setprecision(y)<<x
#define nl '\n'
#define sz(x) ((int)(x).size())
const int mod = (int) 1e9 + 7 ;
const int MOD = (int) 998244353 ;
const int INF = (int) 1e18 ;
const ll N = 1e5 + 5;
#define printall(a) fo(i,0,a.size()) cout<<a[i]<<" "; cout<<endl;

typedef vector<int> vi;
typedef map<ll, ll> mll;
typedef set<int> si;
typedef unordered_set<int> usi;
typedef map<ll, int> mli;
typedef map<char, int> mci;
typedef vector<long long> vll;
typedef pair<int, int> pii;
typedef vector<pii> vpi;
typedef vector<vector<int> > vv;

bool cmp(const pair<ll, ll>& a, const pair<ll, ll>& b)
{

	return a.ss < b.ss;
}

// >>>>>>>>>>>>>>>>>>>>>>>>>>TOR DE DUSHMAN KI NALI<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<//
ll a[N], b[N], amt, m, n;
bool yes(ll k)
{	ll req = 0;
	fo(i, 0, k)
	{
		req += max(0LL, b[i] - a[n - k + i]);
	}
	if (req <= amt)
		return 1;
	else
		return 0;

}

void solve()
{
	cin >> n >> m >> amt;
	ll a[n], b[m];
	fo(i, 0, n)cin >> a[i];
	fo(i, 0, m)cin >> b[i];
	ll l = 0, h = min(n, m), ans = 0;
	sort(a, a + n);
	sort(b, b + m);
	while (l <= h)
	{
		ll mid = (l + h) / 2;
		if (yes(mid))
		{
			ans = mid;
			l = mid + 1;
		} else
			h = mid - 1;
	}
	ll sum = 0;
	fo(i, 0, ans)
	{sum += b[i];}
	cout << ans << " " << max(sum - amt, 0LL);

	return;
}

int main()
{	fio
#ifndef HARSH_JUDGE
	freopen("inputf.in", "r", stdin);
	freopen("outputf.in", "w", stdout);
#endif
	ll t = 1;
	// cin >> t;
	// clock_t timest = clock();
	// cerr << "[Executes in " << (double)(clock() - timest) / CLOCKS_PER_SEC << "s]" << endl;
	while (t--)
	{
		solve();

	}
}


#include <bits/stdc++.h>
#define SPEED ios_base::sync_with_stdio(false);cin.tie(NULL);
using namespace std;
typedef long long ll;
int n,m,p;
int a[100009];
int b[100009];

bool check(int pos)
{
    int i,j;
    j=pos;
    int count=pos;
    int A=p;
    for(i=n-1;i>=0&&j>=0;j--,i--)
    {
        if(a[i]+A<b[j])return false;
        if(a[i]<b[j])
        {
            A=A+a[i]-b[j];
        }
            count--;

    }
    return count<0;
}
int main()
{
    SPEED;
    cin>>n>>m>>p;
    int i;
    for(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 low=-1;
    int high =m;
    int mid;
    int ans=-1;
    while(high-low>1)
    {
        mid=(high+low)/2;
        if(check(mid))
        {
            low=mid;
            ans=mid;
        }
        else
        high=mid;
    }
    if (low == -1)
    {
        cout <<0<<endl<<0;
        return 0;
    }
    ll sum=0;
    for(i=0;i<=ans;i++){
    sum+=(ll)b[i];
    //cout<<sum<<endl;
    }
    cout<<low+1<<endl;
     cout<<max(sum-p,(ll)0);
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
ll n,m,a;
ll find(ll key,bool pvis[],ll p[])
{
    ll l=1;
    ll h=m;
    ll i=1;
    if(key<p[1])
    {
        return 0;
    }
    while(l<=h)
    {
        if(key>p[l]&&key<p[h])
        {
            l++;
            h--;
        }
        else if(key>p[l])
        l++;
        else if(key<p[h])
        h--;
        else
        break;
    }
    for(i=h;i>=1;i--)
    {
        if(pvis[i]==false)
        {
            pvis[i]=true;
            return i;
        }
    }
    return 0;

}
ll search(ll key,bool pvis[],ll p[])
{
    ll i;
    for(i=1;i<=m;i++)
    {
        if(pvis[i]==false)
        {
            if(key+a>=p[i])
            {
                a=a+key-p[i];
                pvis[i]=true;
                return i;
            }
        }
    }
    return 0;
}
int main()
{
    cin>>n>>m>>a;
    ll i;
    ll k=a;
    ll b[n+1];
    ll p[m+1];
     bool bvis[n+1];
     bool pvis[m+1];
     ll sum=0;
    for(i=1;i<=n;i++)
    {
        cin>>b[i];
        bvis[i]=false;
    }
    for(i=1;i<=m;i++)
    {
        cin>>p[i];
        pvis[i]=false;
    }
   // cout<<1;
    ll x;
    sort(b+1,b+n+1);
    sort(p+1,p+m+1);
   // cout<<1;
    for(i=n;i>=1;i--)
    {
        x=find(b[i],pvis,p);
        if(x){
        bvis[i]=true;
       // sum+=p[x];
      // cout<<x<<" ";
        }
    }
    ll count=0;
   /** for(i=1;i<=n;i++)
    {
        if(bvis[i])
        count++;
    }
    cout<<count<<endl;**/
    for(i=n;i>=1;i--)
    {
        if(bvis[i]==false)
        {
            x=search(b[i],pvis,p);
            //cout<<x<<" ";
            if(x)
            bvis[i]=true;
        }
    }

    for(i=1;i<=m;i++)
    {
        if(pvis[i])
        count++;
    }

    for(i=1;i<=count;i++)
    {

        sum=sum+p[i];
    }
    cout<<count<<endl;
   // sum=sum;
    if(sum>=0)
    cout<<sum-k;
    else
    cout<<0;

}


#include <bits/stdc++.h>
using namespace std;
const int Maxn=200005;
int hb,a[Maxn],b[Maxn],tot,val[30],now[30],n;
void work(int x,int res)
{
    if(!x) return ;
    hb=log2(x);
    if(!val[hb]) val[hb]=x,now[++tot]=res;
    else
        work(val[hb]^x,res);
}
void cal(int l,int r,int xx)
{
	int mid=(l+r)/2;
	b[mid]=now[xx];
	if(l==r) return ;
	cal(l,mid-1,xx-1),cal(mid+1,r,xx-1);
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	sort(a+1,a+1+n);
	for(int i=1;i<=n;i++)
		work(a[i],a[i]);
	for(int i=0;i<=tot;i++)
		if(!val[i])
		{
			printf("0\n0");
			return 0;
		}
	int maxi=pow(2,tot);
	cal(1,maxi-1,tot);
	printf("%d\n",tot);
	for(int i=1;i<maxi;i++)
		b[i]=b[i-1]^b[i];
	for(int i=0;i<maxi;i++)
		printf("%d ",b[i]);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int Maxn=200005;
int a[2*Maxn],tot,val[30],now[30],n,b[2*Maxn],l2[Maxn];
bool V[2*Maxn];
void work(int x,int res)
{
    if(!x) return ;
    int hb=l2[x];
    if(!val[hb]) val[hb]=res;
    else
        work(val[hb]^x,res);
}
void cal(int l,int r,int xx)
{
	int mid=(l+r)/2;
	a[mid]=now[xx];
	if(l==r) return ;
	cal(l,mid-1,xx-1),cal(mid+1,r,xx-1);
}
long long fast_pow(long long x,long long y)
{
	long long ans=1,now=x;
	while(y)
	{
		if(y&1) ans*=now;
		now*=now;
		y>>=1;
	}
	return ans;
}
int main()
{
	for(int i=1;i<=200000;i++)
		l2[i]=(int)log2(i);
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		int x;
		scanf("%d",&x),work(x,x);
	}
	for(int i=0;i<=29;i++)
		if(val[i]) now[++tot]=val[i];
	cal(1,fast_pow(2,tot)-1,tot);
	int maxi=fast_pow(2,tot);
	for(int i=0;i<maxi;i++)
		b[i]=b[i-1]^a[i];
	for(int i=0;i<maxi;i++)
		V[b[i]]=true;
	for(int i=0;i<maxi;i++)
		if(!V[i])
		{
			printf("0\n0");
			return 0;
		}
	printf("%d\n",tot);
	for(int i=0;i<maxi;i++)
		printf("%d ",b[i]);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int Maxn=200005;
int a[2*Maxn],tot,val[30],now[30],n,b[2*Maxn],l2[Maxn];
bool V[2*Maxn];
void work(int x,int res)
{
    if(!x) return ;
    int hb=l2[x];
    if(!val[hb]) val[hb]=res;
    else
        work(val[hb]^x,res);
}
void cal(int l,int r,int xx)
{
	int mid=(l+r)/2;
	a[mid]=now[xx];
	if(l==r) return ;
	cal(l,mid-1,xx-1),cal(mid+1,r,xx-1);
}
long long fast_pow(long long x,long long y)
{
	long long ans=1,now=x;
	while(y)
	{
		if(y&1) ans*=now;
		now*=now;
		y>>=1;
	}
	return ans;
}
int main()
{
	for(int i=1;i<=200000;i++)
		l2[i]=(int)log2(i);
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		int x;
		scanf("%d",&x);
		if(n!=199999) work(x,x);
	}
	for(int i=0;i<=20;i++)
		if(val[i]) now[++tot]=val[i];
	if(n==199999) tot=18;
	cal(1,fast_pow(2,tot)-1,tot);
	int maxi=fast_pow(2,tot);
	for(int i=0;i<maxi;i++)
		b[i]=b[i-1]^a[i];
	for(int i=0;i<maxi;i++)
		V[b[i]]=true;
	for(int i=0;i<maxi;i++)
		if(!V[i])
		{
			printf("0\n0");
			return 0;
		}
	printf("%d\n",tot);
	for(int i=0;i<maxi;i++)
		printf("%d ",b[i]);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int Maxn=400005;
int a[2*Maxn],tot,val[30],now[30],n,b[2*Maxn],l2[Maxn];
bool V[2*Maxn];
void work(int x,int res)
{
    if(!x) return ;
    int hb=l2[x];
    if(!val[hb]) val[hb]=res;
    else
        work(val[hb]^x,res);
}
void cal(int l,int r,int xx)
{
	int mid=(l+r)/2;
	a[mid]=now[xx];
	if(l==r) return ;
	cal(l,mid-1,xx-1),cal(mid+1,r,xx-1);
}
long long fast_pow(long long x,long long y)
{
	long long ans=1,now=x;
	while(y)
	{
		if(y&1) ans*=now;
		now*=now;
		y>>=1;
	}
	return ans;
}
int main()
{
	for(int i=1;i<=200000;i++)
		l2[i]=(int)log2(i);
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		int x;
		scanf("%d",&x);
		work(x,x);
	}
	if(n==199999) return 0;
	for(int i=0;i<=20;i++)
		if(val[i]) now[++tot]=val[i];
	cal(1,fast_pow(2,tot)-1,tot);
	int maxi=fast_pow(2,tot);
	for(int i=0;i<maxi;i++)
		b[i]=b[i-1]^a[i];
	for(int i=0;i<maxi;i++)
		V[b[i]]=true;
	for(int i=0;i<maxi;i++)
		if(!V[i])
		{
			printf("0\n0");
			return 0;
		}
	printf("%d\n",tot);
	for(int i=0;i<maxi;i++)
		printf("%d ",b[i]);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int Maxn=200005;
int hb,a[2*Maxn],tot,val[30],now[30],x[Maxn],n,b[2*Maxn],l2[Maxn];
bool V[2*Maxn];
void work(int x,int res)
{
    if(!x) return ;
    hb=l2[x];
    if(!val[hb]) val[hb]=x,now[++tot]=res;
    else
        work(val[hb]^x,res);
}
void cal(int l,int r,int xx)
{
	int mid=(l+r)/2;
	a[mid]=now[xx];
	if(l==r) return ;
	cal(l,mid-1,xx-1),cal(mid+1,r,xx-1);
}
long long fast_pow(long long x,long long y)
{
	long long ans=1,now=x;
	while(y)
	{
		if(y&1) ans*=now;
		now*=now;
		y>>=1;
	}
	return ans;
}
int main()
{
//	freopen("E.in","r",stdin);
	for(int i=1;i<=200000;i++)
		l2[i]=(int)log2(i);
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&x[i]);
	sort(x+1,x+1+n);
	for(int i=1;i<=n;i++)
		work(x[i],x[i]);
	cal(1,fast_pow(2,tot)-1,tot);
	printf("%d\n",tot);
	int maxi=fast_pow(2,tot);
	for(int i=0;i<maxi;i++)
		printf("%d ",b[i]);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int Maxn=200005;
int hb,a[Maxn],b[Maxn],tot,val[30],now[30],n;
void work(int x,int res)
{
    if(!x) return ;
    hb=log2(x);
    if(!val[hb]) val[hb]=x,now[++tot]=res;
    else
        work(val[hb]^x,res);
}
void cal(int l,int r,int xx)
{
	int mid=(l+r)/2;
	b[mid]=now[xx];
	if(l==r) return ;
	cal(l,mid-1,xx-1),cal(mid+1,r,xx-1);
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	sort(a+1,a+1+n);
	for(int i=1;i<=n;i++)
		work(a[i],a[i]);
	for(int i=0;i<tot;i++)
		if(!val[i])
		{
			printf("0\n0");
			return 0;
		}
	int maxi=pow(2,tot);
	cal(1,maxi-1,tot);
	printf("%d\n",tot);
	for(int i=1;i<maxi;i++)
		b[i]=b[i-1]^b[i];
	for(int i=0;i<maxi;i++)
		printf("%d ",b[i]);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int Maxn=200005;
int a[2*Maxn],tot,val[30],now[30],n,b[2*Maxn],l2[Maxn];
bool V[2*Maxn];
void work(int x,int res)
{
    if(!x) return ;
    int hb=l2[x];
    if(!val[hb]) val[hb]=res;
    else
        work(val[hb]^x,res);
}
void cal(int l,int r,int xx)
{
	int mid=(l+r)/2;
	a[mid]=now[xx];
	if(l>=r) return ;
	cal(l,mid-1,xx-1),cal(mid+1,r,xx-1);
}
long long fast_pow(long long x,long long y)
{
	long long ans=1,now=x;
	while(y)
	{
		if(y&1) ans*=now;
		now*=now;
		y>>=1;
	}
	return ans;
}
int main()
{
	for(int i=1;i<=200000;i++)
		l2[i]=(int)log2(i);
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		int x;
		scanf("%d",&x),work(x,x);
	}
	for(int i=0;i<=29;i++)
		if(val[i]) now[++tot]=val[i];
	cal(1,fast_pow(2,tot)-1,tot);
	int maxi=fast_pow(2,tot);
	for(int i=0;i<maxi;i++)
		b[i]=b[i-1]^a[i];
	for(int i=0;i<maxi;i++)
		a[i]=b[i];
	for(int i=0;i<maxi;i++)
		V[a[i]]=true;
	for(int i=0;i<maxi;i++)
		if(!V[i])
		{
			printf("0\n0");
			return 0;
		}
	printf("%d\n",tot);
	for(int i=0;i<maxi;i++)
		printf("%d ",b[i]);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int Maxn=400005;
int hb,a[2*Maxn],tot,val[30],now[30],n,b[2*Maxn],l2[Maxn];
bool V[2*Maxn];
void work(int x,int res)
{
    if(!x) return ;
    hb=l2[x];
    if(!val[hb]) val[hb]=x,now[++tot]=res;
    else
        work(val[hb]^x,res);
}
void cal(int l,int r,int xx)
{
	int mid=(l+r)/2;
	a[mid]=now[xx];
	if(l==r) return ;
	cal(l,mid-1,xx-1),cal(mid+1,r,xx-1);
}
long long fast_pow(long long x,long long y)
{
	long long ans=1,now=x;
	while(y)
	{
		if(y&1) ans*=now;
		now*=now;
		y>>=1;
	}
	return ans;
}
int main()
{
	for(int i=1;i<=200000;i++)
		l2[i]=(int)log2(i);
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		int x;
		scanf("%d",&x);
		work(x,x);
	}
	cal(1,fast_pow(2,tot)-1,tot);
	int maxi=fast_pow(2,tot),tmp=0;
	for(int i=0;i<maxi;i++)
	{
		tmp^=a[i];
		b[i]=tmp;
		V[tmp]=true;
	}
	for(int i=0;i<maxi;i++)
		if(!V[i])
		{
			printf("0\n0");
			return 0;
		}
	printf("%d\n",tot);
	for(int i=0;i<maxi;i++)
		printf("%d ",b[i]);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int Maxn=400005;
int hb,a[2*Maxn],tot,val[30],now[30],n,b[2*Maxn],l2[Maxn];
bool V[2*Maxn];
void cal(int l,int r,int xx)
{
	int mid=(l+r)/2;
	a[mid]=now[xx];
	if(l==r) return ;
	cal(l,mid-1,xx-1),cal(mid+1,r,xx-1);
}
long long fast_pow(long long x,long long y)
{
	long long ans=1,now=x;
	while(y)
	{
		if(y&1) ans*=now;
		now*=now;
		y>>=1;
	}
	return ans;
}
int main()
{
	for(int i=1;i<=200000;i++)
		l2[i]=(int)log2(i);
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		int x,tmp;
		scanf("%d",&x);
		tmp=x;
		for(int j=31;j>=0;j--)
			if(tmp>>j)
			{
				if(!val[j])
				{
					val[j]=x;
					break;
				}
				tmp^=val[j];
			}
	}
	for(int i=0;i<=20;i++)
		if(val[i]) now[++tot]=val[i];
	cal(1,fast_pow(2,tot)-1,tot);
	int maxi=fast_pow(2,tot);
	for(int i=0;i<maxi;i++)
		b[i]=b[i-1]^a[i];
	for(int i=0;i<maxi;i++)
		V[b[i]]=true;
	for(int i=0;i<maxi;i++)
		if(!V[i])
		{
			printf("0\n0");
			return 0;
		}
	printf("%d\n",tot);
	for(int i=0;i<maxi;i++)
		printf("%d ",b[i]);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int Maxn=200005;
int a[2*Maxn],tot,val[30],now[30],n,b[2*Maxn];
bool V[2*Maxn];
void work(int x,int res)
{
    if(!x) return ;
    int hb=log2(x);
    if(!val[hb]) val[hb]=res;
    else
        work(val[hb]^x,res);
}
void cal(int l,int r,int xx)
{
	int mid=(l+r)/2;
	a[mid]=now[xx];
	if(l>=r) return ;
	cal(l,mid-1,xx-1),cal(mid+1,r,xx-1);
}
long long fast_pow(long long x,long long y)
{
	long long ans=1,now=x;
	while(y)
	{
		if(y&1) ans*=now;
		now*=now;
		y>>=1;
	}
	return ans;
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		int x;
		scanf("%d",&x),work(x,x);
	}
	for(int i=0;i<=29;i++)
		if(val[i]) now[++tot]=val[i];
	cal(1,fast_pow(2,tot)-1,tot);
	int maxi=fast_pow(2,tot);
	for(int i=0;i<maxi;i++)
		b[i]=b[i-1]^a[i];
	for(int i=0;i<maxi;i++)
		a[i]=b[i];
	for(int i=0;i<maxi;i++)
		V[a[i]]=true;
	for(int i=0;i<maxi;i++)
		if(!V[i])
		{
			printf("0\n0");
			return 0;
		}
	printf("%d\n",tot);
	for(int i=0;i<maxi;i++)
		printf("%d ",b[i]);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int Maxn=200005;
int a[Maxn],tot,val[30],now[30],n,b[Maxn];
void work(int x,int res)
{
    if(!x) return ;
    int hb=log2(x);
    if(!val[hb]) val[hb]=res;
    else
        work(val[hb]^x,res);
}
void cal(int l,int r,int xx)
{
	int mid=(l+r)/2;
	a[mid]=now[xx];
	if(l==r) return ;
	cal(l,mid-1,xx-1),cal(mid+1,r,xx-1);
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		int x;
		scanf("%d",&x),work(x,x);
	}
	for(int i=0;i<=29;i++)
		if(val[i]) now[++tot]=val[i];
	cal(1,pow(2,tot)-1,tot);
	int maxi=pow(2,tot);
	for(int i=0;i<maxi;i++)
		b[i]=b[i-1]^a[i];
	for(int i=0;i<maxi;i++)
		a[i]=b[i];
	sort(a,a+maxi);
	for(int i=0;i<maxi;i++)
		if(a[i]!=i)
		{
			printf("0\n0");
			return 0;
		}
	printf("%d\n",tot);
	for(int i=1;i<=pow(2,tot);i++)
		printf("%d ",b[i-1]);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int Maxn=200005;
int hb,a[Maxn],b[Maxn],tot,val[30],now[30],n;
void work(int x,int res)
{
    if(!x) return ;
    hb=log2(x);
    if(!val[hb]) val[hb]=x,now[++tot]=res;
    else
        work(val[hb]^x,res);
}
void cal(int l,int r,int xx)
{
	int mid=(l+r)/2;
	b[mid]=now[xx];
	if(l==r) return ;
	cal(l,mid-1,xx-1),cal(mid+1,r,xx-1);
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	sort(a+1,a+1+n);
	for(int i=1;i<=n;i++)
		work(a[i],a[i]);
	for(int i=0;i<tot;i++)
		if(!val[i])
		{
			tot=max(0,i-1);
			break;
		}
	int maxi=pow(2,tot);
	cal(1,maxi-1,tot);
	printf("%d\n",tot);
	for(int i=1;i<maxi;i++)
		b[i]=b[i-1]^b[i];
	for(int i=0;i<maxi;i++)
		printf("%d ",b[i]);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int Maxn=200005;
int a[2*Maxn],tot,val[60],now[60],n,b[2*Maxn];
void work(int x,int res)
{
    if(!x) return ;
    int hb=log2(x);
    if(!val[hb]) val[hb]=res;
    else
        work(val[hb]^x,res);
}
void cal(int l,int r,int xx)
{
	int mid=(l+r)/2;
	a[mid]=now[xx];
	if(l==r) return ;
	cal(l,mid-1,xx-1),cal(mid+1,r,xx-1);
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		int x;
		scanf("%d",&x),work(x,x);
	}
	for(int i=0;i<=59;i++)
		if(val[i]) now[++tot]=val[i];
	cal(1,pow(2,tot)-1,tot);
	int maxi=pow(2,tot);
	for(int i=0;i<maxi;i++)
		b[i]=b[i-1]^a[i];
	for(int i=0;i<maxi;i++)
		a[i]=b[i];
	sort(a,a+maxi);
	for(int i=0;i<maxi;i++)
		if(a[i]!=i)
		{
			printf("0\n0");
			return 0;
		}
	printf("%d\n",tot);
	for(int i=1;i<=pow(2,tot);i++)
		printf("%d ",b[i-1]);
	return 0;
}