#include <bits/stdc++.h>
using namespace std;
const int N = 6, INF = (int)1e9;
int n;
int lower[N][N], upper[N][N], w[N][N];
map<vector<int>, int> f;
int calc(vector<int> v) {
  if (f.count(v)) return f[v];
  int &val = f[v] = -INF;
  for (int x = n - 1; x >= 0; --x)
    if (v[x] >= 0 || x == 0) {
      if (x == 0) return val = 0;
      for (int a = lower[0][x]; a <= upper[0][x]; ++a)
        for (int b = lower[1][x]; b <= upper[1][x]; ++b)
          for (int c = lower[2][x]; c <= upper[2][x]; ++c)
            for (int d = lower[3][x]; d <= upper[3][x]; ++d)
              for (int e = lower[4][x]; e <= upper[4][x]; ++e)
                for (int g = lower[5][x]; g <= upper[5][x]; ++g)
                  if (a + b + c + d + e + g == v[x]) {
                    vector<int> tv(v);
                    for (int y = 0; y < x; ++y)
                      if (tv[y] == -1) tv[y] = 0;
                    tv[0] += a;
                    tv[1] += b;
                    tv[2] += c;
                    tv[3] += d;
                    tv[4] += e;
                    tv[x] = -1;
                    int cost = 0;
                    cost += a ? w[0][x] + a * a : 0;
                    cost += b ? w[1][x] + b * b : 0;
                    cost += c ? w[2][x] + c * c : 0;
                    cost += d ? w[3][x] + d * d : 0;
                    cost += e ? w[4][x] + e * e : 0;
                    cost += e ? w[5][x] + g * g : 0;
                    val = max(val, calc(tv) + cost);
                  }
      break;
    }
  return val;
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n * (n - 1) / 2; ++i) {
    int s, t;
    scanf("%d%d", &s, &t);
    --s, --t;
    scanf("%d%d%d", &lower[s][t], &upper[s][t], &w[s][t]);
  }
  for (int i = 0; i <= 30; ++i) {
    f.clear();
    vector<int> v(n, -1);
    v[n - 1] = i;
    if (calc(v) >= 0) {
      printf("%d %d\n", i, calc(v));
      return 0;
    }
  }
  puts("-1 -1");
}
