#include <bits/stdc++.h>
using namespace std;
const int M = 10;
int edge[M][M][3];
int flow[M];
int max_cost = -1;
void solve(int node1, int node2, int cost, int n) {
  if (node1 < n && node2 > n) {
    if (flow[node1] == 0) {
      solve(node1 + 1, node1 + 2, cost, n);
    }
    return;
  }
  if (node1 == n) {
    if (cost > max_cost) {
      max_cost = cost;
    }
    return;
  }
  for (int iflow = edge[node1][node2][0]; iflow <= edge[node1][node2][1];
       iflow++) {
    if (flow[node1] < iflow) {
      return;
    }
    if (iflow != 0) {
      cost = cost + edge[node1][node2][2] + iflow * iflow;
    }
    flow[node1] -= iflow;
    flow[node2] += iflow;
    solve(node1, node2 + 1, cost, n);
    if (iflow != 0) {
      cost = cost - edge[node1][node2][2] - iflow * iflow;
    }
    flow[node1] += iflow;
    flow[node2] -= iflow;
  }
  return;
}
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n * (n - 1) / 2; i++) {
    int a, b;
    cin >> a >> b;
    for (int j = 0; j < 3; j++) {
      cin >> edge[a][b][j];
    }
  }
  int min_flow = 0;
  for (min_flow = 0; min_flow <= 26; min_flow++) {
    flow[1] = min_flow;
    solve(1, 2, 0, n);
    if (max_cost != -1) {
      break;
    }
  }
  if (max_cost != -1) {
    cout << min_flow << " " << max_cost << endl;
  } else {
    cout << "-1 -1" << endl;
  }
  return 0;
}
