#include <bits/stdc++.h>
using namespace std;
int a[50][50], l[50][50], h[50][50];
int f[50];
int n;
int top;
int ans;
void dfs(int x, int y, int flow, int w) {
  if (x == n) {
    ans = max(ans, w);
    return;
  }
  if (y > n) {
    if (flow == 0) dfs(x + 1, x + 2, f[x + 1], w);
    return;
  }
  for (int i = l[x][y]; i <= flow && i <= h[x][y]; i++) {
    f[y] += i;
    dfs(x, y + 1, flow - i, w + i * i + ((i) ? a[x][y] : 0));
    f[y] -= i;
  }
}
int main() {
  scanf("%d", &n);
  int m = n * (n - 1) / 2;
  int x, y;
  top = 0;
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &x, &y);
    scanf("%d%d%d", &l[x][y], &h[x][y], &a[x][y]);
    top += h[x][y];
  }
  for (int i = 0; i < 30; i++) {
    ans = -1;
    memset(f, 0, sizeof(f));
    dfs(1, 2, i, 0);
    if (ans != -1) {
      printf("%d %d\n", i, ans);
      return 0;
    }
  }
  printf("-1 -1\n");
  return 0;
}
