#include <bits/stdc++.h>
using namespace std;
struct Edg {
  int s, f, l, h, a[10];
} e[20];
int n, m;
int hav[10];
int ansx, ansy;
bool flag = 0;
bool check(int x) {
  for (int i = 1; i < x; ++i)
    if (hav[i]) return 0;
  return 1;
}
void dfs(int pos, int sum) {
  if (pos == m) {
    if (ansy < sum) {
      if (!check(n)) return;
      ansy = sum;
      flag = 1;
    }
    return;
  }
  if (!check(e[pos].s)) return;
  for (int i = e[pos].l; i <= e[pos].h && i <= hav[e[pos].s]; ++i) {
    hav[e[pos].s] -= i;
    hav[e[pos].f] += i;
    dfs(pos + 1, sum + e[pos].a[i]);
    hav[e[pos].s] += i;
    hav[e[pos].f] -= i;
  }
}
bool cmp(Edg a, Edg b) { return a.s < b.s; }
int main() {
  scanf("%d", &n);
  m = n * (n - 1) / 2;
  int tmp;
  for (int i = 0; i < m; ++i) {
    scanf("%d%d%d%d%d", &e[i].s, &e[i].f, &e[i].l, &e[i].h, &tmp);
    for (int j = 1; j < 11; ++j) e[i].a[j] = tmp + j * j;
    e[i].a[0] = 0;
  }
  sort(e, e + m, cmp);
  ansy = -1;
  for (ansx = 0; ansx <= 5 * 5; ++ansx) {
    if (flag) break;
    memset(hav, 0, sizeof(hav));
    hav[1] = ansx;
    dfs(0, 0);
  }
  if (ansy == -1)
    printf("-1 -1\n");
  else {
    printf("%d %d\n", ansx - 1, ansy);
  }
  return 0;
}
