#!/usr/bin/perl -w

use strict;
use v5.30;

# my $in = 3004953;
my $in = shift;

my @elves = (1 .. $in);
my $now = 0;
while (@elves > 1) {
	@elves = grep { $now = !$now } @elves;
	say join(' ', @elves);
}
say $elves[0];
