#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:100000000000000")
using namespace std;
const long long int INF = 2e9;
struct edge {
  int to, minf, maxf, a, flow;
  edge(int to, int minf, int maxf, int a)
      : to(to), minf(minf), maxf(maxf), a(a), flow(0) {}
  edge() {}
};
vector<edge> g[7];
int number[7], cur[7], fl[7];
int out1 = INF, out2 = -1;
void dfs(int id, int l, int flow, int n, int s2) {
  if (id == n - 1) {
    if (out1 > fl[n - 1] || (out1 == fl[n - 1] && out2 < s2)) {
      out1 = fl[n - 1];
      out2 = s2;
    }
    return;
  }
  if (l == (int)g[id].size()) {
    int add = 0;
    for (int i = 0; i < ((int)g[id].size()); i++) {
      int to = g[id][i].to;
      fl[to] += g[id][i].flow;
      cur[to]++;
      add += (g[id][i].flow ? g[id][i].flow * g[id][i].flow + g[id][i].a : 0);
    }
    for (int i = 0; i < ((int)g[id].size()); i++) {
      int to = g[id][i].to;
      if (number[to] == cur[to]) dfs(to, 0, fl[to], n, s2 + add);
    }
    for (int i = 0; i < ((int)g[id].size()); i++) {
      int to = g[id][i].to;
      fl[to] -= g[id][i].flow;
      cur[to]--;
    }
    return;
  }
  int fr = g[id][l].minf;
  if (l == (int)g[id].size() - 1) {
    fr = max(fr, flow);
  }
  for (int i = fr; i <= min(flow, g[id][l].maxf); i++) {
    g[id][l].flow = i;
    dfs(id, l + 1, flow - i, n, s2);
  }
}
int main() {
  memset(number, 0, sizeof number);
  int n;
  cin >> n;
  for (int i = 0; i < (n * (n - 1) / 2); i++) {
    int f, to, minf, maxf, a;
    cin >> f >> to >> minf >> maxf >> a;
    f--;
    to--;
    g[f].push_back(edge(to, minf, maxf, a));
    number[to]++;
  }
  for (int i = 0; i < (50); i++) {
    dfs(0, 0, i, n, 0);
  }
  if (out1 == INF) {
    cout << "-1 -1";
    return 0;
  }
  cout << out1 << " " << out2;
}
