#!/usr/bin/perl -w

use v5.38;

my @stones = map { chomp; [ /-?\d+/g ] } <>;
my ($min, $max) = (200000000000000, 400000000000000);
# my ($min, $max) = (7, 27);

sub from_param {
	my ($x0, $y0, $z0, $xs, $ys, $zs) = @_;
	return ($ys/$xs, $y0-($ys*$x0/$xs));
}

sub to_time {
	my ($x, $xs, $x0) = @_;
	return ($x-$x0)/$xs;
}

my $sum;
for my $s1 (0 .. $#stones-1) {
	my @st1 = @{ $stones[$s1] };
	my ($a, $b) = from_param(@st1);
	say "y=$a*x + $b";

	for my $s2 ($s1+1 .. $#stones) {
		my @st2 = @{ $stones[$s2] };
		my ($c, $d) = from_param(@st2);
		say "  y=$c*x + $d";
		if ($a == $c) {
			if ($b == $d) {
				die "two same lines";
			}
			next;
		}
		my $xi = ($d-$b)/($a-$c);
		my $yi = $a*$xi + $b;
		my $t0 = to_time($xi, $st1[3], $st1[0]);
		my $t1 = to_time($xi, $st2[3], $st2[0]);
		say "  intersection at $xi, $yi at $t0 $t1";
		if ($xi < $min || $xi > $max || $yi < $min || $yi > $max) {
			say "  outside";
			next;
		}
		if ($t0 < 0 || $t1 < 0) {
			say "  in the past";
			next;
		}
		$sum++;
	}
}

say $sum;
