#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
int N;
//cout << "請輸入共有幾行指令" << endl;
cin >> N;
int x=0, y=0;
int *ptrx=&x, *ptry=&y;
for (int i=0; i<N; i++){
int a,b;
//cout << "請輸入方向" << endl;
cin >> a;
//cout << "請輸入距離" << endl;
cin >> b;
if (a==0){
x=x+b;
}
else if(a==1){
y=y+b;
}
else if(a==2){
x=x-b;
}
else if(a==3){
y=y-b;
}
}
cout << *ptry << " " << *ptrx <<endl;
return 0;
}