#!/usr/bin/env perl
use strict;
use warnings;
my ($char, @result);
my $instruction = '';
my $current_cell = 0;
my $stack = {};
my $level = 0;
next if $char !~ m/[adehkKoOru]/;
my $temp = $instruction . $char;
if ($temp eq "Ko") {
($level > 0) ?
push @{$stack->{$level}}, $temp : $result[$current_cell]++;
$instruction = '';
}
elsif ($temp eq "kO") {
($level > 0) ?
push @{$stack->{$level}}, $temp : $result[$current_cell]--;
$instruction = '';
}
elsif ($temp eq "Kudah") {
($level > 0) ?
push @{$stack->{$level}}, $temp : $current_cell++;
$instruction = '';
}
elsif ($temp eq "kudah") {
($level > 0) ?
push @{$stack->{$level}}, $temp : $current_cell--;
$instruction = '';
}
elsif ($instruction eq "Kud" and $char ne "a") {
$stack->{++$level} = [];
$instruction = $char;
}
elsif ($instruction eq "kud" and $char ne "a") {
&cycle();
$level--;
$instruction = $char;
}
elsif ($temp eq "Kukarek") {
($level > 0) ?
push @{$stack->{$level}}, $temp :
$instruction = '';
}
else { $instruction .= $char }
}
sub cycle {
while ( $result[$current_cell] > 0 ) {
foreach my $item ( @{$stack->{$level}} ) {
if ($item eq "Ko") { $result[$current_cell]++ }
elsif ($item eq "kO") { $result[$current_cell]-- }
elsif ($item eq "Kudah") { $current_cell++ }
elsif ($item eq "kudah") { $current_cell-- }
elsif ($item eq "Kukarek") { print chr $result[$current_cell] } }
}
}
IyEvdXNyL2Jpbi9lbnYgcGVybAoKdXNlIHN0cmljdDsKdXNlIHdhcm5pbmdzOwoKbXkgKCRjaGFyLCBAcmVzdWx0KTsKbXkgJGluc3RydWN0aW9uID0gJyc7Cm15ICRjdXJyZW50X2NlbGwgPSAwOwpteSAkc3RhY2sgPSB7fTsKbXkgJGxldmVsID0gMDsKCmZvcmVhY2ggJGNoYXIgKCBzcGxpdCAvLywgam9pbigiIiwgPD4pICkgewogICAgbmV4dCBpZiAkY2hhciAhfiBtL1thZGVoa0tvT3J1XS87CgogICAgbXkgJHRlbXAgPSAkaW5zdHJ1Y3Rpb24gLiAkY2hhcjsKCiAgICBpZiAoJHRlbXAgZXEgIktvIikgICAgewogICAgICAgICgkbGV2ZWwgPiAwKSA/CiAgICAgICAgICAgIHB1c2ggQHskc3RhY2stPnskbGV2ZWx9fSwgJHRlbXAgOgogICAgICAgICAgICAkcmVzdWx0WyRjdXJyZW50X2NlbGxdKys7CgogICAgICAgICRpbnN0cnVjdGlvbiA9ICcnOwogICAgfQogICAgZWxzaWYgKCR0ZW1wIGVxICJrTyIpICAgIHsKICAgICAgICAoJGxldmVsID4gMCkgPwogICAgICAgICAgICBwdXNoIEB7JHN0YWNrLT57JGxldmVsfX0sICR0ZW1wIDoKICAgICAgICAgICAgJHJlc3VsdFskY3VycmVudF9jZWxsXS0tOwoKICAgICAgICAkaW5zdHJ1Y3Rpb24gPSAnJzsKICAgIH0KICAgIGVsc2lmICgkdGVtcCBlcSAiS3VkYWgiKSB7CiAgICAgICAgKCRsZXZlbCA+IDApID8KICAgICAgICAgICAgcHVzaCBAeyRzdGFjay0+eyRsZXZlbH19LCAkdGVtcCA6CiAgICAgICAgICAgICRjdXJyZW50X2NlbGwrKzsKCiAgICAgICAgJGluc3RydWN0aW9uID0gJyc7CiAgICB9CiAgICBlbHNpZiAoJHRlbXAgZXEgImt1ZGFoIikgewogICAgICAgICgkbGV2ZWwgPiAwKSA/CiAgICAgICAgICAgIHB1c2ggQHskc3RhY2stPnskbGV2ZWx9fSwgJHRlbXAgOgogICAgICAgICAgICAkY3VycmVudF9jZWxsLS07CgogICAgICAgICRpbnN0cnVjdGlvbiA9ICcnOwogICAgfQogICAgZWxzaWYgKCRpbnN0cnVjdGlvbiBlcSAiS3VkIiBhbmQgJGNoYXIgbmUgImEiKSB7CiAgICAgICAgJHN0YWNrLT57KyskbGV2ZWx9ID0gW107CiAgICAgICAgJGluc3RydWN0aW9uID0gJGNoYXI7CiAgICB9CiAgICBlbHNpZiAoJGluc3RydWN0aW9uIGVxICJrdWQiIGFuZCAkY2hhciBuZSAiYSIpIHsKICAgICAgICAmY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29Lb0tvIEt1ZC1LdWRhaAprT2tPa09rTyBrdWRhaCBrTyBrdWQtS3VkYWggS28gS3VrYXJlayBrdWRhaApLb0tvS29LbyBLdWQtS3VkYWggS29Lb0tvS28ga3VkYWgga08ga3VkLUt1ZGFoIGtPIEt1a2FyZWsKa09rT2tPa09rTyBLdWthcmVrIEt1a2FyZWsga09rT2tPa09rT2tPa08KS3VrYXJlaw==
KoKoKoKoKoKoKoKoKoKo Kud-Kudah
KoKoKoKoKoKoKoKo kudah kO kud-Kudah Kukarek kudah
KoKoKo Kud-Kudah
kOkOkOkO kudah kO kud-Kudah Ko Kukarek kudah
KoKoKoKo Kud-Kudah KoKoKoKo kudah kO kud-Kudah kO Kukarek
kOkOkOkOkO Kukarek Kukarek kOkOkOkOkOkOkO
Kukarek