#!/usr/local/bin/perl

@int = ();
$j = 0;

# infile is the file of numbers to get

open(INFILE, $ARGV[0])
  || die "Cannot open input file!\n";

while (<INFILE>) {
  /([0-9\.]+)/;
  $int[$j++] = $1;
}


@vals = ();
$i = 0;

# get all the numbers

while (<STDIN>) {
  /(.*)/;
  $vals[$i++] = $1;
}

$sum = 0;
for ($i = 0; $i < $j; $i++) {
  $sum += $vals[$int[$i]-1];   # starts at 0
}

printf("answer is %f\n", $sum);
