#include <bits/stdc++.h>
using namespace std;
int s[6][6];
int sum = 0;
int NUM = 6;
int total = 0;
int mn = 0x7f7f7f5;
int a[6][6];
int MN[6][6];
int MX[6][6];
int resCost = 0x7f7f7f7f;
int totalCost;
void DFS(short start, short fin) {
  ++total;
  if (fin == NUM) {
    ++start;
    fin = start + 1;
    if (start + 1 == NUM) {
      int cur = 0;
      for (int i = 0; i < NUM; i++) {
        cur += s[i][NUM - 1];
      }
      if (cur < mn || cur == mn) {
        int cost = 0;
        for (int i = 0; i < NUM; i++)
          for (int u = i + 1; u < NUM; u++)
            if (s[i][u]) cost += a[i][u] + s[i][u] * s[i][u];
        if (cur < mn)
          resCost = cost;
        else if (cost > resCost)
          resCost = cost;
        mn = cur;
      }
      ++sum;
      return;
    }
  }
  int inc = 0;
  for (int i = 0; i < NUM; i++) inc += s[i][start];
  for (int i = 0; i < NUM; i++) inc -= s[start][i];
  if (start != 0 && inc < MN[start][fin]) return;
  if (fin == NUM - 1 && start != 0) {
    if (MN[start][fin] > inc || MX[start][fin] < inc) return;
    s[start][fin] = inc;
    DFS(start, fin + 1);
    s[start][fin] = 0;
    return;
  }
  for (int put = MN[start][fin]; put <= MX[start][fin]; put++) {
    s[start][fin] = put;
    DFS(start, fin + 1);
  }
  s[start][fin] = 0;
}
int main() {
  cin >> NUM;
  for (int i = 0; i < NUM * (NUM - 1) / 2; i++) {
    int a1, b, r, t, aa;
    cin >> a1 >> b >> r >> t >> aa;
    --a1;
    --b;
    a[a1][b] = aa;
    MN[a1][b] = r;
    MX[a1][b] = t;
  }
  DFS(0, 1);
  if (mn > 11111)
    cout << "-1 -1" << endl;
  else
    cout << mn << ' ' << resCost << endl;
  return 0;
}
