use warnings;
use strict;

use List::Util 'sum';

my @header = split /,/, <>;

chomp $header[-1];

my %column_number;
for my $i (0 .. $
    $column_number{$header[$i]} = $i;
}
my @rows   = map [ split /,/ ], <>;
chomp $_->[-1] for @rows;


$_->[1]++ for @rows;


$_->[ $column_number{C4} ] += $_->[ $column_number{C1} ] for @rows;


push @header, 'Sum';
$column_number{Sum} = $

push @$_, sum(@$_) for @rows;
push @rows, [
                map  {
                    my $col = $_;
                    sum(map $_->[ $column_number{$col} ], @rows);
                } @header
            ];


print join(',' => @header), "\n";
print join(',' => @$_), "\n" for @rows;