#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 29;
int n, lo[6][6], hi[6][6], act[6][6];
int flow[6][6], nodeflow[6];
pair<int, int> solve(int from, int to) {
  if (2 <= from && from < n && from + 1 == to) {
    if (nodeflow[from - 1] != 0) return make_pair(INF, -1);
  }
  if (from == n - 1 && to == n) {
    int cost = 0;
    for (int v = 0; v < (n); v++)
      for (int u = 0; u < (v); u++)
        if (flow[u][v] > 0) cost += act[u][v] + flow[u][v] * flow[u][v];
    return make_pair(-nodeflow[0], cost);
  }
  int nextfrom, nextto;
  if (to < n - 1) {
    nextfrom = from;
    nextto = to + 1;
  } else {
    nextfrom = from + 1;
    nextto = nextfrom + 1;
  }
  pair<int, int> ans = make_pair(INF, -1);
  for (int f = lo[from][to]; f <= hi[from][to]; f++) {
    flow[from][to] = f;
    nodeflow[from] -= f;
    nodeflow[to] += f;
    pair<int, int> tmp = solve(nextfrom, nextto);
    if (tmp.first < ans.first ||
        (tmp.first == ans.first && tmp.second > ans.second))
      ans = tmp;
    nodeflow[from] += f;
    nodeflow[to] -= f;
  }
  return ans;
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < (n * (n - 1) / 2); i++) {
    int s, f, l, h, a;
    scanf("%d%d%d%d%d", &s, &f, &l, &h, &a);
    s--, f--;
    lo[s][f] = l;
    hi[s][f] = h;
    act[s][f] = a;
  }
  pair<int, int> ans = solve(0, 1);
  printf("%d %d\n", ans.first < INF ? ans.first : -1, ans.second);
  return 0;
}
