#include <bits/stdc++.h>
using namespace std;
const int MAXN = 6;
const int MAGIC = 30;
map<vector<int>, int> dict;
int n, u, v;
struct Edge {
  int low, high, cost;
} my_pipe[MAXN][MAXN];
Edge nextEdge() {
  Edge curEdge;
  scanf("%d %d %d", &curEdge.low, &curEdge.high, &curEdge.cost);
  return curEdge;
}
void generate(int dep, vector<vector<int> > &e, int pos, int val,
              vector<int> &state) {
  if (dep == pos) {
    if (val == 0) e.push_back(state);
    return;
  }
  for (int i = my_pipe[dep][pos].low; i <= min(val, my_pipe[dep][pos].high);
       ++i) {
    state.push_back(i);
    generate(dep + 1, e, pos, val - i, state);
    state.pop_back();
  }
}
int dfs(vector<int> v, int pos) {
  if (pos == 0) return 0;
  if (dict.count(v)) return dict[v];
  int ret = -1;
  vector<vector<int> > e;
  vector<int> state;
  generate(0, e, pos, v[pos], state);
  for (int j = 0; j < (int)e.size(); ++j) {
    int c = 0;
    for (int k = 0; k < pos; ++k) {
      c += e[j][k] * e[j][k];
      if (e[j][k] > 0) c += my_pipe[k][pos].cost;
    }
    vector<int> s(pos);
    for (int k = 0; k < pos; ++k) s[k] = v[k] + e[j][k];
    int t = dfs(s, pos - 1);
    if (t != -1 && ret < t + c) ret = t + c;
  }
  return dict[v] = ret;
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n * (n - 1) / 2; ++i) {
    scanf("%d %d", &u, &v);
    my_pipe[u - 1][v - 1] = nextEdge();
  }
  for (int step = 0; step < MAGIC; ++step) {
    dict.clear();
    vector<int> cur(n, 0);
    cur[n - 1] = step;
    int ans = dfs(cur, n - 1);
    if (ans != -1) {
      printf("%d %d\n", step, ans);
      return 0;
    }
  }
  puts("-1 -1");
}
