#include <bits/stdc++.h>
using namespace std;
int n, m, k;
bool debug = false;
int l[7][7], r[7][7], in[7], a[7][7];
int cost, out, mc;
void dfs(int f, int t) {
  if (f == n) {
    mc = max(mc, cost);
  } else if (t > n) {
    if (!in[f]) dfs(f + 1, f + 2);
  } else {
    for (int j = l[f][t]; j <= r[f][t]; j++) {
      if (in[f] < j) break;
      in[f] -= j;
      in[t] += j;
      cost += (j ? a[f][t] : 0) + j * j;
      dfs(f, t + 1);
      in[f] += j;
      in[t] -= j;
      cost -= (j ? a[f][t] : 0) + j * j;
    }
  }
}
int main() {
  scanf("%d", &n);
  int aa, b;
  for (int i = 1; i <= n * (n - 1) / 2; i++) {
    scanf("%d%d", &aa, &b);
    scanf("%d%d%d", &l[aa][b], &r[aa][b], &a[aa][b]);
  }
  for (int i = 0; i <= 30; i++) {
    in[1] = i;
    cost = 0;
    mc = -1;
    dfs(1, 2);
    if (mc >= 0) {
      printf("%d %d\n", i, mc);
      return 0;
    }
  }
  puts("-1 -1");
  return 0;
}
