#include <bits/stdc++.h>
using namespace std;
struct truba {
  int l, h, a, c;
};
int main() {
  int n, s, f, l, h, a, c;
  int ans1 = 1000, ans2 = 0;
  cin >> n;
  truba** T = new truba*[n + 1];
  truba tmp;
  for (int i = 1; i <= n; i++) {
    T[i] = new truba[n + 1];
  }
  for (int i = 0; i < n * (n - 1) / 2; i++) {
    cin >> s >> f >> tmp.l >> tmp.h >> tmp.a;
    tmp.c = tmp.l;
    T[s][f] = tmp;
  }
  for (int At = 0; At < 26; At++) {
    s = 1;
    f = 2;
    for (int i = 1; i <= n; i++)
      for (int j = i + 1; j <= n; j++) T[i][j].c = T[i][j].l;
    while (1) {
      if (f == n) {
        if (s == 1)
          c = At;
        else {
          c = 0;
          for (int i = 1; i < s; i++) c += T[i][s].c;
        }
        for (int i = s + 1; i < n; i++) c -= T[s][i].c;
        if (c <= T[s][f].h && c >= T[s][f].l) {
          T[s][f].c = c;
          s++;
          f = s + 1;
          if (s == n) {
            ans1 = At;
            int cost = 0;
            for (int i = 1; i <= n; i++)
              for (int j = i + 1; j <= n; j++)
                if (T[i][j].c > 0) cost += T[i][j].a + T[i][j].c * T[i][j].c;
            if (cost > ans2) ans2 = cost;
            if (n > 2) {
              s -= 2;
              f = n - 1;
              T[s][f].c++;
            } else
              break;
          } else {
            for (int i = s + 1; i < n; i++) T[s][i].c = T[s][i].l;
          }
        } else {
          f--;
          T[s][f].c++;
        }
      } else if (T[s][f].c <= T[s][f].h) {
        f++;
      } else if (T[s][f].c > T[s][f].h) {
        if (f > s + 1) {
          f--;
          for (int i = f + 1; i < n; i++) T[s][i].c = T[s][i].l;
        } else if (s > 1) {
          s--;
          f = n - 1;
        } else {
          break;
        }
        T[s][f].c++;
      }
    }
    if (ans1 != 1000) break;
  }
  if (ans1 == 1000) {
    cout << "-1 -1";
  } else {
    cout << ans1 << " " << ans2;
  }
  return 0;
}
