#include <bits/stdc++.h>
using namespace std;
int n;
struct Node {
  int L, H, A;
  Node() {}
  Node(int inL, int inH, int inA) : L(inL), H(inH), A(inA) {}
};
Node v[7][7];
int flow[7] = {0};
int ans1 = 100, ans2 = 0;
int Dfs(int pos, int next, int now, int val) {
  if (pos == n) {
    if (now < ans1) {
      ans1 = now;
      ans2 = val;
    } else if (now == ans1 && ans2 < val) {
      ans2 = val;
    }
    return 0;
  }
  if (pos == next)
    Dfs(pos + 1, n, now, val);
  else {
    if (pos + 1 == next) {
      if (v[pos][next].L <= flow[pos] && flow[pos] <= v[pos][next].H) {
        flow[next] += flow[pos];
        Dfs(pos, next - 1, now,
            val + (flow[pos] > 0 ? flow[pos] * flow[pos] + v[pos][next].A : 0));
        flow[next] -= flow[pos];
      }
    } else {
      for (int i = v[pos][next].L; i <= v[pos][next].H; i++) {
        if (i > flow[pos]) break;
        flow[pos] -= i;
        flow[next] += i;
        Dfs(pos, next - 1, now, val + (i > 0 ? i * i + v[pos][next].A : 0));
        flow[next] -= i;
        flow[pos] += i;
      }
    }
  }
  return 0;
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n * (n - 1) / 2; i++) {
    int a, b, L, H, A;
    scanf("%d %d %d %d %d", &a, &b, &L, &H, &A);
    if (a > b) swap(a, b);
    v[a][b] = Node(L, H, A);
  }
  for (int i = 0; i <= 36; i++) {
    flow[1] = i;
    Dfs(1, n, i, 0);
    if (ans1 != 100) break;
  }
  if (ans1 == 100)
    puts("-1 -1");
  else
    printf("%d %d\n", ans1, ans2);
  return 0;
}
