#!/usr/bin/perl

use strict;

MAIN : {

    my ($super_matrix) = @ARGV;
    if (not defined $super_matrix) {
	die ("Usage: ./super_matrix_summing.pl <super matrix>\n");
    }
    
    my $hash;
    open(FILE,$super_matrix);
    while (my $line = <FILE>) {
	chomp $line;
	my ($l1, $l2, $n) = split(/\t/,$line);
	$hash->{$l1} += $n;
	$hash->{$l2} += $n;
    }
    close(FILE);
    
    foreach my $chr (sort {$a cmp $b} keys %$hash) {
	print $chr . "\t" . $hash->{$chr} . "\n";
    }

    
}
