#!/usr/bin/perl

use v5.30;
use strict;

my (@acc, @vel, @pos);
while (<>) {
	my (@l) = /(-?\d+)/g;
	push @pos, [ splice(@l, 0, 3) ];
	push @vel, [ splice(@l, 0, 3) ];
	push @acc, [ splice(@l, 0, 3) ];
}

use List::Util qw(sum);
my ($mina, $minv, $minp, $mini);
for my $i (0 .. $#acc) {
	my $a = sum map { abs } @{ $acc[$i] };
	my $v = sum map { abs } @{ $vel[$i] };
	my $p = sum map { abs } @{ $pos[$i] };
	say "$i: $a, $v, $p";
	if (!defined $mini || $a < $mina) {
		$mina = $a;
		$minv = $v;
		$minp = $p;
		$mini = $i;
	} elsif (defined $mini && $a == $mina && $v < $minv) {
		$minv = $v;
		$minp = $p;
		$mini = $i;
	} elsif (defined $mini && $a == $mina && $v == $minv && $p < $minp) {
		$minp = $p;
		$mini = $i;
	}
}
say $mini;

__END__
while(1) {
	my (@nvel, @npos);
	for my $i (0 .. @acc) {
		my @v;
		push @v, $vel[$i][$_] + $acc[$i][$_] for 0 .. 2;
		push @nvel, \@v;
		my @p;
		push @p, $pos[$i][$_] + $v[$_] for 0 .. 2;
		push @npos, \@p;
	}
}
	
			
	

