#!/usr/bin/perl

$totlen=0;
$count=0;
$minlen=9999999999;
$maxlen=0;
while (<>) {
    ($ctg,$foo) = split;
    $len{$ctg} = $foo;
    $totlen += $foo;

    if ($foo > $maxlen) {$maxlen = $foo;}
    if ($foo < $minlen) {$minlen = $foo;}
    $count++;
}
$halflen = $totlen/2;

@sorted = (sort {$len{$b} <=> $len{$a}} keys %len);
$sum=0;
while ($sum < $halflen) {
 $ctg = shift(@sorted);
 $sum += $len{$ctg};
}

print "$count sequences, sum_length: $totlen\n";
print "min_length: $minlen, max_length: $maxlen, N50: $len{$ctg}\n";
