#!/usr/bin/perl -w

use strict;

open OUT, "> logistic.txt"; # Mac $B$J$N$G=PNO%U%!%$%k8GDj(B
while(<>) {
	chomp; # $B9TKv2~9T5-9f:o=|(B
	s/#.*$//go; # $B%3%a%s%H$L$-(B
	next if m/^\s*$/o; # $B6u9T$H$P$7(B
	my @line = split; # $BJ,3d(B
	my $number_total = shift @line; # $BBh0lNs$H$k(B
	my $number_yes   = shift @line; # $BBhFsNs$H$k(B
	my $others = join "\t", @line; # $B$N$3$j$O$/$C$D$1$k(B
	die "ERROR: invalid line\n\t$_\n" if $number_total < $number_yes;
	for (my $i = 0; $i < $number_yes; $i++) {
		print OUT "1\t$others\n"; # ``1'' $B$N9T$H$7$F=PNO(B
	}
	for (my $i = 0; $i < $number_total - $number_yes; $i++) {
		print OUT "0\t$others\n"; # ``0'' $B$N9T$H$7$F=PNO(B
	}
}
close OUT;

exit 0;
