#include <bits/stdc++.h>
using namespace std;
int l[10][10], h[10][10], a[10][10];
int gcost = -1;
int n;
vector<vector<vector<int>>> combinations(5);
int size;
void construct(vector<int> v, int idx, int value) {
  if (idx == size + 1) {
    combinations[size].push_back(v);
    return;
  }
  for (int i = 0; i <= 5; i++) {
    auto x = v;
    x.push_back(i);
    construct(x, idx + 1, i);
  }
}
void solve(vector<int> entering, int idx, int cost) {
  if (idx == n - 1) {
    gcost = max(gcost, cost);
    return;
  }
  int cur = entering[idx];
  int give = n - idx - 1;
  if (give == 1) {
    if (cur < l[idx][n - 1] || cur > h[idx][n - 1]) return;
    gcost = max(gcost, cost + cur * cur + (cur > 0) * a[idx][n - 1]);
    return;
  }
  for (auto v : combinations[give - 2]) {
    vector<int> out;
    out = v;
    int sum = 0;
    for (auto i : out) sum += i;
    if (sum > cur) continue;
    out.push_back(cur - sum);
    bool f = 0;
    for (int i = 0; i < out.size(); i++) {
      int dest = idx + i + 1;
      if (out[i] < l[idx][dest] || out[i] > h[idx][dest]) f = 1;
    }
    if (f) continue;
    vector<int> new_entering = entering;
    int extra_money = 0;
    for (int i = 0; i < give; i++) {
      int dest = idx + i + 1;
      extra_money += (out[i] > 0) * a[idx][dest] + out[i] * out[i];
      new_entering[dest] += v[i];
    }
    solve(new_entering, idx + 1, cost + extra_money);
  }
}
int main() {
  cin >> n;
  int cnt = (n * (n - 1)) / 2;
  for (int i = 0, s, e; i < cnt; i++) {
    cin >> s >> e;
    s--, e--;
    cin >> l[s][e] >> h[s][e] >> a[s][e];
  }
  for (int i = 0; i < n - 2; i++) {
    size = i, construct({}, 0, 0);
  }
  for (int i = 0; i <= 25; i++) {
    vector<int> v(n);
    v[0] = i;
    solve(v, 0, 0);
    if (gcost != -1) {
      cout << i << " " << gcost;
      return 0;
    }
  }
  cout << "-1 -1";
}
