#include <bits/stdc++.h>
using namespace std;
int l[7][7], h[7][7], c[7][7];
int f[7][7];
int n, m;
int sum, sum1;
int total[7];
int min_ok = 10000;
int ans = 0;
int best_ans = -1;
void bf(int a, int b) {
  if (a == n) {
    bool ok = 1;
    for (int i = 2; i < n; i++) {
      int in = 0;
      int out = 0;
      for (int j = 1; j < i; j++) {
        in += f[j][i];
      }
      for (int j = i + 1; j <= n; j++) {
        out += f[i][j];
      }
      if (in != out) ok = 0;
    }
    if (ok) {
      min_ok = sum1;
      best_ans = max(ans, best_ans);
    }
    return;
  }
  if (a > 1 && b == n) {
    f[a][b] = total[a] - sum;
    if (f[a][b] < l[a][b] || f[a][b] > h[a][b]) return;
    ans += (f[a][b] ? c[a][b] : 0) + f[a][b] * f[a][b];
    int tmp_sum = sum;
    sum = 0;
    bf(a + 1, a + 2);
    sum = tmp_sum;
    ans -= (f[a][b] ? c[a][b] : 0) + f[a][b] * f[a][b];
  } else {
    for (f[a][b] = l[a][b]; f[a][b] <= h[a][b]; f[a][b]++) {
      sum += f[a][b];
      total[b] += f[a][b];
      ans += (f[a][b] ? c[a][b] : 0) + f[a][b] * f[a][b];
      if (b < n)
        bf(a, b + 1);
      else {
        if (sum <= min_ok) {
          sum1 = sum;
          sum = 0;
          bf(a + 1, a + 2);
          sum = sum1;
        }
      }
      total[b] -= f[a][b];
      sum -= f[a][b];
      ans -= (f[a][b] ? c[a][b] : 0) + f[a][b] * f[a][b];
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n;
  m = n * (n - 1) / 2;
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    cin >> l[a][b] >> h[a][b] >> c[a][b];
  }
  bf(1, 2);
  if (best_ans == -1) {
    cout << "-1 -1\n";
  } else {
    cout << min_ok << ' ' << best_ans << '\n';
  }
  return 0;
}
