#include <bits/stdc++.h>
using namespace std;
int n;
map<vector<int>, int> dp[9];
int l[9][9], h[9][9], a[9][9];
void transfer(int left, vector<int> v, int d, int s, int cost) {
  if (d == n) {
    if (left == 0 && (!dp[s + 1].count(v) || cost > dp[s + 1][v])) {
      dp[s + 1][v] = cost;
    }
    return;
  }
  for (int flow = l[s][d]; flow <= h[s][d] && flow <= left; flow++) {
    int new_cost = cost;
    if (flow > 0) {
      new_cost += a[s][d];
    }
    new_cost += flow * flow;
    v[d] += flow;
    transfer(left - flow, v, d + 1, s, new_cost);
    v[d] -= flow;
  }
}
int main() {
  scanf("%d", &n);
  for (int i = n * (n - 1) / 2; i--;) {
    int s, f;
    scanf("%d%d", &s, &f);
    s--;
    f--;
    scanf("%d%d%d", l[s] + f, h[s] + f, a[s] + f);
  }
  int s1 = 0, s2 = 0;
  for (int i = 1; i < n; i++) {
    s1 += l[0][i];
    s2 += h[0][i];
  }
  vector<int> state(n, 0);
  for (int i = s1; i <= s2; i++) {
    state[0] = i;
    dp[0][state] = 0;
  }
  for (int i = 0; i < n - 1; i++) {
    for (__typeof((dp[i]).begin()) e = (dp[i]).begin(); e != (dp[i]).end();
         ++e) {
      state = e->first;
      state[i] = 0;
      transfer(e->first[i], state, i + 1, i, e->second);
    }
  }
  int r1 = INT_MAX, r2 = -INT_MAX;
  for (__typeof((dp[n - 1]).begin()) e = (dp[n - 1]).begin();
       e != (dp[n - 1]).end(); ++e) {
    if (e->first[n - 1] < r1 || e->first[n - 1] == r1 && e->second > r2) {
      r1 = e->first[n - 1];
      r2 = e->second;
    }
  }
  if (r1 == INT_MAX) {
    puts("-1 -1");
  } else {
    printf("%d %d\n", r1, r2);
  }
}
