#include <bits/stdc++.h>
using namespace std;
int n;
int l[6][6], h[6][6], a[6][6];
int in[6];
int cost;
int rec(int inNode, int outNode) {
  if (inNode == n - 1) return 0;
  int bestCost = -1;
  for (int f = l[inNode][outNode]; f <= h[inNode][outNode]; f++) {
    if (in[inNode] >= f && (outNode != n - 1 || in[inNode] == f)) {
      int nextIn = inNode, nextOut = outNode + 1;
      if (outNode == n) {
        nextIn = inNode + 1;
        nextOut = 0;
      };
      if (nextIn == nextOut) nextOut++;
      in[inNode] -= f;
      in[outNode] += f;
      int val = rec(nextIn, nextOut);
      if (val != -1) {
        val += f * f;
        if (f > 0) val += a[inNode][outNode];
        bestCost = max(bestCost, val);
      }
      in[inNode] += f;
      in[outNode] -= f;
    }
  }
  return bestCost;
}
int s, f;
int main() {
  cin >> n;
  for (int i = 0; i < n * (n - 1) / 2; i++) {
    cin >> s >> f;
    s--, f--;
    cin >> l[s][f] >> h[s][f] >> a[s][f];
  }
  int maxCost = -1;
  int f;
  for (f = 0; f <= 25; f++) {
    memset(in, 0, sizeof in);
    in[0] = f;
    maxCost = rec(0, 1);
    if (maxCost != -1) break;
  }
  if (maxCost != -1)
    cout << f << " " << maxCost << endl;
  else
    cout << -1 << " " << -1 << endl;
  return 0;
}
