#include <bits/stdc++.h>
using namespace std;
const int maxn = 7;
struct Pipe {
  int s, f, l, h, a;
  Pipe() {}
  Pipe(int s, int f, int l, int h, int a) : s(s), f(f), l(l), h(h), a(a) {}
};
int n;
Pipe g[maxn][maxn];
map<vector<int>, int> opt;
int dfs(vector<int> state) {
  int u, v;
  if (opt.find(state) != opt.end()) return opt[state];
  if (state[n] == n - 1) {
    return 0;
  }
  int& res = opt[state];
  res = -1;
  if (state[n + 1] == n - 1) {
    if (state[state[n]] != 0) return res = -1;
    state[n] = state[n + 1] = state[n] + 1;
    res = dfs(state);
    return res;
  }
  u = state[n];
  v = state[n + 1] + 1;
  for (int i = g[u][v].l; i <= min(state[u], g[u][v].h); i++) {
    state[u] -= i;
    state[v] += i;
    state[n + 1] = v;
    int t = dfs(state);
    state[u] += i;
    state[v] -= i;
    if (t == -1) continue;
    res = max(res, t + i * i + (i > 0 ? g[u][v].a : 0));
  }
  return res;
}
int main() {
  scanf("%d", &n);
  int maxl = 0;
  for (int i = 0; i < n * (n - 1) / 2; i++) {
    int s, f, l, h, a;
    scanf("%d%d%d%d%d", &s, &f, &l, &h, &a);
    s--, f--;
    g[s][f] = g[f][s] = Pipe(s, f, l, h, a);
    maxl = max(maxl, l);
  }
  if (maxl == 0) {
    printf("0 0\n");
    return 0;
  }
  int start, maxi;
  for (start = 1; start <= n * 5; start++) {
    opt.clear();
    vector<int> s = vector<int>(n + 2);
    for (int i = 0; i < n; i++) s[i] = 0;
    s[n] = 0;
    s[n + 1] = 0;
    s[0] = start;
    maxi = dfs(s);
    if (maxi != -1) break;
  }
  if (start > n * 5) start = maxi = -1;
  printf("%d %d\n", start, maxi);
  return 0;
}
