#include <bits/stdc++.h>
using namespace std;
int INF = 1e9;
const int SIZE = 6;
int N, low[SIZE][SIZE], high[SIZE][SIZE], act[SIZE][SIZE];
int in[SIZE];
int bestCost = -1;
void go(int i, int f, int c);
void go2(int i, int j, int f, int c) {
  if (j >= N) {
    if (!f) go(i + 1, in[i + 1], c);
    return;
  }
  for (int a = low[i][j]; a <= high[i][j]; a++) {
    if (a > f) break;
    in[j] += a;
    go2(i, j + 1, f - a, c + a * a + (a ? act[i][j] : 0));
    in[j] -= a;
  }
}
void go(int i, int f, int c) {
  if (i >= N - 1) {
    if (c > bestCost) bestCost = c;
    return;
  }
  go2(i, i + 1, f, c);
}
int main() {
  cin >> N;
  for (int i = 0; i < N * (N - 1) / 2; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    cin >> low[a][b] >> high[a][b] >> act[a][b];
  }
  int f;
  for (f = 0; f <= 30; f++) {
    go(0, f, 0);
    if (bestCost != -1) break;
  }
  if (f <= 30)
    cout << f << " " << bestCost << endl;
  else
    cout << -1 << " " << -1 << endl;
  return 0;
}
