#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:64000000")
using namespace std;
void __never(int a) { printf("\nOPS %d", a); }
const int INF = 1000000000;
bool was[6][26][6][11][16][21];
int dp[6][26][6][11][16][21];
struct Edge {
  int a, l, h;
};
int n;
Edge graf[7][7];
int mask[7];
void dfs(int a, int b, int rest, int cost, vector<int>& v,
         vector<pair<vector<int>, int> >& res) {
  if (b == n + 1) {
    if (rest != 0) return;
    vector<int> v2(5);
    for (int(i) = (a); (i) <= (n - 2); ++(i)) v2[i] = v[i] + mask[i + 1];
    res.push_back(make_pair(v2, cost));
    return;
  }
  for (int(i) = (graf[a][b].l); (i) <= (graf[a][b].h); ++(i)) {
    if (i > rest) break;
    mask[b] = i;
    dfs(a, b + 1, rest - i, cost + ((i > 0) ? graf[a][b].a : 0) + i * i, v,
        res);
  }
}
int get(vector<int> v, int st) {
  if (was[st][v[0]][v[1]][v[2]][v[3]][v[4]])
    return dp[st][v[0]][v[1]][v[2]][v[3]][v[4]];
  was[st][v[0]][v[1]][v[2]][v[3]][v[4]] = true;
  int& res = dp[st][v[0]][v[1]][v[2]][v[3]][v[4]];
  if (v[0] + v[1] + v[2] + v[3] + v[4] == 0 && st == n - 1) return res = 0;
  vector<pair<vector<int>, int> > vv;
  dfs(st + 1, st + 2, v[st], 0, v, vv);
  res = -INF;
  for (int(i) = (0); (i) <= ((int)((vv).size()) - 1); ++(i)) {
    int h = get(vv[i].first, st + 1);
    if (h > -INF) res = max(res, h + vv[i].second);
  }
  return res;
}
void init() {
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
}
void sol() {
  cin >> n;
  int a, b;
  for (int(i) = (1); (i) <= ((n * (n - 1)) / 2); ++(i)) {
    cin >> a >> b;
    cin >> graf[a][b].l >> graf[a][b].h >> graf[a][b].a;
  }
  bool zero = true;
  for (int(i) = (1); (i) <= (n); ++(i))
    for (int(j) = (i + 1); (j) <= (n); ++(j)) zero &= graf[i][j].l == 0;
  if (zero) {
    printf("0 0");
    return;
  }
  int hi = 0;
  for (int(i) = (2); (i) <= (n); ++(i)) hi += graf[1][i].h;
  vector<int> v(5);
  for (int(I) = (1); (I) <= (hi); ++(I)) {
    v[0] = I;
    if (get(v, 0) > 0) {
      printf("%d %d", I, get(v, 0));
      return;
    }
  }
  printf("-1 -1");
}
void gen() {
  int n = 6;
  printf("%d", n);
  for (int(i) = (1); (i) <= (n); ++(i))
    for (int(j) = (i + 1); (j) <= (n); ++(j))
      printf("\n%d %d %d %d %d", i, j, rand() & 1, 5, rand() & 15);
}
int main() {
  sol();
  return 0;
}
