#!/usr/bin/env perl
# idea:
#   HAS to be O(N) because have to check each item in worst case
use strict;
use warnings;

# first read the whole file in
my @all;

open(my $fh, '<', 'input') or die "$!";
for (<$fh>) {
	chomp;
	push @all, $_;
}

for (my $i = 0; $i < scalar @all; $i++) {
	my $cand = shift @all;
	my $magic = 2020 - $cand;
	my %seen;
	for (@all) {
		my $targ = $magic - $_;
		if (exists $seen{$targ}) {
			print $targ * $_ * $cand . "\n";
			exit(0);
		} else {
			$seen{$_} = 1;
		}
	}
	push @all, $cand;
}
exit(1);
