#!/bin/perl
# Сочетания $n из $V

use warnings qw{ all };
use strict;

my $n = shift @ARGV ||  2; # 5
my $V = shift @ARGV || 4; # из 36 по умолчанию

my @a = (0 .. $n - 1);
print "@a\n";

for ( ;; ) {
my $j;
for ( $j = 0; $j < $n - 1; $j ++ ) {
if ( $a[$j] + 1 < $a[$j + 1] ) {
last;
}
}
unless ( $j < $n - 1 ) {
if ( $a[$n - 1] < $V - 1 ) {
$j = $n - 1
} else {
last
}
}
$a[$j] ++;
@a[0 .. $j - 1] = ( 0 .. $j - 1 );
print "@a\n";
}