#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:64000000")
using namespace std;
const int INF = 1000 * 1000 * 1000;
const long long LINF = 1000000000000000000LL;
const double eps = 1e-9;
void prepare(string s) {
  if ((int)s.size() != 0) {
    freopen((s + ".in").c_str(), "r", stdin);
    freopen((s + ".out").c_str(), "w", stdout);
  }
}
int n;
const int MAXN = 7;
int start[MAXN][MAXN];
int finish[MAXN][MAXN];
int act[MAXN][MAXN];
int cost[MAXN][MAXN];
int a[MAXN][MAXN];
int ans = INF;
int ans_cost;
void f(int x, int y) {
  if (x == n) {
    int sum = 0;
    for (int i = 1; i < n; ++i) sum += a[0][i];
    int cur_cost = 0;
    for (int i = 0; i < n; ++i)
      for (int j = i + 1; j < n; ++j)
        cur_cost += a[i][j] == 0 ? 0 : cost[i][j] + a[i][j] * a[i][j];
    if (sum < ans) {
      ans = sum;
      ans_cost = cur_cost;
    } else if (sum == ans && ans_cost < cur_cost) {
      ans_cost = cur_cost;
    }
    return void();
  }
  if (y == n) {
    if (x == 0) {
      int sum = 0;
      for (int i = 1; i < n; ++i) sum += a[0][i];
      if (sum > ans) return void();
    }
    if (x > 0 && x < n - 1) {
      int sum = 0;
      for (int i = 0; i < x; ++i) sum += a[i][x];
      for (int i = x + 1; i < n; ++i) sum -= a[x][i];
      if (sum != 0) return void();
    }
    f(x + 1, x + 2);
    return void();
  }
  for (int i = start[x][y]; i <= finish[x][y]; ++i) {
    a[x][y] = i;
    f(x, y + 1);
  }
}
bool solve() {
  cin >> n;
  for (int i = 0; i < n; ++i)
    for (int j = i + 1; j < n; ++j) {
      int l, r;
      int mi, ma, act;
      cin >> l >> r >> mi >> ma >> act;
      --l;
      --r;
      start[l][r] = mi;
      finish[l][r] = ma;
      cost[l][r] = act;
    }
  f(0, 1);
  if (ans == INF)
    cout << "-1 -1" << endl;
  else
    cout << ans << ' ' << ans_cost << endl;
  return false;
}
int main() {
  prepare("");
  while (solve()) {
  }
  return 0;
}
