#include <bits/stdc++.h>
using namespace std;
const int inf = 50;
int n, C[6][6], F[6][6], best, L[6][6], H[6][6], in[6], out[6], cost, curCost,
    a, b, c, h, l, gl;
void gen(int a, int b) {
  if (in[n - 1] > best) return;
  if (a == n - 1) {
    if (in[n - 1] < best || curCost > cost) {
      best = in[n - 1];
      cost = curCost;
    }
    return;
  }
  assert(b <= n);
  if (b == n) {
    if (a && in[a]) return;
    gen(a + 1, a + 2);
    return;
  }
  for (int i = L[a][b], _b = (H[a][b]); i <= _b; i++) {
    if (i > in[a]) continue;
    in[a] -= i;
    in[b] += i;
    curCost += i * i + C[a][b] * (i > 0);
    gen(a, b + 1);
    in[a] += i;
    in[b] -= i;
    curCost -= i * i + C[a][b] * (i > 0);
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 0, _n = ((n * (n - 1)) / 2); i < _n; i++) {
    scanf("%d%d%d%d%d", &a, &b, &l, &h, &c);
    a--;
    b--;
    if (a > b) swap(a, b);
    C[a][b] = c;
    L[a][b] = l;
    H[a][b] = h;
  }
  in[0] = best = inf;
  gen(0, 1);
  if (best != inf)
    printf("%d %d\n", best, cost);
  else
    printf("-1 -1\n");
  return 0;
}
