#!/usr/bin/perl -w

use v5.16;

my @deck = (0 .. 10006);
# my @deck = (0 .. 9);

while (<>) {
	if (/new stack/) {
		@deck = reverse @deck;
	} elsif (/increment (\d+)/) {
		my @nd;
		my $p = 0;
		for (@deck) {
			$nd[$p] = $_;
			$p += $1;
			$p %= @deck;
		}
		@deck = @nd;
	} elsif (/cut (\d+)/) {
		push @deck, splice @deck, 0, $1;
	} elsif (/cut (-\d+)/) {
		unshift @deck, splice @deck, $1;
	}
	say join(' ', @deck);
}

my $p = 0;
for (@deck) {
	say "pos $p" if $_ == 2019;
	$p++;
}
