#include <bits/stdc++.h>
using namespace std;
int n;
int Min[10][10], Max[10][10], A[10][10];
int Flow[10][10];
int MinFlow = 10000000, MaxCost;
void check() {
  int SumFlow = 0, SumCost = 0;
  for (int i = 2; i <= n; i++) SumFlow += Flow[1][i];
  for (int i = 1; i < n; i++)
    for (int j = i + 1; j <= n; j++)
      if (Flow[i][j] > 0) SumCost += A[i][j] + Flow[i][j] * Flow[i][j];
  if (SumFlow < MinFlow) MinFlow = SumFlow, MaxCost = SumCost;
  if (SumFlow == MinFlow && SumCost > MaxCost) MaxCost = SumCost;
}
void search(int a, int b) {
  if (a == n)
    check();
  else {
    if (b == n) {
      if (a == 1)
        Flow[a][b] = Min[a][b];
      else {
        int income = 0, outcome = 0;
        for (int i = 1; i < a; i++) income += Flow[i][a];
        for (int i = a + 1; i < n; i++) outcome += Flow[a][i];
        Flow[a][b] = income - outcome;
        if (Flow[a][b] < Min[a][b] || Flow[a][b] > Max[a][b]) return;
      }
      search(a + 1, a + 2);
    } else {
      for (int i = Min[a][b]; i <= Max[a][b]; i++) {
        Flow[a][b] = i;
        search(a, b + 1);
      }
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  while (cin >> n) {
    MinFlow = 10000000;
    for (int i = 1; i <= n * (n - 1) / 2; i++) {
      int s, t, m1, m2, a;
      cin >> s >> t >> m1 >> m2 >> a;
      Min[s][t] = m1;
      Max[s][t] = m2;
      A[s][t] = a;
    }
    search(1, 2);
    if (MinFlow == 10000000)
      cout << "-1 -1" << endl;
    else
      cout << MinFlow << " " << MaxCost << endl;
  }
  return 0;
}
