#!/usr/bin/perl -w

use v5.36;
use strict;
use experimental 'multidimensional';

my $sum;
my $s;
while (<>) {
	$s .= $_;
	next if $. % 3;
	$_ = $s;
	$s = '';
	s/\A\S*(.)\S*\s\S*\1\S*\s\S*\1\S*\s?\z/$1/;
	$sum += /[A-Z]/
		? ord() - ord('A') + 27
		: ord() - ord('a') + 1; 
}
say $sum;
