#include <bits/stdc++.h>
using namespace std;
int lo[9][9], hi[9][9], a[9][9];
int n, bflow, bcost;
vector<int> now;
map<pair<pair<int, int>, vector<int> >, int> tab;
void chmax(int& t, int x) {
  if (x > t) t = x;
}
int dp(int i, int j) {
  if (j == n) return dp(i + 1, i + 2);
  if (i + 1 >= n) {
    for (int k = 0; k < n - 1; ++k)
      if (now[k] > 0) return -(1 << 29);
    return 0;
  }
  pair<pair<int, int>, vector<int> > key = make_pair(make_pair(i, j), now);
  if (tab.count(key) != 0) return tab[key];
  int ret = -(1 << 29);
  for (int k = lo[i][j]; k <= hi[i][j]; ++k)
    if (k <= now[i]) {
      now[i] -= k, now[j] += k;
      int delta = (k == 0) ? 0 : a[i][j] + k * k;
      chmax(ret, dp(i, j + 1) + delta);
      now[j] -= k, now[i] += k;
    }
  return tab[key] = ret;
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < (n - 1) * n / 2; ++i) {
    int s, t;
    scanf("%d%d", &s, &t);
    --s, --t;
    scanf("%d%d%d", &lo[s][t], &hi[s][t], &a[s][t]);
  }
  bflow = -1, bcost = -1;
  for (int i = 0; i < n; ++i) now.push_back(0);
  for (int i = 0; i <= 5 * (n - 1); ++i) {
    now[0] = i;
    chmax(bcost, dp(0, 1));
    if (bcost != -1) {
      bflow = i;
      break;
    }
  }
  printf("%d %d\n", bflow, bcost);
  return 0;
}
