#include <bits/stdc++.h>
using namespace std;
const int maxn = 6;
const int maxe = 15;
int a[maxn][maxn][3];
int exc[maxn];
int edge[maxe][2];
int n, m;
int minf, ans;
void solve(int pos, int ansn, int f) {
  if (f > minf) return;
  if (pos == m) {
    if ((f < minf) || (ans < ansn)) {
      ans = ansn;
      minf = f;
    }
    return;
  }
  int fr = edge[pos][0];
  int t = edge[pos][1];
  for (int i = a[fr][t][0]; i <= a[fr][t][1]; i++) {
    exc[fr] -= i;
    exc[t] += i;
    if ((t != n - 1) || (!fr) || (!exc[fr])) {
      solve(pos + 1, ansn + (!i ? 0 : a[fr][t][2] + (i * i)),
            f + (!fr ? i : 0));
    }
    exc[fr] += i;
    exc[t] -= i;
  }
}
int main() {
  while (scanf("%d", &n) >= 1) {
    m = n * (n - 1) / 2;
    for (int i = 0; i < m; i++) {
      int s, t;
      scanf("%d%d", &s, &t);
      s--, t--;
      for (int j = 0; j < 3; j++) scanf("%d", &a[s][t][j]);
    }
    int num = 0;
    for (int i = 0; i < n; i++) {
      for (int j = i + 1; j < n; j++) {
        edge[num][0] = i;
        edge[num++][1] = j;
      }
      exc[i] = 0;
    }
    assert(num == m);
    ans = 0;
    minf = ((int)1E9);
    solve(0, 0, 0);
    if (minf == ((int)1E9))
      printf("-1 -1\n");
    else
      printf("%d %d\n", minf, ans);
  }
  return 0;
}
