#include <bits/stdc++.h>
using namespace std;
int c[6][6];
int q[6];
int n;
int h[6][6], l[6][6], a[6][6];
int ans1 = -1, ans2 = -1;
void doit(int s, int k) {
  if (s == n - 2) {
    bool solved = true;
    for (int i = 1; i < n - 1; i++)
      if (q[i] < l[i][n - 1] || q[i] > h[i][n - 1]) {
        solved = false;
        break;
      } else
        c[i][n - 1] = q[i];
    c[0][n - 1] = l[0][n - 1];
    if (solved) {
      int coast = 0;
      int fl = 0;
      for (int i = 0; i < n - 1; i++)
        for (int j = i + 1; j < n; j++)
          if (c[i][j]) {
            coast += (a[i][j] + c[i][j] * c[i][j]);
          }
      for (int i = 0; i < n - 1; i++) fl += c[i][n - 1];
      if (ans1 == -1) {
        ans1 = fl;
        ans2 = coast;
      } else {
        if (ans1 > fl || ans1 == fl && ans2 < coast) {
          ans1 = fl;
          ans2 = coast;
        }
      }
    }
    for (int i = 0; i < n - 1; i++) c[i][n - 1] = 0;
    return;
  }
  int min = (h[s][k] < q[s] ? h[s][k] : q[s]);
  for (int j = l[s][k]; j <= min; j++) {
    c[s][k] = j;
    q[k] += j;
    q[s] -= j;
    if (k == n - 2)
      doit(s + 1, s + 2);
    else
      doit(s, k + 1);
    c[s][k] = 0;
    q[k] -= j;
    q[s] += j;
  }
}
int main() {
  cin >> n;
  for (int i = 0; i < n * (n - 1) / 2; i++) {
    int s, f;
    cin >> s >> f;
    s--;
    f--;
    cin >> l[s][f] >> h[s][f] >> a[s][f];
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) c[i][j] = 0;
    q[i] = 0;
  }
  q[0] = 100000;
  doit(0, 1);
  cout << ans1 << ' ' << ans2;
  return 0;
}
