#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:64000000")
using namespace std;
void __never(int a) { printf("\nOPS %d", a); }
int n;
int m[10][10];
int L[10][10], H[10][10], C[10][10];
int in[10], out[10];
int deg[10];
pair<int, int> p[100];
int p_sz = 0;
int cnt = 0;
int best_cost = -1;
bool check() {
  for (int a = (1); a <= (n - 1); a++)
    for (int b = (a + 1); b <= (n); b++)
      if (!(L[a][b] <= m[a][b] && m[a][b] <= H[a][b])) return false;
  int cost = 0;
  for (int a = (1); a <= (n - 1); a++)
    for (int b = (a + 1); b <= (n); b++) {
      cost += m[a][b] * m[a][b];
      if (m[a][b] > 0) cost += C[a][b];
    }
  best_cost = max(cost, best_cost);
  return true;
}
void dfs(int i) {
  if (i == p_sz) {
    if (check()) cnt++;
    return;
  }
  if (deg[p[i].second] == n - 2) {
    int a = out[p[i].second] - in[p[i].second];
    if (0 <= a && a <= 5) {
      m[p[i].first][p[i].second] = a;
      in[p[i].second] += a;
      out[p[i].first] += a;
      deg[p[i].first]++;
      deg[p[i].second]++;
      dfs(i + 1);
      deg[p[i].first]--;
      deg[p[i].second]--;
      out[p[i].first] -= a;
      in[p[i].second] -= a;
      m[p[i].first][p[i].second] = 0;
    }
    return;
  }
  for (int a = (0); a <= (5); a++) {
    bool flag = in[p[i].second] + a <= out[p[i].second];
    if (flag) {
      m[p[i].first][p[i].second] = a;
      in[p[i].second] += a;
      out[p[i].first] += a;
      deg[p[i].first]++;
      deg[p[i].second]++;
      dfs(i + 1);
      deg[p[i].first]--;
      deg[p[i].second]--;
      out[p[i].first] -= a;
      in[p[i].second] -= a;
      m[p[i].first][p[i].second] = 0;
    } else
      break;
  }
}
void sol() {
  for (int a = (n - 1); a >= (1); a--) {
    p[p_sz++] = make_pair(a, n);
    for (int b = (1); b <= (a - 1); b++) p[p_sz++] = make_pair(b, a);
  }
  for (int a = (0); a <= (5 * (n - 1)); a++) {
    out[n] = a;
    dfs(0);
    if (cnt) {
      cout << a << " " << best_cost;
      return;
    }
  }
  cout << "-1 -1";
}
int main() {
  cin >> n;
  for (int a = (1); a <= ((n * (n - 1)) / 2); a++) {
    int i, j, mi, ma, c;
    cin >> i >> j >> mi >> ma >> c;
    L[i][j] = mi;
    H[i][j] = ma;
    C[i][j] = c;
  }
  sol();
  return 0;
}
