#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 6;
int n;
int capmin[MAX_N][MAX_N], capmax[MAX_N][MAX_N], cost[MAX_N][MAX_N];
int solve(int u, int v, int has[MAX_N]) {
  if (u == n) return 0;
  if (v == n)
    return (u == n - 1 || has[u] == 0) ? solve(u + 1, u + 2, has) : -1;
  if (has[u] < 0) return -1;
  int ans = -1;
  for (int pass = capmin[u][v]; pass <= capmax[u][v]; pass++) {
    if (pass > has[u]) break;
    int c = (pass != 0) * cost[u][v] + pass * pass;
    has[u] -= pass;
    has[v] += pass;
    if (solve(u, v + 1, has) >= 0) ans = max(ans, c + solve(u, v + 1, has));
    has[v] -= pass;
    has[u] += pass;
  }
  return ans;
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n * (n - 1) / 2; i++) {
    int u, v;
    scanf("%d %d", &u, &v);
    u--, v--;
    scanf("%d %d %d", &capmin[u][v], &capmax[u][v], &cost[u][v]);
  }
  int ans = -1, am;
  for (am = 0; am <= 30 && ans == -1; am++) {
    int has[] = {am, 0, 0, 0, 0, 0};
    ans = max(ans, solve(0, 1, has));
  }
  am--;
  if (ans < 0) ans = am = -1;
  printf("%d %d\n", am, ans);
  return 0;
}
