#include <bits/stdc++.h>
using std::cin;
using std::cout;
int minFlow, maxFlow, n, flow[10], l[10][10], h[10][10], a[10][10];
void dfs(int u, int v, int cost) {
  if (u == n) {
    maxFlow = std::max(maxFlow, cost);
    return;
  }
  if (v > n) {
    if (!flow[u]) dfs(u + 1, u + 2, cost);
    return;
  }
  for (register int i = l[u][v]; i <= h[u][v]; i++) {
    if (flow[v] < 0) break;
    flow[u] -= i, flow[v] += i;
    dfs(u, v + 1, cost + (!i ? 0 : a[u][v] + i * i));
    flow[u] += i, flow[v] -= i;
  }
}
int main() {
  std::ios::sync_with_stdio(0);
  cin.tie(0);
  while (cin >> n) {
    for (register int i = 0, u, v; i < (n * (n - 1)) / 2; i++)
      cin >> u >> v, cin >> l[u][v] >> h[u][v] >> a[u][v];
    maxFlow = -1;
    for (minFlow = 0; minFlow <= 50; minFlow++) {
      flow[1] = minFlow;
      dfs(1, 2, 0);
      if (~maxFlow) break;
    }
    if (~maxFlow)
      cout << minFlow << " " << maxFlow << "\n";
    else
      cout << "-1 -1\n";
  }
  return 0;
}
