updated final.pl for subset 3