#!/usr/bin/perl -w

use v5.38;
use experimental 'for_list', 'builtin';
use builtin 'indexed';

chomp (my $line = <>);

sub hash {
	$_ = shift;
	my $n = 0;
	for (split //) {
		$n += ord($_);
		$n *= 17;
		$n %= 256;
	}
	$n;
}

my @slot;

for (split /,/, $line) {
	my ($name, $op, $num) = /(\w+)(\W)(\d*)/;
	my $id = hash($name);
	my $sl = $slot[$id];
	if ($op eq '=') {
		my $found;
		for my $s (@$sl) {
			if ($s->[0] eq $name) {
				$found = 1;
				$s->[1] = $num;
			}
		}
		if (!$found) {
			push @$sl, [ $name, $num ];
		}
	} elsif ($op eq '-') {
		@$sl = grep { $_->[0] ne $name } @{ $slot[$id] };
	}
}

my $sum;
for my ($i, $s) (indexed @slot) {
	for my ($j, $p) (indexed @$s) {
		$sum += ($i+1) * ($j+1) * $p->[1];
	}
}
say $sum;

