#!/usr/bin/perl

use strict;
use warnings;

my $normalKeys =
	"????abcd" .
	"efghijkl" .
	"mnopqrst" .
	"uvwxyz12" .
	"34567890" .
	"\n\b\x08\t -=[" .
	"]\\#;'`,." .
	"/???????" .
	"????????" .
	"????????" .
	"????/*-+" .
	"\n1234567" .
	"890.\\??=" .
	"????????" .
	"????????" .
	"????????" .
	"????????" .
	"?\\??????";

my $shiftedKeys =
	"????ABCD" .
	"EFGHIJKL" .
	"MNOPQRST" .
	"UVWXYZ!@" .
	"#\$\%^&*()" .
	"\n\b\x08\t _+{" .
	"}|~:\"~<>" .
	"????????" .
	"????????" .
	"????????" .
	"????/*-+" .
	"\n1234567" .
	"890.\\??=" .
	"????????" .
	"????????" .
	"????????" .
	"????????" .
	"?|??????";

binmode(STDIN);
binmode(STDOUT);

my $data = "";
while (<STDIN>) { $data .= $_; }

my $previousSet = "\0" x 8;
my $dataLen = length($data);
for (my $i = 0; $i + 8 <= $dataLen; $i += 8) {
	my $currentSet = substr($data, $i, 8);
	for (my $j = 2; $j < 8; $j++) {
		my $c = ord(substr($currentSet, $j, 1));
		my $isNew = 1;
		for (my $k = 2; $k < 8; $k++) {
			if (ord(substr($previousSet, $k, 1)) == $c) {
				$isNew = 0;
				last;
			}
		}
		if ($isNew) {
			my $set = ord(substr($currentSet, 0, 1)) & 0x22 ? $shiftedKeys : $normalKeys;
			print substr($set, $c, 1);
		}
	}
	$previousSet = $currentSet;
}
