#include <bits/stdc++.h>
using namespace std;
int n, m, ans, d[100];
struct bian {
  int l, h, w;
} e[20][20];
void dfs(int u, int v, int f, int cost) {
  if (u == n) {
    ans = max(ans, cost);
    return;
  }
  if (v > n) {
    if (f == 0) dfs(u + 1, u + 2, d[u + 1], cost);
  } else
    for (int i = e[u][v].l; i <= e[u][v].h && i <= f; i++) {
      d[v] += i;
      int lin = cost + i * i;
      if (i) lin += e[u][v].w;
      dfs(u, v + 1, f - i, lin);
      d[v] -= i;
    }
}
int main() {
  scanf("%d", &n);
  m = n * (n - 1) / 2;
  for (int i = 1; i <= m; ++i) {
    int u, v, l, h, w;
    scanf("%d%d%d%d%d", &u, &v, &l, &h, &w);
    e[u][v].l = l;
    e[u][v].h = h;
    e[u][v].w = w;
  }
  ans = -1;
  for (int i = 0; i < 30; i++) {
    dfs(1, 2, i, 0);
    if (ans >= 0) {
      printf("%d %d\n", i, ans);
      return 0;
    }
  }
  printf("-1 -1\n");
}
