#include <iostream>
using namespace std;
int main()
{
int n;
while (cin>>n)
{
int x = 0, y = 0, numa = 0, numb = 0;
int a[1000] = { 0 };
int b[1000] = { 0 };
for (int i = 0; i < n; i++)
{
cin >> a[i];
cin >> b[i];
}
for (int i = 0; i < n; i++)
{
if (b[i] == 1)
{
x += a[i];
numa++;
}
if (b[i] == 2)
{
y += a[i];
numb++;
}
}
numa = x / numa;
numb = y / numb;
cout << numa << ' ' << numb << "\r\n";
}
return 0;
}