#include <bits/stdc++.h>
using namespace std;
int n, flow, cost, l[6][6], h[6][6], a[6][6], f[6][6];
void dfs(int first, int second) {
  if (first == -1) {
    int sum = 0;
    for (int i = 0; i < n - 1; i++) sum += f[i][0];
    if (sum > flow) return;
    int c = 0;
    for (int i = 0; i < n - 1; i++)
      for (int j = 0; j < n - 1; j++)
        if (f[i][j] > 0) c += f[i][j] * f[i][j] + a[i][j];
    if (sum < flow || (sum == flow && c > cost)) flow = sum, cost = c;
    return;
  }
  for (int cur = l[first][second]; cur <= h[first][second]; cur++) {
    f[first][second] = cur;
    if (second == 0) {
      int sum = 0;
      for (int i = 0; i <= first; i++) sum += f[first][i];
      for (int i = first + 1; i < n - 2; i++) sum -= f[i][first + 1];
      if (sum < l[n - 2][first + 1] || sum > h[n - 2][first + 1]) continue;
      f[n - 2][first + 1] = sum;
      dfs(first - 1, first - 1);
    } else
      dfs(first, second - 1);
  }
}
int main() {
  int i, j, k, m;
  while (~scanf("%d", &n)) {
    m = (n - 1) * n / 2;
    memset(f, 0, sizeof(f));
    for (i = 0; i < m; i++) {
      scanf("%d%d", &j, &k);
      j--, k -= 2;
      scanf("%d%d%d", &l[k][j], &h[k][j], &a[k][j]);
    }
    flow = 1000000007, cost = -1000000007;
    f[n - 2][0] = l[n - 2][0];
    dfs(n - 3, n - 3);
    if (flow == 1000000007)
      puts("-1 -1");
    else
      printf("%d %d\n", flow, cost);
  }
  return 0;
}
