#include <bits/stdc++.h>
using namespace std;
struct rebro {
  int x, y;
  int l, r;
  int cost;
};
rebro a[17];
rebro b[17];
int n;
int best_cost = -1;
int best_flow = 1000000000;
int in[17];
int out[17];
int p[17];
bool ok = false;
int lim;
void mergesort(rebro *a, rebro *b, int n) {
  int i, i0, i1, iRight, iEnd, width, j;
  for (width = 1; width < n; width *= 2)
    for (i = 0; i < n; i += width * 2) {
      i0 = i;
      i1 = iRight = min(i + width, n);
      iEnd = min(i + width * 2, n);
      for (j = i; i0 < iRight; j++)
        if (i1 == iEnd)
          b[j] = a[i0++];
        else {
          if (a[i0].x < a[i1].x)
            b[j] = a[i0++];
          else if (a[i0].x == a[i1].x) {
            if (a[i0].y < a[i1].y)
              b[j] = a[i0++];
            else
              b[j] = a[i1++];
          } else
            b[j] = a[i1++];
        }
      for (j = i; j < i1; j++) a[j] = b[j];
    }
}
void dfs(int x, int cost) {
  int i;
  if (x == n - 1) {
    if (out[0] != lim) return;
  }
  if (x == 2 * n - 3 && n > 2) {
    if (out[1] != in[1]) return;
  }
  if (x == 3 * n - 6 && n > 3) {
    if (out[2] != in[2]) return;
  }
  if (x == 4 * n - 10 && n > 4) {
    if (out[3] != in[3]) return;
  }
  if (x == 5 * n - 15 && n > 5) {
    if (out[4] != in[4]) return;
  }
  if (x == ((n * (n - 1)) >> 1)) {
    best_flow = lim;
    if (best_cost < cost) best_cost = cost;
    ok = true;
    return;
  }
  for (p[x] = a[x].l; p[x] <= a[x].r; p[x]++) {
    in[a[x].y] += p[x];
    out[a[x].x] += p[x];
    dfs(x + 1, cost + p[x] * p[x] + a[x].cost * min(1, p[x]));
    in[a[x].y] -= p[x];
    out[a[x].x] -= p[x];
  }
}
int main() {
  scanf("%d", &n);
  int i;
  int sum = 0;
  for (i = 0; i < ((n * (n - 1)) >> 1); i++) {
    scanf("%d %d %d %d %d", &a[i].x, &a[i].y, &a[i].l, &a[i].r, &a[i].cost);
    a[i].x--;
    a[i].y--;
    if (a[i].x == 0) sum += a[i].r;
  }
  mergesort(a, b, ((n * (n - 1)) >> 1));
  for (lim = 0; lim <= sum && !ok; lim++) dfs(0, 0);
  if (!ok) {
    printf("-1 -1\n");
    return 0;
  }
  printf("%d %d\n", best_flow, best_cost);
  return 0;
}
