#include <bits/stdc++.h>
using namespace std;
int res = ((int)1e9), cost = 0;
int n, m[8][8], M[8][8], c[8][8];
int E[60][2], e, D[8], Le[8];
int F[8][8];
void gen(int ne) {
  int tmp2 = 0, i, j;
  if (ne == e) {
    for (i = 0; i < n; i++)
      for (j = i + 1; j < n; j++)
        if (F[i][j] > 0) tmp2 += c[i][j] + F[i][j] * F[i][j];
    if (res > -D[n - 1] || (res == -D[n - 1] && cost < tmp2))
      res = -D[n - 1], cost = tmp2;
    return;
  }
  int v1 = E[ne][0], v2 = E[ne][1];
  for (F[v1][v2] = m[v1][v2], D[v1] += m[v1][v2], D[v2] -= m[v1][v2];
       F[v1][v2] <= M[v1][v2]; F[v1][v2]++, D[v1]++, D[v2]--) {
    if (v1 > 0 && Le[v1] == ne && D[v1] != 0) {
      continue;
    }
    gen(ne + 1);
  }
  D[v1] -= M[v1][v2] + 1;
  D[v2] += M[v1][v2] + 1;
}
int main() {
  int i, j, v1, v2, x, y, z;
  scanf("%d", &n);
  for (i = 0; i < (n * (n - 1)) / 2; i++) {
    scanf("%d%d%d%d%d", &v1, &v2, &x, &y, &z);
    v1--, v2--;
    m[v1][v2] = x, M[v1][v2] = y, c[v1][v2] = z;
  }
  for (i = 0; i < n; i++) {
    for (j = i + 1; j < n; j++) E[e][0] = i, E[e][1] = j, e++;
    Le[i] = e - 1;
  }
  gen(0);
  if (res == ((int)1e9))
    printf("-1 -1\n");
  else
    printf("%d %d", res, cost);
  return 0;
}
