#!/usr/bin/perl -ln

# <q-okrtot >qdist

BEGIN { $i = 0; $posl = 200; }

$n[$i++] = $_;
END {

	my $totnum = 0;
	foreach (@n) {
		$totnum += $_;
	}
	print STDERR "Celkem hlasu: $totnum\n";
	$perm = sprintf '%.0f', $totnum/$posl;
	print STDERR "Hlasu per mandat: $perm\n";
	for (my $i = 0; $i <= $#n; $i++) {
		$z[$i] = [ $i, $n[$i] % $perm ];
		$c[$i] = int($n[$i] / $perm);
	}

	foreach (@c) { $tot += $_; }
	print STDERR "Mandatu pred rozdelenim zbytku: $tot\n";
	$r = $posl-$tot;
	@z2 = reverse ( sort { $a->[1] <=> $b->[1] } @z );
	foreach (@z2) { print STDERR "Zbytek kraje $_->[0]: $_->[1]"; }
	foreach (splice(@z2, 0, $r)) { $c[$_->[0]]++; }
	$tot = 0;
	foreach (@c) { $tot += $_; }
	print STDERR $tot;
	print join("\t", @c);
}
