#include <bits/stdc++.h>
using namespace std;
int N;
int lower[8][8], upper[8][8], offset[8][8];
int dfs(vector<int> &vi, int last, int from, int resi);
const int INFTY = 1 << 26;
map<vector<int>, int> memo[8];
int dp(vector<int> &vi, int last) {
  if (last == 0) return 0;
  if (((memo[last]).find(vi) != (memo[last]).end())) return memo[last][vi];
  int res = dfs(vi, last, last - 1, vi[last]);
  return memo[last][vi] = res;
}
int dfs(vector<int> &vi, int last, int from, int resi) {
  if (from == -1) {
    if (resi == 0)
      return dp(vi, last - 1);
    else
      return -INFTY;
  }
  int res = -INFTY;
  for (int f = (0); f <= (int)(resi); ++f)
    if (lower[from][last] <= f && f <= upper[from][last]) {
      int cost = f * f + (f ? offset[from][last] : 0);
      vi[last] -= f, vi[from] += f;
      res = max(res, cost + dfs(vi, last, from - 1, resi - f));
      vi[last] += f, vi[from] -= f;
    }
  return res;
}
int main() {
  while (scanf("%d", &N) != EOF) {
    for (int itr = 0; itr < (int)(N * (N - 1) / 2); ++itr) {
      int t1, t2, l, u, of;
      scanf("%d%d%d%d%d", &t1, &t2, &l, &u, &of);
      t1--, t2--;
      lower[t1][t2] = l, upper[t1][t2] = u;
      offset[t1][t2] = of;
    }
    for (int j = 0; j < (int)(6); ++j) memo[j].clear();
    for (int fuel = (0); fuel <= (int)(25); ++fuel) {
      vector<int> para(N, 0);
      para[N - 1] = fuel;
      int tmp = dp(para, N - 1);
      if (tmp >= 0) {
        printf("%d %d\n", fuel, tmp);
        goto NEXTCASE;
      }
    }
    puts("-1 -1");
  NEXTCASE:;
  }
}
