#include <bits/stdc++.h>
using namespace std;
long long mod = 1000000007;
int n, mx;
int s[16], f[16], l[16], h[16], a[16];
vector<pair<pair<pair<int, int>, pair<int, int> >, int> > v;
int curmin = 2000000000;
int price = 0;
int cur = 0;
int pr = 2000000000;
int in[7];
int out[7];
int idx = 0;
inline void go() {
  if (idx == mx) {
    for (int i = 2; i < n; i++) {
      if (out[i] != in[i]) {
        return;
      }
    }
    if (in[n] < curmin) {
      curmin = in[n];
      pr = price;
    } else if (in[n] == curmin) {
      pr = max(price, pr);
    }
    return;
  }
  if (cur > curmin) {
    return;
  }
  if (s[idx] >= 3) {
    if (in[s[idx] - 1] != out[s[idx] - 1]) {
      return;
    }
  }
  for (int j = l[idx]; j <= h[idx]; j++) {
    if (j == 0) {
      idx++;
      go();
      idx--;
    } else {
      if (s[idx] == n - 1 && f[idx] == n && n > 2 && j != in[s[idx]]) {
        continue;
      }
      price += a[idx];
      price += j * j;
      out[s[idx]] += j;
      in[f[idx]] += j;
      if (s[idx] == 1) {
        cur += j;
      }
      idx++;
      go();
      idx--;
      if (s[idx] == 1) {
        cur -= j;
      }
      out[s[idx]] -= j;
      in[f[idx]] -= j;
      price -= a[idx];
      price -= j * j;
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n;
  for (int i = 0; i < (n * (n - 1)) / 2; i++) {
    cin >> s[i] >> f[i] >> l[i] >> h[i] >> a[i];
    v.push_back(make_pair(
        make_pair(make_pair(s[i], f[i]), make_pair(l[i], h[i])), a[i]));
  }
  sort((v).begin(), (v).end());
  mx = (n * (n - 1)) / 2;
  for (int i = 0; i < mx; i++) {
    s[i] = v[i].first.first.first;
    f[i] = v[i].first.first.second;
    l[i] = v[i].first.second.first;
    h[i] = v[i].first.second.second;
    a[i] = v[i].second;
  }
  memset(in, 0, sizeof(in));
  memset(out, 0, sizeof(out));
  go();
  if (pr == 2000000000) {
    cout << "-1 -1" << endl;
  } else {
    cout << curmin << ' ' << pr << endl;
  }
  return 0;
}
