#include <bits/stdc++.h>
using namespace std;
struct edge {
  int l, h, cost;
  edge(int l, int h, int cost) : l(l), h(h), cost(cost) {}
  edge() {}
};
int n, best;
edge arr[7][7];
int sum[7];
void f(int ind, int cost);
void ff(int ind1, int ind2, int s, int cost) {
  if (ind2 == n + 1) {
    if (s != 0) return;
    f(ind1 + 1, cost);
    return;
  }
  for (int i = arr[ind1][ind2].l; i <= arr[ind1][ind2].h && i <= s; i++) {
    sum[ind2] += i;
    ff(ind1, ind2 + 1, s - i,
       cost + (i == 0 ? 0 : arr[ind1][ind2].cost + i * i));
    sum[ind2] -= i;
  }
}
void f(int ind, int cost) {
  if (ind == n) {
    best = max(best, cost);
    return;
  }
  ff(ind, ind + 1, sum[ind], cost);
}
int main() {
  int a, b;
  cin >> n;
  if (cin.fail()) return 0;
  for (int i = 1; i < n; i++)
    for (int j = i + 1; j <= n; j++) {
      cin >> a >> b;
      cin >> arr[a][b].l >> arr[a][b].h >> arr[a][b].cost;
    }
  int ans = -1;
  for (int i = 0; i <= 25; i++) {
    best = -1;
    sum[1] = i;
    f(1, 0);
    if (best != -1) {
      ans = i;
      break;
    }
  }
  cout << ans << " " << best << endl;
  return 0;
}
