#include <bits/stdc++.h>
using namespace std;
int m, n;
int a[10][10];
int l[10][10];
int h[10][10];
int A, L, H;
int ansa = 123456789, ansb = -123456789;
int curra, currb;
int in[10];
int lob[10] = {}, hib[10] = {};
int loa[10] = {}, hia[10] = {};
void send(int amount, int done, int pos) {
  int i, j;
  if (done == n) {
    if (amount != 0) return;
    pos++;
    if (pos == n) {
      if (currb > ansb) {
        ansb = currb;
      }
      return;
    }
    send(in[pos], pos, pos);
  } else {
    done++;
    if (l[pos][done] > amount) {
      return;
    }
    for (i = l[pos][done]; i <= h[pos][done] && i <= amount; i++) {
      if (i) {
        currb += a[pos][done] + i * i;
      }
      in[done] += i;
      send(amount - i, done, pos);
      if (i) {
        currb -= a[pos][done] + i * i;
      }
      in[done] -= i;
    }
  }
}
int main() {
  int k, t, tests;
  scanf("%d", &n);
  int i, j;
  int s, f;
  for (i = 0; i < n * (n - 1) / 2; i++) {
    scanf("%d%d", &s, &f);
    scanf("%d%d%d", &L, &H, &A);
    a[s][f] = A;
    l[s][f] = L;
    h[s][f] = H;
    loa[s] += L;
    hia[s] += H;
    lob[f] += L;
    hib[f] += H;
  }
  int lo = max(loa[1], lob[n]);
  int hi = min(hia[1], hib[n]);
  for (i = 2; i < n; i++) {
    lo = max(loa[i], lo);
    lo = max(lob[i], lo);
    hi = max(hia[i], hi);
    hi = max(hib[i], hi);
  }
  for (i = lo; i <= hi; i++) {
    curra = currb = 0;
    for (j = 0; j <= n; j++) in[j] = 0;
    send(i, 1, 1);
    if (ansb != -123456789) {
      printf("%d %d\n", i, ansb);
      break;
    }
  }
  if (ansb == -123456789) {
    printf("-1 -1\n");
  }
  return 0;
}
