#include <bits/stdc++.h>
using namespace std;
const int MAX_POSSIBLE_FLOW = 25;
const int MAX = 10;
int n, m, ans;
int min_flow[MAX][MAX];
int max_flow[MAX][MAX];
int act_fee[MAX][MAX];
int sum_node_flow[MAX];
void dfs(int x, int y, int flow, int cost) {
  if (x == n) {
    if (cost > ans) {
      ans = cost;
    }
    return;
  }
  if (y > n) {
    if (!flow) {
      dfs(x + 1, x + 2, sum_node_flow[x + 1], cost);
    }
    return;
  }
  for (int i = min_flow[x][y]; i <= min(flow, max_flow[x][y]); ++i) {
    int additional_cost = 0;
    if (i != 0) {
      additional_cost = act_fee[x][y] + i * i;
    }
    sum_node_flow[y] += i;
    dfs(x, y + 1, flow - i, cost + additional_cost);
    sum_node_flow[y] -= i;
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n * (n - 1) / 2; ++i) {
    int x, y, mi, ma, cost;
    cin >> x >> y >> mi >> ma >> cost;
    min_flow[x][y] = mi;
    max_flow[x][y] = ma;
    act_fee[x][y] = cost;
  }
  for (int i = 0; i <= MAX_POSSIBLE_FLOW; ++i) {
    ans = -1;
    dfs(1, 2, i, 0);
    if (ans >= 0) {
      cout << i << " " << ans << endl;
      return 0;
    }
  }
  puts("-1 -1");
  return 0;
}
