#!/usr/bin/perl
use strict;
use POSIX;

my @COST = (
['2000','3','6000'],
['3000','4','12000'],
['1000','5','5000'],
['4000','3','12000'],
);

my ($avarage_cost, $total_pieces, $total_price);
for my $param (@COST) {
 my ($unit_cost, $pieces, $price) = @$param;
 $total_pieces += $pieces;
 $total_price += $price;
 $avarage_cost = $total_price / $total_pieces;
 $avarage_cost = ceil($avarage_cost);
 $total_price = $total_pieces * $avarage_cost;
 print "$avarage_cost\n";
}