#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void debug(const T& c) {
  cout << "{";
  for (__typeof((c.begin())) it = (c).begin(); it != (c).end(); ++it)
    cout << *it << ",";
  cout << "}" << endl;
}
template <class T>
inline void setmin(T& a, const T& b) {
  if (b < a) a = b;
}
template <class T>
inline void setmax(T& a, const T& b) {
  if (b > a) a = b;
}
template <class T>
inline int size(const T& c) {
  return (int)c.size();
}
template <class T>
inline string to_str(const T& a) {
  ostringstream os("");
  os << a;
  return os.str();
}
template <class T>
inline T sqr(const T& a) {
  return a * a;
}
template <class T>
T next() {
  T x;
  cin >> x;
  return x;
}
int next_int() {
  int x;
  scanf("%d", &x);
  return x;
}
int mini[20][20];
int maxi[20][20];
int acti[20][20];
int flow[20][20];
int stan[20];
int n;
int best_fuel, best_cost;
void popraw(int fuel, int cost) {
  if (fuel < best_fuel) {
    best_fuel = fuel;
    best_cost = cost;
  } else if (fuel == best_fuel && cost > best_cost) {
    best_cost = cost;
  }
}
pair<int, int> next(int a, int b) {
  if (b == n) {
    a++;
    b = a + 1;
  } else {
    b++;
  }
  return make_pair(a, b);
}
void go(int a, int b, int cost) {
  if (a == n) {
    for (int i = (1); i <= (n - 1); ++i)
      if (stan[i] != 0) return;
    popraw(stan[n], cost);
    return;
  }
  pair<int, int> p = next(a, b);
  if (stan[a - 1] > 0 && a - 1 >= 1) return;
  for (int i = (mini[a][b]); i <= (maxi[a][b]); ++i) {
    if (stan[a] >= i) {
      stan[a] -= i;
      stan[b] += i;
      go(p.first, p.second, cost + i * i + (i == 0 ? 0 : acti[a][b]));
      stan[a] += i;
      stan[b] -= i;
    }
  }
}
int main() {
  n = next_int();
  for (int i = (1); i <= (n); ++i)
    for (int j = (i + 1); j <= (n); ++j) {
      int a = next_int();
      int b = next_int();
      mini[a][b] = next_int();
      maxi[a][b] = next_int();
      acti[a][b] = next_int();
    }
  stan[1] = (1 << 30);
  best_fuel = (1 << 30);
  for (int i = (0); i <= (30); ++i) {
    for (int j = (1); j <= (n); ++j) stan[j] = 0;
    stan[1] = i;
    go(1, 2, 0);
    if (best_fuel != (1 << 30)) break;
  }
  if (best_fuel != (1 << 30)) {
    printf("%d %d\n", best_fuel, best_cost);
  } else {
    printf("-1 -1\n");
  }
  return 0;
}
