#include <bits/stdc++.h>
using namespace std;
const long double eps = 1e-8;
const int N = 1e4 + 50;
struct quat {
  long double a, b, c, d;
  quat(long double x = 0, long double y = 0, long double m = 0,
       long double n = 0) {
    a = x, b = y, c = m, d = n;
  }
  quat operator+(const quat &tt) const {
    return quat(a + tt.a, b + tt.b, c + tt.c, d + tt.d);
  }
  quat operator-(const quat &tt) const {
    return quat(a - tt.a, b - tt.b, c - tt.c, d - tt.d);
  }
  quat operator*(const quat &tt) const {
    long double x = a * tt.a - b * tt.b - c * tt.c - d * tt.d;
    long double y = a * tt.b + b * tt.a + c * tt.d - d * tt.c;
    long double m = a * tt.c - b * tt.d + c * tt.a + d * tt.b;
    long double n = a * tt.d + b * tt.c - c * tt.b + d * tt.a;
    return quat(x, y, m, n);
  }
  quat operator*(long double val) {
    return quat(a * val, b * val, c * val, d * val);
  }
  long double size() { return a * a + b * b + c * c + d * d; }
  quat conj() { return quat(a, -b, -c, -d); }
  quat inv() { return conj() * (1 / size()); }
};
quat round(quat x) {
  quat m(roundl(x.a), roundl(x.b), roundl(x.c), roundl(x.d));
  quat n(roundl(x.a - 0.5) + 0.5, roundl(x.b - 0.5) + 0.5,
         roundl(x.c - 0.5) + 0.5, roundl(x.d - 0.5) + 0.5);
  return (m - x).size() < (n - x).size() ? m : n;
}
pair<quat, quat> div(quat x, quat y) {
  quat tt = round(y.inv() * x);
  return {tt, x - y * tt};
}
quat GCD(quat x, quat y) {
  while (y.size() > eps) {
    quat tt = div(x, y).second;
    x = y, y = tt;
  }
  return x;
}
long long GCD(long long a, long long b) { return b ? GCD(b, a % b) : a; }
int n;
long long gcd;
long long x[N], y[N], z[N];
quat tup[N], kk;
vector<long long> vt;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%lld%lld%lld", &x[i], &y[i], &z[i]);
    gcd = GCD(GCD(gcd, abs(x[i])), GCD(y[i], z[i]));
  }
  for (int i = 1; i <= n; ++i) {
    tup[i] = quat(0, x[i] / gcd, y[i] / gcd, z[i] / gcd);
    kk = GCD(kk, tup[i]);
  }
  long long tt = roundl(kk.size());
  int sq = sqrt(tt);
  for (int i = 1; i <= sq; ++i) {
    if (tt % i == 0) {
      vt.emplace_back(i);
      if (i * i != tt) vt.emplace_back(tt / i);
    }
  }
  sort(vt.rbegin(), vt.rend());
  for (auto &x : vt) {
    quat Q = GCD(kk, quat(x));
    quat Qconj = Q.conj();
    long long r = roundl(Q.size());
    if (r != x) continue;
    quat Qprime = Q * (1.0 / r);
    quat Qprimeconj = Qconj * (1.0 / r);
    bool vis = 1;
    for (int i = 1; i <= n; ++i) {
      quat v = Qprimeconj * tup[i] * Qprime;
      if (abs(roundl(v.b) - v.b) > eps || abs(roundl(v.c) - v.c) > eps ||
          abs(roundl(v.d) - v.d) > eps) {
        vis = 0;
        break;
      }
    }
    if (vis) {
      quat ret[3];
      ret[0] = Q * quat(0, 1, 0, 0) * Qconj;
      ret[1] = Q * quat(0, 0, 1, 0) * Qconj;
      ret[2] = Q * quat(0, 0, 0, 1) * Qconj;
      printf("%lld\n", gcd * gcd * r * r);
      for (int i = 0; i < 3; ++i) {
        long long a = (long long)(gcd * roundl(ret[i].b));
        long long b = (long long)(gcd * roundl(ret[i].c));
        long long c = (long long)(gcd * roundl(ret[i].d));
        printf("%lld %lld %lld\n", a, b, c);
      }
      return 0;
    }
  }
  return 0;
}
