#include <bits/stdc++.h>
using namespace std;
const int N = 10;
int n;
int l[N][N], h[N][N], a[N][N];
map<vector<int>, int> Mp[2];
int low[N], up[N];
void dfs(int c, int i, vector<int> v, int cost) {
  if (c == i) {
    Mp[1][v] = max(Mp[1][v], cost);
    return;
  }
  if (v[c] < l[c][i]) return;
  for (int flow = l[c][i]; flow < h[c][i] + 1; ++flow) {
    if (v[c] - flow > up[c] || v[c] - flow < low[c]) continue;
    if (v[c] < flow) break;
    v[c] -= flow;
    v[i] += flow;
    dfs(c + 1, i, v, cost + (flow ? a[c][i] : 0) + flow * flow);
    v[c] += flow;
    v[i] -= flow;
  }
}
bool ok(vector<int> &v) {
  for (int i = 0; i < (int)(v).size() - 1; ++i)
    if (v[i] != 0) return false;
  return true;
}
int main() {
  cin >> n;
  for (int i = 0; i < (n) * (n - 1) / 2; ++i) {
    int s, f, x, y, z;
    cin >> s >> f >> x >> y >> z;
    --s;
    --f;
    l[s][f] = x, h[s][f] = y, a[s][f] = z;
    low[s] += x;
    up[s] += y;
  }
  int cap = 0;
  for (int i = 0; i < n; ++i) cap += h[0][i];
  vector<int> v;
  v.push_back(0);
  for (int i = 0; i < cap + 1; ++i) v[0] = i, Mp[0][v] = 0;
  for (int i = 1; i < n; ++i) {
    for (int j = 0; j < i; ++j) low[j] -= l[j][i], up[j] -= h[j][i];
    Mp[1].clear();
    for (auto e : Mp[0]) {
      vector<int> nv = e.first;
      nv.push_back(0);
      dfs(0, i, nv, e.second);
    }
    Mp[0].swap(Mp[1]);
  }
  int ans = 100000, cost = -1;
  for (auto e : Mp[0]) {
    vector<int> v = e.first;
    if (ok(v)) {
      if (v[n - 1] < ans) ans = v[n - 1], cost = e.second;
      if (v[n - 1] == ans) cost = max(cost, e.second);
    }
  }
  if (ans == 100000)
    cout << -1 << " " << -1 << endl;
  else
    cout << ans << " " << cost << endl;
  return 0;
}
