#include #include using namespace std; int n,m,i,fin,fin1; struct pie { int x,y; }a[100000]; int cmp(pie a,pie b) { if(a.x!=b.x) return a.xb.y; } int main() { scanf("%d %d",&n,&m); for(i=1;i<=n;i++) scanf("%d %d",&a[i].x,&a[i].y); sort(a+1,a+n+1,cmp); for(i=1;i<=n/2;i++) fin+=a[i].x; for(i=n/2+1;i<=n;i++) fin1+=a[i].y; printf("%d %d",fin,fin1); return 0; }