#include <bits/stdc++.h>
using namespace std;
double const pi = 3.1415926535897932384626433832795;
int const inf = (int)1e9;
long long const inf64 = (long long)2e18;
const string name = "c";
int const NMAX = 15;
int n, m, now[6], ans, lvl;
int x[NMAX], y[NMAX], l[NMAX], r[NMAX], p[NMAX];
int g[6][6];
void rec(int x, int y, int sum) {
  if (now[x] < 0) return;
  if (x == n - 1) {
    for (int i = 0; i < (int)n - 1; i++)
      if (now[i] != 0) return;
    ans = max(ans, sum);
    return;
  }
  if (y == n) {
    rec(x + 1, x + 2, sum);
    return;
  }
  int tmp, num = g[x][y];
  for (int i = l[num]; i <= r[num]; ++i) {
    now[x] -= i;
    now[y] += i;
    tmp = i * i;
    if (i > 0) tmp += p[num];
    rec(x, y + 1, sum + tmp);
    now[x] += i;
    now[y] -= i;
  }
}
int main() {
  cin >> n;
  m = n * (n - 1) / 2;
  for (int i = 0; i < (int)m; i++) {
    cin >> x[i] >> y[i] >> l[i] >> r[i] >> p[i];
    x[i]--, y[i]--;
    g[x[i]][y[i]] = i;
  }
  memset(now, 0, sizeof(now));
  for (lvl = 0; lvl <= 25; lvl++) {
    ans = -1;
    now[0] = lvl;
    rec(0, 1, 0);
    if (ans >= 0) {
      cout << lvl << " " << ans << endl;
      return 0;
    }
  }
  cout << -1 << " " << -1 << endl;
  return 0;
}
