#!/usr/bin/perl

use v5.30;
use strict;

my @l = split /[,\s]/, <>;

my $pos = 0;
my $skip = 0;
# my @nodes = (0 .. 4);
my @nodes = (0 .. 255);
my $n = @nodes;

for my $i (@l) {
	my $end = $pos + $i;
	my @to_rev;
	say "pos=$pos skip $skip i=$i ", join(',', @nodes);
	if ($end > $n) {
		push @to_rev, splice @nodes, $pos;
		push @to_rev, splice @nodes, 0, $end - $n;
		@to_rev = reverse @to_rev;
		say "to_rev = ", join(',', @to_rev);
		unshift @nodes, splice @to_rev, @to_rev-($end-$n);
		push @nodes, @to_rev;
	} else {
		push @to_rev, splice @nodes, $pos, $i;
		splice @nodes, $pos, 0, reverse @to_rev;
	}
	$pos += $i + $skip++;;
	$pos -= $n while $pos >= $n;
}

say join(',',@nodes);

say $nodes[0] * $nodes[1];
