#include <bits/stdc++.h>
using namespace std;
int testCases, testNum;
int N, K;
const int maxn = 10;
const int maxm = 50;
int minIn[maxn], maxIn[maxn], minOut[maxn], maxOut[maxn];
int curIn[maxn], curOut[maxn];
int flow[maxn][maxn];
int least[maxn][maxn], most[maxn][maxn];
int activation[maxn][maxn];
int bestFlow, bestCost;
int curFlow;
bool isValid() {
  for (int i = 2; i < N; i++)
    if (curIn[i] != curOut[i]) return false;
  for (int i = 1; i <= N; i++) {
    for (int j = i + 1; j <= N; j++)
      if (flow[i][j] < least[i][j] || flow[i][j] > most[i][j]) return false;
  }
  return true;
}
void solve(int a, int b) {
  if (a == N) {
    if (isValid()) {
      int itsFlow = 0, itsCost = 0;
      for (int i = 1; i <= N; i++) {
        for (int j = i + 1; j <= N; j++) {
          if (flow[i][j] > 0)
            itsCost += activation[i][j] + flow[i][j] * flow[i][j];
        }
      }
      itsFlow = curOut[1];
      if (itsFlow < bestFlow || (itsFlow == bestFlow && itsCost > bestCost)) {
        bestFlow = itsFlow;
        bestCost = itsCost;
      }
    }
  } else {
    int aout = curOut[a], bin = curIn[b];
    for (int f = least[a][b]; f <= most[a][b]; f++) {
      if (aout + f <= curIn[a] && bin + f <= maxOut[b]) {
        curOut[a] = aout + f;
        curIn[b] = bin + f;
        flow[a][b] = f;
        if (curOut[1] > bestFlow) break;
        if (b == N)
          solve(a + 1, a + 2);
        else
          solve(a, b + 1);
      }
    }
    flow[a][b] = -1;
    curOut[a] = aout;
    curIn[b] = bin;
  }
}
int main() {
  scanf("%d", &N);
  for (int i = 0; i < N * (N - 1) / 2; i++) {
    int f, t, l, h, a;
    scanf("%d", &f);
    scanf("%d", &t);
    scanf("%d", &l);
    scanf("%d", &h);
    scanf("%d", &a);
    least[f][t] = l;
    most[f][t] = h;
    activation[f][t] = a;
    maxOut[f] += h;
  }
  bestFlow = 1 << 20;
  bestCost = 0;
  curIn[1] = 1 << 20;
  maxOut[N] = 1 << 20;
  solve(1, 2);
  if (bestFlow == (1 << 20)) {
    printf("-1 -1\n");
  } else
    printf("%d %d\n", bestFlow, bestCost);
}
