#include <bits/stdc++.h>
using namespace std;
struct aresta {
  int minim, maxim, a;
};
int suma(vector<int> &v) {
  int s = 0;
  for (int i = 0; i < int(v.size()); i++) s += v[i];
  return s;
}
void escriu(vector<int> &v) {
  cout << "(";
  for (int i = 0; i < int(v.size()); i++) cout << v[i] << ",";
  cout << ")";
}
int main() {
  int n;
  cin >> n;
  vector<vector<aresta> > g(n, vector<aresta>(n));
  for (int k = 0; k < (n * (n - 1)) / 2; k++) {
    int i, j, minim, maxim, a;
    cin >> i >> j >> minim >> maxim >> a;
    i--;
    j--;
    g[i][j].minim = minim;
    g[i][j].maxim = maxim;
    g[i][j].a = a;
  }
  int maxflujo = 0;
  int minflujo = 0;
  for (int j = 1; j < n; j++) {
    maxflujo += g[0][j].maxim;
    minflujo += g[0][j].minim;
  }
  vector<int> vini(n, 0);
  map<vector<int>, int> m;
  for (int j = 0; j <= maxflujo; j++) {
    vini[0] = j;
    m[vini] = 0;
  }
  for (int j = 1; j < n; j++) {
    for (int i = 0; i < j; i++) {
      map<vector<int>, int> nextm;
      aresta &ar = g[i][j];
      int minim = ar.minim;
      int maxim = ar.maxim;
      int a = ar.a;
      for (map<vector<int>, int>::iterator it = m.begin(); it != m.end();
           it++) {
        vector<int> v = it->first;
        int cost = it->second;
        int inferior = minim;
        if (j == n - 1) inferior = max(inferior, v[i]);
        vector<int> nextv = v;
        for (int k = inferior; k <= min(maxim, v[i]); k++) {
          nextv[i] = v[i] - k;
          nextv[j] = v[j] + k;
          int nextcost = cost + k * k;
          if (k > 0) nextcost += a;
          nextm[nextv] = max(nextm[nextv], nextcost);
        }
      }
      m = nextm;
    }
  }
  int fluxmin = maxflujo + 1;
  int costmax;
  for (map<vector<int>, int>::iterator it = m.begin(); it != m.end(); it++) {
    vector<int> v = it->first;
    int flux = v[n - 1];
    int cost = it->second;
    if (flux < fluxmin or (flux == fluxmin and cost > costmax)) {
      fluxmin = flux;
      costmax = cost;
    }
  }
  if (fluxmin == maxflujo + 1)
    cout << "-1 -1" << endl;
  else
    cout << fluxmin << " " << costmax << endl;
}
