#include <bits/stdc++.h>
int n, ans, l[10][10], r[10][10], f[10], c[10][10];
void dfs(int s, int t, int fl, int cost) {
  if (s == n) {
    if (ans < cost) ans = cost;
    return;
  }
  if (t > n) {
    if (fl == 0) dfs(s + 1, s + 2, f[s + 1], cost);
  } else
    for (int i = l[s][t]; i <= r[s][t] && i <= fl; ++i) {
      f[t] += i;
      dfs(s, t + 1, fl - i, cost + i * i + (i ? c[s][t] : 0));
      f[t] -= i;
    }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n * (n - 1) / 2; ++i) {
    int a, b, p, q, co;
    scanf("%d%d%d%d%d", &a, &b, &p, &q, &co);
    l[a][b] = p, r[a][b] = q, c[a][b] = co;
  }
  for (int i = 0; i <= 25; ++i) {
    ans = -1;
    dfs(1, 2, i, 0);
    if (ans >= 0) {
      printf("%d %d\n", i, ans);
      return 0;
    }
  }
  puts("-1 -1");
  return 0;
}
