#include <bits/stdc++.h>
using namespace std;
struct edge {
  int ai, bi;
  int ci;
};
int solution = -1000000000;
vector<vector<edge> > mtx;
vector<int> actflow;
vector<vector<int> > actp;
int n;
void flow(int x, int y, int actcost) {
  if (y == n) {
    if (actflow[x] != 0) return;
    x = x + 1;
    y = x + 1;
  }
  if (x == n - 1) {
    solution = max(solution, actcost);
    return;
  }
  for (int i = mtx[x][y].ai; i <= mtx[x][y].bi; i++) {
    if (actp[x][y] != 0) actcost -= mtx[x][y].ci;
    actcost -= actp[x][y] * actp[x][y];
    actflow[x] += actp[x][y];
    actflow[y] -= actp[x][y];
    actp[x][y] = i;
    actflow[x] -= actp[x][y];
    actflow[y] += actp[x][y];
    if (actflow[x] < 0) {
      actflow[x] += actp[x][y];
      actflow[y] -= actp[x][y];
      actp[x][y] = 0;
      return;
    }
    if (actp[x][y] != 0) actcost += mtx[x][y].ci;
    actcost += actp[x][y] * actp[x][y];
    flow(x, y + 1, actcost);
  }
  actflow[x] += actp[x][y];
  actflow[y] -= actp[x][y];
  actp[x][y] = 0;
}
int main() {
  scanf("%d", &n);
  actflow.resize(n, 0);
  mtx.resize(n);
  actp.resize(n);
  for (int i = 0; i < n; i++) {
    mtx[i].resize(n);
    actp[i].resize(n, 0);
  }
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      edge tmp;
      int x, y;
      scanf("%d %d %d %d %d", &x, &y, &tmp.ai, &tmp.bi, &tmp.ci);
      x--;
      y--;
      mtx[x][y] = tmp;
    }
  }
  int maxflow = 0;
  for (int i = 1; i < n; i++) maxflow += mtx[0][i].bi;
  for (int i = 0; i <= maxflow; i++) {
    actflow[0] = i;
    flow(0, 1, 0);
    if (solution != -1000000000) {
      printf("%d %d\n", i, solution);
      return 0;
    }
  }
  printf("-1 -1\n");
  return 0;
}
