#include <bits/stdc++.h>
using namespace std;
int L[20][20], H[20][20], N, A[20][20];
int res1 = 1 << 29, res2, flow, cost;
int P[20];
void dfs(int v, int u) {
  if (P[N - 1] > res1) return;
  if (v == N - 1 && (u > 1) && P[u - 1]) return;
  if (v == N) {
    bool valid = 1;
    for (int i = (1); i < (N - 1) && (valid); ++i) valid = P[i] == 0;
    if (!valid) return;
    flow = P[N - 1];
    if (flow < res1)
      res1 = flow, res2 = cost;
    else if (res1 == flow)
      res2 = max(res2, cost);
    return;
  }
  for (int i = (max(0, L[u][v])); i < (1 + min(H[u][v], P[u])); ++i) {
    P[v] += i;
    P[u] -= i;
    cost += i * i + (i > 0) * A[u][v];
    if (u == v - 1)
      dfs(v + 1, 0);
    else
      dfs(v, u + 1);
    cost -= i * i + (i > 0) * A[u][v];
    P[v] -= i;
    P[u] += i;
  }
}
int main(int argc, char **argv) {
  cin >> N;
  for (int i = (0); i < (N); ++i)
    for (int j = (i + 1); j < (N); ++j) {
      int first, second, l, r, a;
      cin >> first >> second >> l >> r >> a;
      --first, --second;
      L[first][second] = l, H[first][second] = r, A[first][second] = a;
    }
  P[0] = 1 << 29;
  dfs(1, 0);
  if (res1 == 1 << 29)
    puts("-1 -1");
  else
    cout << res1 << " " << res2 << endl;
  return 0;
}
