#include <bits/stdc++.h>
using namespace std;
const int N = 10;
int n, ans, tot, flow[N][N], a[N][N], l[N][N], h[N][N];
void dfs(int s, int t, int c) {
  if (t == n + 1) {
    int in = 0, out = 0;
    for (int i = (int)1, _y = n; i <= _y; i++)
      in += flow[i][s], out += flow[s][i];
    if ((s == 1 && out == tot) || (s == n && in == tot) ||
        (s != 1 && s != n && in == out))
      dfs(s + 1, s + 2, c);
    return;
  }
  if (s == n + 1) {
    ans = max(ans, c);
    return;
  }
  for (int i = (int)l[s][t], _y = h[s][t]; i <= _y; i++) {
    flow[s][t] += i;
    dfs(s, t + 1, c + (i ? a[s][t] : 0) + i * i);
    flow[s][t] -= i;
  }
}
int main() {
  scanf("%d", &n);
  for (int i = (int)1, _y = n * (n - 1) / 2; i <= _y; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    scanf("%d%d%d", &l[u][v], &h[u][v], &a[u][v]);
  }
  for (int w = (int)0, _y = 36; w <= _y; w++) {
    ans = -1e9;
    tot = w;
    memset(flow, 0, sizeof flow);
    dfs(1, 2, 0);
    if (ans >= 0) return printf("%d %d\n", w, ans), 0;
  }
  puts("-1 -1");
}
