#include <bits/stdc++.h>
using namespace std;
const int N = 8;
const int M = 100010;
const int INF = 1 << 30;
int n;
pair<int, int> bnd[N][N];
int act[N][N];
map<vector<int>, int> dp[N][N];
void init() {
  memset(bnd, 0, sizeof(bnd));
  memset(act, 0, sizeof(act));
  int tot = n * (n - 1) / 2;
  for (int i = 1; i <= tot; i++) {
    int l, r, u, d, a;
    cin >> l >> r >> d >> u >> a;
    l--, r--;
    if (d > u) swap(u, d);
    bnd[l][r] = bnd[r][l] = make_pair(d, u);
    act[l][r] = act[r][l] = a;
  }
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++) dp[i][j].clear();
}
int dfs(int u, int v, vector<int> now) {
  if (v == n) {
    u++;
    v = u + 1;
  }
  if (u == n - 1) return 0;
  if (dp[u][v].find(now) != dp[u][v].end()) return dp[u][v][now];
  int res = -1;
  int flue = now[u];
  int r = min(bnd[u][v].second, flue);
  int l = bnd[u][v].first;
  if (v == n - 1 && l < flue) l = flue;
  for (int k = l; k <= r; k++) {
    vector<int> tmp = now;
    tmp[u] -= k;
    tmp[v] += k;
    int cost = k ? act[u][v] + k * k : 0;
    int nxt = dfs(u, v + 1, tmp);
    if (nxt < 0) continue;
    res = max(res, cost + nxt);
  }
  return dp[u][v][now] = res;
}
void solve() {
  for (int i = 0; i <= 25; i++) {
    vector<int> beg(n);
    beg[0] = i;
    int res = dfs(0, 1, beg);
    if (res >= 0) {
      cout << i << " " << res << endl;
      return;
    }
  }
  cout << "-1 -1" << endl;
}
int main() {
  while (cin >> n) {
    init();
    solve();
  }
}
