#!/usr/bin/perl -w

use v5.30;
use strict;

local $/ = "\n\n";

my $total = 0;
while(<>) {
	chomp;
	last if !length;

	my @nums = /(\d+)/g;
	my @before = @nums[0..3];
	my ($op, $a, $b, $c) = @nums[4..7];
	my @after  = @nums[8..11];
	my $match = 0;

	# addr
	$match++ if ($before[$a] + $before[$b] == $after[$c]);
	# addi
	$match++ if ($before[$a] + $b == $after[$c]);
	# mulr
	$match++ if ($before[$a] * $before[$b] == $after[$c]);
	# muli
	$match++ if ($before[$a] * $b == $after[$c]);
	# bandr
	$match++ if (($before[$a] & $before[$b]) == $after[$c]);
	# bandi
	$match++ if (($before[$a] & $b) == $after[$c]);
	# borr
	$match++ if (($before[$a] | $before[$b]) == $after[$c]);
	# bori
	$match++ if (($before[$a] | $b) == $after[$c]);
	# setr
	$match++ if ($before[$a] == $after[$c]);
	# seti
	$match++ if ($a == $after[$c]);
	# gtir
	$match++ if (($a > $before[$b] ? 1 : 0) == $after[$c]);
	# gtri
	$match++ if (($before[$a] > $b ? 1 : 0) == $after[$c]);
	# gtrr
	$match++ if (($before[$a] > $before[$b] ? 1 : 0) == $after[$c]);
	# eqir
	$match++ if (($a == $before[$b] ? 1 : 0) == $after[$c]);
	# eqri
	$match++ if (($before[$a] == $b ? 1 : 0) == $after[$c]);
	# eqrr
	$match++ if (($before[$a] == $before[$b] ? 1 : 0) == $after[$c]);

	$total++ if $match >= 3;
}

say $total;
