#include using namespace std; int main () { int N, M, W; cin >> N >> M >> W; int n = N + M; int wei[20]; int val[20]; for (int i = 0; i < N; i ++) { cin >> wei[i] >> val[i]; } for (int i = N; i < N + M; i ++) { cin >> wei[i] >> val[i]; wei[i] *= -1; val[i] *= -1; } int dp[1 << 14][505]; int inf = 1e9 + 7; for (int i = 0; i < (1 << n); i ++) { for (int j = 0; j <= W; j ++) { dp[i][j] = -inf; } } dp[0][0] = 0; for (int i = 1; i < (1 << n); i ++) { for (int j = 0; j < n; j ++) { if ((i >> j) & 1) { for (int k = 0; k <= W; k ++) { dp[i][k] = max(dp[i][k], dp[i - (1 << j)][k]); } for (int k = max(0, -wei[j]); k <= min(W, W - wei[j]); k ++) { dp[i][k + wei[j]] = max(dp[i][k + wei[j]], dp[i - (1 << j)][k] + val[j]); } } } } int ans = 0; for (int i = 0; i <= W; i ++) { ans = max(ans, dp[(1 << n) - 1][W]); } cout << ans << endl; }