#include<bits/stdc++.h>
using namespace std;
int a[5];
int main(){
	int n,x,y,z;
	scanf("%d",&n);
	memset(a,0,sizeof(a));
	for (int i = 1; i <= n; i++){
			int f;
			scanf("%d%d%d",&x,&y,&z);
			if (z == 1) f = 1;
			else f = -1;
			a[x] += y * f * 3;
			for (int j = 1; j <= 4; j++)
				if (j != x) a[j] += (-y)*f;
	}
	printf("%d %d %d %d\n",a[1],a[2],a[3],a[4]);
	return 0;
}