#include using namespace std; /* * */ int main() { int n, m,wb = 0,bb = 0; cin >> n >> m; int w[50000][2]; for (int i = 0;i < n ; i++) { cin >> w[i][0] >> w[i][1]; } int ok = 1; while(ok) { ok = 0; for(int i = 0; i< n;i++) for(int j = i+ 1; j< n;j++) if(w[i][0] < w[j][0]) { int aux = w[i][0]; w[i][0] = w[j][0]; w[j][0] = aux; aux = w[i][1]; w[i][1] = w[j][1]; w[j][1] = aux; ok = 1; } } for (int i = 0;i < n/2 ; i++) wb += w[i][0]; for (int i = n/2;i < n ; i++) bb += w[i][1]; cout << bb << ' ' << wb; return 0; }