#include <bits/stdc++.h>
#pragma warning(disable : 4786)
using namespace std;
struct edge {
  int a, b, l, h, c;
  void scan() { scanf("%d%d%d%d%d", &a, &b, &l, &h, &c); }
};
edge edges[30];
int n, m;
bool comp(edge A, edge B) {
  if (A.a == B.a) return A.b < B.b;
  return A.a < B.a;
}
pair<int, int> memo[16][200000];
int seen[16][200000], arr[6];
pair<int, int> solve(int pos) {
  int i, hash = 0;
  pair<int, int> ret(10000000, 10000000);
  for (i = 1; i < 5; i++) hash = hash * 21 + arr[i];
  if (pos == m) return make_pair(0, 0);
  if (seen[pos][hash]) return memo[pos][hash];
  int a = edges[pos].a, b = edges[pos].b;
  for (i = edges[pos].l; i <= edges[pos].h; i++) {
    int cost = i ? edges[pos].c + i * i : 0;
    int flow = 0;
    if (b == n - 1) flow = i;
    if (a > 0 && arr[a] - i < 0) break;
    if (a > 0 && b == n - 1 && arr[a] - i) continue;
    arr[a] -= i;
    arr[b] += i;
    pair<int, int> q = solve(pos + 1);
    if (q.first != 10000000) {
      q.first += flow;
      q.second -= cost;
      if (q < ret) ret = q;
    }
    arr[a] += i;
    arr[b] -= i;
  }
  seen[pos][hash] = 1;
  return memo[pos][hash] = ret;
}
int main() {
  int i, j, k, tests, cs = 0;
  scanf("%d", &n);
  m = n * (n - 1) / 2;
  for (i = 0; i < m; i++) {
    edges[i].scan();
    --edges[i].a;
    --edges[i].b;
  }
  for (i = 0; i < 6; i++) arr[i] = 0;
  sort(edges, edges + m, comp);
  pair<int, int> ans = solve(0);
  if (ans.first == 10000000)
    puts("-1 -1");
  else
    printf("%d %d\n", ans.first, -ans.second);
  return 0;
}
