#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:10000000")
const long double LDINF = 9128739847123.00;
const long double eps = 1e-9;
const int inf = 1 << 28;
const long double pi = fabsl(atan2l(0.0, -1.0));
using namespace std;
int l[7][7], h[7][7], a[7][7], n;
int inflow[7];
void load() {
  cin >> n;
  int s, f;
  for (int i = 0; i < n * (n - 1) / 2; i++) {
    cin >> s >> f;
    cin >> l[s][f] >> h[s][f] >> a[s][f];
  }
}
int curcost = 0, maxcost;
bool go(int i, int j, int remain) {
  if (remain < 0) return false;
  if (i == n) {
    maxcost = max(maxcost, curcost);
    return true;
  }
  if (j == n + 1) {
    if (remain != 0) return false;
    return go(i + 1, i + 2, inflow[i + 1]);
  }
  bool t = false;
  for (int k = l[i][j]; k <= h[i][j]; k++) {
    if (remain - k < 0) break;
    curcost += (k ? a[i][j] : 0) + k * k;
    inflow[j] += k;
    t |= go(i, j + 1, remain - k);
    inflow[j] -= k;
    curcost -= (k ? a[i][j] : 0) + k * k;
  }
  return t;
}
void solve() {
  maxcost = 0;
  for (int i = 0; i <= 30; i++) {
    memset(inflow, 0, sizeof inflow);
    inflow[1] = i;
    if (go(1, 2, inflow[1])) {
      cout << i << " " << maxcost;
      return;
    }
  }
  cout << "-1 -1";
}
int main() {
  load();
  solve();
  return 0;
}
