#include using namespace std; int main() { int n, a[1001][3], ans[2] = { 0 },kaishi=1; bool pan = 0; string s; cin >> n; for (int i = 1; i <= n; i++) { int yi, er; cin >> s >> a[i][1] >> a[i][2]; yi = a[i][1], er = a[i][2]; if (s == "on") { a[i][0] = 1; ans[0] += a[i][1]; ans[1] += a[i][2]; } if (s == "none") { a[i][0] = 2; kaishi=i; if (pan == 1) { if (yi > ans[0]) { ans[0] = yi; } if (er < ans[1]) { ans[1] = er; } } else { ans[0] = a[i][1]; ans[1] = a[i][2]; } pan = 1; } if (s == "off") { a[i][0] = 3; ans[0] -= a[i][2]; ans[1] -= a[i][1]; if(ans[0]<0){ ans[0]=0; } } //cout << ans[0] << " " << ans[1] << endl; } int ans1[2]; pan=0; for(int i=kaishi;i>=1;i--){ int yi = a[i][1], er = a[i][2]; if (a[i][0]==3) { ans1[0] += a[i][1]; ans1[1] += a[i][2]; } if (a[i][0] == 2) { kaishi=i; if (pan == 1) { if (yi > ans1[0]) { ans1[0] = yi; } if (er < ans1[1]) { ans1[1] = er; } } else { ans1[0] = a[i][1]; ans1[1] = a[i][2]; } pan = 1; } if (a[i][0]==1) { ans1[0] -= a[i][2]; ans1[1] -= a[i][1]; if(ans1[0]<0){ ans1[0]=0; } } } cout << ans1[0] << " " << ans1[1]<