#include <bits/stdc++.h>
const int kMaxN = 6;
const int kMaxS = 6 * 11 * 16 * 21 * 26;
const int kMod[] = {
    1, 6, 6 * 11, 6 * 11 * 16, 6 * 11 * 16 * 21, 6 * 11 * 16 * 21 * 26};
int low[kMaxN][kMaxN], high[kMaxN][kMaxN], cost[kMaxN][kMaxN];
int n;
void Solve() {
  static int queue_mem[2][kMaxS];
  static int dp_mem[2][kMaxS];
  static int used[kMaxS];
  static int left[kMaxN];
  int *now = queue_mem[0], *next = queue_mem[1];
  int *dp_now = dp_mem[0], *dp_next = dp_mem[1];
  int tail_now = 0, tail_next;
  int cnt = 0;
  memset(used, 0, sizeof(used));
  now[tail_now++] = dp_now[0] = 0;
  for (int i = 0; i < n; ++i)
    for (int j = i + 1; j < n; ++j) {
      ++cnt;
      tail_next = 0;
      for (int head_now = 0; head_now < tail_now; ++head_now) {
        int u = now[head_now], v;
        left[0] = 100;
        for (int k = 1; k < n; ++k) left[k] = u % kMod[k] / kMod[k - 1];
        for (int k = low[i][j]; k <= high[i][j] && k <= left[i]; ++k) {
          v = u;
          if (i != 0) v -= k * kMod[i - 1];
          v += k * kMod[j - 1];
          if (used[v] != cnt) {
            used[v] = cnt;
            next[tail_next++] = v;
            dp_next[v] = dp_now[u] + (k > 0 ? cost[i][j] + k * k : 0);
          } else {
            dp_next[v] = std::max(dp_next[v],
                                  dp_now[u] + (k > 0 ? cost[i][j] + k * k : 0));
          }
        }
      }
      std::swap(now, next);
      std::swap(dp_now, dp_next);
      tail_now = tail_next;
    }
  for (int i = 0; i <= (n - 1) * 5; ++i)
    if (used[kMod[n - 2] * i] == cnt) {
      printf("%d %d\n", i, dp_now[kMod[n - 2] * i]);
      return;
    }
  puts("-1 -1");
}
int main() {
  int x, y, l, h, a;
  scanf("%d", &n);
  for (int i = n * (n - 1) / 2; i; --i) {
    scanf("%d%d%d%d%d", &x, &y, &l, &h, &a);
    --x;
    --y;
    low[x][y] = l;
    high[x][y] = h;
    cost[x][y] = a;
  }
  Solve();
  return 0;
}
