#!/usr/bin/perl -w

use v5.36;
use strict;
use experimental 'multidimensional';

local $/ = "\n\n";

my $sum;
while (<>) {
	my ($l, $r) = map { eval $_ } split /\n/;

	$sum += $. if compare($l,$r) == 1;

}
say $sum;

sub compare($l, $r) {
	my $i = 0;
	my $rv = 0;
	while (1) {
		my $lv = $l->[$i];
		my $rv = $r->[$i];

		my $comp;
		if (!defined $lv && defined $rv) {
			return 1;
		} elsif (defined $lv && !defined $rv) {
			return -1;
		} elsif (!defined $lv && !defined $rv) {
			return undef;
		} elsif (ref $lv && ref $rv) {
			$comp = compare($lv, $rv);
		} elsif (ref $lv && !ref $rv) {
			$comp = compare($lv, [$rv]);
		} elsif (!ref $lv && ref $rv) {
			$comp = compare([$lv], $rv);
		} elsif (!ref $lv && !ref $rv) {
			$comp = $rv <=> $lv if $lv != $rv;
		} else {
			die "$lv $rv";
		}
			
		return $comp if defined $comp;
		$i++;
	}
}
			

	
