#!/usr/bin/perl -w

use strict;

my @nums = sort { $a <=> $b } <>;
chomp @nums;

while (@nums > 1) {
	print "Nums: ", join(' ', @nums), "\n";
	my $cmp = $nums[0] + $nums[-1] <=> 2020;
	if ($cmp < 0) {
		shift @nums;
	} elsif ($cmp == 0) {
		print "$nums[0]*$nums[-1]=", $nums[0]*$nums[-1], "\n";
		last;
	} else {
		pop @nums;
	}
}

