#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:16777216")
using namespace std;
int n;
int lo[6][6];
int hi[6][6];
int a[6][6];
struct State {
  int x[7];
  State(int k, int a, int b, int c, int d, int e, int f) {
    x[0] = k, x[1] = a, x[2] = b, x[3] = c, x[4] = d, x[5] = e, x[6] = f;
  }
  bool operator<(const State& r) const {
    for (int i = 0, _n = (7); i < _n; ++i)
      if (x[i] != r.x[i]) return x[i] < r.x[i];
    return false;
  }
};
map<State, int> dp;
map<State, int>::iterator it;
int go(int k, int n1, int n2, int n3, int n4, int n5, int n6);
int rec(int k, int i, int sum, int n1, int n2, int n3, int n4, int n5, int n6) {
  if (i == n) {
    if (sum != 0) return -1;
    return go(k + 1, n1, n2, n3, n4, n5, n6);
  }
  int RET = -1;
  int x[6];
  x[0] = n1, x[1] = n2, x[2] = n3, x[3] = n4, x[4] = n5, x[5] = n6;
  for (int add = lo[k][i]; add <= hi[k][i]; add++) {
    if (add > sum) break;
    int cost = add ? (a[k][i] + add * add) : 0;
    if (i == 0)
      n1 += add;
    else if (i == 1)
      n2 += add;
    else if (i == 2)
      n3 += add;
    else if (i == 3)
      n4 += add;
    else if (i == 4)
      n5 += add;
    else if (i == 5)
      n6 += add;
    int nxt = rec(k, i + 1, sum - add, n1, n2, n3, n4, n5, n6);
    if (nxt != -1) nxt += cost;
    if (nxt > RET) RET = nxt;
    if (i == 0)
      n1 -= add;
    else if (i == 1)
      n2 -= add;
    else if (i == 2)
      n3 -= add;
    else if (i == 3)
      n4 -= add;
    else if (i == 4)
      n5 -= add;
    else if (i == 5)
      n6 -= add;
  }
  return RET;
}
int go(int k, int n1, int n2, int n3, int n4, int n5, int n6) {
  if (k == n - 1) {
    return 0;
  }
  it = dp.find(State(k, n1, n2, n3, n4, n5, n6));
  if (it != dp.end()) return it->second;
  int x[6];
  x[0] = n1, x[1] = n2, x[2] = n3, x[3] = n4, x[4] = n5, x[5] = n6;
  for (int i = 0; i < k; i++)
    if (x[i] != 0) throw 1;
  int m = x[k];
  if (k == 0)
    n1 = 0;
  else if (k == 1)
    n2 = 0;
  else if (k == 2)
    n3 = 0;
  else if (k == 3)
    n4 = 0;
  else if (k == 4)
    n5 = 0;
  else if (k == 5)
    n6 = 0;
  int ret = rec(k, k, m, n1, n2, n3, n4, n5, n6);
  if (k == 0)
    n1 = m;
  else if (k == 1)
    n2 = m;
  else if (k == 2)
    n3 = m;
  else if (k == 3)
    n4 = m;
  else if (k == 4)
    n5 = m;
  else if (k == 5)
    n6 = m;
  dp.insert(make_pair(State(k, n1, n2, n3, n4, n5, n6), ret));
  return ret;
}
void solution() {
  cin >> n;
  for (int it = 0, _n = ((n * (n - 1)) / 2); it < _n; ++it) {
    int i, j;
    cin >> i >> j;
    i--, j--;
    cin >> lo[i][j] >> hi[i][j] >> a[i][j];
  }
  for (int i = 0; i <= 25; i++) {
    int ret = go(0, i, 0, 0, 0, 0, 0);
    if (ret != -1) {
      printf("%d %d\n", i, ret);
      return;
    }
  }
  puts("-1 -1");
}
int main() {
  solution();
  return 0;
}
