#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:16777216")
using namespace std;
struct ted {
  int l, h, a;
};
const int DIM = 7, inf = 1000 * 1000 * 1000;
int n;
ted e[DIM][DIM];
ted et;
int fl[DIM][DIM];
int in[DIM], out[DIM];
int cost;
int a1, a2;
void rec(int u);
int f(int u, int v, int ca) {
  if (ca == 0) return 0;
  return e[u][v].a + ca * ca;
}
void rec2(int u, int v) {
  if (v == n) {
    if (u == 0 && out[u] > a1) return;
    if (u == 0 || u == n - 1 || in[u] == out[u]) rec(u + 1);
    return;
  }
  for (int i = (e[u][v].l); i < (e[u][v].h + 1); i++) {
    fl[u][v] = i;
    in[v] += i;
    out[u] += i;
    cost += f(u, v, i);
    rec2(u, v + 1);
    fl[u][v] = 0;
    in[v] -= i;
    out[u] -= i;
    cost -= f(u, v, i);
  }
}
void rec(int u) {
  if (u == n) {
    if (out[0] < a1 || a2 < cost) {
      a1 = out[0];
      a2 = cost;
    }
    return;
  }
  rec2(u, u + 1);
}
void solve() {
  rec(0);
  if (a1 == inf)
    printf("-1 -1\n");
  else
    printf("%d %d\n", a1, a2);
}
int main() {
  a1 = inf;
  a2 = -inf;
  scanf("%d", &n);
  for (int i = (0); i < (n * (n - 1) / 2); i++) {
    int s, f;
    scanf("%d%d%d%d%d", &s, &f, &et.l, &et.h, &et.a);
    s--;
    f--;
    e[s][f] = et;
  }
  solve();
  return 0;
}
