#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:60777216")
using namespace std;
long long gcd(long long a, long long b) { return a == 0 ? b : gcd(b % a, a); }
string filename = "test";
struct S {
  int s, f, l, h, a;
};
map<pair<int, vector<int> >, int> mem;
int n;
vector<S> v;
bool comp(const S& lhs, const S& rhs) {
  if (lhs.s != rhs.s) return lhs.s < rhs.s;
  return lhs.f < rhs.f;
}
int go(int pos, vector<int> cnts) {
  if (cnts.size() == 0) return 0;
  pair<int, vector<int> > pr(pos, cnts);
  if (mem.find(pr) != mem.end()) {
    return mem[pr];
  }
  int ret = -1;
  int current_capacity = cnts[0];
  bool pop_front = pos == v.size() - 1 || v[pos].s != v[pos + 1].s;
  vector<int> next_cnts(cnts.begin() + (int)(pop_front), cnts.end());
  for (int flow = v[pos].l; flow <= v[pos].h; ++flow) {
    if (current_capacity < flow) break;
    if (pop_front && current_capacity != flow) continue;
    if (!pop_front) {
      next_cnts[0] -= flow;
      if (v[pos].f != n) next_cnts[v[pos].f - v[pos].s] += flow;
    } else {
      if (v[pos].f != n) next_cnts[v[pos].f - v[pos].s - 1] += flow;
    }
    int r1 = go(pos + 1, next_cnts);
    if (r1 != -1) {
      r1 += (flow * flow + (flow > 0 ? v[pos].a : 0));
      if (r1 > ret) ret = r1;
    }
    if (!pop_front) {
      next_cnts[0] += flow;
      if (v[pos].f != n) next_cnts[v[pos].f - v[pos].s] -= flow;
    } else {
      if (v[pos].f != n) next_cnts[v[pos].f - v[pos].s - 1] -= flow;
    }
  }
  mem[pr] = ret;
  return ret;
}
int main() {
  scanf("%d", &n);
  v.resize(n * (n - 1) / 2);
  for (int _n(n * (n - 1) / 2), i(0); i < _n; i++) {
    scanf("%d %d %d %d %d", &v[i].s, &v[i].f, &v[i].l, &v[i].h, &v[i].a);
  }
  sort((v).begin(), (v).end(), comp);
  int res = -1, res_val = -1;
  for (int _n(26), i(0); i < _n; i++) {
    vector<int> tv(n - 1);
    tv[0] = i;
    int r1 = go(0, tv);
    if (r1 != -1) {
      res = i;
      res_val = r1;
      break;
    }
  }
  printf("%d %d\n", res, res_val);
  return 0;
}
