#include <bits/stdc++.h>
using namespace std;
const int maxn = 6 + 3;
int l[maxn][maxn], h[maxn][maxn], a[maxn][maxn];
int n;
int cost[maxn], max_cost, flow[maxn];
void func(int v);
void rec(int fr, int v, int fl) {
  if (v == n) {
    if (fl == 0) func(fr + 1);
    return;
  }
  int i, c;
  for (i = l[fr][v]; i <= h[fr][v]; ++i) {
    if (i > fl) return;
    if (i == 0)
      c = 0;
    else
      c = a[fr][v] + ((i) * (i));
    cost[v] += c;
    flow[v] += i;
    rec(fr, v + 1, fl - i);
    cost[v] -= c;
    flow[v] -= i;
  }
}
void func(int v) {
  if (v == n - 1) {
    int ccc = 0;
    for (int i = 0; i < n; ++i) ccc += cost[i];
    if (max_cost < ccc) max_cost = ccc;
    return;
  }
  rec(v, v + 1, flow[v]);
}
int main() {
  scanf("%d ", &n);
  int i, j, s, f, m;
  m = n * (n - 1) / 2;
  for (i = 0; i < m; ++i) {
    scanf("%d %d", &s, &f);
    --s;
    --f;
    scanf("%d %d %d ", &l[s][f], &h[s][f], &a[s][f]);
  }
  for (i = 0; i <= 76; ++i) {
    memset(cost, 0, sizeof(cost));
    memset(flow, 0, sizeof(flow));
    max_cost = -1;
    flow[0] = i;
    func(0);
    if (max_cost != -1) {
      printf("%d %d", i, max_cost);
      return 0;
    }
  }
  printf("-1 -1");
  return 0;
}
