#!/usr/bin/perl -w

use strict;

my $sum = 0;
while (<>) {
	chomp;
	1 while
		s/\((\d+)\)/$1/ ||
		s/(\([^\(\)]*?)(\d+)\s*\+\s*(\d+)([^\(\)]*\))/$1.($2+$3).$4/e ||
		s/(\([^\(\)]*?)(\d+)\s*\*\s*(\d+)([^\(\)]*\))/$1.($2*$3).$4/e ||
		s/(\d+)\s*([\+])\s*(\d+)/"$1$2$3"/ee ||
		s/(\d+)\s*([\*])\s*(\d+)/"$1$2$3"/ee;
	$sum += $_;
}
print "sum=$sum\n";
