#include <bits/stdc++.h>
using namespace std;
const long double PI = acos(-1.0);
const int INF = (int)1e7;
const int N = 40;
int n;
int cMin[N][N], cMax[N][N], a[N][N], have[N];
int flow = INF, cost;
int cur_cost;
void rec(int v1, int v2) {
  if (have[n - 1] > flow) return;
  if (v1 == n - 1) {
    if (have[n - 1] < flow || cur_cost > cost) {
      flow = have[n - 1];
      cost = cur_cost;
    }
    return;
  }
  assert(v2 <= n);
  if (v2 == n) {
    if (v1 > 0 && have[v1]) return;
    rec(v1 + 1, v1 + 2);
    return;
  }
  for (int i = cMin[v1][v2]; i <= cMax[v1][v2]; i++) {
    if (have[v1] < i) continue;
    have[v1] -= i;
    have[v2] += i;
    cur_cost += i * i + (i ? a[v1][v2] : 0);
    rec(v1, v2 + 1);
    have[v1] += i;
    have[v2] -= i;
    cur_cost -= i * i + (i ? a[v1][v2] : 0);
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n;
  for (int i = 0; i < (int)(n * (n - 1) / 2); ++i) {
    int s, f, l, h, act;
    cin >> s >> f >> l >> h >> act;
    --s, --f;
    cMin[s][f] = cMin[f][s] = l;
    cMax[s][f] = cMax[f][s] = h;
    a[s][f] = a[f][s] = act;
  }
  have[0] = INF;
  rec(0, 1);
  if (flow == INF)
    cout << -1 << " " << -1 << endl;
  else
    cout << flow << " " << cost << endl;
  return 0;
}
