#include <bits/stdc++.h>
using namespace std;
int n;
int mm[10][10];
bool mask[10][10];
struct node {
  int l, h, a;
  node() {}
  node(int c, int d, int e) : l(c), h(d), a(e) {}
};
node gg[10][10];
int optV, optC;
pair<int, int> ee[20];
bool emask[20];
int ent;
int d[10];
struct node2 {
  int s, e, v, cost, a;
  node2() {}
  node2(int a, int b, int c, int d, int e) : s(a), e(b), v(c), cost(d), a(e) {}
  void print() {
    printf("s = %d, e = %d, v = %d, cost = %d, a = %d\n", s, e, v, cost, a);
  }
};
node2 st[20000];
int cnt = 0;
void sol(int i, int cost) {
  int s = ee[i].first, e = ee[i].second;
  auto &ele = gg[s][e];
  if (i == ent) {
    if (d[n] < optV)
      optV = d[n], optC = cost;
    else if (d[n] == optV && cost > optC)
      optC = cost;
    return;
  }
  if (emask[i] && s != 1) {
    if (d[s] >= ele.l && d[s] <= ele.h) {
      int v = d[s];
      d[e] += v;
      d[s] -= v;
      st[cnt++] = {s, e, v, cost, ele.a};
      sol(i + 1, cost + (v == 0 ? 0 : ele.a) + v * v);
      cnt--;
      d[e] -= v;
      d[s] += v;
    } else {
      return;
    }
  } else {
    for (int v = (ele.l); v <= (ele.h); ++v) {
      if (v > d[s]) break;
      d[e] += v;
      d[s] -= v;
      st[cnt++] = {s, e, v, cost, ele.a};
      sol(i + 1, cost + (v == 0 ? 0 : ele.a) + v * v);
      cnt--;
      d[e] -= v;
      d[s] += v;
    }
  }
}
int main() {
  scanf("%d", &n);
  int tt = n * (n - 1) / 2;
  int s, f, l, h, a;
  memset(mask, 0, sizeof(mask));
  for (int i = (1); i <= (tt); ++i) {
    scanf("%d%d%d%d%d", &s, &f, &l, &h, &a);
    mask[s][f] = 1;
    gg[s][f] = {l, h, a};
  }
  memset(emask, 0, sizeof(emask));
  optV = INT_MAX;
  ent = 0;
  for (int i = (1); i <= (n - 1); ++i) {
    bool ok = 0;
    for (int j = (i + 1); j <= (n); ++j) {
      if (mask[i][j] == 1) ee[ent++] = {i, j}, ok = 1;
    }
    if (ok) emask[ent - 1] = 1;
  }
  memset(d, 0, sizeof(d));
  d[1] = INT_MAX;
  sol(0, 0);
  if (optV == INT_MAX)
    printf("-1 -1\n");
  else
    printf("%d %d\n", optV, optC);
  return 0;
}
