#include <bits/stdc++.h>
using namespace std;
const int maxn = 10;
int flow[maxn];
int n, ans;
bool ok;
struct edgnode {
  int low, high, cost;
} g[maxn][maxn];
void search(int u, int v, int c) {
  if (u == n) {
    ok = true;
    ans = max(ans, c);
    return;
  }
  for (int cur = g[u][v].low; cur <= min(g[u][v].high, flow[u]); ++cur) {
    flow[v] += cur;
    flow[u] -= cur;
    int nc = c + cur * cur;
    if (cur) nc += g[u][v].cost;
    if (v == n) {
      if (!flow[u]) search(u + 1, u + 2, nc);
    } else
      search(u, v + 1, nc);
    flow[v] -= cur;
    flow[u] += cur;
  }
}
int main() {
  cin >> n;
  memset(g, 0, sizeof(g));
  for (int i = 0; i != n * (n - 1) / 2; ++i) {
    int a, b;
    cin >> a >> b;
    cin >> g[a][b].low >> g[a][b].high >> g[a][b].cost;
  }
  int minst = 100, maxst = 0, minf, maxf;
  minf = maxf = 0;
  for (int i = 1; i <= n; ++i) {
    minf += g[1][i].low;
    maxf += g[1][i].high;
  }
  minst = minf;
  maxst = maxf;
  minf = maxf = 0;
  for (int i = 1; i <= n; ++i) {
    minf += g[i][n].low;
    maxf += g[i][n].high;
  }
  minst = max(minst, minf);
  maxst = min(maxst, maxf);
  for (int f = minst; f <= maxst; ++f) {
    memset(flow, 0, sizeof(flow));
    flow[1] = f;
    ans = 0;
    ok = false;
    search(1, 2, 0);
    if (ok) {
      cout << f << " " << ans << endl;
      return 0;
    }
  }
  cout << "-1 -1" << endl;
  return 0;
}
