#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
int N;
cin >> N;
vector<int> fun;
for (int i = 0; i < N; ++i) {
int input;
cin >> input;
fun.push_back(input);
}
long long sum1 = 0;
long long sum2 = 0;
for (int i = 0; i < N; ++i) {
int flag;
cin >> flag;
sum1 += (long long)fun[i];
if (!flag) sum2 += (long long)fun[i];
}
cout << sum1 << "\n" << sum2;
return 0;
}