#include <bits/stdc++.h>
using namespace std;
int n, m, ans, v[10];
int s, f, l, h, c;
struct Pipe {
  int l, h, c;
} pipe[10][10];
void dfs(int u, int t, int cost) {
  if (u == n) {
    ans = max(ans, cost);
    return;
  }
  for (int k = pipe[u][t].l; k <= pipe[u][t].h && k <= v[u]; k++) {
    v[u] -= k;
    v[t] += k;
    if (k) cost += pipe[u][t].c;
    cost += k * k;
    if (t == n && v[u])
      ;
    else {
      if (t + 1 <= n)
        dfs(u, t + 1, cost);
      else
        dfs(u + 1, u + 2, cost);
    }
    v[u] += k;
    v[t] -= k;
    if (k) cost -= pipe[u][t].c;
    cost -= k * k;
  }
}
int main() {
  while (~scanf("%d", &n)) {
    m = n * (n - 1) / 2;
    for (int i = 1; i <= m; ++i) {
      int s, f, l, h, c;
      scanf("%d%d%d%d%d", &s, &f, &l, &h, &c);
      pipe[s][f].l = l;
      pipe[s][f].h = h;
      pipe[s][f].c = c;
    }
    ans = -1;
    for (int i = 0; i < 30; i++) {
      memset(v, 0, sizeof(v));
      v[1] = i;
      dfs(1, 2, 0);
      if (ans >= 0) {
        printf("%d", i);
        break;
      }
    }
    if (ans >= 0)
      printf(" %d\n", ans);
    else
      printf("-1 -1\n");
  }
}
