#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:16777216")
using namespace std;
template <class T>
T abs(T x) {
  return x > 0 ? x : -x;
}
int n;
int m;
int l[6][6], r[6][6], a[6][6];
vector<pair<int, int> > v;
int t = 1;
int table[30][15000][16];
bool was[30][15000][16];
int bad = -100000000;
inline void parse(int x, int *mas) {
  for (int i = 0; i < (n - 2); i++) {
    mas[i] = x % 11;
    x /= 11;
  }
}
int h[6] = {1, 11, 121, 1331, 14641, 161051};
int getans(int c0, int c, int p) {
  if (p == n * (n - 1) / 2) {
    if (c0 == 0 && c == 0)
      return 0;
    else
      return bad;
  }
  if (was[c0][c][p] == t) return table[c0][c][p];
  was[c0][c][p] = t;
  int &ans = table[c0][c][p];
  ans = bad;
  int x = v[p].first;
  int y = v[p].second;
  if (x > 0 && c0 != 0) {
    return bad;
  }
  int mas[5];
  parse(c, mas);
  int lv = l[x][y], rv = r[x][y];
  if (x == 0) {
    rv = min(rv, c0);
    for (int z = lv; z <= rv; z++) {
      int b = z * z;
      if (z > 0) b += a[x][y];
      int tmp = getans(c0 - z, c + z * h[y - 1] * (y < n - 1), p + 1);
      ans = max(ans, tmp + b);
    }
  } else {
    rv = min(rv, mas[x - 1]);
    for (int z = lv; z <= rv; z++) {
      int b = z * z;
      if (z > 0) b += a[x][y];
      int tmp =
          getans(c0, c - h[x - 1] * z + z * h[y - 1] * (y < n - 1), p + 1);
      ans = max(ans, tmp + b);
    }
  }
  return ans;
}
int main() {
  cin >> n;
  for (int i = 0; i < (n * (n - 1) / 2); i++) {
    int a, b, c, d, e;
    cin >> a >> b >> c >> d >> e;
    a--;
    b--;
    l[a][b] = c;
    r[a][b] = d;
    ::a[a][b] = e;
  }
  for (int i = 0; i < (n); i++)
    for (int j = i + 1; j < n; j++) {
      v.push_back(make_pair(i, j));
    }
  for (int i = 0; i < (26); i++) {
    int tmp = getans(i, 0, 0);
    if (tmp >= 0) {
      cout << i << ' ' << tmp << endl;
      return 0;
    }
  }
  cout << -1 << ' ' << -1 << endl;
  return 0;
}
