#!/usr/bin/perl

use v5.30;
use strict;

my %neigh;
while (<>) {
	my ($src, $dst) = /(\d+)/g;
	push @{ $neigh{$src} }, $dst;
	push @{ $neigh{$dst} }, $src;
}

my %used;
my $max;
my $mlen;
sub walk {
	my ($score, @path) = @_;
	my $now = $path[-1];
	if (!$mlen || $mlen < @path) {
		$mlen = @path;
		$max = $score;
	} elsif ($mlen && $mlen == @path) {
		$max = $score if $max < $score;
	}
	# say "$score: ", join(' ', @path);
	for my $next (@{ $neigh{$now} }) {
		next if $used{$now,$next} || $used{$next,$now};
		$used{$now,$next} = 1;
		walk ($score + $now + $next, @path, $next);
		delete $used{$now,$next};
	}
}

walk(0, 0);
say $max;
