#include <bits/stdc++.h>
bool debug = false;
using namespace std;
long long convertToNum(string s) {
  long long val = 0;
  for (int i = 0; i < (s.size()); i++) val = val * 10 + s[i] - '0';
  return val;
}
string convertToString(long long a) {
  string res = "";
  if (!a) return "0";
  while (a) {
    res = (char)(a % 10 + 48) + res;
    a /= 10;
  }
  return res;
}
long long GCD(long long x, long long y) {
  if (!x) return y;
  if (!y) return x;
  if (x == y) return x;
  if (x < y)
    return GCD(x, y % x);
  else
    return GCD(x % y, y);
}
long long POW(long long x, long long y, long long Base) {
  if (!y) return 1;
  long long u = POW(x, y / 2, Base);
  u = (u * u) % Base;
  if (y & 1)
    return (u * x) % Base;
  else
    return u;
}
long long resx, resy;
int n;
int low[10][10], high[10][10], active[10][10];
vector<pair<int, int> > edge;
long long total = 0;
int flow[10][10];
int FlowIn[10], FlowOut[10];
void attempt(int vt) {
  if (vt == n * (n - 1) / 2) {
    bool ok = true;
    for (int i = (2); i <= (n - 1); i++)
      if (FlowIn[i] != FlowOut[i]) ok = false;
    if (!ok) return;
    int F = 0;
    for (int i = (2); i <= (n); i++) F += flow[1][i];
    if (F < resx || (F == resx && total > resy)) resx = F, resy = total;
    return;
  }
  int u = edge[vt].first, v = edge[vt].second;
  if (u != 1) {
    int cost = 0;
    for (int i = (2); i <= (n); i++) cost += flow[1][i];
    if (cost > resx) return;
  }
  for (int i = (2); i <= (u - 1); i++)
    if (FlowIn[i] != FlowOut[i]) return;
  for (int delta = (low[u][v]); delta <= (high[u][v]); delta++) {
    flow[u][v] = delta;
    total += (delta == 0 ? 0 : (delta * delta + active[u][v]));
    FlowIn[v] += delta;
    FlowOut[u] += delta;
    attempt(vt + 1);
    FlowIn[v] -= delta;
    FlowOut[u] -= delta;
    total -= (delta == 0 ? 0 : (delta * delta + active[u][v]));
  }
}
int main() {
  cin >> n;
  int u, v;
  for (int i = (1); i <= (n * (n - 1) / 2); i++) {
    cin >> u >> v;
    cin >> low[u][v] >> high[u][v] >> active[u][v];
  }
  resx = 1000000009;
  for (int i = (1); i <= (n); i++)
    for (int j = (i + 1); j <= (n); j++) edge.push_back(make_pair(i, j));
  attempt(0);
  if (resx == 1000000009)
    cout << -1 << " " << -1 << endl;
  else
    cout << resx << " " << resy << endl;
  return 0;
}
