#!/usr/bin/perl -w

use v5.36;
use strict;
use POSIX qw(floor);

sub snafu($sn) {
	my ($n, $order) = (0, 1);
	for my $dig (reverse split(//, $sn)) {
		my $x;
		$x=1  if $dig eq '1';
		$x=2  if $dig eq '2';
		$x=0  if $dig eq '0';
		$x=-1 if $dig eq '-';
		$x-=2 if $dig eq '=';
		$n += $x * $order;
		$order *= 5;
	}
	$n;
}

my $sum;
while (<>) {
	chomp;
	
	$sum +=snafu($_);
}
say "sum = $sum";

my $order = 5**25;
my @digits = qw(= - 0 1 2);
my $ans = '';
while ($order >= 1) {
	my $d = floor($sum/$order);
	my $d2 = ($sum - $order*$d)*5/$order;
	$d++ if $d2 > 2.5;
	$sum -= $order * $d;
	$ans .= $digits[$d+2];
	$order /= 5;
}
$ans =~ s/^0*//;
say $ans;
