#include <bits/stdc++.h>
using namespace std;
struct Edge {
  int a, b;
  int l, h;
  int cost;
  bool operator<(Edge o) const {
    if (a != o.a) {
      return a < o.a;
    }
    if (b != o.b) {
      return b < o.b;
    }
    return 0;
  }
};
Edge edge[20];
int numEdge;
int n;
int minFlow;
int maxCost;
int flowVertex[7];
int flowEdge[20];
int getCost() {
  int ret = 0;
  for (int i = 0; i < numEdge; i++) {
    if (flowEdge[i] != 0) {
      ret += edge[i].cost;
      ret += flowEdge[i] * flowEdge[i];
    }
  }
  return ret;
}
void debug() {
  cerr << "vertex flow : ";
  for (int i = 1; i <= n; i++) {
    cerr << flowVertex[i] << " ";
  }
  cerr << endl;
  cerr << "edge flow : " << endl;
  for (int i = 0; i < numEdge; i++) {
    cerr << edge[i].a << "->" << edge[i].b << " (" << edge[i].cost << ") "
         << flowEdge[i] << endl;
  }
  cerr << getCost() << endl;
}
void DFS(int depth) {
  if (depth == numEdge) {
    if (flowVertex[n - 1] != 0 || flowVertex[n] == 0) {
      return;
    }
    if (minFlow > flowVertex[n]) {
      minFlow = flowVertex[n];
      maxCost = getCost();
    } else if (minFlow == flowVertex[n]) {
      maxCost = max(maxCost, getCost());
    }
  } else {
    int curVertex = edge[depth].a;
    int nxtVertex = edge[depth].b;
    if (curVertex == 1) {
      for (int f = edge[depth].l; f <= edge[depth].h; f++) {
        flowEdge[depth] = f;
        flowVertex[nxtVertex] += f;
        DFS(depth + 1);
        flowVertex[nxtVertex] -= f;
      }
    } else {
      if (flowVertex[curVertex - 1] != 0) {
        return;
      }
      for (int f = edge[depth].l;
           f <= edge[depth].h && f <= flowVertex[curVertex]; f++) {
        flowEdge[depth] = f;
        flowVertex[nxtVertex] += f;
        flowVertex[curVertex] -= f;
        DFS(depth + 1);
        flowVertex[nxtVertex] -= f;
        flowVertex[curVertex] += f;
      }
    }
  }
}
bool specialCase() {
  int ans = 0;
  for (int i = 0; i < numEdge; i++) {
    if (edge[i].l != 0) {
      return false;
    }
  }
  puts("0 0");
  return true;
}
int main() {
  while (scanf("%d", &n) != EOF) {
    numEdge = n * (n - 1) / 2;
    for (int i = 0; i < numEdge; i++) {
      scanf("%d%d%d%d%d", &edge[i].a, &edge[i].b, &edge[i].l, &edge[i].h,
            &edge[i].cost);
    }
    if (specialCase()) {
      continue;
    }
    sort(edge, edge + numEdge);
    maxCost = 0;
    minFlow = 99999999;
    memset(flowEdge, 0, sizeof(flowEdge));
    memset(flowVertex, 0, sizeof(flowVertex));
    DFS(0);
    if (maxCost == 0) {
      puts("-1 -1");
    } else {
      printf("%d %d\n", minFlow, maxCost);
    }
  }
  return 0;
}
