#include <bits/stdc++.h>
#pragma comment(linker, "/stack:64000000")
using namespace std;
template <typename first>
inline first abs(const first& a) {
  return a < 0 ? -a : a;
}
template <typename first>
inline first sqr(const first& a) {
  return a * a;
}
const int INF = INT_MAX / 10;
const long double EPS = 1e-9;
const long double PI = 3.1415926535897932384626433832795;
const int N = 6;
struct edge {
  int v, l, r, a;
};
vector<edge> g[N];
int f[N];
int n;
int solve(int v, int i) {
  if (v == n - 1) return 0;
  if (i == int((g[v]).size()))
    if (f[v] == 0)
      return solve(v + 1, 0);
    else
      return -INF;
  int ans = -INF;
  for (int val = int(g[v][i].l); val <= int(g[v][i].r); val++) {
    int to = g[v][i].v;
    f[v] -= val;
    f[to] += val;
    int cur = val * val;
    if (val > 0) cur += g[v][i].a;
    ans = max(ans, solve(v, i + 1) + cur);
    f[v] += val;
    f[to] -= val;
  }
  return ans;
}
int main() {
  cin >> n;
  for (int i = 0; i < int(n * (n - 1) / 2); i++) {
    int u, v, l, r, a;
    cin >> u >> v >> l >> r >> a;
    u--, v--;
    edge front = {v, l, r, a};
    edge back = {u, l, r, a};
    g[u].push_back(front);
  }
  for (int i = 0; i < int(50); i++) {
    memset(f, 0, sizeof(f));
    f[0] = i;
    int sum = solve(0, 0);
    if (sum >= 0) {
      cout << i << " " << sum << endl;
      return 0;
    }
  }
  puts("-1 -1");
  return 0;
}
